diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/PeripheralNames.h b/targets/TARGET_Cypress/TARGET_PSOC6/PeripheralNames.h new file mode 100644 index 0000000000..9e126988bb --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/PeripheralNames.h @@ -0,0 +1,109 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_PERIPHERALNAMES_H +#define MBED_PERIPHERALNAMES_H + +#include "cmsis.h" +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + UART_0 = (int)SCB0_BASE, + UART_1 = (int)SCB1_BASE, + UART_2 = (int)SCB2_BASE, + UART_3 = (int)SCB3_BASE, + UART_4 = (int)SCB4_BASE, + UART_5 = (int)SCB5_BASE, + UART_6 = (int)SCB6_BASE, + UART_7 = (int)SCB7_BASE, +} UARTName; + + +typedef enum { + SPI_0 = (int)SCB0_BASE, + SPI_1 = (int)SCB1_BASE, + SPI_2 = (int)SCB2_BASE, + SPI_3 = (int)SCB3_BASE, + SPI_4 = (int)SCB4_BASE, + SPI_5 = (int)SCB5_BASE, + SPI_6 = (int)SCB6_BASE, + SPI_7 = (int)SCB7_BASE, +} SPIName; + +typedef enum { + I2C_0 = (int)SCB0_BASE, + I2C_1 = (int)SCB1_BASE, + I2C_2 = (int)SCB2_BASE, + I2C_3 = (int)SCB3_BASE, + I2C_4 = (int)SCB4_BASE, + I2C_5 = (int)SCB5_BASE, + I2C_6 = (int)SCB6_BASE, + I2C_7 = (int)SCB7_BASE, +} I2CName; + +typedef enum { + PWM_32b_0 = TCPWM0_BASE, + PWM_32b_1, + PWM_32b_2, + PWM_32b_3, + PWM_32b_4, + PWM_32b_5, + PWM_32b_6, + PWM_32b_7, + PWM_16b_0 = TCPWM1_BASE, + PWM_16b_1, + PWM_16b_2, + PWM_16b_3, + PWM_16b_4, + PWM_16b_5, + PWM_16b_6, + PWM_16b_7, + PWM_16b_8, + PWM_16b_9, + PWM_16b_10, + PWM_16b_11, + PWM_16b_12, + PWM_16b_13, + PWM_16b_14, + PWM_16b_15, + PWM_16b_16, + PWM_16b_17, + PWM_16b_18, + PWM_16b_19, + PWM_16b_20, + PWM_16b_21, + PWM_16b_22, + PWM_16b_23, +} PWMName; + +typedef enum { + ADC_0 = (int)SAR_BASE, +}ADCName; + +typedef enum { + DAC_0 = (int)CTDAC0_BASE, +} DACName; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/PeripheralPins.h b/targets/TARGET_Cypress/TARGET_PSOC6/PeripheralPins.h new file mode 100644 index 0000000000..07237af517 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/PeripheralPins.h @@ -0,0 +1,62 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_PERIPHERALPINS_H +#define MBED_PERIPHERALPINS_H + +#include "pinmap.h" +#include "PeripheralNames.h" + + +// //*** I2C *** +#if DEVICE_I2C +extern const PinMap PinMap_I2C_SDA[]; +extern const PinMap PinMap_I2C_SCL[]; +#endif + +//*** PWM *** +#if DEVICE_PWMOUT +extern const PinMap PinMap_PWM_OUT[]; +#endif + +//*** SERIAL *** +#ifdef DEVICE_SERIAL +extern const PinMap PinMap_UART_TX[]; +extern const PinMap PinMap_UART_RX[]; +extern const PinMap PinMap_UART_RTS[]; +extern const PinMap PinMap_UART_CTS[]; +#endif + +//*** SPI *** +#ifdef DEVICE_SPI +extern const PinMap PinMap_SPI_MOSI[]; +extern const PinMap PinMap_SPI_MISO[]; +extern const PinMap PinMap_SPI_SCLK[]; +extern const PinMap PinMap_SPI_SSEL[]; +#endif + +//*** ADC *** +#ifdef DEVICE_ANALOGIN +extern const PinMap PinMap_ADC[]; +#endif + +//*** DAC *** +#ifdef DEVICE_ANALOGOUT +extern const PinMap PinMap_DAC[]; +#endif + +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/PinNamesTypes.h b/targets/TARGET_Cypress/TARGET_PSOC6/PinNamesTypes.h new file mode 100644 index 0000000000..559e3cc2c3 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/PinNamesTypes.h @@ -0,0 +1,84 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_PINNAMESTYPES_H +#define MBED_PINNAMESTYPES_H + +#include "cmsis.h" + +typedef enum { + PIN_INPUT = 0, + PIN_OUTPUT +} PinDirection; + +typedef enum { + PullNone = 0, + PullUp = 1, + PullDown = 2, + OpenDrainDriveLow = 3, + OpenDrainDriveHigh = 4, + OpenDrain = OpenDrainDriveLow, + PushPull = 5, + AnalogMode = 6, + PullDefault = PullNone +} PinMode; + +typedef struct { + en_hsiom_sel_t hsiom : 8; + en_clk_dst_t clock : 8; + PinMode mode : 4; + PinDirection dir : 1; +} PinFunction; + +// Encode pin function. +// Output function +#define CY_PIN_FUNCTION(hsiom, clock, mode, dir) (int)(((dir) << 20) | ((mode) << 16) | ((clock) << 8) | (hsiom)) +#define CY_PIN_OUT_FUNCTION(hsiom, clock) CY_PIN_FUNCTION(hsiom, clock, PushPull, PIN_OUTPUT) +#define CY_PIN_OD_FUNCTION(hsiom, clock) CY_PIN_FUNCTION(hsiom, clock, OpenDrain, PIN_OUTPUT) +#define CY_PIN_IN_FUNCTION(hsiom, clock) CY_PIN_FUNCTION(hsiom, clock, PullDefault, PIN_INPUT) +#define CY_PIN_PULLUP_FUNCTION(hsiom, clock) CY_PIN_FUNCTION(hsiom, clock, PullUp, PIN_INPUT) +#define CY_PIN_ANALOG_FUNCTION(clock) CY_PIN_FUNCTION(HSIOM_SEL_GPIO, clock, AnalogMode, 0) + +// Create unique name to force 32-bit PWM usage on a pin. +#define CY_PIN_FORCE_PWM_32(pin) ((uint32_t)(pin) + 0x8000) + +static inline en_hsiom_sel_t CY_PIN_HSIOM(int function) +{ + return (en_hsiom_sel_t)(function & 0xFF); +} + +static inline en_clk_dst_t CY_PIN_CLOCK(int function) +{ + return (en_clk_dst_t)((function >> 8) & 0xFF); +} + +static inline PinMode CY_PIN_MODE(int function) +{ + return (PinMode)((function >> 16) & 0x0F); +} + +static inline PinDirection CY_PIN_DIRECTION(int function) +{ + return (PinDirection)((function >> 20) & 1); +} + +static inline int CY_PERIPHERAL_BASE(int peripheral) +{ + return peripheral & 0xffff0000; +} + +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/PortNames.h b/targets/TARGET_Cypress/TARGET_PSOC6/PortNames.h new file mode 100644 index 0000000000..e30039df79 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/PortNames.h @@ -0,0 +1,47 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_PORTNAMES_H +#define MBED_PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +// Port[15-0] +typedef enum { + Port0 = 0x0, + Port1 = 0x1, + Port2 = 0x2, + Port3 = 0x3, + Port4 = 0x4, + Port5 = 0x5, + Port6 = 0x6, + Port7 = 0x7, + Port8 = 0x8, + Port9 = 0x9, + Port10 = 0xA, + Port11 = 0xB, + Port12 = 0xC, + Port13 = 0xD, + Port14 = 0xE +} PortName; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/PeripheralPins.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/PeripheralPins.c new file mode 100644 index 0000000000..0de9f5e995 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/PeripheralPins.c @@ -0,0 +1,364 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "PeripheralNames.h" +#include "PeripheralPins.h" +#include "pinmap.h" + +#if DEVICE_SERIAL +//*** SERIAL *** +const PinMap PinMap_UART_RX[] = { + {P0_2, UART_0, CY_PIN_IN_FUNCTION( P0_2_SCB0_UART_RX, PCLK_SCB0_CLOCK)}, + {P1_0, UART_7, CY_PIN_IN_FUNCTION( P1_0_SCB7_UART_RX, PCLK_SCB7_CLOCK)}, + {P5_0, UART_5, CY_PIN_IN_FUNCTION( P5_0_SCB5_UART_RX, PCLK_SCB5_CLOCK)}, + {P6_0, UART_3, CY_PIN_IN_FUNCTION( P6_0_SCB3_UART_RX, PCLK_SCB3_CLOCK)}, + {P6_4, UART_6, CY_PIN_IN_FUNCTION( P6_4_SCB6_UART_RX, PCLK_SCB6_CLOCK)}, + {P7_0, UART_4, CY_PIN_IN_FUNCTION( P7_0_SCB4_UART_RX, PCLK_SCB4_CLOCK)}, + {P8_0, UART_4, CY_PIN_IN_FUNCTION( P8_0_SCB4_UART_RX, PCLK_SCB4_CLOCK)}, + {P9_0, UART_2, CY_PIN_IN_FUNCTION( P9_0_SCB2_UART_RX, PCLK_SCB2_CLOCK)}, + {P10_0, UART_1, CY_PIN_IN_FUNCTION( P10_0_SCB1_UART_RX, PCLK_SCB1_CLOCK)}, + {P11_0, UART_5, CY_PIN_IN_FUNCTION( P11_0_SCB5_UART_RX, PCLK_SCB5_CLOCK)}, + {P12_0, UART_6, CY_PIN_IN_FUNCTION( P12_0_SCB6_UART_RX, PCLK_SCB6_CLOCK)}, + {P13_0, UART_6, CY_PIN_IN_FUNCTION( P13_0_SCB6_UART_RX, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_UART_TX[] = { + {P0_3, UART_0, CY_PIN_OUT_FUNCTION( P0_3_SCB0_UART_TX, PCLK_SCB0_CLOCK)}, + {P1_1, UART_7, CY_PIN_OUT_FUNCTION( P1_1_SCB7_UART_TX, PCLK_SCB7_CLOCK)}, + {P5_1, UART_5, CY_PIN_OUT_FUNCTION( P5_1_SCB5_UART_TX, PCLK_SCB5_CLOCK)}, + {P6_1, UART_3, CY_PIN_OUT_FUNCTION( P6_1_SCB3_UART_TX, PCLK_SCB3_CLOCK)}, + {P6_5, UART_6, CY_PIN_OUT_FUNCTION( P6_5_SCB6_UART_TX, PCLK_SCB6_CLOCK)}, + {P7_1, UART_4, CY_PIN_OUT_FUNCTION( P7_1_SCB4_UART_TX, PCLK_SCB4_CLOCK)}, + {P8_1, UART_4, CY_PIN_OUT_FUNCTION( P8_1_SCB4_UART_TX, PCLK_SCB4_CLOCK)}, + {P9_1, UART_2, CY_PIN_OUT_FUNCTION( P9_1_SCB2_UART_TX, PCLK_SCB2_CLOCK)}, + {P10_1, UART_1, CY_PIN_OUT_FUNCTION( P10_1_SCB1_UART_TX, PCLK_SCB1_CLOCK)}, + {P11_1, UART_5, CY_PIN_OUT_FUNCTION( P11_1_SCB5_UART_TX, PCLK_SCB5_CLOCK)}, + {P12_1, UART_6, CY_PIN_OUT_FUNCTION( P12_1_SCB6_UART_TX, PCLK_SCB6_CLOCK)}, + {P13_1, UART_6, CY_PIN_OUT_FUNCTION( P13_1_SCB6_UART_TX, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_UART_RTS[] = { + {P0_4, UART_0, CY_PIN_OUT_FUNCTION( P0_4_SCB0_UART_RTS, PCLK_SCB0_CLOCK)}, + {P1_2, UART_7, CY_PIN_OUT_FUNCTION( P1_2_SCB7_UART_RTS, PCLK_SCB7_CLOCK)}, + {P5_2, UART_5, CY_PIN_OUT_FUNCTION( P5_2_SCB5_UART_RTS, PCLK_SCB5_CLOCK)}, + {P6_2, UART_3, CY_PIN_OUT_FUNCTION( P6_2_SCB3_UART_RTS, PCLK_SCB3_CLOCK)}, + {P6_6, UART_6, CY_PIN_OUT_FUNCTION( P6_6_SCB6_UART_RTS, PCLK_SCB6_CLOCK)}, + {P7_2, UART_4, CY_PIN_OUT_FUNCTION( P7_2_SCB4_UART_RTS, PCLK_SCB4_CLOCK)}, + {P8_2, UART_4, CY_PIN_OUT_FUNCTION( P8_2_SCB4_UART_RTS, PCLK_SCB4_CLOCK)}, + {P9_2, UART_2, CY_PIN_OUT_FUNCTION( P9_2_SCB2_UART_RTS, PCLK_SCB2_CLOCK)}, + {P10_2, UART_1, CY_PIN_OUT_FUNCTION( P10_2_SCB1_UART_RTS, PCLK_SCB1_CLOCK)}, + {P11_2, UART_5, CY_PIN_OUT_FUNCTION( P11_2_SCB5_UART_RTS, PCLK_SCB5_CLOCK)}, + {P12_2, UART_6, CY_PIN_OUT_FUNCTION( P12_2_SCB6_UART_RTS, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_UART_CTS[] = { + {P0_5, UART_0, CY_PIN_IN_FUNCTION( P0_5_SCB0_UART_CTS, PCLK_SCB0_CLOCK)}, + {P1_3, UART_7, CY_PIN_IN_FUNCTION( P1_3_SCB7_UART_CTS, PCLK_SCB7_CLOCK)}, + {P5_3, UART_5, CY_PIN_IN_FUNCTION( P5_3_SCB5_UART_CTS, PCLK_SCB5_CLOCK)}, + {P6_3, UART_3, CY_PIN_IN_FUNCTION( P6_3_SCB3_UART_CTS, PCLK_SCB3_CLOCK)}, + {P6_7, UART_6, CY_PIN_IN_FUNCTION( P6_7_SCB6_UART_CTS, PCLK_SCB6_CLOCK)}, + {P7_3, UART_4, CY_PIN_IN_FUNCTION( P7_3_SCB4_UART_CTS, PCLK_SCB4_CLOCK)}, + {P8_3, UART_4, CY_PIN_IN_FUNCTION( P8_3_SCB4_UART_CTS, PCLK_SCB4_CLOCK)}, + {P9_3, UART_2, CY_PIN_IN_FUNCTION( P9_3_SCB2_UART_CTS, PCLK_SCB2_CLOCK)}, + {P10_3, UART_1, CY_PIN_IN_FUNCTION( P10_3_SCB1_UART_CTS, PCLK_SCB1_CLOCK)}, + {P11_3, UART_5, CY_PIN_IN_FUNCTION( P11_3_SCB5_UART_CTS, PCLK_SCB5_CLOCK)}, + {P12_3, UART_6, CY_PIN_IN_FUNCTION( P12_3_SCB6_UART_CTS, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +#endif // DEVICE_SERIAL + + +#if DEVICE_I2C +//*** I2C *** +const PinMap PinMap_I2C_SCL[] = { + {P0_2, I2C_0, CY_PIN_OD_FUNCTION( P0_2_SCB0_I2C_SCL, PCLK_SCB0_CLOCK)}, + {P1_0, I2C_7, CY_PIN_OD_FUNCTION( P1_0_SCB7_I2C_SCL, PCLK_SCB7_CLOCK)}, + {P5_0, I2C_5, CY_PIN_OD_FUNCTION( P5_0_SCB5_I2C_SCL, PCLK_SCB5_CLOCK)}, + {P6_0, I2C_3, CY_PIN_OD_FUNCTION( P6_0_SCB3_I2C_SCL, PCLK_SCB3_CLOCK)}, + {P6_4, I2C_6, CY_PIN_OD_FUNCTION( P6_4_SCB6_I2C_SCL, PCLK_SCB6_CLOCK)}, + {P7_0, I2C_4, CY_PIN_OD_FUNCTION( P7_0_SCB4_I2C_SCL, PCLK_SCB4_CLOCK)}, + {P8_0, I2C_4, CY_PIN_OD_FUNCTION( P8_0_SCB4_I2C_SCL, PCLK_SCB4_CLOCK)}, + {P9_0, I2C_2, CY_PIN_OD_FUNCTION( P9_0_SCB2_I2C_SCL, PCLK_SCB2_CLOCK)}, + {P10_0, I2C_1, CY_PIN_OD_FUNCTION( P10_0_SCB1_I2C_SCL, PCLK_SCB1_CLOCK)}, + {P11_0, I2C_5, CY_PIN_OD_FUNCTION( P11_0_SCB5_I2C_SCL, PCLK_SCB5_CLOCK)}, + {P12_0, I2C_6, CY_PIN_OD_FUNCTION( P12_0_SCB6_I2C_SCL, PCLK_SCB6_CLOCK)}, + {P13_0, I2C_6, CY_PIN_OD_FUNCTION( P13_0_SCB6_I2C_SCL, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_I2C_SDA[] = { + {P0_3, I2C_0, CY_PIN_OD_FUNCTION( P0_3_SCB0_I2C_SDA, PCLK_SCB0_CLOCK)}, + {P1_1, I2C_7, CY_PIN_OD_FUNCTION( P1_1_SCB7_I2C_SDA, PCLK_SCB7_CLOCK)}, + {P5_1, I2C_5, CY_PIN_OD_FUNCTION( P5_1_SCB5_I2C_SDA, PCLK_SCB5_CLOCK)}, + {P6_1, I2C_3, CY_PIN_OD_FUNCTION( P6_1_SCB3_I2C_SDA, PCLK_SCB3_CLOCK)}, + {P6_5, I2C_6, CY_PIN_OD_FUNCTION( P6_5_SCB6_I2C_SDA, PCLK_SCB6_CLOCK)}, + {P7_1, I2C_4, CY_PIN_OD_FUNCTION( P7_1_SCB4_I2C_SDA, PCLK_SCB4_CLOCK)}, + {P8_1, I2C_4, CY_PIN_OD_FUNCTION( P8_1_SCB4_I2C_SDA, PCLK_SCB4_CLOCK)}, + {P9_1, I2C_2, CY_PIN_OD_FUNCTION( P9_1_SCB2_I2C_SDA, PCLK_SCB2_CLOCK)}, + {P10_1, I2C_1, CY_PIN_OD_FUNCTION( P10_1_SCB1_I2C_SDA, PCLK_SCB1_CLOCK)}, + {P11_1, I2C_5, CY_PIN_OD_FUNCTION( P11_1_SCB5_I2C_SDA, PCLK_SCB5_CLOCK)}, + {P12_1, I2C_6, CY_PIN_OD_FUNCTION( P12_1_SCB6_I2C_SDA, PCLK_SCB6_CLOCK)}, + {P13_1, I2C_6, CY_PIN_OD_FUNCTION( P13_1_SCB6_I2C_SDA, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +#endif // DEVICE_I2C + +#if DEVICE_SPI +//*** SPI *** +const PinMap PinMap_SPI_MOSI[] = { + {P0_2, SPI_0, CY_PIN_OUT_FUNCTION( P0_2_SCB0_SPI_MOSI, PCLK_SCB0_CLOCK)}, + {P1_0, SPI_7, CY_PIN_OUT_FUNCTION( P1_0_SCB7_SPI_MOSI, PCLK_SCB7_CLOCK)}, + {P5_0, SPI_5, CY_PIN_OUT_FUNCTION( P5_0_SCB5_SPI_MOSI, PCLK_SCB5_CLOCK)}, + {P6_0, SPI_3, CY_PIN_OUT_FUNCTION( P6_0_SCB3_SPI_MOSI, PCLK_SCB3_CLOCK)}, + {P6_4, SPI_6, CY_PIN_OUT_FUNCTION( P6_4_SCB6_SPI_MOSI, PCLK_SCB6_CLOCK)}, + {P7_0, SPI_4, CY_PIN_OUT_FUNCTION( P7_0_SCB4_SPI_MOSI, PCLK_SCB4_CLOCK)}, + {P8_0, SPI_4, CY_PIN_OUT_FUNCTION( P8_0_SCB4_SPI_MOSI, PCLK_SCB4_CLOCK)}, + {P9_0, SPI_2, CY_PIN_OUT_FUNCTION( P9_0_SCB2_SPI_MOSI, PCLK_SCB2_CLOCK)}, + {P10_0, SPI_1, CY_PIN_OUT_FUNCTION( P10_0_SCB1_SPI_MOSI, PCLK_SCB1_CLOCK)}, + {P11_0, SPI_5, CY_PIN_OUT_FUNCTION( P11_0_SCB5_SPI_MOSI, PCLK_SCB5_CLOCK)}, + {P12_0, SPI_6, CY_PIN_OUT_FUNCTION( P12_0_SCB6_SPI_MOSI, PCLK_SCB6_CLOCK)}, + {P13_0, SPI_6, CY_PIN_OUT_FUNCTION( P13_0_SCB6_SPI_MOSI, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_SPI_MISO[] = { + {P0_3, SPI_0, CY_PIN_IN_FUNCTION( P0_3_SCB0_SPI_MISO, PCLK_SCB0_CLOCK)}, + {P1_1, SPI_7, CY_PIN_IN_FUNCTION( P1_1_SCB7_SPI_MISO, PCLK_SCB7_CLOCK)}, + {P5_1, SPI_5, CY_PIN_IN_FUNCTION( P5_1_SCB5_SPI_MISO, PCLK_SCB5_CLOCK)}, + {P6_1, SPI_3, CY_PIN_IN_FUNCTION( P6_1_SCB3_SPI_MISO, PCLK_SCB3_CLOCK)}, + {P6_5, SPI_6, CY_PIN_IN_FUNCTION( P6_5_SCB6_SPI_MISO, PCLK_SCB6_CLOCK)}, + {P7_1, SPI_4, CY_PIN_IN_FUNCTION( P7_1_SCB4_SPI_MISO, PCLK_SCB4_CLOCK)}, + {P8_1, SPI_4, CY_PIN_IN_FUNCTION( P8_1_SCB4_SPI_MISO, PCLK_SCB4_CLOCK)}, + {P9_1, SPI_2, CY_PIN_IN_FUNCTION( P9_1_SCB2_SPI_MISO, PCLK_SCB2_CLOCK)}, + {P10_1, SPI_1, CY_PIN_IN_FUNCTION( P10_1_SCB1_SPI_MISO, PCLK_SCB1_CLOCK)}, + {P11_1, SPI_5, CY_PIN_IN_FUNCTION( P11_1_SCB5_SPI_MISO, PCLK_SCB5_CLOCK)}, + {P12_1, SPI_6, CY_PIN_IN_FUNCTION( P12_1_SCB6_SPI_MISO, PCLK_SCB6_CLOCK)}, + {P13_1, SPI_6, CY_PIN_IN_FUNCTION( P13_1_SCB6_SPI_MISO, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_SPI_SCLK[] = { + {P0_4, SPI_0, CY_PIN_OUT_FUNCTION( P0_4_SCB0_SPI_CLK, PCLK_SCB0_CLOCK)}, + {P1_2, SPI_7, CY_PIN_OUT_FUNCTION( P1_2_SCB7_SPI_CLK, PCLK_SCB7_CLOCK)}, + {P5_2, SPI_5, CY_PIN_OUT_FUNCTION( P5_2_SCB5_SPI_CLK, PCLK_SCB5_CLOCK)}, + {P6_2, SPI_3, CY_PIN_OUT_FUNCTION( P6_2_SCB3_SPI_CLK, PCLK_SCB3_CLOCK)}, + {P6_6, SPI_6, CY_PIN_OUT_FUNCTION( P6_6_SCB6_SPI_CLK, PCLK_SCB6_CLOCK)}, + {P7_2, SPI_4, CY_PIN_OUT_FUNCTION( P7_2_SCB4_SPI_CLK, PCLK_SCB4_CLOCK)}, + + {P8_2, SPI_4, CY_PIN_OUT_FUNCTION( P8_2_SCB4_SPI_CLK, PCLK_SCB4_CLOCK)}, + {P9_2, SPI_2, CY_PIN_OUT_FUNCTION( P9_2_SCB2_SPI_CLK, PCLK_SCB2_CLOCK)}, + {P10_2, SPI_1, CY_PIN_OUT_FUNCTION( P10_2_SCB1_SPI_CLK, PCLK_SCB1_CLOCK)}, + {P11_2, SPI_5, CY_PIN_OUT_FUNCTION( P11_2_SCB5_SPI_CLK, PCLK_SCB5_CLOCK)}, + {P12_2, SPI_6, CY_PIN_OUT_FUNCTION( P12_2_SCB6_SPI_CLK, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +const PinMap PinMap_SPI_SSEL[] = { + {P0_5, SPI_0, CY_PIN_OUT_FUNCTION( P0_5_SCB0_SPI_SELECT0, PCLK_SCB0_CLOCK)}, + {P1_3, SPI_7, CY_PIN_OUT_FUNCTION( P1_3_SCB7_SPI_SELECT0, PCLK_SCB7_CLOCK)}, + {P5_3, SPI_5, CY_PIN_OUT_FUNCTION( P5_3_SCB5_SPI_SELECT0, PCLK_SCB5_CLOCK)}, + {P6_3, SPI_3, CY_PIN_OUT_FUNCTION( P6_3_SCB3_SPI_SELECT0, PCLK_SCB3_CLOCK)}, + {P6_7, SPI_6, CY_PIN_OUT_FUNCTION( P6_7_SCB6_SPI_SELECT0, PCLK_SCB6_CLOCK)}, + {P7_3, SPI_4, CY_PIN_OUT_FUNCTION( P7_3_SCB4_SPI_SELECT0, PCLK_SCB4_CLOCK)}, + {P8_3, SPI_4, CY_PIN_OUT_FUNCTION( P8_3_SCB4_SPI_SELECT0, PCLK_SCB4_CLOCK)}, + {P9_3, SPI_2, CY_PIN_OUT_FUNCTION( P9_3_SCB2_SPI_SELECT0, PCLK_SCB2_CLOCK)}, + {P10_3, SPI_1, CY_PIN_OUT_FUNCTION( P10_3_SCB1_SPI_SELECT0, PCLK_SCB1_CLOCK)}, + {P11_3, SPI_5, CY_PIN_OUT_FUNCTION( P11_3_SCB5_SPI_SELECT0, PCLK_SCB5_CLOCK)}, + {P12_3, SPI_6, CY_PIN_OUT_FUNCTION( P12_3_SCB6_SPI_SELECT0, PCLK_SCB6_CLOCK)}, + {NC, NC, 0} +}; +#endif // DEVICE_SPI + +#if DEVICE_PWMOUT +//*** PWM *** +const PinMap PinMap_PWM_OUT[] = { + // 16-bit PWM outputs + {P0_0, PWM_16b_0, CY_PIN_OUT_FUNCTION(P0_0_TCPWM1_LINE0, PCLK_TCPWM1_CLOCKS0)}, + {P0_2, PWM_16b_1, CY_PIN_OUT_FUNCTION(P0_2_TCPWM1_LINE1, PCLK_TCPWM1_CLOCKS1)}, + {P0_4, PWM_16b_2, CY_PIN_OUT_FUNCTION(P0_4_TCPWM1_LINE2, PCLK_TCPWM1_CLOCKS2)}, + {P1_0, PWM_16b_3, CY_PIN_OUT_FUNCTION(P1_0_TCPWM1_LINE3, PCLK_TCPWM1_CLOCKS3)}, + {P1_2, PWM_16b_12, CY_PIN_OUT_FUNCTION(P1_2_TCPWM1_LINE12, PCLK_TCPWM1_CLOCKS12)}, + {P1_4, PWM_16b_13, CY_PIN_OUT_FUNCTION(P1_4_TCPWM1_LINE13, PCLK_TCPWM1_CLOCKS13)}, + {P5_0, PWM_16b_4, CY_PIN_OUT_FUNCTION(P5_0_TCPWM1_LINE4, PCLK_TCPWM1_CLOCKS4)}, + {P5_2, PWM_16b_5, CY_PIN_OUT_FUNCTION(P5_2_TCPWM1_LINE5, PCLK_TCPWM1_CLOCKS5)}, + {P5_4, PWM_16b_6, CY_PIN_OUT_FUNCTION(P5_4_TCPWM1_LINE6, PCLK_TCPWM1_CLOCKS6)}, + {P5_6, PWM_16b_7, CY_PIN_OUT_FUNCTION(P5_6_TCPWM1_LINE7, PCLK_TCPWM1_CLOCKS7)}, + {P6_0, PWM_16b_8, CY_PIN_OUT_FUNCTION(P6_0_TCPWM1_LINE8, PCLK_TCPWM1_CLOCKS8)}, + {P6_2, PWM_16b_9, CY_PIN_OUT_FUNCTION(P6_2_TCPWM1_LINE9, PCLK_TCPWM1_CLOCKS9)}, + {P6_4, PWM_16b_10, CY_PIN_OUT_FUNCTION(P6_4_TCPWM1_LINE10, PCLK_TCPWM1_CLOCKS10)}, + {P6_6, PWM_16b_11, CY_PIN_OUT_FUNCTION(P6_6_TCPWM1_LINE11, PCLK_TCPWM1_CLOCKS11)}, + {P7_0, PWM_16b_12, CY_PIN_OUT_FUNCTION(P7_0_TCPWM1_LINE12, PCLK_TCPWM1_CLOCKS12)}, + {P7_2, PWM_16b_13, CY_PIN_OUT_FUNCTION(P7_2_TCPWM1_LINE13, PCLK_TCPWM1_CLOCKS13)}, + {P7_4, PWM_16b_14, CY_PIN_OUT_FUNCTION(P7_4_TCPWM1_LINE14, PCLK_TCPWM1_CLOCKS14)}, + {P7_6, PWM_16b_15, CY_PIN_OUT_FUNCTION(P7_6_TCPWM1_LINE15, PCLK_TCPWM1_CLOCKS15)}, + {P8_0, PWM_16b_16, CY_PIN_OUT_FUNCTION(P8_0_TCPWM1_LINE16, PCLK_TCPWM1_CLOCKS16)}, + {P8_2, PWM_16b_17, CY_PIN_OUT_FUNCTION(P8_2_TCPWM1_LINE17, PCLK_TCPWM1_CLOCKS17)}, + {P8_4, PWM_16b_18, CY_PIN_OUT_FUNCTION(P8_4_TCPWM1_LINE18, PCLK_TCPWM1_CLOCKS18)}, + {P8_6, PWM_16b_19, CY_PIN_OUT_FUNCTION(P8_6_TCPWM1_LINE19, PCLK_TCPWM1_CLOCKS19)}, + {P9_0, PWM_16b_20, CY_PIN_OUT_FUNCTION(P9_0_TCPWM1_LINE20, PCLK_TCPWM1_CLOCKS20)}, + {P9_2, PWM_16b_21, CY_PIN_OUT_FUNCTION(P9_2_TCPWM1_LINE21, PCLK_TCPWM1_CLOCKS21)}, + {P9_4, PWM_16b_0, CY_PIN_OUT_FUNCTION(P9_4_TCPWM1_LINE0, PCLK_TCPWM1_CLOCKS0)}, + {P9_6, PWM_16b_1, CY_PIN_OUT_FUNCTION(P9_6_TCPWM1_LINE1, PCLK_TCPWM1_CLOCKS1)}, + {P10_0, PWM_16b_22, CY_PIN_OUT_FUNCTION(P10_0_TCPWM1_LINE22, PCLK_TCPWM1_CLOCKS22)}, + {P10_2, PWM_16b_23, CY_PIN_OUT_FUNCTION(P10_2_TCPWM1_LINE23, PCLK_TCPWM1_CLOCKS23)}, + {P10_4, PWM_16b_0, CY_PIN_OUT_FUNCTION(P10_4_TCPWM1_LINE0, PCLK_TCPWM1_CLOCKS0)}, + {P10_6, PWM_16b_2, CY_PIN_OUT_FUNCTION(P10_6_TCPWM1_LINE2, PCLK_TCPWM1_CLOCKS2)}, + {P11_0, PWM_16b_1, CY_PIN_OUT_FUNCTION(P11_0_TCPWM1_LINE1, PCLK_TCPWM1_CLOCKS1)}, + {P11_2, PWM_16b_2, CY_PIN_OUT_FUNCTION(P11_2_TCPWM1_LINE2, PCLK_TCPWM1_CLOCKS2)}, + {P11_4, PWM_16b_3, CY_PIN_OUT_FUNCTION(P11_4_TCPWM1_LINE3, PCLK_TCPWM1_CLOCKS3)}, + {P12_0, PWM_16b_4, CY_PIN_OUT_FUNCTION(P12_0_TCPWM1_LINE4, PCLK_TCPWM1_CLOCKS4)}, + {P12_2, PWM_16b_5, CY_PIN_OUT_FUNCTION(P12_2_TCPWM1_LINE5, PCLK_TCPWM1_CLOCKS5)}, + {P12_4, PWM_16b_6, CY_PIN_OUT_FUNCTION(P12_4_TCPWM1_LINE6, PCLK_TCPWM1_CLOCKS6)}, + {P12_6, PWM_16b_7, CY_PIN_OUT_FUNCTION(P12_6_TCPWM1_LINE7, PCLK_TCPWM1_CLOCKS7)}, + {P13_0, PWM_16b_8, CY_PIN_OUT_FUNCTION(P13_0_TCPWM1_LINE8, PCLK_TCPWM1_CLOCKS8)}, + {P13_6, PWM_16b_11, CY_PIN_OUT_FUNCTION(P13_6_TCPWM1_LINE11, PCLK_TCPWM1_CLOCKS11)}, + // 16-bit PWM inverted outputs + {P0_1, PWM_16b_0, CY_PIN_OUT_FUNCTION(P0_1_TCPWM1_LINE_COMPL0, PCLK_TCPWM1_CLOCKS0)}, + {P0_3, PWM_16b_1, CY_PIN_OUT_FUNCTION(P0_3_TCPWM1_LINE_COMPL1, PCLK_TCPWM1_CLOCKS1)}, + {P0_5, PWM_16b_2, CY_PIN_OUT_FUNCTION(P0_5_TCPWM1_LINE_COMPL2, PCLK_TCPWM1_CLOCKS2)}, + {P1_1, PWM_16b_3, CY_PIN_OUT_FUNCTION(P1_1_TCPWM1_LINE_COMPL3, PCLK_TCPWM1_CLOCKS3)}, + {P1_3, PWM_16b_12, CY_PIN_OUT_FUNCTION(P1_3_TCPWM1_LINE_COMPL12, PCLK_TCPWM1_CLOCKS12)}, + {P1_5, PWM_16b_14, CY_PIN_OUT_FUNCTION(P1_5_TCPWM1_LINE_COMPL14, PCLK_TCPWM1_CLOCKS14)}, + {P5_1, PWM_16b_4, CY_PIN_OUT_FUNCTION(P5_1_TCPWM1_LINE_COMPL4, PCLK_TCPWM1_CLOCKS4)}, + {P5_3, PWM_16b_5, CY_PIN_OUT_FUNCTION(P5_3_TCPWM1_LINE_COMPL5, PCLK_TCPWM1_CLOCKS5)}, + {P5_5, PWM_16b_6, CY_PIN_OUT_FUNCTION(P5_5_TCPWM1_LINE_COMPL6, PCLK_TCPWM1_CLOCKS6)}, + {P6_1, PWM_16b_8, CY_PIN_OUT_FUNCTION(P6_1_TCPWM1_LINE_COMPL8, PCLK_TCPWM1_CLOCKS8)}, + {P6_3, PWM_16b_9, CY_PIN_OUT_FUNCTION(P6_3_TCPWM1_LINE_COMPL9, PCLK_TCPWM1_CLOCKS9)}, + {P6_5, PWM_16b_10, CY_PIN_OUT_FUNCTION(P6_5_TCPWM1_LINE_COMPL10, PCLK_TCPWM1_CLOCKS10)}, + {P6_7, PWM_16b_11, CY_PIN_OUT_FUNCTION(P6_7_TCPWM1_LINE_COMPL11, PCLK_TCPWM1_CLOCKS11)}, + {P7_1, PWM_16b_12, CY_PIN_OUT_FUNCTION(P7_1_TCPWM1_LINE_COMPL12, PCLK_TCPWM1_CLOCKS12)}, + {P7_3, PWM_16b_13, CY_PIN_OUT_FUNCTION(P7_3_TCPWM1_LINE_COMPL13, PCLK_TCPWM1_CLOCKS13)}, + {P7_5, PWM_16b_14, CY_PIN_OUT_FUNCTION(P7_5_TCPWM1_LINE_COMPL14, PCLK_TCPWM1_CLOCKS14)}, + {P7_7, PWM_16b_15, CY_PIN_OUT_FUNCTION(P7_7_TCPWM1_LINE_COMPL15, PCLK_TCPWM1_CLOCKS15)}, + {P8_1, PWM_16b_16, CY_PIN_OUT_FUNCTION(P8_1_TCPWM1_LINE_COMPL16, PCLK_TCPWM1_CLOCKS16)}, + {P8_3, PWM_16b_17, CY_PIN_OUT_FUNCTION(P8_3_TCPWM1_LINE_COMPL17, PCLK_TCPWM1_CLOCKS17)}, + {P8_5, PWM_16b_18, CY_PIN_OUT_FUNCTION(P8_5_TCPWM1_LINE_COMPL18, PCLK_TCPWM1_CLOCKS18)}, + {P8_7, PWM_16b_19, CY_PIN_OUT_FUNCTION(P8_7_TCPWM1_LINE_COMPL19, PCLK_TCPWM1_CLOCKS19)}, + {P9_1, PWM_16b_20, CY_PIN_OUT_FUNCTION(P9_1_TCPWM1_LINE_COMPL20, PCLK_TCPWM1_CLOCKS20)}, + {P9_3, PWM_16b_21, CY_PIN_OUT_FUNCTION(P9_3_TCPWM1_LINE_COMPL21, PCLK_TCPWM1_CLOCKS21)}, + {P9_5, PWM_16b_0, CY_PIN_OUT_FUNCTION(P9_5_TCPWM1_LINE_COMPL0, PCLK_TCPWM1_CLOCKS0)}, + {P9_7, PWM_16b_1, CY_PIN_OUT_FUNCTION(P9_7_TCPWM1_LINE_COMPL1, PCLK_TCPWM1_CLOCKS1)}, + {P10_1, PWM_16b_22, CY_PIN_OUT_FUNCTION(P10_1_TCPWM1_LINE_COMPL22, PCLK_TCPWM1_CLOCKS22)}, + {P10_3, PWM_16b_23, CY_PIN_OUT_FUNCTION(P10_3_TCPWM1_LINE_COMPL23, PCLK_TCPWM1_CLOCKS23)}, + {P10_5, PWM_16b_0, CY_PIN_OUT_FUNCTION(P10_5_TCPWM1_LINE_COMPL0, PCLK_TCPWM1_CLOCKS0)}, + {P11_1, PWM_16b_1, CY_PIN_OUT_FUNCTION(P11_1_TCPWM1_LINE_COMPL1, PCLK_TCPWM1_CLOCKS1)}, + {P11_3, PWM_16b_2, CY_PIN_OUT_FUNCTION(P11_3_TCPWM1_LINE_COMPL2, PCLK_TCPWM1_CLOCKS2)}, + {P11_5, PWM_16b_3, CY_PIN_OUT_FUNCTION(P11_5_TCPWM1_LINE_COMPL3, PCLK_TCPWM1_CLOCKS3)}, + {P12_1, PWM_16b_4, CY_PIN_OUT_FUNCTION(P12_1_TCPWM1_LINE_COMPL4, PCLK_TCPWM1_CLOCKS4)}, + {P12_3, PWM_16b_5, CY_PIN_OUT_FUNCTION(P12_3_TCPWM1_LINE_COMPL5, PCLK_TCPWM1_CLOCKS5)}, + {P12_5, PWM_16b_6, CY_PIN_OUT_FUNCTION(P12_5_TCPWM1_LINE_COMPL6, PCLK_TCPWM1_CLOCKS6)}, + {P12_7, PWM_16b_7, CY_PIN_OUT_FUNCTION(P12_7_TCPWM1_LINE_COMPL7, PCLK_TCPWM1_CLOCKS7)}, + {P13_1, PWM_16b_8, CY_PIN_OUT_FUNCTION(P13_1_TCPWM1_LINE_COMPL8, PCLK_TCPWM1_CLOCKS8)}, + {P13_7, PWM_16b_11, CY_PIN_OUT_FUNCTION(P13_7_TCPWM1_LINE_COMPL11, PCLK_TCPWM1_CLOCKS11)}, + // 32-bit PWM outputs + {PWM32(P0_0), PWM_32b_0, CY_PIN_OUT_FUNCTION(P0_0_TCPWM0_LINE0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P0_2), PWM_32b_1, CY_PIN_OUT_FUNCTION(P0_2_TCPWM0_LINE1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P0_4), PWM_32b_2, CY_PIN_OUT_FUNCTION(P0_4_TCPWM0_LINE2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P1_0), PWM_32b_3, CY_PIN_OUT_FUNCTION(P1_0_TCPWM0_LINE3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P1_2), PWM_32b_4, CY_PIN_OUT_FUNCTION(P1_2_TCPWM0_LINE4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P1_4), PWM_32b_5, CY_PIN_OUT_FUNCTION(P1_4_TCPWM0_LINE5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P5_0), PWM_32b_4, CY_PIN_OUT_FUNCTION(P5_0_TCPWM0_LINE4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P5_2), PWM_32b_5, CY_PIN_OUT_FUNCTION(P5_2_TCPWM0_LINE5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P5_4), PWM_32b_6, CY_PIN_OUT_FUNCTION(P5_4_TCPWM0_LINE6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P5_6), PWM_32b_7, CY_PIN_OUT_FUNCTION(P5_6_TCPWM0_LINE7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P6_0), PWM_32b_0, CY_PIN_OUT_FUNCTION(P6_0_TCPWM0_LINE0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P6_2), PWM_32b_1, CY_PIN_OUT_FUNCTION(P6_2_TCPWM0_LINE1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P6_4), PWM_32b_2, CY_PIN_OUT_FUNCTION(P6_4_TCPWM0_LINE2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P6_6), PWM_32b_3, CY_PIN_OUT_FUNCTION(P6_6_TCPWM0_LINE3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P7_0), PWM_32b_4, CY_PIN_OUT_FUNCTION(P7_0_TCPWM0_LINE4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P7_2), PWM_32b_5, CY_PIN_OUT_FUNCTION(P7_2_TCPWM0_LINE5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P7_4), PWM_32b_6, CY_PIN_OUT_FUNCTION(P7_4_TCPWM0_LINE6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P7_6), PWM_32b_7, CY_PIN_OUT_FUNCTION(P7_6_TCPWM0_LINE7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P8_0), PWM_32b_0, CY_PIN_OUT_FUNCTION(P8_0_TCPWM0_LINE0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P8_2), PWM_32b_1, CY_PIN_OUT_FUNCTION(P8_2_TCPWM0_LINE1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P8_4), PWM_32b_2, CY_PIN_OUT_FUNCTION(P8_4_TCPWM0_LINE2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P8_6), PWM_32b_3, CY_PIN_OUT_FUNCTION(P8_6_TCPWM0_LINE3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P9_0), PWM_32b_4, CY_PIN_OUT_FUNCTION(P9_0_TCPWM0_LINE4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P9_2), PWM_32b_5, CY_PIN_OUT_FUNCTION(P9_2_TCPWM0_LINE5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P9_4), PWM_32b_7, CY_PIN_OUT_FUNCTION(P9_4_TCPWM0_LINE7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P9_6), PWM_32b_0, CY_PIN_OUT_FUNCTION(P9_6_TCPWM0_LINE0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P10_0), PWM_32b_6, CY_PIN_OUT_FUNCTION(P10_0_TCPWM0_LINE6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P10_2), PWM_32b_7, CY_PIN_OUT_FUNCTION(P10_2_TCPWM0_LINE7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P10_4), PWM_32b_0, CY_PIN_OUT_FUNCTION(P10_4_TCPWM0_LINE0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P10_6), PWM_32b_1, CY_PIN_OUT_FUNCTION(P10_6_TCPWM0_LINE1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P11_0), PWM_32b_1, CY_PIN_OUT_FUNCTION(P11_0_TCPWM0_LINE1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P11_2), PWM_32b_2, CY_PIN_OUT_FUNCTION(P11_2_TCPWM0_LINE2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P11_4), PWM_32b_3, CY_PIN_OUT_FUNCTION(P11_4_TCPWM0_LINE3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P12_0), PWM_32b_4, CY_PIN_OUT_FUNCTION(P12_0_TCPWM0_LINE4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P12_2), PWM_32b_5, CY_PIN_OUT_FUNCTION(P12_2_TCPWM0_LINE5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P12_4), PWM_32b_6, CY_PIN_OUT_FUNCTION(P12_4_TCPWM0_LINE6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P12_6), PWM_32b_7, CY_PIN_OUT_FUNCTION(P12_6_TCPWM0_LINE7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P13_0), PWM_32b_0, CY_PIN_OUT_FUNCTION(P13_0_TCPWM0_LINE0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P13_6), PWM_32b_3, CY_PIN_OUT_FUNCTION(P13_6_TCPWM0_LINE3, PCLK_TCPWM0_CLOCKS3)}, + // 32-bit PWM inverted outputs + {PWM32(P0_1), PWM_32b_0, CY_PIN_OUT_FUNCTION(P0_1_TCPWM0_LINE_COMPL0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P0_3), PWM_32b_1, CY_PIN_OUT_FUNCTION(P0_3_TCPWM0_LINE_COMPL1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P0_5), PWM_32b_2, CY_PIN_OUT_FUNCTION(P0_5_TCPWM0_LINE_COMPL2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P1_1), PWM_32b_3, CY_PIN_OUT_FUNCTION(P1_1_TCPWM0_LINE_COMPL3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P1_3), PWM_32b_4, CY_PIN_OUT_FUNCTION(P1_3_TCPWM0_LINE_COMPL4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P1_5), PWM_32b_5, CY_PIN_OUT_FUNCTION(P1_5_TCPWM0_LINE_COMPL5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P5_1), PWM_32b_4, CY_PIN_OUT_FUNCTION(P5_1_TCPWM0_LINE_COMPL4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P5_3), PWM_32b_5, CY_PIN_OUT_FUNCTION(P5_3_TCPWM0_LINE_COMPL5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P5_5), PWM_32b_6, CY_PIN_OUT_FUNCTION(P5_5_TCPWM0_LINE_COMPL6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P6_1), PWM_32b_0, CY_PIN_OUT_FUNCTION(P6_1_TCPWM0_LINE_COMPL0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P6_3), PWM_32b_1, CY_PIN_OUT_FUNCTION(P6_3_TCPWM0_LINE_COMPL1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P6_5), PWM_32b_2, CY_PIN_OUT_FUNCTION(P6_5_TCPWM0_LINE_COMPL2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P6_7), PWM_32b_3, CY_PIN_OUT_FUNCTION(P6_7_TCPWM0_LINE_COMPL3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P7_1), PWM_32b_4, CY_PIN_OUT_FUNCTION(P7_1_TCPWM0_LINE_COMPL4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P7_3), PWM_32b_5, CY_PIN_OUT_FUNCTION(P7_3_TCPWM0_LINE_COMPL5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P7_5), PWM_32b_6, CY_PIN_OUT_FUNCTION(P7_5_TCPWM0_LINE_COMPL6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P7_7), PWM_32b_7, CY_PIN_OUT_FUNCTION(P7_7_TCPWM0_LINE_COMPL7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P8_1), PWM_32b_0, CY_PIN_OUT_FUNCTION(P8_1_TCPWM0_LINE_COMPL0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P8_3), PWM_32b_1, CY_PIN_OUT_FUNCTION(P8_3_TCPWM0_LINE_COMPL1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P8_5), PWM_32b_2, CY_PIN_OUT_FUNCTION(P8_5_TCPWM0_LINE_COMPL2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P8_7), PWM_32b_3, CY_PIN_OUT_FUNCTION(P8_7_TCPWM0_LINE_COMPL3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P9_1), PWM_32b_4, CY_PIN_OUT_FUNCTION(P9_1_TCPWM0_LINE_COMPL4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P9_3), PWM_32b_5, CY_PIN_OUT_FUNCTION(P9_3_TCPWM0_LINE_COMPL5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P9_5), PWM_32b_7, CY_PIN_OUT_FUNCTION(P9_5_TCPWM0_LINE_COMPL7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P9_7), PWM_32b_0, CY_PIN_OUT_FUNCTION(P9_7_TCPWM0_LINE_COMPL0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P10_1), PWM_32b_6, CY_PIN_OUT_FUNCTION(P10_1_TCPWM0_LINE_COMPL6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P10_3), PWM_32b_7, CY_PIN_OUT_FUNCTION(P10_3_TCPWM0_LINE_COMPL7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P10_5), PWM_32b_0, CY_PIN_OUT_FUNCTION(P10_5_TCPWM0_LINE_COMPL0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P11_1), PWM_32b_1, CY_PIN_OUT_FUNCTION(P11_1_TCPWM0_LINE_COMPL1, PCLK_TCPWM0_CLOCKS1)}, + {PWM32(P11_3), PWM_32b_2, CY_PIN_OUT_FUNCTION(P11_3_TCPWM0_LINE_COMPL2, PCLK_TCPWM0_CLOCKS2)}, + {PWM32(P11_5), PWM_32b_3, CY_PIN_OUT_FUNCTION(P11_5_TCPWM0_LINE_COMPL3, PCLK_TCPWM0_CLOCKS3)}, + {PWM32(P12_1), PWM_32b_4, CY_PIN_OUT_FUNCTION(P12_1_TCPWM0_LINE_COMPL4, PCLK_TCPWM0_CLOCKS4)}, + {PWM32(P12_3), PWM_32b_5, CY_PIN_OUT_FUNCTION(P12_3_TCPWM0_LINE_COMPL5, PCLK_TCPWM0_CLOCKS5)}, + {PWM32(P12_5), PWM_32b_6, CY_PIN_OUT_FUNCTION(P12_5_TCPWM0_LINE_COMPL6, PCLK_TCPWM0_CLOCKS6)}, + {PWM32(P12_7), PWM_32b_7, CY_PIN_OUT_FUNCTION(P12_7_TCPWM0_LINE_COMPL7, PCLK_TCPWM0_CLOCKS7)}, + {PWM32(P13_1), PWM_32b_0, CY_PIN_OUT_FUNCTION(P13_1_TCPWM0_LINE_COMPL0, PCLK_TCPWM0_CLOCKS0)}, + {PWM32(P13_7), PWM_32b_3, CY_PIN_OUT_FUNCTION(P13_7_TCPWM0_LINE_COMPL3, PCLK_TCPWM0_CLOCKS3)}, + {NC, NC, 0} +}; +#endif // DEVICE_PWMOUT + +#if DEVICE_ANALOGIN +const PinMap PinMap_ADC[] = { + {P10_0, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_1, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_2, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_3, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_4, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_5, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_6, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {P10_7, ADC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_SAR)}, + {NC, NC, 0} +}; +#endif // DEVICE_ANALOGIN + +#if DEVICE_ANALOGOUT +const PinMap PinMap_DAC[] = { + {P9_6, DAC_0, CY_PIN_ANALOG_FUNCTION(PCLK_PASS_CLOCK_CTDAC)}, + {NC, NC, 0} +}; +#endif // DEVICE_ANALOGIN diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/cy8c6xx7_cm0plus.sct b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/cy8c6xx7_cm0plus.sct new file mode 100644 index 0000000000..c8f7b9ce39 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/cy8c6xx7_cm0plus.sct @@ -0,0 +1,209 @@ +#! armcc -E +; The first line specifies a preprocessor command that the linker invokes +; to pass a scatter file through a C preprocessor. + +;******************************************************************************* +;* \file cy8c6xx7_cm0plus.scat +;* \version 2.10 +;* +;* Linker file for the ARMCC. +;* +;* The main purpose of the linker script is to describe how the sections in the +;* input files should be mapped into the output file, and to control the memory +;* layout of the output file. +;* +;* \note The entry point location is fixed and starts at 0x10000000. The valid +;* application image should be placed there. +;* +;* \note The linker files included with the PDL template projects must be +;* generic and handle all common use cases. Your project may not use every +;* section defined in the linker files. In that case you may see the warnings +;* during the build process: L6314W (no section matches pattern) and/or L6329W +;* (pattern only matches removed unused sections). In your project, you can +;* suppress the warning by passing the "--diag_suppress=L6314W,L6329W" option to +;* the linker, simply comment out or remove the relevant code in the linker +;* file. +;* +;******************************************************************************* +;* \copyright +;* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +;* You may use this file only in accordance with the license, terms, conditions, +;* disclaimers, and limitations in the end user license agreement accompanying +;* the software package with which this file was provided. +;******************************************************************************/ + +; The defines below describe the location and size of blocks of memory in the target. +; Use these defines to specify the memory regions available for allocation. + +; The following defines control RAM and flash memory allocation for the CM0+ core. +; You can change the memory allocation by editing the RAM and Flash defines. +; Your changes must be aligned with the corresponding defines for the CM4 core in 'xx_cm4_dual.scat', +; where 'xx' is the device group; for example, 'cy8c6xx7_cm4_dual.scat'. +; RAM +; RAM +#define RAM_START 0x08000000 +#define RAM_SIZE 0x00010000 +; Flash +; Flash +#define FLASH_START 0x10000000 +#define FLASH_SIZE 0x00078000 + +; The following defines describe a 32K flash region used for EEPROM emulation. +; This region can also be used as the general purpose flash. +; You can assign sections to this memory region for only one of the cores. +; Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region. +; Therefore, repurposing this memory region will prevent such middleware from operation. +#define EM_EEPROM_START 0x14000000 +#define EM_EEPROM_SIZE 0x8000 + +; The following defines describe device specific memory regions and must not be changed. +; Supervisory flash: User data +#define SFLASH_USER_DATA_START 0x16000800 +#define SFLASH_USER_DATA_SIZE 0x00000800 + +; Supervisory flash: Normal Access Restrictions (NAR) +#define SFLASH_NAR_START 0x16001A00 +#define SFLASH_NAR_SIZE 0x00000200 + +; Supervisory flash: Public Key +#define SFLASH_PUBLIC_KEY_START 0x16005A00 +#define SFLASH_PUBLIC_KEY_SIZE 0x00000C00 + +; Supervisory flash: Table of Content # 2 +#define SFLASH_TOC_2_START 0x16007C00 +#define SFLASH_TOC_2_SIZE 0x00000200 + +; Supervisory flash: Table of Content # 2 Copy +#define SFLASH_RTOC_2_START 0x16007E00 +#define SFLASH_RTOC_2_SIZE 0x00000200 + +; External memory +#define XIP_START 0x18000000 +#define XIP_SIZE 0x08000000 + +; eFuse +#define EFUSE_START 0x90700000 +#define EFUSE_SIZE 0x100000 + + +LR_IROM1 FLASH_START FLASH_SIZE +{ + .cy_app_header +0 + { + * (.cy_app_header) + } + + ER_FLASH_VECTORS +0 + { + * (RESET, +FIRST) + } + + ER_FLASH_CODE +0 FIXED + { + * (InRoot$$Sections) + * (+RO) + } + + ER_RAM_VECTORS RAM_START UNINIT + { + * (RESET_RAM, +FIRST) + } + + RW_RAM_DATA +0 + { + * (.cy_ramfunc) + .ANY (+RW, +ZI) + } + + ; Place variables in the section that should not be initialized during the + ; device startup. + RW_IRAM1 +0 UNINIT + { + * (.noinit) + } +} + + +; Emulated EEPROM Flash area +LR_EM_EEPROM EM_EEPROM_START EM_EEPROM_SIZE +{ + .cy_em_eeprom +0 + { + * (.cy_em_eeprom) + } +} + +; Supervisory flash: User data +LR_SFLASH_USER_DATA SFLASH_USER_DATA_START SFLASH_USER_DATA_SIZE +{ + .cy_sflash_user_data +0 + { + * (.cy_sflash_user_data) + } +} + +; Supervisory flash: Normal Access Restrictions (NAR) +LR_SFLASH_NAR SFLASH_NAR_START SFLASH_NAR_SIZE +{ + .cy_sflash_nar +0 + { + * (.cy_sflash_nar) + } +} + +; Supervisory flash: Public Key +LR_SFLASH_PUBLIC_KEY SFLASH_PUBLIC_KEY_START SFLASH_PUBLIC_KEY_SIZE +{ + .cy_sflash_public_key +0 + { + * (.cy_sflash_public_key) + } +} + +; Supervisory flash: Table of Content # 2 +LR_SFLASH_TOC_2 SFLASH_TOC_2_START SFLASH_TOC_2_SIZE +{ + .cy_toc_part2 +0 + { + * (.cy_toc_part2) + } +} + +; Supervisory flash: Table of Content # 2 Copy +LR_SFLASH_RTOC_2 SFLASH_RTOC_2_START SFLASH_RTOC_2_SIZE +{ + .cy_rtoc_part2 +0 + { + * (.cy_rtoc_part2) + } +} + + +; Places the code in the Execute in Place (XIP) section. See the smif driver documentation for details. +LR_EROM XIP_START XIP_SIZE +{ + .cy_xip +0 + { + * (.cy_xip) + } +} + + +; eFuse +LR_EFUSE EFUSE_START EFUSE_SIZE +{ + .cy_efuse +0 + { + * (.cy_efuse) + } +} + + +; The section is used for additional metadata (silicon revision, Silicon/JTAG ID, etc.) storage. +CYMETA 0x90500000 +{ + .cymeta +0 { * (.cymeta) } +} + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_ipc_cm0p.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_controller_ipc_cm0p.a similarity index 63% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_ipc_cm0p.a rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_controller_ipc_cm0p.a index 2a6e381d38..b0c8897b2f 100644 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_ipc_cm0p.a and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_controller_ipc_cm0p.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_uart_cm0p.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_controller_uart_cm0p.a similarity index 63% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_uart_cm0p.a rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_controller_uart_cm0p.a index b937fbd51d..e3cd51295d 100644 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_uart_cm0p.a and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_controller_uart_cm0p.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_radio_max_cm0p.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_radio_max_cm0p.a new file mode 100644 index 0000000000..e81e485fa2 Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_ble_stack_mdk_radio_max_cm0p.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_client_mdk.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_client_mdk.a new file mode 100644 index 0000000000..fcddb074cd Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_client_mdk.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_server_mdk_base.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_server_mdk_base.a new file mode 100644 index 0000000000..84ba700e4c Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_server_mdk_base.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_server_mdk_extra.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_server_mdk_extra.a new file mode 100644 index 0000000000..efa12e0d30 Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/libcy_crypto_server_mdk_extra.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/startup_psoc63_cm0plus.s b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/startup_psoc63_cm0plus.s new file mode 100644 index 0000000000..53ac4e4a1d --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_ARM_STD/startup_psoc63_cm0plus.s @@ -0,0 +1,279 @@ +;/**************************************************************************//** +; * @file startup_psoc63_cm0plus.s +; * @brief CMSIS Core Device Startup File for +; * ARMCM0plus Device Series +; * @version V5.00 +; * @date 02. March 2016 +; ******************************************************************************/ +;/* +; * Copyright (c) 2009-2016 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * 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 +; * +; * 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. +; */ + +;/* +;//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ +;*/ + +__initial_sp EQU 0x08010000 + + 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 0x0000000D ; NMI Handler located at ROM code + 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 Description + DCD NvicMux0_IRQHandler ; CM0 + NVIC Mux input 0 + DCD NvicMux1_IRQHandler ; CM0 + NVIC Mux input 1 + DCD NvicMux2_IRQHandler ; CM0 + NVIC Mux input 2 + DCD NvicMux3_IRQHandler ; CM0 + NVIC Mux input 3 + DCD NvicMux4_IRQHandler ; CM0 + NVIC Mux input 4 + DCD NvicMux5_IRQHandler ; CM0 + NVIC Mux input 5 + DCD NvicMux6_IRQHandler ; CM0 + NVIC Mux input 6 + DCD NvicMux7_IRQHandler ; CM0 + NVIC Mux input 7 + DCD NvicMux8_IRQHandler ; CM0 + NVIC Mux input 8 + DCD NvicMux9_IRQHandler ; CM0 + NVIC Mux input 9 + DCD NvicMux10_IRQHandler ; CM0 + NVIC Mux input 10 + DCD NvicMux11_IRQHandler ; CM0 + NVIC Mux input 11 + DCD NvicMux12_IRQHandler ; CM0 + NVIC Mux input 12 + DCD NvicMux13_IRQHandler ; CM0 + NVIC Mux input 13 + DCD NvicMux14_IRQHandler ; CM0 + NVIC Mux input 14 + DCD NvicMux15_IRQHandler ; CM0 + NVIC Mux input 15 + DCD NvicMux16_IRQHandler ; CM0 + NVIC Mux input 16 + DCD NvicMux17_IRQHandler ; CM0 + NVIC Mux input 17 + DCD NvicMux18_IRQHandler ; CM0 + NVIC Mux input 18 + DCD NvicMux19_IRQHandler ; CM0 + NVIC Mux input 19 + DCD NvicMux20_IRQHandler ; CM0 + NVIC Mux input 20 + DCD NvicMux21_IRQHandler ; CM0 + NVIC Mux input 21 + DCD NvicMux22_IRQHandler ; CM0 + NVIC Mux input 22 + DCD NvicMux23_IRQHandler ; CM0 + NVIC Mux input 23 + DCD NvicMux24_IRQHandler ; CM0 + NVIC Mux input 24 + DCD NvicMux25_IRQHandler ; CM0 + NVIC Mux input 25 + DCD NvicMux26_IRQHandler ; CM0 + NVIC Mux input 26 + DCD NvicMux27_IRQHandler ; CM0 + NVIC Mux input 27 + DCD NvicMux28_IRQHandler ; CM0 + NVIC Mux input 28 + DCD NvicMux29_IRQHandler ; CM0 + NVIC Mux input 29 + DCD NvicMux30_IRQHandler ; CM0 + NVIC Mux input 30 + DCD NvicMux31_IRQHandler ; CM0 + NVIC Mux input 31 + +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + EXPORT __ramVectors + AREA RESET_RAM, READWRITE, NOINIT +__ramVectors SPACE __Vectors_Size + + + AREA |.text|, CODE, READONLY + + +; Saves and disables the interrupts +Cy_SaveIRQ PROC + EXPORT Cy_SaveIRQ + MRS r0, PRIMASK + CPSID I + BX LR + ENDP + + +; Restores the interrupts +Cy_RestoreIRQ PROC + EXPORT Cy_RestoreIRQ + MSR PRIMASK, r0 + BX LR + ENDP + + +; Weak function for startup customization +Cy_OnResetUser PROC + EXPORT Cy_OnResetUser [WEAK] + BX LR + ENDP + +; Reset Handler +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT __main + + ; Define strong function for startup customization + BL Cy_OnResetUser + + ; Copy vectors from ROM to RAM + LDR r1, =__Vectors + LDR r0, =__ramVectors + LDR r2, =__Vectors_Size +Vectors_Copy + LDR r3, [r1] + STR r3, [r0] + ADDS r0, r0, #4 + ADDS r1, r1, #4 + SUBS r2, r2, #1 + CMP r2, #0 + BNE Vectors_Copy + + ; Update Vector Table Offset Register. */ + LDR r0, =__ramVectors + LDR r1, =0xE000ED08 + STR r0, [r1] + dsb 0xF + + LDR R0, =__main + BLX R0 + + ; Should never get here + B . + + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP + +Cy_SysLib_FaultHandler PROC + EXPORT Cy_SysLib_FaultHandler [WEAK] + B . + ENDP + +HardFault_Handler PROC + EXPORT HardFault_Handler [WEAK] + movs r0, #4 + mov r1, LR + tst r0, r1 + beq L_MSP + mrs r0, PSP + bl L_API_call +L_MSP + mrs r0, MSP +L_API_call + bl Cy_SysLib_FaultHandler + 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 Default_Handler [WEAK] + EXPORT NvicMux0_IRQHandler [WEAK] + EXPORT NvicMux1_IRQHandler [WEAK] + EXPORT NvicMux2_IRQHandler [WEAK] + EXPORT NvicMux3_IRQHandler [WEAK] + EXPORT NvicMux4_IRQHandler [WEAK] + EXPORT NvicMux5_IRQHandler [WEAK] + EXPORT NvicMux6_IRQHandler [WEAK] + EXPORT NvicMux7_IRQHandler [WEAK] + EXPORT NvicMux8_IRQHandler [WEAK] + EXPORT NvicMux9_IRQHandler [WEAK] + EXPORT NvicMux10_IRQHandler [WEAK] + EXPORT NvicMux11_IRQHandler [WEAK] + EXPORT NvicMux12_IRQHandler [WEAK] + EXPORT NvicMux13_IRQHandler [WEAK] + EXPORT NvicMux14_IRQHandler [WEAK] + EXPORT NvicMux15_IRQHandler [WEAK] + EXPORT NvicMux16_IRQHandler [WEAK] + EXPORT NvicMux17_IRQHandler [WEAK] + EXPORT NvicMux18_IRQHandler [WEAK] + EXPORT NvicMux19_IRQHandler [WEAK] + EXPORT NvicMux20_IRQHandler [WEAK] + EXPORT NvicMux21_IRQHandler [WEAK] + EXPORT NvicMux22_IRQHandler [WEAK] + EXPORT NvicMux23_IRQHandler [WEAK] + EXPORT NvicMux24_IRQHandler [WEAK] + EXPORT NvicMux25_IRQHandler [WEAK] + EXPORT NvicMux26_IRQHandler [WEAK] + EXPORT NvicMux27_IRQHandler [WEAK] + EXPORT NvicMux28_IRQHandler [WEAK] + EXPORT NvicMux29_IRQHandler [WEAK] + EXPORT NvicMux30_IRQHandler [WEAK] + EXPORT NvicMux31_IRQHandler [WEAK] + +NvicMux0_IRQHandler +NvicMux1_IRQHandler +NvicMux2_IRQHandler +NvicMux3_IRQHandler +NvicMux4_IRQHandler +NvicMux5_IRQHandler +NvicMux6_IRQHandler +NvicMux7_IRQHandler +NvicMux8_IRQHandler +NvicMux9_IRQHandler +NvicMux10_IRQHandler +NvicMux11_IRQHandler +NvicMux12_IRQHandler +NvicMux13_IRQHandler +NvicMux14_IRQHandler +NvicMux15_IRQHandler +NvicMux16_IRQHandler +NvicMux17_IRQHandler +NvicMux18_IRQHandler +NvicMux19_IRQHandler +NvicMux20_IRQHandler +NvicMux21_IRQHandler +NvicMux22_IRQHandler +NvicMux23_IRQHandler +NvicMux24_IRQHandler +NvicMux25_IRQHandler +NvicMux26_IRQHandler +NvicMux27_IRQHandler +NvicMux28_IRQHandler +NvicMux29_IRQHandler +NvicMux30_IRQHandler +NvicMux31_IRQHandler + + B . + ENDP + + ALIGN + + END + + +; [] END OF FILE diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm0plus.ld b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm0plus.ld similarity index 79% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm0plus.ld rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm0plus.ld index 146e0e8492..2148edf235 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm0plus.ld +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm0plus.ld @@ -1,9 +1,13 @@ /***************************************************************************//** * \file cy8c6xx7_cm0plus.ld -* \version 2.0 +* \version 2.10 * * Linker file for the GNU C compiler. * +* The main purpose of the linker script is to describe how the sections in the +* input files should be mapped into the output file, and to control the memory +* layout of the output file. +* * \note The entry point location is fixed and starts at 0x10000000. The valid * application image should be placed there. * @@ -15,7 +19,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -35,21 +39,35 @@ ENTRY(Reset_Handler) */ EXTERN(Reset_Handler) - -/* Linker script to configure memory regions. */ +/* The MEMORY section below describes the location and size of blocks of memory in the target. +* Use this section to specify the memory regions available for allocation. +*/ MEMORY { - flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x80000 - wflash (rx) : ORIGIN = 0x14000000, LENGTH = 0x8000 /* 32 KB */ - sflash_user_data (rx) : ORIGIN = 0x16000800, LENGTH = 0x800 - sflash_nar (rx) : ORIGIN = 0x16001A00, LENGTH = 0x200 - sflash_public_key (rx) : ORIGIN = 0x16005A00, LENGTH = 0xC00 - sflash_toc_2 (rx) : ORIGIN = 0x16007C00, LENGTH = 0x400 - xip (rx) : ORIGIN = 0x18000000, LENGTH = 0x8000000 /* 128 MB */ - efuse (r) : ORIGIN = 0x90700000, LENGTH = 0x100000 /* 1 MB */ - ram (rwx) : ORIGIN = 0x08000000, LENGTH = 0x24000 -} + /* The ram and flash regions control RAM and flash memory allocation for the CM0+ core. + * You can change the memory allocation by editing the 'ram' and 'flash' regions. + * Your changes must be aligned with the corresponding memory regions for the CM4 core in 'xx_cm4_dual.ld', + * where 'xx' is the device group; for example, 'cy8c6xx7_cm4_dual.ld'. + */ + ram (rwx) : ORIGIN = 0x08000000, LENGTH = 0x10000 + flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x78000 + /* This is a 32K flash region used for EEPROM emulation. This region can also be used as the general purpose flash. + * You can assign sections to this memory region for only one of the cores. + * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region. + * Therefore, repurposing this memory region will prevent such middleware from operation. + */ + em_eeprom (rx) : ORIGIN = 0x14000000, LENGTH = 0x8000 /* 32 KB */ + + /* The following regions define device specific memory regions and must not be changed. */ + sflash_user_data (rx) : ORIGIN = 0x16000800, LENGTH = 0x800 /* Supervisory flash: User data */ + sflash_nar (rx) : ORIGIN = 0x16001A00, LENGTH = 0x200 /* Supervisory flash: Normal Access Restrictions (NAR) */ + sflash_public_key (rx) : ORIGIN = 0x16005A00, LENGTH = 0xC00 /* Supervisory flash: Public Key */ + sflash_toc_2 (rx) : ORIGIN = 0x16007C00, LENGTH = 0x200 /* Supervisory flash: Table of Content # 2 */ + sflash_rtoc_2 (rx) : ORIGIN = 0x16007E00, LENGTH = 0x200 /* Supervisory flash: Table of Content # 2 Copy */ + xip (rx) : ORIGIN = 0x18000000, LENGTH = 0x8000000 /* 128 MB */ + efuse (r) : ORIGIN = 0x90700000, LENGTH = 0x100000 /* 1 MB */ +} /* Library configurations */ GROUP(libgcc.a libc.a libm.a libnosys.a) @@ -129,6 +147,34 @@ SECTIONS *(.rodata .rodata.* .constdata .constdata.* .conststring .conststring.*) KEEP(*(.eh_frame*)) + + /* To copy multiple ROM to RAM sections, + * uncomment copy table section and, + * define __STARTUP_COPY_MULTIPLE in startup_psoc63_cm4.S */ + . = ALIGN(4); + __copy_table_start__ = .; + + /* Copy interrupt vectors from flash to RAM */ + LONG (__Vectors) /* From */ + LONG (__ram_vectors_start__) /* To */ + LONG (__Vectors_End - __Vectors) /* Size */ + + /* Copy data section to RAM */ + LONG (__etext) /* From */ + LONG (__data_start__) /* To */ + LONG (__data_end__ - __data_start__) /* Size */ + + __copy_table_end__ = .; + + /* To clear multiple BSS sections, + * uncomment zero table section and, + * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_psoc63_cm4.S */ + . = ALIGN(4); + __zero_table_start__ = .; + LONG (__bss_start__) + LONG (__bss_end__ - __bss_start__) + __zero_table_end__ = .; + } > flash @@ -145,41 +191,6 @@ SECTIONS } > flash __exidx_end = .; - - /* To copy multiple ROM to RAM sections, - * uncomment .copy.table section and, - * define __STARTUP_COPY_MULTIPLE in startup_psoc63_cm0plus.S */ - .copy.table : - { - . = ALIGN(4); - __copy_table_start__ = .; - - /* Copy interrupt vectors from flash to RAM */ - LONG (__Vectors) /* From */ - LONG (__ram_vectors_start__) /* To */ - LONG (__Vectors_End - __Vectors) /* Size */ - - /* Copy data section to RAM */ - LONG (__etext) /* From */ - LONG (__data_start__) /* To */ - LONG (__data_end__ - __data_start__) /* Size */ - - __copy_table_end__ = .; - } > flash - - - /* To clear multiple BSS sections, - * uncomment .zero.table section and, - * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_psoc63_cm0plus.S */ - .zero.table : - { - . = ALIGN(4); - __zero_table_start__ = .; - LONG (__bss_start__) - LONG (__bss_end__ - __bss_start__) - __zero_table_end__ = .; - } > flash - __etext = . ; @@ -211,7 +222,6 @@ SECTIONS KEEP(*(.init_array)) PROVIDE_HIDDEN (__init_array_end = .); - . = ALIGN(4); /* finit data */ PROVIDE_HIDDEN (__fini_array_start = .); @@ -291,11 +301,11 @@ SECTIONS ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") - /* Work Flash */ - .cy_wflash : + /* Emulated EEPROM Flash area */ + .cy_em_eeprom : { - KEEP(*(.cy_wflash)) - } > wflash + KEEP(*(.cy_em_eeprom)) + } > em_eeprom /* Supervisory Flash: User data */ @@ -325,6 +335,13 @@ SECTIONS KEEP(*(.cy_toc_part2)) } > sflash_toc_2 + + /* Supervisory Flash: Table of Content # 2 Copy */ + .cy_rtoc_part2 : + { + KEEP(*(.cy_rtoc_part2)) + } > sflash_rtoc_2 + /* Places the code in the Execute in Place (XIP) section. See the smif driver * documentation for details. @@ -349,13 +366,13 @@ SECTIONS } -/* The following symbols used by the cypdlelftool. */ +/* The following symbols used by the cymcuelftool. */ /* Flash */ __cy_memory_0_start = 0x10000000; __cy_memory_0_length = 0x00100000; __cy_memory_0_row_size = 0x200; -/* Working Flash */ +/* Emulated EEPROM Flash area */ __cy_memory_1_start = 0x14000000; __cy_memory_1_length = 0x8000; __cy_memory_1_row_size = 0x200; diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_client_gcc.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_client_gcc.a similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_client_gcc.a rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_client_gcc.a index 32d9aa905a..26c4932cab 100644 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_client_gcc.a and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_client_gcc.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_base.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_base.a similarity index 83% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_base.a rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_base.a index 685790d83a..67d15827cc 100644 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_base.a and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_base.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_extra.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_extra.a similarity index 82% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_extra.a rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_extra.a index 937eeefec7..90564cb875 100644 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_extra.a and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_extra.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm0plus.S b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm0plus.S similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm0plus.S rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm0plus.S index ccb6d5e97b..00178a1aad 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm0plus.S +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm0plus.S @@ -178,7 +178,6 @@ Cy_RestoreIRQ: Reset_Handler: bl Cy_OnResetUser - cpsid i /* Firstly it copies data from read only memory to RAM. There are two schemes * to copy. One can copy more than one sections. Another can only copy @@ -313,11 +312,7 @@ Reset_Handler: str r0, [r1] dsb 0xF -#ifndef __NO_SYSTEM_INIT - bl SystemInit -#endif - - bl main + bl _start /* Should never get here */ b . diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/cy8c6xx7_cm0plus.icf b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/cy8c6xx7_cm0plus.icf new file mode 100644 index 0000000000..36c45e1a77 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/cy8c6xx7_cm0plus.icf @@ -0,0 +1,218 @@ +/***************************************************************************//** +* \file cy8c6xx7_cm0plus.icf +* \version 2.10 +* +* Linker file for the IAR compiler. +* +* The main purpose of the linker script is to describe how the sections in the +* input files should be mapped into the output file, and to control the memory +* layout of the output file. +* +* \note The entry point is fixed and starts at 0x10000000. The valid application +* image should be placed there. +* +* \note The linker files included with the PDL template projects must be generic +* and handle all common use cases. Your project may not use every section +* defined in the linker files. In that case you may see warnings during the +* build process. In your project, you can simply comment out or remove the +* relevant code in the linker file. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_4.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x00000000; + +/* The symbols below define the location and size of blocks of memory in the target. + * Use these symbols to specify the memory regions available for allocation. + */ + +/* The following symbols control RAM and flash memory allocation for the CM0+ core. + * You can change the memory allocation by editing RAM and Flash symbols. + * Your changes must be aligned with the corresponding symbols for CM4 core in 'xx_cm4_dual.icf', + * where 'xx' is the device group; for example, 'cy8c6xx7_cm4_dual.icf'. + */ +/* RAM */ +define symbol __ICFEDIT_region_IRAM1_start__ = 0x08000000; +define symbol __ICFEDIT_region_IRAM1_end__ = 0x08010000; +/* Flash */ +define symbol __ICFEDIT_region_IROM1_start__ = 0x10000000; +define symbol __ICFEDIT_region_IROM1_end__ = 0x10078000; + +/* The following symbols define a 32K flash region used for EEPROM emulation. + * This region can also be used as the general purpose flash. + * You can assign sections to this memory region for only one of the cores. + * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region. + * Therefore, repurposing this memory region will prevent such middleware from operation. + */ +define symbol __ICFEDIT_region_IROM2_start__ = 0x14000000; +define symbol __ICFEDIT_region_IROM2_end__ = 0x14007FFF; + +/* The following symbols define device specific memory regions and must not be changed. */ +/* Supervisory FLASH - User Data */ +define symbol __ICFEDIT_region_IROM3_start__ = 0x16000800; +define symbol __ICFEDIT_region_IROM3_end__ = 0x160007FF; + +/* Supervisory FLASH - Normal Access Restrictions (NAR) */ +define symbol __ICFEDIT_region_IROM4_start__ = 0x16001A00; +define symbol __ICFEDIT_region_IROM4_end__ = 0x16001BFF; + +/* Supervisory FLASH - Public Key */ +define symbol __ICFEDIT_region_IROM5_start__ = 0x16005A00; +define symbol __ICFEDIT_region_IROM5_end__ = 0x160065FF; + +/* Supervisory FLASH - Table of Content # 2 */ +define symbol __ICFEDIT_region_IROM6_start__ = 0x16007C00; +define symbol __ICFEDIT_region_IROM6_end__ = 0x16007DFF; + +/* Supervisory FLASH - Table of Content # 2 Copy */ +define symbol __ICFEDIT_region_IROM7_start__ = 0x16007E00; +define symbol __ICFEDIT_region_IROM7_end__ = 0x16007FFF; + +/* eFuse */ +define symbol __ICFEDIT_region_IROM8_start__ = 0x90700000; +define symbol __ICFEDIT_region_IROM8_end__ = 0x907FFFFF; + +/* XIP */ +define symbol __ICFEDIT_region_EROM1_start__ = 0x18000000; +define symbol __ICFEDIT_region_EROM1_end__ = 0x1FFFFFFF; + +define symbol __ICFEDIT_region_EROM2_start__ = 0x0; +define symbol __ICFEDIT_region_EROM2_end__ = 0x0; +define symbol __ICFEDIT_region_EROM3_start__ = 0x0; +define symbol __ICFEDIT_region_EROM3_end__ = 0x0; + + +define symbol __ICFEDIT_region_IRAM2_start__ = 0x0; +define symbol __ICFEDIT_region_IRAM2_end__ = 0x0; +define symbol __ICFEDIT_region_ERAM1_start__ = 0x0; +define symbol __ICFEDIT_region_ERAM1_end__ = 0x0; +define symbol __ICFEDIT_region_ERAM2_start__ = 0x0; +define symbol __ICFEDIT_region_ERAM2_end__ = 0x0; +define symbol __ICFEDIT_region_ERAM3_start__ = 0x0; +define symbol __ICFEDIT_region_ERAM3_end__ = 0x0; +/*-Sizes-*/ +if (!isdefinedsymbol(__STACK_SIZE)) { + define symbol __ICFEDIT_size_cstack__ = 0x1000; +} else { + define symbol __ICFEDIT_size_cstack__ = __STACK_SIZE; +} +define symbol __ICFEDIT_size_proc_stack__ = 0x0; +if (!isdefinedsymbol(__HEAP_SIZE)) { + define symbol __ICFEDIT_size_heap__ = 0x4000; +} else { + define symbol __ICFEDIT_size_heap__ = __HEAP_SIZE; +} +/**** End of ICF editor section. ###ICF###*/ + + +define memory mem with size = 4G; +define region IROM1_region = mem:[from __ICFEDIT_region_IROM1_start__ to __ICFEDIT_region_IROM1_end__]; +define region IROM2_region = mem:[from __ICFEDIT_region_IROM2_start__ to __ICFEDIT_region_IROM2_end__]; +define region IROM3_region = mem:[from __ICFEDIT_region_IROM3_start__ to __ICFEDIT_region_IROM3_end__]; +define region IROM4_region = mem:[from __ICFEDIT_region_IROM4_start__ to __ICFEDIT_region_IROM4_end__]; +define region IROM5_region = mem:[from __ICFEDIT_region_IROM5_start__ to __ICFEDIT_region_IROM5_end__]; +define region IROM6_region = mem:[from __ICFEDIT_region_IROM6_start__ to __ICFEDIT_region_IROM6_end__]; +define region IROM7_region = mem:[from __ICFEDIT_region_IROM7_start__ to __ICFEDIT_region_IROM7_end__]; +define region IROM8_region = mem:[from __ICFEDIT_region_IROM8_start__ to __ICFEDIT_region_IROM8_end__]; +define region EROM1_region = mem:[from __ICFEDIT_region_EROM1_start__ to __ICFEDIT_region_EROM1_end__]; +define region IRAM1_region = mem:[from __ICFEDIT_region_IRAM1_start__ to __ICFEDIT_region_IRAM1_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block PROC_STACK with alignment = 8, size = __ICFEDIT_size_proc_stack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; +define block HSTACK {block HEAP, block PROC_STACK, last block CSTACK}; +define block RO {first section .intvec, readonly}; + +/*-Initializations-*/ +initialize by copy { readwrite }; +do not initialize { section .noinit, section .intvec_ram }; + + +/*-Placement-*/ + +/* Flash */ +".cy_app_header" : place at start of IROM1_region { section .cy_app_header }; +place in IROM1_region { block RO }; + +/* Emulated EEPROM Flash area */ +".cy_em_eeprom" : place at start of IROM2_region { section .cy_em_eeprom }; + +/* Supervisory Flash - User Data */ +".cy_sflash_user_data" : place at start of IROM3_region { section .cy_sflash_user_data }; + +/* Supervisory Flash - NAR */ +".cy_sflash_nar" : place at start of IROM4_region { section .cy_sflash_nar }; + +/* Supervisory Flash - Public Key */ +".cy_sflash_public_key" : place at start of IROM5_region { section .cy_sflash_public_key }; + +/* Supervisory Flash - TOC2 */ +".cy_toc_part2" : place at start of IROM6_region { section .cy_toc_part2 }; + +/* Supervisory Flash - RTOC2 */ +".cy_rtoc_part2" : place at start of IROM7_region { section .cy_rtoc_part2 }; + +/* eFuse */ +".cy_efuse" : place at start of IROM8_region { section .cy_efuse }; + +/* Execute in Place (XIP). See the smif driver documentation for details. */ +".cy_xip" : place at start of EROM1_region { section .cy_xip }; + +/* RAM */ +place at start of IRAM1_region { readwrite section .intvec_ram}; +place in IRAM1_region { readwrite }; +place at end of IRAM1_region { block HSTACK }; + +/* These sections are used for additional metadata (silicon revision, Silicon/JTAG ID, etc.) storage. */ +".cymeta" : place at address mem : 0x90500000 { readonly section .cymeta }; + + +keep { section .cy_app_header, + section .cy_em_eeprom, + section .cy_sflash_user_data, + section .cy_sflash_nar, + section .cy_sflash_public_key, + section .cy_toc_part2, + section .cy_rtoc_part2, + section .cy_efuse, + section .cy_xip, + section .cymeta, + }; + + +/* The following symbols used by the cymcuelftool. */ +/* Flash */ +define exported symbol __cy_memory_0_start = 0x10000000; +define exported symbol __cy_memory_0_length = 0x00100000; +define exported symbol __cy_memory_0_row_size = 0x200; + +/* Emulated EEPROM Flash area */ +define exported symbol __cy_memory_1_start = 0x14000000; +define exported symbol __cy_memory_1_length = 0x8000; +define exported symbol __cy_memory_1_row_size = 0x200; + +/* Supervisory Flash */ +define exported symbol __cy_memory_2_start = 0x16000000; +define exported symbol __cy_memory_2_length = 0x8000; +define exported symbol __cy_memory_2_row_size = 0x200; + +/* XIP */ +define exported symbol __cy_memory_3_start = 0x18000000; +define exported symbol __cy_memory_3_length = 0x08000000; +define exported symbol __cy_memory_3_row_size = 0x200; + +/* eFuse */ +define exported symbol __cy_memory_4_start = 0x90700000; +define exported symbol __cy_memory_4_length = 0x100000; +define exported symbol __cy_memory_4_row_size = 1; + +/* EOF */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_client_mdk.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_client_mdk.a new file mode 100644 index 0000000000..fcddb074cd Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_client_mdk.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_server_mdk_base.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_server_mdk_base.a new file mode 100644 index 0000000000..84ba700e4c Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_server_mdk_base.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_server_mdk_extra.a b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_server_mdk_extra.a new file mode 100644 index 0000000000..efa12e0d30 Binary files /dev/null and b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/libcy_crypto_server_mdk_extra.a differ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/startup_psoc63_cm0plus.s b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/startup_psoc63_cm0plus.s new file mode 100644 index 0000000000..34ad737a3a --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/device/TOOLCHAIN_IAR/startup_psoc63_cm0plus.s @@ -0,0 +1,417 @@ +;/**************************************************************************//** +; * @file startup_psoc63_cm0plus.s +; * @brief CMSIS Core Device Startup File for +; * ARMCM0plus Device Series +; * @version V5.00 +; * @date 08. March 2016 +; ******************************************************************************/ +;/* +; * Copyright (c) 2009-2016 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * 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 +; * +; * 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. +; */ + +; +; The modules in this file are included in the libraries, and may be replaced +; by any user-defined modules that define the PUBLIC symbol _program_start or +; a user defined start symbol. +; To override the cstartup defined in the library, simply add your modified +; version to the workbench project. +; +; The vector table is normally located at address 0. +; When debugging in RAM, it can be located in RAM, aligned to at least 2^6. +; The name "__vector_table" has special meaning for C-SPY: +; it is where the SP start value is found, and the NVIC vector +; table register (VTOR) is initialized to this address if != 0. +; +; Cortex-M version +; + + MODULE ?cstartup + + ;; Forward declaration of sections. + SECTION CSTACK:DATA:NOROOT(3) + SECTION .intvec_ram:DATA:NOROOT(2) + SECTION .intvec:CODE:NOROOT(2) + + EXTERN __iar_program_start + PUBLIC __vector_table + PUBLIC __vector_table_0x1c + PUBLIC __Vectors + PUBLIC __Vectors_End + PUBLIC __Vectors_Size + PUBLIC __ramVectors + + DATA + +__vector_table + DCD sfe(CSTACK) + DCD Reset_Handler + + DCD 0x0000000D ; NMI_Handler is defined in ROM code + DCD HardFault_Handler + DCD 0 + DCD 0 + DCD 0 +__vector_table_0x1c + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler + DCD 0 + DCD 0 + DCD PendSV_Handler + DCD SysTick_Handler + + ; External interrupts Power Mode Description + DCD NvicMux0_IRQHandler ; CM0 + NVIC Mux input 0 + DCD NvicMux1_IRQHandler ; CM0 + NVIC Mux input 1 + DCD NvicMux2_IRQHandler ; CM0 + NVIC Mux input 2 + DCD NvicMux3_IRQHandler ; CM0 + NVIC Mux input 3 + DCD NvicMux4_IRQHandler ; CM0 + NVIC Mux input 4 + DCD NvicMux5_IRQHandler ; CM0 + NVIC Mux input 5 + DCD NvicMux6_IRQHandler ; CM0 + NVIC Mux input 6 + DCD NvicMux7_IRQHandler ; CM0 + NVIC Mux input 7 + DCD NvicMux8_IRQHandler ; CM0 + NVIC Mux input 8 + DCD NvicMux9_IRQHandler ; CM0 + NVIC Mux input 9 + DCD NvicMux10_IRQHandler ; CM0 + NVIC Mux input 10 + DCD NvicMux11_IRQHandler ; CM0 + NVIC Mux input 11 + DCD NvicMux12_IRQHandler ; CM0 + NVIC Mux input 12 + DCD NvicMux13_IRQHandler ; CM0 + NVIC Mux input 13 + DCD NvicMux14_IRQHandler ; CM0 + NVIC Mux input 14 + DCD NvicMux15_IRQHandler ; CM0 + NVIC Mux input 15 + DCD NvicMux16_IRQHandler ; CM0 + NVIC Mux input 16 + DCD NvicMux17_IRQHandler ; CM0 + NVIC Mux input 17 + DCD NvicMux18_IRQHandler ; CM0 + NVIC Mux input 18 + DCD NvicMux19_IRQHandler ; CM0 + NVIC Mux input 19 + DCD NvicMux20_IRQHandler ; CM0 + NVIC Mux input 20 + DCD NvicMux21_IRQHandler ; CM0 + NVIC Mux input 21 + DCD NvicMux22_IRQHandler ; CM0 + NVIC Mux input 22 + DCD NvicMux23_IRQHandler ; CM0 + NVIC Mux input 23 + DCD NvicMux24_IRQHandler ; CM0 + NVIC Mux input 24 + DCD NvicMux25_IRQHandler ; CM0 + NVIC Mux input 25 + DCD NvicMux26_IRQHandler ; CM0 + NVIC Mux input 26 + DCD NvicMux27_IRQHandler ; CM0 + NVIC Mux input 27 + DCD NvicMux28_IRQHandler ; CM0 + NVIC Mux input 28 + DCD NvicMux29_IRQHandler ; CM0 + NVIC Mux input 29 + DCD NvicMux30_IRQHandler ; CM0 + NVIC Mux input 30 + DCD NvicMux31_IRQHandler ; CM0 + NVIC Mux input 31 + +__Vectors_End + +__Vectors EQU __vector_table +__Vectors_Size EQU __Vectors_End - __Vectors + + SECTION .intvec_ram:DATA:REORDER:NOROOT(2) +__ramVectors + DS32 __Vectors_Size + + + THUMB + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default handlers +;; + PUBWEAK Default_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Default_Handler + B Default_Handler + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Saves and disables the interrupts +;; + PUBLIC Cy_SaveIRQ + SECTION .text:CODE:REORDER:NOROOT(2) +Cy_SaveIRQ + MRS r0, PRIMASK + CPSID I + BX LR + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Restores the interrupts +;; + PUBLIC Cy_RestoreIRQ + SECTION .text:CODE:REORDER:NOROOT(2) +Cy_RestoreIRQ + MSR PRIMASK, r0 + BX LR + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Weak function for startup customization +;; + PUBWEAK Cy_OnResetUser + SECTION .text:CODE:REORDER:NOROOT(2) +Cy_OnResetUser + BX LR + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default interrupt handlers. +;; + THUMB + PUBWEAK Reset_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Reset_Handler + + ; Define strong function for startup customization + LDR R0, =Cy_OnResetUser + BLX R0 + + ; Copy vectors from ROM to RAM + LDR r1, =__vector_table + LDR r0, =__ramVectors + LDR r2, =__Vectors_Size +intvec_copy + LDR r3, [r1] + STR r3, [r0] + ADDS r0, r0, #4 + ADDS r1, r1, #4 + SUBS r2, r2, #1 + CMP r2, #0 + BNE intvec_copy + + ; Update Vector Table Offset Register + LDR r0, =__ramVectors + LDR r1, =0xE000ED08 + STR r0, [r1] + dsb + + LDR R0, =__iar_program_start + BLX R0 + +; Should never get here +Cy_Main_Exited + B Cy_Main_Exited + + + PUBWEAK NMI_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +NMI_Handler + B NMI_Handler + + + PUBWEAK Cy_SysLib_FaultHandler + SECTION .text:CODE:REORDER:NOROOT(1) +Cy_SysLib_FaultHandler + B Cy_SysLib_FaultHandler + + PUBWEAK HardFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Handler + IMPORT Cy_SysLib_FaultHandler + movs r0, #4 + mov r1, LR + tst r0, r1 + beq L_MSP + mrs r0, PSP + b L_API_call +L_MSP + mrs r0, MSP +L_API_call + ; Storing LR content for Creator call stack trace + push {LR} + bl Cy_SysLib_FaultHandler + + + PUBWEAK SVC_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SVC_Handler + B SVC_Handler + + PUBWEAK PendSV_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +PendSV_Handler + B PendSV_Handler + + PUBWEAK SysTick_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SysTick_Handler + B SysTick_Handler + + + ; External interrupts + PUBWEAK NvicMux0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux0_IRQHandler + B NvicMux0_IRQHandler + + PUBWEAK NvicMux1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux1_IRQHandler + B NvicMux1_IRQHandler + + PUBWEAK NvicMux2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux2_IRQHandler + B NvicMux2_IRQHandler + + PUBWEAK NvicMux3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux3_IRQHandler + B NvicMux3_IRQHandler + + PUBWEAK NvicMux4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux4_IRQHandler + B NvicMux4_IRQHandler + + PUBWEAK NvicMux5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux5_IRQHandler + B NvicMux5_IRQHandler + + PUBWEAK NvicMux6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux6_IRQHandler + B NvicMux6_IRQHandler + + PUBWEAK NvicMux7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux7_IRQHandler + B NvicMux7_IRQHandler + + PUBWEAK NvicMux8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux8_IRQHandler + B NvicMux8_IRQHandler + + PUBWEAK NvicMux9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux9_IRQHandler + B NvicMux9_IRQHandler + + PUBWEAK NvicMux10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux10_IRQHandler + B NvicMux10_IRQHandler + + PUBWEAK NvicMux11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux11_IRQHandler + B NvicMux11_IRQHandler + + PUBWEAK NvicMux12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux12_IRQHandler + B NvicMux12_IRQHandler + + PUBWEAK NvicMux13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux13_IRQHandler + B NvicMux13_IRQHandler + + PUBWEAK NvicMux14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux14_IRQHandler + B NvicMux14_IRQHandler + + PUBWEAK NvicMux15_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux15_IRQHandler + B NvicMux15_IRQHandler + + PUBWEAK NvicMux16_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux16_IRQHandler + B NvicMux16_IRQHandler + + PUBWEAK NvicMux17_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux17_IRQHandler + B NvicMux17_IRQHandler + + PUBWEAK NvicMux18_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux18_IRQHandler + B NvicMux18_IRQHandler + + PUBWEAK NvicMux19_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux19_IRQHandler + B NvicMux19_IRQHandler + + PUBWEAK NvicMux20_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux20_IRQHandler + B NvicMux20_IRQHandler + + PUBWEAK NvicMux21_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux21_IRQHandler + B NvicMux21_IRQHandler + + PUBWEAK NvicMux22_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux22_IRQHandler + B NvicMux22_IRQHandler + + PUBWEAK NvicMux23_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux23_IRQHandler + B NvicMux23_IRQHandler + + PUBWEAK NvicMux24_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux24_IRQHandler + B NvicMux24_IRQHandler + + PUBWEAK NvicMux25_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux25_IRQHandler + B NvicMux25_IRQHandler + + PUBWEAK NvicMux26_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux26_IRQHandler + B NvicMux26_IRQHandler + + PUBWEAK NvicMux27_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux27_IRQHandler + B NvicMux27_IRQHandler + + PUBWEAK NvicMux28_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux28_IRQHandler + B NvicMux28_IRQHandler + + PUBWEAK NvicMux29_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux29_IRQHandler + B NvicMux29_IRQHandler + + PUBWEAK NvicMux30_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux30_IRQHandler + B NvicMux30_IRQHandler + + PUBWEAK NvicMux31_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +NvicMux31_IRQHandler + B NvicMux31_IRQHandler + + + END + + +; [] END OF FILE diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/ipc_rpc_m0.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/ipc_rpc_m0.c new file mode 100644 index 0000000000..adb8297988 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/ipc_rpc_m0.c @@ -0,0 +1,41 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "psoc6_utils.h" +#include "ipc_rpc.h" +#include "rpc_defs.h" +#include "cy_ipc_config.h" +#include "ipc/cy_ipc_pipe.h" + +#undef RPC_GEN +#define RPC_GEN RPC_GEN_IMPLEMENTATION + +#include "rpc_defs.h" +#include "rpc_api.h" + +#undef RPC_GEN +#define RPC_GEN RPC_GEN_INITIALIZATION + +void ipcrpc_init(void) +{ + uint32_t rpc_counter = 0; + +#include "rpc_defs.h" +#include "rpc_api.h" +} + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/system_psoc63_cm0plus.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/system_psoc63_cm0plus.c similarity index 86% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/system_psoc63_cm0plus.c rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/system_psoc63_cm0plus.c index c7088c6f2d..29e50f068f 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/system_psoc63_cm0plus.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M0/system_psoc63_cm0plus.c @@ -1,26 +1,35 @@ /***************************************************************************//** * \file system_psoc63_cm0plus.c -* \version 2.0 +* \version 2.10 * * The device system-source file. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ +/* + * Copyright (c) 20017-2018 Future Electronics + */ #include #include +#include "device.h" #include "system_psoc63.h" #include "cy_device_headers.h" -#if !defined(CY_IPC_DEFAULT_CFG_DISABLE) - #include "ipc/cy_ipc_pipe.h" - #include "ipc/cy_ipc_sema.h" -#endif /* CY_IPC_DEFAULT_CFG_DISABLE */ +#if defined(CY_DEVICE_PSOC6ABLE2) + #if !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) + #include "syslib/cy_syslib.h" + #endif /* !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) */ + #if !defined(CY_IPC_DEFAULT_CFG_DISABLE) + #include "ipc/cy_ipc_drv.h" + #include "flash/cy_flash.h" + #endif /* !defined(CY_IPC_DEFAULT_CFG_DISABLE) */ +#endif /* defined(CY_DEVICE_PSOC6ABLE2) */ /******************************************************************************* @@ -28,41 +37,28 @@ *******************************************************************************/ /** Default HFClk frequency in Hz */ -#define CY_CLK_HFCLK0_FREQ_HZ_DEFAULT ( 8000000UL) +#define CY_CLK_HFCLK0_FREQ_HZ_DEFAULT CY_CLK_HFCLK0_FREQ_HZ /** Default PeriClk frequency in Hz */ -#define CY_CLK_PERICLK_FREQ_HZ_DEFAULT (4000000UL) +#define CY_CLK_PERICLK_FREQ_HZ_DEFAULT CY_CLK_PERICLK_FREQ_HZ /** Default SlowClk system core frequency in Hz */ -#define CY_CLK_SYSTEM_FREQ_HZ_DEFAULT (4000000UL) +#define CY_CLK_SYSTEM_FREQ_HZ_DEFAULT CY_CLK_SLOWCLK_FREQ_HZ -/** IMO frequency in Hz */ -#define CY_CLK_IMO_FREQ_HZ (8000000UL) - -/** HVILO frequency in Hz */ -#define CY_CLK_HVILO_FREQ_HZ (32000UL) - -#if (SRSS_PILO_PRESENT == 1U) || defined(CY_DOXYGEN) - /** PILO frequency in Hz */ - #define CY_CLK_PILO_FREQ_HZ (32768UL) -#endif /* (SRSS_PILO_PRESENT == 1U) || defined(CY_DOXYGEN) */ - -/** WCO frequency in Hz */ -#define CY_CLK_WCO_FREQ_HZ (32768UL) - -#if (SRSS_ALTLF_PRESENT == 1U) || defined(CY_DOXYGEN) - /** ALTLF frequency in Hz */ - #define CY_CLK_ALTLF_FREQ_HZ (32768UL) -#endif /* (SRSS_ALTLF_PRESENT == 1U) || defined(CY_DOXYGEN) */ - - -/** Holds the SlowClk system core clock, which is the system clock frequency supplied to the SysTick timer and the -* processor core clock. This variable can be used by debuggers to query the frequency of the debug timer or to configure -* the trace clock speed. +/** +* Holds the SlowClk (Cortex-M0+) or FastClk (Cortex-M4) system core clock, +* which is the system clock frequency supplied to the SysTick timer and the +* processor core clock. +* This variable implements CMSIS Core global variable. +* Refer to the [CMSIS documentation] +* (http://www.keil.com/pack/doc/CMSIS/Core/html/group__system__init__gr.html "System and Clock Configuration") +* for more details. +* This variable can be used by debuggers to query the frequency +* of the debug timer or to configure the trace clock speed. * -* \attention Compilers must be configured to avoid removing this variable in case the application program is not using -* it. Debugging systems require the variable to be physically present in memory so that it can be examined to configure -* the debugger. */ +* \attention Compilers must be configured to avoid removing this variable in case +* the application program is not using it. Debugging systems require the variable +* to be physically present in memory so that it can be examined to configure the debugger. */ uint32_t SystemCoreClock = CY_CLK_SYSTEM_FREQ_HZ_DEFAULT; /** Holds the HFClk0 clock frequency. Updated by \ref SystemCoreClockUpdate(). */ @@ -137,6 +133,29 @@ uint32_t cy_delay32kMs = CY_DELAY_MS_OVERFLOW_THRESHOLD * #define CY_SYS_CM4_PWR_CTL_KEY_CLOSE (0xFA05UL) +/******************************************************************************* +* Function Name: mbed_sdk_init +****************************************************************************//** +* +* Mbed's post-memory-initialization function. +* Used here to initialize common parts of the Cypress libraries. +* +*******************************************************************************/ +void mbed_sdk_init(void) +{ + /* Initialize shared resource manager */ + cy_srm_initialize(); + /* Initialize system and clocks. */ + /* Placed here as it must be done after proper LIBC initialization. */ + SystemInit(); + /* Allocate and initialize semaphores for the system operations. */ + Cy_IPC_SystemSemaInit(); + Cy_IPC_SystemPipeInit(); + Cy_Flash_Init(); + ipcrpc_init(); +} + + /******************************************************************************* * Function Name: SystemInit ****************************************************************************//** @@ -164,26 +183,32 @@ void SystemInit(void) SRSS->CLK_FLL_CONFIG3 = CY_FB_CLK_FLL_CONFIG3_VALUE; SRSS->CLK_FLL_CONFIG4 = CY_FB_CLK_FLL_CONFIG4_VALUE; - /* Unlock and disable WDT */ SRSS->WDT_CTL = ((SRSS->WDT_CTL & (uint32_t)(~SRSS_WDT_CTL_WDT_LOCK_Msk)) | CY_WDT_LOCK_BIT0); SRSS->WDT_CTL = (SRSS->WDT_CTL | CY_WDT_LOCK_BIT1); SRSS->WDT_CTL &= (~ (uint32_t) SRSS_WDT_CTL_WDT_EN_Msk); - Cy_SystemInit(); SystemCoreClockUpdate(); - -#if !defined(CY_IPC_DEFAULT_CFG_DISABLE) - /* Allocate and initialize semaphores for the system operations. */ - Cy_IPC_SystemSemaInit(); - Cy_IPC_SystemPipeInit(); -#endif /* CY_IPC_DEFAULT_CFG_DISABLE */ - - /* Clear data register of IPC structure #7, reserved for the Deep Sleep operations. */ - IPC_STRUCT7->DATA = 0UL; - /* Release IPC structure #7 to avoid deadlocks in case of SW or WDT reset during Deep Sleep entering. */ - IPC_STRUCT7->RELEASE = 0UL; + +#if defined(CY_DEVICE_PSOC6ABLE2) + #if !defined(CY_IPC_DEFAULT_CFG_DISABLE) + /* Allocate and initialize semaphores for the system operations. */ + Cy_IPC_SystemSemaInit(); + Cy_IPC_SystemPipeInit(); + Cy_Flash_Init(); + #endif /* CY_IPC_DEFAULT_CFG_DISABLE */ + + #if !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) + if (CY_SYSLIB_DEVICE_REV_0A == Cy_SysLib_GetDeviceRevision()) + { + /* Clear data register of IPC structure #7, reserved for the Deep-Sleep operations. */ + IPC_STRUCT7->DATA = 0UL; + /* Release IPC structure #7 to avoid deadlocks in case of SW or WDT reset during Deep-Sleep entering. */ + IPC_STRUCT7->RELEASE = 0UL; + } + #endif /* !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) */ +#endif /* CY_DEVICE_PSOC6ABLE2 */ } @@ -550,7 +575,7 @@ void Cy_SysResetCM4(void) * * The intention of the function is to declare boundaries of the memories for the * MDK compilers. For the rest of the supported compilers, this is done using -* linker configuration files. The following symbols used by the cypdlelftool. +* linker configuration files. The following symbols used by the cymcuelftool. * *******************************************************************************/ #if defined (__ARMCC_VERSION) @@ -587,9 +612,9 @@ __cy_memory_0_start EQU __cpp(CY_FLASH_BASE) __cy_memory_0_length EQU __cpp(CY_FLASH_SIZE) __cy_memory_0_row_size EQU 0x200 - /* Working Flash */ -__cy_memory_1_start EQU __cpp(CY_WFLASH_BASE) -__cy_memory_1_length EQU __cpp(CY_WFLASH_SIZE) + /* Flash region for EEPROM emulation */ +__cy_memory_1_start EQU __cpp(CY_EM_EEPROM_BASE) +__cy_memory_1_length EQU __cpp(CY_EM_EEPROM_SIZE) __cy_memory_1_row_size EQU 0x200 /* Supervisory Flash */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_ARM_STD/cy8c6xx7_cm4_dual.sct b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_ARM_STD/cy8c6xx7_cm4_dual.sct new file mode 100644 index 0000000000..ee145fb075 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_ARM_STD/cy8c6xx7_cm4_dual.sct @@ -0,0 +1,214 @@ +#! armcc -E +; The first line specifies a preprocessor command that the linker invokes +; to pass a scatter file through a C preprocessor. + +;******************************************************************************* +;* \file cy8c6xx7_cm4_dual.scat +;* \version 2.10 +;* +;* Linker file for the ARMCC. +;* +;* The main purpose of the linker script is to describe how the sections in the +;* input files should be mapped into the output file, and to control the memory +;* layout of the output file. +;* +;* \note The entry point location is fixed and starts at 0x10000000. The valid +;* application image should be placed there. +;* +;* \note The linker files included with the PDL template projects must be +;* generic and handle all common use cases. Your project may not use every +;* section defined in the linker files. In that case you may see the warnings +;* during the build process: L6314W (no section matches pattern) and/or L6329W +;* (pattern only matches removed unused sections). In your project, you can +;* suppress the warning by passing the "--diag_suppress=L6314W,L6329W" option to +;* the linker, simply comment out or remove the relevant code in the linker +;* file. +;* +;******************************************************************************* +;* \copyright +;* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +;* You may use this file only in accordance with the license, terms, conditions, +;* disclaimers, and limitations in the end user license agreement accompanying +;* the software package with which this file was provided. +;******************************************************************************/ + +; The defines below describe the location and size of blocks of memory in the target. +; Use these defines to specify the memory regions available for allocation. + +; The following defines control RAM and flash memory allocation for the CM4 core. +; You can change the memory allocation by editing RAM and Flash defines. +; Note that 2 KB of RAM (at the end of the RAM section) are reserved for system use. +; Using this memory region for other purposes will lead to unexpected behavior. +; Your changes must be aligned with the corresponding defines for CM0+ core in 'xx_cm0plus.scat', +; where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.scat'. +; RAM +; RAM +#define RAM_START 0x08010000 +#define RAM_SIZE 0x00037800 +; Flash +; Flash +#define FLASH_START 0x10080000 +#define FLASH_SIZE 0x00078000 + +; The following defines describe a 32K flash region used for EEPROM emulation. +; This region can also be used as the general purpose flash. +; You can assign sections to this memory region for only one of the cores. +; Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region. +; Therefore, repurposing this memory region will prevent such middleware from operation. +#define EM_EEPROM_START 0x14000000 +#define EM_EEPROM_SIZE 0x8000 + +; The following defines describe device specific memory regions and must not be changed. +; Supervisory flash: User data +#define SFLASH_USER_DATA_START 0x16000800 +#define SFLASH_USER_DATA_SIZE 0x00000800 + +; Supervisory flash: Normal Access Restrictions (NAR) +#define SFLASH_NAR_START 0x16001A00 +#define SFLASH_NAR_SIZE 0x00000200 + +; Supervisory flash: Public Key +#define SFLASH_PUBLIC_KEY_START 0x16005A00 +#define SFLASH_PUBLIC_KEY_SIZE 0x00000C00 + +; Supervisory flash: Table of Content # 2 +#define SFLASH_TOC_2_START 0x16007C00 +#define SFLASH_TOC_2_SIZE 0x00000200 + +; Supervisory flash: Table of Content # 2 Copy +#define SFLASH_RTOC_2_START 0x16007E00 +#define SFLASH_RTOC_2_SIZE 0x00000200 + +; External memory +#define XIP_START 0x18000000 +#define XIP_SIZE 0x08000000 + +; eFuse +#define EFUSE_START 0x90700000 +#define EFUSE_SIZE 0x100000 + + +LR_IROM1 FLASH_START FLASH_SIZE +{ + ER_FLASH_VECTORS +0 + { + * (RESET, +FIRST) + } + + ER_FLASH_CODE +0 FIXED + { + * (InRoot$$Sections) + * (+RO) + } + + ER_RAM_VECTORS RAM_START UNINIT + { + * (RESET_RAM, +FIRST) + } + + RW_RAM_DATA +0 + { + * (.cy_ramfunc) + .ANY (+RW, +ZI) + } + + ; Place variables in the section that should not be initialized during the + ; device startup. + RW_IRAM1 +0 UNINIT + { + * (.noinit) + } + + ; Used for the digital signature of the secure application and the + ; Bootloader SDK appication. The size of the section depends on the required + ; data size. + .cy_app_signature (FLASH_START + FLASH_SIZE - 256) 256 + { + * (.cy_app_signature) + } +} + + +; Emulated EEPROM Flash area +LR_EM_EEPROM EM_EEPROM_START EM_EEPROM_SIZE +{ + .cy_em_eeprom +0 + { + * (.cy_em_eeprom) + } +} + +; Supervisory flash: User data +LR_SFLASH_USER_DATA SFLASH_USER_DATA_START SFLASH_USER_DATA_SIZE +{ + .cy_sflash_user_data +0 + { + * (.cy_sflash_user_data) + } +} + +; Supervisory flash: Normal Access Restrictions (NAR) +LR_SFLASH_NAR SFLASH_NAR_START SFLASH_NAR_SIZE +{ + .cy_sflash_nar +0 + { + * (.cy_sflash_nar) + } +} + +; Supervisory flash: Public Key +LR_SFLASH_PUBLIC_KEY SFLASH_PUBLIC_KEY_START SFLASH_PUBLIC_KEY_SIZE +{ + .cy_sflash_public_key +0 + { + * (.cy_sflash_public_key) + } +} + +; Supervisory flash: Table of Content # 2 +LR_SFLASH_TOC_2 SFLASH_TOC_2_START SFLASH_TOC_2_SIZE +{ + .cy_toc_part2 +0 + { + * (.cy_toc_part2) + } +} + +; Supervisory flash: Table of Content # 2 Copy +LR_SFLASH_RTOC_2 SFLASH_RTOC_2_START SFLASH_RTOC_2_SIZE +{ + .cy_rtoc_part2 +0 + { + * (.cy_rtoc_part2) + } +} + + +; Places the code in the Execute in Place (XIP) section. See the smif driver documentation for details. +LR_EROM XIP_START XIP_SIZE +{ + .cy_xip +0 + { + * (.cy_xip) + } +} + + +; eFuse +LR_EFUSE EFUSE_START EFUSE_SIZE +{ + .cy_efuse +0 + { + * (.cy_efuse) + } +} + + +; The section is used for additional metadata (silicon revision, Silicon/JTAG ID, etc.) storage. +CYMETA 0x90500000 +{ + .cymeta +0 { * (.cymeta) } +} + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_ARM_STD/startup_psoc63_cm4.s b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_ARM_STD/startup_psoc63_cm4.s new file mode 100644 index 0000000000..c31adadbef --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_ARM_STD/startup_psoc63_cm4.s @@ -0,0 +1,654 @@ +;/**************************************************************************//** +; * @file startup_psoc63_cm4.s +; * @brief CMSIS Core Device Startup File for +; * ARMCM4 Device Series +; * @version V5.00 +; * @date 02. March 2016 +; ******************************************************************************/ +;/* +; * Copyright (c) 2009-2016 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * 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 +; * +; * 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. +; */ + +;/* +;//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ +;*/ + + +__initial_sp EQU 0x08047800 + + 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 0x0000000D ; NMI Handler located at ROM code + DCD HardFault_Handler ; Hard Fault Handler + DCD MemManage_Handler ; MPU Fault Handler + DCD BusFault_Handler ; Bus Fault Handler + DCD UsageFault_Handler ; Usage Fault Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD SVC_Handler ; SVCall Handler + DCD DebugMon_Handler ; Debug Monitor Handler + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + + ; External interrupts Power Mode Description + DCD ioss_interrupts_gpio_0_IRQHandler ; GPIO Port Interrupt #0 + DCD ioss_interrupts_gpio_1_IRQHandler ; GPIO Port Interrupt #1 + DCD ioss_interrupts_gpio_2_IRQHandler ; GPIO Port Interrupt #2 + DCD ioss_interrupts_gpio_3_IRQHandler ; GPIO Port Interrupt #3 + DCD ioss_interrupts_gpio_4_IRQHandler ; GPIO Port Interrupt #4 + DCD ioss_interrupts_gpio_5_IRQHandler ; GPIO Port Interrupt #5 + DCD ioss_interrupts_gpio_6_IRQHandler ; GPIO Port Interrupt #6 + DCD ioss_interrupts_gpio_7_IRQHandler ; GPIO Port Interrupt #7 + DCD ioss_interrupts_gpio_8_IRQHandler ; GPIO Port Interrupt #8 + DCD ioss_interrupts_gpio_9_IRQHandler ; GPIO Port Interrupt #9 + DCD ioss_interrupts_gpio_10_IRQHandler ; GPIO Port Interrupt #10 + DCD ioss_interrupts_gpio_11_IRQHandler ; GPIO Port Interrupt #11 + DCD ioss_interrupts_gpio_12_IRQHandler ; GPIO Port Interrupt #12 + DCD ioss_interrupts_gpio_13_IRQHandler ; GPIO Port Interrupt #13 + DCD ioss_interrupts_gpio_14_IRQHandler ; GPIO Port Interrupt #14 + DCD ioss_interrupt_gpio_IRQHandler ; GPIO All Ports + DCD ioss_interrupt_vdd_IRQHandler ; GPIO Supply Detect Interrupt + DCD lpcomp_interrupt_IRQHandler ; Low Power Comparator Interrupt + DCD scb_8_interrupt_IRQHandler ; Serial Communication Block #8 (DeepSleep capable) + DCD srss_interrupt_mcwdt_0_IRQHandler ; Multi Counter Watchdog Timer interrupt + DCD srss_interrupt_mcwdt_1_IRQHandler ; Multi Counter Watchdog Timer interrupt + DCD srss_interrupt_backup_IRQHandler ; Backup domain interrupt + DCD srss_interrupt_IRQHandler ; Other combined Interrupts for SRSS (LVD, WDT, CLKCAL) + DCD pass_interrupt_ctbs_IRQHandler ; CTBm Interrupt (all CTBms) + DCD bless_interrupt_IRQHandler ; Bluetooth Radio interrupt + DCD cpuss_interrupts_ipc_0_IRQHandler ; CPUSS Inter Process Communication Interrupt #0 + DCD cpuss_interrupts_ipc_1_IRQHandler ; CPUSS Inter Process Communication Interrupt #1 + DCD cpuss_interrupts_ipc_2_IRQHandler ; CPUSS Inter Process Communication Interrupt #2 + DCD cpuss_interrupts_ipc_3_IRQHandler ; CPUSS Inter Process Communication Interrupt #3 + DCD cpuss_interrupts_ipc_4_IRQHandler ; CPUSS Inter Process Communication Interrupt #4 + DCD cpuss_interrupts_ipc_5_IRQHandler ; CPUSS Inter Process Communication Interrupt #5 + DCD cpuss_interrupts_ipc_6_IRQHandler ; CPUSS Inter Process Communication Interrupt #6 + DCD cpuss_interrupts_ipc_7_IRQHandler ; CPUSS Inter Process Communication Interrupt #7 + DCD cpuss_interrupts_ipc_8_IRQHandler ; CPUSS Inter Process Communication Interrupt #8 + DCD cpuss_interrupts_ipc_9_IRQHandler ; CPUSS Inter Process Communication Interrupt #9 + DCD cpuss_interrupts_ipc_10_IRQHandler ; CPUSS Inter Process Communication Interrupt #10 + DCD cpuss_interrupts_ipc_11_IRQHandler ; CPUSS Inter Process Communication Interrupt #11 + DCD cpuss_interrupts_ipc_12_IRQHandler ; CPUSS Inter Process Communication Interrupt #12 + DCD cpuss_interrupts_ipc_13_IRQHandler ; CPUSS Inter Process Communication Interrupt #13 + DCD cpuss_interrupts_ipc_14_IRQHandler ; CPUSS Inter Process Communication Interrupt #14 + DCD cpuss_interrupts_ipc_15_IRQHandler ; CPUSS Inter Process Communication Interrupt #15 + DCD scb_0_interrupt_IRQHandler ; Serial Communication Block #0 + DCD scb_1_interrupt_IRQHandler ; Serial Communication Block #1 + DCD scb_2_interrupt_IRQHandler ; Serial Communication Block #2 + DCD scb_3_interrupt_IRQHandler ; Serial Communication Block #3 + DCD scb_4_interrupt_IRQHandler ; Serial Communication Block #4 + DCD scb_5_interrupt_IRQHandler ; Serial Communication Block #5 + DCD scb_6_interrupt_IRQHandler ; Serial Communication Block #6 + DCD scb_7_interrupt_IRQHandler ; Serial Communication Block #7 + DCD csd_interrupt_IRQHandler ; CSD (Capsense) interrupt + DCD cpuss_interrupts_dw0_0_IRQHandler ; CPUSS DataWire #0, Channel #0 + DCD cpuss_interrupts_dw0_1_IRQHandler ; CPUSS DataWire #0, Channel #1 + DCD cpuss_interrupts_dw0_2_IRQHandler ; CPUSS DataWire #0, Channel #2 + DCD cpuss_interrupts_dw0_3_IRQHandler ; CPUSS DataWire #0, Channel #3 + DCD cpuss_interrupts_dw0_4_IRQHandler ; CPUSS DataWire #0, Channel #4 + DCD cpuss_interrupts_dw0_5_IRQHandler ; CPUSS DataWire #0, Channel #5 + DCD cpuss_interrupts_dw0_6_IRQHandler ; CPUSS DataWire #0, Channel #6 + DCD cpuss_interrupts_dw0_7_IRQHandler ; CPUSS DataWire #0, Channel #7 + DCD cpuss_interrupts_dw0_8_IRQHandler ; CPUSS DataWire #0, Channel #8 + DCD cpuss_interrupts_dw0_9_IRQHandler ; CPUSS DataWire #0, Channel #9 + DCD cpuss_interrupts_dw0_10_IRQHandler ; CPUSS DataWire #0, Channel #10 + DCD cpuss_interrupts_dw0_11_IRQHandler ; CPUSS DataWire #0, Channel #11 + DCD cpuss_interrupts_dw0_12_IRQHandler ; CPUSS DataWire #0, Channel #12 + DCD cpuss_interrupts_dw0_13_IRQHandler ; CPUSS DataWire #0, Channel #13 + DCD cpuss_interrupts_dw0_14_IRQHandler ; CPUSS DataWire #0, Channel #14 + DCD cpuss_interrupts_dw0_15_IRQHandler ; CPUSS DataWire #0, Channel #15 + DCD cpuss_interrupts_dw1_0_IRQHandler ; CPUSS DataWire #1, Channel #0 + DCD cpuss_interrupts_dw1_1_IRQHandler ; CPUSS DataWire #1, Channel #1 + DCD cpuss_interrupts_dw1_2_IRQHandler ; CPUSS DataWire #1, Channel #2 + DCD cpuss_interrupts_dw1_3_IRQHandler ; CPUSS DataWire #1, Channel #3 + DCD cpuss_interrupts_dw1_4_IRQHandler ; CPUSS DataWire #1, Channel #4 + DCD cpuss_interrupts_dw1_5_IRQHandler ; CPUSS DataWire #1, Channel #5 + DCD cpuss_interrupts_dw1_6_IRQHandler ; CPUSS DataWire #1, Channel #6 + DCD cpuss_interrupts_dw1_7_IRQHandler ; CPUSS DataWire #1, Channel #7 + DCD cpuss_interrupts_dw1_8_IRQHandler ; CPUSS DataWire #1, Channel #8 + DCD cpuss_interrupts_dw1_9_IRQHandler ; CPUSS DataWire #1, Channel #9 + DCD cpuss_interrupts_dw1_10_IRQHandler ; CPUSS DataWire #1, Channel #10 + DCD cpuss_interrupts_dw1_11_IRQHandler ; CPUSS DataWire #1, Channel #11 + DCD cpuss_interrupts_dw1_12_IRQHandler ; CPUSS DataWire #1, Channel #12 + DCD cpuss_interrupts_dw1_13_IRQHandler ; CPUSS DataWire #1, Channel #13 + DCD cpuss_interrupts_dw1_14_IRQHandler ; CPUSS DataWire #1, Channel #14 + DCD cpuss_interrupts_dw1_15_IRQHandler ; CPUSS DataWire #1, Channel #15 + DCD cpuss_interrupts_fault_0_IRQHandler ; CPUSS Fault Structure Interrupt #0 + DCD cpuss_interrupts_fault_1_IRQHandler ; CPUSS Fault Structure Interrupt #1 + DCD cpuss_interrupt_crypto_IRQHandler ; CRYPTO Accelerator Interrupt + DCD cpuss_interrupt_fm_IRQHandler ; FLASH Macro Interrupt + DCD cpuss_interrupts_cm0_cti_0_IRQHandler ; CM0+ CTI #0 + DCD cpuss_interrupts_cm0_cti_1_IRQHandler ; CM0+ CTI #1 + DCD cpuss_interrupts_cm4_cti_0_IRQHandler ; CM4 CTI #0 + DCD cpuss_interrupts_cm4_cti_1_IRQHandler ; CM4 CTI #1 + DCD tcpwm_0_interrupts_0_IRQHandler ; TCPWM #0, Counter #0 + DCD tcpwm_0_interrupts_1_IRQHandler ; TCPWM #0, Counter #1 + DCD tcpwm_0_interrupts_2_IRQHandler ; TCPWM #0, Counter #2 + DCD tcpwm_0_interrupts_3_IRQHandler ; TCPWM #0, Counter #3 + DCD tcpwm_0_interrupts_4_IRQHandler ; TCPWM #0, Counter #4 + DCD tcpwm_0_interrupts_5_IRQHandler ; TCPWM #0, Counter #5 + DCD tcpwm_0_interrupts_6_IRQHandler ; TCPWM #0, Counter #6 + DCD tcpwm_0_interrupts_7_IRQHandler ; TCPWM #0, Counter #7 + DCD tcpwm_1_interrupts_0_IRQHandler ; TCPWM #1, Counter #0 + DCD tcpwm_1_interrupts_1_IRQHandler ; TCPWM #1, Counter #1 + DCD tcpwm_1_interrupts_2_IRQHandler ; TCPWM #1, Counter #2 + DCD tcpwm_1_interrupts_3_IRQHandler ; TCPWM #1, Counter #3 + DCD tcpwm_1_interrupts_4_IRQHandler ; TCPWM #1, Counter #4 + DCD tcpwm_1_interrupts_5_IRQHandler ; TCPWM #1, Counter #5 + DCD tcpwm_1_interrupts_6_IRQHandler ; TCPWM #1, Counter #6 + DCD tcpwm_1_interrupts_7_IRQHandler ; TCPWM #1, Counter #7 + DCD tcpwm_1_interrupts_8_IRQHandler ; TCPWM #1, Counter #8 + DCD tcpwm_1_interrupts_9_IRQHandler ; TCPWM #1, Counter #9 + DCD tcpwm_1_interrupts_10_IRQHandler ; TCPWM #1, Counter #10 + DCD tcpwm_1_interrupts_11_IRQHandler ; TCPWM #1, Counter #11 + DCD tcpwm_1_interrupts_12_IRQHandler ; TCPWM #1, Counter #12 + DCD tcpwm_1_interrupts_13_IRQHandler ; TCPWM #1, Counter #13 + DCD tcpwm_1_interrupts_14_IRQHandler ; TCPWM #1, Counter #14 + DCD tcpwm_1_interrupts_15_IRQHandler ; TCPWM #1, Counter #15 + DCD tcpwm_1_interrupts_16_IRQHandler ; TCPWM #1, Counter #16 + DCD tcpwm_1_interrupts_17_IRQHandler ; TCPWM #1, Counter #17 + DCD tcpwm_1_interrupts_18_IRQHandler ; TCPWM #1, Counter #18 + DCD tcpwm_1_interrupts_19_IRQHandler ; TCPWM #1, Counter #19 + DCD tcpwm_1_interrupts_20_IRQHandler ; TCPWM #1, Counter #20 + DCD tcpwm_1_interrupts_21_IRQHandler ; TCPWM #1, Counter #21 + DCD tcpwm_1_interrupts_22_IRQHandler ; TCPWM #1, Counter #22 + DCD tcpwm_1_interrupts_23_IRQHandler ; TCPWM #1, Counter #23 + DCD udb_interrupts_0_IRQHandler ; UDB Interrupt #0 + DCD udb_interrupts_1_IRQHandler ; UDB Interrupt #1 + DCD udb_interrupts_2_IRQHandler ; UDB Interrupt #2 + DCD udb_interrupts_3_IRQHandler ; UDB Interrupt #3 + DCD udb_interrupts_4_IRQHandler ; UDB Interrupt #4 + DCD udb_interrupts_5_IRQHandler ; UDB Interrupt #5 + DCD udb_interrupts_6_IRQHandler ; UDB Interrupt #6 + DCD udb_interrupts_7_IRQHandler ; UDB Interrupt #7 + DCD udb_interrupts_8_IRQHandler ; UDB Interrupt #8 + DCD udb_interrupts_9_IRQHandler ; UDB Interrupt #9 + DCD udb_interrupts_10_IRQHandler ; UDB Interrupt #10 + DCD udb_interrupts_11_IRQHandler ; UDB Interrupt #11 + DCD udb_interrupts_12_IRQHandler ; UDB Interrupt #12 + DCD udb_interrupts_13_IRQHandler ; UDB Interrupt #13 + DCD udb_interrupts_14_IRQHandler ; UDB Interrupt #14 + DCD udb_interrupts_15_IRQHandler ; UDB Interrupt #15 + DCD pass_interrupt_sar_IRQHandler ; SAR ADC interrupt + DCD audioss_interrupt_i2s_IRQHandler ; I2S Audio interrupt + DCD audioss_interrupt_pdm_IRQHandler ; PDM/PCM Audio interrupt + DCD profile_interrupt_IRQHandler ; Energy Profiler interrupt + DCD smif_interrupt_IRQHandler ; Serial Memory Interface interrupt + DCD usb_interrupt_hi_IRQHandler ; USB Interrupt + DCD usb_interrupt_med_IRQHandler ; USB Interrupt + DCD usb_interrupt_lo_IRQHandler ; USB Interrupt + DCD pass_interrupt_dacs_IRQHandler ; Consolidated interrrupt for all DACs + +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + + EXPORT __ramVectors + AREA RESET_RAM, READWRITE, NOINIT +__ramVectors SPACE __Vectors_Size + + + AREA |.text|, CODE, READONLY + + +; Saves and disables the interrupts +Cy_SaveIRQ PROC + EXPORT Cy_SaveIRQ + MRS r0, PRIMASK + CPSID I + BX LR + ENDP + + +; Restores the interrupts +Cy_RestoreIRQ PROC + EXPORT Cy_RestoreIRQ + MSR PRIMASK, r0 + BX LR + ENDP + + +; Weak function for startup customization +Cy_OnResetUser PROC + EXPORT Cy_OnResetUser [WEAK] + BX LR + ENDP + + +; Reset Handler +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT Cy_SystemInitFpuEnable + IMPORT __main + + ; Define strong function for startup customization + BL Cy_OnResetUser + + ; Copy vectors from ROM to RAM + LDR r1, =__Vectors + LDR r0, =__ramVectors + LDR r2, =__Vectors_Size +Vectors_Copy + LDR r3, [r1] + STR r3, [r0] + ADDS r0, r0, #4 + ADDS r1, r1, #4 + SUBS r2, r2, #1 + CMP r2, #0 + BNE Vectors_Copy + + ; Update Vector Table Offset Register. */ + LDR r0, =__ramVectors + LDR r1, =0xE000ED08 + STR r0, [r1] + dsb 0xF + + ; Enable the FPU if used + LDR R0, =Cy_SystemInitFpuEnable + BLX R0 + + LDR R0, =__main + BLX R0 + + ; Should never get here + B . + + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP + +Cy_SysLib_FaultHandler PROC + EXPORT Cy_SysLib_FaultHandler [WEAK] + B . + ENDP +HardFault_Wrapper\ + PROC + EXPORT HardFault_Wrapper [WEAK] + movs r0, #4 + mov r1, LR + tst r0, r1 + beq L_MSP + mrs r0, PSP + bl L_API_call +L_MSP + mrs r0, MSP +L_API_call + bl Cy_SysLib_FaultHandler + ENDP +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B HardFault_Wrapper + ENDP +MemManage_Handler\ + PROC + EXPORT MemManage_Handler [WEAK] + B HardFault_Wrapper + ENDP +BusFault_Handler\ + PROC + EXPORT BusFault_Handler [WEAK] + B HardFault_Wrapper + ENDP +UsageFault_Handler\ + PROC + EXPORT UsageFault_Handler [WEAK] + B HardFault_Wrapper + ENDP +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP +DebugMon_Handler\ + PROC + EXPORT DebugMon_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 Default_Handler [WEAK] + EXPORT ioss_interrupts_gpio_0_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_1_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_2_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_3_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_4_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_5_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_6_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_7_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_8_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_9_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_10_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_11_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_12_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_13_IRQHandler [WEAK] + EXPORT ioss_interrupts_gpio_14_IRQHandler [WEAK] + EXPORT ioss_interrupt_gpio_IRQHandler [WEAK] + EXPORT ioss_interrupt_vdd_IRQHandler [WEAK] + EXPORT lpcomp_interrupt_IRQHandler [WEAK] + EXPORT scb_8_interrupt_IRQHandler [WEAK] + EXPORT srss_interrupt_mcwdt_0_IRQHandler [WEAK] + EXPORT srss_interrupt_mcwdt_1_IRQHandler [WEAK] + EXPORT srss_interrupt_backup_IRQHandler [WEAK] + EXPORT srss_interrupt_IRQHandler [WEAK] + EXPORT pass_interrupt_ctbs_IRQHandler [WEAK] + EXPORT bless_interrupt_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_0_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_1_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_2_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_3_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_4_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_5_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_6_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_7_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_8_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_9_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_10_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_11_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_12_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_13_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_14_IRQHandler [WEAK] + EXPORT cpuss_interrupts_ipc_15_IRQHandler [WEAK] + EXPORT scb_0_interrupt_IRQHandler [WEAK] + EXPORT scb_1_interrupt_IRQHandler [WEAK] + EXPORT scb_2_interrupt_IRQHandler [WEAK] + EXPORT scb_3_interrupt_IRQHandler [WEAK] + EXPORT scb_4_interrupt_IRQHandler [WEAK] + EXPORT scb_5_interrupt_IRQHandler [WEAK] + EXPORT scb_6_interrupt_IRQHandler [WEAK] + EXPORT scb_7_interrupt_IRQHandler [WEAK] + EXPORT csd_interrupt_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_0_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_1_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_2_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_3_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_4_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_5_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_6_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_7_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_8_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_9_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_10_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_11_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_12_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_13_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_14_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw0_15_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_0_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_1_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_2_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_3_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_4_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_5_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_6_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_7_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_8_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_9_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_10_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_11_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_12_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_13_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_14_IRQHandler [WEAK] + EXPORT cpuss_interrupts_dw1_15_IRQHandler [WEAK] + EXPORT cpuss_interrupts_fault_0_IRQHandler [WEAK] + EXPORT cpuss_interrupts_fault_1_IRQHandler [WEAK] + EXPORT cpuss_interrupt_crypto_IRQHandler [WEAK] + EXPORT cpuss_interrupt_fm_IRQHandler [WEAK] + EXPORT cpuss_interrupts_cm0_cti_0_IRQHandler [WEAK] + EXPORT cpuss_interrupts_cm0_cti_1_IRQHandler [WEAK] + EXPORT cpuss_interrupts_cm4_cti_0_IRQHandler [WEAK] + EXPORT cpuss_interrupts_cm4_cti_1_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_0_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_1_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_2_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_3_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_4_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_5_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_6_IRQHandler [WEAK] + EXPORT tcpwm_0_interrupts_7_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_0_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_1_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_2_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_3_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_4_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_5_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_6_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_7_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_8_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_9_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_10_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_11_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_12_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_13_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_14_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_15_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_16_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_17_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_18_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_19_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_20_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_21_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_22_IRQHandler [WEAK] + EXPORT tcpwm_1_interrupts_23_IRQHandler [WEAK] + EXPORT udb_interrupts_0_IRQHandler [WEAK] + EXPORT udb_interrupts_1_IRQHandler [WEAK] + EXPORT udb_interrupts_2_IRQHandler [WEAK] + EXPORT udb_interrupts_3_IRQHandler [WEAK] + EXPORT udb_interrupts_4_IRQHandler [WEAK] + EXPORT udb_interrupts_5_IRQHandler [WEAK] + EXPORT udb_interrupts_6_IRQHandler [WEAK] + EXPORT udb_interrupts_7_IRQHandler [WEAK] + EXPORT udb_interrupts_8_IRQHandler [WEAK] + EXPORT udb_interrupts_9_IRQHandler [WEAK] + EXPORT udb_interrupts_10_IRQHandler [WEAK] + EXPORT udb_interrupts_11_IRQHandler [WEAK] + EXPORT udb_interrupts_12_IRQHandler [WEAK] + EXPORT udb_interrupts_13_IRQHandler [WEAK] + EXPORT udb_interrupts_14_IRQHandler [WEAK] + EXPORT udb_interrupts_15_IRQHandler [WEAK] + EXPORT pass_interrupt_sar_IRQHandler [WEAK] + EXPORT audioss_interrupt_i2s_IRQHandler [WEAK] + EXPORT audioss_interrupt_pdm_IRQHandler [WEAK] + EXPORT profile_interrupt_IRQHandler [WEAK] + EXPORT smif_interrupt_IRQHandler [WEAK] + EXPORT usb_interrupt_hi_IRQHandler [WEAK] + EXPORT usb_interrupt_med_IRQHandler [WEAK] + EXPORT usb_interrupt_lo_IRQHandler [WEAK] + EXPORT pass_interrupt_dacs_IRQHandler [WEAK] + +ioss_interrupts_gpio_0_IRQHandler +ioss_interrupts_gpio_1_IRQHandler +ioss_interrupts_gpio_2_IRQHandler +ioss_interrupts_gpio_3_IRQHandler +ioss_interrupts_gpio_4_IRQHandler +ioss_interrupts_gpio_5_IRQHandler +ioss_interrupts_gpio_6_IRQHandler +ioss_interrupts_gpio_7_IRQHandler +ioss_interrupts_gpio_8_IRQHandler +ioss_interrupts_gpio_9_IRQHandler +ioss_interrupts_gpio_10_IRQHandler +ioss_interrupts_gpio_11_IRQHandler +ioss_interrupts_gpio_12_IRQHandler +ioss_interrupts_gpio_13_IRQHandler +ioss_interrupts_gpio_14_IRQHandler +ioss_interrupt_gpio_IRQHandler +ioss_interrupt_vdd_IRQHandler +lpcomp_interrupt_IRQHandler +scb_8_interrupt_IRQHandler +srss_interrupt_mcwdt_0_IRQHandler +srss_interrupt_mcwdt_1_IRQHandler +srss_interrupt_backup_IRQHandler +srss_interrupt_IRQHandler +pass_interrupt_ctbs_IRQHandler +bless_interrupt_IRQHandler +cpuss_interrupts_ipc_0_IRQHandler +cpuss_interrupts_ipc_1_IRQHandler +cpuss_interrupts_ipc_2_IRQHandler +cpuss_interrupts_ipc_3_IRQHandler +cpuss_interrupts_ipc_4_IRQHandler +cpuss_interrupts_ipc_5_IRQHandler +cpuss_interrupts_ipc_6_IRQHandler +cpuss_interrupts_ipc_7_IRQHandler +cpuss_interrupts_ipc_8_IRQHandler +cpuss_interrupts_ipc_9_IRQHandler +cpuss_interrupts_ipc_10_IRQHandler +cpuss_interrupts_ipc_11_IRQHandler +cpuss_interrupts_ipc_12_IRQHandler +cpuss_interrupts_ipc_13_IRQHandler +cpuss_interrupts_ipc_14_IRQHandler +cpuss_interrupts_ipc_15_IRQHandler +scb_0_interrupt_IRQHandler +scb_1_interrupt_IRQHandler +scb_2_interrupt_IRQHandler +scb_3_interrupt_IRQHandler +scb_4_interrupt_IRQHandler +scb_5_interrupt_IRQHandler +scb_6_interrupt_IRQHandler +scb_7_interrupt_IRQHandler +csd_interrupt_IRQHandler +cpuss_interrupts_dw0_0_IRQHandler +cpuss_interrupts_dw0_1_IRQHandler +cpuss_interrupts_dw0_2_IRQHandler +cpuss_interrupts_dw0_3_IRQHandler +cpuss_interrupts_dw0_4_IRQHandler +cpuss_interrupts_dw0_5_IRQHandler +cpuss_interrupts_dw0_6_IRQHandler +cpuss_interrupts_dw0_7_IRQHandler +cpuss_interrupts_dw0_8_IRQHandler +cpuss_interrupts_dw0_9_IRQHandler +cpuss_interrupts_dw0_10_IRQHandler +cpuss_interrupts_dw0_11_IRQHandler +cpuss_interrupts_dw0_12_IRQHandler +cpuss_interrupts_dw0_13_IRQHandler +cpuss_interrupts_dw0_14_IRQHandler +cpuss_interrupts_dw0_15_IRQHandler +cpuss_interrupts_dw1_0_IRQHandler +cpuss_interrupts_dw1_1_IRQHandler +cpuss_interrupts_dw1_2_IRQHandler +cpuss_interrupts_dw1_3_IRQHandler +cpuss_interrupts_dw1_4_IRQHandler +cpuss_interrupts_dw1_5_IRQHandler +cpuss_interrupts_dw1_6_IRQHandler +cpuss_interrupts_dw1_7_IRQHandler +cpuss_interrupts_dw1_8_IRQHandler +cpuss_interrupts_dw1_9_IRQHandler +cpuss_interrupts_dw1_10_IRQHandler +cpuss_interrupts_dw1_11_IRQHandler +cpuss_interrupts_dw1_12_IRQHandler +cpuss_interrupts_dw1_13_IRQHandler +cpuss_interrupts_dw1_14_IRQHandler +cpuss_interrupts_dw1_15_IRQHandler +cpuss_interrupts_fault_0_IRQHandler +cpuss_interrupts_fault_1_IRQHandler +cpuss_interrupt_crypto_IRQHandler +cpuss_interrupt_fm_IRQHandler +cpuss_interrupts_cm0_cti_0_IRQHandler +cpuss_interrupts_cm0_cti_1_IRQHandler +cpuss_interrupts_cm4_cti_0_IRQHandler +cpuss_interrupts_cm4_cti_1_IRQHandler +tcpwm_0_interrupts_0_IRQHandler +tcpwm_0_interrupts_1_IRQHandler +tcpwm_0_interrupts_2_IRQHandler +tcpwm_0_interrupts_3_IRQHandler +tcpwm_0_interrupts_4_IRQHandler +tcpwm_0_interrupts_5_IRQHandler +tcpwm_0_interrupts_6_IRQHandler +tcpwm_0_interrupts_7_IRQHandler +tcpwm_1_interrupts_0_IRQHandler +tcpwm_1_interrupts_1_IRQHandler +tcpwm_1_interrupts_2_IRQHandler +tcpwm_1_interrupts_3_IRQHandler +tcpwm_1_interrupts_4_IRQHandler +tcpwm_1_interrupts_5_IRQHandler +tcpwm_1_interrupts_6_IRQHandler +tcpwm_1_interrupts_7_IRQHandler +tcpwm_1_interrupts_8_IRQHandler +tcpwm_1_interrupts_9_IRQHandler +tcpwm_1_interrupts_10_IRQHandler +tcpwm_1_interrupts_11_IRQHandler +tcpwm_1_interrupts_12_IRQHandler +tcpwm_1_interrupts_13_IRQHandler +tcpwm_1_interrupts_14_IRQHandler +tcpwm_1_interrupts_15_IRQHandler +tcpwm_1_interrupts_16_IRQHandler +tcpwm_1_interrupts_17_IRQHandler +tcpwm_1_interrupts_18_IRQHandler +tcpwm_1_interrupts_19_IRQHandler +tcpwm_1_interrupts_20_IRQHandler +tcpwm_1_interrupts_21_IRQHandler +tcpwm_1_interrupts_22_IRQHandler +tcpwm_1_interrupts_23_IRQHandler +udb_interrupts_0_IRQHandler +udb_interrupts_1_IRQHandler +udb_interrupts_2_IRQHandler +udb_interrupts_3_IRQHandler +udb_interrupts_4_IRQHandler +udb_interrupts_5_IRQHandler +udb_interrupts_6_IRQHandler +udb_interrupts_7_IRQHandler +udb_interrupts_8_IRQHandler +udb_interrupts_9_IRQHandler +udb_interrupts_10_IRQHandler +udb_interrupts_11_IRQHandler +udb_interrupts_12_IRQHandler +udb_interrupts_13_IRQHandler +udb_interrupts_14_IRQHandler +udb_interrupts_15_IRQHandler +pass_interrupt_sar_IRQHandler +audioss_interrupt_i2s_IRQHandler +audioss_interrupt_pdm_IRQHandler +profile_interrupt_IRQHandler +smif_interrupt_IRQHandler +usb_interrupt_hi_IRQHandler +usb_interrupt_med_IRQHandler +usb_interrupt_lo_IRQHandler +pass_interrupt_dacs_IRQHandler + + B . + ENDP + + ALIGN + + END + + +; [] END OF FILE diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm4_dual.ld b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm4_dual.ld similarity index 77% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm4_dual.ld rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm4_dual.ld index 8192d3318e..1934071efc 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm4_dual.ld +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_GCC_ARM/cy8c6xx7_cm4_dual.ld @@ -1,9 +1,13 @@ /***************************************************************************//** * \file cy8c6xx7_cm4_dual.ld -* \version 2.0 +* \version 2.10 * * Linker file for the GNU C compiler. * +* The main purpose of the linker script is to describe how the sections in the +* input files should be mapped into the output file, and to control the memory +* layout of the output file. +* * \note The entry point location is fixed and starts at 0x10000000. The valid * application image should be placed there. * @@ -15,7 +19,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -35,21 +39,37 @@ ENTRY(Reset_Handler) */ EXTERN(Reset_Handler) - -/* Linker script to configure memory regions. */ +/* The MEMORY section below describes the location and size of blocks of memory in the target. +* Use this section to specify the memory regions available for allocation. +*/ MEMORY { - flash (rx) : ORIGIN = 0x10080000, LENGTH = 0x80000 - wflash (rx) : ORIGIN = 0x14000000, LENGTH = 0x8000 /* 32 KB */ - sflash_user_data (rx) : ORIGIN = 0x16000800, LENGTH = 0x800 - sflash_nar (rx) : ORIGIN = 0x16001A00, LENGTH = 0x200 - sflash_public_key (rx) : ORIGIN = 0x16005A00, LENGTH = 0xC00 - sflash_toc_2 (rx) : ORIGIN = 0x16007C00, LENGTH = 0x400 - xip (rx) : ORIGIN = 0x18000000, LENGTH = 0x8000000 /* 128 MB */ - efuse (r) : ORIGIN = 0x90700000, LENGTH = 0x100000 /* 1 MB */ - ram (rwx) : ORIGIN = 0x08024000, LENGTH = 0x23800 -} + /* The ram and flash regions control RAM and flash memory allocation for the CM4 core. + * You can change the memory allocation by editing the 'ram' and 'flash' regions. + * Note that 2 KB of RAM (at the end of the RAM section) are reserved for system use. + * Using this memory region for other purposes will lead to unexpected behavior. + * Your changes must be aligned with the corresponding memory regions for CM0+ core in 'xx_cm0plus.ld', + * where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.ld'. + */ + ram (rwx) : ORIGIN = 0x08010000, LENGTH = 0x37800 + flash (rx) : ORIGIN = 0x10080000, LENGTH = 0x78000 + /* This is a 32K flash region used for EEPROM emulation. This region can also be used as the general purpose flash. + * You can assign sections to this memory region for only one of the cores. + * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region. + * Therefore, repurposing this memory region will prevent such middleware from operation. + */ + em_eeprom (rx) : ORIGIN = 0x14000000, LENGTH = 0x8000 /* 32 KB */ + + /* The following regions define device specific memory regions and must not be changed. */ + sflash_user_data (rx) : ORIGIN = 0x16000800, LENGTH = 0x800 /* Supervisory flash: User data */ + sflash_nar (rx) : ORIGIN = 0x16001A00, LENGTH = 0x200 /* Supervisory flash: Normal Access Restrictions (NAR) */ + sflash_public_key (rx) : ORIGIN = 0x16005A00, LENGTH = 0xC00 /* Supervisory flash: Public Key */ + sflash_toc_2 (rx) : ORIGIN = 0x16007C00, LENGTH = 0x200 /* Supervisory flash: Table of Content # 2 */ + sflash_rtoc_2 (rx) : ORIGIN = 0x16007E00, LENGTH = 0x200 /* Supervisory flash: Table of Content # 2 Copy */ + xip (rx) : ORIGIN = 0x18000000, LENGTH = 0x8000000 /* 128 MB */ + efuse (r) : ORIGIN = 0x90700000, LENGTH = 0x100000 /* 1 MB */ +} /* Library configurations */ GROUP(libgcc.a libc.a libm.a libnosys.a) @@ -124,6 +144,34 @@ SECTIONS *(.rodata .rodata.* .constdata .constdata.* .conststring .conststring.*) KEEP(*(.eh_frame*)) + + /* To copy multiple ROM to RAM sections, + * uncomment copy table section and, + * define __STARTUP_COPY_MULTIPLE in startup_psoc63_cm4.S */ + . = ALIGN(4); + __copy_table_start__ = .; + + /* Copy interrupt vectors from flash to RAM */ + LONG (__Vectors) /* From */ + LONG (__ram_vectors_start__) /* To */ + LONG (__Vectors_End - __Vectors) /* Size */ + + /* Copy data section to RAM */ + LONG (__etext) /* From */ + LONG (__data_start__) /* To */ + LONG (__data_end__ - __data_start__) /* Size */ + + __copy_table_end__ = .; + + /* To clear multiple BSS sections, + * uncomment zero table section and, + * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_psoc63_cm4.S */ + . = ALIGN(4); + __zero_table_start__ = .; + LONG (__bss_start__) + LONG (__bss_end__ - __bss_start__) + __zero_table_end__ = .; + } > flash @@ -140,41 +188,6 @@ SECTIONS } > flash __exidx_end = .; - - /* To copy multiple ROM to RAM sections, - * uncomment .copy.table section and, - * define __STARTUP_COPY_MULTIPLE in startup_psoc63_cm4.S */ - .copy.table : - { - . = ALIGN(4); - __copy_table_start__ = .; - - /* Copy interrupt vectors from flash to RAM */ - LONG (__Vectors) /* From */ - LONG (__ram_vectors_start__) /* To */ - LONG (__Vectors_End - __Vectors) /* Size */ - - /* Copy data section to RAM */ - LONG (__etext) /* From */ - LONG (__data_start__) /* To */ - LONG (__data_end__ - __data_start__) /* Size */ - - __copy_table_end__ = .; - } > flash - - - /* To clear multiple BSS sections, - * uncomment .zero.table section and, - * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_psoc63_cm4.S */ - .zero.table : - { - . = ALIGN(4); - __zero_table_start__ = .; - LONG (__bss_start__) - LONG (__bss_end__ - __bss_start__) - __zero_table_end__ = .; - } > flash - __etext = . ; @@ -294,11 +307,11 @@ SECTIONS } > flash - /* Work Flash */ - .cy_wflash : + /* Emulated EEPROM Flash area */ + .cy_em_eeprom : { - KEEP(*(.cy_wflash)) - } > wflash + KEEP(*(.cy_em_eeprom)) + } > em_eeprom /* Supervisory Flash: User data */ @@ -328,6 +341,13 @@ SECTIONS KEEP(*(.cy_toc_part2)) } > sflash_toc_2 + + /* Supervisory Flash: Table of Content # 2 Copy */ + .cy_rtoc_part2 : + { + KEEP(*(.cy_rtoc_part2)) + } > sflash_rtoc_2 + /* Places the code in the Execute in Place (XIP) section. See the smif driver * documentation for details. @@ -352,13 +372,13 @@ SECTIONS } -/* The following symbols used by the cypdlelftool. */ +/* The following symbols used by the cymcuelftool. */ /* Flash */ __cy_memory_0_start = 0x10000000; __cy_memory_0_length = 0x00100000; __cy_memory_0_row_size = 0x200; -/* Working Flash */ +/* Emulated EEPROM Flash area */ __cy_memory_1_start = 0x14000000; __cy_memory_1_length = 0x8000; __cy_memory_1_row_size = 0x200; diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm4.S b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm4.S similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm4.S rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm4.S index 5a1c62d640..6deba77053 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm4.S +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_GCC_ARM/startup_psoc63_cm4.S @@ -293,7 +293,6 @@ Cy_RestoreIRQ: Reset_Handler: bl Cy_OnResetUser - cpsid i /* Firstly it copies data from read only memory to RAM. There are two schemes * to copy. One can copy more than one sections. Another can only copy @@ -414,18 +413,14 @@ Reset_Handler: /* Update Vector Table Offset Register. */ ldr r0, =__ramVectors - ldr r1, =CY_CPU_VTOR_ADDR + ldr r1, =CY_CPU_VTOR_ADDR str r0, [r1] dsb 0xF - /* Enable the FPU if used */ - bl Cy_SystemInitFpuEnable + /* Enable the FPU if used */ + bl Cy_SystemInitFpuEnable -#ifndef __NO_SYSTEM_INIT - bl SystemInit -#endif - - bl main + bl _start /* Should never get here */ b . diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_IAR/cy8c6xx7_cm4_dual.icf b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_IAR/cy8c6xx7_cm4_dual.icf new file mode 100644 index 0000000000..2e5cc5f697 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_IAR/cy8c6xx7_cm4_dual.icf @@ -0,0 +1,219 @@ +/***************************************************************************//** +* \file cy8c6xx7_cm4_dual.icf +* \version 2.10 +* +* Linker file for the IAR compiler. +* +* The main purpose of the linker script is to describe how the sections in the +* input files should be mapped into the output file, and to control the memory +* layout of the output file. +* +* \note The entry point is fixed and starts at 0x10000000. The valid application +* image should be placed there. +* +* \note The linker files included with the PDL template projects must be generic +* and handle all common use cases. Your project may not use every section +* defined in the linker files. In that case you may see warnings during the +* build process. In your project, you can simply comment out or remove the +* relevant code in the linker file. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_4.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x00000000; + +/* The symbols below define the location and size of blocks of memory in the target. + * Use these symbols to specify the memory regions available for allocation. + */ + +/* The following symbols control RAM and flash memory allocation for the CM4 core. + * You can change the memory allocation by editing RAM and Flash symbols. + * Note that 2 KB of RAM (at the end of the RAM section) are reserved for system use. + * Using this memory region for other purposes will lead to unexpected behavior. + * Your changes must be aligned with the corresponding symbols for CM0+ core in 'xx_cm0plus.icf', + * where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.icf'. + */ +/* RAM */ +define symbol __ICFEDIT_region_IRAM1_start__ = 0x08010000; +define symbol __ICFEDIT_region_IRAM1_end__ = 0x08047800; +/* Flash */ +define symbol __ICFEDIT_region_IROM1_start__ = 0x10080000; +define symbol __ICFEDIT_region_IROM1_end__ = 0x100F8000; + +/* The following symbols define a 32K flash region used for EEPROM emulation. + * This region can also be used as the general purpose flash. + * You can assign sections to this memory region for only one of the cores. + * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region. + * Therefore, repurposing this memory region will prevent such middleware from operation. + */ +define symbol __ICFEDIT_region_IROM2_start__ = 0x14000000; +define symbol __ICFEDIT_region_IROM2_end__ = 0x14007FFF; + +/* The following symbols define device specific memory regions and must not be changed. */ +/* Supervisory FLASH - User Data */ +define symbol __ICFEDIT_region_IROM3_start__ = 0x16000800; +define symbol __ICFEDIT_region_IROM3_end__ = 0x160007FF; + +/* Supervisory FLASH - Normal Access Restrictions (NAR) */ +define symbol __ICFEDIT_region_IROM4_start__ = 0x16001A00; +define symbol __ICFEDIT_region_IROM4_end__ = 0x16001BFF; + +/* Supervisory FLASH - Public Key */ +define symbol __ICFEDIT_region_IROM5_start__ = 0x16005A00; +define symbol __ICFEDIT_region_IROM5_end__ = 0x160065FF; + +/* Supervisory FLASH - Table of Content # 2 */ +define symbol __ICFEDIT_region_IROM6_start__ = 0x16007C00; +define symbol __ICFEDIT_region_IROM6_end__ = 0x16007DFF; + +/* Supervisory FLASH - Table of Content # 2 Copy */ +define symbol __ICFEDIT_region_IROM7_start__ = 0x16007E00; +define symbol __ICFEDIT_region_IROM7_end__ = 0x16007FFF; + +/* eFuse */ +define symbol __ICFEDIT_region_IROM8_start__ = 0x90700000; +define symbol __ICFEDIT_region_IROM8_end__ = 0x907FFFFF; + +/* XIP */ +define symbol __ICFEDIT_region_EROM1_start__ = 0x18000000; +define symbol __ICFEDIT_region_EROM1_end__ = 0x1FFFFFFF; + +define symbol __ICFEDIT_region_EROM2_start__ = 0x0; +define symbol __ICFEDIT_region_EROM2_end__ = 0x0; +define symbol __ICFEDIT_region_EROM3_start__ = 0x0; +define symbol __ICFEDIT_region_EROM3_end__ = 0x0; + + +define symbol __ICFEDIT_region_IRAM2_start__ = 0x0; +define symbol __ICFEDIT_region_IRAM2_end__ = 0x0; +define symbol __ICFEDIT_region_ERAM1_start__ = 0x0; +define symbol __ICFEDIT_region_ERAM1_end__ = 0x0; +define symbol __ICFEDIT_region_ERAM2_start__ = 0x0; +define symbol __ICFEDIT_region_ERAM2_end__ = 0x0; +define symbol __ICFEDIT_region_ERAM3_start__ = 0x0; +define symbol __ICFEDIT_region_ERAM3_end__ = 0x0; +/*-Sizes-*/ +if (!isdefinedsymbol(__STACK_SIZE)) { + define symbol __ICFEDIT_size_cstack__ = 0x1000; +} else { + define symbol __ICFEDIT_size_cstack__ = __STACK_SIZE; +} +define symbol __ICFEDIT_size_proc_stack__ = 0x0; +if (!isdefinedsymbol(__HEAP_SIZE)) { + define symbol __ICFEDIT_size_heap__ = 0x3800; +} else { + define symbol __ICFEDIT_size_heap__ = __HEAP_SIZE; +} +/**** End of ICF editor section. ###ICF###*/ + +define memory mem with size = 4G; +define region IROM1_region = mem:[from __ICFEDIT_region_IROM1_start__ to __ICFEDIT_region_IROM1_end__]; +define region IROM2_region = mem:[from __ICFEDIT_region_IROM2_start__ to __ICFEDIT_region_IROM2_end__]; +define region IROM3_region = mem:[from __ICFEDIT_region_IROM3_start__ to __ICFEDIT_region_IROM3_end__]; +define region IROM4_region = mem:[from __ICFEDIT_region_IROM4_start__ to __ICFEDIT_region_IROM4_end__]; +define region IROM5_region = mem:[from __ICFEDIT_region_IROM5_start__ to __ICFEDIT_region_IROM5_end__]; +define region IROM6_region = mem:[from __ICFEDIT_region_IROM6_start__ to __ICFEDIT_region_IROM6_end__]; +define region IROM7_region = mem:[from __ICFEDIT_region_IROM7_start__ to __ICFEDIT_region_IROM7_end__]; +define region IROM8_region = mem:[from __ICFEDIT_region_IROM8_start__ to __ICFEDIT_region_IROM8_end__]; +define region EROM1_region = mem:[from __ICFEDIT_region_EROM1_start__ to __ICFEDIT_region_EROM1_end__]; +define region IRAM1_region = mem:[from __ICFEDIT_region_IRAM1_start__ to __ICFEDIT_region_IRAM1_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block PROC_STACK with alignment = 8, size = __ICFEDIT_size_proc_stack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; +define block HSTACK {block HEAP, block PROC_STACK, last block CSTACK}; +define block RO {first section .intvec, readonly}; + +/*-Initializations-*/ +initialize by copy { readwrite }; +do not initialize { section .noinit, section .intvec_ram }; + + +/*-Placement-*/ + +/* Flash */ +place at start of IROM1_region { block RO }; +".cy_app_signature" : place at address (__ICFEDIT_region_IROM1_end__ - 0x200) { section .cy_app_signature }; + +/* Emulated EEPROM Flash area */ +".cy_em_eeprom" : place at start of IROM2_region { section .cy_em_eeprom }; + +/* Supervisory Flash - User Data */ +".cy_sflash_user_data" : place at start of IROM3_region { section .cy_sflash_user_data }; + +/* Supervisory Flash - NAR */ +".cy_sflash_nar" : place at start of IROM4_region { section .cy_sflash_nar }; + +/* Supervisory Flash - Public Key */ +".cy_sflash_public_key" : place at start of IROM5_region { section .cy_sflash_public_key }; + +/* Supervisory Flash - TOC2 */ +".cy_toc_part2" : place at start of IROM6_region { section .cy_toc_part2 }; + +/* Supervisory Flash - RTOC2 */ +".cy_rtoc_part2" : place at start of IROM7_region { section .cy_rtoc_part2 }; + +/* eFuse */ +".cy_efuse" : place at start of IROM8_region { section .cy_efuse }; + +/* Execute in Place (XIP). See the smif driver documentation for details. */ +".cy_xip" : place at start of EROM1_region { section .cy_xip }; + +/* RAM */ +place at start of IRAM1_region { readwrite section .intvec_ram}; +place in IRAM1_region { readwrite }; +place at end of IRAM1_region { block HSTACK }; + +/* These sections are used for additional metadata (silicon revision, Silicon/JTAG ID, etc.) storage. */ +".cymeta" : place at address mem : 0x90500000 { readonly section .cymeta }; + + +keep { section .cy_app_signature, + section .cy_em_eeprom, + section .cy_sflash_user_data, + section .cy_sflash_nar, + section .cy_sflash_public_key, + section .cy_toc_part2, + section .cy_rtoc_part2, + section .cy_efuse, + section .cy_xip, + section .cymeta, + }; + + +/* The following symbols used by the cymcuelftool. */ +/* Flash */ +define exported symbol __cy_memory_0_start = 0x10000000; +define exported symbol __cy_memory_0_length = 0x00100000; +define exported symbol __cy_memory_0_row_size = 0x200; + +/* Emulated EEPROM Flash area */ +define exported symbol __cy_memory_1_start = 0x14000000; +define exported symbol __cy_memory_1_length = 0x8000; +define exported symbol __cy_memory_1_row_size = 0x200; + +/* Supervisory Flash */ +define exported symbol __cy_memory_2_start = 0x16000000; +define exported symbol __cy_memory_2_length = 0x8000; +define exported symbol __cy_memory_2_row_size = 0x200; + +/* XIP */ +define exported symbol __cy_memory_3_start = 0x18000000; +define exported symbol __cy_memory_3_length = 0x08000000; +define exported symbol __cy_memory_3_row_size = 0x200; + +/* eFuse */ +define exported symbol __cy_memory_4_start = 0x90700000; +define exported symbol __cy_memory_4_length = 0x100000; +define exported symbol __cy_memory_4_row_size = 1; + +/* EOF */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_IAR/startup_psoc63_cm4.s b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_IAR/startup_psoc63_cm4.s new file mode 100644 index 0000000000..e6329ba27a --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/TOOLCHAIN_IAR/startup_psoc63_cm4.s @@ -0,0 +1,1148 @@ +;/**************************************************************************//** +; * @file startup_psoc63_cm4.s +; * @brief CMSIS Core Device Startup File for +; * ARMCM4 Device Series +; * @version V5.00 +; * @date 08. March 2016 +; ******************************************************************************/ +;/* +; * Copyright (c) 2009-2016 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * 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 +; * +; * 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. +; */ + +; +; The modules in this file are included in the libraries, and may be replaced +; by any user-defined modules that define the PUBLIC symbol _program_start or +; a user defined start symbol. +; To override the cstartup defined in the library, simply add your modified +; version to the workbench project. +; +; The vector table is normally located at address 0. +; When debugging in RAM, it can be located in RAM, aligned to at least 2^6. +; The name "__vector_table" has special meaning for C-SPY: +; it is where the SP start value is found, and the NVIC vector +; table register (VTOR) is initialized to this address if != 0. +; +; Cortex-M version +; + + MODULE ?cstartup + + ;; Forward declaration of sections. + SECTION CSTACK:DATA:NOROOT(3) + SECTION .intvec_ram:DATA:NOROOT(2) + SECTION .intvec:CODE:NOROOT(2) + + EXTERN __iar_program_start + EXTERN Cy_SystemInitFpuEnable + PUBLIC __vector_table + PUBLIC __vector_table_0x1c + PUBLIC __Vectors + PUBLIC __Vectors_End + PUBLIC __Vectors_Size + PUBLIC __ramVectors + + DATA + +__vector_table + DCD sfe(CSTACK) + DCD Reset_Handler + + DCD 0x0000000D ; NMI_Handler is defined in ROM code + DCD HardFault_Handler + DCD MemManage_Handler + DCD BusFault_Handler + DCD UsageFault_Handler +__vector_table_0x1c + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler + DCD DebugMon_Handler + DCD 0 + DCD PendSV_Handler + DCD SysTick_Handler + + + ; External interrupts Description + DCD ioss_interrupts_gpio_0_IRQHandler ; GPIO Port Interrupt #0 + DCD ioss_interrupts_gpio_1_IRQHandler ; GPIO Port Interrupt #1 + DCD ioss_interrupts_gpio_2_IRQHandler ; GPIO Port Interrupt #2 + DCD ioss_interrupts_gpio_3_IRQHandler ; GPIO Port Interrupt #3 + DCD ioss_interrupts_gpio_4_IRQHandler ; GPIO Port Interrupt #4 + DCD ioss_interrupts_gpio_5_IRQHandler ; GPIO Port Interrupt #5 + DCD ioss_interrupts_gpio_6_IRQHandler ; GPIO Port Interrupt #6 + DCD ioss_interrupts_gpio_7_IRQHandler ; GPIO Port Interrupt #7 + DCD ioss_interrupts_gpio_8_IRQHandler ; GPIO Port Interrupt #8 + DCD ioss_interrupts_gpio_9_IRQHandler ; GPIO Port Interrupt #9 + DCD ioss_interrupts_gpio_10_IRQHandler ; GPIO Port Interrupt #10 + DCD ioss_interrupts_gpio_11_IRQHandler ; GPIO Port Interrupt #11 + DCD ioss_interrupts_gpio_12_IRQHandler ; GPIO Port Interrupt #12 + DCD ioss_interrupts_gpio_13_IRQHandler ; GPIO Port Interrupt #13 + DCD ioss_interrupts_gpio_14_IRQHandler ; GPIO Port Interrupt #14 + DCD ioss_interrupt_gpio_IRQHandler ; GPIO All Ports + DCD ioss_interrupt_vdd_IRQHandler ; GPIO Supply Detect Interrupt + DCD lpcomp_interrupt_IRQHandler ; Low Power Comparator Interrupt + DCD scb_8_interrupt_IRQHandler ; Serial Communication Block #8 (DeepSleep capable) + DCD srss_interrupt_mcwdt_0_IRQHandler ; Multi Counter Watchdog Timer interrupt + DCD srss_interrupt_mcwdt_1_IRQHandler ; Multi Counter Watchdog Timer interrupt + DCD srss_interrupt_backup_IRQHandler ; Backup domain interrupt + DCD srss_interrupt_IRQHandler ; Other combined Interrupts for SRSS (LVD, WDT, CLKCAL) + DCD pass_interrupt_ctbs_IRQHandler ; CTBm Interrupt (all CTBms) + DCD bless_interrupt_IRQHandler ; Bluetooth Radio interrupt + DCD cpuss_interrupts_ipc_0_IRQHandler ; CPUSS Inter Process Communication Interrupt #0 + DCD cpuss_interrupts_ipc_1_IRQHandler ; CPUSS Inter Process Communication Interrupt #1 + DCD cpuss_interrupts_ipc_2_IRQHandler ; CPUSS Inter Process Communication Interrupt #2 + DCD cpuss_interrupts_ipc_3_IRQHandler ; CPUSS Inter Process Communication Interrupt #3 + DCD cpuss_interrupts_ipc_4_IRQHandler ; CPUSS Inter Process Communication Interrupt #4 + DCD cpuss_interrupts_ipc_5_IRQHandler ; CPUSS Inter Process Communication Interrupt #5 + DCD cpuss_interrupts_ipc_6_IRQHandler ; CPUSS Inter Process Communication Interrupt #6 + DCD cpuss_interrupts_ipc_7_IRQHandler ; CPUSS Inter Process Communication Interrupt #7 + DCD cpuss_interrupts_ipc_8_IRQHandler ; CPUSS Inter Process Communication Interrupt #8 + DCD cpuss_interrupts_ipc_9_IRQHandler ; CPUSS Inter Process Communication Interrupt #9 + DCD cpuss_interrupts_ipc_10_IRQHandler ; CPUSS Inter Process Communication Interrupt #10 + DCD cpuss_interrupts_ipc_11_IRQHandler ; CPUSS Inter Process Communication Interrupt #11 + DCD cpuss_interrupts_ipc_12_IRQHandler ; CPUSS Inter Process Communication Interrupt #12 + DCD cpuss_interrupts_ipc_13_IRQHandler ; CPUSS Inter Process Communication Interrupt #13 + DCD cpuss_interrupts_ipc_14_IRQHandler ; CPUSS Inter Process Communication Interrupt #14 + DCD cpuss_interrupts_ipc_15_IRQHandler ; CPUSS Inter Process Communication Interrupt #15 + DCD scb_0_interrupt_IRQHandler ; Serial Communication Block #0 + DCD scb_1_interrupt_IRQHandler ; Serial Communication Block #1 + DCD scb_2_interrupt_IRQHandler ; Serial Communication Block #2 + DCD scb_3_interrupt_IRQHandler ; Serial Communication Block #3 + DCD scb_4_interrupt_IRQHandler ; Serial Communication Block #4 + DCD scb_5_interrupt_IRQHandler ; Serial Communication Block #5 + DCD scb_6_interrupt_IRQHandler ; Serial Communication Block #6 + DCD scb_7_interrupt_IRQHandler ; Serial Communication Block #7 + DCD csd_interrupt_IRQHandler ; CSD (Capsense) interrupt + DCD cpuss_interrupts_dw0_0_IRQHandler ; CPUSS DataWire #0, Channel #0 + DCD cpuss_interrupts_dw0_1_IRQHandler ; CPUSS DataWire #0, Channel #1 + DCD cpuss_interrupts_dw0_2_IRQHandler ; CPUSS DataWire #0, Channel #2 + DCD cpuss_interrupts_dw0_3_IRQHandler ; CPUSS DataWire #0, Channel #3 + DCD cpuss_interrupts_dw0_4_IRQHandler ; CPUSS DataWire #0, Channel #4 + DCD cpuss_interrupts_dw0_5_IRQHandler ; CPUSS DataWire #0, Channel #5 + DCD cpuss_interrupts_dw0_6_IRQHandler ; CPUSS DataWire #0, Channel #6 + DCD cpuss_interrupts_dw0_7_IRQHandler ; CPUSS DataWire #0, Channel #7 + DCD cpuss_interrupts_dw0_8_IRQHandler ; CPUSS DataWire #0, Channel #8 + DCD cpuss_interrupts_dw0_9_IRQHandler ; CPUSS DataWire #0, Channel #9 + DCD cpuss_interrupts_dw0_10_IRQHandler ; CPUSS DataWire #0, Channel #10 + DCD cpuss_interrupts_dw0_11_IRQHandler ; CPUSS DataWire #0, Channel #11 + DCD cpuss_interrupts_dw0_12_IRQHandler ; CPUSS DataWire #0, Channel #12 + DCD cpuss_interrupts_dw0_13_IRQHandler ; CPUSS DataWire #0, Channel #13 + DCD cpuss_interrupts_dw0_14_IRQHandler ; CPUSS DataWire #0, Channel #14 + DCD cpuss_interrupts_dw0_15_IRQHandler ; CPUSS DataWire #0, Channel #15 + DCD cpuss_interrupts_dw1_0_IRQHandler ; CPUSS DataWire #1, Channel #0 + DCD cpuss_interrupts_dw1_1_IRQHandler ; CPUSS DataWire #1, Channel #1 + DCD cpuss_interrupts_dw1_2_IRQHandler ; CPUSS DataWire #1, Channel #2 + DCD cpuss_interrupts_dw1_3_IRQHandler ; CPUSS DataWire #1, Channel #3 + DCD cpuss_interrupts_dw1_4_IRQHandler ; CPUSS DataWire #1, Channel #4 + DCD cpuss_interrupts_dw1_5_IRQHandler ; CPUSS DataWire #1, Channel #5 + DCD cpuss_interrupts_dw1_6_IRQHandler ; CPUSS DataWire #1, Channel #6 + DCD cpuss_interrupts_dw1_7_IRQHandler ; CPUSS DataWire #1, Channel #7 + DCD cpuss_interrupts_dw1_8_IRQHandler ; CPUSS DataWire #1, Channel #8 + DCD cpuss_interrupts_dw1_9_IRQHandler ; CPUSS DataWire #1, Channel #9 + DCD cpuss_interrupts_dw1_10_IRQHandler ; CPUSS DataWire #1, Channel #10 + DCD cpuss_interrupts_dw1_11_IRQHandler ; CPUSS DataWire #1, Channel #11 + DCD cpuss_interrupts_dw1_12_IRQHandler ; CPUSS DataWire #1, Channel #12 + DCD cpuss_interrupts_dw1_13_IRQHandler ; CPUSS DataWire #1, Channel #13 + DCD cpuss_interrupts_dw1_14_IRQHandler ; CPUSS DataWire #1, Channel #14 + DCD cpuss_interrupts_dw1_15_IRQHandler ; CPUSS DataWire #1, Channel #15 + DCD cpuss_interrupts_fault_0_IRQHandler ; CPUSS Fault Structure Interrupt #0 + DCD cpuss_interrupts_fault_1_IRQHandler ; CPUSS Fault Structure Interrupt #1 + DCD cpuss_interrupt_crypto_IRQHandler ; CRYPTO Accelerator Interrupt + DCD cpuss_interrupt_fm_IRQHandler ; FLASH Macro Interrupt + DCD cpuss_interrupts_cm0_cti_0_IRQHandler ; CM0+ CTI #0 + DCD cpuss_interrupts_cm0_cti_1_IRQHandler ; CM0+ CTI #1 + DCD cpuss_interrupts_cm4_cti_0_IRQHandler ; CM4 CTI #0 + DCD cpuss_interrupts_cm4_cti_1_IRQHandler ; CM4 CTI #1 + DCD tcpwm_0_interrupts_0_IRQHandler ; TCPWM #0, Counter #0 + DCD tcpwm_0_interrupts_1_IRQHandler ; TCPWM #0, Counter #1 + DCD tcpwm_0_interrupts_2_IRQHandler ; TCPWM #0, Counter #2 + DCD tcpwm_0_interrupts_3_IRQHandler ; TCPWM #0, Counter #3 + DCD tcpwm_0_interrupts_4_IRQHandler ; TCPWM #0, Counter #4 + DCD tcpwm_0_interrupts_5_IRQHandler ; TCPWM #0, Counter #5 + DCD tcpwm_0_interrupts_6_IRQHandler ; TCPWM #0, Counter #6 + DCD tcpwm_0_interrupts_7_IRQHandler ; TCPWM #0, Counter #7 + DCD tcpwm_1_interrupts_0_IRQHandler ; TCPWM #1, Counter #0 + DCD tcpwm_1_interrupts_1_IRQHandler ; TCPWM #1, Counter #1 + DCD tcpwm_1_interrupts_2_IRQHandler ; TCPWM #1, Counter #2 + DCD tcpwm_1_interrupts_3_IRQHandler ; TCPWM #1, Counter #3 + DCD tcpwm_1_interrupts_4_IRQHandler ; TCPWM #1, Counter #4 + DCD tcpwm_1_interrupts_5_IRQHandler ; TCPWM #1, Counter #5 + DCD tcpwm_1_interrupts_6_IRQHandler ; TCPWM #1, Counter #6 + DCD tcpwm_1_interrupts_7_IRQHandler ; TCPWM #1, Counter #7 + DCD tcpwm_1_interrupts_8_IRQHandler ; TCPWM #1, Counter #8 + DCD tcpwm_1_interrupts_9_IRQHandler ; TCPWM #1, Counter #9 + DCD tcpwm_1_interrupts_10_IRQHandler ; TCPWM #1, Counter #10 + DCD tcpwm_1_interrupts_11_IRQHandler ; TCPWM #1, Counter #11 + DCD tcpwm_1_interrupts_12_IRQHandler ; TCPWM #1, Counter #12 + DCD tcpwm_1_interrupts_13_IRQHandler ; TCPWM #1, Counter #13 + DCD tcpwm_1_interrupts_14_IRQHandler ; TCPWM #1, Counter #14 + DCD tcpwm_1_interrupts_15_IRQHandler ; TCPWM #1, Counter #15 + DCD tcpwm_1_interrupts_16_IRQHandler ; TCPWM #1, Counter #16 + DCD tcpwm_1_interrupts_17_IRQHandler ; TCPWM #1, Counter #17 + DCD tcpwm_1_interrupts_18_IRQHandler ; TCPWM #1, Counter #18 + DCD tcpwm_1_interrupts_19_IRQHandler ; TCPWM #1, Counter #19 + DCD tcpwm_1_interrupts_20_IRQHandler ; TCPWM #1, Counter #20 + DCD tcpwm_1_interrupts_21_IRQHandler ; TCPWM #1, Counter #21 + DCD tcpwm_1_interrupts_22_IRQHandler ; TCPWM #1, Counter #22 + DCD tcpwm_1_interrupts_23_IRQHandler ; TCPWM #1, Counter #23 + DCD udb_interrupts_0_IRQHandler ; UDB Interrupt #0 + DCD udb_interrupts_1_IRQHandler ; UDB Interrupt #1 + DCD udb_interrupts_2_IRQHandler ; UDB Interrupt #2 + DCD udb_interrupts_3_IRQHandler ; UDB Interrupt #3 + DCD udb_interrupts_4_IRQHandler ; UDB Interrupt #4 + DCD udb_interrupts_5_IRQHandler ; UDB Interrupt #5 + DCD udb_interrupts_6_IRQHandler ; UDB Interrupt #6 + DCD udb_interrupts_7_IRQHandler ; UDB Interrupt #7 + DCD udb_interrupts_8_IRQHandler ; UDB Interrupt #8 + DCD udb_interrupts_9_IRQHandler ; UDB Interrupt #9 + DCD udb_interrupts_10_IRQHandler ; UDB Interrupt #10 + DCD udb_interrupts_11_IRQHandler ; UDB Interrupt #11 + DCD udb_interrupts_12_IRQHandler ; UDB Interrupt #12 + DCD udb_interrupts_13_IRQHandler ; UDB Interrupt #13 + DCD udb_interrupts_14_IRQHandler ; UDB Interrupt #14 + DCD udb_interrupts_15_IRQHandler ; UDB Interrupt #15 + DCD pass_interrupt_sar_IRQHandler ; SAR ADC interrupt + DCD audioss_interrupt_i2s_IRQHandler ; I2S Audio interrupt + DCD audioss_interrupt_pdm_IRQHandler ; PDM/PCM Audio interrupt + DCD profile_interrupt_IRQHandler ; Energy Profiler interrupt + DCD smif_interrupt_IRQHandler ; Serial Memory Interface interrupt + DCD usb_interrupt_hi_IRQHandler ; USB Interrupt + DCD usb_interrupt_med_IRQHandler ; USB Interrupt + DCD usb_interrupt_lo_IRQHandler ; USB Interrupt + DCD pass_interrupt_dacs_IRQHandler ; Consolidated interrrupt for all DACs + +__Vectors_End + +__Vectors EQU __vector_table +__Vectors_Size EQU __Vectors_End - __Vectors + + SECTION .intvec_ram:DATA:REORDER:NOROOT(2) +__ramVectors + DS32 __Vectors_Size + + + THUMB + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default handlers +;; + PUBWEAK Default_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Default_Handler + B Default_Handler + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Saves and disables the interrupts +;; + PUBLIC Cy_SaveIRQ + SECTION .text:CODE:REORDER:NOROOT(2) +Cy_SaveIRQ + MRS r0, PRIMASK + CPSID I + BX LR + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Restores the interrupts +;; + PUBLIC Cy_RestoreIRQ + SECTION .text:CODE:REORDER:NOROOT(2) +Cy_RestoreIRQ + MSR PRIMASK, r0 + BX LR + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Weak function for startup customization +;; + PUBWEAK Cy_OnResetUser + SECTION .text:CODE:REORDER:NOROOT(2) +Cy_OnResetUser + BX LR + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Define strong version to return zero for +;; __iar_program_start to skip data sections +;; initialization. +;; + PUBLIC __low_level_init + SECTION .text:CODE:REORDER:NOROOT(2) +__low_level_init + MOVS R0, #1 + BX LR + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default interrupt handlers. +;; + PUBWEAK Reset_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Reset_Handler + + ; Define strong function for startup customization + LDR R0, =Cy_OnResetUser + BLX R0 + + ; Copy vectors from ROM to RAM + LDR r1, =__vector_table + LDR r0, =__ramVectors + LDR r2, =__Vectors_Size +intvec_copy + LDR r3, [r1] + STR r3, [r0] + ADDS r0, r0, #4 + ADDS r1, r1, #4 + SUBS r2, r2, #1 + CMP r2, #0 + BNE intvec_copy + + ; Update Vector Table Offset Register + LDR r0, =__ramVectors + LDR r1, =0xE000ED08 + STR r0, [r1] + dsb + + ; Enable the FPU if used + LDR R0, =Cy_SystemInitFpuEnable + BLX R0 + + LDR R0, =__iar_program_start + BLX R0 + +; Should never get here +Cy_Main_Exited + B Cy_Main_Exited + + + PUBWEAK NMI_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +NMI_Handler + B NMI_Handler + + + PUBWEAK Cy_SysLib_FaultHandler + SECTION .text:CODE:REORDER:NOROOT(1) +Cy_SysLib_FaultHandler + B Cy_SysLib_FaultHandler + + PUBWEAK HardFault_Wrapper + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Wrapper + IMPORT Cy_SysLib_FaultHandler + movs r0, #4 + mov r1, LR + tst r0, r1 + beq L_MSP + mrs r0, PSP + b L_API_call +L_MSP + mrs r0, MSP +L_API_call + ; Storing LR content for Creator call stack trace + push {LR} + bl Cy_SysLib_FaultHandler + + PUBWEAK HardFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Handler + B HardFault_Wrapper + + PUBWEAK MemManage_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +MemManage_Handler + B HardFault_Wrapper + + PUBWEAK BusFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +BusFault_Handler + B HardFault_Wrapper + + PUBWEAK UsageFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +UsageFault_Handler + B HardFault_Wrapper + + PUBWEAK SVC_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SVC_Handler + B SVC_Handler + + PUBWEAK DebugMon_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +DebugMon_Handler + B DebugMon_Handler + + PUBWEAK PendSV_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +PendSV_Handler + B PendSV_Handler + + PUBWEAK SysTick_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SysTick_Handler + B SysTick_Handler + + + ; External interrupts + PUBWEAK ioss_interrupts_gpio_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_0_IRQHandler + B ioss_interrupts_gpio_0_IRQHandler + + PUBWEAK ioss_interrupts_gpio_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_1_IRQHandler + B ioss_interrupts_gpio_1_IRQHandler + + PUBWEAK ioss_interrupts_gpio_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_2_IRQHandler + B ioss_interrupts_gpio_2_IRQHandler + + PUBWEAK ioss_interrupts_gpio_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_3_IRQHandler + B ioss_interrupts_gpio_3_IRQHandler + + PUBWEAK ioss_interrupts_gpio_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_4_IRQHandler + B ioss_interrupts_gpio_4_IRQHandler + + PUBWEAK ioss_interrupts_gpio_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_5_IRQHandler + B ioss_interrupts_gpio_5_IRQHandler + + PUBWEAK ioss_interrupts_gpio_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_6_IRQHandler + B ioss_interrupts_gpio_6_IRQHandler + + PUBWEAK ioss_interrupts_gpio_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_7_IRQHandler + B ioss_interrupts_gpio_7_IRQHandler + + PUBWEAK ioss_interrupts_gpio_8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_8_IRQHandler + B ioss_interrupts_gpio_8_IRQHandler + + PUBWEAK ioss_interrupts_gpio_9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_9_IRQHandler + B ioss_interrupts_gpio_9_IRQHandler + + PUBWEAK ioss_interrupts_gpio_10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_10_IRQHandler + B ioss_interrupts_gpio_10_IRQHandler + + PUBWEAK ioss_interrupts_gpio_11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_11_IRQHandler + B ioss_interrupts_gpio_11_IRQHandler + + PUBWEAK ioss_interrupts_gpio_12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_12_IRQHandler + B ioss_interrupts_gpio_12_IRQHandler + + PUBWEAK ioss_interrupts_gpio_13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_13_IRQHandler + B ioss_interrupts_gpio_13_IRQHandler + + PUBWEAK ioss_interrupts_gpio_14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupts_gpio_14_IRQHandler + B ioss_interrupts_gpio_14_IRQHandler + + PUBWEAK ioss_interrupt_gpio_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupt_gpio_IRQHandler + B ioss_interrupt_gpio_IRQHandler + + PUBWEAK ioss_interrupt_vdd_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +ioss_interrupt_vdd_IRQHandler + B ioss_interrupt_vdd_IRQHandler + + PUBWEAK lpcomp_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +lpcomp_interrupt_IRQHandler + B lpcomp_interrupt_IRQHandler + + PUBWEAK scb_8_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_8_interrupt_IRQHandler + B scb_8_interrupt_IRQHandler + + PUBWEAK srss_interrupt_mcwdt_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +srss_interrupt_mcwdt_0_IRQHandler + B srss_interrupt_mcwdt_0_IRQHandler + + PUBWEAK srss_interrupt_mcwdt_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +srss_interrupt_mcwdt_1_IRQHandler + B srss_interrupt_mcwdt_1_IRQHandler + + PUBWEAK srss_interrupt_backup_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +srss_interrupt_backup_IRQHandler + B srss_interrupt_backup_IRQHandler + + PUBWEAK srss_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +srss_interrupt_IRQHandler + B srss_interrupt_IRQHandler + + PUBWEAK pass_interrupt_ctbs_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +pass_interrupt_ctbs_IRQHandler + B pass_interrupt_ctbs_IRQHandler + + PUBWEAK bless_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +bless_interrupt_IRQHandler + B bless_interrupt_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_0_IRQHandler + B cpuss_interrupts_ipc_0_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_1_IRQHandler + B cpuss_interrupts_ipc_1_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_2_IRQHandler + B cpuss_interrupts_ipc_2_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_3_IRQHandler + B cpuss_interrupts_ipc_3_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_4_IRQHandler + B cpuss_interrupts_ipc_4_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_5_IRQHandler + B cpuss_interrupts_ipc_5_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_6_IRQHandler + B cpuss_interrupts_ipc_6_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_7_IRQHandler + B cpuss_interrupts_ipc_7_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_8_IRQHandler + B cpuss_interrupts_ipc_8_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_9_IRQHandler + B cpuss_interrupts_ipc_9_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_10_IRQHandler + B cpuss_interrupts_ipc_10_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_11_IRQHandler + B cpuss_interrupts_ipc_11_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_12_IRQHandler + B cpuss_interrupts_ipc_12_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_13_IRQHandler + B cpuss_interrupts_ipc_13_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_14_IRQHandler + B cpuss_interrupts_ipc_14_IRQHandler + + PUBWEAK cpuss_interrupts_ipc_15_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_ipc_15_IRQHandler + B cpuss_interrupts_ipc_15_IRQHandler + + PUBWEAK scb_0_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_0_interrupt_IRQHandler + B scb_0_interrupt_IRQHandler + + PUBWEAK scb_1_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_1_interrupt_IRQHandler + B scb_1_interrupt_IRQHandler + + PUBWEAK scb_2_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_2_interrupt_IRQHandler + B scb_2_interrupt_IRQHandler + + PUBWEAK scb_3_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_3_interrupt_IRQHandler + B scb_3_interrupt_IRQHandler + + PUBWEAK scb_4_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_4_interrupt_IRQHandler + B scb_4_interrupt_IRQHandler + + PUBWEAK scb_5_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_5_interrupt_IRQHandler + B scb_5_interrupt_IRQHandler + + PUBWEAK scb_6_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_6_interrupt_IRQHandler + B scb_6_interrupt_IRQHandler + + PUBWEAK scb_7_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +scb_7_interrupt_IRQHandler + B scb_7_interrupt_IRQHandler + + PUBWEAK csd_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +csd_interrupt_IRQHandler + B csd_interrupt_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_0_IRQHandler + B cpuss_interrupts_dw0_0_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_1_IRQHandler + B cpuss_interrupts_dw0_1_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_2_IRQHandler + B cpuss_interrupts_dw0_2_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_3_IRQHandler + B cpuss_interrupts_dw0_3_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_4_IRQHandler + B cpuss_interrupts_dw0_4_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_5_IRQHandler + B cpuss_interrupts_dw0_5_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_6_IRQHandler + B cpuss_interrupts_dw0_6_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_7_IRQHandler + B cpuss_interrupts_dw0_7_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_8_IRQHandler + B cpuss_interrupts_dw0_8_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_9_IRQHandler + B cpuss_interrupts_dw0_9_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_10_IRQHandler + B cpuss_interrupts_dw0_10_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_11_IRQHandler + B cpuss_interrupts_dw0_11_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_12_IRQHandler + B cpuss_interrupts_dw0_12_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_13_IRQHandler + B cpuss_interrupts_dw0_13_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_14_IRQHandler + B cpuss_interrupts_dw0_14_IRQHandler + + PUBWEAK cpuss_interrupts_dw0_15_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw0_15_IRQHandler + B cpuss_interrupts_dw0_15_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_0_IRQHandler + B cpuss_interrupts_dw1_0_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_1_IRQHandler + B cpuss_interrupts_dw1_1_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_2_IRQHandler + B cpuss_interrupts_dw1_2_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_3_IRQHandler + B cpuss_interrupts_dw1_3_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_4_IRQHandler + B cpuss_interrupts_dw1_4_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_5_IRQHandler + B cpuss_interrupts_dw1_5_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_6_IRQHandler + B cpuss_interrupts_dw1_6_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_7_IRQHandler + B cpuss_interrupts_dw1_7_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_8_IRQHandler + B cpuss_interrupts_dw1_8_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_9_IRQHandler + B cpuss_interrupts_dw1_9_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_10_IRQHandler + B cpuss_interrupts_dw1_10_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_11_IRQHandler + B cpuss_interrupts_dw1_11_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_12_IRQHandler + B cpuss_interrupts_dw1_12_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_13_IRQHandler + B cpuss_interrupts_dw1_13_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_14_IRQHandler + B cpuss_interrupts_dw1_14_IRQHandler + + PUBWEAK cpuss_interrupts_dw1_15_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_dw1_15_IRQHandler + B cpuss_interrupts_dw1_15_IRQHandler + + PUBWEAK cpuss_interrupts_fault_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_fault_0_IRQHandler + B cpuss_interrupts_fault_0_IRQHandler + + PUBWEAK cpuss_interrupts_fault_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_fault_1_IRQHandler + B cpuss_interrupts_fault_1_IRQHandler + + PUBWEAK cpuss_interrupt_crypto_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupt_crypto_IRQHandler + B cpuss_interrupt_crypto_IRQHandler + + PUBWEAK cpuss_interrupt_fm_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupt_fm_IRQHandler + B cpuss_interrupt_fm_IRQHandler + + PUBWEAK cpuss_interrupts_cm0_cti_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_cm0_cti_0_IRQHandler + B cpuss_interrupts_cm0_cti_0_IRQHandler + + PUBWEAK cpuss_interrupts_cm0_cti_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_cm0_cti_1_IRQHandler + B cpuss_interrupts_cm0_cti_1_IRQHandler + + PUBWEAK cpuss_interrupts_cm4_cti_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_cm4_cti_0_IRQHandler + B cpuss_interrupts_cm4_cti_0_IRQHandler + + PUBWEAK cpuss_interrupts_cm4_cti_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +cpuss_interrupts_cm4_cti_1_IRQHandler + B cpuss_interrupts_cm4_cti_1_IRQHandler + + PUBWEAK tcpwm_0_interrupts_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_0_IRQHandler + B tcpwm_0_interrupts_0_IRQHandler + + PUBWEAK tcpwm_0_interrupts_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_1_IRQHandler + B tcpwm_0_interrupts_1_IRQHandler + + PUBWEAK tcpwm_0_interrupts_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_2_IRQHandler + B tcpwm_0_interrupts_2_IRQHandler + + PUBWEAK tcpwm_0_interrupts_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_3_IRQHandler + B tcpwm_0_interrupts_3_IRQHandler + + PUBWEAK tcpwm_0_interrupts_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_4_IRQHandler + B tcpwm_0_interrupts_4_IRQHandler + + PUBWEAK tcpwm_0_interrupts_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_5_IRQHandler + B tcpwm_0_interrupts_5_IRQHandler + + PUBWEAK tcpwm_0_interrupts_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_6_IRQHandler + B tcpwm_0_interrupts_6_IRQHandler + + PUBWEAK tcpwm_0_interrupts_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_0_interrupts_7_IRQHandler + B tcpwm_0_interrupts_7_IRQHandler + + PUBWEAK tcpwm_1_interrupts_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_0_IRQHandler + B tcpwm_1_interrupts_0_IRQHandler + + PUBWEAK tcpwm_1_interrupts_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_1_IRQHandler + B tcpwm_1_interrupts_1_IRQHandler + + PUBWEAK tcpwm_1_interrupts_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_2_IRQHandler + B tcpwm_1_interrupts_2_IRQHandler + + PUBWEAK tcpwm_1_interrupts_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_3_IRQHandler + B tcpwm_1_interrupts_3_IRQHandler + + PUBWEAK tcpwm_1_interrupts_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_4_IRQHandler + B tcpwm_1_interrupts_4_IRQHandler + + PUBWEAK tcpwm_1_interrupts_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_5_IRQHandler + B tcpwm_1_interrupts_5_IRQHandler + + PUBWEAK tcpwm_1_interrupts_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_6_IRQHandler + B tcpwm_1_interrupts_6_IRQHandler + + PUBWEAK tcpwm_1_interrupts_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_7_IRQHandler + B tcpwm_1_interrupts_7_IRQHandler + + PUBWEAK tcpwm_1_interrupts_8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_8_IRQHandler + B tcpwm_1_interrupts_8_IRQHandler + + PUBWEAK tcpwm_1_interrupts_9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_9_IRQHandler + B tcpwm_1_interrupts_9_IRQHandler + + PUBWEAK tcpwm_1_interrupts_10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_10_IRQHandler + B tcpwm_1_interrupts_10_IRQHandler + + PUBWEAK tcpwm_1_interrupts_11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_11_IRQHandler + B tcpwm_1_interrupts_11_IRQHandler + + PUBWEAK tcpwm_1_interrupts_12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_12_IRQHandler + B tcpwm_1_interrupts_12_IRQHandler + + PUBWEAK tcpwm_1_interrupts_13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_13_IRQHandler + B tcpwm_1_interrupts_13_IRQHandler + + PUBWEAK tcpwm_1_interrupts_14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_14_IRQHandler + B tcpwm_1_interrupts_14_IRQHandler + + PUBWEAK tcpwm_1_interrupts_15_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_15_IRQHandler + B tcpwm_1_interrupts_15_IRQHandler + + PUBWEAK tcpwm_1_interrupts_16_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_16_IRQHandler + B tcpwm_1_interrupts_16_IRQHandler + + PUBWEAK tcpwm_1_interrupts_17_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_17_IRQHandler + B tcpwm_1_interrupts_17_IRQHandler + + PUBWEAK tcpwm_1_interrupts_18_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_18_IRQHandler + B tcpwm_1_interrupts_18_IRQHandler + + PUBWEAK tcpwm_1_interrupts_19_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_19_IRQHandler + B tcpwm_1_interrupts_19_IRQHandler + + PUBWEAK tcpwm_1_interrupts_20_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_20_IRQHandler + B tcpwm_1_interrupts_20_IRQHandler + + PUBWEAK tcpwm_1_interrupts_21_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_21_IRQHandler + B tcpwm_1_interrupts_21_IRQHandler + + PUBWEAK tcpwm_1_interrupts_22_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_22_IRQHandler + B tcpwm_1_interrupts_22_IRQHandler + + PUBWEAK tcpwm_1_interrupts_23_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +tcpwm_1_interrupts_23_IRQHandler + B tcpwm_1_interrupts_23_IRQHandler + + PUBWEAK udb_interrupts_0_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_0_IRQHandler + B udb_interrupts_0_IRQHandler + + PUBWEAK udb_interrupts_1_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_1_IRQHandler + B udb_interrupts_1_IRQHandler + + PUBWEAK udb_interrupts_2_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_2_IRQHandler + B udb_interrupts_2_IRQHandler + + PUBWEAK udb_interrupts_3_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_3_IRQHandler + B udb_interrupts_3_IRQHandler + + PUBWEAK udb_interrupts_4_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_4_IRQHandler + B udb_interrupts_4_IRQHandler + + PUBWEAK udb_interrupts_5_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_5_IRQHandler + B udb_interrupts_5_IRQHandler + + PUBWEAK udb_interrupts_6_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_6_IRQHandler + B udb_interrupts_6_IRQHandler + + PUBWEAK udb_interrupts_7_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_7_IRQHandler + B udb_interrupts_7_IRQHandler + + PUBWEAK udb_interrupts_8_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_8_IRQHandler + B udb_interrupts_8_IRQHandler + + PUBWEAK udb_interrupts_9_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_9_IRQHandler + B udb_interrupts_9_IRQHandler + + PUBWEAK udb_interrupts_10_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_10_IRQHandler + B udb_interrupts_10_IRQHandler + + PUBWEAK udb_interrupts_11_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_11_IRQHandler + B udb_interrupts_11_IRQHandler + + PUBWEAK udb_interrupts_12_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_12_IRQHandler + B udb_interrupts_12_IRQHandler + + PUBWEAK udb_interrupts_13_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_13_IRQHandler + B udb_interrupts_13_IRQHandler + + PUBWEAK udb_interrupts_14_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_14_IRQHandler + B udb_interrupts_14_IRQHandler + + PUBWEAK udb_interrupts_15_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +udb_interrupts_15_IRQHandler + B udb_interrupts_15_IRQHandler + + PUBWEAK pass_interrupt_sar_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +pass_interrupt_sar_IRQHandler + B pass_interrupt_sar_IRQHandler + + PUBWEAK audioss_interrupt_i2s_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +audioss_interrupt_i2s_IRQHandler + B audioss_interrupt_i2s_IRQHandler + + PUBWEAK audioss_interrupt_pdm_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +audioss_interrupt_pdm_IRQHandler + B audioss_interrupt_pdm_IRQHandler + + PUBWEAK profile_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +profile_interrupt_IRQHandler + B profile_interrupt_IRQHandler + + PUBWEAK smif_interrupt_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +smif_interrupt_IRQHandler + B smif_interrupt_IRQHandler + + PUBWEAK usb_interrupt_hi_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +usb_interrupt_hi_IRQHandler + B usb_interrupt_hi_IRQHandler + + PUBWEAK usb_interrupt_med_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +usb_interrupt_med_IRQHandler + B usb_interrupt_med_IRQHandler + + PUBWEAK usb_interrupt_lo_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +usb_interrupt_lo_IRQHandler + B usb_interrupt_lo_IRQHandler + + PUBWEAK pass_interrupt_dacs_IRQHandler + SECTION .text:CODE:REORDER:NOROOT(1) +pass_interrupt_dacs_IRQHandler + B pass_interrupt_dacs_IRQHandler + + + END + + +; [] END OF FILE diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/psoc63_m0_default_1.0.hex b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/psoc63_m0_default_1.0.hex new file mode 100644 index 0000000000..e578247a7f --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/device/psoc63_m0_default_1.0.hex @@ -0,0 +1,198 @@ +:020000041000EA +:4000000000000108310100100D00000095010010000000000000000000000000000000000000000000000000000000009101001000000000000000009101001091010010DC +:400040009101001095090010910100109101001091010010910100109101001091010010910100109101001091010010910100109101001091010010910100109101001054 +:400080009101001091010010910100109101001091010010910100109101001091010010910100109101001091010010910100109101001091010010910100109101001020 +:4000C00010B5064C2378002B07D1054B002B02D0044800E000BF0123237010BD8C04000800000000C82A0010084B10B5002B03D00749084800E000BF07480368002B00D1EA +:4001000010BD064B002BFBD09847F9E70000000090040008C82A001024010008000000007047EFF3108072B6704780F310887047FFF7F6FF72B6104C104DAC4209DA216831 +:400140006268A368043B02DBC858D050FAE70C34F3E70B490B4A0020521A02DD043A8850FCDC094809490860BFF34F8F00F00EF900F01EF8FEE70000CC2A0010E42A0010B0 +:400180008C0400089C0700080000000808ED00E0FEE7FEE700B504207146084202D0EFF3098001E0EFF30880043001F0DFFEFEE710B500F0CBF962B6064B5B689B0301D5F3 +:4001C00001F084FE044800F055F9002001F0F6FDFBE7C046000026400000081070B56249E0239B00CB580F2213401A00D0329200525807210A40032A05D0042A06D0002A89 +:4002000012D15A4814E05A4A106811E01A00C0329200554952581F210A40112A06D0132A04D0FA20C00103E0524801E080200002002B36D14C4BB222D2009A5801211140F7 +:40024000B125ED005A59120F032422405B591B0F1C4207D0444C63591B0F03242340012B02D102E0012300E00023002B01D0002901D1032A4BD13C4BB022D2009D58AD0333 +:40028000AD0B3D495958C904C90C9C58240E01231C40013402F0BCF96843210002F0B8F935E0012B33D1304BC822D2009A5801251540C024E4001A59120F03210A401B5995 +:4002C0001B0F194207D028490B591B0F03210B40012B02D102E0012300E00023002B01D0002D01D1032A12D11F4DC022D200AB587F210B40A958090A1F263140AC58240C15 +:400300003440584302F084F9210002F081F9E0239B00154AD3581B0903221340D840144C6060164B1D692D0AFC32154001351969090E013102F06CF9A060290002F068F941 +:400340000500E06020610E4BC0180E4902F060F920750D4BE818FA21890002F059F9A061C003E06170BDC0460000264000127A00C000000800366E0184050000000021408E +:400380003F420F0040420F00E703000010B5234BB021C9005A58520052085A50E02080001A583024A2431A50802252045A501C491C4A9950A021890104329950FF211A4A84 +:4003C000995081315A58920092088020C00502435A505A588020000602435A505A58012082435A5000F0E0FBFFF7F8FE00F0DAFA00F0E2FA01F050F9B0235B055B78002BF5 +:4004000004D0B0235B055B78DBB200E02123212B03D1064B0022DA605A6010BD0000264001000200840500008C050000E00023408023024AD358032018407047000021406A +:4004400010B5FFF76EFE084980228C58074B2340074C23438B508823034AD358DB06FAD5FFF763FE10BDC04600002140FCFF00000100FA0570B50500FFF753FE0400FFF771 +:40048000D7FF032801D1FFF7DBFF0A4AB0239B00D55080215058084B03400848034353508823044AD358DB06FAD52000FFF73DFE70BDC04600002140FCFF00000300FA05E4 +:4004C00010B50400007B00F057F9606010BDC04610B50400007B216900F0DCF8606010BD10B50169007B00F00FF910BD10B50400C06800F09BF9606010BDC04610B5C06862 +:4005000000F0AAF910BDC04610B50400C06800F0BDF9606010BDC04610B5C06800F0D2F910BDC04610B504000C23C05E00F056F8606010BD10B50C23C05E00F07BF810BD8D +:4005400010B5C06800F0E2F910BDC04610B500221849042000F0D4FE01221749042000F0CFFE02221549042000F0CAFE03221449042000F0C5FE04221249042000F0C0FE54 +:4005800005221149042000F0BBFE06220F49042000F0B6FE07220E49042000F0B1FE08220C49042000F0ACFE09220B49042000F0A7FE10BDC1040010D1040010E104001071 +:4005C000ED040010FD040010090500101905001025050010350500104105001070B50412FF231C40F83B184005000D2C15D8072813D801F026FD0D4B1A5D13002B41DB07F6 +:4006000006D40123AB401343084A1355002401E00124644201F019FD05E03421044801F077FC01246442200070BDC046A8040008A827001070B50412FF231C40F83B18400B +:4006400005000D2C15D8072816D801F0FAFC0F4B1B5D1A002A41D20706D50122AA4093430A4A1355002401E00124644201F0EDFC04E00124644201E001246442002C03D09D +:400680004A21034801F044FC70BDC046A8040008A8270010F8B504000D00032803D96921174801F035FC63001B199A00154BD358AB4203D26A21124801F02AFC01F0C1FC95 +:4006C0006200121993000F4AD3189A680123AB40134210D10B4F61000E19B600B446BE191343B3606A1C72606146CB599A4203D90022726000E0FF2501F0A7FC2800F8BD39 +:40070000A8270010E000000870B504000D00032803D98221164801F0FBFB63001B199A00144BD358AB4203D28321114801F0F0FB01F087FC6200121993000E4AD3189A689E +:400740000123AB401A4208D061000C19A100094C61189A438A60002401E00124644201F074FC002C03D08F21014801F0D1FB70BDA8270010E0000008F0B583B005000400BF +:40078000032803D99921274801F0C2FB01F059FC019025496B00581982008A1850685B199A005358984203D39D211E4801F0B0FB6A00521993001C4AD3185F681FE01A4953 +:4007C0006300181982008A1850681B199A005358984205D9620012199300CB1800225A60620012199300104AD3185B689F4212D0610009198A000C498A1801335360620041 +:4008000012199300084AD31859682800FFF742FF0600FF28D3D0019801F017FC300003B0F0BDC046A8270010E000000810B5040007280CD801F005FC064B1B191B7C002BBE +:4008400003D1044B1C190123237401F0FEFB0120404210BDA804000810B5040007280CD801F0EFFB074B1B191B7C012B03D1054B1C190023237401F0E8FBD021024801F044 +:4008800047FB10BDA8040008A827001010B504001F2811D801F0D5FB094B1B191B7E002B05D1074B1C1901232376002401E00124644201F0CAFB01E001246442200010BD57 +:4008C000A804000810B504001F2811D801F0B9FB0C4B1B191B7E012B05D10A4B1C1900232376002401E00124644201F0AEFB01E001246442002C03D0F521034801F008FBD0 +:4009000010BDC046A8040008A827001010B5B0214905144BCB5C3F221340134C0C5D224092011A43114BCC5C1F2323401B031343C022D200895C7F220A40520413430C4AF6 +:4009400030215354190A303251701B0C9370002305E0074AD2183021525CC2540133052BF7DD10BD040600000506000003060000E000000810B50248583000F0E1FC10BD7B +:400980006005000810B50248B03000F0D9FC10BD6005000810B5024800F0D2FC10BDC0466005000810B5034A60328021042000F0B7FA10BD6006000870B501F042FB050032 +:4009C000094800F06DFB094C200000F0D3FB2000343000F0CFFB2000683000F0CBFB280001F033FB70BDC04660050008B8270010FEE7C046014A024B1A6070470100118053 +:400A0000000E1F4170B582B0584A116808230B431360574C03E0012001F06EFA013C534B1B695B0701D4002CF5D1002C01D1514B00E00023002B02D00520FFF7D9FF4E4C3B +:400A4000A022D200A35803218B4301263343A3504A4D04222900684601F066FE684601F0D1FC474A9020135846490B40135013691B021B0A802040040343136113691940F6 +:400A80001161E0239B00E2580F218A431643E650E25821318A43E250E258802109060A43E2500021022000F0ADFC0021032000F0A9FC0021042000F0A5FC0321002000F0AD +:400AC000A1FC0321012000F09DFC291D0522684601F02AFE6946012000F0BCFC002802D00320FFF785FF2849012000F025FD002802D00320FFF77CFF1F4C244BE158244A95 +:400B00000A4001252A43E250E158224A0A40E250E258802109060A43E250043BE1581E4A0A40E250E1581D4A0A40802189010A43E250E258802109020A43E2500B4A1168F9 +:400B4000174B0B401360002001F082FAC0235B00E3581D4204D1134AA3585B005B08A3506421002001F01AFA02B070BD0000274020A1070002004A0000002640542800101C +:400B800000002140FF00FFFF1027000004050000FEFCFFFFFFFF00FFFFF0FFFFFF8FFFFFFFFCFFFF0C05000030B58FB09621002001F0F4F901F0CAF9002801D101F0B6F9F8 +:400BC000012001F033F8244A516C244B0B40E82189010B435364536C1B0AFF2213403A2B07D11D4A516C1E4B0B40E82189010B43536401AC34220021200001F09EFD194D00 +:400C000022000021280000F051FD34220021200001F093FD22000121280000F047FDFFF7F1FE24220021200001F087FD2100280000F0A6FE22000C4B0C3323CB23C223CB1C +:400C400023C223CB23C22100084800F099FEFFF7D1FE0FB030BDC04600002740FF00FFFFFFC5FFDF00003240542800100003324010B583089A00801AC000FF228240D44396 +:400C800081400A40072B32D89B001949CB589F46184B196A0C4022431A6228E0154B596A0C4022435A6222E0124B996A0C4022439A621CE00F4BD96A0C402243DA6216E0B2 +:400CC0000C4B196B0C4022431A6310E0094B596B0C4022435A630AE0064B996B0C4022439A6304E0034BD96B0C402243DA6310BD842800100000214083089A00801AC100BA +:400D0000FF228A40072B2BD89B001748C3589F46164B186A1040C84023E0144B586A1040C8401EE0114B986A1040C84019E00F4BD86A1040C84014E00C4B186B1040C8401B +:400D40000FE00A4B586B1040C8400AE0074B986B1040C84005E0054BD86B1040C84000E00020C0B27047C046A42800100000214070B504000D000B4B9A680B4B9A420BD1A5 +:400D8000002903D1FC21094801F0C2F81034064BA400E058E55003E01034A400044BE05870BDC04600ED00E000000008C428001000000010F0B583B0041E019150D04368BA +:400DC000032B03D93621294801F0A2F80023E05E002802DBA178FFF74BFF0023E25E6368002A12DB9008224EC0308000875903210A40D200FF25290091408F4399012B0045 +:400E00000B4093403B43835117E092B20F21114008398908063189001648844661444E6803200240D200FF2738009040864398013B000340934033434B600E4B9A680E4B84 +:400E40009A420FD1019B002B03D14521074801F05FF80023E05E0199FFF78AFF002002E0064800E0002003B0F0BDC046C428001000E100E000ED00E0000000080100560005 +:400E800070B504000D000369002B0ADA0B0C03D00549064801F03CF82D042D0C6560002000E0034870BDC046A70200000829001001008A0070B505000C000368002B01DA0D +:400EC000002300E0084B002B0BD1EA60230C03D00649074801F01CF82404240CAC60002000E0014870BDC04601008A008E0200000829001070B505000C1E03D1992106483A +:400F000001F006F82B69002B03DAEB682360002000E0024870BDC0464829001001008A00F8B504000E0015000F283FD8002A10D100290ED10F2804D99E21FF31214800F036 +:400F4000E7FF6401204B9C466444204B1C60002037E0002D2CD0002E2CD0F3062CD10F2C04D99E21FF31174800F0D2FF6401164B9C466444154F3C607E60BD60F20800213D +:400F8000280001F0DAFB00212000FFF779FF3A0001CA0021FFF78EFF00280FD10B4B18680021FFF76DFF00280AD10AE0084808E0074806E0064804E0054802E0054800E0A2 +:400FC0000448F8BD88290010000023405007000803018A0001018A00F0B583B00D001C4B1B68DC68236883422DD947097B01C01A012383401E00002903D101F022F80190A6 +:4010000001E000230193124B18680368002B01DA002300E00F4B002B0ED16368BF00DF193B68334203D0B3433B60002400E00A4C0021FFF725FF00E0084C002D04D1019801 +:4010400001F003F800E0064C200003B0F0BDC0465007000801008A00020188000301880004018A000A4B1B68DA68136883420BD943095901401A0121814052689B009B58D3 +:401080000B4203D0034802E0034800E003487047500700080101880004018A0000018800034B1B68002B01D1014B18607047C0465C070008F0B5474680B404000F009046AC +:4010C0001E00072803D9B421254800F021FF254B1B682C2060431C18FF22150035402560330A13406360330CA3600F2D04D99E21FF311D4800F00CFF6B011C4A94466344DF +:40110000236165680F2D04D9DC214900164800F0FFFE6D01164B9C4665446561A668330C04D0EB214900104800F0F2FE330C04D0D821FF310C4800F0EBFE3604330C1E43A3 +:40114000AE604346E36127620023A361069B002B02D000229B5EA38104BC9046F0BDC046C82900105C070008882900100000234000102340F0B58FB0041E03D150212E48FA +:4011800000F0C6FE6368032B03D952212A4800F0BFFEE36A002B03D15621274800F0B8FEE368072B03D95721234800F0B1FE236A072B03D95821204800F0AAFE236B002B94 +:4011C00003D159211C4800F0A3FE07AA1300210061C961C321C921C302AD290023001433C1CBC1C141CB41C10821535E0CAE3380079B1933B370089B0D930B9B0A980096D4 +:40120000A26AE16AFFF756FF2B69E868002200920021FFF74FFF216B3000FFF7CBFD0023F25E002A05DB1F231A401E3B9340034A13600FB0F0BDC046C829001000E100E05C +:40124000F8B505000F0016001C00002A03D1FC21244800F05DFE072D03D9FD21214800F057FE072F03D9FE211E4800F051FE1E4B1B682C212800484318187943591801228B +:4012800013004D68AB401B044568AA4015000269002A20D08F69002F1FD11268002A01DA002200E0114A002A19D132681204120C134333600369DE6001238B614C62046998 +:4012C0002B0C03D00A490B4800F022FE2A04120CA260002004E0084802E0084800E00748F8BDC046C82900105C07000801008A008E0200008829001004028A0007028A0005 +:4013000070B505000C001600072804D96021FF31084800F0FDFD084B1B682C2068431818C369B34204D9036AB6009C51002000E0024870BDC82900105C0700080A028A00E6 +:4013400070B582B0040000230193002804D1D92149002B4800F0DCFD2369002B04D1B421FF31274800F0D4FD6369002B04D1DA214900234800F0CCFD236A002B04D1B62186 +:40138000FF311F4800F0C4FD6269D5682B0C1FD01B041360136820690369002B18DA01A9FFF7A8FD00280ED1019803681E0CFF221340E269934207D29B00226AD358002B34 +:4013C00002D0984700E0002631002069FFF758FD2D042D0C0FD063691D601B68636A002B03D098470023636203E0A36A002B00D098470023A36163691B6802B070BDC04665 +:40140000C829001004281DD8042904D94B1EFF3B9BB2132B18D8FF290CD91F2319400B4A0300C0339B009950D03080000423835000200AE007231940D0308000034BC15005 +:40144000002002E0024800E0014870470000264001004A0070B50300012823D102008032FF32920030481258002A1DDB8A78023AD2B20E2A1AD84A78002A19D0122A19D8E1 +:401480000A78C878002801D0132400E01624944212D8002801D0382000E0702090420DD300200CE021480AE0214808E01F4806E01E4804E01D4802E01C4800E01B48002890 +:4014C00030D1013B0A79022A1ED00A787F2616404A781202F8246401224032438E783604F8256D0334002C4022431600CA78D20680252D052A401400320022431C008134A8 +:40150000FF34A400084D6251074D8133FF339B005C59084A14400A791207C02189050A4022435A5170BDC0460000264001004A0003004A00FFFFFFCF70B50C0001281CD1F3 +:40154000451E104A8030FF3080008358802109060B43835003E0012000F0CEFC013C2B009133FF339B00074A9B58DB0701D4002CF1D1002C03D1044802E0044800E0002089 +:4015800070BDC0460000264002004A0001004A00214B984230D00ED8402831D004D800281FD010282AD031E080282BD080235B00984229D02AE0194B984229D007D8A023D9 +:4015C0001B0698420DD0164B984212D01EE0154B98420AD0144B984209D0144B984215D101E0002016E0124814E0124812E0124810E0A020C0030DE007480BE00F4809E0EE +:401600000F4807E00F4805E0034803E00E4801E0A420C0037047C04606005200010000F0090000A0040000F0050000F0030000F0010052000200520003005200010050006C +:401640000200500005005200FF00520010B50C4B1B69002B11DB0B4B1868FFF799FF0121094B0A4AD150084B084AD358002BFAD1074BD358002BF6D100E0064810BDC04634 +:4016800000002340600700080C040000000025408C0400000200500010B5022202490020FFF72EFE10BDC0466D010008F8B506000D001400002800D142E1002A00D141E135 +:4016C000072903D93921A04800F022FC2368012B03D93A219C4800F01BFC0F2362689A4303D03B21984800F013FC237A1F22934303D03C21944800F00BFCE368032B03D9C2 +:401700003D21914800F004FC2369012B03D93E218D4800F0FDFB6369012B03D93F218A4800F0F6FBA369012B03D94021864800F0EFFBE369032B03D94121834800F0E8FB78 +:40174000236A012B03D942217F4800F0E1FB636A012B03D943217C4800F0DAFBA36A012B03D94421784800F0D3FBE36A032B03D94521754800F0CCFB236B072B03D94621F0 +:40178000714800F0C5FB2768072D03D96F49704800F0BEFB012F04D9BA2189006C4800F0B7FB002F03D10123AB40736002E00123AB40B3606768072D04D9E421890064483E +:4017C00000F0A6FB0F233A009A4303D06149604800F09EFBAA00B36A0F210800904083430F4097401F43B762277A072D03D95A49574800F08DFB1F233A009A4303D05749F4 +:40180000534800F085FB564BF318DB09554A944663441B01032D0BD81A68E8001F2181408A4311001F223A4082400A431A600BE0291F5A68C9001F208840824310001F2256 +:401840003A408A4002435A60E768082D03D946493F4800F05DFB032F03D944493C4800F057FB6A00736A03210800904083430F4097401F4377622769082D03D93C493448FA +:4018800000F046FB012F04D9CA21C900304800F03FFBB36901221100A9408B431740AF401F43B7616769072D03D93249284800F02FFB012F03D93049254800F029FBF26A86 +:4018C00001231900A9408C468A431F40AF401743F7626F00103703210800B84062461043326B8243A0691840A8400243E0690140B9400A433263706BFF2294469043276ABE +:401900001F40636A5A00022313403B43A26A9100042739400B431F00E36AD900182319403B000B43226B520161460A401343AD00FE2292001540AB4003437363002002E056 +:401940000E4800E00D48F8BD082A0010E7020000482A00109103000045020000460200000000CEBF00100304D4060000D50600004F060000D2030000D303000001005A00A3 +:4019800070B505000C00002848D0002948D0FF230A689A4303D08D21224800F0B9FAFF2322699A4303D08E211E4800F0B1FAA3685B0D03D08F211B4800F0AAFA63685B0A47 +:4019C00003D09021174800F0A3FAE3695B0F03D09121144800F09CFA236A5B0F03D09221104800F095FA104BEB18DB090F4A944663441B0122682A60E268AA622269EA628D +:401A000062692A63A2686A626268AA61A2696A63E2691A60226A5A60002002E0044800E0034870BD082A00100000CEBF0010030401005A00034A9369802149040B43936160 +:401A40007047C04600F02540024A9169024B0B409361704700F02540FFFFFFFE0D4BF222D2019A580260F022D2019A5842600A4A9A588260094A9A58C260094A9A58026138 +:401A8000084A9A584261084A9A588261074A9B58C36170470000344004780000087800000C7800001078000014780000187800000D4BF022D201416899500C4A816899506A +:401AC0000B4AC16899500B4A016999500A4A416999500A4A81699950094AC16999500168E83299507047C0460000344004780000087800000C780000107800001478000032 +:401B00001878000010B5074A074813580F24A34302210B43135004381358A3431943115010BDC0460000214004F0000010B5074A074813580F24A34303210B4313500438EC +:401B40001358A3431943115010BDC0460000214004F000000449054A8858054B0340C020C00103438B5070470000214004F00000FF8FFFFF0449054A8858054B0340802017 +:401B8000C00103438B5070470000214004F00000FF8FFFFF10B50400012803D90D490E4800F0B6F9002C03D10C4B5869C00F00E00020012C0CD1094B9B695B0005D4074BC3 +:401BC0009B69002B03DA012002E0012000E0002010BDC04641060000882A00100000264070B504000D00072803D90D490D4800F08FF90D4B9B690722134021009C420DD05B +:401C0000094882690726B243344014438461002D04D0994202D9C82000F06EF970BDC046A1060000882A00100000264070B50500012803D92A492B4800F06AF900F001FA4B +:401C40000400294B294AD3581F221340E822D200B02149058A5CD31A5A1E9341DBB29D4239D0002D14D1FFF7E5FEFFF74BFF1F481D4943581F229343143A13434350FFF754 +:401C800069FFE823DB00B0225205D35CDAB211E01648154943581F229343143A13434350092000F029F9FFF765FF114BB0225205D35CDAB20D4E0C4831581F2399431340DE +:401CC0000B433350012D06D1092000F015F9FFF72DFFFFF7B9FE200000F0B7F970BDC046ED060000882A00101CFF0000000026404107000070B584B005000E00042803D933 +:401D000029492A4800F004F9731EDBB2012B07D9042E05D0082E03D02549244800F0F8F8042E01D0012E1DD1224B5C68002013E023799D420FD1A368002B01D01E420AD1DD +:401D4000E36801A85A6842609B688360067023689847184B9C606469002C23D0164B9842E6D11FE0134B9C68022E02D1002C00D02469002011E023799D420DD1A368002B7B +:401D800001D01E4208D1E36801A85A6842609B6883600670236898472469002C02D0064B9842E8D104B070BD24080000882A00102508000070070008FF00420070B50500A6 +:401DC000012804D9F221FF31384800F0A1F8384B1B68002B05D001210120FFF78BFF040000E00024002C59D100F02BF90600304B1B68002B03D004210120FFF77BFFE0239B +:401E00002C4AD358DB0603D529480C30FFF726FEB0235B055B78002B04D0B0235B055B78DBB200E02123212B03D1280000F0B4FC1FE02149214BCB581F221340E822D20075 +:401E4000B0204005825CD31A5A1E9341DBB20A68120207D4012B05D1194BC158194B164AD15003E00021174B134AD150280000F08BFCE0230F4AD358DB0603D50C480C3091 +:401E8000FFF716FE300000F0E0F8094B1B68002B09D008210120FFF72DFF04E002210120FFF728FF084C200070BDC046882A00107007000800000140000026401CFF0000EA +:401EC00010180000307F0000FF00420010B500F0B8F8074B5A6807490A40E824A40122435A605A68114059605B6800F0AEF810BD00002640FF00FC0F10B5034B1B78584344 +:401F000000F096F810BDC046D400000801BEFEE770B50D00044C18220100200000F015FCA5610020FFF7F2FF50040008054B802212069A649B6C002B01DB002000E0024829 +:401F40007047C0460000274003004600054B8022120198585B68FF221A4202D08023DB021843704700002640FEE7C04610B50A4B0268DA6142681A6282685A62C2689A6259 +:401F80000269DA6242691A6382695A63C2699A63FFF7EAFF10BDC04650040008F0B5002801D0192200E064228A42924152421C4BE8256D005C590327BC433A4014435C51C5 +:401FC0005C59184E34405C51D03D5C59BC4322435A515A5916405E51002805D010290DD921290DD8012014E01D290BD93A290BD957290BD978290BD803200AE0002008E04E +:40200000022006E0002004E0012002E0022000E00420054A13680F218B4303431360F0BD00002140FFFCFFFF00002540000000000230800803D001300238FCD1C046C046AD +:402040007047EFF3108072B6704780F310887047042805D1094A116804230B4313600CE00006C0239B04184090239B00044AD050024A136804218B431360704710E000E0A4 +:402080000000214070B50D000F4B184300040F4BD861FA24A40003E0013C0120FFF72CFF0A4B1B6CDB0701D4002CF5D1002C08D0064B196C01220A431A64DB6A2B800020C0 +:4020C00000E0034870BDC0460080FFFF00003C400400160010B500040E4B184001430E4BD961FA24A40003E0013C0120FFF704FF094B1B6CDB0701D4002CF5D1002C06D09B +:40210000054A116C01230B431364002000E0034810BDC0460000FF7F00003C4004001600F0B583B006000A24C02149017548FFF7D1FF002804D16B46991D7248FFF7A2FF49 +:40214000002C01D0013C00E06F48002805D16B46DA88C0235B019A42E6D1002825D16B46991D6A48FFF78EFF00281ED16B4606331B885B0519D40A248021C9006348FFF7C7 +:40218000A9FF002804D16B46991D6048FFF77AFF002C01D0013C00E05B48002805D16B46DA888023DB009A42E6D1002804D16B46991D5748FFF766FF002844D16B46063398 +:4021C0001B883F229343B278012A15D1F178012904D88FB20222D21B95B201E000250227402213439BB2302213436A46D380494BCB40494A136013E0F178002904D18FB2A3 +:402200000122D21B95B201E00025012740229343102213436A46D380404BCB403E4A13606B469C1DD9883943D9803948FFF752FFF378DB1B03221340AA0092B2134323809D +:40224000374A38498B50B0235B055B78002B04D0B0235B055B78DBB200E02123212B4FD0314BB0225205D35A9BB2002B48D0002804D16B46991D2D48FFF704FF002824D109 +:402280006B469A1DDB8860218B4318001380B0256D05254C2B5B60310B405B08034324490B401380295BC901F020C00001400B43204919401180285BC0239B000340DB002C +:4022C000194311801948FFF705FF002804D16B46991D1948FFF7D6FE002811D16B469A1DD988C023994311800F4BB0204005C05A302303409B00194311800F48FFF7EAFE08 +:4023000003B0F0BD021E000004001600031E0000091E00000048E801C00000080024F40064F0010000003C4016180000071E00007FF8FFFFFFE7FFFF061E000070B50C00D8 +:402340004000084901430848FFF7C4FE051E04D106490748FFF7BEFE05006001FFF7CCFD280070BD01100000081E0000376800000F1E000010B59CB02422002113A800F098 +:40238000DCF9154B1693154C1894154B1A931B93242200210AA800F0D0F9124B0D930F94114B1193114B12932422002101A800F0C4F90F4B049306940E4B089313A90E48B6 +:4023C000FFF7DEFA0AA90D48FFF7DAFA01A90C48FFF7D6FA1CB010BD666666660000FFFF1C1C1C1C66E6EE661C1A1A1A1A1A000066E666661A1A001C0001324080013240CE +:4024000000023240F8B5051E00D1C1E0644B5B689B0301D5FFF75AFD624B634AD358DB0704D5624BD358DB0700D5B3E0FFF7A2FF5D4B5F495F4A99502A788021C9020A437D +:402440005D495A505D495E4A9950802252009B58DB0700D5A0E05B4B1B6F1B0709D45A4B18685A4B984206D9190000F0D1F8013802E0012000E000204B4B1B68002803D0E3 +:402480004003534A104300E052481843464B1860434B5B695B000ED501210320FFF7A0FB3F4B5B695B000CD53D4A93698021C9050B43936105E03C49474A885803230343A0 +:4024C0008B50394C374AA658444B3343A3504020FFF712FD424BE358DB070BD42700404C01233B514020FFF707FD03233B514020FFF702FD3B4B1E403B4B1E43294B2A4AA0 +:40250000D650FA24E40003E0013C0120FFF7F4FC364B374AD358DB0601D4002CF4D1002C01D0002400E0334C002C23D11E49324A8858082303438B500120FFF72BFB002864 +:4025400001D108231E432D4B1E4001231E43154B154AD6502A4E03E0013E0120FFF7CCFC124B114AD358DB0701D4002EF4D1002E00D1204C002C03D12800FFF7D1FD04005C +:40258000002C0AD168782978FFF7D8FE040004E01C4C02E01C4C00E01C4C2000F8BDC04600002640A0F0010000003C40B4F0010006000001A4F00100A8F0010001000100BB +:4025C000ACF0010000F03D40C800000800093D00041A0080040A0080C4F0010030000300B0F00100EFFFFEFF2000020010400000000032400400160068F00100FFFFFBFFCC +:40260000F07E0E00010016000300160002001600002243088B4274D303098B425FD3030A8B4244D3030B8B4228D3030C8B420DD3FF22090212BA030C8B4202D312120902EF +:4026400065D0030B8B4219D300E0090AC30B8B4201D3CB03C01A5241830B8B4201D38B03C01A5241430B8B4201D34B03C01A5241030B8B4201D30B03C01A5241C30A8B4229 +:4026800001D3CB02C01A5241830A8B4201D38B02C01A5241430A8B4201D34B02C01A5241030A8B4201D30B02C01A5241CDD2C3098B4201D3CB01C01A524183098B4201D3A2 +:4026C0008B01C01A524143098B4201D34B01C01A524103098B4201D30B01C01A5241C3088B4201D3CB00C01A524183088B4201D38B00C01A524143088B4201D34B00C01A3C +:402700005241411A00D20146524110467047FFE701B5002000F006F802BDC0460029F7D076E770477047C046002310B59A4203D0CC5CC4540133F9E710BD03008218934298 +:4027400002D019700133FAE77047030030B5002A0DD00C7801335D1E013A2C700131002CF5D19A189A4202D01C700133FAE730BDF8B5C046F8BC08BC9E467047F8B5C046AE +:40278000F8BC08BC9E46704701B40248844601BC604700BF4D03000801B40248844601BC604700BF7902000870736F63365F7574696C732E63000000030000000100000043 +:4027C000010000000000000005036000040000000100000000000000010000000604600008000000D00600089509001008000000010000000200000002000000080800034C +:40280000090000000100000000000000030000000909000308000000F0060008750900100A0000000100000004000000040000000A0A000C0B0000000100000000000000A3 +:40284000050000000B0B000C100000001007000885090010192001021901020000000000000000000000000000000000000000BA0000000000000000000000000000000052 +:4028800000001D1D900C00109C0C0010A80C0010B40C0010C00C0010CC0C0010D80C0010E40C0010100D00101A0D0010240D00102E0D0010380D0010420D00104C0D001021 +:4028C000560D001047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C737973696E745C63795F737973693B +:402900006E742E630000000047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C6970635C63795F697063F4 +:402940005F6472762E68000047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C6970635C63795F697063E6 +:402980005F6472762E63000047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572732F7065726970686572616C2F6970632F63795F69706332 +:4029C0005F6472762E68000047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C6970635C63795F69706366 +:402A00005F706970652E630047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C6770696F5C63795F6770BA +:402A4000696F2E630000000047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C6770696F5C63795F6770AF +:402A8000696F2E680000000047656E6572617465645F536F757263655C50536F43365C70646C5C647269766572735C7065726970686572616C5C737973706D5C63795F7341 +:402AC0007973706D2E630000000000000000001000000008C0000000EC2A0010C0000008900300008C0400081003000000127A0000127A0000093D0000093D0000093D008E +:402B000004000000A00F00000000D0070700000000000000000000000F00000000000000000000000300000000000000000000000000000000000000000000001900005089 +:402B4000A000000002FF0000E9000010C1000010000000000004400B12D03E22094B1A60094A0A4B1A600A4B0621A322D2009950084A98509B58074B054AD358002BFADA75 +:402B80007047C046040126401E1F000008012640000026401C05000010B54378FF2B0DD100F064F9064BDB685A68116801230B4313601368DB07FCD400F028F910BDC04620 +:402BC00080002340F0B583B006000F0000F046F90500032824D12B4B1B69002B22DB002000F034F9284B98421ED00023274A0021012000F01BF9002803D0254C17E00134A5 +:402C000000E00024002000F021F91F4B984202D0204B9C42F3D91F4B9C4207D91C4C06E0002404E01A4C02E0194C00E00024002C24D100F01BF90190174A0121174800F084 +:402C4000DDF800280ED1002E04D13800FFF782FF134C08E0114B1B69002BFBDB00F0DEF8040000E00A4C032D05D10121002000F0E5F80028F9D1019800F0C8F8200003B07B +:402C8000F0BDC046C0002340010188001801000805005200EF49020060070008000023400100500070B5304B1B68002BFBDA2E4BD96802220A43DA60DB68DB071FD52A4EC6 +:402CC000F2681204150C294B1A69120A1204FF2424042240110090241A59120A12060A432A43F2601969224A114090252D012943196119590A402A431A511A691B591A4BFD +:402D000000225A605B681B4A116904230B431361012801D030BF00E020BF134B1B68002BFBDA114BDB68DB0715D510480269104B1A4014000C4DEA68120C1202FF210902A4 +:402D40000A4022430261902142581340EA68120E120213434350044BDA6802218A43DA6000225A6070BDC046E000234000002140FF00FFFF00ED00E0164A116904230B43AD +:402D80001361012801D030BF00E020BF124B1B68002BFBDA86235B00104AD358002B14D10F4A104B1A6006220F4B1A6038320F4B1A6006320E4B1A600D4B1B68002BFBDA30 +:402DC0000C4986235B00054AD1500022024B5A607047C04600ED00E0E0002340000025401E1F00000801264018052640040126401C052640AAAAAAAA0000000001B40248E7 +:402E0000844601BC604700BFB50E001001B40248844601BC604700BF4B20001001B40248844601BC604700BF4D16001001B40248844601BC604700BF4112001001B40248BE +:402E4000844601BC604700BFD90F001001B40248844601BC604700BF6510001001B40248844601BC604700BF3104001001B40248844601BC604700BF43200010000000006C +:402E80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012 +:402EC00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000D2 +:402F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000091 +:402F40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000051 +:402F80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011 +:402FC00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000D1 +:0200000490303A +:02000000CE5ED2 +:0200000490501A +:0C0000000005E20721002101E215EF5E7F +:00000001FF \ No newline at end of file diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/ipc_rpc.cpp b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/ipc_rpc.cpp new file mode 100644 index 0000000000..4b33d7c5f1 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/ipc_rpc.cpp @@ -0,0 +1,125 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "ipc_rpc.h" +#include "Mutex.h" +#include "Semaphore.h" +#include "mbed_assert.h" +#include "cy_ipc_config.h" +#include "ipc/cy_ipc_pipe.h" +#include +#include "platform/SingletonPtr.h" + +using namespace rtos; + + +static SingletonPtr msg_mutex; +static SingletonPtr msg_semaphore; + +#define RPC_GEN RPC_GEN_INTERFACE_IDS + +#include "rpc_defs.h" +#include "rpc_api.h" + +#undef RPC_GEN + +extern "C" { + +void ipcrpc_release(void) +{ + // Just signal on semaphore that we are done with a call. + msg_semaphore->release(); +} + + +uint32_t ipcrpc_call(uint32_t call_id, uint32_t args_num, ...) +{ + va_list ap; + static IpcRpcMessage message; + cy_en_ipc_pipe_status_t status; + ScopedMutexLock lock(*msg_mutex.get()); + + // Make sure semaphore is initialized. + (void)msg_semaphore.get(); + + // Copy data to the buffer. + message.client_id = call_id; + message.args_num = args_num; + message.result = 0; // default result + + va_start(ap, args_num); + for (uint32_t i = 0; i < args_num; ++i) { + message.args[i] = va_arg (ap, uint32_t); + } + va_end (ap); + + // send message + status = Cy_IPC_Pipe_SendMessage(CY_IPC_EP_RPCPIPE_DEST, + CY_IPC_EP_RPCPIPE_ADDR, + &message, + ipcrpc_release); + // We are using dedicated IPC channel here and have locked global mutex + // so this had to succeed. + MBED_ASSERT(status == CY_IPC_PIPE_SUCCESS); + + // Now wait for the response; + msg_semaphore->wait(); + + return message.result; +} + + +#define RPC_GEN RPC_GEN_INTERFACE_IDS_INIT + +void ipcrpc_init(void) +{ + uint32_t rpc_counter = 0; + +#include "rpc_defs.h" +#include "rpc_api.h" +} + +#undef RPC_GEN + +#define RPC_GEN RPC_GEN_INTERFACE + +#include "rpc_defs.h" +#include "rpc_api.h" + +///////// + +#undef RPC_GEN + +#define RPC_GEN RPC_GEN_IMPLEMENTATION + +#include "rpc_defs.h" +#include "rpc_api.h" + +#undef RPC_GEN + +#define RPC_GEN RPC_GEN_INITIALIZATION + +void ipcrpc_init2(void) +{ + uint32_t rpc_counter = 0; +#include "rpc_defs.h" +#include "rpc_api.h" +} + +} /* extern "C" */ + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/system_psoc63_cm4.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/system_psoc63_cm4.c similarity index 81% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/system_psoc63_cm4.c rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/system_psoc63_cm4.c index c5437c7795..f3ec95213e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/system_psoc63_cm4.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/TARGET_MCU_PSOC6_M4/system_psoc63_cm4.c @@ -1,26 +1,31 @@ /***************************************************************************//** * \file system_psoc63_cm4.c -* \version 2.0 +* \version 2.10 * * The device system-source file. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ +/* + * Copyright (c) 20017-2018 Future Electronics + */ #include #include +#include "device.h" #include "system_psoc63.h" #include "cy_device_headers.h" +#include "ipc_rpc.h" -#if !defined(CY_IPC_DEFAULT_CFG_DISABLE) - #include "ipc/cy_ipc_pipe.h" - #include "ipc/cy_ipc_sema.h" -#endif /* CY_IPC_DEFAULT_CFG_DISABLE */ +#if defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_IPC_DEFAULT_CFG_DISABLE) + #include "ipc/cy_ipc_drv.h" + #include "flash/cy_flash.h" +#endif /* defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_IPC_DEFAULT_CFG_DISABLE) */ /******************************************************************************* @@ -28,41 +33,28 @@ *******************************************************************************/ /** Default HFClk frequency in Hz */ -#define CY_CLK_HFCLK0_FREQ_HZ_DEFAULT ( 8000000UL) +#define CY_CLK_HFCLK0_FREQ_HZ_DEFAULT CY_CLK_HFCLK0_FREQ_HZ /** Default PeriClk frequency in Hz */ -#define CY_CLK_PERICLK_FREQ_HZ_DEFAULT (4000000UL) +#define CY_CLK_PERICLK_FREQ_HZ_DEFAULT CY_CLK_PERICLK_FREQ_HZ /** Default SlowClk system core frequency in Hz */ -#define CY_CLK_SYSTEM_FREQ_HZ_DEFAULT (8000000UL) - -/** IMO frequency in Hz */ -#define CY_CLK_IMO_FREQ_HZ (8000000UL) - -/** HVILO frequency in Hz */ -#define CY_CLK_HVILO_FREQ_HZ (32000UL) - -#if (SRSS_PILO_PRESENT == 1U) || defined(CY_DOXYGEN) - /** PILO frequency in Hz */ - #define CY_CLK_PILO_FREQ_HZ (32768UL) -#endif /* (SRSS_PILO_PRESENT == 1U) || defined(CY_DOXYGEN) */ - -/** WCO frequency in Hz */ -#define CY_CLK_WCO_FREQ_HZ (32768UL) - -#if (SRSS_ALTLF_PRESENT == 1U) || defined(CY_DOXYGEN) - /** ALTLF frequency in Hz */ - #define CY_CLK_ALTLF_FREQ_HZ (32768UL) -#endif /* (SRSS_ALTLF_PRESENT == 1U) || defined(CY_DOXYGEN) */ +#define CY_CLK_SYSTEM_FREQ_HZ_DEFAULT CY_CLK_HFCLK0_FREQ_HZ -/** Holds the FastClk system core clock, which is the system clock frequency supplied to the SysTick timer and the -* processor core clock. This variable can be used by debuggers to query the frequency of the debug timer or to configure -* the trace clock speed. +/* +* Holds the FastClk system core clock, which is the system clock frequency +* supplied to the SysTick timer and the processor core clock. +* This variable implements CMSIS Core global variable. +* Refer to the [CMSIS documentation] +* (http://www.keil.com/pack/doc/CMSIS/Core/html/group__system__init__gr.html "System and Clock Configuration") +* for more details. +* This variable can be used by debuggers to query the frequency +* of the debug timer or to configure the trace clock speed. * -* \attention Compilers must be configured to avoid removing this variable in case the application program is not using -* it. Debugging systems require the variable to be physically present in memory so that it can be examined to configure -* the debugger. */ +* \attention Compilers must be configured to avoid removing this variable in case +* the application program is not using it. Debugging systems require the variable +* to be physically present in memory so that it can be examined to configure the debugger. */ uint32_t SystemCoreClock = CY_CLK_SYSTEM_FREQ_HZ_DEFAULT; /** Holds the HFClk0 clock frequency. Updated by \ref SystemCoreClockUpdate(). */ @@ -88,6 +80,14 @@ uint32_t cy_PeriClkFreqHz = CY_CLK_PERICLK_FREQ_HZ_DEFAULT; #define CY_WDT_LOCK_BIT0 ((uint32_t)0x01u << 30u) #define CY_WDT_LOCK_BIT1 ((uint32_t)0x01u << 31u) +#if (__CM0P_PRESENT == 0) + /* CLK_FLL_CONFIG default values */ + #define CY_FB_CLK_FLL_CONFIG_VALUE (0x01000000u) + #define CY_FB_CLK_FLL_CONFIG2_VALUE (0x00020001u) + #define CY_FB_CLK_FLL_CONFIG3_VALUE (0x00002800u) + #define CY_FB_CLK_FLL_CONFIG4_VALUE (0x000000FFu) +#endif /* (__CM0P_PRESENT == 0) */ + /******************************************************************************* * SystemCoreClockUpdate (void) @@ -131,15 +131,32 @@ uint32_t cy_delay32kMs = CY_DELAY_MS_OVERFLOW_THRESHOLD * /******************************************************************************* * Function Name: SystemInit ****************************************************************************//** -* +* \cond * Initializes the system: +* - Restores FLL registers to the default state for single core devices. * - Unlocks and disables WDT. * - Calls the Cy_SystemInit() function, if compiled from PSoC Creator. * - Calls \ref SystemCoreClockUpdate(). -* +* \endcond *******************************************************************************/ void SystemInit(void) { +#if (__CM0P_PRESENT == 0) + /* Restore FLL registers to the default state as they are not restored by the ROM code */ + uint32_t copy = SRSS->CLK_FLL_CONFIG; + copy &= ~SRSS_CLK_FLL_CONFIG_FLL_ENABLE_Msk; + SRSS->CLK_FLL_CONFIG = copy; + + copy = SRSS->CLK_ROOT_SELECT[0u]; + copy &= ~SRSS_CLK_ROOT_SELECT_ROOT_DIV_Msk; /* Set ROOT_DIV = 0*/ + SRSS->CLK_ROOT_SELECT[0u] = copy; + + SRSS->CLK_FLL_CONFIG = CY_FB_CLK_FLL_CONFIG_VALUE; + SRSS->CLK_FLL_CONFIG2 = CY_FB_CLK_FLL_CONFIG2_VALUE; + SRSS->CLK_FLL_CONFIG3 = CY_FB_CLK_FLL_CONFIG3_VALUE; + SRSS->CLK_FLL_CONFIG4 = CY_FB_CLK_FLL_CONFIG4_VALUE; +#endif /* (__CM0P_PRESENT == 0) */ + /* Unlock and disable WDT */ SRSS->WDT_CTL = ((SRSS->WDT_CTL & (uint32_t)(~SRSS_WDT_CTL_WDT_LOCK_Msk)) | CY_WDT_LOCK_BIT0); SRSS->WDT_CTL = (SRSS->WDT_CTL | CY_WDT_LOCK_BIT1); @@ -147,12 +164,29 @@ void SystemInit(void) Cy_SystemInit(); SystemCoreClockUpdate(); - -#if !defined(CY_IPC_DEFAULT_CFG_DISABLE) +} + + +/******************************************************************************* +* Function Name: mbed_sdk_init +****************************************************************************//** +* +* Mbed's post-memory-initialization function. +* Used here to initialize common parts of the Cypress libraries. +* +*******************************************************************************/ +void mbed_sdk_init(void) +{ + /* Initialize shared resource manager */ + cy_srm_initialize(); + /* Initialize system and clocks. */ + /* Placed here as it must be done after proper LIBC initialization. */ + SystemInit(); /* Allocate and initialize semaphores for the system operations. */ Cy_IPC_SystemSemaInit(); Cy_IPC_SystemPipeInit(); -#endif /* CY_IPC_DEFAULT_CFG_DISABLE */ + Cy_Flash_Init(); + ipcrpc_init(); } @@ -368,7 +402,7 @@ void Cy_SystemInitFpuEnable(void) * * The intention of the function is to declare boundaries of the memories for the * MDK compilers. For the rest of the supported compilers, this is done using -* linker configuration files. The following symbols used by the cypdlelftool. +* linker configuration files. The following symbols used by the cymcuelftool. * *******************************************************************************/ #if defined (__ARMCC_VERSION) @@ -404,9 +438,9 @@ __cy_memory_0_start EQU __cpp(CY_FLASH_BASE) __cy_memory_0_length EQU __cpp(CY_FLASH_SIZE) __cy_memory_0_row_size EQU 0x200 - /* Working Flash */ -__cy_memory_1_start EQU __cpp(CY_WFLASH_BASE) -__cy_memory_1_length EQU __cpp(CY_WFLASH_SIZE) + /* Flash region for EEPROM emulation */ +__cy_memory_1_start EQU __cpp(CY_EM_EEPROM_BASE) +__cy_memory_1_length EQU __cpp(CY_EM_EEPROM_SIZE) __cy_memory_1_row_size EQU 0x200 /* Supervisory Flash */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device.h new file mode 100644 index 0000000000..0ef546175a --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device.h @@ -0,0 +1,81 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_DEVICE_H +#define MBED_DEVICE_H + +/*----------------------------------------------------------------------------*/ +/** Config options. */ +/*----------------------------------------------------------------------------*/ +/** ALTHF (BLE ECO) frequency in Hz */ +#define CYDEV_CLK_ALTHF__HZ ( 8000000UL) + +/*----------------------------------------------------------------------------*/ + +#include "cmsis.h" +#include "objects.h" + +/* + * Board clocks. + */ +/** IMO frequency in Hz */ +#define CY_CLK_IMO_FREQ_HZ ( 8000000UL) +/** PILO frequency in Hz */ +#define CY_CLK_PILO_FREQ_HZ ( 32768UL) + +/** WCO frequency in Hz */ +#define CY_CLK_WCO_FREQ_HZ ( 32768UL) + +/** HVILO frequency in Hz */ +#define CY_CLK_HVILO_FREQ_HZ ( 32000UL) + +/** ALTLF frequency in Hz */ +#define CY_CLK_ALTLF_FREQ_HZ ( 32768UL) + +/** Default HFClk frequency in Hz */ +#ifndef CY_CLK_HFCLK0_FREQ_HZ +#define CY_CLK_HFCLK0_FREQ_HZ (100000000UL) +#endif + +/** Default PeriClk frequency in Hz */ +#ifndef CY_CLK_PERICLK_FREQ_HZ +#define CY_CLK_PERICLK_FREQ_HZ (CY_CLK_HFCLK0_FREQ_HZ / 2) +#endif + +/** Default SlowClk system core frequency in Hz */ +#ifndef CY_CLK_SYSTEM_FREQ_HZ +#define CY_CLK_SYSTEM_FREQ_HZ (CY_CLK_PERICLK_FREQ_HZ) +#endif + + +/** Interrupt assignment for CM0+ core. + * On PSoC6 CM0+ core physical interrupt are routed into NVIC through a programmable + * multiplexer. This requires that we define which of the 32 NVIC channels is used + * by which interrupt. This is done here. + */ +#define CY_M0_CORE_IRQ_CHANNEL_US_TICKER ((IRQn_Type)0) +#define CY_M0_CORE_IRQ_CHANNEL_SERIAL ((IRQn_Type)4) +#define CY_M0_CORE_IRQ_CHANNEL_BLE ((IRQn_Type)3) + +/** Identifiers used in allocation of NVIC channels. + */ +#define CY_US_TICKER_IRQN_ID (0x100) +#define CY_SERIAL_IRQN_ID (0x200) +#define CY_BLE_IRQN_ID (0x300) +#define CY_GPIO_IRQN_ID (0x400) +#define CY_LP_TICKER_IRQN_ID (0x500) +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cmsis.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cmsis.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cmsis.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cmsis.h index 18c5387bd3..6973d9a1a1 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cmsis.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cmsis.h @@ -33,5 +33,6 @@ #define MBED_CMSIS_H #include "cy_device_headers.h" +#undef BLE #endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cy8c6347bzi_bld53.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy8c6347bzi_bld53.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cy8c6347bzi_bld53.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy8c6347bzi_bld53.h index 24e44b7bb0..cb6e526f1d 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cy8c6347bzi_bld53.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy8c6347bzi_bld53.h @@ -5,12 +5,12 @@ * CY8C6347BZI-BLD53 device header * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -433,6 +433,7 @@ typedef enum { #define __VTOR_PRESENT 1 /*!< Set to 1 if CPU supports Vector Table Offset Register */ #define __MPU_PRESENT 1 /*!< MPU present or not */ #define __FPU_PRESENT 1 /*!< FPU present or not */ +#define __CM0P_PRESENT 1 /*!< CM0P present or not */ /** \} Configuration_of_CMSIS */ @@ -451,8 +452,8 @@ typedef enum { #define CY_SRAM0_SIZE 0x00048000UL #define CY_FLASH_BASE 0x10000000UL #define CY_FLASH_SIZE 0x00100000UL -#define CY_WFLASH_BASE 0x14000000UL -#define CY_WFLASH_SIZE 0x00008000UL +#define CY_EM_EEPROM_BASE 0x14000000UL +#define CY_EM_EEPROM_SIZE 0x00008000UL #define CY_XIP_BASE 0x18000000UL #define CY_XIP_SIZE 0x08000000UL #define CY_SFLASH_BASE 0x16000000UL @@ -460,27 +461,18 @@ typedef enum { #define CY_EFUSE_BASE 0x402C0800UL #define CY_EFUSE_SIZE 0x000000C8UL +#define CY_DEVICE_PSOC6ABLE2 #define CY_SILICON_ID 0xE2072100UL - #define CY_HF_CLK_MAX_FREQ 150000000UL -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ +#define CPUSS_FLASHC_PA_SIZE_LOG2 0x7UL #define SCB_GET_EZ_DATA_NR(base) 256u -/* I2C slave support? ('0': no, '1': yes) */ #define SCB_IS_I2C_SLAVE_CAPABLE(base) true -/* I2C master support? ('0': no, '1': yes) */ #define SCB_IS_I2C_MASTER_CAPABLE(base) ((base) != SCB8) -/* DeepSleep support ('0':no, '1': yes) */ #define SCB_IS_I2C_DS_CAPABLE(base) ((base) == SCB8) -/* SPI slave support? ('0': no, '1': yes) */ #define SCB_IS_SPI_SLAVE_CAPABLE(base) true -/* SPI master support? ('0': no, '1': yes) */ #define SCB_IS_SPI_MASTER_CAPABLE(base) ((base) != SCB8) -/* DeepSleep support ('0':no, '1': yes) */ #define SCB_IS_SPI_DS_CAPABLE(base) ((base) == SCB8) -/* UART support? ('0': no, '1': yes) */ #define SCB_IS_UART_CAPABLE(base) ((base) != SCB8) /* IP List */ @@ -570,6 +562,7 @@ typedef enum { #include "cyip_backup.h" #include "cyip_dw.h" #include "cyip_efuse.h" +#include "cyip_efuse_data.h" #include "cyip_profile.h" #include "cyip_hsiom.h" #include "cyip_gpio.h" @@ -1267,15 +1260,19 @@ typedef enum { * I2S *******************************************************************************/ -#define I2S_BASE 0x42A10000UL -#define I2S ((I2S_Type*) I2S_BASE) /* 0x42A10000 */ +#define I2S0_BASE 0x42A10000UL +#define I2S0 ((I2S_Type*) I2S0_BASE) /* 0x42A10000 */ /******************************************************************************* * PDM *******************************************************************************/ -#define PDM_BASE 0x42A20000UL -#define PDM ((PDM_Type*) PDM_BASE) /* 0x42A20000 */ +#define PDM0_BASE 0x42A20000UL +#define PDM0 ((PDM_Type*) PDM0_BASE) /* 0x42A20000 */ + +/* Backward compabitility definitions */ +#define I2S I2S0 +#define PDM PDM0 /** \} CY8C6347BZI-BLD53 */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cy_device_headers.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_device_headers.h similarity index 79% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cy_device_headers.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_device_headers.h index b9775ccc88..985411da79 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/cy_device_headers.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_device_headers.h @@ -5,12 +5,12 @@ * Common header file to be included by the drivers. * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -51,6 +51,16 @@ #include "cy8c68237bz_ble.h" #elif defined (CY8C68237FM_BLE) #include "cy8c68237fm_ble.h" +#elif defined (CY8C6336BZI_BUD13) + #include "cy8c6336bzi_bud13.h" +#elif defined (CY8C6347BZI_BUD43) + #include "cy8c6347bzi_bud43.h" +#elif defined (CY8C6347BZI_BUD33) + #include "cy8c6347bzi_bud33.h" +#elif defined (CY8C6347BZI_BUD53) + #include "cy8c6347bzi_bud53.h" +#elif defined (CY8C6337BZI_BLF13) + #include "cy8c6337bzi_blf13.h" #else #error Undefined part number #endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_config.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_ipc_config.c similarity index 51% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_config.c rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_ipc_config.c index d2ebdd9a52..6d7bca1687 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_config.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_ipc_config.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_ipc_config.c -* \version 1.10 +* \version 1.10.1 * * Description: * This C file is not intended to be part of the IPC driver. It is the code @@ -8,22 +8,18 @@ * and pipes. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ -#include "flash/cy_flash.h" #include "ipc/cy_ipc_drv.h" #include "ipc/cy_ipc_pipe.h" #include "ipc/cy_ipc_sema.h" -#include "sysint/cy_sysint.h" #include "cy_ipc_config.h" -static void Cy_Flash_NotifyHandler(uint32_t * msgPtr); - /* Create an array of endpoint structures */ static cy_stc_ipc_pipe_ep_t cy_ipc_pipe_sysEpArray[CY_IPC_MAX_ENDPOINTS]; @@ -48,11 +44,21 @@ static cy_stc_ipc_pipe_ep_t cy_ipc_pipe_sysEpArray[CY_IPC_MAX_ENDPOINTS]; /* .userPipeIsrHandler */ &Cy_IPC_SystemPipeIsr\ } + + /******************************************************************************* * Function Name: Cy_IPC_SystemSemaInit ****************************************************************************//** * -* Initializes the system semaphores. +* Initializes the system semaphores. The system semaphores are used by Flash. +* +* This function is called in the SystemInit() function. If the default startup +* file is not used, or SystemInit() is not called in your project, +* call the following three functions prior to executing any flash or EmEEPROM +* write or erase operation: +* -# Cy_IPC_SystemSemaInit() +* -# Cy_IPC_SystemPipeInit() +* -# Cy_Flash_Init() * *******************************************************************************/ void Cy_IPC_SystemSemaInit(void) @@ -66,13 +72,49 @@ void Cy_IPC_SystemSemaInit(void) #endif } + +/******************************************************************************* +* Function Name: Cy_IPC_UserPipeIsr +****************************************************************************//** +* +* This is the interrupt service routine for the user pipe. +* +*******************************************************************************/ +void Cy_IPC_UserPipeIsr(void) +{ + Cy_IPC_Pipe_ExecCallback(&cy_ipc_pipe_sysEpArray[CY_IPC_EP_USRPIPE_ADDR]); +} + + +/******************************************************************************* +* Function Name: Cy_IPC_RpcPipeIsr +****************************************************************************//** +* +* This is the interrupt service routine for the RPC pipe. +* +*******************************************************************************/ +void Cy_IPC_RpcPipeIsr(void) +{ + Cy_IPC_Pipe_ExecCallback(&cy_ipc_pipe_sysEpArray[CY_IPC_EP_RPCPIPE_ADDR]); +} + /******************************************************************************* * Function Name: Cy_IPC_SystemPipeInit ****************************************************************************//** * -* Initializes the system pipes. The system pipes are used by BLE. +* Initializes the system pipes. The system pipes are used by BLE and Flash. * \note The function should be called on all CPUs. * +* This function is called in the SystemInit() function. If the default startup +* file is not used, or SystemInit() is not called in your project, +* call the following three functions prior to executing any flash or EmEEPROM +* write or erase operation: +* -# Cy_IPC_SystemSemaInit() +* -# Cy_IPC_SystemPipeInit() +* -# Cy_Flash_Init() +* +* Also this function is called to support BLE host/controller communication. +* *******************************************************************************/ void Cy_IPC_SystemPipeInit(void) { @@ -81,14 +123,54 @@ void Cy_IPC_SystemPipeInit(void) intr = Cy_SysLib_EnterCriticalSection(); static cy_ipc_pipe_callback_ptr_t cy_ipc_pipe_sysCbArray[CY_IPC_CYPIPE_CLIENT_CNT]; + static cy_ipc_pipe_callback_ptr_t cy_ipc_pipe_userCbArray[CY_IPC_USRPIPE_CLIENT_CNT]; + static cy_ipc_pipe_callback_ptr_t cy_ipc_pipe_rpcCbArray[CY_IPC_RPCPIPE_CLIENT_CNT]; static const cy_stc_ipc_pipe_config_t systemPipeConfig = CY_CYPIPE_DEFAULT_CONFIG; + static const cy_stc_ipc_pipe_config_t userPipeConfig = { + .ep0ConfigData = { + .ipcNotifierNumber = CY_IPC_INTR_USRPIPE_CM0, + .ipcNotifierPriority = CY_IPC_INTR_USRPIPE_PRIOR_EP0, + .ipcNotifierMuxNumber = CY_IPC_INTR_USRPIPE_MUX_EP0, + .epAddress = CY_IPC_EP_USRPIPE_CM0_ADDR, + .epConfig = CY_IPC_USRPIPE_CONFIG_EP0 + }, + .ep1ConfigData = { + .ipcNotifierNumber = CY_IPC_INTR_USRPIPE_CM4, + .ipcNotifierPriority = CY_IPC_INTR_USRPIPE_PRIOR_EP1, + .ipcNotifierMuxNumber = 0u, + .epAddress = CY_IPC_EP_USRPIPE_CM4_ADDR, + .epConfig = CY_IPC_USRPIPE_CONFIG_EP1 + }, + .endpointClientsCount = CY_IPC_USRPIPE_CLIENT_CNT, + .endpointsCallbacksArray = cy_ipc_pipe_userCbArray, + .userPipeIsrHandler = &Cy_IPC_UserPipeIsr + }; + static const cy_stc_ipc_pipe_config_t rpcPipeConfig = { + .ep0ConfigData = { + .ipcNotifierNumber = CY_IPC_INTR_RPCPIPE_CM0, + .ipcNotifierPriority = CY_IPC_INTR_RPCPIPE_PRIOR_EP0, + .ipcNotifierMuxNumber = CY_IPC_INTR_RPCPIPE_MUX_EP0, + .epAddress = CY_IPC_EP_RPCPIPE_CM0_ADDR, + .epConfig = CY_IPC_RPCPIPE_CONFIG_EP0 + }, + .ep1ConfigData = { + .ipcNotifierNumber = CY_IPC_INTR_RPCPIPE_CM4, + .ipcNotifierPriority = CY_IPC_INTR_RPCPIPE_PRIOR_EP1, + .ipcNotifierMuxNumber = 0u, + .epAddress = CY_IPC_EP_RPCPIPE_CM4_ADDR, + .epConfig = CY_IPC_RPCPIPE_CONFIG_EP1 + }, + .endpointClientsCount = CY_IPC_RPCPIPE_CLIENT_CNT, + .endpointsCallbacksArray = cy_ipc_pipe_rpcCbArray, + .userPipeIsrHandler = &Cy_IPC_RpcPipeIsr + }; Cy_IPC_Pipe_Config(cy_ipc_pipe_sysEpArray); Cy_IPC_Pipe_Init(&systemPipeConfig); - - (void)Cy_IPC_Pipe_RegisterCallback(CY_IPC_EP_CYPIPE_ADDR, &Cy_Flash_NotifyHandler, (uint32_t)CY_FLASH_IPC_CLIENT_ID); + Cy_IPC_Pipe_Init(&userPipeConfig); + Cy_IPC_Pipe_Init(&rpcPipeConfig); Cy_SysLib_ExitCriticalSection(intr); } @@ -105,39 +187,6 @@ void Cy_IPC_SystemPipeIsr(void) Cy_IPC_Pipe_ExecCallback(&cy_ipc_pipe_sysEpArray[CY_IPC_EP_CYPIPE_ADDR]); } -/******************************************************************************* -* Function Name: Cy_Flash_NotifyHandler -****************************************************************************//** -* -* This is the interrupt service routine for the pipe notifications. -* -*******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif -static void Cy_Flash_NotifyHandler(uint32_t * msgPtr) -{ - uint32_t intr; - - IPC_MSG *ipcMsgPtr = (IPC_MSG *)msgPtr; - - if (CY_FLASH_ENTER_WAIT_LOOP == ipcMsgPtr->pktType) - { - intr = Cy_SysLib_EnterCriticalSection(); - - /* Notification to the Flash driver to start the current operation */ - (void) Cy_IPC_Sema_Set(CY_FLASH_WAIT_SEMA, true); - - /* Notification to me about the end of the operation */ - while (CY_IPC_SEMA_STATUS_LOCKED == Cy_IPC_Sema_Status(CY_FLASH_WAIT_SEMA)) - { - } - - Cy_SysLib_ExitCriticalSection(intr); - } -} /* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_config.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_ipc_config.h similarity index 56% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_config.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_ipc_config.h index 97be5db9ee..67edd79ae1 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_config.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cy_ipc_config.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_ipc_config.h -* \version 1.10 +* \version 1.10.1 * * \brief * This header file is not intended to be part of the IPC driver since it defines @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -51,12 +51,6 @@ This will allow 128 (4*32) semaphores */ #define CY_IPC_SEMA_COUNT (uint32_t)(128u) -/* System IPC Notify Masks */ -#define CY_IPC_SEMA_NOTIFY_MASK (uint32_t)(0x0001ul << CY_IPC_CHAN_SEMA) - -/* System IPC channel release Masks */ -#define CY_IPC_SEM_RELEASE_MASK (uint32_t)(0x0001ul << CY_IPC_CHAN_SEMA) - /* IPC Pipe definitions */ #define CY_IPC_MAX_ENDPOINTS (uint32_t)(8u) @@ -65,6 +59,7 @@ *******************************************************************************/ #define CY_IPC_CYPIPE_CLIENT_CNT (uint32_t)(8u) #define CY_IPC_USRPIPE_CLIENT_CNT (uint32_t)(8u) +#define CY_IPC_RPCPIPE_CLIENT_CNT (uint32_t)(16u) #if (CY_CPU_CORTEX_M0P) #define CY_IPC_EP_CYPIPE_ADDR CY_IPC_EP_CYPIPE_CM0_ADDR @@ -72,7 +67,7 @@ #define CY_IPC_EP_CYPIPE_ADDR CY_IPC_EP_CYPIPE_CM4_ADDR #endif /* (CY_CPU_CORTEX_M0P) */ -#define CY_IPC_INTR_CYPIPE_MUX_EP0 (uint32_t)(1u) /* IPC CYPRESS PIPE */ +#define CY_IPC_INTR_CYPIPE_MUX_EP0 (uint32_t)(1u) /* IPC CYPRESS PIPE */ #define CY_IPC_INTR_CYPIPE_EP0 (uint32_t)(3u) /* Notifier EP0 */ #define CY_IPC_INTR_CYPIPE_PRIOR_EP0 (uint32_t)(1u) /* Notifier Priority */ @@ -119,12 +114,101 @@ #define CY_IPC_EP_USRPIPE_ADDR_EP0 (uint32_t)(2u) #define CY_IPC_EP_USRPIPE_ADDR_EP1 (uint32_t)(3u) +/* Endpoint indexes in the pipe array */ +#define CY_IPC_EP_USRPIPE_CM0_ADDR (uint32_t)(2u) +#define CY_IPC_EP_USRPIPE_CM4_ADDR (uint32_t)(3u) + + +#if (CY_CPU_CORTEX_M0P) + #define CY_IPC_EP_USRPIPE_ADDR CY_IPC_EP_USRPIPE_CM0_ADDR + #define CY_IPC_EP_USRPIPE_DEST CY_IPC_EP_USRPIPE_CM4_ADDR +#else + #define CY_IPC_EP_USRPIPE_ADDR CY_IPC_EP_USRPIPE_CM4_ADDR + #define CY_IPC_EP_USRPIPE_DEST CY_IPC_EP_USRPIPE_CM0_ADDR +#endif /* (CY_CPU_CORTEX_M0P) */ + +#define CY_IPC_INTR_USRPIPE_MUX_EP0 (uint32_t)(2u) +#define CY_IPC_INTR_USRPIPE_EP0 CY_IPC_INTR_USRPIPE_CM0 +#define CY_IPC_INTR_USRPIPE_PRIOR_EP0 (uint32_t)(1u) /* Notifier Priority */ + +#define CY_IPC_INTR_USRPIPE_EP1 CY_IPC_INTR_USRPIPE_CM4 +#define CY_IPC_INTR_USRPIPE_PRIOR_EP1 (uint32_t)(1u) /* Notifier Priority */ + +#define CY_IPC_USRPIPE_CHAN_MASK_EP0 (uint32_t)(0x0001ul << CY_IPC_CHAN_USRPIPE_CM0) +#define CY_IPC_USRPIPE_CHAN_MASK_EP1 (uint32_t)(0x0001ul << CY_IPC_CHAN_USRPIPE_CM4) + + +#define CY_IPC_USRPIPE_CONFIG_EP0 (uint32_t)( (CY_IPC_USRPIPE_INTR_MASK << CY_IPC_PIPE_CFG_IMASK_Pos) \ + | (CY_IPC_INTR_USRPIPE_EP0 << CY_IPC_PIPE_CFG_INTR_Pos) \ + | CY_IPC_CHAN_USRPIPE_CM0) +#define CY_IPC_USRPIPE_CONFIG_EP1 (uint32_t)( (CY_IPC_USRPIPE_INTR_MASK << CY_IPC_PIPE_CFG_IMASK_Pos) \ + | (CY_IPC_INTR_USRPIPE_EP1 << CY_IPC_PIPE_CFG_INTR_Pos) \ + | CY_IPC_CHAN_USRPIPE_CM4) +#define CY_IPC_USRPIPE_INTR_MASK (uint32_t)( CY_IPC_USRPIPE_CHAN_MASK_EP0 | CY_IPC_USRPIPE_CHAN_MASK_EP1 ) + + +/******************************************************************************/ +#define CY_IPC_CHAN_RPCPIPE_CM0 (uint32_t)(10u) +#define CY_IPC_CHAN_RPCPIPE_CM4 (uint32_t)(11u) + +#define CY_IPC_INTR_RPCPIPE_CM0 (uint32_t)(10u) +#define CY_IPC_INTR_RPCPIPE_CM4 (uint32_t)(11u) + +#define CY_IPC_EP_RPCPIPE_ADDR_EP0 (uint32_t)(4u) +#define CY_IPC_EP_RPCPIPE_ADDR_EP1 (uint32_t)(5u) + +/* Endpoint indexes in the pipe array */ +#define CY_IPC_EP_RPCPIPE_CM0_ADDR (uint32_t)(4u) +#define CY_IPC_EP_RPCPIPE_CM4_ADDR (uint32_t)(5u) + + +#if (CY_CPU_CORTEX_M0P) + #define CY_IPC_EP_RPCPIPE_ADDR CY_IPC_EP_RPCPIPE_CM0_ADDR + #define CY_IPC_EP_RPCPIPE_DEST CY_IPC_EP_RPCPIPE_CM4_ADDR +#else + #define CY_IPC_EP_RPCPIPE_ADDR CY_IPC_EP_RPCPIPE_CM4_ADDR + #define CY_IPC_EP_RPCPIPE_DEST CY_IPC_EP_RPCPIPE_CM0_ADDR +#endif /* (CY_CPU_CORTEX_M0P) */ + +#define CY_IPC_INTR_RPCPIPE_MUX_EP0 (uint32_t)(4u) +#define CY_IPC_INTR_RPCPIPE_EP0 CY_IPC_INTR_RPCPIPE_CM0 +#define CY_IPC_INTR_RPCPIPE_PRIOR_EP0 (uint32_t)(1u) /* Notifier Priority */ + +#define CY_IPC_INTR_RPCPIPE_EP1 CY_IPC_INTR_RPCPIPE_CM4 +#define CY_IPC_INTR_RPCPIPE_PRIOR_EP1 (uint32_t)(1u) /* Notifier Priority */ + +#define CY_IPC_RPCPIPE_CHAN_MASK_EP0 (uint32_t)(0x0001ul << CY_IPC_CHAN_RPCPIPE_CM0) +#define CY_IPC_RPCPIPE_CHAN_MASK_EP1 (uint32_t)(0x0001ul << CY_IPC_CHAN_RPCPIPE_CM4) + + +#define CY_IPC_RPCPIPE_CONFIG_EP0 (uint32_t)( (CY_IPC_RPCPIPE_INTR_MASK << CY_IPC_PIPE_CFG_IMASK_Pos) \ + | (CY_IPC_INTR_RPCPIPE_EP0 << CY_IPC_PIPE_CFG_INTR_Pos) \ + | CY_IPC_CHAN_RPCPIPE_CM0) +#define CY_IPC_RPCPIPE_CONFIG_EP1 (uint32_t)( (CY_IPC_RPCPIPE_INTR_MASK << CY_IPC_PIPE_CFG_IMASK_Pos) \ + | (CY_IPC_INTR_RPCPIPE_EP1 << CY_IPC_PIPE_CFG_INTR_Pos) \ + | CY_IPC_CHAN_RPCPIPE_CM4) +#define CY_IPC_RPCPIPE_INTR_MASK (uint32_t)( CY_IPC_RPCPIPE_CHAN_MASK_EP0 | CY_IPC_RPCPIPE_CHAN_MASK_EP1 ) + #ifdef __cplusplus extern "C" { #endif + + +/* +* \addtogroup group_ipc_configuration_sema +* \{ +*/ void Cy_IPC_SystemSemaInit(void); +/* \} group_ipc_configuration_sema */ + +/* +* \addtogroup group_ipc_configuration_cypipe +* \{ +*/ void Cy_IPC_SystemPipeInit(void); +/* \} group_ipc_configuration_cypipe */ + void Cy_IPC_SystemPipeIsr(void); #ifdef __cplusplus diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cymetadata.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cymetadata.c new file mode 100644 index 0000000000..9d1538e803 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/cymetadata.c @@ -0,0 +1,58 @@ +/******************************************************************************* +* File Name: cymetadata.c +* +* PSoC Creator 4.1 +* +* Description: +* This file defines all extra memory spaces that need to be included. +* This file is automatically generated by PSoC Creator. +* +******************************************************************************** +* Copyright (c) 2007-2017 Cypress Semiconductor. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +********************************************************************************/ + + +#include "stdint.h" + + +#if defined(__GNUC__) || defined(__ARMCC_VERSION) +#ifndef CY_META_SECTION +#define CY_META_SECTION __attribute__ ((__section__(".cymeta"), used)) +#endif +CY_META_SECTION +#elif defined(__ICCARM__) + +#pragma location=".cymeta" +#else +#error "Unsupported toolchain" +#endif +const uint8_t cy_metadata[] = { +#if defined(CY8C637BZI_BLD74) + 0x00u, 0x05u, 0xE2u, 0x01u, 0x11u, 0x00u, 0x00u, 0x01u, + 0x00u, 0x00u, 0x00u, 0x00u +#elif defined(CY8C6347BZI_BLD53) + 0x00u, 0x05u, 0xE2u, 0x07u, 0x21u, 0x00u, 0x21u, 0x01u, + 0x00u, 0x00u, 0x00u, 0x00u +#else +#error "Unknown target device" +#endif +}; + +#if defined(CY8C637BZI_BLD74) +#if defined(__GNUC__) || defined(__ARMCC_VERSION) +#ifndef CY_CHIP_PROT_SECTION +#define CY_CHIP_PROT_SECTION __attribute__ ((__section__(".cychipprotect"), used)) +#endif +CY_CHIP_PROT_SECTION +#elif defined(__ICCARM__) +#pragma location=".cychipprotect" +#else +#error "Unsupported toolchain" +#endif +const uint8_t cy_meta_chipprotect[] = { + 0x01u +}; +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/gpio_psoc63_116_bga_ble.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/gpio_psoc63_116_bga_ble.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/gpio_psoc63_116_bga_ble.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/gpio_psoc63_116_bga_ble.h index b3a17d5830..f6afee5360 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/gpio_psoc63_116_bga_ble.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/gpio_psoc63_116_bga_ble.h @@ -5,12 +5,12 @@ * PSoC 63 device GPIO header for 116-BGA-BLE package * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -34,180 +34,258 @@ enum /* Port List */ /* PORT 0 (GPIO) */ #define P0_0_PORT GPIO_PRT0 +#define P0_0_PIN 0u #define P0_0_NUM 0u #define P0_1_PORT GPIO_PRT0 +#define P0_1_PIN 1u #define P0_1_NUM 1u #define P0_2_PORT GPIO_PRT0 +#define P0_2_PIN 2u #define P0_2_NUM 2u #define P0_3_PORT GPIO_PRT0 +#define P0_3_PIN 3u #define P0_3_NUM 3u #define P0_4_PORT GPIO_PRT0 +#define P0_4_PIN 4u #define P0_4_NUM 4u #define P0_5_PORT GPIO_PRT0 +#define P0_5_PIN 5u #define P0_5_NUM 5u /* PORT 1 (GPIO_OVT) */ #define P1_0_PORT GPIO_PRT1 +#define P1_0_PIN 0u #define P1_0_NUM 0u #define P1_1_PORT GPIO_PRT1 +#define P1_1_PIN 1u #define P1_1_NUM 1u #define P1_2_PORT GPIO_PRT1 +#define P1_2_PIN 2u #define P1_2_NUM 2u #define P1_3_PORT GPIO_PRT1 +#define P1_3_PIN 3u #define P1_3_NUM 3u #define P1_4_PORT GPIO_PRT1 +#define P1_4_PIN 4u #define P1_4_NUM 4u #define P1_5_PORT GPIO_PRT1 +#define P1_5_PIN 5u #define P1_5_NUM 5u /* PORT 5 (GPIO) */ #define P5_0_PORT GPIO_PRT5 +#define P5_0_PIN 0u #define P5_0_NUM 0u #define P5_1_PORT GPIO_PRT5 +#define P5_1_PIN 1u #define P5_1_NUM 1u #define P5_2_PORT GPIO_PRT5 +#define P5_2_PIN 2u #define P5_2_NUM 2u #define P5_3_PORT GPIO_PRT5 +#define P5_3_PIN 3u #define P5_3_NUM 3u #define P5_4_PORT GPIO_PRT5 +#define P5_4_PIN 4u #define P5_4_NUM 4u #define P5_5_PORT GPIO_PRT5 +#define P5_5_PIN 5u #define P5_5_NUM 5u #define P5_6_PORT GPIO_PRT5 +#define P5_6_PIN 6u #define P5_6_NUM 6u /* PORT 6 (GPIO) */ #define P6_0_PORT GPIO_PRT6 +#define P6_0_PIN 0u #define P6_0_NUM 0u #define P6_1_PORT GPIO_PRT6 +#define P6_1_PIN 1u #define P6_1_NUM 1u #define P6_2_PORT GPIO_PRT6 +#define P6_2_PIN 2u #define P6_2_NUM 2u #define P6_3_PORT GPIO_PRT6 +#define P6_3_PIN 3u #define P6_3_NUM 3u #define P6_4_PORT GPIO_PRT6 +#define P6_4_PIN 4u #define P6_4_NUM 4u #define P6_5_PORT GPIO_PRT6 +#define P6_5_PIN 5u #define P6_5_NUM 5u #define P6_6_PORT GPIO_PRT6 +#define P6_6_PIN 6u #define P6_6_NUM 6u #define P6_7_PORT GPIO_PRT6 +#define P6_7_PIN 7u #define P6_7_NUM 7u /* PORT 7 (GPIO) */ #define P7_0_PORT GPIO_PRT7 +#define P7_0_PIN 0u #define P7_0_NUM 0u #define P7_1_PORT GPIO_PRT7 +#define P7_1_PIN 1u #define P7_1_NUM 1u #define P7_2_PORT GPIO_PRT7 +#define P7_2_PIN 2u #define P7_2_NUM 2u #define P7_3_PORT GPIO_PRT7 +#define P7_3_PIN 3u #define P7_3_NUM 3u #define P7_4_PORT GPIO_PRT7 +#define P7_4_PIN 4u #define P7_4_NUM 4u #define P7_5_PORT GPIO_PRT7 +#define P7_5_PIN 5u #define P7_5_NUM 5u #define P7_6_PORT GPIO_PRT7 +#define P7_6_PIN 6u #define P7_6_NUM 6u #define P7_7_PORT GPIO_PRT7 +#define P7_7_PIN 7u #define P7_7_NUM 7u /* PORT 8 (GPIO) */ #define P8_0_PORT GPIO_PRT8 +#define P8_0_PIN 0u #define P8_0_NUM 0u #define P8_1_PORT GPIO_PRT8 +#define P8_1_PIN 1u #define P8_1_NUM 1u #define P8_2_PORT GPIO_PRT8 +#define P8_2_PIN 2u #define P8_2_NUM 2u #define P8_3_PORT GPIO_PRT8 +#define P8_3_PIN 3u #define P8_3_NUM 3u #define P8_4_PORT GPIO_PRT8 +#define P8_4_PIN 4u #define P8_4_NUM 4u #define P8_5_PORT GPIO_PRT8 +#define P8_5_PIN 5u #define P8_5_NUM 5u #define P8_6_PORT GPIO_PRT8 +#define P8_6_PIN 6u #define P8_6_NUM 6u #define P8_7_PORT GPIO_PRT8 +#define P8_7_PIN 7u #define P8_7_NUM 7u /* PORT 9 (GPIO) */ #define P9_0_PORT GPIO_PRT9 +#define P9_0_PIN 0u #define P9_0_NUM 0u #define P9_1_PORT GPIO_PRT9 +#define P9_1_PIN 1u #define P9_1_NUM 1u #define P9_2_PORT GPIO_PRT9 +#define P9_2_PIN 2u #define P9_2_NUM 2u #define P9_3_PORT GPIO_PRT9 +#define P9_3_PIN 3u #define P9_3_NUM 3u #define P9_4_PORT GPIO_PRT9 +#define P9_4_PIN 4u #define P9_4_NUM 4u #define P9_5_PORT GPIO_PRT9 +#define P9_5_PIN 5u #define P9_5_NUM 5u #define P9_6_PORT GPIO_PRT9 +#define P9_6_PIN 6u #define P9_6_NUM 6u #define P9_7_PORT GPIO_PRT9 +#define P9_7_PIN 7u #define P9_7_NUM 7u /* PORT 10 (GPIO) */ #define P10_0_PORT GPIO_PRT10 +#define P10_0_PIN 0u #define P10_0_NUM 0u #define P10_1_PORT GPIO_PRT10 +#define P10_1_PIN 1u #define P10_1_NUM 1u #define P10_2_PORT GPIO_PRT10 +#define P10_2_PIN 2u #define P10_2_NUM 2u #define P10_3_PORT GPIO_PRT10 +#define P10_3_PIN 3u #define P10_3_NUM 3u #define P10_4_PORT GPIO_PRT10 +#define P10_4_PIN 4u #define P10_4_NUM 4u #define P10_5_PORT GPIO_PRT10 +#define P10_5_PIN 5u #define P10_5_NUM 5u #define P10_6_PORT GPIO_PRT10 +#define P10_6_PIN 6u #define P10_6_NUM 6u /* PORT 11 (GPIO) */ #define P11_0_PORT GPIO_PRT11 +#define P11_0_PIN 0u #define P11_0_NUM 0u #define P11_1_PORT GPIO_PRT11 +#define P11_1_PIN 1u #define P11_1_NUM 1u #define P11_2_PORT GPIO_PRT11 +#define P11_2_PIN 2u #define P11_2_NUM 2u #define P11_3_PORT GPIO_PRT11 +#define P11_3_PIN 3u #define P11_3_NUM 3u #define P11_4_PORT GPIO_PRT11 +#define P11_4_PIN 4u #define P11_4_NUM 4u #define P11_5_PORT GPIO_PRT11 +#define P11_5_PIN 5u #define P11_5_NUM 5u #define P11_6_PORT GPIO_PRT11 +#define P11_6_PIN 6u #define P11_6_NUM 6u #define P11_7_PORT GPIO_PRT11 +#define P11_7_PIN 7u #define P11_7_NUM 7u /* PORT 12 (GPIO) */ #define P12_0_PORT GPIO_PRT12 +#define P12_0_PIN 0u #define P12_0_NUM 0u #define P12_1_PORT GPIO_PRT12 +#define P12_1_PIN 1u #define P12_1_NUM 1u #define P12_2_PORT GPIO_PRT12 +#define P12_2_PIN 2u #define P12_2_NUM 2u #define P12_3_PORT GPIO_PRT12 +#define P12_3_PIN 3u #define P12_3_NUM 3u #define P12_4_PORT GPIO_PRT12 +#define P12_4_PIN 4u #define P12_4_NUM 4u #define P12_5_PORT GPIO_PRT12 +#define P12_5_PIN 5u #define P12_5_NUM 5u #define P12_6_PORT GPIO_PRT12 +#define P12_6_PIN 6u #define P12_6_NUM 6u #define P12_7_PORT GPIO_PRT12 +#define P12_7_PIN 7u #define P12_7_NUM 7u /* PORT 13 (GPIO) */ #define P13_0_PORT GPIO_PRT13 +#define P13_0_PIN 0u #define P13_0_NUM 0u #define P13_1_PORT GPIO_PRT13 +#define P13_1_PIN 1u #define P13_1_NUM 1u #define P13_6_PORT GPIO_PRT13 +#define P13_6_PIN 6u #define P13_6_NUM 6u #define P13_7_PORT GPIO_PRT13 +#define P13_7_PIN 7u #define P13_7_NUM 7u /* Analog Connections */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/psoc63_config.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/psoc63_config.h similarity index 83% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/psoc63_config.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/psoc63_config.h index f4f6196d97..c860dfc139 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/psoc63_config.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/psoc63_config.h @@ -5,12 +5,12 @@ * PSoC 63 device configuration header * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -1438,7 +1438,7 @@ typedef enum /* Level or edge detection setting for a trigger mux */ typedef enum { - /* The trigger is a simple level output */ + /* The trigger is a simple level output */ TRIGGER_TYPE_LEVEL = 0u, /* The trigger is synchronized to the consumer blocks clock and a two cycle pulse is generated on this clock */ @@ -1617,8 +1617,12 @@ typedef enum #define SRSS_HARD_ECOMUX_PRESENT 1u /* ALTHF mux is present in hardened clkactfllmux block (Must be >= ALTHF_PRESENT) */ #define SRSS_HARD_ALTHFMUX_PRESENT 1u -/* Width of MCWDT Subcounters 0 and 1. Applies to all MCWDT. */ -#define SRSS_MCWDT_CTR_WIDTH 32u +/* Low-current buck regulator present. Can be derived from S40S_SISOBUCKLC_PRESENT + or SIMOBUCK_PRESENT. */ +#define SRSS_BUCKCTL_PRESENT 1u +/* Low-current SISO buck core regulator is present. Only compatible with ULP + linear regulator system (ULPLINREG_PRESENT==1). */ +#define SRSS_S40S_SISOBUCKLC_PRESENT 0u /* Backup memory is present (only used when BACKUP_PRESENT==1) */ #define SRSS_BACKUP_BMEM_PRESENT 0u /* Number of Backup registers to include (each is 32b). Only used when @@ -1628,18 +1632,6 @@ typedef enum #define IOSS_HSIOM_AMUX_SPLIT_NR 9u /* Number of HSIOM ports in device (same as GPIO.GPIO_PRT_NR) */ #define IOSS_HSIOM_HSIOM_PORT_NR 15u -/* Number of PWR/GND MONITOR CELLs in the device */ -#define IOSS_HSIOM_MONITOR_NR 0u -/* Number of PWR/GND MONITOR CELLs in range 0..31 */ -#define IOSS_HSIOM_MONITOR_NR_0_31 0u -/* Number of PWR/GND MONITOR CELLs in range 32..63 */ -#define IOSS_HSIOM_MONITOR_NR_32_63 0u -/* Number of PWR/GND MONITOR CELLs in range 64..95 */ -#define IOSS_HSIOM_MONITOR_NR_64_95 0u -/* Number of PWR/GND MONITOR CELLs in range 96..127 */ -#define IOSS_HSIOM_MONITOR_NR_96_127 0u -/* Indicates the presence of alternate JTAG interface */ -#define IOSS_HSIOM_ALTJTAG_PRESENT 0u /* Number of GPIO ports in range 0..31 */ #define IOSS_GPIO_GPIO_PORT_NR_0_31 15u /* Number of GPIO ports in range 32..63 */ @@ -1660,6 +1652,550 @@ typedef enum #define PERI_MS_PPU_COMBINATORIAL 1u /* The number of programmable PPU structures for PERI (all peripherals) */ #define PERI_MS_PPU_PROG_STRUCT_NR 16u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_CLOCK_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT0_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_CLOCK_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT1_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_CLOCK_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL2_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL3_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL4_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL5_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL6_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL7_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL8_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL9_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL12_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL13_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT2_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL2_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL3_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL4_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL5_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL6_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL8_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL9_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL10_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL11_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL12_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT3_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL2_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT4_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT5_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL2_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL3_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL4_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL5_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL6_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL7_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL8_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL9_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT6_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT7_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT8_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT9_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL0_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL1_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL2_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT10_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT11_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT12_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT13_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT14_PERI_GROUP_STRUCT_SL15_PRESENT 0u +/* Presence of a timeout functionality (1: Yes, 0:No) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_CLOCK_PRESENT 1u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL0_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL1_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL2_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL3_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL4_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL5_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL6_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL7_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL8_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL9_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL10_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL11_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL12_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL13_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL14_PRESENT 0u +/* Slave present (0:No, 1:Yes) */ +#define PERI_GROUP_PRESENT15_PERI_GROUP_STRUCT_SL15_PRESENT 0u /* Number of programmable clocks (outputs) */ #define PERI_CLOCK_NR 59u /* Number of 8.0 dividers */ @@ -2388,6 +2924,78 @@ typedef enum /* PDM capable? (0=No,1=Yes) */ #define AUDIOSS_PDM 1u +/* MMIO Targets Defines */ +#define CY_MMIO_CRYPTO_GROUP_NR 1u +#define CY_MMIO_CRYPTO_SLAVE_NR 1u +#define CY_MMIO_CPUSS_GROUP_NR 2u +#define CY_MMIO_CPUSS_SLAVE_NR 1u +#define CY_MMIO_FAULT_GROUP_NR 2u +#define CY_MMIO_FAULT_SLAVE_NR 2u +#define CY_MMIO_IPC_GROUP_NR 2u +#define CY_MMIO_IPC_SLAVE_NR 3u +#define CY_MMIO_PROT_GROUP_NR 2u +#define CY_MMIO_PROT_SLAVE_NR 4u +#define CY_MMIO_FLASHC_GROUP_NR 2u +#define CY_MMIO_FLASHC_SLAVE_NR 5u +#define CY_MMIO_SRSS_GROUP_NR 2u +#define CY_MMIO_SRSS_SLAVE_NR 6u +#define CY_MMIO_BACKUP_GROUP_NR 2u +#define CY_MMIO_BACKUP_SLAVE_NR 7u +#define CY_MMIO_DW_GROUP_NR 2u +#define CY_MMIO_DW_SLAVE_NR 8u +#define CY_MMIO_EFUSE_GROUP_NR 2u +#define CY_MMIO_EFUSE_SLAVE_NR 12u +#define CY_MMIO_PROFILE_GROUP_NR 2u +#define CY_MMIO_PROFILE_SLAVE_NR 13u +#define CY_MMIO_HSIOM_GROUP_NR 3u +#define CY_MMIO_HSIOM_SLAVE_NR 1u +#define CY_MMIO_GPIO_GROUP_NR 3u +#define CY_MMIO_GPIO_SLAVE_NR 2u +#define CY_MMIO_SMARTIO_GROUP_NR 3u +#define CY_MMIO_SMARTIO_SLAVE_NR 3u +#define CY_MMIO_UDB_GROUP_NR 3u +#define CY_MMIO_UDB_SLAVE_NR 4u +#define CY_MMIO_LPCOMP_GROUP_NR 3u +#define CY_MMIO_LPCOMP_SLAVE_NR 5u +#define CY_MMIO_CSD0_GROUP_NR 3u +#define CY_MMIO_CSD0_SLAVE_NR 6u +#define CY_MMIO_TCPWM0_GROUP_NR 3u +#define CY_MMIO_TCPWM0_SLAVE_NR 8u +#define CY_MMIO_TCPWM1_GROUP_NR 3u +#define CY_MMIO_TCPWM1_SLAVE_NR 9u +#define CY_MMIO_LCD0_GROUP_NR 3u +#define CY_MMIO_LCD0_SLAVE_NR 10u +#define CY_MMIO_BLE_GROUP_NR 3u +#define CY_MMIO_BLE_SLAVE_NR 11u +#define CY_MMIO_USBFS0_GROUP_NR 3u +#define CY_MMIO_USBFS0_SLAVE_NR 12u +#define CY_MMIO_SMIF0_GROUP_NR 4u +#define CY_MMIO_SMIF0_SLAVE_NR 2u +#define CY_MMIO_SCB0_GROUP_NR 6u +#define CY_MMIO_SCB0_SLAVE_NR 1u +#define CY_MMIO_SCB1_GROUP_NR 6u +#define CY_MMIO_SCB1_SLAVE_NR 2u +#define CY_MMIO_SCB2_GROUP_NR 6u +#define CY_MMIO_SCB2_SLAVE_NR 3u +#define CY_MMIO_SCB3_GROUP_NR 6u +#define CY_MMIO_SCB3_SLAVE_NR 4u +#define CY_MMIO_SCB4_GROUP_NR 6u +#define CY_MMIO_SCB4_SLAVE_NR 5u +#define CY_MMIO_SCB5_GROUP_NR 6u +#define CY_MMIO_SCB5_SLAVE_NR 6u +#define CY_MMIO_SCB6_GROUP_NR 6u +#define CY_MMIO_SCB6_SLAVE_NR 7u +#define CY_MMIO_SCB7_GROUP_NR 6u +#define CY_MMIO_SCB7_SLAVE_NR 8u +#define CY_MMIO_SCB8_GROUP_NR 6u +#define CY_MMIO_SCB8_SLAVE_NR 9u +#define CY_MMIO_PASS_GROUP_NR 9u +#define CY_MMIO_PASS_SLAVE_NR 1u +#define CY_MMIO_I2S0_GROUP_NR 10u +#define CY_MMIO_I2S0_SLAVE_NR 1u +#define CY_MMIO_PDM0_GROUP_NR 10u +#define CY_MMIO_PDM0_SLAVE_NR 2u + #endif /* _PSOC63_CONFIG_H_ */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/system_psoc63.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/system_psoc63.h similarity index 69% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/system_psoc63.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/system_psoc63.h index b4d44c1618..42fa1534a0 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/system_psoc63.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/device/system_psoc63.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file system_psoc63.h -* \version 2.0 +* \version 2.10 * * \brief Device system header file. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -24,111 +24,136 @@ * - See \ref group_system_config_device_initialization for the: * * \ref group_system_config_dual_core_device_initialization * * \ref group_system_config_single_core_device_initialization -* - See \ref group_system_config_device_memory_definition for the: -* * \ref group_system_config_device_memory_dual_core_definition -* * \ref group_system_config_device_memory_single_core_definition +* - \ref group_system_config_device_memory_definition * - \ref group_system_config_heap_stack_config * - \ref group_system_config_merge_apps * - Default interrupt handlers definition -* - \ref group_system_config_device_vector_table +* - \ref group_system_config_device_vector_table * - \ref group_system_config_cm4_functions * * \section group_system_config_configuration Configuration Considerations * * \subsection group_system_config_device_memory_definition Device Memory Definition -* The physical flash and RAM memory is shared between the CPU cores. The flash -* and RAM allocation for each -* CPU is defined by the linker scripts. +* The flash and RAM allocation for each CPU is defined by the linker scripts. +* For dual-core devices, the physical flash and RAM memory is shared between the CPU cores. +* 2 KB of RAM (allocated at the end of RAM) are reserved for system use. +* For Single-Core devices the system reserves additional 80 bytes of RAM. +* Using the reserved memory area for other purposes will lead to unexpected behavior. * -* \subsubsection group_system_config_device_memory_dual_core_definition Dual-Core Devices -* By default, the flash and RAM memory is equally divided between two cores. -* This proportion can be changed by editing -* the linker configuration files. +* \note The linker files provided with the PDL are generic and handle all common +* use cases. Your project may not use every section defined in the linker files. +* In that case you may see warnings during the build process. To eliminate build +* warnings in your project, you can simply comment out or remove the relevant +* code in the linker file. * * ARM GCC\n * The flash and RAM sections for the CPU are defined in the linker files: -* 'xx_yy.ld', where 'xx' is the device group, and 'yy' is the target CPU; for -* example, 'cy8c6x7_cm0plus.ld' and 'cy8c6x7_cm4_dual.ld'. -* Note: if the start of the Cortex-M4 application image is changed, the value +* 'xx_yy.ld', where 'xx' is the device group, and 'yy' is the target CPU; for example, +* 'cy8c6xx7_cm0plus.ld' and 'cy8c6xx7_cm4_dual.ld'. +* \note If the start of the Cortex-M4 application image is changed, the value * of the of the \ref CY_CORTEX_M4_APPL_ADDR should also be changed. The * \ref CY_CORTEX_M4_APPL_ADDR macro should be used as the parameter for the * Cy_SysEnableCM4() function call. * -* The flash and RAM sizes can be changed by editing the LENGTH value in the +* Change the flash and RAM sizes by editing the macros value in the * linker files for both CPUs: * - 'xx_cm0plus.ld', where 'xx' is the device group: -* * \code rom (rx) : ORIGIN = 0x10000000, LENGTH = 0x00080000 \endcode -* * \code ram_cm0p (rwx) : ORIGIN = 0x08000000, LENGTH = 0x00024000 \endcode +* \code +* flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x00080000 +* ram (rwx) : ORIGIN = 0x08000000, LENGTH = 0x00024000 +* \endcode * - 'xx_cm4_dual.ld', where 'xx' is the device group: -* * \code rom (rx) : ORIGIN = 0x10080000, LENGTH = 0x00080000 \endcode -* * \code ram_cm4 (rwx) : ORIGIN = 0x08024000, LENGTH = 0x00024000 \endcode +* \code +* flash (rx) : ORIGIN = 0x10080000, LENGTH = 0x00080000 +* ram (rwx) : ORIGIN = 0x08024000, LENGTH = 0x00023800 +* \endcode +* * Change the value of the \ref CY_CORTEX_M4_APPL_ADDR macro to the rom ORIGIN's * value in the 'xx_cm4_dual.ld' file, where 'xx' is the device group. Do this * by either: * - Passing the following commands to the compiler:\n -* * \code -D CY_CORTEX_M4_APPL_ADDR=0x10080000 \endcode +* \code -D CY_CORTEX_M4_APPL_ADDR=0x10080000 \endcode * - Editing the \ref CY_CORTEX_M4_APPL_ADDR value in the 'system_xx.h', where 'xx' is device family:\n -* * \code #define CY_CORTEX_M4_APPL_ADDR (0x10080000u) \endcode +* \code #define CY_CORTEX_M4_APPL_ADDR (0x10080000u) \endcode * * ARM MDK\n * The flash and RAM sections for the CPU are defined in the linker files: -* 'xx_yy.scat', where 'xx' is the device group, and 'yy' is the target CPU; for -* example, 'cy8c6x7_cm0plus.scat' and 'cy8c6x7_cm4_dual.scat'. -* Note: if the start of the Cortex-M4 application image is changed, the value -* of the of the \ref CY_CORTEX_M4_APPL_ADDR should also be changed. The -* \ref CY_CORTEX_M4_APPL_ADDR macro should be used as the parameter for the \ref -* Cy_SysEnableCM4() function call. -* -* The flash and RAM sizes can be changed by editing the macros value in the -* linker files for both CPUs: -* - 'xx_cm0plus.scat', where 'xx' is the device group: -* * \code #define FLASH_START 0x10000000 \endcode -* * \code #define FLASH_SIZE 0x00080000 \endcode -* - 'xx_cm4_dual.scat', where 'xx' is the device group: -* * \code #define FLASH_START 0x10080000 \endcode -* * \code #define FLASH_SIZE 0x00080000 \endcode -* Change the value of the \ref CY_CORTEX_M4_APPL_ADDR macro to the FLASH_START -* value in the 'xx_cm4_dual.scat' file, -* where 'xx' is the device group. Do this by either: -* - Passing the following commands to the compiler:\n -* * \code -D CY_CORTEX_M4_APPL_ADDR=0x10080000 \endcode -* - Editing the \ref CY_CORTEX_M4_APPL_ADDR value in the 'system_xx.h', where -* 'xx' is device family:\n -* * \code #define CY_CORTEX_M4_APPL_ADDR (0x10080000u) \endcode -* -* IAR\n -* The flash and RAM sections for the CPU are defined in the linker files: -* 'xx_yy.icf', where 'xx' is the device group, and 'yy' is the target CPU; for -* example, 'cy8c6x7_cm0plus.icf' and 'cy8c6x7_cm4_dual.icf'. -* Note: if the start of the Cortex-M4 application image is changed, the value +* 'xx_yy.scat', where 'xx' is the device group, and 'yy' is the target CPU; for example, +* 'cy8c6xx7_cm0plus.scat' and 'cy8c6xx7_cm4_dual.scat'. +* \note If the start of the Cortex-M4 application image is changed, the value * of the of the \ref CY_CORTEX_M4_APPL_ADDR should also be changed. The * \ref CY_CORTEX_M4_APPL_ADDR macro should be used as the parameter for the \ref * Cy_SysEnableCM4() function call. * -* The flash and RAM sizes can be changed by editing the macros value in the +* \note The linker files provided with the PDL are generic and handle all common +* use cases. Your project may not use every section defined in the linker files. +* In that case you may see the warnings during the build process: +* L6314W (no section matches pattern) and/or L6329W +* (pattern only matches removed unused sections). In your project, you can +* suppress the warning by passing the "--diag_suppress=L6314W,L6329W" option to +* the linker. You can also comment out or remove the relevant code in the linker +* file. +* +* Change the flash and RAM sizes by editing the macros value in the * linker files for both CPUs: -* - 'xx_cm0plus.icf', where 'xx' is the device group: -* * \code define symbol __ICFEDIT_region_IROM_start__ = 0x10000000; \endcode -* * \code define symbol __ICFEDIT_region_IROM_end__ = 0x10080000; \endcode -* * \code define symbol __ICFEDIT_region_IRAM_CM0P_start__ = 0x08000000; \endcode -* * \code define symbol __ICFEDIT_region_IRAM_CM0P_end__ = 0x08024000; \endcode -* - 'xx_cm4_dual.icf', where 'xx' is the device group: -* * \code define symbol __ICFEDIT_region_IROM_start__ = 0x10080000; \endcode -* * \code define symbol __ICFEDIT_region_IROM_end__ = 0x10100000; \endcode -* * \code define symbol __ICFEDIT_region_IRAM_CM4_start__ = 0x08024000; \endcode -* * \code define symbol __ICFEDIT_region_IRAM_CM4_end__ = 0x08048000; \endcode -* Change the value of the \ref CY_CORTEX_M4_APPL_ADDR macro to the -* __ICFEDIT_region_IROM_start__ value in the 'xx_cm4_dual.icf' file, where 'xx' -* is the device group. Do this by either: +* - 'xx_cm0plus.scat', where 'xx' is the device group: +* \code +* #define FLASH_START 0x10000000 +* #define FLASH_SIZE 0x00080000 +* #define RAM_START 0x08000000 +* #define RAM_SIZE 0x00024000 +* \endcode +* - 'xx_cm4_dual.scat', where 'xx' is the device group: +* \code +* #define FLASH_START 0x10080000 +* #define FLASH_SIZE 0x00080000 +* #define RAM_START 0x08024000 +* #define RAM_SIZE 0x00023800 +* \endcode +* +* Change the value of the \ref CY_CORTEX_M4_APPL_ADDR macro to the FLASH_START +* value in the 'xx_cm4_dual.scat' file, +* where 'xx' is the device group. Do this by either: * - Passing the following commands to the compiler:\n -* * \code -D CY_CORTEX_M4_APPL_ADDR=0x10080000 \endcode +* \code -D CY_CORTEX_M4_APPL_ADDR=0x10080000 \endcode * - Editing the \ref CY_CORTEX_M4_APPL_ADDR value in the 'system_xx.h', where * 'xx' is device family:\n -* * \code #define CY_CORTEX_M4_APPL_ADDR (0x10080000u) \endcode +* \code #define CY_CORTEX_M4_APPL_ADDR (0x10080000u) \endcode * -* \subsubsection group_system_config_device_memory_single_core_definition Single-Core Devices -* For single-core devices, 8 KB of flash and RAM are reserved for the pre-build -* Cortex-M0+ application that is loaded for the hidden Cortex-M0+. +* IAR\n +* The flash and RAM sections for the CPU are defined in the linker files: +* 'xx_yy.icf', where 'xx' is the device group, and 'yy' is the target CPU; for example, +* 'cy8c6xx7_cm0plus.icf' and 'cy8c6xx7_cm4_dual.icf'. +* \note If the start of the Cortex-M4 application image is changed, the value +* of the of the \ref CY_CORTEX_M4_APPL_ADDR should also be changed. The +* \ref CY_CORTEX_M4_APPL_ADDR macro should be used as the parameter for the \ref +* Cy_SysEnableCM4() function call. +* +* Change the flash and RAM sizes by editing the macros value in the +* linker files for both CPUs: +* - 'xx_cm0plus.icf', where 'xx' is the device group: +* \code +* define symbol __ICFEDIT_region_IROM1_start__ = 0x10000000; +* define symbol __ICFEDIT_region_IROM1_end__ = 0x10080000; +* define symbol __ICFEDIT_region_IRAM1_start__ = 0x08000000; +* define symbol __ICFEDIT_region_IRAM1_end__ = 0x08024000; +* \endcode +* - 'xx_cm4_dual.icf', where 'xx' is the device group: +* \code +* define symbol __ICFEDIT_region_IROM1_start__ = 0x10080000; +* define symbol __ICFEDIT_region_IROM1_end__ = 0x10100000; +* define symbol __ICFEDIT_region_IRAM1_start__ = 0x08024000; +* define symbol __ICFEDIT_region_IRAM1_end__ = 0x08047800; +* \endcode +* +* Change the value of the \ref CY_CORTEX_M4_APPL_ADDR macro to the +* __ICFEDIT_region_IROM1_start__ value in the 'xx_cm4_dual.icf' file, where 'xx' +* is the device group. Do this by either: +* - Passing the following commands to the compiler:\n +* \code -D CY_CORTEX_M4_APPL_ADDR=0x10080000 \endcode +* - Editing the \ref CY_CORTEX_M4_APPL_ADDR value in the 'system_xx.h', where +* 'xx' is device family:\n +* \code #define CY_CORTEX_M4_APPL_ADDR (0x10080000u) \endcode * * \subsection group_system_config_device_initialization Device Initialization * After a power-on-reset (POR), the boot process is handled by the boot code @@ -136,27 +161,18 @@ * code passes the control to the Cortex-M0+ startup code located in flash. * * \subsubsection group_system_config_dual_core_device_initialization Dual-Core Devices -* The Cortex-M0+ startup code performs the device initialization by a call to +* The Cortex-M0+ startup code performs the device initialization by a call to * SystemInit() and then calls the main() function. The Cortex-M4 core is disabled * by default. Enable the core using the \ref Cy_SysEnableCM4() function. * See \ref group_system_config_cm4_functions for more details. +* \note Startup code executes SystemInit() function for the both Cortex-M0+ and Cortex-M4 cores. +* The function has a separate implementation on each core. +* Both function implementations unlock and disable the WDT. +* Therefore enable the WDT after both cores have been initialized. * * \subsubsection group_system_config_single_core_device_initialization Single-Core Devices * The Cortex-M0+ core is not user-accessible on these devices. In this case the -* Cortex-M0+ pre-built application image handles setup of the CM0+ core and -* starts the Cortex-M4 core. -* -* CM0+ NVIC IRQn channels 26-31 are reserved for system use. Other IRQn channels -* are available to the user application. The pre-built application configures: -* * IRQn 26-27 for the IPC driver -* * IRQn 28-30 for the Crypto driver -* * IRQn 31 for system communication -* -* The Cortex-M0+ application image performs the following tasks: -* * Enables global interrupts on the Cortex-M0+ core. -* * Starts the crypto server. See [Cryptography (Crypto)](\ref group_crypto) for details. -* * Enables the Cortex-M4 core by calling \ref Cy_SysEnableCM4(). -* * Requests Deep Sleep mode entry with wakeup on interrupt in the infinite loop. +* Flash Boot handles setup of the CM0+ core and starts the Cortex-M4 core. * * \subsection group_system_config_heap_stack_config Heap and Stack Configuration * There are two ways to adjust heap and stack configurations: @@ -171,13 +187,13 @@ * 'startup_xx_yy.S', where 'xx' is the device family, and 'yy' is the target CPU; * for example, startup_psoc63_cm0plus.s and startup_psoc63_cm4.s. * Change the heap and stack sizes by modifying the following lines:\n -* * \code .equ Stack_Size, 0x00001000 \endcode -* * \code .equ Heap_Size, 0x00000400 \endcode +* \code .equ Stack_Size, 0x00001000 \endcode +* \code .equ Heap_Size, 0x00000400 \endcode * * - Specifying via command line\n * Change the heap and stack sizes passing the following commands to the compiler:\n -* * \code -D __STACK_SIZE=0x000000400 \endcode -* * \code -D __HEAP_SIZE=0x000000100 \endcode +* \code -D __STACK_SIZE=0x000000400 \endcode +* \code -D __HEAP_SIZE=0x000000100 \endcode * * \subsubsection group_system_config_heap_stack_config_mdk ARM MDK * - Editing source code files\n @@ -185,40 +201,40 @@ * 'startup_xx_yy.s', where 'xx' is the device family, and 'yy' is the target * CPU; for example, startup_psoc63_cm0plus.s and startup_psoc63_cm4.s. * Change the heap and stack sizes by modifying the following lines:\n -* * \code Stack_Size EQU 0x00001000 \endcode -* * \code Heap_Size EQU 0x00000400 \endcode +* \code Stack_Size EQU 0x00001000 \endcode +* \code Heap_Size EQU 0x00000400 \endcode * * - Specifying via command line\n * Change the heap and stack sizes passing the following commands to the assembler:\n -* * \code "--predefine=___STACK_SIZE SETA 0x000000400" \endcode -* * \code "--predefine=__HEAP_SIZE SETA 0x000000100" \endcode +* \code "--predefine=___STACK_SIZE SETA 0x000000400" \endcode +* \code "--predefine=__HEAP_SIZE SETA 0x000000100" \endcode * * \subsubsection group_system_config_heap_stack_config_iar IAR * - Editing source code files\n * The heap and stack sizes are defined in the linker scatter files: 'xx_yy.icf', * where 'xx' is the device family, and 'yy' is the target CPU; for example, -* cy8c6x7_cm0plus.icf and cy8c6x7_cm4_dual.icf. +* cy8c6xx7_cm0plus.icf and cy8c6xx7_cm4_dual.icf. * Change the heap and stack sizes by modifying the following lines:\n -* * \code Stack_Size EQU 0x00001000 \endcode -* * \code Heap_Size EQU 0x00000400 \endcode +* \code Stack_Size EQU 0x00001000 \endcode +* \code Heap_Size EQU 0x00000400 \endcode * * - Specifying via command line\n * Change the heap and stack sizes passing the following commands to the * linker (including quotation marks):\n -* * \code --define_symbol __STACK_SIZE=0x000000400 \endcode -* * \code --define_symbol __HEAP_SIZE=0x000000100 \endcode +* \code --define_symbol __STACK_SIZE=0x000000400 \endcode +* \code --define_symbol __HEAP_SIZE=0x000000100 \endcode * -* - \subsection group_system_config_merge_apps Merging CM0+ and CM4 Executables +* \subsection group_system_config_merge_apps Merging CM0+ and CM4 Executables * The CM0+ project and linker script build the CM0+ application image. Similarly, * the CM4 linker script builds the CM4 application image. Each specifies * locations, sizes, and contents of sections in memory. See * \ref group_system_config_device_memory_definition for the symbols and default * values. * -* The cypdlelftool is invoked by a post-build command. The precise project +* The cymcuelftool is invoked by a post-build command. The precise project * setting is IDE-specific. * -* The cypdlelftool combines the two executables. The tool examines the +* The cymcuelftool combines the two executables. The tool examines the * executables to ensure that memory regions either do not overlap, or contain * identical bytes (shared). If there are no problems, it creates a new ELF file * with the merged image, without changing any of the addresses or data. @@ -228,7 +244,7 @@ * code actually defines the contents of the vector table and performs the copy. * \subsubsection group_system_config_device_vector_table_gcc ARM GCC * The linker script file is 'xx_yy.ld', where 'xx' is the device family, and -* 'yy' is the target CPU; for example, cy8c6x7_cm0plus.ld and cy8c6x7_cm4_dual.ld. +* 'yy' is the target CPU; for example, cy8c6xx7_cm0plus.ld and cy8c6xx7_cm4_dual.ld. * It defines sections and locations in memory.\n * Copy interrupt vectors from flash to RAM: \n * From: \code LONG (__Vectors) \endcode @@ -241,8 +257,8 @@ * Flash to RAM. * \subsubsection group_system_config_device_vector_table_mdk ARM MDK * The linker script file is 'xx_yy.scat', where 'xx' is the device family, -* and 'yy' is the target CPU; for example, cy8c6x7_cm0plus.scat and -* cy8c6x7_cm4_dual.scat. The linker script specifies that the vector table +* and 'yy' is the target CPU; for example, cy8c6xx7_cm0plus.scat and +* cy8c6xx7_cm4_dual.scat. The linker script specifies that the vector table * (RESET_RAM) shall be first in the RAM section.\n * RESET_RAM represents the vector table. It is defined in the assembler startup * files: 'startup_xx_yy.s', where 'xx' is the device family, and 'yy' is the @@ -251,7 +267,7 @@ * * \subsubsection group_system_config_device_vector_table_iar IAR * The linker script file is 'xx_yy.icf', where 'xx' is the device family, and -* 'yy' is the target CPU; for example, cy8c6x7_cm0plus.icf and cy8c6x7_cm4_dual.icf. +* 'yy' is the target CPU; for example, cy8c6xx7_cm0plus.icf and cy8c6xx7_cm4_dual.icf. * This file defines the .intvec_ram section and its location. * \code place at start of IRAM1_region { readwrite section .intvec_ram}; \endcode * The vector table address (and the vector table itself) are defined in the @@ -265,18 +281,22 @@ * more details. * * \section group_system_config_MISRA MISRA Compliance -* The drivers violates the following MISRA-C:2004 rules: * * * -* -* -* -* +* +* +* +* +* +* +* +* +* +* * *
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
2.3RThe character sequence // shall not be used within a comment.The comments provide a useful WEB link to the documentation.
* -* * \section group_system_config_changelog Changelog * * @@ -285,6 +305,39 @@ * * * +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* * * * @@ -308,6 +361,17 @@ * \} */ +/** +* \addtogroup group_system_config_system_functions +* \{ +* \details +* The following system functions implement CMSIS Core functions. +* Refer to the [CMSIS documentation] +* (http://www.keil.com/pack/doc/CMSIS/Core/html/group__system__init__gr.html "System and Clock Configuration") +* for more details. +* \} +*/ + #ifdef __cplusplus extern "C" { #endif @@ -414,12 +478,12 @@ extern "C" { #if (CY_SYSTEM_CPU_CM0P == 1UL) || defined(CY_DOXYGEN) /** The Cortex-M0+ startup driver identifier */ #define CY_STARTUP_M0P_ID ((uint32_t)((uint32_t)((0x0Eu) & 0x3FFFu) << 18u)) -#endif +#endif /* (CY_SYSTEM_CPU_CM0P == 1UL) */ #if (CY_SYSTEM_CPU_CM0P != 1UL) || defined(CY_DOXYGEN) /** The Cortex-M4 startup driver identifier */ #define CY_STARTUP_M4_ID ((uint32_t)((uint32_t)((0x0Fu) & 0x3FFFu) << 18u)) -#endif +#endif /* (CY_SYSTEM_CPU_CM0P != 1UL) */ /** \} group_system_config_system_macro */ @@ -471,7 +535,7 @@ extern uint32_t cy_delay32kMs; #define CY_SYS_CM4_STATUS_RESET (1u) /**< The Cortex-M4 core is in the Reset mode: clock off, no isolated, no retain and reset. */ /** \} group_system_config_cm4_status_macro */ -#endif +#endif /* (CY_SYSTEM_CPU_CM0P == 1UL) */ /** \addtogroup group_system_config_globals * \{ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/ipc_rpc.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/ipc_rpc.h new file mode 100644 index 0000000000..45df7734a0 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/ipc_rpc.h @@ -0,0 +1,64 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef IPC_RPC_H +#define IPC_RPC_H + +#include + +#if defined(__MBED__) +#define IPCPIPE_ASSERT MBED_ASSERT +#include "mbed_assert.h" +#else +#include "project.h" +#define IPCPIPE_ASSERT CY_ASSERT +#endif + +#define IPCRPC_MAX_ARGUMENTS 8 + +/* IPC Pipe message data structure */ +typedef struct +{ + uint32_t client_id; + uint32_t result; + uint32_t args_num; + uint32_t args[IPCRPC_MAX_ARGUMENTS]; +} IpcRpcMessage; + + +typedef struct +{ + volatile uint8_t busy_flag; + IpcRpcMessage message; +} IpcRpcBuffer; + + + + +#if defined(__cplusplus) +extern "C" { +#endif + +void ipcrpc_init(void); +uint32_t ipcrpc_call(uint32_t call_id, uint32_t args_num, ...); + +#if defined(__cplusplus) +} +#endif + +#endif /* IPC_RPC_H */ +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/psoc6_static_srm.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/psoc6_static_srm.h new file mode 100644 index 0000000000..9a1f9870c0 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C63XX/psoc6_static_srm.h @@ -0,0 +1,74 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + + */ + +/* + * This file defines hardware resources statically allocated to M0 core + * when static resource managemnt is used. + * + * There are 4 classes of resources that must be declared here: + * - M0_ASSIGNED_PORTS macro defines which ports and pins are reserved + * for M0 core use. + * You define these as a colon separated list of ports and pins reserved + * using macro SRM_PORT(port_num, pins), one time for each reserved port. + * SRM_PORT macro arguments are port number, in the range 0 .. 14 and + * pins is a hex value with a bit set for each reserved pin on a port. + * + * - M0_ASSIGNED_DIVIDERS macro defines which clock dividers are reserved + * for M0 core use. + * You define these as a colon separated list of dividers reserved + * using macro SRM_DIVIDER(type, reservations), one time for each required + * devider type. + * SRM_DIVIDER arguments are divider type, one of cy_en_divider_types_t + * values and reservations is a hex mask value with a bit set for each + * reserved divider of a given type. + * + * - M0_ASSIGNED_SCBS macro defines which SCB blocks are reserved + * for M0 core use. + * You define these as a colon separated list of SCBs reserved using + * macro SRM_SCB(n), which argument is SCB number in a range 0 .. 7. + * + * - M0_ASSIGNED_TCPWM macro defines which TCPWM blocks are reserved + * for M0 core use. + * You define these as a colon separated list of TCPWMs reserved using + * macro SRM_TCPWM(n), which argument is TCPWM number in a range 0 .. 31. + * + * If a particular resource class is not used at all by M0 core you can + * skip defining relevant M0_ASSIGNED_* macro or define it as an empty one. + * + * Examples: + * #define M0_ASSIGNED_PORTS SRM_PORT(0, 0x30), SRM_PORT(5, 0x03) + * + * #define M0_ASSIGNED_DIVIDERS SRM_DIVIDER(CY_SYSCLK_DIV_8_BIT, 0x01) + * + * #define M0_ASSIGNED_SCBS SRM_SCB(2) + * + * #define M0_ASSIGNED_TCPWMS + * + */ + +// Reservations below apply to default M0 hex image. + +// P0_0 and p0_1 reserved for WCO, P6-6 and P6_7 reserved for SWD +#define M0_ASSIGNED_PORTS SRM_PORT(0, 0x03), SRM_PORT(6, 0xc0), SRM_PORT(11, 0x02) +// 8-bit divider 0 reserved for us ticker. +#define M0_ASSIGNED_DIVIDERS SRM_DIVIDER(CY_SYSCLK_DIV_8_BIT, 0x01), \ + SRM_DIVIDER(CY_SYSCLK_DIV_16_BIT, 0x01) +#define M0_ASSIGNED_SCBS +#define M0_ASSIGNED_TCPWMS + +/* End of File */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/PinNames.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/PinNames.h similarity index 60% rename from targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/PinNames.h rename to targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/PinNames.h index 23ab89eee5..10a8f6dd41 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/PinNames.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/PinNames.h @@ -1,31 +1,18 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * 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 * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of ARM Limited nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBED_PINNAMES_H @@ -35,12 +22,20 @@ #include "PinNamesTypes.h" #include "PortNames.h" -#ifdef __cplusplus -extern "C" { -#endif +#if PSOC6_ENABLE_M0_M4_DEBUG -#define CY_UART_RX P5_0 -#define CY_UART_TX P5_1 +#define CY_STDIO_UART_RX P9_0 +#define CY_STDIO_UART_TX P9_1 +#define CY_STDIO_UART_CTS P9_2 +#define CY_STDIO_UART_RTS P9_3 +#else + +#define CY_STDIO_UART_RX P5_0 +#define CY_STDIO_UART_TX P5_1 +#define CY_STDIO_UART_CTS P5_2 +#define CY_STDIO_UART_RTS P5_3 + +#endif // PSOC6_ENABLE_M0_M4_DEBUG // PinName[15-0] = Port[15-8] + Pin[7-0] typedef enum { @@ -179,73 +174,80 @@ typedef enum { P14_6 = (Port14 << 8) + 0x06, P14_7 = (Port14 << 8) + 0x07, - P15_0 = (Port15 << 8) + 0x00, - P15_1 = (Port15 << 8) + 0x01, - P15_2 = (Port15 << 8) + 0x02, - P15_3 = (Port15 << 8) + 0x03, - P15_4 = (Port15 << 8) + 0x04, - P15_5 = (Port15 << 8) + 0x05, - P15_6 = (Port15 << 8) + 0x06, - P15_7 = (Port15 << 8) + 0x07, - // Arduino connector namings - A0 = P10_0, - A1 = P10_1, + A0 = P10_4, + A1 = P10_5, A2 = P10_2, A3 = P10_3, - A4 = P10_4, - A5 = P10_5, + A4 = P10_1, + A5 = P10_0, - D0 = P5_0, - D1 = P5_1, - D2 = P5_2, - D3 = P5_3, - D4 = P5_4, - D5 = P5_5, - D6 = P5_6, - D7 = P0_2, - D8 = P13_0, - D9 = P13_1, - D10 = P12_3, - D11 = P12_0, - D12 = P12_1, - D13 = P12_2, + D0 = P6_4, + D1 = P6_5, + D2 = P10_6, + D3 = P12_6, + D4 = P12_7, + D5 = P6_2, + D6 = P6_3, + D7 = P7_2, + D8 = P7_1, + D9 = P7_7, + D10 = P9_4, + D11 = P9_0, + D12 = P9_1, + D13 = P9_2, + D14 = P10_1, + D15 = P10_0, - // Generic signals namings + // Generic signal names - LED_RED = P0_3, - LED_GREEN = P1_1, - LED_BLUE = P11_1, + I2C_SCL = P10_0, + I2C_SDA = P10_1, + SPI_MOSI = P9_0, + SPI_MISO = P9_1, + SPI_CLK = P9_2, + SPI_CS = P9_3, + UART_RX = P6_4, + UART_TX = P6_5, SWITCH2 = P0_4, - - LED1 = LED_RED, - LED2 = LED_GREEN, - LED3 = LED_BLUE, - LED4 = LED_RED, + LED1 = P6_2, + LED2 = P6_3, + LED3 = P7_2, + LED4 = P6_2, + LED_RED = LED1, USER_BUTTON = SWITCH2, BUTTON1 = USER_BUTTON, // Standardized interfaces names - SERIAL_TX = CY_UART_TX, - SERIAL_RX = CY_UART_RX, - USBTX = CY_UART_TX, - USBRX = CY_UART_RX, - // I2C_SCL = PB_8, - // I2C_SDA = PB_9, - // SPI_MOSI = PA_7, - // SPI_MISO = PA_6, - // SPI_SCK = PA_5, - // SPI_CS = PB_6, - // PWM_OUT = PB_3, + STDIO_UART_TX = CY_STDIO_UART_TX, + STDIO_UART_RX = CY_STDIO_UART_RX, + STDIO_UART_CTS = CY_STDIO_UART_CTS, + STDIO_UART_RTS = CY_STDIO_UART_RTS, + USBTX = CY_STDIO_UART_TX, + USBRX = CY_STDIO_UART_RX, // Not connected NC = (int)0xFFFFFFFF } PinName; -#ifdef __cplusplus +// PinName[15-0] = Port[15-8] + Pin[4-0] +static inline unsigned CY_PIN(PinName pin) +{ + return pin & 0x07; } -#endif + +static inline unsigned CY_PORT(PinName pin) +{ + return (pin >> 8) & 0xFF; +} + +// Because MBED pin mapping API does not allow to map multiple instances of the PWM +// to be mapped to the same pin, we create special pin names to force 32-bit PWM unit +// usage instead of standard 16-bit PWM. + +#define PWM32(pin) CY_PIN_FORCE_PWM_32(pin) + #endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/TARGET_FUTURE_SEQUANA_M0/board_config.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/TARGET_FUTURE_SEQUANA_M0/board_config.c new file mode 100644 index 0000000000..bd91adc937 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/TARGET_FUTURE_SEQUANA_M0/board_config.c @@ -0,0 +1,335 @@ + +/******************************************************************************* +* File Name: cyfitter_cfg.c +* +* PSoC Creator 4.2 +* +* Description: +* This file contains device initialization code. +* Except for the user defined sections in CyClockStartupError(), this file should not be modified. +* This file is automatically generated by PSoC Creator. +* +******************************************************************************** +* Copyright (c) 2007-2017 Cypress Semiconductor. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +********************************************************************************/ +/* + * Copyright (c) 20017-2018 Future Electronics + */ + +#include +#include "device.h" +#include "gpio/cy_gpio.h" +#include "syslib/cy_syslib.h" +#include "sysclk/cy_sysclk.h" +#include "systick/cy_systick.h" +#include "sysanalog/cy_sysanalog.h" + +#if FEATURE_BLE +#include "ble/cy_ble_clk.h" +#endif // FEATURE_BLE + +#define CY_NEED_CYCLOCKSTARTUPERROR 1 +#include "syspm/cy_syspm.h" + +#include "psoc6_utils.h" + +#if defined(__GNUC__) || defined(__ARMCC_VERSION) +#define CYPACKED +#define CYPACKED_ATTR __attribute__ ((packed)) +#define CYALIGNED __attribute__ ((aligned)) +#define CY_CFG_UNUSED __attribute__ ((unused)) +#ifndef CY_CFG_SECTION +#define CY_CFG_SECTION __attribute__ ((section(".psocinit"))) +#endif + +#if defined(__ARMCC_VERSION) +#define CY_CFG_MEMORY_BARRIER() __memory_changed() +#else +#define CY_CFG_MEMORY_BARRIER() __sync_synchronize() +#endif + +#elif defined(__ICCARM__) +#include + +#define CYPACKED __packed +#define CYPACKED_ATTR +#define CYALIGNED _Pragma("data_alignment=4") +#define CY_CFG_UNUSED _Pragma("diag_suppress=Pe177") +#define CY_CFG_SECTION _Pragma("location=\".psocinit\"") + +#define CY_CFG_MEMORY_BARRIER() __DMB() + +#else +#error Unsupported toolchain +#endif + +#ifndef CYCODE +#define CYCODE +#endif +#ifndef CYDATA +#define CYDATA +#endif +#ifndef CYFAR +#define CYFAR +#endif +#ifndef CYXDATA +#define CYXDATA +#endif + + +CY_CFG_UNUSED +static void CYMEMZERO(void *s, size_t n); +CY_CFG_UNUSED +static void CYMEMZERO(void *s, size_t n) +{ + (void)memset(s, 0, n); +} +CY_CFG_UNUSED +static void CYCONFIGCPY(void *dest, const void *src, size_t n); +CY_CFG_UNUSED +static void CYCONFIGCPY(void *dest, const void *src, size_t n) +{ + (void)memcpy(dest, src, n); +} +CY_CFG_UNUSED +static void CYCONFIGCPYCODE(void *dest, const void *src, size_t n); +CY_CFG_UNUSED +static void CYCONFIGCPYCODE(void *dest, const void *src, size_t n) +{ + (void)memcpy(dest, src, n); +} + + + + +/* Clock startup error codes */ +#define CYCLOCKSTART_NO_ERROR 0u +#define CYCLOCKSTART_XTAL_ERROR 1u +#define CYCLOCKSTART_32KHZ_ERROR 2u +#define CYCLOCKSTART_PLL_ERROR 3u +#define CYCLOCKSTART_FLL_ERROR 4u +#define CYCLOCKSTART_WCO_ERROR 5u + +#ifdef CY_NEED_CYCLOCKSTARTUPERROR +/******************************************************************************* +* Function Name: CyClockStartupError +******************************************************************************** +* Summary: +* If an error is encountered during clock configuration (crystal startup error, +* PLL lock error, etc.), the system will end up here. Unless reimplemented by +* the customer, this function will stop in an infinite loop. +* +* Parameters: +* void +* +* Return: +* void +* +*******************************************************************************/ +CY_CFG_UNUSED +static void CyClockStartupError(uint8 errorCode); +CY_CFG_UNUSED +static void CyClockStartupError(uint8 errorCode) +{ + /* To remove the compiler warning if errorCode not used. */ + errorCode = errorCode; + + /* If we have a clock startup error (bad MHz crystal, PLL lock, etc.), */ + /* we will end up here to allow the customer to implement something to */ + /* deal with the clock condition. */ + +#ifdef CY_CFG_CLOCK_STARTUP_ERROR_CALLBACK + CY_CFG_Clock_Startup_ErrorCallback(); +#else + while(1) {} +#endif /* CY_CFG_CLOCK_STARTUP_ERROR_CALLBACK */ +} +#endif + +static void ClockInit(void) +{ + uint32_t status; + + /* Enable all source clocks */ + status = Cy_SysClk_WcoEnable(500000u); + if (CY_RET_SUCCESS != status) + { + CyClockStartupError(CYCLOCKSTART_WCO_ERROR); + } + Cy_SysClk_ClkLfSetSource(CY_SYSCLK_CLKLF_IN_WCO); + +#if FEATURE_BLE + { + cy_stc_ble_bless_eco_cfg_params_t bleCfg = { + .ecoXtalStartUpTime = (785 / 31.25), + .loadCap = ((9.9 - 7.5) / 0.075), + .ecoFreq = CY_BLE_BLESS_ECO_FREQ_32MHZ, + .ecoSysDiv = CY_BLE_SYS_ECO_CLK_DIV_4 + }; + Cy_BLE_EcoStart(&bleCfg); + } +#endif // FEATURE_BLE + + /* Configure CPU clock dividers */ + Cy_SysClk_ClkFastSetDivider(0u); + Cy_SysClk_ClkPeriSetDivider((CY_CLK_HFCLK0_FREQ_HZ / CY_CLK_PERICLK_FREQ_HZ) - 1); + Cy_SysClk_ClkSlowSetDivider((CY_CLK_PERICLK_FREQ_HZ / CY_CLK_SYSTEM_FREQ_HZ) - 1); + + /* Configure LF & HF clocks */ + Cy_SysClk_ClkHfSetSource(0u, CY_SYSCLK_CLKHF_IN_CLKPATH1); + Cy_SysClk_ClkHfSetDivider(0u, CY_SYSCLK_CLKHF_NO_DIVIDE); + Cy_SysClk_ClkHfEnable(0u); + + /* Configure Path Clocks */ + /* PLL path is used to clock HF domain from BLE ECO */ + Cy_SysClk_ClkPathSetSource(2, CY_SYSCLK_CLKPATH_IN_IMO); + Cy_SysClk_ClkPathSetSource(3, CY_SYSCLK_CLKPATH_IN_IMO); + Cy_SysClk_ClkPathSetSource(4, CY_SYSCLK_CLKPATH_IN_IMO); +#if FEATURE_BLE + Cy_SysClk_ClkPathSetSource(0, CY_SYSCLK_CLKPATH_IN_ALTHF); + Cy_SysClk_ClkPathSetSource(1, CY_SYSCLK_CLKPATH_IN_ALTHF); + { + const cy_stc_pll_config_t pllConfig = { + .inputFreq = CY_CLK_ALTHF_FREQ_HZ, + .outputFreq = CY_CLK_HFCLK0_FREQ_HZ, + .lfMode = false, + .outputMode = CY_SYSCLK_FLLPLL_OUTPUT_AUTO + }; +#else + Cy_SysClk_ClkPathSetSource(0, CY_SYSCLK_CLKPATH_IN_IMO); + Cy_SysClk_ClkPathSetSource(1, CY_SYSCLK_CLKPATH_IN_IMO); + { + const cy_stc_pll_config_t pllConfig = { + .inputFreq = CY_CLK_IMO_FREQ_HZ, + .outputFreq = CY_CLK_HFCLK0_FREQ_HZ, + .lfMode = false, + .outputMode = CY_SYSCLK_FLLPLL_OUTPUT_AUTO + }; +#endif // FEATURE_BLE + status = Cy_SysClk_PllConfigure(1u, &pllConfig); + if (CY_SYSCLK_SUCCESS != status) { + CyClockStartupError(CYCLOCKSTART_PLL_ERROR); + } + } + status = Cy_SysClk_PllEnable(1u, 10000u); + if (CY_SYSCLK_SUCCESS != status) { + CyClockStartupError(CYCLOCKSTART_PLL_ERROR); + } + + /* Configure miscellaneous clocks */ + Cy_SysClk_ClkTimerSetSource(CY_SYSCLK_CLKTIMER_IN_HF0_NODIV); + Cy_SysClk_ClkTimerSetDivider(0); + Cy_SysClk_ClkTimerEnable(); + Cy_SysClk_ClkPumpSetSource(CY_SYSCLK_PUMP_IN_CLKPATH0); + Cy_SysClk_ClkPumpSetDivider(CY_SYSCLK_PUMP_DIV_4); + Cy_SysClk_ClkPumpEnable(); + Cy_SysClk_ClkBakSetSource(CY_SYSCLK_BAK_IN_WCO); + + /* Disable unused clocks started by default */ + Cy_SysClk_IloDisable(); + + /* Set memory wait states based on HFClk[0] */ + Cy_SysLib_SetWaitStates(false, (CY_CLK_HFCLK0_FREQ_HZ + 990000) / 1000000UL); +} + + +/* Analog API Functions */ + + +/******************************************************************************* +* Function Name: AnalogSetDefault +******************************************************************************** +* +* Summary: +* Sets up the analog portions of the chip to default values based on chip +* configuration options from the project. +* +* Parameters: +* void +* +* Return: +* void +* +*******************************************************************************/ +static void AnalogSetDefault(void) +{ + const cy_stc_sysanalog_config_t config = { + .startup = CY_SYSANALOG_STARTUP_NORMAL, + .iztat = CY_SYSANALOG_IZTAT_SOURCE_LOCAL, + .vref = CY_SYSANALOG_VREF_SOURCE_LOCAL_1_2V, + .deepSleep = CY_SYSANALOG_DEEPSLEEP_IPTAT_1 + }; + Cy_SysAnalog_Init(&config); + Cy_SysAnalog_Enable(); +} + + + + +/******************************************************************************* +* Function Name: Cy_SystemInit +******************************************************************************** +* Summary: +* This function is called by the start-up code for the selected device. It +* performs all of the necessary device configuration based on the design +* settings. This includes settings from the Design Wide Resources (DWR) such +* as Clocks and Pins as well as any component configuration that is necessary. +* +* Parameters: +* void +* +* Return: +* void +* +*******************************************************************************/ + +void Cy_SystemInit(void) +{ + /* Set worst case memory wait states (150 MHz), ClockInit() will update */ + Cy_SysLib_SetWaitStates(false, 150); + + if(0u == Cy_SysLib_GetResetReason()) { /* POR, XRES, or BOD */ + Cy_SysLib_ResetBackupDomain(); + } + + /* Power Mode */ + Cy_SysPm_LdoSetVoltage(CY_SYSPM_LDO_VOLTAGE_1_1V); + + /* PMIC Control */ + Cy_SysPm_UnlockPmic(); + Cy_SysPm_DisablePmicOutput(); + + /* Pin0_0 and Pin0_1 drive WCO, configure as analog before configuring clock */ + cy_reserve_io_pin(P0_0); + cy_reserve_io_pin(P0_1); + Cy_GPIO_Pin_FastInit(GPIO_PRT0, 0, CY_GPIO_DM_ANALOG, 0, P0_0_GPIO); + Cy_GPIO_Pin_FastInit(GPIO_PRT0, 1, CY_GPIO_DM_ANALOG, 0, P0_1_GPIO); + + /* Clock */ + ClockInit(); + + /******* Pre-defined port configuration section ********/ + { + /* RGB LED is P_0_3 (R), P_1_1 (G) and P_11_1 (B) */ + const uint32_t led_off = 1; + Cy_GPIO_Pin_FastInit(GPIO_PRT0, 3, CY_GPIO_DM_STRONG_IN_OFF, led_off, P0_3_GPIO); + Cy_GPIO_Pin_FastInit(GPIO_PRT1, 1, CY_GPIO_DM_STRONG_IN_OFF, led_off, P1_1_GPIO); + Cy_GPIO_Pin_FastInit(GPIO_PRT11, 1, CY_GPIO_DM_STRONG_IN_OFF, led_off, P11_1_GPIO); + + /* USER BUTTON is P_0_4 */ + Cy_GPIO_Pin_FastInit(GPIO_PRT0, 4, CY_GPIO_DM_PULLUP, 1, P0_4_GPIO); + + /* Configure hw debug interface on port 6 */ + cy_reserve_io_pin(P6_6); + cy_reserve_io_pin(P6_7); + Cy_GPIO_Pin_FastInit(GPIO_PRT6, 6, CY_GPIO_DM_PULLUP, 0, P6_6_CPUSS_SWJ_SWDIO_TMS); + Cy_GPIO_Pin_FastInit(GPIO_PRT6, 7, CY_GPIO_DM_PULLDOWN, 0, P6_7_CPUSS_SWJ_SWCLK_TCLK); + } + + /* Perform basic analog initialization to defaults */ + AnalogSetDefault(); + +} diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/stdio_init.cpp b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/stdio_init.cpp new file mode 100644 index 0000000000..84b491e318 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_FUTURE_SEQUANA/stdio_init.cpp @@ -0,0 +1,31 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "mbed.h" + + /* + * This makes sure, stdio serial is initialized on M4 core at the very beging + * and outside of any critical context, so printf is usable anyware, including + * interrupt and fault handlers. + * Hardware devices cannot be initialized in the interrupt or critical section context + * on PSoC 6 M4 core. + */ + +#ifndef TARGET_MCU_PSOC6_M0 +Serial _stdio_uart_object(STDIO_UART_TX, STDIO_UART_RX); +#endif + \ No newline at end of file diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/analogin_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/analogin_api.c new file mode 100644 index 0000000000..54ee6c309f --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/analogin_api.c @@ -0,0 +1,190 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "device.h" +#include "analogin_api.h" +#include "cy_sar.h" +#include "psoc6_utils.h" +#include "mbed_assert.h" +#include "mbed_error.h" +#include "pinmap.h" +#include "PeripheralPins.h" +#include "platform/mbed_error.h" + +#if DEVICE_ANALOGIN + +const uint16_t ADC_MAX_VALUE = 0x0fff; + +const uint32_t SAR_BASE_CLOCK_HZ = 18000000; // 18 MHz or less + +/** Default SAR channel configuration. + * Notice, that because dynamic SAR MUX switching is disabled, + * per-channel MUX configuration is ignored, thus not configured here. + */ +#define DEFAULT_CHANNEL_CONFIG ( \ + CY_SAR_CHAN_SINGLE_ENDED | \ + CY_SAR_CHAN_AVG_ENABLE | \ + CY_SAR_CHAN_SAMPLE_TIME_0 \ +) + + +/** Global SAR configuration data, modified as channels are configured. + */ +static cy_stc_sar_config_t sar_config = { + .ctrl = CY_SAR_VREF_SEL_VDDA_DIV_2 | + CY_SAR_NEG_SEL_VREF | + CY_SAR_CTRL_COMP_DLY_12 | + CY_SAR_COMP_PWR_50 | + CY_SAR_SARSEQ_SWITCH_DISABLE, /**< Control register */ + .sampleCtrl = CY_SAR_RIGHT_ALIGN | + CY_SAR_SINGLE_ENDED_UNSIGNED | + CY_SAR_AVG_CNT_16 | + CY_SAR_AVG_MODE_SEQUENTIAL_FIXED | + CY_SAR_TRIGGER_MODE_FW_ONLY, /**< Sample control register */ + .sampleTime01 = (4uL << CY_SAR_SAMPLE_TIME0_SHIFT) | + (4uL << CY_SAR_SAMPLE_TIME1_SHIFT), /**< Sample time in ADC clocks for ST0 and ST1 */ + .sampleTime23 = (4uL << CY_SAR_SAMPLE_TIME2_SHIFT) | + (4uL << CY_SAR_SAMPLE_TIME3_SHIFT), /**< Sample time in ADC clocks for ST2 and ST3 */ + .rangeThres = 0, /**< Range detect threshold register for all channels (unused)*/ + .rangeCond = 0, /**< Range detect mode for all channels (unused)*/ + .chanEn = 0, /**< Enable bits for the channels */ + .chanConfig = { /**< Channel configuration registers */ + DEFAULT_CHANNEL_CONFIG, // chn 0 + DEFAULT_CHANNEL_CONFIG, // chn 1 + DEFAULT_CHANNEL_CONFIG, // chn 2 + DEFAULT_CHANNEL_CONFIG, // chn 3 + DEFAULT_CHANNEL_CONFIG, // chn 4 + DEFAULT_CHANNEL_CONFIG, // chn 5 + DEFAULT_CHANNEL_CONFIG, // chn 6 + DEFAULT_CHANNEL_CONFIG, // chn 7 + DEFAULT_CHANNEL_CONFIG, // chn 8 + DEFAULT_CHANNEL_CONFIG, // chn 9 + DEFAULT_CHANNEL_CONFIG, // chn 10 + DEFAULT_CHANNEL_CONFIG, // chn 11 + DEFAULT_CHANNEL_CONFIG, // chn 12 + DEFAULT_CHANNEL_CONFIG, // chn 13 + DEFAULT_CHANNEL_CONFIG, // chn 14 + DEFAULT_CHANNEL_CONFIG, // chn 15 + }, + .intrMask = 0, /**< Interrupt enable mask */ + .satIntrMask = 0, /**< Saturate interrupt mask register */ + .rangeIntrMask = 0, /**< Range interrupt mask register */ + .muxSwitch = 0, /**< SARMUX firmware switches to connect analog signals to SAR */ + .muxSwitchSqCtrl = 0, /**< SARMUX Switch SAR sequencer control */ + .configRouting = false, /**< Configure or ignore routing related registers (muxSwitch, muxSwitchSqCtrl) */ + .vrefMvValue = 0, /**< Reference voltage in millivolts used in counts to volts conversion */ +}; + +static bool sar_initialized = false; + + +static void sar_init(analogin_t *obj) +{ + if (!sar_initialized) { + uint32_t sar_clock_divider = CY_INVALID_DIVIDER; + + sar_initialized = true; + // Allocate and setup clock. + sar_clock_divider = cy_clk_allocate_divider(CY_SYSCLK_DIV_8_BIT); + if (sar_clock_divider == CY_INVALID_DIVIDER) { + error("SAR clock divider allocation failed."); + return; + } + Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, + sar_clock_divider, + ((CY_CLK_PERICLK_FREQ_HZ + SAR_BASE_CLOCK_HZ / 2) / SAR_BASE_CLOCK_HZ) - 1); + Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, sar_clock_divider); + Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_8_BIT, sar_clock_divider); + + Cy_SAR_Init(obj->base, &sar_config); + Cy_SAR_Enable(obj->base); + } +} + + +/** Initialize the analogin peripheral + * + * Configures the pin used by analogin. + * @param obj The analogin object to initialize + * @param pin The analogin pin name + */ +void analogin_init(analogin_t *obj, PinName pin) +{ + uint32_t sar = 0; + uint32_t sar_function = 0; + + MBED_ASSERT(obj); + MBED_ASSERT(pin != (PinName)NC); + + + sar = pinmap_peripheral(pin, PinMap_ADC); + if (sar != (uint32_t)NC) { + if (cy_reserve_io_pin(pin)) { + error("ANALOG IN pin reservation conflict."); + } + obj->base = (SAR_Type*)CY_PERIPHERAL_BASE(sar); + obj->pin = pin; + obj->channel_mask = 1 << CY_PIN(pin); + + // Configure clock. + sar_function = pinmap_function(pin, PinMap_ADC); + obj->clock = CY_PIN_CLOCK(sar_function); + sar_init(obj); + pin_function(pin, sar_function); + } else { + error("ANALOG IN pinout mismatch."); + } +} + + +/** Read the input voltage, represented as a float in the range [0.0, 1.0] + * + * @param obj The analogin object + * @return A floating value representing the current input voltage + */ +float analogin_read(analogin_t *obj) +{ + uint16_t result = analogin_read_u16(obj); + + return (float)result * (1.0 / ADC_MAX_VALUE); +} + + +/** Read the value from analogin pin, represented as an unsigned 16bit value + * + * @param obj The analogin object + * @return An unsigned 16bit value representing the current input voltage + */ +uint16_t analogin_read_u16(analogin_t *obj) +{ + uint32_t result = 0; + + Cy_SAR_SetChanMask(obj->base, obj->channel_mask); + Cy_SAR_SetAnalogSwitch(obj->base, CY_SAR_MUX_SWITCH0, obj->channel_mask, CY_SAR_SWITCH_CLOSE); + Cy_SAR_StartConvert(obj->base, CY_SAR_START_CONVERT_SINGLE_SHOT); + if (Cy_SAR_IsEndConversion(obj->base, CY_SAR_WAIT_FOR_RESULT) == CY_SAR_SUCCESS) { + result = Cy_SAR_GetResult32(obj->base, CY_PIN(obj->pin)); + } else { + error("ANALOG IN: measurement failed!"); + } + Cy_SAR_SetAnalogSwitch(obj->base, CY_SAR_MUX_SWITCH0, obj->channel_mask, CY_SAR_SWITCH_OPEN); + // We are running 16x oversampling extending results to 16 bits. + return (uint16_t)(result); +} + +#endif // DEVICE_ANALOGIN + diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/analogout_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/analogout_api.c new file mode 100644 index 0000000000..c8467b150a --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/analogout_api.c @@ -0,0 +1,185 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "device.h" +#include "analogout_api.h" +#include "cy_ctdac.h" +#include "psoc6_utils.h" +#include "mbed_assert.h" +#include "mbed_error.h" +#include "pinmap.h" +#include "PeripheralPins.h" +#include "platform/mbed_error.h" + +#if DEVICE_ANALOGOUT + +#define CTDAC_NUM_BITS 12 +const uint16_t CTDAC_MAX_VALUE = (uint16_t)((1UL << CTDAC_NUM_BITS) - 1); + +const uint32_t CTDAC_BASE_CLOCK_HZ = 500000; // 500 kHz or less + +#define CTDAC_DEGLITCH_CYCLES 35 + + + +/** Global CTDAC configuration data. + */ +static cy_stc_ctdac_config_t ctdac_config = { + .refSource = CY_CTDAC_REFSOURCE_VDDA, /**< Reference source: Vdda or externally through Opamp1 of CTB */ + .formatMode = CY_CTDAC_FORMAT_UNSIGNED, /**< Format of DAC value: signed or unsigned */ + .updateMode = CY_CTDAC_UPDATE_BUFFERED_WRITE, /**< Update mode: direct or buffered writes or hardware, edge or level */ + .deglitchMode = CY_CTDAC_DEGLITCHMODE_UNBUFFERED, /**< Deglitch mode: disabled, buffered, unbuffered, or both */ + .outputMode = CY_CTDAC_OUTPUT_VALUE, /**< Output mode: enabled (value or value + 1), high-z, Vssa, or Vdda */ + .outputBuffer = CY_CTDAC_OUTPUT_UNBUFFERED, /**< Output path: Buffered through Opamp0 of CTB or connected directly to Pin 6 */ + .deepSleep = CY_CTDAC_DEEPSLEEP_DISABLE, /**< Enable or disable the CTDAC during Deep Sleep */ + .deglitchCycles = CTDAC_DEGLITCH_CYCLES, /**< Number of deglitch cycles from 0 to 63 */ + .value = 0, /**< Current DAC value */ + .nextValue = 0, /**< Next DAC value for double buffering */ + .enableInterrupt = false, /**< If true, enable interrupt when next value register is transferred to value register */ + .configClock = false, /**< Configure or ignore clock information */ +}; + + +static bool ctdac_initialized = 0; + +static void ctdac_init(dac_t *obj) +{ + if (!ctdac_initialized) { + uint32_t dac_clock_divider = CY_INVALID_DIVIDER; + + ctdac_initialized = true; + // Allocate and setup clock. + dac_clock_divider = cy_clk_allocate_divider(CY_SYSCLK_DIV_8_BIT); + if (dac_clock_divider == CY_INVALID_DIVIDER) { + error("CTDAC clock divider allocation failed."); + return; + } + Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, + dac_clock_divider, + ((CY_CLK_PERICLK_FREQ_HZ + CTDAC_BASE_CLOCK_HZ / 2) / CTDAC_BASE_CLOCK_HZ) - 1); + Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, dac_clock_divider); + Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_8_BIT, dac_clock_divider); + + Cy_CTDAC_Init(obj->base, &ctdac_config); + Cy_CTDAC_Enable(obj->base); + } +} + + +/** Initialize the analogout peripheral + * + * Configures the pin used by analogout. + * @param obj The analogout object to initialize + * @param pin The analogout pin name + */ +void analogout_init(dac_t *obj, PinName pin) +{ + uint32_t dac = 0; + uint32_t dac_function = 0; + + MBED_ASSERT(obj); + MBED_ASSERT(pin != (PinName)NC); + + + dac = pinmap_peripheral(pin, PinMap_DAC); + if (dac != (uint32_t)NC) { + if (cy_reserve_io_pin(pin)) { + error("ANALOG OUT pin reservation conflict."); + } + obj->base = (CTDAC_Type*)CY_PERIPHERAL_BASE(dac); + obj->pin = pin; + + // Configure clock. + dac_function = pinmap_function(pin, PinMap_DAC); + obj->clock = CY_PIN_CLOCK(dac_function); + pin_function(pin, dac_function); + ctdac_init(obj); + } else { + error("ANALOG OUT pinout mismatch."); + } +} + +/** Release the analogout object + * + * Note: This is not currently used in the mbed-drivers + * @param obj The analogout object + */ +void analogout_free(dac_t *obj) +{ + +} + +/** Set the output voltage, specified as a percentage (float) + * + * @param obj The analogout object + * @param value The floating-point output voltage to be set + */ +void analogout_write(dac_t *obj, float value) +{ + uint32_t val = 0; + + if (value > 1.0) { + val = CTDAC_MAX_VALUE; + } else if (value > 0.0) { + val = value * CTDAC_MAX_VALUE; + } + Cy_CTDAC_SetValueBuffered(obj->base, val); +} + +/** Set the output voltage, specified as unsigned 16-bit + * + * @param obj The analogout object + * @param value The unsigned 16-bit output voltage to be set + */ +void analogout_write_u16(dac_t *obj, uint16_t value) +{ + uint32_t val = 0; + + val = (value >> (16 - CTDAC_NUM_BITS)); // Convert from 16-bit range. + + Cy_CTDAC_SetValueBuffered(obj->base, val); +} + +/** Read the current voltage value on the pin + * + * @param obj The analogout object + * @return A floating-point value representing the current voltage on the pin, + * measured as a percentage + */ +float analogout_read(dac_t *obj) +{ + return (float)analogout_read_u16(obj) / 0xffff; +} + +/** Read the current voltage value on the pin, as a normalized unsigned 16bit value + * + * @param obj The analogout object + * @return An unsigned 16-bit value representing the current voltage on the pin + */ +uint16_t analogout_read_u16(dac_t *obj) +{ + uint16_t value = (obj->base->CTDAC_VAL_NXT >> CTDAC_CTDAC_VAL_NXT_VALUE_Pos) & CTDAC_CTDAC_VAL_NXT_VALUE_Msk; + + value <<= (16 - CTDAC_NUM_BITS); // Convert to 16-bit range. + + return value; +} + + + +#endif // DEVICE_ANALOGIN + diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto.h similarity index 95% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto.h index 59f8f484fa..cd67ac7ff6 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto.h @@ -7,7 +7,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -35,14 +35,14 @@ * \section group_crypto_overview Overview * The Crypto driver uses a client-server architecture. * -* Firmware initializes and starts the Crypto server. The server runs only on the -* CM0+ core, and works with the Crypto hardware. The Crypto server is implemented -* as a secure block. It performs all cryptographic operations for the client. -* Access to the server is through the Inter Process Communication (IPC) driver. -* Direct access is not allowed. +* Firmware initializes and starts the Crypto server. The server can run on +* either core and works with the Crypto hardware. The Crypto server is +* implemented as a secure block. It performs all cryptographic operations for +* the client. Access to the server is through the Inter Process Communication +* (IPC) driver. Direct access is not allowed. * -* The Crypto client can run on either core. Firmware initializes and starts the -* client. The firmware then provides the configuration data required for the +* The Crypto client can run on either core too. Firmware initializes and starts +* the client. The firmware then provides the configuration data required for the * desired cryptographic technique, and requests that the server run the * cryptographic operation. * @@ -152,13 +152,13 @@ * *
Reason for Change
2.10Added constructor attribute to SystemInit() function declaration for ARM MDK compiler. \n +* Removed $Sub$$main symbol for ARM MDK compiler. +* uVision Debugger support.
Updated description of the Startup behavior for Single-Core Devices. \n +* Added note about WDT disabling by SystemInit() function. +* Documentation improvement.
2.0Added restoring of FLL registers to the default state in SystemInit() API for single core devices. +* Single core device support. +*
Added Normal Access Restrictions, Public Key, TOC part2 and TOC part2 copy to Supervisory flash linker memory regions. \n +* Renamed 'wflash' memory region to 'em_eeprom'. +* Linker scripts usability improvement.
Added Cy_IPC_SystemSemaInit(), Cy_IPC_SystemPipeInit(), Cy_Flash_Init() functions call to SystemInit() API.Reserved system resources for internal operations.
Added clearing and releasing of IPC structure #7 (reserved for the Deep-Sleep operations) to SystemInit() API.To avoid deadlocks in case of SW or WDT reset during Deep-Sleep entering.
1.0Initial version
* -* On the CM0+, the error, release, and notify interrupts are assigned to -* NVIC IRQn 28-30 respectively. Do not modify these values. +* On the CM0+, the notify, release and error interrupts are assigned to +* NVIC IRQn 2, 30, 31 respectively. Do not modify these values. * See System Interrupt (SysInt) for background on CM0+ interrupts. * * \section group_crypto_server_init Server Initialization * -* Use \ref Cy_Crypto_Server_Start. This call must be made from the CM0+ core only. +* Use \ref Cy_Crypto_Server_Start. * Provide the configuration parameters (cy_stc_crypto_config_t) and a pointer * to the server context (cy_stc_crypto_server_context_t). * Do not fill in the values for the context structure. @@ -266,6 +266,11 @@ * mandatory, and represent the data for either the public or private key as * appropriate. * +* \note The modulus and exponent values in the +* \ref cy_stc_crypto_rsa_pub_key_t must be in little-endian order.
+* Use the \ref Cy_Crypto_Rsa_InvertEndianness function to convert to or from +* little-endian order. +* * The remaining fields represent three pre-calculated coefficients that can * reduce execution time by up to 5x. The fields are: coefficient for Barrett * reduction, binary inverse of the modulus, and the result of @@ -447,6 +452,24 @@ * * * +* +* +* +* +* +* +* +* +* * * * @@ -457,21 +480,21 @@ * \defgroup group_crypto_common Configuration * \{ * \defgroup group_crypto_config_macros Macros -* \defgroup group_crypto_config_structure Structure +* \defgroup group_crypto_config_structure Data Structures * \} * * \defgroup group_crypto_client Crypto Client * \{ * \defgroup group_crypto_macros Macros -* \defgroup group_crypto_enums Enumerated Types -* \defgroup group_crypto_cli_data_structures Data Structures * \defgroup group_crypto_cli_functions Functions +* \defgroup group_crypto_cli_data_structures Data Structures +* \defgroup group_crypto_enums Enumerated Types * \} * * \defgroup group_crypto_server Crypto Server * \{ -* \defgroup group_crypto_srv_data_structures Data Structures * \defgroup group_crypto_srv_functions Functions +* \defgroup group_crypto_srv_data_structures Data Structures * \} */ @@ -846,19 +869,19 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Ctr_Run(cy_en_crypto_dir_mode_t dirMode, * the context structure when making this function call. * * \param src -* The pointer to a source plain text. Must be 4-Byte aligned. +* The pointer to a source plain text. Must be 4-byte aligned. * * \param srcSize * The size of a source plain text. * * \param key -* The pointer to the encryption key. +* The pointer to the encryption key. Must be 4-byte aligned. * * \param keyLength * \ref cy_en_crypto_aes_key_length_t * * \param cmacPtr -* The pointer to the calculated CMAC. +* The pointer to the calculated CMAC. Must be 4-byte aligned. * * \param cfContext * The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all @@ -892,12 +915,13 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Cmac_Run(uint32_t *src, * * \param message * The pointer to a message whose hash value is being computed. +* Must be 4-byte aligned. * * \param messageSize * The size of a message. * * \param digest -* The pointer to the hash digest. +* The pointer to the hash digest. Must be 4-byte aligned. * * \param cfContext * the pointer to the \ref cy_stc_crypto_context_sha_t structure that stores all @@ -926,16 +950,17 @@ cy_en_crypto_status_t Cy_Crypto_Sha_Run(uint32_t *message, * preparation, calculation, and finalization steps. * * \param hmac -* The pointer to the calculated HMAC. +* The pointer to the calculated HMAC. Must be 4-byte aligned. * * \param message * The pointer to a message whose hash value is being computed. +* Must be 4-byte aligned. * * \param messageSize * The size of a message. * * \param key -* The pointer to the key. +* The pointer to the key. Must be 4-byte aligned. * * \param keyLength * The length of the key. @@ -965,7 +990,7 @@ cy_en_crypto_status_t Cy_Crypto_Hmac_Run(uint32_t *hmac, * Function Name: Cy_Crypto_Str_MemCpy ****************************************************************************//** * -* This function copy memory block. It operates data in the user SRAM and doesn't +* This function copies a memory block. It operates on data in the user SRAM and doesn't * use Crypto internal SRAM. * * \note Memory blocks should not overlap. @@ -999,7 +1024,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemCpy(void *dst, * Function Name: Cy_Crypto_Str_MemSet ****************************************************************************//** * -* This function sets the memory block. It operates data in the user SRAM and +* This function sets the memory block. It operates on data in the user SRAM and * doesn't use Crypto internal SRAM. * * There is no alignment restriction. @@ -1031,7 +1056,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemSet(void *dst, * Function Name: Cy_Crypto_Str_MemCmp ****************************************************************************//** * -* This function compares memory blocks. It operates data in the user SRAM and +* This function compares memory blocks. It operates on data in the user SRAM and * doesn't use Crypto internal SRAM. * * There is no alignment restriction. @@ -1047,7 +1072,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemSet(void *dst, * The size in bytes of the compare operation. Maximum size is 65535 Bytes. * * \param resultPtr -* The pointer to the result of compare: +* The pointer to the result of compare (must be 4-byte aligned): * - 0 - if Source 1 equal Source 2 * - 1 - if Source 1 not equal Source 2 * @@ -1069,7 +1094,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemCmp(void const *src0, * Function Name: Crypto_Str_MemXor ****************************************************************************//** * -* This function calculate XOR of two memory blocks. It operates data in the user +* This function calculates the XOR of two memory blocks. It operates on data in the user * SRAM and doesn't use Crypto internal SRAM. * * \note Memory structures should not overlap. @@ -1373,7 +1398,7 @@ cy_en_crypto_status_t Cy_Crypto_Crc_Init(uint32_t polynomial, * The size of a message in bytes. * * \param crc -* The pointer to a computed CRC value. +* The pointer to a computed CRC value. Must be 4-byte aligned. * * \param lfsrInitState * The initial state of the LFSR. @@ -1410,7 +1435,7 @@ cy_en_crypto_status_t Cy_Crypto_Crc_Run(void *data, * The maximum length of a random number, in the range [0, 32] bits. * * \param randomNum -* The pointer to a generated true random number. +* The pointer to a generated true random number. Must be 4-byte aligned. * * \param cfContext * The pointer to the \ref cy_stc_crypto_context_trng_t structure that stores @@ -1442,13 +1467,13 @@ cy_en_crypto_status_t Cy_Crypto_Trng_Generate(uint32_t GAROPol, * Can be CRYPTO_ENCRYPT or CRYPTO_DECRYPT (\ref cy_en_crypto_dir_mode_t) * * \param key -* The pointer to the encryption/decryption key. +* The pointer to the encryption/decryption key. Must be 4-byte aligned. * * \param srcBlock -* The pointer to a source block. Must be 4-byte aligned. +* The pointer to a source block. Must be 4-byte aligned. Must be 4-byte aligned. * * \param dstBlock -* The pointer to a destination cipher block. +* The pointer to a destination cipher block. Must be 4-byte aligned. * * \param cfContext * The pointer to the cy_stc_crypto_context_des_t structure that stores @@ -1478,13 +1503,13 @@ cy_en_crypto_status_t Cy_Crypto_Des_Run(cy_en_crypto_dir_mode_t dirMode, * Can be CRYPTO_ENCRYPT or CRYPTO_DECRYPT (\ref cy_en_crypto_dir_mode_t) * * \param key -* The pointer to the encryption/decryption key. +* The pointer to the encryption/decryption key. Must be 4-byte aligned. * * \param srcBlock -* The pointer to a source block. Must be 4-vyte aligned. +* The pointer to a source block. Must be 4-vyte aligned. Must be 4-byte aligned. * * \param dstBlock -* The pointer to a destination cipher block. +* The pointer to a destination cipher block. Must be 4-byte aligned. * * \param cfContext * The pointer to the cy_stc_crypto_context_des_t structure that stores @@ -1525,10 +1550,12 @@ cy_en_crypto_status_t Cy_Crypto_Tdes_Run(cy_en_crypto_dir_mode_t dirMode, * * Returns the processed value and a success value. * -* \note Incoming message and result processed message are little-endianess big -* integer values. To convert it from (to) binary (octet) strings use the \ref -* Cy_Crypto_Rsa_InvertEndianness function. -* +* \note Incoming message and result processed message must be in +* little-endian order.
+* The modulus and exponent values in the \ref cy_stc_crypto_rsa_pub_key_t +* must also be in little-endian order.
+* Use \ref Cy_Crypto_Rsa_InvertEndianness function to convert to or from +* little-endian order. * * \param pubKey * The pointer to the \ref cy_stc_crypto_rsa_pub_key_t structure that stores @@ -1541,7 +1568,7 @@ cy_en_crypto_status_t Cy_Crypto_Tdes_Run(cy_en_crypto_dir_mode_t dirMode, * The length of the message to be processed. * * \param processedMessage -* The pointer to processed message. +* The pointer to processed message. Must be 4-byte aligned. * * \param cfContext * The pointer to the \ref cy_stc_crypto_context_rsa_t structure that stores diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_common.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_common.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_common.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_common.h index d723e03be3..3870340c32 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_common.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_common.h @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -64,13 +64,13 @@ /** Defines the Crypto AES block size (in bytes) */ #define CY_CRYPTO_AES_BLOCK_SIZE (16u) -/** Defines the Crypto AES key maximum size (in bytes) */ +/** Defines the Crypto AES_128 key maximum size (in bytes) */ #define CY_CRYPTO_AES_128_KEY_SIZE (16u) -/** Defines the Crypto AES key maximum size (in bytes) */ +/** Defines the Crypto AES_192 key maximum size (in bytes) */ #define CY_CRYPTO_AES_192_KEY_SIZE (24u) -/** Defines the Crypto AES key maximum size (in bytes) */ +/** Defines the Crypto AES_256 key maximum size (in bytes) */ #define CY_CRYPTO_AES_256_KEY_SIZE (32u) /** Defines size of the AES block, in four-byte words */ @@ -157,7 +157,7 @@ typedef struct Note: In the second case user should process data separately and clear interrupt by calling \ref Cy_Crypto_Server_Process. This model is used in the - multitasking environment (e.g. CyOS). */ + multitasking environment. */ cy_israddress userGetDataHandler; /** Server-side user IRQ handler function, called when a Crypto hardware @@ -198,8 +198,14 @@ typedef struct * - n - modulus part of the key * - e - exponent part of the key. * - * Other fields are accelerating coefficients and can be calculated by - * \ref Cy_Crypto_Rsa_CalcCoefs. + * Other fields are accelerating coefficients and can be calculated by + * \ref Cy_Crypto_Rsa_CalcCoefs. + * + * \note The modulus and exponent values in the + * \ref cy_stc_crypto_rsa_pub_key_t must also be in little-endian order.
+ * Use \ref Cy_Crypto_Rsa_InvertEndianness function to convert to or from + * little-endian order. + * */ typedef struct { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_config.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_config.c similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_config.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_config.c index 99532a4a23..b5b9440ebd 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_config.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_config.c @@ -7,7 +7,7 @@ * required to configure the crypto driver by user. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_config.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_config.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_config.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_config.h index d99a8e61a5..289ee2f951 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_config.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_config.h @@ -7,7 +7,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_server.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_server.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_server.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_server.h index 9fc2dc6721..51a1298a38 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/crypto/cy_crypto_server.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/crypto/cy_crypto_server.h @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctb/cy_ctb.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctb/cy_ctb.c similarity index 83% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctb/cy_ctb.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctb/cy_ctb.c index 3755204f1f..835f0c58b0 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctb/cy_ctb.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctb/cy_ctb.c @@ -7,7 +7,7 @@ * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -138,17 +138,28 @@ const cy_stc_ctb_fast_config_oa1_t Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5 = * Function Name: Cy_CTB_Init ****************************************************************************//** * -* Initializes or restores the CTB and both Opamps according to the +* Initialize or restore the CTB and both opamps according to the * provided settings. Parameters are usually set only once, at initialization. * * \param base * Pointer to structure describing registers * * \param config -* Pointer to structure containing configuration data +* Pointer to structure containing configuration data for entire CTB * -* \return cy_en_ctb_status_t -* Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTB_SUCCESS or \ref CY_CTB_BAD_PARAM +* +* \funcusage +* +* The following code snippet configures Opamp0 as a comparator +* and Opamp1 as an opamp follower with 10x drive. The terminals +* are routed to external pins by closing the switches shown. +* +* \image html ctb_init_funcusage.png +* \image latex ctb_init_funcusage.png +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_CTBINIT * *******************************************************************************/ cy_en_ctb_status_t Cy_CTB_Init(CTBM_Type *base, const cy_stc_ctb_config_t *config) @@ -221,11 +232,6 @@ cy_en_ctb_status_t Cy_CTB_Init(CTBM_Type *base, const cy_stc_ctb_config_t *confi base->CTD_SW = config->ctdSwitchCtrl; } - if (config->enable) - { - Cy_CTB_Enable(base); - } - result = CY_CTB_SUCCESS; } @@ -236,24 +242,28 @@ cy_en_ctb_status_t Cy_CTB_Init(CTBM_Type *base, const cy_stc_ctb_config_t *confi * Function Name: Cy_CTB_OpampInit ****************************************************************************//** * -* Initializes each Opamp separately without impacting analog routing. +* Initialize each opamp separately without impacting analog routing. * Intended for use by automatic analog routing and configuration tools -* to configure each Opamp without having to integrate the settings with -* those of the other Opamp first. +* to configure each opamp without having to integrate the settings with +* those of the other opamp first. * -* Can also be used to configure both Opamps to have the same settings. +* Can also be used to configure both opamps to have the same settings. * * \param base * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param config * Pointer to structure containing configuration data * -* \return cy_en_ctb_status_t -* Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTB_SUCCESS or \ref CY_CTB_BAD_PARAM +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_OPAMPINIT * *******************************************************************************/ cy_en_ctb_status_t Cy_CTB_OpampInit(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, const cy_stc_ctb_opamp_config_t *config) @@ -282,7 +292,7 @@ cy_en_ctb_status_t Cy_CTB_OpampInit(CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp base->CTB_CTRL = (uint32_t) config->deepSleep; - /* The two Opamp control registers are symmetrical */ + /* The two opamp control registers are symmetrical */ oaResCtrl = (uint32_t) config->oaPower \ | (uint32_t) config->oaMode \ | (uint32_t) config->oaPump \ @@ -297,7 +307,7 @@ cy_en_ctb_status_t Cy_CTB_OpampInit(CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp base->OA_RES0_CTRL = oaResCtrl; base->OA0_COMP_TRIM = (uint32_t) ((config->oaMode == CY_CTB_MODE_OPAMP10X) ? CY_CTB_OPAMP_COMPENSATION_CAP_MAX: CY_CTB_OPAMP_COMPENSATION_CAP_MIN); - /* The INTR_MASK register is shared between the two Opamps */ + /* The INTR_MASK register is shared between the two opamps */ base->INTR_MASK |= (config->oaCompIntrEn ? CTBM_INTR_MASK_COMP0_MASK_Msk : CY_CTB_DEINIT); } @@ -306,16 +316,10 @@ cy_en_ctb_status_t Cy_CTB_OpampInit(CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp base->OA_RES1_CTRL = oaResCtrl; base->OA1_COMP_TRIM = (uint32_t) ((config->oaMode == CY_CTB_MODE_OPAMP10X) ? CY_CTB_OPAMP_COMPENSATION_CAP_MAX: CY_CTB_OPAMP_COMPENSATION_CAP_MIN); - /* The INTR_MASK register is shared between the two Opamps */ + /* The INTR_MASK register is shared between the two opamps */ base->INTR_MASK |= (config->oaCompIntrEn ? CTBM_INTR_MASK_COMP1_MASK_Msk : CY_CTB_DEINIT); } - if (config->enable) - { - Cy_CTB_Enable(base); - } - - result = CY_CTB_SUCCESS; } @@ -335,8 +339,8 @@ cy_en_ctb_status_t Cy_CTB_OpampInit(CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp * If true, all analog routing switches are reset to their default state. * If false, analog switch registers are untouched. * -* \return cy_en_ctb_status_t -* Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTB_SUCCESS or \ref CY_CTB_BAD_PARAM * *******************************************************************************/ cy_en_ctb_status_t Cy_CTB_DeInit(CTBM_Type *base, bool deInitRouting) @@ -373,20 +377,24 @@ cy_en_ctb_status_t Cy_CTB_DeInit(CTBM_Type *base, bool deInitRouting) * Function Name: Cy_CTB_FastInit ****************************************************************************//** * -* Initializes each Opamp of the CTB to one of the common use modes. -* These provide a quick and easy method of configuring the CTB when using -* the PDL driver for device configuration. Only routing switches required for -* the selected mode are configured, leaving final input and output connections -* to the user. Additional use modes are provided. These correspond with VDAC -* driver modes to support easy configuration of VDAC output buffer and input -* reference buffer options when used with the VDAC PDL driver. +* Initialize each opamp of the CTB to one of the common use modes. * -* Other configuration options are set to: -* - .oaPump = CY_CTB_PUMP_ENABLE -* - .oaCompEdge = CY_CTB_COMP_EDGE_BOTH -* - .oaCompLevel = CY_CTB_COMP_DSI_TRIGGER_OUT_PULSE -* - .oaCompBypass = CY_CTB_COMP_BYPASS_SYNC -* - .oaCompHyst = CY_CTB_COMP_HYST_10MV +* This function provides a quick and easy method of configuring the CTB +* using pre-defined configurations. +* Only routing switches required for the selected mode are configured, leaving final input and output connections +* to the user. +* Additional use modes that relate to the \ref group_ctdac "CTDAC" +* are provided to support easy configuration of the CTDAC output buffer and input +* reference buffer. +* +* The fast configuration structures define the opamp power, mode, and routing. +* This function sets the other configuration options of the CTB to: +* - .deepSleep = CY_CTB_DEEPSLEEP_DISABLE +* - .oaPump = \ref CY_CTB_PUMP_ENABLE +* - .oaCompEdge = \ref CY_CTB_COMP_EDGE_BOTH +* - .oaCompLevel = \ref CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL +* - .oaCompBypass = \ref CY_CTB_COMP_BYPASS_SYNC +* - .oaCompHyst = \ref CY_CTB_COMP_HYST_10MV * - .oaCompIntrEn = true * \param base @@ -394,7 +402,7 @@ cy_en_ctb_status_t Cy_CTB_DeInit(CTBM_Type *base, bool deInitRouting) * * \param config0 * Pointer to structure containing configuration data for quick initialization -* of Opamp0. Use one of the provided structures or define your own. +* of Opamp0. Defined your own or use one of the provided structures: * - \ref Cy_CTB_Fast_Opamp0_Unused * - \ref Cy_CTB_Fast_Opamp0_Comp * - \ref Cy_CTB_Fast_Opamp0_Opamp1x @@ -405,7 +413,7 @@ cy_en_ctb_status_t Cy_CTB_DeInit(CTBM_Type *base, bool deInitRouting) * * \param config1 * Pointer to structure containing configuration data for quick initialization -* of Opamp1. Use one of the provided structures or define your own. +* of Opamp1. Defined your own or use one of the provided structures: * - \ref Cy_CTB_Fast_Opamp1_Unused * - \ref Cy_CTB_Fast_Opamp1_Comp * - \ref Cy_CTB_Fast_Opamp1_Opamp1x @@ -414,8 +422,12 @@ cy_en_ctb_status_t Cy_CTB_DeInit(CTBM_Type *base, bool deInitRouting) * - \ref Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref * - \ref Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5 * -* \return cy_en_ctb_status_t -* Status of initialization, CY_CTB_SUCCESS or CY_CTB_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTB_SUCCESS or \ref CY_CTB_BAD_PARAM +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_FASTINIT * *******************************************************************************/ cy_en_ctb_status_t Cy_CTB_FastInit(CTBM_Type *base, const cy_stc_ctb_fast_config_oa0_t *config0, const cy_stc_ctb_fast_config_oa1_t *config1) @@ -450,7 +462,7 @@ cy_en_ctb_status_t Cy_CTB_FastInit(CTBM_Type *base, const cy_stc_ctb_fast_config | (uint32_t) config0->oa0Mode \ | (uint32_t) CY_CTB_PUMP_ENABLE \ | (uint32_t) CY_CTB_COMP_EDGE_BOTH \ - | (uint32_t) CY_CTB_COMP_DSI_TRIGGER_OUT_PULSE \ + | (uint32_t) CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL \ | (uint32_t) CY_CTB_COMP_BYPASS_SYNC \ | (uint32_t) CY_CTB_COMP_HYST_10MV \ | ((CY_CTB_MODE_OPAMP1X == config0->oa0Mode) ? CY_CTB_OPAMP_BOOST_ENABLE : CY_CTB_OPAMP_BOOST_DISABLE); @@ -459,7 +471,7 @@ cy_en_ctb_status_t Cy_CTB_FastInit(CTBM_Type *base, const cy_stc_ctb_fast_config | (uint32_t) config1->oa1Mode \ | (uint32_t) CY_CTB_PUMP_ENABLE \ | (uint32_t) CY_CTB_COMP_EDGE_BOTH \ - | (uint32_t) CY_CTB_COMP_DSI_TRIGGER_OUT_PULSE \ + | (uint32_t) CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL \ | (uint32_t) CY_CTB_COMP_BYPASS_SYNC \ | (uint32_t) CY_CTB_COMP_HYST_10MV \ | ((CY_CTB_MODE_OPAMP1X == config1->oa1Mode) ? CY_CTB_OPAMP_BOOST_ENABLE : CY_CTB_OPAMP_BOOST_DISABLE); @@ -483,9 +495,9 @@ cy_en_ctb_status_t Cy_CTB_FastInit(CTBM_Type *base, const cy_stc_ctb_fast_config * Function Name: Cy_CTB_SetCurrentMode ****************************************************************************//** * -* High level API function for configuring the current modes of the Opamps. -* This API configures all Opamps of the CTB to the same current mode. -* These modes are differentiated by the IPTAT current level, the Opamp +* High level function to configure the current modes of the opamps. +* This function configures all opamps of the CTB to the same current mode. +* These modes are differentiated by the reference current level, the opamp * input range, and the Deep Sleep mode operation. * * - The reference current level is set using \ref Cy_CTB_SetIptatLevel @@ -494,13 +506,14 @@ cy_en_ctb_status_t Cy_CTB_FastInit(CTBM_Type *base, const cy_stc_ctb_fast_config * \ref Cy_SysAnalog_SetDeepSleepMode is called with CY_SYSANALOG_DEEPSLEEP_IPTAT_IZTAT_VREF. * - When 100 nA current level is used, * - \ref Cy_CTB_EnableRedirect is called to route the AREF IPTAT reference -* to the Opamp IZTAT and disable the Opamps IPTAT. +* to the opamp IZTAT and disable the opamps IPTAT. * - The IPTAT generator is enabled in Deep Sleep. That is, * \ref Cy_SysAnalog_SetDeepSleepMode is called with CY_SYSANALOG_DEEPSLEEP_IPTAT_2 * unless it is already configured for CY_SYSANALOG_DEEPSLEEP_IPTAT_IZTAT_VREF. * -* Note that the IPTAT level is a chip wide configuration so multiple -* Opamps cannot operate at different IPTAT levels. +* \note +* The IPTAT level is a chip wide configuration so multiple +* opamps cannot operate at different IPTAT levels. * When calling \ref Cy_CTB_SetCurrentMode for a CTB instance on the device, * it should be called for all other CTB instances as well. * @@ -512,35 +525,40 @@ cy_en_ctb_status_t Cy_CTB_FastInit(CTBM_Type *base, const cy_stc_ctb_fast_config * * * -* +* * * * * * -* +* * * * * * -* +* * * * * *
VersionChangesReason for Change
2.0Clarified what parameters must be 4-byte aligned for the functions: +* \ref Cy_Crypto_Aes_Cmac_Run, \ref Cy_Crypto_Sha_Run, +* \ref Cy_Crypto_Hmac_Run, \ref Cy_Crypto_Str_MemCmp, +* \ref Cy_Crypto_Trng_Generate, \ref Cy_Crypto_Des_Run, +* \ref Cy_Crypto_Tdes_Run, \ref Cy_Crypto_Rsa_Proc +* Documentation update and clarification
+* Changed crypto IP power control
+* Enhanced Vector Unit functionality for RSA crypto algorithm
+* Added support of the single-core devices +*
New device support
1.0Initial versionDeep Sleep Operation
CY_CTB_CURRENT_HIGH_ACTIVE\ref CY_CTB_CURRENT_HIGH_ACTIVE1 uARail-to-Rail (charge pump enabled)Disabled in Deep Sleep
CY_CTB_CURRENT_HIGH_ACTIVE_DEEPSLEEP\ref CY_CTB_CURRENT_HIGH_ACTIVE_DEEPSLEEP1 uA0 - VDDA-1.5 V (charge pump disabled)Enabled in Deep Sleep
CY_CTB_CURRENT_LOW_ACTIVE_DEEPSLEEP\ref CY_CTB_CURRENT_LOW_ACTIVE_DEEPSLEEP100 nA0 - VDDA-1.5 V (charge pump disabled)Enabled in Deep Sleep
* -* NOTE: The output range of the Opamp is 0.2 V to VDDA-0.2 V (depending on output load). +* \note +* The output range of the opamp is 0.2 V to VDDA - 0.2 V (depending on output load). * * \param base * Pointer to structure describing registers * * \param currentMode -* Enable or disable CTB in Deep Sleep. +* Current mode selection * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_CURRENT_MODE +* *******************************************************************************/ void Cy_CTB_SetCurrentMode(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode) { @@ -558,7 +576,7 @@ void Cy_CTB_SetCurrentMode(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode Cy_CTB_SetIptatLevel(CY_CTB_IPTAT_NORMAL); Cy_CTB_DisableRedirect(); - /* Disable Deep Sleep mode for the CTB - not Opamp specific */ + /* Disable Deep Sleep mode for the CTB - not opamp specific */ Cy_CTB_SetDeepSleepMode(base, CY_CTB_DEEPSLEEP_DISABLE); /* Enable Opamp0 pump */ @@ -577,7 +595,7 @@ void Cy_CTB_SetCurrentMode(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode Cy_CTB_SetIptatLevel(CY_CTB_IPTAT_NORMAL); Cy_CTB_DisableRedirect(); - /* Enable Deep Sleep mode for the CTB - not Opamp specific */ + /* Enable Deep Sleep mode for the CTB - not opamp specific */ Cy_CTB_SetDeepSleepMode(base, CY_CTB_DEEPSLEEP_ENABLE); /* Disable Opamp0 pump */ @@ -590,7 +608,7 @@ void Cy_CTB_SetCurrentMode(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode case CY_CTB_CURRENT_LOW_ACTIVE_DEEPSLEEP: default: - /* The AREF IPTAT output for the Opamps must be enabled in Deep Sleep. + /* The AREF IPTAT output for the opamps must be enabled in Deep Sleep. * This means a minimum Deep Sleep mode setting of CY_SYSANALOG_DEEPSLEEP_IPTAT_2. */ arefDeepSleep = Cy_SysAnalog_GetDeepSleepMode(); if ((arefDeepSleep == CY_SYSANALOG_DEEPSLEEP_DISABLE) || (arefDeepSleep == CY_SYSANALOG_DEEPSLEEP_IPTAT_1)) @@ -602,7 +620,7 @@ void Cy_CTB_SetCurrentMode(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode Cy_CTB_SetIptatLevel(CY_CTB_IPTAT_LOW); Cy_CTB_EnableRedirect(); - /* Enable Deep Sleep mode for the CTB - not Opamp specific */ + /* Enable Deep Sleep mode for the CTB - not opamp specific */ Cy_CTB_SetDeepSleepMode(base, CY_CTB_DEEPSLEEP_ENABLE); /* Disable Opamp0 pump */ @@ -618,27 +636,31 @@ void Cy_CTB_SetCurrentMode(CTBM_Type *base, cy_en_ctb_current_mode_t currentMode * Function Name: Cy_CTB_SetDeepSleepMode ****************************************************************************//** * -* Sets whether to allow the CTB to continue to stay powered in Deep Sleep mode. -* -* If enabled, the AREF block must also be enabled for Deep Sleep (see -* \ref Cy_SysAnalog_SetDeepSleepMode). -* Also, if any of the COS, CA0, CHD, CH6, COB, COR, CRS, or CRD switches -* are used in Deep Sleep, the CTDAC must also be enabled for Deep Sleep (see -* \ref Cy_CTDAC_SetDeepSleepMode). +* Enable or disable the entire CTB (not per opamp) in Deep Sleep mode. * +* If enabled, the AREF block must also be enabled for Deep Sleep to provide +* the needed reference currents to the opamps (see \ref Cy_SysAnalog_SetDeepSleepMode). +* Additionally, ensure that only internal CTB switches are used for routing. +* Switches on AMUXBUSA and AMUXBUSB are not enabled in Deep Sleep. * See the \ref group_ctb_dependencies section for more information. * -* Note that in Deep Sleep mode, the charge pump is disabled so the input -* range is reduced to 0 - VDDA-1.5 V. +* \note +* In Deep Sleep mode, the charge pumps are disabled so the input +* range of the opamps is reduced to 0 V to VDDA - 1.5 V. * * \param base * Pointer to structure describing registers * * \param deepSleep -* Enable or disable CTB in Deep Sleep. +* \ref CY_CTB_DEEPSLEEP_DISABLE or \ref CY_CTB_DEEPSLEEP_ENABLE from +* \ref cy_en_ctb_deep_sleep_t. * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_DEEPSLEEP_MODE +* *******************************************************************************/ void Cy_CTB_SetDeepSleepMode(CTBM_Type *base, cy_en_ctb_deep_sleep_t deepSleep) { @@ -655,19 +677,23 @@ void Cy_CTB_SetDeepSleepMode(CTBM_Type *base, cy_en_ctb_deep_sleep_t deepSleep) * Function Name: Cy_CTB_SetOutputMode ****************************************************************************//** * -* Sets the Opamp output mode to 1x drive, 10x drive, or comparator mode. +* Set the opamp output mode to 1x drive, 10x drive, or comparator mode. * * \param base * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param mode -* Opamp mode selection +* Opamp mode selection. Select a value from \ref cy_en_ctb_mode_t. * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_OUTPUT_MODE +* *******************************************************************************/ void Cy_CTB_SetOutputMode(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_mode_t mode) { @@ -697,24 +723,33 @@ void Cy_CTB_SetOutputMode(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en * Function Name: Cy_CTB_SetPower ****************************************************************************//** * -* Sets the Opamp power mode to one of three levels to trade off power for -* gain bandwidth. Also enable or disable voltage pump to increase input -* range to supply rails. +* Configure the power level and charge pump for a specific opamp. +* +* At higher power levels, the opamp consumes more current but provides more +* gain bandwidth. +* Enabling the charge pump increases current but provides +* rail-to-rail input range. Disabling the charge pump limits the input range to +* VDDA - 1.5 V. +* See the device datasheet for performance specifications. * * \param base * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param power -* Power mode selection +* Power mode selection. Select a value from \ref cy_en_ctb_power_t. * * \param pump -* Enable or disable the charge pump for increased input range +* Enable or disable the charge pump. Select a value from \ref cy_en_ctb_pump_t. * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_POWER +* *******************************************************************************/ void Cy_CTB_SetPower(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_power_t power, cy_en_ctb_pump_t pump) { @@ -743,7 +778,7 @@ void Cy_CTB_SetPower(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_ * Function Name: Cy_CTB_DACSampleAndHold ****************************************************************************//** * -* Performs sampling and holding of the CTDAC output. +* Perform sampling and holding of the CTDAC output. * To perform a sample or a hold, a preparation step must first be executed to * open the required switches. Because of this, each sample or hold * requires three function calls: @@ -752,22 +787,9 @@ void Cy_CTB_SetPower(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_ * -# Enable or disable the CTDAC output * -# Call this function again to perform a sample or hold * -* For example, -* -* To sample the CTDAC output voltage: -* -# Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_PREPARE_SAMPLE); -* -# Cy_CTDAC_SetOutputMode(CTDAC0, CY_CTDAC_OUTPUT_VALUE); -* -# Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_SAMPLE); -* -# Cy_SysLib_DelayUs(10); -* * It takes 10 us to perform a sample of the CTDAC output to provide * time for the capacitor to settle to the new value. * -* To hold the CTDAC output voltage: -* -# Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_PREPARE_HOLD); -* -# Cy_CTDAC_SetOutputMode(CTDAC0, CY_CTDAC_OUTPUT_HIGHZ); -* -# Cy_CTB_DACSampleAndHold(CTBM0, CY_CTB_SH_HOLD); -* * \param base * Pointer to structure describing registers * @@ -776,6 +798,14 @@ void Cy_CTB_SetPower(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, cy_en_ctb_ * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SAMPLE_CODE_SNIPPET +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_HOLD_CODE_SNIPPET +* *******************************************************************************/ void Cy_CTB_DACSampleAndHold(CTBM_Type *base, cy_en_ctb_sample_hold_mode_t mode) { @@ -815,7 +845,7 @@ void Cy_CTB_DACSampleAndHold(CTBM_Type *base, cy_en_ctb_sample_hold_mode_t mode) * Function Name: Cy_CTB_OpampSetOffset ****************************************************************************//** * -* Overrides the CTB opamp offset factory trim. +* Override the CTB opamp offset factory trim. * The trim is a six bit value and the MSB is a direction bit. * * @@ -850,13 +880,17 @@ void Cy_CTB_DACSampleAndHold(CTBM_Type *base, cy_en_ctb_sample_hold_mode_t mode) * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param trim * Trim value from 0 to 63 * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_OFFSET_TRIM +* *******************************************************************************/ void Cy_CTB_OpampSetOffset(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, uint32_t trim) { @@ -878,16 +912,20 @@ void Cy_CTB_OpampSetOffset(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, uint * Function Name: Cy_CTB_OpampGetOffset ****************************************************************************//** * -* Returns the current CTB Opamp offset trim value. +* Return the current CTB opamp offset trim value. * * \param base * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0 or CY_CTB_OPAMP_1 +* \ref CY_CTB_OPAMP_0 or \ref CY_CTB_OPAMP_1 * * \return Offset trim value * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_GET_OFFSET_TRIM +* *******************************************************************************/ uint32_t Cy_CTB_OpampGetOffset(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum) { @@ -911,8 +949,8 @@ uint32_t Cy_CTB_OpampGetOffset(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opam * Function Name: Cy_CTB_OpampSetSlope ****************************************************************************//** * -* Override the CTB Opamp slope factory trim. -* The offset of the Opamp will vary across temperature. +* Override the CTB opamp slope factory trim. +* The offset of the opamp will vary across temperature. * This trim compensates for the slope of the offset across temperature. * This compensation uses a bias current from the Analaog Reference block. * To disable it, set the trim to 0. @@ -951,13 +989,17 @@ uint32_t Cy_CTB_OpampGetOffset(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opam * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param trim * Trim value from 0 to 63 * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_SLOPE_TRIM +* *******************************************************************************/ void Cy_CTB_OpampSetSlope(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, uint32_t trim) { @@ -979,16 +1021,20 @@ void Cy_CTB_OpampSetSlope(CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum, uint3 * Function Name: Cy_CTB_OpampGetSlope ****************************************************************************//** * -* Returns the current CTB Opamp slope trim value. +* Return the CTB opamp slope trim value. * * \param base * Pointer to structure describing registers * * \param opampNum -* CY_CTB_OPAMP_0 or CY_CTB_OPAMP_1 +* \ref CY_CTB_OPAMP_0 or \ref CY_CTB_OPAMP_1 * * \return Slope trim value * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_GET_SLOPE_TRIM +* *******************************************************************************/ uint32_t Cy_CTB_OpampGetSlope(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opampNum) { @@ -1012,7 +1058,7 @@ uint32_t Cy_CTB_OpampGetSlope(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp * Function Name: Cy_CTB_SetAnalogSwitch ****************************************************************************//** * -* Provides firmware control of the CTB switches. Each call to this function +* Provide firmware control of the CTB switches. Each call to this function * can open a set of switches or close a set of switches in one register. * * \param base @@ -1026,18 +1072,17 @@ uint32_t Cy_CTB_OpampGetSlope(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp * The mask of the switches to either open or close. * The switch masks can be found in the following enums: \ref cy_en_ctb_oa0_switches_t, * \ref cy_en_ctb_oa1_switches_t, and \ref cy_en_ctb_ctd_switches_t. +* Use the enum that is consistent with the provided register. * * \param state -* CY_CTB_SWITCH_OPEN or CY_CTB_SWITCH_CLOSE -* -* For example, to route the non-inverting input of opamp0 to Pin 0 of the CTB port, -* and the inverting input of opamp0 to Pin 1: -* switchSelect = CY_CTB_SWITCH_OA0_SW; -* switchMask = CY_CTB_SW_OA0_POS_PIN0_MASK | CY_CTB_SW_OA0_NEG_PIN1_MASK; -* state = CY_CTB_SWITCH_CLOSE; +* \ref CY_CTB_SWITCH_OPEN or \ref CY_CTB_SWITCH_CLOSE * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_ANALOG_SWITCH +* *******************************************************************************/ void Cy_CTB_SetAnalogSwitch(CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_ctb_switch_state_t state) { @@ -1081,7 +1126,7 @@ void Cy_CTB_SetAnalogSwitch(CTBM_Type *base, cy_en_ctb_switch_register_sel_t swi * Function Name: Cy_CTB_GetAnalogSwitch ****************************************************************************//** * -* Returns the open or closed state of the specified analog switch. +* Return the open or closed state of the specified analog switch. * * \param base * Pointer to structure describing registers @@ -1090,10 +1135,15 @@ void Cy_CTB_SetAnalogSwitch(CTBM_Type *base, cy_en_ctb_switch_register_sel_t swi * A value of the enum \ref cy_en_ctb_switch_register_sel_t to select the switch * register * -* \return uint32_t +* \return +* The state of the switches in the provided register. * Compare this value to the switch masks in the following enums: * \ref cy_en_ctb_oa0_switches_t, \ref cy_en_ctb_oa1_switches_t, and \ref cy_en_ctb_ctd_switches_t. * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_GET_ANALOG_SWITCH +* *******************************************************************************/ uint32_t Cy_CTB_GetAnalogSwitch(const CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect) { @@ -1118,41 +1168,18 @@ uint32_t Cy_CTB_GetAnalogSwitch(const CTBM_Type *base, cy_en_ctb_switch_register return switchRegValue; } -/******************************************************************************* -* Function Name: Cy_CTB_OpenAllSwitches -****************************************************************************//** -* -* Open all the switches and disable all hardware control of the switches. -* Primarily used as a quick method of reconfiguring all analog connections -* that are sparsely closed. -* -* \param base -* Pointer to structure describing registers -* -* \return None -* -*******************************************************************************/ -void Cy_CTB_OpenAllSwitches(CTBM_Type *base) -{ - base->OA0_SW_CLEAR = CY_CTB_DEINIT_OA0_SW; - base->OA1_SW_CLEAR = CY_CTB_DEINIT_OA1_SW; - base->CTD_SW_CLEAR = CY_CTB_DEINIT_CTD_SW; - base->CTB_SW_DS_CTRL = CY_CTB_DEINIT; - base->CTB_SW_SQ_CTRL = CY_CTB_DEINIT; -} - /******************************************************************************* * Function Name: Cy_CTB_CompSetConfig ****************************************************************************//** * -* Configures the CTB comparator for pulse or level output, to bypass clock +* Configure the CTB comparator for pulse or level output, to bypass clock * synchronization, and to enable hysteresis. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param level * Configure output to produce a pulse or level output signal @@ -1165,6 +1192,10 @@ void Cy_CTB_OpenAllSwitches(CTBM_Type *base) * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_COMP_SET_CONFIG +* *******************************************************************************/ void Cy_CTB_CompSetConfig(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum, cy_en_ctb_comp_level_t level, cy_en_ctb_comp_bypass_t bypass, cy_en_ctb_comp_hyst_t hyst) { @@ -1192,18 +1223,23 @@ void Cy_CTB_CompSetConfig(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum, cy_en_ * Function Name: Cy_CTB_CompGetConfig ****************************************************************************//** * -* Returns the CTB comparator operating configuration. +* Return the CTB comparator operating configuration as set by \ref Cy_CTB_CompSetConfig. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0 or CY_CTB_OPAMP_1 +* \ref CY_CTB_OPAMP_0 or \ref CY_CTB_OPAMP_1 * -* \return comparator status +* \return +* The comparator configuration. * Compare the register value with the masks in \ref cy_en_ctb_comp_level_t, * \ref cy_en_ctb_comp_bypass_t, and \ref cy_en_ctb_comp_hyst_t. * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_COMP_GET_CONFIG +* *******************************************************************************/ uint32_t Cy_CTB_CompGetConfig(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) { @@ -1227,19 +1263,23 @@ uint32_t Cy_CTB_CompGetConfig(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compN * Function Name: Cy_CTB_CompSetInterruptEdgeType ****************************************************************************//** * -* Configures the type of edge that will trigger a comparator interrupt. +* Configure the type of edge that will trigger a comparator interrupt. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \param edge -* Edge type +* Edge type that will trigger an interrupt. Select a value from \ref cy_en_ctb_comp_edge_t. * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_COMP_SET_INTERRUPT_EDGE_TYPE +* *******************************************************************************/ void Cy_CTB_CompSetInterruptEdgeType(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum, cy_en_ctb_comp_edge_t edge) { @@ -1265,20 +1305,26 @@ void Cy_CTB_CompSetInterruptEdgeType(CTBM_Type *base, cy_en_ctb_opamp_sel_t comp * Function Name: Cy_CTB_CompGetStatus ****************************************************************************//** * -* Returns status of the indicated comparator output. +* Return the comparator output status. +* When the positive input voltage is greater than the negative input voltage, +* the comparator status is high. Otherwise, the status is low. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0 or CY_CTB_OPAMP_1 +* \ref CY_CTB_OPAMP_0 or \ref CY_CTB_OPAMP_1. +* \ref CY_CTB_OPAMP_NONE and \ref CY_CTB_OPAMP_BOTH are invalid options. * -* \return comparator status -* 0 - Comparator output low -* 1 - Comparator output high +* \return +* The comparator status. +* A value of 0 is returned if compNum is invalid. +* - 0: Status is low +* - 1: Status is high * -* A value of 0 is returned if compNum is an invalid value, CY_CTB_OPAMP_NONE -* or CY_CTB_OPAMP_BOTH. +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_COMP_GET_STATUS * *******************************************************************************/ uint32_t Cy_CTB_CompGetStatus(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctb/cy_ctb.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctb/cy_ctb.h similarity index 76% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctb/cy_ctb.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctb/cy_ctb.h index 4e8903d590..2554ac076a 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctb/cy_ctb.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctb/cy_ctb.h @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -16,37 +16,32 @@ * \defgroup group_ctb Continuous Time Block (CTB) * \{ * This driver provides API functions to configure and use the analog CTB. -* The CTB comprises two identical Opamps, a switch routing matrix, -* and a sample and hold circuit. The high level features are: +* The CTB comprises two identical opamps, a switch routing matrix, +* and a sample and hold (SH) circuit. The high level features are: * -* - Two highly configurable Opamps -* - Each Opamp has programmable power and output drive strength -* - Each Opamp can be configured as a voltage follower using internal routing -* - Each Opamp can be configured as a comparator with optional 10 mV hysteresis +* - Two highly configurable opamps +* - Each opamp has programmable power and output drive strength +* - Each opamp can be configured as a voltage follower using internal routing +* - Each opamp can be configured as a comparator with optional 10 mV hysteresis * - Flexible input and output routing * - Works as a buffer or amplifier for SAR ADC inputs -* - Works as a buffer, amplifier, or sample-and-hold for the CTDAC output +* - Works as a buffer, amplifier, or sample and hold (SH) for the CTDAC output * - Can operate in Deep Sleep power mode * -* Each Opamp, marked OA0 and OA1, has one input and three output stages, +* Each opamp, marked OA0 and OA1, has one input and three output stages, * all of which share the common input stage. * Note that only one output stage can be selected at a time. -* The output stage can operate as a low-drive strength Opamp (1X), a high-drive strength -* Opamp (10X), or a comparator. +* The output stage can operate as a low-drive strength opamp for internal connections (1X), a high-drive strength +* opamp for driving a device pin (10X), or a comparator. * -* The input range of the Opamp can be rail-to-rail if the charge pump is enabled. -* Without the charge pump, the input range is 0 - VDDA-1.5 V. The output range -* of the Opamp is 0.2 V to VDDA-0.2 V, but this depends on the load. See the -* device datasheet for more detail. -* -* Using the switching matrix, the Opamp inputs and outputs +* Using the switching matrix, the opamp inputs and outputs * can be connected to dedicated general-purpose I/Os or other internal analog * blocks. See the device datasheet for the dedicated CTB port. * -* \image html ctb_block_diagram.png +* \image html ctb_block_diagram.png "CTB Switch Diagram" width=1000px * \image latex ctb_block_diagram.png * -* \section group_ctb_init Initialization +* \section group_ctb_init Initialization and Enable * * Before enabling the CTB, set up any external components (such as resistors) * that are needed for the design. To configure the entire hardware block, call \ref Cy_CTB_Init. @@ -75,23 +70,80 @@ * * After initialization, call \ref Cy_CTB_Enable to enable the hardware. * +* \section group_ctb_io_connections Input/Output Connections +* +* The CTB has internal switches to support flexible input and output routing. If these switches +* have not been configured during initialization, call \ref Cy_CTB_SetAnalogSwitch to +* make the input and output connections. +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_ANALOG_SWITCH +* +* As shown in the CTB switch diagram, the 10x output of OA0 and OA1 have dedicated +* connections to Pin 2 and Pin 3, respectively, of the CTB port. If different output +* connections are required, the other CTB switches and/or AMUXBUX A/B switches can be used. +* * \section group_ctb_comparator Comparator Mode * -* Each Opamp can be configured as a comparator. Note that when used as a +* Each opamp can be configured as a comparator. Note that when used as a * comparator, the hardware shuts down the 1X and 10X output drivers. * Specific to the comparator mode, there is an optional 10 mV input hysteresis * and configurable edge detection interrupt handling. +* +* - Negative input terminal: This input is usually connected to the reference voltage. +* - Positive input terminal: This input is usually connected to the voltage that is being compared. +* - Comparator digital output: This output goes high when the positive input voltage +* is greater than the negative input voltage. +* +* The comparator output can be routed to a pin or other components using HSIOM or trigger muxes. +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_COMP_OUT_ROUTING +* +* \subsection group_ctb_comparator_handling_interrupts Handling interrupts +* * The comparator output is connected to an edge detector * block, which is used to detect the edge (rising, falling, both, or disabled) * for interrupt generation. * +* The following code snippet demonstrates how to implement a routine to handle the interrupt. +* The routine gets called when any comparator on the device generates an interrupt. +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_COMP_ISR +* +* The following code snippet demonstrates how to configure and enable the interrupt. +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_COMP_INTR_SETUP +* +* \section group_ctb_opamp_range Opamp Input and Output Range +* +* The input range of the opamp can be rail-to-rail if the charge pump is enabled. +* Without the charge pump, the input range is 0 V to VDDA - 1.5 V. The output range +* of the opamp is typically 0.2 V to VDDA - 0.2 V and will depend on the load. See the +* device datasheet for more detail. +* +*
+* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
Charge PumpInput Range
Output Range
Enabled0 V to VDDA0.2 V to VDDA - 0.2 V
Disabled0 V to VDDA - 1.5 V0.2 V to VDDA - 0.2 V
+* * \section group_ctb_sample_hold Sample and Hold Mode * -* The CTB has a sample and hold (S/H) circuit at the non-inverting input of Opamp0. +* The CTB has a sample and hold (SH) circuit at the non-inverting input of Opamp0. * The circuit includes a hold capacitor, Chold, with a firmware controlled switch, CHD. * Sampling and holding the source voltage is performed * by closing and opening appropriate switches in the CTB using firmware. -* If the S/H circuit is used for the CTDAC, the \ref Cy_CTB_DACSampleAndHold function +* If the SH circuit is used for the CTDAC, the \ref Cy_CTB_DACSampleAndHold function * should be called. * * \image html ctb_fast_config_vdac_sh.png @@ -102,10 +154,10 @@ * The CTB relies on other blocks to function properly. The dependencies * are documented here. * -*Charge Pump Configuration +* \subsection group_ctb_dependencies_charge_pump Charge Pump Configuration * -* Each Opamp of the CTB has a charge pump that when enabled increases the -* input range to the supply rails. When disabled, the Opamp input range is 0 - VDDA - 1.5 V. +* Each opamp of the CTB has a charge pump that when enabled increases the +* input range to the supply rails. When disabled, the opamp input range is 0 - VDDA - 1.5 V. * When enabled, the pump requires a clock. * Call the \ref Cy_CTB_SetClkPumpSource function in the \ref group_sysanalog driver to * set the clock source for all CTBs. This clock can come from one of two sources: @@ -116,6 +168,9 @@ * - \ref Cy_SysClk_ClkPumpSetSource * - \ref Cy_SysClk_ClkPumpSetDivider * - \ref Cy_SysClk_ClkPumpEnable +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_CLK_PUMP_SOURCE_SRSS +* * -# One of the Peri Clock dividers * * Call the following functions to configure a Peri Clock divider as the @@ -124,10 +179,12 @@ * - \ref Cy_SysClk_PeriphSetDivider * - \ref Cy_SysClk_PeriphEnableDivider * +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_CLK_PUMP_SOURCE_PERI +* * When the charge pump is enabled, the clock frequency should be set as follows: * * -* +* * * * @@ -138,18 +195,19 @@ * *
Opamp PowerPump Clock Freq
Opamp Power LevelPump Clock Freq
Low or Medium8 - 24 MHz
* -* The High power level of the Opamp requires a 24 MHz pump clock. +* The High power level of the opamp requires a 24 MHz pump clock. * In Deep Sleep mode, all high frequency clocks are * disabled and the charge pump will be disabled. * -* Note that the same pump clock is used by all Opamps on the device. Be aware of this -* when configuring different Opamps to different power levels. +* \note +* The same pump clock is used by all opamps on the device. Be aware of this +* when configuring different opamps to different power levels. * -* Reference Current Configurations +* \subsection group_ctb_dependencies_reference_current Reference Current Configurations * * The CTB uses two reference current generators, IPTAT and IZTAT, from * the AREF block (see \ref group_sysanalog driver). The IPTAT current is -* used to trim the slope of the Opamp offset across temperature. +* used to trim the slope of the opamp offset across temperature. * The AREF must be initialized and enabled for the CTB to function properly. * * If the CTB is configured to operate in Deep Sleep mode, @@ -184,38 +242,23 @@ * while consuming the most current. * For Deep Sleep operation, use the other two configurations with the charge pump disabled. * For ultra low power, use the 100 nA current level. -* To configure the Opamps to operate in one of these options, call \ref Cy_CTB_SetCurrentMode. +* To configure the opamps to operate in one of these options, call \ref Cy_CTB_SetCurrentMode. * -* Sample and Hold Switch Control +* \subsection group_ctb_dependencies_sample_hold Sample and Hold Switch Control * -* The following eight switches that are contained in the CTB are enabled by the CTDAC IP -* block: +* If you are using rev-08 of the CY8CKIT-062, the following eight switches +* in the CTB are enabled by the CTDAC IP block: * -* - COS, CA0, CHD, CH6, COB, COR, CRS and CRD +* - COS, CA0, CHD, CH6, COB, COR, CRS, and CRD * -* If any of the above switches are used, the \ref Cy_CTDAC_Enable function must be called. -* Additionally, if any of the switches are used in Deep Sleep mode, the CTDAC must also -* be configured to operate in Deep Sleep (see \ref Cy_CTDAC_SetDeepSleepMode). +* On the rev-08 board, if any of the above switches are used, you must call \ref Cy_CTDAC_Enable +* to enable these switches. * -* \section group_ctb_code_example Complete Code Example +* Additionally, on the rev-08 board, if any of the switches are used in Deep Sleep mode, +* the CTDAC must also be configured to operate in Deep Sleep (see \ref Cy_CTDAC_SetDeepSleepMode). * -* The following example code demonstrates how to configure Opamp0 -* as a comparator and Opamp1 as a voltage follower. The terminals -* are routed to external pins by closing the switches shown. -* -* \image html ctb_code_example.png -* \image latex ctb_code_example.png -* -* The example code also shows how to handle the comparator interrupt. -* -* \code -* #include "ctb/cy_ctb.h" -* #include "sysanalog/cy_sysanalog.h" -* #include "sysint/cy_sysint.h" -* #include "gpio/cy_gpio.h" -* \endcode -* -* \snippet ctb_sut_01.cydsn/main_cm0p.c CTB_CODE_EXAMPLE +* In later revisions of the board, the switches are enabled by the CTB block so +* calls to the CTDAC IP block are not necessary. * * \section group_ctb_more_information More Information * @@ -248,7 +291,7 @@ * \defgroup group_ctb_functions_aref Reference Current Mode Functions * \} * \defgroup group_ctb_globals Global Variables -* \defgroup group_ctb_data_structures Data structures +* \defgroup group_ctb_data_structures Data Structures * \defgroup group_ctb_enums Enumerated Types */ @@ -360,6 +403,9 @@ extern "C" { #define CY_CTB_SWITCHMASK(select,mask) (((select) == CY_CTB_SWITCH_OA0_SW) ? (((mask) & (~CY_CTB_DEINIT_OA0_SW)) == 0uL) : \ (((select) == CY_CTB_SWITCH_OA1_SW) ? (((mask) & (~CY_CTB_DEINIT_OA1_SW)) == 0uL) : \ (((mask) & (~CY_CTB_DEINIT_CTD_SW)) == 0uL))) +#define CY_CTB_SARSEQCTRL(mask) (((mask) == CY_CTB_SW_SEQ_CTRL_D51_MASK) \ + || ((mask) == CY_CTB_SW_SEQ_CTRL_D52_D62_MASK) \ + || ((mask) == CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK)) /** \endcond */ @@ -376,7 +422,7 @@ extern "C" { /** * Most functions allow you to configure a single opamp or both opamps at once. -* The \ref Cy_CTB_SetInterruptMask function can be called with CY_CTB_OPAMP_NONE +* The \ref Cy_CTB_SetInterruptMask function can be called with \ref CY_CTB_OPAMP_NONE * and interrupts will be disabled. */ typedef enum{ @@ -431,17 +477,17 @@ typedef enum { }cy_en_ctb_power_t; /** -* The output stage of each Opamp can be configured for low-drive strength (1X) to drive internal circuits, +* The output stage of each opamp can be configured for low-drive strength (1X) to drive internal circuits, * for high-drive strength (10X) to drive external circuits, or as a comparator. */ typedef enum { - CY_CTB_MODE_OPAMP1X = 0u, /**< Configure Opamp for low drive strength (1x) */ - CY_CTB_MODE_OPAMP10X = 1u << CTBM_OA_RES0_CTRL_OA0_DRIVE_STR_SEL_Pos, /**< Configure Opamp high drive strength (10x) */ - CY_CTB_MODE_COMP = 1u << CTBM_OA_RES0_CTRL_OA0_COMP_EN_Pos, /**< Configure Opamp as a comparator */ + CY_CTB_MODE_OPAMP1X = 0u, /**< Configure opamp for low drive strength for internal connections (1x) */ + CY_CTB_MODE_OPAMP10X = 1u << CTBM_OA_RES0_CTRL_OA0_DRIVE_STR_SEL_Pos, /**< Configure opamp high drive strength for driving a device pin (10x) */ + CY_CTB_MODE_COMP = 1u << CTBM_OA_RES0_CTRL_OA0_COMP_EN_Pos, /**< Configure opamp as a comparator */ }cy_en_ctb_mode_t; /** -* Each Opamp has a charge pump to increase the input range to the rails. +* Each opamp has a charge pump to increase the input range to the rails. * When the charge pump is enabled, the input range is 0 to VDDA. * When disabled, the input range is 0 to VDDA - 1.5 V. * @@ -547,34 +593,45 @@ typedef enum }cy_en_ctb_oa1_switches_t; /** -* Switch masks for CTDAC routing to be used in \ref Cy_CTB_SetAnalogSwitch. -* -* Eight of the 10 switches are enabled by the CTDAC IP block. That is, -* \ref Cy_CTDAC_Enable must also be called to close these switches. -* The CTDAC output should be high-z in order to not interfere with the CTB. -* -* The two switches that do not require the CTDAC are: -* - CY_CTB_SW_CTD_CHOLD_OA0_POS_ISOLATE_MASK (switch CIS) -* - CY_CTB_SW_CTD_CHOLD_LEAKAGE_REDUCTION_MASK (switch ILR) +* Switch masks for CTDAC to CTB routing to be used in \ref Cy_CTB_SetAnalogSwitch. */ typedef enum { - CY_CTB_SW_CTD_REF_OA1_OUT_MASK = CTBM_CTD_SW_CTDD_CRD_Msk, /**< Switch CRD: Opamp1 output to CTDAC reference. CTDAC must be enabled */ - CY_CTB_SW_CTD_REFSENSE_OA1_NEG_MASK = CTBM_CTD_SW_CTDS_CRS_Msk, /**< Switch CRS: CTDAC reference sense to Opamp1 inverting input. CTDAC must be enabled */ - CY_CTB_SW_CTD_OUT_OA1_NEG_MASK = CTBM_CTD_SW_CTDS_COR_Msk, /**< Switch COR: CTDAC output to Opamp1 inverting input. CTDAC must be enabled */ - CY_CTB_SW_CTD_OUT_PIN6_MASK = CTBM_CTD_SW_CTDO_C6H_Msk, /**< Switch C6H: CTDAC output to P6 of CTB device port. CTDAC must be enabled */ - CY_CTB_SW_CTD_OUT_CHOLD_MASK = CTBM_CTD_SW_CTDO_COS_Msk, /**< Switch COS: CTDAC output to hold cap (deglitch capable). CTDAC must be enabled */ - CY_CTB_SW_CTD_OUT_OA0_1X_OUT_MASK = CTBM_CTD_SW_CTDH_COB_Msk, /**< Switch COB: Drive CTDAC output with opamp0 1x output during hold mode. CTDAC must be enabled */ - CY_CTB_SW_CTD_CHOLD_CONNECT_MASK = CTBM_CTD_SW_CTDH_CHD_Msk, /**< Switch CHD: Hold cap connection. CTDAC must be enabled */ - CY_CTB_SW_CTD_CHOLD_OA0_POS_MASK = CTBM_CTD_SW_CTDH_CA0_Msk, /**< Switch CA0: Hold cap to Opamp0 non-inverting input. CTDAC must be enabled */ + CY_CTB_SW_CTD_REF_OA1_OUT_MASK = CTBM_CTD_SW_CTDD_CRD_Msk, /**< Switch CRD: Opamp1 output to CTDAC reference. */ + CY_CTB_SW_CTD_REFSENSE_OA1_NEG_MASK = CTBM_CTD_SW_CTDS_CRS_Msk, /**< Switch CRS: CTDAC reference sense to Opamp1 inverting input. */ + CY_CTB_SW_CTD_OUT_OA1_NEG_MASK = CTBM_CTD_SW_CTDS_COR_Msk, /**< Switch COR: CTDAC output to Opamp1 inverting input. */ + CY_CTB_SW_CTD_OUT_PIN6_MASK = CTBM_CTD_SW_CTDO_C6H_Msk, /**< Switch C6H: CTDAC output to P6 of CTB device port. */ + CY_CTB_SW_CTD_OUT_CHOLD_MASK = CTBM_CTD_SW_CTDO_COS_Msk, /**< Switch COS: CTDAC output to hold cap (deglitch capable). */ + CY_CTB_SW_CTD_OUT_OA0_1X_OUT_MASK = CTBM_CTD_SW_CTDH_COB_Msk, /**< Switch COB: Drive CTDAC output with opamp0 1x output during hold mode. */ + CY_CTB_SW_CTD_CHOLD_CONNECT_MASK = CTBM_CTD_SW_CTDH_CHD_Msk, /**< Switch CHD: Hold cap connection. */ + CY_CTB_SW_CTD_CHOLD_OA0_POS_MASK = CTBM_CTD_SW_CTDH_CA0_Msk, /**< Switch CA0: Hold cap to Opamp0 non-inverting input. */ CY_CTB_SW_CTD_CHOLD_OA0_POS_ISOLATE_MASK = CTBM_CTD_SW_CTDH_CIS_Msk, /**< Switch CIS: Opamp0 non-inverting input isolation (for hold cap) */ CY_CTB_SW_CTD_CHOLD_LEAKAGE_REDUCTION_MASK = CTBM_CTD_SW_CTDH_ILR_Msk, /**< Switch ILR: Hold cap leakage reduction (drives far side of isolation switch CIS) */ }cy_en_ctb_ctd_switches_t; + /** -* Each Opamp also has a programmable compensation capacitor block, -* that optimizes the stability of the Opamp performance based on output load. -* The compensation cap will be set by the driver based on the Opamp drive strength (1x or 10x) selection. +* Masks for CTB switches that can be controlled by the SAR sequencer. +* These masks are used in \ref Cy_CTB_EnableSarSeqCtrl and \ref Cy_CTB_DisableSarSeqCtrl. +* +* The SAR ADC subsystem supports analog routes through three CTB switches on SARBUS0 and SARBUS1. +* This control allows for pins on the CTB dedicated port to route to the SAR ADC input channels: +* +* - D51: Connects the inverting terminal of OA0 to SARBUS0 +* - D52: Connects the inverting terminal of OA1 to SARBUS0 +* - D62: Connects the inverting terminal of OA1 to SARBUS1 +*/ +typedef enum +{ + CY_CTB_SW_SEQ_CTRL_D51_MASK = CTBM_CTB_SW_SQ_CTRL_P2_SQ_CTRL23_Msk, /**< Enable SAR sequencer control of the D51 switch */ + CY_CTB_SW_SEQ_CTRL_D52_D62_MASK = CTBM_CTB_SW_SQ_CTRL_P3_SQ_CTRL23_Msk, /**< Enable SAR sequencer control of the D52 and D62 switches */ + CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK = CTBM_CTB_SW_SQ_CTRL_P2_SQ_CTRL23_Msk | CTBM_CTB_SW_SQ_CTRL_P3_SQ_CTRL23_Msk, /**< Enable SAR sequency control of all three switches */ +}cy_en_ctb_switch_sar_seq_t; + +/** +* Each opamp also has a programmable compensation capacitor block, +* that optimizes the stability of the opamp performance based on output load. +* The compensation cap will be set by the driver based on the opamp drive strength (1x or 10x) selection. */ typedef enum { @@ -585,7 +642,7 @@ typedef enum }cy_en_ctb_compensation_cap_t; /** Enable or disable the gain booster. -* The gain booster will be set by the driver based on the Opamp drive strength (1x or 10x) selection. +* The gain booster will be set by the driver based on the opamp drive strength (1x or 10x) selection. */ typedef enum { @@ -598,9 +655,9 @@ typedef enum * To perform a sample or a hold, a preparation step must first be executed to * open the required switches. * -* -# Call \ref Cy_CTB_DACSampleAndHold with CY_CTB_SH_PREPARE_SAMPLE or CY_CTB_SH_PREPARE_HOLD +* -# Call \ref Cy_CTB_DACSampleAndHold with \ref CY_CTB_SH_PREPARE_SAMPLE or \ref CY_CTB_SH_PREPARE_HOLD * -# Enable or disable CTDAC output -* -# Call \ref Cy_CTB_DACSampleAndHold with CY_CTB_SH_SAMPLE or CY_CTB_SH_HOLD +* -# Call \ref Cy_CTB_DACSampleAndHold with \ref CY_CTB_SH_SAMPLE or \ref CY_CTB_SH_HOLD */ typedef enum { @@ -662,8 +719,7 @@ typedef enum { * Configuration structure to set up the entire CTB to be used with \ref Cy_CTB_Init. */ typedef struct { - cy_en_ctb_deep_sleep_t deepSleep; /**< Enable or disable the CTDAC during Deep Sleep */ - bool enable; /**< Enable hardware after initialization. If disabled, call \ref Cy_CTB_Enable after initialization */ + cy_en_ctb_deep_sleep_t deepSleep; /**< Enable or disable the CTB during Deep Sleep */ /* Opamp0 configuration */ cy_en_ctb_power_t oa0Power; /**< Opamp0 power mode: off, low, medium, or high */ @@ -693,12 +749,11 @@ typedef struct { }cy_stc_ctb_config_t; /** -* This configuration structure is used to initialize only one Opamp of the CTB +* This configuration structure is used to initialize only one opamp of the CTB * without impacting analog routing. This structure is used with \ref Cy_CTB_OpampInit. */ typedef struct { - cy_en_ctb_deep_sleep_t deepSleep; /**< Enable or disable the CTDAC during Deep Sleep */ - bool enable; /**< Enable hardware after initialization. If disabled, call \ref Cy_CTB_Enable after initialization */ + cy_en_ctb_deep_sleep_t deepSleep; /**< Enable or disable the CTB during Deep Sleep */ /* Opamp configuration */ cy_en_ctb_power_t oaPower; /**< Opamp power mode: off, low, medium, or high */ @@ -714,11 +769,11 @@ typedef struct { /** This configuration structure is used to quickly initialize Opamp0 for the most commonly used configurations. * * Other configuration options are set to: -* - .oa0Pump = CY_CTB_PUMP_ENABLE -* - .oa0CompEdge = CY_CTB_COMP_EDGE_BOTH -* - .oa0CompLevel = CY_CTB_COMP_DSI_TRIGGER_OUT_PULSE -* - .oa0CompBypass = CY_CTB_COMP_BYPASS_SYNC -* - .oa0CompHyst = CY_CTB_COMP_HYST_10MV +* - .oa0Pump = \ref CY_CTB_PUMP_ENABLE +* - .oa0CompEdge = \ref CY_CTB_COMP_EDGE_BOTH +* - .oa0CompLevel = \ref CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL +* - .oa0CompBypass = \ref CY_CTB_COMP_BYPASS_SYNC +* - .oa0CompHyst = \ref CY_CTB_COMP_HYST_10MV * - .oa0CompIntrEn = true */ typedef struct @@ -732,11 +787,11 @@ typedef struct /** This configuration structure is used to quickly initialize Opamp1 for the most commonly used configurations. * * Other configuration options are set to: -* - .oa1Pump = CY_CTB_PUMP_ENABLE -* - .oa1CompEdge = CY_CTB_COMP_EDGE_BOTH -* - .oa1CompLevel = CY_CTB_COMP_DSI_TRIGGER_OUT_PULSE -* - .oa1CompBypass = CY_CTB_COMP_BYPASS_SYNC -* - .oa1CompHyst = CY_CTB_COMP_HYST_10MV +* - .oa1Pump = \ref CY_CTB_PUMP_ENABLE +* - .oa1CompEdge = \ref CY_CTB_COMP_EDGE_BOTH +* - .oa1CompLevel = \ref CY_CTB_COMP_DSI_TRIGGER_OUT_LEVEL +* - .oa1CompBypass = \ref CY_CTB_COMP_BYPASS_SYNC +* - .oa1CompHyst = \ref CY_CTB_COMP_HYST_10MV * - .oa1CompIntrEn = true */ typedef struct @@ -752,12 +807,6 @@ typedef struct /** \addtogroup group_ctb_globals * \{ -* The \ref Cy_CTB_FastInit function allows for fast and easy initialization of the CTB -* based on commonly used configurations. Only routing switches required for -* the selected mode are configured, leaving final input and output connections -* to the user. Additional use modes are provided to easily configure the CTB as -* an output buffer or reference buffer for the CTDAC. These modes are used -* along with the CTDAC PDL driver. */ /*************************************** * Global Variables @@ -775,7 +824,7 @@ extern const cy_stc_ctb_fast_config_oa0_t Cy_CTB_Fast_Opamp0_Unused; */ extern const cy_stc_ctb_fast_config_oa0_t Cy_CTB_Fast_Opamp0_Comp; -/** Configure Opamp0 as an Opamp with 1x drive. No routing is configured. +/** Configure Opamp0 as an opamp with 1x drive. No routing is configured. * * \image html ctb_fast_config_opamp1x.png * \image latex ctb_fast_config_opamp1x.png width=100px @@ -784,7 +833,7 @@ extern const cy_stc_ctb_fast_config_oa0_t Cy_CTB_Fast_Opamp0_Comp; */ extern const cy_stc_ctb_fast_config_oa0_t Cy_CTB_Fast_Opamp0_Opamp1x; -/** Configure Opamp0 as an Opamp with 10x drive. No routing is configured. +/** Configure Opamp0 as an opamp with 10x drive. No routing is configured. * * \image html ctb_fast_config_opamp10x.png * \image latex ctb_fast_config_opamp10x.png width=100px @@ -794,7 +843,7 @@ extern const cy_stc_ctb_fast_config_oa0_t Cy_CTB_Fast_Opamp0_Opamp1x; extern const cy_stc_ctb_fast_config_oa0_t Cy_CTB_Fast_Opamp0_Opamp10x; /** Configure Opamp0 as one stage of a differential amplifier. -* The Opamp is in 10x drive and the switches shown are closed. +* The opamp is in 10x drive and the switches shown are closed. * * \image html ctb_fast_config_oa0_diffamp.png * \image latex ctb_fast_config_oa0_diffamp.png width=100px @@ -845,7 +894,7 @@ extern const cy_stc_ctb_fast_config_oa1_t Cy_CTB_Fast_Opamp1_Unused; */ extern const cy_stc_ctb_fast_config_oa1_t Cy_CTB_Fast_Opamp1_Comp; -/** Configure Opamp1 as an Opamp with 1x drive. No routing is configured. +/** Configure Opamp1 as an opamp with 1x drive. No routing is configured. * * \image html ctb_fast_config_opamp1x.png * \image latex ctb_fast_config_opamp1x.png width=100px @@ -864,7 +913,7 @@ extern const cy_stc_ctb_fast_config_oa1_t Cy_CTB_Fast_Opamp1_Opamp1x; extern const cy_stc_ctb_fast_config_oa1_t Cy_CTB_Fast_Opamp1_Opamp10x; /** Configure Opamp1 as one stage of a differential amplifier. -* The Opamp is in 10x drive and the switches shown are closed. +* The opamp is in 10x drive and the switches shown are closed. * * \image html ctb_fast_config_oa1_diffamp.png * \image latex ctb_fast_config_oa1_diffamp.png width=100px @@ -960,7 +1009,7 @@ uint32_t Cy_CTB_CompGetStatus(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compN /** * \addtogroup group_ctb_functions_trim -* These are advanced functions for trimming the offset and slope of the Opamps. +* These are advanced functions for trimming the offset and slope of the opamps. * Most users do not need to call these functions and can use the factory trimmed values. * \{ */ @@ -977,7 +1026,9 @@ uint32_t Cy_CTB_OpampGetSlope(const CTBM_Type *base, cy_en_ctb_opamp_sel_t opamp */ void Cy_CTB_SetAnalogSwitch(CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_ctb_switch_state_t state); uint32_t Cy_CTB_GetAnalogSwitch(const CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect); -void Cy_CTB_OpenAllSwitches(CTBM_Type *base); +__STATIC_INLINE void Cy_CTB_OpenAllSwitches(CTBM_Type *base); +__STATIC_INLINE void Cy_CTB_EnableSarSeqCtrl(CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask); +__STATIC_INLINE void Cy_CTB_DisableSarSeqCtrl(CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask); /** \} */ /** @@ -987,7 +1038,7 @@ void Cy_CTB_OpenAllSwitches(CTBM_Type *base); */ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatus(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); __STATIC_INLINE void Cy_CTB_ClearInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); -__STATIC_INLINE void Cy_CTB_SetSwInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); +__STATIC_INLINE void Cy_CTB_SetInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); __STATIC_INLINE void Cy_CTB_SetInterruptMask(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); __STATIC_INLINE uint32_t Cy_CTB_GetInterruptMask(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatusMasked(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum); @@ -995,7 +1046,7 @@ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatusMasked(const CTBM_Type *base, /** * \addtogroup group_ctb_functions_aref -* This set of functions impacts all Opamps on the chip. +* This set of functions impacts all opamps on the chip. * Notice how some of these functions do not take a base address input. * When calling \ref Cy_CTB_SetCurrentMode for a CTB instance on the device, * it should be called for all other CTB instances as well. This is because @@ -1018,7 +1069,7 @@ __STATIC_INLINE void Cy_CTB_DisableRedirect(void); * Function Name: Cy_CTB_Enable ****************************************************************************//** * -* Powers up the hardware block necessary for the operation of the CTB. +* Power up the CTB hardware block. * * \param base * Pointer to structure describing registers @@ -1035,7 +1086,7 @@ __STATIC_INLINE void Cy_CTB_Enable(CTBM_Type *base) * Function Name: Cy_CTB_Disable ****************************************************************************//** * -* Powers down the hardware block necessary for the operation of the CTB. +* Power down the CTB hardware block. * * \param base * Pointer to structure describing registers @@ -1050,6 +1101,100 @@ __STATIC_INLINE void Cy_CTB_Disable(CTBM_Type *base) /** \} */ +/** +* \addtogroup group_ctb_functions_switches +* \{ +*/ + +/******************************************************************************* +* Function Name: Cy_CTB_OpenAllSwitches +****************************************************************************//** +* +* Open all the switches and disable all hardware (SAR Sequencer and DSI) control of the switches. +* Primarily used as a quick method of re-configuring all analog connections +* that are sparsely closed. +* +* \param base +* Pointer to structure describing registers +* +* \return None +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_OPEN_ALL_SWITCHES +* +*******************************************************************************/ +__STATIC_INLINE void Cy_CTB_OpenAllSwitches(CTBM_Type *base) +{ + base->OA0_SW_CLEAR = CY_CTB_DEINIT_OA0_SW; + base->OA1_SW_CLEAR = CY_CTB_DEINIT_OA1_SW; + base->CTD_SW_CLEAR = CY_CTB_DEINIT_CTD_SW; + base->CTB_SW_DS_CTRL = CY_CTB_DEINIT; + base->CTB_SW_SQ_CTRL = CY_CTB_DEINIT; +} + +/******************************************************************************* +* Function Name: Cy_CTB_EnableSarSeqCtrl +****************************************************************************//** +* +* Enable SAR sequencer control of specified switch(es). +* +* This allows the SAR ADC to use routes through the CTB when configuring its channels. +* +* There are three switches in the CTB that can be enabled by the SAR sequencer. +* - D51: This switch connects the negative input of Opamp0 to the SARBUS0 +* - D52: This switch connects the positive input of Opamp1 to the SARBUS0 +* - D62: This switch connects the positive input of Opamp1 to the SARBUS1 +* +* \param base +* Pointer to structure describing registers +* +* \param switchMask +* The switch or switches in which to enable SAR sequencer control. +* Use an enumerated value from \ref cy_en_ctb_switch_sar_seq_t. +* +* \return None +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_ENABLE_SAR_SEQ_CTRL +* +*******************************************************************************/ +__STATIC_INLINE void Cy_CTB_EnableSarSeqCtrl(CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask) +{ + CY_ASSERT_L3(CY_CTB_SARSEQCTRL(switchMask)); + + base->CTB_SW_SQ_CTRL |= (uint32_t) switchMask; +} + +/******************************************************************************* +* Function Name: Cy_CTB_DisableSarSeqCtrl +****************************************************************************//** +* +* Disable SAR sequencer control of specified switch(es). +* +* \param base +* Pointer to structure describing registers +* +* \param switchMask +* The switch or switches in which to disable SAR sequencer control. +* Use an enumerated value from \ref cy_en_ctb_switch_sar_seq_t. +* +* \return None +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_DISABLE_SAR_SEQ_CTRL +* +*******************************************************************************/ +__STATIC_INLINE void Cy_CTB_DisableSarSeqCtrl(CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask) +{ + CY_ASSERT_L3(CY_CTB_SARSEQCTRL(switchMask)); + + base->CTB_SW_SQ_CTRL &= ~((uint32_t) switchMask); +} +/** \} */ + /** * \addtogroup group_ctb_functions_interrupts * \{ @@ -1059,22 +1204,26 @@ __STATIC_INLINE void Cy_CTB_Disable(CTBM_Type *base) * Function Name: Cy_CTB_GetInterruptStatus ****************************************************************************//** * -* Returns status of the interrupt that happens when the configured comparator +* Return the status of the interrupt when the configured comparator * edge is detected. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * -* \return Interrupt status -* 0 - Edge was not detected -* Non-zero - Configured edge type was detected -* -* If compNum is CY_CTB_OPAMP_BOTH, cast the returned status -* to cy_en_ctb_opamp_sel_t to determine which comparator edge (or both) +* \return +* The interrupt status. +* If compNum is \ref CY_CTB_OPAMP_BOTH, cast the returned status +* to \ref cy_en_ctb_opamp_sel_t to determine which comparator edge (or both) * was detected. +* - 0: Edge was not detected +* - Non-zero: Configured edge type was detected +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm0p.c SNIPPET_COMP_GETINTERRUPTSTATUS * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatus(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) @@ -1088,7 +1237,7 @@ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatus(const CTBM_Type *base, cy_en_ * Function Name: Cy_CTB_ClearInterrupt ****************************************************************************//** * -* Clears the CTB comparator triggered interrupt. +* Clear the CTB comparator triggered interrupt. * The interrupt must be cleared with this function so that the hardware * can set subsequent interrupts and those interrupts can be forwarded * to the interrupt controller, if enabled. @@ -1097,7 +1246,7 @@ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatus(const CTBM_Type *base, cy_en_ * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \return None * @@ -1107,24 +1256,27 @@ __STATIC_INLINE void Cy_CTB_ClearInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_ CY_ASSERT_L3(CY_CTB_OPAMPNUM(compNum)); base->INTR = (uint32_t) compNum; + + /* Dummy read for buffered writes. */ + (void) base->INTR; } /******************************************************************************* -* Function Name: Cy_CTB_SetSwInterrupt +* Function Name: Cy_CTB_SetInterrupt ****************************************************************************//** * -* Forces the CTB interrupt to trigger using software. +* Force the CTB interrupt to trigger using software. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * * \return None * *******************************************************************************/ -__STATIC_INLINE void Cy_CTB_SetSwInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) +__STATIC_INLINE void Cy_CTB_SetInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) { CY_ASSERT_L3(CY_CTB_OPAMPNUM(compNum)); @@ -1142,13 +1294,15 @@ __STATIC_INLINE void Cy_CTB_SetSwInterrupt(CTBM_Type *base, cy_en_ctb_opamp_sel_ * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_NONE, CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH -* -* Calling this function with CY_CTB_OPAMP_NONE will disable all -* interrupt requests. +* \ref CY_CTB_OPAMP_NONE, \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH. +* Calling this function with CY_CTB_OPAMP_NONE will disable all interrupt requests. * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_INTERRUPT_MASK +* *******************************************************************************/ __STATIC_INLINE void Cy_CTB_SetInterruptMask(CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) { @@ -1161,7 +1315,7 @@ __STATIC_INLINE void Cy_CTB_SetInterruptMask(CTBM_Type *base, cy_en_ctb_opamp_se * Function Name: Cy_CTB_GetInterruptMask ****************************************************************************//** * -* Returns whether the CTB comparator edge interrupt output is +* Return whether the CTB comparator edge interrupt output is * forwarded to the CPU interrupt controller as configured by * \ref Cy_CTB_SetInterruptMask. * @@ -1169,15 +1323,19 @@ __STATIC_INLINE void Cy_CTB_SetInterruptMask(CTBM_Type *base, cy_en_ctb_opamp_se * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * -* \return Interrupt mask -* 0 - Interrupt output not forwarded to interrupt controller -* Non-zero - Interrupt output forwarded to interrupt controller -* -* If compNum is CY_CTB_OPAMP_BOTH, cast the returned mask -* to cy_en_ctb_opamp_sel_t to determine which comparator interrupt +* \return +* The interrupt mask. +* If compNum is \ref CY_CTB_OPAMP_BOTH, cast the returned mask +* to \ref cy_en_ctb_opamp_sel_t to determine which comparator interrupt * output (or both) is forwarded. +* - 0: Interrupt output not forwarded to interrupt controller +* - Non-zero: Interrupt output forwarded to interrupt controller +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_GET_INTERRUPT_MASK * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptMask(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) @@ -1191,22 +1349,21 @@ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptMask(const CTBM_Type *base, cy_en_ct * Function Name: Cy_CTB_GetInterruptStatusMasked ****************************************************************************//** * -* Returns the CTB comparator edge output interrupt state after being masked. +* Return the CTB comparator edge output interrupt state after being masked. * This is the bitwise AND of \ref Cy_CTB_GetInterruptStatus and \ref Cy_CTB_GetInterruptMask. * * \param base * Pointer to structure describing registers * * \param compNum -* CY_CTB_OPAMP_0, CY_CTB_OPAMP_1, or CY_CTB_OPAMP_BOTH +* \ref CY_CTB_OPAMP_0, \ref CY_CTB_OPAMP_1, or \ref CY_CTB_OPAMP_BOTH * -* \return Interrupt masked -* 0 - Edge not detected or not masked -* Non-zero - Configured edge type detected and masked -* -* If compNum is CY_CTB_OPAMP_BOTH, cast the returned value -* to cy_en_ctb_opamp_sel_t to determine which comparator interrupt +* \return +* If compNum is \ref CY_CTB_OPAMP_BOTH, cast the returned value +* to \ref cy_en_ctb_opamp_sel_t to determine which comparator interrupt * output (or both) is detected and masked. +* - 0: Configured edge not detected or not masked +* - Non-zero: Configured edge type detected and masked * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatusMasked(const CTBM_Type *base, cy_en_ctb_opamp_sel_t compNum) @@ -1226,7 +1383,7 @@ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatusMasked(const CTBM_Type *base, * Function Name: Cy_CTB_SetIptatLevel ****************************************************************************//** * -* Set the IPTAT level to 1uA or 100nA. The IPTAT generator is used by the CTB +* Set the IPTAT reference level to 1 uA or 100 nA. The IPTAT generator is used by the CTB * for slope offset drift. * * \param iptat @@ -1234,6 +1391,10 @@ __STATIC_INLINE uint32_t Cy_CTB_GetInterruptStatusMasked(const CTBM_Type *base, * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_IPTAT_LEVEL +* *******************************************************************************/ __STATIC_INLINE void Cy_CTB_SetIptatLevel(cy_en_ctb_iptat_t iptat) { @@ -1246,13 +1407,15 @@ __STATIC_INLINE void Cy_CTB_SetIptatLevel(cy_en_ctb_iptat_t iptat) * Function Name: Cy_CTB_SetClkPumpSource ****************************************************************************//** * -* Set the clock source for the CTB charge pump. The clock can come from: -* - a dedicated divider off of one of the CLK_PATH in the SRSS +* Set the clock source for both charge pumps in the CTB. Recall that each opamp +* has its own charge pump. The clock can come from: +* +* - A dedicated divider off of one of the CLK_PATH in the SRSS. * Call the following functions to configure the pump clock from the SRSS: * - \ref Cy_SysClk_ClkPumpSetSource * - \ref Cy_SysClk_ClkPumpSetDivider * - \ref Cy_SysClk_ClkPumpEnable -* - one of the Peri Clock dividers +* - One of the Peri Clock dividers. * Call the following functions to configure a Peri Clock divider as the * pump clock: * - \ref Cy_SysClk_PeriphAssignDivider with the IP block set to PCLK_PASS_CLOCK_PUMP_PERI @@ -1260,10 +1423,19 @@ __STATIC_INLINE void Cy_CTB_SetIptatLevel(cy_en_ctb_iptat_t iptat) * - \ref Cy_SysClk_PeriphEnableDivider * * \param clkPump -* Value from enum \ref cy_en_ctb_clk_pump_source_t +* Clock source selection (SRSS or PeriClk) for the pump. Select a value from +* \ref cy_en_ctb_clk_pump_source_t * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_CLK_PUMP_SOURCE_SRSS +* +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_SET_CLK_PUMP_SOURCE_PERI +* *******************************************************************************/ __STATIC_INLINE void Cy_CTB_SetClkPumpSource(cy_en_ctb_clk_pump_source_t clkPump) { @@ -1292,11 +1464,15 @@ __STATIC_INLINE void Cy_CTB_SetClkPumpSource(cy_en_ctb_clk_pump_source_t clkPump * should be used when the IPTAT bias level is set to 100 nA * (see \ref Cy_CTB_SetIptatLevel). * -* Without the IPTAT reference, the CTB cannot compensate for the slope of +* When the CTB.IPTAT is HiZ, the CTB cannot compensate for the slope of * the offset across temperature. * * \return None * +* \funcusage +* +* \snippet ctb_sut_01.cydsn/main_cm4.c CTB_SNIPPET_ENABLE_REDIRECT +* *******************************************************************************/ __STATIC_INLINE void Cy_CTB_EnableRedirect(void) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctdac/cy_ctdac.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctdac/cy_ctdac.c similarity index 82% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctdac/cy_ctdac.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctdac/cy_ctdac.c index 796094d797..cc77ee2df8 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctdac/cy_ctdac.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctdac/cy_ctdac.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_ctdac.c -* \version 1.0 +* \version 1.0.1 * * Provides the public functions for the API for the CTDAC driver. * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -58,8 +58,12 @@ const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_OA1Ref_BufferedOut = * \param config * Pointer to structure containing configuration data * -* \return cy_en_ctdac_status_t -* Status of initialization, CY_CTDAC_SUCCESS or CY_CTDAC_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTDAC_SUCCESS or \ref CY_CTDAC_BAD_PARAM +* +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_INIT_CUSTOM * *******************************************************************************/ cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t *config) @@ -116,9 +120,6 @@ cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t /* Handle the output mode */ ctdacCtrl |= (uint32_t)config->outputMode; - /* Handle enable bit */ - ctdacCtrl |= ((uint32_t)config->enable) << CTDAC_CTDAC_CTRL_ENABLED_Pos; - /* Handle the reference source */ switch(config->refSource) { @@ -171,8 +172,8 @@ cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t * * Reset CTDAC registers back to power on reset defaults. * -* Does not disable or configure the clock. Call \ref Cy_CTDAC_Init or \ref Cy_CTDAC_FastInit -* to configure the CTDAC and clock. +* \note +* Does not disable the clock. * * \param base * Pointer to structure describing registers @@ -181,8 +182,12 @@ cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t * If true, all switches are reset to their default state. * If false, switch registers are untouched. * -* \return cy_en_ctdac_status_t -* Status of initialization, CY_CTDAC_SUCCESS, or CY_CTDAC_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTDAC_SUCCESS, or \ref CY_CTDAC_BAD_PARAM +* +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_DEINIT * *******************************************************************************/ cy_en_ctdac_status_t Cy_CTDAC_DeInit(CTDAC_Type *base, bool deInitRouting) @@ -217,39 +222,61 @@ cy_en_ctdac_status_t Cy_CTDAC_DeInit(CTDAC_Type *base, bool deInitRouting) * Function Name: Cy_CTDAC_FastInit ****************************************************************************//** * -* Initializes the CTDAC to one of the common use modes. -* These provide a quick and easy method of configuring the CTDAC when using +* Initialize the CTDAC to one of the common use modes. +* This function provides a quick and easy method of configuring the CTDAC when using * the PDL driver for device configuration. * * The other configuration options are set to: -* - .formatMode = CY_CTDAC_FORMAT_UNSIGNED -* - .updateMode = CY_CTDAC_UPDATE_BUFFERED_WRITE -* - .deglitchMode = CY_CTDAC_DEGLITCHMODE_NONE -* - .outputMode = CY_CTDAC_OUTPUT_VALUE -* - .deepSleep = CY_CTDAC_DEEPSLEEP_DISABLE -* - .deglitchCycles = CY_CTDAC_DEINIT -* - .value = CY_CTDAC_UNSIGNED_MID_CODE_VALUE -* - .nextValue = CY_CTDAC_UNSIGNED_MID_CODE_VALUE +* - .formatMode = \ref CY_CTDAC_FORMAT_UNSIGNED +* - .updateMode = \ref CY_CTDAC_UPDATE_BUFFERED_WRITE +* - .deglitchMode = \ref CY_CTDAC_DEGLITCHMODE_NONE +* - .outputMode = \ref CY_CTDAC_OUTPUT_VALUE +* - .deepSleep = \ref CY_CTDAC_DEEPSLEEP_DISABLE +* - .deglitchCycles = \ref CY_CTDAC_DEINIT +* - .value = \ref CY_CTDAC_UNSIGNED_MID_CODE_VALUE +* - .nextValue = \ref CY_CTDAC_UNSIGNED_MID_CODE_VALUE * - .enableInterrupt = true * - .configClock = true -* - .dividerType = CY_CTDAC_FAST_CLKCFG_TYPE -* - .dividerNum = CY_CTDAC_FAST_CLKCFG_NUM -* - .dividerInitValue = CY_CTDAC_FAST_CLKCFG_DIV -* - .dividerFracValue = CY_CTDAC_DEINIT +* - .dividerType = \ref CY_CTDAC_FAST_CLKCFG_TYPE +* - .dividerNum = \ref CY_CTDAC_FAST_CLKCFG_NUM +* - .dividerInitValue = \ref CY_CTDAC_FAST_CLKCFG_DIV +* - .dividerFracValue = \ref CY_CTDAC_DEINIT +* +* A separate call to \ref Cy_CTDAC_Enable is needed to turn on the hardware. * * \param base * Pointer to structure describing registers * * \param config -* Pointer to structure containing configuration data for quick initialization -* Use one of the provided structures or define your own. +* Pointer to structure containing configuration data for quick initialization. +* Define your own or use one of the provided structures: * - \ref Cy_CTDAC_Fast_VddaRef_UnbufferedOut * - \ref Cy_CTDAC_Fast_VddaRef_BufferedOut * - \ref Cy_CTDAC_Fast_OA1Ref_UnbufferedOut * - \ref Cy_CTDAC_Fast_OA1Ref_BufferedOut * -* \return cy_en_ctdac_status_t -* Status of initialization, CY_CTDAC_SUCCESS or CY_CTDAC_BAD_PARAM +* \return +* Status of initialization, \ref CY_CTDAC_SUCCESS or \ref CY_CTDAC_BAD_PARAM +* +* \funcusage +* +* The following code snippets configures VDDA as the reference source and +* routes the output directly to Pin 6 (unbuffered). +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_FAST_INIT +* +* \funcusage +* +* The following code snippet shows how the CTDAC and CTB blocks can +* quickly be configured to work together. The code +* configures the CTDAC to use a buffered output, +* a buffered reference source from the internal bandgap voltage, and closes +* all required analog routing switches. +* +* \image html ctdac_fast_init_funcusage.png +* \image latex ctdac_fast_init_funcusage.png +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_FAST_INIT_CTB * *******************************************************************************/ cy_en_ctdac_status_t Cy_CTDAC_FastInit(CTDAC_Type *base, const cy_stc_ctdac_fast_config_t *config) @@ -311,7 +338,7 @@ cy_en_ctdac_status_t Cy_CTDAC_FastInit(CTDAC_Type *base, const cy_stc_ctdac_fast base->CTDAC_VAL = CY_CTDAC_UNSIGNED_MID_CODE_VALUE; base->CTDAC_VAL_NXT = CY_CTDAC_UNSIGNED_MID_CODE_VALUE; - /* For fast configuration, the DAC clock is the Peri clock divided by 100 */ + /* For fast configuration, the DAC clock is the Peri clock divided by 100. */ Cy_CTDAC_ConfigureClock(CY_CTDAC_UPDATE_BUFFERED_WRITE, CY_CTDAC_FAST_CLKCFG_TYPE, CY_CTDAC_FAST_CLKCFG_NUM, CY_CTDAC_FAST_CLKCFG_DIV, CY_CTDAC_DEINIT); base->CTDAC_CTRL = ctdacCtrl; @@ -384,7 +411,7 @@ static void Cy_CTDAC_ConfigureClock(cy_en_ctdac_update_t updateMode, cy_en_divid * Function Name: Cy_CTDAC_SetSignMode ****************************************************************************//** * -* Sets whether to interpret the DAC value as signed or unsigned. +* Set whether to interpret the DAC value as signed or unsigned. * In unsigned mode, the DAC value register is used without any decoding. * In signed mode, the MSB is inverted by adding 0x800 to the DAC value. * This converts the lowest signed number, 0x800, to the lowest unsigned @@ -398,6 +425,10 @@ static void Cy_CTDAC_ConfigureClock(cy_en_ctdac_update_t updateMode, cy_en_divid * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_SIGN_MODE +* *******************************************************************************/ void Cy_CTDAC_SetSignMode(CTDAC_Type *base, cy_en_ctdac_format_t formatMode) { @@ -415,17 +446,20 @@ void Cy_CTDAC_SetSignMode(CTDAC_Type *base, cy_en_ctdac_format_t formatMode) * Function Name: Cy_CTDAC_SetDeepSleepMode ****************************************************************************//** * -* Sets whether to allow the DAC hardware to continue to stay powered in -* Deep Sleep mode. +* Enable or disable the DAC hardware operation in Deep Sleep mode. * * \param base * Pointer to structure describing registers * * \param deepSleep -* Enabled or disabled. See \ref cy_en_ctdac_deep_sleep_t for values. +* Enable or disable Deep Sleep operation. Select value from \ref cy_en_ctdac_deep_sleep_t. * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_DEEPSLEEP_MODE +* *******************************************************************************/ void Cy_CTDAC_SetDeepSleepMode(CTDAC_Type *base, cy_en_ctdac_deep_sleep_t deepSleep) { @@ -442,16 +476,27 @@ void Cy_CTDAC_SetDeepSleepMode(CTDAC_Type *base, cy_en_ctdac_deep_sleep_t deepSl * Function Name: Cy_CTDAC_SetOutputMode ****************************************************************************//** * -* Set the output mode to one of the supported options. +* Set the output mode of the CTDAC: +* - \ref CY_CTDAC_OUTPUT_HIGHZ : Disable the output +* - \ref CY_CTDAC_OUTPUT_VALUE : Enable the output and drive the value +* stored in the CTDAC_VAL register. +* - \ref CY_CTDAC_OUTPUT_VALUE_PLUS1 : Enable the output and drive the +* value stored in the CTDAC_VAL register plus 1. +* - \ref CY_CTDAC_OUTPUT_VSSA : Output pulled to VSSA through 1.1 MOhm (typ) resistor. +* - \ref CY_CTDAC_OUTPUT_VREF : Output pulled to VREF through 1.1 MOhm (typ) resistor. * * \param base * Pointer to structure describing registers * * \param outputMode -* Output drive mode. See \ref cy_en_ctdac_output_mode_t for values. +* Select a value from \ref cy_en_ctdac_output_mode_t. * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_OUTPUT_MODE +* *******************************************************************************/ void Cy_CTDAC_SetOutputMode(CTDAC_Type *base, cy_en_ctdac_output_mode_t outputMode) { @@ -469,7 +514,8 @@ void Cy_CTDAC_SetOutputMode(CTDAC_Type *base, cy_en_ctdac_output_mode_t outputMo * Function Name: Cy_CTDAC_SetDeglitchMode ****************************************************************************//** * -* Set the deglitch mode or disable deglitching completely. +* Enable deglitching on the unbuffered path, buffered path, both, or +* disable deglitching. The deglitch mode should match the configured output path. * * \param base * Pointer to structure describing registers @@ -479,6 +525,10 @@ void Cy_CTDAC_SetOutputMode(CTDAC_Type *base, cy_en_ctdac_output_mode_t outputMo * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_DEGLITCH_MODE +* *******************************************************************************/ void Cy_CTDAC_SetDeglitchMode(CTDAC_Type *base, cy_en_ctdac_deglitch_t deglitchMode) { @@ -497,7 +547,10 @@ void Cy_CTDAC_SetDeglitchMode(CTDAC_Type *base, cy_en_ctdac_deglitch_t deglitchM ****************************************************************************//** * * Set the number of deglitch cycles (0 to 63) that will be used. -* To calculate the deglitch time, (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ. +* To calculate the deglitch time: +* +* (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ +* * The optimal deglitch time is 700 ns. * * \param base @@ -508,6 +561,10 @@ void Cy_CTDAC_SetDeglitchMode(CTDAC_Type *base, cy_en_ctdac_deglitch_t deglitchM * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_DEGLITCH_CYCLES +* *******************************************************************************/ void Cy_CTDAC_SetDeglitchCycles(CTDAC_Type *base, uint32_t deglitchCycles) { @@ -531,10 +588,14 @@ void Cy_CTDAC_SetDeglitchCycles(CTDAC_Type *base, uint32_t deglitchCycles) * Pointer to structure describing registers * * \param refSource -* The reference source. See \ref cy_en_ctdac_ref_source_t for values. +* The reference source. Select a value from \ref cy_en_ctdac_ref_source_t. * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_REF +* *******************************************************************************/ void Cy_CTDAC_SetRef(CTDAC_Type *base, cy_en_ctdac_ref_source_t refSource) { @@ -558,27 +619,29 @@ void Cy_CTDAC_SetRef(CTDAC_Type *base, cy_en_ctdac_ref_source_t refSource) * Function Name: Cy_CTDAC_SetAnalogSwitch ****************************************************************************//** * -* Provides firmware control of the CTDAC switches. Each call to this function +* Provide firmware control of the CTDAC switches. Each call to this function * can open a set of switches or close a set of switches. * -* This is an advanced function. The switches will be managed by the reference -* source and output mode selections when initializing the hardware. +* \note +* The switches are configured by the reference +* source and output mode selections during initialization. * * \param base * Pointer to structure describing registers * * \param switchMask * The mask of the switches to either open or close. -* The switches can be found in the \ref cy_en_ctdac_switches_t enum. -* -* For example, to close both CVD and CO6 switches: -* switchMask = CY_CTDAC_SWITCH_CVD_MASK | CY_CTDAC_SWITCH_CO6_MASK; +* Select one or more values from \ref cy_en_ctdac_switches_t and "OR" them together. * * \param state -* Open or close the switches, see enum \ref cy_en_ctdac_switch_state_t. +* Open or close the switche(s). Select a value from \ref cy_en_ctdac_switch_state_t. * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_ANALOG_SWITCH +* *******************************************************************************/ void Cy_CTDAC_SetAnalogSwitch(CTDAC_Type *base, uint32_t switchMask, cy_en_ctdac_switch_state_t state) { @@ -612,13 +675,17 @@ void Cy_CTDAC_SetAnalogSwitch(CTDAC_Type *base, uint32_t switchMask, cy_en_ctdac * \param callbackParams * Pointer to structure of type \ref cy_stc_syspm_callback_params_t * -* \return cy_en_syspm_status_t +* \return * See \ref cy_en_syspm_status_t * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_DEEP_SLEEP_CALLBACK +* *******************************************************************************/ cy_en_syspm_status_t Cy_CTDAC_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) { - /** Static variable preserved between function calls. + /* Static variable preserved between function calls. * Tracks the state of the deglitch mode before sleep so that it can be re-enabled after wakeup */ static uint32_t deglitchModeBeforeSleep; diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctdac/cy_ctdac.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctdac/cy_ctdac.h similarity index 72% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctdac/cy_ctdac.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctdac/cy_ctdac.h index 09ad23cc3a..9b32c4e500 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ctdac/cy_ctdac.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ctdac/cy_ctdac.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_ctdac.h -* \version 1.0 +* \version 1.0.1 * * Header file for the CTDAC driver * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -16,6 +16,26 @@ * \defgroup group_ctdac Continuous Time Digital to Analog Converter (CTDAC) * \{ * The CTDAC driver provides APIs to configure the 12-bit Continuous-Time DAC. +* +* - 12-bit continuous time output +* - 2 us settling time for a 25 pF load when output buffered through Opamp0 of \ref group_ctb "CTB" +* - Can be enabled in Deep Sleep power mode +* - Selectable voltage reference: +* - VDDA +* - Internal analog reference buffered through Opamp1 of \ref group_ctb "CTB" +* - External reference buffered through Opamp1 of \ref group_ctb "CTB" +* - Selectable output paths: +* - Direct DAC output to a pin +* - Buffered DAC output through Opamp0 of \ref group_ctb "CTB" +* - Sample and hold output path through Opamp0 of \ref group_ctb "CTB" +* - Selectable input modes: +* - Unsigned 12-bit mode +* - Virtual signed 12-bit mode +* - Configurable update rate using clock or strobe signal +* - Double buffered DAC voltage control register +* - Interrupt and DMA trigger on DAC buffer empty +* - Configurable as PGA along with Opamp1 of the \ref group_ctb "CTB" +* * The CTDAC generates a 12-bit DAC output voltage from the reference. * The DAC reference can come from VDDA or from any signal buffered through Opamp0 * of the CTB. This can be an external signal through a GPIO or from the internal @@ -29,27 +49,6 @@ * \image html ctdac_block_diagram.png * \image latex ctdac_block_diagram.png * -* Features -* -* - 12-bit continuous time output -* - 2 us settling time for a 25 pF load -* - Can be enabled in Deep Sleep power mode -* - Selectable voltage reference: -* - VDDA -* - Internal analog reference buffered through Opamp1 of CTB -* - External reference buffered through Opamp1 of CTB -* - Selectable output paths: -* - Direct DAC output to a pin -* - Buffered DAC output through Opamp0 of CTB -* - Sample and hold output path through Opamp0 of CTB -* - Selectable input modes: -* - Unsigned 12-bit mode -* - Virtual signed 12-bit mode -* - Configurable update rate using clock or strobe signal -* - Double buffered DAC voltage control register -* - Interrupt and DMA trigger on DAC buffer empty -* - Configurable as PGA along with Opamp1 of the CTB -* * The CTDAC has two switches, CO6 for configuring the output path and * CVD for the reference source. * @@ -65,13 +64,15 @@ * enable the CTB block before enabling the CTDAC block. * * The driver also provides a \ref Cy_CTDAC_FastInit function for fast and easy initialization of the CTDAC. -* There are four configurations that cover the four combinations of the reference and output buffers. +* The driver has pre-defined configuration structures for the four combinations of the reference and output buffers. * * - \ref Cy_CTDAC_Fast_VddaRef_UnbufferedOut * - \ref Cy_CTDAC_Fast_VddaRef_BufferedOut * - \ref Cy_CTDAC_Fast_OA1Ref_UnbufferedOut * - \ref Cy_CTDAC_Fast_OA1Ref_BufferedOut * +* After initialization, call \ref Cy_CTDAC_Enable to enable the hardware. +* * \section group_ctdac_updatemode Update Modes * The CTDAC contains two registers: * -# CTDAC_VAL @@ -80,8 +81,8 @@ * This register is written with \ref Cy_CTDAC_SetValue. * -# CTDAC_VAL_NXT * -* For buffered writes that can be configured to update the DAC at a -* selected periodic rate or with a strobe trigger. +* For buffered writes to update the DAC value at a +* periodic rate or with a strobe trigger input. * This register is written with \ref Cy_CTDAC_SetValueBuffered. * * The update mode is @@ -93,9 +94,9 @@ * This allows control of the buffered update timing from an external source, for example, by another * chip peripheral or from an off-chip source. * -* Direct write +* \subsection group_ctdac_updatemode_direct_write Direct write * -* In this mode, this user writes directly into the CTDAC_VAL register +* In this mode, the user writes directly into the CTDAC_VAL register * using \ref Cy_CTDAC_SetValue. The action of writing to this register * will update the DAC output. This mode does not generate an interrupt * or trigger signal. @@ -105,7 +106,7 @@ * \image html ctdac_update_mode_direct_write.png * \image latex ctdac_update_mode_direct_write.png * -* Buffered write +* \subsection group_ctdac_updatemode_buffered_write Buffered write * * In this mode, the user writes to the CTDAC_VAL_NXT register using * \ref Cy_CTDAC_SetValueBuffered. The rising edge of the clock @@ -113,26 +114,26 @@ * * Whenever data is transferred from the CTDAC_VAL_NXT register, * an interrupt is asserted the same time as the trigger. But while -* the trigger is automatically cleared after two Peri Clock cycles, the +* the trigger is automatically cleared after two PeriClk cycles, the * user must clear the interrupt with \ref Cy_CTDAC_ClearInterrupt. * * \image html ctdac_update_mode_buffered_write.png * \image latex ctdac_update_mode_buffered_write.png * -* Strobe edge sync +* \subsection group_ctdac_updatemode_strobe_edge_sync Strobe edge sync * * In this mode, the user writes to the CTDAC_VAL_NXT register using * \ref Cy_CTDAC_SetValueBuffered. * Each rising edge of the DSI strobe input enables * one subsequent update from the next rising edge of the clock. The DSI -* input must remain high for two Peri Clock cycles and go low for -* another two Peri Clock cycles to allow for the next update. +* input must remain high for two PeriClk cycles and go low for +* another two PeriClk cycles to allow for the next update. * This restricts the DSI strobe input frequency to the PeriClk frequency divided by four. * * \image html ctdac_update_mode_strobe_edge_sync.png * \image latex ctdac_update_mode_strobe_edge_sync.png * -* Strobe edge immediate +* \subsection group_ctdac_updatemode_strobe_edge_immediate Strobe edge immediate * * In this mode, the user writes to the CTDAC_VAL_NXT register using * \ref Cy_CTDAC_SetValueBuffered. @@ -143,7 +144,7 @@ * \image html ctdac_update_mode_strobe_edge_immediate.png * \image latex ctdac_update_mode_strobe_edge_immediate.png * -* Strobe level +* \subsection group_ctdac_updatemode_strobe_level Strobe level * * In this mode, the user writes to the CTDAC_VAL_NXT register using * \ref Cy_CTDAC_SetValueBuffered. @@ -155,35 +156,127 @@ * \image html ctdac_update_mode_strobe_level.png * \image latex ctdac_update_mode_strobe_level.png * -* \section group_ctdac_trigger DMA Trigger -* When data is transferred from the CTDAC_VAL_NXT to the CTDAC_VAL register -* an interrupt and an output trigger signal are generated. -* The trigger signal can be routed to DMA using the \ref group_trigmux. +* \section group_ctdac_dacmode DAC Modes +* +* The format of code stored in the CTDAC_VAL register can either be unsigned +* or signed two's complemented. +* Only the first 12 bits of the register are used by the DAC so there is +* no need for sign extension. With the signed format, the DAC decodes +* the code in the register by adding 0x800. +* The DAC can output the register value or the register value plus 1 (see \ref Cy_CTDAC_SetOutputMode). +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
12-bit unsigned code12-bit two's complement signed codeVout (for \ref CY_CTDAC_OUTPUT_VALUE )Vout (for \ref CY_CTDAC_OUTPUT_VALUE_PLUS1 )
0x0000x8000Vref/4096
0x8000x0000.5 * VrefVref * 2049 / 4096
0xFFF0x7FFVref * 4095 / 4096Vref
+* +* The expressions in the above table are based on an unbuffered DAC output. +* When the output is buffered, the input and output range of the buffer will affect the +* output voltage. See \ref group_ctb_opamp_range in the CTB driver for more information. +* +* \section group_ctdac_trigger Interrupts and Trigger +* +* When data from the CTDAC_VAL_NXT is transferred to the CTDAC_VAL register, +* an interrupt and trigger output are generated. The trigger output can be +* used with a DMA block to update the CTDAC value register at high speeds without any CPU intervention. +* Alternatively, the interrupt output can be used when DMA is not available +* to update the CTDAC value register, but at a slower speed. +* +* Recall with the \ref group_ctdac_updatemode, the interrupt and trigger output are available in all modes except +* \ref group_ctdac_updatemode_direct_write. +* +* \subsection group_ctdac_dma_trigger DMA Trigger +* +* The CTDAC trigger output signal can be routed to a DMA block using the \ref group_trigmux +* to trigger an update to the CTDAC_VAL_NXT register. * When making the required \ref Cy_TrigMux_Connect calls, use the pre-defined enums, TRIG14_IN_PASS_TR_CTDAC_EMPTY -* and TRIGGER_TYPE_PASS_TR_CTDAC_EMPTY. For example, +* and TRIGGER_TYPE_PASS_TR_CTDAC_EMPTY. * -* \code -* (void)Cy_TrigMux_Connect(TRIG14_IN_PASS_TR_CTDAC_EMPTY, TRIG14_OUT_TR_GROUP0_INPUT50, CY_TR_MUX_TR_INV_DISABLE, TRIGGER_TYPE_PASS_TR_CTDAC_EMPTY); -* (void)Cy_TrigMux_Connect(TRIG0_IN_TR_GROUP14_OUTPUT7, TRIG0_OUT_CPUSS_DW0_TR_IN1, CY_TR_MUX_TR_INV_DISABLE, TRIGGER_TYPE_TR_GROUP_OUTPUT__LEVEL); -* \endcode +* \subsection group_ctdac_handling_interrupts Handling Interrupts * -* \section group_ctdac_code_example Complete Code Example +* The following code snippet demonstrates how to implement a routine to handle the interrupt. +* The routine gets called when any CTDAC on the device generates an interrupt. * -* The following example code demonstrates how to generate a continuous -* sine wave using the CTDAC. The CTDAC uses both Opamps of the CTB -* to buffer the analog reference and to buffer the output to an external Pin 2. +* \snippet ctdac_sut_01.cydsn/main_cm0p.c SNIPPET_CTDAC_ISR * -* \image html ctdac_code_example.png -* \image latex ctdac_code_example.png +* The following code snippet demonstrates how to configure and enable the interrupt. * -* \code -* #include "ctdac/cy_ctdac.h" -* #include "ctb/cy_ctb.h" -* #include "sysanalog/cy_sysanalog.h" -* #include "sysint/cy_sysint.h" -* \endcode +* \snippet ctdac_sut_01.cydsn/main_cm0p.c SNIPPET_CTDAC_INTR_SETUP * -* \snippet ctdac_sut_01.cydsn/main_cm0p.c CTDAC_CODE_EXAMPLE +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_DMA_TRIGGER +* +* \section group_ctdac_deglitch Deglitch +* +* The hardware has the ability to deglitch the output value every time it is updated. +* This prevents small glitches in the DAC output during an update to propagate to +* the pin or opamp input. When deglitch is enabled, a switch on the output path +* is forced open for a configurable number of PeriClk cycles. This deglitch time +* is calculated as: +* +* (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ +* +* The optimal and recommended deglitch time is 700 ns. Call \ref Cy_CTDAC_SetDeglitchCycles to set DEGLITCH_CNT. +* +* There are two switches used for deglitching. +* - Switch COS in the CTB between the DAC output and the Opamp0 input +* - Switch CO6 in the CTDAC between the DAC output and external pin +* +* Call \ref Cy_CTDAC_SetDeglitchMode to set the deglitch path. Match this with the output buffer selection. +* If the output is buffered through the CTB, select \ref CY_CTDAC_DEGLITCHMODE_BUFFERED. +* If the output is unbuffered to a direct pin, select \ref CY_CTDAC_DEGLITCHMODE_UNBUFFERED. +* +* \note +* If deglitching is enabled, the hardware does not force the deglitch switches into a closed +* state during Deep Sleep mode. Therefore, there is a chance that the device enters +* Deep Sleep mode while the hardware is deglitching and the switches on the output path remain open. +* To ensure the DAC will operate properly in Deep Sleep when enabled, make sure to +* register the \ref Cy_CTDAC_DeepSleepCallback before entering Deep Sleep mode. +* +* \section group_ctdac_sample_hold Sample and Hold +* +* When buffering the DAC output, the CTB has a Sample and Hold (SH) feature that can be used for saving power. +* The DAC output voltage is retained on an internal capacitor for a duration of time while the +* DAC output can be turned off. The DAC hardware needs to be turned on in a periodic fashion +* to recharge the hold capacitor. This feature is firmware controlled using a sequence of function calls. +* See \ref Cy_CTB_DACSampleAndHold in the \ref group_ctb_sample_hold "CTB" driver. +* +* The hold time depends on the supply and reference voltages. The following hold times are based on the +* time it takes for the buffered output to change by 1 LSB. +* +* - Hold time = 750 us @ Vref = VDDA , VDDA = 1.7 V +* - Hold time = 525 us @ Vref = VDDA , VDDA = 3.6 V +* - Hold time = 200 us @ Vref = 1.2 V, VDDA = 3.6 V +* +* \section group_ctdac_low_power Low Power Support +* +* The CTDAC driver provides a callback function to handle power mode transitions. +* If the CTDAC is configured for Deep Sleep operation and \ref group_ctdac_deglitch "deglitching" is enabled, +* the callback \ref Cy_CTDAC_DeepSleepCallback must be registered before calling +* \ref Cy_SysPm_DeepSleep. +* Refer to \ref group_syspm driver for more information about power mode transitions and +* callback registration. * * \section group_ctdac_more_information More Information * @@ -215,6 +308,11 @@ * * * +* +* +* +* +* * * * @@ -224,12 +322,14 @@ * \defgroup group_ctdac_macros Macros * \defgroup group_ctdac_functions Functions * \{ +* \defgroup group_ctdac_functions_init Initialization Functions +* \defgroup group_ctdac_functions_basic Basic Configuration Functions * \defgroup group_ctdac_functions_switches Switch Control Functions * \defgroup group_ctdac_functions_interrupts Interrupt Functions -* \defgroup group_ctdac_functions_syspm_callback SysPm Deep Sleep Callback +* \defgroup group_ctdac_functions_syspm_callback Low Power Callback * \} * \defgroup group_ctdac_globals Global Variables -* \defgroup group_ctdac_data_structures Data structures +* \defgroup group_ctdac_data_structures Data Structures * \defgroup group_ctdac_enums Enumerated Types */ @@ -265,16 +365,17 @@ extern "C" { /** CTDAC driver identifier */ #define CY_CTDAC_ID CY_PDL_DRV_ID(0x19u) -/** \cond INTERNAL */ #define CY_CTDAC_DEINIT (0uL) /**< De-init value for CTDAC registers */ -#define CY_CTDAC_DEINT_CTDAC_SW (CTDAC_CTDAC_SW_CLEAR_CTDD_CVD_Msk | CTDAC_CTDAC_SW_CLEAR_CTDO_CO6_Msk) /**< Mask for de-initializing the CTDAC switch control register */ -#define CY_CTDAC_STROBE_EDGE_IMMEDIATE_DIV (0uL) /**< Clock divider value for the Strobe Edge Immediate update mode */ -#define CY_CTDAC_STROBE_EDGE_IMMEDIATE_DIV_FRAC (0uL) /**< Clock fractional divider value for the Strobe Edge Immediate update mode */ +#define CY_CTDAC_UNSIGNED_MID_CODE_VALUE (0x800uL) /**< Middle code value for unsigned values */ +#define CY_CTDAC_UNSIGNED_MAX_CODE_VALUE (0xFFFuL) /**< Maximum code value for unsigned values */ #define CY_CTDAC_FAST_CLKCFG_TYPE CY_SYSCLK_DIV_8_BIT /**< Clock divider type for quick clock setup */ #define CY_CTDAC_FAST_CLKCFG_NUM (0uL) /**< Clock divider number for quick clock setup */ #define CY_CTDAC_FAST_CLKCFG_DIV (99uL) /**< Clock divider integer value for quick clock setup. Divides PERI clock by 100. */ -#define CY_CTDAC_UNSIGNED_MID_CODE_VALUE (0x800uL) /**< Middle code value for unsigned values */ -#define CY_CTDAC_UNSIGNED_MAX_CODE_VALUE (0xFFFuL) /**< Maximum code value for unsigned values */ + +/** \cond INTERNAL */ +#define CY_CTDAC_DEINT_CTDAC_SW (CTDAC_CTDAC_SW_CLEAR_CTDD_CVD_Msk | CTDAC_CTDAC_SW_CLEAR_CTDO_CO6_Msk) /**< Mask for de-initializing the CTDAC switch control register */ +#define CY_CTDAC_STROBE_EDGE_IMMEDIATE_DIV (0uL) /**< Clock divider value for the Strobe Edge Immediate update mode */ +#define CY_CTDAC_STROBE_EDGE_IMMEDIATE_DIV_FRAC (0uL) /**< Clock fractional divider value for the Strobe Edge Immediate update mode */ #define CY_CTDAC_DEGLITCH_CYCLES_MAX (63uL) /**< Macros for conditions used by CY_ASSERT calls */ @@ -311,7 +412,7 @@ extern "C" { /** * Configure the mode for how the DAC value is updated. -* All the modes require a CTDAC clock except for CY_CTDAC_UPDATE_DIRECT_WRITE. +* All the modes require a CTDAC clock except for \ref group_ctdac_updatemode_direct_write. */ typedef enum { CY_CTDAC_UPDATE_DIRECT_WRITE = 0uL, /**< DAC value is updated with a direct write by calling to \ref Cy_CTDAC_SetValue */ @@ -351,26 +452,15 @@ typedef enum { }cy_en_ctdac_output_mode_t; /** -* The CTDAC provides an option to deglitch the output value every time it is updated. -* This prevents small glitches in the DAC output during an update to propagate to -* the pin or Opamp input. When deglitch is enabled, a switch on the output path -* is forced open for a configurable number of Peri Clock cycles. To calculate the deglitch -* time, (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ. -* -* There are two switches used for deglitching. -* - Switch COS in the CTB between the DAC output and the Opamp0 input -* - Switch CO6 in the CTDAC between the DAC output and external pin -* -* Match the deglitch path with the output buffer selection. -* If the output is buffered through the CTB, select CY_CTDAC_DEGLITCHMODE_BUFFERED. -* If the output is unbuffered to a direct pin, select CY_CTDAC_DEGLITCHMODE_UNBUFFERED. +* Configure the deglitch mode. See the \ref group_ctdac_deglitch section for +* more information on how deglitching works. */ typedef enum { CY_CTDAC_DEGLITCHMODE_NONE = 0uL, /**< Disable deglitch */ CY_CTDAC_DEGLITCHMODE_UNBUFFERED = CTDAC_CTDAC_CTRL_DEGLITCH_CO6_Msk, /**< Deglitch through the CO6 switch */ CY_CTDAC_DEGLITCHMODE_BUFFERED = CTDAC_CTDAC_CTRL_DEGLITCH_COS_Msk, /**< Deglitch through the CTB COS switch */ CY_CTDAC_DEGLITCHMODE_BOTH = CTDAC_CTDAC_CTRL_DEGLITCH_COS_Msk \ - | CTDAC_CTDAC_CTRL_DEGLITCH_CO6_Msk /**< Deglitch through both CO6 and CTB COS switches */ + | CTDAC_CTDAC_CTRL_DEGLITCH_CO6_Msk /**< Deglitch through both CO6 and CTB COS switches */ }cy_en_ctdac_deglitch_t; /** @@ -379,7 +469,7 @@ typedef enum { * The CVD switch is closed when Vdda is the reference source. */ typedef enum { - CY_CTDAC_REFSOURCE_EXTERNAL = 0uL, /**< Use an external source as the reference. CVD switch is open. */ + CY_CTDAC_REFSOURCE_EXTERNAL = 0uL, /**< Use an external source from Opamp1 of the CTB as the reference. CVD switch is open. */ CY_CTDAC_REFSOURCE_VDDA = 1uL /**< Use Vdda as the reference. CVD switch is closed. */ }cy_en_ctdac_ref_source_t; @@ -439,34 +529,33 @@ typedef struct int32_t value; /**< Current DAC value */ int32_t nextValue; /**< Next DAC value for double buffering */ bool enableInterrupt; /**< If true, enable interrupt when next value register is transferred to value register */ - bool enable; /**< Enable or disable hardware after initialization */ /* Configuring the clock */ bool configClock; /**< Configure or ignore clock information */ - cy_en_divider_types_t dividerType; /**< Specifies which type of divider to use. Can be integer or fractional divider. Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE */ - uint32_t dividerNum; /**< Specifies which divider of the selected type to configure. Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE */ - uint32_t dividerIntValue; /**< The integer divider value. The divider value causes integer division of (divider value + 1). Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE or CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE */ - uint32_t dividerFracValue; /**< The fractional divider value if using a fractional clock. Not used if updateMode is CY_CTDAC_UPDATE_DIRECT_WRITE or CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE */ + cy_en_divider_types_t dividerType; /**< Specifies which type of divider to use. Can be integer or fractional divider. Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE */ + uint32_t dividerNum; /**< Specifies which divider of the selected type to configure. Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE */ + uint32_t dividerIntValue; /**< The integer divider value. The divider value causes integer division of (divider value + 1). Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE or \ref CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE */ + uint32_t dividerFracValue; /**< The fractional divider value if using a fractional clock. Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE or \ref CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE */ }cy_stc_ctdac_config_t; /** Configuration structure to quickly set up the CTDAC to be used with \ref Cy_CTDAC_FastInit * This structure provides a selection for the CTDAC reference source and output path. * * The other configuration options are set to: -* - .formatMode = CY_CTDAC_FORMAT_UNSIGNED -* - .updateMode = CY_CTDAC_UPDATE_BUFFERED_WRITE -* - .deglitchMode = CY_CTDAC_DEGLITCHMODE_NONE -* - .outputMode = CY_CTDAC_OUTPUT_VALUE -* - .deepSleep = CY_CTDAC_DEEPSLEEP_DISABLE -* - .deglitchCycles = CY_CTDAC_DEINIT -* - .value = CY_CTDAC_UNSIGNED_MID_CODE_VALUE -* - .nextValue = CY_CTDAC_UNSIGNED_MID_CODE_VALUE +* - .formatMode = \ref CY_CTDAC_FORMAT_UNSIGNED +* - .updateMode = \ref CY_CTDAC_UPDATE_BUFFERED_WRITE +* - .deglitchMode = \ref CY_CTDAC_DEGLITCHMODE_NONE +* - .outputMode = \ref CY_CTDAC_OUTPUT_VALUE +* - .deepSleep = \ref CY_CTDAC_DEEPSLEEP_DISABLE +* - .deglitchCycles = \ref CY_CTDAC_DEINIT +* - .value = \ref CY_CTDAC_UNSIGNED_MID_CODE_VALUE +* - .nextValue = \ref CY_CTDAC_UNSIGNED_MID_CODE_VALUE * - .enableInterrupt = true * - .configClock = true -* - .dividerType = CY_CTDAC_FAST_CLKCFG_TYPE -* - .dividerNum = CY_CTDAC_FAST_CLKCFG_NUM -* - .dividerInitValue = CY_CTDAC_FAST_CLKCFG_DIV -* - .dividerFracValue = CY_CTDAC_DEINIT +* - .dividerType = \ref CY_CTDAC_FAST_CLKCFG_TYPE +* - .dividerNum = \ref CY_CTDAC_FAST_CLKCFG_NUM +* - .dividerInitValue = \ref CY_CTDAC_FAST_CLKCFG_DIV +* - .dividerFracValue = \ref CY_CTDAC_DEINIT */ typedef struct { @@ -530,11 +619,24 @@ extern const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_OA1Ref_BufferedOut; * \addtogroup group_ctdac_functions * \{ */ + +/** +* \addtogroup group_ctdac_functions_init +* This set of functions are for initializing, enabling, and disabling the CTDAC. +* \{ +*/ cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t *config); cy_en_ctdac_status_t Cy_CTDAC_DeInit(CTDAC_Type *base, bool deInitRouting); cy_en_ctdac_status_t Cy_CTDAC_FastInit(CTDAC_Type *base, const cy_stc_ctdac_fast_config_t *config); __STATIC_INLINE void Cy_CTDAC_Enable(CTDAC_Type *base); __STATIC_INLINE void Cy_CTDAC_Disable(CTDAC_Type *base); +/** \} */ + +/** +* \addtogroup group_ctdac_functions_basic +* This set of functions are for configuring basic usage of the CTDAC. +* \{ +*/ __STATIC_INLINE void Cy_CTDAC_SetValue(CTDAC_Type *base, int32_t value); __STATIC_INLINE void Cy_CTDAC_SetValueBuffered(CTDAC_Type *base, int32_t value); void Cy_CTDAC_SetSignMode(CTDAC_Type *base, cy_en_ctdac_format_t formatMode); @@ -543,6 +645,7 @@ void Cy_CTDAC_SetOutputMode(CTDAC_Type *base, cy_en_ctdac_output_mode_t outputMo void Cy_CTDAC_SetDeglitchMode(CTDAC_Type *base, cy_en_ctdac_deglitch_t deglitchMode); void Cy_CTDAC_SetDeglitchCycles(CTDAC_Type *base, uint32_t deglitchCycles); void Cy_CTDAC_SetRef(CTDAC_Type *base, cy_en_ctdac_ref_source_t refSource); +/** \} */ /** \addtogroup group_ctdac_functions_switches * @@ -558,12 +661,12 @@ __STATIC_INLINE void Cy_CTDAC_OpenAllSwitches(CTDAC_Type *base); /** \} */ /** \addtogroup group_ctdac_functions_interrupts -* This set of functions is related to the VDAC_EMPTY interrupt +* This set of functions is related to the CTDAC interrupt * \{ */ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus(const CTDAC_Type *base); __STATIC_INLINE void Cy_CTDAC_ClearInterrupt(CTDAC_Type *base); -__STATIC_INLINE void Cy_CTDAC_SetSwInterrupt(CTDAC_Type *base); +__STATIC_INLINE void Cy_CTDAC_SetInterrupt(CTDAC_Type *base); __STATIC_INLINE void Cy_CTDAC_SetInterruptMask(CTDAC_Type *base, uint32_t mask); __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptMask(const CTDAC_Type *base); __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatusMasked(const CTDAC_Type *base); @@ -576,11 +679,15 @@ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatusMasked(const CTDAC_Type *bas cy_en_syspm_status_t Cy_CTDAC_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams); /** \} */ +/** +* \addtogroup group_ctdac_functions_init +* \{ +*/ /******************************************************************************* * Function Name: Cy_CTDAC_Enable ****************************************************************************//** * -* Powers up the CTDAC hardware block +* Power up the CTDAC hardware block. * * \param base * Pointer to structure describing registers @@ -609,17 +716,26 @@ __STATIC_INLINE void Cy_CTDAC_Disable(CTDAC_Type *base) { base->CTDAC_CTRL &= ~CTDAC_CTDAC_CTRL_ENABLED_Msk; } +/** \} */ +/** +* \addtogroup group_ctdac_functions_basic +* \{ +*/ /******************************************************************************* * Function Name: Cy_CTDAC_SetValue ****************************************************************************//** * * Set the CTDAC_VAL register (DAC hardware is -* updated on the next Peri clock cycle). Only the least significant 12 bits +* updated on the next PeriClk cycle). Only the least significant 12 bits * have an effect. Sign extension of negative values is unnecessary and is * ignored by the hardware. The way in which the CTDAC interprets the 12-bit * data is controlled by \ref Cy_CTDAC_SetSignMode. * +* \note +* Call this function only when the update mode is set to \ref group_ctdac_updatemode_direct_write. +* Calling this function for any other update mode will not have the intended effect. +* * \param base * Pointer to structure describing registers * @@ -628,6 +744,10 @@ __STATIC_INLINE void Cy_CTDAC_Disable(CTDAC_Type *base) * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_VALUE +* *******************************************************************************/ __STATIC_INLINE void Cy_CTDAC_SetValue(CTDAC_Type *base, int32_t value) { @@ -645,6 +765,10 @@ __STATIC_INLINE void Cy_CTDAC_SetValue(CTDAC_Type *base, int32_t value) * ignored by the hardware. The way in which the CTDAC interprets the 12-bit * data is controlled by \ref Cy_CTDAC_SetSignMode. * +* \note +* Calling this function in \ref group_ctdac_updatemode_direct_write mode will not update the DAC output. +* Call this function for all modes that use buffered values (i.e. uses a clock). +* * \param base * Pointer to structure describing registers * @@ -653,30 +777,36 @@ __STATIC_INLINE void Cy_CTDAC_SetValue(CTDAC_Type *base, int32_t value) * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_VALUE_BUFFERED +* *******************************************************************************/ -__STATIC_INLINE void Cy_CTDAC_SetValueBuffered(CTDAC_Type *base, int32_t value){ +__STATIC_INLINE void Cy_CTDAC_SetValueBuffered(CTDAC_Type *base, int32_t value) +{ base->CTDAC_VAL_NXT = (((uint32_t)value) << CTDAC_CTDAC_VAL_NXT_VALUE_Pos) & CTDAC_CTDAC_VAL_NXT_VALUE_Msk; } +/** \} */ /** * \addtogroup group_ctdac_functions_switches * \{ */ - /******************************************************************************* * Function Name: Cy_CTDAC_GetAnalogSwitch ****************************************************************************//** * -* Gets the state (open or close) of CTDAC switches as a uint32_t value. +* Return the state (open or close) of the CTDAC switches. * -* This is an advanced function. The switches will be managed by the reference +* \note +* The switches will be managed by the reference * source and output mode selections when initializing the hardware. - +* * \param base * Pointer to structure describing registers * -* \return uint32_t -* Compare the value to the switch masks found in \ref cy_en_ctdac_switches_t. +* \return +* Switch state. Compare this value to the masks found in \ref cy_en_ctdac_switches_t. * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTDAC_GetAnalogSwitch(const CTDAC_Type *base) @@ -689,14 +819,16 @@ __STATIC_INLINE uint32_t Cy_CTDAC_GetAnalogSwitch(const CTDAC_Type *base) ****************************************************************************//** * * Open or close switch CO6 that controls whether the output gets routed -* directly to a pin or through Opamp0 of the CTB. +* directly to a pin or through Opamp0 of the CTB. This function calls +* \ref Cy_CTDAC_SetAnalogSwitch with the switchMask set to \ref CY_CTDAC_SWITCH_CO6_MASK. * -* Note that this switch will temporarily -* be opened for deglitching if DEGLITCHMODE_UNBUFFERED or DEGLITCHMODE_BOTH -* is set in \ref Cy_CTDAC_SetDeglitchMode. +* \note +* The switches is configured by the output mode selections during initialization. * -* This is an advanced function. The switches will be managed by the reference -* source and output mode selections when initializing the hardware. +* \note +* This switch will temporarily +* be opened for deglitching if the degitch mode is \ref CY_CTDAC_DEGLITCHMODE_UNBUFFERED or +* \ref CY_CTDAC_DEGLITCHMODE_BOTH. * * \param base * Pointer to structure describing registers @@ -706,6 +838,10 @@ __STATIC_INLINE uint32_t Cy_CTDAC_GetAnalogSwitch(const CTDAC_Type *base) * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_SET_SWITCH_CO6 +* *******************************************************************************/ __STATIC_INLINE void Cy_CTDAC_SetSwitchCO6(CTDAC_Type *base, cy_en_ctdac_switch_state_t state) { @@ -716,16 +852,17 @@ __STATIC_INLINE void Cy_CTDAC_SetSwitchCO6(CTDAC_Type *base, cy_en_ctdac_switch_ * Function Name: Cy_CTDAC_OpenAllSwitches ****************************************************************************//** * -* Open all switches. -* -* This is an advanced function. The switches will be managed by the reference -* source and output mode selections when initializing the hardware. +* Open all switches in the CTDAC (CO6 and CVD). * * \param base * Pointer to structure describing registers * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm4.c CTDAC_SNIPPET_OPEN_ALL_SWITCHES +* *******************************************************************************/ __STATIC_INLINE void Cy_CTDAC_OpenAllSwitches(CTDAC_Type *base) { @@ -742,18 +879,23 @@ __STATIC_INLINE void Cy_CTDAC_OpenAllSwitches(CTDAC_Type *base) * Function Name: Cy_CTDAC_GetInterruptStatus ****************************************************************************//** * -* Returns the interrupt status which gets set by the hardware +* Return the interrupt status which gets set by the hardware * when the CTDAC_VAL_NXT register value is transferred to the CTDAC_VAL register. * Once set, the CTDAC_VAL_NXT register is ready to accept a new value. * -* Interrupts are available in all update modes except \ref CY_CTDAC_UPDATE_DIRECT_WRITE. +* \note +* Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write. * * \param base * Pointer to structure describing registers * * \return -* 0 = Value not moved from CTDAC_VAL_NXT to CTDAC_VAL -* 1 = Value moved from CTDAC_VAL_NXT to CTDAC_VAL +* - 0: Value not moved from CTDAC_VAL_NXT to CTDAC_VAL +* - 1: Value moved from CTDAC_VAL_NXT to CTDAC_VAL +* +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm0p.c SNIPPET_CTDAC_GET_INTERRUPT_STATUS * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus(const CTDAC_Type *base) @@ -765,13 +907,14 @@ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus(const CTDAC_Type *base) * Function Name: Cy_CTDAC_ClearInterrupt ****************************************************************************//** * -* Clears the interrupt that was set by the hardware when the +* Clear the interrupt that was set by the hardware when the * CTDAC_VAL_NXT register value is transferred to the CTDAC_VAL register. * The interrupt must be cleared with this function so that * the hardware can set subsequent interrupts and those interrupts * can be forwarded to the interrupt controller, if enabled. * -* Interrupts are available in all update modes except \ref CY_CTDAC_UPDATE_DIRECT_WRITE. +* \note +* Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write. * * \param base * Pointer to structure describing registers @@ -782,15 +925,19 @@ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus(const CTDAC_Type *base) __STATIC_INLINE void Cy_CTDAC_ClearInterrupt(CTDAC_Type *base) { base->INTR = CTDAC_INTR_VDAC_EMPTY_Msk; + + /* Dummy read for buffered writes. */ + (void) base->INTR; } /******************************************************************************* -* Function Name: Cy_CTDAC_SetSwInterrupt +* Function Name: Cy_CTDAC_SetInterrupt ****************************************************************************//** * -* Forces the CTDAC interrupt to trigger using software. +* Force the CTDAC interrupt to trigger using software. * -* Interrupts are available in all update modes except \ref CY_CTDAC_UPDATE_DIRECT_WRITE. +* \note +* Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write. * * \param base * Pointer to structure describing registers @@ -798,7 +945,7 @@ __STATIC_INLINE void Cy_CTDAC_ClearInterrupt(CTDAC_Type *base) * \return None * *******************************************************************************/ -__STATIC_INLINE void Cy_CTDAC_SetSwInterrupt(CTDAC_Type *base) +__STATIC_INLINE void Cy_CTDAC_SetInterrupt(CTDAC_Type *base) { base->INTR_SET = CTDAC_INTR_SET_VDAC_EMPTY_SET_Msk; } @@ -810,17 +957,23 @@ __STATIC_INLINE void Cy_CTDAC_SetSwInterrupt(CTDAC_Type *base) * Configure the CTDAC interrupt to be forwarded to the CPU interrupt * controller. * -* Interrupts are available in all update modes except \ref CY_CTDAC_UPDATE_DIRECT_WRITE. +* \note +* Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write. * * \param base * Pointer to structure describing registers * * \param mask -* 0: Disable CTDAC interrupt request (will not be forwarded to CPU interrupt controller) -* 1: Enable CTDAC interrupt request (will be forwarded to CPU interrupt controller) +* The CTDAC only has one interrupt so the mask is one bit. +* - 0: Disable CTDAC interrupt request (will not be forwarded to CPU interrupt controller) +* - 1: Enable CTDAC interrupt request (will be forwarded to CPU interrupt controller) * * \return None * +* \funcusage +* +* \snippet ctdac_sut_01.cydsn/main_cm0p.c SNIPPET_CTDAC_SET_INTERRUPT_MASK +* *******************************************************************************/ __STATIC_INLINE void Cy_CTDAC_SetInterruptMask(CTDAC_Type *base, uint32_t mask) { @@ -833,18 +986,20 @@ __STATIC_INLINE void Cy_CTDAC_SetInterruptMask(CTDAC_Type *base, uint32_t mask) * Function Name: Cy_CTDAC_GetInterruptMask ****************************************************************************//** * -* Returns whether the CTDAC interrupt is +* Return whether the CTDAC interrupt is * forwarded to the CPU interrupt controller * as configured by \ref Cy_CTDAC_SetInterruptMask. * -* Interrupts are available in all update modes except \ref CY_CTDAC_UPDATE_DIRECT_WRITE. +* \note +* Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write. * * \param base * Pointer to structure describing registers * * \return -* 0 = Interrupt output not forwarded to CPU interrupt controller -* 1 = Interrupt output forwarded to CPU interrupt controller +* The CTDAC only has one interrupt so the return value is either 0 or 1. +* - 0: Interrupt output not forwarded to CPU interrupt controller +* - 1: Interrupt output forwarded to CPU interrupt controller * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptMask(const CTDAC_Type *base) @@ -856,19 +1011,20 @@ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptMask(const CTDAC_Type *base) * Function Name: Cy_CTDAC_GetInterruptStatusMasked ****************************************************************************//** * -* Returns the bitwise AND of \ref Cy_CTDAC_GetInterruptStatus and +* Return the bitwise AND of \ref Cy_CTDAC_GetInterruptStatus and * \ref Cy_CTDAC_SetInterruptMask. When high, the DAC interrupt is * asserted and the interrupt is forwarded to the CPU interrupt * controller. * -* Interrupts are available in all update modes except \ref CY_CTDAC_UPDATE_DIRECT_WRITE. +* \note +* Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write. * * \param base * Pointer to structure describing registers * * \return -* 0 = Value not moved from CTDAC_VAL_NXT to CTDAC_VAL or not masked -* 1 = Value moved from CTDAC_VAL_NXT to CTDAC_VAL and masked +* - 0: Value not moved from CTDAC_VAL_NXT to CTDAC_VAL or not masked +* - 1: Value moved from CTDAC_VAL_NXT to CTDAC_VAL and masked * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatusMasked(const CTDAC_Type *base){ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/dma/cy_dma.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/dma/cy_dma.c similarity index 70% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/dma/cy_dma.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/dma/cy_dma.c index 2b50f08363..ec638423de 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/dma/cy_dma.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/dma/cy_dma.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_dma.c -* \version 2.0 +* \version 2.0.1 * * \brief * The source code file for the DMA driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -24,12 +24,12 @@ extern "C" { * Function Name: Cy_DMA_Descriptor_Init ****************************************************************************//** * -* Initializes descriptor structure in SRAM from a pre-initialized +* Initializes the descriptor structure in SRAM from a pre-initialized * configuration structure. * This function initializes only the descriptor and not the channel. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param config * This is a configuration structure that has all initialization information for @@ -86,6 +86,7 @@ cy_en_dma_status_t Cy_DMA_Descriptor_Init(cy_stc_dma_descriptor_t * descriptor, descriptor->xCtl = _VAL2FLD(CY_DMA_CTL_SRC_INCR, config->srcXincrement) | _VAL2FLD(CY_DMA_CTL_DST_INCR, config->dstXincrement) | + /* Convert the data count from the user's range (1-256) into the machine range (0-255). */ _VAL2FLD(CY_DMA_CTL_COUNT, config->xCount - 1UL); descriptor->yCtl = (uint32_t)config->nextDescriptor; @@ -103,11 +104,13 @@ cy_en_dma_status_t Cy_DMA_Descriptor_Init(cy_stc_dma_descriptor_t * descriptor, descriptor->xCtl = _VAL2FLD(CY_DMA_CTL_SRC_INCR, config->srcXincrement) | _VAL2FLD(CY_DMA_CTL_DST_INCR, config->dstXincrement) | + /* Convert the data count from the user's range (1-256) into the machine range (0-255). */ _VAL2FLD(CY_DMA_CTL_COUNT, config->xCount - 1UL); descriptor->yCtl = _VAL2FLD(CY_DMA_CTL_SRC_INCR, config->srcYincrement) | _VAL2FLD(CY_DMA_CTL_DST_INCR, config->dstYincrement) | + /* Convert the data count from the user's range (1-256) into the machine range (0-255). */ _VAL2FLD(CY_DMA_CTL_COUNT, config->yCount - 1UL); descriptor->nextPtr = (uint32_t)config->nextDescriptor; @@ -115,7 +118,7 @@ cy_en_dma_status_t Cy_DMA_Descriptor_Init(cy_stc_dma_descriptor_t * descriptor, } default: { - /* Unsupported type of descriptor */ + /* An unsupported type of a descriptor */ break; } } @@ -131,10 +134,10 @@ cy_en_dma_status_t Cy_DMA_Descriptor_Init(cy_stc_dma_descriptor_t * descriptor, * Function Name: Cy_DMA_Descriptor_DeInit ****************************************************************************//** * -* Clears all the content of the specified descriptor. +* Clears the content of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * *******************************************************************************/ void Cy_DMA_Descriptor_DeInit(cy_stc_dma_descriptor_t * descriptor) @@ -155,13 +158,13 @@ void Cy_DMA_Descriptor_DeInit(cy_stc_dma_descriptor_t * descriptor) * Initializes the DMA channel with a descriptor and other parameters. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel * A channel number. * * \param channelConfig -* A structure that has the initialization information for the +* The structure that has the initialization information for the * channel. * * \return @@ -174,22 +177,16 @@ cy_en_dma_status_t Cy_DMA_Channel_Init(DW_Type * base, uint32_t channel, cy_stc_ if (((CY_DMA_IS_DW_CH_NR_VALID(base, channel)) && (NULL != channelConfig) && (NULL != channelConfig->descriptor))) { - uint32_t regVal; - CY_ASSERT_L2(CY_DMA_IS_PRIORITY_VALID(channelConfig->priority)); - /* Set current descriptor */ + /* Set the current descriptor */ base->CH_STRUCT[channel].CH_CURR_PTR = (uint32_t)channelConfig->descriptor; - /* Set if the channel is preemtable */ - regVal = base->CH_STRUCT[channel].CH_CTL & ((uint32_t) ~(DW_CH_STRUCT_CH_CTL_PREEMPTABLE_Msk | - DW_CH_STRUCT_CH_CTL_PRIO_Msk | - DW_CH_STRUCT_CH_CTL_ENABLED_Msk)); - - base->CH_STRUCT[channel].CH_CTL = regVal | _BOOL2FLD(DW_CH_STRUCT_CH_CTL_PREEMPTABLE, channelConfig->preemptable) | - _VAL2FLD(DW_CH_STRUCT_CH_CTL_PRIO, channelConfig->priority) | - _BOOL2FLD(DW_CH_STRUCT_CH_CTL_ENABLED, channelConfig->enable); - + /* Set the channel configuration */ + base->CH_STRUCT[channel].CH_CTL = _BOOL2FLD(DW_CH_STRUCT_CH_CTL_PREEMPTABLE, channelConfig->preemptable) | + _VAL2FLD(DW_CH_STRUCT_CH_CTL_PRIO, channelConfig->priority) | + _BOOL2FLD(DW_CH_STRUCT_CH_CTL_ENABLED, channelConfig->enable) | + _BOOL2FLD(DW_CH_STRUCT_CH_CTL_B, channelConfig->bufferable); retVal = CY_DMA_SUCCESS; } @@ -201,10 +198,10 @@ cy_en_dma_status_t Cy_DMA_Channel_Init(DW_Type * base, uint32_t channel, cy_stc_ * Function Name: Cy_DMA_Channel_DeInit ****************************************************************************//** * -* Clears all the content of registers corresponding to the channel. +* Clears the content of registers corresponding to the channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel * A channel number. @@ -227,13 +224,13 @@ void Cy_DMA_Channel_DeInit(DW_Type * base, uint32_t channel) * * Sets a Next Descriptor parameter for the specified descriptor. * -* Based on descriptor type the offset of address for the next descriptor may -* vary. For a single transfer descriptor type, this register is at offset 0x0c. -* For a 1D transfer descriptor type, this register is at offset 0x10. For a 2D -* transfer descriptor type, this register is at offset 0x14. +* Based on the descriptor type, the offset of the address for the next descriptor may +* vary. For the single-transfer descriptor type, this register is at offset 0x0c. +* For the 1D-transfer descriptor type, this register is at offset 0x10. +* For the 2D-transfer descriptor type, this register is at offset 0x14. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param nextDescriptor * The pointer to the next descriptor. @@ -270,13 +267,13 @@ void Cy_DMA_Descriptor_SetNextDescriptor(cy_stc_dma_descriptor_t * descriptor, c * * Returns a next descriptor address of the specified descriptor. * -* Based on descriptor type the offset of address for the next descriptor may -* vary. For a single transfer descriptor type, this register is at offset 0x0c. -* For a 1D transfer descriptor type, this register is at offset 0x10. For a 2D -* transfer descriptor type, this register is at offset 0x14. +* Based on the descriptor type, the offset of the address for the next descriptor may +* vary. For a single-transfer descriptor type, this register is at offset 0x0c. +* For the 1D-transfer descriptor type, this register is at offset 0x10. +* For the 2D-transfer descriptor type, this register is at offset 0x14. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The pointer to the next descriptor. @@ -303,7 +300,7 @@ cy_stc_dma_descriptor_t * Cy_DMA_Descriptor_GetNextDescriptor(cy_stc_dma_descrip break; default: - /* Unsupported type of descriptor */ + /* An unsupported type of the descriptor */ break; } @@ -311,6 +308,46 @@ cy_stc_dma_descriptor_t * Cy_DMA_Descriptor_GetNextDescriptor(cy_stc_dma_descrip } +/******************************************************************************* +* Function Name: Cy_DMA_Descriptor_SetDescriptorType +****************************************************************************//** +* +* Sets the descriptor's type for the specified descriptor. +* Moves the next descriptor register value into the proper place in accordance +* to the actual descriptor type. +* During the descriptor's type changing, the Xloop and Yloop settings, such as +* data count and source/destination increment (i.e. the content of the +* xCtl and yCtl descriptor registers) might be lost (overriden by the +* next descriptor value) because of the different descriptor registers structures +* for different descriptor types. Set up carefully the Xloop +* (and Yloop, if used) data count and source/destination increment if the +* descriptor type is changed from a simpler to a more complicated type +* ("single transfer" -> "1D", "1D" -> "2D", etc.). +* +* \param descriptor +* The descriptor structure instance declared by the user/component. +* +* \param descriptorType +* The descriptor type \ref cy_en_dma_descriptor_type_t. +* +*******************************************************************************/ +void Cy_DMA_Descriptor_SetDescriptorType(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_descriptor_type_t descriptorType) +{ + CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L3(CY_DMA_IS_TYPE_VALID(descriptorType)); + + if (descriptorType != Cy_DMA_Descriptor_GetDescriptorType(descriptor)) /* Don't perform if the type is not changed */ + { + /* Store the current nextDescriptor pointer. */ + cy_stc_dma_descriptor_t * locNextDescriptor = Cy_DMA_Descriptor_GetNextDescriptor(descriptor); + /* Change the descriptor type. */ + descriptor->ctl = _CLR_SET_FLD32U(descriptor->ctl, CY_DMA_CTL_TYPE, descriptorType); + /* Restore the nextDescriptor pointer into the proper place. */ + Cy_DMA_Descriptor_SetNextDescriptor(descriptor, locNextDescriptor); + } +} + + #if defined(__cplusplus) } #endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/dma/cy_dma.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/dma/cy_dma.h similarity index 83% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/dma/cy_dma.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/dma/cy_dma.h index e13a8c6bdc..acb7051ec9 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/dma/cy_dma.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/dma/cy_dma.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_dma.h -* \version 2.0 +* \version 2.0.1 * * \brief * The header file of the DMA driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -18,46 +18,51 @@ * \{ * Configures a DMA channel and its descriptor(s). * -* The DMA Channel component can be used in any project that needs to transfer data -* without CPU intervention, based on a hardware trigger signal from another component. +* The DMA channel can be used in any project to transfer data +* without CPU intervention basing on a hardware trigger signal from another component. * * A device may support more than one DMA hardware block. Each block has a set of -* registers, and a base hardware address. Each block also supports multiple channels. -* Many API functions for the DMA driver require the base hardware address and the +* registers, a base hardware address, and supports multiple channels. +* Many API functions for the DMA driver require a base hardware address and * channel number. Ensure that you use the correct hardware address for the DMA block in use. * * Features: * * Devices support up to two DMA hardware blocks * * Each DMA block supports up to 16 DMA channels * * Supports channel descriptors in SRAM -* * Four Priority Levels for each channel -* * Byte, Half-word (2 byte), and Word (4 byte) transfers +* * Four priority levels for each channel +* * Byte, half-word (2-byte), and word (4-byte) transfers * * Configurable source and destination addresses * * \section group_dma_configuration Configuration Considerations * -* To set up a DMA driver you initialize a descriptor, +* To set up a DMA driver, initialize a descriptor, * intialize and enable a channel, and enable the DMA block. * -* To set up the descriptor, provide the configuration parameters for the +* To set up a descriptor, provide the configuration parameters for the * descriptor in the \ref cy_stc_dma_descriptor_config_t structure. Then call the * \ref Cy_DMA_Descriptor_Init function to initialize the descriptor in SRAM. You can * modify the source and destination addresses dynamically by calling * \ref Cy_DMA_Descriptor_SetSrcAddress and \ref Cy_DMA_Descriptor_SetDstAddress. * -* To set up the DMA channel, provide a filled \ref cy_stc_dma_channel_config_t +* To set up a DMA channel, provide a filled \ref cy_stc_dma_channel_config_t * structure. Call the \ref Cy_DMA_Channel_Init function, specifying the channel * number. Use \ref Cy_DMA_Channel_Enable to enable the configured DMA channel. * * Call \ref Cy_DMA_Channel_Enable for each DMA channel in use. * -* The following is a simplified structure of the DMA driver API interdependences +* When configured, another peripheral typically triggers the DMA. The trigger is +* connected to the DMA using the trigger multiplexer. The trigger multiplexer +* driver has a software trigger you can use in firmware to trigger the DMA. See the +* Trigger Multiplexer documentation. +* +* The following is a simplified structure of the DMA driver API interdependencies * in a typical user application: * \image html dma.png * * NOTE: Even if a DMA channel is enabled, it is not operational until * the DMA block is enabled using function \ref Cy_DMA_Enable.\n -* NOTE: If the DMA descriptor is configured to generate an interrupt, +* NOTE: if the DMA descriptor is configured to generate an interrupt, * the interrupt must be enabled using the \ref Cy_DMA_Channel_SetInterruptMask * function for each DMA channel. * @@ -65,9 +70,9 @@ * \snippet dma/dma_v2_0_sut_00.cydsn/main_cm4.c Cy_DMA_Snippet * * \section group_dma_more_information More Information. -* -* See the DMA Component datasheet. -* See also the DMA chapter of the device technical reference manual (TRM). +* See: the DMA chapter of the device technical reference manual (TRM); +* the DMA Component datasheet; +* CE219940 - PSoC 6 MCU Multiple DMA Concatenation. * * \section group_dma_MISRA MISRA-C Compliance * The DMA driver has the following specific deviations: @@ -82,19 +87,19 @@ * * * -* -* +* * * * * -* -* +* +* * *
VersionChangesReason for Change
1.0.1Added low power support section. Minor documentation edits.Documentation update and clarification
1.0Initial version
10.3RA composite expression of 'essentially unsigned' type is being +* A composite expression of the "essentially unsigned" type is being * cast to a different type category.The value got from the bitfield physically can't exceed the enumeration -* that describes this bitfield. So the code is safety by design.The value got from the bitfield physically cannot exceed the enumeration +* that describes this bitfield. So, the code is safe by design.
14.2RAll non-null statements shall either: -* a) have at least one side effect however executed -* b) cause control flow to changeA result of a read operation is ignored when this read is just intended - to ensure the previous write operation is flushed out to the hardware.All non-null statements will either: +* a) have at least one-side effect however executed; +* b) cause the control flow to changeA Read operation result is ignored when this read is just intended +* to ensure the previous Write operation is flushed out to the hardware.
* @@ -103,23 +108,28 @@ * * * -* -* -* +* +* +* * * * * +* projects). To enable the backward compatibility support, the CY_DMA_BWC +* definition should be changed to "1". +* +* +* +* +* * * *
VersionChangesReason for Change
1.0Initial version2.0.1Changed \ref CY_DMA_BWC macro values from Boolean to numericImprovements made based on usability feedback
2.0* All the API is refactored to be consistent within itself and with the * rest of the PDL content. -* * The descriptor API is update in the next manner: -* The \ref Cy_DMA_Descriptor_Init function sets whole the bunch of descriptor -* settings, and all the rest of descriptor API is the get/set interface -* to the each of descriptor settings. -* * There is a bunch of macros to support a backward compatibility with most -* of the driver version 1.0 API, however it is strongly recommended to use +* * The descriptor API is updated as follows: +* The \ref Cy_DMA_Descriptor_Init function sets a full bunch of descriptor +* settings, and the rest of the descriptor API is a get/set interface +* to each of the descriptor settings. +* * There is a group of macros to support the backward compatibility with most +* of the driver version 1.0 API. But, it is strongly recommended to use * the new v2.0 interface in new designs (do not just copy-paste from old -* projects). To enable the backward compatibility support the CY_DMA_BWC -* definition should be changed to "true".
1.0Initial version
@@ -132,8 +142,8 @@ * \defgroup group_dma_descriptor_functions Descriptor Functions * \defgroup group_dma_channel_functions Channel Functions * \} -* \defgroup group_dma_data_structures Data structures -* \defgroup group_dma_enums Enumerated types +* \defgroup group_dma_data_structures Data Structures +* \defgroup group_dma_enums Enumerated Types */ #if !defined(CY_DMA_H) @@ -162,22 +172,22 @@ extern "C" { * \{ */ -/** Driver major version */ +/** The driver major version */ #define CY_DMA_DRV_VERSION_MAJOR 2 -/** Driver minor version */ +/** The driver minor version */ #define CY_DMA_DRV_VERSION_MINOR 0 -/** DMA driver identifier */ +/** The DMA driver identifier */ #define CY_DMA_ID (CY_PDL_DRV_ID(0x13U)) -/** DMA channel interrupt mask */ +/** The DMA channel interrupt mask */ #define CY_DMA_INTR_MASK (0x01UL) -/** Backward compatibility flag. It enables a bunch of macros which provide -* a backward compatibility with most of DMA driver version 1.0 interface. */ +/** The backward compatibility flag. Enables a group of macros which provide +* the backward compatibility with most of the DMA driver version 1.0 interface. */ #ifndef CY_DMA_BWC - #define CY_DMA_BWC (false) + #define CY_DMA_BWC (0U) #endif /** \} group_dma_macros */ @@ -230,10 +240,10 @@ typedef enum /** This enum has the options for descriptor retriggering */ typedef enum { - CY_DMA_RETDIG_IM = 0UL, /**< Retrigger immidiatelly */ - CY_DMA_RETDIG_4CYC = 1UL, /**< Retrigger after 4 SYSCLK */ - CY_DMA_RETDIG_16CYC = 2UL, /**< Retrigger after 16 SYSCLK */ - CY_DMA_WAIT_FOR_REACT = 3UL /**< Wait for trigger reactivation */ + CY_DMA_RETRIG_IM = 0UL, /**< Retrigger immediatelly */ + CY_DMA_RETRIG_4CYC = 1UL, /**< Retrigger after 4 Clk_Slow cycles */ + CY_DMA_RETRIG_16CYC = 2UL, /**< Retrigger after 16 Clk_Slow cycles */ + CY_DMA_WAIT_FOR_REACT = 3UL /**< Wait for trigger reactivation */ } cy_en_dma_retrigger_t; /** This enum has the options for the transfer size */ @@ -254,22 +264,22 @@ typedef enum typedef enum { CY_DMA_SUCCESS = 0x00UL, /**< Success. */ - CY_DMA_BAD_PARAM = CY_DMA_ID | CY_PDL_STATUS_ERROR | 0x01UL /**< Input parameters passed to DMA API are not valid. */ + CY_DMA_BAD_PARAM = CY_DMA_ID | CY_PDL_STATUS_ERROR | 0x01UL /**< The input parameters passed to the DMA API are not valid. */ } cy_en_dma_status_t; /** \} group_dma_enums */ -/** \cond Macros for conditions used by CY_ASSERT calls */ +/** \cond Macros for the conditions used by CY_ASSERT calls */ #define CY_DMA_IS_COUNT_VALID(count) (((count) >= 1UL) && ((count) <= 256UL)) #define CY_DMA_IS_INCR_VALID(incr) (((incr) >= -2048L) && ((incr) <= 2047L)) #define CY_DMA_IS_PRIORITY_VALID(prio) ((prio) <= 3UL) #define CY_DMA_IS_INTR_MASK_VALID(interrupt) (0UL == ((interrupt) & ((uint32_t) ~CY_DMA_INTR_MASK))) -#define CY_DMA_IS_RETRIGGER_VALID(retrigger) ((CY_DMA_RETDIG_IM == (retrigger)) || \ - (CY_DMA_RETDIG_4CYC == (retrigger)) || \ - (CY_DMA_RETDIG_16CYC == (retrigger)) || \ +#define CY_DMA_IS_RETRIGGER_VALID(retrigger) ((CY_DMA_RETRIG_IM == (retrigger)) || \ + (CY_DMA_RETRIG_4CYC == (retrigger)) || \ + (CY_DMA_RETRIG_16CYC == (retrigger)) || \ (CY_DMA_WAIT_FOR_REACT == (retrigger))) #define CY_DMA_IS_TRIG_TYPE_VALID(trigType) ((CY_DMA_1ELEMENT == (trigType)) || \ @@ -294,7 +304,7 @@ typedef enum #define CY_DMA_IS_DW_CH_NR_VALID(dwNr, chNr) (((0U != CPUSS_DW0_PRESENT) && (DW0 == (dwNr)) && ((chNr) < CPUSS_DW0_CH_NR)) || \ ((0U != CPUSS_DW1_PRESENT) && (DW1 == (dwNr)) && ((chNr) < CPUSS_DW1_CH_NR))) -/* Descriptor structure bitfiled definitions */ +/* The descriptor structure bit-filed definitions */ #define CY_DMA_CTL_RETRIG_Pos 0UL #define CY_DMA_CTL_RETRIG_Msk 0x3UL #define CY_DMA_CTL_INTR_TYPE_Pos 2UL @@ -330,12 +340,12 @@ typedef enum */ /** -* DMA descriptor structure type. It is a user/component-declared structure which is -* allocated in RAM and just a pointer to which is needed for DMA HW to work with it. +* DMA descriptor structure type. It is a user/component-declared structure +* allocated in RAM. The DMA HW requires a pointer to this structure to work with it. * -* For advanced users: the descriptor can be allocated even in Flash, but in this -* case user should manually predefine all the structure items with constants, -* bacause most of driver's API (especially those functions which are modifying +* For advanced users: the descriptor can be allocated even in Flash, then the user +* manually predefines all the structure items with constants, +* bacause most of the driver's API (especially functions modifying * descriptors, including \ref Cy_DMA_Descriptor_Init()) can't work with * read-only descriptors. */ @@ -353,7 +363,7 @@ typedef struct * This structure is a configuration structure pre-initialized by the user and * passed as a parameter to the \ref Cy_DMA_Descriptor_Init(). * It can be allocated in RAM/Flash (on user's choice). -* In case of RAM allocation there is a possibility to reinitialize a descriptor in runtime. +* In case of Flash allocation there is a possibility to reinitialize the descriptor in runtime. * This structure has all the parameters of the descriptor as separate parameters. * Most of these parameters are represented in the \ref cy_stc_dma_descriptor_t structure as bit fields. */ @@ -386,6 +396,8 @@ typedef struct bool preemptable; /**< Specifies if the channel is preemptable by another higher-priority channel */ uint32_t priority; /**< This parameter specifies the channel's priority */ bool enable; /**< This parameter specifies if the channel is enabled after initializing */ + bool bufferable; /**< This parameter specifies whether a write transaction can complete + without waiting for the destination to accept the write transaction data. */ } cy_stc_dma_channel_config_t; /** \} group_dma_data_structures */ @@ -412,6 +424,7 @@ __STATIC_INLINE void * Cy_DMA_GetActiveDstAddress(DW_Type const * base); void Cy_DMA_Descriptor_DeInit(cy_stc_dma_descriptor_t * descriptor); void Cy_DMA_Descriptor_SetNextDescriptor (cy_stc_dma_descriptor_t * descriptor, cy_stc_dma_descriptor_t const * nextDescriptor); + void Cy_DMA_Descriptor_SetDescriptorType (cy_stc_dma_descriptor_t * descriptor, cy_en_dma_descriptor_type_t descriptorType); __STATIC_INLINE void Cy_DMA_Descriptor_SetSrcAddress (cy_stc_dma_descriptor_t * descriptor, void const * srcAddress); __STATIC_INLINE void Cy_DMA_Descriptor_SetDstAddress (cy_stc_dma_descriptor_t * descriptor, void const * dstAddress); __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopDataCount (cy_stc_dma_descriptor_t * descriptor, uint32_t xCount); @@ -427,10 +440,10 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetDataSize (cy_stc_dma_descripto __STATIC_INLINE void Cy_DMA_Descriptor_SetSrcTransferSize (cy_stc_dma_descriptor_t * descriptor, cy_en_dma_transfer_size_t srcTransferSize); __STATIC_INLINE void Cy_DMA_Descriptor_SetDstTransferSize (cy_stc_dma_descriptor_t * descriptor, cy_en_dma_transfer_size_t dstTransferSize); __STATIC_INLINE void Cy_DMA_Descriptor_SetRetrigger (cy_stc_dma_descriptor_t * descriptor, cy_en_dma_retrigger_t retrigger); -__STATIC_INLINE void Cy_DMA_Descriptor_SetDescriptorType (cy_stc_dma_descriptor_t * descriptor, cy_en_dma_descriptor_type_t descriptorType); __STATIC_INLINE void Cy_DMA_Descriptor_SetChannelState (cy_stc_dma_descriptor_t * descriptor, cy_en_dma_channel_state_t channelState); cy_stc_dma_descriptor_t * Cy_DMA_Descriptor_GetNextDescriptor (cy_stc_dma_descriptor_t const * descriptor); +__STATIC_INLINE cy_en_dma_descriptor_type_t Cy_DMA_Descriptor_GetDescriptorType (cy_stc_dma_descriptor_t const * descriptor); __STATIC_INLINE void * Cy_DMA_Descriptor_GetSrcAddress (cy_stc_dma_descriptor_t const * descriptor); __STATIC_INLINE void * Cy_DMA_Descriptor_GetDstAddress (cy_stc_dma_descriptor_t const * descriptor); __STATIC_INLINE uint32_t Cy_DMA_Descriptor_GetXloopDataCount (cy_stc_dma_descriptor_t const * descriptor); @@ -446,7 +459,6 @@ __STATIC_INLINE cy_en_dma_data_size_t Cy_DMA_Descriptor_GetDataSize __STATIC_INLINE cy_en_dma_transfer_size_t Cy_DMA_Descriptor_GetSrcTransferSize (cy_stc_dma_descriptor_t const * descriptor); __STATIC_INLINE cy_en_dma_transfer_size_t Cy_DMA_Descriptor_GetDstTransferSize (cy_stc_dma_descriptor_t const * descriptor); __STATIC_INLINE cy_en_dma_retrigger_t Cy_DMA_Descriptor_GetRetrigger (cy_stc_dma_descriptor_t const * descriptor); -__STATIC_INLINE cy_en_dma_descriptor_type_t Cy_DMA_Descriptor_GetDescriptorType (cy_stc_dma_descriptor_t const * descriptor); __STATIC_INLINE cy_en_dma_channel_state_t Cy_DMA_Descriptor_GetChannelState (cy_stc_dma_descriptor_t const * descriptor); /** \} group_dma_descriptor_functions */ @@ -495,7 +507,7 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * * Enables the DMA block. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Enable(DW_Type * base) @@ -511,7 +523,7 @@ __STATIC_INLINE void Cy_DMA_Enable(DW_Type * base) * Disables the DMA block. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Disable(DW_Type * base) @@ -528,7 +540,7 @@ __STATIC_INLINE void Cy_DMA_Disable(DW_Type * base) * the DMA block. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \return * Returns a bit-field with all of the currently active/pending channels in the @@ -545,13 +557,13 @@ __STATIC_INLINE uint32_t Cy_DMA_GetActiveChannel(DW_Type const * base) * Function Name: Cy_DMA_GetActiveSrcAddress ****************************************************************************//** * -* Returns the source address that is being used for current transfer. +* Returns the source address being used for the current transfer. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \return -* Returns a pointer to the source of transfer. +* Returns the pointer to the source of transfer. * *******************************************************************************/ __STATIC_INLINE void * Cy_DMA_GetActiveSrcAddress(DW_Type const * base) @@ -564,13 +576,13 @@ __STATIC_INLINE void * Cy_DMA_GetActiveSrcAddress(DW_Type const * base) * Function Name: Cy_DMA_GetActiveDstAddress ****************************************************************************//** * -* Returns the destination address that is being used for the current transfer. +* Returns the destination address being used for the current transfer. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \return -* Returns a pointer to the destination of transfer. +* Returns the pointer to the destination of transfer. * *******************************************************************************/ __STATIC_INLINE void * Cy_DMA_GetActiveDstAddress(DW_Type const * base) @@ -594,7 +606,7 @@ __STATIC_INLINE void * Cy_DMA_GetActiveDstAddress(DW_Type const * base) * Sets the source address parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param srcAddress * The source address value for the descriptor. @@ -613,7 +625,7 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetSrcAddress(cy_stc_dma_descriptor_t * d * Returns the source address parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The source address value of the descriptor. @@ -632,7 +644,7 @@ __STATIC_INLINE void * Cy_DMA_Descriptor_GetSrcAddress(cy_stc_dma_descriptor_t c * Sets the destination address parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param dstAddress * The destination address value for the descriptor. @@ -651,7 +663,7 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetDstAddress(cy_stc_dma_descriptor_t * d * Returns the destination address parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The destination address value of the descriptor. @@ -670,7 +682,7 @@ __STATIC_INLINE void * Cy_DMA_Descriptor_GetDstAddress(cy_stc_dma_descriptor_t c * Sets the interrupt type parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param interruptType * The interrupt type set for the descriptor. \ref cy_en_dma_trigger_type_t @@ -689,13 +701,13 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetInterruptType(cy_stc_dma_descriptor_t * Function Name: Cy_DMA_Descriptor_GetInterruptType ****************************************************************************//** * -* Returns the Interrupt Type of the specified descriptor. +* Returns the Interrupt-Type of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* The Interrupt Type \ref cy_en_dma_trigger_type_t. +* The Interrupt-Type \ref cy_en_dma_trigger_type_t. * *******************************************************************************/ __STATIC_INLINE cy_en_dma_trigger_type_t Cy_DMA_Descriptor_GetInterruptType(cy_stc_dma_descriptor_t const * descriptor) @@ -710,10 +722,10 @@ __STATIC_INLINE cy_en_dma_trigger_type_t Cy_DMA_Descriptor_GetInterruptType(cy_s * Function Name: Cy_DMA_Descriptor_SetTriggerInType ****************************************************************************//** * -* Sets the Trigger In Type parameter for the specified descriptor. +* Sets the Trigger-In-Type parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param triggerInType * The Trigger In Type parameter \ref cy_en_dma_trigger_type_t @@ -732,13 +744,13 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetTriggerInType(cy_stc_dma_descriptor_t * Function Name: Cy_DMA_Descriptor_GetTriggerInType ****************************************************************************//** * -* Returns the Trigger In Type of the specified descriptor. +* Returns the Trigger-In-Type parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* The Trigger In Type \ref cy_en_dma_trigger_type_t +* The Trigger-In-Type \ref cy_en_dma_trigger_type_t * *******************************************************************************/ __STATIC_INLINE cy_en_dma_trigger_type_t Cy_DMA_Descriptor_GetTriggerInType(cy_stc_dma_descriptor_t const * descriptor) @@ -753,13 +765,13 @@ __STATIC_INLINE cy_en_dma_trigger_type_t Cy_DMA_Descriptor_GetTriggerInType(cy_s * Function Name: Cy_DMA_Descriptor_SetTriggerOutType ****************************************************************************//** * -* Sets the trigger-out-type parameter for the specified descriptor. +* Sets the Trigger-Out-Type parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param triggerOutType -* The trigger-out-type set for the descriptor. \ref cy_en_dma_trigger_type_t +* The Trigger-Out-Type set for the descriptor. \ref cy_en_dma_trigger_type_t * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetTriggerOutType(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_trigger_type_t triggerOutType) @@ -775,13 +787,13 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetTriggerOutType(cy_stc_dma_descriptor_t * Function Name: Cy_DMA_Descriptor_GetTriggerOutType ****************************************************************************//** * -* Returns the Trigger Out Type parameter of the specified descriptor. +* Returns the Trigger-Out-Type parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* The Trigger Out Type parameter \ref cy_en_dma_trigger_type_t. +* The Trigger-Out-Type parameter \ref cy_en_dma_trigger_type_t. * *******************************************************************************/ __STATIC_INLINE cy_en_dma_trigger_type_t Cy_DMA_Descriptor_GetTriggerOutType(cy_stc_dma_descriptor_t const * descriptor) @@ -796,13 +808,13 @@ __STATIC_INLINE cy_en_dma_trigger_type_t Cy_DMA_Descriptor_GetTriggerOutType(cy_ * Function Name: Cy_DMA_Descriptor_SetDataSize ****************************************************************************//** * -* Sets the data element size for the specified descriptor. +* Sets the Data Element Size parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param dataSize -* Data element size \ref cy_en_dma_data_size_t +* The Data Element Size \ref cy_en_dma_data_size_t * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetDataSize(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_data_size_t dataSize) @@ -818,13 +830,13 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetDataSize(cy_stc_dma_descriptor_t * des * Function Name: Cy_DMA_Descriptor_GetDataSize ****************************************************************************//** * -* Returns the data element size of the specified descriptor. +* Returns the Data Element Size parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* Data element size \ref cy_en_dma_data_size_t +* The Data Element Size \ref cy_en_dma_data_size_t. * *******************************************************************************/ __STATIC_INLINE cy_en_dma_data_size_t Cy_DMA_Descriptor_GetDataSize(cy_stc_dma_descriptor_t const * descriptor) @@ -839,14 +851,13 @@ __STATIC_INLINE cy_en_dma_data_size_t Cy_DMA_Descriptor_GetDataSize(cy_stc_dma_d * Function Name: Cy_DMA_Descriptor_SetSrcTransferSize ****************************************************************************//** * -* Sets the source transfer size for the specified descriptor. +* Sets the Source Transfer Size parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param srcTransferSize -* This parameter provides the source transfer size parameters of the descriptor. -* \ref cy_en_dma_transfer_size_t +* The Source Transfer Size \ref cy_en_dma_transfer_size_t. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetSrcTransferSize(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_transfer_size_t srcTransferSize) @@ -862,13 +873,13 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetSrcTransferSize(cy_stc_dma_descriptor_ * Function Name: Cy_DMA_Descriptor_GetSrcTransferSize ****************************************************************************//** * -* Returns the source transfer size of the specified descriptor. +* Returns the Source Transfer Size parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* Source Transfer Size \ref cy_en_dma_transfer_size_t. +* The Source Transfer Size \ref cy_en_dma_transfer_size_t. * *******************************************************************************/ __STATIC_INLINE cy_en_dma_transfer_size_t Cy_DMA_Descriptor_GetSrcTransferSize(cy_stc_dma_descriptor_t const * descriptor) @@ -883,13 +894,13 @@ __STATIC_INLINE cy_en_dma_transfer_size_t Cy_DMA_Descriptor_GetSrcTransferSize(c * Function Name: Cy_DMA_Descriptor_SetDstTransferSize ****************************************************************************//** * -* Sets the Destination Transfer Size for the specified descriptor. +* Sets the Destination Transfer Size parameter for the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param dstTransferSize -* A Destination Transfer Size \ref cy_en_dma_transfer_size_t. +* The Destination Transfer Size \ref cy_en_dma_transfer_size_t. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetDstTransferSize(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_transfer_size_t dstTransferSize) @@ -905,10 +916,10 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetDstTransferSize(cy_stc_dma_descriptor_ * Function Name: Cy_DMA_Descriptor_GetDstTransferSize ****************************************************************************//** * -* Returns the Destination Transfer Size of the specified descriptor. +* Returns the Destination Transfer Size parameter of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The Destination Transfer Size \ref cy_en_dma_transfer_size_t @@ -930,10 +941,10 @@ __STATIC_INLINE cy_en_dma_transfer_size_t Cy_DMA_Descriptor_GetDstTransferSize(c * wait for the input trigger to be deactivated. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param retrigger -* A \ref cy_en_dma_retrigger_t parameter specifies whether the controller +* The \ref cy_en_dma_retrigger_t parameter specifies whether the controller * should wait for the input trigger to be deactivated. * *******************************************************************************/ @@ -954,7 +965,7 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetRetrigger(cy_stc_dma_descriptor_t * de * wait for the input trigger to be deactivated. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The Retrigger setting \ref cy_en_dma_retrigger_t. @@ -968,33 +979,6 @@ __STATIC_INLINE cy_en_dma_retrigger_t Cy_DMA_Descriptor_GetRetrigger(cy_stc_dma_ } -/******************************************************************************* -* Function Name: Cy_DMA_Descriptor_SetDescriptorType -****************************************************************************//** -* -* Sets the descriptor's type for the specified descriptor. -* During the descriptor's type changing the Next Descriptor parameter should be -* properly replaced by \ref Cy_DMA_Descriptor_GetNextDescriptor -* (before reconfiguration) and \ref Cy_DMA_Descriptor_SetNextDescriptor (before -* reconfiguration) API functions. -* -* -* \param descriptor -* A descriptor structure instance declared by user/component. -* -* \param descriptorType -* A Descriptor Type \ref cy_en_dma_descriptor_type_t. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_DMA_Descriptor_SetDescriptorType(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_descriptor_type_t descriptorType) -{ - CY_ASSERT_L1(NULL != descriptor); - CY_ASSERT_L3(CY_DMA_IS_TYPE_VALID(descriptorType)); - - descriptor->ctl = _CLR_SET_FLD32U(descriptor->ctl, CY_DMA_CTL_TYPE, descriptorType); -} - - /******************************************************************************* * Function Name: Cy_DMA_Descriptor_GetDescriptorType ****************************************************************************//** @@ -1002,7 +986,7 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetDescriptorType(cy_stc_dma_descriptor_t * Returns the descriptor's type of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The descriptor type \ref cy_en_dma_descriptor_type_t @@ -1023,10 +1007,10 @@ __STATIC_INLINE cy_en_dma_descriptor_type_t Cy_DMA_Descriptor_GetDescriptorType( * Sets the channel state on completion of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param channelState -* The Channel State \ref cy_en_dma_channel_state_t. +* The channel state \ref cy_en_dma_channel_state_t. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetChannelState(cy_stc_dma_descriptor_t * descriptor, cy_en_dma_channel_state_t channelState) @@ -1045,7 +1029,7 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetChannelState(cy_stc_dma_descriptor_t * * Returns the channel state on completion of the specified descriptor. * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The Channel State setting \ref cy_en_dma_channel_state_t @@ -1064,20 +1048,21 @@ __STATIC_INLINE cy_en_dma_channel_state_t Cy_DMA_Descriptor_GetChannelState(cy_s ****************************************************************************//** * * Sets the number of data elements to transfer in the X loop -* for the specified descriptor. +* for the specified descriptor (for 1D or 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param xCount -* A number of data elements to transfer in the X loop. +* The number of data elements to transfer in the X loop. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopDataCount(cy_stc_dma_descriptor_t * descriptor, uint32_t xCount) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_SINGLE_TRANSFER != Cy_DMA_Descriptor_GetDescriptorType(descriptor)); CY_ASSERT_L2(CY_DMA_IS_COUNT_VALID(xCount)); - + /* Convert the data count from the user's range (1-256) into the machine range (0-255). */ descriptor->xCtl = _CLR_SET_FLD32U(descriptor->xCtl, CY_DMA_CTL_COUNT, xCount - 1UL); } @@ -1087,10 +1072,10 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopDataCount(cy_stc_dma_descriptor_t ****************************************************************************//** * * Returns the number of data elements for the X loop of the specified -* descriptor. +* descriptor (for 1D or 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The number of data elements to transfer in the X loop. @@ -1099,8 +1084,9 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopDataCount(cy_stc_dma_descriptor_t __STATIC_INLINE uint32_t Cy_DMA_Descriptor_GetXloopDataCount(cy_stc_dma_descriptor_t const * descriptor) { CY_ASSERT_L1(NULL != descriptor); - - return (_FLD2VAL(CY_DMA_CTL_COUNT, descriptor->xCtl)); + CY_ASSERT_L1(CY_DMA_SINGLE_TRANSFER != Cy_DMA_Descriptor_GetDescriptorType(descriptor)); + /* Convert the data count from the machine range (0-255) into the user's range (1-256). */ + return (_FLD2VAL(CY_DMA_CTL_COUNT, descriptor->xCtl) + 1UL); } @@ -1109,18 +1095,19 @@ __STATIC_INLINE uint32_t Cy_DMA_Descriptor_GetXloopDataCount(cy_stc_dma_descript ****************************************************************************//** * * Sets the source increment parameter for the X loop of the specified -* descriptor. +* descriptor (for 1D or 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param srcXincrement -* A value of source increment. Valid range is -2048 ... 2047. +* The value of the source increment. The valid range is -2048 ... 2047. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopSrcIncrement(cy_stc_dma_descriptor_t * descriptor, int32_t srcXincrement) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_SINGLE_TRANSFER != Cy_DMA_Descriptor_GetDescriptorType(descriptor)); CY_ASSERT_L2(CY_DMA_IS_INCR_VALID(srcXincrement)); descriptor->xCtl = _CLR_SET_FLD32U(descriptor->xCtl, CY_DMA_CTL_SRC_INCR, srcXincrement); @@ -1132,18 +1119,19 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopSrcIncrement(cy_stc_dma_descripto ****************************************************************************//** * * Returns the source increment parameter for the X loop of the specified -* descriptor. +* descriptor (for 1D or 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* The value of source increment. +* The value of the source increment. * *******************************************************************************/ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetXloopSrcIncrement(cy_stc_dma_descriptor_t const * descriptor) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_SINGLE_TRANSFER != Cy_DMA_Descriptor_GetDescriptorType(descriptor)); return ((int32_t) _FLD2VAL(CY_DMA_CTL_SRC_INCR, descriptor->xCtl)); } @@ -1154,18 +1142,19 @@ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetXloopSrcIncrement(cy_stc_dma_descri ****************************************************************************//** * * Sets the destination increment parameter for the X loop for the specified -* descriptor. +* descriptor (for 1D or 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param dstXincrement -* A value of destination increment. Valid range is -2048 ... 2047. +* The value of the destination increment. The valid range is -2048 ... 2047. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopDstIncrement(cy_stc_dma_descriptor_t * descriptor, int32_t dstXincrement) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_SINGLE_TRANSFER != Cy_DMA_Descriptor_GetDescriptorType(descriptor)); CY_ASSERT_L2(CY_DMA_IS_INCR_VALID(dstXincrement)); descriptor->xCtl = _CLR_SET_FLD32U(descriptor->xCtl, CY_DMA_CTL_DST_INCR, dstXincrement); @@ -1177,18 +1166,19 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetXloopDstIncrement(cy_stc_dma_descripto ****************************************************************************//** * * Returns the destination increment parameter for the X loop of the specified -* descriptor. +* descriptor (for 1D or 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* The value of destination increment. +* The value of the destination increment. * *******************************************************************************/ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetXloopDstIncrement(cy_stc_dma_descriptor_t const * descriptor) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_SINGLE_TRANSFER != Cy_DMA_Descriptor_GetDescriptorType(descriptor)); return ((int32_t) _FLD2VAL(CY_DMA_CTL_DST_INCR, descriptor->xCtl)); } @@ -1198,20 +1188,22 @@ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetXloopDstIncrement(cy_stc_dma_descri * Function Name: Cy_DMA_Descriptor_SetYloopDataCount ****************************************************************************//** * -* Sets the number of data elements for the Y loop of the specified descriptor. +* Sets the number of data elements for the Y loop of the specified descriptor +* (for 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param yCount -* A number of X loops to execute in the Y loop. +* The number of X loops to execute in the Y loop. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopDataCount(cy_stc_dma_descriptor_t * descriptor, uint32_t yCount) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_2D_TRANSFER == Cy_DMA_Descriptor_GetDescriptorType(descriptor)); CY_ASSERT_L2(CY_DMA_IS_COUNT_VALID(yCount)); - + /* Convert the data count from the user's range (1-256) into the machine range (0-255). */ descriptor->yCtl = _CLR_SET_FLD32U(descriptor->yCtl, CY_DMA_CTL_COUNT, yCount - 1UL); } @@ -1221,10 +1213,10 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopDataCount(cy_stc_dma_descriptor_t ****************************************************************************//** * * Returns the number of X loops to execute in the Y loop of the specified -* descriptor. +* descriptor (for 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The number of X loops to execute in the Y loop. @@ -1233,8 +1225,9 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopDataCount(cy_stc_dma_descriptor_t __STATIC_INLINE uint32_t Cy_DMA_Descriptor_GetYloopDataCount(cy_stc_dma_descriptor_t const * descriptor) { CY_ASSERT_L1(NULL != descriptor); - - return (_FLD2VAL(CY_DMA_CTL_COUNT, descriptor->yCtl)); + CY_ASSERT_L1(CY_DMA_2D_TRANSFER == Cy_DMA_Descriptor_GetDescriptorType(descriptor)); + /* Convert the data count from the machine range (0-255) into the user's range (1-256). */ + return (_FLD2VAL(CY_DMA_CTL_COUNT, descriptor->yCtl) + 1UL); } @@ -1243,18 +1236,19 @@ __STATIC_INLINE uint32_t Cy_DMA_Descriptor_GetYloopDataCount(cy_stc_dma_descript ****************************************************************************//** * * Sets the source increment parameter for the Y loop for the specified -* descriptor. +* descriptor (for 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param srcYincrement -* A value of source increment. Valid range is -2048 ... 2047. +* The value of the source increment. The valid range is -2048 ... 2047. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopSrcIncrement(cy_stc_dma_descriptor_t * descriptor, int32_t srcYincrement) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_2D_TRANSFER == Cy_DMA_Descriptor_GetDescriptorType(descriptor)); CY_ASSERT_L2(CY_DMA_IS_INCR_VALID(srcYincrement)); descriptor->yCtl = _CLR_SET_FLD32U(descriptor->yCtl, CY_DMA_CTL_SRC_INCR, srcYincrement); @@ -1266,10 +1260,10 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopSrcIncrement(cy_stc_dma_descripto ****************************************************************************//** * * Returns the source increment parameter for the outer Y of the specified -* descriptor. +* descriptor (for 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return * The value of source increment. @@ -1278,6 +1272,7 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopSrcIncrement(cy_stc_dma_descripto __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetYloopSrcIncrement(cy_stc_dma_descriptor_t const * descriptor) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_2D_TRANSFER == Cy_DMA_Descriptor_GetDescriptorType(descriptor)); return ((int32_t) _FLD2VAL(CY_DMA_CTL_SRC_INCR, descriptor->yCtl)); } @@ -1288,18 +1283,19 @@ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetYloopSrcIncrement(cy_stc_dma_descri ****************************************************************************//** * * Sets the destination increment parameter for the Y loop of the specified -* descriptor. +* descriptor (for 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \param dstYincrement -* A value of destination increment. Valid range is -2048 ... 2047. +* The value of the destination increment. Valid range is -2048 ... 2047. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopDstIncrement(cy_stc_dma_descriptor_t * descriptor, int32_t dstYincrement) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_2D_TRANSFER == Cy_DMA_Descriptor_GetDescriptorType(descriptor)); CY_ASSERT_L2(CY_DMA_IS_INCR_VALID(dstYincrement)); descriptor->yCtl = _CLR_SET_FLD32U(descriptor->yCtl, CY_DMA_CTL_DST_INCR, dstYincrement); @@ -1311,18 +1307,19 @@ __STATIC_INLINE void Cy_DMA_Descriptor_SetYloopDstIncrement(cy_stc_dma_descripto ****************************************************************************//** * * Returns the destination increment parameter for the Y loop of the specified -* descriptor. +* descriptor (for 2D descriptors only). * * \param descriptor -* A descriptor structure instance declared by user/component. +* The descriptor structure instance declared by the user/component. * * \return -* The value of destination increment. +* The value of the destination increment. * *******************************************************************************/ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetYloopDstIncrement(cy_stc_dma_descriptor_t const * descriptor) { CY_ASSERT_L1(NULL != descriptor); + CY_ASSERT_L1(CY_DMA_2D_TRANSFER == Cy_DMA_Descriptor_GetDescriptorType(descriptor)); return ((int32_t) _FLD2VAL(CY_DMA_CTL_DST_INCR, descriptor->yCtl)); } @@ -1341,16 +1338,16 @@ __STATIC_INLINE int32_t Cy_DMA_Descriptor_GetYloopDstIncrement(cy_stc_dma_descri * Function Name: Cy_DMA_Channel_SetDescriptor ****************************************************************************//** * -* Sets a descriptor as current for specified DMA channel. +* Sets a descriptor as current for the specified DMA channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \param descriptor -* This is the descriptor which will be associated with the channel. +* This is the descriptor to be associated with the channel. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Channel_SetDescriptor(DW_Type * base, uint32_t channel, cy_stc_dma_descriptor_t const * descriptor) @@ -1370,10 +1367,10 @@ __STATIC_INLINE void Cy_DMA_Channel_SetDescriptor(DW_Type * base, uint32_t chann * The function is used to enable a DMA channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Channel_Enable(DW_Type * base, uint32_t channel) @@ -1391,10 +1388,10 @@ __STATIC_INLINE void Cy_DMA_Channel_Enable(DW_Type * base, uint32_t channel) * The function is used to disable a DMA channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Channel_Disable(DW_Type * base, uint32_t channel) @@ -1412,10 +1409,10 @@ __STATIC_INLINE void Cy_DMA_Channel_Disable(DW_Type * base, uint32_t channel) * The function is used to set a priority for the DMA channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \param priority * The priority to be set for the DMA channel. The allowed values are 0,1,2,3. @@ -1434,13 +1431,13 @@ __STATIC_INLINE void Cy_DMA_Channel_SetPriority(DW_Type * base, uint32_t channel * Function Name: Cy_DMA_Channel_GetPriority ****************************************************************************//** * -* Returns the priority of DMA channel. +* Returns the priority of the DMA channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \return * The priority of the channel. @@ -1461,13 +1458,13 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetPriority(DW_Type const * base, uint32 * Returns the descriptor that is active in the channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \return -* The pointer to the descriptor that assocaited with the channel. +* The pointer to the descriptor assocaited with the channel. * *******************************************************************************/ __STATIC_INLINE cy_stc_dma_descriptor_t * Cy_DMA_Channel_GetCurrentDescriptor(DW_Type const * base, uint32_t channel) @@ -1486,13 +1483,13 @@ __STATIC_INLINE cy_stc_dma_descriptor_t * Cy_DMA_Channel_GetCurrentDescriptor(DW * Returns the interrupt status of the specified channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \return -* The status of an interrupt for specified channel. +* The status of an interrupt for the specified channel. * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatus(DW_Type const * base, uint32_t channel) @@ -1510,13 +1507,13 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatus(DW_Type const * base, * Returns the interrupt reason of the specified channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \return -* A cause \ref cy_en_dma_intr_cause_t of an interrupt. +* The cause \ref cy_en_dma_intr_cause_t of the interrupt. * *******************************************************************************/ __STATIC_INLINE cy_en_dma_intr_cause_t Cy_DMA_Channel_GetStatus(DW_Type const * base, uint32_t channel) @@ -1534,10 +1531,10 @@ __STATIC_INLINE cy_en_dma_intr_cause_t Cy_DMA_Channel_GetStatus(DW_Type const * * Clears the interrupt status of the specified channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Channel_ClearInterrupt(DW_Type * base, uint32_t channel) @@ -1556,10 +1553,10 @@ __STATIC_INLINE void Cy_DMA_Channel_ClearInterrupt(DW_Type * base, uint32_t chan * Sets the interrupt for the specified channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Channel_SetInterrupt(DW_Type * base, uint32_t channel) @@ -1574,13 +1571,13 @@ __STATIC_INLINE void Cy_DMA_Channel_SetInterrupt(DW_Type * base, uint32_t channe * Function Name: Cy_DMA_Channel_GetInterruptMask ****************************************************************************//** * -* Returns interrupt mask value of the specified channel. +* Returns the interrupt mask value of the specified channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \return * The interrupt mask value. @@ -1598,17 +1595,17 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptMask(DW_Type const * base, u * Function Name: Cy_DMA_Channel_SetInterruptMask ****************************************************************************//** * -* Sets interrupt mask value for the specified channel. +* Sets an interrupt mask value for the specified channel. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * * \param interrupt -* An interrupt mask: -* CY_DMA_INTR_MASK to enable interrupt or 0UL to disable interrupt. +* The interrupt mask: +* CY_DMA_INTR_MASK to enable the interrupt or 0UL to disable the interrupt. * *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Channel_SetInterruptMask(DW_Type * base, uint32_t channel, uint32_t interrupt) @@ -1623,14 +1620,14 @@ __STATIC_INLINE void Cy_DMA_Channel_SetInterruptMask(DW_Type * base, uint32_t ch * Function Name: Cy_DMA_Channel_GetInterruptStatusMasked ****************************************************************************//** * -* Returns logical AND of corresponding INTR and INTR_MASK fields -* in a single load operation. +* Returns the logical AND of the corresponding INTR and INTR_MASK fields +* in a single-load operation. * * \param base -* A pointer to the hardware DMA block. +* The pointer to the hardware DMA block. * * \param channel -* A channel number. +* The channel number. * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * base, uint32_t channel) @@ -1645,17 +1642,17 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * /** \} group_dma_functions */ -/** \cond Definitions to support backward compatibility, they are strongly not recommended to use in new designs */ +/** \cond The definitions to support the backward compatibility, do not use them in new designs */ #if(CY_DMA_BWC) - /* typedefs */ + /* Type definitions */ #define cy_stc_dma_chnl_config_t cy_stc_dma_channel_config_t #define cy_stc_dma_descr_t cy_stc_dma_descriptor_t #define cy_stc_dma_descr_config_t cy_stc_dma_descriptor_config_t #define cy_en_dma_trig_type_t cy_en_dma_trigger_type_t - /* structure items */ + /* Structure items */ #define DMA_Descriptor descriptor #define deact retrigger #define intrType interruptType @@ -1673,7 +1670,7 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * #define destYincr dstYincrement #define descrNext nextDescriptor - /* constants */ + /* Constants */ #define CY_DMA_CH_DISABLED (CY_DMA_CHANNEL_DISABLED) #define CY_DMA_CH_ENABLED (CY_DMA_CHANNEL_ENABLED) @@ -1696,8 +1693,12 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * #define CY_DMA_TRIGIN_DESCRCHAIN (CY_DMA_DESCR_CHAIN) #define CY_DMA_INVALID_INPUT_PARAMETERS (CY_DMA_BAD_PARAM) + + #define CY_DMA_RETDIG_IM (CY_DMA_RETRIG_IM) + #define CY_DMA_RETDIG_4CYC (CY_DMA_RETRIG_4CYC) + #define CY_DMA_RETDIG_16CYC (CY_DMA_RETRIG_16CYC) - /* descr struct items */ + /* Descriptor structure items */ #define DESCR_CTL ctl #define DESCR_SRC src #define DESCR_DST dst @@ -1705,7 +1706,7 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * #define DESCR_Y_CTL yCtl #define DESCR_NEXT_PTR nextPtr - /* descr struct bitfields */ + /* Descriptor structure bit-fields */ #define DW_DESCR_STRUCT_DESCR_CTL_WAIT_FOR_DEACT_Pos 0UL #define DW_DESCR_STRUCT_DESCR_CTL_WAIT_FOR_DEACT_Msk 0x3UL #define DW_DESCR_STRUCT_DESCR_CTL_INTR_TYPE_Pos 2UL @@ -1743,7 +1744,7 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * #define DW_DESCR_STRUCT_DESCR_NEXT_PTR_ADDR_Pos 2UL #define DW_DESCR_STRUCT_DESCR_NEXT_PTR_ADDR_Msk 0xFFFFFFFCUL - /* functions */ + /* Functions */ #define Cy_DMA_GetActiveChnl Cy_DMA_GetActiveChannel #define Cy_DMA_GetActiveSrcAddr Cy_DMA_GetActiveSrcAddress #define Cy_DMA_GetActiveDstAddr Cy_DMA_GetActiveDstAddress @@ -1775,8 +1776,8 @@ __STATIC_INLINE uint32_t Cy_DMA_Channel_GetInterruptStatusMasked(DW_Type const * /******************************************************************************* * Function Name: Cy_DMA_Descr_SetTxfrWidth ****************************************************************************//** -* This is a legacy API function, it is left here just for backward compatibility -* It is strongly not recommended to use in new designs. +* This is a legacy API function, it is left here just for the backward compatibility +* Do not use it in new designs. *******************************************************************************/ __STATIC_INLINE void Cy_DMA_Descr_SetTxfrWidth(cy_stc_dma_descr_t * descriptor, uint32_t dataElementSize, diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/efuse/cy_efuse.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/efuse/cy_efuse.c new file mode 100644 index 0000000000..00fff84925 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/efuse/cy_efuse.c @@ -0,0 +1,227 @@ +/***************************************************************************//** +* \file cy_efuse.c +* \version 1.0 +* +* \brief +* Provides API implementation of the eFuse driver. +* +******************************************************************************** +* \copyright +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +#include "cy_efuse.h" +#include "ipc/cy_ipc_drv.h" + +/** \cond INTERNAL */ +#define CY_EFUSE_OPCODE_SUCCESS (0xA0000000UL) /**< The command completed with no errors */ +#define CY_EFUSE_OPCODE_STS_Msk (0xF0000000UL) /**< The status mask of the SROM API return value */ +#define CY_EFUSE_OPCODE_INV_PROT (0xF0000001UL) /**< The API is not available in the current protection state */ +#define CY_EFUSE_OPCODE_INV_ADDR (0xF0000002UL) /**< An attempt to read byte from the out-of-bond or protected eFuse region */ +#define CY_EFUSE_OPCODE_READ_FUSE_BYTE (0x03000000UL) /**< The SROM API opcode for Read fuse byte operation */ +#define CY_EFUSE_OPCODE_OFFSET_Pos (8UL) /**< A fuse byte offset position in an opcode */ +#define CY_EFUSE_OPCODE_DATA_Msk (0xFFUL) /**< The mask for extracting data from the SROM API return value */ +#define CY_EFUSE_IPC_STRUCT (Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL)) /**< IPC structure to be used */ +#define CY_EFUSE_IPC_NOTIFY_STRUCT0 (0x1UL << CY_IPC_INTR_SYSCALL1) /**< IPC notify bit for IPC_STRUCT0 (dedicated to System Call) */ +/** \endcond */ + +static volatile uint32_t opcode; + +static cy_en_efuse_status_t ProcessOpcode(void); + +/******************************************************************************* +* Function Name: Cy_EFUSE_GetEfuseBit +****************************************************************************//** +* +* Reports the current state of a given eFuse bit-number. Consult the device TRM +* to determine the target fuse bit number. +* +* \note An attempt to read an eFuse data from a protected memory region +* will generate a HardFault. +* +* \param bitNum +* The number of the bit to read. The valid range of the bit number is +* from 0 to EFUSE_EFUSE_NR * 32 * 8 - 1 where: +* - EFUSE_EFUSE_NR is number of efuse macros in the selected device series, +* - 32 is a number of fuse bytes in one efuse macro, +* - 8 is a number of fuse bits in the byte. +* +* The EFUSE_EFUSE_NR macro is defined in the series-specific header file, e.g +* \e \/devices/psoc6/psoc63/include/psoc63_config.\e h +* +* \param bitVal +* The pointer to the location to store the bit value. +* +* \return +* \ref cy_en_efuse_status_t +* +* \funcusage +* The example below shows how to read device life-cycle register bits in +* PSoC 6: +* \snippet eFuse_v1_0_sut_00.cydsn/main_cm0p.c SNIPPET_EFUSE_READ_BIT +* +*******************************************************************************/ +cy_en_efuse_status_t Cy_EFUSE_GetEfuseBit(uint32_t bitNum, bool *bitVal) +{ + cy_en_efuse_status_t result = CY_EFUSE_BAD_PARAM; + + if (bitVal != NULL) + { + uint32_t offset = bitNum / CY_EFUSE_BITS_PER_BYTE; + uint8_t byteVal; + *bitVal = false; + + /* Read the eFuse byte */ + result = Cy_EFUSE_GetEfuseByte(offset, &byteVal); + + if (result == CY_EFUSE_SUCCESS) + { + uint32_t bitPos = bitNum % CY_EFUSE_BITS_PER_BYTE; + /* Extract the bit from the byte */ + *bitVal = (((byteVal >> bitPos) & 0x01U) != 0U); + } + } + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_EFUSE_GetEfuseByte +****************************************************************************//** +* +* Reports the current state of the eFuse byte. +* If the offset parameter is beyond the available quantities, +* zeroes will be stored to the byteVal parameter. Consult the device TRM +* to determine the target fuse byte offset. +* +* \note An attempt to read an eFuse data from a protected memory region +* will generate a HardFault. +* +* \param offset +* The offset of the byte to read. The valid range of the byte offset is +* from 0 to EFUSE_EFUSE_NR * 32 - 1 where: +* - EFUSE_EFUSE_NR is a number of efuse macros in the selected device series, +* - 32 is a number of fuse bytes in one efuse macro. +* +* The EFUSE_EFUSE_NR macro is defined in the series-specific header file, e.g +* \e \/devices/psoc6/psoc63/include/psoc63_config.\e h +* +* \param byteVal +* The pointer to the location to store eFuse data. +* +* \return +* \ref cy_en_efuse_status_t +* +* \funcusage +* The example below shows how to read a device life-cycle stage register in +* PSoC 6: +* \snippet eFuse_v1_0_sut_00.cydsn/main_cm0p.c SNIPPET_EFUSE_READ_LIFECYCLE +* +*******************************************************************************/ +cy_en_efuse_status_t Cy_EFUSE_GetEfuseByte(uint32_t offset, uint8_t *byteVal) +{ + cy_en_efuse_status_t result = CY_EFUSE_BAD_PARAM; + + if (byteVal != NULL) + { + /* Prepare opcode before calling the SROM API */ + opcode = CY_EFUSE_OPCODE_READ_FUSE_BYTE | (offset << CY_EFUSE_OPCODE_OFFSET_Pos); + + /* Send the IPC message */ + if (Cy_IPC_Drv_SendMsgPtr(CY_EFUSE_IPC_STRUCT, CY_EFUSE_IPC_NOTIFY_STRUCT0, (void*)&opcode) == CY_IPC_DRV_SUCCESS) + { + /* Wait until the IPC structure is locked */ + while(Cy_IPC_Drv_IsLockAcquired(CY_EFUSE_IPC_STRUCT) != false) + { + } + + /* The result of the SROM API call is returned to the opcode variable */ + if ((opcode & CY_EFUSE_OPCODE_STS_Msk) == CY_EFUSE_OPCODE_SUCCESS) + { + *byteVal = (uint8_t)(opcode & CY_EFUSE_OPCODE_DATA_Msk); + result = CY_EFUSE_SUCCESS; + } + else + { + result = ProcessOpcode(); + *byteVal = 0U; + } + } + else + { + result = CY_EFUSE_IPC_BUSY; + } + } + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_EFUSE_GetExternalStatus +****************************************************************************//** +* +* This function handles the case where a module such as a security image captures +* a system call from this driver and reports its own status or error code, +* for example, protection violation. In that case, a function from this +* driver returns an unknown error (see \ref cy_en_efuse_status_t). After receipt +* of an unknown error, the user may call this function to get the status +* of the capturing module. +* +* The user is responsible for parsing the content of the returned value +* and casting it to the appropriate enumeration. +* +* \return +* The error code of the previous efuse operation. +* +*******************************************************************************/ +uint32_t Cy_EFUSE_GetExternalStatus(void) +{ + return (opcode); +} + + +/******************************************************************************* +* Function Name: ProcessOpcode +****************************************************************************//** +* +* Converts System Call returns to the eFuse driver return defines. If +* an unknown error was returned, the error code can be accessed via the +* Cy_EFUSE_GetExternalStatus() function. +* +* \param opcode The value returned by a System Call. +* +* \return +* \ref cy_en_efuse_status_t +* +*******************************************************************************/ +static cy_en_efuse_status_t ProcessOpcode(void) +{ + cy_en_efuse_status_t result; + + switch(opcode) + { + case CY_EFUSE_OPCODE_INV_PROT : + { + result = CY_EFUSE_INVALID_PROTECTION; + break; + } + case CY_EFUSE_OPCODE_INV_ADDR : + { + result = CY_EFUSE_INVALID_FUSE_ADDR; + break; + } + default : + { + result = CY_EFUSE_ERR_UNC; + break; + } + } + + return (result); +} + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/efuse/cy_efuse.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/efuse/cy_efuse.h new file mode 100644 index 0000000000..9f09c5cc00 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/efuse/cy_efuse.h @@ -0,0 +1,180 @@ +/***************************************************************************//** +* \file cy_efuse.h +* \version 1.0 +* +* Provides the API declarations of the eFuse driver. +* +******************************************************************************** +* \copyright +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +#if !defined(CY_EFUSE_H) +#define CY_EFUSE_H + +/** +* \defgroup group_efuse Electronic Fuses (eFuse) +* \{ +* +* Electronic Fuses (eFuses) - non-volatile memory whose +* each bit is one-time programmable (OTP). One eFuse macro consists of +* 256 bits (32 * 8). The PSoC devices have up to 16 eFuse macros; consult the +* device-specific datasheet to determine how many macros for a particular device. +* These are implemented as a regular Advanced High-performance Bus (AHB) +* peripheral with the following characteristics: +* - eFuses are used to control the device life-cycle stage (NORMAL, SECURE, +* and SECURE_WITH_DEBUG) and the protection settings; +* - eFuse memory can be programmed (eFuse bit value changed from '0' to '1') +* only once; if an eFuse bit is blown, it cannot be cleared again; +* - programming fuses requires the associated I/O supply to be at a specific +* level: the VDDIO0 (or VDDIO if only one VDDIO is present in the package) +* supply of the device should be set to 2.5 V (±5%); +* - fuses are programmed via the PSoC Programmer tool that parses the hex file +* and extracts the necessary information; the fuse data must be located at the +* dedicated section in the hex file. For more details see +* [PSoC 6 Programming Specifications](http://www.cypress.com/documentation/programming-specifications/psoc-6-programming-specifications) +* +* \section group_efuse_configuration Configuration Considerations +* +* Efuse memory can have different organization depending on the selected device. +* Consult the device TRM to determine the efuse memory organization and +* registers bitmap on the selected device. +* +* To read fuse data use the driver [functions] (\ref group_efuse_functions). +* +* To blow fuses, define a data structure of \ref cy_stc_efuse_data_t type in the +* firmware. The structure must be placed in the special memory section, for +* this use a compiler attribute. +* Each byte in the structure corresponds to the one fuse bit in the +* device. It allows the PSoC Programmer tool to distinguish bytes that are +* being set from bytes we don't care about or with unknown values. Fill the +* structure with the following values: +* - 0x00 - Not blown; +* - 0x01 - Blown; +* - 0xFF - Ignore. +* +* After the structure is defined and the values are set, build the project and +* download the firmware. To blow fuses, the firmware must be downloaded by the +* PSoC Programmer tool. Before you download firmware, ensure that the +* conditions from the PSoC 6 Programming Specification are met. +* +* The code below shows an example of the efuse data structure +* definition to blow SECURE bit of the life-cycle stage register. +* The bits to blow are set to the EFUSE_STATE_SET value. +* \snippet eFuse_v1_0_sut_00.cydsn/main_cm0p.c SNIPPET_EFUSE_DATA_STC +* +* \section group_efuse_more_information More Information +* +* Refer to the technical reference manual (TRM) and the device datasheet. +* +* \section group_efuse_MISRA MISRA-C Compliance +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
2.3RThe character sequence // shall not be used within a comment.The comments provide a useful WEB link to the documentation.
11.5RDangerous pointer cast results in loss of volatile qualification.The removal of the volatile qualification inside the function has no +* side effects.
+* +* \section group_efuse_changelog Changelog +* +* +* +* +* +* +* +*
VersionChangesReason for Change
1.0Initial version
+* +* \defgroup group_efuse_macros Macros +* \defgroup group_efuse_functions Functions +* \defgroup group_efuse_data_structures Data Structures +* \defgroup group_efuse_enumerated_types Enumerated Types +*/ + +#include "cy_device_headers.h" +#include "syslib/cy_syslib.h" + +/*************************************** +* Macro Definitions +***************************************/ +/** +* \addtogroup group_efuse_macros +* \{ +*/ + +/** The driver major version */ +#define CY_EFUSE_DRV_VERSION_MAJOR 1 +/** The driver minor version */ +#define CY_EFUSE_DRV_VERSION_MINOR 0 +/** The eFuse driver identifier */ +#define CY_EFUSE_ID (CY_PDL_DRV_ID(0x1AUL)) +/** The number of bits in the byte */ +#define CY_EFUSE_BITS_PER_BYTE (8UL) +/** \} group_efuse_macros */ + +/*************************************** +* Enumerated Types +***************************************/ +/** +* \addtogroup group_efuse_enumerated_types +* \{ +*/ +/** This enum has the return values of the eFuse driver */ +typedef enum +{ + CY_EFUSE_SUCCESS = 0x00UL, /**< Success */ + CY_EFUSE_INVALID_PROTECTION = CY_EFUSE_ID | CY_PDL_STATUS_ERROR | 0x01UL, /**< Invalid access in the current protection state */ + CY_EFUSE_INVALID_FUSE_ADDR = CY_EFUSE_ID | CY_PDL_STATUS_ERROR | 0x02UL, /**< Invalid eFuse address */ + CY_EFUSE_BAD_PARAM = CY_EFUSE_ID | CY_PDL_STATUS_ERROR | 0x03UL, /**< One or more invalid parameters */ + CY_EFUSE_IPC_BUSY = CY_EFUSE_ID | CY_PDL_STATUS_ERROR | 0x04UL, /**< The IPC structure is already locked by another process */ + CY_EFUSE_ERR_UNC = CY_EFUSE_ID | CY_PDL_STATUS_ERROR | 0xFFUL /**< Unknown error code. See Cy_EFUSE_GetExternalStatus() */ +} cy_en_efuse_status_t; + +/** \} group_efuse_data_structure */ + +#if defined(__cplusplus) +extern "C" { +#endif +/*************************************** +* Function Prototypes +***************************************/ + +/** +* \addtogroup group_efuse_functions +* \{ +*/ +cy_en_efuse_status_t Cy_EFUSE_GetEfuseBit(uint32_t bitNum, bool *bitVal); +cy_en_efuse_status_t Cy_EFUSE_GetEfuseByte(uint32_t offset, uint8_t *byteVal); +uint32_t Cy_EFUSE_GetExternalStatus(void); +/** \} group_efuse_functions */ + +#if defined(__cplusplus) +} +#endif + + +#endif /* #if !defined(CY_EFUSE_H) */ + +/** \} group_efuse */ + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/flash/cy_flash.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/flash/cy_flash.c new file mode 100644 index 0000000000..dedf6c0dbb --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/flash/cy_flash.c @@ -0,0 +1,1273 @@ +/***************************************************************************//** +* \file cy_flash.c +* \version 3.0 +* +* \brief +* Provides the public functions for the API for the PSoC 6 Flash Driver. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ +#include "flash/cy_flash.h" +#include "sysclk/cy_sysclk.h" +#include "sysint/cy_sysint.h" +#include "ipc/cy_ipc_drv.h" +#include "ipc/cy_ipc_sema.h" +#include "ipc/cy_ipc_pipe.h" + +/*************************************** +* Data Structure definitions +***************************************/ + +/* Flash driver context */ +typedef struct +{ + uint32_t opcode; /**< Specifies the code of flash operation */ + uint32_t arg1; /**< Specifies the configuration of flash operation */ + uint32_t arg2; /**< Specifies the configuration of flash operation */ + uint32_t arg3; /**< Specifies the configuration of flash operation */ +} cy_stc_flash_context_t; + + +/*************************************** +* Macro definitions +***************************************/ + +/** \cond INTERNAL */ +/** Set SROM API in blocking mode */ +#define CY_FLASH_BLOCKING_MODE ((0x01UL) << 8UL) +/** Set SROM API in non blocking mode */ +#define CY_FLASH_NON_BLOCKING_MODE (0UL) + +/** SROM API flash region ID shift for flash row information */ +#define CY_FLASH_REGION_ID_SHIFT (16U) +#define CY_FLASH_REGION_ID_MASK (3U) +#define CY_FLASH_ROW_ID_MASK (0xFFFFU) +/** SROM API flash region IDs */ +#define CY_FLASH_REGION_ID_MAIN (0UL) +#define CY_FLASH_REGION_ID_EM_EEPROM (1UL) +#define CY_FLASH_REGION_ID_SFLASH (2UL) + +/** SROM API opcode mask */ +#define CY_FLASH_OPCODE_Msk ((0xFFUL) << 24UL) +/** SROM API opcode for flash write operation */ +#define CY_FLASH_OPCODE_WRITE_ROW ((0x05UL) << 24UL) +/** SROM API opcode for flash program operation */ +#define CY_FLASH_OPCODE_PROGRAM_ROW ((0x06UL) << 24UL) +/** SROM API opcode for row erase operation */ +#define CY_FLASH_OPCODE_ERASE_ROW ((0x1CUL) << 24UL) +/** SROM API opcode for flash checksum operation */ +#define CY_FLASH_OPCODE_CHECKSUM ((0x0BUL) << 24UL) +/** SROM API opcode for flash hash operation */ +#define CY_FLASH_OPCODE_HASH ((0x0DUL) << 24UL) +/** SROM API flash row shift for flash checksum operation */ +#define CY_FLASH_OPCODE_CHECKSUM_ROW_SHIFT (8UL) +/** SROM API flash row shift for flash checksum operation */ +#define CY_FLASH_OPCODE_CHECKSUM_REGION_SHIFT (22UL) +/** SROM API flash data size parameter for flash write operation */ +#define CY_FLASH_CONFIG_DATASIZE (CPUSS_FLASHC_PA_SIZE_LOG2 - 1UL) +/** Data to be programmed to flash is located in SRAM memory region */ +#define CY_FLASH_DATA_LOC_SRAM (0x100UL) +/** SROM API flash verification option for flash write operation */ +#define CY_FLASH_CONFIG_VERIFICATION_EN ((0x01UL) << 16u) + +/** Command completed with no errors */ +#define CY_FLASH_ROMCODE_SUCCESS (0xA0000000UL) +/** Invalid device protection state */ +#define CY_FLASH_ROMCODE_INVALID_PROTECTION (0xF0000001UL) +/** Invalid flash page latch address */ +#define CY_FLASH_ROMCODE_INVALID_FM_PL (0xF0000003UL) +/** Invalid flash address */ +#define CY_FLASH_ROMCODE_INVALID_FLASH_ADDR (0xF0000004UL) +/** Row is write protected */ +#define CY_FLASH_ROMCODE_ROW_PROTECTED (0xF0000005UL) +/** Comparison between Page Latches and FM row failed */ +#define CY_FLASH_ROMCODE_PL_ROW_COMP_FA (0xF0000022UL) +/** Command in progress; no error */ +#define CY_FLASH_ROMCODE_IN_PROGRESS_NO_ERROR (0xA0000009UL) +/** Flash operation is successfully initiated */ +#define CY_FLASH_IS_OPERATION_STARTED (0x00000010UL) +/** Flash is under operation */ +#define CY_FLASH_IS_BUSY (0x00000040UL) +/** IPC structure is already locked by another process */ +#define CY_FLASH_IS_IPC_BUSY (0x00000080UL) +/** Input parameters passed to Flash API are not valid */ +#define CY_FLASH_IS_INVALID_INPUT_PARAMETERS (0x00000100UL) + +/** Result mask */ +#define CY_FLASH_RESULT_MASK (0x0FFFFFFFUL) +/** Error shift */ +#define CY_FLASH_ERROR_SHIFT (28UL) +/** No error */ +#define CY_FLASH_ERROR_NO_ERROR (0xAUL) + +/** CM4 Flash Proxy address */ +#define CY_FLASH_CM4_FLASH_PROXY_ADDR (*(Cy_Flash_Proxy *)(0x00000D1CUL)) +typedef cy_en_flashdrv_status_t (*Cy_Flash_Proxy)(cy_stc_flash_context_t *context); + +/** IPC notify bit for IPC_STRUCT0 (dedicated to flash operation) */ +#define CY_FLASH_IPC_NOTIFY_STRUCT0 (0x1UL << CY_IPC_INTR_SYSCALL1) + +/** Disable delay */ +#define CY_FLASH_NO_DELAY (0U) + +#if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + /** Number of ticks to wait 1 uS */ + #define CY_FLASH_TICKS_FOR_1US (8U) + /** Slow control register */ + #define CY_FLASH_TST_DDFT_SLOW_CTL_REG (*(reg32 *) 0x40260108U) + /** Slow control register */ + #define CY_FLASH_TST_DDFT_FAST_CTL_REG (*(reg32 *) 0x40260104U) + /** Define to set the IMO to perform a delay after the flash operation started */ + #define CY_FLASH_TST_DDFT_SLOW_CTL_MASK (0x00001F1EUL) + /** Fast control register */ + #define CY_FLASH_TST_DDFT_FAST_CTL_MASK (62U) + /** Slow output register - output disabled */ + #define CY_FLASH_CLK_OUTPUT_DISABLED (0U) + + /* The default delay time value */ + #define CY_FLASH_DEFAULT_DELAY (150UL) + /* Calculates the time in microseconds to wait for the number of the CM0P ticks */ + #define CY_FLASH_DELAY_CORRECTIVE(ticks) ((((uint32)Cy_SysClk_ClkPeriGetDivider() + 1UL) * \ + (Cy_SysClk_ClkSlowGetDivider() + 1UL) * (ticks) * 1000UL)\ + / ((uint32_t)cy_Hfclk0FreqHz / 1000UL)) + + /* Number of the CM0P ticks for StartProgram function delay corrective time */ + #define CY_FLASH_START_PROGRAM_DELAY_TICKS (6000UL) + /* Delay time for StartProgram function in us */ + #define CY_FLASH_START_PROGRAM_DELAY_TIME (900UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_PROGRAM_DELAY_TICKS)) + /* Number of the CM0P ticks for StartErase function delay corrective time */ + #define CY_FLASH_START_ERASE_DELAY_TICKS (9500UL) + /* Delay time for StartErase function in us */ + #define CY_FLASH_START_ERASE_DELAY_TIME (2200UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_ERASE_DELAY_TICKS)) + /* Number of the CM0P ticks for StartWrite function delay corrective time */ + #define CY_FLASH_START_WRITE_DELAY_TICKS (19000UL) + /* Delay time for StartWrite function in us */ + #define CY_FLASH_START_WRITE_DELAY_TIME (9800UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_WRITE_DELAY_TICKS)) + + /** Delay time for Start Write function in us with corrective time */ + #define CY_FLASH_START_WRITE_DELAY (CY_FLASH_START_WRITE_DELAY_TIME) + /** Delay time for Start Program function in us with corrective time */ + #define CY_FLASH_START_PROGRAM_DELAY (CY_FLASH_START_PROGRAM_DELAY_TIME) + /** Delay time for Start Erase function in uS with corrective time */ + #define CY_FLASH_START_ERASE_DELAY (CY_FLASH_START_ERASE_DELAY_TIME) + + #define CY_FLASH_ENTER_WAIT_LOOP (0xFFU) + #define CY_FLASH_IPC_CLIENT_ID (2U) + + /** Semaphore number reserved for flash driver */ + #define CY_FLASH_WAIT_SEMA (0UL) + /* Semaphore check timeout (in tries) */ + #define CY_FLASH_SEMA_WAIT_MAX_TRIES (150000UL) + + typedef struct + { + uint8_t clientID; + uint8_t pktType; + uint16_t intrRelMask; + } cy_flash_notify_t; + + static void Cy_Flash_NotifyHandler(uint32_t * msgPtr); + static void Cy_Flash_RAMDelay(uint32_t microseconds); + + #if (CY_CPU_CORTEX_M0P) + #define IS_CY_PIPE_FREE(...) (!Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_CYPIPE_EP1))) + #define NOTIFY_PEER_CORE(a) Cy_IPC_Pipe_SendMessage(CY_IPC_EP_CYPIPE_CM4_ADDR, CY_IPC_EP_CYPIPE_CM0_ADDR, (a), NULL) + #else + #define IS_CY_PIPE_FREE(...) (!Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_CYPIPE_EP0))) + #define NOTIFY_PEER_CORE(a) Cy_IPC_Pipe_SendMessage(CY_IPC_EP_CYPIPE_CM0_ADDR, CY_IPC_EP_CYPIPE_CM4_ADDR, (a), NULL) + #endif + + #if (CY_CPU_CORTEX_M4) + static void Cy_Flash_ResumeIrqHandler(void); + #endif +#else /* !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) */ + /** Delay time for Start Write function in us with corrective time */ + #define CY_FLASH_START_WRITE_DELAY (CY_FLASH_NO_DELAY) + /** Delay time for Start Program function in us with corrective time */ + #define CY_FLASH_START_PROGRAM_DELAY (CY_FLASH_NO_DELAY) + /** Delay time fot Start Erase function in uS with corrective time */ + #define CY_FLASH_START_ERASE_DELAY (CY_FLASH_NO_DELAY) +#endif /* !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) */ +/** \endcond */ + + +/* Static functions */ +static bool Cy_Flash_BoundsCheck(uint32_t flashAddr); +static uint32_t Cy_Flash_GetRowNum(uint32_t flashAddr); +static cy_en_flashdrv_status_t Cy_Flash_ProcessOpcode(uint32_t opcode); +static cy_en_flashdrv_status_t Cy_Flash_OperationStatus(void); +static cy_en_flashdrv_status_t Cy_Flash_SendCmd(uint32_t mode, uint32_t microseconds); + +static volatile cy_stc_flash_context_t flashContext; + +#if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + /******************************************************************************* + * Function Name: Cy_Flash_NotifyHandler + ****************************************************************************//** + * + * This is the interrupt service routine for the pipe notifications. + * + *******************************************************************************/ + typedef struct + { + uint32_t maxSema; /* Maximum semaphores in system */ + uint32_t *arrayPtr; /* Pointer to semaphores array */ + } cy_stc_ipc_sema_t; + + #if defined (__ICCARM__) + #pragma diag_suppress=Ta023 + __ramfunc + #else + CY_SECTION(".cy_ramfunc") + #endif + static void Cy_Flash_NotifyHandler(uint32_t * msgPtr) + { + uint32_t intr; + static uint32_t semaIndex; + static uint32_t semaMask; + static volatile uint32_t *semaPtr; + static cy_stc_ipc_sema_t *semaStruct; + + cy_flash_notify_t *ipcMsgPtr = (cy_flash_notify_t *)msgPtr; + + if (CY_FLASH_ENTER_WAIT_LOOP == ipcMsgPtr->pktType) + { + intr = Cy_SysLib_EnterCriticalSection(); + + /* Get pointer to structure */ + semaStruct = (cy_stc_ipc_sema_t *)Cy_IPC_Drv_ReadDataValue(Cy_IPC_Drv_GetIpcBaseAddress( CY_IPC_CHAN_SEMA)); + + /* Get the index into the semaphore array and calculate the mask */ + semaIndex = CY_FLASH_WAIT_SEMA / CY_IPC_SEMA_PER_WORD; + semaMask = (uint32_t)(1ul << (CY_FLASH_WAIT_SEMA - (semaIndex * CY_IPC_SEMA_PER_WORD) )); + semaPtr = &semaStruct->arrayPtr[semaIndex]; + + /* Notification to the Flash driver to start the current operation */ + *semaPtr |= semaMask; + + /* Check a notification from other core to end of waiting */ + while (((*semaPtr) & semaMask) != 0ul) + { + } + + Cy_SysLib_ExitCriticalSection(intr); + } + } + #if defined (__ICCARM__) + #pragma diag_default=Ta023 + #endif +#endif + +/******************************************************************************* +* Function Name: Cy_Flash_Init +****************************************************************************//** +* +* Initiates all needed prerequisites to support flash erase/write. +* Should be called from each core. +* +* Requires a call to Cy_IPC_SystemSemaInit() and Cy_IPC_SystemPipeInit() functions +* before use. +* +* This function is called in the SystemInit() function, for proper flash write +* and erase operations. If the default startup file is not used, or the function +* SystemInit() is not called in your project, call the following three functions +* prior to executing any flash or EmEEPROM write or erase operations: +* -# Cy_IPC_SystemSemaInit() +* -# Cy_IPC_SystemPipeInit() +* -# Cy_Flash_Init() +* +*******************************************************************************/ +void Cy_Flash_Init(void) +{ + #if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + #if (CY_CPU_CORTEX_M4) + cy_stc_sysint_t flashIntConfig = + { + cpuss_interrupt_fm_IRQn, /* .intrSrc */ + 0 /* .intrPriority */ + }; + + (void)Cy_SysInt_Init(&flashIntConfig, &Cy_Flash_ResumeIrqHandler); + NVIC_EnableIRQ(flashIntConfig.intrSrc); + #endif + + (void)Cy_IPC_Pipe_RegisterCallback(CY_IPC_EP_CYPIPE_ADDR, &Cy_Flash_NotifyHandler, + (uint32_t)CY_FLASH_IPC_CLIENT_ID); + #endif +} + +/******************************************************************************* +* Function Name: Cy_Flash_SendCmd +****************************************************************************//** +* +* Sends a command to the SROM via the IPC channel. The function is placed to the +* SRAM memory to guarantee successful operation. After an IPC message is sent, +* the function waits for a defined time before exiting the function. +* +* \param mode +* Sets the blocking or non-blocking Flash operation. +* +* \param microseconds +* The number of microseconds to wait before exiting the functions +* in range 0-65535 us. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +#if defined(CY_DEVICE_PSOC6ABLE2) \ + && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) \ + && !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + #if defined (__ICCARM__) + #pragma diag_suppress=Ta023 + __ramfunc + #else + CY_SECTION(".cy_ramfunc") + #endif +#endif +static cy_en_flashdrv_status_t Cy_Flash_SendCmd(uint32_t mode, uint32_t microseconds) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_IPC_BUSY; + IPC_STRUCT_Type *ipcBase = Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL); + +#if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + + uint32_t semaTryCount = 0uL; + uint32_t intr; + + CY_ALIGN(4) static cy_flash_notify_t ipcWaitMessage = + { + /* .clientID */ CY_FLASH_IPC_CLIENT_ID, + /* .pktType */ CY_FLASH_ENTER_WAIT_LOOP, + /* .intrRelMask */ 0 + }; + + #if (CY_CPU_CORTEX_M0P) + bool isCM4Powered = (CY_SYS_CM4_STATUS_ENABLED == Cy_SysGetCM4Status()); + + if (!isCM4Powered) + { + result = CY_FLASH_DRV_SUCCESS; + } + else + { + #endif + if (IS_CY_PIPE_FREE()) + { + if (CY_IPC_SEMA_STATUS_LOCKED != Cy_IPC_Sema_Status(CY_FLASH_WAIT_SEMA)) + { + if (CY_IPC_PIPE_SUCCESS == NOTIFY_PEER_CORE(&ipcWaitMessage)) + { + /* Wait for SEMA lock by peer core */ + while ((CY_IPC_SEMA_STATUS_LOCKED != Cy_IPC_Sema_Status(CY_FLASH_WAIT_SEMA)) && ((semaTryCount < CY_FLASH_SEMA_WAIT_MAX_TRIES))) + { + /* check for timeout (as maximum tries count) */ + ++semaTryCount; + } + + if (semaTryCount < CY_FLASH_SEMA_WAIT_MAX_TRIES) + { + result = CY_FLASH_DRV_SUCCESS; + } + } + } + } + #if (CY_CPU_CORTEX_M0P) + } + #endif + + if (CY_FLASH_DRV_SUCCESS == result) + { + /* Notifier is ready, start of the operation */ + intr = Cy_SysLib_EnterCriticalSection(); + +#endif /* !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) */ + + /* Tries to acquire the IPC structure and pass the arguments to SROM API */ + if (Cy_IPC_Drv_SendMsgPtr(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL), CY_FLASH_IPC_NOTIFY_STRUCT0, + (void*)&flashContext) == CY_IPC_DRV_SUCCESS) + { + if (mode == CY_FLASH_NON_BLOCKING_MODE) + { + #if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + Cy_Flash_RAMDelay(microseconds); + #endif + + /* The Flash operation is successfully initiated */ + result = CY_FLASH_DRV_OPERATION_STARTED; + } + else + { + while (0u != _FLD2VAL(IPC_STRUCT_ACQUIRE_SUCCESS, ipcBase->LOCK_STATUS)) + { + /* Polls whether the IPC is released and the Flash operation is performed */ + } + + result = Cy_Flash_OperationStatus(); + } + } + else + { + /* The IPC structure is already locked by another process */ + result = CY_FLASH_DRV_IPC_BUSY; + } + +#if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + #if (CY_CPU_CORTEX_M0P) + if (isCM4Powered) + { + #endif + while (CY_IPC_SEMA_SUCCESS != Cy_IPC_Sema_Clear(CY_FLASH_WAIT_SEMA, true)) + { + /* Clear SEMA lock */ + } + #if (CY_CPU_CORTEX_M0P) + } + #endif + + Cy_SysLib_ExitCriticalSection(intr); + /* End of the flash operation */ + } +#endif /* !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) */ + + return (result); +} +#if defined (__ICCARM__) + #pragma diag_default=Ta023 +#endif + + +#if !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) + /******************************************************************************* + * Function Name: Cy_Flash_RAMDelay + ****************************************************************************//** + * + * Wait for a defined time in the SRAM memory region. + * + * \param microseconds + * Delay time in microseconds in range 0-65535 us. + * + *******************************************************************************/ + #if defined (__ICCARM__) + #pragma diag_suppress=Ta023 + __ramfunc + #else + CY_SECTION(".cy_ramfunc") + #endif + static void Cy_Flash_RAMDelay(uint32_t microseconds) + { + uint32_t ticks = (microseconds & 0xFFFFUL) * CY_FLASH_TICKS_FOR_1US; + if (ticks != CY_FLASH_NO_DELAY) + { + CY_FLASH_TST_DDFT_FAST_CTL_REG = CY_FLASH_TST_DDFT_FAST_CTL_MASK; + CY_FLASH_TST_DDFT_SLOW_CTL_REG = CY_FLASH_TST_DDFT_SLOW_CTL_MASK; + + SRSS->CLK_OUTPUT_SLOW = _VAL2FLD(SRSS_CLK_OUTPUT_SLOW_SLOW_SEL0, CY_SYSCLK_MEAS_CLK_IMO) | + _VAL2FLD(SRSS_CLK_OUTPUT_SLOW_SLOW_SEL1, CY_FLASH_CLK_OUTPUT_DISABLED); + + /* Load the down-counter without status bit value */ + SRSS->CLK_CAL_CNT1 = _VAL2FLD(SRSS_CLK_CAL_CNT1_CAL_COUNTER1, ticks); + + /* Make sure that the counter is started */ + ticks = _FLD2VAL(SRSS_CLK_CAL_CNT1_CAL_COUNTER_DONE, SRSS->CLK_CAL_CNT1); + + while (0UL == _FLD2VAL(SRSS_CLK_CAL_CNT1_CAL_COUNTER_DONE, SRSS->CLK_CAL_CNT1)) + { + /* Wait until the counter stops counting */ + } + } + } + #if defined (__ICCARM__) + #pragma diag_default=Ta023 + #endif + + #if (CY_CPU_CORTEX_M4) + + /* Based on bookmark codes of mxs40srompsoc BROS,002-03298 */ + #define CY_FLASH_PROGRAM_ROW_BOOKMARK (0x00000001UL) + #define CY_FLASH_ERASE_ROW_BOOKMARK (0x00000002UL) + #define CY_FLASH_WRITE_ROW_ERASE_BOOKMARK (0x00000003UL) + #define CY_FLASH_WRITE_ROW_PROGRAM_BOOKMARK (0x00000004UL) + + /* Number of the CM0P ticks for function delay corrective time at final stage */ + #define CY_FLASH_START_PROGRAM_FINAL_DELAY_TICKS (1000UL) + #define CY_FLASH_PROGRAM_ROW_DELAY (130UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_PROGRAM_FINAL_DELAY_TICKS)) + #define CY_FLASH_ERASE_ROW_DELAY (130UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_PROGRAM_FINAL_DELAY_TICKS)) + #define CY_FLASH_WRITE_ROW_ERASE_DELAY (130UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_PROGRAM_FINAL_DELAY_TICKS)) + #define CY_FLASH_WRITE_ROW_PROGRAM_DELAY (130UL + CY_FLASH_DELAY_CORRECTIVE(CY_FLASH_START_PROGRAM_FINAL_DELAY_TICKS)) + + + /******************************************************************************* + * Function Name: Cy_Flash_ResumeIrqHandler + ****************************************************************************//** + * + * This is the interrupt service routine to make additional processing of the + * flash operations resume phase. + * + *******************************************************************************/ + #if defined (__ICCARM__) + #pragma diag_suppress=Ta023 + __ramfunc + #else + CY_SECTION(".cy_ramfunc") + #endif + static void Cy_Flash_ResumeIrqHandler(void) + { + IPC_STRUCT_Type *ipcBase = Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_CYPIPE_EP0); + + uint32_t bookmark; + bookmark = FLASHC->FM_CTL.BOOKMARK & 0xffffUL; + + uint32_t cm0s = CPUSS->CM0_STATUS; + + switch (bookmark) + { + case CY_FLASH_PROGRAM_ROW_BOOKMARK: + if (cm0s == (CPUSS_CM0_STATUS_SLEEPING_Msk | CPUSS_CM0_STATUS_SLEEPDEEP_Msk)) + { + ipcBase->NOTIFY = _VAL2FLD(IPC_STRUCT_NOTIFY_INTR_NOTIFY, (1UL << CY_IPC_INTR_CYPIPE_EP0)); + } + Cy_Flash_RAMDelay(CY_FLASH_PROGRAM_ROW_DELAY); + break; + case CY_FLASH_ERASE_ROW_BOOKMARK: + if (cm0s == (CPUSS_CM0_STATUS_SLEEPING_Msk | CPUSS_CM0_STATUS_SLEEPDEEP_Msk)) + { + ipcBase->NOTIFY = _VAL2FLD(IPC_STRUCT_NOTIFY_INTR_NOTIFY, (1UL << CY_IPC_INTR_CYPIPE_EP0)); + } + Cy_Flash_RAMDelay(CY_FLASH_ERASE_ROW_DELAY); /* Delay when erase row is finished */ + break; + case CY_FLASH_WRITE_ROW_ERASE_BOOKMARK: + if (cm0s == (CPUSS_CM0_STATUS_SLEEPING_Msk | CPUSS_CM0_STATUS_SLEEPDEEP_Msk)) + { + ipcBase->NOTIFY = _VAL2FLD(IPC_STRUCT_NOTIFY_INTR_NOTIFY, (1UL << CY_IPC_INTR_CYPIPE_EP0)); + } + Cy_Flash_RAMDelay(CY_FLASH_WRITE_ROW_ERASE_DELAY); /* Delay when erase phase for row is finished */ + break; + case CY_FLASH_WRITE_ROW_PROGRAM_BOOKMARK: + if (cm0s == (CPUSS_CM0_STATUS_SLEEPING_Msk | CPUSS_CM0_STATUS_SLEEPDEEP_Msk)) + { + ipcBase->NOTIFY = _VAL2FLD(IPC_STRUCT_NOTIFY_INTR_NOTIFY, (1UL << CY_IPC_INTR_CYPIPE_EP0)); + } + Cy_Flash_RAMDelay(CY_FLASH_WRITE_ROW_PROGRAM_DELAY); + break; + default: + break; + } + } + #if defined (__ICCARM__) + #pragma diag_default=Ta023 + #endif + #endif /* (CY_CPU_CORTEX_M4) */ +#endif /* !defined(CY_FLASH_RWW_DRV_SUPPORT_DISABLED) */ + + +/******************************************************************************* +* Function Name: Cy_Flash_EraseRow +****************************************************************************//** +* +* This function erases a single row of flash. Reports success or +* a reason for failure. Does not return until the Write operation is +* complete. Returns immediately and reports a \ref CY_FLASH_DRV_IPC_BUSY error in +* the case when another process is writing to flash or erasing the row. +* +* User firmware should not enter the Hibernate or Deep-Sleep mode until flash +* Erase is complete. +* For all safe execution conditions see \ref group_flash_configuration +* documentation section. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* The Read-while-Write violation occurs when the flash read operation is +* initiated in the same flash sector where the flash write operation is +* performing. Refer to the device datasheet for the details. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_EraseRow(uint32_t rowAddr) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + + /* Prepares arguments to be passed to SROM API */ + if (Cy_Flash_BoundsCheck(rowAddr) != false) + { + SystemCoreClockUpdate(); + + flashContext.opcode = CY_FLASH_OPCODE_ERASE_ROW | CY_FLASH_BLOCKING_MODE; + flashContext.arg1 = rowAddr; + flashContext.arg2 = 0UL; + flashContext.arg3 = 0UL; + + result = Cy_Flash_SendCmd(CY_FLASH_BLOCKING_MODE, CY_FLASH_START_ERASE_DELAY); + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_ProgramRow +****************************************************************************//** +* +* This function writes an array of data to a single row of flash. Before calling +* this function, the target flash region must be erased by the +* Cy_Flash_StartErase() or Cy_Flash_EraseRow() function. +* +* Reports success or a reason for failure. Does not return until the Program +* operation is complete. Returns immediately and reports a +* \ref CY_FLASH_DRV_IPC_BUSY error in the case when another process is writing +* to flash. +* +* User firmware should not enter the Hibernate or Deep-sleep mode until flash +* Program is complete. +* For all safe execution conditions see \ref group_flash_configuration +* documentation section. +* +* Data to be programmed must be located in the SRAM memory region. +* \note Before reading data from previously programmed/erased flash rows, the +* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() +* function. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* The Read-while-Write violation occurs when the flash read operation is +* initiated in the same flash sector where the flash write operation is +* performing. Refer to the device datasheet for the details. +* +* \param data The pointer to the data which has to be written to flash. The size +* of the data array must be equal to the flash row size. The flash row size for +* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to +* the device datasheet for the details. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_ProgramRow(uint32_t rowAddr, const uint32_t* data) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + + /* Checks whether the input parameters are valid */ + if ((Cy_Flash_BoundsCheck(rowAddr) != false) && (NULL != data)) + { + SystemCoreClockUpdate(); + + /* Prepares arguments to be passed to SROM API */ + flashContext.opcode = CY_FLASH_OPCODE_PROGRAM_ROW | CY_FLASH_BLOCKING_MODE; + flashContext.arg1 = CY_FLASH_CONFIG_DATASIZE | CY_FLASH_DATA_LOC_SRAM; + flashContext.arg2 = rowAddr; + flashContext.arg3 = (uint32_t)data; + + result = Cy_Flash_SendCmd(CY_FLASH_BLOCKING_MODE, CY_FLASH_START_PROGRAM_DELAY); + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_WriteRow +****************************************************************************//** +* +* This function writes an array of data to a single row of flash. This is done +* in two steps - erase and then program flash row with the input data. +* Reports success or a reason for failure. Does not return until the Write +* operation is complete. +* Returns immediately and reports a \ref CY_FLASH_DRV_IPC_BUSY error in the case +* when another process is writing to flash. +* +* User firmware should not enter the Hibernate or Deep-sleep mode until flash +* Write is complete. +* For all safe execution conditions see \ref group_flash_configuration +* documentation section. +* +* Data to be programmed must be located in the SRAM memory region. +* \note Before reading data from previously programmed/erased flash rows, the +* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() +* function. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* The Read-while-Write violation occurs when the flash read operation is +* initiated in the same flash sector where the flash write operation is +* performing. Refer to the device datasheet for the details. +* +* \param data The pointer to the data which has to be written to flash. The size +* of the data array must be equal to the flash row size. The flash row size for +* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to +* the device datasheet for the details. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_WriteRow(uint32_t rowAddr, const uint32_t* data) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + + /* Checks whether the input parameters are valid */ + if ((Cy_Flash_BoundsCheck(rowAddr) != false) && (NULL != data)) + { + SystemCoreClockUpdate(); + + /* Prepares arguments to be passed to SROM API */ + flashContext.opcode = CY_FLASH_OPCODE_WRITE_ROW | CY_FLASH_BLOCKING_MODE; + flashContext.arg1 = 0UL; + flashContext.arg2 = rowAddr; + flashContext.arg3 = (uint32_t)data; + + result = Cy_Flash_SendCmd(CY_FLASH_BLOCKING_MODE, CY_FLASH_START_WRITE_DELAY); + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_StartWrite +****************************************************************************//** +* +* Erase flash row and performs programming of the row with the input data. +* Returns immediately and reports a successful start or reason for failure. +* Reports a \ref CY_FLASH_DRV_IPC_BUSY error in the case when another process is +* writing to flash. +* +* User firmware should not enter the Hibernate or Deep-Sleep mode until flash +* Write is complete. +* For all safe execution conditions see \ref group_flash_configuration +* documentation section. +* +* Data to be programmed must be located in the SRAM memory region. +* \note Before reading data from previously programmed/erased flash rows, the +* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() +* function. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* The Read-while-Write violation occurs when the flash read operation is +* initiated in the same flash sector where the flash write operation is +* performing. Refer to the device datasheet for the details. +* +* \param data The pointer to the data to be written to flash. The size +* of the data array must be equal to the flash row size. The flash row size for +* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to +* the device datasheet for the details. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_StartWrite(uint32_t rowAddr, const uint32_t* data) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + + /* Checks whether the input parameters are valid */ + if ((Cy_Flash_BoundsCheck(rowAddr) != false) && (NULL != data)) + { + result = Cy_Flash_StartErase(rowAddr); + + if (CY_FLASH_DRV_OPERATION_STARTED == result) + { + /* Polls whether the IPC is released and the Flash operation is performed */ + do + { + result = Cy_Flash_OperationStatus(); + } + while (result == CY_FLASH_DRV_OPCODE_BUSY); + + if (CY_FLASH_DRV_SUCCESS == result) + { + result = Cy_Flash_StartProgram(rowAddr, data); + } + } + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_IsOperationComplete +****************************************************************************//** +* +* Reports a successful operation result, reason of failure or busy status +* ( \ref CY_FLASH_DRV_OPCODE_BUSY ). +* +* \return Returns the status of the Flash operation (see \ref cy_en_flashdrv_status_t). +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_IsOperationComplete(void) +{ + return (Cy_Flash_OperationStatus()); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_StartErase +****************************************************************************//** +* +* Starts erasing a single row of flash. Returns immediately and reports a +* successful start or reason for failure. Reports a \ref CY_FLASH_DRV_IPC_BUSY +* error in the case when IPC structure is locked by another process. +* +* User firmware should not enter the Hibernate or Deep-Sleep mode until +* flash Erase is complete. +* For all safe execution conditions see \ref group_flash_configuration +* documentation section. +* +* \note Before reading data from previously programmed/erased flash rows, the +* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() +* function. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* The Read-while-Write violation occurs when the flash read operation is +* initiated in the same flash sector where the flash erase operation is +* performing. Refer to the device datasheet for the details. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_StartErase(uint32_t rowAddr) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + + if (Cy_Flash_BoundsCheck(rowAddr) != false) + { + SystemCoreClockUpdate(); + + /* Prepares arguments to be passed to SROM API */ + flashContext.opcode = CY_FLASH_OPCODE_ERASE_ROW; + flashContext.arg1 = rowAddr; + flashContext.arg2 = 0UL; + flashContext.arg3 = 0UL; + result = Cy_Flash_SendCmd(CY_FLASH_NON_BLOCKING_MODE, CY_FLASH_START_ERASE_DELAY); + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_StartProgram +****************************************************************************//** +* +* Starts writing an array of data to a single row of flash. Before calling this +* function, the target flash region must be erased by the Cy_Flash_StartErase() +* or Cy_Flash_EraseRow() function. +* +* Returns immediately and reports a successful start or reason for failure. +* Reports a \ref CY_FLASH_DRV_IPC_BUSY error if another process is writing +* to flash. +* +* The user firmware should not enter Hibernate or Deep-Sleep mode until flash +* Program is complete. +* For all safe execution conditions see \ref group_flash_configuration +* documentation section. +* +* Data to be programmed must be located in the SRAM memory region. +* \note Before reading data from previously programmed/erased flash rows, the +* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() +* function. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* The Read-while-Write violation occurs when the Flash Write operation is +* performing. Refer to the device datasheet for the details. +* +* \param data The pointer to the data to be written to flash. The size +* of the data array must be equal to the flash row size. The flash row size for +* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to +* the device datasheet for the details. +* +* \return Returns the status of the Flash operation, +* see \ref cy_en_flashdrv_status_t. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_StartProgram(uint32_t rowAddr, const uint32_t* data) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + + if ((Cy_Flash_BoundsCheck(rowAddr) != false) && (NULL != data)) + { + SystemCoreClockUpdate(); + + /* Prepares arguments to be passed to SROM API */ + flashContext.opcode = CY_FLASH_OPCODE_PROGRAM_ROW | CY_FLASH_NON_BLOCKING_MODE; + flashContext.arg1 = CY_FLASH_CONFIG_DATASIZE | CY_FLASH_DATA_LOC_SRAM; + flashContext.arg2 = rowAddr; + flashContext.arg3 = (uint32_t)data; + + result = Cy_Flash_SendCmd(CY_FLASH_NON_BLOCKING_MODE, CY_FLASH_START_PROGRAM_DELAY); + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_RowChecksum +****************************************************************************//** +* +* Returns a checksum value of the specified flash row. +* +* \note Now Cy_Flash_RowChecksum() requires the row address (rowAddr) +* as a parameter. In previous versions of the driver, this function used +* the row number (rowNum) for this parameter. +* +* \param rowAddr Address of the flash row. +* Address must match row start address otherwise API returns \ref +* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS status. The number of the flash rows +* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. +* +* \param checksumPtr The pointer to the address where checksum is to be stored +* +* \return Returns the status of the Flash operation. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_RowChecksum (uint32_t rowAddr, uint32_t* checksumPtr) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + uint32_t resTmp; + uint32_t rowID; + + /* Checks whether the input parameters are valid */ + if ((Cy_Flash_BoundsCheck(rowAddr)) && (NULL != checksumPtr)) + { + rowID = Cy_Flash_GetRowNum(rowAddr); + + /* Prepares arguments to be passed to SROM API */ + flashContext.opcode = CY_FLASH_OPCODE_CHECKSUM | + (((rowID >> CY_FLASH_REGION_ID_SHIFT) & CY_FLASH_REGION_ID_MASK) << CY_FLASH_OPCODE_CHECKSUM_REGION_SHIFT) | + ((rowID & CY_FLASH_ROW_ID_MASK) << CY_FLASH_OPCODE_CHECKSUM_ROW_SHIFT); + + /* Tries to acquire the IPC structure and pass the arguments to SROM API */ + if (Cy_IPC_Drv_SendMsgPtr(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL), CY_FLASH_IPC_NOTIFY_STRUCT0, + (void*)&flashContext) == CY_IPC_DRV_SUCCESS) + { + /* Polls whether IPC is released and the Flash operation is performed */ + while (Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL)) != false) + { + /* Wait till IPC is released */ + } + + resTmp = flashContext.opcode; + + if ((resTmp >> CY_FLASH_ERROR_SHIFT) == CY_FLASH_ERROR_NO_ERROR) + { + result = CY_FLASH_DRV_SUCCESS; + *checksumPtr = flashContext.opcode & CY_FLASH_RESULT_MASK; + } + else + { + result = Cy_Flash_ProcessOpcode(flashContext.opcode); + } + } + else + { + /* The IPC structure is already locked by another process */ + result = CY_FLASH_DRV_IPC_BUSY; + } + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_CalculateHash +****************************************************************************//** +* +* Returns a hash value of the specified region of flash. Hash calculation +* algorithm provided by SROM code. +* +* \param data Start the data address. API returns invalid address status if +* called on out of bound FLASH region. +* +* \param numberOfBytes The hash value is calculated for the number of bytes +* after the start data address (0 - 1 byte, 1- 2 bytes etc). +* +* \param hashPtr The pointer to the address where hash is to be stored +* +* \return Returns the status of the Flash operation. +* +*******************************************************************************/ +cy_en_flashdrv_status_t Cy_Flash_CalculateHash (const uint32_t* data, uint32_t numberOfBytes, uint32_t* hashPtr) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + volatile uint32_t resTmp; + + /* Checks whether the input parameters are valid */ + if ((data != NULL) && (0ul != numberOfBytes)) + { + /* Prepares arguments to be passed to SROM API */ + flashContext.opcode = CY_FLASH_OPCODE_HASH; + flashContext.arg1 = (uint32_t)data; + flashContext.arg2 = numberOfBytes; + + /* Tries to acquire the IPC structure and pass the arguments to SROM API */ + if (Cy_IPC_Drv_SendMsgPtr(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL), CY_FLASH_IPC_NOTIFY_STRUCT0, + (void*)&flashContext) == CY_IPC_DRV_SUCCESS) + { + /* Polls whether IPC is released and the Flash operation is performed */ + while (Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL)) != false) + { + /* Wait till IPC is released */ + } + + resTmp = flashContext.opcode; + + if ((resTmp >> CY_FLASH_ERROR_SHIFT) == CY_FLASH_ERROR_NO_ERROR) + { + result = CY_FLASH_DRV_SUCCESS; + *hashPtr = flashContext.opcode & CY_FLASH_RESULT_MASK; + } + else + { + result = Cy_Flash_ProcessOpcode(flashContext.opcode); + } + } + else + { + /* The IPC structure is already locked by another process */ + result = CY_FLASH_DRV_IPC_BUSY; + } + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_GetRowNum +****************************************************************************//** +* +* Returns flash region ID and row number of the Flash address. +* +* \param flashAddr Address to be checked +* +* \return +* The valid return value is encoded as follows (or 0xFFFFFFFFUL for invalid +* address) +* +*
Field Value +*
Flash row number [15:0] bits +*
Flash region ID [31:16] bits +*
+* +*******************************************************************************/ +static uint32_t Cy_Flash_GetRowNum(uint32_t flashAddr) +{ + uint32_t result; + + if ((flashAddr >= CY_FLASH_BASE) && (flashAddr < (CY_FLASH_BASE + CY_FLASH_SIZE))) + { + result = (CY_FLASH_REGION_ID_MAIN << CY_FLASH_REGION_ID_SHIFT) | + ((flashAddr - CY_FLASH_BASE) / CY_FLASH_SIZEOF_ROW); + } + else + if ((flashAddr >= CY_EM_EEPROM_BASE) && (flashAddr < (CY_EM_EEPROM_BASE + CY_EM_EEPROM_SIZE))) + { + result = (CY_FLASH_REGION_ID_EM_EEPROM << CY_FLASH_REGION_ID_SHIFT) | + ((flashAddr - CY_EM_EEPROM_BASE) / CY_FLASH_SIZEOF_ROW); + } + else + if ((flashAddr >= SFLASH_BASE) && (flashAddr < (SFLASH_BASE + SFLASH_SECTION_SIZE))) + { + result = (CY_FLASH_REGION_ID_SFLASH << CY_FLASH_REGION_ID_SHIFT) | + ((flashAddr - SFLASH_BASE) / CY_FLASH_SIZEOF_ROW); + } + else + { + result = 0xFFFFFFFFUL; + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_BoundsCheck +****************************************************************************//** +* +* Returns false if Flash address is out of boundary, otherwise returns true. +* +* \param flashAddr Address to be checked +* +* \return false - out of bound, true - in flash bounds +* +*******************************************************************************/ +static bool Cy_Flash_BoundsCheck(uint32_t flashAddr) +{ + return ((Cy_Flash_GetRowNum(flashAddr) != 0xFFFFFFFFUL) && ((flashAddr % CY_FLASH_SIZEOF_ROW) == 0UL)); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_ProcessOpcode +****************************************************************************//** +* +* Converts System Call returns to the Flash driver return defines. +* +* \param opcode The value returned by the System Call. +* +* \return Flash driver return. +* +*******************************************************************************/ +static cy_en_flashdrv_status_t Cy_Flash_ProcessOpcode(uint32_t opcode) +{ + cy_en_flashdrv_status_t result; + + switch (opcode) + { + case 0UL: + { + result = CY_FLASH_DRV_SUCCESS; + break; + } + case CY_FLASH_ROMCODE_SUCCESS: + { + result = CY_FLASH_DRV_SUCCESS; + break; + } + case CY_FLASH_ROMCODE_INVALID_PROTECTION: + { + result = CY_FLASH_DRV_INV_PROT; + break; + } + case CY_FLASH_ROMCODE_INVALID_FM_PL: + { + result = CY_FLASH_DRV_INVALID_FM_PL; + break; + } + case CY_FLASH_ROMCODE_INVALID_FLASH_ADDR: + { + result = CY_FLASH_DRV_INVALID_FLASH_ADDR; + break; + } + case CY_FLASH_ROMCODE_ROW_PROTECTED: + { + result = CY_FLASH_DRV_ROW_PROTECTED; + break; + } + case CY_FLASH_ROMCODE_IN_PROGRESS_NO_ERROR: + { + result = CY_FLASH_DRV_PROGRESS_NO_ERROR; + break; + } + case (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS: + { + result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + break; + } + case CY_FLASH_IS_OPERATION_STARTED : + { + result = CY_FLASH_DRV_OPERATION_STARTED; + break; + } + case CY_FLASH_IS_BUSY : + { + result = CY_FLASH_DRV_OPCODE_BUSY; + break; + } + case CY_FLASH_IS_IPC_BUSY : + { + result = CY_FLASH_DRV_IPC_BUSY; + break; + } + case CY_FLASH_IS_INVALID_INPUT_PARAMETERS : + { + result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; + break; + } + default: + { + result = CY_FLASH_DRV_ERR_UNC; + break; + } + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_OperationStatus +****************************************************************************//** +* +* Checks the status of the Flash Operation, and returns it. +* +* \return Returns the status of the Flash operation +* (see \ref cy_en_flashdrv_status_t). +* +*******************************************************************************/ +static cy_en_flashdrv_status_t Cy_Flash_OperationStatus(void) +{ + cy_en_flashdrv_status_t result = CY_FLASH_DRV_OPCODE_BUSY; + + /* Checks if the IPC structure is not locked */ + if (Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_CHAN_SYSCALL)) == false) + { + /* The result of SROM API calling is returned to the driver context */ + result = Cy_Flash_ProcessOpcode(flashContext.opcode); + + /* Clear pre-fetch cache after flash operation */ +#if (CY_CPU_CORTEX_M0P) + FLASHC->CM0_CA_CMD = FLASHC_CM0_CA_CMD_INV_Msk; +#else + FLASHC->CM4_CA_CMD = FLASHC_CM4_CA_CMD_INV_Msk; +#endif /* (CY_CPU_CORTEX_M0P) */ + + while ((FLASHC->CM0_CA_CMD != 0U) || (FLASHC->CM4_CA_CMD != 0U)) + { + } + } + + return (result); +} + + +/******************************************************************************* +* Function Name: Cy_Flash_GetExternalStatus +****************************************************************************//** +* +* This function handles the case where a module such as security image captures +* a system call from this driver and reports its own status or error code, +* for example protection violation. In that case, a function from this +* driver returns an unknown error (see \ref cy_en_flashdrv_status_t). After receipt +* of an unknown error, the user may call this function to get the status +* of the capturing module. +* +* The user is responsible for parsing the content of the returned value +* and casting it to the appropriate enumeration. +* +* \return +* The error code that was stored in the opcode variable. +* +*******************************************************************************/ +uint32_t Cy_Flash_GetExternalStatus(void) +{ + return (flashContext.opcode); +} + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/flash/cy_flash.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/flash/cy_flash.h new file mode 100644 index 0000000000..f46e32e003 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/flash/cy_flash.h @@ -0,0 +1,407 @@ +/***************************************************************************//** +* \file cy_flash.h +* \version 3.0 +* +* Provides the API declarations of the Flash driver. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +#if !defined(CY_FLASH_H) +#define CY_FLASH_H + +/** +* \defgroup group_flash Flash System Routine (Flash) +* \{ +* Internal flash memory programming +* +* Flash memory in PSoC devices provides non-volatile storage for user firmware, +* user configuration data, and bulk data storage. +* +* Flash operations are implemented as system calls. System calls are executed +* out of SROM in the privileged mode of operation. Users have no access to read +* or modify the SROM code. The driver API requests the system call by acquiring +* the Inter-processor communication (IPC) and writing the SROM function opcode +* and parameters to its input registers. As a result, an NMI interrupt is invoked +* and the requested SROM API is executed. The operation status is returned to the +* driver context and a release interrupt is triggered. +* +* Writing to flash can take up to 20 milliseconds. During this time, +* the device should not be reset (including XRES pin, software reset, and +* watchdog) or unexpected changes may be made to portions of the flash. +* Also, the low-voltage detect circuits should be configured to generate an +* interrupt instead of a reset. +* +* A Read while Write violation occurs when a flash Read operation is initiated +* in the same or neighboring flash sector where the flash Write, Erase, or +* Program operation is working. This violation may cause a HardFault exception. +* To avoid the Read while Write violation, the user must carefully split the +* Read and Write operation on flash sectors which are not neighboring, +* considering both cores in the multi-processor device. The flash is divided +* into four equal sectors. You may edit the linker script to place the code +* into neighboring sectors. For example, use sectors number 0 and 1 for code +* and sectors 2 and 3 for data storage. +* +* \section group_flash_configuration Configuration Considerations +* +* \subsection group_flash_config_intro Introduction: +* The PSoC 6 MCU user-programmable Flash consists of: +* - Up to four User Flash sectors (0 through 3) - 256KB each. +* - EEPROM emulation sector - 32KB. +* +* Write operations are performed on a per-sector basis and may be done as +* Blocking or Partially Blocking, defined as follows: +* +* \subsection group_flash_config_blocking Blocking: +* In this case, the entire Flash block is not available for the duration of the +* Write (up to 20 milliseconds). Therefore, no Flash accesses +* (from any Bus Master) can occur during that time. CPU execution can be +* performed from SRAM. All pre-fetching must be disabled. Application code +* execution from Flash is blocked for the Flash Write duration for both cores. +* +* \subsection group_flash_config_block_const Constraints for Blocking Flash operations: +* -# During write to flash, the device should not be reset (including XRES pin, +* software reset, and watchdog), or unexpected changes may be made to portions +* of the flash. +* -# The low-voltage detect circuits should be configured to generate an +* interrupt instead of a reset. +* -# Flash write operation is allowed only in one of the following CM4 states: +* -# CM4 is Active and initialized:
+* call \ref Cy_SysEnableCM4 "Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR)". +* Note: If desired user may put CM4 core in Deep Sleep any time +* after calling Cy_SysEnableCM4(). +* -# CM4 is Off:
+* call Cy_SysDisableCM4(). Note: In this state Debug mode is not +* supported. +* . +* -# Flash write cannot be performed in ULP (core voltage 0.9V) mode. +* -# Interrupts must be enabled on both active cores. Do not enter a critical +* section during flash operation. +* -# User must guarantee that system pipe interrupts (IPC interrupts 3 and 4) +* have the highest priority, or at least that pipe interrupts are not +* interrupted or in a pending state for more than 700 µs. +* -# User must guarantee that during flash write operation no flash read +* operations are performed by bus masters other than CM0+ and CM4 (DMA and +* Crypto). +* -# If you do not use the default startup, ensure that firmware calls the +* following functions before any flash write/erase operations: +* \snippet Flash_sut_01.cydsn/main_cm0p.c Flash Initialization +* +* \subsection group_flash_config_rww Partially Blocking: +* This method has a much shorter time window during which Flash accesses are not +* allowed. Application code execution from Flash is blocked for only a part of +* Flash Write duration, for both cores. Blocking duration depends upon the API +* sequence used. +* +* For API sequence Cy_Flash_StartErase() + Cy_Flash_StartProgram() there are +* four block-out regions during which the read is blocked using the software +* driver (PDL). See Figure 1. +* +*
+* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
Table 1 - Block-out periods
Block-outPhaseDuration
AThe beginning of the Erase operation2ms + 9500 SlowClk cycles
BThe end of the Erase operation0.13ms + 1000 SlowClk cycles
CThe beginning of the Program operation0.8ms + 6000 SlowClk cycles
DThe end of the Program operation0.13ms + 1000 SlowClk cycles
+*
+* +* This allows both cores to execute an application for about 80% of Flash Write +* operation - see Figure 1. +* This capability is important for communication protocols that rely on fast +* response. +* +* \image html flash-rww-diagram.png "Figure 1 - Blocking Intervals in Flash Write operation" width=70% +* +* For the Cy_Flash_StartWrite() function, the block-out period is different for +* the two cores. The core that initiates Cy_Flash_StartWrite() is blocked for +* two periods: +* - From start of Erase operation (start of A on Figure 1) till the start of +* Program operation (end of C on Figure 1). +* - During D period on Figure 1. +* +* The core that performs read/execute is blocked identically to the +* Cy_Flash_StartErase() + Cy_Flash_StartProgram() sequence - see Figure 1. +* +* This allows the core that initiates Cy_Flash_StartWrite() to execute an +* application for about 20% of the Flash Write operation. The other core executes +* the application for about 80% of the Flash Write operation. +* +* Some constraints must be planned for in the Partially Blocking mode which are +* described in detail below. +* +* \subsection group_flash_config_rww_const Constraints for Partially Blocking Flash operations: +* -# During write to flash, the device should not be reset (including XRES pin, +* software reset, and watchdog) or unexpected changes may be made to portions +* of the flash. +* -# The low-voltage detect circuits should be configured to generate an +* interrupt instead of a reset. +* -# During write to flash, application code should not change the clock +* settings. Use Cy_Flash_IsOperationComplete() to ensure flash write +* operation is finished. +* -# Flash write operation is allowed only in one of the following CM4 states: +* -# CM4 is Active and initialized:
+* call \ref Cy_SysEnableCM4 "Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR)". +* Note: If desired user may put CM4 core in Deep Sleep any time +* after calling Cy_SysEnableCM4(). +* -# CM4 is Off:
+* call Cy_SysDisableCM4(). Note: In this state Debug mode is not +* supported. +* . +* -# Use the following rules for split by sectors. (In this context, read means +* read of any bus master: CM0+, CM4, DMA, Crypto, etc.) +* -# Do not write to and read/execute from the same flash sector at the same +* time. This is true for all sectors. +* -# Writing rules in User Flash: +* -# Any bus master can read/execute from UFLASH S0 and/or S1, during +* flash write to UFLASH S2 or S3. +* -# Any bus master can read/execute from UFLASH S2 and/or S3, during +* flash write to UFLASH S0 or S1. +* +* Suggestion: in case of bootloading, it is recommended to place +* code for CM4 in either S0 or S1. CM0+ code resides in S0. Write data +* to S2 and S3 sections. +* . +* -# Flash write cannot be performed in ULP mode (core voltage 0.9V). +* -# Interrupts must be enabled on both active cores. Do not enter a critical +* section during flash operation. +* -# User must guarantee that system pipe interrupts (IPC interrupts 3 and 4) +* have the highest priority, or at least that pipe interrupts are not +* interrupted or in a pending state for more than 700 µs. +* -# User must guarantee that during flash write operation no flash read +* operations are performed by bus masters other than CM0+ and CM4 +* (DMA and Crypto). +* -# If you do not use the default startup, ensure that firmware calls the +* following functions before any flash write/erase operations: +* \snippet Flash_sut_01.cydsn/main_cm0p.c Flash Initialization +* +* \subsection group_flash_config_emeeprom EEPROM section use: +* If you plan to use "cy_em_eeprom" section for different purposes for both of +* device cores or use Em_EEPROM Middleware together with flash driver +* write operations you must modify the linker scripts.
+* For more information, refer to the Middleware/Cypress Em_EEPROM Middleware +* Library section of the PDL documentation. +* +* \section group_flash_more_information More Information +* +* See the technical reference manual (TRM) for more information about the Flash +* architecture. +* +* \section group_flash_MISRA MISRA-C Compliance +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
11.4ACasting to different object pointer type.The cast of the uint32_t pointer to pipe message structure pointer +* is used to get transmitted data via the \ref group_ipc channel. +* We cast only one pointer, so there is no way to avoid this cast.
11.5RNot performed, the cast that removes any const or volatile qualification from the type addressed by a pointer.The removal of the volatile qualification inside the function has no side effects.
+* +* \section group_flash_changelog Changelog +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
VersionChangesReason for Change
3.0New function - Cy_Flash_ProgramRow();
+* Updated Cy_Flash_RowChecksum(): changed input parameter to take the +* row address (rowAddr) instead of the row number +* (rowNum);
+* Renamed macro for disabling RWW support in driver to +* CY_FLASH_RWW_DRV_SUPPORT_DISABLED.
+* Updated \ref group_flash_configuration documentation section with +* flash usage constraints.
Improvements made based on usability feedback to use a common +* interface
2.0Added non-blocking erase function - Cy_Flash_StartErase(). +* Removed the clear cache function call.The clear cache operation is removed from the blocking Write/Erase +* function because in this case it is performed by the hardware. +* Otherwise it is documented that it is the user's responsibility to +* clear the cache after executing the non-blocking Write/Erase flash +* operation.
Added new Cy_Flash_IsOperationComplete() function to check completeness. +* Obsoleted Cy_Flash_IsWriteComplete(), Cy_Flash_IsProgramComplete(), +* and Cy_Flash_IsEraseComplete() functions.
+* Added Cy_Flash_GetExternalStatus() function to get unparsed status where +* flash driver will be used in security applications with other modules +* as SecureImage.
+* Added Cy_Flash_Init() function to initialize all needed prerequisites +* for Erase/Write operations.
Updated driver design to improve user experience.
Updated driver implementation to remove MISRA rules deviations.Driver implementation quality improvement.
1.0Initial version
+* +* \defgroup group_flash_macros Macros +* \{ +* \defgroup group_flash_general_macros Flash general parameters +* Provides general information about flash +* \} +* \defgroup group_flash_functions Functions +* \defgroup group_flash_enumerated_types Enumerated Types +*/ + +#include +#include "syslib/cy_syslib.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/*************************************** +* Macro definitions +***************************************/ +/** +* \addtogroup group_flash_macros +* \{ +*/ + +/** Driver major version */ +#define CY_FLASH_DRV_VERSION_MAJOR 3 + +/** Driver minor version */ +#define CY_FLASH_DRV_VERSION_MINOR 0 + +#define CY_FLASH_ID (CY_PDL_DRV_ID(0x14UL)) /**< FLASH PDL ID */ + +#define CY_FLASH_ID_INFO (uint32_t)( CY_FLASH_ID | CY_PDL_STATUS_INFO ) /**< Return prefix for FLASH driver function status codes */ +#define CY_FLASH_ID_WARNING (uint32_t)( CY_FLASH_ID | CY_PDL_STATUS_WARNING) /**< Return prefix for FLASH driver function warning return values */ +#define CY_FLASH_ID_ERROR (uint32_t)( CY_FLASH_ID | CY_PDL_STATUS_ERROR) /**< Return prefix for FLASH driver function error return values */ + +/** \} group_flash_macros */ + + +/** +* \addtogroup group_flash_general_macros +* \{ +*/ + +/** Flash row size */ +#define CY_FLASH_SIZEOF_ROW (CPUSS_FLASHC_PA_SIZE * 4u) +/** Number of flash rows */ +#define CY_FLASH_NUMBER_ROWS (CY_FLASH_SIZE / CY_FLASH_SIZEOF_ROW) +/** Long words flash row size */ +#define CY_FLASH_SIZEOF_ROW_LONG_UNITS (CY_FLASH_SIZEOF_ROW / sizeof(uint32_t)) + +/** \} group_flash_general_macros */ + + +/** +* \addtogroup group_flash_enumerated_types +* \{ +*/ + +/** This enum has the return values of the Flash driver */ +typedef enum cy_en_flashdrv_status +{ + CY_FLASH_DRV_SUCCESS = 0x00UL, /**< Success */ + CY_FLASH_DRV_INV_PROT = ( CY_FLASH_ID_ERROR + 0x0UL), /**< Invalid device protection state */ + CY_FLASH_DRV_INVALID_FM_PL = ( CY_FLASH_ID_ERROR + 0x1UL), /**< Invalid flash page latch address */ + CY_FLASH_DRV_INVALID_FLASH_ADDR = ( CY_FLASH_ID_ERROR + 0x2UL), /**< Invalid flash address */ + CY_FLASH_DRV_ROW_PROTECTED = ( CY_FLASH_ID_ERROR + 0x3UL), /**< Row is write protected */ + CY_FLASH_DRV_IPC_BUSY = ( CY_FLASH_ID_ERROR + 0x5UL), /**< IPC structure is already locked by another process */ + CY_FLASH_DRV_INVALID_INPUT_PARAMETERS = ( CY_FLASH_ID_ERROR + 0x6UL), /**< Input parameters passed to Flash API are not valid */ + CY_FLASH_DRV_PL_ROW_COMP_FA = ( CY_FLASH_ID_ERROR + 0x22UL), /**< Comparison between Page Latches and FM row failed */ + CY_FLASH_DRV_ERR_UNC = ( CY_FLASH_ID_ERROR + 0xFFUL), /**< Unknown error code. See \ref Cy_Flash_GetExternalStatus() */ + CY_FLASH_DRV_PROGRESS_NO_ERROR = ( CY_FLASH_ID_INFO + 0x0UL), /**< Command in progress; no error */ + CY_FLASH_DRV_OPERATION_STARTED = ( CY_FLASH_ID_INFO + 0x1UL), /**< Flash operation is successfully initiated */ + CY_FLASH_DRV_OPCODE_BUSY = ( CY_FLASH_ID_INFO + 0x2UL) /**< Flash is under operation */ +} cy_en_flashdrv_status_t; + +/** \} group_flash_enumerated_types */ + +/*************************************** +* Function Prototypes +***************************************/ + +/** +* \addtogroup group_flash_functions +* \{ +*/ +void Cy_Flash_Init(void); +cy_en_flashdrv_status_t Cy_Flash_EraseRow(uint32_t rowAddr); +cy_en_flashdrv_status_t Cy_Flash_ProgramRow(uint32_t rowAddr, const uint32_t* data); +cy_en_flashdrv_status_t Cy_Flash_WriteRow(uint32_t rowAddr, const uint32_t* data); +cy_en_flashdrv_status_t Cy_Flash_StartWrite(uint32_t rowAddr, const uint32_t* data); +cy_en_flashdrv_status_t Cy_Flash_StartProgram(uint32_t rowAddr, const uint32_t* data); +cy_en_flashdrv_status_t Cy_Flash_StartErase(uint32_t rowAddr); +cy_en_flashdrv_status_t Cy_Flash_IsOperationComplete(void); +cy_en_flashdrv_status_t Cy_Flash_RowChecksum(uint32_t rowAddr, uint32_t* checksumPtr); +cy_en_flashdrv_status_t Cy_Flash_CalculateHash(const uint32_t* data, uint32_t numberOfBytes, uint32_t* hashPtr); +uint32_t Cy_Flash_GetExternalStatus(void); +/** \} group_flash_functions */ + +/** \cond INTERNAL */ +/* Macros to backward compatibility */ +#define Cy_Flash_IsWriteComplete(...) Cy_Flash_IsOperationComplete() +#define Cy_Flash_IsProgramComplete(...) Cy_Flash_IsOperationComplete() +#define Cy_Flash_IsEraseComplete(...) Cy_Flash_IsOperationComplete() +/** \endcond */ + +#if defined(__cplusplus) +} +#endif + + +#endif /* #if !defined(CY_FLASH_H) */ + +/** \} group_flash */ + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/gpio/cy_gpio.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/gpio/cy_gpio.c new file mode 100644 index 0000000000..c6bbfb8159 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/gpio/cy_gpio.c @@ -0,0 +1,264 @@ +/***************************************************************************//** +* \file cy_gpio.c +* \version 1.10.1 +* +* \brief +* Provides an API implementation of the GPIO driver +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +#include "cy_gpio.h" + +#if defined(__cplusplus) +extern "C" { +#endif + + +/******************************************************************************* +* Function Name: Cy_GPIO_Pin_Init +****************************************************************************//** +* +* \brief Initializes all pin configuration settings for the specified pin. +* +* \param base +* Pointer to the pin's port register base address +* +* \param pinNum +* Position of the pin bit-field within the port register +* +* \param config +* Pointer to the pin config structure base address +* +* \return +* Initialization status +* +* \note +* This function modifies port registers in read-modify-write operations. It is +* not thread safe as the resource is shared among multiple pins on a port. +* +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Pin_Init +* +*******************************************************************************/ +cy_en_gpio_status_t Cy_GPIO_Pin_Init(GPIO_PRT_Type *base, uint32_t pinNum, const cy_stc_gpio_pin_config_t *config) +{ + cy_en_gpio_status_t status = CY_GPIO_SUCCESS; + uint32_t maskCfgOut; + uint32_t tempReg; + + if((NULL != base) && (NULL != config)) + { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->outVal)); + CY_ASSERT_L2(CY_GPIO_IS_DM_VALID(config->driveMode)); + CY_ASSERT_L2(CY_GPIO_IS_HSIOM_VALID(config->hsiom)); + CY_ASSERT_L2(CY_GPIO_IS_INT_EDGE_VALID(config->intEdge)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->intMask)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->vtrip)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->slewRate)); + CY_ASSERT_L2(CY_GPIO_IS_DRIVE_SEL_VALID(config->driveSel)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->vregEn)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->ibufMode)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(config->vtripSel)); + CY_ASSERT_L2(CY_GPIO_IS_VREF_SEL_VALID(config->vrefSel)); + CY_ASSERT_L2(CY_GPIO_IS_VOH_SEL_VALID(config->vohSel)); + + Cy_GPIO_Write(base, pinNum, config->outVal); + Cy_GPIO_SetDrivemode(base, pinNum, config->driveMode); + Cy_GPIO_SetHSIOM(base, pinNum, config->hsiom); + + Cy_GPIO_SetInterruptEdge(base, pinNum, config->intEdge); + Cy_GPIO_SetInterruptMask(base, pinNum, config->intMask); + Cy_GPIO_SetVtrip(base, pinNum, config->vtrip); + + /* Slew rate and Driver strength */ + maskCfgOut = (CY_GPIO_CFG_OUT_SLOW_MASK << pinNum) + | (CY_GPIO_CFG_OUT_DRIVE_SEL_MASK << ((uint32_t)(pinNum << 1u) + CY_GPIO_CFG_OUT_DRIVE_OFFSET)); + tempReg = base->CFG_OUT & ~(maskCfgOut); + base->CFG_OUT = tempReg | ((config->slewRate & CY_GPIO_CFG_OUT_SLOW_MASK) << pinNum) + | ((config->driveSel & CY_GPIO_CFG_OUT_DRIVE_SEL_MASK) << ((uint32_t)(pinNum << 1u) + CY_GPIO_CFG_OUT_DRIVE_OFFSET)); + + /* SIO specific configuration */ + tempReg = base->CFG_SIO & ~(CY_GPIO_SIO_PIN_MASK); + base->CFG_SIO = tempReg | (((config->vregEn & CY_GPIO_VREG_EN_MASK) + | ((config->ibufMode & CY_GPIO_IBUF_MASK) << CY_GPIO_IBUF_SHIFT) + | ((config->vtripSel & CY_GPIO_VTRIP_SEL_MASK) << CY_GPIO_VTRIP_SEL_SHIFT) + | ((config->vrefSel & CY_GPIO_VREF_SEL_MASK) << CY_GPIO_VREF_SEL_SHIFT) + | ((config->vohSel & CY_GPIO_VOH_SEL_MASK) << CY_GPIO_VOH_SEL_SHIFT)) + << ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET)); + } + else + { + status = CY_GPIO_BAD_PARAM; + } + + return(status); +} + + +/******************************************************************************* +* Function Name: Cy_GPIO_Port_Init +****************************************************************************//** +* +* \brief Initialize a complete port of pins from a single init structure. +* +* The configuration structure used in this function has a 1:1 mapping to the +* GPIO and HSIOM registers. Refer to the device Technical Reference Manual (TRM) +* for the register details on how to populate them. +* +* \param base +* Pointer to the pin's port register base address +* +* \param config +* Pointer to the pin config structure base address +* +* \return +* Initialization status +* +* \note +* If using the PSoC Creator IDE, there is no need to initialize the pins when +* using the GPIO component on the schematic. Ports are configured in +* Cy_SystemInit() before main() entry. +* +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Port_Init +* +*******************************************************************************/ +cy_en_gpio_status_t Cy_GPIO_Port_Init(GPIO_PRT_Type* base, const cy_stc_gpio_prt_config_t *config) +{ + cy_en_gpio_status_t status = CY_GPIO_SUCCESS; + uint32_t portNum; + HSIOM_PRT_Type* baseHSIOM; + + if((NULL != base) && (NULL != config)) + { + CY_ASSERT_L2(CY_GPIO_IS_PIN_BIT_VALID(config->out)); + CY_ASSERT_L2(CY_GPIO_IS_PIN_BIT_VALID(config->cfgIn)); + CY_ASSERT_L2(CY_GPIO_IS_INTR_CFG_VALID(config->intrCfg)); + CY_ASSERT_L2(CY_GPIO_IS_INTR_MASK_VALID(config->intrMask)); + CY_ASSERT_L2(CY_GPIO_IS_SEL_ACT_VALID(config->sel0Active)); + CY_ASSERT_L2(CY_GPIO_IS_SEL_ACT_VALID(config->sel1Active)); + + portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; + baseHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); + + base->OUT = config->out; + base->CFG = config->cfg; + base->CFG_IN = config->cfgIn; + base->CFG_OUT = config->cfgOut; + base->INTR_CFG = config->intrCfg; + base->INTR_MASK = config->intrMask; + base->CFG_SIO = config->cfgSIO; + baseHSIOM->PORT_SEL0 = config->sel0Active; + baseHSIOM->PORT_SEL1 = config->sel1Active; + } + else + { + status = CY_GPIO_BAD_PARAM; + } + + return(status); +} + + +/******************************************************************************* +* Function Name: Cy_GPIO_Pin_FastInit +****************************************************************************//** +* +* \brief Initialize the most common configuration settings for all pin types. +* +* These include, drive mode, initial output value, and HSIOM connection. +* +* \param base +* Pointer to the pin's port register base address +* +* \param pinNum +* Position of the pin bit-field within the port register +* +* \param driveMode +* Pin drive mode. Options are detailed in \ref group_gpio_driveModes macros +* +* \param outVal +* Logic state of the output buffer driven to the pin (1 or 0) +* +* \param hsiom +* HSIOM input selection +* +* \return +* void +* +* \note +* This function modifies port registers in read-modify-write operations. It is +* not thread safe as the resource is shared among multiple pins on a port. +* +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Pin_FastInit +* +*******************************************************************************/ +void Cy_GPIO_Pin_FastInit(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t driveMode, + uint32_t outVal, en_hsiom_sel_t hsiom) +{ + uint32_t tempReg; + + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_DM_VALID(driveMode)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(outVal)); + CY_ASSERT_L2(CY_GPIO_IS_HSIOM_VALID(hsiom)); + + tempReg = (base->OUT & ~(CY_GPIO_OUT_MASK << pinNum)); + base->OUT = tempReg | ((outVal & CY_GPIO_OUT_MASK) << pinNum); + + tempReg = (base->CFG & ~(CY_GPIO_CFG_DM_MASK << (pinNum << CY_GPIO_DRIVE_MODE_OFFSET))); + base->CFG = tempReg | ((driveMode & CY_GPIO_CFG_DM_MASK) << (pinNum << CY_GPIO_DRIVE_MODE_OFFSET)); + + Cy_GPIO_SetHSIOM(base, pinNum, hsiom); +} + + +/******************************************************************************* +* Function Name: Cy_GPIO_Port_Deinit +****************************************************************************//** +* +* \brief Reset a complete port of pins back to power on reset defaults. +* +* \param base +* Pointer to the pin's port register base address +* +* \return +* void +* +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Port_Deinit +* +*******************************************************************************/ +void Cy_GPIO_Port_Deinit(GPIO_PRT_Type* base) +{ + uint32_t portNum; + HSIOM_PRT_Type* portAddrHSIOM; + + portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; + portAddrHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); + + base->OUT = CY_GPIO_PRT_DEINIT; + base->CFG = CY_GPIO_PRT_DEINIT; + base->CFG_IN = CY_GPIO_PRT_DEINIT; + base->CFG_OUT = CY_GPIO_PRT_DEINIT; + base->INTR_CFG = CY_GPIO_PRT_DEINIT; + base->INTR_MASK = CY_GPIO_PRT_DEINIT; + base->CFG_SIO = CY_GPIO_PRT_DEINIT; + portAddrHSIOM->PORT_SEL0 = CY_GPIO_PRT_DEINIT; + portAddrHSIOM->PORT_SEL1 = CY_GPIO_PRT_DEINIT; +} + +#if defined(__cplusplus) +} +#endif + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/gpio/cy_gpio.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/gpio/cy_gpio.h similarity index 79% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/gpio/cy_gpio.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/gpio/cy_gpio.h index e806024627..2d29840b8e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/gpio/cy_gpio.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/gpio/cy_gpio.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_gpio.h -* \version 1.0 +* \version 1.10.1 * * \brief * Provides an API declaration of the GPIO driver * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -41,7 +41,7 @@ * * \section group_gpio_configuration Configuration Considerations * -* 1. Pin muxing is controlled through the High-Speed IO Matrix (HSIOM) selection. +* 1. Pin multiplexing is controlled through the High-Speed IO Matrix (HSIOM) selection. * This allows the pin to connect to signal sources/sinks throughout the device, * as defined by the pin HSIOM selection options (en_hsiom_sel_t). * 2. All pins are initialized to High-Z drive mode with HSIOM connected to CPU (SW @@ -50,26 +50,56 @@ * registers. These functions are not thread safe and care must be taken when * called by the application. * -* The whole gpio port can be updated using the port mask by direct port -* register writing. The code example below shows the different ways of -* manipulating Port#1 using the Port output data register, -* the Port output data set register, and the Port output data clear register: -* -* \snippet gpio_sut_01.cydsn/main_cm4.c Cy_GPIO_Snippet +* Multiple pins on a port can be updated using direct port register writes with an +* appropriate port mask. An example is shown below, highlighting the different ways of +* configuring Port 1 pins using, +* +* - Port output data register +* - Port output data set register +* - Port output data clear register * +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c Cy_GPIO_Snippet * * \section group_gpio_more_information More Information * * Refer to the technical reference manual (TRM) and the device datasheet. * * \section group_gpio_MISRA MISRA-C Compliance] -* -* The gpio driver does not have any specific deviations. +* +* +* +* +* +* +* +* +* +* +* +* +* +*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
16.7AA pointer parameter in a function prototype should be declared as pointer +* to const if the pointer is not used to modify the addressed object.The objects pointed to by the base addresses of the GPIO port are not always modified. +* While a const qualifier can be used in select scenarios, it brings little benefit +* in adding this to the affected functions.
* * \section group_gpio_changelog Changelog * * * +* +* +* +* +* +* +* +* +* +* * * * @@ -84,8 +114,8 @@ * \defgroup group_gpio_functions_sio SIO Functions * \defgroup group_gpio_functions_interrupt Port Interrupt Functions * \} -* \defgroup group_gpio_data_structures Data structures -* \defgroup group_gpio_enums Enumerated types +* \defgroup group_gpio_data_structures Data Structures +* \defgroup group_gpio_enums Enumerated Types */ #if !defined(CY_GPIO_H) @@ -107,7 +137,7 @@ extern "C" { #define CY_GPIO_DRV_VERSION_MAJOR 1 /** Driver minor version */ -#define CY_GPIO_DRV_VERSION_MINOR 0 +#define CY_GPIO_DRV_VERSION_MINOR 10 /** GPIO driver ID */ #define CY_GPIO_ID CY_PDL_DRV_ID(0x16u) @@ -225,7 +255,59 @@ typedef struct { #define CY_GPIO_INTR_FILT_OFFSET (18UL) /**< Offset for filtered interrupt config */ #define CY_GPIO_CFG_SIO_OFFSET (2UL) /**< Offset for SIO config */ -#define CY_GPIO_ZERO (0UL) /**< Constant zero */ +/* Parameter validation constants */ +#define CY_GPIO_PINS_MAX (8UL) /**< Number of pins in the port */ +#define CY_GPIO_PRT_PINS_MASK (0x0000000FFUL) +#define CY_GPIO_PRT_INTR_CFG_EDGE_SEL_MASK (GPIO_PRT_INTR_CFG_EDGE0_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE1_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE2_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE3_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE4_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE5_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE6_SEL_Msk | \ + GPIO_PRT_INTR_CFG_EDGE7_SEL_Msk) +#define CY_GPIO_PRT_INTR_CFG_RANGE_MASK (CY_GPIO_PRT_INTR_CFG_EDGE_SEL_MASK | \ + GPIO_PRT_INTR_CFG_FLT_EDGE_SEL_Msk | \ + GPIO_PRT_INTR_CFG_FLT_SEL_Msk) +#define CY_GPIO_PRT_INT_MASK_MASK (0x0000001FFUL) +#define CY_GPIO_PRT_SEL_ACTIVE_MASK (0x1FFFFFFFUL) + +/* Parameter validation macros */ +#define CY_GPIO_IS_PIN_VALID(pinNum) (CY_GPIO_PINS_MAX > (pinNum)) +#define CY_GPIO_IS_FILTER_PIN_VALID(pinNum) (CY_GPIO_PINS_MAX >= (pinNum)) +#define CY_GPIO_IS_VALUE_VALID(outVal) (1UL >= (outVal)) +#define CY_GPIO_IS_DM_VALID(driveMode) (0U == ((driveMode) & (uint32_t)~CY_GPIO_CFG_DM_MASK)) + +#define CY_GPIO_IS_HSIOM_VALID(hsiom) (0U == ((hsiom) & (uint32_t)~CY_GPIO_HSIOM_MASK)) + +#define CY_GPIO_IS_INT_EDGE_VALID(intEdge) ((CY_GPIO_INTR_DISABLE == (intEdge)) || \ + (CY_GPIO_INTR_RISING == (intEdge)) || \ + (CY_GPIO_INTR_FALLING == (intEdge)) || \ + (CY_GPIO_INTR_BOTH == (intEdge))) + +#define CY_GPIO_IS_DRIVE_SEL_VALID(driveSel) ((CY_GPIO_DRIVE_FULL == (driveSel)) || \ + (CY_GPIO_DRIVE_1_2 == (driveSel)) || \ + (CY_GPIO_DRIVE_1_4 == (driveSel)) || \ + (CY_GPIO_DRIVE_1_8 == (driveSel))) + +#define CY_GPIO_IS_VREF_SEL_VALID(vrefSel) ((CY_SIO_VREF_PINREF == (vrefSel)) || \ + (CY_SIO_VREF_1_2V == (vrefSel)) || \ + (CY_SIO_VREF_AMUX_A == (vrefSel)) || \ + (CY_SIO_VREF_AMUX_B == (vrefSel))) + +#define CY_GPIO_IS_VOH_SEL_VALID(vrefSel) ((CY_SIO_VOH_1_00 == (vrefSel)) || \ + (CY_SIO_VOH_1_25 == (vrefSel)) || \ + (CY_SIO_VOH_1_49 == (vrefSel)) || \ + (CY_SIO_VOH_1_67 == (vrefSel)) || \ + (CY_SIO_VOH_2_08 == (vrefSel)) || \ + (CY_SIO_VOH_2_50 == (vrefSel)) || \ + (CY_SIO_VOH_2_78 == (vrefSel)) || \ + (CY_SIO_VOH_4_16 == (vrefSel))) + +#define CY_GPIO_IS_PIN_BIT_VALID(pinBit) (0U == ((pinBit) & (uint32_t)~CY_GPIO_PRT_PINS_MASK)) +#define CY_GPIO_IS_INTR_CFG_VALID(intrCfg) (0U == ((intrCfg) & (uint32_t)~CY_GPIO_PRT_INTR_CFG_RANGE_MASK)) +#define CY_GPIO_IS_INTR_MASK_VALID(intrMask) (0U == ((intrMask) & (uint32_t)~CY_GPIO_PRT_INT_MASK_MASK)) +#define CY_GPIO_IS_SEL_ACT_VALID(selActive) (0U == ((selActive) & (uint32_t)~CY_GPIO_PRT_SEL_ACTIVE_MASK)) /** \endcond */ @@ -373,9 +455,8 @@ typedef struct { cy_en_gpio_status_t Cy_GPIO_Pin_Init(GPIO_PRT_Type* base, uint32_t pinNum, const cy_stc_gpio_pin_config_t *config); cy_en_gpio_status_t Cy_GPIO_Port_Init(GPIO_PRT_Type* base, const cy_stc_gpio_prt_config_t *config); -__STATIC_INLINE void Cy_GPIO_Pin_FastInit(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t driveMode, - uint32_t outVal, en_hsiom_sel_t hsiom); -__STATIC_INLINE void Cy_GPIO_Port_Deinit(GPIO_PRT_Type* base); +void Cy_GPIO_Pin_FastInit(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t driveMode, uint32_t outVal, en_hsiom_sel_t hsiom); +void Cy_GPIO_Port_Deinit(GPIO_PRT_Type* base); __STATIC_INLINE void Cy_GPIO_SetHSIOM(GPIO_PRT_Type* base, uint32_t pinNum, en_hsiom_sel_t value); __STATIC_INLINE en_hsiom_sel_t Cy_GPIO_GetHSIOM(GPIO_PRT_Type* base, uint32_t pinNum); __STATIC_INLINE GPIO_PRT_Type* Cy_GPIO_PortToAddr(uint32_t portNum); @@ -462,100 +543,6 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause3(void); * \{ */ -/******************************************************************************* -* Function Name: Cy_GPIO_Pin_FastInit -****************************************************************************//** -* -* \brief Initialize the most common configuration settings for all pin types. -* -* These include, drive mode, initial output value, and HSIOM connection. -* -* \param base -* Pointer to the pin's port register base address -* -* \param pinNum -* Position of the pin bit-field within the port register -* -* \param driveMode -* Pin drive mode. Options are detailed in \ref group_gpio_driveModes macros -* -* \param outVal -* Logic state of the output buffer driven to the pin (1 or 0) -* -* \param hsiom -* HSIOM input selection -* -* \return -* void -* -* \note -* This function modifies port registers in read-modify-write operations. It is -* not thread safe as the resource is shared among multiple pins on a port. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_GPIO_Pin_FastInit(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t driveMode, - uint32_t outVal, en_hsiom_sel_t hsiom) -{ - uint32_t tempReg; - uint32_t portNum; - HSIOM_PRT_Type* portAddrHSIOM; - - tempReg = (base->OUT & ~(CY_GPIO_OUT_MASK << pinNum)); - base->OUT = tempReg | ((outVal & CY_GPIO_OUT_MASK) << pinNum); - - tempReg = (base->CFG & ~(CY_GPIO_CFG_DM_MASK << (pinNum << CY_GPIO_DRIVE_MODE_OFFSET))); - base->CFG = tempReg | ((driveMode & CY_GPIO_CFG_DM_MASK) << (pinNum << CY_GPIO_DRIVE_MODE_OFFSET)); - - portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; - portAddrHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); - - if(pinNum < CY_GPIO_PRT_HALF) - { - tempReg = portAddrHSIOM->PORT_SEL0 & ~(CY_GPIO_HSIOM_MASK << (pinNum << CY_GPIO_HSIOM_OFFSET)); - portAddrHSIOM->PORT_SEL0 = tempReg | ((hsiom & CY_GPIO_HSIOM_MASK) << (pinNum << CY_GPIO_HSIOM_OFFSET)); - } - else - { - pinNum -= CY_GPIO_PRT_HALF; - tempReg = portAddrHSIOM->PORT_SEL1 & ~(CY_GPIO_HSIOM_MASK << (pinNum << CY_GPIO_HSIOM_OFFSET)); - portAddrHSIOM->PORT_SEL1 = tempReg | ((hsiom & CY_GPIO_HSIOM_MASK) << (pinNum << CY_GPIO_HSIOM_OFFSET)); - } -} - - -/******************************************************************************* -* Function Name: Cy_GPIO_Port_Deinit -****************************************************************************//** -* -* \brief Reset a complete port of pins back to power on reset defaults. -* -* \param base -* Pointer to the pin's port register base address -* -* \return -* void -* -*******************************************************************************/ -__STATIC_INLINE void Cy_GPIO_Port_Deinit(GPIO_PRT_Type* base) -{ - uint32_t portNum; - HSIOM_PRT_Type* portAddrHSIOM; - - portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; - portAddrHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); - - base->OUT = CY_GPIO_PRT_DEINIT; - base->CFG = CY_GPIO_PRT_DEINIT; - base->CFG_IN = CY_GPIO_PRT_DEINIT; - base->CFG_OUT = CY_GPIO_PRT_DEINIT; - base->INTR_CFG = CY_GPIO_PRT_DEINIT; - base->INTR_MASK = CY_GPIO_PRT_DEINIT; - base->CFG_SIO = CY_GPIO_PRT_DEINIT; - portAddrHSIOM->PORT_SEL0 = CY_GPIO_PRT_DEINIT; - portAddrHSIOM->PORT_SEL1 = CY_GPIO_PRT_DEINIT; -} - - /******************************************************************************* * Function Name: Cy_GPIO_SetHSIOM ****************************************************************************//** @@ -581,6 +568,9 @@ __STATIC_INLINE void Cy_GPIO_Port_Deinit(GPIO_PRT_Type* base) * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetHSIOM +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetHSIOM(GPIO_PRT_Type* base, uint32_t pinNum, en_hsiom_sel_t value) { @@ -588,6 +578,9 @@ __STATIC_INLINE void Cy_GPIO_SetHSIOM(GPIO_PRT_Type* base, uint32_t pinNum, en_h uint32_t tempReg; HSIOM_PRT_Type* portAddrHSIOM; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_HSIOM_VALID(value)); + portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; portAddrHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); @@ -620,12 +613,17 @@ __STATIC_INLINE void Cy_GPIO_SetHSIOM(GPIO_PRT_Type* base, uint32_t pinNum, en_h * \return * HSIOM input selection * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetHSIOM +* *******************************************************************************/ __STATIC_INLINE en_hsiom_sel_t Cy_GPIO_GetHSIOM(GPIO_PRT_Type* base, uint32_t pinNum) { uint32_t returnValue; uint32_t portNum; HSIOM_PRT_Type* portAddrHSIOM; + + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; portAddrHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); @@ -659,11 +657,14 @@ __STATIC_INLINE en_hsiom_sel_t Cy_GPIO_GetHSIOM(GPIO_PRT_Type* base, uint32_t pi * \return * Base address of the port register structure * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_PortToAddr +* *******************************************************************************/ __STATIC_INLINE GPIO_PRT_Type* Cy_GPIO_PortToAddr(uint32_t portNum) { GPIO_PRT_Type* base; - + if(portNum < (uint32_t)IOSS_GPIO_GPIO_PORT_NR) { base = (GPIO_PRT_Type *)(GPIO_BASE + (GPIO_PRT_SECTION_SIZE * portNum)); @@ -694,14 +695,20 @@ __STATIC_INLINE GPIO_PRT_Type* Cy_GPIO_PortToAddr(uint32_t portNum) * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \return * Logic level present on the pin * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Read +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_Read(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + return (base->IN >> (pinNum)) & CY_GPIO_IN_MASK; } @@ -727,11 +734,17 @@ __STATIC_INLINE uint32_t Cy_GPIO_Read(GPIO_PRT_Type* base, uint32_t pinNum) * \return * void * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Write +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_Write(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + /* Thread-safe: Directly access the pin registers instead of base->OUT */ - if(CY_GPIO_ZERO == value) + if(0UL == value) { base->OUT_CLR = CY_GPIO_OUT_MASK << pinNum; } @@ -757,9 +770,14 @@ __STATIC_INLINE void Cy_GPIO_Write(GPIO_PRT_Type* base, uint32_t pinNum, uint32_ * \return * Logic level on the pin output driver * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_ReadOut +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_ReadOut(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->OUT >> pinNum) & CY_GPIO_OUT_MASK; } @@ -782,9 +800,14 @@ __STATIC_INLINE uint32_t Cy_GPIO_ReadOut(GPIO_PRT_Type* base, uint32_t pinNum) * \return * void * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Set +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_Set(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + base->OUT_SET = CY_GPIO_OUT_MASK << pinNum; } @@ -807,9 +830,14 @@ __STATIC_INLINE void Cy_GPIO_Set(GPIO_PRT_Type* base, uint32_t pinNum) * \return * void * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Clr +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_Clr(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + base->OUT_CLR = CY_GPIO_OUT_MASK << pinNum; } @@ -833,9 +861,14 @@ __STATIC_INLINE void Cy_GPIO_Clr(GPIO_PRT_Type* base, uint32_t pinNum) * \return * void * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_Inv +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_Inv(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + base->OUT_INV = CY_GPIO_OUT_MASK << pinNum; } @@ -867,12 +900,18 @@ __STATIC_INLINE void Cy_GPIO_Inv(GPIO_PRT_Type* base, uint32_t pinNum) * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetDrivemode +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetDrivemode(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_DM_VALID(value)); + pinLoc = pinNum << CY_GPIO_DRIVE_MODE_OFFSET; tempReg = (base->CFG & ~(CY_GPIO_CFG_DM_MASK << pinLoc)); base->CFG = tempReg | ((value & CY_GPIO_CFG_DM_MASK) << pinLoc); @@ -894,9 +933,14 @@ __STATIC_INLINE void Cy_GPIO_SetDrivemode(GPIO_PRT_Type* base, uint32_t pinNum, * \return * Pin drive mode. Options are detailed in \ref group_gpio_driveModes macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetDrivemode +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetDrivemode(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG >> (pinNum << CY_GPIO_DRIVE_MODE_OFFSET)) & CY_GPIO_CFG_DM_MASK; } @@ -923,11 +967,17 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetDrivemode(GPIO_PRT_Type* base, uint32_t pinN * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVtrip +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetVtrip(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + tempReg = base->CFG_IN & ~(CY_GPIO_CFG_IN_VTRIP_SEL_MASK << pinNum); base->CFG_IN = tempReg | ((value & CY_GPIO_CFG_IN_VTRIP_SEL_MASK) << pinNum); } @@ -948,9 +998,14 @@ __STATIC_INLINE void Cy_GPIO_SetVtrip(GPIO_PRT_Type* base, uint32_t pinNum, uint * \return * Pin voltage threshold mode. Options are detailed in \ref group_gpio_vtrip macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVtrip +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetVtrip(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_IN >> pinNum) & CY_GPIO_CFG_IN_VTRIP_SEL_MASK; } @@ -977,11 +1032,17 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetVtrip(GPIO_PRT_Type* base, uint32_t pinNum) * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetSlewRate +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetSlewRate(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + tempReg = base->CFG_OUT & ~(CY_GPIO_CFG_OUT_SLOW_MASK << pinNum); base->CFG_OUT = tempReg | ((value & CY_GPIO_CFG_OUT_SLOW_MASK) << pinNum); } @@ -1002,9 +1063,14 @@ __STATIC_INLINE void Cy_GPIO_SetSlewRate(GPIO_PRT_Type* base, uint32_t pinNum, u * \return * Pin slew rate. Options are detailed in \ref group_gpio_slewRate macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetSlewRate +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetSlewRate(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_OUT >> pinNum) & CY_GPIO_CFG_OUT_SLOW_MASK; } @@ -1031,13 +1097,19 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetSlewRate(GPIO_PRT_Type* base, uint32_t pinNu * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetDriveSel +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetDriveSel(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; - pinLoc = pinNum + CY_GPIO_CFG_OUT_DRIVE_OFFSET; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_DRIVE_SEL_VALID(value)); + + pinLoc = (uint32_t)(pinNum << 1u) + CY_GPIO_CFG_OUT_DRIVE_OFFSET; tempReg = base->CFG_OUT & ~(CY_GPIO_CFG_OUT_DRIVE_SEL_MASK << pinLoc); base->CFG_OUT = tempReg | ((value & CY_GPIO_CFG_OUT_DRIVE_SEL_MASK) << pinLoc); } @@ -1058,10 +1130,16 @@ __STATIC_INLINE void Cy_GPIO_SetDriveSel(GPIO_PRT_Type* base, uint32_t pinNum, u * \return * Pin drive strength. Options are detailed in \ref group_gpio_driveStrength macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetDriveSel +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetDriveSel(GPIO_PRT_Type* base, uint32_t pinNum) { - return (base->CFG_OUT >> (pinNum + CY_GPIO_CFG_OUT_DRIVE_OFFSET)) & CY_GPIO_CFG_OUT_DRIVE_SEL_MASK; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + + return ((base->CFG_OUT >> ((uint32_t)(pinNum << 1u) + CY_GPIO_CFG_OUT_DRIVE_OFFSET)) + & CY_GPIO_CFG_OUT_DRIVE_SEL_MASK); } /** \} group_gpio_functions_gpio */ @@ -1095,12 +1173,18 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetDriveSel(GPIO_PRT_Type* base, uint32_t pinNu * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVregEn +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetVregEn(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + pinLoc = (pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET; tempReg = base->CFG_SIO & ~(CY_GPIO_VREG_EN_MASK << pinLoc); base->CFG_SIO = tempReg | ((value & CY_GPIO_VREG_EN_MASK) << pinLoc); @@ -1124,9 +1208,14 @@ __STATIC_INLINE void Cy_GPIO_SetVregEn(GPIO_PRT_Type* base, uint32_t pinNum, uin * \return * SIO pair output buffer regulator mode. Options are detailed in \ref group_gpio_sioVreg macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVregEn +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetVregEn(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_SIO >> ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET)) & CY_GPIO_VREG_EN_MASK; } @@ -1155,12 +1244,18 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetVregEn(GPIO_PRT_Type* base, uint32_t pinNum) * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetIbufMode +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetIbufMode(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + pinLoc = ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_IBUF_SHIFT; tempReg = (base->CFG_SIO & ~(CY_GPIO_IBUF_MASK << pinLoc)); base->CFG_SIO = tempReg | ((value & CY_GPIO_IBUF_MASK) << pinLoc); @@ -1184,9 +1279,14 @@ __STATIC_INLINE void Cy_GPIO_SetIbufMode(GPIO_PRT_Type* base, uint32_t pinNum, u * \return * SIO pair input buffer mode. Options are detailed in \ref group_gpio_sioIbuf macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetIbufMode +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetIbufMode(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_SIO >> (((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_IBUF_SHIFT)) & CY_GPIO_IBUF_MASK; } @@ -1215,12 +1315,18 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetIbufMode(GPIO_PRT_Type* base, uint32_t pinNu * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVtripSel +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetVtripSel(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + pinLoc = ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_VTRIP_SEL_SHIFT; tempReg = (base->CFG_SIO & ~(CY_GPIO_VTRIP_SEL_MASK << pinLoc)); base->CFG_SIO = tempReg | ((value & CY_GPIO_VTRIP_SEL_MASK) << pinLoc); @@ -1244,9 +1350,14 @@ __STATIC_INLINE void Cy_GPIO_SetVtripSel(GPIO_PRT_Type* base, uint32_t pinNum, u * \return * SIO pair input buffer trip point. Options are detailed in \ref group_gpio_sioVtrip macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVtripSel +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetVtripSel(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_SIO >> (((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_VTRIP_SEL_SHIFT)) & CY_GPIO_VTRIP_SEL_MASK; } @@ -1275,12 +1386,18 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetVtripSel(GPIO_PRT_Type* base, uint32_t pinNu * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVrefSel +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetVrefSel(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VREF_SEL_VALID(value)); + pinLoc = ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_VREF_SEL_SHIFT; tempReg = (base->CFG_SIO & ~(CY_GPIO_VREF_SEL_MASK << pinLoc)); base->CFG_SIO = tempReg | ((value & CY_GPIO_VREF_SEL_MASK) << pinLoc); @@ -1304,9 +1421,14 @@ __STATIC_INLINE void Cy_GPIO_SetVrefSel(GPIO_PRT_Type* base, uint32_t pinNum, ui * \return * SIO pair reference voltage. Options are detailed in \ref group_gpio_sioVref macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVrefSel +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetVrefSel(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_SIO >> (((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_VREF_SEL_SHIFT)) & CY_GPIO_VREF_SEL_MASK; } @@ -1338,12 +1460,18 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetVrefSel(GPIO_PRT_Type* base, uint32_t pinNum * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVohSel +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetVohSel(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VOH_SEL_VALID(value)); + pinLoc = ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_VOH_SEL_SHIFT; tempReg = (base->CFG_SIO & ~(CY_GPIO_VOH_SEL_MASK << pinLoc)); base->CFG_SIO = tempReg | ((value & CY_GPIO_VOH_SEL_MASK) << pinLoc); @@ -1367,9 +1495,14 @@ __STATIC_INLINE void Cy_GPIO_SetVohSel(GPIO_PRT_Type* base, uint32_t pinNum, uin * \return * SIO pair reference voltage. Options are detailed in \ref group_gpio_sioVoh macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetVohSel +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetVohSel(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(pinNum)); + return (base->CFG_SIO >> (((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET) + CY_GPIO_VOH_SEL_SHIFT)) & CY_GPIO_VOH_SEL_MASK; } @@ -1384,21 +1517,31 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetVohSel(GPIO_PRT_Type* base, uint32_t pinNum) * Function Name: Cy_GPIO_GetInterruptStatus ****************************************************************************//** * -* \brief Return the current interrupt state of the pin. +* \brief Returns the current unmasked interrupt state of the pin. +* +* The core processor's NVIC is triggered by the masked interrupt bits. This +* function allows reading the unmasked interrupt state. Whether the bit +* positions actually trigger the interrupt are defined by the interrupt mask bits. * * \param base * Pointer to the pin's port register base address * * \param pinNum * Position of the pin bit-field within the port register +* Bit position 8 is the routed pin through the port glitch filter. * * \return * 0 = Pin interrupt condition not detected * 1 = Pin interrupt condition detected * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_GetInterruptStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptStatus(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + return (base->INTR >> pinNum) & CY_GPIO_INTR_STATUS_MASK; } @@ -1414,13 +1557,19 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptStatus(GPIO_PRT_Type* base, uint32_ * * \param pinNum * Position of the pin bit-field within the port register +* Bit position 8 is the routed pin through the port glitch filter. * * \return * void * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_ClearInterrupt +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_ClearInterrupt(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + /* Any INTR MMIO registers AHB clearing must be preceded with an AHB read access */ (void)base->INTR; @@ -1441,7 +1590,8 @@ __STATIC_INLINE void Cy_GPIO_ClearInterrupt(GPIO_PRT_Type* base, uint32_t pinNum * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \param value * 0 = Pin interrupt not forwarded to CPU interrupt controller @@ -1454,11 +1604,17 @@ __STATIC_INLINE void Cy_GPIO_ClearInterrupt(GPIO_PRT_Type* base, uint32_t pinNum * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetInterruptMask +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetInterruptMask(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_VALUE_VALID(value)); + tempReg= base->INTR_MASK & ~(CY_GPIO_INTR_EN_MASK << pinNum); base->INTR_MASK = tempReg | ((value & CY_GPIO_INTR_EN_MASK) << pinNum); } @@ -1468,22 +1624,30 @@ __STATIC_INLINE void Cy_GPIO_SetInterruptMask(GPIO_PRT_Type* base, uint32_t pinN * Function Name: Cy_GPIO_GetInterruptMask ****************************************************************************//** * -* \brief Returns the state of the pin interrupt mask to determine whether it is -* configured to be forwarded to the CPU interrupt controller. +* \brief Returns the state of the pin interrupt mask. +* +* This mask is used to determine whether the pin is configured to be forwarded +* to the CPU NVIC. * * \param base * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \return * 0 = Pin interrupt not forwarded to CPU interrupt controller * 1 = Pin interrupt masked and forwarded to CPU interrupt controller * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetInterruptMask +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptMask(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + return (base->INTR_MASK >> pinNum) & CY_GPIO_INTR_EN_MASK; } @@ -1494,19 +1658,29 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptMask(GPIO_PRT_Type* base, uint32_t * * \brief Return the pin's current interrupt state after being masked. * +* The core processor's NVIC is triggered by the masked interrupt bits. This +* function allows reading this masked interrupt state. Note that the bits that +* are not masked will not be forwarded to the NVIC. +* * \param base * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \return * 0 = Pin interrupt not detected or not forwarded to CPU interrupt controller * 1 = Pin interrupt detected and forwarded to CPU interrupt controller * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptStatusMasked(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + return (base->INTR_MASKED >> pinNum) & CY_GPIO_INTR_MASKED_MASK; } @@ -1521,14 +1695,20 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptStatusMasked(GPIO_PRT_Type* base, u * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \return * void * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetSwInterrupt +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetSwInterrupt(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + base->INTR_SET = CY_GPIO_INTR_SET_MASK << pinNum; } @@ -1543,7 +1723,8 @@ __STATIC_INLINE void Cy_GPIO_SetSwInterrupt(GPIO_PRT_Type* base, uint32_t pinNum * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \param value * Pin interrupt mode. Options are detailed in \ref group_gpio_interruptTrigger macros @@ -1555,12 +1736,18 @@ __STATIC_INLINE void Cy_GPIO_SetSwInterrupt(GPIO_PRT_Type* base, uint32_t pinNum * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetInterruptEdge +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetInterruptEdge(GPIO_PRT_Type* base, uint32_t pinNum, uint32_t value) { uint32_t tempReg; uint32_t pinLoc; + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + CY_ASSERT_L2(CY_GPIO_IS_INT_EDGE_VALID(value)); + pinLoc = pinNum << CY_GPIO_INTR_CFG_OFFSET; tempReg = base->INTR_CFG & ~(CY_GPIO_INTR_EDGE_MASK << pinLoc); base->INTR_CFG = tempReg | ((value & CY_GPIO_INTR_EDGE_MASK) << pinLoc); @@ -1577,14 +1764,20 @@ __STATIC_INLINE void Cy_GPIO_SetInterruptEdge(GPIO_PRT_Type* base, uint32_t pinN * Pointer to the pin's port register base address * * \param pinNum -* Position of the pin bit-field within the port register +* Position of the pin bit-field within the port register. +* Bit position 8 is the routed pin through the port glitch filter. * * \return * Pin interrupt mode. Options are detailed in \ref group_gpio_interruptTrigger macros * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetInterruptEdge +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptEdge(GPIO_PRT_Type* base, uint32_t pinNum) { + CY_ASSERT_L2(CY_GPIO_IS_FILTER_PIN_VALID(pinNum)); + return (base->INTR_CFG >> (pinNum << CY_GPIO_INTR_CFG_OFFSET)) & CY_GPIO_INTR_EDGE_MASK; } @@ -1593,7 +1786,12 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptEdge(GPIO_PRT_Type* base, uint32_t * Function Name: Cy_GPIO_SetFilter ****************************************************************************//** * -* \brief Configures which pin on the port connects to the port filter. +* \brief Configures which pin on the port connects to the port-specific glitch filter. +* +* Each port contains a single 50ns glitch filter. Any of the pins on the port +* can be routed to this filter such that the input signal is filtered before +* reaching the edge-detect interrupt circuitry. The state of the filterred pin +* can also be read by calling the Cy_GPIO_Read() function. * * \param base * Pointer to the pin's port register base address @@ -1608,11 +1806,20 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptEdge(GPIO_PRT_Type* base, uint32_t * This function modifies a port register in a read-modify-write operation. It is * not thread safe as the resource is shared among multiple pins on a port. * +* \note +* The filtered pin does not have an associated HSIOM connection. Therefore +* it cannot be routed directly to other peripherals in hardware. +* +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetFilter +* *******************************************************************************/ __STATIC_INLINE void Cy_GPIO_SetFilter(GPIO_PRT_Type* base, uint32_t value) { uint32_t tempReg; + CY_ASSERT_L2(CY_GPIO_IS_PIN_VALID(value)); + tempReg = base->INTR_CFG & ~(CY_GPIO_INTR_FLT_EDGE_MASK << CY_GPIO_INTR_FILT_OFFSET); base->INTR_CFG = tempReg | ((value & CY_GPIO_INTR_FLT_EDGE_MASK) << CY_GPIO_INTR_FILT_OFFSET); } @@ -1622,7 +1829,13 @@ __STATIC_INLINE void Cy_GPIO_SetFilter(GPIO_PRT_Type* base, uint32_t value) * Function Name: Cy_GPIO_GetFilter ****************************************************************************//** * -* \brief Returns which pin is currently configured to connect to the port filter. +* \brief Returns which pin is currently configured to connect to the port-specific +* glitch filter. +* +* Each port contains a single 50ns glitch filter. Any of the pins on the port +* can be routed to this filter such that the input signal is filtered before +* reaching the edge-detect interrupt circuitry. The state of the filterred pin +* can also be read by calling the Cy_GPIO_Read() function. * * \param base * Pointer to the pin's port register base address @@ -1630,6 +1843,9 @@ __STATIC_INLINE void Cy_GPIO_SetFilter(GPIO_PRT_Type* base, uint32_t value) * \return * The number of the port pin routed to the port filter (0...7) * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_SetFilter +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetFilter(GPIO_PRT_Type* base) { @@ -1649,6 +1865,9 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetFilter(GPIO_PRT_Type* base) * 0 = Interrupt not detected on port * 1 = Interrupt detected and sent to CPU interrupt controller on port * +* \funcusage +* \snippet gpio/gpio_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_GPIO_GetInterruptCause0 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause0(void) { @@ -1669,6 +1888,9 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause0(void) * 0 = Interrupt not detected on port * 1 = Interrupt detected and sent to CPU interrupt controller on port * +* \funcusage +* Refer to the Cy_GPIO_GetInterruptCause0() example. +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause1(void) { @@ -1689,6 +1911,9 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause1(void) * 0 = Interrupt not detected on port * 1 = Interrupt detected and sent to CPU interrupt controller on port * +* \funcusage +* Refer to the Cy_GPIO_GetInterruptCause0() example. +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause2(void) { @@ -1709,6 +1934,9 @@ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause2(void) * 0 = Interrupt not detected on port * 1 = Interrupt detected and sent to CPU interrupt controller on port * +* \funcusage +* Refer to the Cy_GPIO_GetInterruptCause0() example. +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_GPIO_GetInterruptCause3(void) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/i2s/cy_i2s.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/i2s/cy_i2s.c similarity index 78% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/i2s/cy_i2s.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/i2s/cy_i2s.c index 0c58856dc7..6f2b77e848 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/i2s/cy_i2s.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/i2s/cy_i2s.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_i2s.c -* \version 2.0 +* \version 2.0.1 * * The source code file for the I2S driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -29,51 +29,54 @@ extern "C" { * must be called before calling this function. * * \param base The pointer to the I2S instance address. +* * \param config The pointer to a configuration structure. +* * \return error / status code. See \ref cy_en_i2s_status_t. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_Init +* *******************************************************************************/ cy_en_i2s_status_t Cy_I2S_Init(I2S_Type * base, cy_stc_i2s_config_t const * config) { cy_en_i2s_status_t ret = CY_I2S_BAD_PARAM; - cy_en_i2s_ws_pw_t wsPulseWidth; - uint32_t channels, clockDiv; - cy_en_i2s_len_t channelLength; - + if((NULL != base) && (NULL != config)) { - ret = CY_I2S_SUCCESS; - - /* Clock setting */ - clockDiv = (uint32_t)config->clkDiv - 1U; + cy_en_i2s_ws_pw_t wsPulseWidth; + cy_en_i2s_len_t channelLength; + uint32_t channels; + uint32_t clockDiv = (uint32_t)config->clkDiv - 1U; CY_ASSERT_L2(CY_I2S_IS_CLK_DIV_VALID(clockDiv)); + /* The clock setting */ base->CLOCK_CTL = _VAL2FLD(I2S_CLOCK_CTL_CLOCK_DIV, clockDiv) | _BOOL2FLD(I2S_CLOCK_CTL_CLOCK_SEL, config->extClk); - /* Tx setting */ - if(config->txEnabled) + /* The Tx setting */ + if (config->txEnabled) { CY_ASSERT_L3(CY_I2S_IS_ALIGNMENT_VALID(config->txAlignment)); CY_ASSERT_L3(CY_I2S_IS_OVHDATA_VALID(config->txOverheadValue)); - if((CY_I2S_TDM_MODE_A == config->txAlignment) || (CY_I2S_TDM_MODE_B == config->txAlignment)) + if ((CY_I2S_TDM_MODE_A == config->txAlignment) || (CY_I2S_TDM_MODE_B == config->txAlignment)) { channels = (uint32_t)config->txChannels - 1UL; - wsPulseWidth = CY_I2S_WS_ONE_CHANNEL_LENGTH; + wsPulseWidth = config->txWsPulseWidth; channelLength = CY_I2S_LEN32; CY_ASSERT_L2(CY_I2S_IS_CHANNELS_VALID(channels)); + CY_ASSERT_L3(CY_I2S_IS_WSPULSE_VALID(wsPulseWidth)); CY_ASSERT_L3(CY_I2S_IS_LEN_VALID(config->txWordLength)); } else { channels = 1UL; - wsPulseWidth = config->txWsPulseWidth; + wsPulseWidth = CY_I2S_WS_ONE_CHANNEL_LENGTH; channelLength = config->txChannelLength; - CY_ASSERT_L3(CY_I2S_IS_WSPULSE_VALID(wsPulseWidth)); CY_ASSERT_L3(CY_I2S_IS_CHAN_WORD_VALID(channelLength, config->txWordLength)); } @@ -94,27 +97,27 @@ cy_en_i2s_status_t Cy_I2S_Init(I2S_Type * base, cy_stc_i2s_config_t const * conf _VAL2FLD(I2S_TX_CTL_OVHDATA, config->txOverheadValue); } - /* Rx setting */ - if(config->rxEnabled) + /* The Rx setting */ + if (config->rxEnabled) { CY_ASSERT_L3(CY_I2S_IS_ALIGNMENT_VALID(config->rxAlignment)); - if((CY_I2S_TDM_MODE_A == config->rxAlignment) || (CY_I2S_TDM_MODE_B == config->rxAlignment)) + if ((CY_I2S_TDM_MODE_A == config->rxAlignment) || (CY_I2S_TDM_MODE_B == config->rxAlignment)) { channels = (uint32_t)config->rxChannels - 1UL; - wsPulseWidth = CY_I2S_WS_ONE_CHANNEL_LENGTH; + wsPulseWidth = config->rxWsPulseWidth; channelLength = CY_I2S_LEN32; CY_ASSERT_L2(CY_I2S_IS_CHANNELS_VALID(channels)); + CY_ASSERT_L3(CY_I2S_IS_WSPULSE_VALID(wsPulseWidth)); CY_ASSERT_L3(CY_I2S_IS_LEN_VALID(config->rxWordLength)); } else { channels = 1UL; - wsPulseWidth = config->rxWsPulseWidth; + wsPulseWidth = CY_I2S_WS_ONE_CHANNEL_LENGTH; channelLength = config->rxChannelLength; - CY_ASSERT_L3(CY_I2S_IS_WSPULSE_VALID(wsPulseWidth)); CY_ASSERT_L3(CY_I2S_IS_CHAN_WORD_VALID(channelLength, config->rxWordLength)); } @@ -135,31 +138,33 @@ cy_en_i2s_status_t Cy_I2S_Init(I2S_Type * base, cy_stc_i2s_config_t const * conf _BOOL2FLD(I2S_RX_CTL_BIT_EXTENSION, config->rxSignExtension); } - /* I2S enable setting */ - if(config->txEnabled) + /* The I2S enable setting */ + if (config->txEnabled) { base->CTL |= I2S_CTL_TX_ENABLED_Msk; } - if(config->rxEnabled) + if (config->rxEnabled) { base->CTL |= I2S_CTL_RX_ENABLED_Msk; } - /* FIFO setting */ - if(config->txEnabled) + /* The FIFO setting */ + if (config->txEnabled) { base->TX_FIFO_CTL = _VAL2FLD(I2S_TX_FIFO_CTL_TRIGGER_LEVEL, config->txFifoTriggerLevel); base->TR_CTL |= _BOOL2FLD(I2S_TR_CTL_TX_REQ_EN, config->txDmaTrigger); } - if(config->rxEnabled) + if (config->rxEnabled) { base->RX_FIFO_CTL = _VAL2FLD(I2S_RX_FIFO_CTL_TRIGGER_LEVEL, config->rxFifoTriggerLevel); base->TR_CTL |= _BOOL2FLD(I2S_TR_CTL_RX_REQ_EN, config->rxDmaTrigger); } + + ret = CY_I2S_SUCCESS; } return (ret); @@ -174,6 +179,9 @@ cy_en_i2s_status_t Cy_I2S_Init(I2S_Type * base, cy_stc_i2s_config_t const * conf * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_DeInit +* *******************************************************************************/ void Cy_I2S_DeInit(I2S_Type * base) { @@ -195,12 +203,14 @@ void Cy_I2S_DeInit(I2S_Type * base) * Function Name: Cy_I2S_DeepSleepCallback ****************************************************************************//** * -* This is a callback function that can be used at the application layer to -* manage an I2S operation before entering into/after exiting from the Deep Sleep -* mode. +* This is a callback function to be used at the application layer to +* manage an I2S operation during the Deep-Sleep cycle. It stores the I2S state +* (Tx/Rx enabled/disabled/paused) into the context structure and stops the +* communication before entering into Deep-Sleep power mode and restores the I2S +* state after waking up. * * \param -* callbackParams - A pointer to the callback parameters structure, +* callbackParams - The pointer to the callback parameters structure, * see \ref cy_stc_syspm_callback_params_t. * * \return the SysPm callback status \ref cy_en_syspm_status_t. @@ -208,6 +218,9 @@ void Cy_I2S_DeInit(I2S_Type * base) * \note Use the \ref cy_stc_i2s_context_t data type for definition of the * *context element of the \ref cy_stc_syspm_callback_params_t strusture. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_DeepSleepCallback +* *******************************************************************************/ cy_en_syspm_status_t Cy_I2S_DeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams) { @@ -225,37 +238,38 @@ cy_en_syspm_status_t Cy_I2S_DeepSleepCallback(cy_stc_syspm_callback_params_t * c case CY_SYSPM_BEFORE_TRANSITION: *locInterruptMask = Cy_I2S_GetInterruptMask(locBase); /* Store I2S interrupts */ - Cy_I2S_SetInterruptMask(locBase, 0UL); /* Disable I2S interrupts */ *locState = Cy_I2S_GetCurrentState(locBase); /* Store I2S state */ - if(0UL != (*locState & I2S_CMD_TX_START_Msk)) + if (0UL != (*locState & I2S_CMD_TX_START_Msk)) { Cy_I2S_DisableTx(locBase); /* Stop TX operation */ } - if(0UL != (*locState & I2S_CMD_RX_START_Msk)) + if (0UL != (*locState & I2S_CMD_RX_START_Msk)) { Cy_I2S_DisableRx(locBase); /* Stop RX operation */ } - /* Unload FIFOs to do not lost any data (if needed) */ + Cy_I2S_SetInterruptMask(locBase, 0UL); /* Disable I2S interrupts */ + /* Unload FIFOs in order not to lose data (if needed) */ break; case CY_SYSPM_AFTER_TRANSITION: - if(0UL != (*locState & I2S_CMD_RX_START_Msk)) + if (0UL != (*locState & I2S_CMD_RX_START_Msk)) { - Cy_I2S_ClearRxFifo (locBase); /* Clear RX FIFO */ - Cy_I2S_EnableRx (locBase); /* Start RX operation */ + Cy_I2S_ClearRxFifo(locBase); /* Clear the RX FIFO */ + Cy_I2S_EnableRx(locBase); /* Start RX operation */ } - if(0UL != (*locState & I2S_CMD_TX_START_Msk)) + if (0UL != (*locState & I2S_CMD_TX_START_Msk)) { - Cy_I2S_ClearTxFifo (locBase); /* Clear TX FIFO */ - Cy_I2S_WriteTxData (locBase, 0UL); /* Fill first TX frame */ - Cy_I2S_WriteTxData (locBase, 0UL); - if(0UL != (*locState & I2S_CMD_TX_PAUSE_Msk)) + Cy_I2S_ClearTxFifo(locBase); /* Clear the TX FIFO */ + Cy_I2S_WriteTxData(locBase, 0UL); /* Fill at least one TX frame */ + Cy_I2S_WriteTxData(locBase, 0UL); + if (0UL != (*locState & I2S_CMD_TX_PAUSE_Msk)) { - Cy_I2S_PauseTx(locBase); /* Restore TX paused state */ + Cy_I2S_PauseTx(locBase); /* Restore the TX paused state */ } Cy_I2S_EnableTx(locBase); /* Start TX operation */ } - Cy_I2S_SetInterruptMask (locBase, *locInterruptMask); /* Restore I2S interrupts */ + Cy_I2S_ClearInterrupt(locBase, *locInterruptMask); /* Clear possible pending I2S interrupts */ + Cy_I2S_SetInterruptMask(locBase, *locInterruptMask); /* Restore I2S interrupts */ break; default: diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/i2s/cy_i2s.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/i2s/cy_i2s.h similarity index 87% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/i2s/cy_i2s.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/i2s/cy_i2s.h index a124832a33..b288257378 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/i2s/cy_i2s.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/i2s/cy_i2s.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_i2s.h -* \version 2.0 +* \version 2.0.1 * * The header file of the I2S driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -20,10 +20,10 @@ * codecs or simple DACs. It can also receive digital audio streaming data. * * Features: -* * An industry-standard NXP I2S interface -* * Supports master/slave TX/RX operation -* * Programmable Channel/Word Lengths -* * Supports External Clock operation +* * An industry standard NXP I2S interface. +* * Supports master/slave TX/RX operation. +* * Programmable Channel/Word Lengths. +* * Supports External Clock operation. * * The I2S bus is an industry standard. The hardware interface was * developed by Philips Semiconductors (now NXP Semiconductors). @@ -33,36 +33,36 @@ * To set up an I2S, provide the configuration parameters in the * \ref cy_stc_i2s_config_t structure. * -* For example, for TX configuration, set txEnabled to true, configure +* For example, for Tx configuration, set txEnabled to true, configure * txDmaTrigger (depending on whether DMA is going to be used or not), set * extClk (if an external clock is used), provide clkDiv, txMasterMode, * txAlignment, txChannels (only 2 is supported in I2S and Left Justified modes) * txSdoLatchingTime (for slave mode only), txChannelLength, txWordLength, * txWsPulseWidth (for TMD modes only), txWatchdogEnable and txWatchdogValue -* (both for slave mode only, and when the watchdog interrupt will be used), +* (both for Slave mode only, and when the watchdog interrupt will be used), * either txSckoInversion or txSckiInversion (based on txMasterMode setting), * txFifoTriggerLevel (when the Trig interrupt will be used) and txOverheadValue -* (only when word length is less than channel length). -* The similar setup is for RX configuration. +* (only when the word length is less than channel length). +* A similar setup is for the Rx configuration. * * To initialize the I2S block, call the \ref Cy_I2S_Init function, providing the * filled \ref cy_stc_i2s_config_t structure. * Before starting the transmission, clear the FIFO \ref Cy_I2S_ClearTxFifo, then -* fill the first TX data frame by calling \ref Cy_I2S_WriteTxData once for each +* fill the first Tx data frame by calling \ref Cy_I2S_WriteTxData once for each * channel (e.g. twice for I2S mode with only two channels) with zero data. Then * call the \ref Cy_I2S_EnableTx itself. -* For the reception the sequence is the same except of filling the first data +* For the reception the sequence is the same except for filling the first data * frame, just RX FIFO clearing is enough. * * For example: -* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c Cy_I2S_Snippet +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_Init * -* If you use DMA, the DMA channel should be previously configured. I2S interrupts +* If you use a DMA, the DMA channel should be previously configured. The I2S interrupts * (if applicable) can be enabled by calling \ref Cy_I2S_SetInterruptMask. * * For example, if the trigger interrupt is used, during operation the ISR * should call the \ref Cy_I2S_WriteTxData as many times as required for your -* FIFO payload, but not more than FIFO size. Then call \ref Cy_I2S_ClearInterrupt +* FIFO payload, but not more than the FIFO size. Then call \ref Cy_I2S_ClearInterrupt * with appropriate parameters. * * The I2S/Left Justified data formats always contains two data channels. @@ -73,19 +73,20 @@ * left channel will finally sound, for right-only case zero should go first). * The TDM frame word order in FIFOs is similar, one-by-one. * -* If DMA is used and a DMA channel is properly configured - no CPU activity +* If a DMA is used and the DMA channel is properly configured - no CPU activity * (or any application code) is needed for I2S operation. * -* The I2S frame looks like the next: +* The I2S frame appears as: * \image html i2s_frame.png -* This is an example for channel length = 32. The similar is for all the rest -* channel lengths, with only limitation: the word length could be less or equal +* This is an example for the channel length = 32. A similar is for all the rest +* channel lengths, with one limitation: the word length could be less or equal * to the channel length. See the device Technical Reference Manual (TRM) * for more details. * * \section group_i2s_more_information More Information -* See the the I2S chapter of the device technical reference manual (TRM). -* Also, see I2S_PDL Component datasheet. +* See: the the I2S chapter of the device technical reference manual (TRM); +* I2S_PDL Component datasheet; +* CE218636 - PSOC 6 MCU INTER-IC SOUND (I2S) EXAMPLE. * * \section group_i2s_MISRA MISRA-C Compliance * The I2S driver has the following specific deviations: @@ -99,12 +100,12 @@ * * * -* +* * +* function becomes the user responsibility because the pointer is +* initialized when a callback is registered in the SysPm driver. * *
VersionChangesReason for Change
1.10.1Updated description for the functions: \ref Cy_GPIO_GetInterruptStatus, +* \ref Cy_GPIO_GetInterruptMask, \ref Cy_GPIO_GetInterruptStatusMasked. +* Minor documentation edits. +* Documentation update and clarification
1.10Added input parameter validation to the API functions
1.0Initial version
11.4AA cast should not be performed between a pointer to object type and -* a different pointer to object type.A cast should not be performed between a pointer to the object type and +* a different pointer to the object type.The function \ref Cy_I2S_DeepSleepCallback is a callback of * \ref cy_en_syspm_status_t type. The cast operation safety in this -* function becomes the user responsibility because pointer are -* initialized when callback is registered in SysPm driver.
* @@ -112,21 +113,29 @@ * * * -* -* -* +* +* +* * * * * * * +* +* +* +* +* *
VersionChangesReason for Change
1.0Initial version2.0.1Added Low Power Callback sectionDocumentation update and clarification
2.0The slave operation is added, Left Justified and TDM modes are added
1.0Initial version
* * \defgroup group_i2s_macros Macros * \defgroup group_i2s_functions Functions +* \{ +* \defgroup group_i2s_functions_syspm_callback Low Power Callback +* \} * \defgroup group_i2s_data_structures Data Structures -* \defgroup group_i2s_enums Enumerated types +* \defgroup group_i2s_enums Enumerated Types */ @@ -150,13 +159,13 @@ extern "C" { * \{ */ -/** Driver major version */ +/** The driver major version */ #define CY_I2S_DRV_VERSION_MAJOR 2 -/** Driver minor version */ +/** The driver minor version */ #define CY_I2S_DRV_VERSION_MINOR 0 -/** I2S driver identifier */ +/** The I2S driver identifier */ #define CY_I2S_ID (CY_PDL_DRV_ID(0x20U)) /** @@ -288,8 +297,8 @@ typedef struct bool txMasterMode; /**< 'false': TX in slave mode, 'true': TX in master mode. */ cy_en_i2s_alignment_t txAlignment; /**< TX data alignment, see: #cy_en_i2s_alignment_t. */ cy_en_i2s_ws_pw_t txWsPulseWidth; /**< TX Word Select pulse width. - The value of this parameter is ignored in TDM modes - the WS pulse - width is always "one channel length" is these modes. */ + The value of this parameter is ignored in I2S and Left Justified modes + the WS pulse width is always "one channel length" in these modes. */ bool txWatchdogEnable; /**< 'false': TX watchdog disabled, 'true': TX watchdog enabled. */ uint32_t txWatchdogValue; /**< TX watchdog counter value (32 bit). */ bool txSdoLatchingTime; /**< 'false': SDO bit starts at falling edge (accordingly to the I2S @@ -328,8 +337,8 @@ typedef struct bool rxMasterMode; /**< 'false': RX in slave mode, 'true': RX in master mode. */ cy_en_i2s_alignment_t rxAlignment; /**< RX data alignment, see: #cy_en_i2s_alignment_t. */ cy_en_i2s_ws_pw_t rxWsPulseWidth; /**< RX Word Select pulse width. - The value of this parameter is ignored in TDM modes - the WS pulse - width is always "one channel length" is these modes. */ + The value of this parameter is ignored in I2S and Left Justified modes + the WS pulse width is always "one channel length" in these modes. */ bool rxWatchdogEnable; /**< 'false': RX watchdog disabled, 'true': RX watchdog enabled. */ uint32_t rxWatchdogValue; /**< RX watchdog counter value (32 bit). */ bool rxSdiLatchingTime; /**< 'false': SDI bit starts at falling edge (accordingly to the I2S @@ -371,17 +380,17 @@ typedef struct /** - * I2S backup structure type to be used for SysPm callback + * The I2S backup structure type to be used for the SysPm callback. * \ref Cy_I2S_DeepSleepCallback context definition. * - * \cond Also can be used for another purposes to store the current TX/RX + * \cond Also can be used for other purposes to store the current Tx/Rx * operation state and interrupt settings - the factors that are usually - * being changed on the fly. \endcond + * changed on the fly. \endcond */ typedef struct { - uint32_t enableState; /**< Stores I2S state */ - uint32_t interruptMask; /**< Stores I2S interrupt mask */ + uint32_t enableState; /**< Stores the I2S state */ + uint32_t interruptMask; /**< Stores the I2S interrupt mask */ } cy_stc_i2s_context_t; /** \} group_i2s_data_structures */ @@ -467,7 +476,13 @@ typedef struct cy_en_i2s_status_t Cy_I2S_Init(I2S_Type * base, cy_stc_i2s_config_t const * config); void Cy_I2S_DeInit(I2S_Type * base); + +/** \addtogroup group_i2s_functions_syspm_callback +* The driver supports SysPm callback for Deep Sleep transition. +* \{ +*/ cy_en_syspm_status_t Cy_I2S_DeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams); +/** \} */ __STATIC_INLINE void Cy_I2S_EnableTx(I2S_Type * base); __STATIC_INLINE void Cy_I2S_PauseTx(I2S_Type * base); @@ -513,6 +528,9 @@ __STATIC_INLINE uint32_t Cy_I2S_GetInterruptStatusMasked(I2S_Type const * base); * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_EnableTx +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_EnableTx(I2S_Type * base) { @@ -528,6 +546,9 @@ __STATIC_INLINE void Cy_I2S_EnableTx(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_PauseTx +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_PauseTx(I2S_Type * base) { @@ -543,6 +564,9 @@ __STATIC_INLINE void Cy_I2S_PauseTx(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ResumeTx +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_ResumeTx(I2S_Type * base) { @@ -561,6 +585,9 @@ __STATIC_INLINE void Cy_I2S_ResumeTx(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_DisableTx +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_DisableTx(I2S_Type * base) { @@ -580,6 +607,9 @@ __STATIC_INLINE void Cy_I2S_DisableTx(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_EnableRx +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_EnableRx(I2S_Type * base) { @@ -598,6 +628,9 @@ __STATIC_INLINE void Cy_I2S_EnableRx(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_DisableRx +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_DisableRx(I2S_Type * base) { @@ -612,8 +645,12 @@ __STATIC_INLINE void Cy_I2S_DisableRx(I2S_Type * base) * Returns the current I2S state (TX/RX running/paused/stopped). * * \param base The pointer to the I2S instance address. +* * \return The current state \ref group_i2s_macros_current_state. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetCurrentState +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_GetCurrentState(I2S_Type const * base) { @@ -625,10 +662,13 @@ __STATIC_INLINE uint32_t Cy_I2S_GetCurrentState(I2S_Type const * base) * Function Name: Cy_I2S_ClearTxFifo ****************************************************************************//** * -* Clears TX FIFO (resets the Read/Write FIFO pointers). +* Clears the TX FIFO (resets the Read/Write FIFO pointers). * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ClearTxFifo +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_ClearTxFifo(I2S_Type * base) { @@ -645,7 +685,11 @@ __STATIC_INLINE void Cy_I2S_ClearTxFifo(I2S_Type * base) * Gets the number of used words in the TX FIFO. * * \param base The pointer to the I2S instance address. -* \return The current number of used words in rge TX FIFO. +* +* \return The current number of used words in the TX FIFO. +* +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetNumInTxFifo * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_GetNumInTxFifo(I2S_Type const * base) @@ -661,8 +705,12 @@ __STATIC_INLINE uint32_t Cy_I2S_GetNumInTxFifo(I2S_Type const * base) * Writes data to the TX FIFO. Increases the TX FIFO level. * * \param base The pointer to the I2S instance address. +* * \param data Data to be written to the TX FIFO. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_WriteTxData +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_WriteTxData(I2S_Type * base, uint32_t data) { @@ -677,8 +725,12 @@ __STATIC_INLINE void Cy_I2S_WriteTxData(I2S_Type * base, uint32_t data) * Gets the TX FIFO Read pointer. This function is rather for debug purposes. * * \param base The pointer to the I2S instance address. +* * \return The current TX Read pointer value. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetTxReadPointer +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_I2S_GetTxReadPointer(I2S_Type const * base) { @@ -693,8 +745,12 @@ __STATIC_INLINE uint8_t Cy_I2S_GetTxReadPointer(I2S_Type const * base) * Gets the TX FIFO Write pointer. This function is rather for debug purposes. * * \param base The pointer to the I2S instance address. +* * \return The current TX Write pointer value. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetTxWritePointer +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_I2S_GetTxWritePointer(I2S_Type const * base) { @@ -710,6 +766,9 @@ __STATIC_INLINE uint8_t Cy_I2S_GetTxWritePointer(I2S_Type const * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_FreezeTxFifo +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_FreezeTxFifo(I2S_Type * base) { @@ -725,6 +784,9 @@ __STATIC_INLINE void Cy_I2S_FreezeTxFifo(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_UnfreezeTxFifo +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_UnfreezeTxFifo(I2S_Type * base) { @@ -740,6 +802,9 @@ __STATIC_INLINE void Cy_I2S_UnfreezeTxFifo(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ClearRxFifo +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_ClearRxFifo(I2S_Type * base) { @@ -756,8 +821,12 @@ __STATIC_INLINE void Cy_I2S_ClearRxFifo(I2S_Type * base) * Gets the number of used words in the RX FIFO. * * \param base The pointer to the I2S instance address. +* * \return The current number of used words in rge RX FIFO. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetNumInRxFifo +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_GetNumInRxFifo(I2S_Type const * base) { @@ -769,11 +838,15 @@ __STATIC_INLINE uint32_t Cy_I2S_GetNumInRxFifo(I2S_Type const * base) * Function Name: Cy_I2S_ReadRxData ****************************************************************************//** * -* Reads data from the RX FIFO. Decreases the TX FIFO level. +* Reads data from the RX FIFO. Decreases the RX FIFO level. * * \param base The pointer to the I2S instance address. +* * \return The read data. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ReadRxData +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_ReadRxData(I2S_Type const * base) { @@ -789,8 +862,12 @@ __STATIC_INLINE uint32_t Cy_I2S_ReadRxData(I2S_Type const * base) * This function is rather for debug purposes. * * \param base The pointer to the I2S instance address. +* * \return The read data. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ReadRxDataSilent +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_ReadRxDataSilent(I2S_Type const * base) { @@ -805,8 +882,12 @@ __STATIC_INLINE uint32_t Cy_I2S_ReadRxDataSilent(I2S_Type const * base) * Gets the RX FIFO Read pointer. This function is rather for debug purposes. * * \param base The pointer to the I2S instance address. +* * \return The current RX Read pointer value. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetRxReadPointer +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_I2S_GetRxReadPointer(I2S_Type const * base) { @@ -821,8 +902,12 @@ __STATIC_INLINE uint8_t Cy_I2S_GetRxReadPointer(I2S_Type const * base) * Gets the RX FIFO Write pointer. This function is rather for debug purposes. * * \param base The pointer to the I2S instance address. +* * \return The current RX Write pointer value. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetRxWritePointer +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_I2S_GetRxWritePointer(I2S_Type const * base) { @@ -838,6 +923,9 @@ __STATIC_INLINE uint8_t Cy_I2S_GetRxWritePointer(I2S_Type const * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_FreezeRxFifo +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_FreezeRxFifo(I2S_Type * base) { @@ -853,6 +941,9 @@ __STATIC_INLINE void Cy_I2S_FreezeRxFifo(I2S_Type * base) * * \param base The pointer to the I2S instance address. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_UnfreezeRxFifo +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_UnfreezeRxFifo(I2S_Type * base) { @@ -867,8 +958,12 @@ __STATIC_INLINE void Cy_I2S_UnfreezeRxFifo(I2S_Type * base) * Gets an interrupt status (returns a content of the INTR register). * * \param base The pointer to the I2S instance address. +* * \return The interrupt bit mask \ref group_i2s_macros_intrerrupt_masks. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetInterruptStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_GetInterruptStatus(I2S_Type const * base) { @@ -883,8 +978,12 @@ __STATIC_INLINE uint32_t Cy_I2S_GetInterruptStatus(I2S_Type const * base) * Clears one or more interrupt factors (sets the INTR register). * * \param base The pointer to the I2S instance address. +* * \param interrupt Interrupt bit mask \ref group_i2s_macros_intrerrupt_masks. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ClearInterrupt +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_ClearInterrupt(I2S_Type * base, uint32_t interrupt) { @@ -901,8 +1000,12 @@ __STATIC_INLINE void Cy_I2S_ClearInterrupt(I2S_Type * base, uint32_t interrupt) * Sets one or more interrupt factors (sets the INTR_SET register). * * \param base The pointer to the I2S instance address. +* * \param interrupt Interrupt bit mask \ref group_i2s_macros_intrerrupt_masks. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_SetInterrupt +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_SetInterrupt(I2S_Type * base, uint32_t interrupt) { @@ -918,8 +1021,12 @@ __STATIC_INLINE void Cy_I2S_SetInterrupt(I2S_Type * base, uint32_t interrupt) * Returns the interrupt mask (a content of the INTR_MASK register). * * \param base The pointer to the I2S instance address. +* * \return The interrupt bit mask \ref group_i2s_macros_intrerrupt_masks. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_GetInterruptMask +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_GetInterruptMask(I2S_Type const * base) { @@ -934,8 +1041,12 @@ __STATIC_INLINE uint32_t Cy_I2S_GetInterruptMask(I2S_Type const * base) * Sets one or more interrupt factor masks (the INTR_MASK register). * * \param base The pointer to the I2S instance address. +* * \param interrupt Interrupt bit mask \ref group_i2s_macros_intrerrupt_masks. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_SetInterruptMask +* *******************************************************************************/ __STATIC_INLINE void Cy_I2S_SetInterruptMask(I2S_Type * base, uint32_t interrupt) { @@ -951,8 +1062,12 @@ __STATIC_INLINE void Cy_I2S_SetInterruptMask(I2S_Type * base, uint32_t interrupt * Returns the interrupt status masked (a content of the INTR_MASKED register). * * \param base The pointer to the I2S instance address. +* * \return The interrupt bit mask(s) \ref group_i2s_macros_intrerrupt_masks. * +* \funcusage +* \snippet i2s/i2s_v2_0_sut_00.cydsn/main_cm4.c snippet_Cy_I2S_ClearInterrupt +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_I2S_GetInterruptStatusMasked(I2S_Type const * base) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_drv.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_drv.c similarity index 92% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_drv.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_drv.c index b1d73a4778..5d090519ab 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_drv.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_drv.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_ipc_drv.c -* \version 1.10 +* \version 1.10.1 * * \breif * IPC Driver - This source file contains the low-level driver code for * the IPC hardware. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -24,8 +24,6 @@ * The function also has a way to specify through a parameter which IPC * interrupts must be notified during the release event. * -* This function is internal and should not be called directly by user software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -41,19 +39,17 @@ * \retval CY_IPC_DRV_ERROR: The IPC channel was not acquired before the * function call. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_ReadMsgPtr +* *******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif cy_en_ipcdrv_status_t Cy_IPC_Drv_LockRelease (IPC_STRUCT_Type* base, uint32_t releaseEventIntr) { cy_en_ipcdrv_status_t retStatus; - /* Check to make sure the IPC is Acquired */ - if( Cy_IPC_Drv_IsLockAcquired(base) ) - { + /* Check to make sure the IPC is Acquired */ + if( Cy_IPC_Drv_IsLockAcquired(base) ) + { /* The IPC was acquired, release the IPC channel */ Cy_IPC_Drv_ReleaseNotify(base, releaseEventIntr); @@ -67,6 +63,7 @@ cy_en_ipcdrv_status_t Cy_IPC_Drv_LockRelease (IPC_STRUCT_Type* base, uint32_t re return (retStatus); } + /******************************************************************************* * Function Name: Cy_IPC_Drv_SendMsgWord ****************************************************************************//** @@ -77,8 +74,6 @@ cy_en_ipcdrv_status_t Cy_IPC_Drv_LockRelease (IPC_STRUCT_Type* base, uint32_t re * remains locked after the function returns. The receiver of the message should * release the channel. * -* This function is internal and should not be called directly by user software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -95,6 +90,9 @@ cy_en_ipcdrv_status_t Cy_IPC_Drv_LockRelease (IPC_STRUCT_Type* base, uint32_t re * \retval CY_IPC_DRV_SUCCESS: The send operation was successful. * \retval CY_IPC_DRV_ERROR: The IPC channel is unavailable because it is already locked. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_SendMsgWord +* *******************************************************************************/ cy_en_ipcdrv_status_t Cy_IPC_Drv_SendMsgWord (IPC_STRUCT_Type* base, uint32_t notifyEventIntr, uint32_t message) { @@ -128,8 +126,6 @@ cy_en_ipcdrv_status_t Cy_IPC_Drv_SendMsgWord (IPC_STRUCT_Type* base, uint32_t n * Cy_IPC_Drv_Release() function after reading the message to release the * IPC channel. * -* This function is internal and should not be called directly by user software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -146,6 +142,9 @@ cy_en_ipcdrv_status_t Cy_IPC_Drv_SendMsgWord (IPC_STRUCT_Type* base, uint32_t n * channel was already in a released state, meaning the data * may be invalid. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_ReadMsgWord +* *******************************************************************************/ cy_en_ipcdrv_status_t Cy_IPC_Drv_ReadMsgWord (IPC_STRUCT_Type const * base, uint32_t * message) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_drv.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_drv.h similarity index 92% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_drv.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_drv.h index 9c41d9f626..03e52f2053 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_drv.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_drv.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_ipc_drv.h -* \version 1.10 +* \version 1.10.1 * * Provides an API declaration of the IPC driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -34,12 +34,6 @@ * Firmware does not need to use the DRV API. It can implement IPC functionality * entirely with the PIPE and SEMA APIs. * -* \note "Warning[Ta023]: Call to a non __ramfunc function." - The warning may -* appear during the build process while using IAR IDE. The reason - some -* functions in RAM memory that use the __ramfunc keyword, may invoke -* functions located in the ROM memory. You can ignore this warning or -* disable it by adding the --diag_suppress=Ta023 option to the compiler. -* * \section group_ipc_background Background * * IPC is implemented in hardware as a collection of individual communication @@ -170,15 +164,20 @@ * duplex communication between cores. On the CM0+ the notify interrupt is * assigned to NVIC IRQn 27. See System Interrupt (SysInt) for background. * +* To create your own pipe you should make 3 steps: +* -# Define pipe callbacks processing interrupt handler +* -# Define your pipe configuration by cy_stc_ipc_pipe_config_t type structure +* -# Call Cy_IPC_Pipe_Init() to initialize your pipe on both cores +* * \section group_ipc_configuration_sema Configuration Considerations - SEMA * -* Startup code calls Cy_IPC_SystemSemaInit (in cy_ipc_config.c) to set up -* semaphore functionality. This function calls the PDL init function +* Startup code calls Cy_IPC_SystemSemaInit() (in cy_ipc_config.c) to set up +* semaphore functionality. This function calls the PDL init function * Cy_IPC_Sema_Init() with default values. By default the semaphore system * uses IPC channel 4, and creates 128 semaphores. Do not change the IPC * channel. You can change the number of semaphores. * -* To change the number of semaphores, modify this line of code in cy_ipc_config.h. +* To change the number of semaphores, modify this line of code in cy_ipc_config.h. * * \code * #define CY_IPC_SEMA_COUNT (uint32_t)(128u) @@ -191,6 +190,17 @@ * * \section group_ipc_more_information More Information * +* Cy_IPC_SystemSemaInit() and Cy_IPC_SystemPipeInit() functions are called in the +* SystemInit function. If the default startup file is not used, or SystemInit is +* not called in your project, call the following three functions prior to +* executing any flash or EmEEPROM write or erase operation. For example: +* -# Cy_IPC_SystemSemaInit() +* -# Cy_IPC_SystemPipeInit() +* -# Cy_Flash_Init() +* +* Also Cy_IPC_SystemPipeInit function is called to support BLE host/controller +* communication. +* * See the technical reference manual(TRM) for more information on the IPC. * * \section group_ipc_MISRA MISRA-C Compliance @@ -223,6 +233,30 @@ * * * +* \section group_ipc_changelog Changelog +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
VersionChangesReason for Change
1.10.1Updated description of the \ref Cy_IPC_Pipe_Init, +* \ref Cy_IPC_Pipe_EndpointInit, \ref Cy_IPC_Sema_Set functions. +* Added / updated code snippets. +* Documentation update and clarification
1.10Added support for more IPC structuresNew device support
1.0Initial version
+* * \defgroup group_ipc_drv IPC driver layer (IPC_DRV) * \{ * The functions of this layer are used in the higher IPC levels @@ -316,7 +350,6 @@ extern "C" { __STATIC_INLINE void Cy_IPC_Drv_WriteDataValue (IPC_STRUCT_Type* base, uint32_t dataValue); __STATIC_INLINE uint32_t Cy_IPC_Drv_ReadDataValue (IPC_STRUCT_Type const * base); -__STATIC_INLINE void Cy_IPC_Drv_ReleaseNotify (IPC_STRUCT_Type* base, uint32_t notifyEventIntr); __STATIC_INLINE uint32_t Cy_IPC_Drv_ExtractAcquireMask (uint32_t intMask); __STATIC_INLINE uint32_t Cy_IPC_Drv_ExtractReleaseMask (uint32_t intMask); @@ -332,6 +365,7 @@ __STATIC_INLINE IPC_STRUCT_Type* Cy_IPC_Drv_GetIpcBaseAddress (uint32_t ip __STATIC_INLINE IPC_INTR_STRUCT_Type* Cy_IPC_Drv_GetIntrBaseAddr (uint32_t ipcIntrIndex); __STATIC_INLINE void Cy_IPC_Drv_AcquireNotify (IPC_STRUCT_Type * base, uint32_t notifyEventIntr); +__STATIC_INLINE void Cy_IPC_Drv_ReleaseNotify (IPC_STRUCT_Type * base, uint32_t notifyEventIntr); __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_LockAcquire (IPC_STRUCT_Type const * base); cy_en_ipcdrv_status_t Cy_IPC_Drv_LockRelease (IPC_STRUCT_Type * base, uint32_t releaseEventIntr); @@ -360,9 +394,6 @@ __STATIC_INLINE void Cy_IPC_Drv_ClearInterrupt (IPC_INTR_STRUCT_Type * base, * This function takes an IPC channel index as a parameter and returns the base * address the IPC registers corresponding to the IPC channel. * -* This function is internal and should not be called directly by user -* software. -* * \note The user is responsible for ensuring that ipcIndex does not exceed the * limits. * @@ -373,6 +404,9 @@ __STATIC_INLINE void Cy_IPC_Drv_ClearInterrupt (IPC_INTR_STRUCT_Type * base, * \return * Returns a pointer to the base of the IPC registers. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_SendMsgWord +* *******************************************************************************/ __STATIC_INLINE IPC_STRUCT_Type* Cy_IPC_Drv_GetIpcBaseAddress (uint32_t ipcIndex) { @@ -387,9 +421,6 @@ __STATIC_INLINE IPC_STRUCT_Type* Cy_IPC_Drv_GetIpcBaseAddress (uint32_t ipcIndex * This function takes an IPC interrupt structure index and returns the base * address of the IPC interrupt registers corresponding to the IPC Interrupt. * -* This function is internal and should not be called directly by user -* software. -* * \note The user is responsible for ensuring that ipcIntrIndex does not exceed the * limits. * @@ -400,6 +431,9 @@ __STATIC_INLINE IPC_STRUCT_Type* Cy_IPC_Drv_GetIpcBaseAddress (uint32_t ipcIndex * \return * Returns a pointer to the base of the IPC interrupt registers. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetInterruptStatus +* *******************************************************************************/ __STATIC_INLINE IPC_INTR_STRUCT_Type* Cy_IPC_Drv_GetIntrBaseAddr (uint32_t ipcIntrIndex) { @@ -414,9 +448,6 @@ __STATIC_INLINE IPC_INTR_STRUCT_Type* Cy_IPC_Drv_GetIntrBaseAddr (uint32_t ipcIn * This function is used to set the interrupt mask for an IPC Interrupt. * The mask sets release or acquire notification events for all IPC channels. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This is a handle to the IPC interrupt. This handle can be calculated from the * IPC interrupt number using \ref Cy_IPC_Drv_GetIntrBaseAddr. @@ -429,6 +460,9 @@ __STATIC_INLINE IPC_INTR_STRUCT_Type* Cy_IPC_Drv_GetIntrBaseAddr (uint32_t ipcIn * An encoded list of all IPC channels that can trigger the interrupt on a * notify event. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE void Cy_IPC_Drv_SetInterruptMask (IPC_INTR_STRUCT_Type* base, uint32_t ipcReleaseMask, uint32_t ipcNotifyMask) @@ -446,9 +480,6 @@ __STATIC_INLINE void Cy_IPC_Drv_SetInterruptMask (IPC_INTR_STRUCT_Type* base, * * This function is used to read the interrupt mask. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This is a handle to the IPC interrupt. This handle can be calculated from * the IPC interrupt number using \ref Cy_IPC_Drv_GetIntrBaseAddr. @@ -461,6 +492,9 @@ __STATIC_INLINE void Cy_IPC_Drv_SetInterruptMask (IPC_INTR_STRUCT_Type* base, * Ipc_PORTX_NOTIFY X+16th bit set * * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptMask(IPC_INTR_STRUCT_Type const * base) { @@ -475,9 +509,6 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptMask(IPC_INTR_STRUCT_Type const * can be used in the interrupt service routine to find which source triggered * the interrupt. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This is a handle to the IPC interrupt. This handle can be calculated from the * IPC interrupt number using \ref Cy_IPC_Drv_GetIntrBaseAddr. @@ -490,6 +521,9 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptMask(IPC_INTR_STRUCT_Type const * Ipc_PORTX_NOTIFY X+16th bit set * * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptStatusMasked (IPC_INTR_STRUCT_Type const * base) { @@ -503,9 +537,6 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptStatusMasked (IPC_INTR_STRUCT_Ty * This function is used to read the pending interrupts. Note that this read is * an unmasked read of the interrupt status. Interrupt sources read as active by * this function would generate interrupts only if they were not masked. - -* This function is internal and should not be called directly by user -* software. * * \param base * This is a handle to the IPC interrupt. This handle can be calculated from the @@ -519,6 +550,9 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptStatusMasked (IPC_INTR_STRUCT_Ty * Ipc_PORTX_NOTIFY X+16th bit set * * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetInterruptStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptStatus(IPC_INTR_STRUCT_Type const * base) { @@ -534,9 +568,6 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptStatus(IPC_INTR_STRUCT_Type cons * \note That interrupt sources set using this interrupt would generate interrupts * only if they are not masked. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This is a handle to the IPC interrupt. This handle can be calculated from the * IPC interrupt number using \ref Cy_IPC_Drv_GetIntrBaseAddr. @@ -549,6 +580,9 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetInterruptStatus(IPC_INTR_STRUCT_Type cons * An encoded list of all IPC channels that can trigger the interrupt on a * notify event. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_SetInterrupt +* *******************************************************************************/ __STATIC_INLINE void Cy_IPC_Drv_SetInterrupt(IPC_INTR_STRUCT_Type* base, uint32_t ipcReleaseMask, uint32_t ipcNotifyMask) { @@ -565,9 +599,6 @@ __STATIC_INLINE void Cy_IPC_Drv_SetInterrupt(IPC_INTR_STRUCT_Type* base, uint32 * This function is used to clear the interrupt source. Use this function to clear * a pending interrupt source in the interrupt status. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This is a handle to the IPC interrupt. This handle can be calculated from the * IPC interrupt number using \ref Cy_IPC_Drv_GetIntrBaseAddr. @@ -580,6 +611,9 @@ __STATIC_INLINE void Cy_IPC_Drv_SetInterrupt(IPC_INTR_STRUCT_Type* base, uint32 * An encoded list of all IPC channels that can trigger the interrupt on a * notify event. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE void Cy_IPC_Drv_ClearInterrupt(IPC_INTR_STRUCT_Type* base, uint32_t ipcReleaseMask, uint32_t ipcNotifyMask) { @@ -600,9 +634,6 @@ __STATIC_INLINE void Cy_IPC_Drv_ClearInterrupt(IPC_INTR_STRUCT_Type* base, uint * * The function generates a notify event by IPC interrupt structures. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -614,6 +645,9 @@ __STATIC_INLINE void Cy_IPC_Drv_ClearInterrupt(IPC_INTR_STRUCT_Type* base, uint * by a notification. Bit number correspond to number of the IPC interrupt * structure. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_LockAcquire +* *******************************************************************************/ __STATIC_INLINE void Cy_IPC_Drv_AcquireNotify (IPC_STRUCT_Type* base, uint32_t notifyEventIntr) { @@ -627,9 +661,6 @@ __STATIC_INLINE void Cy_IPC_Drv_AcquireNotify (IPC_STRUCT_Type* base, uint32_t * * The function generates a notify event to an IPC interrupt structure. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -639,6 +670,9 @@ __STATIC_INLINE void Cy_IPC_Drv_AcquireNotify (IPC_STRUCT_Type* base, uint32_t * \param notifyEventIntr * Bit encoded list of IPC interrupt lines that are triggered by a notification. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_ReadMsgWord +* *******************************************************************************/ __STATIC_INLINE void Cy_IPC_Drv_ReleaseNotify (IPC_STRUCT_Type* base, uint32_t notifyEventIntr) { @@ -689,11 +723,6 @@ __STATIC_INLINE void Cy_IPC_Drv_WriteDataValue (IPC_STRUCT_Type* base, uint3 * Value from DATA register. * *******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif __STATIC_INLINE uint32_t Cy_IPC_Drv_ReadDataValue (IPC_STRUCT_Type const * base) { return (base->DATA); @@ -706,9 +735,6 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_ReadDataValue (IPC_STRUCT_Type const * base) * The function is used to test the status of an IPC channel. The function * tells the reader if the IPC channel was in the locked or released state. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -720,6 +746,9 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_ReadDataValue (IPC_STRUCT_Type const * base) * true: The IPC channel is in the Locked state. * false: The IPC channel is in the Released state. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_LockAcquire +* *******************************************************************************/ __STATIC_INLINE bool Cy_IPC_Drv_IsLockAcquired (IPC_STRUCT_Type const * base) { @@ -732,9 +761,6 @@ __STATIC_INLINE bool Cy_IPC_Drv_IsLockAcquired (IPC_STRUCT_Type const * base) * * The function is used to get the status of an IPC channel. * -* This function is internal and should not be called directly by user -* software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -744,6 +770,9 @@ __STATIC_INLINE bool Cy_IPC_Drv_IsLockAcquired (IPC_STRUCT_Type const * base) * \return * Value from LOCK_STATUS register. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_GetLockStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_IPC_Drv_GetLockStatus (IPC_STRUCT_Type const * base) { @@ -806,8 +835,6 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_ExtractReleaseMask (uint32_t intMask) * The function also has an associated notification field that will let the * message notify one or multiple interrupts. * -* This function is internal and should not be called directly by user software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -826,6 +853,9 @@ __STATIC_INLINE uint32_t Cy_IPC_Drv_ExtractReleaseMask (uint32_t intMask) * \retval CY_IPC_DRV_ERROR: The IPC channel is unavailable because * it is already locked. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_SendMsgPtr +* *******************************************************************************/ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_SendMsgPtr(IPC_STRUCT_Type* base, uint32_t notifyEventIntr, void const * msgPtr) { @@ -839,8 +869,6 @@ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_SendMsgPtr(IPC_STRUCT_Type* ba * * This function is used to read a 32-bit pointer message through an IPC channel. * -* This function is internal and should not be called directly by user software. -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -859,6 +887,9 @@ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_SendMsgPtr(IPC_STRUCT_Type* ba * channel was already in a released state meaning the data * in it is invalid. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_ReadMsgPtr +* *******************************************************************************/ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_ReadMsgPtr (IPC_STRUCT_Type const * base, void ** msgPtr) { @@ -872,8 +903,6 @@ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_ReadMsgPtr (IPC_STRUCT_Type c * * This function is used to acquire the IPC channel. * -* This function is internal and should not be called directly by user software -* * \param base * This parameter is a handle that represents the base address of the registers * of the IPC channel. @@ -885,6 +914,9 @@ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_ReadMsgPtr (IPC_STRUCT_Type c * \retval CY_IPC_DRV_ERROR: The IPC was not acquired because it was already acquired * by another master * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Drv_LockAcquire +* *******************************************************************************/ __STATIC_INLINE cy_en_ipcdrv_status_t Cy_IPC_Drv_LockAcquire (IPC_STRUCT_Type const * base) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_pipe.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_pipe.c similarity index 89% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_pipe.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_pipe.c index 96617a3db1..3762088267 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_pipe.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_pipe.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_ipc_pipe.c -* \version 1.10 +* \version 1.10.1 * * Description: * IPC Pipe Driver - This source file includes code for the Pipe layer on top * of the IPC driver. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -25,10 +25,18 @@ static cy_stc_ipc_pipe_ep_t * cy_ipc_pipe_epArray = NULL; * This function stores a copy of a pointer to the array of endpoints. All * access to endpoints will be via the index of the endpoint in this array. * +* \note In general case, this function is called in the default startup code, +* so user doesn't need to call it anywhere. +* However, it may be useful in case of some pipe customizations. +* * \param theEpArray * This is the pointer to an array of endpoint structures that the designer * created and will be used to reference all endpoints. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myIpcPipeEpArray +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_Config +* *******************************************************************************/ void Cy_IPC_Pipe_Config(cy_stc_ipc_pipe_ep_t * theEpArray) { @@ -46,9 +54,18 @@ void Cy_IPC_Pipe_Config(cy_stc_ipc_pipe_ep_t * theEpArray) * Initializes the system pipes. The system pipes are used by BLE. * \note The function should be called on all CPUs. * +* \note In general case, this function is called in the default startup code, +* so user doesn't need to call it anywhere. +* However, it may be useful in case of some pipe customizations. +* * \param config * This is the pointer to the pipe configuration structure * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myIpcPipeCbArray +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myIpcPipeEpConfig +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_Init +* *******************************************************************************/ void Cy_IPC_Pipe_Init(cy_stc_ipc_pipe_config_t const *config) { @@ -123,6 +140,10 @@ void Cy_IPC_Pipe_Init(cy_stc_ipc_pipe_config_t const *config) * with the callback functions for that endpoint using the * Cy_IPC_Pipe_RegisterCallback() function. * +* \note In general case, this function is called within \ref Cy_IPC_Pipe_Init, +* so user doesn't need to call it anywhere. +* However, it may be useful in case of some pipe/endpoint customizations. +* * \param epAddr * This parameter is the address (or index in the array of endpoint structures) * that designates the endpoint you want to initialize. @@ -145,6 +166,11 @@ void Cy_IPC_Pipe_Init(cy_stc_ipc_pipe_config_t const *config) * \param epInterrupt * This is a pointer to the endpoint interrupt description structure. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myIpcPipeCbArray +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myIpcPipeEpConfig +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_EndpointInit +* *******************************************************************************/ void Cy_IPC_Pipe_EndpointInit(uint32_t epAddr, cy_ipc_pipe_callback_array_ptr_t cbArray, uint32_t cbCnt, uint32_t epConfig, cy_stc_sysint_t const *epInterrupt) @@ -203,11 +229,15 @@ void Cy_IPC_Pipe_EndpointInit(uint32_t epAddr, cy_ipc_pipe_callback_array_ptr_t * \param callBackPtr * Pointer to the Release callback function. * -* \return +* \return * CY_IPC_PIPE_SUCCESS: Message was sent to the other end of the pipe * CY_IPC_PIPE_ERROR_BAD_HANDLE: The handle provided for the pipe was not valid * CY_IPC_PIPE_ERROR_SEND_BUSY: The pipe is already busy sending a message * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myReleaseCallback +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_SendMessage +* *******************************************************************************/ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_SendMessage(uint32_t toAddr, uint32_t fromAddr, void * msgPtr, cy_ipc_pipe_relcallback_ptr_t callBackPtr) @@ -299,20 +329,25 @@ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_SendMessage(uint32_t toAddr, uint32_t fromAd * * \param callBackPtr * Pointer to the callback function called when the endpoint has received a message. +* If this parameters is NULL current callback will be unregistered. * * \param clientId * The index in the callback array (Client ID) where the function pointer is saved. * -* \return +* \return * CY_IPC_PIPE_SUCCESS: Callback registered successfully * CY_IPC_PIPE_ERROR_BAD_CLIENT: Client ID out of range, callback not registered. +* +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myAcquireCallback +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_RegisterCallback +* *******************************************************************************/ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_RegisterCallback(uint32_t epAddr, cy_ipc_pipe_callback_ptr_t callBackPtr, uint32_t clientId) { cy_en_ipc_pipe_status_t returnStatus; cy_stc_ipc_pipe_ep_t * thisEp; - CY_ASSERT_L1(NULL != callBackPtr); CY_ASSERT_L2(CY_IPC_MAX_ENDPOINTS > epAddr); thisEp = &cy_ipc_pipe_epArray[epAddr]; @@ -346,15 +381,20 @@ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_RegisterCallback(uint32_t epAddr, cy_ipc_pip * * \param callBackPtr * Pointer to the callback executed when the endpoint has received a message. +* If this parameters is NULL current callback will be unregistered. * -* \return +* \return * None +* +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myDefaultReleaseCallback +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_RegisterCallbackRel +* *******************************************************************************/ void Cy_IPC_Pipe_RegisterCallbackRel(uint32_t epAddr, cy_ipc_pipe_relcallback_ptr_t callBackPtr) { cy_stc_ipc_pipe_ep_t * endpoint; - CY_ASSERT_L1(NULL != callBackPtr); CY_ASSERT_L2(CY_IPC_MAX_ENDPOINTS > epAddr); endpoint = &cy_ipc_pipe_epArray[epAddr]; @@ -373,8 +413,13 @@ void Cy_IPC_Pipe_RegisterCallbackRel(uint32_t epAddr, cy_ipc_pipe_relcallback_pt * \param endpoint * Pointer to endpoint structure. * -* \return +* \return * None +* +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_myIpcPipeEpArray +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_ExecCallback +* *******************************************************************************/ void Cy_IPC_Pipe_ExecCallback(cy_stc_ipc_pipe_ep_t * endpoint) { @@ -464,9 +509,12 @@ void Cy_IPC_Pipe_ExecCallback(cy_stc_ipc_pipe_ep_t * endpoint) * This parameter is the address (or index in the array of endpoint structures) * that designates the endpoint to pause. * -* \return +* \return * CY_IPC_PIPE_SUCCESS: Callback registered successfully * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_EndpointPauseResume +* *******************************************************************************/ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_EndpointPause(uint32_t epAddr) { @@ -492,9 +540,12 @@ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_EndpointPause(uint32_t epAddr) * This parameter is the address (or index in the array of endpoint structures) * that designates the endpoint to resume. * -* \return +* \return * CY_IPC_PIPE_SUCCESS: Callback registered successfully * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Pipe_EndpointPauseResume +* *******************************************************************************/ cy_en_ipc_pipe_status_t Cy_IPC_Pipe_EndpointResume(uint32_t epAddr) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_pipe.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_pipe.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_pipe.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_pipe.h index 5656d357f0..315cc6302a 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_pipe.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_pipe.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_ipc_pipe.h -* \version 1.10 +* \version 1.10.1 * * Description: * IPC Pipe Driver - This header file contains all the function prototypes, * structure definitions, pipe constants, and pipe endpoint address definitions. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_sema.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_sema.c similarity index 90% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_sema.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_sema.c index a7a1e036e3..7e18c2698f 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_sema.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_sema.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_ipc_sema.c -* \version 1.10 +* \version 1.10.1 * * Description: * IPC Semaphore Driver - This source file contains the source code for the * semaphore level APIs for the IPC interface. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -27,7 +27,8 @@ static IPC_STRUCT_Type* cy_semaIpcStruct; /* * Internal IPC semaphore control data structure. */ -typedef struct { +typedef struct +{ uint32_t maxSema; /* Maximum semaphores in system */ uint32_t *arrayPtr; /* Pointer to semaphores array */ } cy_stc_ipc_sema_t; @@ -56,12 +57,15 @@ typedef struct { * \param memPtr * This points to the array of (count/32) words that contain the semaphore data. * -* \return +* \return Status of the operation * \retval CY_IPC_SEMA_SUCCESS: Successfully initialized * \retval CY_IPC_SEMA_BAD_PARAM: Memory pointer is NULL and count is not zero, * or count not multiple of 32 * \retval CY_IPC_SEMA_ERROR_LOCKED: Could not acquire semaphores IPC channel * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Sema_Init +* *******************************************************************************/ cy_en_ipcsema_status_t Cy_IPC_Sema_Init(uint32_t ipcChannel, uint32_t count, uint32_t memPtr[]) @@ -144,7 +148,8 @@ cy_en_ipcsema_status_t Cy_IPC_Sema_Init(uint32_t ipcChannel, * CY_IPC_SEMA_LOCKED. * * It first acquires the IPC channel that is used for all the semaphores, sets -* the semaphore if it is cleared, then releases the IPC channel used for the semaphore. +* the semaphore if it is cleared, then releases the IPC channel used for the +* semaphore. * * \param semaNumber * The semaphore number to acquire. @@ -153,13 +158,22 @@ cy_en_ipcsema_status_t Cy_IPC_Sema_Init(uint32_t ipcChannel, * When this parameter is enabled the function can be preempted by another * task or other forms of context switching in an RTOS environment. * -* \return +* \note +* If preemptable is enabled (true), the user must ensure that there are +* no deadlocks in the system, which can be caused by an interrupt that occurs +* after the IPC channel is locked. Unless the user is ready to handle IPC +* channel locks correctly at the application level, set premptable to +* false. +* +* \return Status of the operation * \retval CY_IPC_SEMA_SUCCESS: The semaphore was set successfully * \retval CY_IPC_SEMA_LOCKED: The semaphore channel is busy or locked * by another process * \retval CY_IPC_SEMA_NOT_ACQUIRED: Semaphore was already set * \retval CY_IPC_SEMA_OUT_OF_RANGE: The semaphore number is not valid * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Sema_Set * *******************************************************************************/ cy_en_ipcsema_status_t Cy_IPC_Sema_Set(uint32_t semaNumber, bool preemptable) @@ -223,7 +237,8 @@ cy_en_ipcsema_status_t Cy_IPC_Sema_Set(uint32_t semaNumber, bool preemptable) * This functions tries to releases a semaphore. * * It first acquires the IPC channel that is used for all the semaphores, clears -* the semaphore if it is set, then releases the IPC channel used for the semaphores. +* the semaphore if it is set, then releases the IPC channel used for the +* semaphores. * * \param semaNumber * The index of the semaphore to release. @@ -232,12 +247,21 @@ cy_en_ipcsema_status_t Cy_IPC_Sema_Set(uint32_t semaNumber, bool preemptable) * When this parameter is enabled the function can be preempted by another * task or other forms of context switching in an RTOS environment. * -* \return +* \note +* If preemptable is enabled (true), the user must ensure that there are +* no deadlocks in the system, which can be caused by an interrupt that occurs +* after the IPC channel is locked. Unless the user is ready to handle IPC +* channel locks correctly at the application level, set premptable to +* false. +* +* \return Status of the operation * \retval CY_IPC_SEMA_SUCCESS: The semaphore was cleared successfully * \retval CY_IPC_SEMA_NOT_ACQUIRED: The semaphore was already cleared * \retval CY_IPC_SEMA_LOCKED: The semaphore channel was semaphored or busy * \retval CY_IPC_SEMA_OUT_OF_RANGE: The semaphore number is not valid * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Sema_Clear * *******************************************************************************/ cy_en_ipcsema_status_t Cy_IPC_Sema_Clear(uint32_t semaNumber, bool preemptable) @@ -301,18 +325,15 @@ cy_en_ipcsema_status_t Cy_IPC_Sema_Clear(uint32_t semaNumber, bool preemptable) * \param semaNumber * The index of the semaphore to return status. * -* \return +* \return Status of the operation * \retval CY_IPC_SEMA_STATUS_LOCKED: The semaphore is in the set state. * \retval CY_IPC_SEMA_STATUS_UNLOCKED: The semaphore is in the cleared state. * \retval CY_IPC_SEMA_OUT_OF_RANGE: The semaphore number is not valid * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Sema_Status * *******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif cy_en_ipcsema_status_t Cy_IPC_Sema_Status(uint32_t semaNumber) { cy_en_ipcsema_status_t retStatus; @@ -355,6 +376,9 @@ cy_en_ipcsema_status_t Cy_IPC_Sema_Status(uint32_t semaNumber) * \return * Returns the semaphores quantity. * +* \funcusage +* \snippet IPC_sut_01.cydsn/main_cm4.c snippet_Cy_IPC_Sema_GetMaxSems +* *******************************************************************************/ uint32_t Cy_IPC_Sema_GetMaxSems(void) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_sema.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_sema.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_sema.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_sema.h index f2a202d1d2..bca926b245 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/ipc/cy_ipc_sema.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/ipc/cy_ipc_sema.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_ipc_sema.h -* \version 1.10 +* \version 1.10.1 * * \brief * Header file for IPC SEM functions * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lpcomp/cy_lpcomp.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lpcomp/cy_lpcomp.c similarity index 85% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lpcomp/cy_lpcomp.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lpcomp/cy_lpcomp.c index 655f83c97d..0ea938a732 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lpcomp/cy_lpcomp.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lpcomp/cy_lpcomp.c @@ -1,6 +1,6 @@ /******************************************************************************* * \file cy_lpcomp.c -* \version 1.10 +* \version 1.10.1 * * \brief * This file provides the driver code to the API for the Low Power Comparator @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -19,6 +19,7 @@ extern "C" { #endif +static cy_stc_lpcomp_context_t cy_lpcomp_context; /******************************************************************************* * Function Name: Cy_LPComp_Init @@ -46,6 +47,8 @@ cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type* base, cy_en_lpcomp_channel_t c CY_ASSERT_L3(CY_LPCOMP_IS_CHANNEL_VALID(channel)); CY_ASSERT_L3(CY_LPCOMP_IS_OUT_MODE_VALID(config->outputMode)); CY_ASSERT_L3(CY_LPCOMP_IS_HYSTERESIS_VALID(config->hysteresis)); + CY_ASSERT_L3(CY_LPCOMP_IS_POWER_VALID(config->power)); + CY_ASSERT_L3(CY_LPCOMP_IS_INTR_MODE_VALID(config->intType)); if ((base != NULL) && (config != NULL)) { @@ -63,7 +66,13 @@ cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type* base, cy_en_lpcomp_channel_t c _VAL2FLD(LPCOMP_CMP1_CTRL_DSI_BYPASS1, (uint32_t)config->outputMode) | _VAL2FLD(LPCOMP_CMP1_CTRL_DSI_LEVEL1, (uint32_t)config->outputMode >> 1u); } - + + /* Save intType to use it in the Cy_LPComp_Enable() function */ + cy_lpcomp_context.intType[(uint8_t)channel - 1u] = config->intType; + + /* Save power to use it in the Cy_LPComp_Enable() function */ + cy_lpcomp_context.power[(uint8_t)channel - 1u] = config->power; + ret = CY_LPCOMP_SUCCESS; } @@ -71,13 +80,85 @@ cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type* base, cy_en_lpcomp_channel_t c } +/******************************************************************************* +* Function Name: Cy_LPComp_Enable +****************************************************************************//** +* +* Enables the LPCOMP and sets the LPCOMP interrupt mode. +* +* \param *base +* The LPCOMP register structure pointer. +* +* \param channel +* The LPCOMP channel index. +* +* \return None +* +*******************************************************************************/ +void Cy_LPComp_Enable(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel) +{ + cy_en_lpcomp_pwr_t powerSpeed; + + CY_ASSERT_L3(CY_LPCOMP_IS_CHANNEL_VALID(channel)); + + powerSpeed = cy_lpcomp_context.power[(uint8_t)channel - 1u]; + + /* Set power */ + Cy_LPComp_SetPower(base, channel, powerSpeed); + + /* Make delay before enabling the comparator interrupt to prevent false triggering */ + if (CY_LPCOMP_MODE_ULP == powerSpeed) + { + Cy_SysLib_DelayUs(CY_LPCOMP_ULP_POWER_DELAY); + } + else if (CY_LPCOMP_MODE_LP == powerSpeed) + { + Cy_SysLib_DelayUs(CY_LPCOMP_LP_POWER_DELAY); + } + else + { + Cy_SysLib_DelayUs(CY_LPCOMP_NORMAL_POWER_DELAY); + } + + /* Enable the comparator interrupt */ + Cy_LPComp_SetInterruptTriggerMode(base, channel, cy_lpcomp_context.intType[(uint8_t)channel - 1u]); +} + + +/******************************************************************************* +* Function Name: Cy_LPComp_Disable +****************************************************************************//** +* +* Disables the LPCOMP power and sets the interrupt mode to disabled. +* +* \param *base +* The LPCOMP register structure pointer. +* +* \param channel +* The LPCOMP channel index. +* +* \return None +* +*******************************************************************************/ +void Cy_LPComp_Disable(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel) +{ + CY_ASSERT_L3(CY_LPCOMP_IS_CHANNEL_VALID(channel)); + + /* Disable the comparator interrupt */ + Cy_LPComp_SetInterruptTriggerMode(base, channel, CY_LPCOMP_INTR_DISABLE); + + /* Set power off */ + Cy_LPComp_SetPower(base, channel, CY_LPCOMP_MODE_OFF); +} + + /******************************************************************************* * Function Name: Cy_LPComp_SetInterruptTriggerMode ****************************************************************************//** * * Sets the interrupt edge-detect mode. * This also controls the value provided on the output. -* Note: Interrupts can be enabled after the block is enabled and the appropriate +* \note Interrupts can be enabled after the block is enabled and the appropriate * start-up time has elapsed: * 3 us for the normal power mode; * 6 us for the LP mode; @@ -100,7 +181,7 @@ cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type* base, cy_en_lpcomp_channel_t c * *******************************************************************************/ void Cy_LPComp_SetInterruptTriggerMode(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_int_t intType) -{ +{ CY_ASSERT_L3(CY_LPCOMP_IS_CHANNEL_VALID(channel)); CY_ASSERT_L3(CY_LPCOMP_IS_INTR_MODE_VALID(intType)); @@ -112,6 +193,9 @@ void Cy_LPComp_SetInterruptTriggerMode(LPCOMP_Type* base, cy_en_lpcomp_channel_t { base->CMP1_CTRL = _CLR_SET_FLD32U(base->CMP1_CTRL, LPCOMP_CMP1_CTRL_INTTYPE1, (uint32_t)intType); } + + /* Save interrupt type to use it in the Cy_LPComp_Enable() function */ + cy_lpcomp_context.intType[(uint8_t)channel - 1u] = intType; } @@ -120,8 +204,12 @@ void Cy_LPComp_SetInterruptTriggerMode(LPCOMP_Type* base, cy_en_lpcomp_channel_t ****************************************************************************//** * * Sets the drive power and speeds to one of the four settings. -* Note: The comparator interrupt should be enabled after enabling of the -* comparator itself. Otherwise, unexpected interrupts events can occur. +* \note Interrupts can be enabled after the block is enabled and the appropriate +* start-up time has elapsed: +* 3 us for the normal power mode; +* 6 us for the LP mode; +* 50 us for the ULP mode. +* Otherwise, unexpected interrupts events can occur. * * \param *base * The LPCOMP register structure pointer. @@ -200,7 +288,7 @@ void Cy_LPComp_SetHysteresis(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, * comparator input can be connected to the local VREF. * At least one unconnected input causes a comparator undefined output. * -* Note: Connection to AMUXBUSA/AMUXBUSB requires closing the additional +* \note Connection to AMUXBUSA/AMUXBUSB requires closing the additional * switches which are a part of the IO system. These switches can be configured * using the HSIOM->AMUX_SPLIT_CTL[3] register. * Refer to the appropriate Technical Reference Manual (TRM) of a device @@ -347,8 +435,6 @@ void Cy_LPComp_SetOutputMode(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, * It stores the state of the LPComp enable and then disables the LPComp block * before going to the low power modes, and recovers the LPComp power state after * wake-up using the stored value. -* The function attribution has a weak linkage, so the user can override this -* function for a custom lower-power callback. * * \param *callbackParams * The \ref cy_stc_syspm_callback_params_t structure with the callback @@ -458,8 +544,6 @@ cy_en_syspm_status_t Cy_LPComp_DeepSleepCallback(cy_stc_syspm_callback_params_t * * This function checks the current power mode of LPComp and then disable the * LPComp block, if there is no wake-up source from LPComp in the hibernate mode. -* The function attribution has a weak linkage, so the user can override this -* function for a custom lower-power callback. * * \param *callbackParams * The \ref cy_stc_syspm_callback_params_t structure with the callback diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lpcomp/cy_lpcomp.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lpcomp/cy_lpcomp.h similarity index 92% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lpcomp/cy_lpcomp.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lpcomp/cy_lpcomp.h index 4d781123aa..18df43a9ac 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lpcomp/cy_lpcomp.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lpcomp/cy_lpcomp.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_lpcomp.h -* \version 1.10 +* \version 1.10.1 * * This file provides constants and parameter values for the Low Power Comparator driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -50,27 +50,19 @@ * to the dedicated IO pins, AMUXBUSA/AMUXBUSB or Vref: * \image html lpcomp_inputs.png * -* 4) Power on the comparator using the Cy_LPComp_SetPower() function. +* 4) Power on the comparator using the Cy_LPComp_Enable() function. * -* 5) Optionally, enable the comparator interrupt using -* Cy_LPComp_SetInterruptTriggerMode() with the corresponding parameter -* for the interrupt mode (Rising edge, Falling edge, or Both edges). -* -* 6) The comparator output can be monitored using +* 5) The comparator output can be monitored using * the Cy_LPComp_GetCompare() function or using the LPComp interrupt * (if the interrupt is enabled). * -* NOTE 1: To prevent false triggering, a delay before enabling -* the comparator interrupt is required. The recommended delay is -* 10 us for the Normal power mode and 50 us for the Ultra low-power mode. -* -* NOTE 2: The interrupt is not cleared automatically. +* \note The interrupt is not cleared automatically. * It is the user's responsibility to do that. * The interrupt is cleared by writing a 1 in the corresponding interrupt * register bit position. The preferred way to clear interrupt sources * is using the Cy_LPComp_ClearInterrupt() function. * -* NOTE 3: Individual comparator interrupt outputs are ORed together +* \note Individual comparator interrupt outputs are ORed together * as a single asynchronous interrupt source before it is sent out and * used to wake up the system in the low-power mode. * For PSoC 6 devices, the individual comparator interrupt is masked @@ -78,6 +70,17 @@ * the INTR_MASKED register. * Writing a 1 to the INTR register bit will clear the interrupt. * +* \section group_lpcomp_lp Low Power Support +* The LPComp provides the callback functions to facilitate +* the low-power mode transition. The callback +* \ref Cy_LPComp_DeepSleepCallback must be called during execution +* of \ref Cy_SysPm_DeepSleep; \ref Cy_LPComp_HibernateCallback must be +* called during execution of \ref Cy_SysPm_Hibernate. +* To trigger the callback execution, the callback must be registered +* before calling the mode transition function. +* Refer to \ref group_syspm driver for more +* information about low-power mode transitions. +* * \section group_lpcomp_more_information More Information * * Refer to the appropriate device technical reference manual (TRM) for @@ -112,9 +115,9 @@ * * * -* -* -* +* +* +* * * * @@ -123,11 +126,19 @@ * Added input parameter validation to the API functions. * * +* +* +* +* +* *
VersionChangesReason for Change
1.0Initial version1.10.1Added Low Power Callback sectionDocumentation update and clarification
1.10
1.0Initial version
* * \defgroup group_lpcomp_macros Macros * \defgroup group_lpcomp_functions Functions -* \defgroup group_lpcomp_data_structures Data structures +* \{ +* \defgroup group_lpcomp_functions_syspm_callback Low Power Callback +* \} +* \defgroup group_lpcomp_data_structures Data Structures * \defgroup group_lpcomp_enums Enumerated Types */ @@ -227,10 +238,15 @@ extern "C" #define CY_HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_SR_Msk (HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk | \ HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk) -#define CY_LPCOMP_REF_CONNECTED (1u) +#define CY_LPCOMP_REF_CONNECTED (1u) -#define CY_LPCOMP_WAKEUP_PIN0_Msk CY_SYSPM_WAKEUP_LPCOMP0 -#define CY_LPCOMP_WAKEUP_PIN1_Msk CY_SYSPM_WAKEUP_LPCOMP1 +#define CY_LPCOMP_WAKEUP_PIN0_Msk CY_SYSPM_WAKEUP_LPCOMP0 +#define CY_LPCOMP_WAKEUP_PIN1_Msk CY_SYSPM_WAKEUP_LPCOMP1 + +/* Internal constants for Cy_LPComp_Enable() */ +#define CY_LPCOMP_NORMAL_POWER_DELAY (3u) +#define CY_LPCOMP_LP_POWER_DELAY (6u) +#define CY_LPCOMP_ULP_POWER_DELAY (50u) /** \endcond */ /** \} group_lpcomp_macros */ @@ -319,8 +335,19 @@ typedef struct { cy_en_lpcomp_out_t outputMode; /**< The LPCOMP's outputMode: Direct output, Synchronized output or Pulse output */ cy_en_lpcomp_hyst_t hysteresis; /**< Enables or disables the LPCOMP's hysteresis */ + cy_en_lpcomp_pwr_t power; /**< Sets the LPCOMP power mode */ + cy_en_lpcomp_int_t intType; /**< Sets the LPCOMP interrupt mode */ } cy_stc_lpcomp_config_t; +/** \cond CONTEXT_STRUCTURE */ + +typedef struct { + cy_en_lpcomp_int_t intType[CY_LPCOMP_MAX_CHANNEL_NUM]; + cy_en_lpcomp_pwr_t power[CY_LPCOMP_MAX_CHANNEL_NUM]; +} cy_stc_lpcomp_context_t; + +/** \endcond */ + /** \} group_lpcomp_data_structures */ /** \cond INTERNAL_MACROS */ @@ -354,7 +381,7 @@ typedef struct { ((input) == CY_LPCOMP_SW_AMUXBUSB) || \ ((input) == CY_LPCOMP_SW_LOCAL_VREF)) -/** \endcond */ +/** \endcond */ /** * \addtogroup group_lpcomp_functions @@ -366,6 +393,8 @@ typedef struct { *******************************************************************************/ cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel, const cy_stc_lpcomp_config_t *config); +void Cy_LPComp_Enable(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel); +void Cy_LPComp_Disable(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel); __STATIC_INLINE void Cy_LPComp_GlobalEnable(LPCOMP_Type *base); __STATIC_INLINE void Cy_LPComp_GlobalDisable(LPCOMP_Type *base); __STATIC_INLINE void Cy_LPComp_UlpReferenceEnable(LPCOMP_Type *base); @@ -383,8 +412,13 @@ __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptMask(LPCOMP_Type const * base); __STATIC_INLINE void Cy_LPComp_SetInterruptMask(LPCOMP_Type* base, uint32_t interrupt); __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptStatusMasked(LPCOMP_Type const * base); __STATIC_INLINE void Cy_LPComp_ConnectULPReference(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel); +/** \addtogroup group_lpcomp_functions_syspm_callback +* The driver supports SysPm callback for Deep Sleep and Hibernate transition. +* \{ +*/ cy_en_syspm_status_t Cy_LPComp_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams); cy_en_syspm_status_t Cy_LPComp_HibernateCallback(cy_stc_syspm_callback_params_t *callbackParams); +/** \} */ /******************************************************************************* @@ -472,8 +506,6 @@ __STATIC_INLINE void Cy_LPComp_UlpReferenceDisable(LPCOMP_Type *base) * * This function returns a nonzero value when the voltage connected to the * positive input is greater than the negative input voltage. -* This function reads the direct (unflopped) comparator output, which can -* also be metastable (since it may result in incorrect data). * * \param *base * The LPComp register structure pointer. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lvd/cy_lvd.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lvd/cy_lvd.c similarity index 87% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lvd/cy_lvd.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lvd/cy_lvd.c index ea524c97b5..6117ded8ed 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lvd/cy_lvd.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lvd/cy_lvd.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_lvd.c -* \version 1.0 +* \version 1.0.1 * * The source code file for the LVD driver. * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -24,9 +24,9 @@ extern "C" { ****************************************************************************//** * * When this function is registered by \ref Cy_SysPm_RegisterCallback - it -* automatically enables the LVD after wake up from DeepSleep mode. +* automatically enables the LVD after wake up from Deep-Sleep mode. * -* \param callbackParams a pointer to the callback parameters structure, +* \param callbackParams The pointer to the callback parameters structure, * see \ref cy_stc_syspm_callback_params_t. * * \return the SysPm callback status \ref cy_en_syspm_status_t. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lvd/cy_lvd.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lvd/cy_lvd.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lvd/cy_lvd.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lvd/cy_lvd.h index 4bef5308d4..12bc857fdb 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/lvd/cy_lvd.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/lvd/cy_lvd.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_lvd.h -* \version 1.0 +* \version 1.0.1 * * The header file of the LVD driver. * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -29,7 +29,7 @@ * Then configure interrupts by the \ref Cy_LVD_SetInterruptConfig function, do * not forget to initialise an interrupt handler (the interrupt source number * is srss_interrupt_IRQn). -* Then enable LVD by the \ref Cy_LVD_Enable function, then wait for at least 8us +* Then enable LVD by the \ref Cy_LVD_Enable function, then wait for at least 20us * to get the circuit stabilized and clear the possible false interrupts by the * \ref Cy_LVD_ClearInterrupt, and finally the LVD interrupt can be enabled by * the \ref Cy_LVD_SetInterruptMask function. @@ -84,6 +84,11 @@ * * * +* +* +* +* +* * * * @@ -92,7 +97,10 @@ * * \defgroup group_lvd_macros Macros * \defgroup group_lvd_functions Functions -* \defgroup group_lvd_enums Enumerated types +* \{ +* \defgroup group_lvd_functions_syspm_callback Low Power Callback +* \} +* \defgroup group_lvd_enums Enumerated Types */ @@ -109,13 +117,13 @@ extern "C" { * \{ */ -/** Driver major version */ +/** The driver major version */ #define CY_LVD_DRV_VERSION_MAJOR 1 -/** Driver minor version */ +/** The driver minor version */ #define CY_LVD_DRV_VERSION_MINOR 0 -/** LVD driver identifier */ +/** The LVD driver identifier */ #define CY_LVD_ID (CY_PDL_DRV_ID(0x39U)) /** Interrupt mask for \ref Cy_LVD_GetInterruptStatus(), @@ -217,8 +225,12 @@ __STATIC_INLINE void Cy_LVD_SetInterruptMask(void); __STATIC_INLINE void Cy_LVD_ClearInterruptMask(void); __STATIC_INLINE uint32_t Cy_LVD_GetInterruptStatusMasked(void); __STATIC_INLINE void Cy_LVD_SetInterruptConfig(cy_en_lvd_intr_config_t lvdInterruptConfig); +/** \addtogroup group_lvd_functions_syspm_callback +* The driver supports SysPm callback for Deep Sleep transition. +* \{ +*/ cy_en_syspm_status_t Cy_LVD_DeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams); - +/** \} */ /******************************************************************************* * Function Name: Cy_LVD_Enable diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/mcwdt/cy_mcwdt.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/mcwdt/cy_mcwdt.c new file mode 100644 index 0000000000..0c913a11f4 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/mcwdt/cy_mcwdt.c @@ -0,0 +1,192 @@ +/***************************************************************************//** +* \file cy_mcwdt.c +* \version 1.10.1 +* +* Description: +* Provides a system API for the MCWDT driver. +* +******************************************************************************** +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +#include "cy_mcwdt.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/******************************************************************************* +* Function Name: Cy_MCWDT_Init +****************************************************************************//** +* +* Initializes the MCWDT block. +* +* \param base +* The base pointer to a structure that describes the registers. +* +* \param config +* The pointer to a structure that contains component configuration data. +* +* \return cy_en_mcwdt_status_t +* *base checking result. If the pointer is NULL, returns error. +* +* \note +* This API should not be called when the counters are running. Prior to calling +* this API the counter should be disabled. +* +*******************************************************************************/ +cy_en_mcwdt_status_t Cy_MCWDT_Init(MCWDT_STRUCT_Type *base, cy_stc_mcwdt_config_t const *config) +{ + cy_en_mcwdt_status_t ret = CY_MCWDT_BAD_PARAM; + + if ((base != NULL) && (config != NULL)) + { + CY_ASSERT_L2(CY_MCWDT_IS_MATCH_VALID(config->c0ClearOnMatch, config->c0Match)); + CY_ASSERT_L2(CY_MCWDT_IS_MATCH_VALID(config->c1ClearOnMatch, config->c1Match)); + CY_ASSERT_L2(CY_MCWDT_IS_BIT_VALID(config->c2ToggleBit)); + CY_ASSERT_L3(CY_MCWDT_IS_MODE_VALID((cy_en_mcwdtmode_t)config->c0Mode)); + CY_ASSERT_L3(CY_MCWDT_IS_MODE_VALID((cy_en_mcwdtmode_t)config->c1Mode)); + CY_ASSERT_L3(CY_MCWDT_IS_MODE_VALID((cy_en_mcwdtmode_t)config->c2Mode)); + + base->MCWDT_MATCH = _VAL2FLD(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH1, config->c1Match) | + _VAL2FLD(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH0, config->c0Match); + + base->MCWDT_CONFIG = _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_BITS2, config->c2ToggleBit) | + _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_MODE2, config->c2Mode) | + _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR0, config->c0ClearOnMatch) | + _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR1, config->c1ClearOnMatch) | + (config->c1c2Cascade ? MCWDT_STRUCT_MCWDT_CONFIG_WDT_CASCADE1_2_Msk : 0UL) | + _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_MODE1, config->c1Mode) | + (config->c0c1Cascade ? MCWDT_STRUCT_MCWDT_CONFIG_WDT_CASCADE0_1_Msk : 0UL) | + _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_MODE0, config->c0Mode); + + ret = CY_MCWDT_SUCCESS; + } + + return (ret); +} + + +/******************************************************************************* +* Function Name: Cy_MCWDT_DeInit +****************************************************************************//** +* +* De-initializes the MCWDT block, returns register values to their default state. +* +* \param base +* The base pointer to a structure that describes the registers. +* +* \note +* This API should not be called when the counters are running. Prior to calling +* this API the counter should be disabled. +* +*******************************************************************************/ +void Cy_MCWDT_DeInit(MCWDT_STRUCT_Type *base) +{ + Cy_MCWDT_Unlock(base); + + base->MCWDT_CNTLOW = 0UL; + base->MCWDT_CNTHIGH = 0UL; + base->MCWDT_MATCH = 0UL; + base->MCWDT_CONFIG = 0UL; + base->MCWDT_CTL = 0UL; + base->MCWDT_INTR = 0UL; + base->MCWDT_INTR_SET = 0UL; + base->MCWDT_INTR_MASK = 0UL; +} + + +/******************************************************************************* +* Function Name: Cy_MCWDT_GetCountCascaded +****************************************************************************//** +* +* Reports the current value of combined C1-C0 cascaded counters. +* +* \param base +* The base pointer to a structure that describes the registers. +* +* \note +* The user must enable both counters, and cascade C0 to C1, +* before calling this function. C2 is not reported. +* Instead, to get a 64-bit C2-C1-C0 cascaded value, the +* user must call this function followed by +* Cy_MCWDT_GetCount(base, CY_MCWDT_COUNTER2), and then combine the results. +* \note This function does not return the correct result when it is called +* after the Cy_MCWDT_Enable() or Cy_MCWDT_ResetCounters() function with +* a delay less than two lf_clk cycles. The recommended waitUs parameter +* value is 100 us. +* +*******************************************************************************/ +uint32_t Cy_MCWDT_GetCountCascaded(MCWDT_STRUCT_Type const *base) +{ + uint32_t countVal = base->MCWDT_CNTLOW; + uint32_t counter1 = countVal >> MCWDT_STRUCT_MCWDT_CNTLOW_WDT_CTR1_Pos; + uint32_t counter0 = countVal & MCWDT_STRUCT_MCWDT_CNTLOW_WDT_CTR0_Msk; + uint32_t match0 = _FLD2VAL(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH0, base->MCWDT_MATCH); + uint32_t match1 = _FLD2VAL(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH1, base->MCWDT_MATCH); + + /* + * The counter counter0 goes to zero when it reaches the match0 + * value (c0ClearOnMatch = 1) or reaches the maximum + * value (c0ClearOnMatch = 0). The counter counter1 increments on + * the next rising edge of the MCWDT clock after + * the Clear On Match event takes place. + * The software increments counter1 to eliminate the case + * when the both counter0 and counter1 counters have zeros. + */ + if (0u == counter0) + { + counter1++; + } + + /* Check if the counter0 is Free running */ + if (0u == _FLD2VAL(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR0, base->MCWDT_CONFIG)) + { + /* Save match0 value with the correction when counter0 + * goes to zero when it reaches the match0 value. + */ + countVal = match0 + 1u; + + if (0u < counter1) + { + /* Set match to the maximum value */ + match0 = MCWDT_STRUCT_MCWDT_CNTLOW_WDT_CTR0_Msk; + } + + if (countVal < counter0) + { + /* Decrement counter1 when the counter0 is great than match0 value */ + counter1--; + } + } + + /* Add the correction to counter0 */ + counter0 += counter1; + + /* Set counter1 match value to 65535 when the counter1 is free running */ + if (0u == _FLD2VAL(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR1, base->MCWDT_CONFIG)) + { + match1 = MCWDT_STRUCT_MCWDT_CNTLOW_WDT_CTR1_Msk >> MCWDT_STRUCT_MCWDT_CNTLOW_WDT_CTR1_Pos; + } + + /* Check for overflow */ + if (match1 < counter1) + { + counter1 = 0u; + } + + /* Calculate the combined value for C1-C0 cascaded counters */ + countVal = counter0 + (counter1 * match0); + + return (countVal); +} + + +#if defined(__cplusplus) +} +#endif + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/mcwdt/cy_mcwdt.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/mcwdt/cy_mcwdt.h similarity index 89% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/mcwdt/cy_mcwdt.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/mcwdt/cy_mcwdt.h index 6a0150e11c..887213a061 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/mcwdt/cy_mcwdt.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/mcwdt/cy_mcwdt.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_mcwdt.h -* \version 1.0 +* \version 1.10.1 * * Provides an API declaration of the Cypress PDL 3.0 MCWDT driver * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -15,7 +15,7 @@ /** * \defgroup group_mcwdt Multi-Counter Watchdog (MCWDT) * \{ -* MCWDT has two 16-bit counters and one 32-bit counter. +* A MCWDT has two 16-bit counters and one 32-bit counter. * You can use this driver to create a free-running * timer or generate periodic interrupts. The driver also * includes support for the watchdog function to recover from CPU or @@ -64,7 +64,8 @@ * * You can also set the mode of operation for any counter. If you choose * interrupt mode, use Cy_MCWDT_SetInterruptMask() with the -* parameter for the masks described in Macro Section. +* parameter for the masks described in Macro Section. All counter interrupts +* are OR'd together to from a single combined MCWDT interrupt. * Additionally, enable the Global interrupts and initialize the referenced * interrupt by setting the priority and the interrupt vector using * \ref Cy_SysInt_Init() of the sysint driver. @@ -89,6 +90,17 @@ *
VersionChangesReason of Change
1.0.1Added Low Power Callback sectionDocumentation update and clarification
1.0Initial Version
* * +* +* +* +* +* +* +* +* +* +* * * * @@ -97,7 +109,7 @@ * * \defgroup group_mcwdt_macros Macros * \defgroup group_mcwdt_functions Functions -* \defgroup group_mcwdt_data_structures Data structures +* \defgroup group_mcwdt_data_structures Data Structures * \defgroup group_mcwdt_enums Enumerated Types */ @@ -139,14 +151,10 @@ typedef struct Range: 0 - 31. */ uint8_t c2Mode; /**< The sub-counter#2 mode. It can have the following values: \ref CY_MCWDT_MODE_NONE and \ref CY_MCWDT_MODE_INT. */ - bool c0ClearOnMatch; /**< The sub-counter#0 Clear On Match parameter enabled/disabled. - Range: FALSE - TRUE. */ - bool c1ClearOnMatch; /**< The sub-counter#1 Clear On Match parameter enabled/disabled. - Range: FALSE - TRUE. */ - bool c0c1Cascade; /**< The sub-counter#1 is clocked by LFCLK or from sub-counter#0 cascade. - Range: FALSE - TRUE. */ - bool c1c2Cascade; /**< The sub-counter#2 is clocked by LFCLK or from sub-counter#1 cascade. - Range: FALSE - TRUE. */ + bool c0ClearOnMatch; /**< The sub-counter#0 Clear On Match parameter enabled/disabled. */ + bool c1ClearOnMatch; /**< The sub-counter#1 Clear On Match parameter enabled/disabled. */ + bool c0c1Cascade; /**< The sub-counter#1 is clocked by LFCLK or from sub-counter#0 cascade. */ + bool c1c2Cascade; /**< The sub-counter#2 is clocked by LFCLK or from sub-counter#1 cascade. */ } cy_stc_mcwdt_config_t; /** \} group_mcwdt_data_structures */ @@ -160,7 +168,7 @@ typedef struct #define CY_MCWDT_DRV_VERSION_MAJOR 1 /** Driver minor version */ -#define CY_MCWDT_DRV_VERSION_MINOR 0 +#define CY_MCWDT_DRV_VERSION_MINOR 10 /** \cond INTERNAL_MACROS */ @@ -187,7 +195,9 @@ typedef struct #define CY_MCWDT_CTR0_Pos (0u) #define CY_MCWDT_CTR1_Pos (1u) #define CY_MCWDT_CTR2_Pos (2u) -#define CY_MCWDT_CTR_Pos (0UL) +#define CY_MCWDT_CTR_Pos (0UL) + +#define CY_MCWDT_C2_MODE_MASK (1u) /** \endcond */ @@ -255,6 +265,36 @@ typedef enum /** \} group_mcwdt_enums */ +/** \cond PARAM_CHECK_MACROS */ + +/** Parameter check macros */ +#define CY_MCWDT_IS_CNTS_MASK_VALID(counters) (0U == ((counters) & (uint32_t)~CY_MCWDT_CTR_Msk)) + +#define CY_MCWDT_IS_CNT_NUM_VALID(counter) ((CY_MCWDT_COUNTER0 == (counter)) || \ + (CY_MCWDT_COUNTER1 == (counter)) || \ + (CY_MCWDT_COUNTER2 == (counter))) + +#define CY_MCWDT_IS_MODE_VALID(mode) ((CY_MCWDT_MODE_NONE == (mode)) || \ + (CY_MCWDT_MODE_INT == (mode)) || \ + (CY_MCWDT_MODE_RESET == (mode)) || \ + (CY_MCWDT_MODE_INT_RESET == (mode))) + +#define CY_MCWDT_IS_ENABLE_VALID(enable) (1UL >= (enable)) + + +#define CY_MCWDT_IS_CASCADE_VALID(cascade) ((CY_MCWDT_CASCADE_NONE == (cascade)) || \ + (CY_MCWDT_CASCADE_C0C1 == (cascade)) || \ + (CY_MCWDT_CASCADE_C1C2 == (cascade)) || \ + (CY_MCWDT_CASCADE_BOTH == (cascade))) + +#define CY_MCWDT_IS_MATCH_VALID(clearOnMatch, match) ((clearOnMatch) ? (1UL <= (match)) : true) + +#define CY_MCWDT_IS_BIT_VALID(bit) (31UL >= (bit)) + + +/** \endcond */ + + /******************************************************************************* * Function Prototypes *******************************************************************************/ @@ -289,6 +329,7 @@ __STATIC_INLINE void Cy_MCWDT_SetInterrupt(MCWDT_STRUCT_Type *base, uint32_t __STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptMask(MCWDT_STRUCT_Type const *base); __STATIC_INLINE void Cy_MCWDT_SetInterruptMask(MCWDT_STRUCT_Type *base, uint32_t counters); __STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptStatusMasked(MCWDT_STRUCT_Type const *base); +uint32_t Cy_MCWDT_GetCountCascaded(MCWDT_STRUCT_Type const *base); /******************************************************************************* @@ -319,6 +360,8 @@ __STATIC_INLINE void Cy_MCWDT_Enable(MCWDT_STRUCT_Type *base, uint32_t counters, { uint32_t enableCounters; + CY_ASSERT_L2(CY_MCWDT_IS_CNTS_MASK_VALID(counters)); + /* Extract particular counters for enable */ enableCounters = ((0UL != (counters & CY_MCWDT_CTR0)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_ENABLE0_Msk : 0UL) | ((0UL != (counters & CY_MCWDT_CTR1)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_ENABLE1_Msk : 0UL) | @@ -358,6 +401,8 @@ __STATIC_INLINE void Cy_MCWDT_Disable(MCWDT_STRUCT_Type *base, uint32_t counters { uint32_t disableCounters; + CY_ASSERT_L2(CY_MCWDT_IS_CNTS_MASK_VALID(counters)); + /* Extract particular counters for disable */ disableCounters = ((0UL != (counters & CY_MCWDT_CTR0)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_ENABLE0_Msk : 0UL) | ((0UL != (counters & CY_MCWDT_CTR1)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_ENABLE1_Msk : 0UL) | @@ -389,6 +434,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetEnabledStatus(MCWDT_STRUCT_Type const *base { uint32_t status = 0u; + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + switch (counter) { case CY_MCWDT_COUNTER0: @@ -501,6 +548,9 @@ __STATIC_INLINE void Cy_MCWDT_SetMode(MCWDT_STRUCT_Type *base, cy_en_mcwdtctr_t { uint32_t mask, shift; + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + CY_ASSERT_L3(CY_MCWDT_IS_MODE_VALID(mode)); + shift = CY_MCWDT_BYTE_SHIFT * counter; mask = (counter == CY_MCWDT_COUNTER2) ? CY_MCWDT_C2_MODE_MASK : CY_MCWDT_C0C1_MODE_MASK; mask = mask << shift; @@ -529,6 +579,8 @@ __STATIC_INLINE cy_en_mcwdtmode_t Cy_MCWDT_GetMode(MCWDT_STRUCT_Type const *base { uint32_t mode, mask; + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + mask = (counter == CY_MCWDT_COUNTER2) ? CY_MCWDT_C2_MODE_MASK : CY_MCWDT_C0C1_MODE_MASK; mode = (base->MCWDT_CONFIG >> (CY_MCWDT_BYTE_SHIFT * counter)) & mask; @@ -561,6 +613,9 @@ __STATIC_INLINE cy_en_mcwdtmode_t Cy_MCWDT_GetMode(MCWDT_STRUCT_Type const *base *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_SetClearOnMatch(MCWDT_STRUCT_Type *base, cy_en_mcwdtctr_t counter, uint32_t enable) { + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + CY_ASSERT_L2(CY_MCWDT_IS_ENABLE_VALID(enable)); + if (CY_MCWDT_COUNTER0 == counter) { base->MCWDT_CONFIG = _CLR_SET_FLD32U(base->MCWDT_CONFIG, MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR0, enable); @@ -595,6 +650,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetClearOnMatch(MCWDT_STRUCT_Type const *base, { uint32_t getClear; + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + if (CY_MCWDT_COUNTER0 == counter) { getClear = _FLD2VAL(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR0, base->MCWDT_CONFIG); @@ -627,6 +684,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetClearOnMatch(MCWDT_STRUCT_Type const *base, *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_SetCascade(MCWDT_STRUCT_Type *base, cy_en_mcwdtcascade_t cascade) { + CY_ASSERT_L3(CY_MCWDT_IS_CASCADE_VALID(cascade)); + base->MCWDT_CONFIG = _CLR_SET_FLD32U(base->MCWDT_CONFIG, MCWDT_STRUCT_MCWDT_CONFIG_WDT_CASCADE0_1, (uint32_t) cascade); base->MCWDT_CONFIG = _CLR_SET_FLD32U(base->MCWDT_CONFIG, MCWDT_STRUCT_MCWDT_CONFIG_WDT_CASCADE1_2, @@ -672,8 +731,8 @@ __STATIC_INLINE cy_en_mcwdtcascade_t Cy_MCWDT_GetCascade(MCWDT_STRUCT_Type const * * \param match * The value to match against the counter. -* The valid range is [0-65535] for c0ClearOnMatch = 0 and [1-65535] for -* c0ClearOnMatch = 1. +* The valid range is [0-65535] for c0ClearOnMatch (or c1ClearOnMatch) = 0 +* and [1-65535] for c0ClearOnMatch (or c1ClearOnMatch) = 1. * * \note * The match value is not supported by Counter 2. @@ -693,6 +752,12 @@ __STATIC_INLINE cy_en_mcwdtcascade_t Cy_MCWDT_GetCascade(MCWDT_STRUCT_Type const *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_SetMatch(MCWDT_STRUCT_Type *base, cy_en_mcwdtctr_t counter, uint32_t match, uint16_t waitUs) { + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + CY_ASSERT_L2(CY_MCWDT_IS_MATCH_VALID((CY_MCWDT_COUNTER0 == counter) ? + ((base->MCWDT_CONFIG & MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR0_Msk) > 0U) : + ((base->MCWDT_CONFIG & MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR1_Msk) > 0U), + match)); + base->MCWDT_MATCH = (counter == CY_MCWDT_COUNTER0) ? _CLR_SET_FLD32U(base->MCWDT_MATCH, MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH0, (match & MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH0_Msk)) : @@ -726,6 +791,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetMatch(MCWDT_STRUCT_Type const *base, cy_en_ { uint32_t match; + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + match = (counter == CY_MCWDT_COUNTER0) ? _FLD2VAL(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH0, base->MCWDT_MATCH) : _FLD2VAL(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH1, base->MCWDT_MATCH); @@ -752,6 +819,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetMatch(MCWDT_STRUCT_Type const *base, cy_en_ *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_SetToggleBit(MCWDT_STRUCT_Type *base, uint32_t bit) { + CY_ASSERT_L2(CY_MCWDT_IS_BIT_VALID(bit)); + base->MCWDT_CONFIG = _CLR_SET_FLD32U(base->MCWDT_CONFIG, MCWDT_STRUCT_MCWDT_CONFIG_WDT_BITS2, bit); } @@ -796,6 +865,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetCount(MCWDT_STRUCT_Type const *base, cy_en_ { uint32_t countVal = 0u; + CY_ASSERT_L3(CY_MCWDT_IS_CNT_NUM_VALID(counter)); + switch (counter) { case CY_MCWDT_COUNTER0: @@ -833,6 +904,11 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetCount(MCWDT_STRUCT_Type const *base, cy_en_ * \param waitUs * The function waits for some delay in microseconds before returning, because * a reset occurs after one lf_clk cycle passes. The recommended value is 62 us. +* \note This function resets the counters two times to prevent the case when +* the Counter 1 is not reset when the counters are cascaded. The delay waitUs +* must be greater than 100 us when the counters are cascaded. +* The total delay is greater than 2*waitUs because the function has +* the delay after the first reset. * \note * Setting this parameter to a zero means No wait. In this case, it is the * user's responsibility to check whether the selected counters were reset @@ -844,13 +920,19 @@ __STATIC_INLINE void Cy_MCWDT_ResetCounters(MCWDT_STRUCT_Type *base, uint32_t co { uint32_t resetCounters; + CY_ASSERT_L2(CY_MCWDT_IS_CNTS_MASK_VALID(counters)); + /* Extract particular counters for reset */ resetCounters = ((0UL != (counters & CY_MCWDT_CTR0)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_RESET0_Msk : 0UL) | ((0UL != (counters & CY_MCWDT_CTR1)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_RESET1_Msk : 0UL) | ((0UL != (counters & CY_MCWDT_CTR2)) ? MCWDT_STRUCT_MCWDT_CTL_WDT_RESET2_Msk : 0UL); base->MCWDT_CTL |= resetCounters; - + + Cy_SysLib_DelayUs(waitUs); + + base->MCWDT_CTL |= resetCounters; + Cy_SysLib_DelayUs(waitUs); } @@ -894,6 +976,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptStatus(MCWDT_STRUCT_Type const *ba *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_ClearInterrupt(MCWDT_STRUCT_Type *base, uint32_t counters) { + CY_ASSERT_L2(CY_MCWDT_IS_CNTS_MASK_VALID(counters)); + base->MCWDT_INTR = counters; (void) base->MCWDT_INTR; } @@ -915,6 +999,8 @@ __STATIC_INLINE void Cy_MCWDT_ClearInterrupt(MCWDT_STRUCT_Type *base, uint32_t c *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_SetInterrupt(MCWDT_STRUCT_Type *base, uint32_t counters) { + CY_ASSERT_L2(CY_MCWDT_IS_CNTS_MASK_VALID(counters)); + base->MCWDT_INTR_SET = counters; } @@ -957,6 +1043,8 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptMask(MCWDT_STRUCT_Type const *base *******************************************************************************/ __STATIC_INLINE void Cy_MCWDT_SetInterruptMask(MCWDT_STRUCT_Type *base, uint32_t counters) { + CY_ASSERT_L2(CY_MCWDT_IS_CNTS_MASK_VALID(counters)); + base->MCWDT_INTR_MASK = counters; } @@ -984,6 +1072,7 @@ __STATIC_INLINE uint32_t Cy_MCWDT_GetInterruptStatusMasked(MCWDT_STRUCT_Type con return (base->MCWDT_INTR_MASKED); } + /** \} group_mcwdt_functions */ #if defined(__cplusplus) diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.c similarity index 87% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.c index 7230e531cf..49f23d86b7 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_pdm_pcm.c -* \version 2.0 +* \version 2.10 * * The source code file for the PDM_PCM driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -14,7 +14,7 @@ #include "cy_pdm_pcm.h" -/* C binding of definitions if building with C++ compiler */ +/* The C binding of definitions if building with the C++ compiler */ #ifdef __cplusplus extern "C" { @@ -29,16 +29,16 @@ extern "C" * Function Name: Cy_PDM_PCM_Init ***************************************************************************//** * -* Initialize PDM-PCM module +* Initialize the PDM-PCM module * * \pre If the PDM-PCM module is initialized previously, the * \ref Cy_PDM_PCM_DeInit() must be called before calling this function. * -* \param base Pointer to PDM-PCM instance address -* \param config Pointer to configuration structure +* \param base The pointer to the PDM-PCM instance address +* \param config The pointer to a configuration structure. * \return error / status code. See \ref cy_en_pdm_pcm_status_t. * -* Example of the configuration structure: +* An example of a configuration structure: * \snippet PDM_PCM_PDL_sut_00.cydsn/main_cm4.c PDM_PCM Configuration * *******************************************************************************/ @@ -64,15 +64,15 @@ cy_en_pdm_pcm_status_t Cy_PDM_PCM_Init(PDM_Type * base, cy_stc_pdm_pcm_config_t ret = CY_PDM_PCM_SUCCESS; - base->CTL &= (uint32_t) ~PDM_CTL_ENABLED_Msk; /* Disable PDM_PCM block */ + base->CTL &= (uint32_t) ~PDM_CTL_ENABLED_Msk; /* Disable the PDM_PCM block */ - /* Clock setting */ + /* The clock setting */ base->CLOCK_CTL = _VAL2FLD(PDM_CLOCK_CTL_CLK_CLOCK_DIV, config->clkDiv) | _VAL2FLD(PDM_CLOCK_CTL_MCLKQ_CLOCK_DIV, config->mclkDiv) | _VAL2FLD(PDM_CLOCK_CTL_CKO_CLOCK_DIV, config->ckoDiv) | _VAL2FLD(PDM_CLOCK_CTL_SINC_RATE, config->sincDecRate); - /* Enable PDM-PCM block */ + /* Enable the PDM-PCM block */ base->CTL = _VAL2FLD(PDM_CTL_PGA_R, config->gainRight) | _VAL2FLD(PDM_CTL_PGA_L, config->gainLeft) | _VAL2FLD(PDM_CTL_STEP_SEL, config->softMuteFineGain) | @@ -117,21 +117,21 @@ void Cy_PDM_PCM_DeInit(PDM_Type * base) base->TR_CTL = 0UL; base->DATA_CTL = 0UL; base->MODE_CTL = CY_PDM_PCM_MODE_CTL_DEFAULT; - base->CTL = CY_PDM_PCM_CTL_DEFAULT; /* Disable PDM_PCM IP block */ - base->CLOCK_CTL = CY_PDM_PCM_CLOCK_CTL_DEFAULT; /* Default clock settings */ + base->CTL = CY_PDM_PCM_CTL_DEFAULT; /* Disable the PDM_PCM IP block */ + base->CLOCK_CTL = CY_PDM_PCM_CLOCK_CTL_DEFAULT; /* The default clock settings */ } /****************************************************************************** * Function Name: Cy_PDM_PCM_SetGain ***************************************************************************//** * -* Sets the gain factor to left or right channel. +* Sets the gain factor to the left or right channel. * * \param base -* Pointer to PDM-PCM instance address +* The pointer to the PDM-PCM instance address. * * \param chan -* Channel selector for gain setting \ref cy_en_pdm_pcm_chan_select_t. +* The channel selector for gain setting \ref cy_en_pdm_pcm_chan_select_t. * * \param gain * Gain for the selected channel \ref cy_en_pdm_pcm_gain_t. @@ -156,13 +156,13 @@ void Cy_PDM_PCM_SetGain(PDM_Type * base, cy_en_pdm_pcm_chan_select_t chan, cy_en * Function Name: Cy_PDM_PCM_GetGain ***************************************************************************//** * -* Retrieve the current gain factor of left or right channel. +* Retrieves the current gain factor of the left or right channel. * * \param base -* Pointer to PDM-PCM instance address +* the pointer to the PDM-PCM instance address. * * \param chan -* Channel selector for gain setting \ref cy_en_pdm_pcm_chan_select_t. +* The channel selector for gain setting \ref cy_en_pdm_pcm_chan_select_t. * * \return * Gain of the selected channel \ref cy_en_pdm_pcm_gain_t. @@ -191,11 +191,11 @@ cy_en_pdm_pcm_gain_t Cy_PDM_PCM_GetGain(PDM_Type const * base, cy_en_pdm_pcm_cha * Function Name: Cy_PDM_PCM_DeepSleepCallback ****************************************************************************//** * -* This is an example callback function that can be used the application layer to -* manage PDM-PCM operation before entering and after exiting Deep-Sleep mode. +* This is an example callback function that can be used at the application layer to +* manage the PDM-PCM operation before entering and after exiting Deep-Sleep mode. * * \param callbackParams -* structure with the syspm callback parameters, +* The structure with the syspm callback parameters, * see \ref cy_stc_syspm_callback_params_t. * * \return diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.h similarity index 86% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.h index e3d2e075dc..a527c7e4c1 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/pdm_pcm/cy_pdm_pcm.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_pdm_pcm.h -* \version 2.0 +* \version 2.10 * * The header file of the PDM_PCM driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -33,7 +33,7 @@ * to the analog signal's amplitude. The output of a 1-bit DAC is the same * as the PDM encoding of the signal. * -* Pulse-code modulation (PCM) is a method used to digitally represent sampled analog signals. +* Pulse-code modulation (PCM) is the method used to digitally represent sampled analog signals. * It is the standard form of digital audio in computers, compact discs, digital telephony, * and other digital audio applications. In a PCM stream, the amplitude of the analog signal * is sampled regularly at uniform intervals, and each sample is quantized @@ -53,19 +53,20 @@ * To initialize the PDM-PCM block, call the \ref Cy_PDM_PCM_Init function, providing the * filled \ref cy_stc_pdm_pcm_config_t structure. * -* If you use DMA, the DMA channel should be previously configured. PDM-PCM interrupts +* If you use a DMA, the DMA channel should be previously configured. PDM-PCM interrupts * (if applicable) can be enabled by calling \ref Cy_PDM_PCM_SetInterruptMask. * * For example, if the trigger interrupt is used during operation, the ISR * should call the \ref Cy_PDM_PCM_ReadFifo as many times as required for your * FIFO payload. Then call \ref Cy_PDM_PCM_ClearInterrupt with appropriate parameters. * -* If DMA is used and a DMA channel is properly configured, no CPU activity +* If a DMA is used and the DMA channel is properly configured, no CPU activity * (or application code) is needed for PDM-PCM operation. * * \section group_pdm_pcm_more_information More Information -* See the PDM_PCM_PDL Component datasheet. -* Also, see the PDM-PCM chapter of the device technical reference manual (TRM). +* See: the PDM-PCM chapter of the device technical reference manual (TRM); +* the PDM_PCM_PDL Component datasheet; +* CE219431 - PSOC 6 MCU PDM-TO-PCM EXAMPLE. * * \section group_pdm_pcm_MISRA MISRA-C Compliance * The PDM-PCM driver has the following specific deviations: @@ -79,20 +80,20 @@ * * * -* * +* that describes this bitfield. So the code is safe by design. * * * * -* +* * +* function becomes the user responsibility because the pointer is +* initialized when a callback is registered in SysPm driver. * *
VersionChangesReason for Change
1.10.1Updated description of the \ref cy_stc_mcwdt_config_t structure typeDocumentation update and clarification
1.10Added input parameter validation to the API functions.
+* Added API function GetCountCascaded()
1.0Initial version
10.3RA composite expression of 'essentially unsigned' type is being +* A composite expression of the "essentially unsigned" type is * cast to a different type category.The value got from the bitfield physically can't exceed the enumeration -* that describes this bitfield. So the code is safety by design.
11.4AA cast should not be performed between a pointer to object type and -* a different pointer to object type.A cast should not be performed between a pointer to the object type and +* a different pointer to the object type.The function \ref Cy_I2S_DeepSleepCallback is a callback of * \ref cy_en_syspm_status_t type. The cast operation safety in this -* function becomes the user responsibility because pointer are -* initialized when callback is registered in SysPm driver.
* @@ -100,20 +101,56 @@ * * * -* -* -* +* +* +* * * * -* +* +* +* +* +* +* * * *
VersionChangesReason for Change
1.0Initial version2.10The gain values in range +4.5...+10.5dB (5 items) of /ref cy_en_pdm_pcm_gain_t are corrected. +* Added Low Power Callback section.Incorrect setting of gain values in limited range. +* Documentation update and clarification.
2.0User-friendliness enhancementEnumeration types for gain and soft mute cycles are added.
+* Function parameter checks are added.
+* The next functions are removed: +* * Cy_PDM_PCM_EnterLowPowerCallback +* * Cy_PDM_PCM_ExitLowPowerCallback +* * Cy_PDM_PCM_EnableDataStream +* * Cy_PDM_PCM_DisableDataStream +* * Cy_PDM_PCM_SetFifoLevel +* * Cy_PDM_PCM_GetFifoLevel +* * Cy_PDM_PCM_EnableDmaRequest +* * Cy_PDM_PCM_DisableDmaRequest +* +* The next functions behaviour are modified: +* * Cy_PDM_PCM_Enable +* * Cy_PDM_PCM_Disable +* * Cy_PDM_PCM_SetInterruptMask +* * Cy_PDM_PCM_GetInterruptMask +* * Cy_PDM_PCM_GetInterruptStatusMasked +* * Cy_PDM_PCM_GetInterruptStatus +* * Cy_PDM_PCM_ClearInterrupt +* * Cy_PDM_PCM_SetInterrupt +* +* The Cy_PDM_PCM_GetFifoNumWords function is renamed to Cy_PDM_PCM_GetNumInFifo.
+* The Cy_PDM_PCM_GetCurrentState function is added. +*
Improvements based on usability feedbacks.
+* API is reworked for consistency within the PDL. +*
1.0Initial version
* * \defgroup group_pdm_pcm_macros Macros * \defgroup group_pdm_pcm_functions Functions -* \defgroup group_pdm_pcm_data_structures Data structures +* \{ +* \defgroup group_pdm_pcm_functions_syspm_callback Low Power Callback +* \} +* \defgroup group_pdm_pcm_data_structures Data Structures * \defgroup group_pdm_pcm_enums Enumerated Types * */ @@ -135,7 +172,7 @@ #error "The PDM-PCM driver is not supported on this device" #endif -/* C binding of definitions if building with C++ compiler */ +/* The C binding of definitions if building with the C++ compiler */ #ifdef __cplusplus extern "C" { @@ -151,13 +188,13 @@ extern "C" * \{ */ -/** Driver major version */ +/** The driver major version */ #define CY_PDM_PCM_DRV_VERSION_MAJOR 2 -/** Driver minor version */ -#define CY_PDM_PCM_DRV_VERSION_MINOR 0 +/** The driver minor version */ +#define CY_PDM_PCM_DRV_VERSION_MINOR 10 -/** PDM-PCM driver identifier */ +/** The PDM-PCM driver identifier */ #define CY_PDM_PCM_ID CY_PDL_DRV_ID(0x26u) /** @@ -230,11 +267,11 @@ typedef enum CY_PDM_PCM_BYPASS = 8U, /**< 0 dB (bypass). */ CY_PDM_PCM_GAIN_1_5_DB = 9U, /**< +1.5 dB (amplification). */ CY_PDM_PCM_GAIN_3_DB = 10U, /**< +3 dB (amplification). */ - CY_PDM_PCM_GAIN_4_5_DB = 12U, /**< +4.5 dB (amplification). */ - CY_PDM_PCM_GAIN_6_DB = 13U, /**< +6 dB (amplification). */ - CY_PDM_PCM_GAIN_7_5_DB = 14U, /**< +7.5 dB (amplification). */ - CY_PDM_PCM_GAIN_9_DB = 15U, /**< +9 dB (amplification). */ - CY_PDM_PCM_GAIN_10_5_DB = 16U /**< +10.5 dB (amplification). */ + CY_PDM_PCM_GAIN_4_5_DB = 11U, /**< +4.5 dB (amplification). */ + CY_PDM_PCM_GAIN_6_DB = 12U, /**< +6 dB (amplification). */ + CY_PDM_PCM_GAIN_7_5_DB = 13U, /**< +7.5 dB (amplification). */ + CY_PDM_PCM_GAIN_9_DB = 14U, /**< +9 dB (amplification). */ + CY_PDM_PCM_GAIN_10_5_DB = 15U /**< +10.5 dB (amplification). */ } cy_en_pdm_pcm_gain_t; @@ -417,7 +454,12 @@ cy_en_pdm_pcm_status_t Cy_PDM_PCM_Init(PDM_Type * base, cy_stc_pdm_pcm_config_ void Cy_PDM_PCM_SetGain(PDM_Type * base, cy_en_pdm_pcm_chan_select_t chan, cy_en_pdm_pcm_gain_t gain); cy_en_pdm_pcm_gain_t Cy_PDM_PCM_GetGain(PDM_Type const * base, cy_en_pdm_pcm_chan_select_t chan); +/** \addtogroup group_pdm_pcm_functions_syspm_callback +* The driver supports SysPm callback for Deep Sleep transition. +* \{ +*/ cy_en_syspm_status_t Cy_PDM_PCM_DeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams); +/** \} */ __STATIC_INLINE void Cy_PDM_PCM_Enable(PDM_Type * base); __STATIC_INLINE void Cy_PDM_PCM_Disable(PDM_Type * base); @@ -450,7 +492,7 @@ __STATIC_INLINE uint32_t Cy_PDM_PCM_ReadFifoSilent(PDM_Type const * base); * * Enables the PDM-PCM data conversion. * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_Enable(PDM_Type * base) @@ -464,7 +506,7 @@ __STATIC_INLINE void Cy_PDM_PCM_Enable(PDM_Type * base) * * Disables the PDM-PCM data conversion. * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_Disable(PDM_Type * base) @@ -479,7 +521,7 @@ __STATIC_INLINE void Cy_PDM_PCM_Disable(PDM_Type * base) * * Returns the current PDM-PCM state (running/stopped). * -* \param base Pointer to PDM-PCM instance address. +* \param base The pointer to the PDM-PCM instance address. * \return The current state (CMD register). * ******************************************************************************/ @@ -495,7 +537,7 @@ __STATIC_INLINE uint32_t Cy_PDM_PCM_GetCurrentState(PDM_Type const * base) * * Sets one or more PDM-PCM interrupt factor bits (sets the INTR_MASK register). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address * \param interrupt Interrupt bit mask \ref group_pdm_pcm_macros_intrerrupt_masks. * ******************************************************************************/ @@ -512,7 +554,7 @@ __STATIC_INLINE void Cy_PDM_PCM_SetInterruptMask(PDM_Type * base, uint32_t inter * * Returns the PDM-PCM interrupt mask (a content of the INTR_MASK register). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * \return The interrupt bit mask \ref group_pdm_pcm_macros_intrerrupt_masks. * ******************************************************************************/ @@ -526,10 +568,10 @@ __STATIC_INLINE uint32_t Cy_PDM_PCM_GetInterruptMask(PDM_Type const * base) * Function Name: Cy_PDM_PCM_GetInterruptStatusMasked ***************************************************************************//** * -* Reports status of enabled (masked) PDM-PCM interrupt sources +* Reports the status of enabled (masked) PDM-PCM interrupt sources. * (an INTR_MASKED register). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * \return The interrupt bit mask \ref group_pdm_pcm_macros_intrerrupt_masks. * *****************************************************************************/ @@ -543,9 +585,9 @@ __STATIC_INLINE uint32_t Cy_PDM_PCM_GetInterruptStatusMasked(PDM_Type const * ba * Function Name: Cy_PDM_PCM_GetInterruptStatus ***************************************************************************//** * -* Reports status of PDM-PCM interrupt sources (an INTR register). +* Reports the status of PDM-PCM interrupt sources (an INTR register). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * \return The interrupt bit mask \ref group_pdm_pcm_macros_intrerrupt_masks. * ******************************************************************************/ @@ -559,9 +601,9 @@ __STATIC_INLINE uint32_t Cy_PDM_PCM_GetInterruptStatus(PDM_Type const * base) * Function Name: Cy_PDM_PCM_ClearInterrupt ***************************************************************************//** * -* Clears one or more PDM-PCM interrupt status (sets an INTR register's bits). +* Clears one or more PDM-PCM interrupt statuses (sets an INTR register's bits). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address * \param interrupt * The interrupt bit mask \ref group_pdm_pcm_macros_intrerrupt_masks. * @@ -578,9 +620,9 @@ __STATIC_INLINE void Cy_PDM_PCM_ClearInterrupt(PDM_Type * base, uint32_t interru * Function Name: Cy_PDM_PCM_SetInterrupt ***************************************************************************//** * -* Sets one or more interrupt source status (sets an INTR_SET register). +* Sets one or more interrupt source statuses (sets an INTR_SET register). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * \param interrupt * The interrupt bit mask \ref group_pdm_pcm_macros_intrerrupt_masks. * @@ -598,8 +640,8 @@ __STATIC_INLINE void Cy_PDM_PCM_SetInterrupt(PDM_Type * base, uint32_t interrupt * * Reports the current number of used words in the output data FIFO. * -* \param base Pointer to PDM-PCM instance address -* \return Current number of used FIFO words (range is 0 - 254) +* \param base The pointer to the PDM-PCM instance address. +* \return The current number of used FIFO words (range is 0 - 254). * ******************************************************************************/ __STATIC_INLINE uint8_t Cy_PDM_PCM_GetNumInFifo(PDM_Type const * base) @@ -614,7 +656,7 @@ __STATIC_INLINE uint8_t Cy_PDM_PCM_GetNumInFifo(PDM_Type const * base) * * Resets the output data FIFO, removing all data words from the FIFO. * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_ClearFifo(PDM_Type * base) @@ -630,8 +672,8 @@ __STATIC_INLINE void Cy_PDM_PCM_ClearFifo(PDM_Type * base) * * Reads ("pops") one word from the output data FIFO. * -* \param base Pointer to PDM-PCM instance address. -* \return Data word. +* \param base The pointer to the PDM-PCM instance address. +* \return The data word. * ******************************************************************************/ __STATIC_INLINE uint32_t Cy_PDM_PCM_ReadFifo(PDM_Type const * base) @@ -644,9 +686,9 @@ __STATIC_INLINE uint32_t Cy_PDM_PCM_ReadFifo(PDM_Type const * base) * Function Name: Cy_PDM_PCM_EnableSoftMute ***************************************************************************//** * -* Enables soft mute +* Enables soft mute. * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_EnableSoftMute(PDM_Type * base) @@ -659,9 +701,9 @@ __STATIC_INLINE void Cy_PDM_PCM_EnableSoftMute(PDM_Type * base) * Function Name: Cy_PDM_PCM_DisableSoftMute ***************************************************************************//** * -* Disables soft mute +* Disables soft mute. * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_DisableSoftMute(PDM_Type * base) @@ -674,9 +716,9 @@ __STATIC_INLINE void Cy_PDM_PCM_DisableSoftMute(PDM_Type * base) * Function Name: Cy_PDM_PCM_FreezeFifo ***************************************************************************//** * -* Freezes RX FIFO (Debug purpose) +* Freezes the RX FIFO (Debug purpose). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_FreezeFifo(PDM_Type * base) @@ -689,9 +731,9 @@ __STATIC_INLINE void Cy_PDM_PCM_FreezeFifo(PDM_Type * base) * Function Name: Cy_PDM_PCM_UnfreezeFifo ***************************************************************************//** * -* Unfreezes RX FIFO (Debug purpose) +* Unfreezes the RX FIFO (Debug purpose). * -* \param base Pointer to PDM-PCM instance address +* \param base The pointer to the PDM-PCM instance address. * ******************************************************************************/ __STATIC_INLINE void Cy_PDM_PCM_UnfreezeFifo(PDM_Type * base) @@ -704,7 +746,7 @@ __STATIC_INLINE void Cy_PDM_PCM_UnfreezeFifo(PDM_Type * base) * Function Name: Cy_PDM_PCM_ReadFifoSilent ***************************************************************************//** * -* Reads RX FIFO silent (without touching the FIFO function) +* Reads the RX FIFO silent (without touching the FIFO function). * * \param base Pointer to PDM-PCM instance address. * \return FIFO value. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/profile/cy_profile.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/profile/cy_profile.c similarity index 75% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/profile/cy_profile.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/profile/cy_profile.c index 7a370872a1..92167f965d 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/profile/cy_profile.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/profile/cy_profile.c @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -19,17 +19,17 @@ extern "C" { #endif /* __cplusplus */ -/* # of elements in an array */ +/* Number of elements in an array */ #define CY_N_ELMTS(a) (sizeof(a)/sizeof((a)[0])) static cy_en_profile_status_t Cy_Profile_IsPtrValid(const cy_stc_profile_ctr_ptr_t ctrAddr); -/* control and status information for each counter */ +/* Internal structure - Control and status information for each counter */ static cy_stc_profile_ctr_t cy_ep_ctrs[PROFILE_PRFL_CNT_NR]; /* ========================================================================== */ -/* ===================== LOCAL FUNCTIONS SECTION ====================== */ +/* ===================== LOCAL FUNCTION SECTION ====================== */ /* ========================================================================== */ /******************************************************************************* * Function Name: Cy_Profile_IsPtrValid @@ -104,15 +104,22 @@ void Cy_Profile_ISR(void) /* ========================================================================== */ -/* ================== GENERAL EP FUNCTIONS SECTION ==================== */ +/* ================== GENERAL PROFILE FUNCTIONS ==================== */ /* ========================================================================== */ /******************************************************************************* * Function Name: Cy_Profile_StartProfiling ****************************************************************************//** * -* Starts profiling. +* Starts the profiling/measurement window. +* +* This operation allows the enabled profile counters to start counting. +* +* \note The profile interrupt should be enabled before calling this function +* in order for the firmware to be notified when a counter overflow occurs. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_StartProfiling * -* \note Before calling this function, the user must enable the profiler interrupt. *******************************************************************************/ void Cy_Profile_StartProfiling(void) { @@ -132,8 +139,11 @@ void Cy_Profile_StartProfiling(void) * Function Name: Cy_Profile_ClearConfiguration ****************************************************************************//** * -* Clears all counter configuration and sets all counters and overflow counters to 0. -* Calls Cy_Profile_ClearCounters() to clear counter registers. +* Clears all counter configurations and sets all counters and overflow counters +* to 0. Calls Cy_Profile_ClearCounters() to clear counter registers. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_ClearConfiguration * *******************************************************************************/ void Cy_Profile_ClearConfiguration(void) @@ -142,32 +152,33 @@ void Cy_Profile_ClearConfiguration(void) Cy_Profile_ClearCounters(); } + /******************************************************************************* * Function Name: Cy_Profile_ConfigureCounter ****************************************************************************//** * -* Assigns a given monitor source to a counter, and loads the CTL register -* bitfields of an assigned counter. +* Configures and assigns a hardware profile counter to the list of used counters. * -* The available monitor sources vary per device series. Refer to the series-specific -* configuration header file for the list of available monitor sources. +* This function assigns an available profile counter to a slot in the internal +* software data structure and returns the handle for that slot location. The data +* structure is used to keep track of the counter status and to implement a 64-bit +* profile counter. If no counter slots are available, the function returns a +* NULL pointer. * -* \param monitor The monitor source # +* \param monitor The monitor source number * * \param duration Events are monitored (0), or duration is monitored (1) * -* \param refClk The reference clock to use; see \ref cy_en_profile_ref_clk_t. -* In general, it is recommended to use CY_PROFILE_CLK_HF to maximize resolution. +* \param refClk Counter reference clock * * \param weight Weighting factor for the counter value * * \return A pointer to the counter data structure. NULL if no counter is * available. * -* \note The counter is not enabled by this function. See functions -* \ref Cy_Profile_EnableCounter() and \ref Cy_Profile_DisableCounter(). See the -* Technical Reference Manual (TRM) chapter on the EP for reference clock considerations. -* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_ConfigureCounter +* *******************************************************************************/ cy_stc_profile_ctr_ptr_t Cy_Profile_ConfigureCounter(en_ep_mon_sel_t monitor, cy_en_profile_duration_t duration, cy_en_profile_ref_clk_t refClk, uint32_t weight) @@ -199,21 +210,27 @@ cy_stc_profile_ctr_ptr_t Cy_Profile_ConfigureCounter(en_ep_mon_sel_t monitor, cy return (retVal); } + /******************************************************************************* * Function Name: Cy_Profile_FreeCounter ****************************************************************************//** * * Frees up a counter from a previously-assigned monitor source. -* \ref Cy_Profile_ConfigureCounter() must have been called for this counter before -* calling this function. * -* \param ctrAddr The handle to (address of) the assigned counter, which is -* obtained by a call to \ref Cy_Profile_ConfigureCounter(). +* \ref Cy_Profile_ConfigureCounter() must have been called for this counter +* before calling this function. +* +* \param ctrAddr The handle to the assigned counter (returned by calling +* \ref Cy_Profile_ConfigureCounter()). * -* \return \ref CY_PROFILE_SUCCESS, or \ref CY_PROFILE_BAD_PARAM for counter not in use. +* \return +* Status of the operation. +* +* \note The counter is not disabled by this function. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_FreeCounter * -* \note The counter is not disabled by this function. See functions -* \ref Cy_Profile_EnableCounter() and \ref Cy_Profile_DisableCounter(). *******************************************************************************/ cy_en_profile_status_t Cy_Profile_FreeCounter(cy_stc_profile_ctr_ptr_t ctrAddr) { @@ -227,17 +244,24 @@ cy_en_profile_status_t Cy_Profile_FreeCounter(cy_stc_profile_ctr_ptr_t ctrAddr) return (retStatus); } + /******************************************************************************* * Function Name: Cy_Profile_EnableCounter ****************************************************************************//** * -* Enables an assigned counter. \ref Cy_Profile_ConfigureCounter() must have been -* called for this counter before calling this function. +* Enables an assigned counter. * -* \param ctrAddr The handle to (address of) the assigned counter, which is -* obtained by a call to \ref Cy_Profile_ConfigureCounter(). +* \ref Cy_Profile_ConfigureCounter() must have been called for this counter +* before calling this function. +* +* \param ctrAddr The handle to the assigned counter, (returned by calling +* \ref Cy_Profile_ConfigureCounter()). * -* \return \ref CY_PROFILE_SUCCESS, or \ref CY_PROFILE_BAD_PARAM for counter not in use. +* \return +* Status of the operation. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_EnableCounter * *******************************************************************************/ cy_en_profile_status_t Cy_Profile_EnableCounter(cy_stc_profile_ctr_ptr_t ctrAddr) @@ -255,17 +279,24 @@ cy_en_profile_status_t Cy_Profile_EnableCounter(cy_stc_profile_ctr_ptr_t ctrAddr return (retStatus); } + /******************************************************************************* * Function Name: Cy_Profile_DisableCounter ****************************************************************************//** * -* Disables an assigned counter. \ref Cy_Profile_ConfigureCounter() must have been -* called for this counter before calling this function. +* Disables an assigned counter. * -* \param ctrAddr The handle to (address of) the assigned counter, which is -* obtained by a call to \ref Cy_Profile_ConfigureCounter(). +* \ref Cy_Profile_ConfigureCounter() must have been called for this counter +* before calling this function. +* +* \param ctrAddr The handle to the assigned counter, (returned by calling +* \ref Cy_Profile_ConfigureCounter()). * -* \return \ref CY_PROFILE_SUCCESS, or \ref CY_PROFILE_BAD_PARAM for counter not in use. +* \return +* Status of the operation. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_DisableCounter * *******************************************************************************/ cy_en_profile_status_t Cy_Profile_DisableCounter(cy_stc_profile_ctr_ptr_t ctrAddr) @@ -289,14 +320,18 @@ cy_en_profile_status_t Cy_Profile_DisableCounter(cy_stc_profile_ctr_ptr_t ctrAdd * Function Name: Cy_Profile_GetRawCount ****************************************************************************//** * -* Reports the count value for a specified counter. +* Reports the raw count value for a specified counter. * -* \param ctrAddr the handle to (address of) the assigned counter, which is -* obtained by a call to \ref Cy_Profile_ConfigureCounter(). +* \param ctrAddr The handle to the assigned counter, (returned by calling +* \ref Cy_Profile_ConfigureCounter()). * -* \param result The address to which to write the result. +* \param result Output parameter used to write in the result. * -* \return \ref CY_PROFILE_SUCCESS, or \ref CY_PROFILE_BAD_PARAM for counter not in use. +* \return +* Status of the operation. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_GetRawCount * *******************************************************************************/ cy_en_profile_status_t Cy_Profile_GetRawCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result) @@ -319,14 +354,18 @@ cy_en_profile_status_t Cy_Profile_GetRawCount(cy_stc_profile_ctr_ptr_t ctrAddr, ****************************************************************************//** * * Reports the count value for a specified counter, multiplied by the weight -* factor set in \ref Cy_Profile_ConfigureCounter() for that counter. +* factor for that counter. * -* \param ctrAddr the handle to (address of) the assigned counter, which is -* obtained by a call to \ref Cy_Profile_ConfigureCounter(). +* \param ctrAddr The handle to the assigned counter, (returned by calling +* \ref Cy_Profile_ConfigureCounter()). * -* \param result The address to which to write the result. +* \param result Output parameter used to write in the result. * -* \return \ref CY_PROFILE_SUCCESS, or \ref CY_PROFILE_BAD_PARAM for counter not in use. +* \return +* Status of the operation. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_GetWeightedCount * *******************************************************************************/ cy_en_profile_status_t Cy_Profile_GetWeightedCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result) @@ -345,14 +384,21 @@ cy_en_profile_status_t Cy_Profile_GetWeightedCount(cy_stc_profile_ctr_ptr_t ctrA * Function Name: Cy_Profile_GetSumWeightedCounts ****************************************************************************//** * -* Calls \ref Cy_Profile_GetWeightedCount() for all specified counters. Reports the sum -* across all valid counters. +* Reports the weighted sum result of the first n number of counter count values +* starting from the specified profile counter data structure base address. * -* \param ptrsArray Array of handles to (addresses of) assigned counters +* Each count value is multiplied by its weighing factor before the summing +* operation is performed. * -* \param numCounters Number of scanned elements in ptrsArray[] +* \param ptrsArray Base address of the profile counter data structure * -* \return The sum +* \param numCounters Number of measured counters in ptrsArray[] +* +* \return +* The weighted sum of the specified counters +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_GetSumWeightedCounts * *******************************************************************************/ uint64_t Cy_Profile_GetSumWeightedCounts(cy_stc_profile_ctr_ptr_t ptrsArray[], diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/profile/cy_profile.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/profile/cy_profile.h new file mode 100644 index 0000000000..19a85e0ada --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/profile/cy_profile.h @@ -0,0 +1,458 @@ +/***************************************************************************//** +* \file cy_profile.h +* \version 1.0 +* +* Provides an API declaration of the energy profiler driver. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +/** +* \defgroup group_energy_profiler Energy Profiler (Profile) +* \{ +* +* The energy profiler driver is an API for configuring and using the profile +* hardware block. The profile block enables measurement of the signal activity +* of select peripherals and monitor sources during a measurement window. Using +* these measurements, it is possible to construct a profile of the energy consumed +* in the device by scaling the individual peripheral actvities with appropriate +* scaling (weight) factors. This gives the application the ability to monitor +* the energy consumed by the internal resources with minimal CPU overhead and +* without external monitoring hardware. +* +* \section group_profile_details Details +* +* \subsection group_profile_hardware Profile Hardware +* +* The profile hardware consists of a number of profile counters that accept specific +* triggers for incrementing the count value. This allows the events of the source +* (such as the number of SCB0 bus accesses or the duration of time the BLE RX radio +* is active) to be counted during the measurement window. The available monitor +* sources in the device can be found in the en_ep_mon_sel_t enum in the device +* configuration file (e.g. psoc62_config.h). These can be sourced to any of the +* profile counters as triggers. There are two methods of using the monitor sources +* in a profile counter. +* +* - Event: The count value is incremented when a pulse event signal is seen by the +* counter. This type of monitoring is suitable when the monitoring source of +* interest needs to count the discrete events (such as the number of Flash read +* accesses) happening in the measurement window. +* +* - Duration: The count value is incremented at every clock edge while the monitor +* signal is high. This type of monitoring is suitable when a signal is active for +* a finite amount of time (such as the time the BLE TX radio is active) and the +* duration needs to be expressed as number of clock cycles in the measurement window. +* +* Many of the available monitor sources are suitable for event type monitoring. +* Using a duration type on these signals may not give valuable information. Review +* the device TRM for more information on the monitor sources and details on how they +* should be used. +* +* \subsection group_profile_measurement_types Measurement Types +* +* Depending on the item of interest, energy measurement can be performed by using +* the following methods. +* +* - Continuous measurement: A profile counter can be assigned a monitor signal of +* constant 1 (PROFILE_ONE), which sets the counter to increment at every (assigned) +* clock cycle. This can be used to give a reference time for the measurement window +* and also allows the construction of time stamps. For example, a software controlled +* GPIO can be "timestamped" by reading the counter value (on the fly) before it is +* toggled. When the measurement window ends, the energy contribution caused by the +* GPIO toggle can be incorporated into the final calculation. +* +* - Event measurement: Monitored events happening in a measurement window can be +* used to increment a profile counter. This gives the activity numbers, which can +* then be multiplied by the instantaneous power numbers associated with the source +* to give the average energy consumption (Energy = Power x time). For example, the +* energy consumped by an Operating System (OS) task can be estimated by monitoring +* the processor's active cycle count (E.g. CPUSS_MONITOR_CM4) and the Flash read +* accesses (CPUSS_MONITOR_FLASH). Note that these activity numbers can also be +* timestamped using the continuous measurement method to differentiate between the +* different task switches. The activity numbers are then multiplied by the associated +* processor and flash access power numbers to give the average energy consumed by +* that task. +* +* - Duration measurement: A peripheral event such as the SMIF select signal can be +* used by a profile counter to measure the time spent on XIP communication through the +* SPI interface. This activity number can then be multiplied by the power associated +* with that activity to give the average energy consumed by that block during the +* measurement window. This type of monitoring should only be performed for signals +* that are difficult to track in software. For example, a combination of interrupts +* and time stamps can be used to track the activity of many peripherals in a continuous +* monitoring model. However tracking the activity of signals such the BLE radio +* should be done using the duration measurement method. +* +* - Low power measurement: The profile counters do not support measurement during chip +* deep-sleep, hibernate and off states. i.e. the profile counters are meant for active +* run-time measurements only. In order to measure the time spent in low power modes (LPM), +* a real-time clock (RTC) should be used. Take a timestamp before LPM entry and a +* timestamp upon LPM exit in a continuous measurement model. Then multiply the difference +* by the appropriate LPM power numbers. +* +* \subsection group_profile_usage Driver Usage +* +* At the highest level, the energy profiler must perform the following steps to +* obtain a measurement: +* +* 1. Initialize the profile hardware block. +* 2. Initialize the profile interrupt (profile_interrupt_IRQn). +* 3. Configure, initialize, and enable the profile counters. +* 4. Enable the profile interrupt and start the profiling/measurement window. +* 5. Perform run-time reads of the counters (if needed). +* 6. Disable the profile interrupt and stop the profiling/measurement window. +* 7. Read the counters and gather the results. +* 8. Calculate the energy consumption. +* +* Refer to the SysInt driver on the details of configuring the profile hardware interrupt. +* +* The profile interrupt triggers when a counter overflow event is detected on any of the +* enabled profile counters. A sample interrupt service routine Cy_Profile_ISR() is provided, +* which can be used to update the internal counter states stored in RAM. Refer to the +* Configuration Considerations for more information. +* +* \section group_profile_configuration Configuration Considerations +* +* Each counter is a 32-bit register that counts either a number of clock cycles, +* or a number of events. It is possible to overflow the 32-bit register. To address +* this issue, the driver implements a 32-bit overflow counter. Combined with the 32-bit +* register, this gives a 64-bit counter for each monitored source. +* +* When an overflow occurs, the profile hardware generates an interrupt. The interrupt is +* configured using the SysInt driver, where the sample interrupt handler Cy_Profile_ISR() +* can be used as the ISR. The ISR increments the overflow counter for each profiling counter +* and clears the interrupt. +* +* \section group_profile_more_information More Information +* +* See the profiler chapter of the device technical reference manual (TRM). +* +* \section group_profile_MISRA MISRA-C Compliance +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
12.4RRight hand operand of '&&' or '||' is an expression with possible side effects.Function-like macros are used to achieve more efficient code.
16.7AA pointer parameter can be of type 'pointer to const'.The pointer is cast for comparison purposes and thus can't be a const.
+* +* \section group_profile_changelog Changelog +* +* +* +* +* +* +* +*
VersionChangesReason for Change
1.0Initial version
+* +* \defgroup group_profile_macros Macros +* \defgroup group_profile_functions Functions +* \{ +* \defgroup group_profile_functions_interrupt Interrupt Functions +* \defgroup group_profile_functions_general General Functions +* \defgroup group_profile_functions_counter Counter Functions +* \defgroup group_profile_functions_calculation Calculation Functions +* \} +* \defgroup group_profile_data_structures Data Structures +* \defgroup group_profile_enums Enumerated Types +*/ + +#if !defined(CY_PROFILE_H) +#define CY_PROFILE_H + +#include "cy_device_headers.h" +#include "syslib/cy_syslib.h" +#include + +#ifndef CY_IP_MXPROFILE + #error "The PROFILE driver is not supported on this device" +#endif + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +/** \addtogroup group_profile_macros +* \{ +*/ + +/** Driver major version */ +#define CY_PROFILE_DRV_VERSION_MAJOR 1 + +/** Driver minor version */ +#define CY_PROFILE_DRV_VERSION_MINOR 0 + +/** Profile driver identifier */ +#define CY_PROFILE_ID CY_PDL_DRV_ID(0x1EU) + +/** Start profiling command for the CMD register */ +#define CY_PROFILE_START_TR 1UL + +/** Stop profiling command for the CMD register */ +#define CY_PROFILE_STOP_TR 2UL + +/** Command to clear all counter registers to 0 */ +#define CY_PROFILE_CLR_ALL_CNT 0x100UL + +/** \} group_profile_macros */ + +/** +* \addtogroup group_profile_enums +* \{ +*/ + +/** +* Profile counter reference clock source. Used when duration monitoring. +*/ +typedef enum +{ + CY_PROFILE_CLK_TIMER = 0, /**< Timer clock (TimerClk) */ + CY_PROFILE_CLK_IMO = 1, /**< Internal main oscillator (IMO) */ + CY_PROFILE_CLK_ECO = 2, /**< External crystal oscillator (ECO) */ + CY_PROFILE_CLK_LF = 3, /**< Low-frequency clock (LFCLK) */ + CY_PROFILE_CLK_HF = 4, /**< High-Frequency clock (HFCLK0) */ + CY_PROFILE_CLK_PERI = 5, /**< Peripheral clock (PeriClk) */ +} cy_en_profile_ref_clk_t; + +/** +* Monitor method type. +*/ +typedef enum +{ + CY_PROFILE_EVENT = 0, /**< Count (edge-detected) module events */ + CY_PROFILE_DURATION = 1, /**< Count (level) duration in clock cycles */ +} cy_en_profile_duration_t; + +/** Profiler status codes */ +typedef enum +{ + CY_PROFILE_SUCCESS = 0x00U, /**< Operation completed successfully */ + CY_PROFILE_BAD_PARAM = CY_PROFILE_ID | CY_PDL_STATUS_ERROR | 1UL /**< Invalid input parameters */ + + } cy_en_profile_status_t; + + /** \} group_profile_enums */ + +/** +* \addtogroup group_profile_data_structures +* \{ +*/ + +/** +* Profile counter control register structure. For each counter, holds the CTL register fields. +*/ +typedef struct +{ + cy_en_profile_duration_t cntDuration; /**< 0 = event; 1 = duration */ + cy_en_profile_ref_clk_t refClkSel; /**< The reference clock used by the counter */ + en_ep_mon_sel_t monSel; /**< The monitor signal to be observed by the counter */ +} cy_stc_profile_ctr_ctl_t; + +/** +* Software structure for holding a profile counter status and configuration information. +*/ +typedef struct +{ + uint8_t ctrNum; /**< Profile counter number */ + uint8_t used; /**< 0 = available; 1 = used */ + cy_stc_profile_ctr_ctl_t ctlRegVals; /**< Initial counter CTL register settings */ + PROFILE_CNT_STRUCT_Type * cntAddr; /**< Base address of the counter instance registers */ + uint32_t ctlReg; /**< Current CTL register value */ + uint32_t cntReg; /**< Current CNT register value */ + uint32_t overflow; /**< Extension of cntReg to form a 64-bit counter value */ + uint32_t weight; /**< Weighting factor for the counter */ +} cy_stc_profile_ctr_t; + +/** +* Pointer to a structure holding the status information for a profile counter. +*/ +typedef cy_stc_profile_ctr_t * cy_stc_profile_ctr_ptr_t; +/** \} group_profile_data_structures */ + +/** +* \addtogroup group_profile_functions +* \{ +*/ + +/** +* \addtogroup group_profile_functions_interrupt +* \{ +*/ +/* ========================================================================== */ +/* ==================== INTERRUPT FUNCTION SECTION ==================== */ +/* ========================================================================== */ +void Cy_Profile_ISR(void); +/** \} group_profile_functions_interrupt */ + +/** +* \addtogroup group_profile_functions_general +* \{ +*/ +__STATIC_INLINE void Cy_Profile_Init(void); +__STATIC_INLINE void Cy_Profile_DeInit(void); +void Cy_Profile_StartProfiling(void); +__STATIC_INLINE void Cy_Profile_DeInit(void); +__STATIC_INLINE void Cy_Profile_StopProfiling(void); +__STATIC_INLINE uint32_t Cy_Profile_IsProfiling(void); + + +/* ========================================================================== */ +/* =============== GENERAL PROFILE FUNCTIONS SECTION ================= */ +/* ========================================================================== */ +/******************************************************************************* +* Function Name: Cy_Profile_Init +****************************************************************************//** +* +* Initializes and enables the profile hardware. +* +* This function must be called once when energy profiling is desired. The +* operation does not start a profiling session. +* +* \note The profile interrupt must also be configured. \ref Cy_Profile_ISR() +* can be used as its handler. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_Init +* +*******************************************************************************/ +__STATIC_INLINE void Cy_Profile_Init(void) +{ + PROFILE->CTL = _VAL2FLD(PROFILE_CTL_ENABLED, 1UL/*enabled */) | + _VAL2FLD(PROFILE_CTL_WIN_MODE, 0UL/*start/stop mode*/); + PROFILE->INTR_MASK = 0UL; /* clear all counter interrupt mask bits */ +} + + +/******************************************************************************* +* Function Name: Cy_Profile_DeInit +****************************************************************************//** +* +* Clears the interrupt mask and disables the profile hardware. +* +* This function should be called when energy profiling is no longer desired. +* +* \note The profile interrupt is not disabled by this operation and must be +* disabled separately. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_DeInit +* +*******************************************************************************/ +__STATIC_INLINE void Cy_Profile_DeInit(void) +{ + PROFILE->CTL = _VAL2FLD(PROFILE_CTL_ENABLED, 0UL/*disabled */); + PROFILE->INTR_MASK = 0UL; /* clear all counter interrupt mask bits */ +} + + +/******************************************************************************* +* Function Name: Cy_Profile_StopProfiling +****************************************************************************//** +* +* Stops the profiling/measurement window. +* +* This operation prevents the enabled profile counters from counting. +* +* \note The profile interrupt should be disabled before calling this function. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_StopProfiling +* +*******************************************************************************/ +__STATIC_INLINE void Cy_Profile_StopProfiling(void) +{ + PROFILE->CMD = CY_PROFILE_STOP_TR; +} + + +/******************************************************************************* +* Function Name: Cy_Profile_IsProfiling +****************************************************************************//** +* +* Reports the active status of the profiling window. +* +* \return 0 = profiling is not active; 1 = profiling is active +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_IsProfiling +* +*******************************************************************************/ +__STATIC_INLINE uint32_t Cy_Profile_IsProfiling(void) +{ + return _FLD2VAL(PROFILE_STATUS_WIN_ACTIVE, PROFILE->STATUS); +} +/** \} group_profile_functions_general */ + +/** +* \addtogroup group_profile_functions_counter +* \{ +*/ +void Cy_Profile_ClearConfiguration(void); +__STATIC_INLINE void Cy_Profile_ClearCounters(void); +cy_stc_profile_ctr_ptr_t Cy_Profile_ConfigureCounter(en_ep_mon_sel_t monitor, cy_en_profile_duration_t duration, cy_en_profile_ref_clk_t refClk, uint32_t weight); +cy_en_profile_status_t Cy_Profile_FreeCounter(cy_stc_profile_ctr_ptr_t ctrAddr); +cy_en_profile_status_t Cy_Profile_EnableCounter(cy_stc_profile_ctr_ptr_t ctrAddr); +cy_en_profile_status_t Cy_Profile_DisableCounter(cy_stc_profile_ctr_ptr_t ctrAddr); + +/* ========================================================================== */ +/* =================== COUNTER FUNCTIONS SECTION ====================== */ +/* ========================================================================== */ +/******************************************************************************* +* Function Name: Cy_Profile_ClearCounters +****************************************************************************//** +* +* Clears all hardware counters to 0. +* +* \funcusage +* \snippet profile/profile_v1_0_sut_01.cydsn/main_cm4.c snippet_Cy_Profile_ClearCounters +* +*******************************************************************************/ +__STATIC_INLINE void Cy_Profile_ClearCounters(void) +{ + PROFILE->CMD = CY_PROFILE_CLR_ALL_CNT; +} +/** \} group_profile_functions_counter */ + +/** +* \addtogroup group_profile_functions_calculation +* \{ +*/ +/* ========================================================================== */ +/* ================== CALCULATION FUNCTIONS SECTION =================== */ +/* ========================================================================== */ +cy_en_profile_status_t Cy_Profile_GetRawCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result); +cy_en_profile_status_t Cy_Profile_GetWeightedCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result); +uint64_t Cy_Profile_GetSumWeightedCounts(cy_stc_profile_ctr_ptr_t ptrsArray[], uint32_t numCounters); +/** \} group_profile_functions_calculation */ + +/** \} group_profile_functions */ + +#if defined(__cplusplus) +} +#endif /* __cplusplus */ + +#endif /* CY_PROFILE_H */ + +/** \} group_profile */ + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/prot/cy_prot.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/prot/cy_prot.c similarity index 84% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/prot/cy_prot.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/prot/cy_prot.c index f86eeb780d..42b74aa7f9 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/prot/cy_prot.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/prot/cy_prot.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_prot.c -* \version 1.0 +* \version 1.10 * * \brief * Provides an API implementation of the Protection Unit driver * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -28,7 +28,7 @@ extern "C" { * and privilege level of the bus transaction created by the specified master. * * \param busMaster -* Indicates which master needs to be configured. Refer to the CY_PROT_MASTER_X +* Indicates which master needs to be configured. Refer to the CPUSS_MS_ID_X * defines. * * \param privileged @@ -52,20 +52,60 @@ extern "C" { * CY_PROT_SUCCESS | The function completed successfully * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigBusMaster +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster, bool privileged, bool secure, uint32_t pcMask) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t regVal; - uint32_t * addrMsCtl = (uint32_t *)(PROT_BASE + (uint32_t)((uint32_t)busMaster << CY_PROT_MSX_CTL_SHIFT)); + uint32_t * addrMsCtl; - if((uint32_t)(pcMask & CY_PROT_MPU_PC_LIMIT_MASK) != 0UL) + CY_ASSERT_L1(CY_PROT_IS_BUS_MASTER_VALID(busMaster)); + + addrMsCtl = (uint32_t *)(PROT_BASE + (uint32_t)((uint32_t)busMaster << CY_PROT_MSX_CTL_SHIFT)); + + /* Check if PC mask is in supported range */ + switch (busMaster) { - /* PC mask out of range - not supported in device */ - status = CY_PROT_BAD_PARAM; + case (CPUSS_MS_ID_CM0): + { + status = ((uint32_t)(pcMask & CY_PROT_MS0_PC_LIMIT_MASK) != 0UL) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_CRYPTO): + { + status = ((uint32_t)(pcMask & CY_PROT_MS1_PC_LIMIT_MASK) != 0UL) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_DW0): + { + status = ((uint32_t)(pcMask & CY_PROT_MS2_PC_LIMIT_MASK) != 0UL) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_DW1): + { + status = ((uint32_t)(pcMask & CY_PROT_MS3_PC_LIMIT_MASK) != 0UL) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_CM4): + { + status = ((uint32_t)(pcMask & CY_PROT_MS14_PC_LIMIT_MASK) != 0UL) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_TC): + { + status = ((uint32_t)(pcMask & CY_PROT_MS15_PC_LIMIT_MASK) != 0UL) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + default: + status = CY_PROT_BAD_PARAM; + break; } - else + + if(status != CY_PROT_BAD_PARAM) { regVal = _VAL2FLD(PROT_SMPU_MS0_CTL_NS, !secure) | _VAL2FLD(PROT_SMPU_MS0_CTL_P, privileged) @@ -88,7 +128,7 @@ cy_en_prot_status_t Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster, bool pri * master, the value set through this function is used. * * \param busMaster -* The bus master to configure. Refer to the CY_PROT_MASTER_X defines. +* The bus master to configure. Refer to the CPUSS_MS_ID_X defines. * * \param pc * Active protection context of the specified master. Note that only those @@ -102,19 +142,59 @@ cy_en_prot_status_t Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster, bool pri * CY_PROT_SUCCESS | The function completed successfully * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_SetActivePC +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_SetActivePC(en_prot_master_t busMaster, uint32_t pc) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; - PROT_MPU_Type* addrMpu = (PROT_MPU_Type*)(&PROT->CYMPU[busMaster]); + cy_en_prot_status_t status; + PROT_MPU_Type* addrMpu; - if(pc >= (uint32_t)CY_PROT_MS_PC_NR_MAX) + CY_ASSERT_L1(CY_PROT_IS_BUS_MASTER_VALID(busMaster)); + + addrMpu = (PROT_MPU_Type*)(&PROT->CYMPU[busMaster]); + + /* Check if PC value is in supported range */ + switch (busMaster) { - /* Invalid PC value - not supported in device */ - status = CY_PROT_BAD_PARAM; + case (CPUSS_MS_ID_CM0): + { + status = (pc > CPUSS_PROT_SMPU_MS0_PC_NR_MINUS1) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_CRYPTO): + { + status = (pc > CPUSS_PROT_SMPU_MS1_PC_NR_MINUS1) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_DW0): + { + status = (pc > CPUSS_PROT_SMPU_MS2_PC_NR_MINUS1) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_DW1): + { + status = (pc > CPUSS_PROT_SMPU_MS3_PC_NR_MINUS1) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_CM4): + { + status = (pc > CPUSS_PROT_SMPU_MS14_PC_NR_MINUS1) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + case (CPUSS_MS_ID_TC): + { + status = (pc > CPUSS_PROT_SMPU_MS15_PC_NR_MINUS1) ? CY_PROT_BAD_PARAM : CY_PROT_SUCCESS; + break; + } + default: + status = CY_PROT_BAD_PARAM; + break; } - else + + if(status != CY_PROT_BAD_PARAM) { addrMpu->MS_CTL = _VAL2FLD(PROT_MPU_MS_CTL_PC, pc) | _VAL2FLD(PROT_MPU_MS_CTL_PC_SAVED, pc); status = (_FLD2VAL(PROT_MPU_MS_CTL_PC, addrMpu->MS_CTL) != pc) ? CY_PROT_FAILURE : CY_PROT_SUCCESS; @@ -132,15 +212,22 @@ cy_en_prot_status_t Cy_Prot_SetActivePC(en_prot_master_t busMaster, uint32_t pc) * * \param busMaster * The bus master, whose protection context is being read. Refer to the -* CY_PROT_MASTER_X defines. +* CPUSS_MS_ID_X defines. * * \return * Active protection context of the master -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_SetActivePC +* *******************************************************************************/ uint32_t Cy_Prot_GetActivePC(en_prot_master_t busMaster) { - PROT_MPU_Type* addrMpu = (PROT_MPU_Type*)(&PROT->CYMPU[busMaster]); + PROT_MPU_Type* addrMpu; + + CY_ASSERT_L1(CY_PROT_IS_BUS_MASTER_VALID(busMaster)); + + addrMpu = (PROT_MPU_Type*)(&PROT->CYMPU[busMaster]); return ((uint32_t)_FLD2VAL(PROT_MPU_MS_CTL_PC, addrMpu->MS_CTL)); } @@ -169,14 +256,22 @@ uint32_t Cy_Prot_GetActivePC(en_prot_master_t busMaster) * ------------ | ----------- * CY_PROT_SUCCESS | The MPU struct was configured * CY_PROT_FAILURE | Configuration failed due to a protection violation -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigMpuStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type* base, const cy_stc_mpu_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t addrReg; uint32_t attReg; - + + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_MPU_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_MPU_PERM_VALID(config->privPermission)); + CY_ASSERT_L3(CY_PROT_IS_REGION_SIZE_VALID(config->regionSize)); + addrReg = _VAL2FLD(PROT_MPU_MPU_STRUCT_ADDR_SUBREGION_DISABLE, config->subregions) | _VAL2FLD(PROT_MPU_MPU_STRUCT_ADDR_ADDR24, (uint32_t)((uint32_t)config->address >> CY_PROT_ADDR_SHIFT)); attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK) @@ -208,12 +303,15 @@ cy_en_prot_status_t Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type* base, cons * ------------ | ----------- * CY_PROT_SUCCESS | The MPU struct was enabled * CY_PROT_FAILURE | The MPU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnableMpuStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; - + cy_en_prot_status_t status; + base->ATT |= _VAL2FLD(PROT_MPU_MPU_STRUCT_ATT_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PROT_MPU_MPU_STRUCT_ATT_ENABLED, base->ATT) != CY_PROT_STRUCT_ENABLE) ? CY_PROT_FAILURE : CY_PROT_SUCCESS; @@ -239,11 +337,14 @@ cy_en_prot_status_t Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base) * ------------ | ----------- * CY_PROT_SUCCESS | The MPU struct was disabled * CY_PROT_FAILURE | The MPU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisableMpuStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT &= ~_VAL2FLD(PROT_MPU_MPU_STRUCT_ATT_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PROT_MPU_MPU_STRUCT_ATT_ENABLED, base->ATT) == CY_PROT_STRUCT_ENABLE) ? @@ -282,13 +383,20 @@ cy_en_prot_status_t Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base) * CY_PROT_SUCCESS | SMPU master struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigSmpuMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_SMPU_MS_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_SMPU_MS_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_SMPU_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -342,14 +450,22 @@ cy_en_prot_status_t Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* b * CY_PROT_SUCCESS | SMPU slave struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigSmpuSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t addrReg; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_SMPU_SL_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_SMPU_SL_PERM_VALID(config->privPermission)); + CY_ASSERT_L3(CY_PROT_IS_REGION_SIZE_VALID(config->regionSize)); + if(((uint32_t)config->pcMask & CY_PROT_SMPU_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -394,11 +510,14 @@ cy_en_prot_status_t Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* ba * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was enabled * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnableSmpuMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 |= _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, base->ATT1) != CY_PROT_STRUCT_ENABLE) ? @@ -427,11 +546,14 @@ cy_en_prot_status_t Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* b * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was disabled * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisableSmpuMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 &= ~_VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, base->ATT1) == CY_PROT_STRUCT_ENABLE) ? @@ -460,11 +582,14 @@ cy_en_prot_status_t Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was enabled * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnableSmpuSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 |= _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, base->ATT0) != CY_PROT_STRUCT_ENABLE) ? @@ -493,11 +618,14 @@ cy_en_prot_status_t Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* ba * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was disabled * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisableSmpuSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 &= ~_VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, base->ATT0) == CY_PROT_STRUCT_ENABLE) ? @@ -536,13 +664,20 @@ cy_en_prot_status_t Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* b * CY_PROT_SUCCESS | PPU PROG master struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuProgMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuProgMasterStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_PROG_MS_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_PROG_MS_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_PROG_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -600,14 +735,22 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuProgMasterStruct(PERI_PPU_PR_Type* base, co * CY_PROT_SUCCESS | PPU PROG slave struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuProgSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t addrReg; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_PROG_SL_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_PROG_SL_PERM_VALID(config->privPermission)); + CY_ASSERT_L3(CY_PROT_IS_REGION_SIZE_VALID(config->regionSize)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_PROG_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -660,11 +803,14 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveStruct(PERI_PPU_PR_Type* base, con * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was enabled * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuProgMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuProgMasterStruct(PERI_PPU_PR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 |= _VAL2FLD(PERI_PPU_PR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_PR_ATT1_ENABLED, base->ATT1) != CY_PROT_STRUCT_ENABLE) ? @@ -694,11 +840,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuProgMasterStruct(PERI_PPU_PR_Type* base) * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was disabled * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuProgMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuProgMasterStruct(PERI_PPU_PR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 &= ~_VAL2FLD(PERI_PPU_PR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_PR_ATT1_ENABLED, base->ATT1) == CY_PROT_STRUCT_ENABLE) ? @@ -727,11 +876,14 @@ cy_en_prot_status_t Cy_Prot_DisablePpuProgMasterStruct(PERI_PPU_PR_Type* base) * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was enabled * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuProgSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuProgSlaveStruct(PERI_PPU_PR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 |= _VAL2FLD(PERI_PPU_PR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_PR_ATT0_ENABLED, base->ATT0) != CY_PROT_STRUCT_ENABLE) ? @@ -761,11 +913,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuProgSlaveStruct(PERI_PPU_PR_Type* base) * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was disabled * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuProgSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuProgSlaveStruct(PERI_PPU_PR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 &= ~_VAL2FLD(PERI_PPU_PR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_PR_ATT0_ENABLED, base->ATT0) == CY_PROT_STRUCT_ENABLE) ? @@ -804,13 +959,20 @@ cy_en_prot_status_t Cy_Prot_DisablePpuProgSlaveStruct(PERI_PPU_PR_Type* base) * CY_PROT_SUCCESS | PPU GR master struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuFixedGrMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrMasterStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -873,13 +1035,20 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrMasterStruct(PERI_PPU_GR_Type* base, * CY_PROT_SUCCESS | PPU GR slave struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuFixedGrSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -928,11 +1097,14 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base, * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was enabled * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuFixedGrMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 |= _VAL2FLD(PERI_PPU_GR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_GR_ATT1_ENABLED, base->ATT1) != CY_PROT_STRUCT_ENABLE) ? @@ -962,11 +1134,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base) * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was disabled * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuFixedGrMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 &= ~_VAL2FLD(PERI_PPU_GR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_GR_ATT1_ENABLED, base->ATT1) == CY_PROT_STRUCT_ENABLE) ? @@ -995,11 +1170,14 @@ cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was enabled * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuFixedGrSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 |= _VAL2FLD(PERI_PPU_GR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_GR_ATT0_ENABLED, base->ATT0) != CY_PROT_STRUCT_ENABLE) ? @@ -1029,11 +1207,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base) * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was disabled * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuFixedGrSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 &= ~_VAL2FLD(PERI_PPU_GR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_PPU_GR_ATT0_ENABLED, base->ATT0) == CY_PROT_STRUCT_ENABLE) ? @@ -1072,13 +1253,20 @@ cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base) * CY_PROT_SUCCESS | PPU SL master struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuFixedSlMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -1140,13 +1328,20 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* ba * CY_PROT_SUCCESS | PPU SL slave struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuFixedSlSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -1196,11 +1391,14 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* bas * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was enabled * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuFixedSlMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 |= _VAL2FLD(PERI_GR_PPU_SL_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_SL_ATT1_ENABLED, base->ATT1) != CY_PROT_STRUCT_ENABLE) ? @@ -1230,11 +1428,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* ba * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was disabled * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuFixedSlMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 &= ~_VAL2FLD(PERI_GR_PPU_SL_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_SL_ATT1_ENABLED, base->ATT1) == CY_PROT_STRUCT_ENABLE) ? @@ -1263,11 +1464,14 @@ cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* b * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was enabled * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuFixedSlSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 |= _VAL2FLD(PERI_GR_PPU_SL_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_SL_ATT0_ENABLED, base->ATT0) != CY_PROT_STRUCT_ENABLE) ? @@ -1297,11 +1501,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* bas * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was disabled * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuFixedSlSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 &= ~_VAL2FLD(PERI_GR_PPU_SL_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_SL_ATT0_ENABLED, base->ATT0) == CY_PROT_STRUCT_ENABLE) ? @@ -1340,13 +1547,20 @@ cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* ba * CY_PROT_SUCCESS | PPU RG master struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuFixedRgMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -1408,13 +1622,20 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* ba * CY_PROT_SUCCESS | PPU RG slave struct was successfully configured * CY_PROT_FAILURE | The resource is locked * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_ConfigPpuFixedRgSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; uint32_t attReg; + CY_ASSERT_L1(NULL != base); + CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->userPermission)); + CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->privPermission)); + if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL) { /* PC mask out of range - not supported in device */ @@ -1464,12 +1685,15 @@ cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* bas * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was enabled * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuFixedRgMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; - + cy_en_prot_status_t status; + base->ATT1 |= _VAL2FLD(PERI_GR_PPU_RG_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_RG_ATT1_ENABLED, base->ATT1) != CY_PROT_STRUCT_ENABLE) ? CY_PROT_FAILURE : CY_PROT_SUCCESS; @@ -1498,11 +1722,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* ba * ------------ | ----------- * CY_PROT_SUCCESS | The Master PU struct was disabled * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuFixedRgMasterStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT1 &= ~_VAL2FLD(PERI_GR_PPU_RG_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_RG_ATT1_ENABLED, base->ATT1) == CY_PROT_STRUCT_ENABLE) ? @@ -1531,11 +1758,14 @@ cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* b * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was enabled * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_EnablePpuFixedRgSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 |= _VAL2FLD(PERI_GR_PPU_RG_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_RG_ATT0_ENABLED, base->ATT0) != CY_PROT_STRUCT_ENABLE) ? @@ -1565,11 +1795,14 @@ cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* bas * ------------ | ----------- * CY_PROT_SUCCESS | The Slave PU struct was disabled * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked -* +* +* \funcusage +* \snippet prot/prot_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_Prot_DisablePpuFixedRgSlaveStruct +* *******************************************************************************/ cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base) { - cy_en_prot_status_t status = CY_PROT_SUCCESS; + cy_en_prot_status_t status; base->ATT0 &= ~_VAL2FLD(PERI_GR_PPU_RG_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE); status = (_FLD2VAL(PERI_GR_PPU_RG_ATT0_ENABLED, base->ATT0) == CY_PROT_STRUCT_ENABLE) ? diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/prot/cy_prot.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/prot/cy_prot.h new file mode 100644 index 0000000000..a47ed56060 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/prot/cy_prot.h @@ -0,0 +1,895 @@ +/***************************************************************************//** +* \file cy_prot.h +* \version 1.10 +* +* \brief +* Provides an API declaration of the Protection Unit driver +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +/** +* \defgroup group_prot Protection Unit (Prot) +* \{ +* +* The Protection Unit driver provides an API to configure the Memory Protection +* Units (MPU), Shared Memory Protection Units (SMPU), and Peripheral Protection +* Units (PPU). These are separate from the ARM Core MPUs and provide additional +* mechanisms for securing resource accesses. The Protection units address the +* following concerns in an embedded design: +* - Security requirements: This includes the prevention of malicious attacks +* to access secure memory or peripherals. +* - Safety requirements: This includes detection of accidental (non-malicious) +* SW errors and random HW errors. It is important to enable failure analysis +* to investigate the root cause of a safety violation. +* +* \section group_prot_protection_type Protection Types +* +* Protection units are hardware configuration structures that control bus accesses +* to the resources that they protect. By combining these individual configuration +* structures, a system is built to allow strict restrictions on the capabilities +* of individual bus masters (e.g. CM0+, CM4, Crypt) and their operating modes. +* This architecture can then be integrated into the overall security system +* of the end application. To build this system, 3 main protection unit types +* are available; MPU, SMPU and PPU. When a resource is accessed (memory/register), +* it must pass the evaluation performed for each category. These access evaluations +* are prioritized, where MPU has the highest priority, followed by SMPU, followed +* by PPU. i.e. if an SMPU and a PPU protect the same resource and if access is +* denied by the SMPU, then the PPU access evaluation is skipped. This can lead to a +* denial-of-service scenario and the application should pay special attention in +* taking ownership of the protection unit configurations. +* +* \subsection group_prot_memory_protection Memory Protection +* +* Memory access control for a bus master is controlled using an MPU. These are +* most often used to distinguish user and privileged accesses from a single bus +* master such as task switching in an OS/kernel. For ARM cores (CM0+, CM4), the +* core MPUs are used to perform this task. For other non-ARM bus masters such +* as Crypto, MPU structs are available, which can be used in a similar manner +* as the ARM core MPUs. These MPUs however must be configured by the ARM cores. +* Other bus masters that do not have an MPU, such as DMA (DW), inherit the access +* control attributes of the bus master that configured the channel. Also note +* that unlike other protection units, MPUs do not support protection context +* evaluation. MPU structs have a descending priority, where larger index struct +* has higher priority access evaluation over lower index structs. E.g. MPU_STRUCT15 +* has higher priority than MPU_STRUCT14 and its access will be evaluated before +* MPU_STRUCT14. If both target the same memory, then the higher index (MPU_STRUCT15) +* will be used, and the lower index (MPU_STRUCT14) will be ignored. +* +* \subsection group_prot_shared_memory_protection Shared Memory Protection +* +* In order to protect a region of memory from all bus masters, an SMPU is used. +* This protection effectively allows only those with correct bus master access +* settings to read/write/execute the memory region. This type of protection +* is used in general memory such as Flash and SRAM. Peripheral registers are +* best configured using the peripheral protection units instead. SMPU structs +* have a descending priority, where larger index struct has higher priority +* access evaluation over lower index structs. E.g. SMPU_STRUCT15 has higher priority +* than SMPU_STRUCT14 and its access will be evaluated before SMPU_STRUCT14. +* If both target the same memory, then the higher index (MPU_STRUCT15) will be +* used, and the lower index (SMPU_STRUCT14) will be ignored. +* +* \subsection group_prot_peripheral_protection Peripheral Protection +* +* Peripheral protection is provided by PPUs and allow control of peripheral +* register accesses by bus masters. Four types of PPUs are available. +* - Fixed Group (GR) PPUs are used to protect an entire peripheral MMIO group +* from invalid bus master accesses. The MMIO grouping information and which +* resource belongs to which group is device specific and can be obtained +* from the device technical reference manual (TRM). Group PPUs have the highest +* priority in the PPU category. Therefore their access evaluations take precedence +* over the other types of PPUs. +* - Programmable (PROG) PPUs are used to protect any peripheral memory region +* in a device from invalid bus master accesses. It is the most versatile +* type of peripheral protection unit. Programmable PPUs have the second highest +* priority and take precedence over Region PPUs and Slave PPUs. Similar to SMPUs, +* higher index PROG PPUs have higher priority than lower indexes PROG PPUs. +* - Fixed Region (RG) PPUs are used to protect an entire peripheral slave +* instance from invalid bus master accesses. For example, TCPWM0, TCPWM1, +* SCB0, and SCB1, etc. Region PPUs have the third highest priority and take precedence +* over Slave PPUs. +* - Fixed Slave (SL) PPUs are used to protect specified regions of peripheral +* instances. For example, individual DW channel structs, SMPU structs, and +* IPC structs, etc. Slave PPUs have the lowest priority in the PPU category and +* therefore are evaluated last. +* +* \section group_prot_protection_context Protection Context +* +* Protection context (PC) attribute is present in all bus masters and is evaluated +* when accessing memory protected by an SMPU or a PPU. There are no limitations +* to how the PC values are allocated to the bus masters and this makes it +* possible for multiple bus masters to essentially share protection context +* values. The exception to this rule is the PC value 0. +* +* \subsection group_prot_pc0 PC=0 +* +* Protection context 0 is a hardware controlled protection context update +* mechanism that allows only a single entry point for transitioning into PC=0 +* value. This mechanism is only present for the secure CM0+ core and is a +* fundamental feature in defining a security solution. While all bus masters +* are configured to PC=0 at device boot, it is up to the security solution +* to transition these bus masters to PC!=0 values. Once this is done, those +* bus masters can no longer revert back to PC=0 and can no longer access +* resources protected at PC=0. +* +* In order to enter PC=0, the CM0+ core must assign an interrupt vector or +* an exception handler address to the CPUSS.CM0_PC0_HANDLER register. This +* allows the hardware to check whether the executing code address matches the +* value in this register. If they match, the current PC value is saved and +* the CM0+ bus master automatically transitions to PC=0. It is then up to +* the executing code to decide if and when it will revert to a PC!=0 value. +* At that point, the only way to re-transition to PC=0 is through the defined +* exception/interrupt handler. +* +* \section group_prot_access_evaluation Access Evaluation +* +* Each protection unit is capable of evaluating several access types. These can +* be used to build a system of logical evaluations for different kinds of +* bus master modes of operations. These access types can be divided into +* three broad access categories. +* +* - User/Privileged access: The ARM convention of user mode versus privileged +* mode is applied in the protection units. For ARM cores, switching between +* user and privileged modes is handled by updating its Control register or +* by exception entries. Other bus masters such as Crypto have their own +* user/privileged settings bit in the bus master control register. This is +* then controlled by the ARM cores. Bus masters that do not have +* user/privileged access controls, such as DMA, inherit their attributes +* from the bus master that configured it. The user/privileged distinction +* is used mainly in the MPUs for single bus master accesses but they can +* also be used in all other protection units. +* - Secure/Non-secure access: The secure/non-secure attribute is another +* identifier to distinguish between two separate modes of operations. Much +* like the user/privileged access, the secure/non-secure mode flag is present +* in the bus master control register. The ARM core does not have this +* attribute in its control register and must use the bus master control +* register instead. Bus masters that inherit their attributes, such as DMA, +* inherit the secure/non-secure attribute. The primary use-case for this +* access evaluation is to define a region to be secure or non-secure using +* an SMPU or a PPU. A bus master with a secure attribute can access +* both secure and non-secure regions, whereas a bus master with non-secure +* attribute can only access non-secure regions. +* - Protection Context access: Protection Context is an attribute +* that serves two purposes; To enter the hardware controlled secure PC=0 +* mode of operation from non-secure modes and to provide finer granularity +* to the bus master access definitions. It is used in SMPU and PPU configuration +* to control which bus master protection context can access the resources +* that they protect. +* +* \section group_prot_protection_structure Protection Structure +* +* Each protection unit is comprised of a master struct and a slave struct pair. +* The exception to this rule is MPU structs, which only have the slave struct +* equivalent. The protection units apply their access evaluations in a decreasing +* index order. For example, if SMPU1 and SMPU2 both protect a specific memory region, +* the the higher index (SMPU2) will be evaluated first. In a secure system, the +* higher index protection structs would then provide the high level of security +* and the lower indexes would provide the lower level of security. Refer to the +* \ref group_prot_protection_type section for more information. +* +* \subsection group_prot_slave_struct Slave Struct +* +* The slave struct is used to configure the protection settings for the resource +* of interest (memory/registers). Depending on the type of protection unit, +* the available attributes differ. However all Slave protection units have the +* following general format. +* +* \subsubsection group_prot_slave_addr Slave Struct Address Definition +* +* - Address: For MPU, SMPU and PROG PPU, the address field is used to define +* the base memory region to apply the protection. This field has a dependency +* on the region size, which dictates the alignment of the protection unit. E.g. +* if the region size is 64KB, the address field is aligned to 64KB. Hence +* the lowest bits [15:0] are ignored. For instance, if the address is defined +* at 0x0800FFFF, the protection unit would apply its protection settings from +* 0x08000000. Thus alignment must be checked before defining the protection +* address. The address field for other PPUs are not used, as they are bound +* to their respective peripheral memory locations. +* - Region Size: For MPU, SMPU and PROG PPU, the region size is used to define +* the memory block size to apply the protection settings, starting from the +* defined base address. It is also used to define the 8 sub-regions for the +* chosen memory block. E.g. If the region size is 64KB, each subregion would +* be 8KB. This information can then be used to disable the protection +* settings for select subregions, which gives finer granularity to the +* memory regions. PPUs do not have region size definitions as they are bound +* to their respective peripheral memory locations. +* - Subregions: The memory block defined by the address and region size fields +* is divided into 8 (0 to 7) equally spaced subregions. The protection settings +* of the protection unit can be disabled for these subregions. E.g. for a +* given 64KB of memory block starting from address 0x08000000, disabling +* subregion 0 would result in the protection settings not affecting the memory +* located between 0x08000000 to 0x08001FFF. PPUs do not have subregion +* definitions as they are bound to their respective peripheral memory locations. +* +* \subsubsection group_prot_slave_attr Slave Struct Attribute Definition +* +* - User Permission: Protection units can control the access restrictions +* of the read (R), write (W) and execute (X) (subject to their availability +* depending on the type of protection unit) operations on the memory block +* when the bus master is operating in user mode. PPU structs do not provide +* execute attributes. +* - Privileged Permission: Similar to the user permission, protection units can +* control the access restrictions of the read (R), write (W) and execute (X) +* (subject to their availability depending on the type of protection unit) +* operations on the memory block when the bus master is operating in +* privileged mode. PPU structs do not provide execute attributes. +* - Secure/Non-secure: Applies the secure/non-secure protection settings to +* the defined memory region. Secure protection allows only bus masters that +* access the memory with secure attribute. Non-secure protection allows +* bus masters that have either secure or non-secure attributes. +* - PC match: This attribute allows the protection unit to either apply the +* 3 access evaluations (user/privileged, secure/non-secure, protection context) +* or to only provide an address range match. This is useful when multiple +* protection units protect an overlapping memory region and it's desirable +* to only have access evaluations applied from only one of these protection +* units. For example, SMPU1 protects memory A and SMPU2 protects memory B. +* There exists a region where A and B intersect and this is accessed by a +* bus master. Both SMPU1 and SMPU2 are configured to operate in "match" mode. +* In this scenario, the access evaluation will only be applied by the higher +* index protection unit (i.e. SMPU2) and the access attributes of SMPU1 will +* be ignored. If the bus master then tries to access a memory region A (that +* does not intersect with B), the access evaluation from SMPU1 will be used. +* Note that the PC match functionality is only available in SMPUs. +* - PC mask: Defines the allowed protection context values that can access the +* protected memory. The bus master attribute must be operating in one of the +* protection context values allowed by the protection unit. E.g. If SMPU1 is +* configured to allow only PC=1 and PC=5, a bus master (such as CM4) must +* be operating at PC=1 or PC=5 when accessing the protected memory region. +* +* \subsection group_prot_master_struct Master Struct +* +* The master struct protects its slave struct in the protection unit. This +* architecture makes possible for the slave configuration to be protected from +* reconfiguration by an unauthorized bus master. The configuration attributes +* and the format are similar to that of the slave structs. +* +* \subsubsection group_prot_master_addr Master Struct Address Definition +* +* - Address: The address definition for master struct is fixed to the slave +* struct that it protects. +* - Region Size: The region size is fixed to 256B region. +* - Subregion: This value is fixed to only enable the first 64B subregions, +* which applies the protection settings to the entire protection unit. +* +* \subsubsection group_prot_master_attr Master Struct Attribute Definition +* +* - User Permission: Only the write (W) access attribute is allowed for +* master structs, which controls whether a bus master operating in user +* mode has the write access. +* - Privileged Permission: Only the write (W) access attribute is allowed for +* master structs, which controls whether a bus master operating in privileged +* mode has the write access. +* - Secure/Non-Secure: Same behavior as slave struct. +* - PC match: Same behavior as slave struct. +* - PC mask: Same behavior as slave struct. +* +* \section group_prot_driver_usage Driver Usage +* +* Setting up and using protection units can be summed up in four stages: +* +* - Configure the bus master attributes. This defines the capabilities of +* the bus master when trying to access the protected resources. +* - Configure the slave struct of a given protection unit. This defines +* the protection attributes to be applied to the bus master accessing +* the protected resource and also defines the size and location of the +* memory block to protect. +* - Configure the master struct of the protection unit. This defines the +* attributes to be checked against the bus master that is trying to +* reconfigure the slave struct. +* - Set the active PC value of the bus master and place it in the correct +* mode of operation (user/privileged, secure/non-secure). Then access +* the protected memory. +* +* For example, by configuring the CM0+ bus master configuration to allow +* only protection contexts 2 and 3, the bus master will be able to +* set its protection context only to 2 or 3. During runtime, the CM0+ core +* can set its protection context to 2 by calling Cy_Prot_SetActivePC() +* and access all regions of protected memory that allow PC=2. A fault will +* be triggered if a resource is protected with different protection settings. +* +* Note that each protection unit is distinguished by its type (e.g. +* PROT_MPU_MPU_STRUCT_Type). The list of supported protection units can be +* obtained from the device definition header file. Choose a protection unit +* of interest, and call its corresponding Cy_Prot_ConfigStruct() function +* with its software protection unit configuration structure populated. Then +* enable the protection unit by calling the Cy_Prot_EnableStruct() function. +* +* Note that the bus master ID (en_prot_master_t) is defined in the device +* config header file. +* +* \section group_prot_configuration Configuration Considerations +* +* When a resource (memory/register) is accessed, it must pass evaluation of +* all three protection unit categories in the following order: MPU->SMPU->PPU. +* The application should ensure that a denial-of-service attack cannot be +* made on the PPU by the SMPU. For this reason, it is recommended that the +* application's security policy limit the ability for the non-secure client +* from configuring the SMPUs. +* +* Within each category, the priority hierarchy must be carefully considered +* to ensure that a higher priority protection unit cannot be configured to +* override the security configuration of a lower index protection unit. +* Therefore if a lower index protection unit is configured, relevant higher +* priority indexes should be configured (or protected from unwanted +* reconfiguration). E.g. If a PPU_SL is configured, PPU_RG and PPU_GR that +* overlaps with the protected registers should also be configured. SImilar +* to SMPUs, it is recommended that the configuration of PPU_PROG be limited. +* Otherwise they can be used to override the protection settings of PPU_RG +* and PPU_SL structs. +* +* All bus masters are set to PC=0 value at device reset and therefore have full +* access to all resources. It is up to the security solution to implement +* what privileges each bus master has. Once transitioned to a PC!=0 value, +* only the CM0+ core is capable of re-entering the PC=0 via the user-defined +* exception entry in the CPUSS.CM0_PC0_HANDLER register. +* +* - SMPU 15 and 14 are configured and enabled to only allow PC=0 accesses at +* device boot. +* - PROG PPU 15, 14, 13 and 12 are configured to only allow PC=0 accesses at +* device boot. +* - GR PPU 0 and 2 are configured to only allow PC=0 accesses at device boot. +* +* \section group_prot_more_information More Information +* +* Refer to Technical Reference Manual (TRM) and the device datasheet. +* +* \section group_prot_MISRA MISRA-C Compliance] +* The Prot driver does not have any driver-specific deviations. +* +* \section group_prot_changelog Changelog +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
VersionChangesReason for Change
1.10Added input parameter validation to the API functions.
+* cy_en_prot_pcmask_t, cy_en_prot_subreg_t and cy_en_prot_pc_t +* types are set to typedef enum
Improved debugging capability
Expanded documentation
1.0Initial version
+* +* \defgroup group_prot_macros Macros +* \defgroup group_prot_functions Functions +* \{ +* \defgroup group_prot_functions_busmaster Bus Master and PC Functions +* \defgroup group_prot_functions_mpu MPU Functions +* \defgroup group_prot_functions_smpu SMPU Functions +* \defgroup group_prot_functions_ppu_prog PPU Programmable (PROG) Functions +* \defgroup group_prot_functions_ppu_gr PPU Group (GR) Functions +* \defgroup group_prot_functions_ppu_sl PPU Slave (SL) Functions +* \defgroup group_prot_functions_ppu_rg PPU Region (RG) Functions +* \} +* \defgroup group_prot_data_structures Data Structures +* \defgroup group_prot_enums Enumerated Types +*/ + +#if !defined(__CY_PROT_H__) +#define __CY_PROT_H__ + +#include +#include +#include "syslib/cy_syslib.h" +#include "cy_device_headers.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/** \addtogroup group_prot_macros +* \{ +*/ + +/** Driver major version */ +#define CY_PROT_DRV_VERSION_MAJOR 1 + +/** Driver minor version */ +#define CY_PROT_DRV_VERSION_MINOR 10 + +/** Prot driver ID */ +#define CY_PROT_ID CY_PDL_DRV_ID(0x30u) + +/** \} group_prot_macros */ + +/** +* \addtogroup group_prot_enums +* \{ +*/ + +/** +* Prot Driver error codes +*/ +typedef enum +{ + CY_PROT_SUCCESS = 0x00u, /**< Returned successful */ + CY_PROT_BAD_PARAM = CY_PROT_ID | CY_PDL_STATUS_ERROR | 0x01u, /**< Bad parameter was passed */ + CY_PROT_FAILURE = CY_PROT_ID | CY_PDL_STATUS_ERROR | 0x03u /**< The resource is locked */ +} cy_en_prot_status_t; + +/** +* User/Privileged permission +*/ +typedef enum +{ + CY_PROT_PERM_DISABLED = 0x00u, /**< Read, Write and Execute disabled */ + CY_PROT_PERM_R = 0x01u, /**< Read enabled */ + CY_PROT_PERM_W = 0x02u, /**< Write enabled */ + CY_PROT_PERM_RW = 0x03u, /**< Read and Write enabled */ + CY_PROT_PERM_X = 0x04u, /**< Execute enabled */ + CY_PROT_PERM_RX = 0x05u, /**< Read and Execute enabled */ + CY_PROT_PERM_WX = 0x06u, /**< Write and Execute enabled */ + CY_PROT_PERM_RWX = 0x07u /**< Read, Write and Execute enabled */ +}cy_en_prot_perm_t; + +/** +* Memory region size +*/ +typedef enum +{ + CY_PROT_SIZE_256B = 7u, /**< 256 bytes */ + CY_PROT_SIZE_512B = 8u, /**< 512 bytes */ + CY_PROT_SIZE_1KB = 9u, /**< 1 Kilobyte */ + CY_PROT_SIZE_2KB = 10u, /**< 2 Kilobytes */ + CY_PROT_SIZE_4KB = 11u, /**< 4 Kilobytes */ + CY_PROT_SIZE_8KB = 12u, /**< 8 Kilobytes */ + CY_PROT_SIZE_16KB = 13u, /**< 16 Kilobytes */ + CY_PROT_SIZE_32KB = 14u, /**< 32 Kilobytes */ + CY_PROT_SIZE_64KB = 15u, /**< 64 Kilobytes */ + CY_PROT_SIZE_128KB = 16u, /**< 128 Kilobytes */ + CY_PROT_SIZE_256KB = 17u, /**< 256 Kilobytes */ + CY_PROT_SIZE_512KB = 18u, /**< 512 Kilobytes */ + CY_PROT_SIZE_1MB = 19u, /**< 1 Megabyte */ + CY_PROT_SIZE_2MB = 20u, /**< 2 Megabytes */ + CY_PROT_SIZE_4MB = 21u, /**< 4 Megabytes */ + CY_PROT_SIZE_8MB = 22u, /**< 8 Megabytes */ + CY_PROT_SIZE_16MB = 23u, /**< 16 Megabytes */ + CY_PROT_SIZE_32MB = 24u, /**< 32 Megabytes */ + CY_PROT_SIZE_64MB = 25u, /**< 64 Megabytes */ + CY_PROT_SIZE_128MB = 26u, /**< 128 Megabytes */ + CY_PROT_SIZE_256MB = 27u, /**< 256 Megabytes */ + CY_PROT_SIZE_512MB = 28u, /**< 512 Megabytes */ + CY_PROT_SIZE_1GB = 29u, /**< 1 Gigabyte */ + CY_PROT_SIZE_2GB = 30u, /**< 2 Gigabytes */ + CY_PROT_SIZE_4GB = 31u /**< 4 Gigabytes */ +}cy_en_prot_size_t; + +/** +* Protection Context (PC) +*/ +enum cy_en_prot_pc_t +{ + CY_PROT_PC1 = 1u, /**< PC = 1 */ + CY_PROT_PC2 = 2u, /**< PC = 2 */ + CY_PROT_PC3 = 3u, /**< PC = 3 */ + CY_PROT_PC4 = 4u, /**< PC = 4 */ + CY_PROT_PC5 = 5u, /**< PC = 5 */ + CY_PROT_PC6 = 6u, /**< PC = 6 */ + CY_PROT_PC7 = 7u, /**< PC = 7 */ + CY_PROT_PC8 = 8u, /**< PC = 8 */ + CY_PROT_PC9 = 9u, /**< PC = 9 */ + CY_PROT_PC10 = 10u, /**< PC = 10 */ + CY_PROT_PC11 = 11u, /**< PC = 11 */ + CY_PROT_PC12 = 12u, /**< PC = 12 */ + CY_PROT_PC13 = 13u, /**< PC = 13 */ + CY_PROT_PC14 = 14u, /**< PC = 14 */ + CY_PROT_PC15 = 15u /**< PC = 15 */ +}; + +/** +* Subregion disable (0-7) +*/ +enum cy_en_prot_subreg_t +{ + CY_PROT_SUBREGION_DIS0 = 0x01u, /**< Disable subregion 0 */ + CY_PROT_SUBREGION_DIS1 = 0x02u, /**< Disable subregion 1 */ + CY_PROT_SUBREGION_DIS2 = 0x04u, /**< Disable subregion 2 */ + CY_PROT_SUBREGION_DIS3 = 0x08u, /**< Disable subregion 3 */ + CY_PROT_SUBREGION_DIS4 = 0x10u, /**< Disable subregion 4 */ + CY_PROT_SUBREGION_DIS5 = 0x20u, /**< Disable subregion 5 */ + CY_PROT_SUBREGION_DIS6 = 0x40u, /**< Disable subregion 6 */ + CY_PROT_SUBREGION_DIS7 = 0x80u /**< Disable subregion 7 */ +}; + +/** +* Protection context mask (PC_MASK) +*/ +enum cy_en_prot_pcmask_t +{ + CY_PROT_PCMASK1 = 0x0001u, /**< Mask to allow PC = 1 */ + CY_PROT_PCMASK2 = 0x0002u, /**< Mask to allow PC = 2 */ + CY_PROT_PCMASK3 = 0x0004u, /**< Mask to allow PC = 3 */ + CY_PROT_PCMASK4 = 0x0008u, /**< Mask to allow PC = 4 */ + CY_PROT_PCMASK5 = 0x0010u, /**< Mask to allow PC = 5 */ + CY_PROT_PCMASK6 = 0x0020u, /**< Mask to allow PC = 6 */ + CY_PROT_PCMASK7 = 0x0040u, /**< Mask to allow PC = 7 */ + CY_PROT_PCMASK8 = 0x0080u, /**< Mask to allow PC = 8 */ + CY_PROT_PCMASK9 = 0x0100u, /**< Mask to allow PC = 9 */ + CY_PROT_PCMASK10 = 0x0200u, /**< Mask to allow PC = 10 */ + CY_PROT_PCMASK11 = 0x0400u, /**< Mask to allow PC = 11 */ + CY_PROT_PCMASK12 = 0x0800u, /**< Mask to allow PC = 12 */ + CY_PROT_PCMASK13 = 0x1000u, /**< Mask to allow PC = 13 */ + CY_PROT_PCMASK14 = 0x2000u, /**< Mask to allow PC = 14 */ + CY_PROT_PCMASK15 = 0x4000u /**< Mask to allow PC = 15 */ +}; + +/** \} group_prot_enums */ + + +/*************************************** +* Constants +***************************************/ + +/** \cond INTERNAL */ + +/* Helper function for finding max */ +#define CY_PROT_MAX(x,y) (((x)>(y))?(x):(y)) + +/* General Masks and shifts */ +#define CY_PROT_MSX_CTL_SHIFT (0x02UL) /**< Shift for MSx_CTL register */ +#define CY_PROT_STRUCT_ENABLE (0x01UL) /**< Enable protection unit struct */ +#define CY_PROT_ADDR_SHIFT (8UL) /**< Address shift for MPU, SMPU and PROG PPU structs */ + +/* Permission masks and shifts */ +#define CY_PROT_ATT_PERMISSION_MASK (0x07UL) /**< Protection Unit attribute permission mask */ +#define CY_PROT_ATT_USER_PERMISSION_SHIFT (0x00UL) /**< Protection Unit user attribute permission shift */ +#define CY_PROT_ATT_PRIV_PERMISSION_SHIFT (0x03UL) /**< Protection Unit priliged attribute permission shift */ + +/* Maximum Master Protection Context */ +#define CY_PROT_MS_PC_NR_MAX CY_PROT_MAX(CPUSS_PROT_SMPU_MS0_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS1_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS2_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS3_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS4_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS5_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS6_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS7_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS8_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS9_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS10_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS11_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS12_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS13_PC_NR_MINUS1, \ + CY_PROT_MAX(CPUSS_PROT_SMPU_MS14_PC_NR_MINUS1, \ + CPUSS_PROT_SMPU_MS15_PC_NR_MINUS1))))))))))))))) + +/* Protection Context limit masks */ +#define CY_PROT_MS0_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS0_PC_NR_MINUS1) +#define CY_PROT_MS1_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS1_PC_NR_MINUS1) +#define CY_PROT_MS2_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS2_PC_NR_MINUS1) +#define CY_PROT_MS3_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS3_PC_NR_MINUS1) +#define CY_PROT_MS4_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS4_PC_NR_MINUS1) +#define CY_PROT_MS5_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS5_PC_NR_MINUS1) +#define CY_PROT_MS6_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS6_PC_NR_MINUS1) +#define CY_PROT_MS7_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS7_PC_NR_MINUS1) +#define CY_PROT_MS8_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS8_PC_NR_MINUS1) +#define CY_PROT_MS9_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS9_PC_NR_MINUS1) +#define CY_PROT_MS10_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS10_PC_NR_MINUS1) +#define CY_PROT_MS11_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS11_PC_NR_MINUS1) +#define CY_PROT_MS12_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS12_PC_NR_MINUS1) +#define CY_PROT_MS13_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS13_PC_NR_MINUS1) +#define CY_PROT_MS14_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS14_PC_NR_MINUS1) +#define CY_PROT_MS15_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_PROT_SMPU_MS15_PC_NR_MINUS1) + +#define CY_PROT_MPU_PC_LIMIT_MASK (0xFFFFFFFFUL << CY_PROT_MS_PC_NR_MAX) +#define CY_PROT_SMPU_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_SMPU_STRUCT_PC_NR_MINUS1) +#define CY_PROT_PPU_PROG_PC_LIMIT_MASK (0xFFFFFFFFUL << PERI_PPU_PROG_STRUCT_PC_NR_MINUS1) +#define CY_PROT_PPU_FIXED_PC_LIMIT_MASK (0xFFFFFFFFUL << PERI_PPU_FIXED_STRUCT_PC_NR_MINUS1) + +/* Parameter validation masks to check for read-only values */ +#define CY_PROT_SMPU_ATT0_MASK ((uint32_t)~(PROT_SMPU_SMPU_STRUCT_ATT0_PC_MASK_0_Msk)) +#define CY_PROT_SMPU_ATT1_MASK ((uint32_t)~(PROT_SMPU_SMPU_STRUCT_ATT1_UX_Msk \ + | PROT_SMPU_SMPU_STRUCT_ATT1_PX_Msk \ + | PROT_SMPU_SMPU_STRUCT_ATT1_PC_MASK_0_Msk \ + | PROT_SMPU_SMPU_STRUCT_ATT1_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_PROG_ATT0_MASK ((uint32_t)~(PERI_PPU_PR_ATT0_UX_Msk \ + | PERI_PPU_PR_ATT0_PX_Msk \ + | PERI_PPU_PR_ATT0_PC_MASK_0_Msk \ + )) +#define CY_PROT_PPU_PROG_ATT1_MASK ((uint32_t)~(PERI_PPU_PR_ATT1_UX_Msk \ + | PERI_PPU_PR_ATT1_PX_Msk \ + | PERI_PPU_PR_ATT1_PC_MASK_0_Msk \ + | PERI_PPU_PR_ATT1_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_GR_ATT0_MASK ((uint32_t)~(PERI_PPU_GR_ATT0_UX_Msk \ + | PERI_PPU_GR_ATT0_PX_Msk \ + | PERI_PPU_GR_ATT0_PC_MASK_0_Msk \ + | PERI_PPU_GR_ATT0_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_GR_ATT1_MASK ((uint32_t)~(PERI_PPU_GR_ATT1_UX_Msk \ + | PERI_PPU_GR_ATT1_PX_Msk \ + | PERI_PPU_GR_ATT1_PC_MASK_0_Msk \ + | PERI_PPU_GR_ATT1_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_SL_ATT0_MASK ((uint32_t)~(PERI_PPU_GR_ATT0_UX_Msk \ + | PERI_PPU_GR_ATT0_PX_Msk \ + | PERI_PPU_GR_ATT0_PC_MASK_0_Msk \ + | PERI_PPU_GR_ATT0_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_SL_ATT1_MASK ((uint32_t)~(PERI_PPU_GR_ATT1_UX_Msk \ + | PERI_PPU_GR_ATT1_PX_Msk \ + | PERI_PPU_GR_ATT1_PC_MASK_0_Msk \ + | PERI_PPU_GR_ATT1_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_RG_ATT0_MASK ((uint32_t)~(PERI_PPU_GR_ATT0_UX_Msk \ + | PERI_PPU_GR_ATT0_PX_Msk \ + | PERI_PPU_GR_ATT0_PC_MASK_0_Msk \ + | PERI_PPU_GR_ATT0_REGION_SIZE_Msk \ + )) +#define CY_PROT_PPU_RG_ATT1_MASK ((uint32_t)~(PERI_PPU_GR_ATT1_UX_Msk \ + | PERI_PPU_GR_ATT1_PX_Msk \ + | PERI_PPU_GR_ATT1_PC_MASK_0_Msk \ + | PERI_PPU_GR_ATT1_REGION_SIZE_Msk \ + )) + +/* Parameter check macros */ +#define CY_PROT_BUS_MASTER_MAX (16UL) +#define CY_PROT_IS_BUS_MASTER_VALID(busMaster) (CY_PROT_BUS_MASTER_MAX > ((uint32_t)(busMaster))) + +#define CY_PROT_IS_MPU_PERM_VALID(permission) (((permission) == CY_PROT_PERM_DISABLED) || \ + ((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_W) || \ + ((permission) == CY_PROT_PERM_RW) || \ + ((permission) == CY_PROT_PERM_X) || \ + ((permission) == CY_PROT_PERM_RX) || \ + ((permission) == CY_PROT_PERM_WX) || \ + ((permission) == CY_PROT_PERM_RWX)) + +#define CY_PROT_IS_SMPU_MS_PERM_VALID(permission) (((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_RW)) + +#define CY_PROT_IS_SMPU_SL_PERM_VALID(permission) (((permission) == CY_PROT_PERM_DISABLED) || \ + ((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_W) || \ + ((permission) == CY_PROT_PERM_RW) || \ + ((permission) == CY_PROT_PERM_X) || \ + ((permission) == CY_PROT_PERM_RX) || \ + ((permission) == CY_PROT_PERM_WX) || \ + ((permission) == CY_PROT_PERM_RWX)) + +#define CY_PROT_IS_PROG_MS_PERM_VALID(permission) (((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_RW)) + +#define CY_PROT_IS_PROG_SL_PERM_VALID(permission) (((permission) == CY_PROT_PERM_DISABLED) || \ + ((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_W) || \ + ((permission) == CY_PROT_PERM_RW)) + +#define CY_PROT_IS_FIXED_MS_PERM_VALID(permission) (((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_RW)) + +#define CY_PROT_IS_FIXED_SL_PERM_VALID(permission) (((permission) == CY_PROT_PERM_DISABLED) || \ + ((permission) == CY_PROT_PERM_R) || \ + ((permission) == CY_PROT_PERM_W) || \ + ((permission) == CY_PROT_PERM_RW)) + +#define CY_PROT_IS_REGION_SIZE_VALID(regionSize) (((regionSize) == CY_PROT_SIZE_256B) || \ + ((regionSize) == CY_PROT_SIZE_512B) || \ + ((regionSize) == CY_PROT_SIZE_1KB) || \ + ((regionSize) == CY_PROT_SIZE_2KB) || \ + ((regionSize) == CY_PROT_SIZE_4KB) || \ + ((regionSize) == CY_PROT_SIZE_8KB) || \ + ((regionSize) == CY_PROT_SIZE_16KB) || \ + ((regionSize) == CY_PROT_SIZE_32KB) || \ + ((regionSize) == CY_PROT_SIZE_64KB) || \ + ((regionSize) == CY_PROT_SIZE_128KB) || \ + ((regionSize) == CY_PROT_SIZE_256KB) || \ + ((regionSize) == CY_PROT_SIZE_512KB) || \ + ((regionSize) == CY_PROT_SIZE_1MB) || \ + ((regionSize) == CY_PROT_SIZE_2MB) || \ + ((regionSize) == CY_PROT_SIZE_4MB) || \ + ((regionSize) == CY_PROT_SIZE_8MB) || \ + ((regionSize) == CY_PROT_SIZE_16MB) || \ + ((regionSize) == CY_PROT_SIZE_32MB) || \ + ((regionSize) == CY_PROT_SIZE_64MB) || \ + ((regionSize) == CY_PROT_SIZE_128MB) || \ + ((regionSize) == CY_PROT_SIZE_256MB) || \ + ((regionSize) == CY_PROT_SIZE_512MB) || \ + ((regionSize) == CY_PROT_SIZE_1GB) || \ + ((regionSize) == CY_PROT_SIZE_2GB) || \ + ((regionSize) == CY_PROT_SIZE_4GB)) + +/** \endcond */ + + +/*************************************** +* Configuration Structures +***************************************/ + +/** +* \addtogroup group_prot_data_structures +* \{ +*/ + +/** Configuration structure for MPU Struct initialization */ +typedef struct +{ + uint32_t* address; /**< Base address of the memory region */ + cy_en_prot_size_t regionSize; /**< Size of the memory region */ + uint8_t subregions; /**< Mask of the 8 subregions to disable */ + cy_en_prot_perm_t userPermission; /**< User permissions for the region */ + cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ + bool secure; /**< Non Secure = 0, Secure = 1 */ +} cy_stc_mpu_cfg_t; + +/** Configuration structure for SMPU struct initialization */ +typedef struct +{ + uint32_t* address; /**< Base address of the memory region (Only applicable to slave) */ + cy_en_prot_size_t regionSize; /**< Size of the memory region (Only applicable to slave) */ + uint8_t subregions; /**< Mask of the 8 subregions to disable (Only applicable to slave) */ + cy_en_prot_perm_t userPermission; /**< User permissions for the region */ + cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ + bool secure; /**< Non Secure = 0, Secure = 1 */ + bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ + uint16_t pcMask; /**< Mask of allowed protection context(s) */ +} cy_stc_smpu_cfg_t; + +/** Configuration structure for Programmable (PROG) PPU (PPU_PR) struct initialization */ +typedef struct +{ + uint32_t* address; /**< Base address of the memory region (Only applicable to slave) */ + cy_en_prot_size_t regionSize; /**< Size of the memory region (Only applicable to slave) */ + uint8_t subregions; /**< Mask of the 8 subregions to disable (Only applicable to slave) */ + cy_en_prot_perm_t userPermission; /**< User permissions for the region */ + cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ + bool secure; /**< Non Secure = 0, Secure = 1 */ + bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ + uint16_t pcMask; /**< Mask of allowed protection context(s) */ +} cy_stc_ppu_prog_cfg_t; + +/** Configuration structure for Fixed Group (GR) PPU (PPU_GR) struct initialization */ +typedef struct +{ + cy_en_prot_perm_t userPermission; /**< User permissions for the region */ + cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ + bool secure; /**< Non Secure = 0, Secure = 1 */ + bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ + uint16_t pcMask; /**< Mask of allowed protection context(s) */ +} cy_stc_ppu_gr_cfg_t; + +/** Configuration structure for Fixed Slave (SL) PPU (PPU_SL) struct initialization */ +typedef struct +{ + cy_en_prot_perm_t userPermission; /**< User permissions for the region */ + cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ + bool secure; /**< Non Secure = 0, Secure = 1 */ + bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ + uint16_t pcMask; /**< Mask of allowed protection context(s) */ +} cy_stc_ppu_sl_cfg_t; + +/** Configuration structure for Fixed Region (RG) PPU (PPU_RG) struct initialization */ +typedef struct +{ + cy_en_prot_perm_t userPermission; /**< User permissions for the region */ + cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ + bool secure; /**< Non Secure = 0, Secure = 1 */ + bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ + uint16_t pcMask; /**< Mask of allowed protection context(s) */ +} cy_stc_ppu_rg_cfg_t; + +/** \} group_prot_data_structures */ + + +/*************************************** +* Function Prototypes +***************************************/ + +/** +* \addtogroup group_prot_functions +* \{ +*/ + +/** +* \addtogroup group_prot_functions_busmaster +* \{ +*/ + +cy_en_prot_status_t Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster, bool privileged, bool secure, uint32_t pcMask); +cy_en_prot_status_t Cy_Prot_SetActivePC(en_prot_master_t busMaster, uint32_t pc); +uint32_t Cy_Prot_GetActivePC(en_prot_master_t busMaster); + +/** \} group_prot_functions_busmaster */ + +/** +* \addtogroup group_prot_functions_mpu +* \{ +*/ + +cy_en_prot_status_t Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type* base, const cy_stc_mpu_cfg_t* config); +cy_en_prot_status_t Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base); +cy_en_prot_status_t Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base); + +/** \} group_prot_functions_mpu */ + +/** +* \addtogroup group_prot_functions_smpu +* \{ +*/ + +cy_en_prot_status_t Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config); +cy_en_prot_status_t Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config); +cy_en_prot_status_t Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base); +cy_en_prot_status_t Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base); +cy_en_prot_status_t Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base); +cy_en_prot_status_t Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base); + +/** \} group_prot_functions_smpu */ + +/** +* \addtogroup group_prot_functions_ppu_prog +* \{ +*/ + +cy_en_prot_status_t Cy_Prot_ConfigPpuProgMasterStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config); +cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config); +cy_en_prot_status_t Cy_Prot_EnablePpuProgMasterStruct(PERI_PPU_PR_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuProgMasterStruct(PERI_PPU_PR_Type* base); +cy_en_prot_status_t Cy_Prot_EnablePpuProgSlaveStruct(PERI_PPU_PR_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuProgSlaveStruct(PERI_PPU_PR_Type* base); + +/** \} group_prot_functions_ppu_prog */ + +/** +* \addtogroup group_prot_functions_ppu_gr +* \{ +*/ + +cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrMasterStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config); +cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config); +cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base); +cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base); + +/** \} group_prot_functions_ppu_gr */ + +/** +* \addtogroup group_prot_functions_ppu_sl +* \{ +*/ + +cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config); +cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config); +cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base); +cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base); + +/** \} group_prot_functions_ppu_sl */ + +/** +* \addtogroup group_prot_functions_ppu_rg +* \{ +*/ +cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config); +cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config); +cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base); +cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base); +cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base); + +/** \} group_prot_functions_ppu_rg */ + +/** \} group_prot_functions */ + +/** \} group_prot */ + +#if defined(__cplusplus) +} +#endif + +#endif /* CY_PROT_H */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/rtc/cy_rtc.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/rtc/cy_rtc.c similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/rtc/cy_rtc.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/rtc/cy_rtc.c index db0e9f3f6e..2c92da4226 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/rtc/cy_rtc.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/rtc/cy_rtc.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_rtc.c -* \version 2.0 +* \version 2.10 * * This file provides constants and parameter values for the APIs for the * Real-Time Clock (RTC). * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -523,7 +523,7 @@ cy_en_rtc_status_t Cy_RTC_SetDateAndTimeDirect(uint32_t sec, uint32_t min, uint3 curTimeAndDate.amPm = CY_RTC_AM; } } - curTimeAndDate.dayOfWeek = Cy_RTC_ConvertDayOfWeek(date, month, year); + curTimeAndDate.dayOfWeek = Cy_RTC_ConvertDayOfWeek(date, month, (year + CY_RTC_TWO_THOUSAND_YEARS)); curTimeAndDate.date = date; curTimeAndDate.month = month; curTimeAndDate.year = year; @@ -772,41 +772,47 @@ cy_en_rtc_status_t Cy_RTC_SetHoursFormat(cy_en_rtc_hours_format_t hoursFormat) * Function Name: Cy_RTC_SelectFrequencyPrescaler() ****************************************************************************//** * -* Selects the RTC pre-scaler value and changes its clock frequency. Under -* condition that the external 32.768 kHz WCO is absent on the board, the RTC can -* be driven by 32.768kHz square clock source or an external 50-Hz or 60-Hz +* Selects the RTC pre-scaler value and changes its clock frequency. +* If the external 32.768 kHz WCO is absent on the board, the RTC can +* be driven by a 32.768kHz square clock source or an external 50-Hz or 60-Hz * sine-wave clock source, for example the wall AC frequency. * * \param clkSel clock frequency, see \ref cy_en_rtc_clock_freq_t. * * In addition to generating the 32.768 kHz clock from external crystals, the WCO * can be sourced by an external clock source (50 Hz or 60Hz), even the wall AC -* frequency as a timebase, to drive the RTC using wco_out and wco_in pins. -* The API helps select between the RTC sources: -* * An 32.768 kHz digital clock source
+* frequency as a timebase. The API helps select between the RTC sources: +* * A 32.768 kHz digital clock source
* * An external 50-Hz or 60-Hz sine-wave clock source * * If you want to use an external 50-Hz or 60-Hz sine-wave clock source to -* drive the WCO, the next procedure is required:
+* drive the RTC, the next procedure is required:
* 1) Disable the WCO
-* 2) Drive the wco_out and wco_in pins to an external signal source*
-* 3) Call Cy_RTC_SelectFrequencyPrescaler(CY_RTC_FREQ_60_HZ) if you want to -* drive the WCO, for example, with 60 Hz source
-* 4) Enable the WCO
+* 2) Bypass the WCO using the Cy_SysClk_WcoBypass() function
+* 3) Configure both wco_out and wco_in pins. Note that only one of the wco pins +* should be driven and the other wco pin should be floating, which depends on +* the source that drives the RTC (*1)
+* 4) Call Cy_RTC_SelectFrequencyPrescaler(CY_RTC_FREQ_60_HZ), if you want to +* drive the WCO, for example, with a 60 Hz source
+* 5) Enable the WCO
* * If you want to use the WCO after using an external 50-Hz or 60-Hz sine-wave -* clock source:
+* clock source:
* 1) Disable the WCO
-* 2) Drive off wco_out and wco_in pins with external signal source
-* 3) Call Cy_RTC_SelectFrequencyPrescaler(CY_RTC_FREQ_WCO_32768_HZ)
-* 4) Enable the WCO
-* +* 2) Switch-off the WCO bypass using the Cy_SysClk_WcoBypass() function
+* 3) Drive off the wco pin with an external signal source
+* 4) Call Cy_RTC_SelectFrequencyPrescaler(CY_RTC_FREQ_WCO_32768_HZ)
+* 5) Enable the WCO
+* +* (1) - Refer to the device TRM to know how to configure the wco pins properly +* and which wco pin should be driven/floating. +* * \warning * There is a limitation to the external clock source frequencies. Only two * frequencies are allowed - 50 Hz or 60 Hz. Note that this limitation is related * to the RTC pre-scaling feature presented in this function. This * limitation is not related to WCO external clock sources which can drive the -* WCO in the bypass mode. +* WCO in Bypass mode. * *******************************************************************************/ void Cy_RTC_SelectFrequencyPrescaler(cy_en_rtc_clock_freq_t clkSel) @@ -897,6 +903,7 @@ cy_en_rtc_status_t Cy_RTC_SetNextDstTime(cy_stc_rtc_dst_format_t const *nextDst) dstAlarmTimeAndDate.minEn = CY_RTC_ALARM_ENABLE; dstAlarmTimeAndDate.hour = nextDst->hour; dstAlarmTimeAndDate.hourEn = CY_RTC_ALARM_ENABLE; + dstAlarmTimeAndDate.dayOfWeek = nextDst->dayOfWeek; dstAlarmTimeAndDate.dayOfWeekEn = CY_RTC_ALARM_DISABLE; /* Calculate a day-of-month value for the relative DST start structure */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/rtc/cy_rtc.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/rtc/cy_rtc.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/rtc/cy_rtc.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/rtc/cy_rtc.h index a7bf96f235..b136214e09 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/rtc/cy_rtc.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/rtc/cy_rtc.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_rtc.h -* \version 2.0 +* \version 2.10 * * This file provides constants and parameter values for the APIs for the * Real-Time Clock (RTC). * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -59,20 +59,20 @@ * therefore can run without vddd/vccd present. This can be used to wake the chip * from Hibernate mode. * -* * The Internal Low-speed Oscillator (ILO) routed from LFClk or directly +* * The Internal Low-speed Oscillator (ILO) routed from Clk_LF or directly * (as alternate backup domain clock source). Depending on the device power * mode the alternate backup domain clock source is set. For example, for -* DeepSleep mode the ILO is routed through LFClk. But for Hibernate +* DeepSleep mode the ILO is routed through Clk_LF. But for Hibernate * power mode the ILO is set directly. Note that, the ILO should be configured to -* work in the Hibernate mode. For more info refer to the System Clock -* (sysclk) driver. The ILO is a low-accuracy RC-oscillator that does not require +* work in the Hibernate mode. For more info refer to the \ref group_sysclk +* driver. The ILO is a low-accuracy RC-oscillator that does not require * any external elements on the board. Its poor accuracy (+/- 30%) means it is * less useful for the RTC. However, current can be supplied by an internal * power supply (Vback) and therefore it can run without Vddd/Vccd present. * This also can be used to wake the chip from Hibernate mode using RTC alarm * interrupt. For more details refer to Power Modes (syspm) driver description. * -* * The Precision Internal Low-speed Oscillator (PILO), routed from LFClk +* * The Precision Internal Low-speed Oscillator (PILO), routed from Clk_LF * (alternate backup domain clock source). This is an RC-oscillator (ILO) that * can achieve accuracy of +/- 2% with periodic calibration. It is not expected * to be accurate enough for good RTC capability. The PILO requires @@ -88,11 +88,11 @@ * * The WCO is the recommended clock source for the RTC, if it is present * in design. For setting the Backup domain clock source, refer to the -* System Clock (sysclk) driver. +* \ref group_sysclk driver. * * \note If the WCO is enabled, it should source the Backup domain directly. -* Do not route the WCO through the LFClk. This is because LFClk is not available -* in all low-power modes. +* Do not route the WCO through the Clk_LF. This is because Clk_LF is not +* available in all low-power modes. * * \section group_rtc_section_configuration Configuration Considerations * @@ -186,6 +186,17 @@ * * After the cy_stc_rtc_dst_t structure is filled, call Cy_RTC_EnableDstTime() * +* \section group_rtc_lp Low Power Support +* The RTC provides the callback functions to facilitate +* the low-power mode transition. The callback +* \ref Cy_RTC_DeepSleepCallback must be called during execution +* of \ref Cy_SysPm_DeepSleep; \ref Cy_RTC_HibernateCallback must be +* called during execution of \ref Cy_SysPm_Hibernate. +* To trigger the callback execution, the callback must be registered +* before calling the mode transition function. +* Refer to \ref group_syspm driver for more +* information about low-power mode transitions. +* * \section group_rtc_section_more_information More Information * * For more information on the RTC peripheral, refer to the technical reference @@ -222,13 +233,19 @@ * * * -* -* -* +* +* +* * * * -* * * +* +* +* +* +* *
VersionChangesReason for Change
1.0Initial version2.10 Corrected Cy_RTC_SetDateAndTimeDirect(), Cy_RTC_SetNextDstTime() +* function
+* Corrected internal macro
+* Documentation updates
Incorrect behavior of \ref Cy_RTC_SetDateAndTimeDirect() and +* \ref Cy_RTC_SetNextDstTime() work in debug mode
+* Debug assert correction in \ref Cy_RTC_ConvertDayOfWeek, +* \ref Cy_RTC_IsLeapYear, \ref Cy_RTC_DaysInMonth
2.0Enhancement and defect fixes:
+*
Enhancement and defect fixes:
* * Added input parameter(s) validation to all public functions.
* * Removed "Cy_RTC_" prefixes from the internal functions names.
* * Renamed the elements in the cy_stc_rtc_alarm structure.
@@ -237,6 +254,11 @@ *
1.0Initial version
* * \defgroup group_rtc_macros Macros @@ -250,7 +272,7 @@ * \defgroup group_rtc_low_power_functions Low Power Callbacks * \} * \defgroup group_rtc_data_structures Data Structures -* \defgroup group_rtc_enums Enumerated types +* \defgroup group_rtc_enums Enumerated Types */ #if !defined (_CY_RTC_H_) @@ -284,7 +306,7 @@ extern "C" { #define CY_RTC_DRV_VERSION_MAJOR 2 /** Driver minor version */ -#define CY_RTC_DRV_VERSION_MINOR 0 +#define CY_RTC_DRV_VERSION_MINOR 10 /** \} group_rtc_macros */ /******************************************************************************* @@ -782,7 +804,7 @@ extern uint8_t const cy_RTC_daysInMonthTbl[CY_RTC_MONTHS_PER_YEAR]; #define CY_RTC_IS_YEAR_SHORT_VALID(year) ((year) <= CY_RTC_MAX_YEAR) /* Internal macro to validate the year value in the Cy_RTC_ConvertDayOfWeek() */ -#define CY_RTC_IS_YEAR_LONG_VALID(year) (((year) >= CY_RTC_TWO_THOUSAND_YEARS) || \ +#define CY_RTC_IS_YEAR_LONG_VALID(year) (((year) >= CY_RTC_TWO_THOUSAND_YEARS) && \ ((year) <= CY_RTC_TWENTY_ONE_HUNDRED_YEARS)) /* Internal macro to validate RTC alarm parameter */ @@ -884,7 +906,7 @@ __STATIC_INLINE uint32_t Cy_RTC_ConvertDayOfWeek(uint32_t day, uint32_t month, u * function call. Leap year is identified as a year that is a multiple of 4 * or 400 but not 100. * -* \param year The year to be checked. +* \param year The year to be checked. Valid range - 2000...2100. * * \return * false - The year is not leap; true - The year is leap. @@ -910,7 +932,7 @@ __STATIC_INLINE bool Cy_RTC_IsLeapYear(uint32_t year) * * \param month The month of the year, see \ref group_rtc_month. * -* \param year A year value. +* \param year A year value. Valid range - 2000...2100. * * \return A number of days in a month in the year passed through the parameters. * diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sar/cy_sar.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sar/cy_sar.c similarity index 73% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sar/cy_sar.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sar/cy_sar.c index 3ad2c2fcee..4a3283fe45 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sar/cy_sar.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sar/cy_sar.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_sar.c -* \version 1.0 +* \version 1.10 * * Provides the public functions for the API for the SAR driver. * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -31,18 +31,23 @@ volatile int32_t Cy_SAR_countsPer10Volt[CY_SAR_MAX_NUM_CHANNELS]; ****************************************************************************//** * * Initialize all SAR configuration registers. -* If the enable data field of the config structure is true, -* a call to \ref Cy_SAR_Enable is made after all registers are initialized. +* If routing is to be configured, all switches will be cleared before +* being initialized. * * \param base * Pointer to structure describing registers * * \param config * Pointer to structure containing configuration data. See \ref cy_stc_sar_config_t +* and guidance in the \ref group_sar_initialization section. * -* \return cy_en_sar_status_t -* - CY_SAR_SUCCESS: initialization complete -* - CY_SAR_BAD_PARAM: input pointers are null, initialization incomplete +* \return +* - \ref CY_SAR_SUCCESS : initialization complete +* - \ref CY_SAR_BAD_PARAM : input pointers are null, initialization incomplete +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_INIT_CUSTOM * *******************************************************************************/ cy_en_sar_status_t Cy_SAR_Init(SAR_Type *base, const cy_stc_sar_config_t *config) @@ -67,13 +72,12 @@ cy_en_sar_status_t Cy_SAR_Init(SAR_Type *base, const cy_stc_sar_config_t *config CY_ASSERT_L2(CY_SAR_SAMPLE_CTRL(config->sampleCtrl)); CY_ASSERT_L2(CY_SAR_SAMPLE_TIME(config->sampleTime01)); CY_ASSERT_L2(CY_SAR_SAMPLE_TIME(config->sampleTime23)); - CY_ASSERT_L3(CY_SAR_LIMITCOND(config->rangeCond)); + CY_ASSERT_L3(CY_SAR_RANGECOND(config->rangeCond)); CY_ASSERT_L2(CY_SAR_CHANMASK(config->chanEn)); CY_ASSERT_L2(CY_SAR_INTRMASK(config->intrMask)); CY_ASSERT_L2(CY_SAR_CHANMASK(config->satIntrMask)); CY_ASSERT_L2(CY_SAR_CHANMASK(config->rangeIntrMask)); - base->CTRL = (config->ctrl & ~SAR_CTRL_ENABLED_Msk); base->SAMPLE_CTRL = config->sampleCtrl; base->SAMPLE_TIME01 = config->sampleTime01; base->SAMPLE_TIME23 = config->sampleTime23; @@ -119,16 +123,21 @@ cy_en_sar_status_t Cy_SAR_Init(SAR_Type *base, const cy_stc_sar_config_t *config CY_ASSERT_L2(CY_SAR_SWITCHMASK(config->muxSwitch)); CY_ASSERT_L2(CY_SAR_SQMASK(config->muxSwitchSqCtrl)); + /* Clear out all the switches so that only the desired switches in the config structure are set. */ + base->MUX_SWITCH_CLEAR0 = CY_SAR_CLEAR_ALL_SWITCHES; + base->MUX_SWITCH0 = config->muxSwitch; base->MUX_SWITCH_SQ_CTRL = config->muxSwitchSqCtrl; } - /* Write to the CTRL register last so that if the enable bit is set, - * it will be written last */ - if (true == config->enable) + /* Set the Cap trim if it was trimmed out of range from sflash */ + if ((CY_SAR_CAP_TRIM_MAX == base->ANA_TRIM0) || (CY_SAR_CAP_TRIM_MIN == base->ANA_TRIM0)) { - Cy_SAR_Enable(base); + base->ANA_TRIM0 = CY_SAR_CAP_TRIM; } + + /* Set the REFBUF_EN bit as this is required for proper operation. */ + base->CTRL = config->ctrl | SAR_CTRL_REFBUF_EN_Msk; result = CY_SAR_SUCCESS; } @@ -150,8 +159,13 @@ cy_en_sar_status_t Cy_SAR_Init(SAR_Type *base, const cy_stc_sar_config_t *config * If true, all SARMUX switches are opened and switch control registers are reset * to zero. If false, switch registers are untouched. * -* \return cy_en_sar_status_t -* CY_SAR_SUCCESS or CY_SAR_BAD_PARAM if input pointers are null +* \return +* - \ref CY_SAR_SUCCESS : de-initialization complete +* - \ref CY_SAR_BAD_PARAM : input pointers are null, de-initialization incomplete +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_DEINIT * *******************************************************************************/ cy_en_sar_status_t Cy_SAR_DeInit(SAR_Type *base, bool deInitRouting) @@ -197,7 +211,7 @@ cy_en_sar_status_t Cy_SAR_DeInit(SAR_Type *base, bool deInitRouting) * Function Name: Cy_SAR_Enable ****************************************************************************//** * -* Powers up the SAR ADC subsystem block. The hardware is ready to use +* Power up the SAR ADC subsystem block. The hardware is ready to use * after 2 us, which is included in this function. * * \param base @@ -226,18 +240,23 @@ void Cy_SAR_Enable(SAR_Type *base) * Function Name: Cy_SAR_Sleep ****************************************************************************//** * -* This is the preferred routine to prepare the hardware for sleep. -* It will stop continuous conversions, if enabled. Once the SAR BUSY bit is low, -* the hardware block will be turned off. The reference buffer (REFBUF) will -* also be disabled. +* This is the preferred routine to prepare the hardware for Deep sleep. * -* Call this function before putting the device into Deep Sleep mode. +* It will call \ref Cy_SAR_StopConvert to disable continuous conversions +* and wait for SAR conversions to stop before entering Deep Sleep. +* If the SARMUX is not configured for Deep Sleep operation, the entire SAR hardware +* block will be turned off. * * \param base * Pointer to structure describing registers * * \return None * +* \funcusage +* +* This function is used in the \ref Cy_SAR_DeepSleepCallback. There is no +* need to call this function directly. +* *******************************************************************************/ void Cy_SAR_Sleep(SAR_Type *base) { @@ -261,7 +280,12 @@ void Cy_SAR_Sleep(SAR_Type *base) /* Wait for SAR to stop conversions before entering low power */ } - ctrlReg &= ~SAR_CTRL_ENABLED_Msk; + /* Turn off the entire hardware block only if the SARMUX is not + * enabled for Deep Sleep operation. */ + if (SAR_CTRL_DEEPSLEEP_ON_Msk != (ctrlReg & SAR_CTRL_DEEPSLEEP_ON_Msk)) + { + base->CTRL &= ~SAR_CTRL_ENABLED_Msk; + } } base->CTRL = ctrlReg; @@ -273,7 +297,7 @@ void Cy_SAR_Sleep(SAR_Type *base) * * This is the preferred routine to restore the hardware to the state after calling * \ref Cy_SAR_Sleep. Restoring the hardware involves re-enabling the hardware, -* the reference buffer, and start continuous scanning if it was previously +* the reference buffer, and continuous scanning if it was previously * enabled before entering sleep. * * \param base @@ -285,6 +309,11 @@ void Cy_SAR_Sleep(SAR_Type *base) * * \return None * +* \funcusage +* +* This function is used in the \ref Cy_SAR_DeepSleepCallback. There is no +* need to call this function directly. +* *******************************************************************************/ void Cy_SAR_Wakeup(SAR_Type *base) { @@ -318,6 +347,10 @@ void Cy_SAR_Wakeup(SAR_Type *base) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_START_CONVERT +* *******************************************************************************/ void Cy_SAR_StartConvert(SAR_Type *base, cy_en_sar_start_convert_sel_t startSelect) { @@ -339,7 +372,7 @@ void Cy_SAR_StartConvert(SAR_Type *base, cy_en_sar_start_convert_sel_t startSele * Function Name: Cy_SAR_StopConvert ****************************************************************************//** * -* Stops continuous scanning of enabled channels. +* Stop continuous scanning of enabled channels. * If a conversion is currently executing, that conversion will complete, * but no further conversions will occur until the next call to * \ref Cy_SAR_StartConvert or the next hardware trigger, if enabled. @@ -349,6 +382,10 @@ void Cy_SAR_StartConvert(SAR_Type *base, cy_en_sar_start_convert_sel_t startSele * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_STOP_CONVERT +* *******************************************************************************/ void Cy_SAR_StopConvert(SAR_Type *base) { @@ -362,13 +399,15 @@ void Cy_SAR_StopConvert(SAR_Type *base) * Function Name: Cy_SAR_SetConvertMode ****************************************************************************//** * -* Sets the mode in which conversions are triggered. This function does +* Set the mode in which conversions are triggered. This function does * not start any conversions; it only configures the mode for subsequent conversions. +* * There are three modes: * - firmware only; hardware triggering is disabled * - firmware and edge sensitive hardware triggering * - firmware and level sensitive hardware triggering -* Notice that firmware triggering is always enabled. +* +* Note that firmware triggering is always enabled. * * \param base * Pointer to structure describing registers @@ -378,6 +417,10 @@ void Cy_SAR_StopConvert(SAR_Type *base) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm4.c SAR_SNIPPET_SET_CONVERT_MODE +* *******************************************************************************/ void Cy_SAR_SetConvertMode(SAR_Type *base, cy_en_sar_sample_ctrl_trigger_mode_t mode) { @@ -393,7 +436,7 @@ void Cy_SAR_SetConvertMode(SAR_Type *base, cy_en_sar_sample_ctrl_trigger_mode_t * Function Name: Cy_SAR_IsEndConversion ****************************************************************************//** * -* Immediately returns the status of the conversion or does not return (blocking) +* Immediately return the status of the conversion or does not return (blocking) * until the conversion completes, depending on the retMode parameter. * In blocking mode, there is a time out of about 10 seconds for a CPU speed of * 100 MHz. @@ -404,13 +447,18 @@ void Cy_SAR_SetConvertMode(SAR_Type *base, cy_en_sar_sample_ctrl_trigger_mode_t * \param retMode * A value of the enum \ref cy_en_sar_return_mode_t * -* \return cy_en_sar_status_t -* - CY_SAR_SUCCESS: the last conversion is complete -* - CY_SAR_CONVERSION_NOT_COMPLETE: the conversion has not completed -* - CY_SAR_TIMEOUT: the watchdog timer has expired in blocking mode +* \return +* - \ref CY_SAR_SUCCESS : the last conversion is complete +* - \ref CY_SAR_CONVERSION_NOT_COMPLETE : the conversion has not completed +* - \ref CY_SAR_TIMEOUT : the watchdog timer has expired in blocking mode +* +* \sideeffect +* This function reads the end of conversion status and clears it after. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_IS_END_CONVERSION * -* \sideeffect This function reads the end of conversion status and clears -* it after. *******************************************************************************/ cy_en_sar_status_t Cy_SAR_IsEndConversion(SAR_Type *base, cy_en_sar_return_mode_t retMode) { @@ -459,7 +507,7 @@ cy_en_sar_status_t Cy_SAR_IsEndConversion(SAR_Type *base, cy_en_sar_return_mode_ * Function Name: Cy_SAR_IsChannelSigned ****************************************************************************//** * -* Returns true if channel result is configured for signed format, else false. +* Return true if channel result is configured for signed format, else false. * The formats for single-ended and differential channels are independent. * This function will first check whether the channel is single-ended or differential. * @@ -467,11 +515,15 @@ cy_en_sar_status_t Cy_SAR_IsEndConversion(SAR_Type *base, cy_en_sar_return_mode_ * Pointer to structure describing registers * * \param chan -* The channel to check, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel to check, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * -* \return bool +* \return * If channel number is invalid, false is returned * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_IS_CHANNEL_SIGNED +* *******************************************************************************/ bool Cy_SAR_IsChannelSigned(const SAR_Type *base, uint32_t chan) { @@ -506,17 +558,21 @@ bool Cy_SAR_IsChannelSigned(const SAR_Type *base, uint32_t chan) * Function Name: Cy_SAR_IsChannelSingleEnded ****************************************************************************//** * -* Returns true if channel is single ended, else false +* Return true if channel is single ended, else false * * \param base * Pointer to structure describing registers * * \param chan -* The channel to check, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel to check, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * -* \return bool +* \return * If channel number is invalid, false is returned * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_IS_CHANNEL_SE +* *******************************************************************************/ bool Cy_SAR_IsChannelSingleEnded(const SAR_Type *base, uint32_t chan) { @@ -538,19 +594,23 @@ bool Cy_SAR_IsChannelSingleEnded(const SAR_Type *base, uint32_t chan) * Function Name: Cy_SAR_GetResult16 ****************************************************************************//** * -* Gets the data available in the channel result data register as a signed +* Return the data available in the channel result data register as a signed * 16-bit integer. * * \param base * Pointer to structure describing registers * * \param chan -* The channel to read the result from, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel to read the result from, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * -* \return int16_t +* \return * Data is returned as a signed 16-bit integer. * If channel number is invalid, 0 is returned. * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_RESULT16 +* *******************************************************************************/ int16_t Cy_SAR_GetResult16(const SAR_Type *base, uint32_t chan) { @@ -570,19 +630,23 @@ int16_t Cy_SAR_GetResult16(const SAR_Type *base, uint32_t chan) * Function Name: Cy_SAR_GetResult32 ****************************************************************************//** * -* Gets the data available in the channel result data register as a signed +* Return the data available in the channel result data register as a signed * 32-bit integer. * * \param base * Pointer to structure describing registers * * \param chan -* The channel to read the result from, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel to read the result from, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * -* \return int16_t +* \return * Data is returned as a signed 32-bit integer. * If channel number is invalid, 0 is returned. * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_RESULT32 +* *******************************************************************************/ int32_t Cy_SAR_GetResult32(const SAR_Type *base, uint32_t chan) { @@ -614,7 +678,7 @@ int32_t Cy_SAR_GetResult32(const SAR_Type *base, uint32_t chan) * Function Name: Cy_SAR_SetLowLimit ****************************************************************************//** * -* Sets the low threshold for range detection. The values are interpreted +* Set the low threshold for range detection. The values are interpreted * as signed or unsigned according to the channel configuration. Range * detection is done on the value stored in the result register. That is, after * averaging, shifting sign extension, and left/right alignment. @@ -627,10 +691,14 @@ int32_t Cy_SAR_GetResult32(const SAR_Type *base, uint32_t chan) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SET_LOWHIGH_LIMIT +* *******************************************************************************/ void Cy_SAR_SetLowLimit(SAR_Type *base, uint32_t lowLimit) { - CY_ASSERT_L2(CY_SAR_LIMIT(lowLimit)); + CY_ASSERT_L2(CY_SAR_RANGE_LIMIT(lowLimit)); uint32_t rangeThresReg; @@ -644,7 +712,7 @@ void Cy_SAR_SetLowLimit(SAR_Type *base, uint32_t lowLimit) * Function Name: Cy_SAR_SetHighLimit ****************************************************************************//** * -* Sets the high threshold for range detection. The values are interpreted +* Set the high threshold for range detection. The values are interpreted * as signed or unsigned according to the channel configuration. Range * detection is done on the value stored in the result register. That is, after * averaging, shifting sign extension, and left/right alignment. @@ -657,10 +725,14 @@ void Cy_SAR_SetLowLimit(SAR_Type *base, uint32_t lowLimit) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SET_LOWHIGH_LIMIT +* *******************************************************************************/ void Cy_SAR_SetHighLimit(SAR_Type *base, uint32_t highLimit) { - CY_ASSERT_L2(CY_SAR_LIMIT(highLimit)); + CY_ASSERT_L2(CY_SAR_RANGE_LIMIT(highLimit)); uint32_t rangeThresReg; @@ -673,27 +745,26 @@ void Cy_SAR_SetHighLimit(SAR_Type *base, uint32_t highLimit) * Function Name: Cy_SAR_SetOffset ****************************************************************************//** * -* Sets the offset that is used by the functions \ref Cy_SAR_CountsTo_uVolts, -* \ref Cy_SAR_CountsTo_mVolts, and \ref Cy_SAR_CountsTo_Volts. +* Override the channel offset stored in the \ref Cy_SAR_offset array +* for the voltage conversion functions. * -* Offset is applied to counts before unit scaling and gain. All CountsTo_[mV, uV, V]olts() -* functions use the following equation: -* V = (Counts/AvgDivider - Offset)*TEN_VOLT/Gain +* Offset is applied to counts before unit scaling and gain. * See \ref Cy_SAR_CountsTo_Volts for more about this formula. * -* To set channel 0's offset based on known V_offset_mV, use: -* Cy_SAR_SetOffset(0uL, -1 * V_offset_mV * (1uL << (Resolution - 1)) / V_ref_mV); +* To change channel 0's offset based on a known V_offset_mV, use: +* +* Cy_SAR_SetOffset(0uL, -1 * V_offset_mV * (1uL << Resolution) / (2 * V_ref_mV)); * * \param chan -* The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1. +* The channel number, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1. * * \param offset -* This value is a measured value when the inputs are shorted or +* The count value measured when the inputs are shorted or * connected to the same input voltage. * -* \return cy_en_sar_status_t -* - CY_SAR_BAD_PARAM: channel number is equal to or greater than CY_SAR_MAX_NUM_CHANNELS -* - CY_SAR_SUCCESS: offset was set successfully +* \return +* - \ref CY_SAR_SUCCESS : offset was set successfully +* - \ref CY_SAR_BAD_PARAM : channel number is equal to or greater than \ref CY_SAR_MAX_NUM_CHANNELS * *******************************************************************************/ cy_en_sar_status_t Cy_SAR_SetOffset(uint32_t chan, int16_t offset) @@ -715,25 +786,26 @@ cy_en_sar_status_t Cy_SAR_SetOffset(uint32_t chan, int16_t offset) * Function Name: Cy_SAR_SetGain ****************************************************************************//** * -* Sets the gain in counts per 10 volt for the voltage conversion functions. -* This value is set by default by the reference and -* input range settings. Gain is applied after offset and unit scaling. All -* CountsTo_[mV, uV, V]olts() functions use the following equation: -* V = (Counts/AvgDivider - Offset)*TEN_VOLT/Gain +* Override the gain stored in the \ref Cy_SAR_countsPer10Volt array for the voltage conversion functions. +* The gain is configured at initialization in \ref Cy_SAR_Init +* based on the SARADC resolution and voltage reference. +* +* Gain is applied after offset and unit scaling. * See \ref Cy_SAR_CountsTo_Volts for more about this formula. * -* To set channel 0's gain based on known V_ref_mV, use: -* Cy_SAR_SetGain(0uL, 10000 * (1uL << (Resolution - 1)) / V_ref_mV); +* To change channel 0's gain based on a known V_ref_mV, use: +* +* Cy_SAR_SetGain(0uL, 10000 * (1uL << Resolution) / (2 * V_ref_mV)); * * \param chan -* The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1. +* The channel number, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1. * * \param adcGain * The gain in counts per 10 volt. * -* \return cy_en_sar_status_t -* - CY_SAR_BAD_PARAM: channel number is equal to or greater than CY_SAR_MAX_NUM_CHANNELS -* - CY_SAR_SUCCESS: gain was set successfully +* \return +* - \ref CY_SAR_SUCCESS : gain was set successfully +* - \ref CY_SAR_BAD_PARAM : channel number is equal to or greater than \ref CY_SAR_MAX_NUM_CHANNELS * *******************************************************************************/ cy_en_sar_status_t Cy_SAR_SetGain(uint32_t chan, int32_t adcGain) @@ -755,16 +827,26 @@ cy_en_sar_status_t Cy_SAR_SetGain(uint32_t chan, int32_t adcGain) * Function Name: Cy_SAR_RawCounts2Counts ****************************************************************************//** * -* Converts the channel result to a consistent result after accounting for +* Convert the channel result to a consistent result after accounting for * averaging and subtracting the offset. -* If using interleaved or sequential accumulate and dump, -* the channel result will be divided by the averaging amount. +* The equation used is: +* +* Counts = (RawCounts/AvgDivider - Offset) +* +* where, +* - RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register +* - AvgDivider: divider based on averaging mode (\ref cy_en_sar_sample_ctrl_avg_mode_t) and number of samples averaged +* (\ref cy_en_sar_sample_ctrl_avg_cnt_t) +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM : AvgDivider is the number of samples averaged or 16, whichever is smaller +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_FIXED : AvgDivider is 1 +* - \ref CY_SAR_AVG_MODE_INTERLEAVED : AvgDivider is the number of samples averaged +* - Offset: Value from \ref Cy_SAR_offset * * \param base * Pointer to structure describing registers * * \param chan -* The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel number, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * * \param adcCounts * Conversion result from \ref Cy_SAR_GetResult16 @@ -773,6 +855,12 @@ cy_en_sar_status_t Cy_SAR_SetGain(uint32_t chan, int32_t adcGain) * adcCounts after averaging and offset adjustments. * If channel number is invalid, adcCounts is returned unmodified. * +* \funcusage +* +* This function is used by \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, +* and \ref Cy_SAR_CountsTo_uVolts. Calling this function directly is usually +* not needed. +* *******************************************************************************/ int16_t Cy_SAR_RawCounts2Counts(const SAR_Type *base, uint32_t chan, int16_t adcCounts) { @@ -829,37 +917,45 @@ int16_t Cy_SAR_RawCounts2Counts(const SAR_Type *base, uint32_t chan, int16_t adc * Function Name: Cy_SAR_CountsTo_Volts ****************************************************************************//** * -* Converts the ADC output to Volts as a float32. For example, if the ADC +* Convert the ADC output to Volts as a float32. For example, if the ADC * measured 0.534 volts, the return value would be 0.534. * The calculation of voltage depends on the contents of \ref Cy_SAR_offset, * \ref Cy_SAR_countsPer10Volt, and other parameters. * The equation used is: * -* V = (Counts/AvgDivider - Offset)*TEN_VOLT/Gain +* V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain * -* -Counts = Raw Counts from SAR register -* -AvgDivider = divider based on averaging mode -* -Sequential, Sum: AvgDivider = number averaged -* Note: The divider should be a maximum of 16. If using more averages, -* pre-scale Counts by (number averaged / 16) -* -Interleaved, Sum: AvgDivider = number averaged -* -Sequential, Fixed: AvgDivider = 1 -* -Offset = Value from \ref Cy_SAR_offset -* -TEN_VOLT = 10 V constant and unit scalar. -* -Gain = Value from \ref Cy_SAR_countsPer10Volt +* where, +* - RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register +* - AvgDivider: divider based on averaging mode (\ref cy_en_sar_sample_ctrl_avg_mode_t) and number of samples averaged +* (\ref cy_en_sar_sample_ctrl_avg_cnt_t) +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM : AvgDivider is the number of samples averaged or 16, whichever is smaller +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_FIXED : AvgDivider is 1 +* - \ref CY_SAR_AVG_MODE_INTERLEAVED : AvgDivider is the number of samples averaged +* - Offset: Value from \ref Cy_SAR_offset +* - TEN_VOLT: 10 V constant since the gain is in counts per 10 volts. +* - Gain: Value from \ref Cy_SAR_countsPer10Volt +* +* \note +* This funtion is only valid when result alignment is right aligned. * * \param base * Pointer to structure describing registers * * \param chan -* The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel number, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * * \param adcCounts * Conversion result from \ref Cy_SAR_GetResult16 * * \return * Result in Volts. -* If channel number is invalid, 0 is returned. +* - If channel number is invalid, 0 is returned. +* - If channel is left aligned, 0 is returned. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_COUNTSTO_VOLTS * *******************************************************************************/ float32_t Cy_SAR_CountsTo_Volts(const SAR_Type *base, uint32_t chan, int16_t adcCounts) @@ -886,37 +982,46 @@ float32_t Cy_SAR_CountsTo_Volts(const SAR_Type *base, uint32_t chan, int16_t adc * Function Name: Cy_SAR_CountsTo_mVolts ****************************************************************************//** * -* Converts the ADC output to millivolts as an int16. For example, if the ADC +* Convert the ADC output to millivolts as an int16. For example, if the ADC * measured 0.534 volts, the return value would be 534. * The calculation of voltage depends on the contents of \ref Cy_SAR_offset, * \ref Cy_SAR_countsPer10Volt, and other parameters. * The equation used is: * -* V = (Counts/AvgDivider - Offset)*TEN_VOLT/Gain +* V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain +* mV = V * 1000 * -* -Counts = Raw Counts from SAR register -* -AvgDivider = divider based on averaging mode -* -Sequential, Sum: AvgDivider = number averaged -* Note: The divider should be a maximum of 16. If using more averages, -* pre-scale Counts by (number averaged / 16) -* -Interleaved, Sum: AvgDivider = number averaged -* -Sequential, Fixed: AvgDivider = 1 -* -Offset = Value from \ref Cy_SAR_offset -* -TEN_VOLT = 10V constant and unit scalar -* -Gain = Value from \ref Cy_SAR_countsPer10Volt +* where, +* - RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register +* - AvgDivider: divider based on averaging mode (\ref cy_en_sar_sample_ctrl_avg_mode_t) and number of samples averaged +* (\ref cy_en_sar_sample_ctrl_avg_cnt_t) +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM : AvgDivider is the number of samples averaged or 16, whichever is smaller +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_FIXED : AvgDivider is 1 +* - \ref CY_SAR_AVG_MODE_INTERLEAVED : AvgDivider is the number of samples averaged +* - Offset: Value from \ref Cy_SAR_offset +* - TEN_VOLT: 10 V constant since the gain is in counts per 10 volts. +* - Gain: Value from \ref Cy_SAR_countsPer10Volt +* +* \note +* This funtion is only valid when result alignment is right aligned. * * \param base * Pointer to structure describing registers * * \param chan -* The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel number, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * * \param adcCounts * Conversion result from \ref Cy_SAR_GetResult16 * * \return * Result in millivolts. -* If channel number is invalid, 0 is returned. +* - If channel number is invalid, 0 is returned. +* - If channel is left aligned, 0 is returned. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_COUNTSTO_MVOLTS * *******************************************************************************/ int16_t Cy_SAR_CountsTo_mVolts(const SAR_Type *base, uint32_t chan, int16_t adcCounts) @@ -951,37 +1056,46 @@ int16_t Cy_SAR_CountsTo_mVolts(const SAR_Type *base, uint32_t chan, int16_t adcC * Function Name: Cy_SAR_CountsTo_uVolts ****************************************************************************//** * -* Converts the ADC output to microvolts as a int32. For example, if the ADC +* Convert the ADC output to microvolts as a int32. For example, if the ADC * measured 0.534 volts, the return value would be 534000. * The calculation of voltage depends on the contents of \ref Cy_SAR_offset, * \ref Cy_SAR_countsPer10Volt, and other parameters. * The equation used is: * -* V = (Counts/AvgDivider - Offset)*TEN_VOLT/Gain +* V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain +* uV = V * 1000000 * -* -Counts = Raw Counts from SAR register -* -AvgDivider = divider based on averaging mode -* -Sequential, Sum: AvgDivider = number averaged -* Note: The divider should be a maximum of 16. If using more averages, -* pre-scale Counts by (number averaged / 16) -* -Interleaved, Sum: AvgDivider = number averaged -* -Sequential, Fixed: AvgDivider = 1 -* -Offset = Value from \ref Cy_SAR_offset -* -TEN_VOLT = 10V constant and unit scalar. -* -Gain = Value from \ref Cy_SAR_countsPer10Volt +* where, +* - RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register +* - AvgDivider: divider based on averaging mode (\ref cy_en_sar_sample_ctrl_avg_mode_t) and number of samples averaged +* (\ref cy_en_sar_sample_ctrl_avg_cnt_t) +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM : AvgDivider is the number of samples averaged or 16, whichever is smaller +* - \ref CY_SAR_AVG_MODE_SEQUENTIAL_FIXED : AvgDivider is 1 +* - \ref CY_SAR_AVG_MODE_INTERLEAVED : AvgDivider is the number of samples averaged +* - Offset: Value from \ref Cy_SAR_offset +* - TEN_VOLT: 10 V constant since the gain is in counts per 10 volts. +* - Gain: Value from \ref Cy_SAR_countsPer10Volt +* +* \note +* This funtion is only valid when result alignment is right aligned. * * \param base * Pointer to structure describing registers * * \param chan -* The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 +* The channel number, between 0 and \ref CY_SAR_MAX_NUM_CHANNELS - 1 * * \param adcCounts * Conversion result from \ref Cy_SAR_GetResult16 * * \return * Result in microvolts. -* If channel number is valid, 0 is returned. +* - If channel number is valid, 0 is returned. +* - If channel is left aligned, 0 is returned. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_COUNTSTO_UVOLTS * *******************************************************************************/ int32_t Cy_SAR_CountsTo_uVolts(const SAR_Type *base, uint32_t chan, int16_t adcCounts) @@ -1007,32 +1121,33 @@ int32_t Cy_SAR_CountsTo_uVolts(const SAR_Type *base, uint32_t chan, int16_t adcC * Function Name: Cy_SAR_SetAnalogSwitch ****************************************************************************//** * -* Provides firmware control of the SARMUX switches. Each call to this function -* can open a set of switches or close a set of switches. +* Provide firmware control of the SARMUX switches for firmware sequencing. +* Each call to this function can open or close a set of switches. +* Previously configured switches are untouched. * -* When the SAR sequencer is controlling the SARMUX switches, -* there is no need to use this function. +* If the SARSEQ is enabled, there is no need to use this function. * * \param base * Pointer to structure describing registers * * \param switchSelect -* A value of the enum \ref cy_en_sar_switch_register_sel_t to select the switch -* register +* The switch register that contains the desired switches. Select a value +* from \ref cy_en_sar_switch_register_sel_t. * * \param switchMask * The mask of the switches to either open or close. -* The switches can be found in the \ref cy_en_sar_mux_switch_fw_ctrl_t enum. -* -* For example, to control the switch between SARMUX P0 and Vplus and the switch between SARMUX P1 and Vminus, -* call this function with: -* switchMask = CY_SAR_MUX_FW_P0_VPLUS | CY_SAR_MUX_FW_P1_VMINUS; +* Select one or more values from the \ref cy_en_sar_mux_switch_fw_ctrl_t enum +* and "OR" them together. * * \param state -* A value of the enum \ref cy_en_sar_switch_state_t. +* Open or close the desired swithces. Select a value from \ref cy_en_sar_switch_state_t. * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm4.c SAR_SNIPPET_SET_ANALOG_SWITCH +* *******************************************************************************/ void Cy_SAR_SetAnalogSwitch(SAR_Type *base, cy_en_sar_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_sar_switch_state_t state) { @@ -1060,7 +1175,7 @@ void Cy_SAR_SetAnalogSwitch(SAR_Type *base, cy_en_sar_switch_register_sel_t swit case CY_SAR_SWITCH_OPEN: default: - /** Unlike the close case, we are not OR'ing the register. Set 1 to clear.*/ + /* Unlike the close case, we are not OR'ing the register. Set 1 to clear.*/ *switchClearReg = switchMask; break; } @@ -1070,19 +1185,19 @@ void Cy_SAR_SetAnalogSwitch(SAR_Type *base, cy_en_sar_switch_register_sel_t swit * Function Name: Cy_SAR_GetAnalogSwitch ****************************************************************************//** * -* Gets the state (open or close) of SARMUX switches as a uint32_t value. +* Return the state (open or close) of SARMUX switches. * * \param base * Pointer to structure describing registers * * \param switchSelect -* A value of the enum \ref cy_en_sar_switch_register_sel_t to select the switch -* register +* The switch register that contains the desired switches. Select a value +* from \ref cy_en_sar_switch_register_sel_t. * -* \return uint32_t +* \return * Each bit corresponds to a single switch, where a bit value of 0 is open * and 1 is closed. -* The switch masks can be found in the \ref cy_en_sar_mux_switch_fw_ctrl_t enum. +* Compare this value to the switch masks in \ref cy_en_sar_mux_switch_fw_ctrl_t. * *******************************************************************************/ uint32_t Cy_SAR_GetAnalogSwitch(const SAR_Type *base, cy_en_sar_switch_register_sel_t switchSelect) @@ -1106,31 +1221,26 @@ uint32_t Cy_SAR_GetAnalogSwitch(const SAR_Type *base, cy_en_sar_switch_register_ * Function Name: Cy_SAR_SetSwitchSarSeqCtrl ****************************************************************************//** * -* Sets which switches are controlled by the SAR sequencer. +* Enable or disable SARSEQ control of one or more switches. +* Previously configured switches are untouched. * * \param base * Pointer to structure describing registers * * \param switchMask * The mask of the switches. -* The switches can be found in the \ref cy_en_sar_mux_switch_sq_ctrl_t enum. -* For example, to give control of all SARMUX pin switches to the sequencer, -* call this function with: -* switchMask = CY_SAR_MUX_SQ_CTRL_P0 | \ -* CY_SAR_MUX_SQ_CTRL_P1 | \ -* CY_SAR_MUX_SQ_CTRL_P2 | \ -* CY_SAR_MUX_SQ_CTRL_P3 | \ -* CY_SAR_MUX_SQ_CTRL_P4 | \ -* CY_SAR_MUX_SQ_CTRL_P5 | \ -* CY_SAR_MUX_SQ_CTRL_P6 | \ -* CY_SAR_MUX_SQ_CTRL_P7; -* ctrl = CY_SAR_SWITCH_SEQ_CTRL_ENABLE; +* Select one or more values from the \ref cy_en_sar_mux_switch_sq_ctrl_t enum +* and "OR" them together. * * \param ctrl -* A value of the enum \ref cy_en_sar_switch_sar_seq_ctrl_t. +* Enable or disable SARSEQ control. Select a value from \ref cy_en_sar_switch_sar_seq_ctrl_t. * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm4.c SAR_SNIPPET_SET_SWITCH_SAR_SEQ_CTRL +* *******************************************************************************/ void Cy_SAR_SetSwitchSarSeqCtrl(SAR_Type *base, uint32_t switchMask, cy_en_sar_switch_sar_seq_ctrl_t ctrl) { @@ -1159,9 +1269,13 @@ void Cy_SAR_SetSwitchSarSeqCtrl(SAR_Type *base, uint32_t switchMask, cy_en_sar_s * \param callbackParams * Pointer to structure of type \ref cy_stc_syspm_callback_params_t * -* \return cy_en_syspm_status_t +* \return * See \ref cy_en_syspm_status_t * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_DEEPSLEEP_CALLBACK +* *******************************************************************************/ cy_en_syspm_status_t Cy_SAR_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sar/cy_sar.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sar/cy_sar.h similarity index 56% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sar/cy_sar.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sar/cy_sar.h index be52f5a5c2..1f9120a59e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sar/cy_sar.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sar/cy_sar.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_sar.h -* \version 1.0 +* \version 1.10 * * Header file for the SAR driver. * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -19,50 +19,227 @@ * * This SAR ADC subsystem is comprised of: * - a 12-bit SAR converter (SARADC) -* - an embedded reference buffer (REFBUF) -* - a mux (SARMUX) at the inputs of the converter -* - a sequence controller (SARSEQ) that enables multi-channel acquisition +* - an embedded reference block (SARREF) +* - a mux (\ref group_sar_sarmux "SARMUX") at the inputs of the converter +* - a sequence controller (\ref group_sar_sarmux "SARSEQ") that enables multi-channel acquisition * in a round robin fashion, without CPU intervention, to maximize scan rates. * * \image html sar_block_diagram.png * * The high level features of the subsystem are: * - maximum sample rate of 1 Msps -* - multiple individually configurable channels (8, 12, or 16 depending on the device) +* - Sixteen individually configurable channels (depends on device routing capabilities) * - per channel selectable +* - single-ended or differential input mode +* - input from external pin (8 channels in single-ended mode or 4 channels in differential mode) +* or from internal signals (AMUXBUS, CTB, Die Temperature Sensor) * - choose one of four programmable acquisition times -* - single-ended and differential input mode * - averaging and accumulation * - scan can be triggered by firmware or hardware in single shot or continuous mode * - hardware averaging from 2 to 256 samples -* - selectable voltage references (Vdda, Vdda/2, analog reference, or external) +* - selectable voltage references +* - internal VDDA and VDDA/2 references +* - buffered 1.2 V bandgap reference from \ref group_sysanalog "AREF" +* - external reference from dedicated pin * - Interrupt generation * * \section group_sar_usage Usage * -* This section will go through the high level steps of using this driver with some example code. +* The high level steps to use this driver are: * -* High level usage flow: +* -# \ref group_sar_initialization +* -# \ref group_sar_trigger_conversions +* -# \ref group_sar_handle_interrupts +* -# \ref group_sar_retrieve_result * -* - Initialize the hardware -* - Enable the hardware -* - Trigger conversions -* - Wait for conversion to complete -* - Retrieve channel results -* -* Initialization +* \section group_sar_initialization Initialization and Enable * * To configure the SAR subsystem, call \ref Cy_SAR_Init. Pass in a pointer to the \ref SAR_Type * structure for the base hardware register address and pass in the configuration structure, -* \ref cy_stc_sar_config_t. This initializes the SAR subsystem. +* \ref cy_stc_sar_config_t. * -* Enable +* After initialization, call \ref Cy_SAR_Enable to enable the hardware. * -* If the \ref cy_stc_sar_config_t.enable field of the configuration structure is set to true -* during initialization, the hardware will be enabled after initialization. -* If set to false, a call to \ref Cy_SAR_Enable is required to enable the hardware. +* Here is guidance on how to set the data fields of the configuration structure: * -* Triggering conversions +* \subsection group_sar_init_struct_ctrl uint32_t ctrl +* +* This field specifies configurations that apply to all channels such as the Vref +* source or the negative terminal selection for all single-ended channels. +* Select a value from each of the following enums that begin with "cy_en_sar_ctrl_" and "OR" them together. +* - \ref cy_en_sar_ctrl_pwr_ctrl_vref_t +* - \ref cy_en_sar_ctrl_vref_sel_t +* - \ref cy_en_sar_ctrl_bypass_cap_t +* - \ref cy_en_sar_ctrl_neg_sel_t +* - \ref cy_en_sar_ctrl_hw_ctrl_negvref_t +* - \ref cy_en_sar_ctrl_comp_delay_t +* - \ref cy_en_sar_ctrl_comp_pwr_t +* - \ref cy_en_sar_ctrl_sarmux_deep_sleep_t +* - \ref cy_en_sar_ctrl_sarseq_routing_switches_t +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SAR_CTRL +* +* \subsection group_sar_init_struct_sampleCtrl uint32_t sampleCtrl +* +* This field configures sampling details that apply to all channels. +* Select a value from each of the following enums that begin with "cy_en_sar_sample_" and "OR" them together. +* - \ref cy_en_sar_sample_ctrl_result_align_t +* - \ref cy_en_sar_sample_ctrl_single_ended_format_t +* - \ref cy_en_sar_sample_ctrl_differential_format_t +* - \ref cy_en_sar_sample_ctrl_avg_cnt_t +* - \ref cy_en_sar_sample_ctrl_avg_mode_t +* - \ref cy_en_sar_sample_ctrl_trigger_mode_t +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SAMPLE_CTRL +* +* \subsection group_sar_init_struct_sampleTime01 uint32_t sampleTime01 +* +* This field configures the value for sample times 0 and 1 in ADC clock cycles. +* +* The SAR has four programmable 10-bit aperture times that are configured using two data fields, +* \ref group_sar_init_struct_sampleTime01 and +* \ref group_sar_init_struct_sampleTime23. +* Ten bits allow for a range of 0 to 1023 cycles, however 0 and 1 are invalid. +* The minimum aperture time is 167 ns. With an 18 MHz ADC clock, this is +* equal to 3 cycles or a value of 4 in this field. The actual aperture time is one cycle less than +* the value stored in this field. +* +* Use the shifts defined in \ref cy_en_sar_sample_time_shift_t. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SAMPLE_TIME01 +* +* \subsection group_sar_init_struct_sampleTime23 uint32_t sampleTime23 +* +* This field configures the value for sample times 2 and 3 in ADC clock cycles. +* Use the shifts defined in \ref cy_en_sar_sample_time_shift_t. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SAMPLE_TIME23 +* +* \subsection group_sar_init_struct_rangeThres uint32_t rangeThres +* +* This field configures the upper and lower thresholds for the range interrupt. +* These thresholds apply on a global level for all channels with range detection enabled. +* +* The SARSEQ supports range detection to allow for automatic detection of sample values +* compared to two programmable thresholds without CPU involvement. +* Range detection is done after averaging, alignment, and sign extension (if applicable). In other words the +* threshold values need to have the same data format as the result data. +* The values are interpreted as signed or unsigned according to each channel's configuration. +* +* Use the shifts defined in \ref cy_en_sar_range_thres_shift_t. +* +* The \ref Cy_SAR_SetLowLimit and \ref Cy_SAR_SetHighLimit provide run-time configurability of these thresholds. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_RANGE_THRES +* +* \subsection group_sar_init_struct_rangeCond cy_en_sar_range_detect_condition_t rangeCond +* +* This field configures the condition (below, inside, outside, or above) that will trigger +* the range interrupt. Select a value from the \ref cy_en_sar_range_detect_condition_t enum. +* +* \subsection group_sar_init_struct_chanEn uint32_t chanEn +* +* This field configures which channels will be scanned. +* Each bit corresponds to a channel. Bit 0 enables channel 0, bit 1 enables channel 1, +* bit 2 enables channel 2, and so on. +* +* \subsection group_sar_init_struct_chanConfig uint32_t chanConfig[16] +* +* Each channel has its own channel configuration register. +* The channel configuration specifies which pin/signal is connected to that channel +* and how the channel is sampled. +* +* Select a value from each of the following enums that begin with "cy_en_sar_chan_config_" and "OR" them together. +* +* - \ref cy_en_sar_chan_config_input_mode_t +* - \ref cy_en_sar_chan_config_pos_pin_addr_t +* - \ref cy_en_sar_chan_config_pos_port_addr_t +* - \ref cy_en_sar_chan_config_avg_en_t +* - \ref cy_en_sar_chan_config_sample_time_t +* - \ref cy_en_sar_chan_config_neg_pin_addr_t +* - \ref cy_en_sar_chan_config_neg_port_addr_t +* +* Some important considerations are: +* - The POS_PORT_ADDR and POS_PIN_ADDR bit fields are used by the SARSEQ to select +* the connection to the positive terminal (Vplus) of the ADC for each channel. +* - When the channel is an unpaired differential input (\ref CY_SAR_CHAN_DIFFERENTIAL_UNPAIRED), the +* NEG_PORT_ADDR and NEG_PIN_ADDR are used by the SARSEQ to select the connection +* to the negative terminal (Vminus) of the ADC. +* - When the channel is a differential input pair (\ref CY_SAR_CHAN_DIFFERENTIAL_PAIRED), the NEG_PORT_ADDR and NEG_PIN_ADDR are ignored. +* For differential input pairs, only the pin for the positive terminal needs to be +* specified and this pin must be even. For example, Pin 0 (positive terminal) and Pin 1 (negative terminal) +* are a pair. Pin 2 (positive terminal) and Pin 3 (negative terminal) are a pair. +* +* If the SARSEQ is disabled (\ref cy_en_sar_ctrl_sarseq_routing_switches_t) or +* it is not controlling any switches (\ref group_sar_init_struct_muxSwitchSqCtrl = 0), the port and pin addresses +* are ignored. This is possible when there is only one channel to scan. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_CHAN_CONFIG +* +* \subsection group_sar_init_struct_intrMask uint32_t intrMask +* +* This field configures which interrupt events (end of scan, overflow, or firmware collision) will be serviced by the firmware. +* +* Select one or more values from the \ref cy_en_sar_intr_mask_t enum and "OR" them +* together. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_INTR_MASK +* +* \subsection group_sar_init_struct_satIntrMask uint32_t satIntrMask +* +* This field configures which channels will cause a saturation interrupt. +* +* The SARSEQ has a saturation detect that is always applied to every conversion. +* This feature detects whether a channel's sample value is equal to the minimum or maximum values. +* This allows the firmware to take action, for example, discard the result, when the SARADC saturates. +* The sample value is tested right after conversion, that is, before averaging. This means that it +* can happen that the interrupt is set while the averaged result in the data register is not +* equal to the minimum or maximum. +* +* Each bit corresponds to a channel. A value of 0 disables saturation detection for all channels. +* +* \subsection group_sar_init_struct_rangeIntrMask uint32_t rangeIntrMask +* +* This field configures which channels will cause a range detection interrupt. +* Each bit corresponds to a channel. A value of 0 disables range detection for all channels. +* +* \subsection group_sar_init_struct_muxSwitch uint32_t muxSwitch +* +* This field is the firmware control of the SARMUX switches. +* +* Use one or more values from the \ref cy_en_sar_mux_switch_fw_ctrl_t enum and "OR" them together. +* If the SARSEQ is enabled, the SARMUX switches that will be used must +* also be closed using this firmware control. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_MUX_SWITCH +* +* Firmware control can be changed at run-time by calling \ref Cy_SAR_SetAnalogSwitch with \ref CY_SAR_MUX_SWITCH0 +* and the desired switch states. +* +* \subsection group_sar_init_struct_muxSwitchSqCtrl uint32_t muxSwitchSqCtrl +* +* This field enables or disables SARSEQ control of the SARMUX switches. +* To disable control of all switches, set this field to 0. To disable the SARSEQ all together, +* use \ref CY_SAR_SARSEQ_SWITCH_DISABLE when configuring the \ref group_sar_init_struct_ctrl register. +* +* Use one or more values from the \ref cy_en_sar_mux_switch_sq_ctrl_t enum and "OR" them together. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_MUX_SQ_CTRL +* +* SARSEQ control can be changed at run-time by calling \ref Cy_SAR_SetSwitchSarSeqCtrl. +* +* \subsection group_sar_init_struct_configRouting bool configRouting +* +* If true, the \ref group_sar_init_struct_muxSwitch and \ref group_sar_init_struct_muxSwitchSqCtrl fields +* will be used. If false, the fields will be ignored. +* +* \subsection group_sar_init_struct_vrefMvValue uint32_t vrefMvValue +* +* This field sets the value of the reference voltage in millivolts used. This value +* is used for converting counts to volts in the \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, and +* \ref Cy_SAR_CountsTo_uVolts functions. +* +* \section group_sar_trigger_conversions Triggering Conversions * * The SAR subsystem has the following modes for triggering a conversion: * @@ -77,7 +254,9 @@ * SARSEQ will immediately start the next scan. That is, the SARSEQ will always be BUSY. * As a result all other triggers, firmware or hardware, are essentially ignored. * -* +* * * * @@ -104,44 +283,225 @@ * \ref CY_SAR_TRIGGER_MODE_FW_AND_HWLEVEL. * *
To enter this mode, call \ref Cy_SAR_StartConvert with \ref CY_SAR_START_CONVERT_CONTINUOUS.To enter this mode, call \ref Cy_SAR_StartConvert with \ref CY_SAR_START_CONVERT_CONTINUOUS. +* To stop continuous conversions, call \ref Cy_SAR_StopConvert. +*
Firmware single shot
- +* * The trigger mode can be changed during run time with \ref Cy_SAR_SetConvertMode. * -* Refer to \ref group_trigmux to configure the multiplexer to route a trigger signal to the SAR trigger input. +* For the hardware trigger modes, use the \ref group_trigmux driver to route an internal or external +* signal to the SAR trigger input. * When making the required \ref Cy_TrigMux_Connect calls, use the pre-defined enum, TRIG6_OUT_PASS_TR_SAR_IN, * for the SAR trigger input. * -* Handling Interrupts +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_CONFIG_TRIGGER * -* The driver has a function, \ref Cy_SAR_IsEndConversion, that can query the conversion -* status or wait in blocking mode until the conversion is complete. Alternatively, -* implement an interrupt routine and assign it to the SAR interrupt. +* \section group_sar_handle_interrupts Handling Interrupts +* +* The SAR can generate interrupts on these events: +* +* - End of scan (EOS): when scanning of all enabled channels complete. +* - Overflow: when the result register is updated before the previous result is read. +* - FW collision: when a new trigger is received while the SAR is still processing the previous trigger. +* - Saturation detection: when the channel result is equal to the minimum or maximum value. +* - Range detection: when the channel result meets the programmed upper or lower threshold values. +* +* The SAR interrupt to the NVIC is raised any time the intersection (logic and) of the interrupt +* flags and the corresponding interrupt masks are non-zero. +* +* Implement an interrupt routine and assign it to the SAR interrupt. * Use the pre-defined enum, pass_interrupt_sar_IRQn, as the interrupt source for the SAR. * -* See \ref group_sar_code_example for example code. +* The following code snippet demonstrates how to implement a routine to handle the interrupt. +* The routine gets called when any one of the SAR interrupts are triggered. +* When servicing an interrupt, the user must clear the interrupt so that subsequent +* interrupts can be handled. * -* Getting ADC result +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_ISR +* +* The following code snippet demonstrates how to configure and enable the interrupt. +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_CONFIG_INTR +* +* Alternately, instead of handling the interrupts, the \ref Cy_SAR_IsEndConversion function +* allows for firmware polling of the end of conversion status. +* +* \section group_sar_retrieve_result Retrieve Channel Results * * Retrieve the ADC result by calling \ref Cy_SAR_GetResult16 with the desired channel. -* For a voltage value, pass the ADC result to \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, or +* To convert the result to a voltage, pass the ADC result to \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, or * \ref Cy_SAR_CountsTo_uVolts. * * \section group_sar_clock SAR Clock Configuration * -* Assign a clock to the SAR and set the divider value with \ref Cy_SysClk_PeriphAssignDivider. -* The pre-defined enum, PCLK_PASS_CLOCK_SAR, should be used to identify the SAR subsystem. -* Set the clock divider value to achieve the desired clock rate. The maximum frequency is 18 MHz. +* The SAR requires a clock. Assign a clock to the SAR using the +* pre-defined enum, PCLK_PASS_CLOCK_SAR, to identify the SAR subsystem. +* Set the clock divider value to achieve the desired clock rate. The SAR can support +* a maximum frequency of 18 MHz. * -* See \ref group_sar_code_example for example code. +* \snippet sar_sut_01.cydsn/main_cm4.c SAR_SNIPPET_CONFIGURE_CLOCK * -* \section group_sar_code_example Complete Code Example +* \section group_sar_scan_time Scan Rate * -* \code -* #include "sar/cy_sar.h" -* #include "sysanalog/cy_sysanalog.h" -* #include "sysint/cy_sysint.h" -* \endcode -* \snippet sar_sut_01.cydsn/main_cm0p.c SAR_CODE_EXAMPLE +* The scan rate is dependent on the following: +* +* - ADC clock rate +* - Number of channels +* - Averaging +* - Resolution +* - Acquisition times +* +* \subsection group_sar_acquisition_time Acquisition Time +* +* The acquisition time of a channel is based on which of the four global aperture times are selected for that +* channel. The selection is done during initialization per channel with \ref group_sar_init_struct_chanConfig. +* The four global aperture times are also set during initialization with \ref group_sar_init_struct_sampleTime01 and +* \ref group_sar_init_struct_sampleTime23. Note that these global aperture times are in SAR clock cycles and the +* acquisition time is 1 less than that value in the register. +* +* \image html sar_acquisition_time_eqn.png +* +* \subsection group_sar_channel_sample_time Channel Sample Time +* +* The sample time for a channel is the time required to acquire the analog signal +* and convert it to a digital code. +* +* \image html sar_channel_sample_time_eqn.png +* +* The SAR ADC is a 12-bit converter so Resolution = 12. +* +* \subsection group_sar_total_scan_time Total Scan Time +* +* Channels using one of the sequential averaging modes (\ref CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM or \ref CY_SAR_AVG_MODE_SEQUENTIAL_FIXED) +* are sampled multiple times per scan. The number of samples averaged are set during initialization +* with \ref group_sar_init_struct_sampleCtrl using one of the values from \ref cy_en_sar_sample_ctrl_avg_cnt_t. +* Channels that are not averaged or use the \ref CY_SAR_AVG_MODE_INTERLEAVED mode are only sampled once per scan. +* +* The total scan time is the sum of each channel's sample time multiplied by the samples per scan. +* +* \image html sar_scan_rate_eqn.png +* +* where N is the total number of channels in the scan. +* +* \section group_sar_sarmux SARMUX and SARSEQ +* +* The SARMUX is an analog programmable multiplexer. Its switches can be controlled by the SARSEQ or firmware. +* and the inputs can come from: +* - a dedicated port (can support 8 single-ended channels or 4 differential channels) +* - an internal die temperature (DieTemp) sensor +* - CTB output via SARBUS0/1 (if CTBs are available on the device) +* - AMUXBUSA/B +* +* The following figure shows the SARMUX switches. See the device datasheet for the exact location of SARMUX pins. +* +* \image html sar_sarmux_switches.png +* +* When using the SARSEQ, the following configurations must be performed: +* - enable SARSEQ control of required switches (see \ref group_sar_init_struct_muxSwitchSqCtrl) +* - close the required switches with firmware (see \ref group_sar_init_struct_muxSwitch) +* - configure the POS_PORT_ADDR and POS_PIN_ADDR, and if used, the NEG_PORT_ADDR and NEG_PIN_ADDR (see \ref group_sar_init_struct_chanConfig) +* +* While firmware can control every switch in the SARMUX, not every switch can be controlled by the SARSEQ (green switches in the above figure). +* Additionally, switches outside of the SARMUX such as the AMUXBUSA/B switches or +* CTB switches will require separate function calls (see \ref group_gpio "GPIO" and \ref group_ctb "CTB" drivers). +* The SARSEQ can control three switches in the \ref group_ctb "CTB" driver (see \ref Cy_CTB_EnableSarSeqCtrl). +* These switches need to be enabled for SARSEQ control if the CTB outputs are used as the SARMUX inputs. +* +* The following table shows the required POS_PORT_ADDR and POS_PIN_ADDR settings +* for different input connections. +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
Input Connection SelectionPOS_PORT_ADDRPOS_PIN_ADDR
SARMUX dedicated port\ref CY_SAR_POS_PORT_ADDR_SARMUX\ref CY_SAR_CHAN_POS_PIN_ADDR_0 through \ref CY_SAR_CHAN_POS_PIN_ADDR_7
DieTemp sensor\ref CY_SAR_POS_PORT_ADDR_SARMUX_VIRT\ref CY_SAR_CHAN_POS_PIN_ADDR_0
AMUXBUSA\ref CY_SAR_POS_PORT_ADDR_SARMUX_VIRT\ref CY_SAR_CHAN_POS_PIN_ADDR_2
AMUXBUSB\ref CY_SAR_POS_PORT_ADDR_SARMUX_VIRT\ref CY_SAR_CHAN_POS_PIN_ADDR_3
CTB0 Opamp0 1x output\ref CY_SAR_POS_PORT_ADDR_CTB0\ref CY_SAR_CHAN_POS_PIN_ADDR_2
CTB0 Opamp1 1x output\ref CY_SAR_POS_PORT_ADDR_CTB0\ref CY_SAR_CHAN_POS_PIN_ADDR_3
+* +* \subsection group_sar_sarmux_dietemp Input from DieTemp sensor +* +* When using the DieTemp sensor, always use single-ended mode. +* The temperature sensor can be routed to Vplus using the \ref CY_SAR_MUX_FW_TEMP_VPLUS switch. +* Connecting this switch will also enable the sensor. Set the \ref group_sar_acquisition_time "acquisition time" to +* be at least 1 us to meet the settling time of the temperature sensor. +* +* \image html sar_sarmux_dietemp.png +* +* \snippet sar_sut_02.cydsn/main_cm4.c SNIPPET_SAR_SARMUX_DIETEMP +* +* \subsection group_sar_sarmux_se_diff Input from SARMUX port +* +* The following figure and code snippet show how two GPIOs on the SARMUX dedicated port +* are connected to the SARADC as separate single-ended channels and as a differential-pair channel. +* +* \image html sar_sarmux_dedicated_port.png +* +* \snippet sar_sut_02.cydsn/main_cm4.c SNIPPET_SAR_SARMUX_SE_DIFF +* +* \subsection group_sar_sarmux_ctb Input from CTB output visa SARBUS0/1 +* +* The following figure and code snippet show how the two opamp outputs from the CTB +* are connected to the SARADC as separate single-ended channels and as a differential-pair channel. +* Note that separate function calls are needed to configure and enable the opamps, perform required analog routing, +* and enable SARSEQ control of the switches contained in the CTB. +* +* \image html sar_sarmux_ctb.png +* +* \snippet sar_sut_02.cydsn/main_cm4.c SNIPPET_SAR_SARMUX_CTB +* +* \subsection group_sar_sarmux_amuxbus Input from other pins through AMUXBUSA/B +* +* The following figure and code snippet show how two GPIOs on any port through the AMUXBUSA and AMUXBUSB +* are connected to the SARADC as separate single-ended channels and as a differential-pair channel. +* Note that separate function calls are needed to route the device pins to the SARMUX. The AMUXBUSes +* are separated into multiple segments and these segments are connected/disconnected using the AMUX_SPLIT_CTL +* registers in the HSIOM. In the following code snippet, to connect Port 1 to the SARMUX, the left and right +* switches of AMUX_SPLIT_CTL[1] and AMUX_SPLIT_CTL[6] need to be closed. +* +* \image html sar_sarmux_amuxbus.png +* +* \snippet sar_sut_02.cydsn/main_cm4.c SNIPPET_SAR_SARMUX_AMUXBUS +* +* \section group_sar_low_power Low Power Support +* This SAR driver provides a callback function to handle power mode transitions. +* The \ref Cy_SAR_DeepSleepCallback function ensures that SAR conversions are stopped +* before Deep Sleep entry. Upon wakeup, the callback +* enables the hardware and continuous conversions, if previously enabled. +* +* To trigger the callback execution, the callback must be registered before calling \ref Cy_SysPm_DeepSleep. Refer to +* \ref group_syspm driver for more information about power mode transitions and +* callback registration. +* +* Recall that during configuration of the \ref group_sar_init_struct_ctrl "ctrl" field, +* the SARMUX can be configured to remain enabled in Deep Sleep mode. +* All other blocks (SARADC, REFBUF, and SARSEQ) do not support Deep Sleep mode operation. * * \section group_sar_more_information More Information * For more information on the SAR ADC subsystem, refer to the technical reference manual (TRM). @@ -172,6 +532,22 @@ * * * +* +* +* +* +* +* +* +* +* +* +* +* +* * * * @@ -182,7 +558,7 @@ * \defgroup group_sar_functions Functions * \{ * \defgroup group_sar_functions_basic Initialization and Basic Functions -* \defgroup group_sar_functions_power Power Mode Functions +* \defgroup group_sar_functions_power Low Power Callback * \defgroup group_sar_functions_config Run-time Configuration Functions * \defgroup group_sar_functions_countsto Counts Conversion Functions * \defgroup group_sar_functions_interrupt Interrupt Functions @@ -190,16 +566,16 @@ * \defgroup group_sar_functions_helper Useful Configuration Query Functions * \} * \defgroup group_sar_globals Global Variables -* \defgroup group_sar_data_structures Data structures +* \defgroup group_sar_data_structures Data Structures * \defgroup group_sar_enums Enumerated Types * \{ * \defgroup group_sar_ctrl_register_enums Control Register Enums * \defgroup group_sar_sample_ctrl_register_enums Sample Control Register Enums -* \defgroup group_sar_sample_time_shift_ts Sample Time Configuration Registers Enums -* \defgroup group_sar_range_thres_register_enums Range Configuration Registers Enums -* \defgroup group_sar_chan_config_register_enums Channel Configuration Registers Enums -* \defgroup group_sar_intr_mask_t_register_enums Interrupt Mask Register Enum -* \defgroup group_sar_mux_switch_register_enums SARMUX Switch Control Registers Enums +* \defgroup group_sar_sample_time_shift_enums Sample Time Register Enums +* \defgroup group_sar_range_thres_register_enums Range Interrupt Register Enums +* \defgroup group_sar_chan_config_register_enums Channel Configuration Register Enums +* \defgroup group_sar_intr_mask_t_register_enums Interrupt Mask Register Enums +* \defgroup group_sar_mux_switch_register_enums SARMUX Switch Control Register Enums * \} */ @@ -229,7 +605,7 @@ extern "C" { #define CY_SAR_DRV_VERSION_MAJOR 1 /** Driver minor version */ -#define CY_SAR_DRV_VERSION_MINOR 0 +#define CY_SAR_DRV_VERSION_MINOR 10 /** SAR driver identifier */ #define CY_SAR_ID CY_PDL_DRV_ID(0x01u) @@ -301,19 +677,22 @@ extern "C" { #define CY_SAR_10MV_COUNTS (10000) /**< Value of 10 in millivolts */ #define CY_SAR_10UV_COUNTS (10000000L) /**< Value of 10 in microvolts */ #define CY_SAR_WRK_MAX_12BIT (0x00001000uL) /**< Maximum SAR work register value for a 12-bit resolution */ -#define CY_SAR_LIMIT_MAX (0xFFFFuL) /**< Maximum value for the low and high limit values */ +#define CY_SAR_RANGE_LIMIT_MAX (0xFFFFuL) /**< Maximum value for the low and high range interrupt threshold values */ +#define CY_SAR_CAP_TRIM_MAX (0x3FuL) /**< Maximum value for CAP_TRIM */ +#define CY_SAR_CAP_TRIM_MIN (0x00uL) /**< Maximum value for CAP_TRIM */ +#define CY_SAR_CAP_TRIM (0x0BuL) /**< Correct cap trim value */ /**< Macros for conditions used in CY_ASSERT calls */ #define CY_SAR_CHANNUM(chan) ((chan) < CY_SAR_MAX_NUM_CHANNELS) #define CY_SAR_CHANMASK(mask) ((mask) < (1uL << CY_SAR_MAX_NUM_CHANNELS)) -#define CY_SAR_LIMITCOND(cond) ((cond) <= CY_SAR_LIMIT_COND_OUTSIDE) +#define CY_SAR_RANGECOND(cond) ((cond) <= CY_SAR_RANGE_COND_OUTSIDE) #define CY_SAR_INTRMASK(mask) ((mask) <= (uint32_t)(CY_SAR_INTR_EOS_MASK | CY_SAR_INTR_OVERFLOW_MASK | CY_SAR_INTR_FW_COLLISION_MASK)) #define CY_SAR_TRIGGER(mode) (((mode) == CY_SAR_TRIGGER_MODE_FW_ONLY) \ || ((mode) == CY_SAR_TRIGGER_MODE_FW_AND_HWEDGE) \ || ((mode) == CY_SAR_TRIGGER_MODE_FW_AND_HWLEVEL)) #define CY_SAR_RETURN(mode) (((mode) == CY_SAR_RETURN_STATUS) || ((mode) == CY_SAR_WAIT_FOR_RESULT)) #define CY_SAR_STARTCONVERT(mode) (((mode) == CY_SAR_START_CONVERT_SINGLE_SHOT) || ((mode) == CY_SAR_START_CONVERT_CONTINUOUS)) -#define CY_SAR_LIMIT(limit) ((limit) <= CY_SAR_LIMIT_MAX) +#define CY_SAR_RANGE_LIMIT(limit) ((limit) <= CY_SAR_RANGE_LIMIT_MAX) #define CY_SAR_SWITCHSELECT(select) ((select) == CY_SAR_MUX_SWITCH0) #define CY_SAR_SWITCHMASK(mask) ((mask) <= CY_SAR_CLEAR_ALL_SWITCHES) #define CY_SAR_SWITCHSTATE(state) (((state) == CY_SAR_SWITCH_OPEN) || ((state) == CY_SAR_SWITCH_CLOSE)) @@ -335,23 +714,26 @@ extern "C" { * Global Variables ***************************************/ -/** This array is used to calibrates the offset for each channel. +/** This array is used to calibrate the offset for each channel. +* +* At initialization, channels that are single-ended, signed, and with Vneg = Vref +* have an offset of -(2^12)/2 = -2048. All other channels have an offset of 0. +* The offset can be overridden using \ref Cy_SAR_SetOffset. +* +* The channel offsets are used by the \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, and +* \ref Cy_SAR_CountsTo_uVolts functions to convert counts to voltage. * -* At initialization, the offset array's entries are set to 0, except for channels -* that are Single-Ended, Signed, and have Vneg=Vref, for which they are set to -* -2^(Resolution-1)/Vref(mV). These can be modified using \ref Cy_SAR_SetOffset. The array -* is used by the \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, and -* \ref Cy_SAR_CountsTo_uVolts functions. */ extern volatile int16_t Cy_SAR_offset[CY_SAR_MAX_NUM_CHANNELS]; /** This array is used to calibrate the gain for each channel. * -* It is set at initialization and the value depends on voltage reference. -* It can be changed using \ref Cy_SAR_SetGain. +* It is set at initialization and the value depends on the SARADC resolution +* and voltage reference, 10*(2^12)/(2*Vref). +* The gain can be overridden using \ref Cy_SAR_SetGain. * -* The array is used by the \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, and -* \ref Cy_SAR_CountsTo_uVolts functions. +* The channel gains are used by the \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, and +* \ref Cy_SAR_CountsTo_uVolts functions to convert counts to voltage. */ extern volatile int32_t Cy_SAR_countsPer10Volt[CY_SAR_MAX_NUM_CHANNELS]; @@ -428,7 +810,7 @@ typedef enum /** Reference voltage selection definitions */ typedef enum { - CY_SAR_VREF_SEL_BGR = 4uL << SAR_CTRL_VREF_SEL_Pos, /**< System wide bandgap (Vref buffer on)*/ + CY_SAR_VREF_SEL_BGR = 4uL << SAR_CTRL_VREF_SEL_Pos, /**< System wide bandgap from \ref group_sysanalog "AREF" (Vref buffer on) */ CY_SAR_VREF_SEL_EXT = 5uL << SAR_CTRL_VREF_SEL_Pos, /**< External Vref direct from a pin */ CY_SAR_VREF_SEL_VDDA_DIV_2 = 6uL << SAR_CTRL_VREF_SEL_Pos, /**< Vdda/2 (Vref buffer on) */ CY_SAR_VREF_SEL_VDDA = 7uL << SAR_CTRL_VREF_SEL_Pos /**< Vdda */ @@ -445,31 +827,31 @@ typedef enum CY_SAR_BYPASS_CAP_ENABLE = 1uL << SAR_CTRL_VREF_BYP_CAP_EN_Pos /**< Enable Vref bypass cap */ }cy_en_sar_ctrl_bypass_cap_t; -/** Single ended negative terminal (NEG) selection definitions. +/** Negative terminal (Vminus) selection definitions for single-ended channels. * -* The NEG input for single ended channels can be connected to -* Vref, Vssa_Kelvin, or routed out to an external pin. -* The options for routing to a pin are through P1, P3, P5, or P7 -* of the SARMUX or an acore wire in AROUTE. +* The Vminus input for single ended channels can be connected to +* Vref, VSSA, or routed out to an external pin. +* The options for routing to a pin are through Pin 1, Pin 3, Pin 5, or Pin 7 +* of the SARMUX dedicated port or an acore wire in AROUTE, if available on the device. * -* Vssa_Kelvin comes straight from a Vssa pad without any shared branches +* \ref CY_SAR_NEG_SEL_VSSA_KELVIN comes straight from a Vssa pad without any shared branches * so as to keep quiet and avoid voltage drops. */ typedef enum { - CY_SAR_NEG_SEL_VSSA_KELVIN = 0uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is connected to VSSA_KELVIN */ - CY_SAR_NEG_SEL_P1 = 2uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is connected to P1 pin of SARMUX */ - CY_SAR_NEG_SEL_P3 = 3uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is connected to P3 pin of SARMUX */ - CY_SAR_NEG_SEL_P5 = 4uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is connected to P5 pin of SARMUX */ - CY_SAR_NEG_SEL_P7 = 5uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is connected to P6 pin of SARMUX */ - CY_SAR_NEG_SEL_ACORE = 6uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is connected to an ACORE in AROUTE */ - CY_SAR_NEG_SEL_VREF = 7uL << SAR_CTRL_NEG_SEL_Pos, /**< NEG input is shorted to VREF input of SARADC */ + CY_SAR_NEG_SEL_VSSA_KELVIN = 0uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to VSSA_KELVIN */ + CY_SAR_NEG_SEL_P1 = 2uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to Pin 1 of SARMUX dedicated port */ + CY_SAR_NEG_SEL_P3 = 3uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to Pin 3 of SARMUX dedicated port */ + CY_SAR_NEG_SEL_P5 = 4uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to Pin 5 of SARMUX dedicated port */ + CY_SAR_NEG_SEL_P7 = 5uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to Pin 6 of SARMUX dedicated port */ + CY_SAR_NEG_SEL_ACORE = 6uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to an ACORE in AROUTE */ + CY_SAR_NEG_SEL_VREF = 7uL << SAR_CTRL_NEG_SEL_Pos, /**< Connect Vminus to VREF input of SARADC */ }cy_en_sar_ctrl_neg_sel_t; -/** Enable hardware control of the switch between Vref and the NEG input */ +/** Enable hardware control of the switch between Vref and the Vminus input */ typedef enum { - CY_SAR_CTRL_NEGVREF_FW_ONLY = 0uL << SAR_CTRL_SAR_HW_CTRL_NEGVREF_Pos, /**< Only firmware control of the switch*/ + CY_SAR_CTRL_NEGVREF_FW_ONLY = 0uL << SAR_CTRL_SAR_HW_CTRL_NEGVREF_Pos, /**< Only firmware control of the switch */ CY_SAR_CTRL_NEGVREF_HW = 1uL << SAR_CTRL_SAR_HW_CTRL_NEGVREF_Pos /**< Enable hardware control of the switch */ }cy_en_sar_ctrl_hw_ctrl_negvref_t; @@ -482,14 +864,6 @@ typedef enum CY_SAR_CTRL_COMP_DLY_12 = 3uL << SAR_CTRL_COMP_DLY_Pos /**< 12 ns delay, use for SAR conversion rate up to 1 Msps */ }cy_en_sar_ctrl_comp_delay_t; -/** Enable the reference buffer (REFBUF) and the routing for the reference block. -* The REFBUF should always be enabled for any reference source selection. */ -typedef enum -{ - CY_SAR_REFBUF_DISABLE = 0uL << SAR_CTRL_REFBUF_EN_Pos, /**< Only firmware control of the switch */ - CY_SAR_REFBUF_ENABLE = 1uL << SAR_CTRL_REFBUF_EN_Pos /**< Enable hardware control of the switch */ -}cy_en_sar_ctrl_refbuf_en_t; - /** Configure the comparator power mode */ typedef enum { @@ -503,49 +877,55 @@ typedef enum CY_SAR_COMP_PWR_10 = 7uL << SAR_CTRL_COMP_PWR_Pos, /**< 10% power, use this for < 100 ksps */ }cy_en_sar_ctrl_comp_pwr_t; -/** Enable or disable the SARMUX during Deep Sleep power mode */ +/** Enable or disable the SARMUX during Deep Sleep power mode. */ typedef enum { - CY_SAR_DEEPSLEEP_SARMUX_OFF = 0uL << SAR_CTRL_DEEPSLEEP_ON_Pos, /**< Disable SARMUX IP during Deep Sleep */ - CY_SAR_DEEPSLEEP_SARMUX_ON = 1uL << SAR_CTRL_DEEPSLEEP_ON_Pos /**< Enable SARMUX IP during Deep Sleep */ -}cy_en_sar_ctrl_deepsleep_on_t; + CY_SAR_DEEPSLEEP_SARMUX_OFF = 0uL << SAR_CTRL_DEEPSLEEP_ON_Pos, /**< Disable SARMUX operation during Deep Sleep */ + CY_SAR_DEEPSLEEP_SARMUX_ON = 1uL << SAR_CTRL_DEEPSLEEP_ON_Pos /**< Enable SARMUX operation during Deep Sleep */ +}cy_en_sar_ctrl_sarmux_deep_sleep_t; -/** Enable or disable the SAR sequencer control of routing switches */ +/** Enable or disable the SARSEQ control of routing switches */ typedef enum { - CY_SAR_SARSEQ_SWITCH_ENABLE = 0uL << SAR_CTRL_SWITCH_DISABLE_Pos, /**< Enable the SAR sequencer to change the routing switches defined in the channel configurations */ - CY_SAR_SARSEQ_SWITCH_DISABLE = 1uL << SAR_CTRL_SWITCH_DISABLE_Pos /**< SAR sequencer does not enable any switches. It is up to the firmware to set the routing switches */ + CY_SAR_SARSEQ_SWITCH_ENABLE = 0uL << SAR_CTRL_SWITCH_DISABLE_Pos, /**< Enable the SARSEQ to change the routing switches defined in the channel configurations */ + CY_SAR_SARSEQ_SWITCH_DISABLE = 1uL << SAR_CTRL_SWITCH_DISABLE_Pos /**< Disable the SARSEQ. It is up to the firmware to set the routing switches */ }cy_en_sar_ctrl_sarseq_routing_switches_t; /* \} */ /** \addtogroup group_sar_sample_ctrl_register_enums -* This set of enumerations aids in configuring the SAR SAMPLE_CTRL register +* This set of enumerations are used in configuring the SAR SAMPLE_CTRL register * \{ */ /** Configure result alignment, either left or right aligned. * -* Note that averaging always uses right alignment. If the LEFT_ALIGN -* is selected with averaging enabled, it is ignored. */ +* \note +* Averaging always uses right alignment. If the \ref CY_SAR_LEFT_ALIGN +* is selected with averaging enabled, it is ignored. +* +* \note +* The voltage conversion functions (\ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, +* \ref Cy_SAR_CountsTo_uVolts) are only valid for right alignment. +* */ typedef enum { CY_SAR_RIGHT_ALIGN = 0uL << SAR_SAMPLE_CTRL_LEFT_ALIGN_Pos, /**< Right align result data to bits [11:0] with sign extension to 16 bits if channel is signed */ CY_SAR_LEFT_ALIGN = 1uL << SAR_SAMPLE_CTRL_LEFT_ALIGN_Pos /**< Left align result data to bits [15:4] */ -}cy_en_sar_sample_ctrl_align_t; +}cy_en_sar_sample_ctrl_result_align_t; /** Configure format, signed or unsigned, of single-ended channels */ typedef enum { CY_SAR_SINGLE_ENDED_UNSIGNED = 0uL << SAR_SAMPLE_CTRL_SINGLE_ENDED_SIGNED_Pos, /**< Result data for single-ended channels is unsigned */ CY_SAR_SINGLE_ENDED_SIGNED = 1uL << SAR_SAMPLE_CTRL_SINGLE_ENDED_SIGNED_Pos /**< Result data for single-ended channels is signed */ -}cy_en_sar_sample_ctrl_single_ended_signed_t; +}cy_en_sar_sample_ctrl_single_ended_format_t; /** Configure format, signed or unsigned, of differential channels */ typedef enum { CY_SAR_DIFFERENTIAL_UNSIGNED = 0uL << SAR_SAMPLE_CTRL_DIFFERENTIAL_SIGNED_Pos, /**< Result data for differential channels is unsigned */ CY_SAR_DIFFERENTIAL_SIGNED = 1uL << SAR_SAMPLE_CTRL_DIFFERENTIAL_SIGNED_Pos /**< Result data for differential channels is signed */ -}cy_en_sar_sample_ctrl_differential_signed_t; +}cy_en_sar_sample_ctrl_differential_format_t; /** Configure number of samples for averaging. * This applies only to channels with averaging enabled. @@ -560,34 +940,36 @@ typedef enum CY_SAR_AVG_CNT_64 = 5uL << SAR_SAMPLE_CTRL_AVG_CNT_Pos, /**< Set samples averaged to 64 */ CY_SAR_AVG_CNT_128 = 6uL << SAR_SAMPLE_CTRL_AVG_CNT_Pos, /**< Set samples averaged to 128 */ CY_SAR_AVG_CNT_256 = 7uL << SAR_SAMPLE_CTRL_AVG_CNT_Pos /**< Set samples averaged to 256 */ -}cy_en_sar_sample_ctrl_avg_cnt_signed_t; +}cy_en_sar_sample_ctrl_avg_cnt_t; /** Configure the averaging mode. * * - Sequential accumulate and dump: a channel will be sampled back to back. -* The average result is calculated and stored and then the next enabled -* channel is sampled. The result is forced to shift right so that it fits -* in 16 bits. +* The result is added to a running sum in a 20-bit register. At the end +* of the scan, the accumulated value is shifted right to fit into 16 bits +* and stored into the CHAN_RESULT register. * - Sequential fixed: a channel will be sampled back to back. -* The average result is calculated and stored and then the next enabled -* channel is sampled. The result is forced to shift right so that it fits -* in 12 bits. -* - Interleaved: one sample is taken per triggered scan, only in the scan where -* the final averaging count is reached. A valid average is calculated and stored -* in the RESULT register. In all other scans, the RESULT register for averaged -* channels will have an invalid result. In this mode, make sure that the averaging -* count is low enough to ensure that the intermediate value does not exceed 16-bits. -* Otherwise, the MSBs will be lost. So for a 12-bit resolution, the averaging count -* should be set to 16 or less. -* -* If averaging is enabled for all enabled channels, the interrupt frequency -* will be reduced by a factor of AVG_CNT (the number of samples averaged). +* The result is added to a running sum in a 20-bit register. At the end +* of the scan, the accumulated value is shifted right to fit into 12 bits +* and stored into the CHAN_RESULT register. +* - Interleaved: a channel will be sampled once per scan. +* The result is added to a running sum in a 16-bit register. +* In the scan where the final averaging count is reached, +* the accumulated value is shifted right to fit into 12 bits +* and stored into the CHAN_RESULT register. +* In all other scans, the CHAN_RESULT will have an invalid result. +* In interleaved mode, make sure that the averaging +* count is low enough to ensure that the intermediate value does not exceed 16 bits, +* that is averaging count is 16 or less. Otherwise, the MSBs will be lost. +* In the special case that averaging is enabled for all enabled channels +* and interleaved mode is used, the interrupt frequency +* will be reduced by a factor of the number of samples averaged. */ typedef enum { CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM = 0uL, /**< Set mode to sequential accumulate and dump */ CY_SAR_AVG_MODE_SEQUENTIAL_FIXED = SAR_SAMPLE_CTRL_AVG_SHIFT_Msk, /**< Set mode to sequential 12-bit fixed */ - CY_SAR_AVG_MODE_INTERLEAVED = SAR_SAMPLE_CTRL_AVG_MODE_Msk, /**< Set mode to interleaved */ + CY_SAR_AVG_MODE_INTERLEAVED = SAR_SAMPLE_CTRL_AVG_MODE_Msk, /**< Set mode to interleaved. Number of samples per scan must be 16 or less. */ }cy_en_sar_sample_ctrl_avg_mode_t; /** Configure the trigger mode. @@ -595,19 +977,17 @@ typedef enum * Firmware triggering is always enabled and can be single shot or continuous. * Additionally, hardware triggering can be enabled with the option to be * edge or level sensitive. -* -* These modes are passed into \ref Cy_SAR_SetConvertMode. */ typedef enum { CY_SAR_TRIGGER_MODE_FW_ONLY = 0uL, /**< Firmware trigger only, disable hardware trigger*/ CY_SAR_TRIGGER_MODE_FW_AND_HWEDGE = SAR_SAMPLE_CTRL_DSI_TRIGGER_EN_Msk, /**< Enable edge sensitive hardware trigger. Each rising edge will trigger a single scan. */ - CY_SAR_TRIGGER_MODE_FW_AND_HWLEVEL = SAR_SAMPLE_CTRL_DSI_TRIGGER_EN_Msk | SAR_SAMPLE_CTRL_DSI_TRIGGER_LEVEL_Msk, /**< Enable level sensitive hardware trigger. The SAR will continuously scan while the trigger signal is HIGH. */ + CY_SAR_TRIGGER_MODE_FW_AND_HWLEVEL = SAR_SAMPLE_CTRL_DSI_TRIGGER_EN_Msk | SAR_SAMPLE_CTRL_DSI_TRIGGER_LEVEL_Msk, /**< Enable level sensitive hardware trigger. The SAR will continuously scan while the trigger signal is high. */ }cy_en_sar_sample_ctrl_trigger_mode_t; /* \} */ -/** \addtogroup group_sar_sample_time_shift_ts +/** \addtogroup group_sar_sample_time_shift_enums * This set of enumerations aids in configuring the SAR SAMPLE_TIME* registers * \{ */ @@ -640,17 +1020,17 @@ typedef enum */ typedef enum { - CY_SAR_LIMIT_LOW_SHIFT = SAR_RANGE_THRES_RANGE_LOW_Pos, /**< Shift for setting lower limit of range detection */ - CY_SAR_LIMIT_HIGH_SHIFT = SAR_RANGE_THRES_RANGE_HIGH_Pos, /**< Shift for setting upper limit of range detection */ + CY_SAR_RANGE_LOW_SHIFT = SAR_RANGE_THRES_RANGE_LOW_Pos, /**< Shift for setting lower limit of range detection */ + CY_SAR_RANGE_HIGH_SHIFT = SAR_RANGE_THRES_RANGE_HIGH_Pos, /**< Shift for setting upper limit of range detection */ }cy_en_sar_range_thres_shift_t; -/** Configure the condition (below, inside, above, or outside) of the range detection */ +/** Configure the condition (below, inside, above, or outside) of the range detection interrupt */ typedef enum { - CY_SAR_LIMIT_COND_BELOW = 0uL, /**< Limit detected when result < RANGE_LOW */ - CY_SAR_LIMIT_COND_INSIDE = 1uL, /**< Limit detected when RANGE_LOW <= result < RANGE_HIGH */ - CY_SAR_LIMIT_COND_ABOVE = 2uL, /**< Limit detected when RANGE_HIGH <= result */ - CY_SAR_LIMIT_COND_OUTSIDE = 3uL, /**< Limit detected when result < RANGE_LOW || RANGE_HIGH <= result */ + CY_SAR_RANGE_COND_BELOW = 0uL, /**< Range interrupt detected when result < RANGE_LOW */ + CY_SAR_RANGE_COND_INSIDE = 1uL, /**< Range interrupt detected when RANGE_LOW <= result < RANGE_HIGH */ + CY_SAR_RANGE_COND_ABOVE = 2uL, /**< Range interrupt detected when RANGE_HIGH <= result */ + CY_SAR_RANGE_COND_OUTSIDE = 3uL, /**< Range interrupt detected when result < RANGE_LOW || RANGE_HIGH <= result */ }cy_en_sar_range_detect_condition_t; /* \} */ @@ -660,12 +1040,15 @@ typedef enum */ /** Configure the input mode of the channel * -* - Single ended channel: the NEG_SEL in the CTRL register determines what drives the Vminus pin -* - Differential paired: Vplus and Vminus are a pair. The POS_PIN_ADDR[0] is ignored and considered to be 0. -* In other words, POS_PIN_ADDR points to the even pin of a pin pair. In that case, the even pin of the -* pair is connected to Vplus and the odd pin of the pair is connected to Vminus. -* POS_PORT_ADDR is used to identify the port that contains the pins. -* - Differential unpaired: The NEG_PIN_ADDR and NEG_PORT_ADDR determine what drives the Vminus pin. +* - Single ended channel: the \ref cy_en_sar_ctrl_neg_sel_t selection in the \ref group_sar_init_struct_ctrl register +* determines what drives the Vminus pin +* - Differential paired: Vplus and Vminus are a pair. Bit 0 of \ref cy_en_sar_chan_config_pos_pin_addr_t "POS_PIN_ADDR" +* is ignored and considered to be 0. +* In other words, \ref cy_en_sar_chan_config_pos_pin_addr_t "POS_PIN_ADDR" points to the even pin of a pin pair. +* The even pin is connected to Vplus and the odd pin is connected to Vminus. +* \ref cy_en_sar_chan_config_pos_port_addr_t "POS_PORT_ADDR" is used to identify the port that contains the pins. +* - Differential unpaired: The \ref cy_en_sar_chan_config_neg_pin_addr_t "NEG_PIN_ADDR" and +* \ref cy_en_sar_chan_config_neg_port_addr_t "NEG_PORT_ADDR" determine what drives the Vminus pin. * This is a variation of differential mode with no even-odd pair limitation */ typedef enum @@ -678,33 +1061,35 @@ typedef enum /** Configure address of the pin connected to the Vplus terminal of the SARADC. */ typedef enum { - CY_SAR_CHAN_POS_PIN_ADDR_0 = 0uL, /**< Pin 0 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_1 = 1uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 1 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_2 = 2uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 2 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_3 = 3uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 3 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_4 = 4uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 4 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_5 = 5uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 5 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_6 = 6uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 6 on port specified in POS_PORT_ADDR */ - CY_SAR_CHAN_POS_PIN_ADDR_7 = 7uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 7 on port specified in POS_PORT_ADDR */ + CY_SAR_CHAN_POS_PIN_ADDR_0 = 0uL, /**< Pin 0 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_1 = 1uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 1 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_2 = 2uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 2 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_3 = 3uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 3 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_4 = 4uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 4 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_5 = 5uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 5 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_6 = 6uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 6 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ + CY_SAR_CHAN_POS_PIN_ADDR_7 = 7uL << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos, /**< Pin 7 on port specified in \ref cy_en_sar_chan_config_pos_port_addr_t */ }cy_en_sar_chan_config_pos_pin_addr_t; /** Configure address of the port that contains the pin connected to the Vplus terminal of the SARADC * -* - Port 0 is 8 pins of the SARMUX +* - \ref CY_SAR_POS_PORT_ADDR_SARMUX is for the dedicated SARMUX port (8 pins) * - Port 1 through 4 are respectively the pins of CTB0, CTB1, CTB2, and CTB3 (if present) * - Port 7, 5, and 6 (VPORT0/1/2) are the groups of internal signals that can be selected * in the SARMUX or AROUTE (if present). +* +* See the \ref group_sar_sarmux section for more guidance. */ typedef enum { - CY_SAR_POS_PORT_ADDR_SARMUX = 0uL, /**< SARMUX pins */ - CY_SAR_POS_PORT_ADDR_CTB0 = 1uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< CTB0 */ - CY_SAR_POS_PORT_ADDR_CTB1 = 2uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< CTB1 */ - CY_SAR_POS_PORT_ADDR_CTB2 = 3uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< CTB2 */ - CY_SAR_POS_PORT_ADDR_CTB3 = 4uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< CTB3 */ - CY_SAR_POS_PORT_ADDR_AROUTE_VIRT2 = 5uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT2) */ - CY_SAR_POS_PORT_ADDR_AROUTE_VIRT1 = 6uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT1) */ - CY_SAR_POS_PORT_ADDR_SARMUX_VIRT = 7uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< SARMUX virtual port (VPORT0) */ + CY_SAR_POS_PORT_ADDR_SARMUX = 0uL, /**< Dedicated SARMUX port with 8 possible pins */ + CY_SAR_POS_PORT_ADDR_CTB0 = 1uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< Outputs from CTB0, if present */ + CY_SAR_POS_PORT_ADDR_CTB1 = 2uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< Outputs from CTB1, if present */ + CY_SAR_POS_PORT_ADDR_CTB2 = 3uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< Outputs from CTB2, if present */ + CY_SAR_POS_PORT_ADDR_CTB3 = 4uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< Outputs from CTB3, if present */ + CY_SAR_POS_PORT_ADDR_AROUTE_VIRT2 = 5uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT2), if present */ + CY_SAR_POS_PORT_ADDR_AROUTE_VIRT1 = 6uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT1), if present */ + CY_SAR_POS_PORT_ADDR_SARMUX_VIRT = 7uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< SARMUX virtual port for DieTemp and AMUXBUSA/B */ }cy_en_sar_chan_config_pos_port_addr_t; /** Enable or disable averaging for the channel */ @@ -715,7 +1100,8 @@ typedef enum }cy_en_sar_chan_config_avg_en_t; /** Select which sample time to use for the channel. -* There are four global samples times available. +* There are four global samples times available set by \ref group_sar_init_struct_sampleTime01 and +* \ref group_sar_init_struct_sampleTime23. */ typedef enum { @@ -728,14 +1114,14 @@ typedef enum /** Configure address of the pin connected to the Vminus terminal of the SARADC. */ typedef enum { - CY_SAR_CHAN_NEG_PIN_ADDR_0 = 0uL, /**< Pin 0 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_1 = 1uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 1 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_2 = 2uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 2 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_3 = 3uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 3 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_4 = 4uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 4 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_5 = 5uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 5 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_6 = 6uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 6 on port specified in NEG_PORT_ADDR */ - CY_SAR_CHAN_NEG_PIN_ADDR_7 = 7uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 7 on port specified in NEG_PORT_ADDR */ + CY_SAR_CHAN_NEG_PIN_ADDR_0 = 0uL, /**< Pin 0 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_1 = 1uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 1 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_2 = 2uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 2 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_3 = 3uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 3 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_4 = 4uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 4 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_5 = 5uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 5 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_6 = 6uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 6 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ + CY_SAR_CHAN_NEG_PIN_ADDR_7 = 7uL << SAR_CHAN_CONFIG_NEG_PIN_ADDR_Pos, /**< Pin 7 on port specified in \ref cy_en_sar_chan_config_neg_port_addr_t */ }cy_en_sar_chan_config_neg_pin_addr_t; /** Configure address of the port that contains the pin connected to the Vminus terminal of the SARADC. @@ -746,10 +1132,10 @@ typedef enum */ typedef enum { - CY_SAR_NEG_PORT_ADDR_SARMUX = 0uL, /**< SARMUX pins */ - CY_SAR_NEG_PORT_ADDR_AROUTE_VIRT2 = 5uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT2) */ - CY_SAR_NEG_PORT_ADDR_AROUTE_VIRT1 = 6uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT1) */ - CY_SAR_NEG_PORT_ADDR_SARMUX_VIRT = 7uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< SARMUX virtual port (VPORT0) */ + CY_SAR_NEG_PORT_ADDR_SARMUX = 0uL, /**< Dedicated SARMUX port with 8 possible pins */ + CY_SAR_NEG_PORT_ADDR_AROUTE_VIRT2 = 5uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT2), if present */ + CY_SAR_NEG_PORT_ADDR_AROUTE_VIRT1 = 6uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< AROUTE virtual port (VPORT1), if present */ + CY_SAR_NEG_PORT_ADDR_SARMUX_VIRT = 7uL << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos, /**< SARMUX virtual port for AMUXBUSA/B */ }cy_en_sar_chan_config_neg_port_addr_t; /* \} */ @@ -760,7 +1146,7 @@ typedef enum */ /** Configure which signal will cause an interrupt event. * -* - End of Scan (EOS): occurs after completing a scan of all enabled channels +* - End of scan (EOS): occurs after completing a scan of all enabled channels * - Overflow: occurs when hardware sets a new EOS interrupt while the previous interrupt * has not be cleared by the firmware * - Firmware collision: occurs when firmware attempts to start one-shot @@ -775,82 +1161,87 @@ typedef enum CY_SAR_INTR_OVERFLOW_MASK = SAR_INTR_MASK_OVERFLOW_MASK_Msk, /**< Enable overflow interrupt */ CY_SAR_INTR_FW_COLLISION_MASK = SAR_INTR_MASK_FW_COLLISION_MASK_Msk, /**< Enable firmware collision interrupt */ }cy_en_sar_intr_mask_t; + /* \} */ /** \addtogroup group_sar_mux_switch_register_enums -* This set of enumerations aids in configuring the SAR MUX_SWITCH and MUX_SQ_CTRL register +* This set of enumerations aids in configuring the \ref group_sar_init_struct_muxSwitch and \ref group_sar_init_struct_muxSwitchSqCtrl registers * \{ */ /** Firmware control for the SARMUX switches to connect analog signals to the SAR ADC * -* To close multiple switches, OR the enum values together. +* To close multiple switches, "OR" the enum values together. +* +* See the \ref group_sar_sarmux section for more guidance. */ typedef enum { /* SARMUX pins to Vplus */ - CY_SAR_MUX_FW_P0_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P0_VPLUS_Msk, /**< Switch between pin P0 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P1_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P1_VPLUS_Msk, /**< Switch between pin P1 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P2_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P2_VPLUS_Msk, /**< Switch between pin P2 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P3_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P3_VPLUS_Msk, /**< Switch between pin P3 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P4_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P4_VPLUS_Msk, /**< Switch between pin P4 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P5_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P5_VPLUS_Msk, /**< Switch between pin P5 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P6_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P6_VPLUS_Msk, /**< Switch between pin P6 of SARMUX and Vplus of SAR ADC */ - CY_SAR_MUX_FW_P7_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P7_VPLUS_Msk, /**< Switch between pin P7 of SARMUX and Vplus of SAR ADC */ + CY_SAR_MUX_FW_P0_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P0_VPLUS_Msk, /**< Switch between Pin 0 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P1_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P1_VPLUS_Msk, /**< Switch between Pin 1 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P2_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P2_VPLUS_Msk, /**< Switch between Pin 2 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P3_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P3_VPLUS_Msk, /**< Switch between Pin 3 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P4_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P4_VPLUS_Msk, /**< Switch between Pin 4 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P5_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P5_VPLUS_Msk, /**< Switch between Pin 5 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P6_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P6_VPLUS_Msk, /**< Switch between Pin 6 of SARMUX and Vplus of SARADC */ + CY_SAR_MUX_FW_P7_VPLUS = SAR_MUX_SWITCH0_MUX_FW_P7_VPLUS_Msk, /**< Switch between Pin 7 of SARMUX and Vplus of SARADC */ /* SARMUX pins to Vminus */ - CY_SAR_MUX_FW_P0_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P0_VMINUS_Msk, /**< Switch between pin P0 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P1_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P1_VMINUS_Msk, /**< Switch between pin P1 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P2_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P2_VMINUS_Msk, /**< Switch between pin P2 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P3_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P3_VMINUS_Msk, /**< Switch between pin P3 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P4_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P4_VMINUS_Msk, /**< Switch between pin P4 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P5_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P5_VMINUS_Msk, /**< Switch between pin P5 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P6_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P6_VMINUS_Msk, /**< Switch between pin P6 of SARMUX and Vminus of SAR ADC */ - CY_SAR_MUX_FW_P7_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P7_VMINUS_Msk, /**< Switch between pin P7 of SARMUX and Vminus of SAR ADC */ + CY_SAR_MUX_FW_P0_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P0_VMINUS_Msk, /**< Switch between Pin 0 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P1_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P1_VMINUS_Msk, /**< Switch between Pin 1 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P2_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P2_VMINUS_Msk, /**< Switch between Pin 2 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P3_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P3_VMINUS_Msk, /**< Switch between Pin 3 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P4_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P4_VMINUS_Msk, /**< Switch between Pin 4 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P5_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P5_VMINUS_Msk, /**< Switch between Pin 5 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P6_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P6_VMINUS_Msk, /**< Switch between Pin 6 of SARMUX and Vminus of SARADC */ + CY_SAR_MUX_FW_P7_VMINUS = SAR_MUX_SWITCH0_MUX_FW_P7_VMINUS_Msk, /**< Switch between Pin 7 of SARMUX and Vminus of SARADC */ /* Vssa to Vminus and temperature sensor to Vplus */ - CY_SAR_MUX_FW_VSSA_VMINUS = SAR_MUX_SWITCH0_MUX_FW_VSSA_VMINUS_Msk, /**< Switch between Vssa_Kelvin and Vminus of SAR ADC */ - CY_SAR_MUX_FW_TEMP_VPLUS = SAR_MUX_SWITCH0_MUX_FW_TEMP_VPLUS_Msk, /**< Switch between temperature sensor and vplus of SAR ADC */ + CY_SAR_MUX_FW_VSSA_VMINUS = SAR_MUX_SWITCH0_MUX_FW_VSSA_VMINUS_Msk, /**< Switch between VSSA and Vminus of SARADC */ + CY_SAR_MUX_FW_TEMP_VPLUS = SAR_MUX_SWITCH0_MUX_FW_TEMP_VPLUS_Msk, /**< Switch between the DieTemp sensor and vplus of SARADC */ /* Amuxbus A and B to Vplus and Vminus */ - CY_SAR_MUX_FW_AMUXBUSA_VPLUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSA_VPLUS_Msk, /**< Switch between amuxbusa and vplus of SAR ADC */ - CY_SAR_MUX_FW_AMUXBUSB_VPLUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSB_VPLUS_Msk, /**< Switch between amuxbusb and vplus of SAR ADC */ - CY_SAR_MUX_FW_AMUXBUSA_VMINUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSA_VMINUS_Msk, /**< Switch between amuxbusa and vminus of SAR ADC */ - CY_SAR_MUX_FW_AMUXBUSB_VMINUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSB_VMINUS_Msk, /**< Switch between amuxbusb and vminus of SAR ADC */ + CY_SAR_MUX_FW_AMUXBUSA_VPLUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSA_VPLUS_Msk, /**< Switch between AMUXBUSA and vplus of SARADC */ + CY_SAR_MUX_FW_AMUXBUSB_VPLUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSB_VPLUS_Msk, /**< Switch between AMUXBUSB and vplus of SARADC */ + CY_SAR_MUX_FW_AMUXBUSA_VMINUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSA_VMINUS_Msk, /**< Switch between AMUXBUSA and vminus of SARADC */ + CY_SAR_MUX_FW_AMUXBUSB_VMINUS = SAR_MUX_SWITCH0_MUX_FW_AMUXBUSB_VMINUS_Msk, /**< Switch between AMUXBUSB and vminus of SARADC */ /* Sarbus 0 and 1 to Vplus and Vminus */ - CY_SAR_MUX_FW_SARBUS0_VPLUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS0_VPLUS_Msk, /**< Switch between sarbus0 and vplus of SAR ADC */ - CY_SAR_MUX_FW_SARBUS1_VPLUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS1_VPLUS_Msk, /**< Switch between sarbus1 and vplus of SAR ADC */ - CY_SAR_MUX_FW_SARBUS0_VMINUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS0_VMINUS_Msk, /**< Switch between sarbus0 and vminus of SAR ADC */ - CY_SAR_MUX_FW_SARBUS1_VMINUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS1_VMINUS_Msk, /**< Switch between sarbus1 and vminus of SAR ADC */ + CY_SAR_MUX_FW_SARBUS0_VPLUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS0_VPLUS_Msk, /**< Switch between SARBUS0 and vplus of SARADC */ + CY_SAR_MUX_FW_SARBUS1_VPLUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS1_VPLUS_Msk, /**< Switch between SARBUS1 and vplus of SARADC */ + CY_SAR_MUX_FW_SARBUS0_VMINUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS0_VMINUS_Msk, /**< Switch between SARBUS0 and vminus of SARADC */ + CY_SAR_MUX_FW_SARBUS1_VMINUS = SAR_MUX_SWITCH0_MUX_FW_SARBUS1_VMINUS_Msk, /**< Switch between SARBUS1 and vminus of SARADC */ /* SARMUX pins to Core IO */ - CY_SAR_MUX_FW_P4_COREIO0 = SAR_MUX_SWITCH0_MUX_FW_P4_COREIO0_Msk, /**< Switch between pin P4 of SARMUX and coreio0 */ - CY_SAR_MUX_FW_P5_COREIO1 = SAR_MUX_SWITCH0_MUX_FW_P5_COREIO1_Msk, /**< Switch between pin P5 of SARMUX and coreio1 */ - CY_SAR_MUX_FW_P6_COREIO2 = SAR_MUX_SWITCH0_MUX_FW_P6_COREIO2_Msk, /**< Switch between pin P6 of SARMUX and coreio2 */ - CY_SAR_MUX_FW_P7_COREIO3 = SAR_MUX_SWITCH0_MUX_FW_P7_COREIO3_Msk, /**< Switch between pin P7 of SARMUX and coreio3 */ + CY_SAR_MUX_FW_P4_COREIO0 = SAR_MUX_SWITCH0_MUX_FW_P4_COREIO0_Msk, /**< Switch between Pin 4 of SARMUX and coreio0, if present */ + CY_SAR_MUX_FW_P5_COREIO1 = SAR_MUX_SWITCH0_MUX_FW_P5_COREIO1_Msk, /**< Switch between Pin 5 of SARMUX and coreio1, if present */ + CY_SAR_MUX_FW_P6_COREIO2 = SAR_MUX_SWITCH0_MUX_FW_P6_COREIO2_Msk, /**< Switch between Pin 6 of SARMUX and coreio2, if present */ + CY_SAR_MUX_FW_P7_COREIO3 = SAR_MUX_SWITCH0_MUX_FW_P7_COREIO3_Msk, /**< Switch between Pin 7 of SARMUX and coreio3, if present */ }cy_en_sar_mux_switch_fw_ctrl_t; -/** Enable SAR sequencer control for the SARMUX switches +/** Mask definitions of SARMUX switches that can be controlled by the SARSEQ. * -* To enable sequencer control of multiple switches, OR the enum values together. +* To enable sequencer control of multiple switches, "OR" the enum values together. +* +* See the \ref group_sar_sarmux section for more guidance. */ typedef enum { - CY_SAR_MUX_SQ_CTRL_P0 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P0_Msk, /**< Give SARSEQ control of P0 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P1 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P1_Msk, /**< Give SARSEQ control of P1 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P2 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P2_Msk, /**< Give SARSEQ control of P2 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P3 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P3_Msk, /**< Give SARSEQ control of P3 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P4 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P4_Msk, /**< Give SARSEQ control of P4 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P5 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P5_Msk, /**< Give SARSEQ control of P5 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P6 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P6_Msk, /**< Give SARSEQ control of P6 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_P7 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P7_Msk, /**< Give SARSEQ control of P7 switches (for Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_VSSA = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_VSSA_Msk, /**< Give SARSEQ control of the switch between vssa and Vminus */ - CY_SAR_MUX_SQ_CTRL_TEMP = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_TEMP_Msk, /**< Give SARSEQ control of the switch between temp and Vplus */ - CY_SAR_MUX_SQ_CTRL_AMUXBUSA = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_AMUXBUSA_Msk, /**< Give SARSEQ control of amuxbusa switches (vor Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_AMUXBUSB = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_AMUXBUSB_Msk, /**< Give SARSEQ control of amuxbusb switches (vor Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_SARBUS0 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_SARBUS0_Msk, /**< Give SARSEQ control of sarbus0 switches (vor Vplus and Vminus) */ - CY_SAR_MUX_SQ_CTRL_SARBUS1 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_SARBUS1_Msk, /**< Give SARSEQ control of sarbus1 switches (vor Vplus and Vminus) */ + CY_SAR_MUX_SQ_CTRL_P0 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P0_Msk, /**< Enable SARSEQ control of Pin 0 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P1 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P1_Msk, /**< Enable SARSEQ control of Pin 1 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P2 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P2_Msk, /**< Enable SARSEQ control of Pin 2 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P3 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P3_Msk, /**< Enable SARSEQ control of Pin 3 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P4 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P4_Msk, /**< Enable SARSEQ control of Pin 4 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P5 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P5_Msk, /**< Enable SARSEQ control of Pin 5 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P6 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P6_Msk, /**< Enable SARSEQ control of Pin 6 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_P7 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_P7_Msk, /**< Enable SARSEQ control of Pin 7 switches (for Vplus and Vminus) of SARMUX dedicated port */ + CY_SAR_MUX_SQ_CTRL_VSSA = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_VSSA_Msk, /**< Enable SARSEQ control of the switch between VSSA and Vminus */ + CY_SAR_MUX_SQ_CTRL_TEMP = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_TEMP_Msk, /**< Enable SARSEQ control of the switch between DieTemp and Vplus */ + CY_SAR_MUX_SQ_CTRL_AMUXBUSA = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_AMUXBUSA_Msk, /**< Enable SARSEQ control of AMUXBUSA switches (for Vplus and Vminus) */ + CY_SAR_MUX_SQ_CTRL_AMUXBUSB = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_AMUXBUSB_Msk, /**< Enable SARSEQ control of AMUXBUSB switches (for Vplus and Vminus) */ + CY_SAR_MUX_SQ_CTRL_SARBUS0 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_SARBUS0_Msk, /**< Enable SARSEQ control of SARBUS0 switches (for Vplus and Vminus) */ + CY_SAR_MUX_SQ_CTRL_SARBUS1 = SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_SARBUS1_Msk, /**< Enable SARSEQ control of SARBUS1 switches (for Vplus and Vminus) */ }cy_en_sar_mux_switch_sq_ctrl_t; /* \} */ @@ -872,192 +1263,25 @@ typedef enum * A set of enumerations is provided in this * driver to help with configuring this structure. * -*
VersionChangesReason for Change
1.10 Added workaround for parts with out of range CAP_TRIM in Init API. Correct CAP_TRIM is necessary achieving specified SAR ADC linearity
Turn off the entire hardware block only if the SARMUX is not enabled +* for Deep Sleep operation. +* Improvement of the \ref Cy_SAR_Sleep flow
Updated "Low Power Support" section to describe registering the Deep Sleep callback. +* Added parenthesis around logical AND operation in Sleep API.Documentation update and clarification
1.0Initial version
-* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
Data FieldConfiguration
ctrlThis global configuration register contains options that apply to all channels. -* Select a value from each of the following enum and "OR" them together to form this ctrl: -* - \ref cy_en_sar_ctrl_pwr_ctrl_vref_t -* - \ref cy_en_sar_ctrl_vref_sel_t -* - \ref cy_en_sar_ctrl_bypass_cap_t -* - \ref cy_en_sar_ctrl_neg_sel_t -* - \ref cy_en_sar_ctrl_hw_ctrl_negvref_t -* - \ref cy_en_sar_ctrl_comp_delay_t -* - \ref cy_en_sar_ctrl_refbuf_en_t -* - \ref cy_en_sar_ctrl_comp_pwr_t -* - \ref cy_en_sar_ctrl_deepsleep_on_t -* - \ref cy_en_sar_ctrl_sarseq_routing_switches_t -* -* Note that all these enums begin with cy_en_sar_ctrl_*. -*
enableIf true, enable the hardware at the end of initialization. If false, -* a call to \ref Cy_SAR_Enable is required to enable the hardware. -*
sampleCtrlThis global configuration register contain options that apply to all channels. -* Select a value from each of the following enum and "OR" them together to form this sampleCtrl: -* - \ref cy_en_sar_sample_ctrl_align_t -* - \ref cy_en_sar_sample_ctrl_single_ended_signed_t -* - \ref cy_en_sar_sample_ctrl_differential_signed_t -* - \ref cy_en_sar_sample_ctrl_avg_cnt_signed_t -* - \ref cy_en_sar_sample_ctrl_avg_mode_t -* - \ref cy_en_sar_sample_ctrl_trigger_mode_t -* -* Note that all these enums begin with cy_en_sar_sample*. -*
sampleTime01Configure the value for sample time choices 0 and 1. -* The SARADC supports a programmable sample time (aperture). To make this capability -* available across multiple channels, without slowing them down collectively to the -* slowest common denominator, there are four fully programmable 10-bit sample times. -* 10 bits allow for a range of 0 to 1023 cycles, however 0 and 1 are invalid. -* The minimum sample time is 167 ns. With an 18 MHz clock, this is -* equal to three cycles. The actual sample time is one cycle less than -* the sample time register value, so the minimum register value is 4. -* -* Use the shifts defined in \ref cy_en_sar_sample_time_shift_t when setting this register. -* For example, -* -* sampleTime01 = (4uL << CY_SAR_SAMPLE_TIME0_SHIFT) | -* (5uL << CY_SAR_SAMPLE_TIME1_SHIFT); -*
sampleTime23Configure the value for sample time choices 2 and 3. -* Use the shifts defined in \ref cy_en_sar_sample_time_shift_t when setting this register. -* For example, -* -* sampleTime23 = (4uL << CY_SAR_SAMPLE_TIME2_SHIFT) | -* (5uL << CY_SAR_SAMPLE_TIME3_SHIFT); -*
rangeThresConfigure the upper and lower thresholds for range detection. -* The SARSEQ supports range detection to allow for automatic detection of sample values -* compared to two programmable thresholds without CPU involvement. -* Range detection is defined by two global thresholds and a condition. -* The RANGE_LOW value defines the lower threshold and RANGE_HIGH defines the upper threshold of the range. -* Range detect is done after averaging, alignment, and sign extension (if applicable). In other words the -* thresholds values need to have the same data format as the result data (see Data alignment section above). -* Range detection is always done for all channels scanned. -* The values here are interpreted signed or unsigned according to the channel configuration. -* -* Use the shifts defined in \ref cy_en_sar_range_thres_shift_t when setting this register. -* For example, -* -* rangeThres = (0xFFuL << CY_SAR_LIMIT_LOW_SHIFT) | -* (0x3FFuL << CY_SAR_LIMIT_HIGH_SHIFT); -*
rangeCondConfigure the condition that will trigger the range detect interrupt. -* Select a value from the \ref cy_en_sar_range_detect_condition_t enum. -*
chanEnConfigure which channels will be scanned. -* All enabled channels will be scanned when the next trigger happens. -* -* Each bit corresponds to a channel. For example, setting chanEn = 0x7 -* will enable channels 0, 1, and 2. -*
chanConfig[CY_SAR_MAX_NUM_CHANNELS] Each of the channels has its own channel configuration register. -* The channel configuration specifies which pin/signal that channel converts -* and how to do that conversion. The number of channels is 8, 12, or 16 depending on the device. -* Select a value from each of the following enum and "OR" them together to form the chanConfig: -* - \ref cy_en_sar_chan_config_input_mode_t -* - \ref cy_en_sar_chan_config_pos_pin_addr_t -* - \ref cy_en_sar_chan_config_pos_port_addr_t -* - \ref cy_en_sar_chan_config_avg_en_t -* - \ref cy_en_sar_chan_config_sample_time_t -* - \ref cy_en_sar_chan_config_neg_pin_addr_t -* - \ref cy_en_sar_chan_config_neg_port_addr_t -* -* Note that all these enums begin with h cy_en_sar_chan_config*. -*
intrMaskConfigure which interrupt source will be serviced by the firmware or ignore. -* The SAR interrupt to the NVIC is raised any time the intersection (logic and) of the interrupt -* flags and the corresponding interrupt masks are non-zero. -* When servicing an interrupt, the interrupt service routine is supposed to clear the interrupt source, -* after picking up any related data, by writing a 1 to the interrupt bit. -* -* The \ref cy_en_sar_intr_mask_t enum defines the mask for each interrupt source. -* Enable more than one by "OR"ing the masks together. For example, setting -* intrMask = CY_SAR_INTR_EOS_MASK | CY_SAR_INTR_OVERFLOW_MASK, both the -* end of scan (EOS) and overflow interrupts will be serviced by the NVIC. -*
satIntrMaskConfigure which channels will cause a saturate interrupt event. -* The SARSEQ has a saturation detect that is always applied to every conversion. -* This feature detects whether a sample value is equal to the minimum or the maximum value. -* This allows the firmware to take action, for example, discard the result, when the SARADC saturates. -* The sample value is tested right after conversion, that is, before averaging. This means that it -* can happen that the interrupt is set while the averaged result in the data register is not -* equal to the minimum or maximum. To enable a fast response to saturation this interrupt flag -* is set immediately, that is, before the full scan or even averaging for the channel is completed. -* -* Each bit corresponds to a channel. For example, setting the satIntrMask -* to 0x05 will enable channels 0 and 2 for saturation detection. -*
rangeIntrMaskConfigure which channels will cause a range detection interrupt event -* Each bit corresponds to a channel. For example, setting the rangeIntrMask -* to 0x03 will enable channels 0 and 1 for range detection. -* Setting rangeIntrMask to 0, the firmware will ignore the range detect interrupt for any channel. -*
muxSwitchFirmware control of the SARMUX switches. -* The \ref cy_en_sar_mux_switch_fw_ctrl_t enum defines the mask for the switches. -* "OR" the masks together to close multiple switches. -*
muxSwitchSqCtrlConfigure SAR sequencer control of the SARMUX switches. -* The \ref cy_en_sar_mux_switch_sq_ctrl_t enum defines the mask for sequencer control for the switches. -* "OR" the masks together to enable sequencer control of multiple switches. -*
configRoutingIf true, the \ref Cy_SAR_Init function will apply the muxSwitch and muxSwitchSqCtrl values. -* If false, the two values will be ignored. -*
vrefMvValueThe value of the reference voltage in millivolts used for converting counts -* to voltage in the \ref Cy_SAR_CountsTo_Volts, \ref Cy_SAR_CountsTo_mVolts, and -* \ref Cy_SAR_CountsTo_uVolts functions. -*
+* See the \ref group_sar_initialization section for guidance. **/ typedef struct { - uint32_t ctrl; /**< Control register */ - bool enable; /**< Enable hardware after initialization */ - uint32_t sampleCtrl; /**< Sample control register */ - uint32_t sampleTime01; /**< Sample time in ADC clocks for ST0 and ST1 */ - uint32_t sampleTime23; /**< Sample time in ADC clocks for ST2 and ST3 */ + uint32_t ctrl; /**< Control register settings (applies to all channels) */ + uint32_t sampleCtrl; /**< Sample control register settings (applies to all channels) */ + uint32_t sampleTime01; /**< Sample time in ADC clocks for Sample Time 0 and 1 */ + uint32_t sampleTime23; /**< Sample time in ADC clocks for Sample Time 2 and 3 */ uint32_t rangeThres; /**< Range detect threshold register for all channels */ - cy_en_sar_range_detect_condition_t rangeCond; /**< Range detect mode for all channels */ + cy_en_sar_range_detect_condition_t rangeCond; /**< Range detect condition (below, inside, output, or above) for all channels */ uint32_t chanEn; /**< Enable bits for the channels */ - uint32_t chanConfig[CY_SAR_MAX_NUM_CHANNELS]; /**< Channel configuration registers */ + uint32_t chanConfig[CY_SAR_MAX_NUM_CHANNELS]; /**< Channel configuration */ uint32_t intrMask; /**< Interrupt enable mask */ - uint32_t satIntrMask; /**< Saturate interrupt mask register */ - uint32_t rangeIntrMask; /**< Range interrupt mask register */ + uint32_t satIntrMask; /**< Saturation detection interrupt enable mask */ + uint32_t rangeIntrMask; /**< Range detection interrupt enable mask */ uint32_t muxSwitch; /**< SARMUX firmware switches to connect analog signals to SAR */ - uint32_t muxSwitchSqCtrl; /**< SARMUX Switch SAR sequencer control */ + uint32_t muxSwitchSqCtrl; /**< Enable SARSEQ control of specific SARMUX switches */ bool configRouting; /**< Configure or ignore routing related registers (muxSwitch, muxSwitchSqCtrl) */ - uint32_t vrefMvValue; /**< Reference voltage in millivolts used in counts to volts conversion */ + uint32_t vrefMvValue; /**< Reference voltage in millivolts used in converting counts to volts */ } cy_stc_sar_config_t; /** This structure is used by the driver to backup the state of the SAR @@ -1112,7 +1336,7 @@ void Cy_SAR_SetConvertMode(SAR_Type *base, cy_en_sar_sample_ctrl_trigger_mode_t __STATIC_INLINE void Cy_SAR_SetChanMask(SAR_Type *base, uint32_t enableMask); void Cy_SAR_SetLowLimit(SAR_Type *base, uint32_t lowLimit); void Cy_SAR_SetHighLimit(SAR_Type *base, uint32_t highLimit); -__STATIC_INLINE void Cy_SAR_SetLimitCondition(SAR_Type *base, cy_en_sar_range_detect_condition_t cond); +__STATIC_INLINE void Cy_SAR_SetRangeCond(SAR_Type *base, cy_en_sar_range_detect_condition_t cond); /** \} */ /** \addtogroup group_sar_functions_countsto @@ -1129,8 +1353,6 @@ cy_en_sar_status_t Cy_SAR_SetGain(uint32_t chan, int32_t adcGain); /** \addtogroup group_sar_functions_switches * This set of functions is for controlling/querying the SARMUX switches -* The following figure shows the SARMUX switches. See the device datasheet for the exact location of SARMUX pins. -* \image html sar_sarmux_switches.png * \{ */ void Cy_SAR_SetAnalogSwitch(SAR_Type *base, cy_en_sar_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_sar_switch_state_t state); @@ -1141,29 +1363,31 @@ __STATIC_INLINE void Cy_SAR_SetVssaSarSeqCtrl(SAR_Type *base, cy_en_sar_switch_s /** \} */ /** \addtogroup group_sar_functions_interrupt -* This set of functions are related to SAR interrupts +* This set of functions are related to SAR interrupts. * \{ */ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatus(const SAR_Type *base); __STATIC_INLINE void Cy_SAR_ClearInterrupt(SAR_Type *base, uint32_t intrMask); -__STATIC_INLINE void Cy_SAR_SetSwInterrupt(SAR_Type *base, uint32_t intrMask); +__STATIC_INLINE void Cy_SAR_SetInterrupt(SAR_Type *base, uint32_t intrMask); __STATIC_INLINE void Cy_SAR_SetInterruptMask(SAR_Type *base, uint32_t intrMask); __STATIC_INLINE uint32_t Cy_SAR_GetInterruptMask(const SAR_Type *base); __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatusMasked(const SAR_Type *base); -__STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptStatus(const SAR_Type *base); -__STATIC_INLINE void Cy_SAR_ClearLimitInterrupt(SAR_Type *base, uint32_t chanMask); -__STATIC_INLINE void Cy_SAR_SetSwLimitInterrupt(SAR_Type *base, uint32_t chanMask); -__STATIC_INLINE void Cy_SAR_SetLimitInterruptMask(SAR_Type *base, uint32_t chanMask); -__STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptMask(const SAR_Type *base); -__STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptStatusMasked(const SAR_Type *base); +__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptStatus(const SAR_Type *base); +__STATIC_INLINE void Cy_SAR_ClearRangeInterrupt(SAR_Type *base, uint32_t chanMask); +__STATIC_INLINE void Cy_SAR_SetRangeInterrupt(SAR_Type *base, uint32_t chanMask); +__STATIC_INLINE void Cy_SAR_SetRangeInterruptMask(SAR_Type *base, uint32_t chanMask); +__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptMask(const SAR_Type *base); +__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptStatusMasked(const SAR_Type *base); __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatus(const SAR_Type *base); __STATIC_INLINE void Cy_SAR_ClearSatInterrupt(SAR_Type *base, uint32_t chanMask); -__STATIC_INLINE void Cy_SAR_SetSwSatInterrupt(SAR_Type *base, uint32_t chanMask); +__STATIC_INLINE void Cy_SAR_SetSatInterrupt(SAR_Type *base, uint32_t chanMask); __STATIC_INLINE void Cy_SAR_SetSatInterruptMask(SAR_Type *base, uint32_t chanMask); __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptMask(const SAR_Type *base); __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatusMasked(const SAR_Type *base); + +__STATIC_INLINE uint32_t Cy_SAR_GetInterruptCause(const SAR_Type *base); /** \} */ @@ -1201,16 +1425,23 @@ __STATIC_INLINE void Cy_SAR_Disable(SAR_Type *base) * Function Name: Cy_SAR_GetChanResultUpdated ****************************************************************************//** * -* Gets the data available in the channel result update register. -* Each bit of the result corresponds to the channel. -* When sequential accumulative or interleaved averaging is enabled, -* the channel result will be invalid until the desired number of -* samples has been averaged. +* Return whether the RESULT register has been updated or not. +* If the bit is high, the corresponding channel RESULT register was updated, +* i.e. was sampled during the previous scan and, in case of Interleaved averaging, +* reached the averaging count. +* If the bit is low, the corresponding channel is not enabled or the averaging count +* is not yet reached for Interleaved averaging. * * \param base * Pointer to structure describing registers * -* \return uint32_t +* \return +* Each bit of the result corresponds to the channel. +* Bit 0 is for channel 0, etc. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_CHAN_RESULT_UPDATED * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetChanResultUpdated(const SAR_Type *base) @@ -1226,7 +1457,7 @@ __STATIC_INLINE uint32_t Cy_SAR_GetChanResultUpdated(const SAR_Type *base) * Function Name: Cy_SAR_SetChanMask ****************************************************************************//** * -* Sets the enable/disable mask for the channels. +* Set the enable/disable mask for the channels. * * \param base * Pointer to structure describing registers @@ -1238,6 +1469,10 @@ __STATIC_INLINE uint32_t Cy_SAR_GetChanResultUpdated(const SAR_Type *base) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SET_CHAN_MASK +* *******************************************************************************/ __STATIC_INLINE void Cy_SAR_SetChanMask(SAR_Type *base, uint32_t enableMask) { @@ -1247,10 +1482,10 @@ __STATIC_INLINE void Cy_SAR_SetChanMask(SAR_Type *base, uint32_t enableMask) } /******************************************************************************* -* Function Name: Cy_SAR_SetLimitCondition +* Function Name: Cy_SAR_SetRangeCond ****************************************************************************//** * -* Sets the condition in which limit detection interrupts are triggered. +* Set the condition in which range detection interrupts are triggered. * * \param base * Pointer to structure describing registers @@ -1260,10 +1495,14 @@ __STATIC_INLINE void Cy_SAR_SetChanMask(SAR_Type *base, uint32_t enableMask) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SET_RANGE_COND +* *******************************************************************************/ -__STATIC_INLINE void Cy_SAR_SetLimitCondition(SAR_Type *base, cy_en_sar_range_detect_condition_t cond) +__STATIC_INLINE void Cy_SAR_SetRangeCond(SAR_Type *base, cy_en_sar_range_detect_condition_t cond) { - CY_ASSERT_L3(CY_SAR_LIMITCOND(cond)); + CY_ASSERT_L3(CY_SAR_RANGECOND(cond)); base->RANGE_COND = (uint32_t)cond << SAR_RANGE_COND_RANGE_COND_Pos; } @@ -1277,13 +1516,17 @@ __STATIC_INLINE void Cy_SAR_SetLimitCondition(SAR_Type *base, cy_en_sar_range_de * Function Name: Cy_SAR_GetInterruptStatus ****************************************************************************//** * -* Returns the interrupt register status. +* Return the interrupt register status. * * \param base * Pointer to structure describing registers * * \return Interrupt status * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_ISR +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatus(const SAR_Type *base) { @@ -1294,7 +1537,7 @@ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatus(const SAR_Type *base) * Function Name: Cy_SAR_ClearInterrupt ****************************************************************************//** * -* Clears the interrupt. +* Clear the interrupt. * The interrupt must be cleared with this function so that the hardware * can set subsequent interrupts and those interrupts can be forwarded * to the interrupt controller, if enabled. @@ -1303,10 +1546,12 @@ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatus(const SAR_Type *base) * Pointer to structure describing registers * * \param intrMask -* The mask of interrupts to clear. -* - Bit 0: EOS_INTR -* - Bit 1: OVERFLOW_INTR -* - Bit 2: FW_COLLISION_INTR +* The mask of interrupts to clear. Typically this will be the value returned +* from \ref Cy_SAR_GetInterruptStatus. +* Alternately, select one or more values from \ref cy_en_sar_intr_mask_t and "OR" them together. +* - \ref CY_SAR_INTR_EOS_MASK +* - \ref CY_SAR_INTR_OVERFLOW_MASK +* - \ref CY_SAR_INTR_FW_COLLISION_MASK * * \return None * @@ -1316,27 +1561,31 @@ __STATIC_INLINE void Cy_SAR_ClearInterrupt(SAR_Type *base, uint32_t intrMask) CY_ASSERT_L2(CY_SAR_INTRMASK(intrMask)); base->INTR = intrMask; + + /* Dummy read for buffered writes. */ + (void) base->INTR; } /******************************************************************************* -* Function Name: Cy_SAR_SetSwInterrupt +* Function Name: Cy_SAR_SetInterrupt ****************************************************************************//** * -* Triggers an interrupt with software. +* Trigger an interrupt with software. * * \param base * Pointer to structure describing registers * * \param intrMask * The mask of interrupts to set. -* - Bit 0: EOS_INTR -* - Bit 1: OVERFLOW_INTR -* - Bit 2: FW_COLLISION_INTR +* Select one or more values from \ref cy_en_sar_intr_mask_t and "OR" them together. +* - \ref CY_SAR_INTR_EOS_MASK +* - \ref CY_SAR_INTR_OVERFLOW_MASK +* - \ref CY_SAR_INTR_FW_COLLISION_MASK * * \return None * *******************************************************************************/ -__STATIC_INLINE void Cy_SAR_SetSwInterrupt(SAR_Type *base, uint32_t intrMask) +__STATIC_INLINE void Cy_SAR_SetInterrupt(SAR_Type *base, uint32_t intrMask) { CY_ASSERT_L2(CY_SAR_INTRMASK(intrMask)); @@ -1347,19 +1596,25 @@ __STATIC_INLINE void Cy_SAR_SetSwInterrupt(SAR_Type *base, uint32_t intrMask) * Function Name: Cy_SAR_SetInterruptMask ****************************************************************************//** * -* Enables which interrupts can trigger the CPU interrupt controller. +* Enable which interrupts can trigger the CPU interrupt controller. * * \param base * Pointer to structure describing registers * * \param intrMask -* The mask of interrupts to enable. -* - Bit 0: EOS_INTR -* - Bit 1: OVERFLOW_INTR -* - Bit 2: FW_COLLISION_INTR +* The mask of interrupts. Select one or more values from \ref cy_en_sar_intr_mask_t +* and "OR" them together. +* - \ref CY_SAR_INTR_MASK_NONE : Disable EOS, overflow, and firmware collision interrupts. +* - \ref CY_SAR_INTR_EOS_MASK +* - \ref CY_SAR_INTR_OVERFLOW_MASK +* - \ref CY_SAR_INTR_FW_COLLISION_MASK * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SET_INTERRUPT_MASK +* *******************************************************************************/ __STATIC_INLINE void Cy_SAR_SetInterruptMask(SAR_Type *base, uint32_t intrMask) { @@ -1372,14 +1627,18 @@ __STATIC_INLINE void Cy_SAR_SetInterruptMask(SAR_Type *base, uint32_t intrMask) * Function Name: Cy_SAR_GetInterruptMask ****************************************************************************//** * -* Returns which interrupts can trigger the CPU interrupt controller +* Return which interrupts can trigger the CPU interrupt controller * as configured by \ref Cy_SAR_SetInterruptMask. * * \param base * Pointer to structure describing registers * -* \return uint32_t -* Interrupt mask +* \return +* Interrupt mask. Compare this value with masks in \ref cy_en_sar_intr_mask_t. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_INTERRUPT_MASK * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptMask(const SAR_Type *base) @@ -1391,14 +1650,14 @@ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptMask(const SAR_Type *base) * Function Name: Cy_SAR_GetInterruptStatusMasked ****************************************************************************//** * -* Returns the bitwise AND between the interrupt request and mask registers. +* Return the bitwise AND between the interrupt request and mask registers. * See \ref Cy_SAR_GetInterruptStatus and \ref Cy_SAR_GetInterruptMask. * * \param base * Pointer to structure describing registers * -* \return uint32_t -* Bitwise AND between the interrupt request and mask registers +* \return +* Bitwise AND of the interrupt request and mask registers * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatusMasked(const SAR_Type *base) @@ -1407,27 +1666,36 @@ __STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatusMasked(const SAR_Type *base) } /******************************************************************************* -* Function Name: Cy_SAR_GetLimitInterruptStatus +* Function Name: Cy_SAR_GetRangeInterruptStatus ****************************************************************************//** * -* Returns the limit interrupt register status. +* Return the range interrupt register status. +* If the status bit is low for a channel, the channel may not be enabled +* (\ref Cy_SAR_SetChanMask), range detection is not enabled for the +* channel (\ref Cy_SAR_SetRangeInterruptMask), or range detection was not +* triggered for the channel. * * \param base * Pointer to structure describing registers * -* \return Interrupt status +* \return +* The range interrupt status for all channels. Bit 0 is for channel 0, etc. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_RANGE_INTERRUPT_STATUS * *******************************************************************************/ -__STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptStatus(const SAR_Type *base) +__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptStatus(const SAR_Type *base) { return base->RANGE_INTR; } /******************************************************************************* -* Function Name: Cy_SAR_ClearLimitInterrupt +* Function Name: Cy_SAR_ClearRangeInterrupt ****************************************************************************//** * -* Clears the limit interrupt for the specified channel mask. +* Clear the range interrupt for the specified channel mask. * The interrupt must be cleared with this function so that * the hardware can set subset interrupts and those interrupts can * be forwarded to the interrupt controller, if enabled. @@ -1437,22 +1705,26 @@ __STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptStatus(const SAR_Type *base) * * \param chanMask * The channel mask. Bit 0 is for channel 0, etc. +* Typically, this is the value returned from \ref Cy_SAR_GetRangeInterruptStatus. * * \return None * *******************************************************************************/ -__STATIC_INLINE void Cy_SAR_ClearLimitInterrupt(SAR_Type *base, uint32_t chanMask) +__STATIC_INLINE void Cy_SAR_ClearRangeInterrupt(SAR_Type *base, uint32_t chanMask) { CY_ASSERT_L2(CY_SAR_CHANMASK(chanMask)); base->RANGE_INTR = chanMask; + + /* Dummy read for buffered writes. */ + (void) base->RANGE_INTR; } /******************************************************************************* -* Function Name: Cy_SAR_SetSwLimitInterrupt +* Function Name: Cy_SAR_SetRangeInterrupt ****************************************************************************//** * -* Triggers a limit interrupt with software for the specific channel mask. +* Trigger a range interrupt with software for the specific channel mask. * * \param base * Pointer to structure describing registers @@ -1463,7 +1735,7 @@ __STATIC_INLINE void Cy_SAR_ClearLimitInterrupt(SAR_Type *base, uint32_t chanMas * \return None * *******************************************************************************/ -__STATIC_INLINE void Cy_SAR_SetSwLimitInterrupt(SAR_Type *base, uint32_t chanMask) +__STATIC_INLINE void Cy_SAR_SetRangeInterrupt(SAR_Type *base, uint32_t chanMask) { CY_ASSERT_L2(CY_SAR_CHANMASK(chanMask)); @@ -1471,10 +1743,10 @@ __STATIC_INLINE void Cy_SAR_SetSwLimitInterrupt(SAR_Type *base, uint32_t chanMas } /******************************************************************************* -* Function Name: Cy_SAR_SetLimitInterruptMask +* Function Name: Cy_SAR_SetRangeInterruptMask ****************************************************************************//** * -* Enables which channels can trigger a limit interrupt. +* Enable which channels can trigger a range interrupt. * * \param base * Pointer to structure describing registers @@ -1484,8 +1756,12 @@ __STATIC_INLINE void Cy_SAR_SetSwLimitInterrupt(SAR_Type *base, uint32_t chanMas * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_SET_RANGE_INTERRUPT_MASK +* *******************************************************************************/ -__STATIC_INLINE void Cy_SAR_SetLimitInterruptMask(SAR_Type *base, uint32_t chanMask) +__STATIC_INLINE void Cy_SAR_SetRangeInterruptMask(SAR_Type *base, uint32_t chanMask) { CY_ASSERT_L2(CY_SAR_CHANMASK(chanMask)); @@ -1493,39 +1769,39 @@ __STATIC_INLINE void Cy_SAR_SetLimitInterruptMask(SAR_Type *base, uint32_t chanM } /******************************************************************************* -* Function Name: Cy_SAR_GetLimitInterruptMask +* Function Name: Cy_SAR_GetRangeInterruptMask ****************************************************************************//** * -* Returns which interrupts can trigger a range interrupt as configured by -* \ref Cy_SAR_SetLimitInterruptMask. +* Return which interrupts can trigger a range interrupt as configured by +* \ref Cy_SAR_SetRangeInterruptMask. * * \param base * Pointer to structure describing registers * -* \return uint32_t -* The limit mask register +* \return +* The range interrupt mask * *******************************************************************************/ -__STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptMask(const SAR_Type *base) +__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptMask(const SAR_Type *base) { return base->RANGE_INTR_MASK; } /******************************************************************************* -* Function Name: Cy_SAR_GetLimitInterruptStatusMasked +* Function Name: Cy_SAR_GetRangeInterruptStatusMasked ****************************************************************************//** * -* Returns the bitwise AND between the limit interrupt request and mask registers. -* See \ref Cy_SAR_GetLimitInterruptStatus and \ref Cy_SAR_GetLimitInterruptMask. +* Return the bitwise AND between the range interrupt request and mask registers. +* See \ref Cy_SAR_GetRangeInterruptStatus and \ref Cy_SAR_GetRangeInterruptMask. * * \param base * Pointer to structure describing registers * -* \return uint32_t -* Bitwise AND between the interrupt request and mask registers +* \return +* Bitwise AND between of range interrupt request and mask * *******************************************************************************/ -__STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptStatusMasked(const SAR_Type *base) +__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptStatusMasked(const SAR_Type *base) { return base->RANGE_INTR_MASKED; } @@ -1534,12 +1810,21 @@ __STATIC_INLINE uint32_t Cy_SAR_GetLimitInterruptStatusMasked(const SAR_Type *ba * Function Name: Cy_SAR_GetSatInterruptStatus ****************************************************************************//** * -* Returns the saturate interrupt register status. +* Return the saturate interrupt register status. +* If the status bit is low for a channel, the channel may not be enabled +* (\ref Cy_SAR_SetChanMask), saturation detection is not enabled for the +* channel (\ref Cy_SAR_SetSatInterruptMask), or saturation detection was not +* triggered for the channel. * * \param base * Pointer to structure describing registers * -* \return Interrupt status +* \return +* The saturate interrupt status for all channels. Bit 0 is for channel 0, etc. +* +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_SAT_INTERRUPT_STATUS * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatus(const SAR_Type *base) @@ -1551,7 +1836,7 @@ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatus(const SAR_Type *base) * Function Name: Cy_SAR_ClearSatInterrupt ****************************************************************************//** * -* Clears the saturate interrupt for the specified channel mask. +* Clear the saturate interrupt for the specified channel mask. * The interrupt must be cleared with this function so that the hardware * can set subsequent interrupts and those interrupts can be forwarded * to the interrupt controller, if enabled. @@ -1561,6 +1846,7 @@ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatus(const SAR_Type *base) * * \param chanMask * The channel mask. Bit 0 is for channel 0, etc. +* Typically, this is the value returned from \ref Cy_SAR_GetSatInterruptStatus. * * \return None * @@ -1570,13 +1856,16 @@ __STATIC_INLINE void Cy_SAR_ClearSatInterrupt(SAR_Type *base, uint32_t chanMask) CY_ASSERT_L2(CY_SAR_CHANMASK(chanMask)); base->SATURATE_INTR = chanMask; + + /* Dummy read for buffered writes. */ + (void) base->SATURATE_INTR; } /******************************************************************************* -* Function Name: Cy_SAR_SetSwSatInterrupt +* Function Name: Cy_SAR_SetSatInterrupt ****************************************************************************//** * -* Triggers a saturate interrupt with software for the specific channel mask. +* Trigger a saturate interrupt with software for the specific channel mask. * * \param base * Pointer to structure describing registers @@ -1587,7 +1876,7 @@ __STATIC_INLINE void Cy_SAR_ClearSatInterrupt(SAR_Type *base, uint32_t chanMask) * \return None * *******************************************************************************/ -__STATIC_INLINE void Cy_SAR_SetSwSatInterrupt(SAR_Type *base, uint32_t chanMask) +__STATIC_INLINE void Cy_SAR_SetSatInterrupt(SAR_Type *base, uint32_t chanMask) { CY_ASSERT_L2(CY_SAR_CHANMASK(chanMask)); @@ -1598,7 +1887,7 @@ __STATIC_INLINE void Cy_SAR_SetSwSatInterrupt(SAR_Type *base, uint32_t chanMask) * Function Name: Cy_SAR_SetSatInterruptMask ****************************************************************************//** * -* Enables which channels can trigger a saturate interrupt. +* Enable which channels can trigger a saturate interrupt. * * \param base * Pointer to structure describing registers @@ -1608,6 +1897,10 @@ __STATIC_INLINE void Cy_SAR_SetSwSatInterrupt(SAR_Type *base, uint32_t chanMask) * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_GET_SAT_INTERRUPT_MASK +* *******************************************************************************/ __STATIC_INLINE void Cy_SAR_SetSatInterruptMask(SAR_Type *base, uint32_t chanMask) { @@ -1620,14 +1913,14 @@ __STATIC_INLINE void Cy_SAR_SetSatInterruptMask(SAR_Type *base, uint32_t chanMas * Function Name: Cy_SAR_GetSatInterruptMask ****************************************************************************//** * -* Returns which interrupts can trigger a saturate interrupt as configured +* Return which interrupts can trigger a saturate interrupt as configured * by \ref Cy_SAR_SetSatInterruptMask. * * \param base * Pointer to structure describing registers * -* \return uint32_t -* The limit mask register +* \return +* The saturate interrupt mask. Bit 0 is for channel 0, etc. * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptMask(const SAR_Type *base) @@ -1639,14 +1932,14 @@ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptMask(const SAR_Type *base) * Function Name: Cy_SAR_GetSatInterruptStatusMasked ****************************************************************************//** * -* Returns the bitwise AND between the saturate interrupt request and mask registers. +* Return the bitwise AND between the saturate interrupt request and mask registers. * See \ref Cy_SAR_GetSatInterruptStatus and \ref Cy_SAR_GetSatInterruptMask. * * \param base * Pointer to structure describing registers * -* \return uint32_t -* Bitwise AND between the interrupt request and mask registers +* \return +* Bitwise AND of the saturate interrupt request and mask * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatusMasked(const SAR_Type *base) @@ -1654,6 +1947,34 @@ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatusMasked(const SAR_Type *base return base->SATURATE_INTR_MASKED; } +/******************************************************************************* +* Function Name: Cy_SAR_GetInterruptCause +****************************************************************************//** +* +* Return the cause of the interrupt. +* The interrupt routine can be called due to one of the following events: +* - End of scan (EOS) +* - Overflow +* - Firmware collision +* - Saturation detected on one or more channels +* - Range detected on one or more channels +* +* \param base +* Pointer to structure describing registers +* +* \return +* Mask of what caused the interrupt. Compare this value with one of these masks: +* - SAR_INTR_CAUSE_EOS_MASKED_MIR_Msk : EOS caused the interrupt +* - SAR_INTR_CAUSE_OVERFLOW_MASKED_MIR_Msk : Overflow caused the interrupt +* - SAR_INTR_CAUSE_FW_COLLISION_MASKED_MIR_Msk : Firmware collision cause the interrupt +* - SAR_INTR_CAUSE_SATURATE_MASKED_RED_Msk : Saturation detection on one or more channels caused the interrupt +* - SAR_INTR_CAUSE_RANGE_MASKED_RED_Msk : Range detection on one or more channels caused the interrupt +* +*******************************************************************************/ +__STATIC_INLINE uint32_t Cy_SAR_GetInterruptCause(const SAR_Type *base) +{ + return base->INTR_CAUSE; +} /** \} */ /** \addtogroup group_sar_functions_helper @@ -1663,7 +1984,7 @@ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatusMasked(const SAR_Type *base * Function Name: Cy_SAR_IsChannelDifferential ****************************************************************************//** * -* Returns true of channel is differential, else false. +* Return true of channel is differential, else false. * * \param base * Pointer to structure describing registers @@ -1671,9 +1992,13 @@ __STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatusMasked(const SAR_Type *base * \param chan * The channel to check, starting at 0. * -* \return bool +* \return * A false is return if chan is invalid. * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_IS_CHANNEL_DIFF +* *******************************************************************************/ __STATIC_INLINE bool Cy_SAR_IsChannelDifferential(const SAR_Type *base, uint32_t chan) { @@ -1688,20 +2013,22 @@ __STATIC_INLINE bool Cy_SAR_IsChannelDifferential(const SAR_Type *base, uint32_t * Function Name: Cy_SAR_SetVssaVminusSwitch ****************************************************************************//** * -* Sets the state (open or closed) of the switch between VSSA_KELVIN and VMINUS -* through firmware. -* -* When the SAR sequencer is controlling the SARMUX switches, -* there is no need to use this function. +* Open or close the switch between VSSA and Vminus of the SARADC through firmware. +* This function calls \ref Cy_SAR_SetAnalogSwitch with switchSelect set to +* \ref CY_SAR_MUX_SWITCH0 and switchMask set to SAR_MUX_SWITCH0_MUX_FW_VSSA_VMINUS_Msk. * * \param base * Pointer to structure describing registers * * \param state -* A value of the enum \ref cy_en_sar_switch_state_t. +* Open or close the switch. Select a value from \ref cy_en_sar_switch_state_t. * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_VSSA_VMINUS_SWITCH +* *******************************************************************************/ __STATIC_INLINE void Cy_SAR_SetVssaVminusSwitch(SAR_Type *base, cy_en_sar_switch_state_t state) { @@ -1712,17 +2039,22 @@ __STATIC_INLINE void Cy_SAR_SetVssaVminusSwitch(SAR_Type *base, cy_en_sar_switch * Function Name: Cy_SAR_SetVssaSarSeqCtrl ****************************************************************************//** * -* Sets whether the SAR sequencer will control the switch between VSSA_KELVIN and VMINUS -* or not. +* Enable or disable SARSEQ control of the switch between VSSA and Vminus of the SARADC. +* This function calls \ref Cy_SAR_SetSwitchSarSeqCtrl +* with switchMask set to SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_VSSA_Msk. * * \param base * Pointer to structure describing registers * * \param ctrl -* A value of the enum \ref cy_en_sar_switch_sar_seq_ctrl_t. +* Enable or disable control. Select a value from \ref cy_en_sar_switch_sar_seq_ctrl_t. * * \return None * +* \funcusage +* +* \snippet sar_sut_01.cydsn/main_cm0p.c SNIPPET_SAR_VSSA_SARSEQ_CTRL +* *******************************************************************************/ __STATIC_INLINE void Cy_SAR_SetVssaSarSeqCtrl(SAR_Type *base, cy_en_sar_switch_sar_seq_ctrl_t ctrl) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_common.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_common.c similarity index 92% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_common.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_common.c index abcafb71af..d17d5304df 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_common.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_common.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_common.c -* \version 2.0 +* \version 2.10 * * Provides common API implementation of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -70,7 +70,7 @@ void Cy_SCB_ReadArrayNoCheck(CySCB_Type const *base, void *buffer, uint32_t size ****************************************************************************//** * * Reads an array of data out of the SCB receive FIFO. -* This function does not block, it returns how many data elements were +* This function does not block; it returns how many data elements are * read from the receive FIFO. * * \param base @@ -78,7 +78,7 @@ void Cy_SCB_ReadArrayNoCheck(CySCB_Type const *base, void *buffer, uint32_t size * * \param buffer * The pointer to location to place data read from receive FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -93,7 +93,7 @@ uint32_t Cy_SCB_ReadArray(CySCB_Type const *base, void *buffer, uint32_t size) /* Get available items in RX FIFO */ uint32_t numToCopy = Cy_SCB_GetNumInRxFifo(base); - /* Adjust items which will be read */ + /* Adjust items that will be read */ if (numToCopy > size) { numToCopy = size; @@ -118,8 +118,8 @@ uint32_t Cy_SCB_ReadArray(CySCB_Type const *base, void *buffer, uint32_t size) * The pointer to the SCB instance. * * \param buffer -* The pointer to location to place data read from receive FIFO. -* The item size is defined by the data type which depends on the configured +* The pointer to the location to place data read from the receive FIFO. +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -148,7 +148,7 @@ void Cy_SCB_ReadArrayBlocking(CySCB_Type const *base, void *buffer, uint32_t siz ****************************************************************************//** * * Places a single data element in the SCB transmit FIFO. -* This function does not block and returns how many data elements were placed +* This function does not block. It returns how many data elements are placed * in the transmit FIFO. * * \param base @@ -156,7 +156,7 @@ void Cy_SCB_ReadArrayBlocking(CySCB_Type const *base, void *buffer, uint32_t siz * * \param data * Data to put in the transmit FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \return @@ -182,7 +182,7 @@ uint32_t Cy_SCB_Write(CySCB_Type *base, uint32_t data) * Function Name: Cy_SCB_WriteArrayNoCheck ****************************************************************************//** * -* Places an array of data in the SCB transmit FIFO without checking if the +* Places an array of data in the SCB transmit FIFO without checking whether the * transmit FIFO has enough space. * Before calling this function, make sure that the transmit FIFO has enough * space to put all requested data elements. @@ -192,7 +192,7 @@ uint32_t Cy_SCB_Write(CySCB_Type *base, uint32_t data) * * \param buffer * The pointer to data to place in the transmit FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * TX data width. * * \param size @@ -234,7 +234,7 @@ void Cy_SCB_WriteArrayNoCheck(CySCB_Type *base, void *buffer, uint32_t size) ****************************************************************************//** * * Places an array of data in the SCB transmit FIFO. -* This function does not block and it returns how many data elements were +* This function does not block. It returns how many data elements were * placed in the transmit FIFO. * * \param base @@ -282,7 +282,7 @@ uint32_t Cy_SCB_WriteArray(CySCB_Type *base, void *buffer, uint32_t size) * * \param buffer * The pointer to data to place in transmit FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -344,9 +344,9 @@ void Cy_SCB_WriteString(CySCB_Type *base, char_t const string[]) ****************************************************************************//** * * Places a number of the same data elements in the SCB transmit FIFO without -* checking if the transmit FIFO has enough space. The data elements is equal +* checking whether the transmit FIFO has enough space. The data elements is equal * to txData parameter. -* Before calling this function make sure that transmit FIFO has enough space +* Before calling this function, make sure that transmit FIFO has enough space * to put all requested data elements. * * \param base diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_common.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_common.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_common.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_common.h index e49ebad6d1..53c67133c8 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_common.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_common.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_common.h -* \version 2.0 +* \version 2.10 * * Provides common API declarations of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -67,6 +67,11 @@ * * * +* +* +* +* +* * * @@ -212,7 +217,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxFifoLevel (CySCB_Type const *base); #define CY_SCB_DRV_VERSION_MAJOR (2) /** Driver minor version */ -#define CY_SCB_DRV_VERSION_MINOR (0) +#define CY_SCB_DRV_VERSION_MINOR (10) /** SCB driver identifier */ #define CY_SCB_ID CY_PDL_DRV_ID(0x2AU) @@ -371,7 +376,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxFifoLevel (CySCB_Type const *base); * \defgroup group_scb_common_macros_master_intr Master Interrupt Statuses * \{ */ -/** The I2C master's lost arbitration */ +/** The I2C master lost arbitration */ #define CY_SCB_MASTER_INTR_I2C_ARB_LOST SCB_INTR_M_I2C_ARB_LOST_Msk /** The I2C master received a NACK */ @@ -410,7 +415,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxFifoLevel (CySCB_Type const *base); * \{ */ /** -* Wake up request: the SPI slave detected an active edge of the slave select +* Wake up request: the SPI slave detects an active edge of the slave select * signal. Note that this interrupt source triggers in active mode. */ #define CY_SCB_SPI_INTR_WAKEUP SCB_INTR_SPI_EC_WAKE_UP_Msk @@ -467,6 +472,12 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxFifoLevel (CySCB_Type const *base); #define CY_SCB_I2C_CTRL_MODE_Pos SCB_I2C_CTRL_SLAVE_MODE_Pos #define CY_SCB_I2C_CTRL_MODE_Msk (SCB_I2C_CTRL_SLAVE_MODE_Msk | \ SCB_I2C_CTRL_MASTER_MODE_Msk) + +/* Cypress ID #282226: +* SCB_I2C_CFG_SDA_IN_FILT_TRIM[1]: SCB clock enable (1), clock disable (0). +*/ +#define CY_SCB_I2C_CFG_CLK_ENABLE_Msk (_VAL2FLD(SCB_I2C_CFG_SDA_IN_FILT_TRIM, 2UL)) + /* I2C has fixed data width */ #define CY_SCB_I2C_DATA_WIDTH (7UL) @@ -561,7 +572,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxFifoLevel (CySCB_Type const *base); ****************************************************************************//** * * Reads a data element directly out of the RX FIFO. -* This function does not check if the RX FIFO has data before reading it. +* This function does not check whether the RX FIFO has data before reading it. * * \param base * The pointer to the SCB instance. @@ -627,7 +638,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetNumInRxFifo(CySCB_Type const *base) * The pointer to the SCB instance. * * \return -* 1 - RX shift register valid, 0 - RX shift register not valid. +* 1 - RX shift register valid; 0 - RX shift register not valid. * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SCB_GetRxSrValid(CySCB_Type const *base) @@ -646,7 +657,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxSrValid(CySCB_Type const *base) * The pointer to the SCB instance. * * \note -* If there is partial data in the shifter, it gets cleared and lost. +* If there is partial data in the shifter, it is cleared and lost. * *******************************************************************************/ __STATIC_INLINE void Cy_SCB_ClearRxFifo(CySCB_Type* base) @@ -663,7 +674,7 @@ __STATIC_INLINE void Cy_SCB_ClearRxFifo(CySCB_Type* base) ****************************************************************************//** * * Writes data directly into the TX FIFO. -* This function does not check if the TX FIFO is not full before writing +* This function does not check whether the TX FIFO is not full before writing * into it. * * \param base @@ -683,7 +694,7 @@ __STATIC_INLINE void Cy_SCB_WriteTxFifo(CySCB_Type* base, uint32_t data) * Function Name: Cy_SCB_SetTxFifoLevel ****************************************************************************//** * -* Sets the TX FIFO level, when there are fewer data elements in the TX FIFO than +* Sets the TX FIFO level. When there are fewer data elements in the TX FIFO than * this level, the TX FIFO level interrupt is triggered. * * \param base @@ -731,7 +742,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetNumInTxFifo(CySCB_Type const *base) * The pointer to the SCB instance. * * \return -* 1 - TX shift register valid, 0 - TX shift register not valid. +* 1 - TX shift register valid; 0 - TX shift register not valid. * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SCB_GetTxSrValid(CySCB_Type const *base) @@ -744,7 +755,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetTxSrValid(CySCB_Type const *base) * Function Name: Cy_SCB_IsTxComplete ****************************************************************************//** * -* Checks if the TX FIFO and Shifter are empty and there is no more data to send. +* Checks whether the TX FIFO and Shifter are empty and there is no more data to send. * * \param base * Pointer to SPI the SCB instance. @@ -769,8 +780,8 @@ __STATIC_INLINE bool Cy_SCB_IsTxComplete(CySCB_Type const *base) * The pointer to the SCB instance. * * \note -* The TX FIFO clear operation also clears the shift register, thus the shifter -* could be cleared in the middle of a data element transfer; resulting in +* The TX FIFO clear operation also clears the shift register. Thus the shifter +* could be cleared in the middle of a data element transfer. Thia results in * "ones" being sent on the bus for the remainder of the transfer. * *******************************************************************************/ @@ -789,7 +800,7 @@ __STATIC_INLINE void Cy_SCB_ClearTxFifo(CySCB_Type *base) * * Sets whether the RX and TX FIFOs are in byte mode. * The FIFOs are either 16-bit wide or 8-bit wide (byte mode). -* When the FIFO is in byte mode it is twice as deep, see device datasheet +* When the FIFO is in byte mode it is twice as deep. See the device datasheet * for FIFO depths. * * \param base @@ -1084,7 +1095,7 @@ __STATIC_INLINE uint32_t Cy_SCB_GetTxInterruptStatusMasked(CySCB_Type const *bas * * \note * - CY_SCB_INTR_TX_FIFO_LEVEL interrupt source is not cleared when the -* TX FIFO has less entries than the TX level. +* TX FIFO has fewer entries than the TX level. * - CY_SCB_INTR_TX_NOT_FULL interrupt source is not cleared when the * TX FIFO has empty entries in the TX FIFO. * - CY_SCB_INTR_TX_EMPTY interrupt source is not cleared when the @@ -1626,7 +1637,7 @@ __STATIC_INLINE void Cy_SCB_ClearSpiInterrupt(CySCB_Type *base, uint32_t interru (void) base->INTR_SPI_EC; } - +/** \cond INTERNAL */ /******************************************************************************* * Function Name: Cy_SCB_GetFifoSize ****************************************************************************//** @@ -1676,7 +1687,7 @@ __STATIC_INLINE bool Cy_SCB_IsRxDataWidthByte(CySCB_Type const *base) * The pointer to the SCB instance. * * \return -* If ture, the TX data width is a byte (8 bits). Otherwise, false. +* If true, the TX data width is a byte (8 bits). Otherwise, false. * *******************************************************************************/ __STATIC_INLINE bool Cy_SCB_IsTxDataWidthByte(CySCB_Type const *base) @@ -1728,6 +1739,8 @@ __STATIC_INLINE uint32_t Cy_SCB_GetRxFifoLevel(CySCB_Type const *base) { return _FLD2VAL(SCB_RX_FIFO_CTRL_TRIGGER_LEVEL, base->RX_FIFO_CTRL); } + +/** \endcond */ /** \} group_scb_common_functions */ #if defined(__cplusplus) diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_ezi2c.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_ezi2c.c similarity index 88% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_ezi2c.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_ezi2c.c index eb44626f45..731de3dbb6 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_ezi2c.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_ezi2c.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_ezi2c.c -* \version 2.0 +* \version 2.10 * * Provides EZI2C API implementation of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -47,7 +47,7 @@ static void UpdateAddressMask (CySCB_Type *base, cy_stc_scb_ezi2c_context_t cons * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -61,7 +61,7 @@ cy_en_scb_ezi2c_status_t Cy_SCB_EZI2C_Init(CySCB_Type *base, cy_stc_scb_ezi2c_co cy_stc_scb_ezi2c_context_t *context) { /* Input parameters verification */ - if ((NULL == base) && (NULL == config) && (NULL == context)) + if ((NULL == base) || (NULL == config) || (NULL == context)) { return CY_SCB_EZI2C_BAD_PARAM; } @@ -150,7 +150,7 @@ cy_en_scb_ezi2c_status_t Cy_SCB_EZI2C_Init(CySCB_Type *base, cy_stc_scb_ezi2c_co *******************************************************************************/ void Cy_SCB_EZI2C_DeInit(CySCB_Type *base) { - /* Returns the block registers into the default state */ + /* Return the block registers into the default state */ base->CTRL = CY_SCB_CTRL_DEF_VAL; base->I2C_CTRL = CY_SCB_I2C_CTRL_DEF_VAL; @@ -185,11 +185,11 @@ void Cy_SCB_EZI2C_DeInit(CySCB_Type *base) * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \note -* Calling this function when EZI2C is busy (the slave was addressed and is +* Calling this function while EZI2C is busy (the slave has been addressed and is * communicating with the master), may cause transaction corruption because * the hardware stops driving the output and ignores the input. Ensure that * the EZI2C slave is not busy before calling this function. @@ -210,37 +210,38 @@ void Cy_SCB_EZI2C_Disable(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) ****************************************************************************//** * * This function handles the transition of the EZI2C SCB into and out of -* Deep-Sleep mode. It prevents the device from entering Deep-Sleep mode -* if the EZI2C slave is actively communicating. -* The following behavior of the EZI2C depends on if the SCB block is -* wakeup-capable or not: -* * The SCB wakeup-capable: on the incoming EZI2C slave address, the slave -* receives address and stretches the clock until the device is awoken from -* Deep-Sleep mode. If the slave address occurs before the device enters -* Deep-Sleep mode, the device will not enter Deep-Sleep mode. -* * The SCB is not wakeup-capable: the EZI2C is disabled. It is enabled when -* the device failed to enter Deep-Sleep mode or it is awaken from Deep-Sleep -* mode. During the EZI2C is disabled, it stops driving the outputs and +* Deep Sleep mode. It prevents the device from entering Deep Sleep mode if +* the EZI2C slave is actively communicating. +* The following behavior of the EZI2C depends on whether the SCB block is +* wakeup-capable: +* * The SCB wakeup-capable: on the incoming EZI2C slave address, the slave +* receives the address and stretches the clock until the device is woken from +* Deep Sleep mode. If the slave address occurs before the device enters +* Deep Sleep mode, the device will not enter Deep Sleep mode. +* * The SCB is not wakeup-capable: the EZI2C is disabled. It is enabled +* when the device fails to enter Deep Sleep mode or it is woken from Deep Sleep +* mode. While the EZI2C is disabled, it stops driving the outputs and * ignores the input lines. The slave NACKs all incoming addresses. * -* This function can be called during execution of \ref Cy_SysPm_DeepSleep, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_DeepSleep. +* To do this, register this function as a callback before calling * \ref Cy_SysPm_DeepSleep : specify \ref CY_SYSPM_DEEPSLEEP as the callback * type and call \ref Cy_SysPm_RegisterCallback. * * \param callbackParams -* The pointer to the callback parameters structure +* The pointer to the callback parameters structure. * \ref cy_stc_syspm_callback_params_t. * * \return * \ref cy_en_syspm_status_t * -* \warning +* \note +* Only applicable for rev-08 of the CY8CKIT-062-BLE. * For proper operation, when the EZI2C slave is configured to be a wakeup source -* from Deep-Sleep mode, this function must be copied and modified by the user. +* from Deep Sleep mode, this function must be copied and modified by the user. * The EZI2C clock disable code must be inserted in the -* \ref CY_SYSPM_BEFORE_TRANSITION and enable code in the \ref CY_SYSPM_AFTER_TRANSITION -* mode processing. +* \ref CY_SYSPM_BEFORE_TRANSITION and clock enable code in the +* \ref CY_SYSPM_AFTER_TRANSITION mode processing. * *******************************************************************************/ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) @@ -257,8 +258,8 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params /* Disable the slave interrupt sources to protect the state */ Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_CLEAR_ALL_INTR_SRC); - /* If the EZI2C is in the IDLE state, it is ready for Deep-Sleep - * mode, otherwise return fail and restore the slave interrupt + /* If the EZI2C is in the IDLE state, it is ready for Deep Sleep + * mode. Otherwise, it returns fail and restores the slave interrupt * sources. */ if (CY_SCB_EZI2C_STATE_IDLE == locContext->state) @@ -267,7 +268,7 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params { /* The SCB is wakeup-capable: do not restore the address * match interrupt source. The next transaction intended - * for the slave will be paused (SCL is stretched) before + * for the slave will be paused (the SCL is stretched) before * the address is ACKed because the corresponding interrupt * source is disabled. */ @@ -277,8 +278,8 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params { /* The SCB is NOT wakeup-capable: disable the EZI2C. * The slave stops responding to the master until the - * EZI2C is enabled. This happens when the device is failed - * to enter Deep-Sleep mode or it is awaken from Deep-Sleep + * EZI2C is enabled. This happens when the device fails + * to enter Deep Sleep mode or it is woken from Deep Sleep * mode. */ Cy_SCB_EZI2C_Disable(locBase, locContext); @@ -297,20 +298,20 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params case CY_SYSPM_CHECK_FAIL: { - /* The other driver is not ready for Deep-Sleep mode. Restore + /* The other driver is not ready for Deep Sleep mode. Restore * Active mode configuration. */ if (_FLD2BOOL(SCB_CTRL_EC_AM_MODE, locBase->CTRL)) { /* The SCB is wakeup-capable: restore the slave interrupt - * sources + * sources. */ Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_EZI2C_SLAVE_INTR); } else { - /* The SCB is NOT wakeup-capable: enable the slave to operate */ + /* The SCB is NOT wakeup-capable: enable the slave to operate. */ Cy_SCB_EZI2C_Enable(locBase); } @@ -331,16 +332,19 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params { /* The SCB is wakeup-capable: enable the I2C wakeup interrupt * source. If any transaction was paused the the EZI2C interrupt - * becomes pending and prevents entering Deep-Sleep mode. + * becomes pending and prevents entering Deep Sleep mode. * The transaction continues as soon as the global interrupts * are enabled. */ Cy_SCB_SetI2CInterruptMask(locBase, CY_SCB_I2C_INTR_WAKEUP); - /* IMPORTANT (insert code below): for proper entering Deep - * Sleep the EZI2C clock must be disabled. This code must be - * inserted by the user because the driver does not have access - * to the clock. + /* Disable SCB clock */ + locBase->I2C_CFG &= (uint32_t) ~CY_SCB_I2C_CFG_CLK_ENABLE_Msk; + + /* IMPORTANT (replace line above for the CY8CKIT-062 rev-08): + * for proper entering Deep Sleep mode the I2C clock must be disabled. + * This code must be inserted by the user because the driver + * does not have access to the clock. */ } @@ -352,16 +356,19 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params { if (_FLD2BOOL(SCB_CTRL_EC_AM_MODE, locBase->CTRL)) { - /* IMPORTANT (insert code below): for proper exiting Deep - * Sleep, the EZI2C clock must be enabled. This code must be - * inserted by the user because the driver does not have access - * to the clock. + /* Enable SCB clock */ + locBase->I2C_CFG |= CY_SCB_I2C_CFG_CLK_ENABLE_Msk; + + /* IMPORTANT (replace line above for the CY8CKIT-062 rev-08): + * for proper exiting Deep Sleep mode, the I2C clock must be enabled. + * This code must be inserted by the user because the driver + * does not have access to the clock. */ /* The SCB is wakeup-capable: disable the I2C wakeup interrupt * source and restore slave interrupt sources. */ - Cy_SCB_SetI2CInterruptMask(locBase, CY_SCB_CLEAR_ALL_INTR_SRC); + Cy_SCB_SetI2CInterruptMask (locBase, CY_SCB_CLEAR_ALL_INTR_SRC); Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_EZI2C_SLAVE_INTR); } else @@ -387,15 +394,15 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_DeepSleepCallback(cy_stc_syspm_callback_params ****************************************************************************//** * * This function handles the transition of the EZI2C SCB block into Hibernate -* mode. It prevents the device from entering Hibernate mode if the EZI2C slave +* mode. It prevents the device from entering Hibernate mode if the EZI2C slave * is actively communicating. * If the EZI2C is ready to enter Hibernate mode, it is disabled. If the device -* failed to enter Hibernate mode, the EZI2C is enabled. During the EZI2C -* is disabled, it does stops driving the output and ignores the inputs. +* fails to enter Hibernate mode, the EZI2C is enabled. While the EZI2C +* is disabled, it stops driving the output and ignores the inputs. * The slave NACKs all incoming addresses. * -* This function can be called during execution of \ref Cy_SysPm_Hibernate, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_Hibernate. +* To do this, register this function as a callback before calling * \ref Cy_SysPm_Hibernate : specify \ref CY_SYSPM_HIBERNATE as the callback * type and call \ref Cy_SysPm_RegisterCallback. * @@ -421,13 +428,13 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_HibernateCallback(cy_stc_syspm_callback_params /* Disable the slave interrupt sources to protect the state */ Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_CLEAR_ALL_INTR_SRC); - /* If the EZI2C is in the IDLE state, it is ready for Hibernate mode, - * otherwise return fail and restore the slave interrupt sources. + /* If the EZI2C is in the IDLE state, it is ready for Hibernate mode. + * Otherwise, returns fail and restores the slave interrupt sources. */ if (CY_SCB_EZI2C_STATE_IDLE == locContext->state) { /* Disable the EZI2C. It stops responding to the master until - * the EZI2C is enabled. This happens if the device failed to + * the EZI2C is enabled. This happens if the device fails to * enter Hibernate mode. */ Cy_SCB_EZI2C_Disable(locBase, locContext); @@ -483,7 +490,7 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_HibernateCallback(cy_stc_syspm_callback_params * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -524,7 +531,7 @@ uint32_t Cy_SCB_EZI2C_GetActivity(CySCB_Type const *base, cy_stc_scb_ezi2c_conte * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -553,7 +560,7 @@ void Cy_SCB_EZI2C_SetAddress1(CySCB_Type *base, uint8_t addr, cy_stc_scb_ezi2c_c * * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -592,11 +599,11 @@ uint32_t Cy_SCB_EZI2C_GetAddress1(CySCB_Type const *base, cy_stc_scb_ezi2c_conte * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \note -* * This fucntion is not interrupt-protected and to prevent a race condition, +* * This function is not interrupt-protected and to prevent a race condition, * it must be protected from the EZI2C interruption in the place where it * is called. * * Calling this function in the middle of a transaction intended for the @@ -633,7 +640,7 @@ void Cy_SCB_EZI2C_SetBuffer1(CySCB_Type const *base, uint8_t *buffer, uint32_t s * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \note @@ -664,7 +671,7 @@ void Cy_SCB_EZI2C_SetAddress2(CySCB_Type *base, uint8_t addr, cy_stc_scb_ezi2c_c * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -703,11 +710,11 @@ uint32_t Cy_SCB_EZI2C_GetAddress2(CySCB_Type const *base, cy_stc_scb_ezi2c_conte * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t * allocated by the user. The structure is used during the EZI2C operation for -* internal configuration and data keeping. The user must not modify anything +* internal configuration and data retention. The user must not modify anything * in this structure. * * \note -* * This fucntion is not interrupt-protected and to prevent a race condition, +* * This function is not interrupt-protected. To prevent a race condition, * it must be protected from the EZI2C interruption in the place where it * is called. * * Calling this function in the middle of a transaction intended for the @@ -735,7 +742,7 @@ void Cy_SCB_EZI2C_SetBuffer2(CySCB_Type const *base, uint8_t *buffer, uint32_t s * * This is the interrupt function for the SCB configured in the EZI2C mode. * This function must be called inside the user-defined interrupt service -* routine to make the EZI2C slave to work. +* routine to make the EZI2C slave work. * * \param base * The pointer to the EZI2C SCB instance. @@ -743,7 +750,7 @@ void Cy_SCB_EZI2C_SetBuffer2(CySCB_Type const *base, uint8_t *buffer, uint32_t s * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -754,6 +761,11 @@ void Cy_SCB_EZI2C_Interrupt(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *contex /* Handle an I2C wake-up event */ if (0UL != (CY_SCB_I2C_INTR_WAKEUP & Cy_SCB_GetI2CInterruptStatusMasked(base))) { + /* Move from IDLE state, the slave was addressed. Following address match + * interrupt continue transfer. + */ + context->state = CY_SCB_EZI2C_STATE_ADDR; + Cy_SCB_ClearI2CInterrupt(base, CY_SCB_I2C_INTR_WAKEUP); } @@ -832,7 +844,7 @@ void Cy_SCB_EZI2C_Interrupt(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *contex * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -862,7 +874,7 @@ static void HandleErrors(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -878,7 +890,7 @@ static void HandleAddress(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) uint32_t address = (Cy_SCB_ReadRxFifo(base) >> 1UL); Cy_SCB_ClearRxInterrupt(base, CY_SCB_RX_INTR_LEVEL); - /* Decide if the address matches */ + /* Decide whether the address matches */ if ((address == context->address1) || (address == context->address2)) { /* ACK the address */ @@ -901,7 +913,7 @@ static void HandleAddress(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) } } - /* Clear the TX FIFO before continue the transaction */ + /* Clear the TX FIFO before continuing the transaction */ Cy_SCB_ClearTxFifo(base); /* Set the command to an ACK or NACK address */ @@ -914,7 +926,7 @@ static void HandleAddress(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) /* Prepare for a transaction */ if (_FLD2BOOL(SCB_I2C_STATUS_S_READ,base->I2C_STATUS)) { - /* The master reads data from the slave */ + /* The master reads data from the slave */ context->state = CY_SCB_EZI2C_STATE_TX_DATA; /* Prepare the buffer for transmit */ @@ -949,7 +961,7 @@ static void HandleAddress(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) * Function Name: HandleDataReceive ****************************************************************************//** * -* Updates RX FIFO level to trigger the next read from it. It also manages +* Updates the RX FIFO level to trigger the next read from it. It also manages * the auto-data NACK feature. * * \param base @@ -997,7 +1009,7 @@ static void UpdateRxFifoLevel(CySCB_Type *base, uint32_t bufSize) * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1035,12 +1047,12 @@ static void HandleDataReceive(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *cont } } - /* Check if the received base address is valid */ + /* Check whether the received base address is valid */ if (checkBaseAddr) { uint32_t cmd = SCB_I2C_S_CMD_S_ACK_Msk; - /* Decide if the base address within the buffer range */ + /* Decide whether the base address within the buffer range */ if (baseAddr < context->bufSize) { /* Accept the new base address */ @@ -1107,7 +1119,7 @@ static void HandleDataReceive(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *cont { uint32_t byte = Cy_SCB_ReadRxFifo(base); - /* Check if there is space to store the byte */ + /* Check whether there is space to store the byte */ if (context->bufSize > 0UL) { /* Continue the transfer: send an ACK */ @@ -1166,7 +1178,7 @@ static void HandleDataReceive(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *cont * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1201,7 +1213,7 @@ static void HandleDataTransmit(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *con * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1259,7 +1271,7 @@ static void HandleStop(CySCB_Type *base, cy_stc_scb_ezi2c_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_ezi2c_context_t allocated * by the user. The structure is used during the EZI2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1270,7 +1282,7 @@ static void UpdateAddressMask(CySCB_Type *base, cy_stc_scb_ezi2c_context_t const /* Check how many addresses are used: */ if (0U != context->address2) { - /* If (addr1 and addr2) bit matches - mask bit equals 1, otherwise 0 */ + /* If (addr1 and addr2) bits match - mask bit equals 1; otherwise 0 */ addrMask = (uint32_t) ~((uint32_t) context->address1 ^ (uint32_t) context->address2); } else diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_ezi2c.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_ezi2c.h similarity index 67% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_ezi2c.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_ezi2c.h index 65074bbfde..4f8f8ef3a6 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_ezi2c.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_ezi2c.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_ezi2c.h -* \version 2.0 +* \version 2.10 * * Provides EZI2C API declarations of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -15,7 +15,7 @@ /** * \addtogroup group_scb_ezi2c * \{ -* Driver API for EZI2C slave Peripheral +* Driver API for EZI2C Slave Peripheral * * I2C - The Inter-Integrated Circuit (I2C) bus is an industry-standard. * The two-wire hardware interface was developed by Philips Semiconductors @@ -25,7 +25,7 @@ * device based on the SCB hardware block. This slave device emulates a common * I2C EEPROM interface that acts like dual-port memory between the external * master and your code. I2C devices based on the SCB hardware are compatible -* with the I2C Standard mode, Fast mode, and Fast mode Plus specifications as +* with the I2C Standard mode, Fast mode, and Fast mode Plus specifications, as * defined in the I2C bus specification. * * Features: @@ -36,66 +36,141 @@ * * Supports Hardware Address Match * * Supports two hardware addresses with separate buffers * * Supports Wake from Deep Sleep on address match -* * Simple to set up and use, does not require calling EZI2C API +* * Simple to set up and use; does not require calling EZI2C API * at run time. * * \section group_scb_ezi2c_configuration Configuration Considerations +* The EZI2C slave driver configuration can be divided to number of sequential +* steps listed below: +* * \ref group_scb_ezi2c_config +* * \ref group_scb_ezi2c_pins +* * \ref group_scb_ezi2c_clock +* * \ref group_scb_ezi2c_data_rate +* * \ref group_scb_ezi2c_intr +* * \ref group_scb_ezi2c_enable +* +* \note +* EZI2C slave driver is built on top of the SCB hardware block. The SCB3 +* instance is used as an example for all code snippets. Modify the code to +* match your design. * -* To set up the EZI2C slave driver, provide the configuration parameters in the -* \ref cy_stc_scb_ezi2c_config_t structure. For the slave, the primary slave -* address slaveAddress1 must be provided. The other parameters are optional -* for operation. -* To get EZI2C slave operate with desired data rate the SCB clock frequency -* must be configured. Use the SysClk driver API to do that. Refer to the -* technical reference manual (TRM) to get information how to select SCB -* frequency in I2C mode to support desired data rate. -* To initialize the driver, call the \ref Cy_SCB_EZI2C_Init function providing -* a pointer to the filled \ref cy_stc_scb_ezi2c_config_t structure and -* allocated \ref cy_stc_scb_ezi2c_context_t. The \ref Cy_SCB_EZI2C_Interrupt -* function must be called in the interrupt handler for the selected -* SCB instance and this interrupt must be enabled in the NVIC. Set up the -* EZI2C slave buffers before calling \ref Cy_SCB_EZI2C_Enable using -* \ref Cy_SCB_EZI2C_SetBuffer1 for the primary slave address and -* \ref Cy_SCB_EZI2C_SetBuffer2 for the secondary if it is enabled. Finally, -* enable the EZI2C slave operation calling \ref Cy_SCB_EZI2C_Enable. +* \subsection group_scb_ezi2c_config Configure EZI2C slave +* To set up the EZI2C slave driver, provide the configuration parameters in the +* \ref cy_stc_scb_ezi2c_config_t structure. The primary slave address +* slaveAddress1 must be provided. The other parameters are optional for +* operation. To initialize the driver, call \ref Cy_SCB_EZI2C_Init +* function providing a pointer to the filled \ref cy_stc_scb_ezi2c_config_t +* structure and allocated \ref cy_stc_scb_ezi2c_context_t. * -* The following operation might not require calling any EZI2C slave function -* because the I2C master is able to access the slave buffer and the application -* can directly access it as well. Note that this is an application level task +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_CFG +* +* Set up the EZI2C slave buffer before enabling its +* operation by using \ref Cy_SCB_EZI2C_SetBuffer1 for the primary slave address +* and \ref Cy_SCB_EZI2C_SetBuffer2 for the secondary (if the secondary is enabled). +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_CFG_BUFFER +* +* \subsection group_scb_ezi2c_pins Assign and Configure Pins +* Only dedicated SCB pins can be used for I2C operation. The HSIOM +* register must be configured to connect the block to the pins. Also the I2C pins +* must be configured in Open-Drain, Drives Low mode (this pin configuration +* implies usage of external pull-up resistors): +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_CFG_PINS +* +* \note +* The alternative pins configuration is Resistive Pull-ups which implies usage +* internal pull-up resistors. This configuration is not recommended because +* resistor value is fixed and cannot be used for all supported data rates. +* Refer to device datasheet parameter RPULLUP for resistor value specifications. +* +* \subsection group_scb_ezi2c_clock Assign Clock Divider +* The clock source must be connected to the SCB block to oversample input and +* output signals. You must use one of the 8-bit or 16-bit dividers (the +* source clock of this divider must be Clk_Peri). Use the +* \ref group_sysclk driver API to do that. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_CFG_ASSIGN_CLOCK +* +* \subsection group_scb_ezi2c_data_rate Configure Data Rate +* To get EZI2C slave to operate at the desired data rate, the source clock must be +* fast enough to provide sufficient oversampling. Therefore, the clock divider +* must be configured to provide desired clock frequency. Use the +* \ref group_sysclk driver API to do that. +* Refer to the technical reference manual (TRM) section I2C sub-section +* Oversampling and Bit Rate to get information about how to configure the I2C to run +* at the desired data rate. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_CFG_DATA_RATE +* +* \subsection group_scb_ezi2c_intr Configure Interrupt +* The interrupt is mandatory for the EZI2C slave operation. +* The \ref Cy_SCB_EZI2C_Interrupt function must be called in the interrupt +* handler for the selected SCB instance. Also, this interrupt must be enabled +* in the NVIC or it will not work. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_INTR_A +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_INTR_B +* +* \subsection group_scb_ezi2c_enable Enable EZI2C slave +* Finally, enable the EZI2C slave operation by calling \ref Cy_SCB_EZI2C_Enable. +* Now the I2C device responds to the assigned address. +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\ezi2c_snippets.c EZI2C_ENABLE +* +* \section group_scb_ezi2c_use_cases Common Use Cases +* The EZI2C slave operation might not require calling any EZI2C slave function +* because the I2C master is able to access the slave buffer. The application +* can directly access it as well. Note that this is an application-level task * to ensure the buffer content integrity. +* +* \subsection group_scb_ezi2c_master_wr Master Write operation +* This operation starts with sending a base address that is one +* or two bytes, depending on the sub-address size configuration. This base +* address is retained and will be used for later read operations. Following +* the base address, there is a sequence of bytes written into the buffer +* starting from the base address location. The buffer index is incremented +* for each written byte, but this does not affect the base address that is +* retained. The length of a write operation is limited by the maximum buffer +* read/write region size.\n +* When a master attempts to write outside the read/write region or past the +* end of the buffer, the last byte is NACKed. +* +* \image html scb_ezi2c_write.png +* +* \subsection group_scb_ezi2c_master_rd Master Read operation +* This operation always starts from the base address set by the most +* recent write operation. The buffer index is incremented for each read byte. +* Two sequential read operations start from the same base address no matter +* how many bytes are read. The length of a read operation is not limited by +* the maximum size of the data buffer. The EZI2C slave returns 0xFF bytes +* if the read operation passes the end of the buffer.\n +* Typically, a read operation requires the base address to be updated before +* starting the read. In this case, the write and read operations must be +* combined together. * -* The master can access the buffer: -* * Master Write operation starts with sending a base address which is 1 -* or 2 bytes depending on the sub-address size configuration. This base -* address is retained and will be used for later read operations. Following -* the base address, there is a sequence of bytes written into the buffer -* starting from the base address location. The buffer index is incremented -* for each written byte, but this does not affect the base address which is -* retained. The length of a write operation is limited by the maximum buffer -* read/write region size.\n -* When a master attempts to write outside the read/write region or past the -* end of the buffer, the last byte is NACKed. -* * Master Read operation always starts from the base address set by the most -* recent Write operation. The buffer index is incremented for each read byte. -* Two sequential read operations start from the same base address no matter -* how many bytes were read. The length of a read operation is not limited by -* the maximum size of the data buffer. The EZI2C slave returns 0xFF bytes -* if the read operation passes the end of the buffer.\n -* Typically, a read operation requires the base address to be updated before -* starting the read. In this case, the write and read operations must be -* combined together. The I2C master may use the ReStart or Stop/Start -* conditions to combine the operations. The write operation sets only the -* base address and the following read operation will start from the new base -* address. In cases where the base address remains the same, there is no need -* for a write operation. +* \image html scb_ezi2c_read.png * -* The EZI2C driver provides the callback functions to facilitate the low-power -* mode transition. The callback \ref Cy_SCB_EZI2C_DeepSleepCallback can be called -* during execution of \ref Cy_SysPm_DeepSleep; \ref Cy_SCB_EZI2C_HibernateCallback -* can be called during execution of \ref Cy_SysPm_Hibernate. To trigger the -* callback execution, the callback must be registered before calling the -* mode transition function. Refer to SysPm driver for more information about -* low-power mode transitions. +* The I2C master may use the ReStart or Stop/Start conditions to combine the +* operations. The write operation sets only the base address and the following +* read operation will start from the new base address. In cases where the base +* address remains the same, there is no need for a write operation. +* \image html scb_ezi2c_set_ba_read.png +* +* \section group_scb_ezi2c_lp Low Power Support +* The EZI2C slave provides the callback functions to handle power mode +* transition. The callback \ref Cy_SCB_EZI2C_DeepSleepCallback must be called +* during execution of \ref Cy_SysPm_DeepSleep; +* \ref Cy_SCB_EZI2C_HibernateCallback must be called during execution of +* \ref Cy_SysPm_Hibernate. To trigger the callback execution, the callback must +* be registered before calling the power mode transition function. Refer to +* \ref group_syspm driver for more information about power mode transitions and +* callback registration. +* +* \note +* Only applicable for rev-08 of the CY8CKIT-062-BLE. +* For proper operation, when the EZI2C slave is configured to be a wakeup +* source from Deep Sleep mode, the \ref Cy_SCB_EZI2C_DeepSleepCallback must +* be copied and modified. Refer to the function description to get the details. * * \section group_scb_ezi2c_more_information More Information * @@ -106,7 +181,7 @@ *
VersionChangesReason for Change
2.10None.SCB I2C driver updated.
2.0Added parameters validation for public API. *
* * -* +* * * * @@ -125,7 +200,7 @@ * * * -* * * @@ -142,8 +217,8 @@ * * +* code clarity when returning error status code if input parameter +* validation fails. * *
MISRA RuleRule Class (Required / Advisory)Rule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
14.1RThere shall be no unreachable code.The SCB block parameters can be a constant false or true depends on +* The SCB block parameters can be a constant false or true depending on * the selected device and cause code to be unreachable.
A function shall have a single point of exit at the end of the * function.The functions can return from several points. This is done to improve -* code clarity when returning error status code if input parameters -* validation is failed.
* @@ -151,12 +226,17 @@ * * * +* +* +* +* +* * * * * * -* * * @@ -225,6 +305,7 @@ typedef enum typedef enum { CY_SCB_EZI2C_STATE_IDLE, + CY_SCB_EZI2C_STATE_ADDR, CY_SCB_EZI2C_STATE_RX_OFFSET_MSB, CY_SCB_EZI2C_STATE_RX_OFFSET_LSB, CY_SCB_EZI2C_STATE_RX_DATA0, @@ -260,7 +341,7 @@ typedef struct cy_stc_scb_ezi2c_config cy_en_scb_ezi2c_sub_addr_size_t subAddressSize; /** - * When set, the slave will wake the device from deep sleep on an address + * When set, the slave will wake the device from Deep Sleep on an address * match (The device datasheet must be consulted to determine which SCBs * support this mode) */ @@ -271,7 +352,7 @@ typedef struct cy_stc_scb_ezi2c_config * All fields for the context structure are internal. Firmware never reads or * writes these values. Firmware allocates the structure and provides the * address of the structure to the driver in function calls. Firmware must -* ensure that the defined instance of this structure remains in scope while +* ensure that the defined instance of this structure remains in scope * while the drive is in use. */ typedef struct cy_stc_scb_ezi2c_context @@ -406,14 +487,14 @@ cy_en_syspm_status_t Cy_SCB_EZI2C_HibernateCallback(cy_stc_syspm_callback_params * slave address. The sources of the error are: a misplaced Start or Stop * condition or lost arbitration while the slave drives SDA. * When CY_SCB_EZI2C_STATUS_ERR is set, the slave buffer may contain an -* invalid byte. It is recommended to discard the buffer content in this case. +* invalid byte. Discard the buffer content in this case. */ #define CY_SCB_EZI2C_STATUS_ERR (0x20UL) /** \} group_scb_ezi2c_macros_get_activity */ /** * This value is returned by the slave when the buffer is not configured or -* the master requests more bytes than available in the buffer. +* the master requests more bytes than are available in the buffer. */ #define CY_SCB_EZI2C_DEFAULT_TX (0xFFUL) diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_i2c.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_i2c.c similarity index 85% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_i2c.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_i2c.c index 8e496e866a..665f88b6a0 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_i2c.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_i2c.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_i2c.c -* \version 2.0 +* \version 2.10 * * Provides I2C API implementation of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -22,13 +22,11 @@ extern "C" { * Function Prototypes ***************************************/ -static void SlaveInterrupt (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void SlaveHandleAddress (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void SlaveHandleDataReceive (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void SlaveHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void SlaveHandleStop (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); -static void MasterInterrupt (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void MasterHandleEvents (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void MasterHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t *context); static void MasterHandleDataReceive (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); @@ -55,7 +53,7 @@ static uint32_t WaitOneUnit(uint32_t *timeout); * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -68,7 +66,7 @@ static uint32_t WaitOneUnit(uint32_t *timeout); cy_en_scb_i2c_status_t Cy_SCB_I2C_Init(CySCB_Type *base, cy_stc_scb_i2c_config_t const *config, cy_stc_scb_i2c_context_t *context) { /* Input parameters verification */ - if ((NULL == base) && (NULL == config) && (NULL == context)) + if ((NULL == base) || (NULL == config) || (NULL == context)) { return CY_SCB_I2C_BAD_PARAM; } @@ -160,7 +158,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_Init(CySCB_Type *base, cy_stc_scb_i2c_config_t * Function Name: Cy_SCB_I2C_DeInit ****************************************************************************//** * -* De-initializes the SCB block, returns register values to default. +* De-initializes the SCB block and returns register values to default. * * \param base * The pointer to the I2C SCB instance. @@ -207,14 +205,14 @@ void Cy_SCB_I2C_DeInit(CySCB_Type *base) * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note * Calling this function when I2C is busy (master preforms transaction or slave * was address and communicates with master) may cause transaction corruption * because the hardware stops driving the outputs and ignores the inputs. -* It is recommenced to ensure that I2C is not busy before calling this function. +* Ensure that I2C is not busy before calling this function. * *******************************************************************************/ void Cy_SCB_I2C_Disable(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) @@ -233,23 +231,23 @@ void Cy_SCB_I2C_Disable(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) ****************************************************************************//** * * This function handles the transition of the I2C SCB into and out of -* Deep-Sleep mode. It prevents the device from entering Deep-Sleep mode if -* the I2C slave or master is actively communicating. -* The following behavior of the I2C SCB depends on if the SCB block is +* Deep Sleep mode. It prevents the device from entering Deep Sleep +* mode if the I2C slave or master is actively communicating. +* The following behavior of the I2C SCB depends on whether the SCB block is * wakeup-capable or not: -* * The SCB wakeup-capable: on the incoming I2C slave address, the slave +* * The SCB wakeup-capable: on the incoming I2C slave address, the slave * receives address and stretches the clock until the device is awoken from -* Deep-Sleep mode. If the slave address occurs before the device enters -* Deep-Sleep mode, the device will not enter Deep-Sleep mode. -* Only the I2C slave can be configured to be a wakeup source from Deep-Sleep +* Deep Sleep mode. If the slave address occurs before the device enters +* Deep Sleep mode, the device will not enter Deep Sleep mode. +* Only the I2C slave can be configured to be a wakeup source from Deep Sleep * mode. -* * The SCB is not wakeup-capable: the I2C is disabled. It is enabled when the -* device failed to enter Deep-Sleep mode or it is awaken from Deep-Sleep mode. -* During the I2C is disabled, it does stops driving the outputs and ignores -* the inputs. The slave NACKs all incoming addresses. +* * The SCB is not wakeup-capable: the I2C is disabled. It is enabled when +* the device failed to enter Deep Sleep mode or when it is awoken from Deep +* Sleep mode. While the I2C is disabled, it does stops driving the outputs and +* ignores the inputs. The slave NACKs all incoming addresses. * -* This function can be called during execution of \ref Cy_SysPm_DeepSleep, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_DeepSleep. +* To do it, register this function as a callback before calling * \ref Cy_SysPm_DeepSleep : specify \ref CY_SYSPM_DEEPSLEEP as the callback * type and call \ref Cy_SysPm_RegisterCallback. * @@ -260,11 +258,12 @@ void Cy_SCB_I2C_Disable(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) * \return * \ref cy_en_syspm_status_t * -* \warning +* \note +* Only applicable for rev-08 of the CY8CKIT-062-BLE. * For proper operation, when the I2C slave is configured to be a wakeup source -* from Deep-Sleep mode, this function must be copied and modified by the user. +* from Deep Sleep mode, this function must be copied and modified by the user. * The I2C clock disable code must be inserted in the \ref CY_SYSPM_BEFORE_TRANSITION -* and enable code in the \ref CY_SYSPM_AFTER_TRANSITION mode processing. +* and clock enable code in the \ref CY_SYSPM_AFTER_TRANSITION mode processing. * *******************************************************************************/ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) @@ -281,7 +280,7 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t /* Disable the slave interrupt sources to protect the state */ Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_CLEAR_ALL_INTR_SRC); - /* If the I2C is in the IDLE state, it is ready for Deep-Sleep mode + /* If the I2C is in the IDLE state, it is ready for Deep Sleep mode * (either the master or the slave is not busy), * otherwise return fail and restore the slave interrupt sources. */ @@ -302,8 +301,8 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t /* The SCB is NOT wakeup-capable: disable the I2C. The slave * stops responding to the master and the master stops * driving the bus until the I2C is enabled. This happens - * when the device failed to enter into Deep-Sleep mode or it - * is awaken from Deep-Sleep mode. + * when the device failed to enter into Deep Sleep mode or it + * is awaken from Deep Sleep mode. */ Cy_SCB_I2C_Disable(locBase, locContext); Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_I2C_SLAVE_INTR); @@ -321,7 +320,7 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t case CY_SYSPM_CHECK_FAIL: { - /* The other driver is not ready for Deep-Sleep mode. Restore + /* The other driver is not ready for Deep Sleep mode. Restore * Active mode configuration. */ @@ -342,9 +341,9 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t case CY_SYSPM_BEFORE_TRANSITION: { - /* This code executes inside the critical section and enabling the + /* This code executes inside the critical section. Enabling the * active interrupt source makes the interrupt pending in the NVIC. - * However, the interrupt processing is delayed until the code exists + * However, the interrupt processing is delayed until the code exits * the critical section. The pending interrupt force WFI instruction * does nothing and the device remains in Active mode. */ @@ -353,16 +352,19 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t { /* The SCB is wakeup-capable: enable the I2C wakeup interrupt * source. If any transaction was paused, the I2C interrupt - * becomes pending and prevents entering Deep-Sleep mode. + * becomes pending and prevents entering Deep Sleep mode. * The transaction continues as soon as the global interrupts * are enabled. */ Cy_SCB_SetI2CInterruptMask(locBase, CY_SCB_I2C_INTR_WAKEUP); - /* IMPORTANT (insert code below): for proper entering Deep - * Sleep the I2C clock must be disabled. This code must be - * inserted by the user because the driver does not have access - * to the clock. + /* Disable SCB clock */ + locBase->I2C_CFG &= (uint32_t) ~CY_SCB_I2C_CFG_CLK_ENABLE_Msk; + + /* IMPORTANT (replace line above for the CY8CKIT-062 rev-08): + * for proper entering Deep Sleep mode the I2C clock must be disabled. + * This code must be inserted by the user because the driver + * does not have access to the clock. */ } @@ -374,16 +376,19 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t { if (_FLD2BOOL(SCB_CTRL_EC_AM_MODE, locBase->CTRL)) { - /* IMPORTANT (insert code below): for proper exiting Deep - * Sleep, the I2C clock must be enabled. This code must be - * inserted by the user because the driver does not have access - * to the clock. + /* Enable SCB clock */ + locBase->I2C_CFG |= CY_SCB_I2C_CFG_CLK_ENABLE_Msk; + + /* IMPORTANT (replace line above for the CY8CKIT-062 rev-08): + * for proper exiting Deep Sleep, the I2C clock must be enabled. + * This code must be inserted by the user because the driver + * does not have access to the clock. */ /* The SCB is wakeup-capable: disable the I2C wakeup interrupt * source and restore slave interrupt sources. */ - Cy_SCB_SetI2CInterruptMask(locBase, CY_SCB_CLEAR_ALL_INTR_SRC); + Cy_SCB_SetI2CInterruptMask (locBase, CY_SCB_CLEAR_ALL_INTR_SRC); Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_I2C_SLAVE_INTR); } else @@ -408,16 +413,16 @@ cy_en_syspm_status_t Cy_SCB_I2C_DeepSleepCallback(cy_stc_syspm_callback_params_t * Function Name: Cy_SCB_I2C_HibernateCallback ****************************************************************************//** * -* This function handles the transition of the I2C SCB block into Hibernate mode. -* It prevents the device from entering Hibernate mode if the I2C slave or +* This function handles the transition of the I2C SCB block into Hibernate +* mode. It prevents the device from entering Hibernate mode if the I2C slave or * master is actively communicating. * If the I2C is ready to enter Hibernate mode, it is disabled. If the device failed -* to enter Hibernate mode the I2C is enabled. After the I2C is disabled, it stops +* to enter Hibernate mode, the I2C is enabled. After the I2C is disabled, it stops * driving the outputs and ignores the inputs. The slave NACKs all incoming * addresses. * -* This function can be called during execution of \ref Cy_SysPm_Hibernate, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_Hibernate. +* To do it, register this function as a callback before calling * \ref Cy_SysPm_Hibernate : specify \ref CY_SYSPM_HIBERNATE as the callback * type and call \ref Cy_SysPm_RegisterCallback. * @@ -444,8 +449,8 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t Cy_SCB_SetSlaveInterruptMask(locBase, CY_SCB_CLEAR_ALL_INTR_SRC); /* If the I2C is in the IDLE state, it is ready for Hibernate mode - * (either the master or the slave is not busy), - * otherwise, return fail and restore the slave interrupt sources. + * (either the master or the slave is not busy). + * Otherwise, return fail and restore the slave interrupt sources. */ if (CY_SCB_I2C_IDLE == locContext->state) { @@ -465,7 +470,7 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t case CY_SYSPM_CHECK_FAIL: { - /* The other driver is not ready for Deep-Sleep mode. Restore the + /* The other driver is not ready for Hibernate mode. Restore the * Active mode configuration. */ @@ -512,11 +517,11 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t * * \note * This function does not change the values of the clock divider connected -* to the SCB, it only changes the SCB clock oversample registers. If this +* to the SCB, it changes only the SCB clock oversample registers. If this * function is not able to achieve the desired data rate, then the clock -* divider has to be adjusted. Call this function only while the SCB is +* divider must be adjusted. Call this function only while the SCB is * disabled. For the slave, this function only checks that the attached clock is -* fast enough to meet the desired data rate, it does not change any registers. +* fast enough to meet the desired data rate. It does not change any registers. * *******************************************************************************/ uint32_t Cy_SCB_I2C_SetDataRate(CySCB_Type *base, uint32_t dataRateHz, uint32_t scbClockHz) @@ -543,11 +548,11 @@ uint32_t Cy_SCB_I2C_SetDataRate(CySCB_Type *base, uint32_t dataRateHz, uint32_t uint32_t lowPhase; uint32_t highPhase; - /* Convert scb clock and data rate in kHz */ + /* Convert SCB clock and data rate in kHz */ uint32_t scbClockKHz = scbClockHz / 1000UL; uint32_t dataRateKHz = dataRateHz / 1000UL; - /* Get period of the scb clock in ns */ + /* Get period of the SCB clock in ns */ uint32_t period = 1000000000UL / scbClockHz; /* Get duration of SCL low and high for the selected data rate */ @@ -567,14 +572,14 @@ uint32_t Cy_SCB_I2C_SetDataRate(CySCB_Type *base, uint32_t dataRateHz, uint32_t sclHigh = CY_SCB_I2C_MASTER_FSTP_SCL_HIGH; } - /* Get low phase minimum value in scb clocks */ + /* Get low phase minimum value in SCB clocks */ lowPhase = sclLow / period; while (((period * lowPhase) < sclLow) && (lowPhase < CY_SCB_I2C_LOW_PHASE_MAX)) { ++lowPhase; } - /* Get high phase minimum value in scb clocks */ + /* Get high phase minimum value in SCB clocks */ highPhase = sclHigh / period; while (((period * highPhase) < sclHigh) && (highPhase < CY_SCB_I2C_HIGH_PHASE_MAX)) { @@ -719,7 +724,7 @@ uint32_t Cy_SCB_I2C_GetDataRate(CySCB_Type const *base, uint32_t scbClockHz) * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -740,13 +745,13 @@ uint32_t Cy_SCB_I2C_SlaveGetStatus(CySCB_Type const *base, cy_stc_scb_i2c_contex ****************************************************************************//** * * Configures the buffer pointer and the read buffer size. This is the buffer -* that the master reads data from. After this function is called, data +* from which the master reads data. After this function is called, data * transfer from the read buffer to the master is handled by * \ref Cy_SCB_I2C_Interrupt. * -* When Read transaction is completed (master generated Stop, ReStart or +* When the Read transaction is completed (master generated Stop, ReStart or * error occurred), the \ref CY_SCB_I2C_SLAVE_RD_BUSY status is cleared and -* the \ref CY_SCB_I2C_SLAVE_RD_CMPLT is set, also +* the \ref CY_SCB_I2C_SLAVE_RD_CMPLT is set. Also * the \ref CY_SCB_I2C_SLAVE_RD_CMPLT_EVENT event is generated. * * \param base @@ -761,7 +766,7 @@ uint32_t Cy_SCB_I2C_SlaveGetStatus(CySCB_Type const *base, cy_stc_scb_i2c_contex * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note @@ -806,14 +811,14 @@ void Cy_SCB_I2C_SlaveConfigReadBuf(CySCB_Type const *base, uint8_t *buffer, uint * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \sideeffect * If the TX FIFO is used, this function clears it. * The TX FIFO clear operation also clears the shift register, thus * the shifter can be cleared in the middle of a data element transfer, -* corrupting it. The data element corruption means that all bits which has +* corrupting it. The data element corruption means that all bits that have * not been transmitted are transmitted as "ones" on the bus. * *******************************************************************************/ @@ -853,15 +858,15 @@ void Cy_SCB_I2C_SlaveAbortRead(CySCB_Type *base, cy_stc_scb_i2c_context_t *conte * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * The number of bytes read by the master. * * \note -* * This function returns an invalid value if read transaction was -* aborted or any of listed events occurred during the transaction: +* * This function returns an invalid value if a read transaction was +* aborted or any listed event occurs during the transaction: * \ref CY_SCB_I2C_SLAVE_ARB_LOST, \ref CY_SCB_I2C_SLAVE_BUS_ERR. * * This number is updated only when a transaction completes, either through * an error or successfully. @@ -888,7 +893,7 @@ uint32_t Cy_SCB_I2C_SlaveGetReadTransferCount(CySCB_Type const *base, cy_stc_scb * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -937,20 +942,20 @@ uint32_t Cy_SCB_I2C_SlaveClearReadStatus(CySCB_Type const *base, cy_stc_scb_i2c_ * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note -* * The write buffer must not be modified and stay allocated until it has been +* * The write buffer must not be modified and must stay allocated until it has been * written by the master. -* * If this function has not been called and the master tries to write data -* the 1st byte is NAKed and discarded. -* * If the master writes more bytes than slave can stores in the write buffer -* the \ref CY_SCB_I2C_SLAVE_WR_OVRFL status is set and slave will NACK last +* * If this function has not been called and the master tries to write data, +* the first byte is NAKed and discarded. +* * If the master writes more bytes than the slave can store in the write buffer, +* the \ref CY_SCB_I2C_SLAVE_WR_OVRFL status is set and the slave will NACK last * byte, unless the RX FIFO is used. Then the slave will NAK only after * RX FIFO becomes full. -* * If the RX FIFO is used the minimum write buffer size is automatically -* the size of the RX FIFO. If write buffer is less than RX FIFO size extra +* * If the RX FIFO is used, the minimum write buffer size is automatically +* the size of the RX FIFO. If a write buffer is less than the RX FIFO size, extra * bytes are ACKed and stored into RX FIFO but ignored by firmware. * *******************************************************************************/ @@ -973,7 +978,7 @@ void Cy_SCB_I2C_SlaveConfigWriteBuf(CySCB_Type const *base, uint8_t *buffer, uin ****************************************************************************//** * * Aborts the configured slave write buffer to be written by the master. -* If master writes and "abort operation" is requested the next incoming byte will +* If master writes and "abort operation" are requested, the next incoming byte will * be NAKed. * * \param base @@ -982,12 +987,12 @@ void Cy_SCB_I2C_SlaveConfigWriteBuf(CySCB_Type const *base, uint8_t *buffer, uin * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note -* If the RX FIFO is used the NAK will not be sent until RX FIFO -* becomes full however bytes accepted after abort request are ignored. +* If the RX FIFO is used, the NAK will not be sent until RX FIFO +* becomes full, however bytes accepted after an abort request are ignored. * *******************************************************************************/ void Cy_SCB_I2C_SlaveAbortWrite(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) @@ -1029,17 +1034,17 @@ void Cy_SCB_I2C_SlaveAbortWrite(CySCB_Type *base, cy_stc_scb_i2c_context_t *con * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * Number of bytes written by the master. * * \note -* * This function returns an invalid value if write transaction was -* aborted or any of listed events occurred during the transaction: +* * This function returns an invalid value if write transaction is +* aborted or any listed event occurs during the transaction: * \ref CY_SCB_I2C_SLAVE_ARB_LOST, \ref CY_SCB_I2C_SLAVE_BUS_ERR. -* * This number is only updated when the transaction completes, either through +* * This number is updated only when the transaction completes, either through * an error or successfully. * *******************************************************************************/ @@ -1056,7 +1061,7 @@ uint32_t Cy_SCB_I2C_SlaveGetWriteTransferCount(CySCB_Type const *base, cy_stc_sc * Function Name: Cy_SCB_I2C_SlaveClearWriteStatus ****************************************************************************//** * -* Clears the write status flags and error conditions flags returns and their +* Clears the write status flags and error condition flags and returns their * values. * * \param base @@ -1065,7 +1070,7 @@ uint32_t Cy_SCB_I2C_SlaveGetWriteTransferCount(CySCB_Type const *base, cy_stc_sc * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1106,7 +1111,7 @@ uint32_t Cy_SCB_I2C_SlaveClearWriteStatus(CySCB_Type const *base, cy_stc_scb_i2c * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1153,15 +1158,28 @@ uint32_t Cy_SCB_I2C_MasterGetStatus(CySCB_Type const *base, cy_stc_scb_i2c_conte * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * \ref cy_en_scb_i2c_status_t * * \note -* The buffer must not be modified and stay allocated until read operation -* completion. +* * The buffer must not be modified and must stay allocated until read operation +* completion. +* +* * \ref Cy_SCB_I2C_MasterRead requests the SCB hardware to generate a Start +* Condition. The hardware will not generate the Start while the I2C bus is busy. +* The SCB hardware sets the busy status after the Start detection, and clears +* it on the Stop detection. Noise caused by the ESD or other events may cause +* an erroneous Start condition on the bus. Then, the master will never generate +* a Start condition because the hardware assumes the bus is busy. If this occurs, +* the \ref Cy_SCB_I2C_MasterGetStatus returns \ref CY_SCB_I2C_MASTER_BUSY +* status and the transaction will never finish. The option is to implement a +* timeout to detect the transfer completion. If the transfer never completes, +* the SCB needs a reset by calling the \ref Cy_SCB_I2C_Disable and +* \ref Cy_SCB_I2C_Enable functions. The \ref Cy_SCB_I2C_MasterAbortRead +* function will not work, the block must be reset. * *******************************************************************************/ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterRead(CySCB_Type *base, @@ -1181,6 +1199,10 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterRead(CySCB_Type *base, { uint32_t intrState; + /* Set address byte (bit0 = 1, read direction) */ + uint32_t address = _VAL2FLD(CY_SCB_I2C_ADDRESS, xferConfig->slaveAddress) | + (uint32_t) CY_SCB_I2C_READ_XFER; + /* Setup context */ context->masterStatus = CY_SCB_I2C_MASTER_BUSY; @@ -1191,27 +1213,31 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterRead(CySCB_Type *base, context->masterPause = xferConfig->xferPending; context->masterRdDir = true; - /* Clean-up hardware before transfer. Note RX FIFO is empty at here */ + /* Clean-up hardware before transfer. Note RX FIFO is empty at here. */ Cy_SCB_ClearMasterInterrupt(base, CY_SCB_I2C_MASTER_INTR_ALL); Cy_SCB_ClearTxFifo(base); if (CY_SCB_I2C_IDLE == context->state) { - /* Generate Start condition */ + /* Put the address in the TX FIFO, then generate a Start condition. + * This sequence ensures that after the Start condition generation + * the address is available to be sent onto the bus. + */ + Cy_SCB_WriteTxFifo(base, address); base->I2C_M_CMD = SCB_I2C_M_CMD_M_START_ON_IDLE_Msk; } else { - /* Generate ReStart condition. Note if previous transfer was read, - * NACK is generated before ReStart to complete it. + /* Generate a ReStart condition. + * If the previous transfer was read, NACK is generated before + * ReStart to complete the previous transfer. */ base->I2C_M_CMD = (SCB_I2C_M_CMD_M_START_Msk | (_FLD2BOOL(SCB_I2C_STATUS_M_READ, base->I2C_STATUS) ? SCB_I2C_M_CMD_M_NACK_Msk : 0UL)); - } - /* Put address in TX FIFO */ - Cy_SCB_WriteTxFifo(base, _VAL2FLD(CY_SCB_I2C_ADDRESS, xferConfig->slaveAddress) | - (uint32_t) CY_SCB_I2C_READ_XFER); + /* Put address in TX FIFO */ + Cy_SCB_WriteTxFifo(base, address); + } /* Configure interrupt for data reception */ if ((context->useRxFifo) && (!context->masterPause) && (context->masterBufferSize >= 2UL)) @@ -1260,7 +1286,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterRead(CySCB_Type *base, * * This function requests master to abort read operation by NAKing the next byte * and generating a Stop condition. The function does not wait until these -* actions are completed therefore next read operation can be initiated only +* actions are completed. Therefore the next read operation can be initiated only * after the \ref CY_SCB_I2C_MASTER_BUSY is cleared. * * \param base @@ -1269,7 +1295,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterRead(CySCB_Type *base, * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * ******************************************************************************/ @@ -1358,15 +1384,28 @@ void Cy_SCB_I2C_MasterAbortRead(CySCB_Type *base, cy_stc_scb_i2c_context_t *cont * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * \ref cy_en_scb_i2c_status_t * * \note -* The buffer must not be modified and stay allocated until data has been -* copied into TX FIFO. +* * The buffer must not be modified and must stay allocated until data has been +* copied into TX FIFO. +* +* * \ref Cy_SCB_I2C_MasterWrite requests the SCB hardware to generate a Start +* Condition. The hardware will not generate the Start while the I2C bus is busy. +* The SCB hardware sets the busy status after the Start detection, and clears +* it on the Stop detection. Noise caused by the ESD or other events may cause +* an erroneous Start condition on the bus. Then, the master will never generate +* a Start condition because the hardware assumes the bus is busy. If this occurs, +* the \ref Cy_SCB_I2C_MasterGetStatus returns \ref CY_SCB_I2C_MASTER_BUSY +* status and the transaction will never finish. The option is to implement a +* timeout to detect the transfer completion. If the transfer never completes, +* the SCB needs a reset by calling the \ref Cy_SCB_I2C_Disable and +* \ref Cy_SCB_I2C_Enable functions. The \ref Cy_SCB_I2C_MasterAbortWrite +* function will not work, the block must be reset. * *******************************************************************************/ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWrite(CySCB_Type *base, @@ -1386,6 +1425,9 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWrite(CySCB_Type *base, { uint32_t intrState; + /* Set address byte (bit0 = 0, write direction) */ + uint32_t address = _VAL2FLD(CY_SCB_I2C_ADDRESS, xferConfig->slaveAddress); + /* Setup context */ context->masterStatus = CY_SCB_I2C_MASTER_BUSY; @@ -1396,26 +1438,51 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWrite(CySCB_Type *base, context->masterPause = xferConfig->xferPending; context->masterRdDir = false; - /* Clean-up hardware before transfer. Note RX FIFO is empty at here */ + /* Clean-up hardware before transfer. Note RX FIFO is empty at here. */ Cy_SCB_ClearMasterInterrupt(base, CY_SCB_I2C_MASTER_INTR_ALL); Cy_SCB_ClearTxFifo(base); if (CY_SCB_I2C_IDLE == context->state) { - /* Generate Start condition */ + /* Put the address in the TX FIFO, then generate a Start condition. + * This sequence ensures that after the Start condition generation + * the address is available to be sent onto the bus. + */ + Cy_SCB_WriteTxFifo (base, address); + Cy_SCB_ClearTxInterrupt(base, CY_SCB_TX_INTR_UNDERFLOW); base->I2C_M_CMD = SCB_I2C_M_CMD_M_START_ON_IDLE_Msk; } else { - /* Generate ReStart condition. Note if previous transfer was read, - * NACK is generated before ReStart to complete it. + /* Generate a ReStart condition. + * If the previous transfer was read, NACK is generated before + * ReStart to complete the previous transfer. */ base->I2C_M_CMD = (SCB_I2C_M_CMD_M_START_Msk | (_FLD2BOOL(SCB_I2C_STATUS_M_READ, base->I2C_STATUS) ? SCB_I2C_M_CMD_M_NACK_Msk : 0UL)); - } - /* Put address in TX FIFO */ - Cy_SCB_WriteTxFifo(base, _VAL2FLD(CY_SCB_I2C_ADDRESS, xferConfig->slaveAddress)); + if (0U == context->masterBufferSize) + { + /* The address is the last byte to transfer. + * Put the address byte in the TX FIFO and clear the TX + * Underflow interrupt source inside the critical section + * to ensure that the TX Underflow interrupt will trigger + * after the address byte is sent onto the bus. + */ + intrState = Cy_SysLib_EnterCriticalSection(); + + /* Put address in TX FIFO */ + Cy_SCB_WriteTxFifo (base, address); + Cy_SCB_ClearTxInterrupt(base, CY_SCB_TX_INTR_UNDERFLOW); + + Cy_SysLib_ExitCriticalSection(intrState); + } + else + { + /* Put address in TX FIFO */ + Cy_SCB_WriteTxFifo(base, address); + } + } context->state = CY_SCB_I2C_MASTER_TX; @@ -1445,9 +1512,9 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWrite(CySCB_Type *base, * Function Name: Cy_SCB_I2C_MasterAbortWrite ****************************************************************************//** * -* This function requests master to abort write operation by generating Stop -* condition. The function does not wait until this action is completed, -* therefore next write operation can be initiated only after the +* This function requests the master to abort write operation by generating a Stop +* condition. The function does not wait until this action is completed. +* Therefore next write operation can be initiated only after the * \ref CY_SCB_I2C_MASTER_BUSY is cleared. * * \param base @@ -1456,16 +1523,16 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWrite(CySCB_Type *base, * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \sideeffect -* If the TX FIFO is used it is cleared before Stop generation. -* The TX FIFO clear operation also clears shift register thus shifter +* If the TX FIFO is used, it is cleared before Stop generation. +* The TX FIFO clear operation also clears shift register. Thus the shifter * could be cleared in the middle of a data element transfer, corrupting it. * The remaining bits to transfer within corrupted data element are * complemented with ones.\n -* If the clear operation is requested while master transmits address +* If the clear operation is requested while the master transmits the address, * the direction of transaction is changed to read and one byte is read * before Stop is issued. This byte is discarded. * @@ -1542,7 +1609,7 @@ void Cy_SCB_I2C_MasterAbortWrite(CySCB_Type *base, cy_stc_scb_i2c_context_t *con * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1550,11 +1617,11 @@ void Cy_SCB_I2C_MasterAbortWrite(CySCB_Type *base, cy_stc_scb_i2c_context_t *con * * \note * * This function returns an invalid value if read or write transaction was -* aborted or any of listed events occurred during the transaction: +* aborted or any listed event occurs during the transaction: * \ref CY_SCB_I2C_MASTER_ARB_LOST, \ref CY_SCB_I2C_MASTER_BUS_ERR or * \ref CY_SCB_I2C_MASTER_ABORT_START. * -* * This number is only updated when the transaction completes, either through +* * This number is updated only when the transaction completes, either through * an error or successfully. * *******************************************************************************/ @@ -1577,9 +1644,9 @@ uint32_t Cy_SCB_I2C_MasterGetTransferCount(CySCB_Type const *base, cy_stc_scb_i2 ****************************************************************************//** * * Generates a Start condition and sends a slave address with the Read/Write bit. -* This function is blocking and it does not return until the Start condition -* and address byte are sent and a ACK/NAK is received, an error or timeout -* occurred. +* This function is blocking. It does not return until the Start condition +* and address byte are sent and a ACK/NAK is received, or an error or timeout +* occurs. * * \param base * The pointer to the I2C SCB instance. @@ -1593,7 +1660,7 @@ uint32_t Cy_SCB_I2C_MasterGetTransferCount(CySCB_Type const *base, cy_stc_scb_i2 * See \ref cy_en_scb_i2c_direction_t for the set of constants. * * \param timeoutMs -* Defines in milliseconds the time that this function can block for. +* Defines in milliseconds the time for which this function can block. * If that time expires, the function returns. If a zero is passed, * the function waits forever for the action to complete. If a timeout occurs, * the SCB block is reset. Note The maximum value is UINT32_MAX/1000. @@ -1601,14 +1668,14 @@ uint32_t Cy_SCB_I2C_MasterGetTransferCount(CySCB_Type const *base, cy_stc_scb_i2 * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * \ref cy_en_scb_i2c_status_t * * \note -* After a Read transaction is initiated and the slave ACKs the address, at +* After a read transaction is initiated and the slave ACKs the address, at * least one byte must be read before completing the transaction or changing * its direction. * @@ -1633,12 +1700,12 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStart(CySCB_Type *base, uint32_t timeout = CY_SCB_I2C_CONVERT_TIMEOUT_TO_US(timeoutMs); /* Set the read or write direction */ - context->state = CY_SCB_I2C_MASTER_ADDR; + context->state = CY_SCB_I2C_MASTER_ADDR; context->masterRdDir = (CY_SCB_I2C_READ_XFER == bitRnW); /* Clean up the hardware before a transfer. Note RX FIFO is empty at here */ Cy_SCB_ClearMasterInterrupt(base, CY_SCB_I2C_MASTER_INTR_ALL); - Cy_SCB_ClearRxInterrupt(base, CY_SCB_RX_INTR_NOT_EMPTY); + Cy_SCB_ClearRxInterrupt (base, CY_SCB_RX_INTR_NOT_EMPTY); Cy_SCB_ClearTxFifo(base); /* Generate a Start and send address byte */ @@ -1671,9 +1738,9 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStart(CySCB_Type *base, * * Generates a ReStart condition and sends a slave address with the Read/Write * bit. -* This function is blocking and it does not return until the ReStart condition -* and address byte are sent and an ACK/NAK is received, an error or timeout -* occurred. +* This function is blocking. It does not return until the ReStart condition +* and address byte are sent and an ACK/NAK is received, or an error or timeout +* occurs. * * \param base * The pointer to the I2C SCB instance. @@ -1687,7 +1754,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStart(CySCB_Type *base, * See \ref cy_en_scb_i2c_direction_t for the set of constants. * * \param timeoutMs -* Defines in milliseconds the time that this function can block for. +* Defines in milliseconds the time for which this function can block. * If that time expires, the function returns. If a zero is passed, * the function waits forever for the action to complete. If a timeout occurs, * the SCB block is reset. Note The maximum value is UINT32_MAX/1000. @@ -1695,7 +1762,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStart(CySCB_Type *base, * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1705,7 +1772,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStart(CySCB_Type *base, * * A successful transaction must be initiated by \ref Cy_SCB_I2C_MasterSendStart * before calling this function. If this condition is not met, this function * does nothing and returns \ref CY_SCB_I2C_MASTER_NOT_READY. -* * After a Read transaction is initiated and the slave ACKs the address, +* * After a read transaction is initiated and the slave ACKs the address, * at least one byte must be read before completing the transaction or * changing its direction. * @@ -1723,28 +1790,49 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendReStart(CySCB_Type *base, if (0UL != (CY_SCB_I2C_MASTER_ACTIVE & context->state)) { - uint32_t locStatus; + uint32_t locStatus = 0U; uint32_t timeout = CY_SCB_I2C_CONVERT_TIMEOUT_TO_US(timeoutMs); /* Set the read or write direction */ - context->state = CY_SCB_I2C_MASTER_ADDR; + context->state = CY_SCB_I2C_MASTER_ADDR; context->masterRdDir = (CY_SCB_I2C_READ_XFER == bitRnW); - /* Generate a restart (for write direction) and NACK plus restart for the Read direction */ - base->I2C_M_CMD = SCB_I2C_M_CMD_M_START_Msk | - (_FLD2BOOL(SCB_I2C_STATUS_M_READ, base->I2C_STATUS) ? - SCB_I2C_M_CMD_M_NACK_Msk : 0UL); + /* Generate ReStart condition. + * If previous transfer was read, NACK is generated before ReStart to + * complete previous transfer. + */ + base->I2C_M_CMD = SCB_I2C_M_CMD_M_START_Msk | (_FLD2BOOL(SCB_I2C_STATUS_M_READ, base->I2C_STATUS) ? + SCB_I2C_M_CMD_M_NACK_Msk : 0UL); - /* Send the address byte */ - Cy_SCB_WriteTxFifo(base, (_VAL2FLD(CY_SCB_I2C_ADDRESS, address) | (uint32_t) bitRnW)); - - /* Wait for a completion event from the or slave */ - do + /* Previous transfer was a write */ + if (false == _FLD2BOOL(SCB_I2C_STATUS_M_READ, base->I2C_STATUS)) { - locStatus = (CY_SCB_I2C_MASTER_TX_BYTE_DONE & Cy_SCB_GetMasterInterruptStatus(base)); - locStatus |= WaitOneUnit(&timeout); + /* Cypress ID #295908: Wait until ReStart is generated to complete + * the previous write transfer. This ensures that the address byte + * will not be interpreted as the data byte of the previous + * transfer. + */ + while ((0U == locStatus) && + (0U != (SCB_I2C_M_CMD_M_START_Msk & base->I2C_M_CMD))) + { + locStatus = WaitOneUnit(&timeout); + } + } - } while (0UL == locStatus); + /* Check for timeout and continue */ + if (0U == locStatus) + { + /* Send the address byte */ + Cy_SCB_WriteTxFifo(base, (_VAL2FLD(CY_SCB_I2C_ADDRESS, address) | (uint32_t) bitRnW)); + + /* Wait for a completion event from the or slave */ + do + { + locStatus = (CY_SCB_I2C_MASTER_TX_BYTE_DONE & Cy_SCB_GetMasterInterruptStatus(base)); + locStatus |= WaitOneUnit(&timeout); + + } while (0UL == locStatus); + } /* Convert the status from register plus timeout to the return status */ retStatus = HandleStatus(base, locStatus, context); @@ -1759,14 +1847,14 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendReStart(CySCB_Type *base, ****************************************************************************//** * * Generates a Stop condition to complete the current transaction. -* This function is blocking and it does not return until the Stop condition -* is generated, an error occurred or timeout occurred. +* This function is blocking. It does not return until the Stop condition +* is generated, or an error or timeout occurs. * * \param base * The pointer to the I2C SCB instance. * * \param timeoutMs -* Defines in milliseconds the time that this function can block for. +* Defines in milliseconds the time for which this function can block. * If that time expires, the function returns. If a zero is passed, * the function waits forever for the action to complete. If a timeout occurs, * the SCB block is reset. Note The maximum value is UINT32_MAX/1000. @@ -1774,7 +1862,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendReStart(CySCB_Type *base, * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1786,7 +1874,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendReStart(CySCB_Type *base, * before calling this function. If this condition is not met, this function * does nothing and returns. * \ref CY_SCB_I2C_MASTER_NOT_READY. -* * Even after the slave NAKs the address, this function has to be called +* * Even after the slave NAKs the address, this function must be called * to complete the transaction. * *******************************************************************************/ @@ -1829,8 +1917,9 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStop(CySCB_Type *base,uint32_t timeo * a NAK. The NAK will be generated before a Stop or ReStart condition by * \ref Cy_SCB_I2C_MasterSendStop or \ref Cy_SCB_I2C_MasterSendReStart function * appropriately. -* This function is blocking and it does not return until a byte is -* received, an error occurred or timeout occurred. +* This function is blocking. It does not return until a byte is +* received, or an error or timeout occurs. +* The corresponding non-blocking function is \ref Cy_SCB_I2C_MasterRead. * * \param base * The pointer to the I2C SCB instance. @@ -1843,7 +1932,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStop(CySCB_Type *base,uint32_t timeo * The pointer to the location to store the Read byte. * * \param timeoutMs -* Defines in milliseconds the time that this function can block for. +* Defines in milliseconds the time for which this function can block. * If that time expires, the function returns. If a zero is passed, * the function waits forever for the action to complete. If a timeout occurs, * the SCB block is reset. Note The maximum value is UINT32_MAX/1000. @@ -1851,7 +1940,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterSendStop(CySCB_Type *base,uint32_t timeo * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1925,8 +2014,9 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterReadByte(CySCB_Type *base, ****************************************************************************//** * * Sends one byte to a slave. -* This function is blocking and it does not return until a byte is -* transmitted, an error occurred or timeout occurred. +* This function is blocking. It does not return until a byte is +* transmitted, or an error or timeout occurs. +* The corresponding non-blocking function is \ref Cy_SCB_I2C_MasterWrite. * * \param base * The pointer to the I2C SCB instance. @@ -1935,7 +2025,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterReadByte(CySCB_Type *base, * The byte to write to a slave. * * \param timeoutMs -* Defines in milliseconds the time that this function can block for. +* Defines in milliseconds the time for which this function can block. * If that time expires, the function returns. If a zero is passed, * the function waits forever for the action to complete. If a timeout occurs, * the SCB block is reset. Note The maximum value is UINT32_MAX/1000. @@ -1943,7 +2033,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterReadByte(CySCB_Type *base, * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1992,10 +2082,12 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWriteByte(CySCB_Type *base, uint8_t byte ****************************************************************************//** * * This is the interrupt function for the SCB configured in the I2C mode. -* This function must be called inside the user-defined interrupt service -* routine in order for higher-level functions to work: -* * Slave: Any of the slave functions. -* * Master: \ref Cy_SCB_I2C_MasterRead and \ref Cy_SCB_I2C_MasterWrite. +* The interrupt is mandatory for I2C operation and this function must be called +* inside the user-defined interrupt service. The exception is the I2C master, +* which uses only the \ref group_scb_i2c_master_low_level_functions functions. +* To reduce the flash consumed by the I2C driver call +* \ref Cy_SCB_I2C_SlaveInterrupt when I2C mode is the slave and +* \ref Cy_SCB_I2C_MasterInterrupt when I2C mode is the master. * * \param base * The pointer to the I2C SCB instance. @@ -2003,7 +2095,7 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWriteByte(CySCB_Type *base, uint8_t byte * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2012,21 +2104,23 @@ void Cy_SCB_I2C_Interrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) if (0UL != (CY_SCB_I2C_MASTER_ACTIVE & context->state)) { /* Execute a transfer as the master */ - MasterInterrupt(base, context); + Cy_SCB_I2C_MasterInterrupt(base, context); } else { /* Execute a transfer as the slave */ - SlaveInterrupt(base, context); + Cy_SCB_I2C_SlaveInterrupt(base, context); } } /******************************************************************************* -* Function Name: SlaveInterrupt +* Function Name: Cy_SCB_I2C_SlaveInterrupt ****************************************************************************//** * -* This is the interrupt function to execute a slave transfer. +* This is the interrupt function for the SCB configured in I2C mode as the +* slave. This function should be called inside the user-defined interrupt +* service routine to make any of the slave functions to work. * * \param base * The pointer to the I2C SCB instance. @@ -2034,17 +2128,22 @@ void Cy_SCB_I2C_Interrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ -static void SlaveInterrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) +void Cy_SCB_I2C_SlaveInterrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) { uint32_t slaveIntrStatus; /* Handle an I2C wake-up event */ if (0UL != (CY_SCB_I2C_INTR_WAKEUP & Cy_SCB_GetI2CInterruptStatusMasked(base))) { + /* Move from IDLE state, the slave was addressed. Following address match + * interrupt continue transfer. + */ + context->state = CY_SCB_I2C_SLAVE_ACTIVE; + Cy_SCB_ClearI2CInterrupt(base, CY_SCB_I2C_INTR_WAKEUP); } @@ -2130,7 +2229,7 @@ static void SlaveInterrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2176,7 +2275,7 @@ static void SlaveHandleAddress(CySCB_Type *base, cy_stc_scb_i2c_context_t *conte else { /* Disable the stop interrupt source */ - Cy_SCB_SetI2CInterruptMask(base, CY_SCB_I2C_SLAVE_INTR_NO_STOP); + Cy_SCB_SetSlaveInterruptMask(base, CY_SCB_I2C_SLAVE_INTR_NO_STOP); } } } @@ -2266,13 +2365,13 @@ static void SlaveHandleAddress(CySCB_Type *base, cy_stc_scb_i2c_context_t *conte * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ static void SlaveHandleDataReceive(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) { - /* Check if there is space to put data */ + /* Check whether there is space to put data */ if (context->slaveRxBufferSize > 0UL) { if (context->useRxFifo) @@ -2338,7 +2437,7 @@ static void SlaveHandleDataReceive(CySCB_Type *base, cy_stc_scb_i2c_context_t *c * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2364,7 +2463,7 @@ static void SlaveHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t * Cy_SCB_SetTxInterruptMask(base, CY_SCB_TX_INTR_LEVEL); } - /* Check if the Read buffer was updated in the callback */ + /* Check whether the Read buffer was updated in the callback */ if (context->slaveRdBufEmpty) { /* The Read buffer is empty: copy CY_SCB_I2C_DEFAULT_TX into TX FIFO */ @@ -2394,10 +2493,14 @@ static void SlaveHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t * { uint32_t intrStatus; - /* Put the last data element and make sure that "TX done" will happen for it */ + /* Put the last data byte in the TX FIFO and clear the TX Underflow + * interrupt source inside the critical section to ensure that the + * TX Underflow interrupt will trigger after all data bytes from the + * TX FIFO are transferred onto the bus. + */ intrStatus = Cy_SysLib_EnterCriticalSection(); - Cy_SCB_WriteTxFifo(base, (uint32_t) context->slaveTxBuffer[0UL]); + Cy_SCB_WriteTxFifo (base, (uint32_t) context->slaveTxBuffer[0UL]); Cy_SCB_ClearTxInterrupt(base, CY_SCB_TX_INTR_UNDERFLOW); Cy_SysLib_ExitCriticalSection(intrStatus); @@ -2439,7 +2542,7 @@ static void SlaveHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t * * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2519,10 +2622,13 @@ static void SlaveHandleStop(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) /******************************************************************************* -* Function Name: MasterInterrupt +* Function Name: Cy_SCB_I2C_MasterInterrupt ****************************************************************************//** * -* This is the interrupt function for the SCB configured in the I2C master. +* This is the interrupt function for the SCB configured in I2C mode as the +* master. This function should be called inside the user-defined interrupt +* service routine to make \ref group_scb_i2c_master_high_level_functions +* functions to work. * * \param base * The pointer to the I2C SCB instance. @@ -2530,15 +2636,15 @@ static void SlaveHandleStop(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ -static void MasterInterrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) +void Cy_SCB_I2C_MasterInterrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) { uint32_t intrCause = Cy_SCB_GetInterruptCause(base); - /* Check if the slave is active. It can be addressed during the master set-up transfer */ + /* Check whether the slave is active. It can be addressed during the master set-up transfer */ if (0UL != (CY_SCB_SLAVE_INTR & intrCause)) { /* Abort the transfer due to slave operation */ @@ -2601,12 +2707,12 @@ static void MasterInterrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note * The master CY_SCB_MASTER_INTR_I2C_ACK interrupt source is used for Stop -* generation or reqest to abort transfer. +* generation or request to abort transfer. * *******************************************************************************/ static void MasterHandleEvents(CySCB_Type *base, cy_stc_scb_i2c_context_t *context) @@ -2623,7 +2729,7 @@ static void MasterHandleEvents(CySCB_Type *base, cy_stc_scb_i2c_context_t *conte context->masterStatus |= (0UL != (CY_SCB_MASTER_INTR_I2C_ACK & Cy_SCB_GetMasterInterruptStatus(base))) ? CY_SCB_I2C_MASTER_DATA_NAK : CY_SCB_I2C_MASTER_ADDR_NAK; - /* Check if Stop generation was requested before */ + /* Check whether Stop generation was requested before */ if (CY_SCB_I2C_MASTER_WAIT_STOP != context->state) { context->state = (context->masterPause) ? CY_SCB_I2C_MASTER_CMPLT : CY_SCB_I2C_MASTER_STOP; @@ -2662,7 +2768,7 @@ static void MasterHandleEvents(CySCB_Type *base, cy_stc_scb_i2c_context_t *conte * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2752,7 +2858,7 @@ static void MasterHandleDataReceive(CySCB_Type *base, cy_stc_scb_i2c_context_t * * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2781,12 +2887,14 @@ static void MasterHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t { uint32_t intrStatus; - /* Put the last data byte into TX FIFO and make sure that TX - * underflow will happen after all data is transfered onto the bus. + /* Put the last data byte in the TX FIFO and clear the TX Underflow + * interrupt source inside the critical section to ensure that the + * TX Underflow interrupt will trigger after all data bytes from the + * TX FIFO are transferred onto the bus. */ intrStatus = Cy_SysLib_EnterCriticalSection(); - Cy_SCB_WriteTxFifo(base, (uint32_t) context->masterBuffer[0UL]); + Cy_SCB_WriteTxFifo (base, (uint32_t) context->masterBuffer[0UL]); Cy_SCB_ClearTxInterrupt(base, CY_SCB_TX_INTR_UNDERFLOW); Cy_SysLib_ExitCriticalSection(intrStatus); @@ -2845,7 +2953,7 @@ static void MasterHandleDataTransmit(CySCB_Type *base, cy_stc_scb_i2c_context_t * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2887,7 +2995,7 @@ static void MasterHandleStop(CySCB_Type *base, cy_stc_scb_i2c_context_t *context * \param context * The pointer to the context structure \ref cy_stc_scb_i2c_context_t allocated * by the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -2927,8 +3035,8 @@ static void MasterHandleComplete(CySCB_Type *base, cy_stc_scb_i2c_context_t *con /* Reset the scb IP block when: * 1. Master mode: Reset IP when arbitration is lost or a bus error occurs. * 2. Master-Slave mode: Reset IP if it is not the address phase (ACK is 0). - * Otherwise, reset only on a bus error. If "lost arbitration" happened, the slave - * can be addressed, so let the slave accept the address. + * Otherwise, reset only on a bus error. If "lost arbitration" happens, the slave + * can be addressed, so let the slave accept the address. */ bool resetIp = true; @@ -2981,7 +3089,7 @@ static void MasterHandleComplete(CySCB_Type *base, cy_stc_scb_i2c_context_t *con ****************************************************************************//** * * Waits for one unit before unblock code execution. -* Note If a timeout value is 0, this function does nothing and returns 0. +* Note that if a timeout value is 0, this function does nothing and returns 0. * * \param timeout * The pointer to a timeout value. @@ -3014,7 +3122,7 @@ static uint32_t WaitOneUnit(uint32_t *timeout) * Function Name: HandleStatus ****************************************************************************//** * -* Convers passed status into the cy_en_scb_i2c_status_t. +* Converts passed status into the cy_en_scb_i2c_status_t. * * \param base * The pointer to the I2C SCB instance. @@ -3057,8 +3165,8 @@ static cy_en_scb_i2c_status_t HandleStatus(CySCB_Type *base, uint32_t status, cy if (CY_SCB_I2C_MASTER_ADDR == context->state) { /* This is the address phase: - * 1. Master mode: Reset IP when "arbitration lost" occurred. - * 2. Master-Slave mode: If "lost arbitration" occurred, the slave + * 1. Master mode: Reset IP when "arbitration lost" occurs. + * 2. Master-Slave mode: If "lost arbitration" occurs, the slave * can be addressed to let the slave accept the address; do not * reset IP. */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_i2c.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_i2c.h similarity index 76% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_i2c.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_i2c.h index 3ab2945305..1a6be34132 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_i2c.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_i2c.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_i2c.h -* \version 2.0 +* \version 2.10 * * Provides I2C API declarations of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -32,63 +32,171 @@ * * Supports slave, master, and master-slave operation * * Supports standard data rates of 100/400/1000 kbps * * Hardware Address Match, multiple addresses -* * Wake From DeepSleep on Address Match +* * Wake From Deep Sleep on Address Match * * \section group_scb_i2c_configuration Configuration Considerations +* The I2C driver configuration can be divided to number of sequential +* steps listed below: +* * \ref group_scb_i2c_config +* * \ref group_scb_i2c_pins +* * \ref group_scb_i2c_clock +* * \ref group_scb_i2c_data_rate +* * \ref group_scb_i2c_intr +* * \ref group_scb_i2c_enable * -* To set up the I2C driver, provide the configuration parameters in the +* \note +* I2C driver is built on top of the SCB hardware block. The SCB3 instance is +* used as an example for all code snippets. Modify the code to match your +* design. +* +* \subsection group_scb_i2c_config Configure I2C +* To set up the I2C slave driver, provide the configuration parameters in the * \ref cy_stc_scb_i2c_config_t structure. Provide i2cMode to the select * operation mode slave, master or master-slave. For master modes, provide -* useRxFifo and useTxFifo. For slave mode, also provide the slaveAddress and -* slaveAddressMask. The other parameters are optional for operation. -* To initialize the driver, call the \ref Cy_SCB_I2C_Init function providing -* the pointer to filled configuration structure \ref cy_stc_scb_i2c_config_t -* and the pointer to allocated context structure \ref cy_stc_scb_i2c_context_t. -* To get I2C operate with the desired data rate, the SCB clock and SCL duration -* (only applicable for master mode) must be configured. Use the SysClk driver -* API to configure SCB clock frequency and \ref Cy_SCB_I2C_SetDataRate to set -* the SCL low phase and high phase duration. Refer to the technical reference -* manual (TRM) to get more information on how to configure the I2C to operate -* with the desired data rate. Call \ref Cy_SCB_I2C_Enable to start the I2C -* operation after configuration is completed. +* useRxFifo and useTxFifo parameters. For slave mode, also provide the +* slaveAddress and slaveAddressMask. The other parameters are optional for +* operation. To initialize the driver, call \ref Cy_SCB_I2C_Init +* function providing a pointer to the filled \ref cy_stc_scb_i2c_config_t +* structure and allocated \ref cy_stc_scb_i2c_context_t. * -* Master mode operation: \n +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_CFG +* +* \subsection group_scb_i2c_pins Assign and Configure Pins +* Only dedicated SCB pins can be used for I2C operation. The HSIOM +* register must be configured to connect block to the pins. Also the I2C pins +* must be configured in Open-Drain, Drives Low mode (this pins configuration +* implies usage of external pull-up resistors): +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_CFG_PINS +* +* \note +* The alternative pins configuration is Resistive Pull-ups which implies usage +* internal pull-up resistors. This configuration is not recommended because +* resistor value is fixed and cannot be used for all supported data rates. +* Refer to the device datasheet parameter RPULLUP for resistor value specifications. +* +* \subsection group_scb_i2c_clock Assign Clock Divider +* The clock source must be connected to the SCB block to oversample input and +* output signals. You must use one of the 8-bit or 16-bit dividers (the +* source clock of this divider must be Clk_Peri). Use the +* \ref group_sysclk driver API to do that. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_CFG_ASSIGN_CLOCK +* +* Set up I2C slave read and write buffer before enabling its +* operation using \ref Cy_SCB_I2C_SlaveConfigReadBuf and \ref +* Cy_SCB_I2C_SlaveConfigWriteBuf appropriately. Note that the master reads +* data from the slave read buffer and writes data into the slave write buffer. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_CFG_BUFFER +* +* \subsection group_scb_i2c_data_rate Configure Data Rate +* To get I2C slave operation with the desired data rate, the source clock must be +* fast enough to provide sufficient oversampling. Therefore, the clock divider +* must be configured to provide desired clock frequency. Use the +* \ref group_sysclk driver API to do that. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_CFG_DATA_RATE_SLAVE +* +* To get I2C master operation with the desired data rate, the source clock +* frequency and SCL low and high phase duration must be configured. Use the +* \ref group_sysclk driver API to configure source clock frequency. Then call +* \ref Cy_SCB_I2C_SetDataRate to set the SCL low and high phase duration. +* This function reach for SCL low and high phase settings based on source clock +* frequency. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_CFG_DATA_RATE_MASTER +* +* Alternatively, the low and high phase can be set directly using +* \ref Cy_SCB_I2C_MasterSetLowPhaseDutyCycle and +* \ref Cy_SCB_I2C_MasterSetHighPhaseDutyCycle functions. \n +* Refer to the technical reference manual (TRM) section I2C sub-section +* Oversampling and Bit Rate to get information how to configure I2C to run with +* the desired data rate. +* +* \note +* For I2C slave, the analog filter is used for all supported data rates. \n +* For I2C master, the analog filter is used for Standard and Fast modes and the +* digital filter for Fast Plus mode. +* +* \subsection group_scb_i2c_intr Configure Interrupt +* The interrupt is mandatory for I2C operation. The exception is the I2C master, +* which uses only the \ref group_scb_i2c_master_low_level_functions functions. +* The driver provides three interrupt functions: \ref Cy_SCB_I2C_Interrupt, +* \ref Cy_SCB_I2C_SlaveInterrupt, and \ref Cy_SCB_I2C_MasterInterrupt. One of +* these functions must be called in the interrupt handler for the selected SCB +* instance. Call \ref Cy_SCB_I2C_SlaveInterrupt when I2C is configured to +* operate as a slave, \ref Cy_SCB_I2C_MasterInterrupt when I2C is configured +* to operate as a master and \ref Cy_SCB_I2C_Interrupt when I2C is configured +* to operate as master and slave. Using the slave- or master-specific interrupt +* function allows reducing the flash consumed by the I2C driver. Also this +* interrupt must be enabled in the NVIC otherwise it will not work. +* \note +* The I2C driver documentation refers to the \ref Cy_SCB_I2C_Interrupt function +* when interrupt processing is mandatory for the operation. This is done to +* simplify the readability of the driver's documentation. The application should +* call the slave- or master-specific interrupt functions \ref Cy_SCB_I2C_SlaveInterrupt +* or \ref Cy_SCB_I2C_MasterInterrupt, when appropriate. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_INTR_A +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_INTR_B +* +* \subsection group_scb_i2c_enable Enable I2C +* Finally, enable the I2C operation calling \ref Cy_SCB_I2C_Enable. Then I2C +* slave starts respond to the assigned address and I2C master ready to execute +* transfers. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_ENABLE +* +* \section group_scb_i2c_use_cases Common Use Cases +* +* \subsection group_scb_i2c_master_mode Master Operation * The master API is divided into two categories: * \ref group_scb_i2c_master_high_level_functions and -* \ref group_scb_i2c_master_low_level_functions. Therefore there are two -* methods for initiating I2C master transactions using either low-level or -* high-level API. These two methods are described below. Only one method should -* be used at a time. They should not be mixed. +* \ref group_scb_i2c_master_low_level_functions. Therefore, there are two +* methods for initiating I2C master transactions using either Low-Level or +* High-Level API. These two methods are described below. Only one method +* should be used at a time. They should not be mixed. * -* * Call \ref Cy_SCB_I2C_MasterRead or \ref Cy_SCB_I2C_MasterWrite to -* communicate with the slave. These functions do not block and only -* start a transaction. After a transfer is started, the -* \ref Cy_SCB_I2C_Interrupt handles the further data transfer until its -* completion. Therefore, \ref Cy_SCB_I2C_Interrupt must be called inside the -* user interrupt handler to make the API above work. To monitor the transfer, -* use \ref Cy_SCB_I2C_MasterGetStatus or \ref Cy_SCB_I2C_RegisterEventCallback -* to register callback function to be notified about -* \ref group_scb_i2c_macros_callback_events. +* \subsubsection group_scb_i2c_master_hl Use High-Level Functions +* Call \ref Cy_SCB_I2C_MasterRead or \ref Cy_SCB_I2C_MasterWrite to +* communicate with the slave. These functions do not block and only start a +* transaction. After a transaction starts, the \ref Cy_SCB_I2C_Interrupt +* handles the further data transaction until its completion (successfully or with an error +* occurring). Therefore, \ref Cy_SCB_I2C_Interrupt must be called inside the +* interrupt handler to make the functions above work. To monitor the transaction, +* use \ref Cy_SCB_I2C_MasterGetStatus or register callback function using +* \ref Cy_SCB_I2C_RegisterEventCallback to be notified about +* \ref group_scb_i2c_macros_callback_events. * -* * Call \ref Cy_SCB_I2C_MasterSendStart to generate a start, send an address -* with the Read/Write direction bit, and receive acknowledgment. After the -* address is ACKed by the slave, the transaction can be continued by calling -* \ref Cy_SCB_I2C_MasterReadByte or \ref Cy_SCB_I2C_MasterWriteByte depending -* on its direction. These functions handle one byte per call, therefore -* they should be called for each byte in the transaction. Note that for the -* Read transaction the last byte must be NAKed. To complete the current -* transaction, call \ref Cy_SCB_I2C_MasterSendStop or call -* \ref Cy_SCB_I2C_MasterSendReStart to complete the current transaction and -* start a new one. Typically, do a restart to change the transaction -* direction without releasing the bus from the master control. -* Note that these functions are blocking and do not require calling -* \ref Cy_SCB_I2C_Interrupt inside the user interrupt handler. Using these -* functions requires extensive knowledge of the I2C protocol to execute -* transactions correctly. +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_MASTER_WRITE_READ_INT * -* Slave mode operation: \n +* \subsubsection group_scb_i2c_master_ll Use Low-Level Functions +* Call \ref Cy_SCB_I2C_MasterSendStart to generate a start, send an address +* with the Read/Write direction bit, and receive acknowledgment. After the +* address is ACKed by the slave, the transaction can be continued by calling +* \ref Cy_SCB_I2C_MasterReadByte or \ref Cy_SCB_I2C_MasterWriteByte depending +* on its direction. These functions handle one byte per call. Therefore, +* they should be called for each byte in the transaction. Note that for the +* Read transaction, the last byte must be NAKed. To complete the current +* transaction, call \ref Cy_SCB_I2C_MasterSendStop or call +* \ref Cy_SCB_I2C_MasterSendReStart to complete the current transaction and +* start a new one. Typically, do a restart to change the transaction +* direction without releasing the bus from the master control. +* The Low-Level functions are blocking and do not require calling +* \ref Cy_SCB_I2C_Interrupt inside the interrupt handler. Using these +* functions requires extensive knowledge of the I2C protocol to execute +* transactions correctly. +* +* Master Write Operation +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_MASTER_WRITE_MANUAL +* +* Master Read Operation +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_MASTER_READ_MANUAL +* +* \subsection group_scb_i2c_slave Slave Operation * The slave operation is based on the \ref Cy_SCB_I2C_Interrupt that must be -* called inside the user interrupt handler. The Read and Write buffer must +* called inside the interrupt handler. The Read and Write buffer must * be provided for the slave to enable communication with the master. Use * \ref Cy_SCB_I2C_SlaveConfigReadBuf and \ref Cy_SCB_I2C_SlaveConfigWriteBuf * for this purpose. Note that after transaction completion the buffer must be @@ -97,26 +205,39 @@ * For example: The Read buffer is configured to be 10 bytes and the master Read * is 8 bytes. If the Read buffer is not configured again, the next master Read * will start from the 9th byte. -* To monitor the transfer status, use \ref Cy_SCB_I2C_SlaveGetStatus or +* To monitor the transaction status, use \ref Cy_SCB_I2C_SlaveGetStatus or * use \ref Cy_SCB_I2C_RegisterEventCallback to register a callback function * to be notified about \ref group_scb_i2c_macros_callback_events. * +* Get Slave Events Notification +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_SLAVE_REG_CALLBACK +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_SLAVE_NOTIFICATION +* +* Polling Slave Completion Events +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\i2c_snippets.c I2C_SLAVE_POLLING +* * \note * All slave API (except \ref Cy_SCB_I2C_SlaveAbortRead and -* \ref Cy_SCB_I2C_SlaveAbortWrite) are not interrupt-protected and to +* \ref Cy_SCB_I2C_SlaveAbortWrite) are not interrupt-protected and to * prevent a race condition, they should be protected from the I2C interruption * in the place where they are called. * -* The I2C driver provides the callback functions to facilitate the low-power -* mode transition. The callback \ref Cy_SCB_I2C_DeepSleepCallback can be called +* \section group_scb_i2c_lp Low Power Support +* The I2C driver provides the callback functions to handle power mode transition. +* The callback \ref Cy_SCB_I2C_DeepSleepCallback must be called * during execution of \ref Cy_SysPm_DeepSleep; \ref Cy_SCB_I2C_HibernateCallback -* can be called during execution of \ref Cy_SysPm_Hibernate. To trigger the +* must be called during execution of \ref Cy_SysPm_Hibernate. To trigger the * callback execution, the callback must be registered before calling the -* mode transition function. Refer to SysPm driver for more information about -* low-power mode transitions. +* power mode transition function. Refer to \ref group_syspm driver for more +* information about power mode transitions and callback registration. +* +* \note +* Only applicable for rev-08 of the CY8CKIT-062-BLE. +* For proper operation, when the I2C slave is configured to be a wakeup +* source from Deep Sleep mode, the \ref Cy_SCB_I2C_DeepSleepCallback must be +* copied and modified. Refer to the function description to get the details. * * \section group_scb_i2c_more_information More Information -* * For more information on the SCB peripheral, refer to the technical reference * manual (TRM). * @@ -136,7 +257,7 @@ * * * @@ -173,7 +294,7 @@ * function. * +* validation fails. * *
VersionChangesReason for Change
2.10None.SCB I2C driver updated.
2.0Added parameters validation for public API.
Replaced variables which have limited range of values with enumerated +* Replaced variables that have limited range of values with enumerated * types.
The functions \ref Cy_SCB_I2C_DeepSleepCallback and * \ref Cy_SCB_I2C_HibernateCallback are callback of * \ref cy_en_syspm_status_t type. The cast operation safety in these -* functions becomes the user responsibility because pointers are +* functions becomes the user's responsibility because pointers are * initialized when callback is registered in SysPm driver.
The functions can return from several points. This is done to improve * code clarity when returning error status code if input parameters -* validation is failed.
* @@ -181,7 +302,56 @@ * * * -* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* * * * @@ -245,8 +415,8 @@ typedef enum /** * The master is not ready to start a new transaction. * Either the master is still processing a previous transaction or in the - * master-slave mode the slave operation is in progress. Call this function - * again once that operation is completed or aborted. + * master-slave mode, the slave operation is in progress. Call this function + * again after that operation is completed or aborted. */ CY_SCB_I2C_MASTER_NOT_READY = (CY_SCB_ID | CY_PDL_STATUS_ERROR | CY_SCB_I2C_ID | 2U), @@ -334,7 +504,7 @@ typedef void (* cy_cb_scb_i2c_handle_events_t)(uint32_t event); * \ref group_scb_i2c_macros_addr_callback_events. * This callback must return a decision to ACK (continue transaction) or * NAK (end transaction) the received address. -* Note if the slave configured to accept an address in RX FIFO, it must read +* Note if the slave is configured to accept an address in RX FIFO, it must read * from it using the \ref Cy_SCB_ReadRxFifo function. */ typedef cy_en_scb_i2c_command_t (* cy_cb_scb_i2c_handle_addr_t)(uint32_t event); @@ -354,20 +524,20 @@ typedef struct cy_stc_scb_i2c_config * FIFO when it has some number of bytes (typically, when it is half full). * * If this option is disabled, the interrupt is enabled to take data out of * the RX FIFO when a byte is available. Also, hardware does not - * automatically ACK the data, firmware must tell the hardware to ACK + * automatically ACK the data. Firmware must tell the hardware to ACK * the byte (so each byte requires interrupt processing). * \n Typically, this option should be enabled to configure hardware to * automatically ACK incoming data. Otherwise hardware might not get the command * to ACK or NACK a byte fast enough, and clock stretching is applied - * (the transaction is delayed) until command is set. When this option is - * enabled the number of interrupts required to process the transaction + * (the transaction is delayed) until the command is set. When this option is + * enabled, the number of interrupts required to process the transaction * is significantly reduced because several bytes are handled at once. * \n However, there is a side effect: * * For master mode, the drawback is that the master may receive more * data than desired due to the interrupt latency. An interrupt fires * when the second-to-last byte has been received. This interrupt tells * the hardware to stop receiving data. If the latency of this interrupt - * is longer than one transfer of the byte on the I2C bus, then the + * is longer than one transaction of the byte on the I2C bus, then the * hardware automatically ACKs the following bytes until the interrupt * is serviced or the RX FIFO becomes full. * * For slave mode, the drawback is that the slave only NACKs @@ -389,14 +559,14 @@ typedef struct cy_stc_scb_i2c_config * (so each byte requires interrupt processing). * \n Typically, this option should be enabled to keep the TX FIFO loaded with * data and reduce the probability of clock stretching. When there is no data - * to transfer, clock stretching is applied (the transaction is delayed) until - * data is loaded. When this option is enabled the number of interrupts required + * to transaction, clock stretching is applied (the transaction is delayed) until + * the data is loaded. When this option is enabled, the number of interrupts required * to process the transaction is significantly reduced because several * bytes are handled at once. * \n The drawback of enabling useTxFifo is that the abort operation clears * the TX FIFO. The TX FIFO clear operation also clears the shift * register. As a result the shifter may be cleared in the middle of a byte - * transfer, corrupting it. The remaining bits to transfer within the + * transaction, corrupting it. The remaining bits to transaction within the * corrupted byte are complemented with 1s. If this is an issue, * then do not enable this option. */ @@ -426,7 +596,7 @@ typedef struct cy_stc_scb_i2c_config bool ackGeneralAddr; /** - * When set, the slave will wake the device from deep sleep on an address + * When set, the slave will wake the device from Deep Sleep on an address * match (the device datasheet must be consulted to determine which SCBs * support this mode) */ @@ -437,9 +607,9 @@ typedef struct cy_stc_scb_i2c_config * All fields for the context structure are internal. Firmware never reads or * writes these values. Firmware allocates the structure and provides the * address of the structure to the driver in function calls. Firmware must -* ensure that the defined instance of this structure remains in scope while +* ensure that the defined instance of this structure remains in scope * while the drive is in use. - */ +*/ typedef struct cy_stc_scb_i2c_context { /** \cond INTERNAL */ @@ -449,8 +619,8 @@ typedef struct cy_stc_scb_i2c_context volatile uint32_t state; /**< The driver state */ volatile uint32_t masterStatus; /**< The master status */ - bool masterPause; /**< Stores how the master ends the transfer */ - bool masterRdDir; /**< The direction of the master transfer */ + bool masterPause; /**< Stores how the master ends the transaction */ + bool masterRdDir; /**< The direction of the master transaction */ uint8_t *masterBuffer; /**< The pointer to the master buffer (either for a transmit or a receive operation) */ uint32_t masterBufferSize; /**< The current master buffer size */ @@ -589,7 +759,9 @@ cy_en_scb_i2c_status_t Cy_SCB_I2C_MasterWriteByte (CySCB_Type *base, uint8_t by * \addtogroup group_scb_i2c_interrupt_functions * \{ */ -void Cy_SCB_I2C_Interrupt(CySCB_Type *base, cy_stc_scb_i2c_context_t *context); +void Cy_SCB_I2C_Interrupt (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); +void Cy_SCB_I2C_SlaveInterrupt (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); +void Cy_SCB_I2C_MasterInterrupt (CySCB_Type *base, cy_stc_scb_i2c_context_t *context); __STATIC_INLINE void Cy_SCB_I2C_RegisterEventCallback(CySCB_Type const *base, cy_cb_scb_i2c_handle_events_t callback, cy_stc_scb_i2c_context_t *context); @@ -621,7 +793,7 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t * may be set to indicate the current status. * \{ */ -/** There is a Read transaction in progress */ +/** There is a read transaction in progress */ #define CY_SCB_I2C_SLAVE_RD_BUSY (0x00000001UL) /** @@ -642,7 +814,7 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t */ #define CY_SCB_I2C_SLAVE_RD_UNDRFL (0x00000008UL) -/** There is a Write transaction in progress */ +/** There is a write transaction in progress */ #define CY_SCB_I2C_SLAVE_WR_BUSY (0x00000010UL) /** @@ -656,11 +828,11 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t */ #define CY_SCB_I2C_SLAVE_WR_OVRFL (0x00000040UL) -/** The slave lost arbitration, the transaction was aborted */ +/** The slave lost arbitration, and the transaction was aborted */ #define CY_SCB_I2C_SLAVE_ARB_LOST (0x00000080UL) /** -* The slave captured an error on the bus during a master transaction (sources +* The slave captured an error on the bus during a master transaction (source * of error is misplaced Start or Stop). */ #define CY_SCB_I2C_SLAVE_BUS_ERR (0x00000100UL) @@ -770,7 +942,7 @@ cy_en_syspm_status_t Cy_SCB_I2C_HibernateCallback(cy_stc_syspm_callback_params_t #define CY_SCB_I2C_MASTER_RD_CMPLT_EVENT (0x00040000UL) /** -* Indicates the I2C hardware detected an error. It occurs together with +* Indicates the I2C hardware has detected an error. It occurs together with * \ref CY_SCB_I2C_MASTER_RD_CMPLT_EVENT or \ref CY_SCB_I2C_MASTER_WR_CMPLT_EVENT * depends on the direction of the transfer. * Check \ref Cy_SCB_I2C_MasterGetStatus to determine the source of the error. @@ -995,7 +1167,7 @@ __STATIC_INLINE void Cy_SCB_I2C_Enable(CySCB_Type *base) * Function Name: Cy_SCB_I2C_IsBusBusy ****************************************************************************//** * -* Checks if the I2C bus is busy. +* Checks whether the I2C bus is busy. * * \param base * The pointer to the I2C SCB instance. @@ -1182,7 +1354,7 @@ __STATIC_INLINE void Cy_SCB_I2C_MasterSetHighPhaseDutyCycle(CySCB_Type *base, ui * \param context * The pointer to context structure \ref cy_stc_scb_i2c_context_t allocated by * the user. The structure is used while the I2C operation for internal -* configuration and data keeping. The user should not modify anything in +* configuration and data retention. The user should not modify anything in * this structure. * * \note @@ -1217,7 +1389,7 @@ __STATIC_INLINE void Cy_SCB_I2C_RegisterEventCallback(CySCB_Type const *base, * \param context * The pointer to context structure \ref cy_stc_scb_i2c_context_t allocated by * the user. The structure is used during the I2C operation for internal -* configuration and data keeping. The user should not modify anything in +* configuration and data retention. The user should not modify anything in * this structure. * * \note diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_spi.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_spi.c similarity index 84% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_spi.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_spi.c index ebc6a21e71..606e086eac 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_spi.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_spi.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_spi.c -* \version 2.0 +* \version 2.10 * * Provides SPI API implementation of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -38,9 +38,9 @@ static void DiscardArrayNoCheck(CySCB_Type const *base, uint32_t size); * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. -* If only SPI functions which do not require context will be used pass NULL +* If only SPI functions that do not require context will be used to pass NULL * as pointer to context. * * \return @@ -53,7 +53,7 @@ static void DiscardArrayNoCheck(CySCB_Type const *base, uint32_t size); cy_en_scb_spi_status_t Cy_SCB_SPI_Init(CySCB_Type *base, cy_stc_scb_spi_config_t const *config, cy_stc_scb_spi_context_t *context) { /* Input parameters verification */ - if ((NULL == base) && (NULL == config)) + if ((NULL == base) || (NULL == config)) { return CY_SCB_SPI_BAD_PARAM; } @@ -156,7 +156,7 @@ cy_en_scb_spi_status_t Cy_SCB_SPI_Init(CySCB_Type *base, cy_stc_scb_spi_config_t * Function Name: Cy_SCB_SPI_DeInit ****************************************************************************//** * -* De-initializes the SCB block, returns the register values to default. +* De-initializes the SCB block; returns the register values to default. * * \param base * The pointer to the SPI SCB instance. @@ -193,9 +193,9 @@ void Cy_SCB_SPI_DeInit(CySCB_Type *base) * Function Name: Cy_SCB_SPI_Disable ****************************************************************************//** * -* Disables the SCB block, clears context statuses and disables +* Disables the SCB block, clears context statuses, and disables * TX and RX interrupt sources. -* Note that after the block is disabled the TX and RX FIFOs and +* Note that after the block is disabled, the TX and RX FIFOs and * hardware statuses are cleared. Also, the hardware stops driving the output * and ignores the input. * @@ -205,16 +205,16 @@ void Cy_SCB_SPI_DeInit(CySCB_Type *base) * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. -* If only SPI functions which do not require context will be used pass NULL +* If only SPI functions that do not require context will be used to pass NULL * as pointer to context. * * \note * Calling this function when the SPI is busy (master preforms data transfer or * slave communicates with the master) may cause transfer corruption because the * hardware stops driving the outputs and ignores the inputs. -* It is recommenced to ensure that the SPI is not busy before calling this +* Ensure that the SPI is not busy before calling this * function. * *******************************************************************************/ @@ -247,25 +247,34 @@ void Cy_SCB_SPI_Disable(CySCB_Type *base, cy_stc_scb_spi_context_t *context) ****************************************************************************//** * * This function handles the transition of the SCB SPI into and out of -* Deep-Sleep mode. It prevents the device from entering Deep-Sleep if the -* SPI slave or master is actively communicating, or there is any data in the -* TX or RX FIFOs. -* The following behavior of the SPI SCB depends on if the SCB block is +* Deep Sleep mode. It prevents the device from entering Deep Sleep mode +* if the SPI slave or master is actively communicating, or there is any data +* in the TX or RX FIFOs. +* The following behavior of the SPI SCB depends on whether the SCB block is * wakeup-capable or not: -* * The SCB wakeup-capable: any transfer intended to the slave wakes up the -* device from Deep-Sleep mode. The slave responds with 0xFF to the transfer. -* If the transfer occurs before the device enters Deep-Sleep mode, the device -* will not enter Deep-Sleep mode and incoming data is stored in the RX FIFO, -* otherwise incoming data is ignored. -* Only the SPI slave can be configured to be a wakeup source from Deep-Sleep +* * The SCB is wakeup-capable: any transfer intended to the slave wakes up +* the device from Deep Sleep mode. The slave responds with 0xFF to the transfer +* and incoming data is ignored. +* If the transfer occurs before the device enters Deep Sleep mode, the device +* will not enter Deep Sleep mode and incoming data is stored in the RX FIFO. +* The SCB clock is disabled before entering Deep Sleep and enabled after the +* device exits Deep Sleep mode. The SCB clock must be enabled after exiting +* Deep Sleep mode and after the source of hf_clk[0] gets stable, this includes +* the FLL/PLL. The SysClk callback ensures that hf_clk[0] gets stable and +* it must be called before Cy_SCB_SPI_DeepSleepCallback. The SCB clock +* disabling may lead to corrupted data in the RX FIFO. Clear the RX FIFO +* after this callback is executed. If the transfer occurs before the device +* enters Deep Sleep mode, the device will not enter Deep Sleep mode and +* incoming data will be stored in the RX FIFO. \n +* Only the SPI slave can be configured to be a wakeup source from Deep Sleep * mode. -* * The SCB is not wakeup-capable: the SPI is disabled. It is enabled when the -* device failed to enter Deep-Sleep mode or it is awaken from Deep-Sleep mode. -* During the SPI is disabled, it stops driving the outputs and ignores the +* * The SCB is not wakeup-capable: the SPI is disabled. It is enabled when +* the device fails to enter Deep Sleep mode or it is awakened from Deep Sleep +* mode. While the SPI is disabled, it stops driving the outputs and ignores the * inputs. Any incoming data is ignored. * -* This function can be called during execution of \ref Cy_SysPm_DeepSleep, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_DeepSleep. +* To do it, register this function as a callback before calling * \ref Cy_SysPm_DeepSleep : specify \ref CY_SYSPM_DEEPSLEEP as the callback * type and call \ref Cy_SysPm_RegisterCallback. * @@ -276,6 +285,13 @@ void Cy_SCB_SPI_Disable(CySCB_Type *base, cy_stc_scb_spi_context_t *context) * \return * \ref cy_en_syspm_status_t * +* \note +* Only applicable for rev-08 of the CY8CKIT-062-BLE. +* For proper operation, when the SPI slave is configured to be a wakeup source +* from Deep Sleep mode, this function must be copied and modified by the user. +* The SPI clock disable code must be inserted in the \ref CY_SYSPM_BEFORE_TRANSITION +* and clock enable code in the \ref CY_SYSPM_AFTER_TRANSITION mode processing. +* *******************************************************************************/ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) { @@ -288,14 +304,14 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t { case CY_SYSPM_CHECK_READY: { - /* Check if the High-level API is not busy executing the transfer + /* Check whether the High-level API is not busy executing the transfer * operation. */ if (0UL == (CY_SCB_SPI_TRANSFER_ACTIVE & Cy_SCB_SPI_GetTransferStatus(locBase, locContext))) { /* If the SPI bus is not busy, all data elements are transferred * on the bus from the TX FIFO and shifter and the RX FIFOs are - * empty - the SPI is ready to enter Deep-Sleep mode. + * empty - the SPI is ready to enter Deep Sleep mode. */ if (!Cy_SCB_SPI_IsBusBusy(locBase)) { @@ -323,8 +339,8 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t /* The SCB is NOT wakeup-capable: disable the * SPI. The master and slave stop driving the * bus until the SPI is enabled. This happens - * when the device failed to enter Deep-Sleep - * mode or it is awaken from Deep-Sleep mode. + * when the device fails to enter Deep Sleep + * mode or it is awakened from Deep Sleep mode. */ Cy_SCB_SPI_Disable(locBase, locContext); @@ -339,7 +355,7 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t case CY_SYSPM_CHECK_FAIL: { - /* The other driver is not ready for Deep-Sleep mode. Restore + /* The other driver is not ready for Deep Sleep mode. Restore * Active mode configuration. */ @@ -357,7 +373,7 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t { /* This code executes inside the critical section and enabling the * active interrupt source makes the interrupt pending in the NVIC. - * However, the interrupt processing is delayed until the code exists + * However, the interrupt processing is delayed until the code exits * the critical section. The pending interrupt force WFI instruction * does nothing and the device remains in Active mode. */ @@ -365,10 +381,19 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t if (_FLD2BOOL(SCB_CTRL_EC_AM_MODE, locBase->CTRL)) { /* The SCB is wakeup-capable: enable the SPI wakeup interrupt - * source. If any transaction happened, the wakeup interrupt - * becomes pending and prevents entering Deep-Sleep mode. + * source. If any transaction happens, the wakeup interrupt + * becomes pending and prevents entering Deep Sleep mode. */ Cy_SCB_SetSpiInterruptMask(locBase, CY_SCB_I2C_INTR_WAKEUP); + + /* Disable SCB clock */ + locBase->I2C_CFG &= (uint32_t) ~CY_SCB_I2C_CFG_CLK_ENABLE_Msk; + + /* IMPORTANT (replace line above for the CY8CKIT-062 rev-08): + * for proper entering Deep Sleep mode the SPI clock must be disabled. + * This code must be inserted by the user because the driver + * does not have access to the clock. + */ } retStatus = CY_SYSPM_SUCCESS; @@ -379,6 +404,15 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t { if (_FLD2BOOL(SCB_CTRL_EC_AM_MODE, locBase->CTRL)) { + /* Enable SCB clock */ + locBase->I2C_CFG |= CY_SCB_I2C_CFG_CLK_ENABLE_Msk; + + /* IMPORTANT (replace line above for the CY8CKIT-062 rev-08): + * for proper exiting Deep Sleep mode, the SPI clock must be enabled. + * This code must be inserted by the user because the driver + * does not have access to the clock. + */ + /* The SCB is wakeup-capable: disable the SPI wakeup interrupt * source */ @@ -407,15 +441,15 @@ cy_en_syspm_status_t Cy_SCB_SPI_DeepSleepCallback(cy_stc_syspm_callback_params_t ****************************************************************************//** * * This function handles the transition of the SCB SPI into Hibernate mode. -* It prevents the device from entering Hibernate mode if the SPI slave or master -* is actively communicating, or there is any data in the TX or RX FIFOs. +* It prevents the device from entering Hibernate mode if the SPI slave or +* master is actively communicating, or there is any data in the TX or RX FIFOs. * If the SPI is ready to enter Hibernate mode, it is disabled. If the device -* failed to enter Hibernate mode, the SPI is enabled. During the SPI is +* failed to enter Hibernate mode, the SPI is enabled. While the SPI is * disabled, it stops driving the outputs and ignores the inputs. * Any incoming data is ignored. * -* This function can be called during execution of \ref Cy_SysPm_Hibernate, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_Hibernate. +* To do it, register this function as a callback before calling * \ref Cy_SysPm_Hibernate : specify \ref CY_SYSPM_HIBERNATE as the callback * type and call \ref Cy_SysPm_RegisterCallback. * @@ -438,7 +472,7 @@ cy_en_syspm_status_t Cy_SCB_SPI_HibernateCallback(cy_stc_syspm_callback_params_t { case CY_SYSPM_CHECK_READY: { - /* Check if the High-level API is not busy executing the transfer + /* Check whether the High-level API is not busy executing the transfer * operation. */ if (0UL == (CY_SCB_SPI_TRANSFER_ACTIVE & Cy_SCB_SPI_GetTransferStatus(locBase, locContext))) @@ -470,7 +504,7 @@ cy_en_syspm_status_t Cy_SCB_SPI_HibernateCallback(cy_stc_syspm_callback_params_t case CY_SYSPM_CHECK_FAIL: { - /* The other driver is not ready for Deep-Sleep mode. Restore Active + /* The other driver is not ready for Hibernate mode. Restore Active * mode configuration. */ @@ -516,14 +550,14 @@ cy_en_syspm_status_t Cy_SCB_SPI_HibernateCallback(cy_stc_syspm_callback_params_t * If the data that will be received is not important, pass NULL as rxBuffer. * If the data that will be transmitted is not important, pass NULL as txBuffer * and then the \ref CY_SCB_SPI_DEFAULT_TX is sent out as each data element. -* Note that passing NULL as rxBuffer and txBuffer considered invalid case. +* Note that passing NULL as rxBuffer and txBuffer are considered invalid cases. * * After the function configures TX and RX interrupt sources, it returns and * \ref Cy_SCB_SPI_Interrupt manages further data transfer. * -* * In the master mode, the transfer operation is started after calling this +* * In the master mode, the transfer operation starts after calling this * function -* * In the slave mode, the transfer is registered and will be started when +* * In the slave mode, the transfer registers and will start when * the master request arrives. * * When the transfer operation is completed (requested number of data elements @@ -535,12 +569,12 @@ cy_en_syspm_status_t Cy_SCB_SPI_HibernateCallback(cy_stc_syspm_callback_params_t * * \param txBuffer * The pointer of the buffer with data to transmit. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type that depends on the configured * TX data width. * * \param rxBuffer * The pointer to the buffer to store received data. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type that depends on the configured * RX data width. * * \param size @@ -549,14 +583,14 @@ cy_en_syspm_status_t Cy_SCB_SPI_HibernateCallback(cy_stc_syspm_callback_params_t * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * \ref cy_en_scb_spi_status_t * * \note -* * The buffers must not be modified and stay allocated until the end of the +* * The buffers must not be modified and must stay allocated until the end of the * transfer. * * This function overrides all RX and TX FIFO interrupt sources and changes * the RX and TX FIFO level. @@ -571,7 +605,7 @@ cy_en_scb_spi_status_t Cy_SCB_SPI_Transfer(CySCB_Type *base, void *txBuffer, voi cy_en_scb_spi_status_t retStatus = CY_SCB_SPI_TRANSFER_BUSY; - /* Check if there are no active transfer requests */ + /* Check whether there are no active transfer requests */ if (0UL == (CY_SCB_SPI_TRANSFER_ACTIVE & context->status)) { uint32_t fifoSize = Cy_SCB_GetFifoSize(base); @@ -640,20 +674,20 @@ cy_en_scb_spi_status_t Cy_SCB_SPI_Transfer(CySCB_Type *base, void *txBuffer, voi * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note * In the slave mode and after abort of transfer operation master continue * sending data it gets into RX FIFO and TX FIFO is underflow as there is -* nothing to send. To drop this data, RX FIFO has to be cleared when -* the transfer is completed. Otherwise, received data will be kept and +* nothing to send. To drop this data, RX FIFO must be cleared when +* the transfer is complete. Otherwise, received data will be kept and * copied to the buffer when \ref Cy_SCB_SPI_Transfer is called. * * \sideeffect * The transmit FIFO clear operation also clears the shift register, so that -* the shifter could be cleared in the middle of a data element transfer, -* corrupting it. The data element corruption means that all bits which has +* the shifter can be cleared in the middle of a data element transfer, +* corrupting it. The data element corruption means that all bits that have * not been transmitted are transmitted as "ones" on the bus. * *******************************************************************************/ @@ -695,7 +729,7 @@ void Cy_SCB_SPI_AbortTransfer(CySCB_Type *base, cy_stc_scb_spi_context_t *contex * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -725,7 +759,7 @@ uint32_t Cy_SCB_SPI_GetNumTransfered(CySCB_Type const *base, cy_stc_scb_spi_cont * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -751,7 +785,7 @@ uint32_t Cy_SCB_SPI_GetTransferStatus(CySCB_Type const *base, cy_stc_scb_spi_con * * This is the interrupt function for the SCB configured in the SPI mode. * This function must be called inside the user-defined interrupt service -* routine in order for \ref Cy_SCB_SPI_Transfer to work. +* routine for \ref Cy_SCB_SPI_Transfer to work. * * \param base * The pointer to the SPI SCB instance. @@ -759,13 +793,13 @@ uint32_t Cy_SCB_SPI_GetTransferStatus(CySCB_Type const *base, cy_stc_scb_spi_con * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ void Cy_SCB_SPI_Interrupt(CySCB_Type *base, cy_stc_scb_spi_context_t *context) { - uint32 locXferErr = 0UL; + bool locXferErr = false; /* Wake up on the slave select condition */ if (0UL != (CY_SCB_SPI_INTR_WAKEUP & Cy_SCB_GetSpiInterruptStatusMasked(base))) @@ -776,7 +810,7 @@ void Cy_SCB_SPI_Interrupt(CySCB_Type *base, cy_stc_scb_spi_context_t *context) /* The slave error condition */ if (0UL != (CY_SCB_SLAVE_INTR_SPI_BUS_ERROR & Cy_SCB_GetSlaveInterruptStatusMasked(base))) { - locXferErr = CY_SCB_SPI_TRANSFER_ERR; + locXferErr = true; context->status |= CY_SCB_SPI_SLAVE_TRANSFER_ERR; Cy_SCB_ClearSlaveInterrupt(base, CY_SCB_SLAVE_INTR_SPI_BUS_ERROR); @@ -785,7 +819,7 @@ void Cy_SCB_SPI_Interrupt(CySCB_Type *base, cy_stc_scb_spi_context_t *context) /* The RX overflow error condition */ if (0UL != (CY_SCB_RX_INTR_OVERFLOW & Cy_SCB_GetRxInterruptStatusMasked(base))) { - locXferErr = CY_SCB_SPI_TRANSFER_ERR; + locXferErr = true; context->status |= CY_SCB_SPI_TRANSFER_OVERFLOW; Cy_SCB_ClearRxInterrupt(base, CY_SCB_RX_INTR_OVERFLOW); @@ -794,18 +828,18 @@ void Cy_SCB_SPI_Interrupt(CySCB_Type *base, cy_stc_scb_spi_context_t *context) /* The TX underflow error condition or slave complete data transfer */ if (0UL != (CY_SCB_TX_INTR_UNDERFLOW & Cy_SCB_GetTxInterruptStatusMasked(base))) { - locXferErr = CY_SCB_SPI_TRANSFER_ERR; + locXferErr = true; context->status |= CY_SCB_SPI_TRANSFER_UNDERFLOW; Cy_SCB_ClearTxInterrupt(base, CY_SCB_TX_INTR_UNDERFLOW); } /* Report an error, use a callback */ - if (0UL != locXferErr) + if (locXferErr) { if (NULL != context->cbEvents) { - context->cbEvents(CY_SCB_SPI_TRANSFER_ERR); + context->cbEvents(CY_SCB_SPI_TRANSFER_ERR_EVENT); } } @@ -854,7 +888,7 @@ void Cy_SCB_SPI_Interrupt(CySCB_Type *base, cy_stc_scb_spi_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -919,7 +953,7 @@ static void HandleReceive(CySCB_Type *base, cy_stc_scb_spi_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_spi.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_spi.h similarity index 82% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_spi.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_spi.h index f1be6d370f..f118099a28 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_spi.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_spi.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_spi.h -* \version 2.0 +* \version 2.10 * * Provides SPI API declarations of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -27,31 +27,101 @@ * data widths. * * \section group_scb_spi_configuration Configuration Considerations +* The SPI driver configuration can be divided to number of sequential +* steps listed below: +* * \ref group_scb_spi_config +* * \ref group_scb_spi_pins +* * \ref group_scb_spi_clock +* * \ref group_scb_spi_data_rate +* * \ref group_scb_spi_intr +* * \ref group_scb_spi_enable * -* To set up an SPI, provide configuration parameters in the +* \note +* The SPI driver is built on top of the SCB hardware block. The SCB1 instance is +* used as an example for all code snippets. Modify the code to match your +* design. +* +* \subsection group_scb_spi_config Configure SPI +* To set up the SPI slave driver, provide the configuration parameters in the * \ref cy_stc_scb_spi_config_t structure. For example: provide spiMode, * subMode, sclkMode, oversample, rxDataWidth, and txDataWidth. The other -* parameters are optional for operation. To initialize the driver, -* call the \ref Cy_SCB_SPI_Init function providing the filled -* \ref cy_stc_scb_spi_config_t structure and allocated -* \ref cy_stc_scb_spi_context_t. To get the SPI operate with the desired data rate -* the SCB clock and SCLK duration (only applicable for master mode) must be -* configured. Use the SysClk driver API to configure the SCB clock frequency and -* initialize the oversample parameter in the \ref cy_stc_scb_spi_config_t -* structure to set SCLK duration. Refer to the technical reference -* manual (TRM) to get more information on how to configure the SPI to operate -* with the desired data rate. Call \ref Cy_SCB_SPI_Enable to start the SPI -* operation after configuration is completed. +* parameters are optional for operation. To initialize the driver, call +* \ref Cy_SCB_SPI_Init function providing a pointer to the filled +* \ref cy_stc_scb_spi_config_t structure and allocated \ref cy_stc_scb_spi_context_t. * -* The SPI API are the same for the master and slave mode operation and -* are divided into two categories: \ref group_scb_spi_low_level_functions -* and \ref group_scb_spi_high_level_functions. Do not mix high-level and -* low-level API because a low-level API can adversely affect the operation -* of a higher level API. +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_CFG * -* The \ref group_scb_spi_low_level_functions API's functions allow -* interacting directly with the hardware and do not use interrupts. -* These functions do not require context for operation, thus NULL can be +* \subsection group_scb_spi_pins Assign and Configure Pins +* Only dedicated SCB pins can be used for SPI operation. The HSIOM +* register must be configured to connect block to the pins. Also the SPI output +* pins must be configured in Strong Drive mode and SPI input pins in +* Digital High-Z: +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_CFG_PINS +* +* \note +* The SCB stops driving pins when it is disabled or enters low power mode (except +* Alternate Active or Sleep). To keep the pins' states, they should be reconfigured or +* be frozen. +* +* \subsection group_scb_spi_clock Assign Clock Divider +* The clock source must be connected to the SCB block to oversample input and +* output signals. You must use one of the 8-bit or 16-bit dividers (the +* source clock of this divider must be Clk_Peri). Use the +* \ref group_sysclk driver API to do that. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_CFG_ASSIGN_CLOCK +* +* \subsection group_scb_spi_data_rate Configure Data Rate +* To get the SPI slave to operate with the desired data rate, the source clock must be +* fast enough to provide sufficient oversampling. Therefore, the clock divider +* must be configured to provide desired clock frequency. Use the +* \ref group_sysclk driver API to do that. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_CFG_DATA_RATE_SLAVE +* +* To get the SPI master to operate with the desired data rate, the source clock frequency +* and the SCLK (SPI clock) period must be configured. Use the +* \ref group_sysclk driver API to configure source clock frequency. Set the +* oversample parameter in configuration structure to define number of SCB +* clocks in one SCLK period. When this value is even, the first and second phases +* of the SCLK period are the same. Otherwise, the first phase is one SCB clock +* cycle longer than the second phase. The level of the first phase of the clock +* period depends on CPOL settings: 0 - low level and 1 - high level. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_CFG_DATA_RATE_MASTER +* +* Refer to the technical reference manual (TRM) section SPI sub-section +* Oversampling and Bit Rate to get information about how to configure SPI to run with +* desired data rate. +* +* \subsection group_scb_spi_intr Configure Interrupt +* The interrupt is optional for the SPI operation. To configure the interrupt, +* the \ref Cy_SCB_SPI_Interrupt function must be called in the interrupt +* handler for the selected SCB instance. Also, this interrupt must be enabled +* in the NVIC. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_INTR_A +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_INTR_B +* +* \subsection group_scb_spi_enable Enable SPI +* Finally, enable the SPI operation calling \ref Cy_SCB_SPI_Enable. +* For the slave, this means that SPI device starts respond to the transfers. +* For the master, it is ready to execute transfers. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_ENABLE +* +* \section group_scb_spi_use_cases Common Use Cases +* The SPI API is the same for the master and slave mode operation and +* is divided into two categories: \ref group_scb_spi_low_level_functions +* and \ref group_scb_spi_high_level_functions. \n +* Do not mix High-Level and Low-Level API because a Low-Level +* API can adversely affect the operation of a High-Level API. +* +* \subsection group_scb_spi_ll Low-Level API +* The \ref group_scb_spi_low_level_functions API allows +* interacting directly with the hardware and do not use interrupt. +* These functions do not require context for operation. Thus, NULL can be * passed in \ref Cy_SCB_SPI_Init and \ref Cy_SCB_SPI_Disable instead of * a pointer to the context structure. * @@ -66,37 +136,99 @@ * * * The statuses can be polled using: \ref Cy_SCB_SPI_GetRxFifoStatus, * \ref Cy_SCB_SPI_GetTxFifoStatus and \ref Cy_SCB_SPI_GetSlaveMasterStatus. -* The statuses are W1C (Write 1 to Clear) and after a status is set, -* it must be cleared. Note that there are statuses evaluated as level. These -* statuses remain set when an event is true. Therefore, after the clear -* operation, the status is cleared but then it is restored (if event is still +* The statuses are W1C (Write 1 to Clear) and after a status +* is set, it must be cleared. Note that there are statuses evaluated as level. +* These statuses remain set until an event is true. Therefore, after the clear +* operation, the status is cleared but then it is restored (if the event is still * true). * For example: the TX FIFO empty interrupt source can be cleared when the * TX FIFO is not empty. Put at least two data elements (one goes to the -* shifter and next to FIFO) before clearing this status. +* shifter and next to FIFO) before clearing this status. \n +* Also, following functions can be used for polling as well +* \ref Cy_SCB_SPI_IsBusBusy, \ref Cy_SCB_SPI_IsTxComplete, +* \ref Cy_SCB_SPI_GetNumInRxFifo and \ref Cy_SCB_SPI_GetNumInTxFifo. * +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_TRANFER_DATA_LL +* +* \subsection group_scb_spi_hl High-Level API * The \ref group_scb_spi_high_level_functions API uses an interrupt to execute * a transfer. Call \ref Cy_SCB_SPI_Transfer to start communication: for the -* master mode a transfer to the slave is started while for the slave mode +* master mode, a transfer to the slave starts but for the slave mode, * the Read and Write buffers are prepared for the following communication * with the master. * After a transfer is started, the \ref Cy_SCB_SPI_Interrupt handles the -* transfer until its completion. Therefore it must be called inside the -* user interrupt handler to make the high-level API work. To monitor the status +* transfer until its completion. Therefore, it must be called inside the +* user interrupt handler to make the High-Level API work. To monitor the status * of the transfer operation, use \ref Cy_SCB_SPI_GetTransferStatus. -* Alternately, use \ref Cy_SCB_SPI_RegisterCallback to register a callback +* Alternatively, use \ref Cy_SCB_SPI_RegisterCallback to register a callback * function to be notified about \ref group_scb_spi_macros_callback_events. * -* The SPI driver provides the callback functions to facilitate the low-power -* mode transition. The callback \ref Cy_SCB_SPI_DeepSleepCallback can be called +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\spi_snippets.c SPI_TRANFER_DATA +* +* \section group_scb_spi_dma_trig DMA Trigger +* The SCB provides TX and RX output trigger signals that can be routed to the +* DMA controller inputs. These signals are assigned based on the data availability +* in the TX and RX FIFOs appropriately. +* +* * The RX trigger signal remains active until the number of data +* elements in the RX FIFO is greater than the value of RX FIFO level. Use +* function \ref Cy_SCB_SetRxFifoLevel or set configuration structure +* rxFifoTriggerLevel parameter to configure RX FIFO level value. \n +* For example, the RX FIFO has 8 data elements and the RX FIFO level is 0. +* The RX trigger signal remains active until DMA does not read all data from +* the RX FIFO. +* +* * The TX trigger signal remains active until the number of data elements +* in the TX FIFO is less than the value of TX FIFO level. Use function +* \ref Cy_SCB_SetTxFifoLevel or set configuration structure txFifoTriggerLevel +* parameter to configure TX FIFO level value. \n +* For example, the TX FIFO has 0 data elements (empty) and the TX FIFO level +* is 7. The TX trigger signal remains active until DMA does not load TX FIFO +* with 7 data elements (note that after the first TX load operation, the data +* element goes to the shift register and TX FIFO remains empty). +* +* To route SCB TX or RX trigger signals to the DMA controller, use \ref group_trigmux +* driver API. +* +* \note +* To properly handle DMA level request signal activation and de-activation from the SCB +* peripheral block the DMA Descriptor typically must be configured to re-trigger +* after 16 Clk_Slow cycles. +* +* \section group_scb_spi_lp Low Power Support +* The SPI driver provides the callback functions to handle power mode transition. +* The callback \ref Cy_SCB_SPI_DeepSleepCallback must be called * during execution of \ref Cy_SysPm_DeepSleep; \ref Cy_SCB_SPI_HibernateCallback -* can be called during execution of \ref Cy_SysPm_Hibernate. To trigger the +* must be called during execution of \ref Cy_SysPm_Hibernate. To trigger the * callback execution, the callback must be registered before calling the -* mode transition function. Refer to SysPm driver for more information about -* low-power mode transitions. +* power mode transition function. Refer to \ref group_syspm driver for more +* information about power mode transitions and callback registration. +* +* The SPI master is disabled during Deep Sleep and Hibernate and stops driving +* the output pins. The state of the SPI master output pins SCLK, SS, and MOSI is +* High-Z, which can cause unexpected behavior of the SPI Slave due to possible +* glitches on these lines. These pins must be set to the inactive state before +* entering Deep Sleep or Hibernate mode. To do that, configure the SPI master +* pins output to drive the inactive state and High-Speed Input Output +* Multiplexer (HSIOM) to control output by GPIO (use \ref group_gpio +* driver API). The pins configuration must be restored after exiting Deep Sleep +* mode to return the SPI master control of the pins (after exiting Hibernate +* mode, the system init code does the same). +* Note that the SPI master must be enabled to drive the pins during +* configuration change not to cause glitches on the lines. Copy either or +* both \ref Cy_SCB_SPI_DeepSleepCallback and \ref Cy_SCB_SPI_HibernateCallback +* as appropriate, and make the changes described above inside the function. +* Alternately, external pull-up or pull-down resistors can be connected +* to the appropriate SPI lines to keep them inactive during Deep-Sleep or +* Hibernate. +* +* \note +* Only applicable for rev-08 of the CY8CKIT-062-BLE. +* For proper operation, when the SPI slave is configured to be a wakeup +* source from Deep Sleep mode, the \ref Cy_SCB_SPI_DeepSleepCallback must be +* copied and modified. Refer to the function description to get the details. * * \section group_scb_spi_more_information More Information -* * For more information on the SCB peripheral, refer to the technical reference * manual (TRM). * @@ -114,7 +246,7 @@ * * * * -* +* * -* -* +* +* * *
VersionChangesReason for Change
2.0 2.10Fixed the ReStart condition generation sequence for a write +* transaction in the \ref Cy_SCB_I2C_MasterWrite function.The driver can notify about a zero length write transaction completion +* before the address byte is sent if the \ref Cy_SCB_I2C_MasterWrite +* function execution was interrupted between setting the restart +* generation command and writing the address byte into the TX FIFO.
Added the slave- and master-specific interrupt functions: +* \ref Cy_SCB_I2C_SlaveInterrupt and \ref Cy_SCB_I2C_MasterInterrupt. +* Improved the interrupt configuration options for the I2C slave and +* master mode configurations.
Updated the Start condition generation sequence in the \ref +* Cy_SCB_I2C_MasterWrite and \ref Cy_SCB_I2C_MasterRead.
Updated the ReStart condition generation sequence for a write +* transaction in the \ref Cy_SCB_I2C_MasterSendReStart function.
2.0Fixed the \ref Cy_SCB_I2C_MasterSendReStart function to properly +* generate the ReStart condition when the previous transaction was +* a write.The master interpreted the address byte written into the TX FIFO as a +* data byte and continued a write transaction. The ReStart condition was +* generated after the master completed transferring the data byte. +* The SCL line was stretched by the master waiting for the address byte +* to be written into the TX FIFO after the ReStart condition generation. +* The following timeout detection released the bus from the master +* control.
Fixed the slave operation after the address byte was NACKed by the +* firmware.The observed slave operation failure depends on whether Level 2 assert +* is enabled or not. Enabled: the device stuck in the fault handler due +* to the assert assignment in the \ref Cy_SCB_I2C_Interrupt. Disabled: +* the slave sets the transaction completion status and notifies on the +* transaction completion event after the address was NACKed. The failure +* is observed only when the slave is configured to accept an address in +* the RX FIFO.
Added parameters validation for public API.
A cast should not be performed between a pointer to object type and * a different pointer to object type. -* * The pointer to the buffer memory is void to allow handling different +* * The pointer to the buffer memory is void to allow handling * different data types: uint8_t (4-8 bits) or uint16_t (9-16 bits). * The cast operation is safe because the configuration is verified * before operation is performed. @@ -162,12 +294,21 @@ * * * -* +* +* +* +* +* +* +* +* +* +* * * * * -* * * @@ -385,7 +526,7 @@ typedef struct cy_stc_scb_spi_config * When set, the slave will wake the device when the slave select line * becomes active. * Note that not all SCBs support this mode. Consult the device - * datasheet to determine which SCBs support wake from deep sleep. + * datasheet to determine which SCBs support wake from Deep Sleep. */ bool enableWakeFromSleep; @@ -427,10 +568,10 @@ typedef struct cy_stc_scb_spi_config }cy_stc_scb_spi_config_t; /** SPI context structure. -* All fields for the context structure are internal. Firmware never reads or -* writes these values. Firmware allocates the structure and provides the -* address of the structure to the driver in function calls. Firmware must -* ensure that the defined instance of this structure remains in scope while +* All fields for the context structure are internal. Firmware never reads or +* writes these values. Firmware allocates the structure and provides the +* address of the structure to the driver in function calls. Firmware must +* ensure that the defined instance of this structure remains in scope * while the drive is in use. */ typedef struct cy_stc_scb_spi_context @@ -778,11 +919,11 @@ __STATIC_INLINE void Cy_SCB_SPI_Enable(CySCB_Type *base) * The pointer to the SPI SCB instance. * * \return -* True - the bus is busy, false - the bus is idle. +* True - the bus is busy; false - the bus is idle. * * \note * * The SPI master does not assign the slave select line immediately after -* the 1st data element is written into the TX FIFO. It takes up to 2 SCLK +* the first data element is written into the TX FIFO. It takes up to two SCLK * clocks to assign the slave select line. Before this happens, the bus * is considered idle. * * If the SPI master is configured to separate a data elements transfer, @@ -1034,7 +1175,7 @@ __STATIC_INLINE uint32_t Cy_SCB_SPI_GetNumInTxFifo(CySCB_Type const *base) * Function Name: Cy_SCB_SPI_IsTxComplete ****************************************************************************//** * -* Checks if the TX FIFO and Shifter are empty and there is no more data to send +* Checks whether the TX FIFO and Shifter are empty and there is no more data to send * * \param base * Pointer to the SPI SCB instance. @@ -1060,8 +1201,8 @@ __STATIC_INLINE bool Cy_SCB_SPI_IsTxComplete(CySCB_Type const *base) * * \sideeffect * The TX FIFO clear operation also clears the shift register, so that -* the shifter could be cleared in the middle of a data element transfer, -* corrupting it. The data element corruption means that all bits which has +* the shifter can be cleared in the middle of a data element transfer, +* corrupting it. The data element corruption means that all bits that have * not been transmitted are transmitted as 1s on the bus. * *******************************************************************************/ @@ -1139,7 +1280,7 @@ __STATIC_INLINE void Cy_SCB_SPI_ClearSlaveMasterStatus(CySCB_Type *base, uint32_ ****************************************************************************//** * * Reads a single data element from the SPI RX FIFO. -* This function does not check if the RX FIFO has data before reading it. +* This function does not check whether the RX FIFO has data before reading it. * If the RX FIFO is empty, the function returns \ref CY_SCB_SPI_RX_NO_DATA. * * \param base @@ -1175,7 +1316,7 @@ __STATIC_INLINE uint32_t Cy_SCB_SPI_Read(CySCB_Type const *base) * * \param buffer * The pointer to the location to place data read from the RX FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * RX data width. * * \param size @@ -1336,7 +1477,7 @@ __STATIC_INLINE void Cy_SCB_SPI_WriteArrayBlocking(CySCB_Type *base, void *buffe * \param context * The pointer to the context structure \ref cy_stc_scb_spi_context_t allocated * by the user. The structure is used during the SPI operation for internal -* configuration and data keeping. The user should not modify anything +* configuration and data retention. The user should not modify anything * in this structure. * * \note diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_uart.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_uart.c similarity index 93% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_uart.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_uart.c index 9c406983fe..374e2037e3 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_uart.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_uart.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_uart.c -* \version 2.0 +* \version 2.10 * * Provides UART API implementation of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -39,7 +39,7 @@ static void HandleDataTransmit(CySCB_Type *base, cy_stc_scb_uart_context_t *cont * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * If only UART functions which do not require context will be used pass NULL * as pointer to context. @@ -53,7 +53,7 @@ static void HandleDataTransmit(CySCB_Type *base, cy_stc_scb_uart_context_t *cont *******************************************************************************/ cy_en_scb_uart_status_t Cy_SCB_UART_Init(CySCB_Type *base, cy_stc_scb_uart_config_t const *config, cy_stc_scb_uart_context_t *context) { - if ((NULL == base) && (NULL == config)) + if ((NULL == base) || (NULL == config)) { return CY_SCB_UART_BAD_PARAM; } @@ -178,7 +178,7 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Init(CySCB_Type *base, cy_stc_scb_uart_confi * Function Name: Cy_SCB_UART_DeInit ****************************************************************************//** * -* De-initializes the SCB block, returns the register values to default. +* De-initializes the SCB block. Returns the register values to default. * * \param base * The pointer to the UART SCB instance. @@ -232,9 +232,9 @@ void Cy_SCB_UART_DeInit(CySCB_Type *base) * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. -* If only UART functions which do not require context will be used pass NULL +* If only UART functions that do not require context will be used to pass NULL * as pointer to context. * * \note @@ -265,14 +265,14 @@ void Cy_SCB_UART_Disable(CySCB_Type *base, cy_stc_scb_uart_context_t *context) ****************************************************************************//** * * This function handles the transition of the SCB UART into and out of -* Deep-Sleep mode. It prevents the device from entering Deep-Sleep mode if -* the UART is transmitting data or has any data in the RX FIFO. If the UART -* is ready to enter Deep-Sleep mode, it is disabled. The UART is enabled -* when the device failed to enter Deep-Sleep mode or it is awaken from -* Deep-Sleep mode. During the UART is disabled, it stops driving the outputs +* Deep Sleep mode. It prevents the device from entering Deep Sleep +* mode if the UART is transmitting data or has any data in the RX FIFO. If the +* UART is ready to enter Deep Sleep mode, it is disabled. The UART is enabled +* when the device fails to enter Deep Sleep mode or it is awakened from +* Deep Sleep mode. While the UART is disabled, it stops driving the outputs * and ignores the inputs. Any incoming data is ignored. * -* This function can be called during execution of \ref Cy_SysPm_DeepSleep, +* This function must be called during execution of \ref Cy_SysPm_DeepSleep, * to do it, register this function as a callback before calling * \ref Cy_SysPm_DeepSleep : specify \ref CY_SYSPM_DEEPSLEEP as the callback * type and call \ref Cy_SysPm_RegisterCallback. @@ -296,7 +296,7 @@ cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_ { case CY_SYSPM_CHECK_READY: { - /* Check if the High-level API is not busy executing the transmit + /* Check whether the High-level API is not busy executing the transmit * or receive operation. */ if ((0UL == (CY_SCB_UART_TRANSMIT_ACTIVE & Cy_SCB_UART_GetTransmitStatus(locBase, locContext))) && @@ -304,7 +304,7 @@ cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_ { /* If all data elements are transmitted from the TX FIFO and * shifter and the RX FIFO is empty: the UART is ready to enter - * Deep-Sleep mode. + * Deep Sleep mode. */ if (Cy_SCB_UART_IsTxComplete(locBase)) { @@ -314,7 +314,7 @@ cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_ * lines and the receiver stops receiving data until * the UART is enabled. * This happens when the device failed to enter Deep - * Sleep or it is awaken from Deep-Sleep mode. + * Sleep or it is awaken from Deep Sleep mode. */ Cy_SCB_UART_Disable(locBase, locContext); @@ -327,7 +327,7 @@ cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_ case CY_SYSPM_CHECK_FAIL: { - /* The other driver is not ready for Deep-Sleep mode. Restore the + /* The other driver is not ready for Deep Sleep mode. Restore the * Active mode configuration. */ @@ -340,7 +340,7 @@ cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_ case CY_SYSPM_BEFORE_TRANSITION: /* Do noting: the UART is not capable of waking up from - * Deep-Sleep mode. + * Deep Sleep mode. */ break; @@ -365,15 +365,15 @@ cy_en_syspm_status_t Cy_SCB_UART_DeepSleepCallback(cy_stc_syspm_callback_params_ * Function Name: Cy_SCB_UART_HibernateCallback ****************************************************************************//** * -* This function handles the transition of the SCB UART into Hibernate mode. +* This function handles the transition of the SCB UART into Hibernate mode. * It prevents the device from entering Hibernate mode if the UART is * transmitting data or has any data in the RX FIFO. If the UART is ready -* to enter Hibernate mode, it is disabled. If the device failed to enter -* Hibernate mode, the UART is enabled. During the UART is disabled, it stops +* to enter Hibernate mode, it is disabled. If the device fails to enter +* Hibernate mode, the UART is enabled. While the UART is disabled, it stops * driving the outputs and ignores the inputs. Any incoming data is ignored. * -* This function can be called during execution of \ref Cy_SysPm_Hibernate, -* to do it, register this function as a callback before calling +* This function must be called during execution of \ref Cy_SysPm_Hibernate. +* To do it, register this function as a callback before calling * \ref Cy_SysPm_Hibernate : specify \ref CY_SYSPM_HIBERNATE as the callback type * and call \ref Cy_SysPm_RegisterCallback. * @@ -412,7 +412,7 @@ cy_en_syspm_status_t Cy_SCB_UART_HibernateCallback(cy_stc_syspm_callback_params_ * * \param buffer * Pointer to the user defined ring buffer. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -423,7 +423,7 @@ cy_en_syspm_status_t Cy_SCB_UART_HibernateCallback(cy_stc_syspm_callback_params_ * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note @@ -460,7 +460,7 @@ void Cy_SCB_UART_StartRingBuffer(CySCB_Type *base, void *buffer, uint32_t size, * Function Name: Cy_SCB_UART_StopRingBuffer ****************************************************************************//** * -* Stops receiving data into the ring buffer, and clears the ring buffer. +* Stops receiving data into the ring buffer and clears the ring buffer. * * \param base * The pointer to the UART SCB instance. @@ -468,7 +468,7 @@ void Cy_SCB_UART_StartRingBuffer(CySCB_Type *base, void *buffer, uint32_t size, * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -494,7 +494,7 @@ void Cy_SCB_UART_StopRingBuffer(CySCB_Type *base, cy_stc_scb_uart_context_t *con * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -538,7 +538,7 @@ uint32_t Cy_SCB_UART_GetNumInRingBuffer(CySCB_Type const *base, cy_stc_scb_uart_ * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -573,7 +573,7 @@ void Cy_SCB_UART_ClearRingBuffer(CySCB_Type const *base, cy_stc_scb_uart_context * * \param buffer * Pointer to buffer to store received data. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -582,7 +582,7 @@ void Cy_SCB_UART_ClearRingBuffer(CySCB_Type const *base, cy_stc_scb_uart_context * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -603,7 +603,7 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Receive(CySCB_Type *base, void *buffer, uint cy_en_scb_uart_status_t retStatus = CY_SCB_UART_RECEIVE_BUSY; - /* Check if there are no active transfer requests */ + /* check whether there are no active transfer requests */ if (0UL == (context->rxStatus & CY_SCB_UART_RECEIVE_ACTIVE)) { uint8_t *tmpBuf = (uint8_t *) buffer; @@ -658,7 +658,7 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Receive(CySCB_Type *base, void *buffer, uint size -= numToCopy; context->rxBufIdx = numToCopy; - /* Check if all requested data has been read from the ring buffer */ + /* Check whether all requested data has been read from the ring buffer */ if (0UL == size) { /* Enable the RX-error interrupt sources to update the error status */ @@ -726,7 +726,7 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Receive(CySCB_Type *base, void *buffer, uint * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \note @@ -734,7 +734,7 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Receive(CySCB_Type *base, void *buffer, uint * operation. * * If after the abort of the receive operation the transmitter continues * sending data, it gets into the RX FIFO. To drop this data, the RX FIFO -* and ring buffer (if enabled) have to be cleared when the transmitter +* and ring buffer (if enabled) must be cleared when the transmitter * stops sending data. Otherwise, received data will be kept and copied * to the buffer when \ref Cy_SCB_UART_Receive is called. * @@ -766,7 +766,7 @@ void Cy_SCB_UART_AbortReceive(CySCB_Type *base, cy_stc_scb_uart_context_t *conte * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -795,7 +795,7 @@ uint32_t Cy_SCB_UART_GetNumReceived(CySCB_Type const *base, cy_stc_scb_uart_cont * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -831,7 +831,7 @@ uint32_t Cy_SCB_UART_GetReceiveStatus(CySCB_Type const *base, cy_stc_scb_uart_co * * \param buffer * Pointer to user data to place in transmit buffer. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -840,14 +840,14 @@ uint32_t Cy_SCB_UART_GetReceiveStatus(CySCB_Type const *base, cy_stc_scb_uart_co * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return * \ref cy_en_scb_uart_status_t * * \note -* * The buffer must not be modified and stay allocated until its content is +* * The buffer must not be modified and must stay allocated until its content is * copied into the TX FIFO. * * This function overrides the TX FIFO interrupt sources and changes the * TX FIFO level. @@ -861,7 +861,7 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Transmit(CySCB_Type *base, void *buffer, uin cy_en_scb_uart_status_t retStatus = CY_SCB_UART_TRANSMIT_BUSY; - /* Check if there are no active transfer requests */ + /* Check whether there are no active transfer requests */ if (0UL == (CY_SCB_UART_TRANSMIT_ACTIVE & context->txStatus)) { /* Set up context */ @@ -906,13 +906,13 @@ cy_en_scb_uart_status_t Cy_SCB_UART_Transmit(CySCB_Type *base, void *buffer, uin * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \sideeffect * The transmit FIFO clear operation also clears the shift register, so that -* the shifter could be cleared in the middle of a data element transfer, -* corrupting it. The data element corruption means that all bits which has +* the shifter can be cleared in the middle of a data element transfer, +* corrupting it. The data element corruption means that all bits that have * not been transmitted are transmitted as "ones" on the bus. * *******************************************************************************/ @@ -942,7 +942,7 @@ void Cy_SCB_UART_AbortTransmit(CySCB_Type *base, cy_stc_scb_uart_context_t *cont * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -971,7 +971,7 @@ uint32_t Cy_SCB_UART_GetNumLeftToTransmit(CySCB_Type const *base, cy_stc_scb_uar * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * * \return @@ -1006,8 +1006,8 @@ uint32_t Cy_SCB_UART_GetTransmitStatus(CySCB_Type const *base, cy_stc_scb_uart_c * Width of break condition. Valid range is the TX data width (4 to 16 bits) * * \note -* Before sending break all UART TX interrurpt sources are disabled. The state -* of UART TX interrurpt sources is restored before function retuns. +* Before sending break all UART TX interrupt sources are disabled. The state +* of UART TX interrupt sources is restored before function returns. * * \sideeffect * If this function is called while there is data in the TX FIFO or shifter that @@ -1021,7 +1021,7 @@ void Cy_SCB_UART_SendBreakBlocking(CySCB_Type *base, uint32_t breakWidth) CY_ASSERT_L2(CY_SCB_UART_IS_TX_BREAK_WIDTH_VALID(breakWidth)); - /* Disable all UART TX interurpt sources and clear UART TX Done history */ + /* Disable all UART TX interrupt sources and clear UART TX Done history */ txIntrReg = Cy_SCB_GetTxInterruptMask(base); Cy_SCB_SetTxInterruptMask(base, 0UL); Cy_SCB_ClearTxInterrupt(base, CY_SCB_TX_INTR_UART_DONE); @@ -1064,7 +1064,7 @@ void Cy_SCB_UART_SendBreakBlocking(CySCB_Type *base, uint32_t breakWidth) * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1171,7 +1171,7 @@ void Cy_SCB_UART_Interrupt(CySCB_Type *base, cy_stc_scb_uart_context_t *context) * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1239,7 +1239,7 @@ static void HandleDataReceive(CySCB_Type *base, cy_stc_scb_uart_context_t *conte * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ @@ -1323,7 +1323,7 @@ static void HandleRingBuffer(CySCB_Type *base, cy_stc_scb_uart_context_t *contex * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user must not modify anything +* configuration and data retention. The user must not modify anything * in this structure. * *******************************************************************************/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_uart.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_uart.h similarity index 83% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_uart.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_uart.h index b7dccecf37..d8ff3e5da8 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/scb/cy_scb_uart.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/scb/cy_scb_uart.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_scb_uart.h -* \version 2.0 +* \version 2.10 * * Provides UART API declarations of the SCB driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -34,33 +34,90 @@ * the line to "0". * * \section group_scb_uart_configuration Configuration Considerations +* The UART driver configuration can be divided to number of sequential +* steps listed below: +* * \ref group_scb_uart_config +* * \ref group_scb_uart_pins +* * \ref group_scb_uart_clock +* * \ref group_scb_uart_data_rate +* * \ref group_scb_uart_intr +* * \ref group_scb_uart_enable * -* To set up a UART, provide configuration parameters in the +* \note +* UART driver is built on top of the SCB hardware block. The SCB5 instance is +* used as an example for all code snippets. Modify the code to match your +* design. +* +* \subsection group_scb_uart_config Configure UART +* To set up the UART slave driver, provide the configuration parameters in the * \ref cy_stc_scb_uart_config_t structure. For example: provide uartMode, * oversample, dataWidth, enableMsbFirst, parity, and stopBits. The other * parameters are optional for operation. To initialize the driver, -* call the \ref Cy_SCB_UART_Init function providing filled -* \ref cy_stc_scb_uart_config_t structure and allocated -* \ref cy_stc_scb_uart_context_t. To get the UART operate with the desired -* baud rate, the SCB clock and oversample must be configured. Use the SysClk -* driver API to configure the SCB clock frequency and initialize the oversample -* parameter in the \ref cy_stc_scb_uart_config_t structure to set the number -* of the SCB clocks within one UART bit-time. Refer to the technical reference -* manual (TRM) to get more information on how to configure the UART to operate -* with the desired baud rate. Call \ref Cy_SCB_UART_Enable to start the UART -* operation after configuration is completed. +* call \ref Cy_SCB_UART_Init function providing a pointer to the filled +* \ref cy_stc_scb_uart_config_t structure and allocated \ref cy_stc_scb_uart_context_t. * -* The UART API is divided into two categories: -* \ref group_scb_uart_low_level_functions and -* \ref group_scb_uart_high_level_functions. Do not mix high-level and -* low-level API because a low-level API can adversely affect the operation -* of a higher level API. +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_CFG * -* The \ref group_scb_uart_low_level_functions API's functions allow interacting -* directly with the hardware and do not use interrupts. These functions do -* not require context for operation, thus NULL can be passed in -* \ref Cy_SCB_UART_Init and \ref Cy_SCB_UART_Disable instead of a pointer to -* the context structure. +* \subsection group_scb_uart_pins Assign and Configure Pins +* Only dedicated SCB pins can be used for UART operation. The HSIOM +* register must be configured to connect the block to the pins. Also the UART output +* pins must be configured in Strong Drive mode and UART input pins in +* Digital High-Z: +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_CFG_PINS +* +* \note +* The SCB stops driving pins when it is disabled or enters low power mode (except +* Alternate Active or Sleep). To keep the pins' states, they should be reconfigured or +* be frozen. +* +* \subsection group_scb_uart_clock Assign Clock Divider +* The clock source must be connected to the SCB block to oversample input and +* output signals. You must use one of the 8-bit or 16-bit dividers (the +* source clock of this divider must be Clk_Peri). Use the \ref group_sysclk +* driver API to do that. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_CFG_ASSIGN_CLOCK +* +* \subsection group_scb_uart_data_rate Configure Baud Rate +* To get the UART to operate with the desired baud rate, the source clock frequency +* and the oversample must be configured. Use the \ref group_sysclk driver API +* to configure source clock frequency. Set the oversample parameter +* in configuration structure to define the number of the SCB clocks +* within one UART bit-time. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_CFG_DATA_RATE +* +* Refer to the technical reference manual (TRM) section UART sub-section +* Clocking and Oversampling to get information about how to configure the UART to run with +* desired baud rate. +* +* \subsection group_scb_uart_intr Configure Interrupt +* The interrupt is optional for the UART operation. To configure interrupt +* the \ref Cy_SCB_UART_Interrupt function must be called in the interrupt +* handler for the selected SCB instance. Also, this interrupt must be enabled +* in the NVIC. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_INTR_A +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_INTR_B +* +* \subsection group_scb_uart_enable Enable UART +* Finally, enable the UART operation calling \ref Cy_SCB_UART_Enable. +* +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_ENABLE + +* \section group_scb_uart_use_cases Common Use Cases +* The UART API is divided into two categories: \ref group_scb_spi_low_level_functions +* and \ref group_scb_spi_high_level_functions. \n +* Do not mix High-Level and Low-Level API because a Low-Level +* API can adversely affect the operation of a High-Level API. +* +* \subsection group_scb_uart_ll Low-Level API +* The \ref group_scb_uart_low_level_functions API allows +* interacting directly with the hardware and do not use interrupt. +* These functions do not require context for operation, thus NULL can be +* passed in \ref Cy_SCB_UART_Init and \ref Cy_SCB_UART_Disable instead of +* a pointer to the context structure. * * * To write data into the TX FIFO, use one of the provided functions: * \ref Cy_SCB_UART_Put, \ref Cy_SCB_UART_PutArray, @@ -71,43 +128,106 @@ * \ref Cy_SCB_UART_Get, \ref Cy_SCB_UART_GetArray or * \ref Cy_SCB_UART_GetArrayBlocking. * -* * The statuses can be polled by using: \ref Cy_SCB_UART_GetRxFifoStatus and +* * The statuses can be polled using: \ref Cy_SCB_UART_GetRxFifoStatus and * \ref Cy_SCB_UART_GetTxFifoStatus. -* The statuses are W1C (Write 1 to Clear) and after status is set it must -* be cleared. Note that there are statuses that are evaluated as level. These -* statuses remain set when an event is true. Therefore after clear operation -* the status is cleared but then restored (if event is true). -* For example: the TX FIFO empty can be cleared when the TX FIFO is -* NOT empty. You have to put at least (two data elements, one goes to shifter -* and next in FIFO) before clearing this status. +* The statuses are W1C (Write 1 to Clear) and after a status +* is set, it must be cleared. Note that there are statuses evaluated as level. +* These statuses remain set until an event is true. Therefore, after the clear +* operation, the status is cleared but then it is restored (if event is still +* true). +* For example: the TX FIFO empty interrupt source can be cleared when the +* TX FIFO is not empty. Put at least two data elements (one goes to the +* shifter and next to FIFO) before clearing this status. \n +* Also, following functions can be used for polling as well +* \ref Cy_SCB_UART_IsTxComplete, \ref Cy_SCB_UART_GetNumInRxFifo and +* \ref Cy_SCB_UART_GetNumInTxFifo. * +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_TRANSMIT_DATA_LL +* +* \subsection group_scb_uart_hl High-Level API + * The \ref group_scb_uart_high_level_functions API uses an interrupt to * execute transfer. Call \ref Cy_SCB_UART_Transmit to start transmission. * Call \ref Cy_SCB_UART_Receive to start receive operation. After the * operation is started the \ref Cy_SCB_UART_Interrupt handles the data * transfer until its completion. * Therefore \ref Cy_SCB_UART_Interrupt must be called inside the -* user interrupt handler to make the high level API work. To monitor status +* interrupt handler to make the High-Level API work. To monitor status * of transmit operation, use \ref Cy_SCB_UART_GetTransmitStatus and * \ref Cy_SCB_UART_GetReceiveStatus to monitor receive status appropriately. * Alternatively use \ref Cy_SCB_UART_RegisterCallback to register callback * function to be notified about \ref group_scb_uart_macros_callback_events. * +* Receive Operation +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_RECEIVE_DATA_HL +* +* Transmit Operation +* \snippet SCB_CompDatasheet_sut_01_revA.cydsn\uart_snippets.c UART_TRANSMIT_DATA_HL +* * There is also capability to insert a receive ring buffer that operates between * the RX FIFO and the user buffer. The received data is copied into the ring * buffer from the RX FIFO. This process runs in the background after the ring * buffer operation is started by \ref Cy_SCB_UART_StartRingBuffer. * When \ref Cy_SCB_UART_Receive is called, it first reads data from the ring * buffer and then sets up an interrupt to receive more data if the required -* amount has not been read yet. +* amount has not yet been read. * -* The UART driver provides the callback functions to facilitate the low-power -* mode transition. The callback \ref Cy_SCB_UART_DeepSleepCallback can be called +* \section group_scb_uart_dma_trig DMA Trigger +* The SCB provides TX and RX output trigger signals that can be routed to the +* DMA controller inputs. These signals are assigned based on the data availability +* in the TX and RX FIFOs appropriately. +* +* * The RX trigger signal remains active until the number of data +* elements in the RX FIFO is greater than the value of RX FIFO level. Use +* function \ref Cy_SCB_SetRxFifoLevel or set configuration structure +* rxFifoTriggerLevel parameter to configure RX FIFO level value. \n +* For example, the RX FIFO has 8 data elements and the RX FIFO level is 0. +* The RX trigger signal remains active until DMA does not read all data from +* the RX FIFO. +* +* * The TX trigger signal remains active until the number of data elements +* in the TX FIFO is less than the value of TX FIFO level. Use function +* \ref Cy_SCB_SetTxFifoLevel or set configuration structure txFifoTriggerLevel +* parameter to configure TX FIFO level value. \n +* For example, the TX FIFO has 0 data elements (empty) and the TX FIFO level +* is 7. The TX trigger signal remains active until DMA does not load TX FIFO +* with 7 data elements (note that after the first TX load operation, the data +* element goes to the shift register and TX FIFO remains empty). +* +* To route SCB TX or RX trigger signals to DMA controller use \ref group_trigmux +* driver API. +* +* \note +* To properly handle DMA level request signal activation and de-activation from the SCB +* peripheral block the DMA Descriptor typically must be configured to re-trigger +* after 16 Clk_Slow cycles. +* +* \section group_scb_uart_lp Low Power Support +* The UART driver provides the callback functions to handle power mode +* transition. The callback \ref Cy_SCB_UART_DeepSleepCallback must be called * during execution of \ref Cy_SysPm_DeepSleep; \ref Cy_SCB_UART_HibernateCallback -* can be called during execution of \ref Cy_SysPm_Hibernate. To trigger the +* must be called during execution of \ref Cy_SysPm_Hibernate. To trigger the * callback execution, the callback must be registered before calling the -* mode transition function. Refer to SysPm driver for more information about -* low-power mode transitions. +* power mode transition function. Refer to \ref group_syspm driver for more +* information about power mode transitions and callback registration. +* +* The UART is disabled during Deep Sleep and Hibernate and stops driving +* the output pins. The state of the UART output pins TX and RTS is High-Z, +* which can cause unexpected behavior of the UART receiver due to possible +* glitches on these lines. These pins must be set to the inactive state before +* entering Deep Sleep or Hibernate mode. To do that, configure the UART +* pins output to drive the inactive state and High-Speed Input Output +* Multiplexer (HSIOM) to control output by GPIO (use \ref group_gpio +* driver API). The pins configuration must be restored after exiting Deep Sleep +* mode to return the UART control of the pins (after exiting Hibernate mode, +* the system init code does the same). +* Note that the UART must be enabled to drive the pins during configuration +* change not to cause glitches on the lines. Copy either or both +* \ref Cy_SCB_UART_DeepSleepCallback and \ref Cy_SCB_UART_HibernateCallback as +* appropriate, and make the changes described above inside the function. +* Alternately, external pull-up or pull-down resistors can be connected +* to the appropriate UART lines to keep them inactive during Deep-Sleep or +* Hibernate. * * \section group_scb_uart_more_information More Information * @@ -153,7 +273,7 @@ * function. * +* validation fails. * *
VersionChangesReason for Change
2.02.10None.SCB I2C driver updated.
2.0Fixed SPI callback notification when error event occurred.The SPI callback passed incorrect event value if error event occurred.
Added parameters validation for public API.
Replaced variables which have limited range of values with enumerated +* Replaced variables that have limited range of values with enumerated * types.
The functions can return from several points. This is done to improve * code clarity when returning error status code if input parameters -* validation is failed.
* @@ -161,12 +281,17 @@ * * * +* +* +* +* +* * * * * * -* * * @@ -180,8 +305,8 @@ * * * -* * @@ -321,7 +446,7 @@ typedef struct stc_scb_uart_config uint32_t dataWidth; /** - * Enables the hardware to shift out data element MSB first, otherwise, + * Enables the hardware to shift out data element MSB first; otherwise, * LSB first */ bool enableMsbFirst; @@ -337,7 +462,7 @@ typedef struct stc_scb_uart_config /** * Enables a digital 3-tap median filter to be applied to the input - * of the RX FIFO to filter glitches on the line (for IrDA, this parameter + * of the RX FIFO to filter glitches on the line (for IrDA, this parameter * is ignored) * */ @@ -393,7 +518,7 @@ typedef struct stc_scb_uart_config /** * Enables retransmission of the frame placed in the TX FIFO when - * NACK is received in SmartCard mode (for Standard and IrDA , this parameter + * NACK is received in SmartCard mode (for Standard and IrDA , this parameter * is ignored) */ bool smartCardRetryOnNack; @@ -437,7 +562,7 @@ typedef struct stc_scb_uart_config * When there are fewer entries in the TX FIFO then this level * the TX trigger output goes high. This output can be connected * to a DMA channel through a trigger mux. - * Also it controls \ref CY_SCB_UART_TX_TRIGGER interrupt source. + * Also, it controls \ref CY_SCB_UART_TX_TRIGGER interrupt source. */ uint32_t txFifoTriggerLevel; @@ -449,10 +574,10 @@ typedef struct stc_scb_uart_config } cy_stc_scb_uart_config_t; /** UART context structure. -* All fields for the context structure are internal. Firmware never reads or -* writes these values. Firmware allocates the structure and provides the -* address of the structure to the driver in function calls. Firmware must -* ensure that the defined instance of this structure remains in scope while +* All fields for the context structure are internal. Firmware never reads or +* writes these values. Firmware allocates the structure and provides the +* address of the structure to the driver in function calls. Firmware must +* ensure that the defined instance of this structure remains in scope * while the drive is in use. */ typedef struct cy_stc_scb_uart_context @@ -616,7 +741,7 @@ cy_en_syspm_status_t Cy_SCB_UART_HibernateCallback(cy_stc_syspm_callback_params_ #define CY_SCB_UART_RX_NOT_EMPTY (SCB_INTR_RX_NOT_EMPTY_Msk) /** -* The RX FIFO is full, there is no more space for additional data, +* The RX FIFO is full, there is no more space for additional data, and * any additional data will be dropped */ #define CY_SCB_UART_RX_FULL (SCB_INTR_RX_FULL_Msk) @@ -946,7 +1071,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_GetRtsFifoLevel(CySCB_Type const *base) * * \note * The skip start-bit feature is applied whenever the UART is disabled due -* to entrance into DeepSleep or after calling \ref Cy_SCB_UART_Disable. +* to entrance into Deep Sleep or after calling \ref Cy_SCB_UART_Disable. * *******************************************************************************/ __STATIC_INLINE void Cy_SCB_UART_EnableSkipStart(CySCB_Type *base) @@ -1043,7 +1168,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_GetArray(CySCB_Type const *base, void *buff * * \param buffer * The pointer to the location to place the data read from the RX FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -1063,7 +1188,7 @@ __STATIC_INLINE void Cy_SCB_UART_GetArrayBlocking(CySCB_Type const *base, void * ****************************************************************************//** * * Returns the current status of the RX FIFO. -* Clear the active statuses to let the SCB hardware update them. +* Clears the active statuses to let the SCB hardware update them. * * \param base * The pointer to the UART SCB instance. @@ -1095,7 +1220,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_GetRxFifoStatus(CySCB_Type const *base) * * This status is also used for interrupt generation, so clearing it also * clears the interrupt sources. * * Level-sensitive statuses such as \ref CY_SCB_UART_RX_TRIGGER, -* \ref CY_SCB_UART_RX_NOT_EMPTY and \ref CY_SCB_UART_RX_FULL set high again after +* \ref CY_SCB_UART_RX_NOT_EMPTY and \ref CY_SCB_UART_RX_FULL are set high again after * being cleared if the condition remains true. * *******************************************************************************/ @@ -1158,7 +1283,7 @@ __STATIC_INLINE void Cy_SCB_UART_ClearRxFifo(CySCB_Type *base) * * \param data * Data to put in the TX FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \return @@ -1176,7 +1301,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_Put(CySCB_Type *base, uint32_t data) ****************************************************************************//** * * Places an array of data in the UART TX FIFO. -* This function does not block and it returns how many data elements were +* This function does not block. It returns how many data elements were * placed in the TX FIFO. * * \param base @@ -1184,7 +1309,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_Put(CySCB_Type *base, uint32_t data) * * \param buffer * The pointer to data to place in the TX FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * TX data width. * * \param size @@ -1215,7 +1340,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_PutArray(CySCB_Type *base, void *buffer, ui * * \param buffer * The pointer to data to place in the TX FIFO. -* The item size is defined by the data type which depends on the configured +* The item size is defined by the data type, which depends on the configured * data width. * * \param size @@ -1289,7 +1414,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_GetTxFifoStatus(CySCB_Type const *base) * * The status is also used for interrupt generation, so clearing it also * clears the interrupt sources. * * Level-sensitive statuses such as \ref CY_SCB_UART_TX_TRIGGER, -* \ref CY_SCB_UART_TX_EMPTY and \ref CY_SCB_UART_TX_NOT_FULL set high again after +* \ref CY_SCB_UART_TX_EMPTY and \ref CY_SCB_UART_TX_NOT_FULL are set high again after * being cleared if the condition remains true. * *******************************************************************************/ @@ -1328,7 +1453,7 @@ __STATIC_INLINE uint32_t Cy_SCB_UART_GetNumInTxFifo(CySCB_Type const *base) * Function Name: Cy_SCB_UART_IsTxComplete ****************************************************************************//** * -* Checks if the TX FIFO and Shifter are empty and there is no more data to send +* Checks whether the TX FIFO and Shifter are empty and there is no more data to send * * \param base * Pointer to the UART SCB instance. @@ -1387,7 +1512,7 @@ __STATIC_INLINE void Cy_SCB_UART_ClearTxFifo(CySCB_Type *base) * \param context * The pointer to the context structure \ref cy_stc_scb_uart_context_t allocated * by the user. The structure is used during the UART operation for internal -* configuration and data keeping. The user should not modify anything +* configuration and data retention. The user should not modify anything * in this structure. * * \note diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif.c similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif.c index 9318e504ec..0b769ed0f8 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_smif.c -* \version 1.10 +* \version 1.10.1 * * \brief * This file provides the source code for the SMIF driver APIs. @@ -9,7 +9,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif.h index fda496c9f2..fded44b765 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_smif.h -* \version 1.10 +* \version 1.10.1 * * Provides an API declaration of the Cypress SMIF driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -136,6 +136,19 @@ * SMIF Configuration tool generates all configuration structures needed for * memslot level API usage. * +* \subsection group_smif_xip_init SMIF XIP Initialization +* The eXecute In Place (XIP) is a mode of operation where read or write commands +* to the memory device are directed through the SMIF without any use of API +* function calls. In this mode the SMIF block maps the AHB bus-accesses to +* external memory device addresses to make it behave similar to internal memory. +* This allows the CPU to execute code directly from external memory. This mode +* is not limited to code and is suitable also for data read and write accesses. +* \snippet smif/smif_sut_01.cydsn/main_cm4.c SMIF_INIT: XIP +* \note Example of input parameters initialization is in \ref group_smif_init +* section. +* \warning Functions that called from external memory should be declared with +* long call attribute. +* * \section group_smif_more_information More Information * * More information regarding the Serial Memory Interface can be found in the component @@ -179,6 +192,17 @@ *
VersionChangesReason for Change
2.10None.SCB I2C driver updated.
2.0Added parameters validation for public API.
Replaced variables which have limited range of values with enumerated +* Replaced variables that have limited range of values with enumerated * types.
Fixed low power callbacks Cy_SCB_UART_DeepSleepCallback and -* Cy_SCB_UART_HibernateCallback to prevent the device from entering +* Fixed low power callbacks \ref Cy_SCB_UART_DeepSleepCallback and +* \ref Cy_SCB_UART_HibernateCallback to prevent the device from entering * low power mode when RX FIFO is not empty.The callbacks allowed entering device into low power mode when RX FIFO * had data.
* * +* +* +* +* +* +* +* +* +* +* * * * @@ -205,8 +229,9 @@ * * \} * \defgroup group_smif_mem_slot_functions Memory Slot Functions +* \defgroup group_smif_functions_syspm_callback Low Power Callback * \} -* \defgroup group_smif_data_structures Data structures +* \defgroup group_smif_data_structures Data Structures * \{ * \defgroup group_smif_data_structures_memslot SMIF Memory Description Structures * General hierarchy of memory structures are: @@ -404,7 +429,7 @@ typedef enum { /**< Generates a bus error. */ CY_SMIF_BUS_ERROR = 0UL, - /** Stalls the bus with the Wait states. This option will increase the + /** Stalls the bus with the wait states. This option will increase the * interrupt latency. */ CY_SMIF_WAIT_STATES = 1UL @@ -650,8 +675,13 @@ cy_en_smif_status_t Cy_SMIF_CachePrefetchingEnable(SMIF_Type *base, cy_en_smif_c cy_en_smif_status_t Cy_SMIF_CachePrefetchingDisable(SMIF_Type *base, cy_en_smif_cache_en_t cacheType); cy_en_smif_status_t Cy_SMIF_CacheInvalidate(SMIF_Type *base, cy_en_smif_cache_en_t cacheType); +/** \addtogroup group_smif_functions_syspm_callback +* The driver supports SysPm callback for Deep Sleep and Hibernate transition. +* \{ +*/ cy_en_syspm_status_t Cy_SMIF_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams); cy_en_syspm_status_t Cy_SMIF_HibernateCallback(cy_stc_syspm_callback_params_t *callbackParams); +/** \} */ /*************************************** diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif_memslot.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif_memslot.c similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif_memslot.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif_memslot.c index f469fbad59..eba4304c36 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif_memslot.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif_memslot.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_smif_memslot.c -* \version 1.10 +* \version 1.10.1 * * \brief * This file provides the source code for the memory-level APIs of the SMIF driver. @@ -9,7 +9,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif_memslot.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif_memslot.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif_memslot.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif_memslot.h index ce00937c97..7456b84be4 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/smif/cy_smif_memslot.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/smif/cy_smif_memslot.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_smif_memslot.h -* \version 1.10 +* \version 1.10.1 * * \brief * This file provides the constants and parameter values for the memory-level @@ -10,7 +10,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysanalog/cy_sysanalog.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysanalog/cy_sysanalog.c similarity index 86% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysanalog/cy_sysanalog.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysanalog/cy_sysanalog.c index 49746b29c7..fbdfe9c8ec 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysanalog/cy_sysanalog.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysanalog/cy_sysanalog.c @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -24,7 +24,6 @@ const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_Local = /*.iztat */ CY_SYSANALOG_IZTAT_SOURCE_LOCAL, /*.vref */ CY_SYSANALOG_VREF_SOURCE_LOCAL_1_2V, /*.deepSleep */ CY_SYSANALOG_DEEPSLEEP_DISABLE, - /*.enable */ true, }; /* Configure the AREF to use the SRSS Vref and SRSS IZTAT. Can be used with \ref Cy_SysAnalog_Init. */ @@ -34,7 +33,6 @@ const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_SRSS = /*.iztat */ CY_SYSANALOG_IZTAT_SOURCE_SRSS, /*.vref */ CY_SYSANALOG_VREF_SOURCE_SRSS, /*.deepSleep */ CY_SYSANALOG_DEEPSLEEP_DISABLE, - /*.enable */ true, }; /* Configure the AREF to use the external Vref and local IZTAT. Can be used with \ref Cy_SysAnalog_Init. */ @@ -44,21 +42,24 @@ const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_External = /*.iztat */ CY_SYSANALOG_IZTAT_SOURCE_LOCAL, /*.vref */ CY_SYSANALOG_VREF_SOURCE_EXTERNAL, /*.deepSleep */ CY_SYSANALOG_DEEPSLEEP_DISABLE, - /*.enable */ true, }; /******************************************************************************* * Function Name: Cy_SysAnalog_Init ****************************************************************************//** * -* Initialize the AREF configuration register. +* Initialize the AREF block. * * \param config * Pointer to structure containing configuration data. See \ref cy_stc_sysanalog_config_t * -* \return cy_en_sysanalog_status_t -* - CY_SYSANALOG_SUCCESS: initialization complete -* - CY_SYSANALOG_BAD_PARAM: input pointers are null, initialization incomplete +* \return +* - \ref CY_SYSANALOG_SUCCESS : initialization complete +* - \ref CY_SYSANALOG_BAD_PARAM : input pointers are null, initialization incomplete +* +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_INIT * *******************************************************************************/ cy_en_sysanalog_status_t Cy_SysAnalog_Init(const cy_stc_sysanalog_config_t *config) @@ -83,8 +84,7 @@ cy_en_sysanalog_status_t Cy_SysAnalog_Init(const cy_stc_sysanalog_config_t *conf | CY_SYSANALOG_DEFAULT_BIAS_SCALE \ | (uint32_t) config->iztat \ | (uint32_t) config->vref \ - | (uint32_t) config->deepSleep \ - | ((uint32_t) config->enable << PASS_AREF_AREF_CTRL_ENABLED_Pos); + | (uint32_t) config->deepSleep; PASS_AREF->AREF_CTRL = ctrlReg; diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysanalog/cy_sysanalog.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysanalog/cy_sysanalog.h similarity index 90% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysanalog/cy_sysanalog.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysanalog/cy_sysanalog.h index 322b21466c..ddc4fe8338 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysanalog/cy_sysanalog.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysanalog/cy_sysanalog.h @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -19,7 +19,7 @@ * This driver provides an interface for configuring the Analog Reference (AREF) block * and querying the INTR_CAUSE register of the PASS. * -* AREF Block +* The AREF block has the following features: * * - Generates a voltage reference (VREF) from one of three sources: * - Local 1.2 V reference (low noise, optimized for analog performance) @@ -34,6 +34,7 @@ * * The locally generated references are the recommended sources for blocks in the PASS because * they have tighter accuracy, temperature stability, and lower noise than the SRSS references. +* The SRSS references can be used to save power if the low accuracy and higher noise can be tolerated. * * \image html aref_block_diagram.png * \image latex aref_block_diagram.png @@ -68,8 +69,6 @@ * *
VersionChangesReason for Change
1.10.1Added Low Power Callback sectionDocumentation update and clarification
1.10Fix write to external memory from CM0+ core. Add checks of API input parameters. +* Minor documentation updates
1.0Initial version
* -* PASS INTR_CAUSE -* * This driver provides a function to query the INTR_CAUSE register of the PASS. * There are two interrupts in the PASS: * @@ -81,7 +80,7 @@ * * \section group_sysanalog_usage Usage * -* Initialization +* \subsection group_sysanalog_usage_init Initialization * * To configure the AREF, call \ref Cy_SysAnalog_Init and provide a pointer * to the configuration structure, \ref cy_stc_sysanalog_config_t. Three predefined structures @@ -91,13 +90,9 @@ * - \ref Cy_SysAnalog_Fast_SRSS * - \ref Cy_SysAnalog_Fast_External * -* Enable +* After initialization, call \ref Cy_SysAnalog_Enable to enable the hardware. * -* If the \ref cy_stc_sysanalog_config_t.enable field of the configuration structure is set to true, -* the hardware will be enabled after initialization. -* If set to false, a separate call to \ref Cy_SysAnalog_Enable is required to enable the hardware. -* -* Deep Sleep Operation +* \subsection group_sysanalog_usage_dsop Deep Sleep Operation * * The AREF current and voltage references can be enabled to operate in Deep Sleep mode * with \ref Cy_SysAnalog_SetDeepSleepMode. There are four options for Deep Sleep operation: @@ -115,7 +110,8 @@ * * If the CTDAC is configured to use the VREF in Deep Sleep mode, the AREF must be enabled for \ref CY_SYSANALOG_DEEPSLEEP_IPTAT_IZTAT_VREF. * -* Note that the SRSS references are not available to the AREF in Deep Sleep mode. When operating +* \note +* The SRSS references are not available to the AREF in Deep Sleep mode. When operating * in Deep Sleep mode, the local or external references must be selected. * * \section group_sysanalog_more_information More Information @@ -139,7 +135,7 @@ * \defgroup group_sysanalog_macros Macros * \defgroup group_sysanalog_functions Functions * \defgroup group_sysanalog_globals Global Variables -* \defgroup group_sysanalog_data_structures Data structures +* \defgroup group_sysanalog_data_structures Data Structures * \defgroup group_sysanalog_enums Enumerated Types */ @@ -209,19 +205,17 @@ typedef enum CY_SYSANALOG_BAD_PARAM = CY_SYSANALOG_ID | CY_PDL_STATUS_ERROR | 0x01uL /**< Invalid input parameters */ }cy_en_sysanalog_status_t; -/** Aref startup timing modes +/** Aref startup mode from power on reset and from Deep Sleep wakeup * -* The AREF block supports a fast 10 us startup time with a noise trade off. -* This fast startup time is during wakeup from Deep Sleep mode only. -* To achieve the fast startup from Deep Sleep mode, the IPTAT must be enabled in Deep Sleep mode -* (see \ref cy_en_sysanalog_deep_sleep_t). +* To achieve the fast startup time (10 us) from Deep Sleep wakeup, the IPTAT generators must be +* enabled in Deep Sleep mode (see \ref cy_en_sysanalog_deep_sleep_t). * * The fast startup is the recommended mode. */ typedef enum { - CY_SYSANALOG_STARTUP_NORMAL = 0u, /**< Normal startup with nominal noise */ - CY_SYSANALOG_STARTUP_FAST = 1u << PASS_AREF_AREF_CTRL_AREF_MODE_Pos /**< Fast startup from Deep Sleep mode with high noise */ + CY_SYSANALOG_STARTUP_NORMAL = 0u, /**< Normal startup */ + CY_SYSANALOG_STARTUP_FAST = 1u << PASS_AREF_AREF_CTRL_AREF_MODE_Pos /**< Fast startup (10 us) - recommended */ }cy_en_sysanalog_startup_t; /** AREF voltage reference sources @@ -313,7 +307,6 @@ typedef struct cy_en_sysanalog_iztat_source_t iztat; /**< AREF 1uA IZTAT source: Local or SRSS */ cy_en_sysanalog_vref_source_t vref; /**< AREF Vref: Local, SRSS, or external pin */ cy_en_sysanalog_deep_sleep_t deepSleep; /**< AREF Deep Sleep mode */ - bool enable; /**< Enable or disable PASS AREF clock */ }cy_stc_sysanalog_config_t; /** \} group_sysanalog_data_structures */ @@ -329,7 +322,6 @@ typedef struct * Other configuration options are set to: * - .startup = CY_PASS_AREF_MODE_FAST * - .deepSleep = CY_PASS_AREF_DEEPSLEEP_DISABLE -* - .enable = true */ extern const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_Local; @@ -337,7 +329,6 @@ extern const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_Local; * Other configuration options are set to: * - .startup = CY_PASS_AREF_MODE_FAST * - .deepSleep = CY_PASS_AREF_DEEPSLEEP_DISABLE -* - .enable = true */ extern const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_SRSS; @@ -345,7 +336,6 @@ extern const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_SRSS; * Other configuration options are set to: * - .startup = CY_PASS_AREF_MODE_FAST * - .deepSleep = CY_PASS_AREF_DEEPSLEEP_DISABLE -* - .enable = true */ extern const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_External; @@ -378,6 +368,10 @@ __STATIC_INLINE void Cy_SysAnalog_IztatSelect(cy_en_sysanalog_iztat_source_t izt * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_DEINIT +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_DeInit(void) { @@ -400,6 +394,10 @@ __STATIC_INLINE void Cy_SysAnalog_DeInit(void) * \return uint32_t * Interrupt cause register value. * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_GET_INTR_CAUSE +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SysAnalog_GetIntrCause(void) { @@ -417,14 +415,19 @@ __STATIC_INLINE uint32_t Cy_SysAnalog_GetIntrCause(void) * - Enable IPTAT generator and IPTAT outputs for CTB * - Enable all generators and outputs: IPTAT, IZTAT, and VREF * -* Note that the SRSS references are not available to the AREF in Deep Sleep mode. When operating +* \note +* The SRSS references are not available to the AREF in Deep Sleep mode. When operating * in Deep Sleep mode, the local or external references must be selected. * * \param deepSleep -* value from enum \ref cy_en_sysanalog_deep_sleep_t +* Select a value from \ref cy_en_sysanalog_deep_sleep_t * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_SET_DEEPSLEEP_MODE +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_SetDeepSleepMode(cy_en_sysanalog_deep_sleep_t deepSleep) { @@ -440,7 +443,12 @@ __STATIC_INLINE void Cy_SysAnalog_SetDeepSleepMode(cy_en_sysanalog_deep_sleep_t * * Return Deep Sleep mode configuration as set by \ref Cy_SysAnalog_SetDeepSleepMode * -* \return cy_en_sysanalog_deep_sleep_t +* \return +* A value from \ref cy_en_sysanalog_deep_sleep_t +* +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_GET_DEEPSLEEP_MODE * *******************************************************************************/ __STATIC_INLINE cy_en_sysanalog_deep_sleep_t Cy_SysAnalog_GetDeepSleepMode(void) @@ -456,6 +464,10 @@ __STATIC_INLINE cy_en_sysanalog_deep_sleep_t Cy_SysAnalog_GetDeepSleepMode(void) * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_ENABLE +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_Enable(void) { @@ -470,6 +482,10 @@ __STATIC_INLINE void Cy_SysAnalog_Enable(void) * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_DISABLE +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_Disable(void) { @@ -480,16 +496,22 @@ __STATIC_INLINE void Cy_SysAnalog_Disable(void) * Function Name: Cy_SysAnalog_SetArefMode ****************************************************************************//** * -* Set the AREF start up mode from Deep Sleep mode. -* The AREF can start up in a normal or fast mode. If fast start up -* is desired, the AREF must be enabled in Deep Sleep mode with the IPTAT -* generator enabled. See \ref Cy_SysAnalog_SetDeepSleepMode. +* Set the AREF startup mode from power on reset or from Deep Sleep wakeup. +* The AREF can startup in a normal or fast mode. +* +* If fast startup is desired from Deep Sleep wakeup, the IPTAT generators must be enabled during +* Deep Sleep. This is a minimum Deep Sleep mode setting of \ref CY_SYSANALOG_DEEPSLEEP_IPTAT_1 +* (see also \ref Cy_SysAnalog_SetDeepSleepMode). * * \param startup * Value from enum \ref cy_en_sysanalog_startup_t * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_SET_AREF_MODE +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_SetArefMode(cy_en_sysanalog_startup_t startup) { @@ -515,6 +537,10 @@ __STATIC_INLINE void Cy_SysAnalog_SetArefMode(cy_en_sysanalog_startup_t startup) * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_VREF_SELECT +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_VrefSelect(cy_en_sysanalog_vref_source_t vref) { @@ -532,13 +558,17 @@ __STATIC_INLINE void Cy_SysAnalog_VrefSelect(cy_en_sysanalog_vref_source_t vref) * - the SRSS (not available to the AREF in Deep Sleep mode) * * The locally generated reference has higher accuracy, more stability over temperature, -* an lower noise than the SRSS reference. +* and lower noise than the SRSS reference. * * \param iztat * Value from enum \ref cy_en_sysanalog_iztat_source_t * * \return None * +* \funcusage +* +* \snippet sysanalog_sut_01.cydsn/main_cm0p.c SYSANA_SNIPPET_IZTAT_SELECT +* *******************************************************************************/ __STATIC_INLINE void Cy_SysAnalog_IztatSelect(cy_en_sysanalog_iztat_source_t iztat) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysclk/cy_sysclk.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysclk/cy_sysclk.c similarity index 88% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysclk/cy_sysclk.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysclk/cy_sysclk.c index 49d305e95a..e789ea9e30 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysclk/cy_sysclk.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysclk/cy_sysclk.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_sysclk.c -* \version 1.10 +* \version 1.10.1 * * Provides an API implementation of the sysclk driver. * ******************************************************************************** * \copyright -* Copyright 2016, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -36,9 +36,8 @@ extern "C" { * Function Name: Cy_SysClk_EcoConfigure ****************************************************************************//** * -* This function configures the external crystal oscillator (ECO) trim bits based -* on crystal characteristics. This function should be called only when the ECO is -* disabled. +* Configures the external crystal oscillator (ECO) trim bits based on crystal +* characteristics. This function should be called only when the ECO is disabled. * * \param freq Operating frequency of the crystal in Hz. * @@ -54,40 +53,48 @@ extern "C" { * CY_SYSCLK_INVALID_STATE - ECO already enabled * * \note -* The following calculations are implemented, generally in floating point:
-* freqMHz = freq / 1,000,000
-* max amplitude Vpp = 1,000 * sqrt(drivelevel / 2 / esr) / 3.14 / freqMHz / cLoad
-* gm_min mA/V = 5 * 4 * 3.14 * 3.14 * freqMhz^2 * cLoad^2 * 4 * esr / 1,000,000,000
-* Number of amplifier sections = INT(gm_min / 4.5)
+* The following calculations are implemented, generally in floating point: +* +* \verbatim +* freqMHz = freq / 1000000 +* max amplitude Vpp = 1000 * sqrt(drivelevel / 2 / esr) / 3.14 / freqMHz / cLoad +* gm_min mA/V = 5 * 4 * 3.14 * 3.14 * freqMhz^2 * cLoad^2 * 4 * esr / 1000000000 +* Number of amplifier sections = INT(gm_min / 4.5) +* * As a result of the above calculations, max amplitude must be >= 0.5, and the * number of amplifier sections must be <= 3, otherwise this function returns with -* a parameter error.
-* atrim = if max amplitude < 0.5 then error
-* else 2 * the following:
-* max amplitude < 0.6: 0
-* max amplitude < 0.7: 1
-* max amplitude < 0.8: 2
-* max amplitude < 0.9: 3
-* max amplitude < 1.15: 5
-* max amplitude < 1.275: 6
-* max amplitude >= 1.275: 7
-* wdtrim = if max amplitude < 0.5 then error
-* else 2 * the following:
-* max amplitude < 1.2: INT(5 * max amplitude) - 2
-* max amplitude >= 1.2: 3
-* gtrim = if number of amplifier sections > 3 then error
-* else the following:
-* number of amplifier sections > 1: number of amplifier sections
-* number of amplifier sections = 1: 0
-* number of amplifier sections < 1: 1
-* rtrim = if gtrim = error then error
-* else the following:
-* freqMHz > 26.8: 0
-* freqMHz > 23.33: 1
-* freqMHz > 16.5: 2
-* freqMHz <= 16.5: 3
-* ftrim = if atrim = error then error
-* else INT(atrim / 2)
+* a parameter error. +* +* atrim = if (max amplitude < 0.5) then error +* else 2 * the following: +* max amplitude < 0.6: 0 +* max amplitude < 0.7: 1 +* max amplitude < 0.8: 2 +* max amplitude < 0.9: 3 +* max amplitude < 1.15: 5 +* max amplitude < 1.275: 6 +* max amplitude >= 1.275: 7 +* wdtrim = if (max amplitude < 0.5) then error +* else 2 * the following: +* max amplitude < 1.2: INT(5 * max amplitude) - 2 +* max amplitude >= 1.2: 3 +* gtrim = if (number of amplifier sections > 3) then error +* else the following: +* number of amplifier sections > 1: number of amplifier sections +* number of amplifier sections = 1: 0 +* number of amplifier sections < 1: 1 +* rtrim = if (gtrim = error) then error +* else the following: +* freqMHz > 26.8: 0 +* freqMHz > 23.33: 1 +* freqMHz > 16.5: 2 +* freqMHz <= 16.5: 3 +* ftrim = if (atrim = error) then error +* else INT(atrim / 2) +* \endverbatim +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_EcoConfigure * *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_EcoConfigure(uint32_t freq, uint32_t cLoad, uint32_t esr, uint32_t driveLevel) @@ -169,6 +176,9 @@ cy_en_sysclk_status_t Cy_SysClk_EcoConfigure(uint32_t freq, uint32_t cLoad, uint * CY_SYSCLK_TIMEOUT - ECO timed out and did not lock * CY_SYSCLK_INVALID_STATE - ECO already enabled * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_EcoEnable +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_EcoEnable(uint32_t timeoutus) { @@ -218,6 +228,10 @@ cy_en_sysclk_status_t Cy_SysClk_EcoEnable(uint32_t timeoutus) * If calling this function changes an FLL or PLL input frequency, disable the FLL * or PLL before calling this function. After calling this function, call the FLL * or PLL configure function, for example \ref Cy_SysClk_FllConfigure(). +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPathSetSource +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_ClkPathSetSource(uint32_t clkPath, cy_en_clkpath_in_sources_t source) { @@ -251,6 +265,9 @@ cy_en_sysclk_status_t Cy_SysClk_ClkPathSetSource(uint32_t clkPath, cy_en_clkpath * * \return \ref cy_en_clkpath_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPathGetSource +* *******************************************************************************/ cy_en_clkpath_in_sources_t Cy_SysClk_ClkPathGetSource(uint32_t clkPath) { @@ -306,6 +323,10 @@ cy_en_clkpath_in_sources_t Cy_SysClk_ClkPathGetSource(uint32_t clkPath) * \note * Do not call this function when the FLL is enabled. If it is, then this function * returns immediately with an error return value and no register updates. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllConfigure +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_FllConfigure(uint32_t inputFreq, uint32_t outputFreq, cy_en_fll_pll_output_mode_t outputMode) { @@ -357,9 +378,9 @@ cy_en_sysclk_status_t Cy_SysClk_FllConfigure(uint32_t inputFreq, uint32_t output /* 4. Compute the FLL reference divider value. refDiv is a constant if the WCO is the FLL source, otherwise the formula is - refDiv = ROUNDUP((1 / (trimStep[ccoRange] / 2)) * (inputFreq / ccoFreq)) */ - config.refDiv = wcoSource ? 19u : ((uint16_t)ceilf((float32_t)inputFreq / - ((trimSteps[config.ccoRange] / 2.0f) * (float32_t)ccoFreq))); + refDiv = ROUNDUP((inputFreq / outputFreq) * 250) */ + config.refDiv = wcoSource ? 19u : + ((uint16_t)ceilf(((float32_t)inputFreq / (float32_t)outputFreq) * 250.0f)); /* 5. Compute the FLL multiplier value. Formula is fllMult = ccoFreq / (inputFreq / refDiv) */ config.fllMult = CY_SYSCLK_DIV_ROUNDUP(ccoFreq, CY_SYSCLK_DIV_ROUND(inputFreq, config.refDiv)); @@ -445,6 +466,10 @@ cy_en_sysclk_status_t Cy_SysClk_FllConfigure(uint32_t inputFreq, uint32_t output * \note * Do not call this function when the FLL is enabled. If it is, then this function * returns immediately with an error return value and no register updates. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllManualConfigure +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_FllManualConfigure(const cy_stc_fll_manual_config_t *config) { @@ -506,6 +531,9 @@ cy_en_sysclk_status_t Cy_SysClk_FllManualConfigure(const cy_stc_fll_manual_confi * * \param config \ref cy_stc_fll_manual_config_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllGetConfiguration +* *******************************************************************************/ void Cy_SysClk_FllGetConfiguration(cy_stc_fll_manual_config_t *config) { @@ -545,6 +573,10 @@ void Cy_SysClk_FllGetConfiguration(cy_stc_fll_manual_config_t *config) * \note * While waiting for the FLL to lock, the FLL bypass mode is set to \ref CY_SYSCLK_FLLPLL_OUTPUT_INPUT. * After the FLL is locked, the FLL bypass mdoe is then set to \ref CY_SYSCLK_FLLPLL_OUTPUT_OUTPUT. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllEnable +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_FllEnable(uint32_t timeoutus) { @@ -668,6 +700,10 @@ cy_en_sysclk_status_t Cy_SysClk_FllEnable(uint32_t timeoutus) * \note * Do not call this function when the PLL is enabled. If it is, then this function * returns immediately with an error return value and no register updates. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllConfigure +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_PllConfigure(uint32_t clkPath, const cy_stc_pll_config_t *config) { @@ -777,6 +813,10 @@ cy_en_sysclk_status_t Cy_SysClk_PllConfigure(uint32_t clkPath, const cy_stc_pll_ * \note * Do not call this function when the PLL is enabled. If it is, then this function * returns immediately with an error return value and no register updates. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllManualConfigure +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_PllManualConfigure(uint32_t clkPath, const cy_stc_pll_manual_config_t *config) { @@ -838,6 +878,9 @@ cy_en_sysclk_status_t Cy_SysClk_PllManualConfigure(uint32_t clkPath, const cy_st * CY_SYSCLK_SUCCESS - PLL data successfully reported
* CY_SYSCLK_BAD_PARAM - invalid clock path number * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllGetConfiguration +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_PllGetConfiguration(uint32_t clkPath, cy_stc_pll_manual_config_t *config) { @@ -872,6 +915,9 @@ cy_en_sysclk_status_t Cy_SysClk_PllGetConfiguration(uint32_t clkPath, cy_stc_pll * CY_SYSCLK_TIMEOUT - Timeout waiting for PLL lock
* CY_SYSCLK_BAD_PARAM - invalid clock path number * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllEnable +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_PllEnable(uint32_t clkPath, uint32_t timeoutus) { @@ -918,11 +964,13 @@ static bool preventCounting = false; * * Assigns clocks to the clock measurement counters, and starts counting. The counters * let you measure a clock frequency using another clock as a reference. There are two -* counters.
-* One counter (counter1), which is clocked by clock1, is loaded with an initial value -* and counts down to zero.
-* The second counter (counter2), which is clocked by clock2, counts up until the first -* counter reaches zero.
+* counters. +* +* - One counter (counter1), which is clocked by clock1, is loaded with an initial +* value and counts down to zero. +* - The second counter (counter2), which is clocked by clock2, counts up until +* the first counter reaches zero. +* * Either clock1 or clock2 can be a reference clock; the other clock becomes the * measured clock. The reference clock frequency is always known.
* After calling this function, call \ref Cy_SysClk_ClkMeasurementCountersDone() @@ -951,6 +999,9 @@ static bool preventCounting = false; * \note Do not enter a device low power mode (Sleep, Deep Sleep) while doing a measurement; * the measured clock frequency may not be accurate. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_StartClkMeasurementCounters +* *******************************************************************************/ cy_en_sysclk_status_t Cy_SysClk_StartClkMeasurementCounters(cy_en_meas_clks_t clock1, uint32_t count1, cy_en_meas_clks_t clock2) { @@ -1053,20 +1104,25 @@ cy_en_sysclk_status_t Cy_SysClk_StartClkMeasurementCounters(cy_en_meas_clks_t cl * Function Name: Cy_SysClk_ClkMeasurementCountersGetFreq ****************************************************************************//** * -* Calculates the frequency of the indicated measured clock (clock1 or clock2).
-* If clock1 is the measured clock, its frequency is:
-* clock1 frequency = (count1 / count2) * clock2 frequency
-* If clock2 is the measured clock, its frequency is:
-* clock2 frequency = (count2 / count1) * clock1 frequency
+* Calculates the frequency of the indicated measured clock (clock1 or clock2). +* +* - If clock1 is the measured clock, its frequency is:
+* clock1 frequency = (count1 / count2) * clock2 frequency +* - If clock2 is the measured clock, its frequency is:
+* clock2 frequency = (count2 / count1) * clock1 frequency +* * Call this function only after counting is done; see \ref Cy_SysClk_ClkMeasurementCountersDone(). * -* \param measuredClock False (0) if the measured clock is clock1, true (nonzero) +* \param measuredClock False (0) if the measured clock is clock1, true (1) * if the measured clock is clock2. * * \param refClkFreq The reference clock frequency (clock1 or clock2). * * \return The frequency of the measured clock, in Hz. * +* \funcusage +* Refer to the Cy_SysClk_StartClkMeasurementCounters() function usage. +* *******************************************************************************/ uint32_t Cy_SysClk_ClkMeasurementCountersGetFreq(bool measuredClock, uint32_t refClkFreq) { @@ -1111,6 +1167,10 @@ uint32_t Cy_SysClk_ClkMeasurementCountersGetFreq(bool measuredClock, uint32_t re * \return Change in trim value; 0 if done, that is, no change in trim value. * * \note The watchdog timer (WDT) must be unlocked before calling this function. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_IloTrim +* *******************************************************************************/ /** \cond INTERNAL */ /* target frequency */ @@ -1156,6 +1216,9 @@ int32_t Cy_SysClk_IloTrim(uint32_t iloFreq) * * \return Change in trim value; 0 if done, that is, no change in trim value. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PiloTrim +* *******************************************************************************/ /** \cond INTERNAL */ /* target frequency */ @@ -1214,25 +1277,26 @@ int32_t Cy_SysClk_PiloTrim(uint32_t piloFreq) * Function Name: Cy_SysClk_DeepSleepCallback ****************************************************************************//** * -* This is a callback function for System Power Management (SysPm), for entering -* DeepSleep mode. This function does the following tests:
-* FLL and PLL:
-* 1. If the FLL or a PLL have the ECO as a source (see \ref Cy_SysClk_ClkPathGetSource), -* and is enabled, changes the source to IMO.
-* 2. On wakeup, timeout-waits for FLL and PLL to regain their frequency locks, -* if enabled.
-* Frequency measurement: Prevents entry into DeepSleep mode if currently counting; -* see \ref Cy_SysClk_StartClkMeasurementCounters. Does not allow start of counting -* if already indicated that entry into DeepSleep mode is OK.
+* Callback function to be used when entering chip deep-sleep mode. This function is +* applicable for when either the FLL or the PLL is enabled. It performs the following: +* +* 1. Before entering deep-sleep, the clock configuration is saved in SRAM. If the +* FLL/PLL source is the ECO, then the source is updated to the IMO. +* 2. Upon wakeup from deep-sleep, the function restores the configuration and +* waits for the FLL/PLL to regain their frequency locks. +* +* The function prevents entry into DeepSleep mode if the measurement counters +* are currently counting; see \ref Cy_SysClk_StartClkMeasurementCounters. * * This function can be called during execution of \ref Cy_SysPm_DeepSleep. * To do so, register this function as a callback before calling * \ref Cy_SysPm_DeepSleep - specify \ref CY_SYSPM_DEEPSLEEP as the callback * type and call \ref Cy_SysPm_RegisterCallback. * -* \note If the FLL or PLL source is the ECO, this function must be registered, and -* it must be the last callback function that is registered. This is needed to allow the -* ECO to stabilize before reconnecting it to the FLL or PLL. +* \note This function must be the last callback function that is registered. +* Doing so minimizes the time spent on low power mode entry and exit. In the case +* where the ECO sources the FLL/PLL, this also allows the ECO to stabilize before +* reconnecting it to the FLL or PLL. * * \param callbackParams * structure with the syspm callback parameters, @@ -1242,6 +1306,9 @@ int32_t Cy_SysClk_PiloTrim(uint32_t piloFreq) * a clock measurement, otherwise Fail. Timeout if timeout waiting for FLL or a PLL * to regain its frequency lock. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_DeepSleepCallback +* *******************************************************************************/ cy_en_syspm_status_t Cy_SysClk_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) { @@ -1272,7 +1339,7 @@ cy_en_syspm_status_t Cy_SysClk_DeepSleepCallback(cy_stc_syspm_callback_params_t { /* If FLL or PLL is enabled, */ if (0ul != ((fllpll == 0ul) ? (_FLD2VAL(SRSS_CLK_FLL_CONFIG_FLL_ENABLE, SRSS->CLK_FLL_CONFIG)) : - (_FLD2VAL(SRSS_CLK_PLL_CONFIG_ENABLE, SRSS->CLK_PLL_CONFIG[fllpll])))) + (_FLD2VAL(SRSS_CLK_PLL_CONFIG_ENABLE, SRSS->CLK_PLL_CONFIG[fllpll - 1ul])))) { /* and the FLL or PLL has ECO as a source, */ if (Cy_SysClk_ClkPathGetSource(fllpll) == CY_SYSCLK_CLKPATH_IN_ECO) @@ -1282,11 +1349,20 @@ cy_en_syspm_status_t Cy_SysClk_DeepSleepCallback(cy_stc_syspm_callback_params_t /* keep a record that this FLL or PLL's source was changed from ECO */ changedSourcePaths |= (uint16_t)(1u << fllpll); } + + /* Set the FLL/PLL bypass mode to 2 */ + if(fllpll == 0UL) + { + CY_SYSCLK_CLR_SET(SRSS->CLK_FLL_CONFIG3, SRSS_CLK_FLL_CONFIG3_BYPASS_SEL, (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_INPUT); + } + else + { + CY_SYSCLK_CLR_SET(SRSS->CLK_PLL_CONFIG[fllpll - 1ul], SRSS_CLK_PLL_CONFIG_BYPASS_SEL, (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_INPUT); + } } } - /* Set the FLL bypass mode to 2 */ - CY_SYSCLK_CLR_SET(SRSS->CLK_FLL_CONFIG3, SRSS_CLK_FLL_CONFIG3_BYPASS_SEL, (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_INPUT); - /* Also, prevent starting a new clock measurement until after we've come back from DeepSleep. */ + + /* Prevent starting a new clock measurement until after we've come back from DeepSleep. */ preventCounting = true; } } @@ -1301,50 +1377,59 @@ cy_en_syspm_status_t Cy_SysClk_DeepSleepCallback(cy_stc_syspm_callback_params_t uint32_t timeout; /* Cy_SysClk_EcoGetStatus()return value 2ul = fully stabilized */ for (timeout = TIMEOUTK; (timeout != 0ul) && (Cy_SysClk_EcoGetStatus() != 2ul); timeout--){} - if (timeout != 0ul) + if (timeout == 0ul) { rtnval = CY_SYSPM_TIMEOUT; } - else + } + + if(rtnval == CY_SYSPM_SUCCESS) + { + /* for FLL and each PLL, */ + uint32_t fllpll; /* 0 = FLL, all other values = a PLL */ + for (fllpll = 0ul; fllpll < (SRSS_NUM_PLL + 1ul); fllpll++) { - /* for FLL and each PLL, */ - uint32_t fllpll; /* 0 = FLL, all other values = a PLL */ - for (fllpll = 0ul; fllpll < (SRSS_NUM_PLL + 1ul); fllpll++) + /* If FLL or PLL is enabled, */ + if (0ul != ((fllpll == 0ul) ? (_FLD2VAL(SRSS_CLK_FLL_CONFIG_FLL_ENABLE, SRSS->CLK_FLL_CONFIG)) : + (_FLD2VAL(SRSS_CLK_PLL_CONFIG_ENABLE, SRSS->CLK_PLL_CONFIG[fllpll - 1ul])))) { - /* If FLL or PLL is enabled, */ - if (0ul != - ((fllpll == 0ul) ? (_FLD2VAL(SRSS_CLK_FLL_CONFIG_FLL_ENABLE, SRSS->CLK_FLL_CONFIG)) : - (_FLD2VAL(SRSS_CLK_PLL_CONFIG_ENABLE, SRSS->CLK_PLL_CONFIG[fllpll])))) + /* check the record that this FLL or PLL's source was changed from ECO */ + if ((changedSourcePaths & (uint16_t)(1u << fllpll)) != 0u) { - /* check the record that this FLL or PLL's source was changed from ECO */ - if ((changedSourcePaths & (uint16_t)(1u << fllpll)) != 0u) + /* Change this FLL or PLL source back to ECO */ + (void)Cy_SysClk_ClkPathSetSource(fllpll, CY_SYSCLK_CLKPATH_IN_ECO); + } + + /* Timeout wait for FLL or PLL to regain lock. */ + uint32_t timout; + for (timout = TIMEOUTK; timout != 0ul; timout--) + { + if (true == ((fllpll == 0ul) ? Cy_SysClk_FllLocked() : Cy_SysClk_PllLocked(fllpll))) { - /* Change this FLL or PLL source back to ECO */ - (void)Cy_SysClk_ClkPathSetSource(fllpll, CY_SYSCLK_CLKPATH_IN_ECO); + break; } - { /* Timeout wait for FLL or PLL to regain lock. */ - uint32_t timout; - for (timout = TIMEOUTK; timout != 0ul; timout--) - { - if (true == ((fllpll == 0ul) ? Cy_SysClk_FllLocked() : Cy_SysClk_PllLocked(fllpll))) - { - break; - } - } - if (timout != 0ul) - { - rtnval = CY_SYSPM_TIMEOUT; - } + } + if (timout == 0ul) + { + rtnval = CY_SYSPM_TIMEOUT; + } + else + { + /* Set the FLL/PLL bypass mode to 3 */ + if(fllpll == 0UL) + { + CY_SYSCLK_CLR_SET(SRSS->CLK_FLL_CONFIG3, SRSS_CLK_FLL_CONFIG3_BYPASS_SEL, (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_OUTPUT); + } + else + { + CY_SYSCLK_CLR_SET(SRSS->CLK_PLL_CONFIG[fllpll - 1ul], SRSS_CLK_PLL_CONFIG_BYPASS_SEL, (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_OUTPUT); } } } } } - /* Set the FLL bypass mode to 3 */ - CY_SYSCLK_CLR_SET(SRSS->CLK_FLL_CONFIG3, SRSS_CLK_FLL_CONFIG3_BYPASS_SEL, - (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_OUTPUT); - /* Coming back from DeepSleep; we can allow clock measurement. */ + /* Allow clock measurement. */ preventCounting = false; } @@ -1383,16 +1468,16 @@ cy_en_syspm_status_t Cy_SysClk_DeepSleepCallback(cy_stc_syspm_callback_params_t void Cy_SysClk_WcoConfigureCsv(const cy_stc_wco_csv_config_t *config) { CY_ASSERT_L1(config != NULL); - CY_ASSERT_L3(config->SupervisorClock <= CY_SYSCLK_WCO_CSV_SUPERVISOR_PILO); - CY_ASSERT_L3(config->LossWindow <= CY_SYSCLK_CSV_LOSS_512_CYCLES); - CY_ASSERT_L3(config->LossAction <= CY_SYSCLK_CSV_ERROR_FAULT_RESET); + CY_ASSERT_L3(config->supervisorClock <= CY_SYSCLK_WCO_CSV_SUPERVISOR_PILO); + CY_ASSERT_L3(config->lossWindow <= CY_SYSCLK_CSV_LOSS_512_CYCLES); + CY_ASSERT_L3(config->lossAction <= CY_SYSCLK_CSV_ERROR_FAULT_RESET); /* First clear all bits, including the enable bit; disable loss detection. */ SRSS->CLK_CSV_WCO_CTL = 0ul; /* Then write the structure elements (which include an enable bit) to the register. */ - SRSS->CLK_CSV_WCO_CTL = _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_MUX, (uint32_t)config->SupervisorClock) | - _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_LOSS_WINDOW, (uint32_t)(config->LossWindow)) | - _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_LOSS_ACTION, (uint32_t)(config->LossAction)) | + SRSS->CLK_CSV_WCO_CTL = _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_MUX, (uint32_t)config->supervisorClock) | + _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_LOSS_WINDOW, (uint32_t)(config->lossWindow)) | + _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_LOSS_ACTION, (uint32_t)(config->lossAction)) | _VAL2FLD(SRSS_CLK_CSV_WCO_CTL_CSV_LOSS_EN, config->enableLossDetection); } #endif /* (SRSS_WCOCSV_PRESENT != 0) || defined(CY_DOXYGEN) */ @@ -1430,24 +1515,24 @@ cy_en_sysclk_status_t Cy_SysClk_ClkHfConfigureCsv(uint32_t clkHf, const cy_stc_c { CY_ASSERT_L1(clkHf < SRSS_NUM_HFROOT); CY_ASSERT_L1(config != NULL); - CY_ASSERT_L3(config->SupervisorClock <= CY_SYSCLK_CLKHF_CSV_SUPERVISOR_ALTHF); - CY_ASSERT_L3(config->FrequencyAction <= CY_SYSCLK_CSV_ERROR_FAULT_RESET); - CY_ASSERT_L3(config->LossWindow <= CY_SYSCLK_CSV_LOSS_512_CYCLES); - CY_ASSERT_L3(config->LossAction <= CY_SYSCLK_CSV_ERROR_FAULT_RESET); + CY_ASSERT_L3(config->supervisorClock <= CY_SYSCLK_CLKHF_CSV_SUPERVISOR_ALTHF); + CY_ASSERT_L3(config->frequencyAction <= CY_SYSCLK_CSV_ERROR_FAULT_RESET); + CY_ASSERT_L3(config->lossWindow <= CY_SYSCLK_CSV_LOSS_512_CYCLES); + CY_ASSERT_L3(config->lossAction <= CY_SYSCLK_CSV_ERROR_FAULT_RESET); /* First update the limit bits; this can be done regardless of enable state. */ - SRSS->CLK_CSV[clkHf].HF_LIMIT = _VAL2FLD(CLK_CSV_HF_LIMIT_UPPER_LIMIT, config->FrequencyUpperLimit) | - _VAL2FLD(CLK_CSV_HF_LIMIT_LOWER_LIMIT, config->FrequencyLowerLimit); + SRSS->CLK_CSV[clkHf].HF_LIMIT = _VAL2FLD(CLK_CSV_HF_LIMIT_UPPER_LIMIT, config->frequencyUpperLimit) | + _VAL2FLD(CLK_CSV_HF_LIMIT_LOWER_LIMIT, config->frequencyLowerLimit); /* Then clear all CTL register bits, including the enable bit; disable loss detection. */ SRSS->CLK_CSV[clkHf].HF_CTL = 0ul; /* Finally, write the structure elements (which include an enable bit) to the CTL register. */ SRSS->CLK_CSV[clkHf].HF_CTL = _VAL2FLD(CLK_CSV_HF_CTL_CSV_LOSS_EN, config->enableLossDetection) | - _VAL2FLD(CLK_CSV_HF_CTL_CSV_LOSS_ACTION, (uint32_t)(config->LossAction)) | + _VAL2FLD(CLK_CSV_HF_CTL_CSV_LOSS_ACTION, (uint32_t)(config->lossAction)) | _VAL2FLD(CLK_CSV_HF_CTL_CSV_FREQ_EN, config->enableFrequencyFaultDetection) | - _VAL2FLD(CLK_CSV_HF_CTL_CSV_FREQ_ACTION, (uint32_t)(config->FrequencyAction)) | - _VAL2FLD(CLK_CSV_HF_CTL_CSV_LOSS_WINDOW, (uint32_t)(config->LossWindow)) | - _VAL2FLD(CLK_CSV_HF_CTL_CSV_MUX, (uint32_t)(config->SupervisorClock)) | - _VAL2FLD(CLK_CSV_HF_CTL_CSV_FREQ_WINDOW, config->SupervisingWindow); + _VAL2FLD(CLK_CSV_HF_CTL_CSV_FREQ_ACTION, (uint32_t)(config->frequencyAction)) | + _VAL2FLD(CLK_CSV_HF_CTL_CSV_LOSS_WINDOW, (uint32_t)(config->lossWindow)) | + _VAL2FLD(CLK_CSV_HF_CTL_CSV_MUX, (uint32_t)(config->supervisorClock)) | + _VAL2FLD(CLK_CSV_HF_CTL_CSV_FREQ_WINDOW, config->supervisingWindow); return CY_SYSCLK_SUCCESS; /* placeholder */ } #endif /* (SRSS_MASK_HFCSV != 0) || defined(CY_DOXYGEN) */ @@ -1477,6 +1562,9 @@ cy_en_sysclk_status_t Cy_SysClk_ClkHfConfigureCsv(uint32_t clkHf, const cy_stc_c * The reported frequency may be zero, which indicates unknown. This happens if * the source input is clk_ext, ECO, clk_althf, dsi_out, or clk_altlf. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphGetFrequency +* *******************************************************************************/ uint32_t Cy_SysClk_PeriphGetFrequency(cy_en_divider_types_t dividerType, uint32_t dividerNum) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysclk/cy_sysclk.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysclk/cy_sysclk.h similarity index 81% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysclk/cy_sysclk.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysclk/cy_sysclk.h index b6e0b9007d..1b4acd85a4 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysclk/cy_sysclk.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysclk/cy_sysclk.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_sysclk.h -* \version 1.10 +* \version 1.10.1 * * Provides an API declaration of the sysclk driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -19,8 +19,7 @@ * peripheral clocks. Firmware uses the API to configure , enable, or disable * a clock. * -* The PSoC 6 clock system includes a variety of resources that can vary per -* device, including: +* The clock system includes a variety of resources that can vary per device, including: * - Internal clock sources such as internal oscillators * - External clock sources such as crystal oscillators or a signal on an I/O pin * - Generated clocks such as an FLL, a PLL, and peripheral clocks @@ -29,42 +28,29 @@ * clock system. * * The PDL defines clock system capabilities in:\n -* devices\//include\_config.h. For example\n -* devices/psoc6/psoc63/include/psoc63_config.h. User-configurable clock speeds -* are defined in the file system_.h. +* devices\//include\_config.h. (E.g. +* devices/psoc6/psoc63/include/psoc63_config.h). +* User-configurable clock speeds are defined in the file system_.h. * -* This diagram represents the PSoC 63 series clock tree. The actual tree -* may vary based on series. +* As an illustration of the clocking system, the following diagram shows the +* PSoC 63 series clock tree. The actual tree may vary depending on the device series. * ![](sysclk_tree.png) * -* In addition to the clocks shown on the diagram, this driver also supports -* multiple peripheral clocks, as well as the fast clock, slow clock, backup -* domain clock, timer clock, and pump clock. There are also functions for -* clock measurement and trimming. -* -* The API for any given clock contains the functions to manage that clock. These -* functions may include: -* - Enable or Disable -* - Get or Set Source -* - Get or Set Divider -* - Configure -* -* In the API reference for this driver, most clocks have -* a dedicated section, so the information to manage that clock is in one -* place. Use the left navigation menu to locate the desired information. +* The sysclk driver supports multiple peripheral clocks, as well as the fast +* clock, slow clock, backup domain clock, timer clock, and pump clock. The API +* for any given clock contains the functions to manage that clock. Functions +* for clock measurement and trimming are also provided. * * \section group_sysclk_configuration Configuration Considerations -* There are no general SysClk configuration concerns. -* Some clocks (for example the PLL) require configuration. For such a clock the -* API typically provides a Configure function to set up the clock. See notes on -* individual function definitions. -* \warning When the device is in the Ultra-Low Power (ULP) mode, the maximum -* frequency of some clocks is reduced. See the device datasheet for details. +* The availability of clock functions depend on the availability of the chip +* resources that support those functions. Consult the device TRM before +* attempting to use these functions. * +* LPActive and LPSleep power modes limit the maximum clock frequency allowed +* on the device. Refer to the SysPm driver and the TRM for details. * * \section group_sysclk_more_information More Information -* See the Clock Component datasheet. See also the Clocking System chapter of -* the device technical reference manual (TRM). +* Refer to the technical reference manual (TRM) and the device datasheet. * * \section group_sysclk_MISRA MISRA-C Compliance * @@ -178,6 +164,32 @@ *
* * +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* * * * @@ -193,69 +205,77 @@ * \} * \defgroup group_sysclk_eco External Crystal Oscillator (ECO) * \{ -*

The PSoC 6 BLE device contains an oscillator to drive an external -* crystal. This clock source is built using an oscillator circuit -* in PSoC. The circuit employs an external crystal that must be populated on -* the external crystal pins of the PSoC. The ECO can be the source clock for -* any of the clock paths. See \ref group_sysclk_path_src.

+* The External Crystal Oscillator (ECO) is a clock source that consists +* of an oscillator circuit that drives an external crystal through its +* dedicated ECO pins. The ECO is a source clock that can be used to +* source one or more clock paths (Refer to \ref group_sysclk_path_src). +* These clock paths can then source the processors and peripherals in +* the device. * -* Use Cy_SysClk_EcoConfigure() to configure the ECO. Pass in the required -* parameters, there is no configuration structure. Use Cy_SysClk_ClkPathSetSource() -* to specify the clock path source as \ref CY_SYSCLK_CLKPATH_IN_ECO +* The ECO relies on the presence of an external crystal. The pins +* connected to this crystal must be configured to operate in analog +* drive mode with HSIOM connection set to GPIO control (HSIOM_SEL_GPIO). * * \defgroup group_sysclk_eco_funcs Functions * \} * \defgroup group_sysclk_path_src Clock Path Source * \{ -*

Use these functions to set or get the source clock for a clock path. A clock -* path can use the same or a different source clock as any other path. API -* functions set or get the source.

+* Clock paths are a series of multiplexers that allow a source clock +* to drive multiple clocking resources down the chain. These paths are +* used for active domain clocks that are not operational during chip +* deep-sleep, hibernate and off modes. Illustrated below is a diagram +* of the clock paths for the PSoC 63 series, showing the first three +* clock paths. The source clocks for these paths are highlighted in +* the red box. * -* Clock path: Path 0 is the FLL; path 1 is the PLL, path 2 is direct -* to the high-frequency clocks. +* - IMO: 8 MHz Internal Main Oscillator (Default) +* - EXTCLK: External clock (signal brought in through dedicated pins) +* - ECO: External Crystal Oscillator (requires external crystal on dedicated pins) +* - ALTHF: Select on-chip signals (e.g. BLE ECO) +* - Digital Signal (DSI): Digital signal from a UDB source +* +* Some clock paths such as path 0 and path 1 have additional resources +* that can be utilized to provide a higher frequency clock. For example, +* path 0 source clock can be used as the reference clock for the FLL and +* path 1 source clock can be used as the reference clock for the PLL. * -* Clock source: Use constants enumerated in \ref cy_en_clkpath_in_sources_t -* to identify the source clock. The actual available clock paths and sources may -* vary from the diagram. * ![](sysclk_path_source.png) * * \note The PDL driver cannot configure a clock path to use Digital Signal * Interconnect (DSI) outputs as sources. This must be done through DSI -* configuration in PSoC Creator. +* configuration tool such as PSoC Creator. * * \defgroup group_sysclk_path_src_funcs Functions * \defgroup group_sysclk_path_src_enums Enumerated Types * \} * \defgroup group_sysclk_fll Frequency Locked Loop (FLL) * \{ -*

The FLL generates a clock output based on the input frequency. Consult -* device-specific documentation for the frequency ranges for your device. -* The design makes it possible to use a lower -* frequency source, such as IMO, to generate higher clock frequencies -* for the rest of the system.

+* The FLL is a clock generation circuit that can be used to produce a +* higher frequency clock from a reference clock. The output clock exhibits +* some characteristics of the reference clock such as the accuracy of the +* source. However other attributes such as the clock phase are not preserved. +* The FLL is similar in purpose to a (Phase locked loop) PLL but they are +* not equivalent. * -* The FLL is similar in purpose to a PLL but is not equivalent. * - They may have different frequency ranges. * - The FLL starts up (locks) faster and consumes less current than the PLL. * - The FLL accepts a source clock with lower frequency than PLL, such as the WCO (32 KHz). -* - The FLL does not lock phase. It is essentially a counter with a -* current-controlled oscillator (CCO). The counter counts the number of output -* clock edges in a reference clock period and adjusts the CCO until the -* expected ratio is achieved (locked). After initial lock, the CCO is -* adjusted dynamically to keep the ratio within tolerance. The lock tolerance -* is user-adjustable. +* - The FLL does not lock phase. The hardware consist of a counter with a +* current-controlled oscillator (CCO). The counter counts the number of output +* clock edges in a reference clock period and adjusts the CCO until the +* expected ratio is achieved (locked). After initial lock, the CCO is +* adjusted dynamically to keep the ratio within tolerance. The lock tolerance +* is user-adjustable. * ![](sysclk_fll.png) * -* Firmware configures the FLL using Cy_SysClk_FllConfigure(). Specify the input -* and output frequencies, and the output mode. See \ref cy_en_fll_pll_output_mode_t -* for output choices. -* -* Alternatively, firmware can fill in values for the -* \ref cy_stc_fll_manual_config_t structure, and call Cy_SysClk_FllManualConfigure(). -* This call provides precise control over the FLL configuration, such as the -* lock tolerance. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* The SysClk driver supports two models for configuring the FLL. The first +* model is to call the Cy_SysClk_FllConfigure() function, which calculates the +* necessary parameters for the FLL at run-time. This may be necessary for dynamic +* run-time changes to the FLL. However this method is slow as it needs to perform +* the calculation before configuring the FLL. The other model is to call +* Cy_SysClk_FllManualConfigure() function with pre-calculated parameter values. +* This method is faster but requires prior knowledge of the necessary parameters. +* Consult the device TRM for the FLL calculation equations. * * \defgroup group_sysclk_fll_funcs Functions * \defgroup group_sysclk_fll_structs Data Structures @@ -263,151 +283,139 @@ * \} * \defgroup group_sysclk_pll Phase Locked Loop (PLL) * \{ -*

The PLL generates a clock output based on the input frequency. Consult -* device-specific documentation for the frequency ranges for your device. The -* design makes it possible to use a lower frequency source, such as IMO, to -* generate higher clock frequencies for the rest of the system.

+* The PLL is a clock generation circuit that can be used to produce a +* higher frequency clock from a reference clock. The output clock exhibits +* characteristics of the reference clock such as the accuracy of the source +* and its phase. The PLL is similar in purpose to a (Frequency locked loop) FLL +* but they are not equivalent. * -* The PLL is similar in purpose to the FLL but is not equivalent. * - They may have different frequency ranges. * - The PLL starts up more slowly and consumes more current than the FLL. * - The PLL requires a higher frequency source clock than PLL. * ![](sysclk_pll.png) * -* Firmware can configure the PLL using Cy_SysClk_PllConfigure(). Provide -* configuration values in a filled \ref cy_stc_pll_config_t structure. See -* \ref cy_en_fll_pll_output_mode_t for output choices. -* -* Alternatively, firmware can fill in values for the \ref cy_stc_pll_manual_config_t -* structure, and call Cy_SysClk_PllManualConfigure(). -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* The SysClk driver supports two models for configuring the PLL. The first +* model is to call the Cy_SysClk_PllConfigure() function, which calculates the +* necessary parameters for the PLL at run-time. This may be necessary for dynamic +* run-time changes to the PLL. However this method is slow as it needs to perform +* the calculation before configuring the PLL. The other model is to call +* Cy_SysClk_PllManualConfigure() function with pre-calculated parameter values. +* This method is faster but requires prior knowledge of the necessary parameters. +* Consult the device TRM for the PLL calculation equations. * * \defgroup group_sysclk_pll_funcs Functions * \defgroup group_sysclk_pll_structs Data Structures * \} * \defgroup group_sysclk_ilo Internal Low-Speed Oscillator (ILO) * \{ -*

The ILO operates with no external components and outputs a stable clock at -* 32.768 kHz nominal. The ILO is relatively low power and low -* accuracy. The ILO is in the backup domain. It is available in all -* power modes. The ILO can be used as a source for the \ref group_sysclk_clk_lf.

+* The ILO operates with no external components and outputs a stable clock at +* 32.768 kHz nominal. The ILO is relatively low power and low accuracy. It is +* available in all power modes and can be used as a source for the Backup domain clock. * ![](sysclk_backup.png) * -* The ILO is always the source clock for the \ref group_wdt. Therefore: +* To ensure the ILO remains active in Hibernate mode, and across power-on-reset +* (POR) or brown out detect (BOD), firmware must call Cy_SysClk_IloHibernateOn(). +* +* Additionally, the ILO clock can be trimmed to +/- 1.5% of nominal frequency using +* a higher precision clock source. Use the \ref group_sysclk_calclk API to measure +* the current ILO frequency before trimming. +* +* \note The ILO is always the source clock for the \ref group_wdt. Therefore: * - The WDT must be unlocked when making an ILO function call in the PDL * - It is recommended to always have the ILO enabled * -* API functions enable or disable the clock. To ensure the ILO remains active -* in Hibernate mode, and across power-on-reset (POR) or brown out detect (BOD), -* firmware must call Cy_SysClk_IloHibernateOn() and pass in a Boolean TRUE. -* -* This clock can be trimmed. Firmware uses functions described in -* \ref group_sysclk_calclk to get the current clock frequency before trimming. -* Then call Cy_SysClk_IloTrim(). -* -* See the Clocking System chapter of the device technical reference manual (TRM). -* * \defgroup group_sysclk_ilo_funcs Functions * \} * \defgroup group_sysclk_pilo Precision Internal Low-Speed Oscillator (PILO) * \{ -*

PILO provides a more accurate 32.768-kHz clock than \ref group_sysclk_ilo "ILO", when -* periodically calibrated using a high-accuracy clock such as the -* \ref group_sysclk_eco "ECO". PILO works in Deep-Sleep and higher power -* modes. It is not available in Hibernate mode.

+* PILO provides a higher accuracy 32.768 kHz clock than the \ref group_sysclk_ilo "ILO". +* When periodically calibrated using a high-accuracy clock such as the +* \ref group_sysclk_eco "ECO", the PILO can achieve 250 ppm accuracy of nominal frequency. +* The PILO is capable of operating in device Active, Sleep and Deep-Sleep power modes. +* It is not available in Hibernate mode. * * The PILO can be used as a source for the \ref group_sysclk_clk_lf. However, -* because PILO is disabled in Hibernate mode, RTC timers and counters can be -* corrupted. If this is unacceptable, use \ref group_sysclk_ilo "ILO" or -* \ref group_sysclk_wco "WCO" as the source clock for -* the low-frequency clock. +* because PILO is disabled in Hibernate mode, RTC timers cannot operate in this mode +* when clocked using the PILO. Instead, either the \ref group_sysclk_ilo "ILO" or +* \ref group_sysclk_wco "WCO" should be used when hibernate operation is required. * * ![](sysclk_backup.png) * * Periodic calibration to a high-accuracy clock (such as ECO) is required to -* maintain accuracy. Firmware uses functions described in Clock Measurement -* to get the current PILO frequency before trimming. Then use Cy_SysClk_PiloTrim(). -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* maintain accuracy. The application should use the functions described in the +* \ref group_sysclk_calclk API to measure the current PILO frequency before trimming. * * \defgroup group_sysclk_pilo_funcs Functions * \} * \defgroup group_sysclk_calclk Clock Measurement * \{ -*

These functions measure the frequency of a specified clock relative to a -* reference clock. They are typically called in the following order:

-* 1. Specify the measured clock, the count, and the reference clock; then start the counters: -* Cy_SysClk_StartClkMeasurementCounters(); -* 2. Wait for the measurement counter to finish counting: -* while(Cy_SysClk_ClkMeasurementCountersDone() != CY_RET_FINISHED); -* 3. Get the measured frequency:
-* freq_measure = Cy_SysClk_ClkMeasurementCountersGetFreq(); +* These functions measure the frequency of a specified clock relative to a +* reference clock. They are typically called in the following order: +* +* 1. Specify the measured clock, the count, and the reference clock +* 2. Start the counters +* 3. Wait for the measurement counter to finish counting +* 4. Retrieve the measured frequency * * \note These functions may also be used as part of a clock trimming -* process - see the \ref group_sysclk_trim "Clock Trim" section. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* process. Refer to the \ref group_sysclk_trim "Clock Trim" API. * * \defgroup group_sysclk_calclk_funcs Functions * \defgroup group_sysclk_calclk_enums Enumerated Types * \} * \defgroup group_sysclk_trim Clock Trim (ILO, PILO) * \{ -*

These functions perform a single trim operation on the ILO or PILO. Each +* These functions perform a single trim operation on the ILO or PILO. Each * function's parameter is the actual frequency of the clock. To measure the -* frequency, use the functions described in the \ref group_sysclk_calclk section.

+* frequency, use the functions described in the \ref group_sysclk_calclk API. * * To trim the clock as close as possible to the target frequency, multiple * calls to the trim function may be needed. A typical usage example is to: * 1. Call the clock measurement functions to get the actual frequency of the clock -* 2. Call the trim function, passing in the measured frequency: -* Cy_SysClk_IloTrim() or Cy_SysClk_PiloTrim() -* 3. Repeat the above until the trim function reports trimming is done. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* 2. Call the trim function, passing in the measured frequency +* 3. Repeat the above until the trim function reports that the clock is trimmed to within limits. * * \defgroup group_sysclk_trim_funcs Functions * \} -* \defgroup group_sysclk_pm Power Management +* \defgroup group_sysclk_pm Low Power Callback * \{ -* The PDL provides a callback function that firmware can use to handle -* transition to DeepSleep mode: Cy_SysClk_DeepSleepCallback(). -* -* Firmware can configure the system to call this function during execution of -* Cy_SysPm_DeepSleep(). To do so, register this function as a callback before -* calling Cy_SysPm_DeepSleep(). Specify \ref CY_SYSPM_DEEPSLEEP as the callback type, +* Entering and exiting low power modes require compatible clock configurations +* to be set before entering low power and restored upon wake-up and exit. The +* SysClk driver provides a Cy_SysClk_DeepSleepCallback() function to support +* deep-sleep mode entry. +* +* This function can be called either by itself before initiating low-power mode +* entry or it can be used in conjunction with the SysPm driver as a registered +* callback. To do so, register this function as a callback before calling +* Cy_SysPm_DeepSleep(). Specify \ref CY_SYSPM_DEEPSLEEP as the callback type, * and call Cy_SysPm_RegisterCallback(). * -* \note If the FLL or PLL source is the ECO, this function must be registered, -* and it must be the last callback function that is registered. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* \note If the FLL or PLL source is the ECO, this function must be called. * * \defgroup group_sysclk_pm_funcs Functions * \} * \defgroup group_sysclk_wco Watch Crystal Oscillator (WCO) * \{ -*

The WCO is a highly accurate 32.768-kHz clock source. It is the primary -* clock source for the real-time clock (RTC). The WCO can be used as a -* source for the low-frequency clock. A design can bypass the WCO. If so, -* an external 32 KHz clock must be provided on the WCO_OUT pin.

+* The WCO is a highly accurate 32.768 kHz clock source capable of operating +* in all power modes (excluding the Off mode). It is the primary clock source for +* the backup domain clock, which is used by the real-time clock (RTC). The +* WCO can also be used as a source for the low-frequency clock to support other +* low power mode peripherals. * * ![](sysclk_backup.png) * -* The WCO has a built-in clock supervisor (CSV). The supervisor detects if -* the WCO has been lost; that is, the WCO is no longer producing clock -* pulses. The CSV does this by checking to ensure there is at least one WCO -* clock pulse within a certain time window. The ILO or PILO can be the -* supervising clock. Firmware can configure the CSV to trigger a fault, -* a reset, or a fault after four cycles of the supervising clock. +* The WCO requires the configuration of the dedicated WCO pins (SRSS_WCO_IN_PIN, +* SRSS_WCO_OUT_PIN). These must be configured as Analog Hi-Z drive modes and the +* HSIOM selection set to GPIO. The WCO can also be used in bypass mode, where +* an external 32.768 kHz square wave is brought in directly through the +* SRSS_WCO_OUT_PIN pin. * -* To configure the CSV, fill in the values of a \ref cy_stc_wco_csv_config_t -* structure and call Cy_SysClk_WcoConfigureCsv(). This structure specifies -* the supervising clock, that the CSV is enabled, the time window, and the -* action on error. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* Some devices support a built-in clock supervisor (CSV) in the WCO. The clock +* supervisor detects if the WCO has been lost; that is, the WCO is no longer +* producing clock pulses. The CSV does this by checking to ensure there is at +* least one WCO clock pulse within a certain time window. The ILO or PILO can be +* the supervising clock. Firmware can configure the CSV to trigger a fault, +* a reset, or both after specified cycles of the supervising clock. * * \defgroup group_sysclk_wco_funcs Functions * \defgroup group_sysclk_wco_structs Data Structures @@ -415,40 +423,33 @@ * \} * \defgroup group_sysclk_clk_hf High-Frequency Clocks * \{ -*

PSoC 6 has five high-frequency root clocks. Each CLK_HF has a particular -* destination on the device.

+* Multiple high frequency clocks (CLK_HF) are available in the device. For example, +* PSoC 63 series has five high-frequency root clocks. Each CLK_HF has a particular +* connection and chip-specific destination on the device. * * |Name |Description | * |:--------|:-------------------------------------------------------| -* |CLK_HF[0]| Root clock for both CPUs, PERI, and AHB infrastructure | +* |CLK_HF[0]| Root clock for CPUs, PERI, and AHB infrastructure | * |CLK_HF[1]| Root clock for the PDM/PCM and I2S audio subsystem | * |CLK_HF[2]| Root clock for the Serial Memory Interface subsystem | * |CLK_HF[3]| Root clock for USB communications | * |CLK_HF[4]| Clock output on clk_ext pin (when used as an output) | * * ![](sysclk_hf.png) -* -* Each root clock has a clock supervisor (CSV) that can detect frequency loss, -* or monitor that the clock frequency stays within a specified range. The -* possible supervising clocks are IMO, the external clock, or ALTHF. Loss -* detection and frequency monitoring can be enabled or disabled -* independently. Each has its own programmable action that occurs on -* detection of an error. * -* To configure the CSV, fill in the values of a \ref cy_stc_clkhf_csv_config_t -* structure and call Cy_SysClk_ClkHfConfigureCsv(). This structure specifies -* the supervising clock, the action on error, the frequency range to -* monitor, and other configuration options. -* -* API functions enable or disable, set or get the clock source, set or get the -* clock divider. -* -* Note that CLK_HF[0] cannot be disabled. This divided clock drives the CM4, -* the CM0+, and the peripherals in the system. +* High frequency clocks are sourced by path clocks, which should be configured +* first. An exception to this rule is CLK_HF[0], which cannot be disabled. +* This divided clock drives the core processors and the peripherals in the system. +* In order to update its clock source, CLK_HF[0] source must be selected without +* disabling the clock. * * ![](sysclk_hf_dist.png) * -* See the Clocking System chapter of the device technical reference manual (TRM). +* Some devices support a clock supervisor (CSV) for each root clock. These +* can detect frequency loss, or monitor that the clock frequency stays within +* a specified range. The possible supervising clocks are IMO, ECO, or ALTHF. +* Loss detection and frequency monitoring can be enabled or disabled independently. +* Each has its own programmable action that occurs on detection of an error. * * \defgroup group_sysclk_clk_hf_funcs Functions * \defgroup group_sysclk_clk_hf_structs Data Structures @@ -456,37 +457,32 @@ * \} * \defgroup group_sysclk_clk_fast Fast Clock * \{ -*

The fast clock drives the Cortex-M4 processor. This clock is a divided -* version of CLK_HF[0]. See \ref group_sysclk_clk_hf "HF Clocks". -* -* The API functions for this clock set or get the divider. +* The fast clock drives the "fast" processor (e.g. Cortex-M4 processor in PSoC 6). +* This clock is sourced by CLK_HF[0] (\ref group_sysclk_clk_hf "HF Clocks"). +* A divider value of 1~256 can be used to further divide the CLK_HF[0] to a +* desired clock speed for the processor. * * ![](sysclk_fast.png) * -* See the Clocking System chapter of the device technical reference manual (TRM). -* * \defgroup group_sysclk_clk_fast_funcs Functions * \} * \defgroup group_sysclk_clk_peri Peripheral Clock * \{ -*

The peripheral clock is a divided clock of CLK_HF0. See -* \ref group_sysclk_clk_hf "HF Clocks". It is the source clock for the -* \ref group_sysclk_clk_slow, and multiple peripheral clocks. See -* \ref group_sysclk_clk_peripheral.

-* -* The API functions for this clock set or get the divider. +* The peripheral clock is a divided clock of CLK_HF0 (\ref group_sysclk_clk_hf "HF Clocks"). +* It is the source clock for the \ref group_sysclk_clk_slow, and most active domain +* peripheral clocks (\ref group_sysclk_clk_peripheral). A divider value of 1~256 +* can be used to further divide the CLK_HF[0] to a desired clock speed for the peripherals. * * ![](sysclk_peri.png) * -* See the Clocking System chapter of the device technical reference manual (TRM). -* * \defgroup group_sysclk_clk_peri_funcs Functions * \} * \defgroup group_sysclk_clk_peripheral Peripherals Clock Dividers * \{ -*

There are multiple peripheral clock dividers that, in effect, create +* There are multiple peripheral clock dividers that, in effect, create * multiple separate peripheral clocks. The available dividers vary per device -* series. As an example, for the PSoC 63 series there are 29 dividers:

+* series. As an example, for the PSoC 63 series there are 29 dividers: +* * - eight 8-bit dividers * - sixteen 16-bit dividers * - four fractional 16.5-bit dividers (16 integer bits, 5 fractional bits) @@ -503,102 +499,73 @@ * Each peripheral can connect to any one of the programmable dividers. A * particular peripheral clock divider can drive multiple peripherals. * -* API functions set (Cy_SysClk_PeriphAssignDivider()) or get -* (Cy_SysClk_PeriphGetAssignedDivider()) the divider assigned to a peripheral. -* -* Other API functions set or get the actual divider value, set or get a -* fractional divider, and enable or disable a divider. -* -* The driver supports phase aligning two peripheral clock dividers with +* The SysClk driver also supports phase aligning two peripheral clock dividers using * Cy_SysClk_PeriphEnablePhaseAlignDivider(). Alignment works for both integer * and fractional dividers. The divider to which a second divider is aligned * must already be enabled. -* -* See the Clocking System chapter of the device technical reference manual (TRM). * * \defgroup group_sysclk_clk_peripheral_funcs Functions * \defgroup group_sysclk_clk_peripheral_enums Enumerated Types * \} * \defgroup group_sysclk_clk_slow Slow Clock * \{ -*

The slow clock is the source clock for the Cortex-M0+. This clock is a -* divided version of the \ref group_sysclk_clk_peri, which in turn is a divided version -* of CLK_HF[0]. See \ref group_sysclk_clk_hf "HF Clocks".

-* -* The API functions for this clock set or get the divider. +* The slow clock is the source clock for the "slow" processor (e.g. Cortex-M0+ in PSoC 6). +* This clock is a divided version of the \ref group_sysclk_clk_peri, which in turn is +* a divided version of CLK_HF[0] (\ref group_sysclk_clk_hf "HF Clocks"). A divider +* value of 1~256 can be used to further divide the Peri clock to a desired clock speed +* for the processor. * * ![](sysclk_slow.png) * -* See the Clocking System chapter of the device technical reference manual (TRM). -* * \defgroup group_sysclk_clk_slow_funcs Functions * \} * \defgroup group_sysclk_clk_lf Low-Frequency Clock * \{ -*

The low-frequency clock is the source clock for the \ref group_mcwdt +* The low-frequency clock is the source clock for the \ref group_mcwdt * and can be the source clock for \ref group_sysclk_clk_bak, which drives the -* \ref group_rtc.

+* \ref group_rtc. * * The low-frequency clock has three possible source clocks: * \ref group_sysclk_ilo "ILO", \ref group_sysclk_pilo "PILO", and * \ref group_sysclk_wco "WCO". -* -* The API functions for this clock set or get the source clock. * * ![](sysclk_lf.png) * -* See the Clocking System chapter of the device technical reference manual (TRM). -* * \defgroup group_sysclk_clk_lf_funcs Functions * \defgroup group_sysclk_clk_lf_enums Enumerated Types * \} * \defgroup group_sysclk_clk_timer Timer Clock * \{ -*

The timer clock can be the source clock for the \ref group_arm_system_timer -* (Cy_SysTick_SetClockSource()). It can also be used as a reference clock for -* a counter in the \ref group_energy_profiler "Profile" (Cy_Profile_ConfigureCounter()).

+* The timer clock can be a source for the alternative clock driving +* the \ref group_arm_system_timer. It can also be used as a reference clock +* for a counter in the \ref group_energy_profiler "Energy Profiler". * -* The timer clock is a divided clock of either IMO or CLK_HF[0]. See -* \ref group_sysclk_clk_hf "HF Clocks". -* -* API functions for this clock set or get the source, set or get the divider, -* and enable or disable the clock. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* The timer clock is a divided clock of either the IMO or CLK_HF[0] +* (\ref group_sysclk_clk_hf "HF Clocks"). * * \defgroup group_sysclk_clk_timer_funcs Functions * \defgroup group_sysclk_clk_timer_enums Enumerated Types * \} * \defgroup group_sysclk_clk_pump Pump Clock * \{ -* The pump clock may be required to drive the internal voltage pump for the -* Continuous Time Block mini (CTBm) in the analog subsystem. -* -* The pump clock is a divided clock of one of the clock paths. See -* \ref group_sysclk_path_src. -* -* API functions for this clock set or get the source, set or get the divider, -* and enable or disable the clock. -* -* See the Clocking System chapter of the device technical reference manual -* (TRM) and the Continuous Time Block mini chapter of the TRM. +* The pump clock is a clock source used to provide analog precision in low voltage +* applications. Depedning on the usage scenario, it may be required to drive the +* internal voltage pump for the Continuous Time Block mini (CTBm) in the analog +* subsystem. The pump clock is a divided clock of one of the clock paths +* (\ref group_sysclk_path_src). * * \defgroup group_sysclk_clk_pump_funcs Functions * \defgroup group_sysclk_clk_pump_enums Enumerated Types * \} * \defgroup group_sysclk_clk_bak Backup Domain Clock * \{ -* The backup domain clock drives the \ref group_rtc. -* -* The backup domain clock has two possible source clocks: \ref group_sysclk_wco "WCO" +* The backup domain clock drives the \ref group_rtc. +* This clock has two possible source clocks: \ref group_sysclk_wco "WCO" * or the \ref group_sysclk_clk_lf. In turn the low frequency clock is sourced by * \ref group_sysclk_ilo "ILO", \ref group_sysclk_pilo "PILO", or -* \ref group_sysclk_wco "WCO". Typically ILO is not suitable as an RTC source, -* because of its low accuracy. -* -* The API functions for this clock set or get the source clock. -* -* See the Clocking System chapter of the device technical reference manual (TRM). +* \ref group_sysclk_wco "WCO". Typically the ILO is not suitable as an RTC source, +* because of its low accuracy. However the ILO does operate in hibernate mode and +* may be used as an alterative to the WCO with a tradeoff in precision. * * \defgroup group_sysclk_clk_bak_funcs Functions * \defgroup group_sysclk_clk_bak_enums Enumerated Types @@ -657,6 +624,24 @@ typedef enum /* ========================================================================== */ /* =========================== ECO SECTION ============================ */ /* ========================================================================== */ + +/** +* \addtogroup group_sysclk_macros +* \{ +*/ + +/** +* \defgroup group_sysclk_ecostatus ECO status +* \{ +* Constants used for expressing ECO status. +*/ +#define CY_SYSCLK_ECOSTAT_AMPLITUDE 0UL /**< \brief ECO does not have sufficient amplitude */ +#define CY_SYSCLK_ECOSTAT_INACCURATE 1UL /**< \brief ECO may not be meeting accuracy and duty cycle specs */ +#define CY_SYSCLK_ECOSTAT_STABLE 2UL /**< \brief ECO has fully stabilized */ +/** \} */ + +/** \} group_sysclk_macros */ + /** * \addtogroup group_sysclk_eco_funcs * \{ @@ -673,6 +658,9 @@ __STATIC_INLINE uint32_t Cy_SysClk_EcoGetStatus(void); * Disables the external crystal oscillator (ECO). This function should not be * called if the ECO is sourcing clkHf[0]. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_EcoDisable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_EcoDisable(void) { @@ -686,9 +674,12 @@ __STATIC_INLINE void Cy_SysClk_EcoDisable(void) * Reports the current status of the external crystal oscillator (ECO). * * \return -* 0 = ECO does not have sufficient amplitude
-* 1 = ECO has sufficient amplitude but may not be meeting accuracy and duty cycle specifications
-* 2 = ECO has fully stabilized +* CY_SYSCLK_ECOSTAT_AMPLITUDE = ECO does not have sufficient amplitude
+* CY_SYSCLK_ECOSTAT_INACCURATE = ECO has sufficient amplitude but may not be meeting accuracy and duty cycle specifications
+* CY_SYSCLK_ECOSTAT_STABLE = ECO has fully stabilized +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_EcoGetStatus * *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SysClk_EcoGetStatus(void) @@ -795,7 +786,9 @@ cy_en_sysclk_status_t Cy_SysClk_FllManualConfigure(const cy_stc_fll_manual_confi void Cy_SysClk_FllGetConfiguration(cy_stc_fll_manual_config_t *config); cy_en_sysclk_status_t Cy_SysClk_FllEnable(uint32_t timeoutus); __STATIC_INLINE bool Cy_SysClk_FllLocked(void); +#if (CY_IP_MXS40SRSS_VERSION != 1) || defined(CY_DOXYGEN) __STATIC_INLINE bool Cy_SysClk_FllLostLock(void); +#endif __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_FllDisable(void); /******************************************************************************* @@ -804,7 +797,12 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_FllDisable(void); * * Reports whether or not the FLL is locked. * -* \return false = not locked, true = locked +* \return +* false = not locked
+* true = locked +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllLocked * *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_FllLocked(void) @@ -812,6 +810,7 @@ __STATIC_INLINE bool Cy_SysClk_FllLocked(void) return (bool)(_FLD2VAL(SRSS_CLK_FLL_STATUS_LOCKED, SRSS->CLK_FLL_STATUS)); } +#if (CY_IP_MXS40SRSS_VERSION != 1) || defined(CY_DOXYGEN) /******************************************************************************* * Function Name: Cy_SysClk_FllLostLock ****************************************************************************//** @@ -819,7 +818,12 @@ __STATIC_INLINE bool Cy_SysClk_FllLocked(void) * Reports whether or not the FLL lost its lock since the last time this function * was called. Clears the lost lock indicator. * -* \return false = didn't lose lock, true = lost lock +* \return +* false = did not lose lock
+* true = lost lock +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllLostLock * *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_FllLostLock(void) @@ -829,6 +833,7 @@ __STATIC_INLINE bool Cy_SysClk_FllLostLock(void) SRSS->CLK_FLL_STATUS = _VAL2FLD(SRSS_CLK_FLL_STATUS_UNLOCK_OCCURRED, 1u); return ((bool)retval); } +#endif /******************************************************************************* * Function Name: Cy_SysClk_FllDisable @@ -838,12 +843,15 @@ __STATIC_INLINE bool Cy_SysClk_FllLostLock(void) * * \return \ref cy_en_sysclk_status_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_FllDisable +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_FllDisable(void) { SRSS->CLK_FLL_CONFIG &= ~_VAL2FLD(SRSS_CLK_FLL_CONFIG_FLL_ENABLE, 1u); /* 0 = disable */ SRSS->CLK_FLL_CONFIG4 &= ~_VAL2FLD(SRSS_CLK_FLL_CONFIG4_CCO_ENABLE, 1u); /* 0 = disable */ - return CY_SYSCLK_SUCCESS; /* placeholder */ + return CY_SYSCLK_SUCCESS; } /** \} group_sysclk_fll_funcs */ @@ -897,7 +905,12 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PllDisable(uint32_t clkPath); * * \param clkPath Selects which PLL to check. 1 is the first PLL; 0 is invalid. * -* \return false = not locked, true = locked +* \return +* false = not locked
+* true = locked +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllLocked * *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_PllLocked(uint32_t clkPath) @@ -915,7 +928,12 @@ __STATIC_INLINE bool Cy_SysClk_PllLocked(uint32_t clkPath) * * \param clkPath Selects which PLL to check. 1 is the first PLL; 0 is invalid. * -* \return 0 = didn't lose lock, 1 = lost lock +* \return +* false = did not lose lock
+* true = lost lock +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllLostLock * *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_PllLostLock(uint32_t clkPath) @@ -942,6 +960,9 @@ __STATIC_INLINE bool Cy_SysClk_PllLostLock(uint32_t clkPath) * CY_SYSCLK_SUCCESS - PLL successfully disabled
* CY_SYSCLK_BAD_PARAM - invalid clock path number * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PllDisable +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PllDisable(uint32_t clkPath) { @@ -974,6 +995,10 @@ __STATIC_INLINE void Cy_SysClk_IloHibernateOn(bool on); * Enables the ILO. * * \note The watchdog timer (WDT) must be unlocked before calling this function. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_IloEnable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_IloEnable(void) { @@ -993,6 +1018,10 @@ __STATIC_INLINE void Cy_SysClk_IloEnable(void) * \note The watchdog timer (WDT) must be unlocked before calling this function. * Do not call this function if the WDT is enabled, because the WDT is clocked by * the ILO. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_IloDisable +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_IloDisable(void) { @@ -1013,10 +1042,14 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_IloDisable(void) * brown-out detect (BOD) event. * * \param on -* 1 = ILO stays on during hibernate or across XRES/BOD. 0 = ILO turns off for -* hibernate or XRES/BOD. +* true = ILO stays on during hibernate or across XRES/BOD.
+* false = ILO turns off for hibernate or XRES/BOD. * * \note Writes to the register/bit are ignored if the watchdog (WDT) is locked. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_IloHibernateOn +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_IloHibernateOn(bool on) { @@ -1041,10 +1074,14 @@ __STATIC_INLINE uint32_t Cy_SysClk_PiloGetTrim(void); * Function Name: Cy_SysClk_PiloEnable ****************************************************************************//** * -* Enables the PILO. +* Enables the PILO. +* +* \note This function blocks for 1 millisecond between enabling the PILO and +* releasing the PILO reset. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PiloEnable * -* \note Requires 1 msec, for delay between enabling the PILO and releasing the -* PILO reset. *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_PiloEnable(void) { @@ -1061,6 +1098,9 @@ __STATIC_INLINE void Cy_SysClk_PiloEnable(void) * * Disables the PILO. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PiloDisable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_PiloDisable(void) { @@ -1078,6 +1118,9 @@ __STATIC_INLINE void Cy_SysClk_PiloDisable(void) * Sets the PILO trim bits, which adjusts the PILO frequency. This is typically * done after measuring the PILO frequency; see \ref Cy_SysClk_StartClkMeasurementCounters(). * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PiloSetTrim +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_PiloSetTrim(uint32_t trimVal) { @@ -1090,6 +1133,9 @@ __STATIC_INLINE void Cy_SysClk_PiloSetTrim(uint32_t trimVal) * * Reports the current PILO trim bits value. * +* \funcusage +* Refer to the Cy_SysClk_PiloSetTrim() function usage. +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SysClk_PiloGetTrim(void) { @@ -1172,7 +1218,12 @@ uint32_t Cy_SysClk_ClkMeasurementCountersGetFreq(bool measuredClock, uint32_t re * Checks if clock measurement counting is done, that is, counter1 has counted down * to zero. Call \ref Cy_SysClk_StartClkMeasurementCounters() before calling this function. * -* \return Status of calibration counters: true if done, false if not. +* \return Status of calibration counters:
+* true = done
+* false = not done +* +* \funcusage +* Refer to the Cy_SysClk_StartClkMeasurementCounters() function usage. * *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_ClkMeasurementCountersDone(void) @@ -1265,10 +1316,10 @@ typedef enum */ typedef struct { - cy_en_wco_csv_supervisor_clock_t SupervisorClock; /**< supervisor clock selection */ + cy_en_wco_csv_supervisor_clock_t supervisorClock; /**< supervisor clock selection */ bool enableLossDetection; /**< 1= enabled, 0= disabled. Note that if loss detection is enabled, writes to other register bits are ignored. */ - cy_en_csv_loss_window_t LossWindow; /**< \ref cy_en_csv_loss_window_t */ - cy_en_csv_error_actions_t LossAction; /**< \ref cy_en_csv_error_actions_t */ + cy_en_csv_loss_window_t lossWindow; /**< \ref cy_en_csv_loss_window_t */ + cy_en_csv_error_actions_t lossAction; /**< \ref cy_en_csv_error_actions_t */ } cy_stc_wco_csv_config_t; /** \} group_sysclk_wco_structs */ @@ -1299,6 +1350,9 @@ __STATIC_INLINE void Cy_SysClk_WcoBypass(cy_en_wco_bypass_modes_t bypass); * CY_SYSCLK_SUCCESS - WCO successfully enabled
* CY_SYSCLK_TIMEOUT - Timeout waiting for WCO to stabilize * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_WcoEnable +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_WcoEnable(uint32_t timeoutus) { @@ -1326,7 +1380,12 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_WcoEnable(uint32_t timeoutus) * * Reports the status of the WCO_OK bit. * -* \return true = okay false = not okay +* \return +* true = okay
+* false = not okay +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_WcoOkay * *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_WcoOkay(void) @@ -1340,6 +1399,9 @@ __STATIC_INLINE bool Cy_SysClk_WcoOkay(void) * * Disables the WCO. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_WcoDisable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_WcoDisable(void) { @@ -1350,11 +1412,14 @@ __STATIC_INLINE void Cy_SysClk_WcoDisable(void) * Function Name: Cy_SysClk_WcoBypass ****************************************************************************//** * -* Sets whether the WCO is bypassed or not. If it is bypassed then a 32-kHz clock -* must be provided on the wco_in pin. +* Sets whether the WCO is bypassed or not. If it is bypassed, then a 32-kHz clock +* must be provided on the wco_out pin. * * \param bypass \ref cy_en_wco_bypass_modes_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_WcoBypass +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_WcoBypass(cy_en_wco_bypass_modes_t bypass) { @@ -1428,15 +1493,15 @@ typedef enum */ typedef struct { - cy_en_clkhf_csv_supervisor_clock_t SupervisorClock; /**< \ref cy_en_clkhf_csv_supervisor_clock_t */ - uint16_t SupervisingWindow; /**< Number of supervising clock cycles */ + cy_en_clkhf_csv_supervisor_clock_t supervisorClock; /**< \ref cy_en_clkhf_csv_supervisor_clock_t */ + uint16_t supervisingWindow; /**< Number of supervising clock cycles */ bool enableFrequencyFaultDetection; /**< 1= enabled, 0= disabled */ - uint16_t FrequencyLowerLimit; /**< Lowest frequency in kHz that supervised clock can go */ - uint16_t FrequencyUpperLimit; /**< Highest frequency in kHz that supervised clock can go */ - cy_en_csv_error_actions_t FrequencyAction; /**< \ref cy_en_csv_error_actions_t */ + uint16_t frequencyLowerLimit; /**< Lowest frequency in kHz that supervised clock can go */ + uint16_t frequencyUpperLimit; /**< Highest frequency in kHz that supervised clock can go */ + cy_en_csv_error_actions_t frequencyAction; /**< \ref cy_en_csv_error_actions_t */ bool enableLossDetection; /**< 1= enabled, 0= disabled */ - cy_en_csv_loss_window_t LossWindow; /**< \ref cy_en_csv_loss_window_t */ - cy_en_csv_error_actions_t LossAction; /**< \ref cy_en_csv_error_actions_t */ + cy_en_csv_loss_window_t lossWindow; /**< \ref cy_en_csv_loss_window_t */ + cy_en_csv_error_actions_t lossAction; /**< \ref cy_en_csv_error_actions_t */ } cy_stc_clkhf_csv_config_t; /** \} group_sysclk_clk_hf_structs */ @@ -1465,6 +1530,9 @@ __STATIC_INLINE cy_en_clkhf_dividers_t Cy_SysClk_ClkHfGetDivider(uint32_t clkHf) * * \return \ref cy_en_sysclk_status_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkHfEnable +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfEnable(uint32_t clkHf) { @@ -1488,6 +1556,10 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfEnable(uint32_t clkHf) * \return \ref cy_en_sysclk_status_t * * \note clkHf[0] cannot be disabled. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkHfDisable +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfDisable(uint32_t clkHf) { @@ -1506,12 +1578,15 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfDisable(uint32_t clkHf) * * Selects the source of the selected clkHf. * -* \param clkHf Which clkHf mux to configure. +* \param clkHf selects which clkHf mux to configure. * * \param source \ref cy_en_clkhf_in_sources_t * * \return \ref cy_en_sysclk_status_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkHfSetSource +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfSetSource(uint32_t clkHf, cy_en_clkhf_in_sources_t source) { @@ -1534,6 +1609,9 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfSetSource(uint32_t clkHf, c * * \return \ref cy_en_clkhf_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkHfSetSource +* *******************************************************************************/ __STATIC_INLINE cy_en_clkhf_in_sources_t Cy_SysClk_ClkHfGetSource(uint32_t clkHf) { @@ -1554,6 +1632,10 @@ __STATIC_INLINE cy_en_clkhf_in_sources_t Cy_SysClk_ClkHfGetSource(uint32_t clkHf * \return \ref cy_en_sysclk_status_t * * \note Also call \ref Cy_SysClk_ClkHfSetSource to set the clkHf source. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkHfSetDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfSetDivider(uint32_t clkHf, cy_en_clkhf_dividers_t divider) { @@ -1576,6 +1658,9 @@ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_ClkHfSetDivider(uint32_t clkHf, * * \return \ref cy_en_clkhf_dividers_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkHfSetDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_clkhf_dividers_t Cy_SysClk_ClkHfGetDivider(uint32_t clkHf) { @@ -1605,6 +1690,9 @@ __STATIC_INLINE uint8_t Cy_SysClk_ClkFastGetDivider(void); * \param divider divider value between 0 and 255. * Causes integer division of (divider value + 1), or division by 1 to 256. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkFastSetDivider +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkFastSetDivider(uint8_t divider) { @@ -1620,6 +1708,9 @@ __STATIC_INLINE void Cy_SysClk_ClkFastSetDivider(uint8_t divider) * \return The divider value for the fast clock. * The integer division done is by (divider value + 1), or division by 1 to 256. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkFastSetDivider +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_SysClk_ClkFastGetDivider(void) { @@ -1649,6 +1740,9 @@ __STATIC_INLINE uint8_t Cy_SysClk_ClkPeriGetDivider(void); * \param divider divider value between 0 and 255 * Causes integer division of (divider value + 1), or division by 1 to 256. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPeriSetDivider +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkPeriSetDivider(uint8_t divider) { @@ -1664,6 +1758,9 @@ __STATIC_INLINE void Cy_SysClk_ClkPeriSetDivider(uint8_t divider) * \return The divider value. * The integer division done is by (divider value + 1), or division by 1 to 256. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPeriSetDivider +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_SysClk_ClkPeriGetDivider(void) { @@ -1722,6 +1819,9 @@ uint32_t Cy_SysClk_PeriphGetFrequency(cy_en_divider_types_t dividerType, uint32_ * * \return \ref cy_en_sysclk_status_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphSetDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PeriphSetDivider(cy_en_divider_types_t dividerType, @@ -1768,6 +1868,9 @@ __STATIC_INLINE cy_en_sysclk_status_t * The integer division done is by (divider value + 1), or division by 1 to 256 * (8-bit divider) or 1 to 65536 (16-bit divider). * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphSetDivider +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SysClk_PeriphGetDivider(cy_en_divider_types_t dividerType, uint32_t dividerNum) { @@ -1810,6 +1913,9 @@ __STATIC_INLINE uint32_t Cy_SysClk_PeriphGetDivider(cy_en_divider_types_t divide * * \return \ref cy_en_sysclk_status_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphSetFracDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PeriphSetFracDivider(cy_en_divider_types_t dividerType, uint32_t dividerNum, @@ -1860,6 +1966,9 @@ __STATIC_INLINE cy_en_sysclk_status_t * * \return None. Loads pointed-to variables. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphSetFracDivider +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_PeriphGetFracDivider(cy_en_divider_types_t dividerType, uint32_t dividerNum, uint32_t *dividerIntValue, uint32_t *dividerFracValue) @@ -1895,6 +2004,9 @@ __STATIC_INLINE void Cy_SysClk_PeriphGetFracDivider(cy_en_divider_types_t divide * * \return \ref cy_en_sysclk_status_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphAssignDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PeriphAssignDivider(en_clk_dst_t ipBlock, @@ -1927,6 +2039,9 @@ __STATIC_INLINE cy_en_sysclk_status_t * \return The divider type and number, where bits [7:6] = type, bits[5:0] = divider * number within that type * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphAssignDivider +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_SysClk_PeriphGetAssignedDivider(en_clk_dst_t ipBlock) { @@ -1947,6 +2062,10 @@ __STATIC_INLINE uint32_t Cy_SysClk_PeriphGetAssignedDivider(en_clk_dst_t ipBlock * \note This function also sets the phase alignment bits such that the enabled * divider is aligned to clk_peri. See \ref Cy_SysClk_PeriphDisableDivider() * for information on how to phase-align a divider after it is enabled. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphEnableDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PeriphEnableDivider(cy_en_divider_types_t dividerType, uint32_t dividerNum) @@ -1976,20 +2095,15 @@ __STATIC_INLINE cy_en_sysclk_status_t * Function Name: Cy_SysClk_PeriphDisableDivider ****************************************************************************//** * -* Disables a selected divider, preparatory to aligning it with another divider; -* see \ref Cy_SysClk_PeriphEnablePhaseAlignDivider. +* Disables a selected divider. * * \param dividerType specifies which type of divider to use; \ref cy_en_divider_types_t. * * \param dividerNum specifies which divider of the selected type to configure. * -* \note -* To phase-align a divider, do the following:
-* 1. Call this function.
-* 2. Call the appropriate Cy_SysClk_PeriphSet...Divider function to configure the -* divider.
-* 3. Call \ref Cy_SysClk_PeriphEnablePhaseAlignDivider to enable the divider and do -* the phase alignment. +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphDisableDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PeriphDisableDivider(cy_en_divider_types_t dividerType, uint32_t dividerNum) @@ -2018,7 +2132,8 @@ __STATIC_INLINE cy_en_sysclk_status_t * * First disables a selected divider (\ref Cy_SysClk_PeriphDisableDivider), * then aligns that divider to another programmable divider, and enables the -* selected divider. +* selected divider. The divider to align to must already be enabled in order +* to align a divider to it. * * \param dividerType specifies which type of divider to use; \ref cy_en_divider_types_t. * @@ -2031,6 +2146,10 @@ __STATIC_INLINE cy_en_sysclk_status_t * \note * To phase-align a divider to clk_peri, set dividerTypePA to 3 and dividerNumPA * to 63. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphEnablePhaseAlignDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_PeriphEnablePhaseAlignDivider(cy_en_divider_types_t dividerType, uint32_t dividerNum, @@ -2072,7 +2191,13 @@ __STATIC_INLINE cy_en_sysclk_status_t * * \param dividerNum specifies which divider of the selected type to configure. * -* \return The enabled/disabled state; 0 = disabled, 1 = enabled. +* \return The enabled/disabled state;
+* false = disabled
+* true = enabled +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_PeriphGetDividerEnabled +* *******************************************************************************/ __STATIC_INLINE bool Cy_SysClk_PeriphGetDividerEnabled(cy_en_divider_types_t dividerType, uint32_t dividerNum) { @@ -2125,6 +2250,9 @@ __STATIC_INLINE uint8_t Cy_SysClk_ClkSlowGetDivider(void); * \param divider Divider value between 0 and 255. * Causes integer division of (divider value + 1), or division by 1 to 256. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkSlowSetDivider +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkSlowSetDivider(uint8_t divider) { @@ -2140,6 +2268,9 @@ __STATIC_INLINE void Cy_SysClk_ClkSlowSetDivider(uint8_t divider) * \return The divider value. * The integer division done is by (divider value + 1), or division by 1 to 256. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkSlowSetDivider +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_SysClk_ClkSlowGetDivider(void) { @@ -2184,6 +2315,10 @@ __STATIC_INLINE cy_en_clklf_in_sources_t Cy_SysClk_ClkLfGetSource(void); * \param source \ref cy_en_clklf_in_sources_t * * \note The watchdog timer (WDT) must be unlocked before calling this function. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkLfSetSource +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkLfSetSource(cy_en_clklf_in_sources_t source) { @@ -2199,6 +2334,9 @@ __STATIC_INLINE void Cy_SysClk_ClkLfSetSource(cy_en_clklf_in_sources_t source) * * \return \ref cy_en_clklf_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkLfSetSource +* *******************************************************************************/ __STATIC_INLINE cy_en_clklf_in_sources_t Cy_SysClk_ClkLfGetSource(void) { @@ -2245,10 +2383,14 @@ __STATIC_INLINE void Cy_SysClk_ClkTimerDisable(void); ****************************************************************************//** * * Sets the source for the timer clock (clk_timer). The timer clock can be used -* as a source for SYSTICK and one or more of the energy profiler counters. +* as a source for SYSTICK as an alternate clock and one or more of the energy +* profiler counters. * * \param source \ref cy_en_clktimer_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkTimerSetSource +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkTimerSetSource(cy_en_clktimer_in_sources_t source) { @@ -2267,6 +2409,9 @@ __STATIC_INLINE void Cy_SysClk_ClkTimerSetSource(cy_en_clktimer_in_sources_t sou * * \return \ref cy_en_clktimer_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkTimerSetSource +* *******************************************************************************/ __STATIC_INLINE cy_en_clktimer_in_sources_t Cy_SysClk_ClkTimerGetSource(void) { @@ -2286,6 +2431,10 @@ __STATIC_INLINE cy_en_clktimer_in_sources_t Cy_SysClk_ClkTimerGetSource(void) * * \note * Do not change the divider value while the timer clock is enabled. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkTimerSetDivider +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkTimerSetDivider(uint8_t divider) { @@ -2300,6 +2449,9 @@ __STATIC_INLINE void Cy_SysClk_ClkTimerSetDivider(uint8_t divider) * * \return The divider value * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkTimerSetDivider +* *******************************************************************************/ __STATIC_INLINE uint8_t Cy_SysClk_ClkTimerGetDivider(void) { @@ -2313,6 +2465,9 @@ __STATIC_INLINE uint8_t Cy_SysClk_ClkTimerGetDivider(void) * Enables the timer clock (clk_timer). The timer clock can be used as a source * for SYSTICK and one or more of the energy profiler counters. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkTimerEnable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkTimerEnable(void) { @@ -2325,6 +2480,9 @@ __STATIC_INLINE void Cy_SysClk_ClkTimerEnable(void) * * Disables the timer clock (clk_timer). * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkTimerDisable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkTimerDisable(void) { @@ -2402,6 +2560,10 @@ __STATIC_INLINE void Cy_SysClk_ClkPumpDisable(void); * * \note * Do not change the source while the pump clock is enabled. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPumpSetSource +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkPumpSetSource(cy_en_clkpump_in_sources_t source) { @@ -2417,6 +2579,9 @@ __STATIC_INLINE void Cy_SysClk_ClkPumpSetSource(cy_en_clkpump_in_sources_t sourc * * \return \ref cy_en_clkpump_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPumpSetSource +* *******************************************************************************/ __STATIC_INLINE cy_en_clkpump_in_sources_t Cy_SysClk_ClkPumpGetSource(void) { @@ -2433,6 +2598,10 @@ __STATIC_INLINE cy_en_clkpump_in_sources_t Cy_SysClk_ClkPumpGetSource(void) * * \note * Do not change the divider value while the pump clock is enabled. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPumpSetDivider +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkPumpSetDivider(cy_en_clkpump_divide_t divider) { @@ -2448,6 +2617,9 @@ __STATIC_INLINE void Cy_SysClk_ClkPumpSetDivider(cy_en_clkpump_divide_t divider) * * \return \ref cy_en_clkpump_divide_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPumpSetDivider +* *******************************************************************************/ __STATIC_INLINE cy_en_clkpump_divide_t Cy_SysClk_ClkPumpGetDivider(void) { @@ -2461,6 +2633,9 @@ __STATIC_INLINE cy_en_clkpump_divide_t Cy_SysClk_ClkPumpGetDivider(void) * Enables the pump clock (clk_pump). The pump clock can be used for the analog * pumps in the CTBm block. * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPumpEnable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkPumpEnable(void) { @@ -2473,6 +2648,9 @@ __STATIC_INLINE void Cy_SysClk_ClkPumpEnable(void) * * Disables the pump clock (clk_pump). * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkPumpDisable +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkPumpDisable(void) { @@ -2519,6 +2697,10 @@ __STATIC_INLINE cy_en_clkbak_in_sources_t Cy_SysClk_ClkBakGetSource(void); * clkLf is not available in all power modes. For this reason, WCO is the * preferred source. If the WCO is routed through the clkLf multiplexer * (see \ref Cy_SysClk_ClkLfSetSource), select WCO directly - do not select clkLf. +* +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkBakSetSource +* *******************************************************************************/ __STATIC_INLINE void Cy_SysClk_ClkBakSetSource(cy_en_clkbak_in_sources_t source) { @@ -2534,6 +2716,9 @@ __STATIC_INLINE void Cy_SysClk_ClkBakSetSource(cy_en_clkbak_in_sources_t source) * * \return \ref cy_en_clkbak_in_sources_t * +* \funcusage +* \snippet sysclk/sysclk_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysClk_ClkBakSetSource +* *******************************************************************************/ __STATIC_INLINE cy_en_clkbak_in_sources_t Cy_SysClk_ClkBakGetSource(void) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysint/cy_sysint.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysint/cy_sysint.c similarity index 80% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysint/cy_sysint.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysint/cy_sysint.c index d896db13e4..09c183c11e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysint/cy_sysint.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysint/cy_sysint.c @@ -1,5 +1,5 @@ /***************************************************************************//** -* \file +* \file cy_sysint.c * \version 1.10 * * \brief @@ -7,7 +7,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -25,10 +25,12 @@ extern "C" { ****************************************************************************//** * * \brief Initializes the referenced interrupt by setting the priority and the -* interrupt vector. Note that the interrupt vector will only be relocated if the -* vector table was moved to __ramVectors in SRAM. Otherwise it is ignored. +* interrupt vector. * -* Use the CMSIS core function NVIC_EnableIRQ(config.intrSrc) to enable it. +* Note that the interrupt vector will only be relocated if the vector table was +* moved to __ramVectors in SRAM. Otherwise it is ignored. +* +* Use the CMSIS core function NVIC_EnableIRQ(config.intrSrc) to enable the interrupt. * * \param config * Interrupt configuration structure @@ -39,6 +41,9 @@ extern "C" { * \return * Initialization status * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_Init +* *******************************************************************************/ cy_en_sysint_status_t Cy_SysInt_Init(const cy_stc_sysint_t* config, cy_israddress userIsr) { @@ -46,25 +51,23 @@ cy_en_sysint_status_t Cy_SysInt_Init(const cy_stc_sysint_t* config, cy_israddres if(NULL != config) { + CY_ASSERT_L3(CY_SYSINT_IS_PRIORITY_VALID(config->intrPriority)); + #if (CY_CPU_CORTEX_M0P) - if (config->intrSrc < 0) - { - NVIC_SetPriority(config->intrSrc, config->intrPriority); - } - else + if (config->intrSrc > SysTick_IRQn) { /* Configure the interrupt mux */ Cy_SysInt_SetIntSource(config->intrSrc, config->cm0pSrc); - NVIC_SetPriority(config->intrSrc, config->intrPriority); } - #else - /* Set the priority */ - NVIC_SetPriority(config->intrSrc, config->intrPriority); #endif + NVIC_SetPriority(config->intrSrc, config->intrPriority); + /* Only set the new vector if it was moved to __ramVectors */ if (SCB->VTOR == (uint32_t)&__ramVectors) { + CY_ASSERT_L1(CY_SYSINT_IS_VECTOR_VALID(userIsr)); + (void)Cy_SysInt_SetVector(config->intrSrc, userIsr); } } @@ -77,7 +80,7 @@ cy_en_sysint_status_t Cy_SysInt_Init(const cy_stc_sysint_t* config, cy_israddres } -#if CY_CPU_CORTEX_M0P || defined (CY_DOXYGEN) +#if (CY_CPU_CORTEX_M0P) || defined (CY_DOXYGEN) /******************************************************************************* * Function Name: Cy_SysInt_SetIntSource @@ -94,15 +97,18 @@ cy_en_sysint_status_t Cy_SysInt_Init(const cy_stc_sysint_t* config, cy_israddres * \param cm0pSrc * Device interrupt to be routed to the NVIC mux * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SetIntSource +* *******************************************************************************/ void Cy_SysInt_SetIntSource(IRQn_Type intrSrc, cy_en_intr_t cm0pSrc) { /* Calculation of variables and masks */ uint32_t regPos = (uint32_t)intrSrc >> CY_SYSINT_CM0P_MUX_SHIFT; - uint32_t bitPos = ((uint32_t)intrSrc - (regPos << CY_SYSINT_CM0P_MUX_SHIFT)) << CY_SYSINT_CM0P_MUX_SCALE; + uint32_t bitPos = ((uint32_t)intrSrc - (uint32_t)(regPos << CY_SYSINT_CM0P_MUX_SHIFT)) << CY_SYSINT_CM0P_MUX_SCALE; uint32_t bitMask = (uint32_t)(CY_SYSINT_CM0P_MUX_MASK << bitPos); uint32_t bitMaskClr = (uint32_t)(~bitMask); - uint32_t bitMaskSet = ((cm0pSrc << bitPos) & bitMask); + uint32_t bitMaskSet = (((uint32_t)cm0pSrc << bitPos) & bitMask); uint32_t tempReg; @@ -159,6 +165,9 @@ void Cy_SysInt_SetIntSource(IRQn_Type intrSrc, cy_en_intr_t cm0pSrc) * Device interrupt source connected to the NVIC mux. A returned value of * "disconnected_IRQn" (240) indicates that the interrupt source is disconnected. * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SetIntSource +* *******************************************************************************/ cy_en_intr_t Cy_SysInt_GetIntSource(IRQn_Type intrSrc) { @@ -167,39 +176,41 @@ cy_en_intr_t Cy_SysInt_GetIntSource(IRQn_Type intrSrc) uint32_t bitPos = ((uint32_t)intrSrc - (regPos << CY_SYSINT_CM0P_MUX_SHIFT)) << CY_SYSINT_CM0P_MUX_SCALE; uint32_t bitMask = (uint32_t)(CY_SYSINT_CM0P_MUX_MASK << bitPos); - cy_en_intr_t tempReg; - + cy_en_intr_t srcVal = disconnected_IRQn; + uint32_t tempReg = 0UL; + switch(regPos) { case CY_SYSINT_CM0P_MUX0: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL0 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL0 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX1: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL1 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL1 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX2: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL2 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL2 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX3: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL3 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL3 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX4: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL4 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL4 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX5: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL5 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL5 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX6: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL6 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL6 & bitMask) >> bitPos; break; case CY_SYSINT_CM0P_MUX7: - tempReg = (cy_en_intr_t)((CPUSS->CM0_INT_CTL7 & bitMask) >> bitPos); + tempReg = (CPUSS->CM0_INT_CTL7 & bitMask) >> bitPos; break; default: - tempReg = (cy_en_intr_t)CY_SYSINT_CM0P_MUX_ERROR; break; } - return tempReg; + + srcVal = (cy_en_intr_t)tempReg; + return (srcVal); } #endif @@ -227,6 +238,9 @@ cy_en_intr_t Cy_SysInt_GetIntSource(IRQn_Type intrSrc) * Previous address of the ISR in the interrupt vector table, before the * function call * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SetVector +* *******************************************************************************/ cy_israddress Cy_SysInt_SetVector(IRQn_Type intrSrc, cy_israddress userIsr) { @@ -235,6 +249,8 @@ cy_israddress Cy_SysInt_SetVector(IRQn_Type intrSrc, cy_israddress userIsr) /* Only set the new vector if it was moved to __ramVectors */ if (SCB->VTOR == (uint32_t)&__ramVectors) { + CY_ASSERT_L1(CY_SYSINT_IS_VECTOR_VALID(userIsr)); + prevIsr = __ramVectors[CY_INT_IRQ_BASE + intrSrc]; __ramVectors[CY_INT_IRQ_BASE + intrSrc] = userIsr; } @@ -265,6 +281,9 @@ cy_israddress Cy_SysInt_SetVector(IRQn_Type intrSrc, cy_israddress userIsr) * \return * Address of the ISR in the interrupt vector table * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SetVector +* *******************************************************************************/ cy_israddress Cy_SysInt_GetVector(IRQn_Type intrSrc) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysint/cy_sysint.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysint/cy_sysint.h similarity index 88% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysint/cy_sysint.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysint/cy_sysint.h index 4abf7911c5..c16d2a0e4c 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/sysint/cy_sysint.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/sysint/cy_sysint.h @@ -7,7 +7,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -23,8 +23,9 @@ * be used to configure and connect device peripheral interrupts to one or more * cores. * -* \n -* Initialization +* \section group_sysint_driver_usage Driver Usage +* +* \subsection group_sysint_initialization Initialization * * Interrupt numbers are defined in a device-specific header file, such as * cy8c68237bz_ble.h. @@ -48,18 +49,17 @@ * to a deep-sleep capable IRQn channel. Otherwise it won't work. The device * header file identifies which IRQn channels are deep-sleep capable. * -* \n -* Enable +* \subsection group_sysint_enable Enable * * After initializing an interrupt, use the CMSIS Core * NVIC_EnableIRQ() function * to enable it. Given an initialization structure named config, * the function should be called as follows: -* +* \code * NVIC_EnableIRQ(config.intrSrc) +* \endcode * -* \n -* Writing an interrupt service routine +* \subsection group_sysint_service Writing an interrupt service routine * * Servicing interrupts in the Peripheral Drivers should follow a prescribed * recipe to ensure all interrupts are serviced and duplicate interrupts are not @@ -94,6 +94,12 @@ * must be connected to one of these muxes to be able to trigger in deep-sleep. * Refer to the IRQn_Type definition in the device header. * +* The default interrupt handler functions are defined as weak functions in the +* startup file. Defining these in the user application will allow the linker to +* place them in the Flash vector table. This avoids the need for a RAM vector table. +* However in this scenario, interrupt handler re-location at run-time is not possible, +* unless the vector table is relocated to RAM. +* * \section group_sysint_more_information More Information * * Refer to the technical reference manual (TRM) and the device datasheet. @@ -126,13 +132,13 @@ *
VersionChangesReason for Change
1.10.1Renamed Power Management section to Low Power Callback sectionDocumentation update and clarification
1.10Updated FLL parameter calculationSupport low frequency sources
Added Cy_SysClk_PiloSetTrim() and Cy_SysclkPiloGetTrim() functionsSupport PILO manual trims
Made Cy_SysClk_FllLostLock() function dependent on SRSS v1Feature is not supported in SRSS v1
Updated Cy_SysClk_DeepSleepCallback() to save/restore both FLL and PLL settingsThe function should return when the lock is established or a timeout has occurred
General documentation updates
1.0Initial version
* * -* -* +* +* * * * -* -* +* +* * * *
VersionChangesReason for Change
1.0Initial version1.10Cy_SysInt_GetState() function is redefined to call NVIC_GetEnableIRQ().
1.10Cy_SysInt_GetState() function is redefined to call NVIC_GetEnableIRQ().1.0Initial version
@@ -140,7 +146,7 @@ * \defgroup group_sysint_macros Macros * \defgroup group_sysint_globals Global variables * \defgroup group_sysint_functions Functions -* \defgroup group_sysint_data_structures Data structures +* \defgroup group_sysint_data_structures Data Structures * \defgroup group_sysint_enums Enumerated Types */ @@ -259,7 +265,9 @@ typedef struct { #define CY_SYSINT_CM0P_MUX6 (6u) /**< CM0+ NVIC multiplexer register 6 */ #define CY_SYSINT_CM0P_MUX7 (7u) /**< CM0+ NVIC multiplexer register 7 */ -#define CY_SYSINT_CM0P_MUX_ERROR (0xfffffffful) /**< Invalid CM0+ NVIC multiplexer error code */ +/* Parameter validation macros */ +#define CY_SYSINT_IS_PRIORITY_VALID(intrPriority) ((uint32_t)(1UL << __NVIC_PRIO_BITS) > (intrPriority)) +#define CY_SYSINT_IS_VECTOR_VALID(userIsr) (NULL != (userIsr)) /** \endcond */ @@ -277,7 +285,7 @@ cy_israddress Cy_SysInt_SetVector(IRQn_Type intrSrc, cy_israddress userIsr); cy_israddress Cy_SysInt_GetVector(IRQn_Type intrSrc); __STATIC_INLINE void Cy_SysInt_SetIntSourceNMI(IRQn_Type intrSrc); __STATIC_INLINE IRQn_Type Cy_SysInt_GetIntSourceNMI(void); -#if (CY_CPU_CORTEX_M0P) +#if (CY_CPU_CORTEX_M0P) || defined (CY_DOXYGEN) void Cy_SysInt_SetIntSource(IRQn_Type intrSrc, cy_en_intr_t cm0pSrc); cy_en_intr_t Cy_SysInt_GetIntSource(IRQn_Type intrSrc); #else @@ -285,16 +293,6 @@ __STATIC_INLINE IRQn_Type Cy_SysInt_GetIntSourceNMI(void); #endif -/******************************************************************************* -* Function Name: Cy_SysInt_GetState -****************************************************************************//** -* -* Invokes the NVIC_GetEnableIRQ NVIC function. -* -*******************************************************************************/ -#define Cy_SysInt_GetState NVIC_GetEnableIRQ - - /******************************************************************************* * Function Name: Cy_SysInt_SetIntSourceNMI ****************************************************************************//** @@ -304,12 +302,17 @@ __STATIC_INLINE IRQn_Type Cy_SysInt_GetIntSourceNMI(void); * The interrupt source must be a positive number. Setting the value to * "unconnected_IRQn" (240) disconnects the interrupt source from the NMI. * -* Note that for CM0+, this function sets the interrupt mux output feeding into -* the NVIC as the source for the NMI. -* * \param intrSrc * Interrupt source * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SetIntSourceNMI +* +* \note The CM0+ NMI is used for performing system calls that execute out of ROM. +* Hence modification of the NMI source is strongly discouraged. However if it +* must be updated, the NMI source must be provided from the cy_en_intr_t enum +* as it is a direct connection to the interrupt source. +* *******************************************************************************/ __STATIC_INLINE void Cy_SysInt_SetIntSourceNMI(IRQn_Type intrSrc) { @@ -331,6 +334,9 @@ __STATIC_INLINE void Cy_SysInt_SetIntSourceNMI(IRQn_Type intrSrc) * Interrupt Source. A value of "unconnected_IRQn" (240) means that there is no * interrupt source for the NMI, and it can be only be triggered through software. * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SetIntSourceNMI +* *******************************************************************************/ __STATIC_INLINE IRQn_Type Cy_SysInt_GetIntSourceNMI(void) { @@ -350,12 +356,15 @@ __STATIC_INLINE IRQn_Type Cy_SysInt_GetIntSourceNMI(void) * * \brief Triggers an interrupt using software (Not applicable for CM0+). * -* Note Only privileged software can enable unprivileged access to the -* Software Trigger Interrupt Register (STIR). -* * \param intrSrc * Interrupt source * +* \funcusage +* \snippet sysint/sysint_v1_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysInt_SoftwareTrig +* +* \note Only privileged software can enable unprivileged access to the +* Software Trigger Interrupt Register (STIR). +* *******************************************************************************/ __STATIC_INLINE void Cy_SysInt_SoftwareTrig(IRQn_Type intrSrc) { @@ -364,6 +373,15 @@ __STATIC_INLINE void Cy_SysInt_SoftwareTrig(IRQn_Type intrSrc) #endif +/******************************************************************************* +* Function Name: Cy_SysInt_GetState +****************************************************************************//** +* +* This function is deprecated. It invokes the NVIC_GetEnableIRQ function. +* +*******************************************************************************/ +#define Cy_SysInt_GetState NVIC_GetEnableIRQ + /** \} group_sysint_functions */ #if defined(__cplusplus) diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_ARM_STD/cy_syslib_mdk.s b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_ARM_STD/cy_syslib_mdk.s similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_ARM_STD/cy_syslib_mdk.s rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_ARM_STD/cy_syslib_mdk.s index dbf9ce26c9..6b82f72022 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_ARM_STD/cy_syslib_mdk.s +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_ARM_STD/cy_syslib_mdk.s @@ -1,11 +1,11 @@ ;------------------------------------------------------------------------------- ; \file CyBootAsmRv.s -; \version 2.0 +; \version 2.0.1 ; ; \brief Assembly routines for RealView. ; ;------------------------------------------------------------------------------- -; Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +; Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. ; You may use this file only in accordance with the license, terms, conditions, ; disclaimers, and limitations in the end user license agreement accompanying ; the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S index 1103acbdad..3b65b1c576 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_syslib_core_armcc.s -* \version 2.0 +* \version 2.0.1 * * \brief Assembly routines for GNU as. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_IAR/cy_syslib_iar.s b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_IAR/cy_syslib_iar.s similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_IAR/cy_syslib_iar.s rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_IAR/cy_syslib_iar.s index f2ef3682e2..8d4fc8c422 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/TOOLCHAIN_IAR/cy_syslib_iar.s +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/TOOLCHAIN_IAR/cy_syslib_iar.s @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_syslib_iar.s -* \version 2.0 +* \version 2.0.1 * * \brief Assembly routines for IAR Embedded Workbench IDE. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/cy_syslib.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/cy_syslib.c similarity index 73% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/cy_syslib.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/cy_syslib.c index fdd12f3d2b..e7629d5748 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/cy_syslib.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/cy_syslib.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_syslib.c -* \version 2.0 +* \version 2.0.1 * * Description: -* Provides system API implementation for the syslib driver. +* Provides system API implementation for the SysLib driver. * ******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -30,33 +30,13 @@ #define CY_SYSLIB_FLASH_ULP_WS_1_FREQ_MAX ( 33UL) #define CY_SYSLIB_FLASH_ULP_WS_2_FREQ_MAX ( 50UL) -/* ROM wait states for the slow clock domain (LP mode at 1.1v) */ -#define CY_SYSLIB_ROM_LP_SLOW_WS_0_FREQ_MAX (100UL) -#define CY_SYSLIB_ROM_LP_SLOW_WS_1_FREQ_MAX (120UL) +/* ROM and SRAM wait states for the slow clock domain (LP mode at 1.1v) */ +#define CY_SYSLIB_LP_SLOW_WS_0_FREQ_MAX (100UL) +#define CY_SYSLIB_LP_SLOW_WS_1_FREQ_MAX (120UL) -/* ROM wait states for the slow clock domain (ULP mode at 0.9v) */ -#define CY_SYSLIB_ROM_ULP_SLOW_WS_0_FREQ_MAX ( 25UL) -#define CY_SYSLIB_ROM_ULP_SLOW_WS_1_FREQ_MAX ( 50UL) - -/* ROM wait states for the fast clock domain (LP mode at 1.1v) */ -#define CY_SYSLIB_ROM_LP_FAST_WS_0_FREQ_MAX (120UL) - -/* ROM wait states for the slow clock domain (ULP mode at 0.9v) */ -#define CY_SYSLIB_ROM_ULP_FAST_WS_0_FREQ_MAX ( 50UL) - -/* SRAM wait states for the slow clock domain (LP mode at 1.1v) */ -#define CY_SYSLIB_RAM_LP_SLOW_WS_0_FREQ_MAX (100UL) -#define CY_SYSLIB_RAM_LP_SLOW_WS_1_FREQ_MAX (120UL) - -/* SRAM wait states for the slow clock domain (ULP mode at 0.9v) */ -#define CY_SYSLIB_RAM_ULP_SLOW_WS_0_FREQ_MAX ( 25UL) -#define CY_SYSLIB_RAM_ULP_SLOW_WS_1_FREQ_MAX ( 50UL) - -/* SRAM wait states for the fast clock domain (LP mode at 1.1v) */ -#define CY_SYSLIB_RAM_LP_FAST_WS_0_FREQ_MAX (120UL) - -/* SRAM wait states for the fast clock domain (ULP mode at 0.9v) */ -#define CY_SYSLIB_RAM_ULP_FAST_WS_0_FREQ_MAX ( 50UL) +/* ROM and SRAM wait states for the slow clock domain (ULP mode at 0.9v) */ +#define CY_SYSLIB_ULP_SLOW_WS_0_FREQ_MAX ( 25UL) +#define CY_SYSLIB_ULP_SLOW_WS_1_FREQ_MAX ( 50UL) #if !defined(NDEBUG) @@ -68,9 +48,6 @@ CY_NOINIT cy_stc_fault_frame_t cy_faultFrame; #endif /* (CY_ARM_FAULT_DEBUG == CY_ARM_FAULT_DEBUG_ENABLED) */ -static void Cy_SysLib_SetWaitStates_ULP(uint32_t clkHfMHz); -static void Cy_SysLib_SetWaitStates_LP(uint32_t clkHfMHz); - #if defined(__ARMCC_VERSION) static __ASM void Cy_SysLib_AsmInfiniteLoop(void) { b . }; #endif /* (__ARMCC_VERSION) */ @@ -156,7 +133,7 @@ void Cy_SysLib_DelayUs(uint16_t microseconds) *******************************************************************************/ __NO_RETURN void Cy_SysLib_Halt(uint32_t reason) { - if(0u != reason) + if(0U != reason) { /* To remove an unreferenced local variable warning */ } @@ -281,16 +258,16 @@ cy_en_syslib_status_t Cy_SysLib_ResetBackupDomain(void) *******************************************************************************/ uint32_t Cy_SysLib_GetResetReason(void) { - uint32_t retVal; + uint32_t retVal = SRSS->RES_CAUSE; - retVal = SRSS->RES_CAUSE; +#if (SRSS_WCOCSV_PRESENT != 0U) + uint32_t resCause2 = SRSS->RES_CAUSE2; -#if (SRSS_WCOCSV_PRESENT != 0u) - retVal |= ((CY_LO16(SRSS->RES_CAUSE2) > 0u) ? CY_SYSLIB_RESET_HFCLK_LOSS : 0u) | - ((CY_HI16(SRSS->RES_CAUSE2) > 0u) ? CY_SYSLIB_RESET_HFCLK_ERR : 0u); -#endif /* (SRSS_WCOCSV_PRESENT != 0u) */ + retVal |= ((CY_LO16(resCause2) > 0U) ? CY_SYSLIB_RESET_HFCLK_LOSS : 0U) | + ((CY_HI16(resCause2) > 0U) ? CY_SYSLIB_RESET_HFCLK_ERR : 0U); +#endif /* (SRSS_WCOCSV_PRESENT != 0U) */ - if(0u != _FLD2VAL(SRSS_PWR_HIBERNATE_TOKEN, SRSS->PWR_HIBERNATE)) + if(0U != _FLD2VAL(SRSS_PWR_HIBERNATE_TOKEN, SRSS->PWR_HIBERNATE)) { retVal |= CY_SYSLIB_RESET_HIB_WAKEUP; } @@ -299,7 +276,7 @@ uint32_t Cy_SysLib_GetResetReason(void) } -#if (SRSS_WCOCSV_PRESENT != 0u) || defined(CY_DOXYGEN) +#if (SRSS_WCOCSV_PRESENT != 0U) || defined(CY_DOXYGEN) /******************************************************************************* * Function Name: Cy_SysLib_GetNumHfclkResetCause ****************************************************************************//** @@ -322,7 +299,7 @@ uint32_t Cy_SysLib_GetNumHfclkResetCause(void) { return (SRSS->RES_CAUSE2); } -#endif /* (SRSS_WCOCSV_PRESENT != 0u) || defined(CY_DOXYGEN) */ +#endif /* (SRSS_WCOCSV_PRESENT != 0U) || defined(CY_DOXYGEN) */ /******************************************************************************* @@ -338,10 +315,10 @@ void Cy_SysLib_ClearResetReason(void) /* RES_CAUSE and RES_CAUSE2 register's bits are RW1C (every bit is cleared upon writing 1), * so write all ones to clear all the reset reasons. */ - SRSS->RES_CAUSE = 0xFFFFFFFFu; - SRSS->RES_CAUSE2 = 0xFFFFFFFFu; + SRSS->RES_CAUSE = 0xFFFFFFFFU; + SRSS->RES_CAUSE2 = 0xFFFFFFFFU; - if(0u != _FLD2VAL(SRSS_PWR_HIBERNATE_TOKEN, SRSS->PWR_HIBERNATE)) + if(0U != _FLD2VAL(SRSS_PWR_HIBERNATE_TOKEN, SRSS->PWR_HIBERNATE)) { /* Clears PWR_HIBERNATE token */ SRSS->PWR_HIBERNATE &= ~SRSS_PWR_HIBERNATE_TOKEN_Msk; @@ -367,17 +344,17 @@ void Cy_SysLib_ClearResetReason(void) *******************************************************************************/ void Cy_SysLib_SoftResetCM4(void) { - volatile uint32_t msg = CY_IPC_DATA_FOR_CM4_SOFT_RESET; + static uint32_t msg = CY_IPC_DATA_FOR_CM4_SOFT_RESET; /* Tries to acquire the IPC structure and pass the arguments to SROM API. * SROM API parameters: * ipcPtr: IPC_STRUCT0 - IPC Structure 0 reserved for M0+ Secure Access. - * notifyEvent_Intr: 1u - IPC Interrupt Structure 1 is used for Releasing IPC 0 (M0+ NMI Handler). + * notifyEvent_Intr: 1U - IPC Interrupt Structure 1 is used for Releasing IPC 0 (M0+ NMI Handler). * msgPtr: &msg - The address of SRAM with the API's parameters. */ - if(CY_IPC_DRV_SUCCESS != Cy_IPC_Drv_SendMsgPtr(IPC_STRUCT0, 1u, (void *) &msg)) + if(CY_IPC_DRV_SUCCESS != Cy_IPC_Drv_SendMsgPtr(IPC_STRUCT0, 1U, (void *) &msg)) { - CY_ASSERT(0u != 0u); + CY_ASSERT(0U != 0U); } while(Cy_IPC_Drv_IsLockAcquired(IPC_STRUCT0)) @@ -410,19 +387,21 @@ void Cy_SysLib_SoftResetCM4(void) *******************************************************************************/ uint64_t Cy_SysLib_GetUniqueId(void) { - uint64_t uniqueId; + uint32_t uniqueIdHi; + uint32_t uniqueIdLo; - uniqueId = ((uint64_t)SFLASH->DIE_YEAR << CY_UNIQUE_ID_DIE_YEAR_Pos) | - (((uint64_t)SFLASH->DIE_MINOR & 1u) << CY_UNIQUE_ID_DIE_MINOR_Pos) | - ((uint64_t)SFLASH->DIE_SORT << CY_UNIQUE_ID_DIE_SORT_Pos) | - ((uint64_t)SFLASH->DIE_Y << CY_UNIQUE_ID_DIE_Y_Pos) | - ((uint64_t)SFLASH->DIE_X << CY_UNIQUE_ID_DIE_X_Pos) | - ((uint64_t)SFLASH->DIE_WAFER << CY_UNIQUE_ID_DIE_WAFER_Pos) | - ((uint64_t)SFLASH->DIE_LOT[2u] << CY_UNIQUE_ID_DIE_LOT_2_Pos) | - ((uint64_t)SFLASH->DIE_LOT[1u] << CY_UNIQUE_ID_DIE_LOT_1_Pos) | - ((uint64_t)SFLASH->DIE_LOT[0u] << CY_UNIQUE_ID_DIE_LOT_0_Pos); + uniqueIdHi = ((uint32_t) SFLASH->DIE_YEAR << (CY_UNIQUE_ID_DIE_YEAR_Pos - CY_UNIQUE_ID_DIE_X_Pos)) | + (((uint32_t)SFLASH->DIE_MINOR & 1U) << (CY_UNIQUE_ID_DIE_MINOR_Pos - CY_UNIQUE_ID_DIE_X_Pos)) | + ((uint32_t) SFLASH->DIE_SORT << (CY_UNIQUE_ID_DIE_SORT_Pos - CY_UNIQUE_ID_DIE_X_Pos)) | + ((uint32_t) SFLASH->DIE_Y << (CY_UNIQUE_ID_DIE_Y_Pos - CY_UNIQUE_ID_DIE_X_Pos)) | + ((uint32_t) SFLASH->DIE_X); - return (uniqueId); + uniqueIdLo = ((uint32_t) SFLASH->DIE_WAFER << CY_UNIQUE_ID_DIE_WAFER_Pos) | + ((uint32_t) SFLASH->DIE_LOT[2U] << CY_UNIQUE_ID_DIE_LOT_2_Pos) | + ((uint32_t) SFLASH->DIE_LOT[1U] << CY_UNIQUE_ID_DIE_LOT_1_Pos) | + ((uint32_t) SFLASH->DIE_LOT[0U]); + + return (((uint64_t) uniqueIdHi << CY_UNIQUE_ID_DIE_X_Pos) | uniqueIdLo); } @@ -439,11 +418,7 @@ uint64_t Cy_SysLib_GetUniqueId(void) * address in the fault stack frame to be stored. * \note This function stores the fault stack frame only for the first occurred * fault. -* \note This function sets two flags into the fault structure: one flag checks -* which core caused the fault, another checks the type of the fault for -* the CM4 core. The flags should be cleared after analysis of the stored -* register values, to have a possibility to distinguish the next fault. -* \note The PDL doesn't provide an API to analyse the stored register +* \note The PDL doesn't provide an API to analyze the stored register * values. The user has to add additional functions for the analysis, * if necessary. * \note The CY_ARM_FAULT_DEBUG macro defines if the Fault Handler is enabled. @@ -519,7 +494,7 @@ void Cy_SysLib_FaultHandler(uint32_t const *faultStackAddr) * function. * * \note This function has the WEAK option, so the user can redefine the function -* behaviour for a custom processing. +* behavior for a custom processing. * For example, the function redefinition could be constructed from fault * stack processing and NVIC_SystemReset() function call. * @@ -565,165 +540,50 @@ __WEAK void Cy_SysLib_ProcessingFault(void) * \note Refer to the device TRM for the low power modes description. * * \param clkHfMHz The HFClk0 clock frequency in MHz. Specifying a frequency -* above the supported maximum will set the Wait states as for +* above the supported maximum will set the wait states as for * the maximum frequency. * *******************************************************************************/ void Cy_SysLib_SetWaitStates(bool ulpMode, uint32_t clkHfMHz) { + uint32_t waitStates; + uint32_t freqMax; + + freqMax = ulpMode ? CY_SYSLIB_ULP_SLOW_WS_0_FREQ_MAX : CY_SYSLIB_LP_SLOW_WS_0_FREQ_MAX; + waitStates = (clkHfMHz <= freqMax) ? 0UL : 1UL; + + /* ROM */ + CPUSS->ROM_CTL = _CLR_SET_FLD32U(CPUSS->ROM_CTL, CPUSS_ROM_CTL_SLOW_WS, waitStates); + CPUSS->ROM_CTL = _CLR_SET_FLD32U(CPUSS->ROM_CTL, CPUSS_ROM_CTL_FAST_WS, 0UL); + + /* SRAM */ + CPUSS->RAM0_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM0_CTL0, CPUSS_RAM0_CTL0_SLOW_WS, waitStates); + CPUSS->RAM0_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM0_CTL0, CPUSS_RAM0_CTL0_FAST_WS, 0UL); + #if defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) + CPUSS->RAM1_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM1_CTL0, CPUSS_RAM1_CTL0_SLOW_WS, waitStates); + CPUSS->RAM1_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM1_CTL0, CPUSS_RAM1_CTL0_FAST_WS, 0UL); + #endif /* defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) */ + #if defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) + CPUSS->RAM2_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM2_CTL0, CPUSS_RAM2_CTL0_SLOW_WS, waitStates); + CPUSS->RAM2_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM2_CTL0, CPUSS_RAM2_CTL0_FAST_WS, 0UL); + #endif /* defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) */ + + /* Flash */ if (ulpMode) { - Cy_SysLib_SetWaitStates_ULP(clkHfMHz); + waitStates = (clkHfMHz <= CY_SYSLIB_FLASH_ULP_WS_0_FREQ_MAX) ? 0UL : + ((clkHfMHz <= CY_SYSLIB_FLASH_ULP_WS_1_FREQ_MAX) ? 1UL : 2UL); } else { - Cy_SysLib_SetWaitStates_LP(clkHfMHz); - } -} - - -/******************************************************************************* -* Function Name: Cy_SysLib_SetWaitStates_LP -****************************************************************************//** -* -* Sets the ROM, SRAM, and Flash Wait states for the low power mode. -* This function is called by \ref Cy_SysLib_SetWaitStates(). -* -* \param clkHfMHz The HFClk0 clock frequency in MHz. Specifying a frequency -* above the supported maximum will set the Wait states as for -* the maximum frequency. -* -*******************************************************************************/ -static void Cy_SysLib_SetWaitStates_LP(uint32_t clkHfMHz) -{ - uint32_t waitStates; - - /* ROM */ - if (clkHfMHz < CY_SYSLIB_ROM_LP_SLOW_WS_0_FREQ_MAX) - { - waitStates = 0UL; - } else - { - waitStates = 1UL; - } - CPUSS->ROM_CTL = _CLR_SET_FLD32U(CPUSS->ROM_CTL, CPUSS_ROM_CTL_SLOW_WS, waitStates); - - waitStates = 0UL; - CPUSS->ROM_CTL = _CLR_SET_FLD32U(CPUSS->ROM_CTL, CPUSS_ROM_CTL_FAST_WS, waitStates); - - /* SRAM */ - if (clkHfMHz < CY_SYSLIB_RAM_LP_SLOW_WS_0_FREQ_MAX) - { - waitStates = 0UL; - } else - { - waitStates = 1UL; - } - CPUSS->RAM0_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM0_CTL0, CPUSS_RAM0_CTL0_SLOW_WS, waitStates); - #if defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) - CPUSS->RAM1_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM1_CTL0, CPUSS_RAM1_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) */ - #if defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) - CPUSS->RAM2_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM2_CTL0, CPUSS_RAM2_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) */ - - waitStates = 0UL; - CPUSS->RAM0_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM0_CTL0, CPUSS_RAM0_CTL0_FAST_WS, waitStates); - #if defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) - CPUSS->RAM1_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM1_CTL0, CPUSS_RAM1_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) */ - #if defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) - CPUSS->RAM2_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM2_CTL0, CPUSS_RAM2_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) */ - - /* Flash */ - if (clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_0_FREQ_MAX) - { - waitStates = 0UL; - } else if (clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_1_FREQ_MAX) - { - waitStates = 1UL; - } else if (clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_2_FREQ_MAX) - { - waitStates = 2UL; - } else if (clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_3_FREQ_MAX) - { - waitStates = 3UL; - } else - { - waitStates = 4UL; + waitStates = (clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_0_FREQ_MAX) ? 0UL : + ((clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_1_FREQ_MAX) ? 1UL : + ((clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_2_FREQ_MAX) ? 2UL : + ((clkHfMHz <= CY_SYSLIB_FLASH_LP_WS_3_FREQ_MAX) ? 3UL : 4UL))); } FLASHC->FLASH_CTL = _CLR_SET_FLD32U(FLASHC->FLASH_CTL, FLASHC_FLASH_CTL_MAIN_WS, waitStates); } -/******************************************************************************* -* Function Name: Cy_SysLib_SetWaitStates_ULP -****************************************************************************//** -* -* Sets the ROM, SRAM, and Flash Wait states for the ultra-low power mode. -* This function is called by \ref Cy_SysLib_SetWaitStates(). -* -* \param clkHfMHz The HFClk0 clock frequency in MHz. Specifying a frequency -* above the supported maximum will set the Wait states as for -* the maximum frequency. -* -*******************************************************************************/ -static void Cy_SysLib_SetWaitStates_ULP(uint32_t clkHfMHz) -{ - uint32_t waitStates; - - /* ROM */ - if (clkHfMHz < CY_SYSLIB_ROM_ULP_SLOW_WS_0_FREQ_MAX) - { - waitStates = 0UL; - } else - { - waitStates = 1UL; - } - CPUSS->ROM_CTL = _CLR_SET_FLD32U(CPUSS->ROM_CTL, CPUSS_ROM_CTL_SLOW_WS, waitStates); - - waitStates = 0UL; - CPUSS->ROM_CTL = _CLR_SET_FLD32U(CPUSS->ROM_CTL, CPUSS_ROM_CTL_FAST_WS, waitStates); - - /* SRAM */ - if (clkHfMHz < CY_SYSLIB_RAM_ULP_SLOW_WS_0_FREQ_MAX) - { - waitStates = 0UL; - } else - { - waitStates = 1UL; - } - CPUSS->RAM0_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM0_CTL0, CPUSS_RAM0_CTL0_SLOW_WS, waitStates); - #if defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) - CPUSS->RAM1_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM1_CTL0, CPUSS_RAM1_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) */ - #if defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) - CPUSS->RAM2_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM2_CTL0, CPUSS_RAM2_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) */ - - waitStates = 0UL; - CPUSS->RAM0_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM0_CTL0, CPUSS_RAM0_CTL0_FAST_WS, waitStates); - #if defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) - CPUSS->RAM1_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM1_CTL0, CPUSS_RAM1_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC1_PRESENT) && (RAMC1_PRESENT == 1UL) */ - #if defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) - CPUSS->RAM2_CTL0 = _CLR_SET_FLD32U(CPUSS->RAM2_CTL0, CPUSS_RAM2_CTL0_SLOW_WS, waitStates); - #endif /* defined (RAMC2_PRESENT) && (RAMC2_PRESENT == 1UL) */ - - /* Flash */ - if (clkHfMHz <= CY_SYSLIB_FLASH_ULP_WS_0_FREQ_MAX) - { - waitStates = 0UL; - } else if (clkHfMHz <= CY_SYSLIB_FLASH_ULP_WS_1_FREQ_MAX) - { - waitStates = 1UL; - } else - { - waitStates = 2UL; - } - FLASHC->FLASH_CTL = _CLR_SET_FLD32U(FLASHC->FLASH_CTL, FLASHC_FLASH_CTL_MAIN_WS, waitStates); -} - /* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/cy_syslib.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/cy_syslib.h similarity index 81% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/cy_syslib.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/cy_syslib.h index 6c220e1303..54a482df48 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syslib/cy_syslib.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syslib/cy_syslib.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_syslib.h -* \version 2.0 +* \version 2.0.1 * -* Provides an API declaration of the syslib driver. +* Provides an API declaration of the SysLib driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -31,7 +31,7 @@ * * A variable type definition from MISRA-C which specifies signedness * * Cross compiler compatible attributes * * Getting a silicon-unique ID API -* * Setting Wait states API +* * Setting wait states API * * Resetting the backup domain API * * APIs to serve Fault handler * @@ -125,6 +125,34 @@ * * * +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* * * * @@ -168,9 +196,9 @@ extern "C" { #define CY_CPU_CORTEX_M4 (__CORTEX_M == 4) /**< CM4 core CPU Code */ /** The macro to disable the Fault Handler */ -#define CY_ARM_FAULT_DEBUG_DISABLED (0u) +#define CY_ARM_FAULT_DEBUG_DISABLED (0U) /** The macro to enable the Fault Handler */ -#define CY_ARM_FAULT_DEBUG_ENABLED (1u) +#define CY_ARM_FAULT_DEBUG_ENABLED (1U) #if !defined(CY_ARM_FAULT_DEBUG) /** The macro defines if the Fault Handler is enabled. Enabled by default. */ @@ -182,16 +210,16 @@ extern "C" { * \{ * Function status type codes */ -#define CY_PDL_STATUS_CODE_Pos (0u) /**< The module status code position in the status code */ -#define CY_PDL_STATUS_TYPE_Pos (16u) /**< The status type position in the status code */ -#define CY_PDL_MODULE_ID_Pos (18u) /**< The software module ID position in the status code */ +#define CY_PDL_STATUS_CODE_Pos (0U) /**< The module status code position in the status code */ +#define CY_PDL_STATUS_TYPE_Pos (16U) /**< The status type position in the status code */ +#define CY_PDL_MODULE_ID_Pos (18U) /**< The software module ID position in the status code */ #define CY_PDL_STATUS_INFO (0UL << CY_PDL_STATUS_TYPE_Pos) /**< The information status type */ #define CY_PDL_STATUS_WARNING (1UL << CY_PDL_STATUS_TYPE_Pos) /**< The warning status type */ #define CY_PDL_STATUS_ERROR (2UL << CY_PDL_STATUS_TYPE_Pos) /**< The error status type */ -#define CY_PDL_MODULE_ID_Msk (0x3FFFu) /**< The software module ID mask */ +#define CY_PDL_MODULE_ID_Msk (0x3FFFU) /**< The software module ID mask */ /** Get the software PDL module ID */ #define CY_PDL_DRV_ID(id) ((uint32_t)((uint32_t)((id) & CY_PDL_MODULE_ID_Msk) << CY_PDL_MODULE_ID_Pos)) -#define CY_SYSLIB_ID CY_PDL_DRV_ID(0x11u) /**< SYSLIB PDL ID */ +#define CY_SYSLIB_ID CY_PDL_DRV_ID(0x11U) /**< SYSLIB PDL ID */ /** \} group_syslib_macros_status_codes */ /** \} group_syslib_macros */ @@ -357,25 +385,25 @@ typedef enum *******************************************************************************/ /** Get the lower 8 bits of a 16-bit value. */ -#define CY_LO8(x) ((uint8_t) ((x) & 0xFFu)) +#define CY_LO8(x) ((uint8_t) ((x) & 0xFFU)) /** Get the upper 8 bits of a 16-bit value. */ -#define CY_HI8(x) ((uint8_t) ((uint16_t)(x) >> 8u)) +#define CY_HI8(x) ((uint8_t) ((uint16_t)(x) >> 8U)) /** Get the lower 16 bits of a 32-bit value. */ -#define CY_LO16(x) ((uint16_t) ((x) & 0xFFFFu)) +#define CY_LO16(x) ((uint16_t) ((x) & 0xFFFFU)) /** Get the upper 16 bits of a 32-bit value. */ -#define CY_HI16(x) ((uint16_t) ((uint32_t)(x) >> 16u)) +#define CY_HI16(x) ((uint16_t) ((uint32_t)(x) >> 16U)) /** Swap the byte ordering of a 16-bit value */ -#define CY_SWAP_ENDIAN16(x) ((uint16_t)(((x) << 8u) | (((x) >> 8u) & 0x00FFu))) +#define CY_SWAP_ENDIAN16(x) ((uint16_t)(((x) << 8U) | (((x) >> 8U) & 0x00FFU))) /** Swap the byte ordering of a 32-bit value */ -#define CY_SWAP_ENDIAN32(x) ((uint32_t)((((x) >> 24u) & 0x000000FFu) | (((x) & 0x00FF0000u) >> 8u) | \ - (((x) & 0x0000FF00u) << 8u) | ((x) << 24u))) +#define CY_SWAP_ENDIAN32(x) ((uint32_t)((((x) >> 24U) & 0x000000FFU) | (((x) & 0x00FF0000U) >> 8U) | \ + (((x) & 0x0000FF00U) << 8U) | ((x) << 24U))) /** Swap the byte ordering of a 64-bit value */ -#define CY_SWAP_ENDIAN64(x) ((uint64_t) (((uint64_t) CY_SWAP_ENDIAN32((uint32_t)(x)) << 32u) | \ - CY_SWAP_ENDIAN32((uint32_t)((x) >> 32u)))) +#define CY_SWAP_ENDIAN64(x) ((uint64_t) (((uint64_t) CY_SWAP_ENDIAN32((uint32_t)(x)) << 32U) | \ + CY_SWAP_ENDIAN32((uint32_t)((x) >> 32U)))) /******************************************************************************* @@ -404,7 +432,11 @@ typedef enum #define CY_SECTION(name) CY_PRAGMA(location = name) #define CY_UNUSED #define CY_NOINLINE CY_PRAGMA(optimize = no_inline) - #define CY_ALIGN(align) CY_PRAGMA(data_alignment = align) + #if (__VER__ < 8010001) + #define CY_ALIGN(align) CY_PRAGMA(data_alignment = align) + #else + #define CY_ALIGN(align) __ALIGNED(align) + #endif /* (__VER__ < 8010001) */ #else #error "An unsupported toolchain" #endif /* (__ARMCC_VERSION) */ @@ -423,41 +455,41 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical #if !defined(NDEBUG) /** The max size of the file name which stores the ASSERT location */ - #define CY_MAX_FILE_NAME_SIZE (24u) + #define CY_MAX_FILE_NAME_SIZE (24U) extern CY_NOINIT char_t cy_assertFileName[CY_MAX_FILE_NAME_SIZE]; /**< The assert buffer */ extern CY_NOINIT uint32_t cy_assertLine; /**< The assert line value */ #endif /* NDEBUG */ #if (CY_ARM_FAULT_DEBUG == CY_ARM_FAULT_DEBUG_ENABLED) - #define CY_R0_Pos (0u) /**< The position of the R0 content in a fault structure */ - #define CY_R1_Pos (1u) /**< The position of the R1 content in a fault structure */ - #define CY_R2_Pos (2u) /**< The position of the R2 content in a fault structure */ - #define CY_R3_Pos (3u) /**< The position of the R3 content in a fault structure */ - #define CY_R12_Pos (4u) /**< The position of the R12 content in a fault structure */ - #define CY_LR_Pos (5u) /**< The position of the LR content in a fault structure */ - #define CY_PC_Pos (6u) /**< The position of the PC content in a fault structure */ - #define CY_PSR_Pos (7u) /**< The position of the PSR content in a fault structure */ + #define CY_R0_Pos (0U) /**< The position of the R0 content in a fault structure */ + #define CY_R1_Pos (1U) /**< The position of the R1 content in a fault structure */ + #define CY_R2_Pos (2U) /**< The position of the R2 content in a fault structure */ + #define CY_R3_Pos (3U) /**< The position of the R3 content in a fault structure */ + #define CY_R12_Pos (4U) /**< The position of the R12 content in a fault structure */ + #define CY_LR_Pos (5U) /**< The position of the LR content in a fault structure */ + #define CY_PC_Pos (6U) /**< The position of the PC content in a fault structure */ + #define CY_PSR_Pos (7U) /**< The position of the PSR content in a fault structure */ #if (CY_CPU_CORTEX_M4) && ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U))) - #define CY_FPSCR_IXC_Msk (0x00000010u) /**< The cumulative exception bit for floating-point exceptions */ - #define CY_FPSCR_IDC_Msk (0x00000080u) /**< The cumulative exception bit for floating-point exceptions */ - #define CY_S0_Pos (8u) /**< The position of the FPU S0 content in a fault structure */ - #define CY_S1_Pos (9u) /**< The position of the FPU S1 content in a fault structure */ - #define CY_S2_Pos (10u) /**< The position of the FPU S2 content in a fault structure */ - #define CY_S3_Pos (11u) /**< The position of the FPU S3 content in a fault structure */ - #define CY_S4_Pos (12u) /**< The position of the FPU S4 content in a fault structure */ - #define CY_S5_Pos (13u) /**< The position of the FPU S5 content in a fault structure */ - #define CY_S6_Pos (14u) /**< The position of the FPU S6 content in a fault structure */ - #define CY_S7_Pos (15u) /**< The position of the FPU S7 content in a fault structure */ - #define CY_S8_Pos (16u) /**< The position of the FPU S8 content in a fault structure */ - #define CY_S9_Pos (17u) /**< The position of the FPU S9 content in a fault structure */ - #define CY_S10_Pos (18u) /**< The position of the FPU S10 content in a fault structure */ - #define CY_S11_Pos (19u) /**< The position of the FPU S11 content in a fault structure */ - #define CY_S12_Pos (20u) /**< The position of the FPU S12 content in a fault structure */ - #define CY_S13_Pos (21u) /**< The position of the FPU S13 content in a fault structure */ - #define CY_S14_Pos (22u) /**< The position of the FPU S14 content in a fault structure */ - #define CY_S15_Pos (23u) /**< The position of the FPU S15 content in a fault structure */ - #define CY_FPSCR_Pos (24u) /**< The position of the FPU FPSCR content in a fault structure */ + #define CY_FPSCR_IXC_Msk (0x00000010U) /**< The cumulative exception bit for floating-point exceptions */ + #define CY_FPSCR_IDC_Msk (0x00000080U) /**< The cumulative exception bit for floating-point exceptions */ + #define CY_S0_Pos (8U) /**< The position of the FPU S0 content in a fault structure */ + #define CY_S1_Pos (9U) /**< The position of the FPU S1 content in a fault structure */ + #define CY_S2_Pos (10U) /**< The position of the FPU S2 content in a fault structure */ + #define CY_S3_Pos (11U) /**< The position of the FPU S3 content in a fault structure */ + #define CY_S4_Pos (12U) /**< The position of the FPU S4 content in a fault structure */ + #define CY_S5_Pos (13U) /**< The position of the FPU S5 content in a fault structure */ + #define CY_S6_Pos (14U) /**< The position of the FPU S6 content in a fault structure */ + #define CY_S7_Pos (15U) /**< The position of the FPU S7 content in a fault structure */ + #define CY_S8_Pos (16U) /**< The position of the FPU S8 content in a fault structure */ + #define CY_S9_Pos (17U) /**< The position of the FPU S9 content in a fault structure */ + #define CY_S10_Pos (18U) /**< The position of the FPU S10 content in a fault structure */ + #define CY_S11_Pos (19U) /**< The position of the FPU S11 content in a fault structure */ + #define CY_S12_Pos (20U) /**< The position of the FPU S12 content in a fault structure */ + #define CY_S13_Pos (21U) /**< The position of the FPU S13 content in a fault structure */ + #define CY_S14_Pos (22U) /**< The position of the FPU S14 content in a fault structure */ + #define CY_S15_Pos (23U) /**< The position of the FPU S15 content in a fault structure */ + #define CY_FPSCR_Pos (24U) /**< The position of the FPU FPSCR content in a fault structure */ #endif /* CY_CPU_CORTEX_M4 && __FPU_PRESENT */ extern CY_NOINIT cy_stc_fault_frame_t cy_faultFrame; /**< Fault frame structure */ @@ -534,8 +566,8 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical * *******************************************************************************/ #define CY_GET_REG24(addr) (uint32_t) ((*((const volatile uint8_t *)(addr))) | \ - (uint32_t) ((*((const volatile uint8_t *)(addr) + 1)) << 8u) | \ - (uint32_t) ((*((const volatile uint8_t *)(addr) + 2)) << 16u)) + (uint32_t) ((*((const volatile uint8_t *)(addr) + 1)) << 8U) | \ + (uint32_t) ((*((const volatile uint8_t *)(addr) + 2)) << 16U)) /******************************************************************************* @@ -552,8 +584,8 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical #define CY_SET_REG24(addr, value) do \ { \ (*((volatile uint8_t *) (addr))) = (uint8_t)(value); \ - (*((volatile uint8_t *) (addr) + 1)) = (uint8_t)((value) >> 8u); \ - (*((volatile uint8_t *) (addr) + 2)) = (uint8_t)((value) >> 16u); \ + (*((volatile uint8_t *) (addr) + 1)) = (uint8_t)((value) >> 8U); \ + (*((volatile uint8_t *) (addr) + 2)) = (uint8_t)((value) >> 16U); \ } \ while(0) @@ -598,13 +630,13 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical * Class 1 - The highest class, safety-critical functions which rely on parameters that could be * changed between different PSoC devices */ -#define CY_ASSERT_CLASS_1 (1u) +#define CY_ASSERT_CLASS_1 (1U) /** Class 2 - Functions that have fixed limits such as counter periods (16-bits/32-bits etc.) */ -#define CY_ASSERT_CLASS_2 (2u) +#define CY_ASSERT_CLASS_2 (2U) /** Class 3 - Functions that accept enums as constant parameters */ -#define CY_ASSERT_CLASS_3 (3u) +#define CY_ASSERT_CLASS_3 (3U) #ifndef CY_ASSERT_LEVEL /** The user-definable assert level from compiler command-line argument (similarly to DEBUG / NDEBUG) */ @@ -612,17 +644,17 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical #endif /* CY_ASSERT_LEVEL */ #if (CY_ASSERT_LEVEL == CY_ASSERT_CLASS_1) - #define CY_ASSERT_L1(x) CY_ASSERT(x) /**< Assert Level 1 */ + #define CY_ASSERT_L1(x) CY_ASSERT(x) /**< Assert Level 1 */ #define CY_ASSERT_L2(x) do{} while(0) /**< Assert Level 2 */ #define CY_ASSERT_L3(x) do{} while(0) /**< Assert Level 3 */ #elif (CY_ASSERT_LEVEL == CY_ASSERT_CLASS_2) - #define CY_ASSERT_L1(x) CY_ASSERT(x) /**< Assert Level 1 */ - #define CY_ASSERT_L2(x) CY_ASSERT(x) /**< Assert Level 2 */ + #define CY_ASSERT_L1(x) CY_ASSERT(x) /**< Assert Level 1 */ + #define CY_ASSERT_L2(x) CY_ASSERT(x) /**< Assert Level 2 */ #define CY_ASSERT_L3(x) do{} while(0) /**< Assert Level 3 */ #else /* Default is Level 3 */ - #define CY_ASSERT_L1(x) CY_ASSERT(x) /**< Assert Level 1 */ - #define CY_ASSERT_L2(x) CY_ASSERT(x) /**< Assert Level 2 */ - #define CY_ASSERT_L3(x) CY_ASSERT(x) /**< Assert Level 3 */ + #define CY_ASSERT_L1(x) CY_ASSERT(x) /**< Assert Level 1 */ + #define CY_ASSERT_L2(x) CY_ASSERT(x) /**< Assert Level 2 */ + #define CY_ASSERT_L3(x) CY_ASSERT(x) /**< Assert Level 3 */ #endif /* CY_ASSERT_LEVEL == CY_ASSERT_CLASS_1 */ /** \} group_syslib_macros_assert */ @@ -697,7 +729,7 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical * Constants *****************************************************************************/ /** Defines a 32-kHz clock delay */ -#define CY_DELAY_MS_OVERFLOW (0x8000u) +#define CY_DELAY_MS_OVERFLOW (0x8000U) /** * \defgroup group_syslib_macros_reset_cause Reset cause @@ -705,31 +737,31 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical * Define RESET_CAUSE mask values */ /** A basic WatchDog Timer (WDT) reset has occurred since the last power cycle. */ -#define CY_SYSLIB_RESET_HWWDT (0x0001u) +#define CY_SYSLIB_RESET_HWWDT (0x0001U) /** The fault logging system requested a reset from its Active logic. */ -#define CY_SYSLIB_RESET_ACT_FAULT (0x0002u) +#define CY_SYSLIB_RESET_ACT_FAULT (0x0002U) /** The fault logging system requested a reset from its Deep-Sleep logic. */ -#define CY_SYSLIB_RESET_DPSLP_FAULT (0x0004u) +#define CY_SYSLIB_RESET_DPSLP_FAULT (0x0004U) /** The CPU requested a system reset through it's SYSRESETREQ. This can be done via a debugger probe or in firmware. */ -#define CY_SYSLIB_RESET_SOFT (0x0010u) +#define CY_SYSLIB_RESET_SOFT (0x0010U) /** The Multi-Counter Watchdog timer #0 reset has occurred since the last power cycle. */ -#define CY_SYSLIB_RESET_SWWDT0 (0x0020u) +#define CY_SYSLIB_RESET_SWWDT0 (0x0020U) /** The Multi-Counter Watchdog timer #1 reset has occurred since the last power cycle. */ -#define CY_SYSLIB_RESET_SWWDT1 (0x0040u) +#define CY_SYSLIB_RESET_SWWDT1 (0x0040U) /** The Multi-Counter Watchdog timer #2 reset has occurred since the last power cycle. */ -#define CY_SYSLIB_RESET_SWWDT2 (0x0080u) +#define CY_SYSLIB_RESET_SWWDT2 (0x0080U) /** The Multi-Counter Watchdog timer #3 reset has occurred since the last power cycle. */ -#define CY_SYSLIB_RESET_SWWDT3 (0x0100u) +#define CY_SYSLIB_RESET_SWWDT3 (0x0100U) /** The reset has occurred on a wakeup from Hibernate power mode. */ #define CY_SYSLIB_RESET_HIB_WAKEUP (0x40000UL) -#if (SRSS_WCOCSV_PRESENT != 0u) +#if (SRSS_WCOCSV_PRESENT != 0U) /** The clock supervision logic requested a reset due to the loss of a watch-crystal clock. */ - #define CY_SYSLIB_RESET_CSV_WCO_LOSS (0x0008u) + #define CY_SYSLIB_RESET_CSV_WCO_LOSS (0x0008U) /** The clock supervision logic requested a reset due to the loss of a high-frequency clock. */ #define CY_SYSLIB_RESET_HFCLK_LOSS (0x10000UL) /** The clock supervision logic requested a reset due to the frequency error of a high-frequency clock. */ #define CY_SYSLIB_RESET_HFCLK_ERR (0x20000UL) -#endif /* (SRSS_WCOCSV_PRESENT != 0u) */ +#endif /* (SRSS_WCOCSV_PRESENT != 0U) */ /** \} group_syslib_macros_reset_cause */ @@ -743,15 +775,15 @@ typedef double float64_t; /**< Specific-length typedef for the basic numerical * \{ * Unique ID fields positions */ -#define CY_UNIQUE_ID_DIE_YEAR_Pos (57u) /**< The position of the DIE_YEAR field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_MINOR_Pos (56u) /**< The position of the DIE_MINOR field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_SORT_Pos (48u) /**< The position of the DIE_SORT field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_Y_Pos (40u) /**< The position of the DIE_Y field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_X_Pos (32u) /**< The position of the DIE_X field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_WAFER_Pos (24u) /**< The position of the DIE_WAFER field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_LOT_2_Pos (16u) /**< The position of the DIE_LOT_2 field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_LOT_1_Pos (8u) /**< The position of the DIE_LOT_1 field in the silicon Unique ID */ -#define CY_UNIQUE_ID_DIE_LOT_0_Pos (0u) /**< The position of the DIE_LOT_0 field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_YEAR_Pos (57U) /**< The position of the DIE_YEAR field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_MINOR_Pos (56U) /**< The position of the DIE_MINOR field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_SORT_Pos (48U) /**< The position of the DIE_SORT field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_Y_Pos (40U) /**< The position of the DIE_Y field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_X_Pos (32U) /**< The position of the DIE_X field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_WAFER_Pos (24U) /**< The position of the DIE_WAFER field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_LOT_2_Pos (16U) /**< The position of the DIE_LOT_2 field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_LOT_1_Pos (8U) /**< The position of the DIE_LOT_1 field in the silicon Unique ID */ +#define CY_UNIQUE_ID_DIE_LOT_0_Pos (0U) /**< The position of the DIE_LOT_0 field in the silicon Unique ID */ /** \} group_syslib_macros_unique_id */ @@ -780,9 +812,9 @@ __NO_RETURN void Cy_SysLib_Halt(uint32_t reason); void Cy_SysLib_ClearFlashCacheAndBuffer(void); cy_en_syslib_status_t Cy_SysLib_ResetBackupDomain(void); uint32_t Cy_SysLib_GetResetReason(void); -#if (SRSS_WCOCSV_PRESENT != 0u) || defined(CY_DOXYGEN) +#if (SRSS_WCOCSV_PRESENT != 0U) || defined(CY_DOXYGEN) uint32_t Cy_SysLib_GetNumHfclkResetCause(void); -#endif /* (SRSS_WCOCSV_PRESENT != 0u) || defined(CY_DOXYGEN) */ +#endif /* (SRSS_WCOCSV_PRESENT != 0U) || defined(CY_DOXYGEN) */ void Cy_SysLib_ClearResetReason(void); uint64_t Cy_SysLib_GetUniqueId(void); #if (CY_CPU_CORTEX_M0P) @@ -829,6 +861,40 @@ void Cy_SysLib_ExitCriticalSection(uint32_t savedIntrStatus); /** \cond INTERNAL */ +#define CY_SYSLIB_DEVICE_REV_0A (0x21U) /**< The device TO *A Revision ID */ +#define CY_SYSLIB_DEVICE_PSOC6ABLE2 (0x100U) /**< The PSoC6 BLE2 device Family ID */ + + +/******************************************************************************* +* Function Name: Cy_SysLib_GetDeviceRevision +****************************************************************************//** +* +* This function returns a device Revision ID. +* +* \return A device Revision ID. +* +*******************************************************************************/ +__STATIC_INLINE uint8_t Cy_SysLib_GetDeviceRevision(void) +{ + return ((SFLASH->SI_REVISION_ID == 0UL) ? CY_SYSLIB_DEVICE_REV_0A : SFLASH->SI_REVISION_ID); +} + + +/******************************************************************************* +* Function Name: Cy_SysLib_GetDevice +****************************************************************************//** +* +* This function returns a device Family ID. +* +* \return A device Family ID. +* +*******************************************************************************/ +__STATIC_INLINE uint16_t Cy_SysLib_GetDevice(void) +{ + return ((SFLASH->FAMILY_ID == 0UL) ? CY_SYSLIB_DEVICE_PSOC6ABLE2 : SFLASH->FAMILY_ID); +} + + typedef uint32_t cy_status; /** The ARM 32-bit status value for backward compatibility with the UDB components. Do not use it in your code. */ typedef uint32_t cystatus; @@ -851,36 +917,36 @@ typedef volatile uint32_t reg32; /**< Alias to uint32_t for backward compatibil /** The ARM 32-bit Return error / status code for backward compatibility. * Do not use them in your code. */ -#define CY_RET_SUCCESS (0x00u) /* Successful */ -#define CY_RET_BAD_PARAM (0x01u) /* One or more invalid parameters */ -#define CY_RET_INVALID_OBJECT (0x02u) /* An invalid object specified */ -#define CY_RET_MEMORY (0x03u) /* A memory-related failure */ -#define CY_RET_LOCKED (0x04u) /* A resource lock failure */ -#define CY_RET_EMPTY (0x05u) /* No more objects available */ -#define CY_RET_BAD_DATA (0x06u) /* Bad data received (CRC or other error check) */ -#define CY_RET_STARTED (0x07u) /* Operation started, but not necessarily completed yet */ -#define CY_RET_FINISHED (0x08u) /* Operation is completed */ -#define CY_RET_CANCELED (0x09u) /* Operation is canceled */ -#define CY_RET_TIMEOUT (0x10u) /* Operation timed out */ -#define CY_RET_INVALID_STATE (0x11u) /* Operation is not setup or is in an improper state */ -#define CY_RET_UNKNOWN ((cy_status) 0xFFFFFFFFu) /* Unknown failure */ +#define CY_RET_SUCCESS (0x00U) /* Successful */ +#define CY_RET_BAD_PARAM (0x01U) /* One or more invalid parameters */ +#define CY_RET_INVALID_OBJECT (0x02U) /* An invalid object specified */ +#define CY_RET_MEMORY (0x03U) /* A memory-related failure */ +#define CY_RET_LOCKED (0x04U) /* A resource lock failure */ +#define CY_RET_EMPTY (0x05U) /* No more objects available */ +#define CY_RET_BAD_DATA (0x06U) /* Bad data received (CRC or other error check) */ +#define CY_RET_STARTED (0x07U) /* Operation started, but not necessarily completed yet */ +#define CY_RET_FINISHED (0x08U) /* Operation is completed */ +#define CY_RET_CANCELED (0x09U) /* Operation is canceled */ +#define CY_RET_TIMEOUT (0x10U) /* Operation timed out */ +#define CY_RET_INVALID_STATE (0x11U) /* Operation is not setup or is in an improper state */ +#define CY_RET_UNKNOWN ((cy_status) 0xFFFFFFFFU) /* Unknown failure */ /** ARM 32-bit Return error / status codes for backward compatibility with the UDB components. * Do not use them in your code. */ -#define CYRET_SUCCESS (0x00u) /* Successful */ -#define CYRET_BAD_PARAM (0x01u) /* One or more invalid parameters */ -#define CYRET_INVALID_OBJECT (0x02u) /* An invalid object specified */ -#define CYRET_MEMORY (0x03u) /* A memory-related failure */ -#define CYRET_LOCKED (0x04u) /* A resource lock failure */ -#define CYRET_EMPTY (0x05u) /* No more objects available */ -#define CYRET_BAD_DATA (0x06u) /* Bad data received (CRC or other error check) */ -#define CYRET_STARTED (0x07u) /* Operation started, but not necessarily completed yet */ -#define CYRET_FINISHED (0x08u) /* Operation is completed */ -#define CYRET_CANCELED (0x09u) /* Operation is canceled */ -#define CYRET_TIMEOUT (0x10u) /* Operation timed out */ -#define CYRET_INVALID_STATE (0x11u) /* Operation is not setup or is in an improper state */ -#define CYRET_UNKNOWN ((cystatus) 0xFFFFFFFFu) /* Unknown failure */ +#define CYRET_SUCCESS (0x00U) /* Successful */ +#define CYRET_BAD_PARAM (0x01U) /* One or more invalid parameters */ +#define CYRET_INVALID_OBJECT (0x02U) /* An invalid object specified */ +#define CYRET_MEMORY (0x03U) /* A memory-related failure */ +#define CYRET_LOCKED (0x04U) /* A resource lock failure */ +#define CYRET_EMPTY (0x05U) /* No more objects available */ +#define CYRET_BAD_DATA (0x06U) /* Bad data received (CRC or other error check) */ +#define CYRET_STARTED (0x07U) /* Operation started, but not necessarily completed yet */ +#define CYRET_FINISHED (0x08U) /* Operation is completed */ +#define CYRET_CANCELED (0x09U) /* Operation is canceled */ +#define CYRET_TIMEOUT (0x10U) /* Operation timed out */ +#define CYRET_INVALID_STATE (0x11U) /* Operation is not setup or is in an improper state */ +#define CYRET_UNKNOWN ((cystatus) 0xFFFFFFFFU) /* Unknown failure */ /** A type of ISR callbacks for backward compatibility with the UDB components. Do not use it in your code. */ typedef void (* cyisraddress)(void); diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syspm/cy_syspm.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syspm/cy_syspm.c new file mode 100644 index 0000000000..177b2421ff --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syspm/cy_syspm.c @@ -0,0 +1,2654 @@ +/***************************************************************************//** +* \file cy_syspm.c +* \version 2.10 +* +* This driver provides the source code for API power management. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ +#include "cy_syspm.h" + +/******************************************************************************* +* Internal Variables +*******************************************************************************/ +static cy_stc_syspm_callback_t* callbackRoot = NULL; +static cy_stc_syspm_callback_t* callbackListLast = NULL; +static uint32_t curRegisteredCallbacks = 0U; + +#if(0u != CY_CPU_CORTEX_M4) + static bool wasEventSent = false; +#endif /* (0u != CY_CPU_CORTEX_M4) */ + + +/******************************************************************************* +* Internal Functions +*******************************************************************************/ +#ifdef CY_IP_MXUDB + static void SaveRegisters(cy_stc_syspm_backup_regs_t *regs); + static void RestoreRegisters(cy_stc_syspm_backup_regs_t const *regs); +#endif /* CY_IP_MXUDB */ + +static void EnterDeepSleep(cy_en_syspm_waitfor_t waitFor); + +static void SetReadMarginTrimUlp(void); +static void SetReadMarginTrimLp(void); +static void SetWriteAssistTrimUlp(void); +static void SetWriteAssistTrimLp(void); + +static void SetVoltageBitForFlash(void); +static void ClearVoltageBitForFlash(void); + +#if defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) + static void Cy_EnterDeepSleep(cy_en_syspm_waitfor_t waitFor); +#endif /* defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) */ + + +/******************************************************************************* +* Internal Defines +*******************************************************************************/ +#if defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) + + /** The internal define for clock divider */ + #define SYSPM_CLK_DIVIDER (9U) + + /* Mask for the fast clock divider value */ + #define SYSPM_FAST_CLK_DIV_Msk (0xFF000000UL) + + /* Position for the fast clock divider value */ + #define SYSPM_FAST_CLK_DIV_Pos (24UL) + + /* Mask for the slow clock divider value */ + #define SYSPM_SLOW_CLK_DIV_Msk (0x00FF0000UL) + + /* Position for the slow clock divider value */ + #define SYSPM_SLOW_CLK_DIV_Pos (16UL) + + #if(0u != CY_CPU_CORTEX_M4) + #define CUR_CORE_DP_MASK (0x01UL) + #define OTHER_CORE_DP_MASK (0x02UL) + #else + #define CUR_CORE_DP_MASK (0x02UL) + #define OTHER_CORE_DP_MASK (0x01UL) + #endif + +#endif /* defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) */ + +/* Redefine for sflash region */ +#define DELAY_DONE_FLAG FLASHC + +/* Slow control register */ +#define TST_DDFT_SLOW_CTL_REG (*(volatile uint32_t *) 0x40260108U) + +/* Slow output register */ +#define CLK_OUTPUT_SLOW_REG (*(volatile uint32_t *) 0x40260518U) + +/* Fast control register */ +#define TST_DDFT_FAST_CTL_REG (*(volatile uint32_t *) 0x40260104U) + +/* Counter register */ +#define CLK_CAL_CNT1_REG (*(volatile uint32_t *) 0x4026051CU) + +#ifdef CY_IP_MXUDB + + /* The UDB placement on MMIO slave level */ + #define PERI_UDB_SLAVE_ENABLED ((uint32_t) (1UL << CY_MMIO_UDB_SLAVE_NR)) +#endif /* CY_IP_MXUDB */ + +/** The definition for the delay of the LDO after its output +* voltage is changed +*/ +#define LDO_STABILIZATION_DELAY_US (9U) + +/* Define for the IPC structure used by syspm driver */ +#define SYSPM_IPC_STC IPC_STRUCT7 + +/** Define to indicate that a 10 us delay is needed */ +#define NEED_DELAY (0x0U) + +/** Define to set the IMO to count a 10 us delay after exiting Deep Sleep */ +#define TST_DDFT_SLOW_CTL_MASK (0x00001F1EU) + +/** Slow output register */ +#define CLK_OUTPUT_SLOW_MASK (0x06U) + +/** Slow control register */ +#define TST_DDFT_FAST_CTL_MASK (62U) + +/** Load value for the timer to count delay after exiting Deep Sleep */ +#define IMO_10US_DELAY (68U) + +/** Define to indicate that the clock is finished counting */ +#define CLK_CAL_CNT1_DONE ((uint32_t) ((uint32_t) 1U << CLK_CAL_CNT1_DONE_POS)) + +/** Define to indicate that the clock is finished counting */ +#define CLK_CAL_CNT1_DONE_POS (31U) + +/** Define to indicate that a 10 us delay was done after exiting Deep Sleep */ +#define DELAY_DONE (0xAAAAAAAAU) + +/** Define for transitional 0.95 V for the LDO regulator */ +#define LDO_OUT_VOLTAGE_0_95V (0x0BU) + +/** Define for transitional 1.1 V for the LDO regulator */ +#define LDO_OUT_VOLTAGE_1_1V (0x17U) + +/** Define for transitional 1.15 V for the LDO regulator */ +#define LDO_OUT_VOLTAGE_1_15V (0x1BU) + +#if(0u != SRSS_BUCKCTL_PRESENT) + + /** Define for transitional 0.95 V for buck regulator */ + #define BUCK_OUT1_VOLTAGE_0_95V (3U) +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ + +/* These defines will be removed and SFLASH registers used instead */ + +/** Trim define for ROM in LP mode */ +#define CPUSS_TRIM_ROM_LP (0x00000013U) + +/** Trim define for RAM in LP mode */ +#define CPUSS_TRIM_RAM_LP (0x00004013U) + +/** Trim define for ROM in ULP mode */ +#define CPUSS_TRIM_ROM_ULP (0x00000012U) + +/** Trim define for RAM in ULP mode */ +#define CPUSS_TRIM_RAM_ULP (0x00006012U) + + +/******************************************************************************* +* Function Name: Cy_SysPm_ReadStatus +****************************************************************************//** +* +* Reads the status of the core(s). +* +* \return The current power mode. See \ref group_syspm_return_status. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_ReadStatus +* +*******************************************************************************/ +uint32_t Cy_SysPm_ReadStatus(void) +{ + uint32_t interruptState; + uint32_t pmStatus = 0U; + interruptState = Cy_SysLib_EnterCriticalSection(); + +#if(0u != CY_IP_M4CPUSS) + + /* Check whether CM4 is in Deep Sleep mode*/ + if((0U != _FLD2VAL(CPUSS_CM4_STATUS_SLEEPING, CPUSS->CM4_STATUS)) && + (0U != _FLD2VAL(CPUSS_CM4_STATUS_SLEEPDEEP, CPUSS->CM4_STATUS))) + { + pmStatus |= CY_SYSPM_STATUS_CM4_DEEPSLEEP; + } + /* Check whether CM4 is in Sleep mode*/ + else if(0U != _FLD2VAL(CPUSS_CM4_STATUS_SLEEPING, CPUSS->CM4_STATUS)) + { + pmStatus |= CY_SYSPM_STATUS_CM4_SLEEP; + } + else + { + pmStatus |= CY_SYSPM_STATUS_CM4_ACTIVE; + } +#endif /* (0u != CY_IP_M4CPUSS) */ + + /* Check whether CM0p is in Deep Sleep mode*/ + if((0U != _FLD2VAL(CPUSS_CM0_STATUS_SLEEPING, CPUSS->CM0_STATUS)) && + (0U != _FLD2VAL(CPUSS_CM0_STATUS_SLEEPDEEP, CPUSS->CM0_STATUS))) + { + pmStatus |= (uint32_t) CY_SYSPM_STATUS_CM0_DEEPSLEEP; + } + /* Check whether CM0p is in Sleep mode*/ + else if (0U != _FLD2VAL(CPUSS_CM0_STATUS_SLEEPING, CPUSS->CM0_STATUS)) + { + pmStatus |= CY_SYSPM_STATUS_CM0_SLEEP; + } + else + { + pmStatus |= CY_SYSPM_STATUS_CM0_ACTIVE; + } + + /* Check whether the device is in Low Power mode by reading + * the Active Reference status + */ + if(0U != (_FLD2VAL(SRSS_PWR_CTL_ACT_REF_DIS, SRSS->PWR_CTL))) + { + pmStatus |= CY_SYSPM_STATUS_SYSTEM_LOWPOWER; + } + Cy_SysLib_ExitCriticalSection(interruptState); + + return(pmStatus); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_Sleep +****************************************************************************//** +* +* Sets a CPU core to Sleep mode. +* +* Puts the core into Sleep power mode, if none of callback functions were +* registered. +* +* For more details about switching into Sleep power mode and debug, +* refer to the device TRM. +* +* If at least one callback function with the CY_SYSPM_SLEEP type was registered, +* the next algorithm is executed: +* Prior to entering Sleep mode, all callback functions of the CY_SYSPM_SLEEP +* type with the CY_SYSPM_CHECK_READY parameter are called. This allows the driver +* to signal whether it is ready to enter the Low Power mode. If any of the +* callbacks of the CY_SYSPM_SLEEP type with the CY_SYSPM_CHECK_READY parameter +* returns CY_SYSPM_FAIL, the remaining callback of the CY_SYSPM_SLEEP type with +* the CY_SYSPM_CHECK_READY parameter calls are skipped. +* After CY_SYSPM_FAIL, all the CY_SYSPM_SLEEP callbacks with +* the CY_SYSPM_CHECK_FAIL parameter are executed. These are the callbacks +* of the CY_SYSPM_SLEEP type with the CY_SYSPM_CHECK_READY +* parameter that were previously executed before getting CY_SYSPM_FAIL. +* The Sleep mode is not entered and the Cy_SysPm_Sleep() function returns +* CY_SYSPM_FAIL. +* +* If all of the callbacks of the CY_SYSPM_SLEEP type with the +* CY_SYSPM_CHECK_READY parameter calls return CY_SYSPM_SUCCESS, then all +* callbacks of the CY_SYSPM_SLEEP type with the CY_SYSPM_CHECK_FAIL parameters +* calls are skipped. Also, all callbacks of the CY_SYSPM_SLEEP type and +* CY_SYSPM_BEFORE_TRANSITION parameter calls are executed, allowing the +* peripherals to prepare for Sleep. The CPU then enters Sleep mode. +* This is a CPU-centric power mode. This means that the CPU has entered Sleep +* mode and its main clock is removed. It is identical to Active from a +* peripheral point of view. Any enabled interrupt can cause a wakeup from +* Sleep mode. +* +* After a wakeup from Sleep, all of the registered callbacks of the +* CY_SYSPM_SLEEP type and with the CY_SYSPM_AFTER_TRANSITION parameter are +* executed to return the peripherals to Active operation. The Cy_SysPm_Sleep() +* function returns CY_SYSPM_SUCCESS. +* No callbacks of the CY_SYSPM_SLEEP type with the CY_SYSPM_BEFORE_TRANSITION +* parameter or callbacks of the CY_SYSPM_SLEEP type and +* CY_SYSPM_AFTER_TRANSITION parameter callbacks are executed if Sleep mode +* is not entered. +* +* \note The last callback that returned CY_SYSPM_FAIL is not executed with the +* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. +* +* The return values from executed callback functions with the +* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION +* modes are ignored. +* +* \ref cy_en_syspm_callback_mode_t, except the CY_SYSPM_CHECK_READY, are ignored +* +* \param waitFor Selects wait for action. See \ref cy_en_syspm_waitfor_t. +* +* \return +* Entered status, see \ref cy_en_syspm_status_t. +* +* \sideeffect +* This function clears the Event Register of CM4 core after wakeup from WFE. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Sleep +* +*******************************************************************************/ +cy_en_syspm_status_t Cy_SysPm_Sleep(cy_en_syspm_waitfor_t waitFor) +{ + uint32_t interruptState; + cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; + + CY_ASSERT_L3(CY_SYSPM_IS_WAIT_FOR_VALID(waitFor)); + + /* Call registered callback functions with CY_SYSPM_CHECK_READY parameter */ + if(0U != curRegisteredCallbacks) + { + retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_CHECK_READY); + } + + /* The device (core) can switch into the sleep power mode only when + * all executed registered callback functions with the CY_SYSPM_CHECK_READY + * parameter returned CY_SYSPM_SUCCESS. + */ + if(retVal == CY_SYSPM_SUCCESS) + { + /* Call the registered callback functions with + * CY_SYSPM_BEFORE_TRANSITION parameter. The return value should be + * CY_SYSPM_SUCCESS. + */ + interruptState = Cy_SysLib_EnterCriticalSection(); + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_BEFORE_TRANSITION); + } + + /* The CPU enters the Sleep power mode upon execution of WFI/WFE */ + SCB->SCR = _CLR_SET_FLD32U((SCB->SCR), SCB_SCR_SLEEPDEEP, 0U); + + if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) + { + __WFI(); + } + else + { + __WFE(); + + #if(0u != CY_CPU_CORTEX_M4) + + /* For the CM4 core, the WFE instructions are called twice. + * The second WFE call clears the Event register of CM4 core. + * Cypress ID #279077. + */ + if(wasEventSent) + { + __WFE(); + } + + wasEventSent = true; + #endif /* (0u != CY_CPU_CORTEX_M4) */ + } + Cy_SysLib_ExitCriticalSection(interruptState); + + /* Call the registered callback functions with the + * CY_SYSPM_AFTER_TRANSITION parameter. The return value should be + * CY_SYSPM_SUCCESS. + */ + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_AFTER_TRANSITION); + } + } + else + { + /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to + * undo everything done in the callback with the CY_SYSPM_CHECK_READY + * parameter. The return value should be CY_SYSPM_SUCCESS. + */ + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_CHECK_FAIL); + retVal = CY_SYSPM_FAIL; + } + return retVal; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_DeepSleep +****************************************************************************//** +* +* Sets a CPU core to the Deep Sleep mode. +* +* Puts the core into the Deep Sleep power mode. Prior to entering the Deep Sleep +* mode, all callbacks of the CY_SYSPM_DEEPSLEEP type with the +* CY_SYSPM_CHECK_READY parameter registered callbacks are called, allowing the +* driver to signal whether it is ready to enter the power mode. If any +* CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_READY parameter call returns +* CY_SYSPM_FAIL, the remaining callback CY_SYSPM_DEEPSLEEP type with the +* CY_SYSPM_CHECK_READY parameter calls are skipped. After a CY_SYSPM_FAIL, all +* of the callbacks of the CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_FAIL +* parameter are executed that correspond to the callbacks with +* CY_SYSPM_DEEPSLEEP type with CY_SYSPM_CHECK_READY parameter calls that +* occurred up to the point of failure. +* The Deep Sleep mode is not entered and the Cy_SysPm_DeepSleep() function +* returns CY_SYSPM_FAIL. +* +* If all callbacks of the CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_READY +* parameter calls return CY_SYSPM_SUCCESS, then all callbacks of the +* CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_FAIL parameter calls are +* skipped and all callbacks of the CY_SYSPM_DEEPSLEEP type with the +* CY_SYSPM_BEFORE_TRANSITION parameter calls are executed, allowing the +* peripherals to prepare for Deep Sleep. +* The Deep Sleep mode is then entered. Any enabled interrupt can cause a wakeup +* from the Deep Sleep mode. +* +* \note The last callback which returned CY_SYSPM_FAIL is not executed with the +* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. +* +* The return values from executed callback functions with the +* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION +* modes are ignored. +* +* If the firmware attempts to enter this mode before the system is ready (that +* is, when PWR_CONTROL.LPM_READY = 0), then the device will go into the (LP) +* Sleep mode instead and automatically enter Deep Sleep mode when the +* system is ready. +* +* The system puts the whole device into Deep Sleep mode when all the +* processor(s) is (are) in Deep Sleep, there are no busy peripherals, the +* debugger is not active, and the Deep Sleep circuits are +* ready (PWR_CONTROL.LPM_READY=1). +* +* The peripherals that do not need a clock or that receive a clock from their +* external interface (e.g. I2C/SPI) continue operating. All circuits using the +* current from Vccdpslp supply are under the current limitation, which is +* controlled by the Deep Sleep regulator. +* +* Wakeup occurs when an interrupt asserts from a Deep Sleep active peripheral. +* For more details, see the corresponding peripheral's datasheet. +* +* \note +* For multi-core devices, the second core, which did not participate in +* device wakeup, continues to execute the Deep Sleep instructions. Any Deep Sleep +* capable interrupt routed to this core can wake it. +* +* For more details about switching into the Deep Sleep power mode and debug, +* refer to the device TRM. +* +* A normal wakeup from the Deep Sleep power mode returns to either LPActive or +* Active, depending on the previous state and programmed behavior for the +* particular wakeup interrupt. +* +* After wakeup from Deep Sleep, all of the registered callbacks with +* CY_SYSPM_DEEPSLEEP type with CY_SYSPM_AFTER_TRANSITION are executed to return +* peripherals to Active operation. The Cy_SysPm_DeepSleep() function returns +* CY_SYSPM_SUCCESS. No callbacks are executed with CY_SYSPM_DEEPSLEEP type with +* CY_SYSPM_BEFORE_TRANSITION or CY_SYSPM_AFTER_TRANSITION parameter, if +* Deep Sleep mode was not entered. +* +* \param waitFor Selects wait for action. See \ref cy_en_syspm_waitfor_t. +* +* \sideeffect +* This side effect is applicable only for devices with UDB IP block available. +* You can obtain unpredictable behavior of the UDB block after the device wakeup +* from Deep Sleep. +* Unpredictable behavior scenario: +* * The first core saves non-retained UDB configuration registers and goes into +* the Deep Sleep (Cy_SysPm_DeepSleep() function). +* * These non-retained UDB configuration registers are modified in runtime by +* another (second) active core. +* * The second core saves non-retained UDB configuration registers and goes into +* the Deep Sleep (Cy_SysPm_DeepSleep() function). +* These conditions save different values of the non-retained UDB configuration +* registers. The prevented scenario: on the first core wakeup, these registers +* are restored by the values saved on the first core. After the second core +* wakeup, these registers are "reconfigured" by the values saved on the second +* core. +* Be aware of this situation. +* +* \sideeffect +* This function clears the Event Register of CM4 core after wakeup from WFE. +* +* \sideeffect +* This side effect is applicable only for rev-08 of the CY8CKIT-062. +* The function changes the slow and fast clock dividers to +* SYSPM_CLK_DIVIDER right before entering into Deep Sleep and restores +* these dividers after wakeup. +* +* \return +* Entered status, see \ref cy_en_syspm_status_t. +* +* \note +* The FLL/PLL are not restored right before the CPU starts executing the +* instructions after Deep Sleep. This can affect the peripheral which is +* driven by PLL/FLL. Ensure that the PLL/FLL were properly restored (locked) +* after the wakeup from Deep Sleep. Refer to the +* \ref group_sysclk driver documentation driver for the information how to +* read the PLL/FLL lock statuses. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_DeepSleep +* +*******************************************************************************/ +cy_en_syspm_status_t Cy_SysPm_DeepSleep(cy_en_syspm_waitfor_t waitFor) +{ + uint32_t interruptState; + cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; + + CY_ASSERT_L3(CY_SYSPM_IS_WAIT_FOR_VALID(waitFor)); + + /* Call the registered callback functions with + * the CY_SYSPM_CHECK_READY parameter. + */ + if(0U != curRegisteredCallbacks) + { + retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_CHECK_READY); + } + + /* The device (core) can switch into the Deep Sleep power mode only when + * all executed registered callback functions with the CY_SYSPM_CHECK_READY + * parameter returned CY_SYSPM_SUCCESS. + */ + if(retVal == CY_SYSPM_SUCCESS) + { + /* Call the registered callback functions with the + * CY_SYSPM_BEFORE_TRANSITION parameter. The return value should be + * CY_SYSPM_SUCCESS. + */ + interruptState = Cy_SysLib_EnterCriticalSection(); + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_BEFORE_TRANSITION); + } + + #ifdef CY_IP_MXUDB + + static cy_stc_syspm_backup_regs_t regs; + + /* Check whether the UDB disabled on MMIO level */ + if (0UL != (PERI->GR[CY_MMIO_UDB_GROUP_NR].SL_CTL & PERI_UDB_SLAVE_ENABLED)) + { + + /* Save non-retained registers */ + SaveRegisters(®s); + } + #endif /* CY_IP_MXUDB */ + + #if defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) + + if (CY_SYSLIB_DEVICE_REV_0A == (uint32_t) Cy_SysLib_GetDeviceRevision()) + { + Cy_EnterDeepSleep(waitFor); + } + else + #endif /* defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) */ + { + cy_en_syspm_ldo_voltage_t curLdoVoltage; + + curLdoVoltage = Cy_SysPm_LdoGetVoltage(); + + /* Configure additional wakeup delay from Deep Sleep + * for 1.1 V LDO. Cypress ID #290172. + */ + if ((Cy_SysPm_LdoIsEnabled()) && (CY_SYSPM_LDO_VOLTAGE_1_1V == curLdoVoltage)) + { + SRSS->PWR_TRIM_WAKE_CTL = CY_SYSPM_SFLASH->PWR_TRIM_WAKE_CTL; + } + else + { + SRSS->PWR_TRIM_WAKE_CTL = 0UL; + } + + /* Set the core into Deep Sleep */ + EnterDeepSleep(waitFor); + } + + #ifdef CY_IP_MXUDB + + /* Do not restore the UDB if it is disabled on MMIO level */ + if (0UL != (PERI->GR[CY_MMIO_UDB_GROUP_NR].SL_CTL & PERI_UDB_SLAVE_ENABLED)) + { + /* Restore non-retained registers */ + RestoreRegisters(®s); + } + #endif /* CY_IP_MXUDB */ + + Cy_SysLib_ExitCriticalSection(interruptState); + + /* Call the registered callback functions with the CY_SYSPM_AFTER_TRANSITION + * parameter. The return value should be CY_SYSPM_SUCCESS. + */ + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_AFTER_TRANSITION); + } + } + else + { + /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to + * undo everything done in the callback with the CY_SYSPM_CHECK_READY + * parameter. The return value should be CY_SYSPM_SUCCESS. + */ + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_CHECK_FAIL); + retVal = CY_SYSPM_FAIL; + } + return retVal; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_Hibernate +****************************************************************************//** +* +* Sets the device into Hibernate mode. +* +* Puts the core into the Hibernate power mode. Prior to entering Hibernate +* mode, all callbacks of the CY_SYSPM_HIBERNATE type are executed. +* First, callbacks of the CY_SYSPM_HIBERNATE type and with +* CY_SYSPM_CHECK_READY parameter are called, allowing the driver to signal if it +* is not ready to enter the power mode. If any of the callbacks of the +* CY_SYSPM_HIBERNATE type with the CY_SYSPM_CHECK_READY parameter call returns +* CY_SYSPM_FAIL, the remaining CY_SYSPM_HIBERNATE callbacks with the +* CY_SYSPM_CHECK_READY parameter calls are skipped. After CY_SYSPM_FAIL, all +* of the CY_SYSPM_HIBERNATE callbacks with CY_SYSPM_CHECK_FAIL parameter are +* executed that correspond to the CY_SYSPM_HIBERNATE callbacks with +* CY_SYSPM_CHECK_READY parameter calls that occurred up to the point of failure. +* Hibernate mode is not entered and the Cy_SysPm_Hibernate() function +* returns CY_SYSPM_FAIL. +* +* If all CY_SYSPM_HIBERNATE callbacks with the CY_SYSPM_CHECK_READY parameter +* calls return CY_SYSPM_SUCCESS, then all CY_SYSPM_HIBERNATE callbacks with +* CY_SYSPM_CHECK_FAIL calls are skipped and all CY_SYSPM_HIBERNATE callbacks +* CY_SYSPM_BEFORE_TRANSITION parameter calls are executed allowing the +* peripherals to prepare for Hibernate. The I/O output state is frozen and +* Hibernate mode is then entered. In Hibernate mode, all internal supplies +* are off and no internal state is retained. There is no handshake with the +* CPUs and the chip will enter Hibernate immediately. +* +* The I/O output state is frozen and Hibernate mode is then +* entered. In Hibernate mode, all internal supplies are off and no +* internal state is retained. +* For multi-core devices there is no handshake with the CPUs and the chip +* will enter Hibernate power mode immediately. +* +* \note The last callback that returned CY_SYSPM_FAIL is not executed with the +* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. +* +* The return values from executed callback functions with the +* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION +* modes are ignored. +* +* A wakeup from Hibernate is triggered by toggling the wakeup pin(s), a WDT +* match, or back-up domain alarm expiration, depending on how the they were +* configured. A wakeup causes a normal boot procedure. +* To configure the wakeup pin(s), a Digital Input Pin must be configured, and +* resistively pulled up or down to the inverse state of the wakeup polarity. To +* distinguish a wakeup from Hibernate mode and a general reset event, the +* Cy_SysLib_GetResetReason() function can be used. The wakeup pin and low-power +* comparators are active-low by default. The wakeup pin or the LPComparators +* polarity can be changed with the \ref Cy_SysPm_SetHibernateWakeupSource() function. +* This function call will not return if Hibernate mode is entered. +* The CY_SYSPM_HIBERNATE callbacks with the CY_SYSPM_AFTER_TRANSITION parameter +* are never executed. +* +* This function freezes the I/O cells implicitly. Entering +* Hibernate mode before freezing the I/O cells is not possible. The I/O cells remain frozen +* after waking from Hibernate mode until the firmware unfreezes them +* with a \ref Cy_SysPm_IoUnfreeze() function call. +* +* \return +* Entered status, see \ref cy_en_syspm_status_t. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Hibernate +* +*******************************************************************************/ +cy_en_syspm_status_t Cy_SysPm_Hibernate(void) +{ + cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; + + /* Call the registered callback functions with the + * CY_SYSPM_CHECK_READY parameter + */ + if(0U != curRegisteredCallbacks) + { + retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_HIBERNATE, CY_SYSPM_CHECK_READY); + } + + /* The device (core) can switch into Hibernate power mode only when + * all executed registered callback functions with CY_SYSPM_CHECK_READY + * parameter returned CY_SYSPM_SUCCESS. + */ + if(retVal == CY_SYSPM_SUCCESS) + { + /* Call registered callback functions with CY_SYSPM_BEFORE_TRANSITION + * parameter. Return value should be CY_SYSPM_SUCCESS. + */ + (void) Cy_SysLib_EnterCriticalSection(); + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_HIBERNATE, CY_SYSPM_BEFORE_TRANSITION); + } + + /* Preserve the token that will retain through a wakeup sequence + * thus could be used by Cy_SysLib_GetResetReason() to differentiate + * Wakeup from a general reset event. + * Preserve the wakeup source(s) configuration. + */ + SRSS->PWR_HIBERNATE = + (SRSS->PWR_HIBERNATE & CY_SYSPM_PWR_WAKEUP_HIB_MASK) | CY_SYSPM_PWR_TOKEN_HIBERNATE; + + /* Freeze I/O-Cells to save I/O-Cell state */ + Cy_SysPm_IoFreeze(); + + SRSS->PWR_HIBERNATE |= CY_SYSPM_PWR_SET_HIBERNATE; + + /* Read register to make sure it is settled */ + (void) SRSS->PWR_HIBERNATE; + + /* Wait for transition */ + __WFI(); + + /* The callback functions calls with the CY_SYSPM_AFTER_TRANSITION + * parameter in the Hibernate power mode are not applicable as device + * wake-up was made on device reboot. + */ + + /* A wakeup from Hibernate is performed by toggling of the wakeup + * pins, or WDT matches, or Backup domain alarm expires. This depends on what + * item is configured in the hibernate register. After a wakeup event, a + * normal Boot procedure occurs. + * There is no need to exit from the critical section. + */ + } + else + { + /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to + * undo everything done in the callback with the CY_SYSPM_CHECK_READY + * parameter. The return value should be CY_SYSPM_SUCCESS. + */ + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_HIBERNATE, CY_SYSPM_CHECK_FAIL); + retVal = CY_SYSPM_FAIL; + } + return retVal; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_EnterLowPowerMode +****************************************************************************//** +* +* This function switches only the supply regulators into Low Power mode. +* You must configure +* clocks and/or peripherals to meet current load limitations in LP Active. +* For more details about power modes and current load limitations refer to +* the device technical reference manual (TRM). +* +* The LPActive mode is similar to the Active mode. +* The difference is that the current is limited and some functions have limited +* features/performance. +* +* The key feature of the Low Power mode is the limited current. Restrictions are +* placed on the clock frequencies and allow the peripherals to achieve +* a current limit. +* +* Before entering Low Power mode, you must configure the system so +* the total current drawn from Vccd is less that the value presented in the +* technical reference manual (TRM). Refer to the TRM for the maximum load for +* low power operation and clock limitations in Low Power mode with different +* core supply regulator voltages. +* +* * Peripherals can use the knowledge of the LPActive mode to make +* trade-offs that consume less current. For more details, see the corresponding +* peripherals' datasheet. +* * High-speed clock sources are available with the appropriate pre-divider +* settings to limit the system current. +* Refer to the TRM for the maximum frequency values for low power operation +* using different Core Regulators' output voltages. +* +* This function puts the device into Low Power mode. Prior to entering Low Power mode, +* all the registered CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with CY_SYSPM_CHECK_READY +* parameter are called. This allows the driver to signal if it is not ready to +* enter Low Power mode. If any CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with the +* CY_SYSPM_CHECK_READY parameter call returns CY_SYSPM_FAIL, the remaining +* CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with the CY_SYSPM_CHECK_READY parameter +* calls are skipped. +* +* After a CY_SYSPM_FAIL, all of the CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with +* CY_SYSPM_CHECK_FAIL parameter are executed that correspond to the +* CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with CY_SYSPM_CHECK_READY parameter calls +* that occurred up to the point of failure. Low Power mode is not entered and +* the Cy_SysPm_EnterLowPowerMode() function returns CY_SYSPM_FAIL. +* +* If all CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with the CY_SYSPM_CHECK_READY +* parameter calls return CY_SYSPM_SUCCESS, then all CY_SYSPM_ENTER_LOWPOWER_MODE +* callbacks with CY_SYSPM_CHECK_FAIL calls are skipped and all +* CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION parameter +* calls are executed. This allows the peripherals to prepare for low power. +* Low Power mode is then entered. +* +* After entering Low Power mode, all of the registered +* CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with the CY_SYSPM_AFTER_TRANSITION parameter +* are executed to complete preparing the peripherals for low power operation. +* The Cy_SysPm_EnterLowPowerMode() function returns CY_SYSPM_SUCCESS. +* No CY_SYSPM_ENTER_LOWPOWER_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION or +* CY_SYSPM_AFTER_TRANSITION parameter are executed, if Low Power mode is not +* entered. +* +* \note The last callback that returned CY_SYSPM_FAIL is not executed with +* the CY_SYSPM_CHECK_FAIL parameter because of the FAIL. +* +* The return values from executed callback functions with the +* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION +* modes are ignored. +* +* \note The callbacks are not executed if the device is already not in +* Low Power mode. +* +* \return +* See \ref cy_en_syspm_status_t.
+* CY_SYSPM_SUCCESS - Entered the LPActive mode or the device is already +* in LPActive.
+* CY_SYSPM_FAIL - The LPActive mode is not entered or low power circuits +* are not ready to enter Low Power mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_EnterLowPowerMode +* +*******************************************************************************/ +cy_en_syspm_status_t Cy_SysPm_EnterLowPowerMode(void) +{ + uint32_t interruptState; + cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; + + /* Check whether device is in the low power mode. */ + if(0U == (_FLD2VAL(SRSS_PWR_CTL_ACT_REF_DIS, SRSS->PWR_CTL))) + { + /* The entering into the low power mode is permitted when low + * power circuits are ready to enter into the low power mode. + */ + if(0U != _FLD2VAL(SRSS_PWR_CTL_LPM_READY, SRSS->PWR_CTL)) + { + /* Call the registered callback functions with the + * CY_SYSPM_CHECK_READY parameter. + */ + if(0U != curRegisteredCallbacks) + { + retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LOWPOWER_MODE, CY_SYSPM_CHECK_READY); + } + + /* The device (core) can switch into the low power mode only when + * all executed registered callback functions with the + * CY_SYSPM_CHECK_READY parameter returned CY_SYSPM_SUCCESS. + */ + if(retVal == CY_SYSPM_SUCCESS) + { + + /* Call the registered callback functions with the + * CY_SYSPM_BEFORE_TRANSITION parameter. The return value + * should be CY_SYSPM_SUCCESS. + */ + interruptState = Cy_SysLib_EnterCriticalSection(); + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LOWPOWER_MODE, CY_SYSPM_BEFORE_TRANSITION); + } + + /* Configure the low-power operating mode for LDO regulator */ + if(Cy_SysPm_LdoIsEnabled()) + { + SRSS->PWR_CTL |= (_VAL2FLD(SRSS_PWR_CTL_LINREG_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_PORBOD_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_BGREF_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_VREFBUF_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_IREF_LPMODE, 1U)); + } + else + { + /* Configure the low-power operating mode for Buck regulator */ + SRSS->PWR_CTL |= (_VAL2FLD(SRSS_PWR_CTL_PORBOD_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_BGREF_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_VREFBUF_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_IREF_LPMODE, 1U)); + } + + /* This wait time allows the circuits to remove their dependence on + * the Active mode circuits, such as Active Reference. + */ + Cy_SysLib_DelayUs(CY_SYSPM_ACTIVE_TO_LP_WAIT_US); + + /* Disabling active reference */ + SRSS->PWR_CTL |= _VAL2FLD(SRSS_PWR_CTL_ACT_REF_DIS, 1U); + + Cy_SysLib_ExitCriticalSection(interruptState); + + /* Call the registered callback functions with the + * CY_SYSPM_AFTER_TRANSITION parameter. The return value + * should be CY_SYSPM_SUCCESS. + */ + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LOWPOWER_MODE, CY_SYSPM_AFTER_TRANSITION); + } + } + else + { + /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to + * undo everything done in the callback with the CY_SYSPM_CHECK_READY + * parameter. The return value should be CY_SYSPM_SUCCESS. + */ + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LOWPOWER_MODE, CY_SYSPM_CHECK_FAIL); + retVal = CY_SYSPM_FAIL; + } + } + else + { + retVal = CY_SYSPM_FAIL; + } + } + else + { + /* Do nothing because the device is already in Low Power mode. */ + } + return retVal; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_ExitLowPowerMode +****************************************************************************//** +* +* Exits the device from Low Power mode. +* +* Returns the device to the Active mode. In the Active power mode, the operating +* current can be increased to the normal mode limit. The clock frequencies also +* can be increased to the normal mode limit. Refer to the device TRM for the +* current and frequency limitations in the Active power mode. +* +* Prior to exiting Low Power mode, all the registered CY_SYSPM_EXIT_LOWPOWER_MODE +* callbacks with the CY_SYSPM_CHECK_READY parameter are called. This allows +* the driver to signal if it is not ready to exit +* Low Power mode. If any CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with +* the CY_SYSPM_CHECK_READY parameter call returns CY_SYSPM_FAIL, the remaining +* CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with the CY_SYSPM_CHECK_READY parameter calls +* are skipped. After a CY_SYSPM_FAIL, all of the CY_SYSPM_EXIT_LOWPOWER_MODE callbacks +* with CY_SYSPM_CHECK_FAIL parameter are executed that correspond to the +* CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with CY_SYSPM_CHECK_READY parameter calls that +* occurred up to the point of failure. Active mode is not entered and the +* Cy_SysPm_ExitLowPowerMode() function returns CY_SYSPM_FAIL. +* +* If all CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with CY_SYSPM_CHECK_READY calls return +* CY_SYSPM_SUCCESS, then all the CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with +* the CY_SYSPM_CHECK_FAIL parameter calls are skipped and all +* CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION parameter +* calls are executed allowing the peripherals to prepare for Active mode. +* Low Power mode is then exited. +* +* After exiting Low Power mode, all of the registered callbacks that have +* type CY_SYSPM_EXIT_LOWPOWER_MODE are executed with the CY_SYSPM_AFTER_TRANSITION +* parameter to complete preparing the peripherals for Active mode operation. +* The Cy_SysPm_ExitLowPowerMode() function returns CY_SYSPM_SUCCESS. +* No CY_SYSPM_EXIT_LOWPOWER_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION or +* CY_SYSPM_AFTER_TRANSITION parameter are executed if Low Power mode is +* not exited. +* +* \note The last callback that returned CY_SYSPM_FAIL is not executed with the +* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. +* +* The return values from executed callback functions with the +* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION +* modes are ignored. +* +* \note The callbacks are not executed if the device is not already in Low +* Power mode. +* +* \return +* See \ref cy_en_syspm_status_t.
+* CY_SYSPM_SUCCESS - Exited from the LPActive power mode, or the device is +* already in Active mode.
+* CY_SYSPM_FAIL - Exit from the LPActive mode is not done. +* +* \warning This function blocks as it waits until Active Reference is ready +* to enter to the normal mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_ExitLowPowerMode +* +*******************************************************************************/ +cy_en_syspm_status_t Cy_SysPm_ExitLowPowerMode(void) +{ + uint32_t interruptState; + uint32_t timeOut = CY_SYSPM_WAIT_DELAY_TRYES; + cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; + + /* Check if the device is in the low power mode */ + if(0U != (_FLD2VAL(SRSS_PWR_CTL_ACT_REF_DIS, SRSS->PWR_CTL))) + { + /* Call the registered callback functions with the + * CY_SYSPM_CHECK_READY parameter. + */ + if(0U != curRegisteredCallbacks) + { + retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LOWPOWER_MODE, CY_SYSPM_CHECK_READY); + } + + /* The device (core) can switch into the Low Power mode only in the + * condition that all executed registered callback functions with the + * CY_SYSPM_CHECK_READY parameter return CY_SYSPM_SUCCESS. + */ + if(retVal == CY_SYSPM_SUCCESS) + { + /* Call the registered callback functions with the + * CY_SYSPM_BEFORE_TRANSITION parameter. The return value should be + * CY_SYSPM_SUCCESS. + */ + interruptState = Cy_SysLib_EnterCriticalSection(); + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LOWPOWER_MODE, CY_SYSPM_BEFORE_TRANSITION); + } + + /* Set the normal operation mode for LDO regulator if + * it is enabled + */ + if(Cy_SysPm_LdoIsEnabled()) + { + SRSS->PWR_CTL &= ((uint32_t)~(SRSS_PWR_CTL_LINREG_LPMODE_Msk)); + } + + /* Configure the normal operating mode for the POR/BOD circuits and + * for the Bandgap Voltage and Current References + */ + SRSS->PWR_CTL &= ((uint32_t)~(_VAL2FLD(SRSS_PWR_CTL_PORBOD_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_ACT_REF_DIS, 1U) | + _VAL2FLD(SRSS_PWR_CTL_VREFBUF_LPMODE, 1U) | + _VAL2FLD(SRSS_PWR_CTL_IREF_LPMODE, 1U))); + + /* This wait time allows setting Active Reference */ + Cy_SysLib_DelayUs(CY_SYSPM_LP_TO_ACTIVE_WAIT_BEFORE_US); + + while((0U == _FLD2VAL(SRSS_PWR_CTL_ACT_REF_OK, SRSS->PWR_CTL)) && (0U != timeOut)) + { + timeOut--; + } + + if(0U == timeOut) + { + retVal = CY_SYSPM_TIMEOUT; + + Cy_SysLib_ExitCriticalSection(interruptState); + } + else + { + /* Configure the normal operation mode */ + SRSS->PWR_CTL &= ((uint32_t) (~SRSS_PWR_CTL_BGREF_LPMODE_Msk)); + + /* This wait time allows setting Active Reference */ + Cy_SysLib_DelayUs(CY_SYSPM_LP_TO_ACTIVE_WAIT_AFTER_US); + + Cy_SysLib_ExitCriticalSection(interruptState); + + /* Call registered callback functions with CY_SYSPM_AFTER_TRANSITION + * parameter. Return value should be CY_SYSPM_SUCCESS. + */ + if(0U != curRegisteredCallbacks) + { + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LOWPOWER_MODE, CY_SYSPM_AFTER_TRANSITION); + } + } + + } + else + { + /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to + * undo everything done in the callback with the CY_SYSPM_CHECK_READY + * parameter. The return value should be CY_SYSPM_SUCCESS. + */ + (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LOWPOWER_MODE, CY_SYSPM_CHECK_FAIL); + retVal = CY_SYSPM_FAIL; + } + } + else + { + /* Do nothing because the device is already in the Active power mode */ + } + return retVal; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_SleepOnExit +****************************************************************************//** +* +* This function configures the Sleep-on-exit feature of the core. +* +* This API sets the SLEEPONEXIT bit of the SCR register. +* +* When the Sleep-on-exit feature is enabled (SLEEPONEXIT bit is set), +* the core wakes up to service the interrupt and then immediately goes +* back to sleep. Because of this, the unstacking process is not carried out, so +* this feature is useful for the interrupt driven application and helps to +* reduce the unnecessary stack push and pop operations. +* The core does not go to sleep if the interrupt handler returns to +* another interrupt handler (nested interrupt). +* You can use this feature in applications that require only the core to run +* when an interrupt occurs. +* +* When the Sleep-on-exit feature is disabled (SLEEPONEXIT bit is cleared), +* the core returns back to the main thread after servicing the interrupt +* without going back to sleep. +* +* Refer to the ARM documentation about the Sleep-on-exit feature and +* SLEEPONEXIT of the SCR register. +* +* \param enable +* true - enable Sleep-on-exit feature
false - disable +* Sleep-on-exit feature. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_SleepOnExit +* +*******************************************************************************/ +void Cy_SysPm_SleepOnExit(bool enable) +{ + uint32_t interruptState; + interruptState = Cy_SysLib_EnterCriticalSection(); + + if(enable) + { + /* Enable Sleep-on-exit mode */ + SCB->SCR |= _VAL2FLD(SCB_SCR_SLEEPONEXIT, 1U); + } + else + { + /* Disable Sleep-on-exit mode */ + SCB->SCR &= ((uint32_t) ~(SCB_SCR_SLEEPONEXIT_Msk)); + } + Cy_SysLib_ExitCriticalSection(interruptState); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_SetHibernateWakeupSource +****************************************************************************//** +* +* This function configures sources to wake up the device from the Hibernate +* power mode. Such sources can be wakeup pins, LPComparators, Watchdog (WDT) +* interrupt, or a Real-Time clock (RTC) alarm (interrupt). +* +* Wakeup pins: +* +* A wakeup is supported by up to two pins with programmable polarity. These pins +* may be connected to the I/O pins or on-chip peripherals under some conditions. +* Setting the wakeup pin to this level will cause a wakeup from Hibernate +* mode. The wakeup pins are active/low by default. +* +* LPComparators: +* +* A wakeup is supported by up to two LPComps with programmable polarity. These +* LPComp may be connected to the I/O pins or on-chip peripherals under some +* conditions. +* Setting the LPComp to this level will cause a wakeup from Hibernate +* mode. The wakeup LPComp are active-low by default. +* +* \note The low-power comparators should be configured and enabled before +* switching into the hibernate low power mode. Refer to the LPComp +* driver description for more details. +* +* Watchdog Timer: +* +* \note The WDT should be configured and enabled before entering into the +* Hibernate power mode. +* +* A wakeup is performed by a WDT interrupt and a normal boot procedure +* after a device reset. The device can wake up from Hibernate after a WDT +* device reset, if the WDT was configured to wake up, the device on its +* interrupt and WDT was enabled. +* +* Real-time Clock: +* +* A wakeup is performed by the RTC alarm and a normal boot procedure +* after a device reset. +* Refer to the Real-Time Clock (RTC) driver description for more details. +* +* For information about wakeup sources and their assignment in the specific +* families devices, refer to the appropriate device TRM. +* +* \param wakeupSource +* The source to be configured as a wakeup source from +* the Hibernate power mode, see \ref cy_en_syspm_hibernate_wakeup_source_t. +* The input parameters values can be ORed. For example, if you want to set +* LPComp0 (active high) and WDT, call this function: +* Cy_SysPm_SetHibernateWakeupSource(CY_SYSPM_HIBERNATE_LPCOMP0_HIGH | CY_SYSPM_HIBERNATE_WDT). +* +* \warning Do not call this function with different polarity levels for the same +* wakeup source. For example, do not call a function like this: +* Cy_SysPm_SetHibernateWakeupSource(CY_SYSPM_HIBERNATE_LPCOMP0_LOW, CY_SYSPM_HIBERNATE_LPCOMP0_HIGH); +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_SetHibernateWakeupSource +* +*******************************************************************************/ +void Cy_SysPm_SetHibernateWakeupSource(uint32_t wakeupSource) +{ + CY_ASSERT_L3(CY_SYSPM_IS_WAKE_UP_SOURCE_VALID(wakeupSource)); + + /* Reconfigure the wake-up pins and LPComp polarity based on the input */ + if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_LPCOMP0)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP0_BIT)); + } + + if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_LPCOMP1)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP1_BIT)); + } + + if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_PIN0)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN0_BIT)); + } + + if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_PIN1)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN1_BIT)); + } + + SRSS->PWR_HIBERNATE |= ((uint32_t) wakeupSource); + + /* Read register to make sure it is settled */ + (void) SRSS->PWR_HIBERNATE; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_ClearHibernateWakeupSource +****************************************************************************//** +* +* This function disables a wakeup source that was previously configured to +* wake up the device from the hibernate power mode. +* +* \param wakeupSource +* For the source to be disabled, see \ref cy_en_syspm_hibernate_wakeup_source_t. +* The input parameters values can be ORed. For example, if you want to disable +* LPComp0 (active high) and WDT call this function: +* Cy_SysPm_ClearHibernateWakeupSource(CY_SYSPM_HIBERNATE_LPCOMP0_HIGH | CY_SYSPM_HIBERNATE_WDT). +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_ClearHibernateWakeupSource +* +*******************************************************************************/ +void Cy_SysPm_ClearHibernateWakeupSource(uint32_t wakeupSource) +{ + uint32_t clearWakeupSource; + + CY_ASSERT_L3(CY_SYSPM_IS_WAKE_UP_SOURCE_VALID(wakeupSource)); + + if (0U != _FLD2VAL(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, wakeupSource)) + { + /* Clear the high active level of the requested sources */ + if((uint32_t) CY_SYSPM_HIBERNATE_LPCOMP0_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_HIBERNATE_LPCOMP0_HIGH)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP0_BIT)); + } + + if((uint32_t) CY_SYSPM_HIBERNATE_LPCOMP1_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_HIBERNATE_LPCOMP1_HIGH)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP1_BIT)); + } + + if((uint32_t) CY_SYSPM_HIBERNATE_PIN0_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_HIBERNATE_PIN0_HIGH)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN0_BIT)); + } + + if((uint32_t) CY_SYSPM_HIBERNATE_PIN1_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_HIBERNATE_PIN1_HIGH)) + { + SRSS->PWR_HIBERNATE &= + ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN1_BIT)); + } + } + + /* Remove the polarity bits from the input value */ + clearWakeupSource = ((uint32_t) wakeupSource & ((uint32_t) ~ SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Msk)); + + SRSS->PWR_HIBERNATE &= ((uint32_t) ~ clearWakeupSource); + + /* Read register to make sure it is settled */ + (void) SRSS->PWR_HIBERNATE; +} + + +#if(0u != SRSS_BUCKCTL_PRESENT) + /******************************************************************************* + * Function Name: Cy_SysPm_BuckEnable + ****************************************************************************//** + * + * Switch the power supply regulator to Buck regulator instead of the LDO. + * The Buck core regulator provides output voltage(s) using one external + * inductor and can supply Vccd with higher efficiency than the LDO under some + * conditions, such as high external supply voltage. + * + * Before changing from LDO to Buck, ensure that the circuit board has + * connected Vccbuck1 to Vccd and also populated the + * necessary external components for the Buck regulator, including an + * inductor and a capacitor for each output. + * Refer to the device TRM for more details. + * + * When changing from a higher voltage to a lower voltage + * (from LDO 1.1V to Buck 0.9V), ensure that: + * * The device maximum operating frequency for all the Clk_HF paths, peripheral, + * and slow clock are under the ULP limitations. + * * The total current consumption is under the ULP limitations. + * + * * The appropriate wait states values are set for the flash using + * the Cy_SysLib_SetWaitStates() function as explained below. + * + * Setting wait states values for flash + * + * The flash access time when the core output voltage is 0.9 V (nominal) is + * longer than at 1.1 V (nominal). Therefore, the number of the wait states must + * be adjusted. Use the Cy_SysLib_SetWaitStates() function to set the appropriate + * wait state values for flash. + * + * To change from a higher voltage (LDO 1.1 V) to a lower voltage (Buck 0.9 V), + * call the Cy_SysLib_SetWaitStates(true, hfClkFreqMz) function before changing + * the voltage, where hfClkFreqMz is the frequency of HfClk0 in MHz. + * + * To change from a lower voltage (LDO 0.9 V) to a higher voltage (Buck 1.1 V), + * calling the Cy_SysLib_SetWaitStates(false, hfClkFreqMz) function is to set + * the wait states is optional, but can be done to improve the performance. + * The clock frequency may now be increased up to LP mode for a new voltage. + * + * \note 1. The final Buck output is set to 0.9 V (nominal) - the flash works + * in the Read-only operation. + * \note 2. The final Buck output is set to 1.1 V (nominal) - the flash works + * in the Read and Write operations. + * \note 3. The actual device Vccd voltage can be different from the nominal + * voltage because the actual voltage value depends on the conditions + * including the load current. + * + * \warning There is no way to go back to the LDO after the + * Buck regulator supplies a core. The function switches off the LDO. + * + * For more details refer to the \ref group_syspm_managing_core_regulators + * section. + * Refer to the \ref group_syslib driver for more details about setting the wait + * states. + * + * \note + * The function is applicable for devices with the Buck regulator. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckEnable + * + *******************************************************************************/ + void Cy_SysPm_BuckEnable(cy_en_syspm_buck_voltage1_t voltage) + { + CY_ASSERT_L3(CY_SYSPM_IS_BUCK_VOLTAGE1_VALID(voltage)); + + uint32_t interruptState; + cy_en_syspm_ldo_voltage_t curLdoVoltage; + + curLdoVoltage = Cy_SysPm_LdoGetVoltage(); + interruptState = Cy_SysLib_EnterCriticalSection(); + + /* When the LDO is 1.1V and final target Buck 0.9V need to update the + * RAM and ROM trim values + */ + if ((CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V == voltage) && (CY_SYSPM_LDO_VOLTAGE_1_1V == curLdoVoltage)) + { + /* Set the analog signal bit for the flash before the voltage is + * changed from 1.1V to 0.9V + */ + SetVoltageBitForFlash(); + + /* Update read-write margin value for the ULP mode */ + SetReadMarginTrimUlp(); + + /* Reduce LDO output voltage to 0.95 V nominal */ + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_0_95V); + + /* Update write assist value for the ULP mode */ + SetWriteAssistTrimUlp(); + } + /* When the LDO is 0.9V and final target Buck 1.1 V need to update the + * RAM and ROM trim values + */ + else if ((CY_SYSPM_BUCK_OUT1_VOLTAGE_1_1V == voltage) && (CY_SYSPM_LDO_VOLTAGE_0_9V == curLdoVoltage)) + { + /* Increase LDO to 0.95 V */ + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_0_95V); + + /* Wait until regulator is stable */ + Cy_SysLib_DelayUs(LDO_STABILIZATION_DELAY_US); + + /* Update write assist value for the LP mode */ + SetWriteAssistTrimLp(); + + /* Increase LDO to 1.1 V */ + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_1_1V); + + /* Wait until regulator is stable */ + Cy_SysLib_DelayUs(LDO_STABILIZATION_DELAY_US); + + /* Update read-write margin value for the LP mode */ + SetReadMarginTrimLp(); + + /* Set the LDO 1.15V as final Buck output is 1.1 V */ + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_1_15V); + + /* Clear the analog signal bit for the flash before the voltage is + * changed from 1.1 V to 0.9 V + */ + ClearVoltageBitForFlash(); + } + /* If LDO is 0.9V and final Buck is 0.9V increase the LDO on 50 mV*/ + else if ((CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V == voltage) && (CY_SYSPM_LDO_VOLTAGE_0_9V == curLdoVoltage)) + { + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_0_95V); + } + /* If LDO is 1.1V and final Buck is 1.1 V increase the LDO on 50 mV*/ + else + { + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_1_15V); + } + + /* A delay for the supply to stabilize at the new higher voltage */ + Cy_SysLib_DelayUs(LDO_STABILIZATION_DELAY_US); + + /* Disable the Deep Sleep, nWell, and Retention regulators */ + SRSS->PWR_CTL |= (_VAL2FLD(SRSS_PWR_CTL_DPSLP_REG_DIS, 1U) | + _VAL2FLD(SRSS_PWR_CTL_RET_REG_DIS, 1U) | + _VAL2FLD(SRSS_PWR_CTL_NWELL_REG_DIS, 1U)); + + /* Configure the Buck regulator */ + SRSS->PWR_BUCK_CTL = + _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL), SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, (uint32_t) voltage); + + /* Check whether the Buck regulator is already enabled */ + if(!Cy_SysPm_BuckIsEnabled()) + { + SRSS->PWR_BUCK_CTL |= _VAL2FLD(SRSS_PWR_BUCK_CTL_BUCK_EN, 1U); + } + + SRSS->PWR_BUCK_CTL |= _VAL2FLD(SRSS_PWR_BUCK_CTL_BUCK_OUT1_EN, 1U); + + /* Wait until Buck output 1 is stable */ + Cy_SysLib_DelayUs(CY_SYSPM_BUCK_CORE_SUPPLY_STABLE_US); + + /* Disable the LDO, because Vbuckout1 and LDO are shorted */ + SRSS->PWR_CTL |= _VAL2FLD(SRSS_PWR_CTL_LINREG_DIS, 1U); + + Cy_SysLib_ExitCriticalSection(interruptState); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckSetVoltage1 + ****************************************************************************//** + * + * Sets the output 1 voltage for the Buck regulator that can supply core(s). + * This output can supply cores instead of the LDO. + * + * When changing from a higher voltage to a lower voltage, ensure that: + * * The device maximum operating frequency for all the Clk_HF paths, peripheral, + * and slow clock are under the \ref group_syspm_ulp_limitations. + * * The total current consumption is under the \ref group_syspm_ulp_limitations. + * + * * The appropriate wait states values are set for the flash using + * the Cy_SysLib_SetWaitStates() function as explained below. + * + * Setting wait states values for flash + * + * The flash access time when the core output voltage is 0.9 V (nominal) is + * longer than at 1.1 V (nominal). Therefore, the number of the wait states must + * be adjusted. Use the Cy_SysLib_SetWaitStates() function to set the appropriate + * wait state values for flash. + * + * To change from a higher voltage to a lower voltage 0.9 V (nominal), + * call the Cy_SysLib_SetWaitStates(true, hfClkFreqMz) function before changing + * the voltage, where hfClkFreqMz is the frequency of HfClk0 in MHz. + * + * To change from a lower voltage to a higher voltage 1.1 V (nominal), calling + * the Cy_SysLib_SetWaitStates(false, hfClkFreqMz) function is to set the + * wait states is optional, but can be done to improve the performance. + * The clock frequency may now be increased up to + * \ref group_syspm_lp_limitations for a new voltage. + * + * \note 1. The output is set to 0.9 V (nominal) - the flash works in the + * Read-only operation. + * \note 2. The output is set to 1.1 V (nominal) - the flash works in the Read + * and Write operations. + * \note 3. The actual device Vccd voltage can be different from the nominal + * voltage because the actual voltage value depends on the conditions + * including the load current. + * + * For more details refer to the \ref group_syspm_managing_core_regulators + * section. + * Refer to the \ref group_syslib driver for more details about setting the + * wait states. + * + * \param voltage + * The desired output 1 regulator voltage (Vccbuck1). + * See \ref cy_en_syspm_buck_voltage1_t + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_VoltageRegulator + * + *******************************************************************************/ + void Cy_SysPm_BuckSetVoltage1(cy_en_syspm_buck_voltage1_t voltage) + { + CY_ASSERT_L3(CY_SYSPM_IS_BUCK_VOLTAGE1_VALID(voltage)); + + uint32_t interruptState; + interruptState = Cy_SysLib_EnterCriticalSection(); + + /* Check whether the required voltage is equal to the current voltage */ + if (voltage != Cy_SysPm_BuckGetVoltage1()) + { + + if (CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V == voltage) + { + /* Set the analog signal bit for the flash before the voltage is + * changed from 1.1 V to 0.9 V + */ + SetVoltageBitForFlash(); + + /* Update read-write margin value for the ULP mode */ + SetReadMarginTrimUlp(); + + /* Reduce Buck output voltage to 0.95V nominal */ + SRSS->PWR_BUCK_CTL = + _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL), SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, BUCK_OUT1_VOLTAGE_0_95V); + + /* Update write assist value for the ULP mode */ + SetWriteAssistTrimUlp(); + } + else + { + /* Increase Buck output voltage to 0.95 V nominal */ + SRSS->PWR_BUCK_CTL = + _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL), SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, BUCK_OUT1_VOLTAGE_0_95V); + + /* Wait until regulator is stable */ + Cy_SysLib_DelayUs(BUCK_STABILIZATION_DELAY_US); + + /* Update write assist value for the LP mode */ + SetWriteAssistTrimLp(); + } + + /* The system may continue operating while the voltage on Vccd + * discharges to the new voltage. The time it takes to reach the + * new voltage depends on the conditions, including the load current + * on Vccd and the external capacitor size. + */ + SRSS->PWR_BUCK_CTL = + _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL), SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, (uint32_t) voltage); + + /* Delay to stabilize at the new voltage is required only + * when changing from a lower voltage to a higher voltage. + */ + if(CY_SYSPM_BUCK_OUT1_VOLTAGE_1_1V == voltage) + { + Cy_SysLib_DelayUs(BUCK_STABILIZATION_DELAY_US); + + /* Update read-write margin value for the LP mode */ + SetReadMarginTrimLp(); + + /* Set analog signal bit for flash before voltage is changed + * from 0.9 V to 1.1 V. + */ + ClearVoltageBitForFlash(); + } + } + Cy_SysLib_ExitCriticalSection(interruptState); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckIsOutputEnabled + ****************************************************************************//** + * + * This function gets the current output status of the Buck outputs. + * + * \param output + * The Buck regulator output. See \ref cy_en_syspm_buck_out_t. + * + * \return + * The current state of the requested output. True if the requested output + * is enabled. + * False if the requested output is disabled. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckIsOutputEnabled + * + *******************************************************************************/ + bool Cy_SysPm_BuckIsOutputEnabled(cy_en_syspm_buck_out_t output) + { + CY_ASSERT_L3(CY_SYSPM_IS_BUCK_OUTPUT_VALID(output)); + + bool retVal = false; + + if (output == CY_SYSPM_BUCK_VBUCK_1) + { + retVal = (_FLD2BOOL(SRSS_PWR_BUCK_CTL_BUCK_OUT1_EN, SRSS->PWR_BUCK_CTL)); + } + + #if (0u != SRSS_SIMOBUCK_PRESENT) + if(output == CY_SYSPM_BUCK_VRF) + { + retVal = ((0U != _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, SRSS->PWR_BUCK_CTL2)) || + (0U != _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_EN, SRSS->PWR_BUCK_CTL2))); + } + #endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ + + return(retVal); + } + + #if(0u != SRSS_SIMOBUCK_PRESENT) + /******************************************************************************* + * Function Name: Cy_SysPm_BuckEnableVoltage2 + ****************************************************************************//** + * + * Enable the output 2 voltage (Vbuckrf) of the SIMO Buck regulator. + * The output 2 voltage (Vbuckrf) of the Buck regulator is used to supply + * the BLE HW block. + * When the Buck regulator is switched off, the function enables the + * regulator and after it, enables output 2. + * + * \note The function does not affect Buck output 1 that can supply + * a core. + * + * \warning The function does not select the Buck output 2 voltage and + * does not set/clear the HW-controlled bit for Buck output 2. Call + * Cy_SysPm_BuckSetVoltage2() or Cy_SysPm_BuckSetVoltage2HwControl() to + * configure the Buck output 2. + * + * The function is applicable for devices with the SIMO Buck regulator. + * Refer to device datasheet about information if device contains + * SIMO Buck. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckEnableVoltage2 + * + *******************************************************************************/ + void Cy_SysPm_BuckEnableVoltage2(void) + { + if(!Cy_SysPm_BuckIsEnabled()) + { + /* Enable the SIMO Buck regulator */ + SRSS->PWR_BUCK_CTL |= _VAL2FLD(SRSS_PWR_BUCK_CTL_BUCK_EN, 1U); + } + + /* Enable the SIMO Buck output 2 */ + SRSS->PWR_BUCK_CTL2 |= _VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_EN, 1U); + + /* Wait until the output is stable */ + Cy_SysLib_DelayUs(CY_SYSPM_BUCK_BLE_SUPPLY_STABLE_US); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckSetVoltage2 + ****************************************************************************//** + * + * This function sets output voltage 2 of the SIMO Buck regulator. + * + * \param voltage + * The voltage of the Buck regulator output 2. + * See \ref cy_en_syspm_buck_voltage2_t. + * + * \param waitToSettle + * True - Enable the 200 us delay after setting a higher voltage. + * False - Disable the 200 us delay after setting a higher voltage. + * + * \warning You must enable the delay (waitToSettle = true) + * while changing from a lower voltage to a higher voltage. + * + * \note The 200 us delay is required only when changing from a + * lower voltage to a higher voltage. Changing from a higher voltage to a lower one, + * the delay is not required. + * + * The function is applicable for devices with the SIMO Buck regulator. + * Refer to device datasheet about information if device contains + * SIMO Buck. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckSetVoltage2 + * + *******************************************************************************/ + void Cy_SysPm_BuckSetVoltage2(cy_en_syspm_buck_voltage2_t voltage, bool waitToSettle) + { + uint32_t curVoltage; + + CY_ASSERT_L3(CY_SYSPM_IS_BUCK_VOLTAGE2_VALID(voltage)); + + /* Get the current voltage */ + curVoltage = (uint32_t) Cy_SysPm_BuckGetVoltage2(); + + if((uint32_t) voltage != curVoltage) + { + SRSS->PWR_BUCK_CTL2 = + _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL2), SRSS_PWR_BUCK_CTL2_BUCK_OUT2_SEL, (uint32_t) voltage); + + /* Delay to stabilize at the new voltage is required only + * when changing from a lower voltage to a higher voltage. + */ + if(waitToSettle && ((uint32_t) voltage > curVoltage)) + { + Cy_SysLib_DelayUs(BUCK_STABILIZATION_DELAY_US); + } + } + } + #endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ + + +/******************************************************************************* +* Function Name: Cy_SysPm_LdoSetVoltage +****************************************************************************//** +* +* Set an output voltage on the LDO. +* +* When changing from a higher voltage to a lower voltage, ensure that: +* * The device maximum operating frequency for all the Clk_HF paths, peripheral, +* and slow clock are under the \ref group_syspm_ulp_limitations. +* * The total current consumption is under the \ref group_syspm_ulp_limitations. +* * The appropriate wait states values are set for the flash using +* the Cy_SysLib_SetWaitStates() function as explained below. +* +* Setting wait states values for Flash +* +* The flash access time when the core output voltage is 0.9 V (nominal) is +* longer than at 1.1 V (nominal). Therefore, the number of the wait states must +* be adjusted. Use the Cy_SysLib_SetWaitStates() function to set the appropriate +* wait state values for flash. +* +* To change from a higher voltage to a lower voltage 0.9 V (nominal), +* call the Cy_SysLib_SetWaitStates(true, hfClkFreqMz) function before changing +* the voltage, where hfClkFreqMz is the frequency of HfClk0 in MHz. +* +* To change from a lower voltage to a higher voltage 1.1 V (nominal), calling +* the Cy_SysLib_SetWaitStates(false, hfClkFreqMz) function is to set the +* wait states is optional, but can be done to improve the performance. +* The clock frequency may now be increased up to \ref group_syspm_lp_limitations +* for a new voltage. +* +* \note 1. The output is set to 0.9 V (nominal) - the flash works in the +* Read-only operation. +* \note 2. The output is set to 1.1 V (nominal) - the flash works in the Read +* and Write operations. +* \note 3. The actual device Vccd voltage can be different from the nominal +* voltage because the actual voltage value depends on the conditions +* including the load current. +* +* For more details refer to the \ref group_syspm_managing_core_regulators +* section. +* Refer to the \ref group_syslib driver for more details about setting the wait +* states. +* +* \param voltage +* The desired output regulator voltage. +* See \ref cy_en_syspm_ldo_voltage_t voltage +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_VoltageRegulator +* +*******************************************************************************/ +void Cy_SysPm_LdoSetVoltage(cy_en_syspm_ldo_voltage_t voltage) +{ + CY_ASSERT_L3(CY_SYSPM_IS_LDO_VOLTAGE_VALID(voltage)); + + uint32_t interruptState; + interruptState = Cy_SysLib_EnterCriticalSection(); + + if (Cy_SysPm_LdoGetVoltage() != voltage) + { + uint32_t trimVoltage; + + if (CY_SYSPM_LDO_VOLTAGE_0_9V == voltage) + { + /* Set the analog signal bit for the flash before the voltage is changed + * from 1.1 V to 0.9 V. Store trimmed voltage value into the local variable + */ + SetVoltageBitForFlash(); + + /* Update read-write margin value for the ULP mode */ + SetReadMarginTrimUlp(); + + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_0_95V); + + /* Update write assist value for the ULP mode */ + SetWriteAssistTrimUlp(); + + trimVoltage = SFLASH->LDO_0P9V_TRIM; + } + else + { + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, LDO_OUT_VOLTAGE_0_95V); + + /* A delay for the supply to stabilize at the new higher voltage */ + Cy_SysLib_DelayUs(LDO_STABILIZATION_DELAY_US); + + /* Update write assist value for the LP mode */ + SetWriteAssistTrimLp(); + + trimVoltage = SFLASH->LDO_1P1V_TRIM; + } + + /* The system may continue operating while the voltage on Vccd + * discharges to the new voltage. The time it takes to reach the + * new voltage depends on the conditions, including the load current on + * Vccd and the external capacitor size + */ + SRSS->PWR_TRIM_PWRSYS_CTL = + _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, trimVoltage); + + if (CY_SYSPM_LDO_VOLTAGE_1_1V == voltage) + { + /* A delay for the supply to stabilize at the new higher voltage */ + Cy_SysLib_DelayUs(LDO_STABILIZATION_DELAY_US); + + /* Update read-write margin value for the LP mode */ + SetReadMarginTrimLp(); + + /* Set the analog signal bit to the flash macro register after + * the output voltage is 1.1 V + */ + ClearVoltageBitForFlash(); + } + } + + Cy_SysLib_ExitCriticalSection(interruptState); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_RegisterCallback +****************************************************************************//** +* +* Registers a new syspm callback. +* +* A callback is a function called after an event in the driver or +* middleware module has occurred. The handler callback API will be executed if +* the specific event occurs. See \ref cy_stc_syspm_callback_t. +* +* \note The registered callbacks are executed in two orders, based on callback +* mode \ref cy_en_syspm_callback_mode_t. For modes CY_SYSPM_CHECK_READY and +* CY_SYSPM_BEFORE_TRANSITION, the order is this: the first registered callback +* will be always the first executed. And the last registered callback will be +* executed as the last callback. For modes CY_SYSPM_AFTER_TRANSITION and +* CY_SYSPM_CHECK_FAIL, the order is this: the first registered callback will be +* always the last executed. And the last registered callback will be executed +* as the first callback. +* +* \param handler +* The address of the syspm callback structure. +* See \ref cy_stc_syspm_callback_t. +* \note Do not modify the registered structure in run-time. +* +* \return +* True if a callback was registered;
+* False if a callback was not registered or maximum callbacks were registered. +* +* It is allowed to register up to 32 callbacks. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Func_Declaration +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Params_Declaration +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Structure_Declaration +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Func_Implementation +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_RegisterCallback +* +*******************************************************************************/ +bool Cy_SysPm_RegisterCallback(cy_stc_syspm_callback_t* handler) +{ + uint32_t interruptState; + bool retStatus = false; + + interruptState = Cy_SysLib_EnterCriticalSection(); + + /* Check if the maximum callbacks were registered and verify input */ + retStatus = ((handler != NULL) && (curRegisteredCallbacks < CY_SYSPM_CALLBACKS_NUMBER_MAX)); + + if (retStatus) + { + if ((handler->callbackParams != NULL) && (handler->callback != NULL)) + { + cy_stc_syspm_callback_t* curCallback = callbackRoot; + cy_stc_syspm_callback_t* lastRegCallback = NULL; + + /* Search last registered callback item */ + while (curCallback != NULL) + { + if (curCallback == handler) + { + /* Do not register already registered callback item */ + retStatus = false; + break; + } + + /* Safe callback before switching into the next item */ + lastRegCallback = curCallback; + + curCallback = curCallback->nextItm; + } + + /* Link requested callback item to the linked list */ + if (retStatus) + { + if (callbackRoot == NULL) + { + /* Link first callback item to the linked list */ + callbackRoot = handler; + } + else + { + /* Link requested item to previous item */ + lastRegCallback->nextItm = handler; + } + + /* Update links to next and previous callback items of requested + * callback item + */ + handler->prevItm = lastRegCallback; + handler->nextItm = NULL; + callbackListLast = handler; + + /* Increment the value with number of registered callbacks */ + ++curRegisteredCallbacks; + } + } + else + { + retStatus = false; + } + } + + Cy_SysLib_ExitCriticalSection(interruptState); + + return(retStatus); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_UnregisterCallback +****************************************************************************//** +* +* This function unregisters a callback. +* +* The registered callback can be unregistered. Otherwise, false will be +* returned. +* +* \param handler The item that should be unregistered. +* See \ref cy_stc_syspm_callback_t. +* +* \return +* True if on success
+* False if it was not unregistered or no callbacks were registered. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_UnregisterCallback +* +*******************************************************************************/ +bool Cy_SysPm_UnregisterCallback(cy_stc_syspm_callback_t const *handler) +{ + uint32_t interruptState; + bool retStatus = false; + + interruptState = Cy_SysLib_EnterCriticalSection(); + + /* Check if there was at least one callback registered */ + if (curRegisteredCallbacks > 0UL) + { + cy_stc_syspm_callback_t* curCallback = callbackRoot; + + /* Search requested callback item in the linked list */ + while (curCallback != NULL) + { + /* Requested callback is found */ + if (curCallback == handler) + { + retStatus = true; + break; + } + + /* Go to next callback item in the linked list */ + curCallback = curCallback->nextItm; + } + + if (retStatus) + { + /* Update links of related to unregistered callback items */ + if (handler->nextItm != NULL) + { + handler->nextItm->prevItm = handler->prevItm; + } + if (handler->prevItm != NULL) + { + handler->prevItm->nextItm = handler->nextItm; + } + + /* Requested callback was first in the list */ + if (callbackRoot == handler) + { + callbackRoot = callbackRoot->nextItm; + } + + /* Requested callback was last in the list */ + if (callbackListLast == handler) + { + callbackListLast = handler->prevItm; + } + + /* Decrement the value with number of registered callbacks */ + --curRegisteredCallbacks; + } + } + + Cy_SysLib_ExitCriticalSection(interruptState); + + return(retStatus); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_ExecuteCallback +****************************************************************************//** +* +* The function executes all registered callbacks with provided type and mode. +* \note This low-level function is being used by \ref Cy_SysPm_Sleep, +* \ref Cy_SysPm_DeepSleep, \ref Cy_SysPm_Hibernate, \ref Cy_SysPm_EnterLowPowerMode +* and \ref Cy_SysPm_ExitLowPowerMode API functions, however might be also useful as +* an independent API function in some custom applications. +* \note The registered callbacks will be executed in order based on +* \ref cy_en_syspm_callback_type_t value. +* The are possible two orders of callbacks execution:
+* * From first registered to last registered. Such order is relevant to +* callbacks with mode CY_SYSPM_CHECK_READY and CY_SYSPM_BEFORE_TRANSITION. +* * Backward flow execution: from last executed callback to the +* first registered. Such order is relevant to callbacks with mode +* CY_SYSPM_AFTER_TRANSITION and CY_SYSPM_CHECK_FAIL. Note that, the last +* registered callback function is skipped with mode CY_SYSPM_CHECK_FAIL. This +* is because the callback that returned CY_SYSPM_FAIL already knows that it failed. +* +* If no callbacks are registered, returns CY_SYSPM_SUCCESS. +* +* \param type +* The callback type. See \ref cy_en_syspm_callback_type_t. +* +* \param mode +* The callback mode. See \ref cy_en_syspm_callback_mode_t. +* +* \note +* If mode is CY_SYSPM_CHECK_READY or CY_SYSPM_BEFORE_TRANSITION the +* all required callbacks would be executed in order from first +* registered to last registered. +* If mode is CY_SYSPM_CHECK_FAIL or CY_SYSPM_AFTER_TRANSITION the +* all required callbacks would be executed in order from last executed callback +* to first registered. +* +* \return +* CY_SYSPM_SUCCESS Callback successfully completed or nor callbacks registered. +* CY_SYSPM_FAIL one of executed callback(s) returned fail. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_ExecuteCallback +* +*******************************************************************************/ +cy_en_syspm_status_t Cy_SysPm_ExecuteCallback(cy_en_syspm_callback_type_t type, cy_en_syspm_callback_mode_t mode) +{ + static cy_stc_syspm_callback_t* lastExecutedCallback = NULL; + cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; + cy_stc_syspm_callback_t* curCallback; + cy_stc_syspm_callback_params_t curParams; + + CY_ASSERT_L3(CY_SYSPM_IS_CALLBACK_TYPE_VALID(type)); + CY_ASSERT_L3(CY_SYSPM_IS_CALLBACK_MODE_VALID(mode)); + + if((mode == CY_SYSPM_BEFORE_TRANSITION) || (mode == CY_SYSPM_CHECK_READY)) + { + /* Execute registered callbacks with order from first registered to the + * last registered. The modes defined in the .skipMode element are not + * executed + */ + curCallback = callbackRoot; + while((curCallback != NULL) && (retVal != CY_SYSPM_FAIL)) + { + if((curCallback->type == type) && ((0U == curCallback->skipMode) || + (0U == ((uint32_t) mode & curCallback->skipMode)))) + { + /* Update elements for local callback parameter values */ + curParams.base = curCallback->callbackParams->base; + curParams.context = curCallback->callbackParams->context; + curParams.mode = mode; + + retVal = curCallback->callback(&curParams); + + /* Update callback pointer with value of executed callback. + * Such update is required to execute further callbacks in + * backward order after exit from low power mode or to undo + * configuration after callback returned fail: from last executed + * to first registered. + */ + lastExecutedCallback = curCallback; + } + curCallback = curCallback->nextItm; + } + } + else + { + /* Execute registered callbacks with order from lastCallback to + * the first registered callback. Such a flow is required if previous + * callback function returned CY_SYSPM_FAIL or previous callback mode was + * CY_SYSPM_BEFORE_TRANSITION. Such an order is required to undo configurations in + * correct backward order. + */ + curCallback = callbackListLast; + + /* Skip last executed callback that returned CY_SYSPM_FAIL, as this + * callback already knows that it failed + */ + if (mode == CY_SYSPM_CHECK_FAIL) + { + curCallback = lastExecutedCallback; + if (curCallback != NULL) + { + curCallback = curCallback->prevItm; + } + } + + /* Execute all registered callback functions with required type and mode */ + while ((curCallback != NULL) && (retVal != CY_SYSPM_FAIL)) + { + if ((curCallback->type == type) && ((curCallback->skipMode == 0UL) || + (((uint32_t) mode & curCallback->skipMode) == 0UL))) + { + /* Update elements for local callback parameter values */ + curParams.base = curCallback->callbackParams->base; + curParams.context = curCallback->callbackParams->context; + curParams.mode = mode; + + retVal = curCallback->callback(&curParams); + } + curCallback = curCallback->prevItm; + } + } + return (retVal); +} + +/** \cond INTERNAL */ +/******************************************************************************* +* Function Name: Cy_SysPm_IoFreeze +****************************************************************************//** +* +* This function saves the output states and configuration of I/O cells. +* +* I/O-cell configuration can be changed while I/O-cells are frozen. The new +* configuration becomes effective only after the pins are unfrozen. +* +* Cy_SysPm_Hibernate() calls this function to freeze the I/O cells while +* entering hibernate. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Freeze +* +*******************************************************************************/ +void Cy_SysPm_IoFreeze(void) +{ + uint32_t interruptState; + uint32_t regValue; + + interruptState = Cy_SysLib_EnterCriticalSection(); + + /* Check the FREEZE state to avoid a recurrent I/O-cells freeze attempt, + * because the second call to this function will cause an accidental switch + * to Hibernate mode (the system will enter Hibernate mode immediately + * after writing to the hibernate bit because both UNLOCK and FREEZE were set + * correctly in the previous call to this function). + */ + if(0U == _FLD2VAL(SRSS_PWR_HIBERNATE_FREEZE, SRSS->PWR_HIBERNATE)) + { + /* Clear the unlock field for correct freeze of the I/O cells */ + SRSS->PWR_HIBERNATE = _CLR_SET_FLD32U((SRSS->PWR_HIBERNATE), SRSS_PWR_HIBERNATE_UNLOCK, 0U); + + /* Disable overriding by the peripherals the next pin-freeze command */ + SRSS->PWR_HIBERNATE |= CY_SYSPM_PWR_SET_HIBERNATE; + + /* The second write causes freeze of I/O cells to save the I/O-cell state */ + regValue = SRSS->PWR_HIBERNATE; + SRSS->PWR_HIBERNATE = regValue; + } + Cy_SysLib_ExitCriticalSection(interruptState); +} +/** \endcond */ + + +/******************************************************************************* +* Function Name: Cy_SysPm_IoUnfreeze +****************************************************************************//** +* +* This function unfreezes the I/O cells which were automatically frozen when the +* Hibernate is entered with the call to \ref Cy_SysPm_Hibernate(). +* +* I/O-cells remain frozen after a wakeup from hibernate mode until the +* firmware unfreezes them, by calling this function. +* +* If the firmware must retain the data value on the port, then the +* value must be read and re-written to the data register before calling this +* function. Furthermore, the drive mode must be re-programmed before the pins are +* unfrozen. If this is not done, the pin will change to the default state +* the moment the freeze is removed. +* +* Note that I/O cell configuration can be changed while frozen. The new +* configuration becomes effective only after the pins are unfrozen. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_IoUnfreeze +* +*******************************************************************************/ +void Cy_SysPm_IoUnfreeze(void) +{ + uint32_t interruptState; + interruptState = Cy_SysLib_EnterCriticalSection(); + + /* Preserve the last reset reason and wakeup polarity. Then, unfreeze I/O: + * write PWR_HIBERNATE.FREEZE=0, .UNLOCK=0x3A, .HIBERANTE=0, + */ + SRSS->PWR_HIBERNATE = (SRSS->PWR_HIBERNATE & CY_SYSPM_PWR_RETAIN_HIBERNATE_STATUS) | CY_SYSPM_PWR_HIBERNATE_UNLOCK; + + /* Lock the hibernate mode: + * write PWR_HIBERNATE.HIBERNATE=0, UNLOCK=0x00, HIBERANTE=0 + */ + SRSS->PWR_HIBERNATE &= CY_SYSPM_PWR_RETAIN_HIBERNATE_STATUS; + + /* Read register to make sure it is settled */ + (void) SRSS->PWR_HIBERNATE; + + Cy_SysLib_ExitCriticalSection(interruptState); +} + + +/******************************************************************************* +* Function Name: SetVoltageBitForFlash +****************************************************************************//** +* +* The internal function that changes the Vcc setting for the flash. +* +* Sets the bit for the flash macro register. This bit should be set when the +* voltage for the core regulators is less than 0.99 V. +* +*******************************************************************************/ +static void SetVoltageBitForFlash(void) +{ + FLASHC_FM_CTL->ANA_CTL0 |= _VAL2FLD(FLASHC_FM_CTL_ANA_CTL0_VCC_SEL, 1U); +} + + +/******************************************************************************* +* Function Name: ClearVoltageBitForFlash +****************************************************************************//** +* +* This is the internal function that changes the Vcc setting for the flash. +* +* Clears the bit for the flash macro register. This bit should +* be cleared if the output voltage for the core regulators is higher than 0.99 V. +* +*******************************************************************************/ +static void ClearVoltageBitForFlash(void) +{ + FLASHC_FM_CTL->ANA_CTL0 &= ((uint32_t) (~_VAL2FLD(FLASHC_FM_CTL_ANA_CTL0_VCC_SEL, 1U))); +} + +#ifdef CY_IP_MXUDB + + /******************************************************************************* + * Function Name: SaveRegisters + ****************************************************************************//** + * + * The internal function saves non-retained registers before entering Deep Sleep. + * Cypress ID #280370. + * + * \param regs + * The structure where the registers are saved before Deep Sleep. + * + *******************************************************************************/ + static void SaveRegisters(cy_stc_syspm_backup_regs_t *regs) + { + /* Save the registers before deep sleep */ + regs->CY_UDB_UDBIF_BANK_CTL_REG = UDB->UDBIF.BANK_CTL; + + regs->CY_UDB_BCTL_MDCLK_EN_REG = UDB->BCTL.MDCLK_EN; + regs->CY_UDB_BCTL_MBCLK_EN_REG = UDB->BCTL.MBCLK_EN; + regs->CY_UDB_BCTL_BOTSEL_L_REG = UDB->BCTL.BOTSEL_L; + regs->CY_UDB_BCTL_BOTSEL_U_REG = UDB->BCTL.BOTSEL_U; + regs->CY_UDB_BCTL_QCLK_EN0_REG = UDB->BCTL.QCLK_EN[0U]; + regs->CY_UDB_BCTL_QCLK_EN1_REG = UDB->BCTL.QCLK_EN[1U]; + regs->CY_UDB_BCTL_QCLK_EN2_REG = UDB->BCTL.QCLK_EN[2U]; + } + + + /******************************************************************************* + * Function Name: RestoreRegisters + ****************************************************************************//** + * + * The internal function restores the non-retained registers after + * leaving the Deep Sleep power mode. Cypress ID #280370. + * + * \param regs + * The structure with data stored into the required non-retained registers + * after Deep Sleep. + * + *******************************************************************************/ + static void RestoreRegisters(cy_stc_syspm_backup_regs_t const *regs) + { + /* Restore the registers after deep sleep */ + UDB->BCTL.MDCLK_EN = regs->CY_UDB_BCTL_MDCLK_EN_REG; + UDB->BCTL.MBCLK_EN = regs->CY_UDB_BCTL_MBCLK_EN_REG; + UDB->BCTL.BOTSEL_L = regs->CY_UDB_BCTL_BOTSEL_L_REG; + UDB->BCTL.BOTSEL_U = regs->CY_UDB_BCTL_BOTSEL_U_REG; + UDB->BCTL.QCLK_EN[0U] = regs->CY_UDB_BCTL_QCLK_EN0_REG; + UDB->BCTL.QCLK_EN[1U] = regs->CY_UDB_BCTL_QCLK_EN1_REG; + UDB->BCTL.QCLK_EN[2U] = regs->CY_UDB_BCTL_QCLK_EN2_REG; + + UDB->UDBIF.BANK_CTL = regs->CY_UDB_UDBIF_BANK_CTL_REG; + } +#endif /* CY_IP_MXUDB */ + +#if defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) + + /******************************************************************************* + * Function Name: Cy_EnterDeepSleep + ****************************************************************************//** + * + * The internal function that prepares the system for Deep Sleep and + * restores the system after a wakeup from Deep Sleep. + * + * \param waitFor Selects wait for action. See \ref cy_en_syspm_waitfor_t. + * + *******************************************************************************/ + #if defined (__ICCARM__) + #pragma diag_suppress=Ta023 + __ramfunc + #else + CY_SECTION(".cy_ramfunc") CY_NOINLINE + #endif + static void Cy_EnterDeepSleep(cy_en_syspm_waitfor_t waitFor) + { + /* Acquire the IPC to prevent changing of the shared resources at the same time */ + while(0U == _FLD2VAL(IPC_STRUCT_ACQUIRE_SUCCESS, SYSPM_IPC_STC->ACQUIRE)) + { + /* Wait until the IPC structure is released by another core */ + } + + /* Set the flag that current core entered Deep Sleep */ + SYSPM_IPC_STC->DATA |= CUR_CORE_DP_MASK; + + /* Change the slow and fast clock dividers only under condition that + * the other core is already in Deep Sleep. Cypress ID #284516 + */ + if (0U != (SYSPM_IPC_STC->DATA & OTHER_CORE_DP_MASK)) + { + /* Get the divider values of the slow and high clocks and store them into + * the IPC data register + */ + SYSPM_IPC_STC->DATA = + (SYSPM_IPC_STC->DATA & ((uint32_t) ~(SYSPM_FAST_CLK_DIV_Msk | SYSPM_SLOW_CLK_DIV_Msk))) | + (((uint32_t)(_FLD2VAL(CPUSS_CM0_CLOCK_CTL_SLOW_INT_DIV, CPUSS->CM0_CLOCK_CTL) << SYSPM_SLOW_CLK_DIV_Pos)) | + ((uint32_t)(_FLD2VAL(CPUSS_CM4_CLOCK_CTL_FAST_INT_DIV, CPUSS->CM4_CLOCK_CTL) << SYSPM_FAST_CLK_DIV_Pos))); + + /* Increase the clock divider for the slow and fast clocks to SYSPM_CLK_DIVIDER */ + CPUSS->CM0_CLOCK_CTL = + _CLR_SET_FLD32U(CPUSS->CM0_CLOCK_CTL, CPUSS_CM0_CLOCK_CTL_SLOW_INT_DIV, SYSPM_CLK_DIVIDER); + + CPUSS->CM4_CLOCK_CTL = + _CLR_SET_FLD32U(CPUSS->CM4_CLOCK_CTL, CPUSS_CM4_CLOCK_CTL_FAST_INT_DIV, SYSPM_CLK_DIVIDER); + + /* Read the divider value to make sure it is set */ + (void) CPUSS->CM0_CLOCK_CTL; + (void) CPUSS->CM4_CLOCK_CTL; + } + + /* Release the IPC */ + SYSPM_IPC_STC->RELEASE = 0U; + + /* Read this register to make sure it is settled */ + (void) SYSPM_IPC_STC->RELEASE; + + #if(0u != CY_CPU_CORTEX_M0P) + + /* The CPU enters the Deep Sleep mode upon execution of WFI/WFE */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) + { + __WFI(); + } + else + { + __WFE(); + } + #else + + /* Repeat the WFI/WFE instructions if a wake up was not intended. + * Cypress ID #272909 + */ + do + { + /* The CPU enters Deep Sleep mode upon execution of WFI/WFE */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) + { + __WFI(); + } + else + { + __WFE(); + + /* Call the WFE instructions twice to clear the Event register + * of the CM4 core. Cypress ID #279077 + */ + if(wasEventSent) + { + __WFE(); + } + + wasEventSent = true; + } + } while (_FLD2VAL(CPUSS_CM4_PWR_CTL_PWR_MODE, CPUSS->CM4_PWR_CTL) == CY_SYSPM_CM4_PWR_RETAINED); + + #endif /* (0u != CY_CPU_CORTEX_M0P) */ + + /* Acquire the IPC to prevent changing of the shared resources at the same time */ + while(0U == _FLD2VAL(IPC_STRUCT_ACQUIRE_SUCCESS, SYSPM_IPC_STC->ACQUIRE)) + { + /* Wait until the IPC structure is released by another core */ + } + + /* Read and change the slow and fast clock dividers only under condition + * that the other core is already in Deep Sleep. Cypress ID #284516 + */ + if(0U != (SYSPM_IPC_STC->DATA & OTHER_CORE_DP_MASK)) + { + /* Restore the clock dividers for the slow and fast clocks */ + CPUSS->CM0_CLOCK_CTL = + (_CLR_SET_FLD32U(CPUSS->CM0_CLOCK_CTL, CPUSS_CM0_CLOCK_CTL_SLOW_INT_DIV, + (_FLD2VAL(SYSPM_SLOW_CLK_DIV, SYSPM_IPC_STC->DATA)))); + + CPUSS->CM4_CLOCK_CTL = + (_CLR_SET_FLD32U(CPUSS->CM4_CLOCK_CTL, CPUSS_CM4_CLOCK_CTL_FAST_INT_DIV, + (_FLD2VAL(SYSPM_FAST_CLK_DIV, SYSPM_IPC_STC->DATA)))); + } + + /* Indicate that the current core is out of Deep Sleep */ + SYSPM_IPC_STC->DATA &= ((uint32_t) ~CUR_CORE_DP_MASK); + + /* Release the IPC */ + SYSPM_IPC_STC->RELEASE = 0U; + } + #if defined (__ICCARM__) + #pragma diag_default=Ta023 + #endif +#endif /* defined(CY_DEVICE_PSOC6ABLE2) && !defined(CY_PSOC6ABLE2_REV_0A_SUPPORT_DISABLE) */ + + +/******************************************************************************* +* Function Name: EnterDeepSleep +****************************************************************************//** +* +* The internal function that prepares the system for Deep Sleep, +* sets the CPU core to the Deep Sleep, and restores the system after a +* wakeup from Deep Sleep. +* +* \param waitFor +* Selects wait for action. See \ref cy_en_syspm_waitfor_t. +* +*******************************************************************************/ +#if defined (__ICCARM__) + #pragma diag_suppress=Ta023 + __ramfunc +#else + CY_SECTION(".cy_ramfunc") CY_NOINLINE +#endif +static void EnterDeepSleep(cy_en_syspm_waitfor_t waitFor) +{ +#if(0u != CY_CPU_CORTEX_M0P) + + /* The CPU enters the Deep Sleep mode upon execution of WFI/WFE */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) + { + __WFI(); + } + else + { + __WFE(); + } +#else + + /* Repeat the WFI/WFE instructions if a wake up was not intended. + * Cypress ID #272909 + */ + do + { + /* The CPU enters Deep Sleep mode upon execution of WFI/WFE */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) + { + __WFI(); + } + else + { + __WFE(); + + /* Call the WFE instructions twice to clear the Event register + * of the CM4 core. Cypress ID #279077 + */ + if(wasEventSent) + { + __WFE(); + } + + wasEventSent = true; + } + } while (_FLD2VAL(CPUSS_CM4_PWR_CTL_PWR_MODE, CPUSS->CM4_PWR_CTL) == CY_SYSPM_CM4_PWR_RETAINED); + +#endif /* (0u != CY_CPU_CORTEX_M0P) */ + + /* Acquire the IPC to prevent changing of the shared resources at the same time. + * Shared resources is the BIST_DATA[0] register. + */ + while(0U == _FLD2VAL(IPC_STRUCT_ACQUIRE_SUCCESS, SYSPM_IPC_STC->ACQUIRE)) + { + /* Wait until the IPC structure is released by another core */ + } + + /* Set 10 uS delay only under condition that the DELAY_DONE_FLAG is + * cleared. Cypress ID #288510 + */ + if(DELAY_DONE_FLAG->BIST_DATA[0] == NEED_DELAY) + { + /* Configure the counter to be sourced by IMO */ + TST_DDFT_SLOW_CTL_REG = TST_DDFT_SLOW_CTL_MASK; + CLK_OUTPUT_SLOW_REG = CLK_OUTPUT_SLOW_MASK; + TST_DDFT_FAST_CTL_REG = TST_DDFT_FAST_CTL_MASK; + + /* Load the down-counter to count the 10 uS */ + CLK_CAL_CNT1_REG = IMO_10US_DELAY; + + while(0U == (CLK_CAL_CNT1_REG & CLK_CAL_CNT1_DONE)) + { + /* Wait until the counter stops counting */ + } + + /* Indicate that 10 uS delay was done */ + DELAY_DONE_FLAG->BIST_DATA[0] = DELAY_DONE; + } + + /* Release the IPC structure in do while loop just to sure that this code + * is not optimized + */ + do + { + SYSPM_IPC_STC->RELEASE = 0U; + } while (0U != 0U); +} +#if defined (__ICCARM__) + #pragma diag_default=Ta023 +#endif + + +/******************************************************************************* +* Function Name: SetReadMarginTrimUlp +****************************************************************************//** +* +* This is the internal function that updates the read-margin trim values for the +* RAM and ROM. The trim update is done during transition of regulator voltage +* from higher to a lower one. +* +*******************************************************************************/ +static void SetReadMarginTrimUlp(void) +{ + /* Update read-write margin value for the ULP mode. Cypress ID#297292 */ + CPUSS->TRIM_RAM_CTL = (CPUSS->TRIM_RAM_CTL & ((uint32_t) ~CPUSS_TRIM_RAM_CTL_RM_Msk)) | + (CPUSS_TRIM_RAM_ULP & CPUSS_TRIM_RAM_CTL_RM_Msk); + + CPUSS->TRIM_ROM_CTL = (CPUSS->TRIM_ROM_CTL & ((uint32_t) ~CPUSS_TRIM_ROM_CTL_RM_Msk)) | + (CPUSS_TRIM_ROM_ULP & CPUSS_TRIM_ROM_CTL_RM_Msk); +} + + +/******************************************************************************* +* Function Name: SetReadMarginTrimLp +****************************************************************************//** +* +* The internal function which updates the read-margin trim values for the +* RAM and ROM. The trim update is done during transition of regulator voltage +* from lower to a higher one. +* +*******************************************************************************/ +static void SetReadMarginTrimLp(void) +{ + /* Update read-write margin value for the LP mode. Cypress ID#297292 */ + CPUSS->TRIM_RAM_CTL = (CPUSS->TRIM_RAM_CTL & ((uint32_t) ~CPUSS_TRIM_RAM_CTL_RM_Msk)) | + (CPUSS_TRIM_RAM_LP & CPUSS_TRIM_RAM_CTL_RM_Msk); + + CPUSS->TRIM_ROM_CTL = (CPUSS->TRIM_ROM_CTL & ((uint32_t) ~CPUSS_TRIM_ROM_CTL_RM_Msk)) | + (CPUSS_TRIM_ROM_LP & CPUSS_TRIM_ROM_CTL_RM_Msk); +} + + +/******************************************************************************* +* Function Name: SetWriteAssistTrimUlp +****************************************************************************//** +* +* This is the internal function that updates the write assistant trim value for the +* RAM. The trim update is done during transition of regulator voltage +* from higher to a lower. +* +*******************************************************************************/ +static void SetWriteAssistTrimUlp(void) +{ + /* Update write assist value for the ULP mode. Cypress ID#297292 */ + CPUSS->TRIM_RAM_CTL = (CPUSS->TRIM_RAM_CTL & ((uint32_t) ~CPUSS_TRIM_RAM_CTL_WA_Msk)) | + (CPUSS_TRIM_RAM_ULP & CPUSS_TRIM_RAM_CTL_WA_Msk); +} + + +/******************************************************************************* +* Function Name: SetWriteAssistTrimLp +****************************************************************************//** +* +* This is the internal function that updates the write assistant trim value for the +* RAM. The trim update is done during transition of regulator voltage +* from lower to a higher one. +* +*******************************************************************************/ +static void SetWriteAssistTrimLp(void) +{ + /* Update write assist value for the LP mode. Cypress ID#297292 */ + CPUSS->TRIM_RAM_CTL = (CPUSS->TRIM_RAM_CTL & ((uint32_t) ~CPUSS_TRIM_RAM_CTL_WA_Msk)) | + (CPUSS_TRIM_RAM_LP & CPUSS_TRIM_RAM_CTL_WA_Msk); +} + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syspm/cy_syspm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syspm/cy_syspm.h new file mode 100644 index 0000000000..fc663f6a19 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/syspm/cy_syspm.h @@ -0,0 +1,2263 @@ +/***************************************************************************//** +* \file cy_syspm.h +* \version 2.10 +* +* Provides the function definitions for the power management API. +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +* +*******************************************************************************/ + +/** +* \defgroup group_syspm System Power Management (SysPm) +* \{ +* +* Use the System Power Management (SysPm) driver to enter low-power modes and +* reduce system power consumption in power sensitive designs. For multi-core +* devices, this library allows you to individually enter low-power modes for +* each core. +* +* This document contains the following topics: +* +* * \ref group_syspm_power_modes +* * \ref group_syspm_device_power_modes +* - \ref group_syspm_switching_into_lpactive +* - \ref group_syspm_switching_from_lpactive +* - \ref group_syspm_switching_into_sleep_deepsleep +* - \ref group_syspm_wakingup_from_sleep_deepsleep +* - \ref group_syspm_switching_into_hibernate +* - \ref group_syspm_wakingup_from_hibernate +* * \ref group_syspm_managing_core_regulators +* - \ref group_syspm_ulp_limitations +* - \ref group_syspm_lp_limitations +* * \ref group_syspm_managing_pmic +* * \ref group_syspm_managing_backup_domain +* * \ref group_syspm_cb +* - \ref group_syspm_cb_example +* - \ref group_syspm_cb_config_consideration +* - \ref group_syspm_cb_parameters +* - \ref group_syspm_cb_structures +* - \ref group_syspm_cb_function_implementation +* - \ref group_syspm_cb_flow +* - \ref group_syspm_cb_uregistering +* * \ref group_syspm_definitions +* +* \section group_syspm_section_configuration Configuration Considerations +* \subsection group_syspm_power_modes Power Modes +* PSoC 6 MCUs support the following power modes (in the order of high-to-low +* power consumption): Active, Low-Power (LPActive), Deep Sleep, and Hibernate. +* The core(s) can also be in Arm-defined power modes - Active, Sleep, +* and Deep Sleep. +* +* \subsection group_syspm_device_power_modes Device Power Modes +* * Active - In this mode the code is executed, and all logic and +* memories are powered. Firmware may disable clocks for specific peripherals +* and power down specific analog power domains. +* +* * LPActive - Low-Power mode is like Active mode, but with clock +* restrictions and limited/slower peripherals to achieve a lower system current. +* Refer to \ref group_syspm_switching_into_lpactive in Configuration +* considerations. +* +* * Deep Sleep - is a lower power mode where high-frequency clocks are +* disabled. Deep-Sleep-capable peripherals are available. A normal wakeup from +* Deep Sleep returns to either LPActive, Active, or Sleep, depending on the +* previous state and programmed behavior for the configured wakeup interrupt. +* Likewise, a debug wakeup from Deep Sleep returns to Sleep, depending on which +* mode was used to enter the Deep Sleep power mode. +* +* * Hibernate - is an even lower power mode that is entered from +* firmware, just like Deep Sleep. However, on a wakeup the core and all +* peripherals go through a full reset. The I/O's state is frozen so that the +* output driver state is held. Note that in this mode, the core(s) and all +* peripherals lose their states, so the system and firmware reboot on a wakeup +* event. Backup memory (if present) can be used to store system states for use +* on the next reboot. +* +* \subsubsection group_syspm_switching_into_lpactive Switching Device into LPActive +* Before switching into the LPActive power mode, ensure that the device meets +* the current load limitation. Decrease the clock frequencies, and slow or +* disable peripherals. Refer to the \ref group_syspm_managing_core_regulators +* Section.
+* * The IMO is set to the Clk_HF +* +* * Turn off unused peripherals, or decrease their operating frequencies to +* achieve total current consumption less than or equal to 20 mA. +* +* * Call the Cy_SysPm_EnterLowPowerMode() function that will put references +* such as POR and BOD into Low-Power mode. +* +* * If the core is sourced by the LDO Core Voltage Regulator, then the +* 0.9 V (nominal) mode must be set. Refer \ref group_syspm_functions_ldo API +* in \ref group_syspm_functions_core_regulators. +* +* * If the core is sourced by the Buck Core Voltage Regulator, then it is +* recommended, but not required, to set CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V. +* Decide whether your application can meet the requirements for the +* CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V. +* See \ref group_syspm_managing_core_regulators. +* +* \subsubsection group_syspm_switching_from_lpactive Switching Device from LPActive +* To switch a device from LPActive to Active mode, just +* call Cy_SysPm_ExitLowPowerMode(). +* +* \subsubsection group_syspm_switching_into_sleep_deepsleep Switching Device or Core to Sleep or Deep Sleep +* For multi-core devices, the Cy_SysPm_Sleep() and Cy_SysPm_DeepSleep() +* functions switch only the core that calls the function into the Sleep or +* the Deep Sleep power mode. To set the whole device in the Sleep or Deep Sleep +* power mode, ensure that each core calls the Cy_SysPm_Sleep() or +* Cy_SysPm_DeepSleep() function. +* +* There are situations when the device does not switch into the Deep Sleep +* power mode immediately after the second core calls Cy_SysPm_DeepSleep(). +* The device will switch into Deep Sleep mode automatically a little bit later, +* after the low-power circuits are ready to switch into Deep Sleep. Refer to +* the Cy_SysPm_DeepSleep() description for more details. +* +* All pending interrupts should be cleared before the device is put into a +* Sleep or Deep Sleep mode, even if they are masked. +* +* For single-core devices, SysPm functions that return the status of the +* unsupported core always return CY_SYSPM_STATUS__DEEPSLEEP. +* +* \subsubsection group_syspm_wakingup_from_sleep_deepsleep Waking Up from Sleep or Deep Sleep +* For Arm-based devices, an interrupt is required for the core to wake up. +* For multi-core devices, one core can wake up the other core by sending the +* event instruction. Use the CMSIS function __SEV() to sent event from one core +* to another. +* +* \subsubsection group_syspm_switching_into_hibernate Switching Device to Hibernate +* If you call Cy_SysPm_Hibernate() from either core, the device will be switched +* into the Hibernate power mode directly, as there is no +* handshake between cores. +* +* \subsubsection group_syspm_wakingup_from_hibernate Waking Up from Hibernate +* +* The system can wake up from Hibernate mode by configuring: +* +* * Wakeup pin +* +* * LP Comparator +* +* * RTC alarm +* +* * WDT interrupt +* +* Wakeup is supported from device specific pin(s) with programmable polarity. +* Additionally, unregulated peripherals can wake the device under some +* conditions. For example, a low-power comparator can wake the device by +* comparing two external voltages but may not support comparison to an +* internally-generated voltage. The Backup domain remains functional, and if +* present it can schedule an alarm to wake the device from Hibernate using RTC. +* Alternatively, the Watchdog Timer (WDT) can be configured to wake-up the +* device by WDT interrupt. +* Refer to \ref Cy_SysPm_SetHibernateWakeupSource() for more details. +* +* \subsection group_syspm_managing_core_regulators Managing Core Voltage Regulators +* The SysPm driver provides functionality to manage the power modes of the +* low-dropout (LDO) and Buck Core Voltage Regulators. +* For both core regulators, two voltages are possible: +* +* * 0.9 V (nominal) - core is sourced by 0.9 V (nominal). This core regulator +* power mode is called Ultra Low-Power (ULP). In this mode, the device +* functionality and performance is limited. You must decrease the operating +* frequency and current consumption to meet the +* \ref group_syspm_ulp_limitations, shown below. +* * 1.1 V (nominal) - core is sourced by 1.1 V (nominal). This core regulator +* power mode is called low-power mode (LP). In this mode, you must meet the +* \ref group_syspm_lp_limitations, shown below. +* +* \subsubsection group_syspm_ulp_limitations ULP Limitations +* When the core voltage is 0.9 V (nominal) the next limitations must be +* meet:
+* - the maximum operating frequency for all Clk_HF paths must not exceed +* 50 MHz, whereas the peripheral and slow clock must not exceed 25 MHz +* (refer to \ref group_sysclk driver documentation). +* - the total current consumption must be less than or equal to 20 mA
+* +* \subsubsection group_syspm_lp_limitations LP Limitations +* When the core voltage is 1.1V (nominal) the next limitations must be meet: +* - the maximum operating frequency for all Clk_HF paths must not exceed +* 150 MHz, whereas the peripheral and slow clock must not exceed 100 MHz +* (refer to \ref group_sysclk driver documentation).
+* - the total current consumption must be less than or equal to 250 mA +* +* \subsection group_syspm_managing_pmic Managing PMIC +* +* The SysPm driver also provides an API to configure the external power +* management integrated circuit (PMIC) that supplies Vddd. +* Use the API to enable the PMIC output that is routed to pmic_wakeup_out pin, +* and configure the polarity of the PMIC input (pmic_wakeup_in) that is used to +* wake up the PMIC. +* +* The PMIC is automatically enabled when: +* +* * the PMIC is locked by a call to Cy_SysPm_PmicLock() +* +* * the configured polarity of the PMIC input and the polarity driven to +* pmic_wakeup_in pin matches. +* +* Because a call to Cy_SysPm_PmicLock() automatically enables the PMIC, the PMIC +* can remain disabled only when it is unlocked. See Cy_SysPm_PmicUnlock() +* for more details. +* +* Use Cy_SysPm_PmicIsLocked() to read the current PMIC lock status. +* +* To enable the PMIC, use these functions in this order:
+* \code{.c} +* 1 Cy_SysPm_PmicUnlock(); +* 2 Cy_SysPm_PmicEnable(); +* 3 Cy_SysPm_PmicLock(); +* \endcode +* +* To disable the PMIC block, unlock the PMIC. Then call Cy_SysPm_PmicDisable() +* with the inverted value of the current active state of the pmic_wakeup_in pin. +* For example, assume the current state of the pmic_wakeup_in pin is active low. +* To disable the PMIC, call these functions in this order:
+* \code{.c} +* 1 Cy_SysPm_PmicUnlock(); +* 2 Cy_SysPm_PmicDisable(CY_SYSPM_PMIC_POLARITY_HIGH); +* \endcode +* Note that you do not call Cy_SysPm_PmicLock(), because that automatically +* enables the PMIC. +* +* While disabled, the PMIC block is automatically enabled when the +* pmic_wakeup_in pin state is changed into high state. +* +* To disable the PMIC output, call these functions in this order: +* Cy_SysPm_PmicUnlock(); +* Cy_SysPm_PmicDisableOutput(); +* +* Do not call Cy_SysPm_PmicLock() (which automatically enables the PMIC output). +* +* When disabled, the PMIC output is enabled when the PMIC is locked, or by +* calling Cy_SysPm_PmicEnableOutput(). +* +* \subsection group_syspm_managing_backup_domain Managing the Backup Domain +* The SysPm driver provide functions to: +* +* * Configure supercapacitor charge +* +* * Select power supply (Vbackup or Vddd) for the Vddbackup +* +* * Measure Vddbackup using the ADC +* +* Refer to the \ref group_syspm_functions_backup functions for more details. +* +* \subsection group_syspm_cb SysPm Callbacks +* The SysPm driver handles the low power callbacks declared in the application. +* +* If there are no callbacks registered, the device just executes the power mode +* transition. However, it is often the case that your firmware must prepare for +* low power mode. For example, you may need to disable a peripheral, or ensure +* that a message is not being transmitted or received. +* +* To enable this, the SysPm driver implements a callback mechanism. When a lower +* power mode transition is about to take place (either entering or exiting +* \ref group_syspm_device_power_modes), the registered callbacks are called. +* +* The SysPm driver organizes all the callbacks into a linked list. While +* entering a low-power mode, SysPm goes through that linked list from first to +* last, executing the callbacks one after another. While exiting low-power mode, +* SysPm goes through that linked list again, but in the opposite direction from +* last to first. +* +* For example, the picture below shows three callback structures organized into +* a linked list: myDeepSleep1, mySleep1, myDeepSleep2 (represented with the +* \ref cy_stc_syspm_callback_t configuration structure). Each structure +* contains, among other fields, the address of the callback function. The code +* snippets below set this up so that myDeepSleep1 is called first when entering +* the low-power mode. This also means that myDeepSleep1 will be the last one to +* execute when exiting the low-power mode. +* +* The callback structures after registration: +* \image html syspm_2_10_after_registration.png +* +* Your application must register each callback, so that SysPm can execute it. +* Upon registration, the linked list is built by the SysPm driver. Notice +* the &mySleep1 address in the myDeepSleep1 +* \ref cy_stc_syspm_callback_t structure. This is filled in by the SysPm driver +* when you register mySleep1. The order in which the callbacks are registered in +* the application defines the order of their execution by the SysPm driver. You +* may have up to 32 callback functions registered. +* Call \ref Cy_SysPm_RegisterCallback() to register each callback function. +* +* A callback function is typically associated with a particular driver that +* handles the peripheral. So the callback mechanism enables a peripheral to +* prepare for a low-power mode (for instance, shutting down the analog part); +* or to perform tasks while exiting a low-power mode (like enabling the analog +* part again). +* +* With the callback mechanism you can prevent switching into a low-power mode if +* a peripheral is not ready. For example, driver X is in the process of +* receiving a message. In the callback function implementation simply return +* CY_SYSPM_FAIL in a response to CY_SYSPM_CHECK_READY. +* +* If success is returned while executing a callback, the SysPm driver calls the +* next callback and so on to the end of the list. If at some point a callback +* returns CY_SYSPM_FAIL in response to the CY_SYSPM_CHECK_READY step, all the +* callbacks that have already executed are executed in reverse order, with the +* CY_SYSPM_CHECK_FAIL step. This allows each callback to know that entering the +* low-power mode has failed. The callback can then undo whatever it did to +* prepare for low power mode. For example, if the driver X callback shut down +* the analog part, it can re-enable the analog part. +* +* Let's switch to an example explaining the implementation, setup, and +* registration of three callbacks (myDeepSleep1, mySleep1, myDeepSleep2) in the +* application. The \ref group_syspm_cb_config_consideration are provided after +* the \ref group_syspm_cb_example. +* +* \subsection group_syspm_cb_example SysPm Callbacks Example +* +* The following code snippets demonstrate how use the SysPm callbacks mechanism. +* We will build the prototype for an application that registers +* three callback functions:
+* 1. mySleep1 - handles Sleep
+* 2. myDeepSleep1 - handles Deep Sleep and is associated with peripheral +* HW1_address (see PDL Design +* section to learn about the base hardware +* address)
+* 3. myDeepSleep2 - handles entering and exiting Deep Sleep and is +* associated with peripheral HW2_address
+* +* We set things up so that the mySleep1 and myDeepSleep1 callbacks do nothing +* while entering the low power mode (skip on CY_SYSPM_SKIP_BEFORE_TRANSITION - +* see \ref group_syspm_cb_function_implementation in +* \ref group_syspm_cb_config_consideration). +* Skipping the actions while entering low power might be useful if you need +* to save the time while switching low-power modes. This is because the callback +* function with skipped mode is not even called. +* +* Let's first declare the callback functions. Each gets the pointer to the +* \ref cy_stc_syspm_callback_params_t structure as the argument. +* +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Func_Declaration +* +* Now we setup the \ref cy_stc_syspm_callback_params_t structures that we will +* pass to callback functions. Note that for the myDeepSleep1 and myDeepSleep2 +* callbacks we also pass the pointers to the peripherals related to that +* callback (see PDL Design section to +* learn about the base hardware address). +* The configuration considerations related to this structure are described +* in \ref group_syspm_cb_parameters in \ref group_syspm_cb_config_consideration. +* +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Params_Declaration +* +* Now we setup the actual callback configuration structures. Each of these +* contains, among the other fields, the address of the +* \ref cy_stc_syspm_callback_params_t we just set up. We will use the callback +* configuration structures later in the code to register the callbacks in the +* SysPm driver. Again, we set things up so that the mySleep1 and myDeepSleep1 +* callbacks do nothing while entering the low power mode +* (skip on CY_SYSPM_SKIP_BEFORE_TRANSITION) - see +* \ref group_syspm_cb_function_implementation in +* \ref group_syspm_cb_config_consideration. +* +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Structure_Declaration +* +* Note that in each case the last two fields are NULL. These are fields used by +* the SysPm driver to set up the linked list of callback functions. +* +* The callback structures are now defined and allocated in the user's +* memory space: +* \image html syspm_2_10_before_registration.png +* +* Now we implement the callback functions. See +* \ref group_syspm_cb_function_implementation in +* \ref group_syspm_cb_config_consideration for the instructions on how the +* callback functions should be implemented. +* +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Callback_Func_Implementation +* +* Finally, we register the callbacks so that the SysPm driver knows about them. +* The order in which the callbacks will be called depends upon the order in +* which the callbacks are registered. If there are no callbacks registered, +* the device just executes the power mode transition. +* +* Callbacks that reconfigure global resources, such as clock frequencies, should +* be registered last. They then modify global resources as the final step before +* entering the low power mode, and restore those resources first, as the system +* returns from low-power mode. +* +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_RegisterCallback +* +* We are done configuring three callbacks. Now the SysPm driver will execute the +* callbacks appropriately whenever there is a call to a power mode transition +* function: \ref Cy_SysPm_Sleep(), \ref Cy_SysPm_DeepSleep(), +* \ref Cy_SysPm_EnterLowPowerMode(), \ref Cy_SysPm_ExitLowPowerMode(), and +* \ref Cy_SysPm_Hibernate(). +* \note On a wakeup from hibernate the device goes through a reset, so the +* callbacks with CY_SYSPM_AFTER_TRANSITION are not executed. Refer to +* \ref Cy_SysPm_Hibernate() for more details. +* +* Refer to \ref group_syspm_cb_uregistering in +* \ref group_syspm_cb_config_consideration to learn what to do if you need to +* remove the callback from the linked list. You might want to unregister the +* callback for debug purposes. +* +* Refer to \ref group_syspm_cb_flow in \ref group_syspm_cb_config_consideration +* to learn about how the SysPm is processing the callbacks. +* +* \subsection group_syspm_cb_config_consideration Callback Configuration Considerations +* +* \subsubsection group_syspm_cb_parameters Callback Function Parameters +* +* The callbackParams parameter of the callback function is a +* \ref cy_stc_syspm_callback_params_t structure. The first field in this +* structure (mode) is for internal use. In the example code we used a +* dummy value CY_SYSPM_CHECK_READY to eliminate compilation errors associated +* with the enumeration. The driver sets the mode field to the correct +* value when calling the callback functions (the mode is referred to as step in +* the \ref group_syspm_cb_function_implementation). The callback function reads +* the value and acts based on the mode set by the SysPm driver. The base +* and context fields are optional and can be NULL. Some drivers require a +* base hardware address and a context. If your callback routine needs access to +* the driver registers or context, provide those values (see +* PDL Design section +* to learn about Base Hardware Address). Be aware of MISRA warnings if these +* parameters are NULL. +* +* \subsubsection group_syspm_cb_structures Callback Function Structure +* For each callback, provide a \ref cy_stc_syspm_callback_t structure. Some +* fields in this structure are maintained by the driver. Use NULL for +* prevItm and nextItm. The driver uses these fields to build a +* linked list of callback functions. +* +* \warning The Cy_SysPm_RegisterCallback() function stores a pointer to the +* cy_stc_syspm_callback_t variable. Do not modify elements of the +* cy_stc_syspm_callback_t structure after the callback is registered. +* You are responsible for ensuring that the variable remains in scope. +* Typically the structure is declared as a global or static variable, or as a +* local variable in the main() function. +* +* \subsubsection group_syspm_cb_function_implementation Callback Function Implementation +* +* Every callback function should handle four possible steps (referred to as +* "mode") defined in \ref cy_en_syspm_callback_mode_t :
+* * CY_SYSPM_CHECK_READY - prepare for entering a low power mode
+* * CY_SYSPM_BEFORE_TRANSITION - The actions to be done before entering +* the low-power mode
+* * CY_SYSPM_AFTER_TRANSITION - The actions to be done after exiting the +* low-power mode
+* * CY_SYSPM_CHECK_FAIL - roll back the actions done in the callbacks +* executed previously with CY_SYSPM_CHECK_READY
+* +* A callback function can skip steps (see \ref group_syspm_skip_callback_modes). +* In our example mySleep1 and myDeepSleep1 callbacks do nothing while entering +* the low power mode (skip on CY_SYSPM_BEFORE_TRANSITION). If there is anything +* preventing low power mode entry - return CY_SYSPM_FAIL in response to +* CY_SYSPM_CHECK_READY in your callback implementation. Note that the callback +* should return CY_SYSPM_FAIL only in response to CY_SYSPM_CHECK_READY. The +* callback function should always return CY_SYSPM_PASS for other modes: +* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION +* (see \ref group_syspm_cb_flow). +* +* \subsubsection group_syspm_cb_flow Callbacks Execution Flow +* +* This section explains what happens during a power transition, when callbacks +* are implemented and set up correctly. The following discussion assumes:
+* * All required callback functions are defined and implemented
+* * All cy_stc_syspm_callback_t structures are filled with required values
+* * All callbacks are successfully registered +* +* User calls one of the power mode transition functions: \ref Cy_SysPm_Sleep(), +* \ref Cy_SysPm_DeepSleep(), \ref Cy_SysPm_EnterLowPowerMode(), +* \ref Cy_SysPm_ExitLowPowerMode(), and \ref Cy_SysPm_Hibernate(). +* It calls each callback with the mode set to CY_SYSPM_CHECK_READY. This +* triggers execution of the code for that step inside of each user callback. +* +* If that process is successful for all callbacks, then +* \ref Cy_SysPm_ExecuteCallback() calls each callback with the mode set to +* CY_SYSPM_BEFORE_TRANSITION. This triggers execution of the code for that step +* inside each user callback. We then enter the low power mode. +* +* When exiting the low power mode, the SysPm driver executes +* \ref Cy_SysPm_ExecuteCallback() again. This time it calls each callback in +* reverse order, with the mode set to CY_SYSPM_AFTER_TRANSITION. This triggers +* execution of the code for that step inside each user callback. When complete, +* we are back to Active state. +* +* A callback can return CY_SYSPM_FAIL only while executing the +* CY_SYSPM_CHECK_READY step. If that happens, then the remaining callbacks are +* not executed. Any callbacks that have already executed are called again, in +* reverse order, with CY_SYSPM_CHECK_FAIL. This allows the system to return to +* the previous state. Then any of the functions (\ref Cy_SysPm_Sleep(), +* \ref Cy_SysPm_DeepSleep(), \ref Cy_SysPm_EnterLowPowerMode(), +* \ref Cy_SysPm_ExitLowPowerMode(), and \ref Cy_SysPm_Hibernate()) that +* attempted to switch the device into a low power mode will +* return CY_SYSPM_FAIL. +* +* Callbacks that reconfigure global resources, such as clock frequencies, +* should be registered last. They then modify global resources as the final +* step before entering the low power mode, and restore those resources first, +* as the system returns from Low-power mode. +* +* \subsubsection group_syspm_cb_uregistering Callback Unregistering +* +* Unregistering the callback might be useful when you need dynamically manage +* the callbacks. +* +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_UnregisterCallback +* The callback structures after mySleep1 callback is unregistered: +* \image html syspm_2_10_unregistration.png +* +* \section group_syspm_definitions Definitions +* +*
VersionChangesReason for Change
2.0.1Minor documentation editsDocumentation update and clarification
2.0 +* Added Cy_SysLib_ResetBackupDomain() API implementation. \n +* Added CY_NOINLINE attribute implementation. \n +* Added DIE_YEAR field to 64-bit unique ID return value of Cy_SysLib_GetUniqueId() API. \n +* Added storing of SCB->HFSR, SCB->SHCSR registers and SCB->MMFAR, SCB->BFAR addresses to Fault Handler debug structure. \n +* Optimized Cy_SysLib_SetWaitStates() API implementation. +* Improvements made based on usability feedback.
Added Assertion Classes and Levels.For error checking, parameter validation and status returns in the PDL API.
Applied CY_NOINIT attribute to cy_assertFileName, cy_assertLine, and cy_faultFrame global variables.To store debug information into a non-zero init area for future analysis.
Removed CY_WEAK attribute implementation.CMSIS __WEAK attribute should be used instead.
1.0Initial version
+* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
TermDefinition
LDOLow Dropout Linear Regulator (LDO). The functions that manage this +* block are grouped as \ref group_syspm_functions_ldo under +* \ref group_syspm_functions_core_regulators
SIMO BuckSingle Inductor Multiple Output Buck Regulator, referred as +* "Buck regulator" throughout the documentation. The functions that +* manage this block are grouped as \ref group_syspm_functions_buck under +* \ref group_syspm_functions_core_regulators
PMICPower Management Integrated Circuit. The functions that manage this +* block are grouped as \ref group_syspm_functions_pmic
LPActiveLow-Power Active mode. The MCU power mode. +* See the \ref group_syspm_switching_into_lpactive +* section for details
+* +* \section group_syspm_section_more_information More Information +* For more information on the Power Management (SysPm) driver, +* refer to the technical reference manual (TRM). +* +* \section group_syspm_MISRA MISRA-C Compliance +* The SysPm driver does not have any specific deviations. +* +* \section group_syspm_changelog Changelog +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*
VersionChangesReason for Change
2.10
+* * Changed names for all Backup, Buck-related functions, defines, +* and enums
+* * Changed next power mode function names:
+* Cy_SysPm_EnterLpMode
+* Cy_SysPm_ExitLpMode
+* Cy_SysPm_SetHibWakeupSource
+* Cy_SysPm_ClearHibWakeupSource
+* Cy_SysPm_GetIoFreezeStatus
+* * Changed following enumeration names:
+* cy_en_syspm_hib_wakeup_source_t
+* cy_en_syspm_simo_buck_voltage1_t
+* cy_en_syspm_simo_buck_voltage2_t
+* * Updated Power Modes documentation section
+* * Added Low Power Callback Managements section
+* * Documentation edits +*
Improvements made based on usability feedback
+* Documentation update and clarification +*
2.0Enhancement and defect fixes:
+* * Added input parameter(s) validation to all public functions
+* * Removed "_SysPm_" prefixes from the internal functions names
+* * Changed the type of elements with limited set of values, from +* uint32_t to enumeration +* * Enhanced syspm callback mechanism +* * Added functions to control:
+* * Power supply for the Vddbackup
+* * Supercapacitor charge
+* * Vddbackup measurement by ADC
+*
1.0Initial version
+* +* \defgroup group_syspm_macros Macros +* \defgroup group_syspm_functions Functions +* \{ +* \defgroup group_syspm_functions_power Power Modes +* \defgroup group_syspm_functions_power_status Power Status +* \defgroup group_syspm_functions_iofreeze I/Os Freeze +* \defgroup group_syspm_functions_core_regulators Core Voltage Regulation +* \{ +* \defgroup group_syspm_functions_ldo LDO +* \defgroup group_syspm_functions_buck Buck +* \} +* \defgroup group_syspm_functions_pmic PMIC +* \defgroup group_syspm_functions_backup Backup Domain +* \defgroup group_syspm_functions_callback Low Power Callbacks +* \} +* \defgroup group_syspm_data_structures Data Structures +* \defgroup group_syspm_data_enumerates Enumerated Types +*/ + +#if !defined (CY_SYSPM_H) +#define CY_SYSPM_H + +#include +#include +#include "cy_device_headers.h" +#include "syslib/cy_syslib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************* +* Register Constants +*******************************************************************************/ + +/** +* \addtogroup group_syspm_macros +* \{ +*/ + +/** Driver major version */ +#define CY_SYSPM_DRV_VERSION_MAJOR 2 + +/** Driver minor version */ +#define CY_SYSPM_DRV_VERSION_MINOR 10 + +/** syspm driver identifier */ +#define CY_SYSPM_ID (CY_PDL_DRV_ID(0x10U)) + + +/******************************************************************************* +* Internal Defines +*******************************************************************************/ + +/** \cond INTERNAL */ + +/* Internal redefine for sflash */ +#define CY_SYSPM_SFLASH SFLASH + +/** The internal define of the unlock value for the PMIC functions */ +#define CY_SYSPM_PMIC_UNLOCK_KEY (0x3AU) + +/** The internal define of the tries number in the Cy_SysPm_ExitLowPowerMode() +* function +*/ +#define CY_SYSPM_WAIT_DELAY_TRYES (100U) + +/* Macro to validate parameters in Cy_SysPm_SetHibernateWakeupSource() and for Cy_SysPm_ClearHibernateWakeupSource() function */ +#define CY_SYSPM_IS_WAKE_UP_SOURCE_VALID(wakeupSource) (0UL == ((wakeupSource) & \ + ((uint32_t) ~(CY_SYSPM_HIB_WAKEUP_SOURSE_MASK)))) + +/* Macro to validate parameters in Cy_SysPm_PmicDisable() function */ +#define CY_SYSPM_IS_POLARITY_VALID(polarity) (((polarity) == CY_SYSPM_PMIC_POLARITY_LOW) || \ + ((polarity) == CY_SYSPM_PMIC_POLARITY_HIGH)) + +/* Macro to validate parameters in Cy_SysPm_BuckSetVoltage1() function */ +#define CY_SYSPM_IS_BUCK_VOLTAGE1_VALID(voltage) (((voltage) == CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT1_VOLTAGE_1_1V)) + +/* Macro to validate parameters in Cy_SysPm_BuckSetVoltage2() function */ +#define CY_SYSPM_IS_BUCK_VOLTAGE2_VALID(voltage) (((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_15V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_2V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_25V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_3V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_35V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_4V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_45V) || \ + ((voltage) == CY_SYSPM_BUCK_OUT2_VOLTAGE_1_5V)) + +/* Macro to validate parameters in Cy_SysPm_BuckIsOutputEnabled() function */ +#define CY_SYSPM_IS_BUCK_OUTPUT_VALID(output) (((output) == CY_SYSPM_BUCK_VBUCK_1) || \ + ((output) == CY_SYSPM_BUCK_VRF)) + +/* Macro to validate parameters in Cy_SysPm_LdoSetVoltage() function */ +#define CY_SYSPM_IS_LDO_VOLTAGE_VALID(voltage) (((voltage) == CY_SYSPM_LDO_VOLTAGE_0_9V) || \ + ((voltage) == CY_SYSPM_LDO_VOLTAGE_1_1V)) + +/* Macro to validate parameters in Cy_SysPm_ExecuteCallback() function */ +#define CY_SYSPM_IS_CALLBACK_TYPE_VALID(type) (((type) == CY_SYSPM_SLEEP) || \ + ((type) == CY_SYSPM_DEEPSLEEP) || \ + ((type) == CY_SYSPM_HIBERNATE) || \ + ((type) == CY_SYSPM_ENTER_LOWPOWER_MODE) || \ + ((type) == CY_SYSPM_EXIT_LOWPOWER_MODE)) + +/* Macro to validate parameters in Cy_SysPm_ExecuteCallback() function */ +#define CY_SYSPM_IS_CALLBACK_MODE_VALID(mode) (((mode) == CY_SYSPM_CHECK_READY) || \ + ((mode) == CY_SYSPM_CHECK_FAIL) || \ + ((mode) == CY_SYSPM_BEFORE_TRANSITION) || \ + ((mode) == CY_SYSPM_AFTER_TRANSITION)) + +/* Macro to validate parameters in Cy_SysPm_Sleep() and for Cy_SysPm_DeepSleep() function */ +#define CY_SYSPM_IS_WAIT_FOR_VALID(waitFor) (((waitFor) == CY_SYSPM_WAIT_FOR_INTERRUPT) || \ + ((waitFor) == CY_SYSPM_WAIT_FOR_EVENT)) + +/* Macro to validate parameters in Cy_SysPm_BackupSetSupply() function */ +#define CY_SYSPM_IS_VDDBACKUP_VALID(vddBackControl) (((vddBackControl) == CY_SYSPM_VDDBACKUP_DEFAULT) || \ + ((vddBackControl) == CY_SYSPM_VDDBACKUP_VBACKUP)) + +/* Macro to validate parameters in Cy_SysPm_BackupSuperCapCharge() function */ +#define CY_SYSPM_IS_SC_CHARGE_KEY_VALID(key) (((key) == CY_SYSPM_SC_CHARGE_ENABLE) || \ + ((key) == CY_SYSPM_SC_CHARGE_DISABLE)) + +#if(0u != SRSS_BUCKCTL_PRESENT) + + /** The definition for the delay of the Buck supply regulator + * stabilization after it was configured with enabled Buck output 1 */ + #define CY_SYSPM_BUCK_CORE_SUPPLY_STABLE_US (900U) + + /** The definition for the delay of the Buck supply regulator + * stabilization after it was configured with enabled Buck + * output 2 only + */ + #define CY_SYSPM_BUCK_BLE_SUPPLY_STABLE_US (600U) + + /** The definition for the delay of the Buck regulator after its output + * voltage is changed + */ + #define BUCK_STABILIZATION_DELAY_US (200U) + +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ + +/** The wait time for transition of the device from the Active into +* the LPActive +*/ +#define CY_SYSPM_ACTIVE_TO_LP_WAIT_US (1U) + +/** The wait delay time which occurs before the Active reference is settled. +* This delay is used in transition of the device from Active into the LPActive +* low-power mode +*/ +#define CY_SYSPM_LP_TO_ACTIVE_WAIT_BEFORE_US (8U) + +/** The wait delay time which occurs after the Active reference is settled. +* This delay is used in transition the device from Active into the LPActive +* mode +*/ +#define CY_SYSPM_LP_TO_ACTIVE_WAIT_AFTER_US (1U) + +/** The maximum callbacks number */ +#define CY_SYSPM_CALLBACKS_NUMBER_MAX (32U) + +/** The mask to unlock the Hibernate power mode */ +#define CY_SYSPM_PWR_HIBERNATE_UNLOCK ((uint32_t) 0x3Au << SRSS_PWR_HIBERNATE_UNLOCK_Pos) + +/** The mask to set the Hibernate power mode */ +#define CY_SYSPM_PWR_SET_HIBERNATE ((uint32_t) CY_SYSPM_PWR_HIBERNATE_UNLOCK |\ + SRSS_PWR_HIBERNATE_FREEZE_Msk |\ + SRSS_PWR_HIBERNATE_HIBERNATE_Msk) + +/** The mask to retain the Hibernate power mode status */ +#define CY_SYSPM_PWR_RETAIN_HIBERNATE_STATUS ((uint32_t) SRSS_PWR_HIBERNATE_TOKEN_Msk |\ + SRSS_PWR_HIBERNATE_MASK_HIBALARM_Msk |\ + SRSS_PWR_HIBERNATE_MASK_HIBWDT_Msk |\ + SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Msk |\ + SRSS_PWR_HIBERNATE_MASK_HIBPIN_Msk) + +/** The mask for the wakeup sources */ +#define CY_SYSPM_PWR_WAKEUP_HIB_MASK ((uint32_t) SRSS_PWR_HIBERNATE_MASK_HIBALARM_Msk |\ + SRSS_PWR_HIBERNATE_MASK_HIBWDT_Msk |\ + SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Msk |\ + SRSS_PWR_HIBERNATE_MASK_HIBPIN_Msk) + +/** The define to update the token to indicate the transition into Hibernate */ +#define CY_SYSPM_PWR_TOKEN_HIBERNATE ((uint32_t) 0x1BU << SRSS_PWR_HIBERNATE_TOKEN_Pos) + +/** The internal define of the first wakeup pin bit used in the +* Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_PIN0_BIT (1UL) + +/** The internal define of the second wakeup pin bit +* used in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_PIN1_BIT (2UL) + +/** +* The internal define of the first LPComparator bit +* used in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_LPCOMP0_BIT (4UL) + +/** +* The internal define for the second LPComparator bit +* used in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_LPCOMP1_BIT (8UL) + +/** +* The internal define of the first LPComparator value +* used in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_LPCOMP0 ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << \ + SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) + +/** +* The internal define of the second LPComparator value +* used in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_LPCOMP1 ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << \ + SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) + +/** +* The internal define of the first wake-up pin value +* used in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_PIN0 ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << \ + SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) + +/** +* The internal define of the second wake-up pin value used +* in the Cy_SysPm_SetHibernateWakeupSource() function +*/ +#define CY_SYSPM_WAKEUP_PIN1 ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << \ + SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) + +/** The internal define for the first LPComparator polarity configuration */ +#define CY_SYSPM_WAKEUP_LPCOMP0_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << \ + SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) + +/** The internal define for the second LPComparator polarity configuration */ +#define CY_SYSPM_WAKEUP_LPCOMP1_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << \ + SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) + +/** The internal define for the first wake-up pin polarity configuration */ +#define CY_SYSPM_WAKEUP_PIN0_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << \ + SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) + +/** The internal define for the second wake-up pin polarity configuration */ +#define CY_SYSPM_WAKEUP_PIN1_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << \ + SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) + +/* Internal macro of all possible wakeup sources from hibernate power mode */ +#define CY_SYSPM_HIB_WAKEUP_SOURSE_MASK (CY_SYSPM_HIBERNATE_LPCOMP0_HIGH | CY_SYSPM_HIBERNATE_LPCOMP1_HIGH | \ + CY_SYSPM_HIBERNATE_RTC_ALARM | CY_SYSPM_HIBERNATE_WDT | \ + CY_SYSPM_HIBERNATE_PIN0_HIGH | CY_SYSPM_HIBERNATE_PIN1_HIGH) +/** \endcond */ + +/** +* \defgroup group_syspm_return_status The Power Mode Status Defines +* \{ +* The defines of the core(s) and device power mode status. +*/ +#if(0u != CY_IP_M4CPUSS) + + /** The CM4 is Active */ + #define CY_SYSPM_STATUS_CM4_ACTIVE (0x01U) + + /** The CM4 is in Sleep */ + #define CY_SYSPM_STATUS_CM4_SLEEP (0x02U) + + /** The CM4 is in Deep Sleep */ + #define CY_SYSPM_STATUS_CM4_DEEPSLEEP (0x04U) + + /** The CM4 is Low-Power mode */ + #define CY_SYSPM_STATUS_CM4_LOWPOWER (0x80U) + + /** The define of retained power mode of the CM4 */ + #define CY_SYSPM_CM4_PWR_RETAINED (2UL) + +#endif /* (0u != CY_IP_M4CPUSS) */ + +/** The CM0 is Active */ +#define CY_SYSPM_STATUS_CM0_ACTIVE ((uint32_t) ((uint32_t)0x01U << 8U)) + +/** The CM0 is in Sleep */ +#define CY_SYSPM_STATUS_CM0_SLEEP ((uint32_t) ((uint32_t)0x02U << 8U)) + +/** The CM0 is in Deep Sleep */ +#define CY_SYSPM_STATUS_CM0_DEEPSLEEP ((uint32_t) ((uint32_t)0x04U << 8U)) + +/** The CM0 is in Low-Power mode */ +#define CY_SYSPM_STATUS_CM0_LOWPOWER ((uint32_t) ((uint32_t)0x80U << 8U)) + +#if(0u != CY_IP_M4CPUSS) + + /** The device is in the Low-Power mode define */ + #define CY_SYSPM_STATUS_SYSTEM_LOWPOWER ((uint32_t) (CY_SYSPM_STATUS_CM0_LOWPOWER | \ + (CY_SYSPM_STATUS_CM4_LOWPOWER))) +#else + /** The device is in the Low-Power mode define */ + #define CY_SYSPM_STATUS_SYSTEM_LOWPOWER CY_SYSPM_STATUS_CM0_LOWPOWER + +#endif /* (0u != CY_IP_M4CPUSS) */ +/** \} group_syspm_return_status */ + +/** \} group_syspm_macros */ + +/******************************************************************************* +* Configuration Structures +*******************************************************************************/ + +/** +* \addtogroup group_syspm_data_enumerates +* \{ +*/ + +/** The SysPm status definitions */ +typedef enum +{ + CY_SYSPM_SUCCESS = 0x00U, /**< Successful */ + CY_SYSPM_BAD_PARAM = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0x01U, /**< One or more invalid parameters */ + CY_SYSPM_TIMEOUT = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0x02U, /**< A time-out occurs */ + CY_SYSPM_INVALID_STATE = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0x03U, /**< The operation is not setup or is in an + improper state */ + CY_SYSPM_FAIL = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0xFFU /**< An unknown failure */ +} cy_en_syspm_status_t; + +/** +* This enumeration is used to initialize a wait action - an interrupt or +* an event. Refer to the CMSIS for the WFE and WFI instruction explanations. +*/ +typedef enum +{ + CY_SYSPM_WAIT_FOR_INTERRUPT, /**< Wait for an interrupt */ + CY_SYSPM_WAIT_FOR_EVENT /**< Wait for an event */ +} cy_en_syspm_waitfor_t; + +/** This enumeration is used to configure sources for wakeup from the Hibernate +* power mode +*/ +typedef enum +{ + /** Configure a low level for the first LPComp */ + CY_SYSPM_HIBERNATE_LPCOMP0_LOW = + ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), + + /** Configure a high level for the first LPComp */ + CY_SYSPM_HIBERNATE_LPCOMP0_HIGH = + ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | + ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), + + /** Configure a low level for the second LPComp */ + CY_SYSPM_HIBERNATE_LPCOMP1_LOW = ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), + + /** Configure a high level for the second LPComp */ + CY_SYSPM_HIBERNATE_LPCOMP1_HIGH = + ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | + ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), + + /** Configure the RTC alarm */ + CY_SYSPM_HIBERNATE_RTC_ALARM = SRSS_PWR_HIBERNATE_MASK_HIBALARM_Msk, + + /** Configure the WDT interrupt */ + CY_SYSPM_HIBERNATE_WDT = SRSS_PWR_HIBERNATE_MASK_HIBWDT_Msk, + + /** Configure a low level for the first wakeup-pin */ + CY_SYSPM_HIBERNATE_PIN0_LOW = ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), + + /** Configure a high level for the first wakeup-pin */ + CY_SYSPM_HIBERNATE_PIN0_HIGH = + ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | + ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), + + /** Configure a low level for the second wakeup-pin */ + CY_SYSPM_HIBERNATE_PIN1_LOW = ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), + + /** Configure a high level for the second wakeup-pin */ + CY_SYSPM_HIBERNATE_PIN1_HIGH = + ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | + ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), +} cy_en_syspm_hibernate_wakeup_source_t; + +/** The enumeration is used to select output voltage for the LDO */ +typedef enum +{ + CY_SYSPM_LDO_VOLTAGE_0_9V, /**< 0.9 V nominal LDO voltage */ + CY_SYSPM_LDO_VOLTAGE_1_1V /**< 1.1 V nominal LDO voltage */ +} cy_en_syspm_ldo_voltage_t; + +#if(0u != SRSS_BUCKCTL_PRESENT) + + /** + * The enumeration is used to select the output voltage for the Buck + * output 1, which can supply a core(s). + */ + typedef enum + { + CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V = 0x02U, /**< 0.9 V nominal Buck voltage */ + CY_SYSPM_BUCK_OUT1_VOLTAGE_1_1V = 0x05U /**< 1.1 V nominal Buck voltage */ + } cy_en_syspm_buck_voltage1_t; + + /** + * The enumerations are used to select the Buck regulator outputs + */ + typedef enum + { + CY_SYSPM_BUCK_VBUCK_1, /**< Buck output 1 Voltage (Vbuck1) */ + CY_SYSPM_BUCK_VRF /**< Buck out 2 Voltage (Vbuckrf) */ + } cy_en_syspm_buck_out_t; + + #if(0u != SRSS_SIMOBUCK_PRESENT) + + /** + * The enumeration is used to select the output voltage for the Buck + * output 2, which can source the BLE HW block. + */ + typedef enum + { + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_15V = 0U, /**< 1.15 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_2V = 1U, /**< 1.20 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_25V = 2U, /**< 1.25 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_3V = 3U, /**< 1.3 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_35V = 4U, /**< 1.35 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_4V = 5U, /**< 1.4 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_45V = 6U, /**< 1.45 V nominal voltage */ + CY_SYSPM_BUCK_OUT2_VOLTAGE_1_5V = 7U /**< 1.5 V nominal voltage */ + } cy_en_syspm_buck_voltage2_t; + + #endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ + +/** +* This enumeration is used to set a polarity for the PMIC input. The PMIC is +* automatically enabled when configured polarity of PMIC input and the polarity +* driven to pmic_wakeup_in pin matches. +*/ +typedef enum +{ + CY_SYSPM_PMIC_POLARITY_LOW = 0U, /**< Set active low state for the PMIC input */ + CY_SYSPM_PMIC_POLARITY_HIGH = 1U /**< Set active high state for the PMIC input */ +} cy_en_syspm_pmic_wakeup_polarity_t; + +/** +* This enumeration sets a switch to select Vbackup or Vddd to supply Vddbackup +*/ +typedef enum +{ + CY_SYSPM_VDDBACKUP_DEFAULT = 0U, /**< Automatically selects Vddd or Vbackup to supply + Vddbackup */ + CY_SYSPM_VDDBACKUP_VBACKUP = 2U /**< Set Vbackup to supply Vddbackup */ +} cy_en_syspm_vddbackup_control_t; + +/** +* This enumeration configures supercapacitor charging. +*/ +typedef enum +{ + CY_SYSPM_SC_CHARGE_ENABLE = 0x3CU, /**< Enables supercapacitor charging */ + CY_SYSPM_SC_CHARGE_DISABLE = 0x00U /**< Disables supercapacitor charging */ +} cy_en_syspm_sc_charge_key_t; + +/** +* This enumeration is used for selecting the low power mode on which the +* appropriate registered callback handler will be executed. For example, +* the registered callback of the type CY_SYSPM_SLEEP will be executed while +* switching into the Sleep power mode. +*/ +typedef enum +{ + CY_SYSPM_SLEEP, /**< The Sleep enum callback type */ + CY_SYSPM_DEEPSLEEP, /**< The Deep Sleep enum callback type */ + CY_SYSPM_HIBERNATE, /**< The Hibernate enum callback type */ + CY_SYSPM_ENTER_LOWPOWER_MODE, /**< The enter into the LPActive mode enum callback type */ + CY_SYSPM_EXIT_LOWPOWER_MODE, /**< The exit out of the LPActive mode enum callback type */ +} cy_en_syspm_callback_type_t; + +/** The callback mode enumeration. This enum defines the callback mode */ +typedef enum +{ + CY_SYSPM_CHECK_READY = 0x01U, /**< Callbacks with this mode are executed before entering into the + low-power mode. Callback function check if the device is ready + to enter the low-power mode */ + CY_SYSPM_CHECK_FAIL = 0x02U, /**< Callbacks with this mode are executed after the previous callbacks + execution with CY_SYSPM_CHECK_READY return CY_SYSPM_FAIL. The callback + with the CY_SYSPM_CHECK_FAIL mode should roll back the actions done in + the callbacks executed previously with CY_SYSPM_CHECK_READY */ + CY_SYSPM_BEFORE_TRANSITION = 0x04U, /**< The actions to be done before entering into the low-power mode */ + CY_SYSPM_AFTER_TRANSITION = 0x08U, /**< The actions to be done after exiting the low-power mode */ +} cy_en_syspm_callback_mode_t; + +/** \} group_syspm_data_enumerates */ + +/** +* \addtogroup group_syspm_macros +* \{ +*/ +/** +* \defgroup group_syspm_skip_callback_modes The Defines to skip the callbacks modes +* \{ +* The defines of the SysPm callbacks modes that can be skipped during execution. +* For more information about callbacks modes refer +* to \ref cy_en_syspm_callback_mode_t. +*/ +#define CY_SYSPM_SKIP_CHECK_READY (0x01U) /**< The define to skip the check ready mode in the syspm callback */ +#define CY_SYSPM_SKIP_CHECK_FAIL (0x02U) /**< The define to skip the check fail mode in the syspm callback */ +#define CY_SYSPM_SKIP_BEFORE_TRANSITION (0x04U) /**< The define to skip the before transition mode in the syspm callback */ +#define CY_SYSPM_SKIP_AFTER_TRANSITION (0x08U) /**< The define to skip the after transition mode in the syspm callback */ +/** \} group_syspm_skip_callback_modes */ +/** \} group_syspm_macros */ + +/** +* \addtogroup group_syspm_data_structures +* \{ +*/ + +/** The structure with the syspm callback parameters */ +typedef struct +{ + cy_en_syspm_callback_mode_t mode; /**< The callback mode. You can skip assigning as this element is for + internal usage, see \ref cy_en_syspm_callback_mode_t. This element + should not be defined as it is updated every time before the + callback function is executed */ + void *base; /**< The base address of a HW instance, matches name of the driver in + the API for the base address. Can be not defined if not required */ + void *context; /**< The context for the handler function. This item can be + skipped if not required. Can be not defined if not required */ + +} cy_stc_syspm_callback_params_t; + +/** The type for syspm callbacks */ +typedef cy_en_syspm_status_t (*Cy_SysPmCallback) (cy_stc_syspm_callback_params_t *callbackParams); + +/** The structure with the syspm callback configuration elements */ +typedef struct cy_stc_syspm_callback +{ + Cy_SysPmCallback callback; /**< The callback handler function */ + cy_en_syspm_callback_type_t type; /**< The callback type, see \ref cy_en_syspm_callback_type_t */ + uint32_t skipMode; /**< The mask of modes to be skipped during callback + execution, see \ref group_syspm_skip_callback_modes. The + corresponding callback mode won't execute if the + appropriate define is set. These values can be ORed. + If all modes are required to be executed this element + should be equal to zero. */ + + cy_stc_syspm_callback_params_t *callbackParams; /**< The address of a cy_stc_syspm_callback_params_t, + the callback is executed with these parameters */ + + struct cy_stc_syspm_callback *prevItm; /**< The previous list item. This element should not be + defined, or defined as NULL. It is for internal + usage to link this structure to the next registered structure. + It will be updated during callback registering. Do not + modify this element in run-time */ + + struct cy_stc_syspm_callback *nextItm; /**< The next list item. This element should not be + defined, or defined as NULL. It is for internal usage to + link this structure to the previous registered structure. + It will be updated during callback registering. Do not + modify this element in run-time */ +} cy_stc_syspm_callback_t; + +#ifdef CY_IP_MXUDB + + /** \cond INTERNAL */ + + /** This internal structure stores non-retained registers in the Deep Sleep + * power mode. + */ + typedef struct + { + /* The UDB interface control register */ + uint32_t CY_UDB_UDBIF_BANK_CTL_REG; + + /* The UDB bank control registers */ + uint32_t CY_UDB_BCTL_MDCLK_EN_REG; + uint32_t CY_UDB_BCTL_MBCLK_EN_REG; + uint32_t CY_UDB_BCTL_BOTSEL_L_REG; + uint32_t CY_UDB_BCTL_BOTSEL_U_REG; + uint32_t CY_UDB_BCTL_QCLK_EN0_REG; + uint32_t CY_UDB_BCTL_QCLK_EN1_REG; + uint32_t CY_UDB_BCTL_QCLK_EN2_REG; + } cy_stc_syspm_backup_regs_t; + /** \endcond */ + +#endif /* CY_IP_MXUDB */ + +/** \} group_syspm_data_structures */ + + +/** +* \addtogroup group_syspm_functions +* \{ +*/ + +/** +* \addtogroup group_syspm_functions_power_status +* \{ +*/ +#if(0u != CY_IP_M4CPUSS) + + __STATIC_INLINE bool Cy_SysPm_Cm4IsActive(void); + __STATIC_INLINE bool Cy_SysPm_Cm4IsSleep(void); + __STATIC_INLINE bool Cy_SysPm_Cm4IsDeepSleep(void); + __STATIC_INLINE bool Cy_SysPm_Cm4IsLowPower(void); + +#endif /* (0u != CY_IP_M4CPUSS) */ + +__STATIC_INLINE bool Cy_SysPm_Cm0IsActive(void); +__STATIC_INLINE bool Cy_SysPm_Cm0IsSleep(void); +__STATIC_INLINE bool Cy_SysPm_Cm0IsDeepSleep(void); +__STATIC_INLINE bool Cy_SysPm_Cm0IsLowPower(void); +__STATIC_INLINE bool Cy_SysPm_IsLowPower(void); +uint32_t Cy_SysPm_ReadStatus(void); +/** \} group_syspm_functions_power_status */ + +/** +* \addtogroup group_syspm_functions_power +* \{ +*/ +cy_en_syspm_status_t Cy_SysPm_Sleep(cy_en_syspm_waitfor_t waitFor); +cy_en_syspm_status_t Cy_SysPm_DeepSleep(cy_en_syspm_waitfor_t waitFor); +cy_en_syspm_status_t Cy_SysPm_Hibernate(void); +void Cy_SysPm_SetHibernateWakeupSource(uint32_t wakeupSource); +void Cy_SysPm_ClearHibernateWakeupSource(uint32_t wakeupSource); +cy_en_syspm_status_t Cy_SysPm_EnterLowPowerMode(void); +cy_en_syspm_status_t Cy_SysPm_ExitLowPowerMode(void); +void Cy_SysPm_SleepOnExit(bool enable); +/** \} group_syspm_functions_power */ + +/** +* \addtogroup group_syspm_functions_iofreeze +* \{ +*/ + +/** \cond INTERNAL */ +void Cy_SysPm_IoFreeze(void); +/** \endcond */ + +void Cy_SysPm_IoUnfreeze(void); +__STATIC_INLINE bool Cy_SysPm_IoIsFrozen(void); +/** \} group_syspm_functions_iofreeze */ + +/** +* \addtogroup group_syspm_functions_ldo +* \{ +*/ +void Cy_SysPm_LdoSetVoltage(cy_en_syspm_ldo_voltage_t voltage); +__STATIC_INLINE cy_en_syspm_ldo_voltage_t Cy_SysPm_LdoGetVoltage(void); +__STATIC_INLINE bool Cy_SysPm_LdoIsEnabled(void); +/** \} group_syspm_functions_ldo */ + +/** +* \addtogroup group_syspm_functions_pmic +* \{ +*/ +__STATIC_INLINE void Cy_SysPm_PmicEnable(void); +__STATIC_INLINE void Cy_SysPm_PmicDisable(cy_en_syspm_pmic_wakeup_polarity_t polarity); +__STATIC_INLINE void Cy_SysPm_PmicAlwaysEnable(void); +__STATIC_INLINE void Cy_SysPm_PmicEnableOutput(void); +__STATIC_INLINE void Cy_SysPm_PmicDisableOutput(void); +__STATIC_INLINE void Cy_SysPm_PmicLock(void); +__STATIC_INLINE void Cy_SysPm_PmicUnlock(void); +__STATIC_INLINE bool Cy_SysPm_PmicIsEnabled(void); +__STATIC_INLINE bool Cy_SysPm_PmicIsOutputEnabled(void); +__STATIC_INLINE bool Cy_SysPm_PmicIsLocked(void); +/** \} group_syspm_functions_pmic */ + +/** +* \addtogroup group_syspm_functions_backup +* \{ +*/ +__STATIC_INLINE void Cy_SysPm_BackupSetSupply(cy_en_syspm_vddbackup_control_t vddBackControl); +__STATIC_INLINE cy_en_syspm_vddbackup_control_t Cy_SysPm_BackupGetSupply(void); +__STATIC_INLINE void Cy_SysPm_BackupEnableVoltageMeasurement(void); +__STATIC_INLINE void Cy_SysPm_BackupDisableVoltageMeasurement(void); +__STATIC_INLINE void Cy_SysPm_BackupSuperCapCharge(cy_en_syspm_sc_charge_key_t key); +/** \} group_syspm_functions_backup */ + +/** +* \addtogroup group_syspm_functions_buck +* \{ +*/ +#if(0u != SRSS_BUCKCTL_PRESENT) + __STATIC_INLINE bool Cy_SysPm_BuckIsEnabled(void); + __STATIC_INLINE cy_en_syspm_buck_voltage1_t Cy_SysPm_BuckGetVoltage1(void); + + void Cy_SysPm_BuckEnable(cy_en_syspm_buck_voltage1_t voltage); + void Cy_SysPm_BuckSetVoltage1(cy_en_syspm_buck_voltage1_t voltage); + bool Cy_SysPm_BuckIsOutputEnabled(cy_en_syspm_buck_out_t output); + + #if(0u != SRSS_SIMOBUCK_PRESENT) + __STATIC_INLINE cy_en_syspm_buck_voltage2_t Cy_SysPm_BuckGetVoltage2(void); + __STATIC_INLINE void Cy_SysPm_BuckDisableVoltage2(void); + __STATIC_INLINE void Cy_SysPm_BuckSetVoltage2HwControl(bool hwControl); + __STATIC_INLINE bool Cy_SysPm_BuckIsVoltage2HwControlled(void); + void Cy_SysPm_BuckEnableVoltage2(void); + void Cy_SysPm_BuckSetVoltage2(cy_en_syspm_buck_voltage2_t voltage, bool waitToSettle); + #endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ +/** \} group_syspm_functions_buck */ + +/** +* \addtogroup group_syspm_functions_callback +* \{ +*/ +bool Cy_SysPm_RegisterCallback(cy_stc_syspm_callback_t *handler); +bool Cy_SysPm_UnregisterCallback(cy_stc_syspm_callback_t const *handler); +cy_en_syspm_status_t Cy_SysPm_ExecuteCallback(cy_en_syspm_callback_type_t type, cy_en_syspm_callback_mode_t mode); +/** \} group_syspm_functions_callback */ + +/** +* \addtogroup group_syspm_functions_power_status +* \{ +*/ + +#if(0u != CY_IP_M4CPUSS) + /******************************************************************************* + * Function Name: Cy_SysPm_Cm4IsActive + ****************************************************************************//** + * + * Checks whether CM4 is in Active mode. + * + * \return + * true - if CM4 is in Active mode; false - if the CM4 is not in Active mode. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm4IsActive + * + *******************************************************************************/ + __STATIC_INLINE bool Cy_SysPm_Cm4IsActive(void) + { + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_ACTIVE) != 0U); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_Cm4IsSleep + ****************************************************************************//** + * + * Checks whether the CM4 is in Sleep mode. + * + * \return + * true - if the CM4 is in Sleep mode; + * false - if the CM4 is not in Sleep mode. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm4IsSleep + * + *******************************************************************************/ + __STATIC_INLINE bool Cy_SysPm_Cm4IsSleep(void) + { + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_SLEEP) != 0U); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_Cm4IsDeepSleep + ****************************************************************************//** + * + * Checks whether the CM4 is in the Deep Sleep mode. + * + * \return + * true - if CM4 is in Deep Sleep mode; false - if the CM4 is not in + * Deep Sleep mode. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm4IsDeepSleep + * + *******************************************************************************/ + __STATIC_INLINE bool Cy_SysPm_Cm4IsDeepSleep(void) + { + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_DEEPSLEEP) != 0U); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_Cm4IsLowPower + ****************************************************************************//** + * + * Checks whether the CM4 is in Low-Power mode. Note that Low-Power mode is a + * status of the device. + * + * \return + * true - if the CM4 is in Low-Power mode; + * false - if the CM4 is not in Low-Power mode. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm4IsLowPower + * + *******************************************************************************/ + __STATIC_INLINE bool Cy_SysPm_Cm4IsLowPower(void) + { + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_LOWPOWER) != 0U); + } +/** \} group_syspm_functions_power_status */ +#endif /* (0u != CY_IP_M4CPUSS) */ + +/** +* \addtogroup group_syspm_functions_power_status +* \{ +*/ + +/******************************************************************************* +* Function Name: Cy_SysPm_Cm0IsActive +****************************************************************************//** +* +* Checks whether the CM0+ is in Active mode. +* +* \return +* true - if the CM0+ is in Active mode; +* false - if the CM0+ is not in Active mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm0IsActive +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_Cm0IsActive(void) +{ + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_ACTIVE) != 0U); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_Cm0IsSleep +****************************************************************************//** +* +* Checks whether the CM0+ is in Sleep mode. +* +* \return +* true - if the CM0+ is in Sleep mode; +* false - if the CM0+ is not in Sleep mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm0IsSleep +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_Cm0IsSleep(void) +{ + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_SLEEP) != 0U); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_Cm0IsDeepSleep +****************************************************************************//** +* +* Checks whether the CM0+ is in Deep Sleep mode. +* +* \return +* true - if the CM0+ is in Deep Sleep mode; +* false - if the CM0+ is not in Deep Sleep mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm0IsDeepSleep +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_Cm0IsDeepSleep(void) +{ + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_DEEPSLEEP) != 0U); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_Cm0IsLowPower +****************************************************************************//** +* +* Checks whether the CM0+ is in Low-Power mode. Note that Low-Power mode is a +* status of the device. +* +* \return +* true - if the CM0+ is in Low-Power mode; +* false - if the CM0+ is not in Low-Power mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_Cm0IsLowPower +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_Cm0IsLowPower(void) +{ + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_LOWPOWER) != 0U); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_IsLowPower +****************************************************************************//** +* +* Checks whether the device is in Low-Power mode. +* +* \return +* true - the system is in Low-Power mode; +* false - the system is is not in Low-Power mode. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_IsLowPower +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_IsLowPower(void) +{ + return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_SYSTEM_LOWPOWER) != 0U); +} + +/** \} group_syspm_functions_power_status */ + + +/** +* \addtogroup group_syspm_functions_buck +* \{ +*/ +#if(0u != SRSS_BUCKCTL_PRESENT) + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckIsEnabled + ****************************************************************************//** + * + * Get the current status of the Buck regulator. + * + * \return + * The current state of the Buck regulator. True if the Buck regulator + * is enabled; false if it is disabled. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_VoltageRegulator + * + *******************************************************************************/ + __STATIC_INLINE bool Cy_SysPm_BuckIsEnabled(void) + { + return((0u !=_FLD2VAL(SRSS_PWR_BUCK_CTL_BUCK_EN, SRSS->PWR_BUCK_CTL)) ? true : false); + } + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckGetVoltage1 + ****************************************************************************//** + * + * Gets the current nominal output 1 voltage (Vccbuck1) of + * the Buck regulator. + * + * \note The actual device output 1 voltage (Vccbuck1) can be different from + * the nominal voltage because the actual voltage value depends on the + * conditions including the load current. + * + * \return + * The nominal output voltage 1 (Vccbuck1) of the Buck regulator. + * See \ref cy_en_syspm_buck_voltage1_t. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_VoltageRegulator + * + *******************************************************************************/ + __STATIC_INLINE cy_en_syspm_buck_voltage1_t Cy_SysPm_BuckGetVoltage1(void) + { + uint32_t retVal; + retVal = _FLD2VAL(SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, SRSS->PWR_BUCK_CTL); + + return((cy_en_syspm_buck_voltage1_t) retVal); + } + + + #if(0u != SRSS_SIMOBUCK_PRESENT) + /******************************************************************************* + * Function Name: Cy_SysPm_BuckGetVoltage2 + ****************************************************************************//** + * + * Gets the current output 2 nominal voltage (Vbuckrf) of the SIMO + * Buck regulator. + * + * \note The actual device output 2 voltage (Vbuckrf) can be different from the + * nominal voltage because the actual voltage value depends on the conditions + * including the load current. + * + * \return + * The nominal output voltage of the Buck SIMO regulator output 2 + * voltage (Vbuckrf). + * See \ref cy_en_syspm_buck_voltage2_t. + * + * The function is applicable for devices with the SIMO Buck regulator. + * Refer to device datasheet about information if device contains + * SIMO Buck. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckGetVoltage2 + * + *******************************************************************************/ + __STATIC_INLINE cy_en_syspm_buck_voltage2_t Cy_SysPm_BuckGetVoltage2(void) + { + uint32_t retVal; + retVal = _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_SEL, SRSS->PWR_BUCK_CTL2); + + return((cy_en_syspm_buck_voltage2_t) retVal); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckDisableVoltage2 + ****************************************************************************//** + * + * Disables the output 2 voltage (Vbuckrf) of the SIMO Buck regulator. The + * output 2 voltage (Vbuckrf) of the Buck regulator is used to supply + * the BLE HW block. + * + * \note The function does not have effect if the Buck regulator is + * switched off. + * + * \note Ensures that the new voltage supply for the BLE HW block is settled + * and is stable before calling the Cy_SysPm_BuckDisableVoltage2() function. + * + * The function is applicable for devices with the SIMO Buck regulator. + * Refer to device datasheet about information if device contains + * SIMO Buck. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckDisableVoltage2 + * + *******************************************************************************/ + __STATIC_INLINE void Cy_SysPm_BuckDisableVoltage2(void) + { + /* Disable the Vbuck2 output */ + SRSS->PWR_BUCK_CTL2 &= ((uint32_t) ~ (_VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_EN, 1U))); + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckSetVoltage2HwControl + ****************************************************************************//** + * + * Sets the hardware control for the SIMO Buck output 2 (Vbuckrf). + * + * The hardware control for the Vbuckrf output. When this bit is set, the + * value in BUCK_OUT2_EN is ignored and the hardware signal is used instead. If the + * product has supporting hardware, it can directly control the enable signal + * for Vbuckrf. + * + * \param hwControl + * Enables/disables hardware control for the SIMO Buck output 2. + * + * Function does not have an effect if SIMO Buck regulator is disabled. + * + * The function is applicable for devices with the SIMO Buck regulator. + * Refer to device datasheet about information if device contains + * SIMO Buck. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckSetVoltage2HwControl + * + *******************************************************************************/ + __STATIC_INLINE void Cy_SysPm_BuckSetVoltage2HwControl(bool hwControl) + { + if(Cy_SysPm_BuckIsEnabled()) + { + if(hwControl) + { + SRSS->PWR_BUCK_CTL2 |= _VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, 1U); + } + else + { + SRSS->PWR_BUCK_CTL2 &= ((uint32_t)~(_VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, 1U))); + } + } + } + + + /******************************************************************************* + * Function Name: Cy_SysPm_BuckIsVoltage2HwControlled + ****************************************************************************//** + * + * Gets the hardware control for Vbuckrf. + * + * The hardware control for the Vbuckrf output. When this bit is set, the + * value in BUCK_OUT2_EN is ignored and the hardware signal is used instead. + * If the product has supporting hardware, it can directly control the enable + * signal for Vbuckrf. + * + * \return + * True if the HW control is set; false if the FW control is set for the + * Buck output 2. + * + * The function is applicable for devices with the SIMO Buck regulator. + * Refer to device datasheet about information if device contains + * SIMO Buck. + * + * \funcusage + * \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BuckIsVoltage2HwControlled + * + *******************************************************************************/ + __STATIC_INLINE bool Cy_SysPm_BuckIsVoltage2HwControlled(void) + { + return((0U != _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, SRSS->PWR_BUCK_CTL2)) ? true : false); + } + #endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ +/** \} group_syspm_functions_buck */ + +/** +* \addtogroup group_syspm_functions_ldo +* \{ +*/ + +/******************************************************************************* +* Function Name: Cy_SysPm_LdoGetVoltage +****************************************************************************//** +* +* Gets the current output voltage value of the LDO. +* +* \note The actual device Vccd voltage can be different from the +* nominal voltage because the actual voltage value depends on the conditions +* including the load current. +* +* \return +* The nominal output voltage of the LDO. +* See \ref cy_en_syspm_ldo_voltage_t. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_VoltageRegulator +* +*******************************************************************************/ +__STATIC_INLINE cy_en_syspm_ldo_voltage_t Cy_SysPm_LdoGetVoltage(void) +{ + uint32_t curVoltage; + + curVoltage = _FLD2VAL(SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, SRSS->PWR_TRIM_PWRSYS_CTL); + + return((curVoltage == (CY_SYSPM_SFLASH->LDO_0P9V_TRIM)) ? CY_SYSPM_LDO_VOLTAGE_0_9V : CY_SYSPM_LDO_VOLTAGE_1_1V); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_LdoIsEnabled +****************************************************************************//** +* +* Reads the current status of the LDO. +* +* \return +* True means the LDO is enabled. False means it is disabled. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_VoltageRegulator +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_LdoIsEnabled(void) +{ + return((0U != _FLD2VAL(SRSS_PWR_CTL_LINREG_DIS, SRSS->PWR_CTL)) ? false : true); +} + +/** \} group_syspm_functions_ldo */ + + +/** +* \addtogroup group_syspm_functions_iofreeze +* \{ +*/ + +/******************************************************************************* +* Function Name: Cy_SysPm_IoIsFrozen +****************************************************************************//** +* +* Checks whether IOs are frozen. +* +* \return Returns True if IOs are frozen.
False if IOs are unfrozen. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_IoUnfreeze +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_IoIsFrozen(void) +{ + return(0U != _FLD2VAL(SRSS_PWR_HIBERNATE_FREEZE, SRSS->PWR_HIBERNATE)); +} + +/** \} group_syspm_functions_iofreeze */ + + +/** +* \addtogroup group_syspm_functions_pmic +* \{ +*/ + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicEnable +****************************************************************************//** +* +* Enable the external PMIC that supplies Vddd (if present). +* +* For information about the PMIC input and output pins and their assignment in +* the specific families devices, refer to the appropriate device TRM. +* +* The function is not effective when the PMIC is locked. Call +* Cy_SysPm_PmicUnlock() before enabling the PMIC. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicEnable +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicEnable(void) +{ + if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) + { + BACKUP->PMIC_CTL = + _VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY) | + _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, 1U) | + _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN, 1U); + } +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicDisable +****************************************************************************//** +* +* Disables the PMIC. This function does not affect the output pin. Configures +* the PMIC input pin polarity. The PMIC input pin has programmable polarity to +* enable the PMIC using different input polarities. The PMIC output pin is +* automatically enabled when input polarity and configured polarity matches. +* The function is not effective when the active level of PMIC input pin +* is equal to configured PMIC polarity. +* +* The function is not effective when the PMIC is locked. Call +* Cy_SysPm_PmicUnlock() before enabling the PMIC. +* +* \param polarity +* Configures the PMIC wakeup input pin to be active low or active +* high. See \ref cy_en_syspm_pmic_wakeup_polarity_t. +* +* The PMIC will be enabled automatically by any of RTC alarm or PMIC wakeup +* event regardless of the PMIC lock state. +* +* \warning +* The PMIC is enabled automatically when you call Cy_SysPm_PmicLock(). +* To keep the PMIC disabled, the PMIC must remain unlocked. +* +* For information about the PMIC input and output pins and their assignment in +* the specific families devices, refer to the appropriate device TRM. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicDisable +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicDisable(cy_en_syspm_pmic_wakeup_polarity_t polarity) +{ + CY_ASSERT_L3(CY_SYSPM_IS_POLARITY_VALID(polarity)); + + if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) + { + BACKUP->PMIC_CTL = + (_VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY) | + _CLR_SET_FLD32U(BACKUP->PMIC_CTL, BACKUP_PMIC_CTL_POLARITY, (uint32_t) polarity)) & + ((uint32_t) ~ _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN, 1U)); + } +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicAlwaysEnable +****************************************************************************//** +* +* Enables the signal through the PMIC output pin. This is a Write once API, +* ensure that the PMIC cannot be disabled or polarity changed until a next +* device reset. +* +* For information about the PMIC input and output pins and their assignment in +* the specific families devices, refer to the appropriate device TRM. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicAlwaysEnable +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicAlwaysEnable(void) +{ + BACKUP->PMIC_CTL |= _VAL2FLD(BACKUP_PMIC_CTL_PMIC_ALWAYSEN, 1U); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicEnableOutput +****************************************************************************//** +* +* Enable the PMIC output. +* +* The function is not effective when the PMIC is locked. Call +* Cy_SysPm_PmicUnlock() before enabling the PMIC. +* +* For information about the PMIC output pin and it assignment in +* the specific families devices, refer to the appropriate device TRM. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicEnableOutput +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicEnableOutput(void) +{ + if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) + { + BACKUP->PMIC_CTL |= + _VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY) | _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, 1U); + } +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicDisableOutput +****************************************************************************//** +* +* Disables the PMIC output. +* +* When PMIC output pin is disabled and is unlocked the pmic output pin can be +* used for the another purpose. +* +* The function is not effective when the PMIC is locked. Call +* Cy_SysPm_PmicUnlock() before enabling the PMIC. +* +* For information about the PMIC output pin and it assignment in +* the specific families devices, refer to the appropriate device TRM. +* +* \warning +* The PMIC output is enabled automatically when you call Cy_SysPm_PmicLock(). +* To keep PMIC output disabled, the PMIC must remain unlocked. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicDisableOutput +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicDisableOutput(void) +{ + if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) + { + BACKUP->PMIC_CTL = + (BACKUP->PMIC_CTL | _VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY)) & + ((uint32_t) ~ _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, 1U)); + } +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicLock +****************************************************************************//** +* +* Locks the PMIC control register so that no changes can be made. The changes +* are related to the PMIC enabling/disabling and PMIC output signal +* enabling/disabling. +* +* \warning +* The PMIC and/or the PMIC output are enabled automatically when +* you call Cy_SysPm_PmicLock(). To keep the PMIC or PMIC output disabled, +* the PMIC must remain unlocked. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicLock +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicLock(void) +{ + BACKUP->PMIC_CTL = _CLR_SET_FLD32U(BACKUP->PMIC_CTL, BACKUP_PMIC_CTL_UNLOCK, 0U); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicUnlock +****************************************************************************//** +* +* Unlocks the PMIC control register so that changes can be made. The changes are +* related to the PMIC enabling/disabling and PMIC output signal +* enabling/disabling. +* +* \warning +* The PMIC and/or the PMIC output are enabled automatically when +* you call Cy_SysPm_PmicLock(). To keep the PMIC or PMIC output disabled, +* the PMIC must remain unlocked. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicEnable +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_PmicUnlock(void) +{ + BACKUP->PMIC_CTL = _CLR_SET_FLD32U(BACKUP->PMIC_CTL, BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicIsEnabled +****************************************************************************//** +* +* The function returns the status of the PMIC. +* +* \return +* True - The PMIC is enabled.
+* False - The PMIC is disabled.
+* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicLock +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_PmicIsEnabled(void) +{ + return(0U != _FLD2VAL(BACKUP_PMIC_CTL_PMIC_EN, BACKUP->PMIC_CTL)); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicIsOutputEnabled +****************************************************************************//** +* +* The function returns the status of the PMIC output. +* +* \return +* True - The PMIC output is enabled.
+* False - The PMIC output is disabled.
+* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicDisable +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_PmicIsOutputEnabled(void) +{ + return(0U != _FLD2VAL(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, BACKUP->PMIC_CTL)); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_PmicIsLocked +****************************************************************************//** +* +* Returns the PMIC lock status +* +* \return +* True - The PMIC is locked.
+* False - The PMIC is unlocked.
+* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_PmicLock +* +*******************************************************************************/ +__STATIC_INLINE bool Cy_SysPm_PmicIsLocked(void) +{ + return((_FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL) == CY_SYSPM_PMIC_UNLOCK_KEY) ? false : true); +} + +/** \} group_syspm_functions_pmic */ + + +/** +* \addtogroup group_syspm_functions_backup +* \{ +*/ + +/******************************************************************************* +* Function Name: Cy_SysPm_BackupSetSupply +****************************************************************************//** +* +* Sets the Backup Supply (Vddback) operation mode. +* +* \param +* vddBackControl +* Selects Backup Supply (Vddback) operation mode. +* See \ref cy_en_syspm_vddbackup_control_t. +* +* Refer to device TRM for more details about Backup supply modes. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BackupSetSupply +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_BackupSetSupply(cy_en_syspm_vddbackup_control_t vddBackControl) +{ + CY_ASSERT_L3(CY_SYSPM_IS_VDDBACKUP_VALID(vddBackControl)); + + BACKUP->CTL = _CLR_SET_FLD32U((BACKUP->CTL), BACKUP_CTL_VDDBAK_CTL, (uint32_t) vddBackControl); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_BackupGetSupply +****************************************************************************//** +* +* Returns the current Backup Supply (Vddback) operation mode. +* +* \return +* The current Backup Supply (Vddback) operation mode, +* see \ref cy_en_syspm_status_t. +* +* Refer to device TRM for more details about Backup supply modes. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BackupGetSupply +* +*******************************************************************************/ +__STATIC_INLINE cy_en_syspm_vddbackup_control_t Cy_SysPm_BackupGetSupply(void) +{ + uint32_t retVal; + retVal = _FLD2VAL(BACKUP_CTL_VDDBAK_CTL, BACKUP->CTL); + + return((cy_en_syspm_vddbackup_control_t) retVal); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_BackupEnableVoltageMeasurement +****************************************************************************//** +* +* This function enables the Vbackup supply measurement by the ADC. The function +* connects the Vbackup supply to the AMUXBUSA. Note that measured signal is +* scaled by 40% to allow being measured by the ADC. +* +* Refer to device TRM for more details about Vbackup supply measurement. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BackupEnableVoltageMeasurement +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_BackupEnableVoltageMeasurement(void) +{ + BACKUP->CTL |= BACKUP_CTL_VBACKUP_MEAS_Msk; +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_BackupDisableVoltageMeasurement +****************************************************************************//** +* +* The function disables the Vbackup supply measurement by the ADC. The function +* disconnects the Vbackup supply from the AMUXBUSA. +* +* Refer to device TRM for more details about Vbackup supply measurement. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BackupDisableVoltageMeasurement +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_BackupDisableVoltageMeasurement(void) +{ + BACKUP->CTL &= ((uint32_t) ~BACKUP_CTL_VBACKUP_MEAS_Msk); +} + + +/******************************************************************************* +* Function Name: Cy_SysPm_BackupSuperCapCharge +****************************************************************************//** +* +* Configures the supercapacitor charger circuit. +* +* \param key +* Passes the key to enable or disable the supercapacitor charger circuit. +* See \ref cy_en_syspm_sc_charge_key_t. +* +* \warning +* This function is used only for charging the supercapacitor. +* Do not use this function to charge a battery. Refer to device TRM for more +* details. +* +* \funcusage +* \snippet syspm/syspm_2_10_sut_01.cydsn/main_cm4.c snippet_Cy_SysPm_BackupSuperCapCharge +* +*******************************************************************************/ +__STATIC_INLINE void Cy_SysPm_BackupSuperCapCharge(cy_en_syspm_sc_charge_key_t key) +{ + CY_ASSERT_L3(CY_SYSPM_IS_SC_CHARGE_KEY_VALID(key)); + + if(key == CY_SYSPM_SC_CHARGE_ENABLE) + { + BACKUP->CTL = _CLR_SET_FLD32U((BACKUP->CTL), BACKUP_CTL_EN_CHARGE_KEY, (uint32_t) CY_SYSPM_SC_CHARGE_ENABLE); + } + else + { + BACKUP->CTL &= ((uint32_t) ~BACKUP_CTL_EN_CHARGE_KEY_Msk); + } +} + +/** \} group_syspm_functions_backup */ +/** \} group_syspm_functions*/ + +/** \cond INTERNAL */ + +/******************************************************************************* +* Backward compatibility macro. The following code is DEPRECATED and must +* not be used in new projects +*******************************************************************************/ +#if(0u != SRSS_BUCKCTL_PRESENT) + + /* BWC defines for Buck related functions */ + #if(0u != SRSS_SIMOBUCK_PRESENT) + typedef cy_en_syspm_buck_voltage1_t cy_en_syspm_simo_buck_voltage1_t; + typedef cy_en_syspm_buck_voltage2_t cy_en_syspm_simo_buck_voltage2_t; + + #define Cy_SysPm_SimoBuckGetVoltage2 Cy_SysPm_BuckGetVoltage2 + #define Cy_SysPm_DisableVoltage2 Cy_SysPm_BuckDisableVoltage2 + #define Cy_SysPm_EnableVoltage2 Cy_SysPm_BuckEnableVoltage2 + #define Cy_SysPm_SimoBuckSetHwControl Cy_SysPm_BuckSetVoltage2HwControl + #define Cy_SysPm_SimoBuckGetHwControl Cy_SysPm_BuckIsVoltage2HwControlled + #define Cy_SysPm_SimoBuckSetVoltage2 Cy_SysPm_BuckSetVoltage2 + + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_15V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_15V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_2V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_2V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_25V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_25V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_3V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_3V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_35V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_35V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_4V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_4V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_45V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_45V + #define CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_5V CY_SYSPM_BUCK_OUT2_VOLTAGE_1_5V + #endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ + + #define CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V + #define CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V CY_SYSPM_BUCK_OUT1_VOLTAGE_1_1V + + #define Cy_SysPm_SwitchToSimoBuck() (Cy_SysPm_BuckEnable(CY_SYSPM_BUCK_OUT1_VOLTAGE_0_9V)) + #define Cy_SysPm_SimoBuckGetVoltage1 Cy_SysPm_BuckGetVoltage1 + #define Cy_SysPm_SimoBuckIsEnabled Cy_SysPm_BuckIsEnabled + #define Cy_SysPm_SimoBuckSetVoltage1 Cy_SysPm_BuckSetVoltage1 + #define Cy_SysPm_SimoBuckOutputIsEnabled Cy_SysPm_BuckIsOutputEnabled +#endif /* (0u != SRSS_BUCKCTL_PRESENT) */ + +#define CY_SYSPM_LPCOMP0_LOW CY_SYSPM_HIBERNATE_LPCOMP0_LOW +#define CY_SYSPM_LPCOMP0_HIGH CY_SYSPM_HIBERNATE_LPCOMP0_HIGH +#define CY_SYSPM_LPCOMP1_LOW CY_SYSPM_HIBERNATE_LPCOMP1_LOW +#define CY_SYSPM_LPCOMP1_HIGH CY_SYSPM_HIBERNATE_LPCOMP1_HIGH +#define CY_SYSPM_HIBALARM CY_SYSPM_HIBERNATE_RTC_ALARM +#define CY_SYSPM_HIBWDT CY_SYSPM_HIBERNATE_WDT +#define CY_SYSPM_HIBPIN0_LOW CY_SYSPM_HIBERNATE_PIN0_LOW +#define CY_SYSPM_HIBPIN0_HIGH CY_SYSPM_HIBERNATE_PIN0_HIGH +#define CY_SYSPM_HIBPIN1_LOW CY_SYSPM_HIBERNATE_PIN1_LOW +#define CY_SYSPM_HIBPIN1_HIGH CY_SYSPM_HIBERNATE_PIN1_HIGH + +#define CY_SYSPM_ENTER_LP_MODE CY_SYSPM_ENTER_LOWPOWER_MODE +#define CY_SYSPM_EXIT_LP_MODE CY_SYSPM_EXIT_LOWPOWER_MODE + +/* BWC defines for functions related to low power transition*/ +#define Cy_SysPm_EnterLpMode Cy_SysPm_EnterLowPowerMode +#define Cy_SysPm_ExitLpMode Cy_SysPm_ExitLowPowerMode + +typedef cy_en_syspm_hibernate_wakeup_source_t cy_en_syspm_hib_wakeup_source_t; + +/* BWC defines related to hibernation functions */ +#define Cy_SysPm_SetHibWakeupSource Cy_SysPm_SetHibernateWakeupSource +#define Cy_SysPm_ClearHibWakeupSource Cy_SysPm_ClearHibernateWakeupSource +#define Cy_SysPm_GetIoFreezeStatus Cy_SysPm_IoIsFrozen + +/* BWC defines for Backup related functions */ +#define Cy_SysPm_SetBackupSupply Cy_SysPm_BackupSetSupply +#define Cy_SysPm_GetBackupSupply Cy_SysPm_BackupGetSupply +#define Cy_SysPm_EnableBackupVMeasure Cy_SysPm_BackupEnableVoltageMeasurement +#define Cy_SysPm_DisableBackupVMeasure Cy_SysPm_BackupDisableVoltageMeasurement + +/* BWC defines for PMIC related functions */ +#define Cy_SysPm_EnablePmic Cy_SysPm_PmicEnable +#define Cy_SysPm_DisablePmic Cy_SysPm_PmicDisable +#define Cy_SysPm_AlwaysEnablePmic Cy_SysPm_PmicAlwaysEnable +#define Cy_SysPm_EnablePmicOutput Cy_SysPm_PmicEnableOutput +#define Cy_SysPm_DisablePmicOutput Cy_SysPm_PmicDisableOutput +#define Cy_SysPm_LockPmic Cy_SysPm_PmicLock +#define Cy_SysPm_UnlockPmic Cy_SysPm_PmicUnlock +#define Cy_SysPm_IsPmicEnabled Cy_SysPm_PmicIsEnabled +#define Cy_SysPm_IsPmicOutputEnabled Cy_SysPm_PmicIsOutputEnabled +#define Cy_SysPm_IsPmicLocked Cy_SysPm_PmicIsLocked + +/** \endcond */ + +#ifdef __cplusplus +} +#endif + +#endif /* CY_SYSPM_H */ + +/** \} group_syspm */ + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/systick/cy_systick.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/systick/cy_systick.c similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/systick/cy_systick.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/systick/cy_systick.c index 8df829a952..7f5b477628 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/systick/cy_systick.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/systick/cy_systick.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_systick.c -* \version 1.0 +* \version 1.0.1 * * Provides the API definitions of the SisTick driver. * ******************************************************************************** * \copyright -* Copyright 2016, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/systick/cy_systick.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/systick/cy_systick.h similarity index 95% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/systick/cy_systick.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/systick/cy_systick.h index 41cf32a594..868769b864 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/systick/cy_systick.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/systick/cy_systick.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_systick.h -* \version 1.0 +* \version 1.0.1 * * Provides the API declarations of the SysTick driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -54,10 +54,12 @@ *
Description of Deviation(s)
8.88.12RequiredAn external object or function shall be declared in one and only one file.The variable is not used within project, so is defined without previous declaration.When an array is declared with external linkage, its size shall be +* stated explicitly or defined implicitly by initialization.The warning is related to the __ramVectors symbol defined in the assembly startup code. +* It's size is device-specific and unknown to the SysTick driver.
* @@ -66,16 +68,16 @@ * * * -* -* -* -* -* * * * * +* +* +* +* +* *
VersionChangesReason for Change
1.0Initial version
1.0.1Fixed a warning issued when the compilation of C++ source code was * enabled.
1.0Initial version
* * \defgroup group_systick_macros Macros diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm.h similarity index 90% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm.h index c9a95f425e..ffa91ef7c7 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_tcpwm.h -* \version 1.0 +* \version 1.0.1 * * The header file of the TCPWM driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -150,12 +150,33 @@ * reference manual (TRM). * * \section group_tcpwm_MISRA MISRA-C Compliance -* The tcpwm driver does not have any specific deviations +* +* +* +* +* +* +* +* +* +* +* +* +* +*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
14.2RAll non-null statements shall either: a) have at least one side-effect +* however executed, or b) cause control flow to change.The unused function parameters are cast to void. This statement +* has no side-effect and is used to suppress a compiler warning.
* * \section group_tcpwm_changelog Changelog * * * +* +* +* +* +* * * * @@ -169,7 +190,7 @@ * \addtogroup group_tcpwm_common * Common API for the Timer Counter PWM Block. * \{ -* \defgroup group_tcpwm_macros_common Macro +* \defgroup group_tcpwm_macros_common Macros * \defgroup group_tcpwm_functions_common Functions * \defgroup group_tcpwm_data_structures_common Data Structures * \defgroup group_tcpwm_enums Enumerated Types @@ -349,6 +370,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatusMasked(TCPWM_Type const *bas * \param counters * A bit field representing each counter in the TCPWM block. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Enable_Multiple +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Enable_Multiple(TCPWM_Type *base, uint32_t counters) { @@ -369,6 +393,9 @@ __STATIC_INLINE void Cy_TCPWM_Enable_Multiple(TCPWM_Type *base, uint32_t counter * \param counters * A bit field representing each counter in the TCPWM block. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Disable_Multiple +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Disable_Multiple(TCPWM_Type *base, uint32_t counters) { @@ -388,6 +415,9 @@ __STATIC_INLINE void Cy_TCPWM_Disable_Multiple(TCPWM_Type *base, uint32_t counte * \param counters * A bit field representing each counter in the TCPWM block. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Enable_Multiple +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_TriggerStart(TCPWM_Type *base, uint32_t counters) { @@ -407,6 +437,9 @@ __STATIC_INLINE void Cy_TCPWM_TriggerStart(TCPWM_Type *base, uint32_t counters) * \param counters * A bit field representing each counter in the TCPWM block. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_TriggerReloadOrIndex +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex(TCPWM_Type *base, uint32_t counters) { @@ -426,6 +459,9 @@ __STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex(TCPWM_Type *base, uint32_t co * \param counters * A bit field representing each counter in the TCPWM block. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_TriggerStopOrKill +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill(TCPWM_Type *base, uint32_t counters) { @@ -445,6 +481,9 @@ __STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill(TCPWM_Type *base, uint32_t count * \param counters * A bit field representing each counter in the TCPWM block. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_Capture +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap(TCPWM_Type *base, uint32_t counters) { @@ -467,6 +506,9 @@ __STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap(TCPWM_Type *base, uint32_t co * \return *. See \ref group_tcpwm_interrupt_sources * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_GetInterruptStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatus(TCPWM_Type const *base, uint32_t cntNum) { @@ -489,6 +531,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatus(TCPWM_Type const *base, uin * \param source * source to clear. See \ref group_tcpwm_interrupt_sources * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_ClearInterrupt(TCPWM_Type *base, uint32_t cntNum, uint32_t source) { @@ -512,6 +557,9 @@ __STATIC_INLINE void Cy_TCPWM_ClearInterrupt(TCPWM_Type *base, uint32_t cntNum, * \param source * The source to set an interrupt. See \ref group_tcpwm_interrupt_sources. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_SetInterrupt +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_SetInterrupt(TCPWM_Type *base, uint32_t cntNum, uint32_t source) { @@ -535,6 +583,9 @@ __STATIC_INLINE void Cy_TCPWM_SetInterrupt(TCPWM_Type *base, uint32_t cntNum, u * \param mask *. See \ref group_tcpwm_interrupt_sources * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_SetInterruptMask +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_SetInterruptMask(TCPWM_Type *base, uint32_t cntNum, uint32_t mask) { @@ -557,6 +608,9 @@ __STATIC_INLINE void Cy_TCPWM_SetInterruptMask(TCPWM_Type *base, uint32_t cntNum * \return * Interrupt Mask. See \ref group_tcpwm_interrupt_sources * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_SetInterruptMask +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptMask(TCPWM_Type const *base, uint32_t cntNum) { @@ -579,6 +633,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptMask(TCPWM_Type const *base, uint3 * \return * Interrupt Mask. See \ref group_tcpwm_interrupt_sources * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_GetInterruptStatusMasked +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatusMasked(TCPWM_Type const *base, uint32_t cntNum) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.c similarity index 93% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.c index e7120d5ab1..254035d052 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_tcpwm_counter.c -* \version 1.0 +* \version 1.0.1 * * \brief * The source file of the tcpwm driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -37,6 +37,10 @@ extern "C" { * * \return error / status code. See \ref cy_en_tcpwm_status_t. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_Config +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_Init +* *******************************************************************************/ cy_en_tcpwm_status_t Cy_TCPWM_Counter_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_counter_config_t const *config) @@ -112,6 +116,9 @@ cy_en_tcpwm_status_t Cy_TCPWM_Counter_Init(TCPWM_Type *base, uint32_t cntNum, * \param config * The pointer to configuration structure. See \ref cy_stc_tcpwm_counter_config_t. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_DeInit +* *******************************************************************************/ void Cy_TCPWM_Counter_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_counter_config_t const *config) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.h similarity index 91% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.h index 58591e4d92..31554fe2d7 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_counter.h @@ -1,24 +1,18 @@ /***************************************************************************//** * \file cy_tcpwm_counter.h -* \version 1.0 +* \version 1.0.1 * * \brief * The header file of the TCPWM Timer Counter driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ -/** -* \defgroup group_tcpwm_macros_counter Macro -* \defgroup group_tcpwm_functions_counter Functions -* \defgroup group_tcpwm_data_structures_counter Data Structures -* \} */ - #if !defined(CY_TCPWM_COUNTER_H) #define CY_TCPWM_COUNTER_H @@ -34,6 +28,12 @@ extern "C" { * Driver API for Timer/Counter. */ +/** +* \defgroup group_tcpwm_macros_counter Macros +* \defgroup group_tcpwm_functions_counter Functions +* \defgroup group_tcpwm_data_structures_counter Data Structures +* \} */ + /** * \addtogroup group_tcpwm_data_structures_counter * \{ @@ -169,6 +169,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const *base, uint * \param cntNum * The Counter instance number in the selected TCPWM. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_Init +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum) { @@ -188,6 +191,9 @@ __STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum) * \param cntNum * The Counter instance number in the selected TCPWM. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_DeInit +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Counter_Disable(TCPWM_Type *base, uint32_t cntNum) { @@ -210,6 +216,9 @@ __STATIC_INLINE void Cy_TCPWM_Counter_Disable(TCPWM_Type *base, uint32_t cntNum) * \return * The status. See \ref group_tcpwm_counter_status * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_GetStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus(TCPWM_Type const *base, uint32_t cntNum) { @@ -239,6 +248,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus(TCPWM_Type const *base, uin * \return * The capture value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_Capture +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture(TCPWM_Type const *base, uint32_t cntNum) { @@ -261,6 +273,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture(TCPWM_Type const *base, ui * \return * The buffered capture value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_Capture +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCaptureBuf(TCPWM_Type const *base, uint32_t cntNum) { @@ -283,6 +298,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCaptureBuf(TCPWM_Type const *base, * \param compare0 * The Compare0 value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetCompare0 +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0) { @@ -305,6 +323,9 @@ __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0(TCPWM_Type *base, uint32_t cnt * \return * Compare value 0. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetCompare0 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0(TCPWM_Type const *base, uint32_t cntNum) { @@ -327,6 +348,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0(TCPWM_Type const *base, u * \param compare1 * The Compare1 value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetCompare1 +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1) { @@ -349,6 +373,9 @@ __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1(TCPWM_Type *base, uint32_t cnt * \return * Compare value 1. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetCompare1 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1(TCPWM_Type const *base, uint32_t cntNum) { @@ -371,6 +398,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1(TCPWM_Type const *base, u * \param enable * true = swap enabled, false = swap disabled * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_EnableCompareSwap +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompareSwap(TCPWM_Type *base, uint32_t cntNum, bool enable) { @@ -400,8 +430,11 @@ __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompareSwap(TCPWM_Type *base, uint32 * \param count * The value to write into the counter. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetCounter +* *******************************************************************************/ -__STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count) +__STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count) { base->CNT[cntNum].COUNTER = count; } @@ -422,6 +455,9 @@ __STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntN * \return * The current counter value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_GetCounter +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter(TCPWM_Type const *base, uint32_t cntNum) { @@ -444,6 +480,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter(TCPWM_Type const *base, ui * \param period * The value to write into a period. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetPeriod +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod(TCPWM_Type *base, uint32_t cntNum, uint32_t period) { @@ -466,6 +505,9 @@ __STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod(TCPWM_Type *base, uint32_t cntNu * \return * The current period value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_counter_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_Counter_SetPeriod +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const *base, uint32_t cntNum) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.c similarity index 94% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.c index 2baeda5704..a4b3b6cd28 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_tcpwm_pwm.c -* \version 1.0 +* \version 1.0.1 * * \brief * The source file of the tcpwm driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -37,6 +37,10 @@ extern "C" { * * \return error / status code. See \ref cy_en_tcpwm_status_t. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_Config +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_Init +* *******************************************************************************/ cy_en_tcpwm_status_t Cy_TCPWM_PWM_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_pwm_config_t const *config) { @@ -123,6 +127,9 @@ cy_en_tcpwm_status_t Cy_TCPWM_PWM_Init(TCPWM_Type *base, uint32_t cntNum, cy_st * \param config * The pointer to a configuration structure. See \ref cy_stc_tcpwm_pwm_config_t. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_DeInit +* *******************************************************************************/ void Cy_TCPWM_PWM_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_pwm_config_t const *config) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.h similarity index 92% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.h index 9555e3aa1a..863ccfe013 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_pwm.h @@ -1,24 +1,18 @@ /***************************************************************************//** * \file cy_tcpwm_pwm.h -* \version 1.0 +* \version 1.0.1 * * \brief * The header file of the TCPWM PWM driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ -/** -* \defgroup group_tcpwm_macros_pwm Macro -* \defgroup group_tcpwm_functions_pwm Functions -* \defgroup group_tcpwm_data_structures_pwm Data Structures -* \} */ - #if !defined(CY_TCPWM_PWM_H) #define CY_TCPWM_PWM_H @@ -34,6 +28,12 @@ extern "C" { * \{ */ +/** +* \defgroup group_tcpwm_macros_pwm Macros +* \defgroup group_tcpwm_functions_pwm Functions +* \defgroup group_tcpwm_data_structures_pwm Data Structures +* \} */ + /** * \addtogroup group_tcpwm_data_structures_pwm * \{ @@ -231,6 +231,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_EnablePeriodSwap(TCPWM_Type *base, uint32_t cn * \param cntNum * The Counter instance number in the selected TCPWM. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_Init +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_Enable(TCPWM_Type *base, uint32_t cntNum) { @@ -249,6 +252,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_Enable(TCPWM_Type *base, uint32_t cntNum) * \param cntNum * The Counter instance number in the selected TCPWM. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_DeInit +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_Disable(TCPWM_Type *base, uint32_t cntNum) { @@ -271,6 +277,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_Disable(TCPWM_Type *base, uint32_t cntNum) * \return * The status. See \ref group_tcpwm_pwm_status * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_GetStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetStatus(TCPWM_Type const *base, uint32_t cntNum) { @@ -300,6 +309,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetStatus(TCPWM_Type const *base, uint32_t * \param compare0 * The Compare0 value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetCompare0 +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0) { @@ -322,6 +334,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0(TCPWM_Type *base, uint32_t cntNum, * \return * Compare value 0. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetCompare0 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0(TCPWM_Type const *base, uint32_t cntNum) { @@ -344,6 +359,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0(TCPWM_Type const *base, uint32 * \param compare1 * The Compare1 value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetCompare1 +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare1(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1) { @@ -366,6 +384,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare1(TCPWM_Type *base, uint32_t cntNum, * \return * Compare value 1. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetCompare1 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare1(TCPWM_Type const *base, uint32_t cntNum) { @@ -388,6 +409,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare1(TCPWM_Type const *base, uint32 * \param enable * true = swap enabled; false = swap disabled * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_EnableCompareSwap +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_EnableCompareSwap(TCPWM_Type *base, uint32_t cntNum, bool enable) { @@ -417,6 +441,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_EnableCompareSwap(TCPWM_Type *base, uint32_t c * \param count * The value to write into the counter. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetCounter +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count) { @@ -439,6 +466,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_SetCounter(TCPWM_Type *base, uint32_t cntNum, * \return * The current counter value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_GetCounter +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCounter(TCPWM_Type const *base, uint32_t cntNum) { @@ -461,6 +491,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCounter(TCPWM_Type const *base, uint32_ * \param period0 * The value to write into a period. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetPeriod0 +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod0(TCPWM_Type *base, uint32_t cntNum, uint32_t period0) { @@ -483,6 +516,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod0(TCPWM_Type *base, uint32_t cntNum, * \return * The current period value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetPeriod0 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0(TCPWM_Type const *base, uint32_t cntNum) { @@ -505,6 +541,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0(TCPWM_Type const *base, uint32_ * \param period1 * The value to write into a period1. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetPeriod1 +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod1(TCPWM_Type *base, uint32_t cntNum, uint32_t period1) { @@ -527,6 +566,9 @@ __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod1(TCPWM_Type *base, uint32_t cntNum, * \return * The current period value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_SetPeriod1 +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod1(TCPWM_Type const *base, uint32_t cntNum) { @@ -549,6 +591,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod1(TCPWM_Type const *base, uint32_ * \param enable * true = swap enabled; false = swap disabled * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_pwm_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_PWM_EnablePeriodSwap +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_PWM_EnablePeriodSwap(TCPWM_Type *base, uint32_t cntNum, bool enable) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.c similarity index 92% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.c index 30f78778ee..05499a2be4 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_tcpwm_quaddec.c -* \version 1.0 +* \version 1.0.1 * * \brief * The source file of the tcpwm driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -37,6 +37,10 @@ extern "C" { * * \return error / status code. See \ref cy_en_tcpwm_status_t. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_Config +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_Init +* *******************************************************************************/ cy_en_tcpwm_status_t Cy_TCPWM_QuadDec_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_quaddec_config_t const *config) @@ -87,6 +91,9 @@ cy_en_tcpwm_status_t Cy_TCPWM_QuadDec_Init(TCPWM_Type *base, uint32_t cntNum, * \param config * The pointer to a configuration structure. See \ref cy_stc_tcpwm_quaddec_config_t. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_DeInit +* *******************************************************************************/ void Cy_TCPWM_QuadDec_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_quaddec_config_t const *config) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.h similarity index 91% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.h index 4edffbc7b9..de455e454f 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/tcpwm/cy_tcpwm_quaddec.h @@ -1,24 +1,18 @@ /***************************************************************************//** * \file cy_tcpwm_quaddec.h -* \version 1.0 +* \version 1.0.1 * * \brief * The header file of the TCPWM Quadrature Decoder driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ -/** -* \defgroup group_tcpwm_macros_quaddec Macro -* \defgroup group_tcpwm_functions_quaddec Functions -* \defgroup group_tcpwm_data_structures_quaddec Data Structures -* \} */ - #if !defined(CY_TCPWM_QUADDEC_H) #define CY_TCPWM_QUADDEC_H @@ -34,6 +28,12 @@ extern "C" { * \{ */ +/** +* \defgroup group_tcpwm_macros_quaddec Macros +* \defgroup group_tcpwm_functions_quaddec Functions +* \defgroup group_tcpwm_data_structures_quaddec Data Structures +* \} */ + /** * \addtogroup group_tcpwm_data_structures_quaddec * \{ @@ -127,6 +127,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCounter(TCPWM_Type const *base, uin * \param cntNum * The Counter instance number in the selected TCPWM. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_Init +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_QuadDec_Enable(TCPWM_Type *base, uint32_t cntNum) { @@ -145,6 +148,9 @@ __STATIC_INLINE void Cy_TCPWM_QuadDec_Enable(TCPWM_Type *base, uint32_t cntNum) * \param cntNum * The Counter instance number in the selected TCPWM. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_DeInit +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_QuadDec_Disable(TCPWM_Type *base, uint32_t cntNum) { @@ -167,6 +173,9 @@ __STATIC_INLINE void Cy_TCPWM_QuadDec_Disable(TCPWM_Type *base, uint32_t cntNum) * \return * The status. See \ref group_tcpwm_quaddec_status * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_GetStatus +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetStatus(TCPWM_Type const *base, uint32_t cntNum) { @@ -196,6 +205,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetStatus(TCPWM_Type const *base, uint * \return * The capture value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_Capture +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture(TCPWM_Type const *base, uint32_t cntNum) { @@ -218,6 +230,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture(TCPWM_Type const *base, uin * \return * The buffered capture value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_Capture +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCaptureBuf(TCPWM_Type const *base, uint32_t cntNum) { @@ -240,6 +255,9 @@ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCaptureBuf(TCPWM_Type const *base, * \param count * The value to write into the counter. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_SetCounter +* *******************************************************************************/ __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count) { @@ -262,6 +280,9 @@ __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCounter(TCPWM_Type *base, uint32_t cntN * \return * The current counter value. * +* \funcusage +* \snippet tcpwm/tcpwm_v1_0_quaddec_sut_01.cydsn/main_cm4.c snippet_Cy_TCPWM_QuadDec_GetCounter +* *******************************************************************************/ __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCounter(TCPWM_Type const *base, uint32_t cntNum) { diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/trigmux/cy_trigmux.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/trigmux/cy_trigmux.c similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/trigmux/cy_trigmux.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/trigmux/cy_trigmux.c index 59b103987e..a75e83bfd8 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/trigmux/cy_trigmux.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/trigmux/cy_trigmux.c @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/trigmux/cy_trigmux.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/trigmux/cy_trigmux.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/trigmux/cy_trigmux.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/trigmux/cy_trigmux.h index fdc3e5e9aa..d1c31e77e6 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/trigmux/cy_trigmux.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/trigmux/cy_trigmux.h @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -111,11 +111,6 @@ *
VersionChangesReason for Change
1.0.1Added a deviation to the MISRA Compliance section. +* Added function-level code snippets.Documentation update and clarification
1.0Initial version
* * -* -* -* -* -* * * * * +* +* +* +* +* *
VersionChangesReason for Change
1.0Initial version
1.10The input/output bit in the trigLine parameter of the * Cy_TrigMux_SwTrigger() function is changed to 30.
@@ -123,6 +118,11 @@ * Added input parameter validation to the API functions.
1.0Initial version
* * \defgroup group_trigmux_macros Macros diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/wdt/cy_wdt.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/wdt/cy_wdt.c similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/wdt/cy_wdt.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/wdt/cy_wdt.c index 67d596b456..3260df3356 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/wdt/cy_wdt.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/wdt/cy_wdt.c @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_wdt.c -* \version 1.0 +* \version 1.0.1 * * This file provides the source code to the API for the WDT driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/wdt/cy_wdt.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/wdt/cy_wdt.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/wdt/cy_wdt.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/wdt/cy_wdt.h index 62c63ea0d9..82cc433f0d 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/wdt/cy_wdt.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/drivers/peripheral/wdt/cy_wdt.h @@ -1,12 +1,12 @@ /***************************************************************************//** * \file cy_wdt.h -* \version 1.0 +* \version 1.0.1 * * This file provides constants and parameter values for the WDT driver. * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -24,6 +24,8 @@ * A timeout period is set up in the Watchdog timer, and if a timeout occurs, the * device is reset (WRES).
* The Second use case is to generate periodic interrupts. +* It is strongly recommended not to use the WDT for periodic interrupt +* generation. However, if absolutely required, see information below. * * A "reset cause" register exists, and the firmware should check this register * at a start-up. An appropriate action can be taken if a WRES reset is detected. @@ -163,6 +165,11 @@ * * * +* +* +* +* +* * * * diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_backup.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_backup.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_backup.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_backup.h index af7ab0d13a..f797399c6c 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_backup.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_backup.h @@ -5,12 +5,12 @@ * BACKUP IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ble.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ble.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ble.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ble.h index b136579217..8513db5292 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ble.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ble.h @@ -5,12 +5,12 @@ * BLE IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_cpuss.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_cpuss.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_cpuss.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_cpuss.h index 184cce21ce..a7ab807b3a 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_cpuss.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_cpuss.h @@ -5,12 +5,12 @@ * CPUSS IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_crypto.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_crypto.h similarity index 85% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_crypto.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_crypto.h index 6069c0ac20..73bccdd220 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_crypto.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_crypto.h @@ -4,13 +4,9 @@ * \brief * CRYPTO IP definitions * -* \note -* Generated 7/14/2017 by CyDeviceHeaderGenerator v1.1.0.67 -* from the register map configuration rev#20170327 -* ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_csd.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_csd.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_csd.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_csd.h index b6fcc35443..80ed04fabd 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_csd.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_csd.h @@ -5,12 +5,12 @@ * CSD IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ctbm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ctbm.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ctbm.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ctbm.h index fe71157314..4a86dde28e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ctbm.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ctbm.h @@ -5,12 +5,12 @@ * CTBM IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ctdac.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ctdac.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ctdac.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ctdac.h index b9f2af7e59..1f537fcb2f 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ctdac.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ctdac.h @@ -5,12 +5,12 @@ * CTDAC IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_dw.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_dw.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_dw.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_dw.h index 9dfd5db009..bb16655471 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_dw.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_dw.h @@ -5,12 +5,12 @@ * DW IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_efuse.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_efuse.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_efuse.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_efuse.h index ffdd71db38..251e5f87bc 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_efuse.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_efuse.h @@ -5,12 +5,12 @@ * EFUSE IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_efuse_data.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_efuse_data.h new file mode 100644 index 0000000000..d62577eea8 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_efuse_data.h @@ -0,0 +1,105 @@ +/***************************************************************************//** +* \file cyip_efuse_data.h +* +* \brief +* EFUSE_DATA IP definitions +* +* \note +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 +* +******************************************************************************** +* \copyright +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. +* You may use this file only in accordance with the license, terms, conditions, +* disclaimers, and limitations in the end user license agreement accompanying +* the software package with which this file was provided. +*******************************************************************************/ + +#ifndef _CYIP_EFUSE_DATA_H_ +#define _CYIP_EFUSE_DATA_H_ + +#include "cyip_headers.h" + +/** + * \brief DEAD access restrictions (DEAD_ACCESS_RESTRICT0) + */ +typedef struct { + uint8_t CM0_DISABLE; + uint8_t CM4_DISABLE; + uint8_t SYS_DISABLE; + uint8_t SYS_AP_MPU_ENABLE; + uint8_t SFLASH_ALLOWED[2]; + uint8_t MMIO_ALLOWED[2]; +} cy_stc_dead_access_restrict0_t; + +/** + * \brief DEAD access restrictions (DEAD_ACCESS_RESTRICT1) + */ +typedef struct { + uint8_t FLASH_ALLOWED[3]; + uint8_t SRAM_ALLOWED[3]; + uint8_t SMIF_XIP_ALLOWED; + uint8_t DIRECT_EXECUTE_DISABLE; +} cy_stc_dead_access_restrict1_t; + +/** + * \brief SECURE access restrictions (SECURE_ACCESS_RESTRICT0) + */ +typedef struct { + uint8_t CM0_DISABLE; + uint8_t CM4_DISABLE; + uint8_t SYS_DISABLE; + uint8_t SYS_AP_MPU_ENABLE; + uint8_t SFLASH_ALLOWED[2]; + uint8_t MMIO_ALLOWED[2]; +} cy_stc_secure_access_restrict0_t; + +/** + * \brief SECURE access restrictions (SECURE_ACCESS_RESTRICT1) + */ +typedef struct { + uint8_t FLASH_ALLOWED[3]; + uint8_t SRAM_ALLOWED[3]; + uint8_t SMIF_XIP_ALLOWED; + uint8_t DIRECT_EXECUTE_DISABLE; +} cy_stc_secure_access_restrict1_t; + +/** + * \brief NORMAL, SECURE_WITH_DEBUG, and SECURE fuse bits (LIFECYCLE_STAGE) + */ +typedef struct { + uint8_t NORMAL; + uint8_t SECURE_WITH_DEBUG; + uint8_t SECURE; + uint8_t RMA; + uint8_t RESERVED[4]; +} cy_stc_lifecycle_stage_t; + +/** + * \brief Customer data (CUSTOMER_DATA) + */ +typedef struct { + uint8_t CUSTOMER_USE[8]; +} cy_stc_customer_data_t; + + +/** + * \brief eFUSE memory (EFUSE_DATA) + */ +typedef struct { + uint8_t RESERVED[312]; + cy_stc_dead_access_restrict0_t DEAD_ACCESS_RESTRICT0; + cy_stc_dead_access_restrict1_t DEAD_ACCESS_RESTRICT1; + cy_stc_secure_access_restrict0_t SECURE_ACCESS_RESTRICT0; + cy_stc_secure_access_restrict1_t SECURE_ACCESS_RESTRICT1; + cy_stc_lifecycle_stage_t LIFECYCLE_STAGE; + uint8_t RESERVED1[160]; + cy_stc_customer_data_t CUSTOMER_DATA[64]; +} cy_stc_efuse_data_t; + + +#endif /* _CYIP_EFUSE_DATA_H_ */ + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_fault.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_fault.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_fault.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_fault.h index d8d5d435bd..3c8f17927b 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_fault.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_fault.h @@ -5,12 +5,12 @@ * FAULT IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_flashc.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_flashc.h similarity index 90% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_flashc.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_flashc.h index 1d60b122c2..0414e51df3 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_flashc.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_flashc.h @@ -5,12 +5,12 @@ * FLASHC IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -65,7 +65,7 @@ typedef struct { __IOM uint32_t RED_CTL67; /*!< 0x0000008C Redundancy Controll normal sectors 6,7 */ __IOM uint32_t RED_CTL_SM01; /*!< 0x00000090 Redundancy Controll special sectors 0,1 */ __IM uint32_t RESERVED1[27]; - __IM uint32_t TM_CMPR[32]; /*!< 0x00000100 Comparison between FM data out and Page Latches on each column. */ + __IM uint32_t TM_CMPR[32]; /*!< 0x00000100 Do Not Use */ __IM uint32_t RESERVED2[416]; __IOM uint32_t FM_HV_DATA[256]; /*!< 0x00000800 Flash macro high Voltage page latches data */ __IM uint32_t FM_MEM_DATA[256]; /*!< 0x00000C00 Flash macro memory sense amplifier and column decoder data */ @@ -216,17 +216,17 @@ typedef struct { #define FLASHC_FM_CTL_ANA_CTL1_NDAC_Msk 0xF000000UL #define FLASHC_FM_CTL_ANA_CTL1_VPROT_OVERRIDE_Pos 28UL #define FLASHC_FM_CTL_ANA_CTL1_VPROT_OVERRIDE_Msk 0x10000000UL -#define FLASHC_FM_CTL_ANA_CTL1_SPARE2_Pos 29UL -#define FLASHC_FM_CTL_ANA_CTL1_SPARE2_Msk 0x20000000UL +#define FLASHC_FM_CTL_ANA_CTL1_R_GRANT_CTL_Pos 29UL +#define FLASHC_FM_CTL_ANA_CTL1_R_GRANT_CTL_Msk 0x20000000UL #define FLASHC_FM_CTL_ANA_CTL1_RST_SFT_HVPL_Pos 30UL #define FLASHC_FM_CTL_ANA_CTL1_RST_SFT_HVPL_Msk 0x40000000UL /* FLASHC_FM_CTL.GEOMETRY_GEN */ -#define FLASHC_FM_CTL_GEOMETRY_GEN_RWW_Pos 1UL -#define FLASHC_FM_CTL_GEOMETRY_GEN_RWW_Msk 0x2UL -#define FLASHC_FM_CTL_GEOMETRY_GEN_MAX_DOUT_WIDTH_Pos 2UL -#define FLASHC_FM_CTL_GEOMETRY_GEN_MAX_DOUT_WIDTH_Msk 0x4UL -#define FLASHC_FM_CTL_GEOMETRY_GEN_SECTOR0_SR_Pos 3UL -#define FLASHC_FM_CTL_GEOMETRY_GEN_SECTOR0_SR_Msk 0x8UL +#define FLASHC_FM_CTL_GEOMETRY_GEN_DNU_0X20_1_Pos 1UL +#define FLASHC_FM_CTL_GEOMETRY_GEN_DNU_0X20_1_Msk 0x2UL +#define FLASHC_FM_CTL_GEOMETRY_GEN_DNU_0X20_2_Pos 2UL +#define FLASHC_FM_CTL_GEOMETRY_GEN_DNU_0X20_2_Msk 0x4UL +#define FLASHC_FM_CTL_GEOMETRY_GEN_DNU_0X20_3_Pos 3UL +#define FLASHC_FM_CTL_GEOMETRY_GEN_DNU_0X20_3_Msk 0x8UL /* FLASHC_FM_CTL.TEST_CTL */ #define FLASHC_FM_CTL_TEST_CTL_TEST_MODE_Pos 0UL #define FLASHC_FM_CTL_TEST_CTL_TEST_MODE_Msk 0x1FUL @@ -254,10 +254,10 @@ typedef struct { #define FLASHC_FM_CTL_WAIT_CTL_WAIT_FM_HV_WR_Pos 16UL #define FLASHC_FM_CTL_WAIT_CTL_WAIT_FM_HV_WR_Msk 0x70000UL /* FLASHC_FM_CTL.MONITOR_STATUS */ -#define FLASHC_FM_CTL_MONITOR_STATUS_NEG_PUMP_VLO_Pos 1UL -#define FLASHC_FM_CTL_MONITOR_STATUS_NEG_PUMP_VLO_Msk 0x2UL -#define FLASHC_FM_CTL_MONITOR_STATUS_POS_PUMP_VHI_Pos 2UL -#define FLASHC_FM_CTL_MONITOR_STATUS_POS_PUMP_VHI_Msk 0x4UL +#define FLASHC_FM_CTL_MONITOR_STATUS_POS_PUMP_VLO_Pos 1UL +#define FLASHC_FM_CTL_MONITOR_STATUS_POS_PUMP_VLO_Msk 0x2UL +#define FLASHC_FM_CTL_MONITOR_STATUS_NEG_PUMP_VHI_Pos 2UL +#define FLASHC_FM_CTL_MONITOR_STATUS_NEG_PUMP_VHI_Msk 0x4UL /* FLASHC_FM_CTL.SCRATCH_CTL */ #define FLASHC_FM_CTL_SCRATCH_CTL_DUMMY32_Pos 0UL #define FLASHC_FM_CTL_SCRATCH_CTL_DUMMY32_Msk 0xFFFFFFFFUL @@ -362,23 +362,47 @@ typedef struct { #define FLASHC_FM_CTL_RED_CTL23_RED_EN_3_Pos 24UL #define FLASHC_FM_CTL_RED_CTL23_RED_EN_3_Msk 0x1000000UL /* FLASHC_FM_CTL.RED_CTL45 */ -#define FLASHC_FM_CTL_RED_CTL45_RED_ADDR_4_Pos 0UL -#define FLASHC_FM_CTL_RED_CTL45_RED_ADDR_4_Msk 0xFFUL -#define FLASHC_FM_CTL_RED_CTL45_RED_EN_4_Pos 8UL -#define FLASHC_FM_CTL_RED_CTL45_RED_EN_4_Msk 0x100UL -#define FLASHC_FM_CTL_RED_CTL45_RED_ADDR_5_Pos 16UL -#define FLASHC_FM_CTL_RED_CTL45_RED_ADDR_5_Msk 0xFF0000UL -#define FLASHC_FM_CTL_RED_CTL45_RED_EN_5_Pos 24UL -#define FLASHC_FM_CTL_RED_CTL45_RED_EN_5_Msk 0x1000000UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_1_Pos 0UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_1_Msk 0x1UL +#define FLASHC_FM_CTL_RED_CTL45_REG_ACT_HV_Pos 1UL +#define FLASHC_FM_CTL_RED_CTL45_REG_ACT_HV_Msk 0x2UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_3_Pos 2UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_3_Msk 0x4UL +#define FLASHC_FM_CTL_RED_CTL45_FDIV_TRIM_HV_0_Pos 3UL +#define FLASHC_FM_CTL_RED_CTL45_FDIV_TRIM_HV_0_Msk 0x8UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_5_Pos 4UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_5_Msk 0x10UL +#define FLASHC_FM_CTL_RED_CTL45_FDIV_TRIM_HV_1_Pos 5UL +#define FLASHC_FM_CTL_RED_CTL45_FDIV_TRIM_HV_1_Msk 0x20UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_6_Pos 6UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_6_Msk 0x40UL +#define FLASHC_FM_CTL_RED_CTL45_VLIM_TRIM_HV_0_Pos 7UL +#define FLASHC_FM_CTL_RED_CTL45_VLIM_TRIM_HV_0_Msk 0x80UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_8_Pos 8UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_8_Msk 0x100UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_23_16_Pos 16UL +#define FLASHC_FM_CTL_RED_CTL45_DNU_45_23_16_Msk 0xFF0000UL /* FLASHC_FM_CTL.RED_CTL67 */ -#define FLASHC_FM_CTL_RED_CTL67_RED_ADDR_6_Pos 0UL -#define FLASHC_FM_CTL_RED_CTL67_RED_ADDR_6_Msk 0xFFUL -#define FLASHC_FM_CTL_RED_CTL67_RED_EN_6_Pos 8UL -#define FLASHC_FM_CTL_RED_CTL67_RED_EN_6_Msk 0x100UL -#define FLASHC_FM_CTL_RED_CTL67_RED_ADDR_7_Pos 16UL -#define FLASHC_FM_CTL_RED_CTL67_RED_ADDR_7_Msk 0xFF0000UL -#define FLASHC_FM_CTL_RED_CTL67_RED_EN_7_Pos 24UL -#define FLASHC_FM_CTL_RED_CTL67_RED_EN_7_Msk 0x1000000UL +#define FLASHC_FM_CTL_RED_CTL67_VLIM_TRIM_HV_1_Pos 0UL +#define FLASHC_FM_CTL_RED_CTL67_VLIM_TRIM_HV_1_Msk 0x1UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_1_Pos 1UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_1_Msk 0x2UL +#define FLASHC_FM_CTL_RED_CTL67_VPROT_ACT_HV_Pos 2UL +#define FLASHC_FM_CTL_RED_CTL67_VPROT_ACT_HV_Msk 0x4UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_3_Pos 3UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_3_Msk 0x8UL +#define FLASHC_FM_CTL_RED_CTL67_IPREF_TC_HV_Pos 4UL +#define FLASHC_FM_CTL_RED_CTL67_IPREF_TC_HV_Msk 0x10UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_5_Pos 5UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_5_Msk 0x20UL +#define FLASHC_FM_CTL_RED_CTL67_IPREF_TRIMA_HI_HV_Pos 6UL +#define FLASHC_FM_CTL_RED_CTL67_IPREF_TRIMA_HI_HV_Msk 0x40UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_7_Pos 7UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_7_Msk 0x80UL +#define FLASHC_FM_CTL_RED_CTL67_IPREF_TRIMA_LO_HV_Pos 8UL +#define FLASHC_FM_CTL_RED_CTL67_IPREF_TRIMA_LO_HV_Msk 0x100UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_23_16_Pos 16UL +#define FLASHC_FM_CTL_RED_CTL67_DNU_67_23_16_Msk 0xFF0000UL /* FLASHC_FM_CTL.RED_CTL_SM01 */ #define FLASHC_FM_CTL_RED_CTL_SM01_RED_ADDR_SM0_Pos 0UL #define FLASHC_FM_CTL_RED_CTL_SM01_RED_ADDR_SM0_Msk 0xFFUL diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_gpio.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_gpio.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_gpio.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_gpio.h index a1a977e3d7..e285570c3d 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_gpio.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_gpio.h @@ -5,12 +5,12 @@ * GPIO IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_headers.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_headers.h similarity index 94% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_headers.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_headers.h index 25604d3c32..0e9567bd53 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_headers.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_headers.h @@ -6,7 +6,7 @@ * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_hsiom.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_hsiom.h similarity index 68% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_hsiom.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_hsiom.h index cb6bec2f4d..067e7824d5 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_hsiom.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_hsiom.h @@ -5,12 +5,12 @@ * HSIOM IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -44,14 +44,7 @@ typedef struct { HSIOM_PRT_Type PRT[128]; /*!< 0x00000000 HSIOM port registers */ __IM uint32_t RESERVED[1536]; __IOM uint32_t AMUX_SPLIT_CTL[64]; /*!< 0x00002000 AMUX splitter cell control */ - __IM uint32_t RESERVED1[64]; - __IOM uint32_t MONITOR_CTL_0; /*!< 0x00002200 Power/Ground Monitor cell control 0 */ - __IOM uint32_t MONITOR_CTL_1; /*!< 0x00002204 Power/Ground Monitor cell control 1 */ - __IOM uint32_t MONITOR_CTL_2; /*!< 0x00002208 Power/Ground Monitor cell control 2 */ - __IOM uint32_t MONITOR_CTL_3; /*!< 0x0000220C Power/Ground Monitor cell control 3 */ - __IM uint32_t RESERVED2[12]; - __IOM uint32_t ALT_JTAG_EN; /*!< 0x00002240 Alternate JTAG IF selection register */ -} HSIOM_Type; /*!< Size = 8772 (0x2244) */ +} HSIOM_Type; /*!< Size = 8448 (0x2100) */ /* HSIOM_PRT.PORT_SEL0 */ @@ -87,21 +80,6 @@ typedef struct { #define HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk 0x20UL #define HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_S0_Pos 6UL #define HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_S0_Msk 0x40UL -/* HSIOM.MONITOR_CTL_0 */ -#define HSIOM_MONITOR_CTL_0_MONITOR_EN_Pos 0UL -#define HSIOM_MONITOR_CTL_0_MONITOR_EN_Msk 0xFFFFFFFFUL -/* HSIOM.MONITOR_CTL_1 */ -#define HSIOM_MONITOR_CTL_1_MONITOR_EN_Pos 0UL -#define HSIOM_MONITOR_CTL_1_MONITOR_EN_Msk 0xFFFFFFFFUL -/* HSIOM.MONITOR_CTL_2 */ -#define HSIOM_MONITOR_CTL_2_MONITOR_EN_Pos 0UL -#define HSIOM_MONITOR_CTL_2_MONITOR_EN_Msk 0xFFFFFFFFUL -/* HSIOM.MONITOR_CTL_3 */ -#define HSIOM_MONITOR_CTL_3_MONITOR_EN_Pos 0UL -#define HSIOM_MONITOR_CTL_3_MONITOR_EN_Msk 0xFFFFFFFFUL -/* HSIOM.ALT_JTAG_EN */ -#define HSIOM_ALT_JTAG_EN_ENABLE_Pos 31UL -#define HSIOM_ALT_JTAG_EN_ENABLE_Msk 0x80000000UL #endif /* _CYIP_HSIOM_H_ */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_i2s.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_i2s.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_i2s.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_i2s.h index 0134d197e0..1383cb1977 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_i2s.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_i2s.h @@ -5,12 +5,12 @@ * I2S IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ipc.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ipc.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ipc.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ipc.h index bae437a8d8..9726b5e329 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_ipc.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_ipc.h @@ -5,12 +5,12 @@ * IPC IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_lcd.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_lcd.h similarity index 95% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_lcd.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_lcd.h index b61a3941ee..5913c6f51e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_lcd.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_lcd.h @@ -5,12 +5,12 @@ * LCD IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_lpcomp.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_lpcomp.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_lpcomp.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_lpcomp.h index 32a67741ff..e19db35b0f 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_lpcomp.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_lpcomp.h @@ -5,12 +5,12 @@ * LPCOMP IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_pass.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_pass.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_pass.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_pass.h index 5697385a97..0c75a92960 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_pass.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_pass.h @@ -5,12 +5,12 @@ * PASS IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_pdm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_pdm.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_pdm.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_pdm.h index 17f7de5c92..db7674282c 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_pdm.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_pdm.h @@ -5,12 +5,12 @@ * PDM IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_peri.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_peri.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_peri.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_peri.h index 60c517ae49..5771bc740e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_peri.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_peri.h @@ -5,12 +5,12 @@ * PERI IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_profile.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_profile.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_profile.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_profile.h index 201aa1c2e9..3ba7bdaa6f 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_profile.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_profile.h @@ -5,12 +5,12 @@ * PROFILE IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_prot.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_prot.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_prot.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_prot.h index 30f219e87a..b812954058 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_prot.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_prot.h @@ -5,12 +5,12 @@ * PROT IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_sar.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_sar.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_sar.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_sar.h index ff2d58a8e4..b3d7f1e325 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_sar.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_sar.h @@ -5,12 +5,12 @@ * SAR IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_scb.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_scb.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_scb.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_scb.h index e8f8252068..a5689ab56e 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_scb.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_scb.h @@ -5,12 +5,12 @@ * SCB IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_sflash.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_sflash.h similarity index 77% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_sflash.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_sflash.h index bab77d746b..2255521a16 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_sflash.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_sflash.h @@ -5,12 +5,12 @@ * SFLASH IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -31,9 +31,12 @@ * \brief FLASH Supervisory Region (SFLASH) */ typedef struct { - __IM uint16_t RESERVED; - __IOM uint16_t SILICON_ID; /*!< 0x00000002 Indicates siliconID of the device */ - __IM uint32_t RESERVED1[383]; + __IM uint8_t RESERVED; + __IOM uint8_t SI_REVISION_ID; /*!< 0x00000001 Indicates Silicon Revision ID of the device */ + __IOM uint16_t SILICON_ID; /*!< 0x00000002 Indicates Silicon ID of the device */ + __IM uint32_t RESERVED1[2]; + __IOM uint16_t FAMILY_ID; /*!< 0x0000000C Indicates Family ID of the device */ + __IM uint16_t RESERVED2[761]; __IOM uint8_t DIE_LOT[3]; /*!< 0x00000600 Lot Number (3 bytes) */ __IOM uint8_t DIE_WAFER; /*!< 0x00000603 Wafer Number */ __IOM uint8_t DIE_X; /*!< 0x00000604 X Position on Wafer, CRI Pass/Fail Bin */ @@ -43,14 +46,20 @@ typedef struct { __IOM uint8_t DIE_DAY; /*!< 0x00000608 Day number */ __IOM uint8_t DIE_MONTH; /*!< 0x00000609 Month number */ __IOM uint8_t DIE_YEAR; /*!< 0x0000060A Year number */ - __IM uint8_t RESERVED2[97]; + __IM uint8_t RESERVED3[61]; + __IOM uint16_t SAR_TEMP_MULTIPLIER; /*!< 0x00000648 SAR Temperature Sensor Multiplication Factor */ + __IOM uint16_t SAR_TEMP_OFFSET; /*!< 0x0000064A SAR Temperature Sensor Offset */ + __IM uint32_t RESERVED4[8]; __IOM uint32_t CSP_PANEL_ID; /*!< 0x0000066C CSP Panel Id to record panel ID of CSP die */ - __IM uint32_t RESERVED3[100]; + __IM uint32_t RESERVED5[52]; + __IOM uint8_t LDO_0P9V_TRIM; /*!< 0x00000740 LDO_0P9V_TRIM */ + __IOM uint8_t LDO_1P1V_TRIM; /*!< 0x00000741 LDO_1P1V_TRIM */ + __IM uint16_t RESERVED6[95]; __IOM uint32_t BLE_DEVICE_ADDRESS[128]; /*!< 0x00000800 BLE_DEVICE_ADDRESS */ __IOM uint32_t USER_FREE_ROW1[128]; /*!< 0x00000A00 USER_FREE_ROW1 */ __IOM uint32_t USER_FREE_ROW2[128]; /*!< 0x00000C00 USER_FREE_ROW2 */ __IOM uint32_t USER_FREE_ROW3[128]; /*!< 0x00000E00 USER_FREE_ROW3 */ - __IM uint32_t RESERVED4[302]; + __IM uint32_t RESERVED7[302]; __IOM uint8_t DEVICE_UID[16]; /*!< 0x000014B8 Unique Identifier Number for each device */ __IOM uint8_t MASTER_KEY[16]; /*!< 0x000014C8 Master key to change other keys */ __IOM uint32_t STANDARD_SMPU_STRUCT_SLAVE_ADDR[16]; /*!< 0x000014D8 Standard SMPU STRUCT Slave Address value */ @@ -58,47 +67,55 @@ typedef struct { __IOM uint32_t STANDARD_SMPU_STRUCT_MASTER_ATTR[16]; /*!< 0x00001558 Standard SMPU STRUCT Master Attribute value */ __IOM uint32_t STANDARD_MPU_STRUCT[16]; /*!< 0x00001598 Standard MPU STRUCT */ __IOM uint32_t STANDARD_PPU_STRUCT[16]; /*!< 0x000015D8 Standard PPU STRUCT */ - __IM uint32_t RESERVED5[122]; + __IM uint32_t RESERVED8[122]; __IOM uint16_t PILO_FREQ_STEP; /*!< 0x00001800 Resolution step for PILO at class in BCD format */ - __IM uint16_t RESERVED6; + __IM uint16_t RESERVED9; __IOM uint32_t CSDV2_CSD0_ADC_VREF0; /*!< 0x00001804 CSD 1p2 & 1p6 voltage levels for accuracy */ __IOM uint32_t CSDV2_CSD0_ADC_VREF1; /*!< 0x00001808 CSD 2p3 & 0p8 voltage levels for accuracy */ __IOM uint32_t CSDV2_CSD0_ADC_VREF2; /*!< 0x0000180C CSD calibration spare voltage level for accuracy */ - __IM uint32_t RESERVED7[508]; + __IOM uint32_t PWR_TRIM_WAKE_CTL; /*!< 0x00001810 Wakeup delay */ + __IM uint16_t RESERVED10; + __IOM uint16_t RADIO_LDO_TRIMS; /*!< 0x00001816 Radio LDO Trims */ + __IOM uint32_t CPUSS_TRIM_ROM_CTL_ULP; /*!< 0x00001818 CPUSS TRIM ROM CTL ULP value */ + __IOM uint32_t CPUSS_TRIM_RAM_CTL_ULP; /*!< 0x0000181C CPUSS TRIM RAM CTL ULP value */ + __IOM uint32_t CPUSS_TRIM_ROM_CTL_LP; /*!< 0x00001820 CPUSS TRIM ROM CTL LP value */ + __IOM uint32_t CPUSS_TRIM_RAM_CTL_LP; /*!< 0x00001824 CPUSS TRIM RAM CTL LP value */ + __IM uint32_t RESERVED11[502]; __IOM uint32_t FLASH_BOOT_OBJECT_SIZE; /*!< 0x00002000 Flash Boot - Object Size */ __IOM uint32_t FLASH_BOOT_APP_ID; /*!< 0x00002004 Flash Boot - Application ID/Version */ __IOM uint32_t FLASH_BOOT_ATTRIBUTE; /*!< 0x00002008 N/A */ __IOM uint32_t FLASH_BOOT_N_CORES; /*!< 0x0000200C Flash Boot - Number of Cores(N) */ __IOM uint32_t FLASH_BOOT_VT_OFFSET; /*!< 0x00002010 Flash Boot - Core Vector Table offset */ __IOM uint32_t FLASH_BOOT_CORE_CPUID; /*!< 0x00002014 Flash Boot - Core CPU ID/Core Index */ - __IOM uint32_t FLASH_BOOT_VECTOR_TABLE[48]; /*!< 0x00002018 Flash Boot - Core Vector Table */ - __IOM uint8_t FLASH_BOOT_CODE[8192]; /*!< 0x000020D8 Flash Boot - Code and Data */ - __IOM uint8_t FLASH_BOOT_CMAC[16]; /*!< 0x000040D8 Secure Hash/CMAC - Not applicable */ - __IM uint32_t RESERVED8[1606]; + __IM uint32_t RESERVED12[48]; + __IOM uint8_t FLASH_BOOT_CODE[8488]; /*!< 0x000020D8 Flash Boot - Code and Data */ + __IM uint32_t RESERVED13[1536]; __IOM uint8_t PUBLIC_KEY[3072]; /*!< 0x00005A00 Public key for signature verification (max RSA key size 4096) */ - __IM uint32_t RESERVED9[1152]; + __IOM uint32_t BOOT_PROT_SETTINGS[384]; /*!< 0x00006600 Boot protection settings (not present in PSOC6ABLE2) */ + __IM uint32_t RESERVED14[768]; __IOM uint32_t TOC1_OBJECT_SIZE; /*!< 0x00007800 Object size in bytes for CRC calculation starting from offset 0x00 */ __IOM uint32_t TOC1_MAGIC_NUMBER; /*!< 0x00007804 Magic number(0x01211219) */ - __IOM uint32_t TOC1_FCMAC_OBJECTS; /*!< 0x00007808 Number of objects starting from offset 0xC to be verified for - FACTORY_CMAC */ + __IOM uint32_t TOC1_FHASH_OBJECTS; /*!< 0x00007808 Number of objects starting from offset 0xC to be verified for + FACTORY_HASH */ __IOM uint32_t TOC1_SFLASH_GENERAL_TRIM_ADDR; /*!< 0x0000780C Address of trims stored in SFLASH */ __IOM uint32_t TOC1_UNIQUE_ID_ADDR; /*!< 0x00007810 Address of Unique ID stored in SFLASH */ __IOM uint32_t TOC1_FB_OBJECT_ADDR; /*!< 0x00007814 Addresss of FLASH Boot(FB) object that include FLASH patch also */ __IOM uint32_t TOC1_SYSCALL_TABLE_ADDR; /*!< 0x00007818 Address of SYSCALL_TABLE entry in SFLASH */ - __IM uint32_t RESERVED10[120]; + __IOM uint32_t TOC1_BOOT_PROTECTION_ADDR; /*!< 0x0000781C Address of boot protection object */ + __IM uint32_t RESERVED15[119]; __IOM uint32_t TOC1_CRC_ADDR; /*!< 0x000079FC Upper 2 bytes contain CRC16-CCITT and lower 2 bytes are 0 */ __IOM uint32_t RTOC1_OBJECT_SIZE; /*!< 0x00007A00 Redundant Object size in bytes for CRC calculation starting from offset 0x00 */ __IOM uint32_t RTOC1_MAGIC_NUMBER; /*!< 0x00007A04 Redundant Magic number(0x01211219) */ - __IOM uint32_t RTOC1_FCMAC_OBJECTS; /*!< 0x00007A08 Redundant Number of objects starting from offset 0xC to be - verified for FACTORY_CMAC */ + __IOM uint32_t RTOC1_FHASH_OBJECTS; /*!< 0x00007A08 Redundant Number of objects starting from offset 0xC to be + verified for FACTORY_HASH */ __IOM uint32_t RTOC1_SFLASH_GENERAL_TRIM_ADDR; /*!< 0x00007A0C Redundant Address of trims stored in SFLASH */ __IOM uint32_t RTOC1_UNIQUE_ID_ADDR; /*!< 0x00007A10 Redundant Address of Unique ID stored in SFLASH */ __IOM uint32_t RTOC1_FB_OBJECT_ADDR; /*!< 0x00007A14 Redundant Addresss of FLASH Boot(FB) object that include FLASH patch also */ __IOM uint32_t RTOC1_SYSCALL_TABLE_ADDR; /*!< 0x00007A18 Redundant Address of SYSCALL_TABLE entry in SFLASH */ - __IM uint32_t RESERVED11[120]; + __IM uint32_t RESERVED16[120]; __IOM uint32_t RTOC1_CRC_ADDR; /*!< 0x00007BFC Redundant CRC,Upper 2 bytes contain CRC16-CCITT and lower 2 bytes are 0 */ __IOM uint32_t TOC2_OBJECT_SIZE; /*!< 0x00007C00 Object size in bytes for CRC calculation starting from offset @@ -113,12 +130,13 @@ typedef struct { __IOM uint32_t TOC2_SECOND_USER_APP_ADDR; /*!< 0x00007C18 Address of Second User Application Object */ __IOM uint32_t TOC2_SECOND_USER_APP_FORMAT; /*!< 0x00007C1C Format of Second User Application Object. 0 - Basic, 1 - Cypress standard & 2 - Simplified */ - __IOM uint32_t TOC2_SCMAC_OBJECTS; /*!< 0x00007C20 Number of additional objects(in addition to objects covered by + __IOM uint32_t TOC2_SHASH_OBJECTS; /*!< 0x00007C20 Number of additional objects(in addition to objects covered by FACORY_CAMC) starting from offset 0x24 to be verified for - SECURE_CMAC(SCMAC) */ + SECURE_HASH(SHASH) */ __IOM uint32_t TOC2_SIGNATURE_VERIF_KEY; /*!< 0x00007C24 Address of signature verification key (0 if none).The object is signature specific key. It is the public key in case of RSA */ - __IM uint32_t RESERVED12[117]; + __IM uint32_t RESERVED17[116]; + __IOM uint32_t TOC2_FLAGS; /*!< 0x00007DF8 TOC2_FLAGS */ __IOM uint32_t TOC2_CRC_ADDR; /*!< 0x00007DFC CRC,Upper 2 bytes contain CRC16-CCITT and lower 2 bytes are 0 */ __IOM uint32_t RTOC2_OBJECT_SIZE; /*!< 0x00007E00 Redundant Object size in bytes for CRC calculation starting from offset 0x00 */ @@ -132,21 +150,28 @@ typedef struct { __IOM uint32_t RTOC2_SECOND_USER_APP_ADDR; /*!< 0x00007E18 Redundant Address of Second User Application Object */ __IOM uint32_t RTOC2_SECOND_USER_APP_FORMAT; /*!< 0x00007E1C Redundant Format of Second User Application Object. 0 - Basic, 1 - Cypress standard & 2 - Simplified */ - __IOM uint32_t RTOC2_SCMAC_OBJECTS; /*!< 0x00007E20 Redundant Number of additional objects(in addition to objects + __IOM uint32_t RTOC2_SHASH_OBJECTS; /*!< 0x00007E20 Redundant Number of additional objects(in addition to objects covered by FACORY_CAMC) starting from offset 0x24 to be verified - for SECURE_CMAC(SCMAC) */ + for SECURE_HASH(SHASH) */ __IOM uint32_t RTOC2_SIGNATURE_VERIF_KEY; /*!< 0x00007E24 Redundant Address of signature verification key (0 if none).The object is signature specific key. It is the public key in case of RSA */ - __IM uint32_t RESERVED13[117]; + __IM uint32_t RESERVED18[116]; + __IOM uint32_t RTOC2_FLAGS; /*!< 0x00007FF8 RTOC2_FLAGS */ __IOM uint32_t RTOC2_CRC_ADDR; /*!< 0x00007FFC Redundant CRC,Upper 2 bytes contain CRC16-CCITT and lower 2 bytes are 0 */ } SFLASH_Type; /*!< Size = 32768 (0x8000) */ +/* SFLASH.SI_REVISION_ID */ +#define SFLASH_SI_REVISION_ID_SI_REVISION_ID_Pos 0UL +#define SFLASH_SI_REVISION_ID_SI_REVISION_ID_Msk 0xFFUL /* SFLASH.SILICON_ID */ #define SFLASH_SILICON_ID_ID_Pos 0UL #define SFLASH_SILICON_ID_ID_Msk 0xFFFFUL +/* SFLASH.FAMILY_ID */ +#define SFLASH_FAMILY_ID_FAMILY_ID_Pos 0UL +#define SFLASH_FAMILY_ID_FAMILY_ID_Msk 0xFFFFUL /* SFLASH.DIE_LOT */ #define SFLASH_DIE_LOT_LOT_Pos 0UL #define SFLASH_DIE_LOT_LOT_Msk 0xFFUL @@ -184,9 +209,21 @@ typedef struct { /* SFLASH.DIE_YEAR */ #define SFLASH_DIE_YEAR_MINOR_Pos 0UL #define SFLASH_DIE_YEAR_MINOR_Msk 0xFFUL +/* SFLASH.SAR_TEMP_MULTIPLIER */ +#define SFLASH_SAR_TEMP_MULTIPLIER_TEMP_MULTIPLIER_Pos 0UL +#define SFLASH_SAR_TEMP_MULTIPLIER_TEMP_MULTIPLIER_Msk 0xFFFFUL +/* SFLASH.SAR_TEMP_OFFSET */ +#define SFLASH_SAR_TEMP_OFFSET_TEMP_OFFSET_Pos 0UL +#define SFLASH_SAR_TEMP_OFFSET_TEMP_OFFSET_Msk 0xFFFFUL /* SFLASH.CSP_PANEL_ID */ #define SFLASH_CSP_PANEL_ID_DATA32_Pos 0UL #define SFLASH_CSP_PANEL_ID_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.LDO_0P9V_TRIM */ +#define SFLASH_LDO_0P9V_TRIM_DATA8_Pos 0UL +#define SFLASH_LDO_0P9V_TRIM_DATA8_Msk 0xFFUL +/* SFLASH.LDO_1P1V_TRIM */ +#define SFLASH_LDO_1P1V_TRIM_DATA8_Pos 0UL +#define SFLASH_LDO_1P1V_TRIM_DATA8_Msk 0xFFUL /* SFLASH.BLE_DEVICE_ADDRESS */ #define SFLASH_BLE_DEVICE_ADDRESS_ADDR_Pos 0UL #define SFLASH_BLE_DEVICE_ADDRESS_ADDR_Msk 0xFFFFFFFFUL @@ -200,11 +237,11 @@ typedef struct { #define SFLASH_USER_FREE_ROW3_DATA32_Pos 0UL #define SFLASH_USER_FREE_ROW3_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.DEVICE_UID */ -#define SFLASH_DEVICE_UID_DATA_Pos 0UL -#define SFLASH_DEVICE_UID_DATA_Msk 0xFFUL +#define SFLASH_DEVICE_UID_DATA8_Pos 0UL +#define SFLASH_DEVICE_UID_DATA8_Msk 0xFFUL /* SFLASH.MASTER_KEY */ -#define SFLASH_MASTER_KEY_DATA_Pos 0UL -#define SFLASH_MASTER_KEY_DATA_Msk 0xFFUL +#define SFLASH_MASTER_KEY_DATA8_Pos 0UL +#define SFLASH_MASTER_KEY_DATA8_Msk 0xFFUL /* SFLASH.STANDARD_SMPU_STRUCT_SLAVE_ADDR */ #define SFLASH_STANDARD_SMPU_STRUCT_SLAVE_ADDR_DATA32_Pos 0UL #define SFLASH_STANDARD_SMPU_STRUCT_SLAVE_ADDR_DATA32_Msk 0xFFFFFFFFUL @@ -236,8 +273,30 @@ typedef struct { /* SFLASH.CSDV2_CSD0_ADC_VREF2 */ #define SFLASH_CSDV2_CSD0_ADC_VREF2_VREF_HI_LEVELS_2P6_Pos 0UL #define SFLASH_CSDV2_CSD0_ADC_VREF2_VREF_HI_LEVELS_2P6_Msk 0xFFFFUL -#define SFLASH_CSDV2_CSD0_ADC_VREF2_UNUSED_Pos 16UL -#define SFLASH_CSDV2_CSD0_ADC_VREF2_UNUSED_Msk 0xFFFF0000UL +/* SFLASH.PWR_TRIM_WAKE_CTL */ +#define SFLASH_PWR_TRIM_WAKE_CTL_WAKE_DELAY_Pos 0UL +#define SFLASH_PWR_TRIM_WAKE_CTL_WAKE_DELAY_Msk 0xFFUL +/* SFLASH.RADIO_LDO_TRIMS */ +#define SFLASH_RADIO_LDO_TRIMS_LDO_ACT_Pos 0UL +#define SFLASH_RADIO_LDO_TRIMS_LDO_ACT_Msk 0xFUL +#define SFLASH_RADIO_LDO_TRIMS_LDO_LNA_Pos 4UL +#define SFLASH_RADIO_LDO_TRIMS_LDO_LNA_Msk 0x30UL +#define SFLASH_RADIO_LDO_TRIMS_LDO_IF_Pos 6UL +#define SFLASH_RADIO_LDO_TRIMS_LDO_IF_Msk 0xC0UL +#define SFLASH_RADIO_LDO_TRIMS_LDO_DIG_Pos 8UL +#define SFLASH_RADIO_LDO_TRIMS_LDO_DIG_Msk 0x300UL +/* SFLASH.CPUSS_TRIM_ROM_CTL_ULP */ +#define SFLASH_CPUSS_TRIM_ROM_CTL_ULP_DATA32_Pos 0UL +#define SFLASH_CPUSS_TRIM_ROM_CTL_ULP_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.CPUSS_TRIM_RAM_CTL_ULP */ +#define SFLASH_CPUSS_TRIM_RAM_CTL_ULP_DATA32_Pos 0UL +#define SFLASH_CPUSS_TRIM_RAM_CTL_ULP_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.CPUSS_TRIM_ROM_CTL_LP */ +#define SFLASH_CPUSS_TRIM_ROM_CTL_LP_DATA32_Pos 0UL +#define SFLASH_CPUSS_TRIM_ROM_CTL_LP_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.CPUSS_TRIM_RAM_CTL_LP */ +#define SFLASH_CPUSS_TRIM_RAM_CTL_LP_DATA32_Pos 0UL +#define SFLASH_CPUSS_TRIM_RAM_CTL_LP_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.FLASH_BOOT_OBJECT_SIZE */ #define SFLASH_FLASH_BOOT_OBJECT_SIZE_DATA32_Pos 0UL #define SFLASH_FLASH_BOOT_OBJECT_SIZE_DATA32_Msk 0xFFFFFFFFUL @@ -260,27 +319,24 @@ typedef struct { /* SFLASH.FLASH_BOOT_CORE_CPUID */ #define SFLASH_FLASH_BOOT_CORE_CPUID_DATA32_Pos 0UL #define SFLASH_FLASH_BOOT_CORE_CPUID_DATA32_Msk 0xFFFFFFFFUL -/* SFLASH.FLASH_BOOT_VECTOR_TABLE */ -#define SFLASH_FLASH_BOOT_VECTOR_TABLE_DATA32_Pos 0UL -#define SFLASH_FLASH_BOOT_VECTOR_TABLE_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.FLASH_BOOT_CODE */ -#define SFLASH_FLASH_BOOT_CODE_DATA_Pos 0UL -#define SFLASH_FLASH_BOOT_CODE_DATA_Msk 0xFFUL -/* SFLASH.FLASH_BOOT_CMAC */ -#define SFLASH_FLASH_BOOT_CMAC_DATA_Pos 0UL -#define SFLASH_FLASH_BOOT_CMAC_DATA_Msk 0xFFUL +#define SFLASH_FLASH_BOOT_CODE_DATA32_Pos 0UL +#define SFLASH_FLASH_BOOT_CODE_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.PUBLIC_KEY */ #define SFLASH_PUBLIC_KEY_DATA_Pos 0UL #define SFLASH_PUBLIC_KEY_DATA_Msk 0xFFUL +/* SFLASH.BOOT_PROT_SETTINGS */ +#define SFLASH_BOOT_PROT_SETTINGS_DATA32_Pos 0UL +#define SFLASH_BOOT_PROT_SETTINGS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.TOC1_OBJECT_SIZE */ #define SFLASH_TOC1_OBJECT_SIZE_DATA32_Pos 0UL #define SFLASH_TOC1_OBJECT_SIZE_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.TOC1_MAGIC_NUMBER */ #define SFLASH_TOC1_MAGIC_NUMBER_DATA32_Pos 0UL #define SFLASH_TOC1_MAGIC_NUMBER_DATA32_Msk 0xFFFFFFFFUL -/* SFLASH.TOC1_FCMAC_OBJECTS */ -#define SFLASH_TOC1_FCMAC_OBJECTS_DATA32_Pos 0UL -#define SFLASH_TOC1_FCMAC_OBJECTS_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.TOC1_FHASH_OBJECTS */ +#define SFLASH_TOC1_FHASH_OBJECTS_DATA32_Pos 0UL +#define SFLASH_TOC1_FHASH_OBJECTS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.TOC1_SFLASH_GENERAL_TRIM_ADDR */ #define SFLASH_TOC1_SFLASH_GENERAL_TRIM_ADDR_DATA32_Pos 0UL #define SFLASH_TOC1_SFLASH_GENERAL_TRIM_ADDR_DATA32_Msk 0xFFFFFFFFUL @@ -293,6 +349,9 @@ typedef struct { /* SFLASH.TOC1_SYSCALL_TABLE_ADDR */ #define SFLASH_TOC1_SYSCALL_TABLE_ADDR_DATA32_Pos 0UL #define SFLASH_TOC1_SYSCALL_TABLE_ADDR_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.TOC1_BOOT_PROTECTION_ADDR */ +#define SFLASH_TOC1_BOOT_PROTECTION_ADDR_DATA32_Pos 0UL +#define SFLASH_TOC1_BOOT_PROTECTION_ADDR_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.TOC1_CRC_ADDR */ #define SFLASH_TOC1_CRC_ADDR_DATA32_Pos 0UL #define SFLASH_TOC1_CRC_ADDR_DATA32_Msk 0xFFFFFFFFUL @@ -302,9 +361,9 @@ typedef struct { /* SFLASH.RTOC1_MAGIC_NUMBER */ #define SFLASH_RTOC1_MAGIC_NUMBER_DATA32_Pos 0UL #define SFLASH_RTOC1_MAGIC_NUMBER_DATA32_Msk 0xFFFFFFFFUL -/* SFLASH.RTOC1_FCMAC_OBJECTS */ -#define SFLASH_RTOC1_FCMAC_OBJECTS_DATA32_Pos 0UL -#define SFLASH_RTOC1_FCMAC_OBJECTS_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.RTOC1_FHASH_OBJECTS */ +#define SFLASH_RTOC1_FHASH_OBJECTS_DATA32_Pos 0UL +#define SFLASH_RTOC1_FHASH_OBJECTS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.RTOC1_SFLASH_GENERAL_TRIM_ADDR */ #define SFLASH_RTOC1_SFLASH_GENERAL_TRIM_ADDR_DATA32_Pos 0UL #define SFLASH_RTOC1_SFLASH_GENERAL_TRIM_ADDR_DATA32_Msk 0xFFFFFFFFUL @@ -344,12 +403,15 @@ typedef struct { /* SFLASH.TOC2_SECOND_USER_APP_FORMAT */ #define SFLASH_TOC2_SECOND_USER_APP_FORMAT_DATA32_Pos 0UL #define SFLASH_TOC2_SECOND_USER_APP_FORMAT_DATA32_Msk 0xFFFFFFFFUL -/* SFLASH.TOC2_SCMAC_OBJECTS */ -#define SFLASH_TOC2_SCMAC_OBJECTS_DATA32_Pos 0UL -#define SFLASH_TOC2_SCMAC_OBJECTS_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.TOC2_SHASH_OBJECTS */ +#define SFLASH_TOC2_SHASH_OBJECTS_DATA32_Pos 0UL +#define SFLASH_TOC2_SHASH_OBJECTS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.TOC2_SIGNATURE_VERIF_KEY */ #define SFLASH_TOC2_SIGNATURE_VERIF_KEY_DATA32_Pos 0UL #define SFLASH_TOC2_SIGNATURE_VERIF_KEY_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.TOC2_FLAGS */ +#define SFLASH_TOC2_FLAGS_DATA32_Pos 0UL +#define SFLASH_TOC2_FLAGS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.TOC2_CRC_ADDR */ #define SFLASH_TOC2_CRC_ADDR_DATA32_Pos 0UL #define SFLASH_TOC2_CRC_ADDR_DATA32_Msk 0xFFFFFFFFUL @@ -377,12 +439,15 @@ typedef struct { /* SFLASH.RTOC2_SECOND_USER_APP_FORMAT */ #define SFLASH_RTOC2_SECOND_USER_APP_FORMAT_DATA32_Pos 0UL #define SFLASH_RTOC2_SECOND_USER_APP_FORMAT_DATA32_Msk 0xFFFFFFFFUL -/* SFLASH.RTOC2_SCMAC_OBJECTS */ -#define SFLASH_RTOC2_SCMAC_OBJECTS_DATA32_Pos 0UL -#define SFLASH_RTOC2_SCMAC_OBJECTS_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.RTOC2_SHASH_OBJECTS */ +#define SFLASH_RTOC2_SHASH_OBJECTS_DATA32_Pos 0UL +#define SFLASH_RTOC2_SHASH_OBJECTS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.RTOC2_SIGNATURE_VERIF_KEY */ #define SFLASH_RTOC2_SIGNATURE_VERIF_KEY_DATA32_Pos 0UL #define SFLASH_RTOC2_SIGNATURE_VERIF_KEY_DATA32_Msk 0xFFFFFFFFUL +/* SFLASH.RTOC2_FLAGS */ +#define SFLASH_RTOC2_FLAGS_DATA32_Pos 0UL +#define SFLASH_RTOC2_FLAGS_DATA32_Msk 0xFFFFFFFFUL /* SFLASH.RTOC2_CRC_ADDR */ #define SFLASH_RTOC2_CRC_ADDR_DATA32_Pos 0UL #define SFLASH_RTOC2_CRC_ADDR_DATA32_Msk 0xFFFFFFFFUL diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_smartio.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_smartio.h similarity index 96% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_smartio.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_smartio.h index 74aa344e34..fd76493f62 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_smartio.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_smartio.h @@ -5,12 +5,12 @@ * SMARTIO IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_smif.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_smif.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_smif.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_smif.h index 83cbd24e78..46b6a72cd1 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_smif.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_smif.h @@ -5,12 +5,12 @@ * SMIF IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_srss.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_srss.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_srss.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_srss.h index 8cc3298c24..993f583aab 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_srss.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_srss.h @@ -5,12 +5,12 @@ * SRSS IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -54,8 +54,8 @@ typedef struct { __IOM uint32_t PWR_HIBERNATE; /*!< 0x00000004 HIBERNATE Mode Register */ __IOM uint32_t PWR_LVD_CTL; /*!< 0x00000008 Low Voltage Detector (LVD) Configuration Register */ __IM uint32_t RESERVED[2]; - __IOM uint32_t PWR_BUCK_CTL; /*!< 0x00000014 SIMO Buck Control Register */ - __IOM uint32_t PWR_BUCK_CTL2; /*!< 0x00000018 SIMO Buck Control Register 2 */ + __IOM uint32_t PWR_BUCK_CTL; /*!< 0x00000014 Buck Control Register */ + __IOM uint32_t PWR_BUCK_CTL2; /*!< 0x00000018 Buck Control Register 2 */ __IM uint32_t PWR_LVD_STATUS; /*!< 0x0000001C Low Voltage Detector (LVD) Status Register */ __IM uint32_t RESERVED1[24]; __IOM uint32_t PWR_HIB_DATA[16]; /*!< 0x00000080 HIBERNATE Data Register */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_tcpwm.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_tcpwm.h similarity index 98% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_tcpwm.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_tcpwm.h index 6fe6d7adcc..e00b154285 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_tcpwm.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_tcpwm.h @@ -5,12 +5,12 @@ * TCPWM IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_udb.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_udb.h similarity index 99% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_udb.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_udb.h index 6efafcbcfd..22a9437563 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_udb.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_udb.h @@ -5,12 +5,12 @@ * UDB IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_usbfs.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_usbfs.h similarity index 97% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_usbfs.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_usbfs.h index 7fec7cb4cf..079afe11bd 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/ip/cyip_usbfs.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/ip/cyip_usbfs.h @@ -5,12 +5,12 @@ * USBFS IP definitions * * \note -* Generated 9/21/2017 by CyDeviceHeaderGenerator v1.2.0.101 -* from the register map configuration rev#1007711 +* Generator version: 1.2.0.117 +* Database revision: rev#1034984 * ******************************************************************************** * \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2016-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -86,100 +86,100 @@ typedef struct { __IOM uint32_t SIE_EP8_CNT1; /*!< 0x000001F4 Non-control endpoint count register */ __IOM uint32_t SIE_EP8_CR0; /*!< 0x000001F8 Non-control endpoint's control Register */ __IM uint32_t RESERVED12; - __IOM uint32_t ARB_EP1_CFG; /*!< 0x00000200 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP1_INT_EN; /*!< 0x00000204 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP1_SR; /*!< 0x00000208 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_EP1_CFG; /*!< 0x00000200 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP1_INT_EN; /*!< 0x00000204 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP1_SR; /*!< 0x00000208 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED13; - __IOM uint32_t ARB_RW1_WA; /*!< 0x00000210 Endpoint Write Address value */ - __IOM uint32_t ARB_RW1_WA_MSB; /*!< 0x00000214 Endpoint Write Address value */ - __IOM uint32_t ARB_RW1_RA; /*!< 0x00000218 Endpoint Read Address value */ - __IOM uint32_t ARB_RW1_RA_MSB; /*!< 0x0000021C Endpoint Read Address value */ + __IOM uint32_t ARB_RW1_WA; /*!< 0x00000210 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW1_WA_MSB; /*!< 0x00000214 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW1_RA; /*!< 0x00000218 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW1_RA_MSB; /*!< 0x0000021C Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW1_DR; /*!< 0x00000220 Endpoint Data Register */ __IM uint32_t RESERVED14[3]; - __IOM uint32_t BUF_SIZE; /*!< 0x00000230 Dedicated Endpoint Buffer Size Register */ + __IOM uint32_t BUF_SIZE; /*!< 0x00000230 Dedicated Endpoint Buffer Size Register *1 */ __IM uint32_t RESERVED15; - __IOM uint32_t EP_ACTIVE; /*!< 0x00000238 Endpoint Active Indication Register */ - __IOM uint32_t EP_TYPE; /*!< 0x0000023C Endpoint Type (IN/OUT) Indication */ - __IOM uint32_t ARB_EP2_CFG; /*!< 0x00000240 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP2_INT_EN; /*!< 0x00000244 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP2_SR; /*!< 0x00000248 Endpoint Interrupt Enable Register */ + __IOM uint32_t EP_ACTIVE; /*!< 0x00000238 Endpoint Active Indication Register *1 */ + __IOM uint32_t EP_TYPE; /*!< 0x0000023C Endpoint Type (IN/OUT) Indication *1 */ + __IOM uint32_t ARB_EP2_CFG; /*!< 0x00000240 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP2_INT_EN; /*!< 0x00000244 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP2_SR; /*!< 0x00000248 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED16; - __IOM uint32_t ARB_RW2_WA; /*!< 0x00000250 Endpoint Write Address value */ - __IOM uint32_t ARB_RW2_WA_MSB; /*!< 0x00000254 Endpoint Write Address value */ - __IOM uint32_t ARB_RW2_RA; /*!< 0x00000258 Endpoint Read Address value */ - __IOM uint32_t ARB_RW2_RA_MSB; /*!< 0x0000025C Endpoint Read Address value */ + __IOM uint32_t ARB_RW2_WA; /*!< 0x00000250 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW2_WA_MSB; /*!< 0x00000254 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW2_RA; /*!< 0x00000258 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW2_RA_MSB; /*!< 0x0000025C Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW2_DR; /*!< 0x00000260 Endpoint Data Register */ __IM uint32_t RESERVED17[3]; - __IOM uint32_t ARB_CFG; /*!< 0x00000270 Arbiter Configuration Register */ + __IOM uint32_t ARB_CFG; /*!< 0x00000270 Arbiter Configuration Register *1 */ __IOM uint32_t USB_CLK_EN; /*!< 0x00000274 USB Block Clock Enable Register */ - __IOM uint32_t ARB_INT_EN; /*!< 0x00000278 Arbiter Interrupt Enable */ - __IM uint32_t ARB_INT_SR; /*!< 0x0000027C Arbiter Interrupt Status */ - __IOM uint32_t ARB_EP3_CFG; /*!< 0x00000280 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP3_INT_EN; /*!< 0x00000284 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP3_SR; /*!< 0x00000288 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_INT_EN; /*!< 0x00000278 Arbiter Interrupt Enable *1 */ + __IM uint32_t ARB_INT_SR; /*!< 0x0000027C Arbiter Interrupt Status *1 */ + __IOM uint32_t ARB_EP3_CFG; /*!< 0x00000280 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP3_INT_EN; /*!< 0x00000284 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP3_SR; /*!< 0x00000288 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED18; - __IOM uint32_t ARB_RW3_WA; /*!< 0x00000290 Endpoint Write Address value */ - __IOM uint32_t ARB_RW3_WA_MSB; /*!< 0x00000294 Endpoint Write Address value */ - __IOM uint32_t ARB_RW3_RA; /*!< 0x00000298 Endpoint Read Address value */ - __IOM uint32_t ARB_RW3_RA_MSB; /*!< 0x0000029C Endpoint Read Address value */ + __IOM uint32_t ARB_RW3_WA; /*!< 0x00000290 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW3_WA_MSB; /*!< 0x00000294 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW3_RA; /*!< 0x00000298 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW3_RA_MSB; /*!< 0x0000029C Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW3_DR; /*!< 0x000002A0 Endpoint Data Register */ __IM uint32_t RESERVED19[3]; - __IOM uint32_t CWA; /*!< 0x000002B0 Common Area Write Address */ - __IOM uint32_t CWA_MSB; /*!< 0x000002B4 Endpoint Read Address value */ + __IOM uint32_t CWA; /*!< 0x000002B0 Common Area Write Address *1 */ + __IOM uint32_t CWA_MSB; /*!< 0x000002B4 Endpoint Read Address value *1 */ __IM uint32_t RESERVED20[2]; - __IOM uint32_t ARB_EP4_CFG; /*!< 0x000002C0 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP4_INT_EN; /*!< 0x000002C4 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP4_SR; /*!< 0x000002C8 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_EP4_CFG; /*!< 0x000002C0 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP4_INT_EN; /*!< 0x000002C4 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP4_SR; /*!< 0x000002C8 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED21; - __IOM uint32_t ARB_RW4_WA; /*!< 0x000002D0 Endpoint Write Address value */ - __IOM uint32_t ARB_RW4_WA_MSB; /*!< 0x000002D4 Endpoint Write Address value */ - __IOM uint32_t ARB_RW4_RA; /*!< 0x000002D8 Endpoint Read Address value */ - __IOM uint32_t ARB_RW4_RA_MSB; /*!< 0x000002DC Endpoint Read Address value */ + __IOM uint32_t ARB_RW4_WA; /*!< 0x000002D0 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW4_WA_MSB; /*!< 0x000002D4 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW4_RA; /*!< 0x000002D8 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW4_RA_MSB; /*!< 0x000002DC Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW4_DR; /*!< 0x000002E0 Endpoint Data Register */ __IM uint32_t RESERVED22[3]; __IOM uint32_t DMA_THRES; /*!< 0x000002F0 DMA Burst / Threshold Configuration */ __IOM uint32_t DMA_THRES_MSB; /*!< 0x000002F4 DMA Burst / Threshold Configuration */ __IM uint32_t RESERVED23[2]; - __IOM uint32_t ARB_EP5_CFG; /*!< 0x00000300 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP5_INT_EN; /*!< 0x00000304 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP5_SR; /*!< 0x00000308 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_EP5_CFG; /*!< 0x00000300 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP5_INT_EN; /*!< 0x00000304 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP5_SR; /*!< 0x00000308 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED24; - __IOM uint32_t ARB_RW5_WA; /*!< 0x00000310 Endpoint Write Address value */ - __IOM uint32_t ARB_RW5_WA_MSB; /*!< 0x00000314 Endpoint Write Address value */ - __IOM uint32_t ARB_RW5_RA; /*!< 0x00000318 Endpoint Read Address value */ - __IOM uint32_t ARB_RW5_RA_MSB; /*!< 0x0000031C Endpoint Read Address value */ + __IOM uint32_t ARB_RW5_WA; /*!< 0x00000310 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW5_WA_MSB; /*!< 0x00000314 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW5_RA; /*!< 0x00000318 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW5_RA_MSB; /*!< 0x0000031C Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW5_DR; /*!< 0x00000320 Endpoint Data Register */ __IM uint32_t RESERVED25[3]; __IOM uint32_t BUS_RST_CNT; /*!< 0x00000330 Bus Reset Count Register */ __IM uint32_t RESERVED26[3]; - __IOM uint32_t ARB_EP6_CFG; /*!< 0x00000340 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP6_INT_EN; /*!< 0x00000344 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP6_SR; /*!< 0x00000348 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_EP6_CFG; /*!< 0x00000340 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP6_INT_EN; /*!< 0x00000344 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP6_SR; /*!< 0x00000348 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED27; - __IOM uint32_t ARB_RW6_WA; /*!< 0x00000350 Endpoint Write Address value */ - __IOM uint32_t ARB_RW6_WA_MSB; /*!< 0x00000354 Endpoint Write Address value */ - __IOM uint32_t ARB_RW6_RA; /*!< 0x00000358 Endpoint Read Address value */ - __IOM uint32_t ARB_RW6_RA_MSB; /*!< 0x0000035C Endpoint Read Address value */ + __IOM uint32_t ARB_RW6_WA; /*!< 0x00000350 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW6_WA_MSB; /*!< 0x00000354 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW6_RA; /*!< 0x00000358 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW6_RA_MSB; /*!< 0x0000035C Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW6_DR; /*!< 0x00000360 Endpoint Data Register */ __IM uint32_t RESERVED28[7]; - __IOM uint32_t ARB_EP7_CFG; /*!< 0x00000380 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP7_INT_EN; /*!< 0x00000384 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP7_SR; /*!< 0x00000388 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_EP7_CFG; /*!< 0x00000380 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP7_INT_EN; /*!< 0x00000384 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP7_SR; /*!< 0x00000388 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED29; - __IOM uint32_t ARB_RW7_WA; /*!< 0x00000390 Endpoint Write Address value */ - __IOM uint32_t ARB_RW7_WA_MSB; /*!< 0x00000394 Endpoint Write Address value */ - __IOM uint32_t ARB_RW7_RA; /*!< 0x00000398 Endpoint Read Address value */ - __IOM uint32_t ARB_RW7_RA_MSB; /*!< 0x0000039C Endpoint Read Address value */ + __IOM uint32_t ARB_RW7_WA; /*!< 0x00000390 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW7_WA_MSB; /*!< 0x00000394 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW7_RA; /*!< 0x00000398 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW7_RA_MSB; /*!< 0x0000039C Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW7_DR; /*!< 0x000003A0 Endpoint Data Register */ __IM uint32_t RESERVED30[7]; - __IOM uint32_t ARB_EP8_CFG; /*!< 0x000003C0 Endpoint Configuration Register */ - __IOM uint32_t ARB_EP8_INT_EN; /*!< 0x000003C4 Endpoint Interrupt Enable Register */ - __IOM uint32_t ARB_EP8_SR; /*!< 0x000003C8 Endpoint Interrupt Enable Register */ + __IOM uint32_t ARB_EP8_CFG; /*!< 0x000003C0 Endpoint Configuration Register *1 */ + __IOM uint32_t ARB_EP8_INT_EN; /*!< 0x000003C4 Endpoint Interrupt Enable Register *1 */ + __IOM uint32_t ARB_EP8_SR; /*!< 0x000003C8 Endpoint Interrupt Enable Register *1 */ __IM uint32_t RESERVED31; - __IOM uint32_t ARB_RW8_WA; /*!< 0x000003D0 Endpoint Write Address value */ - __IOM uint32_t ARB_RW8_WA_MSB; /*!< 0x000003D4 Endpoint Write Address value */ - __IOM uint32_t ARB_RW8_RA; /*!< 0x000003D8 Endpoint Read Address value */ - __IOM uint32_t ARB_RW8_RA_MSB; /*!< 0x000003DC Endpoint Read Address value */ + __IOM uint32_t ARB_RW8_WA; /*!< 0x000003D0 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW8_WA_MSB; /*!< 0x000003D4 Endpoint Write Address value *1 */ + __IOM uint32_t ARB_RW8_RA; /*!< 0x000003D8 Endpoint Read Address value *1 */ + __IOM uint32_t ARB_RW8_RA_MSB; /*!< 0x000003DC Endpoint Read Address value *1 */ __IOM uint32_t ARB_RW8_DR; /*!< 0x000003E0 Endpoint Data Register */ __IM uint32_t RESERVED32[7]; __IOM uint32_t MEM_DATA[512]; /*!< 0x00000400 DATA */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/em_eeprom/cy_em_eeprom.c b/targets/TARGET_Cypress/TARGET_PSOC6/device/middleware/em_eeprom/cy_em_eeprom.c similarity index 72% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/em_eeprom/cy_em_eeprom.c rename to targets/TARGET_Cypress/TARGET_PSOC6/device/middleware/em_eeprom/cy_em_eeprom.c index 0b4ab54643..01e4f39a91 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/em_eeprom/cy_em_eeprom.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/middleware/em_eeprom/cy_em_eeprom.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_em_eeprom.c -* \version 1.0 +* \version 1.0.1 * * \brief * This file provides source code of the API for the Emulated EEPROM library. @@ -10,7 +10,7 @@ * ******************************************************************************** * \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -34,14 +34,19 @@ static void FindLastWrittenRow(uint32_t * lastWrRowPtr, cy_stc_eeprom_context_t static uint32_t GetRowAddrBySeqNum(uint32_t seqNum, cy_stc_eeprom_context_t * context); static uint8_t CalcChecksum(uint8_t rowData[], uint32_t len); static void GetNextRowToWrite(uint32_t seqNum, - uint32_t * rowToWrPtr, uint32_t * rowToRdPtr, cy_stc_eeprom_context_t * context); + uint32_t * rowToWrPtr, + uint32_t * rowToRdPtr, + cy_stc_eeprom_context_t * context); static cy_en_em_eeprom_status_t CheckRanges(cy_stc_eeprom_config_t* config); static cy_en_em_eeprom_status_t WriteRow(uint32_t rowAddr, uint32_t *rowData, cy_stc_eeprom_context_t * context); static cy_en_em_eeprom_status_t EraseRow(uint32_t rowAddr, uint32_t ramBuffAddr, cy_stc_eeprom_context_t * context); static cy_en_em_eeprom_status_t CheckCrcAndCopy(uint32_t startAddr, - uint32_t dstAddr, uint32_t rowOffset, uint32_t numBytes, cy_stc_eeprom_context_t * context); + uint32_t dstAddr, + uint32_t rowOffset, + uint32_t numBytes, + cy_stc_eeprom_context_t * context); static uint32_t GetAddresses(uint32_t *startAddr, uint32_t *endAddr, uint32_t *offset, uint32_t rowNum, uint32_t addr, uint32_t len); - +static cy_en_em_eeprom_status_t FillChecksum(cy_stc_eeprom_context_t * context); /** * \addtogroup group_em_eeprom_functions @@ -52,20 +57,37 @@ static uint32_t GetAddresses(uint32_t *startAddr, uint32_t *endAddr, uint32_t *o * Function Name: Cy_Em_EEPROM_Init ****************************************************************************//** * -* Initializes the Emulated EEPROM library. +* Initializes the Emulated EEPROM library by filling the context structure. * * \param config * The pointer to a configuration structure. See \ref cy_stc_eeprom_config_t. * * \param context -* The pointer to the EEPROM context structure \ref cy_stc_eeprom_context_t. +* The pointer to the EEPROM context structure to be filled by the function. +* \ref cy_stc_eeprom_context_t. * * \return * error / status code. See \ref cy_en_em_eeprom_status_t. * +* \note +* The context structure should not be modified by the user after it is filled +* with this function. Modification of context structure may cause the +* unexpected behavior of the Cy_Em_EEPROM API functions which rely on it. +* +* \note +* This function uses a buffer of the flash row size to perform read +* operation. For the size of the row refer to the specific PSoC device +* datasheet. +* +* \sideeffect +* If the "Redundant Copy" option is used, the function performs a number of +* write operations to the EEPROM to initialize flash rows checksums. Therefore, +* Cy_Em_EEPROM_NumWrites(), when it is called right after Cy_Em_EEPROM_Init(), +* will return a non-zero value that identifies the number of writes performed +* by Cy_Em_EEPROM_Init(). +* *******************************************************************************/ -cy_en_em_eeprom_status_t - Cy_Em_EEPROM_Init(cy_stc_eeprom_config_t* config, cy_stc_eeprom_context_t * context) +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Init(cy_stc_eeprom_config_t* config, cy_stc_eeprom_context_t * context) { cy_en_em_eeprom_status_t ret = CY_EM_EEPROM_BAD_PARAM; @@ -83,11 +105,22 @@ cy_en_em_eeprom_status_t context->blockingWrite = config->blockingWrite; context->userFlashStartAddr = config->userFlashStartAddr; /* Store frequently used data for internal use */ - context->numberOfRows = CY_EM_EEPROM_GET_NUM_ROWS_IN_EEPROM(config->eepromSize); + context->numberOfRows = CY_EM_EEPROM_GET_NUM_ROWS_IN_EEPROM(config->eepromSize); context->wlEndAddr = ((CY_EM_EEPROM_GET_EEPROM_SIZE(context->numberOfRows) * config->wearLevelingFactor) + config->userFlashStartAddr); /* Find last written EEPROM row and store it for quick access */ FindLastWrittenRow(&context->lastWrRowAddr, context); + + if((0u == CY_EM_EEPROM_GET_SEQ_NUM(context->lastWrRowAddr)) && (0u != context->redundantCopy)) + { + /* Call the function only after device reprogramming in case + * if redundant copy is enabled. + */ + ret = FillChecksum(context); + + /* Update the last written EEPROM row for Cy_Em_EEPROM_NumWrites() */ + FindLastWrittenRow(&context->lastWrRowAddr, context); + } } } @@ -122,13 +155,16 @@ cy_en_em_eeprom_status_t * operation. For the size of the row refer to the specific PSoC device * datasheet. * -* In case in if redundant copy option is enabled the function may perform writes +* \note +* In case if redundant copy option is enabled the function may perform writes * to EEPROM. This is done in case if the data in the EEPPROM is corrupted and * the data in redundant copy is valid based on CRC-8 data integrity check. * *******************************************************************************/ -cy_en_em_eeprom_status_t - Cy_Em_EEPROM_Read(uint32_t addr, void * eepromData, uint32_t size, cy_stc_eeprom_context_t * context) +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Read(uint32_t addr, + void * eepromData, + uint32_t size, + cy_stc_eeprom_context_t * context) { cy_en_em_eeprom_status_t ret = CY_EM_EEPROM_BAD_PARAM; uint32_t i; @@ -147,173 +183,170 @@ cy_en_em_eeprom_status_t uint32_t rdAddr = addr; uint32_t rdSize = size; /* Get the sequence number of the last written row */ - uint32_t seqNum = CY_GET_REG32(context->lastWrRowAddr); + uint32_t seqNum = CY_EM_EEPROM_GET_SEQ_NUM(context->lastWrRowAddr); + uint32_t updateAddrFlag = 0u; - if(0u != seqNum) + /* Calculate the number of the row read operations. Currently this only concerns + * the reads from the EEPROM data locations. + */ + uint32_t numRowReads = ((((rdAddr + rdSize) - 1u) / CY_EM_EEPROM_EEPROM_DATA_LEN) - + (rdAddr / CY_EM_EEPROM_EEPROM_DATA_LEN)) + 1u; + + /* Get the address of the first row of the currently active EEPROM sector. If + * no wear leveling is used - the EEPROM has only one sector, so use the base + * addr stored in "context->userFlashStartAddr". + */ + curEepromBaseAddr = (((context->lastWrRowAddr - context->userFlashStartAddr) / + (CY_EM_EEPROM_FLASH_SIZEOF_ROW * context->numberOfRows)) * + (CY_EM_EEPROM_FLASH_SIZEOF_ROW * context->numberOfRows)) + + context->userFlashStartAddr; + + /* Find the number of the row that contains the start address of the data */ + for(i = 0u; i < context->numberOfRows; i++) { - uint32_t updateAddrFlag = 0u; - - /* Calculate the number of the row read operations. Currently this only concerns - * the reads from the EEPROM data locations. - */ - uint32_t numRowReads = ((((rdAddr + rdSize) - 1u) / CY_EM_EEPROM_EEPROM_DATA_LEN) - - (rdAddr / CY_EM_EEPROM_EEPROM_DATA_LEN)) + 1u; - - /* Get the address of the first row of the currently active EEPROM sector. If - * no wear leveling is used - the EEPROM has only one sector, so use the base - * addr stored in "context->userFlashStartAddr". - */ - curEepromBaseAddr = (((context->lastWrRowAddr - context->userFlashStartAddr) / - (CY_EM_EEPROM_FLASH_SIZEOF_ROW * context->numberOfRows)) * - (CY_EM_EEPROM_FLASH_SIZEOF_ROW * context->numberOfRows)) + - context->userFlashStartAddr; - - /* Find the number of the row that contains the start address of the data */ - for(i = 0u; i < context->numberOfRows; i++) + if(0u != CY_EM_EEPROM_IS_ADDR_IN_ROW_RANGE(rdAddr, i)) { - if(0u != CY_EM_EEPROM_IS_ADDR_IN_ROW_RANGE(rdAddr, i)) + dataStartEepromRowNum = i; + curRdEepromRowNum = dataStartEepromRowNum; + break; + } + } + + /* Find the row number of the last written row */ + actEepromRowNum = (context->lastWrRowAddr - curEepromBaseAddr) / CY_EM_EEPROM_FLASH_SIZEOF_ROW; + + /* Check if wear leveling is used */ + if(context->wearLevelingFactor > 1u) + { + uint32_t dataEndEepromRowNum = dataStartEepromRowNum + (numRowReads - 1u); + + /* Check if the future validation of the read address is required. */ + updateAddrFlag = (dataStartEepromRowNum > actEepromRowNum) ? 1u : + ((dataEndEepromRowNum > actEepromRowNum) ? 1u : 0u); + } + + /* Copy data from the EEPROM data locations to the user buffer */ + for(i = 0u; i < numRowReads; i++) + { + startRowAddr = curEepromBaseAddr + (curRdEepromRowNum * CY_EM_EEPROM_FLASH_SIZEOF_ROW); + curRowOffset = CY_EM_EEPROM_EEPROM_DATA_LEN + (rdAddr % CY_EM_EEPROM_EEPROM_DATA_LEN); + + /* Check if there are more reads pending and update the number of the + * remaining bytes to read respectively. + */ + if((i + 1u) < numRowReads) + { + numBytesToRead = CY_EM_EEPROM_EEPROM_DATA_LEN - (rdAddr % CY_EM_EEPROM_EEPROM_DATA_LEN); + } + else + { + numBytesToRead = rdSize; + } + + /* Check if the read address needs to be updated to point to the correct + * EEPROM sector. + */ + if((0u != updateAddrFlag) && (curRdEepromRowNum > actEepromRowNum)) + { + startRowAddr -= context->numberOfRows * CY_EM_EEPROM_FLASH_SIZEOF_ROW; + + if(startRowAddr < context->userFlashStartAddr) + { + startRowAddr = context->wlEndAddr - + ((context->numberOfRows - curRdEepromRowNum) * CY_EM_EEPROM_FLASH_SIZEOF_ROW); + } + } + + if(0u != context->redundantCopy) + { + /* Check a checksum of the EEPROM row and if it is bad, check a checksum in + * the corresponding row in redundant copy, otherwise return failure. + */ + ret = CheckCrcAndCopy(startRowAddr, eeData, curRowOffset, numBytesToRead, context); + + if(CY_EM_EEPROM_SUCCESS != ret) { - dataStartEepromRowNum = i; - curRdEepromRowNum = dataStartEepromRowNum; break; } } - - /* Find the row number of the last written row */ - actEepromRowNum = (context->lastWrRowAddr - curEepromBaseAddr) / CY_EM_EEPROM_FLASH_SIZEOF_ROW; - - /* Check if wear leveling is used */ - if(context->wearLevelingFactor > 1u) + else { - uint32_t dataEndEepromRowNum = dataStartEepromRowNum + (numRowReads - 1u); + /* Copy the data to the user buffer */ + (void)memcpy((void *)(eeData), + (void *)(startRowAddr + curRowOffset), + numBytesToRead); - /* Check if the future validation of the read address is required. */ - updateAddrFlag = (dataStartEepromRowNum > actEepromRowNum) ? 1u : - ((dataEndEepromRowNum > actEepromRowNum) ? 1u : 0u); + /* Indicate success to be able to execute next code block */ + ret = CY_EM_EEPROM_SUCCESS; } - /* Copy data from the EEPROM data locations to the user buffer */ - for(i = 0u; i < numRowReads; i++) + /* Update variables anticipated in the read operation */ + rdAddr += numBytesToRead; + rdSize -= numBytesToRead; + eeData += numBytesToRead; + curRdEepromRowNum++; + } + + /* This code block will copy the latest data from the EEPROM headers into the + * user buffer. The data previously copied into the user buffer may be updated + * as the EEPROM headers contain more recent data. + * The code block is executed when two following conditions are true: + * 1) The reads from "historic" data locations were successful; + * 2) The user performed at least one write operation to Em_EEPROM (0u != + * seqNum). + */ + if((CY_EM_EEPROM_SUCCESS == ret) && (0u != seqNum)) + { + numRowReads = (context->numberOfRows <= seqNum) ? (context->numberOfRows) : (seqNum); + numRowReads--; + + for(i = (seqNum - numRowReads); i <= seqNum; i++) { - startRowAddr = curEepromBaseAddr + (curRdEepromRowNum * CY_EM_EEPROM_FLASH_SIZEOF_ROW); - curRowOffset = CY_EM_EEPROM_EEPROM_DATA_LEN + (rdAddr % CY_EM_EEPROM_EEPROM_DATA_LEN); + startRowAddr = GetRowAddrBySeqNum(i, context); - /* Check if there are more reads pending and update the number of the - * remaining bytes to read respectively. - */ - if((i + 1u) < numRowReads) + if (0u != startRowAddr) { - numBytesToRead = CY_EM_EEPROM_EEPROM_DATA_LEN - (rdAddr % CY_EM_EEPROM_EEPROM_DATA_LEN); - } - else - { - numBytesToRead = rdSize; - } + /* The following variables are introduced to increase code readability. */ + uint32_t startAddr = *(uint32_t *)(startRowAddr + CY_EM_EEPROM_HEADER_ADDR_OFFSET); + uint32_t endAddr = startAddr + (*(uint32_t *)(startRowAddr + CY_EM_EEPROM_HEADER_LEN_OFFSET)); - /* Check if the read address needs to be updated to point to the correct - * EEPROM sector. - */ - if((0u != updateAddrFlag) && (curRdEepromRowNum > actEepromRowNum)) - { - startRowAddr -= context->numberOfRows * CY_EM_EEPROM_FLASH_SIZEOF_ROW; - - if(startRowAddr < context->userFlashStartAddr) + /* Check if the current row EEPROM header contains the data requested for read */ + if(0u != CY_EM_EEPROM_IS_ADDRESES_CROSSING(startAddr, endAddr, addr, addr + size)) { - startRowAddr = context->wlEndAddr - - ((context->numberOfRows - curRdEepromRowNum) * CY_EM_EEPROM_FLASH_SIZEOF_ROW); - } - } + uint32_t srcOffset = (startAddr > addr) ? (0u) : (addr - startAddr); + uint32_t dstOffset = (startAddr > addr) ? (startAddr - addr): (0u); + rdAddr = (startAddr > addr) ? (startAddr) : (addr); - if(0u != context->redundantCopy) - { - /* Check a checksum of the EEPROM row and if it is bad, check a checksum in - * the corresponding row in redundant copy, otherwise return failure. - */ - ret = CheckCrcAndCopy(startRowAddr, eeData, curRowOffset, numBytesToRead, context); + srcOffset += CY_EM_EEPROM_HEADER_DATA_OFFSET; - if(CY_EM_EEPROM_SUCCESS != ret) - { - break; - } - } - else - { - /* Copy the data to the user buffer */ - (void)memcpy((void *)(eeData), - (void *)(startRowAddr + curRowOffset), - numBytesToRead); + /* Calculate the number of bytes to be read from the current row's EEPROM header */ + numBytesToRead = ((endAddr < (addr + size)) ? endAddr : (addr + size)) - rdAddr; - /* Indicate success to be able to execute next code block */ - ret = CY_EM_EEPROM_SUCCESS; - } + /* Calculate the offset in the user buffer from which the data will be updated. */ + eeData = ((uint32_t)eepromData) + dstOffset; - /* Update variables anticipated in the read operation */ - rdAddr += numBytesToRead; - rdSize -= numBytesToRead; - eeData += numBytesToRead; - curRdEepromRowNum++; - } - - /* This code block will copy the latest data from the EEPROM headers into the - * user buffer. The data previously copied into the user buffer may be updated - * as the EEPROM headers contain more recent data. - */ - if(CY_EM_EEPROM_SUCCESS == ret) - { - numRowReads = context->numberOfRows - 1u; - - for(i = (seqNum - numRowReads); i <= seqNum; i++) - { - startRowAddr = GetRowAddrBySeqNum(i, context); - - if (0u != startRowAddr) - { - /* The following variables are introduced to increase code readability. */ - uint32_t startAddr = *(uint32_t *)(startRowAddr + CY_EM_EEPROM_HEADER_ADDR_OFFSET); - uint32_t endAddr = startAddr + (*(uint32_t *)(startRowAddr + CY_EM_EEPROM_HEADER_LEN_OFFSET)); - - /* Check if the current row EEPROM header contains the data requested for read */ - if(0u != CY_EM_EEPROM_IS_ADDRESES_CROSSING(startAddr, endAddr, addr, addr + size)) + /* Check a checksum of the EEPROM row and if it is bad, check a checksum in the + * corresponding row in redundant copy, otherwise return failure. Copy the data + * from the recent EEPROM headers to the user buffer. This will overwrite the + * data copied form EEPROM data locations as the data in EEPROM headers is newer. + */ + if(0u != context->redundantCopy) { - rdAddr = (startAddr > addr) ? (startAddr) : (addr); + ret = CheckCrcAndCopy(startRowAddr, eeData, srcOffset, numBytesToRead, context); - /* Calculate the number of bytes to be read from the current row's EEPROM header */ - numBytesToRead = ((endAddr < (addr + size)) ? endAddr : (addr + size)) - rdAddr; - - /* Calculate the offset in the user buffer from which the data will be updated. */ - eeData = ((uint32_t)eepromData) + (rdAddr - addr); - - /* Check a checksum of the EEPROM row and if it is bad, check a checksum in the - * corresponding row in redundant copy, otherwise return failure. Copy the data - * from the recent EEPROM headers to the user buffer. This will overwrite the - * data copied form EEPROM data locations as the data in EEPROM headers is newer. - */ - if(0u != context->redundantCopy) + if(CY_EM_EEPROM_SUCCESS != ret) { - ret = CheckCrcAndCopy(startRowAddr, eeData, - CY_EM_EEPROM_HEADER_DATA_OFFSET, numBytesToRead, context); - - if(CY_EM_EEPROM_SUCCESS != ret) - { - break; - } - } - else - { - (void)memcpy((void *)(eeData), - (void *)(startRowAddr + CY_EM_EEPROM_HEADER_DATA_OFFSET), - numBytesToRead); + break; } } + else + { + (void)memcpy((void *)(eeData), (void *)(startRowAddr + srcOffset), numBytesToRead); + } } } } } - else - { - /* No records in the EEPROM */ - ret = CY_EM_EEPROM_BAD_DATA; - } } return(ret); @@ -362,6 +395,7 @@ cy_en_em_eeprom_status_t * user code on CM4 is not blocked and the user code on CM0P is blocked until * erase flash row operation is finished. Plan your task allocation accordingly. * +* \sideeffect * In case if non-blocking write option is used and when user flash is used as * an EEPROM storage care should be taken to prevent the read while write (RWW) * exception. To prevent the RWW exception the user flash macro that includes @@ -369,8 +403,10 @@ cy_en_em_eeprom_status_t * The read also means the user code execution from the respective flash macro. * *******************************************************************************/ -cy_en_em_eeprom_status_t - Cy_Em_EEPROM_Write(uint32_t addr, void * eepromData, uint32_t size, cy_stc_eeprom_context_t * context) +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Write(uint32_t addr, + void * eepromData, + uint32_t size, + cy_stc_eeprom_context_t * context) { cy_en_em_eeprom_status_t ret = CY_EM_EEPROM_BAD_PARAM; uint32_t i; @@ -395,7 +431,7 @@ cy_en_em_eeprom_status_t { uint32_t skipOperation = 0u; /* Get the sequence number of the last written row */ - uint32_t seqNum = CY_GET_REG32(emEepromRowAddr); + uint32_t seqNum = CY_EM_EEPROM_GET_SEQ_NUM(emEepromRowAddr); /* Get the address of the row to be written. The "emEepromRowAddr" may be * updated with the proper address (if wear leveling is used). The @@ -409,8 +445,8 @@ cy_en_em_eeprom_status_t /* Fill the EM_EEPROM header info for the row in the RAM buffer */ seqNum++; - writeRamBuffer[0u] = seqNum; - writeRamBuffer[1u] = addr; + writeRamBuffer[CY_EM_EEPROM_HEADER_SEQ_NUM_OFFSET_U32] = seqNum; + writeRamBuffer[CY_EM_EEPROM_HEADER_ADDR_OFFSET_U32] = addr; tmpData = (void *) eeData; /* Check if this is the last row to write */ @@ -565,6 +601,7 @@ cy_en_em_eeprom_status_t * So it is recommended to use this function in utmost case to prolongate * flash life. * +* \note * This function uses a buffer of the flash row size to perform erase * operation. For the size of the row refer to the specific PSoC device * datasheet. @@ -576,6 +613,7 @@ cy_en_em_eeprom_status_t * user code on CM4 is not blocked and the user code on CM0P is blocked until * erase flash row operation is finished. Plan your task allocation accordingly. * +* \sideeffect * In case if non-blocking write option is used and when user flash is used as * an EEPROM storage care should be taken to prevent the read while write (RWW) * exception. To prevent the RWW exception the user flash macro that includes @@ -595,7 +633,7 @@ cy_en_em_eeprom_status_t Cy_Em_EEPROM_Erase(cy_stc_eeprom_context_t * context) uint32_t storedSeqNum; /* Get the sequence number of the last written row */ - seqNum = CY_GET_REG32(emEepromRowAddr); + seqNum = CY_EM_EEPROM_GET_SEQ_NUM(emEepromRowAddr); /* If there were no writes to EEPROM - nothing to erase */ if(0u != seqNum) @@ -671,7 +709,7 @@ cy_en_em_eeprom_status_t Cy_Em_EEPROM_Erase(cy_stc_eeprom_context_t * context) *******************************************************************************/ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context) { - return(CY_GET_REG32(context->lastWrRowAddr)); + return(CY_EM_EEPROM_GET_SEQ_NUM(context->lastWrRowAddr)); } /** \} */ @@ -684,7 +722,7 @@ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context) ****************************************************************************//** * * Performs a search of the last written row address of the EEPROM associated -* with the context structure. If there were no writes to the EEPROm the +* with the context structure. If there were no writes to the EEPROM the * function returns the start address of the EEPROM. The row address is returned * in the input parameter. * @@ -706,7 +744,7 @@ static void FindLastWrittenRow(uint32_t * lastWrRowPtr, cy_stc_eeprom_context_t for(numRows = 0u; numRows < (context->numberOfRows * context->wearLevelingFactor); numRows++) { - seqNum = CY_GET_REG32(emEepromAddr); + seqNum = CY_EM_EEPROM_GET_SEQ_NUM(emEepromAddr); if((0u != seqNum) && (seqNum > prevSeqNum)) { /* Some record in EEPROM was found. Store found sequence @@ -743,7 +781,7 @@ static uint32_t GetRowAddrBySeqNum(uint32_t seqNum, cy_stc_eeprom_context_t * co { uint32_t emEepromAddr = context->userFlashStartAddr; - while(CY_GET_REG32(emEepromAddr) != seqNum) + while(CY_EM_EEPROM_GET_SEQ_NUM(emEepromAddr) != seqNum) { /* Switch to the next row */ emEepromAddr = emEepromAddr + CY_EM_EEPROM_FLASH_SIZEOF_ROW; @@ -785,7 +823,9 @@ static uint32_t GetRowAddrBySeqNum(uint32_t seqNum, cy_stc_eeprom_context_t * co * *******************************************************************************/ static void GetNextRowToWrite(uint32_t seqNum, - uint32_t * rowToWrPtr, uint32_t * rowToRdPtr, cy_stc_eeprom_context_t * context) + uint32_t * rowToWrPtr, + uint32_t * rowToRdPtr, + cy_stc_eeprom_context_t * context) { /* Switch to the next row to be written if the current sequence number is * not zero. @@ -926,8 +966,9 @@ static cy_en_em_eeprom_status_t CheckRanges(cy_stc_eeprom_config_t* config) * error / status code. See \ref cy_en_em_eeprom_status_t. * *******************************************************************************/ -static cy_en_em_eeprom_status_t WriteRow(uint32_t rowAddr, uint32_t *rowData, - cy_stc_eeprom_context_t * context) +static cy_en_em_eeprom_status_t WriteRow(uint32_t rowAddr, + uint32_t *rowData, + cy_stc_eeprom_context_t * context) { cy_en_em_eeprom_status_t ret = CY_EM_EEPROM_WRITE_FAIL; if(0u != context->blockingWrite) @@ -987,14 +1028,15 @@ static cy_en_em_eeprom_status_t WriteRow(uint32_t rowAddr, uint32_t *rowData, * error / status code. See \ref cy_en_em_eeprom_status_t. * *******************************************************************************/ -static cy_en_em_eeprom_status_t EraseRow(uint32_t rowAddr, uint32_t ramBuffAddr, - cy_stc_eeprom_context_t * context) +static cy_en_em_eeprom_status_t EraseRow(uint32_t rowAddr, + uint32_t ramBuffAddr, + cy_stc_eeprom_context_t * context) { uint32_t emEepromRowAddr = rowAddr; cy_en_em_eeprom_status_t ret = CY_EM_EEPROM_WRITE_FAIL; uint32_t i = 1u; - ramBuffAddr = ramBuffAddr; /* To avoid compiler warning */ + (void)ramBuffAddr; /* To avoid compiler warning */ if(0u != context->redundantCopy) { @@ -1086,7 +1128,10 @@ static cy_en_em_eeprom_status_t EraseRow(uint32_t rowAddr, uint32_t ramBuffAddr, * *******************************************************************************/ static cy_en_em_eeprom_status_t CheckCrcAndCopy(uint32_t startAddr, - uint32_t dstAddr, uint32_t rowOffset, uint32_t numBytes, cy_stc_eeprom_context_t * context) + uint32_t dstAddr, + uint32_t rowOffset, + uint32_t numBytes, + cy_stc_eeprom_context_t * context) { cy_en_em_eeprom_status_t ret; uint32_t writeRamBuffer[CY_EM_EEPROM_FLASH_SIZEOF_ROW / CY_EM_EEPROM_U32_DIV]; @@ -1166,8 +1211,12 @@ static cy_en_em_eeprom_status_t CheckCrcAndCopy(uint32_t startAddr, * no data to be written * *******************************************************************************/ -static uint32_t GetAddresses(uint32_t *startAddr, uint32_t *endAddr, uint32_t *offset, uint32_t rowNum, - uint32_t addr, uint32_t len) +static uint32_t GetAddresses(uint32_t *startAddr, + uint32_t *endAddr, + uint32_t *offset, + uint32_t rowNum, + uint32_t addr, + uint32_t len) { uint32_t skip = 0u; @@ -1205,6 +1254,80 @@ static uint32_t GetAddresses(uint32_t *startAddr, uint32_t *endAddr, uint32_t *o } +/******************************************************************************* +* Function Name: FillChecksum +****************************************************************************//** +* +* Performs calculation of the checksum on each row in the Em_EEPROM and fills +* the Em_EEPROM headers checksum field with the calculated checksums. +* +* \param context +* The pointer to the EEPROM context structure. +* +* \return +* error / status code. See \ref cy_en_em_eeprom_status_t. +* +* \theory +* In case if redundant copy option is used the Em_EEPROM would return bad +* checksum while trying to read the EEPROM rows which were not yet written by +* the user. E.g. any read after device reprogramming without previous Write() +* operation to the EEPROM would fail. This would happen because the Em_EEPROM +* headers checksum field values (which is zero at the moment) would not be +* equal to the actual data checksum. This function allows to avoid read failure +* after device reprogramming. +* +* \note +* This function uses a buffer of the flash row size to perform read +* operation. For the size of the row refer to the specific PSoC device +* datasheet. +* +*******************************************************************************/ +static cy_en_em_eeprom_status_t FillChecksum(cy_stc_eeprom_context_t * context) +{ + uint32_t i; + uint32_t rdAddr; + uint32_t writeRamBuffer[CY_EM_EEPROM_FLASH_SIZEOF_ROW / CY_EM_EEPROM_U32_DIV]; + uint32_t wrAddr = context->lastWrRowAddr; + uint32_t tmpRowAddr; + /* Get the sequence number (number of writes) */ + uint32_t seqNum = CY_EM_EEPROM_GET_SEQ_NUM(wrAddr); + cy_en_em_eeprom_status_t ret = CY_EM_EEPROM_BAD_PARAM; + + for(i = 0u; i < (context->numberOfRows * context->wearLevelingFactor); i++) + { + /* Copy the EEPROM row from Flash to RAM */ + (void)memcpy((void *)&writeRamBuffer[0u], (void *)(wrAddr), CY_EM_EEPROM_FLASH_SIZEOF_ROW); + + /* Increment the sequence number */ + seqNum++; + writeRamBuffer[CY_EM_EEPROM_HEADER_SEQ_NUM_OFFSET_U32] = seqNum; + + /* Calculate and fill the checksum to the Em_EEPROM header */ + writeRamBuffer[CY_EM_EEPROM_HEADER_CHECKSUM_OFFSET_U32] = (uint32_t) + CalcChecksum((uint8_t *) &writeRamBuffer[CY_EM_EEPROM_EEPROM_DATA_OFFSET_U32], + CY_EM_EEPROM_EEPROM_DATA_LEN); + + /* Write the data to the specified flash row */ + ret = WriteRow(wrAddr, writeRamBuffer, context); + + /* Update the row address to point to the relevant row in the redundant + * EEPROM's copy. + */ + tmpRowAddr = (wrAddr - context->userFlashStartAddr) + context->wlEndAddr; + + /* Write the data to the specified flash row */ + ret = WriteRow(tmpRowAddr, writeRamBuffer, context); + + /* Get the address of the next row to be written. + * "rdAddr" is not used in this function but provided to prevent NULL + * pointer exception in GetNextRowToWrite(). + */ + GetNextRowToWrite(seqNum, &wrAddr, &rdAddr, context); + } + + return(ret); +} + /** \endcond */ #if defined(__cplusplus) diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/em_eeprom/cy_em_eeprom.h b/targets/TARGET_Cypress/TARGET_PSOC6/device/middleware/em_eeprom/cy_em_eeprom.h similarity index 61% rename from targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/em_eeprom/cy_em_eeprom.h rename to targets/TARGET_Cypress/TARGET_PSOC6/device/middleware/em_eeprom/cy_em_eeprom.h index 349095df67..e88cca2e11 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/em_eeprom/cy_em_eeprom.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/device/middleware/em_eeprom/cy_em_eeprom.h @@ -1,13 +1,13 @@ /******************************************************************************* * \file cy_em_eeprom.h -* \version 1.0 +* \version 1.0.1 * * \brief * This file provides the function prototypes and constants for the Emulated * EEPROM middleware library. * ******************************************************************************** -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. +* Copyright 2017-2018, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. @@ -16,10 +16,10 @@ /** * \mainpage Cypress Em_EEPROM Middleware Library * - * The Emulated EEPROM provides an API that allows creating of an emulated + * The Emulated EEPROM provides an API that allows creating an emulated * EEPROM in flash that has the ability to do wear leveling and restore * corrupted data from a redundant copy. The Emulated EEPROM library is designed - * to be used with Em_EEPROM component. + * to be used with the Em_EEPROM component. * * The Cy_Em_EEPROM API is described in the following sections: * - \ref group_em_eeprom_macros @@ -29,45 +29,109 @@ * * Features: * * EEPROM-Like Non-Volatile Storage - * * Easy to use read and write API + * * Easy to use Read and Write API * * Optional Wear Leveling * * Optional Redundant Data storage * * \section group_em_eeprom_configuration Configuration Considerations * - * To initialize an Emulated EEPROM on a device different than PSoC 6, just - * pass the start address of the EEPROM storage to Em_EEPRPOM component start - * function. E.g. + * The Em_EEPROM operates on the top of the flash driver. The flash driver has + * some prerequisites for proper operation. Refer to the "Flash System + * Routine (Flash)" section of the PDL API Reference Manual. * - * (void) Em_EEPROM_Init((uint32_t) &emEeprom[0]); + * Initializing Emulated EEPROM in User flash * - * The "emEeprom[]" is an array which should be defined in main.c and it should - * be aligned to the size of the device's flash row. An example of a - * declaration of such array for MDK and GCC compilers is following: + * To initialize an Emulated EEPROM in the User flash, the EEPROM storage should + * be declared by the user. For the proper operation, the EEPROM storage should + * be aligned to the size of the flash row. An example of the EEPROM storage + * declaration is below (applicable for GCC and MDK compilers): * - * const uint8_t emEeprom[Em_EEPROM_PHYSICAL_SIZE] __ALIGNED(Em_EEPROM_FLASH_SIZEOF_ROW) = {0u}; - * - * A similar declaration for the IAR compiler: - * - * #pragma data_alignment = Em_EEPROM_FLASH_SIZEOF_ROW + * CY_ALIGN(CY_EM_EEPROM_FLASH_SIZEOF_ROW) * const uint8_t emEeprom[Em_EEPROM_PHYSICAL_SIZE] = {0u}; * - * Note that the user can specify his own name the array. + * The same declaration for the IAR compiler: * - * Also note that the Em_EEPROM_PHYSICAL_SIZE is larger than the EEPROM size - * user entered in the Em_EEPROM component GUI. The Em_EEPROM_PHYSICAL_SIZE - * also includes the overhead to implement the emulated EEPROM, wear leveling - * overhead and redundant copy overhead. + * #pragma data_alignment = CY_EM_EEPROM_FLASH_SIZEOF_ROW + * const uint8_t emEeprom[Em_EEPROM_PHYSICAL_SIZE] = {0u}; + * + * Note that the name "emEeprom" is shown for reference. Any other name can be + * used instead. Also, note that the Em_EEPROM_PHYSICAL_SIZE constant is + * generated by the PSoC Creator Em_EEPROM component and so it is instance name + * dependent and its prefix should be changed when the name of the component + * changes. If the The Cy_Em_EEPROM middleware library is used without the + * Em_EEPROM component, the user has to provide a proper size for the EEPROM + * storage instead of Em_EEPROM_PHYSICAL_SIZE. The size of the EEPROM storage + * can be calculated using the following equation: + * + * Physical size = EEPROM data size * 2 * wear leveling * (1 + redundant copy) * - * For PSoC 6 devices the user may not define the array as shown above if one - * wishes to anticipate less that 32K of Flash. For that purpose just pass - * zero to the Em_EEPRPOM component start function. The Cy_Em_EEPROM library - * will automatically reserve the required amount of flash in the region - * known as work flash. In case if the user needs more than 32 KBytes to - * implement Emulated EEPROM (Em_EEPROM_PHYSICAL_SIZE > 32K), the user should - * define an array to reserve the required amount of flash as was described - * above. + * where, + * "EEPROM data size" - the size of data the user wants to store in the + * EEPROM. The data size must divide evenly to the half of the flash row size. + * "wear leveling" - the wear leveling factor (1-10). + * "redundant copy" - "zero" if a redundant copy is not used, and "one" + * otherwise. * + * The start address of the storage should be filled to the Emulated EEPROM + * configuration structure and then passed to the Cy_Em_EEPROM_Init(). + * If the Em_EEPROM component is used, the config (Em_EEPROM_config) and + * context structures (Em_EEPROM_context) are defined by the component, so the + * user may just use that structures otherwise both of the structures need to + * be provided by the user. Note that if the "Config Data in Flash" + * option is selected in the component, then the configuration structure should + * be copied to RAM to allow EEPROM storage start address update. The following + * code demonstrates utilization of "Em_EEPROM_config" and "Em_EEPROM_context" + * Em_EEPROM component structures for Cy_Em_EEPROM middleware library + * initialization: + * + * cy_en_em_eeprom_status_t retValue; + * cy_stc_eeprom_config_t config; + * + * memcpy((void *)&config, + (void *)&Em_EEPROM_config, + sizeof(cy_stc_eeprom_config_t)); + * config.userFlashStartAddr = (uint32_t)emEeprom; + * retValue = Cy_Em_EEPROM_Init(&config, &Em_EEPROM_context); + * + * Initializing EEPROM in Emulated EEPROM flash area + * + * Initializing of the EEPROM storage in the Emulated EEPROM flash area is + * identical to initializing of the EEPROM storage in the User flash with one + * difference. The location of the Emulated EEPROM storage should be specified + * somewhere in the EmulatedEEPROM flash area. If the Em_EEPROM component is + * utilized in the project, then the respective storage + * (Em_EEPROM_em_EepromStorage[]) is automatically declared by the component + * if the "Use Emulated EEPROM" option is set to "Yes". The user just needs to + * fill the start address of the storage to the config structure. If the + * Em_EEPROM component is not used, the user needs to declare the storage + * in the Emulated EEPROM flash area. An example of such declaration is + * following (applicable for GCC and MDK compilers): + * + * CY_SECTION(".cy_em_eeprom") CY_ALIGN(CY_EM_EEPROM_FLASH_SIZEOF_ROW) + * const uint8_t emEeprom[Em_EEPROM_PHYSICAL_SIZE] = {0u}; + * + * The same declaration for the IAR compiler: + * + * #pragma location = ".cy_em_eeprom" + * #pragma data_alignment = CY_EM_EEPROM_FLASH_SIZEOF_ROW + * const uint8_t emEeprom[Em_EEPROM_PHYSICAL_SIZE] = {0u}; + * + * where, + * Em_EEPROM_PHYSICAL_SIZE - is a constant that is generated by the Em_EEPROM + * component when the component is utilized in the project or it should be + * provided by the user. The equation for the calculation of the constant is + * shown above. + * + * Note that the size of the Emulated EEPROM flash area is limited. Refer to the + * specific device datasheet for the value of the available EEPROM Emulation + * area. + * + * Also note that by default, the Em_EEPROM storage is fully allocated to both + * of the PSoC 6 cores in the ".cy_em_eeprom" section. If the Em_EEPROM is + * used on one of the cores, you must reallocate the declaration of the + * ".cy_em_eeprom" section in both linker scripts. Otherwise, while building the + * project the cymcuelftool will report an error because of ".cy_em_eeprom" + * section contents collision. * * \section group_em_eeprom_more_information More Information * See the Em_EEPROM Component datasheet. @@ -87,10 +151,19 @@ * * * - * - * + * + * + * + * + * + * + * + * * * * @@ -104,7 +177,8 @@ * * * - * + * * @@ -120,6 +194,12 @@ * \section group_em_eeprom_changelog Changelog *
VersionChangesReason for Change
1.0.1General documentation updatesAdded info about periodic interrupt generation use case
1.0Initial version
11.4AThe cast should not be performed between a pointer to the object type and - * a different pointer to the object type.The cast from the object type and a different pointer to the object was used - * intentionally because of the performance reasons.The cast should not be performed between a pointer to the object type + * and a different pointer to the object type.The cast from the object type and a different pointer to the object + * was used intentionally because of the performance reasons.
14.2RAll non-null statements shall either have at least one side-effect, + * however executed, or cause control flow to change.To maintain common codebase, some variables, unused for a specific + * device, are casted to void to prevent generation of an unused variable + * compiler warning.
16.7
17.4RThe array indexing shall be the only allowed form of pointer arithmetic.The array indexing shall be the only allowed form of pointer + * arithmetic.The pointer arithmetic used in several places on the Cy_Em_EEPROM * implementation is safe and preferred because it increases the code * flexibility.
* + * + * + * + * + * * * * @@ -127,30 +207,29 @@ * *
VersionChangesReason for Change
1.0.1EM_EEPROM storage allocation note added to + * \ref group_em_eeprom_configurationDocumentation update and clarification
1.0Initial Version
* - * \defgroup group_em_eeprom_macros Emulated EEPROM Macros + * \defgroup group_em_eeprom_macros Macros * \brief - * This section describes Emulated EEPROM Macros. + * This section describes the Emulated EEPROM Macros. * - * \defgroup group_em_eeprom_data_structures Emulated EEPROM Data Structures + * \defgroup group_em_eeprom_functions Functions * \brief - * Describes data structures defined by Emulated EEPROM. + * This section describes the Emulated EEPROM Function Prototypes. * - * \defgroup group_em_eeprom_enums Emulated EEPROM Return values + * \defgroup group_em_eeprom_data_structures Data Structures * \brief - * Describes enumeration types defined by Emulated EEPROM. + * Describes the data structures defined by the Emulated EEPROM. * - * \defgroup group_em_eeprom_functions Emulated EEPROM Function Prototypes + * \defgroup group_em_eeprom_enums Enumerated types * \brief - * This section describes Emulated EEPROM Function Prototypes. + * Describes the enumeration types defined by the Emulated EEPROM. * */ -#if !defined(CY_EM_EEPROM_EM_EEPROM_H) -#define CY_EM_EEPROM_EM_EEPROM_H +#if !defined(CY_EM_EEPROM_H) +#define CY_EM_EEPROM_H #include -#include #include #include "syslib/cy_syslib.h" #include "flash/cy_flash.h" @@ -164,7 +243,6 @@ extern "C" { /*************************************** * Conditional Compilation Parameters ***************************************/ -#define CY_PSOC6 (CYDEV_CHIP_FAMILY_USED == CYDEV_CHIP_FAMILY_PSOC6) /*************************************** @@ -194,7 +272,9 @@ typedef struct */ uint8_t blockingWrite; - /** The start address for the EEPROM memory in the user's flash. */ + /** The start address of the EEPROM memory in the user's flash or in the + * Emulated EEPROM flash area. + */ uint32_t userFlashStartAddr; } cy_stc_eeprom_config_t; @@ -275,14 +355,16 @@ typedef enum * \addtogroup group_em_eeprom_functions * \{ */ -cy_en_em_eeprom_status_t Cy_Em_EEPROM_Init( - cy_stc_eeprom_config_t* config, cy_stc_eeprom_context_t * context); -cy_en_em_eeprom_status_t Cy_Em_EEPROM_Read( - uint32_t addr, void * eepromData, uint32_t size, cy_stc_eeprom_context_t * context); -cy_en_em_eeprom_status_t Cy_Em_EEPROM_Write( - uint32_t addr, void * eepromData, uint32_t size, cy_stc_eeprom_context_t * context); -cy_en_em_eeprom_status_t Cy_Em_EEPROM_Erase( - cy_stc_eeprom_context_t * context); +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Init(cy_stc_eeprom_config_t* config, cy_stc_eeprom_context_t * context); +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Read(uint32_t addr, + void * eepromData, + uint32_t size, + cy_stc_eeprom_context_t * context); +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Write(uint32_t addr, + void * eepromData, + uint32_t size, + cy_stc_eeprom_context_t * context); +cy_en_em_eeprom_status_t Cy_Em_EEPROM_Erase(cy_stc_eeprom_context_t * context); uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context); /** \} group_em_eeprom_functions */ @@ -295,13 +377,13 @@ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context); * \{ */ /** Library major version */ -#define CY_EM_EEPROM_VERSION_MAJOR (1) +#define CY_EM_EEPROM_VERSION_MAJOR (1) /** Library minor version */ -#define CY_EM_EEPROM_VERSION_MINOR (0) +#define CY_EM_EEPROM_VERSION_MINOR (0) /** Defines the maximum data length that can be stored in one flash row */ -#define CY_EM_EEPROM_EEPROM_DATA_LEN (CY_EM_EEPROM_FLASH_SIZEOF_ROW / 2u) +#define CY_EM_EEPROM_EEPROM_DATA_LEN (CY_EM_EEPROM_FLASH_SIZEOF_ROW / 2u) /** \} group_em_eeprom_macros */ @@ -317,13 +399,14 @@ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context); /* Device specific flash constants */ #define CY_EM_EEPROM_FLASH_BASE_ADDR (CY_FLASH_BASE) #define CY_EM_EEPROM_FLASH_SIZE (CY_FLASH_SIZE) -#define CY_EM_EEPROM_WFLASH_BASE_ADDR (CY_WFLASH_BASE) -#define CY_EM_EEPROM_WFLASH_SIZE (CY_WFLASH_SIZE) -#define CY_EM_EEPROM_WFLASH_END_ADDR (CY_WFLASH_BASE + CY_WFLASH_SIZE) +#define CY_EM_EEPROM_EM_EEPROM_BASE_ADDR (CY_EM_EEPROM_BASE) +#define CY_EM_EEPROM_EM_EEPROM_SIZE (CY_EM_EEPROM_SIZE) +#define CY_EM_EEPROM_EM_EEPROM_END_ADDR (CY_EM_EEPROM_EM_EEPROM_BASE_ADDR + CY_EM_EEPROM_EM_EEPROM_SIZE) /* Checks is the EEPROM is in flash range */ #define CY_EM_EEPROM_IS_IN_FLASH_RANGE(startAddr, endAddr) \ (((((startAddr) > CY_EM_EEPROM_FLASH_BASE_ADDR) && ((endAddr) <= CY_EM_EEPROM_FLASH_END_ADDR)) || \ - (((startAddr) >= CY_EM_EEPROM_WFLASH_BASE_ADDR) && ((endAddr) <= CY_EM_EEPROM_WFLASH_END_ADDR)))) + (((startAddr) >= CY_EM_EEPROM_EM_EEPROM_BASE_ADDR) && \ + ((endAddr) <= CY_EM_EEPROM_EM_EEPROM_END_ADDR)))) #define CY_EM_EEPROM_FLASH_END_ADDR (CY_EM_EEPROM_FLASH_BASE_ADDR + CY_EM_EEPROM_FLASH_SIZE) @@ -385,6 +468,8 @@ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context); ((CY_EM_EEPROM_CRC8_XOR_VAL == ((crc) & CY_EM_EEPROM_CRC8_XOR_VAL)) ? \ ((uint8_t)(((uint8_t)((uint8_t)((crc) << 1u))) ^ CY_EM_EEPROM_CRC8_POLYNOM)) : ((uint8_t)((crc) << 1u))) +#define CY_EM_EEPROM_GET_SEQ_NUM(addr) (*(uint32_t*)(addr)) + /** \endcond */ /** @@ -417,6 +502,7 @@ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context); /* Offsets for 32-bit RAM buffer addressing */ #define CY_EM_EEPROM_EEPROM_DATA_OFFSET_U32 ((CY_EM_EEPROM_FLASH_SIZEOF_ROW / 2u) / 4u) +#define CY_EM_EEPROM_HEADER_SEQ_NUM_OFFSET_U32 (0u) #define CY_EM_EEPROM_HEADER_ADDR_OFFSET_U32 (1u) #define CY_EM_EEPROM_HEADER_LEN_OFFSET_U32 (2u) #define CY_EM_EEPROM_HEADER_DATA_OFFSET_U32 (3u) @@ -443,7 +529,7 @@ uint32_t Cy_Em_EEPROM_NumWrites(cy_stc_eeprom_context_t * context); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* CY_EM_EEPROM_EM_EEPROM_H */ +#endif /* CY_EM_EEPROM_H */ /* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c new file mode 100644 index 0000000000..4215ac72dd --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c @@ -0,0 +1,85 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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. + */ + +#include "device.h" +#include "flash_api.h" +#include "drivers/peripheral/flash/cy_flash.h" + +#if DEVICE_FLASH + +int32_t flash_init(flash_t *obj) +{ + (void)(obj); + return 0; +} + +int32_t flash_free(flash_t *obj) +{ + (void)(obj); + return 0; +} + +int32_t flash_erase_sector(flash_t *obj, uint32_t address) +{ + (void)(obj); + int32_t status = 0; + if (Cy_Flash_EraseRow(address) != CY_FLASH_DRV_SUCCESS) { + status = -1; + } + + return status; +} + +int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size) +{ + (void)(obj); + int32_t status = 0; + if (Cy_Flash_ProgramRow(address, (const uint32_t *)data) != CY_FLASH_DRV_SUCCESS) { + status = -1; + } + + return status; +} + +uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) +{ + (void)(obj); + if ((address >= CY_FLASH_BASE) && (address < CY_FLASH_BASE + CY_FLASH_SIZE)) { + return CY_FLASH_SIZEOF_ROW; + } + + return MBED_FLASH_INVALID_SIZE; +} + +uint32_t flash_get_page_size(const flash_t *obj) +{ + (void)(obj); + return CY_FLASH_SIZEOF_ROW; +} + +uint32_t flash_get_start_address(const flash_t *obj) +{ + (void)(obj); + return CY_FLASH_BASE; +} + +uint32_t flash_get_size(const flash_t *obj) +{ + (void)(obj); + return CY_FLASH_SIZE; +} + +#endif // DEVICE_FLASH diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/gpio_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/gpio_api.c new file mode 100644 index 0000000000..8c1949f3c4 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/gpio_api.c @@ -0,0 +1,99 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "cmsis.h" +#include "device.h" +#include "mbed_assert.h" +#include "gpio_object.h" +#include "psoc6_utils.h" +#include "mbed_error.h" +#include "rtx_lib.h" + +static inline void gpio_set_dir_mode(gpio_t *obj) +{ + MBED_ASSERT(obj); + MBED_ASSERT(obj->port); + MBED_ASSERT(obj->pin != NC); + + uint32_t pin = CY_PIN(obj->pin); + uint32_t cymode = gpio_get_cy_drive_mode(obj->dir, obj->mode); + + Cy_GPIO_SetDrivemode(obj->port, pin, cymode); + + if (obj->dir == PIN_INPUT) { + // Force output to enable pulls. + switch (cymode) { + case CY_GPIO_DM_PULLUP: + Cy_GPIO_Write(obj->port, pin, 1); + break; + case CY_GPIO_DM_PULLDOWN: + Cy_GPIO_Write(obj->port, pin, 0); + break; + } + } +} + +void gpio_init(gpio_t *obj, PinName pin) +{ + MBED_ASSERT(obj); + obj->pin = pin; + obj->dir = PIN_INPUT; + obj->mode = PullNone; + + if (pin == NC) { + return; + } + + MBED_ASSERT(CY_PIN(obj->pin) < 8); // PSoC6 architecture supports 8 pins per port. + + /* + * Perform i/o reservation only if this is called outside of critical section/interrupt context. + * This is a workaround for mbed_die() implementation, which configures LED1 inside critical section. + * Normally user is advised to perform all of the i/o configuration at the program beginning, + * or elswere in the running thread context. when we decct that we are in the wrong context here, + * we assume it's explicitely called from mbed_die() or other fault handling, so eventual forcing + * of the pin mode is deliberate and should not cause more problems. + */ + if (!(IsIrqMode() || IsIrqMasked())) { + if (cy_reserve_io_pin(pin)) { + error("GPIO pin reservation conflict."); + } + } + obj->port = Cy_GPIO_PortToAddr(CY_PORT(obj->pin)); + + const uint32_t outputVal = 0; + + Cy_GPIO_Pin_FastInit(obj->port, CY_PIN(obj->pin), CY_GPIO_DM_HIGHZ, outputVal, HSIOM_SEL_GPIO); +} + +void gpio_mode(gpio_t *obj, PinMode mode) +{ + MBED_ASSERT(obj); + MBED_ASSERT(obj->pin != NC); + + obj->mode = mode; + gpio_set_dir_mode(obj); +} + +void gpio_dir(gpio_t *obj, PinDirection direction) +{ + MBED_ASSERT(obj); + MBED_ASSERT(obj->pin != NC); + + obj->dir = direction; + gpio_set_dir_mode(obj); +} diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/gpio_irq_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/gpio_irq_api.c new file mode 100644 index 0000000000..febabcdaca --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/gpio_irq_api.c @@ -0,0 +1,313 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "cmsis.h" +#include "device.h" +#include "mbed_assert.h" +#include "gpio_object.h" +#include "gpio_irq_api.h" +#include "psoc6_utils.h" +#include "cy_sysint.h" + + +#define NUM_GPIO_PORTS IOSS_GPIO_GPIO_PORT_NR +#define NUM_GPIO_PORT_PINS 8 +#define GPIO_DEFAULT_IRQ_PRIORITY 5 + +static gpio_irq_t *irq_objects[NUM_GPIO_PORTS][NUM_GPIO_PORT_PINS] = {NULL}; + +typedef struct irq_port_info_s { + IRQn_Type irqn; + uint32_t pin_mask; +} irq_port_info_t; + +static irq_port_info_t irq_port_usage[NUM_GPIO_PORTS] = {{0, 0},}; + +static void gpio_irq_dispatcher(uint32_t port_id) +{ + uint32_t pin; + gpio_irq_event event; + GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(port_id); + + for (pin = 0; pin < NUM_GPIO_PORT_PINS; ++pin) { + if (Cy_GPIO_GetInterruptStatusMasked(port, pin)) { + gpio_irq_t *obj = irq_objects[port_id][pin]; + MBED_ASSERT(obj); + Cy_GPIO_ClearInterrupt(port, pin); + event = (obj->mode == IRQ_FALL)? IRQ_FALL : IRQ_RISE; + obj->handler(obj->id_arg, event); + } + } +} + +static void gpio_irq_dispatcher_port0(void) +{ + gpio_irq_dispatcher(0); +} + +static void gpio_irq_dispatcher_port1(void) +{ + gpio_irq_dispatcher(1); +} + +static void gpio_irq_dispatcher_port2(void) +{ + gpio_irq_dispatcher(2); +} + +static void gpio_irq_dispatcher_port3(void) +{ + gpio_irq_dispatcher(3); +} + +static void gpio_irq_dispatcher_port4(void) +{ + gpio_irq_dispatcher(4); +} + +static void gpio_irq_dispatcher_port5(void) +{ + gpio_irq_dispatcher(5); +} + +static void gpio_irq_dispatcher_port6(void) +{ + gpio_irq_dispatcher(6); +} + +static void gpio_irq_dispatcher_port7(void) +{ + gpio_irq_dispatcher(7); +} + +static void gpio_irq_dispatcher_port8(void) +{ + gpio_irq_dispatcher(8); +} + +static void gpio_irq_dispatcher_port9(void) +{ + gpio_irq_dispatcher(9); +} + +static void gpio_irq_dispatcher_port10(void) +{ + gpio_irq_dispatcher(10); +} + +static void gpio_irq_dispatcher_port11(void) +{ + gpio_irq_dispatcher(11); +} + +static void gpio_irq_dispatcher_port12(void) +{ + gpio_irq_dispatcher(12); +} + +static void gpio_irq_dispatcher_port13(void) +{ + gpio_irq_dispatcher(13); +} + +static void gpio_irq_dispatcher_port14(void) +{ + gpio_irq_dispatcher(14); +} + +static void (*irq_dispatcher_table[])(void) = { + gpio_irq_dispatcher_port0, + gpio_irq_dispatcher_port1, + gpio_irq_dispatcher_port2, + gpio_irq_dispatcher_port3, + gpio_irq_dispatcher_port4, + gpio_irq_dispatcher_port5, + gpio_irq_dispatcher_port6, + gpio_irq_dispatcher_port7, + gpio_irq_dispatcher_port8, + gpio_irq_dispatcher_port9, + gpio_irq_dispatcher_port10, + gpio_irq_dispatcher_port11, + gpio_irq_dispatcher_port12, + gpio_irq_dispatcher_port13, + gpio_irq_dispatcher_port14 +}; + + +static IRQn_Type gpio_irq_allocate_channel(gpio_irq_t *obj) +{ +#if defined (TARGET_MCU_PSOC6_M0) + obj->cm0p_irq_src = ioss_interrupts_gpio_0_IRQn + obj->port_id; + return cy_m0_nvic_allocate_channel(CY_GPIO_IRQN_ID + obj->port_id); +#else + return (IRQn_Type)(ioss_interrupts_gpio_0_IRQn + obj->port_id); +#endif // M0 +} + +static void gpio_irq_release_channel(IRQn_Type channel, uint32_t port_id) +{ +#if defined (TARGET_MCU_PSOC6_M0) + cy_m0_nvic_release_channel(channel, CY_GPIO_IRQN_ID + port_id); +#endif //M0 +} + +static int gpio_irq_setup_channel(gpio_irq_t *obj) +{ + cy_stc_sysint_t irq_config; + + if (irq_port_usage[obj->port_id].pin_mask == 0) { + IRQn_Type irqn = gpio_irq_allocate_channel(obj); + if (irqn < 0) { + return (-1); + } + irq_port_usage[obj->port_id].irqn = irqn; + // Configure NVIC + irq_config.intrPriority = GPIO_DEFAULT_IRQ_PRIORITY; + irq_config.intrSrc = irqn; +#if defined (TARGET_MCU_PSOC6_M0) + irq_config.cm0pSrc = obj->cm0p_irq_src; +#endif + if (Cy_SysInt_Init(&irq_config, irq_dispatcher_table[obj->port_id]) != CY_SYSINT_SUCCESS) { + return(-1); + } + + irq_port_usage[obj->port_id].pin_mask |= (1 << obj->pin); + NVIC_EnableIRQ(irqn); + } + + // TODO: Should we enable individual pin interrupt here? + + return 0; +} + + +/** Initialize the GPIO IRQ pin + * + * @param obj The GPIO object to initialize + * @param pin The GPIO pin name + * @param handler The handler to be attached to GPIO IRQ + * @param id The object ID (id != 0, 0 is reserved) + * @return -1 if pin is NC, 0 otherwise + */ +int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) +{ + if (pin != NC) { + obj->port_id = CY_PORT(pin); + obj->port = Cy_GPIO_PortToAddr(obj->port_id); + obj->pin = CY_PIN(pin); + if (obj->pin > NUM_GPIO_PORT_PINS) { + MBED_ASSERT("Invalid pin ID!"); + return (-1); + } + obj->handler = handler; + obj->id_arg = id; + return gpio_irq_setup_channel(obj); + } else { + return (-1); + } +} + +/** Release the GPIO IRQ PIN + * + * @param obj The gpio object + */ +void gpio_irq_free(gpio_irq_t *obj) +{ + gpio_irq_disable(obj); + // TODO: Need atomicity for the following operations. + NVIC_DisableIRQ(irq_port_usage[obj->port_id].irqn); + irq_port_usage[obj->port_id].pin_mask &= ~(1 << obj->pin); + if (irq_port_usage[obj->port_id].pin_mask == 0) { + gpio_irq_release_channel(irq_port_usage[obj->port_id].irqn, obj->port_id); + return; + } + NVIC_EnableIRQ(irq_port_usage[obj->port_id].irqn); +} + +/** Enable/disable pin IRQ event + * + * @param obj The GPIO object(IRQn_Type) + * @param event The GPIO IRQ event + * @param enable The enable flag + */ +void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) +{ + if (enable) { + if (event == IRQ_RISE) { + if (obj->mode == IRQ_FALL) { + obj->mode += IRQ_RISE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_BOTH); + } else { + obj->mode = IRQ_RISE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_RISING); + } + } else if (event == IRQ_FALL) { + if (obj->mode == IRQ_RISE) { + obj->mode += IRQ_FALL; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_BOTH); + } else { + obj->mode = IRQ_FALL; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_FALLING); + } + } else { + obj->mode = IRQ_NONE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_DISABLE); + } + } else if (obj->mode != IRQ_NONE) { + if (event == IRQ_RISE) { + if (obj->mode == IRQ_RISE) { + obj->mode = IRQ_NONE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_DISABLE); + } else { + obj->mode = IRQ_FALL; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_FALLING); + } + } else if (event == IRQ_FALL) { + if (obj->mode == IRQ_FALL) { + obj->mode = IRQ_NONE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_DISABLE); + } else { + obj->mode = IRQ_RISE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_RISING); + } + } else { + obj->mode = IRQ_NONE; + Cy_GPIO_SetInterruptEdge(obj->port, obj->pin, CY_GPIO_INTR_DISABLE); + } + } +} + +/** Enable GPIO IRQ + * + * This is target dependent, as it might enable the entire port or just a pin + * @param obj The GPIO object + */ +void gpio_irq_enable(gpio_irq_t *obj) +{ + Cy_GPIO_SetInterruptMask(obj->port, obj->pin, 1); +} + +/** Disable GPIO IRQ + * + * This is target dependent, as it might disable the entire port or just a pin + * @param obj The GPIO object + */ +void gpio_irq_disable(gpio_irq_t *obj) +{ + Cy_GPIO_SetInterruptMask(obj->port, obj->pin, 0); +} + diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/gpio_object.h b/targets/TARGET_Cypress/TARGET_PSOC6/gpio_object.h new file mode 100644 index 0000000000..2fd677f247 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/gpio_object.h @@ -0,0 +1,85 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_GPIO_OBJECTS_H +#define MBED_GPIO_OBJECTS_H + +#include "mbed_assert.h" +#include "PinNamesTypes.h" +#include "PinNames.h" + +#include "drivers/peripheral/gpio/cy_gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct gpio_s { + GPIO_PRT_Type *port; + PinName pin; + PinDirection dir; + PinMode mode; +}; + +typedef struct gpio_s gpio_t; + +/** Set the output value + * + * @param obj The GPIO object + * @param value The value to be set + */ +static inline void gpio_write(gpio_t *obj, int value) +{ + MBED_ASSERT(obj->pin != NC); + + Cy_GPIO_Write(obj->port, CY_PIN(obj->pin), value); +} + +/** Read the input value + * + * @param obj The GPIO object + * @return An integer value 1 or 0 + */ +static inline int gpio_read(gpio_t *obj) +{ + MBED_ASSERT(obj->pin != NC); + + return Cy_GPIO_Read(obj->port, CY_PIN(obj->pin)); +} + +static inline int gpio_is_connected(const gpio_t *obj) +{ + return obj->pin != NC; +} + +/** Get the pin name from the port's pin number + * + * @param port The port name + * @param pin_n The pin number within the specified port + * @return The pin name for the port's pin number + */ +inline PinName port_pin(PortName port, int pin_n) +{ + return (PinName)((port << 8) + pin_n); +} + + +#ifdef __cplusplus +} +#endif + +#endif // MBED_GPIO_OBJECTS_H diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/i2c_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/i2c_api.c new file mode 100644 index 0000000000..e82442d12a --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/i2c_api.c @@ -0,0 +1,692 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "cmsis.h" +#include "mbed_assert.h" +#include "mbed_error.h" +#include "PeripheralPins.h" +#include "pinmap.h" +#include "i2c_api.h" +#include "psoc6_utils.h" + +#include "drivers/peripheral/sysclk/cy_sysclk.h" +#include "drivers/peripheral/gpio/cy_gpio.h" +#include "drivers/peripheral/scb/cy_scb_i2c.h" +#include "drivers/peripheral/sysint/cy_sysint.h" + +#define I2C_DEFAULT_SPEED 100000 +#define NUM_I2C_PORTS 8 +#define I2C_DEFAULT_IRQ_PRIORITY 3 +#define I2C_NUM_DIVIDERS 3 +#define MIN_I2C_CLOCK_FREQUENCY CY_SCB_I2C_SLAVE_STD_CLK_MIN +// Default timeout in milliseconds. +#define I2C_DEFAULT_TIMEOUT 1000 + +#define PENDING_NONE 0 +#define PENDING_RX 1 +#define PENDING_TX 2 +#define PENDING_TX_RX 3 + +typedef enum { + I2C_DIVIDER_LOW = 0, + I2C_DIVIDER_MID, + I2C_DIVIDER_HIGH, + I2C_INVALID_DIVIDER = 0xff +} I2cDividerType; + + +typedef struct { + uint32_t div_num; + cy_en_divider_types_t div_type; + uint32_t clk_frequency; +} I2cDividerInfo; + + +static const cy_stc_scb_i2c_config_t default_i2c_config = { + .i2cMode = CY_SCB_I2C_MASTER, + .useRxFifo = true, + .useTxFifo = true, + .slaveAddress = 0, + .slaveAddressMask = 0, + .acceptAddrInFifo = false, + .ackGeneralAddr = false, + .enableWakeFromSleep = false +}; + + +static I2cDividerInfo i2c_dividers[I2C_NUM_DIVIDERS] = { + { I2C_INVALID_DIVIDER, 0, CY_SCB_I2C_SLAVE_STD_CLK_MIN }, // Low divider uses lowest possible frequency. + { I2C_INVALID_DIVIDER, 0, CY_SCB_I2C_SLAVE_FST_CLK_MIN }, + { I2C_INVALID_DIVIDER, 0, CY_SCB_I2C_SLAVE_FSTP_CLK_MIN } +}; + +typedef struct i2c_s i2c_obj_t; + +#if DEVICE_I2C_ASYNCH +#define OBJ_P(in) (&(in->i2c)) +#else +#define OBJ_P(in) (in) +#endif + + +#if DEVICE_I2C_ASYNCH + +static IRQn_Type i2c_irq_allocate_channel(i2c_obj_t *obj) +{ +#if defined (TARGET_MCU_PSOC6_M0) + obj->cm0p_irq_src = scb_0_interrupt_IRQn + obj->i2c_id; + return cy_m0_nvic_allocate_channel(CY_SERIAL_IRQN_ID + obj->i2c_id); +#else + return (IRQn_Type)(ioss_interrupts_gpio_0_IRQn + obj->i2c_id); +#endif // M0 +} + +static void i2c_irq_release_channel(IRQn_Type channel, uint32_t i2c_id) +{ +#if defined (TARGET_MCU_PSOC6_M0) + cy_m0_nvic_release_channel(channel, CY_SERIAL_IRQN_ID + i2c_id); +#endif //M0 +} + +static int i2c_irq_setup_channel(i2c_obj_t *obj) +{ + cy_stc_sysint_t irq_config; + + if (obj->irqn == unconnected_IRQn) { + IRQn_Type irqn = i2c_irq_allocate_channel(obj); + if (irqn < 0) { + return (-1); + } + // Configure NVIC + irq_config.intrPriority = I2C_DEFAULT_IRQ_PRIORITY; + irq_config.intrSrc = irqn; +#if defined (TARGET_MCU_PSOC6_M0) + irq_config.cm0pSrc = obj->cm0p_irq_src; +#endif + if (Cy_SysInt_Init(&irq_config, (cy_israddress)(obj->handler)) != CY_SYSINT_SUCCESS) { + return(-1); + } + + obj->irqn = irqn; + NVIC_EnableIRQ(irqn); + } + return 0; +} + +#endif // DEVICE_I2C_ASYNCH + +static int allocate_divider(I2cDividerType divider) +{ + I2cDividerInfo *p_div = &i2c_dividers[divider]; + + if (p_div->div_num == CY_INVALID_DIVIDER) { + p_div->div_num = cy_clk_allocate_divider(CY_SYSCLK_DIV_8_BIT); + if (p_div->div_num != CY_INVALID_DIVIDER) { + p_div->div_type = CY_SYSCLK_DIV_8_BIT; + } else { + p_div->div_num = cy_clk_allocate_divider(CY_SYSCLK_DIV_16_BIT); + if (p_div->div_num != CY_INVALID_DIVIDER) { + p_div->div_type = CY_SYSCLK_DIV_16_BIT; + } + } + } + + if (p_div->div_num != CY_INVALID_DIVIDER) { + // Set up proper frequency; + uint32_t div_value = CY_CLK_PERICLK_FREQ_HZ / p_div->clk_frequency; + p_div->clk_frequency = CY_CLK_PERICLK_FREQ_HZ / div_value; + if (Cy_SysClk_PeriphSetDivider(p_div->div_type, p_div->div_num, div_value) == CY_SYSCLK_SUCCESS) { + Cy_SysClk_PeriphEnableDivider(p_div->div_type, p_div->div_num); + } else { + p_div->div_num = CY_INVALID_DIVIDER; + } + } + + return (p_div->div_num == CY_INVALID_DIVIDER)? -1 : 0; +} + +/** Select one of the 3 dividers used depending on the required frequency. + */ +static I2cDividerType select_divider(uint32_t frequency) +{ + if (frequency <= (MIN_I2C_CLOCK_FREQUENCY / CY_SCB_I2C_DUTY_CYCLE_MAX)) { + // Required speed lower than min supported. + return I2C_INVALID_DIVIDER; + } else if (frequency <= CY_SCB_I2C_STD_DATA_RATE) { + return I2C_DIVIDER_LOW; + } else if (frequency <= CY_SCB_I2C_FST_DATA_RATE) { + return I2C_DIVIDER_MID; + } else if (frequency <= CY_SCB_I2C_FSTP_DATA_RATE) { + return I2C_DIVIDER_HIGH; + } else { + // Required speed too high; + return I2C_INVALID_DIVIDER; + } +} + +/** Initializes i2c clock for the required speed + */ +static cy_en_sysclk_status_t i2c_init_clock(i2c_obj_t *obj, uint32_t speed) +{ + I2cDividerInfo *p_div = NULL; + cy_en_sysclk_status_t status = CY_SYSCLK_INVALID_STATE; + I2cDividerType divider = select_divider(speed); + + if (divider == I2C_INVALID_DIVIDER) { + error("i2c: required speed/frequency is out of valid range."); + return CY_SYSCLK_BAD_PARAM; + } + + if (allocate_divider(divider) < 0) { + error("i2c: cannot allocate clock divider."); + return CY_SYSCLK_INVALID_STATE; + } + + obj->divider = divider; + p_div = &i2c_dividers[divider]; + + status = Cy_SysClk_PeriphAssignDivider(obj->clock, p_div->div_type, p_div->div_num); + if (status != CY_SYSCLK_SUCCESS) { + error("i2c: cannot assign clock divider."); + return status; + } + + /* Set desired speed/frequency */ + obj->actual_speed = Cy_SCB_I2C_SetDataRate(obj->base, speed, p_div->clk_frequency); + return (obj->actual_speed != 0)? CY_SYSCLK_SUCCESS : CY_SYSCLK_BAD_PARAM; +} + +/** + * Initializes i/o pins for i2c sda/scl. + */ +static void i2c_init_pins(i2c_obj_t *obj) +{ + int sda_function = pinmap_function(obj->pin_sda, PinMap_I2C_SDA); + int scl_function = pinmap_function(obj->pin_scl, PinMap_I2C_SCL); + pin_function(obj->pin_sda, sda_function); + pin_function(obj->pin_scl, scl_function); +} + + +/** + * Initializes and enables I2C/SCB. + */ +static void i2c_init_peripheral(i2c_obj_t *obj) +{ + cy_stc_scb_i2c_config_t i2c_config = default_i2c_config; + I2cDividerInfo *p_div = &i2c_dividers[obj->divider]; + + Cy_SCB_I2C_Init(obj->base, &i2c_config, &obj->context); + Cy_SCB_I2C_SetDataRate(obj->base,obj->actual_speed, p_div->clk_frequency); + Cy_SCB_I2C_Enable(obj->base); +} + +/** + * Coverts PDL status into Mbed status. + */ + static int i2c_convert_status(cy_en_scb_i2c_status_t status) { + switch (status) { + case CY_SCB_I2C_MASTER_NOT_READY: + case CY_SCB_I2C_MASTER_MANUAL_ARB_LOST: + case CY_SCB_I2C_MASTER_MANUAL_BUS_ERR: + case CY_SCB_I2C_MASTER_MANUAL_ABORT_START: + return I2C_ERROR_BUS_BUSY; + + case CY_SCB_I2C_MASTER_MANUAL_TIMEOUT: + case CY_SCB_I2C_MASTER_MANUAL_ADDR_NAK: + case CY_SCB_I2C_MASTER_MANUAL_NAK: + return I2C_ERROR_NO_SLAVE; + + case CY_SCB_I2C_SUCCESS: + case CY_SCB_I2C_BAD_PARAM: + default: + return 0; + } + } + +/** + * Callback function to handle into and out of deep sleep state transitions. + */ +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER +static cy_en_syspm_status_t i2c_pm_callback(cy_stc_syspm_callback_params_t *callback_params) +{ + cy_stc_syspm_callback_params_t params = *callback_params; + i2c_obj_t *obj = (i2c_obj_t *)params.context; + params.context = &obj->context; + + return Cy_SCB_I2C_DeepSleepCallback(¶ms); +} +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + + +/** Initialize the I2C peripheral. It sets the default parameters for I2C + * peripheral, and configures its specified pins. + * + * @param obj The I2C object + * @param sda The sda pin + * @param scl The scl pin + */ +void i2c_init(i2c_t *obj_in, PinName sda, PinName scl) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + uint32_t i2c = pinmap_peripheral(sda, PinMap_I2C_SDA); + i2c = pinmap_merge(i2c, pinmap_peripheral(scl, PinMap_I2C_SCL)); + if (i2c != (uint32_t)NC) { + if (cy_reserve_io_pin(sda) || cy_reserve_io_pin(scl)) { + error("I2C pin reservation conflict."); + } + obj->base = (CySCB_Type*)i2c; + obj->i2c_id = ((I2CName)i2c - I2C_0) / (I2C_1 - I2C_0); + obj->pin_sda = sda; + obj->pin_scl = scl; + obj->clock = CY_PIN_CLOCK(pinmap_function(scl, PinMap_I2C_SCL)); + obj->divider = I2C_INVALID_DIVIDER; + obj->mode = CY_SCB_I2C_MASTER; + obj->timeout = I2C_DEFAULT_TIMEOUT; +#if DEVICE_I2C_ASYNCH + obj->pending = PENDING_NONE; + obj->events = 0; +#endif // DEVICE_I2C_ASYNCH + i2c_init_clock(obj, I2C_DEFAULT_SPEED); + i2c_init_pins(obj); + i2c_init_peripheral(obj); +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + obj->pm_callback_handler.callback = i2c_pm_callback; + obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP; + obj->pm_callback_handler.skipMode = 0; + obj->pm_callback_handler.callbackParams = &obj->pm_callback_params; + obj->pm_callback_params.base = obj->base; + obj->pm_callback_params.context = obj; + if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) { + error("PM callback registration failed!"); + } +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + } else { + error("I2C pinout mismatch. Requested pins Rx and Tx can't be used for the same I2C communication."); + } +} + +/** Configure the I2C frequency + * + * @param obj The I2C object + * @param hz Frequency in Hz + */ +void i2c_frequency(i2c_t *obj_in, int hz) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + Cy_SCB_I2C_Disable(obj->base, &obj->context); + i2c_init_clock(obj, hz); + Cy_SCB_I2C_Enable(obj->base); +} + +/** Send START command + * + * This function is a dummy operation on PSoC + */ +int i2c_start(i2c_t *obj_in) +{ + return 0; +} + +/** Send STOP command + * + * @param obj The I2C object + */ +int i2c_stop(i2c_t *obj_in) +{ + i2c_obj_t *obj = OBJ_P(obj_in); +// Cy_SCB_I2C_MasterSendStop(obj->base, obj->timeout, &obj->context); + return 0; +} + +/** Blocking reading data + * + * @param obj The I2C object + * @param address 7-bit address (last bit is 1) + * @param data The buffer for receiving + * @param length Number of bytes to read + * @param stop Stop to be generated after the transfer is done + * @return Number of read bytes + */ +int i2c_read(i2c_t *obj_in, int address, char *data, int length, int stop) +{ + cy_en_scb_i2c_status_t status = CY_SCB_I2C_SUCCESS; + i2c_obj_t *obj = OBJ_P(obj_in); + cy_en_scb_i2c_command_t ack = CY_SCB_I2C_ACK; + int byte_count = 0; + address >>= 1; + + // Start transaction, send address. + if (obj->context.state == CY_SCB_I2C_IDLE) { + status = Cy_SCB_I2C_MasterSendStart(obj->base, address, CY_SCB_I2C_READ_XFER, obj->timeout, &obj->context); + } + if (status == CY_SCB_I2C_SUCCESS) { + while (length > 0) { + if (length == 1) { + ack = CY_SCB_I2C_NAK; + } + status = Cy_SCB_I2C_MasterReadByte(obj->base, ack, (uint8_t *)data, obj->timeout, &obj->context); + if (status != CY_SCB_I2C_SUCCESS) { + break; + } + ++byte_count; + --length; + ++data; + } + // SCB in I2C mode is very time sensitive. In practice we have to request STOP after + // each block, otherwise it may break the transmission. + Cy_SCB_I2C_MasterSendStop(obj->base, obj->timeout, &obj->context); + } + + if (status != CY_SCB_I2C_SUCCESS) { + Cy_SCB_I2C_MasterSendStop(obj->base, obj->timeout, &obj->context); + byte_count = i2c_convert_status(status); + } + + return byte_count; +} + +/** Blocking sending data + * + * @param obj The I2C object + * @param address 7-bit address (last bit is 0) + * @param data The buffer for sending + * @param length Number of bytes to write + * @param stop Stop to be generated after the transfer is done + * @return + * zero or non-zero - Number of written bytes + * negative - I2C_ERROR_XXX status + */ +int i2c_write(i2c_t *obj_in, int address, const char *data, int length, int stop) +{ + cy_en_scb_i2c_status_t status = CY_SCB_I2C_SUCCESS; + i2c_obj_t *obj = OBJ_P(obj_in); + int byte_count = 0; + address >>= 1; + + // Start transaction, send address. + if (obj->context.state == CY_SCB_I2C_IDLE) { + status = Cy_SCB_I2C_MasterSendStart(obj->base, address, CY_SCB_I2C_WRITE_XFER, obj->timeout, &obj->context); + } + if (status == CY_SCB_I2C_SUCCESS) { + while (length > 0) { + status = Cy_SCB_I2C_MasterWriteByte(obj->base, *data, obj->timeout, &obj->context); + if (status != CY_SCB_I2C_SUCCESS) { + break;; + } + ++byte_count; + --length; + ++data; + } + // SCB in I2C mode is very time sensitive. In practice we have to request STOP after + // each block, otherwise it may break the transmission. + Cy_SCB_I2C_MasterSendStop(obj->base, obj->timeout, &obj->context); + } + + if (status != CY_SCB_I2C_SUCCESS) { + Cy_SCB_I2C_MasterSendStop(obj->base, obj->timeout, &obj->context); + byte_count = i2c_convert_status(status); + } + + return byte_count; +} + +/** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop() + * + * @param obj The I2C object + */ +void i2c_reset(i2c_t *obj_in) +{ + i2c_stop(obj_in); +} + +/** Read one byte + * + * @param obj The I2C object + * @param last Acknowledge + * @return The read byte + */ +int i2c_byte_read(i2c_t *obj_in, int last) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + uint8_t tmp_byte = 0; + cy_en_scb_i2c_command_t ack = last? CY_SCB_I2C_NAK : CY_SCB_I2C_ACK; + cy_en_scb_i2c_status_t status = Cy_SCB_I2C_MasterReadByte(obj->base, ack, &tmp_byte, obj->timeout, &obj->context); + + if (status == CY_SCB_I2C_SUCCESS) { + return tmp_byte; + } else { + return 0; + } +} + +/** Write one byte + * + * @param obj The I2C object + * @param data Byte to be written + * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout. + */ +int i2c_byte_write(i2c_t *obj_in, int data) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + cy_en_scb_i2c_status_t status = Cy_SCB_I2C_MasterWriteByte(obj->base, (uint8_t)data, obj->timeout, &obj->context); + switch (status) { + case CY_SCB_I2C_MASTER_MANUAL_TIMEOUT: + return 2; + case CY_SCB_I2C_MASTER_MANUAL_ADDR_NAK: + case CY_SCB_I2C_MASTER_MANUAL_NAK: + return 0; + case CY_SCB_I2C_SUCCESS: + return 1; + default: + // Error has occurred. + return (-1); + } +} + +#if DEVICE_I2CSLAVE + +/** Configure I2C as slave or master. + * @param obj The I2C object + * @return non-zero if a value is available + */ +void i2c_slave_mode(i2c_t *obj_in, int enable_slave) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + +} + +/** Check to see if the I2C slave has been addressed. + * @param obj The I2C object + * @return The status - 1 - read addresses, 2 - write to all slaves, + * 3 write addressed, 0 - the slave has not been addressed + */ +int i2c_slave_receive(i2c_t *obj_in) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + +} + +/** Configure I2C as slave or master. + * @param obj The I2C object + * @return non-zero if a value is available + */ +int i2c_slave_read(i2c_t *obj_in, char *data, int length) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + +} + +/** Configure I2C as slave or master. + * @param obj The I2C object + * @return non-zero if a value is available + */ +int i2c_slave_write(i2c_t *obj_in, const char *data, int length) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + +} + +/** Configure I2C address. + * @param obj The I2C object + * @param idx Currently not used + * @param address The address to be set + * @param mask Currently not used + */ +void i2c_slave_address(i2c_t *obj_in, int idx, uint32_t address, uint32_t mask) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + obj->slave_addr = (uint8_t)address >> 1; + Cy_SCB_I2C_SlaveSetAddress(obj->base, obj->slave_addr); +} + +#endif + + +#if DEVICE_I2C_ASYNCH + +/** + * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer + * @{ + */ + +/** Start I2C asynchronous transfer + * + * @param obj The I2C object + * @param tx The transmit buffer + * @param tx_length The number of bytes to transmit + * @param rx The receive buffer + * @param rx_length The number of bytes to receive + * @param address The address to be set - 7bit or 9bit + * @param stop If true, stop will be generated after the transfer is done + * @param handler The I2C IRQ handler to be set + * @param hint DMA hint usage + */ +void i2c_transfer_asynch(i2c_t *obj_in, + const void *tx, + size_t tx_length, + void *rx, size_t rx_length, + uint32_t address, + uint32_t stop, + uint32_t handler, + uint32_t event, + DMAUsage hint) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + + (void)hint; // At the moment we do not support DMA transfers, so this parameter gets ignored. + + if (obj->pending != PENDING_NONE) { + return; + } + + obj->rx_config.slaveAddress = address >> 1; + obj->tx_config.slaveAddress = address >> 1; + obj->events = event; + obj->handler = handler; + if (i2c_irq_setup_channel(obj) < 0) { + return; + } + + obj->rx_config.buffer = rx; + obj->rx_config.bufferSize = rx_length; + obj->rx_config.xferPending = !stop; + + obj->tx_config.buffer = (void*)tx; + obj->tx_config.bufferSize = tx_length; + obj->tx_config.xferPending = rx_length || !stop; + + if (tx_length) { + // Write first, then read, or write only. + if (rx_length > 0) { + obj->pending = PENDING_TX_RX; + } else { + obj->pending = PENDING_TX; + } + Cy_SCB_I2C_MasterWrite(obj->base, &obj->tx_config, &obj->context); + } else if (rx_length) { + // Read transaction; + obj->pending = PENDING_RX; + Cy_SCB_I2C_MasterRead(obj->base, &obj->rx_config, &obj->context); + } +} + +/** The asynchronous IRQ handler + * + * @param obj The I2C object which holds the transfer information + * @return Event flags if a transfer termination condition was met, otherwise return 0. + */ +uint32_t i2c_irq_handler_asynch(i2c_t *obj_in) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + uint32_t event = 0; + // Process actual interrupt. + Cy_SCB_I2C_Interrupt(obj->base, &obj->context); + if (obj->context.state == CY_SCB_I2C_MASTER_CMPLT) { + if (obj->context.masterStatus & CY_SCB_I2C_MASTER_ERR) { + if (obj->context.masterStatus & CY_SCB_I2C_MASTER_ADDR_NAK) { + event = I2C_EVENT_ERROR_NO_SLAVE; + } else if (obj->context.masterStatus & CY_SCB_I2C_MASTER_DATA_NAK) { + event = I2C_EVENT_TRANSFER_EARLY_NACK; + } else { + event = I2C_EVENT_ERROR; + } + } else { + // Check if a read phase is pending after write. + if (obj->pending == PENDING_TX_RX) { + obj->pending = PENDING_RX; + Cy_SCB_I2C_MasterRead(obj->base, &obj->rx_config, &obj->context); + } else { + event = I2C_EVENT_TRANSFER_COMPLETE; + } + } + } + if (event) { + obj->pending = PENDING_NONE; + } + return event & obj->events; +} + +/** Attempts to determine if the I2C peripheral is already in use + * + * @param obj The I2C object + * @return Non-zero if the I2C module is active or zero if it is not + */ +uint8_t i2c_active(i2c_t *obj_in) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + return (obj->pending != PENDING_NONE); +} + +/** Abort asynchronous transfer + * + * This function does not perform any check - that should happen in upper layers. + * @param obj The I2C object + */ +void i2c_abort_asynch(i2c_t *obj_in) +{ + i2c_obj_t *obj = OBJ_P(obj_in); + if (obj->pending != PENDING_NONE) { + if (obj->pending == PENDING_RX) { + Cy_SCB_I2C_MasterAbortRead(obj->base, &obj->context); + } else { + Cy_SCB_I2C_MasterAbortWrite(obj->base, &obj->context); + } + } +} + +#endif // DEVICE_ASYNCH diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/ipcpipe_transport.c b/targets/TARGET_Cypress/TARGET_PSOC6/ipcpipe_transport.c new file mode 100644 index 0000000000..65c9695738 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/ipcpipe_transport.c @@ -0,0 +1,175 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "ipcpipe_transport.h" +#include "cy_ipc_config.h" +#include "ipc/cy_ipc_pipe.h" +#include "syspm/cy_syspm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static IpcPipeBuffer ipcpipe_buffer[2]; + +volatile uint32_t ipcpipe_current_buffer = 0; +volatile uint32_t ipcpipe_transfer_buffer = 0; + +static uint32_t num_registered_clients = 0; + +IpcPipeTxCompleteHandler *ipcpipe_xfer_complete_cb[CY_IPC_USRPIPE_CLIENT_CNT] = {NULL}; + + +void ipcpipe_buffer_release(void) +{ + IPCPIPE_ASSERT(ipcpipe_buffer[ipcpipe_transfer_buffer].busy_flag == 1); + ipcpipe_buffer[ipcpipe_transfer_buffer].busy_flag = 0; +} + +void ipcpipe_buffer_release_callback(void) +{ + uint32_t client_id = ipcpipe_buffer[ipcpipe_transfer_buffer].message.client_id; + IpcPipeTxCompleteHandler *handler = ipcpipe_xfer_complete_cb[client_id]; + + IPCPIPE_ASSERT(client_id < CY_IPC_USRPIPE_CLIENT_CNT); + IPCPIPE_ASSERT(ipcpipe_buffer[ipcpipe_transfer_buffer].busy_flag == 1); + ipcpipe_buffer[ipcpipe_transfer_buffer].busy_flag = 0; + + /* call back transfer complete function */ + if (handler) { + (*handler)(); + } +} + +/** Sets current buffer available for transmission. + */ +void ipcpipe_transfer_lock_buffer(uint32_t current_buffer) +{ + IPCPIPE_ASSERT(current_buffer < 2); + IPCPIPE_ASSERT(ipcpipe_buffer[current_buffer].busy_flag == 0); + /* make sure previous transfer has ended */ + while (ipcpipe_buffer[ipcpipe_transfer_buffer].busy_flag) { + /* busy wait */ + } + + ipcpipe_buffer[current_buffer].busy_flag = 1; + ipcpipe_transfer_buffer = current_buffer; +} + +uint32_t ipcpipe_buffer_aquire(void) +{ + uint32_t buffer_index; + /* check that we have a buffer available */ + while (ipcpipe_buffer[ipcpipe_current_buffer].busy_flag) { + /* just wait here */ + Cy_SysPm_Sleep(CY_SYSPM_WAIT_FOR_INTERRUPT); + } + + buffer_index = ipcpipe_current_buffer; + ipcpipe_current_buffer = ipcpipe_current_buffer ? 0 : 1; + return buffer_index; +} + +/** Write header and data over IPC pipe. + */ +void ipcpipe_write_data(uint32_t client_id, uint8_t *header, uint32_t header_length, uint8_t *data, uint32_t data_length) +{ + uint32_t sent_idx = 0; + cy_en_ipc_pipe_status_t status; + int avail = 0; + + IPCPIPE_ASSERT(client_id < CY_IPC_USRPIPE_CLIENT_CNT); + + while ((sent_idx < data_length) || (header_length > 0)) { + uint32_t buffer_id = ipcpipe_buffer_aquire(); + IpcPipeBuffer *buffer = &ipcpipe_buffer[buffer_id]; + uint32_t data_idx = 0; + + /* copy over the header */ + buffer->message.header_length = header_length; + while (header_length > 0) { + buffer->message.header[data_idx++] = *header++; + --header_length; + } + /* copy over the data */ + data_idx = 0; + while ((sent_idx < data_length) && (data_idx < IPCPIPE_MAX_DATA_LENGTH)) { + buffer->message.data[data_idx++] = data[sent_idx++]; + } + buffer->message.data_length = data_idx; + buffer->message.client_id = client_id; + /* put into the pipe */ + ipcpipe_transfer_lock_buffer(buffer_id); + do { + avail = ipcpipe_buffer[ipcpipe_current_buffer].busy_flag == 0; + + status = Cy_IPC_Pipe_SendMessage(CY_IPC_EP_USRPIPE_DEST, /* destination EP */ + CY_IPC_EP_USRPIPE_ADDR, /* source EP */ + &buffer->message, + avail? ipcpipe_buffer_release : ipcpipe_buffer_release_callback); + if (status == CY_IPC_PIPE_ERROR_SEND_BUSY) { + Cy_SysPm_Sleep(CY_SYSPM_WAIT_FOR_INTERRUPT); + } + } while (status != CY_IPC_PIPE_SUCCESS); + } + + /* execute transfer complete callback as appropriate */ + if (avail && ipcpipe_xfer_complete_cb[client_id]) { + (*ipcpipe_xfer_complete_cb[client_id])(); + } +} + +void ipcpipe_transport_start(uint32_t client_id, IpcPipeRxHandler *rx_handler, IpcPipeTxCompleteHandler *tx_handler) +{ + IPCPIPE_ASSERT(client_id < CY_IPC_USRPIPE_CLIENT_CNT); + + /* register/initialize required callbacks */ + Cy_IPC_Pipe_RegisterCallback(CY_IPC_EP_USRPIPE_ADDR, rx_handler, client_id); + Cy_IPC_Pipe_RegisterCallbackRel(CY_IPC_EP_USRPIPE_ADDR, ipcpipe_buffer_release); + ipcpipe_xfer_complete_cb[client_id] = tx_handler; + if (++num_registered_clients == 1) { + ipcpipe_transport_enable(); + } +} + +void ipcpipe_transport_stop(uint32_t client_id) +{ + Cy_IPC_Pipe_RegisterCallback(CY_IPC_EP_USRPIPE_ADDR, NULL, client_id); + Cy_IPC_Pipe_RegisterCallbackRel(CY_IPC_EP_USRPIPE_ADDR, NULL); + ipcpipe_xfer_complete_cb[client_id] = NULL; + if (--num_registered_clients == 0) { + ipcpipe_transport_disable(); + } +} + +void ipcpipe_transport_enable(void) +{ + Cy_IPC_Pipe_EndpointResume(CY_IPC_EP_USRPIPE_ADDR); +} + + +void ipcpipe_transport_disable(void) +{ + Cy_IPC_Pipe_EndpointPause(CY_IPC_EP_USRPIPE_ADDR); +} + +#ifdef __cplusplus +} +#endif + + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/ipcpipe_transport.h b/targets/TARGET_Cypress/TARGET_PSOC6/ipcpipe_transport.h new file mode 100644 index 0000000000..8e4e8bb5df --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/ipcpipe_transport.h @@ -0,0 +1,76 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef IPCPIPE_TRANSPORT_H +#define IPCPIPE_TRANSPORT_H + +#include + +#if defined(__MBED__) +#define IPCPIPE_ASSERT MBED_ASSERT +#include "mbed_assert.h" +#else +#include "project.h" +#define IPCPIPE_ASSERT CY_ASSERT +#endif + + +#define IPCPIPE_MAX_DATA_LENGTH 256 +#define IPCPIPE_MAX_HEADER_LENGTH 4 + +/* Client IDs */ +#define IPCPIPE_CLIENT_H4 0 + +/* IPC Pipe message data structure */ +typedef struct +{ + uint32_t client_id; + uint32_t header_length; + uint32_t data_length; + uint8_t header[IPCPIPE_MAX_HEADER_LENGTH]; + uint8_t data[IPCPIPE_MAX_DATA_LENGTH]; +} IpcPipeMessage; + + +typedef struct +{ + volatile uint8_t busy_flag; + IpcPipeMessage message; +} IpcPipeBuffer; + + +typedef void (IpcPipeRxHandler)(uint32_t *message_ptr); +typedef void (IpcPipeTxCompleteHandler)(void); + +#ifdef __cplusplus +extern "C" { +#endif + +void ipcpipe_write_data(uint32_t client_id, uint8_t* header, uint32_t header_length, uint8_t *data, uint32_t data_length); +void ipcpipe_transport_start(uint32_t client_id, IpcPipeRxHandler *rx_handler, IpcPipeTxCompleteHandler *tx_handler); +void ipcpipe_transport_stop(uint32_t client_id); +void ipcpipe_transport_enable(void); +void ipcpipe_transport_disable(void); + +#ifdef __cplusplus +} +#endif + + +#endif /* IPCPIPE_H4_TRANSPORT_H */ + +/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/lp_ticker.c b/targets/TARGET_Cypress/TARGET_PSOC6/lp_ticker.c new file mode 100644 index 0000000000..6cc8d8aa15 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/lp_ticker.c @@ -0,0 +1,182 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include +#include "device.h" +#include "mbed_error.h" +#include "lp_ticker_api.h" +#include "device/drivers/peripheral/mcwdt/cy_mcwdt.h" +#include "device/drivers/peripheral/sysint/cy_sysint.h" +#include "psoc6_utils.h" + +#if DEVICE_LPTICKER + +/* + * Low Power Timer API on PSoC6 uses MCWD0 timer0 to implement functionality. + */ + +#if defined(TARGET_MCU_PSOC6_M0) +#define LPT_MCWDT_UNIT MCWDT_STRUCT0 +#define LPT_INTERRUPT_PRIORITY 3 +#define LPT_INTERRUPT_SOURCE srss_interrupt_mcwdt_0_IRQn +#else +#define LPT_MCWDT_UNIT MCWDT_STRUCT1 +#define LPT_INTERRUPT_PRIORITY 6 +#define LPT_INTERRUPT_SOURCE srss_interrupt_mcwdt_1_IRQn +#endif +#define LPT_MCWDT_DELAY_WAIT 0 // Recommended value is 93, but then we fail function execution time test. + +static const ticker_info_t lp_ticker_info = { + .frequency = CY_CLK_WCO_FREQ_HZ, + .bits = 16, +}; + +static bool lpt_init_done = false; +// Timer h/w configuration. +static cy_stc_mcwdt_config_t config = { + .c0Match = 0, + .c1Match = 0, + .c0Mode = CY_MCWDT_MODE_INT, + .c1Mode = CY_MCWDT_MODE_NONE, + .c2ToggleBit = 0, + .c2Mode = CY_MCWDT_MODE_NONE, + .c0ClearOnMatch = false, + .c1ClearOnMatch = false, + .c0c1Cascade = false, + .c1c2Cascade = false +}; + +// Interrupt configuration. +static cy_stc_sysint_t lpt_sysint_config = { +#if defined(TARGET_MCU_PSOC6_M0) + .intrSrc = (IRQn_Type)(-1), + .cm0pSrc = LPT_INTERRUPT_SOURCE, +#else + .intrSrc = LPT_INTERRUPT_SOURCE, +#endif + .intrPriority = LPT_INTERRUPT_PRIORITY +}; + + +/** Initialize the low power ticker + * + */ +void lp_ticker_init(void) +{ + lp_ticker_disable_interrupt(); + lp_ticker_clear_interrupt(); + + if (lpt_init_done) { + return; + } + +#ifdef TARGET_MCU_PSOC6_M0 + // Allocate NVIC channel. + lpt_sysint_config.intrSrc = cy_m0_nvic_allocate_channel(CY_LP_TICKER_IRQN_ID); + if (lpt_sysint_config.intrSrc == (IRQn_Type)(-1)) { + // No free NVIC channel. + error("LP_TICKER NVIC channel allocation failed."); + return; + } +#endif + + Cy_MCWDT_Init(LPT_MCWDT_UNIT, &config); + Cy_SysInt_Init(&lpt_sysint_config, lp_ticker_irq_handler); + NVIC_EnableIRQ(lpt_sysint_config.intrSrc); + Cy_MCWDT_Enable(LPT_MCWDT_UNIT, CY_MCWDT_CTR0, LPT_MCWDT_DELAY_WAIT); + lpt_init_done = true; +} + +/** Deinitialize the lower power ticker + * + */ +void lp_ticker_free(void) +{ + NVIC_DisableIRQ(lpt_sysint_config.intrSrc); + Cy_MCWDT_Disable(LPT_MCWDT_UNIT, CY_MCWDT_CTR0, LPT_MCWDT_DELAY_WAIT); +#ifdef TARGET_MCU_PSOC6_M0 + cy_m0_nvic_release_channel(CY_LP_TICKER_IRQN_ID, lpt_sysint_config.intrSrc); + lpt_sysint_config.intrSrc = (IRQn_Type)(-1); +#endif + lpt_init_done = 0; +} + +/** Read the current counter + * + * @return The current timer's counter value in microseconds + */ +uint32_t lp_ticker_read(void) +{ + return Cy_MCWDT_GetCount(LPT_MCWDT_UNIT, CY_MCWDT_COUNTER0); +} + +/** Set interrupt for specified timestamp + * + * @param timestamp The time in microseconds to be set + */ +void lp_ticker_set_interrupt(timestamp_t timestamp) +{ + uint16_t delay; + uint16_t current = Cy_MCWDT_GetCount(LPT_MCWDT_UNIT, CY_MCWDT_COUNTER0); + uint16_t new_ts = (uint16_t)timestamp; + delay = new_ts - current; + // Make sure the event is set for the future. Mbed internally will not schedule + // delays longer than 0x7000, so too large delay means it should occur already. + // MCWDT has internal delay of about 1.5 LF clock ticks, so this is the minimum + // that we can schedule. + if ((delay < 3) || (delay > (uint16_t)(-3))) { + // Cheating a bit here. + new_ts = current + 3; + } + + // Cypress PDL manual says that valid match range is 1..65535. + if (new_ts == 0) { + new_ts = 1; + } + + // Set up and enable match interrupt. + Cy_MCWDT_SetMatch(LPT_MCWDT_UNIT, CY_MCWDT_COUNTER0, new_ts, LPT_MCWDT_DELAY_WAIT); + Cy_MCWDT_SetInterruptMask(LPT_MCWDT_UNIT, CY_MCWDT_CTR0); +} + +/** Disable low power ticker interrupt + * + */ +void lp_ticker_disable_interrupt(void) +{ + Cy_MCWDT_SetInterruptMask(LPT_MCWDT_UNIT, 0); +} + +/** Clear the low power ticker interrupt + * + */ +void lp_ticker_clear_interrupt(void) +{ + Cy_MCWDT_ClearInterrupt(LPT_MCWDT_UNIT, CY_MCWDT_CTR0); +} + +void lp_ticker_fire_interrupt(void) +{ + NVIC_SetPendingIRQ(lpt_sysint_config.intrSrc); +} + +const ticker_info_t* lp_ticker_get_info(void) +{ + return &lp_ticker_info; +} + +#endif // DEVICE_LPTICKER diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/mbed_rtx.h b/targets/TARGET_Cypress/TARGET_PSOC6/mbed_rtx.h similarity index 63% rename from targets/TARGET_Cypress/TARGET_PSoC6/mbed_rtx.h rename to targets/TARGET_Cypress/TARGET_PSOC6/mbed_rtx.h index 9a9ff4275c..0cef96044c 100644 --- a/targets/TARGET_Cypress/TARGET_PSoC6/mbed_rtx.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/mbed_rtx.h @@ -1,4 +1,6 @@ -/* mbed Microcontroller Library +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics * Copyright (c) 2016 u-blox * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,21 +19,21 @@ #ifndef MBED_MBED_RTX_H #define MBED_MBED_RTX_H -#if defined(TARGET_CY8CKIT_062_BLE_M0) +#if defined(TARGET_MCU_PSOC6_M0) - #ifndef INITIAL_SP - #define INITIAL_SP (0x08000000 + 0x00024000) // Ram origin + length - #endif +#ifndef INITIAL_SP +#define INITIAL_SP (0x08000000 + 0x00010000) // Ram origin + length +#endif -#elif defined(TARGET_CY8CKIT_062_BLE_M4) +#elif defined(TARGET_MCU_PSOC6_M4) - #ifndef INITIAL_SP - #define INITIAL_SP (0x08008000 + 0x00024000) // Ram origin + length - #endif +#ifndef INITIAL_SP +#define INITIAL_SP (0x08010000 + 0x00037800) // Ram origin + length +#endif #else - #error "Unknown board" +#error "Unknown board" #endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/objects.h b/targets/TARGET_Cypress/TARGET_PSOC6/objects.h new file mode 100644 index 0000000000..b9fd8e7862 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/objects.h @@ -0,0 +1,227 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef MBED_OBJECTS_H +#define MBED_OBJECTS_H + +#include "cmsis.h" +#include "PeripheralNames.h" +#include "PinNames.h" +#include "PortNames.h" + +#include "gpio_irq_api.h" +#include "gpio_object.h" +#include "drivers/peripheral/sysclk/cy_sysclk.h" +#include "drivers/peripheral/syspm/cy_syspm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if DEVICE_INTERRUPTIN +struct gpio_irq_s { + GPIO_PRT_Type* port; + uint32_t port_id; + uint32_t pin; + gpio_irq_event mode; + gpio_irq_handler handler; + uint32_t id_arg; +#if defined (TARGET_MCU_PSOC6_M0) + cy_en_intr_t cm0p_irq_src; +#endif +}; +#endif // DEVICE_INTERRUPTIN + +struct port_s { + GPIO_PRT_Type *port; + + uint32_t port_id; + uint32_t mask; + PinDirection direction; + PinMode mode; +// __IO uint32_t *reg_in; +// __IO uint32_t *reg_out; +}; + +// struct analogin_s { +// ADCName adc; +// PinName pin; +// uint32_t channel; +// }; + +#if DEVICE_SERIAL +#include "cy_scb_uart.h" + +struct serial_s { + CySCB_Type *base; + uint32_t serial_id; + PinName pin_rx; + PinName pin_tx; + PinName pin_cts; + PinName pin_rts; + en_clk_dst_t clock; + cy_en_divider_types_t div_type; + uint8_t div_num; + uint8_t data_width; + cy_en_scb_uart_stop_bits_t stop_bits; + cy_en_scb_uart_parity_t parity; +#if DEVICE_SERIAL_ASYNCH + uint32_t rx_events; + bool rx_pending; + uint32_t tx_events; + bool tx_pending; + cy_israddress async_handler; +#endif // DEVICE_SERIAL_ASYNCH +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + cy_stc_syspm_callback_params_t pm_callback_params; + cy_stc_syspm_callback_t pm_callback_handler; +#endif +}; +#endif // DEVICE_SERIAL + +#if DEVICE_SPI +#include "cy_scb_spi.h" + +struct spi_s { + CySCB_Type *base; + uint32_t spi_id; + PinName pin_miso; + PinName pin_mosi; + PinName pin_sclk; + PinName pin_ssel; + en_clk_dst_t clock; + uint32_t div_num; + cy_en_divider_types_t div_type; + uint32_t clk_frequency; + cy_en_scb_spi_mode_t ms_mode; + cy_en_scb_spi_sclk_mode_t clk_mode; + uint8_t data_bits; + cy_stc_scb_spi_context_t context; +#if DEVICE_SPI_ASYNCH + IRQn_Type irqn; +#if defined (TARGET_MCU_PSOC6_M0) + cy_en_intr_t cm0p_irq_src; +#endif + uint16_t pending; + uint16_t events; + uint32_t handler; + void *rx_buffer; + uint32_t rx_buffer_size; + void *tx_buffer; + uint32_t tx_buffer_size; +#endif // DEVICE_SPI_ASYNCH +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + cy_stc_syspm_callback_params_t pm_callback_params; + cy_stc_syspm_callback_t pm_callback_handler; +#endif +}; +#endif // DEVICE_SPI + +#if DEVICE_I2C +#include "cy_scb_i2c.h" + +struct i2c_s { + CySCB_Type *base; + uint32_t i2c_id; + PinName pin_sda; + PinName pin_scl; + en_clk_dst_t clock; + uint32_t divider; + uint32_t actual_speed; + cy_en_scb_i2c_mode_t mode; + uint32_t timeout; +#if DEVICE_I2C_SLAVE + uint16_t ADDRESS; + uint16_t is_setAddress; +#endif + cy_stc_scb_i2c_context_t context; +#if DEVICE_I2C_ASYNCH + cy_stc_scb_i2c_master_xfer_config_t rx_config; + cy_stc_scb_i2c_master_xfer_config_t tx_config; + IRQn_Type irqn; +#if defined (TARGET_MCU_PSOC6_M0) + cy_en_intr_t cm0p_irq_src; +#endif + uint16_t pending; + uint16_t events; + uint32_t handler; +#endif // DEVICE_I2C_ASYNCH +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + cy_stc_syspm_callback_params_t pm_callback_params; + cy_stc_syspm_callback_t pm_callback_handler; +#endif +}; +#endif // DEVICE_I2C + +#if DEVICE_PWMOUT +#include "cy_tcpwm.h" + +struct pwmout_s { + TCPWM_Type *base; + PinName pin; + uint32_t counter_id; + uint32_t clock; + uint32_t period; + uint32_t pulse_width; + uint32_t prescaler; +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + cy_stc_syspm_callback_params_t pm_callback_params; + cy_stc_syspm_callback_t pm_callback_handler; +#endif +}; +#endif // DEVICE_PWMOUT + +#ifdef DEVICE_ANALOGIN +#include "cy_sar.h" + +struct analogin_s { + SAR_Type *base; + PinName pin; + uint32_t channel_mask; + uint32_t clock; +}; +#endif // DEVICE_ANALOGIN + +#ifdef DEVICE_ANALOGOUT +#include "cy_ctdac.h" + +struct dac_s { + CTDAC_Type *base; + PinName pin; + uint32_t clock; +}; +#endif // DEVICE_ANALOGOUT + +#ifdef DEVICE_FLASH +struct flash_s { + /* nothing to be stored for now */ + void *dummy; +}; +#endif // DEVICE_FLASH + +#if DEVICE_TRNG +struct trng_s { + /* nothing to be stored for now */ + void *dummy; +}; +#endif // DEVICE_TRNG + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/pinmap.c b/targets/TARGET_Cypress/TARGET_PSOC6/pinmap.c new file mode 100644 index 0000000000..23fe537aa7 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/pinmap.c @@ -0,0 +1,67 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "mbed_assert.h" +#include "pinmap.h" +#include "mbed_error.h" +#include "cy_gpio.h" +#include "psoc6_utils.h" + +void pin_function(PinName pin, int function) +{ + if (pin != NC) { + GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(CY_PORT(pin)); + uint32_t mode = gpio_get_cy_drive_mode(CY_PIN_DIRECTION(function), CY_PIN_MODE(function)); + + Cy_GPIO_Pin_FastInit(port, CY_PIN(pin), mode, 1, CY_PIN_HSIOM(function)); + // Force output to enable pulls. + switch (mode) { + case CY_GPIO_DM_PULLUP: + Cy_GPIO_Write(port, CY_PIN(pin), 1); + break; + case CY_GPIO_DM_PULLDOWN: + Cy_GPIO_Write(port, CY_PIN(pin), 0); + break; + default: + /* do nothing */ + break; + } + } +} + +void pin_mode(PinName pin, PinMode mode) +{ + if (pin != NC) { + uint32_t cymode = gpio_get_cy_drive_mode(PIN_INPUT, mode); + GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(CY_PORT(pin)); + + Cy_GPIO_SetDrivemode(port, CY_PIN(pin), cymode); + + // Force output to enable pulls. + switch (cymode) { + case CY_GPIO_DM_PULLUP: + Cy_GPIO_Write(port, CY_PIN(pin), 1); + break; + case CY_GPIO_DM_PULLDOWN: + Cy_GPIO_Write(port, CY_PIN(pin), 0); + break; + default: + /* do nothing */ + break; + } + } +} diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/port_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/port_api.c new file mode 100644 index 0000000000..cf6c881c2d --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/port_api.c @@ -0,0 +1,144 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "cmsis.h" +#include "device.h" +#include "mbed_assert.h" +#include "gpio_object.h" +#include "port_api.h" +#include "psoc6_utils.h" +#include "mbed_error.h" + +static void port_init_pins(port_t *obj) +{ + uint32_t pin; + uint32_t cy_mode; + + MBED_ASSERT(obj); + MBED_ASSERT(obj->port); + + cy_mode = gpio_get_cy_drive_mode(obj->direction, obj->mode); + for (pin = 0; pin < 8; ++pin) { + if (obj->mask & (1 << pin)) { + Cy_GPIO_Pin_FastInit(obj->port, pin, cy_mode, 0, HSIOM_SEL_GPIO); + } + } + + // Force output to enable pulls. + if (obj->direction == PIN_INPUT) { + switch (cy_mode) { + case CY_GPIO_DM_PULLUP: + port_write(obj, 0xff); + break; // Force output to enable pulls. + + case CY_GPIO_DM_PULLDOWN: + port_write(obj, 0); + break; + } + } +} + +/** Initilize the port + * + * @param obj The port object to initialize + * @param port The port name + * @param mask The bitmask to identify which bits in the port should be included (0 - ignore) + * @param dir The port direction + */ +void port_init(port_t *obj, PortName port, int mask, PinDirection dir) +{ + uint32_t pin; + + MBED_ASSERT(obj); + + for (pin = 0; pin < 8; ++pin) { + if (mask & (1 << pin)) { + if (cy_reserve_io_pin((PinName)((port << 8)+pin))) { + error("Port pin reservation conflict."); + } + } + } + obj->port_id = port; + obj->port = Cy_GPIO_PortToAddr(port); + obj->mask = mask & 0xff; // Only 8 bits exist on a port in PSoC. + obj->direction = dir; + obj->mode = PullDefault; + port_init_pins(obj); +} + +/** Set the input port mode + * + * @param obj The port object + * @param mode THe port mode to be set + */ +void port_mode(port_t *obj, PinMode mode) +{ + MBED_ASSERT(obj); + MBED_ASSERT(obj->port); + + obj->mode = mode; + port_init_pins(obj); +} + +/** Set port direction (in/out) + * + * @param obj The port object + * @param dir The port direction to be set + */ +void port_dir(port_t *obj, PinDirection dir) +{ + MBED_ASSERT(obj); + MBED_ASSERT(obj->port); + + obj->direction = dir; + port_init_pins(obj); +} + +/** Write value to the port + * + * @param obj The port object + * @param value The value to be set + */ +void port_write(port_t *obj, int value) +{ + MBED_ASSERT(obj); + MBED_ASSERT(obj->port); + + if (obj->mask == 0xff) { + obj->port->OUT = value; + } else { + // In case some bits are used for different functionality we need to write + // each bit separately to not break things out, eg. pull up state on other bits. + uint32_t pin; + for (pin = 0; pin < 8; ++pin) { + if (obj->mask & (1 << pin)) { + Cy_GPIO_Write(obj->port, pin, value & 0x1); + value >>= 1; + } + } + } +} + +/** Read the current value on the port + * + * @param obj The port object + * @return An integer with each bit corresponding to an associated port pin setting + */ +int port_read(port_t *obj) +{ + return obj->port->IN & obj->mask; +} diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.c b/targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.c new file mode 100644 index 0000000000..3c23de8d28 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.c @@ -0,0 +1,453 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "psoc6_utils.h" + +#if defined(__MBED__) + +#include "mbed_critical.h" +#include "mbed_error.h" + +#else + +/** Adaptation layer to native Cypress environment */ +/* Notice, that since we use critical section here only for operations + * that do not involve function calls, we can get away with using + * a global static variable for interrupt status saving. + */ + +#include "syslib/cy_syslib.h" + +#define error(arg) CY_ASSERT(0) +#define MBED_ASSERT CY_ASSERT + +#define core_util_critical_section_enter() \ + uint32_t _last_irq_status_ = Cy_SysLib_EnterCriticalSection() + +#define core_util_critical_section_exit() \ + Cy_SysLib_ExitCriticalSection(_last_irq_status_) + +#endif /* defined(__MBED__) */ + + +#define CY_NUM_PSOC6_PORTS 14 +#define CY_NUM_DIVIDER_TYPES 4 +#define NUM_SCB 8 +#define NUM_TCPWM 32 + + +#if defined(TARGET_MCU_PSOC6_M0) || PSOC6_DYNSRM_DISABLE || !defined(__MBED__) + +/****************************************************************************/ +/* Dynamic Shared Resource Manager */ +/****************************************************************************/ +/* + * This part of the code is responsible for management of the hardware + * resource shared between both CPUs of the PSoC 6. + * It supports allocation, freeing and conflict detection, so that never + * both CPUs try to use a single resource. + * It also detects conflicts arising from allocation of hardware devices + * for different modes of operation and when user tries to assign multiple + * functions to the same chip pin. + * It supports two modes of operation: + * 1. DYNAMIC (default mode) + * Resource manager is run on M0 core and M4 core asks it to allocate + * or free resources using RPC over IPC mechanism. + * M0 core communicates with manager via local function calls. + * 2. STATIC (enabled with PSOC6_DYNSRM_DISABLE compilation flag) + * In this mode resources are split statically between both cores. + * Targets using this mode should add psoc6_static_srm.h file to + * each core folder with declarations of resources assigned to it. + * See example file for details. + */ + + +#if PSOC6_DYNSRM_DISABLE + +#define SRM_INIT_RESOURCE(_type_, _res_, _field_, ...) \ +do { \ + struct _init_s_ { \ + uint8_t idx; \ + _type_ val; \ + } init[] = {{0, 0}, __VA_ARGS__}; \ + uint32_t i; \ + for (i = 1; i < sizeof(init)/sizeof(struct _init_s_); ++i) \ + _res_[init[i].idx]_field_ = init[i].val; \ +} while(0) + +#if defined(TARGET_MCU_PSOC6_M0) +/* + * On M0 we start with all resources assigned to M4 and then clear reservations + * for those assigned to it (M0). + */ +#define SRM_PORT(port, pins) {(port), (uint8_t)~(pins)} +#define SRM_DIVIDER(type, dividers) {(type), (uint16_t)~(dividers)} +#define SRM_SCB(num) {(num), (0)} +#define SRM_TCPWM(num) {(num), (0)} + +#define DEFAULT_PORT_RES 0xff +#define DEFAULT_DIVIDER_RES 0xffff +#define DEFAULT_SCM_RES 1 +#define DEFAULT_TCPWM_RES 1 + +#else // defined(TARGET_MCU_PSOC6_M0) + +#define SRM_PORT(port, pins) {(port), (pins)} +#define SRM_DIVIDER(type, dividers) {(type), (dividers)} +#define SRM_SCB(num) {(num), (1)} +#define SRM_TCPWM(num) {(num), (1)} + +#define DEFAULT_PORT_RES 0 +#define DEFAULT_DIVIDER_RES 0 +#define DEFAULT_SCM_RES 0 +#define DEFAULT_TCPWM_RES 0 +#endif // defined(TARGET_MCU_PSOC6_M0) + +#include "psoc6_static_srm.h" + +#else // PSOC6_DYNSRM_DISABLE + +#define DEFAULT_PORT_RES 0 +#define DEFAULT_DIVIDER_RES 0 +#define DEFAULT_SCM_RES 0 +#define DEFAULT_TCPWM_RES 0 + +#endif // PSOC6_DYNSRM_DISABLE + +static uint8_t port_reservations[CY_NUM_PSOC6_PORTS] = {DEFAULT_PORT_RES}; + +typedef struct { + const uint32_t max_index; + uint32_t current_index; + uint32_t reservations; +} divider_alloc_t; + +static divider_alloc_t divider_allocations[CY_NUM_DIVIDER_TYPES] = { + { PERI_DIV_8_NR - 1, 0, DEFAULT_DIVIDER_RES }, // CY_SYSCLK_DIV_8_BIT + { PERI_DIV_16_NR - 1, 0, DEFAULT_DIVIDER_RES }, // CY_SYSCLK_DIV_16_BIT + { PERI_DIV_16_5_NR - 1, 0, DEFAULT_DIVIDER_RES }, // CY_SYSCLK_DIV_16_5_BIT + { PERI_DIV_24_5_NR - 1, 0, DEFAULT_DIVIDER_RES } // CY_SYSCLK_DIV_24_5_BIT +}; + +static uint8_t scb_reservations[NUM_SCB] = {DEFAULT_SCM_RES}; + +static uint8_t tcpwm_reservations[NUM_TCPWM] = {DEFAULT_TCPWM_RES}; + + +int cy_reserve_io_pin(PinName pin_name) +{ + uint32_t port = CY_PORT(pin_name); + uint32_t pin = CY_PIN(pin_name); + int result = (-1); + + if ((port < CY_NUM_PSOC6_PORTS) && (pin <= 7)) { + core_util_critical_section_enter(); + if (!(port_reservations[port] & (1 << pin))) { + port_reservations[port] |= (1 << pin); + result = 0; + } + core_util_critical_section_exit(); + } else { + error("Trying to reserve non existing port/pin!"); + } + return result; +} + + +void cy_free_io_pin(PinName pin_name) +{ + uint32_t port = CY_PORT(pin_name); + uint32_t pin = CY_PIN(pin_name); + int result = (-1); + + if ((port < CY_NUM_PSOC6_PORTS) && (pin <= 7)) { + core_util_critical_section_enter(); + if (port_reservations[port] & (1 << pin)) { + port_reservations[port] &= ~(1 << pin); + result = 0; + } + core_util_critical_section_exit(); + } + + if (result) { + error("Trying to free wrong port/pin."); + } +} + + +uint32_t cy_clk_reserve_divider(cy_en_divider_types_t div_type, uint32_t div_num) +{ + uint32_t divider = CY_INVALID_DIVIDER; + divider_alloc_t *p_alloc = ÷r_allocations[div_type]; + + MBED_ASSERT(div_type < CY_NUM_DIVIDER_TYPES); + MBED_ASSERT(div_num <= p_alloc->max_index); + + core_util_critical_section_enter(); + + if ((p_alloc->reservations & (1 << div_num)) == 0) { + p_alloc->reservations |= (1 << div_num); + divider = div_num; + p_alloc->current_index = ++div_num; + if (p_alloc->current_index > p_alloc->max_index) { + p_alloc->current_index = 0; + } + } + + core_util_critical_section_exit(); + + return divider; +} + + +void cy_clk_free_divider(cy_en_divider_types_t div_type, uint32_t div_num) +{ + int result = (-1); + divider_alloc_t *p_alloc = ÷r_allocations[div_type]; + + MBED_ASSERT(div_type < CY_NUM_DIVIDER_TYPES); + MBED_ASSERT(div_num <= p_alloc->max_index); + + core_util_critical_section_enter(); + + if ((p_alloc->reservations & (1 << div_num)) != 0) { + p_alloc->reservations &= ~(1 << div_num); + result = 0; + } + + core_util_critical_section_exit(); + + if (result) { + error("Trying to release wrong clock divider."); + } +} + + +uint32_t cy_clk_allocate_divider(cy_en_divider_types_t div_type) +{ + uint32_t divider = CY_INVALID_DIVIDER; + divider_alloc_t *p_alloc = ÷r_allocations[div_type]; + + MBED_ASSERT(div_type < CY_NUM_DIVIDER_TYPES); + + core_util_critical_section_enter(); + + MBED_ASSERT(p_alloc->current_index < p_alloc->max_index); + + + for ( uint32_t first_index = p_alloc->current_index; + CY_INVALID_DIVIDER == (divider = cy_clk_reserve_divider(div_type, p_alloc->current_index)); + ++p_alloc->current_index) { + if (p_alloc->current_index > p_alloc->max_index) { + p_alloc->current_index = 0; + } + if (p_alloc->current_index == first_index) { + break; + } + } + + core_util_critical_section_exit(); + + return divider; +} + + +int cy_reserve_scb(uint32_t scb_num) +{ + int result = (-1); + + if (scb_num < NUM_SCB) { + core_util_critical_section_enter(); + if (scb_reservations[scb_num] == 0) { + scb_reservations[scb_num] = 1; + } + core_util_critical_section_exit(); + } + return result; +} + + +void cy_free_scb(uint32_t scb_num) +{ + int result = (-1); + + if (scb_num < NUM_SCB) { + core_util_critical_section_enter(); + if (scb_reservations[scb_num] == 1) { + scb_reservations[scb_num] = 0; + } + core_util_critical_section_exit(); + } + if (result) { + error("Trying to release wrong SCB."); + } +} + + +int cy_reserve_tcpwm(uint32_t tcpwm_num) +{ + int result = (-1); + + if (tcpwm_num < NUM_TCPWM) { + core_util_critical_section_enter(); + if (tcpwm_reservations[tcpwm_num] == 0) { + tcpwm_reservations[tcpwm_num] = 1; + result = 0; + } + core_util_critical_section_exit(); + } + return result; +} + + +void cy_free_tcpwm(uint32_t tcpwm_num) +{ + int result = (-1); + + if (tcpwm_num < NUM_TCPWM) { + core_util_critical_section_enter(); + if (tcpwm_reservations[tcpwm_num] == 1) { + tcpwm_reservations[tcpwm_num] = 0; + result = 0; + } + core_util_critical_section_exit(); + } + if (result) { + error("Trying to release wrong TCPWM."); + } +} + + +/* + * NVIC channel dynamic allocation (multiplexing) is used only on M0. + * On M4 IRQs are statically pre-assigned to NVIC channels. + */ + +#if defined(TARGET_MCU_PSOC6_M0) + +#define NUM_NVIC_CHANNELS ((uint32_t)(NvicMux31_IRQn - NvicMux0_IRQn) + 1) + +static uint32_t irq_channels[NUM_NVIC_CHANNELS] = {0}; + + +IRQn_Type cy_m0_nvic_allocate_channel(uint32_t channel_id) +{ + IRQn_Type alloc = (IRQn_Type)(-1); + uint32_t chn; + MBED_ASSERT(channel_id); + + core_util_critical_section_enter(); + for (chn = 0; chn < NUM_NVIC_CHANNELS; ++chn) { + if (irq_channels[chn] == 0) { + irq_channels[chn] = channel_id; + alloc = NvicMux0_IRQn + chn; + break; irq_channels[chn] = channel_id; + + } + } + core_util_critical_section_exit(); + return alloc; +} + +IRQn_Type cy_m0_nvic_reserve_channel(IRQn_Type channel, uint32_t channel_id) +{ + uint32_t chn = channel - NvicMux0_IRQn; + + MBED_ASSERT(chn < NUM_NVIC_CHANNELS); + MBED_ASSERT(channel_id); + + core_util_critical_section_enter(); + if (irq_channels[chn]) { + channel = (IRQn_Type)(-1); + } else { + irq_channels[chn] = channel_id; + } + core_util_critical_section_exit(); + return channel; +} + +void cy_m0_nvic_release_channel(IRQn_Type channel, uint32_t channel_id) +{ + uint32_t chn = channel - NvicMux0_IRQn; + + MBED_ASSERT(chn < NUM_NVIC_CHANNELS); + MBED_ASSERT(channel_id); + + core_util_critical_section_enter(); + if (irq_channels[chn] == channel_id) { + irq_channels[chn] = 0; + } else { + error("NVIC channel cross-check failed on release."); + } + core_util_critical_section_exit(); +} + +#define CY_BLE_SFLASH_DIE_X_MASK (0x3Fu) +#define CY_BLE_SFLASH_DIE_X_BITS (6u) +#define CY_BLE_SFLASH_DIE_Y_MASK (0x3Fu) +#define CY_BLE_SFLASH_DIE_Y_BITS (6u) +#define CY_BLE_SFLASH_DIE_XY_BITS (CY_BLE_SFLASH_DIE_X_BITS + CY_BLE_SFLASH_DIE_Y_BITS) +#define CY_BLE_SFLASH_DIE_WAFER_MASK (0x1Fu) +#define CY_BLE_SFLASH_DIE_WAFER_BITS (5u) +#define CY_BLE_SFLASH_DIE_XYWAFER_BITS (CY_BLE_SFLASH_DIE_XY_BITS + CY_BLE_SFLASH_DIE_WAFER_BITS) +#define CY_BLE_SFLASH_DIE_LOT_MASK (0x7Fu) +#define CY_BLE_SFLASH_DIE_LOT_BITS (7u) + +static uint8_t cy_ble_deviceAddress[6] = {0x19u, 0x00u, 0x00u, 0x50u, 0xA0u, 0x00u}; + +void cy_get_bd_mac_address(uint8_t *buffer) +{ + uint32_t bdAddrLoc; + bdAddrLoc = ((uint32_t)SFLASH->DIE_X & (uint32_t)CY_BLE_SFLASH_DIE_X_MASK) | + ((uint32_t)(((uint32_t)SFLASH->DIE_Y) & ((uint32_t)CY_BLE_SFLASH_DIE_Y_MASK)) << + CY_BLE_SFLASH_DIE_X_BITS) | + ((uint32_t)(((uint32_t)SFLASH->DIE_WAFER) & ((uint32_t)CY_BLE_SFLASH_DIE_WAFER_MASK)) << + CY_BLE_SFLASH_DIE_XY_BITS) | + ((uint32_t)(((uint32_t)SFLASH->DIE_LOT[0]) & ((uint32_t)CY_BLE_SFLASH_DIE_LOT_MASK)) << + CY_BLE_SFLASH_DIE_XYWAFER_BITS); + + cy_ble_deviceAddress[0] = (uint8_t)bdAddrLoc; + cy_ble_deviceAddress[1] = (uint8_t)(bdAddrLoc >> 8u); + cy_ble_deviceAddress[2] = (uint8_t)(bdAddrLoc >> 16u); + + for (int i = 0; i < 6; ++i) { + buffer[i] = cy_ble_deviceAddress[i]; + } +} + +#endif // defined(TARGET_MCU_PSOC6_M0) + +#endif // defined(TARGET_MCU_PSOC6_M0) || PSOC6_DSRM_DISABLE || !defined(__MBED__) + +void cy_srm_initialize(void) +{ +#if PSOC6_DYNSRM_DISABLE + #ifdef M0_ASSIGNED_PORTS + SRM_INIT_RESOURCE(uint8_t, port_reservations,, M0_ASSIGNED_PORTS); + #endif + #ifdef M0_ASSIGNED_DIVIDERS + SRM_INIT_RESOURCE(uint32_t, divider_allocations, .reservations, M0_ASSIGNED_DIVIDERS); + #endif + #ifdef M0_ASSIGNED_SCBS + SRM_INIT_RESOURCE(uint8_t, scb_reservations,, M0_ASSIGNED_SCBS); + #endif + #ifdef M0_ASSIGNED_TCPWMS + SRM_INIT_RESOURCE(uint8_t, tcpwm_reservations,, M0_ASSIGNED_TCPWMS); + #endif +#endif // PSOC6_DYNSRM_DISABLE +} + diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.h b/targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.h new file mode 100644 index 0000000000..78d5a977e7 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/psoc6_utils.h @@ -0,0 +1,223 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef _PSOC6_UTILS_H_ +#define _PSOC6_UTILS_H_ + +#if defined(__MBED__) + +#include +#include +#include "drivers/peripheral/gpio/cy_gpio.h" +#include "drivers/peripheral/sysclk/cy_sysclk.h" + +#else + +#include "project.h" + +#endif + +#include "PinNamesTypes.h" +#include "PinNames.h" + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +#define CY_INVALID_DIVIDER 0xFF + +/** \brief Allocates clock divider to be used for a new clock signal. + * + * \param div_type cy_en_divider_types_t Divider type. + * \return uint32_t Divider number (id) or CY_CLK_INVALID_DIVIDER if unavailable. + * + */ +uint32_t cy_clk_allocate_divider(cy_en_divider_types_t div_type); + +/** \brief Reserves clock divider to be used for a new clock signal. + * + * \param div_type cy_en_divider_types_t Divider type. + * \param div_num Divider number to be reserved. + * \return uint32_t Divider number (id) or CY_CLK_INVALID_DIVIDER if unavailable. + * + */ +uint32_t cy_clk_reserve_divider(cy_en_divider_types_t div_type, uint32_t div_num); + +/** \brief Releases already reserved clock divider. + * + * \param div_type cy_en_divider_types_t Divider type. + * \param div_num Divider number to be released. + * + */ +void cy_clk_free_divider(cy_en_divider_types_t div_type, uint32_t div_num); + +#ifdef TARGET_MCU_PSOC6_M0 + +#include "gpio_irq_api.h" + +/** \brief On PSoC6 M0 core interrupts are routed into NVIC via additional multiplexer. + * This function allocates free NVIC channel to be used by particular interrupt. + * + * \param allocation_id Unique identifier (for debug purposes). + * \return IRQ channel allocated or (-1) if no free channel is available. + * + */ +IRQn_Type cy_m0_nvic_allocate_channel(uint32_t allocation_id); + +/** \brief Reserves particular NVIC channel if it is available. + * + * \param channel IRQn_Type Channel to be reserved. + * \param allocation_id uint32_t Identifier. + * \return IRQ channel allocated or (-1) if no free channel is available. + * + */ +IRQn_Type cy_m0_nvic_reserve_channel(IRQn_Type channel, uint32_t allocation_id); + +/** \brief Releases NVIC channel. + * + * \param channel IRQn_Type Channel to be released. + * \param allocation_id uint32_t Id used during allocation (for cross check). + * \return void + * + */ +void cy_m0_nvic_release_channel(IRQn_Type channel, uint32_t allocation_id); + +#endif /* M0+ core */ + + +/** \brief Request allocation of SCB block. + * + * \param scb_num uint32_t Id of the SCB block. + * \return (0) when OK, (-1) when reservation conflict occurs. + * + */ +int cy_reserve_scb(uint32_t scb_num); + +/** \brief Releases SCB block. + * + * \param scb_num uint32_t Id of the SCB block. + * \return void + * + */ +void cy_free_scb(uint32_t scb_num); + +/** \brief Request allocation of TCPWM block. + * + * \param tcpwm_num uint32_t Id of the TCPWM block. + * \return (0) when OK, (-1) when reservation conflict occurs. + * + */ +int cy_reserve_tcpwm(uint32_t tcpwm_num); + +/** \brief Releases TCPWM block. + * + * \param tcpwm_num uint32_t Id of the TCPWM block. + * \return void + * + */ +void cy_free_tcpwm(uint32_t tcpwm_num); + +/** \brief Request allocation of i/o pin. + * + * \param pin PinName Id of the pin to allocate. + * \return (0) when OK, (-1) when reservation conflict occurs. + * + */ +int cy_reserve_io_pin(PinName pin); + + +/** \brief Releases i/o pin. + * + * \param pin PinName Id of the pin. + * \return void + * + */ +void cy_free_io_pin(PinName pin); + +/** \brief Initializes shared resource manager. + * + * \param none. + * \return void + * + */ +void cy_srm_initialize(void); + + +/** \brief Returns board-specific hardware MAC address. + * + * \param uint8_t *buffer Buffer where address will be returned. + * \return void. + * + */ +void cy_get_bd_mac_address(uint8_t* buffer); + + +/** \brief Determines proper PSoC6 pin drive mode settings. + * + * \param dir PinDirection Pin direction, in or out. + * \param mode PinMode Mbed pin mode. + * \return PSoC6 pin drive mode. + * + */ +static inline uint32_t gpio_get_cy_drive_mode(PinDirection dir, PinMode mode) +{ + uint32_t cymode = 0; + + switch (mode) { + case PullNone: + switch (dir) { + case PIN_INPUT: + cymode = CY_GPIO_DM_HIGHZ; + break; + case PIN_OUTPUT: + cymode = CY_GPIO_DM_STRONG; + break; + } + break; + + case PushPull: + cymode = CY_GPIO_DM_STRONG; + break; + + case PullUp: + cymode = CY_GPIO_DM_PULLUP; + break; + case PullDown: + cymode = CY_GPIO_DM_PULLDOWN; + break; + case OpenDrainDriveLow: + cymode = CY_GPIO_DM_OD_DRIVESLOW; + break; + case OpenDrainDriveHigh: + cymode = CY_GPIO_DM_OD_DRIVESHIGH; + break; + case AnalogMode: + cymode = CY_GPIO_DM_ANALOG; + break; + } + + return cymode; +} + + + +#if defined(__cplusplus) +} +#endif /* __cplusplus */ + + +#endif // _PSOC6_UTILS_H_ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c new file mode 100644 index 0000000000..7e85ec6680 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c @@ -0,0 +1,369 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "device.h" +#include "pwmout_api.h" +#include "cy_tcpwm.h" +#include "cy_tcpwm_pwm.h" +#include "psoc6_utils.h" +#include "mbed_assert.h" +#include "mbed_error.h" +#include "pinmap.h" +#include "PeripheralPins.h" +#include "platform/mbed_error.h" +#include "cy_syspm.h" + +#define PWMOUT_BASE_CLOCK_HZ 1000000UL +#define MAX_16_BIT_PERIOD 65536 + +static uint32_t pwm_clock_divider = CY_INVALID_DIVIDER; + +static const cy_stc_tcpwm_pwm_config_t pwm_config = { + .pwmMode = CY_TCPWM_PWM_MODE_PWM, + .clockPrescaler = 0, // will be configured separately + .pwmAlignment = CY_TCPWM_PWM_LEFT_ALIGN, + .runMode = CY_TCPWM_PWM_CONTINUOUS, + .period0 = 0, // will be configured separately + .enablePeriodSwap = 0, + .compare0 = 0, // will be configured separately + .compare1 = 0, // will be configured separately + .enableCompareSwap = 0, + .interruptSources = 0, //CY_TCPWM_INT_ON_CC, + .invertPWMOut = CY_TCPWM_PWM_INVERT_DISABLE, + .invertPWMOutN = CY_TCPWM_PWM_INVERT_ENABLE, + .killMode = CY_TCPWM_PWM_ASYNC_KILL, + .countInputMode = CY_TCPWM_INPUT_LEVEL, + .countInput = CY_TCPWM_INPUT_1, + .swapInputMode = CY_TCPWM_INPUT_LEVEL, + .swapInput = CY_TCPWM_INPUT_1, + .reloadInputMode = CY_TCPWM_INPUT_LEVEL, + .reloadInput = CY_TCPWM_INPUT_0, + .startInputMode = CY_TCPWM_INPUT_LEVEL, + .startInput = CY_TCPWM_INPUT_0, + .killInputMode = CY_TCPWM_INPUT_LEVEL, + .killInput = CY_TCPWM_INPUT_0, +}; + + +static void Cy_TCPWM_PWM_SetPrescaler(TCPWM_Type *base, uint32_t cntNum, uint32_t prescaler) +{ + base->CNT[cntNum].CTRL = _CLR_SET_FLD32U(base->CNT[cntNum].CTRL, TCPWM_CNT_CTRL_GENERIC, prescaler); +} + + +static void pwm_start_32b(pwmout_t *obj, uint32_t new_period, uint32_t new_width) +{ + obj->period = new_period; + obj->pulse_width = new_width; + Cy_TCPWM_PWM_SetPeriod0(obj->base, obj->counter_id, obj->period - 1); + Cy_TCPWM_PWM_SetCompare0(obj->base, obj->counter_id, obj->pulse_width); + Cy_TCPWM_PWM_Enable(obj->base, obj->counter_id); + Cy_TCPWM_TriggerStart(obj->base, 1UL << obj->counter_id); +} + + +static void pwm_start_16b(pwmout_t *obj, uint32_t period, uint32_t width) +{ + uint32_t prescaler = 0; + + obj->period = period; + obj->pulse_width = width; + + // For 16-bit counters we need to configure prescaler appropriately. + while ((period > MAX_16_BIT_PERIOD) && (prescaler < CY_TCPWM_PWM_PRESCALER_DIVBY_128)) { + period /= 2; + prescaler += 1; + } + if (period > MAX_16_BIT_PERIOD) { + // We have reached the prescaler limit, set period to max value. + error("Can't configure required PWM period."); + period = MAX_16_BIT_PERIOD; + } + + obj->prescaler = prescaler; + width >>= prescaler; + + Cy_TCPWM_PWM_SetPeriod0(obj->base, obj->counter_id, period - 1); + Cy_TCPWM_PWM_SetPrescaler(obj->base, obj->counter_id, prescaler); + Cy_TCPWM_PWM_SetCompare0(obj->base, obj->counter_id, width); + Cy_TCPWM_PWM_Enable(obj->base, obj->counter_id); + Cy_TCPWM_TriggerStart(obj->base, 1UL << obj->counter_id); +} + + +static void pwm_start(pwmout_t *obj, uint32_t new_period, uint32_t new_pulse_width) +{ + obj->period = new_period; + obj->pulse_width = new_pulse_width; + Cy_TCPWM_PWM_Disable(obj->base, obj->counter_id); + if (new_period > 0) { + if (obj->base == TCPWM0) { + pwm_start_32b(obj, new_period, new_pulse_width); + } else { + pwm_start_16b(obj, new_period, new_pulse_width); + } + } +} + + +/** Callback handler to restart the timer after deep sleep. + * + */ +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER +static cy_en_syspm_status_t pwm_pm_callback(cy_stc_syspm_callback_params_t *callback_params) +{ + pwmout_t *obj = (pwmout_t *)callback_params->context; + + switch (callback_params->mode) { + case CY_SYSPM_BEFORE_TRANSITION: + /* Disable timer before transition */ + Cy_TCPWM_PWM_Disable(obj->base, obj->counter_id); + break; + + case CY_SYSPM_AFTER_TRANSITION: + /* Enable the timer to operate */ + if (obj->period > 0) { + Cy_TCPWM_PWM_Enable(obj->base, obj->counter_id); + Cy_TCPWM_TriggerStart(obj->base, 1UL << obj->counter_id); + } + break; + + default: + break; + } + + return CY_SYSPM_SUCCESS; +} +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + + +/** Initialize the pwm out peripheral and configure the pin + * + * @param obj The pwmout object to initialize + * @param pin The pwmout pin to initialize + */ +void pwmout_init(pwmout_t *obj, PinName pin) +{ + uint32_t pwm_cnt = 0; + uint32_t pwm_function = 0; + + MBED_ASSERT(obj); + MBED_ASSERT(pin != (PinName)NC); + // Allocate and setup clock. + if (pwm_clock_divider == CY_INVALID_DIVIDER) { + pwm_clock_divider = cy_clk_allocate_divider(CY_SYSCLK_DIV_8_BIT); + if (pwm_clock_divider == CY_INVALID_DIVIDER) { + error("PWM clock divider allocation failed."); + return; + } + Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, + pwm_clock_divider, + (CY_CLK_PERICLK_FREQ_HZ / PWMOUT_BASE_CLOCK_HZ) - 1); + Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, pwm_clock_divider); + } + + pwm_cnt = pinmap_peripheral(pin, PinMap_PWM_OUT); + if (pwm_cnt != (uint32_t)NC) { + if (cy_reserve_io_pin(pin)) { + error("PWMOUT pin reservation conflict."); + } + obj->base = (TCPWM_Type*)CY_PERIPHERAL_BASE(pwm_cnt); + obj->pin = pin; + if (obj->base == TCPWM0) { + obj->counter_id = ((PWMName)pwm_cnt - PWM_32b_0) / (PWM_32b_1 - PWM_32b_0); + } else { + // TCPWM1 is used. + obj->counter_id = ((PWMName)pwm_cnt - PWM_16b_0) / (PWM_16b_1 - PWM_16b_0); + } + + // Configure clock. + pwm_function = pinmap_function(pin, PinMap_PWM_OUT); + obj->clock = CY_PIN_CLOCK(pwm_function); + Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_8_BIT, pwm_clock_divider); + Cy_TCPWM_PWM_Init(obj->base, obj->counter_id, &pwm_config); + pin_function(pin, pwm_function); + // These will be properly configured later on. + obj->period = 0; + obj->pulse_width = 0; + obj->prescaler = 0; +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + obj->pm_callback_handler.callback = pwm_pm_callback; + obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP; + obj->pm_callback_handler.skipMode = CY_SYSPM_SKIP_CHECK_READY | CY_SYSPM_SKIP_CHECK_FAIL; + obj->pm_callback_handler.callbackParams = &obj->pm_callback_params; + obj->pm_callback_params.base = obj->base; + obj->pm_callback_params.context = obj; + if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) { + error("PM callback registration failed!"); + } +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + + } else { + error("PWM OUT pinout mismatch."); + } +} + +/** Deinitialize the pwmout object + * + * @param obj The pwmout object + */ +void pwmout_free(pwmout_t *obj) +{ + // TODO: Not implemented yet. +} + +/** Set the output duty-cycle in range <0.0f, 1.0f> + * + * Value 0.0f represents 0 percentage, 1.0f represents 100 percent. + * @param obj The pwmout object + * @param percent The floating-point percentage number + */ +void pwmout_write(pwmout_t *obj, float percent) +{ + uint32_t pulse_width; + MBED_ASSERT(obj); + + if (percent < 0.0) { + percent = 0.0; + } else if (percent > 1.0) { + percent = 1.0; + } + pulse_width = (uint32_t)(percent * obj->period + 0.5); + pwm_start(obj, obj->period, pulse_width); +} + +/** Read the current float-point output duty-cycle + * + * @param obj The pwmout object + * @return A floating-point output duty-cycle + */ +float pwmout_read(pwmout_t *obj) +{ + MBED_ASSERT(obj); + + return (float)(obj->pulse_width) / obj->period; +} + +/** Set the PWM period specified in seconds, keeping the duty cycle the same + * + * Periods smaller than microseconds (the lowest resolution) are set to zero. + * @param obj The pwmout object + * @param seconds The floating-point seconds period + */ +void pwmout_period(pwmout_t *obj, float seconds) +{ + uint32_t period; + uint32_t pulse_width; + + MBED_ASSERT(obj); + + if (seconds < 0.0) { + seconds = 0.0; + } + period = (uint32_t)(seconds * 1000000 + 0.5); + pulse_width = (uint32_t)((uint64_t)period * obj->pulse_width / obj->period); + pwm_start(obj, period, pulse_width); +} + +/** Set the PWM period specified in miliseconds, keeping the duty cycle the same + * + * @param obj The pwmout object + * @param ms The milisecond period + */ +void pwmout_period_ms(pwmout_t *obj, int ms) +{ + uint32_t period; + uint32_t pulse_width; + + MBED_ASSERT(obj); + + if (ms < 0.0) { + ms = 0.0; + } + period = (uint32_t)(ms * 1000 + 0.5); + pulse_width = (uint32_t)((uint64_t)period * obj->pulse_width / obj->period); + pwm_start(obj, period, pulse_width); +} + +/** Set the PWM period specified in microseconds, keeping the duty cycle the same + * + * @param obj The pwmout object + * @param us The microsecond period + */ +void pwmout_period_us(pwmout_t *obj, int us) +{ + uint32_t pulse_width; + + MBED_ASSERT(obj); + + if (us < 0) { + us = 0; + } + pulse_width = (uint32_t)((uint64_t)us * obj->pulse_width / obj->period); + pwm_start(obj, us, pulse_width); +} + +/** Set the PWM pulsewidth specified in seconds, keeping the period the same. + * + * @param obj The pwmout object + * @param seconds The floating-point pulsewidth in seconds + */ +void pwmout_pulsewidth(pwmout_t *obj, float seconds) +{ + uint32_t pulse_width; + + MBED_ASSERT(obj); + + if (seconds < 0.0) { + seconds = 0.0; + } + pulse_width = (uint32_t)(seconds * 1000000 + 0.5); + pwm_start(obj, obj->period, pulse_width); +} + +/** Set the PWM pulsewidth specified in miliseconds, keeping the period the same. + * + * @param obj The pwmout object + * @param ms The floating-point pulsewidth in miliseconds + */ +void pwmout_pulsewidth_ms(pwmout_t *obj, int ms) +{ + uint32_t pulse_width; + + MBED_ASSERT(obj); + + if (ms < 0.0) { + ms = 0.0; + } + pulse_width = (uint32_t)(ms * 1000 + 0.5); + pwm_start(obj, obj->period, pulse_width); +} + +/** Set the PWM pulsewidth specified in microseconds, keeping the period the same. + * + * @param obj The pwmout object + * @param us The floating-point pulsewidth in microseconds + */ +void pwmout_pulsewidth_us(pwmout_t *obj, int us) +{ + MBED_ASSERT(obj); + + if (us < 0) { + us = 0; + } + pwm_start(obj, obj->period, us); +} diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/rpc_api.h b/targets/TARGET_Cypress/TARGET_PSOC6/rpc_api.h new file mode 100644 index 0000000000..7abb7bda88 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/rpc_api.h @@ -0,0 +1,87 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +/** This file contains declarations of all the functions executed on CM0+ core + * that need to be callable from CM4 core via internal RPC mechanism. + * + * Functions are declared using RPC_FUNCTION( _type_, _name_, _args_) macro, + * where it's arguments are also created using support macros: + * _type_ is a function type declared as either TYPE() or VOID, + * _name_ is a function name declared using macro NAME(), + * function must use "C" type interfacing (ABI), + * _args_ function arguments declared using macro ARGS(), + * where is a list of type definitions (as in function + * prototype). + * + * Proper RPC interfacing between processors is automatically generated based + * on the content of this file. + */ + +/* Notice! This file explicitly avoids using re-include suppress schema. */ + +#include "psoc6_utils.h" +#include "rpc_defs.h" + +#undef __RPC_API_H_BODY_START__ +#define __RPC_API_H_BODY_START__ + +#if !PSOC6_DYNSRM_DISABLE + +RPC_FUNCTION(TYPE( uint32_t ), + NAME( cy_clk_allocate_divider ), + ARGS( cy_en_divider_types_t /* div_type */)) + +RPC_FUNCTION(TYPE( uint32_t ), + NAME( cy_clk_reserve_divider ), + ARGS( cy_en_divider_types_t /* div_type */, uint32_t /* div_num */)) + +RPC_FUNCTION(VOID, + NAME( cy_clk_free_divider ), + ARGS( cy_en_divider_types_t /* div_type */, uint32_t /* div_num */)) + +RPC_FUNCTION(TYPE( int ), + NAME( cy_reserve_scb ), + ARGS( uint32_t /* scb_num */)) + +RPC_FUNCTION(VOID, + NAME( cy_free_scb ), + ARGS( uint32_t /* scb_num */)) + +RPC_FUNCTION(TYPE( int ), + NAME( cy_reserve_tcpwm ), + ARGS( uint32_t /* tcpwm_num */)) + +RPC_FUNCTION(VOID, + NAME( cy_free_tcpwm ), + ARGS( uint32_t /* tcpwm_num */)) + +RPC_FUNCTION(TYPE( int ), + NAME( cy_reserve_io_pin ), + ARGS( PinName /* pin */)) + +RPC_FUNCTION(VOID, + NAME( cy_free_io_pin ), + ARGS( PinName /* pin */)) + +RPC_FUNCTION(VOID, + NAME( cy_get_bd_mac_address ), + ARGS( uint8_t* /* buffer */ )) + +#endif // !PSOC6_DYNSRM_DISABLE + +#undef __RPC_API_H_BODY_END__ +#define __RPC_API_H_BODY_END__ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/rpc_defs.h b/targets/TARGET_Cypress/TARGET_PSOC6/rpc_defs.h new file mode 100644 index 0000000000..755718d787 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/rpc_defs.h @@ -0,0 +1,143 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#ifndef RPC_DEFS_H +#define RPC_DEFS_H + + + +#define _GET_10TH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N +#define _GET_9TH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N +#define _GET_8TH_ARG(_1, _2, _3, _4, _5, _6, _7, N, ...) N +#define _GET_7TH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N +#define _GET_6TH_ARG(_1, _2, _3, _4, _5, N, ...) N +#define _GET_5TH_ARG(_1, _2, _3, _4, N, ...) N +#define _GET_4TH_ARG(_1, _2, _3, N, ...) N +#define _GET_3TH_ARG(_1, _2, N, ...) N +#define _GET_2ND_ARG(_1, N, ...) N +#define _GET_1ST_ARG(N, ...) N + +// Count how many args are in a variadic macro. We now use GCC/Clang's extension to +// handle the case where ... expands to nothing. We must add a placeholder arg before +// ##__VA_ARGS__ (its value is totally irrelevant, but it's necessary to preserve +// the shifting offset we want). In addition, we must add 0 as a valid value to be in +// the N position. +#define COUNT_VARARGS(...) _GET_10TH_ARG(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + +#define _GET_OVERRIDE(_1, _2, _3, _4, _5, NAME, ...) NAME + +#define _RPC_CALL_0() () +#define _RPC_CALL_1(_t1) ((_t1)(message->args[0])) +#define _RPC_CALL_2(_t1, _t2) ((_t1)(message->args[0]), (_t2)(message->args[1])) +#define _RPC_CALL_3(_t1, _t2, _t3) ((_t1)(message->args[0]), (_t2)(message->args[1]), (_t3)(message->args[2])) +#define _RPC_CALL_4(_t1, _t2, _t3, _t4) ((_t1)(message->args[0]), (_t2)(message->args[1]), (_t3)(message->args[2]), (_t4)(message->args[3])) +#define _RPC_CALL_5(_t1, _t2, _t3, _t4, _t5) ((_t1)(message->args[0]), (_t2)(message->args[1]), (_t4)(message->args[3]), (_t5)(message->args[4]), (_t2)(message->args[1])) + +#define _RPC_DECL_ARGS_0() +#define _RPC_DECL_ARGS_1(_t1) _t1 arg1 +#define _RPC_DECL_ARGS_2(_t1, _t2) _t1 arg1, _t2 arg2 +#define _RPC_DECL_ARGS_3(_t1, _t2, _t3) _t1 arg1, _t2 arg2, _t3 arg3 +#define _RPC_DECL_ARGS_4(_t1, _t2, _t3, _t4) _t1 arg1, _t2 arg2, _t3 arg3, _t4 arg4 +#define _RPC_DECL_ARGS_5(_t1, _t2, _t3, _t4, _t5) _t1 arg1, _t2 arg2, _t3 arg3, _t4 arg4, _t5 arg5 + +#define _RPC_ARGS_0() +#define _RPC_ARGS_1(_t1) , arg1 +#define _RPC_ARGS_2(_t1, _t2) , arg1, arg2 +#define _RPC_ARGS_3(_t1, _t2, _t3) , arg1, arg2, arg3 +#define _RPC_ARGS_4(_t1, _t2, _t3, _t4) , arg1, arg2, arg3, arg4 +#define _RPC_ARGS_5(_t1, _t2, _t3, _t4, _t5) , arg1, arg2, arg3, arg4, arg5 + + +#define RPC_DECL_ARGS(...) \ + _GET_OVERRIDE(__VA_ARGS__, _RPC_DECL_ARGS_5, _RPC_DECL_ARGS_4, _RPC_DECL_ARGS_3, _RPC_DECL_ARGS_2, _RPC_DECL_ARGS_1, _RPC_DECL_ARGS_0)(__VA_ARGS__) + +#define RPC_LIST_ARGS(...) \ + _GET_OVERRIDE(__VA_ARGS__, _RPC_ARGS_5, _RPC_ARGS_4, _RPC_ARGS_3, _RPC_ARGS_2, _RPC_ARGS_1, _RPC_ARGS_0)(__VA_ARGS__) + +#define RPC_CALL_ARGS(...) \ + _GET_OVERRIDE(__VA_ARGS__, _RPC_CALL_5, _RPC_CALL_4, _RPC_CALL_3, _RPC_CALL_2, _RPC_CALL_1, _RPC_CALL_0)(__VA_ARGS__) + + +#define _RPC_VOID(arg) +#define _RPC_NON_VOID(arg) arg +#define NAME(_name_) _name_ +#define TYPE(_type_) _RPC_NON_VOID, _type_ +#define VOID _RPC_VOID, void +#define ARGS(...) __VA_ARGS__ +#define RPC_FUNCTION(...) RPC_FUNCTION_(__VA_ARGS__) + +#define RPC_GEN_INTERFACE_IDS 1 +#define RPC_GEN_INTERFACE_IDS_INIT 2 +#define RPC_GEN_INTERFACE 3 +#define RPC_GEN_IMPLEMENTATION 4 +#define RPC_GEN_IMPL_INIT 5 + +#endif // RPC_DEFS_H + +#undef __RPC_DEFS_H_BODY_START__ +#define __RPC_DEFS_H_BODY_START__ + +#if RPC_GEN == RPC_GEN_INTERFACE_IDS +/** Generating interface IDs. + * This will generate a set of variable named RPC_ID_ with unique integer IDs. + */ +#undef RPC_FUNCTION_ +#define RPC_FUNCTION_(T, _type_, _name_, ...) static uint32_t RPC_ID_##_name_ = 0; + +#elif RPC_GEN == RPC_GEN_INTERFACE_IDS_INIT +/** Initialization of interface IDs. + * This will generate a set of variable named RPC_ID_ with unique integer IDs. + */ +#undef RPC_FUNCTION_ +#define RPC_FUNCTION_(T, _type_, _name_, ...)\ + RPC_ID_##_name_ = rpc_counter++; + +#elif RPC_GEN == RPC_GEN_INTERFACE +/** Generating interface functions on caller core. + * This will generate a set of functions with the defined API that will internally call RPC pipe. + */ +#undef RPC_FUNCTION_ +#define RPC_FUNCTION_(T, _type_, _name_, ... )\ +_type_ _name_(RPC_DECL_ARGS(__VA_ARGS__)) {\ + T(return ) (_type_)ipcrpc_call(RPC_ID_##_name_, COUNT_VARARGS(__VA_ARGS__) RPC_LIST_ARGS(__VA_ARGS__));\ +} + +#elif RPC_GEN == RPC_GEN_IMPLEMENTATION +/** Generating implementation interface on a target (calee) core. + * This will generate a set of functions named RPC_ which internally will decode + * RPC message and will then call appropriate API function. + */ +#undef RPC_FUNCTION_ +#define RPC_FUNCTION_( T, _type_, _name_, ...)\ +void RPC_##_name_(uint32_t *msg_ptr) {\ + IpcRpcMessage *message = (IpcRpcMessage *)msg_ptr;\ + T(message->result = ) (_type_) _name_ RPC_CALL_ARGS(__VA_ARGS__);\ +} + +#elif RPC_GEN == RPC_GEN_INITIALIZATION +/** This will generate an initialization code on target(calee) core that will register + * interface functions generated in the previous step as RPC message receivers. + */ +#undef RPC_FUNCTION_ +#define RPC_FUNCTION_( T, _type_, _name_, ...)\ + Cy_IPC_Pipe_RegisterCallback(CY_IPC_EP_RPCPIPE_ADDR, RPC_##_name_, rpc_counter++); + +#endif // RPC_GEN + +#undef __RPC_DEFS_H_BODY_END__ +#define __RPC_DEFS_H_BODY_END__ + diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/rtc_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/rtc_api.c new file mode 100644 index 0000000000..856fd852cf --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/rtc_api.c @@ -0,0 +1,182 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "device.h" +#include "rtc_api.h" +#include "mbed_error.h" +#include "mbed_mktime.h" +#include "cy_rtc.h" + + +#if DEVICE_RTC + +/* + * Since Mbed tests insist on supporting 1970 - 2106 years range + * and Cypress h/w supports only 2000 - 2099 years range, +* two backup registers are used to flag century correction. + */ + #define BR_LAST_YEAR_READ 14 + #define BR_CENTURY_CORRECTION 15 + +static int enabled = 0; + +static uint32_t rtc_read_convert_year(uint32_t short_year) +{ + uint32_t century = BACKUP->BREG[BR_CENTURY_CORRECTION]; + + if (BACKUP->BREG[BR_LAST_YEAR_READ] > short_year) { + BACKUP->BREG[BR_CENTURY_CORRECTION] = ++century; + } + BACKUP->BREG[BR_LAST_YEAR_READ] = short_year; + + return century * 100 + short_year; +} + +static uint32_t rtc_write_convert_year(uint32_t long_year) +{ + uint32_t short_year = long_year; + uint32_t century = short_year / 100; + short_year -= century * 100; + BACKUP->BREG[BR_CENTURY_CORRECTION] = century; + BACKUP->BREG[BR_LAST_YEAR_READ] = short_year; + return short_year; +} + +/** Initialize the RTC peripheral + * + */ +void rtc_init(void) +{ + static cy_stc_rtc_config_t init_val = { + /* Time information */ + .hrFormat = CY_RTC_24_HOURS, + .sec = 0, + .min = 0, + .hour = 0, + .dayOfWeek = CY_RTC_SATURDAY, + .date = 1, + .month = 1, + .year = 0 // 2000 - 30 == 1970 + }; + cy_stc_rtc_config_t cy_time; + + if (!enabled) { + // Setup power management callback. + // Setup century interrupt. + // Verify RTC time consistency. + Cy_RTC_GetDateAndTime(&cy_time); + if ( CY_RTC_IS_SEC_VALID(cy_time.sec) && + CY_RTC_IS_MIN_VALID(cy_time.min) && + CY_RTC_IS_HOUR_VALID(cy_time.hour) && + CY_RTC_IS_DOW_VALID(cy_time.dayOfWeek) && + CY_RTC_IS_MONTH_VALID(cy_time.month) && + CY_RTC_IS_YEAR_SHORT_VALID(cy_time.year) && + (cy_time.hrFormat == CY_RTC_24_HOURS)) { + enabled = 1; + } else { + // reinitialize + init_val.year = rtc_write_convert_year(1970); + if (Cy_RTC_Init(&init_val) == CY_RTC_SUCCESS) { + enabled = 1; + } + } + } +} + + +/** Deinitialize RTC + * + * TODO: The function is not used by rtc api in mbed-drivers. + */ +void rtc_free(void) +{ + +} + + +/** Get the RTC enable status + * + * @retval 0 disabled + * @retval 1 enabled + */ +int rtc_isenabled(void) +{ + return enabled; +} + + +/** Get the current time from the RTC peripheral + * + * @return The current time + */ +time_t rtc_read(void) +{ + cy_stc_rtc_config_t cy_time; + struct tm gmt; + time_t timestamp = 0; + uint32_t interrupt_state; + + // Since RTC reading function is unreliable when the RTC is busy with previous update + // we have to make sure it's not before calling it. + while (CY_RTC_BUSY == Cy_RTC_GetSyncStatus()) {} + + interrupt_state = Cy_SysLib_EnterCriticalSection(); + Cy_RTC_GetDateAndTime(&cy_time); + gmt.tm_sec = cy_time.sec; + gmt.tm_min = cy_time.min; + gmt.tm_hour = cy_time.hour; + gmt.tm_mday = cy_time.date; + gmt.tm_mon = cy_time.month - 1; + gmt.tm_year = rtc_read_convert_year(cy_time.year); + gmt.tm_isdst = 0; + Cy_SysLib_ExitCriticalSection(interrupt_state); + + _rtc_maketime(&gmt, ×tamp, RTC_4_YEAR_LEAP_YEAR_SUPPORT); + return timestamp; +} + +/** Set the current time to the RTC peripheral + * + * @param t The current time to be set + */ +void rtc_write(time_t t) +{ + cy_en_rtc_status_t status; + struct tm gmt; + + if ( _rtc_localtime(t, &gmt, RTC_4_YEAR_LEAP_YEAR_SUPPORT)) { + uint32_t year; + uint32_t interrupt_state; + // Make sure RTC is not busy and can be updated. + while (CY_RTC_BUSY == Cy_RTC_GetSyncStatus()) {} + + interrupt_state = Cy_SysLib_EnterCriticalSection(); + year = rtc_write_convert_year(gmt.tm_year); + status = Cy_RTC_SetDateAndTimeDirect(gmt.tm_sec, + gmt.tm_min, + gmt.tm_hour, + gmt.tm_mday, + gmt.tm_mon + 1, + year); + Cy_SysLib_ExitCriticalSection(interrupt_state); + if (status != CY_RTC_SUCCESS) { + error("Error 0x%x while setting RTC time.", status); + } + } +} + +#endif // DEVICE_RTC diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c new file mode 100644 index 0000000000..13f7617b4b --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c @@ -0,0 +1,892 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#if DEVICE_SERIAL + +#include + +#include "cmsis.h" +#include "mbed_assert.h" +#include "mbed_error.h" +#include "PeripheralPins.h" +#include "pinmap.h" +#include "serial_api.h" +#include "psoc6_utils.h" + +#include "drivers/peripheral/sysclk/cy_sysclk.h" +#include "drivers/peripheral/gpio/cy_gpio.h" +#include "drivers/peripheral/scb/cy_scb_uart.h" +#include "drivers/peripheral/sysint/cy_sysint.h" + +#define UART_OVERSAMPLE 12 +#define UART_DEFAULT_BAUDRATE 115200 +#define NUM_SERIAL_PORTS 8 +#define SERIAL_DEFAULT_IRQ_PRIORITY 3 + +typedef struct serial_s serial_obj_t; +#if DEVICE_SERIAL_ASYNCH +#define OBJ_P(in) (&(in->serial)) +#else +#define OBJ_P(in) (in) +#endif + +/* + * NOTE: Cypress PDL high level API implementation of USART doe not + * align well with Mbed interface for interrupt-driven serial I/O. + * For this reason only low level PDL API is used here. + */ + + +static const cy_stc_scb_uart_config_t default_uart_config = { + .uartMode = CY_SCB_UART_STANDARD, + .enableMutliProcessorMode = false, + .smartCardRetryOnNack = false, + .irdaInvertRx = false, + .irdaEnableLowPowerReceiver = false, + + .oversample = UART_OVERSAMPLE, + + .enableMsbFirst = false, + .dataWidth = 8UL, + .parity = CY_SCB_UART_PARITY_NONE, + .stopBits = CY_SCB_UART_STOP_BITS_1, + .enableInputFilter = false, + .breakWidth = 11UL, + .dropOnFrameError = false, + .dropOnParityError = false, + + .receiverAddress = 0x0UL, + .receiverAddressMask = 0x0UL, + .acceptAddrInFifo = false, + + .enableCts = false, + .ctsPolarity = CY_SCB_UART_ACTIVE_LOW, + .rtsRxFifoLevel = 20UL, + .rtsPolarity = CY_SCB_UART_ACTIVE_LOW, + + .rxFifoTriggerLevel = 0UL, + .rxFifoIntEnableMask = 0x0UL, + + .txFifoTriggerLevel = 0UL, + .txFifoIntEnableMask = 0x0UL +}; + +int stdio_uart_inited = false; +serial_t stdio_uart; + +typedef struct irq_info_s { + serial_obj_t *serial_obj; + uart_irq_handler handler; + uint32_t id_arg; + IRQn_Type irqn; +#if defined (TARGET_MCU_PSOC6_M0) + cy_en_intr_t cm0p_irq_src; +#endif +} irq_info_t; + +static irq_info_t irq_info[NUM_SERIAL_PORTS] = { + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn}, + {NULL, NULL, 0, unconnected_IRQn} +}; + + +static void serial_irq_dispatcher(uint32_t serial_id) +{ + MBED_ASSERT(serial_id < NUM_SERIAL_PORTS); + irq_info_t *info = &irq_info[serial_id]; + serial_obj_t *obj = info->serial_obj; + MBED_ASSERT(obj); + +#if DEVICE_SERIAL_ASYNCH + if (obj->async_handler) { + obj->async_handler(); + return; + } +#endif + if (Cy_SCB_GetRxInterruptStatusMasked(obj->base) & CY_SCB_RX_INTR_NOT_EMPTY) { + info->handler(info->id_arg, RxIrq); + Cy_SCB_ClearRxInterrupt(obj->base, CY_SCB_RX_INTR_NOT_EMPTY); + } + + if (Cy_SCB_GetTxInterruptStatusMasked(obj->base) & (CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE)) { + info->handler(info->id_arg, TxIrq); + } +} + +static void serial_irq_dispatcher_uart0(void) +{ + serial_irq_dispatcher(0); +} + +static void serial_irq_dispatcher_uart1(void) +{ + serial_irq_dispatcher(1); +} + +static void serial_irq_dispatcher_uart2(void) +{ + serial_irq_dispatcher(2); +} + +static void serial_irq_dispatcher_uart3(void) +{ + serial_irq_dispatcher(3); +} + +static void serial_irq_dispatcher_uart4(void) +{ + serial_irq_dispatcher(4); +} + +static void serial_irq_dispatcher_uart5(void) +{ + serial_irq_dispatcher(5); +} + +void serial_irq_dispatcher_uart6(void) +{ + serial_irq_dispatcher(6); +} + +static void serial_irq_dispatcher_uart7(void) +{ + serial_irq_dispatcher(7); +} + + +static void (*irq_dispatcher_table[])(void) = { + serial_irq_dispatcher_uart0, + serial_irq_dispatcher_uart1, + serial_irq_dispatcher_uart2, + serial_irq_dispatcher_uart3, + serial_irq_dispatcher_uart4, + serial_irq_dispatcher_uart5, + serial_irq_dispatcher_uart6, + serial_irq_dispatcher_uart7 +}; + + +static IRQn_Type serial_irq_allocate_channel(serial_obj_t *obj) +{ +#if defined (TARGET_MCU_PSOC6_M0) + irq_info[obj->serial_id].cm0p_irq_src = scb_0_interrupt_IRQn + obj->serial_id; + return cy_m0_nvic_allocate_channel(CY_SERIAL_IRQN_ID + obj->serial_id); +#else + return (IRQn_Type)(scb_0_interrupt_IRQn + obj->serial_id); +#endif // M0 +} + +static void serial_irq_release_channel(IRQn_Type channel, uint32_t serial_id) +{ +#if defined (TARGET_MCU_PSOC6_M0) + cy_m0_nvic_release_channel(channel, CY_SERIAL_IRQN_ID + serial_id); +#endif //M0 +} + +static int serial_irq_setup_channel(serial_obj_t *obj) +{ + cy_stc_sysint_t irq_config; + irq_info_t *info = &irq_info[obj->serial_id]; + + if (info->irqn == unconnected_IRQn) { + IRQn_Type irqn = serial_irq_allocate_channel(obj); + if (irqn < 0) { + return (-1); + } + // Configure NVIC + irq_config.intrPriority = SERIAL_DEFAULT_IRQ_PRIORITY; + irq_config.intrSrc = irqn; +#if defined (TARGET_MCU_PSOC6_M0) + irq_config.cm0pSrc = info->cm0p_irq_src; +#endif + if (Cy_SysInt_Init(&irq_config, irq_dispatcher_table[obj->serial_id]) != CY_SYSINT_SUCCESS) { + return(-1); + } + + info->irqn = irqn; + info->serial_obj = obj; + NVIC_EnableIRQ(irqn); + } + return 0; +} + +/** + * Calculates fractional divider value. + */ +static uint32_t divider_value(uint32_t frequency, uint32_t frac_bits) +{ + /* UARTs use peripheral clock */ + return ((CY_CLK_PERICLK_FREQ_HZ * (1 << frac_bits)) + (frequency / 2)) / frequency; +} + +static cy_en_sysclk_status_t serial_init_clock(serial_obj_t *obj, uint32_t baudrate) +{ + cy_en_sysclk_status_t status = CY_SYSCLK_BAD_PARAM; + + if (obj->div_num == CY_INVALID_DIVIDER) { + uint32_t divider_num = cy_clk_allocate_divider(CY_SYSCLK_DIV_16_5_BIT); + + if (divider_num < PERI_DIV_16_5_NR) { + /* Assign fractional divider. */ + status = Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_16_5_BIT, divider_num); + if (status == CY_SYSCLK_SUCCESS) { + obj->div_type = CY_SYSCLK_DIV_16_5_BIT; + obj->div_num = divider_num; + } + } else { + // Try 16-bit divider. + divider_num = cy_clk_allocate_divider(CY_SYSCLK_DIV_16_BIT); + if (divider_num < PERI_DIV_16_NR) { + /* Assign 16-bit divider. */ + status = Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_16_BIT, divider_num); + if (status == CY_SYSCLK_SUCCESS) { + obj->div_type = CY_SYSCLK_DIV_16_BIT; + obj->div_num = divider_num; + } + } else { + error("Serial: cannot assign clock divider."); + } + } + } else { + status = CY_SYSCLK_SUCCESS; + } + + if (status == CY_SYSCLK_SUCCESS) { + /* Set baud rate */ + if (obj->div_type == CY_SYSCLK_DIV_16_5_BIT) { + Cy_SysClk_PeriphDisableDivider(CY_SYSCLK_DIV_16_5_BIT, obj->div_num); + uint32_t divider = divider_value(baudrate * UART_OVERSAMPLE, 5); + status = Cy_SysClk_PeriphSetFracDivider(CY_SYSCLK_DIV_16_5_BIT, + obj->div_num, + (divider >> 5) - 1, // integral part + divider & 0x1F); // fractional part + Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_16_5_BIT, obj->div_num); + } else if (obj->div_type == CY_SYSCLK_DIV_16_BIT) { + Cy_SysClk_PeriphDisableDivider(CY_SYSCLK_DIV_16_BIT, obj->div_num); + status = Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_16_BIT, + obj->div_num, + divider_value(baudrate * UART_OVERSAMPLE, 0)); + Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_16_BIT, obj->div_num); + } + } + return status; +} + +/** + * Initializes i/o pins for UART tx/rx. + */ +static void serial_init_pins(serial_obj_t *obj) +{ + int tx_function = pinmap_function(obj->pin_tx, PinMap_UART_TX); + int rx_function = pinmap_function(obj->pin_rx, PinMap_UART_RX); + if (cy_reserve_io_pin(obj->pin_tx) || cy_reserve_io_pin(obj->pin_rx)) { + error("Serial TX/RX pin reservation conflict."); + } + pin_function(obj->pin_tx, tx_function); + pin_function(obj->pin_rx, rx_function); +} + +/** + * Initializes i/o pins for UART flow control. + */ +static void serial_init_flow_pins(serial_obj_t *obj) +{ + if (obj->pin_rts != NC) { + int rts_function = pinmap_function(obj->pin_rts, PinMap_UART_RTS); + if (cy_reserve_io_pin(obj->pin_rts)) { + error("Serial RTS pin reservation conflict."); + } + pin_function(obj->pin_rts, rts_function); + } + + if (obj->pin_cts != NC) { + int cts_function = pinmap_function(obj->pin_cts, PinMap_UART_CTS); + if (cy_reserve_io_pin(obj->pin_cts)) { + error("Serial CTS pin reservation conflict."); + } + pin_function(obj->pin_cts, cts_function); + } +} + + +/** + * Initializes and enables UART/SCB. + */ +static void serial_init_peripheral(serial_obj_t *obj) +{ + cy_stc_scb_uart_config_t uart_config = default_uart_config; + + uart_config.dataWidth = obj->data_width; + uart_config.parity = obj->parity; + uart_config.stopBits = obj->stop_bits; + uart_config.enableCts = (obj->pin_cts != NC); + + Cy_SCB_UART_Init(obj->base, &uart_config, NULL); + Cy_SCB_UART_Enable(obj->base); +} + +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER +static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *params) +{ + serial_obj_t *obj = (serial_obj_t *)params->context; + cy_en_syspm_status_t status = CY_SYSPM_FAIL; + + switch (params->mode) { + case CY_SYSPM_CHECK_READY: + /* If all data elements are transmitted from the TX FIFO and + * shifter and the RX FIFO is empty: the UART is ready to enter + * Deep Sleep mode. + */ + if (Cy_SCB_UART_IsTxComplete(obj->base)) { + if (0UL == Cy_SCB_UART_GetNumInRxFifo(obj->base)) { + /* Disable the UART. The transmitter stops driving the + * lines and the receiver stops receiving data until + * the UART is enabled. + * This happens when the device failed to enter Deep + * Sleep or it is awaken from Deep Sleep mode. + */ + Cy_SCB_UART_Disable(obj->base, NULL); + status = CY_SYSPM_SUCCESS; + } + } + break; + + + case CY_SYSPM_CHECK_FAIL: + /* Enable the UART to operate */ + Cy_SCB_UART_Enable(obj->base); + status = CY_SYSPM_SUCCESS; + break; + + case CY_SYSPM_BEFORE_TRANSITION: + status = CY_SYSPM_SUCCESS; + break; + + case CY_SYSPM_AFTER_TRANSITION: + /* Enable the UART to operate */ + Cy_SCB_UART_Enable(obj->base); + status = CY_SYSPM_SUCCESS; + break; + + default: + break; + } + return status; +} +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + +void serial_init(serial_t *obj_in, PinName tx, PinName rx) +{ + serial_obj_t *obj = OBJ_P(obj_in); + bool is_stdio = (tx == CY_STDIO_UART_TX) || (rx == CY_STDIO_UART_RX); + + if (is_stdio && stdio_uart_inited) { + memcpy(obj_in, &stdio_uart, sizeof(serial_t)); + return; + } + { + uint32_t uart = pinmap_peripheral(tx, PinMap_UART_TX); + uart = pinmap_merge(uart, pinmap_peripheral(rx, PinMap_UART_RX)); + if (uart != (uint32_t)NC) { + obj->base = (CySCB_Type*)uart; + obj->serial_id = ((UARTName)uart - UART_0) / (UART_1 - UART_0); + obj->pin_tx = tx; + obj->pin_rx = rx; + obj->clock = CY_PIN_CLOCK(pinmap_function(tx, PinMap_UART_TX)); + obj->div_num = CY_INVALID_DIVIDER; + obj->data_width = 8; + obj->stop_bits = CY_SCB_UART_STOP_BITS_1; + obj->parity = CY_SCB_UART_PARITY_NONE; + obj->pin_rts = NC; + obj->pin_cts = NC; + + serial_init_clock(obj, UART_DEFAULT_BAUDRATE); + serial_init_peripheral(obj); + //Cy_GPIO_Write(Cy_GPIO_PortToAddr(CY_PORT(P13_6)), CY_PIN(P13_6), 1); + serial_init_pins(obj); + //Cy_GPIO_Write(Cy_GPIO_PortToAddr(CY_PORT(P13_6)), CY_PIN(P13_6), 0); +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + obj->pm_callback_handler.callback = serial_pm_callback; + obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP; + obj->pm_callback_handler.skipMode = 0; + obj->pm_callback_handler.callbackParams = &obj->pm_callback_params; + obj->pm_callback_params.base = obj->base; + obj->pm_callback_params.context = obj; + if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) { + error("PM callback registration failed!"); + } +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + if (is_stdio) { + memcpy(&stdio_uart, obj_in, sizeof(serial_t)); + stdio_uart_inited = true; + } + } else { + error("Serial pinout mismatch. Requested pins Rx and Tx can't be used for the same Serial communication."); + } + } +} + +void serial_baud(serial_t *obj_in, int baudrate) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + Cy_SCB_UART_Disable(obj->base, NULL); + serial_init_clock(obj, baudrate); + Cy_SCB_UART_Enable(obj->base); +} + +void serial_format(serial_t *obj_in, int data_bits, SerialParity parity, int stop_bits) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + if ((data_bits >= 5) && (data_bits <= 9)) { + obj->data_width = data_bits; + } + + switch (parity) { + case ParityNone: + obj->parity = CY_SCB_UART_PARITY_NONE; + break; + case ParityOdd: + obj->parity = CY_SCB_UART_PARITY_ODD; + break; + case ParityEven: + obj->parity = CY_SCB_UART_PARITY_EVEN; + break; + case ParityForced1: + case ParityForced0: + MBED_ASSERT("Serial parity mode not supported!"); + break; + } + + switch (stop_bits) { + case 1: + obj->stop_bits = CY_SCB_UART_STOP_BITS_1; + break; + case 2: + obj->stop_bits = CY_SCB_UART_STOP_BITS_2; + break; + case 3: + obj->stop_bits = CY_SCB_UART_STOP_BITS_3; + break; + case 4: + obj->stop_bits = CY_SCB_UART_STOP_BITS_4; + break; + } + + Cy_SCB_UART_Disable(obj->base, NULL); + serial_init_peripheral(obj); +} + + +void serial_putc(serial_t *obj_in, int c) +{ + serial_obj_t *obj = OBJ_P(obj_in); + while (!serial_writable(obj_in)) { + // empty + } + Cy_SCB_UART_Put(obj->base, c); +} + +int serial_getc(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + while (!serial_readable(obj_in)) { + // empty + } + return Cy_SCB_UART_Get(obj->base); +} + +int serial_readable(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + return Cy_SCB_GetNumInRxFifo(obj->base) != 0; +} + +int serial_writable(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + return Cy_SCB_GetNumInTxFifo(obj->base) != Cy_SCB_GetFifoSize(obj->base); +} + +/** Clear the serial peripheral + * + * @param obj The serial object + */ +void serial_clear(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + Cy_SCB_UART_Disable(obj->base, NULL); + Cy_SCB_ClearTxFifo(obj->base); + Cy_SCB_ClearRxFifo(obj->base); + serial_init_peripheral(obj); +} + +/** Set the break + * + * @param obj The serial object + */ +void serial_break_set(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + /* Cypress SCB does not support transmitting break directly. + * We emulate functionality by switching TX pin to GPIO mode. + */ + GPIO_PRT_Type *port_tx = Cy_GPIO_PortToAddr(CY_PORT(obj->pin_tx)); + Cy_GPIO_Pin_FastInit(port_tx, CY_PIN(obj->pin_tx), CY_GPIO_DM_STRONG_IN_OFF, 0, HSIOM_SEL_GPIO); + Cy_GPIO_Write(port_tx, CY_PIN(obj->pin_tx), 0); +} + +/** Clear the break + * + * @param obj The serial object + */ +void serial_break_clear(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + /* Connect TX pin back to SCB, see a comment in serial_break_set() above */ + GPIO_PRT_Type *port_tx = Cy_GPIO_PortToAddr(CY_PORT(obj->pin_tx)); + int tx_function = pinmap_function(obj->pin_tx, PinMap_UART_TX); + Cy_GPIO_Pin_FastInit(port_tx, CY_PIN(obj->pin_tx), CY_GPIO_DM_STRONG_IN_OFF, 0, CY_PIN_HSIOM(tx_function)); +} + +/** Configure the serial for the flow control. It sets flow control in the hardware + * if a serial peripheral supports it, otherwise software emulation is used. + * + * @param obj The serial object + * @param type The type of the flow control. Look at the available FlowControl types. + * @param rxflow The TX pin name + * @param txflow The RX pin name + */ +void serial_set_flow_control(serial_t *obj_in, FlowControl type, PinName rxflow, PinName txflow) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + Cy_SCB_UART_Disable(obj->base, NULL); + + switch (type) { + case FlowControlNone: + obj->pin_rts = NC; + obj->pin_cts = NC; + break; + case FlowControlRTS: + obj->pin_rts = rxflow; + obj->pin_cts = NC; + break; + case FlowControlCTS: + obj->pin_rts = NC; + obj->pin_cts = txflow; + break; + case FlowControlRTSCTS: + obj->pin_rts = rxflow; + obj->pin_cts = txflow; + break; + } + + serial_init_peripheral(obj); + serial_init_flow_pins(obj); +} + +#if DEVICE_SERIAL_ASYNCH + +void serial_irq_handler(serial_t *obj_in, uart_irq_handler handler, uint32_t id) +{ + serial_obj_t *obj = OBJ_P(obj_in); + irq_info_t *info = &irq_info[obj->serial_id]; + + if (info->irqn != unconnected_IRQn) { + NVIC_DisableIRQ(info->irqn); + } + info->handler = handler; + info->id_arg = id; + serial_irq_setup_channel(obj); +} + +void serial_irq_set(serial_t *obj_in, SerialIrq irq, uint32_t enable) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + switch (irq) { + case RxIrq: + if (enable) { + Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_RX_INTR_NOT_EMPTY); + } else { + Cy_SCB_SetRxInterruptMask(obj->base, 0); + } + break; + case TxIrq: + if (enable) { + Cy_SCB_SetTxInterruptMask(obj->base, CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE); + } else { + Cy_SCB_SetTxInterruptMask(obj->base, 0); + } + break; + } +} + +static void serial_finish_tx_asynch(serial_obj_t *obj) +{ + Cy_SCB_SetTxInterruptMask(obj->base, 0); + obj->tx_pending = false; +} + +static void serial_finish_rx_asynch(serial_obj_t *obj) +{ + Cy_SCB_SetRxInterruptMask(obj->base, 0); + obj->rx_pending = false; +} + + +/** Begin asynchronous TX transfer. The used buffer is specified in the serial object, + * tx_buff + * + * @param obj The serial object + * @param tx The transmit buffer + * @param tx_length The number of bytes to transmit + * @param tx_width Deprecated argument + * @param handler The serial handler + * @param event The logical OR of events to be registered + * @param hint A suggestion for how to use DMA with this transfer + * @return Returns number of data transfered, otherwise returns 0 + */ +int serial_tx_asynch(serial_t *obj_in, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint) +{ + serial_obj_t *obj = OBJ_P(obj_in); + const uint8_t *p_buf = tx; + + (void)tx_width; // Obsolete argument + (void)hint; // At the moment we do not support DAM transfers, so this parameter gets ignored. + + if (obj->tx_pending) { + return 0; + } + + obj->async_handler = (cy_israddress)handler; + if (serial_irq_setup_channel(obj) < 0) { + return 0; + } + + // Write as much as possible into the FIFO first. + while ((tx_length > 0) && Cy_SCB_UART_Put(obj->base, *p_buf)) { + ++p_buf; + --tx_length; + } + + if (tx_length > 0) { + obj->tx_events = event; + obj_in->tx_buff.buffer = (void *)p_buf; + obj_in->tx_buff.length = tx_length; + obj_in->tx_buff.pos = 0; + obj->tx_pending = true; + // Enable interrupts to complete transmission. + Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE); + + } else { + // Enable interrupt to signal completing of the transmission. + Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_UART_TX_DONE); + } + return tx_length; +} + +/** Begin asynchronous RX transfer (enable interrupt for data collecting) + * The used buffer is specified in the serial object - rx_buff + * + * @param obj The serial object + * @param rx The receive buffer + * @param rx_length The number of bytes to receive + * @param rx_width Deprecated argument + * @param handler The serial handler + * @param event The logical OR of events to be registered + * @param handler The serial handler + * @param char_match A character in range 0-254 to be matched + * @param hint A suggestion for how to use DMA with this transfer + */ +void serial_rx_asynch(serial_t *obj_in, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + (void)rx_width; // Obsolete argument + (void)hint; // At the moment we do not support DAM transfers, so this parameter gets ignored. + + if (obj->rx_pending || (rx_length == 0)) { + return; + } + + obj_in->char_match = char_match; + obj_in->char_found = false; + obj->rx_events = event; + obj_in->rx_buff.buffer = rx; + obj_in->rx_buff.length = rx_length; + obj_in->rx_buff.pos = 0; + obj->async_handler = (cy_israddress)handler; + if (serial_irq_setup_channel(obj) < 0) { + return; + } + obj->rx_pending = true; + // Enable interrupts to start receiving. + Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_UART_RX_INTR_MASK & ~CY_SCB_RX_INTR_UART_BREAK_DETECT); +} + +/** Attempts to determine if the serial peripheral is already in use for TX + * + * @param obj The serial object + * @return Non-zero if the RX transaction is ongoing, 0 otherwise + */ +uint8_t serial_tx_active(serial_t *obj) +{ + return obj->serial.tx_pending; +} + +/** Attempts to determine if the serial peripheral is already in use for RX + * + * @param obj The serial object + * @return Non-zero if the RX transaction is ongoing, 0 otherwise + */ +uint8_t serial_rx_active(serial_t *obj) +{ + return obj->serial.rx_pending; +} + +/** The asynchronous TX and RX handler. + * + * @param obj The serial object + * @return Returns event flags if an RX transfer termination condition was met; otherwise returns 0 + */ +int serial_irq_handler_asynch(serial_t *obj_in) +{ + uint32_t cur_events = 0; + uint32_t tx_status; + uint32_t rx_status; + + serial_obj_t *obj = OBJ_P(obj_in); + + rx_status = Cy_SCB_GetRxInterruptStatusMasked(obj->base); + + tx_status = Cy_SCB_GetTxInterruptStatusMasked(obj->base); + + + if (tx_status & CY_SCB_TX_INTR_LEVEL) { + // FIFO has space available for more TX + uint8_t *ptr = obj_in->tx_buff.buffer; + ptr += obj_in->tx_buff.pos; + while ((obj_in->tx_buff.pos < obj_in->tx_buff.length) && + Cy_SCB_UART_Put(obj->base, *ptr)) { + ++ptr; + ++(obj_in->tx_buff.pos); + } + if (obj_in->tx_buff.pos == obj_in->tx_buff.length) { + // No more bytes to follow; check to see if we need to signal completion. + if (obj->tx_events & SERIAL_EVENT_TX_COMPLETE) { + // Disable FIFO interrupt as there are no more bytes to follow. + Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_UART_TX_DONE); + } else { + // Nothing more to do, mark end of transmission. + serial_finish_tx_asynch(obj); + } + } + } + + if (tx_status & CY_SCB_TX_INTR_UART_DONE) { + // Mark end of the transmission. + serial_finish_tx_asynch(obj); + cur_events |= SERIAL_EVENT_TX_COMPLETE & obj->tx_events; + } + + Cy_SCB_ClearTxInterrupt(obj->base, tx_status); + + if (rx_status & CY_SCB_RX_INTR_OVERFLOW) { + cur_events |= SERIAL_EVENT_RX_OVERRUN_ERROR & obj->rx_events; + } + + if (rx_status & CY_SCB_RX_INTR_UART_FRAME_ERROR) { + cur_events |= SERIAL_EVENT_RX_FRAMING_ERROR & obj->rx_events; + } + + if (rx_status & CY_SCB_RX_INTR_UART_PARITY_ERROR) { + cur_events |= SERIAL_EVENT_RX_PARITY_ERROR & obj->rx_events; + } + + if (rx_status & CY_SCB_RX_INTR_LEVEL) { + uint8_t *ptr = obj_in->rx_buff.buffer; + ptr += obj_in->rx_buff.pos; + while (obj_in->rx_buff.pos < obj_in->rx_buff.length) { + uint32_t c = Cy_SCB_UART_Get(obj->base); + if (c == CY_SCB_UART_RX_NO_DATA) { + break; + } + *ptr++ = (uint8_t)c; + ++(obj_in->rx_buff.pos); + // Check for character match condition. + if (obj_in->char_match != SERIAL_RESERVED_CHAR_MATCH) { + if (c == obj_in->char_match) { + obj_in->char_found = true; + cur_events |= SERIAL_EVENT_RX_CHARACTER_MATCH & obj->rx_events; + // Clamp RX. + obj_in->rx_buff.length = obj_in->rx_buff.pos; + break; + } + } + } + } + + if (obj_in->rx_buff.pos == obj_in->rx_buff.length) { + serial_finish_rx_asynch(obj); + } + + Cy_SCB_ClearRxInterrupt(obj->base, rx_status); + + return cur_events; +} + +/** Abort the ongoing TX transaction. It disables the enabled interrupt for TX and + * flushes the TX hardware buffer if TX FIFO is used + * + * @param obj The serial object + */ +void serial_tx_abort_asynch(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + serial_finish_tx_asynch(obj); + Cy_SCB_UART_ClearTxFifo(obj->base); +} + +/** Abort the ongoing RX transaction. It disables the enabled interrupt for RX and + * flushes the RX hardware buffer if RX FIFO is used + * + * @param obj The serial object + */ +void serial_rx_abort_asynch(serial_t *obj_in) +{ + serial_obj_t *obj = OBJ_P(obj_in); + + serial_finish_rx_asynch(obj); + Cy_SCB_UART_ClearRxFifo(obj->base); +} + +#endif // DEVICE_SERIAL_ASYNCH + +#endif // DEVICE_SERIAL diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/sleep_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/sleep_api.c new file mode 100644 index 0000000000..cf637f03fa --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/sleep_api.c @@ -0,0 +1,69 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "cmsis.h" +#include "device.h" +#include "cy_syspm.h" + +#ifdef DEVICE_SLEEP + +/** Send the microcontroller to sleep + * + * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the + * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates + * dynamic power used by the processor, memory systems and buses. The processor, peripheral and + * memory state are maintained, and the peripherals continue to work and can generate interrupts. + * + * The processor can be woken up by any internal peripheral interrupt or external pin interrupt. + * + * @note + * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. + * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be + * able to access the LocalFileSystem + */ +void hal_sleep(void) +{ + Cy_SysPm_Sleep(CY_SYSPM_WAIT_FOR_INTERRUPT); +} + +/** Send the microcontroller to deep sleep + * + * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode + * has the same sleep features as sleep plus it powers down peripherals and clocks. All state + * is still maintained. + * + * The processor can only be woken up by an external interrupt on a pin or a watchdog timer. + * + * @note + * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. + * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be + * able to access the LocalFileSystem + */ +void hal_deepsleep(void) +{ +#if DEVICE_LPTICKER + if(CY_SYSPM_SUCCESS == Cy_SysPm_DeepSleep(CY_SYSPM_WAIT_FOR_INTERRUPT)) { + // Have to make sure PLL clock is restored before continuing. + // FLL clock is not used in basic configuration. + while(!Cy_SysClk_PllLocked(1)) { + // Just wait here. + } + } +#endif +} + +#endif // DEVICE_SLEEP diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/spi_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/spi_api.c new file mode 100644 index 0000000000..80e9217e2c --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/spi_api.c @@ -0,0 +1,648 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "cmsis.h" +#include "mbed_assert.h" +#include "mbed_error.h" +#include "mbed_debug.h" +#include "PeripheralPins.h" +#include "pinmap.h" +#include "spi_api.h" +#include "psoc6_utils.h" + +#include "drivers/peripheral/sysclk/cy_sysclk.h" +#include "drivers/peripheral/gpio/cy_gpio.h" +#include "drivers/peripheral/scb/cy_scb_spi.h" +#include "drivers/peripheral/sysint/cy_sysint.h" + +#define SPI_DEFAULT_SPEED 100000 +#define NUM_SPI_PORTS 8 +#define SPI_DEFAULT_IRQ_PRIORITY 3 +#define SPI_OVERSAMPLE 4 /* 4..16 */ +// Default timeout in milliseconds. +#define SPI_DEFAULT_TIMEOUT 1000 + +#define PENDING_NONE 0 +#define PENDING_RX 1 +#define PENDING_TX 2 +#define PENDING_TX_RX 3 + + + +static const cy_stc_scb_spi_config_t default_spi_config = { + .spiMode = CY_SCB_SPI_MASTER, + .subMode = CY_SCB_SPI_MOTOROLA, + .sclkMode = CY_SCB_SPI_CPHA0_CPOL0, + .oversample = SPI_OVERSAMPLE, + .rxDataWidth = 8, + .txDataWidth = 8, + .enableMsbFirst = true, + .enableFreeRunSclk = false, + .enableInputFilter = false, + .enableMisoLateSample = false, + .enableTransferSeperation = false, + .enableWakeFromSleep = false, + .ssPolarity = CY_SCB_SPI_ACTIVE_LOW, + .rxFifoTriggerLevel = 0, + .rxFifoIntEnableMask = 0, + .txFifoTriggerLevel = 0, + .txFifoIntEnableMask = 0, + .masterSlaveIntEnableMask = 0 +}; + + + +typedef struct spi_s spi_obj_t; + +#if DEVICE_SPI_ASYNCH +#define OBJ_P(in) (&(in->spi)) +#else +#define OBJ_P(in) (in) +#endif + + +#if DEVICE_SPI_ASYNCH + +static IRQn_Type spi_irq_allocate_channel(spi_obj_t *obj) +{ +#if defined (TARGET_MCU_PSOC6_M0) + obj->cm0p_irq_src = scb_0_interrupt_IRQn + obj->spi_id; + return cy_m0_nvic_allocate_channel(CY_SERIAL_IRQN_ID + obj->spi_id); +#else + return (IRQn_Type)(ioss_interrupts_gpio_0_IRQn + obj->spi_id); +#endif // M0 +} + +static void spi_irq_release_channel(IRQn_Type channel, uint32_t spi_id) +{ +#if defined (TARGET_MCU_PSOC6_M0) + cy_m0_nvic_release_channel(channel, CY_SERIAL_IRQN_ID + spi_id); +#endif //M0 +} + +static int spi_irq_setup_channel(spi_obj_t *obj) +{ + cy_stc_sysint_t irq_config; + + if (obj->irqn == unconnected_IRQn) { + IRQn_Type irqn = spi_irq_allocate_channel(obj); + if (irqn < 0) { + return (-1); + } + // Configure NVIC + irq_config.intrPriority = SPI_DEFAULT_IRQ_PRIORITY; + irq_config.intrSrc = irqn; +#if defined (TARGET_MCU_PSOC6_M0) + irq_config.cm0pSrc = obj->cm0p_irq_src; +#endif + if (Cy_SysInt_Init(&irq_config, (cy_israddress)(obj->handler)) != CY_SYSINT_SUCCESS) { + return(-1); + } + + obj->irqn = irqn; + NVIC_EnableIRQ(irqn); + } + return 0; +} + +#endif // DEVICE_SPI_ASYNCH + +static int allocate_divider(spi_obj_t *obj) +{ + if (obj->div_num == CY_INVALID_DIVIDER) { + obj->div_type = CY_SYSCLK_DIV_16_BIT; + obj->div_num = cy_clk_allocate_divider(CY_SYSCLK_DIV_16_BIT); + } + return (obj->div_num == CY_INVALID_DIVIDER)? -1 : 0; +} + + +/** Initializes spi clock for the required speed + */ +static cy_en_sysclk_status_t spi_init_clock(spi_obj_t *obj, uint32_t frequency) +{ + cy_en_sysclk_status_t status = CY_SYSCLK_INVALID_STATE; + uint32_t div_value; + + if (obj->div_num == CY_INVALID_DIVIDER) { + if (allocate_divider(obj) < 0) { + error("spi: cannot allocate clock divider."); + return CY_SYSCLK_INVALID_STATE; + } + } + + // Set up proper frequency; round up the divider so the frequency is not higher than specified. + div_value = (CY_CLK_PERICLK_FREQ_HZ + frequency *(SPI_OVERSAMPLE - 1)) / frequency / SPI_OVERSAMPLE; + obj->clk_frequency = CY_CLK_PERICLK_FREQ_HZ / div_value / SPI_OVERSAMPLE; + Cy_SysClk_PeriphDisableDivider(obj->div_type, obj->div_num); + if (Cy_SysClk_PeriphSetDivider(obj->div_type, obj->div_num, div_value) != CY_SYSCLK_SUCCESS) { + obj->div_num = CY_INVALID_DIVIDER; + } + Cy_SysClk_PeriphEnableDivider(obj->div_type, obj->div_num); + + if (obj->div_num != CY_INVALID_DIVIDER) { + status = Cy_SysClk_PeriphAssignDivider(obj->clock, obj->div_type, obj->div_num); + if (status != CY_SYSCLK_SUCCESS) { + error("spi: cannot assign clock divider."); + return status; + } + } + return CY_SYSCLK_SUCCESS; +} + +/** + * Initializes i/o pins for spi. + */ +static void spi_init_pins(spi_obj_t *obj) +{ + if (cy_reserve_io_pin(obj->pin_sclk) || + cy_reserve_io_pin(obj->pin_mosi) || + cy_reserve_io_pin(obj->pin_miso) || + cy_reserve_io_pin(obj->pin_ssel)) { + error("SPI pin reservation conflict."); + } + pin_function(obj->pin_sclk, pinmap_function(obj->pin_sclk, PinMap_SPI_SCLK)); + pin_function(obj->pin_mosi, pinmap_function(obj->pin_mosi, PinMap_SPI_MOSI)); + pin_function(obj->pin_miso, pinmap_function(obj->pin_miso, PinMap_SPI_MISO)); + pin_function(obj->pin_ssel, pinmap_function(obj->pin_ssel, PinMap_SPI_SSEL)); + // Pin configuration in PinMap defaults to Master mode; revert for Slave. + if (obj->ms_mode == CY_SCB_SPI_SLAVE) { + pin_mode(obj->pin_sclk, PullNone); + pin_mode(obj->pin_mosi, PullNone); + pin_mode(obj->pin_miso, PushPull); + pin_mode(obj->pin_ssel, PullNone); + } +} + +/** + * Initializes and enables SPI/SCB. + */ +static void spi_init_peripheral(spi_obj_t *obj) +{ + cy_stc_scb_spi_config_t spi_config = default_spi_config; + spi_config.spiMode = obj->ms_mode; + spi_config.sclkMode = obj->clk_mode; + spi_config.rxDataWidth = obj->data_bits; + spi_config.txDataWidth = obj->data_bits; + Cy_SCB_SPI_Init(obj->base, &spi_config, &obj->context); + Cy_SCB_SPI_Enable(obj->base); +} + + +/** Callback function to handle into and out of deep sleep state transitions. + * + */ +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER +static cy_en_syspm_status_t spi_pm_callback(cy_stc_syspm_callback_params_t *callback_params) +{ + cy_stc_syspm_callback_params_t params = *callback_params; + spi_obj_t *obj = (spi_obj_t *)params.context; + params.context = &obj->context; + + return Cy_SCB_SPI_DeepSleepCallback(¶ms); +} +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + + +/** Initialize the SPI peripheral. It sets the default parameters for SPI + * peripheral, and configures its specified pins. + * + * @param obj The SPI object + * @param mosi The mosi pin + * @param miso The miso pin + * @param sclk The sclk pin + * @param ssel The ssel pin + */ +void spi_init(spi_t *obj_in, PinName mosi, PinName miso, PinName sclk, PinName ssel) +{ + spi_obj_t *obj = OBJ_P(obj_in); + uint32_t spi = (uint32_t)NC; + en_clk_dst_t clock; + + if (mosi != NC) { + spi = pinmap_merge(spi, pinmap_peripheral(mosi, PinMap_SPI_MOSI)); + clock = CY_PIN_CLOCK(pinmap_function(mosi, PinMap_SPI_MOSI)); + } + if (miso != NC) { + spi = pinmap_merge(spi, pinmap_peripheral(miso, PinMap_SPI_MISO)); + clock = CY_PIN_CLOCK(pinmap_function(miso, PinMap_SPI_MISO)); + } + if (sclk != NC) { + spi = pinmap_merge(spi, pinmap_peripheral(sclk, PinMap_SPI_SCLK)); + clock = CY_PIN_CLOCK(pinmap_function(sclk, PinMap_SPI_SCLK)); + } + if (ssel != NC) { + spi = pinmap_merge(spi, pinmap_peripheral(ssel, PinMap_SPI_SSEL)); + clock = CY_PIN_CLOCK(pinmap_function(ssel, PinMap_SPI_SSEL)); + } + + if (spi != (uint32_t)NC) { + obj->base = (CySCB_Type*)spi; + obj->spi_id = ((SPIName)spi - SPI_0) / (SPI_1 - SPI_0); + obj->pin_mosi = mosi; + obj->pin_miso = miso; + obj->pin_sclk = sclk; + obj->pin_ssel = ssel; + obj->data_bits = 8; + obj->clock = clock; + obj->div_num = CY_INVALID_DIVIDER; + obj->ms_mode = CY_SCB_SPI_MASTER; +#if DEVICE_SPI_ASYNCH + obj->pending = PENDING_NONE; + obj->events = 0; + obj->tx_buffer = NULL; + obj->tx_buffer_size = 0; + obj->rx_buffer = NULL; + obj->rx_buffer_size = 0; +#endif // DEVICE_SPI_ASYNCH + spi_init_clock(obj, SPI_DEFAULT_SPEED); + spi_init_pins(obj); + spi_init_peripheral(obj); +#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + obj->pm_callback_handler.callback = spi_pm_callback; + obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP; + obj->pm_callback_handler.skipMode = 0; + obj->pm_callback_handler.callbackParams = &obj->pm_callback_params; + obj->pm_callback_params.base = obj->base; + obj->pm_callback_params.context = obj; + if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) { + error("PM callback registration failed!"); + } +#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER + } else { + error("Serial pinout mismatch. Requested pins Rx and Tx can't be used for the same Serial communication."); + } +} + +/** Configure the SPI format + * + * Set the number of bits per frame, configure clock polarity and phase, shift order and master/slave mode. + * The default bit order is MSB. + * @param[in,out] obj The SPI object to configure + * @param[in] bits The number of bits per frame + * @param[in] mode The SPI mode (clock polarity, phase, and shift direction) + * @param[in] slave Zero for master mode or non-zero for slave mode + */ +void spi_format(spi_t *obj_in, int bits, int mode, int slave) +{ + spi_obj_t *obj = OBJ_P(obj_in); + cy_en_scb_spi_mode_t new_mode = slave? CY_SCB_SPI_SLAVE : CY_SCB_SPI_MASTER; + if ((bits < 4) || (bits > 16)) return; + Cy_SCB_SPI_Disable(obj->base, &obj->context); + obj->data_bits = bits; + obj->clk_mode = (cy_en_scb_spi_sclk_mode_t)(mode & 0x3); + if (obj->ms_mode != new_mode) { + obj->ms_mode = new_mode; + spi_init_pins(obj); + } + spi_init_peripheral(obj); +} + +/** Configure the SPI frequency + * + * @param obj The SPI object + * @param hz Frequency in Hz + */ +void spi_frequency(spi_t *obj_in, int hz) +{ + spi_obj_t *obj = OBJ_P(obj_in); + Cy_SCB_SPI_Disable(obj->base, &obj->context); + spi_init_clock(obj, hz); + Cy_SCB_SPI_Enable(obj->base); +} + + + +/** Write a byte out in master mode and receive a value + * + * @param[in] obj The SPI peripheral to use for sending + * @param[in] value The value to send + * @return Returns the value received during send + */ +int spi_master_write(spi_t *obj_in, int value) +{ + spi_obj_t *obj = OBJ_P(obj_in); + + if (obj->ms_mode == CY_SCB_SPI_MASTER) { + while (spi_busy(obj_in)) { + // wait for the device to become ready + } + Cy_SCB_SPI_Write(obj->base, value); + while (!Cy_SCB_SPI_IsTxComplete(obj->base)) { + // wait for the transmission to complete + } + return Cy_SCB_SPI_Read(obj->base); + } else { + return (int)CY_SCB_SPI_RX_NO_DATA; + } +} + +/** Write a block out in master mode and receive a value + * + * The total number of bytes sent and recieved will be the maximum of + * tx_length and rx_length. The bytes written will be padded with the + * value 0xff. + * + * @param[in] obj The SPI peripheral to use for sending + * @param[in] tx_buffer Pointer to the byte-array of data to write to the device + * @param[in] tx_length Number of bytes to write, may be zero + * @param[in] rx_buffer Pointer to the byte-array of data to read from the device + * @param[in] rx_length Number of bytes to read, may be zero + * @param[in] write_fill Default data transmitted while performing a read + * @returns + * The number of bytes written and read from the device. This is + * maximum of tx_length and rx_length. + */ +int spi_master_block_write(spi_t *obj_in, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill) +{ + spi_obj_t *obj = OBJ_P(obj_in); + int trans_length = 0; + int rx_count = 0; + int tx_count = 0; + uint8_t tx_byte = (uint8_t)write_fill; + + if (obj->ms_mode != CY_SCB_SPI_MASTER) { + return 0; + } + + // Make sure no leftovers from previous transactions. + Cy_SCB_SPI_ClearRxFifo(obj->base); + // Calculate transaction length, + trans_length = (tx_length > rx_length)? tx_length : rx_length; + // get first byte to transmit. + if (tx_count < tx_length) { + tx_byte = *tx_buffer++; + } + // Send required number of bytes. + while (tx_count < trans_length) { + if (Cy_SCB_SPI_Write(obj->base, tx_byte)) { + ++tx_count; + // Get next byte to transfer. + if (tx_count < tx_length) { + tx_byte = *tx_buffer++; + } else { + tx_byte = (uint8_t)write_fill; + } + } + // If we have bytes to receive check the rx fifo. + if (rx_count < rx_length) { + if (Cy_SCB_SPI_GetNumInRxFifo(obj->base) > 0) { + *rx_buffer++ = (char)Cy_SCB_SPI_Read(obj->base); + ++rx_count; + } + } + } + // Wait for tx fifo to empty while reading received bytes. + while (!Cy_SCB_SPI_IsTxComplete(obj->base)) { + if ((rx_count < rx_length) && (Cy_SCB_SPI_GetNumInRxFifo(obj->base) > 0)) { + *rx_buffer++ = (char)Cy_SCB_SPI_Read(obj->base); + ++rx_count; + } + } + // Read any ramaining bytes from the fifo. + while (rx_count < rx_length) { + *rx_buffer++ = (char)Cy_SCB_SPI_Read(obj->base); + } + // Clean up if we have read less bytes than available. + Cy_SCB_SPI_ClearRxFifo(obj->base); + return trans_length; +} + +/** Check if a value is available to read + * + * @param[in] obj The SPI peripheral to check + * @return non-zero if a value is available + */ +int spi_slave_receive(spi_t *obj_in) { + spi_obj_t *obj = OBJ_P(obj_in); + if (obj->ms_mode == CY_SCB_SPI_SLAVE) { + return Cy_SCB_SPI_GetNumInRxFifo(obj->base); + } else { + return 0; + } +} + +/** Get a received value out of the SPI receive buffer in slave mode + * + * Blocks until a value is available + * @param[in] obj The SPI peripheral to read + * @return The value received + */ +int spi_slave_read(spi_t *obj_in) +{ + spi_obj_t *obj = OBJ_P(obj_in); + + if (obj->ms_mode == CY_SCB_SPI_SLAVE) { + while (Cy_SCB_SPI_GetNumInRxFifo(obj->base) == 0) { + // Wait for data. + } + return Cy_SCB_SPI_GetNumInRxFifo(obj->base); + } else { + return (int)CY_SCB_SPI_RX_NO_DATA; + } +} + +/** Write a value to the SPI peripheral in slave mode + * + * Blocks until the SPI peripheral can be written to + * @param[in] obj The SPI peripheral to write + * @param[in] value The value to write + */ +void spi_slave_write(spi_t *obj_in, int value) +{ + spi_obj_t *obj = OBJ_P(obj_in); + + if (obj->ms_mode == CY_SCB_SPI_SLAVE) { + while ((Cy_SCB_SPI_GetTxFifoStatus(obj->base) & CY_SCB_SPI_TX_NOT_FULL) == 0) { + // Wait for a place available in a fifo. + } + Cy_SCB_SPI_Write(obj->base, value); + } +} + +/** Checks if the specified SPI peripheral is in use + * + * @param[in] obj The SPI peripheral to check + * @return non-zero if the peripheral is currently transmitting + */ +int spi_busy(spi_t *obj) { + return !Cy_SCB_SPI_IsTxComplete(OBJ_P(obj)->base); +} + +/** Get the module number + * + * @param[in] obj The SPI peripheral to check + * @return The module number + */ +uint8_t spi_get_module(spi_t *obj_in) { + return (uint8_t) OBJ_P(obj_in)->spi_id; +} + + +#if DEVICE_SPI_ASYNCH + +/** + * \defgroup hal_AsynchSPI Asynchronous SPI Hardware Abstraction Layer + * @{ + */ + +/** Begin the SPI transfer. Buffer pointers and lengths are specified in tx_buff and rx_buff + * + * @param[in] obj The SPI object that holds the transfer information + * @param[in] tx The transmit buffer + * @param[in] tx_length The number of bytes to transmit + * @param[in] rx The receive buffer + * @param[in] rx_length The number of bytes to receive + * @param[in] bit_width The bit width of buffer words + * @param[in] event The logical OR of events to be registered + * @param[in] handler SPI interrupt handler + * @param[in] hint A suggestion for how to use DMA with this transfer + */ +void spi_master_transfer(spi_t *obj_in, + const void *tx, + size_t tx_length, + void *rx, + size_t rx_length, + uint8_t bit_width, + uint32_t handler, + uint32_t event, + DMAUsage hint) +{ + spi_obj_t *obj = OBJ_P(obj_in); + + (void)hint; // At the moment we do not support DAM transfers, so this parameter gets ignored. + + if (obj->pending != PENDING_NONE) { + return; + } + + // Validate buffer parameters. + if (((obj->data_bits <= 8) && (bit_width != 8)) || ((obj->data_bits > 8) && (bit_width != 16))) { + error("spi: buffer configurations does not match device configuration"); + return; + } + + obj->events = event; + obj->handler = handler; + if (spi_irq_setup_channel(obj) < 0) { + return; + } + + if (tx_length > rx_length) { + if (rx_length > 0) { + // I) write + read, II) write only + obj->pending = PENDING_TX_RX; + obj->rx_buffer = NULL; + obj->tx_buffer = (bit_width == 8)? + (void*)(((uint8_t*)tx) + rx_length) : + (void*)(((uint16_t*)tx) + rx_length); + obj->tx_buffer_size = tx_length - rx_length; + Cy_SCB_SPI_Transfer(obj->base, (void*)tx, rx, rx_length, &obj->context); + } else { + // I) write only. + obj->pending = PENDING_TX; + obj->rx_buffer = NULL; + obj->tx_buffer = NULL; + Cy_SCB_SPI_Transfer(obj->base, (void*)tx, NULL, tx_length, &obj->context); + } + } else if (rx_length > tx_length) { + if (tx_length > 0) { + // I) write + read, II) read only + obj->pending = PENDING_TX_RX; + obj->rx_buffer = (bit_width == 8)? + (void*)(((uint8_t*)rx) + tx_length) : + (void*)(((uint16_t*)rx) + tx_length); + obj->rx_buffer_size = rx_length - tx_length; + obj->tx_buffer = NULL; + Cy_SCB_SPI_Transfer(obj->base, (void*)tx, rx, tx_length, &obj->context); + } else { + // I) read only. + obj->pending = PENDING_RX; + obj->rx_buffer = NULL; + obj->tx_buffer = NULL; + Cy_SCB_SPI_Transfer(obj->base, NULL, rx, rx_length, &obj->context); + } + } else { + // Rx and Tx of the same size + // I) write + read. + obj->pending = PENDING_TX_RX; + obj->rx_buffer = NULL; + obj->tx_buffer = NULL; + Cy_SCB_SPI_Transfer(obj->base, (void*)tx, rx, tx_length, &obj->context); + } +} + +/** The asynchronous IRQ handler + * + * @param obj The SPI object which holds the transfer information + * @return Event flags if a transfer termination condition was met, otherwise return 0. + */ +uint32_t spi_irq_handler_asynch(spi_t *obj_in) +{ + spi_obj_t *obj = OBJ_P(obj_in); + uint32_t event = 0; + void *buf; + // Process actual interrupt. + Cy_SCB_SPI_Interrupt(obj->base, &obj->context); + if (obj->context.status & CY_SCB_SPI_TRANSFER_OVERFLOW) { + event = SPI_EVENT_RX_OVERFLOW; + } else if (obj->context.status & (CY_SCB_SPI_SLAVE_TRANSFER_ERR | CY_SCB_SPI_TRANSFER_OVERFLOW)) { + event = SPI_EVENT_ERROR; + } else if (0 == (obj->context.status & CY_SCB_SPI_TRANSFER_ACTIVE)) { + // Check to see if the second transfer phase needs to be started. + MBED_ASSERT(!(obj->tx_buffer && obj->rx_buffer)); + if (obj->tx_buffer) { + obj->pending = PENDING_TX; + buf = obj->tx_buffer; + obj->tx_buffer = NULL; + Cy_SCB_SPI_Transfer(obj->base, buf, NULL, obj->tx_buffer_size, &obj->context); + } else if (obj->rx_buffer) { + obj->pending = PENDING_RX; + buf = obj->rx_buffer; + obj->rx_buffer = NULL; + Cy_SCB_SPI_Transfer(obj->base, NULL, buf, obj->rx_buffer_size, &obj->context); + } else { + event = SPI_EVENT_COMPLETE; + obj->pending = PENDING_NONE; + } + } + return event & obj->events; +} + +/** Attempts to determine if the SPI peripheral is already in use + * + * @param obj The SPI object + * @return Non-zero if the SPI module is active or zero if it is not + */ +uint8_t spi_active(spi_t *obj_in) +{ + spi_obj_t *obj = OBJ_P(obj_in); + return (obj->pending != PENDING_NONE); +} + +/** Abort asynchronous transfer + * + * This function does not perform any check - that should happen in upper layers. + * @param obj The SPI object + */ +void spi_abort_asynch(spi_t *obj_in) +{ + spi_obj_t *obj = OBJ_P(obj_in); + Cy_SCB_SPI_AbortTransfer(obj->base, &obj->context); +} + +#endif // DEVICE_ASYNCH diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/trng_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/trng_api.c new file mode 100644 index 0000000000..6c22dc8f27 --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/trng_api.c @@ -0,0 +1,171 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include "device.h" +#include "mbed_critical.h" +#include "mbed_error.h" +#include "trng_api.h" +#include "drivers/peripheral/ipc/cy_ipc_drv.h" +#include "drivers/peripheral/crypto/cy_crypto_config.h" +#include "drivers/peripheral/crypto/cy_crypto.h" +#include "drivers/peripheral/crypto/cy_crypto_server.h" + + +#if DEVICE_TRNG + +/* Polynomial configuration for the programmable Galois and Fibonacci ring oscillators */ +#define CRYPTO_TRNG_GARO_POL (0x42000000) +#define CRYPTO_TRNG_FIRO_POL (0x43000000) + + +static uint32_t trng_initialized = 0; + +/** The Crypto configuration structure. */ +static const cy_stc_crypto_config_t crypto_config = +{ + /* .ipcChannel */ CY_IPC_CHAN_CRYPTO, + /* .acquireNotifierChannel */ CY_CRYPTO_IPC_INTR_NOTIFY_NUM, + /* .releaseNotifierChannel */ CY_CRYPTO_IPC_INTR_RELEASE_NUM, + + /* .releaseNotifierConfig */ { +#if (CY_CPU_CORTEX_M0P) + /* .intrSrc */ CY_CRYPTO_CM0_RELEASE_INTR_NR, + /* .cm0pSrc */ (cy_en_intr_t)CY_IPC_INTR_NUM_TO_VECT((int32_t)CY_CRYPTO_IPC_INTR_RELEASE_NUM), +#else + /* .intrSrc */ (IRQn_Type)CY_IPC_INTR_NUM_TO_VECT((int32_t)CY_CRYPTO_IPC_INTR_RELEASE_NUM), +#endif + /* .intrPriority */ CY_CRYPTO_RELEASE_INTR_PR, + }, + /* .userCompleteCallback */ NULL + +#if (CY_CRYPTO_CORE_ENABLE) + , + /* .userGetDataHandler */ NULL, + /* .userErrorHandler */ NULL, + + /* .acquireNotifierConfig */ { +#if (CY_CPU_CORTEX_M0P) + /* .intrSrc */ CY_CRYPTO_CM0_NOTIFY_INTR_NR, + /* .cm0pSrc */ (cy_en_intr_t)CY_IPC_INTR_NUM_TO_VECT((int32_t)CY_CRYPTO_IPC_INTR_NOTIFY_NUM), +#else + /* .intrSrc */ (IRQn_Type)CY_IPC_INTR_NUM_TO_VECT((int32_t)CY_CRYPTO_IPC_INTR_NOTIFY_NUM), +#endif + /* .intrPriority */ CY_CRYPTO_NOTIFY_INTR_PR, + }, + /* .cryptoErrorIntrConfig */ { +#if (CY_CPU_CORTEX_M0P) + /* .intrSrc */ CY_CRYPTO_CM0_ERROR_INTR_NR, + /* .cm0pSrc */ cpuss_interrupt_crypto_IRQn, +#else + /* .intrSrc */ cpuss_interrupt_crypto_IRQn, +#endif + /* .intrPriority */ CY_CRYPTO_ERROR_INTR_PR, + } +#endif +}; + +#if defined(TARGET_MCU_PSOC6_M0) +static cy_stc_crypto_server_context_t crypto_server_context; +#endif +static cy_stc_crypto_context_t crypto_scratch; +static cy_stc_crypto_context_trng_t trng_context; + +/** Initialize the TRNG peripheral + * + * @param obj The TRNG object + */ +void trng_init(trng_t *obj) +{ + (void) obj; + + if (core_util_atomic_incr_u32(&trng_initialized, 1) > 1) { + error("Only single instance of TRNG is supported."); + } + + /* Start the Crypto Server, only on Cm0 core */ +#if defined(TARGET_MCU_PSOC6_M0) + Cy_Crypto_Server_Start(&crypto_config, &crypto_server_context); + Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); +#endif + + /* Initialize the Crypto Driver */ + Cy_Crypto_Init(&crypto_config, &crypto_scratch); + Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); + + /* Enable Crypto Engine */ + Cy_Crypto_Enable(); + Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); + +} + +/** Deinitialize the TRNG peripheral + * + * @param obj The TRNG object + */ +void trng_free(trng_t *obj) +{ + (void) obj; + + Cy_Crypto_Enable(); + Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); + Cy_Crypto_DeInit(); + +#if defined(TARGET_MCU_PSOC6_M0) + Cy_Crypto_Server_Stop(); +#endif + trng_initialized = 0; +} + + +/** Get random data from TRNG peripheral + * + * @param obj The TRNG object + * @param output The pointer to an output array + * @param length The size of output data, to avoid buffer overwrite + * @param output_length The length of generated data + * @return 0 success, -1 fail + */ +int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) +{ + uint8_t random_val[4]; + uint32_t i; + + (void) obj; + + *output_length = length; + while (length > 0) { + if (Cy_Crypto_Trng_Generate(CRYPTO_TRNG_GARO_POL, + CRYPTO_TRNG_FIRO_POL, + 32, + (uint32_t *)random_val, + &trng_context) != CY_CRYPTO_SUCCESS) { + *output_length = 0; + return (-1); + } + + Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); + + for (i = 0; (i < 4) && (length > 0); ++i) { + *output++ = random_val[i]; + --length; + } + } + + return 0; +} + +#endif // DEVICE_TRNG diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/us_ticker.c b/targets/TARGET_Cypress/TARGET_PSOC6/us_ticker.c new file mode 100644 index 0000000000..3e40e8678a --- /dev/null +++ b/targets/TARGET_Cypress/TARGET_PSOC6/us_ticker.c @@ -0,0 +1,222 @@ +/* + * mbed Microcontroller Library + * Copyright (c) 2017-2018 Future Electronics + * + * 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. + */ + +#include +#include +#include "device.h" +#include "PeripheralNames.h" +#include "us_ticker_api.h" +#include "mbed_error.h" +#include "psoc6_utils.h" + +#include "drivers/peripheral/sysint/cy_sysint.h" +#include "drivers/peripheral/sysclk/cy_sysclk.h" +#include "drivers/peripheral/tcpwm/cy_tcpwm_counter.h" +#include "drivers/peripheral/syspm/cy_syspm.h" + +/** Each CPU core in PSoC6 needs its own usec timer. + ** Although each of TCPWM timers have two compare registers, + ** it has only one interrupt line, so we need to allocate + ** two TCPWM counters for the purpose of us_ticker + **/ + + +#if defined(TARGET_MCU_PSOC6_M0) + +#define TICKER_COUNTER_UNIT TCPWM0 +#define TICKER_COUNTER_NUM 0 +#define TICKER_COUNTER_INTERRUPT_SOURCE tcpwm_0_interrupts_0_IRQn +#define TICKER_COUNTER_NVIC_IRQN CY_M0_CORE_IRQ_CHANNEL_US_TICKER +#define TICKER_COUNTER_INTERRUPT_PRIORITY 3 + +#elif defined(TARGET_MCU_PSOC6_M4) + +#define TICKER_COUNTER_UNIT TCPWM0 +#define TICKER_COUNTER_NUM 1 +#define TICKER_COUNTER_INTERRUPT_SOURCE tcpwm_0_interrupts_1_IRQn +#define TICKER_COUNTER_NVIC_IRQN TICKER_COUNTER_INTERRUPT_SOURCE +#define TICKER_COUNTER_INTERRUPT_PRIORITY 6 + +#else +#error "Unknown MCU type." +#endif + + +static const ticker_info_t us_ticker_info = { + .frequency = 1000000UL, + .bits = 32, +}; + +static const cy_stc_sysint_t us_ticker_sysint_cfg = { + .intrSrc = TICKER_COUNTER_NVIC_IRQN, +#if defined(TARGET_MCU_PSOC6_M0) + .cm0pSrc = TICKER_COUNTER_INTERRUPT_SOURCE, +#endif + .intrPriority = TICKER_COUNTER_INTERRUPT_PRIORITY +}; + +static int us_ticker_inited = 0; +static uint32_t us_ticker_divider_num = CY_INVALID_DIVIDER; + +static const cy_stc_tcpwm_counter_config_t cy_counter_config = { + .period = 0xFFFFFFFFUL, + .clockPrescaler = CY_TCPWM_COUNTER_PRESCALER_DIVBY_1, + .runMode = CY_TCPWM_COUNTER_CONTINUOUS, + .countDirection = CY_TCPWM_COUNTER_COUNT_UP, + .compareOrCapture = CY_TCPWM_COUNTER_MODE_COMPARE, + .enableCompareSwap = false, + .interruptSources = CY_TCPWM_INT_ON_CC, + .countInputMode = CY_TCPWM_INPUT_LEVEL, + .countInput = CY_TCPWM_INPUT_1 +}; + +// PM callback to be executed when exiting deep sleep. +static cy_en_syspm_status_t ticker_pm_callback(cy_stc_syspm_callback_params_t *callbackParams); + +static cy_stc_syspm_callback_params_t ticker_pm_callback_params = { + .base = TICKER_COUNTER_UNIT +}; + +static cy_stc_syspm_callback_t ticker_pm_callback_handler = { + .callback = ticker_pm_callback, + .type = CY_SYSPM_DEEPSLEEP, + .skipMode = CY_SYSPM_SKIP_CHECK_READY | CY_SYSPM_SKIP_CHECK_FAIL | CY_SYSPM_SKIP_BEFORE_TRANSITION, + .callbackParams = &ticker_pm_callback_params +}; + + +/** Callback handler to restart the timer after deep sleep. + * + */ +static cy_en_syspm_status_t ticker_pm_callback(cy_stc_syspm_callback_params_t *params) +{ + if (params->mode == CY_SYSPM_AFTER_TRANSITION) { + Cy_TCPWM_Counter_Enable(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); + Cy_TCPWM_TriggerStart(TICKER_COUNTER_UNIT, 1UL << TICKER_COUNTER_NUM); + } + return CY_SYSPM_SUCCESS; +} + +/** Interrupt handler. + * + */ +static void local_irq_handler(void) +{ + us_ticker_clear_interrupt(); + us_ticker_disable_interrupt(); + us_ticker_irq_handler(); +} + + +void us_ticker_init(void) +{ + us_ticker_disable_interrupt(); + us_ticker_clear_interrupt(); + + if (us_ticker_inited) + return; + + us_ticker_inited = 1; + + /* + * Configure the clock + */ + us_ticker_divider_num = cy_clk_allocate_divider(CY_SYSCLK_DIV_8_BIT); + + // us_ticker 1 MHz from PCLK 50 MHz + + Cy_SysClk_PeriphAssignDivider(PCLK_TCPWM0_CLOCKS0 + TICKER_COUNTER_NUM, CY_SYSCLK_DIV_8_BIT, us_ticker_divider_num); + Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, us_ticker_divider_num, (CY_CLK_PERICLK_FREQ_HZ / 1000000UL) - 1); + Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, us_ticker_divider_num); + + /* + Configure the counter + */ + + Cy_TCPWM_Counter_Init(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM, &cy_counter_config); + Cy_TCPWM_Counter_Enable(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); + if (!Cy_SysPm_RegisterCallback(&ticker_pm_callback_handler)) { + error("PM callback registration failed!"); + } + Cy_TCPWM_TriggerStart(TICKER_COUNTER_UNIT, 1UL << TICKER_COUNTER_NUM); + +#if defined (TARGET_MCU_PSOC6_M0) + if (cy_m0_nvic_reserve_channel(TICKER_COUNTER_NVIC_IRQN, CY_US_TICKER_IRQN_ID) == (IRQn_Type)(-1)) { + error("Microsecond ticker NVIC channel reservation conflict."); + } +#endif // + + Cy_SysInt_Init(&us_ticker_sysint_cfg, local_irq_handler); +} + +void us_ticker_free(void) +{ + us_ticker_disable_interrupt(); + Cy_TCPWM_Counter_Disable(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); + Cy_SysPm_UnregisterCallback(&ticker_pm_callback_handler); + cy_clk_free_divider(CY_SYSCLK_DIV_8_BIT, us_ticker_divider_num); + us_ticker_divider_num = CY_INVALID_DIVIDER; +#if defined (TARGET_MCU_PSOC6_M0) + cy_m0_nvic_release_channel(TICKER_COUNTER_NVIC_IRQN, CY_US_TICKER_IRQN_ID); +#endif // + us_ticker_inited = 0; +} + +uint32_t us_ticker_read(void) +{ + if (!us_ticker_inited) + us_ticker_init(); + return Cy_TCPWM_Counter_GetCounter(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); +} + +void us_ticker_set_interrupt(timestamp_t timestamp) +{ + uint32_t current_ts = Cy_TCPWM_Counter_GetCounter(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); + uint32_t delta = timestamp - current_ts; + + if (!us_ticker_inited) + us_ticker_init(); + + // Set new output compare value + if ((delta < 2) || (delta > (uint32_t)(-3))) { + timestamp = current_ts + 2; + } + Cy_TCPWM_Counter_SetCompare0(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM, timestamp); + // Enable int + NVIC_EnableIRQ(TICKER_COUNTER_NVIC_IRQN); +} + +void us_ticker_disable_interrupt(void) +{ + NVIC_DisableIRQ(TICKER_COUNTER_NVIC_IRQN); +} + +void us_ticker_clear_interrupt(void) +{ + Cy_TCPWM_ClearInterrupt(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM, CY_TCPWM_INT_ON_CC); +} + +void us_ticker_fire_interrupt(void) +{ + NVIC_EnableIRQ(TICKER_COUNTER_NVIC_IRQN); + NVIC_SetPendingIRQ(TICKER_COUNTER_NVIC_IRQN); +} + +const ticker_info_t* us_ticker_get_info(void) +{ + return &us_ticker_info; +} diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/PeripheralNames.h b/targets/TARGET_Cypress/TARGET_PSoC6/PeripheralNames.h deleted file mode 100644 index 7ab3dc1d8c..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/PeripheralNames.h +++ /dev/null @@ -1,90 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_PERIPHERALNAMES_H -#define MBED_PERIPHERALNAMES_H - -#include "cmsis.h" -#include "PinNames.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// typedef enum { -// ADC_1 = (int)ADC1_BASE, -// ADC_2 = (int)ADC2_BASE, -// ADC_3 = (int)ADC3_BASE, -// } ADCName; - -// typedef enum { -// DAC_1 = (int)DAC_BASE, -// } DACName; - -// typedef enum { -// UART_1 = (int)USART1_BASE, -// UART_2 = (int)USART2_BASE, -// UART_3 = (int)USART3_BASE, -// } UARTName; - -#define STDIO_UART_TX CY_UART_TX -#define STDIO_UART_RX CY_UART_RX - -// typedef enum { -// SPI_1 = (int)SPI1_BASE, -// SPI_2 = (int)SPI2_BASE, -// SPI_3 = (int)SPI3_BASE, -// } SPIName; - -// typedef enum { -// I2C_0 = (int)I2C0_BASE, -// I2C_1 = (int)I2C1_BASE, -// } I2CName; - -// typedef enum { -// PWM_0 = (int)PWM_CH0_BASE, -// PWM_1 = (int)PWM_CH1_BASE, -// PWM_2 = (int)PWM_CH2_BASE, -// PWM_3 = (int)PWM_CH3_BASE, -// PWM_4 = (int)PWM_CH4_BASE, -// PWM_5 = (int)PWM_CH5_BASE, -// PWM_6 = (int)PWM_CH6_BASE, -// PWM_7 = (int)PWM_CH7_BASE, -// } PWMName; - -// typedef enum { -// CAN_1 = (int)CAN1_BASE, -// } CANName; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/PeripheralPins.h b/targets/TARGET_Cypress/TARGET_PSoC6/PeripheralPins.h deleted file mode 100644 index a24ce8e001..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/PeripheralPins.h +++ /dev/null @@ -1,84 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_PERIPHERALPINS_H -#define MBED_PERIPHERALPINS_H - -#include "pinmap.h" -#include "PeripheralNames.h" - -// //*** ADC *** -// #ifdef DEVICE_ANALOGIN -// extern const PinMap PinMap_ADC[]; -// #endif - -// //*** DAC *** -// #ifdef DEVICE_ANALOGOUT -// extern const PinMap PinMap_DAC[]; -// #endif - -// //*** I2C *** -// #if DEVICE_I2C -// extern const PinMap PinMap_I2C_SDA[]; -// extern const PinMap PinMap_I2C_SCL[]; -// #endif - -// //*** PWM *** -// #if DEVICE_PWMOUT -// extern const PinMap PinMap_PWM[]; -// #endif - -// //*** SERIAL *** -// #ifdef DEVICE_SERIAL -// extern const PinMap PinMap_UART_TX[]; -// extern const PinMap PinMap_UART_RX[]; -// #endif - -// //*** I2C *** -// #ifdef DEVICE_I2C -// extern const PinMap PinMap_I2C_SDA[]; -// extern const PinMap PinMap_I2C_SCL[]; -// #endif - -// //*** SPI *** -// #ifdef DEVICE_SPI -// extern const PinMap PinMap_SPI_MOSI[]; -// extern const PinMap PinMap_SPI_MISO[]; -// extern const PinMap PinMap_SPI_SCLK[]; -// extern const PinMap PinMap_SPI_SSEL[]; -// #endif - -// //*** CAN *** -// #ifdef DEVICE_CAN -// extern const PinMap PinMap_CAN_RD[]; -// extern const PinMap PinMap_CAN_TD[]; -// #endif - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/PinNamesTypes.h b/targets/TARGET_Cypress/TARGET_PSoC6/PinNamesTypes.h deleted file mode 100644 index bda1000b2f..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/PinNamesTypes.h +++ /dev/null @@ -1,67 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) 2016, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_PINNAMESTYPES_H -#define MBED_PINNAMESTYPES_H - -#include "cmsis.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// PinName[15-0] = Port[15-8] + Pin[7-0] -#define CYPRESS_PIN(pinname) ((pinname) & 0xFF) -#define CYPRESS_PORT(pinname) (((pinname) >> 8) & 0xFF) - -typedef enum { - PIN_INPUT = 0, - PIN_OUTPUT -} PinDirection; - -typedef enum { - PullNone = 0, - PullUp = 1, - PullDown = 2, - OpenDrainPullUp = 3, - OpenDrainNoPull = 4, - OpenDrainPullDown = 5, - PushPullNoPull = PullNone, - PushPullPullUp = PullUp, - PushPullPullDown = PullDown, - OpenDrain = OpenDrainPullUp, - PullDefault = PullNone -} PinMode; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/PortNames.h b/targets/TARGET_Cypress/TARGET_PSoC6/PortNames.h deleted file mode 100644 index 3f2e76232b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/PortNames.h +++ /dev/null @@ -1,61 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_PORTNAMES_H -#define MBED_PORTNAMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -// Port[7-0] -typedef enum { - Port0 = 0x0, - Port1 = 0x1, - Port2 = 0x2, - Port3 = 0x3, - Port4 = 0x4, - Port5 = 0x5, - Port6 = 0x6, - Port7 = 0x7, - Port8 = 0x8, - Port9 = 0x9, - Port10 = 0xA, - Port11 = 0xB, - Port12 = 0xC, - Port13 = 0xD, - Port14 = 0xE, - Port15 = 0xF -} PortName; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/BLE_config.h b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/BLE_config.h deleted file mode 100644 index 3aba0931a2..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/BLE_config.h +++ /dev/null @@ -1,330 +0,0 @@ -/***************************************************************************//** -* \file CY_BLE_config.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#if !defined(CY_BLE_CONFIG_H) -#define CY_BLE_CONFIG_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -//#include "cyfitter.h" -#include "syslib/cy_syslib.h" - - -/** -* \addtogroup group_macros -* @{ -*/ - -/* BLE_bless_isr */ -#define BLE_bless_isr__INTC_CORTEXM0P_ASSIGNED 1 -#define BLE_bless_isr__INTC_CORTEXM0P_MUX 3u -#define BLE_bless_isr__INTC_CORTEXM0P_PRIORITY 3u -#define BLE_bless_isr__INTC_CORTEXM4_ASSIGNED 1 -#define BLE_bless_isr__INTC_CORTEXM4_PRIORITY 7u -#define BLE_bless_isr__INTC_NUMBER 24u - - -/*************************************** -* Services Enable defines -***************************************/ - - - -/*************************************** -* API Constants -***************************************/ - -/** The component operating mode. */ -#define CY_BLE_CONFIG_MODE (0u) -#define CY_BLE_PROFILE (0u) -#define CY_BLE_HCI (1u) - -/** The core for the Host. For DUAL core device Controller will be compiled for different core. */ -#define CY_BLE_CONFIG_HOST_CORE (0u) -/** The core for the Controller in HCI mode. */ -#define CY_BLE_CONFIG_HCI_CONTR_CORE (1u) - -#define CY_BLE_CORE_CORTEX_M4 (0u) -#define CY_BLE_CORE_CORTEX_M0P (1u) -#define CY_BLE_CORE_CORTEX_NONE (0xffu) - -#define CY_BLE_HOST_CORE ((CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M4) ? \ - CY_CPU_CORTEX_M4 : CY_CPU_CORTEX_M0P) - -#define CY_BLE_HCI_CONTR_CORE ((CY_BLE_CONFIG_HCI_CONTR_CORE == CY_BLE_CORE_CORTEX_M4) ? \ - CY_CPU_CORTEX_M4 : CY_CPU_CORTEX_M0P) - -#define CY_BLE_CONTR_CORE ((CY_BLE_CONFIG_MODE == CY_BLE_HCI) ? CY_BLE_HCI_CONTR_CORE : \ - ((CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M0P) ? \ - CY_CPU_CORTEX_M4 : CY_CPU_CORTEX_M0P)) - -#define CY_BLE_MODE_PROFILE ((CY_BLE_CONFIG_MODE == CY_BLE_PROFILE) && (CY_BLE_HOST_CORE)) -#define CY_BLE_MODE_HCI ((CY_BLE_CONFIG_MODE == CY_BLE_HCI) && (CY_BLE_HCI_CONTR_CORE)) - -#define CY_BLE_CONFIG_EXT_PA_ENABLED ((0u | \ - 0u | \ - 0u) != 0u) - -/* Indicates whether deep sleep mode is used */ -#define CY_BLE_CONFIG_USE_DEEP_SLEEP (1u) - -/** Determines the internal stack mode. Used to switch the operation for debugging. - - ReleaseMode - Host and Controller with software interface. - - DebugMode - Host and Controller with IPC interface. - - HostOnly - Host with UART interface. - - HostContrUart - Host and Controller with a UART interface. -*/ -#define CY_BLE_CONFIG_STACK_MODE (2u) -#define CY_BLE_CONFIG_STACK_HOST_ONLY (1u) -#define CY_BLE_CONFIG_STACK_DEBUG (2u) -#define CY_BLE_CONFIG_STACK_RELEASE (3u) -#define CY_BLE_CONFIG_STACK_DEBUG_UART (4u) -#define CY_BLE_CONFIG_STACK_HOST_IPC (5u) - -#define CY_BLE_CONFIG_STACK_MODE_CONTR_UART ((CY_BLE_MODE_HCI) || \ - ((CY_BLE_CONFIG_MODE == CY_BLE_PROFILE) && \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG_UART) && \ - CY_BLE_CONTR_CORE)) - -#define CY_BLE_CONFIG_STACK_MODE_HOST_UART ((CY_BLE_MODE_PROFILE) && \ - (((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_HOST_ONLY) || \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG_UART)) && \ - CY_BLE_HOST_CORE)) - -#define CY_BLE_CONFIG_STACK_MODE_HOST_IPC ((CY_BLE_MODE_PROFILE) && \ - (((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_HOST_IPC) || \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG)) && \ - CY_BLE_HOST_CORE)) - -#define CY_BLE_CONFIG_STACK_CONTR_CORE ((CY_BLE_MODE_HCI) || \ - ((CY_BLE_CONFIG_MODE == CY_BLE_PROFILE) && \ - ((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_RELEASE) && \ - (CY_BLE_HOST_CORE)) || \ - (((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG) || \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG_UART)) &&\ - (CY_BLE_CONTR_CORE)))) - -#define CY_BLE_CONFIG_STACK_IPC_CONTR_CORE ((CY_BLE_CONFIG_MODE == CY_BLE_PROFILE) && \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG) && \ - (CY_BLE_CONTR_CORE)) - -#define CY_BLE_CONFIG_CONTR_CORE ((CY_BLE_CONFIG_MODE == CY_BLE_HCI) ? \ - CY_BLE_CONFIG_HCI_CONTR_CORE : \ - ((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_RELEASE) ? \ - CY_BLE_CONFIG_HOST_CORE : \ - (((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG) || \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG_UART)) ? \ - ((CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M4) ? \ - CY_BLE_CORE_CORTEX_M0P : CY_BLE_CORE_CORTEX_M4) : \ - CY_BLE_CORE_CORTEX_NONE)) ) - -#define CY_BLE_HOST_CONTR_CORE (CY_BLE_MODE_PROFILE || CY_BLE_CONFIG_STACK_CONTR_CORE) - -#if(CY_BLE_CONFIG_STACK_CONTR_CORE) /* Check for the proper BLESS ISR configuration in the DWR */ - -#if ((CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M4) && \ - (!defined BLE_bless_isr__INTC_CORTEXM4_ASSIGNED)) - #error Enable BLE_bless_isr interrupt for the ARM CM4 core in the interrupt configuration tab of \ - the Design-Wide Resources (DWR) file (project.cydwr) -#endif /* (CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M4) */ -#if ((CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M0P) && \ - (!defined BLE_bless_isr__INTC_CORTEXM0P_ASSIGNED)) - #error Enable BLE_bless_isr interrupt for the ARM CM0+ core in the interrupt configuration tab of \ - the Design-Wide Resources (DWR) file (project.cydwr) -#endif /* CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M0P) */ - -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ - -#if(CY_BLE_CONFIG_STACK_MODE_CONTR_UART) /* Check for the proper UART ISR configuration in the DWR */ - -#if((CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M4) && \ - (!defined BLE_uart_isr__INTC_CORTEXM4_ASSIGNED)) - #error Enable BLE_uart_isr interrupt for the ARM CM4 core in the interrupt configuration tab of \ - the Design-Wide Resources (DWR) file (project.cydwr) -#endif /* CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M4 */ -#if((CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M0P) && \ - (!defined BLE_uart_isr__INTC_CORTEXM0P_ASSIGNED)) - #error Enable BLE_uart_isr interrupt for the ARM CM0+ core in the interrupt configuration tab of \ - the Design-Wide Resources (DWR) file (project.cydwr) -#endif /* CY_BLE_CONFIG_CONTR_CORE == CY_BLE_CORE_CORTEX_M0P */ - -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ - -#if(CY_BLE_CONFIG_STACK_MODE_HOST_UART) /* Check for the proper HOST UART ISR configuration in the DWR */ - -#if((CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M4) && \ - (!defined BLE_host_uart_isr__INTC_CORTEXM4_ASSIGNED)) - #error Enable BLE_host_uart_isr interrupt for the ARM CM4 core in the interrupt configuration tab of \ - the Design-Wide Resources (DWR) file (project.cydwr) -#endif /* CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M4 */ -#if((CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M0P) && \ - (!defined BLE_host_uart_isr__INTC_CORTEXM0P_ASSIGNED)) - #error Enable BLE_host_uart_isr interrupt for the ARM CM0+ core in the interrupt configuration tab of \ - the Design-Wide Resources (DWR) file (project.cydwr) -#endif /* CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M0P */ - -#endif /* (CY_BLE_CONFIG_STACK_MODE_HOST_UART) */ - -/** The maximum number of BLE connections */ -#define CY_BLE_CONFIG_CONN_COUNT (4u) -/** The number of BLE connections */ -#define CY_BLE_CONFIG_GATTC_COUNT (0x00u) -/** The number of GAP Peripheral configurations */ -#define CY_BLE_CONFIG_GAP_PERIPHERAL_COUNT (0x01u) -/** The number of GAP Broadcaster configurations */ -#define CY_BLE_CONFIG_GAP_BROADCASTER_COUNT (0x00u) -/** The number of GAP Central configurations */ -#define CY_BLE_CONFIG_GAP_CENTRAL_COUNT (0x00u) -/** The number of GAP Observer configurations */ -#define CY_BLE_CONFIG_GAP_OBSERVER_COUNT (0x00u) -/** The number of Security configurations */ -#define CY_BLE_CONFIG_AUTH_INFO_COUNT (0x01u) -/** LL Privacy 1.2 feature */ -#define CY_BLE_CONFIG_ENABLE_LL_PRIVACY (0x01u) -/** LE 2 Mbps feature */ -#define CY_BLE_CONFIG_ENABLE_PHY_UPDATE (0u) -/** Radio power calibration */ -#define CY_BLE_CONFIG_TX_POWER_CALIBRATION_ENABLE (0u) -/** The GAP security level */ -#define CY_BLE_CONFIG_GAP_SECURITY_LEVEL (0x00u) -#define CY_BLE_CONFIG_SHARING_MODE (0u) -/** The GAP Role */ -#define CY_BLE_CONFIG_GAP_ROLE (0x01u) -/** The Bonding Requirement */ -#define CY_BLE_CONFIG_BONDING_REQUIREMENT (0x00u) -/** The maximum number of bonded devices to be supported by this device. */ -#define CY_BLE_CONFIG_MAX_BONDED_DEVICES (16u) -/** The maximum number of peer devices whose addresses should be resolved by this device. */ -#define CY_BLE_CONFIG_MAX_RESOLVABLE_DEVICES (16u) -/** The maximum number of devices that can be added to the whitelist. */ -#define CY_BLE_CONFIG_MAX_WHITE_LIST_SIZE (16u) - -#define CY_BLE_SECURITY_CONFIGURATION_0_INDEX (0x00u) - -#define CY_BLE_ADV_PKT_0_INDEX_FLAGS (0x00u) -#define CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX (0x00u) - - -/* Additional queue depth provided from the customizer */ -#define CY_BLE_CONFIG_ADD_Q_DEPTH_PER_CONN (0u) - -/** GATT MTU Size */ -#define CY_BLE_CONFIG_GATT_MTU (0x0017u) - -/** GATT Maximum attribute length */ -#define CY_BLE_CONFIG_GATT_DB_MAX_VALUE_LEN (0x000Fu) - -#define CY_BLE_GATT_DB_INDEX_COUNT (0x000Fu) - -/** The number of characteristics supporting a Reliable Write property */ -#define CY_BLE_CONFIG_GATT_RELIABLE_CHAR_COUNT (0x0000u) -/** The total length of characteristics with Reliable Write property */ -#define CY_BLE_CONFIG_GATT_RELIABLE_CHAR_LENGTH (0x0000u) - -/** The parameter to enable an application to provide a dynamically allocated buffer for preparing a Write request. */ -#define CY_BLE_CONFIG_GATT_ENABLE_EXTERNAL_PREP_WRITE_BUFF (0u) - -/** The parameter to enable configuration of the L2CAP logical channels */ -#define CY_BLE_CONFIG_L2CAP_ENABLE (1u) - -#if(CY_BLE_CONFIG_L2CAP_ENABLE != 0u) - /** L2CAP MTU Size */ - #define CY_BLE_CONFIG_L2CAP_MTU (23u) - /** L2CAP MPS Size */ - #define CY_BLE_CONFIG_L2CAP_MPS (23u) - /** Number of L2CAP Logical channels */ - #define CY_BLE_CONFIG_L2CAP_LOGICAL_CHANNEL_COUNT (1u) - /** Number of L2CAP PSMs */ - #define CY_BLE_CONFIG_L2CAP_PSM_COUNT (1u) -#endif /* CY_BLE_L2CAP_ENABLE != 0u */ - - -#define CY_BLE_CONFIG_GATT_DB_ATT_VAL_COUNT (0x07u) - -/** Max Tx payload size */ -#define CY_BLE_CONFIG_LL_MAX_TX_PAYLOAD_SIZE (0x1Bu) -/** Max Rx payload size */ -#define CY_BLE_CONFIG_LL_MAX_RX_PAYLOAD_SIZE (0x1Bu) - -/** GATT Role */ -#define CY_BLE_CONFIG_GATT_ROLE (0x01u) -#define CY_BLE_CONFIG_GATT_DB_CCCD_COUNT (0x02u) - -/** Max unique services in the project */ -#define CY_BLE_MAX_SRVI (0x01u) - - -/*************************************** -* API Constants for BLE services -* (using in CY_BLE_.h) -***************************************/ - -/* HIDS */ -/** The maximum supported count of HID services for the GATT Server role */ -#define CY_BLE_CONFIG_HIDSS_SERVICE_COUNT (0x00u) -/** The maximum supported count of HID reports for the GATT Server role */ -#define CY_BLE_CONFIG_HIDSS_REPORT_COUNT (0x00u) - -/** The maximum supported count of HID services for the GATT Client role */ -#define CY_BLE_CONFIG_HIDSC_SERVICE_COUNT (0x00u) -/** The maximum supported count of HID reports for the GATT Client role */ -#define CY_BLE_CONFIG_HIDSC_REPORT_COUNT (0x00u) - - - - - -/* BAS */ -/** The maximum supported count of BAS services for the GATT Server role */ -#define CY_BLE_CONFIG_BASS_SERVICE_COUNT (0x00u) -/** The maximum supported count of BAS reports for the GATT Client role */ -#define CY_BLE_CONFIG_BASC_SERVICE_COUNT (0x00u) - - - -/* ESS */ -/** The maximum supported count of ESS characteristics for the GATT Client role */ -#define CY_BLE_CONFIG_ES_TOTAL_CHAR_COUNT (0x00u) - -/* AIOS */ -/** The maximum supported count of AIOS characteristics for the GATT Client role */ -#define CY_BLE_CONFIG_AIO_TOTAL_CHAR_COUNT (0x00u) - -/* CUSTOM */ -/** The maximum supported count of Custom services for the GATT Server role */ -#define CY_BLE_CONFIG_CUSTOMS_SERVICE_COUNT (0x00u) -/** The maximum supported count of Custom services for the GATT Client role */ -#define CY_BLE_CONFIG_CUSTOMC_SERVICE_COUNT (0x00u) -/** The maximum supported count of the Custom Service characteristics */ -#define CY_BLE_CONFIG_CUSTOM_SERVICE_CHAR_COUNT (0x00u) -/** The maximum supported count of the Custom Service descriptors in one characteristic */ -#define CY_BLE_CONFIG_CUSTOM_SERVICE_CHAR_DESCRIPTORS_COUNT (0x00u) - -/* Below are the indexes and handles of the defined Custom Services and their characteristics */ - - - -/** @} group_macros */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CY_BLE_CONFIG_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/PeripheralPins.c b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/PeripheralPins.c deleted file mode 100644 index 451cf138c9..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/PeripheralPins.c +++ /dev/null @@ -1,131 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#include "PeripheralNames.h" -#include "PeripheralPins.h" -#include "pinmap.h" - -// //*** ADC *** -// const PinMap PinMap_ADC[] = { -// {PC_15, ADC_0, STM_PIN_DATA_EXT(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN0 -// {PC_14, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN1 -// {PC_13, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN2 -// {PC_12, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN3 -// {PC_11, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN4 -// {PC_10, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN5 -// {PC_9 , ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN6 -// {PC_8 , ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN7 -// {NC, NC, 0} -// }; - -// //*** DAC *** -// const PinMap PinMap_DAC[] = { -// {PA_4, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // OUT1 -// {PA_5, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // OUT2 (Warning: LED1 is also on this pin) -// {NC, NC, 0} -// }; - -// //*** SERIAL *** -// const PinMap PinMap_UART_TX[] = { -// {PA_13, UART_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_2, UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_10, UART_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {NC, NC, 0} -// }; -// const PinMap PinMap_UART_RX[] = { -// {PA_14, UART_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_3, UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_11, UART_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {NC, NC, 0} -// }; - -// //*** I2C *** -// const PinMap PinMap_I2C_SDA[] = { -// {PA_10, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_9, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_5, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PA_6, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC, NC, 0} -// }; -// const PinMap PinMap_I2C_SCL[] = { -// {PA_9, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_8, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_4, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PA_5, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC, NC, 0} -// }; - -// //*** SPI *** -// const PinMap PinMap_SPI_SCLK[] = { -// {PA_6 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_1 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_13, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_12, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; -// const PinMap PinMap_SPI_MOSI[] = { -// {PA_8 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_3 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_15, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_14, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; -// const PinMap PinMap_SPI_MISO[] = { -// {PA_7 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_2 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_14, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_13, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; -// const PinMap PinMap_SPI_SSEL[] = { -// {PA_5 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_0 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_12, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_11, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; - -// //*** PWM *** -// const PinMap PinMap_PWM[] = { -// {PA_0 , PWM_6, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_1 , PWM_7, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_5 , PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_7 , PWM_4, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_8 , PWM_5, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_9 , PWM_6, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_10, PWM_7, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PC_0 , PWM_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_2 , PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_4 , PWM_4, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_5 , PWM_5, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_8 , PWM_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_10, PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)} -// }; diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_ipc_cm0p.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_ipc_cm0p.a deleted file mode 100644 index 9bb8405e2c..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_ipc_cm0p.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_uart_cm0p.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_uart_cm0p.a deleted file mode 100644 index 61a838bd24..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_uart_cm0p.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_radio_max_cm0p.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_radio_max_cm0p.a deleted file mode 100644 index 0eac688d65..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_radio_max_cm0p.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_soc_cm0p.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_soc_cm0p.a deleted file mode 100644 index 5205deffd9..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_soc_cm0p.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/libble_stack_gcc_controller_ipc_cm0p.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/libble_stack_gcc_controller_ipc_cm0p.a deleted file mode 100644 index 96f368b18c..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/libble_stack_gcc_controller_ipc_cm0p.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/libble_stack_gcc_radio_max_cm0p.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/libble_stack_gcc_radio_max_cm0p.a deleted file mode 100644 index 7bbe6715f5..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M0/device/TOOLCHAIN_GCC_ARM/libble_stack_gcc_radio_max_cm0p.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/PeripheralPins.c b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/PeripheralPins.c deleted file mode 100644 index 451cf138c9..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/PeripheralPins.c +++ /dev/null @@ -1,131 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#include "PeripheralNames.h" -#include "PeripheralPins.h" -#include "pinmap.h" - -// //*** ADC *** -// const PinMap PinMap_ADC[] = { -// {PC_15, ADC_0, STM_PIN_DATA_EXT(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN0 -// {PC_14, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN1 -// {PC_13, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN2 -// {PC_12, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN3 -// {PC_11, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN4 -// {PC_10, ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN5 -// {PC_9 , ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN6 -// {PC_8 , ADC_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF3)}, // ADC0_IN7 -// {NC, NC, 0} -// }; - -// //*** DAC *** -// const PinMap PinMap_DAC[] = { -// {PA_4, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // OUT1 -// {PA_5, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // OUT2 (Warning: LED1 is also on this pin) -// {NC, NC, 0} -// }; - -// //*** SERIAL *** -// const PinMap PinMap_UART_TX[] = { -// {PA_13, UART_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_2, UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_10, UART_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {NC, NC, 0} -// }; -// const PinMap PinMap_UART_RX[] = { -// {PA_14, UART_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_3, UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {PC_11, UART_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)}, -// {NC, NC, 0} -// }; - -// //*** I2C *** -// const PinMap PinMap_I2C_SDA[] = { -// {PA_10, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_9, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_5, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PA_6, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC, NC, 0} -// }; -// const PinMap PinMap_I2C_SCL[] = { -// {PA_9, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_8, I2C_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_4, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PA_5, I2C_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC, NC, 0} -// }; - -// //*** SPI *** -// const PinMap PinMap_SPI_SCLK[] = { -// {PA_6 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_1 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_13, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_12, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; -// const PinMap PinMap_SPI_MOSI[] = { -// {PA_8 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_3 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_15, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_14, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; -// const PinMap PinMap_SPI_MISO[] = { -// {PA_7 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_2 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_14, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_13, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; -// const PinMap PinMap_SPI_SSEL[] = { -// {PA_5 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PB_0 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_12, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_11, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , 0} -// }; - -// //*** PWM *** -// const PinMap PinMap_PWM[] = { -// {PA_0 , PWM_6, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_1 , PWM_7, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PA_5 , PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_7 , PWM_4, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_8 , PWM_5, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_9 , PWM_6, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PA_10, PWM_7, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)}, -// {PC_0 , PWM_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_2 , PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_4 , PWM_4, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_5 , PWM_5, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {PC_8 , PWM_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}, -// {PC_10, PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)}, -// {NC , NC , WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)} -// }; diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/PinNames.h b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/PinNames.h deleted file mode 100644 index 23ab89eee5..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/PinNames.h +++ /dev/null @@ -1,251 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_PINNAMES_H -#define MBED_PINNAMES_H - -#include "cmsis.h" -#include "PinNamesTypes.h" -#include "PortNames.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CY_UART_RX P5_0 -#define CY_UART_TX P5_1 - -// PinName[15-0] = Port[15-8] + Pin[7-0] -typedef enum { - P0_0 = (Port0 << 8) + 0x00, - P0_1 = (Port0 << 8) + 0x01, - P0_2 = (Port0 << 8) + 0x02, - P0_3 = (Port0 << 8) + 0x03, - P0_4 = (Port0 << 8) + 0x04, - P0_5 = (Port0 << 8) + 0x05, - P0_6 = (Port0 << 8) + 0x06, - P0_7 = (Port0 << 8) + 0x07, - - P1_0 = (Port1 << 8) + 0x00, - P1_1 = (Port1 << 8) + 0x01, - P1_2 = (Port1 << 8) + 0x02, - P1_3 = (Port1 << 8) + 0x03, - P1_4 = (Port1 << 8) + 0x04, - P1_5 = (Port1 << 8) + 0x05, - P1_6 = (Port1 << 8) + 0x06, - P1_7 = (Port1 << 8) + 0x07, - - P2_0 = (Port2 << 8) + 0x00, - P2_1 = (Port2 << 8) + 0x01, - P2_2 = (Port2 << 8) + 0x02, - P2_3 = (Port2 << 8) + 0x03, - P2_4 = (Port2 << 8) + 0x04, - P2_5 = (Port2 << 8) + 0x05, - P2_6 = (Port2 << 8) + 0x06, - P2_7 = (Port2 << 8) + 0x07, - - P3_0 = (Port3 << 8) + 0x00, - P3_1 = (Port3 << 8) + 0x01, - P3_2 = (Port3 << 8) + 0x02, - P3_3 = (Port3 << 8) + 0x03, - P3_4 = (Port3 << 8) + 0x04, - P3_5 = (Port3 << 8) + 0x05, - P3_6 = (Port3 << 8) + 0x06, - P3_7 = (Port3 << 8) + 0x07, - - P4_0 = (Port4 << 8) + 0x00, - P4_1 = (Port4 << 8) + 0x01, - P4_2 = (Port4 << 8) + 0x02, - P4_3 = (Port4 << 8) + 0x03, - P4_4 = (Port4 << 8) + 0x04, - P4_5 = (Port4 << 8) + 0x05, - P4_6 = (Port4 << 8) + 0x06, - P4_7 = (Port4 << 8) + 0x07, - - P5_0 = (Port5 << 8) + 0x00, - P5_1 = (Port5 << 8) + 0x01, - P5_2 = (Port5 << 8) + 0x02, - P5_3 = (Port5 << 8) + 0x03, - P5_4 = (Port5 << 8) + 0x04, - P5_5 = (Port5 << 8) + 0x05, - P5_6 = (Port5 << 8) + 0x06, - P5_7 = (Port5 << 8) + 0x07, - - P6_0 = (Port6 << 8) + 0x00, - P6_1 = (Port6 << 8) + 0x01, - P6_2 = (Port6 << 8) + 0x02, - P6_3 = (Port6 << 8) + 0x03, - P6_4 = (Port6 << 8) + 0x04, - P6_5 = (Port6 << 8) + 0x05, - P6_6 = (Port6 << 8) + 0x06, - P6_7 = (Port6 << 8) + 0x07, - - P7_0 = (Port7 << 8) + 0x00, - P7_1 = (Port7 << 8) + 0x01, - P7_2 = (Port7 << 8) + 0x02, - P7_3 = (Port7 << 8) + 0x03, - P7_4 = (Port7 << 8) + 0x04, - P7_5 = (Port7 << 8) + 0x05, - P7_6 = (Port7 << 8) + 0x06, - P7_7 = (Port7 << 8) + 0x07, - - P8_0 = (Port8 << 8) + 0x00, - P8_1 = (Port8 << 8) + 0x01, - P8_2 = (Port8 << 8) + 0x02, - P8_3 = (Port8 << 8) + 0x03, - P8_4 = (Port8 << 8) + 0x04, - P8_5 = (Port8 << 8) + 0x05, - P8_6 = (Port8 << 8) + 0x06, - P8_7 = (Port8 << 8) + 0x07, - - P9_0 = (Port9 << 8) + 0x00, - P9_1 = (Port9 << 8) + 0x01, - P9_2 = (Port9 << 8) + 0x02, - P9_3 = (Port9 << 8) + 0x03, - P9_4 = (Port9 << 8) + 0x04, - P9_5 = (Port9 << 8) + 0x05, - P9_6 = (Port9 << 8) + 0x06, - P9_7 = (Port9 << 8) + 0x07, - - P10_0 = (Port10 << 8) + 0x00, - P10_1 = (Port10 << 8) + 0x01, - P10_2 = (Port10 << 8) + 0x02, - P10_3 = (Port10 << 8) + 0x03, - P10_4 = (Port10 << 8) + 0x04, - P10_5 = (Port10 << 8) + 0x05, - P10_6 = (Port10 << 8) + 0x06, - P10_7 = (Port10 << 8) + 0x07, - - P11_0 = (Port11 << 8) + 0x00, - P11_1 = (Port11 << 8) + 0x01, - P11_2 = (Port11 << 8) + 0x02, - P11_3 = (Port11 << 8) + 0x03, - P11_4 = (Port11 << 8) + 0x04, - P11_5 = (Port11 << 8) + 0x05, - P11_6 = (Port11 << 8) + 0x06, - P11_7 = (Port11 << 8) + 0x07, - - P12_0 = (Port12 << 8) + 0x00, - P12_1 = (Port12 << 8) + 0x01, - P12_2 = (Port12 << 8) + 0x02, - P12_3 = (Port12 << 8) + 0x03, - P12_4 = (Port12 << 8) + 0x04, - P12_5 = (Port12 << 8) + 0x05, - P12_6 = (Port12 << 8) + 0x06, - P12_7 = (Port12 << 8) + 0x07, - - P13_0 = (Port13 << 8) + 0x00, - P13_1 = (Port13 << 8) + 0x01, - P13_2 = (Port13 << 8) + 0x02, - P13_3 = (Port13 << 8) + 0x03, - P13_4 = (Port13 << 8) + 0x04, - P13_5 = (Port13 << 8) + 0x05, - P13_6 = (Port13 << 8) + 0x06, - P13_7 = (Port13 << 8) + 0x07, - - P14_0 = (Port14 << 8) + 0x00, - P14_1 = (Port14 << 8) + 0x01, - P14_2 = (Port14 << 8) + 0x02, - P14_3 = (Port14 << 8) + 0x03, - P14_4 = (Port14 << 8) + 0x04, - P14_5 = (Port14 << 8) + 0x05, - P14_6 = (Port14 << 8) + 0x06, - P14_7 = (Port14 << 8) + 0x07, - - P15_0 = (Port15 << 8) + 0x00, - P15_1 = (Port15 << 8) + 0x01, - P15_2 = (Port15 << 8) + 0x02, - P15_3 = (Port15 << 8) + 0x03, - P15_4 = (Port15 << 8) + 0x04, - P15_5 = (Port15 << 8) + 0x05, - P15_6 = (Port15 << 8) + 0x06, - P15_7 = (Port15 << 8) + 0x07, - - // Arduino connector namings - A0 = P10_0, - A1 = P10_1, - A2 = P10_2, - A3 = P10_3, - A4 = P10_4, - A5 = P10_5, - - D0 = P5_0, - D1 = P5_1, - D2 = P5_2, - D3 = P5_3, - D4 = P5_4, - D5 = P5_5, - D6 = P5_6, - D7 = P0_2, - D8 = P13_0, - D9 = P13_1, - D10 = P12_3, - D11 = P12_0, - D12 = P12_1, - D13 = P12_2, - - // Generic signals namings - - LED_RED = P0_3, - LED_GREEN = P1_1, - LED_BLUE = P11_1, - - SWITCH2 = P0_4, - - LED1 = LED_RED, - LED2 = LED_GREEN, - LED3 = LED_BLUE, - LED4 = LED_RED, - - USER_BUTTON = SWITCH2, - BUTTON1 = USER_BUTTON, - - // Standardized interfaces names - SERIAL_TX = CY_UART_TX, - SERIAL_RX = CY_UART_RX, - USBTX = CY_UART_TX, - USBRX = CY_UART_RX, - // I2C_SCL = PB_8, - // I2C_SDA = PB_9, - // SPI_MOSI = PA_7, - // SPI_MISO = PA_6, - // SPI_SCK = PA_5, - // SPI_CS = PB_6, - // PWM_OUT = PB_3, - - // Not connected - NC = (int)0xFFFFFFFF -} PinName; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_ipc_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_ipc_cm4.a deleted file mode 100644 index e11d3b42b2..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_ipc_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_uart_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_uart_cm4.a deleted file mode 100644 index d9e8856a22..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_controller_uart_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_ipc_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_ipc_cm4.a deleted file mode 100644 index b367c9d9ec..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_ipc_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_uart_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_uart_cm4.a deleted file mode 100644 index 8416822e6a..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_host_uart_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_radio_max_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_radio_max_cm4.a deleted file mode 100644 index 34aa520aa4..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_radio_max_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_soc_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_soc_cm4.a deleted file mode 100644 index 72c8d47924..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_ARM_STD/cy_ble_stack_mdk_soc_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/libcy_ble_stack_gcc_host_ipc_cm4.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/libcy_ble_stack_gcc_host_ipc_cm4.a deleted file mode 100644 index 5fe461fe47..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/TARGET_CY8CKIT_062_BLE_M4/device/TOOLCHAIN_GCC_ARM/libcy_ble_stack_gcc_host_ipc_cm4.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device.h b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device.h deleted file mode 100644 index b134699e38..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device.h +++ /dev/null @@ -1,39 +0,0 @@ -// The 'features' section in 'target.json' is now used to create the device's hardware preprocessor switches. -// Check the 'features' section of the target description in 'targets.json' for more details. -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_DEVICE_H -#define MBED_DEVICE_H - -#include "objects.h" -//#include "project.h" - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_full.a b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_full.a deleted file mode 100644 index 29b5ed4003..0000000000 Binary files a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/TOOLCHAIN_GCC_ARM/libcy_crypto_server_gcc_full.a and /dev/null differ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/gpio_psoc6ble_116_bga_ble.h b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/gpio_psoc6ble_116_bga_ble.h deleted file mode 100644 index 46d8b6031b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/gpio_psoc6ble_116_bga_ble.h +++ /dev/null @@ -1,1611 +0,0 @@ -/***************************************************************************//** -* \file gpio_psoc6ble_116_bga_ble.h -* -* \brief -* PSoC 6 BLE device GPIO header for 116-BGA-BLE package -* -* \note -* Generated 2/9/2017 by CyDeviceHeaderGenerator v1.1.0.47 -* from the register map configuration rev#961378 -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef _GPIO_PSOC6BLE_116_BGA_BLE_H_ -#define _GPIO_PSOC6BLE_116_BGA_BLE_H_ - -/* Analog Connections */ -#define CSD_CMODPADD_PORT 7u -#define CSD_CMODPADD_PIN 1u -#define CSD_CMODPADS_PORT 7u -#define CSD_CMODPADS_PIN 1u -#define CSD_CSH_TANKPADD_PORT 7u -#define CSD_CSH_TANKPADD_PIN 2u -#define CSD_CSH_TANKPADS_PORT 7u -#define CSD_CSH_TANKPADS_PIN 2u -#define CSD_CSHIELDPADS_PORT 7u -#define CSD_CSHIELDPADS_PIN 7u -#define CSD_VREF_EXT_PORT 7u -#define CSD_VREF_EXT_PIN 3u -#define LPCOMP_INN_COMP1_PORT 6u -#define LPCOMP_INN_COMP1_PIN 3u -#define LPCOMP_INP_COMP0_PORT 5u -#define LPCOMP_INP_COMP0_PIN 6u -#define LPCOMP_INP_COMP1_PORT 6u -#define LPCOMP_INP_COMP1_PIN 2u -#define PASS_AREF_EXT_VREF_PORT 9u -#define PASS_AREF_EXT_VREF_PIN 7u -#define PASS_CTB_OA0_OUT_10X_PORT 9u -#define PASS_CTB_OA0_OUT_10X_PIN 2u -#define PASS_CTB_OA1_OUT_10X_PORT 9u -#define PASS_CTB_OA1_OUT_10X_PIN 3u -#define PASS_CTB_PADS0_PORT 9u -#define PASS_CTB_PADS0_PIN 0u -#define PASS_CTB_PADS1_PORT 9u -#define PASS_CTB_PADS1_PIN 1u -#define PASS_CTB_PADS2_PORT 9u -#define PASS_CTB_PADS2_PIN 2u -#define PASS_CTB_PADS3_PORT 9u -#define PASS_CTB_PADS3_PIN 3u -#define PASS_CTB_PADS4_PORT 9u -#define PASS_CTB_PADS4_PIN 4u -#define PASS_CTB_PADS5_PORT 9u -#define PASS_CTB_PADS5_PIN 5u -#define PASS_CTB_PADS6_PORT 9u -#define PASS_CTB_PADS6_PIN 6u -#define PASS_CTB_PADS7_PORT 9u -#define PASS_CTB_PADS7_PIN 7u -#define PASS_SARMUX_PADS0_PORT 10u -#define PASS_SARMUX_PADS0_PIN 0u -#define PASS_SARMUX_PADS1_PORT 10u -#define PASS_SARMUX_PADS1_PIN 1u -#define PASS_SARMUX_PADS2_PORT 10u -#define PASS_SARMUX_PADS2_PIN 2u -#define PASS_SARMUX_PADS3_PORT 10u -#define PASS_SARMUX_PADS3_PIN 3u -#define PASS_SARMUX_PADS4_PORT 10u -#define PASS_SARMUX_PADS4_PIN 4u -#define PASS_SARMUX_PADS5_PORT 10u -#define PASS_SARMUX_PADS5_PIN 5u -#define PASS_SARMUX_PADS6_PORT 10u -#define PASS_SARMUX_PADS6_PIN 6u -#define SRSS_ADFT_PIN0_PORT 10u -#define SRSS_ADFT_PIN0_PIN 0u -#define SRSS_ADFT_PIN1_PORT 10u -#define SRSS_ADFT_PIN1_PIN 1u -#define SRSS_ECO_IN_PORT 12u -#define SRSS_ECO_IN_PIN 6u -#define SRSS_ECO_OUT_PORT 12u -#define SRSS_ECO_OUT_PIN 7u -#define SRSS_WCO_IN_PORT 0u -#define SRSS_WCO_IN_PIN 0u -#define SRSS_WCO_OUT_PORT 0u -#define SRSS_WCO_OUT_PIN 1u - -/* HSIOM Connections */ -typedef enum -{ - /* Generic HSIOM connections */ - HSIOM_SEL_GPIO = 0, /* GPIO controls 'out' */ - HSIOM_SEL_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - HSIOM_SEL_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - HSIOM_SEL_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - HSIOM_SEL_AMUXA = 4, /* Analog mux bus A */ - HSIOM_SEL_AMUXB = 5, /* Analog mux bus B */ - HSIOM_SEL_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - HSIOM_SEL_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - HSIOM_SEL_ACT_0 = 8, /* Active functionality 0 */ - HSIOM_SEL_ACT_1 = 9, /* Active functionality 1 */ - HSIOM_SEL_ACT_2 = 10, /* Active functionality 2 */ - HSIOM_SEL_ACT_3 = 11, /* Active functionality 3 */ - HSIOM_SEL_DS_0 = 12, /* DeepSleep functionality 0 */ - HSIOM_SEL_DS_1 = 13, /* DeepSleep functionality 1 */ - HSIOM_SEL_DS_2 = 14, /* DeepSleep functionality 2 */ - HSIOM_SEL_DS_3 = 15, /* DeepSleep functionality 3 */ - HSIOM_SEL_ACT_4 = 16, /* Active functionality 4 */ - HSIOM_SEL_ACT_5 = 17, /* Active functionality 5 */ - HSIOM_SEL_ACT_6 = 18, /* Active functionality 6 */ - HSIOM_SEL_ACT_7 = 19, /* Active functionality 7 */ - HSIOM_SEL_ACT_8 = 20, /* Active functionality 8 */ - HSIOM_SEL_ACT_9 = 21, /* Active functionality 9 */ - HSIOM_SEL_ACT_10 = 22, /* Active functionality 10 */ - HSIOM_SEL_ACT_11 = 23, /* Active functionality 11 */ - HSIOM_SEL_ACT_12 = 24, /* Active functionality 12 */ - HSIOM_SEL_ACT_13 = 25, /* Active functionality 13 */ - HSIOM_SEL_ACT_14 = 26, /* Active functionality 14 */ - HSIOM_SEL_ACT_15 = 27, /* Active functionality 15 */ - HSIOM_SEL_DS_4 = 28, /* DeepSleep functionality 4 */ - HSIOM_SEL_DS_5 = 29, /* DeepSleep functionality 5 */ - HSIOM_SEL_DS_6 = 30, /* DeepSleep functionality 6 */ - HSIOM_SEL_DS_7 = 31, /* DeepSleep functionality 7 */ - - /* P0.0 */ - P0_0_GPIO = 0, /* GPIO controls 'out' */ - P0_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P0_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P0_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P0_0_AMUXA = 4, /* Analog mux bus A */ - P0_0_AMUXB = 5, /* Analog mux bus B */ - P0_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P0_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P0_0_TCPWM0_LINE0 = 8, /* Digital Active - tcpwm[0].line[0]:0 */ - P0_0_TCPWM1_LINE0 = 9, /* Digital Active - tcpwm[1].line[0]:0 */ - P0_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:0 */ - P0_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:0 */ - P0_0_LCD_COM0 = 12, /* Digital Deep Sleep - lcd.com[0]:0 */ - P0_0_LCD_SEG0 = 13, /* Digital Deep Sleep - lcd.seg[0]:0 */ - P0_0_SRSS_EXT_CLK = 16, /* Digital Active - srss.ext_clk:0 */ - P0_0_SCB0_SPI_SELECT1 = 20, /* Digital Active - scb[0].spi_select1:0 */ - P0_0_PERI_TR_IO_INPUT0 = 24, /* Digital Active - peri.tr_io_input[0]:0 */ - - /* P0.1 */ - P0_1_GPIO = 0, /* GPIO controls 'out' */ - P0_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P0_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P0_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P0_1_AMUXA = 4, /* Analog mux bus A */ - P0_1_AMUXB = 5, /* Analog mux bus B */ - P0_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P0_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P0_1_TCPWM0_LINE_COMPL0 = 8, /* Digital Active - tcpwm[0].line_compl[0]:0 */ - P0_1_TCPWM1_LINE_COMPL0 = 9, /* Digital Active - tcpwm[1].line_compl[0]:0 */ - P0_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:1 */ - P0_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:1 */ - P0_1_LCD_COM1 = 12, /* Digital Deep Sleep - lcd.com[1]:0 */ - P0_1_LCD_SEG1 = 13, /* Digital Deep Sleep - lcd.seg[1]:0 */ - P0_1_SCB0_SPI_SELECT2 = 20, /* Digital Active - scb[0].spi_select2:0 */ - P0_1_PERI_TR_IO_INPUT1 = 24, /* Digital Active - peri.tr_io_input[1]:0 */ - P0_1_CPUSS_SWJ_TRSTN = 29, /* Digital Deep Sleep - cpuss.swj_trstn */ - - /* P0.2 */ - P0_2_GPIO = 0, /* GPIO controls 'out' */ - P0_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P0_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P0_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P0_2_AMUXA = 4, /* Analog mux bus A */ - P0_2_AMUXB = 5, /* Analog mux bus B */ - P0_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P0_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P0_2_TCPWM0_LINE1 = 8, /* Digital Active - tcpwm[0].line[1]:0 */ - P0_2_TCPWM1_LINE1 = 9, /* Digital Active - tcpwm[1].line[1]:0 */ - P0_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:2 */ - P0_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:2 */ - P0_2_LCD_COM2 = 12, /* Digital Deep Sleep - lcd.com[2]:0 */ - P0_2_LCD_SEG2 = 13, /* Digital Deep Sleep - lcd.seg[2]:0 */ - P0_2_SCB0_UART_RX = 18, /* Digital Active - scb[0].uart_rx:0 */ - P0_2_SCB0_I2C_SCL = 19, /* Digital Active - scb[0].i2c_scl:0 */ - P0_2_SCB0_SPI_MOSI = 20, /* Digital Active - scb[0].spi_mosi:0 */ - - /* P0.3 */ - P0_3_GPIO = 0, /* GPIO controls 'out' */ - P0_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P0_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P0_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P0_3_AMUXA = 4, /* Analog mux bus A */ - P0_3_AMUXB = 5, /* Analog mux bus B */ - P0_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P0_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P0_3_TCPWM0_LINE_COMPL1 = 8, /* Digital Active - tcpwm[0].line_compl[1]:0 */ - P0_3_TCPWM1_LINE_COMPL1 = 9, /* Digital Active - tcpwm[1].line_compl[1]:0 */ - P0_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:3 */ - P0_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:3 */ - P0_3_LCD_COM3 = 12, /* Digital Deep Sleep - lcd.com[3]:0 */ - P0_3_LCD_SEG3 = 13, /* Digital Deep Sleep - lcd.seg[3]:0 */ - P0_3_SCB0_UART_TX = 18, /* Digital Active - scb[0].uart_tx:0 */ - P0_3_SCB0_I2C_SDA = 19, /* Digital Active - scb[0].i2c_sda:0 */ - P0_3_SCB0_SPI_MISO = 20, /* Digital Active - scb[0].spi_miso:0 */ - - /* P0.4 */ - P0_4_GPIO = 0, /* GPIO controls 'out' */ - P0_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P0_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P0_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P0_4_AMUXA = 4, /* Analog mux bus A */ - P0_4_AMUXB = 5, /* Analog mux bus B */ - P0_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P0_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P0_4_TCPWM0_LINE2 = 8, /* Digital Active - tcpwm[0].line[2]:0 */ - P0_4_TCPWM1_LINE2 = 9, /* Digital Active - tcpwm[1].line[2]:0 */ - P0_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:4 */ - P0_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:4 */ - P0_4_LCD_COM4 = 12, /* Digital Deep Sleep - lcd.com[4]:0 */ - P0_4_LCD_SEG4 = 13, /* Digital Deep Sleep - lcd.seg[4]:0 */ - P0_4_SCB0_UART_RTS = 18, /* Digital Active - scb[0].uart_rts:0 */ - P0_4_SCB0_SPI_CLK = 20, /* Digital Active - scb[0].spi_clk:0 */ - P0_4_PERI_TR_IO_OUTPUT0 = 25, /* Digital Active - peri.tr_io_output[0]:2 */ - - /* P0.5 */ - P0_5_GPIO = 0, /* GPIO controls 'out' */ - P0_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P0_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P0_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P0_5_AMUXA = 4, /* Analog mux bus A */ - P0_5_AMUXB = 5, /* Analog mux bus B */ - P0_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P0_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P0_5_TCPWM0_LINE_COMPL2 = 8, /* Digital Active - tcpwm[0].line_compl[2]:0 */ - P0_5_TCPWM1_LINE_COMPL2 = 9, /* Digital Active - tcpwm[1].line_compl[2]:0 */ - P0_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:5 */ - P0_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:5 */ - P0_5_LCD_COM5 = 12, /* Digital Deep Sleep - lcd.com[5]:0 */ - P0_5_LCD_SEG5 = 13, /* Digital Deep Sleep - lcd.seg[5]:0 */ - P0_5_SRSS_EXT_CLK = 16, /* Digital Active - srss.ext_clk:1 */ - P0_5_SCB0_UART_CTS = 18, /* Digital Active - scb[0].uart_cts:0 */ - P0_5_SCB0_SPI_SELECT0 = 20, /* Digital Active - scb[0].spi_select0:0 */ - P0_5_PERI_TR_IO_OUTPUT1 = 25, /* Digital Active - peri.tr_io_output[1]:2 */ - - /* P1.0 */ - P1_0_GPIO = 0, /* GPIO controls 'out' */ - P1_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P1_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P1_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P1_0_AMUXA = 4, /* Analog mux bus A */ - P1_0_AMUXB = 5, /* Analog mux bus B */ - P1_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P1_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P1_0_TCPWM0_LINE3 = 8, /* Digital Active - tcpwm[0].line[3]:0 */ - P1_0_TCPWM1_LINE3 = 9, /* Digital Active - tcpwm[1].line[3]:0 */ - P1_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:6 */ - P1_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:6 */ - P1_0_LCD_COM6 = 12, /* Digital Deep Sleep - lcd.com[6]:0 */ - P1_0_LCD_SEG6 = 13, /* Digital Deep Sleep - lcd.seg[6]:0 */ - P1_0_SCB7_UART_RX = 18, /* Digital Active - scb[7].uart_rx:0 */ - P1_0_SCB7_I2C_SCL = 19, /* Digital Active - scb[7].i2c_scl:0 */ - P1_0_SCB7_SPI_MOSI = 20, /* Digital Active - scb[7].spi_mosi:0 */ - P1_0_PERI_TR_IO_INPUT2 = 24, /* Digital Active - peri.tr_io_input[2]:0 */ - - /* P1.1 */ - P1_1_GPIO = 0, /* GPIO controls 'out' */ - P1_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P1_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P1_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P1_1_AMUXA = 4, /* Analog mux bus A */ - P1_1_AMUXB = 5, /* Analog mux bus B */ - P1_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P1_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P1_1_TCPWM0_LINE_COMPL3 = 8, /* Digital Active - tcpwm[0].line_compl[3]:0 */ - P1_1_TCPWM1_LINE_COMPL3 = 9, /* Digital Active - tcpwm[1].line_compl[3]:0 */ - P1_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:7 */ - P1_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:7 */ - P1_1_LCD_COM7 = 12, /* Digital Deep Sleep - lcd.com[7]:0 */ - P1_1_LCD_SEG7 = 13, /* Digital Deep Sleep - lcd.seg[7]:0 */ - P1_1_SCB7_UART_TX = 18, /* Digital Active - scb[7].uart_tx:0 */ - P1_1_SCB7_I2C_SDA = 19, /* Digital Active - scb[7].i2c_sda:0 */ - P1_1_SCB7_SPI_MISO = 20, /* Digital Active - scb[7].spi_miso:0 */ - P1_1_PERI_TR_IO_INPUT3 = 24, /* Digital Active - peri.tr_io_input[3]:0 */ - - /* P1.2 */ - P1_2_GPIO = 0, /* GPIO controls 'out' */ - P1_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P1_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P1_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P1_2_AMUXA = 4, /* Analog mux bus A */ - P1_2_AMUXB = 5, /* Analog mux bus B */ - P1_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P1_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P1_2_TCPWM0_LINE4 = 8, /* Digital Active - tcpwm[0].line[4]:4 */ - P1_2_TCPWM1_LINE12 = 9, /* Digital Active - tcpwm[1].line[12]:1 */ - P1_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:8 */ - P1_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:8 */ - P1_2_LCD_COM8 = 12, /* Digital Deep Sleep - lcd.com[8]:0 */ - P1_2_LCD_SEG8 = 13, /* Digital Deep Sleep - lcd.seg[8]:0 */ - P1_2_SCB7_UART_RTS = 18, /* Digital Active - scb[7].uart_rts:0 */ - P1_2_SCB7_SPI_CLK = 20, /* Digital Active - scb[7].spi_clk:0 */ - - /* P1.3 */ - P1_3_GPIO = 0, /* GPIO controls 'out' */ - P1_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P1_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P1_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P1_3_AMUXA = 4, /* Analog mux bus A */ - P1_3_AMUXB = 5, /* Analog mux bus B */ - P1_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P1_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P1_3_TCPWM0_LINE_COMPL4 = 8, /* Digital Active - tcpwm[0].line_compl[4]:4 */ - P1_3_TCPWM1_LINE_COMPL12 = 9, /* Digital Active - tcpwm[1].line_compl[12]:1 */ - P1_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:9 */ - P1_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:9 */ - P1_3_LCD_COM9 = 12, /* Digital Deep Sleep - lcd.com[9]:0 */ - P1_3_LCD_SEG9 = 13, /* Digital Deep Sleep - lcd.seg[9]:0 */ - P1_3_SCB7_UART_CTS = 18, /* Digital Active - scb[7].uart_cts:0 */ - P1_3_SCB7_SPI_SELECT0 = 20, /* Digital Active - scb[7].spi_select0:0 */ - - /* P1.4 */ - P1_4_GPIO = 0, /* GPIO controls 'out' */ - P1_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P1_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P1_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P1_4_AMUXA = 4, /* Analog mux bus A */ - P1_4_AMUXB = 5, /* Analog mux bus B */ - P1_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P1_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P1_4_TCPWM0_LINE5 = 8, /* Digital Active - tcpwm[0].line[5]:4 */ - P1_4_TCPWM1_LINE13 = 9, /* Digital Active - tcpwm[1].line[13]:1 */ - P1_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:10 */ - P1_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:10 */ - P1_4_LCD_COM10 = 12, /* Digital Deep Sleep - lcd.com[10]:0 */ - P1_4_LCD_SEG10 = 13, /* Digital Deep Sleep - lcd.seg[10]:0 */ - P1_4_SCB7_SPI_SELECT1 = 20, /* Digital Active - scb[7].spi_select1:0 */ - - /* P1.5 */ - P1_5_GPIO = 0, /* GPIO controls 'out' */ - P1_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P1_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P1_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P1_5_AMUXA = 4, /* Analog mux bus A */ - P1_5_AMUXB = 5, /* Analog mux bus B */ - P1_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P1_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P1_5_TCPWM0_LINE_COMPL5 = 8, /* Digital Active - tcpwm[0].line_compl[5]:4 */ - P1_5_TCPWM1_LINE_COMPL14 = 9, /* Digital Active - tcpwm[1].line_compl[14]:1 */ - P1_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:11 */ - P1_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:11 */ - P1_5_LCD_COM11 = 12, /* Digital Deep Sleep - lcd.com[11]:0 */ - P1_5_LCD_SEG11 = 13, /* Digital Deep Sleep - lcd.seg[11]:0 */ - P1_5_SCB7_SPI_SELECT2 = 20, /* Digital Active - scb[7].spi_select2:0 */ - - /* P5.0 */ - P5_0_GPIO = 0, /* GPIO controls 'out' */ - P5_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_0_AMUXA = 4, /* Analog mux bus A */ - P5_0_AMUXB = 5, /* Analog mux bus B */ - P5_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_0_TCPWM0_LINE4 = 8, /* Digital Active - tcpwm[0].line[4]:0 */ - P5_0_TCPWM1_LINE4 = 9, /* Digital Active - tcpwm[1].line[4]:0 */ - P5_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:30 */ - P5_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:30 */ - P5_0_LCD_COM30 = 12, /* Digital Deep Sleep - lcd.com[30]:0 */ - P5_0_LCD_SEG30 = 13, /* Digital Deep Sleep - lcd.seg[30]:0 */ - P5_0_SCB5_UART_RX = 18, /* Digital Active - scb[5].uart_rx:0 */ - P5_0_SCB5_I2C_SCL = 19, /* Digital Active - scb[5].i2c_scl:0 */ - P5_0_SCB5_SPI_MOSI = 20, /* Digital Active - scb[5].spi_mosi:0 */ - P5_0_AUDIOSS_CLK_I2S_IF = 22, /* Digital Active - audioss.clk_i2s_if */ - P5_0_PERI_TR_IO_INPUT10 = 24, /* Digital Active - peri.tr_io_input[10]:0 */ - - /* P5.1 */ - P5_1_GPIO = 0, /* GPIO controls 'out' */ - P5_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_1_AMUXA = 4, /* Analog mux bus A */ - P5_1_AMUXB = 5, /* Analog mux bus B */ - P5_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_1_TCPWM0_LINE_COMPL4 = 8, /* Digital Active - tcpwm[0].line_compl[4]:0 */ - P5_1_TCPWM1_LINE_COMPL4 = 9, /* Digital Active - tcpwm[1].line_compl[4]:0 */ - P5_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:31 */ - P5_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:31 */ - P5_1_LCD_COM31 = 12, /* Digital Deep Sleep - lcd.com[31]:0 */ - P5_1_LCD_SEG31 = 13, /* Digital Deep Sleep - lcd.seg[31]:0 */ - P5_1_SCB5_UART_TX = 18, /* Digital Active - scb[5].uart_tx:0 */ - P5_1_SCB5_I2C_SDA = 19, /* Digital Active - scb[5].i2c_sda:0 */ - P5_1_SCB5_SPI_MISO = 20, /* Digital Active - scb[5].spi_miso:0 */ - P5_1_AUDIOSS_TX_SCK = 22, /* Digital Active - audioss.tx_sck */ - P5_1_PERI_TR_IO_INPUT11 = 24, /* Digital Active - peri.tr_io_input[11]:0 */ - - /* P5.2 */ - P5_2_GPIO = 0, /* GPIO controls 'out' */ - P5_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_2_AMUXA = 4, /* Analog mux bus A */ - P5_2_AMUXB = 5, /* Analog mux bus B */ - P5_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_2_TCPWM0_LINE5 = 8, /* Digital Active - tcpwm[0].line[5]:0 */ - P5_2_TCPWM1_LINE5 = 9, /* Digital Active - tcpwm[1].line[5]:0 */ - P5_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:32 */ - P5_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:32 */ - P5_2_LCD_COM32 = 12, /* Digital Deep Sleep - lcd.com[32]:0 */ - P5_2_LCD_SEG32 = 13, /* Digital Deep Sleep - lcd.seg[32]:0 */ - P5_2_SCB5_UART_RTS = 18, /* Digital Active - scb[5].uart_rts:0 */ - P5_2_SCB5_SPI_CLK = 20, /* Digital Active - scb[5].spi_clk:0 */ - P5_2_AUDIOSS_TX_WS = 22, /* Digital Active - audioss.tx_ws */ - - /* P5.3 */ - P5_3_GPIO = 0, /* GPIO controls 'out' */ - P5_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_3_AMUXA = 4, /* Analog mux bus A */ - P5_3_AMUXB = 5, /* Analog mux bus B */ - P5_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_3_TCPWM0_LINE_COMPL5 = 8, /* Digital Active - tcpwm[0].line_compl[5]:0 */ - P5_3_TCPWM1_LINE_COMPL5 = 9, /* Digital Active - tcpwm[1].line_compl[5]:0 */ - P5_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:33 */ - P5_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:33 */ - P5_3_LCD_COM33 = 12, /* Digital Deep Sleep - lcd.com[33]:0 */ - P5_3_LCD_SEG33 = 13, /* Digital Deep Sleep - lcd.seg[33]:0 */ - P5_3_SCB5_UART_CTS = 18, /* Digital Active - scb[5].uart_cts:0 */ - P5_3_SCB5_SPI_SELECT0 = 20, /* Digital Active - scb[5].spi_select0:0 */ - P5_3_AUDIOSS_TX_SDO = 22, /* Digital Active - audioss.tx_sdo */ - - /* P5.4 */ - P5_4_GPIO = 0, /* GPIO controls 'out' */ - P5_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_4_AMUXA = 4, /* Analog mux bus A */ - P5_4_AMUXB = 5, /* Analog mux bus B */ - P5_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_4_TCPWM0_LINE6 = 8, /* Digital Active - tcpwm[0].line[6]:0 */ - P5_4_TCPWM1_LINE6 = 9, /* Digital Active - tcpwm[1].line[6]:0 */ - P5_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:34 */ - P5_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:34 */ - P5_4_LCD_COM34 = 12, /* Digital Deep Sleep - lcd.com[34]:0 */ - P5_4_LCD_SEG34 = 13, /* Digital Deep Sleep - lcd.seg[34]:0 */ - P5_4_SCB5_SPI_SELECT1 = 20, /* Digital Active - scb[5].spi_select1:0 */ - P5_4_AUDIOSS_RX_SCK = 22, /* Digital Active - audioss.rx_sck */ - - /* P5.5 */ - P5_5_GPIO = 0, /* GPIO controls 'out' */ - P5_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_5_AMUXA = 4, /* Analog mux bus A */ - P5_5_AMUXB = 5, /* Analog mux bus B */ - P5_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_5_TCPWM0_LINE_COMPL6 = 8, /* Digital Active - tcpwm[0].line_compl[6]:0 */ - P5_5_TCPWM1_LINE_COMPL6 = 9, /* Digital Active - tcpwm[1].line_compl[6]:0 */ - P5_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:35 */ - P5_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:35 */ - P5_5_LCD_COM35 = 12, /* Digital Deep Sleep - lcd.com[35]:0 */ - P5_5_LCD_SEG35 = 13, /* Digital Deep Sleep - lcd.seg[35]:0 */ - P5_5_SCB5_SPI_SELECT2 = 20, /* Digital Active - scb[5].spi_select2:0 */ - P5_5_AUDIOSS_RX_WS = 22, /* Digital Active - audioss.rx_ws */ - - /* P5.6 */ - P5_6_GPIO = 0, /* GPIO controls 'out' */ - P5_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P5_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P5_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P5_6_AMUXA = 4, /* Analog mux bus A */ - P5_6_AMUXB = 5, /* Analog mux bus B */ - P5_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P5_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P5_6_TCPWM0_LINE7 = 8, /* Digital Active - tcpwm[0].line[7]:0 */ - P5_6_TCPWM1_LINE7 = 9, /* Digital Active - tcpwm[1].line[7]:0 */ - P5_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:36 */ - P5_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:36 */ - P5_6_LCD_COM36 = 12, /* Digital Deep Sleep - lcd.com[36]:0 */ - P5_6_LCD_SEG36 = 13, /* Digital Deep Sleep - lcd.seg[36]:0 */ - P5_6_SCB5_SPI_SELECT3 = 20, /* Digital Active - scb[5].spi_select3:0 */ - P5_6_AUDIOSS_RX_SDI = 22, /* Digital Active - audioss.rx_sdi */ - - /* P6.0 */ - P6_0_GPIO = 0, /* GPIO controls 'out' */ - P6_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_0_AMUXA = 4, /* Analog mux bus A */ - P6_0_AMUXB = 5, /* Analog mux bus B */ - P6_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_0_TCPWM0_LINE0 = 8, /* Digital Active - tcpwm[0].line[0]:1 */ - P6_0_TCPWM1_LINE8 = 9, /* Digital Active - tcpwm[1].line[8]:0 */ - P6_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:38 */ - P6_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:38 */ - P6_0_LCD_COM38 = 12, /* Digital Deep Sleep - lcd.com[38]:0 */ - P6_0_LCD_SEG38 = 13, /* Digital Deep Sleep - lcd.seg[38]:0 */ - P6_0_SCB8_I2C_SCL = 14, /* Digital Deep Sleep - scb[8].i2c_scl:0 */ - P6_0_SCB3_UART_RX = 18, /* Digital Active - scb[3].uart_rx:0 */ - P6_0_SCB3_I2C_SCL = 19, /* Digital Active - scb[3].i2c_scl:0 */ - P6_0_SCB3_SPI_MOSI = 20, /* Digital Active - scb[3].spi_mosi:0 */ - P6_0_CPUSS_FAULT_OUT0 = 25, /* Digital Active - cpuss.fault_out[0] */ - P6_0_SCB8_SPI_MOSI = 30, /* Digital Deep Sleep - scb[8].spi_mosi:0 */ - - /* P6.1 */ - P6_1_GPIO = 0, /* GPIO controls 'out' */ - P6_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_1_AMUXA = 4, /* Analog mux bus A */ - P6_1_AMUXB = 5, /* Analog mux bus B */ - P6_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_1_TCPWM0_LINE_COMPL0 = 8, /* Digital Active - tcpwm[0].line_compl[0]:1 */ - P6_1_TCPWM1_LINE_COMPL8 = 9, /* Digital Active - tcpwm[1].line_compl[8]:0 */ - P6_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:39 */ - P6_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:39 */ - P6_1_LCD_COM39 = 12, /* Digital Deep Sleep - lcd.com[39]:0 */ - P6_1_LCD_SEG39 = 13, /* Digital Deep Sleep - lcd.seg[39]:0 */ - P6_1_SCB8_I2C_SDA = 14, /* Digital Deep Sleep - scb[8].i2c_sda:0 */ - P6_1_SCB3_UART_TX = 18, /* Digital Active - scb[3].uart_tx:0 */ - P6_1_SCB3_I2C_SDA = 19, /* Digital Active - scb[3].i2c_sda:0 */ - P6_1_SCB3_SPI_MISO = 20, /* Digital Active - scb[3].spi_miso:0 */ - P6_1_CPUSS_FAULT_OUT1 = 25, /* Digital Active - cpuss.fault_out[1] */ - P6_1_SCB8_SPI_MISO = 30, /* Digital Deep Sleep - scb[8].spi_miso:0 */ - - /* P6.2 */ - P6_2_GPIO = 0, /* GPIO controls 'out' */ - P6_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_2_AMUXA = 4, /* Analog mux bus A */ - P6_2_AMUXB = 5, /* Analog mux bus B */ - P6_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_2_TCPWM0_LINE1 = 8, /* Digital Active - tcpwm[0].line[1]:1 */ - P6_2_TCPWM1_LINE9 = 9, /* Digital Active - tcpwm[1].line[9]:0 */ - P6_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:40 */ - P6_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:40 */ - P6_2_LCD_COM40 = 12, /* Digital Deep Sleep - lcd.com[40]:0 */ - P6_2_LCD_SEG40 = 13, /* Digital Deep Sleep - lcd.seg[40]:0 */ - P6_2_SCB3_UART_RTS = 18, /* Digital Active - scb[3].uart_rts:0 */ - P6_2_SCB3_SPI_CLK = 20, /* Digital Active - scb[3].spi_clk:0 */ - P6_2_SCB8_SPI_CLK = 30, /* Digital Deep Sleep - scb[8].spi_clk:0 */ - - /* P6.3 */ - P6_3_GPIO = 0, /* GPIO controls 'out' */ - P6_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_3_AMUXA = 4, /* Analog mux bus A */ - P6_3_AMUXB = 5, /* Analog mux bus B */ - P6_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_3_TCPWM0_LINE_COMPL1 = 8, /* Digital Active - tcpwm[0].line_compl[1]:1 */ - P6_3_TCPWM1_LINE_COMPL9 = 9, /* Digital Active - tcpwm[1].line_compl[9]:0 */ - P6_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:41 */ - P6_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:41 */ - P6_3_LCD_COM41 = 12, /* Digital Deep Sleep - lcd.com[41]:0 */ - P6_3_LCD_SEG41 = 13, /* Digital Deep Sleep - lcd.seg[41]:0 */ - P6_3_SCB3_UART_CTS = 18, /* Digital Active - scb[3].uart_cts:0 */ - P6_3_SCB3_SPI_SELECT0 = 20, /* Digital Active - scb[3].spi_select0:0 */ - P6_3_SCB8_SPI_SELECT0 = 30, /* Digital Deep Sleep - scb[8].spi_select0:0 */ - - /* P6.4 */ - P6_4_GPIO = 0, /* GPIO controls 'out' */ - P6_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_4_AMUXA = 4, /* Analog mux bus A */ - P6_4_AMUXB = 5, /* Analog mux bus B */ - P6_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_4_TCPWM0_LINE2 = 8, /* Digital Active - tcpwm[0].line[2]:1 */ - P6_4_TCPWM1_LINE10 = 9, /* Digital Active - tcpwm[1].line[10]:0 */ - P6_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:42 */ - P6_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:42 */ - P6_4_LCD_COM42 = 12, /* Digital Deep Sleep - lcd.com[42]:0 */ - P6_4_LCD_SEG42 = 13, /* Digital Deep Sleep - lcd.seg[42]:0 */ - P6_4_SCB8_I2C_SCL = 14, /* Digital Deep Sleep - scb[8].i2c_scl:1 */ - P6_4_SCB6_UART_RX = 18, /* Digital Active - scb[6].uart_rx:2 */ - P6_4_SCB6_I2C_SCL = 19, /* Digital Active - scb[6].i2c_scl:2 */ - P6_4_SCB6_SPI_MOSI = 20, /* Digital Active - scb[6].spi_mosi:2 */ - P6_4_PERI_TR_IO_INPUT12 = 24, /* Digital Active - peri.tr_io_input[12]:0 */ - P6_4_PERI_TR_IO_OUTPUT0 = 25, /* Digital Active - peri.tr_io_output[0]:1 */ - P6_4_CPUSS_SWJ_SWO_TDO = 29, /* Digital Deep Sleep - cpuss.swj_swo_tdo */ - P6_4_SCB8_SPI_MOSI = 30, /* Digital Deep Sleep - scb[8].spi_mosi:1 */ - P6_4_SRSS_DDFT_PIN_IN0 = 31, /* Digital Deep Sleep - srss.ddft_pin_in[0]:0 */ - - /* P6.5 */ - P6_5_GPIO = 0, /* GPIO controls 'out' */ - P6_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_5_AMUXA = 4, /* Analog mux bus A */ - P6_5_AMUXB = 5, /* Analog mux bus B */ - P6_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_5_TCPWM0_LINE_COMPL2 = 8, /* Digital Active - tcpwm[0].line_compl[2]:1 */ - P6_5_TCPWM1_LINE_COMPL10 = 9, /* Digital Active - tcpwm[1].line_compl[10]:0 */ - P6_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:43 */ - P6_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:43 */ - P6_5_LCD_COM43 = 12, /* Digital Deep Sleep - lcd.com[43]:0 */ - P6_5_LCD_SEG43 = 13, /* Digital Deep Sleep - lcd.seg[43]:0 */ - P6_5_SCB8_I2C_SDA = 14, /* Digital Deep Sleep - scb[8].i2c_sda:1 */ - P6_5_SCB6_UART_TX = 18, /* Digital Active - scb[6].uart_tx:2 */ - P6_5_SCB6_I2C_SDA = 19, /* Digital Active - scb[6].i2c_sda:2 */ - P6_5_SCB6_SPI_MISO = 20, /* Digital Active - scb[6].spi_miso:2 */ - P6_5_PERI_TR_IO_INPUT13 = 24, /* Digital Active - peri.tr_io_input[13]:0 */ - P6_5_PERI_TR_IO_OUTPUT1 = 25, /* Digital Active - peri.tr_io_output[1]:1 */ - P6_5_CPUSS_SWJ_SWDOE_TDI = 29, /* Digital Deep Sleep - cpuss.swj_swdoe_tdi */ - P6_5_SCB8_SPI_MISO = 30, /* Digital Deep Sleep - scb[8].spi_miso:1 */ - P6_5_SRSS_DDFT_PIN_IN1 = 31, /* Digital Deep Sleep - srss.ddft_pin_in[1]:0 */ - - /* P6.6 */ - P6_6_GPIO = 0, /* GPIO controls 'out' */ - P6_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_6_AMUXA = 4, /* Analog mux bus A */ - P6_6_AMUXB = 5, /* Analog mux bus B */ - P6_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_6_TCPWM0_LINE3 = 8, /* Digital Active - tcpwm[0].line[3]:1 */ - P6_6_TCPWM1_LINE11 = 9, /* Digital Active - tcpwm[1].line[11]:0 */ - P6_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:44 */ - P6_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:44 */ - P6_6_LCD_COM44 = 12, /* Digital Deep Sleep - lcd.com[44]:0 */ - P6_6_LCD_SEG44 = 13, /* Digital Deep Sleep - lcd.seg[44]:0 */ - P6_6_SCB6_UART_RTS = 18, /* Digital Active - scb[6].uart_rts:2 */ - P6_6_SCB6_SPI_CLK = 20, /* Digital Active - scb[6].spi_clk:2 */ - P6_6_CPUSS_SWJ_SWDIO_TMS = 29, /* Digital Deep Sleep - cpuss.swj_swdio_tms */ - P6_6_SCB8_SPI_CLK = 30, /* Digital Deep Sleep - scb[8].spi_clk:1 */ - - /* P6.7 */ - P6_7_GPIO = 0, /* GPIO controls 'out' */ - P6_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P6_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P6_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P6_7_AMUXA = 4, /* Analog mux bus A */ - P6_7_AMUXB = 5, /* Analog mux bus B */ - P6_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P6_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P6_7_TCPWM0_LINE_COMPL3 = 8, /* Digital Active - tcpwm[0].line_compl[3]:1 */ - P6_7_TCPWM1_LINE_COMPL11 = 9, /* Digital Active - tcpwm[1].line_compl[11]:0 */ - P6_7_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:45 */ - P6_7_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:45 */ - P6_7_LCD_COM45 = 12, /* Digital Deep Sleep - lcd.com[45]:0 */ - P6_7_LCD_SEG45 = 13, /* Digital Deep Sleep - lcd.seg[45]:0 */ - P6_7_SCB6_UART_CTS = 18, /* Digital Active - scb[6].uart_cts:2 */ - P6_7_SCB6_SPI_SELECT0 = 20, /* Digital Active - scb[6].spi_select0:2 */ - P6_7_CPUSS_SWJ_SWCLK_TCLK = 29, /* Digital Deep Sleep - cpuss.swj_swclk_tclk */ - P6_7_SCB8_SPI_SELECT0 = 30, /* Digital Deep Sleep - scb[8].spi_select0:1 */ - - /* P7.0 */ - P7_0_GPIO = 0, /* GPIO controls 'out' */ - P7_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_0_AMUXA = 4, /* Analog mux bus A */ - P7_0_AMUXB = 5, /* Analog mux bus B */ - P7_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_0_TCPWM0_LINE4 = 8, /* Digital Active - tcpwm[0].line[4]:1 */ - P7_0_TCPWM1_LINE12 = 9, /* Digital Active - tcpwm[1].line[12]:0 */ - P7_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:46 */ - P7_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:46 */ - P7_0_LCD_COM46 = 12, /* Digital Deep Sleep - lcd.com[46]:0 */ - P7_0_LCD_SEG46 = 13, /* Digital Deep Sleep - lcd.seg[46]:0 */ - P7_0_SCB4_UART_RX = 18, /* Digital Active - scb[4].uart_rx:1 */ - P7_0_SCB4_I2C_SCL = 19, /* Digital Active - scb[4].i2c_scl:1 */ - P7_0_SCB4_SPI_MOSI = 20, /* Digital Active - scb[4].spi_mosi:1 */ - P7_0_PERI_TR_IO_INPUT14 = 24, /* Digital Active - peri.tr_io_input[14]:0 */ - P7_0_CPUSS_TRACE_CLOCK = 26, /* Digital Active - cpuss.trace_clock */ - - /* P7.1 */ - P7_1_GPIO = 0, /* GPIO controls 'out' */ - P7_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_1_AMUXA = 4, /* Analog mux bus A */ - P7_1_AMUXB = 5, /* Analog mux bus B */ - P7_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_1_TCPWM0_LINE_COMPL4 = 8, /* Digital Active - tcpwm[0].line_compl[4]:1 */ - P7_1_TCPWM1_LINE_COMPL12 = 9, /* Digital Active - tcpwm[1].line_compl[12]:0 */ - P7_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:47 */ - P7_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:47 */ - P7_1_LCD_COM47 = 12, /* Digital Deep Sleep - lcd.com[47]:0 */ - P7_1_LCD_SEG47 = 13, /* Digital Deep Sleep - lcd.seg[47]:0 */ - P7_1_SCB4_UART_TX = 18, /* Digital Active - scb[4].uart_tx:1 */ - P7_1_SCB4_I2C_SDA = 19, /* Digital Active - scb[4].i2c_sda:1 */ - P7_1_SCB4_SPI_MISO = 20, /* Digital Active - scb[4].spi_miso:1 */ - P7_1_PERI_TR_IO_INPUT15 = 24, /* Digital Active - peri.tr_io_input[15]:0 */ - - /* P7.2 */ - P7_2_GPIO = 0, /* GPIO controls 'out' */ - P7_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_2_AMUXA = 4, /* Analog mux bus A */ - P7_2_AMUXB = 5, /* Analog mux bus B */ - P7_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_2_TCPWM0_LINE5 = 8, /* Digital Active - tcpwm[0].line[5]:1 */ - P7_2_TCPWM1_LINE13 = 9, /* Digital Active - tcpwm[1].line[13]:0 */ - P7_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:48 */ - P7_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:48 */ - P7_2_LCD_COM48 = 12, /* Digital Deep Sleep - lcd.com[48]:0 */ - P7_2_LCD_SEG48 = 13, /* Digital Deep Sleep - lcd.seg[48]:0 */ - P7_2_SCB4_UART_RTS = 18, /* Digital Active - scb[4].uart_rts:1 */ - P7_2_SCB4_SPI_CLK = 20, /* Digital Active - scb[4].spi_clk:1 */ - - /* P7.3 */ - P7_3_GPIO = 0, /* GPIO controls 'out' */ - P7_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_3_AMUXA = 4, /* Analog mux bus A */ - P7_3_AMUXB = 5, /* Analog mux bus B */ - P7_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_3_TCPWM0_LINE_COMPL5 = 8, /* Digital Active - tcpwm[0].line_compl[5]:1 */ - P7_3_TCPWM1_LINE_COMPL13 = 9, /* Digital Active - tcpwm[1].line_compl[13]:0 */ - P7_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:49 */ - P7_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:49 */ - P7_3_LCD_COM49 = 12, /* Digital Deep Sleep - lcd.com[49]:0 */ - P7_3_LCD_SEG49 = 13, /* Digital Deep Sleep - lcd.seg[49]:0 */ - P7_3_SCB4_UART_CTS = 18, /* Digital Active - scb[4].uart_cts:1 */ - P7_3_SCB4_SPI_SELECT0 = 20, /* Digital Active - scb[4].spi_select0:1 */ - - /* P7.4 */ - P7_4_GPIO = 0, /* GPIO controls 'out' */ - P7_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_4_AMUXA = 4, /* Analog mux bus A */ - P7_4_AMUXB = 5, /* Analog mux bus B */ - P7_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_4_TCPWM0_LINE6 = 8, /* Digital Active - tcpwm[0].line[6]:1 */ - P7_4_TCPWM1_LINE14 = 9, /* Digital Active - tcpwm[1].line[14]:0 */ - P7_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:50 */ - P7_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:50 */ - P7_4_LCD_COM50 = 12, /* Digital Deep Sleep - lcd.com[50]:0 */ - P7_4_LCD_SEG50 = 13, /* Digital Deep Sleep - lcd.seg[50]:0 */ - P7_4_SCB4_SPI_SELECT1 = 20, /* Digital Active - scb[4].spi_select1:1 */ - P7_4_BLESS_EXT_LNA_RX_CTL_OUT = 26, /* Digital Active - bless.ext_lna_rx_ctl_out */ - P7_4_CPUSS_TRACE_DATA3 = 27, /* Digital Active - cpuss.trace_data[3]:2 */ - - /* P7.5 */ - P7_5_GPIO = 0, /* GPIO controls 'out' */ - P7_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_5_AMUXA = 4, /* Analog mux bus A */ - P7_5_AMUXB = 5, /* Analog mux bus B */ - P7_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_5_TCPWM0_LINE_COMPL6 = 8, /* Digital Active - tcpwm[0].line_compl[6]:1 */ - P7_5_TCPWM1_LINE_COMPL14 = 9, /* Digital Active - tcpwm[1].line_compl[14]:0 */ - P7_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:51 */ - P7_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:51 */ - P7_5_LCD_COM51 = 12, /* Digital Deep Sleep - lcd.com[51]:0 */ - P7_5_LCD_SEG51 = 13, /* Digital Deep Sleep - lcd.seg[51]:0 */ - P7_5_SCB4_SPI_SELECT2 = 20, /* Digital Active - scb[4].spi_select2:1 */ - P7_5_BLESS_EXT_PA_TX_CTL_OUT = 26, /* Digital Active - bless.ext_pa_tx_ctl_out */ - P7_5_CPUSS_TRACE_DATA2 = 27, /* Digital Active - cpuss.trace_data[2]:2 */ - - /* P7.6 */ - P7_6_GPIO = 0, /* GPIO controls 'out' */ - P7_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_6_AMUXA = 4, /* Analog mux bus A */ - P7_6_AMUXB = 5, /* Analog mux bus B */ - P7_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_6_TCPWM0_LINE7 = 8, /* Digital Active - tcpwm[0].line[7]:1 */ - P7_6_TCPWM1_LINE15 = 9, /* Digital Active - tcpwm[1].line[15]:0 */ - P7_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:52 */ - P7_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:52 */ - P7_6_LCD_COM52 = 12, /* Digital Deep Sleep - lcd.com[52]:0 */ - P7_6_LCD_SEG52 = 13, /* Digital Deep Sleep - lcd.seg[52]:0 */ - P7_6_SCB4_SPI_SELECT3 = 20, /* Digital Active - scb[4].spi_select3:1 */ - P7_6_BLESS_EXT_PA_LNA_CHIP_EN_OUT = 26, /* Digital Active - bless.ext_pa_lna_chip_en_out */ - P7_6_CPUSS_TRACE_DATA1 = 27, /* Digital Active - cpuss.trace_data[1]:2 */ - - /* P7.7 */ - P7_7_GPIO = 0, /* GPIO controls 'out' */ - P7_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P7_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P7_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P7_7_AMUXA = 4, /* Analog mux bus A */ - P7_7_AMUXB = 5, /* Analog mux bus B */ - P7_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P7_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P7_7_TCPWM0_LINE_COMPL7 = 8, /* Digital Active - tcpwm[0].line_compl[7]:1 */ - P7_7_TCPWM1_LINE_COMPL15 = 9, /* Digital Active - tcpwm[1].line_compl[15]:0 */ - P7_7_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:53 */ - P7_7_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:53 */ - P7_7_LCD_COM53 = 12, /* Digital Deep Sleep - lcd.com[53]:0 */ - P7_7_LCD_SEG53 = 13, /* Digital Deep Sleep - lcd.seg[53]:0 */ - P7_7_SCB3_SPI_SELECT1 = 20, /* Digital Active - scb[3].spi_select1:0 */ - P7_7_CPUSS_CLK_FM_PUMP = 21, /* Digital Active - cpuss.clk_fm_pump */ - P7_7_CPUSS_TRACE_DATA0 = 27, /* Digital Active - cpuss.trace_data[0]:2 */ - - /* P8.0 */ - P8_0_GPIO = 0, /* GPIO controls 'out' */ - P8_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_0_AMUXA = 4, /* Analog mux bus A */ - P8_0_AMUXB = 5, /* Analog mux bus B */ - P8_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_0_TCPWM0_LINE0 = 8, /* Digital Active - tcpwm[0].line[0]:2 */ - P8_0_TCPWM1_LINE16 = 9, /* Digital Active - tcpwm[1].line[16]:0 */ - P8_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:54 */ - P8_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:54 */ - P8_0_LCD_COM54 = 12, /* Digital Deep Sleep - lcd.com[54]:0 */ - P8_0_LCD_SEG54 = 13, /* Digital Deep Sleep - lcd.seg[54]:0 */ - P8_0_SCB4_UART_RX = 18, /* Digital Active - scb[4].uart_rx:0 */ - P8_0_SCB4_I2C_SCL = 19, /* Digital Active - scb[4].i2c_scl:0 */ - P8_0_SCB4_SPI_MOSI = 20, /* Digital Active - scb[4].spi_mosi:0 */ - P8_0_PERI_TR_IO_INPUT16 = 24, /* Digital Active - peri.tr_io_input[16]:0 */ - - /* P8.1 */ - P8_1_GPIO = 0, /* GPIO controls 'out' */ - P8_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_1_AMUXA = 4, /* Analog mux bus A */ - P8_1_AMUXB = 5, /* Analog mux bus B */ - P8_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_1_TCPWM0_LINE_COMPL0 = 8, /* Digital Active - tcpwm[0].line_compl[0]:2 */ - P8_1_TCPWM1_LINE_COMPL16 = 9, /* Digital Active - tcpwm[1].line_compl[16]:0 */ - P8_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:55 */ - P8_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:55 */ - P8_1_LCD_COM55 = 12, /* Digital Deep Sleep - lcd.com[55]:0 */ - P8_1_LCD_SEG55 = 13, /* Digital Deep Sleep - lcd.seg[55]:0 */ - P8_1_SCB4_UART_TX = 18, /* Digital Active - scb[4].uart_tx:0 */ - P8_1_SCB4_I2C_SDA = 19, /* Digital Active - scb[4].i2c_sda:0 */ - P8_1_SCB4_SPI_MISO = 20, /* Digital Active - scb[4].spi_miso:0 */ - P8_1_PERI_TR_IO_INPUT17 = 24, /* Digital Active - peri.tr_io_input[17]:0 */ - - /* P8.2 */ - P8_2_GPIO = 0, /* GPIO controls 'out' */ - P8_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_2_AMUXA = 4, /* Analog mux bus A */ - P8_2_AMUXB = 5, /* Analog mux bus B */ - P8_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_2_TCPWM0_LINE1 = 8, /* Digital Active - tcpwm[0].line[1]:2 */ - P8_2_TCPWM1_LINE17 = 9, /* Digital Active - tcpwm[1].line[17]:0 */ - P8_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:56 */ - P8_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:56 */ - P8_2_LCD_COM56 = 12, /* Digital Deep Sleep - lcd.com[56]:0 */ - P8_2_LCD_SEG56 = 13, /* Digital Deep Sleep - lcd.seg[56]:0 */ - P8_2_LPCOMP_DSI_COMP0 = 15, /* Digital Deep Sleep - lpcomp.dsi_comp0:0 */ - P8_2_SCB4_UART_RTS = 18, /* Digital Active - scb[4].uart_rts:0 */ - P8_2_SCB4_SPI_CLK = 20, /* Digital Active - scb[4].spi_clk:0 */ - - /* P8.3 */ - P8_3_GPIO = 0, /* GPIO controls 'out' */ - P8_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_3_AMUXA = 4, /* Analog mux bus A */ - P8_3_AMUXB = 5, /* Analog mux bus B */ - P8_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_3_TCPWM0_LINE_COMPL1 = 8, /* Digital Active - tcpwm[0].line_compl[1]:2 */ - P8_3_TCPWM1_LINE_COMPL17 = 9, /* Digital Active - tcpwm[1].line_compl[17]:0 */ - P8_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:57 */ - P8_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:57 */ - P8_3_LCD_COM57 = 12, /* Digital Deep Sleep - lcd.com[57]:0 */ - P8_3_LCD_SEG57 = 13, /* Digital Deep Sleep - lcd.seg[57]:0 */ - P8_3_LPCOMP_DSI_COMP1 = 15, /* Digital Deep Sleep - lpcomp.dsi_comp1:0 */ - P8_3_SCB4_UART_CTS = 18, /* Digital Active - scb[4].uart_cts:0 */ - P8_3_SCB4_SPI_SELECT0 = 20, /* Digital Active - scb[4].spi_select0:0 */ - - /* P8.4 */ - P8_4_GPIO = 0, /* GPIO controls 'out' */ - P8_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_4_AMUXA = 4, /* Analog mux bus A */ - P8_4_AMUXB = 5, /* Analog mux bus B */ - P8_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_4_TCPWM0_LINE2 = 8, /* Digital Active - tcpwm[0].line[2]:2 */ - P8_4_TCPWM1_LINE18 = 9, /* Digital Active - tcpwm[1].line[18]:0 */ - P8_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:58 */ - P8_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:58 */ - P8_4_LCD_COM58 = 12, /* Digital Deep Sleep - lcd.com[58]:0 */ - P8_4_LCD_SEG58 = 13, /* Digital Deep Sleep - lcd.seg[58]:0 */ - P8_4_SCB4_SPI_SELECT1 = 20, /* Digital Active - scb[4].spi_select1:0 */ - - /* P8.5 */ - P8_5_GPIO = 0, /* GPIO controls 'out' */ - P8_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_5_AMUXA = 4, /* Analog mux bus A */ - P8_5_AMUXB = 5, /* Analog mux bus B */ - P8_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_5_TCPWM0_LINE_COMPL2 = 8, /* Digital Active - tcpwm[0].line_compl[2]:2 */ - P8_5_TCPWM1_LINE_COMPL18 = 9, /* Digital Active - tcpwm[1].line_compl[18]:0 */ - P8_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:59 */ - P8_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:59 */ - P8_5_LCD_COM59 = 12, /* Digital Deep Sleep - lcd.com[59]:0 */ - P8_5_LCD_SEG59 = 13, /* Digital Deep Sleep - lcd.seg[59]:0 */ - P8_5_SCB4_SPI_SELECT2 = 20, /* Digital Active - scb[4].spi_select2:0 */ - - /* P8.6 */ - P8_6_GPIO = 0, /* GPIO controls 'out' */ - P8_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_6_AMUXA = 4, /* Analog mux bus A */ - P8_6_AMUXB = 5, /* Analog mux bus B */ - P8_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_6_TCPWM0_LINE3 = 8, /* Digital Active - tcpwm[0].line[3]:2 */ - P8_6_TCPWM1_LINE19 = 9, /* Digital Active - tcpwm[1].line[19]:0 */ - P8_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:60 */ - P8_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:60 */ - P8_6_LCD_COM60 = 12, /* Digital Deep Sleep - lcd.com[60]:0 */ - P8_6_LCD_SEG60 = 13, /* Digital Deep Sleep - lcd.seg[60]:0 */ - P8_6_SCB4_SPI_SELECT3 = 20, /* Digital Active - scb[4].spi_select3:0 */ - - /* P8.7 */ - P8_7_GPIO = 0, /* GPIO controls 'out' */ - P8_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P8_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P8_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P8_7_AMUXA = 4, /* Analog mux bus A */ - P8_7_AMUXB = 5, /* Analog mux bus B */ - P8_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P8_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P8_7_TCPWM0_LINE_COMPL3 = 8, /* Digital Active - tcpwm[0].line_compl[3]:2 */ - P8_7_TCPWM1_LINE_COMPL19 = 9, /* Digital Active - tcpwm[1].line_compl[19]:0 */ - P8_7_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:61 */ - P8_7_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:61 */ - P8_7_LCD_COM61 = 12, /* Digital Deep Sleep - lcd.com[61]:0 */ - P8_7_LCD_SEG61 = 13, /* Digital Deep Sleep - lcd.seg[61]:0 */ - P8_7_SCB3_SPI_SELECT2 = 20, /* Digital Active - scb[3].spi_select2:0 */ - - /* P9.0 */ - P9_0_GPIO = 0, /* GPIO controls 'out' */ - P9_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_0_AMUXA = 4, /* Analog mux bus A */ - P9_0_AMUXB = 5, /* Analog mux bus B */ - P9_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_0_TCPWM0_LINE4 = 8, /* Digital Active - tcpwm[0].line[4]:2 */ - P9_0_TCPWM1_LINE20 = 9, /* Digital Active - tcpwm[1].line[20]:0 */ - P9_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:62 */ - P9_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:62 */ - P9_0_LCD_COM0 = 12, /* Digital Deep Sleep - lcd.com[0]:1 */ - P9_0_LCD_SEG0 = 13, /* Digital Deep Sleep - lcd.seg[0]:1 */ - P9_0_SCB2_UART_RX = 18, /* Digital Active - scb[2].uart_rx:0 */ - P9_0_SCB2_I2C_SCL = 19, /* Digital Active - scb[2].i2c_scl:0 */ - P9_0_SCB2_SPI_MOSI = 20, /* Digital Active - scb[2].spi_mosi:0 */ - P9_0_PERI_TR_IO_INPUT18 = 24, /* Digital Active - peri.tr_io_input[18]:0 */ - P9_0_CPUSS_TRACE_DATA3 = 27, /* Digital Active - cpuss.trace_data[3]:0 */ - - /* P9.1 */ - P9_1_GPIO = 0, /* GPIO controls 'out' */ - P9_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_1_AMUXA = 4, /* Analog mux bus A */ - P9_1_AMUXB = 5, /* Analog mux bus B */ - P9_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_1_TCPWM0_LINE_COMPL4 = 8, /* Digital Active - tcpwm[0].line_compl[4]:2 */ - P9_1_TCPWM1_LINE_COMPL20 = 9, /* Digital Active - tcpwm[1].line_compl[20]:0 */ - P9_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:63 */ - P9_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:63 */ - P9_1_LCD_COM1 = 12, /* Digital Deep Sleep - lcd.com[1]:1 */ - P9_1_LCD_SEG1 = 13, /* Digital Deep Sleep - lcd.seg[1]:1 */ - P9_1_SCB2_UART_TX = 18, /* Digital Active - scb[2].uart_tx:0 */ - P9_1_SCB2_I2C_SDA = 19, /* Digital Active - scb[2].i2c_sda:0 */ - P9_1_SCB2_SPI_MISO = 20, /* Digital Active - scb[2].spi_miso:0 */ - P9_1_PERI_TR_IO_INPUT19 = 24, /* Digital Active - peri.tr_io_input[19]:0 */ - P9_1_CPUSS_TRACE_DATA2 = 27, /* Digital Active - cpuss.trace_data[2]:0 */ - P9_1_SRSS_DDFT_PIN_IN0 = 31, /* Digital Deep Sleep - srss.ddft_pin_in[0]:1 */ - - /* P9.2 */ - P9_2_GPIO = 0, /* GPIO controls 'out' */ - P9_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_2_AMUXA = 4, /* Analog mux bus A */ - P9_2_AMUXB = 5, /* Analog mux bus B */ - P9_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_2_TCPWM0_LINE5 = 8, /* Digital Active - tcpwm[0].line[5]:2 */ - P9_2_TCPWM1_LINE21 = 9, /* Digital Active - tcpwm[1].line[21]:0 */ - P9_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:64 */ - P9_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:64 */ - P9_2_LCD_COM2 = 12, /* Digital Deep Sleep - lcd.com[2]:1 */ - P9_2_LCD_SEG2 = 13, /* Digital Deep Sleep - lcd.seg[2]:1 */ - P9_2_SCB2_UART_RTS = 18, /* Digital Active - scb[2].uart_rts:0 */ - P9_2_SCB2_SPI_CLK = 20, /* Digital Active - scb[2].spi_clk:0 */ - P9_2_PASS_DSI_CTB_CMP0 = 22, /* Digital Active - pass.dsi_ctb_cmp0:1 */ - P9_2_CPUSS_TRACE_DATA1 = 27, /* Digital Active - cpuss.trace_data[1]:0 */ - - /* P9.3 */ - P9_3_GPIO = 0, /* GPIO controls 'out' */ - P9_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_3_AMUXA = 4, /* Analog mux bus A */ - P9_3_AMUXB = 5, /* Analog mux bus B */ - P9_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_3_TCPWM0_LINE_COMPL5 = 8, /* Digital Active - tcpwm[0].line_compl[5]:2 */ - P9_3_TCPWM1_LINE_COMPL21 = 9, /* Digital Active - tcpwm[1].line_compl[21]:0 */ - P9_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:65 */ - P9_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:65 */ - P9_3_LCD_COM3 = 12, /* Digital Deep Sleep - lcd.com[3]:1 */ - P9_3_LCD_SEG3 = 13, /* Digital Deep Sleep - lcd.seg[3]:1 */ - P9_3_SCB2_UART_CTS = 18, /* Digital Active - scb[2].uart_cts:0 */ - P9_3_SCB2_SPI_SELECT0 = 20, /* Digital Active - scb[2].spi_select0:0 */ - P9_3_PASS_DSI_CTB_CMP1 = 22, /* Digital Active - pass.dsi_ctb_cmp1:1 */ - P9_3_CPUSS_TRACE_DATA0 = 27, /* Digital Active - cpuss.trace_data[0]:0 */ - P9_3_SRSS_DDFT_PIN_IN1 = 31, /* Digital Deep Sleep - srss.ddft_pin_in[1]:1 */ - - /* P9.4 */ - P9_4_GPIO = 0, /* GPIO controls 'out' */ - P9_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_4_AMUXA = 4, /* Analog mux bus A */ - P9_4_AMUXB = 5, /* Analog mux bus B */ - P9_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_4_TCPWM0_LINE7 = 8, /* Digital Active - tcpwm[0].line[7]:5 */ - P9_4_TCPWM1_LINE0 = 9, /* Digital Active - tcpwm[1].line[0]:2 */ - P9_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:66 */ - P9_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:66 */ - P9_4_LCD_COM4 = 12, /* Digital Deep Sleep - lcd.com[4]:1 */ - P9_4_LCD_SEG4 = 13, /* Digital Deep Sleep - lcd.seg[4]:1 */ - P9_4_SCB2_SPI_SELECT1 = 20, /* Digital Active - scb[2].spi_select1:0 */ - - /* P9.5 */ - P9_5_GPIO = 0, /* GPIO controls 'out' */ - P9_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_5_AMUXA = 4, /* Analog mux bus A */ - P9_5_AMUXB = 5, /* Analog mux bus B */ - P9_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_5_TCPWM0_LINE_COMPL7 = 8, /* Digital Active - tcpwm[0].line_compl[7]:5 */ - P9_5_TCPWM1_LINE_COMPL0 = 9, /* Digital Active - tcpwm[1].line_compl[0]:2 */ - P9_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:67 */ - P9_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:67 */ - P9_5_LCD_COM5 = 12, /* Digital Deep Sleep - lcd.com[5]:1 */ - P9_5_LCD_SEG5 = 13, /* Digital Deep Sleep - lcd.seg[5]:1 */ - P9_5_SCB2_SPI_SELECT2 = 20, /* Digital Active - scb[2].spi_select2:0 */ - - /* P9.6 */ - P9_6_GPIO = 0, /* GPIO controls 'out' */ - P9_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_6_AMUXA = 4, /* Analog mux bus A */ - P9_6_AMUXB = 5, /* Analog mux bus B */ - P9_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_6_TCPWM0_LINE0 = 8, /* Digital Active - tcpwm[0].line[0]:6 */ - P9_6_TCPWM1_LINE1 = 9, /* Digital Active - tcpwm[1].line[1]:2 */ - P9_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:68 */ - P9_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:68 */ - P9_6_LCD_COM6 = 12, /* Digital Deep Sleep - lcd.com[6]:1 */ - P9_6_LCD_SEG6 = 13, /* Digital Deep Sleep - lcd.seg[6]:1 */ - P9_6_SCB2_SPI_SELECT3 = 20, /* Digital Active - scb[2].spi_select3:0 */ - - /* P9.7 */ - P9_7_GPIO = 0, /* GPIO controls 'out' */ - P9_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P9_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P9_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P9_7_AMUXA = 4, /* Analog mux bus A */ - P9_7_AMUXB = 5, /* Analog mux bus B */ - P9_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P9_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P9_7_TCPWM0_LINE_COMPL0 = 8, /* Digital Active - tcpwm[0].line_compl[0]:6 */ - P9_7_TCPWM1_LINE_COMPL1 = 9, /* Digital Active - tcpwm[1].line_compl[1]:2 */ - P9_7_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:69 */ - P9_7_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:69 */ - P9_7_LCD_COM7 = 12, /* Digital Deep Sleep - lcd.com[7]:1 */ - P9_7_LCD_SEG7 = 13, /* Digital Deep Sleep - lcd.seg[7]:1 */ - - /* P10.0 */ - P10_0_GPIO = 0, /* GPIO controls 'out' */ - P10_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_0_AMUXA = 4, /* Analog mux bus A */ - P10_0_AMUXB = 5, /* Analog mux bus B */ - P10_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_0_TCPWM0_LINE6 = 8, /* Digital Active - tcpwm[0].line[6]:2 */ - P10_0_TCPWM1_LINE22 = 9, /* Digital Active - tcpwm[1].line[22]:0 */ - P10_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:70 */ - P10_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:70 */ - P10_0_LCD_COM8 = 12, /* Digital Deep Sleep - lcd.com[8]:1 */ - P10_0_LCD_SEG8 = 13, /* Digital Deep Sleep - lcd.seg[8]:1 */ - P10_0_SCB1_UART_RX = 18, /* Digital Active - scb[1].uart_rx:1 */ - P10_0_SCB1_I2C_SCL = 19, /* Digital Active - scb[1].i2c_scl:1 */ - P10_0_SCB1_SPI_MOSI = 20, /* Digital Active - scb[1].spi_mosi:1 */ - P10_0_PERI_TR_IO_INPUT20 = 24, /* Digital Active - peri.tr_io_input[20]:0 */ - P10_0_CPUSS_TRACE_DATA3 = 27, /* Digital Active - cpuss.trace_data[3]:1 */ - - /* P10.1 */ - P10_1_GPIO = 0, /* GPIO controls 'out' */ - P10_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_1_AMUXA = 4, /* Analog mux bus A */ - P10_1_AMUXB = 5, /* Analog mux bus B */ - P10_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_1_TCPWM0_LINE_COMPL6 = 8, /* Digital Active - tcpwm[0].line_compl[6]:2 */ - P10_1_TCPWM1_LINE_COMPL22 = 9, /* Digital Active - tcpwm[1].line_compl[22]:0 */ - P10_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:71 */ - P10_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:71 */ - P10_1_LCD_COM9 = 12, /* Digital Deep Sleep - lcd.com[9]:1 */ - P10_1_LCD_SEG9 = 13, /* Digital Deep Sleep - lcd.seg[9]:1 */ - P10_1_SCB1_UART_TX = 18, /* Digital Active - scb[1].uart_tx:1 */ - P10_1_SCB1_I2C_SDA = 19, /* Digital Active - scb[1].i2c_sda:1 */ - P10_1_SCB1_SPI_MISO = 20, /* Digital Active - scb[1].spi_miso:1 */ - P10_1_PERI_TR_IO_INPUT21 = 24, /* Digital Active - peri.tr_io_input[21]:0 */ - P10_1_CPUSS_TRACE_DATA2 = 27, /* Digital Active - cpuss.trace_data[2]:1 */ - - /* P10.2 */ - P10_2_GPIO = 0, /* GPIO controls 'out' */ - P10_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_2_AMUXA = 4, /* Analog mux bus A */ - P10_2_AMUXB = 5, /* Analog mux bus B */ - P10_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_2_TCPWM0_LINE7 = 8, /* Digital Active - tcpwm[0].line[7]:2 */ - P10_2_TCPWM1_LINE23 = 9, /* Digital Active - tcpwm[1].line[23]:0 */ - P10_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:72 */ - P10_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:72 */ - P10_2_LCD_COM10 = 12, /* Digital Deep Sleep - lcd.com[10]:1 */ - P10_2_LCD_SEG10 = 13, /* Digital Deep Sleep - lcd.seg[10]:1 */ - P10_2_SCB1_UART_RTS = 18, /* Digital Active - scb[1].uart_rts:1 */ - P10_2_SCB1_SPI_CLK = 20, /* Digital Active - scb[1].spi_clk:1 */ - P10_2_CPUSS_TRACE_DATA1 = 27, /* Digital Active - cpuss.trace_data[1]:1 */ - - /* P10.3 */ - P10_3_GPIO = 0, /* GPIO controls 'out' */ - P10_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_3_AMUXA = 4, /* Analog mux bus A */ - P10_3_AMUXB = 5, /* Analog mux bus B */ - P10_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_3_TCPWM0_LINE_COMPL7 = 8, /* Digital Active - tcpwm[0].line_compl[7]:2 */ - P10_3_TCPWM1_LINE_COMPL23 = 9, /* Digital Active - tcpwm[1].line_compl[23]:0 */ - P10_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:73 */ - P10_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:73 */ - P10_3_LCD_COM11 = 12, /* Digital Deep Sleep - lcd.com[11]:1 */ - P10_3_LCD_SEG11 = 13, /* Digital Deep Sleep - lcd.seg[11]:1 */ - P10_3_SCB1_UART_CTS = 18, /* Digital Active - scb[1].uart_cts:1 */ - P10_3_SCB1_SPI_SELECT0 = 20, /* Digital Active - scb[1].spi_select0:1 */ - P10_3_CPUSS_TRACE_DATA0 = 27, /* Digital Active - cpuss.trace_data[0]:1 */ - - /* P10.4 */ - P10_4_GPIO = 0, /* GPIO controls 'out' */ - P10_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_4_AMUXA = 4, /* Analog mux bus A */ - P10_4_AMUXB = 5, /* Analog mux bus B */ - P10_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_4_TCPWM0_LINE0 = 8, /* Digital Active - tcpwm[0].line[0]:3 */ - P10_4_TCPWM1_LINE0 = 9, /* Digital Active - tcpwm[1].line[0]:1 */ - P10_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:74 */ - P10_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:74 */ - P10_4_LCD_COM12 = 12, /* Digital Deep Sleep - lcd.com[12]:1 */ - P10_4_LCD_SEG12 = 13, /* Digital Deep Sleep - lcd.seg[12]:1 */ - P10_4_SCB1_SPI_SELECT1 = 20, /* Digital Active - scb[1].spi_select1:1 */ - P10_4_AUDIOSS_PDM_CLK = 21, /* Digital Active - audioss.pdm_clk */ - - /* P10.5 */ - P10_5_GPIO = 0, /* GPIO controls 'out' */ - P10_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_5_AMUXA = 4, /* Analog mux bus A */ - P10_5_AMUXB = 5, /* Analog mux bus B */ - P10_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_5_TCPWM0_LINE_COMPL0 = 8, /* Digital Active - tcpwm[0].line_compl[0]:3 */ - P10_5_TCPWM1_LINE_COMPL0 = 9, /* Digital Active - tcpwm[1].line_compl[0]:1 */ - P10_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:75 */ - P10_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:75 */ - P10_5_LCD_COM13 = 12, /* Digital Deep Sleep - lcd.com[13]:1 */ - P10_5_LCD_SEG13 = 13, /* Digital Deep Sleep - lcd.seg[13]:1 */ - P10_5_SCB1_SPI_SELECT2 = 20, /* Digital Active - scb[1].spi_select2:1 */ - P10_5_AUDIOSS_PDM_DATA = 21, /* Digital Active - audioss.pdm_data */ - - /* P10.6 */ - P10_6_GPIO = 0, /* GPIO controls 'out' */ - P10_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P10_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P10_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P10_6_AMUXA = 4, /* Analog mux bus A */ - P10_6_AMUXB = 5, /* Analog mux bus B */ - P10_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P10_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P10_6_TCPWM0_LINE1 = 8, /* Digital Active - tcpwm[0].line[1]:6 */ - P10_6_TCPWM1_LINE2 = 9, /* Digital Active - tcpwm[1].line[2]:2 */ - P10_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:76 */ - P10_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:76 */ - P10_6_LCD_COM14 = 12, /* Digital Deep Sleep - lcd.com[14]:1 */ - P10_6_LCD_SEG14 = 13, /* Digital Deep Sleep - lcd.seg[14]:1 */ - P10_6_SCB1_SPI_SELECT3 = 20, /* Digital Active - scb[1].spi_select3:1 */ - - /* P11.0 */ - P11_0_GPIO = 0, /* GPIO controls 'out' */ - P11_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_0_AMUXA = 4, /* Analog mux bus A */ - P11_0_AMUXB = 5, /* Analog mux bus B */ - P11_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_0_TCPWM0_LINE1 = 8, /* Digital Active - tcpwm[0].line[1]:3 */ - P11_0_TCPWM1_LINE1 = 9, /* Digital Active - tcpwm[1].line[1]:1 */ - P11_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:78 */ - P11_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:78 */ - P11_0_LCD_COM16 = 12, /* Digital Deep Sleep - lcd.com[16]:1 */ - P11_0_LCD_SEG16 = 13, /* Digital Deep Sleep - lcd.seg[16]:1 */ - P11_0_SMIF_SPI_SELECT2 = 17, /* Digital Active - smif.spi_select2 */ - P11_0_SCB5_UART_RX = 18, /* Digital Active - scb[5].uart_rx:1 */ - P11_0_SCB5_I2C_SCL = 19, /* Digital Active - scb[5].i2c_scl:1 */ - P11_0_SCB5_SPI_MOSI = 20, /* Digital Active - scb[5].spi_mosi:1 */ - P11_0_PERI_TR_IO_INPUT22 = 24, /* Digital Active - peri.tr_io_input[22]:0 */ - - /* P11.1 */ - P11_1_GPIO = 0, /* GPIO controls 'out' */ - P11_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_1_AMUXA = 4, /* Analog mux bus A */ - P11_1_AMUXB = 5, /* Analog mux bus B */ - P11_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_1_TCPWM0_LINE_COMPL1 = 8, /* Digital Active - tcpwm[0].line_compl[1]:3 */ - P11_1_TCPWM1_LINE_COMPL1 = 9, /* Digital Active - tcpwm[1].line_compl[1]:1 */ - P11_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:79 */ - P11_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:79 */ - P11_1_LCD_COM17 = 12, /* Digital Deep Sleep - lcd.com[17]:1 */ - P11_1_LCD_SEG17 = 13, /* Digital Deep Sleep - lcd.seg[17]:1 */ - P11_1_SMIF_SPI_SELECT1 = 17, /* Digital Active - smif.spi_select1 */ - P11_1_SCB5_UART_TX = 18, /* Digital Active - scb[5].uart_tx:1 */ - P11_1_SCB5_I2C_SDA = 19, /* Digital Active - scb[5].i2c_sda:1 */ - P11_1_SCB5_SPI_MISO = 20, /* Digital Active - scb[5].spi_miso:1 */ - P11_1_PERI_TR_IO_INPUT23 = 24, /* Digital Active - peri.tr_io_input[23]:0 */ - - /* P11.2 */ - P11_2_GPIO = 0, /* GPIO controls 'out' */ - P11_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_2_AMUXA = 4, /* Analog mux bus A */ - P11_2_AMUXB = 5, /* Analog mux bus B */ - P11_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_2_TCPWM0_LINE2 = 8, /* Digital Active - tcpwm[0].line[2]:3 */ - P11_2_TCPWM1_LINE2 = 9, /* Digital Active - tcpwm[1].line[2]:1 */ - P11_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:80 */ - P11_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:80 */ - P11_2_LCD_COM18 = 12, /* Digital Deep Sleep - lcd.com[18]:1 */ - P11_2_LCD_SEG18 = 13, /* Digital Deep Sleep - lcd.seg[18]:1 */ - P11_2_SMIF_SPI_SELECT0 = 17, /* Digital Active - smif.spi_select0 */ - P11_2_SCB5_UART_RTS = 18, /* Digital Active - scb[5].uart_rts:1 */ - P11_2_SCB5_SPI_CLK = 20, /* Digital Active - scb[5].spi_clk:1 */ - - /* P11.3 */ - P11_3_GPIO = 0, /* GPIO controls 'out' */ - P11_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_3_AMUXA = 4, /* Analog mux bus A */ - P11_3_AMUXB = 5, /* Analog mux bus B */ - P11_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_3_TCPWM0_LINE_COMPL2 = 8, /* Digital Active - tcpwm[0].line_compl[2]:3 */ - P11_3_TCPWM1_LINE_COMPL2 = 9, /* Digital Active - tcpwm[1].line_compl[2]:1 */ - P11_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:81 */ - P11_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:81 */ - P11_3_LCD_COM19 = 12, /* Digital Deep Sleep - lcd.com[19]:1 */ - P11_3_LCD_SEG19 = 13, /* Digital Deep Sleep - lcd.seg[19]:1 */ - P11_3_SMIF_SPI_DATA3 = 17, /* Digital Active - smif.spi_data3 */ - P11_3_SCB5_UART_CTS = 18, /* Digital Active - scb[5].uart_cts:1 */ - P11_3_SCB5_SPI_SELECT0 = 20, /* Digital Active - scb[5].spi_select0:1 */ - P11_3_PERI_TR_IO_OUTPUT0 = 25, /* Digital Active - peri.tr_io_output[0]:0 */ - - /* P11.4 */ - P11_4_GPIO = 0, /* GPIO controls 'out' */ - P11_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_4_AMUXA = 4, /* Analog mux bus A */ - P11_4_AMUXB = 5, /* Analog mux bus B */ - P11_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_4_TCPWM0_LINE3 = 8, /* Digital Active - tcpwm[0].line[3]:3 */ - P11_4_TCPWM1_LINE3 = 9, /* Digital Active - tcpwm[1].line[3]:1 */ - P11_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:82 */ - P11_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:82 */ - P11_4_LCD_COM20 = 12, /* Digital Deep Sleep - lcd.com[20]:1 */ - P11_4_LCD_SEG20 = 13, /* Digital Deep Sleep - lcd.seg[20]:1 */ - P11_4_SMIF_SPI_DATA2 = 17, /* Digital Active - smif.spi_data2 */ - P11_4_SCB5_SPI_SELECT1 = 20, /* Digital Active - scb[5].spi_select1:1 */ - P11_4_PERI_TR_IO_OUTPUT1 = 25, /* Digital Active - peri.tr_io_output[1]:0 */ - - /* P11.5 */ - P11_5_GPIO = 0, /* GPIO controls 'out' */ - P11_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_5_AMUXA = 4, /* Analog mux bus A */ - P11_5_AMUXB = 5, /* Analog mux bus B */ - P11_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_5_TCPWM0_LINE_COMPL3 = 8, /* Digital Active - tcpwm[0].line_compl[3]:3 */ - P11_5_TCPWM1_LINE_COMPL3 = 9, /* Digital Active - tcpwm[1].line_compl[3]:1 */ - P11_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:83 */ - P11_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:83 */ - P11_5_LCD_COM21 = 12, /* Digital Deep Sleep - lcd.com[21]:1 */ - P11_5_LCD_SEG21 = 13, /* Digital Deep Sleep - lcd.seg[21]:1 */ - P11_5_SMIF_SPI_DATA1 = 17, /* Digital Active - smif.spi_data1 */ - P11_5_SCB5_SPI_SELECT2 = 20, /* Digital Active - scb[5].spi_select2:1 */ - - /* P11.6 */ - P11_6_GPIO = 0, /* GPIO controls 'out' */ - P11_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_6_AMUXA = 4, /* Analog mux bus A */ - P11_6_AMUXB = 5, /* Analog mux bus B */ - P11_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:84 */ - P11_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:84 */ - P11_6_LCD_COM22 = 12, /* Digital Deep Sleep - lcd.com[22]:1 */ - P11_6_LCD_SEG22 = 13, /* Digital Deep Sleep - lcd.seg[22]:1 */ - P11_6_SMIF_SPI_DATA0 = 17, /* Digital Active - smif.spi_data0 */ - P11_6_SCB5_SPI_SELECT3 = 20, /* Digital Active - scb[5].spi_select3:1 */ - - /* P11.7 */ - P11_7_GPIO = 0, /* GPIO controls 'out' */ - P11_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P11_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P11_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P11_7_AMUXA = 4, /* Analog mux bus A */ - P11_7_AMUXB = 5, /* Analog mux bus B */ - P11_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P11_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P11_7_SMIF_SPI_CLK = 17, /* Digital Active - smif.spi_clk */ - - /* P12.0 */ - P12_0_GPIO = 0, /* GPIO controls 'out' */ - P12_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_0_AMUXA = 4, /* Analog mux bus A */ - P12_0_AMUXB = 5, /* Analog mux bus B */ - P12_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_0_TCPWM0_LINE4 = 8, /* Digital Active - tcpwm[0].line[4]:3 */ - P12_0_TCPWM1_LINE4 = 9, /* Digital Active - tcpwm[1].line[4]:1 */ - P12_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:85 */ - P12_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:85 */ - P12_0_LCD_COM23 = 12, /* Digital Deep Sleep - lcd.com[23]:1 */ - P12_0_LCD_SEG23 = 13, /* Digital Deep Sleep - lcd.seg[23]:1 */ - P12_0_SMIF_SPI_DATA4 = 17, /* Digital Active - smif.spi_data4 */ - P12_0_SCB6_UART_RX = 18, /* Digital Active - scb[6].uart_rx:0 */ - P12_0_SCB6_I2C_SCL = 19, /* Digital Active - scb[6].i2c_scl:0 */ - P12_0_SCB6_SPI_MOSI = 20, /* Digital Active - scb[6].spi_mosi:0 */ - P12_0_PERI_TR_IO_INPUT24 = 24, /* Digital Active - peri.tr_io_input[24]:0 */ - - /* P12.1 */ - P12_1_GPIO = 0, /* GPIO controls 'out' */ - P12_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_1_AMUXA = 4, /* Analog mux bus A */ - P12_1_AMUXB = 5, /* Analog mux bus B */ - P12_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_1_TCPWM0_LINE_COMPL4 = 8, /* Digital Active - tcpwm[0].line_compl[4]:3 */ - P12_1_TCPWM1_LINE_COMPL4 = 9, /* Digital Active - tcpwm[1].line_compl[4]:1 */ - P12_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:86 */ - P12_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:86 */ - P12_1_LCD_COM24 = 12, /* Digital Deep Sleep - lcd.com[24]:1 */ - P12_1_LCD_SEG24 = 13, /* Digital Deep Sleep - lcd.seg[24]:1 */ - P12_1_SMIF_SPI_DATA5 = 17, /* Digital Active - smif.spi_data5 */ - P12_1_SCB6_UART_TX = 18, /* Digital Active - scb[6].uart_tx:0 */ - P12_1_SCB6_I2C_SDA = 19, /* Digital Active - scb[6].i2c_sda:0 */ - P12_1_SCB6_SPI_MISO = 20, /* Digital Active - scb[6].spi_miso:0 */ - P12_1_PERI_TR_IO_INPUT25 = 24, /* Digital Active - peri.tr_io_input[25]:0 */ - - /* P12.2 */ - P12_2_GPIO = 0, /* GPIO controls 'out' */ - P12_2_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_2_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_2_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_2_AMUXA = 4, /* Analog mux bus A */ - P12_2_AMUXB = 5, /* Analog mux bus B */ - P12_2_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_2_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_2_TCPWM0_LINE5 = 8, /* Digital Active - tcpwm[0].line[5]:3 */ - P12_2_TCPWM1_LINE5 = 9, /* Digital Active - tcpwm[1].line[5]:1 */ - P12_2_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:87 */ - P12_2_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:87 */ - P12_2_LCD_COM25 = 12, /* Digital Deep Sleep - lcd.com[25]:1 */ - P12_2_LCD_SEG25 = 13, /* Digital Deep Sleep - lcd.seg[25]:1 */ - P12_2_SMIF_SPI_DATA6 = 17, /* Digital Active - smif.spi_data6 */ - P12_2_SCB6_UART_RTS = 18, /* Digital Active - scb[6].uart_rts:0 */ - P12_2_SCB6_SPI_CLK = 20, /* Digital Active - scb[6].spi_clk:0 */ - - /* P12.3 */ - P12_3_GPIO = 0, /* GPIO controls 'out' */ - P12_3_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_3_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_3_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_3_AMUXA = 4, /* Analog mux bus A */ - P12_3_AMUXB = 5, /* Analog mux bus B */ - P12_3_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_3_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_3_TCPWM0_LINE_COMPL5 = 8, /* Digital Active - tcpwm[0].line_compl[5]:3 */ - P12_3_TCPWM1_LINE_COMPL5 = 9, /* Digital Active - tcpwm[1].line_compl[5]:1 */ - P12_3_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:88 */ - P12_3_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:88 */ - P12_3_LCD_COM26 = 12, /* Digital Deep Sleep - lcd.com[26]:1 */ - P12_3_LCD_SEG26 = 13, /* Digital Deep Sleep - lcd.seg[26]:1 */ - P12_3_SMIF_SPI_DATA7 = 17, /* Digital Active - smif.spi_data7 */ - P12_3_SCB6_UART_CTS = 18, /* Digital Active - scb[6].uart_cts:0 */ - P12_3_SCB6_SPI_SELECT0 = 20, /* Digital Active - scb[6].spi_select0:0 */ - - /* P12.4 */ - P12_4_GPIO = 0, /* GPIO controls 'out' */ - P12_4_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_4_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_4_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_4_AMUXA = 4, /* Analog mux bus A */ - P12_4_AMUXB = 5, /* Analog mux bus B */ - P12_4_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_4_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_4_TCPWM0_LINE6 = 8, /* Digital Active - tcpwm[0].line[6]:3 */ - P12_4_TCPWM1_LINE6 = 9, /* Digital Active - tcpwm[1].line[6]:1 */ - P12_4_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:89 */ - P12_4_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:89 */ - P12_4_LCD_COM27 = 12, /* Digital Deep Sleep - lcd.com[27]:1 */ - P12_4_LCD_SEG27 = 13, /* Digital Deep Sleep - lcd.seg[27]:1 */ - P12_4_SMIF_SPI_SELECT3 = 17, /* Digital Active - smif.spi_select3 */ - P12_4_SCB6_SPI_SELECT1 = 20, /* Digital Active - scb[6].spi_select1:0 */ - - /* P12.5 */ - P12_5_GPIO = 0, /* GPIO controls 'out' */ - P12_5_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_5_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_5_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_5_AMUXA = 4, /* Analog mux bus A */ - P12_5_AMUXB = 5, /* Analog mux bus B */ - P12_5_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_5_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_5_TCPWM0_LINE_COMPL6 = 8, /* Digital Active - tcpwm[0].line_compl[6]:3 */ - P12_5_TCPWM1_LINE_COMPL6 = 9, /* Digital Active - tcpwm[1].line_compl[6]:1 */ - P12_5_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:90 */ - P12_5_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:90 */ - P12_5_LCD_COM28 = 12, /* Digital Deep Sleep - lcd.com[28]:1 */ - P12_5_LCD_SEG28 = 13, /* Digital Deep Sleep - lcd.seg[28]:1 */ - P12_5_SCB6_SPI_SELECT2 = 20, /* Digital Active - scb[6].spi_select2:0 */ - - /* P12.6 */ - P12_6_GPIO = 0, /* GPIO controls 'out' */ - P12_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_6_AMUXA = 4, /* Analog mux bus A */ - P12_6_AMUXB = 5, /* Analog mux bus B */ - P12_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_6_TCPWM0_LINE7 = 8, /* Digital Active - tcpwm[0].line[7]:3 */ - P12_6_TCPWM1_LINE7 = 9, /* Digital Active - tcpwm[1].line[7]:1 */ - P12_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:91 */ - P12_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:91 */ - P12_6_LCD_COM29 = 12, /* Digital Deep Sleep - lcd.com[29]:1 */ - P12_6_LCD_SEG29 = 13, /* Digital Deep Sleep - lcd.seg[29]:1 */ - P12_6_SCB6_SPI_SELECT3 = 20, /* Digital Active - scb[6].spi_select3:0 */ - - /* P12.7 */ - P12_7_GPIO = 0, /* GPIO controls 'out' */ - P12_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P12_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P12_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P12_7_AMUXA = 4, /* Analog mux bus A */ - P12_7_AMUXB = 5, /* Analog mux bus B */ - P12_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P12_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P12_7_TCPWM0_LINE_COMPL7 = 8, /* Digital Active - tcpwm[0].line_compl[7]:3 */ - P12_7_TCPWM1_LINE_COMPL7 = 9, /* Digital Active - tcpwm[1].line_compl[7]:1 */ - P12_7_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:92 */ - P12_7_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:92 */ - P12_7_LCD_COM30 = 12, /* Digital Deep Sleep - lcd.com[30]:1 */ - P12_7_LCD_SEG30 = 13, /* Digital Deep Sleep - lcd.seg[30]:1 */ - - /* P13.0 */ - P13_0_GPIO = 0, /* GPIO controls 'out' */ - P13_0_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P13_0_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P13_0_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P13_0_AMUXA = 4, /* Analog mux bus A */ - P13_0_AMUXB = 5, /* Analog mux bus B */ - P13_0_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P13_0_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P13_0_TCPWM0_LINE0 = 8, /* Digital Active - tcpwm[0].line[0]:4 */ - P13_0_TCPWM1_LINE8 = 9, /* Digital Active - tcpwm[1].line[8]:1 */ - P13_0_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:93 */ - P13_0_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:93 */ - P13_0_LCD_COM31 = 12, /* Digital Deep Sleep - lcd.com[31]:1 */ - P13_0_LCD_SEG31 = 13, /* Digital Deep Sleep - lcd.seg[31]:1 */ - P13_0_SCB6_UART_RX = 18, /* Digital Active - scb[6].uart_rx:1 */ - P13_0_SCB6_I2C_SCL = 19, /* Digital Active - scb[6].i2c_scl:1 */ - P13_0_SCB6_SPI_MOSI = 20, /* Digital Active - scb[6].spi_mosi:1 */ - P13_0_PERI_TR_IO_INPUT26 = 24, /* Digital Active - peri.tr_io_input[26]:0 */ - - /* P13.1 */ - P13_1_GPIO = 0, /* GPIO controls 'out' */ - P13_1_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P13_1_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P13_1_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P13_1_AMUXA = 4, /* Analog mux bus A */ - P13_1_AMUXB = 5, /* Analog mux bus B */ - P13_1_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P13_1_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P13_1_TCPWM0_LINE_COMPL0 = 8, /* Digital Active - tcpwm[0].line_compl[0]:4 */ - P13_1_TCPWM1_LINE_COMPL8 = 9, /* Digital Active - tcpwm[1].line_compl[8]:1 */ - P13_1_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:94 */ - P13_1_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:94 */ - P13_1_LCD_COM32 = 12, /* Digital Deep Sleep - lcd.com[32]:1 */ - P13_1_LCD_SEG32 = 13, /* Digital Deep Sleep - lcd.seg[32]:1 */ - P13_1_SCB6_UART_TX = 18, /* Digital Active - scb[6].uart_tx:1 */ - P13_1_SCB6_I2C_SDA = 19, /* Digital Active - scb[6].i2c_sda:1 */ - P13_1_SCB6_SPI_MISO = 20, /* Digital Active - scb[6].spi_miso:1 */ - P13_1_PERI_TR_IO_INPUT27 = 24, /* Digital Active - peri.tr_io_input[27]:0 */ - - /* P13.6 */ - P13_6_GPIO = 0, /* GPIO controls 'out' */ - P13_6_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P13_6_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P13_6_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P13_6_AMUXA = 4, /* Analog mux bus A */ - P13_6_AMUXB = 5, /* Analog mux bus B */ - P13_6_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P13_6_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P13_6_TCPWM0_LINE3 = 8, /* Digital Active - tcpwm[0].line[3]:4 */ - P13_6_TCPWM1_LINE11 = 9, /* Digital Active - tcpwm[1].line[11]:1 */ - P13_6_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:99 */ - P13_6_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:99 */ - P13_6_LCD_COM37 = 12, /* Digital Deep Sleep - lcd.com[37]:1 */ - P13_6_LCD_SEG37 = 13, /* Digital Deep Sleep - lcd.seg[37]:1 */ - P13_6_SCB6_SPI_SELECT3 = 20, /* Digital Active - scb[6].spi_select3:1 */ - - /* P13.7 */ - P13_7_GPIO = 0, /* GPIO controls 'out' */ - P13_7_GPIO_DSI = 1, /* GPIO controls 'out', DSI controls 'output enable' */ - P13_7_DSI_DSI = 2, /* DSI controls 'out' and 'output enable' */ - P13_7_DSI_GPIO = 3, /* DSI controls 'out', GPIO controls 'output enable' */ - P13_7_AMUXA = 4, /* Analog mux bus A */ - P13_7_AMUXB = 5, /* Analog mux bus B */ - P13_7_AMUXA_DSI = 6, /* Analog mux bus A, DSI control */ - P13_7_AMUXB_DSI = 7, /* Analog mux bus B, DSI control */ - P13_7_TCPWM0_LINE_COMPL3 = 8, /* Digital Active - tcpwm[0].line_compl[3]:4 */ - P13_7_TCPWM1_LINE_COMPL11 = 9, /* Digital Active - tcpwm[1].line_compl[11]:1 */ - P13_7_CSD_CSD_TX = 10, /* Digital Active - csd.csd_tx:100 */ - P13_7_CSD_CSD_TX_N = 11, /* Digital Active - csd.csd_tx_n:100 */ - P13_7_LCD_COM38 = 12, /* Digital Deep Sleep - lcd.com[38]:1 */ - P13_7_LCD_SEG38 = 13 /* Digital Deep Sleep - lcd.seg[38]:1 */ -} en_hsiom_sel_t; - -#endif /* _GPIO_PSOC6BLE_116_BGA_BLE_H_ */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/psoc6ble_config.h b/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/psoc6ble_config.h deleted file mode 100644 index 347d5fb7d4..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/TARGET_CY8C63XX/device/psoc6ble_config.h +++ /dev/null @@ -1,2289 +0,0 @@ -/***************************************************************************//** -* \file psoc6ble_config.h -* -* \brief -* PSoC 6 BLE device configuration header -* -* \note -* Generated 2/9/2017 by CyDeviceHeaderGenerator v1.1.0.47 -* from the register map configuration rev#961378 -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef _PSOC6BLE_CONFIG_H_ -#define _PSOC6BLE_CONFIG_H_ - -/* Clock Connections */ -typedef enum -{ - PCLK_SCB0_CLOCK = 0, /* scb[0].clock */ - PCLK_SCB1_CLOCK = 1, /* scb[1].clock */ - PCLK_SCB2_CLOCK = 2, /* scb[2].clock */ - PCLK_SCB3_CLOCK = 3, /* scb[3].clock */ - PCLK_SCB4_CLOCK = 4, /* scb[4].clock */ - PCLK_SCB5_CLOCK = 5, /* scb[5].clock */ - PCLK_SCB6_CLOCK = 6, /* scb[6].clock */ - PCLK_SCB7_CLOCK = 7, /* scb[7].clock */ - PCLK_SCB8_CLOCK = 8, /* scb[8].clock */ - PCLK_UDB_CLOCKS0 = 9, /* udb.clocks[0] */ - PCLK_UDB_CLOCKS1 = 10, /* udb.clocks[1] */ - PCLK_UDB_CLOCKS2 = 11, /* udb.clocks[2] */ - PCLK_UDB_CLOCKS3 = 12, /* udb.clocks[3] */ - PCLK_UDB_CLOCKS4 = 13, /* udb.clocks[4] */ - PCLK_UDB_CLOCKS5 = 14, /* udb.clocks[5] */ - PCLK_UDB_CLOCKS6 = 15, /* udb.clocks[6] */ - PCLK_UDB_CLOCKS7 = 16, /* udb.clocks[7] */ - PCLK_SMARTIO8_CLOCK = 17, /* smartio[8].clock */ - PCLK_SMARTIO9_CLOCK = 18, /* smartio[9].clock */ - PCLK_TCPWM0_CLOCKS0 = 19, /* tcpwm[0].clocks[0] */ - PCLK_TCPWM0_CLOCKS1 = 20, /* tcpwm[0].clocks[1] */ - PCLK_TCPWM0_CLOCKS2 = 21, /* tcpwm[0].clocks[2] */ - PCLK_TCPWM0_CLOCKS3 = 22, /* tcpwm[0].clocks[3] */ - PCLK_TCPWM0_CLOCKS4 = 23, /* tcpwm[0].clocks[4] */ - PCLK_TCPWM0_CLOCKS5 = 24, /* tcpwm[0].clocks[5] */ - PCLK_TCPWM0_CLOCKS6 = 25, /* tcpwm[0].clocks[6] */ - PCLK_TCPWM0_CLOCKS7 = 26, /* tcpwm[0].clocks[7] */ - PCLK_TCPWM1_CLOCKS0 = 27, /* tcpwm[1].clocks[0] */ - PCLK_TCPWM1_CLOCKS1 = 28, /* tcpwm[1].clocks[1] */ - PCLK_TCPWM1_CLOCKS2 = 29, /* tcpwm[1].clocks[2] */ - PCLK_TCPWM1_CLOCKS3 = 30, /* tcpwm[1].clocks[3] */ - PCLK_TCPWM1_CLOCKS4 = 31, /* tcpwm[1].clocks[4] */ - PCLK_TCPWM1_CLOCKS5 = 32, /* tcpwm[1].clocks[5] */ - PCLK_TCPWM1_CLOCKS6 = 33, /* tcpwm[1].clocks[6] */ - PCLK_TCPWM1_CLOCKS7 = 34, /* tcpwm[1].clocks[7] */ - PCLK_TCPWM1_CLOCKS8 = 35, /* tcpwm[1].clocks[8] */ - PCLK_TCPWM1_CLOCKS9 = 36, /* tcpwm[1].clocks[9] */ - PCLK_TCPWM1_CLOCKS10 = 37, /* tcpwm[1].clocks[10] */ - PCLK_TCPWM1_CLOCKS11 = 38, /* tcpwm[1].clocks[11] */ - PCLK_TCPWM1_CLOCKS12 = 39, /* tcpwm[1].clocks[12] */ - PCLK_TCPWM1_CLOCKS13 = 40, /* tcpwm[1].clocks[13] */ - PCLK_TCPWM1_CLOCKS14 = 41, /* tcpwm[1].clocks[14] */ - PCLK_TCPWM1_CLOCKS15 = 42, /* tcpwm[1].clocks[15] */ - PCLK_TCPWM1_CLOCKS16 = 43, /* tcpwm[1].clocks[16] */ - PCLK_TCPWM1_CLOCKS17 = 44, /* tcpwm[1].clocks[17] */ - PCLK_TCPWM1_CLOCKS18 = 45, /* tcpwm[1].clocks[18] */ - PCLK_TCPWM1_CLOCKS19 = 46, /* tcpwm[1].clocks[19] */ - PCLK_TCPWM1_CLOCKS20 = 47, /* tcpwm[1].clocks[20] */ - PCLK_TCPWM1_CLOCKS21 = 48, /* tcpwm[1].clocks[21] */ - PCLK_TCPWM1_CLOCKS22 = 49, /* tcpwm[1].clocks[22] */ - PCLK_TCPWM1_CLOCKS23 = 50, /* tcpwm[1].clocks[23] */ - PCLK_CSD_CLOCK = 51, /* csd.clock */ - PCLK_LCD_CLOCK = 52, /* lcd.clock */ - PCLK_PROFILE_CLOCK_PROFILE = 53, /* profile.clock_profile */ - PCLK_CPUSS_CLOCK_TRACE_IN = 54, /* cpuss.clock_trace_in */ - PCLK_PASS_CLOCK_CTDAC = 55, /* pass.clock_ctdac */ - PCLK_PASS_CLOCK_PUMP_PERI = 56, /* pass.clock_pump_peri */ - PCLK_PASS_CLOCK_SAR = 57, /* pass.clock_sar */ - PCLK_USB_CLOCK_DEV_BRS = 58 /* usb.clock_dev_brs */ -} en_clk_dst_t; - -/* Trigger Group Inputs */ -/* Trigger Input Group 0 - DMA Request Assignments */ -typedef enum -{ - TRIG0_IN_TR_GROUP10_OUTPUT0 = 0x0000u, /* tr_group[10].output[0] */ - TRIG0_IN_TR_GROUP10_OUTPUT1 = 0x0001u, /* tr_group[10].output[1] */ - TRIG0_IN_TR_GROUP10_OUTPUT2 = 0x0002u, /* tr_group[10].output[2] */ - TRIG0_IN_TR_GROUP10_OUTPUT3 = 0x0003u, /* tr_group[10].output[3] */ - TRIG0_IN_TR_GROUP10_OUTPUT4 = 0x0004u, /* tr_group[10].output[4] */ - TRIG0_IN_TR_GROUP10_OUTPUT5 = 0x0005u, /* tr_group[10].output[5] */ - TRIG0_IN_TR_GROUP10_OUTPUT6 = 0x0006u, /* tr_group[10].output[6] */ - TRIG0_IN_TR_GROUP10_OUTPUT7 = 0x0007u, /* tr_group[10].output[7] */ - TRIG0_IN_TR_GROUP11_OUTPUT0 = 0x0008u, /* tr_group[11].output[0] */ - TRIG0_IN_TR_GROUP11_OUTPUT1 = 0x0009u, /* tr_group[11].output[1] */ - TRIG0_IN_TR_GROUP11_OUTPUT2 = 0x000Au, /* tr_group[11].output[2] */ - TRIG0_IN_TR_GROUP11_OUTPUT3 = 0x000Bu, /* tr_group[11].output[3] */ - TRIG0_IN_TR_GROUP11_OUTPUT4 = 0x000Cu, /* tr_group[11].output[4] */ - TRIG0_IN_TR_GROUP11_OUTPUT5 = 0x000Du, /* tr_group[11].output[5] */ - TRIG0_IN_TR_GROUP11_OUTPUT6 = 0x000Eu, /* tr_group[11].output[6] */ - TRIG0_IN_TR_GROUP11_OUTPUT7 = 0x000Fu, /* tr_group[11].output[7] */ - TRIG0_IN_TR_GROUP11_OUTPUT8 = 0x0010u, /* tr_group[11].output[8] */ - TRIG0_IN_TR_GROUP11_OUTPUT9 = 0x0011u, /* tr_group[11].output[9] */ - TRIG0_IN_TR_GROUP11_OUTPUT10 = 0x0012u, /* tr_group[11].output[10] */ - TRIG0_IN_TR_GROUP11_OUTPUT11 = 0x0013u, /* tr_group[11].output[11] */ - TRIG0_IN_TR_GROUP11_OUTPUT12 = 0x0014u, /* tr_group[11].output[12] */ - TRIG0_IN_TR_GROUP11_OUTPUT13 = 0x0015u, /* tr_group[11].output[13] */ - TRIG0_IN_TR_GROUP11_OUTPUT14 = 0x0016u, /* tr_group[11].output[14] */ - TRIG0_IN_TR_GROUP11_OUTPUT15 = 0x0017u, /* tr_group[11].output[15] */ - TRIG0_IN_TR_GROUP12_OUTPUT8 = 0x0018u, /* tr_group[12].output[8] */ - TRIG0_IN_TR_GROUP12_OUTPUT9 = 0x0019u, /* tr_group[12].output[9] */ - TRIG0_IN_TR_GROUP13_OUTPUT0 = 0x001Au, /* tr_group[13].output[0] */ - TRIG0_IN_TR_GROUP13_OUTPUT1 = 0x001Bu, /* tr_group[13].output[1] */ - TRIG0_IN_TR_GROUP13_OUTPUT2 = 0x001Cu, /* tr_group[13].output[2] */ - TRIG0_IN_TR_GROUP13_OUTPUT3 = 0x001Du, /* tr_group[13].output[3] */ - TRIG0_IN_TR_GROUP13_OUTPUT4 = 0x001Eu, /* tr_group[13].output[4] */ - TRIG0_IN_TR_GROUP13_OUTPUT5 = 0x001Fu, /* tr_group[13].output[5] */ - TRIG0_IN_TR_GROUP13_OUTPUT6 = 0x0020u, /* tr_group[13].output[6] */ - TRIG0_IN_TR_GROUP13_OUTPUT7 = 0x0021u, /* tr_group[13].output[7] */ - TRIG0_IN_TR_GROUP13_OUTPUT8 = 0x0022u, /* tr_group[13].output[8] */ - TRIG0_IN_TR_GROUP13_OUTPUT9 = 0x0023u, /* tr_group[13].output[9] */ - TRIG0_IN_TR_GROUP13_OUTPUT10 = 0x0024u, /* tr_group[13].output[10] */ - TRIG0_IN_TR_GROUP13_OUTPUT11 = 0x0025u, /* tr_group[13].output[11] */ - TRIG0_IN_TR_GROUP13_OUTPUT12 = 0x0026u, /* tr_group[13].output[12] */ - TRIG0_IN_TR_GROUP13_OUTPUT13 = 0x0027u, /* tr_group[13].output[13] */ - TRIG0_IN_TR_GROUP13_OUTPUT14 = 0x0028u, /* tr_group[13].output[14] */ - TRIG0_IN_TR_GROUP13_OUTPUT15 = 0x0029u, /* tr_group[13].output[15] */ - TRIG0_IN_TR_GROUP14_OUTPUT0 = 0x002Au, /* tr_group[14].output[0] */ - TRIG0_IN_TR_GROUP14_OUTPUT1 = 0x002Bu, /* tr_group[14].output[1] */ - TRIG0_IN_TR_GROUP14_OUTPUT2 = 0x002Cu, /* tr_group[14].output[2] */ - TRIG0_IN_TR_GROUP14_OUTPUT3 = 0x002Du, /* tr_group[14].output[3] */ - TRIG0_IN_TR_GROUP14_OUTPUT4 = 0x002Eu, /* tr_group[14].output[4] */ - TRIG0_IN_TR_GROUP14_OUTPUT5 = 0x002Fu, /* tr_group[14].output[5] */ - TRIG0_IN_TR_GROUP14_OUTPUT6 = 0x0030u, /* tr_group[14].output[6] */ - TRIG0_IN_TR_GROUP14_OUTPUT7 = 0x0031u /* tr_group[14].output[7] */ -} en_trig_input_grp0_t; - -/* Trigger Input Group 1 - DMA Request Assignments */ -typedef enum -{ - TRIG1_IN_TR_GROUP10_OUTPUT0 = 0x0100u, /* tr_group[10].output[0] */ - TRIG1_IN_TR_GROUP10_OUTPUT1 = 0x0101u, /* tr_group[10].output[1] */ - TRIG1_IN_TR_GROUP10_OUTPUT2 = 0x0102u, /* tr_group[10].output[2] */ - TRIG1_IN_TR_GROUP10_OUTPUT3 = 0x0103u, /* tr_group[10].output[3] */ - TRIG1_IN_TR_GROUP10_OUTPUT4 = 0x0104u, /* tr_group[10].output[4] */ - TRIG1_IN_TR_GROUP10_OUTPUT5 = 0x0105u, /* tr_group[10].output[5] */ - TRIG1_IN_TR_GROUP10_OUTPUT6 = 0x0106u, /* tr_group[10].output[6] */ - TRIG1_IN_TR_GROUP10_OUTPUT7 = 0x0107u, /* tr_group[10].output[7] */ - TRIG1_IN_TR_GROUP11_OUTPUT0 = 0x0108u, /* tr_group[11].output[0] */ - TRIG1_IN_TR_GROUP11_OUTPUT1 = 0x0109u, /* tr_group[11].output[1] */ - TRIG1_IN_TR_GROUP11_OUTPUT2 = 0x010Au, /* tr_group[11].output[2] */ - TRIG1_IN_TR_GROUP11_OUTPUT3 = 0x010Bu, /* tr_group[11].output[3] */ - TRIG1_IN_TR_GROUP11_OUTPUT4 = 0x010Cu, /* tr_group[11].output[4] */ - TRIG1_IN_TR_GROUP11_OUTPUT5 = 0x010Du, /* tr_group[11].output[5] */ - TRIG1_IN_TR_GROUP11_OUTPUT6 = 0x010Eu, /* tr_group[11].output[6] */ - TRIG1_IN_TR_GROUP11_OUTPUT7 = 0x010Fu, /* tr_group[11].output[7] */ - TRIG1_IN_TR_GROUP11_OUTPUT8 = 0x0110u, /* tr_group[11].output[8] */ - TRIG1_IN_TR_GROUP11_OUTPUT9 = 0x0111u, /* tr_group[11].output[9] */ - TRIG1_IN_TR_GROUP11_OUTPUT10 = 0x0112u, /* tr_group[11].output[10] */ - TRIG1_IN_TR_GROUP11_OUTPUT11 = 0x0113u, /* tr_group[11].output[11] */ - TRIG1_IN_TR_GROUP11_OUTPUT12 = 0x0114u, /* tr_group[11].output[12] */ - TRIG1_IN_TR_GROUP11_OUTPUT13 = 0x0115u, /* tr_group[11].output[13] */ - TRIG1_IN_TR_GROUP11_OUTPUT14 = 0x0116u, /* tr_group[11].output[14] */ - TRIG1_IN_TR_GROUP11_OUTPUT15 = 0x0117u, /* tr_group[11].output[15] */ - TRIG1_IN_TR_GROUP12_OUTPUT8 = 0x0118u, /* tr_group[12].output[8] */ - TRIG1_IN_TR_GROUP12_OUTPUT9 = 0x0119u, /* tr_group[12].output[9] */ - TRIG1_IN_TR_GROUP13_OUTPUT0 = 0x011Au, /* tr_group[13].output[0] */ - TRIG1_IN_TR_GROUP13_OUTPUT1 = 0x011Bu, /* tr_group[13].output[1] */ - TRIG1_IN_TR_GROUP13_OUTPUT2 = 0x011Cu, /* tr_group[13].output[2] */ - TRIG1_IN_TR_GROUP13_OUTPUT3 = 0x011Du, /* tr_group[13].output[3] */ - TRIG1_IN_TR_GROUP13_OUTPUT4 = 0x011Eu, /* tr_group[13].output[4] */ - TRIG1_IN_TR_GROUP13_OUTPUT5 = 0x011Fu, /* tr_group[13].output[5] */ - TRIG1_IN_TR_GROUP13_OUTPUT6 = 0x0120u, /* tr_group[13].output[6] */ - TRIG1_IN_TR_GROUP13_OUTPUT7 = 0x0121u, /* tr_group[13].output[7] */ - TRIG1_IN_TR_GROUP13_OUTPUT8 = 0x0122u, /* tr_group[13].output[8] */ - TRIG1_IN_TR_GROUP13_OUTPUT9 = 0x0123u, /* tr_group[13].output[9] */ - TRIG1_IN_TR_GROUP13_OUTPUT10 = 0x0124u, /* tr_group[13].output[10] */ - TRIG1_IN_TR_GROUP13_OUTPUT11 = 0x0125u, /* tr_group[13].output[11] */ - TRIG1_IN_TR_GROUP13_OUTPUT12 = 0x0126u, /* tr_group[13].output[12] */ - TRIG1_IN_TR_GROUP13_OUTPUT13 = 0x0127u, /* tr_group[13].output[13] */ - TRIG1_IN_TR_GROUP13_OUTPUT14 = 0x0128u, /* tr_group[13].output[14] */ - TRIG1_IN_TR_GROUP13_OUTPUT15 = 0x0129u, /* tr_group[13].output[15] */ - TRIG1_IN_TR_GROUP14_OUTPUT0 = 0x012Au, /* tr_group[14].output[0] */ - TRIG1_IN_TR_GROUP14_OUTPUT1 = 0x012Bu, /* tr_group[14].output[1] */ - TRIG1_IN_TR_GROUP14_OUTPUT2 = 0x012Cu, /* tr_group[14].output[2] */ - TRIG1_IN_TR_GROUP14_OUTPUT3 = 0x012Du, /* tr_group[14].output[3] */ - TRIG1_IN_TR_GROUP14_OUTPUT4 = 0x012Eu, /* tr_group[14].output[4] */ - TRIG1_IN_TR_GROUP14_OUTPUT5 = 0x012Fu, /* tr_group[14].output[5] */ - TRIG1_IN_TR_GROUP14_OUTPUT6 = 0x0130u, /* tr_group[14].output[6] */ - TRIG1_IN_TR_GROUP14_OUTPUT7 = 0x0131u /* tr_group[14].output[7] */ -} en_trig_input_grp1_t; - -/* Trigger Input Group 2 - TCPWM trigger inputs */ -typedef enum -{ - TRIG2_IN_TR_GROUP10_OUTPUT0 = 0x0200u, /* tr_group[10].output[0] */ - TRIG2_IN_TR_GROUP10_OUTPUT1 = 0x0201u, /* tr_group[10].output[1] */ - TRIG2_IN_TR_GROUP10_OUTPUT2 = 0x0202u, /* tr_group[10].output[2] */ - TRIG2_IN_TR_GROUP10_OUTPUT3 = 0x0203u, /* tr_group[10].output[3] */ - TRIG2_IN_TR_GROUP10_OUTPUT4 = 0x0204u, /* tr_group[10].output[4] */ - TRIG2_IN_TR_GROUP10_OUTPUT5 = 0x0205u, /* tr_group[10].output[5] */ - TRIG2_IN_TR_GROUP10_OUTPUT6 = 0x0206u, /* tr_group[10].output[6] */ - TRIG2_IN_TR_GROUP10_OUTPUT7 = 0x0207u, /* tr_group[10].output[7] */ - TRIG2_IN_TR_GROUP11_OUTPUT0 = 0x0208u, /* tr_group[11].output[0] */ - TRIG2_IN_TR_GROUP11_OUTPUT1 = 0x0209u, /* tr_group[11].output[1] */ - TRIG2_IN_TR_GROUP11_OUTPUT2 = 0x020Au, /* tr_group[11].output[2] */ - TRIG2_IN_TR_GROUP11_OUTPUT3 = 0x020Bu, /* tr_group[11].output[3] */ - TRIG2_IN_TR_GROUP11_OUTPUT4 = 0x020Cu, /* tr_group[11].output[4] */ - TRIG2_IN_TR_GROUP11_OUTPUT5 = 0x020Du, /* tr_group[11].output[5] */ - TRIG2_IN_TR_GROUP11_OUTPUT6 = 0x020Eu, /* tr_group[11].output[6] */ - TRIG2_IN_TR_GROUP11_OUTPUT7 = 0x020Fu, /* tr_group[11].output[7] */ - TRIG2_IN_TR_GROUP11_OUTPUT8 = 0x0210u, /* tr_group[11].output[8] */ - TRIG2_IN_TR_GROUP11_OUTPUT9 = 0x0211u, /* tr_group[11].output[9] */ - TRIG2_IN_TR_GROUP11_OUTPUT10 = 0x0212u, /* tr_group[11].output[10] */ - TRIG2_IN_TR_GROUP11_OUTPUT11 = 0x0213u, /* tr_group[11].output[11] */ - TRIG2_IN_TR_GROUP11_OUTPUT12 = 0x0214u, /* tr_group[11].output[12] */ - TRIG2_IN_TR_GROUP11_OUTPUT13 = 0x0215u, /* tr_group[11].output[13] */ - TRIG2_IN_TR_GROUP11_OUTPUT14 = 0x0216u, /* tr_group[11].output[14] */ - TRIG2_IN_TR_GROUP11_OUTPUT15 = 0x0217u, /* tr_group[11].output[15] */ - TRIG2_IN_TR_GROUP12_OUTPUT0 = 0x0218u, /* tr_group[12].output[0] */ - TRIG2_IN_TR_GROUP12_OUTPUT1 = 0x0219u, /* tr_group[12].output[1] */ - TRIG2_IN_TR_GROUP12_OUTPUT2 = 0x021Au, /* tr_group[12].output[2] */ - TRIG2_IN_TR_GROUP12_OUTPUT3 = 0x021Bu, /* tr_group[12].output[3] */ - TRIG2_IN_TR_GROUP12_OUTPUT4 = 0x021Cu, /* tr_group[12].output[4] */ - TRIG2_IN_TR_GROUP12_OUTPUT5 = 0x021Du, /* tr_group[12].output[5] */ - TRIG2_IN_TR_GROUP12_OUTPUT6 = 0x021Eu, /* tr_group[12].output[6] */ - TRIG2_IN_TR_GROUP12_OUTPUT7 = 0x021Fu, /* tr_group[12].output[7] */ - TRIG2_IN_TR_GROUP13_OUTPUT16 = 0x0220u, /* tr_group[13].output[16] */ - TRIG2_IN_TR_GROUP13_OUTPUT17 = 0x0221u, /* tr_group[13].output[17] */ - TRIG2_IN_TR_GROUP14_OUTPUT8 = 0x0222u, /* tr_group[14].output[8] */ - TRIG2_IN_TR_GROUP14_OUTPUT9 = 0x0223u, /* tr_group[14].output[9] */ - TRIG2_IN_TR_GROUP14_OUTPUT10 = 0x0224u, /* tr_group[14].output[10] */ - TRIG2_IN_TR_GROUP14_OUTPUT11 = 0x0225u, /* tr_group[14].output[11] */ - TRIG2_IN_TR_GROUP14_OUTPUT12 = 0x0226u, /* tr_group[14].output[12] */ - TRIG2_IN_TR_GROUP14_OUTPUT13 = 0x0227u, /* tr_group[14].output[13] */ - TRIG2_IN_TR_GROUP14_OUTPUT14 = 0x0228u, /* tr_group[14].output[14] */ - TRIG2_IN_TR_GROUP14_OUTPUT15 = 0x0229u /* tr_group[14].output[15] */ -} en_trig_input_grp2_t; - -/* Trigger Input Group 3 - TCPWM trigger inputs */ -typedef enum -{ - TRIG3_IN_TR_GROUP10_OUTPUT0 = 0x0300u, /* tr_group[10].output[0] */ - TRIG3_IN_TR_GROUP10_OUTPUT1 = 0x0301u, /* tr_group[10].output[1] */ - TRIG3_IN_TR_GROUP10_OUTPUT2 = 0x0302u, /* tr_group[10].output[2] */ - TRIG3_IN_TR_GROUP10_OUTPUT3 = 0x0303u, /* tr_group[10].output[3] */ - TRIG3_IN_TR_GROUP10_OUTPUT4 = 0x0304u, /* tr_group[10].output[4] */ - TRIG3_IN_TR_GROUP10_OUTPUT5 = 0x0305u, /* tr_group[10].output[5] */ - TRIG3_IN_TR_GROUP10_OUTPUT6 = 0x0306u, /* tr_group[10].output[6] */ - TRIG3_IN_TR_GROUP10_OUTPUT7 = 0x0307u, /* tr_group[10].output[7] */ - TRIG3_IN_TR_GROUP11_OUTPUT0 = 0x0308u, /* tr_group[11].output[0] */ - TRIG3_IN_TR_GROUP11_OUTPUT1 = 0x0309u, /* tr_group[11].output[1] */ - TRIG3_IN_TR_GROUP11_OUTPUT2 = 0x030Au, /* tr_group[11].output[2] */ - TRIG3_IN_TR_GROUP11_OUTPUT3 = 0x030Bu, /* tr_group[11].output[3] */ - TRIG3_IN_TR_GROUP11_OUTPUT4 = 0x030Cu, /* tr_group[11].output[4] */ - TRIG3_IN_TR_GROUP11_OUTPUT5 = 0x030Du, /* tr_group[11].output[5] */ - TRIG3_IN_TR_GROUP11_OUTPUT6 = 0x030Eu, /* tr_group[11].output[6] */ - TRIG3_IN_TR_GROUP11_OUTPUT7 = 0x030Fu, /* tr_group[11].output[7] */ - TRIG3_IN_TR_GROUP11_OUTPUT8 = 0x0310u, /* tr_group[11].output[8] */ - TRIG3_IN_TR_GROUP11_OUTPUT9 = 0x0311u, /* tr_group[11].output[9] */ - TRIG3_IN_TR_GROUP11_OUTPUT10 = 0x0312u, /* tr_group[11].output[10] */ - TRIG3_IN_TR_GROUP11_OUTPUT11 = 0x0313u, /* tr_group[11].output[11] */ - TRIG3_IN_TR_GROUP11_OUTPUT12 = 0x0314u, /* tr_group[11].output[12] */ - TRIG3_IN_TR_GROUP11_OUTPUT13 = 0x0315u, /* tr_group[11].output[13] */ - TRIG3_IN_TR_GROUP11_OUTPUT14 = 0x0316u, /* tr_group[11].output[14] */ - TRIG3_IN_TR_GROUP11_OUTPUT15 = 0x0317u, /* tr_group[11].output[15] */ - TRIG3_IN_TR_GROUP12_OUTPUT0 = 0x0318u, /* tr_group[12].output[0] */ - TRIG3_IN_TR_GROUP12_OUTPUT1 = 0x0319u, /* tr_group[12].output[1] */ - TRIG3_IN_TR_GROUP12_OUTPUT2 = 0x031Au, /* tr_group[12].output[2] */ - TRIG3_IN_TR_GROUP12_OUTPUT3 = 0x031Bu, /* tr_group[12].output[3] */ - TRIG3_IN_TR_GROUP12_OUTPUT4 = 0x031Cu, /* tr_group[12].output[4] */ - TRIG3_IN_TR_GROUP12_OUTPUT5 = 0x031Du, /* tr_group[12].output[5] */ - TRIG3_IN_TR_GROUP12_OUTPUT6 = 0x031Eu, /* tr_group[12].output[6] */ - TRIG3_IN_TR_GROUP12_OUTPUT7 = 0x031Fu, /* tr_group[12].output[7] */ - TRIG3_IN_TR_GROUP13_OUTPUT16 = 0x0320u, /* tr_group[13].output[16] */ - TRIG3_IN_TR_GROUP13_OUTPUT17 = 0x0321u, /* tr_group[13].output[17] */ - TRIG3_IN_TR_GROUP14_OUTPUT8 = 0x0322u, /* tr_group[14].output[8] */ - TRIG3_IN_TR_GROUP14_OUTPUT9 = 0x0323u, /* tr_group[14].output[9] */ - TRIG3_IN_TR_GROUP14_OUTPUT10 = 0x0324u, /* tr_group[14].output[10] */ - TRIG3_IN_TR_GROUP14_OUTPUT11 = 0x0325u, /* tr_group[14].output[11] */ - TRIG3_IN_TR_GROUP14_OUTPUT12 = 0x0326u, /* tr_group[14].output[12] */ - TRIG3_IN_TR_GROUP14_OUTPUT13 = 0x0327u, /* tr_group[14].output[13] */ - TRIG3_IN_TR_GROUP14_OUTPUT14 = 0x0328u, /* tr_group[14].output[14] */ - TRIG3_IN_TR_GROUP14_OUTPUT15 = 0x0329u /* tr_group[14].output[15] */ -} en_trig_input_grp3_t; - -/* Trigger Input Group 4 - PROFILE trigger multiplexer */ -typedef enum -{ - TRIG4_IN_TR_GROUP10_OUTPUT0 = 0x0400u, /* tr_group[10].output[0] */ - TRIG4_IN_TR_GROUP10_OUTPUT1 = 0x0401u, /* tr_group[10].output[1] */ - TRIG4_IN_TR_GROUP10_OUTPUT2 = 0x0402u, /* tr_group[10].output[2] */ - TRIG4_IN_TR_GROUP10_OUTPUT3 = 0x0403u, /* tr_group[10].output[3] */ - TRIG4_IN_TR_GROUP10_OUTPUT4 = 0x0404u, /* tr_group[10].output[4] */ - TRIG4_IN_TR_GROUP10_OUTPUT5 = 0x0405u, /* tr_group[10].output[5] */ - TRIG4_IN_TR_GROUP10_OUTPUT6 = 0x0406u, /* tr_group[10].output[6] */ - TRIG4_IN_TR_GROUP10_OUTPUT7 = 0x0407u, /* tr_group[10].output[7] */ - TRIG4_IN_TR_GROUP11_OUTPUT0 = 0x0408u, /* tr_group[11].output[0] */ - TRIG4_IN_TR_GROUP11_OUTPUT1 = 0x0409u, /* tr_group[11].output[1] */ - TRIG4_IN_TR_GROUP11_OUTPUT2 = 0x040Au, /* tr_group[11].output[2] */ - TRIG4_IN_TR_GROUP11_OUTPUT3 = 0x040Bu, /* tr_group[11].output[3] */ - TRIG4_IN_TR_GROUP11_OUTPUT4 = 0x040Cu, /* tr_group[11].output[4] */ - TRIG4_IN_TR_GROUP11_OUTPUT5 = 0x040Du, /* tr_group[11].output[5] */ - TRIG4_IN_TR_GROUP11_OUTPUT6 = 0x040Eu, /* tr_group[11].output[6] */ - TRIG4_IN_TR_GROUP11_OUTPUT7 = 0x040Fu, /* tr_group[11].output[7] */ - TRIG4_IN_TR_GROUP11_OUTPUT8 = 0x0410u, /* tr_group[11].output[8] */ - TRIG4_IN_TR_GROUP11_OUTPUT9 = 0x0411u, /* tr_group[11].output[9] */ - TRIG4_IN_TR_GROUP11_OUTPUT10 = 0x0412u, /* tr_group[11].output[10] */ - TRIG4_IN_TR_GROUP11_OUTPUT11 = 0x0413u, /* tr_group[11].output[11] */ - TRIG4_IN_TR_GROUP11_OUTPUT12 = 0x0414u, /* tr_group[11].output[12] */ - TRIG4_IN_TR_GROUP11_OUTPUT13 = 0x0415u, /* tr_group[11].output[13] */ - TRIG4_IN_TR_GROUP11_OUTPUT14 = 0x0416u, /* tr_group[11].output[14] */ - TRIG4_IN_TR_GROUP11_OUTPUT15 = 0x0417u, /* tr_group[11].output[15] */ - TRIG4_IN_TR_GROUP12_OUTPUT0 = 0x0418u, /* tr_group[12].output[0] */ - TRIG4_IN_TR_GROUP12_OUTPUT1 = 0x0419u, /* tr_group[12].output[1] */ - TRIG4_IN_TR_GROUP12_OUTPUT2 = 0x041Au, /* tr_group[12].output[2] */ - TRIG4_IN_TR_GROUP12_OUTPUT3 = 0x041Bu, /* tr_group[12].output[3] */ - TRIG4_IN_TR_GROUP12_OUTPUT4 = 0x041Cu, /* tr_group[12].output[4] */ - TRIG4_IN_TR_GROUP12_OUTPUT5 = 0x041Du, /* tr_group[12].output[5] */ - TRIG4_IN_TR_GROUP12_OUTPUT6 = 0x041Eu, /* tr_group[12].output[6] */ - TRIG4_IN_TR_GROUP12_OUTPUT7 = 0x041Fu, /* tr_group[12].output[7] */ - TRIG4_IN_TR_GROUP13_OUTPUT16 = 0x0420u, /* tr_group[13].output[16] */ - TRIG4_IN_TR_GROUP13_OUTPUT17 = 0x0421u, /* tr_group[13].output[17] */ - TRIG4_IN_TR_GROUP14_OUTPUT8 = 0x0422u, /* tr_group[14].output[8] */ - TRIG4_IN_TR_GROUP14_OUTPUT9 = 0x0423u, /* tr_group[14].output[9] */ - TRIG4_IN_TR_GROUP14_OUTPUT10 = 0x0424u, /* tr_group[14].output[10] */ - TRIG4_IN_TR_GROUP14_OUTPUT11 = 0x0425u, /* tr_group[14].output[11] */ - TRIG4_IN_TR_GROUP14_OUTPUT12 = 0x0426u, /* tr_group[14].output[12] */ - TRIG4_IN_TR_GROUP14_OUTPUT13 = 0x0427u, /* tr_group[14].output[13] */ - TRIG4_IN_TR_GROUP14_OUTPUT14 = 0x0428u, /* tr_group[14].output[14] */ - TRIG4_IN_TR_GROUP14_OUTPUT15 = 0x0429u /* tr_group[14].output[15] */ -} en_trig_input_grp4_t; - -/* Trigger Input Group 5 - CPUSS.CTI trigger multiplexer */ -typedef enum -{ - TRIG5_IN_TR_GROUP10_OUTPUT0 = 0x0500u, /* tr_group[10].output[0] */ - TRIG5_IN_TR_GROUP10_OUTPUT1 = 0x0501u, /* tr_group[10].output[1] */ - TRIG5_IN_TR_GROUP10_OUTPUT2 = 0x0502u, /* tr_group[10].output[2] */ - TRIG5_IN_TR_GROUP10_OUTPUT3 = 0x0503u, /* tr_group[10].output[3] */ - TRIG5_IN_TR_GROUP10_OUTPUT4 = 0x0504u, /* tr_group[10].output[4] */ - TRIG5_IN_TR_GROUP10_OUTPUT5 = 0x0505u, /* tr_group[10].output[5] */ - TRIG5_IN_TR_GROUP10_OUTPUT6 = 0x0506u, /* tr_group[10].output[6] */ - TRIG5_IN_TR_GROUP10_OUTPUT7 = 0x0507u, /* tr_group[10].output[7] */ - TRIG5_IN_TR_GROUP11_OUTPUT0 = 0x0508u, /* tr_group[11].output[0] */ - TRIG5_IN_TR_GROUP11_OUTPUT1 = 0x0509u, /* tr_group[11].output[1] */ - TRIG5_IN_TR_GROUP11_OUTPUT2 = 0x050Au, /* tr_group[11].output[2] */ - TRIG5_IN_TR_GROUP11_OUTPUT3 = 0x050Bu, /* tr_group[11].output[3] */ - TRIG5_IN_TR_GROUP11_OUTPUT4 = 0x050Cu, /* tr_group[11].output[4] */ - TRIG5_IN_TR_GROUP11_OUTPUT5 = 0x050Du, /* tr_group[11].output[5] */ - TRIG5_IN_TR_GROUP11_OUTPUT6 = 0x050Eu, /* tr_group[11].output[6] */ - TRIG5_IN_TR_GROUP11_OUTPUT7 = 0x050Fu, /* tr_group[11].output[7] */ - TRIG5_IN_TR_GROUP11_OUTPUT8 = 0x0510u, /* tr_group[11].output[8] */ - TRIG5_IN_TR_GROUP11_OUTPUT9 = 0x0511u, /* tr_group[11].output[9] */ - TRIG5_IN_TR_GROUP11_OUTPUT10 = 0x0512u, /* tr_group[11].output[10] */ - TRIG5_IN_TR_GROUP11_OUTPUT11 = 0x0513u, /* tr_group[11].output[11] */ - TRIG5_IN_TR_GROUP11_OUTPUT12 = 0x0514u, /* tr_group[11].output[12] */ - TRIG5_IN_TR_GROUP11_OUTPUT13 = 0x0515u, /* tr_group[11].output[13] */ - TRIG5_IN_TR_GROUP11_OUTPUT14 = 0x0516u, /* tr_group[11].output[14] */ - TRIG5_IN_TR_GROUP11_OUTPUT15 = 0x0517u, /* tr_group[11].output[15] */ - TRIG5_IN_TR_GROUP12_OUTPUT0 = 0x0518u, /* tr_group[12].output[0] */ - TRIG5_IN_TR_GROUP12_OUTPUT1 = 0x0519u, /* tr_group[12].output[1] */ - TRIG5_IN_TR_GROUP12_OUTPUT2 = 0x051Au, /* tr_group[12].output[2] */ - TRIG5_IN_TR_GROUP12_OUTPUT3 = 0x051Bu, /* tr_group[12].output[3] */ - TRIG5_IN_TR_GROUP12_OUTPUT4 = 0x051Cu, /* tr_group[12].output[4] */ - TRIG5_IN_TR_GROUP12_OUTPUT5 = 0x051Du, /* tr_group[12].output[5] */ - TRIG5_IN_TR_GROUP12_OUTPUT6 = 0x051Eu, /* tr_group[12].output[6] */ - TRIG5_IN_TR_GROUP12_OUTPUT7 = 0x051Fu, /* tr_group[12].output[7] */ - TRIG5_IN_TR_GROUP13_OUTPUT16 = 0x0520u, /* tr_group[13].output[16] */ - TRIG5_IN_TR_GROUP13_OUTPUT17 = 0x0521u, /* tr_group[13].output[17] */ - TRIG5_IN_TR_GROUP14_OUTPUT8 = 0x0522u, /* tr_group[14].output[8] */ - TRIG5_IN_TR_GROUP14_OUTPUT9 = 0x0523u, /* tr_group[14].output[9] */ - TRIG5_IN_TR_GROUP14_OUTPUT10 = 0x0524u, /* tr_group[14].output[10] */ - TRIG5_IN_TR_GROUP14_OUTPUT11 = 0x0525u, /* tr_group[14].output[11] */ - TRIG5_IN_TR_GROUP14_OUTPUT12 = 0x0526u, /* tr_group[14].output[12] */ - TRIG5_IN_TR_GROUP14_OUTPUT13 = 0x0527u, /* tr_group[14].output[13] */ - TRIG5_IN_TR_GROUP14_OUTPUT14 = 0x0528u, /* tr_group[14].output[14] */ - TRIG5_IN_TR_GROUP14_OUTPUT15 = 0x0529u /* tr_group[14].output[15] */ -} en_trig_input_grp5_t; - -/* Trigger Input Group 6 - PASS trigger multiplexer */ -typedef enum -{ - TRIG6_IN_TR_GROUP10_OUTPUT0 = 0x0600u, /* tr_group[10].output[0] */ - TRIG6_IN_TR_GROUP10_OUTPUT1 = 0x0601u, /* tr_group[10].output[1] */ - TRIG6_IN_TR_GROUP10_OUTPUT2 = 0x0602u, /* tr_group[10].output[2] */ - TRIG6_IN_TR_GROUP10_OUTPUT3 = 0x0603u, /* tr_group[10].output[3] */ - TRIG6_IN_TR_GROUP10_OUTPUT4 = 0x0604u, /* tr_group[10].output[4] */ - TRIG6_IN_TR_GROUP10_OUTPUT5 = 0x0605u, /* tr_group[10].output[5] */ - TRIG6_IN_TR_GROUP10_OUTPUT6 = 0x0606u, /* tr_group[10].output[6] */ - TRIG6_IN_TR_GROUP10_OUTPUT7 = 0x0607u, /* tr_group[10].output[7] */ - TRIG6_IN_TR_GROUP11_OUTPUT0 = 0x0608u, /* tr_group[11].output[0] */ - TRIG6_IN_TR_GROUP11_OUTPUT1 = 0x0609u, /* tr_group[11].output[1] */ - TRIG6_IN_TR_GROUP11_OUTPUT2 = 0x060Au, /* tr_group[11].output[2] */ - TRIG6_IN_TR_GROUP11_OUTPUT3 = 0x060Bu, /* tr_group[11].output[3] */ - TRIG6_IN_TR_GROUP11_OUTPUT4 = 0x060Cu, /* tr_group[11].output[4] */ - TRIG6_IN_TR_GROUP11_OUTPUT5 = 0x060Du, /* tr_group[11].output[5] */ - TRIG6_IN_TR_GROUP11_OUTPUT6 = 0x060Eu, /* tr_group[11].output[6] */ - TRIG6_IN_TR_GROUP11_OUTPUT7 = 0x060Fu, /* tr_group[11].output[7] */ - TRIG6_IN_TR_GROUP11_OUTPUT8 = 0x0610u, /* tr_group[11].output[8] */ - TRIG6_IN_TR_GROUP11_OUTPUT9 = 0x0611u, /* tr_group[11].output[9] */ - TRIG6_IN_TR_GROUP11_OUTPUT10 = 0x0612u, /* tr_group[11].output[10] */ - TRIG6_IN_TR_GROUP11_OUTPUT11 = 0x0613u, /* tr_group[11].output[11] */ - TRIG6_IN_TR_GROUP11_OUTPUT12 = 0x0614u, /* tr_group[11].output[12] */ - TRIG6_IN_TR_GROUP11_OUTPUT13 = 0x0615u, /* tr_group[11].output[13] */ - TRIG6_IN_TR_GROUP11_OUTPUT14 = 0x0616u, /* tr_group[11].output[14] */ - TRIG6_IN_TR_GROUP11_OUTPUT15 = 0x0617u, /* tr_group[11].output[15] */ - TRIG6_IN_TR_GROUP12_OUTPUT0 = 0x0618u, /* tr_group[12].output[0] */ - TRIG6_IN_TR_GROUP12_OUTPUT1 = 0x0619u, /* tr_group[12].output[1] */ - TRIG6_IN_TR_GROUP12_OUTPUT2 = 0x061Au, /* tr_group[12].output[2] */ - TRIG6_IN_TR_GROUP12_OUTPUT3 = 0x061Bu, /* tr_group[12].output[3] */ - TRIG6_IN_TR_GROUP12_OUTPUT4 = 0x061Cu, /* tr_group[12].output[4] */ - TRIG6_IN_TR_GROUP12_OUTPUT5 = 0x061Du, /* tr_group[12].output[5] */ - TRIG6_IN_TR_GROUP12_OUTPUT6 = 0x061Eu, /* tr_group[12].output[6] */ - TRIG6_IN_TR_GROUP12_OUTPUT7 = 0x061Fu, /* tr_group[12].output[7] */ - TRIG6_IN_TR_GROUP13_OUTPUT16 = 0x0620u, /* tr_group[13].output[16] */ - TRIG6_IN_TR_GROUP13_OUTPUT17 = 0x0621u, /* tr_group[13].output[17] */ - TRIG6_IN_TR_GROUP14_OUTPUT8 = 0x0622u, /* tr_group[14].output[8] */ - TRIG6_IN_TR_GROUP14_OUTPUT9 = 0x0623u, /* tr_group[14].output[9] */ - TRIG6_IN_TR_GROUP14_OUTPUT10 = 0x0624u, /* tr_group[14].output[10] */ - TRIG6_IN_TR_GROUP14_OUTPUT11 = 0x0625u, /* tr_group[14].output[11] */ - TRIG6_IN_TR_GROUP14_OUTPUT12 = 0x0626u, /* tr_group[14].output[12] */ - TRIG6_IN_TR_GROUP14_OUTPUT13 = 0x0627u, /* tr_group[14].output[13] */ - TRIG6_IN_TR_GROUP14_OUTPUT14 = 0x0628u, /* tr_group[14].output[14] */ - TRIG6_IN_TR_GROUP14_OUTPUT15 = 0x0629u /* tr_group[14].output[15] */ -} en_trig_input_grp6_t; - -/* Trigger Input Group 7 - UDB general purpose trigger multiplexer */ -typedef enum -{ - TRIG7_IN_TR_GROUP10_OUTPUT0 = 0x0700u, /* tr_group[10].output[0] */ - TRIG7_IN_TR_GROUP10_OUTPUT1 = 0x0701u, /* tr_group[10].output[1] */ - TRIG7_IN_TR_GROUP10_OUTPUT2 = 0x0702u, /* tr_group[10].output[2] */ - TRIG7_IN_TR_GROUP10_OUTPUT3 = 0x0703u, /* tr_group[10].output[3] */ - TRIG7_IN_TR_GROUP10_OUTPUT4 = 0x0704u, /* tr_group[10].output[4] */ - TRIG7_IN_TR_GROUP10_OUTPUT5 = 0x0705u, /* tr_group[10].output[5] */ - TRIG7_IN_TR_GROUP10_OUTPUT6 = 0x0706u, /* tr_group[10].output[6] */ - TRIG7_IN_TR_GROUP10_OUTPUT7 = 0x0707u, /* tr_group[10].output[7] */ - TRIG7_IN_TR_GROUP11_OUTPUT0 = 0x0708u, /* tr_group[11].output[0] */ - TRIG7_IN_TR_GROUP11_OUTPUT1 = 0x0709u, /* tr_group[11].output[1] */ - TRIG7_IN_TR_GROUP11_OUTPUT2 = 0x070Au, /* tr_group[11].output[2] */ - TRIG7_IN_TR_GROUP11_OUTPUT3 = 0x070Bu, /* tr_group[11].output[3] */ - TRIG7_IN_TR_GROUP11_OUTPUT4 = 0x070Cu, /* tr_group[11].output[4] */ - TRIG7_IN_TR_GROUP11_OUTPUT5 = 0x070Du, /* tr_group[11].output[5] */ - TRIG7_IN_TR_GROUP11_OUTPUT6 = 0x070Eu, /* tr_group[11].output[6] */ - TRIG7_IN_TR_GROUP11_OUTPUT7 = 0x070Fu, /* tr_group[11].output[7] */ - TRIG7_IN_TR_GROUP11_OUTPUT8 = 0x0710u, /* tr_group[11].output[8] */ - TRIG7_IN_TR_GROUP11_OUTPUT9 = 0x0711u, /* tr_group[11].output[9] */ - TRIG7_IN_TR_GROUP11_OUTPUT10 = 0x0712u, /* tr_group[11].output[10] */ - TRIG7_IN_TR_GROUP11_OUTPUT11 = 0x0713u, /* tr_group[11].output[11] */ - TRIG7_IN_TR_GROUP11_OUTPUT12 = 0x0714u, /* tr_group[11].output[12] */ - TRIG7_IN_TR_GROUP11_OUTPUT13 = 0x0715u, /* tr_group[11].output[13] */ - TRIG7_IN_TR_GROUP11_OUTPUT14 = 0x0716u, /* tr_group[11].output[14] */ - TRIG7_IN_TR_GROUP11_OUTPUT15 = 0x0717u, /* tr_group[11].output[15] */ - TRIG7_IN_TR_GROUP12_OUTPUT0 = 0x0718u, /* tr_group[12].output[0] */ - TRIG7_IN_TR_GROUP12_OUTPUT1 = 0x0719u, /* tr_group[12].output[1] */ - TRIG7_IN_TR_GROUP12_OUTPUT2 = 0x071Au, /* tr_group[12].output[2] */ - TRIG7_IN_TR_GROUP12_OUTPUT3 = 0x071Bu, /* tr_group[12].output[3] */ - TRIG7_IN_TR_GROUP12_OUTPUT4 = 0x071Cu, /* tr_group[12].output[4] */ - TRIG7_IN_TR_GROUP12_OUTPUT5 = 0x071Du, /* tr_group[12].output[5] */ - TRIG7_IN_TR_GROUP12_OUTPUT6 = 0x071Eu, /* tr_group[12].output[6] */ - TRIG7_IN_TR_GROUP12_OUTPUT7 = 0x071Fu, /* tr_group[12].output[7] */ - TRIG7_IN_TR_GROUP13_OUTPUT16 = 0x0720u, /* tr_group[13].output[16] */ - TRIG7_IN_TR_GROUP13_OUTPUT17 = 0x0721u, /* tr_group[13].output[17] */ - TRIG7_IN_TR_GROUP14_OUTPUT8 = 0x0722u, /* tr_group[14].output[8] */ - TRIG7_IN_TR_GROUP14_OUTPUT9 = 0x0723u, /* tr_group[14].output[9] */ - TRIG7_IN_TR_GROUP14_OUTPUT10 = 0x0724u, /* tr_group[14].output[10] */ - TRIG7_IN_TR_GROUP14_OUTPUT11 = 0x0725u, /* tr_group[14].output[11] */ - TRIG7_IN_TR_GROUP14_OUTPUT12 = 0x0726u, /* tr_group[14].output[12] */ - TRIG7_IN_TR_GROUP14_OUTPUT13 = 0x0727u, /* tr_group[14].output[13] */ - TRIG7_IN_TR_GROUP14_OUTPUT14 = 0x0728u, /* tr_group[14].output[14] */ - TRIG7_IN_TR_GROUP14_OUTPUT15 = 0x0729u /* tr_group[14].output[15] */ -} en_trig_input_grp7_t; - -/* Trigger Input Group 8 - Trigger multiplexer to pins */ -typedef enum -{ - TRIG8_IN_TR_GROUP10_OUTPUT0 = 0x0800u, /* tr_group[10].output[0] */ - TRIG8_IN_TR_GROUP10_OUTPUT1 = 0x0801u, /* tr_group[10].output[1] */ - TRIG8_IN_TR_GROUP10_OUTPUT2 = 0x0802u, /* tr_group[10].output[2] */ - TRIG8_IN_TR_GROUP10_OUTPUT3 = 0x0803u, /* tr_group[10].output[3] */ - TRIG8_IN_TR_GROUP10_OUTPUT4 = 0x0804u, /* tr_group[10].output[4] */ - TRIG8_IN_TR_GROUP10_OUTPUT5 = 0x0805u, /* tr_group[10].output[5] */ - TRIG8_IN_TR_GROUP10_OUTPUT6 = 0x0806u, /* tr_group[10].output[6] */ - TRIG8_IN_TR_GROUP10_OUTPUT7 = 0x0807u, /* tr_group[10].output[7] */ - TRIG8_IN_TR_GROUP11_OUTPUT0 = 0x0808u, /* tr_group[11].output[0] */ - TRIG8_IN_TR_GROUP11_OUTPUT1 = 0x0809u, /* tr_group[11].output[1] */ - TRIG8_IN_TR_GROUP11_OUTPUT2 = 0x080Au, /* tr_group[11].output[2] */ - TRIG8_IN_TR_GROUP11_OUTPUT3 = 0x080Bu, /* tr_group[11].output[3] */ - TRIG8_IN_TR_GROUP11_OUTPUT4 = 0x080Cu, /* tr_group[11].output[4] */ - TRIG8_IN_TR_GROUP11_OUTPUT5 = 0x080Du, /* tr_group[11].output[5] */ - TRIG8_IN_TR_GROUP11_OUTPUT6 = 0x080Eu, /* tr_group[11].output[6] */ - TRIG8_IN_TR_GROUP11_OUTPUT7 = 0x080Fu, /* tr_group[11].output[7] */ - TRIG8_IN_TR_GROUP11_OUTPUT8 = 0x0810u, /* tr_group[11].output[8] */ - TRIG8_IN_TR_GROUP11_OUTPUT9 = 0x0811u, /* tr_group[11].output[9] */ - TRIG8_IN_TR_GROUP11_OUTPUT10 = 0x0812u, /* tr_group[11].output[10] */ - TRIG8_IN_TR_GROUP11_OUTPUT11 = 0x0813u, /* tr_group[11].output[11] */ - TRIG8_IN_TR_GROUP11_OUTPUT12 = 0x0814u, /* tr_group[11].output[12] */ - TRIG8_IN_TR_GROUP11_OUTPUT13 = 0x0815u, /* tr_group[11].output[13] */ - TRIG8_IN_TR_GROUP11_OUTPUT14 = 0x0816u, /* tr_group[11].output[14] */ - TRIG8_IN_TR_GROUP11_OUTPUT15 = 0x0817u, /* tr_group[11].output[15] */ - TRIG8_IN_TR_GROUP12_OUTPUT0 = 0x0818u, /* tr_group[12].output[0] */ - TRIG8_IN_TR_GROUP12_OUTPUT1 = 0x0819u, /* tr_group[12].output[1] */ - TRIG8_IN_TR_GROUP12_OUTPUT2 = 0x081Au, /* tr_group[12].output[2] */ - TRIG8_IN_TR_GROUP12_OUTPUT3 = 0x081Bu, /* tr_group[12].output[3] */ - TRIG8_IN_TR_GROUP12_OUTPUT4 = 0x081Cu, /* tr_group[12].output[4] */ - TRIG8_IN_TR_GROUP12_OUTPUT5 = 0x081Du, /* tr_group[12].output[5] */ - TRIG8_IN_TR_GROUP12_OUTPUT6 = 0x081Eu, /* tr_group[12].output[6] */ - TRIG8_IN_TR_GROUP12_OUTPUT7 = 0x081Fu, /* tr_group[12].output[7] */ - TRIG8_IN_TR_GROUP13_OUTPUT16 = 0x0820u, /* tr_group[13].output[16] */ - TRIG8_IN_TR_GROUP13_OUTPUT17 = 0x0821u, /* tr_group[13].output[17] */ - TRIG8_IN_TR_GROUP14_OUTPUT8 = 0x0822u, /* tr_group[14].output[8] */ - TRIG8_IN_TR_GROUP14_OUTPUT9 = 0x0823u, /* tr_group[14].output[9] */ - TRIG8_IN_TR_GROUP14_OUTPUT10 = 0x0824u, /* tr_group[14].output[10] */ - TRIG8_IN_TR_GROUP14_OUTPUT11 = 0x0825u, /* tr_group[14].output[11] */ - TRIG8_IN_TR_GROUP14_OUTPUT12 = 0x0826u, /* tr_group[14].output[12] */ - TRIG8_IN_TR_GROUP14_OUTPUT13 = 0x0827u, /* tr_group[14].output[13] */ - TRIG8_IN_TR_GROUP14_OUTPUT14 = 0x0828u, /* tr_group[14].output[14] */ - TRIG8_IN_TR_GROUP14_OUTPUT15 = 0x0829u /* tr_group[14].output[15] */ -} en_trig_input_grp8_t; - -/* Trigger Input Group 9 - Feedback mux to USB DMA interface */ -typedef enum -{ - TRIG9_IN_CPUSS_DW0_TR_OUT0 = 0x0900u, /* cpuss.dw0_tr_out[0] */ - TRIG9_IN_CPUSS_DW0_TR_OUT1 = 0x0901u, /* cpuss.dw0_tr_out[1] */ - TRIG9_IN_CPUSS_DW0_TR_OUT2 = 0x0902u, /* cpuss.dw0_tr_out[2] */ - TRIG9_IN_CPUSS_DW0_TR_OUT3 = 0x0903u, /* cpuss.dw0_tr_out[3] */ - TRIG9_IN_CPUSS_DW0_TR_OUT4 = 0x0904u, /* cpuss.dw0_tr_out[4] */ - TRIG9_IN_CPUSS_DW0_TR_OUT5 = 0x0905u, /* cpuss.dw0_tr_out[5] */ - TRIG9_IN_CPUSS_DW0_TR_OUT6 = 0x0906u, /* cpuss.dw0_tr_out[6] */ - TRIG9_IN_CPUSS_DW0_TR_OUT7 = 0x0907u, /* cpuss.dw0_tr_out[7] */ - TRIG9_IN_CPUSS_DW0_TR_OUT8 = 0x0908u, /* cpuss.dw0_tr_out[8] */ - TRIG9_IN_CPUSS_DW0_TR_OUT9 = 0x0909u, /* cpuss.dw0_tr_out[9] */ - TRIG9_IN_CPUSS_DW0_TR_OUT10 = 0x090Au, /* cpuss.dw0_tr_out[10] */ - TRIG9_IN_CPUSS_DW0_TR_OUT11 = 0x090Bu, /* cpuss.dw0_tr_out[11] */ - TRIG9_IN_CPUSS_DW0_TR_OUT12 = 0x090Cu, /* cpuss.dw0_tr_out[12] */ - TRIG9_IN_CPUSS_DW0_TR_OUT13 = 0x090Du, /* cpuss.dw0_tr_out[13] */ - TRIG9_IN_CPUSS_DW0_TR_OUT14 = 0x090Eu, /* cpuss.dw0_tr_out[14] */ - TRIG9_IN_CPUSS_DW0_TR_OUT15 = 0x090Fu, /* cpuss.dw0_tr_out[15] */ - TRIG9_IN_CPUSS_DW1_TR_OUT0 = 0x0910u, /* cpuss.dw1_tr_out[0] */ - TRIG9_IN_CPUSS_DW1_TR_OUT1 = 0x0911u, /* cpuss.dw1_tr_out[1] */ - TRIG9_IN_CPUSS_DW1_TR_OUT2 = 0x0912u, /* cpuss.dw1_tr_out[2] */ - TRIG9_IN_CPUSS_DW1_TR_OUT3 = 0x0913u, /* cpuss.dw1_tr_out[3] */ - TRIG9_IN_CPUSS_DW1_TR_OUT4 = 0x0914u, /* cpuss.dw1_tr_out[4] */ - TRIG9_IN_CPUSS_DW1_TR_OUT5 = 0x0915u, /* cpuss.dw1_tr_out[5] */ - TRIG9_IN_CPUSS_DW1_TR_OUT6 = 0x0916u, /* cpuss.dw1_tr_out[6] */ - TRIG9_IN_CPUSS_DW1_TR_OUT7 = 0x0917u, /* cpuss.dw1_tr_out[7] */ - TRIG9_IN_CPUSS_DW1_TR_OUT8 = 0x0918u, /* cpuss.dw1_tr_out[8] */ - TRIG9_IN_CPUSS_DW1_TR_OUT9 = 0x0919u, /* cpuss.dw1_tr_out[9] */ - TRIG9_IN_CPUSS_DW1_TR_OUT10 = 0x091Au, /* cpuss.dw1_tr_out[10] */ - TRIG9_IN_CPUSS_DW1_TR_OUT11 = 0x091Bu, /* cpuss.dw1_tr_out[11] */ - TRIG9_IN_CPUSS_DW1_TR_OUT12 = 0x091Cu, /* cpuss.dw1_tr_out[12] */ - TRIG9_IN_CPUSS_DW1_TR_OUT13 = 0x091Du, /* cpuss.dw1_tr_out[13] */ - TRIG9_IN_CPUSS_DW1_TR_OUT14 = 0x091Eu, /* cpuss.dw1_tr_out[14] */ - TRIG9_IN_CPUSS_DW1_TR_OUT15 = 0x091Fu /* cpuss.dw1_tr_out[15] */ -} en_trig_input_grp9_t; - -/* Trigger Input Group 10 - Reduces 32 datawire output triggers to 8 signals, used by all except USB */ -typedef enum -{ - TRIG10_IN_CPUSS_DW0_TR_OUT0 = 0x0A00u, /* cpuss.dw0_tr_out[0] */ - TRIG10_IN_CPUSS_DW0_TR_OUT1 = 0x0A01u, /* cpuss.dw0_tr_out[1] */ - TRIG10_IN_CPUSS_DW0_TR_OUT2 = 0x0A02u, /* cpuss.dw0_tr_out[2] */ - TRIG10_IN_CPUSS_DW0_TR_OUT3 = 0x0A03u, /* cpuss.dw0_tr_out[3] */ - TRIG10_IN_CPUSS_DW0_TR_OUT4 = 0x0A04u, /* cpuss.dw0_tr_out[4] */ - TRIG10_IN_CPUSS_DW0_TR_OUT5 = 0x0A05u, /* cpuss.dw0_tr_out[5] */ - TRIG10_IN_CPUSS_DW0_TR_OUT6 = 0x0A06u, /* cpuss.dw0_tr_out[6] */ - TRIG10_IN_CPUSS_DW0_TR_OUT7 = 0x0A07u, /* cpuss.dw0_tr_out[7] */ - TRIG10_IN_CPUSS_DW0_TR_OUT8 = 0x0A08u, /* cpuss.dw0_tr_out[8] */ - TRIG10_IN_CPUSS_DW0_TR_OUT9 = 0x0A09u, /* cpuss.dw0_tr_out[9] */ - TRIG10_IN_CPUSS_DW0_TR_OUT10 = 0x0A0Au, /* cpuss.dw0_tr_out[10] */ - TRIG10_IN_CPUSS_DW0_TR_OUT11 = 0x0A0Bu, /* cpuss.dw0_tr_out[11] */ - TRIG10_IN_CPUSS_DW0_TR_OUT12 = 0x0A0Cu, /* cpuss.dw0_tr_out[12] */ - TRIG10_IN_CPUSS_DW0_TR_OUT13 = 0x0A0Du, /* cpuss.dw0_tr_out[13] */ - TRIG10_IN_CPUSS_DW0_TR_OUT14 = 0x0A0Eu, /* cpuss.dw0_tr_out[14] */ - TRIG10_IN_CPUSS_DW0_TR_OUT15 = 0x0A0Fu, /* cpuss.dw0_tr_out[15] */ - TRIG10_IN_CPUSS_DW1_TR_OUT0 = 0x0A10u, /* cpuss.dw1_tr_out[0] */ - TRIG10_IN_CPUSS_DW1_TR_OUT1 = 0x0A11u, /* cpuss.dw1_tr_out[1] */ - TRIG10_IN_CPUSS_DW1_TR_OUT2 = 0x0A12u, /* cpuss.dw1_tr_out[2] */ - TRIG10_IN_CPUSS_DW1_TR_OUT3 = 0x0A13u, /* cpuss.dw1_tr_out[3] */ - TRIG10_IN_CPUSS_DW1_TR_OUT4 = 0x0A14u, /* cpuss.dw1_tr_out[4] */ - TRIG10_IN_CPUSS_DW1_TR_OUT5 = 0x0A15u, /* cpuss.dw1_tr_out[5] */ - TRIG10_IN_CPUSS_DW1_TR_OUT6 = 0x0A16u, /* cpuss.dw1_tr_out[6] */ - TRIG10_IN_CPUSS_DW1_TR_OUT7 = 0x0A17u, /* cpuss.dw1_tr_out[7] */ - TRIG10_IN_CPUSS_DW1_TR_OUT8 = 0x0A18u, /* cpuss.dw1_tr_out[8] */ - TRIG10_IN_CPUSS_DW1_TR_OUT9 = 0x0A19u, /* cpuss.dw1_tr_out[9] */ - TRIG10_IN_CPUSS_DW1_TR_OUT10 = 0x0A1Au, /* cpuss.dw1_tr_out[10] */ - TRIG10_IN_CPUSS_DW1_TR_OUT11 = 0x0A1Bu, /* cpuss.dw1_tr_out[11] */ - TRIG10_IN_CPUSS_DW1_TR_OUT12 = 0x0A1Cu, /* cpuss.dw1_tr_out[12] */ - TRIG10_IN_CPUSS_DW1_TR_OUT13 = 0x0A1Du, /* cpuss.dw1_tr_out[13] */ - TRIG10_IN_CPUSS_DW1_TR_OUT14 = 0x0A1Eu, /* cpuss.dw1_tr_out[14] */ - TRIG10_IN_CPUSS_DW1_TR_OUT15 = 0x0A1Fu /* cpuss.dw1_tr_out[15] */ -} en_trig_input_grp10_t; - -/* Trigger Input Group 11 - Reduces 96 tcpwm output triggers to 16 signals, used by all sinks */ -typedef enum -{ - TRIG11_IN_TCPWM0_TR_OVERFLOW0 = 0x0B00u, /* tcpwm[0].tr_overflow[0] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW1 = 0x0B01u, /* tcpwm[0].tr_overflow[1] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW2 = 0x0B02u, /* tcpwm[0].tr_overflow[2] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW3 = 0x0B03u, /* tcpwm[0].tr_overflow[3] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW4 = 0x0B04u, /* tcpwm[0].tr_overflow[4] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW5 = 0x0B05u, /* tcpwm[0].tr_overflow[5] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW6 = 0x0B06u, /* tcpwm[0].tr_overflow[6] */ - TRIG11_IN_TCPWM0_TR_OVERFLOW7 = 0x0B07u, /* tcpwm[0].tr_overflow[7] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH0 = 0x0B08u, /* tcpwm[0].tr_compare_match[0] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH1 = 0x0B09u, /* tcpwm[0].tr_compare_match[1] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH2 = 0x0B0Au, /* tcpwm[0].tr_compare_match[2] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH3 = 0x0B0Bu, /* tcpwm[0].tr_compare_match[3] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH4 = 0x0B0Cu, /* tcpwm[0].tr_compare_match[4] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH5 = 0x0B0Du, /* tcpwm[0].tr_compare_match[5] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH6 = 0x0B0Eu, /* tcpwm[0].tr_compare_match[6] */ - TRIG11_IN_TCPWM0_TR_COMPARE_MATCH7 = 0x0B0Fu, /* tcpwm[0].tr_compare_match[7] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW0 = 0x0B10u, /* tcpwm[0].tr_underflow[0] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW1 = 0x0B11u, /* tcpwm[0].tr_underflow[1] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW2 = 0x0B12u, /* tcpwm[0].tr_underflow[2] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW3 = 0x0B13u, /* tcpwm[0].tr_underflow[3] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW4 = 0x0B14u, /* tcpwm[0].tr_underflow[4] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW5 = 0x0B15u, /* tcpwm[0].tr_underflow[5] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW6 = 0x0B16u, /* tcpwm[0].tr_underflow[6] */ - TRIG11_IN_TCPWM0_TR_UNDERFLOW7 = 0x0B17u, /* tcpwm[0].tr_underflow[7] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW0 = 0x0B18u, /* tcpwm[1].tr_overflow[0] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW1 = 0x0B19u, /* tcpwm[1].tr_overflow[1] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW2 = 0x0B1Au, /* tcpwm[1].tr_overflow[2] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW3 = 0x0B1Bu, /* tcpwm[1].tr_overflow[3] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW4 = 0x0B1Cu, /* tcpwm[1].tr_overflow[4] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW5 = 0x0B1Du, /* tcpwm[1].tr_overflow[5] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW6 = 0x0B1Eu, /* tcpwm[1].tr_overflow[6] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW7 = 0x0B1Fu, /* tcpwm[1].tr_overflow[7] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW8 = 0x0B20u, /* tcpwm[1].tr_overflow[8] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW9 = 0x0B21u, /* tcpwm[1].tr_overflow[9] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW10 = 0x0B22u, /* tcpwm[1].tr_overflow[10] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW11 = 0x0B23u, /* tcpwm[1].tr_overflow[11] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW12 = 0x0B24u, /* tcpwm[1].tr_overflow[12] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW13 = 0x0B25u, /* tcpwm[1].tr_overflow[13] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW14 = 0x0B26u, /* tcpwm[1].tr_overflow[14] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW15 = 0x0B27u, /* tcpwm[1].tr_overflow[15] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW16 = 0x0B28u, /* tcpwm[1].tr_overflow[16] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW17 = 0x0B29u, /* tcpwm[1].tr_overflow[17] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW18 = 0x0B2Au, /* tcpwm[1].tr_overflow[18] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW19 = 0x0B2Bu, /* tcpwm[1].tr_overflow[19] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW20 = 0x0B2Cu, /* tcpwm[1].tr_overflow[20] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW21 = 0x0B2Du, /* tcpwm[1].tr_overflow[21] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW22 = 0x0B2Eu, /* tcpwm[1].tr_overflow[22] */ - TRIG11_IN_TCPWM1_TR_OVERFLOW23 = 0x0B2Fu, /* tcpwm[1].tr_overflow[23] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH0 = 0x0B30u, /* tcpwm[1].tr_compare_match[0] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH1 = 0x0B31u, /* tcpwm[1].tr_compare_match[1] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH2 = 0x0B32u, /* tcpwm[1].tr_compare_match[2] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH3 = 0x0B33u, /* tcpwm[1].tr_compare_match[3] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH4 = 0x0B34u, /* tcpwm[1].tr_compare_match[4] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH5 = 0x0B35u, /* tcpwm[1].tr_compare_match[5] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH6 = 0x0B36u, /* tcpwm[1].tr_compare_match[6] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH7 = 0x0B37u, /* tcpwm[1].tr_compare_match[7] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH8 = 0x0B38u, /* tcpwm[1].tr_compare_match[8] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH9 = 0x0B39u, /* tcpwm[1].tr_compare_match[9] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH10 = 0x0B3Au, /* tcpwm[1].tr_compare_match[10] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH11 = 0x0B3Bu, /* tcpwm[1].tr_compare_match[11] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH12 = 0x0B3Cu, /* tcpwm[1].tr_compare_match[12] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH13 = 0x0B3Du, /* tcpwm[1].tr_compare_match[13] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH14 = 0x0B3Eu, /* tcpwm[1].tr_compare_match[14] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH15 = 0x0B3Fu, /* tcpwm[1].tr_compare_match[15] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH16 = 0x0B40u, /* tcpwm[1].tr_compare_match[16] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH17 = 0x0B41u, /* tcpwm[1].tr_compare_match[17] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH18 = 0x0B42u, /* tcpwm[1].tr_compare_match[18] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH19 = 0x0B43u, /* tcpwm[1].tr_compare_match[19] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH20 = 0x0B44u, /* tcpwm[1].tr_compare_match[20] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH21 = 0x0B45u, /* tcpwm[1].tr_compare_match[21] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH22 = 0x0B46u, /* tcpwm[1].tr_compare_match[22] */ - TRIG11_IN_TCPWM1_TR_COMPARE_MATCH23 = 0x0B47u, /* tcpwm[1].tr_compare_match[23] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW0 = 0x0B48u, /* tcpwm[1].tr_underflow[0] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW1 = 0x0B49u, /* tcpwm[1].tr_underflow[1] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW2 = 0x0B4Au, /* tcpwm[1].tr_underflow[2] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW3 = 0x0B4Bu, /* tcpwm[1].tr_underflow[3] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW4 = 0x0B4Cu, /* tcpwm[1].tr_underflow[4] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW5 = 0x0B4Du, /* tcpwm[1].tr_underflow[5] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW6 = 0x0B4Eu, /* tcpwm[1].tr_underflow[6] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW7 = 0x0B4Fu, /* tcpwm[1].tr_underflow[7] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW8 = 0x0B50u, /* tcpwm[1].tr_underflow[8] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW9 = 0x0B51u, /* tcpwm[1].tr_underflow[9] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW10 = 0x0B52u, /* tcpwm[1].tr_underflow[10] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW11 = 0x0B53u, /* tcpwm[1].tr_underflow[11] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW12 = 0x0B54u, /* tcpwm[1].tr_underflow[12] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW13 = 0x0B55u, /* tcpwm[1].tr_underflow[13] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW14 = 0x0B56u, /* tcpwm[1].tr_underflow[14] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW15 = 0x0B57u, /* tcpwm[1].tr_underflow[15] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW16 = 0x0B58u, /* tcpwm[1].tr_underflow[16] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW17 = 0x0B59u, /* tcpwm[1].tr_underflow[17] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW18 = 0x0B5Au, /* tcpwm[1].tr_underflow[18] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW19 = 0x0B5Bu, /* tcpwm[1].tr_underflow[19] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW20 = 0x0B5Cu, /* tcpwm[1].tr_underflow[20] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW21 = 0x0B5Du, /* tcpwm[1].tr_underflow[21] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW22 = 0x0B5Eu, /* tcpwm[1].tr_underflow[22] */ - TRIG11_IN_TCPWM1_TR_UNDERFLOW23 = 0x0B5Fu /* tcpwm[1].tr_underflow[23] */ -} en_trig_input_grp11_t; - -/* Trigger Input Group 12 - Reduces 28 pin input signals to 10 triggers used by all sinks */ -typedef enum -{ - TRIG12_IN_PERI_TR_IO_INPUT0 = 0x0C00u, /* peri.tr_io_input[0] */ - TRIG12_IN_PERI_TR_IO_INPUT1 = 0x0C01u, /* peri.tr_io_input[1] */ - TRIG12_IN_PERI_TR_IO_INPUT2 = 0x0C02u, /* peri.tr_io_input[2] */ - TRIG12_IN_PERI_TR_IO_INPUT3 = 0x0C03u, /* peri.tr_io_input[3] */ - TRIG12_IN_PERI_TR_IO_INPUT4 = 0x0C04u, /* peri.tr_io_input[4] */ - TRIG12_IN_PERI_TR_IO_INPUT5 = 0x0C05u, /* peri.tr_io_input[5] */ - TRIG12_IN_PERI_TR_IO_INPUT6 = 0x0C06u, /* peri.tr_io_input[6] */ - TRIG12_IN_PERI_TR_IO_INPUT7 = 0x0C07u, /* peri.tr_io_input[7] */ - TRIG12_IN_PERI_TR_IO_INPUT8 = 0x0C08u, /* peri.tr_io_input[8] */ - TRIG12_IN_PERI_TR_IO_INPUT9 = 0x0C09u, /* peri.tr_io_input[9] */ - TRIG12_IN_PERI_TR_IO_INPUT10 = 0x0C0Au, /* peri.tr_io_input[10] */ - TRIG12_IN_PERI_TR_IO_INPUT11 = 0x0C0Bu, /* peri.tr_io_input[11] */ - TRIG12_IN_PERI_TR_IO_INPUT12 = 0x0C0Cu, /* peri.tr_io_input[12] */ - TRIG12_IN_PERI_TR_IO_INPUT13 = 0x0C0Du, /* peri.tr_io_input[13] */ - TRIG12_IN_PERI_TR_IO_INPUT14 = 0x0C0Eu, /* peri.tr_io_input[14] */ - TRIG12_IN_PERI_TR_IO_INPUT15 = 0x0C0Fu, /* peri.tr_io_input[15] */ - TRIG12_IN_PERI_TR_IO_INPUT16 = 0x0C10u, /* peri.tr_io_input[16] */ - TRIG12_IN_PERI_TR_IO_INPUT17 = 0x0C11u, /* peri.tr_io_input[17] */ - TRIG12_IN_PERI_TR_IO_INPUT18 = 0x0C12u, /* peri.tr_io_input[18] */ - TRIG12_IN_PERI_TR_IO_INPUT19 = 0x0C13u, /* peri.tr_io_input[19] */ - TRIG12_IN_PERI_TR_IO_INPUT20 = 0x0C14u, /* peri.tr_io_input[20] */ - TRIG12_IN_PERI_TR_IO_INPUT21 = 0x0C15u, /* peri.tr_io_input[21] */ - TRIG12_IN_PERI_TR_IO_INPUT22 = 0x0C16u, /* peri.tr_io_input[22] */ - TRIG12_IN_PERI_TR_IO_INPUT23 = 0x0C17u, /* peri.tr_io_input[23] */ - TRIG12_IN_PERI_TR_IO_INPUT24 = 0x0C18u, /* peri.tr_io_input[24] */ - TRIG12_IN_PERI_TR_IO_INPUT25 = 0x0C19u, /* peri.tr_io_input[25] */ - TRIG12_IN_PERI_TR_IO_INPUT26 = 0x0C1Au, /* peri.tr_io_input[26] */ - TRIG12_IN_PERI_TR_IO_INPUT27 = 0x0C1Bu /* peri.tr_io_input[27] */ -} en_trig_input_grp12_t; - -/* Trigger Input Group 13 - Reduces DMA requests to 16+2 outputs used by all sinks */ -typedef enum -{ - TRIG13_IN_SCB0_TR_TX_REQ = 0x0D00u, /* scb[0].tr_tx_req */ - TRIG13_IN_SCB0_TR_RX_REQ = 0x0D01u, /* scb[0].tr_rx_req */ - TRIG13_IN_SCB1_TR_TX_REQ = 0x0D02u, /* scb[1].tr_tx_req */ - TRIG13_IN_SCB1_TR_RX_REQ = 0x0D03u, /* scb[1].tr_rx_req */ - TRIG13_IN_SCB2_TR_TX_REQ = 0x0D04u, /* scb[2].tr_tx_req */ - TRIG13_IN_SCB2_TR_RX_REQ = 0x0D05u, /* scb[2].tr_rx_req */ - TRIG13_IN_SCB3_TR_TX_REQ = 0x0D06u, /* scb[3].tr_tx_req */ - TRIG13_IN_SCB3_TR_RX_REQ = 0x0D07u, /* scb[3].tr_rx_req */ - TRIG13_IN_SCB4_TR_TX_REQ = 0x0D08u, /* scb[4].tr_tx_req */ - TRIG13_IN_SCB4_TR_RX_REQ = 0x0D09u, /* scb[4].tr_rx_req */ - TRIG13_IN_SCB5_TR_TX_REQ = 0x0D0Au, /* scb[5].tr_tx_req */ - TRIG13_IN_SCB5_TR_RX_REQ = 0x0D0Bu, /* scb[5].tr_rx_req */ - TRIG13_IN_SCB6_TR_TX_REQ = 0x0D0Cu, /* scb[6].tr_tx_req */ - TRIG13_IN_SCB6_TR_RX_REQ = 0x0D0Du, /* scb[6].tr_rx_req */ - TRIG13_IN_SCB7_TR_TX_REQ = 0x0D0Eu, /* scb[7].tr_tx_req */ - TRIG13_IN_SCB7_TR_RX_REQ = 0x0D0Fu, /* scb[7].tr_rx_req */ - TRIG13_IN_SCB8_TR_TX_REQ = 0x0D10u, /* scb[8].tr_tx_req */ - TRIG13_IN_SCB8_TR_RX_REQ = 0x0D11u, /* scb[8].tr_rx_req */ - TRIG13_IN_AUDIOSS_TR_PDM_RX_REQ = 0x0D12u, /* audioss.tr_pdm_rx_req */ - TRIG13_IN_AUDIOSS_TR_I2S_TX_REQ = 0x0D13u, /* audioss.tr_i2s_tx_req */ - TRIG13_IN_AUDIOSS_TR_I2S_RX_REQ = 0x0D14u, /* audioss.tr_i2s_rx_req */ - TRIG13_IN_SMIF_TR_TX_REQ = 0x0D15u, /* smif.tr_tx_req */ - TRIG13_IN_SMIF_TR_RX_REQ = 0x0D16u, /* smif.tr_rx_req */ - TRIG13_IN_USB_DMA_REQ0 = 0x0D17u, /* usb.dma_req[0] */ - TRIG13_IN_USB_DMA_REQ1 = 0x0D18u, /* usb.dma_req[1] */ - TRIG13_IN_USB_DMA_REQ2 = 0x0D19u, /* usb.dma_req[2] */ - TRIG13_IN_USB_DMA_REQ3 = 0x0D1Au, /* usb.dma_req[3] */ - TRIG13_IN_USB_DMA_REQ4 = 0x0D1Bu, /* usb.dma_req[4] */ - TRIG13_IN_USB_DMA_REQ5 = 0x0D1Cu, /* usb.dma_req[5] */ - TRIG13_IN_USB_DMA_REQ6 = 0x0D1Du, /* usb.dma_req[6] */ - TRIG13_IN_USB_DMA_REQ7 = 0x0D1Eu /* usb.dma_req[7] */ -} en_trig_input_grp13_t; - -/* Trigger Input Group 14 - Reduces general purpose trigger inputs to 8+8 outputs used by all sinks */ -typedef enum -{ - TRIG14_IN_UDB_TR_UDB0 = 0x0E00u, /* udb.tr_udb[0] */ - TRIG14_IN_UDB_TR_UDB1 = 0x0E01u, /* udb.tr_udb[1] */ - TRIG14_IN_UDB_TR_UDB2 = 0x0E02u, /* udb.tr_udb[2] */ - TRIG14_IN_UDB_TR_UDB3 = 0x0E03u, /* udb.tr_udb[3] */ - TRIG14_IN_UDB_TR_UDB4 = 0x0E04u, /* udb.tr_udb[4] */ - TRIG14_IN_UDB_TR_UDB5 = 0x0E05u, /* udb.tr_udb[5] */ - TRIG14_IN_UDB_TR_UDB6 = 0x0E06u, /* udb.tr_udb[6] */ - TRIG14_IN_UDB_TR_UDB7 = 0x0E07u, /* udb.tr_udb[7] */ - TRIG14_IN_UDB_TR_UDB8 = 0x0E08u, /* udb.tr_udb[8] */ - TRIG14_IN_UDB_TR_UDB9 = 0x0E09u, /* udb.tr_udb[9] */ - TRIG14_IN_UDB_TR_UDB10 = 0x0E0Au, /* udb.tr_udb[10] */ - TRIG14_IN_UDB_TR_UDB11 = 0x0E0Bu, /* udb.tr_udb[11] */ - TRIG14_IN_UDB_TR_UDB12 = 0x0E0Cu, /* udb.tr_udb[12] */ - TRIG14_IN_UDB_TR_UDB13 = 0x0E0Du, /* udb.tr_udb[13] */ - TRIG14_IN_UDB_TR_UDB14 = 0x0E0Eu, /* udb.tr_udb[14] */ - TRIG14_IN_UDB_TR_UDB15 = 0x0E0Fu, /* udb.tr_udb[15] */ - TRIG14_IN_UDB_DSI_OUT_TR0 = 0x0E10u, /* udb.dsi_out_tr[0] */ - TRIG14_IN_UDB_DSI_OUT_TR1 = 0x0E11u, /* udb.dsi_out_tr[1] */ - TRIG14_IN_CPUSS_CTI_TR_OUT0 = 0x0E12u, /* cpuss.cti_tr_out[0] */ - TRIG14_IN_CPUSS_CTI_TR_OUT1 = 0x0E13u, /* cpuss.cti_tr_out[1] */ - TRIG14_IN_PASS_TR_SAR_OUT = 0x0E14u, /* pass.tr_sar_out */ - TRIG14_IN_PASS_TR_CTDAC_EMPTY = 0x0E15u, /* pass.tr_ctdac_empty */ - TRIG14_IN_PASS_DSI_CTB_CMP0 = 0x0E16u, /* pass.dsi_ctb_cmp0 */ - TRIG14_IN_PASS_DSI_CTB_CMP1 = 0x0E17u, /* pass.dsi_ctb_cmp1 */ - TRIG14_IN_LPCOMP_DSI_COMP0 = 0x0E18u, /* lpcomp.dsi_comp0 */ - TRIG14_IN_LPCOMP_DSI_COMP1 = 0x0E19u, /* lpcomp.dsi_comp1 */ - TRIG14_IN_SCB0_TR_I2C_SCL_FILTERED = 0x0E1Au, /* scb[0].tr_i2c_scl_filtered */ - TRIG14_IN_SCB1_TR_I2C_SCL_FILTERED = 0x0E1Bu, /* scb[1].tr_i2c_scl_filtered */ - TRIG14_IN_SCB2_TR_I2C_SCL_FILTERED = 0x0E1Cu, /* scb[2].tr_i2c_scl_filtered */ - TRIG14_IN_SCB3_TR_I2C_SCL_FILTERED = 0x0E1Du, /* scb[3].tr_i2c_scl_filtered */ - TRIG14_IN_SCB4_TR_I2C_SCL_FILTERED = 0x0E1Eu, /* scb[4].tr_i2c_scl_filtered */ - TRIG14_IN_SCB5_TR_I2C_SCL_FILTERED = 0x0E1Fu, /* scb[5].tr_i2c_scl_filtered */ - TRIG14_IN_SCB6_TR_I2C_SCL_FILTERED = 0x0E20u, /* scb[6].tr_i2c_scl_filtered */ - TRIG14_IN_SCB7_TR_I2C_SCL_FILTERED = 0x0E21u, /* scb[7].tr_i2c_scl_filtered */ - TRIG14_IN_SCB8_TR_I2C_SCL_FILTERED = 0x0E22u, /* scb[8].tr_i2c_scl_filtered */ - TRIG14_IN_CPUSS_TR_FAULT0 = 0x0E23u, /* cpuss.tr_fault[0] */ - TRIG14_IN_CPUSS_TR_FAULT1 = 0x0E24u /* cpuss.tr_fault[1] */ -} en_trig_input_grp14_t; - -/* Trigger Group Outputs */ -/* Trigger Output Group 0 - DMA Request Assignments */ -typedef enum -{ - TRIG0_OUT_CPUSS_DW0_TR_IN0 = 0x1000u, /* cpuss.dw0_tr_in[0] */ - TRIG0_OUT_CPUSS_DW0_TR_IN1 = 0x1001u, /* cpuss.dw0_tr_in[1] */ - TRIG0_OUT_CPUSS_DW0_TR_IN2 = 0x1002u, /* cpuss.dw0_tr_in[2] */ - TRIG0_OUT_CPUSS_DW0_TR_IN3 = 0x1003u, /* cpuss.dw0_tr_in[3] */ - TRIG0_OUT_CPUSS_DW0_TR_IN4 = 0x1004u, /* cpuss.dw0_tr_in[4] */ - TRIG0_OUT_CPUSS_DW0_TR_IN5 = 0x1005u, /* cpuss.dw0_tr_in[5] */ - TRIG0_OUT_CPUSS_DW0_TR_IN6 = 0x1006u, /* cpuss.dw0_tr_in[6] */ - TRIG0_OUT_CPUSS_DW0_TR_IN7 = 0x1007u, /* cpuss.dw0_tr_in[7] */ - TRIG0_OUT_CPUSS_DW0_TR_IN8 = 0x1008u, /* cpuss.dw0_tr_in[8] */ - TRIG0_OUT_CPUSS_DW0_TR_IN9 = 0x1009u, /* cpuss.dw0_tr_in[9] */ - TRIG0_OUT_CPUSS_DW0_TR_IN10 = 0x100Au, /* cpuss.dw0_tr_in[10] */ - TRIG0_OUT_CPUSS_DW0_TR_IN11 = 0x100Bu, /* cpuss.dw0_tr_in[11] */ - TRIG0_OUT_CPUSS_DW0_TR_IN12 = 0x100Cu, /* cpuss.dw0_tr_in[12] */ - TRIG0_OUT_CPUSS_DW0_TR_IN13 = 0x100Du, /* cpuss.dw0_tr_in[13] */ - TRIG0_OUT_CPUSS_DW0_TR_IN14 = 0x100Eu, /* cpuss.dw0_tr_in[14] */ - TRIG0_OUT_CPUSS_DW0_TR_IN15 = 0x100Fu /* cpuss.dw0_tr_in[15] */ -} en_trig_output_grp0_t; - -/* Trigger Output Group 1 - DMA Request Assignments */ -typedef enum -{ - TRIG1_OUT_CPUSS_DW1_TR_IN0 = 0x1100u, /* cpuss.dw1_tr_in[0] */ - TRIG1_OUT_CPUSS_DW1_TR_IN1 = 0x1101u, /* cpuss.dw1_tr_in[1] */ - TRIG1_OUT_CPUSS_DW1_TR_IN2 = 0x1102u, /* cpuss.dw1_tr_in[2] */ - TRIG1_OUT_CPUSS_DW1_TR_IN3 = 0x1103u, /* cpuss.dw1_tr_in[3] */ - TRIG1_OUT_CPUSS_DW1_TR_IN4 = 0x1104u, /* cpuss.dw1_tr_in[4] */ - TRIG1_OUT_CPUSS_DW1_TR_IN5 = 0x1105u, /* cpuss.dw1_tr_in[5] */ - TRIG1_OUT_CPUSS_DW1_TR_IN6 = 0x1106u, /* cpuss.dw1_tr_in[6] */ - TRIG1_OUT_CPUSS_DW1_TR_IN7 = 0x1107u, /* cpuss.dw1_tr_in[7] */ - TRIG1_OUT_CPUSS_DW1_TR_IN8 = 0x1108u, /* cpuss.dw1_tr_in[8] */ - TRIG1_OUT_CPUSS_DW1_TR_IN9 = 0x1109u, /* cpuss.dw1_tr_in[9] */ - TRIG1_OUT_CPUSS_DW1_TR_IN10 = 0x110Au, /* cpuss.dw1_tr_in[10] */ - TRIG1_OUT_CPUSS_DW1_TR_IN11 = 0x110Bu, /* cpuss.dw1_tr_in[11] */ - TRIG1_OUT_CPUSS_DW1_TR_IN12 = 0x110Cu, /* cpuss.dw1_tr_in[12] */ - TRIG1_OUT_CPUSS_DW1_TR_IN13 = 0x110Du, /* cpuss.dw1_tr_in[13] */ - TRIG1_OUT_CPUSS_DW1_TR_IN14 = 0x110Eu, /* cpuss.dw1_tr_in[14] */ - TRIG1_OUT_CPUSS_DW1_TR_IN15 = 0x110Fu /* cpuss.dw1_tr_in[15] */ -} en_trig_output_grp1_t; - -/* Trigger Output Group 2 - TCPWM trigger inputs */ -typedef enum -{ - TRIG2_OUT_TCPWM0_TR_IN0 = 0x1200u, /* tcpwm[0].tr_in[0] */ - TRIG2_OUT_TCPWM0_TR_IN1 = 0x1201u, /* tcpwm[0].tr_in[1] */ - TRIG2_OUT_TCPWM0_TR_IN2 = 0x1202u, /* tcpwm[0].tr_in[2] */ - TRIG2_OUT_TCPWM0_TR_IN3 = 0x1203u, /* tcpwm[0].tr_in[3] */ - TRIG2_OUT_TCPWM0_TR_IN4 = 0x1204u, /* tcpwm[0].tr_in[4] */ - TRIG2_OUT_TCPWM0_TR_IN5 = 0x1205u, /* tcpwm[0].tr_in[5] */ - TRIG2_OUT_TCPWM0_TR_IN6 = 0x1206u, /* tcpwm[0].tr_in[6] */ - TRIG2_OUT_TCPWM0_TR_IN7 = 0x1207u, /* tcpwm[0].tr_in[7] */ - TRIG2_OUT_TCPWM0_TR_IN8 = 0x1208u, /* tcpwm[0].tr_in[8] */ - TRIG2_OUT_TCPWM0_TR_IN9 = 0x1209u, /* tcpwm[0].tr_in[9] */ - TRIG2_OUT_TCPWM0_TR_IN10 = 0x120Au, /* tcpwm[0].tr_in[10] */ - TRIG2_OUT_TCPWM0_TR_IN11 = 0x120Bu, /* tcpwm[0].tr_in[11] */ - TRIG2_OUT_TCPWM0_TR_IN12 = 0x120Cu, /* tcpwm[0].tr_in[12] */ - TRIG2_OUT_TCPWM0_TR_IN13 = 0x120Du /* tcpwm[0].tr_in[13] */ -} en_trig_output_grp2_t; - -/* Trigger Output Group 3 - TCPWM trigger inputs */ -typedef enum -{ - TRIG3_OUT_TCPWM1_TR_IN0 = 0x1300u, /* tcpwm[1].tr_in[0] */ - TRIG3_OUT_TCPWM1_TR_IN1 = 0x1301u, /* tcpwm[1].tr_in[1] */ - TRIG3_OUT_TCPWM1_TR_IN2 = 0x1302u, /* tcpwm[1].tr_in[2] */ - TRIG3_OUT_TCPWM1_TR_IN3 = 0x1303u, /* tcpwm[1].tr_in[3] */ - TRIG3_OUT_TCPWM1_TR_IN4 = 0x1304u, /* tcpwm[1].tr_in[4] */ - TRIG3_OUT_TCPWM1_TR_IN5 = 0x1305u, /* tcpwm[1].tr_in[5] */ - TRIG3_OUT_TCPWM1_TR_IN6 = 0x1306u, /* tcpwm[1].tr_in[6] */ - TRIG3_OUT_TCPWM1_TR_IN7 = 0x1307u, /* tcpwm[1].tr_in[7] */ - TRIG3_OUT_TCPWM1_TR_IN8 = 0x1308u, /* tcpwm[1].tr_in[8] */ - TRIG3_OUT_TCPWM1_TR_IN9 = 0x1309u, /* tcpwm[1].tr_in[9] */ - TRIG3_OUT_TCPWM1_TR_IN10 = 0x130Au, /* tcpwm[1].tr_in[10] */ - TRIG3_OUT_TCPWM1_TR_IN11 = 0x130Bu, /* tcpwm[1].tr_in[11] */ - TRIG3_OUT_TCPWM1_TR_IN12 = 0x130Cu, /* tcpwm[1].tr_in[12] */ - TRIG3_OUT_TCPWM1_TR_IN13 = 0x130Du /* tcpwm[1].tr_in[13] */ -} en_trig_output_grp3_t; - -/* Trigger Output Group 4 - PROFILE trigger multiplexer */ -typedef enum -{ - TRIG4_OUT_PROFILE_TR_START = 0x1400u, /* profile.tr_start */ - TRIG4_OUT_PROFILE_TR_STOP = 0x1401u /* profile.tr_stop */ -} en_trig_output_grp4_t; - -/* Trigger Output Group 5 - CPUSS.CTI trigger multiplexer */ -typedef enum -{ - TRIG5_OUT_CPUSS_CTI_TR_IN0 = 0x1500u, /* cpuss.cti_tr_in[0] */ - TRIG5_OUT_CPUSS_CTI_TR_IN1 = 0x1501u /* cpuss.cti_tr_in[1] */ -} en_trig_output_grp5_t; - -/* Trigger Output Group 6 - PASS trigger multiplexer */ -typedef enum -{ - TRIG6_OUT_PASS_TR_SAR_IN = 0x1600u /* pass.tr_sar_in */ -} en_trig_output_grp6_t; - -/* Trigger Output Group 7 - UDB general purpose trigger multiplexer */ -typedef enum -{ - TRIG7_OUT_UDB_TR_IN0 = 0x1700u, /* udb.tr_in[0] */ - TRIG7_OUT_UDB_TR_IN1 = 0x1701u /* udb.tr_in[1] */ -} en_trig_output_grp7_t; - -/* Trigger Output Group 8 - Trigger multiplexer to pins */ -typedef enum -{ - TRIG8_OUT_PERI_TR_IO_OUTPUT0 = 0x1800u, /* peri.tr_io_output[0] */ - TRIG8_OUT_PERI_TR_IO_OUTPUT1 = 0x1801u /* peri.tr_io_output[1] */ -} en_trig_output_grp8_t; - -/* Trigger Output Group 9 - Feedback mux to USB DMA interface */ -typedef enum -{ - TRIG9_OUT_USB_DMA_BURSTEND0 = 0x1900u, /* usb.dma_burstend[0] */ - TRIG9_OUT_USB_DMA_BURSTEND1 = 0x1901u, /* usb.dma_burstend[1] */ - TRIG9_OUT_USB_DMA_BURSTEND2 = 0x1902u, /* usb.dma_burstend[2] */ - TRIG9_OUT_USB_DMA_BURSTEND3 = 0x1903u, /* usb.dma_burstend[3] */ - TRIG9_OUT_USB_DMA_BURSTEND4 = 0x1904u, /* usb.dma_burstend[4] */ - TRIG9_OUT_USB_DMA_BURSTEND5 = 0x1905u, /* usb.dma_burstend[5] */ - TRIG9_OUT_USB_DMA_BURSTEND6 = 0x1906u, /* usb.dma_burstend[6] */ - TRIG9_OUT_USB_DMA_BURSTEND7 = 0x1907u /* usb.dma_burstend[7] */ -} en_trig_output_grp9_t; - -/* Trigger Output Group 10 - Reduces 32 datawire output triggers to 8 signals, used by all except USB */ -typedef enum -{ - TRIG10_OUT_UDB_TR_DW_ACK0 = 0x1A00u, /* udb.tr_dw_ack[0] */ - TRIG10_OUT_TR_GROUP0_INPUT0 = 0x1A00u, /* tr_group[0].input[0] */ - TRIG10_OUT_TR_GROUP1_INPUT0 = 0x1A00u, /* tr_group[1].input[0] */ - TRIG10_OUT_TR_GROUP2_INPUT0 = 0x1A00u, /* tr_group[2].input[0] */ - TRIG10_OUT_TR_GROUP3_INPUT0 = 0x1A00u, /* tr_group[3].input[0] */ - TRIG10_OUT_TR_GROUP4_INPUT0 = 0x1A00u, /* tr_group[4].input[0] */ - TRIG10_OUT_TR_GROUP5_INPUT0 = 0x1A00u, /* tr_group[5].input[0] */ - TRIG10_OUT_TR_GROUP6_INPUT0 = 0x1A00u, /* tr_group[6].input[0] */ - TRIG10_OUT_TR_GROUP7_INPUT0 = 0x1A00u, /* tr_group[7].input[0] */ - TRIG10_OUT_TR_GROUP8_INPUT0 = 0x1A00u, /* tr_group[8].input[0] */ - TRIG10_OUT_UDB_TR_DW_ACK1 = 0x1A01u, /* udb.tr_dw_ack[1] */ - TRIG10_OUT_TR_GROUP0_INPUT1 = 0x1A01u, /* tr_group[0].input[1] */ - TRIG10_OUT_TR_GROUP1_INPUT1 = 0x1A01u, /* tr_group[1].input[1] */ - TRIG10_OUT_TR_GROUP2_INPUT1 = 0x1A01u, /* tr_group[2].input[1] */ - TRIG10_OUT_TR_GROUP3_INPUT1 = 0x1A01u, /* tr_group[3].input[1] */ - TRIG10_OUT_TR_GROUP4_INPUT1 = 0x1A01u, /* tr_group[4].input[1] */ - TRIG10_OUT_TR_GROUP5_INPUT1 = 0x1A01u, /* tr_group[5].input[1] */ - TRIG10_OUT_TR_GROUP6_INPUT1 = 0x1A01u, /* tr_group[6].input[1] */ - TRIG10_OUT_TR_GROUP7_INPUT1 = 0x1A01u, /* tr_group[7].input[1] */ - TRIG10_OUT_TR_GROUP8_INPUT1 = 0x1A01u, /* tr_group[8].input[1] */ - TRIG10_OUT_UDB_TR_DW_ACK2 = 0x1A02u, /* udb.tr_dw_ack[2] */ - TRIG10_OUT_TR_GROUP0_INPUT2 = 0x1A02u, /* tr_group[0].input[2] */ - TRIG10_OUT_TR_GROUP1_INPUT2 = 0x1A02u, /* tr_group[1].input[2] */ - TRIG10_OUT_TR_GROUP2_INPUT2 = 0x1A02u, /* tr_group[2].input[2] */ - TRIG10_OUT_TR_GROUP3_INPUT2 = 0x1A02u, /* tr_group[3].input[2] */ - TRIG10_OUT_TR_GROUP4_INPUT2 = 0x1A02u, /* tr_group[4].input[2] */ - TRIG10_OUT_TR_GROUP5_INPUT2 = 0x1A02u, /* tr_group[5].input[2] */ - TRIG10_OUT_TR_GROUP6_INPUT2 = 0x1A02u, /* tr_group[6].input[2] */ - TRIG10_OUT_TR_GROUP7_INPUT2 = 0x1A02u, /* tr_group[7].input[2] */ - TRIG10_OUT_TR_GROUP8_INPUT2 = 0x1A02u, /* tr_group[8].input[2] */ - TRIG10_OUT_UDB_TR_DW_ACK3 = 0x1A03u, /* udb.tr_dw_ack[3] */ - TRIG10_OUT_TR_GROUP0_INPUT3 = 0x1A03u, /* tr_group[0].input[3] */ - TRIG10_OUT_TR_GROUP1_INPUT3 = 0x1A03u, /* tr_group[1].input[3] */ - TRIG10_OUT_TR_GROUP2_INPUT3 = 0x1A03u, /* tr_group[2].input[3] */ - TRIG10_OUT_TR_GROUP3_INPUT3 = 0x1A03u, /* tr_group[3].input[3] */ - TRIG10_OUT_TR_GROUP4_INPUT3 = 0x1A03u, /* tr_group[4].input[3] */ - TRIG10_OUT_TR_GROUP5_INPUT3 = 0x1A03u, /* tr_group[5].input[3] */ - TRIG10_OUT_TR_GROUP6_INPUT3 = 0x1A03u, /* tr_group[6].input[3] */ - TRIG10_OUT_TR_GROUP7_INPUT3 = 0x1A03u, /* tr_group[7].input[3] */ - TRIG10_OUT_TR_GROUP8_INPUT3 = 0x1A03u, /* tr_group[8].input[3] */ - TRIG10_OUT_UDB_TR_DW_ACK4 = 0x1A04u, /* udb.tr_dw_ack[4] */ - TRIG10_OUT_TR_GROUP0_INPUT4 = 0x1A04u, /* tr_group[0].input[4] */ - TRIG10_OUT_TR_GROUP1_INPUT4 = 0x1A04u, /* tr_group[1].input[4] */ - TRIG10_OUT_TR_GROUP2_INPUT4 = 0x1A04u, /* tr_group[2].input[4] */ - TRIG10_OUT_TR_GROUP3_INPUT4 = 0x1A04u, /* tr_group[3].input[4] */ - TRIG10_OUT_TR_GROUP4_INPUT4 = 0x1A04u, /* tr_group[4].input[4] */ - TRIG10_OUT_TR_GROUP5_INPUT4 = 0x1A04u, /* tr_group[5].input[4] */ - TRIG10_OUT_TR_GROUP6_INPUT4 = 0x1A04u, /* tr_group[6].input[4] */ - TRIG10_OUT_TR_GROUP7_INPUT4 = 0x1A04u, /* tr_group[7].input[4] */ - TRIG10_OUT_TR_GROUP8_INPUT4 = 0x1A04u, /* tr_group[8].input[4] */ - TRIG10_OUT_UDB_TR_DW_ACK5 = 0x1A05u, /* udb.tr_dw_ack[5] */ - TRIG10_OUT_TR_GROUP0_INPUT5 = 0x1A05u, /* tr_group[0].input[5] */ - TRIG10_OUT_TR_GROUP1_INPUT5 = 0x1A05u, /* tr_group[1].input[5] */ - TRIG10_OUT_TR_GROUP2_INPUT5 = 0x1A05u, /* tr_group[2].input[5] */ - TRIG10_OUT_TR_GROUP3_INPUT5 = 0x1A05u, /* tr_group[3].input[5] */ - TRIG10_OUT_TR_GROUP4_INPUT5 = 0x1A05u, /* tr_group[4].input[5] */ - TRIG10_OUT_TR_GROUP5_INPUT5 = 0x1A05u, /* tr_group[5].input[5] */ - TRIG10_OUT_TR_GROUP6_INPUT5 = 0x1A05u, /* tr_group[6].input[5] */ - TRIG10_OUT_TR_GROUP7_INPUT5 = 0x1A05u, /* tr_group[7].input[5] */ - TRIG10_OUT_TR_GROUP8_INPUT5 = 0x1A05u, /* tr_group[8].input[5] */ - TRIG10_OUT_UDB_TR_DW_ACK6 = 0x1A06u, /* udb.tr_dw_ack[6] */ - TRIG10_OUT_TR_GROUP0_INPUT6 = 0x1A06u, /* tr_group[0].input[6] */ - TRIG10_OUT_TR_GROUP1_INPUT6 = 0x1A06u, /* tr_group[1].input[6] */ - TRIG10_OUT_TR_GROUP2_INPUT6 = 0x1A06u, /* tr_group[2].input[6] */ - TRIG10_OUT_TR_GROUP3_INPUT6 = 0x1A06u, /* tr_group[3].input[6] */ - TRIG10_OUT_TR_GROUP4_INPUT6 = 0x1A06u, /* tr_group[4].input[6] */ - TRIG10_OUT_TR_GROUP5_INPUT6 = 0x1A06u, /* tr_group[5].input[6] */ - TRIG10_OUT_TR_GROUP6_INPUT6 = 0x1A06u, /* tr_group[6].input[6] */ - TRIG10_OUT_TR_GROUP7_INPUT6 = 0x1A06u, /* tr_group[7].input[6] */ - TRIG10_OUT_TR_GROUP8_INPUT6 = 0x1A06u, /* tr_group[8].input[6] */ - TRIG10_OUT_UDB_TR_DW_ACK7 = 0x1A07u, /* udb.tr_dw_ack[7] */ - TRIG10_OUT_TR_GROUP0_INPUT7 = 0x1A07u, /* tr_group[0].input[7] */ - TRIG10_OUT_TR_GROUP1_INPUT7 = 0x1A07u, /* tr_group[1].input[7] */ - TRIG10_OUT_TR_GROUP2_INPUT7 = 0x1A07u, /* tr_group[2].input[7] */ - TRIG10_OUT_TR_GROUP3_INPUT7 = 0x1A07u, /* tr_group[3].input[7] */ - TRIG10_OUT_TR_GROUP4_INPUT7 = 0x1A07u, /* tr_group[4].input[7] */ - TRIG10_OUT_TR_GROUP5_INPUT7 = 0x1A07u, /* tr_group[5].input[7] */ - TRIG10_OUT_TR_GROUP6_INPUT7 = 0x1A07u, /* tr_group[6].input[7] */ - TRIG10_OUT_TR_GROUP7_INPUT7 = 0x1A07u, /* tr_group[7].input[7] */ - TRIG10_OUT_TR_GROUP8_INPUT7 = 0x1A07u /* tr_group[8].input[7] */ -} en_trig_output_grp10_t; - -/* Trigger Output Group 11 - Reduces 96 tcpwm output triggers to 16 signals, used by all sinks */ -typedef enum -{ - TRIG11_OUT_TR_GROUP0_INPUT8 = 0x1B00u, /* tr_group[0].input[8] */ - TRIG11_OUT_TR_GROUP1_INPUT8 = 0x1B00u, /* tr_group[1].input[8] */ - TRIG11_OUT_TR_GROUP2_INPUT8 = 0x1B00u, /* tr_group[2].input[8] */ - TRIG11_OUT_TR_GROUP3_INPUT8 = 0x1B00u, /* tr_group[3].input[8] */ - TRIG11_OUT_TR_GROUP4_INPUT8 = 0x1B00u, /* tr_group[4].input[8] */ - TRIG11_OUT_TR_GROUP5_INPUT8 = 0x1B00u, /* tr_group[5].input[8] */ - TRIG11_OUT_TR_GROUP6_INPUT8 = 0x1B00u, /* tr_group[6].input[8] */ - TRIG11_OUT_TR_GROUP7_INPUT8 = 0x1B00u, /* tr_group[7].input[8] */ - TRIG11_OUT_TR_GROUP8_INPUT8 = 0x1B00u, /* tr_group[8].input[8] */ - TRIG11_OUT_TR_GROUP0_INPUT9 = 0x1B01u, /* tr_group[0].input[9] */ - TRIG11_OUT_TR_GROUP1_INPUT9 = 0x1B01u, /* tr_group[1].input[9] */ - TRIG11_OUT_TR_GROUP2_INPUT9 = 0x1B01u, /* tr_group[2].input[9] */ - TRIG11_OUT_TR_GROUP3_INPUT9 = 0x1B01u, /* tr_group[3].input[9] */ - TRIG11_OUT_TR_GROUP4_INPUT9 = 0x1B01u, /* tr_group[4].input[9] */ - TRIG11_OUT_TR_GROUP5_INPUT9 = 0x1B01u, /* tr_group[5].input[9] */ - TRIG11_OUT_TR_GROUP6_INPUT9 = 0x1B01u, /* tr_group[6].input[9] */ - TRIG11_OUT_TR_GROUP7_INPUT9 = 0x1B01u, /* tr_group[7].input[9] */ - TRIG11_OUT_TR_GROUP8_INPUT9 = 0x1B01u, /* tr_group[8].input[9] */ - TRIG11_OUT_TR_GROUP0_INPUT10 = 0x1B02u, /* tr_group[0].input[10] */ - TRIG11_OUT_TR_GROUP1_INPUT10 = 0x1B02u, /* tr_group[1].input[10] */ - TRIG11_OUT_TR_GROUP2_INPUT10 = 0x1B02u, /* tr_group[2].input[10] */ - TRIG11_OUT_TR_GROUP3_INPUT10 = 0x1B02u, /* tr_group[3].input[10] */ - TRIG11_OUT_TR_GROUP4_INPUT10 = 0x1B02u, /* tr_group[4].input[10] */ - TRIG11_OUT_TR_GROUP5_INPUT10 = 0x1B02u, /* tr_group[5].input[10] */ - TRIG11_OUT_TR_GROUP6_INPUT10 = 0x1B02u, /* tr_group[6].input[10] */ - TRIG11_OUT_TR_GROUP7_INPUT10 = 0x1B02u, /* tr_group[7].input[10] */ - TRIG11_OUT_TR_GROUP8_INPUT10 = 0x1B02u, /* tr_group[8].input[10] */ - TRIG11_OUT_TR_GROUP0_INPUT11 = 0x1B03u, /* tr_group[0].input[11] */ - TRIG11_OUT_TR_GROUP1_INPUT11 = 0x1B03u, /* tr_group[1].input[11] */ - TRIG11_OUT_TR_GROUP2_INPUT11 = 0x1B03u, /* tr_group[2].input[11] */ - TRIG11_OUT_TR_GROUP3_INPUT11 = 0x1B03u, /* tr_group[3].input[11] */ - TRIG11_OUT_TR_GROUP4_INPUT11 = 0x1B03u, /* tr_group[4].input[11] */ - TRIG11_OUT_TR_GROUP5_INPUT11 = 0x1B03u, /* tr_group[5].input[11] */ - TRIG11_OUT_TR_GROUP6_INPUT11 = 0x1B03u, /* tr_group[6].input[11] */ - TRIG11_OUT_TR_GROUP7_INPUT11 = 0x1B03u, /* tr_group[7].input[11] */ - TRIG11_OUT_TR_GROUP8_INPUT11 = 0x1B03u, /* tr_group[8].input[11] */ - TRIG11_OUT_TR_GROUP0_INPUT12 = 0x1B04u, /* tr_group[0].input[12] */ - TRIG11_OUT_TR_GROUP1_INPUT12 = 0x1B04u, /* tr_group[1].input[12] */ - TRIG11_OUT_TR_GROUP2_INPUT12 = 0x1B04u, /* tr_group[2].input[12] */ - TRIG11_OUT_TR_GROUP3_INPUT12 = 0x1B04u, /* tr_group[3].input[12] */ - TRIG11_OUT_TR_GROUP4_INPUT12 = 0x1B04u, /* tr_group[4].input[12] */ - TRIG11_OUT_TR_GROUP5_INPUT12 = 0x1B04u, /* tr_group[5].input[12] */ - TRIG11_OUT_TR_GROUP6_INPUT12 = 0x1B04u, /* tr_group[6].input[12] */ - TRIG11_OUT_TR_GROUP7_INPUT12 = 0x1B04u, /* tr_group[7].input[12] */ - TRIG11_OUT_TR_GROUP8_INPUT12 = 0x1B04u, /* tr_group[8].input[12] */ - TRIG11_OUT_TR_GROUP0_INPUT13 = 0x1B05u, /* tr_group[0].input[13] */ - TRIG11_OUT_TR_GROUP1_INPUT13 = 0x1B05u, /* tr_group[1].input[13] */ - TRIG11_OUT_TR_GROUP2_INPUT13 = 0x1B05u, /* tr_group[2].input[13] */ - TRIG11_OUT_TR_GROUP3_INPUT13 = 0x1B05u, /* tr_group[3].input[13] */ - TRIG11_OUT_TR_GROUP4_INPUT13 = 0x1B05u, /* tr_group[4].input[13] */ - TRIG11_OUT_TR_GROUP5_INPUT13 = 0x1B05u, /* tr_group[5].input[13] */ - TRIG11_OUT_TR_GROUP6_INPUT13 = 0x1B05u, /* tr_group[6].input[13] */ - TRIG11_OUT_TR_GROUP7_INPUT13 = 0x1B05u, /* tr_group[7].input[13] */ - TRIG11_OUT_TR_GROUP8_INPUT13 = 0x1B05u, /* tr_group[8].input[13] */ - TRIG11_OUT_TR_GROUP0_INPUT14 = 0x1B06u, /* tr_group[0].input[14] */ - TRIG11_OUT_TR_GROUP1_INPUT14 = 0x1B06u, /* tr_group[1].input[14] */ - TRIG11_OUT_TR_GROUP2_INPUT14 = 0x1B06u, /* tr_group[2].input[14] */ - TRIG11_OUT_TR_GROUP3_INPUT14 = 0x1B06u, /* tr_group[3].input[14] */ - TRIG11_OUT_TR_GROUP4_INPUT14 = 0x1B06u, /* tr_group[4].input[14] */ - TRIG11_OUT_TR_GROUP5_INPUT14 = 0x1B06u, /* tr_group[5].input[14] */ - TRIG11_OUT_TR_GROUP6_INPUT14 = 0x1B06u, /* tr_group[6].input[14] */ - TRIG11_OUT_TR_GROUP7_INPUT14 = 0x1B06u, /* tr_group[7].input[14] */ - TRIG11_OUT_TR_GROUP8_INPUT14 = 0x1B06u, /* tr_group[8].input[14] */ - TRIG11_OUT_TR_GROUP0_INPUT15 = 0x1B07u, /* tr_group[0].input[15] */ - TRIG11_OUT_TR_GROUP1_INPUT15 = 0x1B07u, /* tr_group[1].input[15] */ - TRIG11_OUT_TR_GROUP2_INPUT15 = 0x1B07u, /* tr_group[2].input[15] */ - TRIG11_OUT_TR_GROUP3_INPUT15 = 0x1B07u, /* tr_group[3].input[15] */ - TRIG11_OUT_TR_GROUP4_INPUT15 = 0x1B07u, /* tr_group[4].input[15] */ - TRIG11_OUT_TR_GROUP5_INPUT15 = 0x1B07u, /* tr_group[5].input[15] */ - TRIG11_OUT_TR_GROUP6_INPUT15 = 0x1B07u, /* tr_group[6].input[15] */ - TRIG11_OUT_TR_GROUP7_INPUT15 = 0x1B07u, /* tr_group[7].input[15] */ - TRIG11_OUT_TR_GROUP8_INPUT15 = 0x1B07u, /* tr_group[8].input[15] */ - TRIG11_OUT_TR_GROUP0_INPUT16 = 0x1B08u, /* tr_group[0].input[16] */ - TRIG11_OUT_TR_GROUP1_INPUT16 = 0x1B08u, /* tr_group[1].input[16] */ - TRIG11_OUT_TR_GROUP2_INPUT16 = 0x1B08u, /* tr_group[2].input[16] */ - TRIG11_OUT_TR_GROUP3_INPUT16 = 0x1B08u, /* tr_group[3].input[16] */ - TRIG11_OUT_TR_GROUP4_INPUT16 = 0x1B08u, /* tr_group[4].input[16] */ - TRIG11_OUT_TR_GROUP5_INPUT16 = 0x1B08u, /* tr_group[5].input[16] */ - TRIG11_OUT_TR_GROUP6_INPUT16 = 0x1B08u, /* tr_group[6].input[16] */ - TRIG11_OUT_TR_GROUP7_INPUT16 = 0x1B08u, /* tr_group[7].input[16] */ - TRIG11_OUT_TR_GROUP8_INPUT16 = 0x1B08u, /* tr_group[8].input[16] */ - TRIG11_OUT_TR_GROUP0_INPUT17 = 0x1B09u, /* tr_group[0].input[17] */ - TRIG11_OUT_TR_GROUP1_INPUT17 = 0x1B09u, /* tr_group[1].input[17] */ - TRIG11_OUT_TR_GROUP2_INPUT17 = 0x1B09u, /* tr_group[2].input[17] */ - TRIG11_OUT_TR_GROUP3_INPUT17 = 0x1B09u, /* tr_group[3].input[17] */ - TRIG11_OUT_TR_GROUP4_INPUT17 = 0x1B09u, /* tr_group[4].input[17] */ - TRIG11_OUT_TR_GROUP5_INPUT17 = 0x1B09u, /* tr_group[5].input[17] */ - TRIG11_OUT_TR_GROUP6_INPUT17 = 0x1B09u, /* tr_group[6].input[17] */ - TRIG11_OUT_TR_GROUP7_INPUT17 = 0x1B09u, /* tr_group[7].input[17] */ - TRIG11_OUT_TR_GROUP8_INPUT17 = 0x1B09u, /* tr_group[8].input[17] */ - TRIG11_OUT_TR_GROUP0_INPUT18 = 0x1B0Au, /* tr_group[0].input[18] */ - TRIG11_OUT_TR_GROUP1_INPUT18 = 0x1B0Au, /* tr_group[1].input[18] */ - TRIG11_OUT_TR_GROUP2_INPUT18 = 0x1B0Au, /* tr_group[2].input[18] */ - TRIG11_OUT_TR_GROUP3_INPUT18 = 0x1B0Au, /* tr_group[3].input[18] */ - TRIG11_OUT_TR_GROUP4_INPUT18 = 0x1B0Au, /* tr_group[4].input[18] */ - TRIG11_OUT_TR_GROUP5_INPUT18 = 0x1B0Au, /* tr_group[5].input[18] */ - TRIG11_OUT_TR_GROUP6_INPUT18 = 0x1B0Au, /* tr_group[6].input[18] */ - TRIG11_OUT_TR_GROUP7_INPUT18 = 0x1B0Au, /* tr_group[7].input[18] */ - TRIG11_OUT_TR_GROUP8_INPUT18 = 0x1B0Au, /* tr_group[8].input[18] */ - TRIG11_OUT_TR_GROUP0_INPUT19 = 0x1B0Bu, /* tr_group[0].input[19] */ - TRIG11_OUT_TR_GROUP1_INPUT19 = 0x1B0Bu, /* tr_group[1].input[19] */ - TRIG11_OUT_TR_GROUP2_INPUT19 = 0x1B0Bu, /* tr_group[2].input[19] */ - TRIG11_OUT_TR_GROUP3_INPUT19 = 0x1B0Bu, /* tr_group[3].input[19] */ - TRIG11_OUT_TR_GROUP4_INPUT19 = 0x1B0Bu, /* tr_group[4].input[19] */ - TRIG11_OUT_TR_GROUP5_INPUT19 = 0x1B0Bu, /* tr_group[5].input[19] */ - TRIG11_OUT_TR_GROUP6_INPUT19 = 0x1B0Bu, /* tr_group[6].input[19] */ - TRIG11_OUT_TR_GROUP7_INPUT19 = 0x1B0Bu, /* tr_group[7].input[19] */ - TRIG11_OUT_TR_GROUP8_INPUT19 = 0x1B0Bu, /* tr_group[8].input[19] */ - TRIG11_OUT_TR_GROUP0_INPUT20 = 0x1B0Cu, /* tr_group[0].input[20] */ - TRIG11_OUT_TR_GROUP1_INPUT20 = 0x1B0Cu, /* tr_group[1].input[20] */ - TRIG11_OUT_TR_GROUP2_INPUT20 = 0x1B0Cu, /* tr_group[2].input[20] */ - TRIG11_OUT_TR_GROUP3_INPUT20 = 0x1B0Cu, /* tr_group[3].input[20] */ - TRIG11_OUT_TR_GROUP4_INPUT20 = 0x1B0Cu, /* tr_group[4].input[20] */ - TRIG11_OUT_TR_GROUP5_INPUT20 = 0x1B0Cu, /* tr_group[5].input[20] */ - TRIG11_OUT_TR_GROUP6_INPUT20 = 0x1B0Cu, /* tr_group[6].input[20] */ - TRIG11_OUT_TR_GROUP7_INPUT20 = 0x1B0Cu, /* tr_group[7].input[20] */ - TRIG11_OUT_TR_GROUP8_INPUT20 = 0x1B0Cu, /* tr_group[8].input[20] */ - TRIG11_OUT_TR_GROUP0_INPUT21 = 0x1B0Du, /* tr_group[0].input[21] */ - TRIG11_OUT_TR_GROUP1_INPUT21 = 0x1B0Du, /* tr_group[1].input[21] */ - TRIG11_OUT_TR_GROUP2_INPUT21 = 0x1B0Du, /* tr_group[2].input[21] */ - TRIG11_OUT_TR_GROUP3_INPUT21 = 0x1B0Du, /* tr_group[3].input[21] */ - TRIG11_OUT_TR_GROUP4_INPUT21 = 0x1B0Du, /* tr_group[4].input[21] */ - TRIG11_OUT_TR_GROUP5_INPUT21 = 0x1B0Du, /* tr_group[5].input[21] */ - TRIG11_OUT_TR_GROUP6_INPUT21 = 0x1B0Du, /* tr_group[6].input[21] */ - TRIG11_OUT_TR_GROUP7_INPUT21 = 0x1B0Du, /* tr_group[7].input[21] */ - TRIG11_OUT_TR_GROUP8_INPUT21 = 0x1B0Du, /* tr_group[8].input[21] */ - TRIG11_OUT_TR_GROUP0_INPUT22 = 0x1B0Eu, /* tr_group[0].input[22] */ - TRIG11_OUT_TR_GROUP1_INPUT22 = 0x1B0Eu, /* tr_group[1].input[22] */ - TRIG11_OUT_TR_GROUP2_INPUT22 = 0x1B0Eu, /* tr_group[2].input[22] */ - TRIG11_OUT_TR_GROUP3_INPUT22 = 0x1B0Eu, /* tr_group[3].input[22] */ - TRIG11_OUT_TR_GROUP4_INPUT22 = 0x1B0Eu, /* tr_group[4].input[22] */ - TRIG11_OUT_TR_GROUP5_INPUT22 = 0x1B0Eu, /* tr_group[5].input[22] */ - TRIG11_OUT_TR_GROUP6_INPUT22 = 0x1B0Eu, /* tr_group[6].input[22] */ - TRIG11_OUT_TR_GROUP7_INPUT22 = 0x1B0Eu, /* tr_group[7].input[22] */ - TRIG11_OUT_TR_GROUP8_INPUT22 = 0x1B0Eu, /* tr_group[8].input[22] */ - TRIG11_OUT_TR_GROUP0_INPUT23 = 0x1B0Fu, /* tr_group[0].input[23] */ - TRIG11_OUT_TR_GROUP1_INPUT23 = 0x1B0Fu, /* tr_group[1].input[23] */ - TRIG11_OUT_TR_GROUP2_INPUT23 = 0x1B0Fu, /* tr_group[2].input[23] */ - TRIG11_OUT_TR_GROUP3_INPUT23 = 0x1B0Fu, /* tr_group[3].input[23] */ - TRIG11_OUT_TR_GROUP4_INPUT23 = 0x1B0Fu, /* tr_group[4].input[23] */ - TRIG11_OUT_TR_GROUP5_INPUT23 = 0x1B0Fu, /* tr_group[5].input[23] */ - TRIG11_OUT_TR_GROUP6_INPUT23 = 0x1B0Fu, /* tr_group[6].input[23] */ - TRIG11_OUT_TR_GROUP7_INPUT23 = 0x1B0Fu, /* tr_group[7].input[23] */ - TRIG11_OUT_TR_GROUP8_INPUT23 = 0x1B0Fu /* tr_group[8].input[23] */ -} en_trig_output_grp11_t; - -/* Trigger Output Group 12 - Reduces 28 pin input signals to 10 triggers used by all sinks */ -typedef enum -{ - TRIG12_OUT_TR_GROUP2_INPUT24 = 0x1C00u, /* tr_group[2].input[24] */ - TRIG12_OUT_TR_GROUP3_INPUT24 = 0x1C00u, /* tr_group[3].input[24] */ - TRIG12_OUT_TR_GROUP4_INPUT24 = 0x1C00u, /* tr_group[4].input[24] */ - TRIG12_OUT_TR_GROUP5_INPUT24 = 0x1C00u, /* tr_group[5].input[24] */ - TRIG12_OUT_TR_GROUP6_INPUT24 = 0x1C00u, /* tr_group[6].input[24] */ - TRIG12_OUT_TR_GROUP7_INPUT24 = 0x1C00u, /* tr_group[7].input[24] */ - TRIG12_OUT_TR_GROUP8_INPUT24 = 0x1C00u, /* tr_group[8].input[24] */ - TRIG12_OUT_TR_GROUP2_INPUT25 = 0x1C01u, /* tr_group[2].input[25] */ - TRIG12_OUT_TR_GROUP3_INPUT25 = 0x1C01u, /* tr_group[3].input[25] */ - TRIG12_OUT_TR_GROUP4_INPUT25 = 0x1C01u, /* tr_group[4].input[25] */ - TRIG12_OUT_TR_GROUP5_INPUT25 = 0x1C01u, /* tr_group[5].input[25] */ - TRIG12_OUT_TR_GROUP6_INPUT25 = 0x1C01u, /* tr_group[6].input[25] */ - TRIG12_OUT_TR_GROUP7_INPUT25 = 0x1C01u, /* tr_group[7].input[25] */ - TRIG12_OUT_TR_GROUP8_INPUT25 = 0x1C01u, /* tr_group[8].input[25] */ - TRIG12_OUT_TR_GROUP2_INPUT26 = 0x1C02u, /* tr_group[2].input[26] */ - TRIG12_OUT_TR_GROUP3_INPUT26 = 0x1C02u, /* tr_group[3].input[26] */ - TRIG12_OUT_TR_GROUP4_INPUT26 = 0x1C02u, /* tr_group[4].input[26] */ - TRIG12_OUT_TR_GROUP5_INPUT26 = 0x1C02u, /* tr_group[5].input[26] */ - TRIG12_OUT_TR_GROUP6_INPUT26 = 0x1C02u, /* tr_group[6].input[26] */ - TRIG12_OUT_TR_GROUP7_INPUT26 = 0x1C02u, /* tr_group[7].input[26] */ - TRIG12_OUT_TR_GROUP8_INPUT26 = 0x1C02u, /* tr_group[8].input[26] */ - TRIG12_OUT_TR_GROUP2_INPUT27 = 0x1C03u, /* tr_group[2].input[27] */ - TRIG12_OUT_TR_GROUP3_INPUT27 = 0x1C03u, /* tr_group[3].input[27] */ - TRIG12_OUT_TR_GROUP4_INPUT27 = 0x1C03u, /* tr_group[4].input[27] */ - TRIG12_OUT_TR_GROUP5_INPUT27 = 0x1C03u, /* tr_group[5].input[27] */ - TRIG12_OUT_TR_GROUP6_INPUT27 = 0x1C03u, /* tr_group[6].input[27] */ - TRIG12_OUT_TR_GROUP7_INPUT27 = 0x1C03u, /* tr_group[7].input[27] */ - TRIG12_OUT_TR_GROUP8_INPUT27 = 0x1C03u, /* tr_group[8].input[27] */ - TRIG12_OUT_TR_GROUP2_INPUT28 = 0x1C04u, /* tr_group[2].input[28] */ - TRIG12_OUT_TR_GROUP3_INPUT28 = 0x1C04u, /* tr_group[3].input[28] */ - TRIG12_OUT_TR_GROUP4_INPUT28 = 0x1C04u, /* tr_group[4].input[28] */ - TRIG12_OUT_TR_GROUP5_INPUT28 = 0x1C04u, /* tr_group[5].input[28] */ - TRIG12_OUT_TR_GROUP6_INPUT28 = 0x1C04u, /* tr_group[6].input[28] */ - TRIG12_OUT_TR_GROUP7_INPUT28 = 0x1C04u, /* tr_group[7].input[28] */ - TRIG12_OUT_TR_GROUP8_INPUT28 = 0x1C04u, /* tr_group[8].input[28] */ - TRIG12_OUT_TR_GROUP2_INPUT29 = 0x1C05u, /* tr_group[2].input[29] */ - TRIG12_OUT_TR_GROUP3_INPUT29 = 0x1C05u, /* tr_group[3].input[29] */ - TRIG12_OUT_TR_GROUP4_INPUT29 = 0x1C05u, /* tr_group[4].input[29] */ - TRIG12_OUT_TR_GROUP5_INPUT29 = 0x1C05u, /* tr_group[5].input[29] */ - TRIG12_OUT_TR_GROUP6_INPUT29 = 0x1C05u, /* tr_group[6].input[29] */ - TRIG12_OUT_TR_GROUP7_INPUT29 = 0x1C05u, /* tr_group[7].input[29] */ - TRIG12_OUT_TR_GROUP8_INPUT29 = 0x1C05u, /* tr_group[8].input[29] */ - TRIG12_OUT_TR_GROUP2_INPUT30 = 0x1C06u, /* tr_group[2].input[30] */ - TRIG12_OUT_TR_GROUP3_INPUT30 = 0x1C06u, /* tr_group[3].input[30] */ - TRIG12_OUT_TR_GROUP4_INPUT30 = 0x1C06u, /* tr_group[4].input[30] */ - TRIG12_OUT_TR_GROUP5_INPUT30 = 0x1C06u, /* tr_group[5].input[30] */ - TRIG12_OUT_TR_GROUP6_INPUT30 = 0x1C06u, /* tr_group[6].input[30] */ - TRIG12_OUT_TR_GROUP7_INPUT30 = 0x1C06u, /* tr_group[7].input[30] */ - TRIG12_OUT_TR_GROUP8_INPUT30 = 0x1C06u, /* tr_group[8].input[30] */ - TRIG12_OUT_TR_GROUP2_INPUT31 = 0x1C07u, /* tr_group[2].input[31] */ - TRIG12_OUT_TR_GROUP3_INPUT31 = 0x1C07u, /* tr_group[3].input[31] */ - TRIG12_OUT_TR_GROUP4_INPUT31 = 0x1C07u, /* tr_group[4].input[31] */ - TRIG12_OUT_TR_GROUP5_INPUT31 = 0x1C07u, /* tr_group[5].input[31] */ - TRIG12_OUT_TR_GROUP6_INPUT31 = 0x1C07u, /* tr_group[6].input[31] */ - TRIG12_OUT_TR_GROUP7_INPUT31 = 0x1C07u, /* tr_group[7].input[31] */ - TRIG12_OUT_TR_GROUP8_INPUT31 = 0x1C07u, /* tr_group[8].input[31] */ - TRIG12_OUT_TR_GROUP0_INPUT24 = 0x1C08u, /* tr_group[0].input[24] */ - TRIG12_OUT_TR_GROUP1_INPUT24 = 0x1C08u, /* tr_group[1].input[24] */ - TRIG12_OUT_TR_GROUP0_INPUT25 = 0x1C09u, /* tr_group[0].input[25] */ - TRIG12_OUT_TR_GROUP1_INPUT25 = 0x1C09u /* tr_group[1].input[25] */ -} en_trig_output_grp12_t; - -/* Trigger Output Group 13 - Reduces DMA requests to 16+2 outputs used by all sinks */ -typedef enum -{ - TRIG13_OUT_TR_GROUP0_INPUT26 = 0x1D00u, /* tr_group[0].input[26] */ - TRIG13_OUT_TR_GROUP1_INPUT26 = 0x1D00u, /* tr_group[1].input[26] */ - TRIG13_OUT_TR_GROUP0_INPUT27 = 0x1D01u, /* tr_group[0].input[27] */ - TRIG13_OUT_TR_GROUP1_INPUT27 = 0x1D01u, /* tr_group[1].input[27] */ - TRIG13_OUT_TR_GROUP0_INPUT28 = 0x1D02u, /* tr_group[0].input[28] */ - TRIG13_OUT_TR_GROUP1_INPUT28 = 0x1D02u, /* tr_group[1].input[28] */ - TRIG13_OUT_TR_GROUP0_INPUT29 = 0x1D03u, /* tr_group[0].input[29] */ - TRIG13_OUT_TR_GROUP1_INPUT29 = 0x1D03u, /* tr_group[1].input[29] */ - TRIG13_OUT_TR_GROUP0_INPUT30 = 0x1D04u, /* tr_group[0].input[30] */ - TRIG13_OUT_TR_GROUP1_INPUT30 = 0x1D04u, /* tr_group[1].input[30] */ - TRIG13_OUT_TR_GROUP0_INPUT31 = 0x1D05u, /* tr_group[0].input[31] */ - TRIG13_OUT_TR_GROUP1_INPUT31 = 0x1D05u, /* tr_group[1].input[31] */ - TRIG13_OUT_TR_GROUP0_INPUT32 = 0x1D06u, /* tr_group[0].input[32] */ - TRIG13_OUT_TR_GROUP1_INPUT32 = 0x1D06u, /* tr_group[1].input[32] */ - TRIG13_OUT_TR_GROUP0_INPUT33 = 0x1D07u, /* tr_group[0].input[33] */ - TRIG13_OUT_TR_GROUP1_INPUT33 = 0x1D07u, /* tr_group[1].input[33] */ - TRIG13_OUT_TR_GROUP0_INPUT34 = 0x1D08u, /* tr_group[0].input[34] */ - TRIG13_OUT_TR_GROUP1_INPUT34 = 0x1D08u, /* tr_group[1].input[34] */ - TRIG13_OUT_TR_GROUP0_INPUT35 = 0x1D09u, /* tr_group[0].input[35] */ - TRIG13_OUT_TR_GROUP1_INPUT35 = 0x1D09u, /* tr_group[1].input[35] */ - TRIG13_OUT_TR_GROUP0_INPUT36 = 0x1D0Au, /* tr_group[0].input[36] */ - TRIG13_OUT_TR_GROUP1_INPUT36 = 0x1D0Au, /* tr_group[1].input[36] */ - TRIG13_OUT_TR_GROUP0_INPUT37 = 0x1D0Bu, /* tr_group[0].input[37] */ - TRIG13_OUT_TR_GROUP1_INPUT37 = 0x1D0Bu, /* tr_group[1].input[37] */ - TRIG13_OUT_TR_GROUP0_INPUT38 = 0x1D0Cu, /* tr_group[0].input[38] */ - TRIG13_OUT_TR_GROUP1_INPUT38 = 0x1D0Cu, /* tr_group[1].input[38] */ - TRIG13_OUT_TR_GROUP0_INPUT39 = 0x1D0Du, /* tr_group[0].input[39] */ - TRIG13_OUT_TR_GROUP1_INPUT39 = 0x1D0Du, /* tr_group[1].input[39] */ - TRIG13_OUT_TR_GROUP0_INPUT40 = 0x1D0Eu, /* tr_group[0].input[40] */ - TRIG13_OUT_TR_GROUP1_INPUT40 = 0x1D0Eu, /* tr_group[1].input[40] */ - TRIG13_OUT_TR_GROUP0_INPUT41 = 0x1D0Fu, /* tr_group[0].input[41] */ - TRIG13_OUT_TR_GROUP1_INPUT41 = 0x1D0Fu, /* tr_group[1].input[41] */ - TRIG13_OUT_TR_GROUP2_INPUT32 = 0x1D10u, /* tr_group[2].input[32] */ - TRIG13_OUT_TR_GROUP3_INPUT32 = 0x1D10u, /* tr_group[3].input[32] */ - TRIG13_OUT_TR_GROUP4_INPUT32 = 0x1D10u, /* tr_group[4].input[32] */ - TRIG13_OUT_TR_GROUP5_INPUT32 = 0x1D10u, /* tr_group[5].input[32] */ - TRIG13_OUT_TR_GROUP6_INPUT32 = 0x1D10u, /* tr_group[6].input[32] */ - TRIG13_OUT_TR_GROUP7_INPUT32 = 0x1D10u, /* tr_group[7].input[32] */ - TRIG13_OUT_TR_GROUP8_INPUT32 = 0x1D10u, /* tr_group[8].input[32] */ - TRIG13_OUT_TR_GROUP2_INPUT33 = 0x1D11u, /* tr_group[2].input[33] */ - TRIG13_OUT_TR_GROUP3_INPUT33 = 0x1D11u, /* tr_group[3].input[33] */ - TRIG13_OUT_TR_GROUP4_INPUT33 = 0x1D11u, /* tr_group[4].input[33] */ - TRIG13_OUT_TR_GROUP5_INPUT33 = 0x1D11u, /* tr_group[5].input[33] */ - TRIG13_OUT_TR_GROUP6_INPUT33 = 0x1D11u, /* tr_group[6].input[33] */ - TRIG13_OUT_TR_GROUP7_INPUT33 = 0x1D11u, /* tr_group[7].input[33] */ - TRIG13_OUT_TR_GROUP8_INPUT33 = 0x1D11u /* tr_group[8].input[33] */ -} en_trig_output_grp13_t; - -/* Trigger Output Group 14 - Reduces general purpose trigger inputs to 8+8 outputs used by all sinks */ -typedef enum -{ - TRIG14_OUT_TR_GROUP0_INPUT42 = 0x1E00u, /* tr_group[0].input[42] */ - TRIG14_OUT_TR_GROUP1_INPUT42 = 0x1E00u, /* tr_group[1].input[42] */ - TRIG14_OUT_TR_GROUP0_INPUT43 = 0x1E01u, /* tr_group[0].input[43] */ - TRIG14_OUT_TR_GROUP1_INPUT43 = 0x1E01u, /* tr_group[1].input[43] */ - TRIG14_OUT_TR_GROUP0_INPUT44 = 0x1E02u, /* tr_group[0].input[44] */ - TRIG14_OUT_TR_GROUP1_INPUT44 = 0x1E02u, /* tr_group[1].input[44] */ - TRIG14_OUT_TR_GROUP0_INPUT45 = 0x1E03u, /* tr_group[0].input[45] */ - TRIG14_OUT_TR_GROUP1_INPUT45 = 0x1E03u, /* tr_group[1].input[45] */ - TRIG14_OUT_TR_GROUP0_INPUT46 = 0x1E04u, /* tr_group[0].input[46] */ - TRIG14_OUT_TR_GROUP1_INPUT46 = 0x1E04u, /* tr_group[1].input[46] */ - TRIG14_OUT_TR_GROUP0_INPUT47 = 0x1E05u, /* tr_group[0].input[47] */ - TRIG14_OUT_TR_GROUP1_INPUT47 = 0x1E05u, /* tr_group[1].input[47] */ - TRIG14_OUT_TR_GROUP0_INPUT48 = 0x1E06u, /* tr_group[0].input[48] */ - TRIG14_OUT_TR_GROUP1_INPUT48 = 0x1E06u, /* tr_group[1].input[48] */ - TRIG14_OUT_TR_GROUP0_INPUT49 = 0x1E07u, /* tr_group[0].input[49] */ - TRIG14_OUT_TR_GROUP1_INPUT49 = 0x1E07u, /* tr_group[1].input[49] */ - TRIG14_OUT_TR_GROUP2_INPUT34 = 0x1E08u, /* tr_group[2].input[34] */ - TRIG14_OUT_TR_GROUP3_INPUT34 = 0x1E08u, /* tr_group[3].input[34] */ - TRIG14_OUT_TR_GROUP4_INPUT34 = 0x1E08u, /* tr_group[4].input[34] */ - TRIG14_OUT_TR_GROUP5_INPUT34 = 0x1E08u, /* tr_group[5].input[34] */ - TRIG14_OUT_TR_GROUP6_INPUT34 = 0x1E08u, /* tr_group[6].input[34] */ - TRIG14_OUT_TR_GROUP7_INPUT34 = 0x1E08u, /* tr_group[7].input[34] */ - TRIG14_OUT_TR_GROUP8_INPUT34 = 0x1E08u, /* tr_group[8].input[34] */ - TRIG14_OUT_TR_GROUP2_INPUT35 = 0x1E09u, /* tr_group[2].input[35] */ - TRIG14_OUT_TR_GROUP3_INPUT35 = 0x1E09u, /* tr_group[3].input[35] */ - TRIG14_OUT_TR_GROUP4_INPUT35 = 0x1E09u, /* tr_group[4].input[35] */ - TRIG14_OUT_TR_GROUP5_INPUT35 = 0x1E09u, /* tr_group[5].input[35] */ - TRIG14_OUT_TR_GROUP6_INPUT35 = 0x1E09u, /* tr_group[6].input[35] */ - TRIG14_OUT_TR_GROUP7_INPUT35 = 0x1E09u, /* tr_group[7].input[35] */ - TRIG14_OUT_TR_GROUP8_INPUT35 = 0x1E09u, /* tr_group[8].input[35] */ - TRIG14_OUT_TR_GROUP2_INPUT36 = 0x1E0Au, /* tr_group[2].input[36] */ - TRIG14_OUT_TR_GROUP3_INPUT36 = 0x1E0Au, /* tr_group[3].input[36] */ - TRIG14_OUT_TR_GROUP4_INPUT36 = 0x1E0Au, /* tr_group[4].input[36] */ - TRIG14_OUT_TR_GROUP5_INPUT36 = 0x1E0Au, /* tr_group[5].input[36] */ - TRIG14_OUT_TR_GROUP6_INPUT36 = 0x1E0Au, /* tr_group[6].input[36] */ - TRIG14_OUT_TR_GROUP7_INPUT36 = 0x1E0Au, /* tr_group[7].input[36] */ - TRIG14_OUT_TR_GROUP8_INPUT36 = 0x1E0Au, /* tr_group[8].input[36] */ - TRIG14_OUT_TR_GROUP2_INPUT37 = 0x1E0Bu, /* tr_group[2].input[37] */ - TRIG14_OUT_TR_GROUP3_INPUT37 = 0x1E0Bu, /* tr_group[3].input[37] */ - TRIG14_OUT_TR_GROUP4_INPUT37 = 0x1E0Bu, /* tr_group[4].input[37] */ - TRIG14_OUT_TR_GROUP5_INPUT37 = 0x1E0Bu, /* tr_group[5].input[37] */ - TRIG14_OUT_TR_GROUP6_INPUT37 = 0x1E0Bu, /* tr_group[6].input[37] */ - TRIG14_OUT_TR_GROUP7_INPUT37 = 0x1E0Bu, /* tr_group[7].input[37] */ - TRIG14_OUT_TR_GROUP8_INPUT37 = 0x1E0Bu, /* tr_group[8].input[37] */ - TRIG14_OUT_TR_GROUP2_INPUT38 = 0x1E0Cu, /* tr_group[2].input[38] */ - TRIG14_OUT_TR_GROUP3_INPUT38 = 0x1E0Cu, /* tr_group[3].input[38] */ - TRIG14_OUT_TR_GROUP4_INPUT38 = 0x1E0Cu, /* tr_group[4].input[38] */ - TRIG14_OUT_TR_GROUP5_INPUT38 = 0x1E0Cu, /* tr_group[5].input[38] */ - TRIG14_OUT_TR_GROUP6_INPUT38 = 0x1E0Cu, /* tr_group[6].input[38] */ - TRIG14_OUT_TR_GROUP7_INPUT38 = 0x1E0Cu, /* tr_group[7].input[38] */ - TRIG14_OUT_TR_GROUP8_INPUT38 = 0x1E0Cu, /* tr_group[8].input[38] */ - TRIG14_OUT_TR_GROUP2_INPUT39 = 0x1E0Du, /* tr_group[2].input[39] */ - TRIG14_OUT_TR_GROUP3_INPUT39 = 0x1E0Du, /* tr_group[3].input[39] */ - TRIG14_OUT_TR_GROUP4_INPUT39 = 0x1E0Du, /* tr_group[4].input[39] */ - TRIG14_OUT_TR_GROUP5_INPUT39 = 0x1E0Du, /* tr_group[5].input[39] */ - TRIG14_OUT_TR_GROUP6_INPUT39 = 0x1E0Du, /* tr_group[6].input[39] */ - TRIG14_OUT_TR_GROUP7_INPUT39 = 0x1E0Du, /* tr_group[7].input[39] */ - TRIG14_OUT_TR_GROUP8_INPUT39 = 0x1E0Du, /* tr_group[8].input[39] */ - TRIG14_OUT_TR_GROUP2_INPUT40 = 0x1E0Eu, /* tr_group[2].input[40] */ - TRIG14_OUT_TR_GROUP3_INPUT40 = 0x1E0Eu, /* tr_group[3].input[40] */ - TRIG14_OUT_TR_GROUP4_INPUT40 = 0x1E0Eu, /* tr_group[4].input[40] */ - TRIG14_OUT_TR_GROUP5_INPUT40 = 0x1E0Eu, /* tr_group[5].input[40] */ - TRIG14_OUT_TR_GROUP6_INPUT40 = 0x1E0Eu, /* tr_group[6].input[40] */ - TRIG14_OUT_TR_GROUP7_INPUT40 = 0x1E0Eu, /* tr_group[7].input[40] */ - TRIG14_OUT_TR_GROUP8_INPUT40 = 0x1E0Eu, /* tr_group[8].input[40] */ - TRIG14_OUT_TR_GROUP2_INPUT41 = 0x1E0Fu, /* tr_group[2].input[41] */ - TRIG14_OUT_TR_GROUP3_INPUT41 = 0x1E0Fu, /* tr_group[3].input[41] */ - TRIG14_OUT_TR_GROUP4_INPUT41 = 0x1E0Fu, /* tr_group[4].input[41] */ - TRIG14_OUT_TR_GROUP5_INPUT41 = 0x1E0Fu, /* tr_group[5].input[41] */ - TRIG14_OUT_TR_GROUP6_INPUT41 = 0x1E0Fu, /* tr_group[6].input[41] */ - TRIG14_OUT_TR_GROUP7_INPUT41 = 0x1E0Fu, /* tr_group[7].input[41] */ - TRIG14_OUT_TR_GROUP8_INPUT41 = 0x1E0Fu /* tr_group[8].input[41] */ -} en_trig_output_grp14_t; - -/* Level or edge detection setting for a trigger mux */ -typedef enum -{ - /* The trigger is a simple level output */ - TRIGGER_TYPE_LEVEL = 0u, - /* The trigger is synchronized to the consumer blocks clock - and a two cycle pulse is generated on this clock */ - TRIGGER_TYPE_EDGE = 1u -} en_trig_type_t; - -/* Trigger Type Defines */ -/* TCPWM Trigger Types */ -#define TRIGGER_TYPE_TCPWM_LINE TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_TCPWM_LINE_COMPL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_TCPWM_TR_IN__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_TCPWM_TR_IN__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_TCPWM_TR_OVERFLOW TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_TCPWM_TR_COMPARE_MATCH TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_TCPWM_TR_UNDERFLOW TRIGGER_TYPE_EDGE -/* CSD Trigger Types */ -#define TRIGGER_TYPE_CSD_DSI_SAMPLE_OUT TRIGGER_TYPE_EDGE -/* SCB Trigger Types */ -#define TRIGGER_TYPE_SCB_TR_TX_REQ TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_SCB_TR_RX_REQ TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_SCB_TR_I2C_SCL_FILTERED TRIGGER_TYPE_LEVEL -/* PERI Trigger Types */ -#define TRIGGER_TYPE_PERI_TR_IO_INPUT__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_PERI_TR_IO_INPUT__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_PERI_TR_IO_OUTPUT__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_PERI_TR_IO_OUTPUT__EDGE TRIGGER_TYPE_EDGE -/* CPUSS Trigger Types */ -#define TRIGGER_TYPE_CPUSS_DW0_TR_IN__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_CPUSS_DW0_TR_IN__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_CPUSS_DW1_TR_IN__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_CPUSS_DW1_TR_IN__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_CPUSS_CTI_TR_IN TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_CPUSS_DW0_TR_OUT TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_CPUSS_DW1_TR_OUT TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_CPUSS_CTI_TR_OUT TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_CPUSS_TR_FAULT TRIGGER_TYPE_EDGE -/* AUDIOSS Trigger Types */ -#define TRIGGER_TYPE_AUDIOSS_TR_PDM_RX_REQ TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_AUDIOSS_TR_I2S_TX_REQ TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_AUDIOSS_TR_I2S_RX_REQ TRIGGER_TYPE_LEVEL -/* LPCOMP Trigger Types */ -#define TRIGGER_TYPE_LPCOMP_DSI_COMP0 TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_LPCOMP_DSI_COMP1 TRIGGER_TYPE_LEVEL -/* PASS Trigger Types */ -#define TRIGGER_TYPE_PASS_DSI_CTB_CMP0 TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_PASS_DSI_CTB_CMP1 TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_PASS_TR_SAR_IN TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_PASS_TR_SAR_OUT TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_PASS_TR_CTDAC_EMPTY TRIGGER_TYPE_EDGE -/* SMIF Trigger Types */ -#define TRIGGER_TYPE_SMIF_TR_TX_REQ TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_SMIF_TR_RX_REQ TRIGGER_TYPE_LEVEL -/* USB Trigger Types */ -#define TRIGGER_TYPE_USB_DMA_BURSTEND TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_USB_DMA_REQ TRIGGER_TYPE_EDGE -/* UDB Trigger Types */ -#define TRIGGER_TYPE_UDB_TR_IN__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_UDB_TR_IN__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_UDB_TR_DW_ACK__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_UDB_TR_DW_ACK__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_UDB_TR_UDB__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_UDB_TR_UDB__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_UDB_DSI_OUT_TR__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_UDB_DSI_OUT_TR__EDGE TRIGGER_TYPE_EDGE -/* PROFILE Trigger Types */ -#define TRIGGER_TYPE_PROFILE_TR_START TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_PROFILE_TR_STOP TRIGGER_TYPE_EDGE -/* TR_GROUP Trigger Types */ -#define TRIGGER_TYPE_TR_GROUP_OUTPUT__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_TR_GROUP_OUTPUT__EDGE TRIGGER_TYPE_EDGE -#define TRIGGER_TYPE_TR_GROUP_INPUT__LEVEL TRIGGER_TYPE_LEVEL -#define TRIGGER_TYPE_TR_GROUP_INPUT__EDGE TRIGGER_TYPE_EDGE - -/* Monitor Signal Defines */ -typedef enum -{ - PROFILE_ONE = 0, - CPUSS_MONITOR_CM0 = 1, - CPUSS_MONITOR_CM4 = 2, - CPUSS_MONITOR_FLASH = 3, - CPUSS_MONITOR_DW0_AHB = 4, - CPUSS_MONITOR_DW1_AHB = 5, - CPUSS_MONITOR_CRYPTO = 6, - USB_MONITOR_AHB = 7, - SCB0_MONITOR_AHB = 8, - SCB1_MONITOR_AHB = 9, - SCB2_MONITOR_AHB = 10, - SCB3_MONITOR_AHB = 11, - SCB4_MONITOR_AHB = 12, - SCB5_MONITOR_AHB = 13, - SCB6_MONITOR_AHB = 14, - SCB7_MONITOR_AHB = 15, - SCB8_MONITOR_AHB = 16, - UDB_MONITOR_UDB0 = 17, - UDB_MONITOR_UDB1 = 18, - UDB_MONITOR_UDB2 = 19, - UDB_MONITOR_UDB3 = 20, - SMIF_MONITOR_SMIF_SPI_SELECT0 = 21, - SMIF_MONITOR_SMIF_SPI_SELECT1 = 22, - SMIF_MONITOR_SMIF_SPI_SELECT2 = 23, - SMIF_MONITOR_SMIF_SPI_SELECT3 = 24, - SMIF_MONITOR_SMIF_SPI_SELECT_ANY = 25, - BLESS_EXT_LNA_RX_CTL_OUT = 26, - BLESS_EXT_PA_TX_CTL_OUT = 27 -} en_ep_mon_sel_t; - -/* Total count of Energy Profiler monitor signal connections */ -#define EP_MONITOR_COUNT 28u - -/* Bus masters */ -typedef enum -{ - CPUSS_MS_ID_CM0 = 0, - CPUSS_MS_ID_CRYPTO = 1, - CPUSS_MS_ID_DW0 = 2, - CPUSS_MS_ID_DW1 = 3, - CPUSS_MS_ID_CM4 = 14, - CPUSS_MS_ID_TC = 15 -} en_prot_master_t; - -/* Parameter Defines */ -/* Number of regulator modules instantiated within SRSS */ -#define SRSS_NUM_ACTREG_PWRMOD 2u -/* Number of shorting switches between vccd and vccact */ -#define SRSS_NUM_ACTIVE_SWITCH 3u -/* ULP linear regulator system is present */ -#define SRSS_ULPLINREG_PRESENT 1u -/* HT linear regulator system is present */ -#define SRSS_HTLINREG_PRESENT 0u -/* SIMO buck core regulator is present. Only compatible with ULP linear - regulator system (ULPLINREG_PRESENT==1). */ -#define SRSS_SIMOBUCK_PRESENT 1u -/* Precision ILO (PILO) is present */ -#define SRSS_PILO_PRESENT 1u -/* External Crystal Oscillator is present (high frequency) */ -#define SRSS_ECO_PRESENT 1u -/* System Buck-Boost is present */ -#define SRSS_SYSBB_PRESENT 0u -/* Number of clock paths. Must be > 0 */ -#define SRSS_NUM_CLKPATH 3u -/* Number of PLLs present. Must be <= NUM_CLKPATH */ -#define SRSS_NUM_PLL 1u -/* Number of HFCLK roots present. Must be > 0 */ -#define SRSS_NUM_HFROOT 5u -/* Number of PWR_HIB_DATA registers */ -#define SRSS_NUM_HIBDATA 1u -/* Backup domain is present */ -#define SRSS_BACKUP_PRESENT 1u -/* Mask of HFCLK root clock supervisors (CSV). For each clock root i, bit[i] of - mask indicates presence of a CSV. */ -#define SRSS_MASK_HFCSV 1u -/* Clock supervisor is present on WCO. Must be 0 if BACKUP_PRESENT==0. */ -#define SRSS_WCOCSV_PRESENT 1u -/* Number of software watchdog timers. */ -#define SRSS_NUM_MCWDT 2u -/* Number of DSI inputs into clock muxes. This is used for logic optimization. */ -#define SRSS_NUM_DSI 2u -/* Alternate high-frequency clock is present. This is used for logic - optimization. */ -#define SRSS_ALTHF_PRESENT 1u -/* Alternate low-frequency clock is present. This is used for logic - optimization. */ -#define SRSS_ALTLF_PRESENT 0u -/* Backup memory is present (only used when BACKUP_PRESENT==1) */ -#define SRSS_BACKUP_BMEM_PRESENT 0u -/* Number of Backup registers to include (each is 32b). Only used when - BACKUP_PRESENT==1. */ -#define SRSS_BACKUP_NUM_BREG 8u -/* Number of AMUX splitter cells */ -#define IOSS_HSIOM_AMUX_SPLIT_NR 8u -/* Number of HSIOM ports in device (same as GPIO.GPIO_PRT_NR) */ -#define IOSS_HSIOM_HSIOM_PORT_NR 15u -/* Number of GPIO ports in range 0..31 */ -#define IOSS_GPIO_GPIO_PORT_NR_0_31 15u -/* Number of GPIO ports in range 32..63 */ -#define IOSS_GPIO_GPIO_PORT_NR_32_63 0u -/* Number of GPIO ports in range 64..95 */ -#define IOSS_GPIO_GPIO_PORT_NR_64_95 0u -/* Number of GPIO ports in range 96..127 */ -#define IOSS_GPIO_GPIO_PORT_NR_96_127 0u -/* Number of ports in device */ -#define IOSS_GPIO_GPIO_PORT_NR 15u -/* Mask of SMARTIO instances presence */ -#define IOSS_SMARTIO_SMARTIO_MASK 768u -/* The number of protection contexts ([2, 16]). */ -#define PERI_PC_NR 8u -/* Master interface presence mask (4 bits) */ -#define PERI_MS_PRESENT 15u -/* Master interface PPU combinatorial (1) or registerd (0) */ -#define PERI_MS_PPU_COMBINATORIAL 1u -/* The number of programmable PPU structures for PERI (all peripherals) */ -#define PERI_MS_PPU_PROG_STRUCT_NR 16u -/* Number of programmable clocks (outputs) */ -#define PERI_CLOCK_NR 59u -/* Number of 8.0 dividers */ -#define PERI_DIV_8_NR 8u -/* Number of 16.0 dividers */ -#define PERI_DIV_16_NR 16u -/* Number of 16.5 (fractional) dividers */ -#define PERI_DIV_16_5_NR 4u -/* Number of 24.5 (fractional) dividers */ -#define PERI_DIV_24_5_NR 1u -/* Divider number width: max(1,roundup(log2(max(DIV_*_NR))) */ -#define PERI_DIV_ADDR_WIDTH 4u -/* Trigger module present (0=No, 1=Yes) */ -#define PERI_TR 1u -/* Number of trigger groups */ -#define PERI_TR_GROUP_NR 15u -/* The number of protection contexts minus 1 ([1, 15]). */ -#define PERI_PPU_FIXED_STRUCT_PC_NR_MINUS1 7u -/* The number of protection contexts minus 1 ([1, 15]). */ -#define PERI_PPU_PROG_STRUCT_PC_NR_MINUS1 7u -/* UDB present or not ('0': no, '1': yes) */ -#define CPUSS_UDB_PRESENT 1u -/* System RAM 0 size in kilobytes */ -#define CPUSS_SRAM0_SIZE 288u -/* Number of macros used to implement System RAM 0. Example: 8 if 256 KB System - SRAM0 is implemented with 8 32KB macros. */ -#define CPUSS_RAMC0_MACRO_NR 9u -/* System RAM 1 present or not (0=No, 1=Yes) */ -#define CPUSS_RAMC1_PRESENT 0u -/* System RAM 1 size in kilobytes */ -#define CPUSS_SRAM1_SIZE 32u -/* Number of macros used to implement System RAM 1. Example: 8 if 256 KB System - RAM 1 is implemented with 8 32KB macros. */ -#define CPUSS_RAMC1_MACRO_NR 1u -/* System RAM 2 present or not (0=No, 1=Yes) */ -#define CPUSS_RAMC2_PRESENT 0u -/* System RAM 2 size in kilobytes */ -#define CPUSS_SRAM2_SIZE 256u -/* Number of macros used to implement System RAM 2. Example: 8 if 256 KB System - RAM 2 is implemented with 8 32KB macros. */ -#define CPUSS_RAMC2_MACRO_NR 16u -/* System ROM size in KB */ -#define CPUSS_ROM_SIZE 128u -/* Flash main region size in KB */ -#define CPUSS_FLASH_SIZE 1024u -/* Flash work region size in KB (EEPROM emulation, data) */ -#define CPUSS_WFLASH_SIZE 32u -/* Flash supervisory region size in KB */ -#define CPUSS_SFLASH_SIZE 32u -/* Number of external slaves directly connected to slow AHB-Lite - infrastructure. Maximum nubmer of slave supported is 4. Width of this - parameter is 4-bits. 1-bit mask for each slave indicating present or not. - Example: 4'b0011 - slave 0 and slave 1 are present. Note: The SLOW_SLx_ADDR - and SLOW_SLx_MASK parameters (for the slaves present) should be derived from - the Memory Map. */ -#define CPUSS_SLOW_SL_PRESENT 1u -/* Number of external slaves directly connected to fast AHB-Lite - infrastructure. Maximum nubmer of slave supported is 4. Width of this - parameter is 4-bits. 1-bit mask for each slave indicating present or not. - Example: 4'b0011 - slave 0 and slave 1 are present. Note: The FAST_SLx_ADDR - and FAST_SLx_MASK parameters (for the slaves present) should be derived from - the Memory Map. */ -#define CPUSS_FAST_SL_PRESENT 1u -/* Number of external masters driving the slow AHB-Lite infrastructure. Maximum - number of masters supported is 2. Width of this parameter is 2-bits. 1-bit - mask for each master indicating present or not. Example: 2'b01 - master 0 is - present. */ -#define CPUSS_SLOW_MS_PRESENT 0u -/* Number of LF clock (which is connected to clk_lf input of CPUSS) cycles to - make 10ms time period. Example: =327 (or 24'000147) for 32.678 KHz LF clock - from SRSS. */ -#define CPUSS_LF_10MS_TICKS 16777215u -/* Number of total interrupt request inputs to CPUSS */ -#define CPUSS_IRQ_NR 139u -/* Number of DeepSleep wakeup interrupt inputs to CPUSS */ -#define CPUSS_DPSLP_IRQ_NR 33u -/* Number of DeepSleep wakeup interrupt inputs to CM0+ (product configuration) */ -#define CPUSS_CM0_DPSLP_IRQ_NR 8u -/* Width of the CM4 interrupt priority bits. Legal range [3,8] Example: 3 = 8 - levels of priority 8 = 256 levels of priority */ -#define CPUSS_CM4_LVL_WIDTH 3u -/* CM4 Floating point unit present or not (0=No, 1=Yes) */ -#define CPUSS_CM4_FPU_PRESENT 1u -/* Debug level. Legal range [0,3] */ -#define CPUSS_DEBUG_LVL 3u -/* Trace level. Legal range [0,2] Note: CM4 HTM is not supported. Hence vaule 3 - for trace level is not supported in CPUSS. */ -#define CPUSS_TRACE_LVL 2u -/* Embedded Trace Buffer present or not (0=No, 1=Yes) */ -#define CPUSS_ETB_PRESENT 0u -/* CM0+ MTB SRAM buffer size in kilobytes. Legal vaules 4, 8 or 16 */ -#define CPUSS_MTB_SRAM_SIZE 4u -/* CM4 ETB SRAM buffer size in kilobytes. Legal vaules 4, 8 or 16 */ -#define CPUSS_ETB_SRAM_SIZE 16u -/* PTM interface present (0=No, 1=Yes) */ -#define CPUSS_PTM_PRESENT 1u -/* Width of the PTM interface in bits ([2,32]) */ -#define CPUSS_PTM_WIDTH 8u -/* Width of the TPIU interface in bits ([1,32]) */ -#define CPUSS_TPIU_WIDTH 4u -/* CoreSight Part Identification Number */ -#define CPUSS_JEPID 52u -/* CoreSight Part Identification Number */ -#define CPUSS_JEPCONTINUATION 0u -/* CoreSight Part Identification Number */ -#define CPUSS_FAMILYID 256u -/* Cryptography IP present or not (0=No, 1=Yes) */ -#define CPUSS_CRYPTO_PRESENT 1u -/* DataWire 0 present or not (0=No, 1=Yes) */ -#define CPUSS_DW0_PRESENT 1u -/* Number of DataWire 0 channels (8, 16 or 32) */ -#define CPUSS_DW0_CH_NR 16u -/* DataWire 1 present or not (0=No, 1=Yes) */ -#define CPUSS_DW1_PRESENT 1u -/* Number of DataWire 1 channels (8, 16 or 32) */ -#define CPUSS_DW1_CH_NR 16u -/* AES cipher support (0 = no support, 1 = support */ -#define CPUSS_CRYPTO_AES 1u -/* (Tripple) DES cipher support (0 = no support, 1 = support */ -#define CPUSS_CRYPTO_DES 1u -/* Pseudo random number generation support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_PR 1u -/* SHA support included */ -#define CPUSS_CRYPTO_SHA 1u -/* SHA1 hash support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_SHA1 1u -/* SHA256 hash support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_SHA256 1u -/* SHA512 hash support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_SHA512 1u -/* Cyclic Redundancy Check support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_CRC 1u -/* Vector unit support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_VU 1u -/* True random number generation support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_TR 1u -/* String support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_STR 1u -/* AHB-Lite master interface support (0 = no support, 1 = support) */ -#define CPUSS_CRYPTO_MASTER_IF 1u -/* Number of 32-bit words in the IP internal memory buffer (from the set [64, - 128, 256, 512, 1024, 2048, 4096], to allow for a 256 B, 512 B, 1 kB, 2 kB, 4 - kB, 8 kB and 16 kB memory buffer) */ -#define CPUSS_CRYPTO_BUFF_SIZE 1024u -/* Number of fault structures. Legal range [1, 4] */ -#define CPUSS_FAULT_FAULT_NR 2u -/* Number of IPC structures. Legal range [1, 16] */ -#define CPUSS_IPC_IPC_NR 8u -/* Number of IPC interrupt structures. Legal range [1, 16] */ -#define CPUSS_IPC_IPC_IRQ_NR 8u -/* Master 0 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS0_PC_NR_MINUS1 7u -/* Master 1 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS1_PC_NR_MINUS1 7u -/* Master 2 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS2_PC_NR_MINUS1 0u -/* Master 3 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS3_PC_NR_MINUS1 0u -/* Master 4 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS4_PC_NR_MINUS1 0u -/* Master 5 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS5_PC_NR_MINUS1 0u -/* Master 6 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS6_PC_NR_MINUS1 0u -/* Master 7 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS7_PC_NR_MINUS1 0u -/* Master 8 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS8_PC_NR_MINUS1 0u -/* Master 9 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS9_PC_NR_MINUS1 0u -/* Master 10 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS10_PC_NR_MINUS1 0u -/* Master 11 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS11_PC_NR_MINUS1 0u -/* Master 12 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS12_PC_NR_MINUS1 0u -/* Master 13 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS13_PC_NR_MINUS1 0u -/* Master 14 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS14_PC_NR_MINUS1 7u -/* Master 15 protect contexts minus one */ -#define CPUSS_PROT_SMPU_MS15_PC_NR_MINUS1 7u -/* Number of SMPU protection structures */ -#define CPUSS_PROT_SMPU_STRUCT_NR 16u -/* Number of protection contexts supported minus 1. Legal range [1,16] */ -#define CPUSS_SMPU_STRUCT_PC_NR_MINUS1 7u -/* Number of DataWire controllers present (max 2) */ -#define CPUSS_DW_NR 2u -/* Number of channels in each DataWire controller (must be the same for now) */ -#define CPUSS_DW_CH_NR 16u -/* Page size in # of 32-bit words (1: 4 bytes, 2: 8 bytes, ... */ -#define CPUSS_FLASHC_PA_SIZE 128u -/* Number of profiling counters. Legal range [1, 32] */ -#define PROFILE_PRFL_CNT_NR 8u -/* Number of monitor event signals. Legal range [1, 128] */ -#define PROFILE_PRFL_MONITOR_NR 128u -/* Number of UDB Interrupts */ -#define UDB_NUMINT 16u -/* Number of triggers */ -#define UDB_NUMTR 16u -/* Number of UDB array rows (must be multiple of 2) */ -#define UDB_NUMROW 2u -/* Number of UDB array columns */ -#define UDB_NUMCOL 6u -/* DSI on bottom (1) or on bottom and top (2) of UDB array */ -#define UDB_DSISIDES 2u -/* Number of UDBs = NUMROW * NUMCOL */ -#define UDB_NUMUDB 12u -/* Number of UDB pairs = NUMUDB / 2 */ -#define UDB_NUMUDBPAIR 6u -/* Number of DSIs = NUMCOL * DSISIDES */ -#define UDB_NUMDSI 12u -/* Number of quad clocks */ -#define UDB_NUMQCLK 3u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB0_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB0_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB0_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB0_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB0_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB0_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB0_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB0_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB0_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB0_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB0_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB0_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB0_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB0_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB0_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB0_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB0_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB0_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB0_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB0_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB0_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB0_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB0_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB1_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB1_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB1_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB1_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB1_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB1_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB1_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB1_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB1_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB1_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB1_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB1_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB1_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB1_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB1_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB1_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB1_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB1_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB1_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB1_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB1_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB1_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB1_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB2_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB2_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB2_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB2_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB2_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB2_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB2_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB2_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB2_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB2_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB2_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB2_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB2_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB2_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB2_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB2_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB2_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB2_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB2_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB2_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB2_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB2_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB2_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB3_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB3_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB3_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB3_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB3_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB3_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB3_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB3_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB3_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB3_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB3_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB3_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB3_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB3_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB3_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB3_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB3_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB3_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB3_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB3_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB3_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB3_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB3_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB4_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB4_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB4_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB4_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB4_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB4_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB4_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB4_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB4_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB4_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB4_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB4_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB4_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB4_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB4_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB4_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB4_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB4_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB4_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB4_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB4_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB4_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB4_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB5_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB5_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB5_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB5_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB5_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB5_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB5_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB5_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB5_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB5_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB5_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB5_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB5_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB5_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB5_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB5_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB5_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB5_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB5_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB5_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB5_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB5_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB5_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB6_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB6_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB6_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB6_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB6_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB6_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB6_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB6_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB6_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB6_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB6_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB6_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB6_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB6_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB6_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB6_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB6_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB6_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB6_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB6_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB6_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB6_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB6_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB7_DEEPSLEEP 0u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB7_EC 0u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB7_I2C_M 1u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB7_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB7_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB7_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB7_I2C_EC 0u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB7_I2C_M_S 1u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB7_I2C_S_EC 0u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB7_SPI_M 1u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB7_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB7_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB7_SPI_EC 0u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB7_SPI_S_EC 0u -/* UART support? ('0': no, '1': yes) */ -#define SCB7_UART 1u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB7_UART_FLOW 1u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB7_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB7_CMD_RESP 0u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB7_EZ 0u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB7_EZ_CMD_RESP 0u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB7_I2C_S_EZ 0u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB7_SPI_S_EZ 0u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB7_I2C_FAST_PLUS 1u -/* DeepSleep support ('0':no, '1': yes) */ -#define SCB8_DEEPSLEEP 1u -/* Externally clocked support? ('0': no, '1': yes) */ -#define SCB8_EC 1u -/* I2C master support? ('0': no, '1': yes) */ -#define SCB8_I2C_M 0u -/* I2C slave support? ('0': no, '1': yes) */ -#define SCB8_I2C_S 1u -/* I2C support? (I2C_M | I2C_S) */ -#define SCB8_I2C 1u -/* I2C glitch filters present? ('0': no, '1': yes) */ -#define SCB8_GLITCH 1u -/* I2C externally clocked support? ('0': no, '1': yes) */ -#define SCB8_I2C_EC 1u -/* I2C master and slave support? (I2C_M & I2C_S) */ -#define SCB8_I2C_M_S 0u -/* I2C slave with EC? (I2C_S & I2C_EC) */ -#define SCB8_I2C_S_EC 1u -/* SPI master support? ('0': no, '1': yes) */ -#define SCB8_SPI_M 0u -/* SPI slave support? ('0': no, '1': yes) */ -#define SCB8_SPI_S 1u -/* SPI support? (SPI_M | SPI_S) */ -#define SCB8_SPI 1u -/* SPI externally clocked support? ('0': no, '1': yes) */ -#define SCB8_SPI_EC 1u -/* SPI slave with EC? (SPI_S & SPI_EC) */ -#define SCB8_SPI_S_EC 1u -/* UART support? ('0': no, '1': yes) */ -#define SCB8_UART 0u -/* UART flow control support? ('0': no, '1': yes) */ -#define SCB8_UART_FLOW 0u -/* Number of EZ memory Bytes ([32, 256, 512]). This memory is used in EZ mode, - CMD_RESP mode and FIFO mode. Note that in EZ mode, if EZ_DATA_NR is 512, only - 256 B are used. This is because the EZ mode uses 8-bit addresses. */ -#define SCB8_EZ_DATA_NR 256u -/* Command/response mode support? ('0': no, '1': yes) */ -#define SCB8_CMD_RESP 1u -/* EZ mode support? ('0': no, '1': yes) */ -#define SCB8_EZ 1u -/* Command/response mode or EZ mode support? (CMD_RESP | EZ) */ -#define SCB8_EZ_CMD_RESP 1u -/* I2C slave with EZ mode (I2C_S & EZ) */ -#define SCB8_I2C_S_EZ 1u -/* SPI slave with EZ mode (SPI_S & EZ) */ -#define SCB8_SPI_S_EZ 1u -/* Support I2C FM+/1Mbps speed ('0': no, '1': yes) */ -#define SCB8_I2C_FAST_PLUS 1u -/* Number of counters per IP (1..8) */ -#define TCPWM0_CNT_NR 8u -/* Counter width (in number of bits) */ -#define TCPWM0_CNT_CNT_WIDTH 32u -/* Number of counters per IP (1..8) */ -#define TCPWM1_CNT_NR 24u -/* Counter width (in number of bits) */ -#define TCPWM1_CNT_CNT_WIDTH 16u -/* Max number of LCD commons supported */ -#define LCD_COM_NR 8u -/* Max number of LCD pins (total) supported */ -#define LCD_PIN_NR 62u -/* Number of ports supoprting up to 4 COMs */ -#define LCD_NUMPORTS 8u -/* Number of ports supporting up to 8 COMs */ -#define LCD_NUMPORTS8 8u -/* Number of ports supporting up to 16 COMs */ -#define LCD_NUMPORTS16 0u -/* Number of IREF outputs from AREF */ -#define PASS_NR_IREFS 4u -/* Number of CTBs in the Subsystem */ -#define PASS_NR_CTBS 1u -/* Number of CTDACs in the Subsystem */ -#define PASS_NR_CTDACS 1u -/* CTB0 Exists */ -#define PASS_CTB0_EXISTS 1u -/* CTB1 Exists */ -#define PASS_CTB1_EXISTS 0u -/* CTB2 Exists */ -#define PASS_CTB2_EXISTS 0u -/* CTB3 Exists */ -#define PASS_CTB3_EXISTS 0u -/* CTDAC0 Exists */ -#define PASS_CTDAC0_EXISTS 1u -/* CTDAC1 Exists */ -#define PASS_CTDAC1_EXISTS 0u -/* CTDAC2 Exists */ -#define PASS_CTDAC2_EXISTS 0u -/* CTDAC3 Exists */ -#define PASS_CTDAC3_EXISTS 0u -/* Number of SAR channels */ -#define PASS_SAR_SAR_CHANNELS 16u -/* Averaging logic present in SAR */ -#define PASS_SAR_SAR_AVERAGE 1u -/* Range detect logic present in SAR */ -#define PASS_SAR_SAR_RANGEDET 1u -/* Support for UAB sampling */ -#define PASS_SAR_SAR_UAB 0u -#define PASS_CTBM_CTDAC_PRESENT 1u -/* Number of AHB-Lite "hmaster[]" bits ([1, 8]) */ -#define SMIF_MASTER_WIDTH 8u -/* Base address of the SMIF XIP memory region. This address must be a multiple - of the SMIF XIP memory capacity. This address must be a multiple of 64 KB. - This address must be in the [0x0000:0000, 0x1fff:ffff] memory region. The XIP - memory region should NOT overlap with other memory regions. */ -#define SMIF_SMIF_XIP_ADDR 402653184u -/* Capacity of the SMIF XIP memory region. The more significant bits of this - parameter must be '1' and the lesser significant bits of this paramter must - be '0'. E.g., 0xfff0:0000 specifies a 1 MB memory region. Legal values are - {0xffff:0000, 0xfffe:0000, 0xfffc:0000, 0xfff8:0000, 0xfff0:0000, - 0xffe0:0000, ..., 0xe000:0000}. */ -#define SMIF_SMIF_XIP_MASK 4160749568u -/* Cryptography (AES) support ('0' = no support, '1' = support) */ -#define SMIF_CRYPTO 1u -/* Number of external devices supported ([1,4]) */ -#define SMIF_DEVICE_NR 4u -/* External device write support. This is a 4-bit field. Each external device - has a dedicated bit. E.g., if bit 2 is '1', external device 2 has write - support. */ -#define SMIF_DEVICE_WR_EN 15u -/* AHB bus Master Width */ -#define BLE_BLESS_MASTER_WIDTH 8u -/* I2S capable? (0=No,1=Yes) */ -#define AUDIOSS_I2S 1u -/* PDM capable? (0=No,1=Yes) */ -#define AUDIOSS_PDM 1u - -#endif /* _PSOC6BLE_CONFIG_H_ */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/flash/cy_flash.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/flash/cy_flash.c deleted file mode 100644 index 3dc80147a8..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/flash/cy_flash.c +++ /dev/null @@ -1,886 +0,0 @@ -/***************************************************************************//** -* \file cy_flash.c -* \version 2.0 -* -* \brief -* Provides the public functions for the API for the PSoC 6 Flash Driver. -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_flash.h" - - -/** \cond INTERNAL */ -/** Slow control register */ -#define CY_FLASH_TST_DDFT_SLOW_CTL_REG (*(reg32 *) 0x40260108U) -/** Slow control register */ -#define CY_FLASH_TST_DDFT_FAST_CTL_REG (*(reg32 *) 0x40260104U) -/** Slow output register */ -#define CY_FLASH_CLK_OUTPUT_SLOW_REG (*(reg32 *) 0x40260518U) -/** Slow clock calibration register */ -#define CY_FLASH_CLK_CAL_CNT1_REG (*(reg32 *) 0x4026051CU) -/** Define to set the IMO to perform a delay after the flash operation started */ -#define CY_FLASH_TST_DDFT_SLOW_CTL_MASK (0x40001F1EU) -/** Slow output register */ -#define CY_FLASH_CLK_OUTPUT_SLOW_MASK (0x06U) -/** Define to indicate that clock is finished counting */ -#define CY_FLASH_CLK_CAL_CNT1_DONE ((uint32_t) ((uint32_t) 1U << CY_FLASH_CLK_CAL_CNT1_DONE_POS)) -/** Define to indicate that clock is finished counting */ -#define CY_FLASH_CLK_CAL_CNT1_DONE_POS (31U) -/* Calculates the time in microseconds to wait for the number of the CM0P ticks */ -#define CY_FLASH_DEL_CORRECTIVE(ticks) ((((uint32)Cy_SysClk_ClkPeriGetDivider() + 1UL) * (Cy_SysClk_ClkSlowGetDivider() + 1UL) * (ticks) * 1000UL)\ - / ((uint32_t)cy_Hfclk0FreqHz / 1000UL)) -/* Number of the CM0P ticks for StartWrite function delay corrective time */ -#define CY_FLASH_START_WRITE_DEL_TICKS (19000UL) -/* Number of the CM0P ticks for StartProgram function delay corrective time */ -#define CY_FLASH_START_PROGRAM_DEL_TICKS (5250UL) -/* Number of the CM0P ticks for StartErase function delay corrective time */ -#define CY_FLASH_START_ERASE_DEL_TICKS (8500UL) -/* Delay time for StartWrite function in us */ -#define CY_FLASH_START_WRITE_DEL_TIME (9800UL) -/* Delay time for StartProgram function in us */ -#define CY_FLASH_START_PROGRAM_DEL_TIME (120UL) -/* Delay time for StartErase function in us */ -#define CY_FLASH_START_ERASE_DEL_TIME (1000UL) -/** Delay time for Start Write function in us with corrective time */ -#define CY_FLASH_START_WRITE_DELAY (uint32_t)(CY_FLASH_START_WRITE_DEL_TIME +\ - CY_FLASH_DEL_CORRECTIVE(CY_FLASH_START_WRITE_DEL_TICKS)) -/** Delay time for Start Program function in us with corrective time */ -#define CY_FLASH_START_PROGRAM_DELAY (uint32_t)(CY_FLASH_START_PROGRAM_DEL_TIME +\ - CY_FLASH_DEL_CORRECTIVE(CY_FLASH_START_PROGRAM_DEL_TICKS)) -/** Delay time fot Start Erase function in uS with corrective time */ -#define CY_FLASH_START_ERASE_DELAY (uint32_t)(CY_FLASH_START_ERASE_DEL_TIME +\ - CY_FLASH_DEL_CORRECTIVE(CY_FLASH_START_ERASE_DEL_TICKS)) -/** Number of ticks to wait 1 uS */ -#define CY_FLASH_TICKS_FOR_1US (8U) -/** Disable delay */ -#define CY_FLASH_NO_DELAY (0U) -/** Slow control register */ -#define CY_FLASH_TST_DDFT_FAST_CTL_MASK (62U) -/** Command completed with no errors */ -#define CY_FLASH_ROMCODE_SUCCESS (0xA0000000UL) -/** Invalid device protection state */ -#define CY_FLASH_ROMCODE_INVALID_PROTECTION (0xF0000001UL) -/** Invalid flash page latch address */ -#define CY_FLASH_ROMCODE_INVALID_FM_PL (0xF0000003UL) -/** Invalid flash address */ -#define CY_FLASH_ROMCODE_INVALID_FLASH_ADDR (0xF0000004UL) -/** Row is write protected */ -#define CY_FLASH_ROMCODE_ROW_PROTECTED (0xF0000005UL) -/** Comparison between Page Latches and FM row failed */ -#define CY_FLASH_ROMCODE_PL_ROW_COMP_FA (0xF0000022UL) -/** Command in progress; no error */ -#define CY_FLASH_ROMCODE_IN_PROGRESS_NO_ERROR (0xA0000009UL) -/** Flash operation is successfully initiated */ -#define CY_FLASH_IS_OPERATION_STARTED (0x00000010UL) -/** Flash is under operation */ -#define CY_FLASH_IS_BUSY (0x00000040UL) -/** IPC structure is already locked by another process */ -#define CY_FLASH_IS_IPC_BUSY (0x00000080UL) -/** Input parameters passed to Flash API are not valid */ -#define CY_FLASH_IS_INVALID_INPUT_PARAMETERS (0x00000100UL) -/** Result mask */ -#define CY_FLASH_RESULT_MASK (0xFFFFFFFUL) -/** Error shift */ -#define CY_FLASH_ERROR_SHIFT (28UL) -/** No error */ -#define CY_FLASH_ERROR_NO_ERROR (0xAUL) -/** CM4 Flash Proxy address */ -#define CY_FLASH_CM4_FLASH_PROXY_ADDR (0x00007001UL) - -#if (CY_CPU_CORTEX_M0P) -#define IS_CY_PIPE_FREE(...) (!Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_INTR_CYPIPE_EP1))) -#define NOTIFY_PEER_CORE(a) Cy_IPC_Pipe_SendMessage(CY_IPC_EP_CYPIPE_CM4_ADDR, CY_IPC_EP_CYPIPE_CM0_ADDR, a, NULL) -#else -#define IS_CY_PIPE_FREE(...) (!Cy_IPC_Drv_IsLockAcquired(Cy_IPC_Drv_GetIpcBaseAddress(CY_IPC_INTR_CYPIPE_EP0))) -#define NOTIFY_PEER_CORE(a) Cy_IPC_Pipe_SendMessage(CY_IPC_EP_CYPIPE_CM0_ADDR, CY_IPC_EP_CYPIPE_CM4_ADDR, a, NULL) -#endif -/** \endcond */ - -/* Static functions */ -static bool Cy_Flash_BoundsCheck(uint32_t flashAddr); -static uint32_t Cy_Flash_PrepareContext(uint32_t rowAddr, const uint32_t *data, uint32_t blocking); -static cy_en_flashdrv_status_t Cy_Flash_ProcessOpcode(uint32_t opcode); -static cy_en_flashdrv_status_t Cy_Flash_OperationStatus(void); -static cy_en_flashdrv_status_t Cy_Flash_SendCmd(uint32_t mode, uint32_t microseconds); -static void Cy_Flash_RAMDelay(uint32_t microseconds); -static cy_stc_flash_context_t context; - -/** \cond INTERNAL */ -CY_ALIGN(4) static IPC_MSG ipcWaitMessage = -{ - /* .clientID */ CY_FLASH_IPC_CLIENT_ID, - /* .pktType */ CY_FLASH_ENTER_WAIT_LOOP, - /* .intrRelMask */ 0 -}; -/** \endcond */ - -/******************************************************************************* -* Function Name: Cy_Flash_SendCmd -****************************************************************************//** -* -* Sends a command to the SROM via the IPC channel. The function is placed to the -* SRAM memory to guarantee successful operation. After an IPC message is sent, -* the function waits for a defined time before exiting the function. -* -* \param mode Sets the blocking or non-blocking Flash operation. -* -* \param microseconds The number of microseconds to wait before exiting the functions. -* -* \return Returns the status of the Flash operation, -* see \ref cy_en_flashdrv_status_t. -* -*******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif -static cy_en_flashdrv_status_t Cy_Flash_SendCmd(uint32_t mode, uint32_t microseconds) -{ - uint32_t intr; - cy_en_flashdrv_status_t result = CY_FLASH_DRV_IPC_BUSY; - - if (IS_CY_PIPE_FREE()) - { - if (CY_IPC_SEMA_STATUS_LOCKED != Cy_IPC_Sema_Status(CY_FLASH_WAIT_SEMA)) - { - if (CY_IPC_PIPE_SUCCESS == NOTIFY_PEER_CORE(&ipcWaitMessage)) - { - /* Wait for SEMA lock by peer core */ - while(CY_IPC_SEMA_STATUS_LOCKED != Cy_IPC_Sema_Status(CY_FLASH_WAIT_SEMA)) - { - } - - intr = Cy_SysLib_EnterCriticalSection(); - - /* Tries to acquire the IPC structure and pass the arguments to SROM API */ - if (Cy_IPC_Drv_SendMsgPtr(CY_FLASH_IPC_STRUCT, CY_FLASH_IPC_NOTIFY_STRUCT0, (void*)&context) == CY_IPC_DRV_SUCCESS) - { - if (mode == CY_FLASH_NON_BLOCKING_MODE) - { - Cy_Flash_RAMDelay(microseconds); - - /* The Flash operation is successfully initiated */ - result = CY_FLASH_DRV_OPERATION_STARTED; - } - else - { - /* Polls whether the IPC is released and the Flash operation is performed */ - do - { - result = Cy_Flash_IsWriteComplete(); - } - while (result == CY_FLASH_DRV_OPCODE_BUSY); - } - } - else - { - /* The IPC structure is already locked by another process */ - result = CY_FLASH_DRV_IPC_BUSY; - } - - while ( CY_IPC_SEMA_SUCCESS != Cy_IPC_Sema_Clear(CY_FLASH_WAIT_SEMA, false)) - { - } - - Cy_SysLib_ExitCriticalSection(intr); - } - } - } - - return (result); -} - -/******************************************************************************* -* Function Name: Cy_Flash_EraseRow -****************************************************************************//** -* -* This function erases a single row of flash. Reports success or -* a reason for failure. Does not return until the Write operation is -* complete. Returns immediately and reports a \ref CY_FLASH_DRV_IPC_BUSY error in -* the case when another process is writing to flash or erasing the row. -* User firmware should not enter the hibernate mode until flash erase is -* complete. The Flash operation is allowed in Sleep and Deep-sleep modes. -* During the Flash operation, the device should not be reset, including the -* XRES pin, a software reset, and watchdog reset sources. Also, low-voltage -* detect circuits should be configured to generate an interrupt instead of a -* reset. Otherwise, portions of flash may undergo unexpected changes. -* -* \param rowAddr Address of the flash row number. The number of the flash rows -* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. -* The Read-while-Write violation occurs when the flash read operation is -* initiated in the same flash sector where the flash write operation is -* performing. Refer to the device datasheet for the details. -* Address must match row start address. -* -* \return Returns the status of the Flash operation, -* see \ref cy_en_flashdrv_status_t. -* -* \sideeffect If this function is called by the CM4 the user code on CM0P and -* the user code on CM4 are blocked until erase flash row operation is finished. -* If this function is called by the CM0P the user code on CM4 is not blocked and -* the user code on CM0P is blocked until erase flash row operation is finished. -* Plan your task allocation accordingly. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_EraseRow(uint32_t rowAddr) -{ - cy_en_flashdrv_status_t result; - - /* Prepares arguments to be passed to SROM API */ - if (Cy_Flash_BoundsCheck(rowAddr) != false) - { - context.opcode = CY_FLASH_OPCODE_ERASE_ROW | CY_FLASH_BLOCKING_MODE; - context.arg1 = rowAddr; - context.arg2 = 0UL; - context.arg3 = 0UL; - -#if (CY_CPU_CORTEX_M0P) - result = Cy_Flash_SendCmd(CY_FLASH_BLOCKING_MODE, CY_FLASH_NO_DELAY); -#else - Cy_Flash_Proxy Cy_Flash_Cm4Proxy; - Cy_Flash_Cm4Proxy = (Cy_Flash_Proxy)CY_FLASH_CM4_FLASH_PROXY_ADDR; - result = Cy_Flash_Cm4Proxy(&context); - result = Cy_Flash_ProcessOpcode((uint32_t)result); - -#endif /* (CY_CPU_CORTEX_M0P) */ - } - else - { - result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_WriteRow -****************************************************************************//** -* -* This function writes an array of data to a single row of flash. -* Reports success or a reason for failure. Does not return until the Write -* operation is complete. -* Returns immediately and reports a \ref CY_FLASH_DRV_IPC_BUSY error in the case -* when another process is writing to flash. User firmware should not enter the -* hibernate mode until flash Write is complete. The Flash operation is allowed -* in Sleep and Deep-sleep modes. During the Flash operation, the device should -* not be reset, including the XRES pin, a software reset, and watchdog reset -* sources. Also, low-voltage detect circuits should be configured to generate -* an interrupt instead of a reset. Otherwise, portions of flash may undergo -* unexpected changes. -* -* \param rowAddr Address of the flash row number. The number of the flash rows -* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. -* The Read-while-Write violation occurs when the flash read operation is -* initiated in the same flash sector where the flash write operation is -* performing. Refer to the device datasheet for the details. -* Address must match row start address. -* -* \param data The pointer to the data which has to be written to flash. The size -* of the data array must be equal to the flash row size. The flash row size for -* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to -* the device datasheet for the details. -* -* \return Returns the status of the Flash operation, -* see \ref cy_en_flashdrv_status_t. -* -* \sideeffect If this function is called by the CM4 the user code on CM0P and -* the user code on CM4 are blocked until erase flash row operation is finished. -* If this function is called by the CM0P the user code on CM4 is not blocked and -* the user code on CM0P is blocked until erase flash row operation is finished. -* Plan your task allocation accordingly. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_WriteRow(uint32_t rowAddr, const uint32_t* data) -{ - cy_en_flashdrv_status_t result; - -#if (CY_CPU_CORTEX_M0P) - /* Checks whether the input parameters are valid */ - if (Cy_Flash_PrepareContext(rowAddr, data, CY_FLASH_BLOCKING_MODE) != (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS) - { - result = Cy_Flash_SendCmd(CY_FLASH_BLOCKING_MODE, CY_FLASH_NO_DELAY); - } - else - { - result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - -#else - if (Cy_Flash_PrepareContext(rowAddr, data, CY_FLASH_BLOCKING_MODE) != (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS) - { - Cy_Flash_Proxy Cy_Flash_Cm4Proxy; - Cy_Flash_Cm4Proxy = (Cy_Flash_Proxy)CY_FLASH_CM4_FLASH_PROXY_ADDR; - result = Cy_Flash_Cm4Proxy(&context); - result = Cy_Flash_ProcessOpcode((uint32_t)result); - } - else - { - result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } -#endif /* (CY_CPU_CORTEX_M0P) */ - - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_StartWrite -****************************************************************************//** -* -* Starts writing an array of data to a single row of flash. Returns immediately -* and reports a successful start or reason for failure. Returns immediately and -* reports a \ref CY_FLASH_DRV_IPC_BUSY error in the case when another process is writing -* to flash. User firmware should not enter the hibernate mode until flash Write -* is complete. The Flash operation is allowed in Sleep and Deep-sleep modes. -* During the flash operation, the device should not be reset, including the -* XRES pin, a software reset, and watchdog reset sources. Also, the low-voltage -* detect circuits should be configured to generate an interrupt instead of a reset. -* Otherwise, portions of flash may undergo unexpected changes. -* \note Before reading data from previously programmed/erased flash rows, the -* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() -* function. -* -* \param rowAddr Address of the flash row number. The number of the flash rows -* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. -* The Read-while-Write violation occurs when the flash read operation is -* initiated in the same flash sector where the flash write operation is -* performing. Refer to the device datasheet for the details. -* Address must match row start address. -* -* \param data The pointer to the data to be written to flash. The size -* of the data array must be equal to the flash row size. The flash row size for -* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to -* the device datasheet for the details. -* -* \return Returns the status of the Flash operation, -* see \ref cy_en_flashdrv_status_t. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_StartWrite(uint32_t rowAddr, const uint32_t* data) -{ - cy_en_flashdrv_status_t result; - - /* Checks whether the input parameters are valid */ - if (Cy_Flash_PrepareContext(rowAddr, data, CY_FLASH_NON_BLOCKING_MODE) != (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS) - { - result = Cy_Flash_SendCmd(CY_FLASH_NON_BLOCKING_MODE, CY_FLASH_START_WRITE_DELAY); - } - else - { - result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_IsWriteComplete -****************************************************************************//** -* -* Reports a successful Write, reason of failure or busy status -* ( \ref CY_FLASH_DRV_OPCODE_BUSY ). -* -* \return Returns the status of the Flash operation (see \ref cy_en_flashdrv_status_t). -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_IsWriteComplete(void) -{ - return (Cy_Flash_OperationStatus()); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_StartErase -****************************************************************************//** -* -* Starts erasing a single row of flash. Returns immediately -* and reports a successful start or reason for failure. Returns immediately and -* reports a \ref CY_FLASH_DRV_IPC_BUSY error in the case when IPC structure is locked -* by another process. User firmware should not enter the hibernate mode until -* flash Erase is complete. The Flash operation is allowed in Sleep and Deep-sleep modes. -* During the flash operation, the device should not be reset, including the -* XRES pin, a software reset, and watchdog reset sources. Also, the low-voltage -* detect circuits should be configured to generate an interrupt instead of a reset. -* Otherwise, portions of flash may undergo unexpected changes. -* \note Before reading data from previously programmed/erased flash rows, the -* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() -* function. -* -* \param rowAddr Address of the flash row number. The number of the flash rows -* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. -* The Read-while-Write violation occurs when the flash read operation is -* initiated in the same flash sector where the flash erase operation is -* performing. Refer to the device datasheet for the details. -* Address must match row start address. -* -* \return Returns the status of the Flash operation, -* see \ref cy_en_flashdrv_status_t. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_StartErase(uint32_t rowAddr) -{ - cy_en_flashdrv_status_t retVal; - - /* Prepares arguments to be passed to SROM API */ - if (Cy_Flash_BoundsCheck(rowAddr) != false) - { - context.opcode = CY_FLASH_OPCODE_ERASE_ROW; - context.arg1 = rowAddr; - context.arg2 = 0UL; - context.arg3 = 0UL; - retVal = Cy_Flash_SendCmd(CY_FLASH_NON_BLOCKING_MODE, CY_FLASH_START_ERASE_DELAY); - } - else - { - retVal = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - - return (retVal); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_IsEraseComplete -****************************************************************************//** -* -* Reports a successful Erase, reason of failure or busy status -* ( \ref CY_FLASH_DRV_OPCODE_BUSY ). -* -* \return Returns the status of the Flash operation (see \ref cy_en_flashdrv_status_t). -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_IsEraseComplete(void) -{ - return (Cy_Flash_OperationStatus()); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_StartProgram -****************************************************************************//** -* Starts writing an array of data to a single row of flash. Returns immediately -* and reports a successful start or reason for failure. Returns immediately and -* reports a \ref CY_FLASH_DRV_IPC_BUSY error if another process is writing -* to flash. The user firmware should not enter Hibernate mode until flash Write -* is complete. The Flash operation is allowed in Sleep and Deep-Sleep modes. -* During the Flash operation, the device should not be reset, including the -* XRES pin, a software reset, and watchdog reset sources. Also, the low-voltage -* detect circuits should be configured to generate an interrupt instead of a reset. -* Otherwise, portions of flash may undergo unexpected changes.\n -* Before calling this function, the target flash region must be erased by -* the StartErase/EraseRow function.\n -* Data to be programmed must be located in the SRAM memory region. -* \note Before reading data from previously programmed/erased flash rows, the -* user must clear the flash cache with the Cy_SysLib_ClearFlashCacheAndBuffer() -* function. -* -* \param rowAddr The address of the flash row number. The number of the flash rows -* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. -* The Read-while-Write violation occurs when the Flash Write operation is -* performing. Refer to the device datasheet for the details. -* The address must match the row start address. -* -* \param data The pointer to the data to be written to flash. The size -* of the data array must be equal to the flash row size. The flash row size for -* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to -* the device datasheet for the details. -* -* \return Returns the status of the Flash operation, -* see \ref cy_en_flashdrv_status_t. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_StartProgram(uint32_t rowAddr, const uint32_t* data) -{ - cy_en_flashdrv_status_t result; - - /* Prepares arguments to be passed to SROM API */ - if (Cy_Flash_BoundsCheck(rowAddr) != false) - { - context.opcode = CY_FLASH_OPCODE_PROGRAM_ROW | CY_FLASH_NON_BLOCKING_MODE; - context.arg1 = CY_FLASH_CONFIG_DATASIZE | CY_FLASH_DATA_LOC_SRAM; - context.arg2 = rowAddr; - context.arg3 = (uint32_t)data; - - result = Cy_Flash_SendCmd(CY_FLASH_NON_BLOCKING_MODE, CY_FLASH_START_PROGRAM_DELAY); - } - else - { - result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_IsProgramComplete -****************************************************************************//** -* -* Reports a successful program operation, failure or busy status -* ( \ref CY_FLASH_DRV_OPCODE_BUSY ). -* -* \return Returns the status of the Flash operation (see \ref cy_en_flashdrv_status_t). -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_IsProgramComplete(void) -{ - return (Cy_Flash_OperationStatus()); -} - -/******************************************************************************* -* Function Name: Cy_Flash_RowChecksum -****************************************************************************//** -* -* Returns a checksum value of the specified flash row. -* -* \param rowNum The Checksum is calculated to the flash row. -* -* \param checksumPtr The pointer to the address where checksum is to be stored -* -* \return Returns the status of the Flash operation. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_RowChecksum (uint32_t rowNum, uint32_t* checksumPtr) -{ - cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - uint32_t resTmp; - - /* Checks whether the input parameters are valid */ - if (rowNum < CY_FLASH_NUMBER_ROWS) - { - /* Prepares arguments to be passed to SROM API */ - context.opcode = CY_FLASH_OPCODE_CHECKSUM | (rowNum << CY_FLASH_OPCODE_CHECKSUM_ROW_SHIFT); - - /* Tries to acquire the IPC structure and pass the arguments to SROM API */ - if (Cy_IPC_Drv_SendMsgPtr(CY_FLASH_IPC_STRUCT, CY_FLASH_IPC_NOTIFY_STRUCT0, (void*)&context) == CY_IPC_DRV_SUCCESS) - { - /* Polls whether IPC is released and the Flash operation is performed */ - while (Cy_IPC_Drv_IsLockAcquired(CY_FLASH_IPC_STRUCT) != false) - { - /* Wait till IPC is released */ - } - - resTmp = context.opcode; - - if((resTmp >> CY_FLASH_ERROR_SHIFT) == CY_FLASH_ERROR_NO_ERROR) - { - result = CY_FLASH_DRV_SUCCESS; - *checksumPtr = context.opcode & CY_FLASH_RESULT_MASK; - } - } - else - { - /* The IPC structure is already locked by another process */ - result = CY_FLASH_DRV_IPC_BUSY; - } - } - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_CalculateHash -****************************************************************************//** -* -* Returns a hash value of the specified region of flash. -* -* \param data Start the data address. -* -* \param numberOfBytes The hash value is calculated for the number of bytes after the -* start data address (0 - 1 byte, 1- 2 bytes etc). -* -* \param hashPtr The pointer to the address where hash is to be stored -* -* \return Returns the status of the Flash operation. -* -*******************************************************************************/ -cy_en_flashdrv_status_t Cy_Flash_CalculateHash (const uint32_t* data, uint32_t numberOfBytes, uint32_t* hashPtr) -{ - cy_en_flashdrv_status_t result = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - volatile uint32_t resTmp; - - /* Checks whether the input parameters are valid */ - if (data != NULL) - { - /* Prepares arguments to be passed to SROM API */ - context.opcode = CY_FLASH_OPCODE_HASH; - context.arg1 = (uint32_t)data; - context.arg2 = numberOfBytes; - - /* Tries to acquire the IPC structure and pass the arguments to SROM API */ - if (Cy_IPC_Drv_SendMsgPtr(CY_FLASH_IPC_STRUCT, CY_FLASH_IPC_NOTIFY_STRUCT0, (void*)&context) == CY_IPC_DRV_SUCCESS) - { - /* Polls whether IPC is released and the Flash operation is performed */ - while (Cy_IPC_Drv_IsLockAcquired(CY_FLASH_IPC_STRUCT) != false) - { - /* Wait till IPC is released */ - } - - resTmp = context.opcode; - - if((resTmp >> CY_FLASH_ERROR_SHIFT) == CY_FLASH_ERROR_NO_ERROR) - { - result = CY_FLASH_DRV_SUCCESS; - *hashPtr = context.opcode & CY_FLASH_RESULT_MASK; - } - } - else - { - /* The IPC structure is already locked by another process */ - result = CY_FLASH_DRV_IPC_BUSY; - } - } - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_BoundsCheck -****************************************************************************//** -* -* Returns false if Flash address is out of boundary, otherwise returns true. -* -* \param flashAddr Address to be checked -* -* \return false - out of bound, true - in flash bounds -* -*******************************************************************************/ -static bool Cy_Flash_BoundsCheck(uint32_t flashAddr) -{ - bool result = true; - - if ((flashAddr < CY_FLASH_BASE) || (flashAddr >= (CY_FLASH_BASE + CY_FLASH_SIZE))) - { - if ((flashAddr < CY_WFLASH_BASE) || (flashAddr >= (CY_WFLASH_BASE + CY_WFLASH_SIZE))) - { - if ((flashAddr < SFLASH_BASE) || (flashAddr >= (SFLASH_BASE + SFLASH_SECTION_SIZE))) - { - result = false; - } - } - } - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_PrepareContext -****************************************************************************//** -* -* Returns 1 if parameters are correct and initialises context, otherwise returns -* CY_FLASH_DRV_INVALID_INPUT_PARAMETERS. -* -* \param rowAddr Address of the flash row number. The number of the flash rows -* is defined by the \ref CY_FLASH_NUMBER_ROWS macro for the selected device. -* The Read-while-Write violation occurs when the flash read operation is -* initiated in the same flash sector where the flash write operation is -* performing. Refer to the device datasheet for the details. -* Address must match row start address. -* -* \param data The pointer to the data which has to be written to flash. The size -* of the data array must be equal to the flash row size. The flash row size for -* the selected device is defined by the \ref CY_FLASH_SIZEOF_ROW macro. Refer to -* the device datasheet for the details. -* -* \param blocking The parameter of how the context will be executed. -* * 1 - blocking, If this function is called by the CM4 the user code on CM0P -* and the user code on CM4 are blocked until flash write operation is finished. -* If this function is called by the CM0P the user code on CM4 is not blocked -* and the user code on CM0P is blocked until flash write operation is finished. -* * 0 - non-blocking, the user code is not blocked while flash write operation -* is executed. -* -* \return 1 - Context ready, CY_FLASH_DRV_INVALID_INPUT_PARAMETERS - Wrong -* arguments -* -*******************************************************************************/ -static uint32_t Cy_Flash_PrepareContext(uint32_t rowAddr, const uint32_t* data, uint32_t blocking) -{ - uint32_t result; - - if ((Cy_Flash_BoundsCheck(rowAddr) == false) || (NULL == data)) - { - result = (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - else - { - if ((rowAddr%CY_FLASH_SIZEOF_ROW) != 0UL) - { - result = (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - else - { - /* Prepares arguments to be passed to SROM API */ - context.opcode = CY_FLASH_OPCODE_WRITE_ROW | blocking; - context.arg1 = CY_FLASH_CONFIG_DATASIZE; - context.arg2 = rowAddr; - context.arg3 = (uint32_t)data; - - result = 1UL; - } - } - - return (result); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_ProcessOpcode -****************************************************************************//** -* -* Converts System Call returns to the Flash driver return defines. -* -* \param opcode The value returned by the System Call. -* -* \return Flash driver return. -* -*******************************************************************************/ -static cy_en_flashdrv_status_t Cy_Flash_ProcessOpcode(uint32_t opcode) -{ - cy_en_flashdrv_status_t retVal; - - switch (opcode) - { - case 0UL: - { - retVal = CY_FLASH_DRV_SUCCESS; - break; - } - case CY_FLASH_ROMCODE_SUCCESS: - { - retVal = CY_FLASH_DRV_SUCCESS; - break; - } - case CY_FLASH_ROMCODE_INVALID_PROTECTION: - { - retVal = CY_FLASH_DRV_INV_PROT; - break; - } - case CY_FLASH_ROMCODE_INVALID_FM_PL: - { - retVal = CY_FLASH_DRV_INVALID_FM_PL; - break; - } - case CY_FLASH_ROMCODE_INVALID_FLASH_ADDR: - { - retVal = CY_FLASH_DRV_INVALID_FLASH_ADDR; - break; - } - case CY_FLASH_ROMCODE_ROW_PROTECTED: - { - retVal = CY_FLASH_DRV_ROW_PROTECTED; - break; - } - case CY_FLASH_ROMCODE_IN_PROGRESS_NO_ERROR: - { - retVal = CY_FLASH_DRV_PROGRESS_NO_ERROR; - break; - } - case (uint32_t)CY_FLASH_DRV_INVALID_INPUT_PARAMETERS: - { - retVal = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - break; - } - case CY_FLASH_IS_OPERATION_STARTED : - { - retVal = CY_FLASH_DRV_OPERATION_STARTED; - break; - } - case CY_FLASH_IS_BUSY : - { - retVal = CY_FLASH_DRV_OPCODE_BUSY; - break; - } - case CY_FLASH_IS_IPC_BUSY : - { - retVal = CY_FLASH_DRV_IPC_BUSY; - break; - } - case CY_FLASH_IS_INVALID_INPUT_PARAMETERS : - { - retVal = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - break; - } - default: - { - retVal = CY_FLASH_DRV_ERR_UNC; - break; - } - } - - return (retVal); -} - - -/******************************************************************************* -* Function Name: Cy_Flash_OperationStatus -****************************************************************************//** -* -* Checks the status of the Flash Operation, and returns it. -* -* \return Returns the status of the Flash operation -* (see \ref cy_en_flashdrv_status_t). -* -*******************************************************************************/ -static cy_en_flashdrv_status_t Cy_Flash_OperationStatus(void) -{ - cy_en_flashdrv_status_t retVal = CY_FLASH_DRV_OPCODE_BUSY; - - /* Checks if the IPC structure is not locked */ - if (Cy_IPC_Drv_IsLockAcquired(CY_FLASH_IPC_STRUCT) == false) - { - /* The result of SROM API calling is returned to the driver context */ - retVal = Cy_Flash_ProcessOpcode(context.opcode); - } - - return (retVal); -} - -/******************************************************************************* -* Function Name: Cy_Flash_RAMDelay -****************************************************************************//** -* -* Wait for a defined time in the SRAM memory region. -* -*******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif -static void Cy_Flash_RAMDelay(uint32_t microseconds) -{ - uint32_t ticks = microseconds * CY_FLASH_TICKS_FOR_1US; - if (ticks != CY_FLASH_NO_DELAY) - { - CY_FLASH_TST_DDFT_SLOW_CTL_REG = CY_FLASH_TST_DDFT_SLOW_CTL_MASK; - CY_FLASH_CLK_OUTPUT_SLOW_REG = CY_FLASH_CLK_OUTPUT_SLOW_MASK; - CY_FLASH_TST_DDFT_FAST_CTL_REG = CY_FLASH_TST_DDFT_FAST_CTL_MASK; - - /* Load the down-counter */ - CY_FLASH_CLK_CAL_CNT1_REG = ticks; - - /* Make sure that the counter is started */ - (void) CY_FLASH_CLK_CAL_CNT1_REG; - - while(0U == (CY_FLASH_CLK_CAL_CNT1_REG & CY_FLASH_CLK_CAL_CNT1_DONE)) - { - /* Wait until the counter stops counting */ - } - } -} - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/flash/cy_flash.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/flash/cy_flash.h deleted file mode 100644 index a200f8dcef..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/flash/cy_flash.h +++ /dev/null @@ -1,302 +0,0 @@ -/***************************************************************************//** -* \file cy_flash.h -* \version 2.0 -* -* Provides the API declarations of the Flash driver. -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#if !defined(CY_FLASH_H) -#define CY_FLASH_H - -/** -* \defgroup group_flash Flash System Routine (Flash) -* \{ -* Internal flash memory programming -* -* Flash memory in PSoC devices provides non-volatile storage for user firmware, -* user configuration data, and bulk data storage. -* -* Flash operations are implemented as system calls. System calls are executed -* out of SROM in the privileged mode of operation. Users have no access to read -* or modify the SROM code. The driver API requests the system call by acquiring -* the Inter-processor communication (IPC) and writing the SROM function opcode -* and parameters to its input registers. As a result, an NMI interrupt is invoked -* and the requested SROM API is executed. The operation status is returned to the -* driver context and a release interrupt is triggered. -* -* Writing to flash can take up to 20 milliseconds. During this time, -* the device should not be reset (including XRES pin, software reset, and -* watchdog) or unexpected changes may be made to portions of the flash. -* Also, the low-voltage detect circuits should be configured to generate an -* interrupt instead of a reset. -* -* The Read while Write violation occurs when the flash Read operation is initiated -* in the same flash sector where the flash Write operation is performing. The -* violation leads to the exception generation. To avoid the Read while Write -* violation, the user has to carefully split the Read and Write operation from the -* same flash sector considering both cores in the multi-processor device. -* Use different flash sectors for code and data storage. The flash is divided -* into four equal sectors. -* -* \warning If the CM0 core triggers the Flash operation, another core must be in -* Active mode and interrupts must be enabled in both cores. -* -* \note "Warning[Ta023]: Call to a non __ramfunc function." - The warning may -* appear during the build process while using IAR IDE. The reason - some -* functions in RAM memory that use the __ramfunc keyword, may invoke -* functions located in the ROM memory. You can ignore this warning or -* disable it by adding the --diag_suppress=Ta023 option to the compiler. -* -* \section group_flash_configuration Configuration Considerations -* -* Note that to be able to perform FLASH writes, the VCCD should be more than 0.99 V. -* For more information see the technical reference manual (TRM). -* -* \section group_flash_more_information More Information -* -* See the technical reference manual (TRM) for more information about the Flash architecture. -* -* \section group_flash_MISRA MISRA-C Compliance -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
5.6RNo identifier in one name space can have the same spelling as an identifier in another name space, with the -* exception of structure member and union member names.The "context" is used as a structure/union member; they are a label, tag or ordinary -* identifier.
8.7RObjects shall be defined at block scope if they are only accessed -* from within a single function.The driver defines an internal variable that can be accessed by -* any core through the IPC hardware.
-* -* \section group_flash_changelog Changelog -* -* -* -* -* -* -* -* -* -* -* -* -* -*
VersionChangesReason for Change
1.0Initial version
2.0Added non-blocking erase functions ( Cy_Flash_StartErase() and -* Cy_Flash_IsEraseComplete() ). Removed the clear cache function -* call.The clear cache operation is removed from the blocking Write/Erase -* function because in this case it is performed by the hardware. -* Otherwise it is documented that it is the user's responsibility to -* clear the cache after executing the non-blocking Write/Erase flash -* operation.
-* -* \defgroup group_flash_macros Macros -* \defgroup group_flash_functions Functions -* \defgroup group_flash_data_structure Data Structures -* \defgroup group_flash_enumerated_types Enumerated Types -*/ - -#include -#include -#include -#include -#include - -#if defined(__cplusplus) -extern "C" { -#endif - -/*************************************** -* Macro definitions -***************************************/ -/** -* \addtogroup group_flash_macros -* \{ -*/ - -/** Driver major version */ -#define CY_FLASH_DRV_VERSION_MAJOR 2 - -/** Driver minor version */ -#define CY_FLASH_DRV_VERSION_MINOR 0 - -#define CY_FLASH_ID (CY_PDL_DRV_ID(0x14UL)) /**< FLASH PDL ID */ - -#define CY_FLASH_ID_INFO (uint32_t)( CY_FLASH_ID | CY_PDL_STATUS_INFO ) /**< Return prefix for FLASH driver function status codes */ -#define CY_FLASH_ID_WARNING (uint32_t)( CY_FLASH_ID | CY_PDL_STATUS_WARNING) /**< Return prefix for FLASH driver function warning return values */ -#define CY_FLASH_ID_ERROR (uint32_t)( CY_FLASH_ID | CY_PDL_STATUS_ERROR) /**< Return prefix for FLASH driver function error return values */ - -/** \cond INTERNAL */ -#define CY_FLASH_ENTER_WAIT_LOOP 0xFFU -#define CY_FLASH_IPC_CLIENT_ID 2U -/** Semaphore number reserved for flash driver */ -#define CY_FLASH_WAIT_SEMA 0UL -/** \endcond */ - -/** -* \addtogroup group_flash_config_macros Flash configuration -* \{ -* Specifies the parameter values passed to SROM API -*/ - -/** Set SROM API in blocking mode */ -#define CY_FLASH_BLOCKING_MODE ((0x01UL) << 8UL) -/** Set SROM API in non blocking mode */ -#define CY_FLASH_NON_BLOCKING_MODE (0UL) - -/** SROM API opcode for flash write operation */ -#define CY_FLASH_OPCODE_WRITE_ROW ((0x05UL) << 24UL) -/** SROM API opcode for flash program operation */ -#define CY_FLASH_OPCODE_PROGRAM_ROW ((0x06UL) << 24UL) -/** SROM API opcode for row erase operation */ -#define CY_FLASH_OPCODE_ERASE_ROW ((0x1CUL) << 24UL) -/** SROM API opcode for flash checksum operation */ -#define CY_FLASH_OPCODE_CHECKSUM ((0x0BUL) << 24UL) -/** SROM API opcode for flash hash operation */ -#define CY_FLASH_OPCODE_HASH ((0x0DUL) << 24UL) -/** SROM API flash row shift for flash checksum operation */ -#define CY_FLASH_OPCODE_CHECKSUM_ROW_SHIFT (8UL) -/** SROM API flash data size parameter for flash write operation */ -#define CY_FLASH_CONFIG_DATASIZE (0x06UL) -/** Data to be programmed to flash is located in SRAM memory region */ -#define CY_FLASH_DATA_LOC_SRAM (0x100UL) -/** SROM API flash verification option for flash write operation */ -#define CY_FLASH_CONFIG_VERIFICATION_EN ((0x01UL) << 16u) - -/** \} group_flash_config_macros */ - - -/** -* \addtogroup group_flash_general_macros Flash general parameters -* \{ -* Provides general information about flash and IPC -*/ - -/** Flash row size */ -#define CY_FLASH_SIZEOF_ROW (CPUSS_FLASHC_PA_SIZE * 4u) -/** Number of flash rows */ -#define CY_FLASH_NUMBER_ROWS (CY_FLASH_SIZE / CY_FLASH_SIZEOF_ROW) -/** Long words flash row size */ -#define CY_FLASH_SIZEOF_ROW_LONG_UNITS (CY_FLASH_SIZEOF_ROW / sizeof(uint32_t)) -/** IPC channel to be used */ -#define CY_FLASH_IPC_STRUCT ((IPC_STRUCT_Type*) &IPC->STRUCT[CY_IPC_CHAN_SYSCALL]) -/** IPC notify bit for IPC_STRUCT0 (dedicated to flash operation) */ -#define CY_FLASH_IPC_NOTIFY_STRUCT0 (0x1UL << CY_IPC_INTR_SYSCALL1) -/** IPC notify interrupt structure number */ -#define CY_FLASH_IPC_INTR_CM0_NOTIFY (0x1UL << CY_IPC_INTR_FLASH_NOTIFY) - -/** \} group_flash_general_macros */ - -/** \} group_flash_macros */ - -/** -* \addtogroup group_flash_enumerated_types -* \{ -*/ - -/** This enum has the return values of the Flash driver */ -typedef enum -{ - CY_FLASH_DRV_SUCCESS = 0x00UL, /**< Success */ - CY_FLASH_DRV_INV_PROT = ( CY_FLASH_ID_ERROR + 0x0UL), /**< Invalid device protection state */ - CY_FLASH_DRV_INVALID_FM_PL = ( CY_FLASH_ID_ERROR + 0x1UL), /**< Invalid flash page latch address */ - CY_FLASH_DRV_INVALID_FLASH_ADDR = ( CY_FLASH_ID_ERROR + 0x2UL), /**< Invalid flash address */ - CY_FLASH_DRV_ROW_PROTECTED = ( CY_FLASH_ID_ERROR + 0x3UL), /**< Row is write protected */ - CY_FLASH_DRV_IPC_BUSY = ( CY_FLASH_ID_ERROR + 0x5UL), /**< IPC structure is already locked by another process */ - CY_FLASH_DRV_INVALID_INPUT_PARAMETERS = ( CY_FLASH_ID_ERROR + 0x6UL), /**< Input parameters passed to Flash API are not valid */ - CY_FLASH_DRV_PL_ROW_COMP_FA = ( CY_FLASH_ID_ERROR + 0x22UL), /**< Comparison between Page Latches and FM row failed */ - CY_FLASH_DRV_ERR_UNC = ( CY_FLASH_ID_ERROR + 0xFFUL), /**< Unknown error */ - CY_FLASH_DRV_PROGRESS_NO_ERROR = ( CY_FLASH_ID_INFO + 0x0UL), /**< Command in progress; no error */ - CY_FLASH_DRV_OPERATION_STARTED = ( CY_FLASH_ID_INFO + 0x1UL), /**< Flash operation is successfully initiated */ - CY_FLASH_DRV_OPCODE_BUSY = ( CY_FLASH_ID_INFO + 0x2UL) /**< Flash is under operation */ -} cy_en_flashdrv_status_t; - -/** \} group_flash_enumerated_types */ - -/*************************************** -* Data Structure definitions -***************************************/ - -/** -* \addtogroup group_flash_data_structure -* \{ -*/ - -/** Flash driver context */ -typedef struct -{ - uint32_t opcode; /**< Specifies the code of flash operation */ - uint32_t arg1; /**< Specifies the configuration of flash operation */ - uint32_t arg2; /**< Specifies the configuration of flash operation */ - uint32_t arg3; /**< Specifies the configuration of flash operation */ -}cy_stc_flash_context_t; - -/** \} group_flash_data_structure */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** -* \addtogroup group_flash_functions -* \{ -*/ -cy_en_flashdrv_status_t Cy_Flash_EraseRow(uint32_t rowAddr); -cy_en_flashdrv_status_t Cy_Flash_WriteRow(uint32_t rowAddr, const uint32_t* data); -cy_en_flashdrv_status_t Cy_Flash_StartWrite(uint32_t rowAddr, const uint32_t* data); -cy_en_flashdrv_status_t Cy_Flash_IsWriteComplete(void); -cy_en_flashdrv_status_t Cy_Flash_StartProgram(uint32_t rowAddr, const uint32_t* data); -cy_en_flashdrv_status_t Cy_Flash_IsProgramComplete(void); -cy_en_flashdrv_status_t Cy_Flash_StartErase(uint32_t rowAddr); -cy_en_flashdrv_status_t Cy_Flash_IsEraseComplete(void); -cy_en_flashdrv_status_t Cy_Flash_RowChecksum(uint32_t rowNum, uint32_t* checksumPtr); -cy_en_flashdrv_status_t Cy_Flash_CalculateHash(const uint32_t* data, uint32_t numberOfBytes, uint32_t* hashPtr); -/** \cond INTERNAL */ -typedef cy_en_flashdrv_status_t (*Cy_Flash_Proxy)(cy_stc_flash_context_t *context); - -typedef struct _IPC_MSG -{ - uint8_t clientID; - uint8_t pktType; - uint16_t intrRelMask; -} IPC_MSG; -/** \endcond */ - -/** \} group_flash_functions */ - -#if defined(__cplusplus) -} -#endif - - -#endif /* #if !defined(CY_FLASH_H) */ -/** \endcond */ - - -/** \} group_flash */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/gpio/cy_gpio.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/gpio/cy_gpio.c deleted file mode 100644 index 95dcb3e33f..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/gpio/cy_gpio.c +++ /dev/null @@ -1,137 +0,0 @@ -/***************************************************************************//** -* \file cy_gpio.c -* \version 1.0 -* -* \brief -* Provides an API implementation of the GPIO driver -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_gpio.h" - -#if defined(__cplusplus) -extern "C" { -#endif - - -/******************************************************************************* -* Function Name: Cy_GPIO_Pin_Init -****************************************************************************//** -* -* \brief Initialize all pin configuration setting for the pin. -* -* \param base -* Pointer to the pin's port register base address -* -* \param pinNum -* Position of the pin bit-field within the port register -* -* \param config -* Pointer to the pin config structure base address -* -* \return -* Initialization status -* -* \note -* This function modifies port registers in read-modify-write operations. It is -* not thread safe as the resource is shared among multiple pins on a port. -* -*******************************************************************************/ -cy_en_gpio_status_t Cy_GPIO_Pin_Init(GPIO_PRT_Type *base, uint32_t pinNum, const cy_stc_gpio_pin_config_t *config) -{ - cy_en_gpio_status_t status = CY_GPIO_SUCCESS; - uint32_t maskCfgOut; - uint32_t tempReg; - - if((NULL != base) && (NULL != config)) - { - Cy_GPIO_Write(base, pinNum, config->outVal); - Cy_GPIO_SetDrivemode(base, pinNum, config->driveMode); - Cy_GPIO_SetHSIOM(base, pinNum, config->hsiom); - - Cy_GPIO_SetInterruptEdge(base, pinNum, config->intEdge); - Cy_GPIO_SetInterruptMask(base, pinNum, config->intMask); - Cy_GPIO_SetVtrip(base, pinNum, config->vtrip); - - /* Slew rate and Driver strength */ - maskCfgOut = (CY_GPIO_CFG_OUT_SLOW_MASK << pinNum) | (CY_GPIO_CFG_OUT_DRIVE_SEL_MASK << (pinNum + CY_GPIO_CFG_OUT_DRIVE_OFFSET)); - tempReg = base->CFG_OUT & ~(maskCfgOut); - base->CFG_OUT = tempReg | ((config->slewRate & CY_GPIO_CFG_OUT_SLOW_MASK) << pinNum) - | ((config->driveSel & CY_GPIO_CFG_OUT_DRIVE_SEL_MASK) << (pinNum + CY_GPIO_CFG_OUT_DRIVE_OFFSET)); - - /* SIO specific configuration */ - tempReg = base->CFG_SIO & ~(CY_GPIO_SIO_PIN_MASK); - base->CFG_SIO = tempReg | (((config->vregEn & CY_GPIO_VREG_EN_MASK) - | ((config->ibufMode & CY_GPIO_IBUF_MASK) << CY_GPIO_IBUF_SHIFT) - | ((config->vtripSel & CY_GPIO_VTRIP_SEL_MASK) << CY_GPIO_VTRIP_SEL_SHIFT) - | ((config->vrefSel & CY_GPIO_VREF_SEL_MASK) << CY_GPIO_VREF_SEL_SHIFT) - | ((config->vohSel & CY_GPIO_VOH_SEL_MASK) << CY_GPIO_VOH_SEL_SHIFT)) - << ((pinNum & CY_GPIO_SIO_ODD_PIN_MASK) << CY_GPIO_CFG_SIO_OFFSET)); - } - else - { - status = CY_GPIO_BAD_PARAM; - } - - return(status); -} - - -/******************************************************************************* -* Function Name: Cy_GPIO_Port_Init -****************************************************************************//** -* -* \brief Initialize a complete port of pins from a single init structure. -* -* \param base -* Pointer to the pin's port register base address -* -* \param config -* Pointer to the pin config structure base address -* -* \return -* Initialization status -* -*******************************************************************************/ -cy_en_gpio_status_t Cy_GPIO_Port_Init(GPIO_PRT_Type* base, const cy_stc_gpio_prt_config_t *config) -{ - cy_en_gpio_status_t status = CY_GPIO_SUCCESS; - uint32_t portNum; - HSIOM_PRT_Type* baseHSIOM; - - if((NULL != base) && (NULL != config)) - { - portNum = ((uint32_t)(base) - GPIO_BASE) / GPIO_PRT_SECTION_SIZE; - baseHSIOM = (HSIOM_PRT_Type*)(HSIOM_BASE + (HSIOM_PRT_SECTION_SIZE * portNum)); - - base->OUT = config->out; - base->CFG = config->cfg; - base->CFG_IN = config->cfgIn; - base->CFG_OUT = config->cfgOut; - base->INTR_CFG = config->intrCfg; - base->INTR_MASK = config->intrMask; - base->CFG_SIO = config->cfgSIO; - baseHSIOM->PORT_SEL0 = config->sel0Active; - baseHSIOM->PORT_SEL1 = config->sel1Active; - } - else - { - status = CY_GPIO_BAD_PARAM; - } - - return(status); -} - - -#if defined(__cplusplus) -} -#endif - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/mcwdt/cy_mcwdt.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/mcwdt/cy_mcwdt.c deleted file mode 100644 index 1af096c595..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/mcwdt/cy_mcwdt.c +++ /dev/null @@ -1,100 +0,0 @@ -/***************************************************************************//** -* \file cy_mcwdt.c -* \version 1.0 -* -* Description: -* Provides a system API for the MCWDT driver. -* -******************************************************************************** -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_mcwdt.h" - -#if defined(__cplusplus) -extern "C" { -#endif - - -/******************************************************************************* -* Function Name: Cy_MCWDT_Init -****************************************************************************//** -* -* Initializes the MCWDT block. -* -* \param base -* The base pointer to a structure that describes the registers. -* -* \param config -* The pointer to a structure that contains component configuration data. -* -* \return cy_en_mcwdt_status_t -* *base checking result. If the pointer is NULL, returns error. -* -* \note -* This API should not be called when the counters are running. Prior to calling -* this API the counter should be disabled. -* -*******************************************************************************/ -cy_en_mcwdt_status_t Cy_MCWDT_Init(MCWDT_STRUCT_Type *base, cy_stc_mcwdt_config_t const *config) -{ - cy_en_mcwdt_status_t ret = CY_MCWDT_BAD_PARAM; - - if ((base != NULL) && (config != NULL)) - { - base->MCWDT_MATCH = _VAL2FLD(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH1, config->c1Match) | - _VAL2FLD(MCWDT_STRUCT_MCWDT_MATCH_WDT_MATCH0, config->c0Match); - - base->MCWDT_CONFIG = _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_BITS2, config->c2ToggleBit) | - _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_MODE2, config->c2Mode) | - _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR0, config->c0ClearOnMatch) | - _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_CLEAR1, config->c1ClearOnMatch) | - (config->c1c2Cascade ? MCWDT_STRUCT_MCWDT_CONFIG_WDT_CASCADE1_2_Msk : 0UL) | - _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_MODE1, config->c1Mode) | - (config->c0c1Cascade ? MCWDT_STRUCT_MCWDT_CONFIG_WDT_CASCADE0_1_Msk : 0UL) | - _VAL2FLD(MCWDT_STRUCT_MCWDT_CONFIG_WDT_MODE0, config->c0Mode); - - ret = CY_MCWDT_SUCCESS; - } - - return (ret); -} - - -/******************************************************************************* -* Function Name: Cy_MCWDT_DeInit -****************************************************************************//** -* -* De-initializes the MCWDT block, returns register values to their default state. -* -* \param base -* The base pointer to a structure that describes the registers. -* -* \note -* This API should not be called when the counters are running. Prior to calling -* this API the counter should be disabled. -* -*******************************************************************************/ -void Cy_MCWDT_DeInit(MCWDT_STRUCT_Type *base) -{ - Cy_MCWDT_Unlock(base); - - base->MCWDT_CNTLOW = 0UL; - base->MCWDT_CNTHIGH = 0UL; - base->MCWDT_MATCH = 0UL; - base->MCWDT_CONFIG = 0UL; - base->MCWDT_CTL = 0UL; - base->MCWDT_INTR = 0UL; - base->MCWDT_INTR_SET = 0UL; - base->MCWDT_INTR_MASK = 0UL; -} - - -#if defined(__cplusplus) -} -#endif - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/profile/cy_profile.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/profile/cy_profile.h deleted file mode 100644 index bb942ace9b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/profile/cy_profile.h +++ /dev/null @@ -1,376 +0,0 @@ -/***************************************************************************//** -* \file cy_profile.h -* \version 1.0 -* -* Provides an API declaration of the profiler driver. -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -/** -* \defgroup group_energy_profiler Energy Profiler (Profile) -* \{ -* -* The profiler driver contains an API for configuring and using the -* profiler hardware. The profiler enables measurement of the relative -* amount of energy consumed by particular peripherals. Traditional -* profilers correlate energy consumption to the program counter, which helps you -* understand when power is consumed. The profiler provides additional insight into the -* device so you can identify an asynchronous activity that causes energy -* consumption. In other words, the profiler helps you understand where power is consumed. -* -* The profiler does not measure or report actual energy consumption. It measures either -* clock cycles or the number of events that have occurred in the profiling window. -* To derive relative energy consumption for each source, you can multiply the -* absolute count (clock cycles or events) for that source by a coefficient. -* -* Many of the sources available for monitoring are asynchronous operations where -* the cause of energy consumption may be difficult to identify using external hardware. -* -* \section group_profile_configuration Configuration Considerations -* -* There is no PSoC Creator component for this peripheral. To use the profiler you -* include the header file and configure the counters by writing code and calling -* the Profiler API functions. -* -* At the highest level, you perform these tasks: -* - Initialize the profiling block -* - Set up the profiling interrupt -* - Configure, initialize, and enable the counters -* - Start and stop profiling -* - Get the results -* - Exit gracefully -* -* The profiler manages a set of counters. For each counter you use, you assign the source -* you want monitored, a reference clock, and a coefficient used to calculate results. -* You can also get the raw count for any counter. -* -* Each counter is a 32-bit register that counts either a number of clock cycles, -* or a number of events. It is possible to overflow the 32-bit register. The -* firmware implements a 32-bit overflow counter. Combined with the 32-bit register, -* this gives you a 64-bit counter for each monitored source. The profiler generates -* an interrupt when an overflow occurs. You must configure the interrupt handler -* using Cy_SysInt_Init(). You can use Cy_Profile_ISR() as the interrupt handler. It -* increments the overflow counter for each profiling counter that is in use. -* -* When finished profiling, disable the profiler -- do the following: -* - Stop profiling. See \ref Cy_Profile_StopProfiling(). -* - Clear all profiling configuration. See \ref Cy_Profile_ClearConfiguration(). -* - Disable the profiling interrupt. -* - Disable the profiler. See \ref Cy_Profile_DeInit(). -* -* See notes on individual function definitions. -* -* \section group_profile_more_information More Information -* -* See the profiler chapter of the device technical reference manual (TRM). -* -* \section group_profile_MISRA MISRA-C Compliance -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
MISRA RuleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
12.4RRight hand operand of '&&' or '||' is an expression with possible side effects.Function-like macros are used to achieve more efficient code.
16.7AA pointer parameter can be of type 'pointer to const'.The pointer is cast for comparison purposes and thus can't be a const.
-* -* \section group_profile_changelog Changelog -* -* -* -* -* -* -* -*
VersionChangesReason for Change
1.0Initial version
-* -* \defgroup group_profile_macros Macros -* \defgroup group_profile_functions Functions -* \{ -* \defgroup group_profile_functions_interrupt Interrupt Functions -* \defgroup group_profile_functions_general General Functions -* \defgroup group_profile_functions_counter Counter Functions -* \defgroup group_profile_functions_calculation Calculation Functions -* \} -* \defgroup group_profile_data_structures Data Structures -* \defgroup group_profile_enums Enumerated Types -*/ - -#if !defined(CY_PROFILE_H) -#define CY_PROFILE_H - -#include "cy_device_headers.h" -#include "syslib/cy_syslib.h" -#include - -#ifndef CY_IP_MXPROFILE - #error "The PROFILE driver is not supported on this device" -#endif - -#if defined(__cplusplus) -extern "C" { -#endif /* __cplusplus */ - -/** \addtogroup group_profile_macros -* \{ -*/ - -/** Driver major version */ -#define CY_PROFILE_DRV_VERSION_MAJOR 1 - -/** Driver minor version */ -#define CY_PROFILE_DRV_VERSION_MINOR 0 - -/** Profile driver identifier */ -#define CY_PROFILE_ID CY_PDL_DRV_ID(0x1EU) - -/** Start profiling command for the CMD register */ -#define CY_PROFILE_START_TR 1UL - -/** Stop profiling command for the CMD register */ -#define CY_PROFILE_STOP_TR 2UL - -/** Command to clear all counter registers to 0 */ -#define CY_PROFILE_CLR_ALL_CNT 0x100UL - -/** \} group_profile_macros */ - -/** -* \addtogroup group_profile_enums -* \{ -*/ - -/** -* The possible values for CTR register, REF_CLK_SEL bitfield. See the -* technical reference manual (TRM) for reference clock considerations. -*/ -typedef enum -{ - CY_PROFILE_CLK_TIMER = 0, /**< See SRSS register CLK_TIMER_CTL.TIMER_SEL */ - CY_PROFILE_CLK_IMO = 1, /**< Internal main oscillator */ - CY_PROFILE_CLK_ECO = 2, /**< External crystal oscillator */ - CY_PROFILE_CLK_LF = 3, /**< See SRSS register CLK_SELECT.LFCLK_SEL */ - CY_PROFILE_CLK_HF = 4, /**< See SRSS registers CLK_ROOT_SELECT[0].ROOT_MUX and CLK_ROOT_SELECT[0].ROOT_DIV */ - CY_PROFILE_CLK_PERI = 5, /**< See CPUSS register CM0_CLOCK_CTL.PERI_INT_DIV */ -} cy_en_profile_ref_clk_t; - -/** -* The possible values for CTR register, CNT_DURATION bitfield. See the -* technical reference manual (TRM) event / duration considerations. -*/ -typedef enum -{ - CY_PROFILE_EVENT = 0, /**< count module events */ - CY_PROFILE_DURATION = 1, /**< count duration in clock cycles */ -} cy_en_profile_duration_t; - -/** Profiler status codes */ -typedef enum -{ - /** Operation completed successfully */ - CY_PROFILE_SUCCESS = 0x00U, - - /** One or more of input parameters are invalid */ - CY_PROFILE_BAD_PARAM = CY_PROFILE_ID | CY_PDL_STATUS_ERROR | 1UL - - } cy_en_profile_status_t; - - /** \} group_profile_enums */ - -/** -* \addtogroup group_profile_data_structures -* \{ -*/ - -/** -* Profiler counter control register structure. For each counter, holds the CTL register fields. -*/ -typedef struct -{ - cy_en_profile_duration_t cntDuration; /**< 0 = events are monitored; 1 = duration is monitored */ - cy_en_profile_ref_clk_t refClkSel; /**< The reference clock used by this counter; 3 bits */ - en_ep_mon_sel_t monSel; /**< The monitor signal to be observed by this counter; # bits = PROFILE_CNT_STRUCT_PRFL_MONITOR_NR_LOG2 */ -} cy_stc_profile_ctr_ctl_t; - -/** -* Structure holding all information for an profiler counter. -*/ -typedef struct -{ - uint8_t ctrNum; /**< hardware counter # */ - uint8_t used; /**< used 0 = available, 1 = being used */ - cy_stc_profile_ctr_ctl_t ctlRegVals; /**< counter CTL reg bitfield values */ - PROFILE_CNT_STRUCT_Type * cntAddr; /**< base MMIO addr of counter registers */ - uint32_t ctlReg; /**< also includes enabled/disabled status */ - uint32_t cntReg; /**< current counter value */ - uint32_t overflow; /**< this register and cntReg form a 64-bit counter value */ - uint32_t weight; /**< counter weighting factor */ -} cy_stc_profile_ctr_t; - -/** -* Pointer to structure holding all information for an profiler counter. -*/ -typedef cy_stc_profile_ctr_t * cy_stc_profile_ctr_ptr_t; -/** \} group_profile_data_structures */ - -/** -* \addtogroup group_profile_functions -* \{ -*/ - -/** -* \addtogroup group_profile_functions_interrupt -* \{ -*/ -/* ========================================================================== */ -/* ==================== INTERRUPT FUNCTION SECTION ==================== */ -/* ========================================================================== */ -void Cy_Profile_ISR(void); -/** \} group_profile_functions_interrupt */ - -/** -* \addtogroup group_profile_functions_general -* \{ -*/ -__STATIC_INLINE void Cy_Profile_Init(void); -__STATIC_INLINE void Cy_Profile_DeInit(void); -void Cy_Profile_StartProfiling(void); -__STATIC_INLINE void Cy_Profile_DeInit(void); -__STATIC_INLINE void Cy_Profile_StopProfiling(void); -__STATIC_INLINE uint32_t Cy_Profile_IsProfiling(void); - -/* ========================================================================== */ -/* =============== GENERAL PROFILER FUNCTIONS SECTION ================= */ -/* ========================================================================== */ -/******************************************************************************* -* Function Name: Cy_Profile_Init -****************************************************************************//** -* -* Turns on the profiler for profiling. It must be called once when energy profiling is -* desired. This does not start a profiling session. Use Cy_Profile_StartProfiling() -* to start a profiling session. -* -* \note Before calling this function, the user must configure the profiler interrupt -* so that \ref Cy_Profile_ISR() is executed. -*******************************************************************************/ -__STATIC_INLINE void Cy_Profile_Init(void) -{ - PROFILE->CTL = _VAL2FLD(PROFILE_CTL_ENABLED, 1UL/*enabled */) | - _VAL2FLD(PROFILE_CTL_WIN_MODE, 0UL/*start/stop mode*/); - PROFILE->INTR_MASK = 0UL; /* clear all counter interrupt mask bits */ -} - -/******************************************************************************* -* Function Name: Cy_Profile_DeInit -****************************************************************************//** -* -* Turns off the profiler. It should be called when energy profiling is no longer -* desired. -* -* \note When calling this function, the user should consider also deallocating -* the profiler interrupt. -*******************************************************************************/ -__STATIC_INLINE void Cy_Profile_DeInit(void) -{ - PROFILE->CTL = _VAL2FLD(PROFILE_CTL_ENABLED, 0UL/*disabled */); - PROFILE->INTR_MASK = 0UL; /* clear all counter interrupt mask bits */ -} - -/******************************************************************************* -* Function Name: Cy_Profile_StopProfiling -****************************************************************************//** -* -* Stops profiling. -* -* \note When calling this function, the user should also disable the profiler -* interrupt. -*******************************************************************************/ -__STATIC_INLINE void Cy_Profile_StopProfiling(void) -{ - PROFILE->CMD = CY_PROFILE_STOP_TR; -} - -/******************************************************************************* -* Function Name: Cy_Profile_IsProfiling -****************************************************************************//** -* -* Reports whether or not profiling is active. -* -* \return 0 = profiling is not active; 1 = profiling is active -* -*******************************************************************************/ -__STATIC_INLINE uint32_t Cy_Profile_IsProfiling(void) -{ - return _FLD2VAL(PROFILE_STATUS_WIN_ACTIVE, PROFILE->STATUS); -} -/** \} group_profile_functions_general */ - -/** -* \addtogroup group_profile_functions_counter -* \{ -*/ -void Cy_Profile_ClearConfiguration(void); -__STATIC_INLINE void Cy_Profile_ClearCounters(void); -cy_stc_profile_ctr_ptr_t Cy_Profile_ConfigureCounter(en_ep_mon_sel_t monitor, cy_en_profile_duration_t duration, cy_en_profile_ref_clk_t refClk, uint32_t weight); -cy_en_profile_status_t Cy_Profile_FreeCounter(cy_stc_profile_ctr_ptr_t ctrAddr); -cy_en_profile_status_t Cy_Profile_EnableCounter(cy_stc_profile_ctr_ptr_t ctrAddr); -cy_en_profile_status_t Cy_Profile_DisableCounter(cy_stc_profile_ctr_ptr_t ctrAddr); - -/* ========================================================================== */ -/* =================== COUNTER FUNCTIONS SECTION ====================== */ -/* ========================================================================== */ -/******************************************************************************* -* Function Name: Cy_Profile_ClearCounters -****************************************************************************//** -* -* Clears all hardware counters to 0. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_Profile_ClearCounters(void) -{ - PROFILE->CMD = CY_PROFILE_CLR_ALL_CNT; -} -/** \} group_profile_functions_counter */ - -/** -* \addtogroup group_profile_functions_calculation -* \{ -*/ -/* ========================================================================== */ -/* ================== CALCULATION FUNCTIONS SECTION =================== */ -/* ========================================================================== */ -cy_en_profile_status_t Cy_Profile_GetRawCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result); -cy_en_profile_status_t Cy_Profile_GetWeightedCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result); -uint64_t Cy_Profile_GetSumWeightedCounts(cy_stc_profile_ctr_ptr_t ptrsArray[], uint32_t numCounters); -/** \} group_profile_functions_calculation */ - -/** \} group_profile_functions */ - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ - -#endif /* CY_PROFILE_H */ - -/** \} group_profile */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/prot/cy_prot.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/prot/cy_prot.h deleted file mode 100644 index 0e1bc23c62..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/prot/cy_prot.h +++ /dev/null @@ -1,579 +0,0 @@ -/***************************************************************************//** -* \file cy_prot.h -* \version 1.0 -* -* \brief -* Provides an API declaration of the Protection Unit driver -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -/** -* \defgroup group_prot Protection Unit (Prot) -* \{ -* -* The Protection Unit driver provides an API to configure the Memory Protection -* Units (MPU), Shared Memory Protection Units (SMPU), and Peripheral Protection -* Units (PPU). These are separate from the ARM Core MPUs and provide additional -* mechanisms for securing resource accesses. The Protection units address the -* following concerns in an embedded design: -* - Security requirements. This includes the prevention of malicious attacks -* to access secure memory or peripherals. -* - Safety requirements. This includes detection of accidental (non-malicious) -* SW errors and random HW errors. It is important to enable failure analysis -* to investigate the root cause of a safety violation. -* -* \n -* Memory Protection -* -* Memory protection is provided by MPUs and SMPUs and allows control of -* memory accesses by bus masters (e.g., CM0+, CM4, Crypto): -* - MPUs are used to distinguish user and privileged accesses from a single bus -* master such as task switching in an OS/kernel. For ARM core MPUs, the -* assigned Cypress MPUs for those cores provide additional functionality -* such as protection contexts (PC) and security attributes. -* - SMPUs are used to distinguish memory accesses between bus masters. This is -* achieved by using protection contexts and secure-/non-secure attributes. -* -* \n -* Peripheral Protection -* -* Peripheral protection is provided by PPUs and allows control of peripheral -* register accesses by bus masters. Four types of PPUs are available. -* - Programmable (PROG) PPUs are used to protect any peripheral memory region -* in a device from invalid bus master accesses. It is the most versatile -* type of peripheral protection unit. -* - Fixed Group (GR) PPUs are used to protect an entire peripheral MMIO group -* from invalid bus master accesses. The MMIO grouping information and which -* resource belongs to which group is device specific and can be obtained -* from the device technical reference manual (TRM). -* - Fixed Region (RG) PPUs are used to protect an entire peripheral slave -* instance from invalid bus master accesses. For example, TCPWM0, TCPWM1, -* SCB0, and SCB1, etc. -* - Fixed Slave (SL) PPUs are used to protect specified regions of peripheral -* instances. For example, individual DW channel structs, SMPU structs, and -* IPC structs, etc. -* -* \n -* Driver Usage -* -* Each protection unit is distinguished by its type (e.g. -* PROT_MPU_MPU_STRUCT_Type). The list of supported protection units can be -* obtained from the device header file. Choose a protection unit of interest, -* and call its corresponding Cy_Prot_ConfigStruct() function with its -* software protection unit configuration structure populated. Then enable the -* protection unit by calling the Cy_Prot_EnableStruct() function. -* -* Each bus master can be configured to allow/disallow certain types of accesses -* by calling the Cy_Prot_ConfigBusMaster() function. For example, CM0+ core -* is a bus master. By configuring it to allow only protection contexts (PC) -* 2 and 3, the bus master will be able to set its protection context only to -* 2 or 3. In a thread execution, the CM0+ core can set its protection context -* to 2 by calling Cy_Prot_SetActivePC() and access all regions of memory that -* allow PC=2. A fault will be triggered if a resource is protected with different -* protection settings. -* -* \section group_prot_configuration Configuration Considerations -* -* With the exception of MPUs, Protection structures are implemented in -* hardware as master and slave pairs. The master protection structure protects -* the slave protection structure. The slave protection structure protects the -* memory region that is to be protected. -* For example, a slave protection structure is configured to allow protection -* contexts 3 and 4 to access a set of peripheral registers. The corresponding -* master protection structure can then be used to protect the slave structure -* configuration and allow only protection context 1 to make modifications. -* Any bus master attempting to change the slave protection structure must then -* have a protection context 1. Otherwise an access fault will occur. -* -* \section group_prot_more_information More Information -* -* Refer to Technical Reference Manual (TRM) and the device datasheet. -* -* \section group_prot_MISRA MISRA-C Compliance] -* -* -* -* -* -* -* -* -* -* -* -* -* -*
MISRA ruleRule Class (Required/Advisory)Rule DescriptionDescription of Deviation(s)
11.5RDangerous pointer cast results in loss of volatile qualification.Required to access bus master control register
-* -* \section group_prot_changelog Changelog -* -* -* -* -* -* -* -*
VersionChangesReason for Change
1.0Initial version
-* -* \defgroup group_prot_macros Macros -* \defgroup group_prot_functions Functions -* \{ -* \defgroup group_prot_functions_busmaster Bus Master and PC Functions -* \defgroup group_prot_functions_mpu MPU Functions -* \defgroup group_prot_functions_smpu SMPU Functions -* \defgroup group_prot_functions_ppu_prog PPU Programmable (PROG) Functions -* \defgroup group_prot_functions_ppu_gr PPU Group (GR) Functions -* \defgroup group_prot_functions_ppu_sl PPU Slave (SL) Functions -* \defgroup group_prot_functions_ppu_rg PPU Region (RG) Functions -* \} -* \defgroup group_prot_data_structures Data structures -* \defgroup group_prot_enums Enumerated types -*/ - -#if !defined(__CY_PROT_H__) -#define __CY_PROT_H__ - -#include -#include "syslib/cy_syslib.h" -#include "cy_device_headers.h" - -#if defined(__cplusplus) -extern "C" { -#endif - -/** \addtogroup group_prot_macros -* \{ -*/ - -/** Driver major version */ -#define CY_PROT_DRV_VERSION_MAJOR 1 - -/** Driver minor version */ -#define CY_PROT_DRV_VERSION_MINOR 0 - -/** Prot driver ID */ -#define CY_PROT_ID CY_PDL_DRV_ID(0x30u) - -/** \} group_prot_macros */ - -/** -* \addtogroup group_prot_enums -* \{ -*/ - -/** -* Prot Driver error codes -*/ -typedef enum -{ - CY_PROT_SUCCESS = 0x00u, /**< Returned successful */ - CY_PROT_BAD_PARAM = CY_PROT_ID | CY_PDL_STATUS_ERROR | 0x01u, /**< Bad parameter was passed */ - CY_PROT_FAILURE = CY_PROT_ID | CY_PDL_STATUS_ERROR | 0x03u /**< The resource is locked */ -} cy_en_prot_status_t; - -/** -* User/Privileged permission -*/ -typedef enum -{ - CY_PROT_PERM_DISABLED = 0x00u, /**< Read, Write and Execute disabled */ - CY_PROT_PERM_R = 0x01u, /**< Read enabled */ - CY_PROT_PERM_W = 0x02u, /**< Write enabled */ - CY_PROT_PERM_RW = 0x03u, /**< Read and Write enabled */ - CY_PROT_PERM_X = 0x04u, /**< Execute enabled */ - CY_PROT_PERM_RX = 0x05u, /**< Read and Execute enabled */ - CY_PROT_PERM_WX = 0x06u, /**< Write and Execute enabled */ - CY_PROT_PERM_RWX = 0x07u /**< Read, Write and Execute enabled */ -}cy_en_prot_perm_t; - -/** -* Memory region size -*/ -typedef enum -{ - CY_PROT_SIZE_256B = 7u, /**< 256 bytes */ - CY_PROT_SIZE_512B = 8u, /**< 512 bytes */ - CY_PROT_SIZE_1KB = 9u, /**< 1 Kilobyte */ - CY_PROT_SIZE_2KB = 10u, /**< 2 Kilobytes */ - CY_PROT_SIZE_4KB = 11u, /**< 4 Kilobytes */ - CY_PROT_SIZE_8KB = 12u, /**< 8 Kilobytes */ - CY_PROT_SIZE_16KB = 13u, /**< 16 Kilobytes */ - CY_PROT_SIZE_32KB = 14u, /**< 32 Kilobytes */ - CY_PROT_SIZE_64KB = 15u, /**< 64 Kilobytes */ - CY_PROT_SIZE_128KB = 16u, /**< 128 Kilobytes */ - CY_PROT_SIZE_256KB = 17u, /**< 256 Kilobytes */ - CY_PROT_SIZE_512KB = 18u, /**< 512 Kilobytes */ - CY_PROT_SIZE_1MB = 19u, /**< 1 Megabyte */ - CY_PROT_SIZE_2MB = 20u, /**< 2 Megabytes */ - CY_PROT_SIZE_4MB = 21u, /**< 4 Megabytes */ - CY_PROT_SIZE_8MB = 22u, /**< 8 Megabytes */ - CY_PROT_SIZE_16MB = 23u, /**< 16 Megabytes */ - CY_PROT_SIZE_32MB = 24u, /**< 32 Megabytes */ - CY_PROT_SIZE_64MB = 25u, /**< 64 Megabytes */ - CY_PROT_SIZE_128MB = 26u, /**< 128 Megabytes */ - CY_PROT_SIZE_256MB = 27u, /**< 256 Megabytes */ - CY_PROT_SIZE_512MB = 28u, /**< 512 Megabytes */ - CY_PROT_SIZE_1GB = 29u, /**< 1 Gigabyte */ - CY_PROT_SIZE_2GB = 30u, /**< 2 Gigabytes */ - CY_PROT_SIZE_4GB = 31u /**< 4 Gigabytes */ -}cy_en_prot_size_t; - -/** -* Protection Context (PC) -*/ -enum cy_en_prot_pc_t -{ - CY_PROT_PC1 = 1u, /**< PC = 1 */ - CY_PROT_PC2 = 2u, /**< PC = 2 */ - CY_PROT_PC3 = 3u, /**< PC = 3 */ - CY_PROT_PC4 = 4u, /**< PC = 4 */ - CY_PROT_PC5 = 5u, /**< PC = 5 */ - CY_PROT_PC6 = 6u, /**< PC = 6 */ - CY_PROT_PC7 = 7u, /**< PC = 7 */ - CY_PROT_PC8 = 8u, /**< PC = 8 */ - CY_PROT_PC9 = 9u, /**< PC = 9 */ - CY_PROT_PC10 = 10u, /**< PC = 10 */ - CY_PROT_PC11 = 11u, /**< PC = 11 */ - CY_PROT_PC12 = 12u, /**< PC = 12 */ - CY_PROT_PC13 = 13u, /**< PC = 13 */ - CY_PROT_PC14 = 14u, /**< PC = 14 */ - CY_PROT_PC15 = 15u /**< PC = 15 */ -}; - -/** -* Subregion disable (0-7) -*/ -enum cy_en_prot_subreg_t -{ - CY_PROT_SUBREGION_DIS0 = 0x01u, /**< Disable subregion 0 */ - CY_PROT_SUBREGION_DIS1 = 0x02u, /**< Disable subregion 1 */ - CY_PROT_SUBREGION_DIS2 = 0x04u, /**< Disable subregion 2 */ - CY_PROT_SUBREGION_DIS3 = 0x08u, /**< Disable subregion 3 */ - CY_PROT_SUBREGION_DIS4 = 0x10u, /**< Disable subregion 4 */ - CY_PROT_SUBREGION_DIS5 = 0x20u, /**< Disable subregion 5 */ - CY_PROT_SUBREGION_DIS6 = 0x40u, /**< Disable subregion 6 */ - CY_PROT_SUBREGION_DIS7 = 0x80u /**< Disable subregion 7 */ -}; - -/** -* Protection context mask (PC_MASK) -*/ -enum cy_en_prot_pcmask_t -{ - CY_PROT_PCMASK1 = 0x0001u, /**< Mask to allow PC = 1 */ - CY_PROT_PCMASK2 = 0x0002u, /**< Mask to allow PC = 2 */ - CY_PROT_PCMASK3 = 0x0004u, /**< Mask to allow PC = 3 */ - CY_PROT_PCMASK4 = 0x0008u, /**< Mask to allow PC = 4 */ - CY_PROT_PCMASK5 = 0x0010u, /**< Mask to allow PC = 5 */ - CY_PROT_PCMASK6 = 0x0020u, /**< Mask to allow PC = 6 */ - CY_PROT_PCMASK7 = 0x0040u, /**< Mask to allow PC = 7 */ - CY_PROT_PCMASK8 = 0x0080u, /**< Mask to allow PC = 8 */ - CY_PROT_PCMASK9 = 0x0100u, /**< Mask to allow PC = 9 */ - CY_PROT_PCMASK10 = 0x0200u, /**< Mask to allow PC = 10 */ - CY_PROT_PCMASK11 = 0x0400u, /**< Mask to allow PC = 11 */ - CY_PROT_PCMASK12 = 0x0800u, /**< Mask to allow PC = 12 */ - CY_PROT_PCMASK13 = 0x1000u, /**< Mask to allow PC = 13 */ - CY_PROT_PCMASK14 = 0x2000u, /**< Mask to allow PC = 14 */ - CY_PROT_PCMASK15 = 0x4000u /**< Mask to allow PC = 15 */ -}; - -/** \} group_prot_enums */ - - -/*************************************** -* Constants -***************************************/ - -/** \cond INTERNAL */ - -/* Helper function for finding max */ -#define CY_PROT_MAX(x,y) (((x)>(y))?(x):(y)) - -/* General Masks and shifts */ -#define CY_PROT_MSX_CTL_SHIFT (0x02UL) /**< Shift for MSx_CTL register */ -#define CY_PROT_STRUCT_ENABLE (0x01UL) /**< Enable protection unit struct */ -#define CY_PROT_ADDR_SHIFT (8UL) /**< Address shift for MPU, SMPU and PROG PPU structs */ - -/* Permission masks and shifts */ -#define CY_PROT_ATT_PERMISSION_MASK (0x07UL) /**< Protection Unit attribute permission mask */ -#define CY_PROT_ATT_USER_PERMISSION_SHIFT (0x00UL) /**< Protection Unit user attribute permission shift */ -#define CY_PROT_ATT_PRIV_PERMISSION_SHIFT (0x03UL) /**< Protection Unit priliged attribute permission shift */ - -/* Maximum Master Protection Context */ -#define CY_PROT_MS_PC_NR_MAX CY_PROT_MAX(CPUSS_PROT_SMPU_MS0_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS1_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS2_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS3_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS4_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS5_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS6_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS7_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS8_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS9_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS10_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS11_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS12_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS13_PC_NR_MINUS1, \ - CY_PROT_MAX(CPUSS_PROT_SMPU_MS14_PC_NR_MINUS1, \ - CPUSS_PROT_SMPU_MS15_PC_NR_MINUS1))))))))))))))) - -/* Protection Context limit masks */ -#define CY_PROT_MPU_PC_LIMIT_MASK (0xFFFFFFFFUL << CY_PROT_MS_PC_NR_MAX) -#define CY_PROT_SMPU_PC_LIMIT_MASK (0xFFFFFFFFUL << CPUSS_SMPU_STRUCT_PC_NR_MINUS1) -#define CY_PROT_PPU_PROG_PC_LIMIT_MASK (0xFFFFFFFFUL << PERI_PPU_PROG_STRUCT_PC_NR_MINUS1) -#define CY_PROT_PPU_FIXED_PC_LIMIT_MASK (0xFFFFFFFFUL << PERI_PPU_FIXED_STRUCT_PC_NR_MINUS1) - -/* Parameter validation masks to check for read-only values */ -#define CY_PROT_SMPU_ATT0_MASK ((uint32_t)~(PROT_SMPU_SMPU_STRUCT_ATT0_PC_MASK_0_Msk)) -#define CY_PROT_SMPU_ATT1_MASK ((uint32_t)~(PROT_SMPU_SMPU_STRUCT_ATT1_UR_Msk \ - | PROT_SMPU_SMPU_STRUCT_ATT1_UX_Msk \ - | PROT_SMPU_SMPU_STRUCT_ATT1_PR_Msk \ - | PROT_SMPU_SMPU_STRUCT_ATT1_PX_Msk \ - | PROT_SMPU_SMPU_STRUCT_ATT1_PC_MASK_0_Msk \ - | PROT_SMPU_SMPU_STRUCT_ATT1_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_PROG_ATT0_MASK ((uint32_t)~(PERI_PPU_GR_ATT1_UX_Msk \ - | PERI_PPU_GR_ATT1_PX_Msk \ - |PERI_PPU_PR_ATT0_PC_MASK_0_Msk \ - )) -#define CY_PROT_PPU_PROG_ATT1_MASK ((uint32_t)~(PERI_PPU_PR_ATT1_UR_Msk \ - | PERI_PPU_PR_ATT1_UX_Msk \ - | PERI_PPU_PR_ATT1_PR_Msk \ - | PERI_PPU_PR_ATT1_PX_Msk \ - | PERI_PPU_PR_ATT1_PC_MASK_0_Msk \ - | PERI_PPU_PR_ATT1_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_GR_ATT0_MASK ((uint32_t)~(PERI_PPU_GR_ATT0_UX_Msk \ - | PERI_PPU_GR_ATT0_PX_Msk \ - | PERI_PPU_GR_ATT0_PC_MASK_0_Msk \ - | PERI_PPU_GR_ATT0_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_GR_ATT1_MASK ((uint32_t)~(PERI_PPU_GR_ATT1_UR_Msk \ - | PERI_PPU_GR_ATT1_UX_Msk \ - | PERI_PPU_GR_ATT1_PR_Msk \ - | PERI_PPU_GR_ATT1_PX_Msk \ - | PERI_PPU_GR_ATT1_PC_MASK_0_Msk \ - | PERI_PPU_GR_ATT1_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_SL_ATT0_MASK ((uint32_t)~(PERI_GR_PPU_SL_ATT0_UX_Msk \ - | PERI_GR_PPU_SL_ATT0_PX_Msk \ - | PERI_GR_PPU_SL_ATT0_PC_MASK_0_Msk \ - | PERI_GR_PPU_SL_ATT0_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_SL_ATT1_MASK ((uint32_t)~(PERI_GR_PPU_SL_ATT1_UR_Msk \ - | PERI_GR_PPU_SL_ATT1_UX_Msk \ - | PERI_GR_PPU_SL_ATT1_PR_Msk \ - | PERI_GR_PPU_SL_ATT1_PX_Msk \ - | PERI_GR_PPU_SL_ATT1_PC_MASK_0_Msk \ - | PERI_GR_PPU_SL_ATT1_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_RG_ATT0_MASK ((uint32_t)~(PERI_GR_PPU_RG_ATT0_UX_Msk \ - | PERI_GR_PPU_RG_ATT0_PX_Msk \ - | PERI_GR_PPU_RG_ATT0_PC_MASK_0_Msk \ - | PERI_GR_PPU_RG_ATT0_REGION_SIZE_Msk \ - )) -#define CY_PROT_PPU_RG_ATT1_MASK ((uint32_t)~(PERI_GR_PPU_RG_ATT1_UR_Msk \ - | PERI_GR_PPU_RG_ATT1_UX_Msk \ - | PERI_GR_PPU_RG_ATT1_PR_Msk \ - | PERI_GR_PPU_RG_ATT1_PX_Msk \ - | PERI_GR_PPU_RG_ATT1_PC_MASK_0_Msk \ - | PERI_GR_PPU_RG_ATT1_REGION_SIZE_Msk \ - )) - -/** \endcond */ - - -/*************************************** -* Configuration Structures -***************************************/ - -/** -* \addtogroup group_prot_data_structures -* \{ -*/ - -/** Configuration structure for MPU Struct initialization */ -typedef struct -{ - uint32_t* address; /**< Base address of the memory region */ - cy_en_prot_size_t regionSize; /**< Size of the memory region */ - uint8_t subregions; /**< Mask of the 8 subregions to disable */ - cy_en_prot_perm_t userPermission; /**< User permissions for the region */ - cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ - bool secure; /**< Non Secure = 0, Secure = 1 */ -} cy_stc_mpu_cfg_t; - -/** Configuration structure for SMPU struct initialization */ -typedef struct -{ - uint32_t* address; /**< Base address of the memory region (Only applicable to slave) */ - cy_en_prot_size_t regionSize; /**< Size of the memory region (Only applicable to slave) */ - uint8_t subregions; /**< Mask of the 8 subregions to disable (Only applicable to slave) */ - cy_en_prot_perm_t userPermission; /**< User permissions for the region */ - cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ - bool secure; /**< Non Secure = 0, Secure = 1 */ - bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ - uint16_t pcMask; /**< Mask of allowed protection context(s) */ -} cy_stc_smpu_cfg_t; - -/** Configuration structure for Programmable (PROG) PPU (PPU_PR) struct initialization */ -typedef struct -{ - uint32_t* address; /**< Base address of the memory region (Only applicable to slave) */ - cy_en_prot_size_t regionSize; /**< Size of the memory region (Only applicable to slave) */ - uint8_t subregions; /**< Mask of the 8 subregions to disable (Only applicable to slave) */ - cy_en_prot_perm_t userPermission; /**< User permissions for the region */ - cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ - bool secure; /**< Non Secure = 0, Secure = 1 */ - bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ - uint16_t pcMask; /**< Mask of allowed protection context(s) */ -} cy_stc_ppu_prog_cfg_t; - -/** Configuration structure for Fixed Group (GR) PPU (PPU_GR) struct initialization */ -typedef struct -{ - cy_en_prot_perm_t userPermission; /**< User permissions for the region */ - cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ - bool secure; /**< Non Secure = 0, Secure = 1 */ - bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ - uint16_t pcMask; /**< Mask of allowed protection context(s) */ -} cy_stc_ppu_gr_cfg_t; - -/** Configuration structure for Fixed Slave (SL) PPU (PPU_SL) struct initialization */ -typedef struct -{ - cy_en_prot_perm_t userPermission; /**< User permissions for the region */ - cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ - bool secure; /**< Non Secure = 0, Secure = 1 */ - bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ - uint16_t pcMask; /**< Mask of allowed protection context(s) */ -} cy_stc_ppu_sl_cfg_t; - -/** Configuration structure for Fixed Region (RG) PPU (PPU_RG) struct initialization */ -typedef struct -{ - cy_en_prot_perm_t userPermission; /**< User permissions for the region */ - cy_en_prot_perm_t privPermission; /**< Privileged permissions for the region */ - bool secure; /**< Non Secure = 0, Secure = 1 */ - bool pcMatch; /**< Access evaluation = 0, Matching = 1 */ - uint16_t pcMask; /**< Mask of allowed protection context(s) */ -} cy_stc_ppu_rg_cfg_t; - -/** \} group_prot_data_structures */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** -* \addtogroup group_prot_functions -* \{ -*/ - -/** -* \addtogroup group_prot_functions_busmaster -* \{ -*/ - -cy_en_prot_status_t Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster, bool privileged, bool secure, uint32_t pcMask); -cy_en_prot_status_t Cy_Prot_SetActivePC(en_prot_master_t busMaster, uint32_t pc); -uint32_t Cy_Prot_GetActivePC(en_prot_master_t busMaster); - -/** \} group_prot_functions_busmaster */ - -/** -* \addtogroup group_prot_functions_mpu -* \{ -*/ - -cy_en_prot_status_t Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type* base, const cy_stc_mpu_cfg_t* config); -cy_en_prot_status_t Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base); -cy_en_prot_status_t Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base); - -/** \} group_prot_functions_mpu */ - -/** -* \addtogroup group_prot_functions_smpu -* \{ -*/ - -cy_en_prot_status_t Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config); -cy_en_prot_status_t Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config); -cy_en_prot_status_t Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base); -cy_en_prot_status_t Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base); -cy_en_prot_status_t Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base); -cy_en_prot_status_t Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base); - -/** \} group_prot_functions_smpu */ - -/** -* \addtogroup group_prot_functions_ppu_prog -* \{ -*/ - -cy_en_prot_status_t Cy_Prot_ConfigPpuProgMasterStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config); -cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config); -cy_en_prot_status_t Cy_Prot_EnablePpuProgMasterStruct(PERI_PPU_PR_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuProgMasterStruct(PERI_PPU_PR_Type* base); -cy_en_prot_status_t Cy_Prot_EnablePpuProgSlaveStruct(PERI_PPU_PR_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuProgSlaveStruct(PERI_PPU_PR_Type* base); - -/** \} group_prot_functions_ppu_prog */ - -/** -* \addtogroup group_prot_functions_ppu_gr -* \{ -*/ - -cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrMasterStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config); -cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config); -cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base); -cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base); - -/** \} group_prot_functions_ppu_gr */ - -/** -* \addtogroup group_prot_functions_ppu_sl -* \{ -*/ - -cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config); -cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config); -cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base); -cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base); - -/** \} group_prot_functions_ppu_sl */ - -/** -* \addtogroup group_prot_functions_ppu_rg -* \{ -*/ -cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config); -cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config); -cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base); -cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base); -cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base); - -/** \} group_prot_functions_ppu_rg */ - -/** \} group_prot_functions */ - -/** \} group_prot */ - -#if defined(__cplusplus) -} -#endif - -#endif /* CY_PROT_H */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syspm/cy_syspm.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syspm/cy_syspm.c deleted file mode 100644 index ccc873ea0e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syspm/cy_syspm.c +++ /dev/null @@ -1,2064 +0,0 @@ -/***************************************************************************//** -* \file cy_syspm.c -* \version 2.0 -* -* This driver provides the source code for the API for power management. -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ -#include "cy_syspm.h" - -static cy_stc_syspm_callback_t* callbackRoot = NULL; -static uint32_t curRegisteredCallbacks = 0U; - -#ifdef CY_IP_MXUDB - static void Cy_SaveRegisters(cy_stc_syspm_backup_regs_t *regs); - static void Cy_RestoreRegisters(cy_stc_syspm_backup_regs_t const *regs); -#endif /* CY_IP_MXUDB */ - -#if(0u != SRSS_SIMOBUCK_PRESENT) - static void Cy_SetVoltageBitForFlash(bool setBit); -#endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ - -static void Cy_EnterDeepSleep(cy_en_syspm_waitfor_t waitFor); - -#if(0u != CY_CPU_CORTEX_M4) - static bool wasEventSent = false; -#endif /* (0u != CY_CPU_CORTEX_M4) */ - - - -/******************************************************************************* -* Function Name: Cy_SysPm_ReadStatus -****************************************************************************//** -* -* Reads the status of the core(s). -* -* \return The current power mode. See \ref group_syspm_return_status. -* -*******************************************************************************/ -uint32_t Cy_SysPm_ReadStatus(void) -{ - uint32_t interruptState; - uint32_t pmStatus = 0U; - interruptState = Cy_SysLib_EnterCriticalSection(); - -#if(0u != CY_IP_M4CPUSS) - - /* Check whether CM4 is in the deep sleep mode*/ - if((0U != _FLD2VAL(CPUSS_CM4_STATUS_SLEEPING, CPUSS->CM4_STATUS)) && - (0U != _FLD2VAL(CPUSS_CM4_STATUS_SLEEPDEEP, CPUSS->CM4_STATUS))) - { - pmStatus |= CY_SYSPM_STATUS_CM4_DEEPSLEEP; - } - /* Check whether CM4 is in the sleep mode*/ - else if(0U != _FLD2VAL(CPUSS_CM4_STATUS_SLEEPING, CPUSS->CM4_STATUS)) - { - pmStatus |= CY_SYSPM_STATUS_CM4_SLEEP; - } - else - { - pmStatus |= CY_SYSPM_STATUS_CM4_ACTIVE; - } -#endif /* (0u != CY_IP_M4CPUSS) */ - - /* Check whether CM0p is in the deep sleep mode*/ - if((0U != _FLD2VAL(CPUSS_CM0_STATUS_SLEEPING, CPUSS->CM0_STATUS)) && - (0U != _FLD2VAL(CPUSS_CM0_STATUS_SLEEPDEEP, CPUSS->CM0_STATUS))) - { - pmStatus |= (uint32_t) CY_SYSPM_STATUS_CM0_DEEPSLEEP; - } - /* Check whether CM0p is in the sleep mode*/ - else if (0U != _FLD2VAL(CPUSS_CM0_STATUS_SLEEPING, CPUSS->CM0_STATUS)) - { - pmStatus |= CY_SYSPM_STATUS_CM0_SLEEP; - } - else - { - pmStatus |= CY_SYSPM_STATUS_CM0_ACTIVE; - } - - /* Check whether the device is in the low power mode by reading - * the Active Reference status - */ - if(0U != (_FLD2VAL(SRSS_PWR_CTL_ACT_REF_DIS, SRSS->PWR_CTL))) - { - pmStatus |= CY_SYSPM_STATUS_SYSTEM_LOWPOWER; - } - Cy_SysLib_ExitCriticalSection(interruptState); - - return(pmStatus); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_Sleep -****************************************************************************//** -* -* Sets a CPU core to the sleep mode. -* -* Puts the core into the Sleep power mode, if none of callback functions were -* registered. -* -* For more details about switching into the sleep power mode and debug, -* refer to the device TRM. -* -* If at least one callback function with the CY_SYSPM_SLEEP type was registered, -* the next algorithm is executed: -* Prior to entering the sleep mode, all callback functions of the CY_SYSPM_SLEEP -* type with the CY_SYSPM_CHECK_READY parameter are called allowing the driver -* to signal whether it is ready to enter the low power mode. If any of the -* callbacks of the CY_SYSPM_SLEEP type with the CY_SYSPM_CHECK_READY parameter -* returns CY_SYSPM_FAIL, the remaining callback of the CY_SYSPM_SLEEP type with -* the CY_SYSPM_CHECK_READY parameter calls are skipped. -* After CY_SYSPM_FAIL, all the CY_SYSPM_SLEEP callbacks with -* the CY_SYSPM_CHECK_FAIL parameter are executed. These are the callbacks -* of the CY_SYSPM_SLEEP type with the CY_SYSPM_CHECK_READY -* parameter that were previously executed before getting CY_SYSPM_FAIL. -* The sleep mode is not entered and the Cy_SysPm_Sleep() function returns -* CY_SYSPM_FAIL. -* -* If all of the callbacks of the CY_SYSPM_SLEEP type with the -* CY_SYSPM_CHECK_READY parameter calls return CY_SYSPM_SUCCESS, then all -* callbacks of the CY_SYSPM_SLEEP type with the CY_SYSPM_CHECK_FAIL parameters -* calls are skipped, and all callbacks of the CY_SYSPM_SLEEP type and -* CY_SYSPM_BEFORE_TRANSITION parameter calls are executed, allowing the -* peripherals to prepare for sleep. The sleep mode is then entered for the CPU. -* This is a CPU-centric power mode. It means that the CPU has entered the sleep -* mode and its main clock is removed. It is identical to Active from a -* peripheral point of view. Any enabled interrupt can cause a wakeup from the -* sleep mode. -* -* After a wakeup from the sleep, all of the registered callbacks of the -* CY_SYSPM_SLEEP type and with the CY_SYSPM_AFTER_TRANSITION parameter are -* executed to return the peripherals to Active operation. The Cy_SysPm_Sleep() -* function returns CY_SYSPM_SUCCESS. -* No callbacks of the CY_SYSPM_SLEEP type with the CY_SYSPM_BEFORE_TRANSITION -* parameter or callbacks of the CY_SYSPM_SLEEP type and -* CY_SYSPM_AFTER_TRANSITION parameter callbacks are executed if the sleep mode -* is not entered. -* -* \note The last callback which returned CY_SYSPM_FAIL is not executed with the -* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. -* -* The return values from executed callback functions with the -* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION -* modes are ignored. -* -* \ref cy_en_syspm_callback_mode_t, except the CY_SYSPM_CHECK_READY, are ignored -* -* \param waitFor Selects wait for action. See \ref cy_en_syspm_waitfor_t. -* -* \return -* Entered status, see \ref cy_en_syspm_status_t. -* -* \sideeffect -* This function clears the Event Register of CM4 core after wakeup from WFE. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_SysPm_Sleep(cy_en_syspm_waitfor_t waitFor) -{ - uint32_t interruptState; - cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; - - CY_ASSERT_L3(CY_SYSPM_IS_WAIT_FOR_VALID(waitFor)); - - /* Call registered callback functions with CY_SYSPM_CHECK_READY parameter */ - if(0U != curRegisteredCallbacks) - { - retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_CHECK_READY); - } - - /* The device (core) can switch into the sleep power mode only when - * all executed registered callback functions with the CY_SYSPM_CHECK_READY - * parameter returned CY_SYSPM_SUCCESS. - */ - if(retVal == CY_SYSPM_SUCCESS) - { - /* Call the registered callback functions with - * CY_SYSPM_BEFORE_TRANSITION parameter. The return value should be - * CY_SYSPM_SUCCESS. - */ - interruptState = Cy_SysLib_EnterCriticalSection(); - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_BEFORE_TRANSITION); - } - - /* The CPU enters the sleep power mode upon execution of WFI/WFE */ - SCB->SCR = _CLR_SET_FLD32U((SCB->SCR), SCB_SCR_SLEEPDEEP, 0U); - - if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) - { - __WFI(); - } - else - { - __WFE(); - - #if(0u != CY_CPU_CORTEX_M4) - - /* For the CM4 core the WFE instructions are called twice. - * The second WFE call clears the Event register of CM4 core. - * Cypress ID #279077. - */ - if(wasEventSent) - { - __WFE(); - } - - wasEventSent = true; - #endif /* (0u != CY_CPU_CORTEX_M4) */ - } - Cy_SysLib_ExitCriticalSection(interruptState); - - /* Call the registered callback functions with the - * CY_SYSPM_AFTER_TRANSITION parameter. The return value should be - * CY_SYSPM_SUCCESS. - */ - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_AFTER_TRANSITION); - } - } - else - { - /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to - * undo everything done in the callback with the CY_SYSPM_CHECK_READY - * parameter. The return value should be CY_SYSPM_SUCCESS. - */ - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_SLEEP, CY_SYSPM_CHECK_FAIL); - retVal = CY_SYSPM_FAIL; - } - return retVal; -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_DeepSleep -****************************************************************************//** -* -* Sets a CPU core to the deep sleep mode. -* -* Puts the core into the deep sleep power mode. Prior to entering the deep sleep -* mode, all callbacks of the CY_SYSPM_DEEPSLEEP type with the -* CY_SYSPM_CHECK_READY parameter registered callbacks are called, allowing the -* driver to signal whether it is ready to enter the power mode. If any -* CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_READY parameter call returns -* CY_SYSPM_FAIL, the remaining callback CY_SYSPM_DEEPSLEEP type with the -* CY_SYSPM_CHECK_READY parameter calls are skipped. After a CY_SYSPM_FAIL, all -* of the callbacks of the CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_FAIL -* parameter are executed that correspond to the callbacks with -* CY_SYSPM_DEEPSLEEP type with CY_SYSPM_CHECK_READY parameter calls that -* occurred up to the point of failure. -* The deep sleep mode is not entered and the Cy_SysPm_DeepSleep() function -* returns CY_SYSPM_FAIL. -* -* If all callbacks of the CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_READY -* parameter calls return CY_SYSPM_SUCCESS, then all callbacks of the -* CY_SYSPM_DEEPSLEEP type with the CY_SYSPM_CHECK_FAIL parameter calls are -* skipped and all callbacks of the CY_SYSPM_DEEPSLEEP type with the -* CY_SYSPM_BEFORE_TRANSITION parameter calls are executed, allowing the -* peripherals to prepare for deep sleep. -* The deep sleep mode is then entered. Any enabled interrupt can cause a wakeup -* from the deep sleep mode. -* -* \note The last callback which returned CY_SYSPM_FAIL is not executed with the -* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. -* -* The return values from executed callback functions with the -* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION -* modes are ignored. -* -* If the firmware attempts to enter this mode before the system is ready (that -* is, when PWR_CONTROL.LPM_READY = 0), then the device will go into the (LP) -* Sleep mode instead and automatically enter the deep sleep mode when the -* system is ready. -* -* The system puts the whole device into the deep sleep mode when all the -* processor(s) is (are) in deep sleep, there are no busy peripherals, the -* debugger is not active, and the deep sleep circuits are -* ready (PWR_CONTROL.LPM_READY=1). -* -* The peripherals that do not need a clock or that receive a clock from their -* external interface (e.g. I2C/SPI) continue operating. All circuits using the -* current from Vccdpslp supply are under the current limitation that is -* controlled by deep sleep regulator. -* -* Wakeup occurs when an interrupt asserts from a deep sleep active peripheral. -* For more details, see the corresponding peripheral's datasheet. -* -* \note For multi-core devices the second core, that did not participate in -* device wakeup, remain execute the deep sleep instructions. Any deep sleep -* capable interrupt routed to this core can wakeup it. -* -* For more details about switching into the deep sleep power mode and debug, -* refer to the device TRM. -* -* A normal wakeup from the deep sleep power mode returns to either LPActive, -* LPSleep, Active, or Sleep, depending on the previous state and programmed -* behaviour for the particular wakeup interrupt. -* -* After wakeup from Deep Sleep, all of the registered callbacks with -* CY_SYSPM_DEEPSLEEP type with CY_SYSPM_AFTER_TRANSITION are executed to return -* peripherals to Active operation. The Cy_SysPm_DeepSleep() function returns -* CY_SYSPM_SUCCESS. No callbacks are executed with CY_SYSPM_DEEPSLEEP type with -* CY_SYSPM_BEFORE_TRANSITION or CY_SYSPM_AFTER_TRANSITION parameter, if deep -* sleep mode was not entered. -* -* \param waitFor Selects wait for action. See \ref cy_en_syspm_waitfor_t. -* -* \sideeffect -* This side effect is applicable only for devices with UDB IP block available. -* You can obtain unpredictable behavior of the UDB block after the device wakeup -* from Deep Sleep. -* Unpredictable behavior scenario: -* * The first core saves non-retained UDB configuration registers and goes into -* the Deep Sleep (Cy_SysPm_DeepSleep() function). -* * These non-retained UDB configuration registers are modified in runtime by -* another (second) active core. -* * The second core saves non-retained UDB configuration registers and goes into -* the Deep Sleep (Cy_SysPm_DeepSleep() function). -* These conditions save different values of the non-retained UDB configuration -* registers. The prevented scenario: on the first core wakeup, these registers -* are restored by the values saved on the first core, and after the second core -* wakeup, these registers are "reconfigured" by the values saved on the second -* core. -* Be aware of such a situation. -* -* \sideeffect -* This function clears the Event Register of CM4 core after wakeup from WFE. -* -* \sideeffect -* This function changes the the slow and fast clock dividers to -* CY_SYSPM_CLK_DIVIDER right before entering into the deep sleep and restores -* these dividers after the wakeup. -* -* \return -* Entered status, see \ref cy_en_syspm_status_t. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_SysPm_DeepSleep(cy_en_syspm_waitfor_t waitFor) -{ - uint32_t interruptState; - cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; - - CY_ASSERT_L3(CY_SYSPM_IS_WAIT_FOR_VALID(waitFor)); - - /* Call the registered callback functions with - * the CY_SYSPM_CHECK_READY parameter. - */ - if(0U != curRegisteredCallbacks) - { - retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_CHECK_READY); - } - - /* The device (core) can switch into the deep sleep power mode only when - * all executed registered callback functions with the CY_SYSPM_CHECK_READY - * parameter returned CY_SYSPM_SUCCESS. - */ - if(retVal == CY_SYSPM_SUCCESS) - { - /* Call the registered callback functions with the - * CY_SYSPM_BEFORE_TRANSITION parameter. The return value should be - * CY_SYSPM_SUCCESS. - */ - interruptState = Cy_SysLib_EnterCriticalSection(); - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_BEFORE_TRANSITION); - } - - #ifdef CY_IP_MXUDB - - static cy_stc_syspm_backup_regs_t regs; - - /* Check is the UDB disabled on MMIO level */ - if(_FLD2BOOL(PERI_GR_SL_CTL_ENABLED_4, PERI->GR[CY_SYSPM_PERI_GR3_UDB].SL_CTL)) - { - - /* Save non-retained registers */ - Cy_SaveRegisters(®s); - } - #endif /* CY_IP_MXUDB */ - - Cy_EnterDeepSleep(waitFor); - - #ifdef CY_IP_MXUDB - - /* Do not restore the UDB if it is disabled on MMIO level */ - if(_FLD2BOOL(PERI_GR_SL_CTL_ENABLED_4, PERI->GR[CY_SYSPM_PERI_GR3_UDB].SL_CTL)) - { - /* Restore non-retained registers */ - Cy_RestoreRegisters(®s); - } - #endif /* CY_IP_MXUDB */ - - Cy_SysLib_ExitCriticalSection(interruptState); - - /* Call the registered callback functions with the CY_SYSPM_AFTER_TRANSITION - * parameter. The return value should be CY_SYSPM_SUCCESS. - */ - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_AFTER_TRANSITION); - } - } - else - { - /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to - * undo everything done in the callback with the CY_SYSPM_CHECK_READY - * parameter. The return value should be CY_SYSPM_SUCCESS. - */ - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_DEEPSLEEP, CY_SYSPM_CHECK_FAIL); - retVal = CY_SYSPM_FAIL; - } - return retVal; -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_Hibernate -****************************************************************************//** -* -* Sets the device into Hibernate mode. -* -* Puts the core into the hibernate power mode. Prior to entering the hibernate -* mode, all callbacks of the CY_SYSPM_HIBERNATE type are executed. -* First, callbacks of the CY_SYSPM_HIBERNATE type and with -* CY_SYSPM_CHECK_READY parameter are called allowing the driver to signal if it -* is not ready to enter the power mode. If any of the callbacks of the -* CY_SYSPM_HIBERNATE type with the CY_SYSPM_CHECK_READY parameter call returns -* CY_SYSPM_FAIL, the remaining CY_SYSPM_HIBERNATE callbacks with the -* CY_SYSPM_CHECK_READY parameter calls are skipped. After CY_SYSPM_FAIL, all -* of the CY_SYSPM_HIBERNATE callbacks with CY_SYSPM_CHECK_FAIL parameter are -* executed that correspond to the CY_SYSPM_HIBERNATE callbacks with -* CY_SYSPM_CHECK_READY parameter calls that occurred up to the point of failure. -* The hibernate mode is not entered and the Cy_SysPm_Hibernate() function -* returns CY_SYSPM_FAIL. -* -* If all CY_SYSPM_HIBERNATE callbacks with the CY_SYSPM_CHECK_READY parameter -* calls return CY_SYSPM_SUCCESS, then all CY_SYSPM_HIBERNATE callbacks with -* CY_SYSPM_CHECK_FAIL calls are skipped and all CY_SYSPM_HIBERNATE callbacks -* CY_SYSPM_BEFORE_TRANSITION parameter calls are executed allowing the -* peripherals to prepare for Hibernate. The I/O output state is frozen and the -* hibernate mode is then entered. In the hibernate mode, all internal supplies -* are off and no internal state is retained. There is no handshake with the -* CPUs and the chip will begin entry to Hibernate immediately. -* -* The I/O output state is frozen and the hibernate mode is then -* entered. In the hibernate mode all internal supplies are off and no -* internal state is retained. -* For multi-core devices there is no handshake with the CPUs and the chip -* will begin entry to the hibernate power mode immediately. -* -* \note The last callback which returned CY_SYSPM_FAIL is not executed with the -* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. -* -* The return values from executed callback functions with the -* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION -* modes are ignored. -* -* A wakeup from Hibernate is triggered by toggling the wakeup pin(s), a WDT -* match, or back-up domain alarm expiration depending on how the they were -* configured. A wakeup causes a normal boot procedure. -* To configure the wakeup pin(s), a Digital Input Pin must be configured, and -* resistively pulled up or down to the inverse state of the wakeup polarity. To -* distinguish a wakeup from the Hibernate mode and a general reset event, the -* Cy_SysLib_GetResetReason() function can be used. The wakeup pin, low-power -* comparators are active-low by default. The wakeup pin or the LPComparators -* polarity can be changed with the \ref Cy_SysPm_SetHibWakeupSource() function. -* This function call will not return if the hibernate mode is entered. -* The CY_SYSPM_HIBERNATE callbacks with the CY_SYSPM_AFTER_TRANSITION parameter -* are never executed. -* -* This function freezes the IO cells implicitly. It is not possible to enter -* the Hibernate mode before freezing the IO cells. The IO cells remain frozen -* after waking from the hibernate mode until the firmware unfreezes them -* with a \ref Cy_SysPm_IoUnfreeze() function call. -* -* \return -* Entered status, see \ref cy_en_syspm_status_t. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_SysPm_Hibernate(void) -{ - cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; - - /* Call the registered callback functions with the - * CY_SYSPM_CHECK_READY parameter - */ - if(0U != curRegisteredCallbacks) - { - retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_HIBERNATE, CY_SYSPM_CHECK_READY); - } - - /* The device (core) can switch into Hibernate power mode only when - * all executed registered callback functions with CY_SYSPM_CHECK_READY - * parameter returned CY_SYSPM_SUCCESS. - */ - if(retVal == CY_SYSPM_SUCCESS) - { - /* Call registered callback functions with CY_SYSPM_BEFORE_TRANSITION - * parameter. Return value should be CY_SYSPM_SUCCESS. - */ - (void) Cy_SysLib_EnterCriticalSection(); - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_HIBERNATE, CY_SYSPM_BEFORE_TRANSITION); - } - - /* Preserve the token that will retain through a wakeup sequence - * thus could be used by Cy_SysLib_GetResetReason() to differentiate - * Wakeup from a general reset event. - * Preserve the wakeup source(s) configuration. - */ - SRSS->PWR_HIBERNATE = - (SRSS->PWR_HIBERNATE & CY_SYSPM_PWR_WAKEUP_HIB_MASK) | CY_SYSPM_PWR_TOKEN_HIBERNATE; - - /* All the three writes to hibernate register use the same value: - * PWR_HIBERNATE.FREEZE=1, .UNLOCK=0x3A, .HIBERANTE=1, - */ - SRSS->PWR_HIBERNATE |= CY_SYSPM_PWR_SET_HIBERNATE; - - SRSS->PWR_HIBERNATE |= CY_SYSPM_PWR_SET_HIBERNATE; - - SRSS->PWR_HIBERNATE |= CY_SYSPM_PWR_SET_HIBERNATE; - - /* Read register to make sure it is settled */ - (void) SRSS->PWR_HIBERNATE; - - /* Wait for transition */ - __WFI(); - - /* The callback functions calls with the CY_SYSPM_AFTER_TRANSITION - * parameter in the hibernate power mode are not applicable as device - * wake-up was made on device reboot. - */ - - /* A wakeup from the hibernate is performed by toggling of the wakeup - * pins, or WDT matches, or Backup domain alarm expires. Depends on what - * item is configured in the hibernate register. After a wakeup event, a - * normal Boot procedure occurs. - * No need to exit from the critical section. - */ - } - else - { - /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to - * undo everything done in the callback with the CY_SYSPM_CHECK_READY - * parameter. The return value should be CY_SYSPM_SUCCESS. - */ - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_HIBERNATE, CY_SYSPM_CHECK_FAIL); - retVal = CY_SYSPM_FAIL; - } - return retVal; -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_EnterLpMode -****************************************************************************//** -* -* Sets device into the low power mode. -* -* The low power (LPActive/LPSleep) modes are similar to the active/sleep modes. -* The difference is that the current is limited and some functions have limited -* features/performance. -* -* The feature of the low power mode is the limited current. Restrictions are -* placed on the clock frequencies and allow the peripherals to achieve -* a current limit. -* -* Before entering the low power mode, the user should configure the system so -* the total current drawn from Vccd is less that the value presented in the -* technical reference manual (TRM). Refer to the TRM for the maximum load for -* low power operation and clock limitations in the low power mode with different -* core supply regulator voltages. -* -* * Peripherals can use the knowledge of the LPActive/LPSleep mode to make -* trade-offs that consume less current. For more details, see the corresponding -* peripherals' datasheet. -* * High-speed clock sources are available with the appropriate pre-divider -* settings to limit the system current. -* Refer to the TRM for the maximum frequency values for low power operation -* using different Core Regulators output voltages. -* -* Puts the device into the low power mode. Prior to entering the low power mode, -* all the registered CY_SYSPM_ENTER_LP_MODE callbacks with CY_SYSPM_CHECK_READY -* parameter are called. This allows the driver to signal if it is not ready to -* enter the low power mode. If any CY_SYSPM_ENTER_LP_MODE callbacks with the -* CY_SYSPM_CHECK_READY parameter call returns CY_SYSPM_FAIL, the remaining -* CY_SYSPM_ENTER_LP_MODE callbacks with the CY_SYSPM_CHECK_READY parameter -* calls are skipped. -* -* After a CY_SYSPM_FAIL all of the CY_SYSPM_ENTER_LP_MODE callbacks with -* CY_SYSPM_CHECK_FAIL parameter are executed that correspond to the -* CY_SYSPM_ENTER_LP_MODE callbacks with CY_SYSPM_CHECK_READY parameter calls -* that occurred up to the point of failure. Low Power mode is not entered and -* the Cy_SysPm_EnterLpMode() function returns CY_SYSPM_FAIL. -* -* If all CY_SYSPM_ENTER_LP_MODE callbacks with the CY_SYSPM_CHECK_READY -* parameter calls return CY_SYSPM_SUCCESS, then all CY_SYSPM_ENTER_LP_MODE -* callbacks with CY_SYSPM_CHECK_FAIL calls are skipped and all -* CY_SYSPM_ENTER_LP_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION parameter -* calls are executed. This allows the peripherals to prepare for low power. -* The low power mode is then entered. -* -* After entering the low power mode, all of the registered -* CY_SYSPM_ENTER_LP_MODE callbacks with the CY_SYSPM_AFTER_TRANSITION parameter -* are executed to complete preparing the peripherals for low power operation. -* The Cy_SysPm_EnterLpMode() function returns CY_SYSPM_SUCCESS. -* No CY_SYSPM_ENTER_LP_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION or -* CY_SYSPM_AFTER_TRANSITION parameter are executed, if the low power mode is not -* entered. -* -* \note The last callback which returned CY_SYSPM_FAIL is not executed with -* the CY_SYSPM_CHECK_FAIL parameter because of the FAIL. -* -* The return values from executed callback functions with the -* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION -* modes are ignored. -* -* \note The callbacks are not executed if the device is already not in -* the low power mode. -* -* \return -* See \ref cy_en_syspm_status_t.
-* CY_SYSPM_SUCCESS - Entered the LPActive mode or the device is already -* in LPActive.
-* CY_SYSPM_FAIL - The LPActive mode is not entered or low power circuits -* are not ready to enter the low power mode. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_SysPm_EnterLpMode(void) -{ - uint32_t interruptState; - cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; - - /* Check whether device is in the low power mode. */ - if(0U == (_FLD2VAL(SRSS_PWR_CTL_ACT_REF_DIS, SRSS->PWR_CTL))) - { - /* The entering into the low power mode is permitted when low - * power circuits are ready to enter into the low power mode. - */ - if(0U != _FLD2VAL(SRSS_PWR_CTL_LPM_READY, SRSS->PWR_CTL)) - { - /* Call the registered callback functions with the - * CY_SYSPM_CHECK_READY parameter. - */ - if(0U != curRegisteredCallbacks) - { - retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LP_MODE, CY_SYSPM_CHECK_READY); - } - - /* The device (core) can switch into the low power mode only when - * all executed registered callback functions with the - * CY_SYSPM_CHECK_READY parameter returned CY_SYSPM_SUCCESS. - */ - if(retVal == CY_SYSPM_SUCCESS) - { - - /* Call the registered callback functions with the - * CY_SYSPM_BEFORE_TRANSITION parameter. The return value - * should be CY_SYSPM_SUCCESS. - */ - interruptState = Cy_SysLib_EnterCriticalSection(); - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LP_MODE, CY_SYSPM_BEFORE_TRANSITION); - } - - /* Configure the low-power operating mode for Linear Core regulator */ - if(Cy_SysPm_LdoIsEnabled()) - { - SRSS->PWR_CTL |= (_VAL2FLD(SRSS_PWR_CTL_LINREG_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_PORBOD_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_BGREF_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_VREFBUF_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_IREF_LPMODE, 1U)); - } - else - { - /* Configure the low-power operating mode for SIMO Buck regulator */ - SRSS->PWR_CTL |= (_VAL2FLD(SRSS_PWR_CTL_PORBOD_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_BGREF_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_VREFBUF_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_IREF_LPMODE, 1U)); - } - - /* This wait time allows the circuits to remove their dependence on - * the Active mode circuits, such as Active Reference. - */ - Cy_SysLib_DelayUs(CY_SYSPM_ACTIVE_TO_LP_WAIT_US); - - /* Disabling active reference */ - SRSS->PWR_CTL |= _VAL2FLD(SRSS_PWR_CTL_ACT_REF_DIS, 1U); - - Cy_SysLib_ExitCriticalSection(interruptState); - - /* Call the registered callback functions with the - * CY_SYSPM_AFTER_TRANSITION parameter. The return value - * should be CY_SYSPM_SUCCESS. - */ - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LP_MODE, CY_SYSPM_AFTER_TRANSITION); - } - } - else - { - /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to - * undo everything done in the callback with the CY_SYSPM_CHECK_READY - * parameter. The return value should be CY_SYSPM_SUCCESS. - */ - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_ENTER_LP_MODE, CY_SYSPM_CHECK_FAIL); - retVal = CY_SYSPM_FAIL; - } - } - else - { - retVal = CY_SYSPM_FAIL; - } - } - else - { - /* Do nothing because the device is already in the low power mode. */ - } - return retVal; -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_ExitLpMode -****************************************************************************//** -* -* Sets the device out of the low power mode. -* -* Returns the device to the active mode. In the active power mode, the operating -* current can be increased to the normal mode limit. The clock frequencies also -* can be increased to the normal mode limit. Refer to the device TRM for the -* current and frequency limitations in the active power mode. -* -* Prior to exiting the low power mode, all the registered CY_SYSPM_EXIT_LP_MODE -* callbacks with the CY_SYSPM_CHECK_READY parameter are called. This allows -* the driver to signal if it is not ready to exit the -* low power mode. If any CY_SYSPM_EXIT_LP_MODE callbacks with -* the CY_SYSPM_CHECK_READY parameter call returns CY_SYSPM_FAIL, the remaining -* CY_SYSPM_EXIT_LP_MODE callbacks with the CY_SYSPM_CHECK_READY parameter calls -* are skipped. After a CY_SYSPM_FAIL, all of the CY_SYSPM_EXIT_LP_MODE callbacks -* with CY_SYSPM_CHECK_FAIL parameter are executed that correspond to the -* CY_SYSPM_EXIT_LP_MODE callbacks with CY_SYSPM_CHECK_READY parameter calls that -* occurred up to the point of failure. The active mode is not entered and the -* Cy_SysPm_ExitLpMode() function returns CY_SYSPM_FAIL. -* -* If all CY_SYSPM_EXIT_LP_MODE callbacks with CY_SYSPM_CHECK_READY calls return -* CY_SYSPM_SUCCESS, then all the CY_SYSPM_EXIT_LP_MODE callbacks with -* the CY_SYSPM_CHECK_FAIL parameter calls are skipped and all -* CY_SYSPM_EXIT_LP_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION parameter -* calls are executed allowing the peripherals to prepare for the active mode. -* The low power mode is then exited. -* -* After exiting the low power mode, all of the registered callbacks are executed -* CY_SYSPM_EXIT_LP_MODE callbacks with the CY_SYSPM_AFTER_TRANSITION parameter -* to complete preparing the peripherals for the active mode operation. -* The Cy_SysPm_ExitLpMode() function returns CY_SYSPM_SUCCESS. -* No CY_SYSPM_EXIT_LP_MODE callbacks with the CY_SYSPM_BEFORE_TRANSITION or -* CY_SYSPM_AFTER_TRANSITION parameter are executed if the low power mode is -* not exited. -* -* \note The last callback which returned CY_SYSPM_FAIL is not executed with the -* CY_SYSPM_CHECK_FAIL parameter because of the FAIL. -* -* The return values from executed callback functions with the -* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and CY_SYSPM_AFTER_TRANSITION -* modes are ignored. -* -* \note The callbacks are not executed if the device is not already in the low -* power mode. -* -* \return -* See \ref cy_en_syspm_status_t.
-* CY_SYSPM_SUCCESS - Exited from the LPActive power mode, or the device is -* already in the active power.
-* CY_SYSPM_FAIL - Exit from the LPActive mode is not done. -* -* \warning This function blocks as it waits until Active Reference is ready -* to enter into the normal mode. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_SysPm_ExitLpMode(void) -{ - uint32_t interruptState; - uint32_t timeOut = CY_SYSPM_WAIT_DELAY_TRYES; - cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; - - /* Check if the device is in the low power mode */ - if(0U != (_FLD2VAL(SRSS_PWR_CTL_ACT_REF_DIS, SRSS->PWR_CTL))) - { - /* Call the registered callback functions with the - * CY_SYSPM_CHECK_READY parameter. - */ - if(0U != curRegisteredCallbacks) - { - retVal = Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LP_MODE, CY_SYSPM_CHECK_READY); - } - - /* The device (core) can switch into the low power mode only in - * condition that all executed registered callback functions with the - * CY_SYSPM_CHECK_READY parameter returned CY_SYSPM_SUCCESS. - */ - if(retVal == CY_SYSPM_SUCCESS) - { - /* Call the registered callback functions with the - * CY_SYSPM_BEFORE_TRANSITION parameter. The return value should be - * CY_SYSPM_SUCCESS. - */ - interruptState = Cy_SysLib_EnterCriticalSection(); - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LP_MODE, CY_SYSPM_BEFORE_TRANSITION); - } - - /* Set the normal operation mode for Linear Core regulator if - * it is enabled - */ - if(Cy_SysPm_LdoIsEnabled()) - { - SRSS->PWR_CTL &= ((uint32_t)~(SRSS_PWR_CTL_LINREG_LPMODE_Msk)); - } - - /* Configure the normal operating mode for the POR/BOD circuits and - * for the Bandgap Voltage and Current References - */ - SRSS->PWR_CTL &= ((uint32_t)~(_VAL2FLD(SRSS_PWR_CTL_PORBOD_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_ACT_REF_DIS, 1U) | - _VAL2FLD(SRSS_PWR_CTL_VREFBUF_LPMODE, 1U) | - _VAL2FLD(SRSS_PWR_CTL_IREF_LPMODE, 1U))); - - /* This wait time allows setting Active Reference */ - Cy_SysLib_DelayUs(CY_SYSPM_LP_TO_ACTIVE_WAIT_BEFORE_US); - - while((0U == _FLD2VAL(SRSS_PWR_CTL_ACT_REF_OK, SRSS->PWR_CTL)) && (0U != timeOut)) - { - timeOut--; - } - - if(0U == timeOut) - { - retVal = CY_SYSPM_TIMEOUT; - - Cy_SysLib_ExitCriticalSection(interruptState); - } - else - { - /* Configure the normal operation mode */ - SRSS->PWR_CTL &= ((uint32_t) (~SRSS_PWR_CTL_BGREF_LPMODE_Msk)); - - /* This wait time allows setting Active Reference */ - Cy_SysLib_DelayUs(CY_SYSPM_LP_TO_ACTIVE_WAIT_AFTER_US); - - Cy_SysLib_ExitCriticalSection(interruptState); - - /* Call registered callback functions with CY_SYSPM_AFTER_TRANSITION - * parameter. Return value should be CY_SYSPM_SUCCESS. - */ - if(0U != curRegisteredCallbacks) - { - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LP_MODE, CY_SYSPM_AFTER_TRANSITION); - } - } - - } - else - { - /* Execute callback functions with the CY_SYSPM_CHECK_FAIL parameter to - * undo everything done in the callback with the CY_SYSPM_CHECK_READY - * parameter. The return value should be CY_SYSPM_SUCCESS. - */ - (void) Cy_SysPm_ExecuteCallback(CY_SYSPM_EXIT_LP_MODE, CY_SYSPM_CHECK_FAIL); - retVal = CY_SYSPM_FAIL; - } - } - else - { - /* Do nothing because the device is already in the active power mode. */ - } - return retVal; -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_SleepOnExit -****************************************************************************//** -* -* Set Sleep on the Exit mode. -* -* This API gives a possibility to keep the system in the sleep mode at all times -* and only wakeup to run a single interrupt and then immediately go back to -* sleep. -* -* \param enable -* True - enable Sleep on the Exit mode
false - disable -* Sleep on the Exit mode. -* -*******************************************************************************/ -void Cy_SysPm_SleepOnExit(bool enable) -{ - uint32_t interruptState; - interruptState = Cy_SysLib_EnterCriticalSection(); - - if(enable) - { - /* Enable SleepOnExit mode */ - SCB->SCR |= _VAL2FLD(SCB_SCR_SLEEPONEXIT, 1U); - } - else - { - /* Disable SleepOnExit mode */ - SCB->SCR &= ((uint32_t) ~(SCB_SCR_SLEEPONEXIT_Msk)); - } - Cy_SysLib_ExitCriticalSection(interruptState); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_SetHibWakeupSource -****************************************************************************//** -* -* This function configures sources to wake up the device from the hibernate -* power mode. Such sources can be wakeup pins, LPComparators, Watchdog (WDT) -* interrupt, or Real-Time clock (RTC) alarm (interrupt). -* -* Wakeup pins: -* -* A wakeup is supported by up to two pins with programmable polarity. These pins -* may be connected to the IO pins or on-chip peripherals under some conditions. -* Setting the wakeup pin to this level will cause a wakeup from the hibernate -* mode. The wakeup pins are active/low by default. -* -* LPComparators: -* -* A wakeup is supported by up to two LPComps with programmable polarity. These -* LPComp may be connected to the IO pins or on-chip peripherals under some -* conditions. -* Setting the LPComp to this level will cause a wakeup from the hibernate -* mode. The wakeup LPComp are active/low by default. -* -* \note The low-power comparators should be configured and enabled before -* switching into the hibernate low power mode. Refer to the LPComp -* driver description for more details. -* -* Watchdog Timer: -* -* \note The WDT should be configured and enabled before entering into the -* hibernate power mode. -* -* A wakeup is performed by a WDT interrupt and a normal boot procedure -* after a device reset. The device can wake up from Hibernate after a WDT -* device reset, if the WDT was not configured to wake up, the device on its -* interrupt and WDT was enabled. -* -* Real-time Clock: -* -* A wakeup is performed by the RTC alarm and a normal boot procedure -* after a device reset. -* Refer to the Real-Time Clock (RTC) driver description for more details. -* -* For information about wakeup sources and their assignment in the specific -* families devices, refer to the appropriate device TRM. -* -* \param wakeupSource -* The source to be configured as a wakeup source from -* the hibernate power mode. The input parameters values can be ORed. -* For example, if you want to set LPComp0 (active high) and WDT, call -* this function: -* Cy_SysPm_SetHibWakeupSource(CY_SYSPM_LPCOMP0_HIGH | CY_SYSPM_HIBWDT). -* -* \warning Do not call this function with different polarity levels for the same -* wakeup source. For example, do not call a function like this: -* Cy_SysPm_SetHibWakeupSource(CY_SYSPM_LPCOMP0_LOW, CY_SYSPM_LPCOMP0_HIGH); -* -*******************************************************************************/ -void Cy_SysPm_SetHibWakeupSource(cy_en_syspm_hib_wakeup_source_t wakeupSource) -{ - CY_ASSERT_L3(CY_SYSPM_IS_WAKE_UP_SOURCE_VALID(wakeupSource)); - - /* Reconfigure the wake-up pins and LPComp polarity based on the input */ - if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_LPCOMP0)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP0_BIT)); - } - - if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_LPCOMP1)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP1_BIT)); - } - - if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_PIN0)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN0_BIT)); - } - - if(0U != ((uint32_t) wakeupSource & CY_SYSPM_WAKEUP_PIN1)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN1_BIT)); - } - - SRSS->PWR_HIBERNATE |= ((uint32_t) wakeupSource); - - /* Read register to make sure it is settled */ - (void) SRSS->PWR_HIBERNATE; -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_ClearHibWakeupSource -****************************************************************************//** -* -* This function disables a wakeup source which was previously configured to -* wake up the device from the hibernate power mode. -* -* \param wakeupSource -* The source to be disabled. The input parameters values can -* be ORed. For example, if you want to disable LPComp0 (active high) and WDT -* call this function: -* Cy_SysPm_ClearHibWakeupSource(CY_SYSPM_LPCOMP0_HIGH | CY_SYSPM_HIBWDT). -* -*******************************************************************************/ -void Cy_SysPm_ClearHibWakeupSource(cy_en_syspm_hib_wakeup_source_t wakeupSource) -{ - uint32_t clearWakeupSource; - - CY_ASSERT_L3(CY_SYSPM_IS_WAKE_UP_SOURCE_VALID(wakeupSource)); - - if (0U != _FLD2VAL(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, wakeupSource)) - { - /* Clear the high active level of the requested sources */ - if((uint32_t) CY_SYSPM_LPCOMP0_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_LPCOMP0_HIGH)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP0_BIT)); - } - - if((uint32_t) CY_SYSPM_LPCOMP1_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_LPCOMP1_HIGH)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_LPCOMP1_BIT)); - } - - if((uint32_t) CY_SYSPM_HIBPIN0_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_HIBPIN0_HIGH)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN0_BIT)); - } - - if((uint32_t) CY_SYSPM_HIBPIN1_HIGH == ((uint32_t) wakeupSource & (uint32_t) CY_SYSPM_HIBPIN1_HIGH)) - { - SRSS->PWR_HIBERNATE &= - ((uint32_t) ~_VAL2FLD(SRSS_PWR_HIBERNATE_POLARITY_HIBPIN, CY_SYSPM_WAKEUP_PIN1_BIT)); - } - } - - /* Remove the polarity bits from the input value */ - clearWakeupSource = ((uint32_t) wakeupSource & ((uint32_t) ~ SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Msk)); - - SRSS->PWR_HIBERNATE &= ((uint32_t) ~ clearWakeupSource); - - /* Read register to make sure it is settled */ - (void) SRSS->PWR_HIBERNATE; -} - - -#if(0u != SRSS_SIMOBUCK_PRESENT) - /******************************************************************************* - * Function Name: Cy_SysPm_SwitchToSimoBuck - ****************************************************************************//** - * - * Switch the power supply regulator to Single-Input Multiple Output (SIMO) - * Buck regulator instead of Linear regulator. The SIMO Buck core regulator - * provides two outputs using one external inductor and can supply Vccd with - * higher efficiency than the Linear core regulator (LDO) under some - * conditions, such as high external supply voltage. - * - * Before changing from LDO to SIMO Buck, ensure that: - * * The circuit board has connected Vccbuck1 to Vccd and also populated the - * necessary external components for the SIMO Buck regulator, including an - * inductor and a capacitor for each output. - * Refer to the device TRM for more details. - * - * * The operating frequency is reduced so it is within the static timing - * closure limits at the new frequency. - * - * * The current consumption on the core is reduced to meet the 0.9 V (nominal) - * output voltage. The main reason is that while changing from LDO to SIMO Buck, - * the switch happens at 0.9 V (nominal). - * - * * The appropriate Wait states values are set for Flash using the - * Cy_SysLib_SetWaitStates() function. Refer to the System Library (syslib) - * driver for more details. - * - * In general, use the next sequence to obtain SIMO Buck 0.9 V (nominal): - * 1) Set the appropriate Wait states for 0.9 V, by calling - * Cy_SysLib_SetWaitStates(true, hfClkFreqMz), where hfClkFreqMz - - * the desired frequency of HfClk0 in MHz. - * - * 2) Set 0.9 V (nominal) for the LDO regulator. - * - * 3) Switch the regulators by calling the Cy_SysPm_SwitchToSimoBuck() function. - * - * To obtain SIMO Buck 1.1 V (nominal) use the next sequence: - * 1) Set the appropriate Wait states for 0.9 V by calling - * Cy_SysLib_SetWaitStates(true, hfClkFreqMz), where hfClkFreqMz - - * the desired frequency of HfClk0 in MHz - * - * 2) Set 0.9 V (nominal) for the LDO regulator. - * - * 3) Switch the regulators by calling the Cy_SysPm_SwitchToSimoBuck() function. - * - * 4) Change the SIMO Buck output voltage by calling the - * Cy_SysPm_SimoBuckSetVoltage1(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V). - * - * 5) Set the appropriate Wait states for LP by calling - * Cy_SysLib_SetWaitStates(false, hfClkFreqMz), where hfClkFreqMz - - * the desired frequency of HfClk0 in MHz - * - * \warning The system cannot recognize when Vccd is settled at actual - * 0.9 V or 1.1 V for transition, because this voltage depends on the conditions - * including the load current. The firmware works with the - * nominal 0.9 V and 1.1 V voltages. - * - * \warning The Flash access time when the core - * output voltage is 0.9 V (nominal) is longer than at 1.1 V (nominal). - * Therefore, the clock to the Flash should be decreased. Use the - * Cy_SysLib_SetWaitStates() function to set the appropriate Wait state values - * for Flash. Call the Cy_SysLib_SetWaitStates() function before - * Cy_SysPm_SwitchToSimoBuck() if you want to change the voltage - * to 0.9 V (nominal). Call the Cy_SysLib_SetWaitStates() function after - * Cy_SysPm_SwitchToSimoBuck() if you change the voltage from 0.9 V (nominal) - * to 1.1 V (nominal). - * - * \warning There is no way to go back to the Linear regulator after the SIMO - * Buck regulator supplies a core. The function switches off the LDO. - * - * In addition, if the 0.9 V (nominal) output is set, the Flash works - * in the Read-only operation. - * - * If the 1.1 V (nominal) output is set, the Flash works in the Read and Write - * operation and clock frequencies may be increased up to the static - * timing closure limits for a new voltage. - * Refer to the device TRM for more details. - * - * \note - * The function is applicable for devices with the SIMO Buck regulator. - * - *******************************************************************************/ - void Cy_SysPm_SwitchToSimoBuck(void) - { - /* Disable the DeepSleep, nWell, and Retention regulators */ - SRSS->PWR_CTL |= (_VAL2FLD(SRSS_PWR_CTL_DPSLP_REG_DIS, 1U) | - _VAL2FLD(SRSS_PWR_CTL_RET_REG_DIS, 1U) | - _VAL2FLD(SRSS_PWR_CTL_NWELL_REG_DIS, 1U)); - - /* Configure the SIMO Buck regulator */ - SRSS->PWR_BUCK_CTL = _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL), - SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, - (uint32_t) CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V); - - /* Check is the SIMO Buck regulator is already enabled */ - if(!Cy_SysPm_SimoBuckIsEnabled()) - { - SRSS->PWR_BUCK_CTL |= _VAL2FLD(SRSS_PWR_BUCK_CTL_BUCK_EN, 1U); - } - - SRSS->PWR_BUCK_CTL |= _VAL2FLD(SRSS_PWR_BUCK_CTL_BUCK_OUT1_EN, 1U); - - /* Wait until SIMO Buck output 1 is stable */ - Cy_SysLib_DelayUs(CY_SYSPM_SIMO_BUCK_CORE_SUPPLY_STABLE_US); - - /* Disable the Linear regulator LDO because Vbuckout1 and LDO are shorted */ - SRSS->PWR_CTL |= _VAL2FLD(SRSS_PWR_CTL_LINREG_DIS, 1U); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckSetVoltage1 - ****************************************************************************//** - * - * Set the output 1 voltage for the SIMO Buck regulator that can supply cores. - * This output can supply cores instead of the Linear regulator. - * - * When changing from a higher voltage to a lower voltage, make sure that: - * * The operating frequency is reduced so it is within the static timing closure - * limits at the new frequency. - * - * * The appropriate Wait states values are set for Flash using the - * Cy_SysLib_SetWaitStates() function. Refer to the System Library (syslib) - * driver for more details. - * - * \warning The Flash access time when the core - * output voltage is 0.9 V (nominal) is longer than at 1.1 V (nominal). - * Therefore, the clock to the Flash should be decreased. - * - * In addition, if the 0.9 V (nominal) output is set, the Flash works in - * the Read-only operation. - * - * When changing from a lower voltage to a higher voltage, make sure that - * the appropriate Wait states values are set for Flash using the - * Cy_SysLib_SetWaitStates() function. Refer to the System Library (syslib) - * driver for more details. - * - * If the 1.1 V (nominal) output is set, the Flash works in the Read and Write - * operations and the clock frequency may now be increased up to the static - * timing closure limits for the new voltage. - * - * \warning The system cannot recognize when Vccd is settled at the actual - * 0.9 V or 1.1 V for transition, because this voltage depends on the conditions - * including load current. The firmware works with the nominal - * 0.9 V and 1.1 V voltages. - * - * \param voltage - * The desired output 1 regulator voltage (Vccbuck1). - * See \ref cy_en_syspm_simo_buck_voltage1_t - * - *******************************************************************************/ - void Cy_SysPm_SimoBuckSetVoltage1(cy_en_syspm_simo_buck_voltage1_t voltage) - { - CY_ASSERT_L3(CY_SYSPM_IS_SIMO_BUCK_VOLTAGE1_VALID(voltage)); - - /* Check if the required voltage is equal to the current voltage */ - if(voltage != Cy_SysPm_SimoBuckGetVoltage1()) - { - /* Set the analog signal bit for the flash before the voltage is - * changed from 1.1V to 0.9V - */ - if(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V == voltage) - { - Cy_SetVoltageBitForFlash(true); - } - - /* The system may continue operating while the voltage on Vccd - * discharges to the new voltage. The time it takes to reach the - * new voltage depends on the conditions, including the load current - * on Vccd and the external capacitor size. - */ - SRSS->PWR_BUCK_CTL = - _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL), SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, (uint32_t) voltage); - - /* Delay to stabilize at the new voltage is required only - * when changing from a lower voltage to a higher voltage. - */ - if(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V == voltage) - { - Cy_SysLib_DelayUs(CY_SYSPM_SIMO_BUCK_IS_STABLE_US); - - /* Set analog signal bit for flash before voltage is changed - * from 0.9 V to 1.1 V. - */ - Cy_SetVoltageBitForFlash(false); - } - } - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_EnableVoltage2 - ****************************************************************************//** - * - * Enable the output 2 voltage (Vbuckrf) of the SIMO Buck regulator. - * The output 2 voltage (Vbuckrf) of the SIMO Buck regulator is used to supply - * the BLE HW block. - * When the SIMO Buck regulator is switched off, the function enables the - * regulator and after it, enables output 2. - * - * \note The function does not affect SIMO Buck output 1 that can supply - * a core. - * - * \warning The function does not select the SIMO Buck output 2 voltage and - * does not set/clear the HW-controlled bit for SIMO Buck output 2. Call - * Cy_SysPm_SimoBuckSetVoltage2() or Cy_SysPm_SimoBuckSetHwControl() to - * configure the SIMO Buck output 2. - * - *******************************************************************************/ - void Cy_SysPm_EnableVoltage2(void) - { - if(!Cy_SysPm_SimoBuckIsEnabled()) - { - /* Enable the SIMO Buck regulator */ - SRSS->PWR_BUCK_CTL |= _VAL2FLD(SRSS_PWR_BUCK_CTL_BUCK_EN, 1U); - } - - /* Enable the SIMO Buck output 2 */ - SRSS->PWR_BUCK_CTL2 |= _VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_EN, 1U); - - /* Wait until the output is stable */ - Cy_SysLib_DelayUs(CY_SYSPM_SIMO_BUCK_BLE_SUPPLY_STABLE_US); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckSetVoltage2 - ****************************************************************************//** - * - * Set output voltage 2 of the SIMO Buck regulator. - * - * \param voltage - * The voltage of the SIMO Buck regulator output 2. - * See \ref cy_en_syspm_simo_buck_voltage2_t. - * - * \param waitToSettle - * True - Enable the 200 uS delay after setting a higher voltage. - * False - Disable the 200 uS delay after setting a higher voltage. - * - * \warning It is strongly recommended to enable the delay (waitToSettle = true) - * while changing from a lower voltage to a higher voltage. - * - * \note The 200 uS delay is required only under changing from a - * lower voltage to a higher voltage. Changing from a higher voltage to a lower - * the delay is not required. - * - *******************************************************************************/ - void Cy_SysPm_SimoBuckSetVoltage2(cy_en_syspm_simo_buck_voltage2_t voltage, bool waitToSettle) - { - uint32_t curVoltage; - - CY_ASSERT_L3(CY_SYSPM_IS_SIMO_BUCK_VOLTAGE2_VALID(voltage)); - - /* Get the current voltage */ - curVoltage = (uint32_t) Cy_SysPm_SimoBuckGetVoltage2(); - - if((uint32_t) voltage != curVoltage) - { - SRSS->PWR_BUCK_CTL2 = - _CLR_SET_FLD32U((SRSS->PWR_BUCK_CTL2), SRSS_PWR_BUCK_CTL2_BUCK_OUT2_SEL, (uint32_t) voltage); - - /* Delay to stabilize at the new voltage is required only - * when changing from a lower voltage to a higher voltage. - */ - if(waitToSettle && ((uint32_t) voltage > curVoltage)) - { - Cy_SysLib_DelayUs(CY_SYSPM_SIMO_BUCK_IS_STABLE_US); - } - } - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckOutputIsEnabled - ****************************************************************************//** - * - * Get the current output status of the SIMO Buck outputs. - * - * \param output - * The SIMO Buck regulator output. See \ref cy_en_syspm_buck_out_t. - * - * \return - * The current state of the requested output. True if the requested output - * is enabled. - * False if the requested output is disabled. - * - *******************************************************************************/ - bool Cy_SysPm_SimoBuckOutputIsEnabled(cy_en_syspm_buck_out_t output) - { - bool retVal; - - CY_ASSERT_L3(CY_SYSPM_IS_SIMO_BUCK_OUTPUT_VALID(output)); - - if(output == CY_SYSPM_BUCK_VBUCK_1) - { - retVal = (_FLD2BOOL(SRSS_PWR_BUCK_CTL_BUCK_OUT1_EN, SRSS->PWR_BUCK_CTL)); - } - else - { - if((0U != _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, SRSS->PWR_BUCK_CTL2)) || - (0U != _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_EN, SRSS->PWR_BUCK_CTL2))) - { - retVal = true; - } - else - { - retVal = false; - } - } - return(retVal); - } - -#endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ - - -/******************************************************************************* -* Function Name: Cy_SysPm_LdoSetVoltage -****************************************************************************//** -* -* Set the voltage on the Linear regulator (LDO). -* When changing from a higher voltage to a lower voltage, make sure that: -* * The operating frequencies are reduced so these are within the static timing -* closure limits at the new frequency. -* -* * The current consumption on the core is reduced to meet the new output -* voltage. -* -* * The appropriate Wait states values are set for Flash using the -* Cy_SysLib_SetWaitStates() function. Refer to the System Library (syslib) -* driver for more details. -* -* \warning NOTE: The Flash access time when the core -* output voltage is 0.9 V (nominal) is longer than at 1.1 V (nominal). -* Therefore, the clock to the Flash should be decreased. -* -* In addition, if the 0.9 V (nominal) output is set, the Flash works in -* the Read-only operation. -* -* When changing from a lower voltage to a higher voltage, make sure that -* the appropriate Wait states values are set for the Flash using the -* Cy_SysLib_SetWaitStates() function. Refer to the System Library (syslib) -* driver for more details. -* -* If the 1.1 V (nominal) output is set, the Flash works in the Read and Write -* operations. The clock frequency may now be increased up to the static -* timing closure limits for the new voltage. -* -* \note The actual device Vccd voltage can be different from the -* nominal voltage because the actual voltage value depends on the conditions -* including the load current. -* -* \param voltage -* The desired output regulator voltage. -* See \ref cy_en_syspm_ldo_voltage_t voltage -* -*******************************************************************************/ -void Cy_SysPm_LdoSetVoltage(cy_en_syspm_ldo_voltage_t voltage) -{ - CY_ASSERT_L3(CY_SYSPM_IS_LDO_VOLTAGE_VALID(voltage)); - - if(voltage != Cy_SysPm_LdoGetVoltage()) - { - /* Set the analog signal bit for the flash before the voltage is changed - * from 1.1V to 0.9V - */ - if(CY_SYSPM_LDO_VOLTAGE_0_9V == voltage) - { - Cy_SetVoltageBitForFlash(true); - } - - /* The system may continue operating while the voltage on Vccd - * discharges to the new voltage. The time it takes to reach the - * new voltage depends on the conditions, including the load current on - * Vccd and the external capacitor size - */ - SRSS->PWR_TRIM_PWRSYS_CTL = - _CLR_SET_FLD32U((SRSS->PWR_TRIM_PWRSYS_CTL), SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, voltage); - - if(CY_SYSPM_LDO_VOLTAGE_1_1V == voltage) - { - /* A delay for the supply to stabilize at the new higher voltage */ - Cy_SysLib_DelayUs(CY_SYSPM_LDO_IS_STABLE_US); - - /* Set the analog signal bit to the flash macro register after - * the output voltage is 1.1 V - */ - Cy_SetVoltageBitForFlash(false); - } - } -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_RegisterCallback -****************************************************************************//** -* -* Registers a new syspm callback. -* -* A callback is a function called after an event in the driver or -* middleware module has occurred. The handler callback API will be executed if -* the specific event occurs. See \ref cy_stc_syspm_callback_t. -* -* \note The registered callbacks are executed in two orders, based on callback -* mode \ref cy_en_syspm_callback_mode_t. For modes CY_SYSPM_CHECK_READY and -* CY_SYSPM_BEFORE_TRANSITION the order is next: the first registered callback -* will be always the first executed. And the last registered callback will be -* executed as the last callback. For modes CY_SYSPM_AFTER_TRANSITION and -* CY_SYSPM_CHECK_FAIL the order is next: the first registered callback will be -* always the last executed. And the last registered callback will be executed -* as the first callback. -* -* \param handler -* The address of the syspm callback structure. -* See \ref cy_stc_syspm_callback_t. -* \note Do not modify the registered structure in run-time. -* -* \return -* True if a callback was registered;
-* False if a callback was not registered or maximum callbacks were registered. -* -* It is allowed to register up to 32 callbacks. -* -*******************************************************************************/ -bool Cy_SysPm_RegisterCallback(cy_stc_syspm_callback_t* handler) -{ - uint32_t interruptState; - bool retStatus = false; - - interruptState = Cy_SysLib_EnterCriticalSection(); - - /* Check if the maximum callbacks were registered and verify input */ - retStatus = ((handler != NULL) && (curRegisteredCallbacks < CY_SYSPM_CALLBACKS_NUMBER_MAX)); - - if (retStatus) - { - if ((handler->callbackParams != NULL) && (handler->callback != NULL)) - { - cy_stc_syspm_callback_t* curCallback = callbackRoot; - cy_stc_syspm_callback_t* lastRegCallback = NULL; - - /* Search last registered callback item */ - while (curCallback != NULL) - { - if (curCallback == handler) - { - /* Do not register already registered callback item */ - retStatus = false; - break; - } - - /* Safe callback before switching into the next item */ - lastRegCallback = curCallback; - - curCallback = curCallback->nextItm; - } - - /* Link requested callback item to the linked list */ - if (retStatus) - { - if (callbackRoot == NULL) - { - /* Link first callback item to the linked list */ - callbackRoot = handler; - } - else - { - /* Link requested item to previous item */ - lastRegCallback->nextItm = handler; - } - - /* Update links to next and previous callback items of requested - * callback item - */ - handler->prevItm = lastRegCallback; - handler->nextItm = NULL; - - /* Increment the value with number of registered callbacks */ - ++curRegisteredCallbacks; - } - } - else - { - retStatus = false; - } - } - - Cy_SysLib_ExitCriticalSection(interruptState); - - return(retStatus); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_UnregisterCallback -****************************************************************************//** -* -* Unregister a callback. -* -* The registered callback can be unregistered. Otherwise, false will be -* returned. -* -* \param handler The item that should be unregistered. -* See \ref cy_stc_syspm_callback_t. -* -* \return -* True if on success
-* False if it was not unregistered or none callbacks were registered. -* -*******************************************************************************/ -bool Cy_SysPm_UnregisterCallback(cy_stc_syspm_callback_t const *handler) -{ - uint32_t interruptState; - bool retStatus = false; - - interruptState = Cy_SysLib_EnterCriticalSection(); - - /* Check if there was at least one callback registered */ - if (curRegisteredCallbacks > 0UL) - { - cy_stc_syspm_callback_t* curCallback = callbackRoot; - - /* Search requested callback item in the linked list */ - while (curCallback != NULL) - { - /* Requested callback is found */ - if (curCallback == handler) - { - retStatus = true; - break; - } - - /* Go to next callback item in the linked list */ - curCallback = curCallback->nextItm; - } - - if (retStatus) - { - /* Requested callback is first in the list */ - if (callbackRoot == handler) - { - /* Check is this the only one callback registered */ - if (callbackRoot->nextItm != NULL) - { - callbackRoot = callbackRoot->nextItm; - callbackRoot->prevItm = NULL; - } - } - else - { - /* Update links of related to unregistered callback items */ - curCallback->prevItm->nextItm = curCallback->nextItm; - - if (curCallback->nextItm != NULL) - { - curCallback->nextItm->prevItm = curCallback->prevItm; - } - } - - /* Decrement the value with number of registered callbacks */ - --curRegisteredCallbacks; - - if (curRegisteredCallbacks == 0UL) - { - callbackRoot = NULL; - } - } - } - - Cy_SysLib_ExitCriticalSection(interruptState); - - return(retStatus); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_ExecuteCallback -****************************************************************************//** -* -* The function executes all registered callbacks with provided type and mode. -* \note The registered callbacks will be executed in order based on lastCallback -* value. The are possible two orders of callbacks execution:
-* * From first registered to last registered. Such order is relevant to -* callbacks with mode CY_SYSPM_CHECK_READY and CY_SYSPM_BEFORE_TRANSITION. -* * Backward flow execution: from last executed callback to the -* first registered. Such order is relevant to callbacks with mode -* CY_SYSPM_AFTER_TRANSITION and CY_SYSPM_CHECK_FAIL. Note that, the last -* registered callback function is skipped with mode CY_SYSPM_CHECK_FAIL. This -* is because callback which returned CY_SYSPM_FAIL already know that it failed. -* -* If no callbacks are registered, returns CY_SYSPM_SUCCESS. -* -* \param type -* The callback type. See \ref cy_en_syspm_callback_type_t. -* -* \param mode -* The callback mode. See \ref cy_en_syspm_callback_mode_t. -* -* \note -* If mode is CY_SYSPM_CHECK_READY or CY_SYSPM_BEFORE_TRANSITION the -* all required callbacks would be executed in order from first -* registered to last registered. -* If mode is CY_SYSPM_CHECK_FAIL or CY_SYSPM_AFTER_TRANSITION the -* all required callbacks would be executed in order from last executed callback -* to first registered. -* -* \return -* CY_SYSPM_SUCCESS Callback successfully completed or nor callbacks registered. -* CY_SYSPM_FAIL one of executed callback(s) returned fail. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_SysPm_ExecuteCallback(cy_en_syspm_callback_type_t type, cy_en_syspm_callback_mode_t mode) -{ - static cy_stc_syspm_callback_t* lastExecutedCallback = NULL; - cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS; - cy_stc_syspm_callback_t* curCallback; - cy_stc_syspm_callback_params_t curParams; - - CY_ASSERT_L3(CY_SYSPM_IS_CALLBACK_TYPE_VALID(type)); - CY_ASSERT_L3(CY_SYSPM_IS_CALLBACK_MODE_VALID(mode)); - - if((mode == CY_SYSPM_BEFORE_TRANSITION) || (mode == CY_SYSPM_CHECK_READY)) - { - /* Execute registered callbacks with order from first registered to the - * last registered. The modes defined in the .skipMode element are not - * executed - */ - curCallback = callbackRoot; - while((curCallback != NULL) && (retVal != CY_SYSPM_FAIL)) - { - if((curCallback->type == type) && ((0U == curCallback->skipMode) || - (0U == ((uint32_t) mode & curCallback->skipMode)))) - { - /* Update elements for local callback parameter values */ - curParams.base = curCallback->callbackParams->base; - curParams.context = curCallback->callbackParams->context; - curParams.mode = mode; - - retVal = curCallback->callback(&curParams); - - /* Update callback pointer with value of executed callback. - * Such update is required to execute further callbacks in - * backward order after exit from low power mode or to undo - * configuration after callback returned fail: from last executed - * to first registered. - */ - lastExecutedCallback = curCallback; - } - curCallback = curCallback->nextItm; - } - } - else - { - /* Execute registered callbacks with order from lastCallback to - * the first registered callback. Such flow is required if previous - * callback function returned CY_SYSPM_FAIL or previous callback mode was - * CY_SYSPM_BEFORE_TRANSITION. Such order to undo configurations in - * correct backward order. - */ - curCallback = lastExecutedCallback; - - /* Skip last executed callback that returned CY_SYSPM_FAIL, as this - * callback already know that it failed - */ - if ((mode == CY_SYSPM_CHECK_FAIL) && (curCallback != NULL)) - { - curCallback = curCallback->prevItm; - } - - /* Execute all registered callback functions with required type and mode */ - while ((curCallback != NULL) && (retVal != CY_SYSPM_FAIL)) - { - if ((curCallback->type == type) && ((curCallback->skipMode == 0UL) || - (((uint32_t) mode & curCallback->skipMode) == 0UL))) - { - /* Update elements for local callback parameter values */ - curParams.base = curCallback->callbackParams->base; - curParams.context = curCallback->callbackParams->context; - curParams.mode = mode; - - retVal = curCallback->callback(&curParams); - } - curCallback = curCallback->prevItm; - } - } - return (retVal); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_IoFreeze -****************************************************************************//** -* -* Freezes IOs. -* -* Freezes the IO cells directly to save the IO-cell state on a wakeup from the -* Hibernate. Do not call this function before entering the -* Hibernate mode, because Cy_SysPm_Hibernate() function freezes the IO cells. -* -******************************************************************************/ -void Cy_SysPm_IoFreeze(void) -{ - uint32_t interruptState; - uint32_t regValue; - - interruptState = Cy_SysLib_EnterCriticalSection(); - - /* Check the FREEZE state to avoid a recurrent IO-cells freeze attempt, - * because the second call to this function will cause an accidental switch - * to the hibernate mode (the system will enter the hibernate mode immediately - * after writing to the hibernate bit because both UNLOCK and FREEZE were set - * correctly in the previous call to this function). - */ - if(0U == _FLD2VAL(SRSS_PWR_HIBERNATE_FREEZE, SRSS->PWR_HIBERNATE)) - { - /* Clear the unlock field for correct freeze of the IO cells */ - SRSS->PWR_HIBERNATE = _CLR_SET_FLD32U((SRSS->PWR_HIBERNATE), SRSS_PWR_HIBERNATE_UNLOCK, 0U); - - /* Disable overriding by the peripherals the next pin-freeze command */ - SRSS->PWR_HIBERNATE |= CY_SYSPM_PWR_HIBERNATE_UNLOCK | - _VAL2FLD(SRSS_PWR_HIBERNATE_FREEZE, 1U) | - _VAL2FLD(SRSS_PWR_HIBERNATE_HIBERNATE, 1U); - - /* The second Write causes freeze of IO cells to save the IO-cell state */ - regValue = SRSS->PWR_HIBERNATE; - SRSS->PWR_HIBERNATE = regValue; - - /* Read register to make sure it is settled */ - (void) SRSS->PWR_HIBERNATE; - } - Cy_SysLib_ExitCriticalSection(interruptState); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_IoUnfreeze -****************************************************************************//** -* -* Unfreezes the IOs. -* -* The IO-cells remain frozen after a wakeup from the hibernate mode until the -* firmware unfreezes them after booting. The call of this function unfreezes the -* IO-cells explicitly. -* -* If the firmware needs to retain the data value on the port, then the -* value must be read and re-written to the data register before calling this -* API. Furthermore, the drive mode must be re-programmed. If this is not done, -* the pin state will change to the default state the moment the freeze -* is removed. -* -*******************************************************************************/ -void Cy_SysPm_IoUnfreeze(void) -{ - uint32_t interruptState; - interruptState = Cy_SysLib_EnterCriticalSection(); - - /* Preserve the last reset reason and wakeup polarity. Then, unfreeze I/O: - * write PWR_HIBERNATE.FREEZE=0, .UNLOCK=0x3A, .HIBERANTE=0, - */ - SRSS->PWR_HIBERNATE = (SRSS->PWR_HIBERNATE & CY_SYSPM_PWR_RETAIN_HIBERNATE_STATUS) | CY_SYSPM_PWR_HIBERNATE_UNLOCK; - - /* Lock the hibernate mode: - * write PWR_HIBERNATE.HIBERNATE=0, UNLOCK=0x00, HIBERANTE=0 - */ - SRSS->PWR_HIBERNATE &= CY_SYSPM_PWR_RETAIN_HIBERNATE_STATUS; - - /* Read register to make sure it is settled */ - (void) SRSS->PWR_HIBERNATE; - - Cy_SysLib_ExitCriticalSection(interruptState); -} - - -/******************************************************************************* -* Function Name: Cy_SetVoltageBitForFlash -****************************************************************************//** -* -* The internal function that changes the Vcc setting for the flash. -* -* \param setBit -* Set/clear the bit for the flash macro register. This bit should be set (true) -* when the voltage for the core regulators is less than 0.99 V. This bit should -* be set if the output voltage for the core regulators is higher than 0.99 V. -* -*******************************************************************************/ -static void Cy_SetVoltageBitForFlash(bool setBit) -{ - if(setBit) - { - FLASHC_FM_CTL->ANA_CTL0 |= _VAL2FLD(FLASHC_FM_CTL_ANA_CTL0_VCC_SEL, 1U); - } - else - { - FLASHC_FM_CTL->ANA_CTL0 &= ((uint32_t) (~_VAL2FLD(FLASHC_FM_CTL_ANA_CTL0_VCC_SEL, 1U))); - } -} - -#ifdef CY_IP_MXUDB - - /******************************************************************************* - * Function Name: Cy_SaveRegisters - ****************************************************************************//** - * - * The internal function saves non-retained registers before entering Deep Sleep. - * Cypress ID #280370. - * - * \param regs - * The structure where the registers are saved before Deep Sleep - * - *******************************************************************************/ - static void Cy_SaveRegisters(cy_stc_syspm_backup_regs_t *regs) - { - /* Save the registers before deep sleep */ - regs->CY_UDB_UDBIF_BANK_CTL_REG = UDB->UDBIF.BANK_CTL; - - regs->CY_UDB_BCTL_MDCLK_EN_REG = UDB->BCTL.MDCLK_EN; - regs->CY_UDB_BCTL_MBCLK_EN_REG = UDB->BCTL.MBCLK_EN; - regs->CY_UDB_BCTL_BOTSEL_L_REG = UDB->BCTL.BOTSEL_L; - regs->CY_UDB_BCTL_BOTSEL_U_REG = UDB->BCTL.BOTSEL_U; - regs->CY_UDB_BCTL_QCLK_EN0_REG = UDB->BCTL.QCLK_EN[0U]; - regs->CY_UDB_BCTL_QCLK_EN1_REG = UDB->BCTL.QCLK_EN[1U]; - regs->CY_UDB_BCTL_QCLK_EN2_REG = UDB->BCTL.QCLK_EN[2U]; - } - - - /******************************************************************************* - * Function Name: Cy_RestoreRegisters - ****************************************************************************//** - * - * The internal function restores the non-retained registers after - * leaving the Deep Sleep power mode. Cypress ID #280370. - * - * \param regs - * The structure with data stored into the required non-retained registers - * after Deep Sleep. - * - *******************************************************************************/ - static void Cy_RestoreRegisters(cy_stc_syspm_backup_regs_t const *regs) - { - /* Restore the registers after deep sleep */ - UDB->BCTL.MDCLK_EN = regs->CY_UDB_BCTL_MDCLK_EN_REG; - UDB->BCTL.MBCLK_EN = regs->CY_UDB_BCTL_MBCLK_EN_REG; - UDB->BCTL.BOTSEL_L = regs->CY_UDB_BCTL_BOTSEL_L_REG; - UDB->BCTL.BOTSEL_U = regs->CY_UDB_BCTL_BOTSEL_U_REG; - UDB->BCTL.QCLK_EN[0U] = regs->CY_UDB_BCTL_QCLK_EN0_REG; - UDB->BCTL.QCLK_EN[1U] = regs->CY_UDB_BCTL_QCLK_EN1_REG; - UDB->BCTL.QCLK_EN[2U] = regs->CY_UDB_BCTL_QCLK_EN2_REG; - - UDB->UDBIF.BANK_CTL = regs->CY_UDB_UDBIF_BANK_CTL_REG; - } -#endif /* CY_IP_MXUDB */ - - -/******************************************************************************* -* Function Name: Cy_EnterDeepSleep -****************************************************************************//** -* -* The internal function that prepares the system for Deep Sleep and -* restores the system after a wakeup from Deep Sleep. -* -* \param waitFor Selects wait for action. See \ref cy_en_syspm_waitfor_t. -* -*******************************************************************************/ -#if defined (__ICCARM__) - __ramfunc -#else - CY_SECTION(".cy_ramfunc") -#endif -static void Cy_EnterDeepSleep(cy_en_syspm_waitfor_t waitFor) -{ - /* Aquire the IPC to prevent changing of the shared resources at the same time */ - while(0U == _FLD2VAL(IPC_STRUCT_ACQUIRE_SUCCESS, CY_SYSPM_IPC_STC->ACQUIRE)) - { - /* Wait until the IPC structure is released by another core */ - } - - /* Set the flag that current core went to Deep Sleep */ - CY_SYSPM_IPC_STC->DATA |= CY_SYSPM_CUR_CORE_DP_MASK; - - /* Change the slow and fast clock dividers only under condition that - * the other core is already in Deep Sleep. Cypress ID #284516 - */ - if (0U != (CY_SYSPM_IPC_STC->DATA & CY_SYSPM_OTHER_CORE_DP_MASK)) - { - /* Get the divider values of the slow and high clocks and store them into - * the IPC data register - */ - CY_SYSPM_IPC_STC->DATA = - (CY_SYSPM_IPC_STC->DATA & ((uint32_t) ~(CY_SYSPM_FAST_CLK_DIV_Msk | CY_SYSPM_SLOW_CLK_DIV_Msk))) | - (((uint32_t) (_FLD2VAL(CPUSS_CM0_CLOCK_CTL_SLOW_INT_DIV, CPUSS->CM0_CLOCK_CTL) << CY_SYSPM_SLOW_CLK_DIV_Pos)) | - ((uint32_t) (_FLD2VAL(CPUSS_CM4_CLOCK_CTL_FAST_INT_DIV, CPUSS->CM4_CLOCK_CTL) << CY_SYSPM_FAST_CLK_DIV_Pos))); - - /* Increase the clock divider for the slow and fast clocks to CY_SYSPM_CLK_DIVIDER */ - CPUSS->CM0_CLOCK_CTL = - _CLR_SET_FLD32U(CPUSS->CM0_CLOCK_CTL, CPUSS_CM0_CLOCK_CTL_SLOW_INT_DIV, CY_SYSPM_CLK_DIVIDER); - - CPUSS->CM4_CLOCK_CTL = - _CLR_SET_FLD32U(CPUSS->CM4_CLOCK_CTL, CPUSS_CM4_CLOCK_CTL_FAST_INT_DIV, CY_SYSPM_CLK_DIVIDER); - - /* Read the divider value to make sure it is set */ - (void) CPUSS->CM0_CLOCK_CTL; - (void) CPUSS->CM4_CLOCK_CTL; - } - - /* Release the IPC */ - CY_SYSPM_IPC_STC->RELEASE = 0U; - - /* Read this register to make sure it is settled */ - (void) CY_SYSPM_IPC_STC->RELEASE; - -#if(0u != CY_CPU_CORTEX_M0P) - - /* The CPU enters the deep sleep mode upon execution of WFI/WFE */ - SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; - - if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) - { - __WFI(); - } - else - { - __WFE(); - } -#else - - /* Repeat the WFI/WFE instructions if a wake up was not intended. - * Cypress ID #272909 - */ - do - { - /* The CPU enters Deep Sleep mode upon execution of WFI/WFE */ - SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; - - if(waitFor != CY_SYSPM_WAIT_FOR_EVENT) - { - __WFI(); - } - else - { - __WFE(); - - /* Call the WFE instructions twice to clear the Event register - * of the CM4 core. Cypress ID #279077 - */ - if(wasEventSent) - { - __WFE(); - } - - wasEventSent = true; - } - } while (_FLD2VAL(CPUSS_CM4_PWR_CTL_PWR_MODE, CPUSS->CM4_PWR_CTL) == CY_SYSPM_CM4_PWR_RETAINED); - -#endif /* (0u != CY_CPU_CORTEX_M0P) */ - - /* Aquire the IPC to prevent changing of the shared resources at the same time */ - while(0U == _FLD2VAL(IPC_STRUCT_ACQUIRE_SUCCESS, CY_SYSPM_IPC_STC->ACQUIRE)) - { - /* Wait until the IPC structure is released by another core */ - } - - /* Read and change the slow and fast clock dividers only under condition - * that the other core is already in Deep Sleep. Cypress ID #284516 - */ - if(0U != (CY_SYSPM_IPC_STC->DATA & CY_SYSPM_OTHER_CORE_DP_MASK)) - { - /* Restore the clock dividers for the slow and fast clocks */ - CPUSS->CM0_CLOCK_CTL = - (_CLR_SET_FLD32U(CPUSS->CM0_CLOCK_CTL, CPUSS_CM0_CLOCK_CTL_SLOW_INT_DIV, - (_FLD2VAL(CY_SYSPM_SLOW_CLK_DIV, CY_SYSPM_IPC_STC->DATA)))); - - CPUSS->CM4_CLOCK_CTL = - (_CLR_SET_FLD32U(CPUSS->CM4_CLOCK_CTL, CPUSS_CM4_CLOCK_CTL_FAST_INT_DIV, - (_FLD2VAL(CY_SYSPM_FAST_CLK_DIV, CY_SYSPM_IPC_STC->DATA)))); - } - - /* Indicate that the current core is out of Deep Sleep */ - CY_SYSPM_IPC_STC->DATA &= ((uint32_t) ~CY_SYSPM_CUR_CORE_DP_MASK); - - /* Release the IPC */ - CY_SYSPM_IPC_STC->RELEASE = 0U; -} -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syspm/cy_syspm.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syspm/cy_syspm.h deleted file mode 100644 index 36648cf9a4..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/drivers/peripheral/syspm/cy_syspm.h +++ /dev/null @@ -1,1734 +0,0 @@ -/***************************************************************************//** -* \file cy_syspm.h -* \version 2.0 -* -* Provides the function definitions for the power management API. -* -******************************************************************************** -* \copyright -* Copyright 2016-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -* -*******************************************************************************/ - -/** -* \defgroup group_syspm System Power Management (SysPm) -* \{ -* Power Modes -* -* Devices support the following power modes (in the order of -* high-to-low power consumption): Active, Sleep, Low Power (LP) Active, -* LP Sleep, DeepSleep, and Hibernate. -* Active and Sleep are the standard ARM-defined power modes, supported by the -* ARM CPUs. -* DeepSleep is a lower-power mode where high-frequency clocks are disabled. -* Most of the register state is retained and the platform supports saving a -* configurable amount of the SRAM state. -* Hibernate is an even lower power mode that is entered from firmware, -* just like DeepSleep. However, on a wakeup the CPU and all peripherals go -* through a full reset. -* -* The SysPm driver is used to enter low-power states to reduce system -* power consumption in power sensitive designs. For multi-core devices this -* library allows the user to individually power down each CPU into Sleep or -* DeepSleep. -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
CM0+ ModeCM4 ModePower Mode (SRSS)Mode Description
ActiveActiveNormalAll Clocks and peripherals may operate or optionally can -* be disabled. Current load limitation is set as for -* active power mode(*1).
SleepActiveNormalAll Clocks and peripherals may operate or optionally can -* be disabled. Current load limitation is set as for -* active power mode(*1).
DeepSleepActiveNormalAll Clocks and peripherals may operate or optionally can -* be disabled. Current load limitation is set as for -* active power mode(*1).
SleepSleepNormalAll Clocks and peripherals may operate, CPUs Off. Current load -* limitation is set as for active power mode(*1).
DeepSleepSleepNormalAll Clocks and peripherals may operate, CPUs Off. Current load -* limitation is set as for active power mode(*1).
ActiveSleepNormalAll Clocks and peripherals may operate or optionally can -* be disabled. Current load limitation is set as for -* active power mode(*1).
ActiveDeepSleepNormalAll Clocks and peripherals may operate or optionally can -* be disabled. Current load limitation is set as for -* active power mode(*1).
SleepDeepSleepNormalAll Clocks and peripherals may operate, CPUs Off. Current load -* limitation is set as for active power mode(*1).
DeepSleepDeepSleepDeepSleepAll the MHz clocks are off, but so is the DSI routing, and most Analog -* and voltage references are off by default. Only ILO/WCO may operate, -* limited peripherals.
Active (LPActive)Active (LPActive)Low powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive power mode.
Sleep (LPSleep)Active (LPActive)Low powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive power mode.
DeepSleepActive (LPActive)Low powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive power mode.
Active (LPActive)Sleep (LPSleep)Low powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive power mode.
Sleep (LPSleep)Sleep (LPSleep)Low powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive mode. The CPUs are off.
DeepSleepSleep (LPSleep)Low powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive. The CPUs are off
Active (LPActive)DeepSleepLow powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive power mode.
Sleep (LPSleep)DeepSleepLow powerAll the MHz clocks frequencies should be decreased, if needed, to meet -* current load limitations (*1). Peripherals should be slowed, -* if needed, or/and optionally disabled to meet current load limitations -* in LPActive power mode. The CPUs are off
DeepSleepDeepSleepDeepSleepThe entire chip is in a DeepSleep, since it forces the MHz -* clocks, DSI, UDBs, most peripherals, analog, etc., to be shut down. -* Only ILO/WCO may operate, limited peripherals.
--HibernateOnce Hibernate is set, everything goes into the hibernate power mode. -* Only ILO may operate to assert wake-up device using WDT or RTC.
-* -* (*1) When the device switches into LPActive power mode the SysPm driver does -* not decrease clocks or peripherals. The SysPm driver only switches the supply -* regulators into low power mode. It is the user's responsibility to configure -* clocks and/or peripherals to meet current load limitation in LPActive power -* mode. For more details about power modes and current load limitations refer to -* the device Technical Reference Manual (TRM). -* -* Power modes: -* * Active - In this mode the CPU executes code, and all logic and memories -* are powered. Firmware may decide to disable clocks for specific peripherals -* and to power down specific analog power domains. The chip enters Active upon -* initial reset. For internally-generated resets, the chip enters the most -* recently used power mode among Active and LPActive. -* -* * Sleep - In this mode the CPU does not execute code and its clock is -* stopped. It is identical to ACTIVE from a peripheral point of view. -* -* * LPActive - Low-Power Active is similar to Active, with clock -* restrictions and limited/slowed peripheral to achieve a lower system current. -* -* * LPSleep - Low-Power Sleep mode operates the same as Sleep mode -* with the clocking limitations of LPActive mode to further reduce system power. -* -* * DeepSleep - In DeepSleep mode the main system clock is off for CPU, -* Flash, and high-speed logic. Optionally, the low frequency (32.768 kHz) clock -* remains on, and low-frequency peripherals continue operating. -* Peripherals that do not need a clock or receive a clock from their external -* interface (e.g., I2C/SPI) continue operating, and all circuits that draw -* current from the Vccdpslp supply are subject to the current sourcing -* limitations of the DeepSleep Regulator (if the core is supplied by the -* Linear core regulator). If the core is supplied by the SIMO Buck regulator all -* deep sleep peripherals are supplied by Vbuck1. -* A normal wakeup from deep sleep returns to either LPActive, LPSleep, -* Active, or Sleep, depending on the previous state and programmed behavior for -* the configured wakeup interrupt. -* Likewise, a debug wakeup from deep sleep returns to LPSleep or Sleep, -* depending on which mode was used to enter the deep sleep power mode. -* -* * Hibernate - Is the lowest power mode available when external supplies are -* present. It is intended for applications in a dormant state. -* Hibernate is implemented using high voltage logic and switches off all -* internal regulators. The Backup domain continues functioning normally. -* The I/O's state is frozen so that the output driver state is held. -* Note in this mode the CPU and all peripherals lose state, so the system and -* firmware reboot on a wakeup event. -* Wakeup is supported from device specific pin(s) with programmable -* polarity. Additionally, unregulated peripherals can wake the device under -* some conditions. For example, a low-power comparator can wake the device by -* comparing two external voltages but may not support comparison to an -* internally-generated voltage. The Backup domain remains functional, and if -* present it can schedule an alarm to wake the device from Hibernate using RTC. -* The combination of Hibernate and Backup alarms can yield low current duty -* cycling for applications, such as waking once per second for a CapSense -* scan. Alternatively, the Watchdog Timer (WDT) can be configured to wake-up the -* device by WDT interrupt. -* Backup memory (BMEM) can be used to store system state for use on the -* next reboot. -* -* The system can wakeup from hibernate power mode by configuring: -* * Wakeup pin -* * WDT interrupt -* * LP Comparator -* * WDT reset - this can be configured without using the SysPm driver. Just -* configure and enable the WDT before entering the hibernate power mode. All -* other events require use of the API from the SysPm driver. -* -* * XRES - is the state of the part when XRES is applied. This is obviously a -* reset condition, but it is also considered a power mode because some low-power -* applications, such as remote controls, expect very low current consumption -* when XRES is asserted. -* -* * OFF - The OFF state simply represents the state of the part with no power -* applied to it (except perhaps the Backup domain). In some applications, power -* to the device will be switched on and off by another device in the system to -* make the product implement the lowest power consumption level. -* -* Wakeup time after a reset is device-dependent because of the boot run-time. -* The wakeup time varies depending on the number and type of trim parameters and -* the size of device Flash. -* -* For ARM-based devices, an interrupt is required for the CPU to -* wake up. -* -* All pending interrupts should be cleared before the device is put into a -* low-power mode, even if they are masked. -* -* \section group_syspm_section_configuration Configuration Considerations -* After initial device boot the device goes into Active power mode. After some -* code execution the device could be sent into low power mode. -* -* For multi-core devices the Cy_SysPm_Sleep() and Cy_SysPm_DeepSleep() -* functions only switch the core that calls the function into the sleep or the -* deep sleep power mode. To set the whole device the sleep or the deep sleep -* power mode, ensure that each core calls the Cy_SysPm_Sleep() or -* Cy_SysPm_DeepSleep() functions. -* -* There are situations when the device does not switch into the deep sleep power -* mode immediately after the second core calls Cy_SysPm_DeepSleep(). The device -* will switch into the deep sleep mode automatically a little bit later, -* after the low-power circuits are ready to switch into deep sleep. -* Refer to the Cy_SysPm_DeepSleep() description for more details. -* -* If you call Cy_SysPm_Hibernate() the device will be switched -* into the hibernate power mode directly, as there is no handshake -* between cores. -* -* Before switching into LPActive power mode ensure that the device meets the -* current load limitation by decreasing the Mhz clocks, and slowing or disabling -* peripherals. Refer to the device TRM for more details about current load -* limitations in different low-power modes. -* -* The SysPm driver also provides an API to configure the external power -* management integrated circuit (PMIC) that supplies Vddd. -* Use the API to enable the PMIC output that is routed to pmic_wakeup_out pin, -* and configure the polarity of the PMIC input (pmic_wakeup_in) that is used to -* wakeup the PMIC. -* -* The PMIC is automatically enabled when:
-* * the PMIC is locked
-* * the configured polarity of PMIC input and the polarity driven to -* pmic_wakeup_in pin matches. -* -* Note that PMIC remain disabled (either the PMIC or PMIC output) only when -* the PMIC is unlocked. See Cy_SysPm_UnlockPmic() for more details. Use -* Cy_SysPm_IsPmicLocked() to read the current PMIC lock status. -* -* To enable the PMIC, use these functions in this order: -* 1 Cy_SysPm_UnlockPmic(); -* 2 Cy_SysPm_EnablePmic(); -* 3 CY_SysPm_LockPmic(); -* -* After this sequence the PMIC will be enabled regardless to its lock state. -* -* To disable the PMIC block, call Cy_SysPm_DisablePmic() with the inverted -* value of the current active state of the pmic_wakeup_in pin. -* For example, assume the current state of the pmic_wakeup_in pin is active low. -* To disable the PMIC call these functions in this order: -* 1 Cy_SysPm_UnlockPmic(); -* 2 Cy_SysPm_DisablePmic(CY_SYSPM_PMIC_POLARITY_HIGH); -* Do not call Cy_SysPm_LockPmic() (which automatically enables the PMIC). -* -* While disabled, the PMIC block is automatically enabled when the -* pmic_wakeup_in pin state is changed into high state. -* -* To disable the PMIC output, call these functions in this order: -* Cy_SysPm_UnlockPmic(); -* Cy_SysPm_DisablePmicOutput(); -* Do not call Cy_SysPm_LockPmic() (which automatically enables the PMIC output). -* -* When disabled, the PMIC output is enabled when the PMIC is locked, or by -* calling Cy_SysPm_EnablePmicOutput(). -* -* \section group_syspm_callbacks SysPm Callbacks -* The SysPm driver implements a callback mechanism. Using a SysPm callback, -* you perform actions right before entering low-power mode, and directly -* after switching out of low-power mode. With the callback mechanism you -* can prevent switching into low power mode if, for example, a peripheral -* is not ready to enter into the requested low-power mode. -* -* \subsection group__syspm_callback_config Callback Configuration Considerations -* -* Firmware must register each callback. You may have up to 32 callback -* functions. -* -* For each callback, provide a cy_stc_syspm_callback_t structure. Some fields -* in this structure are maintained by the driver. Use NULL for prevItm -* and nextItm. The driver uses these fields to build a linked list of -* callback functions. -* -* The callbackParams element is a cy_stc_syspm_callback_params_t -* structure. The mode element of this structure is for internal use. -* The driver sets that field to the correct value before calling the callback -* function. The callback function reads the value and acts based on the -* mode. -* -* The base and context pointers are optional and can be NULL. -* A callback function is typically associated with a particular driver. Some -* drivers require a base hardware address and a context. If your callback -* routine needs access to the driver registers or context, provide those values. -* Be aware of MISRA warnings if these parameters are NULL. -* -* Call Cy_SysPm_RegisterCallback() to register each callback function. The -* functions will be called based on the order in which they are registered. -* In some cases they are called first to last; in other cases last to first. -* -* \warning The Cy_SysPm_RegisterCallback() function stores a pointer to the -* cy_stc_syspm_callback_t variable. Do not modify elements of the -* cy_stc_syspm_callback_t structure after the callback is registered. -* It is the user's responsibility to ensure that the variable remains in scope. -* Typically the structure is declared as a global or static variable, or as a -* local variable in the main() function. -* -* See the SysPM Callbacks Example section for pseudocode that handles -configuration. -* -* Also refer to Cy_SysPm_Sleep(), Cy_SysPm_DeepSleep(), Cy_SysPm_EnterLpMode(), -* Cy_SysPm_ExitLpMode(), and Cy_SysPm_Hibernate() for more details. -* -* \subsection group__syspm_callback_flow SysPm Callbacks Flow -* -* This section explains what happens during a power transition, when callbacks -* are implemented and set up correctly. The SysPm Callbacks Example section -* provides pseudocode that shows how to do this. -* -* The following discussion assumes: -* * All required callback functions are defined and implemented
-* * All cy_stc_syspm_callback_t structures are filled with required values
-* * All callbacks are successfully registered
-* -* When a power transition occurs, the driver uses Cy_SysPm_ExecuteCallback(). -* There are four possible modes of operation, defined in -* cy_en_syspm_callback_mode_t. A particular callback function can skip modes. -* The modes are: -* * CY_SYSPM_CHECK_READY -* * CY_SYSPM_CHECK_FAIL -* * CY_SYSPM_BEFORE_TRANSITION -* * CY_SYSPM_AFTER_TRANSITION -* -* The SysPm driver calls each registered callback in order, with the same mode. -* For example, each callback is called and should handle the "ready" event. -* The driver then moves on to the next mode, and repeats calling all the -* registered callbacks. -* -* When a function is called that attempts to switch a device into low -* power mode, the flow of events is:
-* 1. All registered callbacks are called with CY_SYSPM_CHECK_READY argument. -* Callbacks are executed in order registered (first to last).
-* 2. If a callback returns CY_SYSPM_FAIL for the readiness check, then:
-* A. The remaining callbacks are not executed.
-* B. Any callbacks that have already executed are called again, in reverse -* order, with CY_SYSPM_CHECK_FAIL. They are called from last to first to -* allow the system to return to the previous state.
-* C. The function that attempted to switch the device into a low power mode -* returns CY_SYSPM_FAIL.
-* 3. If all callback function pass the CY_SYSPM_CHECK_READY process, then:
-* A. All callback functions are called with THE CY_SYSPM_BEFORE_TRANSITION -* argument. Callbacks are executed in order registered (first to last).
-* B. When the callbacks are complete the device enters the low power mode.
-* C. The device returns from low power mode based on a wakeup event -* (interrupt, event). (This step is not applicable for the transitions: -* LPActive to Active and from Active to LPActive which must be called from the -* code.)
-* D. After wakeup, all callbacks are called with the CY_SYSPM_AFTER_TRANSITION -* argument. Callbacks are executed last to first. This step is not applicable -* for wakeup from the Hibernate power mode, because the device is rebooted.
-* E. The function that switched the device to low power mode returns -* CY_SYSPM_PASS.
-* -* If there are no callbacks registered, the device just executes the -* power mode transition. -* -* A callback should return CY_SYSPM_FAIL only in response to -* CY_SYSPM_CHECK_READY. The callback function should always return CY_SYSPM_PASS -* for other modes: -* CY_SYSPM_CHECK_FAIL, CY_SYSPM_BEFORE_TRANSITION, and -* CY_SYSPM_AFTER_TRANSITION. -* -* Callbacks that reconfigure global resources, such as clock frequencies, -* should be registered last. -* -* \subsection group__syspm_callback_example SysPm Callbacks Example -* -* The following pseudo code example demonstrates how use the SysPm callbacks -* mechanism. It also shows a prototype for an application Deep Sleep -* callback function. This code assumes:
-* * This is a dual-core device: CM0+ and CM4 cores
-* * The CM0+ core is already in Deep Sleep
-* * The code is executed on the CM4
-* -* The main.c file of CM4 core would look like this: -* -* \snippet syspm/syspm_2_0_sut_01.cydsn/main_cm4.c SysPm Callback Example -* -* \section group_syspm_section_more_information More Information -* For more information on the Power Modes (SysPm) driver, -* refer to the Technical Reference Manual (TRM). -* -* \section group_syspm_MISRA MISRA-C Compliance -* The SysPm driver does not have any specific deviations. -* -* \section group_syspm_changelog Changelog -* -* -* -* -* -* -* -* -* -* -* -* -*
VersionChangesReason for Change
1.0Initial version
2.0Enhancement and defect fixes:
-* * Added input parameter(s) validation to all public functions.
-* * Removed "_SysPm_" prefixes from the internal functions names.
-* * Changed the type of elements with limited set of values, from -* uint32_t to enumeration. -* * Enhanced syspm callback mechanism. -*
-* -* \defgroup group_syspm_macros Macros -* \defgroup group_syspm_functions Functions -* \defgroup group_syspm_data_structures Data Structures -* \defgroup group_syspm_data_enumerates Enumerated types -*/ - -#ifndef _CY_SYSPM_H_ -#define _CY_SYSPM_H_ - -#include -#include -#include "cy_device_headers.h" -#include "syslib/cy_syslib.h" -#include "ipc/cy_ipc_sema.h" -#include "ipc/cy_ipc_drv.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************* -* Register Constants -*******************************************************************************/ - -/** -* \addtogroup group_syspm_macros -* \{ -*/ - -/** Driver major version */ -#define CY_SYSPM_DRV_VERSION_MAJOR 2 - -/** Driver minor version */ -#define CY_SYSPM_DRV_VERSION_MINOR 0 - -/** \cond INTERNAL */ - -/** The internal define for clock divider */ -#define CY_SYSPM_CLK_DIVIDER (9U) - -/** The internal define of the unlock value for the PMIC functions */ -#define CY_SYSPM_PMIC_UNLOCK_KEY (0x3AU) - -/** The internal define of the tries number in the Cy_SysPm_ExitLpMode() -* function -*/ -#define CY_SYSPM_WAIT_DELAY_TRYES (100U) - -/** The internal define of the first wakeup pin bit used in the -* Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_PIN0_BIT (1UL) - -/** The internal define of the second wakeup pin bit -* used in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_PIN1_BIT (2UL) - -/** -* The internal define of the first LPComparator bit -* used in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_LPCOMP0_BIT (4UL) - -/** -* The internal define for the second LPComparator bit -* used in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_LPCOMP1_BIT (8UL) - -/** -* The internal define of the first LPComparator value -* used in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_LPCOMP0 ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << \ - SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) - -/** -* The internal define of the second LPComparator value -* used in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_LPCOMP1 ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << \ - SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) - -/** -* The internal define of the first wake-up pin value -* used in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_PIN0 ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << \ - SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) - -/** -* The internal define of the second wake-up pin value used -* in the Cy_SysPm_SetHibWakeupSource() function -*/ -#define CY_SYSPM_WAKEUP_PIN1 ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << \ - SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos) - -/** The internal define for the first LPComparator polarity configuration */ -#define CY_SYSPM_WAKEUP_LPCOMP0_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << \ - SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) - -/** The internal define for the second LPComparator polarity configuration */ -#define CY_SYSPM_WAKEUP_LPCOMP1_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << \ - SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) - -/** The internal define for the first wake-up pin polarity configuration */ -#define CY_SYSPM_WAKEUP_PIN0_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << \ - SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) - -/** The internal define for the second wake-up pin polarity configuration */ -#define CY_SYSPM_WAKEUP_PIN1_POLARITY_HIGH ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << \ - SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) - -/* Mask for the fast clock divider value */ -#define CY_SYSPM_FAST_CLK_DIV_Msk (0xFF000000UL) - -/* Position for the fast clock divider value */ -#define CY_SYSPM_FAST_CLK_DIV_Pos (24UL) - -#define CY_SYSPM_IPC_STC IPC_STRUCT7 - -/* Mask for the slow clock divider value */ -#define CY_SYSPM_SLOW_CLK_DIV_Msk (0x00FF0000UL) - -/* Position for the slow clock divider value */ -#define CY_SYSPM_SLOW_CLK_DIV_Pos (16UL) - -#if(0u != CY_CPU_CORTEX_M4) - #define CY_SYSPM_CUR_CORE_DP_MASK (0x01UL) - #define CY_SYSPM_OTHER_CORE_DP_MASK (0x02UL) -#else - #define CY_SYSPM_CUR_CORE_DP_MASK (0x02UL) - #define CY_SYSPM_OTHER_CORE_DP_MASK (0x01UL) -#endif - -/** \endcond */ - -/** syspm driver identifier */ -#define CY_SYSPM_ID (CY_PDL_DRV_ID(0x10U)) - -/** -* \defgroup group_syspm_return_status The Power Mode Status Defines -* \{ -* The defines of the core(s) and device power mode status. -*/ -#if(0u != CY_IP_M4CPUSS) - - /** The CM4 is Active */ - #define CY_SYSPM_STATUS_CM4_ACTIVE (0x01U) - - /** The CM4 is in Sleep */ - #define CY_SYSPM_STATUS_CM4_SLEEP (0x02U) - - /** The CM4 is in DeepSleep */ - #define CY_SYSPM_STATUS_CM4_DEEPSLEEP (0x04U) - - /** The CM4 is Low Power mode */ - #define CY_SYSPM_STATUS_CM4_LOWPOWER (0x80U) - - /** The define of retained power mode of the CM4 */ - #define CY_SYSPM_CM4_PWR_RETAINED (2UL) - -#endif /* (0u != CY_IP_M4CPUSS) */ - -/** The CM0 is Active */ -#define CY_SYSPM_STATUS_CM0_ACTIVE ((uint32_t) ((uint32_t)0x01U << 8U)) - -/** The CM0 is in Sleep */ -#define CY_SYSPM_STATUS_CM0_SLEEP ((uint32_t) ((uint32_t)0x02U << 8U)) - -/** The CM0 is in DeepSleep */ -#define CY_SYSPM_STATUS_CM0_DEEPSLEEP ((uint32_t) ((uint32_t)0x04U << 8U)) - -/** The CM0 is in low power mode */ -#define CY_SYSPM_STATUS_CM0_LOWPOWER ((uint32_t) ((uint32_t)0x80U << 8U)) - -#if(0u != CY_IP_M4CPUSS) - - /** The device is in the low power mode define */ - #define CY_SYSPM_STATUS_SYSTEM_LOWPOWER ((uint32_t) (CY_SYSPM_STATUS_CM0_LOWPOWER | \ - (CY_SYSPM_STATUS_CM4_LOWPOWER))) -#else - /** The device is in the low power mode define */ - #define CY_SYSPM_STATUS_SYSTEM_LOWPOWER CY_SYSPM_STATUS_CM0_LOWPOWER - -#endif /* (0u != CY_IP_M4CPUSS) */ -/** \} group_syspm_return_status */ - -/** The define to update the token to indicate the transition into Hibernate */ -#define CY_SYSPM_PWR_TOKEN_HIBERNATE ((uint32_t) 0x1BU << SRSS_PWR_HIBERNATE_TOKEN_Pos) - -/** The wait time for transition of the device from the Active into -* the LPActive -*/ -#define CY_SYSPM_ACTIVE_TO_LP_WAIT_US (1U) - -/** The wait delay time which occurs before the Active reference is settled. -* This delay is used in transition of the device from Active into the LPActive -* low-power mode -*/ -#define CY_SYSPM_LP_TO_ACTIVE_WAIT_BEFORE_US (8U) - -/** The wait delay time which occurs after the Active reference is settled. -* This delay is used in transition the device from Active into the LPActive -* low-power mode -*/ -#define CY_SYSPM_LP_TO_ACTIVE_WAIT_AFTER_US (1U) - -/** The maximum callbacks number */ -#define CY_SYSPM_CALLBACKS_NUMBER_MAX (32U) - -/** The mask to unlock the Hibernate power mode */ -#define CY_SYSPM_PWR_HIBERNATE_UNLOCK ((uint32_t) 0x3Au << SRSS_PWR_HIBERNATE_UNLOCK_Pos) - -/** The mask to set the Hibernate power mode */ -#define CY_SYSPM_PWR_SET_HIBERNATE ((uint32_t) CY_SYSPM_PWR_HIBERNATE_UNLOCK |\ - SRSS_PWR_HIBERNATE_FREEZE_Msk |\ - SRSS_PWR_HIBERNATE_HIBERNATE_Msk) - -/** The mask to retain the Hibernate power mode status */ -#define CY_SYSPM_PWR_RETAIN_HIBERNATE_STATUS ((uint32_t) SRSS_PWR_HIBERNATE_TOKEN_Msk |\ - SRSS_PWR_HIBERNATE_MASK_HIBALARM_Msk |\ - SRSS_PWR_HIBERNATE_MASK_HIBWDT_Msk |\ - SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Msk |\ - SRSS_PWR_HIBERNATE_MASK_HIBPIN_Msk) - -/** The mask for the wakeup sources */ -#define CY_SYSPM_PWR_WAKEUP_HIB_MASK ((uint32_t) SRSS_PWR_HIBERNATE_MASK_HIBALARM_Msk |\ - SRSS_PWR_HIBERNATE_MASK_HIBWDT_Msk |\ - SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Msk |\ - SRSS_PWR_HIBERNATE_MASK_HIBPIN_Msk) - -/** -* \defgroup group_syspm_skip_callback_modes The defines to skip the callbacks modes -* \{ -* The defines of the syspm callbacks modes that can be skipped during execution. -* For more information about callbacks modes refer -* to \ref cy_en_syspm_callback_mode_t. -*/ -#define CY_SYSPM_SKIP_CHECK_READY (0x01U) /**< The define to skip the check ready mode in the syspm callback */ -#define CY_SYSPM_SKIP_CHECK_FAIL (0x02U) /**< The define to skip the check fail mode in the syspm callback */ -#define CY_SYSPM_SKIP_BEFORE_TRANSITION (0x04U) /**< The define to skip the before transition mode in the syspm callback */ -#define CY_SYSPM_SKIP_AFTER_TRANSITION (0x08U) /**< The define to skip the after transition mode in the syspm callback */ -/** \} group_syspm_skip_callback_modes */ - -#if(0u != SRSS_SIMOBUCK_PRESENT) - - /** The definition for the delay of the SIMO Buck supply regulator - * stabilization after it was configured with enabled SIMO Buck output 1 */ - #define CY_SYSPM_SIMO_BUCK_CORE_SUPPLY_STABLE_US (900U) - - /** The definition for the delay of the SIMO Buck supply regulator - * stabilization after it was configured with enabled SIMO Buck - * output 2 only - */ - #define CY_SYSPM_SIMO_BUCK_BLE_SUPPLY_STABLE_US (600U) - - /** The definition for the delay of the Linear Regulator after its output - * voltage is changed - */ - #define CY_SYSPM_LDO_IS_STABLE_US (9U) - - /** The definition for the delay of the SIMO Buck regulator after its output - * voltage is changed - */ - #define CY_SYSPM_SIMO_BUCK_IS_STABLE_US (200U) - -#endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ - -/** \cond INTERNAL */ - -/* Internal macro of all possible wakeup sources from hibernate power mode */ -#define CY_SYSPM_HIB_WAKEUP_SOURSE_MASK (CY_SYSPM_LPCOMP0_HIGH | CY_SYSPM_LPCOMP1_HIGH | \ - CY_SYSPM_HIBALARM | CY_SYSPM_HIBWDT | \ - CY_SYSPM_HIBPIN0_HIGH | CY_SYSPM_HIBPIN1_HIGH) - -/* Macro to validate parameters in Cy_SysPm_SetHibWakeupSource() and for Cy_SysPm_ClearHibWakeupSource() function */ -#define CY_SYSPM_IS_WAKE_UP_SOURCE_VALID(wakeupSource) (0UL == ((wakeupSource) & \ - ((uint32_t) ~(CY_SYSPM_HIB_WAKEUP_SOURSE_MASK)))) - -/* Macro to validate parameters in Cy_SysPm_DisablePmic() function */ -#define CY_SYSPM_IS_POLARITY_VALID(polarity) (((polarity) == CY_SYSPM_PMIC_POLARITY_LOW) || \ - ((polarity) == CY_SYSPM_PMIC_POLARITY_HIGH)) - -/* Macro to validate parameters in Cy_SysPm_SimoBuckSetVoltage1() function */ -#define CY_SYSPM_IS_SIMO_BUCK_VOLTAGE1_VALID(voltage) (((voltage) == CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V)) - -/* Macro to validate parameters in Cy_SysPm_SimoBuckSetVoltage2() function */ -#define CY_SYSPM_IS_SIMO_BUCK_VOLTAGE2_VALID(voltage) (((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_15V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_2V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_25V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_3V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_35V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_4V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_45V) || \ - ((voltage) == CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_5V)) - -/* Macro to validate parameters in Cy_SysPm_SimoBuckOutputIsEnabled() function */ -#define CY_SYSPM_IS_SIMO_BUCK_OUTPUT_VALID(output) (((output) == CY_SYSPM_BUCK_VBUCK_1) || \ - ((output) == CY_SYSPM_BUCK_VRF)) - -/* Macro to validate parameters in Cy_SysPm_LdoSetVoltage() function */ -#define CY_SYSPM_IS_LDO_VOLTAGE_VALID(voltage) (((voltage) == CY_SYSPM_LDO_VOLTAGE_0_9V) || \ - ((voltage) == CY_SYSPM_LDO_VOLTAGE_1_1V)) - -/* Macro to validate parameters in Cy_SysPm_ExecuteCallback() function */ -#define CY_SYSPM_IS_CALLBACK_TYPE_VALID(type) (((type) == CY_SYSPM_SLEEP) || \ - ((type) == CY_SYSPM_DEEPSLEEP) || \ - ((type) == CY_SYSPM_HIBERNATE) || \ - ((type) == CY_SYSPM_ENTER_LP_MODE) || \ - ((type) == CY_SYSPM_EXIT_LP_MODE)) - -/* Macro to validate parameters in Cy_SysPm_ExecuteCallback() function */ -#define CY_SYSPM_IS_CALLBACK_MODE_VALID(mode) (((mode) == CY_SYSPM_CHECK_READY) || \ - ((mode) == CY_SYSPM_CHECK_FAIL) || \ - ((mode) == CY_SYSPM_BEFORE_TRANSITION) || \ - ((mode) == CY_SYSPM_AFTER_TRANSITION)) - -/* Macro to validate parameters in Cy_SysPm_Sleep() and for Cy_SysPm_DeepSleep() function */ -#define CY_SYSPM_IS_WAIT_FOR_VALID(waitFor) (((waitFor) == CY_SYSPM_WAIT_FOR_INTERRUPT) || \ - ((waitFor) == CY_SYSPM_WAIT_FOR_EVENT)) - -/** \endcond */ - -/** \} group_syspm_macros */ - -/******************************************************************************* -* Configuration Structures -*******************************************************************************/ - -/** -* \addtogroup group_syspm_data_enumerates -* \{ -*/ - -/** This enumeration is used to configure sources for wakeup from Hibernate -* power mode -*/ -typedef enum -{ - /** Configure a low level for the first LPComp */ - CY_SYSPM_LPCOMP0_LOW = - ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), - - /** Configure a high level for the first LPComp */ - CY_SYSPM_LPCOMP0_HIGH = - ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | - ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), - - /** Configure a low level for the second LPComp */ - CY_SYSPM_LPCOMP1_LOW = ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), - - /** Configure a high level for the second LPComp */ - CY_SYSPM_LPCOMP1_HIGH = - ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | - ((uint32_t) CY_SYSPM_WAKEUP_LPCOMP1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), - - /** Configure the RTC alarm */ - CY_SYSPM_HIBALARM = SRSS_PWR_HIBERNATE_MASK_HIBALARM_Msk, - - /** Configure the WDT interrupt */ - CY_SYSPM_HIBWDT = SRSS_PWR_HIBERNATE_MASK_HIBWDT_Msk, - - /** Configure a low level for the first wakeup-pin */ - CY_SYSPM_HIBPIN0_LOW = ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), - - /** Configure a high level for the first wakeup-pin */ - CY_SYSPM_HIBPIN0_HIGH = - ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | - ((uint32_t) CY_SYSPM_WAKEUP_PIN0_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), - - /** Configure a low level for the second wakeup-pin */ - CY_SYSPM_HIBPIN1_LOW = ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos), - - /** Configure a high level for the second wakeup-pin */ - CY_SYSPM_HIBPIN1_HIGH = - ((uint32_t) ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << SRSS_PWR_HIBERNATE_POLARITY_HIBPIN_Pos) | - ((uint32_t) CY_SYSPM_WAKEUP_PIN1_BIT << SRSS_PWR_HIBERNATE_MASK_HIBPIN_Pos)), -} cy_en_syspm_hib_wakeup_source_t; - -/** -* This enumeration is used to initialize a wait action - an interrupt or -* an event. Refer to the CMSIS for the WFE and WFI instruction explanations. -*/ -typedef enum -{ - CY_SYSPM_WAIT_FOR_INTERRUPT, /**< Wait for an interrupt */ - CY_SYSPM_WAIT_FOR_EVENT /**< Wait for an event */ -} cy_en_syspm_waitfor_t; - -/** The enumeration is used to select output voltage for the Linear Regulator */ -typedef enum -{ - CY_SYSPM_LDO_VOLTAGE_0_9V = 0x07U, /**< 0.9 V nominal core voltage */ - CY_SYSPM_LDO_VOLTAGE_1_1V = 0x17U /**< 1.1 V nominal core voltage */ -} cy_en_syspm_ldo_voltage_t; - -#if(0u != SRSS_SIMOBUCK_PRESENT) - - /** - * The enumeration is used to select the output voltage for the SIMO Buck - * output 1, which can supply a core(s). - */ - typedef enum - { - CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V = 0x02U, /**< 0.9 V nominal core voltage */ - CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V = 0x05U /**< 1.1 V nominal core voltage */ - } cy_en_syspm_simo_buck_voltage1_t; - - /** - * The enumeration is used to select the output voltage for the SIMO Buck - * output 2, which can BLE HW block. - */ - typedef enum - { - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_15V = 0U, /**< 1.15 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_2V = 1U, /**< 1.20 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_25V = 2U, /**< 1.25 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_3V = 3U, /**< 1.3 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_35V = 4U, /**< 1.35 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_4V = 5U, /**< 1.4 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_45V = 6U, /**< 1.45 V nominal voltage */ - CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_5V = 7U /**< 1.5 V nominal voltage */ - } cy_en_syspm_simo_buck_voltage2_t; - - /** - * The enumerations are used to select the SIMO Buck regulator outputs - */ - typedef enum - { - CY_SYSPM_BUCK_VBUCK_1, /**< SIMO Buck output 1 Voltage (Vbuck1) */ - CY_SYSPM_BUCK_VRF /**< SIMO Buck out 2 Voltage (Vbuckrf) */ - } cy_en_syspm_buck_out_t; - -#endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ - -/** The SysPm status definitions */ -typedef enum -{ - CY_SYSPM_SUCCESS = 0x00U, /**< Successful */ - CY_SYSPM_BAD_PARAM = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0x01U, /**< One or more invalid parameters */ - CY_SYSPM_TIMEOUT = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0x02U, /**< A time-out occurs */ - CY_SYSPM_INVALID_STATE = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0x03U, /**< The operation is not setup or is in an - improper state */ - CY_SYSPM_FAIL = CY_SYSPM_ID | CY_PDL_STATUS_ERROR | 0xFFU /**< An unknown failure */ -} cy_en_syspm_status_t; - -/** -* This enumeration is used for selecting the low power mode on which the -* appropriate registered callback handler will be executed. For example, -* the registered callback of the type CY_SYSPM_SLEEP will be executed while -* switching into the Sleep power mode. -*/ -typedef enum -{ - CY_SYSPM_SLEEP, /**< The Sleep enum callback type */ - CY_SYSPM_DEEPSLEEP, /**< The DeepSleep enum callback type */ - CY_SYSPM_HIBERNATE, /**< The Hibernate enum callback type */ - CY_SYSPM_ENTER_LP_MODE, /**< The enter into the LPActive mode enum callback type */ - CY_SYSPM_EXIT_LP_MODE, /**< The exit out of the LPActive mode enum callback type */ -} cy_en_syspm_callback_type_t; - -/** The callback mode enumeration. This enum defines the callback mode */ -typedef enum -{ - CY_SYSPM_CHECK_READY = 0x01U, /**< Callbacks with this mode are executed before entering into the - low-power mode. Callback function check if the device is ready - to enter the low-power mode */ - CY_SYSPM_CHECK_FAIL = 0x02U, /**< Callbacks with this mode are executed after the previous callbacks - execution with CY_SYSPM_CHECK_READY return CY_SYSPM_FAIL. The callback - with the CY_SYSPM_CHECK_FAIL mode should roll back the actions done in - the callbacks executed previously with CY_SYSPM_CHECK_READY */ - CY_SYSPM_BEFORE_TRANSITION = 0x04U, /**< The actions to be done before entering into the low-power mode */ - CY_SYSPM_AFTER_TRANSITION = 0x08U, /**< The actions to be done after exiting the low-power mode */ -} cy_en_syspm_callback_mode_t; - -/** -* This enumeration is used to set a polarity for the PMIC input. The PMIC is -* automatically enabled when configured polarity of PMIC input and the polarity -* driven to pmic_wakeup_in pin matches. -*/ -typedef enum -{ - CY_SYSPM_PMIC_POLARITY_LOW = 0U, /**< Set active low state for the PMIC input */ - CY_SYSPM_PMIC_POLARITY_HIGH = 1U /**< Set active high state for the PMIC input */ -} cy_en_syspm_pmic_wakeup_polarity_t; - -/** \} group_syspm_data_enumerates */ - -/** -* \addtogroup group_syspm_data_structures -* \{ -*/ - -/** The structure with the syspm callback parameters */ -typedef struct -{ - cy_en_syspm_callback_mode_t mode; /**< The callback mode, element for internal usage, see - \ref cy_en_syspm_callback_mode_t. This element should not be defined - as it is updated every time before the callback function is executed */ - void *base; /**< The base address of a HW instance, matches name of the driver in - the API for the base address. Can be not defined if not required */ - void *context; /**< The context for the handler function. This item can be - skipped if not required. Can be not defined if not required */ - -} cy_stc_syspm_callback_params_t; - -/** The type for syspm callbacks */ -typedef cy_en_syspm_status_t (*Cy_SysPmCallback) (cy_stc_syspm_callback_params_t *callbackParams); - -/** The structure with the syspm callback configuration elements */ -typedef struct cy_stc_syspm_callback -{ - Cy_SysPmCallback callback; /**< The callback handler function */ - cy_en_syspm_callback_type_t type; /**< The callback type, see \ref cy_en_syspm_callback_type_t */ - uint32_t skipMode; /**< The mask of modes to be skipped during callback - execution, see \ref group_syspm_skip_callback_modes. The - corresponding callback mode won't execute if the - appropriate define is set. These values can be ORed. - If all modes are required to be executed this element - should be equal to zero. */ - - cy_stc_syspm_callback_params_t *callbackParams; /**< The base address of a HW instance, matches name of the - driver in the API for the base address */ - - struct cy_stc_syspm_callback *prevItm; /**< The previous list item. This element is for internal usage - to link this structure to the next registered structure. - It will be updated during callback registering. Do not - modify this element in run-time */ - - struct cy_stc_syspm_callback *nextItm; /**< The next list item. This element is for internal usage to - link this structure to the previous registered structure. - It will be updated during callback registering. Do not - modify this element in run-time */ -} cy_stc_syspm_callback_t; - -#ifdef CY_IP_MXUDB - - /** \cond INTERNAL */ - #define CY_SYSPM_PERI_GR3_UDB (3U) - - /** This internal structure stores non-retained registers in the Deep - * Sleep power mode. - */ - typedef struct - { - /* The UDB interface control register */ - uint32_t CY_UDB_UDBIF_BANK_CTL_REG; - - /* The UDB bank control registers */ - uint32_t CY_UDB_BCTL_MDCLK_EN_REG; - uint32_t CY_UDB_BCTL_MBCLK_EN_REG; - uint32_t CY_UDB_BCTL_BOTSEL_L_REG; - uint32_t CY_UDB_BCTL_BOTSEL_U_REG; - uint32_t CY_UDB_BCTL_QCLK_EN0_REG; - uint32_t CY_UDB_BCTL_QCLK_EN1_REG; - uint32_t CY_UDB_BCTL_QCLK_EN2_REG; - } cy_stc_syspm_backup_regs_t; - /** \endcond */ - -#endif /* CY_IP_MXUDB */ - -/** \} group_syspm_data_structures */ - -/** -* \addtogroup group_syspm_functions -* \{ -*/ - -#if(0u != CY_IP_M4CPUSS) - - __STATIC_INLINE bool Cy_SysPm_Cm4IsActive(void); - __STATIC_INLINE bool Cy_SysPm_Cm4IsSleep(void); - __STATIC_INLINE bool Cy_SysPm_Cm4IsDeepSleep(void); - __STATIC_INLINE bool Cy_SysPm_Cm4IsLowPower(void); - -#endif /* (0u != CY_IP_M4CPUSS) */ - -__STATIC_INLINE bool Cy_SysPm_Cm0IsActive(void); -__STATIC_INLINE bool Cy_SysPm_Cm0IsSleep(void); -__STATIC_INLINE bool Cy_SysPm_Cm0IsDeepSleep(void); -__STATIC_INLINE bool Cy_SysPm_Cm0IsLowPower(void); -__STATIC_INLINE bool Cy_SysPm_IsLowPower(void); - -__STATIC_INLINE cy_en_syspm_ldo_voltage_t Cy_SysPm_LdoGetVoltage(void); -__STATIC_INLINE bool Cy_SysPm_LdoIsEnabled(void); -__STATIC_INLINE bool Cy_SysPm_GetIoFreezeStatus(void); - -__STATIC_INLINE void Cy_SysPm_EnablePmic(void); -__STATIC_INLINE void Cy_SysPm_DisablePmic(cy_en_syspm_pmic_wakeup_polarity_t polarity); -__STATIC_INLINE void Cy_SysPm_AlwaysEnablePmic(void); -__STATIC_INLINE void Cy_SysPm_EnablePmicOutput(void); -__STATIC_INLINE void Cy_SysPm_DisablePmicOutput(void); -__STATIC_INLINE void Cy_SysPm_LockPmic(void); -__STATIC_INLINE void Cy_SysPm_UnlockPmic(void); -__STATIC_INLINE bool Cy_SysPm_IsPmicEnabled(void); -__STATIC_INLINE bool Cy_SysPm_IsPmicOutputEnabled(void); -__STATIC_INLINE bool Cy_SysPm_IsPmicLocked(void); - -#if(0u != SRSS_SIMOBUCK_PRESENT) - - __STATIC_INLINE cy_en_syspm_simo_buck_voltage1_t Cy_SysPm_SimoBuckGetVoltage1(void); - __STATIC_INLINE cy_en_syspm_simo_buck_voltage2_t Cy_SysPm_SimoBuckGetVoltage2(void); - __STATIC_INLINE void Cy_SysPm_DisableVoltage2(void); - __STATIC_INLINE bool Cy_SysPm_SimoBuckIsEnabled(void); - __STATIC_INLINE void Cy_SysPm_SimoBuckSetHwControl(bool hwControl); - __STATIC_INLINE bool Cy_SysPm_SimoBuckGetHwControl(void); - - void Cy_SysPm_SwitchToSimoBuck(void); - void Cy_SysPm_SimoBuckSetVoltage1(cy_en_syspm_simo_buck_voltage1_t voltage); - void Cy_SysPm_EnableVoltage2(void); - void Cy_SysPm_SimoBuckSetVoltage2(cy_en_syspm_simo_buck_voltage2_t voltage, bool waitToSettle); - bool Cy_SysPm_SimoBuckOutputIsEnabled(cy_en_syspm_buck_out_t output); - -#endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ - -uint32_t Cy_SysPm_ReadStatus(void); -cy_en_syspm_status_t Cy_SysPm_Sleep(cy_en_syspm_waitfor_t waitFor); -cy_en_syspm_status_t Cy_SysPm_DeepSleep(cy_en_syspm_waitfor_t waitFor); -cy_en_syspm_status_t Cy_SysPm_Hibernate(void); -cy_en_syspm_status_t Cy_SysPm_EnterLpMode(void); -cy_en_syspm_status_t Cy_SysPm_ExitLpMode(void); -void Cy_SysPm_SleepOnExit(bool enable); - -void Cy_SysPm_SetHibWakeupSource(cy_en_syspm_hib_wakeup_source_t wakeupSource); -void Cy_SysPm_ClearHibWakeupSource(cy_en_syspm_hib_wakeup_source_t wakeupSource); -void Cy_SysPm_LdoSetVoltage(cy_en_syspm_ldo_voltage_t voltage); -bool Cy_SysPm_RegisterCallback(cy_stc_syspm_callback_t *handler); -bool Cy_SysPm_UnregisterCallback(cy_stc_syspm_callback_t const *handler); -cy_en_syspm_status_t Cy_SysPm_ExecuteCallback(cy_en_syspm_callback_type_t type, cy_en_syspm_callback_mode_t mode); -void Cy_SysPm_IoFreeze(void); -void Cy_SysPm_IoUnfreeze(void); - -#if(0u != CY_IP_M4CPUSS) - /******************************************************************************* - * Function Name: Cy_SysPm_Cm4IsActive - ****************************************************************************//** - * - * Checks if CM4 is in the active mode. - * - * \return - * true - if CM4 is in the active mode, false - if the CM4 is not in active mode. - * - *******************************************************************************/ - __STATIC_INLINE bool Cy_SysPm_Cm4IsActive(void) - { - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_ACTIVE) != 0U); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_Cm4IsSleep - ****************************************************************************//** - * - * Checks if the CM4 is in the sleep mode. - * - * \return - * true - if the CM4 is in the sleep mode, - * false - if the CM4 is not in the sleep mode. - * - *******************************************************************************/ - __STATIC_INLINE bool Cy_SysPm_Cm4IsSleep(void) - { - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_SLEEP) != 0U); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_Cm4IsDeepSleep - ****************************************************************************//** - * - * Checks if the CM4 is in the deep sleep mode. - * - * \return - * true - if CM4 is in the deep sleep mode, false - if the CM4 is not in - * the deep sleep mode. - * - *******************************************************************************/ - __STATIC_INLINE bool Cy_SysPm_Cm4IsDeepSleep(void) - { - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_DEEPSLEEP) != 0U); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_Cm4IsLowPower - ****************************************************************************//** - * - * Checks if the CM4 is in the low power mode. - * - * \return - * true - if the CM4 is in the low power mode, - * false - if the CM4 is not in the low power mode. - * - *******************************************************************************/ - __STATIC_INLINE bool Cy_SysPm_Cm4IsLowPower(void) - { - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM4_LOWPOWER) != 0U); - } - -#endif /* (0u != CY_IP_M4CPUSS) */ - - -/******************************************************************************* -* Function Name: Cy_SysPm_Cm0IsActive -****************************************************************************//** -* -* Checks if the CM0+ is in the active mode. -* -* \return -* true - if the CM0+ is in the active mode, -* false - if the CM0+ is not in the active mode. -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_Cm0IsActive(void) -{ - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_ACTIVE) != 0U); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_Cm0IsSleep -****************************************************************************//** -* -* Checks if the CM0+ is in the sleep mode. -* -* \return -* true - if the CM0+ is in the sleep mode, -* false - if the CM0+ is not in the sleep mode. -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_Cm0IsSleep(void) -{ - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_SLEEP) != 0U); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_Cm0IsDeepSleep -****************************************************************************//** -* -* Checks if the CM0+ is in the deep sleep mode. -* -* \return -* true - if the CM0+ is in the deep sleep mode, -* false - if the CM0+ is not in the deep sleep mode. -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_Cm0IsDeepSleep(void) -{ - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_DEEPSLEEP) != 0U); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_Cm0IsLowPower -****************************************************************************//** -* -* Checks if the CM0+ is in the low power mode. -* -* \return -* true - if the CM0+ is in the low power mode, -* false - if the CM0+ is not in the low power mode. -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_Cm0IsLowPower(void) -{ - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_CM0_LOWPOWER) != 0U); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_IsLowPower -****************************************************************************//** -* -* Checks if the device is in the low power mode. -* -* \return -* true - the system is in the low power mode, -* false - the system is is not in the low power mode. -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_IsLowPower(void) -{ - return((Cy_SysPm_ReadStatus() & CY_SYSPM_STATUS_SYSTEM_LOWPOWER) != 0U); -} - -#if(0u != SRSS_SIMOBUCK_PRESENT) - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckIsEnabled - ****************************************************************************//** - * - * Get the current status of the SIMO Buck regulator. - * - * \return - * The current state of the SIMO Buck regulator. True if the SIMO Buck regulator - * is enabled, false if it is disabled - * - *******************************************************************************/ - __STATIC_INLINE bool Cy_SysPm_SimoBuckIsEnabled(void) - { - return((0u !=_FLD2VAL(SRSS_PWR_BUCK_CTL_BUCK_EN, SRSS->PWR_BUCK_CTL)) ? true : false); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckGetVoltage2 - ****************************************************************************//** - * - * Get the current output 2 nominal voltage (Vbuckrf) of the SIMO Buck regulator. - * - * \note The actual device output 2 voltage (Vbuckrf) can be different from the - * nominal voltage because the actual voltage value depends on the conditions - * including the load current. - * - * \return - * The nominal output voltage of the SIMO Buck regulator output 2 - * voltage (Vbuckrf). - * See \ref cy_en_syspm_simo_buck_voltage2_t. - * - *******************************************************************************/ - __STATIC_INLINE cy_en_syspm_simo_buck_voltage2_t Cy_SysPm_SimoBuckGetVoltage2(void) - { - uint32_t retVal; - retVal = _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_SEL, SRSS->PWR_BUCK_CTL2); - - return((cy_en_syspm_simo_buck_voltage2_t) retVal); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckGetVoltage1 - ****************************************************************************//** - * - * Get the current nominal output 1 voltage (Vccbuck1) of - * the SIMO Buck regulator. - * - * \note The actual device output 1 voltage (Vccbuck1) can be different from - * the actual voltage because the actual voltage value depends on the - * conditions including the load current. - * - * \note The actual device output 1 voltage (Vccbuck1) can be different from the - * nominal voltage because the actual voltage value depends on the conditions - * including the load current. - * - * \return - * The nominal output voltage 1 (Vccbuck1) of the SIMO Buck regulator. - * See \ref cy_en_syspm_simo_buck_voltage1_t. - * - *******************************************************************************/ - __STATIC_INLINE cy_en_syspm_simo_buck_voltage1_t Cy_SysPm_SimoBuckGetVoltage1(void) - { - uint32_t retVal; - retVal = _FLD2VAL(SRSS_PWR_BUCK_CTL_BUCK_OUT1_SEL, SRSS->PWR_BUCK_CTL); - - return((cy_en_syspm_simo_buck_voltage1_t) retVal); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_DisableVoltage2 - ****************************************************************************//** - * - * Disable the output 2 voltage (Vbuckrf) of the SIMO Buck regulator. The - * output 2 voltage (Vbuckrf) of the SIMO Buck regulator is used to supply - * the BLE HW block. - * - * \note The function does not have effect if the SIMO Buck regulator is - * switched off. - * - * \note Ensure that the new voltage supply for the BLE HW block is settled - * and it is stable before calling the Cy_SysPm_DisableVoltage2() function. - * - *******************************************************************************/ - __STATIC_INLINE void Cy_SysPm_DisableVoltage2(void) - { - /* Disable the Vbuck2 output */ - SRSS->PWR_BUCK_CTL2 &= ((uint32_t) ~ (_VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_EN, 1U))); - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckSetHwControl - ****************************************************************************//** - * - * Sets the hardware control for the SIMO Buck output 2 (Vbuckrf). - * - * The hardware control for the Vbuckrf output. When this bit is set, the - * value in BUCK_OUT2_EN is ignored and hardware signal is used instead. If the - * product has supporting hardware, it can directly control the enable signal - * for Vbuckrf. - * - * \param hwControl - * Enables/disables hardware control for the SIMO Buck output 2 - * - * Function does not have an effect if SIMO Buck regulator is disabled. - * - *******************************************************************************/ - __STATIC_INLINE void Cy_SysPm_SimoBuckSetHwControl(bool hwControl) - { - if(Cy_SysPm_SimoBuckIsEnabled()) - { - if(hwControl) - { - SRSS->PWR_BUCK_CTL2 |= _VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, 1U); - } - else - { - SRSS->PWR_BUCK_CTL2 &= ((uint32_t)~(_VAL2FLD(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, 1U))); - } - } - } - - - /******************************************************************************* - * Function Name: Cy_SysPm_SimoBuckGetHwControl - ****************************************************************************//** - * - * Gets the hardware control for Vbuckrf. - * - * The hardware control for the Vbuckrf output. When this bit is set, the - * value in BUCK_OUT2_EN is ignored and hardware signal is used instead. If the - * product has supporting hardware, it can directly control the enable signal - * for Vbuckrf. - * - * \return - * True if the HW control is set, false if the FW control is set for the - * SIMO Buck output 2. - * - *******************************************************************************/ - __STATIC_INLINE bool Cy_SysPm_SimoBuckGetHwControl(void) - { - return((0U != _FLD2VAL(SRSS_PWR_BUCK_CTL2_BUCK_OUT2_HW_SEL, SRSS->PWR_BUCK_CTL2)) ? true : false); - } - -#endif /* (0u != SRSS_SIMOBUCK_PRESENT) */ - -/******************************************************************************* -* Function Name: Cy_SysPm_LdoGetVoltage -****************************************************************************//** -* -* Get the current output voltage value of the Linear regulator. -* -* \note The actual device Vccd voltage can be different from the -* nominal voltage because the actual voltage value depends on the conditions -* including the load current. -* -* \return -* The nominal output voltage of the Linear regulator. -* See \ref cy_en_syspm_ldo_voltage_t. -* -*******************************************************************************/ -__STATIC_INLINE cy_en_syspm_ldo_voltage_t Cy_SysPm_LdoGetVoltage(void) -{ - uint32_t retVal; - retVal = _FLD2VAL(SRSS_PWR_TRIM_PWRSYS_CTL_ACT_REG_TRIM, SRSS->PWR_TRIM_PWRSYS_CTL); - - return((cy_en_syspm_ldo_voltage_t) retVal); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_LdoIsEnabled -****************************************************************************//** -* -* Reads the current status of the Linear regulator. -* -* \return -* True means the Linear regulator is enabled. False means it is disabled -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_LdoIsEnabled(void) -{ - return((0U != _FLD2VAL(SRSS_PWR_CTL_LINREG_DIS, SRSS->PWR_CTL)) ? false : true); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_GetIoFreezeStatus -****************************************************************************//** -* -* Checks whether IoFreeze is enabled. -* -* \return Returns True if IOs are frozen
False if IOs are unfrozen. -* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_GetIoFreezeStatus(void) -{ - return(0U != _FLD2VAL(SRSS_PWR_HIBERNATE_FREEZE, SRSS->PWR_HIBERNATE)); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_EnablePmic -****************************************************************************//** -* -* Enable the external PMIC that supplies Vddd (if present). -* -* For information about the PMIC input and output pins and their assignment in -* the specific families devices, refer to the appropriate device TRM. -* -* The function is not effective when the PMIC is locked. Call -* Cy_SysPm_UnlockPmic() before enabling the PMIC. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_EnablePmic(void) -{ - if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) - { - BACKUP->PMIC_CTL = - _VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY) | - _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, 1U) | - _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN, 1U); - } -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_DisablePmic -****************************************************************************//** -* -* Disables the PMIC. This function does not affect the output pin. Configures -* the PMIC input pin polarity. The PMIC input pin has programmable polarity to -* enable the PMIC using different input polarities. The PMIC output pin is -* automatically enabled when input polarity and configured polarity matches. -* The function is not effective when the active level of PMIC input pin -* is equal to configured PMIC polarity. -* -* The function is not effective when the PMIC is locked. Call -* Cy_SysPm_UnlockPmic() before enabling the PMIC. -* -* \param polarity -* Configures the PMIC wakeup input pin to be active low or active -* high. See \ref cy_en_syspm_pmic_wakeup_polarity_t. -* -* The PMIC will be enabled automatically by any of RTC alarm or PMIC wakeup -* event regardless of the PMIC lock state. -* -* \warning -* The PMIC is enabled automatically when you call Cy_SysPm_LockPmic(). -* To keep the PMIC disabled, the PMIC must remain unlocked. -* -* For information about the PMIC input and output pins and their assignment in -* the specific families devices, refer to the appropriate device TRM. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_DisablePmic(cy_en_syspm_pmic_wakeup_polarity_t polarity) -{ - CY_ASSERT_L3(CY_SYSPM_IS_POLARITY_VALID(polarity)); - - if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) - { - BACKUP->PMIC_CTL = - (_VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY) | - _CLR_SET_FLD32U(BACKUP->PMIC_CTL, BACKUP_PMIC_CTL_POLARITY, (uint32_t) polarity)) & - ((uint32_t) ~ _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN, 1U)); - } -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_AlwaysEnablePmic -****************************************************************************//** -* -* Enables the signal through the PMIC output pin. This is a Write once API, -* ensure that the PMIC cannot be disabled or polarity changed until a next -* device reset. -* -* For information about the PMIC input and output pins and their assignment in -* the specific families devices, refer to the appropriate device TRM. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_AlwaysEnablePmic(void) -{ - BACKUP->PMIC_CTL |= _VAL2FLD(BACKUP_PMIC_CTL_PMIC_ALWAYSEN, 1U); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_EnablePmicOutput -****************************************************************************//** -* -* Enable the PMIC output. -* -* The function is not effective when the PMIC is locked. Call -* Cy_SysPm_UnlockPmic() before enabling the PMIC. -* -* For information about the PMIC output pin and it assignment in -* the specific families devices, refer to the appropriate device TRM. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_EnablePmicOutput(void) -{ - if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) - { - BACKUP->PMIC_CTL |= - _VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY) | _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, 1U); - } -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_DisablePmicOutput -****************************************************************************//** -* -* Disable the PMIC output. -* -* When PMIC output pin is disabled and is unlocked the pmic output pin can be -* used for the another purpose. -* -* The function is not effective when the PMIC is locked. Call -* Cy_SysPm_UnlockPmic() before enabling the PMIC. -* -* For information about the PMIC output pin and it assignment in -* the specific families devices, refer to the appropriate device TRM. -* -* \warning -* The PMIC output is enabled automatically when you call Cy_SysPm_LockPmic(). -* To keep PMIC output disabled, the PMIC must remain unlocked. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_DisablePmicOutput(void) -{ - if(CY_SYSPM_PMIC_UNLOCK_KEY == _FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL)) - { - BACKUP->PMIC_CTL = - (BACKUP->PMIC_CTL | _VAL2FLD(BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY)) & - ((uint32_t) ~ _VAL2FLD(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, 1U)); - } -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_LockPmic -****************************************************************************//** -* -* Locks the PMIC control register so that no changes can be made. The changes -* are related to the PMIC enabling/disabling and PMIC output signal -* enabling/disabling. -* -* \warning -* The PMIC and/or the PMIC output are enabled automatically when -* you call Cy_SysPm_LockPmic(). To keep the PMIC or PMIC output disabled, -* the PMIC must remain unlocked. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_LockPmic(void) -{ - BACKUP->PMIC_CTL = _CLR_SET_FLD32U(BACKUP->PMIC_CTL, BACKUP_PMIC_CTL_UNLOCK, 0U); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_UnlockPmic -****************************************************************************//** -* -* Unlocks the PMIC control register so that changes can be made. The changes are -* related to the PMIC enabling/disabling and PMIC output signal -* enabling/disabling. -* -* \warning -* The PMIC and/or the PMIC output are enabled automatically when -* you call Cy_SysPm_LockPmic(). To keep the PMIC or PMIC output disabled, -* the PMIC must remain unlocked. -* -*******************************************************************************/ -__STATIC_INLINE void Cy_SysPm_UnlockPmic(void) -{ - BACKUP->PMIC_CTL = _CLR_SET_FLD32U(BACKUP->PMIC_CTL, BACKUP_PMIC_CTL_UNLOCK, CY_SYSPM_PMIC_UNLOCK_KEY); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_IsPmicEnabled -****************************************************************************//** -* -* The function returns the status of the PMIC. -* -* \return -* True - The PMIC is enabled.
-* False - The PMIC is disabled.
-* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_IsPmicEnabled(void) -{ - return(0U != _FLD2VAL(BACKUP_PMIC_CTL_PMIC_EN, BACKUP->PMIC_CTL)); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_IsPmicOutputEnabled -****************************************************************************//** -* -* The function returns the status of the PMIC output. -* -* \return -* True - The PMIC output is enabled.
-* False - The PMIC output is disabled.
-* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_IsPmicOutputEnabled(void) -{ - return(0U != _FLD2VAL(BACKUP_PMIC_CTL_PMIC_EN_OUTEN, BACKUP->PMIC_CTL)); -} - - -/******************************************************************************* -* Function Name: Cy_SysPm_IsPmicLocked -****************************************************************************//** -* -* Returns the PMIC lock status -* -* \return -* True - The PMIC is locked.
-* False - The PMIC is unlocked.
-* -*******************************************************************************/ -__STATIC_INLINE bool Cy_SysPm_IsPmicLocked(void) -{ - return((_FLD2VAL(BACKUP_PMIC_CTL_UNLOCK, BACKUP->PMIC_CTL) == CY_SYSPM_PMIC_UNLOCK_KEY) ? false : true); -} - -#ifdef __cplusplus -} -#endif - -#endif /* _CY_SYSPM_H_ */ - -/** \} group_syspm_functions*/ -/** \} group_syspm */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble.c deleted file mode 100644 index e6358951b1..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble.c +++ /dev/null @@ -1,657 +0,0 @@ -/***************************************************************************//** -* \file cy_ble.c -* \version 2.0 -* -* \brief -* This file contains the source code for the API of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" -#include "cy_ble_hal_pvt.h" -#include "cy_ipc_config.h" -#include - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_HOST_CONTR_CORE) - - -/*************************************** -* Global Variables -***************************************/ - -/* Allocate RAM memory for the stack. This buffer can be reused by the application when - * the BLE Component is stopped. For the export mode, the buffer is allocated in a heap. - */ -#if (CY_BLE_SHARING_MODE_EXPORT) -uint8_t *cy_ble_stackMemoryRam = NULL; -#else -CY_ALIGN(sizeof(uint32_t)) CY_NOINIT uint8_t cy_ble_stackMemoryRam[CY_BLE_STACK_RAM_SIZE]; -#endif /* CY_BLE_SHARING_MODE_EXPORT */ - -#if (CY_BLE_MODE_PROFILE) -cy_ble_callback_t Cy_BLE_ApplCallback; -#endif /* (CY_BLE_MODE_PROFILE) */ - -/* Pointer to the global BLE Config structures */ -cy_stc_ble_config_t *cy_ble_configPtr = NULL; - - -#if (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) - /* Structure with the syspm callback parameters for BLE deep-sleep */ - static cy_stc_syspm_callback_params_t bleDeepSleepCallbackParams = { .base = NULL}; - static cy_stc_syspm_callback_t bleDeepSleepCallback = - { - .callback = &Cy_BLE_DeepSleepCallback, - .type = CY_SYSPM_DEEPSLEEP, - .skipMode = CY_SYSPM_SKIP_BEFORE_TRANSITION | CY_SYSPM_SKIP_CHECK_FAIL, - .callbackParams = &bleDeepSleepCallbackParams - }; - - - /* Structure with the syspm callback parameters for BLE sleep */ -#if(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) - static cy_stc_syspm_callback_params_t bleSleepCallbackParams = { .base = NULL}; - static cy_stc_syspm_callback_t bleSleepCallback = - { - .callback = &Cy_BLE_SleepCallback, - .type = CY_SYSPM_SLEEP, - .skipMode = CY_SYSPM_SKIP_BEFORE_TRANSITION | CY_SYSPM_SKIP_CHECK_FAIL, - .callbackParams = &bleSleepCallbackParams - }; -#endif /* (CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ -#endif /* (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_UnregisterHostPMCallbacks -***************************************************************************//** -* -* Unregister BLE callback for Deepsleep/Sleep -* -******************************************************************************/ -void Cy_BLE_UnregisterHostPMCallbacks(void) -{ - #if (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) - /* Unregister BLE callback for Deepsleep support */ - (void)Cy_SysPm_UnregisterCallback(&bleDeepSleepCallback); - - /* Unregister sleep mode callback only in dual core mode for the host core */ - #if(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) - { - /* Unregister BLE callback for Sleep support */ - (void)Cy_SysPm_UnregisterCallback(&bleSleepCallback); - } - #endif /* (CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - #endif /* (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) */ -} - -/** - * \addtogroup group_ble_common_api_functions - * @{ - */ - -/****************************************************************************** -* Function Name: Cy_BLE_Init -***************************************************************************//** -* -* Initializes the Component with the parameters set in the customizer. -* -* \param config: The configuration structure for the BLE Component. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as the input parameter. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_Init(cy_stc_ble_config_t *config) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - #if (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) - /* Register BLE callback for Deepsleep support */ - (void)Cy_SysPm_RegisterCallback(&bleDeepSleepCallback); - - /* Register sleep mode callback only in dual core mode for the host core */ - #if(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) - { - /* Register BLE callback for Sleep support */ - (void)Cy_SysPm_RegisterCallback(&bleSleepCallback); - } - #endif /* (CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - #endif /* (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) */ - - /* Register a pointer to the config structure */ - cy_ble_configPtr = config; - - #if (CY_BLE_MODE_PROFILE) - /* Register a callback function via the config structure */ - if(cy_ble_configPtr->callbackFunc != NULL) - { - Cy_BLE_ApplCallback = cy_ble_configPtr->callbackFunc; - } - cy_ble_eventHandlerFlag = 0u; - (void)memset((uint8_t*)&cy_ble_busyStatus, 0, sizeof(cy_ble_busyStatus)); - - cy_ble_cmdStatus = 0u; - - #if (CY_BLE_GATT_ROLE_CLIENT) - { - uint32_t idx; - (void)memset(&cy_ble_serverInfo, 0, sizeof(cy_ble_serverInfo)); - (void)memset(cy_ble_connHandle, -1, sizeof(cy_ble_connHandle)); - (void)memset(&cy_ble_discovery, 0, sizeof(cy_ble_discovery)); - - /* Update cy_ble_discovery[].connIndex with init values (CY_BLE_INVALID_CONN_HANDLE_VALUE) */ - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - cy_ble_discovery[idx].connIndex = CY_BLE_INVALID_CONN_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - cy_ble_advertisingIntervalType = CY_BLE_ADVERTISING_FAST; - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - - #if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) - cy_ble_scanningIntervalType = CY_BLE_SCANNING_FAST; - #endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) */ - - Cy_BLE_ServiceInit(); - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - cy_ble_pendingFlashWrite = 0u; - (void)memset(cy_ble_peerBonding, (int8_t)CY_BLE_GAP_BONDING_NONE, sizeof(cy_ble_peerBonding)); - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - #endif /* (CY_BLE_MODE_PROFILE) */ - } - - return(apiResult); -} -/** @} */ - -/****************************************************************************** -* Function Name: Cy_BLE_Enable -***************************************************************************//** -* -* Initializes and starts the Host stack. -* Calling this function results in generation of a CY_BLE_EVT_STACK_ON event -* on successful initialization of the BLE stack. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_Enable(void) -{ - cy_en_ble_api_result_t apiResult; - -#if (CY_BLE_MODE_PROFILE) - cy_stc_ble_stk_app_data_buff_t cy_ble_stackDataBuff[CY_BLE_STACK_APP_MIN_POOL] = - { - { CY_BLE_GATT_MTU_PLUS_L2CAP_MEM_EXT, CY_BLE_GATT_MTU_BUFF_COUNT }, - { CY_BLE_L2CAP_PSM_PLUS_L2CAP_MEM_EXT, CY_BLE_L2CAP_PSM_COUNT }, - { CY_BLE_L2CAP_CBFC_PLUS_L2CAP_MEM_EXT, 2u * CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT }, - { CY_BLE_L2CAP_MTU_PLUS_L2CAP_MEM_EXT, 2u * CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT } - }; -#endif /* (CY_BLE_MODE_PROFILE) */ - - cy_stc_ble_stack_init_info_t stackInitParam = - { - #if (CY_BLE_MODE_PROFILE) - .CyBleAppCbFunc = (cy_ble_app_ev_cb_t)&Cy_BLE_EventHandler, - #endif /* CY_BLE_MODE_PROFILE */ - .memParam = - { - #if (CY_BLE_MODE_PROFILE) - .totalHeapSz = (uint16_t)(CY_BLE_STACK_RAM_SIZE - CY_BLE_GATT_PREPARE_WRITE_BUFF_LEN), - .dataBuff = cy_ble_stackDataBuff, - .totalDataBufferPools = CY_BLE_STACK_APP_MIN_POOL, - - #if (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) - .bleStackFlashPointer = (const uint8_t*)cy_ble_configPtr->flashStorage->stackFlashptr, - .bleStackFlashSize = CY_BLE_STACK_FLASH_SIZE, - #endif /* CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES */ - #else - .totalHeapSz = CY_BLE_STACK_RAM_SIZE, - #endif /* CY_BLE_MODE_PROFILE */ - }, - .stackConfig = - { - /* Configure DLE */ - .dleConfig.dleMaxTxCapability = CY_BLE_LL_MAX_TX_PAYLOAD_SIZE, - .dleConfig.dleMaxRxCapability = CY_BLE_LL_MAX_RX_PAYLOAD_SIZE, - .dleConfig.dleNumTxBuffer = CY_BLE_LL_DEFAULT_NUM_ACL_TX_PACKETS, - .dleConfig.dleNumRxBuffer = CY_BLE_LL_DEFAULT_NUM_ACL_RX_PACKETS, - - #if (CY_BLE_MODE_PROFILE) - /* Configure queue */ - .l2capConfig.l2capBufferPerConn = CY_BLE_L2CAP_Q_DEPTH_PER_CONN, - #endif /* (CY_BLE_MODE_PROFILE) */ - - /* Configure LL Privacy */ - .privacyConfig.resolvingListSize = CY_BLE_MAX_RESOLVABLE_DEVICES, - - /* Configure bonded device list */ - .bondListConfig.bondListSize = CY_BLE_MAX_BONDED_DEVICES, - - /* Configure white list */ - .whiteListConfig.whiteListSize = CY_BLE_MAX_WHITE_LIST_SIZE, - - .featureMask = (CY_BLE_DLE_FEATURE | CY_BLE_LL_PRIVACY_FEATURE | CY_BLE_SECURE_CONN_FEATURE | - CY_BLE_PHY_UPDATE_FEATURE | CY_BLE_STORE_BONDLIST_FEATURE | - CY_BLE_STORE_RESOLVING_LIST_FEATURE | CY_BLE_STORE_WHITELIST_FEATURE | - CY_BLE_CONFIG_TX_POWER_CALIBRATION_FEATURE), - .maxBleConnections = CY_BLE_CONN_COUNT - } - }; - - #if (CY_BLE_DLE_FEATURE_ENABLED) - Cy_BLE_EnableDleFeature(); /* Enable DLE code in the stack */ - #endif /* CY_BLE_DLE_FEATURE_ENABLED */ - - #if (CY_BLE_LL_PRIVACY_FEATURE_ENABLED) - Cy_BLE_EnablePrivacyFeature(); /* Enable LL Privacy code in the stack */ - #endif /* CY_BLE_LL_PRIVACY_FEATURE_ENABLED */ - - #if (CY_BLE_PHY_UPDATE_FEATURE_ENABLED) - Cy_BLE_EnablePhyUpdateFeature(); /* Enable PHY Update code in the stack */ - #endif /* CY_BLE_PHY_UPDATE_FEATURE_ENABLED */ - - apiResult = Cy_BLE_StackSetFeatureConfig(&stackInitParam.stackConfig); - - if(apiResult == CY_BLE_SUCCESS) - { - stackInitParam.memParam.memoryHeapPtr = cy_ble_stackMemoryRam; - - /* Initialize the BLE stack */ - apiResult = Cy_BLE_StackInit(&stackInitParam); - - #if (CY_BLE_MODE_PROFILE) - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetState(CY_BLE_STATE_INITIALIZING); - - #if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_PERIPHERAL) - (void)memset(&cy_ble_connState, 0, sizeof(cy_ble_connState)); - #endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_PERIPHERAL) */ - - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOPPED); - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - - #if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_STOPPED); - #endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) */ - - #if (CY_BLE_GATT_ROLE_SERVER) - { - cy_stc_ble_gatts_db_info_t dbInfoParam = - { - .gattDbPtr = (const cy_stc_ble_gatts_db_t*)cy_ble_configPtr->gattDB, - .gattDbTotalEntries = cy_ble_configPtr->params->gattDbIndexCount, - .gattDbMaxValue = CY_BLE_CONFIG_GATT_DB_MAX_VALUE_LEN - }; - - apiResult = Cy_BLE_GATTS_DbRegister(&dbInfoParam); - } - #endif /* CY_BLE_GATT_ROLE_SERVER */ - } - #endif /* (CY_BLE_MODE_PROFILE) */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_Disable -***************************************************************************//** -* -* This function stops any ongoing operation in the BLE stack and forces the -* BLE stack to shut down. -* -* Calling this function results in generation of -* a CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE event on a successful stack shutdown. -* -* For HCI mode: -* This is a blocking function and no event is generated. -* Only CY_BLE_SUCCESS will be returned and other error codes are not applicable. -* UART interface will be stopped and UART data will not be processed by stack -* until Cy_BLE_Enable is invoked. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | On calling Cy_BLE_Disable before calling Cy_BLE_Enable or on Controller core. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_Disable(void) -{ - cy_en_ble_api_result_t apiResult; - -#if (CY_BLE_CONFIG_STACK_IPC_CONTR_CORE) - apiResult = CY_BLE_SUCCESS; /* To stop Controller call Cy_BLE_Disable() function on Host core */ -#else - apiResult = Cy_BLE_StackShutdown(); /* Stops all ongoing activities */ - #if (CY_BLE_SHARING_MODE_EXPORT) - if(cy_ble_stackMemoryRam != NULL) - { - free(cy_ble_stackMemoryRam); - } - #endif /* CY_BLE_SHARING_MODE_EXPORT */ -#endif /* CY_BLE_CONFIG_STACK_IPC_CONTR_CORE */ - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_ConfigureExtPA -****************************************************************************//** -* -* This function controls external Power Amplifier and Low Noise Amplifier -* outputs. -* -* \param controlValue Enables and controls polarity of the outputs. -* Use following defines to control external PA and LNA: -* - BLE_BLESS_EXT_PA_LNA_CTRL_ENABLE_EXT_PA_LNA_Msk - When set to 1, enables -* the external PA & LNA and BLESS power profile for energy profiler -* - BLE_BLESS_EXT_PA_LNA_CTRL_CHIP_EN_POL_Msk - Controls the polarity of the chip -* enable control signal: -* * 0 - High enable, Low disable -* * 1 - Low enable, High disable, Incorrect power profile -* - BLE_BLESS_EXT_PA_LNA_CTRL_PA_CTRL_POL_Msk - Controls the polarity of the PA -* control signal: -* * 0 - High enable, Low disable -* * 1 - Low enable, High disable, Incorrect power profile -* - BLE_BLESS_EXT_PA_LNA_CTRL_LNA_CTRL_POL_Msk - Controls the polarity of the LNA -* control signal: -* * 0 - High enable, Low disable -* * 1 - Low enable, High disable, Incorrect power profile -* - BLE_BLESS_EXT_PA_LNA_CTRL_OUT_EN_DRIVE_VAL_Msk - Configures the drive value -* on the output enables of PA, LNA and CHI_EN signals -* * 0 - drive 0 on the output enable signals -* * 1 - drive 1 on the output enable signals -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_ConfigureExtPA(uint32_t controlValue) -{ - BLE->BLESS.EXT_PA_LNA_CTRL = controlValue; -} - - -#if (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) - - -/******************************************************************************* -* Function Name: Cy_BLE_DeepSleepCallback -****************************************************************************//** -* -* This function requests the BLE stack to put Bluetooth Low Energy Sub-System -* (BLESS) to DeepSleep mode. -* -* It is registered to the system power mode by Cy_SysPm_RegisterCallback() -* function with CY_SYSPM_DEEPSLEEP type. After registration it is called by -* Cy_SysPm_DeepSleep() function prior entering the core into the Deep Sleep -* power mode. -* -* When it is called with the enMode parameter set to CY_SYSPM_CHECK_READY, -* function enters BLESS to CY_BLE_BLESS_DEEPSLEEP mode. It also checks the -* BLE Subsystem's current operational mode. When the -* Cy_BLE_StackGetBleSsState() function returns CY_BLE_BLESS_STATE_ECO_ON or -* CY_BLE_BLESS_STATE_DEEPSLEEP state, this function returns CY_SYSPM_PASS and -* allows to put the core into the Deep Sleep power mode. -* At all other times, the function tries to enter core into sleep mode. -* -* This function is available only when BLE low power mode is enabled in the -* Advanced tab of customizer. -* -* \param -* callbackParams pointer to the structure with the syspm callback parameters -* callbackParams->mode - the callback mode, see description -* of the cy_en_syspm_callback_mode_t type. -* -* \return -* * CY_SYSPM_SUCCESS - Entered and exited from DeepSleep -* * CY_SYSPM_FAIL - DeepSleep not entered. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_BLE_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams) -{ - cy_en_syspm_status_t retVal; - static uint32_t interruptState = 0u; - cy_en_ble_bless_state_t blessState; - - /* Local variable to store the status of BLESS Hardware block */ - cy_en_ble_lp_mode_t sleepMode; - - switch(callbackParams->mode) - { - case (CY_SYSPM_CHECK_READY): - #if (CY_BLE_MODE_PROFILE) - if(Cy_BLE_GetState() == CY_BLE_STATE_INITIALIZING) - { - retVal = CY_SYSPM_FAIL; - } - else - #endif /*(CY_BLE_MODE_PROFILE) */ - { - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - cy_en_ble_api_result_t retIsControllerActive; - #endif /* !(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - - #if(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) - /* Disable global interrupt to prevent changes from any other interrupt ISR */ - interruptState = Cy_SysLib_EnterCriticalSection(); - #endif /* (CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - /* Put BLESS into Deep Sleep and check the return status */ - sleepMode = Cy_BLE_StackEnterLPM(CY_BLE_BLESS_DEEPSLEEP); - - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - /* Disable global interrupt to prevent changes from any other interrupt ISR */ - interruptState = Cy_SysLib_EnterCriticalSection(); - #endif /* !(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - - /* Check the Status of BLESS */ - blessState = Cy_BLE_StackGetBleSsState(); - - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - if(blessState == CY_BLE_BLESS_STATE_STOPPED) - { - retVal = CY_SYSPM_SUCCESS; - } - else - #endif /* (!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC))*/ - if(sleepMode == CY_BLE_BLESS_DEEPSLEEP) - { - - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - retIsControllerActive = Cy_BLE_IsControllerActive(CY_BLE_CONTROLLER_SLEEP_MODE_DEEPSLEEP); - #endif /* !(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - - if((Cy_BLE_HAL_NvramWriteIsBusy() == false) && - ((blessState == CY_BLE_BLESS_STATE_ECO_ON) || (blessState == CY_BLE_BLESS_STATE_DEEPSLEEP)) - - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - && (retIsControllerActive == CY_BLE_SUCCESS) - #endif /* !(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - ) - { - /* Enter device deep sleep */ - retVal = CY_SYSPM_SUCCESS; - } - else - { - /* The BLESS hardware block cannot go to Deep Sleep, try sleep mode */ - retVal = CY_SYSPM_FAIL; - } - } - else - { - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - retIsControllerActive = Cy_BLE_IsControllerActive(CY_BLE_CONTROLLER_SLEEP_MODE_SLEEP); - - if((blessState != CY_BLE_BLESS_STATE_EVENT_CLOSE) && - (retIsControllerActive == CY_BLE_SUCCESS)) - { - /* If the BLESS hardware block cannot go to Deep Sleep and BLE Event has not - * closed yet, then place CPU to Sleep */ - (void)Cy_SysPm_Sleep(CY_SYSPM_WAIT_FOR_INTERRUPT); - } - #endif /* (CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - retVal = CY_SYSPM_FAIL; - } - if(retVal == CY_SYSPM_FAIL) - { - /* Enable interrupts after failing check */ - Cy_SysLib_ExitCriticalSection(interruptState); - } - } - break; - - /* Enable interrupts after wakeup */ - case (CY_SYSPM_AFTER_TRANSITION): - Cy_SysLib_ExitCriticalSection(interruptState); - retVal = CY_SYSPM_SUCCESS; - break; - - default: - retVal = CY_SYSPM_FAIL; - break; - } - - return(retVal); -} - -#if(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) - - -/******************************************************************************* -* Function Name: Cy_BLE_SleepCallback -****************************************************************************//** -* -* This function requests the BLE stack to put the Host to Sleep mode. -* -* It is registered to the system power mode by Cy_SysPm_RegisterCallback() -* function with CY_SYSPM_SLEEP type. After registration it is called by -* Cy_SysPm_Sleep() function prior entering the core into the Sleep -* power mode. -* -* This function is available only when BLE low power mode is enabled in the -* Advanced tab of customizer. -* -* \param -* callbackParams pointer to the structure with the syspm callback parameters -* callbackParams->mode - the callback mode, see description -* of the cy_en_syspm_callback_mode_t type. -* -* \return -* * CY_SYSPM_SUCCESS - Entered and exited from Sleep -* * CY_SYSPM_FAIL - Sleep not entered. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_BLE_SleepCallback(cy_stc_syspm_callback_params_t *callbackParams) -{ - cy_en_syspm_status_t retVal; - static uint32_t interruptState = 0u; - /* Local variable to store the status of BLESS Hardware block */ - cy_en_ble_lp_mode_t sleepMode; - - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - cy_en_ble_api_result_t retIsControllerActive = Cy_BLE_IsControllerActive(CY_BLE_CONTROLLER_SLEEP_MODE_SLEEP); - #endif /* !(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - - switch(callbackParams->mode) - { - case (CY_SYSPM_CHECK_READY): - if((Cy_BLE_GetState() == CY_BLE_STATE_INITIALIZING) - #if(!(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC)) - && (retIsControllerActive == CY_BLE_SUCCESS) - #endif /* !(CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ - ) - { - retVal = CY_SYSPM_FAIL; - } - else - { - - /* Disable global interrupt to prevent changes from any other interrupt ISR */ - interruptState = Cy_SysLib_EnterCriticalSection(); - - /* Put BLESS into Deep Sleep and check the return status */ - sleepMode = Cy_BLE_StackEnterLPM(CY_BLE_BLESS_DEEPSLEEP); - - /* Check if host is ready for sleep mode */ - if(sleepMode != CY_BLE_BLESS_DEEPSLEEP) - { - retVal = CY_SYSPM_FAIL; - /* Enable interrupts after failing check */ - Cy_SysLib_ExitCriticalSection(interruptState); - } - else - { - retVal = CY_SYSPM_SUCCESS; - } - } - break; - - /* Enable interrupts after wakeup */ - case (CY_SYSPM_AFTER_TRANSITION): - Cy_SysLib_ExitCriticalSection(interruptState); - retVal = CY_SYSPM_SUCCESS; - break; - - default: - retVal = CY_SYSPM_FAIL; - break; - } - - return(retVal); -} - -#endif /* (CY_BLE_STACK_MODE_HOST_UART || CY_BLE_STACK_MODE_HOST_IPC) */ -#endif /* (CY_BLE_CONFIG_USE_DEEP_SLEEP != 0u) */ - -#endif /* (CY_BLE_HOST_CONTR_CORE) */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble.h deleted file mode 100644 index e3576d56c7..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble.h +++ /dev/null @@ -1,410 +0,0 @@ -/***************************************************************************//** -* \file cy_ble.h -* \version 2.0 -* -* \brief -* Contains the prototypes and constants used in the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_H -#define CY_BLE_H - -#include -#include "syslib/cy_syslib.h" -#include "sysint/cy_sysint.h" -#include "syspm/cy_syspm.h" -#if ((CY_BLE_CONFIG_STACK_MODE_HOST_UART) || (CY_BLE_CONFIG_STACK_MODE_CONTR_UART)) - #include "scb/Cy_SCB_uart.h" -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ -#include "BLE_config.h" -#include -#ifndef CY_IP_MXBLESS - #error "The BLE middleware is not supported on this device" -#endif - -/*************************************** -* Stack includes -***************************************/ - -#include "cy_ble_stack_host_main.h" -#include "cy_ble_stack_gap.h" -#include "cy_ble_stack_gap_central.h" -#include "cy_ble_stack_gap_peripheral.h" -#include "cy_ble_stack_gatt_server.h" -#include "cy_ble_stack_gatt_client.h" -#include "cy_ble_stack_gatt_db.h" -#include "cy_ble_stack_l2cap.h" - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/*************************************** -* Type Definitions -***************************************/ - -/** The event callback function prototype to receive events from the BLE Component */ -typedef void (* cy_ble_callback_t) (uint32_t eventCode, void *eventParam); - -#define CY_BLE_M0S8BLESS_VERSION (4u) - -#define CY_BLE_STACK_MODE (CY_BLE_CONFIG_STACK_MODE) -#define CY_BLE_STACK_HOST_ONLY (1u) -#define CY_BLE_STACK_DEBUG (2u) -#define CY_BLE_STACK_RELEASE (3u) -#define CY_BLE_STACK_HOST_CONTR_UART (4u) -#define CY_BLE_STACK_HOST_IPC (5u) - -#define CY_BLE_STACK_MODE_HOST_UART (CY_BLE_CONFIG_STACK_MODE_HOST_UART) -#define CY_BLE_STACK_MODE_IPC (CY_BLE_STACK_MODE == CY_BLE_STACK_DEBUG) -#define CY_BLE_STACK_MODE_HOST_IPC ((CY_BLE_MODE_PROFILE) && \ - (((CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_HOST_IPC) || \ - (CY_BLE_CONFIG_STACK_MODE == CY_BLE_CONFIG_STACK_DEBUG)) && \ - CY_BLE_HOST_CORE)) - - -#define CY_BLE_CONN_COUNT (CY_BLE_CONFIG_CONN_COUNT) -#define CY_BLE_GAPP_CONF_COUNT (CY_BLE_CONFIG_GAP_PERIPHERAL_COUNT + CY_BLE_CONFIG_GAP_BROADCASTER_COUNT) -#define CY_BLE_GAPC_CONF_COUNT (CY_BLE_CONFIG_GAP_CENTRAL_COUNT + CY_BLE_CONFIG_GAP_OBSERVER_COUNT) - -#define CY_BLE_BONDING_YES (0x00u) -#define CY_BLE_BONDING_NO (0x01u) - -#if (CY_BLE_MODE_PROFILE) - #define CY_BLE_BONDING_REQUIREMENT (CY_BLE_CONFIG_BONDING_REQUIREMENT) -#if (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) - #define CY_BLE_MAX_BONDED_DEVICES (CY_BLE_CONFIG_MAX_BONDED_DEVICES) -#else - #define CY_BLE_MAX_BONDED_DEVICES (0u) -#endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - #define CY_BLE_ENABLE_LL_PRIVACY (CY_BLE_CONFIG_ENABLE_LL_PRIVACY) -#if (CY_BLE_ENABLE_LL_PRIVACY > 0u) - #define CY_BLE_MAX_RESOLVABLE_DEVICES (CY_BLE_CONFIG_MAX_RESOLVABLE_DEVICES) -#else - #define CY_BLE_MAX_RESOLVABLE_DEVICES (0u) -#endif /* (CY_BLE_ENABLE_LL_PRIVACY > 0u) */ - #define CY_BLE_MAX_WHITE_LIST_SIZE (CY_BLE_CONFIG_MAX_WHITE_LIST_SIZE) - #define CY_BLE_GAP_SECURITY_LEVEL (CY_BLE_CONFIG_GAP_SECURITY_LEVEL) -#else - #define CY_BLE_MAX_BONDED_DEVICES (CY_BLE_DEFAULT_BONDED_DEVICE_LIST_SZ) - #define CY_BLE_MAX_RESOLVABLE_DEVICES (CY_BLE_DEFAULT_RPA_LIST_SZ) - #define CY_BLE_MAX_WHITE_LIST_SIZE (CY_BLE_MAX_WHITELIST_LIST_SZ) - #define CY_BLE_ENABLE_LL_PRIVACY (1u) - #define CY_BLE_GAP_SECURITY_LEVEL (0x0u) -#endif /* CY_BLE_MODE_PROFILE */ - -#define CY_BLE_SHARING_NONE (0u) -#define CY_BLE_SHARING_EXPORT (1u) -#define CY_BLE_SHARING_IMPORT (2u) -#define CY_BLE_SHARING_MODE (CY_BLE_CONFIG_SHARING_MODE) -#define CY_BLE_SHARING_MODE_EXPORT (CY_BLE_SHARING_MODE == CY_BLE_SHARING_EXPORT) -#define CY_BLE_SHARING_MODE_IMPORT (CY_BLE_SHARING_MODE == CY_BLE_SHARING_IMPORT) - -/* Align the buffer size value to 4 */ -#define CY_BLE_ALIGN_TO_4(x) ((((x) & 3u) == 0u) ? (x) : (((x) - ((x) & 3u)) + 4u)) - -#if (CY_BLE_MODE_PROFILE) - -#define CY_BLE_GAP_ROLE (CY_BLE_CONFIG_GAP_ROLE) -#define CY_BLE_GAP_HCI (0x00u) -#define CY_BLE_GAP_PERIPHERAL (0x01u) -#define CY_BLE_GAP_CENTRAL (0x02u) -#define CY_BLE_GAP_BOTH (CY_BLE_GAP_CENTRAL | CY_BLE_GAP_PERIPHERAL) -#define CY_BLE_GAP_BROADCASTER (0x04u) -#define CY_BLE_GAP_OBSERVER (0x08u) - -#define CY_BLE_GAP_ROLE_PERIPHERAL (0u != (CY_BLE_GAP_ROLE & CY_BLE_GAP_PERIPHERAL)) -#define CY_BLE_GAP_ROLE_CENTRAL (0u != (CY_BLE_GAP_ROLE & CY_BLE_GAP_CENTRAL)) -#define CY_BLE_GAP_ROLE_OBSERVER (0u != (CY_BLE_GAP_ROLE & CY_BLE_GAP_OBSERVER)) -#define CY_BLE_GAP_ROLE_BROADCASTER (0u != (CY_BLE_GAP_ROLE & CY_BLE_GAP_BROADCASTER)) - -#define CY_BLE_L2CAP_Q_DEPTH_PER_CONN (CY_BLE_L2CAP_STACK_Q_DEPTH_PER_CONN + CY_BLE_CONFIG_ADD_Q_DEPTH_PER_CONN) -#define CY_BLE_L2CAP_Q_HEAP CY_BLE_ALIGN_TO_4(CY_BLE_L2CAP_Q_DEPTH_PER_CONN * \ - CY_BLE_L2CAP_QUEUE_ELEMENT_SIZE * CY_BLE_CONN_COUNT) - -/* If mtu > 32 stack queue depth = (stack queue depth per connection + 2) * maxBleConnection */ -#define CY_BLE_GATT_MTU_BUFF_COUNT ((CY_BLE_L2CAP_Q_DEPTH_PER_CONN + ((CY_BLE_CONFIG_GATT_MTU > \ - CY_BLE_L2CAP_MTU_MIN_VALUE) ? 2u : 0u)) * \ - CY_BLE_CONN_COUNT) - -/* GATT MTU Size */ -#define CY_BLE_GATT_MTU (CY_BLE_CONFIG_GATT_MTU) -#define CY_BLE_GATT_MTU_PLUS_L2CAP_MEM_EXT (CY_BLE_ALIGN_TO_4(CY_BLE_GATT_MTU + CY_BLE_MEM_EXT_SZ + \ - CY_BLE_L2CAP_HDR_SZ)) - -/* GATT Maximum attribute length */ -#define CY_BLE_GATT_MAX_ATTR_LEN ((CY_BLE_CONFIG_GATT_DB_MAX_VALUE_LEN == 0u) ? (1u) : \ - (CY_BLE_CONFIG_GATT_DB_MAX_VALUE_LEN)) -#define CY_BLE_GATT_MAX_ATTR_LEN_PLUS_L2CAP_MEM_EXT \ - (CY_BLE_ALIGN_TO_4(CY_BLE_GATT_MAX_ATTR_LEN + CY_BLE_MEM_EXT_SZ + \ - CY_BLE_L2CAP_HDR_SZ)) - -/* The header length for Prepare Write request */ -#define CY_BLE_GATT_PREPARE_WRITE_HEADER_LEN (5u) -/* The header length for Write request */ -#define CY_BLE_GATT_WRITE_HEADER_LEN (3u) - -/* The number of characteristics supporting a Reliable Write property */ -#define CY_BLE_GATT_RELIABLE_CHAR_COUNT (CY_BLE_CONFIG_GATT_RELIABLE_CHAR_COUNT) -/* The total length of characteristics with a Reliable Write property */ -#define CY_BLE_GATT_RELIABLE_CHAR_LENGTH (CY_BLE_CONFIG_GATT_RELIABLE_CHAR_LENGTH) - -#define CY_BLE_GATT_PREPARE_LENGTH ((CY_BLE_GATT_RELIABLE_CHAR_LENGTH > CY_BLE_GATT_MAX_ATTR_LEN) ? \ - CY_BLE_GATT_RELIABLE_CHAR_LENGTH : CY_BLE_GATT_MAX_ATTR_LEN) - -/* The number of buffers required for Prepare Write request based on assumption that the negotiated MTU - * size is equal to the CY_BLE_GATT_DEFAULT_MTU and all the characteristics supporting a Reliable Write - * property must be written, in order, in a single operation. - * The buffer count is 0 when the maximum attribute size is less than the minimum MTU - 3. - */ -#define CY_BLE_GATT_MAX_PREPARE_BUFF_COUNT \ - (((CY_BLE_GATT_MAX_ATTR_LEN <= (CY_BLE_GATT_DEFAULT_MTU - CY_BLE_GATT_WRITE_HEADER_LEN)) && \ - (CY_BLE_GATT_RELIABLE_CHAR_COUNT == 0u)) ? 0u : \ - ((CY_BLE_GATT_PREPARE_LENGTH / (CY_BLE_GATT_DEFAULT_MTU - CY_BLE_GATT_PREPARE_WRITE_HEADER_LEN)) + \ - (((CY_BLE_GATT_PREPARE_LENGTH % (CY_BLE_GATT_DEFAULT_MTU - CY_BLE_GATT_PREPARE_WRITE_HEADER_LEN)) > 0u) ? \ - 1u : 0u))) - -#define CY_BLE_GATT_PREPARE_LENGTH_ALIGN ((CY_BLE_GATT_MAX_PREPARE_BUFF_COUNT == 0u) ? 0u : \ - CY_BLE_ALIGN_TO_4(CY_BLE_GATT_PREPARE_LENGTH)) - -/* The parameter to enable the application to provide a dynamically allocated buffer for Prepare Write request. */ -#define CY_BLE_GATT_ENABLE_EXTERNAL_PREP_WRITE_BUFF (CY_BLE_CONFIG_GATT_ENABLE_EXTERNAL_PREP_WRITE_BUFF) - -/* Buffer length for the data received during Prepare Write requests - * For dynamic memory allocation by the application level, set the EnableExternalPrepWriteBuff parameter - * in the Expression view of the Advanced tab to true. - */ -#define CY_BLE_GATT_PREPARE_WRITE_BUFF_LEN ((CY_BLE_GATT_ENABLE_EXTERNAL_PREP_WRITE_BUFF != 0u) ? 0u : \ - (CY_BLE_GATT_PREPARE_LENGTH_ALIGN + \ - (CY_BLE_GATT_MAX_PREPARE_BUFF_COUNT * \ - sizeof(cy_stc_ble_gatt_handle_value_offset_param_t)))) - -#define CY_BLE_L2CAP_ENABLE (CY_BLE_CONFIG_L2CAP_ENABLE) - -#if (CY_BLE_L2CAP_ENABLE != 0u) -/* L2CAP MTU Size */ - #define CY_BLE_L2CAP_MTU (CY_BLE_CONFIG_L2CAP_MTU) -/* L2CAP PMS Size */ - #define CY_BLE_L2CAP_MPS (CY_BLE_CONFIG_L2CAP_MPS) - #define CY_BLE_L2CAP_MTU_MPS (CY_BLE_L2CAP_MTU / CY_BLE_L2CAP_MPS) -/* Number of L2CAP Logical channels */ - #define CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT (CY_BLE_CONFIG_L2CAP_LOGICAL_CHANNEL_COUNT) -/* Number of L2CAP PSMs */ - #define CY_BLE_L2CAP_PSM_COUNT (CY_BLE_CONFIG_L2CAP_PSM_COUNT) -#else -/* L2CAP MTU Size */ - #define CY_BLE_L2CAP_MTU (0u) -/* L2CAP PMS Size */ - #define CY_BLE_L2CAP_MPS (0u) - #define CY_BLE_L2CAP_MTU_MPS (0u) -/* Number of L2CAP Logical channels */ - #define CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT (0u) -/* Number of L2CAP PSMs */ - #define CY_BLE_L2CAP_PSM_COUNT (0u) -#endif /* CY_BLE_L2CAP_ENABLE != 0u */ - -/* L2CAP RAM buffer sizes */ -#define CY_BLE_L2CAP_MTU_PLUS_L2CAP_MEM_EXT (CY_BLE_ALIGN_TO_4(CY_BLE_L2CAP_MTU + \ - CY_BLE_MEM_EXT_SZ + CY_BLE_L2CAP_HDR_SZ)) -#define CY_BLE_L2CAP_MPS_PLUS_L2CAP_MEM_EXT (CY_BLE_ALIGN_TO_4(CY_BLE_L2CAP_MPS + CY_BLE_MEM_EXT_SZ + \ - CY_BLE_L2CAP_HDR_SZ)) -#define CY_BLE_L2CAP_PSM_PLUS_L2CAP_MEM_EXT (CY_BLE_ALIGN_TO_4((CY_BLE_L2CAP_PSM_SIZE + CY_BLE_MEM_EXT_SZ) * \ - CY_BLE_L2CAP_PSM_COUNT)) -#define CY_BLE_L2CAP_CBFC_PLUS_L2CAP_MEM_EXT (CY_BLE_ALIGN_TO_4((CY_BLE_L2CAP_CBFC_CHANNEL_SIZE + \ - CY_BLE_MEM_EXT_SZ) * CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT)) - -#endif /* CY_BLE_MODE_PROFILE */ - -/* LL max data length */ -#define CY_BLE_LL_MAX_SUPPORTED_TX_PAYLOAD_SIZE (251u) -#define CY_BLE_LL_MAX_SUPPORTED_RX_PAYLOAD_SIZE (251u) -#define CY_BLE_LL_MIN_SUPPORTED_TX_PAYLOAD_SIZE (27u) -#define CY_BLE_LL_MIN_SUPPORTED_RX_PAYLOAD_SIZE (27u) -#define CY_BLE_LL_MAX_TX_TIME (0x0848u) - -#if (CY_BLE_MODE_PROFILE) - #define CY_BLE_LL_MAX_TX_PAYLOAD_SIZE (CY_BLE_CONFIG_LL_MAX_TX_PAYLOAD_SIZE) - #define CY_BLE_LL_MAX_RX_PAYLOAD_SIZE (CY_BLE_CONFIG_LL_MAX_RX_PAYLOAD_SIZE) -#else /* Use maximum payload size for HCI mode */ - #define CY_BLE_LL_MAX_TX_PAYLOAD_SIZE (CY_BLE_LL_MAX_SUPPORTED_TX_PAYLOAD_SIZE) - #define CY_BLE_LL_MAX_RX_PAYLOAD_SIZE (CY_BLE_LL_MAX_SUPPORTED_RX_PAYLOAD_SIZE) -#endif /* CY_BLE_MODE_PROFILE */ - -#define CY_BLE_LL_MAX_TX_PAYLOAD_BUFFER_SZ CY_BLE_ALIGN_TO_4(CY_BLE_LL_MAX_TX_PAYLOAD_SIZE) -#define CY_BLE_LL_MAX_RX_PAYLOAD_BUFFER_SZ CY_BLE_ALIGN_TO_4(CY_BLE_LL_MAX_RX_PAYLOAD_SIZE) - -#if ((CY_BLE_LL_MAX_TX_PAYLOAD_SIZE > CY_BLE_LL_MIN_SUPPORTED_TX_PAYLOAD_SIZE) || \ - (CY_BLE_LL_MAX_RX_PAYLOAD_SIZE > CY_BLE_LL_MIN_SUPPORTED_RX_PAYLOAD_SIZE)) - #define CY_BLE_DLE_FEATURE (CY_BLE_DLE_FEATURE_MASK) - #define CY_BLE_LL_DLE_HEAP_SZ (CY_BLE_LL_DLE_HEAP_REQ) -#else - #define CY_BLE_DLE_FEATURE (0u) - #define CY_BLE_LL_DLE_HEAP_SZ (0u) -#endif /* DLE enabled */ - -#if (CY_BLE_ENABLE_LL_PRIVACY > 0u) - #define CY_BLE_LL_PRIVACY_FEATURE (CY_BLE_PRIVACY_1_2_FEATURE_MASK) - #define CY_BLE_LL_PRIVACY_HEAP_SZ (CY_BLE_LL_PRIVACY_HEAP_REQ) - #define CY_BLE_STORE_RESOLVING_LIST_FEATURE (CY_BLE_PERSISTENT_STORE_RESOLVING_LIST) -/* Resolving list memory computation */ - #define CY_BLE_STACK_RESOLVING_LIST_SIZE ((CY_BLE_LL_PRIVACY_HEAP_SZ * CY_BLE_MAX_RESOLVABLE_DEVICES) + \ - CY_BLE_LL_PRIVACY_RETENTION_HEAP_REQ) -#else - #define CY_BLE_LL_PRIVACY_FEATURE (0u) - #define CY_BLE_LL_PRIVACY_HEAP_SZ (0u) - #define CY_BLE_STORE_RESOLVING_LIST_FEATURE (0u) - #define CY_BLE_STACK_RESOLVING_LIST_SIZE (0u) -#endif /* CY_BLE_MAX_RESOLVABLE_DEVICES > 0u */ - -#if (CY_BLE_GAP_SECURITY_LEVEL == 0x03) - #define CY_BLE_SECURE_CONN_FEATURE (CY_BLE_SECURE_CONN_FEATURE_MASK) - #define CY_BLE_RAM_SECURE_CONNECTIONS_SIZE (CY_BLE_RAM_SIZE_SECURE_CONNECTIONS) -#else - #define CY_BLE_SECURE_CONN_FEATURE (0u) - #define CY_BLE_RAM_SECURE_CONNECTIONS_SIZE (0u) -#endif /* CY_BLE_GAP_SECURITY_LEVEL == 0x03 */ - -#if ((CY_BLE_CONFIG_ENABLE_PHY_UPDATE != 0u) || (CY_BLE_MODE_HCI)) - #define CY_BLE_PHY_UPDATE_FEATURE (CY_BLE_PHY_UPDATE_FEATURE_MASK) -#else - #define CY_BLE_PHY_UPDATE_FEATURE (0u) -#endif /* (CY_BLE_CONFIG_ENABLE_PHY_UPDATE != 0u) || (CY_BLE_MODE_HCI) */ - -/** Radio power calibration */ -#if (CY_BLE_CONFIG_TX_POWER_CALIBRATION_ENABLE != 0u) - #define CY_BLE_CONFIG_TX_POWER_CALIBRATION_FEATURE (CY_BLE_PERSISTENT_RADIO_CALIBRATION_MASK) -#else - #define CY_BLE_CONFIG_TX_POWER_CALIBRATION_FEATURE (0u) -#endif /* CY_BLE_CONFIG_TX_POWER CALIBRATION != 0u */ - -#if ((CY_BLE_MODE_PROFILE) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - #define CY_BLE_STORE_BONDLIST_FEATURE (CY_BLE_PERSISTENT_STORE_BONDLIST) -/* Bonded device list flash memory computation */ - #define CY_BLE_STACK_BOND_FLASH_SIZE ((CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE * CY_BLE_MAX_BONDED_DEVICES) + \ - (CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE * (CY_BLE_CONN_COUNT + \ - CY_BLE_MAX_BONDED_DEVICES))) -/* Bonded device list RAM memory computation */ - #define CY_BLE_STACK_BOND_RAM_SIZE ((CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE + \ - CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE) * \ - (CY_BLE_CONN_COUNT + CY_BLE_MAX_BONDED_DEVICES)) -#else - #define CY_BLE_STORE_BONDLIST_FEATURE (0u) - #define CY_BLE_STACK_BOND_FLASH_SIZE (0u) - #define CY_BLE_STACK_BOND_RAM_SIZE (0u) -#endif /* (CY_BLE_MODE_PROFILE) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - -#define CY_BLE_STORE_WHITELIST_FEATURE (CY_BLE_PERSISTENT_STORE_WHITELIST) -/* Whitelist list memory computation */ -#define CY_BLE_STACK_WHITELIST_SIZE ((CY_BLE_LL_ONE_WHITELIST_HEAP_REQ * CY_BLE_MAX_WHITE_LIST_SIZE) + \ - CY_BLE_LL_WHITELIST_RETENTION_HEAP_REQ) - -#define CY_BLE_DLE_FEATURE_ENABLED (CY_BLE_DLE_FEATURE != 0u) -#define CY_BLE_LL_PRIVACY_FEATURE_ENABLED (CY_BLE_LL_PRIVACY_FEATURE != 0u) -#define CY_BLE_SECURE_CONN_FEATURE_ENABLED (CY_BLE_SECURE_CONN_FEATURE != 0u) -#define CY_BLE_PHY_UPDATE_FEATURE_ENABLED (CY_BLE_PHY_UPDATE_FEATURE != 0u) - -#define CY_BLE_LL_ACL_TX_HEAP_SZ (CY_BLE_LL_DEFAULT_NUM_ACL_TX_PACKETS * \ - (CY_BLE_LL_MAX_TX_PAYLOAD_BUFFER_SZ + \ - CY_BLE_LL_ACL_DATA_PACKET_OVERHEAD_SZ + \ - CY_BLE_MEM_EXT_SZ)) - -#define CY_BLE_LL_ACL_RX_HEAP_SZ (CY_BLE_LL_DEFAULT_NUM_ACL_RX_PACKETS * \ - (CY_BLE_LL_MAX_RX_PAYLOAD_BUFFER_SZ + \ - CY_BLE_LL_ACL_DATA_PACKET_OVERHEAD_SZ + \ - CY_BLE_MEM_EXT_SZ)) - - -#define CY_BLE_LL_CONTROLLER_HEAP_REQ ((CY_BLE_DLE_DEVICE_PARAM_SZ) + \ - (CY_BLE_LL_DLE_HEAP_REQ * CY_BLE_CONN_COUNT) + \ - ((CY_BLE_CONTROLLER_CONN_SPECIFIC_HEAP_REQ + \ - CY_BLE_LL_ACL_TX_HEAP_SZ) * CY_BLE_CONN_COUNT) + \ - CY_BLE_CONTROLLER_DEVICE_SPECIFIC_HEAP_REQ + \ - CY_BLE_LL_ACL_RX_HEAP_SZ + \ - CY_BLE_STACK_RESOLVING_LIST_SIZE + \ - CY_BLE_STACK_WHITELIST_SIZE) - -/** CRC size for stack flash*/ -#define CY_BLE_STACK_FLASH_CRC_SIZE (2u) - -#if (CY_BLE_MODE_PROFILE) -/** - * \addtogroup group_ble_common_api_macros - * @{ - */ - -/** The size of RAM memory required for the stack */ - #define CY_BLE_STACK_RAM_SIZE (CY_BLE_ALIGN_TO_4(CY_BLE_DEFAULT_HOST_RAM_SIZE + CY_BLE_LL_CONTROLLER_HEAP_REQ + \ - CY_BLE_RAM_SECURE_CONNECTIONS_SIZE + CY_BLE_L2CAP_Q_HEAP + \ - CY_BLE_STACK_BOND_RAM_SIZE + \ - (CY_BLE_GATT_MTU_PLUS_L2CAP_MEM_EXT * CY_BLE_GATT_MTU_BUFF_COUNT) + \ - (CY_BLE_L2CAP_PSM_PLUS_L2CAP_MEM_EXT * CY_BLE_L2CAP_PSM_COUNT) + \ - (CY_BLE_L2CAP_CBFC_PLUS_L2CAP_MEM_EXT * 2u * \ - CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT) + \ - (CY_BLE_L2CAP_MTU_PLUS_L2CAP_MEM_EXT * 2u * \ - CY_BLE_L2CAP_LOGICAL_CHANNEL_COUNT) + \ - (CY_BLE_STACK_BUFFER_MGR_UTIL_RAM_SZ * CY_BLE_STACK_APP_MIN_POOL) + \ - (CY_BLE_RAM_SIZE_HOST_SINGLE_CONN * CY_BLE_CONN_COUNT) + \ - (CY_BLE_GATT_PREPARE_WRITE_BUFF_LEN))) /* This buffer must always be the latest */ -#else -/** The size of RAM memory required for the stack */ - #define CY_BLE_STACK_RAM_SIZE (CY_BLE_LL_CONTROLLER_HEAP_REQ) -#endif /* CY_BLE_MODE_PROFILE */ - - -/** The size of flash memory required for the bonding data */ -#define CY_BLE_STACK_FLASH_SIZE (CY_BLE_STACK_BOND_FLASH_SIZE + \ - CY_BLE_STACK_RESOLVING_LIST_SIZE + \ - CY_BLE_STACK_WHITELIST_SIZE + \ - CY_BLE_STACK_FLASH_CRC_SIZE ) - -/** @} group_ble_common_api_macros */ - -/*************************************** -* Private Function Prototypes -***************************************/ -cy_en_syspm_status_t Cy_BLE_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams); -cy_en_syspm_status_t Cy_BLE_SleepCallback(cy_stc_syspm_callback_params_t *callbackParams); - -/*************************************** -* Function Prototypes -***************************************/ -/** - * \addtogroup group_ble_common_api_functions - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_Enable(void); -cy_en_ble_api_result_t Cy_BLE_Disable(void); -void Cy_BLE_ConfigureExtPA(uint32_t controlValue); -/** @} */ - - -/*************************************** -* External data references -***************************************/ -void Cy_BLE_UnregisterHostPMCallbacks(void); -extern cy_ble_callback_t Cy_BLE_ApplCallback; -extern uint8_t cy_ble_initVar; -#if (CY_BLE_SHARING_MODE_EXPORT) -extern uint8_t *cy_ble_stackMemoryRam; -#else -extern uint8_t cy_ble_stackMemoryRam[CY_BLE_STACK_RAM_SIZE]; -#endif /* CY_BLE_SHARING_MODE_EXPORT */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CY_BLE_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_aios.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_aios.c deleted file mode 100644 index 5474548977..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_aios.c +++ /dev/null @@ -1,2325 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_aios.c -* \version 2.0 -* -* \brief -* Contains the source code for Automation Input Output Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_AIOS)) - -#ifdef CY_BLE_AIOS_SERVER -static cy_ble_gatt_db_attr_handle_t cy_ble_aiossReqHandle; -#endif /* CY_BLE_AIOS_SERVER */ - -#ifdef CY_BLE_AIOS_CLIENT -static cy_ble_gatt_db_attr_handle_t cy_ble_aioscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -uint8_t cy_ble_aioscActiveCharIndex[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -uint8_t cy_ble_aioscActiveCharInstance[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -uint8_t cy_ble_aioscPrevCharInstIndex[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -#endif /* (CY_BLE_AIOS_CLIENT) */ - -static cy_ble_callback_t Cy_BLE_AIOS_ApplCallback = NULL; - -/* The pointer on global BLE AIOS Config structure */ -cy_stc_ble_aios_config_t *cy_ble_aiosConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_AIOS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_AIOSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_AIOSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_AIOS_SetAggregateChar(void); -#endif /* CY_BLE_AIOS_SERVER */ - -#ifdef CY_BLE_AIOS_CLIENT -static void Cy_BLE_AIOSC_DiscoverCharacteristicsEventHandler(const cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_AIOSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_AIOSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_AIOSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_AIOSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_AIOSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_AIOSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_AIOSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -#endif /* CY_BLE_AIOS_CLIENT */ - -static cy_en_ble_gatt_err_code_t Cy_BLE_AIOS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOS_Init -***************************************************************************//** -* -* This function initializes the Automation IO Service. -* \param config: Configuration structure for the Environmental Sensing Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOS_Init(cy_stc_ble_aios_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_aiosConfigPtr = config; - - /* Registers Event Handler for the AIOS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_AIOS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_aiosConfigPtr->callbackFunc != NULL) - { - Cy_BLE_AIOS_ApplCallback = cy_ble_aiosConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_AIOS_SERVER - cy_ble_aiossReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - (void)Cy_BLE_AIOS_SetAggregateChar(); - #endif /* CY_BLE_AIOS_SERVER */ - - #ifdef CY_BLE_AIOS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - uint32_t i; - uint32_t j; - - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_AIOS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - for(i = 0u; (i < (uint32_t)CY_BLE_AIOS_CHAR_COUNT); i++) - { - for(j = 0u; j < cy_ble_aiosConfigPtr->aioscCharInstances[i]; j++) - { - (void)memset(&cy_ble_aiosConfigPtr->aiosc[idx].charInfoAddr[i].charInfoPtr[j], 0, - sizeof(cy_stc_ble_aiosc_char_t)); - } - } - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_AIOS].uuid = CY_BLE_UUID_AUTOMATION_INPUT_OUTPUT_SERVICE; - } - - cy_ble_aioscActiveCharIndex[idx] = 0u; - cy_ble_aioscActiveCharInstance[idx] = 0u; - cy_ble_aioscPrevCharInstIndex[idx] = 0u; - cy_ble_aioscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_AIOS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for AIOS Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode: Indicates the event that triggered this callback -* (e.g. CY_BLE_EVT_AIOS_NOTIFICATION_ENABLED). -* * eventParam: Contains the parameters corresponding to the -* current event. (e.g. Pointer to cy_stc_ble_aios_char_value_t -* structure that contains details of the characteristic -* for which the notification enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_AIOS_ApplCallback = callbackFunc; - if(cy_ble_aiosConfigPtr != NULL) - { - cy_ble_aiosConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - -#ifdef CY_BLE_AIOS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if the it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS - profile or service -* request cannot be serviced because an operation that -* has been previously triggered is still in progress. -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED - Client Characteristic Configuration -* descriptor is not configured according to the requirements -* of the profile or service. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_AIOSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_ble_gatt_db_attr_handle_t tmpHandle; - cy_stc_ble_aioss_char_t *aiosCharInfoPtr; - cy_stc_ble_aios_descr_value_t wrDescrReqParam; - cy_stc_ble_aios_char_value_t wrCharReqParam; - uint32_t descInd; - uint32_t event = 0u; - uint32_t foundItem = CY_BLE_AIOS_UNDEFINED_ITEM; - uint8_t i; - uint8_t j; - - tmpHandle = eventParam->handleValPair.attrHandle; - - if(Cy_BLE_AIOS_ApplCallback != NULL) - { - /* Go through all possible Service characteristics. - * Exit the handler in following conditions: - * 1) No more characteristic left; - * 2) Characteristic or descriptor was successfully written; - * 3) Error occurred while writing characteristic or descriptor. - */ - for(i = 0u; ((i < ((uint8_t)CY_BLE_AIOS_CHAR_COUNT)) && (foundItem == 0u) && (gattErr == CY_BLE_GATT_ERR_NONE)); - i++) - { - /* Check if characteristic is enabled. If the pointer to the characteristic - * is not "NULL", there is at least one instance of the characteristic in - * the AIO Service. - */ - - if(cy_ble_aiosConfigPtr->aioss->charInfoAddr[i].charInfoPtr != NULL) - { - for(j = 0u; j < cy_ble_aiosConfigPtr->aiossCharInstances[i]; j++) - { - aiosCharInfoPtr = &cy_ble_aiosConfigPtr->aioss->charInfoAddr[i].charInfoPtr[j]; - - /* Client Characteristic Write Request handling */ - if(tmpHandle == aiosCharInfoPtr->charHandle) - { - wrDescrReqParam.descrIndex = CY_BLE_AIOS_DESCR_COUNT; - foundItem = CY_BLE_AIOS_CHARACTERISTIC_ITEM; - } - - /* Client Characteristic Descriptor Write Request handling */ - else - { - wrDescrReqParam.descrIndex = CY_BLE_AIOS_DESCR_COUNT; - - for(descInd = 0u; (descInd < (uint32_t)CY_BLE_AIOS_DESCR_COUNT) && - (foundItem != CY_BLE_AIOS_DESCRIPTOR_ITEM); descInd++) - { - if(aiosCharInfoPtr->descrHandle[descInd] == tmpHandle) - { - wrDescrReqParam.descrIndex = (cy_en_ble_aios_descr_index_t)descInd; - foundItem = CY_BLE_AIOS_DESCRIPTOR_ITEM; - } - } - } - - /* Verify if requested handle was found and successfully handled */ - if((gattErr == CY_BLE_GATT_ERR_NONE) && (foundItem == CY_BLE_AIOS_DESCRIPTOR_ITEM)) - { - switch(wrDescrReqParam.descrIndex) - { - case CY_BLE_AIOS_CCCD: - /* Verify that optional notification property is enabled for characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(aiosCharInfoPtr->charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_AIOSS_NOTIFICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_AIOSS_NOTIFICATION_DISABLED; - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set a flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else if(CY_BLE_IS_INDICATION_SUPPORTED(aiosCharInfoPtr->charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_AIOSS_INDICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_AIOSS_INDICATION_DISABLED; - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set a flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - break; - - case CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR: - if(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN( - aiosCharInfoPtr->descrHandle[CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR]) >= - eventParam->handleValPair.value.len) - { - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN( - aiosCharInfoPtr->descrHandle[CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR], - eventParam->handleValPair.value.len); - } - else - { - gattErr = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - break; - - case CY_BLE_AIOS_VALUE_TRIGGER_SETTINGS: - /* Trigger condition value not supported.*/ - if(eventParam->handleValPair.value.val[0u] >= CY_BLE_AIOS_VALUE_TRIGGER_DESCR_MAX_VALUE) - { - gattErr = - (cy_en_ble_gatt_err_code_t)CY_BLE_GATT_ERR_TRIGGER_CODITION_VALUE_NOT_SUPPORTED; - } - break; - - case CY_BLE_AIOS_TIME_TRIGGER_SETTINGS: - /* Trigger condition value not supported.*/ - if(eventParam->handleValPair.value.val[0u] >= CY_BLE_AIOS_TIME_TRIGGER_DESCR_MAX_VALUE) - { - gattErr = - (cy_en_ble_gatt_err_code_t)CY_BLE_GATT_ERR_TRIGGER_CODITION_VALUE_NOT_SUPPORTED; - } - break; - - default: - break; - } - } - - /* Check is there no error conditions happen yet */ - if((gattErr == CY_BLE_GATT_ERR_NONE) - && ((foundItem == CY_BLE_AIOS_CHARACTERISTIC_ITEM) || (foundItem == CY_BLE_AIOS_DESCRIPTOR_ITEM))) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = - Cy_BLE_GATT_DbCheckPermission(eventParam->handleValPair.attrHandle, - &eventParam->connHandle, - CY_BLE_GATT_DB_WRITE | CY_BLE_GATT_DB_PEER_INITIATED); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - /* Fill data and pass it to user */ - - if(foundItem == CY_BLE_AIOS_CHARACTERISTIC_ITEM) - { - wrCharReqParam.connHandle = eventParam->connHandle; - wrCharReqParam.charIndex = (cy_en_ble_aios_char_index_t)i; - wrCharReqParam.charInstance = j; - wrCharReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - wrCharReqParam.value = &eventParam->handleValPair.value; - - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSS_WRITE_CHAR, &wrCharReqParam); - } - else if(foundItem == CY_BLE_AIOS_DESCRIPTOR_ITEM) - { - wrDescrReqParam.connHandle = eventParam->connHandle; - wrDescrReqParam.charIndex = (cy_en_ble_aios_char_index_t)i; - wrDescrReqParam.charInstance = j; - wrDescrReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - wrDescrReqParam.value = &eventParam->handleValPair.value; - - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSS_DESCR_WRITE, &wrDescrReqParam); - } - else - { - /* No handle match was found */ - } - - /* Write value to GATT database */ - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); \ - if(event != 0u) - { - Cy_BLE_AIOS_ApplCallback(event, &wrDescrReqParam); - } - else - { - /* No event was found */ - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - } - - if(gattErr != CY_BLE_GATT_ERR_NONE) - { - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - if(foundItem == CY_BLE_AIOS_CHARACTERISTIC_ITEM) - { - gattErr = Cy_BLE_AIOS_SetAggregateChar(); - } - } - - return(gattErr); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the characteristic value of the service in the local database. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size (in bytes) of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSS_SetCharacteristicValue(cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - /* Validate range of AIOS characteristics */ - if((charIndex < CY_BLE_AIOS_CHAR_COUNT) && (charInstance < cy_ble_aiosConfigPtr->aiossCharInstances[charIndex])) - { - /* Check if requested characteristic is present in Service. - * There are three conditions which should be checked: 1) The pointer to - * "CY_BLE_AIOS_CHAR_T" is not NULL, 2) The handle of the characteristic is - * a valid handle, 3) The requested instance is a valid characteristic - * instance. - */ - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gatt_handle_value_pair_t locHandleValuePair = - { - .attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle, - .value.len = attrSize, - .value.val = attrValue, - }; - - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = locHandleValuePair, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Store data in database */ - if(Cy_BLE_GATTS_WriteAttributeValue(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - if(apiResult == CY_BLE_SUCCESS) - { - apiResult = (cy_en_ble_api_result_t)Cy_BLE_AIOS_SetAggregateChar(); - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the characteristic value of the service, which is a value identified by -* charIndex. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSS_GetCharacteristicValue(cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_AIOS_CHAR_COUNT) && (charInstance < cy_ble_aiosConfigPtr->aiossCharInstances[charIndex])) - { - /* Check if requested characteristic is present in Service. There are three - * conditions to be checked: 1) The pointer to "cy_stc_ble_aioss_char_t" record in - * the cy_ble_aioss struct is not NULL, 2) The handle of the characteristic is a - * valid handle, 3) The requested instance is a valid characteristic instance. - */ - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gatt_handle_value_pair_t locHandleValuePair = - { - .attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle, - .value.len = attrSize, - .value.val = attrValue, - }; - - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = locHandleValuePair, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_ReadAttributeValue(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, attrSize); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the -* Automation Input Output Service from the local GATT database. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_AIOS_CHAR_COUNT) && (charInstance < cy_ble_aiosConfigPtr->aiossCharInstances[charIndex]) && - (descrIndex < CY_BLE_AIOS_DESCR_COUNT)) - { - /* Check if requested descriptor is present in Service. - * There are three conditions to be checked: 1) The pointer to - * "CY_BLE_AiosS_CHAR_T" is not NULL, 2) The handle of the characteristic is - * a valid handle, 3) The handle of the descriptor is a valid handle. - */ - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gatt_handle_value_pair_t locHandleValuePair = - { - .attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[descrIndex], - .value.len = attrSize, - .value.val = attrValue, - }; - - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = locHandleValuePair, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == - CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], attrSize); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Set a characteristic descriptor of a specified characteristic of the Indoor -* Positioning Service from the local GATT database. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data to -* be stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_AIOS_CHAR_COUNT) && (charInstance < cy_ble_aiosConfigPtr->aiossCharInstances[charIndex]) && - (descrIndex < CY_BLE_AIOS_DESCR_COUNT)) - { - /* Check if requested descriptor is present in Service. - * There are three conditions to be checked: 1) The pointer to - * "CY_BLE_AiosS_CHAR_T" is not NULL, 2) The handle of the characteristic is - * a valid handle, 3) The handle of the descriptor is a valid handle. - */ - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gatt_handle_value_pair_t locHandleValuePair = - { - .attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[descrIndex], - .value.len = attrSize, - .value.val = attrValue - }; - - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = locHandleValuePair, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_SendNotification -***************************************************************************//** -* -* Sends a notification with a characteristic value of the Automation Input Output -* Service, which is a value specified by charIndex, to the client's device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_AIOSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - A notification is not enabled by the client. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_AIOS_CHAR_COUNT) && (charInstance < cy_ble_aiosConfigPtr->aiossCharInstances[charIndex])) - { - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[CY_BLE_AIOS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Send notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_aiosConfigPtr->aioss-> - charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[CY_BLE_AIOS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_SendIndication -***************************************************************************//** -* -* Sends an indication with a characteristic value of the Automation Input Output -* Service, which is a value specified by charIndex, to the client's device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_AIOSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the AIOS service-specific callback is registered -* (with Cy_BLE_AIOS_RegisterAttrCallback): -* * CY_BLE_EVT_AiosS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the AIOS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult; - - /* Send indication if it is enabled and connected */ - if(charIndex >= CY_BLE_AIOS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charInstance >= cy_ble_aiosConfigPtr->aiossCharInstances[charIndex]) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[CY_BLE_AIOS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - if(cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send indication to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - /* Save handle to support service specific value confirmation response from client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_aiossReqHandle = indReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* eventParam - The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_AIOSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_en_ble_aios_char_index_t locCharIndex; - cy_stc_ble_aios_char_value_t locCharValue; - uint32_t locReqHandle = 0u; - uint8_t locCharInstance; - - if((Cy_BLE_AIOS_ApplCallback != NULL) && (cy_ble_aiossReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_AIOS_DIGITAL; (locCharIndex < CY_BLE_AIOS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - for(locCharInstance = 0u; (locCharInstance < cy_ble_aiosConfigPtr->aiossCharInstances[locCharIndex]) && - (locReqHandle == 0u); locCharInstance++) - { - if(cy_ble_aiossReqHandle == cy_ble_aiosConfigPtr->aioss->charInfoAddr[locCharIndex]. - charInfoPtr[locCharInstance].charHandle) - { - locCharValue.connHandle = *eventParam; - locCharValue.charIndex = locCharIndex; - locCharValue.charInstance = locCharInstance; - locCharValue.value = NULL; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_aiossReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSS_INDICATION_CONFIRMED, &locCharValue); - locReqHandle = 1u; - } - } - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOS_SetAggregateChar -***************************************************************************//** -* -* Sets the value for Aggregate characteristic. -* All of the defined Digital characteristics with the Read property set be -* part of Aggregate (if available). The length of each of the Digital characteristics -* that is part of the Aggregate is determined from the number of signals defined in the -* Number of Digitals descriptor of the Digital characteristic. The Digital part byte -* aligned and trailing bits (if any) set to 0. The order of the Digital characteristics -* is determined by the value in the Description field of the Characteristic Presentation -* Format descriptor with the lowest value first. -* All of the defined Analog characteristics with Read property set part of the Aggregate -* (if available). The order of the Analog characteristics is determined by the value in -* the Description field of the Characteristic Presentation Format descriptor with the -* lowest value first. -* The first analog input follows directly after the last Digital characteristic. -* -* \return -* A return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - The advertisement packet collected successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * Other GATT Error codes are specified in 'cy_en_ble_gatt_err_code_t' -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_AIOS_SetAggregateChar(void) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_en_ble_aios_char_index_t locCharIndex; - uint8_t locCharInstance; - uint8_t locAttrValue[CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT_LEN]; - uint8_t aggregateChar[CY_BLE_GATT_MTU - 3u]; - uint16_t currentDescriptionValue; - uint16_t minDescriptionValue; - uint16_t minDescriptionValueTmp = 0xFFFFu; - uint16_t maxDescriptionValue; - uint16_t minDescriptionNumber; - uint8_t locCharInstanceNumber; - uint8_t aggregateCharIndex = 0u; - uint8_t aggregateDigitalBits = 0u; - uint8_t numOfDigital; - uint8_t i; - - for(i = 0u; i < (CY_BLE_GATT_MTU - 3u); i++) - { - aggregateChar[i] = 0u; - } - - for(i = 0u; i < CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT_LEN; i++) - { - locAttrValue[i] = 0u; - } - - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[CY_BLE_AIOS_AGGREGATE].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[CY_BLE_AIOS_AGGREGATE].charInfoPtr[0].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_AIOS_DIGITAL; (locCharIndex <= CY_BLE_AIOS_ANALOG) && (gattErr == CY_BLE_GATT_ERR_NONE); - locCharIndex++) - { - minDescriptionValue = 0u; - minDescriptionNumber = 0u; - - for(locCharInstanceNumber = 0u; - (locCharInstanceNumber < cy_ble_aiosConfigPtr->aiossCharInstances[locCharIndex]) && - (gattErr == CY_BLE_GATT_ERR_NONE); locCharInstanceNumber++) - { - maxDescriptionValue = CY_BLE_AIOS_MAX_CHAR_DESCRIPTION_VALUE; - - for(locCharInstance = 0u; - (locCharInstance < cy_ble_aiosConfigPtr->aiossCharInstances[locCharIndex]) && - (gattErr == CY_BLE_GATT_ERR_NONE); locCharInstance++) - { - if((cy_ble_aiosConfigPtr->aioss->charInfoAddr[locCharIndex].charInfoPtr != NULL) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[locCharIndex].charInfoPtr[locCharInstance].charHandle - != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) && - (cy_ble_aiosConfigPtr->aioss->charInfoAddr[locCharIndex].charInfoPtr[locCharInstance]. - descrHandle[CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[locCharIndex]. - charInfoPtr[locCharInstance]. - descrHandle[CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT], - .handleValuePair.value.len = CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT_LEN, - .handleValuePair.value.val = locAttrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - gattErr = Cy_BLE_GATTS_ReadAttributeValue(&dbAttrValInfo); - } - else - { - gattErr = CY_BLE_GATT_ERR_INVALID_HANDLE; - } - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - currentDescriptionValue = - ((uint16_t)(((uint16_t)locAttrValue[CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT_LEN - 1u]) << 8u)) | - ((uint16_t)locAttrValue[CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT_LEN - 2u]); - - if((currentDescriptionValue < maxDescriptionValue) && - (currentDescriptionValue > minDescriptionValue)) - { - maxDescriptionValue = currentDescriptionValue; - minDescriptionNumber = locCharInstance; - minDescriptionValueTmp = currentDescriptionValue; - } - } - } - - minDescriptionValue = minDescriptionValueTmp; - - if(locCharIndex == CY_BLE_AIOS_DIGITAL) - { - /* Read descriptor CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[CY_BLE_AIOS_DIGITAL]. - charInfoPtr[minDescriptionNumber]. - descrHandle[CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR], - .handleValuePair.value.len = CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR_LEN, - .handleValuePair.value.val = &numOfDigital, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - gattErr = Cy_BLE_GATTS_ReadAttributeValue(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - dbAttrValInfo.handleValuePair.attrHandle = - cy_ble_aiosConfigPtr->aioss->charInfoAddr[CY_BLE_AIOS_DIGITAL]. - charInfoPtr[minDescriptionNumber].descrHandle[CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR]; - dbAttrValInfo.handleValuePair.value.len = (((uint16_t)(numOfDigital) / 4u) + 1u); - dbAttrValInfo.handleValuePair.value.val = &aggregateChar[aggregateCharIndex + 1u]; - - gattErr = Cy_BLE_GATTS_ReadAttributeValue(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - for(i = 0u; i < ((numOfDigital / 4u) + 1u); i++) - { - aggregateChar[aggregateCharIndex + i] |= - (uint8_t)(aggregateChar[aggregateCharIndex + i + 1u] << aggregateDigitalBits); - aggregateChar[aggregateCharIndex + i + 1u] >>= (8u - aggregateDigitalBits); - } - - aggregateCharIndex += (((aggregateDigitalBits / 2u) + numOfDigital) / 4u); - aggregateDigitalBits = (((aggregateDigitalBits / 2u) + numOfDigital) % 4u) * 2u; - } - } - } - else if(locCharIndex == CY_BLE_AIOS_ANALOG) - { - /* Read characteristic CY_BLE_AIOS_ANALOG value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[locCharIndex]. - charInfoPtr[minDescriptionNumber].charHandle, - .handleValuePair.value.len = CY_BLE_AIOS_ANALOG_LEN, - .handleValuePair.value.val = &aggregateChar[aggregateCharIndex], - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - gattErr = Cy_BLE_GATTS_ReadAttributeValue(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - aggregateCharIndex += 2u; - } - } - else - { - /* Do nothing */ - } - } - aggregateCharIndex++; - } - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_aiosConfigPtr->aioss->charInfoAddr[CY_BLE_AIOS_AGGREGATE]. - charInfoPtr[0u].charHandle, - .handleValuePair.value.len = aggregateCharIndex - 1u, - .handleValuePair.value.val = aggregateChar, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Store data in database */ - gattErr = Cy_BLE_GATTS_WriteAttributeValue(&dbAttrValInfo); - } - } - - return gattErr; -} - -#endif /* CY_BLE_AIOS_SERVER */ - -#ifdef CY_BLE_AIOS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_DiscoverCharacteristicsEventHandler(const cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* AIOS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_AioscCharUuid[CY_BLE_AIOS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_DIGITAL, - CY_BLE_UUID_CHAR_ANALOG, - CY_BLE_UUID_CHAR_AGGREGATE - }; - - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - uint32_t j; - uint32_t exitLoop = 0u; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_AIOS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - /* Search through all available characteristics */ - for(i = 0u; ((i < (uint32_t)CY_BLE_AIOS_CHAR_COUNT) && (exitLoop == 0u)); i++) - { - for(j = 0u; j < cy_ble_aiosConfigPtr->aioscCharInstances[i]; j++) - { - if(cy_ble_AioscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[i].charInfoPtr != NULL) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[i].charInfoPtr[j].valueHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[i].charInfoPtr[j].valueHandle = - discCharInfo->valueHandle; - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[i].charInfoPtr[j].properties = - discCharInfo->properties; - lastEndHandle[discIdx] = - &cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[i].charInfoPtr[j].endHandle; - exitLoop = 1u; - break; - } - } - } - } - } - - /* Initialize characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - uint32_t charInst = cy_ble_aioscActiveCharInstance[discIdx]; - uint32_t descIdx; - - - if((cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_AIOS) && - (cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr != NULL)) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_AIOS_CCCD; - break; - - case CY_BLE_UUID_CHAR_FORMAT: - descIdx = (uint32_t)CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT; - break; - - case CY_BLE_UUID_CHAR_USER_DESCRIPTION: - descIdx = (uint32_t)CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR; - break; - - case CY_BLE_UUID_CHAR_EXTENDED_PROPERTIES: - descIdx = (uint32_t)CY_BLE_AIOS_CHAR_EXTENDED_PROPERTIES; - break; - - case CY_BLE_UUID_CHAR_VALUE_TRIGGER_SETTING: - descIdx = (uint32_t)CY_BLE_AIOS_VALUE_TRIGGER_SETTINGS; - break; - - case CY_BLE_UUID_CHAR_TIME_TRIGGER_SETTING: - descIdx = (uint32_t)CY_BLE_AIOS_TIME_TRIGGER_SETTINGS; - break; - - case CY_BLE_UUID_CHAR_VALID_RANGE: - descIdx = (uint32_t)CY_BLE_AIOS_VRD; - break; - - case CY_BLE_UUID_CHAR_NUMBER_OF_DIGITALS: - descIdx = (uint32_t)CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else /* Duplication of descriptor */ - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_AIOS) - { - if(charRangeInfo->srviIncIdx == CY_BLE_DISCOVERY_INIT) - { - /* CY_BLE_DISCOVERY_INIT */ - cy_ble_aioscActiveCharInstance[discIdx] = 0u; - } - else - { - /* CY_BLE_DISCOVERY_CONTINUE */ - cy_ble_aioscActiveCharInstance[discIdx]++; - if(cy_ble_aioscActiveCharInstance[discIdx] == - cy_ble_aiosConfigPtr->aioscCharInstances[cy_ble_discovery[discIdx].charCount]) - { - cy_ble_discovery[discIdx].charCount++; - cy_ble_aioscActiveCharInstance[discIdx] = 0u; - } - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_AIOS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - - while((cy_ble_aioscActiveCharInstance[discIdx] < cy_ble_aiosConfigPtr->aioscCharInstances[charIdx]) && - (exitFlag == 0u)) - { - uint32_t charInst = cy_ble_aioscActiveCharInstance[discIdx]; - if((cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].valueHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) && - ((cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].endHandle - - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].valueHandle) != 0u)) - { - charRangeInfo->range.startHandle = - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].valueHandle + 1u; - charRangeInfo->range.endHandle = - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_aioscActiveCharInstance[discIdx]++; - } - } - if(exitFlag == 0u) - { - cy_ble_discovery[discIdx].charCount++; - cy_ble_aioscActiveCharInstance[discIdx] = 0u; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_NotificationEventHandler -***************************************************************************//** -* -* Handles a notification event for the Automation IO Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - cy_en_ble_aios_char_index_t locCharIndex; - uint32_t exitLoop = 0u; - uint32_t j; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_AIOS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_AIOS_DIGITAL; (locCharIndex < CY_BLE_AIOS_CHAR_COUNT) && - (exitLoop == 0u); locCharIndex++) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; j < cy_ble_aiosConfigPtr->aioscCharInstances[locCharIndex]; j++) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_aios_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value, - }; - - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - exitLoop = 1u; - break; - } - } - } - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an indication event for Automation IO Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t j; - cy_en_ble_aios_char_index_t locCharIndex; - - - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_AIOS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_AIOS_DIGITAL; locCharIndex < CY_BLE_AIOS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; j < cy_ble_aiosConfigPtr->aioscCharInstances[locCharIndex]; j++) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_aios_char_value_t indicationValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event for the Automation IO Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t j; - uint32_t locReqHandle = 0u; - cy_en_ble_aios_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_AIOS_ApplCallback != NULL) && - (cy_ble_aioscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_AIOS_DIGITAL; (locCharIndex < CY_BLE_AIOS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_aiosConfigPtr->aioscCharInstances[locCharIndex]) && (locReqHandle == 0u)); j++) - { - if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle) - { - cy_stc_ble_aios_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .charInstance = j, - .value = &eventParam->value - }; - - cy_ble_aioscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_aios_descr_index_t locDescIndex; - - for(locDescIndex = CY_BLE_AIOS_CCCD; (locDescIndex < CY_BLE_AIOS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_aioscReqHandle[discIdx] == cy_ble_aiosConfigPtr->aiosc[discIdx]. - charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[locDescIndex]) - { - cy_stc_ble_aios_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .charInstance = j, - .value = &eventParam->value - }; - - cy_ble_aioscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event for the Automation IO Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint8_t j; - uint32_t locReqHandle = 0u; - cy_en_ble_aios_char_index_t locCharIndex; - - - /* Check if service handler was registered and request handle is - * valid. - */ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_AIOS_ApplCallback != NULL) && - (cy_ble_aioscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_AIOS_DIGITAL; (locCharIndex < CY_BLE_AIOS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - /* If this condition is false, this means that the current characteristic - * is not included in the GUI, in other words support for the characteristic is - * not enabled. - */ - if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_aiosConfigPtr->aioscCharInstances[locCharIndex]) && (locReqHandle == 0u)); j++) - { - cy_stc_ble_aios_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .charInstance = j, - .value = NULL - }; - /* Check if requested descriptor handle is in - * characteristic range. - */ - - if((cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle < - cy_ble_aioscReqHandle[discIdx]) && - (cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].endHandle >= - cy_ble_aioscReqHandle[discIdx])) - { - if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_CCCD]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_CCCD; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_CHAR_EXTENDED_PROPERTIES]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_CHAR_EXTENDED_PROPERTIES; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_VALUE_TRIGGER_SETTINGS]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_VALUE_TRIGGER_SETTINGS; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_TIME_TRIGGER_SETTINGS]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_TIME_TRIGGER_SETTINGS; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_VRD]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_VRD; - } - else if(cy_ble_aioscReqHandle[discIdx] == - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR]) - { - locDescrValue.descrIndex = CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR; - } - else - { - /* Should never enter here */ - } - - - cy_ble_aioscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_AIOS_ApplCallback((uint32_t)CY_BLE_EVT_AIOSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event for the Automation IO Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_AIOSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if(cy_ble_aioscReqHandle[discIdx] == eventParam->errInfo.attrHandle) - { - cy_ble_aioscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_AIOSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the AIOS service-specific callback is registered -* (with Cy_BLE_AIOS_RegisterAttrCallback): -* * CY_BLE_EVT_AIOSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_aios_char_value_t. -* . -* Otherwise (if the AIOS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_AIOS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charInstance >= cy_ble_aiosConfigPtr->aioscCharInstances[charIndex]) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - - /* Save handle to support service specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_aioscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the AIOS service-specific callback is registered -* (with Cy_BLE_AIOS_RegisterAttrCallback): -* * CY_BLE_EVT_AIOSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_aios_char_value_t. -* . -* Otherwise (if the AIOS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_AIOS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charInstance >= cy_ble_aiosConfigPtr->aioscCharInstances[charIndex]) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].valueHandle, - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_aioscReqHandle[discIdx] = - cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_AIOSS_DESCR_WRITE events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_AIOSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_AIOSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_AIOSS_INDICATION_ENABLED -* * CY_BLE_EVT_AIOSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional Characteristic Descriptor -* is absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the AIOS service-specific callback is registered -* (with Cy_BLE_AIOS_RegisterAttrCallback): -* * CY_BLE_EVT_AIOSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_aios_descr_value_t. -* . -* Otherwise (if the AIOS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_aios_descr_index_t - descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx >= CY_BLE_CONFIG_GATTC_COUNT) || - (charIndex >= CY_BLE_AIOS_CHAR_COUNT) || - (charInstance >= cy_ble_aiosConfigPtr->aioscCharInstances[charIndex]) || - (descrIndex >= CY_BLE_AIOS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((descrIndex == CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT) || - (descrIndex == CY_BLE_AIOS_CHAR_EXTENDED_PROPERTIES) || - (descrIndex == CY_BLE_AIOS_VRD) || - (descrIndex == CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR)) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_aioscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional Characteristic Descriptor -* is absent. -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the AIOS service-specific callback is registered -* (with Cy_BLE_AIOS_RegisterAttrCallback): -* * CY_BLE_EVT_AIOSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_aios_descr_value_t. -* . -* Otherwise (if the AIOS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx >= CY_BLE_CONFIG_GATTC_COUNT) || - (charIndex >= CY_BLE_AIOS_CHAR_COUNT) || - (charInstance >= cy_ble_aiosConfigPtr->aioscCharInstances[charIndex]) || - (descrIndex >= CY_BLE_AIOS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[descrIndex], - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - - /* Save handle to support service specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_aioscReqHandle[discIdx] = cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex]; - } - } - - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_AIOSC_SetCharacteristicValueWithoutResponse -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server without response. -* -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AIOSC_SetCharacteristicValueWithoutResponse(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = connHandle }; - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_AIOS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charInstance >= cy_ble_aiosConfigPtr->aioscCharInstances[charIndex]) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if((mtuParam.mtu - CY_BLE_GATT_WRITE_HEADER_LEN) < attrSize) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_write_cmd_req_t writeCmdReqParam = - { - .handleValPair.attrHandle = cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&writeCmdReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_aioscReqHandle[discIdx] = cy_ble_aiosConfigPtr->aiosc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].valueHandle; - } - } - - - return(apiResult); -} - -#endif /* CY_BLE_AIOS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_AIOS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Automation Input Output Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_AIOS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_AIOS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_AIOSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_AIOSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_AIOSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_AIOS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_AIOS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_AIOSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - (void)Cy_BLE_AIOSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_AIOSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_AIOS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_AIOS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_AIOSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_AIOSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_AIOSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_AIOSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_AIOSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_AIOS_CLIENT */ - - default: - break; - } - } - - - return(gattErr); -} - -#endif /* CY_BLE_AIOS */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_aios.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_aios.h deleted file mode 100644 index 1e3504a45e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_aios.h +++ /dev/null @@ -1,319 +0,0 @@ -/***************************************************************************//** -* \file CY_BLE_aios.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Automation Input -* Output Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_AIOS_H -#define CY_BLE_AIOS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_AIOS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -#define CY_BLE_AIO_TOTAL_CHAR_COUNT (CY_BLE_CONFIG_AIO_TOTAL_CHAR_COUNT) - -/** - * \addtogroup group_ble_service_api_AIOS_definitions - * @{ - */ - -/*************************************** -* Data Struct Definition -***************************************/ - -/** AIOS Characteristic indexes */ -typedef enum -{ - CY_BLE_AIOS_DIGITAL, /**< AIOS Digital characteristic*/ - CY_BLE_AIOS_ANALOG, /**< AIOS Analog characteristic*/ - CY_BLE_AIOS_AGGREGATE, /**< AIOS Agrigate characteristic*/ - CY_BLE_AIOS_CHAR_COUNT /**< Total count of AIOS characteristics */ -}cy_en_ble_aios_char_index_t; - -/** AIOS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_AIOS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT, /**< Characteristic Presentation Format Descriptor index */ - CY_BLE_AIOS_CHAR_USER_DESCRIPTION_DESCR, /**< Characteristic User Description Descriptor index */ - CY_BLE_AIOS_CHAR_EXTENDED_PROPERTIES, /**< Characteristic Extended Properties Descriptor index */ - CY_BLE_AIOS_VALUE_TRIGGER_SETTINGS, /**< AIO Value Trigger Settings Descriptor index */ - CY_BLE_AIOS_TIME_TRIGGER_SETTINGS, /**< AIO Time Trigger Settings Descriptor index */ - CY_BLE_AIOS_VRD, /**< Valid Range Descriptor index */ - CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR = 0x06, /**< Number of Digitals Descriptor index */ - CY_BLE_AIOS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_aios_descr_index_t; - -/** AIOS Characteristic with descriptors */ -typedef struct -{ - /** Handles of Characteristic value */ - cy_ble_gatt_db_attr_handle_t charHandle; - - /** Array of Descriptor handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_AIOS_DESCR_COUNT]; -} cy_stc_ble_aioss_char_t; - -/** Structure to hold pointer to cy_stc_ble_aioss_char_t */ -typedef struct -{ - /** Pointer to cy_stc_ble_aioss_char_t that holds information about specific - * AIO Characteristic - */ - cy_stc_ble_aioss_char_t *charInfoPtr; -} cy_stc_ble_aioss_char_info_ptr_t; - -/** Structure with Automation Input Output Service attribute handles */ -typedef struct -{ - /** Automation Input Output Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Automation Input Output Service Array with pointers to - * Characteristic handles. - */ - cy_stc_ble_aioss_char_info_ptr_t charInfoAddr[CY_BLE_AIOS_CHAR_COUNT]; -} cy_stc_ble_aioss_t; - -/** AIOS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_AIOS_DESCR_COUNT]; /**< Array of Descriptor handles */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_aiosc_char_t; - -/** Structure to hold pointer to cy_stc_ble_aiosc_char_t */ -typedef struct -{ - /** Pointer to cy_stc_ble_aiosc_char_t that holds information about specific AIO Characteristic. */ - cy_stc_ble_aiosc_char_t *charInfoPtr; -} cy_stc_ble_aiosc_char_info_ptr_t; - -/** Structure with discovered attributes information of Automation Input Output Service. */ -typedef struct -{ - /** Automation Input Output Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Automation Input Output Service Array with pointers to characteristic information. */ - cy_stc_ble_aiosc_char_info_ptr_t charInfoAddr[CY_BLE_AIOS_CHAR_COUNT]; -} cy_stc_ble_aiosc_t; - -/** AIOS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_aios_char_index_t charIndex; /**< Index of service characteristic */ - uint8_t charInstance; /**< Instance of specific service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ -} cy_stc_ble_aios_char_value_t; - -/** AIOS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_aios_char_index_t charIndex; /**< Index of service characteristic */ - uint8_t charInstance; /**< Instance of specific service characteristic */ - cy_en_ble_aios_descr_index_t descrIndex; /**< Index of descriptor */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< Error code received from application (optional) */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_aios_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Automation Input Output Service GATT DB handles structure for server */ - const cy_stc_ble_aioss_t *aioss; - - /** Number of AIOS characteristics instances for server */ - uint8_t *aiossCharInstances; - - /** Automation Input Output Service GATT DB handles structure for client */ - cy_stc_ble_aiosc_t *aiosc; - - /** Number of AIOS characteristics instances for client */ - const uint8_t *aioscCharInstances; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_aios_config_t; - - -/*************************************** -* API Constants -***************************************/ - -/** Trigger condition value not supported.*/ -#define CY_BLE_GATT_ERR_TRIGGER_CODITION_VALUE_NOT_SUPPORTED (0x80u) - -/** @} */ - -#ifdef CY_BLE_AIOS_SERVER - -#define CY_BLE_AIOS_UNDEFINED_ITEM (0x00u) -#define CY_BLE_AIOS_CHARACTERISTIC_ITEM (0x01u) -#define CY_BLE_AIOS_DESCRIPTOR_ITEM (0x02u) - -#define CY_BLE_AIOS_CHAR_PRESENTATION_FORMAT_LEN (0x07u) -#define CY_BLE_AIOS_NUM_OF_DIGITAL_DESCR_LEN (0x01u) -#define CY_BLE_AIOS_ANALOG_LEN (0x02u) - -#define CY_BLE_AIOS_VALUE_TRIGGER_DESCR_MAX_VALUE (0x07u) -#define CY_BLE_AIOS_TIME_TRIGGER_DESCR_MAX_VALUE (0x03u) - -#define CY_BLE_AIOS_MAX_CHAR_DESCRIPTION_VALUE (0xFFFFu) - -#endif /* CY_BLE_AIOS_SERVER */ - - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_AIOS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_AIOS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_AIOS_SERVER -/** - * \addtogroup group_ble_service_api_AIOS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_AIOSS_SetCharacteristicValue(cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSS_GetCharacteristicValue(cy_en_ble_aios_char_index_t charIndex, - uint8_t charInstance, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, uint8_t - attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, - uint8_t attrSize, uint8_t *attrValue); - -#endif /* CY_BLE_AIOS_SERVER */ - -/** @} */ - -#ifdef CY_BLE_AIOS_CLIENT -/** - * \addtogroup group_ble_service_api_AIOS_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_AIOSC_SetCharacteristicValueWithoutResponse(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t - charInstance, uint8_t attrSize, - uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance); - -cy_en_ble_api_result_t Cy_BLE_AIOSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_AIOSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_aios_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_aios_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_AIOS_CLIENT */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE */ -cy_en_ble_api_result_t Cy_BLE_AIOS_Init(cy_stc_ble_aios_config_t *config); - -/** \endcond */ - - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_AIOS_CLIENT -extern uint8_t cy_ble_aioscActiveCharIndex[CY_BLE_CONFIG_GATTC_COUNT]; -extern uint8_t cy_ble_aioscActiveCharInstance[CY_BLE_CONFIG_GATTC_COUNT]; -extern uint8_t cy_ble_aioscPrevCharInstIndex[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_AIOS_CLIENT) */ - -extern cy_stc_ble_aios_config_t cy_ble_aiosConfig; -extern cy_stc_ble_aios_config_t *cy_ble_aiosConfigPtr; - -/*************************************** -* Macro Functions -***************************************/ - -#define Cy_BLE_AIOS_Get16ByPtr Cy_BLE_Get16ByPtr - -#ifdef CY_BLE_AIOS_CLIENT - -#define Cy_BLE_AIOSC_GetCharacteristicValueHandle(connHandle, charIndex, charInstance) \ - ((((charIndex) >= CY_BLE_AIOS_CHAR_COUNT) || ((charInstance) >= cy_ble_aiosConfigPtr->aiossCharInstances[charIndex])) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_aiosConfigPtr->aiosc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfoPtr[charInstance].valueHandle) - -#define Cy_BLE_AIOSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, charInstance, descrIndex) \ - ((((charIndex) >= CY_BLE_AIOS_CHAR_COUNT) || ((charInstance) >= cy_ble_aiosConfigPtr->aiossCharInstances[charIndex]) || \ - ((descrIndex) >= CY_BLE_AIOS_DESCR_COUNT)) ? CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_aiosConfigPtr->aiosc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfoAddr[charIndex]. \ - charInfoPtr[charInstance].descrHandle[descrIndex]) - -#endif /* (CY_BLE_AIOS_CLIENT) */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_AIOS) */ -#endif /* CY_BLE_AIOS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ancs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ancs.c deleted file mode 100644 index b5cc9e44d3..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ancs.c +++ /dev/null @@ -1,1359 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ancs.c -* \version 2.0 -* -* \brief -* This file contains the source code for -* the Apple Notification Center Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_ANCS)) - -static cy_ble_callback_t Cy_BLE_ANCS_ApplCallback; - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GATT_ROLE_CLIENT) -/* Apple Notification Center Service UUID */ -const cy_stc_ble_uuid128_t cy_ble_ancscServUuid = -{ - { 0xD0u, 0x00u, 0x2Du, 0x12u, 0x1Eu, 0x4Bu, 0x0Fu, 0xA4u, 0x99u, 0x4Eu, 0xCEu, 0xB5u, 0x31u, 0xF4u, 0x05u, 0x79u } -}; - -/* Apple Notification Center Service characteristics UUIDs */ -const cy_stc_ble_uuid128_t cy_ble_ancscCharUuid[CY_BLE_ANCS_CHAR_COUNT] = -{ - /* Notification Source characteristic UUID */ - { { 0xBDu, 0x1Du, 0xA2u, 0x99u, 0xE6u, 0x25u, 0x58u, 0x8Cu, 0xD9u, 0x42u, 0x01u, 0x63u, 0x0Du, 0x12u, 0xBFu, 0x9Fu } }, - /* Control Point characteristic UUID */ - { { 0xD9u, 0xD9u, 0xAAu, 0xFDu, 0xBDu, 0x9Bu, 0x21u, 0x98u, 0xA8u, 0x49u, 0xE1u, 0x45u, 0xF3u, 0xD8u, 0xD1u, 0x69u } }, - /* Data Source characteristic UUID */ - { { 0xFBu, 0x7Bu, 0x7Cu, 0xCEu, 0x6Au, 0xB3u, 0x44u, 0xBEu, 0xB5u, 0x4Bu, 0xD6u, 0x24u, 0xE9u, 0xC6u, 0xEAu, 0x22u } } -}; -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GATT_ROLE_CLIENT */ - -#ifdef CY_BLE_ANCS_CLIENT - -/* Server's Apple Notification Center Service characteristics GATT DB handles structure */ -cy_stc_ble_ancsc_t cy_ble_ancsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_ancscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -#endif /* CY_BLE_ANCS_CLIENT */ - -/* The pointer to the global BLE ANCS config structure */ -cy_stc_ble_ancs_config_t *cy_ble_ancsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_ANCS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_ANCSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_ANCS_SERVER */ - -#ifdef CY_BLE_ANCS_CLIENT -static void Cy_BLE_ANCSC_DiscoverServiceEventHandler(const cy_stc_ble_disc_srv_info_t *discServInfo); -static void Cy_BLE_ANCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_ANCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_ANCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_ANCSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_ANCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_ANCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_ANCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_ANCS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_ANCS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCS_Init -***************************************************************************//** -* -* Initializes profile internals. -* -* \param config: The configuration structure for the Apple Notification -* Center Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCS_Init(cy_stc_ble_ancs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to the config structure */ - cy_ble_ancsConfigPtr = config; - - /* Registers Event Handler for the ANCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_ANCS_EventHandler); - - /* Registers a callback function via the config structure */ - if(cy_ble_ancsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_ANCS_ApplCallback = cy_ble_ancsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_ANCS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_ANCS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_ancsc[idx], 0, sizeof(cy_stc_ble_ancsc_t)); - - /* Initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_ANCS].uuid = 0x0000u; - } - cy_ble_ancscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_ANCS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific Write requests from a peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for ANCS is: -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, void *eventParam), -* where: -* * eventCode indicates the event that triggered this callback. -* * eventParam contains the parameters corresponding to the current event. -* -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise, this -* data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_ANCS_ApplCallback = callbackFunc; - if(cy_ble_ancsConfigPtr != NULL) - { - cy_ble_ancsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - -#ifdef CY_BLE_ANCS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the value of the characteristic identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSS_SetCharacteristicValue(cy_en_ble_ancs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_ANCS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].charHandle) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store the characteristic value into the GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the value of the characteristic, as identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic -* value data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - A characteristic is absent. -* -* \events -* None. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSS_GetCharacteristicValue(cy_en_ble_ancs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_ANCS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].charHandle) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param attrValue: The pointer to the location where characteristic -* descriptor value data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The Characteristic Descriptor value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - A characteristic is absent. -* -* \events -* None. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - cy_en_ble_ancs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if((charIndex >= CY_BLE_ANCS_CHAR_COUNT) || (descrIndex >= CY_BLE_ANCS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].descrHandle[CY_BLE_ANCS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from the database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified characteristic value, as identified by -* the charIndex. -* On enabling notification successfully for a service characteristic it sends out a -* Handle Value notification which results in a CY_BLE_EVT_ANCSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle that consists of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should -* be sent to the Client device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the Client -* -* \events -* None. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_ANCS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].descrHandle[CY_BLE_ANCS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_ancsConfigPtr->ancss->charInfo[charIndex]. - descrHandle[CY_BLE_ANCS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfParam = - { - /* Fill all the fields of the Write request structure ... */ - .handleValPair.attrHandle = cy_ble_ancsConfigPtr->ancss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to the Client using a previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS; -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_ANCSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(Cy_BLE_ANCS_ApplCallback != NULL) - { - cy_stc_ble_ancs_char_value_t locCharValue; - locCharValue.charIndex = CY_BLE_ANCS_CHAR_COUNT; - - if(eventParam->handleValPair.attrHandle == - cy_ble_ancsConfigPtr->ancss->charInfo[CY_BLE_ANCS_NS].descrHandle[CY_BLE_ANCS_CCCD]) - { - locCharValue.charIndex = CY_BLE_ANCS_NS; - } - else if(eventParam->handleValPair.attrHandle == - cy_ble_ancsConfigPtr->ancss->charInfo[CY_BLE_ANCS_DS].descrHandle[CY_BLE_ANCS_CCCD]) - { - locCharValue.charIndex = CY_BLE_ANCS_DS; - } - else - { - /* Leave locCharValue.charIndex = CY_BLE_ANCS_CHAR_COUNT */ - } - - if(locCharValue.charIndex != CY_BLE_ANCS_CHAR_COUNT) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - locCharValue.connHandle = eventParam->connHandle; - locCharValue.value = NULL; - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - uint32_t eventCode; - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_ANCSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_ANCSS_NOTIFICATION_DISABLED; - } - - Cy_BLE_ANCS_ApplCallback(eventCode, &locCharValue); - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set a flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - if(eventParam->handleValPair.attrHandle == cy_ble_ancsConfigPtr->ancss->charInfo[CY_BLE_ANCS_CP].charHandle) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - locCharValue.charIndex = CY_BLE_ANCS_CP; - locCharValue.value = &eventParam->handleValPair.value; - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_ancsConfigPtr->ancss->charInfo[locCharValue.charIndex]. - charHandle, locCharValue.value->len); - - Cy_BLE_ANCS_ApplCallback((uint32_t)CY_BLE_EVT_ANCSS_WRITE_CHAR, &locCharValue); - - if((locCharValue.gattErrorCode == CY_BLE_GATT_ERR_ANCS_UNKNOWN_COMMAND) || - (locCharValue.gattErrorCode == CY_BLE_GATT_ERR_ANCS_INVALID_COMMAND) || - (locCharValue.gattErrorCode == CY_BLE_GATT_ERR_ANCS_INVALID_PARAMETER) || - (locCharValue.gattErrorCode == CY_BLE_GATT_ERR_ANCS_ACTION_FAILED)) - { - gattErr = locCharValue.gattErrorCode; - } - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - } - - return(gattErr); -} - -#endif /* CY_BLE_ANCS_SERVER */ - -#ifdef CY_BLE_ANCS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (identified by -* charIndex) value attribute in the Server. As a result, a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server's side, a CY_BLE_EVT_ANCSS_WRITE_CHAR events is generated. -* On successful request execution on the Server's side, a Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If an ANCS service-specific callback is registered -* (with Cy_BLE_ANCS_RegisterAttrCallback): -* * CY_BLE_EVT_ANCSC_WRITE_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ancs_char_value_t. -* . -* Otherwise (if an ANCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ANCS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ancsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_ancsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_ancsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ancscReqHandle[discIdx] = cy_ble_ancsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the a characteristic value to the Server -* identified by its charIndex. -* -* Internally, a Write Request is sent to the GATT Server and on successful -* execution of the request on the Server's side these following events can be -* generated: -* * CY_BLE_EVT_ANCSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_ANCSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS) -* these events can appear: \n -* If an ANCS service-specific callback is registered -* (with Cy_BLE_ANCS_RegisterAttrCallback): -* * CY_BLE_EVT_ANCSC_WRITE_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ancs_descr_value_t. -* . -* Otherwise (if an ANCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - cy_en_ble_ancs_descr_index_t descrIndex, - uint8_t - attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ANCS_CHAR_COUNT) || (descrIndex >= CY_BLE_ANCS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ancsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - /* Fill all fields of the Write Request structure ... */ - .handleValPair.attrHandle = cy_ble_ancsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - - /* ... and send request to Server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save the handle to support service specific read response from the device */ - cy_ble_ancscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS) -* these next events can appear: \n -* If an ANCS service-specific callback is registered -* (with Cy_BLE_ANCS_RegisterAttrCallback): -* * CY_BLE_EVT_ANCSC_READ_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_ancs_descr_value_t. -* . -* Otherwise (if n ANCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - cy_en_ble_ancs_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ANCS_CHAR_COUNT) || (descrIndex >= CY_BLE_ANCS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ancsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_ancsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ancscReqHandle[discIdx] = cy_ble_ancsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_DiscoverServiceEventHandler -***************************************************************************//** -* -* This function is called on receiving a Read-By-Group Response event or -* Read response with 128-bit service uuid. -* -* \param discServInfo: The pointer to the service information structure. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_DiscoverServiceEventHandler(const cy_stc_ble_disc_srv_info_t *discServInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discServInfo->connHandle); - - if(memcmp(&cy_ble_ancscServUuid, &discServInfo->srvcInfo->uuid.uuid128, CY_BLE_GATT_128_BIT_UUID_SIZE) == 0u) - { - if(cy_ble_serverInfo[discIdx][CY_BLE_SRVI_ANCS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_serverInfo[discIdx][CY_BLE_SRVI_ANCS].range = discServInfo->srvcInfo->range; - cy_ble_discovery[discIdx].servCount++; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, the appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - cy_en_ble_ancs_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT) && - (discCharInfo->valueHandle >= cy_ble_serverInfo[discIdx][CY_BLE_SRVI_ANCS].range.startHandle) && - (discCharInfo->valueHandle <= cy_ble_serverInfo[discIdx][CY_BLE_SRVI_ANCS].range.endHandle)) - { - /* Update the last characteristic endHandle to the declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(locCharIndex = CY_BLE_ANCS_NS; locCharIndex < CY_BLE_ANCS_CHAR_COUNT; locCharIndex++) - { - if(memcmp(&cy_ble_ancscCharUuid[locCharIndex], &discCharInfo->uuid.uuid128, - CY_BLE_GATT_128_BIT_UUID_SIZE) == 0u) - { - if(cy_ble_ancsc[discIdx].charInfo[locCharIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ancsc[discIdx].charInfo[locCharIndex].valueHandle = discCharInfo->valueHandle; - cy_ble_ancsc[discIdx].charInfo[locCharIndex].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_ancsc[discIdx].charInfo[locCharIndex].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initialize the characteristic endHandle to the Service endHandle. The characteristic endHandle will - * be updated to the declaration handle of the following characteristic, in the following characteristic - * discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_ANCS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, the appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ANCS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_ANCS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_ancsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ancsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ANCS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_ANCS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_ancsc[discIdx].charInfo[charIdx].endHandle - - cy_ble_ancsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_ancsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_ancsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_NotificationEventHandler -***************************************************************************//** -* -* Handles a Notification event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ANCS_ApplCallback != NULL)) - { - cy_stc_ble_ancs_char_value_t locCharValue; - - if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_NS].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_ANCS_NS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_DS].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_ANCS_DS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Apple Notification Center Service doesn't support any other notification */ - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locCharValue.connHandle = eventParam->connHandle; - locCharValue.value = &eventParam->handleValPair.value; - Cy_BLE_ANCS_ApplCallback((uint32_t)CY_BLE_EVT_ANCSC_NOTIFICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event. -* -* \param eventParam: The pointer to the data structure. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ANCS_ApplCallback != NULL) && - (cy_ble_ancscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_ancs_descr_value_t locDescrValue; - - if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_NS].descrHandle[CY_BLE_ANCS_CCCD] == cy_ble_ancscReqHandle[discIdx]) - { - locDescrValue.charIndex = CY_BLE_ANCS_NS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_DS].descrHandle[CY_BLE_ANCS_CCCD] == - cy_ble_ancscReqHandle[discIdx]) - { - locDescrValue.charIndex = CY_BLE_ANCS_DS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locDescrValue.connHandle = eventParam->connHandle; - locDescrValue.value = &eventParam->value; - - Cy_BLE_ANCS_ApplCallback((uint32_t)CY_BLE_EVT_ANCSC_READ_DESCR_RESPONSE, &locDescrValue); - } - - cy_ble_ancscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ANCS_ApplCallback != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_ancscReqHandle[discIdx])) - { - if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_CP].valueHandle == cy_ble_ancscReqHandle[discIdx]) - { - cy_stc_ble_ancs_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_ANCS_CP, - .value = NULL - }; - cy_ble_ancscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_ANCS_ApplCallback((uint32_t)CY_BLE_EVT_ANCSC_WRITE_CHAR_RESPONSE, &locCharIndex); - } - else - { - cy_stc_ble_ancs_descr_value_t locDescIndex; - - if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_NS].descrHandle[CY_BLE_ANCS_CCCD] == - cy_ble_ancscReqHandle[discIdx]) - { - locDescIndex.charIndex = CY_BLE_ANCS_NS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_DS].descrHandle[CY_BLE_ANCS_CCCD] == - cy_ble_ancscReqHandle[discIdx]) - { - locDescIndex.charIndex = CY_BLE_ANCS_DS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Apple Notification Center Service doesn't support any other notification */ - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locDescIndex.connHandle = *eventParam; - locDescIndex.descrIndex = CY_BLE_ANCS_CCCD; - locDescIndex.value = NULL; - - cy_ble_ancscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_ANCS_ApplCallback((uint32_t)CY_BLE_EVT_ANCSC_WRITE_DESCR_RESPONSE, &locDescIndex); - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANCSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_ancscReqHandle[discIdx]) - { - if((Cy_BLE_ANCS_ApplCallback != NULL) && - (cy_ble_ancscReqHandle[discIdx] == cy_ble_ancsc[discIdx].charInfo[CY_BLE_ANCS_CP].valueHandle)) - { - cy_stc_ble_ancs_char_value_t locGattError = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_ANCS_CP, - .value = NULL, - .gattErrorCode = eventParam->errInfo.errorCode - }; - - Cy_BLE_ANCS_ApplCallback((uint32_t)CY_BLE_EVT_ANCSC_ERROR_RESPONSE, &locGattError); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - cy_ble_ancscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} -#endif /* CY_BLE_ANCS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_ANCS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Apple Notification Center Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_ANCS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_ANCS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_SERVICE: - Cy_BLE_ANCSC_DiscoverServiceEventHandler((cy_stc_ble_disc_srv_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_ANCSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_ANCSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_ANCSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_ANCS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_ANCS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_ANCSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_ANCS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_ANCS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_ANCSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_ANCSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_ANCSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_ANCSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_ANCS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* CY_BLE_ANCS */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ancs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ancs.h deleted file mode 100644 index f64e5a43af..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ancs.h +++ /dev/null @@ -1,206 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ancs.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Apple Notification Center (ANC) Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_ANCS_H -#define CY_BLE_ANCS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_ANCS)) - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define CY_BLE_ANCS_FLAG_PROCESS (0x01u) - -/*************************************** -* Data Types -***************************************/ - -/** - * \addtogroup group_ble_service_api_ANCS_definitions - * @{ - */ - -/** ANC Service Characteristics indexes */ -typedef enum -{ - CY_BLE_ANCS_NS, /**< Notification Source characteristic index */ - CY_BLE_ANCS_CP, /**< Control Point characteristic index */ - CY_BLE_ANCS_DS, /**< Data Source characteristic index */ - CY_BLE_ANCS_CHAR_COUNT /**< Total count of ANCS characteristics */ -}cy_en_ble_ancs_char_index_t; - -/** ANC Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_ANCS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_ANCS_DESCR_COUNT /**< Total count of ANCS descriptors */ -}cy_en_ble_ancs_descr_index_t; - -/** ANC Service Characteristic structure type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_ANCS_DESCR_COUNT]; /**< Handle of descriptor */ -}cy_stc_ble_ancss_char_t; - -/** Structure with ANC Service attribute handles */ -typedef struct -{ - /** ANC Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** ANC Service characteristics info array */ - cy_stc_ble_ancss_char_t charInfo[CY_BLE_ANCS_CHAR_COUNT]; -} cy_stc_ble_ancss_t; - -/** ANCS client characteristic structure type */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** ANCS client char. descriptor handle */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_ANCS_DESCR_COUNT]; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_ancsc_char_t; - -/** Structure with discovered attributes information of ANC Service */ -typedef struct -{ - cy_stc_ble_ancsc_char_t charInfo[CY_BLE_ANCS_CHAR_COUNT]; /**< Characteristics handle + properties array */ -}cy_stc_ble_ancsc_t; - -/** ANCS Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ancs_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ -} cy_stc_ble_ancs_char_value_t; - -/** ANCS Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ancs_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_ancs_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_ancs_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Service GATT DB handles structure */ - const cy_stc_ble_ancss_t *ancss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_ancs_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_ANCS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_ANCS_Init(cy_stc_ble_ancs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_ANCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_ANCS_SERVER -/** - * \addtogroup group_ble_service_api_ANCS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_ANCSS_SetCharacteristicValue(cy_en_ble_ancs_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANCSS_GetCharacteristicValue(cy_en_ble_ancs_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - cy_en_ble_ancs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANCSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_ANCS_SERVER */ - -#ifdef CY_BLE_ANCS_CLIENT -/** - * \addtogroup group_ble_service_api_ANCS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_ANCSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - cy_en_ble_ancs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ancs_char_index_t charIndex, - cy_en_ble_ancs_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_ANCS_CLIENT */ - -/*************************************** -* External data references -***************************************/ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GATT_ROLE_CLIENT) -extern const cy_stc_ble_uuid128_t cy_ble_ancscServUuid; -extern const cy_stc_ble_uuid128_t cy_ble_ancscCharUuid[CY_BLE_ANCS_CHAR_COUNT]; -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GATT_ROLE_CLIENT */ - -#ifdef CY_BLE_ANCS_CLIENT -/* ANC Service Server's GATT DB handles structure */ -extern cy_stc_ble_ancsc_t cy_ble_ancsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_ANCS_CLIENT */ - -extern cy_stc_ble_ancs_config_t cy_ble_ancsConfig; -extern cy_stc_ble_ancs_config_t *cy_ble_ancsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_ANCS) */ -#endif /* CY_BLE_ANCS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ans.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ans.c deleted file mode 100644 index 1030aad02b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ans.c +++ /dev/null @@ -1,1413 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ans.c -* \version 2.0 -* -* \brief -* Contains the source code for the Alert Notification Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_ANS)) - -static cy_ble_callback_t Cy_BLE_ANS_ApplCallback = NULL; - -#ifdef CY_BLE_ANS_CLIENT -/* ANS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_ansc_t cy_ble_ansc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_anscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_ANS_CLIENT) */ - -/* The pointer to the global BLE ANS config structure */ -cy_stc_ble_ans_config_t *cy_ble_ansConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_ANS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_ANSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_ANS_SERVER */ - -#ifdef CY_BLE_ANS_CLIENT -static void Cy_BLE_ANSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_ANSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_ANSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_ANSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_ANSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_ANSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_ANSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_ANS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_ANS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_ANS_Init -***************************************************************************//** -* -* This function initializes the Alert Notification Service. -* -* \param config: The configuration structure for the Alert Notification Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANS_Init(cy_stc_ble_ans_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to the config structure */ - cy_ble_ansConfigPtr = config; - - /* Registers Event Handler for the ANS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_ANS_EventHandler); - - /* Registers a callback function via the config structure */ - if(cy_ble_ansConfigPtr->callbackFunc != NULL) - { - Cy_BLE_ANS_ApplCallback = cy_ble_ansConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_ANS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_ANS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_ansc[idx], 0, sizeof(cy_stc_ble_ansc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_ANS].uuid = CY_BLE_UUID_ALERT_NOTIFICATION_SERVICE; - } - cy_ble_anscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_ANS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for Alert Notification Service specific -* attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* service-specific events from the BLE Component. The -* definition of cy_ble_callback_t for Alert Notification -* Service is,\n -* typedef void (* cy_ble_callback_t) -* (uint32_t eventCode, void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_ANSS_NOTIFICATION_ENABLED) -* * eventParam contains the parameters corresponding to -* the current event (e.g. Pointer to cy_stc_ble_ans_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise -* this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_ANS_ApplCallback = callbackFunc; - if(cy_ble_ansConfigPtr != NULL) - { - cy_ble_ansConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_ANS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_ANSS_WriteEventHandler -***************************************************************************//** -* -* Handles Write Request Event for Alert Notification Service. -* -* \param eventParam: The pointer to the data that came with a write request for -* Alert Notification Service. -* -* \return -* Return a value of type cy_en_ble_gatt_err_code_t: -* * CY_BLE_GATT_ERR_NONE - The function terminated successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - The handle of Client Configuration -* Characteristic Descriptor or Characteristic of Alert Notification Service -* is not valid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The notification property of a -* specific characteristic of Alert Notification Service is disabled. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_ANSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_ans_char_value_t wrReqParam; - cy_ble_gatt_db_attr_handle_t tmpHandle; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t fFlag = 0u; - uint32_t event = (uint32_t)CY_BLE_EVT_ANSS_WRITE_CHAR; - - tmpHandle = eventParam->handleValPair.attrHandle; - - /* Client Characteristic Configuration Descriptor Write Request */ - if((tmpHandle == cy_ble_ansConfigPtr->anss->charInfo[CY_BLE_ANS_NEW_ALERT].descrHandle[CY_BLE_ANS_CCCD]) || - (tmpHandle == cy_ble_ansConfigPtr->anss->charInfo[CY_BLE_ANS_UNREAD_ALERT_STATUS].descrHandle[CY_BLE_ANS_CCCD])) - { - /* Verify that optional notification property is enabled for Characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_ansConfigPtr->anss->charInfo[CY_BLE_ANS_NEW_ALERT].charHandle) || - CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_ansConfigPtr->anss->charInfo[CY_BLE_ANS_UNREAD_ALERT_STATUS].charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_ANSS_NOTIFICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_ANSS_NOTIFICATION_DISABLED; - } - - if(tmpHandle == cy_ble_ansConfigPtr->anss->charInfo[CY_BLE_ANS_NEW_ALERT].descrHandle[CY_BLE_ANS_CCCD]) - { - wrReqParam.charIndex = CY_BLE_ANS_NEW_ALERT; - } - else - { - wrReqParam.charIndex = CY_BLE_ANS_UNREAD_ALERT_STATUS; - } - - /* Value is NULL for descriptors */ - wrReqParam.value = NULL; - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set fFlag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else if(tmpHandle == cy_ble_ansConfigPtr->anss->charInfo[CY_BLE_ANS_ALERT_NTF_CONTROL_POINT].charHandle) - { - /* Validate Command ID and Category ID ranges */ - if((eventParam->handleValPair.value.val[0u] <= CY_BLE_ANS_IMM_UNREAD_ALERT_STATUS_NTF) && - ((eventParam->handleValPair.value.val[1u] <= CY_BLE_ANS_CAT_ID_INSTANT_MESSAGE) || - (eventParam->handleValPair.value.val[1u] == CY_BLE_ANS_CAT_ID_ALL))) - { - wrReqParam.charIndex = CY_BLE_ANS_ALERT_NTF_CONTROL_POINT; - wrReqParam.value = &eventParam->handleValPair.value; - } - else /* Command ID or Category ID received is invalid */ - { - /* Erroneous request won't be notified to user but Error response will be sent. */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - gattErr = CY_BLE_GATT_ERR_ANS_COMMAND_NOT_SUPPORTED; - } - } - else - { - /* Requested handle does not belong to Alert Notification Service - * Characteristic or Descriptor. */ - fFlag = 1u; - } - - if((gattErr == CY_BLE_GATT_ERR_NONE) && (fFlag == 0u)) - { - /* Write value to GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - wrReqParam.connHandle = eventParam->connHandle; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - if(Cy_BLE_ANS_ApplCallback != NULL) - { - Cy_BLE_ANS_ApplCallback(event, &wrReqParam); - } - } - } - - if(CY_BLE_GATT_ERR_NONE != gattErr) - { - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of Alert Notification Service, which is a value -* identified by charIndex, to the local database. -* -* \param charIndex: The index of the service characteristic of type -* cy_en_ble_ans_char_index_t. The valid values are, -* * CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT -* * CY_BLE_ANS_SUPPORTED_UNREAD_ALERT_CAT -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to characteristic value data that should be stored -* in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSS_SetCharacteristicValue(cy_en_ble_ans_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex < CY_BLE_ANS_CHAR_COUNT) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ansConfigPtr->anss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Store data in database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of Alert Notification Service. The value is -* identified by charIndex. -* -* \param charIndex: The index of the service characteristic of type cy_en_ble_ans_char_index_t. -* The valid values are, -* * CY_BLE_ANS_NEW_ALERT -* * CY_BLE_ANS_UNREAD_ALERT_STATUS -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSS_GetCharacteristicValue(cy_en_ble_ans_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex < CY_BLE_ANS_CHAR_COUNT) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ansConfigPtr->anss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the specified characteristic of Alert -* Notification Service. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the service characteristic of type cy_en_ble_ans_char_index_t. -* The valid values are, -* * CY_BLE_ANS_NEW_ALERT -* * CY_BLE_ANS_UNREAD_ALERT_STATUS -* \param descrIndex: The index of the service characteristic descriptor of type -* cy_en_ble_ans_descr_index_t. The valid value is, -* * CY_BLE_ANS_CCCD -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - cy_en_ble_ans_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(((charIndex == CY_BLE_ANS_NEW_ALERT) || (charIndex == CY_BLE_ANS_UNREAD_ALERT_STATUS)) && - (descrIndex == CY_BLE_ANS_CCCD)) - { - if(cy_ble_ansConfigPtr->anss->charInfo[charIndex].descrHandle[descrIndex] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ansConfigPtr->anss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSS_SendNotification -***************************************************************************//** -* -* Sends a notification with the characteristic value, as specified by its charIndex, -* to the Client device. -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_ANSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic of type cy_en_ble_ans_char_index_t. -* The valid values are, -* * CY_BLE_ANS_UNREAD_ALERT_STATUS -* * CY_BLE_ANS_NEW_ALERT -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be sent -* to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The function completed successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameter is failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_ANS_NEW_ALERT) || (charIndex == CY_BLE_ANS_UNREAD_ALERT_STATUS)) - { - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_ansConfigPtr->anss->charInfo[charIndex]. - descrHandle[CY_BLE_ANS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_ansConfigPtr->anss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - - return(apiResult); -} - -#endif /* CY_BLE_ANS_SERVER */ - - -#ifdef CY_BLE_ANS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_ANSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* ANS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_anscCharUuid[CY_BLE_ANS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_SPRTD_NEW_ALRT_CTGRY, - CY_BLE_UUID_CHAR_NEW_ALERT, - CY_BLE_UUID_CHAR_SPRT_UNRD_ALRT_CTGRY, - CY_BLE_UUID_CHAR_UNREAD_ALRT_STATUS, - CY_BLE_UUID_CHAR_ALERT_NTF_CONTROL_POINT - }; - - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ANS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = (uint32_t)CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT; i < (uint32_t)CY_BLE_ANS_CHAR_COUNT; i++) - { - if(cy_ble_anscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_ansc[discIdx].characteristics[i].charInfo.valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ansc[discIdx].characteristics[i].charInfo.valueHandle = discCharInfo->valueHandle; - cy_ble_ansc[discIdx].characteristics[i].charInfo.properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_ansc[discIdx].characteristics[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initialize the characteristic endHandle to the Service endHandle. The characteristic endHandle will - * be updated to the declaration handle of the following characteristic, in the following characteristic - * discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANS_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* This event is generated when a server successfully sends the data for -* CY_BLE_EVT_GATTC_FIND_INFO_REQ. Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param cy_stc_ble_disc_descr_info_t * discCharInfo: The pointer to a characteristic -* information structure. -* -******************************************************************************/ -static void Cy_BLE_ANSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ANS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_ANS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_ansc[discIdx].characteristics[cy_ble_discovery[discIdx].charCount].descriptors[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ansc[discIdx].characteristics[cy_ble_discovery[discIdx].charCount].descriptors[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ANSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ANS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_ANS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_ansc[discIdx].characteristics[charIdx].endHandle - - cy_ble_ansc[discIdx].characteristics[charIdx].charInfo.valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_ansc[discIdx].characteristics[charIdx].charInfo.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_ansc[discIdx].characteristics[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_NotificationEventHandler -***************************************************************************//** -* -* Handles Notification Event for Alert Notification Service. -* -* \param cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam: The pointer to a -* cy_stc_ble_gattc_handle_value_ntf_param_t -* data structure specified by -* the event. -* -******************************************************************************/ -static void Cy_BLE_ANSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ANS_ApplCallback != NULL)) - { - if((cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_NEW_ALERT].charInfo.valueHandle == - eventParam->handleValPair.attrHandle) || - (cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_UNREAD_ALERT_STATUS].charInfo.valueHandle == - eventParam->handleValPair.attrHandle)) - { - cy_stc_ble_ans_char_value_t ntfParam = - { - .charIndex = CY_BLE_ANS_NEW_ALERT, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_ANS_ApplCallback((uint32_t)CY_BLE_EVT_ANSC_NOTIFICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles Read Response Event for Alert Notification Service. -* -* \param cy_stc_ble_gattc_read_rsp_param_t *eventParam: The pointer to the data that came -* with a read response for ANS. -* -******************************************************************************/ -static void Cy_BLE_ANSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrVal = 0u; - cy_en_ble_ans_char_index_t idx; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ANS_ApplCallback != NULL) && - (cy_ble_anscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT].charInfo.valueHandle == - cy_ble_anscReqHandle[discIdx]) - { - idx = CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT; - } - else if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_SUPPORTED_UNREAD_ALERT_CAT].charInfo.valueHandle == - cy_ble_anscReqHandle[discIdx]) - { - idx = CY_BLE_ANS_SUPPORTED_UNREAD_ALERT_CAT; - } - else if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_NEW_ALERT].descriptors[CY_BLE_ANS_CCCD] == - cy_ble_anscReqHandle[discIdx]) - { - /* Attribute is characteristic descriptor */ - attrVal = 1u; - idx = CY_BLE_ANS_NEW_ALERT; - } - else if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_UNREAD_ALERT_STATUS].descriptors[CY_BLE_ANS_CCCD] == - cy_ble_anscReqHandle[discIdx]) - { - /* Attribute is characteristic descriptor */ - attrVal = 1u; - idx = CY_BLE_ANS_UNREAD_ALERT_STATUS; - } - else - { - /* No ANS characteristic was requested for read */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* Read response for characteristic */ - if(attrVal == 0u) - { - cy_stc_ble_ans_char_value_t rdRspParam = - { - /* Fill Alert Notification Service read response parameter structure with characteristic info. */ - .connHandle = eventParam->connHandle, - .charIndex = idx, - .value = &eventParam->value - }; - rdRspParam.charIndex = idx; - Cy_BLE_ANS_ApplCallback((uint32_t)CY_BLE_EVT_ANSC_READ_CHAR_RESPONSE, (void*)&rdRspParam); - } - else /* Read response for characteristic descriptor */ - { - cy_stc_ble_ans_descr_value_t rdRspParam = - { - /* Fill Alert Notification Service read response parameter structure with characteristic descriptor - * info. */ - .connHandle = eventParam->connHandle, - .charIndex = idx, - .descrIndex = CY_BLE_ANS_CCCD, - .value = &eventParam->value - }; - rdRspParam.charIndex = idx; - Cy_BLE_ANS_ApplCallback((uint32_t)CY_BLE_EVT_ANSC_READ_DESCR_RESPONSE, (void*)&rdRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_anscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles Write Response Event for Alert Notification Service. -* -* \param cy_stc_ble_conn_handle_t *eventParam: The pointer to the cy_stc_ble_conn_handle_t data -* structure. -* -******************************************************************************/ -static void Cy_BLE_ANSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrVal = 0u; - cy_en_ble_ans_char_index_t idx; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ANS_ApplCallback != NULL) && - (cy_ble_anscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_ans_char_value_t wrRspParam = { .connHandle = *eventParam }; - - if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_ALERT_NTF_CONTROL_POINT].charInfo.valueHandle == - cy_ble_anscReqHandle[discIdx]) - { - idx = CY_BLE_ANS_ALERT_NTF_CONTROL_POINT; - } - else if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_NEW_ALERT].descriptors[CY_BLE_ANS_CCCD] == - cy_ble_anscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - idx = CY_BLE_ANS_NEW_ALERT; - } - else if(cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_UNREAD_ALERT_STATUS].descriptors[CY_BLE_ANS_CCCD] == - cy_ble_anscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - idx = CY_BLE_ANS_UNREAD_ALERT_STATUS; - } - else - { - /* No ANS characteristic was requested for write */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* Write response for characteristic */ - if(attrVal == 0u) - { - wrRspParam.charIndex = idx; - wrRspParam.value = NULL; - - Cy_BLE_ANS_ApplCallback((uint32_t)CY_BLE_EVT_ANSC_WRITE_CHAR_RESPONSE, (void*)&wrRspParam); - } - else /* Write response for characteristic descriptor */ - { - /* Fill Alert Notification Service write response parameter structure with - * characteristic descriptor info. */ - cy_stc_ble_ans_descr_value_t wrDescRspParam = - { - .connHandle = *eventParam, - .charIndex = idx, - .descrIndex = CY_BLE_ANS_CCCD, - .value = NULL - }; - - Cy_BLE_ANS_ApplCallback((uint32_t)CY_BLE_EVT_ANSC_WRITE_DESCR_RESPONSE, (void*)&wrDescRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_anscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles Error Response Event for Alert Notification Service. -* -* \param cy_stc_ble_gatt_err_param_t *eventParam: The pointer to -* the cy_stc_ble_gatt_err_param_t -* structure. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_ANSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_anscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_anscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_ANSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: Size of the Characteristic value attribute. -* \param attrValue: Pointer to the characteristic value data that should be -* sent to the server device. -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_STATE - The component in in invalid state for current -* operation. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ANS service-specific callback is registered -* (with Cy_BLE_ANS_RegisterAttrCallback): -* * CY_BLE_EVT_ANSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ans_char_value_t. -* . -* Otherwise (if the ANS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - (attrValue != NULL) && (charIndex == CY_BLE_ANS_ALERT_NTF_CONTROL_POINT) && - (cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_ALERT_NTF_CONTROL_POINT].charInfo.valueHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gattc_write_cmd_req_t writeReqParam = - { - /* Fill all fields of write command request structure ... */ - .connHandle = connHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .handleValPair.attrHandle = cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_ALERT_NTF_CONTROL_POINT]. - charInfo.valueHandle - }; - - /* Send request to write characteristic value */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_anscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - /* Validation of the input parameters failed */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_GetCharacteristicValue -***************************************************************************//** -* -* Sends a request to the peer device to get a characteristic value, as -* identified by its charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully; -* * CY_BLE_ERROR_INVALID_STATE - The component in in invalid state for current -* operation. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ANS service-specific callback is registered -* (with Cy_BLE_ANS_RegisterAttrCallback): -* * CY_BLE_EVT_ANSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ans_char_value_t. -* . -* Otherwise (if the ANS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex) -{ - cy_stc_ble_gattc_read_req_t readReqParam; - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Select characteristic */ - switch(charIndex) - { - case CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT: - readReqParam.attrHandle = cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT]. - charInfo.valueHandle; - break; - - case CY_BLE_ANS_SUPPORTED_UNREAD_ALERT_CAT: - readReqParam.attrHandle = cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_SUPPORTED_UNREAD_ALERT_CAT]. - charInfo.valueHandle; - break; - - default: - /* Characteristic wasn't found */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - break; - } - - if(apiResult == CY_BLE_SUCCESS) - { - readReqParam.connHandle = connHandle; - - /* Send request to read characteristic value */ - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_anscReqHandle[discIdx] = readReqParam.attrHandle; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to the peer device to set the characteristic descriptor of the -* specified characteristic of Alert Notification Service. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_ANSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_ANSS_NOTIFICATION_DISABLED -* -* \param connHandle: The BLE peer device connection handle. -* \param charIndex: The index of the ANS characteristic. -* \param descrIndex: The index of the ANS characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: Pointer to the characteristic descriptor value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_STATE - The component in in invalid state for current -* operation. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ANS service-specific callback is registered -* (with Cy_BLE_ANS_RegisterAttrCallback): -* * CY_BLE_EVT_ANSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ans_descr_value_t. -* . -* Otherwise (if the ANS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - cy_en_ble_ans_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (descrIndex == CY_BLE_ANS_CCCD) && (attrSize == CY_BLE_CCCD_LEN)) - { - if((charIndex == CY_BLE_ANS_NEW_ALERT) || (charIndex == CY_BLE_ANS_UNREAD_ALERT_STATUS)) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - if(charIndex == CY_BLE_ANS_NEW_ALERT) - { - writeReqParam.handleValPair.attrHandle = cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_NEW_ALERT]. - descriptors[CY_BLE_ANS_CCCD]; - } - else - { - writeReqParam.handleValPair.attrHandle = - cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_UNREAD_ALERT_STATUS].descriptors[CY_BLE_ANS_CCCD]; - } - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_anscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - } - else - { - /* Characteristic has not been discovered or has invalid fields */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ANSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to the peer device to get the characteristic descriptor of the -* specified characteristic of Alert Notification Service. -* -* \param connHandle: BLE peer device connection handle. -* \param charIndex: The index of the Service Characteristic. -* \param descrIndex: The index of the Service Characteristic Descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - A request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The component is in invalid state for current -* operation. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Cannot process a request to send PDU due -* to invalid operation performed by the -* application. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ANS service-specific callback is registered -* (with Cy_BLE_ANS_RegisterAttrCallback): -* * CY_BLE_EVT_ANSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_ans_descr_value_t. -* . -* Otherwise (if the ANS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ANSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - uint8_t descrIndex) -{ - cy_stc_ble_gattc_read_req_t readReqParam; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - ((charIndex == CY_BLE_ANS_NEW_ALERT) || (charIndex == CY_BLE_ANS_UNREAD_ALERT_STATUS)) && - (descrIndex == (uint8_t)CY_BLE_ANS_CCCD)) - { - if(charIndex == CY_BLE_ANS_NEW_ALERT) - { - readReqParam.attrHandle = cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_NEW_ALERT]. - descriptors[CY_BLE_ANS_CCCD]; - } - else - { - readReqParam.attrHandle = cy_ble_ansc[discIdx].characteristics[CY_BLE_ANS_UNREAD_ALERT_STATUS]. - descriptors[CY_BLE_ANS_CCCD]; - } - - readReqParam.connHandle = connHandle; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_anscReqHandle[discIdx] = readReqParam.attrHandle; - } - } - else - { - /* Characteristic has not been discovered or had invalid fields */ - } - - return(apiResult); -} - -#endif /* CY_BLE_ANS_CLIENT */ -/****************************************************************************** -* Function Name: Cy_BLE_ANS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Alert Notification Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_ANS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_ANS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_ANSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_ANSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_ANSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_ANCS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_ANS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_ANSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_ANS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_ANS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_ANSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_ANSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_ANSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_ANSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_HRS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} -#endif /* CY_BLE_ANS */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ans.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ans.h deleted file mode 100644 index 48774aba9e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ans.h +++ /dev/null @@ -1,235 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ans.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Alert Notification -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_ANS_H -#define CY_BLE_ANS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_ANS)) - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Data Types -***************************************/ - -/** - * \addtogroup group_ble_service_api_ANS_definitions - * @{ - */ - -/** ANS Characteristic indexes */ -typedef enum -{ - CY_BLE_ANS_SUPPORTED_NEW_ALERT_CAT, /**< Supported New Alert Category Characteristic index */ - CY_BLE_ANS_NEW_ALERT, /**< New Alert Characteristic index */ - CY_BLE_ANS_SUPPORTED_UNREAD_ALERT_CAT, /**< Supported Unread Alert Category Characteristic index */ - CY_BLE_ANS_UNREAD_ALERT_STATUS, /**< Unread Alert Status Characteristic index */ - CY_BLE_ANS_ALERT_NTF_CONTROL_POINT, /**< Alert Notification Control Point Characteristic index */ - CY_BLE_ANS_CHAR_COUNT /**< Total count of ANS characteristics */ -}cy_en_ble_ans_char_index_t; - -/** ANS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_ANS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_ANS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_ans_descr_index_t; - -/** Alert Notification Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ans_char_index_t charIndex; /**< Index of Alert Notification Service Characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to Characteristic value */ -} cy_stc_ble_ans_char_value_t; - -/** Alert Notification Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_ans_char_index_t charIndex; /**< Characteristic index of Service */ - cy_en_ble_ans_descr_index_t descrIndex; /**< Service Characteristic Descriptor index */ - cy_stc_ble_gatt_value_t *value; /**< The pointer to the value of the Service Characteristic - * Descriptor value */ -} cy_stc_ble_ans_descr_value_t; - -/** ANS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of Characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_ANS_DESCR_COUNT]; /**< Handle of Descriptor */ -} cy_stc_ble_anss_char_t; - -/** The structure with the Alert Notification Service attribute handles */ -typedef struct -{ - /** The Alert Notification Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** The array of the Alert Notification Service Characteristics + Descriptors handles */ - cy_stc_ble_anss_char_t charInfo[CY_BLE_ANS_CHAR_COUNT]; -} cy_stc_ble_anss_t; - -/** Service Full characteristic information type */ -typedef struct -{ - /** Characteristic handle + properties */ - cy_stc_ble_srvr_char_info_t charInfo; - - /** End handle of the characteristic */ - cy_ble_gatt_db_attr_handle_t endHandle; - - /** Characteristic descriptors handles */ - cy_ble_gatt_db_attr_handle_t descriptors[CY_BLE_ANS_DESCR_COUNT]; -} cy_stc_ble_srvr_full_char_info_t; - -/** The structure with discovered attributes information of the Alert Notification Service */ -typedef struct -{ - /** The structure with Characteristic handles + properties of the Alert Notification Service */ - cy_stc_ble_srvr_full_char_info_t characteristics[CY_BLE_ANS_CHAR_COUNT]; -} cy_stc_ble_ansc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Service GATT DB handles structure */ - const cy_stc_ble_anss_t *anss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_ans_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_ANS_INVALID_CHAR_INDEX (0xFFu) - -/** Alert Notification Characteristic Command ID */ -#define CY_BLE_ANS_EN_NEW_ALERT_NTF (0x00u) /** Enable New Incoming Alert Notification */ -#define CY_BLE_ANS_EN_UNREAD_ALERT_STATUS_NTF (0x01u) /** Enable Unread Category Status Notification */ -#define CY_BLE_ANS_DIS_NEW_ALERT_NTF (0x02u) /** Disable New Incoming Alert Notification */ -#define CY_BLE_ANS_DIS_UNREAD_ALERT_STATUS_NTF (0x03u) /** Disable Unread Category Status Notification */ -#define CY_BLE_ANS_IMM_NEW_ALERT_NTF (0x04u) /** Notify New Incoming Alert immediately */ -#define CY_BLE_ANS_IMM_UNREAD_ALERT_STATUS_NTF (0x05u) /** Notify Unread Category Status immediately */ - -/* Alert Notification Characteristic Category ID */ -#define CY_BLE_ANS_CAT_ID_SIMPLE_ALERT (0x00u) /* Simple Alert: General text alert or non-text alert */ -#define CY_BLE_ANS_CAT_ID_EMAIL (0x01u) /* Email: Alert when Email messages arrives */ -#define CY_BLE_ANS_CAT_ID_NEWS (0x02u) /* News: News feeds such as RSS, Atom */ -#define CY_BLE_ANS_CAT_ID_CALL (0x03u) /* Call: Incoming call */ -#define CY_BLE_ANS_CAT_ID_MISSED_CALL (0x04u) /* Missed call: Missed Call */ -#define CY_BLE_ANS_CAT_ID_SMS_MMS (0x05u) /* SMS/MMS: SMS/MMS message arrives */ -#define CY_BLE_ANS_CAT_ID_VOICE_MAIL (0x06u) /* Voice mail: Voice mail */ -#define CY_BLE_ANS_CAT_ID_SCHEDULE (0x07u) /* Schedule: Alert occurred on calendar, planner */ -#define CY_BLE_ANS_CAT_ID_HI_PRFIORITIZED_ALERT (0x08u) /* High Prioritized Alert: Alert that should be handled as - * high priority */ -#define CY_BLE_ANS_CAT_ID_INSTANT_MESSAGE (0x09u) /* Instant Message: Alert for incoming instant messages */ - -#define CY_BLE_ANS_CAT_ID_ALL (0xFFu) /* Category ID - All categories */ - -#define CY_BLE_ANS_CHAR_VALUE_OFFSET (0x02u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_ANS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_ANS_Init(cy_stc_ble_ans_config_t *config); -cy_en_ble_api_result_t Cy_BLE_ANS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_ANS_SERVER -/** - * \addtogroup group_ble_service_api_ANS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_ANSS_SetCharacteristicValue(cy_en_ble_ans_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANSS_GetCharacteristicValue(cy_en_ble_ans_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - cy_en_ble_ans_descr_index_t - descrIndex, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_ANS_SERVER */ - -#ifdef CY_BLE_ANS_CLIENT -/** - * \addtogroup group_ble_service_api_ANS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_ANSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_ANSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, - cy_en_ble_ans_descr_index_t - descrIndex, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ANSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ans_char_index_t charIndex, uint8_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_ANS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_ANS_CLIENT -extern cy_stc_ble_ansc_t cy_ble_ansc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_ANS_CLIENT) */ - -extern cy_stc_ble_ans_config_t cy_ble_ansConfig; -extern cy_stc_ble_ans_config_t *cy_ble_ansConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_ANS) */ -#endif /* CY_BLE_ANS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bas.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bas.c deleted file mode 100644 index c2fd166b73..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bas.c +++ /dev/null @@ -1,1189 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bas.c -* \version 2.0 -* -* \brief -* Contains the source code for the Battery Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BAS)) - -static cy_ble_callback_t Cy_BLE_BAS_ApplCallback = NULL; - -#ifdef CY_BLE_BAS_CLIENT -/* BAS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_basc_t cy_ble_basc[CY_BLE_CONFIG_GATTC_COUNT][CY_BLE_BASC_SERVICE_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_bascReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_BAS_CLIENT) */ - -/* The pointer to the global BLE BAS config structure */ -cy_stc_ble_bas_config_t *cy_ble_basConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_BAS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_BASS_WriteEventHandler( - const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_BAS_SERVER */ - -#ifdef CY_BLE_BAS_CLIENT -static void Cy_BLE_BASC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_BASC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_BASC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_BASC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_BASC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_BASC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_BASC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_BAS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_BAS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_BAS_Init -***************************************************************************//** -* -* This function initializes the BAS Service. -* -* \param config: The configuration structure for the BAS Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BAS_Init(cy_stc_ble_bas_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_basConfigPtr = config; - - /* Registers Event Handler for the BAS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_BAS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_basConfigPtr->callbackFunc != NULL) - { - Cy_BLE_BAS_ApplCallback = cy_ble_basConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_BAS_CLIENT - { - uint32_t idx; - uint8_t locServIndex; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - for(locServIndex = 0u; locServIndex < (uint32_t)CY_BLE_BASC_SERVICE_COUNT; locServIndex++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_BAS + locServIndex].range.startHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_basc[idx][locServIndex], 0, sizeof(cy_stc_ble_basc_t)); - - /* Initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_BAS + locServIndex].uuid = CY_BLE_UUID_BAS_SERVICE; - } - } - cy_ble_bascReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_BAS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BAS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific Write requests from the peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* Battery Service events from the BLE Component. The -* definition of cy_ble_callback_t for Battery Service is,\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_BASS_NOTIFICATION_ENABLED) -* * eventParam contains the parameters corresponding to the -* current event (e.g., the pointer to the cy_stc_ble_bas_char_value_t -* structure that contains details of the characteristic -* for which a notification enabled event was triggered) -* -* \sideeffect The *eventParams in the callback function should not be used -* by the application when the callback function execution is -* finished. Otherwise, this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BAS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_BAS_ApplCallback = callbackFunc; - if(cy_ble_basConfigPtr != NULL) - { - cy_ble_basConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_BAS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_BASS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service in the local database. -* -* \param serviceIndex: The index of the service instance. -* \param charIndex: The index of the service characteristic of type -* cy_en_ble_bas_char_index_t. -* \param attrSize: The size of the characteristic value attribute. A battery level -* characteristic has a 1-byte length. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASS_SetCharacteristicValue(uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((serviceIndex >= CY_BLE_BASS_SERVICE_COUNT) || (charIndex >= CY_BLE_BAS_CHAR_COUNT) || - (attrSize != CY_BLE_BAS_BATTERY_LEVEL_LEN) || (*attrValue > CY_BLE_BAS_MAX_BATTERY_LEVEL_VALUE)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Store data in the database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_basConfigPtr->bass[serviceIndex].batteryLevelHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the Battery Service, identified by charIndex. -* -* \param serviceIndex: The index of the service instance. e.g. if two Battery Services -* are supported in your design, then the first service will be -* identified by serviceIndex of 0 and the second service - by serviceIndex -* of 1. -* \param charIndex: The index of a service characteristic of type cy_en_ble_bas_char_index_t. -* \param attrSize: The size of the characteristic value attribute. A battery level -* characteristic has a 1-byte length. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASS_GetCharacteristicValue(uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((serviceIndex >= CY_BLE_BASS_SERVICE_COUNT) || (charIndex >= CY_BLE_BAS_CHAR_COUNT) || - (attrSize != CY_BLE_BAS_BATTERY_LEVEL_LEN)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_basConfigPtr->bass[serviceIndex].batteryLevelHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the -* Battery Service from the local GATT database. -* -* \param connHandle: The BLE peer device connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two Battery Services -* are supported in your design, then the first service will be -* identified by serviceIndex of 0 and the second service - by serviceIndex -* of 1. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_bas_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_bas_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where the characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - cy_en_ble_bas_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((serviceIndex >= CY_BLE_BASS_SERVICE_COUNT) || (charIndex >= CY_BLE_BAS_CHAR_COUNT) || - (descrIndex >= CY_BLE_BAS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - - /* Get data from the database */ - if(descrIndex == CY_BLE_BAS_BATTERY_LEVEL_CCCD) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_basConfigPtr->bass[serviceIndex].cccdHandle; - } - else - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_basConfigPtr->bass[serviceIndex].cpfdHandle; - } - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request Event for the Battery Service. -* -* \param void *eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - A Write request is handled successfully. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - Notification isn't supported. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An internal error while writing attribute -* value. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BASS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - uint8_t locServIndex = 0u; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_bas_char_value_t locCharIndex = { .connHandle = eventParam->connHandle }; - - if(Cy_BLE_BAS_ApplCallback != NULL) - { - do - { - /* Client Characteristic Configuration descriptor Write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_basConfigPtr->bass[locServIndex].cccdHandle) - { - /* Verify that the optional notification property is enabled for the Battery Level characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_basConfigPtr->bass[locServIndex].batteryLevelHandle)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - locCharIndex.serviceIndex = locServIndex; - locCharIndex.charIndex = CY_BLE_BAS_BATTERY_LEVEL; - locCharIndex.value = NULL; - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_BAS_ApplCallback((uint32_t)CY_BLE_EVT_BASS_NOTIFICATION_ENABLED, &locCharIndex); - } - else - { - Cy_BLE_BAS_ApplCallback((uint32_t)CY_BLE_EVT_BASS_NOTIFICATION_DISABLED, &locCharIndex); - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - - /* Sets a flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - locServIndex++; - } - while(locServIndex < CY_BLE_BASS_SERVICE_COUNT); - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASS_SendNotification -***************************************************************************//** -* -* This function updates the value of the Battery Level characteristic in the -* GATT database. If the Client has configured a notification on the Battery -* Level characteristic, the function additionally sends this value using a -* GATT Notification message. -* -* On enabling notification successfully for a service characteristic it sends out a -* Handle Value notification which results in CY_BLE_EVT_BASC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The BLE peer device connection handle -* \param serviceIndex: The index of the service instance. e.g. If two Battery Services -* are supported in your design, then the first service will be -* identified by serviceIndex of 0 and the second service - by -* serviceIndex of 1. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_bas_char_index_t. -* \param attrSize: The size of the characteristic value attribute. A battery level -* characteristic has a 1-byte length. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the Client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Store new data in the database */ - apiResult = Cy_BLE_BASS_SetCharacteristicValue(serviceIndex, charIndex, attrSize, attrValue); - - if(apiResult == CY_BLE_SUCCESS) - { - /* Send notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((cy_ble_basConfigPtr->bass[serviceIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) || - (!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_basConfigPtr->bass[serviceIndex].cccdHandle))) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - /* Fill all fields of the Write request structure ... */ - .handleValPair.attrHandle = cy_ble_basConfigPtr->bass[serviceIndex].batteryLevelHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to the Client using a previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - - return(apiResult); -} - -#endif /* CY_BLE_BAS_SERVER */ - -#ifdef CY_BLE_BAS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, the appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_BASC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (discCharInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_BATTERY_LEVEL) && - (cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_BAS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_BAS_END)) - { - /* The index of the service instance */ - uint32_t basServIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_BAS; - - /* Check and store characteristic handle */ - Cy_BLE_CheckStoreCharHandle(cy_ble_basc[discIdx][basServIdx].batteryLevel); - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* \param discoveryService: The index of the service instance. -* -******************************************************************************/ -static void Cy_BLE_BASC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t basServIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_BAS; - - if((cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_BAS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_BAS_END)) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_basc[discIdx][basServIdx].cccdHandle); - } - else if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_FORMAT) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_basc[discIdx][basServIdx].cpfdHandle); - } - else if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_REPORT_REFERENCE) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_basc[discIdx][basServIdx].rrdHandle); - } - else /* BAS doesn't support other descriptors */ - { - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_BASC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if((cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_BAS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_BAS_END)) - { - /* The index of the service instance */ - uint32_t basServIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_BAS; - - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if((cy_ble_discovery[discIdx].charCount == 0u) && - (cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - charRangeInfo->range.startHandle = cy_ble_basc[discIdx][basServIdx].batteryLevel.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic value from the Server -* identified by charIndex. -* -* This function call can result in generation of the following events based on -* a response from the Server device: -* * CY_BLE_EVT_BASC_READ_CHAR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The BLE peer device connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two Battery Services are -* supported in your design, then the first service will be identified -* by serviceIndex of 0 and the second service - by serviceIndex of 1. -* \param charIndex: The index of a service characteristic of type cy_en_ble_bas_char_index_t. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The Read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS) -* these events can appear: \n -* If the BAS service-specific callback is registered -* (with Cy_BLE_BAS_RegisterAttrCallback): -* * CY_BLE_EVT_BASC_READ_CHAR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bas_char_value_t. -* . -* Otherwise (if a BAS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((serviceIndex >= (uint32_t)CY_BLE_BASC_SERVICE_COUNT) || (charIndex > CY_BLE_BAS_BATTERY_LEVEL) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_basc[discIdx][serviceIndex].batteryLevel.valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_basc[discIdx][serviceIndex].batteryLevel.valueHandle, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - /* Save the handle to support service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bascReqHandle[discIdx] = cy_ble_basc[discIdx][serviceIndex].batteryLevel.valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to set a characteristic descriptor of the specified Battery Service -* characteristic on the server device. -* -* Internally, a Write Request is sent to the GATT Server and on successful -* execution of the request on the Server's side the following events can be -* generated: -* * CY_BLE_EVT_BASS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_BASS_NOTIFICATION_DISABLED -* -* \param connHandle: The BLE peer device connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two Battery Services -* are supported in your design, then the first service will be -* identified by serviceIndex of 0 and the second service - by -* serviceIndex of 1. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_bas_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_bas_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that should -* be sent to the Server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BAS service-specific callback is registered -* (with Cy_BLE_BAS_RegisterAttrCallback): -* * CY_BLE_EVT_BASC_WRITE_DESCR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bas_descr_value_t. -* . -* Otherwise (if a BAS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - cy_en_ble_bas_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((serviceIndex >= (uint32_t)CY_BLE_BASC_SERVICE_COUNT) || (charIndex > CY_BLE_BAS_BATTERY_LEVEL) || - (descrIndex >= CY_BLE_BAS_DESCR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(descrIndex != CY_BLE_BAS_BATTERY_LEVEL_CCCD) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - /* Fill all the fields of the Write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_basc[discIdx][serviceIndex].cccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* ... and send a request to the Server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save the handle to support service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bascReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get a characteristic descriptor of the specified Battery Service -* characteristic from the Server device. This function call can result in -* generation of the following events based on a response from the Server -* device: -* * CY_BLE_EVT_BASC_READ_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The BLE peer device connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two Battery Services are -* supported in your design, then the first service will be identified -* by serviceIndex of 0 and the second - by serviceIndex of 1. -* \param charIndex: The index of a Battery Service characteristic of type -* cy_en_ble_bas_char_index_t. -* \param descrIndex: The index of a Battery Service characteristic descriptor of type -* cy_en_ble_bas_descr_index_t. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BAS service-specific callback is registered -* (with Cy_BLE_BAS_RegisterAttrCallback): -* * CY_BLE_EVT_BASC_READ_DESCR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_bas_descr_value_t. -* . -* Otherwise (if a BAS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BASC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - cy_en_ble_bas_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - cy_stc_ble_gattc_read_req_t readReqParam = { .connHandle = connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((serviceIndex >= CY_BLE_BASC_SERVICE_COUNT) || (charIndex > CY_BLE_BAS_BATTERY_LEVEL) || - (descrIndex >= CY_BLE_BAS_DESCR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(descrIndex == CY_BLE_BAS_BATTERY_LEVEL_CCCD) - { - readReqParam.attrHandle = cy_ble_basc[discIdx][serviceIndex].cccdHandle; - } - else /* CY_BLE_BAS_BATTERY_LEVEL_CPFD */ - { - readReqParam.attrHandle = cy_ble_basc[discIdx][serviceIndex].cpfdHandle; - } - - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save the handle to support a service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bascReqHandle[discIdx] = readReqParam.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_NotificationEventHandler -***************************************************************************//** -* -* Handles a Notification event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BASC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t i; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BAS_ApplCallback != NULL)) - { - for(i = 0u; i < CY_BLE_BASC_SERVICE_COUNT; i++) - { - if(cy_ble_basc[discIdx][i].batteryLevel.valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_bas_char_value_t locCharValue = - { - .serviceIndex = (uint8_t)i, - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BAS_BATTERY_LEVEL, - .value = &eventParam->handleValPair.value, - }; - Cy_BLE_BAS_ApplCallback((uint32_t)CY_BLE_EVT_BASC_NOTIFICATION, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BASC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t locServIndex; - uint32_t locReqHandle = 0u; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BAS_ApplCallback != NULL) && - (cy_ble_bascReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locServIndex = 0u; (locServIndex < CY_BLE_BASC_SERVICE_COUNT) && (locReqHandle == 0u); locServIndex++) - { - if(cy_ble_basc[discIdx][locServIndex].batteryLevel.valueHandle == cy_ble_bascReqHandle[discIdx]) - { - cy_stc_ble_bas_char_value_t batteryLevelValue = - { - .connHandle = eventParam->connHandle, - .serviceIndex = locServIndex, - .charIndex = CY_BLE_BAS_BATTERY_LEVEL, - .value = &eventParam->value - }; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_bascReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_BAS_ApplCallback((uint32_t)CY_BLE_EVT_BASC_READ_CHAR_RESPONSE, &batteryLevelValue); - locReqHandle = 1u; - } - else if((cy_ble_basc[discIdx][locServIndex].cccdHandle == cy_ble_bascReqHandle[discIdx]) || - (cy_ble_basc[discIdx][locServIndex].cpfdHandle == cy_ble_bascReqHandle[discIdx])) - { - cy_stc_ble_bas_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .serviceIndex = locServIndex, - .charIndex = CY_BLE_BAS_BATTERY_LEVEL, - .descrIndex = ((cy_ble_basc[discIdx][locServIndex].cccdHandle == cy_ble_bascReqHandle[discIdx]) ? - CY_BLE_BAS_BATTERY_LEVEL_CCCD : CY_BLE_BAS_BATTERY_LEVEL_CPFD), - .value = &eventParam->value - }; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_bascReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_BAS_ApplCallback((uint32_t)CY_BLE_EVT_BASC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - else /* Unsupported event code */ - { - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BASC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - uint32_t locServIndex; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BAS_ApplCallback != NULL) && - (cy_ble_bascReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locServIndex = 0u; locServIndex < (uint32_t)CY_BLE_BASC_SERVICE_COUNT; locServIndex++) - { - if(cy_ble_basc[discIdx][locServIndex].cccdHandle == cy_ble_bascReqHandle[discIdx]) - { - cy_stc_ble_bas_descr_value_t locDescIndex = - { - .connHandle = *eventParam, - .serviceIndex = locServIndex, - .charIndex = CY_BLE_BAS_BATTERY_LEVEL, - .descrIndex = CY_BLE_BAS_BATTERY_LEVEL_CCCD, - .value = NULL - }; - - cy_ble_bascReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BAS_ApplCallback((uint32_t)CY_BLE_EVT_BASC_WRITE_DESCR_RESPONSE, &locDescIndex); - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BASC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_BASC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_bascReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_bascReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* (CY_BLE_BAS_CLIENT) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_BAS_EventHandler -***************************************************************************//** -* -* Handles events from the BLE stack for the Battery Service. -* -* \param eventCode: The event code. -* \param eventParam: The event parameters. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BAS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_BAS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_BASC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_BASC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_BASC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_BAS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server events - ***************************************************************************/ - #ifdef CY_BLE_BAS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_BASS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_BAS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_BAS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_BASC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_BASC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_BASC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_BASC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_BAS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_BAS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ - diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bas.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bas.h deleted file mode 100644 index 1f26b64cb2..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bas.h +++ /dev/null @@ -1,230 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bas.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Battery Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_BAS_H -#define CY_BLE_BAS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BAS)) - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -#ifdef CY_BLE_BAS_SERVER - -/* The maximum supported Battery Services */ - #define CY_BLE_BASS_SERVICE_COUNT (CY_BLE_CONFIG_BASS_SERVICE_COUNT) - -#endif /* CY_BLE_BAS_SERVER */ - -#ifdef CY_BLE_BAS_CLIENT -/* The maximum supported Battery Services */ - #define CY_BLE_BASC_SERVICE_COUNT (CY_BLE_CONFIG_BASC_SERVICE_COUNT) - -#endif /* (CY_BLE_BAS_CLIENT) */ - - -/*************************************** -* Data Types -***************************************/ - -/** - * \addtogroup group_ble_service_api_BAS_definitions - * @{ - */ - -/** BAS Characteristic indexes */ -typedef enum -{ - CY_BLE_BAS_BATTERY_LEVEL, /**< Battery Level characteristic index */ - CY_BLE_BAS_CHAR_COUNT /**< Total count of characteristics */ -}cy_en_ble_bas_char_index_t; - -/** BAS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_BAS_BATTERY_LEVEL_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_BAS_BATTERY_LEVEL_CPFD, /**< Characteristic Presentation Format descriptor index */ - CY_BLE_BAS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_bas_descr_index_t; - -/** Structure with Battery Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Battery Service handle */ - cy_ble_gatt_db_attr_handle_t batteryLevelHandle; /**< Battery Level characteristic handle */ - cy_ble_gatt_db_attr_handle_t cpfdHandle; /**< Characteristic Presentation Format Descriptor handle */ - cy_ble_gatt_db_attr_handle_t cccdHandle; /**< Client Characteristic Configuration descriptor handle */ -} cy_stc_ble_bass_t; - -/** Structure with discovered attributes information of Battery Service */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_stc_ble_srvr_char_info_t batteryLevel; /**< Battery Level characteristic info */ - cy_ble_gatt_db_attr_handle_t cpfdHandle; /**< Characteristic Presentation Format descriptor handle */ - cy_ble_gatt_db_attr_handle_t cccdHandle; /**< Client Characteristic Configuration descriptor handle */ - cy_ble_gatt_db_attr_handle_t rrdHandle; /**< Report Reference descriptor handle */ -} cy_stc_ble_basc_t; - -/** Battery Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - uint8_t serviceIndex; /**< Service instance */ - cy_en_ble_bas_char_index_t charIndex; /**< Index of a service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_bas_char_value_t; - -/** Battery Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - uint8_t serviceIndex; /**< Service instance */ - cy_en_ble_bas_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_bas_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_bas_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Service GATT DB handles structure */ - const cy_stc_ble_bass_t *bass; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_bas_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -/* Battery Level characteristic length */ -#define CY_BLE_BAS_BATTERY_LEVEL_LEN (0x01u) - -/* Maximum Battery Level value */ -#define CY_BLE_BAS_MAX_BATTERY_LEVEL_VALUE (100u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_BAS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_BAS_Init(cy_stc_ble_bas_config_t *config); -cy_en_ble_api_result_t Cy_BLE_BAS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - - - -#ifdef CY_BLE_BAS_SERVER -/** - * \addtogroup group_ble_service_api_BAS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BASS_SetCharacteristicValue(uint8_t serviceIndex, cy_en_ble_bas_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BASS_GetCharacteristicValue(uint8_t serviceIndex, cy_en_ble_bas_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BASS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - cy_en_ble_bas_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BASS_SendNotification(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_BAS_SERVER */ - -#ifdef CY_BLE_BAS_CLIENT -/** - * \addtogroup group_ble_service_api_BAS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BASC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_BASC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - cy_en_ble_bas_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BASC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_bas_char_index_t charIndex, - cy_en_ble_bas_descr_index_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_BAS_CLIENT) */ - - -/*************************************** -* Macro Functions -***************************************/ - -#ifdef CY_BLE_BAS_CLIENT -#define Cy_BLE_BASC_GetCharacteristicValueHandle(connHandle, serviceIndex, charIndex) \ - ((((serviceIndex) >= CY_BLE_BASC_SERVICE_COUNT) || ((charIndex) > CY_BLE_BAS_BATTERY_LEVEL)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_basc[Cy_BLE_GetDiscoveryIdx(connHandle)][serviceIndex].batteryLevel.valueHandle) - -#define Cy_BLE_BASC_GetCharacteristicDescriptorHandle(connHandle, serviceIndex, charIndex, descrIndex) \ - ((((serviceIndex) >= CY_BLE_BASC_SERVICE_COUNT) || ((charIndex) > CY_BLE_BAS_BATTERY_LEVEL) || \ - ((descrIndex) >= CY_BLE_BAS_DESCR_COUNT)) ? CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - ((descrIndex) == CY_BLE_BAS_BATTERY_LEVEL_CCCD) ? \ - cy_ble_basc[Cy_BLE_GetDiscoveryIdx(connHandle)][serviceIndex].cccdHandle : \ - cy_ble_basc[Cy_BLE_GetDiscoveryIdx(connHandle)][serviceIndex].cpfdHandle) - -#endif /* (CY_BLE_BAS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_BAS_CLIENT -extern cy_stc_ble_basc_t cy_ble_basc[CY_BLE_CONFIG_GATTC_COUNT][CY_BLE_BASC_SERVICE_COUNT]; -#endif /* (CY_BLE_BAS_CLIENT) */ - -extern cy_stc_ble_bas_config_t cy_ble_basConfig; -extern cy_stc_ble_bas_config_t *cy_ble_basConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_BASS) */ -#endif /* CY_BLE_BAS_H */ - - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bcs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bcs.c deleted file mode 100644 index 2752bae70e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bcs.c +++ /dev/null @@ -1,1252 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bcs.c -* \version 2.0 -* -* \brief -* Contains the source code for the Body Composition Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BCS)) - -#ifdef CY_BLE_BCS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_bcssReqHandle; -#endif /* CY_BLE_BCS_SERVER */ - -#ifdef CY_BLE_BCS_CLIENT -/* BCS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_bcsc_t cy_ble_bcsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_bcscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_BCS_CLIENT) */ - -static cy_ble_callback_t Cy_BLE_BCS_ApplCallback = NULL; - -/* The pointer to the global BLE BCS config structure */ -cy_stc_ble_bcs_config_t *cy_ble_bcsConfigPtr; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_BCS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_BCSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_BCSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -#endif /* CY_BLE_BCS_SERVER */ - -#ifdef CY_BLE_BCS_CLIENT -static void Cy_BLE_BCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_BCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_BCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_BCSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_BCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_BCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_BCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_BCS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_BCS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_BCS_Init -***************************************************************************//** -* -* This function initializes the Body Composition Service. -* -* \param config: The configuration structure for the Body Composition Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCS_Init(cy_stc_ble_bcs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure*/ - cy_ble_bcsConfigPtr = config; - - /* Registers Event Handler for the BCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_BCS_EventHandler); - - /* Registers a callback function via config structure*/ - if(cy_ble_bcsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_BCS_ApplCallback = cy_ble_bcsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_BCS_SERVER - cy_ble_bcssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_BCS_SERVER */ - - #ifdef CY_BLE_BCS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_BCS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_bcsc[idx], 0, sizeof(cy_stc_ble_bcsc_t)); - - /* Initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_BCS].uuid = CY_BLE_UUID_BODY_COMPOSITION_SERVICE; - } - cy_ble_bcscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_BCS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific Write requests from a peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode: Indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_BCSS_INDICATION_ENABLED). -* * eventParam: Contains the parameters corresponding to the -* current event. (e.g. the pointer to cy_stc_ble_bcs_char_value_t -* structure that contains details of the characteristic -* the CY_BLE_EVT_BCSS_INDICATION_ENABLED event triggered for). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_BCS_ApplCallback = callbackFunc; - if(cy_ble_bcsConfigPtr != NULL) - { - cy_ble_bcsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_BCS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request event for the Body Composition Service. -* -* \param void *eventParam - The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - The Write is successful. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The request is not supported. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - The Write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - The offset value is invalid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BCSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t event = (uint32_t)CY_BLE_EVT_BCSS_INDICATION_DISABLED; - - if(Cy_BLE_BCS_ApplCallback != NULL) - { - /* Client Characteristic Configuration descriptor Write request */ - if(eventParam->handleValPair.attrHandle == - cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].descrHandle[CY_BLE_BCS_CCCD]) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_BCSS_INDICATION_ENABLED; - } - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_bcs_char_value_t wrReqParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT, - .value = NULL - }; - Cy_BLE_BCS_ApplCallback(event, &wrReqParam); - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set a flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - /* Clear a callback flag indicating that the request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* \param eventParam: The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_BCSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_BCS_ApplCallback != NULL) && (cy_ble_bcssReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Only Weight Measurement characteristic has the Indication property. Check if - * the requested handle is the handle of the Descriptor Value Change handle. - */ - if(cy_ble_bcssReqHandle == cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].charHandle) - { - /* Fill in the event data and inform Application about successfully - * confirmed indication. - */ - cy_stc_ble_bcs_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT, - .value = NULL - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_bcssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_BCS_ApplCallback((uint32_t)CY_BLE_EVT_BCSS_INDICATION_CONFIRMED, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a value for one of the three characteristic values of the Body Composition -* Service. The characteristic is identified by charIndex. -* -* \param charIndex: The index of a Body Composition Service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was written successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSS_SetCharacteristicValue(cy_en_ble_bcs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo; - - if((attrValue != NULL) && (charIndex < CY_BLE_BCS_CHAR_COUNT)) - { - /* Fill the structure */ - if(charIndex == CY_BLE_BCS_BODY_COMPOSITION_FEATURE) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_bcsConfigPtr-> - bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_FEATURE].charHandle; - } - else - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_bcsConfigPtr-> - bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].charHandle; - } - dbAttrValInfo.handleValuePair.value.len = attrSize; - dbAttrValInfo.handleValuePair.value.val = attrValue; - dbAttrValInfo.offset = 0u; - dbAttrValInfo.flags = CY_BLE_GATT_DB_LOCALLY_INITIATED; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return a status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_GetCharacteristicValue -***************************************************************************//** -* -* Reads a characteristic value of the Body Composition Service identified -* by charIndex from the GATT database. -* -* \param charIndex: The index of the Body Composition Service characteristic. -* \param attrSize: The size of the Body Composition Service characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSS_GetCharacteristicValue(cy_en_ble_bcs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_ble_gatt_db_attr_handle_t tmpCharHandle; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex < CY_BLE_BCS_CHAR_COUNT)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(charIndex == CY_BLE_BCS_BODY_COMPOSITION_FEATURE) - { - tmpCharHandle = cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_FEATURE].charHandle; - } - else - { - tmpCharHandle = cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].charHandle; - } - dbAttrValInfo.handleValuePair.attrHandle = tmpCharHandle; - - /* Get a characteristic value from the GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return a status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data to be stored in the GATT -* database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT) && (descrIndex == CY_BLE_BCS_CCCD) && (attrValue != NULL)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT]. - descrHandle[CY_BLE_BCS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Read the characteristic value from the database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Reads a a characteristic descriptor of the specified characteristic of the -* Body Composition Service from the GATT database. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The optional descriptor is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT) && (descrIndex == CY_BLE_BCS_CCCD) && (attrValue != NULL)) - { - if(cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].descrHandle[CY_BLE_BCS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_bcsConfigPtr->bcss-> - charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT]. - descrHandle[CY_BLE_BCS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Get a characteristic value from the GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSS_SendIndication -***************************************************************************//** -* -* Sends indication with a characteristic value of the Body Composition Service, -* which is a value specified by charIndex to the Client device. -* -* On enabling indication successfully it sends out a Handle Value Indication which -* results in CY_BLE_EVT_BCSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the Client. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BCS service-specific callback is registered -* (with Cy_BLE_BCS_RegisterAttrCallback): -* * CY_BLE_EVT_BCSS_INDICATION_CONFIRMED - If the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if a BCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - If the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex == CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT) - { - /* Send indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, - cy_ble_bcsConfigPtr->bcss->charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT]. - descrHandle[CY_BLE_BCS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all the fields of the Write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_bcsConfigPtr->bcss-> - charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to the Client using a previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - - /* Save a handle to support service-specific value confirmation response from the Client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bcssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - } - - return(apiResult); -} - -#endif /* CY_BLE_BCS_SERVER */ - - -#ifdef CY_BLE_BCS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_BCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* BCS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_bcscCharUuid[CY_BLE_BCS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_BODY_COMPOSITION_FEATURE, - CY_BLE_UUID_CHAR_BODY_COMPOSITION_MEASUREMENT - }; - - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BCS)) - { - /* Update the last characteristic endHandle to the declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - /* Search through all available characteristics */ - for(i = (uint32_t)CY_BLE_BCS_BODY_COMPOSITION_FEATURE; i < (uint32_t)CY_BLE_BCS_CHAR_COUNT; i++) - { - if(cy_ble_bcscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_bcsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_bcsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_bcsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_bcsc[discIdx].charInfo[i].endHandle; - break; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initialize the characteristic endHandle to the service endHandle. The characteristic endHandle - * will be updated to the declaration handle of the following characteristic - * in the following characteristic discovery procedure. - */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************s -* Function Name: Cy_BLE_BCSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, the appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_BCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BCS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - if(cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle = discDescrInfo->descrHandle; - } - else /* Duplication of the descriptor */ - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_BCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BCS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if(cy_ble_discovery[discIdx].charCount == 0u) - { - charRangeInfo->range.startHandle = cy_ble_bcsc[discIdx].charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT]. - valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_bcsc[discIdx].charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT]. - endHandle; - } - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an Indication event for the Body Composition Service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BCSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BCS_ApplCallback != NULL)) - { - if(cy_ble_bcsc[discIdx].charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_bcs_char_value_t indicationValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_BCS_ApplCallback((uint32_t)CY_BLE_EVT_BCSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event for the Body Composition Service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t locReqHandle = 1u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BCS_ApplCallback != NULL) && - (cy_ble_bcscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if((cy_ble_bcscReqHandle[discIdx] == - cy_ble_bcsc[discIdx].charInfo[CY_BLE_BCS_BODY_COMPOSITION_FEATURE].valueHandle) || - (cy_ble_bcscReqHandle[discIdx] == - cy_ble_bcsc[discIdx].charInfo[CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT].valueHandle)) - { - cy_stc_ble_bcs_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - if(cy_ble_bcscReqHandle[discIdx] == cy_ble_bcsc[discIdx].charInfo[CY_BLE_BCS_BODY_COMPOSITION_FEATURE]. - valueHandle) - { - locCharValue.charIndex = CY_BLE_BCS_BODY_COMPOSITION_FEATURE; - } - else - { - locCharValue.charIndex = CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT; - } - - locCharValue.value = &eventParam->value; - cy_ble_bcscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_BCS_ApplCallback((uint32_t)CY_BLE_EVT_BCSC_READ_CHAR_RESPONSE, &locCharValue); - } - else if(cy_ble_bcscReqHandle[discIdx] == cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle) - { - cy_stc_ble_bcs_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT, - .descrIndex = CY_BLE_BCS_CCCD, - .value = &eventParam->value - }; - cy_ble_bcscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_BCS_ApplCallback((uint32_t)CY_BLE_EVT_BCSC_READ_DESCR_RESPONSE, &locDescrValue); - } - else - { - locReqHandle = 0u; - } - - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event for the Body Composition Service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - /* Check if the service handler was registered and the request handle is valid */ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BCS_ApplCallback != NULL) && - (cy_ble_bcscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_bcscReqHandle[discIdx] == cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle) - { - cy_stc_ble_bcs_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT, - .descrIndex = CY_BLE_BCS_CCCD, - .value = NULL - }; - cy_ble_bcscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_BCS_ApplCallback((uint32_t)CY_BLE_EVT_BCSC_WRITE_DESCR_RESPONSE, &locDescrValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event for the Body Composition Service. -* -* \param eventParam - The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_bcscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_bcscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the Server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with a zero. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BCS service-specific callback is registered -* (with Cy_BLE_BCS_RegisterAttrCallback): -* * CY_BLE_EVT_BCSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully read on the peer device, ! -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bcs_char_value_t. -* . -* Otherwise (if a BCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BCS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bcsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_bcsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save the handle to support a service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bcscReqHandle[discIdx] = cy_ble_bcsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the Server -* identified by charIndex and descrIndex. -* -* Internally, a Write Request is sent to the GATT Server and on successful -* execution of the request on the Server's side the following events can be -* generated: -* * CY_BLE_EVT_BCSS_INDICATION_ENABLED -* * CY_BLE_EVT_BCSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BCS service-specific callback is registered -* (with Cy_BLE_BCS_RegisterAttrCallback): -* * CY_BLE_EVT_BCSC_WRITE_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bcs_descr_value_t. -* . -* Otherwise (if a BCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BCS_CHAR_COUNT) || (descrIndex >= CY_BLE_BCS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all the fields of the Write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send a request to the Server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save the handle to support a service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bcscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BCSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with a zero. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BCS service-specific callback is registered -* (with Cy_BLE_BCS_RegisterAttrCallback): -* * CY_BLE_EVT_BCSC_READ_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_bcs_descr_value_t. -* . -* Otherwise (if a BCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BCS_CHAR_COUNT) || (descrIndex >= CY_BLE_BCS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save the handle to support a service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bcscReqHandle[discIdx] = cy_ble_bcsc[discIdx].bodyCompositionMeasurementCccdHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - -#endif /* CY_BLE_BCS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_BCS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Body Composition Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BCS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_BCS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_BCSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_BCSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_BCSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_BCS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_BCS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_BCSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_BCSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_BCS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_BCS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_BCSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_BCSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_BCSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_BCSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_BCS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} -#endif /* defined(CY_BLE_BCS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bcs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bcs.h deleted file mode 100644 index c2ab56d267..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bcs.h +++ /dev/null @@ -1,208 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bcs.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Body Composition Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -/** - * \addtogroup group_ble_service_api_BCS_definitions - * @{ - */ - - -#ifndef CY_BLE_BCS_H -#define CY_BLE_BCS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BCS)) - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - - -/*************************************** -* Data Types -***************************************/ - -/** BCS Characteristic indexes */ -typedef enum -{ - CY_BLE_BCS_BODY_COMPOSITION_FEATURE, /**< Body Composition Feature Characteristic index */ - CY_BLE_BCS_BODY_COMPOSITION_MEASUREMENT, /**< Body Composition Measurement Characteristic index */ - CY_BLE_BCS_CHAR_COUNT /**< Total count of BCS Characteristics */ -}cy_en_ble_bcs_char_index_t; - -/** BCS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_BCS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_BCS_DESCR_COUNT /**< Total count of Descriptors */ -}cy_en_ble_bcs_descr_index_t; - -/** BCS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bcs_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_bcs_char_value_t; - -/** BCS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bcs_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_bcs_descr_index_t descrIndex; /**< Index of descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_bcs_descr_value_t; - -/** Structure with Body Composition Service attribute handles */ -typedef struct -{ - /** Handle of Characteristic Value */ - cy_ble_gatt_db_attr_handle_t charHandle; - /** Array of Descriptor handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_BCS_DESCR_COUNT]; -} cy_stc_ble_bcss_char_t; - -/** BCS Characteristic with descriptors handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Body Composition Service handle */ - cy_stc_ble_bcss_char_t charInfo[CY_BLE_BCS_CHAR_COUNT]; /**< Array of characteristics and descriptors handles */ -} cy_stc_ble_bcss_t; - -/** BCS Client Characteristic structure type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - uint8_t properties; /**< Properties for value field */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of a characteristic */ -} cy_stc_ble_bcsc_char_t; - -/** BCS Characteristic with descriptors */ -typedef struct -{ - /** Body Composition Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Body Composition Service characteristics info structure */ - cy_stc_ble_bcsc_char_t charInfo[CY_BLE_BCS_CHAR_COUNT]; - - /** Body Composition Measurement Client Characteristic Configuration handle */ - cy_ble_gatt_db_attr_handle_t bodyCompositionMeasurementCccdHandle; -} cy_stc_ble_bcsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Body Composition Service GATT DB handles structure */ - const cy_stc_ble_bcss_t *bcss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_bcs_config_t; - -/*************************************** -* API Constants -***************************************/ - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_BCS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_BCS_Init(cy_stc_ble_bcs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_BCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_BCS_SERVER -/** - * \addtogroup group_ble_service_api_BCS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BCSS_SetCharacteristicValue(cy_en_ble_bcs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BCSS_GetCharacteristicValue(cy_en_ble_bcs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BCSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BCSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_BCS_SERVER */ - -#ifdef CY_BLE_BCS_CLIENT -/** - * \addtogroup group_ble_service_api_BCS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_BCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t - descrIndex, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bcs_char_index_t charIndex, - cy_en_ble_bcs_descr_index_t - descrIndex); - -/** @} */ -#endif /* CY_BLE_BCS_CLIENT */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_BCS_CLIENT -extern cy_stc_ble_bcsc_t cy_ble_bcsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_BCS_CLIENT */ - -extern cy_stc_ble_bcs_config_t cy_ble_bcsConfig; -extern cy_stc_ble_bcs_config_t *cy_ble_bcsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_BCS) */ -#endif /* CY_BLE_ANCS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bls.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bls.c deleted file mode 100644 index 8527cec0db..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bls.c +++ /dev/null @@ -1,1318 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bls.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Blood Pressure Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BLS)) - -static cy_ble_callback_t Cy_BLE_BLS_ApplCallback; - -#ifdef CY_BLE_BLS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_blssReqHandle; -#endif /* CY_BLE_BLS_SERVER */ - -#ifdef CY_BLE_BLS_CLIENT -/* Server's Blood Pressure Service characteristics GATT DB handles structure */ -cy_stc_ble_blsc_t cy_ble_blsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_blscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_BLS_CLIENT */ - -/* The pointer to the global BLE BLS config structure */ -cy_stc_ble_bls_config_t *cy_ble_blsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_BLS_SERVER -static void Cy_BLE_BLSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_BLSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_BLS_SERVER */ - -#ifdef CY_BLE_BLS_CLIENT -static void Cy_BLE_BLSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_BLSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_BLSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_BLSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_BLSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_BLSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_BLSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_BLSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_BLS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_BLS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_BLS_Init -***************************************************************************//** -* -* This function initializes the BLS Service. -* -* \param config: The configuration structure for the Blood Pressure Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLS_Init(cy_stc_ble_bls_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to the config structure */ - cy_ble_blsConfigPtr = config; - - /* Registers Event Handler for the BLS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_BLS_EventHandler); - - /* Registers a callback function via the config structure */ - if(cy_ble_blsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_BLS_ApplCallback = cy_ble_blsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_BLS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_BLS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_blsc[idx], 0, sizeof(cy_stc_ble_blsc_t)); - - /* Initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_BLS].uuid = CY_BLE_UUID_BLOOD_PRESSURE_SERVICE; - } - cy_ble_blscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific Write requests from the peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for Blood Pressure Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_BASS_NOTIFICATION_ENABLED) -* * eventParam contains the parameters corresponding to the -* current event (e.g. the pointer to the cy_stc_ble_bls_char_value_t -* structure that contains details of the characteristic -* the CY_BLE_EVT_BLSS_NOTIFICATION_ENABLED event triggered for). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_BLS_ApplCallback = callbackFunc; - if(cy_ble_blsConfigPtr != NULL) - { - cy_ble_blsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_BLS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a value of the characteristic which is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSS_SetCharacteristicValue(cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_BLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store the characteristic value into the GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the Blood Pressure Service identified by -* charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSS_GetCharacteristicValue(cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - /* Check the parameters */ - if(charIndex >= CY_BLE_BLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get the characteristic value from the GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the Blood -* Pressure Service from the local GATT database. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where the characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional descriptor is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - cy_en_ble_bls_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - /* Check the parameters */ - if((charIndex >= CY_BLE_BLS_CHAR_COUNT) || (descrIndex >= CY_BLE_BLS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsConfigPtr->blss->charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from the database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_blsConfigPtr->blss->charInfo[charIndex].cccdHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_SendNotification -***************************************************************************//** -* -* Sends notification of the specified characteristic to the Client device. -* -* On enabling notification successfully for a service characteristic it sends out a -* Handle Value Notification which results in CY_BLE_EVT_BLSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consists of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed . -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the Client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_BLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_blsConfigPtr->blss->charInfo[charIndex].cccdHandle)) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of Write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfParam = - { - .handleValPair.attrHandle = cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to the Client using a previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_SendIndication -***************************************************************************//** -* -* Sends an indication of the specified characteristic to the Client device. -* -* On enabling indication successfully it sends out a Handle Value Indication which -* results in a CY_BLE_EVT_BLSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if the -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle which consists of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the Client. -* -* \events -* If execution is successful(return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BLS service-specific callback is registered -* (with Cy_BLE_BLS_RegisterAttrCallback): -* * CY_BLE_EVT_BLSS_INDICATION_CONFIRMED - if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if a BLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_BLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charIndex != CY_BLE_BLS_BPM) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_blsConfigPtr->blss->charInfo[charIndex].cccdHandle)) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of the Write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indParam = - { - .handleValPair.attrHandle = cy_ble_blsConfigPtr->blss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to the Client using a previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indParam); - - /* Save the handle to support a service-specific value confirmation response from the Client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_blssReqHandle = indParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* \param eventParam - The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_BLSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_BLS_ApplCallback != NULL) && - (cy_ble_blsConfigPtr->blss->charInfo[CY_BLE_BLS_BPM].charHandle == cy_ble_blssReqHandle)) - { - cy_stc_ble_bls_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_BLS_BPM, - .value = NULL - }; - cy_ble_blssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BLS_ApplCallback((uint32_t)CY_BLE_EVT_BLSS_INDICATION_CONFIRMED, &locCharIndex); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - The function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or GATT error codes -* returned by Cy_BLE_GATTS_WriteAttributeValueCCCD(). -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BLSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(Cy_BLE_BLS_ApplCallback != NULL) - { - cy_stc_ble_bls_char_value_t locCharIndex; - locCharIndex.connHandle = eventParam->connHandle; - locCharIndex.value = NULL; - - for(locCharIndex.charIndex = CY_BLE_BLS_BPM; locCharIndex.charIndex < CY_BLE_BLS_BPF; locCharIndex.charIndex++) - { - if(eventParam->handleValPair.attrHandle == cy_ble_blsConfigPtr->blss->charInfo[locCharIndex.charIndex]. - cccdHandle) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - uint32_t eventCode; - - if(locCharIndex.charIndex == CY_BLE_BLS_ICP) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_BLSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_BLSS_NOTIFICATION_DISABLED; - } - } - else - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_BLSS_INDICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_BLSS_INDICATION_DISABLED; - } - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set a flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - Cy_BLE_BLS_ApplCallback(eventCode, &locCharIndex); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - - return(gattErr); -} - -#endif /* CY_BLE_BLS_SERVER */ - -#ifdef CY_BLE_BLS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic value from the Server -* identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* -* \events -* If execution is successful(return value = CY_BLE_SUCCESS) -* these events can appear: \n -* If a BLS service specific callback is registered -* (with Cy_BLE_BLS_RegisterAttrCallback): -* * CY_BLE_EVT_BLSC_READ_CHAR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bls_char_value_t. -* . -* Otherwise (if a BLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BLS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_blsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_blsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_blscReqHandle[discIdx] = cy_ble_blsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to set the characteristic descriptor of the specified Blood Pressure -* Service characteristic to the Server device. -* -* Internally, a Write Request is sent to the GATT Server and on successful -* execution of the request on the Server's side the following events can be -* generated: -* * CY_BLE_EVT_BLSS_INDICATION_ENABLED -* * CY_BLE_EVT_BLSS_INDICATION_DISABLED -* * CY_BLE_EVT_BLSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_BLSS_NOTIFICATION_DISABLED -* -* \param connHandle: The BLE peer device connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that should -* be sent to the Server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful(return value = CY_BLE_SUCCESS), -* the next events can appear: \n -* If a BLS service-specific callback is registered -* (with Cy_BLE_BLS_RegisterAttrCallback): -* * CY_BLE_EVT_BLSC_WRITE_DESCR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bls_descr_value_t. -* . -* Otherwise (if the BLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - cy_en_ble_bls_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BLS_CHAR_COUNT) || (descrIndex >= CY_BLE_BLS_DESCR_COUNT) - || (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsc[discIdx].charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of a write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_blsc[discIdx].charInfo[charIndex].cccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - /* ... and send a request to the Server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save the handle to support a service-specific Read response from the device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_blscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified Blood Pressure -* Service characteristic from the Server device. This function call can result -* in the generation of the following events based on the response from the server -* device: -* * CY_BLE_EVT_BLSC_READ_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The BLE peer device connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BLS service-specific callback is registered -* (with Cy_BLE_BLS_RegisterAttrCallback): -* * CY_BLE_EVT_BLSC_READ_DESCR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_bls_descr_value_t. -* . -* Otherwise (if a BLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BLSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - cy_en_ble_bls_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BLS_CHAR_COUNT) || (descrIndex >= CY_BLE_BLS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_blsc[discIdx].charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_blsc[discIdx].charInfo[charIndex].cccdHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_blscReqHandle[discIdx] = cy_ble_blsc[discIdx].charInfo[charIndex].cccdHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, the appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_BLSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* Blood Pressure Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_blscCharUuid[CY_BLE_BLS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_BP_MSRMT, - CY_BLE_UUID_CHAR_INTRMDT_CUFF_PRSR, - CY_BLE_UUID_CHAR_BP_FEATURE - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BLS)) - { - /* Update the last characteristic endHandle to the declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_BLS_CHAR_COUNT; i++) - { - if(cy_ble_blscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_blsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_blsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_blsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_blsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initialize the characteristic endHandle to the Service endHandle. - * The characteristic endHandle will be updated to the declaration - * handle of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_BLS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, the appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_BLSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BLS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if(cy_ble_blsc[discIdx].charInfo[charIdx].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_blsc[discIdx].charInfo[charIdx].cccdHandle = discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_BLSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BLS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_BLS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_blsc[discIdx].charInfo[charIdx].endHandle - cy_ble_blsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_blsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_blsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_NotificationEventHandler -***************************************************************************//** -* -* Handles a Notification event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BLSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BLS_ApplCallback != NULL) && - (cy_ble_blsc[discIdx].charInfo[CY_BLE_BLS_ICP].valueHandle == eventParam->handleValPair.attrHandle)) - { - cy_stc_ble_bls_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BLS_ICP, - .value = &eventParam->handleValPair.value - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BLS_ApplCallback((uint32_t)CY_BLE_EVT_BLSC_NOTIFICATION, &locCharValue); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an Indication event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BLSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BLS_ApplCallback != NULL) && - (cy_ble_blsc[discIdx].charInfo[CY_BLE_BLS_BPM].valueHandle == eventParam->handleValPair.attrHandle)) - { - cy_stc_ble_bls_char_value_t locCharValue = - { - .charIndex = CY_BLE_BLS_BPM, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BLS_ApplCallback((uint32_t)CY_BLE_EVT_BLSC_INDICATION, &locCharValue); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event. -* -* \param cy_stc_ble_gattc_read_rsp_param_t *eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_BLSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BLS_ApplCallback != NULL) && - (cy_ble_blscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_blsc[discIdx].charInfo[CY_BLE_BLS_BPF].valueHandle == cy_ble_blscReqHandle[discIdx]) - { - cy_stc_ble_bls_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BLS_BPF, - .value = &eventParam->value - }; - cy_ble_blscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BLS_ApplCallback((uint32_t)CY_BLE_EVT_BLSC_READ_CHAR_RESPONSE, &locCharValue); - } - else - { - cy_en_ble_bls_char_index_t i; - - for(i = CY_BLE_BLS_BPM; i < CY_BLE_BLS_BPF; i++) - { - if(cy_ble_blsc[discIdx].charInfo[i].cccdHandle == cy_ble_blscReqHandle[discIdx]) - { - cy_stc_ble_bls_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = i, - .descrIndex = CY_BLE_BLS_CCCD, - .value = &eventParam->value - }; - cy_ble_blscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BLS_ApplCallback((uint32_t)CY_BLE_EVT_BLSC_READ_DESCR_RESPONSE, &locDescrValue); - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BLSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BLS_ApplCallback != NULL) && - (cy_ble_blscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_bls_char_index_t i; - for(i = CY_BLE_BLS_BPM; i < CY_BLE_BLS_BPF; i++) - { - if(cy_ble_blsc[discIdx].charInfo[i].cccdHandle == cy_ble_blscReqHandle[discIdx]) - { - cy_stc_ble_bls_descr_value_t locDescIndex = - { - .connHandle = *eventParam, - .charIndex = i, - .descrIndex = CY_BLE_BLS_CCCD, - .value = NULL - }; - cy_ble_blscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BLS_ApplCallback((uint32_t)CY_BLE_EVT_BLSC_WRITE_DESCR_RESPONSE, &locDescIndex); - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BLSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BLSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_blscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_blscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -#endif /* CY_BLE_BLS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_BLSS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Blood Pressure Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BLS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_BLS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_BLSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_BLSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_BLSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_BLS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_BLS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_BLSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_BLSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_BLS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_BLS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_BLSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_BLSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_BLSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_BLSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_BLSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_BLS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_BLS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bls.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bls.h deleted file mode 100644 index fcc54a3caa..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bls.h +++ /dev/null @@ -1,229 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bls.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Blood Pressure Profile of the BLE Component. -* -******************************************************************************** -* \copyright -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -/** - * \addtogroup group_ble_service_api_BLS_definitions - * @{ - */ - - -#ifndef CY_BLE_BLS_H -#define CY_BLE_BLS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BLS)) - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Data Types -***************************************/ - -/** Service Characteristics indexes */ -typedef enum -{ - CY_BLE_BLS_BPM, /**< Blood Pressure Measurement characteristic index */ - CY_BLE_BLS_ICP, /**< Intermediate Cuff Pressure Context characteristic index */ - CY_BLE_BLS_BPF, /**< Blood Pressure Feature characteristic index */ - CY_BLE_BLS_CHAR_COUNT /**< Total count of BLS characteristics */ -}cy_en_ble_bls_char_index_t; - -/** Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_BLS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_BLS_DESCR_COUNT /**< Total count of BLS descriptors */ -}cy_en_ble_bls_descr_index_t; - -/** Characteristic with descriptors */ -typedef struct -{ - /** Blood Pressure Service characteristic's handle */ - cy_ble_gatt_db_attr_handle_t charHandle; - - /** Blood Pressure Service characteristic descriptor's handle */ - cy_ble_gatt_db_attr_handle_t cccdHandle; -}cy_stc_ble_blss_char_t; - -/** Structure with Blood Pressure Service attribute handles */ -typedef struct -{ - /** Blood Pressure Service handle*/ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Array of Blood Pressure Service characteristics + descriptors handles */ - cy_stc_ble_blss_char_t charInfo[CY_BLE_BLS_CHAR_COUNT]; -} cy_stc_ble_blss_t; - -/** Blood Pressure Client Server's characteristic structure type */ -typedef struct -{ - /** Properties for the value field */ - uint8_t properties; - - /** Handle of Server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** Blood Pressure Client characteristic config descriptor's handle */ - cy_ble_gatt_db_attr_handle_t cccdHandle; - - /** Characteristic's end handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_blsc_char_t; - -/** Structure with discovered attributes information of Blood Pressure Service */ -typedef struct -{ - /** Structure with characteristic handles + properties of Blood Pressure Service */ - cy_stc_ble_blsc_char_t charInfo[CY_BLE_BLS_CHAR_COUNT]; -}cy_stc_ble_blsc_t; - -/** Blood Pressure Service characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bls_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_bls_char_value_t; - -/** Blood Pressure Service characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bls_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_bls_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_bls_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Blood Pressure Service GATT DB handles structure */ - const cy_stc_ble_blss_t *blss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_bls_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_BLS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_BLS_Init(cy_stc_ble_bls_config_t *config); -cy_en_ble_api_result_t Cy_BLE_BLS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_BLS_SERVER -/** - * \addtogroup group_ble_service_api_BLS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BLSS_SetCharacteristicValue(cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BLSS_GetCharacteristicValue(cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BLSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - cy_en_ble_bls_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BLSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BLSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); -/** @} */ -#endif /* CY_BLE_BLS_SERVER */ - -#ifdef CY_BLE_BLS_CLIENT -/** - * \addtogroup group_ble_service_api_BLS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BLSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_BLSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - cy_en_ble_bls_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BLSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bls_char_index_t charIndex, - cy_en_ble_bls_descr_index_t descrIndex); -/** @} */ -#endif /* CY_BLE_BLS_CLIENT */ - - -/*************************************** -* Internal macros -***************************************/ - -#ifdef CY_BLE_BLS_SERVER -#define CY_BLE_BLS_IS_ICP_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_blsConfigPtr->blss->charInfo[CY_BLE_BLS_ICP].charHandle) -#endif /* CY_BLE_BLS_SERVER */ - -/* ##Macro Functions */ - -#ifdef CY_BLE_BLS_CLIENT -#define Cy_BLE_BLSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_BLS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_blsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_BLSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_BLS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_BLS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_blsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].cccdHandle) -#endif /* CY_BLE_BLS_CLIENT */ - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_BLS_CLIENT -/* Blood Pressure Service Server's GATT DB handles structure */ -extern cy_stc_ble_blsc_t cy_ble_blsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_BLS_CLIENT */ -extern cy_stc_ble_bls_config_t cy_ble_blsConfig; -extern cy_stc_ble_bls_config_t *cy_ble_blsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_BLS) */ -#endif /* CY_BLE_BLS_H */ - - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bms.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bms.c deleted file mode 100644 index f79e26390e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bms.c +++ /dev/null @@ -1,1362 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bms.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Bond Management Service -* of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BMS)) - -static cy_ble_callback_t Cy_BLE_BMS_ApplCallback; - -#ifdef CY_BLE_BMS_CLIENT -/* BMS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_bmsc_t cy_ble_bmsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_bmscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_BMS_CLIENT */ - -/* The pointer to the global BLE BMS config structure */ -cy_stc_ble_bms_config_t *cy_ble_bmsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_BMS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_BMSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_BMSS_PrepareWriteRequestEventHandler(cy_stc_ble_gatts_prep_write_req_param_t *eventParam); -static void Cy_BLE_BMSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam); -#endif /* CY_BLE_BMS_SERVER */ - -#ifdef CY_BLE_BMS_CLIENT -static void Cy_BLE_BMSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_BMSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_BMSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_BMSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_BMSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_BMSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_BMSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam); -#endif /* CY_BLE_BMS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_BMS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_BMS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: The configuration structure for the Bond Management Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMS_Init(cy_stc_ble_bms_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to the config structure */ - cy_ble_bmsConfigPtr = config; - - /* Registers Event Handler for the BMS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_BMS_EventHandler); - - /* Registers a callback function via the config structure */ - if(cy_ble_bmsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_BMS_ApplCallback = cy_ble_bmsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_BMS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_BMS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_bmsc[idx], 0, sizeof(cy_stc_ble_bmsc_t)); - - /* Initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_BMS].uuid = CY_BLE_UUID_BOND_MANAGEMENT_SERVICE; - } - cy_ble_bmscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific Write requests from the peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for BM Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \sideeffect The *eventParams in the callback function should not be used -* by the application once the callback function execution is -* finished. Otherwise, this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_BMS_ApplCallback = callbackFunc; - if(cy_ble_bmsConfigPtr != NULL) - { - cy_ble_bmsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - -#ifdef CY_BLE_BMS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSS_SetCharacteristicValue(cy_en_ble_bms_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_BMS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bmsConfigPtr->bmss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store a characteristic value into the GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_bmsConfigPtr->bmss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the service identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where Characteristic value data should -* be stored. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSS_GetCharacteristicValue(cy_en_ble_bms_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_BMS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bmsConfigPtr->bmss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get the characteristic value from the GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_bmsConfigPtr->bmss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets a characteristic descriptor of the specified characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_bms_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_bms_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data that should -* be stored to the GATT database. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - cy_en_ble_bms_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_BMS_CHAR_COUNT) || (descrIndex >= CY_BLE_BMS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_bmsConfigPtr->bmss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_bms_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_bms_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - cy_en_ble_bms_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_BMS_CHAR_COUNT) || (descrIndex >= CY_BLE_BMS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_bmsConfigPtr->bmss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request event. Calls the registered BMS application -* callback function. -* -* Note: Writing an attribute into GATT DB (if needed) is the user's responsibility -* after the Authorization Code check in the registered BMS application -* callback function. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATT_ERR_OP_CODE_NOT_SUPPORTED -* * CY_BLE_GATT_ERR_INSUFFICIENT_AUTHORIZATION -* -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BMSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_bms_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .gattErrorCode = CY_BLE_GATT_ERR_NONE - }; - - if((Cy_BLE_BMS_ApplCallback != NULL) && - (eventParam->handleValPair.attrHandle == cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP].charHandle)) - { - locCharValue.gattErrorCode = - Cy_BLE_GATT_DbCheckPermission(eventParam->handleValPair.attrHandle, &eventParam->connHandle, - CY_BLE_GATT_DB_WRITE | CY_BLE_GATT_DB_PEER_INITIATED); - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - locCharValue.charIndex = CY_BLE_BMS_BMCP; - locCharValue.value = &eventParam->handleValPair.value; - - Cy_BLE_BMS_ApplCallback((uint32_t)CY_BLE_EVT_BMSS_WRITE_CHAR, &locCharValue); - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - locCharValue.gattErrorCode = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP].charHandle, - locCharValue.value->len); - } - } - } - - /* Indicate that the request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - return(locCharValue.gattErrorCode); -} - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_PrepareWriteEventHandler -***************************************************************************//** -* -* Handles a Prepare Write Request event. -* -* \param cy_stc_ble_gatts_prep_write_req_param_t *eventParam: The pointer to the data that -* came with a Prepare Write -* request. -* -******************************************************************************/ -static void Cy_BLE_BMSS_PrepareWriteRequestEventHandler(cy_stc_ble_gatts_prep_write_req_param_t *eventParam) -{ - if(eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP].charHandle) - { - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = eventParam->connHandle }; - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - - if(((cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP].descrHandle[CY_BLE_BMS_CEPD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) && - CY_BLE_IS_RELIABLE_WRITE_ENABLED(cy_ble_bmsConfigPtr->bmss-> - charInfo[CY_BLE_BMS_BMCP].descrHandle[CY_BLE_BMS_CEPD])) || - (CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP].charHandle) > - (mtuParam.mtu - CY_BLE_GATT_WRITE_HEADER_LEN))) - { - /* The first prepare write event */ - } - else - { - eventParam->gattErrorCode = (uint8_t)CY_BLE_GATT_ERR_ATTRIBUTE_NOT_LONG; - } - - - /* Indicate that the request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BMSS_ExecuteWriteRequestEventHandler -***************************************************************************//** -* -* Handles an Execute Write Request event. -* -* \param cy_stc_ble_gatts_exec_write_req_t *eventParam: The pointer to the data that came -* with a Write request. -* -******************************************************************************/ -static void Cy_BLE_BMSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam) -{ - uint32_t locCount; - cy_stc_ble_gatt_value_t locGattValue = { .len = 0u, .val = NULL }; - - for(locCount = 0u; locCount < eventParam->prepWriteReqCount; locCount++) - { - if(eventParam->baseAddr[locCount].handleValuePair.attrHandle == - cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP].charHandle) - { - locGattValue.len = eventParam->baseAddr[locCount].offset + eventParam->baseAddr[locCount]. - handleValuePair.value.len; - - if(locGattValue.val == NULL) - { - locGattValue.val = eventParam->baseAddr[locCount].handleValuePair.value.val; - } - else if(eventParam->baseAddr[locCount].offset == 0u) - { - /* The case when the Client wants to rewrite the value from the start */ - locGattValue.val = eventParam->baseAddr[locCount].handleValuePair.value.val; - } - else - { - /* Do nothing */ - } - } - } - - if((Cy_BLE_BMS_ApplCallback != NULL) && (locGattValue.len != 0u) && - (locGattValue.len <= CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_bmsConfigPtr->bmss->charInfo[CY_BLE_BMS_BMCP]. - charHandle))) - { - /* Check the execWriteFlag before executing or cancelling the Write Long operation */ - if(eventParam->execWriteFlag == CY_BLE_GATT_EXECUTE_WRITE_EXEC_FLAG) - { - cy_stc_ble_bms_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - locCharValue.gattErrorCode = CY_BLE_GATT_ERR_NONE; - locCharValue.value = &locGattValue; - - Cy_BLE_BMS_ApplCallback((uint32_t)CY_BLE_EVT_BMSS_WRITE_CHAR, &locCharValue); - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_bmsConfigPtr->bmss-> - charInfo[CY_BLE_BMS_BMCP].charHandle, locGattValue.len); - } - - eventParam->gattErrorCode = (uint8_t)locCharValue.gattErrorCode; - } - - /* Indicate that the request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -#endif /* CY_BLE_BMS_SERVER */ - -#ifdef CY_BLE_BMS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic value from a Server -* identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the Service characteristic. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* -* \events -* If execution is successful(return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BMS service-specific callback is registered -* (with Cy_BLE_BMS_RegisterAttrCallback): -* * CY_BLE_EVT_BMSC_READ_CHAR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bms_char_value_t. -* . -* Otherwise (if a BMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex != CY_BLE_BMS_BMFT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bmsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_bmsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMFT].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bmscReqHandle[discIdx] = cy_ble_bmsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write a characteristic (identified by -* charIndex) value attribute to the Server. The function supports the Write Long -* procedure - it depends on the attrSize parameter - if it is larger than the -* current MTU size - 1, then the Write Long will be executed. -* As a result, a Write request is sent to the GATT Server and on successful -* execution of the request on the Server's side, a CY_BLE_EVT_BMSS_WRITE_CHAR -* events is generated. -* On successful request execution on the Server's side, a Write response is -* sent to the Client. -* -* The Write response only confirms the operation success. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Server device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* -* \events -* If execution is successful(return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BMS service-specific callback is registered -* (with Cy_BLE_BMS_RegisterAttrCallback): -* * CY_BLE_EVT_BMSC_WRITE_CHAR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bms_char_value_t. -* . -* Otherwise (if a BMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_EXEC_WRITE_RSP - if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - there is some trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = connHandle }; - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex != CY_BLE_BMS_BMCP) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if((mtuParam.mtu - CY_BLE_GATT_WRITE_HEADER_LEN) < attrSize) - { - cy_stc_ble_gattc_prep_write_req_t prepWriteReqParam = - { - .handleValOffsetPair.handleValuePair.attrHandle = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle, - .handleValOffsetPair.handleValuePair.value.val = attrValue, - .handleValOffsetPair.handleValuePair.value.len = attrSize, - .handleValOffsetPair.offset = 0u, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteLongCharacteristicValues(&prepWriteReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bmscReqHandle[discIdx] = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle; - } - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bmscReqHandle[discIdx] = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_ReliableWriteCharacteristicValue -***************************************************************************//** -* -* Performs a Reliable Write command for the -* Bond Management Control Point characteristic (identified by -* charIndex) value attribute to the Server. -* -* The Write response only confirms the operation success. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Server device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - The operation is invalid for this -* characteristic. -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BMS service specific callback is registered -* (with Cy_BLE_BMS_RegisterAttrCallback): -* * CY_BLE_EVT_BMSC_WRITE_CHAR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_bms_char_value_t. -* . -* Otherwise (if a BMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_EXEC_WRITE_RSP - if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSC_ReliableWriteCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex != CY_BLE_BMS_BMCP) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_EXTENDED_PROPERTIES & cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_reliable_write_req_t prepWriteReqParam = { .connHandle = connHandle }; - cy_stc_ble_gatt_handle_value_offset_param_t handleValOffsetPairParam = - { - .handleValuePair.attrHandle = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle, - .handleValuePair.value.val = attrValue, - .handleValuePair.value.len = attrSize, - .offset = 0u - }; - - prepWriteReqParam.handleValOffsetPair = &handleValOffsetPairParam; - prepWriteReqParam.numOfRequests = 1u; - - apiResult = Cy_BLE_GATTC_ReliableWrites(&prepWriteReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bmscReqHandle[discIdx] = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* If execution is successful (return value = CY_BLE_SUCCESS), -* these events can appear: \n -* If a BMS service-specific callback is registered -* (with Cy_BLE_BMS_RegisterAttrCallback): -* * CY_BLE_EVT_BMSC_READ_DESCR_RESPONSE - if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_bms_descr_value_t. -* . -* Otherwise (if a BMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with the event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - if there is trouble with the -* requested attribute on the peer device, -* the details are provided with the event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BMSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - cy_en_ble_bms_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_BMS_CHAR_COUNT) || (descrIndex >= CY_BLE_BMS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].descrHandle[CY_BLE_BMS_CEPD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].descrHandle[CY_BLE_BMS_CEPD], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_bmscReqHandle[discIdx] = cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].descrHandle[CY_BLE_BMS_CEPD]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_BMSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* BM Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_bmscCharUuid[CY_BLE_BMS_CHAR_COUNT] = - { - CY_BLE_UUID_BOND_MANAGEMENT_CONTROL_POINT, - CY_BLE_UUID_BOND_MANAGEMENT_FEATURE - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BMS)) - { - /* Update the last characteristic endHandle to the declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint8_t)CY_BLE_BMS_CHAR_COUNT; i++) - { - if(cy_ble_bmscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_bmsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_bmsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_bmsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_bmsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initialize the characteristic endHandle to Service endHandle. - * the characteristic endHandle will be updated to the declaration - * handle of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_BMS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, the appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_BMSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BMS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_EXTENDED_PROPERTIES: - descIdx = (uint32_t)CY_BLE_BMS_CEPD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_bmsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_bmsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_BMSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_BMS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_BMS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_bmsc[discIdx].charInfo[charIdx].endHandle - cy_ble_bmsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_bmsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_bmsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event. -* -* \param eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_BMSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BMS_ApplCallback != NULL) && - (cy_ble_bmscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMFT].valueHandle == cy_ble_bmscReqHandle[discIdx]) - { - cy_stc_ble_bms_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BMS_BMFT, - .value = &eventParam->value - }; - cy_ble_bmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BMS_ApplCallback((uint32_t)CY_BLE_EVT_BMSC_READ_CHAR_RESPONSE, &locCharValue); - } - else if(cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].descrHandle[CY_BLE_BMS_CEPD] == - cy_ble_bmscReqHandle[discIdx]) - { - cy_stc_ble_bms_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BMS_BMCP, - .descrIndex = CY_BLE_BMS_CEPD, - .value = &eventParam->value, - }; - cy_ble_bmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BMS_ApplCallback((uint32_t)CY_BLE_EVT_BMSC_READ_DESCR_RESPONSE, &locDescrValue); - } - else - { - /* Do nothing */ - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BMSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BMS_ApplCallback != NULL) && - (cy_ble_bmscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle == cy_ble_bmscReqHandle[discIdx]) - { - cy_stc_ble_bms_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_BMS_BMCP, - .value = NULL - }; - cy_ble_bmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BMS_ApplCallback((uint32_t)CY_BLE_EVT_BMSC_WRITE_CHAR_RESPONSE, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_ExecuteWriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BMSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_BMS_ApplCallback != NULL) && - (cy_ble_bmsc[discIdx].charInfo[CY_BLE_BMS_BMCP].valueHandle == cy_ble_bmscReqHandle[discIdx])) - { - cy_stc_ble_bms_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_BMS_BMCP, - .value = NULL - }; - cy_ble_bmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_BMS_ApplCallback((uint32_t)CY_BLE_EVT_BMSC_WRITE_CHAR_RESPONSE, &locCharValue); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BMSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_BMSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_bmscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_bmscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} -#endif /* CY_BLE_BMS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_BMS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Bond Management Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BMS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_BMS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_BMSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_BMSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_BMSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_BMS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_BMS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_BMSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - Cy_BLE_BMSS_PrepareWriteRequestEventHandler((cy_stc_ble_gatts_prep_write_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - Cy_BLE_BMSS_ExecuteWriteRequestEventHandler((cy_stc_ble_gatts_exec_write_req_t*)eventParam); - break; - #endif /* CY_BLE_BMS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_BMS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_BMSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_BMSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_BMSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_EXEC_WRITE_RSP: - Cy_BLE_BMSC_ExecuteWriteResponseEventHandler((cy_stc_ble_gattc_exec_write_rsp_t*)eventParam); - break; - #endif /* CY_BLE_BMS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} -#endif /* defined(CY_BLE_BMS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bms.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bms.h deleted file mode 100644 index 27a9ebce3c..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bms.h +++ /dev/null @@ -1,223 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bms.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in the -* Bond Management Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_BMS_H -#define CY_BLE_BMS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BMS)) - -/* The C binding of definitions if building with the C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_BMS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Service Characteristics indexes */ -typedef enum -{ - CY_BLE_BMS_BMCP, /**< Bond Management Control Point characteristic index */ - CY_BLE_BMS_BMFT, /**< Bond Management Feature characteristic index */ - CY_BLE_BMS_CHAR_COUNT /**< Total count of BMS characteristics */ -}cy_en_ble_bms_char_index_t; - -/** Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_BMS_CEPD, /**< Characteristic Extended Properties descriptor index */ - CY_BLE_BMS_DESCR_COUNT /**< Total count of BMS descriptors */ -}cy_en_ble_bms_descr_index_t; - -/** Characteristic with descriptors type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of Characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_BMS_DESCR_COUNT]; /**< Handles of Descriptors */ -} cy_stc_ble_bmss_char_t; - -/** Structure with Service attribute handles */ -typedef struct -{ - /** Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Service characteristics info array */ - cy_stc_ble_bmss_char_t charInfo[CY_BLE_BMS_CHAR_COUNT]; -} cy_stc_ble_bmss_t; - -/** Client Characteristic structure type */ -typedef struct -{ - /** Properties for the value field */ - uint8_t properties; - - /** Handle of Server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** Characteristics descriptors handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_BMS_DESCR_COUNT]; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_bmsc_char_t; - -/** Service structure type */ -typedef struct -{ - /** Characteristics handle + properties array */ - cy_stc_ble_bmsc_char_t charInfo[CY_BLE_BMS_CHAR_COUNT]; -}cy_stc_ble_bmsc_t; - -/** Service Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bms_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for checking the authorization code */ -} cy_stc_ble_bms_char_value_t; - -/** Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bms_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_bms_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_bms_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Bond Management Service GATT DB handles structure */ - const cy_stc_ble_bmss_t *bmss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_bms_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -/** Bond Management Control Point characteristic supports Op Codes */ -#define CY_BLE_BMS_BMCP_OPC_RD (0x03u) /* Delete bond of requesting device (LE transport only). */ -#define CY_BLE_BMS_BMCP_OPC_AB (0x06u) /* Delete all bonds on server (LE transport only). */ -#define CY_BLE_BMS_BMCP_OPC_BA (0x09u) /* Delete all but the active bond on server (LE transport only). */ - -/** Bond Management Control Point characteristic supports Op Codes */ -#define CY_BLE_BMS_BMFT_RD (0x00000010u) /** Delete bond of current connection (LE transport only) supported. */ -#define CY_BLE_BMS_BMFT_RC (0x00000020u) /** Authorization Code required for feature above. */ -#define CY_BLE_BMS_BMFT_AB (0x00000400u) /** Remove all bonds on server (LE transport only) supported. */ -#define CY_BLE_BMS_BMFT_AC (0x00000800u) /** Authorization Code required for feature above. */ -#define CY_BLE_BMS_BMFT_BA (0x00010000u) /** Remove all but the active bond on server (LE transport only) supported. */ -#define CY_BLE_BMS_BMFT_BC (0x00020000u) /** Authorization Code required for feature above. */ - -#define CY_BLE_BMS_FLAG_LW (0x01u) /** Long Write Procedure */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_BMS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_BMS_Init(cy_stc_ble_bms_config_t *config); -cy_en_ble_api_result_t Cy_BLE_BMS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_BMS_SERVER -/** - * \addtogroup group_ble_service_api_BMS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BMSS_SetCharacteristicValue(cy_en_ble_bms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BMSS_GetCharacteristicValue(cy_en_ble_bms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BMSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - cy_en_ble_bms_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BMSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - cy_en_ble_bms_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); -/** @} */ -#endif /* CY_BLE_BMS_SERVER */ - -#ifdef CY_BLE_BMS_CLIENT -/** - * \addtogroup group_ble_service_api_BMS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_BMSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_BMSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BMSC_ReliableWriteCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BMSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bms_char_index_t charIndex, - cy_en_ble_bms_descr_index_t - descrIndex); - -/** @} */ -#endif /* CY_BLE_BMS_CLIENT */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_BMS_CLIENT -/* CGM Service server's GATT DB handles structure */ -extern cy_stc_ble_bmsc_t cy_ble_bmsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_BMS_CLIENT */ - -extern cy_stc_ble_bms_config_t cy_ble_bmsConfig; -extern cy_stc_ble_bms_config_t *cy_ble_bmsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_BMS) */ -#endif /* CY_BLE_BMS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bts.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bts.c deleted file mode 100644 index 11cf5e9a74..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bts.c +++ /dev/null @@ -1,509 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bts.c -* \version 2.0 -* -* \brief -* Contains the source code for the Bootloader service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" -#include "cy_ble_hal_pvt.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BTS)) -static cy_ble_callback_t Cy_BLE_BTS_ApplCallback; - -/* The pointer on global BLE BTS Config structure */ -cy_stc_ble_bts_config_t *cy_ble_btsConfigPtr; - -/*************************************** -* Private Function Prototypes -***************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BTS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_BTSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_BTSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam); -static void Cy_BLE_BTSS_PrepareWriteRequestEventHandler(cy_stc_ble_gatts_prep_write_req_param_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_BTS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_BTS_Init -***************************************************************************//** -* -* This function initializes the BTS service. -* -* \param config: Configuration structure for the Bootloader service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BTS_Init(cy_stc_ble_bts_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_btsConfigPtr = config; - - /* Registers a callback function via config structure */ - if(cy_ble_btsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_BTS_ApplCallback = cy_ble_btsConfigPtr->callbackFunc; - } - - /* Registers Event Handler for the Bootloader Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_BTS_EventHandler); - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_BTS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service-specific write requests from a peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for BTS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, void *eventParam), -* where: -* * eventCode indicates the event that triggered this callback. -* * eventParam contains the parameters corresponding to the current event. -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise this -* data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_BTS_ApplCallback = callbackFunc; - if(cy_ble_btsConfigPtr != NULL) - { - cy_ble_btsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BTS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request event for the Bootloader Service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t * eventParam: The pointer to data that came -* with a Write Request for BTS. -* -* \return -* Return a value of type cy_en_ble_gatt_err_code_t: -* * CY_BLE_GATT_ERR_NONE - A function finished successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - The Handle of the Bootloader -* Characteristic's Client Configuration -* Characteristic Descriptor is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - Write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - Offset value is invalid. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The notification property of the -* Bootloader Characteristic's Client -* Configuration Characteristic -* Descriptor is disabled. -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BTS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - if(Cy_BLE_BTS_ApplCallback != NULL) - { - /* Client Characteristic Configuration descriptor Write Request */ - if(eventParam->handleValPair.attrHandle == cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharDescriptors[CY_BLE_BTS_BT_SERVICE_CCCD]) - { - /* Verify that notification property is enabled for Bootloader Characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharHandle)) - { - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_NOTIFICATION_ENABLED, NULL); - } - else - { - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_NOTIFICATION_DISABLED, NULL); - } - } - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(eventParam->handleValPair.attrHandle == cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharHandle) - { - cy_stc_ble_bts_char_value_t locCharValue = - { - .charIndex = CY_BLE_BTS_BT_SERVICE, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - /* Write value to GATT database */ - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - /* Send callback to user */ - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_WRITE_REQ, &locCharValue); - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - } - } - - return(gattErr); -} - -/****************************************************************************** -* Function Name: Cy_BLE_BTSS_WriteCmdEventHandler -***************************************************************************//** -* -* Handles the Write Without Response Request Event for the Bootloader Service. -* Service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t * eventParam: The pointer to a data structure -* specified by the event. -* -* \return -* Return a value of type cy_en_ble_gatt_err_code_t: -* * CY_BLE_GATT_ERR_NONE - A function finished successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - The Handle of the Bootloader -* Characteristic's Client Configuration -* Characteristic Descriptor is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - Write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - Offset value is invalid. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The notification property of the -* Bootloader Characteristic's Client -* Configuration Characteristic -* Descriptor is disabled. -******************************************************************************/ -static void Cy_BLE_BTSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - if(Cy_BLE_BTS_ApplCallback != NULL) - { - /* Client Characteristic Configuration descriptor Write Request */ - if(eventParam->handleValPair.attrHandle == cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharDescriptors[CY_BLE_BTS_BT_SERVICE_CCCD]) - { - /* Verify that notification property is enabled for Bootloader Characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharHandle)) - { - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_NOTIFICATION_ENABLED, NULL); - } - else - { - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_NOTIFICATION_DISABLED, NULL); - } - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - else if(eventParam->handleValPair.attrHandle == cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharHandle) - { - cy_stc_ble_bts_char_value_t locCharValue = - { - .charIndex = CY_BLE_BTS_BT_SERVICE, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - /* Write value to GATT database */ - (void)Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - /* Send callback to user */ - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_WRITE_CMD_REQ, &locCharValue); - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BTSS_PrepareWriteRequestEventHandler -***************************************************************************//** -* -* Handles a Prepare Write Request event for the Bootloader Service. -* -* \param cy_stc_ble_gatts_prep_write_req_param_t *eventParam: The pointer to the data -* received with a Prepare Write -* Request event for the -* Bootloader service. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_BTSS_PrepareWriteRequestEventHandler(cy_stc_ble_gatts_prep_write_req_param_t *eventParam) -{ - if((Cy_BLE_BTS_ApplCallback != NULL) && - (eventParam->baseAddr[0u].handleValuePair.attrHandle == cy_ble_btsConfigPtr->btss-> - btServiceInfo[CY_BLE_BTS_BT_SERVICE].btServiceCharHandle)) - { - /* Send callback to user */ - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_PREP_WRITE_REQ, eventParam); - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_BTSS_ExecuteWriteRequestEventHandler -***************************************************************************//** -* -* Handles an Execute Write Request event for the Bootloader Service. -* -* \param cy_stc_ble_gatts_exec_write_req_t *eventParam: The pointer to the data that came -* with a Write Request for the -* Bootloader service. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_BTSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam) -{ - if((Cy_BLE_BTS_ApplCallback != NULL) && (eventParam->baseAddr[0u].handleValuePair.attrHandle == - cy_ble_btsConfigPtr->btss->btServiceInfo[CY_BLE_BTS_BT_SERVICE]. - btServiceCharHandle)) - { - /* Send callback to user */ - Cy_BLE_BTS_ApplCallback((uint32_t)CY_BLE_EVT_BTSS_EXEC_WRITE_REQ, eventParam); - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_BTSS_SendNotification -***************************************************************************//** -* -* This function updates the value of the Bootloader service characteristic in the -* GATT database. If the client has configured a notification on the Battery -* Level characteristic, the function additionally sends this value using a -* GATT Notification message. -** -* \param connHandle: The BLE peer device connection handle -* -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_bts_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_BTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bts_char_index_t charIndex, - uint32_t attrSize, - const uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint8_t *btCmdCharacteristicPtr; - - if(charIndex >= CY_BLE_BTS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Store new data in database - * Get pointer to Bootloader Characteristic value to store response there - */ - btCmdCharacteristicPtr = CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(cy_ble_btsConfigPtr->btss->btServiceInfo[charIndex]. - btServiceCharHandle); - - /* Prepare and send notification with the bootloader packet emulator response if notifications are enabled */ - (void)memcpy((void*)btCmdCharacteristicPtr, (const void*)attrValue, attrSize); - - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_btsConfigPtr->btss->btServiceInfo[charIndex]. - btServiceCharDescriptors[CY_BLE_BTS_BT_SERVICE_CCCD])) - { - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_btsConfigPtr->btss->btServiceInfo[charIndex].btServiceCharHandle, - .handleValPair.value.val = btCmdCharacteristicPtr, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - else - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_BTS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Bootloader service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_BTS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - switch((cy_en_ble_event_t)eventCode) - { - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - Cy_BLE_BTSS_ExecuteWriteRequestEventHandler((cy_stc_ble_gatts_exec_write_req_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - Cy_BLE_BTSS_PrepareWriteRequestEventHandler((cy_stc_ble_gatts_prep_write_req_param_t*)eventParam); - } - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - (void)Cy_BLE_GATTS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - Cy_BLE_BTSS_WriteCmdEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - } - break; - - case CY_BLE_EVT_GATTS_WRITE_REQ: - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - gattErr = Cy_BLE_BTS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - } - break; - - default: - break; - } - - return(gattErr); -} -#endif /* defined(CY_BLE_BTS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bts.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bts.h deleted file mode 100644 index 2c28f2c998..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_bts.h +++ /dev/null @@ -1,125 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_bts.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Bootloader Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_BTS_H -#define CY_BLE_BTS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_BTS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -/* Maximum supported Bootload Services */ -#define CY_BLE_BT_SERVICE_COUNT (0x01u) - - -/*************************************** -* Data Types -***************************************/ -/** BTS Characteristic indexes */ -typedef enum -{ - CY_BLE_BTS_BT_SERVICE, /**< Bootloader service characteristic index */ - CY_BLE_BTS_CHAR_COUNT /**< Total count of characteristics */ -}cy_en_ble_bts_char_index_t; - -/** BTS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_BTS_BT_SERVICE_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_BTS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_bts_descr_index_t; - -/** Contains information about the Bootloader Characteristic structure */ -typedef struct -{ - /** Bootloader Characteristic handle */ - cy_ble_gatt_db_attr_handle_t btServiceCharHandle; - - /** Bootloader Characteristic Descriptors handles */ - cy_ble_gatt_db_attr_handle_t btServiceCharDescriptors[CY_BLE_BTS_DESCR_COUNT]; -} cy_stc_ble_bts_info_t; - -/** Structure with Bootloader Service attribute handles. */ -typedef struct -{ - /** Handle of a Bootloader Service */ - cy_ble_gatt_db_attr_handle_t btServiceHandle; - - /** Information about Bootloader Characteristics */ - cy_stc_ble_bts_info_t btServiceInfo[CY_BLE_BTS_CHAR_COUNT]; -} cy_stc_ble_btss_t; - -/** Service configuration structure */ -typedef struct -{ - /** Bootloader Service GATT DB handles structure */ - const cy_stc_ble_btss_t *btss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_bts_config_t; - -/** BTS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_bts_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_bts_char_value_t; - -/*************************************** -* API Constants -***************************************/ - - -/*************************************** -* Function Prototypes -***************************************/ -cy_en_ble_api_result_t Cy_BLE_BTS_Init(cy_stc_ble_bts_config_t *config); - -cy_en_ble_api_result_t Cy_BLE_BTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_bts_char_index_t charIndex, uint32_t attrSize, const - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_BTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); - -/*************************************** -* External data references -***************************************/ -extern uint8_t cy_ble_cmdReceivedFlag; -extern uint16_t cy_ble_cmdLength; -extern uint8_t *cy_ble_btsBuffPtr; - -extern cy_stc_ble_bts_config_t cy_ble_btsConfig; -extern cy_stc_ble_bts_config_t *cy_ble_btsConfigPtr; -extern cy_stc_ble_conn_handle_t btConnHandle; -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_BTS) */ -#endif /* CY_BLE_BTS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cgms.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cgms.c deleted file mode 100644 index 97194b6e57..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cgms.c +++ /dev/null @@ -1,1612 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cgms.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Continuous Glucose Monitoring -* Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CGMS)) - -static cy_ble_callback_t Cy_BLE_CGMS_ApplCallback; - -#ifdef CY_BLE_CGMS_SERVER -/* Internal CGMS flags */ -uint8_t cy_ble_cgmsFlag; - -/* Internal storage for last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_cgmssReqHandle; -#endif /* CY_BLE_CGMS_SERVER */ - -#ifdef CY_BLE_CGMS_CLIENT -/* CGMS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_cgmsc_t cy_ble_cgmsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_cgmscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_CGMS_CLIENT */ - -/* The pointer on global BLE CGMS Config structure */ -cy_stc_ble_cgms_config_t *cy_ble_cgmsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_CGMS_SERVER -static void Cy_BLE_CGMSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_CGMSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_CGMS_SERVER */ - -#ifdef CY_BLE_CGMS_CLIENT -static void Cy_BLE_CGMSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_CGMSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_CGMSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_CGMSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_CGMSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_CGMSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_CGMSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_CGMSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_CGMS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_CGMS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for the Continuous Glucose Monitoring -* Service -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMS_Init(cy_stc_ble_cgms_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure*/ - cy_ble_cgmsConfigPtr = config; - - /* Registers Event Handler for the BCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CGMS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_cgmsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_CGMS_ApplCallback = cy_ble_cgmsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_CGMS_SERVER - cy_ble_cgmsFlag = 0u; - cy_ble_cgmssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_CGMS_SERVER */ - #ifdef CY_BLE_CGMS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_CGMS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_cgmsc[idx], 0, sizeof(cy_stc_ble_cgmsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_CGMS].uuid = CY_BLE_UUID_CGM_SERVICE; - } - cy_ble_cgmscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for CGM Service is, -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* -* \sideeffect The *eventParams in the callback function should not be used -* by the application once the callback function execution is -* finished. Otherwise this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_CGMS_ApplCallback = callbackFunc; - if(cy_ble_cgmsConfigPtr != NULL) - { - cy_ble_cgmsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_CGMS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSS_SetCharacteristicValue(cy_en_ble_cgms_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check parameters */ - if(charIndex >= CY_BLE_CGMS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the service identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where Characteristic value data should -* be stored. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSS_GetCharacteristicValue(cy_en_ble_cgms_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_CGMS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cgms_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_cgms_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data that should -* be stored to the GATT database. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_CGMS_CHAR_COUNT) || (descrIndex >= CY_BLE_CGMS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cgms_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_cgms_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_CGMS_CHAR_COUNT) || (descrIndex >= CY_BLE_CGMS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified characteristic to the client device, -* as defined by the charIndex value. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_CGMSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consists of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the Characteristic value data that should be sent -* to the client device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_CGMS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex]. - descrHandle[CY_BLE_CGMS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfParam = - { - .handleValPair.attrHandle = cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_SendIndication -***************************************************************************//** -* -* Sends an indication of the specified characteristic to the client device, as -* defined by the charIndex value. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_CGMSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle which consists of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the Characteristic value data that should be sent -* to Client device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CGMS service-specific callback is registered -* (with Cy_BLE_CGMS_RegisterAttrCallback): -* * CY_BLE_EVT_CGMSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the CGMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_CGMS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].descrHandle[CY_BLE_CGMS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex]. - descrHandle[CY_BLE_CGMS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indParam = - { - .handleValPair.attrHandle = cy_ble_cgmsConfigPtr->cgmss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indParam); - - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific value confirmation response from client */ - cy_ble_cgmssReqHandle = indParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* \param eventParam: The pointer to a structure of type cy_stc_ble_conn_handle_t -* -******************************************************************************/ -static void Cy_BLE_CGMSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_CGMS_ApplCallback != NULL) - && (cy_ble_cgmsConfigPtr->cgmss->charInfo[CY_BLE_CGMS_RACP].charHandle == cy_ble_cgmssReqHandle)) - { - cy_stc_ble_cgms_char_value_t locCharIndex; - - for(locCharIndex.charIndex = CY_BLE_CGMS_RACP; - locCharIndex.charIndex < CY_BLE_CGMS_CHAR_COUNT; locCharIndex.charIndex++) - { - if(cy_ble_cgmsConfigPtr->cgmss->charInfo[locCharIndex.charIndex].charHandle == cy_ble_cgmssReqHandle) - { - cy_ble_cgmssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - locCharIndex.connHandle = *eventParam; - locCharIndex.value = NULL; - - if(locCharIndex.charIndex == CY_BLE_CGMS_RACP) - { - cy_ble_cgmsFlag &= (uint8_t) ~CY_BLE_CGMS_FLAG_PROCESS; - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSS_INDICATION_CONFIRMED, &locCharIndex); - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request event. Calls the registered CGMS application -* callback function. -* -* Note: Writing the attribute into GATT DB (if needed) is on the user's responsibility, -* after the characteristic content check in the registered CGMS application -* callback function. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CGMSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_cgms_char_value_t locCharValue = - { - .gattErrorCode = CY_BLE_GATT_ERR_NONE, - .connHandle = eventParam->connHandle - }; - - if(Cy_BLE_CGMS_ApplCallback != NULL) - { - for(locCharValue.charIndex = CY_BLE_CGMS_CGMT; - locCharValue.charIndex < CY_BLE_CGMS_CHAR_COUNT; locCharValue.charIndex++) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - if(eventParam->handleValPair.attrHandle == - cy_ble_cgmsConfigPtr->cgmss->charInfo[locCharValue.charIndex].charHandle) - { - locCharValue.value = &eventParam->handleValPair.value; - - if(locCharValue.charIndex == CY_BLE_CGMS_RACP) - { - if(CY_BLE_CGMS_IS_PROCEDURE_IN_PROGRESS) - { - if(eventParam->handleValPair.value.val[0u] == CY_BLE_CGMS_RACP_OPCODE_ABORT) - { - cy_ble_cgmsFlag &= (uint8_t) ~CY_BLE_CGMS_FLAG_PROCESS; - } - else - { - locCharValue.gattErrorCode = CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - } - } - else if(!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_cgmsConfigPtr->cgmss-> - charInfo[CY_BLE_CGMS_RACP].descrHandle[CY_BLE_CGMS_CCCD])) - { - locCharValue.gattErrorCode = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - else - { - cy_ble_cgmsFlag |= CY_BLE_CGMS_FLAG_PROCESS; - } - } - else - { - /* CY_BLE_CGMS_SOCP or CY_BLE_CGMS_SSTM */ - } - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSS_WRITE_CHAR, &locCharValue); - } - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - locCharValue.gattErrorCode = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - } - - /* Clear callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - locCharValue.charIndex = CY_BLE_CGMS_CHAR_COUNT; /* instead of break */ - } - else if(eventParam->handleValPair.attrHandle == - cy_ble_cgmsConfigPtr->cgmss->charInfo[locCharValue.charIndex].descrHandle[CY_BLE_CGMS_CCCD]) - { - locCharValue.value = NULL; - locCharValue.gattErrorCode = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - uint32_t eventCode; - - if(locCharValue.charIndex == CY_BLE_CGMS_CGMT) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_CGMSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_CGMSS_NOTIFICATION_DISABLED; - } - } - else - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_CGMSS_INDICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_CGMSS_INDICATION_DISABLED; - } - } - - Cy_BLE_CGMS_ApplCallback(eventCode, &locCharValue); - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - - /* Clear callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - locCharValue.charIndex = CY_BLE_CGMS_CHAR_COUNT; /* instead of break */ - } - else - { - /* Nothing else */ - } - } - } - - return(locCharValue.gattErrorCode); -} - -#endif /* CY_BLE_CGMS_SERVER */ - -#ifdef CY_BLE_CGMS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_CGMSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CGMS service-specific callback is registered -* (with Cy_BLE_CGMS_RegisterAttrCallback): -* * CY_BLE_EVT_CGMSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cgms_char_value_t. -* . -* Otherwise (if the CGMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CGMS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_cgmsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_cgmsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cgmscReqHandle[discIdx] = cy_ble_cgmsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server -* identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CGMS service-specific callback is registered -* (with Cy_BLE_CGMS_RegisterAttrCallback): -* * CY_BLE_EVT_CGMSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cgms_char_value_t. -* . -* Otherwise (if the CGMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CGMS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_cgmsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_cgmsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cgmscReqHandle[discIdx] = cy_ble_cgmsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the Characteristic Descriptor of the specified characteristic. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_CGMSS_INDICATION_ENABLED -* * CY_BLE_EVT_CGMSS_INDICATION_DISABLED -* * CY_BLE_EVT_CGMSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_CGMSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that should -* be sent to the server device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CGMS service-specific callback is registered -* (with Cy_BLE_CGMS_RegisterAttrCallback): -* * CY_BLE_EVT_CGMSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cgms_descr_value_t. -* . -* Otherwise (if the CGMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CGMS_CHAR_COUNT) || (descrIndex >= CY_BLE_CGMS_DESCR_COUNT) - || (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_CGMS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_cgmsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_CGMS_CCCD], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific read response from device */ - cy_ble_cgmscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CGMS service-specific callback is registered -* (with Cy_BLE_CGMS_RegisterAttrCallback): -* * CY_BLE_EVT_CGMSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_cgms_descr_value_t. -* . -* Otherwise (if the CGMS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CGMSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CGMS_CHAR_COUNT) || (descrIndex >= CY_BLE_CGMS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cgmsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_CGMS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_cgmsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_CGMS_CCCD], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cgmscReqHandle[discIdx] = cy_ble_cgmsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_CGMS_CCCD]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* CGM Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_cgmscCharUuid[CY_BLE_CGMS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_CGM_MEASUREMENT, - CY_BLE_UUID_CHAR_CGM_FEATURE, - CY_BLE_UUID_CHAR_CGM_STATUS, - CY_BLE_UUID_CHAR_CGM_SESSION_START_TIME, - CY_BLE_UUID_CHAR_CGM_SESSION_RUN_TIME, - CY_BLE_UUID_CHAR_RACP, - CY_BLE_UUID_CHAR_CGM_SOCP - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CGMS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_CGMS_CHAR_COUNT; i++) - { - if(cy_ble_cgmscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_cgmsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_cgmsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_cgmsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_cgmsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to declaration - * Handler of following characteristic, - * in following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_CGMS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CGMS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_CGMS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_cgmsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_cgmsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CGMS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_CGMS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_cgmsc[discIdx].charInfo[charIdx].endHandle - - cy_ble_cgmsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_cgmsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_cgmsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_NotificationEventHandler -***************************************************************************//** -* -* Handles a Notification event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CGMS_ApplCallback != NULL)) - { - if(cy_ble_cgmsc[discIdx].charInfo[CY_BLE_CGMS_CGMT].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_cgms_char_value_t locCharValue = - { - .charIndex = CY_BLE_CGMS_CGMT, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSC_NOTIFICATION, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an Indication event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CGMS_ApplCallback != NULL)) - { - cy_stc_ble_cgms_char_value_t locCharValue; - locCharValue.charIndex = CY_BLE_CGMS_RACP; - - while((cy_ble_cgmsc[discIdx].charInfo[locCharValue.charIndex].valueHandle != - eventParam->handleValPair.attrHandle) && (locCharValue.charIndex < CY_BLE_CGMS_CHAR_COUNT)) - { - locCharValue.charIndex++; - } - - if(locCharValue.charIndex < CY_BLE_CGMS_CHAR_COUNT) - { - locCharValue.connHandle = eventParam->connHandle; - locCharValue.value = &eventParam->handleValPair.value; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSC_INDICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event. -* -* \param eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CGMS_ApplCallback != NULL) && - (cy_ble_cgmscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_cgms_char_index_t charIdx; - uint8_t fFlag = 0u; - - for(charIdx = CY_BLE_CGMS_CGMT; (charIdx < CY_BLE_CGMS_CHAR_COUNT) && (fFlag == 0u); charIdx++) - { - if(cy_ble_cgmsc[discIdx].charInfo[charIdx].valueHandle == cy_ble_cgmscReqHandle[discIdx]) - { - cy_stc_ble_cgms_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = charIdx, - .value = &eventParam->value - }; - cy_ble_cgmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSC_READ_CHAR_RESPONSE, &locCharValue); - fFlag = 1u; /* instead of break */ - } - else if(cy_ble_cgmsc[discIdx].charInfo[charIdx].descrHandle[CY_BLE_CGMS_CCCD] == - cy_ble_cgmscReqHandle[discIdx]) - { - cy_stc_ble_cgms_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = charIdx, - .descrIndex = CY_BLE_CGMS_CCCD, - .value = &eventParam->value - }; - cy_ble_cgmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSC_READ_DESCR_RESPONSE, &locDescrValue); - fFlag = 1u; /* instead of break */ - } - else - { - /* nothing else */ - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CGMS_ApplCallback != NULL) && (cy_ble_cgmscReqHandle[discIdx] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_cgms_char_index_t charIdx; - uint8_t fFlag = 0u; - - for(charIdx = CY_BLE_CGMS_CGMT; (charIdx < CY_BLE_CGMS_CHAR_COUNT) && (fFlag == 0u); charIdx++) - { - if(cy_ble_cgmsc[discIdx].charInfo[charIdx].valueHandle == cy_ble_cgmscReqHandle[discIdx]) - { - cy_stc_ble_cgms_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = charIdx, - .value = NULL - }; - cy_ble_cgmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSC_WRITE_CHAR_RESPONSE, &locCharValue); - fFlag = 1u; /* instead of break */ - } - else if(cy_ble_cgmsc[discIdx].charInfo[charIdx].descrHandle[CY_BLE_CGMS_CCCD] == cy_ble_cgmscReqHandle[discIdx]) - { - cy_stc_ble_cgms_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = charIdx, - .descrIndex = CY_BLE_CGMS_CCCD, - .value = NULL - }; - cy_ble_cgmscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CGMS_ApplCallback((uint32_t)CY_BLE_EVT_CGMSC_WRITE_DESCR_RESPONSE, &locDescrValue); - fFlag = 1u; /* instead of break */ - } - else - { - /* nothing else */ - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CGMSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CGMSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_cgmscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_cgmscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* CY_BLE_CGMS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_CGMS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the the Continuous Glucose Monitoring -* Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CGMS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_CGMS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_CGMSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_CGMSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_CGMSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_CGMS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_CGMS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_CGMSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_CGMSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATT_CONNECT_IND: - (void)Cy_BLE_CGMS_Init(cy_ble_cgmsConfigPtr); - break; - #endif /* CY_BLE_CGMS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_CGMS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_CGMSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_CGMSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_CGMSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_CGMSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_CGMSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_CGMS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_CGMS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cgms.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cgms.h deleted file mode 100644 index a8d6c81fef..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cgms.h +++ /dev/null @@ -1,246 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cgms.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in the -* Continuous Glucose Monitoring Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_CGMS_H -#define CY_BLE_CGMS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CGMS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Data Types -***************************************/ - -/** - * \addtogroup group_ble_service_api_CGMS_definitions - * @{ - */ - -/** Service Characteristics indexes */ -typedef enum -{ - CY_BLE_CGMS_CGMT, /**< CGM Measurement characteristic index */ - CY_BLE_CGMS_CGFT, /**< CGM Feature characteristic index */ - CY_BLE_CGMS_CGST, /**< CGM Status characteristic index */ - CY_BLE_CGMS_SSTM, /**< CGM Session Start Time characteristic index */ - CY_BLE_CGMS_SRTM, /**< CGM Session Run Time characteristic index */ - CY_BLE_CGMS_RACP, /**< Record Access Control Point characteristic index */ - CY_BLE_CGMS_SOCP, /**< CGM Specific Ops Control Point characteristic index */ - CY_BLE_CGMS_CHAR_COUNT /**< Total count of CGMS characteristics */ -}cy_en_ble_cgms_char_index_t; - -/** Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_CGMS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_CGMS_DESCR_COUNT /**< Total count of CGMS descriptors */ -}cy_en_ble_cgms_descr_index_t; - -/** Characteristic with descriptors type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of Characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_CGMS_DESCR_COUNT]; /**< Handles of Descriptors */ -} cy_stc_ble_cgmss_char_t; - -/** Structure with CGM Service attribute handles */ -typedef struct -{ - /** CGM Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** CGM Service characteristics info array */ - cy_stc_ble_cgmss_char_t charInfo[CY_BLE_CGMS_CHAR_COUNT]; -} cy_stc_ble_cgmss_t; - -/** CGM Client Characteristic structure type */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of Server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** Characteristics descriptors handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_CGMS_DESCR_COUNT]; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_cgmsc_char_t; - -/** CGM Service structure type */ -typedef struct -{ - /** Characteristics handle + properties array */ - cy_stc_ble_cgmsc_char_t charInfo[CY_BLE_CGMS_CHAR_COUNT]; -}cy_stc_ble_cgmsc_t; - - -/** CGM Service Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_cgms_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ -} cy_stc_ble_cgms_char_value_t; - -/** CGM Service Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_cgms_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_cgms_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_cgms_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Continuous Glucose Monitoring Service GATT DB handles structure */ - const cy_stc_ble_cgmss_t *cgmss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_cgms_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_CGMS_FLAG_PROCESS (0x01u) -#define CY_BLE_CGMS_RACP_OPCODE_ABORT (0x03u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_CGMS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_CGMS_Init(cy_stc_ble_cgms_config_t *config); -cy_en_ble_api_result_t Cy_BLE_CGMS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_CGMS_SERVER -/** - * \addtogroup group_ble_service_api_CGMS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CGMSS_SetCharacteristicValue(cy_en_ble_cgms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSS_GetCharacteristicValue(cy_en_ble_cgms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_CGMS_SERVER */ - -#ifdef CY_BLE_CGMS_CLIENT -/** - * \addtogroup group_ble_service_api_CGMS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CGMSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_CGMSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CGMSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cgms_char_index_t charIndex, - cy_en_ble_cgms_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_CGMS_CLIENT */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE - * Internal macros - */ -#ifdef CY_BLE_CGMS_SERVER -#define CY_BLE_CGMS_IS_PROCEDURE_IN_PROGRESS \ - (0u != (CY_BLE_CGMS_FLAG_PROCESS & cy_ble_cgmsFlag)) -#endif /* CY_BLE_CGMS_SERVER */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_CGMS_SERVER -extern uint8_t cy_ble_cgmsFlag; -#endif /* CY_BLE_CGMS_SERVER */ - -#ifdef CY_BLE_CGMS_CLIENT -/* CGM Service server's GATT DB handles structure */ -extern cy_stc_ble_cgmsc_t cy_ble_cgmsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_CGMS_CLIENT */ - -extern cy_stc_ble_cgms_config_t cy_ble_cgmsConfig; -extern cy_stc_ble_cgms_config_t *cy_ble_cgmsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_CGMS) */ -#endif /* CY_BLE_CGMS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_clk.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_clk.c deleted file mode 100644 index 04e3c94351..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_clk.c +++ /dev/null @@ -1,627 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_clk.c -* \version 2.0 -* -* \brief -* Contains the source code for the BLE ECO clock. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_clk.h" -#include "syslib/cy_syslib.h" -#include "sysclk/cy_sysclk.h" -#include "syspm/cy_syspm.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -static cy_en_ble_eco_status_t Cy_BLE_HalRcbRegRead(uint16_t addr, uint16_t *data); -static cy_en_ble_eco_status_t Cy_BLE_HalRcbRegWrite(uint16_t addr, uint16_t data); -static cy_en_ble_eco_status_t Cy_BLE_HalEcoSetTrim(uint8_t trim); -static cy_en_ble_eco_status_t Cy_BLE_HalMxdRadioEnableClocks(const cy_stc_ble_bless_eco_cfg_params_t *ecoConfig); - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_IsEcoCpuClockSrc -****************************************************************************//** -* -* If ECO from BLESS in CLK_PATH_SELECT register is selected return 1. -* -* \return -* uint8_t: 0 - ECO from BLESS is not used in DWR -* 1 - ECO from BLESS is selected in CLK_PATH_SELECT register -* -*******************************************************************************/ -uint8_t Cy_BLE_HAL_IsEcoCpuClockSrc(void) -{ - uint8_t returnVal = 0u; - uint32_t i; - - for(i = 0u; i < SRSS_NUM_CLKPATH; i++) - { - if(Cy_SysClk_ClkPathGetSource(i) == CY_SYSCLK_CLKPATH_IN_ALTHF) - { - returnVal = 1u; - break; - } - } - - return(returnVal); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_IsWcoLfclkSrc -****************************************************************************//** -* -* In CLK_SELECT register if WCO or PILO return 1 -* -* \return -* uint8_t: 0 - WCO or PILO are not used in DWR -* 1 - WCO is selected in CLK_SELECT register -* -*******************************************************************************/ -uint8_t Cy_BLE_HAL_IsWcoLfclkSrc(void) -{ - cy_en_clklf_in_sources_t lfclkSrs; - - lfclkSrs = Cy_SysClk_ClkLfGetSource(); - - return(((lfclkSrs == CY_SYSCLK_CLKLF_IN_WCO) || (lfclkSrs == CY_SYSCLK_CLKLF_IN_PILO)) ? 1u : 0u); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_Init -****************************************************************************//** -* -* Initializes the BLESS port. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_Init(void) -{ - /* Configures pins for BLESS */ - const cy_stc_gpio_prt_config_t port2_cfg = - { - .cfg = CY_BLE_PORT2_CFG_VAL, - .cfgOut = CY_BLE_PORT_CFG_OUT_VAL, - .sel0Active = CY_BLE_PORT2_HSIOM_SEL0, - .sel1Active = CY_BLE_PORT2_HSIOM_SEL1 - }; - const cy_stc_gpio_prt_config_t port3_cfg = - { - .cfg = CY_BLE_PORT3_CFG_VAL, - .cfgOut = CY_BLE_PORT_CFG_OUT_VAL, - .sel0Active = CY_BLE_PORT3_HSIOM_SEL0, - .sel1Active = CY_BLE_PORT3_HSIOM_SEL1 - }; - const cy_stc_gpio_prt_config_t port4_cfg = - { - .cfg = CY_BLE_PORT4_CFG_VAL, - .cfgOut = CY_BLE_PORT_CFG_OUT_VAL, - .sel0Active = CY_BLE_PORT4_HSIOM_SEL0, - .sel1Active = CY_BLE_PORT4_HSIOM_SEL1 - }; - - (void)Cy_GPIO_Port_Init(GPIO_PRT2, &port2_cfg); - (void)Cy_GPIO_Port_Init(GPIO_PRT3, &port3_cfg); - (void)Cy_GPIO_Port_Init(GPIO_PRT4, &port4_cfg); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HalRcbRegRead -****************************************************************************//** -* -* Reads Radio register. -* -* \param addr: Register address. -* \param *data: Register data (output parameter). -* -* \return -* CY_BLE_ECO_SUCCESS - On successful operation. -* CY_BLE_ECO_HARDWARE_ERROR - If RCB operation failed -* -*******************************************************************************/ -static cy_en_ble_eco_status_t Cy_BLE_HalRcbRegRead(uint16_t addr, uint16_t *data) -{ - cy_en_ble_eco_status_t status = CY_BLE_ECO_SUCCESS; - uint32_t timeout = CY_BLE_RCB_TIMEOUT; - uint32_t temp = (uint32_t)((0x8000UL | addr) << 16u); - - /* Write Address to the RCB */ - BLE->RCB.TX_FIFO_WR = temp; - - /* Wait for Data. */ - while(((BLE->RCB.INTR & BLE_RCB_INTR_RCB_DONE_Msk) == 0u) && (timeout > 0u)) - { - timeout--; - Cy_SysLib_DelayUs(CY_BLE_DELAY_TIME); - } - - if(timeout > 0u) - { - BLE->RCB.INTR |= BLE_RCB_INTR_RCB_DONE_Msk; - *data = (uint16_t)BLE->RCB.RX_FIFO_RD; - } - else - { - status = CY_BLE_ECO_HARDWARE_ERROR; - } - - return(status); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HalRcbRegWrite -****************************************************************************//** -* -* Writes Radio register. -* -* \param addr: Register address. -* \param data: Register data. -* -* \return -* CY_BLE_ECO_SUCCESS - On successful operation. -* CY_BLE_ECO_HARDWARE_ERROR - If RCB operation failed -* -*******************************************************************************/ -static cy_en_ble_eco_status_t Cy_BLE_HalRcbRegWrite(uint16_t addr, uint16_t data) -{ - cy_en_ble_eco_status_t status = CY_BLE_ECO_SUCCESS; - uint32_t timeout = CY_BLE_RCB_TIMEOUT; - uint32_t temp = ((uint32_t)((0x7FFFUL & addr) << 16u)) | data; - - BLE->RCB.TX_FIFO_WR = temp; - - /* Wait for RCB done. */ - while(((BLE->RCB.INTR & BLE_RCB_INTR_RCB_DONE_Msk) == 0u) && (timeout > 0u)) - { - timeout--; - Cy_SysLib_DelayUs(CY_BLE_DELAY_TIME); - } - - if(timeout > 0u) - { - BLE->RCB.INTR |= BLE_RCB_INTR_RCB_DONE_Msk; - } - else - { - status = CY_BLE_ECO_HARDWARE_ERROR; - } - - return(status); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HalEcoSetTrim -****************************************************************************//** -* -* Sets ECO trim value. -* -* \param trim: Trim value. -* -* \return -* CY_BLE_ECO_SUCCESS - On successful operation. -* CY_BLE_ECO_HARDWARE_ERROR - If RCB operation failed -* -*******************************************************************************/ -static cy_en_ble_eco_status_t Cy_BLE_HalEcoSetTrim(uint8_t trim) -{ - uint16_t reg = CY_BLE_RF_DCXO_CFG_REG_VALUE; - cy_en_ble_eco_status_t status; - - /* Load the new CAP TRIM value */ - reg |= (uint16_t)((uint16_t)trim << CY_BLE_RF_DCXO_CFG_REG_DCXO_CAP_SHIFT); - - /* Write the new value to the register */ - status = Cy_BLE_HalRcbRegWrite(CY_BLE_RF_DCXO_CFG_REG, reg); - - if(status == CY_BLE_ECO_SUCCESS) - { - /* Write the new value to the CFG2 register */ - status = Cy_BLE_HalRcbRegWrite(CY_BLE_RF_DCXO_CFG2_REG, CY_BLE_RF_DCXO_CFG2_REG_VALUE); - } - - Cy_SysLib_DelayUs(500u); - - return(status); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HalMxdRadioEnableClocks -****************************************************************************//** -* -* Enables and configures radio clock. -* -* \param ecoConfig: Clock configuration of type 'cy_stc_ble_bless_eco_cfg_params_t'. -* -* \return -* CY_BLE_ECO_SUCCESS - On successful operation. -* CY_BLE_ECO_HARDWARE_ERROR - If RCB operation failed -* -*******************************************************************************/ -static cy_en_ble_eco_status_t Cy_BLE_HalMxdRadioEnableClocks(const cy_stc_ble_bless_eco_cfg_params_t *ecoConfig) -{ - uint16_t temp; - uint16_t blerdDivider; - uint16_t ecoSysDivider; - uint16_t blellDivider = 0u; - uint32_t retries = CY_BLE_RCB_RETRIES; - cy_en_ble_eco_status_t status; - - /* Deassert active domain reset and enable clock buffer in MXD Radio */ - do - { - status = Cy_BLE_HalRcbRegWrite(CY_BLE_PMU_MODE_TRANSITION_REG, CY_BLE_MXD_RADIO_CLK_BUF_EN_VAL); - if(status == CY_BLE_ECO_SUCCESS) - { - status = Cy_BLE_HalRcbRegRead(CY_BLE_PMU_MODE_TRANSITION_REG, &temp); - } - if(retries > 0u) - { - retries--; - } - else - { - status = CY_BLE_ECO_HARDWARE_ERROR; - } - } - while((status == CY_BLE_ECO_SUCCESS) && (temp != CY_BLE_MXD_RADIO_CLK_BUF_EN_VAL)); - - /* Check if ECO clock output is enabled - * In MXD_VER2, ECO clock is stopped on overwriting this bit */ - if(status == CY_BLE_ECO_SUCCESS) - { - retries = CY_BLE_RCB_RETRIES; - status = Cy_BLE_HalRcbRegRead(CY_BLE_PMU_PMU_CTRL_REG, &temp); - if((status == CY_BLE_ECO_SUCCESS) && ((temp & CY_BLE_MXD_RADIO_DIG_CLK_OUT_EN_VAL) == 0u)) - { - /* Enable digital ECO clock output from MXD Radio to BLESS */ - do - { - status = Cy_BLE_HalRcbRegWrite(CY_BLE_PMU_PMU_CTRL_REG, CY_BLE_MXD_RADIO_DIG_CLK_OUT_EN_VAL); - if(status == CY_BLE_ECO_SUCCESS) - { - status = Cy_BLE_HalRcbRegRead(CY_BLE_PMU_PMU_CTRL_REG, &temp); - } - if(retries > 0u) - { - retries--; - } - else - { - status = CY_BLE_ECO_HARDWARE_ERROR; - } - } - while((status == CY_BLE_ECO_SUCCESS) && (temp != CY_BLE_MXD_RADIO_DIG_CLK_OUT_EN_VAL)); - } - } - - /* Configure ECO clock frequency and clock divider in MXD Radio */ - if(status == CY_BLE_ECO_SUCCESS) - { - /* Read the MXD Radio register */ - status = Cy_BLE_HalRcbRegRead(CY_BLE_RF_DCXO_BUF_CFG_REG, &temp); - } - if(status == CY_BLE_ECO_SUCCESS) - { - /* Clear clock divider and select amp buffer output bits */ - temp &= CY_LO16(~((CY_BLE_RF_DCXO_BUF_CFG_REG_CLK_DIV_MASK << CY_BLE_RF_DCXO_BUF_CFG_REG_CLK_DIV_SHIFT) | - (CY_BLE_RF_DCXO_BUF_CFG_REG_BUF_AMP_SEL_MASK << CY_BLE_RF_DCXO_BUF_CFG_REG_BUF_AMP_SEL_SHIFT))); - - /* Total ECO divider consist of divider located on BLERD and BLESS divider - * Set BLERD divider to maximum value taking in to account that 8 Mhz is required for BLELL - * BLELL clock frequency is set to 8Mhz irrespective of the crystal value. - */ - if(ecoConfig->ecoFreq == CY_BLE_BLESS_ECO_FREQ_32MHZ) - { - if(ecoConfig->ecoSysDiv >= CY_BLE_SYS_ECO_CLK_DIV_4) - { - blerdDivider = (uint16_t)CY_BLE_MXD_RADIO_CLK_DIV_4; - } - else - { - blerdDivider = (uint16_t)ecoConfig->ecoSysDiv; - blellDivider = (uint16_t)CY_BLE_MXD_RADIO_CLK_DIV_4 - blerdDivider; - } - temp |= CY_BLE_RF_DCXO_BUF_CFG_REG_XTAL_32M_SEL_BIT; - temp |= (uint16_t)(CY_BLE_MXD_RADIO_CLK_BUF_AMP_32M_LARGE << CY_BLE_RF_DCXO_BUF_CFG_REG_BUF_AMP_SEL_SHIFT); - - /* Update cy_BleEcoClockFreqHz for the proper Cy_SysLib_Delay functionality */ - cy_BleEcoClockFreqHz = CY_BLE_DEFAULT_ECO_CLK_FREQ_32MHZ / (1UL << (uint16_t)ecoConfig->ecoSysDiv); - } - else - { - if(ecoConfig->ecoSysDiv >= CY_BLE_SYS_ECO_CLK_DIV_2) - { - blerdDivider = (uint16_t)CY_BLE_MXD_RADIO_CLK_DIV_2; - } - else - { - blerdDivider = (uint16_t)ecoConfig->ecoSysDiv; - blellDivider = (uint16_t)CY_BLE_MXD_RADIO_CLK_DIV_2 - blerdDivider; - } - temp &= (uint16_t) ~CY_BLE_RF_DCXO_BUF_CFG_REG_XTAL_32M_SEL_BIT; - temp |= (uint16_t)(CY_BLE_MXD_RADIO_CLK_BUF_AMP_16M_LARGE << CY_BLE_RF_DCXO_BUF_CFG_REG_BUF_AMP_SEL_SHIFT); - - /* Update cy_BleEcoClockFreqHz for the proper Cy_SysLib_Delay functionality */ - cy_BleEcoClockFreqHz = CY_BLE_DEFAULT_ECO_CLK_FREQ_16MHZ / (1UL << (uint16_t)ecoConfig->ecoSysDiv); - } - - temp |= (uint16_t)(blerdDivider << CY_BLE_RF_DCXO_BUF_CFG_REG_CLK_DIV_SHIFT); - - /* Write the MXD Radio register */ - status = Cy_BLE_HalRcbRegWrite(CY_BLE_RF_DCXO_BUF_CFG_REG, temp); - - /* Reduce BLESS divider by BLERD divider value */ - ecoSysDivider = (uint16_t)ecoConfig->ecoSysDiv - blerdDivider; - temp = (uint16_t)(ecoSysDivider & BLE_BLESS_XTAL_CLK_DIV_CONFIG_SYSCLK_DIV_Msk); - temp |= (uint16_t)(blellDivider << BLE_BLESS_XTAL_CLK_DIV_CONFIG_LLCLK_DIV_Pos); - - /* Set clock divider */ - BLE->BLESS.XTAL_CLK_DIV_CONFIG = temp; - } - - return(status); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_EcoStop -****************************************************************************//** -* -* Disables BLE ECO clock. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_EcoStop(void) -{ - /* Initiate Soft Reset */ - BLE->BLESS.LL_CLK_EN |= BLE_BLESS_LL_CLK_EN_BLESS_RESET_Msk; -} - - -/******************************************************************************* -* Function Name: Cy_BLE_EcoStart -****************************************************************************//** -* -* Configures and starts BLE ECO clock. -* By default, BLE stack starts BLE ECO clock with default parameters: -* CY_BLE_DEFAULT_OSC_STARTUP_DELAY_LF -* CY_BLE_DEFAULT_CAP_TRIM_VALUE -* CY_BLE_DEFAULT_ECO_FREQ -* CY_BLE_DEFAULT_ECO_DIV -* In case BLE ECO is used with different parameters, enable it in DWR or call -* this function with custom configuration. -* -* This clock is stopped in the deep sleep and hibernate power modes. -* -* \param ecoConfig: Clock configuration of type 'cy_stc_ble_bless_eco_cfg_params_t'. -* -* \return -* CY_BLE_ECO_SUCCESS - On successful operation. -* CY_BLE_ECO_BAD_PARAM - Wrong input parameter. -* CY_BLE_ECO_RCB_CONTROL_LL - If the RCB Control is with BLE Link Layer. -* CY_BLE_ECO_ALREADY_STARTED - If BLE ECO clock is already started -* CY_BLE_ECO_HARDWARE_ERROR - If RCB or BLE ECO operation failed -* -* \sideeffect -* The I/O pins will be automatically unfrozen coming out of hibernate when -* the BLE ECO is in use. -* -*******************************************************************************/ -cy_en_ble_eco_status_t Cy_BLE_EcoStart(const cy_stc_ble_bless_eco_cfg_params_t *ecoConfig) -{ - cy_en_ble_eco_status_t status = CY_BLE_ECO_SUCCESS; - uint32_t temp; - - if(ecoConfig == NULL) - { - status = CY_BLE_ECO_BAD_PARAM; - } - else - { - /* Unfreeze IO after Hibernate */ - if(Cy_SysPm_GetIoFreezeStatus()) - { - Cy_SysPm_IoUnfreeze(); - } - - if(((BLE->BLESS.MT_CFG & BLE_BLESS_MT_CFG_ENABLE_BLERD_Msk) != 0u) && - ((BLE->BLESS.MT_STATUS & BLE_BLESS_MT_STATUS_BLESS_STATE_Msk) != 0u)) - { - status = CY_BLE_ECO_ALREADY_STARTED; - } - else - { - /* HAL Initialization */ - Cy_BLE_HAL_Init(); - - /* BLESS MT Delays configuration */ - BLE->BLESS.MT_DELAY_CFG = - (uint32_t)(CY_BLE_DEFAULT_HVLDO_STARTUP_DELAY << BLE_BLESS_MT_DELAY_CFG_HVLDO_STARTUP_DELAY_Pos) | - (uint32_t)(CY_BLE_DEFAULT_ISOLATE_DEASSERT_DELAY << BLE_BLESS_MT_DELAY_CFG_ISOLATE_DEASSERT_DELAY_Pos) | - (uint32_t)(CY_BLE_DEFAULT_ACT_TO_SWITCH_DELAY << BLE_BLESS_MT_DELAY_CFG_ACT_TO_SWITCH_DELAY_Pos) | - (uint32_t)(CY_BLE_DEFAULT_HVLDO_DISABLE_DELAY << BLE_BLESS_MT_DELAY_CFG_HVLDO_DISABLE_DELAY_Pos); - - BLE->BLESS.MT_DELAY_CFG2 = - (uint32_t)((uint32_t)ecoConfig->ecoXtalStartUpTime << BLE_BLESS_MT_DELAY_CFG2_OSC_STARTUP_DELAY_LF_Pos) | - (uint32_t)(CY_BLE_DEFAULT_ACT_STARTUP_DELAY << BLE_BLESS_MT_DELAY_CFG2_ACT_STARTUP_DELAY_Pos) | - (uint32_t)(CY_BLE_DEFAULT_DIG_LDO_STARTUP_DELAY << BLE_BLESS_MT_DELAY_CFG2_DIG_LDO_STARTUP_DELAY_Pos); - - BLE->BLESS.MT_DELAY_CFG3 = - (uint32_t)(CY_BLE_DEFAULT_XTAL_DISABLE_DELAY << BLE_BLESS_MT_DELAY_CFG3_XTAL_DISABLE_DELAY_Pos) | - (uint32_t)(CY_BLE_DEFAULT_DIG_LDO_DISABLE_DELAY << BLE_BLESS_MT_DELAY_CFG3_DIG_LDO_DISABLE_DELAY_Pos) | - (uint32_t)(CY_BLE_DEFAULT_VDDR_STABLE_DELAY << BLE_BLESS_MT_DELAY_CFG3_VDDR_STABLE_DELAY_Pos); - - /* RCB Initialization - * Check if the RCB Control is with LL. - */ - if((BLE->RCB.RCBLL.CTRL & BLE_RCB_RCBLL_CTRL_RCBLL_CTRL_Msk) != 0u) - { - status = CY_BLE_ECO_RCB_CONTROL_LL; - } - else - { - uint32_t rcbDivider = 0u; - - /* If clock source for RCB is PeriClk */ - if((BLE_BLESS->LL_CLK_EN & BLE_BLESS_LL_CLK_EN_SEL_RCB_CLK_Msk) == 0u) - { - if(cy_PeriClkFreqHz > CY_BLE_DEFAULT_RCB_CTRL_FREQ) - { - rcbDivider = (cy_PeriClkFreqHz / CY_BLE_DEFAULT_RCB_CTRL_FREQ) - 1u; - } - } - else - { - rcbDivider = CY_BLE_DEFAULT_RCB_CTRL_DIV; - } - - /* Configure default RCB Parameters. */ - BLE->RCB.CTRL |= (BLE_RCB_CTRL_ENABLED_Msk | - BLE_RCB_CTRL_RX_CLK_EDGE_Msk | - (CY_BLE_DEFAULT_RCB_CTRL_LEAD << BLE_RCB_CTRL_LEAD_Pos) | - (CY_BLE_DEFAULT_RCB_CTRL_LAG << BLE_RCB_CTRL_LAG_Pos) | - ((rcbDivider > 0u) ? ((rcbDivider << BLE_RCB_CTRL_DIV_Pos) | - BLE_RCB_CTRL_DIV_ENABLED_Msk) : 0u)); - - /* If user uses SIMO Buck, enable Buck2 in hardware mode for BLE */ - if(Cy_SysPm_SimoBuckIsEnabled()) - { - Cy_SysPm_SimoBuckSetVoltage2(CY_SYSPM_SIMO_BUCK_OUT2_VOLTAGE_1_3V, true); - Cy_SysPm_SimoBuckSetHwControl(true); - } - else /* Configure LDO if SIMO Buck2 is not enabled */ - { - BLE->BLESS.MISC_EN_CTRL |= (BLE_BLESS_MISC_EN_CTRL_ACT_REG_EN_CTRL_Msk | - BLE_BLESS_MISC_EN_CTRL_BUCK_EN_CTRL_Msk); - } - - /* Enable the VIO supply and LDO in standby mode for slow ramp */ - temp = BLE->BLESS.MT_CFG; - temp |= BLE_BLESS_MT_CFG_HVLDO_BYPASS_Msk | - BLE_BLESS_MT_CFG_OVERRIDE_HVLDO_BYPASS_Msk | - BLE_BLESS_MT_CFG_HVLDO_EN_Msk | - BLE_BLESS_MT_CFG_OVERRIDE_HVLDO_EN_Msk; - BLE->BLESS.MT_CFG = temp; - Cy_SysLib_DelayUs(64u); - - if((BLE->BLESS.MT_VIO_CTRL & BLE_BLESS_MT_VIO_CTRL_SRSS_SWITCH_EN_Msk) == 0u) - { - /* Enable LDO */ - BLE->BLESS.MT_VIO_CTRL = BLE_BLESS_MT_VIO_CTRL_SRSS_SWITCH_EN_Msk; - - /* Wait for 64us after turning HVLDO ON */ - Cy_SysLib_DelayUs(64u); - - /* Enable LDO Delayed */ - BLE->BLESS.MT_VIO_CTRL = BLE_BLESS_MT_VIO_CTRL_SRSS_SWITCH_EN_Msk | - BLE_BLESS_MT_VIO_CTRL_SRSS_SWITCH_EN_DLY_Msk; - /* Wait for 64us */ - Cy_SysLib_DelayUs(64u); - } - - /* Disable override mode and let hardware take control of HVLDO */ - temp &= ~(BLE_BLESS_MT_CFG_OVERRIDE_HVLDO_BYPASS_Msk | - BLE_BLESS_MT_CFG_OVERRIDE_HVLDO_EN_Msk); - BLE->BLESS.MT_CFG = temp; - - /* Wait for the VIO stable key write operation to complete */ - { - uint32_t timeout = CY_BLE_VIO_TIMEOUT; - while(((GPIO->VDD_ACTIVE & 0x10u) == 0u) && (timeout > 0u)) - { - timeout--; - Cy_SysLib_DelayUs(CY_BLE_DELAY_TIME); - } - if(timeout == 0u) - { - status = CY_BLE_ECO_HARDWARE_ERROR; - } - } - if(status == CY_BLE_ECO_SUCCESS) - { - uint32_t timeout = CY_BLE_ACT_TIMEOUT; - - /* Clear the BLERD_ACTIVE_INTR */ - BLE->BLESS.INTR_STAT |= BLE_BLESS_INTR_STAT_BLERD_ACTIVE_INTR_Msk; - - if(!Cy_SysPm_SimoBuckOutputIsEnabled(CY_SYSPM_BUCK_VRF)) - { - temp |= BLE_BLESS_MT_CFG_ACT_LDO_NOT_BUCK_Msk; - } - /* Enable Radio */ - temp |= BLE_BLESS_MT_CFG_ENABLE_BLERD_Msk; - - /* Disable ECO in DeepSleep mode */ - temp &= ~BLE_BLESS_MT_CFG_DPSLP_ECO_ON_Msk; - BLE->BLESS.MT_CFG = temp; - - /* Wait for BLESS in ACTIVE state */ - while(((BLE->BLESS.MT_STATUS & BLE_BLESS_MT_STATUS_BLESS_STATE_Msk) == 0u) && (timeout > 0u)) - { - timeout--; - Cy_SysLib_DelayUs(CY_BLE_DELAY_TIME); - } - if(timeout == 0u) - { - status = CY_BLE_ECO_HARDWARE_ERROR; - } - } - if(status == CY_BLE_ECO_SUCCESS) - { - /* Enable and configure radio clock */ - status = Cy_BLE_HalMxdRadioEnableClocks(ecoConfig); - } - if(status == CY_BLE_ECO_SUCCESS) - { - /* Set Load capacitance */ - status = Cy_BLE_HalEcoSetTrim(ecoConfig->loadCap); - } - } - } - } - - return(status); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_EcoGetFrequency -****************************************************************************//** -* -* Reports the frequency of the output of a BLE ECO clock. -* -* \return The frequency, in Hz. -* -*******************************************************************************/ -uint32_t Cy_BLE_HAL_EcoGetFrequency(void) -{ - return(cy_BleEcoClockFreqHz); -} - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_clk.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_clk.h deleted file mode 100644 index 9b6d512419..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_clk.h +++ /dev/null @@ -1,239 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_clk.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the BLE clock. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_CLK_H -#define CY_BLE_CLK_H - -#include "cy_device_headers.h" -#include "gpio/cy_gpio.h" -#include "syslib/cy_syslib.h" -#include - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define CY_BLE_CLK_ID (0x05ul << 18u) - -#define CY_BLE_PORT2_CFG_VAL (0x66666666u) -#define CY_BLE_PORT3_CFG_VAL (0x66EEE666u) -#define CY_BLE_PORT4_CFG_VAL (0x6666E666u) - -#define CY_BLE_PORT_CFG_OUT_VAL (0xFFFF0000u) - -#define CY_BLE_PORT2_HSIOM_SEL0 (0x1C1C1C1Cu) -#define CY_BLE_PORT2_HSIOM_SEL1 (0x1C1C1C1Cu) -#define CY_BLE_PORT3_HSIOM_SEL0 (0x1A1A1A1Cu) -#define CY_BLE_PORT3_HSIOM_SEL1 (0x00001A1Au) -#define CY_BLE_PORT4_HSIOM_SEL0 (0x1C001A1Au) -#define CY_BLE_PORT4_HSIOM_SEL1 (0x00000000u) - -#define CY_BLE_DEFAULT_OSC_STARTUP_DELAY_LF (25u) -#define CY_BLE_DEFAULT_CAP_TRIM_VALUE (32u) -#define CY_BLE_DEFAULT_ECO_FREQ (CY_BLE_BLESS_ECO_FREQ_32MHZ) -#define CY_BLE_DEFAULT_ECO_DIV (CY_BLE_SYS_ECO_CLK_DIV_4) - -#define CY_BLE_DEFAULT_HVLDO_STARTUP_DELAY (6UL) -#define CY_BLE_DEFAULT_ISOLATE_DEASSERT_DELAY (0UL) -#define CY_BLE_DEFAULT_ACT_TO_SWITCH_DELAY (0UL) -#define CY_BLE_DEFAULT_HVLDO_DISABLE_DELAY (1UL) - -#define CY_BLE_DEFAULT_ACT_STARTUP_DELAY (0UL) -#define CY_BLE_DEFAULT_DIG_LDO_STARTUP_DELAY (0UL) - -#define CY_BLE_DEFAULT_XTAL_DISABLE_DELAY (1UL) -#define CY_BLE_DEFAULT_DIG_LDO_DISABLE_DELAY (0UL) -#define CY_BLE_DEFAULT_VDDR_STABLE_DELAY (1UL) - -#define CY_BLE_DEFAULT_RCB_CTRL_LEAD (0x2UL) -#define CY_BLE_DEFAULT_RCB_CTRL_LAG (0x2UL) -#define CY_BLE_DEFAULT_RCB_CTRL_DIV (0x1UL) /* LL 8 MHz / 2 */ -#define CY_BLE_DEFAULT_RCB_CTRL_FREQ (4000000UL) /* Default RCB clock is 4 MHz */ - -#define CY_BLE_DEFAULT_ECO_CLK_FREQ_32MHZ (32000000UL) -#define CY_BLE_DEFAULT_ECO_CLK_FREQ_16MHZ (16000000UL) - -#define CY_BLE_MXD_RADIO_CLK_BUF_EN_VAL (CY_BLE_PMU_MODE_TRANSITION_REG_CLK_ANA_DIG_EN_BIT | \ - CY_BLE_PMU_MODE_TRANSITION_REG_RST_ACT_N_BIT) -#define CY_BLE_MXD_RADIO_DIG_CLK_OUT_EN_VAL (CY_BLE_PMU_PMU_CTRL_REG_CLK_CMOS_SEL_BIT) - -/* Radio registers */ -#define CY_BLE_PMU_MODE_TRANSITION_REG (0x1e02u) -#define CY_BLE_PMU_MODE_TRANSITION_REG_CLK_ANA_DIG_EN_BIT (uint16_t)(1UL << 12u) -#define CY_BLE_PMU_MODE_TRANSITION_REG_RST_ACT_N_BIT (uint16_t)(1UL << 11u) - -#define CY_BLE_PMU_PMU_CTRL_REG (0x1e03u) -#define CY_BLE_PMU_PMU_CTRL_REG_CLK_CMOS_SEL_BIT (uint16_t)(1UL << 10u) - -#define CY_BLE_RF_DCXO_CFG_REG (0x1e08u) -#define CY_BLE_RF_DCXO_CFG_REG_DCXO_CAP_SHIFT (1u) -#define CY_BLE_RF_DCXO_CFG_REG_DCXO_CAP_MASK (0xffUL) -#define CY_BLE_RF_DCXO_CFG_REG_VALUE (0x1001u) - -#define CY_BLE_RF_DCXO_CFG2_REG (0x1e0fu) -#define CY_BLE_RF_DCXO_CFG2_REG_VALUE (0x6837u) - -#define CY_BLE_RF_DCXO_BUF_CFG_REG (0x1e09u) -#define CY_BLE_RF_DCXO_BUF_CFG_REG_XTAL_32M_SEL_BIT (uint16_t)(1UL << 6u) -#define CY_BLE_RF_DCXO_BUF_CFG_REG_BUF_AMP_SEL_SHIFT (4u) -#define CY_BLE_RF_DCXO_BUF_CFG_REG_BUF_AMP_SEL_MASK (0x03UL) -#define CY_BLE_RF_DCXO_BUF_CFG_REG_CLK_DIV_SHIFT (0u) -#define CY_BLE_RF_DCXO_BUF_CFG_REG_CLK_DIV_MASK (0x0fUL) - -#define CY_BLE_DELAY_TIME (1u) /* in us */ -#define CY_BLE_RCB_TIMEOUT (1000u / CY_BLE_DELAY_TIME) /* 1ms */ -#define CY_BLE_VIO_TIMEOUT (2000u / CY_BLE_DELAY_TIME) /* 2ms */ -#define CY_BLE_ACT_TIMEOUT (950000u / CY_BLE_DELAY_TIME) /* 950ms */ -#define CY_BLE_RCB_RETRIES (10u) - - - -/** - * \addtogroup group_ble_clock_api_data_types - * @{ - */ -/*************************************** -* Data Types -***************************************/ - -/** BLE Radio ECO clock divider */ -typedef enum -{ - CY_BLE_MXD_RADIO_CLK_DIV_1 = 0u, - CY_BLE_MXD_RADIO_CLK_DIV_2 = 1u, - CY_BLE_MXD_RADIO_CLK_DIV_4 = 2u, - CY_BLE_MXD_RADIO_CLK_DIV_8 = 4u, - CY_BLE_MXD_RADIO_CLK_DIV_16 = 8u -} cy_en_ble_mxd_radio_clk_div_t; - -/** Sine wave buffer output capability select */ -typedef enum -{ - CY_BLE_MXD_RADIO_CLK_BUF_AMP_16M_SMALL = 0u, - CY_BLE_MXD_RADIO_CLK_BUF_AMP_16M_LARGE = 1u, - CY_BLE_MXD_RADIO_CLK_BUF_AMP_32M_SMALL = 2u, - CY_BLE_MXD_RADIO_CLK_BUF_AMP_32M_LARGE = 3u -} cy_en_ble_mxd_radio_clk_buf_amp_t; - -/** BLESS clock divider */ -typedef enum -{ - CY_BLE_BLESS_XTAL_CLK_DIV_1 = 0u, - CY_BLE_BLESS_XTAL_CLK_DIV_2 = 1u, - CY_BLE_BLESS_XTAL_CLK_DIV_4 = 2u, - CY_BLE_BLESS_XTAL_CLK_DIV_8 = 3u -}cy_en_ble_bless_xtal_clk_div_config_llclk_div_t; - -/** BLE ECO Clock Frequency. */ -typedef enum -{ - /** ECO Frequency of 16MHz */ - CY_BLE_BLESS_ECO_FREQ_16MHZ, - - /** ECO Frequency of 32MHz */ - CY_BLE_BLESS_ECO_FREQ_32MHZ -} cy_en_ble_bless_eco_freq_t; - -/** BLE ECO System clock divider */ -typedef enum -{ - /** Link Layer clock divider = 1*/ - CY_BLE_SYS_ECO_CLK_DIV_1 = 0x00u, - - /** Link Layer clock divider = 2*/ - CY_BLE_SYS_ECO_CLK_DIV_2, - - /** Link Layer clock divider = 4*/ - CY_BLE_SYS_ECO_CLK_DIV_4, - - /** Link Layer clock divider = 8*/ - CY_BLE_SYS_ECO_CLK_DIV_8, - - /** Invalid Link Layer clock divider*/ - CY_BLE_SYS_ECO_CLK_DIV_INVALID -} cy_en_ble_bless_sys_eco_clk_div_t; - -/** BLE ECO Clock return value */ -typedef enum -{ - /** ECO started successfully */ - CY_BLE_ECO_SUCCESS = 0x00ul, - - /** Invalid input param values */ - CY_BLE_ECO_BAD_PARAM = CY_PDL_STATUS_ERROR | CY_BLE_CLK_ID | 0x0001ul, - - /** RCB is not available for Firmware control to restart ECO */ - CY_BLE_ECO_RCB_CONTROL_LL = CY_PDL_STATUS_ERROR | CY_BLE_CLK_ID | 0x0002ul, - - /** ECO already started */ - CY_BLE_ECO_ALREADY_STARTED = CY_PDL_STATUS_ERROR | CY_BLE_CLK_ID | 0x0003ul, - - /** Hardware error */ - CY_BLE_ECO_HARDWARE_ERROR = CY_PDL_STATUS_ERROR | CY_BLE_CLK_ID | 0x0004ul, - -} cy_en_ble_eco_status_t; - - -/** BLE ECO configuration parameters */ -typedef struct -{ - /** ECO crystal startup time in multiple of 31.25us (startup_time_from_user min - 31.25us) - * ecoXtalStartUpTime = startup_time_from_user/31.25 */ - uint8_t ecoXtalStartUpTime; - - /** ECO crystal load capacitance - In multiple of 0.075pF (pF_from_user min - 7.5pF, pF_from_user max - 26.625pF) - * loadcap = ((pF_from_user - 7.5)/0.075) */ - uint8_t loadCap; - - /** ECO Frequency. */ - cy_en_ble_bless_eco_freq_t ecoFreq; - - /** System divider for ECO clock */ - cy_en_ble_bless_sys_eco_clk_div_t ecoSysDiv; -} cy_stc_ble_bless_eco_cfg_params_t; -/** @} */ - -/** - * \addtogroup group_ble_clock_api - * @{ - */ - -/*************************************** -* Function Prototypes -***************************************/ -cy_en_ble_eco_status_t Cy_BLE_EcoStart(const cy_stc_ble_bless_eco_cfg_params_t *ecoConfig); -void Cy_BLE_EcoStop(void); - -/** @} */ - - -/*************************************** -* Private Function Prototypes -***************************************/ -uint8_t Cy_BLE_HAL_IsEcoCpuClockSrc(void); -uint8_t Cy_BLE_HAL_IsWcoLfclkSrc(void); -uint32_t Cy_BLE_HAL_EcoGetFrequency(void); -void Cy_BLE_HAL_Init(void); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CY_BLE_CLK_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cps.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cps.c deleted file mode 100644 index 5f7ad5e4f4..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cps.c +++ /dev/null @@ -1,2226 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cps.c -* \version 2.0 -* -* \brief -* Contains the source code for Cycling Power Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CPS)) - -static cy_ble_callback_t Cy_BLE_CPS_ApplCallback = NULL; - -#ifdef CY_BLE_CPS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_cpssReqHandle; - -cy_stc_ble_cps_cp_adjustment_t cy_ble_cpssAdjustment; -static uint8_t cy_ble_cpssFlag; -static cy_stc_ble_gap_conn_param_updated_in_controller_t cy_ble_cpssConnParam; -#endif /* CY_BLE_CPS_SERVER */ - -#ifdef CY_BLE_CPS_CLIENT -/* CPS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_cpsc_t cy_ble_cpsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_cpscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -static uint8_t cy_ble_cpscFlag[CY_BLE_CONFIG_GATTC_COUNT]; -static cy_stc_ble_timer_info_t cy_ble_cpscCpTimeout[CY_BLE_CONFIG_GATTC_COUNT]; -static uint8_t cy_ble_cpscObserverFlag; -#endif /* (CY_BLE_CPS_CLIENT) */ - -#if CY_BLE_GAP_ROLE_BROADCASTER -cy_stc_ble_gapp_disc_param_t cy_ble_cpssBroadcastParam; -cy_stc_ble_gapp_disc_data_t cy_ble_cpssBroadcastData = -{ - { /* Length, FLAGS, BR/EDR NOT Supported */ - CY_BLE_GAP_ADV_FLAGS_PACKET_LENGTH, (uint8_t)CY_BLE_GAP_ADV_FLAGS, CY_BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED, - - /* Advertising Interval data type contains the advInterval value */ - CY_BLE_GAP_ADV_ADVERT_INTERVAL_PACKET_LENGTH, (uint8_t)CY_BLE_GAP_ADV_ADVERT_INTERVAL, - CY_LO8(CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN), CY_HI8(CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN), - - /* The Service Data data type consists of a CPS service UUID with the Cycling Power Measurement - * characteristic value */ - CY_BLE_CPSS_BROADCAST_DATA_LEN_MIN, /* Packet length */ - (uint8_t)CY_BLE_GAP_ADV_SRVC_DATA_16UUID, /* Service Data */ - CY_LO8(CY_BLE_UUID_CPS_SERVICE), CY_HI8(CY_BLE_UUID_CPS_SERVICE), /* CPS service UUID */ - 0x00u, 0x00u, /* Flags */ - 0x11u, 0x11u, /* Instantaneous Power */ - 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, - 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u - }, - - /* Advertising data length */ - CY_BLE_CPSS_BROADCAST_DATA_LEN_MIN + CY_BLE_CPSS_BROADCAST_HEADER_LEN, -}; - -cy_stc_ble_gapp_disc_mode_info_t cy_ble_cpssBroadcastModeInfo = -{ - CY_BLE_GAPP_NONE_DISC_BROADCAST_MODE, /* discMode */ - &cy_ble_cpssBroadcastParam, - &cy_ble_cpssBroadcastData, - NULL, - 0u, /* advTo */ -}; -#endif /* CY_BLE_GAP_ROLE_BROADCASTER */ - -/* The pointer on global BLE CPS Config structure */ -cy_stc_ble_cps_config_t *cy_ble_cpsConfigPtr; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_CPS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_CPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_CPSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_CPSS_ConnParamUpdateRspEventHandler(const cy_stc_ble_l2cap_conn_update_rsp_param_t *eventParam); -static void Cy_BLE_CPSS_ConnUpdateCompleteEventHandler(const cy_stc_ble_gap_conn_param_updated_in_controller_t - *eventParam); - -#if CY_BLE_GAP_ROLE_BROADCASTER -static void Cy_BLE_CPSS_AdvertisementStartStopEventHandler(void); -#endif /* CY_BLE_GAP_ROLE_BROADCASTER */ -#endif /* CY_BLE_CPS_SERVER */ - -#ifdef CY_BLE_CPS_CLIENT -static void Cy_BLE_CPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_CPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_CPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_CPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_CPSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_CPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_CPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_CPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_CPSC_ScanStartStopEventHandler(void); -static void Cy_BLE_CPSC_ScanProcessEventHandler(cy_stc_ble_gapc_adv_report_param_t *eventParam); -static void Cy_BLE_CPSC_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam); -#endif /* (CY_BLE_CPS_CLIENT) */ - -static cy_en_ble_gatt_err_code_t Cy_BLE_CPS_EventHandler(uint32_t eventCode, void *eventParam); - - -#ifdef CY_BLE_CPS_SERVER -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_Init -***************************************************************************//** -* -* This function initializes CPS Service in Server role. -* -******************************************************************************/ -void Cy_BLE_CPSS_Init(void) -{ - cy_ble_cpssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_cpssFlag = 0u; -} - -#endif /* CY_BLE_CPS_SERVER */ - -/****************************************************************************** -* Function Name: Cy_BLE_CPS_Init -***************************************************************************//** -* -* This function initializes CPS Service. -* -* \param config: Configuration structure for CPS Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPS_Init(cy_stc_ble_cps_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_cpsConfigPtr = config; - - /* Registers Event Handler for the ANCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CPS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_cpsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_CPS_ApplCallback = cy_ble_cpsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_CPS_SERVER - Cy_BLE_CPSS_Init(); - cy_ble_cpssAdjustment.samplingRate = CY_BLE_CPS_SAMLING_RATE_DEFAULT; - #endif /* CY_BLE_CPS_SERVER */ - - #ifdef CY_BLE_CPS_CLIENT - { - uint32_t idx; - cy_ble_cpscObserverFlag = 0u; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_CPS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_cpsc[idx], 0, sizeof(cy_stc_ble_cpsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_CPS].uuid = CY_BLE_UUID_CPS_SERVICE; - } - cy_ble_cpscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_cpscFlag[idx] = 0u; - cy_ble_cpscCpTimeout[idx].timeout = CY_BLE_CPS_CP_PROCEDURE_TIMEOUT; - } - } - #endif /* CY_BLE_CPS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for CPS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_CPS_ApplCallback = callbackFunc; - if(cy_ble_cpsConfigPtr != NULL) - { - cy_ble_cpsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_CPS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service in the local database. -* -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_SetCharacteristicValue(cy_en_ble_cps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_CPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the service, which is a value identified by charIndex. -* -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_GetCharacteristicValue(cy_en_ble_cps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_CPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - /* Read characteristic value from database */ - { - .handleValuePair.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_cps_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data that should -* be stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (descrIndex >= CY_BLE_CPS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_cps_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (descrIndex >= CY_BLE_CPS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_WriteEventHandler -***************************************************************************//** -* -* Handles Write Request Event for CPS service. -* -* \param void *eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - write is successful -* * CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_cps_char_index_t locCharIndex; - cy_stc_ble_cps_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint8_t locReqHandle = 0u; - - if(Cy_BLE_CPS_ApplCallback != NULL) - { - /* Error conditions for CP Characteristic value write request */ - if((eventParam->handleValPair.attrHandle == cy_ble_cpsConfigPtr->cpss->charInfo[CY_BLE_CPS_POWER_CP].charHandle) && - (!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_cpsConfigPtr->cpss->charInfo[CY_BLE_CPS_POWER_CP]. - descrHandle[CY_BLE_CPS_CCCD]))) - { - gattErr = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if((eventParam->handleValPair.attrHandle == - cy_ble_cpsConfigPtr->cpss->charInfo[CY_BLE_CPS_POWER_CP].charHandle) && - ((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS) != 0u)) - { - gattErr = CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; (locCharIndex < CY_BLE_CPS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if((eventParam->handleValPair.attrHandle == cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex]. - descrHandle[CY_BLE_CPS_CCCD]) || - (eventParam->handleValPair.attrHandle == cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex]. - descrHandle[CY_BLE_CPS_SCCD]) || - (eventParam->handleValPair.attrHandle == cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex].charHandle)) - { - /* Store value to database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - /* Clear event handled flag to send Write response */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - locReqHandle = 1u; - - locCharValue.charIndex = locCharIndex; - locCharValue.value = &eventParam->handleValPair.value; - - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - /* Characteristic value write request */ - if(eventParam->handleValPair.attrHandle == - cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex].charHandle) - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_WRITE_CHAR, &locCharValue); - - /* In the context of the Cycling Power Control Point characteristic, a procedure is started - * when a write to the Cycling Power Control Point characteristic is successfully completed - */ - if(locCharIndex == CY_BLE_CPS_POWER_CP) - { - cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS; - } - } - - /* Client Characteristic Configuration descriptor write request */ - else if(eventParam->handleValPair.attrHandle == - cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex].descrHandle[CY_BLE_CPS_CCCD]) - { - /* Check characteristic properties for Notification */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex]. - charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - uint16_t requiredConnIntv; - uint8_t prefConnParamCharValue[CY_BLE_PPCPC_LEN]; - requiredConnIntv = CY_BLE_CPS_SAMLING_RATE_TO_CONN_INTV / - cy_ble_cpssAdjustment.samplingRate; - - /* Cycling Power Vector characteristic has special behavior - * described in CPS specification, section 3.5.1 */ - if((locCharIndex == CY_BLE_CPS_POWER_VECTOR) && - (cy_ble_cpssConnParam.connIntv > requiredConnIntv)) - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfoCCCD = - { - .handleValuePair.attrHandle = cy_ble_configPtr->gaps->prefConnParamCharHandle, - .handleValuePair.value.len = sizeof(prefConnParamCharValue), - .handleValuePair.value.val = prefConnParamCharValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfoCCCD) == - CY_BLE_GATT_ERR_NONE) - { - /* If the current connection parameters do not allow sending of - * notification, request new connection parameters by using the GAP - * Connection Parameter Update procedure. - */ - cy_stc_ble_gap_conn_update_param_info_t connUpdateParam = - { - /* Send Connection Parameter Update Request to Client */ - .connIntvMin = requiredConnIntv, - .connIntvMax = requiredConnIntv, - .connLatency = Cy_BLE_Get16ByPtr(prefConnParamCharValue + - CY_BLE_PPCPC_SLAVE_LATENCY_OFFSET), - .supervisionTO = Cy_BLE_Get16ByPtr(prefConnParamCharValue + - CY_BLE_PPCPC_SUP_TIMEOUT_OFFSET), - .bdHandle = eventParam->connHandle.bdHandle - }; - - if(Cy_BLE_L2CAP_LeConnectionParamUpdateRequest(&connUpdateParam) - == CY_BLE_SUCCESS) - { - cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS; - - /* Set event handled flag to not send Write response. Response will be - * sent when Central accept the request for connection parameter update - * in Cy_BLE_CPSS_ConnParamUpdateRspEventHandler function. - */ - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - } - } - } - else - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_NOTIFICATION_ENABLED, - &locCharValue); - } - } - else - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_NOTIFICATION_DISABLED, - &locCharValue); - } - } - - /* Check characteristic properties for Indication */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex].charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_INDICATION_ENABLED, &locCharValue); - } - else - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_INDICATION_DISABLED, &locCharValue); - } - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - /* Server Characteristic Configuration descriptor write request */ - else - { - /* Check characteristic properties for Broadcast */ - if(CY_BLE_IS_BROADCAST_SUPPORTED(cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex]. - charHandle)) - { - if(CY_BLE_IS_BROADCAST_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_BROADCAST_ENABLED, &locCharValue); - } - else - { - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_BROADCAST_DISABLED, &locCharValue); - } - } - } - } - } - } - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_SendNotification -***************************************************************************//** -* -* Sends notification with a characteristic value of the CPS, which is a value -* specified by charIndex, to the Client device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_CPSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the Client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_CPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((!CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle)) || - (!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_cpsConfigPtr->cpss->charInfo[charIndex]. - descrHandle[CY_BLE_CPS_CCCD]))) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to the Client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_SendIndication -***************************************************************************//** -* -* Sends indication with a characteristic value of the CPS, which is a value -* specified by charIndex, to the Client device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_CPSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the Client -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CPS service-specific callback is registered -* (with Cy_BLE_CPS_RegisterAttrCallback): -* * CY_BLE_EVT_CPSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the CPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_CPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((!CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle)) || - (!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_cpsConfigPtr->cpss->charInfo[charIndex]. - descrHandle[CY_BLE_CPS_CCCD]))) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send indication to Client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - /* Save handle to support service-specific value confirmation response from Client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* *eventParam - Pointer to a structure of type 'cy_stc_ble_conn_handle_t'. -* -******************************************************************************/ -static void Cy_BLE_CPSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_en_ble_cps_char_index_t locCharIndex; - cy_stc_ble_cps_char_value_t locCharValue = { .connHandle = *eventParam }; - uint8_t locReqHandle = 0u; - - if((Cy_BLE_CPS_ApplCallback != NULL) && (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_cpssReqHandle)) - { - for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; (locCharIndex < CY_BLE_CPS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_cpssReqHandle == cy_ble_cpsConfigPtr->cpss->charInfo[locCharIndex].charHandle) - { - locCharValue.charIndex = locCharIndex; - locCharValue.value = NULL; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_cpssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* The Cycling Power Control Point procedure is complete when the Server indicated with the Op Code - * set to Response Code. - */ - if(locCharIndex == CY_BLE_CPS_POWER_CP) - { - cy_ble_cpssFlag &= (uint8_t) ~CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS; - } - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_INDICATION_CONFIRMED, &locCharValue); - locReqHandle = 1u; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_ConnParamUpdateRspEventHandler -***************************************************************************//** -* -* Handles the L2CAP connection parameter response event from -* the BLE stack. -* -* \param uint16_t response: -* * Accepted = 0x0000 -* * Rejected = 0x0001 -* -******************************************************************************/ -static void Cy_BLE_CPSS_ConnParamUpdateRspEventHandler(const cy_stc_ble_l2cap_conn_update_rsp_param_t *eventParam) -{ - if((Cy_BLE_CPS_ApplCallback != NULL) && ((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS) != 0u)) - { - cy_stc_ble_conn_handle_t locConnHandle = - { - .bdHandle = eventParam->bdHandle - }; - - cy_ble_cpssFlag &= (uint8_t) ~CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS; - if(eventParam->result != 0u) - { - /* If the Client does not change the connection parameters Server shall return an ATT Error Response - * to the Write Request with an Error Code set to the Application Error Code 0x80 - * (Inappropriate Connection Parameters). */ - cy_stc_ble_gatt_err_param_t err_param = - { - .errInfo.opCode = (cy_en_ble_gatt_pdu_t)CY_BLE_GATT_WRITE_REQ, - .errInfo.attrHandle = cy_ble_cpsConfigPtr->cpss->charInfo[CY_BLE_CPS_POWER_VECTOR]. - descrHandle[CY_BLE_CPS_CCCD], - .errInfo.errorCode = CY_BLE_GATT_ERR_CPS_INAPPROPRIATE_CONNECTION_PARAMETERS, - /* get connHandle form cy_ble_connHandle, to have actual value of connHandle.attId */ - .connHandle = cy_ble_connHandle[Cy_BLE_GetConnHandleIdx(locConnHandle)] - }; - /* Send Error Response */ - (void)Cy_BLE_GATTS_ErrorRsp(&err_param); - } - else - { - cy_stc_ble_cps_char_value_t locCharValue = - { - .connHandle = cy_ble_connHandle[Cy_BLE_GetConnHandleIdx(locConnHandle)], - .charIndex = CY_BLE_CPS_POWER_VECTOR - }; - - cy_stc_ble_gatt_value_t locValue; - uint8_t cccdVal[2u]; - Cy_BLE_Set16ByPtr(cccdVal, CY_BLE_CCCD_NOTIFICATION); - - /* Otherwise, the Server shall respond with a Write Response and start sending notifications - * of the Cycling Power Vector characteristic. */ - (void)Cy_BLE_GATTS_WriteRsp(locConnHandle); - - /* get connHandle form cy_ble_connHandle, to have actual value of connHandle.attId */ - locValue.len = CY_BLE_CCCD_LEN; - locValue.val = cccdVal; - locCharValue.value = &locValue; - - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_NOTIFICATION_ENABLED, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_ConnUpdateCompleteEventHandler -***************************************************************************//** -* -* Handles the CY_BLE_EVT_GAP_CONNECTION_UPDATE_COMPLETE event from -* the BLE stack. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CPSS_ConnUpdateCompleteEventHandler(const cy_stc_ble_gap_conn_param_updated_in_controller_t *eventParam) -{ - /* Store connection parameters */ - cy_ble_cpssConnParam = *eventParam; -} - -#if CY_BLE_GAP_ROLE_BROADCASTER - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_StartBroadcast -***************************************************************************//** -* -* This function is used to start broadcasting of the Cycling Power -* Measurement characteristic or update broadcasting data when it was started -* before. -* -* It is available only in Broadcaster role. -* -* \param advInterval: Advertising interval in 625 us units. The valid range is -* from CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN -* to CY_BLE_GAP_ADV_ADVERT_INTERVAL_MAX. This parameter is ignored -* when when broadcasting is already started. -* \param attrSize: The size of the characteristic value attribute. -* This size is limited by maximum advertising packet length and -* advertising header size. -* \param attrValue: The pointer to the Cycling Power Measurement characteristic -* that include the mandatory fields (e.g. the Flags field and the -* Instantaneous Power field) and depending on the Flags field, -* some optional fields in a non connectable undirected advertising -* event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On passing an invalid parameter. -* CY_BLE_ERROR_INVALID_OPERATION | Operation is not permitted. -* -******************************************************************************/ - -cy_en_ble_api_result_t Cy_BLE_CPSS_StartBroadcast(uint16_t advInterval, - uint8_t attrSize, - const uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((advInterval < CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN) || (advInterval > CY_BLE_GAP_ADV_ADVERT_INTERVAL_MAX) || - (attrSize > (CY_BLE_GAP_MAX_ADV_DATA_LEN - CY_BLE_CPSS_BROADCAST_HEADER_LEN))) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Copy Cycling Power Measurement characteristic value to advertising data packet */ - (void)memcpy(&cy_ble_cpssBroadcastData.advData[CY_BLE_CPSS_BROADCAST_DATA_OFFSET], attrValue, (uint32_t)attrSize); - cy_ble_cpssBroadcastData.advData[CY_BLE_CPSS_BROADCAST_DATA_LEN_OFFSET] = attrSize; - cy_ble_cpssBroadcastData.advDataLen = attrSize + CY_BLE_CPSS_BROADCAST_HEADER_LEN; - - if((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_BROADCAST_IN_PROGRESS) == 0u) - { - /* Put advertising interval to advertising data packet */ - cy_ble_cpssBroadcastData.advData[CY_BLE_CPSS_BROADCAST_ADVERT_INTERVAL_OFFSET] = CY_LO8(advInterval); - cy_ble_cpssBroadcastData.advData[CY_BLE_CPSS_BROADCAST_ADVERT_INTERVAL_OFFSET + 1u] = CY_HI8(advInterval); - - /* Configure advertising timeout, interval and type */ - cy_ble_cpssBroadcastParam.advIntvMin = advInterval; - cy_ble_cpssBroadcastParam.advIntvMax = advInterval; - cy_ble_cpssBroadcastModeInfo.advTo = 0u; - cy_ble_cpssBroadcastParam.advType = CY_BLE_GAPP_NON_CONNECTABLE_UNDIRECTED_ADV; - cy_ble_cpssBroadcastParam.advChannelMap = cy_ble_discoveryParam[cy_ble_advIndex].advChannelMap; - - /* Start broadcasting */ - apiResult = Cy_BLE_GAPP_EnterDiscoveryMode(&cy_ble_cpssBroadcastModeInfo); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_START_BROADCAST; - } - } - else - { - /* Update the advertisement packet if the device is in the advertising mode. */ - apiResult = Cy_BLE_GAPP_UpdateAdvScanData(&cy_ble_cpssBroadcastModeInfo); - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_StopBroadcast -***************************************************************************//** -* -* This function is used to stop broadcasting of the Cycling Power -* Measurement characteristic. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in CPS broadcasting mode. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSS_StopBroadcast(void) -{ - cy_en_ble_api_result_t apiResult; - - if((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_BROADCAST_IN_PROGRESS) != 0u) - { - apiResult = Cy_BLE_GAPP_ExitDiscoveryMode(); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_STOP_BROADCAST; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSS_AdvertisementStartStopEventHandler -***************************************************************************//** -* -* This function handles CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP event for CPS. -* -******************************************************************************/ -static void Cy_BLE_CPSS_AdvertisementStartStopEventHandler(void) -{ - if((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_START_BROADCAST) != 0u) - { - cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_BROADCAST_IN_PROGRESS; - cy_ble_cpssFlag &= (uint8_t) ~CY_BLE_CPSS_FLAG_START_BROADCAST; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - if((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_STOP_BROADCAST) != 0u) - { - cy_ble_cpssFlag &= (uint8_t) ~(CY_BLE_CPSS_FLAG_BROADCAST_IN_PROGRESS | CY_BLE_CPSS_FLAG_STOP_BROADCAST); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -#endif /* CY_BLE_GAP_ROLE_BROADCASTER */ - -#endif /* CY_BLE_CPS_SERVER */ - -#ifdef CY_BLE_CPS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_CPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* CPS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_cpscCharUuid[CY_BLE_CPS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_CPS_MSRMT, /* Cycling Power Measurement characteristic UUID */ - CY_BLE_UUID_CHAR_CPS_FEATURE, /* Cycling Power Feature characteristic UUID */ - CY_BLE_UUID_CHAR_SENSOR_LOCATION, /* Cycling Power Sensor Location characteristic UUID */ - CY_BLE_UUID_CHAR_CPS_VECTOR, /* Cycling Power Vector characteristic UUID */ - CY_BLE_UUID_CHAR_CPS_CP /* Cycling Power Control Point characteristic UUID */ - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CPS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = (uint32_t)CY_BLE_CPS_POWER_MEASURE; i < (uint32_t)CY_BLE_CPS_CHAR_COUNT; i++) - { - if(cy_ble_cpscCharUuid[i] == discCharInfo->uuid.uuid16) - { - Cy_BLE_CheckStoreCharHandle(cy_ble_cpsc[discIdx].charInfo[i]); - lastEndHandle[discIdx] = &cy_ble_cpsc[discIdx].charInfo[i].endHandle; - break; - } - } - - /* Init characteristic endHandle to the Service endHandle. - * Characteristic endHandle will be updated to declaration - * handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_FIND_INFO_RSP" event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discoveryCharIndex: The characteristic index which is discovered. -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_CPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CPS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_CPS_CCCD; - break; - - case CY_BLE_UUID_CHAR_SERVER_CONFIG: - descIdx = (uint32_t)CY_BLE_CPS_SCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_cpsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_cpsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_CPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CPS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_CPS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_cpsc[discIdx].charInfo[charIdx].endHandle - - cy_ble_cpsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_cpsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_cpsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_CPSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that -* should be send to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CPS service-specific callback is registered -* (with Cy_BLE_CPS_RegisterAttrCallback): -* * CY_BLE_EVT_CPSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cps_char_value_t. -* . -* Otherwise (if the CPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cpsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_cpsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - /* Start CP procedure. It will ends when the Collector sends a confirmation to acknowledge the CP - * indication sent by the CP Sensor. A procedure is considered to have timed out if a CP indication - * is not received within the ATT transaction timeout, defined as 30 seconds. - * CY_BLE_EVT_CPSC_TIMEOUT event with cy_stc_ble_cps_char_value_t parameter will indicate about CP - * procedure timeout. - */ - if(charIndex == CY_BLE_CPS_POWER_CP) - { - apiResult = Cy_BLE_StartTimer(&cy_ble_cpscCpTimeout[discIdx]); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpscFlag[discIdx] |= CY_BLE_CPSC_FLAG_CP_PROCEDURE_IN_PROGRESS; - } - } - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value identified by -* charIndex, from the server. -* -* The Read Response returns the characteristic Value in the Attribute Value -* parameter. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CPS service-specific callback is registered -* (with Cy_BLE_CPS_RegisterAttrCallback): -* * CY_BLE_EVT_CPSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cps_char_value_t. -* . -* Otherwise (if the CPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_cpsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_cpsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpscReqHandle[discIdx] = cy_ble_cpsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the server -* which is identified by charIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_CPSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_CPSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_CPSS_INDICATION_ENABLED -* * CY_BLE_EVT_CPSS_INDICATION_DISABLED -* * CY_BLE_EVT_CPSS_BROADCAST_ENABLED -* * CY_BLE_EVT_CPSS_BROADCAST_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type cy_en_ble_cps_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type cy_en_ble_cps_descr_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CPS service-specific callback is registered -* (with Cy_BLE_CPS_RegisterAttrCallback): -* * CY_BLE_EVT_CPSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cps_descr_value_t. -* . -* Otherwise (if the CPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (descrIndex >= CY_BLE_CPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_cpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_cps_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_cps_descr_index_t. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CPS service-specific callback is registered -* (with Cy_BLE_CPS_RegisterAttrCallback): -* * CY_BLE_EVT_CPSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_cps_descr_value_t. -* . -* Otherwise (if the CPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (descrIndex >= CY_BLE_CPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_cpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpscReqHandle[discIdx] = cy_ble_cpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_TimeOutEventHandler -***************************************************************************//** -* -* Handles Timer Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam) -{ - if(((eventParam)->reasonCode == CY_BLE_GENERIC_APP_TO) && (Cy_BLE_CPS_ApplCallback != NULL)) - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(((cy_ble_cpscFlag[idx] & CY_BLE_CPSC_FLAG_CP_PROCEDURE_IN_PROGRESS) != 0u) && - (eventParam->timerHandle == cy_ble_cpscCpTimeout[idx].timerHandle)) - { - cy_stc_ble_cps_char_value_t timeoutValue = - { - .connHandle = cy_ble_connHandle[cy_ble_discovery[idx].connIndex], - .charIndex = CY_BLE_CPS_POWER_CP - }; - - cy_ble_cpscFlag[idx] &= (uint8_t) ~CY_BLE_CPSC_FLAG_CP_PROCEDURE_IN_PROGRESS; - cy_ble_cpscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_TIMEOUT, &timeoutValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_NotificationEventHandler -***************************************************************************//** -* -* Handles Notification Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - cy_en_ble_cps_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CPS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; locCharIndex < CY_BLE_CPS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_cpsc[discIdx].charInfo[locCharIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_cps_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_IndicationEventHandler -***************************************************************************//** -* -* Handles Indication Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - cy_en_ble_cps_char_index_t locCharIndex; - cy_stc_ble_cps_char_value_t indicationValue = { .connHandle = eventParam->connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CPS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; locCharIndex < CY_BLE_CPS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_cpsc[discIdx].charInfo[locCharIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - /* Stop the timer. CP procedure is finished when received indication sent by the CP Sensor. */ - if((cy_ble_cpscReqHandle[discIdx] == cy_ble_cpsc[discIdx].charInfo[CY_BLE_CPS_POWER_CP].valueHandle) && - ((cy_ble_cpscFlag[discIdx] & CY_BLE_CPSC_FLAG_CP_PROCEDURE_IN_PROGRESS) != 0u)) - { - (void)Cy_BLE_StopTimer(&cy_ble_cpscCpTimeout[discIdx]); - cy_ble_cpscFlag[discIdx] &= (uint8_t) ~CY_BLE_CPSC_FLAG_CP_PROCEDURE_IN_PROGRESS; - } - - indicationValue.charIndex = locCharIndex; - indicationValue.value = &eventParam->handleValPair.value; - - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles Read Response Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t locReqHandle = 0u; - cy_en_ble_cps_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CPS_ApplCallback != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_cpscReqHandle[discIdx])) - { - for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; (locCharIndex < CY_BLE_CPS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_cpscReqHandle[discIdx] == cy_ble_cpsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_cps_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - cy_ble_cpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_cps_descr_index_t locDescIndex; - - for(locDescIndex = CY_BLE_CPS_CCCD; (locDescIndex < CY_BLE_CPS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_cpscReqHandle[discIdx] == cy_ble_cpsc[discIdx].charInfo[locCharIndex]. - descrHandle[locDescIndex]) - { - cy_stc_ble_cps_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = &eventParam->value - }; - - cy_ble_cpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint8_t locReqHandle = 0u; - cy_en_ble_cps_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CPS_ApplCallback != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_cpscReqHandle[discIdx])) - { - for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; (locCharIndex < CY_BLE_CPS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_cpscReqHandle[discIdx] == cy_ble_cpsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_cps_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .value = NULL - }; - - cy_ble_cpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_WRITE_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_cps_descr_index_t locDescIndex; - - for(locDescIndex = CY_BLE_CPS_CCCD; (locDescIndex < CY_BLE_CPS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_cpscReqHandle[discIdx] == cy_ble_cpsc[discIdx].charInfo[locCharIndex]. - descrHandle[locDescIndex]) - { - cy_stc_ble_cps_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = NULL - }; - - cy_ble_cpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles Error Response Event. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_cpscReqHandle[discIdx]) - { - cy_ble_cpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_StartObserve -***************************************************************************//** -* -* This function is used for observing GAP peripheral devices. -* A device performing the observer role receives only advertisement data from -* devices irrespective of their discoverable mode settings. Advertisement -* data received is provided by the event, CY_BLE_EVT_CPSC_SCAN_PROGRESS_RESULT. -* This procedure sets the scanType sub parameter to passive scanning. -* -* If 'scanTo' sub-parameter is set to zero value, then passive scanning -* procedure will continue until you call Cy_BLE_CPSC_StopObserve(). -* Possible generated events are: -* * CY_BLE_EVT_CPSC_SCAN_PROGRESS_RESULT -* -* \param scanParamIndex: The index of the scan configuration. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for -* | 'scanInfo' or if any element within 'scanInfo' has an invalid value. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSC_StartObserve(uint8_t scanParamIndex) -{ - cy_en_ble_api_result_t apiResult; - cy_stc_ble_gapc_disc_info_t locDiscoveryInfo = - { - .discProcedure = CY_BLE_GAPC_OBSER_PROCEDURE, - .scanType = CY_BLE_GAPC_PASSIVE_SCANNING, - .scanIntv = cy_ble_configPtr->gapcScanParams[scanParamIndex].fastScanInterval, - .scanWindow = cy_ble_configPtr->gapcScanParams[scanParamIndex].fastScanWindow, - .ownAddrType = CY_BLE_GAP_ADDR_TYPE_PUBLIC, - .scanFilterPolicy = CY_BLE_GAPC_ADV_ACCEPT_ALL_PKT, - .scanTo = 0u, /* Disable Timeout */ - .filterDuplicates = CY_BLE_GAPC_FILTER_DUP_DISABLE - }; - - apiResult = Cy_BLE_GAPC_StartDiscovery(&locDiscoveryInfo); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cpscObserverFlag |= CY_BLE_CPSC_FLAG_START_OBSERVE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_StopObserve -***************************************************************************//** -* -* This function used to stop the discovery of devices. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in CPS observing state. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CPSC_StopObserve(void) -{ - cy_en_ble_api_result_t apiResult; - - if((cy_ble_cpscObserverFlag & CY_BLE_CPSC_FLAG_OBSERVE_IN_PROGRESS) != 0u) - { - apiResult = Cy_BLE_GAPC_StopDiscovery(); - cy_ble_cpscObserverFlag |= CY_BLE_CPSC_FLAG_STOP_OBSERVE; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_ScanStartStopEventHandler -***************************************************************************//** -* -* This function handles CY_BLE_EVT_GAPC_SCAN_START_STOP event for CPS. -* -******************************************************************************/ -static void Cy_BLE_CPSC_ScanStartStopEventHandler(void) -{ - if((cy_ble_cpscObserverFlag & CY_BLE_CPSC_FLAG_START_OBSERVE) != 0u) - { - cy_ble_cpscObserverFlag |= CY_BLE_CPSC_FLAG_OBSERVE_IN_PROGRESS; - cy_ble_cpscObserverFlag &= (uint8_t) ~CY_BLE_CPSC_FLAG_START_OBSERVE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - if((cy_ble_cpscObserverFlag & CY_BLE_CPSC_FLAG_STOP_OBSERVE) != 0u) - { - cy_ble_cpscObserverFlag &= (uint8_t) ~(CY_BLE_CPSC_FLAG_OBSERVE_IN_PROGRESS | CY_BLE_CPSC_FLAG_STOP_OBSERVE); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CPSC_ScanProcessEventHandler -***************************************************************************//** -* -* This function handles CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT event for CPS. -* -* \param eventParam: the pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CPSC_ScanProcessEventHandler(cy_stc_ble_gapc_adv_report_param_t *eventParam) -{ - if((cy_ble_cpscObserverFlag & CY_BLE_CPSC_FLAG_OBSERVE_IN_PROGRESS) != 0u) - { - if(eventParam->eventType == CY_BLE_GAPC_NON_CONN_UNDIRECTED_ADV) - { - if(Cy_BLE_CPS_ApplCallback != NULL) - { - cy_stc_ble_cps_char_value_t broadcastValue; - cy_stc_ble_gatt_value_t locCharValue; - uint8_t advIndex = 0u; - do - { - /* Show Cycling Power Measurement characteristic value from Service Data packet. */ - if((eventParam->data[advIndex] > CY_BLE_CPSC_BROADCAST_DATA_OFFSET) && - (eventParam->data[advIndex + 1u] == (uint8_t)CY_BLE_GAP_ADV_SRVC_DATA_16UUID)) - { - broadcastValue.peerAddrType = eventParam->peerAddrType; - broadcastValue.peerBdAddr = eventParam->peerBdAddr; - broadcastValue.charIndex = CY_BLE_CPS_POWER_MEASURE; - broadcastValue.value = &locCharValue; - locCharValue.val = &eventParam->data[advIndex + CY_BLE_CPSC_BROADCAST_DATA_OFFSET]; - locCharValue.len = (uint16_t)eventParam->data[advIndex] - (CY_BLE_CPSC_BROADCAST_DATA_OFFSET - 1u); - Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSC_SCAN_PROGRESS_RESULT, &broadcastValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - advIndex += eventParam->data[advIndex] + 1u; - } - while(advIndex < eventParam->dataLen); - } - } - else /* Filter for all connectable advertising packets */ - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -#endif /* (CY_BLE_CPS_CLIENT) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_CPS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Cycling Power Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CPS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_CPS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_CPSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_CPSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_CPSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_CPS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - case CY_BLE_EVT_GATT_DISCONNECT_IND: - #ifdef CY_BLE_CPS_SERVER - #if CY_BLE_GAP_ROLE_BROADCASTER - (void)Cy_BLE_CPSS_DisconnectEventHandler(); - #endif /* CY_BLE_GAP_ROLE_BROADCASTER */ - #endif /* CY_BLE_CPS_SERVER */ - - #ifdef CY_BLE_CPS_CLIENT - (void)Cy_BLE_CPSC_DisconnectEventHandler(); - #endif /* CY_BLE_ _CLIENT */ - break; - - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_CPS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_CPSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_CPSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATT_CONNECT_IND: - Cy_BLE_CPSS_ConnectEventHandler(); - break; - - case CY_BLE_EVT_L2CAP_CONN_PARAM_UPDATE_RSP: - Cy_BLE_CPSS_ConnParamUpdateRspEventHandler((cy_stc_ble_l2cap_conn_update_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GAP_CONNECTION_UPDATE_COMPLETE: - Cy_BLE_CPSS_ConnUpdateCompleteEventHandler((cy_stc_ble_gap_conn_param_updated_in_controller_t*)eventParam); - break; - - case CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP: - #if (CY_BLE_GAP_ROLE_BROADCASTER) - Cy_BLE_CPSS_AdvertisementStartStopEventHandler(); - #endif /* CY_BLE_GAP_ROLE_BROADCASTER */ - break; - #endif /* CY_BLE_CPS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_CPS_CLIENT - case CY_BLE_EVT_GAPC_SCAN_START_STOP: - Cy_BLE_CPSC_ScanStartStopEventHandler(); - break; - - case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT: - Cy_BLE_CPSC_ScanProcessEventHandler((cy_stc_ble_gapc_adv_report_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_CPSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_CPSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_CPSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_CPSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_CPSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_TIMEOUT: - Cy_BLE_CPSC_TimeOutEventHandler((cy_stc_ble_timeout_param_t*)eventParam); - break; - #endif /* CY_BLE_CPS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_CPS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ - diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cps.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cps.h deleted file mode 100644 index eace46c4c7..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cps.h +++ /dev/null @@ -1,483 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cps.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Cycling Power Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_CPS_H -#define CY_BLE_CPS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CPS)) - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Data Types -***************************************/ - -/** - * \addtogroup group_ble_service_api_CPS_definitions - * @{ - */ - -/** Characteristic indexes */ -typedef enum -{ - CY_BLE_CPS_POWER_MEASURE, /**< Cycling Power Measurement characteristic index */ - CY_BLE_CPS_POWER_FEATURE, /**< Cycling Power Feature characteristic index */ - CY_BLE_CPS_SENSOR_LOCATION, /**< Sensor Location characteristic index */ - CY_BLE_CPS_POWER_VECTOR, /**< Cycling Power Vector characteristic index */ - CY_BLE_CPS_POWER_CP, /**< Cycling Power Control Point characteristic index */ - CY_BLE_CPS_CHAR_COUNT /**< Total count of CPS characteristics */ -}cy_en_ble_cps_char_index_t; - -/** Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_CPS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_CPS_SCCD, /**< Handle of the Server Characteristic Configuration descriptor */ - CY_BLE_CPS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_cps_descr_index_t; - -/** Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_CPS_DESCR_COUNT]; /**< Handle of descriptor */ -} cy_stc_ble_cpss_char_t; - -/** Structure with Cycling Power Service attribute handles */ -typedef struct -{ - /** Cycling Power Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Cycling Power Service Characteristic handles */ - cy_stc_ble_cpss_char_t charInfo[CY_BLE_CPS_CHAR_COUNT]; -} cy_stc_ble_cpss_t; - -/** Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_CPS_DESCR_COUNT]; /**< Handles of descriptors */ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_cpsc_char_t; - -/** Structure with discovered attributes information of Cycling Power Service */ -typedef struct -{ - /** Characteristic handles array */ - cy_stc_ble_cpsc_char_t charInfo[CY_BLE_CPS_CHAR_COUNT]; -} cy_stc_ble_cpsc_t; - -/** Characteristic value parameter structure of Cycling Power Service */ -typedef struct -{ - /** Peer device handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** bd address type of the device advertising. - * - CY_BLE_GAP_ADDR_TYPE_PUBLIC - * - CY_BLE_GAP_ADDR_TYPE_RANDOM - * - CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA - * - CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA - */ - uint8_t peerAddrType; - - /** Public Device Address or Random Device Address for - * each device that responded to scanning. */ - uint8_t *peerBdAddr; - - /** Index of service characteristic */ - cy_en_ble_cps_char_index_t charIndex; - - /** Characteristic value */ - cy_stc_ble_gatt_value_t *value; -} cy_stc_ble_cps_char_value_t; - -/** Characteristic Descriptor Value parameter structure of Cycling Power Service */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_cps_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_cps_descr_index_t descrIndex; /**< Index of descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_cps_descr_value_t; - -/** Date/time structure of Cycling Power Service */ -typedef struct -{ - uint16_t year; /**< Year */ - uint8_t month; /**< Month */ - uint8_t day; /**< Day */ - uint8_t hours; /**< Time - hours */ - uint8_t minutes; /**< Time - minutes */ - uint8_t seconds; /**< Time - seconds */ -}__PACKED cy_stc_ble_cps_date_time_t; - -/** Adjustment structure of Cycling Power Service */ -typedef struct -{ - uint16_t crankLength; /**< In millimeters with a resolution of 1/2 millimeter */ - uint16_t chainLength; /**< In millimeters with a resolution of 1 millimeter */ - uint16_t chainWeight; /**< In grams with a resolution of 1 gram */ - uint16_t spanLength; /**< In millimeters with a resolution of 1 millimeter */ - cy_stc_ble_cps_date_time_t factoryCalibrationDate; /**< Use the same format as the Date Time characteristic */ - uint8_t samplingRate; /**< In Hertz with a resolution of 1 Hertz */ - int16_t offsetCompensation; /**< Either the raw force in Newton or the raw torque in 1/32 - * Newton meter based on the server capabilities. - * 0xFFFF means "Not Available" */ -}__PACKED cy_stc_ble_cps_cp_adjustment_t; - -/** Service configuration structure */ -typedef struct -{ - /** Cycling Power Service GATT DB handles structure */ - const cy_stc_ble_cpss_t *cpss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_cps_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ -/* Control Point Procedure Timeout */ -#define CY_BLE_CPS_CP_PROCEDURE_TIMEOUT (30u) /* Seconds */ - -#define CY_BLE_CPS_SAMLING_RATE_DEFAULT (25u) /* In Hertz with a resolution of 1 Hertz */ - -/* ConnIntv = 1/SampleRate(Hz)*1000ms/1.25ms(1 frame is 1.25 ms) = 800 / SampleRate */ -#define CY_BLE_CPS_SAMLING_RATE_TO_CONN_INTV (800u) - -/* Server state flags */ -#define CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS (0x01u) -#define CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS (0x02u) -#define CY_BLE_CPSS_FLAG_BROADCAST_IN_PROGRESS (0x04u) -#define CY_BLE_CPSS_FLAG_START_BROADCAST (0x08u) -#define CY_BLE_CPSS_FLAG_STOP_BROADCAST (0x10u) - -/* Client state flags */ -#define CY_BLE_CPSC_FLAG_CP_PROCEDURE_IN_PROGRESS (0x01u) -#define CY_BLE_CPSC_FLAG_OBSERVE_IN_PROGRESS (0x02u) -#define CY_BLE_CPSC_FLAG_START_OBSERVE (0x04u) -#define CY_BLE_CPSC_FLAG_STOP_OBSERVE (0x08u) - - -/** - * \addtogroup group_ble_service_api_CPS_definitions - * @{ - */ - -/* Cycling Power Feature bits */ -#define CY_BLE_CPS_CPF_PEDAL_BIT (0x01u << 0u) /**< Pedal Power Balance Supported */ -#define CY_BLE_CPS_CPF_TORQUE_BIT (0x01u << 1u) /**< Accumulated Torque Supported */ -#define CY_BLE_CPS_CPF_WHEEL_BIT (0x01u << 2u) /**< Wheel Revolution Data Supported */ -#define CY_BLE_CPS_CPF_CRANK_BIT (0x01u << 3u) /**< Crank Revolution Data Supported */ -#define CY_BLE_CPS_CPF_MAGNITUDES_BIT (0x01u << 4u) /**< Extreme Magnitudes Supported */ -#define CY_BLE_CPS_CPF_ANGLES_BIT (0x01u << 5u) /**< Extreme Angles Supported */ -#define CY_BLE_CPS_CPF_DEAD_SPOT_BIT (0x01u << 6u) /**< Top and Bottom Dead Spot Angles Supported */ -#define CY_BLE_CPS_CPF_ENERGY_BIT (0x01u << 7u) /**< Accumulated Energy Supported */ -#define CY_BLE_CPS_CPF_OFFSET_INDICATOR_BIT (0x01u << 8u) /**< Offset Compensation Indicator Supported */ -#define CY_BLE_CPS_CPF_OFFSET_BIT (0x01u << 9u) /**< Offset Compensation Supported */ -#define CY_BLE_CPS_CPF_CPM_CONTENT_MASKING_BIT (0x01u << 10u) /**< Cycling Power Measurement Characteristic - * Content Masking Supported */ -#define CY_BLE_CPS_CPF_MULTIPLE_SENSOR_BIT (0x01u << 11u) /**< Multiple Sensor Locations Supported */ -#define CY_BLE_CPS_CPF_CRANK_LEN_ADJ_BIT (0x01u << 12u) /**< Crank Length Adjustment Supported */ -#define CY_BLE_CPS_CPF_CHAIN_LEN_ADJ_BIT (0x01u << 13u) /**< Chain Length Adjustment Supported */ -#define CY_BLE_CPS_CPF_CHAIN_WEIGHT_ADJ_BIT (0x01u << 14u) /**< Chain Weight Adjustment Supported */ -#define CY_BLE_CPS_CPF_SPAN_LEN_ADJ_BIT (0x01u << 15u) /**< Span Length Adjustment Supported */ -#define CY_BLE_CPS_CPF_SENSOR_MEASURE_BIT (0x01u << 16u) /**< Sensor Measurement Context */ -#define CY_BLE_CPS_CPF_SENSOR_MEASURE_FORCE (0x00u << 16u) /**< Sensor Measurement Context: Force based */ -#define CY_BLE_CPS_CPF_SENSOR_MEASURE_TORQUE (0x01u << 16u) /**< Sensor Measurement Context: Torque based */ -#define CY_BLE_CPS_CPF_INSTANTANEOUS_DIRECTION_BIT (0x01u << 17u) /**< Instantaneous Measurement Direction Supported */ -#define CY_BLE_CPS_CPF_CALL_DATE_BIT (0x01u << 18u) /**< Factory Calibration Date Supported */ -#define CY_BLE_CPS_CPF_ENHANCED_OFFSET_BIT (0x01u << 19u) /**< Enhanced Offset Compensation Supported */ -#define CY_BLE_CPS_CPF_DISTRIBUTE_MASK (0x03u << 20u) /**< Distribute System Support */ -#define CY_BLE_CPS_CPF_DISTRIBUTE_UNSPEC (0x00u << 20u) /**< Distribute System: Unspecified (legacy sensor)*/ -#define CY_BLE_CPS_CPF_DISTRIBUTE_NOT_FOR_USE (0x01u << 20u) /**< Distribute System: Not for use */ -#define CY_BLE_CPS_CPF_DISTRIBUTE_CAN_BE_USED (0x02u << 20u) /**< Distribute System: Can be used */ - - -/* Cycling Power Measurement bits */ -#define CY_BLE_CPS_CPM_PEDAL_PRESENT_BIT (0x01u << 0u) /**< Pedal Power Balance Present */ -#define CY_BLE_CPS_CPM_PEDAL_REFERENCE_BIT (0x01u << 1u) /**< Pedal Power Balance Reference */ -#define CY_BLE_CPS_CPM_TORQUE_PRESENT_BIT (0x01u << 2u) /**< Accumulated Torque Present */ -#define CY_BLE_CPS_CPM_TORQUE_SOURCE_BIT (0x01u << 3u) /**< Accumulated Torque Source */ -#define CY_BLE_CPS_CPM_TORQUE_SOURCE_WHEEL (0x00u << 3u) /**< Accumulated Torque Source: Wheel Based */ -#define CY_BLE_CPS_CPM_TORQUE_SOURCE_CRANK (0x01u << 3u) /**< Accumulated Torque Source: Crank Based */ -#define CY_BLE_CPS_CPM_WHEEL_BIT (0x01u << 4u) /**< Wheel Revolution Data Present */ -#define CY_BLE_CPS_CPM_CRANK_BIT (0x01u << 5u) /**< Crank Revolution Data Present */ -#define CY_BLE_CPS_CPM_FORCE_MAGNITUDES_BIT (0x01u << 6u) /**< Extreme Force Magnitudes Present */ -#define CY_BLE_CPS_CPM_TORQUE_MAGNITUDES_BIT (0x01u << 7u) /**< Extreme Torque Magnitudes Present */ -#define CY_BLE_CPS_CPM_ANGLES_BIT (0x01u << 8u) /**< Extreme Angles Present */ -#define CY_BLE_CPS_CPM_TOP_DEAD_SPOT_BIT (0x01u << 9u) /**< Top Dead Spot Angle Present */ -#define CY_BLE_CPS_CPM_BOTTOM_DEAD_SPOT_BIT (0x01u << 10u) /**< Bottom Dead Spot Angle Present */ -#define CY_BLE_CPS_CPM_ENERGY_BIT (0x01u << 11u) /**< Accumulated Energy Present */ -#define CY_BLE_CPS_CPM_OFFSET_INDICATOR_BIT (0x01u << 12u) /**< Offset Compensation Indicator */ - -/* Cycling Control Point Mask of Cycling Power Measurement characteristic content */ -#define CY_BLE_CPS_CP_PEDAL_PRESENT_BIT (0x01u << 0u) /**< Pedal Power Balance Turn off */ -#define CY_BLE_CPS_CP_TORQUE_PRESENT_BIT (0x01u << 1u) /**< Accumulated Torque Turn off */ -#define CY_BLE_CPS_CP_WHEEL_BIT (0x01u << 2u) /**< Wheel Revolution Data Turn off */ -#define CY_BLE_CPS_CP_CRANK_BIT (0x01u << 3u) /**< Crank Revolution Data Turn off */ -#define CY_BLE_CPS_CP_MAGNITUDES_BIT (0x01u << 4u) /**< Extreme Magnitudes Turn off */ -#define CY_BLE_CPS_CP_ANGLES_BIT (0x01u << 5u) /**< Extreme Angles Turn off */ -#define CY_BLE_CPS_CP_TOP_DEAD_SPOT_BIT (0x01u << 6u) /**< Top Dead Spot Angle Turn off */ -#define CY_BLE_CPS_CP_BOTTOM_DEAD_SPOT_BIT (0x01u << 7u) /**< Bottom Dead Spot Angle Turn off */ -#define CY_BLE_CPS_CP_ENERGY_BIT (0x01u << 8u) /**< Accumulated Energy Turn off */ -#define CY_BLE_CPS_CP_ENERGY_RESERVED (0xFE00u) /**< Reserved bits */ - -/* Cycling Power Vector bits */ -#define CY_BLE_CPS_CPV_CRANK_DATA_BIT (0x01u << 0u) /**< Crank Revolution Data Present */ -#define CY_BLE_CPS_CPV_FIRST_CRANK_MEASURE_BIT (0x01u << 1u) /**< First Crank Measurement Angle Present */ -#define CY_BLE_CPS_CPV_INST_FORCE_MAGN_BIT (0x01u << 2u) /**< Instantaneous Force Magnitude Array Present */ -#define CY_BLE_CPS_CPV_INST_TORQUE_MAGN_BIT (0x01u << 3u) /**< Instantaneous Torque Magnitude Array Present */ -#define CY_BLE_CPS_CPV_INST_MEASURE_DIR_MASK (0x03u << 4u) /**< Instantaneous Measurement Direction */ -#define CY_BLE_CPS_CPV_INST_MEASURE_DIR_TANGENTIAL (0x01u << 4u) /**< Instantaneous Measurement Direction: Tangential*/ -#define CY_BLE_CPS_CPV_INST_MEASURE_DIR_RADIAL (0x02u << 4u) /**< Instantaneous Measurement Direction: Radial */ -#define CY_BLE_CPS_CPV_INST_MEASURE_DIR_LATERAL (0x03u << 4u) /**< Instantaneous Measurement Direction: Lateral */ - -/** Op Codes of the Cycling Power Control Point characteristic */ -typedef enum -{ - CY_BLE_CPS_CP_OC_SCV = 1u, /**< Set Cumulative Value */ - CY_BLE_CPS_CP_OC_USL = 2u, /**< Update Sensor Location */ - CY_BLE_CPS_CP_OC_RSSL = 3u, /**< Request Supported Sensor Locations */ - CY_BLE_CPS_CP_OC_SCRL = 4u, /**< Set Crank Length */ - CY_BLE_CPS_CP_OC_RCRL = 5u, /**< Request Crank Length */ - CY_BLE_CPS_CP_OC_SCHL = 6u, /**< Set Chain Length */ - CY_BLE_CPS_CP_OC_RCHL = 7u, /**< Request Chain Length */ - CY_BLE_CPS_CP_OC_SCHW = 8u, /**< Set Chain Weight */ - CY_BLE_CPS_CP_OC_RCHW = 9u, /**< Request Chain Weight */ - CY_BLE_CPS_CP_OC_SSL = 10u, /**< Set Span Length */ - CY_BLE_CPS_CP_OC_RSL = 11u, /**< Request Span Length */ - CY_BLE_CPS_CP_OC_SOC = 12u, /**< Start Offset Compensation */ - CY_BLE_CPS_CP_OC_MCPMCC = 13u, /**< Mask Cycling Power Measurement Characteristic Content */ - CY_BLE_CPS_CP_OC_RSR = 14u, /**< Request Sampling Rate */ - CY_BLE_CPS_CP_OC_RFCD = 15u, /**< Request Factory Calibration Date */ - CY_BLE_CPS_CP_OC_SEOC = 16u, /**< Start Enhanced Offset Compensation */ - CY_BLE_CPS_CP_OC_RC = 32u /**< Response Code */ -} cy_en_ble_cps_cp_oc_t; - - -/** Response Code of the Cycling Power Control Point characteristic */ -typedef enum -{ - CY_BLE_CPS_CP_RC_SUCCESS = 1u, /**< Response for successful operation. */ - CY_BLE_CPS_CP_RC_NOT_SUPPORTED, /**< Response if unsupported Op Code is received */ - CY_BLE_CPS_CP_RC_INVALID_PARAMETER, /**< Response if Parameter received does not meet the requirements of the - * service or is outside of the supported range of the Sensor */ - CY_BLE_CPS_CP_RC_OPERATION_FAILED /**< Response if the requested procedure failed */ -} cy_en_ble_cps_cp_rc_t; - -/** Sensor Location characteristic value */ -typedef enum -{ - CY_BLE_CPS_SL_OTHER, /**< Sensor Location - Other */ - CY_BLE_CPS_SL_TOP_OF_SHOE, /**< Sensor Location - Top of shoe */ - CY_BLE_CPS_SL_IN_SHOE, /**< Sensor Location - In shoe */ - CY_BLE_CPS_SL_HIP, /**< Sensor Location - Hip */ - CY_BLE_CPS_SL_FRONT_WHEEL, /**< Sensor Location - Front Wheel */ - CY_BLE_CPS_SL_LEFT_CRANK, /**< Sensor Location - Left Crank */ - CY_BLE_CPS_SL_RIGHT_CRANK, /**< Sensor Location - Right Crank */ - CY_BLE_CPS_SL_LEFT_PEDAL, /**< Sensor Location - Left Pedal */ - CY_BLE_CPS_SL_RIGHT_PEDAL, /**< Sensor Location - Right Pedal */ - CY_BLE_CPS_SL_FRONT_HUB, /**< Sensor Location - Front Hub */ - CY_BLE_CPS_SL_REAR_DROPOUT, /**< Sensor Location - Rear Dropout */ - CY_BLE_CPS_SL_CHAINSTAY, /**< Sensor Location - Chainstay */ - CY_BLE_CPS_SL_REAR_WHEEL, /**< Sensor Location - Rear Wheel */ - CY_BLE_CPS_SL_REAR_HUB, /**< Sensor Location - Rear Hub */ - CY_BLE_CPS_SL_CHEST, /**< Sensor Location - Chest */ - CY_BLE_CPS_SL_SPIDER, /**< Sensor Location - Spider */ - CY_BLE_CPS_SL_CHAIN_RING, /**< Sensor Location - Chain Ring */ - CY_BLE_CPS_SL_COUNT /**< Total count of SL characteristics */ -} cy_en_ble_cps_sl_value_t; - -/** @} */ - -#define CY_BLE_CPSS_BROADCAST_ADVERT_INTERVAL_OFFSET (0x05u) -#define CY_BLE_CPSS_BROADCAST_DATA_LEN_OFFSET (0x07u) -#define CY_BLE_CPSS_BROADCAST_DATA_OFFSET (0x0Bu) - -#define CY_BLE_CPSS_BROADCAST_DATA_LEN_MIN (0x07u) -#define CY_BLE_CPSS_BROADCAST_DATA_HEADER_LEN (0x03u) -#define CY_BLE_CPSS_BROADCAST_PACKETS (0x03u) -#define CY_BLE_CPSS_BROADCAST_HEADER_LEN (CY_BLE_GAP_ADV_FLAGS_PACKET_LENGTH + \ - CY_BLE_GAP_ADV_ADVERT_INTERVAL_PACKET_LENGTH + \ - CY_BLE_CPSS_BROADCAST_DATA_HEADER_LEN + \ - CY_BLE_CPSS_BROADCAST_PACKETS) - -#define CY_BLE_CPSC_BROADCAST_DATA_OFFSET (0x04u) - - -/* Function Prototypes */ - -/** \addtogroup group_ble_service_api_CPS_server_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CPS_Init(cy_stc_ble_cps_config_t *config); -cy_en_ble_api_result_t Cy_BLE_CPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); - -/** @} */ - -#ifdef CY_BLE_CPS_SERVER -/** - * \addtogroup group_ble_service_api_CPS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CPSS_SetCharacteristicValue(cy_en_ble_cps_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSS_GetCharacteristicValue(cy_en_ble_cps_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -#if CY_BLE_GAP_ROLE_BROADCASTER -cy_en_ble_api_result_t Cy_BLE_CPSS_StartBroadcast(uint16_t advInterval, uint8_t attrSize, const uint8_t *attrValue); -cy_en_ble_api_result_t Cy_BLE_CPSS_StopBroadcast(void); -/** @} */ -#endif /* CY_BLE_GAP_ROLE_BROADCASTER */ - -#endif /* CY_BLE_CPS_SERVER */ - -#ifdef CY_BLE_CPS_CLIENT -/** - * \addtogroup group_ble_service_api_CPS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_CPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t - descrIndex, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cps_char_index_t charIndex, - cy_en_ble_cps_descr_index_t - descrIndex); - -cy_en_ble_api_result_t Cy_BLE_CPSC_StartObserve(uint8_t scanParamIndex); - -cy_en_ble_api_result_t Cy_BLE_CPSC_StopObserve(void); - -/** @} */ -#endif /* (CY_BLE_CPS_CLIENT) */ - - -/* ##Private Function Prototypes -** \cond IGNORE -*/ -void Cy_BLE_CPSS_Init(void); -#ifdef CY_BLE_CPS_SERVER -#define Cy_BLE_CPSS_ConnectEventHandler Cy_BLE_CPSS_Init -#define Cy_BLE_CPSS_DisconnectEventHandler Cy_BLE_CPSS_StopBroadcast -#endif /* CY_BLE_CPS_SERVER */ - -#ifdef CY_BLE_CPS_CLIENT -#define Cy_BLE_CPSC_DisconnectEventHandler Cy_BLE_CPSC_StopObserve -#endif /* (CY_BLE_CPS_CLIENT) */ -/** \endcond */ - -/* ##Macro Functions */ - -#ifdef CY_BLE_CPS_CLIENT - -#define Cy_BLE_CPSC_CheckCharHandle(handle) \ - do { \ - if((handle).valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \ - { \ - (handle).valueHandle = discCharInfo->valueHandle; \ - (handle).properties = discCharInfo->properties; \ - } \ - else \ - { \ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \ - &(discCharInfo)); \ - } \ - } while(0) - -#define Cy_BLE_CPSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_CPS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_cpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_CPSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_CPS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_CPS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_cpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].descrHandle[descrIndex]) - -#endif /* (CY_BLE_CPS_CLIENT) */ - - -/* ##External data references */ - -#ifdef CY_BLE_CPS_SERVER -extern cy_stc_ble_gapp_disc_mode_info_t cy_ble_cpssBroadcastModeInfo; -extern cy_stc_ble_cps_cp_adjustment_t cy_ble_cpssAdjustment; -#endif /* CY_BLE_CPS_SERVER */ - -#ifdef CY_BLE_CPS_CLIENT -extern cy_stc_ble_cpsc_t cy_ble_cpsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_CPS_CLIENT) */ - -#ifdef CY_BLE_GAP_ROLE_BROADCASTER -extern cy_stc_ble_gapp_disc_param_t cy_ble_cpssBroadcastParam; -extern cy_stc_ble_gapp_disc_data_t cy_ble_cpssBroadcastData; -#endif /* (CY_BLE_GAP_ROLE_BROADCASTER) */ - -extern cy_stc_ble_cps_config_t cy_ble_cpsConfig; -extern cy_stc_ble_cps_config_t *cy_ble_cpsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_CPS) */ -#endif /* CY_BLE_CPS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cscs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cscs.c deleted file mode 100644 index 3c187acc3b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cscs.c +++ /dev/null @@ -1,1749 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cscs.c -* \version 2.0 -* -* \brief -* Contains the source code for the Cycling Speed and Cadence Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CSCS)) - -static cy_ble_callback_t Cy_BLE_CSCS_ApplCallback = NULL; - - -#ifdef CY_BLE_CSCS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_cscssReqHandle; -#endif /* CY_BLE_CSCS_SERVER */ - -#ifdef CY_BLE_CSCS_CLIENT -/* CSCS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_cscsc_t cy_ble_cscsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_cscscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -CY_SECTION(".cy_wflash") CY_ALIGN(CY_FLASH_SIZEOF_ROW) -static const cy_stc_ble_cscsc_t cy_ble_flashCscsc[CY_BLE_CONFIG_GATTC_COUNT] = -{ - { - .characteristics[CY_BLE_CSCS_CSC_MEASUREMENT] = - { - .charInfo ={ 0u, 0u }, - .endHandle = 0u, - .descriptors ={ 0u } - }, - .characteristics[CY_BLE_CSCS_CSC_FEATURE] = - { - .charInfo ={ 0u, 0u }, - .endHandle = 0u, - .descriptors ={ 0u } - }, - .characteristics[CY_BLE_CSCS_SENSOR_LOCATION] = - { - .charInfo ={ 0u, 0u }, - .endHandle = 0u, - .descriptors ={ 0u } - }, - .characteristics[CY_BLE_CSCS_SC_CONTROL_POINT] = - { - .charInfo ={ 0u, 0u }, - .endHandle = 0u, - .descriptors ={ 0u } - }, - } -}; - -#endif /* (CY_BLE_CSCS_CLIENT) */ - -/* The pointer on global BLE CSCS Config structure */ -cy_stc_ble_cscs_config_t *cy_ble_cscsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ - -#ifdef CY_BLE_CSCS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_CSCSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_CSCSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -#endif /* CY_BLE_CSCS_SERVER */ - -#ifdef CY_BLE_CSCS_CLIENT -static void Cy_BLE_CSCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_CSCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_CSCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_CSCSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_CSCSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_CSCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_CSCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_CSCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_CSCS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_CSCS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_CSCS_Init -***************************************************************************//** -* -* This function initializes the Cycling Speed and Cadence Service. -* -* \param config: Configuration structure for the Cycling Speed and Cadence Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCS_Init(cy_stc_ble_cscs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure*/ - cy_ble_cscsConfigPtr = config; - - /* Registers Event Handler for the CSCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CSCS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_cscsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_CSCS_ApplCallback = cy_ble_cscsConfigPtr->callbackFunc; - } - - #if defined(CY_BLE_CSCS_SERVER) - cy_ble_cscssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_CSCS_SERVER */ - - #ifdef CY_BLE_CSCS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_CSCS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_CSCS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memcpy(&cy_ble_cscsc[idx], &cy_ble_flashCscsc[idx], sizeof(cy_stc_ble_cscsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_CSCS].uuid = CY_BLE_UUID_CYCLING_SPEED_AND_CADENCE_SERVICE; - } - cy_ble_cscscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - } - #endif /* CY_BLE_CSCS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CSCS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for Cycling Speed and Cadence Service specific -* attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for CSCS is: -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \sideeffect The *eventParams in the callback function should not be used by -* the application once the callback function execution is -* finished. Otherwise this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_CSCS_ApplCallback = callbackFunc; - if(cy_ble_cscsConfigPtr != NULL) - { - cy_ble_cscsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_CSCS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_CSCSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for the Cycling Speed and Cadence Service. -* -* \param *eventParam: The pointer to the data that came -* with a write request for the -* Cycling Speed and Cadence Service. -* -* \return -* Return a value of type cy_en_ble_gatt_err_code_t: -* * CY_BLE_GATT_ERR_NONE - function terminated successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - the handle of a Client Configuration -* Characteristic Descriptor is not valid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - an Internal Stack error occurred. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - the notification or indication -* property of a specific -* Characteristic of Cycling Speed and -* Cadence Service is disabled. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CSCSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_cscs_char_value_t wrReqParam = { .connHandle = eventParam->connHandle }; - cy_ble_gatt_db_attr_handle_t tmpHandle; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t event = (uint32_t)CY_BLE_EVT_CSCSS_WRITE_CHAR; - uint32_t handleWasFound = 1u; - - tmpHandle = eventParam->handleValPair.attrHandle; - - if(Cy_BLE_CSCS_ApplCallback != NULL) - { - /* Client Characteristic Configuration Descriptor Write Request */ - if(tmpHandle == cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_CSC_MEASUREMENT].descrHandle[CY_BLE_CSCS_CCCD]) - { - /* Verify that optional notification property is enabled for the Characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_CSC_MEASUREMENT]. - charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_CSCSS_NOTIFICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_CSCSS_NOTIFICATION_DISABLED; - } - - wrReqParam.charIndex = CY_BLE_CSCS_CSC_MEASUREMENT; - - /* Value is NULL for descriptors */ - wrReqParam.value = NULL; - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else if(tmpHandle == cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_SC_CONTROL_POINT]. - descrHandle[CY_BLE_CSCS_CCCD]) - { - /* Verify that optional indication property is enabled for the Characteristic */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_SC_CONTROL_POINT]. - charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_CSCSS_INDICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_CSCSS_INDICATION_DISABLED; - } - - wrReqParam.charIndex = CY_BLE_CSCS_SC_CONTROL_POINT; - - /* Value is NULL for descriptors */ - wrReqParam.value = NULL; - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else if(tmpHandle == cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_SC_CONTROL_POINT].charHandle) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_cscssReqHandle) - { - /* Verify if indication are enabled for CSC Control Point Characteristic */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_cscsConfigPtr->cscss-> - charInfo[CY_BLE_CSCS_SC_CONTROL_POINT].charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_SC_CONTROL_POINT]. - descrHandle[CY_BLE_CSCS_CCCD])) - { - event = (uint32_t)CY_BLE_EVT_CSCSS_WRITE_CHAR; - wrReqParam.charIndex = CY_BLE_CSCS_CSC_MEASUREMENT; - wrReqParam.value = &eventParam->handleValPair.value; - } - else - { - /* The peer Client didn't enable indications for the characteristic */ - gattErr = CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - } - else - { - /* Indication is not supported */ - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else - { - gattErr = CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - } - } - else - { - /* No valid service handles were found */ - handleWasFound = 0u; - } - - if((gattErr == CY_BLE_GATT_ERR_NONE) && (handleWasFound != 0u)) - { - /* Write value to GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CSCS_ApplCallback(event, &wrReqParam); - } - } - } - - if(CY_BLE_GATT_ERR_NONE != gattErr) - { - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CSCSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles the Value Confirmation request event from the BLE stack. -* -* \param event_params: Pointer to a structure of type 'cy_stc_ble_conn_handle_t'. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_CSCSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_CSCS_ApplCallback != NULL) && (cy_ble_cscssReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_cscssReqHandle == cy_ble_cscsConfigPtr->cscss->charInfo[CY_BLE_CSCS_SC_CONTROL_POINT].charHandle) - { - cy_stc_ble_cscs_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_CSCS_SC_CONTROL_POINT, - .value = NULL - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_cscssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSS_INDICATION_CONFIRMATION, &locCharValue); - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSS_SetCharacteristicValue -****************************************************************************//** -* -* Sets characteristic value of the Cycling Speed and Cadence Service, which is -* identified by charIndex, to the local database. -* -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_cscs_char_index_t. Valid values are, -* * CY_BLE_CSCS_CSC_FEATURE -* * CY_BLE_CSCS_SENSOR_LOCATION. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should -* be stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSS_SetCharacteristicValue(cy_en_ble_cscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(CY_BLE_CSCS_CHAR_COUNT > charIndex) - { - if(cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Store data in database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSS_GetCharacteristicValue -****************************************************************************//** -* -* Gets a characteristic value of the Cycling Speed and Cadence Service, which -* is identified by charIndex, from the GATT database. -* -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_cscs_char_index_t. Valid value is, -* * CY_BLE_CSCS_SC_CONTROL_POINT. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSS_GetCharacteristicValue(cy_en_ble_cscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(CY_BLE_CSCS_CHAR_COUNT > charIndex) - { - if(cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSS_GetCharacteristicDescriptor -****************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the Cycling -* Speed and Cadence Service, from the GATT database. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic of type cy_en_ble_cscs_char_index_t. -* Valid values are, -* * CY_BLE_CSCS_CSC_MEASUREMENT -* * CY_BLE_CSCS_SC_CONTROL_POINT. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_cscs_descr_index_t. Valid value is -* * CY_BLE_CSCS_CCCD. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - cy_en_ble_cscs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((CY_BLE_CSCS_CHAR_COUNT > charIndex) && (CY_BLE_CSCS_DESCR_COUNT > descrIndex)) - { - if(cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].descrHandle[descrIndex] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSS_SendNotification -****************************************************************************//** -* -* Sends notification with a characteristic value, which is specified by -* charIndex, of the Cycling Speed and Cadence Service to the Client device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_CSCSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_cscs_char_index_t. Valid value is -* * CY_BLE_CSCS_CSC_MEASUREMENT. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value -* data that should be sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameter is failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex == CY_BLE_CSCS_CSC_MEASUREMENT) - { - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, - cy_ble_cscsConfigPtr->cscss->charInfo[charIndex]. - descrHandle[CY_BLE_CSCS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to the Client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSS_SendIndication -****************************************************************************//** -* -* Sends indication with a characteristic value, which is specified by -* charIndex, of the Cycling Speed and Cadence Service to the Client device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_CSCSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_cscs_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value -* data that should be sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameter is failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CSCS service-specific callback is registered -* (with Cy_BLE_CSCS_RegisterAttrCallback): -* * CY_BLE_EVT_CSCSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the CSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex == CY_BLE_CSCS_SC_CONTROL_POINT) - { - /* Send Indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_cscsConfigPtr->cscss->charInfo[charIndex]. - descrHandle[CY_BLE_CSCS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - if(cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_cscsConfigPtr->cscss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - /* Save handle to support service-specific value confirmation response from client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cscssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - return(apiResult); -} - -#endif /* CY_BLE_CSCS_SERVER */ - - -#ifdef CY_BLE_CSCS_CLIENT - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_DiscoverCharacteristicsEventHandler -****************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP" -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* CSCS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_cscscCharUuid[CY_BLE_CSCS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_CSC_MSRMT, - CY_BLE_UUID_CHAR_CSC_FEATURE, - CY_BLE_UUID_CHAR_SENSOR_LOCATION, - CY_BLE_UUID_CHAR_SC_CONTROL_POINT - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CSCS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = (uint32_t)CY_BLE_CSCS_CSC_MEASUREMENT; i < (uint32_t)CY_BLE_CSCS_CHAR_COUNT; i++) - { - if(cy_ble_cscscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_cscsc[discIdx].characteristics[i].charInfo.valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_cscsc[discIdx].characteristics[i].charInfo.valueHandle = discCharInfo->valueHandle; - cy_ble_cscsc[discIdx].characteristics[i].charInfo.properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_cscsc[discIdx].characteristics[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initially characteristic endHandle equals to the Service endHandle. - * Characteristic endHandle will be updated to declaration handler of the - * following characteristic,in the following characteristic discovery - * procedure. - */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_DiscoverCharDescriptorsEventHandler -****************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_FIND_INFO_RSP" event. -* This event is generated when a server successfully sends the data for -* "CY_BLE_EVT_GATTC_FIND_INFO_REQ". Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CSCS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_CSCS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_cscsc[discIdx].characteristics[cy_ble_discovery[discIdx].charCount].descriptors[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_cscsc[discIdx].characteristics[cy_ble_discovery[discIdx].charCount].descriptors[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CSCSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_CSCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CSCS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_CSCS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_cscsc[discIdx].characteristics[charIdx].endHandle - cy_ble_cscsc[discIdx].characteristics[charIdx]. - charInfo.valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_cscsc[discIdx].characteristics[charIdx].charInfo.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_cscsc[discIdx].characteristics[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_NotificationEventHandler -****************************************************************************//** -* -* Handles the Notification Event for the Cycling Speed and Cadence Service. -* -* \param eventParam: The pointer to the cy_stc_ble_gattc_handle_value_ntf_param_t -* data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CSCS_ApplCallback != NULL)) - { - if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_MEASUREMENT].charInfo.valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_cscs_char_value_t ntfParam = - { - .charIndex = CY_BLE_CSCS_CSC_MEASUREMENT, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSC_NOTIFICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_IndicationEventHandler -****************************************************************************//** -* -* Handles the Indication Event for the Cycling Speed and Cadence Service. -* -* \param eventParam: The pointer to the cy_stc_ble_gattc_handle_value_ntf_param_t -* data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CSCS_ApplCallback != NULL)) - { - if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].charInfo.valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_cscs_char_value_t ntfParam = - { - .charIndex = CY_BLE_CSCS_SC_CONTROL_POINT, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSC_INDICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_ReadResponseEventHandler -****************************************************************************//** -* -* Handles the Read Response Event for the Cycling Speed and Cadence Service. -* -* \param eventParam: The pointer to the data that came with a read response for CSCS. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrVal = 0u; - cy_en_ble_cscs_char_index_t idx; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CSCS_ApplCallback != NULL) && - (cy_ble_cscscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_FEATURE].charInfo.valueHandle == - cy_ble_cscscReqHandle[discIdx]) - { - idx = CY_BLE_CSCS_CSC_FEATURE; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SENSOR_LOCATION].charInfo.valueHandle == - cy_ble_cscscReqHandle[discIdx]) - { - idx = CY_BLE_CSCS_SENSOR_LOCATION; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_MEASUREMENT].descriptors[CY_BLE_CSCS_CCCD] == - cy_ble_cscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - idx = CY_BLE_CSCS_CSC_MEASUREMENT; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].descriptors[CY_BLE_CSCS_CCCD] == - cy_ble_cscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - idx = CY_BLE_CSCS_SC_CONTROL_POINT; - } - else - { - /* No CSCS Characteristics were requested for read */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* Read response for characteristic */ - if(attrVal == 0u) - { - /* Fill Cycling Speed and Cadence Service read response parameter structure with - * Characteristic info. */ - cy_stc_ble_cscs_char_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = idx, - .value = &eventParam->value - }; - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSC_READ_CHAR_RESPONSE, (void*)&rdRspParam); - } - else /* Read response for characteristic descriptor */ - { - /* Fill Cycling Speed and Cadence Service read response parameter structure with - * Characteristic Descriptor info. */ - cy_stc_ble_cscs_descr_value_t rdRspParam = { .connHandle = eventParam->connHandle }; - rdRspParam.charIndex = idx; - rdRspParam.descrIndex = CY_BLE_CSCS_CCCD; - rdRspParam.value = &eventParam->value; - - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSC_READ_DESCR_RESPONSE, (void*)&rdRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_cscscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_WriteResponseEventHandler -****************************************************************************//** -* -* Handles the Write Response Event for the Cycling Speed and Cadence Service. -* -* \param eventParam: The pointer to the cy_stc_ble_conn_handle_t data structure. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrType = 0u; - cy_en_ble_cscs_char_index_t idx; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CSCS_ApplCallback != NULL) && - (cy_ble_cscscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_FEATURE].charInfo.valueHandle == - cy_ble_cscscReqHandle[discIdx]) - { - idx = CY_BLE_CSCS_CSC_FEATURE; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SENSOR_LOCATION].charInfo.valueHandle == - cy_ble_cscscReqHandle[discIdx]) - { - idx = CY_BLE_CSCS_SENSOR_LOCATION; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].charInfo.valueHandle == - cy_ble_cscscReqHandle[discIdx]) - { - idx = CY_BLE_CSCS_SC_CONTROL_POINT; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_MEASUREMENT].descriptors[CY_BLE_CSCS_CCCD] == - cy_ble_cscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrType = 1u; - idx = CY_BLE_CSCS_CSC_MEASUREMENT; - } - else if(cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].descriptors[CY_BLE_CSCS_CCCD] == - cy_ble_cscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrType = 1u; - idx = CY_BLE_CSCS_SC_CONTROL_POINT; - } - else - { - /* No CSCS Characteristics were requested for write */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* This should be cleared before calling to */ - cy_ble_cscscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* Write response for characteristic */ - if(attrType == 0u) - { - /* Fill Cycling Speed and Cadence Service write response parameter structure with - * Characteristic info. */ - cy_stc_ble_cscs_char_value_t rdRspParam = - { - .connHandle = *eventParam, - .charIndex = idx, - .value = NULL - }; - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSC_WRITE_CHAR_RESPONSE, (void*)&rdRspParam); - } - else /* Write response for characteristic descriptor */ - { - /* Fill Cycling Speed and Cadence Service write response parameter structure with - * Characteristic Descriptor info. */ - cy_stc_ble_cscs_descr_value_t rdRspParam = { .connHandle = *eventParam }; - rdRspParam.charIndex = idx; - rdRspParam.descrIndex = CY_BLE_CSCS_CCCD; - rdRspParam.value = NULL; - - Cy_BLE_CSCS_ApplCallback((uint32_t)CY_BLE_EVT_CSCSC_WRITE_DESCR_RESPONSE, (void*)&rdRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_ErrorResponseEventHandler -****************************************************************************//** -* -* Handles the Error Response Event for the Cycling Speed and Cadence Service. -* -* \param eventParam: The pointer to the cy_stc_ble_gatt_err_param_t structure. -* -*******************************************************************************/ -static void Cy_BLE_CSCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(cy_ble_cscscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_cscscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_SetCharacteristicValue -****************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_CSCSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: Size of the characteristic value attribute. -* \param attrValue: Pointer to the characteristic value data -* that should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully; -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CSCS service-specific callback is registered -* (with Cy_BLE_CSCS_RegisterAttrCallback): -* * CY_BLE_EVT_CSCSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cscs_char_value_t. -* . -* Otherwise (if the CSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (charIndex == CY_BLE_CSCS_SC_CONTROL_POINT)) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].charInfo.valueHandle) - { - /* Fill all fields of write command request structure ... */ - cy_stc_ble_gattc_write_req_t wrReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .handleValPair.attrHandle = cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT]. - charInfo.valueHandle, - .connHandle = connHandle - }; - /* Send request to write characteristic value */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&wrReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cscscReqHandle[discIdx] = wrReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - /* Validation of input parameters failed */ - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_GetCharacteristicValue -****************************************************************************//** -* -* Sends a request to peer device to get characteristic value of the Cycling -* Speed and Cadence Service, which is identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully; -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CSCS service-specific callback is registered -* (with Cy_BLE_CSCS_RegisterAttrCallback): -* * CY_BLE_EVT_CSCSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cscs_char_value_t. -* . -* Otherwise (if the CSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex) -{ - cy_ble_gatt_db_attr_handle_t tmpCharHandle; - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Select characteristic */ - switch(charIndex) - { - case CY_BLE_CSCS_CSC_FEATURE: - tmpCharHandle = cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_FEATURE].charInfo.valueHandle; - break; - - case CY_BLE_CSCS_SENSOR_LOCATION: - tmpCharHandle = cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SENSOR_LOCATION].charInfo.valueHandle; - break; - - default: - /* Characteristic wasn't found */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - break; - } - - if(apiResult == CY_BLE_SUCCESS) - { - if(tmpCharHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send request to read characteristic value */ - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = tmpCharHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cscscReqHandle[discIdx] = tmpCharHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_SetCharacteristicDescriptor -****************************************************************************//** -* -* Sends a request to peer device to get characteristic descriptor of specified -* characteristic of the Cycling Speed and Cadence Service. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_CSCSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_CSCSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_CSCSS_INDICATION_ENABLED -* * CY_BLE_EVT_CSCSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a CSCS characteristic. -* \param descrIndex: The index of a CSCS characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the characteristic descriptor value -* data that should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request was sent successfully. -* * CY_BLE_ERROR_INVALID_STATE - connection with the client is not established. -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor. -** \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CSCS service-specific callback is registered -* (with Cy_BLE_CSCS_RegisterAttrCallback): -* * CY_BLE_EVT_CSCSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cscs_descr_value_t. -* . -* Otherwise (if the CSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - cy_en_ble_cscs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (descrIndex == CY_BLE_CSCS_CCCD) && (attrSize == CY_BLE_CCCD_LEN)) - { - if((charIndex == CY_BLE_CSCS_CSC_MEASUREMENT) || (charIndex == CY_BLE_CSCS_SC_CONTROL_POINT)) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - if(charIndex == CY_BLE_CSCS_CSC_MEASUREMENT) - { - writeReqParam.handleValPair.attrHandle = - cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_MEASUREMENT].descriptors[CY_BLE_CSCS_CCCD]; - } - else - { - writeReqParam.handleValPair.attrHandle = - cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].descriptors[CY_BLE_CSCS_CCCD]; - } - - if(writeReqParam.handleValPair.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* ... and send a request to the Server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cscscReqHandle[discIdx] = - cy_ble_cscsc[discIdx].characteristics[charIndex].descriptors[CY_BLE_CSCS_CCCD]; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - else - { - /* The characteristic has not been discovered or has invalid fields */ - } - - /* Return the status */ - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_GetCharacteristicDescriptor -****************************************************************************//** -* -* Sends a request to peer device to get characteristic descriptor of specified -* characteristic of the Cycling Speed and Cadence Service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a Service Characteristic. -* \param descrIndex: The index of a Service Characteristic Descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Cannot process a request to send PDU due to -* invalid operation performed by the -* application. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CSCS service-specific callback is registered -* (with Cy_BLE_CSCS_RegisterAttrCallback): -* * CY_BLE_EVT_CSCSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_cscs_descr_value_t. -* . -* Otherwise (if the CSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - cy_en_ble_cscs_descr_index_t descrIndex) -{ - cy_ble_gatt_db_attr_handle_t tmpHandle; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - ((charIndex == CY_BLE_CSCS_CSC_MEASUREMENT) || (charIndex == CY_BLE_CSCS_SC_CONTROL_POINT)) && - (descrIndex == CY_BLE_CSCS_CCCD)) - { - if(charIndex == CY_BLE_CSCS_CSC_MEASUREMENT) - { - tmpHandle = cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_CSC_MEASUREMENT].descriptors[CY_BLE_CSCS_CCCD]; - } - else - { - tmpHandle = cy_ble_cscsc[discIdx].characteristics[CY_BLE_CSCS_SC_CONTROL_POINT].descriptors[CY_BLE_CSCS_CCCD]; - } - - if(tmpHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = tmpHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_cscscReqHandle[discIdx] = tmpHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - /* Characteristic has not been discovered or had invalid fields */ - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_CSCSC_StoreProfileData -****************************************************************************//** -* -* Stores the structure with discovered attributes of Cycling Speed and Cadence -* Server device to the Flash. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - On successful operation. -* * CY_BLE_ERROR_FLASH_WRITE_NOT_PERMITED - Flash Write is not complete. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CSCSC_StoreProfileData(void) -{ - cy_stc_ble_app_flash_param_t appFlashParam = - { - .buffLen = sizeof(cy_ble_cscsc), - .destAddr = (uint8_t*)&cy_ble_flashCscsc, - .srcBuff = (uint8_t*)&cy_ble_cscsc - }; - - return(Cy_BLE_StoreAppData(&appFlashParam)); -} - -#endif /* CY_BLE_CSCS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_CSCS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Cycling Speed and Cadence Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CSCS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_CSCS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_CSCSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_CSCSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_CSCSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_CSCS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_CSCS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_CSCSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_CSCSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATT_CONNECT_IND: - (void)Cy_BLE_CSCS_Init(cy_ble_cscsConfigPtr); - break; - #endif /* CY_BLE_CSCS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_CSCS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_CSCSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_CSCSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_CSCSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_CSCSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_CSCSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_CSCS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_CSCS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cscs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cscs.h deleted file mode 100644 index 56a90fb517..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cscs.h +++ /dev/null @@ -1,236 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cscs.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Cycling Speed and Cadence -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_CSCS_H -#define CY_BLE_CSCS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CSCS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_CSCS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ -/** Characteristic indexes */ -typedef enum -{ - CY_BLE_CSCS_CSC_MEASUREMENT, /**< CSC Measurement Characteristic index */ - CY_BLE_CSCS_CSC_FEATURE, /**< CSC Feature Characteristic index */ - CY_BLE_CSCS_SENSOR_LOCATION, /**< CSC Sensor Location Characteristic index */ - CY_BLE_CSCS_SC_CONTROL_POINT, /**< CSC SC Control Point Characteristic index */ - CY_BLE_CSCS_CHAR_COUNT /**< Total count of CSCS Characteristics */ -} cy_en_ble_cscs_char_index_t; - -/** Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_CSCS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_CSCS_DESCR_COUNT /**< Total count of Descriptors */ -} cy_en_ble_cscs_descr_index_t; - -/** Cycling Speed and Cadence Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_cscs_char_index_t charIndex; /**< Index of Cycling Speed and Cadence Service Characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_cscs_char_value_t; - -/** Cycling Speed and Cadence Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_cscs_char_index_t charIndex; /**< Characteristic index of the Service */ - cy_en_ble_cscs_descr_index_t descrIndex; /**< Characteristic Descriptor index */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of the Service Characteristic Descriptor */ -} cy_stc_ble_cscs_descr_value_t; - -/** Characteristic with descriptors type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of the Characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_CSCS_DESCR_COUNT]; /**< Handles of the Descriptors */ -} cy_stc_ble_cscss_char_t; - -/** Structure with Cycling Speed and Cadence Service attribute handles */ -typedef struct -{ - /** Cycling Speed and Cadence Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Array of Cycling Speed and Cadence Service Characteristics and Descriptors handles */ - cy_stc_ble_cscss_char_t charInfo[CY_BLE_CSCS_CHAR_COUNT]; -} cy_stc_ble_cscss_t; - -/** Service full Characteristic information type */ -typedef struct -{ - /** Characteristic handle and properties */ - cy_stc_ble_srvr_char_info_t charInfo; - - /** Characteristic descriptors handles */ - cy_ble_gatt_db_attr_handle_t descriptors[CY_BLE_CSCS_DESCR_COUNT]; - - /** End handle of Characteristic */ - cy_ble_gatt_db_attr_handle_t endHandle; -} cy_stc_ble_cscsc_srvr_full_char_info_t; - -/** Structure with discovered attributes information of Cycling Speed and Cadence Service */ -typedef struct -{ - /** Characteristics handles array */ - cy_stc_ble_cscsc_srvr_full_char_info_t characteristics[CY_BLE_CSCS_CHAR_COUNT]; -} cy_stc_ble_cscsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Cycling Speed and Cadence Service GATT DB handles structure */ - const cy_stc_ble_cscss_t *cscss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_cscs_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_CSCS_INVALID_CHAR_INDEX (0xFFu) - -/* SC Control Point Characteristic Op Codes */ -#define CY_BLE_CSCS_SET_CUMMULATIVE_VALUE (0x01u) -#define CY_BLE_CSCS_START_SENSOR_CALIBRATION (0x02u) -#define CY_BLE_CSCS_UPDATE_SENSOR_LOCATION (0x03u) -#define CY_BLE_CSCS_REQ_SUPPORTED_SENSOR_LOCATION (0x04u) -#define CY_BLE_CSCS_RESPONSE_CODE (0x10u) - -/* SC Control Point Characteristic Response Codes */ -#define CY_BLE_CSCS_ERR_SUCCESS (0x01u) -#define CY_BLE_CSCS_ERR_OP_CODE_NOT_SUPPORTED (0x02u) -#define CY_BLE_CSCS_ERR_INVALID_PARAMETER (0x03u) -#define CY_BLE_CSCS_ERR_OPERATION_FAILED (0x04u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_CSCS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_CSCS_Init(cy_stc_ble_cscs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_CSCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_CSCS_SERVER -/** - * \addtogroup group_ble_service_api_CSCS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CSCSS_SetCharacteristicValue(cy_en_ble_cscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CSCSS_GetCharacteristicValue(cy_en_ble_cscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CSCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - cy_en_ble_cscs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CSCSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CSCSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_CSCS_SERVER */ - -#ifdef CY_BLE_CSCS_CLIENT -/** - * \addtogroup group_ble_service_api_CSCS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CSCSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CSCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_CSCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - cy_en_ble_cscs_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CSCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cscs_char_index_t charIndex, - cy_en_ble_cscs_descr_index_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_CSCS_CLIENT) */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE */ - -#ifdef CY_BLE_CSCS_CLIENT -cy_en_ble_api_result_t Cy_BLE_CSCSC_StoreProfileData(void); -#endif /* (CY_BLE_CSCS_CLIENT) */ - -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_CSCS_CLIENT -extern cy_stc_ble_cscsc_t cy_ble_cscsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_CSCS_CLIENT) */ - -extern cy_stc_ble_cscs_config_t cy_ble_cscsConfig; -extern cy_stc_ble_cscs_config_t *cy_ble_cscsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_CSCS) */ -#endif /* CY_BLE_CSCS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cts.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cts.c deleted file mode 100644 index bd5454355f..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cts.c +++ /dev/null @@ -1,1624 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cts.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Current Time Service of the BLE -* Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CTS)) - -static cy_ble_callback_t Cy_BLE_CTS_ApplCallback = NULL; - -#ifdef CY_BLE_CTS_CLIENT -/* CTS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_ctsc_t cy_ble_ctsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check the response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_ctscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_CTS_CLIENT) */ - -/* The pointer on global BLE CTS Config structure */ -cy_stc_ble_cts_config_t *cy_ble_ctsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_CTS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_CTSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* (CY_BLE_CTS_SERVER) */ - -#ifdef CY_BLE_CTS_CLIENT -static void Cy_BLE_CTSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_CTSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_CTSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_CTSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_CTSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_CTSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_CTSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_CTS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_CTS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_CTS_Init -***************************************************************************//** -* -* This function initializes the Current Time Service. -* -* \param config: Configuration structure for the Current Time Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTS_Init(cy_stc_ble_cts_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_ctsConfigPtr = config; - - /* Registers Event Handler for the CTS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CTS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_ctsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_CTS_ApplCallback = cy_ble_ctsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_CTS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_CTS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset((void*)&cy_ble_ctsc[idx], 0, sizeof(cy_stc_ble_ctsc_t)); - } - cy_ble_ctscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_CTS].uuid = CY_BLE_UUID_CURRENT_TIME_SERVICE; - } - } - #endif /* (CY_BLE_CTS_CLIENT) */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for Current Time Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_CTSS_NOTIFICATION_ENABLED) -* * eventParam contains the parameters corresponding to the -* current event (e.g. Pointer to cy_stc_ble_cts_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_CTS_ApplCallback = callbackFunc; - if(cy_ble_ctsConfigPtr != NULL) - { - cy_ble_ctsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_CTS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_CTSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for the Current Time Service. -* -* \param eventParam: The pointer to the data that came with a write request for the -* Current Time Service. -* -* \return -* Return a value of type cy_en_ble_gatt_err_code_t: -* * CY_BLE_GATT_ERR_NONE - Function terminated successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - The Handle of the Current Time Client -* Configuration Characteristic Descriptor -* is not valid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The notification property of the -* Current Time Client Configuration -* Characteristic Descriptor is -* disabled. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CTSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - uint32_t event = (uint32_t)CY_BLE_EVT_CTSS_NOTIFICATION_DISABLED; - cy_stc_ble_cts_char_value_t wrReqParam = - { - .gattErrorCode = CY_BLE_GATT_ERR_NONE, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - if(Cy_BLE_CTS_ApplCallback != NULL) - { - /* Client Characteristic Configuration descriptor write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_ctsConfigPtr->ctss->currTimeCccdHandle) - { - /* Verify that optional notification property is enabled for Current Time - * Characteristic. - */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_ctsConfigPtr->ctss->currTimeCharHandle)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - wrReqParam.gattErrorCode = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_CTSS_NOTIFICATION_ENABLED; - } - - if(wrReqParam.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - wrReqParam.charIndex = CY_BLE_CTS_CURRENT_TIME; - wrReqParam.value = NULL; - Cy_BLE_CTS_ApplCallback(event, &wrReqParam); - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - * (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) - */ - } - else - { - wrReqParam.gattErrorCode = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - - /* Clear the callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if((eventParam->handleValPair.attrHandle == cy_ble_ctsConfigPtr->ctss->currTimeCharHandle) || - (eventParam->handleValPair.attrHandle == cy_ble_ctsConfigPtr->ctss->localTimeInfCharHandle)) - { - if(eventParam->handleValPair.attrHandle == cy_ble_ctsConfigPtr->ctss->currTimeCharHandle) - { - wrReqParam.charIndex = CY_BLE_CTS_CURRENT_TIME; - } - else - { - wrReqParam.charIndex = CY_BLE_CTS_LOCAL_TIME_INFO; - } - /* Check if write property is supported */ - wrReqParam.gattErrorCode = Cy_BLE_GATT_DbCheckPermission(eventParam->handleValPair.attrHandle, - &eventParam->connHandle, CY_BLE_GATT_DB_WRITE | - CY_BLE_GATT_DB_PEER_INITIATED); - - if(wrReqParam.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - /* Send callback to user. User must validate the fields of the - * Current Time Characteristic and then perform database - * Characteristic Write procedure to write all or only selected - * fields to the database. In case if user want to ignore some - * fields of Current Time Characteristic user has to set the - * CY_BLE_GATT_ERR_CTS_DATA_FIELD_IGNORED error value in the - * "gattErrorCode" field of the structure passed from the with - * CY_BLE_EVT_CTSS_WRITE_CHAR event. In case if no fields in the - * Current Time Characteristic is ignored the "gattErrorCode" - * should be ignored. - */ - Cy_BLE_CTS_ApplCallback((uint32_t)CY_BLE_EVT_CTSS_WRITE_CHAR, (void*)&wrReqParam); - - if(wrReqParam.gattErrorCode != CY_BLE_GATT_ERR_CTS_DATA_FIELD_IGNORED) - { - /* Ignore all gatt errors except permitted "Data Field Ignored" */ - wrReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - } - } - else - { - wrReqParam.gattErrorCode = CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED; - } - - /* Clear the callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* This empty else statement is required by MISRA */ - } - } - - return(wrReqParam.gattErrorCode); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a value for one of three characteristic values of the Current Time -* Service. The characteristic is identified by charIndex. -* -* \param charIndex: The index of the Current Time Service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was written successfully -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSS_SetCharacteristicValue(cy_en_ble_cts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - uint16_t locYear; - cy_stc_ble_cts_current_time_t currTime; - cy_stc_ble_cts_local_time_info_t localTime; - cy_stc_ble_cts_reference_time_info_t refTime; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(attrValue != NULL) - { - switch(charIndex) - { - case CY_BLE_CTS_CURRENT_TIME: - if(attrSize == CY_BLE_CTS_CURRENT_TIME_SIZE) - { - (void)memcpy((void*)&currTime, (void*)attrValue, (uint32_t)attrSize); - - /* Validate characteristic value - * First, validate "locYear" field - */ - locYear = ((uint16_t)((uint16_t)currTime.yearHigh << CY_BLE_CTS_8_BIT_OFFSET)) | - ((uint16_t)currTime.yearLow); - - if((locYear >= CY_BLE_CTS_YEAR_MIN) && (locYear <= CY_BLE_CTS_YEAR_MAX)) - { - /* Validation passed */ - apiResult = CY_BLE_SUCCESS; - } - - /* Validate "Month" field */ - if((CY_BLE_ERROR_INVALID_PARAMETER != apiResult) && (CY_BLE_CTS_MONTH_MAX < currTime.month)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - /* Next is "Day" field */ - if((CY_BLE_ERROR_INVALID_PARAMETER != apiResult) && (CY_BLE_CTS_DAY_MAX < currTime.day)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - /* Validate "Hours" field */ - if((CY_BLE_ERROR_INVALID_PARAMETER != apiResult) && (CY_BLE_CTS_HOURS_MAX < currTime.hours)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - /* Validate "Minutes" field */ - if((CY_BLE_ERROR_INVALID_PARAMETER != apiResult) && (CY_BLE_CTS_MINUTES_MAX < currTime.minutes)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - /* Validate "Seconds" field */ - if((CY_BLE_ERROR_INVALID_PARAMETER != apiResult) && (CY_BLE_CTS_SECONDS_MAX < currTime.seconds)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - /* Validate "dayOfWeek" field */ - if((CY_BLE_ERROR_INVALID_PARAMETER != apiResult) && (CY_BLE_CTS_DAY_OF_WEEK_MAX <= currTime.dayOfWeek)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->currTimeCharHandle, - .handleValuePair.value.len = attrSize, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - dbAttrValInfo.handleValuePair.value.val = (uint8_t*)&currTime; - - /* Verify "Adjust Reason". If it is set to incorrect value then it will - * be changed to "Unknown" Adjust Reason. */ - CY_BLE_CTS_CHECK_ADJUST_REASON(currTime.adjustReason); - - /* Set Current Time Characteristic value to GATT database. - * Need to handle return type difference of Cy_BLE_GATTS_WriteAttributeValueCCCD() and - * Cy_BLE_CTSS_SetCharacteristicValue(). */ - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - } - break; - - case CY_BLE_CTS_LOCAL_TIME_INFO: - if(attrSize == CY_BLE_CTS_LOCAL_TIME_INFO_SIZE) - { - (void)memcpy((void*)&localTime, (void*)attrValue, (uint32_t)attrSize); - - if(((localTime.timeZone <= CY_BLE_CTS_UTC_OFFSET_MAX) && - (localTime.timeZone >= CY_BLE_CTS_UTC_OFFSET_MIN)) || - (localTime.timeZone == CY_BLE_CTS_UTC_OFFSET_UNKNOWN)) - { - /* Validation passed */ - apiResult = CY_BLE_SUCCESS; - } - - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - /* Validate DST offset */ - switch(localTime.dst) - { - case CY_BLE_CTS_STANDARD_TIME: - case CY_BLE_CTS_DAYLIGHT_TIME_0_5: - case CY_BLE_CTS_DAYLIGHT_TIME_1_0: - case CY_BLE_CTS_DAYLIGHT_TIME_2_0: - case CY_BLE_CTS_DST_UNKNOWN: - /* DST offset is correct */ - apiResult = CY_BLE_SUCCESS; - break; - - default: - /* Validation failed */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - break; - } - } - - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_ctsConfigPtr->ctss->localTimeInfCharHandle) - { - /* Set Local Time Characteristic value to GATT database. - * Need to handle return type difference of Cy_BLE_GATTS_WriteAttributeValueCCCD() and - * Cy_BLE_CTSS_SetCharacteristicValue(). */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->localTimeInfCharHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - break; - - case CY_BLE_CTS_REFERENCE_TIME_INFO: - if(attrSize == CY_BLE_CTS_REFERENCE_TIME_INFO_SIZE) - { - (void)memcpy((void*)&refTime, (void*)attrValue, (uint32_t)attrSize); - - /* Validate "Time Source" value */ - if(CY_BLE_CTS_TIME_SRC_CELL_NET >= refTime.timeSource) - { - /* Time source is correct */ - apiResult = CY_BLE_SUCCESS; - } - - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - /* Validate "Hours since update" field */ - if(refTime.hoursSinseUpdate <= CY_BLE_CTS_HOURS_MAX) - { - /* Value is correct */ - } - else if(refTime.daysSinceUpdate == CY_BLE_CTS_MAX_DAYS_SINCE_UPDATE) - { - /* Per CTS spec "Hours since update" is set to 255 as "Days since update" - * is 255. */ - refTime.hoursSinseUpdate = CY_BLE_CTS_MAX_HOURS_SINCE_UPDATE; - } - else - { - /* Invalid value encountered */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_ctsConfigPtr->ctss->localTimeInfCharHandle) - { - /* Set Reference Time Characteristic value to GATT database. - * Need to handle return type difference of Cy_BLE_GATTS_WriteAttributeValueCCCD() and - * Cy_BLE_CTSS_SetCharacteristicValue(). */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->refTimeInfCharHandle, - .handleValuePair.value.len = attrSize, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - dbAttrValInfo.handleValuePair.value.val = (uint8_t*)&refTime; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - break; - - default: - /* Characteristic wasn't found */ - break; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the Current Time Service, which is identified -* by charIndex. -* -* \param charIndex: The index of a Current Time Service characteristic. -* \param attrSize: The size of the Current Time Service characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSS_GetCharacteristicValue(cy_en_ble_cts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(attrValue != NULL) - { - switch(charIndex) - { - case CY_BLE_CTS_CURRENT_TIME: - if(attrSize == CY_BLE_CTS_CURRENT_TIME_SIZE) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->currTimeCharHandle; - apiResult = CY_BLE_SUCCESS; - } - break; - - case CY_BLE_CTS_LOCAL_TIME_INFO: - if(attrSize == CY_BLE_CTS_LOCAL_TIME_INFO_SIZE) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->localTimeInfCharHandle; - apiResult = CY_BLE_SUCCESS; - } - break; - - case CY_BLE_CTS_REFERENCE_TIME_INFO: - if(attrSize == CY_BLE_CTS_REFERENCE_TIME_INFO_SIZE) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->refTimeInfCharHandle; - apiResult = CY_BLE_SUCCESS; - } - break; - - default: - /* Characteristic wasn't found */ - break; - } - - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - if(dbAttrValInfo.handleValuePair.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Get characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the Current -* Time Service. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - cy_en_ble_cts_char_descriptors_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_CTS_CURRENT_TIME) && (descrIndex == CY_BLE_CTS_CURRENT_TIME_CCCD)) - { - if(cy_ble_ctsConfigPtr->ctss->currTimeCccdHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ctsConfigPtr->ctss->currTimeCccdHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSS_SendNotification -***************************************************************************//** -* -* Sends a notification to the client's device. A characteristic value also gets -* written to the GATT database. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_CTSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic to be send as a notification -* to the Client device. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic notification was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - if(CY_BLE_CTS_CURRENT_TIME != charIndex) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - apiResult = Cy_BLE_CTSS_SetCharacteristicValue(charIndex, attrSize, attrValue); - if(apiResult == CY_BLE_SUCCESS) - { - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((cy_ble_ctsConfigPtr->ctss->currTimeCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) || - (!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_ctsConfigPtr->ctss->currTimeCccdHandle))) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_ctsConfigPtr->ctss->currTimeCharHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_CTS_SERVER) */ - - -#ifdef CY_BLE_CTS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_CTSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* CTS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_ctsCharUuid[CY_BLE_CTS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_CURRENT_TIME, - CY_BLE_UUID_CHAR_LOCAL_TIME_INFO, - CY_BLE_UUID_CHAR_REF_TIME_INFO - }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CTS)) - { - for(i = 0u; i < (uint32_t)CY_BLE_CTS_CHAR_COUNT; i++) - { - if(cy_ble_ctsCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_ctsc[discIdx].currTimeCharacteristics[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ctsc[discIdx].currTimeCharacteristics[i].valueHandle = discCharInfo->valueHandle; - cy_ble_ctsc[discIdx].currTimeCharacteristics[i].properties = discCharInfo->properties; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* This event is generated when a server successfully sends the data for -* CY_BLE_EVT_GATTC_FIND_INFO_REQ" Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_CTSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CTS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - if(cy_ble_ctsc[discIdx].currTimeCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ctsc[discIdx].currTimeCccdHandle = discDescrInfo->descrHandle; - } - else /* Duplication of descriptor */ - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo->uuid); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_CTSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_CTS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if(cy_ble_discovery[discIdx].charCount == 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME]. - valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_CTS].range.endHandle; - } - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: The pointer to the cy_stc_ble_gattc_handle_value_ntf_param_t data -* structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_CTSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CTS_ApplCallback != NULL)) - { - if(cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME].valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_cts_char_value_t ntfParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_CTS_CURRENT_TIME, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_CTS_ApplCallback((uint32_t)CY_BLE_EVT_CTSC_NOTIFICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event for the Current Time Service. -* -* \param eventParam: The pointer to the data that came with a read response for CTS. -* -******************************************************************************/ -static void Cy_BLE_CTSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrVal = 0u; - cy_en_ble_cts_char_index_t idx = CY_BLE_CTS_CURRENT_TIME; - - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CTS_ApplCallback != NULL) && - (cy_ble_ctscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME].valueHandle == - cy_ble_ctscReqHandle[discIdx]) - { - idx = CY_BLE_CTS_CURRENT_TIME; - } - else - if(cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_LOCAL_TIME_INFO].valueHandle == - cy_ble_ctscReqHandle[discIdx]) - { - idx = CY_BLE_CTS_LOCAL_TIME_INFO; - } - else - if(cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_REFERENCE_TIME_INFO].valueHandle == - cy_ble_ctscReqHandle[discIdx]) - { - idx = CY_BLE_CTS_REFERENCE_TIME_INFO; - } - else if(cy_ble_ctsc[discIdx].currTimeCccdHandle == cy_ble_ctscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - } - else - { - /* No CTS characteristics were requested for read */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* Read response for characteristic */ - if(attrVal == 0u) - { - /* Fill Current Time Service read response parameter structure with - * characteristic info. */ - cy_stc_ble_cts_char_value_t rdRspParam = { .connHandle = eventParam->connHandle }; - rdRspParam.charIndex = idx; - rdRspParam.value = &eventParam->value; - - Cy_BLE_CTS_ApplCallback((uint32_t)CY_BLE_EVT_CTSC_READ_CHAR_RESPONSE, (void*)&rdRspParam); - } - else /* Read response for characteristic descriptor */ - { - /* Fill Current Time Service read response parameter structure with - * characteristic descriptor info. */ - cy_stc_ble_cts_descr_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_CTS_CURRENT_TIME, - .descrIndex = CY_BLE_CTS_CURRENT_TIME_CCCD, - .value = &eventParam->value - }; - Cy_BLE_CTS_ApplCallback((uint32_t)CY_BLE_EVT_CTSC_READ_DESCR_RESPONSE, (void*)&rdRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_ctscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event for the Current Time Service. -* -* \param eventParam: The pointer to the cy_stc_ble_conn_handle_t data structure. -* -******************************************************************************/ -static void Cy_BLE_CTSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_CTS_ApplCallback != NULL) && - (cy_ble_ctscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_ctsc[discIdx].currTimeCccdHandle == cy_ble_ctscReqHandle[discIdx]) - { - cy_stc_ble_cts_descr_value_t wrRspParam = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_CTS_CURRENT_TIME, - .descrIndex = CY_BLE_CTS_CURRENT_TIME_CCCD, - .value = NULL - }; - cy_ble_ctscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CTS_ApplCallback((uint32_t)CY_BLE_EVT_CTSC_WRITE_DESCR_RESPONSE, (void*)&wrRspParam); - } - else if((cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME].valueHandle == - cy_ble_ctscReqHandle[discIdx]) || - (cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_LOCAL_TIME_INFO].valueHandle == - cy_ble_ctscReqHandle[discIdx])) - { - cy_stc_ble_cts_char_value_t wrRspParam; - if(cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME].valueHandle == - cy_ble_ctscReqHandle[discIdx]) - { - wrRspParam.charIndex = CY_BLE_CTS_CURRENT_TIME; - } - else - { - wrRspParam.charIndex = CY_BLE_CTS_LOCAL_TIME_INFO; - } - wrRspParam.connHandle = *eventParam; - wrRspParam.value = NULL; - - cy_ble_ctscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_CTS_ApplCallback((uint32_t)CY_BLE_EVT_CTSC_WRITE_CHAR_RESPONSE, (void*)&wrRspParam); - } - else - { - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event for the Current Time Service. -* -* \param eventParam: The pointer to the cy_stc_ble_gatt_err_param_t structure. -* -******************************************************************************/ -static void Cy_BLE_CTSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_ctscReqHandle[discIdx]) - { - cy_ble_ctscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_CTSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: Pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CTS service-specific callback is registered -* (with Cy_BLE_CTS_RegisterAttrCallback): -* * CY_BLE_EVT_CTSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cts_char_value_t. -* . -* Otherwise (if the CTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Select characteristic */ - switch(charIndex) - { - case CY_BLE_CTS_CURRENT_TIME: - writeReqParam.handleValPair.attrHandle = cy_ble_ctsc[discIdx]. - currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME].valueHandle; - break; - - case CY_BLE_CTS_LOCAL_TIME_INFO: - writeReqParam.handleValPair.attrHandle = cy_ble_ctsc[discIdx]. - currTimeCharacteristics[CY_BLE_CTS_LOCAL_TIME_INFO].valueHandle; - break; - - case CY_BLE_CTS_REFERENCE_TIME_INFO: - /* Reference Time Information is read only */ - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - break; - - default: - /* Characteristic wasn't found */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - break; - } - - if(apiResult == CY_BLE_SUCCESS) - { - if(writeReqParam.handleValPair.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send request to read characteristic value */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ctscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the Current Time Service, which is identified -* by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CTS service-specific callback is registered -* (with Cy_BLE_CTS_RegisterAttrCallback): -* * CY_BLE_EVT_CTSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cts_char_value_t. -* . -* Otherwise (if the CTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex) -{ - cy_stc_ble_gattc_read_req_t readReqParam = { .connHandle = connHandle }; - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Select characteristic */ - switch(charIndex) - { - case CY_BLE_CTS_CURRENT_TIME: - readReqParam.attrHandle = cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_CURRENT_TIME].valueHandle; - break; - - case CY_BLE_CTS_LOCAL_TIME_INFO: - readReqParam.attrHandle = cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_LOCAL_TIME_INFO]. - valueHandle; - break; - - case CY_BLE_CTS_REFERENCE_TIME_INFO: - readReqParam.attrHandle = cy_ble_ctsc[discIdx].currTimeCharacteristics[CY_BLE_CTS_REFERENCE_TIME_INFO]. - valueHandle; - break; - - default: - /* Characteristic wasn't found */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - break; - } - - if(apiResult == CY_BLE_SUCCESS) - { - if(readReqParam.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send request to read characteristic value */ - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ctscReqHandle[discIdx] = readReqParam.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets a characteristic descriptor of the Current Time Characteristic of the -* Current Time Service. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_CTSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_CTSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the Current Time Service characteristic. -* \param descrIndex: The index of the Current Time Service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: Pointer to the characteristic descriptor value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* specified attribute. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CTS service-specific callback is registered -* (with Cy_BLE_CTS_RegisterAttrCallback): -* * CY_BLE_EVT_CTSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_cts_descr_value_t. -* . -* Otherwise (if the CTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - cy_en_ble_cts_char_descriptors_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (charIndex == CY_BLE_CTS_CURRENT_TIME) && (descrIndex == CY_BLE_CTS_CURRENT_TIME_CCCD) && - (attrSize == CY_BLE_CCCD_LEN)) - { - if(cy_ble_ctsc[discIdx].currTimeCccdHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .handleValPair.attrHandle = cy_ble_ctsc[discIdx].currTimeCccdHandle, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ctscReqHandle[discIdx] = cy_ble_ctsc[discIdx].currTimeCccdHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - /* Parameter validation failed */ - } - - /* Return the status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CTSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the Current Time Characteristic of the -* Current Time Service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - State is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the CTS service-specific callback is registered -* (with Cy_BLE_CTS_RegisterAttrCallback): -* * CY_BLE_EVT_CTSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_cts_descr_value_t. -* . -* Otherwise (if the CTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CTSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - uint8_t descrIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (charIndex == CY_BLE_CTS_CURRENT_TIME) && - (descrIndex == ((uint8_t)CY_BLE_CTS_CURRENT_TIME_CCCD))) - { - if(cy_ble_ctsc[discIdx].currTimeCccdHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_ctsc[discIdx].currTimeCccdHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ctscReqHandle[discIdx] = cy_ble_ctsc[discIdx].currTimeCccdHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - /* Validation of input parameters failed */ - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_CTS_CLIENT) */ - -/****************************************************************************** -* Function Name: Cy_BLE_CTS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Current Time Service Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CTS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_CTS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_CTSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_CTSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_CTSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_CTS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_CTS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_CTSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_CTS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_CTS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_CTSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_CTSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_CTSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_CTSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_CTS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} -#endif /* defined(CY_BLE_CTS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cts.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cts.h deleted file mode 100644 index 1349c4f9e2..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_cts.h +++ /dev/null @@ -1,316 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_cts.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Current Time Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_CTS_H -#define CY_BLE_CTS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CTS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_CTS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Service Characteristics indexes */ -typedef enum -{ - CY_BLE_CTS_CURRENT_TIME, /**< Current Time characteristic index */ - CY_BLE_CTS_LOCAL_TIME_INFO, /**< Local Time Information characteristic index */ - CY_BLE_CTS_REFERENCE_TIME_INFO, /**< Reference Time Information characteristic index */ - CY_BLE_CTS_CHAR_COUNT /**< Total count of Current Time Service characteristics */ -}cy_en_ble_cts_char_index_t; - -/** Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_CTS_CURRENT_TIME_CCCD, /**< Current Time Client Characteristic configuration descriptor index */ - CY_BLE_CTS_COUNT /**< Total count of Current Time Service characteristic descriptors */ -}cy_en_ble_cts_char_descriptors_t; - -/** Current Time Characteristic structure */ -typedef struct -{ - uint8_t yearLow; /**< LSB of current year */ - uint8_t yearHigh; /**< MSB of current year */ - uint8_t month; /**< Current month */ - uint8_t day; /**< Current day */ - uint8_t hours; /**< Current time - hours */ - uint8_t minutes; /**< Current time - minutes */ - uint8_t seconds; /**< Current time - seconds */ - uint8_t dayOfWeek; /**< Current day of week */ - uint8_t fractions256; /**< The value of 1/256th of second */ - uint8_t adjustReason; /**< Reason of Current Time service characteristics change */ -} cy_stc_ble_cts_current_time_t; - -/** Local Time Information Characteristic structure */ -typedef struct -{ - int8_t timeZone; /**< Current Time Zone */ - uint8_t dst; /**< Daylight Saving Time value */ -} cy_stc_ble_cts_local_time_info_t; - -/** Reference Time Information Characteristic structure */ -typedef struct -{ - uint8_t timeSource; /**< Time update source */ - uint8_t timeAccuracy; /**< Time accuracy */ - uint8_t daysSinceUpdate; /**< Days since last time update */ - uint8_t hoursSinseUpdate; /**< Hours since last time update */ -} cy_stc_ble_cts_reference_time_info_t; - -/** Current Time Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_cts_char_index_t charIndex; /**< Characteristic index of Current Time Service */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Current Time Service characteristic */ -} cy_stc_ble_cts_char_value_t; - -/** Current Time Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_cts_char_index_t charIndex; /**< Characteristic index of Current Time Service */ - cy_en_ble_cts_char_descriptors_t descrIndex; /**< Characteristic index Descriptor of Current Time Service */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Current Time Service characteristic */ -} cy_stc_ble_cts_descr_value_t; - -/** Structure with Current Time Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Current Time Service handle */ - cy_ble_gatt_db_attr_handle_t currTimeCharHandle; /**< Current Time Characteristic handle */ - cy_ble_gatt_db_attr_handle_t currTimeCccdHandle; /**< Current Time Client Characteristic Configuration - * Characteristic handle */ - cy_ble_gatt_db_attr_handle_t localTimeInfCharHandle; /**< Local Time Information Characteristic handle */ - cy_ble_gatt_db_attr_handle_t refTimeInfCharHandle; /**< Reference Time Information Characteristic handle */ -} cy_stc_ble_ctss_t; - -/** Structure with discovered attributes information of Current Time Service */ -typedef struct -{ - /** Structure with Characteristic handles + properties of Current Time Service */ - cy_stc_ble_srvr_char_info_t currTimeCharacteristics[CY_BLE_CTS_CHAR_COUNT]; - - /** Current Time Client Characteristic Configuration handle of Current Time Service */ - cy_ble_gatt_db_attr_handle_t currTimeCccdHandle; -} cy_stc_ble_ctsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Current Time Service GATT DB handles structure */ - const cy_stc_ble_ctss_t *ctss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_cts_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_CTS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_CTS_Init(cy_stc_ble_cts_config_t *config); -cy_en_ble_api_result_t Cy_BLE_CTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -/* GATT Server API functions */ -#ifdef CY_BLE_CTS_SERVER -/** - * \addtogroup group_ble_service_api_CTS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CTSS_SetCharacteristicValue(cy_en_ble_cts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CTSS_GetCharacteristicValue(cy_en_ble_cts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CTSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - cy_en_ble_cts_char_descriptors_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* (CY_BLE_CTS_SERVER) */ - -/* GATT Client API functions */ -#ifdef CY_BLE_CTS_CLIENT -/** - * \addtogroup group_ble_service_api_CTS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_CTSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CTSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_CTSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, - cy_en_ble_cts_char_descriptors_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_CTSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_cts_char_index_t charIndex, uint8_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_CTS_CLIENT) */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_CTS_CURRENT_TIME_SIZE (10u) -#define CY_BLE_CTS_LOCAL_TIME_INFO_SIZE (2u) -#define CY_BLE_CTS_REFERENCE_TIME_INFO_SIZE (4u) -#define CY_BLE_CTS_CLIENT_CONFIG_DESCR_SIZE (2u) - -/* CTS GATT error codes */ -#define CY_BLE_GATT_ERR_CTS_DATA_FIELD_IGNORED ((cy_en_ble_gatt_err_code_t)(0x80u)) - - -/*************************************** -* Current Time ranges -***************************************/ - -/* The range of "Year" is from 1582 to 9999. "Year" is split into two bytes and - * the following values define the maximum and minimum allowed years. */ -#define CY_BLE_CTS_YEAR_MAX (9999u) -#define CY_BLE_CTS_YEAR_MIN (1582u) - -/* Range of "Month" is 0 to 12 */ -#define CY_BLE_CTS_MONTH_MAX (12u) - -/* Range of "Month" is 0 to 31 */ -#define CY_BLE_CTS_DAY_MAX (31u) - -/* Range of "Hours" is 0 to 24 */ -#define CY_BLE_CTS_HOURS_MAX (23u) - -/* Range of "Minutes" is 0 to 59 */ -#define CY_BLE_CTS_MINUTES_MAX (59u) - -/* Range of "Seconds" is 0 to 59 */ -#define CY_BLE_CTS_SECONDS_MAX (CY_BLE_CTS_MINUTES_MAX) - -/* Range of "dayOfWeek" is 1 to 7 */ -#define CY_BLE_CTS_DAY_OF_WEEK_MAX (7u) - -/* Current Time update reasons */ -#define CY_BLE_CTS_REASON_UNKNOWN (0u) -#define CY_BLE_CTS_MANUAL_UPDATE (1u) -#define CY_BLE_CTS_EXTERNAL_REF_UPDATE (2u) -#define CY_BLE_CTS_TIME_ZONE_CHANGE (4u) -#define CY_BLE_CTS_DST_CHANGE (8u) - -#define CY_BLE_CTS_MAX_DAYS_SINCE_UPDATE (255u) -#define CY_BLE_CTS_MAX_HOURS_SINCE_UPDATE (CY_BLE_CTS_MAX_DAYS_SINCE_UPDATE) - -/* DST offset values */ -#define CY_BLE_CTS_STANDARD_TIME (0u) -#define CY_BLE_CTS_DAYLIGHT_TIME_0_5 (2u) -#define CY_BLE_CTS_DAYLIGHT_TIME_1_0 (4u) -#define CY_BLE_CTS_DAYLIGHT_TIME_2_0 (8u) -#define CY_BLE_CTS_DST_UNKNOWN (255u) - -#define CY_BLE_CTS_UTC_OFFSET_MAX (56) -#define CY_BLE_CTS_UTC_OFFSET_MIN (-48) -#define CY_BLE_CTS_UTC_OFFSET_UNKNOWN (-127) - -/* Time update source constants */ -#define CY_BLE_CTS_TIME_SRC_UNKNOWN (0u) -#define CY_BLE_CTS_TIME_SRC_NTP (1u) -#define CY_BLE_CTS_TIME_SRC_GPS (2u) -#define CY_BLE_CTS_TIME_SRC_RADIO (3u) -#define CY_BLE_CTS_TIME_SRC_MANUAL (4u) -#define CY_BLE_CTS_TIME_SRC_ATOMIC_CLK (5u) -#define CY_BLE_CTS_TIME_SRC_CELL_NET (6u) - -/* Client Characteristic Configuration Descriptor constants */ -#define CY_BLE_CTS_CLIENT_CONFIG_MASK (0x03u) -#define CY_BLE_CTS_CLIENT_CONFIG_NTF_ENABLED (0x01u) -#define CY_BLE_CTS_CLIENT_CONFIG_IND_ENABLED (0x02u) - -#define CY_BLE_CTS_INVALID_CHAR_INDEX (0xFFu) - -#define CY_BLE_CTS_8_BIT_OFFSET (8u) - -#ifdef CY_BLE_CTS_SERVER - -/* Performs validation of 'adjReason' if it has invalid value, it will be set to - * "Unknown" reason. */ -#define CY_BLE_CTS_CHECK_ADJUST_REASON(adjReason) ((adjReason) = \ - (((adjReason) == CY_BLE_CTS_REASON_UNKNOWN) ? \ - CY_BLE_CTS_REASON_UNKNOWN : \ - (((adjReason) == CY_BLE_CTS_MANUAL_UPDATE) ? \ - CY_BLE_CTS_MANUAL_UPDATE : \ - (((adjReason) == CY_BLE_CTS_EXTERNAL_REF_UPDATE) ? \ - CY_BLE_CTS_EXTERNAL_REF_UPDATE : \ - (((adjReason) == CY_BLE_CTS_TIME_ZONE_CHANGE) ? \ - CY_BLE_CTS_TIME_ZONE_CHANGE : \ - (((adjReason) == CY_BLE_CTS_DST_CHANGE) ? \ - CY_BLE_CTS_DST_CHANGE : \ - CY_BLE_CTS_REASON_UNKNOWN)))))) - -#endif /* (CY_BLE_CTS_SERVER) */ - - -/*************************************** -* Variables with external linkage -***************************************/ -#ifdef CY_BLE_CTS_CLIENT -extern cy_stc_ble_ctsc_t cy_ble_ctsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_CTS_CLIENT) */ - -extern cy_stc_ble_cts_config_t cy_ble_ctsConfig; -extern cy_stc_ble_cts_config_t *cy_ble_ctsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_CTS) */ -#endif /* CY_BLE_CTS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_custom.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_custom.c deleted file mode 100644 index ffca886507..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_custom.c +++ /dev/null @@ -1,513 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_custom.c -* \version 2.0 -* -* \brief -* Contains the source code for the Custom Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CUSTOM)) - -/* The pointer on global BLE CUSTOM Config structure */ -cy_stc_ble_custom_config_t *cy_ble_customConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_CUSTOM_CLIENT -static void Cy_BLE_CUSTOMC_DiscoverServiceEventHandler(const cy_stc_ble_disc_srv_info_t *discServInfo); -static void Cy_BLE_CUSTOMC_DiscoverCharacteristicsEventHandler(const cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_CUSTOMC_DiscoverCharDescriptorsEventHandler(const cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_CUSTOMC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -#endif /* (CY_BLE_CUSTOM_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_CUSTOM_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_CUSTOM_Init -***************************************************************************//** -* -* This function initializes a Custom Service. -* -* \param config: Configuration structure for the Custom Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_CUSTOM_Init(cy_stc_ble_custom_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_customConfigPtr = config; - - /* Registers Event Handler for the Custom Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CUSTOM_EventHandler); - - #ifdef CY_BLE_CUSTOM_CLIENT - { - uint32_t discIdx; - uint32_t locServIdx; - uint32_t locCharIdx; - uint32_t locDescIdx; - for(discIdx = 0u; discIdx < CY_BLE_CONFIG_GATTC_COUNT; discIdx++) - { - for(locServIdx = 0u; locServIdx < CY_BLE_CUSTOMC_SERVICE_COUNT; locServIdx++) - { - if(cy_ble_serverInfo[discIdx][CY_BLE_SRVI_CUSTOMS + locServIdx].range.startHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - for(locCharIdx = 0u; locCharIdx < cy_ble_customConfigPtr->customc[locServIdx].charCount; - locCharIdx++) - { - cy_ble_customConfigPtr->customc[locServIdx].customServChar[locCharIdx]. - customServCharHandle[discIdx] = 0u; - - for(locDescIdx = 0u; locDescIdx < cy_ble_customConfigPtr->customc[locServIdx]. - customServChar[locCharIdx].descCount; locDescIdx++) - { - cy_ble_customConfigPtr->customc[locServIdx].customServChar[locCharIdx]. - customServCharDesc[locDescIdx].descHandle[discIdx] = 0u; - } - - /* initialize uuid */ - cy_ble_serverInfo[discIdx][CY_BLE_SRVI_CUSTOMS + locServIdx].uuid = 0x0000u; - } - } - } - } - } - #endif /* (CY_BLE_CUSTOM_CLIENT) */ - } - - return(apiResult); -} - - -#ifdef CY_BLE_CUSTOM_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_CUSTOMC_DiscoverServiceEventHandler -***************************************************************************//** -* -* This function is called on receiving a Read By Group Response event or -* Read response with 128-bit service uuid. -* -* \param connHandle: The connection handle. -* \param discServInfo: The pointer to a service information structure. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_CUSTOMC_DiscoverServiceEventHandler(const cy_stc_ble_disc_srv_info_t *discServInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discServInfo->connHandle); - uint32_t fFlag = 0u; - uint32_t j; - - /* Services with 128 bit UUID have discServInfo->uuid equal to 0 and address to - * 128 uuid is stored in cy_ble_customCServ.uuid128 - */ - for(j = 0u; (j < CY_BLE_CUSTOMC_SERVICE_COUNT) && (fFlag == 0u); j++) - { - if(cy_ble_customConfigPtr->customc[j].uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT) - { - if(memcmp(cy_ble_customConfigPtr->customc[j].uuid, &discServInfo->srvcInfo->uuid.uuid128, - CY_BLE_GATT_128_BIT_UUID_SIZE) == 0u) - { - if(cy_ble_serverInfo[discIdx][j + (uint32_t)CY_BLE_SRVI_CUSTOMS].range.startHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_serverInfo[discIdx][j + (uint32_t)CY_BLE_SRVI_CUSTOMS].range = discServInfo->srvcInfo->range; - cy_ble_discovery[discIdx].servCount++; - fFlag = 1u; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CUSTOMC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service index, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_CUSTOMC_DiscoverCharacteristicsEventHandler(const cy_stc_ble_disc_char_info_t *discCharInfo) -{ - static cy_ble_gatt_db_attr_handle_t *customsLastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - static uint32_t discoveryLastServ[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t servIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_CUSTOMS; - uint32_t locReqHandle = 0u; - uint32_t locCharIndex; - - if((cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_CUSTOMS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_CUSTOMS_END)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(customsLastEndHandle[discIdx] != NULL) - { - if(discoveryLastServ[discIdx] == servIdx) - { - *customsLastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - } - customsLastEndHandle[discIdx] = NULL; - } - - for(locCharIndex = 0u; (locCharIndex < cy_ble_customConfigPtr->customc[servIdx].charCount) && (locReqHandle == 0u); - locCharIndex++) - { - uint32_t fFlag = 0u; - - /* Support 128 bit uuid */ - if((discCharInfo->uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT) && - (cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].uuidFormat == - CY_BLE_GATT_128_BIT_UUID_FORMAT)) - { - if(memcmp(cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].uuid, - &discCharInfo->uuid.uuid128, CY_BLE_GATT_128_BIT_UUID_SIZE) == 0u) - { - fFlag = 1u; - } - } - - /* And support 16 bit uuid */ - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].uuidFormat == - CY_BLE_GATT_16_BIT_UUID_FORMAT)) - { - if(memcmp(cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].uuid, - &discCharInfo->uuid.uuid16, CY_BLE_GATT_16_BIT_UUID_SIZE) == 0u) - { - fFlag = 1u; - } - } - - if((fFlag == 1u) && - (cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].customServCharHandle[discIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].customServCharHandle[discIdx] = - discCharInfo->valueHandle; - cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex].properties[discIdx] = - discCharInfo->properties; - - /* Init pointer to characteristic endHandle */ - customsLastEndHandle[discIdx] = &cy_ble_customConfigPtr->customc[servIdx].customServChar[locCharIndex]. - customServCharEndHandle[discIdx]; - - /* Init service index of discovered characteristic */ - discoveryLastServ[discIdx] = servIdx; - locReqHandle = 1u; - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(customsLastEndHandle[discIdx] != NULL) - { - *customsLastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range. - endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GetCustomCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_CUSTOMC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if((cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_CUSTOMS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_CUSTOMS_END)) - { - uint32_t servIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_CUSTOMS; - - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < cy_ble_customConfigPtr->customc[servIdx].charCount) && - (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if(cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx].descCount > 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx]. - customServCharHandle[discIdx] + 1u; - charRangeInfo->range.endHandle = cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx]. - customServCharEndHandle[discIdx]; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_CUSTOMC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_CUSTOMC_DiscoverCharDescriptorsEventHandler(const cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t locDescIndex; - uint32_t locReqHandle = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if((cy_ble_discovery[discIdx].servCount >= ((uint32_t)CY_BLE_SRVI_CUSTOMS)) && - (cy_ble_discovery[discIdx].servCount <= ((uint32_t)CY_BLE_SRVI_CUSTOMS_END))) - { - uint32_t servIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_CUSTOMS; - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - - for(locDescIndex = 0u; (locDescIndex < cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx].descCount) && - (locReqHandle == 0u); locDescIndex++) - { - uint32_t fFlag = 0u; - - if((discDescrInfo->uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT) && - (cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx].customServCharDesc[locDescIndex]. - uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT)) - { - if(memcmp(cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx]. - customServCharDesc[locDescIndex].uuid, &discDescrInfo->uuid.uuid128, - CY_BLE_GATT_128_BIT_UUID_SIZE) == 0u) - { - fFlag = 1u; - } - } - - if((discDescrInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx].customServCharDesc[locDescIndex]. - uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT)) - { - if(memcmp(cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx]. - customServCharDesc[locDescIndex].uuid, &discDescrInfo->uuid.uuid16, - CY_BLE_GATT_16_BIT_UUID_SIZE) == 0u) - { - fFlag = 1u; - } - } - - if((fFlag == 1u) && - (cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx].customServCharDesc[locDescIndex]. - descHandle[discIdx] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_ble_customConfigPtr->customc[servIdx].customServChar[charIdx].customServCharDesc[locDescIndex]. - descHandle[discIdx] = discDescrInfo->descrHandle; - locReqHandle = 1u; - } - } - } -} - -#endif /* (CY_BLE_CUSTOM_CLIENT) */ - -/****************************************************************************** -* Function Name: Cy_BLE_CUSTOM_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Custom Service. -* -* \param eventCode: The event code -* \param eventParam: The event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_CUSTOM_EventHandler(uint32_t eventCode, - void *eventParam) -{ - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_CUSTOM_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_SERVICE: - Cy_BLE_CUSTOMC_DiscoverServiceEventHandler((cy_stc_ble_disc_srv_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_CUSTOMC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_CUSTOMC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_CUSTOMC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_CUSTOM_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_CUSTOM_CLIENT - case CY_BLE_EVT_GATTC_READ_RSP: - case CY_BLE_EVT_GATTC_READ_MULTI_RSP: - { - cy_stc_ble_gattc_read_rsp_param_t *eventParamCast = (cy_stc_ble_gattc_read_rsp_param_t*)eventParam; - cy_stc_ble_conn_handle_t locConnHandle = eventParamCast->connHandle; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(locConnHandle); - - /* Read response with 128-bit included service uuid */ - if((Cy_BLE_GetConnectionState(locConnHandle) == CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING) && - (discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].inclInfo.inclDefHandle != 0u)) - { - cy_stc_ble_disc_srvc128_info_t discServ128Info; - cy_stc_ble_disc_srv_info_t locDiscServInfo = - { - .srvcInfo = &discServ128Info, - .connHandle = locConnHandle - }; - - /* Store service range */ - discServ128Info.range = cy_ble_discovery[discIdx].inclInfo.inclHandleRange; - (void)memcpy((void*)discServ128Info.uuid.uuid128.value, (void*)eventParamCast->value.val, - (uint32_t)eventParamCast->value.len); - Cy_BLE_CUSTOMC_DiscoverServiceEventHandler(&locDiscServInfo); - - /* Re-initiate Cy_BLE_GATTC_FindIncludedServices function, setting the start - * handle to the attribute handle which is placed next to the one used in - * the above step. - */ - discServ128Info.range.startHandle = cy_ble_discovery[discIdx].inclInfo.inclDefHandle + 1u; - discServ128Info.range.endHandle = - cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - if(discServ128Info.range.startHandle <= discServ128Info.range.endHandle) - { - cy_stc_ble_gattc_read_by_type_req_t requestParam = - { - .range = discServ128Info.range, - .connHandle = eventParamCast->connHandle - }; - if(Cy_BLE_GATTC_FindIncludedServices(&requestParam) != CY_BLE_SUCCESS) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_INCL_DISCOVERY_FAILED, - &eventParamCast->connHandle); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - } - } - else /* Continue discovery of the following service */ - { - Cy_BLE_NextInclDiscovery(eventParamCast->connHandle, CY_BLE_DISCOVERY_CONTINUE); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_discovery[discIdx].inclInfo.inclDefHandle = 0u; - } - } - break; - #endif /* CY_BLE_CUSTOM_CLIENT */ - - default: - break; - } - } - - return(CY_BLE_GATT_ERR_NONE); -} -#endif /* defined(CY_BLE_CUSTOM) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_custom.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_custom.h deleted file mode 100644 index 05ece0fb81..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_custom.h +++ /dev/null @@ -1,193 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_custom.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Custom Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_CUSTOM_H -#define CY_BLE_CUSTOM_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_CUSTOM)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -/* Maximum supported Custom Services */ -#define CY_BLE_CUSTOMS_SERVICE_COUNT (CY_BLE_CONFIG_CUSTOMS_SERVICE_COUNT) -#define CY_BLE_CUSTOMC_SERVICE_COUNT (CY_BLE_CONFIG_CUSTOMC_SERVICE_COUNT) -#define CY_BLE_CUSTOM_SERVICE_CHAR_COUNT (CY_BLE_CONFIG_CUSTOM_SERVICE_CHAR_COUNT) -#define CY_BLE_CUSTOM_SERVICE_CHAR_DESCRIPTORS_COUNT (CY_BLE_CONFIG_CUSTOM_SERVICE_CHAR_DESCRIPTORS_COUNT) - -#if (CY_BLE_CUSTOMS_SERVICE_COUNT != 0u) - #define CY_BLE_CUSTOM_SERVER -#endif /* (CY_BLE_CUSTOMS_SERVICE_COUNT != 0u) */ - -#if (CY_BLE_CUSTOMC_SERVICE_COUNT != 0u) - #define CY_BLE_CUSTOM_CLIENT -#endif /* (CY_BLE_CUSTOMC_SERVICE_COUNT != 0u) */ - -/*************************************** -* Data Types -***************************************/ - -/** - * \addtogroup group_ble_service_api_custom - * @{ - */ - -#ifdef CY_BLE_CUSTOM_SERVER - -/** Contains information about Custom Characteristic structure */ -typedef struct -{ - /** Custom Characteristic handle */ - cy_ble_gatt_db_attr_handle_t customServCharHandle; - - /** Custom Characteristic Descriptors handles */ - cy_ble_gatt_db_attr_handle_t customServCharDesc[ /* MDK doesn't allow array with zero length */ - (CY_BLE_CUSTOM_SERVICE_CHAR_DESCRIPTORS_COUNT == 0u) ? 1u : CY_BLE_CUSTOM_SERVICE_CHAR_DESCRIPTORS_COUNT]; -} cy_stc_ble_customs_info_t; - -/** Structure with Custom Service attribute handles. */ -typedef struct -{ - /** Handle of a Custom Service */ - cy_ble_gatt_db_attr_handle_t customServHandle; - - /** Information about Custom Characteristics */ - cy_stc_ble_customs_info_t customServInfo[ /* MDK doesn't allow array with zero length */ - (CY_BLE_CUSTOM_SERVICE_CHAR_COUNT == 0u ) ? 1u : CY_BLE_CUSTOM_SERVICE_CHAR_COUNT]; -} cy_stc_ble_customs_t; - -#endif /* CY_BLE_CUSTOM_SERVER */ - -#ifdef CY_BLE_CUSTOM_CLIENT - -/** Structure with discovered attributes information of Custom Service Descriptors */ -typedef struct -{ - /** Custom Descriptor handle */ - cy_ble_gatt_db_attr_handle_t descHandle[CY_BLE_CONFIG_GATTC_COUNT]; - - /** Custom Descriptor 128 bit UUID */ - const void *uuid; - - /** UUID Format - 16-bit (0x01) or 128-bit (0x02) */ - uint8_t uuidFormat; -} cy_stc_ble_customc_desc_t; - -/** Structure with discovered attributes information of Custom Service Characteristics */ -typedef struct -{ - /** Characteristic handle */ - cy_ble_gatt_db_attr_handle_t customServCharHandle[CY_BLE_CONFIG_GATTC_COUNT]; - - /** Characteristic end handle */ - cy_ble_gatt_db_attr_handle_t customServCharEndHandle[CY_BLE_CONFIG_GATTC_COUNT]; - - /** Custom Characteristic UUID */ - const void *uuid; - - /** UUID Format - 16-bit (0x01) or 128-bit (0x02) */ - uint8_t uuidFormat; - - /** Properties for value field */ - uint8_t properties[CY_BLE_CONFIG_GATTC_COUNT]; - - /** Number of descriptors */ - uint8_t descCount; - - /** Characteristic Descriptors */ - cy_stc_ble_customc_desc_t * customServCharDesc; -} cy_stc_ble_customc_char_t; - -/** Structure with discovered attributes information of Custom Service */ -typedef struct -{ - /** Custom Service handle */ - cy_ble_gatt_db_attr_handle_t customServHandle[CY_BLE_CONFIG_GATTC_COUNT]; - - /** Custom Service UUID */ - const void *uuid; - - /** UUID Format - 16-bit (0x01) or 128-bit (0x02) */ - uint8_t uuidFormat; - - /** Number of characteristics */ - uint8_t charCount; - - /** Custom Service Characteristics */ - cy_stc_ble_customc_char_t * customServChar; -} cy_stc_ble_customc_t; - -#endif /* CY_BLE_CUSTOM_CLIENT */ - -/** Service configuration structure */ -typedef struct -{ -#ifdef CY_BLE_CUSTOM_SERVER - /** Custom Services GATT DB handles structure */ - const cy_stc_ble_customs_t *customs; -#endif /* CY_BLE_CUSTOM_SERVER */ - -#ifdef CY_BLE_CUSTOM_CLIENT - /** Custom Service handle */ - cy_stc_ble_customc_t *customc; -#endif /* CY_BLE_CUSTOM_CLIENT */ -} cy_stc_ble_custom_config_t; - -/** @} */ - -/*************************************** -* Function Prototypes -***************************************/ -cy_en_ble_api_result_t Cy_BLE_CUSTOM_Init(cy_stc_ble_custom_config_t *config); - - -/*************************************** -* External data references -***************************************/ -/** \cond IGNORE */ -#ifdef CY_BLE_CUSTOM_CLIENT -extern cy_stc_ble_customc_t cy_ble_customc[CY_BLE_CUSTOMC_SERVICE_COUNT]; -extern cy_stc_ble_customc_t cy_ble_customCServ[CY_BLE_CUSTOMC_SERVICE_COUNT]; -#endif /* (CY_BLE_CUSTOM_CLIENT) */ - -extern cy_stc_ble_custom_config_t cy_ble_customConfig; -extern cy_stc_ble_custom_config_t *cy_ble_customConfigPtr; - -/*************************************** -* The following code is DEPRECATED and -* should not be used in new projects. -***************************************/ -#define customServiceCharHandle customServCharHandle -#define customServiceCharDescriptors customServCharDesc -#define customServiceHandle customServHandle -#define customServiceInfo customServInfo -/** \endcond */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_CUSTOM) */ -#endif /* CY_BLE_CUSTOM_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_dis.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_dis.c deleted file mode 100644 index e69618668e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_dis.c +++ /dev/null @@ -1,561 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_dis.c -* \version 2.0 -* -* \brief -* Contains the source code for the Device Information Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_DIS)) - -#ifdef CY_BLE_DIS_CLIENT -/* DIS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_disc_t cy_ble_disc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_discReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -static cy_ble_callback_t Cy_BLE_DIS_ApplCallback = NULL; -#endif /* (CY_BLE_DIS_CLIENT) */ - - -/* The pointer on global BLE DIS Config structure */ -cy_stc_ble_dis_config_t *cy_ble_disConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_DIS_CLIENT -static void Cy_BLE_DISC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_DISC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_DISC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_DIS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_DIS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_DIS_Init -***************************************************************************//** -* -* This function initializes the DIS service. -* -* \param config: Configuration structure for the DIS service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_DIS_Init(cy_stc_ble_dis_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_disConfigPtr = config; - - /* Registers Event Handler for the DIS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_DIS_EventHandler); - - - #ifdef CY_BLE_DIS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_DIS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_disc[idx], 0, sizeof(cy_stc_ble_disc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_DIS].uuid = CY_BLE_UUID_DEVICE_INFO_SERVICE; - } - cy_ble_discReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - /* Registers a callback function via config structure*/ - if(cy_ble_disConfigPtr->callbackFunc != NULL) - { - Cy_BLE_DIS_ApplCallback = cy_ble_disConfigPtr->callbackFunc; - } - } - #endif /* CY_BLE_DIS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_DIS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Callback doesn't have events in server role. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for Device Information Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_DIS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - -#ifdef CY_BLE_DIS_CLIENT - Cy_BLE_DIS_ApplCallback = callbackFunc; - if(cy_ble_disConfigPtr != NULL) - { - cy_ble_disConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } -#else - if(callbackFunc != NULL) /* Callback doesn't have events in server role */ - { - } -#endif /* CY_BLE_DIS_CLIENT */ - return(apiResult); -} - -#ifdef CY_BLE_DIS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_DISS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service, which is identified by charIndex, -* to the local database. -* -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_DISS_SetCharacteristicValue(cy_en_ble_dis_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_DIS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_disConfigPtr->diss->charHandle[charIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_DISS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the service, which is identified by charIndex, -* from the GATT database. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_DISS_GetCharacteristicValue(cy_en_ble_dis_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_DIS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_disConfigPtr->diss->charHandle[charIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - -#endif /* CY_BLE_DIS_SERVER */ - -#ifdef CY_BLE_DIS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_DISC_HandleDiscoverCharacteristics -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event. -* Based on the service UUID, an appropriate data structure is populated using the -* data received as part of the callback. -* -* \param *discCharInfo: the pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_DISC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_DIS)) - { - switch(discCharInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_MANUFACTURER_NAME: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_MANUFACTURER_NAME]); - break; - - case CY_BLE_UUID_CHAR_MODEL_NUMBER: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_MODEL_NUMBER]); - break; - - case CY_BLE_UUID_CHAR_SERIAL_NUMBER: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_SERIAL_NUMBER]); - break; - - case CY_BLE_UUID_CHAR_HARDWARE_REV: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_HARDWARE_REV]); - break; - - case CY_BLE_UUID_CHAR_FIRMWARE_REV: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_FIRMWARE_REV]); - break; - - case CY_BLE_UUID_CHAR_SOFTWARE_REV: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_SOFTWARE_REV]); - break; - - case CY_BLE_UUID_CHAR_SYSTEM_ID: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_SYSTEM_ID]); - break; - - case CY_BLE_UUID_CHAR_REG_CERT_DATA: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_REG_CERT_DATA]); - break; - - case CY_BLE_UUID_CHAR_PNP_ID: - Cy_BLE_DISC_CheckCharHandle(cy_ble_disc[discIdx].charInfo[CY_BLE_DIS_PNP_ID]); - break; - - default: - break; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_DISC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server -* which is identified by charIndex. -* -* The Read Response returns the characteristic value in the Attribute Value -* parameter. The Read Response only contains the characteristic value that is -* less than or equal to (MTU - 1) octets in length. If the characteristic value -* is greater than (MTU - 1) octets in length, a Read Long Characteristic Value -* procedure may be used if the rest of the characteristic value is required. -* -* This function call can result in generation of the following events based on -* the response from the server device. -* -* * CY_BLE_EVT_DISC_READ_CHAR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the DIS service-specific callback is registered -* (with Cy_BLE_DIS_RegisterAttrCallback): -* * CY_BLE_EVT_DISC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_dis_char_value_t. -* . -* Otherwise (if the DIS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_DISC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_dis_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((charIndex >= CY_BLE_DIS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_disc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_discReqHandle[discIdx] = cy_ble_disc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_DISC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param *eventParam: the pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_DISC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_en_ble_dis_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_DIS_ApplCallback != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_discReqHandle[discIdx])) - { - for(locCharIndex = CY_BLE_DIS_MANUFACTURER_NAME; locCharIndex < CY_BLE_DIS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_discReqHandle[discIdx] == cy_ble_disc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_dis_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_discReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_DIS_ApplCallback((uint32_t)CY_BLE_EVT_DISC_READ_CHAR_RESPONSE, &locCharValue); - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_DISC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param *eventParam: the pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_DISC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_discReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_discReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* (CY_BLE_DIS_CLIENT) */ - -/****************************************************************************** -* Function Name: Cy_BLE_DIS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Device Information Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_DIS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_DIS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - (void)Cy_BLE_DISC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - #endif /* CY_BLE_DIS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_DIS_CLIENT - case CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP: - /* implementation in cy_ble_event_handler.c */ - break; - - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - Cy_BLE_DISC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - } - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - Cy_BLE_DISC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - } - break; - #endif /* CY_BLE_DIS_CLIENT */ - default: - break; - } - } - - return(CY_BLE_GATT_ERR_NONE); -} - -#endif /* defined(CY_BLE_DIS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ - diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_dis.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_dis.h deleted file mode 100644 index 22c67c180e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_dis.h +++ /dev/null @@ -1,179 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_dis.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Device Information -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_DIS_H -#define CY_BLE_DIS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_DIS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_DIS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** DIS characteristic index */ -typedef enum -{ - CY_BLE_DIS_MANUFACTURER_NAME, /**< Manufacturer Name String characteristic index */ - CY_BLE_DIS_MODEL_NUMBER, /**< Model Number String characteristic index */ - CY_BLE_DIS_SERIAL_NUMBER, /**< Serial Number String characteristic index*/ - CY_BLE_DIS_HARDWARE_REV, /**< Hardware Revision String characteristic index */ - CY_BLE_DIS_FIRMWARE_REV, /**< Firmware Revision String characteristic index */ - CY_BLE_DIS_SOFTWARE_REV, /**< Software Revision String characteristic index */ - CY_BLE_DIS_SYSTEM_ID, /**< System ID characteristic index */ - CY_BLE_DIS_REG_CERT_DATA, /**< IEEE 11073-20601 characteristic index */ - CY_BLE_DIS_PNP_ID, /**< PnP ID characteristic index */ - CY_BLE_DIS_CHAR_COUNT /**< Total count of DIS characteristics */ -}cy_en_ble_dis_char_index_t; - -/** Structure with Device Information Service attribute handles */ -typedef struct -{ - /** Device Information Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Device Information Service Characteristic handles */ - cy_ble_gatt_db_attr_handle_t charHandle[CY_BLE_DIS_CHAR_COUNT]; -} cy_stc_ble_diss_t; - -/** Structure with discovered attributes information of Device Information Service */ -typedef struct -{ - /** Characteristics handle + properties array */ - cy_stc_ble_srvr_char_info_t charInfo[CY_BLE_DIS_CHAR_COUNT]; -} cy_stc_ble_disc_t; - -/** Device Information Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_dis_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_dis_char_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Device Information Service GATT DB handles structure */ - const cy_stc_ble_diss_t *diss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_dis_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_DIS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_DIS_Init(cy_stc_ble_dis_config_t *config); - -cy_en_ble_api_result_t Cy_BLE_DIS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - - -#ifdef CY_BLE_DIS_SERVER -/** - * \addtogroup group_ble_service_api_DIS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_DISS_SetCharacteristicValue(cy_en_ble_dis_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_DISS_GetCharacteristicValue(cy_en_ble_dis_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_DIS_SERVER */ - -#ifdef CY_BLE_DIS_CLIENT -/** - * \addtogroup group_ble_service_api_DIS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_DISC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_dis_char_index_t charIndex); - -/** @} */ -#endif /* (CY_BLE_DIS_CLIENT) */ - - -/*************************************** -* Macro Functions -***************************************/ - -#ifdef CY_BLE_DIS_CLIENT - -#define Cy_BLE_DISC_CheckCharHandle(handle) \ - do { \ - if((handle).valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \ - { \ - (handle).valueHandle = discCharInfo->valueHandle; \ - (handle).properties = discCharInfo->properties; \ - } \ - else \ - { \ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \ - &(discCharInfo)); \ - } \ - } while(0) - -#define Cy_BLE_DISC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_DIS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_disc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#endif /* (CY_BLE_DIS_CLIENT) */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_DIS_CLIENT -extern cy_stc_ble_disc_t cy_ble_disc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_DIS_CLIENT) */ - -extern cy_stc_ble_dis_config_t cy_ble_disConfig; -extern cy_stc_ble_dis_config_t *cy_ble_disConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_DIS) */ -#endif /* CY_BLE_DIS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ds.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ds.h deleted file mode 100644 index bdd296513d..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ds.h +++ /dev/null @@ -1,1728 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ds.h -* \version 1.0 -* -* \brief -* Contains the documentation data. -* -******************************************************************************** -* \copyright -* Copyright 2016, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -/** - * \mainpage Cypress BLE Middleware Library - * - * The Bluetooth Low Energy (BLE) middleware contains a comprehensive API list to allow you to configure the BLE stack and the - * underlying chip hardware. - * - * The BLE middleware incorporates a Bluetooth Core Specification v5.0 compliant protocol stack. - * You may access the GAP, GATT and L2CAP layers of the stack using provided API. - * - * The API are broadly categorized as follows: - * - \ref group_ble_common_api - * - \ref group_ble_service_api - * - \ref group_ble_clock_api_section - * - * Features: - * - Multi-link support up to four simultaneous connections in any combination of roles - * - Bluetooth v5.0 compliant protocol stack - * - LE 2 Mbps - * - Generic Access Profile (GAP) Features - * - Broadcaster, Observer, Peripheral and Central roles - * - User-defined advertising data - * - Bonding support for up to four devices - * - Security modes 1 and 2 - * - Generic Attribute Profile (GATT) Features - * - GATT Client and Server - * - 16-, 32-, and 128-bit UUIDs - * - Special Interest Group (SIG) adopted GATT-based Profiles and Services, and quick prototype of new profile design - * through intuitive GUI Custom Profile development; Support of Bluetooth Developer Studio Profile format - * - Security Manager features - * - Pairing methods: Just works, Passkey Entry, Out of Band, Numeric Comparison - * - Authenticated man-in-the-middle (MITM) protection and data signing - * - Logical Link Adaption Protocol (L2CAP) Connection Oriented Channel - * - Link Layer (LL) Features - * - Master and Slave role - * - 128-bit AES encryption - * - Low Duty Cycle Advertising - * - LE Ping - * - * - * \section group_ble_section_more_information More Information - * Refer to the BLE_PDL component datasheet. - * - * - * \section group_ble_MISRA MISRA-C Compliance - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
MISRA ruleRule Class (Required/ Advisory)Rule DescriptionDescription of Deviation(s)
1.2RNo reliance shall be placed on undefined or unspecified behaviour.This specific behavior is explicitly covered in rule 5.1.
5.1RIdentifiers (internal and external) shall not rely on the significance of more than 31 characters.This rule applies to ISO:C90 standard. PDL conforms to ISO:C99 that does not require this limitation.
9.3RIn an enumerator list, the '=' construct shall not be used to explicitly initialise members other than the - * first, unless all items are explicitly initialised.There are enumerator lists which depend on configurations (e.g. cy_en_ble_srvi_t) and require to - * use the '=' construct for calculating the instance count for the multi-instances services, - * such as HIDS, BAS or CUSTOM
10.1RThe value of an expression of integer type shall not be implicitly converted to a different underlying type - * under some circumstances.An operand of essentially enum type is being converted to unsigned type as a result of an arithmetic or - * conditional operation. The conversion does not have any unintended effect.
11.4AA cast should not be performed between a pointer to object type and a different pointer to object type.A cast involving pointers is conducted with caution that the pointers are correctly aligned for the type of - * object being pointed to.
11.5AA cast shall not be performed that removes any const or volatile qualification from the type addressed by a - * pointer.The const or volatile qualification is lost during pointer cast before passing to the stack functions.
13.7RBoolean operations whose results are invariant shall not be permitted.A Boolean operator can yield a result that can be proven to be always "true" or always "false" in some specific - * configurations because of generalized implementation approach.
16.7AThe object addressed by the pointer parameter is not modified and so the pointer could be of type 'pointer to const'.The 'base' and 'content' parameters in Cy_BLE_DeepSleepCallback function are not used by BLE but callback type is universal for all drivers.
18.4RUnions shall not be used.The use of deviations is acceptable for packing and unpacking of data, for example when sending and - * receiving messages, and implementing variant records provided that the variants are differentiated - * by a common field.
- * - * - * \section group_ble_changelog Changelog - * - * - * - * - * - * - * - *
VersionChangesReason for Change
1.0Initial version.
- * - * - * - * - * - * - * \defgroup group_ble_common_api BLE Common API - * \ingroup group_ble - * - * \brief - * The common API act as a general interface between the BLE application - * and the BLE stack module. The application may use these API to control - * the underlying hardware such as radio power, data encryption and device - * bonding via the stack. It may also access the GAP, GATT and L2CAP layers - * of the stack. These are divided into the following categories: - * - \ref group_ble_common_api_functions - * - \ref group_ble_common_api_gap_functions_section - * - \ref group_ble_common_api_gatt_functions_section - * - \ref group_ble_common_api_l2cap_functions - * - * These API also use API specific definitions and data structures. These are classified - * in the following subset: - * - \ref group_ble_common_api_definitions - * - * - * \defgroup group_ble_common_api_functions BLE Common Core Functions - * \ingroup group_ble_common_api - * \brief - * The common core API are used for general BLE component configuration. - * These include initialization, power management, and utilities. - * - * - * \defgroup group_ble_common_api_gap_functions_section GAP Functions - * \ingroup group_ble_common_api - * \brief - * The GAP APIs allow access to the Generic Access Profile (GAP) layer - * of the BLE stack. Depending on the chosen GAP role in the GUI, you may - * use a subset of the supported APIs. - * - * The GAP API names begin with Cy_BLE_GAP_. In addition to this, the APIs - * also append the GAP role initial letter in the API name. - * - * \defgroup group_ble_common_api_gap_functions GAP Central and Peripheral Functions - * \ingroup group_ble_common_api_gap_functions_section - * \brief - * These are APIs common to both GAP Central role and GAP Peripheral role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_GAP_ - * - * \defgroup group_ble_common_api_gap_central_functions GAP Central Functions - * \ingroup group_ble_common_api_gap_functions_section - * \brief - * APIs unique to designs configured as a GAP Central role. - * - * A letter 'C' is appended to the API name: Cy_BLE_GAPC_ - * - * \defgroup group_ble_common_api_gap_peripheral_functions GAP Peripheral Functions - * \ingroup group_ble_common_api_gap_functions_section - * \brief - * APIs unique to designs configured as a GAP Peripheral role. - * - * A letter 'P' is appended to the API name: Cy_BLE_GAPP_ - * - * - * \defgroup group_ble_common_api_gatt_functions_section GATT Functions - * \ingroup group_ble_common_api - * \brief - * The GATT APIs allow access to the Generic Attribute Profile (GATT) layer - * of the BLE stack. Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported APIs. - * - * The GATT API names begin with CyBle_Gatt. In addition to this, the APIs - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_common_api_gatt_functions GATT Client and Server Functions - * \ingroup group_ble_common_api_gatt_functions_section - * \brief - * These are APIs common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_GATT_ - * - * \defgroup group_ble_common_api_gatt_client_functions GATT Client Functions - * \ingroup group_ble_common_api_gatt_functions_section - * \brief - * APIs unique to designs configured as a GATT Client role. - * - * A letter 'C' is appended to the API name: Cy_BLE_GATTC_ - * - * \defgroup group_ble_common_api_gatt_server_functions GATT Server Functions - * \ingroup group_ble_common_api_gatt_functions_section - * \brief - * APIs unique to designs configured as a GATT Server role. - * - * A letter 'S' is appended to the API name: Cy_BLE_GATTS_ - * - * - * \defgroup group_ble_common_api_l2cap_functions L2CAP Functions - * \ingroup group_ble_common_api - * \brief - * The L2CAP APIs allow access to the Logical link control and adaptation - * protocol (L2CAP) layer of the BLE stack. - * - * The L2CAP API names begin with Cy_BLE_L2CAP. - * - * - * - * \defgroup group_ble_common_api_events BLE Common Events - * \ingroup group_ble_common_api - * \brief - * The BLE stack generates events to notify the application on various status - * alerts concerning the stack. These can be generic stack events or can be - * specific to GAP, GATT or L2CAP layers. The service specific events are - * handled separately in \ref group_ble_service_api_events. - * - * - * \defgroup group_ble_common_api_definitions_section BLE Common Definitions and Data Structures - * \ingroup group_ble_common_api - * \brief - * Contains definitions and structures that are common to all BLE common API. - * Note that some of these are also used in Service-specific API. - * - * \defgroup group_ble_common_macros_error BLE Error Code - * \ingroup group_ble_common_api_definitions_section - * \brief - * Contains definitions for all the spec defined error code in Core Spec 5.0, Vol2, Part D - * - * Related Document: - * BLE Standard Spec - CoreV5.0 - * - * \defgroup group_ble_common_api_macros_section Macros - * \ingroup group_ble_common_api_definitions_section - * - * \defgroup group_ble_common_api_macros Common - * \ingroup group_ble_common_api_macros_section - * BLE Common macros - * - * \defgroup group_ble_common_api_macros_gatt_db BLE GATT Database - * \ingroup group_ble_common_api_macros_section - * \brief - * BLE GATT Database macros - * - * \defgroup group_ble_common_api_macros_gatt_uuid_services BLE Services UUID - * \ingroup group_ble_common_api_macros_section - * \brief - * BLE Services Universal Unique Identifier (UUID) macros - * - * \defgroup group_ble_common_api_macros_gatt_uuid_char_gatt_type BLE GATT Attribute Types UUID - * \ingroup group_ble_common_api_macros_section - * \brief - * BLE GATT Attribute Types defined by GATT Profile UUID macros - * - * \defgroup group_ble_common_api_macros_gatt_uuid_char_desc BLE GATT Characteristic Descriptors UUID - * \ingroup group_ble_common_api_macros_section - * \brief - * BLE GATT Attribute Types defined by GATT Profile UUID macros - * - * \defgroup group_ble_common_api_macros_gatt_uuid_char_type BLE GATT Characteristic Types UUID - * \ingroup group_ble_common_api_macros_section - * \brief - * BLE GATT Characteristic Types UUID macros - * - * \defgroup group_ble_common_api_macros_appearance_values BLE Appearance values - * \ingroup group_ble_common_api_macros_section - * \brief - * BLE Appearance values macros - * - * \defgroup group_ble_common_api_data_stuct_section Data Structures - * \ingroup group_ble_common_api_definitions_section - * - * \defgroup group_ble_common_api_definitions Common - * \ingroup group_ble_common_api_data_stuct_section - * \brief - * Contains the common definitions and data structures used in the BLE. - * - * \defgroup group_ble_common_api_gap_definitions GAP - * \ingroup group_ble_common_api_data_stuct_section - * \brief - * Contains the GAP specific definitions and data structures used in the - * GAP APIs. - * - * \defgroup group_ble_common_api_gatt_definitions GATT - * \ingroup group_ble_common_api_data_stuct_section - * \brief - * Contains the GATT specific definitions and data structures used in the - * GATT APIs. - * - * \defgroup group_ble_common_api_l2cap_definitions L2CAP - * \ingroup group_ble_common_api_data_stuct_section - * \brief - * Contains the L2CAP specific definitions and data structures used in the - * L2CAP APIs. - * - * - * \defgroup group_ble_service_api BLE Service-Specific API - * \ingroup group_ble - * \brief - * This section describes BLE Service-specific API. The Service - * API are only included in the design if the Service is - * added to the selected Profile in the component GUI. - * These are interfaces for the BLE application to use during BLE - * connectivity. The service-specific API internally use the BLE - * Stack API to achieve the Service use case. - * - * Refer to the Special Interest Group - * Web Site - * for links to the latest specifications and other documentation. - * - * Many of the API will generate Service-specific events. The events - * are also used in the Service-specific callback functions. These are - * documented in: - * - \ref group_ble_service_api_events - * - * - * \defgroup group_ble_service_api_events BLE Service-Specific Events - * \ingroup group_ble_service_api - * \brief - * The BLE stack generates service-specific events to notify the application - * that a service-specific status change needs attention. - * - * - * - * \defgroup group_ble_service_api_ANCS Apple Notification Center Service (ANCS) - * \ingroup group_ble_service_api - * \brief - * The Apple Notification Center Service provides iOS notifications from Apple devices for accessories. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The ANCS API names begin with Cy_BLE_ANCS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_ANCS_server_client ANCS Server and Client Function - * \ingroup group_ble_service_api_ANCS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_ANCS_ - * - * \defgroup group_ble_service_api_ANCS_server ANCS Server Functions - * \ingroup group_ble_service_api_ANCS - * \brief - * API unique to ANCS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_ANCSS_ - * - * \defgroup group_ble_service_api_ANCS_client ANCS Client Functions - * \ingroup group_ble_service_api_ANCS - * \brief - * API unique to ANCS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_ANCSC_ - * - * \defgroup group_ble_service_api_ANCS_definitions ANCS Definitions and Data Structures - * \ingroup group_ble_service_api_ANCS - * \brief - * Contains the ANCS specific definitions and data structures used - * in the ANCS API. - * - * - * - * \defgroup group_ble_service_api_ANS Alert Notification Service (ANS) - * \ingroup group_ble_service_api - * \brief - * The Alert Notification Service exposes alert information in a device. - * - * This information includes: - * - Type of alert occurring in a device - * - Additional text information such as the caller's ID or sender's ID - * - Count of new alerts - * - Count of unread alert items - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The ANS API names begin with Cy_BLE_ANS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_ANS_server_client ANS Server and Client Function - * \ingroup group_ble_service_api_ANS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_ANS_ - * - * \defgroup group_ble_service_api_ANS_server ANS Server Functions - * \ingroup group_ble_service_api_ANS - * \brief - * API unique to ANS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_ANSS_ - * - * \defgroup group_ble_service_api_ANS_client ANS Client Functions - * \ingroup group_ble_service_api_ANS - * \brief - * API unique to ANS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_ANSC_ - * - * \defgroup group_ble_service_api_ANS_definitions ANS Definitions and Data Structures - * \ingroup group_ble_service_api_ANS - * \brief - * Contains the ANS specific definitions and data structures used - * in the ANS API. - * - * - * - * \defgroup group_ble_service_api_AIOS Automation IO Service (AIOS) - * \ingroup group_ble_service_api - * \brief - * The Automation IO Service enables a device to connect and interact with an Automation IO Module (IOM) in order to access digital and analog signals. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The AIOS API names begin with Cy_BLE_AIOS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_AIOS_server_client AIOS Server and Client Function - * \ingroup group_ble_service_api_AIOS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_AIOS_ - * - * \defgroup group_ble_service_api_AIOS_server AIOS Server Functions - * \ingroup group_ble_service_api_AIOS - * \brief - * API unique to AIOS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_AIOSS_ - * - * \defgroup group_ble_service_api_AIOS_client AIOS Client Functions - * \ingroup group_ble_service_api_AIOS - * \brief - * API unique to AIOS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_AIOSC_ - * - * \defgroup group_ble_service_api_AIOS_definitions AIOS Definitions and Data Structures - * \ingroup group_ble_service_api_AIOS - * \brief - * Contains the AIOS specific definitions and data structures used - * in the AIOS API. - * - * - * \defgroup group_ble_service_api_BAS Battery Service (BAS) - * \ingroup group_ble_service_api - * \brief - * The Battery Service exposes the battery level of a single battery - * or set of batteries in a device. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The BAS API names begin with Cy_BLE_BAS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_BAS_server_client BAS Server and Client Function - * \ingroup group_ble_service_api_BAS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_BAS_ - * - * \defgroup group_ble_service_api_BAS_server BAS Server Functions - * \ingroup group_ble_service_api_BAS - * \brief - * API unique to BAS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_BASS_ - * - * \defgroup group_ble_service_api_BAS_client BAS Client Functions - * \ingroup group_ble_service_api_BAS - * \brief - * API unique to BAS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_BASC_ - * - * \defgroup group_ble_service_api_BAS_definitions BAS Definitions and Data Structures - * \ingroup group_ble_service_api_BAS - * \brief - * Contains the BAS specific definitions and data structures used - * in the BAS API. - * - * - * - * \defgroup group_ble_service_api_BCS Body Composition Service (BCS) - * \ingroup group_ble_service_api - * \brief - * The Body Composition Service exposes data related to body composition from a body composition analyzer (Server) - * intended for consumer healthcare as well as sports/fitness applications. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The BCS API names begin with Cy_BLE_BCS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_BCS_server_client BCS Server and Client Function - * \ingroup group_ble_service_api_BCS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_BCS_ - * - * \defgroup group_ble_service_api_BCS_server BCS Server Functions - * \ingroup group_ble_service_api_BCS - * \brief - * API unique to BCS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_BCSS_ - * - * \defgroup group_ble_service_api_BCS_client BCS Client Functions - * \ingroup group_ble_service_api_BCS - * \brief - * API unique to BCS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_BCSC_ - * - * \defgroup group_ble_service_api_BCS_definitions BCS Definitions and Data Structures - * \ingroup group_ble_service_api_BCS - * \brief - * Contains the BCS specific definitions and data structures used in the BCS API. - * - * - * - * \defgroup group_ble_service_api_BLS Blood Pressure Service (BLS) - * \ingroup group_ble_service_api - * \brief - * The Blood Pressure Service exposes blood pressure and other data related - * to a non-invasive blood pressure monitor for consumer and professional - * healthcare applications. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The BLS API names begin with Cy_BLE_BLS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_BLS_server_client BLS Server and Client Function - * \ingroup group_ble_service_api_BLS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_BLS_ - * - * \defgroup group_ble_service_api_BLS_server BLS Server Functions - * \ingroup group_ble_service_api_BLS - * \brief - * API unique to BLS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_BLSS_ - * - * \defgroup group_ble_service_api_BLS_client BLS Client Functions - * \ingroup group_ble_service_api_BLS - * \brief - * API unique to BLS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_BLSC_ - * - * \defgroup group_ble_service_api_BLS_definitions BLS Definitions and Data Structures - * \ingroup group_ble_service_api_BLS - * \brief - * Contains the BLS specific definitions and data structures - * used in the BLS API. - * - * - * - * \defgroup group_ble_service_api_BMS Bond Management Service (BMS) - * \ingroup group_ble_service_api - * \brief - * The Bond Management Service defines how a peer Bluetooth device can manage the storage of bond information, especially - * the deletion of it, on the Bluetooth device supporting this service. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The BMS API names begin with Cy_BLE_BMS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_BMS_server_client BMS Server and Client Function - * \ingroup group_ble_service_api_BMS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_BMS_ - * - * \defgroup group_ble_service_api_BMS_server BMS Server Functions - * \ingroup group_ble_service_api_BMS - * \brief - * API unique to BMS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_BMSS_ - * - * \defgroup group_ble_service_api_BMS_client BMS Client Functions - * \ingroup group_ble_service_api_BMS - * \brief - * API unique to BMS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_BMSC_ - * - * \defgroup group_ble_service_api_BMS_definitions BMS Definitions and Data Structures - * \ingroup group_ble_service_api_BMS - * \brief - * Contains the BMS specific definitions and data structures used in the BMS API. - * - * - * - * \defgroup group_ble_service_api_CGMS Continuous Glucose Monitoring Service (CGMS) - * \ingroup group_ble_service_api - * \brief - * The Continuous Glucose Monitoring Service exposes glucose measurement and other data related to a personal CGM sensor - * for healthcare applications. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The CGMS API names begin with Cy_BLE_CGMS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_CGMS_server_client CGMS Server and Client Function - * \ingroup group_ble_service_api_CGMS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_CGMS_ - * - * \defgroup group_ble_service_api_CGMS_server CGMS Server Functions - * \ingroup group_ble_service_api_CGMS - * \brief - * API unique to CGMS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_CGMSS_ - * - * \defgroup group_ble_service_api_CGMS_client CGMS Client Functions - * \ingroup group_ble_service_api_CGMS - * \brief - * API unique to CGMS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_CGMSC_ - * - * \defgroup group_ble_service_api_CGMS_definitions CGMS Definitions and Data Structures - * \ingroup group_ble_service_api_CGMS - * \brief - * Contains the CGMS specific definitions and data structures used in the CGMS API. - * - * - * - * \defgroup group_ble_service_api_CPS Cycling Power Service (CPS) - * \ingroup group_ble_service_api - * \brief - * The Cycling Power Service (CPS) exposes power- and force-related - * data and optionally speed- and cadence-related data from a Cycling - * Power sensor (GATT Server) intended for sports and fitness applications. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The CPS API names begin with Cy_BLE_CPS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * - * \defgroup group_ble_service_api_CPS_server_client CPS Server and Client Function - * \ingroup group_ble_service_api_CPS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_CPS_ - * - * \defgroup group_ble_service_api_CPS_server CPS Server Functions - * \ingroup group_ble_service_api_CPS - * \brief - * API unique to CPS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_CPSS_ - * - * \defgroup group_ble_service_api_CPS_client CPS Client Functions - * \ingroup group_ble_service_api_CPS - * \brief - * API unique to CPS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_CPSC_ - * - * \defgroup group_ble_service_api_CPS_definitions CPS Definitions and Data Structures - * \ingroup group_ble_service_api_CPS - * \brief - * Contains the CPS specific definitions and data structures - * used in the CPS API. - * - * - * \defgroup group_ble_service_api_CSCS Cycling Speed and Cadence Service (CSCS) - * \ingroup group_ble_service_api - * \brief - * The Cycling Speed and Cadence (CSC) Service exposes speed-related - * data and/or cadence-related data while using the Cycling Speed - * and Cadence sensor (Server). - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The CSCS API names begin with Cy_BLE_CSCS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * - * \defgroup group_ble_service_api_CSCS_server_client CSCS Server and Client Function - * \ingroup group_ble_service_api_CSCS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_CSCS_ - * - * \defgroup group_ble_service_api_CSCS_server CSCS Server Functions - * \ingroup group_ble_service_api_CSCS - * \brief - * API unique to CSCS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_CSCSS_ - * - * \defgroup group_ble_service_api_CSCS_client CSCS Client Functions - * \ingroup group_ble_service_api_CSCS - * \brief - * API unique to CSCS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_CSCSC_ - * - * \defgroup group_ble_service_api_CSCS_definitions CSCS Definitions and Data Structures - * \ingroup group_ble_service_api_CSCS - * \brief - * Contains the CSCS specific definitions and data structures - * used in the CSCS API. - * - * - * \defgroup group_ble_service_api_CTS Current Time Service (CTS) - * \ingroup group_ble_service_api - * \brief - * The Current Time Service defines how a Bluetooth device can expose time information - * to other Bluetooth devices. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The CTS API names begin with Cy_BLE_CTS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_CTS_server_client CTS Server and Client Function - * \ingroup group_ble_service_api_CTS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_CTS_ - * - * \defgroup group_ble_service_api_CTS_server CTS Server Functions - * \ingroup group_ble_service_api_CTS - * \brief - * API unique to CTS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_CTSS_ - * - * \defgroup group_ble_service_api_CTS_client CTS Client Functions - * \ingroup group_ble_service_api_CTS - * \brief - * API unique to CTS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_CTSC_ - * - * \defgroup group_ble_service_api_CTS_definitions CTS Definitions and Data Structures - * \ingroup group_ble_service_api_CTS - * \brief - * Contains the CTS specific definitions and data structures - * used in the CTS API. - * - * - * \defgroup group_ble_service_api_DIS Device Information Service (DIS) - * \ingroup group_ble_service_api - * \brief - * The Device Information Service exposes manufacturer and/or - * vendor information about a device. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The DIS API names begin with Cy_BLE_DIS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_DIS_server_client DIS Server and Client Function - * \ingroup group_ble_service_api_DIS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_DIS_ - * - * \defgroup group_ble_service_api_DIS_server DIS Server Functions - * \ingroup group_ble_service_api_DIS - * \brief - * API unique to DIS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_DISS_ - * - * \defgroup group_ble_service_api_DIS_client DIS Client Functions - * \ingroup group_ble_service_api_DIS - * \brief - * API unique to DIS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_DISC_ - * - * \defgroup group_ble_service_api_DIS_definitions DIS Definitions and Data Structures - * \ingroup group_ble_service_api_DIS - * \brief - * Contains the DIS specific definitions and data structures - * used in the DIS API. - * - * - * - * \defgroup group_ble_service_api_ESS Environmental Sensing Service (ESS) - * \ingroup group_ble_service_api - * \brief - * The Environmental Sensing Service exposes measurement data from an environmental sensor intended for sports and fitness - * applications. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The ESS API names begin with Cy_BLE_ESS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_ESS_server_client ESS Server and Client Function - * \ingroup group_ble_service_api_ESS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_ESS_ - * - * \defgroup group_ble_service_api_ESS_server ESS Server Functions - * \ingroup group_ble_service_api_ESS - * \brief - * API unique to ESS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_ESSS_ - * - * \defgroup group_ble_service_api_ESS_client ESS Client Functions - * \ingroup group_ble_service_api_ESS - * \brief - * API unique to ESS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_ESSC_ - * - * \defgroup group_ble_service_api_ESS_definitions ESS Definitions and Data Structures - * \ingroup group_ble_service_api_ESS - * \brief - * Contains the ESS specific definitions and data structures used in the ESS API. - * - * - * - * \defgroup group_ble_service_api_GLS Glucose Service (GLS) - * \ingroup group_ble_service_api - * \brief - * The Glucose Service exposes glucose and other data related to - * a personal glucose sensor for consumer healthcare applications - * and is not designed for clinical use. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The GLS API names begin with Cy_BLE_GLS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_GLS_server_client GLS Server and Client Function - * \ingroup group_ble_service_api_GLS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_GLS_ - * - * \defgroup group_ble_service_api_GLS_server GLS Server Functions - * \ingroup group_ble_service_api_GLS - * \brief - * API unique to GLS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_GLSS_ - * - * \defgroup group_ble_service_api_GLS_client GLS Client Functions - * \ingroup group_ble_service_api_GLS - * \brief - * API unique to GLS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_GLSC_ - * - * \defgroup group_ble_service_api_GLS_definitions GLS Definitions and Data Structures - * \ingroup group_ble_service_api_GLS - * \brief - * Contains the GLS specific definitions and data structures - * used in the GLS API. - * - * - * - * \defgroup group_ble_service_api_HIDS HID Service (HIDS) - * \ingroup group_ble_service_api - * \brief - * The HID Service exposes data and associated formatting for - * HID Devices and HID Hosts. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The HID API names begin with Cy_BLE_HID. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_HIDS_server_client HIDS Server and Client Functions - * \ingroup group_ble_service_api_HIDS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_HIDS_ - * - * \defgroup group_ble_service_api_HIDS_server HIDS Server Functions - * \ingroup group_ble_service_api_HIDS - * \brief - * API unique to HID designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_HIDSS_ - * - * \defgroup group_ble_service_api_HIDS_client HIDS Client Functions - * \ingroup group_ble_service_api_HIDS - * \brief - * API unique to HID designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_HIDSC_ - * - * \defgroup group_ble_service_api_HIDS_definitions HIDS Definitions and Data Structures - * \ingroup group_ble_service_api_HIDS - * \brief - * Contains the HID specific definitions and data structures - * used in the HID API. - * - * - * - * \defgroup group_ble_service_api_HRS Heart Rate Service (HRS) - * \ingroup group_ble_service_api - * \brief - * The Heart Rate Service exposes heart rate and other data - * related to a heart rate sensor intended for fitness applications. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The HRS API names begin with Cy_BLE_HRS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_HRS_server_client HRS Server and Client Function - * \ingroup group_ble_service_api_HRS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_HRS_ - * - * \defgroup group_ble_service_api_HRS_server HRS Server Functions - * \ingroup group_ble_service_api_HRS - * \brief - * API unique to HRS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_HRSS_ - * - * \defgroup group_ble_service_api_HRS_client HRS Client Functions - * \ingroup group_ble_service_api_HRS - * \brief - * API unique to HRS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_HRSC_ - * - * \defgroup group_ble_service_api_HRS_definitions HRS Definitions and Data Structures - * \ingroup group_ble_service_api_HRS - * \brief - * Contains the HRS specific definitions and data structures - * used in the HRS API. - * - * - * - * \defgroup group_ble_service_api_HPS HTTP Proxy Service (HPS) - * \ingroup group_ble_service_api - * \brief - * The HTTP Proxy Service allows a Client device, typically a sensor, - * to communicate with a Web Server through a gateway device. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The HPS API names begin with Cy_BLE_HPS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_HPS_server_client HPS Server and Client Function - * \ingroup group_ble_service_api_HPS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_HPS_ - * - * \defgroup group_ble_service_api_HPS_server HPS Server Functions - * \ingroup group_ble_service_api_HPS - * \brief - * API unique to HPS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_HPSS_ - * - * \defgroup group_ble_service_api_HPS_client HPS Client Functions - * \ingroup group_ble_service_api_HPS - * \brief - * API unique to HPS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_HPSC_ - * - * \defgroup group_ble_service_api_HPS_definitions HPS Definitions and Data Structures - * \ingroup group_ble_service_api_HPS - * \brief - * Contains the HPS specific definitions and data structures - * used in the HPS API. - * - * - * - * \defgroup group_ble_service_api_HTS Health Thermometer Service (HTS) - * \ingroup group_ble_service_api - * \brief - * The Health Thermometer Service exposes temperature and other - * data related to a thermometer used for healthcare applications. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The HTS API names begin with Cy_BLE_HTS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_HTS_server_client HTS Server and Client Function - * \ingroup group_ble_service_api_HTS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_HTS_ - * - * \defgroup group_ble_service_api_HTS_server HTS Server Functions - * \ingroup group_ble_service_api_HTS - * \brief - * API unique to HTS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_HTSS_ - * - * \defgroup group_ble_service_api_HTS_client HTS Client Functions - * \ingroup group_ble_service_api_HTS - * \brief - * API unique to HTS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_HTSC_ - * - * \defgroup group_ble_service_api_HTS_definitions HTS Definitions and Data Structures - * \ingroup group_ble_service_api_HTS - * \brief - * Contains the HTS specific definitions and data structures - * used in the HTS API. - * - * - * - * \defgroup group_ble_service_api_IAS Immediate Alert Service (IAS) - * \ingroup group_ble_service_api - * \brief - * The Immediate Alert Service exposes a control point to allow a peer device to cause the device to immediately alert. - * - * The Immediate Alert Service uses the Alert Level Characteristic - * to cause an alert when it is written with a value other than "No Alert". - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The IAS API names begin with Cy_BLE_IAS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_IAS_server_client IAS Server and Client Function - * \ingroup group_ble_service_api_IAS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_IAS_ - * - * \defgroup group_ble_service_api_IAS_server IAS Server Functions - * \ingroup group_ble_service_api_IAS - * \brief - * API unique to IAS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_IASS_ - * - * \defgroup group_ble_service_api_IAS_client IAS Client Functions - * \ingroup group_ble_service_api_IAS - * \brief - * API unique to IAS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_IASC_ - * - * \defgroup group_ble_service_api_IAS_definitions IAS Definitions and Data Structures - * \ingroup group_ble_service_api_IAS - * \brief - * Contains the IAS specific definitions and data structures - * used in the IAS API. - * - * - * - * \defgroup group_ble_service_api_IPS Indoor Positioning Service (IPS) - * \ingroup group_ble_service_api - * \brief - * The Indoor Positioning exposes coordinates and other location related information via - * an advertisement or indicates that the device address can be used for location look-up, - * enabling mobile devices to find their position. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The IPS API names begin with Cy_BLE_IPS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_IPS_server_client IPS Server and Client Function - * \ingroup group_ble_service_api_IPS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_IPS_ - * - * \defgroup group_ble_service_api_IPS_server IPS Server Functions - * \ingroup group_ble_service_api_IPS - * \brief - * API unique to IPS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_IPSS_ - * - * \defgroup group_ble_service_api_IPS_client IPS Client Functions - * \ingroup group_ble_service_api_IPS - * \brief - * API unique to IPS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_IPSC_ - * - * \defgroup group_ble_service_api_IPS_definitions IPS Definitions and Data Structures - * \ingroup group_ble_service_api_IPS - * \brief - * Contains the IPS specific definitions and data structures - * used in the IPS API. - * - * - * - * \defgroup group_ble_service_api_LLS Link Loss Service (LLS) - * \ingroup group_ble_service_api - * \brief - * The Link Loss Service uses the Alert Level Characteristic to - * cause an alert in the device when the link is lost. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The LLS API names begin with Cy_BLE_LLS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_LLS_server_client LLS Server and Client Function - * \ingroup group_ble_service_api_LLS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_LLS_ - * - * \defgroup group_ble_service_api_LLS_server LLS Server Functions - * \ingroup group_ble_service_api_LLS - * \brief - * API unique to LLS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_LLSS_ - * - * \defgroup group_ble_service_api_LLS_client LLS Client Functions - * \ingroup group_ble_service_api_LLS - * \brief - * API unique to LLS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_LLSC_ - * - * \defgroup group_ble_service_api_LLS_definitions LLS Definitions and Data Structures - * \ingroup group_ble_service_api_LLS - * \brief - * Contains the LLS specific definitions and data structures - * used in the LLS API. - * - * - * - * \defgroup group_ble_service_api_LNS Location and Navigation Service (LNS) - * \ingroup group_ble_service_api - * \brief - * The Location and Navigation Service exposes location and - * navigation-related data from a Location and Navigation sensor - * (Server) intended for outdoor activity applications. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The LNS API names begin with Cy_BLE_LNS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_LNS_server_client LNS Server and Client Function - * \ingroup group_ble_service_api_LNS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_LNS_ - * - * \defgroup group_ble_service_api_LNS_server LNS Server Functions - * \ingroup group_ble_service_api_LNS - * \brief - * API unique to LNS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_LNSS_ - * - * \defgroup group_ble_service_api_LNS_client LNS Client Functions - * \ingroup group_ble_service_api_LNS - * \brief - * API unique to LNS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_LNSC_ - * - * \defgroup group_ble_service_api_LNS_definitions LNS Definitions and Data Structures - * \ingroup group_ble_service_api_LNS - * \brief - * Contains the LNS specific definitions and data structures - * used in the LNS API. - * - * - * - * \defgroup group_ble_service_api_NDCS Next DST Change Service (NDCS) - * \ingroup group_ble_service_api - * \brief - * The Next DST Change Service enables a BLE device that has knowledge about the - * next occurrence of a DST change to expose this information to - * another Bluetooth device. The Service uses the "Time with DST" - * Characteristic and the functions exposed in this Service are - * used to interact with that Characteristic. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The NDCS API names begin with Cy_BLE_NDCS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_NDCS_server_client NDCS Server and Client Functions - * \ingroup group_ble_service_api_NDCS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_NDCS_ - * - * \defgroup group_ble_service_api_NDCS_server NDCS Server Functions - * \ingroup group_ble_service_api_NDCS - * \brief - * API unique to NDCS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_NDCSS_ - * - * \defgroup group_ble_service_api_NDCS_client NDCS Client Functions - * \ingroup group_ble_service_api_NDCS - * \brief - * API unique to NDCS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_NDCSC_ - * - * \defgroup group_ble_service_api_NDCS_definitions NDCS Definitions and Data Structures - * \ingroup group_ble_service_api_NDCS - * \brief - * Contains the NDCS specific definitions and data structures - * used in the NDCS API. - * - * - * - * \defgroup group_ble_service_api_PASS Phone Alert Status Service (PASS) - * \ingroup group_ble_service_api - * \brief - * The Phone Alert Status Service uses the Alert Status Characteristic - * and Ringer Setting Characteristic to expose the phone alert status - * and uses the Ringer Control Point Characteristic to control the - * phone's ringer into mute or enable. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The PASS API names begin with Cy_BLE_PASS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_PASS_server_client PASS Server and Client Function - * \ingroup group_ble_service_api_PASS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_PASS_ - * - * \defgroup group_ble_service_api_PASS_server PASS Server Functions - * \ingroup group_ble_service_api_PASS - * \brief - * API unique to PASS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_PASSS_ - * - * \defgroup group_ble_service_api_PASS_client PASS Client Functions - * \ingroup group_ble_service_api_PASS - * \brief - * API unique to PASS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_PASSC_ - * - * \defgroup group_ble_service_api_PASS_definitions PASS Definitions and Data Structures - * \ingroup group_ble_service_api_PASS - * \brief - * Contains the PASS specific definitions and data structures - * used in the PASS API. - * - * - * - * \defgroup group_ble_service_api_PLXS Pulse Oximeter Service (PLXS) - * \ingroup group_ble_service_api - * \brief - * The Pulse Oximeter Service enables a Collector device to connect and interact with a pulse oximeter intended for healthcare applications. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The PLXS API names begin with Cy_BLE_PLXS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_PLXS_server_client PLXS Server and Client Function - * \ingroup group_ble_service_api_PLXS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_PLXS_ - * - * \defgroup group_ble_service_api_PLXS_server PLXS Server Functions - * \ingroup group_ble_service_api_PLXS - * \brief - * API unique to PLXS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_PLXSS_ - * - * \defgroup group_ble_service_api_PLXS_client PLXS Client Functions - * \ingroup group_ble_service_api_PLXS - * \brief - * API unique to PLXS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_PLXSC_ - * - * \defgroup group_ble_service_api_PLXS_definitions PLXS Definitions and Data Structures - * \ingroup group_ble_service_api_PLXS - * \brief - * Contains the PLXS specific definitions and data structures used - * in the PLXS API. - * - * - * - * \defgroup group_ble_service_api_RSCS Running Speed and Cadence Service (RSCS) - * \ingroup group_ble_service_api - * \brief - * The Running Speed and Cadence (RSC) Service exposes speed, - * cadence and other data related to fitness applications such - * as the stride length and the total distance the user has - * travelled while using the Running Speed and Cadence sensor (Server). - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The RSCS API names begin with Cy_BLE_RSCS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_RSCS_server_client RSCS Server and Client Functions - * \ingroup group_ble_service_api_RSCS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_RSCS_ - * - * \defgroup group_ble_service_api_RSCS_server RSCS Server Functions - * \ingroup group_ble_service_api_RSCS - * \brief - * API unique to RSCS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_RSCSS_ - * - * \defgroup group_ble_service_api_RSCS_client RSCS Client Functions - * \ingroup group_ble_service_api_RSCS - * \brief - * API unique to RSCS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_RSCSC_ - * - * \defgroup group_ble_service_api_RSCS_definitions RSCS Definitions and Data Structures - * \ingroup group_ble_service_api_RSCS - * \brief - * Contains the RSCS specific definitions and data structures - * used in the RSCS API. - * - * - * - * \defgroup group_ble_service_api_RTUS Reference Time Update Service (RTUS) - * \ingroup group_ble_service_api - * \brief - * The Reference Time Update Service enables a Bluetooth device that can update the - * system time using the reference time such as a GPS receiver - * to expose a control point and expose the accuracy (drift) of - * the local system time compared to the reference time source. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The RTUS API names begin with Cy_BLE_RTUS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_RTUS_server_client RTUS Server and Client Function - * \ingroup group_ble_service_api_RTUS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_RTUS_ - * - * \defgroup group_ble_service_api_RTUS_server RTUS Server Functions - * \ingroup group_ble_service_api_RTUS - * \brief - * API unique to RTUS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_RTUSS_ - * - * \defgroup group_ble_service_api_RTUS_client RTUS Client Functions - * \ingroup group_ble_service_api_RTUS - * \brief - * API unique to RTUS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_RTUSC_ - * - * \defgroup group_ble_service_api_RTUS_definitions RTUS Definitions and Data Structures - * \ingroup group_ble_service_api_RTUS - * \brief - * Contains the RTUS specific definitions and data structures - * used in the RTUS API. - * - * - * - * \defgroup group_ble_service_api_SCPS Scan Parameters Service (ScPS) - * \ingroup group_ble_service_api - * \brief - * The Scan Parameters Service enables a Server device to expose - * a Characteristic for the GATT Client to write its scan interval - * and scan window on the Server device, and enables a Server to - * request a refresh of the GATT Client scan interval and scan window. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The ScPS API names begin with Cy_BLE_SCPS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_SCPS_server_client ScPS Server and Client Functions - * \ingroup group_ble_service_api_SCPS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_SCPS_ - * - * \defgroup group_ble_service_api_SCPS_server ScPS Server Functions - * \ingroup group_ble_service_api_SCPS - * \brief - * API unique to ScPS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_SCPSS_ - * - * \defgroup group_ble_service_api_SCPS_client ScPS Client Functions - * \ingroup group_ble_service_api_SCPS - * \brief - * API unique to ScPS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_SCPSC_ - * - * \defgroup group_ble_service_api_SCPS_definitions ScPS Definitions and Data Structures - * \ingroup group_ble_service_api_SCPS - * \brief - * Contains the ScPS specific definitions and data structures - * used in the ScPS API. - * - * - * - * \defgroup group_ble_service_api_TPS TX Power Service (TPS) - * \ingroup group_ble_service_api - * \brief - * The Tx Power Service uses the Tx Power Level Characteristic - * to expose the current transmit power level of a device when - * in a connection. - * - * Depending on the chosen GATT role in the GUI, you may - * use a subset of the supported API. - * - * The TPS API names begin with Cy_BLE_TPS_. In addition to this, the API - * also append the GATT role initial letter in the API name. - * - * \defgroup group_ble_service_api_TPS_server_client TPS Server and Client Function - * \ingroup group_ble_service_api_TPS - * \brief - * These are API common to both GATT Client role and GATT Server role. - * You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_TPS_ - * - * \defgroup group_ble_service_api_TPS_server TPS Server Functions - * \ingroup group_ble_service_api_TPS - * \brief - * API unique to TPS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_TPSS_ - * - * \defgroup group_ble_service_api_TPS_client TPS Client Functions - * \ingroup group_ble_service_api_TPS - * \brief - * API unique to TPS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_TPSC_ - * - * \defgroup group_ble_service_api_TPS_definitions TPS Definitions and Data Structures - * \ingroup group_ble_service_api_TPS - * \brief - * Contains the TPS specific definitions and data structures - * used in the TPS API. - * - * - * - * \defgroup group_ble_service_api_UDS User Data Service (UDS) - * \ingroup group_ble_service_api - * \brief - * The User Data Service exposes user-related data in the sports and fitness environment. This allows remote access and - * update of user data by a Client as well as the synchronization of user data between a Server and a Client. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The UDS API names begin with Cy_BLE_UDS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_UDS_server_client UDS Server and Client Function - * \ingroup group_ble_service_api_UDS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_UDS_ - * - * \defgroup group_ble_service_api_UDS_server UDS Server Functions - * \ingroup group_ble_service_api_UDS - * \brief - * API unique to UDS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_UDSS_ - * - * \defgroup group_ble_service_api_UDS_client UDS Client Functions - * \ingroup group_ble_service_api_UDS - * \brief - * API unique to UDS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_UDSC_ - * - * \defgroup group_ble_service_api_UDS_definitions UDS Definitions and Data Structures - * \ingroup group_ble_service_api_UDS - * \brief - * Contains the UDS specific definitions and data structures used in the UDS API. - * - * - * - * - * \defgroup group_ble_service_api_WPTS Wireless Power Transfer Service (WPTS) - * \ingroup group_ble_service_api - * \brief - * The Wireless Power Transfer Service enables communication between Power Receiver Unit and Power Transmitter Unit - * in the Wireless Power Transfer systems. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The WPTS API names begin with Cy_BLE_WPTS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_WPTS_server_client WPTS Server and Client Function - * \ingroup group_ble_service_api_WPTS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_WPTS_ - * - * \defgroup group_ble_service_api_WPTS_server WPTS Server Functions - * \ingroup group_ble_service_api_WPTS - * \brief - * API unique to WPTS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_WPTSS_ - * - * \defgroup group_ble_service_api_WPTS_client WPTS Client Functions - * \ingroup group_ble_service_api_WPTS - * \brief - * API unique to WPTS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_WPTSC_ - * - * \defgroup group_ble_service_api_WPTS_definitions WPTS Definitions and Data Structures - * \ingroup group_ble_service_api_WPTS - * \brief - * Contains the WPTS specific definitions and data structures used in the WPTS API. - * - * - * - * \defgroup group_ble_service_api_WSS Weight Scale Service (WSS) - * \ingroup group_ble_service_api - * \brief - * The Weight Scale Service exposes weight and related data from a weight scale (Server) intended for consumer healthcare - * as well as sports/fitness applications. - * - * Depending on the chosen GATT role in the GUI, you may use a subset of the supported API. - * - * The WSS API names begin with Cy_BLE_WSS_. In addition to this, the API also append the GATT role initial letter in the - * API name. - * - * \defgroup group_ble_service_api_WSS_server_client WSS Server and Client Function - * \ingroup group_ble_service_api_WSS - * \brief - * These are API common to both GATT Client role and GATT Server role. You may use them in either roles. - * - * No letter is appended to the API name: Cy_BLE_WSS_ - * - * \defgroup group_ble_service_api_WSS_server WSS Server Functions - * \ingroup group_ble_service_api_WSS - * \brief - * API unique to WSS designs configured as a GATT Server role. - * - * A letter 's' is appended to the API name: Cy_BLE_WSSS_ - * - * \defgroup group_ble_service_api_WSS_client WSS Client Functions - * \ingroup group_ble_service_api_WSS - * \brief - * API unique to WSS designs configured as a GATT Client role. - * - * A letter 'c' is appended to the API name: Cy_BLE_WSSC_ - * - * \defgroup group_ble_service_api_WSS_definitions WSS Definitions and Data Structures - * \ingroup group_ble_service_api_WSS - * \brief - * Contains the WSS specific definitions and data structures used in the WSS API. - * - * - * \defgroup group_ble_service_api_custom Custom Service - * \ingroup group_ble_service_api - * \brief - * This section contains the the data structures used for Custom Services. - * - * - * - * \defgroup group_ble_clock_api_section BLE Clock API - * \ingroup group_ble - * \brief - * This section describes the BLE ECO clock. - * - * - * \defgroup group_ble_clock_api Functions - * \ingroup group_ble_clock_api_section - * - * \defgroup group_ble_clock_api_data_types Definitions and Data Structures - * \ingroup group_ble_clock_api_section - * - */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ess.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ess.c deleted file mode 100644 index 32c66cdf8b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ess.c +++ /dev/null @@ -1,2991 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ess.c -* \version 2.0 -* -* \brief -* Contains the source code for the Environmental Sensing Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_ESS)) - -#ifdef CY_BLE_ESS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_esssReqHandle; -#endif /* CY_BLE_ESS_SERVER */ - -#ifdef CY_BLE_ESS_CLIENT -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_esscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Read Long Descriptors variables */ -static uint8_t * cy_ble_esscRdLongBuffPtr[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; -static uint32_t cy_ble_esscRdLongBuffLen[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -static uint8_t cy_ble_esscCurrLen[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; - -uint8_t activeCharIndex[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -uint8_t activeCharInstance[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -uint8_t prevCharInstIndex[CY_BLE_CONFIG_GATTC_COUNT]; - -#endif /* (CY_BLE_ESS_CLIENT) */ - -static cy_ble_callback_t Cy_BLE_ESS_ApplCallback = NULL; - -/* The pointer on global BLE ESS Config structure */ -cy_stc_ble_ess_config_t *cy_ble_essConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_ESS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_ESSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_ESSS_PrepareWriteRequestEventHandler(const cy_stc_ble_gatts_prep_write_req_param_t *eventParam); -static void Cy_BLE_ESSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam); -static void Cy_BLE_ESSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -#endif /* CY_BLE_ESS_SERVER */ - -#ifdef CY_BLE_ESS_CLIENT -static void Cy_BLE_ESSC_DiscoverCharacteristicsEventHandler(const cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_ESSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_ESSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_ESSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_ESSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_ESSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_ESSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_ESSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_ESSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam); -static void Cy_BLE_ESSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_ESS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_ESS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_ESS_Init -***************************************************************************//** -* -* This function initializes the Environmental Sensing Service. -* -* \param config: Configuration structure for the Environmental Sensing Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESS_Init(cy_stc_ble_ess_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure*/ - cy_ble_essConfigPtr = config; - - /* Registers Event Handler for the ESS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_ESS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_essConfigPtr->callbackFunc != NULL) - { - Cy_BLE_ESS_ApplCallback = cy_ble_essConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_ESS_SERVER - cy_ble_esssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_ESS_SERVER */ - - #ifdef CY_BLE_ESS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - uint32_t i; - uint32_t j; - - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_ESS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - for(i = (uint32_t)CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED; (i < ((uint32_t)CY_BLE_ESS_CHAR_COUNT)); i++) - { - for(j = 0u; j < cy_ble_essConfigPtr->esscCharInstances[i]; j++) - { - (void)memset(&cy_ble_essConfigPtr->essc[idx].charInfoAddr[i].charInfoPtr[j], 0, - sizeof(cy_stc_ble_essc_char_t)); - } - } - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_ESS].uuid = CY_BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE; - } - cy_ble_esscRdLongBuffPtr[idx] = NULL; - cy_ble_esscRdLongBuffLen[idx] = 0u; - cy_ble_esscCurrLen[idx] = 0u; - activeCharIndex[idx] = 0u; - activeCharInstance[idx] = 0u; - prevCharInstIndex[idx] = 0u; - cy_ble_esscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_ESS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for ESS Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode: Indicates the event that triggered this callback -* (e.g. CY_BLE_EVT_ESSS_NOTIFICATION_ENABLED). -* * eventParam: Contains the parameters corresponding to the -* current event. (e.g. Pointer to cy_stc_ble_ess_char_value_t -* structure that contains details of the characteristic -* for which the notification enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_ESS_ApplCallback = callbackFunc; - if(cy_ble_essConfigPtr != NULL) - { - cy_ble_essConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_ESS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_ESS_Get24ByPtr -***************************************************************************//** -* -* Returns a three-bytes value by using a pointer to the LSB. The value is -* returned as uint32_t. -* -* \param ptr: The pointer to the LSB of three-byte data (little-endian). -* -* \return -* uint32_t value: Three-byte data. -* -******************************************************************************/ -uint32_t Cy_BLE_ESS_Get24ByPtr(const uint8_t ptr[]) -{ - return(((uint32_t)ptr[0u]) | ((uint32_t)(((uint32_t)ptr[1u]) << 8u)) | ((uint32_t)((uint32_t)ptr[2u]) << 16u)); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESS_Get32ByPtr -***************************************************************************//** -* -* Returns a four-byte value by using a pointer to the LSB. -* -* \param ptr: The pointer to the LSB of four-byte data (little-endian). -* -* \return -* uint32_t value: Four-byte data. -* -******************************************************************************/ -uint32_t Cy_BLE_ESS_Get32ByPtr(const uint8_t ptr[]) -{ - return(((uint32_t)ptr[0u]) | ((uint32_t)(((uint32_t)ptr[1u]) << 8u)) | ((uint32_t)((uint32_t)ptr[2u]) << 16u) | - ((uint32_t)((uint32_t)ptr[3u]) << 24u)); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_CheckIfInRange -***************************************************************************//** -* -* Checks if the "value" is in the range of "min" and "max". As the ESS -* characteristics operate with signed or unsigned value types and the value in -* the GATT database are stored in unsigned variables. Need to clearly identify -* the signedness of each "value", "min" and "max". After that the values can -* be properly compared. The signedness of each parameter is encoded in "state" -* and has the following meaning: -* State 0: All three are positive (all three are of unsigned type) -* State 1: Min - positive, Max - positive, Value - negative -* State 2: Min - positive, Max - negative, Value - positive -* State 3: Min - positive, Max - negative, Value - negative -* State 4: Min - negative, Max - positive, Value - positive -* State 5: Min - negative, Max - positive, Value - negative -* State 6: Min - negative, Max - negative, Value - positive -* State 7: All three are negative -* -* min - Minimum inclusive limit. -* max - Minimum inclusive limit. -* value - The value to be checked if it is in the range. -* state - The state as shown above. -* -* \return -* A return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - "value" is in the range. -* * CY_BLE_GATT_ERR_OUT_OF_RANGE - "value" is not in the range. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_ESSS_CheckIfInRange(uint32_t min, - uint32_t max, - uint32_t value, - uint8_t state) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - switch(state) - { - /* All values are positive */ - case CY_BLE_ESS_STATE_0: - if((min > value) || (max < value)) - { - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - } - break; - - /* "Not in range" cases. Min and Max are negative and value is positive or - * vice versa. - */ - case CY_BLE_ESS_STATE_1: - case CY_BLE_ESS_STATE_6: - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - break; - - /* Min is negative, Max and value are positive */ - case CY_BLE_ESS_STATE_4: - if(max < value) - { - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - } - break; - - /* Max is positive, Min and value are negative */ - case CY_BLE_ESS_STATE_5: - if(min > value) - { - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - } - break; - - /* All values are negative */ - case CY_BLE_ESS_STATE_7: - if((min > value) || (max < value)) - { - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - } - break; - - /* Invalid cases. Handled by customizer. */ - case CY_BLE_ESS_STATE_2: - case CY_BLE_ESS_STATE_3: - default: - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - break; - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESS_HandleRangeCheck -***************************************************************************//** -* -* Performs an extraction of the characteristic value ranges then compares it to -* the value received from the client and returns a result of the comparison. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param length: The length of a buffer to store the main and may ranges. Can be 2,4,6 -* or 8 bytes. -* \param type: Identifies the type of the value pointed by "pValue" (0 - the value -* is of unsigned type, 1 - the value is of signed type). -* \param pValue: The pointer to the value to be validated if it is in the range. -* -* -* \return -* A return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - The value stored in "pValue" is in ranges specified -* by Valid Range Descriptor of the characteristic -* addressed by "charIndex" and "charInstance". -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Failed to read Valid Range Descriptor -* value. -* * CY_BLE_GATT_ERR_OUT_OF_RANGE - The value stored in "pValue" is not in the -* valid ranges. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_ESS_HandleRangeCheck(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - uint16_t length, - uint8_t type, - const uint8_t pValue[]) -{ - uint8_t locState = 0u; - uint8_t skipSignCheck = 0u; - uint8_t tmpBuff[8u]; - uint32_t maxLimit = 0u; - uint32_t minLimit = 0u; - uint32_t operand = 0u; - uint32_t u32Sign = 0u; - cy_en_ble_gatt_err_code_t apiResult = CY_BLE_GATT_ERR_UNLIKELY_ERROR; - - if(Cy_BLE_ESSS_GetCharacteristicDescriptor(connHandle, charIndex, charInstance, CY_BLE_ESS_VRD, length, tmpBuff) == - CY_BLE_SUCCESS) - { - switch(length) - { - case CY_BLE_ESS_2BYTES_LENGTH: - operand = (uint32_t)(pValue[0u]); - minLimit = (uint32_t)(tmpBuff[0u]); - maxLimit = (uint32_t)(tmpBuff[1u]); - u32Sign = CY_BLE_ESS_U8_SIGN_BIT; - break; - - case CY_BLE_ESS_4BYTES_LENGTH: - operand = (uint32_t)Cy_BLE_ESS_Get16ByPtr(&pValue[0u]); - minLimit = (uint32_t)Cy_BLE_ESS_Get16ByPtr(&tmpBuff[0u]); - maxLimit = (uint32_t)Cy_BLE_ESS_Get16ByPtr(&tmpBuff[2u]); - u32Sign = CY_BLE_ESS_U16_SIGN_BIT; - break; - - case CY_BLE_ESS_6BYTES_LENGTH: - operand = (uint32_t)Cy_BLE_ESS_Get24ByPtr(&pValue[0u]); - minLimit = (uint32_t)Cy_BLE_ESS_Get24ByPtr(&tmpBuff[0u]); - maxLimit = (uint32_t)Cy_BLE_ESS_Get24ByPtr(&tmpBuff[3u]); - u32Sign = CY_BLE_ESS_U24_SIGN_BIT; - break; - - case CY_BLE_ESS_8BYTES_LENGTH: - operand = (uint32_t)Cy_BLE_ESS_Get32ByPtr(&pValue[0u]); - minLimit = (uint32_t)Cy_BLE_ESS_Get32ByPtr(&tmpBuff[0u]); - maxLimit = (uint32_t)Cy_BLE_ESS_Get32ByPtr(&tmpBuff[4u]); - break; - - default: - skipSignCheck = 1u; - break; - } - - if(skipSignCheck == 0u) - { - if(type != CY_BLE_ESS_UNSIGNED_TYPE) - { - locState = CY_BLE_ESS_IS_NEGATIVE(minLimit, u32Sign) << 1u; - locState = (locState | CY_BLE_ESS_IS_NEGATIVE(maxLimit, u32Sign)) << 1u; - locState |= CY_BLE_ESS_IS_NEGATIVE(operand, u32Sign); - } - else - { - locState = 0u; - } - } - - /* Compare the operand to the limits with respect to the state - * and return the results. - */ - apiResult = Cy_BLE_ESSS_CheckIfInRange(minLimit, maxLimit, operand, locState); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_WriteEventHandler -***************************************************************************//** -* -* Handles a Write Request event for Environmental Sensing Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -* \return -* A return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write is successful. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - Request is not supported. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - Write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - the offset value is invalid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred. -* * CY_BLE_GATT_ERR_CONDITION_NOT_SUPPORTED - The condition in ES Trigger Settings -* Descriptor is not supported. -* * CY_BLE_GATT_ERR_WRITE_REQ_REJECTED - A write request was rejected. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_ESSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - uint32_t event = (uint32_t)CY_BLE_EVT_ESSS_DESCR_WRITE; - uint32_t foundItem = 0u; - uint8_t i; - uint8_t j; - cy_stc_ble_esss_char_t *essCharInfoPtr; - cy_stc_ble_ess_descr_value_t wrDescrReqParam = { .connHandle = eventParam->connHandle }; - cy_ble_gatt_db_attr_handle_t tmpHandle; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - tmpHandle = eventParam->handleValPair.attrHandle; - - if(Cy_BLE_ESS_ApplCallback != NULL) - { - wrDescrReqParam.descrIndex = CY_BLE_ESS_DESCR_COUNT; - - /* Go through all possible Service characteristics. - * Exit the handler in following conditions: - * 1) No more characteristic left; - * 2) Characteristic or descriptor was successfully written; - * 3) Error occurred while writing characteristic or descriptor. - */ - for(i = 0u; ((i < (uint8_t)CY_BLE_ESS_CHAR_COUNT) && (foundItem == 0u) && (gattErr == CY_BLE_GATT_ERR_NONE)); i++) - { - /* Check if characteristic is enabled. If the pointer to the characteristic - * is not "NULL", there is at least one instance of the characteristic in - * the ES Service. - */ - if(cy_ble_essConfigPtr->esss->charInfoAddr[i].charInfoPtr != NULL) - { - for(j = 0u; j < cy_ble_essConfigPtr->esssCharInstances[i]; j++) - { - essCharInfoPtr = &cy_ble_essConfigPtr->esss->charInfoAddr[i].charInfoPtr[j]; - - /* Client Characteristic Configuration Descriptor Write Request handling */ - if(tmpHandle == essCharInfoPtr->descrHandle[CY_BLE_ESS_CCCD]) - { - /* Verify that optional notification property is enabled for characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(essCharInfoPtr->charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_ESSS_NOTIFICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_ESSS_NOTIFICATION_DISABLED; - } - - /* Value is NULL for descriptors */ - wrDescrReqParam.value = NULL; - wrDescrReqParam.descrIndex = CY_BLE_ESS_CCCD; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else if(CY_BLE_IS_INDICATION_SUPPORTED(essCharInfoPtr->charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_ESSS_INDICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_ESSS_INDICATION_DISABLED; - } - - /* Value is NULL for descriptors */ - wrDescrReqParam.value = NULL; - wrDescrReqParam.descrIndex = CY_BLE_ESS_CCCD; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = (cy_en_ble_gatt_err_code_t)CY_BLE_GATT_ERR_WRITE_REQ_REJECTED; - } - } - else if(tmpHandle == essCharInfoPtr->descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1]) - { - wrDescrReqParam.descrIndex = CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - } - else if(tmpHandle == essCharInfoPtr->descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2]) - { - wrDescrReqParam.descrIndex = CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - } - else if(tmpHandle == essCharInfoPtr->descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3]) - { - wrDescrReqParam.descrIndex = CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - } - else if(tmpHandle == essCharInfoPtr->descrHandle[CY_BLE_ESS_ES_CONFIG_DESCR]) - { - wrDescrReqParam.descrIndex = CY_BLE_ESS_ES_CONFIG_DESCR; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - } - else if(tmpHandle == essCharInfoPtr->descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) - { - wrDescrReqParam.descrIndex = CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR; - foundItem = CY_BLE_ESS_DESCRIPTOR_ITEM; - } - else - { - /* No handle match was found */ - } - - /* Verify if requested handle was found and successfully handled */ - if((gattErr == CY_BLE_GATT_ERR_NONE) && (0u != foundItem)) - { - switch(wrDescrReqParam.descrIndex) - { - case CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1: - case CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2: - case CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3: - if(eventParam->handleValPair.value.val[0u] > CY_BLE_ESS_TRIG_WHILE_EQUAL_NOT_TO) - { - /* Trigger condition is not supported */ - gattErr = (cy_en_ble_gatt_err_code_t)CY_BLE_GATT_ERR_CONDITION_NOT_SUPPORTED; - } - /* If Valid Range Descriptor for the characteristic is present, then - * check the characteristic value range. The ranges should be properly - * set in the server or otherwise the server will constantly return an - * "Out of range" error. - */ - else if((CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - essCharInfoPtr->descrHandle[CY_BLE_ESS_VRD]) && - (eventParam->handleValPair.value.len > 1u) && - (eventParam->handleValPair.value.val[0u] >= CY_BLE_ESS_TRIG_WHILE_LESS_THAN)) - { - /* The following "switch" groups characteristics are based on their value - * type. - */ - switch((cy_en_ble_ess_char_index_t)i) - { - /* uint8_t */ - case CY_BLE_ESS_BAROMETRIC_PRESSURE_TREND: - case CY_BLE_ESS_GUST_FACTOR: - case CY_BLE_ESS_UV_INDEX: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_2BYTES_LENGTH, - CY_BLE_ESS_UNSIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - /* uint16_t */ - case CY_BLE_ESS_APPARENT_WIND_DIR: - case CY_BLE_ESS_APPARENT_WIND_SPEED: - case CY_BLE_ESS_HUMIDITY: - case CY_BLE_ESS_IRRADIANCE: - case CY_BLE_ESS_MAGNETIC_DECLINATION: - case CY_BLE_ESS_RAINFALL: - case CY_BLE_ESS_TRUE_WIND_DIR: - case CY_BLE_ESS_TRUE_WIND_SPEED: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_4BYTES_LENGTH, - CY_BLE_ESS_UNSIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - /* uint24 */ - case CY_BLE_ESS_POLLEN_CONCENTRATION: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_6BYTES_LENGTH, - CY_BLE_ESS_UNSIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - /* uint32_t */ - case CY_BLE_ESS_PRESSURE: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_8BYTES_LENGTH, - CY_BLE_ESS_UNSIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - /* int8_t */ - case CY_BLE_ESS_DEW_POINT: - case CY_BLE_ESS_HEAT_INDEX: - case CY_BLE_ESS_WIND_CHILL: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_2BYTES_LENGTH, - CY_BLE_ESS_SIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - /* int16_t */ - case CY_BLE_ESS_TEMPERATURE: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_4BYTES_LENGTH, - CY_BLE_ESS_SIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - /* int24 */ - case CY_BLE_ESS_ELEVATION: - gattErr = Cy_BLE_ESS_HandleRangeCheck(eventParam->connHandle, - (cy_en_ble_ess_char_index_t)i, j, - CY_BLE_ESS_6BYTES_LENGTH, - CY_BLE_ESS_SIGNED_TYPE, - &eventParam->handleValPair.value.val[1u]); - break; - - case CY_BLE_ESS_MAGNETIC_FLUX_DENSITY_2D: - /* No validation required */ - break; - - case CY_BLE_ESS_MAGNETIC_FLUX_DENSITY_3D: - /* No validation required */ - break; - - default: - /* Invalid characteristic */ - gattErr = CY_BLE_GATT_ERR_UNLIKELY_ERROR; - break; - } - } - else /* No error */ - { - if(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN( - essCharInfoPtr->descrHandle[wrDescrReqParam.descrIndex]) >= - eventParam->handleValPair.value.len) - { - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN( - essCharInfoPtr->descrHandle[wrDescrReqParam.descrIndex], - eventParam->handleValPair.value.len); - } - else - { - gattErr = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - } - break; - - case CY_BLE_ESS_ES_CONFIG_DESCR: - if(eventParam->handleValPair.value.val[0u] > CY_BLE_ESS_CONF_BOOLEAN_OR) - { - /* Trigger Logic value is not supported */ - gattErr = (cy_en_ble_gatt_err_code_t)CY_BLE_GATT_ERR_WRITE_REQ_REJECTED; - } - break; - - case CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR: - /* The ESS spec. states are the following: "The Server may also choose to reject - * a write request to the Characteristic User Description if it determines that - * the contents of the new value are unsuitable, such as a string containing - * characters in a language that the implementation does not support." - * This validation is omitted in the current version of the service. - */ - - if(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN( - essCharInfoPtr->descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) >= - eventParam->handleValPair.value.len) - { - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN( - essCharInfoPtr->descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR], - eventParam->handleValPair.value.len); - } - else - { - gattErr = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - break; - - default: - break; - } - - /* Check is there no error conditions happen yet */ - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - gattErr = Cy_BLE_GATT_DbCheckPermission(eventParam->handleValPair.attrHandle, - &eventParam->connHandle, CY_BLE_GATT_DB_WRITE | - CY_BLE_GATT_DB_PEER_INITIATED); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - /* Fill data and pass it to user */ - wrDescrReqParam.charIndex = (cy_en_ble_ess_char_index_t)i; - wrDescrReqParam.charInstance = j; - wrDescrReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - - if(wrDescrReqParam.descrIndex != CY_BLE_ESS_CCCD) - { - /* Check if descriptor index is not CCCD index as "event" and - * "wrDescrReqParam.value" parameters for CCCD were handled - * above. - */ - wrDescrReqParam.value = &eventParam->handleValPair.value; - } - Cy_BLE_ESS_ApplCallback(event, &wrDescrReqParam); - - if(wrDescrReqParam.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - /* Write value to GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - } - } - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - } - - if(CY_BLE_GATT_ERR_NONE != gattErr) - { - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_PrepareWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to the data that received with a prepare write -* request event for the Environmental Sensing Service. -* -******************************************************************************/ -static void Cy_BLE_ESSS_PrepareWriteRequestEventHandler(const cy_stc_ble_gatts_prep_write_req_param_t *eventParam) -{ - uint32_t i; - uint32_t j; - uint8_t exitLoop = 0u; - cy_stc_ble_esss_char_t *essCharInfoPtr; - - if(Cy_BLE_ESS_ApplCallback != NULL) - { - for(i = 0u; ((i < ((uint8_t)CY_BLE_ESS_CHAR_COUNT)) && (exitLoop == 0u)); i++) - { - /* Check if characteristic is enabled. If the pointer to the characteristic - * is not "NULL", there is at least one instance of the characteristic in - * the ES Service. - */ - if(cy_ble_essConfigPtr->esss->charInfoAddr[i].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_essConfigPtr->esssCharInstances[i]) && (exitLoop == 0u)); j++) - { - essCharInfoPtr = &cy_ble_essConfigPtr->esss->charInfoAddr[i].charInfoPtr[j]; - - /* Need to check following conditions: 1) if requested handle is the handle of - * Characteristic User Description Descriptor; 2) and if there is no active - * requests; 3) or there is an active request but the requested handle is - * different handle. the thord condition means that previous request resulted - * with an error so need to hanle that. - */ - if(eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - essCharInfoPtr->descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) - { - if(cy_ble_esssReqHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send Prepare Write Response which identifies acknowledgment for - * long characteristic value write. - */ - cy_ble_esssReqHandle = - eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle; - } - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - /* Set the flag to exit the loop */ - exitLoop = 1u; - } - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_ExecuteWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Execute Write Request Event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to the data that came with a write request for the -* Environmental Sensing Service. -* -******************************************************************************/ -static void Cy_BLE_ESSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam) -{ - uint8_t i; - uint8_t j; - uint8_t locCount; - uint8_t exitLoop = 0u; - uint16_t locLength = 0u; - cy_stc_ble_gatt_value_t locDescrValue; - cy_stc_ble_ess_descr_value_t wrDescrReqParam = { .connHandle = eventParam->connHandle }; - - if(Cy_BLE_ESS_ApplCallback != NULL) - { - for(i = 0u; ((i < ((uint8_t)CY_BLE_ESS_CHAR_COUNT)) && (exitLoop == 0u)); i++) - { - /* Check if characteristic is enabled. If the pointer to the characteristic - * is not "NULL", there is at least one instance of the characteristic in - * the ES Service. - */ - if(cy_ble_essConfigPtr->esss->charInfoAddr[i].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_essConfigPtr->esssCharInstances[i]) && (exitLoop == 0u)); j++) - { - if((eventParam->baseAddr[0u].handleValuePair.attrHandle == - cy_ble_essConfigPtr->esss->charInfoAddr[i].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) && - (cy_ble_esssReqHandle == eventParam->baseAddr[0u].handleValuePair.attrHandle)) - { - /* Check the execWriteFlag before execute or cancel write long operation */ - if(eventParam->execWriteFlag == CY_BLE_GATT_EXECUTE_WRITE_EXEC_FLAG) - { - for(locCount = 0u; locCount < eventParam->prepWriteReqCount; locCount++) - { - locLength += eventParam->baseAddr[locCount].handleValuePair.value.len; - } - - if(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_esssReqHandle) >= locLength) - { - locDescrValue = eventParam->baseAddr[0u].handleValuePair.value; - /* Fill data and pass it to user */ - wrDescrReqParam.charIndex = (cy_en_ble_ess_char_index_t)i; - wrDescrReqParam.charInstance = j; - wrDescrReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - wrDescrReqParam.value = &locDescrValue; - wrDescrReqParam.value->len = locLength; - wrDescrReqParam.descrIndex = CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR; - - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSS_DESCR_WRITE, &wrDescrReqParam); - - if(wrDescrReqParam.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_esssReqHandle, locLength); - } - } - else - { - wrDescrReqParam.gattErrorCode = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - - /* Pass user error code to Stack */ - eventParam->gattErrorCode = (uint8_t)wrDescrReqParam.gattErrorCode; - } - - /* Set the flag to exit the loop */ - exitLoop = 1u; - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - /* Clear requested handle */ - cy_ble_esssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* eventParam - The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_ESSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_ESS_ApplCallback != NULL) && (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_esssReqHandle)) - { - /* Only Descriptor Value Change Characteristic has Indication property. - * Check if the requested handle is the handle of Descriptor Value Change - * handle. - */ - if(cy_ble_esssReqHandle == - cy_ble_essConfigPtr->esss->charInfoAddr[CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED].charInfoPtr[0u].charHandle) - { - /* Fill in event data and inform Application about - * successfully confirmed indication. - */ - cy_stc_ble_ess_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED, - .value = NULL - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_esssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSS_INDICATION_CONFIRMATION, &locCharValue); - } - } -} - - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_SetChangeIndex -***************************************************************************//** -* -* Performs write operation of two-byte pseudo-random change index to the -* advertisement packet. The "Service Data" field should be selected in the -* component customizer GUI and contain a two-byte initial change index value -* and in opposite case the function will always return -* "CY_BLE_ERROR_INVALID_OPERATION". -* -* This function must be called when Cy_BLE_GetBleSsState() returns -* CY_BLE_BLESS_STATE_EVENT_CLOSE state. -* -* \param essIndex: A two-byte pseudo-random change index to be written to the -* advertisement data. -* -* \param advertisingParamIndex: The index of the peripheral and broadcast -* configuration in customizer. For example: -* *CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX 0x00 -* *CY_BLE_BROADCASTER_CONFIGURATION_0_INDEX 0x01 -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - On NULL pointer, Data length in input -* parameter exceeds 31 bytes. -* * CY_BLE_ERROR_INVALID_OPERATION - The change index is not present in the -* advertisement data or its length is not equal to two bytes or ADV -* Event is not closed, BLESS is active or ADV is not enabled. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_SetChangeIndex(uint16_t essIndex, - uint8_t advertisingParamIndex) -{ - uint32_t fFlag = 0u; - uint8_t adLength = 0u; - uint32_t byteCounter = 0u; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_OPERATION; - - if(advertisingParamIndex >= CY_BLE_GAPP_CONF_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - while((byteCounter < cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advDataLen) && - (fFlag == 0u)) - { - adLength = cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter]; - - if(adLength != 0u) - { - uint16_t servUuid; - - /* Increment byte counter so that it points to AD type field */ - byteCounter++; - - servUuid = Cy_BLE_Get16ByPtr(&cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData-> - advData[byteCounter + 1u]); - - if((cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter] == - CY_BLE_AD_TYPE_SERVICE_DATA) && (servUuid == CY_BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE)) - { - /* Start of a "Service Data" AD type was found. Set flag and exit the loop. */ - fFlag = 1u; - } - else - { - byteCounter += adLength; - } - } - else - { - /* End of advertisement data structure was encountered so exit loop. */ - break; - } - } - - if(fFlag != 0u) - { - /* Check if length is proper */ - if(adLength == CY_BLE_ESS_SERVICE_DATA_LENGTH) - { - /* Increment byte counter so that it points to data value */ - byteCounter += CY_BLE_AD_SERVICE_DATA_OVERHEAD; - - Cy_BLE_Set16ByPtr(&cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex]. - advData->advData[byteCounter], essIndex); - - /* We are done. Indicate success. */ - apiResult = CY_BLE_SUCCESS; - - if((Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING) && - (cy_ble_advIndex == advertisingParamIndex)) - { - /* Update the advertisement packet if the device is in the advertising mode. */ - apiResult = Cy_BLE_GAPP_UpdateAdvScanData(&cy_ble_configPtr->discoveryModeInfo[cy_ble_advIndex]); - } - } - } - } - - return(apiResult); -} - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the characteristic value of the service in the local database. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size (in Bytes) of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_SetCharacteristicValue(cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - /* Validate range of ESS characteristics */ - if((charIndex < CY_BLE_ESS_CHAR_COUNT) && (charInstance < cy_ble_essConfigPtr->esssCharInstances[charIndex])) - { - /* Check if requested characteristic is present in Service. - * There are three conditions which should be checked: 1) The pointer to - * "cy_stc_ble_esss_char_t" is not NULL, 2) The handle of the characteristic is - * a valid handle, 3) The requested instance is a valid characteristic - * instance. - */ - if((cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the characteristic value of the service, which is a value identified by -* charIndex. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_GetCharacteristicValue(cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_ESS_CHAR_COUNT) && (charInstance < cy_ble_essConfigPtr->esssCharInstances[charIndex])) - { - /* Check if requested characteristic is present in Service. There are three - * conditions to be checked: 1) The pointer to "cy_stc_ble_esss_char_t" record in - * the cy_ble_esss struct is not NULL, 2) The handle of the characteristic is a - * valid handle, 3) The requested instance is a valid characteristic instance. - */ - if((cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, attrSize); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the service characteristic descriptor of type -* cy_en_ble_ess_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data to -* be stored in the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_ESS_CHAR_COUNT) && (charInstance < cy_ble_essConfigPtr->esssCharInstances[charIndex]) && - (descrIndex < CY_BLE_ESS_DESCR_COUNT)) - { - /* Check if requested descriptor is present in Service. - * There are three conditions to be checked: 1) The pointer to - * "cy_stc_ble_esss_char_t" is not NULL, 2) The handle of the characteristic is - * a valid handle, 3) The handle of the descriptor is a valid handle. - */ - if((cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex])) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - - /* Set new length of the descriptor value */ - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], attrSize); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the service characteristic descriptor of type -* cy_en_ble_ess_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_ESS_CHAR_COUNT) && (charInstance < cy_ble_essConfigPtr->esssCharInstances[charIndex]) && - (descrIndex < CY_BLE_ESS_DESCR_COUNT)) - { - /* Check if requested descriptor is present in Service. - * There are three conditions to be checked: 1) The pointer to - * "cy_stc_ble_esss_char_t" is not NULL, 2) The handle of the characteristic is - * a valid handle, 3) The handle of the descriptor is a valid handle. - */ - if((cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex])) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_SendNotification -***************************************************************************//** -* -* Sends a notification with a characteristic value of the Environmental Sensing -* Service, which is a value specified by charIndex, to the client's device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_ESSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - A notification is not enabled by the client. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_ESS_CHAR_COUNT) && (charInstance < cy_ble_essConfigPtr->esssCharInstances[charIndex])) - { - if((cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[CY_BLE_ESS_CCCD])) - { - /* Send notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[CY_BLE_ESS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle, - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSS_SendIndication -***************************************************************************//** -* -* Sends an indication with a characteristic value of the Environmental Sensing -* Service, which is a value specified by charIndex, to the client's device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_ESSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED) && - (charInstance < cy_ble_essConfigPtr->esssCharInstances[charIndex])) - { - /* Send indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, - cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[CY_BLE_ESS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_essConfigPtr->esss->charInfoAddr[charIndex].charInfoPtr[charInstance].charHandle) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_essConfigPtr->esss->charInfoAddr[charIndex]. - charInfoPtr[charInstance].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - /* Save handle to support service-specific value confirmation response from client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - return(apiResult); -} - - -#endif /* CY_BLE_ESS_SERVER */ - - -#ifdef CY_BLE_ESS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_ESSC_DiscoverCharacteristicsEventHandler(const cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* ESS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_esscCharUuid[CY_BLE_ESS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_DESCR_VALUE_CHANGED, - CY_BLE_UUID_CHAR_APPARENT_WIND_DIRECTION, - CY_BLE_UUID_CHAR_APPARENT_WIND_SPEED, - CY_BLE_UUID_CHAR_DEW_POINT, - CY_BLE_UUID_CHAR_ELEVATION, - CY_BLE_UUID_CHAR_GUST_FACTOR, - CY_BLE_UUID_CHAR_HEAT_INDEX, - CY_BLE_UUID_CHAR_HUMIDITY, - CY_BLE_UUID_CHAR_IRRADIANCE, - CY_BLE_UUID_CHAR_POLLEN_CONCENTRATION, - CY_BLE_UUID_CHAR_RAINFALL, - CY_BLE_UUID_CHAR_PRESSURE, - CY_BLE_UUID_CHAR_THEMPERATURE, - CY_BLE_UUID_CHAR_TRUE_WIND_DIRECTION, - CY_BLE_UUID_CHAR_TRUE_WIND_SPEED, - CY_BLE_UUID_CHAR_UV_INDEX, - CY_BLE_UUID_CHAR_WIND_CHILL, - CY_BLE_UUID_CHAR_BAR_PRESSURE_TREND, - CY_BLE_UUID_CHAR_MAGNETIC_DECLINATION, - CY_BLE_UUID_CHAR_MAGNETIC_FLUX_DENSITY_2D, - CY_BLE_UUID_CHAR_MAGNETIC_FLUX_DENSITY_3D - }; - - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - uint32_t j; - uint32_t exitLoop = 0u; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ESS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - /* Search through all available characteristics */ - for(i = (uint32_t)CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED; ((i < (uint32_t)CY_BLE_ESS_CHAR_COUNT) && - (exitLoop == 0u)); i++) - { - for(j = 0u; j < cy_ble_essConfigPtr->esscCharInstances[i]; j++) - { - if(cy_ble_esscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[i].charInfoPtr != NULL) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[i].charInfoPtr[j].valueHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[i].charInfoPtr[j].valueHandle = - discCharInfo->valueHandle; - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[i].charInfoPtr[j].properties = - discCharInfo->properties; - lastEndHandle[discIdx] = - &cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[i].charInfoPtr[j].endHandle; - exitLoop = 1u; - break; - } - } - } - } - } - - /* Initialize characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_ESSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - uint32_t charInst = activeCharInstance[discIdx]; - uint32_t descIdx; - - - if((cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ESS) && - (cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr != NULL)) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_ESS_CCCD; - break; - - case CY_BLE_UUID_CHAR_VALID_RANGE: - descIdx = (uint32_t)CY_BLE_ESS_VRD; - break; - - case CY_BLE_UUID_CHAR_USER_DESCRIPTION: - descIdx = (uint32_t)CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR; - break; - - case CY_BLE_UUID_CHAR_ES_CONFIGURATION: - descIdx = (uint32_t)CY_BLE_ESS_ES_CONFIG_DESCR; - break; - - case CY_BLE_UUID_CHAR_EXTENDED_PROPERTIES: - descIdx = (uint32_t)CY_BLE_ESS_CHAR_EXTENDED_PROPERTIES; - break; - - case CY_BLE_UUID_CHAR_ES_MEASUREMENT: - descIdx = (uint32_t)CY_BLE_ESS_ES_MEASUREMENT_DESCR; - break; - - case CY_BLE_UUID_CHAR_ES_TRIGGER_SETTING: - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst]. - descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - descIdx = (uint32_t)CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1; - } - else if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst]. - descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - descIdx = (uint32_t)CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2; - } - else - { - descIdx = (uint32_t)CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3; - } - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else /* Duplication of descriptor */ - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_ESSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_ESS) - { - if(charRangeInfo->srviIncIdx == CY_BLE_DISCOVERY_INIT) - { - /* CY_BLE_DISCOVERY_INIT */ - activeCharInstance[discIdx] = 0u; - } - else - { - /* CY_BLE_DISCOVERY_CONTINUE */ - activeCharInstance[discIdx]++; - if(activeCharInstance[discIdx] == cy_ble_essConfigPtr->esscCharInstances[cy_ble_discovery[discIdx].charCount]) - { - cy_ble_discovery[discIdx].charCount++; - activeCharInstance[discIdx] = 0u; - } - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_ESS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - - while((activeCharInstance[discIdx] < cy_ble_essConfigPtr->esscCharInstances[charIdx]) && (exitFlag == 0u)) - { - uint32_t charInst = activeCharInstance[discIdx]; - if((cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].valueHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) && - ((cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].endHandle - - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].valueHandle) != 0u)) - { - charRangeInfo->range.startHandle = - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].valueHandle + 1u; - charRangeInfo->range.endHandle = - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIdx].charInfoPtr[charInst].endHandle; - exitFlag = 1u; - } - else - { - activeCharInstance[discIdx]++; - } - } - if(exitFlag == 0u) - { - cy_ble_discovery[discIdx].charCount++; - activeCharInstance[discIdx] = 0u; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_NotificationEventHandler -***************************************************************************//** -* -* Handles a notification event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t j; - uint32_t exitLoop = 0u; - cy_en_ble_ess_char_index_t locCharIndex; - - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ESS_ApplCallback != NULL)) - { - for(locCharIndex = (cy_en_ble_ess_char_index_t)0u; (locCharIndex < CY_BLE_ESS_CHAR_COUNT) && - (exitLoop == 0u); locCharIndex++) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; j < cy_ble_essConfigPtr->esscCharInstances[locCharIndex]; j++) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_ess_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - exitLoop = 1u; - break; - } - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an indication event for Environmental Sensing Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ESS_ApplCallback != NULL)) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED]. - charInfoPtr[0u].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_ess_char_value_t indicationValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED, - .value = &eventParam->handleValPair.value, - }; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_ReadLongRespEventHandler -***************************************************************************//** -* -* Handles a Read Long Response event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t j; - uint32_t i; - uint32_t isReqEnded = 0u; - cy_en_ble_ess_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ESS_ApplCallback != NULL)) - { - /* Go trough all characteristics */ - for(locCharIndex = CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED; locCharIndex < CY_BLE_ESS_CHAR_COUNT; locCharIndex++) - { - /* Check if specific characteristic exist */ - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - /* Go trough all characteristic instances */ - for(j = 0u; j < cy_ble_essConfigPtr->esscCharInstances[locCharIndex]; j++) - { - /* Read Long Request is only supported for Characteristic User - * Description descriptor. Check if requested handle equals - * the descriptor. - */ - if((cy_ble_esscReqHandle[discIdx] == cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex]. - charInfoPtr[j].descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) && - (cy_ble_esscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = eventParam->connHandle }; - - /* Update user buffer with received data */ - for(i = 0u; (i < eventParam->value.len) && (cy_ble_esscCurrLen[discIdx] < - cy_ble_esscRdLongBuffLen[discIdx]); i++) - { - cy_ble_esscRdLongBuffPtr[discIdx][cy_ble_esscCurrLen[discIdx]] = eventParam->value.val[i]; - cy_ble_esscCurrLen[discIdx]++; - } - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* If the received data length is less than the MTU size, the Read Long - * request is completed or the provided user's buffer is full. - */ - if(((mtuParam.mtu - 1u) > eventParam->value.len)) - { - cy_ble_esscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - else if(cy_ble_esscCurrLen[discIdx] == cy_ble_esscRdLongBuffLen[discIdx]) - { - cy_stc_ble_gattc_stop_cmd_param_t stopCmdParam = { .connHandle = eventParam->connHandle }; - (void)Cy_BLE_GATTC_StopCmd(&stopCmdParam); - } - else - { - isReqEnded = 1u; - } - - /* If the buffer is full, then stop any remaining read long requests */ - if(isReqEnded == 0u) - { - cy_stc_ble_gatt_value_t rdValue = - { - .val = cy_ble_esscRdLongBuffPtr[discIdx], - .len = cy_ble_esscCurrLen[discIdx] - }; - cy_stc_ble_ess_descr_value_t rdDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .charInstance = j, - .descrIndex = CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR - }; - rdDescrValue.value = &rdValue; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_READ_DESCR_RESPONSE, &rdDescrValue); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t j; - uint32_t locReqHandle = 0u; - cy_en_ble_ess_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ESS_ApplCallback != NULL) && - (cy_ble_esscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED; (locCharIndex < CY_BLE_ESS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_essConfigPtr->esscCharInstances[locCharIndex]) && (locReqHandle == 0u)); j++) - { - if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle) - { - cy_stc_ble_ess_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .charInstance = j, - .value = &eventParam->value - }; - cy_ble_esscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_ess_descr_index_t locDescIndex; - - for(locDescIndex = CY_BLE_ESS_CCCD; (locDescIndex < CY_BLE_ESS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[locDescIndex]) - { - cy_stc_ble_ess_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .charInstance = j, - .value = &eventParam->value - }; - cy_ble_esscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint8_t j; - uint32_t locReqHandle = 0u; - cy_en_ble_ess_char_index_t locCharIndex; - cy_stc_ble_ess_descr_value_t locDescrValue = { .connHandle = *eventParam }; - - /* Check if service handler was registered and request handle is - * valid. - */ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ESS_ApplCallback != NULL) && - (cy_ble_esscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED; (locCharIndex < CY_BLE_ESS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - /* If this condition is false, this means that the current characteristic - * is not included in the GUI, in other words support for the characteristic is - * not enabled. - */ - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_essConfigPtr->esscCharInstances[locCharIndex]) && (locReqHandle == 0u)); j++) - { - /* Check if requested descriptor handle is in - * characteristic range. - */ - if((cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].valueHandle < - cy_ble_esscReqHandle[discIdx]) && - (cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j].endHandle >= - cy_ble_esscReqHandle[discIdx])) - { - if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_CCCD]) - { - locDescrValue.descrIndex = CY_BLE_ESS_CCCD; - } - else - if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1]) - { - locDescrValue.descrIndex = CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1; - } - else - if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2]) - { - locDescrValue.descrIndex = CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2; - } - else if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3]) - { - locDescrValue.descrIndex = CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3; - } - else if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_ES_CONFIG_DESCR]) - { - locDescrValue.descrIndex = CY_BLE_ESS_ES_CONFIG_DESCR; - } - else if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) - { - locDescrValue.descrIndex = CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR; - } - else - { - /* Should never enter here */ - } - - locDescrValue.charIndex = locCharIndex; - locDescrValue.charInstance = j; - locDescrValue.value = NULL; - cy_ble_esscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_ExecuteWriteResponseEventHandler -***************************************************************************//** -* -* Handles a Execute Write Response event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam) -{ - uint8_t j; - uint32_t locReqHandle = 0u; - cy_en_ble_ess_char_index_t locCharIndex; - cy_stc_ble_ess_descr_value_t locDescrValue = { .connHandle = eventParam->connHandle }; - - /* Check if service handler was registered and request handle is - * valid. - */ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_ESS_ApplCallback != NULL) && (cy_ble_esscReqHandle[discIdx] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED; (locCharIndex < CY_BLE_ESS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - /* If this condition is false, this means that the current characteristic - * is not included in the GUI, in other words the - * characteristic support is not enabled. - */ - if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr != NULL) - { - for(j = 0u; ((j < cy_ble_essConfigPtr->esscCharInstances[locCharIndex]) && (locReqHandle == 0u)); j++) - { - if(cy_ble_esscReqHandle[discIdx] == - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[locCharIndex].charInfoPtr[j]. - descrHandle[CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR]) - { - locDescrValue.connHandle = eventParam->connHandle; - locDescrValue.charIndex = locCharIndex; - locDescrValue.charInstance = j; - locDescrValue.value = NULL; - locDescrValue.descrIndex = CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR; - cy_ble_esscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_ESS_ApplCallback((uint32_t)CY_BLE_EVT_ESSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event for the Environmental Sensing Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_ESSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(cy_ble_esscReqHandle[discIdx] == eventParam->errInfo.attrHandle) - { - cy_ble_esscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_ESSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ess_char_value_t. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ESS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charInstance >= cy_ble_essConfigPtr->esscCharInstances[charIndex]) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle) - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ess_char_value_t. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ESS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charInstance >= cy_ble_essConfigPtr->esscCharInstances[charIndex]) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle, - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esscReqHandle[discIdx] = - cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_ESSS_DESCR_WRITE events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_ESSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_ESSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_ESSS_INDICATION_ENABLED -* * CY_BLE_EVT_ESSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional Characteristic Descriptor -* is absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ess_descr_value_t. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ESS_CHAR_COUNT) || (descrIndex >= CY_BLE_ESS_DESCR_COUNT) || - (charInstance >= cy_ble_essConfigPtr->esscCharInstances[charIndex]) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if((descrIndex == CY_BLE_ESS_VRD) || (descrIndex == CY_BLE_ESS_ES_MEASUREMENT_DESCR)) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional Characteristic Descriptor -* is absent. -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_ess_descr_value_t. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ESS_CHAR_COUNT) || (descrIndex >= CY_BLE_ESS_DESCR_COUNT) || - (charInstance >= cy_ble_essConfigPtr->esscCharInstances[charIndex]) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[descrIndex], - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esscReqHandle[discIdx] = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_SetLongCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write a long characteristic descriptor to the server, -* which is identified by charIndex and descrIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic Descriptor -* is absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ess_descr_value_t. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSC_SetLongCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ESS_CHAR_COUNT) || (descrIndex >= CY_BLE_ESS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(descrIndex == CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_prep_write_req_t writeReqParam = - { - .handleValOffsetPair.handleValuePair.attrHandle = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex]. - charInfoPtr[charInstance].descrHandle[descrIndex], - .handleValOffsetPair.handleValuePair.value.val = attrValue, - .handleValOffsetPair.handleValuePair.value.len = attrSize, - .handleValOffsetPair.offset = 0u, - .connHandle = connHandle - }; - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteLongCharacteristicValues(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esscReqHandle[discIdx] = writeReqParam.handleValOffsetPair.handleValuePair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ESSC_GetLongCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to read long characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param charInstance: The instance number of the characteristic specified by -* "charIndex". -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the buffer where the read long characteristic -* descriptor value should be stored. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The optional Characteristic Descriptor -* is absent. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the ESS service-specific callback is registered -* (with Cy_BLE_ESS_RegisterAttrCallback): -* * CY_BLE_EVT_ESSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_ess_descr_value_t. -* . -* Otherwise (if the ESS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ESSC_GetLongCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_ESS_CHAR_COUNT) || (descrIndex >= CY_BLE_ESS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_blob_req_t readLongdata = - { - .handleOffset.offset = 0u, - .handleOffset.attrHandle = cy_ble_essConfigPtr->essc[discIdx].charInfoAddr[charIndex].charInfoPtr[charInstance]. - descrHandle[descrIndex], - .connHandle = connHandle, - }; - cy_ble_esscRdLongBuffLen[discIdx] = (uint32_t)attrSize; - cy_ble_esscRdLongBuffPtr[discIdx] = attrValue; - - apiResult = Cy_BLE_GATTC_ReadLongCharacteristicDescriptors(&readLongdata); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_esscReqHandle[discIdx] = readLongdata.handleOffset.attrHandle; - } - } - - return(apiResult); -} - -#endif /* CY_BLE_ESS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_ESS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Environmental Sensing Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_ESS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_ESS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_ESSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_ESSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_ESSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_ESS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_ESS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_ESSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_ESSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - Cy_BLE_ESSS_PrepareWriteRequestEventHandler((cy_stc_ble_gatts_prep_write_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - Cy_BLE_ESSS_ExecuteWriteRequestEventHandler((cy_stc_ble_gatts_exec_write_req_t*)eventParam); - break; - #endif /* CY_BLE_ESS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_ESS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_ESSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_ESSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_ESSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_ESSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_ESSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_BLOB_RSP: - Cy_BLE_ESSC_ReadLongRespEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_EXEC_WRITE_RSP: - Cy_BLE_ESSC_ExecuteWriteResponseEventHandler((cy_stc_ble_gattc_exec_write_rsp_t*)eventParam); - break; - #endif /* CY_BLE_ESS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_ESS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ess.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ess.h deleted file mode 100644 index 9799da5dbe..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ess.h +++ /dev/null @@ -1,439 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ess.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Environmental Sensing -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_ESS_H -#define CY_BLE_ESS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_ESS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ -#ifdef CY_BLE_ESS_CLIENT - #define CY_BLE_ES_TOTAL_CHAR_COUNT (CY_BLE_CONFIG_ES_TOTAL_CHAR_COUNT) -#endif /* CY_BLE_ESS_CLIENT */ - -#define CY_BLE_ESS_3BYTES_LENGTH (0x03u) - - -/** - * \addtogroup group_ble_service_api_ESS_definitions - * @{ - */ - - - -/*************************************** -* Data Types -***************************************/ - -/** ESS Characteristic indexes */ -typedef enum -{ - CY_BLE_ESS_DESCRIPTOR_VALUE_CHANGED, /**< Descriptor Value Changed Characteristic index */ - CY_BLE_ESS_APPARENT_WIND_DIR, /**< Apparent Wind Direction Characteristic index */ - CY_BLE_ESS_APPARENT_WIND_SPEED, /**< Apparent Wind Speed Characteristic index */ - CY_BLE_ESS_DEW_POINT, /**< Dew Point Characteristic index */ - CY_BLE_ESS_ELEVATION, /**< Elevation Characteristic index */ - CY_BLE_ESS_GUST_FACTOR, /**< Gust Factor Characteristic index */ - CY_BLE_ESS_HEAT_INDEX, /**< Heat Index Characteristic index */ - CY_BLE_ESS_HUMIDITY, /**< Humidity Characteristic index */ - CY_BLE_ESS_IRRADIANCE, /**< Irradiance Characteristic index */ - CY_BLE_ESS_POLLEN_CONCENTRATION, /**< Pollen Concentration Characteristic index */ - CY_BLE_ESS_RAINFALL, /**< Rainfall Characteristic index */ - CY_BLE_ESS_PRESSURE, /**< Pressure Characteristic index */ - CY_BLE_ESS_TEMPERATURE, /**< Temperature Characteristic index */ - CY_BLE_ESS_TRUE_WIND_DIR, /**< True Wind Direction Characteristic index */ - CY_BLE_ESS_TRUE_WIND_SPEED, /**< True Wind Speed Characteristic index */ - CY_BLE_ESS_UV_INDEX, /**< UV Index Characteristic index */ - CY_BLE_ESS_WIND_CHILL, /**< Wind Chill Characteristic index */ - CY_BLE_ESS_BAROMETRIC_PRESSURE_TREND, /**< Barometric Pressure trend Characteristic index */ - CY_BLE_ESS_MAGNETIC_DECLINATION, /**< Magnetic Declination Characteristic index */ - CY_BLE_ESS_MAGNETIC_FLUX_DENSITY_2D, /**< Magnetic Flux Density 2D Characteristic index */ - CY_BLE_ESS_MAGNETIC_FLUX_DENSITY_3D, /**< Magnetic Flux Density 3D Characteristic index */ - CY_BLE_ESS_CHAR_COUNT /**< Total count of ESS characteristics */ -}cy_en_ble_ess_char_index_t; - -/** ESS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_ESS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_ESS_CHAR_EXTENDED_PROPERTIES, /**< Characteristic Extended Properties Descriptor index */ - CY_BLE_ESS_ES_MEASUREMENT_DESCR, /**< ES Measurement Descriptor index */ - CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR1, /**< ES Trigger Settings Descriptor #1 index */ - CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR2, /**< ES Trigger Settings Descriptor #2 index */ - CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR3, /**< ES Trigger Settings Descriptor #3 index */ - CY_BLE_ESS_ES_CONFIG_DESCR, /**< ES Configuration Descriptor index */ - CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR, /**< Characteristic User Description Descriptor index */ - CY_BLE_ESS_VRD, /**< Valid Range Descriptor index */ - CY_BLE_ESS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_ess_descr_index_t; - -/** ESS Characteristic with descriptors */ -typedef struct -{ - /** Handles of Characteristic value */ - cy_ble_gatt_db_attr_handle_t charHandle; - - /** Array of Descriptor handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_ESS_DESCR_COUNT]; -} cy_stc_ble_esss_char_t; - -/** Structure to hold pointer to cy_stc_ble_esss_char_t */ -typedef struct -{ - /** Pointer to cy_stc_ble_esss_char_t that holds information about specific - * ES Characteristic - */ - cy_stc_ble_esss_char_t *charInfoPtr; -} cy_stc_ble_esss_char_info_ptr_t; - -/** Structure with Environmental Sensing Service attribute handles */ -typedef struct -{ - /** Environmental Sensing Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Environmental Sensing Service Array with pointers to - * Characteristic handles. - */ - cy_stc_ble_esss_char_info_ptr_t charInfoAddr[CY_BLE_ESS_CHAR_COUNT]; -} cy_stc_ble_esss_t; - -/** ESS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_ESS_DESCR_COUNT]; /**< Array of Descriptor handles */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_essc_char_t; - -/** Structure to hold pointer to cy_stc_ble_essc_char_t */ -typedef struct -{ - /** Pointer to cy_stc_ble_essc_char_t that holds information about specific - * ES Characteristic. - */ - cy_stc_ble_essc_char_t *charInfoPtr; -} cy_stc_ble_essc_char_info_ptr_t; - -/** Structure with discovered attributes information of Environmental Sensing - * Service. - */ -typedef struct -{ - /** Environmental Sensing Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Environmental Sensing Service Array with pointers to - * characteristic information. - */ - cy_stc_ble_essc_char_info_ptr_t charInfoAddr[CY_BLE_ESS_CHAR_COUNT]; -} cy_stc_ble_essc_t; - -/** ESS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ess_char_index_t charIndex; /**< Index of service characteristic */ - uint8_t charInstance; /**< Instance of specific service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_ess_char_value_t; - -/** ESS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ess_char_index_t charIndex; /**< Index of service characteristic */ - uint8_t charInstance; /**< Instance of specific service characteristic */ - cy_en_ble_ess_descr_index_t descrIndex; /**< Index of descriptor */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< Error code received from application (optional) */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_ess_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Environmental Sensing Service GATT DB handles structure for server */ - const cy_stc_ble_esss_t *esss; - - /** Number of ESS characteristics instances for server */ - uint8_t *esssCharInstances; - - /** Environmental Sensing Service GATT DB handles structure for client */ - cy_stc_ble_essc_t *essc; - - /** Number of ESS characteristics instances for client */ - const uint8_t *esscCharInstances; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_ess_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ -/* ESS specific GATT errors */ -#define CY_BLE_GATT_ERR_WRITE_REQ_REJECTED (0x80u) -#define CY_BLE_GATT_ERR_CONDITION_NOT_SUPPORTED (0x81u) - -#define CY_BLE_ESS_UNSIGNED_TYPE (0u) -#define CY_BLE_ESS_SIGNED_TYPE (1u) - -/* ES Trigger Descriptor "Condition" field constants */ -#define CY_BLE_ESS_TRIG_TRIGGER_INACTIVE (0x00u) -#define CY_BLE_ESS_TRIG_USE_FIXED_TIME_INTERVAL (0x01u) -#define CY_BLE_ESS_TRIG_NO_LESS_THEN_TIME_INTERVAL (0x02u) -#define CY_BLE_ESS_TRIG_WHEN_CHANGED (0x03u) -#define CY_BLE_ESS_TRIG_WHILE_LESS_THAN (0x04u) -#define CY_BLE_ESS_TRIG_WHILE_LESS_OR_EQUAL (0x05u) -#define CY_BLE_ESS_TRIG_WHILE_GREATER_THAN (0x06u) -#define CY_BLE_ESS_TRIG_WHILE_GREATER_OR_EQUAL (0x07u) -#define CY_BLE_ESS_TRIG_WHILE_EQUAL_TO (0x08u) -#define CY_BLE_ESS_TRIG_WHILE_EQUAL_NOT_TO (0x09u) - -/* ES Measurement Descriptor "Sampling Function" field constants */ -#define CY_BLE_ESS_MEASURE_SF_UNSPECIFIED (0x00u) -#define CY_BLE_ESS_MEASURE_SF_INSTANTANEOUS (0x01u) -#define CY_BLE_ESS_MEASURE_SF_ARITHM_MEAN (0x02u) -#define CY_BLE_ESS_MEASURE_SF_RMS (0x03u) -#define CY_BLE_ESS_MEASURE_SF_MAXIMUM (0x04u) -#define CY_BLE_ESS_MEASURE_SF_MINIMUM (0x05u) -#define CY_BLE_ESS_MEASURE_SF_ACCUMULATED (0x06u) -#define CY_BLE_ESS_MEASURE_SF_COUNT (0x07u) - -/* ES Measurement Descriptor "Application" field constants */ -#define CY_BLE_ESS_MEASURE_APP_UNSPECIFIED (0x00u) -#define CY_BLE_ESS_MEASURE_APP_AIR (0x01u) -#define CY_BLE_ESS_MEASURE_APP_WATER (0x02u) -#define CY_BLE_ESS_MEASURE_APP_BAROMETRIC (0x03u) -#define CY_BLE_ESS_MEASURE_APP_SOIL (0x04u) -#define CY_BLE_ESS_MEASURE_APP_INFRARED (0x05u) -#define CY_BLE_ESS_MEASURE_APP_MAP_DATABASE (0x06u) -#define CY_BLE_ESS_MEASURE_APP_BAR_ELEVATION_SOURCE (0x07u) -#define CY_BLE_ESS_MEASURE_APP_GPS_ELEVATION_SOURCE (0x08u) -#define CY_BLE_ESS_MEASURE_APP_GPS_MAP_ELEVATION_SOURCE (0x09u) -#define CY_BLE_ESS_MEASURE_APP_VER_ELEVATION_SOURCE (0x0Au) -#define CY_BLE_ESS_MEASURE_APP_ONSHORE (0x0Bu) -#define CY_BLE_ESS_MEASURE_APP_ONBOARD_VES_VEH (0x0Cu) -#define CY_BLE_ESS_MEASURE_APP_FRONT (0x0Du) -#define CY_BLE_ESS_MEASURE_APP_BACK_REAR (0x0Eu) -#define CY_BLE_ESS_MEASURE_APP_UPPER (0x0Fu) -#define CY_BLE_ESS_MEASURE_APP_LOWER (0x10u) -#define CY_BLE_ESS_MEASURE_APP_PRIMARY (0x11u) -#define CY_BLE_ESS_MEASURE_APP_SECONDARY (0x12u) -#define CY_BLE_ESS_MEASURE_APP_OUTDOOR (0x13u) -#define CY_BLE_ESS_MEASURE_APP_INDOOR (0x14u) -#define CY_BLE_ESS_MEASURE_APP_TOP (0x15u) -#define CY_BLE_ESS_MEASURE_APP_BOTTOM (0x16u) -#define CY_BLE_ESS_MEASURE_APP_MAIN (0x17u) -#define CY_BLE_ESS_MEASURE_APP_BACKUP (0x18u) -#define CY_BLE_ESS_MEASURE_APP_AUXILIARY (0x19u) -#define CY_BLE_ESS_MEASURE_APP_SUPLEMENTARY (0x1Au) -#define CY_BLE_ESS_MEASURE_APP_INSIDE (0x1Bu) -#define CY_BLE_ESS_MEASURE_APP_OUTSIDE (0x1Cu) -#define CY_BLE_ESS_MEASURE_APP_LEFT (0x1Du) -#define CY_BLE_ESS_MEASURE_APP_RIGHT (0x1Eu) -#define CY_BLE_ESS_MEASURE_APP_INTERNAL (0x1Fu) -#define CY_BLE_ESS_MEASURE_APP_EXTERNAL (0x20u) -#define CY_BLE_ESS_MEASURE_APP_SOLAR (0x21u) - -/* ES Configuration Descriptor Trigger Logic value constants */ -#define CY_BLE_ESS_CONF_BOOLEAN_AND (0x00u) -#define CY_BLE_ESS_CONF_BOOLEAN_OR (0x01u) - -/* Descriptor Value Changed Characteristic Flags */ -#define CY_BLE_ESS_VALUE_CHANGE_SOURCE_CLIENT (0x01u) -#define CY_BLE_ESS_VALUE_CHANGE_ES_TRIGGER (0x02u) -#define CY_BLE_ESS_VALUE_CHANGE_ES_CONFIG (0x04u) -#define CY_BLE_ESS_VALUE_CHANGE_ES_MEASUREMENT (0x08u) -#define CY_BLE_ESS_VALUE_CHANGE_USER_DESCRIPTION (0x10u) - -/* Internal Constants -** \cond IGNORE -*/ -#define CY_BLE_ESS_U8_SIGN_BIT (0x00000080ul) -#define CY_BLE_ESS_U16_SIGN_BIT (0x00008000ul) -#define CY_BLE_ESS_U24_SIGN_BIT (0x00800000ul) - -#define CY_BLE_ESS_STATE_0 (0x00u) -#define CY_BLE_ESS_STATE_1 (0x01u) -#define CY_BLE_ESS_STATE_2 (0x02u) -#define CY_BLE_ESS_STATE_3 (0x03u) -#define CY_BLE_ESS_STATE_4 (0x04u) -#define CY_BLE_ESS_STATE_5 (0x05u) -#define CY_BLE_ESS_STATE_6 (0x06u) -#define CY_BLE_ESS_STATE_7 (0x07u) - -#define CY_BLE_ESS_2BYTES_LENGTH (0x02u) -#define CY_BLE_ESS_4BYTES_LENGTH (0x04u) -#define CY_BLE_ESS_6BYTES_LENGTH (0x06u) -#define CY_BLE_ESS_8BYTES_LENGTH (0x08u) - -#define CY_BLE_ESS_UNDEFINED_ITEM (0x00u) -#define CY_BLE_ESS_CHARACTERISTIC_ITEM (0x01u) -#define CY_BLE_ESS_DESCRIPTOR_ITEM (0x02u) - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) -#define CY_BLE_ESS_SERVICE_DATA_LENGTH (0x05u) -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - -/** \endcond */ - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_ESS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_ESS_Init(cy_stc_ble_ess_config_t *config); -cy_en_ble_api_result_t Cy_BLE_ESS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_ESS_SERVER -/** - * \addtogroup group_ble_service_api_ESS_server - * @{ - */ - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - -cy_en_ble_api_result_t Cy_BLE_ESSS_SetChangeIndex(uint16_t essIndex, uint8_t advertisingParamIndex); - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - -cy_en_ble_api_result_t Cy_BLE_ESSS_SetCharacteristicValue(cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSS_GetCharacteristicValue(cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - uint8_t attrSize, uint8_t *attrValue); - -#endif /* CY_BLE_ESS_SERVER */ - -/** @} */ - -#ifdef CY_BLE_ESS_CLIENT -/** - * \addtogroup group_ble_service_api_ESS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_ESSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - uint8_t attrSize, uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance); - -cy_en_ble_api_result_t Cy_BLE_ESSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex); - -cy_en_ble_api_result_t Cy_BLE_ESSC_SetLongCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_ESSC_GetLongCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, - uint8_t charInstance, - cy_en_ble_ess_descr_index_t descrIndex, - uint16_t attrSize, uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_ESS_CLIENT */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE */ -#ifdef CY_BLE_ESS_SERVER -uint32_t Cy_BLE_ESS_Get24ByPtr(const uint8_t ptr[]); -uint32_t Cy_BLE_ESS_Get32ByPtr(const uint8_t ptr[]); -cy_en_ble_gatt_err_code_t Cy_BLE_ESS_HandleRangeCheck(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ess_char_index_t charIndex, uint8_t charInstance, - uint16_t length, uint8_t type, const uint8_t pValue[]); -cy_en_ble_gatt_err_code_t Cy_BLE_ESSS_CheckIfInRange(uint32_t min, uint32_t max, uint32_t value, uint8_t state); -#endif /* CY_BLE_ESS_SERVER */ -/** \endcond */ - - -/*************************************** -* Macro Functions -***************************************/ - -#define Cy_BLE_ESS_Get16ByPtr Cy_BLE_Get16ByPtr -#define CY_BLE_ESS_IS_NEGATIVE(value, sign) (((((uint32_t)(value)) & (sign)) == (sign)) ? (1u) : (0u)) - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_ESS_CLIENT -extern uint8_t activeCharIndex[CY_BLE_CONFIG_GATTC_COUNT]; -extern uint8_t activeCharInstance[CY_BLE_CONFIG_GATTC_COUNT]; -extern uint8_t prevCharInstIndex[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_ESS_CLIENT) */ - -extern cy_stc_ble_ess_config_t cy_ble_essConfig; -extern cy_stc_ble_ess_config_t *cy_ble_essConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_ESS) */ -#endif /* CY_BLE_ESS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_event_handler.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_event_handler.c deleted file mode 100644 index 2ab655cc45..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_event_handler.c +++ /dev/null @@ -1,1611 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_event_handler.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Event Handler State Machine -* of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE) - -/*************************************** -* Private Function Prototypes -***************************************/ - -static void Cy_BLE_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam); -static void Cy_BLE_L2Cap_ConnParamUpdateRspEventHandler(const cy_stc_ble_l2cap_conn_update_rsp_param_t *eventParam); -static void Cy_BLE_GAP_ConnUpdateCompleteEventHandler(const cy_stc_ble_gap_conn_param_updated_in_controller_t *eventParam); - - -#if (CY_BLE_GATT_ROLE_SERVER) -static void Cy_BLE_SendWriteResponse(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam, - cy_en_ble_gatt_err_code_t gattErr); -#endif /* CY_BLE_GATT_ROLE_SERVER */ - -#if (CY_BLE_GATT_ROLE_CLIENT) -static void Cy_BLE_GAPC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - - -/*************************************** -* Global Variables -***************************************/ -volatile uint8_t cy_ble_eventHandlerFlag; -volatile uint8_t cy_ble_busyStatus[CY_BLE_CONN_COUNT]; -volatile uint32_t cy_ble_cmdStatus; - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) -uint8_t cy_ble_advertisingIntervalType; -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) -uint8_t cy_ble_scanningIntervalType; -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER */ - -#if (CY_BLE_GATT_ROLE_CLIENT) -cy_stc_ble_discovery_t cy_ble_discovery[CY_BLE_CONFIG_GATTC_COUNT]; -cy_stc_ble_disc_srvc_info_t cy_ble_serverInfo[CY_BLE_CONFIG_GATTC_COUNT][CY_BLE_SRVI_COUNT]; -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) -cy_stc_ble_event_handler_t cy_ble_eventHandler; - - -/****************************************************************************** -* Function Name: Cy_BLE_RegisterServiceEvtHandler -***************************************************************************//** -* -* Registration Service Event Handler -* -* \param eventHandlerFunc: The pointer to the callback procedure. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RegisterServiceEventHandler(cy_ble_event_handle_t eventHandlerFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint8_t existFlag = 0u; - - if(eventHandlerFunc == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Check if eventHandlerFunc has been already registered */ - uint32_t idx; - for(idx = 0u; (idx < cy_ble_eventHandler.count) && (existFlag == 0u); idx++) - { - if(cy_ble_eventHandler.serviceEventHandler[idx] == eventHandlerFunc) - { - existFlag = 1u; - } - } - } - /* Register eventHandlerFunc callback */ - if((apiResult == CY_BLE_SUCCESS) && (existFlag == 0u)) - { - if(cy_ble_eventHandler.count < CY_BLE_MAX_SRVI) - { - cy_ble_eventHandler.serviceEventHandler[cy_ble_eventHandler.count] = eventHandlerFunc; - cy_ble_eventHandler.count += 1u; - } - else - { - apiResult = CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_InvokeServiceEventHandler -***************************************************************************//** -* -* Invoke registered service event handlers. -* -* \param eventCode: The event code. -* \param eventParam: The event parameters. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_InvokeServiceEventHandler(uint32_t eventCode, - void *eventParam) -{ - uint32_t idx; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - for(idx = 0u; (idx < cy_ble_eventHandler.count) && ((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u); idx++) - { - gattErr = cy_ble_eventHandler.serviceEventHandler[idx](eventCode, eventParam); - } - - return(gattErr); -} -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL */ - -#if (CY_BLE_GATT_ROLE_SERVER) - - -/****************************************************************************** -* Function Name: Cy_BLE_SendWriteResponse -***************************************************************************//** -* -* Sends the Write Response to Write Request when event was handled by service. -* -* \param eventParam - The event parameter. -* \param gattErr - The error code. -* -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_SendWriteResponse(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam, - cy_en_ble_gatt_err_code_t gattErr) -{ - /* Send response when event was handled by the service */ - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - if(gattErr != CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_gatt_err_param_t err_param = - { - .errInfo.opCode = CY_BLE_GATT_WRITE_REQ, - .errInfo.attrHandle = eventParam->handleValPair.attrHandle, - .errInfo.errorCode = gattErr, - .connHandle = eventParam->connHandle - }; - /* Send an Error Response */ - (void)Cy_BLE_GATTS_ErrorRsp(&err_param); - } - else - { - (void)Cy_BLE_GATTS_WriteRsp(eventParam->connHandle); - } - } -} - - -#endif /* CY_BLE_GATT_ROLE_SERVER */ - - - -/****************************************************************************** -* Function Name: Cy_BLE_TimeOutEventHandler -***************************************************************************//** -* -* Handles a CY_BLE_EVT_TIMEOUT event from the BLE stack. -* -* \param eventParam: The pointer to a structure of type cy_stc_ble_timeout_param_t. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam) -{ - if(eventParam->reasonCode == CY_BLE_GATT_RSP_TO) - { - #if (CY_BLE_GATT_ROLE_CLIENT) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->CY_BLE_HANDLE.connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag != 0u)) - { - switch(Cy_BLE_GetConnectionState(eventParam->CY_BLE_HANDLE.connHandle)) - { - case CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING: - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_SRVC_DISCOVERY_FAILED, - (cy_stc_ble_conn_handle_t*)&eventParam->CY_BLE_HANDLE.connHandle); - break; - - case CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING: - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_INCL_DISCOVERY_FAILED, - (cy_stc_ble_conn_handle_t*)&eventParam->CY_BLE_HANDLE.connHandle); - break; - - case CY_BLE_CONN_STATE_CLIENT_CHAR_DISCOVERING: - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DISCOVERY_FAILED, - (cy_stc_ble_conn_handle_t*)&eventParam->CY_BLE_HANDLE.connHandle); - break; - - case CY_BLE_CONN_STATE_CLIENT_DESCR_DISCOVERING: - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DISCOVERY_FAILED, - (cy_stc_ble_conn_handle_t*)&eventParam->CY_BLE_HANDLE.connHandle); - break; - - default: /* Other states should not be set in Auto discovery mode */ - break; - } - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - Cy_BLE_SetConnectionState(eventParam->CY_BLE_HANDLE.connHandle, CY_BLE_CONN_STATE_CONNECTED); - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - #if (CY_BLE_GAP_ROLE_CENTRAL) - /* Connection procedure timeout */ - if((eventParam->reasonCode == CY_BLE_GENERIC_APP_TO) && - (cy_ble_connectingTimeout.timerHandle == eventParam->timerHandle)) - { - if(Cy_BLE_GetState() == CY_BLE_STATE_CONNECTING) - { - (void)Cy_BLE_GAPC_CancelDeviceConnection(); - } - } - #endif /* CY_BLE_GAP_ROLE_CENTRAL */ -} - - -#if (CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT) - -/****************************************************************************** -* Function Name: Cy_BLE_IsDeviceAddressValid -***************************************************************************//** -* -* This function verifies that the BLE public address has been programmed to SFLASH -* during manufacture. It can be used to verify if a public device address is -* programmed to flash memory. -* -* \param deviceAddress: The pointer to the BD address of type cy_stc_ble_gap_bd_addr_t. -* -* \return -* A non-zero value when a device address differs from the default SFLASH content. -* -******************************************************************************/ -uint8_t Cy_BLE_IsDeviceAddressValid(const cy_stc_ble_gap_bd_addr_t *deviceAddress) -{ - uint8_t addressValid = 0u; - uint32_t i; - - if(deviceAddress->type == CY_BLE_GAP_ADDR_TYPE_PUBLIC) - { - for(i = 0u; i < CY_BLE_GAP_BD_ADDR_SIZE; i++) - { - if(deviceAddress->bdAddr[i] != 0u) - { - addressValid = 1u; - break; - } - } - } - - return(addressValid); -} -#endif /* CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT */ - - -/****************************************************************************** -* Function Name: Cy_BLE_L2Cap_ConnParamUpdateRspHandler -***************************************************************************//** -* -* Handles an L2CAP connection parameter response event from -* the BLE stack. -* -* \param eventParam: -* * Accepted = 0x0000 -* * Rejected = 0x0001 -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_L2Cap_ConnParamUpdateRspEventHandler(const cy_stc_ble_l2cap_conn_update_rsp_param_t *eventParam) -{ - /* Unreferenced variable warning workaround */ - if(eventParam->result != 0u) - { - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_ConnUpdateCompleteEventHandler -***************************************************************************//** -* -* Handles a CY_BLE_EVT_GAP_CONNECTION_UPDATE_COMPLETE event from -* the BLE stack. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_GAP_ConnUpdateCompleteEventHandler(const cy_stc_ble_gap_conn_param_updated_in_controller_t *eventParam) -{ - /* Unreferenced variable warning workaround */ - if(eventParam != 0u) - { - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_EventHandler -***************************************************************************//** -* -* Handles events from the BLE stack. -* -* \param event: The event code. -* \param evParam: The event parameters. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_EventHandler(cy_en_ble_event_t event, - void *evParam) -{ - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - - /* Common Profile event handling */ - switch(event) - { - /********************************************************** - * General events - ************************************************************/ - case CY_BLE_EVT_STACK_ON: - - #if (CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT) - { - /* Set a device address */ - if(Cy_BLE_IsDeviceAddressValid(cy_ble_sflashDeviceAddress) != 0u) - { - (void)Cy_BLE_GAP_SetBdAddress(cy_ble_sflashDeviceAddress); - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - Cy_BLE_ChangeAdDeviceAddress(cy_ble_sflashDeviceAddress, 0u); - Cy_BLE_ChangeAdDeviceAddress(cy_ble_sflashDeviceAddress, 1u); - #endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER */ - } - else - { - if(cy_ble_configPtr->params->siliconDeviceAddressEnabled != 0u) - { - uint32_t bdAddrLoc; - bdAddrLoc = ((uint32_t)SFLASH->DIE_X & (uint32_t)CY_BLE_SFLASH_DIE_X_MASK) | - ((uint32_t)(((uint32_t)SFLASH->DIE_Y) & ((uint32_t)CY_BLE_SFLASH_DIE_Y_MASK)) << - CY_BLE_SFLASH_DIE_X_BITS) | - ((uint32_t)(((uint32_t)SFLASH->DIE_WAFER) & ((uint32_t)CY_BLE_SFLASH_DIE_WAFER_MASK)) << - CY_BLE_SFLASH_DIE_XY_BITS) | - ((uint32_t)(((uint32_t)SFLASH->DIE_LOT[0]) & ((uint32_t)CY_BLE_SFLASH_DIE_LOT_MASK)) << - CY_BLE_SFLASH_DIE_XYWAFER_BITS); - - cy_ble_configPtr->deviceAddress->bdAddr[0] = (uint8_t)bdAddrLoc; - cy_ble_configPtr->deviceAddress->bdAddr[1] = (uint8_t)(bdAddrLoc >> 8u); - cy_ble_configPtr->deviceAddress->bdAddr[2] = (uint8_t)(bdAddrLoc >> 16u); - } - (void)Cy_BLE_GAP_SetBdAddress(cy_ble_configPtr->deviceAddress); - - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - Cy_BLE_ChangeAdDeviceAddress(cy_ble_configPtr->deviceAddress, 0u); - Cy_BLE_ChangeAdDeviceAddress(cy_ble_configPtr->deviceAddress, 1u); - #endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER */ - } - /* Set the device IO Capability */ - (void)Cy_BLE_GAP_SetIoCap((cy_en_ble_gap_iocap_t*)&cy_ble_configPtr->params->securityIoCapability); - { - /* Enable all 4.1 events and configured 4.2 events */ - uint8_t leMask[CY_BLE_LE_MASK_LENGTH] = { CY_LO8(CY_BLE_LE_MASK), - CY_HI8(CY_BLE_LE_MASK),0u, 0u, 0u, 0u, 0u, 0u }; - (void)Cy_BLE_SetLeEventMask(leMask); - } - } - #endif /* CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT */ - Cy_BLE_SetState(CY_BLE_STATE_ON); - break; - - case CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE: - Cy_BLE_SetState(CY_BLE_STATE_STOPPED); - - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOPPED); - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - - #if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_STOPPED); - #endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) */ - - /* Adding a delay of 10ms to ensure that the controller is completely - * shut-down before generating the event to the application. - * Controller generates CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE event immediately - * after accepting the shut-down command (before resetting the controller), - * once this behaviour is fixed, this delay will no longer be required - */ - #if(CY_BLE_STACK_MODE_HOST_IPC) - Cy_SysLib_Delay(10u); - #endif /* CY_BLE_STACK_MODE_HOST_IPC */ - - /* Unregister BLE callback for Deepsleep/Sleep */ - Cy_BLE_UnregisterHostPMCallbacks(); - break; - - case CY_BLE_EVT_LE_SET_EVENT_MASK_COMPLETE: - #if (CY_BLE_MODE_PROFILE) - { - if((cy_ble_cmdStatus & CY_BLE_STATUS_SET_TX_PWR_LVL) == 0u) - { - cy_stc_ble_tx_pwr_lvl_info_t bleSsPowerLevel = { .pwrConfigParam.bdHandle = 0x0u }; - - /* Set the Tx Power Level for advertising and connection channels */ - bleSsPowerLevel.blePwrLevel = cy_ble_configPtr->params->txPowerLevelAdv; - bleSsPowerLevel.pwrConfigParam.bleSsChId = CY_BLE_LL_ADV_CH_TYPE; - (void)Cy_BLE_SetTxPowerLevel(&bleSsPowerLevel); - - bleSsPowerLevel.blePwrLevel = cy_ble_configPtr->params->txPowerLevelConn; - bleSsPowerLevel.pwrConfigParam.bleSsChId = CY_BLE_LL_CONN_CH_TYPE; - bleSsPowerLevel.pwrConfigParam.bdHandle = 0xFFu; /* Set the tx power level value for all connection handles.*/ - (void)Cy_BLE_SetTxPowerLevel(&bleSsPowerLevel); - - /* Set flag that executed Cy_BLE_SetTxPowerLevel during componnent start-up */ - cy_ble_cmdStatus |= CY_BLE_STATUS_SET_TX_PWR_LVL; - } - } - #endif /* CY_BLE_MODE_PROFILE */ - break; - - case CY_BLE_EVT_TIMEOUT: - Cy_BLE_TimeOutEventHandler((cy_stc_ble_timeout_param_t*)evParam); - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - #endif /*(CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)*/ - break; - - case CY_BLE_EVT_STACK_BUSY_STATUS: - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) - cy_ble_busyStatus[Cy_BLE_GetConnHandleByBdHandle(((cy_stc_ble_l2cap_state_info_t*)evParam)->bdHandle).attId] = - ((cy_stc_ble_l2cap_state_info_t*)evParam)->flowState; - #endif /*(CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)*/ - break; - - case CY_BLE_EVT_MEMORY_REQUEST: - #if (CY_BLE_MODE_PROFILE) - { - cy_stc_ble_memory_request_t *memReq = (cy_stc_ble_memory_request_t*)evParam; - if(memReq->request == CY_BLE_PREPARED_WRITE_REQUEST) - { - #if (CY_BLE_GATT_ENABLE_EXTERNAL_PREP_WRITE_BUFF == 0u) - /* Stack requests to provide memory to process a remote request */ - if(memReq->allocFree == CY_BLE_ALLOC_MEMORY) - { - static cy_stc_ble_prepare_write_request_memory_t gPrepWriteReqMem; - - /* Configure and return a statically allocated buffer at the end of the cy_ble_stackMemoryRam buffer */ - gPrepWriteReqMem.prepareWriteQueueSize = CY_BLE_GATT_MAX_PREPARE_BUFF_COUNT; - gPrepWriteReqMem.totalAttrValueLength = CY_BLE_GATT_PREPARE_LENGTH_ALIGN; - gPrepWriteReqMem.queueBuffer = &cy_ble_stackMemoryRam[CY_BLE_STACK_RAM_SIZE - - CY_BLE_GATT_PREPARE_WRITE_BUFF_LEN]; - memReq->configMemory = &gPrepWriteReqMem; - } - /* Clear the CY_BLE_CALLBACK flag not to provide a handled event to the application */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - #endif /* CY_BLE_GATT_ENABLE_EXTERNAL_PREP_WRITE_BUFF == 0u */ - } - } - #endif /* CY_BLE_MODE_PROFILE */ - break; - - /********************************************************** - * GAP events - ************************************************************/ - case CY_BLE_EVT_GAP_AUTH_REQ: - break; - - case CY_BLE_EVT_GAP_AUTH_COMPLETE: - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - { - cy_stc_ble_conn_handle_t connectedHandle; - connectedHandle = Cy_BLE_GetConnHandleByBdHandle(((cy_stc_ble_gap_auth_info_t*)evParam)->bdHandle); - cy_ble_peerBonding[connectedHandle.attId] = ((cy_stc_ble_gap_auth_info_t*)evParam)->bonding; - } - #endif /* CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES */ - break; - - case CY_BLE_EVT_GAP_CONNECTION_UPDATE_COMPLETE: - Cy_BLE_GAP_ConnUpdateCompleteEventHandler((const cy_stc_ble_gap_conn_param_updated_in_controller_t*)evParam); - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - #endif /*(CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) */ - break; - - #if (CY_BLE_LL_PRIVACY_FEATURE != 0u) - case CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE: - { - cy_stc_ble_gap_conn_param_updated_in_controller_t connCParam; - cy_stc_ble_gap_enhance_conn_complete_param_t *connEnhanceParam; - - connEnhanceParam = (cy_stc_ble_gap_enhance_conn_complete_param_t*)evParam; - connCParam.status = connEnhanceParam->status; - connCParam.connIntv = connEnhanceParam->connIntv; - connCParam.connLatency = connEnhanceParam->connLatency; - connCParam.supervisionTO = connEnhanceParam->supervisionTo; - Cy_BLE_GAP_ConnUpdateCompleteEventHandler((const cy_stc_ble_gap_conn_param_updated_in_controller_t*)&connCParam); - - /* Advertising is automatically stopped if a Slave is connected, so update the adv state to - * CY_BLE_ADV_STATE_STOPPED */ - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - if(connEnhanceParam->role == (uint8_t)CY_BLE_GAP_LL_ROLE_SLAVE) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOPPED); - } - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - } - #else - case CY_BLE_EVT_GAP_DEVICE_CONNECTED: - Cy_BLE_GAP_ConnUpdateCompleteEventHandler((const cy_stc_ble_gap_conn_param_updated_in_controller_t*)evParam); - - /* Advertising is automatically stopped if a Slave is connected, so update the adv state to CY_BLE_ADV_STATE_STOPPED */ - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - if(((cy_stc_ble_gap_connected_param_t*)evParam)->role == CY_BLE_GAP_LL_ROLE_SLAVE) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOPPED); - } - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - #endif /* CY_BLE_LL_PRIVACY_FEATURE != 0u */ - #if (CY_BLE_GAP_ROLE_CENTRAL) - if(cy_ble_connectingTimeout.timeout != 0u) - { - (void)Cy_BLE_StopTimer(&cy_ble_connectingTimeout); - } - #endif /* CY_BLE_GAP_ROLE_CENTRAL */ - Cy_BLE_SetState(CY_BLE_STATE_ON); - break; - - case CY_BLE_EVT_GAP_DEVICE_DISCONNECTED: - Cy_BLE_SetState(CY_BLE_STATE_ON); - break; - - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - case CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP: - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) */ - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - /* After Cy_BLE_GAPP_StartAdvertisement, the first event indicates that advertising has started */ - if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADV_INITIATED) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_ADVERTISING); - } - /* When the application initiated a stop advertisement */ - else if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_STOP_INITIATED) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOPPED); - } - else /* The following event indicates that advertising has been stopped */ - { - if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOPPED); - if((cy_ble_configPtr->gappAdvParams[cy_ble_advIndex].slowAdvEnable != 0u) && - (cy_ble_configPtr->gappAdvParams[cy_ble_advIndex].fastAdvTimeOut != 0u)) - { - if(cy_ble_advertisingIntervalType == CY_BLE_ADVERTISING_FAST) - { - /* When fast advertising time out occur: Start slow advertising */ - if(Cy_BLE_GAPP_StartAdvertisement(CY_BLE_ADVERTISING_SLOW, cy_ble_advIndex) == - CY_BLE_SUCCESS) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_ADV_INITIATED); - } - } - } - } - } - } - break; - #endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER */ - - #if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) - case CY_BLE_EVT_GAPC_SCAN_START_STOP: - #if (CY_BLE_GAP_ROLE_CENTRAL) - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - #endif /* (CY_BLE_GAP_ROLE_CENTRAL) */ - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - /* After Cy_BLE_GAPC_StartScan, the first event indicates that scanning has been started */ - if(Cy_BLE_GetScanState() == CY_BLE_SCAN_STATE_SCAN_INITIATED) - { - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_SCANNING); - } - /* When the application initiated stop scanning */ - else if(Cy_BLE_GetScanState() == CY_BLE_SCAN_STATE_STOP_INITIATED) - { - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_STOPPED); - } - else /* The following event indicates that scanning has been stopped by stack */ - { - if(Cy_BLE_GetScanState() == CY_BLE_SCAN_STATE_SCANNING) - { - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_STOPPED); - if((cy_ble_configPtr->gapcScanParams[cy_ble_scanIndex].slowScanEnabled != 0u) && - (cy_ble_configPtr->gapcScanParams[cy_ble_scanIndex].fastScanTimeOut != 0u)) - { - if(cy_ble_scanningIntervalType == CY_BLE_SCANNING_FAST) - { - /* When a fast scanning timeout occurs: Start slow scanning */ - if(Cy_BLE_GAPC_StartScan(CY_BLE_SCANNING_SLOW, cy_ble_scanIndex) == CY_BLE_SUCCESS) - { - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_SCAN_INITIATED); - } - } - } - } - } - } - break; - #endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER */ - - /********************************************************** - * L2AP events - ************************************************************/ - case CY_BLE_EVT_L2CAP_CONN_PARAM_UPDATE_RSP: - Cy_BLE_L2Cap_ConnParamUpdateRspEventHandler((cy_stc_ble_l2cap_conn_update_rsp_param_t*)evParam); - - #if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) */ - break; - - /********************************************************** - * GATT events - ************************************************************/ - #if ((CY_BLE_GATT_ROLE_SERVER) || (CY_BLE_GATT_ROLE_CLIENT)) - case CY_BLE_EVT_GATT_CONNECT_IND: - #if (CY_BLE_GATT_ROLE_CLIENT) - /* If connected to the same device which is already discovered */ - if((Cy_BLE_GetConnectionState(*(cy_stc_ble_conn_handle_t*)evParam) == - CY_BLE_CONN_STATE_CLIENT_DISCONNECTED_DISCOVERED) && - (((cy_stc_ble_conn_handle_t*)evParam)->bdHandle == - cy_ble_connHandle[((cy_stc_ble_conn_handle_t*)evParam)->attId].bdHandle)) - { /* Set a discovered state */ - Cy_BLE_SetConnectionState(*(cy_stc_ble_conn_handle_t*)evParam, CY_BLE_CONN_STATE_CLIENT_DISCOVERED); - } - else /* Connected to a new device */ - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - { - /* Clear the discovery index for the Client role */ - #if (CY_BLE_GATT_ROLE_CLIENT) - (void)Cy_BLE_GATTC_RemoveConnHandle(*(cy_stc_ble_conn_handle_t*)evParam); - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - Cy_BLE_SetConnectionState(*(cy_stc_ble_conn_handle_t*)evParam, CY_BLE_CONN_STATE_CONNECTED); - cy_ble_connHandle[((cy_stc_ble_conn_handle_t*)evParam)->attId] = *(cy_stc_ble_conn_handle_t*)evParam; - } - - cy_ble_busyStatus[((cy_stc_ble_conn_handle_t*)evParam)->attId] = CY_BLE_STACK_STATE_FREE; - - #if ((CY_BLE_GATT_ROLE_SERVER) && (CY_BLE_GATT_DB_CCCD_COUNT != 0u) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - - /* Initialize the CCCD values in the RAM when bonding is enabled */ - (void)memcpy((uint8_t*)cy_ble_attValuesCccdMultiple[((cy_stc_ble_conn_handle_t*)evParam)->attId], - cy_ble_configPtr->flashStorage->attValuesCCCDFlashMemory[((cy_stc_ble_conn_handle_t*)evParam)-> - bdHandle], - CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE); - - /* Check CRC for CCCD data */ - { - uint8_t cccdCrc = Cy_BLE_HAL_CalcCRC8(cy_ble_attValuesCccdMultiple[((cy_stc_ble_conn_handle_t*)evParam)->attId], - CY_BLE_GATT_DB_CCCD_COUNT); - - if(cy_ble_attValuesCccdMultiple[((cy_stc_ble_conn_handle_t*)evParam)->attId][CY_BLE_GATT_DB_CCCD_COUNT] != cccdCrc) - { - /* Inform that the CRC for CCCD is wrong */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTS_EVT_CCCD_CORRUPT, NULL); - - /* Clean the CCCD buffer in the RAM */ - (void)memset((uint8_t*)cy_ble_attValuesCccdMultiple[((cy_stc_ble_conn_handle_t*)evParam)->attId], - 0, CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE); - } - } - - #endif /* CY_BLE_GATT_ROLE_SERVER && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATT_DISCONNECT_IND: - #if (CY_BLE_GATT_ROLE_CLIENT) - if((Cy_BLE_GetConnectionState(*(cy_stc_ble_conn_handle_t*)evParam) == CY_BLE_CONN_STATE_CLIENT_DISCOVERED) && - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - { - Cy_BLE_SetConnectionState(*(cy_stc_ble_conn_handle_t*)evParam, - CY_BLE_CONN_STATE_CLIENT_DISCONNECTED_DISCOVERED); - } - else - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - { - Cy_BLE_SetConnectionState(*(cy_stc_ble_conn_handle_t*)evParam, CY_BLE_CONN_STATE_DISCONNECTED); - #if (CY_BLE_GATT_ROLE_CLIENT) - (void)Cy_BLE_GATTC_RemoveConnHandle(*(cy_stc_ble_conn_handle_t*)evParam); - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTS_XCNHG_MTU_REQ: - { - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam; - mtuParam.connHandle = ((cy_stc_ble_gatt_xchg_mtu_param_t*)evParam)->connHandle; - - if(CY_BLE_GATT_MTU > ((cy_stc_ble_gatt_xchg_mtu_param_t*)evParam)->mtu) - { - mtuParam.mtu = ((cy_stc_ble_gatt_xchg_mtu_param_t*)evParam)->mtu; - } - else - { - mtuParam.mtu = CY_BLE_GATT_MTU; - } - (void)Cy_BLE_GATTS_ExchangeMtuRsp(&mtuParam); - } - break; - #endif /* CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT */ - - #if (CY_BLE_GATT_ROLE_CLIENT) - case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - - #if (CY_BLE_GATT_ROLE_SERVER) - case CY_BLE_EVT_GATTS_WRITE_REQ: - { - cy_en_ble_gatt_err_code_t gattErr; - gattErr = Cy_BLE_GATTS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)evParam); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - gattErr = Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - } - Cy_BLE_SendWriteResponse((cy_stc_ble_gatts_write_cmd_req_param_t*)evParam, gattErr); - } - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ: - #if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) - (void)Cy_BLE_GATTS_ReadAttributeValueCCCDReqHandler((cy_stc_ble_gatts_char_val_read_req_t*)evParam); - #endif /* (CY_BLE_GATT_DB_CCCD_COUNT != 0u) */ - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - #endif /* CY_BLE_GATT_ROLE_SERVER */ - - #if (CY_BLE_GATT_ROLE_CLIENT) - case CY_BLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP: - Cy_BLE_ReadByGroupEventHandler((cy_stc_ble_gattc_read_by_grp_rsp_param_t*)evParam); - break; - - case CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP: - Cy_BLE_ReadByTypeEventHandler((cy_stc_ble_gattc_read_by_type_rsp_param_t*)evParam); - break; - - case CY_BLE_EVT_GATTC_READ_BLOB_RSP: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTC_LONG_PROCEDURE_END: - Cy_BLE_LongProcedureEndEventHandler(((cy_stc_ble_gattc_long_procedure_end_param_t*)evParam)->connHandle); - break; - - case CY_BLE_EVT_GATTC_FIND_INFO_RSP: - Cy_BLE_FindInfoEventHandler((cy_stc_ble_gattc_find_info_rsp_param_t*)evParam); - break; - - case CY_BLE_EVT_GATTC_ERROR_RSP: - Cy_BLE_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)evParam); - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_GATTC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)evParam); - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - - /* Respond with a Handle Value Confirmation when request handled */ - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - cy_stc_ble_gattc_confirmation_req_t confirmationParam; - confirmationParam.connHandle = ((cy_stc_ble_gattc_handle_value_ind_param_t*)evParam)->connHandle; - - (void)Cy_BLE_GATTC_Confirmation(&confirmationParam); - } - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTC_READ_MULTI_RSP: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - - case CY_BLE_EVT_GATTC_EXEC_WRITE_RSP: - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)event, (void*)evParam); - break; - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - case CY_BLE_EVT_PENDING_FLASH_WRITE: - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_STACK_FLASH_WRITE_BIT; - break; - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - default: - break; - } - - if((cy_ble_eventHandlerFlag & (CY_BLE_CALLBACK | CY_BLE_ENABLE_ALL_EVENTS)) != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_ApplCallback((uint32_t)event, evParam); - } -} - -#if (CY_BLE_GATT_ROLE_CLIENT) - -/****************************************************************************** -* Function Name: Cy_BLE_ReadByGroupEventHandler -***************************************************************************//** -* -* Handles a Read By Group Response event during an automatic server discovery -* process. -* -* \param eventParam: The event parameters for a Read By Group Response. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_ReadByGroupEventHandler(cy_stc_ble_gattc_read_by_grp_rsp_param_t *eventParam) -{ - cy_stc_ble_disc_srv_info_t locDiscServInfo = { .connHandle = eventParam->connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint16_t locDataLength; - uint16_t attrLength; - uint32_t fFlag; - uint32_t j; - uint32_t i; - - if((Cy_BLE_GetConnectionState(eventParam->connHandle) == CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING) && - (discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag != 0u)) - { - locDataLength = eventParam->attrData.length; - - if((locDataLength == CY_BLE_DISC_SRVC_INFO_LEN) || (locDataLength == CY_BLE_DISC_SRVC_INFO_128_LEN)) - { - attrLength = eventParam->attrData.attrLen; - - for(i = 0u; i < attrLength; i += locDataLength) - { - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - - locDiscServInfo.srvcInfo = (cy_stc_ble_disc_srvc128_info_t*)(eventParam->attrData.attrValue + i); - fFlag = 0u; - - /* Received a 16-bit service UUID */ - if((locDiscServInfo.srvcInfo->range.startHandle >= - cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle) && - (locDiscServInfo.srvcInfo->range.startHandle <= - cy_ble_discovery[discIdx].gattcDiscoveryRange.endHandle)) - { - if(locDataLength == CY_BLE_DISC_SRVC_INFO_LEN) - { - for(j = 0u; (j < (uint32_t)CY_BLE_SRVI_COUNT) && (fFlag == 0u); j++) - { - locDiscServInfo.uuidFormat = CY_BLE_GATT_16_BIT_UUID_FORMAT; - if(cy_ble_serverInfo[discIdx][j].uuid == locDiscServInfo.srvcInfo->uuid.uuid16) - { - if(cy_ble_serverInfo[discIdx][j].range.startHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_serverInfo[discIdx][j].range = locDiscServInfo.srvcInfo->range; - fFlag = 1u; - } - else /* Duplication of service */ - { - /* For multiple service support next service has the same UUID */ - if((j >= (CY_BLE_SRVI_COUNT - 1u)) || - (cy_ble_serverInfo[discIdx][j + 1u].uuid != locDiscServInfo.srvcInfo->uuid.uuid16)) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_SRVC_DUPLICATION, &locDiscServInfo); - fFlag = 1u; - } - } - } - } - } - else /* Received a 128-bit service UUID */ - { - locDiscServInfo.uuidFormat = CY_BLE_GATT_128_BIT_UUID_FORMAT; - - /* Loop thru all registered services and invoke CY_BLE_EVT_GATTC_DISC_CHAR event */ - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)CY_BLE_EVT_GATTC_DISC_SERVICE, - (void*)&locDiscServInfo); - } - } - - /* Generate event CY_BLE_EVT_GATTC_DISC_SKIPPED_SERVICE, if the incoming service was not processed */ - if((fFlag == 0u) && ((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u)) - { - /* Inform application that we discovered the service which is not defined in GATT database */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DISC_SKIPPED_SERVICE, &locDiscServInfo); - } - - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_SRVC_DISCOVERY_FAILED, &eventParam->connHandle); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_NextInclDiscovery -***************************************************************************//** -* -* Looks for the included services in the current service (pointed by -* cy_ble_disCount). If the current service handle range is invalid (any of start -* or end handle is invalid), then increments the cy_ble_disCount and check -* the next service range and does so until a valid range is caught or the end of -* the service set is reached. -* -* \param connHandle: The connection handle. -* \param incrementIndex: A non-zero value indicates that the service index should be -* incremented. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_NextInclDiscovery(cy_stc_ble_conn_handle_t connHandle, - uint8_t incrementIndex) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(incrementIndex != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].servCount++; - } - else - { - cy_ble_discovery[discIdx].servCount = 0u; - cy_ble_discovery[discIdx].inclInfo.inclDefHandle = 0u; - } - - /* Skip not existing services and services out of the discovery range */ - while((cy_ble_discovery[discIdx].servCount < (uint8_t)CY_BLE_SRVI_COUNT) && - ((cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.startHandle < - cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle) || - (cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.startHandle > - cy_ble_discovery[discIdx].gattcDiscoveryRange.endHandle))) - { - cy_ble_discovery[discIdx].servCount++; - } - - if(cy_ble_discovery[discIdx].servCount < (uint8_t)CY_BLE_SRVI_COUNT) - { - cy_stc_ble_gattc_read_by_type_req_t requestParam = - { - .range = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range, - .connHandle = connHandle - }; - if(Cy_BLE_GATTC_FindIncludedServices(&requestParam) != CY_BLE_SUCCESS) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_INCL_DISCOVERY_FAILED, &connHandle); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - } - } - else /* An included service discovery procedure is done, start a characteristic discovery procedure */ - { - if((cy_ble_eventHandlerFlag & CY_BLE_ENABLE_ALL_EVENTS) != 0u) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_INCL_DISCOVERY_COMPLETE, &connHandle); - } - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_CHAR_DISCOVERING); - Cy_BLE_NextCharDiscovery(connHandle, CY_BLE_DISCOVERY_INIT); - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param connHandle: The connection handle. -* \param discCharInfo: The pointer to the characteristic information structure. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_GAPC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_GAP)) - { - switch(discCharInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_DEVICE_NAME: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.deviceNameCharHandle, discCharInfo); - break; - - case CY_BLE_UUID_CHAR_APPEARANCE: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.appearanceCharHandle, discCharInfo); - break; - - case CY_BLE_UUID_CHAR_PERIPH_PRIVCY_FLAG: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.periphPrivacyCharHandle, discCharInfo); - break; - - case CY_BLE_UUID_CHAR_RECONNECTION_ADDR: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.reconnAddrCharHandle, discCharInfo); - break; - - case CY_BLE_UUID_CHAR_PRFRRD_CNXN_PARAM: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.prefConnParamCharHandle, discCharInfo); - break; - - case CY_BLE_UUID_CHAR_CENTRAL_ADDRESS_RESOLUTION: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.centralAddrResolutionCharHandle, discCharInfo); - break; - - case CY_BLE_UUID_CHAR_RESOLVABLE_PRIVATE_ADDR_ONLY: - CY_BLE_GapcCheckCharHandle(cy_ble_discovery[discIdx].gapc.resolvablePrivateAddressOnly, discCharInfo); - break; - - default: - break; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_ReadByTypeEventHandler -***************************************************************************//** -* -* Handles a Read By Type Response event during an automatic server discovery -* process. -* -* \param eventParam: The event parameters for a Read By Type Response. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_ReadByTypeEventHandler(cy_stc_ble_gattc_read_by_type_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t locDataLength; - uint32_t attrLength; - uint32_t i; - uint32_t j; - uint8_t *attrVal; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag != 0u)) - { - /* Count of service information pieces in this mtu */ - locDataLength = (uint32_t)eventParam->attrData.length; - attrLength = (uint32_t)eventParam->attrData.attrLen; - attrVal = eventParam->attrData.attrValue; - - if(Cy_BLE_GetConnectionState(eventParam->connHandle) == CY_BLE_CONN_STATE_CLIENT_CHAR_DISCOVERING) - { - cy_stc_ble_disc_char_info_t locDiscCharInfo; - locDiscCharInfo.connHandle = eventParam->connHandle; - - for(i = 0u; i < attrLength; i += locDataLength) - { - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - - /* Get Handle for characteristic declaration */ - locDiscCharInfo.charDeclHandle = Cy_BLE_Get16ByPtr(attrVal); - attrVal += sizeof(locDiscCharInfo.charDeclHandle); - - /* Get Properties for value */ - locDiscCharInfo.properties = *attrVal; - attrVal += sizeof(locDiscCharInfo.properties); - - /* Get Handle to server database attribute value entry */ - locDiscCharInfo.valueHandle = Cy_BLE_Get16ByPtr(attrVal); - attrVal += sizeof(locDiscCharInfo.valueHandle); - - /* Get Characteristic UUID (128/16 bit) */ - if(locDataLength == CY_BLE_DISC_CHAR_INFO_128_LEN) - { - locDiscCharInfo.uuidFormat = CY_BLE_GATT_128_BIT_UUID_FORMAT; - (void)memcpy(&locDiscCharInfo.uuid.uuid128, attrVal, CY_BLE_GATT_128_BIT_UUID_SIZE); - attrVal += CY_BLE_GATT_128_BIT_UUID_SIZE; - } - else if(locDataLength == CY_BLE_DISC_CHAR_INFO_LEN) - { - locDiscCharInfo.uuidFormat = CY_BLE_GATT_16_BIT_UUID_FORMAT; - locDiscCharInfo.uuid.uuid16 = Cy_BLE_Get16ByPtr(attrVal); - attrVal += CY_BLE_GATT_16_BIT_UUID_SIZE; - } - else - { - /* Unsupported data length value */ - } - - if((locDataLength == CY_BLE_DISC_CHAR_INFO_128_LEN) || (locDataLength == CY_BLE_DISC_CHAR_INFO_LEN)) - { - /* Process common services: GAP and GATT */ - Cy_BLE_GAPC_DiscoverCharacteristicsEventHandler(&locDiscCharInfo); - Cy_BLE_GATTC_DiscoverCharacteristicsEventHandler(&locDiscCharInfo); - - /* Loop thru all registered services and invoke CY_BLE_EVT_GATTC_DISC_CHAR event */ - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)CY_BLE_EVT_GATTC_DISC_CHAR, (void*)&locDiscCharInfo); - } - } - /* The sub-procedure is complete when an Error Response is received and the - * Error Code is set to the Attribute Not Found; or the Read By Type Response has an - * Attribute Handle equal to the Ending Handle of the request - in this case - * a CY_BLE_EVT_GATTC_LONG_PROCEDURE_END event is generated by the stack. */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(Cy_BLE_GetConnectionState(eventParam->connHandle) == CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING) - { - cy_stc_ble_disc_incl_info_t locDiscInclInfo; - locDiscInclInfo.connHandle = eventParam->connHandle; - - for(i = 0u; i < attrLength; i += locDataLength) - { - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - - locDiscInclInfo.inclDefHandle = Cy_BLE_Get16ByPtr(attrVal); - attrVal += sizeof(locDiscInclInfo.inclDefHandle); - - locDiscInclInfo.inclHandleRange.startHandle = Cy_BLE_Get16ByPtr(attrVal); - attrVal += sizeof(locDiscInclInfo.inclHandleRange.startHandle); - - locDiscInclInfo.inclHandleRange.endHandle = Cy_BLE_Get16ByPtr(attrVal); - attrVal += sizeof(locDiscInclInfo.inclHandleRange.endHandle); - - if(locDataLength == CY_BLE_DISC_INCL_INFO_128_LEN) - { - cy_stc_ble_gattc_stop_cmd_param_t stopCmdParam = { .connHandle = eventParam->connHandle }; - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = locDiscInclInfo.inclHandleRange.startHandle, - .connHandle = eventParam->connHandle - }; - locDiscInclInfo.uuidFormat = CY_BLE_GATT_128_BIT_UUID_FORMAT; - - /* Stop ongoing GATT operation */ - (void)Cy_BLE_GATTC_StopCmd(&stopCmdParam); - - /* Get the included service UUID when the included service uses a 128-bit - * UUID, a Read Request is used. The Attribute Handle for the Read Request is - * the Attribute Handle of the included service. - */ - - if(Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam) == CY_BLE_SUCCESS) - { - /* Save handle to support a read response from device */ - cy_ble_discovery[discIdx].inclInfo = locDiscInclInfo; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_INCL_DISCOVERY_FAILED, &eventParam->connHandle); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - } - } - else if(locDataLength == CY_BLE_DISC_INCL_INFO_LEN) - { - locDiscInclInfo.uuidFormat = CY_BLE_GATT_16_BIT_UUID_FORMAT; - locDiscInclInfo.uuid.uuid16 = Cy_BLE_Get16ByPtr(attrVal); - attrVal += CY_BLE_GATT_16_BIT_UUID_SIZE; - - /* Store the range of the included service in the list of services for discovery */ - for(j = 0u; j < (uint32_t)CY_BLE_SRVI_COUNT; j++) - { - if(cy_ble_serverInfo[discIdx][j].uuid == locDiscInclInfo.uuid.uuid16) - { - if(cy_ble_serverInfo[discIdx][j].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_serverInfo[discIdx][j].range = locDiscInclInfo.inclHandleRange; - break; - } - } - } - } - else - { - /* Unsupported data length value */ - } - - /* Loop thru all registered services and invoke CY_BLE_EVT_GATTC_DISC_INCL event */ - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)CY_BLE_EVT_GATTC_DISC_INCL, (void*)&locDiscInclInfo); - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Unhandled state value */ - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_NextCharDiscovery -***************************************************************************//** -* -* Looks for a characteristic handle range for the current service (pointed by -* cy_ble_disCount). If the current range is invalid (any of start or end -* handles is invalid), then increments the cy_ble_disCount and check -* the next service range and does so until a valid range is caught or the end -* of the service set is reached. -* -* \param connHandle: The connection handle. -* \param incrementIndex: A non-zero value indicates that the characteristic index -* should be incremented. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_NextCharDiscovery(cy_stc_ble_conn_handle_t connHandle, - uint8_t incrementIndex) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(incrementIndex != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].servCount++; - } - else - { - cy_ble_discovery[discIdx].servCount = 0u; - } - - /* Skip not existing services and services out of the discovery range */ - while((cy_ble_discovery[discIdx].servCount < (uint32_t)CY_BLE_SRVI_COUNT) && - ((cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.startHandle < - cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle) || - (cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.startHandle > - cy_ble_discovery[discIdx].gattcDiscoveryRange.endHandle))) - { - cy_ble_discovery[discIdx].servCount++; - } - - if(cy_ble_discovery[discIdx].servCount < (uint8_t)CY_BLE_SRVI_COUNT) - { - cy_stc_ble_gattc_read_by_type_req_t reqParam = - { - .connHandle = connHandle, - .range = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range - }; - if(Cy_BLE_GATTC_DiscoverCharacteristics(&reqParam) != CY_BLE_SUCCESS) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DISCOVERY_FAILED, &connHandle); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - } - } - else /* A Characteristic discovery procedure is done, start a descriptor discovery procedure */ - { - if((cy_ble_eventHandlerFlag & CY_BLE_ENABLE_ALL_EVENTS) != 0u) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DISCOVERY_COMPLETE, &connHandle); - } - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_DESCR_DISCOVERING); - Cy_BLE_NextCharDscrDiscovery(connHandle, CY_BLE_DISCOVERY_INIT); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_FindInfoEventHandler -***************************************************************************//** -* -* Handles a Find Info Response event during an automatic server discovery -* process. -* -* \param eventParam: The event parameters for a Find Info Response. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_FindInfoEventHandler(cy_stc_ble_gattc_find_info_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t locDataLength; - uint32_t attrLength; - uint32_t i; - uint8_t *attrVal; - - /* Discovery descriptor information */ - cy_stc_ble_disc_descr_info_t locDiscDescrInfo; - - locDiscDescrInfo.descrHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - if((Cy_BLE_GetConnectionState(eventParam->connHandle) == CY_BLE_CONN_STATE_CLIENT_DESCR_DISCOVERING) && - (discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag != 0u)) - { - attrLength = eventParam->handleValueList.byteCount; /* Number of elements on list in bytes */ - locDiscDescrInfo.uuidFormat = eventParam->uuidFormat; - locDiscDescrInfo.connHandle = eventParam->connHandle; - - if(locDiscDescrInfo.uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) - { - locDataLength = CY_BLE_DB_ATTR_HANDLE_LEN + CY_BLE_GATT_16_BIT_UUID_SIZE; - } - else - { - locDataLength = CY_BLE_DB_ATTR_HANDLE_LEN + CY_BLE_GATT_128_BIT_UUID_SIZE; - } - attrVal = eventParam->handleValueList.list; - - for(i = 0u; i < attrLength; i += locDataLength) - { - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - - locDiscDescrInfo.descrHandle = Cy_BLE_Get16ByPtr(attrVal); - attrVal += CY_BLE_DB_ATTR_HANDLE_LEN; - - - if(locDiscDescrInfo.uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT) - { - (void)memcpy(&locDiscDescrInfo.uuid.uuid128, attrVal, CY_BLE_GATT_128_BIT_UUID_SIZE); - attrVal += CY_BLE_GATT_128_BIT_UUID_SIZE; - } - else - { - locDiscDescrInfo.uuid.uuid16 = Cy_BLE_Get16ByPtr(attrVal); - attrVal += CY_BLE_GATT_16_BIT_UUID_SIZE; - } - - /* Process common services: GATT */ - Cy_BLE_GATTC_DiscoverCharDescriptorsEventHandler(&locDiscDescrInfo); - - /* Loop thru all registered services and invoke CY_BLE_EVT_GATTC_DISC_CHAR event */ - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)CY_BLE_EVT_GATTC_DISC_DESCR, (void*)&locDiscDescrInfo); - } - - /* The sub-procedure is complete when an Error Response is received and the - * Error Code is set to the Attribute Not Found or the Find Information Response has - * an Attribute Handle that is equal to the Ending Handle of the request in this - * case a CY_BLE_EVT_GATTC_LONG_PROCEDURE_END event is generated by the stack. */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_NextCharDscrDiscovery -***************************************************************************//** -* -* Looks for a handle range for the current descriptor (pointed by -* cy_ble_discovery[discIdx].servCount). If the current range is invalid (any of start or end -* handles is invalid), then increments the cy_ble_discovery[discIdx].servCount and check -* the next descriptor range and does so until a valid range is caught or the -* end of the descriptor set is reached. -* -* \param connHandle: The connection handle. -* \param incrementIndex: A non-zero value indicates that the characteristic index should be -* incremented. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_NextCharDscrDiscovery(cy_stc_ble_conn_handle_t connHandle, - uint8_t incrementIndex) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - cy_stc_ble_disc_range_info_t charRangeInfo = { .connHandle = connHandle, .srviIncIdx = incrementIndex }; - - do - { - cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK; - charRangeInfo.range.startHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - charRangeInfo.range.endHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - if(incrementIndex == CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].servCount = 0u; - cy_ble_discovery[discIdx].charCount = 0u; - incrementIndex = CY_BLE_DISCOVERY_CONTINUE; - } - - /* Get a possible range of the common service: GATT */ - Cy_BLE_GATTC_GetCharRange(&charRangeInfo); - - /* Loop thru all registered services and get a possible range of the characteristic descriptor */ - (void)Cy_BLE_InvokeServiceEventHandler((uint32_t)CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE, (void*)&charRangeInfo); - - if((charRangeInfo.range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) || - (charRangeInfo.range.endHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_ble_discovery[discIdx].servCount++; - cy_ble_discovery[discIdx].charCount = 0u; - charRangeInfo.srviIncIdx = CY_BLE_DISCOVERY_INIT; - } - else - { - charRangeInfo.srviIncIdx = CY_BLE_DISCOVERY_CONTINUE; - } - - /* Skip not existing characteristics and characteristics out of discovery range */ - } - while(((charRangeInfo.range.startHandle <= cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle) || - (charRangeInfo.range.startHandle > cy_ble_discovery[discIdx].gattcDiscoveryRange.endHandle) || - (charRangeInfo.range.endHandle < cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle) || - (charRangeInfo.range.startHandle > charRangeInfo.range.endHandle)) && - (cy_ble_discovery[discIdx].servCount < (uint8_t)CY_BLE_SRVI_COUNT)); - - if(cy_ble_discovery[discIdx].servCount < (uint32_t)CY_BLE_SRVI_COUNT) - { - cy_stc_ble_gattc_find_info_req_t reqParam = - { - .connHandle = connHandle, - .range = charRangeInfo.range - }; - - if(Cy_BLE_GATTC_DiscoverCharacteristicDescriptors(&reqParam) != CY_BLE_SUCCESS) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DISCOVERY_FAILED, &connHandle); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - } - } - else /* Discovery done */ - { - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_DISCOVERED); - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DISCOVERY_COMPLETE, &connHandle); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 0u; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_LongProcedureEndEventHandler -***************************************************************************//** -* -* Handles a Long Procedure End event during an automatic server discovery -* process. -* -* \param connHandle: The connection handle. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_LongProcedureEndEventHandler(cy_stc_ble_conn_handle_t connHandle) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag != 0u)) - { - switch(Cy_BLE_GetConnectionState(connHandle)) - { - case CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING: - if((cy_ble_eventHandlerFlag & CY_BLE_ENABLE_ALL_EVENTS) != 0u) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_SRVC_DISCOVERY_COMPLETE, &connHandle); - } - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING); - Cy_BLE_NextInclDiscovery(connHandle, CY_BLE_DISCOVERY_INIT); - /* Do not propagate this event to the application level during an automatic discovery procedure */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - case CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING: - Cy_BLE_NextInclDiscovery(connHandle, CY_BLE_DISCOVERY_CONTINUE); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - case CY_BLE_CONN_STATE_CLIENT_CHAR_DISCOVERING: - Cy_BLE_NextCharDiscovery(connHandle, CY_BLE_DISCOVERY_CONTINUE); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - case CY_BLE_CONN_STATE_CLIENT_DESCR_DISCOVERING: - Cy_BLE_NextCharDscrDiscovery(connHandle, CY_BLE_DISCOVERY_CONTINUE); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - default: - break; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event during an automatic server discovery -* process. -* -* \param eventParam: The event parameters for an Error Response. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag != 0u) && - (eventParam->errInfo.errorCode == CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_LongProcedureEndEventHandler(eventParam->connHandle); - } -} - -#endif /* CY_BLE_GATT_ROLE_CLIENT */ -#endif /* defined(CY_BLE_MODE_PROFILE) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_event_handler.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_event_handler.h deleted file mode 100644 index 2c29e9d886..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_event_handler.h +++ /dev/null @@ -1,2583 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_event_handler.h -* \version 2.0 -* -* \brief -* Contains the prototypes and constants used in the Event Handler State Machine -* of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_EVENT_HANDLER_H -#define CY_BLE_EVENT_HANDLER_H - -#include "cy_ble_gatt.h" -#include "cy_ble_hal_pvt.h" -#include "flash/cy_flash.h" - -#if (CY_BLE_MODE_PROFILE) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Service specific includes -***************************************/ - -#ifdef CY_BLE_ANCS - #include "cy_ble_ancs.h" -#endif /* CY_BLE_ANCS */ -#ifdef CY_BLE_ANS - #include "cy_ble_ans.h" -#endif /* CY_BLE_ANS */ -#ifdef CY_BLE_AIOS - #include "cy_ble_aios.h" -#endif /* CY_BLE_AIOS */ -#ifdef CY_BLE_BAS - #include "cy_ble_bas.h" -#endif /* CY_BLE_BAS */ -#ifdef CY_BLE_BLS - #include "cy_ble_bls.h" -#endif /* CY_BLE_BLS */ -#ifdef CY_BLE_BCS - #include "cy_ble_bcs.h" -#endif /* CY_BLE_BCS */ -#ifdef CY_BLE_BMS - #include "cy_ble_bms.h" -#endif /* CY_BLE_BMS */ -#ifdef CY_BLE_BTS - #include "cy_ble_bts.h" -#endif /* CY_BLE_BTS */ -#ifdef CY_BLE_CGMS - #include "cy_ble_cgms.h" -#endif /* CY_BLE_CGMS */ -#ifdef CY_BLE_CPS - #include "cy_ble_cps.h" -#endif /* CY_BLE_CPS */ -#ifdef CY_BLE_CSCS - #include "cy_ble_cscs.h" -#endif /* CY_BLE_CSCS */ -#ifdef CY_BLE_CTS - #include "cy_ble_cts.h" -#endif /* CY_BLE_CTS */ -#ifdef CY_BLE_CUSTOM - #include "cy_ble_custom.h" -#endif /* CY_BLE_CUSTOM */ -#ifdef CY_BLE_DIS - #include "cy_ble_dis.h" -#endif /* CY_BLE_DIS */ -#ifdef CY_BLE_ESS - #include "cy_ble_ess.h" -#endif /* CY_BLE_ESS */ -#ifdef CY_BLE_GLS - #include "cy_ble_gls.h" -#endif /* CY_BLE_GLS */ -#ifdef CY_BLE_HIDS - #include "cy_ble_hids.h" -#endif /* CY_BLE_HIDS */ -#ifdef CY_BLE_HPS - #include "cy_ble_hps.h" -#endif /* CY_BLE_HPS */ -#ifdef CY_BLE_HRS - #include "cy_ble_hrs.h" -#endif /* CY_BLE_HRS */ -#ifdef CY_BLE_HTS - #include "cy_ble_hts.h" -#endif /* CY_BLE_HTS */ -#ifdef CY_BLE_IAS - #include "cy_ble_ias.h" -#endif /* CY_BLE_IAS */ -#ifdef CY_BLE_IPS - #include "cy_ble_ips.h" -#endif /* CY_BLE_IPS */ -#ifdef CY_BLE_LLS - #include "cy_ble_lls.h" -#endif /* CY_BLE_LLS */ -#ifdef CY_BLE_LNS - #include "cy_ble_lns.h" -#endif /* CY_BLE_LNS */ -#ifdef CY_BLE_NDCS - #include "cy_ble_ndcs.h" -#endif /* CY_BLE_NDCS */ -#ifdef CY_BLE_PASS - #include "cy_ble_pass.h" -#endif /* CY_BLE_PASS */ -#ifdef CY_BLE_PLXS - #include "cy_ble_plxs.h" -#endif /* CY_BLE_PLXS */ -#ifdef CY_BLE_RSCS - #include "cy_ble_rscs.h" -#endif /* CY_BLE_RSCS */ -#ifdef CY_BLE_RTUS - #include "cy_ble_rtus.h" -#endif /* CY_BLE_RTUS */ -#ifdef CY_BLE_SCPS - #include "cy_ble_scps.h" -#endif /* CY_BLE_SCPS */ -#ifdef CY_BLE_TPS - #include "cy_ble_tps.h" -#endif /* CY_BLE_TPS */ -#ifdef CY_BLE_UDS - #include "cy_ble_uds.h" -#endif /* CY_BLE_UDS */ -#ifdef CY_BLE_WPTS - #include "cy_ble_wpts.h" -#endif /* CY_BLE_WPTS */ -#ifdef CY_BLE_WSS - #include "cy_ble_wss.h" -#endif /* CY_BLE_WSS */ - - - -/*************************************** -* Definitions -***************************************/ -/* cy_ble_eventHandlerFlag defines */ -#define CY_BLE_CALLBACK (0x01u) -#define CY_BLE_AUTO_DISCOVERY (0x02u) -#define CY_BLE_START_FLAG (0x04u) -#define CY_BLE_STOP_FLAG (0x08u) -#define CY_BLE_ENABLE_ALL_EVENTS (0x10u) -#define CY_BLE_DISABLE_AUTOMATIC_AUTH (0x20u) - -#if (CY_BLE_GATT_ROLE_CLIENT) -#define CY_BLE_DISC_SRVC_INFO_LEN (4u + CY_BLE_GATT_16_BIT_UUID_SIZE) -#define CY_BLE_DISC_SRVC_INFO_128_LEN (4u + CY_BLE_GATT_128_BIT_UUID_SIZE) -#define CY_BLE_DISC_INCL_INFO_LEN (6u + CY_BLE_GATT_16_BIT_UUID_SIZE) -#define CY_BLE_DISC_INCL_INFO_128_LEN (6u) -#define CY_BLE_DISC_CHAR_INFO_LEN (5u + CY_BLE_GATT_16_BIT_UUID_SIZE) -#define CY_BLE_DISC_CHAR_INFO_128_LEN (5u + CY_BLE_GATT_128_BIT_UUID_SIZE) -#define CY_BLE_DISC_DESCR_INFO_LEN (2u + CY_BLE_GATT_16_BIT_UUID_SIZE) -#define CY_BLE_DISC_DESCR_INFO_128_LEN (2u + CY_BLE_GATT_128_BIT_UUID_SIZE) -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - -#define CY_BLE_LE_MASK_LENGTH (0x8u) -#define CY_BLE_LE_MASK_DEFAULT (0x003Fu) -#define CY_BLE_LE_MASK_DLE ((CY_BLE_DLE_FEATURE_ENABLED) ? (0x0040u) : (0u)) -#define CY_BLE_LE_MASK_SECURE_CONN ((CY_BLE_SECURE_CONN_FEATURE_ENABLED) ? (0x0180u) : (0u)) -#define CY_BLE_LE_MASK_LL_PRIVACY ((CY_BLE_LL_PRIVACY_FEATURE_ENABLED) ? (0x0600u) : (0u)) -#define CY_BLE_LE_MASK_PHY ((CY_BLE_PHY_UPDATE_FEATURE_ENABLED) ? (0x0800u) : (0u)) -#define CY_BLE_LE_MASK (CY_BLE_LE_MASK_DEFAULT | CY_BLE_LE_MASK_DLE | CY_BLE_LE_MASK_LL_PRIVACY \ - | CY_BLE_LE_MASK_SECURE_CONN | CY_BLE_LE_MASK_PHY) -/* Internal command run status defines */ -#define CY_BLE_STATUS_SET_TX_PWR_LVL (uint32_t)(1ul << 0u) - -/*************************************** -* Type Definitions -***************************************/ - -/** - * \addtogroup group_ble_service_api_events - * @{ - */ - - -/** Service specific events */ -typedef enum -{ - /**************************************** - * Security Events - ***************************************/ - /* \cond IGNORE */ - - CY_BLE_AUTHENTICATION_REQUEST_REPLY = CY_BLE_EVT_MAX + 1, /* 0x10000 */ - CY_BLE_PASSKEY_ENTRY_REQUEST_REPLY, - CY_BLE_LONG_TERM_KEY_REQUEST_REPLY, - CY_BLE_KEY_EXCHANGE_INFO_REQUEST_REPLY, - /* \endcond */ - - /**************************************** - * GATT Service Events - ***************************************/ - - /** GATT Server - This event indicates that the CCCD data CRC is wrong. - * If this event occurs, removing the bonding information of all devices - * by using the Cy_BLE_GAP_RemoveBondedDevice() API is recommended. - * The CCCD buffer in the RAM for the current connection is cleaned (set to zero) - * The event parameter is NULL. - */ - CY_BLE_EVT_GATTS_EVT_CCCD_CORRUPT, - - /** GATT Server - Indication for GATT Service's "Service Changed" - * Characteristic was enabled. The parameter of this event is a structure of - * cy_stc_ble_gatts_write_cmd_req_param_t type. - */ - CY_BLE_EVT_GATTS_INDICATION_ENABLED, - - /** GATT Server - Indication for GATT Service's "Service Changed" - * Characteristic was disabled. The parameter of this event is a structure of - * cy_stc_ble_gatts_write_cmd_req_param_t type. - */ - CY_BLE_EVT_GATTS_INDICATION_DISABLED, - - /** GATT Client - GATT Service's "Service Changed" Characteristic Indication - * was received. The parameter of this event is a structure - * of the cy_stc_ble_gattc_handle_value_ind_param_t type. - */ - CY_BLE_EVT_GATTC_INDICATION, - - - /**************************************** - * Service Discovery Events - ***************************************/ - - /** GATT Client - The Service discovery procedure failed. This event may - * be generated on calling Cy_BLE_GATTC_DiscoverPrimaryServices(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_SRVC_DISCOVERY_FAILED, - - /** GATT Client - The discovery of included services failed. This event may - * be generated on calling Cy_BLE_GATTC_FindIncludedServices(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_INCL_DISCOVERY_FAILED, - - /** GATT Client - The discovery of the service's characteristics failed. This event may - * be generated on calling Cy_BLE_GATTC_DiscoverCharacteristics() or - * Cy_BLE_GATTC_ReadUsingCharacteristicUuid(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_CHAR_DISCOVERY_FAILED, - - /** GATT Client - The discovery of the service's characteristics failed. This event may - * be generated on calling Cy_BLE_GATTC_DiscoverCharacteristicDescriptors(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_DESCR_DISCOVERY_FAILED, - - /** GATT Client - A duplicate service record was found during the server device - * discovery. The parameter of this event is a structure of cy_stc_ble_disc_srv_info_t - * type. - */ - CY_BLE_EVT_GATTC_SRVC_DUPLICATION, - - /** GATT Client - Duplicate service's characteristic record was found during - * server device discovery. The parameter of this event is a structure - * of cy_stc_ble_disc_char_info_t type. - */ - CY_BLE_EVT_GATTC_CHAR_DUPLICATION, - - /** GATT Client - A duplicate service's characteristic descriptor record was found - * during server device discovery. The parameter of this event is a structure - * of cy_stc_ble_disc_descr_info_t type. - */ - CY_BLE_EVT_GATTC_DESCR_DUPLICATION, - - /** GATT Client - The Service discovery procedure completed successfully. This - * event may be generated on calling Cy_BLE_GATTC_DiscoverPrimaryServices(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_SRVC_DISCOVERY_COMPLETE, - - /** GATT Client - The included services discovery is completed - * successfully. This event may be generated on calling - * Cy_BLE_GATTC_FindIncludedServices(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_INCL_DISCOVERY_COMPLETE, - - /** GATT Client - The discovery of service's characteristics discovery is completed - * successfully. This event may be generated on calling - * Cy_BLE_GATTC_DiscoverCharacteristics() or - * Cy_BLE_GATTC_ReadUsingCharacteristicUuid(). - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_CHAR_DISCOVERY_COMPLETE, - - /** GATT Client - The service (not defined in the GATT database) was found during - * the server device discovery. The discovery procedure skips this service. - * This event parameter is a structure of the cy_stc_ble_disc_srv_info_t type. - */ - CY_BLE_EVT_GATTC_DISC_SKIPPED_SERVICE, - - /** GATT Client - The discovery of a remote device completed successfully. - * The parameter of this event is a structure of the cy_stc_ble_conn_handle_t type. - */ - CY_BLE_EVT_GATTC_DISCOVERY_COMPLETE, - - /**************************************** - * AIOS Service Events - ***************************************/ - - /** AIOS Server - Notification for Automation Input Output Service Characteristic - * was enabled. The parameter of this event is a structure of - * cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_NOTIFICATION_ENABLED, - - /** AIOS Server - Notification for Automation Input Output Service Characteristic - * was disabled. The parameter of this event is a structure of - * cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_NOTIFICATION_DISABLED, - - /** AIOS Server - Indication for Automation Input Output Service Characteristic - * was enabled. The parameter of this event is a structure - * of cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_INDICATION_ENABLED, - - /** AIOSS Server - Indication for Automation Input Output Service Characteristic - * was disabled. The parameter of this event is a structure - * of cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_INDICATION_DISABLED, - - /** AIOS Server - Automation Input Output Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_INDICATION_CONFIRMED, - - /** AIOS Server - Write Request for Automation Input Output Service Characteristic - * was received. The parameter of this event is a structure - * of cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_WRITE_CHAR, - - /** AIOSS Server - Write Request for Automation Input Output Service - * Characteristic Descriptor was received. The parameter of this event is a structure of - * cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSS_DESCR_WRITE, - - /** AIOS Client - Automation Input Output Characteristic Service Notification - * was received. The parameter of this event is a structure - * of cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSC_NOTIFICATION, - - /** AIOS Client - Automation Input Output Service Characteristic - * Indication was received. The parameter of this event - * is a structure of cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSC_INDICATION, - - /** AIOS Client - Read Response for Read Request for Automation Input Output Service Characteristic - * Value. The parameter of this event is a structure of - * cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSC_READ_CHAR_RESPONSE, - - /** AIOS Client - Write Response for Write Request for Automation Input Output Service - * Characteristic Value. The parameter of this event is a structure of - * cy_stc_ble_aios_char_value_t type. - */ - CY_BLE_EVT_AIOSC_WRITE_CHAR_RESPONSE, - - /** AIOS Client - Read Response for Read Request for Automation Input Output Service - * Characteristic Descriptor Read Request. The parameter of this event is a - * structure of cy_stc_ble_aios_descr_value_t type. - */ - CY_BLE_EVT_AIOSC_READ_DESCR_RESPONSE, - - /** AIOS Client - Write Response for Write Request for Automation Input Output Service - * Client Characteristic Configuration Descriptor Value. The parameter of - * this event is a structure of cy_stc_ble_aios_descr_value_t type. - */ - CY_BLE_EVT_AIOSC_WRITE_DESCR_RESPONSE, - - /** AIOS Client - Error Response for Write Request for Automation Input Output Service - * Characteristic Value. The parameter of this event is a structure of - * cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_AIOSC_ERROR_RESPONSE, - - /**************************************** - * ANCS Service Events - ***************************************/ - - /** ANCS Server - Notification for Apple Notification Center Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_ANCSS_NOTIFICATION_ENABLED, - - /** ANCS Server - Notification for Apple Notification Center Service Characteristic - * was disabled. The parameter of this event is a structure of - * the cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_ANCSS_NOTIFICATION_DISABLED, - - /** ANCS Server - Write Request for Apple Notification Center Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_ANCSS_WRITE_CHAR, - - /** ANCS Client - Apple Notification Center Characteristic Service Notification - * was received. The parameter of this event is a structure - * of the cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_ANCSC_NOTIFICATION, - - /** ANCS Client - Write Response for Write Request for Apple Notification Center Service - * Characteristic Value. The parameter of this event is a structure of - * cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_ANCSC_WRITE_CHAR_RESPONSE, - - /** ANCS Client - Read Response for Read Request for Apple Notification Center Service - * Characteristic Descriptor Read Request. The parameter of this event is a - * structure of the cy_stc_ble_ancs_descr_value_t type. - */ - CY_BLE_EVT_ANCSC_READ_DESCR_RESPONSE, - - /** ANCS Client - Write Response for Write Request for Apple Notification Center Service - * Client Characteristic Configuration Descriptor Value. The parameter of - * this event is a structure of the cy_stc_ble_ancs_descr_value_t type. - */ - CY_BLE_EVT_ANCSC_WRITE_DESCR_RESPONSE, - - /** ANCS Client - Error Response for Write Request for Apple Notification Center Service - * Characteristic Value. The parameter of this event is a structure of - * the cy_stc_ble_ancs_char_value_t type. - */ - CY_BLE_EVT_ANCSC_ERROR_RESPONSE, - - - /**************************************** - * ANS Service Events - ***************************************/ - - /** ANS Server - Notification for Alert Notification Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_ans_char_value_t type. - */ - CY_BLE_EVT_ANSS_NOTIFICATION_ENABLED, - - /** ANS Server - Notification for Alert Notification Service Characteristic - * was disabled. The parameter of this event is a structure of - * the cy_stc_ble_ans_char_value_t type. - */ - CY_BLE_EVT_ANSS_NOTIFICATION_DISABLED, - - /** ANS Server - Write Request for Alert Notification Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_ans_char_value_t type. - */ - CY_BLE_EVT_ANSS_WRITE_CHAR, - - /** ANS Client - Alert Notification Characteristic Service Notification - * was received. The parameter of this event is a structure - * of the cy_stc_ble_ans_char_value_t type. - */ - CY_BLE_EVT_ANSC_NOTIFICATION, - - /** ANS Client - Read Response for Alert Notification Service Characteristic - * Value. The parameter of this event is a structure of - * the cy_stc_ble_ans_char_value_t type. - */ - CY_BLE_EVT_ANSC_READ_CHAR_RESPONSE, - - /** ANS Client - Write Response for Write Request for Alert Notification Service - * Characteristic Value. The parameter of this event is a structure of - * the cy_stc_ble_ans_char_value_t type. - */ - CY_BLE_EVT_ANSC_WRITE_CHAR_RESPONSE, - - /** ANS Client - Read Response for Read Request for Alert Notification Service - * Characteristic Descriptor Read Request. The parameter of this event is a - * structure of the cy_stc_ble_ans_descr_value_t type. - */ - CY_BLE_EVT_ANSC_READ_DESCR_RESPONSE, - - /** ANS Client - Write Response for Write Request for Alert Notification Service - * Client Characteristic Configuration Descriptor Value. The parameter of - * this event is a structure of the cy_stc_ble_ans_descr_value_t type. - */ - CY_BLE_EVT_ANSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * BAS Service Events - ***************************************/ - - /** BAS Server - Notification for Battery Level Characteristic was enabled. The - * parameter of this event is a structure of the cy_stc_ble_bas_char_value_t type. - */ - CY_BLE_EVT_BASS_NOTIFICATION_ENABLED, - - /** BAS Server - Notification for Battery Level Characteristic was disabled. The - * parameter of this event is a structure of the cy_stc_ble_bas_char_value_t type. - */ - CY_BLE_EVT_BASS_NOTIFICATION_DISABLED, - - /** BAS Client - Battery Level Characteristic Notification was received. The - * parameter of this event is a structure of the cy_stc_ble_bas_char_value_t type. - */ - CY_BLE_EVT_BASC_NOTIFICATION, - - /** BAS Client - Read Response for Battery Level Characteristic Value. The - * parameter of this event is a structure of the cy_stc_ble_bas_char_value_t type. - */ - CY_BLE_EVT_BASC_READ_CHAR_RESPONSE, - - /** BAS Client - Read Response for Battery Level Characteristic Descriptor Read - * Request. The parameter of this event is a structure of - * the cy_stc_ble_bas_descr_value_t type. - */ - CY_BLE_EVT_BASC_READ_DESCR_RESPONSE, - - /** BAS Client - Write Response for Battery Level Client Characteristic - * Configuration Descriptor Value. The parameter of this event is a structure of - * the cy_stc_ble_bas_descr_value_t type. - */ - CY_BLE_EVT_BASC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Body Composition Service Events - ***************************************/ - - /** BCS Server - Indication for Body Composition Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_bcs_char_value_t type. - */ - CY_BLE_EVT_BCSS_INDICATION_ENABLED, - - /** BCS Server - Indication for Body Composition Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_bcs_char_value_t type. - */ - CY_BLE_EVT_BCSS_INDICATION_DISABLED, - - /** BCS Server - Body Composition Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_bcs_char_value_t type. - */ - CY_BLE_EVT_BCSS_INDICATION_CONFIRMED, - - /** BCS Client - Body Composition Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_bcs_char_value_t type. - */ - CY_BLE_EVT_BCSC_INDICATION, - - /** BCS Client - Read Response for Read Request of Body Composition - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_bcs_char_value_t type. - */ - CY_BLE_EVT_BCSC_READ_CHAR_RESPONSE, - - /** BCS Client - Read Response for Read Request of Body Composition - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_bcs_descr_value_t type. - */ - CY_BLE_EVT_BCSC_READ_DESCR_RESPONSE, - - /** BCS Client - Write Response for Write Request of Body Composition - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_bcs_descr_value_t type. - */ - CY_BLE_EVT_BCSC_WRITE_DESCR_RESPONSE, - - /**************************************** - * Blood Pressure Service Events - ***************************************/ - - /** BLS Server - Indication for Blood Pressure Service Characteristic was enabled. - * The parameter of this event is a structure of the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSS_INDICATION_ENABLED, - - /** BLS Server - Indication for Blood Pressure Service Characteristic was - * disabled. The parameter of this event is a structure of - * the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSS_INDICATION_DISABLED, - - /** BLS Server - Blood Pressure Service Characteristic Indication was confirmed. - * The parameter of this event is a structure of cy_stc_ble_bls_char_value_t type - */ - CY_BLE_EVT_BLSS_INDICATION_CONFIRMED, - - /** BLS Server - Notification for Blood Pressure Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSS_NOTIFICATION_ENABLED, - - /** BLS Server - Notification for Blood Pressure Service Characteristic - * was disabled. The parameter of this event is a structure of - * the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSS_NOTIFICATION_DISABLED, - - /** BLS Client - Blood Pressure Service Characteristic Indication was received. - * The parameter of this event is a structure of the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSC_INDICATION, - - /** BLS Client - Blood Pressure Service Characteristic Notification was received. - * The parameter of this event is a structure of the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSC_NOTIFICATION, - - /** BLS Client - Read Response for Read Request of Blood Pressure Service - * Characteristic value. The parameter of this event is a structure of - * the cy_stc_ble_bls_char_value_t type. - */ - CY_BLE_EVT_BLSC_READ_CHAR_RESPONSE, - - /** BLS Client - Read Response for Read Request of Blood Pressure Service - * Characteristic Descriptor Read request. The parameter of this event is a - * structure of the cy_stc_ble_bls_descr_value_t type. - */ - CY_BLE_EVT_BLSC_READ_DESCR_RESPONSE, - - /** BLS Client - Write Response for Write Request of Blood Pressure Service - * Characteristic Configuration Descriptor value. The parameter of this event - * is a structure of the cy_stc_ble_bls_descr_value_t type. - */ - CY_BLE_EVT_BLSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Bond Management Service Events - ***************************************/ - - /** BMS Server - Write Request for Bond Management - * was received. The parameter of this event is a structure - * of the cy_stc_ble_bms_char_value_t type. - */ - CY_BLE_EVT_BMSS_WRITE_CHAR, - - /** BMS Client - Read Response for Read Request of Bond Management Service - * Characteristic value. The parameter of this event is a structure of - * the cy_stc_ble_bms_char_value_t type. - */ - CY_BLE_EVT_BMSC_READ_CHAR_RESPONSE, - - /** BMS Client - Write Response for Write Request of Bond Management - * Service Characteristic value. The - * parameter of this event is a structure of - * the cy_stc_ble_bms_char_value_t type. - */ - CY_BLE_EVT_BMSC_WRITE_CHAR_RESPONSE, - - /** BMS Client - Read Response for Read Request of Bond Management Service - * Characteristic Descriptor Read request. The parameter of this event is a - * structure of cy_stc_ble_bms_descr_value_t type. - */ - CY_BLE_EVT_BMSC_READ_DESCR_RESPONSE, - - - /**************************************** - * CGM Service Events - ***************************************/ - - /** CGMS Server - Indication for Continuous Glucose Monitoring Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSS_INDICATION_ENABLED, - - /** CGMS Server - Indication for Continuous Glucose Monitoring Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSS_INDICATION_DISABLED, - - /** CGMS Server - Continuous Glucose Monitoring Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSS_INDICATION_CONFIRMED, - - /** CGMS Server - Notification for Continuous Glucose Monitoring Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSS_NOTIFICATION_ENABLED, - - /** CGMS Server - Notification for Continuous Glucose Monitoring Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSS_NOTIFICATION_DISABLED, - - /** CGMS Server - Write Request for Continuous Glucose Monitoring Service - * was received. The parameter of this event is a structure - * of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSS_WRITE_CHAR, - - /** CGMS Client - Continuous Glucose Monitoring Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSC_INDICATION, - - /** CGMS Client - Continuous Glucose Monitoring Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSC_NOTIFICATION, - - /** CGMS Client - Read Response for Read Request of Continuous Glucose Monitoring - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSC_READ_CHAR_RESPONSE, - - /** CGMS Client - Write Response for Write Request of Continuous Glucose Monitoring - * Service Characteristic value. The - * parameter of this event is a structure of - * the cy_stc_ble_cgms_char_value_t type. - */ - CY_BLE_EVT_CGMSC_WRITE_CHAR_RESPONSE, - - /** CGMS Client - Read Response for Read Request of Continuous Glucose Monitoring - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_cgms_descr_value_t type. - */ - CY_BLE_EVT_CGMSC_READ_DESCR_RESPONSE, - - /** CGMS Client - Write Response for Write Request of Continuous Glucose Monitoring - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_cgms_descr_value_t type. - */ - CY_BLE_EVT_CGMSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * CPS Service Events - ***************************************/ - - /** CPS Server - Notification for Cycling Power Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_NOTIFICATION_ENABLED, - - /** CPS Server - Notification for Cycling Power Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_NOTIFICATION_DISABLED, - - /** CPS Server - Indication for Cycling Power Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_INDICATION_ENABLED, - - /** CPS Server - Indication for Cycling Power Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_INDICATION_DISABLED, - - /** CPS Server - Cycling Power Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_INDICATION_CONFIRMED, - - /** CPS Server - Broadcast for Cycling Power Service Characteristic - * was enabled. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_BROADCAST_ENABLED, - - /** CPS Server - Broadcast for Cycling Power Service Characteristic - * was disabled. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_BROADCAST_DISABLED, - - /** CPS Server - Write Request for Cycling Power Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSS_WRITE_CHAR, - - /** CPS Client - Cycling Power Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSC_NOTIFICATION, - - /** CPS Client - Cycling Power Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSC_INDICATION, - - /** CPS Client - Read Response for Read Request of Cycling Power Service - * Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSC_READ_CHAR_RESPONSE, - - /** CPS Client - Write Response for Write Request of Cycling Power Service - * Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSC_WRITE_CHAR_RESPONSE, - - /** CPS Client - Read Response for Read Request of Cycling Power - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_cps_descr_value_t type. - */ - CY_BLE_EVT_CPSC_READ_DESCR_RESPONSE, - - /** CPS Client - Write Response for Write Request of Cycling Power - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_cps_descr_value_t type. - */ - CY_BLE_EVT_CPSC_WRITE_DESCR_RESPONSE, - - /** CPS Client - This event is triggered every time a device receive - * non-connectable undirected advertising event. - * The parameter of this event is a structure of - * the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSC_SCAN_PROGRESS_RESULT, - - /** CPS Client - Cycling Power CP procedure timeout was received. The parameter - * of this event is a structure of the cy_stc_ble_cps_char_value_t type. - */ - CY_BLE_EVT_CPSC_TIMEOUT, - - /**************************************** - * Cycling Speed and Cadence Service Events - ***************************************/ - - /** CSCS Server - Notification for Cycling Speed and Cadence Service - * Characteristic was enabled. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSS_NOTIFICATION_ENABLED, - - /** CSCS Server - Notification for Cycling Speed and Cadence Service - * Characteristic was disabled. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSS_NOTIFICATION_DISABLED, - - /** CSCS Server - Indication for Cycling Speed and Cadence Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSS_INDICATION_ENABLED, - - /** CSCS Server - Indication for Cycling Speed and Cadence Service Characteristic - * was disabled. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSS_INDICATION_DISABLED, - - /** CSCS Server - Cycling Speed and Cadence Service Characteristic - * Indication was confirmed. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSS_INDICATION_CONFIRMATION, - - /** CSCS Server - Write Request for Cycling Speed and Cadence Service - * Characteristic was received. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSS_WRITE_CHAR, - - /** CSCS Client - Cycling Speed and Cadence Service Characteristic - * Notification was received. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSC_NOTIFICATION, - - /** CSCS Client - Cycling Speed and Cadence Service Characteristic - * Indication was received. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSC_INDICATION, - - /** CSCS Client - Read Response for Read Request of Cycling Speed and Cadence - * Service Characteristic value. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSC_READ_CHAR_RESPONSE, - - /** CSCS Client - Write Response for Write Request of Cycling Speed and Cadence - * Service Characteristic value. The parameter of this event is a structure of - * the cy_stc_ble_cscs_char_value_t type. - */ - CY_BLE_EVT_CSCSC_WRITE_CHAR_RESPONSE, - - /** CSCS Client - Read Response for Read Request of Cycling Speed and Cadence - * Service Characteristic Descriptor Read request. The parameter of this event - * is a structure of the cy_stc_ble_cscs_descr_value_t type. - */ - CY_BLE_EVT_CSCSC_READ_DESCR_RESPONSE, - - /** CSCS Client - Write Response for Write Request of Cycling Speed and Cadence - * Service Characteristic Configuration Descriptor value. The parameter of - * this event is a structure of the cy_stc_ble_cscs_descr_value_t type. - */ - CY_BLE_EVT_CSCSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Current Time Service Events - ***************************************/ - - /** CTS Server - Notification for Current Time Characteristic was enabled. The - * parameter of this event is a structure of the cy_stc_ble_cts_char_value_t type. - */ - CY_BLE_EVT_CTSS_NOTIFICATION_ENABLED, - - /** CTS Server - Notification for Current Time Characteristic was disabled. The - * parameter of this event is a structure of the cy_stc_ble_cts_char_value_t type. - */ - CY_BLE_EVT_CTSS_NOTIFICATION_DISABLED, - - /** CTS Server - Write Request for Current Time Service - * Characteristic was received. The parameter of this event is a structure of - * the cy_stc_ble_cts_char_value_t type. When this event is received, the user is - * responsible for performing any kind of data verification and writing the - * data to the GATT database in case of successful verification or setting - * the error using Cy_BLE_SetGattError() if data verification fails. - */ - CY_BLE_EVT_CTSS_WRITE_CHAR, - - /** CTS Client - Current Time Characteristic Notification was received. The - * parameter of this event is a structure of the cy_stc_ble_cts_char_value_t type. - */ - CY_BLE_EVT_CTSC_NOTIFICATION, - - /** CTS Client - Read Response for Current Time Characteristic - * Value Read Request. The parameter of this event is a - * structure of the cy_stc_ble_cts_char_value_t type. - */ - CY_BLE_EVT_CTSC_READ_CHAR_RESPONSE, - - /** CTS Client - Read Response for Current Time Client - * Characteristic Configuration Descriptor Value Read - * Request. The parameter of this event is a - * structure of the cy_stc_ble_cts_descr_value_t type. - */ - CY_BLE_EVT_CTSC_READ_DESCR_RESPONSE, - - /** CTS Client - Write Response for Current Time Characteristic - * Configuration Descriptor Value. The parameter of this - * event is a structure of the cy_stc_ble_cts_descr_value_t type. - */ - CY_BLE_EVT_CTSC_WRITE_DESCR_RESPONSE, - - /** CTS Client - Write Response for Current Time or Local - * Time Information Characteristic Value. The parameter of this - * event is a structure of the cy_stc_ble_cts_descr_value_t type. - */ - CY_BLE_EVT_CTSC_WRITE_CHAR_RESPONSE, - - /**************************************** - * DIS Service Events - ***************************************/ - - /** DIS Client - Read Response for a Read Request for a - * Device Information Service Characteristic. The parameter of this - * event is a structure of the cy_stc_ble_dis_char_value_t type. - */ - CY_BLE_EVT_DISC_READ_CHAR_RESPONSE, - - - /**************************************** - * Environmental Sensing Service Events - ***************************************/ - - /** ESS Server - Notification for Environmental Sensing Service - * Characteristic was enabled. The parameter of this event is a structure of - * cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSS_NOTIFICATION_ENABLED, - - /** ESS Server - Notification for Environmental Sensing Service - * Characteristic was disabled. The parameter of this event is a structure of - * cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSS_NOTIFICATION_DISABLED, - - /** ESS Server - Indication for Environmental Sensing Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSS_INDICATION_ENABLED, - - /** ESS Server - Indication for Environmental Sensing Service Characteristic - * was disabled. The parameter of this event is a structure of - * cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSS_INDICATION_DISABLED, - - /** ESS Server - Environmental Sensing Service Characteristic - * Indication was confirmed. The parameter of this event is a structure of - * cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSS_INDICATION_CONFIRMATION, - - /** ESS Server - Write Request for Environmental Sensing Service - * Characteristic was received. The parameter of this event is a structure of - * the cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSS_WRITE_CHAR, - - /** ESS Server - Write Request for Environmental Sensing Service - * Characteristic Descriptor was received. The parameter of this event is a structure of - * the cy_stc_ble_ess_descr_value_t type. This event is generated only when write for - * CY_BLE_ESS_CHAR_USER_DESCRIPTION_DESCR, CY_BLE_ESS_ES_TRIGGER_SETTINGS_DESCR or - * CY_BLE_ESS_ES_CONFIG_DESCR occurs. - */ - CY_BLE_EVT_ESSS_DESCR_WRITE, - - /** ESS Client - Environmental Sensing Service Characteristic - * Notification was received. The parameter of this event is a structure of - * the cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSC_NOTIFICATION, - - /** ESS Client - Environmental Sensing Service Characteristic - * Indication was received. The parameter of this event is a structure of - * cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSC_INDICATION, - - /** ESS Client - Read Response for Read Request of Environmental Sensing - * Service Characteristic value. The parameter of this event is a structure of - * the cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSC_READ_CHAR_RESPONSE, - - /** ESS Client - Write Response for Write Request of Environmental Sensing - * Service Characteristic value. The parameter of this event is a structure of - * the cy_stc_ble_ess_char_value_t type. - */ - CY_BLE_EVT_ESSC_WRITE_CHAR_RESPONSE, - - /** ESS Client - Read Response for Read Request of Environmental Sensing - * Service Characteristic Descriptor Read request. The parameter of this event - * is a structure of the cy_stc_ble_ess_descr_value_t type. - */ - CY_BLE_EVT_ESSC_READ_DESCR_RESPONSE, - - /** ESS Client - Write Response for Write Request of Environmental Sensing - * Service Characteristic Configuration Descriptor value. The parameter of - * this event is a structure of the cy_stc_ble_ess_descr_value_t type. - */ - CY_BLE_EVT_ESSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Glucose Service Events - ***************************************/ - - /** GLS Server - Indication for Glucose Service Characteristic - * was enabled. The parameter of this event is a structure - * of cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSS_INDICATION_ENABLED, - - /** GLS Server - Indication for Glucose Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSS_INDICATION_DISABLED, - - /** GLS Server - Glucose Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSS_INDICATION_CONFIRMED, - - /** GLS Server - Notification for Glucose Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSS_NOTIFICATION_ENABLED, - - /** GLS Server - Notification for Glucose Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSS_NOTIFICATION_DISABLED, - - /** GLS Server - Write Request for Glucose Service - * was received. The parameter of this event is a structure - * of cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSS_WRITE_CHAR, - - /** GLS Client - Glucose Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSC_INDICATION, - - /** GLS Client - Glucose Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSC_NOTIFICATION, - - /** GLS Client - Read Response for Read Request of Glucose - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSC_READ_CHAR_RESPONSE, - - /** GLS Client - Write Response for Write Request of Glucose - * Service Characteristic value. The - * parameter of this event is a structure of - * the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_GLSC_WRITE_CHAR_RESPONSE, - - /** GLS Client - Read Response for Read Request of Glucose - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_gls_descr_value_t type. - */ - CY_BLE_EVT_GLSC_READ_DESCR_RESPONSE, - - /** GLS Client - Write Response for Write Request of Glucose - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_gls_descr_value_t type. - */ - CY_BLE_EVT_GLSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * HIDS Service Events - ***************************************/ - - /** HIDS Server - Notification for HID service was - * enabled. The parameter of this event is a - * structure of the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_NOTIFICATION_ENABLED, - - /** HIDS Server - Notification for HID service was - * disabled. The parameter of this event is a - * structure of the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_NOTIFICATION_DISABLED, - - /** HIDS Server - Enter boot mode request. The - * parameter of this event is a structure of - * the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_BOOT_MODE_ENTER, - - /** HIDS Server - Enter report mode request. The - * parameter of this event is a structure of - * the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_REPORT_MODE_ENTER, - - /** HIDS Server - Enter suspend mode request. The - * parameter of this event is a structure of - * cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_SUSPEND, - - /** HIDS Server - Exit suspend mode request. The - * parameter of this event is a structure of - * the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_EXIT_SUSPEND, - - /** HIDS Server - Write Report Characteristic - * request. The parameter of this event is a - * structure of the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSS_REPORT_WRITE_CHAR, - - /** HIDS Client - HID Service Characteristic - * Notification was received. The parameter of this - * event is a structure of the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSC_NOTIFICATION, - - /** HIDS Client - Read Response for Read Request of HID - * Service Characteristic value. The parameter of this - * event is a structure of the cy_stc_ble_hids_descr_value_t type. - */ - CY_BLE_EVT_HIDSC_READ_CHAR_RESPONSE, - - /** HIDS Client - Write Response for Write Request of - * HID Service Characteristic value. The parameter - * of this event is a structure of - * the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSC_WRITE_CHAR_RESPONSE, - - /** HIDS Client - Read Response for Read Request of HID - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_hids_descr_value_t type. - */ - CY_BLE_EVT_HIDSC_READ_DESCR_RESPONSE, - - /** HIDS Client - Write Response for Write Request of HID - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_hids_char_value_t type. - */ - CY_BLE_EVT_HIDSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * HTTP Proxy Service Events - ***************************************/ - - /** HPS Server - Notification for HTTP Proxy Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_hps_char_value_t type. - */ - CY_BLE_EVT_HPSS_NOTIFICATION_ENABLED, - - /** HPS Server - Notification for HTTP Proxy Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_hps_char_value_t type. - */ - CY_BLE_EVT_HPSS_NOTIFICATION_DISABLED, - - /** HPS Server - Write Request for HTTP Proxy Service - * Characteristic was received. The parameter of this event is a structure of - * the cy_stc_ble_hps_char_value_t type. - */ - CY_BLE_EVT_HPSS_WRITE_CHAR, - - /** HPS Client - HTTP Proxy Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_hps_char_value_t type. - */ - CY_BLE_EVT_HPSC_NOTIFICATION, - - /** HPS Client - Read Response for Read Request of HTTP Proxy - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_hps_char_value_t type. - */ - CY_BLE_EVT_HPSC_READ_CHAR_RESPONSE, - - /** HPS Client - Read Response for Read Request of HTTP Proxy - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_hps_descr_value_t type. - */ - CY_BLE_EVT_HPSC_READ_DESCR_RESPONSE, - - /** HPS Client - Write Response for Write Request of HTTP Proxy - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_hps_descr_value_t type. - */ - CY_BLE_EVT_HPSC_WRITE_DESCR_RESPONSE, - - /** HPS Client - Write Response for Write Request of HPS - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_hps_char_value_t type. - */ - CY_BLE_EVT_HPSC_WRITE_CHAR_RESPONSE, - - /**************************************** - * HRS Service Events - ***************************************/ - - /** HRS Server - Reset Energy Expended. The parameter of - * this event is a structure of the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSS_ENERGY_EXPENDED_RESET, - - /** HRS Server - Notification for Heart Rate Measurement - * Characteristic was enabled. The parameter of this - * event is a structure of the cy_stc_ble_hrs_char_value_t type. - */ - - CY_BLE_EVT_HRSS_NOTIFICATION_ENABLED, - - /** HRS Server - Notification for Heart Rate Measurement - * Characteristic was disabled. The parameter of this - * event is a structure of the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSS_NOTIFICATION_DISABLED, - - /** HRS Client - Heart Rate Measurement Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSC_NOTIFICATION, - - /** HRS Client - Read Response for Read Request of HRS - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSC_READ_CHAR_RESPONSE, - - /** HRS Client - Write Response for Write Request of HRS - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSC_WRITE_CHAR_RESPONSE, - - /** HRS Client - Read Response for Read Request of HRS - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSC_READ_DESCR_RESPONSE, - - /** HRS Client - Write Response for Write Request of HRS - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_hrs_char_value_t type. - */ - CY_BLE_EVT_HRSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * HTS Service Events - ***************************************/ - - /** HTS Server - Notification for Health Thermometer Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSS_NOTIFICATION_ENABLED, - - /** HTS Server - Notification for Health Thermometer Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSS_NOTIFICATION_DISABLED, - - /** HTS Server - Indication for Health Thermometer Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSS_INDICATION_ENABLED, - - /** HTS Server - Indication for Health Thermometer Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSS_INDICATION_DISABLED, - - /** HTS Server - Health Thermometer Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSS_INDICATION_CONFIRMED, - - /** HTS Server - Write Request for Health Thermometer Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSS_WRITE_CHAR, - - /** HTS Client - Health Thermometer Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSC_NOTIFICATION, - - /** HTS Client - Health Thermometer Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSC_INDICATION, - - /** HTS Client - Read Response for Read Request of Health Thermometer - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSC_READ_CHAR_RESPONSE, - - /** HTS Client - Write Response for Write Request of Health Thermometer - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_hts_char_value_t type. - */ - CY_BLE_EVT_HTSC_WRITE_CHAR_RESPONSE, - - /** HTS Client - Read Response for Read Request of Health Thermometer - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_hts_descr_value_t type. - */ - CY_BLE_EVT_HTSC_READ_DESCR_RESPONSE, - - /** HTS Client - Write Response for Write Request of Health Thermometer - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_hts_descr_value_t type. - */ - CY_BLE_EVT_HTSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Immediate Alert Service Events - ***************************************/ - - /** IAS Server - Write Command Request for Alert Level - * Characteristic. The parameter of this event - * is a structure of the cy_stc_ble_ias_char_value_t type. - */ - CY_BLE_EVT_IASS_WRITE_CHAR_CMD, - - /**************************************** - * Indoor Positioning Service Events - ***************************************/ - - /** IPS Server - Read Request for Indoor Positioning Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSS_READ_CHAR, - - /** IPS Server - Write Request for Indoor Positioning Service Characteristic - * was received. The parameter of this event is a structure - * of cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSS_WRITE_CHAR, - - /** IPS Server - Write command request for Indoor Positioning Service - * Characteristic. The parameter of this event - * is a structure of the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSS_WRITE_CHAR_CMD, - - /** IPS Client - Read Response for Read Request of Indoor Positioning - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSC_READ_CHAR_RESPONSE, - - /** IPS Client - Read Multiple Response for Read Multiple Request of - * Indoor Positioning Service Characteristic value. The parameter - * of this event is a structure of the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSC_READ_MULTIPLE_CHAR_RESPONSE, - - /** IPS Client - Write Response for Write Request of Indoor Positioning - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSC_WRITE_CHAR_RESPONSE, - - /** IPS Client - Read Response for Read Request of Indoor Positioning - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_ips_descr_value_t type. - */ - CY_BLE_EVT_IPSC_READ_DESCR_RESPONSE, - - /** IPS Client - Write Response for Write Request of Indoor Positioning - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_ips_descr_value_t type. - */ - CY_BLE_EVT_IPSC_WRITE_DESCR_RESPONSE, - - /** IPS Client - Error Response for Write Request for Indoor Positioning - * Service Characteristic Value. The parameter of this event is a structure of - * the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSC_ERROR_RESPONSE, - - /** IPS Client - Read Response for Long Read Request of Indoor Positioning - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_ips_char_value_t type. - */ - CY_BLE_EVT_IPSC_READ_BLOB_RSP, - - /**************************************** - * Link Loss Service Events - ***************************************/ - - /** LLS Server - Write request for Alert Level Characteristic. - * The parameter of this event is a structure of - * the cy_stc_ble_lls_char_value_t type. - */ - CY_BLE_EVT_LLSS_WRITE_CHAR_REQ, - - /** LLS Client - Read response for Alert Level Characteristic. - * The parameter of this event is a structure of - * the cy_stc_ble_lls_char_value_t type. - */ - CY_BLE_EVT_LLSC_READ_CHAR_RESPONSE, - - /** LLS Client - Write response for write request of Alert - * Level Characteristic. The parameter of this event is a - * structure of the cy_stc_ble_lls_char_value_t type. - */ - CY_BLE_EVT_LLSC_WRITE_CHAR_RESPONSE, - - - /**************************************** - * Location and Navigation Service Events - ***************************************/ - - /** LNS Server - Indication for Location and Navigation Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSS_INDICATION_ENABLED, - - /** LNS Server - Indication for Location and Navigation Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSS_INDICATION_DISABLED, - - /** LNS Server - Location and Navigation Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSS_INDICATION_CONFIRMED, - - /** LNS Server - Notification for Location and Navigation Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSS_NOTIFICATION_ENABLED, - - /** LNS Server - Notification for Location and Navigation Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSS_NOTIFICATION_DISABLED, - - /** LNS Server - Write Request for Location and Navigation Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSS_WRITE_CHAR, - - /** LNS Client - Location and Navigation Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSC_INDICATION, - - /** LNS Client - Location and Navigation Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSC_NOTIFICATION, - - /** LNS Client - Read Response for Read Request of Location and Navigation - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSC_READ_CHAR_RESPONSE, - - /** LNS Client - Write Response for Write Request of Location and Navigation - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_lns_char_value_t type. - */ - CY_BLE_EVT_LNSC_WRITE_CHAR_RESPONSE, - - /** LNS Client - Read Response for Read Request of Location and Navigation - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_lns_descr_value_t type. - */ - CY_BLE_EVT_LNSC_READ_DESCR_RESPONSE, - - /** LNS Client - Write Response for Write Request of Location and Navigation - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_lns_descr_value_t type. - */ - CY_BLE_EVT_LNSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Next DST Change Service Events - ***************************************/ - - /** NDCS Client - Read Response for Read Request of Next DST Change - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_ndcs_char_value_t type. - */ - CY_BLE_EVT_NDCSC_READ_CHAR_RESPONSE, - - - /**************************************** - * Phone Alert Status Service Events - ***************************************/ - - /** PASS Server - Notification for Phone Alert Status Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_pass_char_value_t type. - */ - CY_BLE_EVT_PASSS_NOTIFICATION_ENABLED, - - /** PASS Server - Notification for Phone Alert Status Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_pass_char_value_t type. - */ - CY_BLE_EVT_PASSS_NOTIFICATION_DISABLED, - - /** PASS Server - Write Request for Phone Alert Status Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_pass_char_value_t type. - */ - CY_BLE_EVT_PASSS_WRITE_CHAR, - - /** PASS Client - Phone Alert Status Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_pass_char_value_t type. - */ - CY_BLE_EVT_PASSC_NOTIFICATION, - - /** PASS Client - Read Response for Read Request of Phone Alert Status - * Service Characteristic value. The parameter of this event - * is a structure of cy_stc_ble_pass_char_value_t type. - */ - CY_BLE_EVT_PASSC_READ_CHAR_RESPONSE, - - /** PASS Client - Read Response for Read Request of Phone Alert Status - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_pass_descr_value_t type. - */ - CY_BLE_EVT_PASSC_READ_DESCR_RESPONSE, - - /** PASS Client - Write Response for Write Request of Phone Alert Status - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_pass_descr_value_t type. - */ - CY_BLE_EVT_PASSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Pulse Oximeter Service Events - ***************************************/ - - /** PLXS Server - Indication for Pulse Oximeter Service Characteristic - * was enabled. The parameter of this event is a structure - * of cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSS_INDICATION_ENABLED, - - /** PLXS Server - Indication for Pulse Oximeter Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_gls_char_value_t type. - */ - CY_BLE_EVT_PLXSS_INDICATION_DISABLED, - - /** PLXS Server - Pulse Oximeter Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSS_INDICATION_CONFIRMED, - - /** PLXS Server - Notification for Pulse Oximeter Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSS_NOTIFICATION_ENABLED, - - /** PLXS Server - Notification for Pulse Oximeter Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSS_NOTIFICATION_DISABLED, - - /** PLXS Server - Write Request for Pulse Oximeter Service - * was received. The parameter of this event is a structure - * of cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSS_WRITE_CHAR, - - /** PLXS Client - Pulse Oximeter Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSC_INDICATION, - - /** PLXS Client - Pulse Oximeter Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSC_NOTIFICATION, - - /** PLXS Client - Read Response for Read Request of Pulse Oximeter - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSC_READ_CHAR_RESPONSE, - - /** PLXS Client - Write Response for Write Request of Pulse Oximeter - * Service Characteristic value. The - * parameter of this event is a structure of - * the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSC_WRITE_CHAR_RESPONSE, - - /** PLXS Client - Read Response for Read Request of Pulse Oximeter - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_plxs_descr_value_t type. - */ - CY_BLE_EVT_PLXSC_READ_DESCR_RESPONSE, - - /** PLXS Client - Write Response for Write Request of Pulse Oximeter - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_plxs_descr_value_t type. - */ - CY_BLE_EVT_PLXSC_WRITE_DESCR_RESPONSE, - - /** PLXS Client - PLX RACP procedure timeout was received. The parameter - * of this event is a structure of the cy_stc_ble_plxs_char_value_t type. - */ - CY_BLE_EVT_PLXSC_TIMEOUT, - - /**************************************** - * Running Speed and Cadence Service Events - ***************************************/ - - /** RSCS Server - Notification for Running Speed and Cadence Service - * Characteristic was enabled. The parameter of this event is a structure of - * the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSS_NOTIFICATION_ENABLED, - - /** RSCS Server - Notification for Running Speed and Cadence Service - * Characteristic was disabled. The parameter of this event is a structure - * of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSS_NOTIFICATION_DISABLED, - - /** RSCS Server - Indication for Running Speed and Cadence Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSS_INDICATION_ENABLED, - - /** RSCS Server - Indication for Running Speed and Cadence Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSS_INDICATION_DISABLED, - - /** RSCS Server - Running Speed and Cadence Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSS_INDICATION_CONFIRMATION, - - /** RSCS Server - Write Request for Running Speed and Cadence Service - * Characteristic was received. The parameter of this event is a structure - * of cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSS_WRITE_CHAR, - - /** RSCS Client - Running Speed and Cadence Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSC_NOTIFICATION, - - /** RSCS Client - Running Speed and Cadence Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSC_INDICATION, - - /** RSCS Client - Read Response for Read Request of Running Speed and Cadence - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSC_READ_CHAR_RESPONSE, - - /** RSCS Client - Write Response for Write Request of Running Speed and Cadence - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_rscs_char_value_t type. - */ - CY_BLE_EVT_RSCSC_WRITE_CHAR_RESPONSE, - - /** RSCS Client - Read Response for Read Request of Running Speed and Cadence - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_rscs_descr_value_t type. - */ - CY_BLE_EVT_RSCSC_READ_DESCR_RESPONSE, - - /** RSCS Client - Write Response for Write Request of Running Speed and Cadence - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_rscs_descr_value_t type. - */ - CY_BLE_EVT_RSCSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Reference Time Update Service Events - ***************************************/ - - /** RTUS Server - Write command request for Reference Time Update - * Characteristic value. The parameter of this event - * is a structure of cy_stc_ble_rtus_char_value_t type. - */ - CY_BLE_EVT_RTUSS_WRITE_CHAR_CMD, - - /** RTUS Client - Read Response for Read Request of Reference Time Update - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_rtus_char_value_t type. - */ - CY_BLE_EVT_RTUSC_READ_CHAR_RESPONSE, - - - /**************************************** - * Scan Parameters Service Events - ***************************************/ - - /** ScPS Server - Notification for Scan Refresh Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_scps_char_value_t type. - */ - CY_BLE_EVT_SCPSS_NOTIFICATION_ENABLED, - - /** ScPS Server - Notification for Scan Refresh Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_scps_char_value_t type. - */ - CY_BLE_EVT_SCPSS_NOTIFICATION_DISABLED, - - /** ScPS Client - Read Response for Scan Interval Window - * Characteristic Value of Scan Parameters Service. The - * parameter of this event is a structure - * of the cy_stc_ble_scps_char_value_t type. - */ - CY_BLE_EVT_SCPSS_SCAN_INT_WIN_WRITE_CHAR, - - /** ScPS Client - Scan Refresh Characteristic Notification - * was received. The parameter of this event is a - * structure of the cy_stc_ble_scps_char_value_t type. - */ - CY_BLE_EVT_SCPSC_NOTIFICATION, - - /** ScPS Client - Read Response for Scan Refresh Characteristic - * Descriptor Read Request. The parameter of this event is a - * structure of the cy_stc_ble_scps_descr_value_t type. - */ - CY_BLE_EVT_SCPSC_READ_DESCR_RESPONSE, - - /** ScPS Client - Write Response for Scan Refresh Client - * Characteristic Configuration Descriptor Value. The - * parameter of this event is a structure of - * the cy_stc_ble_scps_descr_value_t type. - */ - CY_BLE_EVT_SCPSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Tx Power Service Events - ***************************************/ - - /** TPS Server - Notification for Tx Power Level Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_tps_char_value_t type. - */ - CY_BLE_EVT_TPSS_NOTIFICATION_ENABLED, - - /** TPS Server - Notification for Tx Power Level Characteristic - * was disabled. The parameter of this event is a structure of - * the cy_stc_ble_tps_char_value_t type. - */ - CY_BLE_EVT_TPSS_NOTIFICATION_DISABLED, - - /** TPS Client - Tx Power Level Characteristic Notification. - * The parameter of this event is a structure of - * the cy_stc_ble_tps_char_value_t type. - */ - CY_BLE_EVT_TPSC_NOTIFICATION, - - /** TPS Client - Read Response for Tx Power Level Characteristic - * Value Read Request. The parameter of this event is a - * structure of the cy_stc_ble_tps_char_value_t type. - */ - CY_BLE_EVT_TPSC_READ_CHAR_RESPONSE, - - /** TPS Client - Read Response for Tx Power Level Client - * Characteristic Configuration Descriptor Value Read Request. - * The parameter of this event is a structure of - * the cy_stc_ble_tps_descr_value_t type. - */ - CY_BLE_EVT_TPSC_READ_DESCR_RESPONSE, - - /** TPS Client - Write Response for Tx Power Level Characteristic - * Descriptor Value Write Request. The parameter of this event - * is a structure of the cy_stc_ble_tps_descr_value_t type. - */ - CY_BLE_EVT_TPSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * User Data Service Events - ***************************************/ - - /** UDS Server - Indication for User Data Service Characteristic - * was enabled. The parameter of this event is a structure - * of cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_INDICATION_ENABLED, - - /** UDS Server - Indication for User Data Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_INDICATION_DISABLED, - - /** UDS Server - User Data Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_INDICATION_CONFIRMED, - - /** UDS Server - Notification for User Data Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_NOTIFICATION_ENABLED, - - /** UDS Server - Notification for User Data Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_NOTIFICATION_DISABLED, - - /** UDS Server - Read Request for User Data Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_READ_CHAR, - - /** UDS Server - Write Request for User Data Service Characteristic - * was received. The parameter of this event is a structure - * of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSS_WRITE_CHAR, - - /** UDS Client - User Data Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSC_INDICATION, - - /** UDS Client - User Data Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSC_NOTIFICATION, - - /** UDS Client - Read Response for Read Request of User Data - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSC_READ_CHAR_RESPONSE, - - /** UDS Client - Write Response for Write Request of User Data - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSC_WRITE_CHAR_RESPONSE, - - /** UDS Client - Read Response for Read Request of User Data - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_uds_descr_value_t type. - */ - CY_BLE_EVT_UDSC_READ_DESCR_RESPONSE, - - /** UDS Client - Write Response for Write Request of User Data - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_uds_descr_value_t type. - */ - CY_BLE_EVT_UDSC_WRITE_DESCR_RESPONSE, - - /** UDS Client - Error Response for Write Request for User Data Service - * Characteristic Value. The parameter of this event is a structure of - * the cy_stc_ble_uds_char_value_t type. - */ - CY_BLE_EVT_UDSC_ERROR_RESPONSE, - - - /**************************************** - * Wireless Power Transfer Service Events - ****************************************/ - - /** WPTS Server - Notification for Wireless Power Transfer Service Characteristic - * was enabled. The parameter of this event is a structure of - * the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSS_NOTIFICATION_ENABLED, - - /** WPTS Server - Notification for Wireless Power Transfer Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSS_NOTIFICATION_DISABLED, - - /** WPTS Server - Indication for Wireless Power Transfer Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSS_INDICATION_ENABLED, - - /** WPTS Server - Indication for Wireless Power Transfer Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSS_INDICATION_DISABLED, - - /** WPTS Server - Wireless Power Transfer Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSS_INDICATION_CONFIRMED, - - /** WPTS Server - Write Request for Wireless Power Transfer Service Characteristic - * was received. The parameter of this event is a structure - * of cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSS_WRITE_CHAR, - - /** WPTS Client - Wireless Power Transfer Service Characteristic - * Notification was received. The parameter of this event - * is a structure of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSC_NOTIFICATION, - - /** WPTS Client - Wireless Power Transfer Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSC_INDICATION, - - /** WPTS Client - Write Response for Read Request of Wireless Power Transfer - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSC_WRITE_CHAR_RESPONSE, - - /** WPTS Client - Read Response for Read Request of Wireless Power Transfer - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_wpts_char_value_t type. - */ - CY_BLE_EVT_WPTSC_READ_CHAR_RESPONSE, - - /** WPTS Client - Read Response for Read Request of Wireless Power Transfer - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * the cy_stc_ble_wpts_descr_value_t type. - */ - CY_BLE_EVT_WPTSC_READ_DESCR_RESPONSE, - - /** WPTS Client - Write Response for Write Request of Wireless Power Transfer - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_wpts_descr_value_t type. - */ - CY_BLE_EVT_WPTSC_WRITE_DESCR_RESPONSE, - - - /**************************************** - * Weight Scale Service Events - ****************************************/ - - /** WSS Server - Indication for Weight Scale Service Characteristic - * was enabled. The parameter of this event is a structure - * of the cy_stc_ble_wss_char_value_t type. - */ - CY_BLE_EVT_WSSS_INDICATION_ENABLED, - - /** WSS Server - Indication for Weight Scale Service Characteristic - * was disabled. The parameter of this event is a structure - * of the cy_stc_ble_wss_char_value_t type. - */ - CY_BLE_EVT_WSSS_INDICATION_DISABLED, - - /** WSS Server - Weight Scale Service Characteristic - * Indication was confirmed. The parameter of this event - * is a structure of the cy_stc_ble_wss_char_value_t type. - */ - CY_BLE_EVT_WSSS_INDICATION_CONFIRMED, - - /** WSS Client - Weight Scale Service Characteristic - * Indication was received. The parameter of this event - * is a structure of the cy_stc_ble_wss_char_value_t type. - */ - CY_BLE_EVT_WSSC_INDICATION, - /** WSS Client - Read Response for Read Request of Weight Scale - * Service Characteristic value. The parameter of this event - * is a structure of the cy_stc_ble_wss_char_value_t type. - */ - CY_BLE_EVT_WSSC_READ_CHAR_RESPONSE, - - /** WSS Client - Read Response for Read Request of Weight Scale - * Service Characteristic Descriptor Read request. The - * parameter of this event is a structure of - * cy_stc_ble_wss_descr_value_t type. - */ - CY_BLE_EVT_WSSC_READ_DESCR_RESPONSE, - - /** WSS Client - Write Response for Write Request of Weight Scale - * Service Characteristic Configuration Descriptor value. - * The parameter of this event is a structure of - * the cy_stc_ble_wss_descr_value_t type. - */ - CY_BLE_EVT_WSSC_WRITE_DESCR_RESPONSE, - - /**************************************** - * Bootloader Service Events - ****************************************/ - /** BT Server - Notification for Bootloader Service Characteristic - * was enabled. - */ - CY_BLE_EVT_BTSS_NOTIFICATION_ENABLED, - - /** BT Server - Notification for Bootloader Service Characteristic - * was disabled. - */ - CY_BLE_EVT_BTSS_NOTIFICATION_DISABLED, - /** BT Server - Write Request event for the Bootloader Service Characteristic. - * The parameter of this event is a structure of the cy_stc_ble_bts_char_value_t type. - */ - CY_BLE_EVT_BTSS_WRITE_REQ, - /** BT Server - Write Without Response Request event for the Bootloader Service Characteristic. - * The parameter of this event is a structure of the cy_stc_ble_bts_char_value_t type. - */ - CY_BLE_EVT_BTSS_WRITE_CMD_REQ, - /** Send Prepare Write Response that identifies acknowledgement for - * long characteristic value write. The parameter of this event is a structure of - * the cy_stc_ble_gatts_prep_write_req_param_t type. - */ - CY_BLE_EVT_BTSS_PREP_WRITE_REQ, - - /** Execute Write Request for Bootloader Service - * Characteristic was received. The parameter of this event is a structure of - * the cy_stc_ble_gatts_exec_write_req_t type. - */ - CY_BLE_EVT_BTSS_EXEC_WRITE_REQ, - - - /**************************************** - * Discovery Procedure Events - ***************************************/ - - /** Discovery Services Event. The parameter of this event is a structure of - * the cy_stc_ble_disc_srv_info_t type. - */ - CY_BLE_EVT_GATTC_DISC_SERVICE, - - /** Discovery Includes Event. The parameter of this event is a structure of - * the cy_stc_ble_disc_incl_info_t type. - */ - CY_BLE_EVT_GATTC_DISC_INCL, - - /** Discovery Characteristic Event. The parameter of this event is a structure of - * the cy_stc_ble_disc_char_info_t type. - */ - CY_BLE_EVT_GATTC_DISC_CHAR, - - /** Discovery Descriptors Event. The parameter of this event is a structure of - * the cy_stc_ble_disc_descr_info_t type. - */ - CY_BLE_EVT_GATTC_DISC_DESCR, - - /** Event for run a procedure which returns a possible range of the current - * characteristic descriptor. The parameter of this event is a structure - * of the cy_stc_ble_disc_range_info_t type. - */ - CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE -}cy_en_ble_evt_t; - -/** @} group_service_api_events */ - -#if (CY_BLE_GATT_ROLE_CLIENT) - - -/** Service indexes (SRVI) */ -typedef enum -{ - CY_BLE_SRVI_GAP, - CY_BLE_SRVI_GATT, - -#ifdef CY_BLE_ANCS_CLIENT - CY_BLE_SRVI_ANCS, -#endif /* CY_BLE_ANCS_CLIENT */ -#ifdef CY_BLE_ANS_CLIENT - CY_BLE_SRVI_ANS, -#endif /* CY_BLE_ANS_CLIENT */ -#ifdef CY_BLE_AIOS_CLIENT - CY_BLE_SRVI_AIOS, -#endif /* CY_BLE_AIOS_CLIENT */ -#ifdef CY_BLE_BAS_CLIENT - CY_BLE_SRVI_BAS, - CY_BLE_SRVI_BAS_END = (uint8_t)(CY_BLE_SRVI_BAS) + CY_BLE_BASC_SERVICE_COUNT - 1u, -#endif /* CY_BLE_BAS_CLIENT */ -#ifdef CY_BLE_BCS_CLIENT - CY_BLE_SRVI_BCS, -#endif /* CY_BLE_BCS_CLIENT */ -#ifdef CY_BLE_BLS_CLIENT - CY_BLE_SRVI_BLS, -#endif /* CY_BLE_BLS_CLIENT */ -#ifdef CY_BLE_BMS_CLIENT - CY_BLE_SRVI_BMS, -#endif /* CY_BLE_BMS_CLIENT */ -#ifdef CY_BLE_CGMS_CLIENT - CY_BLE_SRVI_CGMS, -#endif /* CY_BLE_CGMS_CLIENT */ -#ifdef CY_BLE_CPS_CLIENT - CY_BLE_SRVI_CPS, -#endif /* CY_BLE_CPS_CLIENT */ -#ifdef CY_BLE_CSCS_CLIENT - CY_BLE_SRVI_CSCS, -#endif /* CY_BLE_CSCS_CLIENT */ -#ifdef CY_BLE_CTS_CLIENT - CY_BLE_SRVI_CTS, -#endif /* CY_BLE_CTS_CLIENT */ -#ifdef CY_BLE_CUSTOM_CLIENT - CY_BLE_SRVI_CUSTOMS, - CY_BLE_SRVI_CUSTOMS_END =(uint8_t)(CY_BLE_SRVI_CUSTOMS )+ CY_BLE_CUSTOMC_SERVICE_COUNT - 1u, -#endif /* CY_BLE_CUSTOM_CLIENT */ -#ifdef CY_BLE_DIS_CLIENT - CY_BLE_SRVI_DIS, -#endif /* CY_BLE_DIS_CLIENT */ -#ifdef CY_BLE_ESS_CLIENT - CY_BLE_SRVI_ESS, -#endif /* CY_BLE_ESS_CLIENT */ -#ifdef CY_BLE_GLS_CLIENT - CY_BLE_SRVI_GLS, -#endif /* CY_BLE_GLS_CLIENT */ -#ifdef CY_BLE_HIDS_CLIENT - CY_BLE_SRVI_HIDS, - CY_BLE_SRVI_HIDS_END = (uint8_t)(CY_BLE_SRVI_HIDS )+ CY_BLE_HIDSC_SERVICE_COUNT - 1u, -#endif /* CY_BLE_HIDS_CLIENT */ -#ifdef CY_BLE_HPS_CLIENT - CY_BLE_SRVI_HPS, -#endif /* CY_BLE_HPS_CLIENT */ -#ifdef CY_BLE_HRS_CLIENT - CY_BLE_SRVI_HRS, -#endif /* CY_BLE_HRS_CLIENT */ -#ifdef CY_BLE_HTS_CLIENT - CY_BLE_SRVI_HTS, -#endif /* CY_BLE_HTS_CLIENT */ -#ifdef CY_BLE_IAS_CLIENT - CY_BLE_SRVI_IAS, -#endif /* CY_BLE_IAS_CLIENT */ -#ifdef CY_BLE_IPS_CLIENT - CY_BLE_SRVI_IPS, -#endif /* CY_BLE_IPS_CLIENT */ -#ifdef CY_BLE_LLS_CLIENT - CY_BLE_SRVI_LLS, -#endif /* CY_BLE_LLS_CLIENT */ -#ifdef CY_BLE_LNS_CLIENT - CY_BLE_SRVI_LNS, -#endif /* CY_BLE_LNS_CLIENT */ -#ifdef CY_BLE_NDCS_CLIENT - CY_BLE_SRVI_NDCS, -#endif /* CY_BLE_NDCS_CLIENT */ -#ifdef CY_BLE_IPSS_CLIENT - CY_BLE_SRVI_IPSS, -#endif /* CY_BLE_IPSS_CLIENT */ -#ifdef CY_BLE_PASS_CLIENT - CY_BLE_SRVI_PASS, -#endif /* CY_BLE_PASS_CLIENT */ -#ifdef CY_BLE_PLXS_CLIENT - CY_BLE_SRVI_PLXS, -#endif /* CY_BLE_PLXS_CLIENT */ -#ifdef CY_BLE_RSCS_CLIENT - CY_BLE_SRVI_RSCS, -#endif /* CY_BLE_RSCS_CLIENT */ -#ifdef CY_BLE_RTUS_CLIENT - CY_BLE_SRVI_RTUS, -#endif /* CY_BLE_RTUS_CLIENT */ -#ifdef CY_BLE_SCPS_CLIENT - CY_BLE_SRVI_SCPS, -#endif /* CY_BLE_SCPS_CLIENT */ -#ifdef CY_BLE_TPS_CLIENT - CY_BLE_SRVI_TPS, -#endif /* CY_BLE_TPS_CLIENT */ -#ifdef CY_BLE_UDS_CLIENT - CY_BLE_SRVI_UDS, -#endif /* CY_BLE_UDS_CLIENT */ -#ifdef CY_BLE_WPTS_CLIENT - CY_BLE_SRVI_WPTS, -#endif /* CY_BLE_WPTS_CLIENT */ -#ifdef CY_BLE_WSS_CLIENT - CY_BLE_SRVI_WSS, -#endif /* CY_BLE_WSS_CLIENT */ - CY_BLE_SRVI_COUNT /**< Total count of services */ -}cy_en_ble_srvi_t; - -/** Discovery information structure type */ -typedef struct -{ - /** AUTO DISCOVERY flag */ - uint8_t autoDiscoveryFlag; - - /** Counter for discovery procedures */ - uint32_t servCount; - - /** Characteristic Counter for discovery procedures */ - uint32_t charCount; - - /** Discovery included service information, used for 128-bit UUID read response handle - * and for continue discovery. - */ - cy_stc_ble_disc_incl_info_t inclInfo; - - /** GAP Service characteristics server's GATT DB handles structure */ - cy_stc_ble_gapc_t gapc; - - /** GATT Service characteristics server's GATT DB handles structure */ - cy_stc_ble_gattc_t gattc; - - /** GATT Attribute Handle Range type */ - cy_stc_ble_gatt_attr_handle_range_t gattcDiscoveryRange; - - /** Peer device handle index */ - uint32_t connIndex; -}cy_stc_ble_discovery_t; - - -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - -/*************************************** -* Registration Callback -***************************************/ - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) -typedef cy_en_ble_gatt_err_code_t (* cy_ble_event_handle_t) (uint32_t eventCode, void *eventParam); - -/** Registration Service's Event Handler structure type */ -typedef struct -{ - /** The array for storing reference to the service's event handler procedure. */ - cy_ble_event_handle_t serviceEventHandler[CY_BLE_MAX_SRVI]; - - /** Count of functions in the array */ - uint8_t count; -} cy_stc_ble_event_handler_t; - -/* using: cy_ble_eventHandler.serviceEventHandler(eventCode, eventParam); */ - -/* Registration Service's Event Handler functions */ -cy_en_ble_api_result_t Cy_BLE_RegisterServiceEventHandler(cy_ble_event_handle_t eventHandlerFunc); -cy_en_ble_gatt_err_code_t Cy_BLE_InvokeServiceEventHandler(uint32_t eventCode, void *eventParam); - -extern cy_stc_ble_event_handler_t cy_ble_eventHandler; -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL*/ - - -/*************************************** -* Function Prototypes -***************************************/ - -/* Event Handler functions */ -void Cy_BLE_EventHandler(cy_en_ble_event_t event, void *evParam); -void Cy_BLE_ReadByGroupEventHandler(cy_stc_ble_gattc_read_by_grp_rsp_param_t *eventParam); -void Cy_BLE_ReadByTypeEventHandler(cy_stc_ble_gattc_read_by_type_rsp_param_t *eventParam); -void Cy_BLE_FindInfoEventHandler(cy_stc_ble_gattc_find_info_rsp_param_t *eventParam); -void Cy_BLE_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -void Cy_BLE_LongProcedureEndEventHandler(cy_stc_ble_conn_handle_t connHandle); -void Cy_BLE_NextInclDiscovery(cy_stc_ble_conn_handle_t connHandle, uint8_t incrementIndex); -void Cy_BLE_NextCharDiscovery(cy_stc_ble_conn_handle_t connHandle, uint8_t incrementIndex); -void Cy_BLE_NextCharDscrDiscovery(cy_stc_ble_conn_handle_t connHandle, uint8_t incrementIndex); - -/*************************************** -* External data references -***************************************/ - -extern volatile uint8_t cy_ble_busyStatus[CY_BLE_CONN_COUNT]; -extern volatile uint32_t cy_ble_cmdStatus; - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) -extern uint8_t cy_ble_advertisingIntervalType; -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) -extern uint8_t cy_ble_scanningIntervalType; -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER */ - -#if (CY_BLE_GATT_ROLE_CLIENT) -extern cy_stc_ble_discovery_t cy_ble_discovery[CY_BLE_CONFIG_GATTC_COUNT]; -extern cy_stc_ble_disc_srvc_info_t cy_ble_serverInfo[CY_BLE_CONFIG_GATTC_COUNT][CY_BLE_SRVI_COUNT]; -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - -/** - * \addtogroup group_ble_common_api_gatt_functions - * @{ - */ - -/****************************************************************************** -* Function Name: Cy_BLE_GATT_GetBusyStatus -***************************************************************************//** -* -* This function returns a status of the BLE stack (busy or not busy). -* The status is changed after the CY_BLE_EVT_STACK_BUSY_STATUS event. -* -* \param attId: Identifies the active ATT connection Instance. -* -* \return -* uint8_t: The busy status. -* * CY_BLE_STACK_STATE_BUSY - The BLE stack is busy. -* * CY_BLE_STACK_STATE_FREE - The BLE stack is not busy. -* -******************************************************************************/ -#define Cy_BLE_GATT_GetBusyStatus(attId) (cy_ble_busyStatus[attId]) -/** @} group_ble_common_api_gatt_functions */ - -/** - * \addtogroup group_ble_common_api_functions - * @{ - */ - -/** \cond IGNORE */ -/** Macro to check the characteristic handle */ -#define CY_BLE_GapcCheckCharHandle(handle, discCharInfo) \ - do { \ - if((handle) == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \ - { \ - (handle) = (discCharInfo)->valueHandle; \ - } \ - else \ - { \ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \ - &(discCharInfo)); \ - } \ - } while(0) - -/** Macro to check and store the characteristic handle */ -#define Cy_BLE_CheckStoreCharHandle(handle) \ - do { \ - if((handle).valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \ - { \ - (handle).valueHandle = discCharInfo->valueHandle; \ - (handle).properties = discCharInfo->properties; \ - } \ - else \ - { \ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \ - &discCharInfo); \ - } \ - } while(0) - -/** Macro to check and store the characteristic descriptor handle */ -#define Cy_BLE_CheckStoreCharDescrHandle(handle) \ - do { \ - if((handle) == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \ - { \ - (handle) = discDescrInfo->descrHandle; \ - } \ - else \ - { \ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \ - &discDescrInfo); \ - } \ - } while(0) - - -/****************************************************************************** -* Function Name: Cy_BLE_Get16ByPtr -***************************************************************************//** -* -* Returns the two-bytes value by using a pointer to the LSB. -* -* \param ptr: Pointer to the LSB of two-bytes data (little-endian). -* -* \return -* uint16_t: Two-bytes data. -* -******************************************************************************/ -__STATIC_INLINE uint16_t Cy_BLE_Get16ByPtr(const uint8_t ptr[]) -{ - return((uint16_t)ptr[0u] | ((uint16_t)(((uint16_t)ptr[1u]) << 8u))); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_Set16ByPtr -***************************************************************************//** -* -* Sets the two-bytes value by using a pointer to the LSB. -* -* \param ptr: Pointer to the LSB of two-bytes data (little-endian). -* \param value: Two-bytes data to be written. -* -* \return -* None -* -******************************************************************************/ -__STATIC_INLINE void Cy_BLE_Set16ByPtr(uint8_t ptr[], - uint16_t value) -{ - ptr[0u] = (uint8_t)value; - ptr[1u] = (uint8_t)(value >> 8u); -} - -/****************************************************************************** -* Function Name: Cy_BLE_Get24ByPtr -***************************************************************************//** -* -* Returns the three-bytes value by using a pointer to the LSB. -* -* \param ptr: Pointer to the LSB of two-bytes data (little-endian). -* -* \return -* uint16_t: Two-bytes data. -* -******************************************************************************/ -__STATIC_INLINE uint32_t Cy_BLE_Get24ByPtr(const uint8_t ptr[]) -{ - return(((uint32_t)ptr[0u]) | ((uint32_t)(((uint32_t)ptr[1u]) << 8u)) | ((uint32_t)((uint32_t)ptr[2u]) << 16u)); -} - - -/** \endcond */ - - -/*************************************** -* Function Prototypes -***************************************/ - -#if (CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT) - -uint8_t Cy_BLE_IsDeviceAddressValid(const cy_stc_ble_gap_bd_addr_t *deviceAddress); - -#endif /* (CY_BLE_GATT_ROLE_SERVER || CY_BLE_GATT_ROLE_CLIENT) */ - -/** @} group_common_api_functions */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE) */ -#endif /* CY_BLE_EVENT_HANDLER_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gap.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gap.c deleted file mode 100644 index 231ae7b6be..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gap.c +++ /dev/null @@ -1,1440 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_gap.c -* \version 2.0 -* -* \brief -* This file contains the source code for the GAP API of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE) - -#include "cy_ble_hal_pvt.h" -#include - -/*************************************** -* Function Prototypes -***************************************/ - -#if (CY_BLE_GATT_ROLE_SERVER) - #if (CY_BLE_GAP_ROLE_PERIPHERAL) -static void Cy_BLE_ChangeAdLocalName(const char8 name[], uint8_t dest); - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ -#endif /* (CY_BLE_GATT_ROLE_SERVER) */ - - -/*************************************** -* Global Variables -***************************************/ - -cy_en_ble_state_t cy_ble_state; - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) -cy_en_ble_adv_state_t cy_ble_advState; -uint8_t cy_ble_advIndex; -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) -cy_en_ble_scan_state_t cy_ble_scanState; -uint8_t cy_ble_scanIndex; -#endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) */ - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) - -/* This global variable is initialized after connection with peer device, - * after CY_BLE_EVT_GATT_CONNECT_IND event, and could be used by application code - * to send data to peer device. - */ -cy_stc_ble_conn_handle_t cy_ble_connHandle[CY_BLE_CONN_COUNT]; -cy_en_ble_conn_state_t cy_ble_connState[CY_BLE_CONN_COUNT]; - -#if (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) -uint8_t cy_ble_peerBonding[CY_BLE_CONN_COUNT]; -uint8_t cy_ble_pendingFlashWrite; - -#if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) -static uint8_t cy_ble_pendingFlashClearCccdHandle; -#endif /* CY_BLE_GATT_DB_CCCD_COUNT != 0u */ - -#endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ -#endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL) - -cy_stc_ble_gapc_conn_info_t cy_ble_connectionParameters; - -/* Connecting timeout is set to 30 seconds in Cy_BLE_Init function. - * Not zero value starts timer in Cy_BLE_GAPC_ConnectDevice(). - */ -cy_stc_ble_timer_info_t cy_ble_connectingTimeout; - -#endif /* CY_BLE_GAP_ROLE_CENTRAL */ - -cy_stc_ble_gap_bd_addr_t * cy_ble_sflashDeviceAddress = CY_BLE_SFLASH_DEVICE_ADDRESS_PTR; - - -/****************************************************************************** -* Function Name: Cy_BLE_ServiceInit -***************************************************************************//** -* -* Initializes all included services. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_ServiceInit(void) -{ - #if (CY_BLE_GATT_ROLE_CLIENT) - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - /* Check service range before clearing to support partial discovery */ - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_GAP].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_discovery[idx].gapc, 0, sizeof(cy_stc_ble_gapc_t)); - - /* Initialize UUID */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_GAP].uuid = CY_BLE_UUID_GAP_SERVICE; - } - - /* Check service range before clearing to support partial discovery */ - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_GATT].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_discovery[idx].gattc, 0, sizeof(cy_stc_ble_gattc_t)); - - /* Initialize UUID */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_GATT].uuid = CY_BLE_UUID_GATT_SERVICE; - } - - #ifdef CY_BLE_IPSS_CLIENT - cy_ble_serverInfo[idx][CY_BLE_SRVI_IPSS].uuid = CY_BLE_UUID_INTERNET_PROTOCOL_SUPPORT_SERVICE; - #endif /* CY_BLE_IPSS_CLIENT */ - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - - #ifdef CY_BLE_ANCS - (void)Cy_BLE_ANCS_Init(&cy_ble_ancsConfig); - #endif /* CY_BLE_ANCS */ - - #ifdef CY_BLE_ANS - (void)Cy_BLE_ANS_Init(&cy_ble_ansConfig); - #endif /* CY_BLE_ANS */ - - #ifdef CY_BLE_AIOS - (void)Cy_BLE_AIOS_Init(&cy_ble_aiosConfig); - #endif /* CY_BLE_AIOS */ - - #ifdef CY_BLE_BAS - (void)Cy_BLE_BAS_Init(&cy_ble_basConfig); - #endif /* CY_BLE_BAS */ - - #ifdef CY_BLE_BCS - (void)Cy_BLE_BCS_Init(&cy_ble_bcsConfig); - #endif /* CY_BLE_BCS */ - - #ifdef CY_BLE_BLS - (void)Cy_BLE_BLS_Init(&cy_ble_blsConfig); - #endif /* CY_BLE_BLS */ - - #ifdef CY_BLE_BMS - (void)Cy_BLE_BMS_Init(&cy_ble_bmsConfig); - #endif /* CY_BLE_BMS */ - - #ifdef CY_BLE_BTS - (void)Cy_BLE_BTS_Init(&cy_ble_btsConfig); - #endif /* CY_BLE_BTS */ - - #ifdef CY_BLE_CGMS - (void)Cy_BLE_CGMS_Init(&cy_ble_cgmsConfig); - #endif /* CY_BLE_CGMS */ - - #ifdef CY_BLE_CPS - (void)Cy_BLE_CPS_Init(&cy_ble_cpsConfig); - #endif /* CY_BLE_CPS */ - - #ifdef CY_BLE_CSCS - (void)Cy_BLE_CSCS_Init(&cy_ble_cscsConfig); - #endif /* CY_BLE_CSCS */ - - #ifdef CY_BLE_CTS - (void)Cy_BLE_CTS_Init(&cy_ble_ctsConfig); - #endif /* CY_BLE_CTS */ - - #ifdef CY_BLE_CUSTOM - (void)Cy_BLE_CUSTOM_Init(&cy_ble_customConfig); - #endif /* CY_BLE_CUSTOM */ - - #ifdef CY_BLE_DIS - (void)Cy_BLE_DIS_Init(&cy_ble_disConfig); - #endif /* CY_BLE_DIS */ - - #ifdef CY_BLE_ESS - (void)Cy_BLE_ESS_Init(&cy_ble_essConfig); - #endif /* CY_BLE_ESS */ - - #ifdef CY_BLE_GLS - (void)Cy_BLE_GLS_Init(&cy_ble_glsConfig); - #endif /* CY_BLE_GLS */ - - #ifdef CY_BLE_HIDS - (void)Cy_BLE_HIDS_Init(&cy_ble_hidsConfig); - #endif /* CY_BLE_HIDS */ - - #ifdef CY_BLE_HPS - (void)Cy_BLE_HPS_Init(&cy_ble_hpsConfig); - #endif /* CY_BLE_HPS */ - - #ifdef CY_BLE_HRS - (void)Cy_BLE_HRS_Init(&cy_ble_hrsConfig); - #endif /* CY_BLE_HRS */ - - #ifdef CY_BLE_HTS - (void)Cy_BLE_HTS_Init(&cy_ble_htsConfig); - #endif /* CY_BLE_RSCS */ - - #ifdef CY_BLE_IAS - (void)Cy_BLE_IAS_Init(&cy_ble_iasConfig); - #endif /* CY_BLE_IAS */ - - #ifdef CY_BLE_IPS - (void)Cy_BLE_IPS_Init(&cy_ble_ipsConfig); - #endif /* CY_BLE_IPS */ - - #ifdef CY_BLE_LLS - (void)Cy_BLE_LLS_Init(&cy_ble_llsConfig); - #endif /* CY_BLE_LLS */ - - #ifdef CY_BLE_LNS - (void)Cy_BLE_LNS_Init(&cy_ble_lnsConfig); - #endif /* CY_BLE_LNS */ - - #ifdef CY_BLE_NDCS - (void)Cy_BLE_NDCS_Init(&cy_ble_ndcsConfig); - #endif /* CY_BLE_NDCS */ - - #ifdef CY_BLE_PASS - (void)Cy_BLE_PASS_Init(&cy_ble_passConfig); - #endif /* CY_BLE_PASS */ - - #ifdef CY_BLE_RSCS - (void)Cy_BLE_RSCS_Init(&cy_ble_rscsConfig); - #endif /* CY_BLE_RSCS */ - - #ifdef CY_BLE_PLXS - (void)Cy_BLE_PLXS_Init(&cy_ble_plxsConfig); - #endif /* CY_BLE_PLXS */ - - #ifdef CY_BLE_RTUS - (void)Cy_BLE_RTUS_Init(&cy_ble_rtusConfig); - #endif /* CY_BLE_RTUS */ - - #ifdef CY_BLE_SCPS - (void)Cy_BLE_SCPS_Init(&cy_ble_scpsConfig); - #endif /* CY_BLE_SCPS */ - - #ifdef CY_BLE_TPS - (void)Cy_BLE_TPS_Init(&cy_ble_tpsConfig); - #endif /* CY_BLE_TPS */ - - #ifdef CY_BLE_UDS - (void)Cy_BLE_UDS_Init(&cy_ble_udsConfig); - #endif /* CY_BLE_UDS */ - - #ifdef CY_BLE_WPTS - (void)Cy_BLE_WPTS_Init(&cy_ble_wptsConfig); - #endif /* CY_BLE_WPTS */ - - #ifdef CY_BLE_WSS - (void)Cy_BLE_WSS_Init(&cy_ble_wssConfig); - #endif /* CY_BLE_WSS */ -} - - -/****************************************************************************** -* Function Name: Cy_BLE_StoreAppData -***************************************************************************//** -* -* This function instructs the Stack to backup application specific data into -* flash. This API must be called by application to backup application specific -* data. -* -* \param param: parameter of type 'cy_stc_ble_app_flash_param_t -* * param->srcBuff: Source buffer -* * param->destAddr: Destination address -* * param->buffLen: Length of srcData -* * param->writeMode: blocked or non-blocked write mode -* -* This function works in two write modes: blocked or non-blocked : -* CY_BLE_STORE_DATA_MODE_BLOCKING (0x00) - the function writes all data from -* srcBuff and returns CY_BLE_SUCCESS when finish. After writing one rows, -* the function calls Cy_BLE_ProcessEvents that allows stack to process -* pending events. -* CY_BLE_STORE_DATA_MODE_NON_BLOCKING (0x01) - the function writes one row -* per call and returns CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS when write in -* progresing or CY_BLE_SUCCESS, when finish. Afret writing one rows, the -* function calls Cy_BLE_ProcessEvents that allows stack to process pending -* events. -* Application should keep calling this function till it returns -* CY_BLE_SUCCESS. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS | Write operation in progress -* CY_BLE_ERROR_INVALID_PARAMETER | Invalid input parameter -* CY_BLE_ERROR_FLASH_WRITE | Error in flash Write -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StoreAppData(const cy_stc_ble_app_flash_param_t *param) -{ - static cy_en_ble_api_result_t storeState = CY_BLE_SUCCESS; - static uint32_t tLength = 0u; - - uint8_t *tSrcPtr = (uint8_t *) param->srcBuff; - uint32_t tOffset = (uint32) param->destAddr - CY_FLASH_BASE; /* Get offset */ - uint32_t blockSize; - bool exitFlag = false; - - switch (storeState) - { - case CY_BLE_SUCCESS: - case CY_BLE_ERROR_INVALID_PARAMETER: - case CY_BLE_ERROR_FLASH_WRITE: - tLength = param->buffLen; - break; - - case CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS: - if (tLength == 0u) - { - storeState = CY_BLE_SUCCESS; - exitFlag = true; - } - else - { - /* Restore offset and srcPtr according to length */ - tSrcPtr += param->buffLen - tLength; - tOffset += param->buffLen - tLength; - } - break; - - default: - break; - } - - while((tLength !=0u) && (exitFlag == false)) - { - /* Split srcBuff into parts of flash row size (512 bytes) */ - blockSize = (tOffset >> 9) << 9; /* Get current row size regarding to address */ - blockSize = CY_FLASH_SIZEOF_ROW - (tOffset - blockSize); /* Calculate final length of the block which - we can write to row */ - blockSize = (blockSize > tLength )? tLength : blockSize; - - /* Write 512 byte block */ - storeState = Cy_BLE_HAL_NvramWrite(tSrcPtr, (uint8_t *)(tOffset + CY_FLASH_BASE), blockSize); - - tSrcPtr += blockSize; - tOffset += blockSize; - tLength -= blockSize; - - /* For CY_BLE_STORE_DATA_MODE_NON_BLOCKING mode write one row per call */ - if(param->writeMode == CY_BLE_STORE_DATA_MODE_NON_BLOCKING) - { - if (storeState == CY_BLE_SUCCESS) - { - storeState = CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS; - } - exitFlag = true; - } - - /* Cy_BLE_ProcessEvents() allows BLE stack to process pending events */ - Cy_BLE_ProcessEvents(); - } - - return(storeState); -} - - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - - -/****************************************************************************** -* Function Name: Cy_BLE_StoreBondingData -***************************************************************************//** -* -* This function writes the new bonding data from RAM to the dedicated Flash -* location as defined by the component. It performs data comparing between RAM -* and Flash before writing to Flash. If there is no change between RAM and Flash -* data, then no write is performed. It writes only one flash row in one call. -* Application should keep calling this function till it returns CY_BLE_SUCCESS. -* This function is available only when Bonding requirement is selected in -* Security settings. -* -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* -* Error Codes | Description -* ---------------------------------- | ------------------------------------ -* CY_BLE_SUCCESS | On successful operation - CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS | Writing in progress -* CY_BLE_ERROR_FLASH_WRITE_NOT_PERMITED | Flash Write is not permitted -* CY_BLE_ERROR_FLASH_WRITE | Error in flash Write -* -* \globalvars -* The cy_ble_pendingFlashWrite variable is used to detect status -* of pending write to flash operation for stack data and CCCD. -* This function automatically clears pending bits after write operation -* complete. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StoreBondingData(void) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - /* Store Stack data */ - if((cy_ble_pendingFlashWrite & CY_BLE_PENDING_STACK_FLASH_WRITE_BIT) != 0u) - { - cy_stc_ble_stack_flash_param_t stackFlashParam = - { - .bitField = CY_BLE_PERSISTENT_BOND_LIST_BITMASK | - CY_BLE_PERSISTENT_RPA_LIST_BITMASK | - CY_BLE_PERSISTENT_WHITELIST_BITMASK - }; - - apiResult = Cy_BLE_StoreStackData(&stackFlashParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_pendingFlashWrite &= (uint8_t) ~CY_BLE_PENDING_STACK_FLASH_WRITE_BIT; - - /* Change apiResult if there are more pending data to store */ - if((cy_ble_pendingFlashWrite & CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT) != 0u) - { - apiResult = CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS; - } - } - } -#if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) - - /* Store CCCD values */ - if((apiResult == CY_BLE_SUCCESS) && - ((cy_ble_pendingFlashWrite & CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT) != 0u)) - { - uint32_t i; - cy_stc_ble_app_flash_param_t appFlashParam = - { - .buffLen = CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE, - }; - - /* Update CCCD values from RAM for active connections supporting bonding */ - for(i = 0u; i < CY_BLE_CONN_COUNT; i++) - { - if((Cy_BLE_GetConnectionState(cy_ble_connHandle[i]) >= CY_BLE_CONN_STATE_CONNECTED) && - (cy_ble_peerBonding[cy_ble_connHandle[i].attId] == CY_BLE_GAP_BONDING)) - { - uint8_t cccdBlockCrc; - appFlashParam.srcBuff = (uint8_t*)cy_ble_attValuesCccdMultiple[cy_ble_connHandle[i].attId]; - appFlashParam.destAddr = (uint8_t*)cy_ble_configPtr->flashStorage->attValuesCCCDFlashMemory - [cy_ble_connHandle[i].bdHandle]; - - /* Calculate CRC for CCCD block */ - cccdBlockCrc = Cy_BLE_HAL_CalcCRC8(cy_ble_attValuesCccdMultiple[cy_ble_connHandle[i].attId], - CY_BLE_GATT_DB_CCCD_COUNT); - /* Store new CRC value */ - cy_ble_attValuesCccdMultiple[cy_ble_connHandle[i].attId][CY_BLE_GATT_DB_CCCD_COUNT] = cccdBlockCrc; - - apiResult = Cy_BLE_StoreAppData(&appFlashParam); - if(apiResult != CY_BLE_SUCCESS) - { - break; - } - } - } - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_pendingFlashWrite &= (uint8_t) ~CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - } - - /* Clear requested CCCD values */ - if((apiResult == CY_BLE_SUCCESS) && - ((cy_ble_pendingFlashWrite & CY_BLE_PENDING_CCCD_FLASH_CLEAR_MASK) != 0u)) - { - if((cy_ble_pendingFlashWrite & CY_BLE_PENDING_CCCD_FLASH_CLEAR_ALL_BIT) != 0u) - { - /* Remove CCCD values for all bonded devices */ - uint8_t defaultValuesCCCD[CY_BLE_MAX_BONDED_DEVICES + CY_BLE_CONN_COUNT][CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE]; - cy_stc_ble_app_flash_param_t appFlashParam = - { - .srcBuff = (uint8_t*)defaultValuesCCCD, - .destAddr = (uint8_t*)cy_ble_configPtr->flashStorage->attValuesCCCDFlashMemory, - .buffLen = sizeof(defaultValuesCCCD), - }; - - (void)memset(defaultValuesCCCD, 0, sizeof(defaultValuesCCCD)); - - apiResult = Cy_BLE_StoreAppData(&appFlashParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_pendingFlashWrite &= (uint8_t) ~CY_BLE_PENDING_CCCD_FLASH_CLEAR_ALL_BIT; - } - } - else /* Remove CCCD values for particular device */ - { - uint8_t defaultValuesCCCD[CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE] = { 0u }; - cy_stc_ble_app_flash_param_t appFlashParam = - { - .srcBuff = (uint8_t*)defaultValuesCCCD, - .destAddr = (uint8_t*)cy_ble_configPtr->flashStorage-> - attValuesCCCDFlashMemory[cy_ble_pendingFlashClearCccdHandle], - .buffLen = CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE, - }; - - apiResult = Cy_BLE_StoreAppData(&appFlashParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_pendingFlashWrite &= (uint8_t) ~CY_BLE_PENDING_CCCD_FLASH_CLEAR_BIT; - } - } - } -#endif /* CY_BLE_GATT_DB_CCCD_COUNT != 0u */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_RemoveBondedDevice -***************************************************************************//** -* -* This function marks the device untrusted. It removes the bonding information -* of the device including CCCD values. This function removes device from the -* white list also when auto-populate white list with bonded devices option is -* enabled. -* -* This function is available only when Bonding requirement is selected in -* Security settings. -* -* \param bdAddr: Pointer to peer device address, of type cy_stc_ble_gap_bd_addr_t. -* If device address is set to 0, then all devices shall be -* removed from trusted list and white list. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* --------------------------------- | ------------------------------------ -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'bdAddr'. -* CY_BLE_ERROR_INVALID_OPERATION | Whitelist is already in use or there is pending write to flash operation. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device does not exist in the bond list. -* -* \globalvars -* The bdHandle is set in cy_ble_pendingFlashWrite variable to indicate that -* data should be stored to flash by Cy_BLE_StoreBondingData afterwards. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_RemoveBondedDevice(cy_stc_ble_gap_bd_addr_t* bdAddr) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_stc_ble_gap_peer_addr_info_t peerAddrInfoParam; - - if(cy_ble_pendingFlashWrite == 0u) - { - #if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) - /* Request to clear CCCD values which will be done by Cy_BLE_StoreBondingData() */ - cy_stc_ble_gap_bd_addr_t invalidBdAddr = { { 0u, 0u, 0u, 0u, 0u, 0u }, 0u }; - - if(memcmp(((uint8_t*)&(bdAddr->bdAddr)), ((uint8_t*)&(invalidBdAddr.bdAddr)), CY_BLE_GAP_BD_ADDR_SIZE) == 0u) - { - /* Request to remove all bonded devices by Cy_BLE_StoreBondingData() */ - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_CLEAR_ALL_BIT; - } - else - { - /* Get the BD handle from Address */ - peerAddrInfoParam.bdAddr = *bdAddr; - apiResult = Cy_BLE_GAP_GetPeerBdHandle(&peerAddrInfoParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Store BD handle to clear CCCD values by Cy_BLE_StoreBondingData() */ - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_CLEAR_BIT; - cy_ble_pendingFlashClearCccdHandle = peerAddrInfoParam.bdHandle; - } - } - #endif /* CY_BLE_GATT_DB_CCCD_COUNT != 0u */ - if(apiResult == CY_BLE_SUCCESS) - { - apiResult = Cy_BLE_GAP_RemoveDeviceFromBondList(bdAddr); - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - -/****************************************************************************** - * Function Name: Cy_BLE_GAPP_StartAdvertisement - ***************************************************************************//** - * - * This function is used to start the advertisement using the advertisement data - * set in the component customizer's GUI indicated by the advertisingParamIndex. - * After invoking this function, the device will be available for connection by - * the devices configured for GAP central role. It is only included if the - * device is configured for GAP Peripheral or GAP Peripheral + Central role. - * - * On start of advertisement, GAP Peripheral receives the - * CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP event. The following events are - * possible on invoking this function: - * - * * CY_BLE_EVT_GAP_DEVICE_CONNECTED - If the device connects to a GAP Central and - * Link Layer Privacy is disabled in component customizer. - * * CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE - If the device connects to a GAP Central and - * Link Layer Privacy is enabled in component customizer. - * * CY_BLE_EVT_TIMEOUT: If no device in GAP Central mode connects to this - * device within the specified timeout limit. Stack - * automatically initiate stop advertising when Slow - * advertising was initiated, or starts Slow advertising - * after Fast advertising timeout occur. - * * CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP: If device started or stopped - * advertising. Use Cy_BLE_GetAdvertisementState()to - * determine the state. Sequential advertising could be - * started when CY_BLE_ADV_STATE_STOPPED state is returned. - * - * \param advertisingIntervalType: Fast or slow advertising interval with timings - * entered in Advertising settings section of the - * customizer. - * * CY_BLE_ADVERTISING_FAST 0x00u - * * CY_BLE_ADVERTISING_SLOW 0x01u - * * CY_BLE_ADVERTISING_CUSTOM 0x02u - * - * \param advertisingParamIndex: The index of the peripheral and broadcast - * configuration in customizer. For example: - * * CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX 0x00 - * * CY_BLE_BROADCASTER_CONFIGURATION_0_INDEX 0x01 - * - * \return - * cy_en_ble_api_result_t : Return value indicates if the function succeeded or - * failed. The following are possible error codes. - * - * Error Codes | Description - * --------------------------------- | -------------------------------- - * CY_BLE_SUCCESS | On successful operation. - * CY_BLE_ERROR_INVALID_PARAMETER | On passing an invalid parameter. - * CY_BLE_ERROR_INVALID_STATE | On calling this function not in Stopped state. - * CY_BLE_ERROR_INVALID_OPERATION | The operation is not permitted due to connection - * | limit exceeded. - * - *******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPP_StartAdvertisement(uint8_t advertisingIntervalType, - uint8_t advertisingParamIndex) -{ - cy_en_ble_api_result_t apiResult; - - if((advertisingIntervalType > CY_BLE_ADVERTISING_CUSTOM) || (advertisingParamIndex >= CY_BLE_GAPP_CONF_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - else if((Cy_BLE_GetNumOfActiveConn() == CY_BLE_CONN_COUNT) && - ((cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advParam->advType < - CY_BLE_GAPP_SCANNABLE_UNDIRECTED_ADV) || - (cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advParam->advType > - CY_BLE_GAPP_NON_CONNECTABLE_UNDIRECTED_ADV))) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } -#endif /*CY_BLE_GAP_ROLE_PERIPHERAL */ - else if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_STOPPED) - { - cy_ble_advIndex = advertisingParamIndex; - if(advertisingIntervalType == CY_BLE_ADVERTISING_FAST) - { - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advTo = - cy_ble_configPtr->gappAdvParams[advertisingParamIndex].fastAdvTimeOut; - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advParam->advIntvMin = - cy_ble_configPtr->gappAdvParams[advertisingParamIndex].fastAdvIntervalMin; - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advParam->advIntvMax = - cy_ble_configPtr->gappAdvParams[advertisingParamIndex].fastAdvIntervalMax; - } - else if(advertisingIntervalType == CY_BLE_ADVERTISING_SLOW) - { - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advTo = - cy_ble_configPtr->gappAdvParams[advertisingParamIndex].slowAdvTimeOut; - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advParam->advIntvMin = - cy_ble_configPtr->gappAdvParams[advertisingParamIndex].slowAdvIntervalMin; - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advParam->advIntvMax = - cy_ble_configPtr->gappAdvParams[advertisingParamIndex].slowAdvIntervalMax; - } - else /* Do not update advertising intervals */ - { - } - cy_ble_advertisingIntervalType = advertisingIntervalType; - apiResult = Cy_BLE_GAPP_EnterDiscoveryMode(&cy_ble_configPtr->discoveryModeInfo[cy_ble_advIndex]); - - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_ADV_INITIATED); - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPP_StopAdvertisement -***************************************************************************//** -* -* This function can be used to exit from discovery mode. After the execution -* of this function, there will no longer be any advertisements. On stopping -* advertising, GAP Peripheral receives CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP -* event. It is expected that the application layer tracks the function call -* performed before occurrence of this event as this event can occur on making -* a call to Cy_BleGappStartAdvertisement(), Cy_BLE_GAPP_EnterDiscoveryMode(), -* or Cy_BLE_GAPP_StartAdvertisement() functions as well. -* -* The following event occurs on invoking this function: -* * CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in Advertising state. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPP_StopAdvertisement(void) -{ - cy_en_ble_api_result_t apiResult; - - if(Cy_BLE_GetAdvertisementState() != CY_BLE_ADV_STATE_STOPPED) - { - apiResult = Cy_BLE_GAPP_ExitDiscoveryMode(); - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetAdvertisementState(CY_BLE_ADV_STATE_STOP_INITIATED); - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_ChangeAdDeviceAddress -***************************************************************************//** -* -* This function is used to set the Bluetooth device address into the -* advertisement or scan response data structures. -* -* \param bdAddr: Bluetooth Device address. The variable is of type cy_stc_ble_gap_bd_addr_t. -* \param dest: 0 - selects advertisement structure, not zero value selects scan -* response structure. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_ChangeAdDeviceAddress(const cy_stc_ble_gap_bd_addr_t* bdAddr, - uint8_t dest) -{ - uint32_t i; - uint32_t fFlag; - uint32_t adLength; - uint32_t byteCounter; - uint32_t maxLength; - uint32_t advIndex = 0u; - uint8_t *destBuffer; - - do - { - fFlag = 0u; - byteCounter = 0u; - - if(dest == 0u) /* Destination - advertising structure */ - { - destBuffer = cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData; - maxLength = cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advDataLen; - } - else /* Destination - scan response structure */ - { - destBuffer = cy_ble_configPtr->discoveryModeInfo[advIndex].scanRspData->scanRspData; - maxLength = cy_ble_configPtr->discoveryModeInfo[advIndex].scanRspData->scanRspDataLen; - } - - while((byteCounter < maxLength) && (fFlag == 0u)) - { - adLength = destBuffer[byteCounter]; - - if(adLength != 0u) - { - /* Increment byte counter so it can point to AD type */ - byteCounter++; - - if(destBuffer[byteCounter] == CY_BLE_ADV_DEVICE_ADDR) - { - /* Start of the device address type was found. Set flag and exit the loop. */ - fFlag = 1u; - } - else - { - byteCounter += adLength; - } - } - else - { - /* The end of advertisement data structure was encountered though exit the loop. */ - break; - } - } - - if(fFlag != 0u) - { - /* Increment byte counter so it can point to Device address */ - byteCounter++; - - /* Update Device Address type */ - destBuffer[byteCounter] = bdAddr->type; - - for(i = 0u; i < CY_BLE_GAP_BD_ADDR_SIZE; i++) - { - destBuffer[byteCounter + i + 1u] = bdAddr->bdAddr[i]; - } - } - advIndex++; - } - while(advIndex < CY_BLE_GAPP_CONF_COUNT); -} - -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER */ - - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_StartScan -***************************************************************************//** -* -* This function is used for discovering GAP peripheral devices that are -* available for connection. It performs the scanning routine using the -* parameters entered in the component's customizer indicated by -* scanParamIndex parameter. -* -* As soon as the discovery operation starts, CY_BLE_EVT_GAPC_SCAN_START_STOP -* event is generated. The CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT event is -* generated when a GAP peripheral device is located. There are three discovery -* procedures can be selected in the customizer's GUI: -* -* * Observation procedure: A device performing the observer role receives only -* advertisement data from devices irrespective of -* their discoverable mode settings. Advertisement -* data received is provided by the event, -* CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT. This procedure -* requires the scanType sub parameter to be passive -* scanning. -* -* * Discovery procedure: A device performing the discovery procedure receives -* the advertisement data and scan response data from -* devices in both limited discoverable mode and the -* general discoverable mode. Received data is provided -* by the event, CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT. -* This procedure requires the scanType sub-parameter -* to be active scanning. -* -* Every Advertisement / Scan response packet is received in a new event, -* CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT. -* If 'scanTo' sub-parameter is a non-zero value, then upon commencement of -* discovery procedure and elapsed time = 'scanTo', CY_BLE_EVT_TIMEOUT event -* is generated with the event parameter indicating CY_BLE_GAP_SCAN_TO. -* Possible generated events are: -* * CY_BLE_EVT_GAPC_SCAN_START_STOP: If a device started or stopped scanning. -* Use Cy_BLE_GetScanState() to determine the -* state. Sequential scanning could be -* started when CY_BLE_ADV_STATE_STOPPED -* state is returned. -* * CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT -* * CY_BLE_EVT_TIMEOUT (CY_BLE_GAP_SCAN_TO) -* -* \param scanningIntervalType: Fast or slow scanning interval with -* timings entered in Scan settings section of the customizer. -* * CY_BLE_SCANNING_FAST 0x00u -* * CY_BLE_SCANNING_SLOW 0x01u -* * CY_BLE_SCANNING_CUSTOM 0x02u -* -* \param scanParamIndex: The index of the central and scan configuration -* in customizer. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ---------------------------------- | ----------------------------------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On passing an invalid parameter. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in Stopped state. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_StartScan(uint8_t scanningIntervalType, - uint8_t scanParamIndex) -{ - cy_en_ble_api_result_t apiResult; - - if(scanningIntervalType > CY_BLE_SCANNING_CUSTOM) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(Cy_BLE_GetScanState() == CY_BLE_SCAN_STATE_STOPPED) - { - cy_ble_scanIndex = scanParamIndex; - if(scanningIntervalType == CY_BLE_SCANNING_FAST) - { - cy_ble_configPtr->discoveryInfo[scanParamIndex].scanTo = - cy_ble_configPtr->gapcScanParams[scanParamIndex].fastScanTimeOut; - cy_ble_configPtr->discoveryInfo[scanParamIndex].scanIntv = - cy_ble_configPtr->gapcScanParams[scanParamIndex].fastScanInterval; - cy_ble_configPtr->discoveryInfo[scanParamIndex].scanWindow = - cy_ble_configPtr->gapcScanParams[scanParamIndex].fastScanWindow; - } - else if(scanningIntervalType == CY_BLE_SCANNING_SLOW) - { - cy_ble_configPtr->discoveryInfo[scanParamIndex].scanTo = - cy_ble_configPtr->gapcScanParams[scanParamIndex].slowScanTimeOut; - cy_ble_configPtr->discoveryInfo[scanParamIndex].scanIntv = - cy_ble_configPtr->gapcScanParams[scanParamIndex].slowScanInterval; - cy_ble_configPtr->discoveryInfo[scanParamIndex].scanWindow = - cy_ble_configPtr->gapcScanParams[scanParamIndex].slowScanWindow; - } - else /* Do not update scanning intervals */ - { - } - - cy_ble_scanningIntervalType = scanningIntervalType; - apiResult = Cy_BLE_GAPC_StartDiscovery(&cy_ble_configPtr->discoveryInfo[scanParamIndex]); - - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_SCAN_INITIATED); - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_StopScan -***************************************************************************//** -* -* This function used to stop the discovery of devices. On stopping discovery -* operation, CY_BLE_EVT_GAPC_SCAN_START_STOP event is generated. Application -* layer needs to keep track of the function call made before receiving this -* event to associate this event with either the start or stop discovery -* function. -* -* Possible events generated are: -* * CY_BLE_EVT_GAPC_SCAN_START_STOP -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------------------------------- | ----------------------------------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in Scanning state. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_StopScan(void) -{ - cy_en_ble_api_result_t apiResult; - - if(Cy_BLE_GetScanState() == CY_BLE_SCAN_STATE_SCANNING) - { - apiResult = Cy_BLE_GAPC_StopDiscovery(); - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetScanState(CY_BLE_SCAN_STATE_STOP_INITIATED); - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER */ - - -#if (CY_BLE_GAP_ROLE_CENTRAL) - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_ConnectDevice -***************************************************************************//** -* -* This function is used to send a connection request to the remote device with -* the connection parameters set in the component customizer. This function needs -* to be called only once after the target device is discovered by -* Cy_BLE_GAPC_StartScan() and further scanning has stopped. Scanning is -* successfully stopped on invoking Cy_BLE_GAPC_StopScan() and then receiving the -* event CY_BLE_EVT_GAPC_SCAN_START_STOP with sub-parameter 'success' = 0x01u. -* -* On successful connection, the following events are generated at the GAP -* Central device (as well as the GAP Peripheral device), in the following order. -* * CY_BLE_EVT_GATT_CONNECT_IND -* * CY_BLE_EVT_GAP_DEVICE_CONNECTED - If the device connects to a GAP Central and -* Link Layer Privacy is disabled in component customizer. -* * CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE - If the device connects to a GAP Central and -* Link Layer Privacy is enabled in component customizer. -* * CY_BLE_EVT_GAP_DEVICE_CONNECTED -* -* A procedure is considered to have timed out if a connection response packet is -* not received within time set by cy_ble_connectingTimeout global variable -* (30 seconds by default). CY_BLE_EVT_TIMEOUT event with CY_BLE_GENERIC_APP_TO parameter -* will indicate about connection procedure timeout. Connection will automatically -* be canceled and state will be changed to CY_BLE_STATE_ON. -* -* \param address: The device address of the remote device to connect to. -* \param centralParamIndex: The index of the central configuration in customizer. -* For example: -* * CY_BLE_CENTRAL_CONFIGURATION_0_INDEX 0x00 -* * CY_BLE_CENTRAL_CONFIGURATION_1_INDEX 0x01 -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_STACK_INTERNAL | On error occurred in the BLE stack. -* CY_BLE_ERROR_INVALID_PARAMETER | On passing an invalid parameter. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in Disconnected state. -* CY_BLE_ERROR_INVALID_OPERATION | The operation is not permitted due to connection -* | limit exceeded. -* -* Note: Please refer the description of Cy_BLE_GAPC_InitConnection() for recommended -* Connection Interval values. -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_ConnectDevice(const cy_stc_ble_gap_bd_addr_t * address, - uint8_t centralParamIndex) -{ -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - cy_en_ble_adv_state_t advState = Cy_BLE_GetAdvertisementState(); -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL */ - - cy_en_ble_api_result_t apiResult; - uint32_t i; - - if(Cy_BLE_GetState() != CY_BLE_STATE_ON) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(address == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(Cy_BLE_GetNumOfActiveConn() == CY_BLE_CONN_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - else if(((CY_BLE_CONN_COUNT - Cy_BLE_GetNumOfActiveConn()) == 1u) && (advState == CY_BLE_ADV_STATE_ADVERTISING) && - ((cy_ble_configPtr->discoveryModeInfo[cy_ble_advIndex].advParam->advType < - CY_BLE_GAPP_SCANNABLE_UNDIRECTED_ADV) || - (cy_ble_configPtr->discoveryModeInfo[cy_ble_advIndex].advParam->advType > - CY_BLE_GAPP_NON_CONNECTABLE_UNDIRECTED_ADV))) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL */ - else - { - /* Init default connection parameters. - * Application may change it before initiating a connection */ - cy_ble_connectionParameters.scanIntv = cy_ble_configPtr->discoveryInfo[centralParamIndex].scanIntv; - cy_ble_connectionParameters.scanWindow = cy_ble_configPtr->discoveryInfo[centralParamIndex].scanWindow; - cy_ble_connectionParameters.ownAddrType = cy_ble_configPtr->discoveryInfo[centralParamIndex].ownAddrType; - cy_ble_connectionParameters.initiatorFilterPolicy = - cy_ble_configPtr->discoveryInfo[centralParamIndex].scanFilterPolicy; - cy_ble_connectionParameters.connIntvMin = - cy_ble_configPtr->gapcScanParams[centralParamIndex].gapcConnectionIntervalMin; - cy_ble_connectionParameters.connIntvMax = - cy_ble_configPtr->gapcScanParams[centralParamIndex].gapcConnectionIntervalMax; - cy_ble_connectionParameters.connLatency = - cy_ble_configPtr->gapcScanParams[centralParamIndex].gapcConnectionSlaveLatency; - cy_ble_connectionParameters.supervisionTO = - cy_ble_configPtr->gapcScanParams[centralParamIndex].gapcConnectionTimeOut; - cy_ble_connectionParameters.minCeLength = 0x0000u; - cy_ble_connectionParameters.maxCeLength = 0xFFFFu; - cy_ble_connectingTimeout.timeout = CY_BLE_GAPC_CONNECTING_TIMEOUT; - - for(i = 0u; i < CY_BLE_GAP_BD_ADDR_SIZE; i++) - { - cy_ble_connectionParameters.peerBdAddr[i] = address->bdAddr[i]; - } - cy_ble_connectionParameters.peerAddrType = address->type; - - apiResult = Cy_BLE_StartTimer(&cy_ble_connectingTimeout); - - if(apiResult == CY_BLE_SUCCESS) - { - apiResult = Cy_BLE_GAPC_InitConnection(&cy_ble_connectionParameters); - - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetState(CY_BLE_STATE_CONNECTING); - } - } - else - { - (void)Cy_BLE_StopTimer(&cy_ble_connectingTimeout); - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_CancelDeviceConnection -***************************************************************************//** -* -* This function cancels a previously initiated connection with the remote -* device. It is a blocking function. No event is generated on calling this -* function. If the devices are already connected then this function should not -* be used. If you intend to disconnect from an existing connection, the function -* Cy_BLE_GAP_Disconnect() should be used. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ----------------------------------- | -------------------------------------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_STACK_INTERNAL | An error occurred in the BLE stack. -* CY_BLE_ERROR_INVALID_STATE | On calling this function not in Connecting state. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_CancelDeviceConnection(void) -{ - cy_en_ble_api_result_t apiResult; - - if(Cy_BLE_GetState() != CY_BLE_STATE_CONNECTING) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else - { - apiResult = Cy_BLE_GAPC_CancelConnection(); - - if(cy_ble_connectingTimeout.timeout != 0u) - { - (void)Cy_BLE_StopTimer(&cy_ble_connectingTimeout); - } - - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetState(CY_BLE_STATE_ON); - } - } - - return(apiResult); -} - -#endif /* CY_BLE_GAP_ROLE_CENTRAL */ - - -#if (CY_BLE_GATT_ROLE_SERVER) - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - -/****************************************************************************** -* Function Name: Cy_BLE_ChangeAdLocalName -***************************************************************************//** -* This function is used to set the local device name in the advertisement or scan -* response data structure. -* -* \param name: The local device name string to be set in advertisement data -* structure. -* \param dest: 0 - advertisement structure, not zero value selects scan response -* structure. -* -* \return -* None -* -*******************************************************************************/ -static void Cy_BLE_ChangeAdLocalName(const char8 name[], - uint8_t dest) -{ - uint32_t i; - uint8_t fFlag; - uint8_t adLength; - uint8_t byteCounter; - uint8_t *destBuffer; - uint8_t maxLength; - uint8_t advIndex = 0u; - - do - { - fFlag = 0u; - adLength = 0u; - byteCounter = 0u; - - if(dest == 0u) /* Destination - advertising structure */ - { - destBuffer = cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData; - maxLength = cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advDataLen; - } - else /* Destination - scan response structure */ - { - destBuffer = cy_ble_configPtr->discoveryModeInfo[advIndex].scanRspData->scanRspData; - maxLength = cy_ble_configPtr->discoveryModeInfo[advIndex].scanRspData->scanRspDataLen; - } - - while((byteCounter < maxLength) && (fFlag == 0u)) - { - adLength = destBuffer[byteCounter]; - - if(adLength != 0u) - { - /* Increment byte counter so it can point to AD type */ - byteCounter++; - - if((CY_BLE_SHORT_LOCAL_NAME == destBuffer[byteCounter]) || - (CY_BLE_COMPLETE_LOCAL_NAME == destBuffer[byteCounter])) - { - /* Start of the Local Name AD type was found. Set flag and exit the loop. */ - fFlag = 1u; - } - else - { - byteCounter += adLength; - } - } - else - { - /* The end of advertisement data structure was encountered though exit the loop. */ - break; - } - } - - if(fFlag != 0u) - { - /* Reuse "adLength" to hold location of the last character of local name in - * AD structure. */ - adLength += byteCounter; - - /* Increment byte counter to point to start of the local Name string */ - byteCounter++; - - for(i = byteCounter; ((i < (adLength)) && (name[i - byteCounter] != CY_BLE_NULL_CHARCTER)); i++) - { - destBuffer[i] = (uint8_t)name[i - byteCounter]; - } - - /* This loop handles the case when new local name is shorter than old one. - * In this case all remaining characters should be null characters. */ - while(adLength > i) - { - /* Terminate string */ - destBuffer[i] = (uint8_t)CY_BLE_NULL_CHARCTER; - i++; - } - } - advIndex++; - } - while(advIndex < CY_BLE_GAPP_CONF_COUNT); -} - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - - -/****************************************************************************** - * Function Name: Cy_BLE_SetLocalName - ***************************************************************************//** - * This function is used to set the local device name - a Characteristic of the - * GAP Service. If the characteristic length entered in the component customizer - * is shorter than the string specified by the "name" parameter, the local device - * name will be cut to the length specified in the customizer. - * - * \param name: The local device name string. The name string to be written as - * the local device name. It represents a UTF-8 encoded User - * Friendly Descriptive Name for the device. The length of the local - * device string is entered into the component customizer and it can - * be set to a value from 0 to 248 bytes. If the name contained in - * the parameter is shorter than the length from the customizer, the - * end of the name is indicated by a NULL octet (0x00). - * - * \return - * cy_en_ble_api_result_t : Return value indicates if the function succeeded or - * failed. The following are possible error codes. - * - * Error Codes | Description - * ------------ | ----------- - * CY_BLE_SUCCESS | The function completed successfully. - * CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. - * - *******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetLocalName(const char8 name[]) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t i; - char8 *ptr; - uint8_t charLen; - - if(NULL != name) - { - /* Get the pointer to the Device Name characteristic */ - ptr = (char8*)CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(cy_ble_configPtr->gaps->deviceNameCharHandle); - - /* First need to get the maximum length of the characteristic data in the GATT - * database to make sure there is enough place for the data. The length - * can't be longer than 248, so only the LSB of 16 bit of length is to - * be used. */ - charLen = (uint8_t)CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_configPtr->gaps->deviceNameCharHandle); - - /* Copy name into characteristic */ - for(i = 0u; ((i < charLen) && (name[i] != CY_BLE_NULL_CHARCTER)); i++) - { - ptr[i] = name[i]; - } - - if(i < charLen) - { - /* Terminate string */ - ptr[i] = CY_BLE_NULL_CHARCTER; - } - - /* Update device name in advertising and scan response structure */ - #if (CY_BLE_GAP_ROLE_PERIPHERAL) - Cy_BLE_ChangeAdLocalName(name, 0u); - Cy_BLE_ChangeAdLocalName(name, 1u); - #endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GetLocalName -***************************************************************************//** -* -* This function is used to read the local device name - a Characteristic of -* the GAP Service. -* -* \param name: The local device name string. Used to read the local name to the -* given string array. It represents a UTF-8 encoded User Friendly -* Descriptive Name for the device. The length of the local device -* string is entered into the component customizer and it can be set -* to a value from 0 to 248 bytes. If the name contained in the -* parameter is shorter than the length from the customizer, the end -* of the name is indicated by a NULL octet (0x00). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetLocalName(char8 name[]) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint8_t charLen; - uint32_t i; - char8 *ptr; - - if(NULL != name) - { - /* Get the pointer to the Device Name characteristic */ - ptr = (char8*)CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(cy_ble_configPtr->gaps->deviceNameCharHandle); - - /* First need to get the length of the characteristic data in the GATT - * database to make sure there is enough place for the data. The length - * can't be longer than 248, so only the LSB of 16 bit of length is to - * be used. */ - charLen = (uint8_t)CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_LEN(cy_ble_configPtr->gaps->deviceNameCharHandle); - - /* Copy name from characteristic */ - for(i = 0u; ((i < charLen) && (CY_BLE_NULL_CHARCTER != ptr[i])); i++) - { - name[i] = ptr[i]; - } - - /* Terminate string */ - name[i] = CY_BLE_NULL_CHARCTER; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - -#endif /* (CY_BLE_GATT_ROLE_SERVER) */ - -#endif /* defined(CY_BLE_MODE_PROFILE) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gap.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gap.h deleted file mode 100644 index 7f555cbfd5..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gap.h +++ /dev/null @@ -1,867 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_gap.h -* \version 2.0 -* -* \brief -* Contains the prototypes and constants used in the BLE GAP profile. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_GAP_H -#define CY_BLE_GAP_H - -#include "cy_ble.h" - - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/*************************************** -* Type Definitions -***************************************/ - -#if (CY_BLE_MODE_PROFILE) - -/*************************************** -* Enumerated Types and Structures -***************************************/ - -/** - * \addtogroup group_ble_common_api_gap_definitions - * @{ - */ - -/** New Event handler state machine type */ -typedef enum -{ - CY_BLE_STATE_STOPPED, /**< BLE is turned off */ - CY_BLE_STATE_INITIALIZING, /**< Initializing state */ - CY_BLE_STATE_ON, /**< BLE is turned on */ -#if (CY_BLE_GAP_ROLE_CENTRAL) - CY_BLE_STATE_CONNECTING, /**< Connecting */ -#endif /* CY_BLE_GAP_ROLE_CENTRAL */ -} cy_en_ble_state_t; - - -/** Scanning state machine type */ -typedef enum -{ - CY_BLE_SCAN_STATE_STOPPED, /**< Scanning is stopped */ - CY_BLE_SCAN_STATE_SCAN_INITIATED, /**< Scanning is initiated */ - CY_BLE_SCAN_STATE_SCANNING, /**< Scanning process */ - CY_BLE_SCAN_STATE_STOP_INITIATED /**< Stop scanning is initiated */ -} cy_en_ble_scan_state_t; - -/** Advertising state machine type */ -typedef enum -{ - CY_BLE_ADV_STATE_STOPPED, /**< Advertising is stopped */ - CY_BLE_ADV_STATE_ADV_INITIATED, /**< Advertising is initiated */ - CY_BLE_ADV_STATE_ADVERTISING, /**< Advertising process */ - CY_BLE_ADV_STATE_STOP_INITIATED /**< Stop advertising is initiated */ -} cy_en_ble_adv_state_t; - -/** Connection state machine type */ -typedef enum -{ - CY_BLE_CONN_STATE_DISCONNECTED, /**< Essentially idle state */ - CY_BLE_CONN_STATE_CLIENT_DISCONNECTED_DISCOVERED, /**< Server is disconnected but discovered */ - CY_BLE_CONN_STATE_CONNECTED, /**< Peer device is connected for this and following states */ - CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING, /**< Server services are being discovered */ - CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING, /**< Server included services are being discovered */ - CY_BLE_CONN_STATE_CLIENT_CHAR_DISCOVERING, /**< Server characteristics are being discovered */ - CY_BLE_CONN_STATE_CLIENT_DESCR_DISCOVERING, /**< Server char. descriptors are being discovered */ - CY_BLE_CONN_STATE_CLIENT_DISCOVERED /**< Server is discovered */ -} cy_en_ble_conn_state_t; - - -/** Structure with Generic Access Profile Service (GAPS) attribute handles */ -typedef struct -{ - /** Service handle*/ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Handle of the GAPS Device Name Characteristic */ - cy_ble_gatt_db_attr_handle_t deviceNameCharHandle; - - /** Handle of the GAPS Appearance Characteristic */ - cy_ble_gatt_db_attr_handle_t appearanceCharHandle; - - /** Handle of the GAPS Peripheral Preferred Connection Parameters Characteristic */ - cy_ble_gatt_db_attr_handle_t prefConnParamCharHandle; - - /** Handle of the GAPS Central Address Resolution characteristic */ - cy_ble_gatt_db_attr_handle_t centralAddrResolutionCharHandle; - - /** Handle of the GAPS Resolvable Private Address Only characteristic */ - cy_ble_gatt_db_attr_handle_t resolvablePrivateAddressOnly; -} cy_stc_ble_gaps_t; - - -/** GAP Service characteristics server's GATT DB handles structure type */ -typedef struct -{ - /** Handle of the GAPS Device Name Characteristic */ - cy_ble_gatt_db_attr_handle_t deviceNameCharHandle; - - /** Handle of the GAPS Appearance Characteristic */ - cy_ble_gatt_db_attr_handle_t appearanceCharHandle; - - /** Handle of the GAPS Peripheral Privacy Flag Parameters Characteristic */ - cy_ble_gatt_db_attr_handle_t periphPrivacyCharHandle; - - /** Handle of the GAPS Reconnection Address Characteristic */ - cy_ble_gatt_db_attr_handle_t reconnAddrCharHandle; - - /** Handle of the GAPS Peripheral Preferred Connection Parameters Characteristic */ - cy_ble_gatt_db_attr_handle_t prefConnParamCharHandle; - - /** Handle of the GAPS Central Address Resolution characteristic */ - cy_ble_gatt_db_attr_handle_t centralAddrResolutionCharHandle; - - /** Handle of the GAPS Resolvable Private Address Only characteristic */ - cy_ble_gatt_db_attr_handle_t resolvablePrivateAddressOnly; -}cy_stc_ble_gapc_t; - -/* Stack mode defines */ - - -/** Advertisement SIG assigned numbers */ -typedef enum -{ - /** Flags */ - CY_BLE_GAP_ADV_FLAGS = 0x01u, - - /** Incomplete List of 16-bit Service Class UUIDs */ - CY_BLE_GAP_ADV_INCOMPL_16UUID, - - /** Complete List of 16-bit Service Class UUIDs */ - CY_BLE_GAP_ADV_COMPL_16UUID, - - /** Incomplete List of 32-bit Service Class UUIDs */ - CY_BLE_GAP_ADV_INCOMPL_32_UUID, - - /** Complete List of 32-bit Service Class UUIDs */ - CY_BLE_GAP_ADV_COMPL_32_UUID, - - /** Incomplete List of 128-bit Service Class UUIDs */ - CY_BLE_GAP_ADV_INCOMPL_128_UUID, - - /** Complete List of 128-bit Service Class UUIDs */ - CY_BLE_GAP_ADV_COMPL_128_UUID, - - /** Shortened Local Name */ - CY_BLE_GAP_ADV_SHORT_NAME, - - /** Complete Local Name */ - CY_BLE_GAP_ADV_COMPL_NAME, - - /** Tx Power Level */ - CY_BLE_GAP_ADV_TX_PWR_LVL, - - /** Class of Device */ - CY_BLE_GAP_ADV_CLASS_OF_DEVICE = 0x0Du, - - /** Simple Pairing Hash C */ - CY_BLE_GAP_ADV_SMPL_PAIR_HASH_C, - - /** Simple Pairing Randomizer R */ - CY_BLE_GAP_ADV_SMPL_PAIR_RANDOM_R, - - /** Device ID*/ - CY_BLE_GAP_ADV_DEVICE_ID, - - /** Security Manager TK Value */ - CY_BLE_GAP_ADV_SCRT_MNGR_TK_VAL = 0x10u, - - /** Security Manager Out of Band Flags */ - CY_BLE_GAP_ADV_SCRT_MNGR_OOB_FLAGS, - - /** Slave Connection Interval Range */ - CY_BLE_GAP_ADV_SLAVE_CONN_INTRV_RANGE, - - /** List of 16-bit Service Solicitation UUIDs */ - CY_BLE_GAP_ADV_SOLICIT_16UUID = 0x14u, - - /** List of 128-bit Service Solicitation UUIDs */ - CY_BLE_GAP_ADV_SOLICIT_128UUID, - - /** Service Data - 16-bit UUID */ - CY_BLE_GAP_ADV_SRVC_DATA_16UUID, - - /** Public Target Address */ - CY_BLE_GAP_ADV_PUBLIC_TARGET_ADDR, - - /** Random Target Address */ - CY_BLE_GAP_ADV_RANDOM_TARGET_ADDR, - - /** Appearance */ - CY_BLE_GAP_ADV_APPEARANCE, - - /** Advertising Interval */ - CY_BLE_GAP_ADV_ADVERT_INTERVAL, - - /** LE Bluetooth Device Address */ - CY_BLE_GAP_ADV_LE_BT_DEVICE_ADDR, - - /** LE Role */ - CY_BLE_GAP_ADV_LE_ROLE, - - /** Simple Pairing Hash C-256 */ - CY_BLE_GAP_ADV_SMPL_PAIR_HASH_C256, - - /** Simple Pairing Randomizer R-256 */ - CY_BLE_GAP_ADV_SMPL_PAIR_RANDOM_R256, - - /** List of 32-bit Service Solicitation UUIDs */ - CY_BLE_GAP_ADV_SOLICIT_32UUID, - - /** Service Data - 32-bit UUID */ - CY_BLE_GAP_ADV_SRVC_DATA_32UUID, - - /** Service Data - 128-bit UUID */ - CY_BLE_GAP_ADV_SRVC_DATA_128UUID, - - /** 3D Information Data */ - CY_BLE_GAP_ADV_3D_INFO_DATA = 0x3D, - - /** Manufacturer Specific Data */ - CY_BLE_GAP_ADV_MANUFACTURER_SPECIFIC_DATA = 0xFF -}cy_en_ble_gap_adv_assign_numbers_t; - -/** GAPP advertising configuration parameters structure */ -typedef struct -{ - /** The minimum interval for fast advertising the data and establishing the LE Connection */ - uint16_t fastAdvIntervalMin; - - /** The maximum interval for fast advertising the data and establishing the LE Connection */ - uint16_t fastAdvIntervalMax; - - /** The timeout value of fast advertising with fast advertising interval parameters */ - uint16_t fastAdvTimeOut; - - /** Slow advertising enable */ - uint8_t slowAdvEnable; - - /** The minimum interval for slow advertising the data and establishing the LE Connection */ - uint16_t slowAdvIntervalMin; - - /** The maximum interval for slow advertising the data and establishing the LE Connection */ - uint16_t slowAdvIntervalMax; - - /** The timeout value of slow advertising with slow advertising interval parameters */ - uint16_t slowAdvTimeOut; -}cy_stc_ble_gapp_adv_params_t; - -/** GAPC advertising configuration parameters structure */ -typedef struct -{ - /** The scan interval when operating in Fast connection */ - uint16_t fastScanInterval; - - /** Defines the scan window when operating in Fast connection */ - uint16_t fastScanWindow; - - /** The timeout value of scanning with fast scan parameters */ - uint16_t fastScanTimeOut; - - /** Slow scan enable/disable */ - uint8_t slowScanEnabled; - - /** The scan interval when operating in Slow connection */ - uint16_t slowScanInterval; - - /** Defines the scan window when operating in Slow connection */ - uint16_t slowScanWindow; - - /** The timeout value of scanning with Slow scan parameters */ - uint16_t slowScanTimeOut; - - /** The minimum permissible connection time value to be used during a connection event */ - uint16_t gapcConnectionIntervalMin; - - /** The maximum permissible connection time value to be used during a connection event */ - uint16_t gapcConnectionIntervalMax; - - /** Defines the maximum time between two received Data Packet PDUs before - * the connection is considered lost */ - uint16_t gapcConnectionSlaveLatency; - - /** Defines the LE link supervision timeout interval */ - uint16_t gapcConnectionTimeOut; -}cy_stc_ble_gapc_scan_params_t; - -/** Store BLE Application Data parameter into flash */ -typedef struct -{ - /** Source buffer*/ - const uint8_t *srcBuff; - - /** Destination buffer */ - const uint8_t *destAddr; - - /** Source buffer length */ - uint32_t buffLen; - - /** Write mode: blocking (default) / non-blocking */ - uint32_t writeMode; - -} cy_stc_ble_app_flash_param_t; - - -/** @} group_ble_common_api_gap_definitions */ - -/*************************************** -* API Constants -***************************************/ - - -#define CY_BLE_AD_TYPE_MORE16UUID (0x02u) -#define CY_BLE_AD_TYPE_CMPL16UUID (0x03u) -#define CY_BLE_AD_TYPE_MORE32UUID (0x04u) -#define CY_BLE_AD_TYPE_CMPL32UUID (0x05u) -#define CY_BLE_AD_TYPE_MORE128UUID (0x06u) -#define CY_BLE_AD_TYPE_CMPL128UUID (0x07u) - -#define CY_BLE_AD_TYPE_SERVICE_DATA (0x16u) -#define CY_BLE_AD_SERVICE_DATA_OVERHEAD (0x03u) - -#define CY_BLE_DISCOVERY_IDLE (0x00u) -#define CY_BLE_DISCOVERY_SERVICE (0x01u) -#define CY_BLE_DISCOVERY_CHAR (0x02u) -#define CY_BLE_DISCOVERY_DESCR (0x03u) -#define CY_BLE_DISCOVERY_DONE (0x04u) - -/* Cy_BLE_NextCharDscrDiscovery parameters */ -#define CY_BLE_DISCOVERY_INIT (0x00u) -#define CY_BLE_DISCOVERY_CONTINUE (0x01u) - -#define CY_BLE_SFLASH_DIE_X_MASK (0x3Fu) -#define CY_BLE_SFLASH_DIE_X_BITS (6u) -#define CY_BLE_SFLASH_DIE_Y_MASK (0x3Fu) -#define CY_BLE_SFLASH_DIE_Y_BITS (6u) -#define CY_BLE_SFLASH_DIE_XY_BITS (CY_BLE_SFLASH_DIE_X_BITS + CY_BLE_SFLASH_DIE_Y_BITS) -#define CY_BLE_SFLASH_DIE_WAFER_MASK (0x1Fu) -#define CY_BLE_SFLASH_DIE_WAFER_BITS (5u) -#define CY_BLE_SFLASH_DIE_XYWAFER_BITS (CY_BLE_SFLASH_DIE_XY_BITS + CY_BLE_SFLASH_DIE_WAFER_BITS) -#define CY_BLE_SFLASH_DIE_LOT_MASK (0x7Fu) -#define CY_BLE_SFLASH_DIE_LOT_BITS (7u) - -/* Device address stored by user in ROW4 of the SFLASH */ -#define CY_BLE_SFLASH_DEVICE_ADDRESS_PTR ((cy_stc_ble_gap_bd_addr_t*)(SFLASH->BLE_DEVICE_ADDRESS)) - -#define CY_BLE_AD_STRUCTURE_MAX_LENGTH (31u) - -/* AD types for complete, shortened local name and device address */ -#define CY_BLE_SHORT_LOCAL_NAME (0x08u) /**< Shortened Local Name */ -#define CY_BLE_COMPLETE_LOCAL_NAME (0x09u) /**< Complete Local Name */ -#define CY_BLE_ADV_DEVICE_ADDR (0x1Bu) /**< LE Bluetooth Device Address */ - - -#define CY_BLE_ADVERTISING_FAST (0x00u) -#define CY_BLE_ADVERTISING_SLOW (0x01u) -#define CY_BLE_ADVERTISING_CUSTOM (0x02u) - -#define CY_BLE_SCANNING_FAST (0x00u) -#define CY_BLE_SCANNING_SLOW (0x01u) -#define CY_BLE_SCANNING_CUSTOM (0x02u) - -#define CY_BLE_PENDING_STACK_FLASH_WRITE_BIT (0x01u) -#define CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT (0x02u) -#define CY_BLE_PENDING_CCCD_FLASH_CLEAR_BIT (0x04u) -#define CY_BLE_PENDING_CCCD_FLASH_CLEAR_ALL_BIT (0x08u) -#define CY_BLE_PENDING_CCCD_FLASH_CLEAR_MASK \ - (CY_BLE_PENDING_CCCD_FLASH_CLEAR_BIT | CY_BLE_PENDING_CCCD_FLASH_CLEAR_ALL_BIT) - - -/** - * \addtogroup group_ble_common_api_macros - * @{ - */ - -/* GAP Advertisement Flags */ -#define CY_BLE_GAP_ADV_FLAG_LE_LIMITED_DISC_MODE (0x01u) /**< LE Limited Discoverable Mode. */ -#define CY_BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE (0x02u) /**< LE General Discoverable Mode. */ -#define CY_BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED (0x04u) /**< BR/EDR not supported. */ -#define CY_BLE_GAP_ADV_FLAG_LE_BR_EDR_CONTROLLER (0x08u) /**< Simultaneous LE and BR/EDR, Controller. */ -#define CY_BLE_GAP_ADV_FLAG_LE_BR_EDR_HOST (0x10u) /**< Simultaneous LE and BR/EDR, Host. */ -#define CY_BLE_GAP_ADV_FLAGS_PACKET_LENGTH (0x02u) /**< Length of flags in an advertisement packet */ - -/* GAP Advertising interval min and max */ -#define CY_BLE_GAP_ADV_ADVERT_INTERVAL_MIN (0x0020u) /**< Minimum Advertising interval in 625 us units, - * i.e. 20 ms. */ -#define CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN (0x00A0u) /**< Minimum Advertising interval in 625 us units - * for non connectable mode, i.e. 100 ms. */ -#define CY_BLE_GAP_ADV_ADVERT_INTERVAL_MAX (0x4000u) /**< Maximum Advertising interval in 625 us units, - * i.e. 10.24 s. */ -#define CY_BLE_GAP_ADV_ADVERT_INTERVAL_PACKET_LENGTH (0x03u) /**< Length of the Advertising Interval AD type in - * an advertisement packet */ -#define CY_BLE_GAPC_CONNECTING_TIMEOUT (30u) /**< Seconds */ -#define CY_BLE_INVALID_CONN_HANDLE_VALUE (0xFFu) /**< Invalid Connection Handle Value */ - -/* Write mode for Cy_BLE_StoreAppData */ -#define CY_BLE_STORE_DATA_MODE_BLOCKING (0x0u) /**< Blocking write */ -#define CY_BLE_STORE_DATA_MODE_NON_BLOCKING (0x1u) /**< Non-blocking write */ - -/** @} group_ble_common_api_macros */ - -/*************************************** -* Private Function Prototypes -***************************************/ -void Cy_BLE_ServiceInit(void); -uint32_t Cy_BLE_GetDiscoveryIdx(cy_stc_ble_conn_handle_t connHandle); - - -/*************************************** -* Function Prototypes -***************************************/ -/** - * \addtogroup group_ble_common_api_functions - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_StoreAppData(const cy_stc_ble_app_flash_param_t *param); - - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) -cy_en_ble_api_result_t Cy_BLE_StoreBondingData(void); -cy_en_ble_api_result_t Cy_BLE_GAP_RemoveBondedDevice(cy_stc_ble_gap_bd_addr_t* bdAddr); -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - -/** @} group_ble_common_api_functions */ - - -/** - * \addtogroup group_ble_common_api_gap_peripheral_functions - * @{ - */ - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) -cy_en_ble_api_result_t Cy_BLE_GAPP_StartAdvertisement(uint8_t advertisingIntervalType, uint8_t advertisingParamIndex); -cy_en_ble_api_result_t Cy_BLE_GAPP_StopAdvertisement(void); - -/** \cond IGNORE */ -void Cy_BLE_ChangeAdDeviceAddress(const cy_stc_ble_gap_bd_addr_t* bdAddr, uint8_t dest); -/** \endcond */ - -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL */ - -/** @} group_ble_common_api_gap_peripheral_functions */ - -/** - * \addtogroup group_ble_common_api_gap_central_functions - * @{ - */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) -cy_en_ble_api_result_t Cy_BLE_GAPC_StartScan(uint8_t scanningIntervalType, uint8_t scanParamIndex); -cy_en_ble_api_result_t Cy_BLE_GAPC_StopScan(void); -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER */ - -#if (CY_BLE_GAP_ROLE_CENTRAL) -cy_en_ble_api_result_t Cy_BLE_GAPC_ConnectDevice(const cy_stc_ble_gap_bd_addr_t * address, uint8_t centralParamIndex); -cy_en_ble_api_result_t Cy_BLE_GAPC_CancelDeviceConnection(void); -#endif /* CY_BLE_GAP_ROLE_CENTRAL */ - -/** @} group_ble_common_api_gap_central_functions */ - - -/*************************************** -* External data references -***************************************/ -extern volatile uint8_t cy_ble_eventHandlerFlag; -extern cy_stc_ble_gap_bd_addr_t *cy_ble_sflashDeviceAddress; -extern cy_stc_ble_gap_bd_addr_t cy_ble_deviceAddress; -extern cy_en_ble_state_t cy_ble_state; - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) -extern cy_stc_ble_gap_auth_info_t cy_ble_authInfo[CY_BLE_CONFIG_AUTH_INFO_COUNT]; -#endif /* ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) */ - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) -extern cy_en_ble_adv_state_t cy_ble_advState; -extern uint8_t cy_ble_advIndex; -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) -extern cy_en_ble_scan_state_t cy_ble_scanState; -extern uint8_t cy_ble_scanIndex; -#endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) */ - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) -extern cy_stc_ble_conn_handle_t cy_ble_connHandle[CY_BLE_CONN_COUNT]; -extern cy_en_ble_conn_state_t cy_ble_connState[CY_BLE_CONN_COUNT]; -#endif /* ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) -extern cy_stc_ble_gapc_disc_info_t cy_ble_discoveryInfo[CY_BLE_GAPC_CONF_COUNT]; -#endif /* CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER */ - -#if (CY_BLE_GAP_ROLE_CENTRAL) -extern cy_stc_ble_gapc_conn_info_t cy_ble_connectionParameters; -extern cy_stc_ble_timer_info_t cy_ble_connectingTimeout; -#endif /* CY_BLE_GAP_ROLE_CENTRAL */ - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) -extern cy_stc_ble_gapp_disc_mode_info_t cy_ble_discoveryModeInfo[CY_BLE_GAPP_CONF_COUNT]; -extern cy_stc_ble_gapp_disc_param_t cy_ble_discoveryParam[CY_BLE_GAPP_CONF_COUNT]; -extern cy_stc_ble_gapp_disc_data_t cy_ble_discoveryData[CY_BLE_GAPP_CONF_COUNT]; -extern cy_stc_ble_gapp_scan_rsp_data_t cy_ble_scanRspData[CY_BLE_GAPP_CONF_COUNT]; -#endif /* CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER */ - - - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - -/** This is a two-bit variable that contains status of pending write to flash operation. - * This variable is initialized to zero in Cy_BLE_Init(). - * CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT flag is set after write to CCCD event when a - * peer device supports bonding (cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING). - * CY_BLE_PENDING_STACK_FLASH_WRITE_BIT flag is set after CY_BLE_EVT_PENDING_FLASH_WRITE event. - * Cy_BLE_StoreBondingData() should be called to store pending bonding data. - * This function automatically clears pending bits after write operation is complete. - */ -extern uint8_t cy_ble_pendingFlashWrite; - -/** Bonding type setting of peer device, CY_BLE_GAP_BONDING_NONE or CY_BLE_GAP_BONDING. - * It is initialized after pairing with peer device and used for cy_ble_pendingFlashWrite variable - * setting. - */ -extern uint8_t cy_ble_peerBonding[CY_BLE_CONN_COUNT]; - - -#endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - -/*************************************** -* Exported Functions (MACROS) -***************************************/ -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) - -/** - * \addtogroup group_ble_common_api_functions - * @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GetConnHandleIdx -***************************************************************************//** -* This function returns the index of connHandle in cy_ble_connHandle which correspond to -* input parameter -* -* \param connHandle: The connection handle. -* -* \return -* retValue - the index of connHandle -* -******************************************************************************/ -__STATIC_INLINE uint8_t Cy_BLE_GetConnHandleIdx(cy_stc_ble_conn_handle_t connHandle) -{ - uint8_t idx; - uint8_t retValue = CY_BLE_CONN_COUNT; - - for(idx = 0u; idx < CY_BLE_CONN_COUNT; idx++) - { - if(cy_ble_connHandle[idx].bdHandle == connHandle.bdHandle) - { - retValue = idx; - break; - } - } - if(retValue == CY_BLE_CONN_COUNT) - { - /* HALT in debug mode */ - CY_ASSERT(retValue != CY_BLE_CONN_COUNT); - retValue = 0u; - } - - return(retValue); -} -#endif /* ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) */ - -/****************************************************************************** -* Function Name: Cy_BLE_GetState -***************************************************************************//** -* This function is used to determine the current state of the component -* state machine. -* -* The component is in the state CY_BLE_STATE_INITIALIZING after the Cy_BLE_Start() -* is called and until the CY_BLE_EVT_STACK_ON event is not received. After -* successful initialization the state is changed to CY_BLE_STATE_ON. -* -* For GAP Central role when the Cy_BLE_GAPC_ConnectDevice() is called, the state -* is changed to CY_BLE_STATE_CONNECTING. After successful connection indicated -* by CY_BLE_EVT_GAP_DEVICE_CONNECTED or CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE -* event or the timeout indicated by CY_BLE_EVT_TIMEOUT event, the state is -* changed to CY_BLE_STATE_ON. -* -* \return -* * CY_BLE_STATE_STOPPED - BLE is turned off -* * CY_BLE_STATE_INITIALIZING, - Initializing state -* * CY_BLE_STATE_ON - BLE is turned on -* * CY_BLE_STATE_CONNECTING - Connecting -* -******************************************************************************/ -#define Cy_BLE_GetState() (cy_ble_state) - - -/****************************************************************************** -* Function Name: Cy_BLE_SetState -***************************************************************************//** -* -* Used to set the component state machine's state. -* -* \param state: The desired state to which the event handler's -* state machine should be set. The parameter state is a variable -* of type cy_en_ble_state_t. -* -* \return -* None -* -******************************************************************************/ -#define Cy_BLE_SetState(state) (cy_ble_state = (state)) - -#if (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) - - -/****************************************************************************** -* Function Name: Cy_BLE_GetAdvertisementState -***************************************************************************//** -* This function returns the state of the link layer hardware advertisement -* engine. -* -* When Cy_BLE_GAPP_StartAdvertisement() is called, the state is set to -* CY_BLE_ADV_STATE_ADV_INITIATED. It automatically changes to -* CY_BLE_ADV_STATE_ADVERTISING when CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP -* event is received. When Cy_BLE_GAPP_StopAdvertisement() is called, the -* state is set to CY_BLE_ADV_STATE_STOP_INITIATED. It automatically changes -* to CY_BLE_ADV_STATE_STOPPED when the CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP -* event is received. -* -* \return -* cy_en_ble_adv_state_t - The current advertising state. -* -******************************************************************************/ -__STATIC_INLINE cy_en_ble_adv_state_t Cy_BLE_GetAdvertisementState(void) -{ - return(cy_ble_advState); -} - -/****************************************************************************** -* Function Name: Cy_BLE_SetAdvertisementState -***************************************************************************//** -* -* Used to set the state of the link layer hardware advertisement engine. -* -* \param state: The desired state. -* -* \return -* None -* -******************************************************************************/ -__STATIC_INLINE void Cy_BLE_SetAdvertisementState(cy_en_ble_adv_state_t state) -{ - cy_ble_advState = state; -} - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_BROADCASTER) */ - -#if (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) - -/****************************************************************************** -* Function Name: Cy_BLE_GetScanState -***************************************************************************//** -* This returns the state of the link layer hardware scan engine. -* -* When Cy_BLE_GAPC_StartScan() is called the state is set to -* CY_BLE_SCAN_STATE_SCAN_INITIATED. It automatically changes to -* CY_BLE_ SCAN _STATE_SCANNING when the CY_BLE_EVT_GAPC_SCAN_START_STOP event is -* received. When Cy_BLE_GAPC_StopScan() is called, the state is set to -* CY_BLE_SCAN_STATE_STOP_INITIATED. It automatically changes to -* CY_BLE_SCAN_STATE_STOPPED when the CY_BLE_EVT_GAPC_SCAN_START_STOP event is -* received. -* -* \return -* cy_en_ble_scan_state_t - The current scan state. -* -******************************************************************************/ -__STATIC_INLINE cy_en_ble_scan_state_t Cy_BLE_GetScanState(void) -{ - return(cy_ble_scanState); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_SetScanState -***************************************************************************//** -* -* Used to set the state of the link layer hardware scan engine. -* -* \param state: The desired state. -* -* \return -* None -* -******************************************************************************/ -__STATIC_INLINE void Cy_BLE_SetScanState(cy_en_ble_scan_state_t state) -{ - cy_ble_scanState = state; -} - -#endif /* (CY_BLE_GAP_ROLE_CENTRAL || CY_BLE_GAP_ROLE_OBSERVER) */ - - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) - -/****************************************************************************** -* Function Name: Cy_BLE_GetConnectionState -***************************************************************************//** -* This function returns the state of the BLE link for the specified connection -* handle. -* -* The state is set to CY_BLE_CONN_CONNECTED when CY_BLE_EVT_GATT_CONNECT_IND -* event is received with the corresponding connection handle. -* The state is set to CY_BLE_CONN_DISCONNECTED when the -* CY_BLE_EVT_GATT_DISCONNECT_IND event is received. -* -* For GATT Client role when Cy_BLE_GATTC_StartDiscovery() is called, the state -* indicates the current flow of the discovery procedure by -* CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING, -* CY_BLE_CONN_STATE_CLIENT_INCL_DISCOVERING, -* CY_BLE_CONN_STATE_CLIENT_CHAR_DISCOVERING, -* CY_BLE_CONN_STATE_CLIENT_DESCR_DISCOVERING and changes to -* CY_BLE_CONN_STATE_CLIENT_DISCOVERED when the procedure successfully completes. -* -* The state changes from CY_BLE_CONN_STATE_CLIENT_DISCOVERED to -* CY_BLE_CONN_STATE_CLIENT_DISCONNECTED_DISCOVERED when -* the CY_BLE_EVT_GATT_DISCONNECT_IND event is received. -* The state comes backs to CY_BLE_CONN_STATE_CLIENT_DISCOVERED when -* CY_BLE_EVT_GATT_CONNECT_IND event is received and resolvable device -* address is not changed. -* -* \param connHandle: The connection handle. -* -* \return -* cy_en_ble_conn_state_t - The current client state. -* -******************************************************************************/ -__STATIC_INLINE cy_en_ble_conn_state_t Cy_BLE_GetConnectionState(cy_stc_ble_conn_handle_t connHandle) -{ - return((connHandle.attId < CY_BLE_CONN_COUNT) ? cy_ble_connState[connHandle.attId] : CY_BLE_CONN_STATE_DISCONNECTED); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_SetConnectionState -***************************************************************************//** -* -* Used to set BLE link state for the specified connection handle. -* -* \param connHandle: Peer device handle -* \param state: The state that is desired to be set -* -******************************************************************************/ -__STATIC_INLINE void Cy_BLE_SetConnectionState(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_conn_state_t state) -{ - if(connHandle.attId < CY_BLE_CONN_COUNT) - { - cy_ble_connState[connHandle.attId] = state; - } - else - { - /* Halt in debug mode*/ - CY_ASSERT(connHandle.attId >= CY_BLE_CONN_COUNT); - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_GetNumOfActiveConn -***************************************************************************//** -* -* Used to get active number of connections. -* -* \return -* connNum - number of active connections -* -******************************************************************************/ -__STATIC_INLINE uint8_t Cy_BLE_GetNumOfActiveConn(void) -{ - uint32_t i; - uint8_t connNum = 0u; - - for(i = 0u; i < CY_BLE_CONN_COUNT; i++) - { - if(cy_ble_connState[i] >= CY_BLE_CONN_STATE_CONNECTED) - { - connNum++; - } - } - - return(connNum); -} - -/****************************************************************************** -* Function Name: Cy_BLE_GetConnHandleByBdHandle -***************************************************************************//** -* -* Used to get connection handle by bdHandle -* This function halts in debug mode if bdHandle does not exist in the connected device -* list -* -* \param bdHandle: Peer device handle -* -* \return -* connHandle: Full connection handle. -* connHandle.attId = CY_BLE_INVALID_CONN_HANDLE_VALUE: invalid bdHandle -* -******************************************************************************/ -__STATIC_INLINE cy_stc_ble_conn_handle_t Cy_BLE_GetConnHandleByBdHandle(uint8_t bdHandle) -{ - uint32_t i; - cy_stc_ble_conn_handle_t cHandle = - { - .attId = CY_BLE_INVALID_CONN_HANDLE_VALUE, - .bdHandle = CY_BLE_INVALID_CONN_HANDLE_VALUE - }; - - for(i = 0u; i < CY_BLE_CONN_COUNT; i++) - { - if((Cy_BLE_GetConnectionState(cy_ble_connHandle[i]) >= CY_BLE_CONN_STATE_CONNECTED) && - (cy_ble_connHandle[i].bdHandle == bdHandle)) - { - cHandle = cy_ble_connHandle[i]; - break; - } - } - if(cHandle.attId == CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - /* HALT in debug mode */ - CY_ASSERT(cHandle.attId != CY_BLE_INVALID_CONN_HANDLE_VALUE); - } - - return cHandle; -} - -#endif /* ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL)) */ -/** @} group_ble_common_api_functions */ - -#endif /* CY_BLE_MODE_PROFILE */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_GAP_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gatt.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gatt.c deleted file mode 100644 index 0b42a6f252..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gatt.c +++ /dev/null @@ -1,800 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_gatt.c -* \version 2.0 -* -* \brief -* This file contains the source code for the GATT API of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE) - -/*************************************** -* Global variables -***************************************/ -#if (CY_BLE_GATT_ROLE_SERVER) - -#if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) -uint8_t cy_ble_attValuesCccdMultiple[CY_BLE_CONN_COUNT][CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE]; -#endif /* (CY_BLE_GATT_DB_CCCD_COUNT != 0u) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_ReInitGattDb -***************************************************************************//** -* -* Reinitializes the GATT database. -* -* \return -* cy_en_ble_api_result_t: A function result states if it succeeded or failed with -* error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | GATT database was reinitialized successfully. -* CY_BLE_ERROR_INVALID_STATE | If the function is called in any state except CY_BLE_STATE_ON. -* CY_BLE_ERROR_INVALID_PARAMETER | If the Database has zero entries or is a NULL pointer. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_ReInitGattDb(void) -{ - cy_en_ble_api_result_t apiResult; - - if(Cy_BLE_GetState() == CY_BLE_STATE_ON) - { - cy_stc_ble_gatts_db_info_t dbInfoParam = - { - .gattDbPtr = cy_ble_configPtr->gattDB, - .gattDbTotalEntries = cy_ble_configPtr->params->gattDbIndexCount, - .gattDbMaxValue = CY_BLE_CONFIG_GATT_DB_MAX_VALUE_LEN - }; - apiResult = Cy_BLE_GATTS_DbRegister(&dbInfoParam); - } - else - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for GATT service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t: A function returns one of the following status -* values. -* -* Error Codes | Description -* -------------------- | ----------- -* CY_BLE_GATT_ERR_NONE | Write is successful. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - /* Client Characteristic Configuration descriptor write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_configPtr->gatts->cccdHandle) - { - /* Store value to database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .flags = CY_BLE_GATT_DB_PEER_INITIATED, - .offset = 0u - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTS_INDICATION_ENABLED, eventParam); - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTS_INDICATION_DISABLED, eventParam); - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_WriteAttributeValueCCCD -***************************************************************************//** -* -* This function extends Cy_BLE_GATTS_WriteAttributeValue API to support -* storing of separate CCCD values for each (separate) connections. -* -* This function is used to write to the value field of the specified attribute -* in the GATT database of a GATT Server. If attribute is CCCD, the value is -* stored in specific CCCD storages. -* This is a blocking function. No event is generated on calling this function. -* -* If a peer device connected to the GATT Server initiates a write operation, -* this function is executed on the GATT Server. During such a call, the function -* checks for the attribute permissions (flags) before executing the write -* operation by calling. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_attr_val_info_t'. -* -* \return -* Return value is GATT Error code specified in 'cy_en_ble_gatt_err_code_t -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_WriteAttributeValueCCCD(cy_stc_ble_gatts_db_attr_val_info_t *param) -{ - cy_en_ble_gatt_err_code_t errCode; - - errCode = Cy_BLE_GATTS_WriteAttributeValue(param); - -#if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) - /* Support separate CCCD value for each connection */ - if((errCode == CY_BLE_GATT_ERR_NONE) && - (CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(param->handleValuePair.attrHandle, CY_BLE_GATT_DB_CCCD_ATTR))) - { - (void)memcpy((void*)&cy_ble_attValuesCccdMultiple[param->connHandle.attId] - [CY_BLE_GATT_DB_ATTR_GET_CCCD_IDX(param->handleValuePair.attrHandle)], - (void*)param->handleValuePair.value.val, (uint32_t)param->handleValuePair.value.len); - } -#endif /* (CY_BLE_GATT_DB_CCCD_COUNT != 0u) */ - - return(errCode); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_ReadAttributeValueCCCD -***************************************************************************//** -* -* This function extends Cy_BLE_GATTS_ReadAttributeValue API to support -* re-storing of separate CCCD values for each(separate) connections. -* -* This function is used to read the value field of the specified attribute from -* the GATT database in a GATT Server. If attribute is CCCD, the value is -* restored from specific CCCD storages. -* This is a blocking function. No event is generated on calling this function. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_attr_val_info_t'. -* param-> offset: not used, to be ignored -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation -* CY_BLE_GATT_ERR_INVALID_HANDLE | 'handleValuePair.attrHandle' is not valid -* CY_BLE_GATT_ERR_READ_NOT_PERMITTED | Read operation is not permitted on this attribute -* CY_BLE_GATT_ERR_UNLIKELY_ERROR | Invalid arguments passed -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_ReadAttributeValueCCCD(cy_stc_ble_gatts_db_attr_val_info_t *param) -{ - cy_en_ble_gatt_err_code_t errCode; - - if((param->handleValuePair.attrHandle == 0u) || (param->handleValuePair.attrHandle > CY_BLE_GATT_DB_INDEX_COUNT) || - (param->connHandle.attId >= CY_BLE_CONN_COUNT)) - { - errCode = CY_BLE_GATT_ERR_INVALID_HANDLE; - } - else - { - #if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) - if(CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(param->handleValuePair.attrHandle, CY_BLE_GATT_DB_CCCD_ATTR)) - { - CY_BLE_GATT_DB_ATTR_SET_GEN_VALUE(param->handleValuePair.attrHandle, - (void*)&cy_ble_attValuesCccdMultiple[param->connHandle.attId] - [CY_BLE_GATT_DB_ATTR_GET_CCCD_IDX(param->handleValuePair.attrHandle)], - CY_BLE_CCCD_LEN); - } - #endif /* (CY_BLE_GATT_DB_CCCD_COUNT != 0u) */ - - errCode = Cy_BLE_GATTS_ReadAttributeValue(param); - } - - return(errCode); -} - -#if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_ReadAttributeValueCCCDReqHandler -***************************************************************************//** -* -* This function is used to handle CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ -* request and updated CCCD value in GATT database in a GATT Server for -* multi-connection support. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_char_val_read_req_t'. -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation -* CY_BLE_GATT_ERR_INVALID_HANDLE | 'handleValuePair.attrHandle' is not valid -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_ReadAttributeValueCCCDReqHandler(const cy_stc_ble_gatts_char_val_read_req_t *param) -{ - cy_en_ble_gatt_err_code_t errCode = CY_BLE_GATT_ERR_NONE; - - if((param->attrHandle == 0u) || (param->attrHandle > CY_BLE_GATT_DB_INDEX_COUNT) || - (param->connHandle.attId >= CY_BLE_CONN_COUNT)) - { - errCode = CY_BLE_GATT_ERR_INVALID_HANDLE; - } - else - { - if(CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(param->attrHandle, CY_BLE_GATT_DB_CCCD_ATTR)) - { - CY_BLE_GATT_DB_ATTR_SET_GEN_VALUE(param->attrHandle, - (void*)&cy_ble_attValuesCccdMultiple[param->connHandle.attId] - [CY_BLE_GATT_DB_ATTR_GET_CCCD_IDX(param->attrHandle)], - CY_BLE_CCCD_LEN); - } - } - - return(errCode); -} - -#endif /* (CY_BLE_GATT_DB_CCCD_COUNT != 0u) */ - -#endif /* (CY_BLE_GATT_ROLE_SERVER) */ - -#if (CY_BLE_GATT_ROLE_CLIENT) - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_StartDiscovery -***************************************************************************//** -* -* Starts the automatic server discovery process. -* -* Discovery procedure is based on the user configuration. It discovers only -* services, characteristics, descriptors which were declared in the -* GATT database. Discovery procedure has the following flow: -* - discovering primary services by -* BLE Stack function Cy_BLE_GATTC_DiscoverPrimaryServices(); -* - discovering included services by -* BLE Stack function Cy_BLE_GATTC_FindIncludedServices(); -* - discovering characteristics for available services by -* BLE Stack function Cy_BLE_GATTC_DiscoverCharacteristicDescriptors(); -* - discovering characteristic descriptors by -* BLE Stack function CyBle_GattcDiscoverAllCharacteristicDescriptors(); -* -* During the discovery procedure the discovery-specific stack events are -* handled by the component and thus aren't passed to the application callback: -* CY_BLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP, CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP, -* CY_BLE_EVT_GATTC_FIND_INFO_RSP, CY_BLE_EVT_GATTC_ERROR_RSP. -* -* After discovering procedure all information about available services is -* stored in cy_stc_ble_disc_srvc_info_t structures, and discovered -* attributes handles are stored in service-specific client structures, -* such as cy_stc_ble_basc_t for Battery Service or cy_stc_ble_hrsc_t for -* Heart Rate Service. -* -* The following events may be generated after calling this function: -* CY_BLE_EVT_GATTC_DISCOVERY_COMPLETE - event is generated when the remote -* device was successfully discovered. -* CY_BLE_EVT_GATTC_ERROR_RSP - is generated if the device discovery -* has failed. -* CY_BLE_EVT_GATTC_SRVC_DUPLICATION - is generated if duplicate service -* record was found during the server -* device discovery. -* CY_BLE_EVT_GATTC_CHAR_DUPLICATION - is generated if duplicate service's -* characteristic descriptor record was -* found during the server device -* discovery. -* CY_BLE_EVT_GATTC_DESCR_DUPLICATION - is generated if duplicate service's -* characteristic descriptor record was -* found during the server device -* discovery. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function -* succeeded or failed. -* The following are possible error codes: -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
Error CodesDescription
CY_BLE_SUCCESSOn successful operation
CY_BLE_ERROR_INVALID_PARAMETER'connHandle' value does not represent any existing entry.
CY_BLE_ERROR_INVALID_OPERATIONThe operation is not permitted
CY_BLE_ERROR_MEMORY_ALLOCATION_FAILEDMemory allocation failed
CY_BLE_ERROR_INVALID_STATEIf the function is called in any state except connected or discovered
-* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_StartDiscovery(cy_stc_ble_conn_handle_t connHandle) -{ - uint32_t discIdx; - cy_en_ble_api_result_t apiResult; - cy_en_ble_conn_state_t connState = Cy_BLE_GetConnectionState(connHandle); - - if((connState != CY_BLE_CONN_STATE_CONNECTED) && (connState != CY_BLE_CONN_STATE_CLIENT_DISCOVERED)) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else - { - /* Clean old discovery information */ - uint32_t i; - - /* Register connHandle in cy_ble_discovery structure */ - apiResult = Cy_BLE_GATTC_AddConnHandle(connHandle); - discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - for(i = 0u; i < (uint8_t)CY_BLE_SRVI_COUNT; i++) - { - (void)memset(&cy_ble_serverInfo[discIdx][i].range, 0, sizeof(cy_ble_serverInfo[0][0].range)); - } - } - - if(apiResult == CY_BLE_SUCCESS) - { - cy_stc_ble_gattc_read_by_group_req_t reqParam = - { - .connHandle = connHandle - }; - - cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle = CY_BLE_GATT_ATTR_HANDLE_START_RANGE; - cy_ble_discovery[discIdx].gattcDiscoveryRange.endHandle = CY_BLE_GATT_ATTR_HANDLE_END_RANGE; - reqParam.range = cy_ble_discovery[discIdx].gattcDiscoveryRange; - - Cy_BLE_ServiceInit(); - - - apiResult = Cy_BLE_GATTC_DiscoverPrimaryServices(&reqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 1u; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_StartPartialDiscovery -***************************************************************************//** -* -* Starts the automatic server discovery process as per the range provided -* on a GATT Server to which it is connected. This function could be used for -* partial server discovery after indication received to the Service Changed -* Characteristic Value. Two events may be generated -* after calling this function - CY_BLE_EVT_GATTC_DISCOVERY_COMPLETE or -* CY_BLE_EVT_GATTC_ERROR_RSP. The CY_BLE_EVT_GATTC_DISCOVERY_COMPLETE event is -* generated when the remote device was successfully discovered. The -* CY_BLE_EVT_GATTC_ERROR_RSP is generated if the device discovery is failed. -* -* \param connHandle: The handle which consists of the device ID and ATT connection ID. -* \param startHandle: Start of affected attribute handle range. -* \param endHandle: End of affected attribute handle range. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
Error CodesDescription
CY_BLE_SUCCESSOn successful operation
CY_BLE_ERROR_INVALID_PARAMETER'connHandle' value does not represent any existing entry.
CY_BLE_ERROR_INVALID_OPERATIONThe operation is not permitted
CY_BLE_ERROR_MEMORY_ALLOCATION_FAILEDMemory allocation failed
CY_BLE_ERROR_INVALID_STATEIf the function is called in any state except connected or discovered
-* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_StartPartialDiscovery(cy_stc_ble_conn_handle_t connHandle, - cy_ble_gatt_db_attr_handle_t startHandle, - cy_ble_gatt_db_attr_handle_t endHandle) -{ - uint32_t discIdx; - cy_en_ble_api_result_t apiResult; - cy_en_ble_conn_state_t connState = Cy_BLE_GetConnectionState(connHandle); - - if((connState != CY_BLE_CONN_STATE_CONNECTED) && (connState != CY_BLE_CONN_STATE_CLIENT_DISCOVERED)) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else - { - uint32_t i; - - /* Register connHandle in cy_ble_discovery structure */ - apiResult = Cy_BLE_GATTC_AddConnHandle(connHandle); - discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Clean old discovery information of affected attribute range */ - for(i = 0u; i < (uint8_t)CY_BLE_SRVI_COUNT; i++) - { - if((cy_ble_serverInfo[discIdx][i].range.startHandle >= startHandle) && - (cy_ble_serverInfo[discIdx][i].range.startHandle <= endHandle)) - { - (void)memset(&cy_ble_serverInfo[discIdx][i].range, 0, sizeof(cy_ble_serverInfo[0u][0u].range)); - } - } - } - - if(apiResult == CY_BLE_SUCCESS) - { - cy_stc_ble_gattc_read_by_group_req_t readByGroupReqParam = - { - .connHandle = connHandle - }; - - cy_ble_discovery[discIdx].gattcDiscoveryRange.startHandle = startHandle; - cy_ble_discovery[discIdx].gattcDiscoveryRange.endHandle = endHandle; - - Cy_BLE_ServiceInit(); - - readByGroupReqParam.range = cy_ble_discovery[discIdx].gattcDiscoveryRange; - - apiResult = Cy_BLE_GATTC_DiscoverPrimaryServices(&readByGroupReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_SRVC_DISCOVERING); - cy_ble_discovery[discIdx].autoDiscoveryFlag = 1u; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP" -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_GATTC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].uuid == CY_BLE_UUID_GATT_SERVICE)) - { - if(discCharInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_SERVICE_CHANGED) - { - Cy_BLE_CheckStoreCharHandle(cy_ble_discovery[discIdx].gattc.serviceChanged); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_FIND_INFO_RSP" event. -* Based on the descriptor UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_GATTC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_GATT) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_discovery[discIdx].gattc.cccdHandle); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_GATTC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_GATT) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if(cy_ble_discovery[discIdx].charCount == 0u) - { - charRangeInfo->range.startHandle = cy_ble_discovery[discIdx].gattc.serviceChanged. - valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount]. - range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_IndicationEventHandler -***************************************************************************//** -* -* Handles the Indication Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_GATTC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - (cy_ble_discovery[discIdx].gattc.serviceChanged.valueHandle == eventParam->handleValPair.attrHandle)) - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_INDICATION, eventParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_AddConnHandle -***************************************************************************//** -* -* Register connHandle in cy_ble_discovery structure. -* -* \param connHandle: The handle which consists of the device ID and ATT connection ID. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - All client instances are used. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_AddConnHandle(cy_stc_ble_conn_handle_t connHandle) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t fFlag = (uint32_t)CY_BLE_INVALID_CONN_HANDLE_VALUE; - uint32_t i; - - /* Register connHandle in cy_ble_discovery structure */ - for(i = 0u; (i < CY_BLE_CONFIG_GATTC_COUNT) && (fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE); i++) - { - /* fFlag shows that we have already had connHandle index in cy_ble_discovery */ - if(cy_ble_discovery[i].connIndex != CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - if(cy_ble_connHandle[cy_ble_discovery[i].connIndex].bdHandle == connHandle.bdHandle) - { - fFlag = i; - } - } - } - if(fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - for(i = 0u; (i < CY_BLE_CONFIG_GATTC_COUNT) && (fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE); i++) - { - if(cy_ble_discovery[i].connIndex == CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - uint32_t j; - for(j = 0u; (j < CY_BLE_CONN_COUNT) && (fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE); j++) - { - if(cy_ble_connHandle[j].bdHandle == connHandle.bdHandle) - { - cy_ble_discovery[i].connIndex = j; - fFlag = i; - } - } - } - } - } - if(fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED; - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_RemoveConnHandle -***************************************************************************//** -* -* Unregister connHandle from cy_ble_discovery structure. -* This function removes all connHandle indexes from cy_ble_discovery structure -* if connHandle.bdHandle parameter is set to CY_BLE_INVALID_CONN_HANDLE_VALUE. -* -* \param connHandle: The handle which consists of the device ID and ATT connection ID. -* -* \return: A function result states if it succeeded or failed with -* error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If discovery information is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_RemoveConnHandle(cy_stc_ble_conn_handle_t connHandle) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t fFlag = CY_BLE_INVALID_CONN_HANDLE_VALUE; - uint32_t i; - - /* Remove connHandle from cy_ble_discovery structure */ - if(connHandle.bdHandle != CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - for(i = 0u; (i < CY_BLE_CONFIG_GATTC_COUNT) && (fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE); i++) - { - /* fFlag shows that we found connHandle in cy_ble_discovery */ - if(cy_ble_connHandle[cy_ble_discovery[i].connIndex].bdHandle == connHandle.bdHandle) - { - (void)memset(&cy_ble_discovery[i], 0, sizeof(cy_stc_ble_discovery_t)); - cy_ble_discovery[i].connIndex = CY_BLE_INVALID_CONN_HANDLE_VALUE; - fFlag = i; - } - } - if(fFlag == CY_BLE_INVALID_CONN_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_NO_DEVICE_ENTITY; - } - } - else - { - /* Remove all connHandle indexes from cy_ble_discovery structure */ - (void)memset(&cy_ble_discovery, 0, sizeof(cy_ble_discovery)); - - /* Update cy_ble_discovery[].connIndex with init values (CY_BLE_INVALID_CONN_HANDLE_VALUE) */ - for(i = 0u; i < CY_BLE_CONFIG_GATTC_COUNT; i++) - { - cy_ble_discovery[i].connIndex = CY_BLE_INVALID_CONN_HANDLE_VALUE; - } - } - - /* Clean old connection handle information */ - for(i = 0u; i < CY_BLE_CONN_COUNT; i++) - { - if(cy_ble_connHandle[i].bdHandle == connHandle.bdHandle) - { - cy_ble_connHandle[i].bdHandle = CY_BLE_INVALID_CONN_HANDLE_VALUE; - cy_ble_connHandle[i].attId = CY_BLE_INVALID_CONN_HANDLE_VALUE; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_GetDiscoveryIdx -***************************************************************************//** -* -* This function returns the index of discovery structure according to connHandle. -* -* \return -* uint8_t: index of discovery structure -* CY_BLE_CONFIG_GATTC_COUNT: index is not found for connHandle -* -******************************************************************************/ -uint32_t Cy_BLE_GetDiscoveryIdx(cy_stc_ble_conn_handle_t connHandle) -{ - uint32_t idx; - uint32_t retValue = CY_BLE_CONFIG_GATTC_COUNT; - - for(idx = 0u; ((idx < CY_BLE_CONFIG_GATTC_COUNT) && (retValue == CY_BLE_CONFIG_GATTC_COUNT)); idx++) - { - if(cy_ble_connHandle[cy_ble_discovery[idx].connIndex].bdHandle == connHandle.bdHandle) - { - retValue = idx; - } - } - - return(retValue); -} - -#endif /* (CY_BLE_GATT_ROLE_CLIENT) */ -#endif /* defined(CY_BLE_MODE_PROFILE) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gatt.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gatt.h deleted file mode 100644 index 26477d3a2f..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gatt.h +++ /dev/null @@ -1,994 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_gatt.h -* \version 2.0 -* -* \brief -* Contains the prototypes and constants used in the BLE GATT profile. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_GATT_H -#define CY_BLE_GATT_H - -#include "BLE_config.h" -#include "cy_ble_gap.h" - - -#if (CY_BLE_MODE_PROFILE) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -#define CY_BLE_GATT_ROLE (CY_BLE_CONFIG_GATT_ROLE) -#define CY_BLE_GATT_SERVER (0x01u) -#define CY_BLE_GATT_CLIENT (0x02u) -#define CY_BLE_GATT_BOTH (CY_BLE_GATT_SERVER | CY_BLE_GATT_CLIENT) - -#define CY_BLE_GATT_ROLE_SERVER (0u != (CY_BLE_GATT_ROLE & CY_BLE_GATT_SERVER)) -#define CY_BLE_GATT_ROLE_CLIENT (0u != (CY_BLE_GATT_ROLE & CY_BLE_GATT_CLIENT)) - -#if (CY_BLE_GATT_ROLE_SERVER) - -#endif /* CY_BLE_GATT_ROLE_SERVER */ - -#define CY_BLE_GATT_DB_CCCD_COUNT (CY_BLE_CONFIG_GATT_DB_CCCD_COUNT) - -#if (CY_BLE_GATT_DB_CCCD_COUNT == 0u) - #define CY_BLE_GATT_DB_FLASH_CCCD_COUNT (1u) -#else - #define CY_BLE_GATT_DB_FLASH_CCCD_COUNT (CY_BLE_GATT_DB_CCCD_COUNT) -#endif /* CY_BLE_GATT_DB_CCCD_COUNT == 0u */ - -#define CY_BLE_CCCD_CRC_BYTE (0x1u) /**< CCCD CRC byte */ - -/** - * \addtogroup group_ble_common_api_gatt_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Service data received with read by group type response during discovery process */ -typedef struct -{ - cy_stc_ble_gatt_attr_handle_range_t range; /**< Handle range of the request */ - uint16_t uuid; /**< 16-bit UUID */ -}cy_stc_ble_disc_srvc_info_t; - -/** Service data received with read by group type response during discovery process including 128 bit UUID */ -typedef struct -{ - cy_stc_ble_gatt_attr_handle_range_t range; /**< Handle range of the request */ - cy_ble_uuid_t uuid; /**< 128-bit UUID */ -}cy_stc_ble_disc_srvc128_info_t; - -/** Service data that includes data received with read by group type response and connHandle */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< The connection handle */ - cy_stc_ble_disc_srvc128_info_t *srvcInfo; /**< Service data */ - uint8_t uuidFormat; /**< UUID Format - 16-bit (0x01) or 128-bit (0x02) */ -}cy_stc_ble_disc_srv_info_t; - -/** Included service data received with read by type response during discovery process */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< The connection handle */ - cy_ble_gatt_db_attr_handle_t inclDefHandle; /**< Included definition handle */ - cy_stc_ble_gatt_attr_handle_range_t inclHandleRange; /**< Included declaration handle range */ - cy_ble_uuid_t uuid; /**< Included UUID */ - uint8_t uuidFormat; /**< UUID Format - 16-bit (0x01) or 128-bit (0x02) */ -}cy_stc_ble_disc_incl_info_t; - -/** Characteristic data received with read by type response during discovery process */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< The connection handle */ - cy_ble_gatt_db_attr_handle_t charDeclHandle; /**< Handle for characteristic declaration */ - uint8_t properties; /**< Properties for value field */ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle to server database attribute value entry */ - cy_ble_uuid_t uuid; /**< Characteristic UUID */ - uint8_t uuidFormat; /**< UUID Format - 16-bit (0x01) or 128-bit (0x02) */ -}cy_stc_ble_disc_char_info_t; - -/** Characteristic Attribute handle + properties structure */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; -}cy_stc_ble_srvr_char_info_t; - -/** Characteristic descriptor data received with find info response during discovery process */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< The connection handle */ - cy_ble_gatt_db_attr_handle_t descrHandle; /**< Descriptor handle */ - cy_ble_uuid_t uuid; /**< Descriptor UUID */ - uint8_t uuidFormat; /**< UUID Format - 16-bit (0x01) or 128-bit (0x02) */ -}cy_stc_ble_disc_descr_info_t; - -/** Structure with Generic Attribute Service (GATTS) attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Service handle */ - cy_ble_gatt_db_attr_handle_t serviceChangedHandle; /**< Handle of the Service Changed characteristic */ - cy_ble_gatt_db_attr_handle_t cccdHandle; /**< Client Characteristic Configuration descriptor handle */ -} cy_stc_ble_gatts_t; - -/** Structure for return a possible range of the current characteristic descriptor. */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< The connection handle */ - cy_stc_ble_gatt_attr_handle_range_t range; /**< Handle range of the request */ - uint32_t srviIncIdx; /**< A non-zero value indicates that the characteristic index - * should be incremented - */ -} -cy_stc_ble_disc_range_info_t; - -/** Structure with discovered attributes information of Generic Attribute - * Service (GATTS) */ -typedef struct -{ - cy_stc_ble_srvr_char_info_t serviceChanged; /**< Handle of the Service Changed characteristic */ - cy_ble_gatt_db_attr_handle_t cccdHandle; /**< Client Characteristic Configuration descriptor handle */ -} cy_stc_ble_gattc_t; - -/** Structure to store bonding data */ -typedef struct -{ - /** Stack internal bonding data */ - uint8_t stackFlashptr[CY_BLE_STACK_FLASH_SIZE]; - - /** CCCD values */ - uint8_t attValuesCCCDFlashMemory[CY_BLE_MAX_BONDED_DEVICES + CY_BLE_CONN_COUNT][CY_BLE_GATT_DB_FLASH_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE]; - - /** Number of CCCD */ - uint8_t cccdCount; /* CY_BLE_GATT_DB_CCCD_COUNT */ - - /** Number of bonded devices */ - uint8_t boundedDevCount; /* CY_BLE_MAX_BONDED_DEVICES */ -}cy_stc_ble_flash_storage_t; - -/** BLE Configuration parameters structure */ -typedef struct -{ - /** BLESS Power enum reflecting power level values supported by BLESS radio */ - cy_en_ble_bless_pwr_lvl_t txPowerLevelAdv; - - /** BLESS Power enum reflecting power level values supported by BLESS radio */ - cy_en_ble_bless_pwr_lvl_t txPowerLevelConn; - - /** IO capability */ - cy_en_ble_gap_iocap_t securityIoCapability; - - /** Defines paring method */ - uint8_t securityPairingMethod; - - /** Silicon Device Address Enabled */ - uint8_t siliconDeviceAddressEnabled; - - /** Index count for GATT DB */ - uint16_t gattDbIndexCount; -}cy_stc_ble_params_t; - -#endif /* (CY_BLE_MODE_PROFILE) */ - -/** BLE Configuration structure */ -typedef struct -{ -#if (CY_BLE_MODE_PROFILE) - /** Pointer to advertising information structure*/ - cy_stc_ble_gapp_disc_mode_info_t *discoveryModeInfo; - - /** Pointer to advertising configuration structure*/ - cy_stc_ble_gapp_adv_params_t *gappAdvParams; - - /** Pointer to Discovery information collected by Client structure*/ - cy_stc_ble_gapc_disc_info_t *discoveryInfo; - - /** Pointer to scan configuration structure*/ - cy_stc_ble_gapc_scan_params_t *gapcScanParams; - - /** Pointer to structure to store bonding data */ - const cy_stc_ble_flash_storage_t *flashStorage; - - /** Pointer to structure with Generic Attribute Service (GATTS) attribute handles */ - const cy_stc_ble_gatts_t *gatts; - - /** Pointer to structure with Generic Access Profile Service (GAPS) attribute handles */ - const cy_stc_ble_gaps_t *gaps; - - /** Pointer to cy_ble_attValuesCCCD */ - uint8_t *attValuesCCCD; - - /** Pointer to GATT Database structure used in the GAP server */ - const cy_stc_ble_gatts_db_t *gattDB; - - /** Pointer to Authentication Parameters Information structure */ - cy_stc_ble_gap_auth_info_t *authInfo; - - /** Pointer to BLE Configuration Parameters structure */ - const cy_stc_ble_params_t *params; - - /** An application layer event callback function to - * receive service events from the BLE Component */ - cy_ble_callback_t callbackFunc; - - /** Bluetooth Device Address */ - cy_stc_ble_gap_bd_addr_t *deviceAddress; -#endif /* (CY_BLE_MODE_PROFILE) */ - - /** BLESS interrupt configuration */ - const cy_stc_sysint_t *blessIsrConfig; - -#if (CY_BLE_STACK_MODE_HOST_UART) - /** UART interrupt configuration for Host */ - const cy_stc_sysint_t *uartHostIsrConfig; - - /** UART driver configuration for Host */ - const cy_stc_scb_uart_config_t *uartHostConfig; - - /** UART driver hardware instance */ - CySCB_Type *uartHostHw; -#endif /* CY_BLE_STACK_MODE_HOST_UART */ - -#if (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) - /** UART interrupt configuration */ - const cy_stc_sysint_t *uartIsrConfig; - - /** UART driver configuration */ - const cy_stc_scb_uart_config_t *uartConfig; - - /** UART driver hardware instance */ - CySCB_Type *uartHw; -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ -}cy_stc_ble_config_t; - -/** @} group_ble_common_api_gatt_definitions */ - - -/*************************************** -* Function Prototypes -***************************************/ -/** \cond IGNORE */ -cy_en_ble_api_result_t Cy_BLE_Init(cy_stc_ble_config_t *config); -/** \endcond */ - - -#if (CY_BLE_MODE_PROFILE) - -#if (CY_BLE_GATT_ROLE_SERVER) -cy_en_ble_api_result_t Cy_BLE_GATTS_ReInitGattDb(void); -#endif /* CY_BLE_GATT_ROLE_SERVER */ - -/** - * \addtogroup group_ble_common_api_functions - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_SetLocalName(const char8 name[]); -cy_en_ble_api_result_t Cy_BLE_GetLocalName(char8 name[]); -/** @} group_ble_common_api_functions */ - - -#if (CY_BLE_GATT_ROLE_CLIENT) -/** - * \addtogroup group_ble_common_api_gatt_client_functions - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_GATTC_StartDiscovery(cy_stc_ble_conn_handle_t connHandle); -cy_en_ble_api_result_t Cy_BLE_GATTC_StartPartialDiscovery(cy_stc_ble_conn_handle_t connHandle, - cy_ble_gatt_db_attr_handle_t startHandle, - cy_ble_gatt_db_attr_handle_t endHandle); -/** @} group_ble_common_api_gatt_client_functions - */ -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - - - -/*************************************** -* Private Function Prototypes -***************************************/ - -#if (CY_BLE_GATT_ROLE_SERVER) - -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_ReadAttributeValueCCCDReqHandler(const cy_stc_ble_gatts_char_val_read_req_t *param); - -/** - * \addtogroup group_ble_common_api_gatt_server_functions - * @{ - */ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_WriteAttributeValueCCCD(cy_stc_ble_gatts_db_attr_val_info_t *param); -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_ReadAttributeValueCCCD(cy_stc_ble_gatts_db_attr_val_info_t *param); -/** @} group_ble_common_api_gatt_server_functions */ - -#endif /* CY_BLE_GATT_ROLE_SERVER */ - -#if (CY_BLE_GATT_ROLE_CLIENT) - -void Cy_BLE_GATTC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -void Cy_BLE_GATTC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -void Cy_BLE_GATTC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -void Cy_BLE_GATTC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); - -cy_en_ble_api_result_t Cy_BLE_GATTC_AddConnHandle(cy_stc_ble_conn_handle_t connHandle); -cy_en_ble_api_result_t Cy_BLE_GATTC_RemoveConnHandle(cy_stc_ble_conn_handle_t connHandle); -#endif /* CY_BLE_GATT_ROLE_CLIENT */ - - - -/*************************************** -* Variables with external linkage -***************************************/ -/** \cond IGNORE */ -#if (CY_BLE_GATT_ROLE_SERVER) -#if (CY_BLE_GATT_DB_CCCD_COUNT != 0u) -extern uint8_t cy_ble_attValuesCccdMultiple[CY_BLE_CONN_COUNT][CY_BLE_GATT_DB_CCCD_COUNT + CY_BLE_CCCD_CRC_BYTE]; -#endif /* CY_BLE_GATT_DB_CCCD_COUNT != 0u */ -#endif /* (CY_BLE_GATT_ROLE_SERVER) */ - -#endif /* CY_BLE_MODE_PROFILE */ - -/* Global structure to initialize Cy_BLE_Init */ -extern cy_stc_ble_config_t cy_ble_config; -extern cy_stc_ble_config_t *cy_ble_configPtr; -/** \endcond */ - -#if (CY_BLE_MODE_PROFILE) - - -/*************************************** -* API Constants -***************************************/ - -/** - * \addtogroup group_ble_common_api_macros_gatt_uuid_services - * @{ - */ - -/*************************************** -* Universal Unique Identifier (UUID): BLE Services -***************************************/ - -/* Generic Access Profile */ -#define CY_BLE_UUID_GAP_SERVICE (0x1800u) /**< Generic Access Service UUID */ -/* Generic Attribute Profile */ -#define CY_BLE_UUID_GATT_SERVICE (0x1801u) /**< Generic Attribute Service UUID */ - -/* UUID: BLE Other Services */ -#define CY_BLE_UUID_IMMEDIATE_ALERT_SERVICE (0x1802u) /**< Immediate Alert Service UUID */ -#define CY_BLE_UUID_LINK_LOSS_SERVICE (0x1803u) /**< Link Loss Service UUID */ -#define CY_BLE_UUID_TX_POWER_SERVICE (0x1804u) /**< Tx Power Service UUID */ -#define CY_BLE_UUID_CURRENT_TIME_SERVICE (0x1805u) /**< Current Time Service UUID */ -#define CY_BLE_UUID_REF_TIME_UPDATE_SERVICE (0x1806u) /**< Reference Time Update Service UUID */ -#define CY_BLE_UUID_NEXT_DST_CHANGE_SERVICE (0x1807u) /**< Next DST Change Service UUID */ -#define CY_BLE_UUID_GLUCOSE_SERVICE (0x1808u) /**< Glucose Service UUID */ -#define CY_BLE_UUID_HEALTH_THERMOMETER_SERVICE (0x1809u) /**< Health Thermometer Service UUID */ -#define CY_BLE_UUID_DEVICE_INFO_SERVICE (0x180Au) /**< Device Information Service UUID */ -#define CY_BLE_UUID_NWA_SERVICE (0x180Bu) /**< NWA Service UUID */ -#define CY_BLE_UUID_WATCH_DOG_SERVICE (0x180Cu) /**< WATCH DOG Service UUID */ -#define CY_BLE_UUID_HEART_RATE_SERVICE (0x180Du) /**< Heart Rate Service UUID */ -#define CY_BLE_UUID_PHONE_ALERT_STATUS_SERVICE (0x180Eu) /**< Phone Alert Status Service UUID */ -#define CY_BLE_UUID_BAS_SERVICE (0x180Fu) /**< Battery Service Service UUID */ -#define CY_BLE_UUID_BLOOD_PRESSURE_SERVICE (0x1810u) /**< Blood Pressure Service UUID */ -#define CY_BLE_UUID_ALERT_NOTIFICATION_SERVICE (0x1811u) /**< Alert Notification Service Service UUID */ -#define CY_BLE_UUID_HIDS_SERVICE (0x1812u) /**< Human Interface Device Service UUID */ -#define CY_BLE_UUID_SCAN_PARAM_SERVICE (0x1813u) /**< Scan Parameters Service UUID */ -#define CY_BLE_UUID_RUNNING_SPEED_AND_CADENCE_SERVICE (0x1814u) /**< Running Speed and Cadence Service UUID */ -#define CY_BLE_UUID_AUTOMATION_INPUT_OUTPUT_SERVICE (0x1815u) /**< Automation IO Service UUID */ -#define CY_BLE_UUID_CYCLING_SPEED_AND_CADENCE_SERVICE (0x1816u) /**< Cycling Speed and Cadence Service UUID */ -#define CY_BLE_UUID_CPS_SERVICE (0x1818u) /**< Cycling Power Service UUID */ -#define CY_BLE_UUID_LOCATION_AND_NAVIGATION_SERVICE (0x1819u) /**< Location and Navigation Service UUID */ -#define CY_BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE (0x181Au) /**< Environmental Sensing Service UUID */ -#define CY_BLE_UUID_BODY_COMPOSITION_SERVICE (0x181Bu) /**< Body Composition Service UUID */ -#define CY_BLE_UUID_USER_DATA_SERVICE (0x181Cu) /**< User Data Service UUID */ -#define CY_BLE_UUID_WEIGHT_SCALE_SERVICE (0x181Du) /**< Weight Scale Service UUID */ -#define CY_BLE_UUID_BOND_MANAGEMENT_SERVICE (0x181Eu) /**< Bond Management Service UUID */ -#define CY_BLE_UUID_CGM_SERVICE (0x181Fu) /**< Continuous Glucose Monitoring Service UUID */ -#define CY_BLE_UUID_INTERNET_PROTOCOL_SUPPORT_SERVICE (0x1820u) /**< Internet Protocol Support Service UUID */ -#define CY_BLE_UUID_IPS_SERVICE (0x1821u) /**< Indoor Positioning Service UUID */ -#define CY_BLE_UUID_PULSE_OXIMETER_SERVICE (0x1822u) /**< Pulse Oximeter Service UUID */ -#define CY_BLE_UUID_HTTP_PROXY_SERVICE (0x1823u) /**< HTTP Proxy Service UUID */ -#define CY_BLE_UUID_WIRELESS_POWER_TRANSFER_SERVICE (0xFFFEu) /**< WIRELESS POWER TRANSFER Service UUID */ -/** @} group_ble_common_api_macros_gatt_uuid_char_services */ - - -/*************************************** -* UUID: GATT Attribute Types defined by GATT Profile -***************************************/ -/** - * \addtogroup group_ble_common_api_macros_gatt_uuid_char_gatt_type - * @{ - */ - -/** Primary Service Declaration */ -#define CY_BLE_UUID_PRIMARY_SERVICE (0x2800u) -/** Secondary Service Declaration */ -#define CY_BLE_UUID_SECONDARY_SERVICE (0x2801u) -/** Include Declaration */ -#define CY_BLE_UUID_INCLUDE (0x2802u) -/** Characteristic Declaration */ -#define CY_BLE_UUID_CHARACTERISTIC (0x2803u) - -/** @} group_ble_common_api_macros_gatt_uuid_char_gatt_type */ - - -/*************************************** -* UUID: GATT Characteristic Descriptors -***************************************/ -/** - * \addtogroup group_ble_common_api_macros_gatt_uuid_char_desc - * @{ - */ - -/** Characteristic Extended Properties */ -#define CY_BLE_UUID_CHAR_EXTENDED_PROPERTIES (0x2900u) -/** Characteristic User Description Descriptor */ -#define CY_BLE_UUID_CHAR_USER_DESCRIPTION (0x2901u) -/** Client Characteristic Configuration Descriptor */ -#define CY_BLE_UUID_CHAR_CLIENT_CONFIG (0x2902u) -/** Server Characteristic Configuration Descriptor */ -#define CY_BLE_UUID_CHAR_SERVER_CONFIG (0x2903u) -/** Characteristic Format Descriptor */ -#define CY_BLE_UUID_CHAR_FORMAT (0x2904u) -/** Characteristic Aggregate Format Descriptor */ -#define CY_BLE_UUID_CHAR_AGGREGATE_FORMAT (0x2905u) -/** Characteristic Valid Range */ -#define CY_BLE_UUID_CHAR_VALID_RANGE (0x2906u) -/** External Report Reference */ -#define CY_BLE_UUID_CHAR_EXTERNAL_REPORT_REF (0x2907u) -/** Report Reference */ -#define CY_BLE_UUID_CHAR_REPORT_REFERENCE (0x2908u) -/** Number of Digitals */ -#define CY_BLE_UUID_CHAR_NUMBER_OF_DIGITALS (0x2909u) -/** Value Trigger Setting */ -#define CY_BLE_UUID_CHAR_VALUE_TRIGGER_SETTING (0x290Au) -/** Environmental Sensing Configuration */ -#define CY_BLE_UUID_CHAR_ES_CONFIGURATION (0x290Bu) -/** Environmental Sensing Measurement */ -#define CY_BLE_UUID_CHAR_ES_MEASUREMENT (0x290Cu) -/** Environmental Sensing Trigger Setting */ -#define CY_BLE_UUID_CHAR_ES_TRIGGER_SETTING (0x290Du) -/** Time Trigger Setting */ -#define CY_BLE_UUID_CHAR_TIME_TRIGGER_SETTING (0x290Eu) - -/** @} group_ble_common_api_macros_gatt_uuid_char_desc */ - -/*************************************** -* UUID: Commonly used GATT Characteristic Types -***************************************/ -/** - * \addtogroup group_ble_common_api_macros_gatt_uuid_char_type - * @{ - */ - -/** Device Name Characteristic */ -#define CY_BLE_UUID_CHAR_DEVICE_NAME (0x2A00u) -/** Appearance Characteristic */ -#define CY_BLE_UUID_CHAR_APPEARANCE (0x2A01u) -/** Peripheral Privacy Flag Characteristic */ -#define CY_BLE_UUID_CHAR_PERIPH_PRIVCY_FLAG (0x2A02u) -/** Reconnection Address Characteristic */ -#define CY_BLE_UUID_CHAR_RECONNECTION_ADDR (0x2A03u) -/** Peripheral Preferred Connection Parameters Characteristic */ -#define CY_BLE_UUID_CHAR_PRFRRD_CNXN_PARAM (0x2A04u) -/** Service Changed Characteristic */ -#define CY_BLE_UUID_CHAR_SERVICE_CHANGED (0x2A05u) -/** Central Address Resolution Characteristic */ -#define CY_BLE_UUID_CHAR_CENTRAL_ADDRESS_RESOLUTION (0x2AA6u) -/** Resolvable Private Address Only characteristic */ -#define CY_BLE_UUID_CHAR_RESOLVABLE_PRIVATE_ADDR_ONLY (0x2AC9u) - - -/*************************************** -* UUID: Other Characteristic Types -***************************************/ - -#define CY_BLE_UUID_CHAR_ALERT_LEVEL (0x2A06u) /**< Alert Level GATT Characteristic UUID*/ -#define CY_BLE_UUID_CHAR_TX_POWER_LEVEL (0x2A07u) /**< Tx Power Level GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DATE_TIME (0x2A08u) /**< Date Time GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DAY_OF_WEEK (0x2A09u) /**< Day of Week GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DAY_DATE_TIME (0x2A0Au) /**< Day Date Time GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_EXACT_TIME_100 (0x2A0Bu) /**< Exact Time 100 GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_EXACT_TIME_256 (0x2A0Cu) /**< Exact Time 256 GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DST_OFFSET (0x2A0Du) /**< DST Offset GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TIME_ZONE (0x2A0Eu) /**< Time Zone GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LOCAL_TIME_INFO (0x2A0Fu) /**< Local Time Information GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SEC_TIME_ZONE (0x2A10u) /**< Sec Time Zone GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TIME_WITH_DST (0x2A11u) /**< Time with DST GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TIME_ACCURACY (0x2A12u) /**< Time Accuracy GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TIME_SOURCE (0x2A13u) /**< Time Source GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_REF_TIME_INFO (0x2A14u) /**< Reference Time Information GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TIME_BROADCAST (0x2A15u) /**< Time Broadcast GATT Characteristic UUID*/ -#define CY_BLE_UUID_CHAR_TIME_UPDATE_CONTROL_POINT (0x2A16u) /**< Time Update Control Point GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TIME_UPDATE_STATE (0x2A17u) /**< Time Update State GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_GLUCOSE_MSRMNT (0x2A18u) /**< Glucose Measurement GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_BATTERY_LEVEL (0x2A19u) /**< Battery Level GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TEMPERATURE_MSMNT (0x2A1Cu) /**< Temperature Measurement GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TEMPERATURE_TYPE (0x2A1Du) /**< Temperature Type GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_INTERMEDIATE_TEMP (0x2A1Eu) /**< Intermediate Temperature GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MSMNT_INTERVAL (0x2A21u) /**< Measurement Interval GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_BOOT_KEYBOARD_IN_RPT (0x2A22u) /**< Boot Keyboard Input Report GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SYSTEM_ID (0x2A23u) /**< System ID GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MODEL_NUMBER (0x2A24u) /**< Model Number String GATT Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SERIAL_NUMBER (0x2A25u) /**< Serial Number String Characteristic UUID */ -#define CY_BLE_UUID_CHAR_FIRMWARE_REV (0x2A26u) /**< Firmware Revision String Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HARDWARE_REV (0x2A27u) /**< Hardware Revision String Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SOFTWARE_REV (0x2A28u) /**< Software Revision String Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MANUFACTURER_NAME (0x2A29u) /**< Manufacturer Name String Characteristic UUID */ -#define CY_BLE_UUID_CHAR_REG_CERT_DATA (0x2A2Au) /**< IEEE 11073-20601 Regulatory Certification Data List */ -#define CY_BLE_UUID_CHAR_CURRENT_TIME (0x2A2Bu) /**< Current Time Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MAGNETIC_DECLINATION (0x2A2Cu) /**< Magnetic Declination Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SCAN_REFRESH (0x2A31u) /**< Scan Refresh Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_BOOT_KEYBOARD_OUT_RPT (0x2A32u) /**< Boot Keyboard Output Report Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_BOOT_MOUSE_IN_RPT (0x2A33u) /**< Boot Mouse Input Report Characteristic UUID */ -#define CY_BLE_UUID_CHAR_GL_MSRMT_CTX (0x2A34u) /**< Glucose Measurement Context UUID */ -#define CY_BLE_UUID_CHAR_BP_MSRMT (0x2A35u) /**< Blood Pressure Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_INTRMDT_CUFF_PRSR (0x2A36u) /**< Intermediate Cuff Pressure Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HR_MSRMT (0x2A37u) /**< Heart Rate Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_BODY_SENSOR_LOC (0x2A38u) /**< Body Sensor Location Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HR_CNTRL_POINT (0x2A39u) /**< Heart Rate Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_NWA (0x2A3Eu) /**< NWA Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ALERT_STATUS (0x2A3Fu) /**< Alert Status Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RINGER_CONTROL_POINT (0x2A40u) /**< Ringer Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RINGER_SETTING (0x2A41u) /**< Ringer Setting Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ALERT_ID_BIT_MASK (0x2A42u) /**< Alert Category ID Bit Mask Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ALERT_ID (0x2A43u) /**< Alert Category ID Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ALERT_NTF_CONTROL_POINT (0x2A44u) /**< Alert Notification Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_UNREAD_ALRT_STATUS (0x2A45u) /**< Unread Alert Status Characteristic UUID */ -#define CY_BLE_UUID_CHAR_NEW_ALERT (0x2A46u) /**< New Alert Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SPRTD_NEW_ALRT_CTGRY (0x2A47u) /**< Supported New Alert Category Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SPRT_UNRD_ALRT_CTGRY (0x2A48u) /**< Supported Unread Alert Category Characteristic UUID */ -#define CY_BLE_UUID_CHAR_BP_FEATURE (0x2A49u) /**< Blood Pressure Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_INFORMATION (0x2A4Au) /**< HID Information Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_REPORT_MAP (0x2A4Bu) /**< Report Map Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_CONTROL_POINT (0x2A4Cu) /**< HID Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_REPORT (0x2A4Du) /**< Report Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIDS_PROTOCOL_MODE (0x2A4Eu) /**< Protocol Mode Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SCAN_WINDOW (0x2A4Fu) /**< Scan Interval Window Characteristic UUID */ -#define CY_BLE_UUID_CHAR_PNP_ID (0x2A50u) /**< PnP ID Characteristic UUID */ -#define CY_BLE_UUID_CHAR_GL_FEATURE (0x2A51u) /**< Glucose Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RACP (0x2A52u) /**< Record Access Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RSC_MSRMT (0x2A53u) /**< RSC Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RSC_FEATURE (0x2A54u) /**< RSC Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SC_CONTROL_POINT (0x2A55u) /**< SC Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DIGITAL (0x2A56u) /**< Digital Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ANALOG (0x2A58u) /**< Analog Characteristic UUID */ -#define CY_BLE_UUID_CHAR_AGGREGATE (0x2A5Au) /**< Aggregate Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CSC_MSRMT (0x2A5Bu) /**< CSC Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CSC_FEATURE (0x2A5Cu) /**< CSC Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_SENSOR_LOCATION (0x2A5Du) /**< Sensor Location Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPS_MSRMT (0x2A63u) /**< Cycling Power Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPS_VECTOR (0x2A64u) /**< Cycling Power Vector Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPS_FEATURE (0x2A65u) /**< Cycling Power Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPS_CP (0x2A66u) /**< Cycling Power Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LOCATION_AND_SPEED (0x2A67u) /**< Location and Speed Characteristic UUID */ -#define CY_BLE_UUID_CHAR_NAVIGATION (0x2A68u) /**< Navigation Characteristic UUID */ -#define CY_BLE_UUID_CHAR_POSITION_QUALITY (0x2A69u) /**< Position Quality Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LN_FEATURE (0x2A6Au) /**< LN Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LN_CONTROL_POINT (0x2A6Bu) /**< LN Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ELEVATION (0x2A6Cu) /**< Elevation Characteristic UUID */ -#define CY_BLE_UUID_CHAR_PRESSURE (0x2A6Du) /**< Pressure Characteristic UUID */ -#define CY_BLE_UUID_CHAR_THEMPERATURE (0x2A6Eu) /**< Temperature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HUMIDITY (0x2A6Fu) /**< Humidity Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TRUE_WIND_SPEED (0x2A70u) /**< True Wind Speed Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TRUE_WIND_DIRECTION (0x2A71u) /**< True Wind Direction Characteristic UUID */ -#define CY_BLE_UUID_CHAR_APPARENT_WIND_SPEED (0x2A72u) /**< Apparent Wind Speed Characteristic UUID */ -#define CY_BLE_UUID_CHAR_APPARENT_WIND_DIRECTION (0x2A73u) /**< Apparent Wind Direction Characteristic UUID */ -#define CY_BLE_UUID_CHAR_GUST_FACTOR (0x2A74u) /**< Gust Factor Characteristic UUID */ -#define CY_BLE_UUID_CHAR_POLLEN_CONCENTRATION (0x2A75u) /**< Pollen Concentration Characteristic UUID */ -#define CY_BLE_UUID_CHAR_UV_INDEX (0x2A76u) /**< UV Index Characteristic UUID */ -#define CY_BLE_UUID_CHAR_IRRADIANCE (0x2A77u) /**< Irradiance Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RAINFALL (0x2A78u) /**< Rainfall Characteristic UUID */ -#define CY_BLE_UUID_CHAR_WIND_CHILL (0x2A79u) /**< Wind Chill Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HEAT_INDEX (0x2A7Au) /**< Aerobic Heart Rate Lower Limit Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DEW_POINT (0x2A7Bu) /**< Dew Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DESCR_VALUE_CHANGED (0x2A7Du) /**< Descriptor Value Changed Characteristic UUID */ -#define CY_BLE_UUID_CHAR_AEL (0x2A7Eu) /**< Aerobic Heart Rate Lower Limit Characteristic UUID */ -#define CY_BLE_UUID_CHAR_AEROBIC_THRESHOLD (0x2A7Fu) /**< Aerobic Threshold Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_AGE (0x2A80u) /**< Age Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ANL (0x2A81u) /**< Anaerobic Heart Rate Lower Limit Char. UUID */ -#define CY_BLE_UUID_CHAR_ANU (0x2A82u) /**< Anaerobic Heart Rate Upper Limit Char. UUID */ -#define CY_BLE_UUID_CHAR_ANAEROBIC_THRESHOLD (0x2A83u) /**< Anaerobic Threshold Characteristic UUID */ -#define CY_BLE_UUID_CHAR_AEU (0x2A84u) /**< Aerobic Heart Rate Upper Limit Char. UUID */ -#define CY_BLE_UUID_CHAR_DATE_OF_BIRTH (0x2A85u) /**< Date of Birth Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DATE_OF_THRESHOLD_ASSESSMENT (0x2A86u) /**< Date of Threshold Assessment Char. UUID */ -#define CY_BLE_UUID_CHAR_EMAIL_ADDRESS (0x2A87u) /**< Email Address Characteristic UUID */ -#define CY_BLE_UUID_CHAR_FBL (0x2A88u) /**< Fat Burn Heart Rate Lower Limit Char. UUID */ -#define CY_BLE_UUID_CHAR_FBU (0x2A89u) /**< Fat Burn Heart Rate Upper Limit Char. UUID */ -#define CY_BLE_UUID_CHAR_FIRST_NAME (0x2A8Au) /**< First Name Characteristic UUID */ -#define CY_BLE_UUID_CHAR_FIVE_ZONE_HEART_RATE_LIMITS (0x2A8Bu) /**< Five Zone Heart Rate Limits Char. UUID */ -#define CY_BLE_UUID_CHAR_GENDER (0x2A8Cu) /**< Gender Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HEART_RATE_MAX (0x2A8Du) /**< Heart Rate Max Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HEIGHT (0x2A8Eu) /**< Height Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HIP_CIRCUNFERENCE (0x2A8Fu) /**< Hip Circumference Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LAST_NAME (0x2A90u) /**< Last Name Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MRH (0x2A91u) /**< Maximum Recommended Heart Rate Characteristic UUID */ -#define CY_BLE_UUID_CHAR_RESTING_HEART_RATE (0x2A92u) /**< Resting Heart Rate Characteristic UUID */ -#define CY_BLE_UUID_CHAR_STP (0x2A93u) /**< Sport Type for Aerobic and Anaerobic Thresholds */ -#define CY_BLE_UUID_CHAR_THREE_ZONE_HEART_RATE_LIMITS (0x2A94u) /**< Three Zone Heart Rate Limits Characteristic UUID */ -#define CY_BLE_UUID_CHAR_TWO_ZONE_HEART_RATE_LIMIT (0x2A95u) /**< Two Zone Heart Rate Limit Characteristic UUID */ -#define CY_BLE_UUID_CHAR_VO2_MAX (0x2A96u) /**< VO2 Max Characteristic UUID */ -#define CY_BLE_UUID_CHAR_WAIST_CIRCUMFERENCE (0x2A97u) /**< Waist Circumference Characteristic UUID */ -#define CY_BLE_UUID_CHAR_WEIGHT (0x2A98u) /**< Weight Characteristic UUID */ -#define CY_BLE_UUID_CHAR_DATABASE_CHANGE_INCREMENT (0x2A99u) /**< Database Change Increment Characteristic UUID */ -#define CY_BLE_UUID_CHAR_USER_INDEX (0x2A9Au) /**< User Index Characteristic UUID */ -#define CY_BLE_UUID_CHAR_BODY_COMPOSITION_FEATURE (0x2A9Bu) /**< Body Composition Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_BODY_COMPOSITION_MEASUREMENT (0x2A9Cu) /**< Body Composition Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_WEIGHT_MEASUREMENT (0x2A9Du) /**< Weight Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_WEIGHT_SCALE_FEATURE (0x2A9Eu) /**< Weight Scale Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_USER_CONTROL_POINT (0x2A9Fu) /**< User Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MAGNETIC_FLUX_DENSITY_2D (0x2AA0u) /**< Magnetic Flux Density - 2D Characteristic UUID */ -#define CY_BLE_UUID_CHAR_MAGNETIC_FLUX_DENSITY_3D (0x2AA1u) /**< Magnetic Flux Density - 3D Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LANGUAGE (0x2AA2u) /**< Language Characteristic UUID */ -#define CY_BLE_UUID_CHAR_BAR_PRESSURE_TREND (0x2AA3u) /**< Barometric Pressure Trend Characteristic UUID */ -/* Bond Management Characteristics defines */ -#define CY_BLE_UUID_BOND_MANAGEMENT_CONTROL_POINT (0x2AA4u) /**< Bond Management Control Point Characteristic UUID */ -#define CY_BLE_UUID_BOND_MANAGEMENT_FEATURE (0x2AA5u) /**< Bond Management Feature Characteristic UUID */ -/* CGM Characteristics defines */ -#define CY_BLE_UUID_CHAR_CGM_MEASUREMENT (0x2AA7u) /**< CGM Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CGM_FEATURE (0x2AA8u) /**< CGM Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CGM_STATUS (0x2AA9u) /**< CGM Status Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CGM_SESSION_START_TIME (0x2AAAu) /**< CGM Session Start Time Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CGM_SESSION_RUN_TIME (0x2AABu) /**< CGM Session Run Time Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CGM_SOCP (0x2AACu) /**< CGM Specific Ops Control Point Characteristic UUID */ -/* Pulse Oximeter Characteristics defines */ -#define CY_BLE_UUID_CHAR_PLX_SPOT_CHK_MSRMT (0x2A5Eu) /**< PLX Spot-Check Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_PLX_CONTINUOUS_MSRMT (0x2A5Fu) /**< PLX Continuous Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_PLX_FEATURES (0x2A60u) /**< PLX Features Characteristic UUID */ -/* CPM Characteristics Measurements */ -#define CY_BLE_UUID_CHAR_CPM_MSRMT (0x2A63u) /**< Cycling Power Measurement Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPM_VECTOR (0x2A64u) /**< Cycling Power Vector Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPM_FEATURE (0x2A65u) /**< Cycling Power Feature Characteristic UUID */ -#define CY_BLE_UUID_CHAR_CPM_CNTRL_PNT (0x2A66u) /**< Cycling Power Control Point Characteristic UUID */ -/* IPS Characteristics defines */ -#define CY_BLE_UUID_CHAR_INDOOR_POSITINING_CONFIG (0x2AADu) /**< Indoor Positioning Configuration Char. UUID */ -#define CY_BLE_UUID_CHAR_LATITUDE (0x2AAEu) /**< Latitude Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LONGITUDE (0x2AAFu) /**< Longitude Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LOCAL_NORTH_COORDINATE (0x2AB0u) /**< Local North Coordinate Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LOCAL_EAST_COORDINATE (0x2AB1u) /**< Local East Coordinate Characteristic UUID */ -#define CY_BLE_UUID_CHAR_FLOOR_NUMBER (0x2AB2u) /**< Floor Number Characteristic UUID */ -#define CY_BLE_UUID_CHAR_ALTITUDE (0x2AB3u) /**< Altitude Characteristic UUID */ -#define CY_BLE_UUID_CHAR_UNCERTAINTY (0x2AB4u) /**< Uncertainty Characteristic UUID */ -#define CY_BLE_UUID_CHAR_LOCATION_NAME (0x2AB5u) /**< Location Name Characteristic UUID */ -/* HPS Characteristics defines */ -#define CY_BLE_UUID_CHAR_URI (0x2AB6u) /**< URI Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HTTP_HEADERS (0x2AB7u) /**< HTTP Headers Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HTTP_ENTITY_BODY (0x2AB9u) /**< HTTP Entity Body Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HTTP_CP (0x2ABAu) /**< HTTP Control Point Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HTTP_STATUS_CODE (0x2AB8u) /**< HTTP Status Code Characteristic UUID */ -#define CY_BLE_UUID_CHAR_HTTPS_SECURITY (0x2ABBu) /**< HTTPS Security Characteristic UUID */ - -/** @} group_ble_common_api_macros_gatt_uuid_char_type */ - -/** - * \addtogroup group_ble_common_api_macros - * @{ - */ - -/* GATT Characteristic Properties bit field */ -#define CY_BLE_CHAR_PROP_BROADCAST (0x01u) /**< Broadcast */ -#define CY_BLE_CHAR_PROP_READ (0x02u) /**< Read */ -#define CY_BLE_CHAR_PROP_WRITE_WITHOUT_RSP (0x04u) /**< Write Without Response */ -#define CY_BLE_CHAR_PROP_WRITE (0x08u) /**< Write */ -#define CY_BLE_CHAR_PROP_NOTIFY (0x10u) /**< Notify */ -#define CY_BLE_CHAR_PROP_INDICATE (0x20u) /**< Indicate */ -#define CY_BLE_CHAR_PROP_SIGNED_WRITE (0x40u) /**< Authenticated Signed Writes */ -#define CY_BLE_CHAR_PROP_EXTENDED_PROPERTIES (0x80u) /**< Extended properties */ - - -/* Client Characteristic Configuration Descriptor values */ -#define CY_BLE_CCCD_DEFAULT (0x0000u) /**< Notifications and Indications disabled */ -#define CY_BLE_CCCD_NOTIFICATION (0x0001u) /**< Notifications enabled */ -#define CY_BLE_CCCD_INDICATION (0x0002u) /**< Indications enabled */ -#define CY_BLE_CCCD_LEN (0x02u) /**< Length of CCCD desctiptor */ - -/* Server Characteristic Configuration Descriptor values */ -#define CY_BLE_SCCD_DEFAULT (0x0000u) /**< Broadcasts disabled */ -#define CY_BLE_SCCD_BROADCAST (0x0001u) /**< Broadcasts enabled */ -#define CY_BLE_SCCD_LEN (0x02u) /**< Length of SCCD desctiptor */ - -/* Characteristic Presentation Format Descriptor values */ -#define CY_BLE_CPFD_BOOLEAN (0x01u) /**< Unsigned 1-bit; 0=false, 1=true */ -#define CY_BLE_CPFD_UINT2 (0x02u) /**< Unsigned 2-bit integer */ -#define CY_BLE_CPFD_UINT4 (0x03u) /**< Unsigned 4-bit integer */ -#define CY_BLE_CPFD_UINT8 (0x04u) /**< Unsigned 8-bit integer */ -#define CY_BLE_CPFD_UINT12 (0x05u) /**< Unsigned 12-bit integer */ -#define CY_BLE_CPFD_UINT16 (0x06u) /**< Unsigned 16-bit integer */ -#define CY_BLE_CPFD_UINT24 (0x07u) /**< Unsigned 24-bit integer */ -#define CY_BLE_CPFD_UINT32 (0x08u) /**< Unsigned 32-bit integer */ -#define CY_BLE_CPFD_UINT48 (0x09u) /**< Unsigned 48-bit integer */ -#define CY_BLE_CPFD_UINT64 (0x0au) /**< Unsigned 64-bit integer */ -#define CY_BLE_CPFD_UINT128 (0x0bu) /**< Unsigned 128-bit integer */ -#define CY_BLE_CPFD_INT8 (0x0cu) /**< Signed 8-bit integer */ -#define CY_BLE_CPFD_INT12 (0x0du) /**< Signed 12-bit integer */ -#define CY_BLE_CPFD_INT16 (0x0eu) /**< Signed 16-bit integer */ -#define CY_BLE_CPFD_INT24 (0x0fu) /**< Signed 24-bit integer */ -#define CY_BLE_CPFD_INT32 (0x10u) /**< Signed 32-bit integer */ -#define CY_BLE_CPFD_INT48 (0x11u) /**< Signed 48-bit integer */ -#define CY_BLE_CPFD_INT64 (0x12u) /**< Signed 64-bit integer */ -#define CY_BLE_CPFD_INT128 (0x13u) /**< Signed 128-bit integer */ -#define CY_BLE_CPFD_IEEE754_FP32 (0x14u) /**< IEEE-754 32-bit floating point */ -#define CY_BLE_CPFD_IEEE754_FP64 (0x15u) /**< IEEE-754 64-bit floating point */ -#define CY_BLE_CPFD_IEEE11073_SFLOAT16 (0x16u) /**< IEEE-11073 16-bit SFLOAT */ -#define CY_BLE_CPFD_IEEE11073_FLOAT32 (0x17u) /**< IEEE-11073 32-bit FLOAT */ -#define CY_BLE_CPFD_IEEE20601_FORMAT (0x18u) /**< IEEE-20601 format */ -#define CY_BLE_CPFD_UTF8_STRING (0x19u) /**< UTF-8 string */ -#define CY_BLE_CPFD_UTF16_STRING (0x1au) /**< UTF-16 string */ -#define CY_BLE_CPFD_OPAQUE_STRUCTURE (0x1bu) /**< Opaque structure */ -#define CY_BLE_CPFD_LEN (0x01u) /**< Length of CPFD desctiptor */ - -/* Characteristic Extended Properties Descriptor values */ -#define CY_BLE_CEPD_DEFAULT (0x0000u) /**< Writable Auxiliaries & Reliable Write disabled */ -#define CY_BLE_CEPD_RELIABLE_WRITE (0x0001u) /**< Reliable Write enabled */ -#define CY_BLE_CEPD_WRITABLE_AUXILIARIES (0x0002u) /**< Writable Auxiliaries enabled */ -#define CY_BLE_CEPD_LEN (0x02u) /**< Length of CEPD desctiptor */ - -#define CY_BLE_DB_ATTR_HANDLE_LEN (0x02u) /**< Length of DB ATTR HANDLE */ - -/* PDU data length */ -#define CY_BLE_PDU_DATA_LEN_ZERO (0x00u) /**< Zero */ -#define CY_BLE_PDU_DATA_LEN_ONE_BYTE (0x01u) /**< PDU len: 1 byte */ -#define CY_BLE_PDU_DATA_LEN_TWO_BYTES (0x02u) /**< PDU len: 2 bytes */ -#define CY_BLE_PDU_DATA_LEN_THREE_BYTES (0x03u) /**< PDU len: 3 bytes */ -#define CY_BLE_PDU_DATA_LEN_FOUR_BYTES (0x04u) /**< PDU len: 4 bytes */ -#define CY_BLE_PDU_DATA_LEN_FIVE_BYTES (0x05u) /**< PDU len: 5 bytes */ -#define CY_BLE_PDU_DATA_LEN_SIX_BYTES (0x06u) /**< PDU len: 6 bytes */ -#define CY_BLE_PDU_DATA_LEN_SEVEN_BYTES (0x07u) /**< PDU len: 7 bytes */ -#define CY_BLE_PDU_DATA_LEN_EIGHT_BYTES (0x08u) /**< PDU len: 8 bytes */ -#define CY_BLE_PDU_DATA_LEN_NINE_BYTES (0x09u) /**< PDU len: 9 bytes */ - -/* Peripheral Preferred Connection Parameters Characteristic values */ -#define CY_BLE_PPCPC_MIN_CONN_INTV_OFFSET (0x00u) /**< Offset of Minimum Connection Interval Field */ -#define CY_BLE_PPCPC_MAX_CONN_INTV_OFFSET (0x02u) /**< Offset of Maximum Connection Interval Field */ -#define CY_BLE_PPCPC_SLAVE_LATENCY_OFFSET (0x04u) /**< Offset of Slave Latency Field */ -#define CY_BLE_PPCPC_SUP_TIMEOUT_OFFSET (0x06u) /**< Offset of Connection Supervision Timeout Field */ -#define CY_BLE_PPCPC_LEN (0x08u) /**< Length of PPCPC desctiptor */ -/** @} group_ble_common_api_macros */ - -/*************************************** -* Bluetooth Appearance values -***************************************/ -/** - * \addtogroup group_ble_common_api_macros_appearance_values - * @{ - */ - -#define CY_BLE_APPEARANCE_UNKNOWN (0u) /**< Unknown */ -#define CY_BLE_APPEARANCE_GENERIC_PHONE (64u) /**< Generic Phone */ -#define CY_BLE_APPEARANCE_GENERIC_COMPUTER (128u) /**< Generic Computer */ -#define CY_BLE_APPEARANCE_GENERIC_WATCH (192u) /**< Generic Watch */ -#define CY_BLE_APPEARANCE_WATCH_SPORTS_WATCH (193u) /**< Watch: Sports Watch */ -#define CY_BLE_APPEARANCE_GENERIC_CLOCK (256u) /**< Generic Clock */ -#define CY_BLE_APPEARANCE_GENERIC_DISPLAY (320u) /**< Generic Display */ -#define CY_BLE_APPEARANCE_GENERIC_REMOTE_CONTROL (384u) /**< Generic Remote Control */ -#define CY_BLE_APPEARANCE_GENERIC_EYE_GLASSES (448u) /**< Generic Eye-glasses */ -#define CY_BLE_APPEARANCE_GENERIC_TAG (512u) /**< Generic Tag */ -#define CY_BLE_APPEARANCE_GENERIC_KEYRING (576u) /**< Generic Keyring */ -#define CY_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER (640u) /**< Generic Media Player */ -#define CY_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER (704u) /**< Generic Barcode Scanner */ -#define CY_BLE_APPEARANCE_GENERIC_THERMOMETER (768u) /**< Generic Thermometer */ -#define CY_BLE_APPEARANCE_THERMOMETER_EAR (769u) /**< Thermometer: Ear */ -#define CY_BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR (832u) /**< Generic Heart rate Sensor */ -#define CY_BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT (833u) /**< Heart Rate Sensor: Heart Rate Belt */ -#define CY_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE (896u) /**< Generic Glucose */ -#define CY_BLE_APPEARANCE_BLOOD_PRESSURE_ARM (897u) /**< Glucose: Arm */ -#define CY_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST (898u) /**< Glucose: Wrist */ -#define CY_BLE_APPEARANCE_GENERIC_HID (960u) /**< Human Interface Device (HID) */ -#define CY_BLE_APPEARANCE_HIDS_KEYBOARD (961u) /**< Keyboard (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_MOUSE (962u) /**< Mouse (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_JOYSTICK (963u) /**< Joystiq (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_GAMEPAD (964u) /**< Gamepad (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_DIGITIZERSUBTYPE (965u) /**< Digitizer Tablet (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_CARD_READER (966u) /**< Card Reader (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_DIGITAL_PEN (967u) /**< Digital Pen (HID Subtype) */ -#define CY_BLE_APPEARANCE_HIDS_BARCODE (968u) /**< Barcode Scanner (HID Subtype) */ -#define CY_BLE_APPEARANCE_GENERIC_GLUCOSE_METER (1024u) /**< Generic Glucose Meter */ -#define CY_BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR (1088u) /**< Generic Running Walking Sensor */ -#define CY_BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE (1089u) /**< Running Walking Sensor: In-Shoe */ -#define CY_BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE (1090u) /**< Running Walking Sensor: On-Shoe */ -#define CY_BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP (1091u) /**< Running Walking Sensor: On-Hip */ -#define CY_BLE_APPEARANCE_GENERIC_CYCLING (1152u) /**< Generic Cycling */ -#define CY_BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER (1153u) /**< Cycling: Cycling Computer */ -#define CY_BLE_APPEARANCE_CYCLING_SPEED_SENSOR (1154u) /**< Cycling: Speed Sensor */ -#define CY_BLE_APPEARANCE_CYCLING_CADENCE_SENSOR (1155u) /**< Cycling: Cadence Sensor */ -#define CY_BLE_APPEARANCE_CYCLING_POWER_SENSOR (1156u) /**< Cycling: Power Sensor */ -#define CY_BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR (1157u) /**< Cycling: Speed and Cadence Sensor */ -/** @} group_ble_common_api_macros_appearance_values */ - - -/** - * \addtogroup group_ble_common_api_macros - * @{ - */ - -/*************************************** -* SMP Key size constants -***************************************/ - -#define CY_BLE_SMP_USER_PASSKEY_SIZE (6u) /**< User Passkey size */ -#define CY_BLE_SMP_IDADDR_SIZE (7u) /**< Identity Address data size */ -#define CY_BLE_SMP_IRK_SIZE (16u) /**< Identity Resolving Key size */ -#define CY_BLE_SMP_CSRK_SIZE (16u) /**< Connection Signature Resolving key size */ -#define CY_BLE_SMP_LTK_SIZE (16u) /**< Long Term Key Size size */ -#define CY_BLE_SMP_EDIV_SIZE (2u) /**< Encrypted Diversifier size */ -#define CY_BLE_SMP_RAND_24B_SIZE (3u) /**< 24 Bit Random Number size */ -#define CY_BLE_SMP_RAND_64B_SIZE (8u) /**< 64 Bit Random Number size */ -#define CY_BLE_SMP_RAND_128B_SIZE (16u) /**< 128 Bit Random Number size */ - -#define CY_BLE_NULL_CHARCTER ((char8)(0)) /**< Null charter */ - -/*************************************** -* Common constants for LLS and IAS services -***************************************/ -#define CY_BLE_NO_ALERT (0u) /**< Alert Level: No Alert */ -#define CY_BLE_MILD_ALERT (1u) /**< Alert Level: Mild Alert */ -#define CY_BLE_HIGH_ALERT (2u) /**< Alert Level: High Alert */ - -/** @} group_ble_common_api_macros */ - -/*************************************** -* Database macro -***************************************/ -/** - * \addtogroup group_ble_common_api_macros_gatt_db - * @{ - */ - -/** Get permission field of attribute handle */ -#define CY_BLE_GATT_DB_GET_ATTR_PERMISSION(handle) \ - (uint32_t)(cy_ble_configPtr->gattDB[(handle) - 1u].permission) - -/** Compare permission field of attribute entry to - * check desired permission property - */ -#define CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(handle, prpty) \ - ((0ul) != (CY_BLE_GATT_DB_GET_ATTR_PERMISSION(handle) & (prpty))) - -/** Macro to set generic value of attribute */ -#define CY_BLE_GATT_DB_ATTR_SET_GEN_VALUE(handle, src, length) \ - (void)memcpy \ - ( \ - (void*)(cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attFormatValue.attGenericValLen->attGenericVal), \ - (const void*)(src), \ - (uint16_t)(length) \ - ) - - -/** Macro to get generic value of attribute. This macro also used to get - * UUID32 or UUID 128 of the attribute. - */ -#define CY_BLE_GATT_DB_ATTR_GET_GEN_VALUE(dst, handle, length) \ - (void)memcpy \ - ( \ - (void*)(dst), \ - (const void*)(cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attFormatValue.attGenericValLen->attGenericVal), \ - (uint16_t)(length) \ - ) - -/** Macro to get start handle of attribute - * Start handle is only meaningful for characteristic and - * service declaration */ -#define CY_BLE_GATT_DB_GET_START_HANDLE(handle) \ - cy_ble_configPtr->gattDB[(handle) - 1u].attHandle - -/** Macro to get end handle of attribute - * Start handle is only meaningful for characteristic and - * service declaration */ -#define CY_BLE_GATT_DB_GET_END_HANDLE(handle) \ - cy_ble_configPtr->gattDB[(handle) - 1u].attEndHandle - - -/** Macro to get attribute type (UUID) for handle */ -#define CY_BLE_GATT_DB_GET_UUID(handle) \ - cy_ble_configPtr->gattDB[(handle) - 1u].attType - - -/** Macro to get attribute value UUID for handle. This macro is only applicable - * to UUID16. To get UUID32 or UUID 128 use CY_BLE_GATT_DB_ATTR_GET_GEN_VALUE(). - */ -#define CY_BLE_GATT_DB_GET_ATTR_VALUE_UUID(handle) \ - cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attValueUuid - -/** Macro to get actual length of characteristic generic value */ -#define CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_LEN(handle) \ - cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attFormatValue.attGenericValLen->actualLength - -/** Macro to set actual length of characteristic generic value. - * Note that this macro doesn't validate the actual length, which can't be greater then maximum length. - * Use CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN macro to read and validate maximum length. - */ -#define CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(handle, value) \ - do { \ - cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attFormatValue.attGenericValLen->actualLength = (value); \ - } while(0) - -/** Macro to get maximum length of characteristic generic value */ -#define CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(handle) \ - cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attFormatValue.maxAttrLength - -/** Macro to get index of CCCD value */ -#define CY_BLE_GATT_DB_ATTR_GET_CCCD_IDX(handle) (CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(handle) - \ - cy_ble_configPtr->attValuesCCCD) - -/** Macro to get pointer to characteristic generic value */ -#define CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(handle) \ - (uint8_t*)(cy_ble_configPtr->gattDB[(handle) - 1u].attValue.attFormatValue.attGenericValLen->attGenericVal) - -/** Macro to get pointer to CCCD value */ -#define CY_BLE_GATT_DB_ATTR_GET_CCCD_ATTR_GEN_PTR(attId, handle) \ - (uint8_t*)(&cy_ble_attValuesCccdMultiple[attId][CY_BLE_GATT_DB_ATTR_GET_CCCD_IDX(handle)]) - -/** Checks Notification properties in permission field of attribute entry */ -#define CY_BLE_IS_NOTIFICATION_SUPPORTED(handle) \ - CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(handle, CY_BLE_GATT_DB_CH_PROP_NOTIFY) - -/** Checks Notification bit in attribute value referenced by pointer */ -#define CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(valPtr) \ - ((0u) != (CY_BLE_CCCD_NOTIFICATION & Cy_BLE_Get16ByPtr(valPtr))) - -/** Checks Notification bit in attribute value referenced by handle */ -#define CY_BLE_IS_NOTIFICATION_ENABLED(attId, handle) \ - CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(CY_BLE_GATT_DB_ATTR_GET_CCCD_ATTR_GEN_PTR(attId, handle)) - -/** Checks Indication properties in permission field of attribute entry */ -#define CY_BLE_IS_INDICATION_SUPPORTED(handle) \ - CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(handle, CY_BLE_GATT_DB_CH_PROP_INDICATE) - -/** Checks Indication bit in attribute value referenced by pointer */ -#define CY_BLE_IS_INDICATION_ENABLED_IN_PTR(valPtr) \ - ((0u) != (CY_BLE_CCCD_INDICATION & Cy_BLE_Get16ByPtr(valPtr))) - -/** Checks Indication bit in attribute value referenced by handle */ -#define CY_BLE_IS_INDICATION_ENABLED(attId, handle) \ - CY_BLE_IS_INDICATION_ENABLED_IN_PTR(CY_BLE_GATT_DB_ATTR_GET_CCCD_ATTR_GEN_PTR(attId, handle)) - -/** Checks Broadcast properties in permission field of attribute entry */ -#define CY_BLE_IS_BROADCAST_SUPPORTED(handle) \ - CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(handle, CY_BLE_GATT_DB_CH_PROP_BROADCAST) - -/** Checks Broadcast bit in attribute value referenced by pointer */ -#define CY_BLE_IS_BROADCAST_ENABLED_IN_PTR(valPtr) \ - ((0u) != (CY_BLE_SCCD_BROADCAST & Cy_BLE_Get16ByPtr(valPtr))) - -/** Checks Broadcast bit in attribute value referenced by handle */ -#define CY_BLE_IS_BROADCAST_ENABLED(handle) \ - CY_BLE_IS_BROADCAST_ENABLED_IN_PTR(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(handle)) - -/** Checks Reliable Write bit in attribute value referenced by pointer */ -#define CY_BLE_IS_RELIABLE_WRITE_ENABLED_IN_PTR(valPtr) \ - ((0u) != (CY_BLE_CEPD_RELIABLE_WRITE & Cy_BLE_Get16ByPtr(valPtr))) - -/** Checks Reliable Write bit in attribute value referenced by handle */ -#define CY_BLE_IS_RELIABLE_WRITE_ENABLED(handle) \ - CY_BLE_IS_RELIABLE_WRITE_ENABLED_IN_PTR(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(handle)) - -/** @} group_ble_common_api_macros_gatt_db */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE */ -#endif /* CY_BLE_GATT_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gls.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gls.c deleted file mode 100644 index fd4486342b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gls.c +++ /dev/null @@ -1,1505 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_gls.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Glucose Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_GLS)) - -static cy_ble_callback_t Cy_BLE_GLS_ApplCallback; - -#ifdef CY_BLE_GLS_SERVER -uint8_t cy_ble_glsFlag; -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_glssReqHandle; -#endif /* CY_BLE_GLS_SERVER */ - -#ifdef CY_BLE_GLS_CLIENT -/* Server's Glucose Service characteristics GATT DB handles structure */ -cy_stc_ble_glsc_t cy_ble_glsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check the response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_glscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_GLS_CLIENT */ - -/* The pointer on global BLE GLS Config structure */ -cy_stc_ble_gls_config_t *cy_ble_glsConfigPtr = NULL; - - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_GLS_SERVER -static void Cy_BLE_GLSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_GLSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_GLS_SERVER */ - -#ifdef CY_BLE_GLS_CLIENT -static void Cy_BLE_GLSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_GLSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_GLSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_GLSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_GLSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_GLSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_GLSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_GLSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_GLS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_GLS_EventHandler(uint32_t eventCode, void *eventParam); - -/****************************************************************************** -* Function Name: Cy_BLE_GLS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for the Glucose Service Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLS_Init(cy_stc_ble_gls_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_glsConfigPtr = config; - - /* Registers Event Handler for the GLS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_GLS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_glsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_GLS_ApplCallback = cy_ble_glsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_GLS_SERVER - cy_ble_glsFlag = 0u; - cy_ble_glssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_GLS_SERVER */ - #ifdef CY_BLE_GLS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_GLS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_glsc[idx], 0, sizeof(cy_stc_ble_glsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_GLS].uuid = CY_BLE_UUID_GLUCOSE_SERVICE; - } - cy_ble_glscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for Glucose Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \sideeffect The *eventParams in the callback function should not be used -* by the application once the callback function execution is -* finished. Otherwise this data may become corrupted. -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_GLS_ApplCallback = callbackFunc; - if(cy_ble_glsConfigPtr != NULL) - { - cy_ble_glsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_GLS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service, which is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* \events -* None -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSS_SetCharacteristicValue(cy_en_ble_gls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_GLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the service, which is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: Pointer to the location where Characteristic value data should -* be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSS_GetCharacteristicValue(cy_en_ble_gls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_GLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param *attrValue: Pointer to the location where the descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - cy_en_ble_gls_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if((charIndex >= CY_BLE_GLS_CHAR_COUNT) || (descrIndex >= CY_BLE_GLS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsConfigPtr->glss->charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_glsConfigPtr->glss->charInfo[charIndex].cccdHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified characteristic to the client device, -* as defined by the charIndex value. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_GLSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: Pointer to the Characteristic value data that should be sent -* to Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_GLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_glsConfigPtr->glss->charInfo[charIndex].cccdHandle)) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_SendIndication -***************************************************************************//** -* -* Sends an indication of the specified characteristic to the client device, as -* defined by the charIndex value. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_GLSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: Pointer to the Characteristic value data that should be sent -* to Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the GLS service-specific callback is registered -* (with Cy_BLE_GLS_RegisterAttrCallback): -* * CY_BLE_EVT_GLSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the GLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_GLS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsConfigPtr->glss->charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_glsConfigPtr->glss->charInfo[charIndex].cccdHandle)) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indParam = - { - .handleValPair.attrHandle = cy_ble_glsConfigPtr->glss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indParam); - - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific value confirmation response from client */ - cy_ble_glssReqHandle = indParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles the Value Confirmation request event from the BLE stack. -* -* \param *eventParam: Pointer to a structure of type cy_stc_ble_conn_handle_t -* -******************************************************************************/ -static void Cy_BLE_GLSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_GLS_ApplCallback != NULL) && - (cy_ble_glsConfigPtr->glss->charInfo[CY_BLE_GLS_RACP].charHandle == cy_ble_glssReqHandle)) - { - cy_stc_ble_gls_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_GLS_RACP, - .value = NULL - }; - - cy_ble_glssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_glsFlag &= (uint8_t) ~CY_BLE_GLS_FLAG_PROCESS; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSS_INDICATION_CONFIRMED, &locCharIndex); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param *eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_GLSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_gls_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - - if(Cy_BLE_GLS_ApplCallback != NULL) - { - if(eventParam->handleValPair.attrHandle == cy_ble_glsConfigPtr->glss->charInfo[CY_BLE_GLS_RACP].charHandle) - { - if(CY_BLE_GLS_IS_PROCEDURE_IN_PROGRESS - && (CY_BLE_GLS_RACP_OPCODE_ABORT != eventParam->handleValPair.value.val[0u])) - { - gattErr = CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_glsConfigPtr->glss->charInfo[CY_BLE_GLS_RACP].cccdHandle)) - { - gattErr = CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - locCharValue.charIndex = CY_BLE_GLS_RACP; - locCharValue.value = &eventParam->handleValPair.value; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSS_WRITE_CHAR, &locCharValue); - cy_ble_glsFlag |= CY_BLE_GLS_FLAG_PROCESS; - } - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - for(locCharValue.charIndex = CY_BLE_GLS_GLMT; - locCharValue.charIndex < CY_BLE_GLS_CHAR_COUNT; locCharValue.charIndex++) - { - if(eventParam->handleValPair.attrHandle == - cy_ble_glsConfigPtr->glss->charInfo[locCharValue.charIndex].cccdHandle) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - locCharValue.value = NULL; - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if(locCharValue.charIndex < CY_BLE_GLS_GLFT) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSS_NOTIFICATION_ENABLED, &locCharValue); - } - else - { - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSS_NOTIFICATION_DISABLED, &locCharValue); - } - } - else - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSS_INDICATION_ENABLED, &locCharValue); - } - else - { - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSS_INDICATION_DISABLED, &locCharValue); - } - } - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - - return(gattErr); -} - -#endif /* CY_BLE_GLS_SERVER */ - -#ifdef CY_BLE_GLS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_GLSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the GLS service-specific callback is registered -* (with Cy_BLE_GLS_RegisterAttrCallback): -* * CY_BLE_EVT_GLSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_gls_char_value_t. -* . -* Otherwise (if the GLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_GLS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_glsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_glsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_glscReqHandle[discIdx] = cy_ble_glsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server -* which is identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the GLS service-specific callback is registered -* (with Cy_BLE_GLS_RegisterAttrCallback): -* * CY_BLE_EVT_GLSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_gls_char_value_t. -* . -* Otherwise (if the GLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_GLS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_glsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_glsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_glscReqHandle[discIdx] = cy_ble_glsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the Characteristic Descriptor of the specified Characteristic. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_GLSS_INDICATION_ENABLED -* * CY_BLE_EVT_GLSS_INDICATION_DISABLED -* * CY_BLE_EVT_GLSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_GLSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param *attrValue: Pointer to the characteristic descriptor value data that should -* be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the GLS service-specific callback is registered -* (with Cy_BLE_GLS_RegisterAttrCallback): -* * CY_BLE_EVT_GLSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_gls_descr_value_t. -* . -* Otherwise (if the GLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - cy_en_ble_gls_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_GLS_CHAR_COUNT) || (descrIndex >= CY_BLE_GLS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsc[discIdx].charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_glsc[discIdx].charInfo[charIndex].cccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific read response from device */ - cy_ble_glscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the GLS service-specific callback is registered -* (with Cy_BLE_GLS_RegisterAttrCallback): -* * CY_BLE_EVT_GLSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_gls_descr_value_t. -* . -* Otherwise (if the GLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GLSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - cy_en_ble_gls_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_GLS_CHAR_COUNT) || (descrIndex >= CY_BLE_GLS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_glsc[discIdx].charInfo[charIndex].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_glsc[discIdx].charInfo[charIndex].cccdHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_glscReqHandle[discIdx] = cy_ble_glsc[discIdx].charInfo[charIndex].cccdHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_GLSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* Glucose Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_glscCharUuid[CY_BLE_GLS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_GLUCOSE_MSRMNT, - CY_BLE_UUID_CHAR_GL_MSRMT_CTX, - CY_BLE_UUID_CHAR_GL_FEATURE, - CY_BLE_UUID_CHAR_RACP - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_GLS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_GLS_CHAR_COUNT; i++) - { - if(cy_ble_glscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_glsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_glsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_glsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_glsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_GLS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param *discDescrInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_GLSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_GLS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if(cy_ble_glsc[discIdx].charInfo[charIdx].cccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_glsc[discIdx].charInfo[charIdx].cccdHandle = discDescrInfo->descrHandle; - } - else /* Duplication of descriptor */ - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_GLSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_GLS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_GLS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_glsc[discIdx].charInfo[charIdx].endHandle - cy_ble_glsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_glsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_glsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param *eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_GLSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_GLS_ApplCallback != NULL)) - { - cy_stc_ble_gls_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - - if(cy_ble_glsc[discIdx].charInfo[CY_BLE_GLS_GLMT].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_GLS_GLMT; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_glsc[discIdx].charInfo[CY_BLE_GLS_GLMC].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_GLS_GLMC; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Glucose Service doesn't support any other notifications */ - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locCharValue.value = &eventParam->handleValPair.value; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSC_NOTIFICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_IndicationEventHandler -***************************************************************************//** -* -* Handles the Indication Event. -* -* \param *eventParam: the pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_GLSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_GLS_ApplCallback != NULL)) - { - if(cy_ble_glsc[discIdx].charInfo[CY_BLE_GLS_RACP].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_gls_char_value_t locCharValue = - { - .charIndex = CY_BLE_GLS_RACP, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSC_INDICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param *eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_GLSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_GLS_ApplCallback != NULL) && - (cy_ble_glscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_glsc[discIdx].charInfo[CY_BLE_GLS_GLFT].valueHandle == cy_ble_glscReqHandle[discIdx]) - { - cy_stc_ble_gls_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_GLS_GLFT, - .value = &eventParam->value - }; - cy_ble_glscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSC_READ_CHAR_RESPONSE, &locCharValue); - } - else - { - cy_en_ble_gls_char_index_t i; - - for(i = CY_BLE_GLS_GLMT; i < CY_BLE_GLS_CHAR_COUNT; i++) - { - if(cy_ble_glsc[discIdx].charInfo[i].cccdHandle == cy_ble_glscReqHandle[discIdx]) - { - cy_stc_ble_gls_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = i, - .descrIndex = CY_BLE_GLS_CCCD, - .value = &eventParam->value - }; - cy_ble_glscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSC_READ_DESCR_RESPONSE, &locDescrValue); - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param *eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_GLSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_GLS_ApplCallback != NULL) && - (cy_ble_glscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_glsc[discIdx].charInfo[CY_BLE_GLS_RACP].valueHandle == cy_ble_glscReqHandle[discIdx]) - { - cy_stc_ble_gls_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_GLS_RACP, - .value = NULL - }; - cy_ble_glscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSC_WRITE_CHAR_RESPONSE, &locCharIndex); - } - else - { - cy_en_ble_gls_char_index_t i; - - for(i = CY_BLE_GLS_GLMT; i < CY_BLE_GLS_CHAR_COUNT; i++) - { - if(cy_ble_glsc[discIdx].charInfo[i].cccdHandle == cy_ble_glscReqHandle[discIdx]) - { - cy_stc_ble_gls_descr_value_t locDescIndex = - { - .connHandle = *eventParam, - .charIndex = i, - .descrIndex = CY_BLE_GLS_CCCD, - .value = NULL - }; - cy_ble_glscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_GLS_ApplCallback((uint32_t)CY_BLE_EVT_GLSC_WRITE_DESCR_RESPONSE, &locDescIndex); - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_GLSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param *eventParam: Pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_GLSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_glscReqHandle[discIdx]) - { - cy_ble_glscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -#endif /* CY_BLE_GLS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_GLS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Glucose Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_GLS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_GLS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_GLSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_GLSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_GLSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_GLS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - case CY_BLE_EVT_GATT_DISCONNECT_IND: - (void)Cy_BLE_GLS_Init(cy_ble_glsConfigPtr); - break; - - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_GLS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_GLSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_GLSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_GLS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_GLS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_GLSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_GLSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_GLSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_GLSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_GLSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_GLS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_GLS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gls.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gls.h deleted file mode 100644 index b4983a0e3e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_gls.h +++ /dev/null @@ -1,230 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_gls.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in the -* Glucose Profile of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_GLS_H -#define CY_BLE_GLS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_GLS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define CY_BLE_GLS_FLAG_PROCESS (0x01u) -#define CY_BLE_GLS_RACP_OPCODE_ABORT (0x03u) - -/** - * \addtogroup group_ble_service_api_GLS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Service Characteristics indexes */ -typedef enum -{ - CY_BLE_GLS_GLMT, /**< Glucose Measurement characteristic index */ - CY_BLE_GLS_GLMC, /**< Glucose Measurement Context characteristic index */ - CY_BLE_GLS_GLFT, /**< Glucose Feature characteristic index */ - CY_BLE_GLS_RACP, /**< Record Access Control Point characteristic index */ - CY_BLE_GLS_CHAR_COUNT /**< Total count of GLS characteristics */ -}cy_en_ble_gls_char_index_t; - -/** Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_GLS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_GLS_DESCR_COUNT /**< Total count of GLS descriptors */ -}cy_en_ble_gls_descr_index_t; - -/** Glucose Server Characteristic structure type */ -typedef struct -{ - /** Glucose Service char handle */ - cy_ble_gatt_db_attr_handle_t charHandle; - - /** Glucose Service CCCD handle */ - cy_ble_gatt_db_attr_handle_t cccdHandle; -}cy_stc_ble_glss_char_t; - -/** Structure with Glucose Service attribute handles */ -typedef struct -{ - /** Glucose Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Glucose Service characteristics info array */ - cy_stc_ble_glss_char_t charInfo[CY_BLE_GLS_CHAR_COUNT]; -} cy_stc_ble_glss_t; - -/** Glucose Client Characteristic structure type */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** Glucose client char. descriptor handle */ - cy_ble_gatt_db_attr_handle_t cccdHandle; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_glsc_char_t; - -/** Glucose Service structure type */ -typedef struct -{ - /** Characteristics handle + properties array */ - cy_stc_ble_glsc_char_t charInfo[CY_BLE_GLS_CHAR_COUNT]; -}cy_stc_ble_glsc_t; - -/** Glucose Service Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_gls_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_gls_char_value_t; - -/** Glucose Service Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_gls_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_gls_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_gls_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Glucose Profile GATT DB handles structure */ - const cy_stc_ble_glss_t *glss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_gls_config_t; -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_GLS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_GLS_Init(cy_stc_ble_gls_config_t *config); -cy_en_ble_api_result_t Cy_BLE_GLS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_GLS_SERVER -/** - * \addtogroup group_ble_service_api_GLS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_GLSS_SetCharacteristicValue(cy_en_ble_gls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); -cy_en_ble_api_result_t Cy_BLE_GLSS_GetCharacteristicValue(cy_en_ble_gls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_GLSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - cy_en_ble_gls_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_GLSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_GLSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_GLS_SERVER */ - -#ifdef CY_BLE_GLS_CLIENT -/** - * \addtogroup group_ble_service_api_GLS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_GLSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_GLSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_GLSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - cy_en_ble_gls_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_GLSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_gls_char_index_t charIndex, - cy_en_ble_gls_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_GLS_CLIENT */ - - -/* Internal macros */ -#ifdef CY_BLE_GLS_SERVER -#define CY_BLE_GLS_IS_GMC_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_glsConfigPtr->glss->charInfo[CY_BLE_GLS_GLMC].charHandle) - -#define CY_BLE_GLS_IS_PROCEDURE_IN_PROGRESS \ - (0u != (CY_BLE_GLS_FLAG_PROCESS & cy_ble_glsFlag)) -#endif /* CY_BLE_GLS_SERVER */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_GLS_SERVER -/* Glucose Service GATT DB handles structure */ -extern uint8_t cy_ble_glsFlag; -#endif /* CY_BLE_GLSC_SERVER */ - -#ifdef CY_BLE_GLS_CLIENT -/* Glucose Service server's GATT DB handles structure */ -extern cy_stc_ble_glsc_t cy_ble_glsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_GLS_CLIENT */ - -extern cy_stc_ble_gls_config_t cy_ble_glsConfig; -extern cy_stc_ble_gls_config_t *cy_ble_glsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_GLS) */ -#endif /* CY_BLE_GLS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_int.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_int.c deleted file mode 100644 index 0ab610be08..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_int.c +++ /dev/null @@ -1,133 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hal_int.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Interrupt Service Routine for the -* HAL section of the BLE component -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ -#include "cy_ble_event_handler.h" -#include "cy_ble_hal_pvt.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_HOST_CONTR_CORE) - -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - -/******************************************************************************* -* Function Name: Cy_BLE_BlessInterrupt -****************************************************************************//** -* -* Handles the Interrupt Service Routine for the BLE sub-system. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_BlessInterrupt(void) -{ - /* Call stack manager bless function handler */ - Cy_BLE_HAL_BlessInterruptHandler(); - /* Host stack takes care of clearing interrupts */ -} - -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ - -#if (CY_BLE_STACK_MODE_HOST_UART) - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_HOST_UART_Interrupt -****************************************************************************//** -* -* Handles the Interrupt Service Routine for the UART. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_HOST_UART_Interrupt(void) -{ - uint8_t uartTxStatus = CY_BLE_INTR_TX_SUCCESS; - uint32_t srcInterrupt = 0u; - - uint8_t lenRxFifo; - uint8_t srcCount; - uint8_t uartRxStatus = CY_BLE_INTR_RX_SUCCESS; - uint8_t receivedData; - - /* Evaluate RX interrupt event */ - srcInterrupt = Cy_SCB_GetRxInterruptStatusMasked(cy_ble_configPtr->uartHostHw); - - if(0u != (srcInterrupt & CY_SCB_RX_INTR_NOT_EMPTY)) - { - if(0u != (srcInterrupt & CY_SCB_RX_INTR_UART_PARITY_ERROR)) - { - uartRxStatus |= CY_BLE_INTR_RX_PARITY_ERROR; - } - if(0u != (srcInterrupt & CY_SCB_RX_INTR_UART_FRAME_ERROR)) - { - uartRxStatus |= CY_BLE_INTR_RX_FRAME_ERROR; - } - if(0u != (srcInterrupt & CY_SCB_RX_INTR_OVERFLOW)) - { - uartRxStatus |= CY_BLE_INTR_RX_OVERFLOW; - } - if(uartRxStatus == CY_BLE_INTR_RX_SUCCESS) - { - lenRxFifo = (uint8_t)Cy_SCB_GetNumInRxFifo(cy_ble_configPtr->uartHostHw); - for(srcCount = 0u; srcCount < lenRxFifo; srcCount++) - { - receivedData = (uint8_t)Cy_SCB_ReadRxFifo(cy_ble_configPtr->uartHostHw); - Cy_BLE_HAL_HciTransportHandler((char8)receivedData, 1u); - } - } - else - { - Cy_SCB_ClearRxFifo(cy_ble_configPtr->uartHostHw); - } - Cy_SCB_ClearRxInterrupt(cy_ble_configPtr->uartHostHw, srcInterrupt); - } - else - { - /* No RX interrupt. Do nothing. */ - } - - /* Evaluate TX interrupt event in sequence */ - srcInterrupt = Cy_SCB_GetTxInterruptStatusMasked(cy_ble_configPtr->uartHostHw); - - /* Stack manager TX UART complete */ - if(0u != (srcInterrupt & CY_SCB_TX_INTR_UART_DONE)) - { - if(0u != (srcInterrupt & CY_SCB_TX_INTR_OVERFLOW)) - { - /*Stack manager TX UART error */ - uartTxStatus |= CY_BLE_INTR_TX_OVERFLOW; - } - Cy_SCB_ClearTxInterrupt(cy_ble_configPtr->uartHostHw, srcInterrupt); - } - else - { - /* No TX interrupt. Do nothing. */ - } -} -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ - -#endif /* (CY_BLE_HOST_CONTR_CORE) */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_pvt.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_pvt.c deleted file mode 100644 index 44d47295dc..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_pvt.c +++ /dev/null @@ -1,1557 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hal_pvt.c -* \version 2.0 -* -* \brief -* This file contains the source code for the HAL section of the BLE component -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include "cy_ble_hal_pvt.h" - -#if ((CY_BLE_STACK_MODE_IPC) && (CY_BLE_HOST_CORE)) - -/* BLE application IPC notification handler */ -static cy_ble_ipc_app_notif_callback_t Cy_BLE_IPC_HostRegisteredCallback; - -#endif /* ((CY_BLE_STACK_MODE_IPC) && (CY_BLE_HOST_CORE)) */ - - - -#if (CY_BLE_HOST_CONTR_CORE) -#if (CY_BLE_STACK_MODE_HOST_UART) - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_HOST_UART_Start -****************************************************************************//** -* -* Enables the platform UART TX and RX interrupts and then enables the UART -* component. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_HOST_UART_Start(void) -{ - /* Setup ISR */ - Cy_SysInt_Init(cy_ble_configPtr->uartHostIsrConfig, &Cy_BLE_HAL_HOST_UART_Interrupt); - NVIC_EnableIRQ((IRQn_Type)cy_ble_configPtr->uartHostIsrConfig->intrSrc); - - (void)Cy_SCB_UART_Init(cy_ble_configPtr->uartHostHw, cy_ble_configPtr->uartHostConfig, NULL); - /* Configure interrupt sources. */ - Cy_SCB_SetRxInterruptMask(cy_ble_configPtr->uartHostHw, CY_SCB_RX_INTR_NOT_EMPTY | CY_SCB_RX_INTR_OVERFLOW | - CY_SCB_RX_INTR_UNDERFLOW); - Cy_SCB_SetTxInterruptMask(cy_ble_configPtr->uartHostHw, CY_SCB_TX_INTR_OVERFLOW | CY_SCB_TX_INTR_UART_DONE); - - Cy_SCB_UART_Enable(cy_ble_configPtr->uartHostHw); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_HOST_UART_Stop -****************************************************************************//** -* -* Disables the UART, clears all pending interrupts and disables the UART TX -* and RX interrupts. This will also empty out the FIFOs. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_HOST_UART_Stop(void) -{ - /* Stop interrupt and UART */ - NVIC_DisableIRQ((IRQn_Type)cy_ble_configPtr->uartHostIsrConfig->intrSrc); - - Cy_SCB_UART_Disable(cy_ble_configPtr->uartHostHw, NULL); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_HOST_UART_Transmit -****************************************************************************//** -* -* Sends the data to UART TX FIFO. The function handles data length up to the -* supported TX FIFO length of the UART hardware module. -* -* \param data: Pointer to the data to send through the UART -* \param length: the length of data to transmit in bytes -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_HOST_UART_Transmit(const uint8_t *dataBuf, - uint8_t length) -{ - Cy_SCB_UART_PutArrayBlocking(cy_ble_configPtr->uartHostHw, (uint8_t*)dataBuf, (uint32_t)length); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_HOST_UART_IsrEnable -****************************************************************************//** -* -* Enables the UART interrupt to the interrupt controller. -* Do not call this function unless Cy_BLE_HAL_HOST_UART_Start() has been called or the -* functionality of the Cy_SysInt_Init() function, which sets the vector and the -* priority, has been called. -* -*******************************************************************************/ -void Cy_BLE_HAL_HOST_UART_IsrEnable(void) -{ - NVIC_EnableIRQ((IRQn_Type)cy_ble_configPtr->uartHostIsrConfig->intrSrc); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_HOST_UART_IsrDisable -****************************************************************************//** -* -* Disables the UART Interrupt in the interrupt controller. -* -*******************************************************************************/ -void Cy_BLE_HAL_HOST_UART_IsrDisable(void) -{ - NVIC_DisableIRQ((IRQn_Type)cy_ble_configPtr->uartHostIsrConfig->intrSrc); -} - -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ - - -#if (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_UART_Interrupt -****************************************************************************//** -* -* Handles the Interrupt Service Routine for the UART. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_UART_Interrupt(void) -{ - uint8_t uartTxStatus = CY_BLE_INTR_TX_SUCCESS; - uint32_t srcInterrupt; - - uint8_t length = 0u; - uint8_t srcCount = 0u; - uint8_t uartRxStatus = CY_BLE_INTR_RX_SUCCESS; - uint8_t receivedData; - - /* Evaluate RX interrupt event */ - srcInterrupt = Cy_SCB_GetRxInterruptStatusMasked(cy_ble_configPtr->uartHw); - - if(0u != (srcInterrupt & CY_SCB_RX_INTR_NOT_EMPTY)) - { - if(0u != (srcInterrupt & CY_SCB_RX_INTR_UART_PARITY_ERROR)) - { - uartRxStatus |= CY_BLE_INTR_RX_PARITY_ERROR; - } - if(0u != (srcInterrupt & CY_SCB_RX_INTR_UART_FRAME_ERROR)) - { - uartRxStatus |= CY_BLE_INTR_RX_FRAME_ERROR; - } - if(0u != (srcInterrupt & CY_SCB_RX_INTR_OVERFLOW)) - { - uartRxStatus |= CY_BLE_INTR_RX_OVERFLOW; - } - if(uartRxStatus == CY_BLE_INTR_RX_SUCCESS) - { - length = (uint8_t)Cy_SCB_GetNumInRxFifo(cy_ble_configPtr->uartHw); - for(srcCount = 0u; srcCount < length; srcCount++) - { - receivedData = (uint8_t)Cy_SCB_ReadRxFifo(cy_ble_configPtr->uartHw); - Cy_BLE_HAL_UartRxDataHandler(receivedData); - } - } - else - { - Cy_SCB_ClearRxFifo(cy_ble_configPtr->uartHw); - } - Cy_SCB_ClearRxInterrupt(cy_ble_configPtr->uartHw, srcInterrupt); - } - else - { - /* No RX interrupt. Do nothing. */ - } - - /* Evaluate TX interrupt event in sequence */ - srcInterrupt = Cy_SCB_GetTxInterruptStatusMasked(cy_ble_configPtr->uartHw); - - /* Stack manager TX UART complete */ - if(0u != (srcInterrupt & CY_SCB_TX_INTR_UART_DONE)) - { - if(0u != (srcInterrupt & CY_SCB_TX_INTR_OVERFLOW)) - { - /*Stack manager TX UART error */ - uartTxStatus |= CY_BLE_INTR_TX_OVERFLOW; - } - Cy_BLE_HAL_UartTxCompltHandler(); - Cy_SCB_ClearTxInterrupt(cy_ble_configPtr->uartHw, srcInterrupt); - } - else - { - /* No TX interrupt. Do nothing. */ - } -} - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_UART_Start -****************************************************************************//** -* -* Enables the platform UART TX and RX interrupts and then enables the UART -* component. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_UART_Start(void) -{ - /* Setup ISR */ - Cy_SysInt_Init(cy_ble_configPtr->uartIsrConfig, &Cy_BLE_HAL_UART_Interrupt); - NVIC_EnableIRQ((IRQn_Type)cy_ble_configPtr->uartIsrConfig->intrSrc); - - (void)Cy_SCB_UART_Init(cy_ble_configPtr->uartHw, cy_ble_configPtr->uartConfig, NULL); - /* Configure interrupt sources. */ - Cy_SCB_SetRxInterruptMask(cy_ble_configPtr->uartHw, - CY_SCB_RX_INTR_NOT_EMPTY | CY_SCB_RX_INTR_OVERFLOW | CY_SCB_RX_INTR_UNDERFLOW); - Cy_SCB_SetTxInterruptMask(cy_ble_configPtr->uartHw, CY_SCB_TX_INTR_OVERFLOW | CY_SCB_TX_INTR_UART_DONE); - - Cy_SCB_UART_Enable(cy_ble_configPtr->uartHw); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_UART_Stop -****************************************************************************//** -* -* Disables the UART, clears all pending interrupts and disables the UART TX -* and RX interrupts. This will also empty out the FIFOs. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_UART_Stop(void) -{ - /* Stop interrupt and UART */ - NVIC_DisableIRQ((IRQn_Type)cy_ble_configPtr->uartIsrConfig->intrSrc); - - Cy_SCB_UART_Disable(cy_ble_configPtr->uartHw, NULL); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_UART_Transmit -****************************************************************************//** -* -* Sends the data to UART TX FIFO. The function handles data length up to the -* supported TX FIFO length of the UART hardware module. -* -* \param data: Pointer to the data to send through the UART -* \param length: the length of data to transmit in bytes -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_UART_Transmit(uint8_t *dataBuf, - uint8_t length) -{ - Cy_SCB_UART_PutArrayBlocking(cy_ble_configPtr->uartHw, dataBuf, (uint32_t)length); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_UART_IsrEnable -****************************************************************************//** -* -* Enables the UART interrupt to the interrupt controller. -* Do not call this function unless Cy_BLE_HAL_UART_Start() has been called or the -* functionality of the Cy_SysInt_Init() function, which sets the vector and the -* priority, has been called. -* -*******************************************************************************/ -void Cy_BLE_HAL_UART_IsrEnable(void) -{ - NVIC_EnableIRQ((IRQn_Type)cy_ble_configPtr->uartIsrConfig->intrSrc); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_UART_IsrDisable -****************************************************************************//** -* -* Disables the UART Interrupt in the interrupt controller. -* -*******************************************************************************/ -void Cy_BLE_HAL_UART_IsrDisable(void) -{ - NVIC_DisableIRQ((IRQn_Type)cy_ble_configPtr->uartIsrConfig->intrSrc); -} - -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ - -#if(CY_BLE_CONFIG_STACK_CONTR_CORE) -/******************************************************************************* -* Function Name: Cy_BLE_HAL_RadioCalibrationWrite -****************************************************************************//** -* -* Write radio calibration data to SFLASH -* -* \param data: Pointer to the buffer containing the data to be stored. -* \param length: The length of the data in bytes. -* -* \return -* CY_BLE_SUCCESS A successful write -* CY_BLE_ERROR_INVALID_PARAMETER At least one of the input parameters is invalid -* CY_BLE_ERROR_FLASH_WRITE Error in flash Write -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HAL_RadioCalibrationWrite(const void *data, uint32_t length) -{ - cy_en_ble_api_result_t rc; - - if((data != NULL) && - (length <= (CY_FLASH_SIZEOF_ROW - sizeof(cy_stc_ble_gap_bd_addr_t)))) - { - rc = Cy_BLE_HAL_NvramWrite(data, (uint8_t *)CY_BLE_SFLASH_BLE_RADIO_CALL_ADDRESS, length); - } - else - { - rc = CY_BLE_ERROR_INVALID_PARAMETER; - } - return(rc); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_RadioCalibrationRead -****************************************************************************//** -* -* Read radio calibration data from SFLASH -* -* \param data: Pointer to the buffer containing the data to be read from SFASH. -* \param length: The length of the data in bytes. -* -* \return -* CY_BLE_SUCCESS A successful read -* CY_BLE_ERROR_INVALID_PARAMETER At least one of the input parameters is invalid -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HAL_RadioCalibrationRead(void *data, uint32_t length) -{ - cy_en_ble_api_result_t rc = CY_BLE_SUCCESS; - - if((data != NULL) && - (length <= (CY_FLASH_SIZEOF_ROW - sizeof(cy_stc_ble_gap_bd_addr_t)))) - { - (void) memcpy(data, (void *)CY_BLE_SFLASH_BLE_RADIO_CALL_ADDRESS, length); - } - else - { - rc = CY_BLE_ERROR_INVALID_PARAMETER; - } - return(rc); -} - -#endif /* CY_BLE_CONFIG_STACK_CONTR_CORE */ - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_NvramWrite -****************************************************************************//** -* -* This function writes the data to the NVRAM store. It will check the -* appropriate alignment of a start address and also perform an address range -* check based on the length before performing the write operation. -* This function performs memory compare and writes only row where there are new -* data to write. -* -* \param buffer: Pointer to the buffer containing the data to be stored. -* \param varFlash: Pointer to the array or variable in the flash. -* \param length: The length of the data in bytes. -* -* \return -* CY_BLE_SUCCESS A successful write -* CY_BLE_ERROR_INVALID_PARAMETER At least one of the input parameters is invalid -* CY_BLE_ERROR_FLASH_WRITE Error in flash Write -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HAL_NvramWrite(const uint8_t buffer[], - const uint8_t varFlash[], - uint32_t length) -{ - cy_en_ble_api_result_t bleReturn; - cy_en_flashdrv_status_t rc = CY_FLASH_DRV_SUCCESS; - - uint32_t writeBuffer[CY_FLASH_SIZEOF_ROW / sizeof(uint32_t)]; - uint32_t rowId; - uint32_t dstIndex; - uint32_t srcIndex = 0u; - uint32_t eeOffset; - uint32_t byteOffset; - uint32_t rowsNotEqual; - uint8_t *writeBufferPointer; - - eeOffset = (uint32_t)varFlash; - writeBufferPointer = (uint8_t*)writeBuffer; - - /* Make sure, that varFlash[] points to Flash or WFlash */ - if(((eeOffset >= CY_FLASH_BASE) && - ((eeOffset + length) <= (CY_FLASH_BASE + CY_FLASH_SIZE))) || - ((eeOffset >= CY_WFLASH_BASE) && - ((eeOffset + length) <= (CY_WFLASH_BASE + CY_WFLASH_SIZE))) || - ((eeOffset >= (uint32_t)SFLASH->BLE_DEVICE_ADDRESS) && - ((eeOffset + length) <= ((uint32_t)SFLASH->BLE_DEVICE_ADDRESS + CY_FLASH_SIZEOF_ROW)))) - { - cy_en_syspm_simo_buck_voltage1_t simoVoltage = CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V; - cy_en_syspm_ldo_voltage_t ldoVoltage = CY_SYSPM_LDO_VOLTAGE_1_1V; - - if(Cy_SysPm_SimoBuckIsEnabled()) - { - simoVoltage = Cy_SysPm_SimoBuckGetVoltage1(); - if(simoVoltage == CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V) - { /* Increase core voltage for write to flash operation */ - Cy_SysPm_SimoBuckSetVoltage1(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V); - } - } - if(Cy_SysPm_LdoIsEnabled()) - { - ldoVoltage = Cy_SysPm_LdoGetVoltage(); - if(ldoVoltage == CY_SYSPM_LDO_VOLTAGE_0_9V) - { /* Increase core voltage for write to flash operation */ - Cy_SysPm_LdoSetVoltage(CY_SYSPM_LDO_VOLTAGE_1_1V); - } - } - - eeOffset -= CY_FLASH_BASE; - rowId = eeOffset / CY_FLASH_SIZEOF_ROW; - byteOffset = CY_FLASH_SIZEOF_ROW * rowId; - - while((srcIndex < length) && (rc == CY_FLASH_DRV_SUCCESS)) - { - rowsNotEqual = 0u; - /* Copy data to the write buffer either from the source buffer or from the flash */ - for(dstIndex = 0u; dstIndex < CY_FLASH_SIZEOF_ROW; dstIndex++) - { - if((byteOffset >= eeOffset) && (srcIndex < length)) - { - writeBufferPointer[dstIndex] = buffer[srcIndex]; - /* Detect that row programming is required */ - if((rowsNotEqual == 0u) && (CY_GET_REG8(CY_FLASH_BASE + byteOffset) != buffer[srcIndex])) - { - rowsNotEqual = 1u; - } - srcIndex++; - } - else - { - writeBufferPointer[dstIndex] = CY_GET_REG8(CY_FLASH_BASE + byteOffset); - } - byteOffset++; - } - - if(rowsNotEqual != 0u) - { - /* Erase flash row */ - rc = Cy_Flash_StartErase((rowId * CY_FLASH_SIZEOF_ROW) + CY_FLASH_BASE); - if(rc == CY_FLASH_DRV_OPERATION_STARTED) - { - /* Polls whether the Flash operation is performed */ - do - { - rc = Cy_Flash_IsEraseComplete(); - } - while (rc == CY_FLASH_DRV_OPCODE_BUSY); - } - - /* Program flash row */ - if(rc == CY_FLASH_DRV_SUCCESS) - { - /* Program flash row */ - rc = Cy_Flash_StartProgram((rowId * CY_FLASH_SIZEOF_ROW) + CY_FLASH_BASE, writeBuffer); - if(rc == CY_FLASH_DRV_OPERATION_STARTED) - { - /* Polls whether the Flash operation is performed */ - do - { - rc = Cy_Flash_IsProgramComplete(); - } - while (rc == CY_FLASH_DRV_OPCODE_BUSY); - } - } - - } - - /* Go to the next row */ - rowId++; - } - if((Cy_SysPm_SimoBuckIsEnabled()) && (simoVoltage == CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V)) - { /* Return core voltage */ - Cy_SysPm_SimoBuckSetVoltage1(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V); - } - if((Cy_SysPm_LdoIsEnabled()) && (ldoVoltage == CY_SYSPM_LDO_VOLTAGE_0_9V)) - { /* Return core voltage */ - Cy_SysPm_LdoSetVoltage(CY_SYSPM_LDO_VOLTAGE_0_9V); - } - } - else - { - rc = CY_FLASH_DRV_INVALID_INPUT_PARAMETERS; - } - - /* Return BLE error code */ - switch(rc) - { - case CY_FLASH_DRV_SUCCESS: - bleReturn = CY_BLE_SUCCESS; - break; - - case CY_FLASH_DRV_INVALID_INPUT_PARAMETERS: - case CY_FLASH_DRV_INVALID_FLASH_ADDR: - bleReturn = CY_BLE_ERROR_INVALID_PARAMETER; - break; - - default: - bleReturn = CY_BLE_ERROR_FLASH_WRITE; - break; - } - - return(bleReturn); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_NvramNonBlockingRowWrite -****************************************************************************//** -* -* This function writes one row to the NVRAM store. It will check the -* appropriate alignment of a start address and also perform an address range -* check based on the length before performing the write operation. -* This function performs memory compare and writes only row where there are new -* data to write. -* -* If function returns CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS -* it means that writing is no complete yet and require to invoke again to get finish. -* -* This function is designated for internal usage. -* -* \param buffer: Pointer to the buffer containing the data to be stored. -* \param varFlash: Pointer to the array or variable in the flash. -* \param length: The length of the data in bytes. -* -* \return -* CY_BLE_SUCCESS A successful write -* CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS Row writing in progress -* CY_BLE_ERROR_INVALID_PARAMETER At least one of the input parameters is invalid -* CY_BLE_ERROR_FLASH_WRITE Error in flash Write -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HAL_NvramNonBlockingRowWrite(const uint8_t buffer[], - const uint8_t varFlash[], - uint32_t length) -{ - static cy_en_ble_api_result_t nvramState = CY_BLE_SUCCESS; - static cy_en_syspm_simo_buck_voltage1_t simoVoltage = CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V; - static cy_en_syspm_ldo_voltage_t ldoVoltage = CY_SYSPM_LDO_VOLTAGE_1_1V; - static uint32_t writeBuffer[CY_FLASH_SIZEOF_ROW / sizeof(uint32_t)] = {0x00}; - - cy_en_flashdrv_status_t rc = CY_FLASH_DRV_SUCCESS; - - uint32_t rowId; - uint32_t dstIndex; - uint32_t srcIndex = 0u; - uint32_t eeOffset = (uint32_t)varFlash; - uint32_t byteOffset; - uint8_t *writeBufferPointer; - - bool rowNotEqual = false; - bool restoreCoreVoltage = false; - - writeBufferPointer = (uint8_t*)writeBuffer; - - /* Make sure, that varFlash[] points to Flash or WFlash */ - if((((eeOffset >= CY_FLASH_BASE) && ((eeOffset + length) <= (CY_FLASH_BASE + CY_FLASH_SIZE))) || - ((eeOffset >= CY_WFLASH_BASE) && ((eeOffset + length) <= (CY_WFLASH_BASE + CY_WFLASH_SIZE)))) && - (length <= CY_FLASH_SIZEOF_ROW) - ) - { - eeOffset -= CY_FLASH_BASE; - rowId = eeOffset / CY_FLASH_SIZEOF_ROW; - byteOffset = CY_FLASH_SIZEOF_ROW * rowId; - - switch (nvramState) - { - /* Start write row */ - case CY_BLE_SUCCESS: - case CY_BLE_ERROR_FLASH_WRITE: - case CY_BLE_ERROR_INVALID_PARAMETER: - - /* Copy data to the write buffer either from the source buffer or from the flash - and check if row programming is required */ - for(dstIndex = 0u; dstIndex < CY_FLASH_SIZEOF_ROW; dstIndex++) - { - if((byteOffset >= eeOffset) && (srcIndex < length)) - { - writeBufferPointer[dstIndex] = buffer[srcIndex]; - - /* Detect that row programming is required */ - if((rowNotEqual == false) && (CY_GET_REG8(CY_FLASH_BASE + byteOffset) != buffer[srcIndex])) - { - rowNotEqual = true; - } - srcIndex++; - } - else - { - writeBufferPointer[dstIndex] = CY_GET_REG8(CY_FLASH_BASE + byteOffset); - } - byteOffset++; - } - - /* Start a new write */ - if(rowNotEqual != false) - { - /* Increase core voltage for write to flash operation */ - if(Cy_SysPm_SimoBuckIsEnabled()) - { - simoVoltage = Cy_SysPm_SimoBuckGetVoltage1(); - if(simoVoltage == CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V) - { /* Increase core voltage for write to flash operation */ - Cy_SysPm_SimoBuckSetVoltage1(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_1_1V); - } - } - if(Cy_SysPm_LdoIsEnabled()) - { - ldoVoltage = Cy_SysPm_LdoGetVoltage(); - if(ldoVoltage == CY_SYSPM_LDO_VOLTAGE_0_9V) - { /* Increase core voltage for write to flash operation */ - Cy_SysPm_LdoSetVoltage(CY_SYSPM_LDO_VOLTAGE_1_1V); - } - } - - /* Write flash row */ - rc = Cy_Flash_StartWrite((rowId * CY_FLASH_SIZEOF_ROW) + CY_FLASH_BASE, writeBuffer); - - if (rc != CY_FLASH_DRV_OPERATION_STARTED) - { - /* We have error during start write, returns CY_BLE_ERROR_FLASH_WRITE and stop writing */ - nvramState = CY_BLE_ERROR_FLASH_WRITE; - - /* Set flag for restore core voltage */ - restoreCoreVoltage = true; - } - - nvramState = CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS; - } - else - { - nvramState = CY_BLE_SUCCESS; - } - break; - - case CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS: - - /* Check the status of the Flash operation */ - rc = Cy_Flash_IsWriteComplete(); - - if(rc == CY_FLASH_DRV_SUCCESS) - { - nvramState = CY_BLE_SUCCESS; - restoreCoreVoltage = true; - } - - if(rc == CY_FLASH_DRV_OPCODE_BUSY) - { - nvramState = CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS; - } - break; - - default: - break; - } - - /* Restore core voltage */ - if(restoreCoreVoltage == true) - { - if((Cy_SysPm_SimoBuckIsEnabled()) && (simoVoltage == CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V)) - { /* Return core voltage */ - Cy_SysPm_SimoBuckSetVoltage1(CY_SYSPM_SIMO_BUCK_OUT1_VOLTAGE_0_9V); - } - if((Cy_SysPm_LdoIsEnabled()) && (ldoVoltage == CY_SYSPM_LDO_VOLTAGE_0_9V)) - { /* Return core voltage */ - Cy_SysPm_LdoSetVoltage(CY_SYSPM_LDO_VOLTAGE_0_9V); - } - } - } - else - { - nvramState = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(nvramState); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_NvramWriteIsBusy -****************************************************************************//** -* -* Reports the flash operation in the BLE host core is active -* -* \return -* true - flash operation is active -* false - no flash activity -* -*******************************************************************************/ -bool Cy_BLE_HAL_NvramWriteIsBusy(void) -{ - uint32_t ipcChanNum; - bool retVal = true; - - /* Select CY_IPC_CHAN_SYSCAL regarding to host core */ - #if (CY_BLE_HOST_CORE == CY_CPU_CORTEX_M4) - ipcChanNum = CY_IPC_CHAN_SYSCALL_CM4; - #else - ipcChanNum = CY_IPC_CHAN_SYSCALL_CM0; - #endif /* (CY_CPU_CORTEX_M0P) */ - - /* Checks if the IPC structure is not locked */ - if (Cy_IPC_Drv_IsLockAcquired((IPC_STRUCT_Type*) &IPC->STRUCT[ipcChanNum]) == false) - { - retVal = false; - } - - return (retVal); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_CalcCRC8 -****************************************************************************//** -* -* Implements CRC-8 calculation -* -* \param data -* The data to be used to calculate the CRC. -* -* \param length -* The length of data. -* -* \return -* The calculated CRC value. -* -*******************************************************************************/ -uint8_t Cy_BLE_HAL_CalcCRC8(uint8_t data[], uint32_t length) -{ - /* CRC-8 constants */ - const uint8_t CY_BLE_HAL_CRC8_SEED = 0x00u; - const uint8_t CY_BLE_HAL_CRC8_POLYNOM = 0x31u; - const uint8_t CY_BLE_HAL_CRC8_POLYNOM_LEN = 0x8u; - - uint8_t crc = CY_BLE_HAL_CRC8_SEED; - uint8_t i; - - while(0u != length) - { - crc ^= *data; - for (i = 0u; i < CY_BLE_HAL_CRC8_POLYNOM_LEN; i++) - { - crc = (0x80u == (((uint16_t)crc) & 0x80u)) ? - ((uint8_t)(((uint8_t)(crc << 1u)) ^ CY_BLE_HAL_CRC8_POLYNOM)) : ((uint8_t)(crc << 1u)); - } - data++; - length--; - } - - return crc; -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_GetIcPackageType -****************************************************************************//** -* -* This function returns package type -* -* return: -* 0 - BGA package -* 1 - CSP package -* -*******************************************************************************/ -/******************************************************************************* -* Function Name: Cy_BLE_HAL_GetIcPackageType -****************************************************************************//** -* -* This function returns package type -* -* return: -* 0 - BGA package -* 1 - CSP package -* -*******************************************************************************/ -uint32_t Cy_BLE_HAL_GetIcPackageType(void) -{ - return((CY_GPIO_PACKAGE_TYPE == CY_GPIO_PACKAGE_CSP) ? 1u : 0u); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_DelayUs -****************************************************************************//** -* -* Interface to Cy_SysLib_DelayUs function. -* -*******************************************************************************/ -void Cy_BLE_HAL_DelayUs(uint16_t delayVal) -{ - Cy_SysLib_DelayUs(delayVal); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_DelayMs -****************************************************************************//** -* -* Interface to Cy_SysLib_Delay function. -* -*******************************************************************************/ -void Cy_BLE_HAL_DelayMs(uint32_t delayVal) -{ - Cy_SysLib_Delay(delayVal); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_EnableGlobalInterrupts -****************************************************************************//** -* -* This function enables all interrupt used by the component. -* -*******************************************************************************/ -void Cy_BLE_HAL_EnableGlobalInterrupts(void) -{ -#if (CY_BLE_STACK_MODE_HOST_UART) - Cy_BLE_HAL_HOST_UART_IsrEnable(); -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ - -#if (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) - Cy_BLE_HAL_UART_IsrEnable(); -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ - -/* Enable IPC interrupt */ -#if (CY_BLE_STACK_MODE_IPC) - Cy_BLE_Ipc_Cypipe_Isr_Enable(); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ - -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - NVIC_EnableIRQ((IRQn_Type)cy_ble_configPtr->blessIsrConfig->intrSrc); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_DisableGlobalInterrupts -****************************************************************************//** -* -* This disables all interrupt used by the component. -* -*******************************************************************************/ -void Cy_BLE_HAL_DisableGlobalInterrupts(void) -{ -#if (CY_BLE_STACK_MODE_HOST_UART) - Cy_BLE_HAL_HOST_UART_IsrDisable(); -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ - -#if (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) - Cy_BLE_HAL_UART_IsrDisable(); -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ - -/* Disable IPC interrupt */ -#if (CY_BLE_STACK_MODE_IPC) - Cy_BLE_Ipc_Cypipe_Isr_Disable(); -#endif /* (CY_BLE_STACK_MODE_IPC) */ - -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - NVIC_DisableIRQ((IRQn_Type)cy_ble_configPtr->blessIsrConfig->intrSrc); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ -} - -/* Stack Interface to clock */ - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_LfClkGetSource -****************************************************************************//** -* -* Interface to Cy_SysClk_LfClkGetSource function. -* -*******************************************************************************/ -cy_en_clklf_in_sources_t Cy_BLE_HAL_LfClkGetSource(void) -{ - return(Cy_SysClk_ClkLfGetSource()); -} - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_ClkMeasurementCountersDone -****************************************************************************//** -* -* Interface to Cy_SysClk_ClkMeasurementCountersDone function. -* -*******************************************************************************/ -int32_t Cy_BLE_HAL_ClkMeasurementCountersDone(void) -{ - return((int32_t)Cy_SysClk_ClkMeasurementCountersDone()); -} - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_ClkMeasurementCountersGetClock2Freq -****************************************************************************//** -* -* Interface to Cy_SysClk_ClkMeasurementCountersGetFreq function. -* -*******************************************************************************/ -uint32_t Cy_BLE_HAL_ClkMeasurementCountersGetFreq(bool measuredClock, - uint32_t refClkFreq) -{ - return(Cy_SysClk_ClkMeasurementCountersGetFreq(measuredClock, refClkFreq)); -} - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_StartClkMeasurementCounters -****************************************************************************//** -* -* Interface to Cy_SysClk_StartClkMeasurementCounters function. -* -*******************************************************************************/ -uint32_t Cy_BLE_HAL_StartClkMeasurementCounters(cy_en_meas_clks_t clock1, - uint32_t count1, - cy_en_meas_clks_t clock2) -{ - return((uint32_t)Cy_SysClk_StartClkMeasurementCounters(clock1, count1, clock2)); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_PiloTrim -****************************************************************************//** -* -* Interface to Cy_SysClk_PiloTrim function. -* -*******************************************************************************/ -int32_t Cy_BLE_HAL_PiloTrim(uint32_t piloFreq) -{ - return(Cy_SysClk_PiloTrim(piloFreq)); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_BlessStart -****************************************************************************//** -* -* Starts Interrupt Controller. -* -* \return -* None -* -*******************************************************************************/ -void Cy_BLE_HAL_BlessStart(void) -{ - Cy_BLE_HAL_Init(); - - /* Configures external power apmlifier outputs. */ - Cy_BLE_ConfigureExtPA(BLE_BLESS_EXT_PA_LNA_CTRL_ENABLE_EXT_PA_LNA_Msk | - (CY_BLE_CONFIG_EXT_PA_ENABLED ? BLE_BLESS_EXT_PA_LNA_CTRL_OUT_EN_DRIVE_VAL_Msk : 0u)); - -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - /* Setup BLESS ISR */ - (void)Cy_SysInt_Init(cy_ble_configPtr->blessIsrConfig, &Cy_BLE_BlessInterrupt); - NVIC_EnableIRQ((IRQn_Type)cy_ble_configPtr->blessIsrConfig->intrSrc); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_GetIpBlockVersion -****************************************************************************//** -* -* This function returns the version of m0s8bless ip block. -* -* \return -* uint32_t bits: -* 7:0 - ip version ( 1 - BLE_ver1, 2 - BLE_ver2, 3 - BLE_ver3, 4 - BLE_ver3 (*A) ) -* 31:8 - reserved for future usage -* -*******************************************************************************/ -uint32_t Cy_BLE_HAL_GetIpBlockVersion(void) -{ - return(CY_BLE_M0S8BLESS_VERSION); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_EnterCriticalSection -****************************************************************************//** -* -* Interface to Cy_SysLib_EnterCriticalSection function. -* -*******************************************************************************/ -uint32_t Cy_BLE_HAL_EnterCriticalSection(void) -{ - return(Cy_SysLib_EnterCriticalSection()); -} - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_ExitCriticalSection -****************************************************************************//** -* -* Interface to Cy_SysLib_ExitCriticalSection function. -* -*******************************************************************************/ -void Cy_BLE_HAL_ExitCriticalSection(uint32_t interruptState) -{ - Cy_SysLib_ExitCriticalSection(interruptState); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_SysPmSleep -****************************************************************************//** -* -* Interface to Cy_SysPm_Sleep function. -* -*******************************************************************************/ -cy_en_syspm_status_t Cy_BLE_HAL_SysPmSleep(cy_en_syspm_waitfor_t enWaitFor) -{ - return(Cy_SysPm_Sleep(enWaitFor)); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_HAL_SimoBuckSetVoltage2 -****************************************************************************//** -* -* Interface to Cy_SysPm_SimoBuckSetVoltage2 function with disable the 200 uS -* delay after setting a higher voltage. -* -*******************************************************************************/ -void Cy_BLE_HAL_SimoBuckSetVoltage2(cy_en_syspm_simo_buck_voltage2_t voltage) -{ - Cy_SysPm_SimoBuckSetVoltage2(voltage, false); -} - - -#if (CY_BLE_STACK_MODE_IPC) - - -/******************************************************************************* -* Function Name: Cy_BLE_Ipc_Cypipe_Isr_Enable -****************************************************************************//** -* -* Enables the IPC pipe interrupt to the interrupt controller. -* -*******************************************************************************/ -void Cy_BLE_Ipc_Cypipe_Isr_Enable(void) -{ -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - (void)Cy_IPC_Pipe_EndpointResume(CY_BLE_IPC_CONTROLLER_ADDR); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ -#if (CY_BLE_HOST_CORE) - (void)Cy_IPC_Pipe_EndpointResume(CY_BLE_IPC_HOST_ADDR); -#endif /* (CY_BLE_HOST_CORE) */ -} - - -/******************************************************************************* -* Function Name: Cy_BLE_Ipc_Cypipe_Isr_Disable -****************************************************************************//** -* -* Disables the IPC pipe Interrupt in the interrupt controller. -* -*******************************************************************************/ -void Cy_BLE_Ipc_Cypipe_Isr_Disable(void) -{ -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - (void)Cy_IPC_Pipe_EndpointPause(CY_BLE_IPC_CONTROLLER_ADDR); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ -#if (CY_BLE_HOST_CORE) - (void)Cy_IPC_Pipe_EndpointPause(CY_BLE_IPC_HOST_ADDR); -#endif /* (CY_BLE_HOST_CORE) */ -} - -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) - - -/******************************************************************************* -* Function Name: Cy_BLE_IPC_ControllerRegisterClientCallbacks -****************************************************************************//** -* -* This function registers a callbacks to be called when a message is received on a pipe. -* -* \param ctrlMsgRecvCallBack -* Pointer to the callback to be called when the handle has received a message. -* -* \param ctrlMsgFlushRecvCallBack -* Pointer to the callback to be called when the handle has received a flush message. -* -* \return -* CY_IPC_PIPE_SUCCESS - Callback registered successfully -* CY_IPC_PIPE_ERROR_BAD_CLIENT - Client ID out of range, callback not registered. -*******************************************************************************/ -cy_en_ipc_pipe_status_t Cy_BLE_IPC_ControllerRegisterClientCallbacks(cy_ipc_pipe_callback_ptr_t ctrlMsgRecvCallBack, - cy_ipc_pipe_callback_ptr_t ctrlMsgFlushRecvCallBack) -{ - cy_en_ipc_pipe_status_t returnStatus; - - returnStatus = Cy_IPC_Pipe_RegisterCallback(CY_BLE_IPC_CONTROLLER_ADDR, ctrlMsgRecvCallBack, - CY_BLE_CYPIPE_MSG_SEND_ID); - - if(returnStatus == CY_IPC_PIPE_SUCCESS) - { - returnStatus = Cy_IPC_Pipe_RegisterCallback(CY_BLE_IPC_CONTROLLER_ADDR, ctrlMsgFlushRecvCallBack, - CY_BLE_CYPIPE_MSG_COMPLETE_ID); - } - - return(returnStatus); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_IPC_SendMessageToHost -****************************************************************************//** -* -* This function sends a message from the Controller to Host. -* -* \param msg -* Pointer to the message structure to be sent. -* -* \param controllerIpcRelCallBack -* Pointer to the Release callback function. -* -* \param controllerPollCallBack -* Pointer to the callback to be called when the handle has received a message. -* -* \return -* CY_IPC_PIPE_SUCCESS - message was sent to the other end of the pipe -* CY_IPC_PIPE_BAD_HANDLE - the handle provided for the pipe was not valid -* CY_IPC_PIPE_SEND_BUSY - the pipe is already busy sending a message -* CY_IPC_PIPE_DIR_ERROR - tried to send on the "to" end of a unidirectional pipe -*******************************************************************************/ -cy_en_ipc_pipe_status_t Cy_BLE_IPC_SendMessageToHost(uint32_t *msg, - cy_ipc_pipe_relcallback_ptr_t controllerIpcRelCallBack, - cy_ipc_pipe_relcallback_ptr_t controllerPollCallBack) -{ - cy_en_ipc_pipe_status_t returnStatus; - - returnStatus = Cy_IPC_Pipe_SendMessage(CY_BLE_IPC_HOST_ADDR, CY_BLE_IPC_CONTROLLER_ADDR, msg, - controllerIpcRelCallBack); - - if(returnStatus != CY_IPC_PIPE_SUCCESS) - { - Cy_IPC_Pipe_RegisterCallbackRel(CY_BLE_IPC_CONTROLLER_ADDR, controllerPollCallBack); - } - - return(returnStatus); -} - -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ - -#if (CY_BLE_HOST_CORE) - -/* BLE stack IPC Host handler */ -static cy_ipc_pipe_callback_ptr_t Cy_BLE_IPC_HostMsgFlushRecvStackHandle; -static void Cy_BLE_IPC_HostMsgFlushRecvCallBack(uint32_t * msgPtr); - - -/******************************************************************************* -* Function Name: Cy_BLE_IPC_HostMsgFlushRecvCallBack -****************************************************************************//** -* -* This a callbacks to be called when a message is received on a pipe. -* -* \param msgPtr -* Pointer to the callback message. -* -*******************************************************************************/ -static void Cy_BLE_IPC_HostMsgFlushRecvCallBack(uint32_t * msgPtr) -{ - /* Call BLE stack IPC handler */ - Cy_BLE_IPC_HostMsgFlushRecvStackHandle(msgPtr); - - /* Call the application IPC notification handler */ - if(Cy_BLE_IPC_HostRegisteredCallback != NULL) - { - Cy_BLE_IPC_HostRegisteredCallback(); - } -} - -/******************************************************************************* -* Function Name: Cy_BLE_IPC_HostRegisterClientCallbacks -****************************************************************************//** -* -* This function registers a callbacks to be called when a message is received on a pipe. -* -* \param hostMsgRecvCallBack -* Pointer to the callback to be called when the handle has received a message. -* -* \param hostMsgFlushRecvCallBack -* Pointer to the callback to be called when the handle has received a flush message. -* -* \return -* CY_IPC_PIPE_SUCCESS - Callback registered successfully -* CY_IPC_PIPE_ERROR_BAD_CLIENT - Client ID out of range, callback not registered. -*******************************************************************************/ -cy_en_ipc_pipe_status_t Cy_BLE_IPC_HostRegisterClientCallbacks(cy_ipc_pipe_callback_ptr_t hostMsgRecvCallBack, - cy_ipc_pipe_callback_ptr_t hostMsgFlushRecvCallBack) -{ - cy_en_ipc_pipe_status_t returnStatus; - - Cy_BLE_IPC_HostMsgFlushRecvStackHandle = hostMsgFlushRecvCallBack; - - returnStatus = Cy_IPC_Pipe_RegisterCallback(CY_BLE_IPC_HOST_ADDR, hostMsgRecvCallBack, CY_BLE_CYPIPE_MSG_SEND_ID); - - if(returnStatus == CY_IPC_PIPE_SUCCESS) - { - returnStatus = Cy_IPC_Pipe_RegisterCallback(CY_BLE_IPC_HOST_ADDR, &Cy_BLE_IPC_HostMsgFlushRecvCallBack, - CY_BLE_CYPIPE_MSG_COMPLETE_ID); - } - - return(returnStatus); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_IPC_RegisterAppHostCallback -****************************************************************************//** -* -* This function registers a application notify callback. -* This callback is triggered on receiving IPC messages from controller -* -* \param CallBack -* Pointer to the application notify callback. -* -* \return -* CY_BLE_SUCCESS | Callback registered successfully -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPC_RegisterAppHostCallback(cy_ble_ipc_app_notif_callback_t CallBack) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(CallBack != NULL) - { - Cy_BLE_IPC_HostRegisteredCallback = CallBack; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - return apiResult; -} - - -/******************************************************************************* -* Function Name: Cy_BLE_IPC_SendMessageToController -****************************************************************************//** -* -* This function sends a message from the Host to Controller. -* -* \param msg -* Pointer to the message structure to be sent. -* -* \param hostIpcRelCallBack -* Pointer to the Release callback function. -* -* \param hostPollCallBack -* Pointer to the callback to be called when the handle has received a message. -* -* \return -* CY_IPC_PIPE_SUCCESS - message was sent to the other end of the pipe -* CY_IPC_PIPE_BAD_HANDLE - the handle provided for the pipe was not valid -* CY_IPC_PIPE_SEND_BUSY - the pipe is already busy sending a message -* CY_IPC_PIPE_DIR_ERROR - tried to send on the "to" end of a unidirectional pipe -*******************************************************************************/ -cy_en_ipc_pipe_status_t Cy_BLE_IPC_SendMessageToController(uint32_t *msg, - cy_ipc_pipe_relcallback_ptr_t hostIpcRelCallBack, - cy_ipc_pipe_relcallback_ptr_t hostPollCallBack) -{ - cy_en_ipc_pipe_status_t returnStatus; - - returnStatus = Cy_IPC_Pipe_SendMessage(CY_BLE_IPC_CONTROLLER_ADDR, CY_BLE_IPC_HOST_ADDR, msg, hostIpcRelCallBack); - - if(returnStatus != CY_IPC_PIPE_SUCCESS) - { - Cy_IPC_Pipe_RegisterCallbackRel(CY_BLE_IPC_HOST_ADDR, hostPollCallBack); - } - - return(returnStatus); -} -#endif /* (CY_BLE_HOST_CORE) */ - -#endif /* (CY_BLE_STACK_MODE_IPC) */ - -/* Mapping functions for stack size optimization */ -#if (CY_BLE_MODE_PROFILE) - -#if (CY_BLE_SECURE_CONN_FEATURE_ENABLED) - -void Cy_BLE_HAL_EccHeapInit(uint8_t *heapMem, uint8_t numOfConn) -{ - Cy_BLE_HAL_MappingEccHeapInit(heapMem, numOfConn); -} - -void Cy_BLE_HAL_EccHeapDeInit(void) -{ - Cy_BLE_HAL_MappingEccHeapDeInit(); -} - -uint16_t Cy_BLE_HAL_EccGetFeatureHeapReq(uint8_t numOfConn) -{ - return(Cy_BLE_HAL_MappingEccGetFeatureHeapReq(numOfConn)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateSecurityKeypair(uint8_t p_publicKey[], - uint8_t p_privateKey[], - uint8_t random[]) -{ - return(Cy_BLE_HAL_MappingEccGenerateSecurityKeypair(p_publicKey, p_privateKey, random)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateDHKey(const uint8_t p_publicKey[], - const uint8_t p_privateKey[], - uint8_t p_secret[], uint8_t ci) -{ - return(Cy_BLE_HAL_MappingEccGenerateDHKey(p_publicKey, p_privateKey, p_secret, ci)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_EccValidPublicKey(const uint8_t p_publicKey[]) -{ - return(Cy_BLE_HAL_MappingEccValidPublicKey(p_publicKey)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingLocalPublicKeyHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingLocalPublicKeyHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingRemoteKeyHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingRemoteKeyHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingDhkeyHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyCheckHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingDhkeyCheckHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingKeypressNotificationHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingKeypressNotificationHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingRandHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingRandHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingConfirmHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingConfirmHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingLrConfirmingHandler(void *param) -{ - return(Cy_BLE_HAL_MappingPairingLrConfirmingHandler(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxDhkeyGenerateComplete(void *param) -{ - Cy_BLE_HAL_MappingTbxDhkeyGenerateComplete(param); - - return(CY_BLE_SUCCESS); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxLocalPubkeyGenerateComplete(void *param) -{ - Cy_BLE_HAL_MappingTbxLocalPubkeyGenerateComplete(param); - - return(CY_BLE_SUCCESS); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateLocalP256PublicKey(uint8_t param) -{ - return(Cy_BLE_HAL_MappingTbxGenerateLocalP256PublicKey(param)); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateDHkey(void *param1, - void *param2, - uint8_t param3) -{ - return(Cy_BLE_HAL_MappingTbxGenerateDHkey(param1, param2, param3)); -} - -void Cy_BLE_HAL_SmpScCmacComplete(uint8_t param) -{ - Cy_BLE_HAL_MappingSmpScCmacComplete(param); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_SeSmpScUserPasskeyHandler(void *param1, - void *param2) -{ - return(Cy_BLE_HAL_MappingSeSmpScUserPasskeyHandler(param1, param2)); -} - -void Cy_BLE_HAL_EccPointMult(uint8_t param) -{ - Cy_BLE_HAL_MappingEccPointMult(param); -} - -#else /* If feature is not required, return error. */ - -void Cy_BLE_HAL_EccHeapInit(uint8_t *heapMem CY_UNUSED, uint8_t numOfConn CY_UNUSED) -{ - -} - -void Cy_BLE_HAL_EccHeapDeInit(void) -{ - -} - -uint16_t Cy_BLE_HAL_EccGetFeatureHeapReq(uint8_t numOfConn) -{ - return(0u); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateSecurityKeypair(uint8_t p_publicKey[] CY_UNUSED, - uint8_t p_privateKey[] CY_UNUSED, - uint8_t random[] CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateDHKey(const uint8_t p_publicKey[] CY_UNUSED, - const uint8_t p_privateKey[] CY_UNUSED, - uint8_t p_secret[] CY_UNUSED, uint8_t ci CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_EccValidPublicKey(const uint8_t p_publicKey[] CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingLocalPublicKeyHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingRemoteKeyHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyCheckHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingKeypressNotificationHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingRandHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingConfirmHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingLrConfirmingHandler(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxDhkeyGenerateComplete(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxLocalPubkeyGenerateComplete(void *param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateLocalP256PublicKey(uint8_t param CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateDHkey(void *param1 CY_UNUSED, - void *param2 CY_UNUSED, - uint8_t param3 CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -void Cy_BLE_HAL_SmpScCmacComplete(uint8_t param CY_UNUSED) -{ -} - -cy_en_ble_api_result_t Cy_BLE_HAL_SeSmpScUserPasskeyHandler(void *param1 CY_UNUSED, - void *param2 CY_UNUSED) -{ - return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); -} - -void Cy_BLE_HAL_EccPointMult(uint8_t param CY_UNUSED) -{ -} - -#endif /* (CY_BLE_SECURE_CONN_FEATURE_ENABLED) */ - -#endif /* CY_BLE_MODE_PROFILE */ - -#endif /* CY_BLE_HOST_CONTR_CORE */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_pvt.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_pvt.h deleted file mode 100644 index cf6b9b9e39..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hal_pvt.h +++ /dev/null @@ -1,179 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hal_pvt.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the HAL section -* of the BLE component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_HALL_PVT_H -#define CY_BLE_HALL_PVT_H - -#include "BLE_config.h" - -#include "cy_ble_stack_pvt.h" -#include "cy_ble.h" -#include "cy_ble_gatt.h" -#include "cy_ble_clk.h" -#include "syspm/cy_syspm.h" -#include "flash/cy_flash.h" -#include "ipc/cy_ipc_pipe.h" -#include "cy_device_headers.h" - - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/*************************************** -* HAL Constants -***************************************/ -#define CY_BLE_HCI_COMMAND_SUCCEEDED (0x00u) -#define CY_BLE_UNKNOWN_HCI_COMMAND_ERROR (0x01u) - -#define CY_BLE_CYPIPE_MSG_COMPLETE_ID (0u) -#define CY_BLE_CYPIPE_MSG_SEND_ID (1u) - -#if (CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M4) - #define CY_BLE_IPC_CONTROLLER_ADDR (0u) /* (CY_IPC_EP_CYPIPE_CM0_ADDR) */ - #define CY_BLE_IPC_HOST_ADDR (1u) /* (CY_IPC_EP_CYPIPE_CM4_ADDR) */ -#else - #define CY_BLE_IPC_CONTROLLER_ADDR (1u) /* (CY_IPC_EP_CYPIPE_CM4_ADDR) */ - #define CY_BLE_IPC_HOST_ADDR (0u) /* (CY_IPC_EP_CYPIPE_CM0_ADDR) */ -#endif /* (CY_BLE_CONFIG_HOST_CORE == CY_BLE_CORE_CORTEX_M4) */ - -#define CY_BLE_SFLASH_BLE_RADIO_CALL_ADDRESS ((uint32_t)SFLASH->BLE_DEVICE_ADDRESS + sizeof(cy_stc_ble_gap_bd_addr_t)) - - -/*************************************** -* Function Prototypes -***************************************/ - -/* HAL ISR prototypes */ -void Cy_BLE_BlessInterrupt(void); -#if (CY_BLE_STACK_MODE_HOST_UART) -void Cy_BLE_HAL_HOST_UART_Interrupt(void); -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ -#if (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) -void Cy_BLE_HAL_UART_Interrupt(void); -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ - -void Cy_BLE_HAL_DelayUs(uint16_t delayVal); -void Cy_BLE_HAL_DelayMs(uint32_t delayVal); -void Cy_BLE_HAL_EnableGlobalInterrupts(void); -void Cy_BLE_HAL_DisableGlobalInterrupts(void); -void Cy_BLE_HAL_BlessStart(void); -uint32_t Cy_BLE_HAL_GetIpBlockVersion(void); -uint32_t Cy_BLE_HAL_GetIcPackageType(void); - -uint32_t Cy_BLE_HAL_EnterCriticalSection(void); -void Cy_BLE_HAL_ExitCriticalSection(uint32_t interruptState); -cy_en_syspm_status_t Cy_BLE_HAL_SysPmSleep(cy_en_syspm_waitfor_t enWaitFor); -void Cy_BLE_HAL_SimoBuckSetVoltage2(cy_en_syspm_simo_buck_voltage2_t voltage); - -/* Stack Interface to clock */ -int32_t Cy_BLE_HAL_ClkMeasurementCountersDone(void); -uint32_t Cy_BLE_HAL_ClkMeasurementCountersGetFreq(bool measuredClock, uint32_t refClkFreq); -uint32_t Cy_BLE_HAL_StartClkMeasurementCounters(cy_en_meas_clks_t clock1, uint32_t count1, cy_en_meas_clks_t clock2); -int32_t Cy_BLE_HAL_PiloTrim(uint32_t piloFreq); -cy_en_clklf_in_sources_t Cy_BLE_HAL_LfClkGetSource(void); - -/* Stack Interface to flash */ -cy_en_ble_api_result_t Cy_BLE_HAL_NvramWrite(const uint8_t buffer[], const uint8_t varFlash[], uint32_t length); -cy_en_ble_api_result_t Cy_BLE_HAL_NvramNonBlockingRowWrite(const uint8_t buffer[], const uint8_t varFlash[], uint32_t length); -bool Cy_BLE_HAL_NvramWriteIsBusy(void); -uint8_t Cy_BLE_HAL_CalcCRC8(uint8_t data[], uint32_t length); - -#if(CY_BLE_CONFIG_STACK_CONTR_CORE) - cy_en_ble_api_result_t Cy_BLE_HAL_RadioCalibrationRead(void *data, uint32_t length); - cy_en_ble_api_result_t Cy_BLE_HAL_RadioCalibrationWrite(const void *data, uint32_t length); -#endif /* CY_BLE_CONFIG_STACK_CONTR_CORE */ - -#if (CY_BLE_SECURE_CONN_FEATURE_ENABLED) - #if (CY_BLE_MODE_PROFILE) - void Cy_BLE_HAL_MappingEccHeapInit(uint8_t *heapMem, uint8_t numOfConn); - void Cy_BLE_HAL_MappingEccHeapDeInit(void); - uint16_t Cy_BLE_HAL_MappingEccGetFeatureHeapReq(uint8_t numOfConn); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingEccGenerateSecurityKeypair(uint8_t p_publicKey[], - uint8_t p_privateKey[], - uint8_t random[]); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingEccGenerateDHKey(const uint8_t p_publicKey[], - const uint8_t p_privateKey[], - uint8_t p_secret[], uint8_t ci); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingEccValidPublicKey(const uint8_t p_publicKey[]); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingLocalPublicKeyHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingRemoteKeyHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingDhkeyHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingDhkeyCheckHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingKeypressNotificationHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingRandHandler(void * param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingConfirmHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingPairingLrConfirmingHandler(void *param); - void Cy_BLE_HAL_MappingTbxDhkeyGenerateComplete(void *param); - void Cy_BLE_HAL_MappingTbxLocalPubkeyGenerateComplete(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingTbxGenerateLocalP256PublicKey(uint8_t param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingTbxGenerateDHkey(void *param1, void *param2, uint8_t param3); - void Cy_BLE_HAL_MappingSmpScCmacComplete(uint8_t param); - cy_en_ble_api_result_t Cy_BLE_HAL_MappingSeSmpScUserPasskeyHandler(void *param, void *param2); - void Cy_BLE_HAL_MappingEccPointMult(uint8_t param); - #endif /* (CY_BLE_MODE_PROFILE) */ -#endif /* (CY_BLE_SECURE_CONN_FEATURE_ENABLED) */ - -#if (CY_BLE_STACK_MODE_HOST_UART) -void Cy_BLE_HAL_HOST_UART_Start(void); -void Cy_BLE_HAL_HOST_UART_Stop(void); -void Cy_BLE_HAL_HOST_UART_Transmit(const uint8_t *dataBuf, uint8_t length); -void Cy_BLE_HAL_HOST_UART_IsrEnable(void); -void Cy_BLE_HAL_HOST_UART_IsrDisable(void); -#endif /* (CY_BLE_STACK_MODE_HOST_UART) */ - -#if (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) -void Cy_BLE_HAL_UART_Start(void); -void Cy_BLE_HAL_UART_Stop(void); -void Cy_BLE_HAL_UART_Transmit(uint8_t *dataBuf, uint8_t length); -void Cy_BLE_HAL_UART_IsrEnable(void); -void Cy_BLE_HAL_UART_IsrDisable(void); -#endif /* (CY_BLE_CONFIG_STACK_MODE_CONTR_UART) */ - -#if (CY_BLE_STACK_MODE_IPC) -void Cy_BLE_Ipc_Cypipe_Isr_Enable(void); -void Cy_BLE_Ipc_Cypipe_Isr_Disable(void); -#if (CY_BLE_CONFIG_STACK_CONTR_CORE) -cy_en_ipc_pipe_status_t Cy_BLE_IPC_ControllerRegisterClientCallbacks(cy_ipc_pipe_callback_ptr_t ctrlMsgRecvCallBack, - cy_ipc_pipe_callback_ptr_t ctrlMsgFlushRecvCallBack); -cy_en_ipc_pipe_status_t Cy_BLE_IPC_SendMessageToHost(uint32_t *msg, - cy_ipc_pipe_relcallback_ptr_t controllerIpcRelCallBack, - cy_ipc_pipe_relcallback_ptr_t controllerPollCallBack); -#endif /* (CY_BLE_CONFIG_STACK_CONTR_CORE) */ -#if (CY_BLE_HOST_CORE) -cy_en_ipc_pipe_status_t Cy_BLE_IPC_HostRegisterClientCallbacks(cy_ipc_pipe_callback_ptr_t hostMsgRecvCallBack, - cy_ipc_pipe_callback_ptr_t hostMsgFlushRecvCallBack); -cy_en_ipc_pipe_status_t Cy_BLE_IPC_SendMessageToController(uint32_t *msg, - cy_ipc_pipe_relcallback_ptr_t hostIpcRelCallBack, - cy_ipc_pipe_relcallback_ptr_t hostPollCallBack); - - -typedef void (* cy_ble_ipc_app_notif_callback_t) (void); - -cy_en_ble_api_result_t Cy_BLE_IPC_RegisterAppHostCallback(cy_ble_ipc_app_notif_callback_t CallBack); - -#endif /* (CY_BLE_HOST_CORE) */ -#endif /* (CY_BLE_STACK_MODE_IPC) */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_HALL_PVT_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hids.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hids.c deleted file mode 100644 index ce326f30f2..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hids.c +++ /dev/null @@ -1,2134 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hids.c -* \version 2.0 -* -* \brief -* Contains the source code for the HID service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HIDS)) - -static cy_ble_callback_t Cy_BLE_HIDS_ApplCallback; - -#ifdef CY_BLE_HIDS_SERVER -/* Local function prototypes */ -static uint32_t Cy_BLE_HIDSS_CccdWriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_HIDS_SERVER */ - -#ifdef CY_BLE_HIDS_CLIENT -/* HIDS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_hidsc_t cy_ble_hidsc[CY_BLE_CONFIG_GATTC_COUNT][CY_BLE_HIDSC_SERVICE_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_hidscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -uint8_t cy_ble_hidscServiceCount[CY_BLE_CONFIG_GATTC_COUNT]; - -/* To discovery descriptors for multiple HID service instances */ -uint8_t cy_ble_hidscDisServiceIndex[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_HIDS_CLIENT */ - -/* The pointer on global BLE HIDS Config structure */ -cy_stc_ble_hids_config_t *cy_ble_hidsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_HIDS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_HIDSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_HIDSS_OnDeviceConnected(void); -#endif /* CY_BLE_HIDS_SERVER */ - -#ifdef CY_BLE_HIDS_CLIENT -static void Cy_BLE_HIDSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_HIDSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_HIDSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_HIDSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_HIDSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_HIDSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_HIDSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_HIDSC_InclDiscoveryEventHandler(const cy_stc_ble_disc_incl_info_t *discInclInfo); -#endif /* CY_BLE_HIDS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_HIDS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDS_Init -***************************************************************************//** -* -* This function initializes the HID Service. -* -* \param config: Configuration structure for the HID Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDS_Init(cy_stc_ble_hids_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_hidsConfigPtr = config; - - /* Registers Event Handler for the HID Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_HIDS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_hidsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_HIDS_ApplCallback = cy_ble_hidsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_HIDS_CLIENT - { - uint32_t idx; - uint32_t locServIndex; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - for(locServIndex = 0u; locServIndex < CY_BLE_HIDSC_SERVICE_COUNT; locServIndex++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_HIDS + locServIndex].range.startHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_hidsc[idx][locServIndex], 0, sizeof(cy_stc_ble_hidsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_HIDS + locServIndex].uuid = CY_BLE_UUID_HIDS_SERVICE; - } - } - cy_ble_hidscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - cy_ble_hidscServiceCount[idx] = 0u; - } - } - #endif /* CY_BLE_HIDS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for HID Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_HIDS_NOTIFICATION_ENABLED). -* * eventParam contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_hids_char_value_t -* structure that contains details of the characteristic for -* which notification enabled event was triggered). -* -* -* \sideeffect The *eventParams in the callback function should not be used by -* the application once the callback function execution is finished. -* Otherwise this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_HIDS_ApplCallback = callbackFunc; - if(cy_ble_hidsConfigPtr != NULL) - { - cy_ble_hidsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_HIDS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets local characteristic value of the specified HID Service characteristics. -* -* \param serviceIndex: The index of the service instance. e.g. If two HID Services are -* supported in your design, then first service will be identified -* by serviceIndex of 0 and the second by serviceIndex of 1. -* \param charIndex: The index of a service characteristic. -* * CY_BLE_HIDS_PROTOCOL_MODE - Protocol Mode characteristic -* * CY_BLE_HIDS_REPORT_MAP - Report Map characteristic -* * CY_BLE_HIDS_INFORMATION - HID Information characteristic -* * CY_BLE_HIDS_CONTROL_POINT - HID Control Point characteristic -* * CY_BLE_HIDS_BOOT_KYBRD_IN_REP - Boot Keyboard Input Report Characteristic -* * CY_BLE_HIDS_BOOT_KYBRD_OUT_REP - Boot Keyboard Output Report Characteristic -* * CY_BLE_HIDS_BOOT_MOUSE_IN_REP - Boot Mouse Input Report Characteristic -* * CY_BLE_HIDS_REPORT - Report Characteristic -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSS_SetCharacteristicValue(uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_ble_gatt_db_attr_handle_t charValueHandle; - - if((serviceIndex >= CY_BLE_HIDSS_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - switch(charIndex) - { - case CY_BLE_HIDS_PROTOCOL_MODE: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].protocolModeHandle; - break; - - case CY_BLE_HIDS_REPORT_MAP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].reportMapHandle; - break; - - case CY_BLE_HIDS_INFORMATION: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].informationHandle; - break; - - case CY_BLE_HIDS_CONTROL_POINT: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].controlPointHandle; - break; - - case CY_BLE_HIDS_BOOT_KYBRD_IN_REP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX].reportHandle; - break; - - case CY_BLE_HIDS_BOOT_KYBRD_OUT_REP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_OUT_REP_INDX].reportHandle; - break; - - case CY_BLE_HIDS_BOOT_MOUSE_IN_REP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX].reportHandle; - break; - - default: /* Report characteristic */ - /* Verify that requested report exists in particular service */ - if(((uint8_t)charIndex - (uint8_t)CY_BLE_HIDS_REPORT) < - cy_ble_hidsConfigPtr->hidss[serviceIndex].reportCount) - { - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - reportArray[charIndex - CY_BLE_HIDS_REPORT].reportHandle; - } - else - { - charValueHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - break; - } - if(charValueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = charValueHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets local characteristic value of the specified HID Service characteristics. -* -* \param serviceIndex: The index of the service instance. e.g. If two HID Services are -* supported in your design, then first service will be identified -* by serviceIndex of 0 and the second by serviceIndex of 1. -* -* \param charIndex: The index of the service characteristic. -* * CY_BLE_HIDS_PROTOCOL_MODE - Protocol Mode characteristic -* * CY_BLE_HIDS_REPORT_MAP - Report Map characteristic -* * CY_BLE_HIDS_INFORMATION - HID Information characteristic -* * CY_BLE_HIDS_CONTROL_POINT - HID Control Point characteristic -* * CY_BLE_HIDS_BOOT_KYBRD_IN_REP - Boot Keyboard Input Report Characteristic -* * CY_BLE_HIDS_BOOT_KYBRD_OUT_REP - Boot Keyboard Output Report Characteristic -* * CY_BLE_HIDS_BOOT_MOUSE_IN_REP - Boot Mouse Input Report Characteristic -* * CY_BLE_HIDS_REPORT - Report Characteristic -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSS_GetCharacteristicValue(uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_ble_gatt_db_attr_handle_t charValueHandle; - - if((serviceIndex >= CY_BLE_HIDSS_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - switch(charIndex) - { - case CY_BLE_HIDS_PROTOCOL_MODE: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].protocolModeHandle; - break; - - case CY_BLE_HIDS_REPORT_MAP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].reportMapHandle; - break; - - case CY_BLE_HIDS_INFORMATION: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].informationHandle; - break; - - case CY_BLE_HIDS_CONTROL_POINT: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].controlPointHandle; - break; - - case CY_BLE_HIDS_BOOT_KYBRD_IN_REP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX].reportHandle; - break; - - case CY_BLE_HIDS_BOOT_KYBRD_OUT_REP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_OUT_REP_INDX].reportHandle; - break; - - case CY_BLE_HIDS_BOOT_MOUSE_IN_REP: - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX].reportHandle; - break; - - default: /* Report characteristic */ - /* Verify that requested report exists in particular service */ - if(((uint8_t)charIndex - (uint8_t)CY_BLE_HIDS_REPORT) < - cy_ble_hidsConfigPtr->hidss[serviceIndex].reportCount) - { - charValueHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex]. - reportArray[charIndex - CY_BLE_HIDS_REPORT].reportHandle; - } - else - { - charValueHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - break; - } - - if(charValueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = charValueHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets local characteristic descriptor of the specified HID Service -* characteristic. -* -* \param connHandle: BLE peer device connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two HID Services are -* supported in your design, then first service will be identified -* by serviceIndex of 0 and the second by serviceIndex of 1. -* -* \param charIndex: The index of the characteristic. -* * CY_BLE_HIDS_REPORT_MAP - Report Map Characteristic -* * CY_BLE_HIDS_BOOT_KYBRD_IN_REP - Boot Keyboard Input Report Characteristic -* * CY_BLE_HIDS_BOOT_KYBRD_OUT_REP - Boot Keyboard Output Report Characteristic -* * CY_BLE_HIDS_BOOT_MOUSE_IN_REP - Boot Mouse Input Report Characteristic -* * CY_BLE_HIDS_REPORT - Report Characteristic -* -* \param descrIndex: The index of the descriptor. -* * CY_BLE_HIDS_REPORT_CCCD - Client Characteristic Configuration descriptor -* * CY_BLE_HIDS_REPORT_RRD - Report Reference descriptor -* * CY_BLE_HIDS_REPORT_MAP_ERRD - Report Map External Report Reference descriptor -* -* \param attrSize: The size of the descriptor value attribute. -* -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_ble_gatt_db_attr_handle_t locDescrHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - const cy_stc_ble_hidss_report_t *locReport; - - if((serviceIndex >= CY_BLE_HIDSS_SERVICE_COUNT) || (descrIndex >= CY_BLE_HIDS_DESCR_COUNT) || - (charIndex >= CY_BLE_HIDS_CHAR_COUNT) || (charIndex < CY_BLE_HIDS_REPORT_MAP) || - (charIndex == CY_BLE_HIDS_BOOT_KYBRD_OUT_REP)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(charIndex == CY_BLE_HIDS_REPORT_MAP) - { - if(descrIndex == CY_BLE_HIDS_REPORT_MAP_ERRD) - { - locDescrHandle = cy_ble_hidsConfigPtr->hidss[serviceIndex].reportMapErrdHandle; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - else /* Report characteristics */ - { - /* Get report structure */ - if((charIndex >= CY_BLE_HIDS_BOOT_KYBRD_IN_REP) && (charIndex <= CY_BLE_HIDS_BOOT_MOUSE_IN_REP)) - { - locReport = &cy_ble_hidsConfigPtr->hidss[serviceIndex]. - bootReportArray[charIndex - CY_BLE_HIDS_BOOT_KYBRD_IN_REP]; - } - else - { - locReport = &cy_ble_hidsConfigPtr->hidss[serviceIndex].reportArray[charIndex - CY_BLE_HIDS_REPORT]; - } - /* Get descriptor handle from report structure */ - if(descrIndex == CY_BLE_HIDS_REPORT_CCCD) - { - locDescrHandle = locReport->cccdHandle; - } - else if(descrIndex == CY_BLE_HIDS_REPORT_RRD) - { - locDescrHandle = locReport->rrdHandle; - } - else /* External Report Reference descriptor doesn't exist for report characteristic */ - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - if(apiResult != CY_BLE_ERROR_INVALID_PARAMETER) - { - if(locDescrHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Read value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = locDescrHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_CccdWriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event of the Client Characteristic Configuration -* descriptor. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* uint32_t eventCode: The event code to be send to application. -* -******************************************************************************/ -static uint32_t Cy_BLE_HIDSS_CccdWriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - uint32_t eventCode; - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_NOTIFICATION_DISABLED; - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - -#if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } -#endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - return(eventCode); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write is successful. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HIDSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint8_t locServIndex = 0u; - uint32_t reportIndex; - cy_en_ble_hids_char_index_t locCharIndex; - cy_stc_ble_hids_char_value_t locCharValue; - uint32_t eventCode = 0u; - - if(Cy_BLE_HIDS_ApplCallback != NULL) - { - locCharValue.connHandle = eventParam->connHandle; - locCharValue.value = NULL; - do - { - locCharValue.serviceIndex = locServIndex; - /* Protocol Mode characteristic write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex].protocolModeHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_PROTOCOL_MODE; - if(eventParam->handleValPair.value.len == CY_BLE_HIDS_PM_CHAR_LEN) - { - switch(eventParam->handleValPair.value.val[0u]) - { - case CY_BLE_HIDS_PROTOCOL_MODE_BOOT: - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_BOOT_MODE_ENTER; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - case CY_BLE_HIDS_PROTOCOL_MODE_REPORT: - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_REPORT_MODE_ENTER; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - default: /* Reserved for Future Use. */ - break; - } - } - } - /* Control Point characteristic write request */ - else if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex].controlPointHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_CONTROL_POINT; - if(eventParam->handleValPair.value.len == CY_BLE_HIDS_CP_CHAR_LEN) - { - switch(eventParam->handleValPair.value.val[0u]) - { - case CY_BLE_HIDS_CP_SUSPEND: - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_SUSPEND; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - case CY_BLE_HIDS_CP_EXIT_SUSPEND: - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_EXIT_SUSPEND; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - - default: /* Reserved for Future Use. */ - break; - } - } - } - else if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX].reportHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_BOOT_KYBRD_IN_REP; - locCharValue.value = &eventParam->handleValPair.value; - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_REPORT_WRITE_CHAR; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX].cccdHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_BOOT_KYBRD_IN_REP; - eventCode = Cy_BLE_HIDSS_CccdWriteEventHandler(eventParam); - } - else if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_OUT_REP_INDX].reportHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_BOOT_KYBRD_OUT_REP; - locCharValue.value = &eventParam->handleValPair.value; - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_REPORT_WRITE_CHAR; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX].reportHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_BOOT_MOUSE_IN_REP; - locCharValue.value = &eventParam->handleValPair.value; - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_REPORT_WRITE_CHAR; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(eventParam->handleValPair.attrHandle == cy_ble_hidsConfigPtr->hidss[locServIndex]. - bootReportArray[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX].cccdHandle) - { - locCharValue.charIndex = CY_BLE_HIDS_BOOT_MOUSE_IN_REP; - eventCode = Cy_BLE_HIDSS_CccdWriteEventHandler(eventParam); - } - else - { - uint8_t locReqHandle = 0u; - - locCharIndex = CY_BLE_HIDS_REPORT; - for(reportIndex = 0u; (reportIndex < cy_ble_hidsConfigPtr->hidss[locServIndex].reportCount) && - (locReqHandle == 0u); reportIndex++) - { - if(eventParam->handleValPair.attrHandle == - cy_ble_hidsConfigPtr->hidss[locServIndex].reportArray[reportIndex].reportHandle) - { - locCharValue.charIndex = locCharIndex; - locCharValue.value = &eventParam->handleValPair.value; - eventCode = (uint32_t)CY_BLE_EVT_HIDSS_REPORT_WRITE_CHAR; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - locReqHandle = 1u; - } - if(eventParam->handleValPair.attrHandle == - cy_ble_hidsConfigPtr->hidss[locServIndex].reportArray[reportIndex].cccdHandle) - { - locCharValue.charIndex = locCharIndex; - eventCode = Cy_BLE_HIDSS_CccdWriteEventHandler(eventParam); - locReqHandle = 1u; - } - locCharIndex++; - } - } - locServIndex++; - - /* Store data to database if event is handled */ - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = eventParam->handleValPair.attrHandle, - .handleValuePair.value.len = eventParam->handleValPair.value.len, - .handleValuePair.value.val = eventParam->handleValPair.value.val, - .offset = 0u, - .connHandle = eventParam->connHandle, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_HIDS_ApplCallback(eventCode, &locCharValue); - } - break; - } - } - while(locServIndex < CY_BLE_HIDSS_SERVICE_COUNT); - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_SendNotification -***************************************************************************//** -* -* Sends specified HID Service characteristic notification to the Client device. -* -* CY_BLE_EVT_HIDSC_NOTIFICATION event is received by the peer device, on invoking -* this function. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_HIDSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: BLE peer device connection handle. -* \param serviceIndex: The index of the HID service instance. e.g. If two HID Services -* are supported in your design, then first service will be -* identified by serviceIndex of 0 and the second by serviceIndex -* of 1. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: Pointer to the characteristic value data that should be sent to -* the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - const cy_stc_ble_hidss_report_t *locReport; - - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((serviceIndex >= CY_BLE_HIDSS_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(charIndex == CY_BLE_HIDS_BOOT_KYBRD_IN_REP) - { - locReport = &cy_ble_hidsConfigPtr->hidss[serviceIndex].bootReportArray[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX]; - } - else if(charIndex == CY_BLE_HIDS_BOOT_MOUSE_IN_REP) - { - locReport = &cy_ble_hidsConfigPtr->hidss[serviceIndex].bootReportArray[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX]; - } - else if((charIndex >= CY_BLE_HIDS_REPORT) && (charIndex <= CY_BLE_HIDS_REPORT_END)) - { - /* Verify that requested report exists in particular service */ - if(((uint8_t)charIndex - (uint8_t)CY_BLE_HIDS_REPORT) < cy_ble_hidsConfigPtr->hidss[serviceIndex].reportCount) - { - locReport = &cy_ble_hidsConfigPtr->hidss[serviceIndex].reportArray[charIndex - CY_BLE_HIDS_REPORT]; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - if(apiResult == CY_BLE_SUCCESS) - { - if(locReport->reportHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Send Notification if it is enabled */ - if(CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, locReport->cccdHandle)) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = locReport->reportHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - else - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSS_OnDeviceConnected -***************************************************************************//** -* -* Handles the connection establishment request. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_HIDSS_OnDeviceConnected(void) -{ - /* The Protocol Mode characteristic value shall be reset to the default value - * following a connection establishment */ - uint8_t defaultProtocol = CY_BLE_HIDS_PROTOCOL_DEFAULT; - uint8_t locServIndex = 0u; - - do - { - if(cy_ble_hidsConfigPtr->hidss[locServIndex].protocolModeHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Store default protocol value in database */ - CY_BLE_GATT_DB_ATTR_SET_GEN_VALUE(cy_ble_hidsConfigPtr->hidss[locServIndex].protocolModeHandle, - &defaultProtocol, sizeof(defaultProtocol)); - } - ++locServIndex; - } - while(locServIndex < CY_BLE_HIDSS_SERVICE_COUNT); -} - - -#endif /* CY_BLE_HIDS_SERVER */ - -#ifdef CY_BLE_HIDS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_InclDiscoveryEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event -* Based on the service UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* \param discoveryService: The index of the service instance. -* -* -******************************************************************************/ -static void Cy_BLE_HIDSC_InclDiscoveryEventHandler(const cy_stc_ble_disc_incl_info_t *discInclInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discInclInfo->connHandle); - uint32_t discoveryService = cy_ble_discovery[discIdx].servCount - CY_BLE_SRVI_HIDS; - - if((discInclInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_HIDS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_HIDS_END)) - { - cy_ble_hidsc[discIdx][discoveryService].includeHandle = discInclInfo->inclDefHandle; - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event -* Based on the service UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_HIDSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - static uint32_t discoveryLastServ[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t discoveryService = cy_ble_discovery[discIdx].servCount - CY_BLE_SRVI_HIDS; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_HIDS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_HIDS_END)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - if(discoveryLastServ[discIdx] == discoveryService) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - } - lastEndHandle[discIdx] = NULL; - } - - switch(discCharInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_HIDS_PROTOCOL_MODE: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService].protocolMode); - break; - - case CY_BLE_UUID_CHAR_HIDS_INFORMATION: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService].information); - break; - - case CY_BLE_UUID_CHAR_HIDS_REPORT_MAP: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService].reportMap); - lastEndHandle[discIdx] = &cy_ble_hidsc[discIdx][discoveryService].reportMap.endHandle; - break; - - case CY_BLE_UUID_CHAR_HIDS_CONTROL_POINT: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService].controlPoint); - break; - - case CY_BLE_UUID_CHAR_HIDS_REPORT: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService]. - report[cy_ble_hidsc[discIdx][discoveryService].reportCount]); - lastEndHandle[discIdx] = &cy_ble_hidsc[discIdx][discoveryService]. - report[cy_ble_hidsc[discIdx][discoveryService].reportCount].endHandle; - - if(cy_ble_hidsc[discIdx][discoveryService].reportCount < CY_BLE_HIDSC_REPORT_COUNT) - { - cy_ble_hidsc[discIdx][discoveryService].reportCount++; - } - break; - - case CY_BLE_UUID_CHAR_HIDS_BOOT_KEYBOARD_IN_RPT: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService]. - bootReport[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX]); - lastEndHandle[discIdx] = &cy_ble_hidsc[discIdx][discoveryService]. - bootReport[CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX].endHandle; - break; - - case CY_BLE_UUID_CHAR_HIDS_BOOT_KEYBOARD_OUT_RPT: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService]. - bootReport[CY_BLE_HIDS_BOOT_KYBRD_OUT_REP_INDX]); - lastEndHandle[discIdx] = &cy_ble_hidsc[discIdx][discoveryService]. - bootReport[CY_BLE_HIDS_BOOT_KYBRD_OUT_REP_INDX].endHandle; - break; - - case CY_BLE_UUID_CHAR_HIDS_BOOT_MOUSE_IN_RPT: - Cy_BLE_CheckStoreCharHandle(cy_ble_hidsc[discIdx][discoveryService]. - bootReport[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX]); - lastEndHandle[discIdx] = &cy_ble_hidsc[discIdx][discoveryService]. - bootReport[CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX].endHandle; - break; - - default: - break; - } - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - /* Init service index of discovered characteristic */ - discoveryLastServ[discIdx] = discoveryService; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* This event is generated when the server successfully sends the data for -* CY_BLE_EVT_GATTC_FIND_INFO_REQ. Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* \param discoveryService: The index of the service instance. -* -******************************************************************************/ -static void Cy_BLE_HIDSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t hidsServIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_HIDS; - - if((cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_HIDS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_HIDS_END)) - { - switch((cy_en_ble_hids_char_index_t)cy_ble_discovery[discIdx].charCount) - { - case CY_BLE_HIDS_REPORT_MAP: - /* Descriptors for reportMap characteristics */ - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_EXTERNAL_REPORT_REF) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_hidsc[discIdx][hidsServIdx].reportMap.errdHandle); - } - break; - - case CY_BLE_HIDS_BOOT_KYBRD_IN_REP: - case CY_BLE_HIDS_BOOT_KYBRD_OUT_REP: - case CY_BLE_HIDS_BOOT_MOUSE_IN_REP: - { - /* Descriptors for report characteristics */ - uint32_t bootRepIdx = cy_ble_discovery[discIdx].charCount - CY_BLE_HIDS_BOOT_KYBRD_IN_REP; - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_hidsc[discIdx][hidsServIdx].bootReport[bootRepIdx]. - cccdHandle); - } - else if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_REPORT_REFERENCE) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_hidsc[discIdx][hidsServIdx].bootReport[bootRepIdx]. - rrdHandle); - } - else /* Report Characteristic doesn't support other descriptors */ - { - } - break; - } - - default: - { - if((cy_ble_discovery[discIdx].charCount >= (uint32_t)CY_BLE_HIDS_REPORT) && - (cy_ble_discovery[discIdx].charCount <= (uint32_t)CY_BLE_HIDS_REPORT_END)) - { - /* Descriptors for report characteristics */ - uint32_t reportIdx = cy_ble_discovery[discIdx].charCount - (uint32_t)CY_BLE_HIDS_REPORT; - - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_hidsc[discIdx][hidsServIdx].report[reportIdx]. - cccdHandle); - } - else if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_REPORT_REFERENCE) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_hidsc[discIdx][hidsServIdx].report[reportIdx]. - rrdHandle); - } - else /* Report Characteristic doesn't support other descriptors */ - { - } - } - break; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_HIDSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t hidsServIdx = cy_ble_discovery[discIdx].servCount - (uint32_t)CY_BLE_SRVI_HIDS; - uint32_t exitFlag = 0u; - - if((cy_ble_discovery[discIdx].servCount >= (uint32_t)CY_BLE_SRVI_HIDS) && - (cy_ble_discovery[discIdx].servCount <= (uint32_t)CY_BLE_SRVI_HIDS_END)) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_HIDS_CHAR_COUNT) && (exitFlag == 0u)) - { - switch((cy_en_ble_hids_char_index_t)cy_ble_discovery[discIdx].charCount) - { - case CY_BLE_HIDS_REPORT_MAP: - /* Read report map characteristic range */ - if((cy_ble_hidsc[discIdx][hidsServIdx].reportMap.endHandle - - cy_ble_hidsc[discIdx][hidsServIdx].reportMap.valueHandle) != 0u) - { - charRangeInfo->range.startHandle = cy_ble_hidsc[discIdx][hidsServIdx].reportMap.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_hidsc[discIdx][hidsServIdx].reportMap.endHandle; - exitFlag = 1u; - } - break; - - case CY_BLE_HIDS_BOOT_KYBRD_IN_REP: - case CY_BLE_HIDS_BOOT_KYBRD_OUT_REP: - case CY_BLE_HIDS_BOOT_MOUSE_IN_REP: - { - /* Read boot report characteristic range */ - uint32_t bootRepIdx = cy_ble_discovery[discIdx].charCount - CY_BLE_HIDS_BOOT_KYBRD_IN_REP; - - if((cy_ble_hidsc[discIdx][hidsServIdx].bootReport[bootRepIdx].endHandle - - cy_ble_hidsc[discIdx][hidsServIdx].bootReport[bootRepIdx].valueHandle) != 0u) - { - charRangeInfo->range.startHandle = cy_ble_hidsc[discIdx][hidsServIdx].bootReport[bootRepIdx]. - valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_hidsc[discIdx][hidsServIdx].bootReport[bootRepIdx]. - endHandle; - exitFlag = 1u; - } - break; - } - - default: - { - if((cy_ble_discovery[discIdx].charCount >= (uint32_t)CY_BLE_HIDS_REPORT) && - (cy_ble_discovery[discIdx].charCount <= (uint32_t)CY_BLE_HIDS_REPORT_END)) - { - /* Read report characteristic range */ - uint32_t reportIdx = cy_ble_discovery[discIdx].charCount - CY_BLE_HIDS_REPORT; - if((cy_ble_hidsc[discIdx][hidsServIdx].report[reportIdx].endHandle - - cy_ble_hidsc[discIdx][hidsServIdx].report[reportIdx].valueHandle) != 0u) - { - charRangeInfo->range.startHandle = cy_ble_hidsc[discIdx][hidsServIdx].report[reportIdx]. - valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_hidsc[discIdx][hidsServIdx].report[reportIdx]. - endHandle; - exitFlag = 1u; - } - } - break; - } - } - - if(exitFlag == 0u) - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_SetCharacteristicValue -***************************************************************************//** -* -* Sends a request to set characteristic value of the specified HID Service, -* which is identified by serviceIndex and reportIndex, on the server device. -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_HIDSC_WRITE_CHAR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param subProcedure: Characteristic value write sub-procedure. -* * CY_BLE_HIDSC_WRITE_WITHOUT_RESPONSE -* * CY_BLE_HIDSC_WRITE_CHAR_VALUE -* \param serviceIndex: The index of the service instance. e.g. If two HID Services -* are supported in your design, then first service will be -* identified by serviceIndex of 0 and the second by -* serviceIndex of 1. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HIDS service-specific callback is registered -* (with Cy_BLE_HIDS_RegisterAttrCallback): -* * CY_BLE_EVT_HIDSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hids_char_value_t. -* . -* Otherwise (if the HIDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hidsc_char_write_t subProcedure, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - cy_ble_gatt_db_attr_handle_t charValueHandle; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((serviceIndex >= CY_BLE_HIDSC_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - charValueHandle = Cy_BLE_HIDSC_GetCharacteristicValueHandle(connHandle, serviceIndex, charIndex); - - if(charValueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_cmd_req_t writeReqParam = - { - .handleValPair.attrHandle = charValueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Use WriteWithoutResponse subprocedure for the following characteristics: - * CY_BLE_HIDS_PROTOCOL_MODE - * CY_BLE_HIDS_CONTROL_POINT - */ - if(subProcedure == CY_BLE_HIDSC_WRITE_WITHOUT_RESPONSE) - { - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&writeReqParam); - } - else - { - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hidscReqHandle[discIdx] = charValueHandle; - } - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic value from a server -* which is identified by charIndex. -* -* The Read Response returns the characteristic value in the Attribute Value -* parameter. -* -* The Read Response only contains the characteristic value that is less than or -* equal to (MTU - 1) octets in length. If the characteristic value is greater -* than (MTU - 1) octets in length, the Read Long Characteristic Value procedure -* may be used if the rest of the characteristic Value is required. -* -* \param connHandle: The connection handle. -* \param subProcedure: The characteristic value read sub-procedure. -* * CY_BLE_HIDSC_READ_CHAR_VALUE -* * CY_BLE_HIDSC_READ_LONG_CHAR_VALUE. -* \param serviceIndex: The index of the service instance. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HIDS service-specific callback is registered -* (with Cy_BLE_HIDS_RegisterAttrCallback): -* * CY_BLE_EVT_HIDSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hids_char_value_t. -* . -* Otherwise (if the HIDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_READ_BLOB_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hidsc_char_read_t subProcedure, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - cy_ble_gatt_db_attr_handle_t charValueHandle; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((serviceIndex >= CY_BLE_HIDSC_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - charValueHandle = Cy_BLE_HIDSC_GetCharacteristicValueHandle(connHandle, serviceIndex, charIndex); - - if(charValueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Use Read Long Characteristic procedure for Report map characteristic */ - if(subProcedure == CY_BLE_HIDSC_READ_LONG_CHAR_VALUE) - { - cy_stc_ble_gattc_read_blob_req_t charReadLongParam = - { - .handleOffset.attrHandle = charValueHandle, - .handleOffset.offset = 0u, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadLongCharacteristicValues(&charReadLongParam); - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = charValueHandle, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - } - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hidscReqHandle[discIdx] = charValueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the server, -* which is identified by charIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_HIDSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_HIDSS_NOTIFICATION_DISABLED -* -* \param connHandle: The BLE peer device connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two HID Services -* are supported in your design, then first service will be -* identified by serviceIndex of 0 and the second by -* serviceIndex of 1. -* \param charIndex: The index of the HID service characteristic. -* \param descrIndex: The index of the HID service characteristic descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HIDS service-specific callback is registered -* (with Cy_BLE_HIDS_RegisterAttrCallback): -* * CY_BLE_EVT_HIDSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hids_descr_value_t. -* . -* Otherwise (if the HIDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - cy_ble_gatt_db_attr_handle_t locDescrHandle; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((serviceIndex >= CY_BLE_HIDSC_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT) || - (descrIndex >= CY_BLE_HIDS_DESCR_COUNT) || (charIndex < CY_BLE_HIDS_REPORT_MAP) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - locDescrHandle = Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle(connHandle, serviceIndex, charIndex, descrIndex); - - if(locDescrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = locDescrHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle, - }; - - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hidscReqHandle[discIdx] = locDescrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the specified characteristic of the HID -* Service from the server device. -* -* This function call can result in generation of the following events based on -* the response from the server device. -* * CY_BLE_EVT_HIDSC_READ_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param serviceIndex: The index of the service instance. e.g. If two HID Services -* are supported in your design, then first service will be -* identified by serviceIndex of 0 and the second by -* serviceIndex of 1. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the HID Service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HIDS service-specific callback is registered -* (with Cy_BLE_HIDS_RegisterAttrCallback): -* * CY_BLE_EVT_HIDSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_hids_descr_value_t. -* . -* Otherwise (if the HIDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HIDSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - cy_stc_ble_gattc_read_req_t readReqParam; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((serviceIndex >= CY_BLE_HIDSC_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT) || - (descrIndex >= CY_BLE_HIDS_DESCR_COUNT) || (charIndex < CY_BLE_HIDS_REPORT_MAP) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - readReqParam.attrHandle = Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle(connHandle, serviceIndex, charIndex, - descrIndex); - - if(readReqParam.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - readReqParam.connHandle = connHandle; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hidscReqHandle[discIdx] = readReqParam.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: pointer to the data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_HIDSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint8_t locServIndex; - cy_en_ble_hids_char_index_t locCharIndex; - - if(Cy_BLE_HIDS_ApplCallback != NULL) - { - for(locServIndex = 0u; locServIndex < CY_BLE_HIDSC_SERVICE_COUNT; locServIndex++) - { - for(locCharIndex = CY_BLE_HIDS_PROTOCOL_MODE; locCharIndex < CY_BLE_HIDS_CHAR_COUNT; locCharIndex++) - { - if(Cy_BLE_HIDSC_GetCharacteristicValueHandle(eventParam->connHandle, locServIndex, locCharIndex) == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_hids_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .serviceIndex = locServIndex, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_HIDS_ApplCallback((uint32_t)CY_BLE_EVT_HIDSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam: pointer to the data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_HIDSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint8_t locReqHandle = 0u; - uint8_t locServIndex; - cy_en_ble_hids_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HIDS_ApplCallback != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_hidscReqHandle[discIdx])) - { - for(locServIndex = 0u; (locServIndex < CY_BLE_HIDSC_SERVICE_COUNT) && (locReqHandle == 0u); locServIndex++) - { - for(locCharIndex = CY_BLE_HIDS_PROTOCOL_MODE; (locCharIndex < CY_BLE_HIDS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_hidscReqHandle[discIdx] == - Cy_BLE_HIDSC_GetCharacteristicValueHandle(eventParam->connHandle, locServIndex, locCharIndex)) - { - cy_stc_ble_hids_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .serviceIndex = locServIndex, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - - cy_ble_hidscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HIDS_ApplCallback((uint32_t)CY_BLE_EVT_HIDSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - if(locCharIndex >= CY_BLE_HIDS_REPORT_MAP) - { - cy_en_ble_hids_descr_t locDescIndex; - - for(locDescIndex = CY_BLE_HIDS_REPORT_CCCD; (locDescIndex < CY_BLE_HIDS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_hidscReqHandle[discIdx] == - Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle(eventParam->connHandle, locServIndex, - locCharIndex, locDescIndex)) - { - cy_stc_ble_hids_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .serviceIndex = locServIndex, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = &eventParam->value, - }; - - cy_ble_hidscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HIDS_ApplCallback((uint32_t)CY_BLE_EVT_HIDSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_WriteResponseEventHandler -***************************************************************************//** -* Handles the Write Response Event. -* -* \param eventParam: the pointer to the data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_HIDSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint8_t locServIndex; - uint8_t locReqHandle = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - cy_en_ble_hids_char_index_t locCharIndex; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HIDS_ApplCallback != NULL) && - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_hidscReqHandle[discIdx])) - { - for(locServIndex = 0u; (locServIndex < CY_BLE_HIDSC_SERVICE_COUNT) && (locReqHandle == 0u); locServIndex++) - { - for(locCharIndex = CY_BLE_HIDS_PROTOCOL_MODE; (locCharIndex < CY_BLE_HIDS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_hidscReqHandle[discIdx] == Cy_BLE_HIDSC_GetCharacteristicValueHandle(*eventParam, locServIndex, - locCharIndex)) - { - cy_stc_ble_hids_char_value_t locCharValue = - { - .connHandle = *eventParam, - .serviceIndex = locServIndex, - .charIndex = locCharIndex, - .value = NULL - }; - - cy_ble_hidscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HIDS_ApplCallback((uint32_t)CY_BLE_EVT_HIDSC_WRITE_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - if(locCharIndex >= CY_BLE_HIDS_REPORT_MAP) - { - cy_en_ble_hids_descr_t locDescIndex; - - for(locDescIndex = CY_BLE_HIDS_REPORT_CCCD; (locDescIndex < CY_BLE_HIDS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_hidscReqHandle[discIdx] == - Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle(*eventParam, locServIndex, locCharIndex, - locDescIndex)) - { - cy_stc_ble_hids_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .serviceIndex = locServIndex, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = NULL - }; - - cy_ble_hidscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HIDS_ApplCallback((uint32_t)CY_BLE_EVT_HIDSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_GetCharacteristicValueHandle -***************************************************************************//** -* -* Returns the discovered peer device characteristic value handle. -* -* \param serviceIndex: The index of the service instance. -* \param charIndex: The index of a service characteristic. -* -* \return -* Returns characteristic value handle of type cy_ble_gatt_db_attr_handle_t. -* * CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE: when a peer device doesn't have an optional characteristic -* -******************************************************************************/ -cy_ble_gatt_db_attr_handle_t Cy_BLE_HIDSC_GetCharacteristicValueHandle(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex) -{ - cy_ble_gatt_db_attr_handle_t returnHandle; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((serviceIndex >= CY_BLE_HIDSC_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT)) - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - else - { - if(charIndex == CY_BLE_HIDS_PROTOCOL_MODE) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].protocolMode.valueHandle; - } - else if(charIndex == CY_BLE_HIDS_INFORMATION) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].information.valueHandle; - } - else if(charIndex == CY_BLE_HIDS_CONTROL_POINT) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].controlPoint.valueHandle; - } - else if(charIndex == CY_BLE_HIDS_REPORT_MAP) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].reportMap.valueHandle; - } - else if(charIndex <= CY_BLE_HIDS_BOOT_MOUSE_IN_REP) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].bootReport[charIndex - CY_BLE_HIDS_BOOT_KYBRD_IN_REP]. - valueHandle; - } - else if(((uint8_t)charIndex - (uint8_t)CY_BLE_HIDS_REPORT) < cy_ble_hidsc[discIdx][(serviceIndex)].reportCount) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].report[charIndex - CY_BLE_HIDS_REPORT].valueHandle; - } - else - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - - return(returnHandle); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle -***************************************************************************//** -* -* Returns the discovered peer device characteristic descriptor handle. -* -* \param serviceIndex: the index of the service instance -* \param charIndex: the index of a service characteristic. -* \param descrIndex: the index of the descriptor. -* -* \return -* Returns characteristic value handle of type cy_ble_gatt_db_attr_handle_t. -* * CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE: when a peer device doesn't have an optional descriptor -* -******************************************************************************/ -cy_ble_gatt_db_attr_handle_t Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex) -{ - cy_ble_gatt_db_attr_handle_t returnHandle; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((serviceIndex >= CY_BLE_HIDSC_SERVICE_COUNT) || (charIndex >= CY_BLE_HIDS_CHAR_COUNT) || - (charIndex < CY_BLE_HIDS_REPORT_MAP)) - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - else - { - if(charIndex == CY_BLE_HIDS_REPORT_MAP) - { - if(descrIndex == CY_BLE_HIDS_REPORT_MAP_ERRD) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].reportMap.errdHandle; - } - else - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - else if(charIndex <= CY_BLE_HIDS_BOOT_MOUSE_IN_REP) - { - if(descrIndex == CY_BLE_HIDS_REPORT_CCCD) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].bootReport[charIndex - CY_BLE_HIDS_BOOT_KYBRD_IN_REP]. - cccdHandle; - } - else if(descrIndex == CY_BLE_HIDS_REPORT_RRD) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].bootReport[charIndex - CY_BLE_HIDS_BOOT_KYBRD_IN_REP]. - rrdHandle; - } - else - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - else if(((uint8_t)charIndex - (uint8_t)CY_BLE_HIDS_REPORT) < cy_ble_hidsc[discIdx][serviceIndex].reportCount) - { - if(descrIndex == CY_BLE_HIDS_REPORT_CCCD) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].report[charIndex - CY_BLE_HIDS_REPORT].cccdHandle; - } - else if(descrIndex == CY_BLE_HIDS_REPORT_RRD) - { - returnHandle = cy_ble_hidsc[discIdx][serviceIndex].report[charIndex - CY_BLE_HIDS_REPORT].rrdHandle; - } - else - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - else - { - returnHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - - return(returnHandle); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: the pointer to the data structure specified by the event. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_HIDSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_hidscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_hidscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -#endif /* CY_BLE_HIDS_CLIENT */ - - -/****************************************************************************** -* Function Name: Cy_BLE_HIDS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the HID service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HIDS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_HIDS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_HIDSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_INCL: - Cy_BLE_HIDSC_InclDiscoveryEventHandler((cy_stc_ble_disc_incl_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_HIDSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_HIDSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_HIDS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_HIDS_SERVER - case CY_BLE_EVT_GATT_CONNECT_IND: - Cy_BLE_HIDSS_OnDeviceConnected(); - break; - - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_HIDSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - (void)Cy_BLE_HIDSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_HIDS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_HIDS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_HIDSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_HIDSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_HIDSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_HIDSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_HIDS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} -#endif /* defined(CY_BLE_HIDS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hids.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hids.h deleted file mode 100644 index 7c277e093b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hids.h +++ /dev/null @@ -1,452 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hids.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for HID service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_HIDS_H -#define CY_BLE_HIDS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HIDS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - - - -/* Maximum supported count of HID services and reports */ -#define CY_BLE_HIDSS_SERVICE_COUNT (CY_BLE_CONFIG_HIDSS_SERVICE_COUNT) -#define CY_BLE_HIDSS_REPORT_COUNT (CY_BLE_CONFIG_HIDSS_REPORT_COUNT) - -#ifdef CY_BLE_HIDS_CLIENT - -/* Maximum supported count of HID services and reports */ -#define CY_BLE_HIDSC_SERVICE_COUNT (CY_BLE_CONFIG_HIDSC_SERVICE_COUNT) -#define CY_BLE_HIDSC_REPORT_COUNT (CY_BLE_CONFIG_HIDSC_REPORT_COUNT) -#define CY_BLE_HIDSC_HOST_ROLE (CY_BLE_CONFIG_HIDSC_HOST_ROLE) - -#endif /* CY_BLE_HIDS_CLIENT */ - -/* Maximum 3 boot reports exist */ -#define CY_BLE_HIDS_BOOT_REPORT_COUNT (0x03u) - -/* Define maximum report count over both roles */ -#ifdef CY_BLE_HIDS_SERVER - #ifdef CY_BLE_HIDS_CLIENT /* Both roles */ - #if (CY_BLE_HIDSC_REPORT_COUNT > CY_BLE_HIDSS_REPORT_COUNT) - #define CY_BLE_HIDS_REPORT_COUNT CY_BLE_HIDSC_REPORT_COUNT - #else - #define CY_BLE_HIDS_REPORT_COUNT CY_BLE_HIDSS_REPORT_COUNT - #endif /* CY_BLE_HIDSC_REPORT_COUNT > CY_BLE_HIDSS_REPORT_COUNT */ - #else /* Only server role */ - #define CY_BLE_HIDS_REPORT_COUNT CY_BLE_HIDSS_REPORT_COUNT - #endif /* CY_BLE_HIDS_CLIENT */ -#else /* Only client role*/ - #define CY_BLE_HIDS_REPORT_COUNT CY_BLE_HIDSC_REPORT_COUNT -#endif /* CY_BLE_HIDS_SERVER */ - -/** - * \addtogroup group_ble_service_api_HIDS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** HIDS characteristic indexes */ -typedef enum -{ - CY_BLE_HIDS_PROTOCOL_MODE = 0u, /**< Protocol Mode Characteristic index */ - CY_BLE_HIDS_INFORMATION = 1u, /**< HID Information Characteristic index */ - CY_BLE_HIDS_CONTROL_POINT = 2u, /**< HID Control Point Characteristic index */ - CY_BLE_HIDS_REPORT_MAP = 3u, /**< Report Map Characteristic index */ - CY_BLE_HIDS_BOOT_KYBRD_IN_REP = 4u, /**< Boot Keyboard Input Report Characteristic index */ - CY_BLE_HIDS_BOOT_KYBRD_OUT_REP = 5u, /**< Boot Keyboard Output Report Characteristic index */ - CY_BLE_HIDS_BOOT_MOUSE_IN_REP = 6u, /**< Boot Mouse Input Report Characteristic index */ - CY_BLE_HIDS_REPORT = 7u, /**< Report Characteristic index */ - CY_BLE_HIDS_REPORT_END = /**< Index of last Report Char */ - CY_BLE_HIDS_REPORT + CY_BLE_HIDS_REPORT_COUNT - 1u, - CY_BLE_HIDS_CHAR_COUNT = CY_BLE_HIDS_REPORT_END + 1u /**< Total count of characteristics */ - -}cy_en_ble_hids_char_index_t; - -/** HID Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_HIDS_REPORT_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_HIDS_REPORT_RRD, /**< Report Reference descriptor index */ - CY_BLE_HIDS_REPORT_MAP_ERRD, /**< Report Map External Report Reference descriptor index */ - CY_BLE_HIDS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_hids_descr_t; - -/** HID server Report Reference descriptor value - Report ID and Report Type */ -typedef struct -{ - /** Non-zero value if there are more than one instance of the same Report Type */ - uint8_t reportId; - - /** Type of Report characteristic */ - uint8_t reportType; -} cy_stc_ble_hidss_report_ref_t; - -/** HID Information characteristic value */ -typedef struct -{ - /** Version number of HIDSe USB HID Specification implemented by HID Device */ - uint16_t bcdHID; - - /** Identifies for which country hardware is localized for */ - uint8_t bCountryCode; - - /** Bit 0: RemoteWake - Indicates whether HID Device is capable of - * sending wake-signal to HID Host. - * Bit 1: NormallyConnectable - Indicates whether HID Device will be - * advertising when bonded but not connected. - */ - uint8_t flags; -} cy_stc_ble_hidss_information_t; - -/** HID Server Report characteristic */ -typedef struct -{ - /** Handle of Report characteristic value */ - cy_ble_gatt_db_attr_handle_t reportHandle; - - /** Handle of Client Characteristic Configuration descriptor */ - cy_ble_gatt_db_attr_handle_t cccdHandle; - - /** Handle of Report Reference descriptor */ - cy_ble_gatt_db_attr_handle_t rrdHandle; -} cy_stc_ble_hidss_report_t; - -/** Structure with HID Service attribute handles */ -typedef struct -{ - /** Handle of HID service */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Handle of Protocol Mode Characteristic */ - cy_ble_gatt_db_attr_handle_t protocolModeHandle; - - /** Number of report Characteristics */ - uint8_t reportCount; - - /** Info about report Characteristics */ - const cy_stc_ble_hidss_report_t *reportArray; - - /** Info about Boot Report Characteristics */ - cy_stc_ble_hidss_report_t bootReportArray[CY_BLE_HIDS_BOOT_REPORT_COUNT]; - - /** Handle of Report Map Characteristic */ - cy_ble_gatt_db_attr_handle_t reportMapHandle; - - /** Handle of Report Map External Report Reference descr. */ - cy_ble_gatt_db_attr_handle_t reportMapErrdHandle; - - /** Handle of HID Information Characteristic */ - cy_ble_gatt_db_attr_handle_t informationHandle; - - /** Handle of HID Control Point Characteristic */ - cy_ble_gatt_db_attr_handle_t controlPointHandle; -} cy_stc_ble_hidss_t; - - -#ifdef CY_BLE_HIDS_CLIENT - -/** HID Client Report characteristic */ -typedef struct -{ - /** Handle of Client Characteristic Configuration Descriptor */ - cy_ble_gatt_db_attr_handle_t cccdHandle; - - /** Handle of Report Reference Descriptor */ - cy_ble_gatt_db_attr_handle_t rrdHandle; - - /** Handle of Report Characteristic value */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** End handle of Characteristic */ - cy_ble_gatt_db_attr_handle_t endHandle; - - /** Properties for value field */ - uint8_t properties; -} cy_stc_ble_hidsc_report_t; - -/** HID client Report map characteristic */ -typedef struct -{ - /** Handle of Report Map External Report Reference descriptor */ - cy_ble_gatt_db_attr_handle_t errdHandle; - - /** Handle of Report characteristic value */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t endHandle; - - /** Properties for value field */ - uint8_t properties; -} cy_stc_ble_hidsc_report_map_t; - -/** Structure with discovered attributes information of HID Service */ -typedef struct -{ - /** Peer device handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Protocol Mode Characteristic handle and properties */ - cy_stc_ble_srvr_char_info_t protocolMode; - - /** Boot Report Characteristic info */ - cy_stc_ble_hidsc_report_t bootReport[CY_BLE_HIDS_BOOT_REPORT_COUNT]; - - /** Report Map Characteristic handle and descriptors */ - cy_stc_ble_hidsc_report_map_t reportMap; - - /** Information Characteristic handle and properties */ - cy_stc_ble_srvr_char_info_t information; - - /** Control Point Characteristic handle and properties */ - cy_stc_ble_srvr_char_info_t controlPoint; - - /** Report Characteristic info */ - cy_stc_ble_hidsc_report_t report[CY_BLE_HIDSC_REPORT_COUNT]; - - /** Number of report Characteristics */ - uint8_t reportCount; - - /** Included declaration handle */ - cy_ble_gatt_db_attr_handle_t includeHandle; -} cy_stc_ble_hidsc_t; - -/** Characteristic Value Write Sub-Procedure supported by HID Service */ -typedef enum -{ - CY_BLE_HIDSC_WRITE_WITHOUT_RESPONSE, /**< Write Without Response */ - CY_BLE_HIDSC_WRITE_CHAR_VALUE /**< Write Characteristic Value */ -}cy_en_ble_hidsc_char_write_t; - -/** Characteristic Value Read Sub-Procedure supported by HID Service */ -typedef enum -{ - CY_BLE_HIDSC_READ_CHAR_VALUE, /**< Read Characteristic Value */ - CY_BLE_HIDSC_READ_LONG_CHAR_VALUE /**< Read Long Characteristic Values */ -}cy_en_ble_hidsc_char_read_t; - -#endif /* (CY_BLE_HIDS_CLIENT) */ - -/** HID Service Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - uint8_t serviceIndex; /**< Index of HID Service */ - cy_en_ble_hids_char_index_t charIndex; /**< Index of HID Service Characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to Characteristic value */ -} cy_stc_ble_hids_char_value_t; - -/** HID Service Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - uint8_t serviceIndex; /**< Index of HID Service */ - cy_en_ble_hids_char_index_t charIndex; /**< Index of HID Service Characteristic */ - cy_en_ble_hids_descr_t descrIndex; /**< Service Characteristic Descriptor index */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Service Characteristic Descriptor value */ -} cy_stc_ble_hids_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** HID Service GATT DB handles structure */ - const cy_stc_ble_hidss_t *hidss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_hids_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -/* Boot Report indexes */ -#define CY_BLE_HIDS_BOOT_KYBRD_IN_REP_INDX (0x00u) -#define CY_BLE_HIDS_BOOT_KYBRD_OUT_REP_INDX (0x01u) -#define CY_BLE_HIDS_BOOT_MOUSE_IN_REP_INDX (0x02u) - -/* Report Type values */ -#define CY_BLE_HIDS_PROTOCOL_MODE_BOOT (0x00u) -#define CY_BLE_HIDS_PROTOCOL_MODE_REPORT (0x01u) -#define CY_BLE_HIDS_PROTOCOL_DEFAULT CY_BLE_HIDS_PROTOCOL_MODE_REPORT - -/* Report Type values */ -#define CY_BLE_HIDS_REPORT_TYPE_INPUT (0x01u) -#define CY_BLE_HIDS_REPORT_TYPE_OUTPUT (0x02u) -#define CY_BLE_HIDS_REPORT_TYPE_FEATURE (0x03u) - -/* Control-point attributes */ -#define CY_BLE_HIDS_CP_SUSPEND (0x00u) -#define CY_BLE_HIDS_CP_EXIT_SUSPEND (0x01u) - -/* Information characteristic value flags */ -#define CY_BLE_HIDS_INFO_FLAG_REMOTE_WAKE_MASK (0x01u) -#define CY_BLE_HIDS_INFO_FLAG_NORMALLY_CONNECTABLE_MASK (0x02u) - -#define CY_BLE_HIDS_PM_CHAR_LEN (0x01u) -#define CY_BLE_HIDS_CP_CHAR_LEN (0x01u) -#define CY_BLE_HIDS_RRD_LEN (0x02u) - -#define CY_BLE_HIDSC_HOST_ROLE_BOOT (0x00u) -#define CY_BLE_HIDSC_HOST_ROLE_REPORT (0x01u) -#define CY_BLE_HIDSC_HOST_ROLE_BOOT_AND_REPORT (0x02u) - - -/*************************************** -* Function Prototypes -***************************************/ -/** - * \addtogroup group_ble_service_api_HIDS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_HIDS_Init(cy_stc_ble_hids_config_t *config); -cy_en_ble_api_result_t Cy_BLE_HIDS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_HIDS_SERVER -/** - * \addtogroup group_ble_service_api_HIDS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_HIDSS_SetCharacteristicValue(uint8_t serviceIndex, cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HIDSS_GetCharacteristicValue(uint8_t serviceIndex, cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HIDSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HIDSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_HIDS_SERVER */ - -#ifdef CY_BLE_HIDS_CLIENT -/** - * \addtogroup group_ble_service_api_HIDS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_HIDSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hidsc_char_write_t subProcedure, - uint8_t serviceIndex, cy_en_ble_hids_char_index_t charIndex, - uint8_t attrSize, uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_HIDSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hidsc_char_read_t subProcedure, - uint8_t serviceIndex, cy_en_ble_hids_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_HIDSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HIDSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, uint8_t serviceIndex, - cy_en_ble_hids_char_index_t charIndex, - cy_en_ble_hids_descr_t descrIndex); - -/** @} */ -#endif /* CY_BLE_HIDS_CLIENT */ - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE */ - -#ifdef CY_BLE_HIDS_CLIENT -cy_ble_gatt_db_attr_handle_t Cy_BLE_HIDSC_GetCharacteristicValueHandle(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, cy_en_ble_hids_char_index_t - charIndex); - -cy_ble_gatt_db_attr_handle_t Cy_BLE_HIDSC_GetCharacteristicDescriptorHandle(cy_stc_ble_conn_handle_t connHandle, - uint8_t serviceIndex, cy_en_ble_hids_char_index_t - charIndex, cy_en_ble_hids_descr_t descrIndex); -#endif /* CY_BLE_HIDS_CLIENT */ -/** \endcond */ - - -/*************************************** -* Macro Functions -***************************************/ - - -#ifdef CY_BLE_HIDS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_HIDS_GetProtocolMode -***************************************************************************//** -* -* This function returns the current Protocol Mode of the service, as defined by -* the service index. -* -* \param serviceIndex: The sequence number of the HID Service -* -* \return -* uint8_t protocolMode: -* * CY_BLE_HIDS_PROTOCOL_MODE_BOOT 0 Boot protocol mode -* * CY_BLE_HIDS_PROTOCOL_MODE_REPORT 1 Report Protocol mode -* -******************************************************************************/ -#define Cy_BLE_HIDSS_GetProtocolMode(serviceIndex) \ - ((uint8_t)*CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_PTR(cy_ble_hidsConfigPtr->hidss[(serviceIndex)].protocolModeHandle)) - -#endif /* (CY_BLE_HIDS_SERVER) */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_HIDS_CLIENT -extern cy_stc_ble_hidsc_t cy_ble_hidsc[CY_BLE_CONFIG_GATTC_COUNT][CY_BLE_HIDSC_SERVICE_COUNT]; -extern uint8_t cy_ble_hidscServiceCount[CY_BLE_CONFIG_GATTC_COUNT]; -extern uint8_t cy_ble_hidscDisServiceIndex[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_HIDS_CLIENT */ - -extern cy_stc_ble_hids_config_t cy_ble_hidsConfig; -extern cy_stc_ble_hids_config_t *cy_ble_hidsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_HIDS) */ -#endif /* CY_BLE_HIDS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hps.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hps.c deleted file mode 100644 index 03411dd96b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hps.c +++ /dev/null @@ -1,1877 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hps.c -* \version 2.0 -* -* \brief -* Contains the source code for HTTP Proxy Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HPS)) - -#ifdef CY_BLE_HPS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_hpssReqHandle; -#endif /* CY_BLE_HPS_SERVER */ - -#ifdef CY_BLE_HPS_CLIENT -/* HPS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_hpsc_t cy_ble_hpsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_hpscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Variables for Read Long Characteristic Values handling */ -static uint8_t * cy_ble_hpscRdLongBuffPtr; -static uint16_t cy_ble_hpscRdLongBuffLen; -static uint16_t cy_ble_hpscCurrLen; -#endif /* CY_BLE_HPS_CLIENT */ - -static cy_ble_callback_t Cy_BLE_HPS_ApplCallback = NULL; - -/* The pointer on global BLE HPS Config structure */ -cy_stc_ble_hps_config_t *cy_ble_hpsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_HPS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_HPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_HPSS_PrepareWriteRequestEventHandler(const cy_stc_ble_gatts_prep_write_req_param_t *eventParam); -static void Cy_BLE_HPSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam); -#endif /* CY_BLE_HPS_SERVER */ - -#ifdef CY_BLE_HPS_CLIENT -static void Cy_BLE_HPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_HPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_HPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_HPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_HPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_HPSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_HPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_HPSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam); -static void Cy_BLE_HPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_HPS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_HPS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_HPS_Init -***************************************************************************//** -* -* This function initializes HTTP Proxy Service. -* -* \param config: Configuration structure for the HTTP Proxy Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPS_Init(cy_stc_ble_hps_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_hpsConfigPtr = config; - - /* Registers Event Handler for the HPS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_HPS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_hpsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_HPS_ApplCallback = cy_ble_hpsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_HPS_SERVER - cy_ble_hpssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_HPS_SERVER */ - - #ifdef CY_BLE_HPS_CLIENT - { - uint32_t idx; - cy_ble_hpscRdLongBuffPtr = NULL; - cy_ble_hpscRdLongBuffLen = 0u; - cy_ble_hpscCurrLen = 0u; - - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_HPS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_hpsc[idx], 0, sizeof(cy_stc_ble_hpsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_HPS].uuid = CY_BLE_UUID_HTTP_PROXY_SERVICE; - } - cy_ble_hpscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_HPS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) \n -* * eventCode - Indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_HPSS_NOTIFICATION_ENABLED). -* * eventParam - Contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_hps_char_value_t -* structure that contains details of the characteristic -* for which an indication enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_HPS_ApplCallback = callbackFunc; - if(cy_ble_hpsConfigPtr != NULL) - { - cy_ble_hpsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_HPS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_WriteEventHandler -***************************************************************************//** -* -* Handles Write Request Event for HTTP Proxy Service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write is successful. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The request is not supported. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - The write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - The offset value is invalid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t event = (uint32_t)CY_BLE_EVT_HPSS_NOTIFICATION_DISABLED; - cy_stc_ble_hps_char_value_t wrCharReqParam = - { - .connHandle = eventParam->connHandle - }; - - if(Cy_BLE_HPS_ApplCallback != NULL) - { - /* Client Characteristic Configuration descriptor write request */ - if(eventParam->handleValPair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE].descrHandle[CY_BLE_HPS_CCCD]) - { - wrCharReqParam.charIndex = CY_BLE_HPS_HTTP_STATUS_CODE; - wrCharReqParam.value = NULL; - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_HPSS_NOTIFICATION_ENABLED; - } - } - else - { - event = (uint32_t)CY_BLE_EVT_HPSS_WRITE_CHAR; - wrCharReqParam.value = &eventParam->handleValPair.value; - - if(cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_URI].charHandle == eventParam->handleValPair.attrHandle) - { - wrCharReqParam.charIndex = CY_BLE_HPS_URI; - } - else if(cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_HEADERS].charHandle == - eventParam->handleValPair.attrHandle) - { - wrCharReqParam.charIndex = CY_BLE_HPS_HTTP_HEADERS; - } - else if(cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_ENTITY_BODY].charHandle == - eventParam->handleValPair.attrHandle) - { - wrCharReqParam.charIndex = CY_BLE_HPS_HTTP_ENTITY_BODY; - } - else if(cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_CP].charHandle == - eventParam->handleValPair.attrHandle) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE]. - descrHandle[CY_BLE_HPS_CCCD])) - { - wrCharReqParam.charIndex = CY_BLE_HPS_HTTP_CP; - } - else - { - gattErr = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED; - - /* Clear callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - else - { - /* Set charIndex to CY_BLE_HPS_CHAR_COUNT as the requested handle doesn't - * match to any handles of HPS characteristics. - */ - wrCharReqParam.charIndex = CY_BLE_HPS_CHAR_COUNT; - } - } - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if(wrCharReqParam.charIndex < CY_BLE_HPS_CHAR_COUNT) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if((event == (uint32_t)CY_BLE_EVT_HPSS_WRITE_CHAR) && - (wrCharReqParam.value->len <= - (CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(eventParam->handleValPair.attrHandle)))) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(eventParam->handleValPair.attrHandle, - wrCharReqParam.value->len); - } - - /* Make sure that GATT error is set to "No error" */ - wrCharReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - Cy_BLE_HPS_ApplCallback(event, &wrCharReqParam); - gattErr = wrCharReqParam.gattErrorCode; - } - - if((event == (uint32_t)CY_BLE_EVT_HPSS_NOTIFICATION_ENABLED) || - (event == (uint32_t)CY_BLE_EVT_HPSS_NOTIFICATION_DISABLED)) - { - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - - /* Clear callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_PrepareWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Write Request HTTP Proxy Service. -* -* \param eventParam: The pointer to the data that received with a prepare write -* request event for the HTTP Proxy Service. -* -******************************************************************************/ -static void Cy_BLE_HPSS_PrepareWriteRequestEventHandler(const cy_stc_ble_gatts_prep_write_req_param_t *eventParam) -{ - if(Cy_BLE_HPS_ApplCallback != NULL) - { - if((eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_URI].charHandle) || - (eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_HEADERS].charHandle) || - (eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_ENTITY_BODY].charHandle)) - { - if(cy_ble_hpssReqHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send Prepare Write Response which identifies acknowledgment for - * long characteristic value write. - */ - - cy_ble_hpssReqHandle = - eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle; - } - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_ExecuteWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Execute Write Request Event for the HTTP Proxy Service. -* -* \param eventParam: The pointer to the data that came with a write request -* for the HTTP Proxy Service. -* -******************************************************************************/ -static void Cy_BLE_HPSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam) -{ - uint32_t locCount; - uint16_t locLength = 0u; - cy_stc_ble_gatt_value_t locCharValue; - cy_stc_ble_hps_char_value_t wrCharReqParam = { .connHandle = eventParam->connHandle }; - - if((Cy_BLE_HPS_ApplCallback != NULL) && (cy_ble_hpssReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if((eventParam->baseAddr[0u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_URI].charHandle) || - (eventParam->baseAddr[0u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_HEADERS].charHandle) || - (eventParam->baseAddr[0u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_ENTITY_BODY].charHandle)) - { - /* Check the execWriteFlag before execute or cancel write long operation */ - if(eventParam->execWriteFlag == CY_BLE_GATT_EXECUTE_WRITE_EXEC_FLAG) - { - /* Calculate total length */ - for(locCount = 0u; locCount < eventParam->prepWriteReqCount; locCount++) - { - locLength += eventParam->baseAddr[locCount].handleValuePair.value.len; - } - - if(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_hpssReqHandle) >= locLength) - { - /* Fill data and pass it to user */ - if(eventParam->baseAddr[0u].handleValuePair.attrHandle == cy_ble_hpsConfigPtr->hpss-> - charInfo[CY_BLE_HPS_URI].charHandle) - { - wrCharReqParam.charIndex = CY_BLE_HPS_URI; - } - else if(eventParam->baseAddr[0u].handleValuePair.attrHandle == - cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_HEADERS].charHandle) - { - wrCharReqParam.charIndex = CY_BLE_HPS_HTTP_HEADERS; - } - else - { - wrCharReqParam.charIndex = CY_BLE_HPS_HTTP_ENTITY_BODY; - } - - - wrCharReqParam.gattErrorCode = CY_BLE_GATT_ERR_NONE; - locCharValue = eventParam->baseAddr[0u].handleValuePair.value; - wrCharReqParam.value = &locCharValue; - wrCharReqParam.value->len = locLength; - - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSS_WRITE_CHAR, &wrCharReqParam); - - if(wrCharReqParam.gattErrorCode == CY_BLE_GATT_ERR_NONE) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_hpssReqHandle, locLength); - } - } - else - { - wrCharReqParam.gattErrorCode = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - - /* Pass user error code to Stack */ - eventParam->gattErrorCode = (uint8_t)wrCharReqParam.gattErrorCode; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - /* Clear requested handle */ - cy_ble_hpssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a value for one of characteristic values of the HTTP Proxy -* Service. The characteristic is identified by charIndex. -* -* \param charIndex: The index of a HTTP Proxy Service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was written successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSS_SetCharacteristicValue(cy_en_ble_hps_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex < CY_BLE_HPS_CHAR_COUNT)) - { - /* Fill structure */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_hpsConfigPtr->hpss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - if(attrSize <= CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(dbAttrValInfo.handleValuePair.attrHandle)) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(dbAttrValInfo.handleValuePair.attrHandle, attrSize); - } - - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_GetCharacteristicValue -***************************************************************************//** -* -* Reads a characteristic value of the HTTP Proxy Service, which is identified -* by charIndex from the GATT database. -* -* \param charIndex: The index of the HTTP Proxy Service characteristic. -* \param attrSize: The size of the HTTP Proxy Service characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSS_GetCharacteristicValue(cy_en_ble_hps_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex < CY_BLE_HPS_CHAR_COUNT)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_hpsConfigPtr->hpss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Get characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the characteristic descriptor value of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data to be stored in the GATT -* database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_HPS_HTTP_STATUS_CODE) && (descrIndex == CY_BLE_HPS_CCCD) && (attrValue != NULL)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE]. - descrHandle[CY_BLE_HPS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Sets characteristic value to database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Reads a a characteristic descriptor of a specified characteristic of the -* HTTP Proxy Service from the GATT database. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_HPS_HTTP_STATUS_CODE) && (descrIndex == CY_BLE_HPS_CCCD) && (attrValue != NULL)) - { - if(cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE].descrHandle[CY_BLE_HPS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE]. - descrHandle[CY_BLE_HPS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Get characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSS_SendNotification -***************************************************************************//** -* -* Sends a notification with a characteristic value of the HTTP Proxy -* Service, which is a value specified by charIndex, to the client's device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_HPSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - A notification is not enabled by the client. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex < CY_BLE_HPS_CHAR_COUNT) - { - if(cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE].descrHandle[CY_BLE_HPS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send notification if it is enabled and peer device is connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, - cy_ble_hpsConfigPtr->hpss-> - charInfo[CY_BLE_HPS_HTTP_STATUS_CODE].descrHandle[CY_BLE_HPS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_hpsConfigPtr->hpss->charInfo[CY_BLE_HPS_HTTP_STATUS_CODE]. - charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - -#endif /* CY_BLE_HPS_SERVER */ - - -#ifdef CY_BLE_HPS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_HPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* HPS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_hpscCharUuid[CY_BLE_HPS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_URI, - CY_BLE_UUID_CHAR_HTTP_HEADERS, - CY_BLE_UUID_CHAR_HTTP_ENTITY_BODY, - CY_BLE_UUID_CHAR_HTTP_CP, - CY_BLE_UUID_CHAR_HTTP_STATUS_CODE, - CY_BLE_UUID_CHAR_HTTPS_SECURITY - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HPS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - /* Search through all available characteristics */ - for(i = (uint32_t)CY_BLE_HPS_URI; (i < (uint32_t)CY_BLE_HPS_CHAR_COUNT); i++) - { - if(cy_ble_hpscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_hpsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_hpsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_hpsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_hpsc[discIdx].charInfo[i].endHandle; - break; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. Characteristic endHandle - * will be updated to the declaration handler of the following characteristic, - * in the following characteristic discovery procedure. - */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_HPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HPS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_HPS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if(cy_ble_hpsc[discIdx].charInfo[charIdx].descrHandle[descIdx] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_hpsc[discIdx].charInfo[charIdx].descrHandle[descIdx] = discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_HPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HPS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_HPS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_hpsc[discIdx].charInfo[charIdx].endHandle - cy_ble_hpsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_hpsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_hpsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_NotificationEventHandler -***************************************************************************//** -* -* Handles a notification event for the HTTP Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - if(Cy_BLE_HPS_ApplCallback != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - (cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_STATUS_CODE].valueHandle == - eventParam->handleValPair.attrHandle)) - { - cy_stc_ble_hps_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_HPS_HTTP_STATUS_CODE, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event for the HTTP Proxy Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_en_ble_hps_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HPS_ApplCallback != NULL) && - (cy_ble_hpscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_HPS_URI; (locCharIndex < CY_BLE_HPS_CHAR_COUNT); locCharIndex++) - { - if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[locCharIndex].valueHandle) - { - break; - } - } - - if(locCharIndex < CY_BLE_HPS_CHAR_COUNT) - { - cy_stc_ble_hps_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - - cy_ble_hpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_READ_CHAR_RESPONSE, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_STATUS_CODE]. - descrHandle[CY_BLE_HPS_CCCD]) - { - cy_stc_ble_hps_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_HPS_HTTP_STATUS_CODE, - .descrIndex = CY_BLE_HPS_CCCD, - .value = &eventParam->value - }; - - cy_ble_hpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_READ_DESCR_RESPONSE, &locDescrValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Do nothing */ - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_ReadLongRespEventHandler -***************************************************************************//** -* -* Handles a Read Long Response event for the HTTP Proxy Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HPSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_stc_ble_gattc_stop_cmd_param_t stopCmdParam = { .connHandle = eventParam->connHandle }; - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = eventParam->connHandle }; - cy_en_ble_hps_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t isReqEnded = 1u; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HPS_ApplCallback != NULL)) - { - /* Check if requested handle equals to any of HPS characteristic handles */ - if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_URI].valueHandle) - { - locCharIndex = CY_BLE_HPS_URI; - } - else if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_HEADERS].valueHandle) - { - locCharIndex = CY_BLE_HPS_HTTP_HEADERS; - } - else if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_ENTITY_BODY].valueHandle) - { - locCharIndex = CY_BLE_HPS_HTTP_ENTITY_BODY; - } - else - { - locCharIndex = CY_BLE_HPS_CHAR_COUNT; - } - - /* If match was found then proceed with the request handling */ - if((locCharIndex < CY_BLE_HPS_CHAR_COUNT) && (cy_ble_hpscReqHandle[discIdx] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Update user buffer with received data */ - if(cy_ble_hpscCurrLen < cy_ble_hpscRdLongBuffLen) - { - (void)memcpy((void*)&cy_ble_hpscRdLongBuffPtr[cy_ble_hpscCurrLen], (void*)&eventParam->value.val[0], - (uint32_t)eventParam->value.len); - - cy_ble_hpscCurrLen += eventParam->value.len; - } - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* If the received data length is less than the MTU size, the Read Long - * request is completed or the provided user's buffer is full. - */ - if(((mtuParam.mtu - 1u) > eventParam->value.len)) - { - cy_ble_hpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - else if(cy_ble_hpscCurrLen == cy_ble_hpscRdLongBuffLen) - { - (void)Cy_BLE_GATTC_StopCmd(&stopCmdParam); - } - else - { - isReqEnded = 0u; - } - - /* If the buffer is full, then stop processing any remaining read long - * requests. - */ - if(isReqEnded == 1u) - { - cy_stc_ble_hps_char_value_t rdCharValue = { .connHandle = eventParam->connHandle }; - - cy_stc_ble_gatt_value_t rdValue = - { - .val = cy_ble_hpscRdLongBuffPtr, - .len = cy_ble_hpscCurrLen - }; - rdCharValue.charIndex = locCharIndex; - rdCharValue.value = &rdValue; - - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_READ_CHAR_RESPONSE, &rdCharValue); - cy_ble_hpscCurrLen = 0u; - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event for the HTTP Proxy Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_en_ble_hps_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HPS_ApplCallback != NULL) && - (cy_ble_hpscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_HPS_URI; (locCharIndex < CY_BLE_HPS_CHAR_COUNT); locCharIndex++) - { - if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[locCharIndex].valueHandle) - { - break; - } - } - - if(locCharIndex < CY_BLE_HPS_CHAR_COUNT) - { - cy_stc_ble_hps_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .value = NULL - }; - - cy_ble_hpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_WRITE_CHAR_RESPONSE, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_hpscReqHandle[discIdx] == - cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_STATUS_CODE].descrHandle[CY_BLE_HPS_CCCD]) - { - cy_stc_ble_hps_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_HPS_HTTP_STATUS_CODE, - .descrIndex = CY_BLE_HPS_CCCD, - .value = NULL - }; - - cy_ble_hpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_WRITE_DESCR_RESPONSE, &locDescrValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* The requested handle doesn't belong to HPS */ - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_ExecuteWriteResponseEventHandler -***************************************************************************//** -* -* Handles a Execute Write Response event for the HTTP Proxy Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HPSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - cy_en_ble_hps_char_index_t locCharIndex; - - /* Check if service handler was registered and request handle is valid. */ - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HPS_ApplCallback != NULL)) - { - /* Check if requested handle equals to any of HPS characteristic handles */ - if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_URI].valueHandle) - { - locCharIndex = CY_BLE_HPS_URI; - } - else if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_HEADERS].valueHandle) - { - locCharIndex = CY_BLE_HPS_HTTP_HEADERS; - } - else if(cy_ble_hpscReqHandle[discIdx] == cy_ble_hpsc[discIdx].charInfo[CY_BLE_HPS_HTTP_ENTITY_BODY].valueHandle) - { - locCharIndex = CY_BLE_HPS_HTTP_ENTITY_BODY; - } - else - { - locCharIndex = CY_BLE_HPS_CHAR_COUNT; - } - - if(locCharIndex < CY_BLE_HPS_CHAR_COUNT) - { - cy_stc_ble_hps_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = NULL - }; - - cy_ble_hpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HPS_ApplCallback((uint32_t)CY_BLE_EVT_HPSC_WRITE_CHAR_RESPONSE, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event for the HTTP Proxy Service. -* -* \param eventParam - The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_hpscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_hpscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_HPSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HPS service-specific callback is registered -* (with Cy_BLE_HPS_RegisterAttrCallback): -* * CY_BLE_EVT_HPSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hps_char_value_t. -* -* Otherwise (if the HPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there was some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hpscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HPS service-specific callback is registered -* (with Cy_BLE_HPS_RegisterAttrCallback): \n -* * CY_BLE_EVT_HPSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_hps_char_value_t. -* . -* Otherwise (if the HPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hpscReqHandle[discIdx] = cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_SetLongCharacteristicValue -***************************************************************************//** -* -* Sends a request to set a long characteristic value of the service, which is -* a value identified by charIndex, to the server's device. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HPS service-specific callback is registered -* (with Cy_BLE_HPS_RegisterAttrCallback): -* * CY_BLE_EVT_HPSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hps_char_value_t. -* -* Otherwise (if the HPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_EXEC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSC_SetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_prep_write_req_t writeReqParam = - { - .handleValOffsetPair.handleValuePair.attrHandle = cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle, - .handleValOffsetPair.handleValuePair.value.val = attrValue, - .handleValOffsetPair.handleValuePair.value.len = attrSize, - .handleValOffsetPair.offset = 0u, - .connHandle = connHandle - }; - - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteLongCharacteristicValues(&writeReqParam); - - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hpscReqHandle[discIdx] = writeReqParam.handleValOffsetPair.handleValuePair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_GetLongCharacteristicValue -***************************************************************************//** -* -* This function is used to read a long characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param attrSize: The size of the buffer to store long characteristic value. -* \param attrValue: The pointer to the buffer where the read long characteristic -* value should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HPS service-specific callback is registered -* (with Cy_BLE_HPS_RegisterAttrCallback): -* * CY_BLE_EVT_HPSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_hps_char_value_t. -* -* Otherwise (if the HPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_BLOB_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSC_GetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_blob_req_t readLongData = - { - .handleOffset.attrHandle = cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle, - .handleOffset.offset = 0u, - .connHandle = connHandle - }; - - cy_ble_hpscRdLongBuffLen = attrSize; - cy_ble_hpscRdLongBuffPtr = attrValue; - - apiResult = Cy_BLE_GATTC_ReadLongCharacteristicValues(&readLongData); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hpscReqHandle[discIdx] = cy_ble_hpsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the server, -* which is identified by charIndex and descrIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HPS service-specific callback is registered -* (with Cy_BLE_HPS_RegisterAttrCallback): -* * CY_BLE_EVT_HPSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hps_char_value_t. -* Otherwise (if the HPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HPS_CHAR_COUNT) || (descrIndex >= CY_BLE_HPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_hpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hpscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HPSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HPS service-specific callback is registered -* (with Cy_BLE_HPS_RegisterAttrCallback): -* * CY_BLE_EVT_HPSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully read on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_hps_descr_value_t. -* . -* Otherwise (if the HPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HPS_CHAR_COUNT) || (descrIndex >= CY_BLE_HPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_hpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hpscReqHandle[discIdx] = cy_ble_hpsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - -#endif /* CY_BLE_HPS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_HPS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the HTTP Proxy Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HPS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_HPS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_HPSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_HPSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_HPSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_HPS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_HPS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_HPSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - Cy_BLE_HPSS_PrepareWriteRequestEventHandler((cy_stc_ble_gatts_prep_write_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - Cy_BLE_HPSS_ExecuteWriteRequestEventHandler((cy_stc_ble_gatts_exec_write_req_t*)eventParam); - break; - #endif /* CY_BLE_HPS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_HPS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_HPSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_HPSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_HPSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_BLOB_RSP: - Cy_BLE_HPSC_ReadLongRespEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_EXEC_WRITE_RSP: - Cy_BLE_HPSC_ExecuteWriteResponseEventHandler((cy_stc_ble_gattc_exec_write_rsp_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_HPSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_HPS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_HPS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hps.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hps.h deleted file mode 100644 index 42ba746ac5..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hps.h +++ /dev/null @@ -1,247 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hps.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for HTTP Proxy Service. -* -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_HPS_H -#define CY_BLE_HPS_H - -#include "cy_ble_event_handler.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HPS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -/** - * \addtogroup group_ble_service_api_HPS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** HPS Characteristic indexes */ -typedef enum -{ - CY_BLE_HPS_URI, /**< Universal Resource Identifier Characteristics index */ - CY_BLE_HPS_HTTP_HEADERS, /**< HTTP Headers Characteristics index */ - CY_BLE_HPS_HTTP_ENTITY_BODY, /**< HTTP Entity Body Characteristics index */ - CY_BLE_HPS_HTTP_CP, /**< HTTP Control Point Characteristics index */ - CY_BLE_HPS_HTTP_STATUS_CODE, /**< HTTP Status Code Characteristics index */ - CY_BLE_HPS_HTTPS_SECURITY, /**< HTTPS Security Characteristics index */ - CY_BLE_HPS_CHAR_COUNT /**< Total count of HPS Characteristics */ -}cy_en_ble_hps_char_index_t; - -/** HPS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_HPS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_HPS_DESCR_COUNT /**< Total count of Descriptors */ -} cy_en_ble_hps_descr_index_t; - -/** HPS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_hps_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< Error code received from application (optional) */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_hps_char_value_t; - -/** HPS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_hps_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_hps_descr_index_t descrIndex; /**< Index of descriptor */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< Error code received from application (optional) */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_hps_descr_value_t; - -/** Structure with HTTP Proxy Service attribute handles */ -typedef struct -{ - /** Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t charHandle; - /** Array of descriptor handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_HPS_DESCR_COUNT]; -} cy_stc_ble_hpss_char_t; - -/** HPS Characteristic with descriptors handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< HTTP Proxy Service handle */ - cy_stc_ble_hpss_char_t charInfo[CY_BLE_HPS_CHAR_COUNT]; /**< Array of characteristics and descriptors handles */ -} cy_stc_ble_hpss_t; - -/** HPS Service full characteristic information structure */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - uint8_t properties; /**< Properties for value field */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_HPS_DESCR_COUNT]; /**< Array of descriptor handles */ -} cy_stc_ble_hpsc_char_t; - -/** Structure with discovered attributes information of HTTP Proxy Service */ -typedef struct -{ - /** HTTP Proxy Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - /** HTTP Proxy Service characteristics info structure */ - cy_stc_ble_hpsc_char_t charInfo[CY_BLE_HPS_CHAR_COUNT]; -} cy_stc_ble_hpsc_t; - -/** HTTP Requests */ -typedef enum -{ - CY_BLE_HPS_HTTP_GET = 0x01u, /**< HTTP GET Request */ - CY_BLE_HPS_HTTP_HEAD, /**< HTTP HEAD Request */ - CY_BLE_HPS_HTTP_POST, /**< HTTP POST Request */ - CY_BLE_HPS_HTTP_PUT, /**< HTTP PUT Request */ - CY_BLE_HPS_HTTP_DELETE, /**< HTTP DELETE Request */ - CY_BLE_HPS_HTTPS_GET, /**< HTTS GET Request */ - CY_BLE_HPS_HTTPS_HEAD, /**< HTTPS HEAD Request */ - CY_BLE_HPS_HTTPS_POST, /**< HTTPS POST Request */ - CY_BLE_HPS_HTTPS_PUT, /**< HTTPS PUT Request */ - CY_BLE_HPS_HTTPS_DELETE, /**< HTTPS DELETE Request */ - CY_BLE_HPS_HTTP_REQ_CANCEL /**< HTTP CANCEL Request */ -}cy_en_ble_hps_http_request_t; - -/** Service configuration structure */ -typedef struct -{ - /** HTTP Proxy Service GATT DB handles structure */ - const cy_stc_ble_hpss_t *hpss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_hps_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ -/* HTTP Status Code Data Status bits */ -#define CY_BLE_HPS_HTTP_HEADERS_RECEIVED (0x01u) -#define CY_BLE_HPS_HTTP_HEADERS_TRUNCATED (0x02u) -#define CY_BLE_HPS_HTTP_BODY_RECEIVED (0x04u) -#define CY_BLE_HPS_HTTP_BODY_TRUNCATED (0x08u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_HPS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_HPS_Init(cy_stc_ble_hps_config_t *config); -cy_en_ble_api_result_t Cy_BLE_HPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -/** - * \addtogroup group_ble_service_api_HPS_server - * @{ - */ - -#ifdef CY_BLE_HPS_SERVER - -cy_en_ble_api_result_t Cy_BLE_HPSS_SetCharacteristicValue(cy_en_ble_hps_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSS_GetCharacteristicValue(cy_en_ble_hps_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, cy_en_ble_hps_char_index_t - charIndex, uint8_t attrSize, uint8_t *attrValue); - -#endif /* CY_BLE_HPS_SERVER */ - -/** @} */ - -/** - * \addtogroup group_ble_service_api_HPS_client - * @{ - */ - -#ifdef CY_BLE_HPS_CLIENT - -cy_en_ble_api_result_t Cy_BLE_HPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_HPSC_SetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSC_GetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hps_char_index_t charIndex, - cy_en_ble_hps_descr_index_t descrIndex); - -#endif /* CY_BLE_HPS_CLIENT */ - -/** @} */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_HPS_CLIENT -extern cy_stc_ble_hpsc_t cy_ble_hpsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_HPS_CLIENT */ - -extern cy_stc_ble_hps_config_t cy_ble_hpsConfig; -extern cy_stc_ble_hps_config_t *cy_ble_hpsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_HPS) */ -#endif /* CY_BLE_HPS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hrs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hrs.c deleted file mode 100644 index 4ea9a24b52..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hrs.c +++ /dev/null @@ -1,1270 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hrs.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Heart Rate Service of -* the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HRS)) - -static cy_ble_callback_t Cy_BLE_HRS_ApplCallback; - -#ifdef CY_BLE_HRS_CLIENT -/* Server's Heart Rate Service characteristics GATT DB handles structure */ -cy_stc_ble_hrsc_t cy_ble_hrsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check the response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_hrscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_HRS_CLIENT */ - -/* The pointer on global BLE HRS Config structure */ -cy_stc_ble_hrs_config_t *cy_ble_hrsConfigPtr = NULL; - - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_HRS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_HRSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_HRS_SERVER */ - -#ifdef CY_BLE_HRS_CLIENT -static void Cy_BLE_HRSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_HRSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_HRSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_HRSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_HRSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_HRSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_HRSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_HRS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_HRS_EventHandler(uint32_t eventCode, void *eventParam); - -/****************************************************************************** -* Function Name: Cy_BLE_HRS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for the Heart Rate Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRS_Init(cy_stc_ble_hrs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure*/ - cy_ble_hrsConfigPtr = config; - - /* Registers Event Handler for the HRS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_HRS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_hrsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_HRS_ApplCallback = cy_ble_hrsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_HRS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_HRS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_hrsc[idx], 0, sizeof(cy_stc_ble_hrsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_HRS].uuid = CY_BLE_UUID_HEART_RATE_SERVICE; - } - cy_ble_hrscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for HRS Service is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_HRSS_NOTIFICATION_ENABLED). -* * eventParam contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_hrs_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_HRS_ApplCallback = callbackFunc; - if(cy_ble_hrsConfigPtr != NULL) - { - cy_ble_hrsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_HRS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets local characteristic value of the specified Heart Rate Service -* characteristic. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSS_SetCharacteristicValue(cy_en_ble_hrs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_HRS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if((charIndex == CY_BLE_HRS_BSL) && (!CY_BLE_HRS_IS_BSL_SUPPORTED)) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .handleValuePair.attrHandle = cy_ble_hrsConfigPtr->hrss->charHandle[charIndex], - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the local characteristic value of specified Heart Rate Service -* characteristic. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSS_GetCharacteristicValue(cy_en_ble_hrs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_HRS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if((charIndex == CY_BLE_HRS_BSL) && (!CY_BLE_HRS_IS_BSL_SUPPORTED)) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_hrsConfigPtr->hrss->charHandle[charIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_READ | CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the local characteristic descriptor of the specified Heart Rate -* Service characteristic. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. The Heart Rate -* Measurement characteristic client configuration descriptor has -* 2 bytes length. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - cy_en_ble_hrs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - if((charIndex >= CY_BLE_HRS_CHAR_COUNT) || (descrIndex >= CY_BLE_HRS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if((charIndex != CY_BLE_HRS_HRM) || (descrIndex != CY_BLE_HRS_HRM_CCCD)) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_hrsConfigPtr->hrss->hrmCccdHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_READ | CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSS_SendNotification -***************************************************************************//** -* -* Sends notification of a specified Heart Rate Service characteristic value -* to the Client device. No response is expected. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_HRSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_HRS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if((cy_ble_hrsConfigPtr->hrss->hrmCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - || (!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_hrsConfigPtr->hrss->hrmCccdHandle))) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_hrsConfigPtr->hrss->charHandle[charIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Heart Rate Measurement Client Configuration Characteristic -* Descriptor Write Event or Control Point Characteristic Write Event. -* -* \param void *eventParam: The pointer to the data structure specified by the event. -* -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HRSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - uint32_t eventCode = 0u; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_hrs_char_value_t locCharIndex; - - locCharIndex.connHandle = eventParam->connHandle; - locCharIndex.value = NULL; - - if(eventParam->handleValPair.attrHandle == cy_ble_hrsConfigPtr->hrss->hrmCccdHandle) - { - locCharIndex.charIndex = CY_BLE_HRS_HRM; - /* Heart Rate Measurement characteristic descriptor write request */ - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_HRSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_HRSS_NOTIFICATION_DISABLED; - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(eventParam->handleValPair.attrHandle == cy_ble_hrsConfigPtr->hrss->charHandle[CY_BLE_HRS_CPT]) - { - locCharIndex.charIndex = CY_BLE_HRS_CPT; - /* Heart Rate Control Point characteristic write request */ - if(CY_BLE_HRS_RESET_ENERGY_EXPENDED == eventParam->handleValPair.value.val[0u]) - { - eventCode = (uint32_t)CY_BLE_EVT_HRSS_ENERGY_EXPENDED_RESET; - } - else - { - gattErr = CY_BLE_GATT_ERR_HEART_RATE_CONTROL_POINT_NOT_SUPPORTED; - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Heart Rate Service doesn't support any other write requests */ - } - - if(0u != eventCode) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if(Cy_BLE_HRS_ApplCallback != NULL) - { - Cy_BLE_HRS_ApplCallback(eventCode, &locCharIndex); - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTS_WRITE_REQ, eventParam); - } - } - } - - return(gattErr); -} - -#endif /* CY_BLE_HRS_SERVER */ - -#ifdef CY_BLE_HRS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic value attribute -* (identified by charIndex) to the server. The Write Response just confirms -* the operation success. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_HRSC_WRITE_CHAR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HRS service-specific callback is registered -* (with Cy_BLE_HRS_RegisterAttrCallback): -* * CY_BLE_EVT_HRSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hrs_char_value_t. -* . -* Otherwise (if the HRS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HRS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT) || - ((charIndex == CY_BLE_HRS_CPT) && (attrSize > CY_BLE_HRS_CPT_CHAR_LEN))) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hrsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_hrsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_hrsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hrscReqHandle[discIdx] = cy_ble_hrsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server -* which is identified by charIndex. -* -* The Read Response returns the characteristic Value in the Attribute Value -* parameter. -* -* The Read Response only contains the characteristic Value that is less than or -* equal to (MTU - 1) octets in length. If the characteristic Value is greater -* than (MTU - 1) octets in length, the Read Long Characteristic Value procedure -* may be used if the rest of the characteristic Value is required. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HRS service-specific callback is registered -* (with Cy_BLE_HRS_RegisterAttrCallback): -* * CY_BLE_EVT_HRSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hrs_char_value_t. -* . -* Otherwise (if the HRS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HRS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_hrsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_hrsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_hrsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hrscReqHandle[discIdx] = cy_ble_hrsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic Value to the server, which -* is identified by charIndex. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_HRSC_WRITE_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* One of the following events is received by the peer device, on invoking -* this function: -* * CY_BLE_EVT_HRSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_HRSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_HRSS_ENERGY_EXPENDED_RESET -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HRS service-specific callback is registered -* (with Cy_BLE_HRS_RegisterAttrCallback): -* * CY_BLE_EVT_HRSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hrs_descr_value_t. -* . -* Otherwise (if the HRS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - cy_en_ble_hrs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HRS_CHAR_COUNT) || (descrIndex >= CY_BLE_HRS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charIndex != CY_BLE_HRS_HRM) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if(cy_ble_hrsc[discIdx].hrmCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_hrsc[discIdx].hrmCccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hrscReqHandle[discIdx] = cy_ble_hrsc[discIdx].hrmCccdHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the service. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_HRSC_READ_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HRS service-specific callback is registered -* (with Cy_BLE_HRS_RegisterAttrCallback): -* * CY_BLE_EVT_HRSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_hrs_descr_value_t. -* . -* Otherwise (if the HRS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HRSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - cy_en_ble_hrs_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HRS_CHAR_COUNT) || (descrIndex >= CY_BLE_HRS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charIndex != CY_BLE_HRS_HRM) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if(cy_ble_hrsc[discIdx].hrmCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_hrsc[discIdx].hrmCccdHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_hrscReqHandle[discIdx] = cy_ble_hrsc[discIdx].hrmCccdHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -* -******************************************************************************/ -static void Cy_BLE_HRSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* Heart Rate Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_hrscCharUuid[CY_BLE_HRS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_HR_MSRMT, - CY_BLE_UUID_CHAR_BODY_SENSOR_LOC, - CY_BLE_UUID_CHAR_HR_CNTRL_POINT - }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HRS)) - { - for(i = 0u; i < (uint32_t)CY_BLE_HRS_CHAR_COUNT; i++) - { - if(cy_ble_hrscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_hrsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_hrsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_hrsc[discIdx].charInfo[i].properties = discCharInfo->properties; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_HRSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HRS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - if(cy_ble_hrsc[discIdx].hrmCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_hrsc[discIdx].hrmCccdHandle = discDescrInfo->descrHandle; - } - else /* Duplication of descriptor */ - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_HRSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HRS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if(cy_ble_discovery[discIdx].charCount == 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_hrsc[discIdx].charInfo[CY_BLE_HRS_HRM].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_HRS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_HRSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - (cy_ble_hrsc[discIdx].charInfo[CY_BLE_HRS_HRM].valueHandle == eventParam->handleValPair.attrHandle)) - { - if(Cy_BLE_HRS_ApplCallback != NULL) - { - cy_stc_ble_hrs_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_HRS_HRM, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_HRS_ApplCallback((uint32_t)CY_BLE_EVT_HRSC_NOTIFICATION, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param cy_stc_ble_gattc_read_rsp_param_t *eventParam: The pointer to the data structure. -* -* -******************************************************************************/ -static void Cy_BLE_HRSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HRS_ApplCallback != NULL) && - (cy_ble_hrscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_hrsc[discIdx].charInfo[CY_BLE_HRS_BSL].valueHandle == cy_ble_hrscReqHandle[discIdx]) - { - cy_stc_ble_hrs_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_HRS_BSL, - .value = &eventParam->value - }; - cy_ble_hrscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_HRS_ApplCallback((uint32_t)CY_BLE_EVT_HRSC_READ_CHAR_RESPONSE, &locCharValue); - } - else if(cy_ble_hrsc[discIdx].hrmCccdHandle == cy_ble_hrscReqHandle[discIdx]) - { - cy_stc_ble_hrs_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_HRS_HRM, - .descrIndex = CY_BLE_HRS_HRM_CCCD, - .value = &eventParam->value - }; - cy_ble_hrscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_HRS_ApplCallback((uint32_t)CY_BLE_EVT_HRSC_READ_DESCR_RESPONSE, &locDescrValue); - } - else - { - /* No any more read response handles */ - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_HRSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HRS_ApplCallback != NULL) && - (cy_ble_hrscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_hrsc[discIdx].charInfo[CY_BLE_HRS_CPT].valueHandle == cy_ble_hrscReqHandle[discIdx]) - { - cy_stc_ble_hrs_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_HRS_CPT, - .value = NULL - }; - cy_ble_hrscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_HRS_ApplCallback((uint32_t)CY_BLE_EVT_HRSC_WRITE_CHAR_RESPONSE, &locCharIndex); - } - if(cy_ble_hrsc[discIdx].hrmCccdHandle == cy_ble_hrscReqHandle[discIdx]) - { - cy_stc_ble_hrs_descr_value_t locDescIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_HRS_HRM, - .descrIndex = CY_BLE_HRS_HRM_CCCD, - .value = NULL - }; - cy_ble_hrscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_HRS_ApplCallback((uint32_t)CY_BLE_EVT_HRSC_WRITE_DESCR_RESPONSE, &locDescIndex); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HRSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: Pointer to the data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_HRSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_hrscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_hrscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* CY_BLE_HRS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_HRS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Heart Rate Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HRS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_HRS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_HRSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_HRSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_HRSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_HRS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_HRS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_HRSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_HRS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_HRS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_HRSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_HRSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_HRSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_HRSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_HRS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} -#endif /* defined(CY_BLE_HRS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hrs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hrs.h deleted file mode 100644 index 400ce5b323..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hrs.h +++ /dev/null @@ -1,209 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hrs.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Heart Rate Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_HRS_H -#define CY_BLE_HRS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HRS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* Definitions for Body Sensor Location characteristic */ -#define CY_BLE_HRS_BSL_CHAR_LEN (1u) - -/* Definitions for ControlPoint characteristic */ -#define CY_BLE_HRS_CPT_CHAR_LEN (1u) -#define CY_BLE_HRS_RESET_ENERGY_EXPENDED (0x01u) - - -/** - * \addtogroup group_ble_service_api_HRS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** HRS Characteristics indexes */ -typedef enum -{ - CY_BLE_HRS_HRM, /**< Heart Rate Measurement characteristic index */ - CY_BLE_HRS_BSL, /**< Body Sensor Location characteristic index */ - CY_BLE_HRS_CPT, /**< Control Point characteristic index */ - CY_BLE_HRS_CHAR_COUNT /**< Total count of HRS characteristics */ -}cy_en_ble_hrs_char_index_t; - -/** HRS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_HRS_HRM_CCCD, /**< Heart Rate Measurement client char. config. descriptor index */ - CY_BLE_HRS_DESCR_COUNT /**< Total count of HRS HRM descriptors */ -}cy_en_ble_hrs_descr_index_t; - -/** Structure with Heart Rate Service attribute handles */ -typedef struct -{ - /** Heart Rate Service handle*/ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Heart Rate Service characteristics handles and properties array */ - cy_ble_gatt_db_attr_handle_t charHandle[CY_BLE_HRS_CHAR_COUNT]; - - /** Heart Rate Measurement client char. config. descriptor Handle */ - cy_ble_gatt_db_attr_handle_t hrmCccdHandle; -} cy_stc_ble_hrss_t; - -/** Structure with discovered attributes information of Heart Rate Service */ -typedef struct -{ - /** Heart Rate Service characteristics handles and properties array */ - cy_stc_ble_srvr_char_info_t charInfo[CY_BLE_HRS_CHAR_COUNT]; - - /** Heart Rate Measurement client char. config. descriptor Handle */ - cy_ble_gatt_db_attr_handle_t hrmCccdHandle; -}cy_stc_ble_hrsc_t; - -/** HRS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_hrs_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_hrs_char_value_t; - -/** HRS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_hrs_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_hrs_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_hrs_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Heart Rate Service GATT DB handles structure */ - const cy_stc_ble_hrss_t *hrss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_hrs_config_t; -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_HRS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_HRS_Init(cy_stc_ble_hrs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_HRS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_HRS_SERVER -/** - * \addtogroup group_ble_service_api_HRS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_HRSS_SetCharacteristicValue(cy_en_ble_hrs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HRSS_GetCharacteristicValue(cy_en_ble_hrs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HRSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - cy_en_ble_hrs_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HRSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_HRS_SERVER */ - -#ifdef CY_BLE_HRS_CLIENT -/** - * \addtogroup group_ble_service_api_HRS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_HRSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HRSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_HRSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - cy_en_ble_hrs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HRSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hrs_char_index_t charIndex, - cy_en_ble_hrs_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_HRS_CLIENT */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE - * Internal macros - */ -#ifdef CY_BLE_HRS_SERVER -#define CY_BLE_HRS_IS_BSL_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_hrsConfigPtr->hrss->charHandle[CY_BLE_HRS_BSL]) -#endif /* CY_BLE_HRS_SERVER */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_HRS_CLIENT -/* Heart Rate Service server's GATT DB handles structure */ -extern cy_stc_ble_hrsc_t cy_ble_hrsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_HRS_CLIENT */ - -extern cy_stc_ble_hrs_config_t cy_ble_hrsConfig; -extern cy_stc_ble_hrs_config_t *cy_ble_hrsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_HRS) */ -#endif /* CY_BLE_HRS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hts.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hts.c deleted file mode 100644 index b131bf6b6e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hts.c +++ /dev/null @@ -1,1551 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hts.c -* \version 2.0 -* -* \brief -* Contains the source code for Health Thermometer Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HTS)) - -static cy_ble_callback_t Cy_BLE_HTS_ApplCallback = NULL; - -#ifdef CY_BLE_HTS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_htssReqHandle; -#endif /* CY_BLE_HTS_SERVER */ - -#ifdef CY_BLE_HTS_CLIENT -/* HTS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_htsc_t cy_ble_htsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_htscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_HTS_CLIENT) */ - -/* The pointer on global BLE HTS Config structure */ -cy_stc_ble_hts_config_t *cy_ble_htsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_HTS_SERVER -static void Cy_BLE_HTSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_HTSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_HTS_SERVER */ - -#ifdef CY_BLE_HTS_CLIENT -static void Cy_BLE_HTSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_HTSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_HTSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_HTSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_HTSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_HTSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_HTSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_HTSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_HTS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_HTS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_HTS_Init -***************************************************************************//** -* -* This function initializes HTS Service. -* -* \param config: Configuration structure for HTS Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTS_Init(cy_stc_ble_hts_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_htsConfigPtr = config; - - /* Registers Event Handler for the HTS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_HTS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_htsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_HTS_ApplCallback = cy_ble_htsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_HTS_SERVER - cy_ble_htssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_HTS_SERVER */ - - #ifdef CY_BLE_HTS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_HTS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_htsc[idx], 0, sizeof(cy_stc_ble_htsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_HTS].uuid = CY_BLE_UUID_HEALTH_THERMOMETER_SERVICE; - } - cy_ble_htscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_HTS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for HTS Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_HTSS_NOTIFICATION_ENABLED). -* * eventParam contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_hts_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_HTS_ApplCallback = callbackFunc; - if(cy_ble_htsConfigPtr != NULL) - { - cy_ble_htsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_HTS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the characteristic value of the service in the local database. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size (in Bytes) of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSS_SetCharacteristicValue(cy_en_ble_hts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_HTS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_htsConfigPtr->htss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the characteristic value of the service, which is a value identified by -* charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSS_GetCharacteristicValue(cy_en_ble_hts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex >= CY_BLE_HTS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_htsConfigPtr->htss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data that should -* be stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_HTS_CHAR_COUNT) || (descrIndex >= CY_BLE_HTS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(cy_ble_htsConfigPtr->htss->charInfo[charIndex].descrHandle[descrIndex] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_htsConfigPtr->htss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_HTS_CHAR_COUNT) || (descrIndex >= CY_BLE_HTS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(cy_ble_htsConfigPtr->htss->charInfo[charIndex].descrHandle[descrIndex] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_htsConfigPtr->htss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_WriteEventHandler -***************************************************************************//** -* -* Handles Write Request Event for HTS service. -* -* \param void *eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HTSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_hts_char_index_t locCharIndex; - cy_stc_ble_hts_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint8_t locReqHandle = 0u; - - - if(Cy_BLE_HTS_ApplCallback != NULL) - { - for(locCharIndex = CY_BLE_HTS_TEMP_MEASURE; (locCharIndex < CY_BLE_HTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if((eventParam->handleValPair.attrHandle == - cy_ble_htsConfigPtr->htss->charInfo[locCharIndex].descrHandle[CY_BLE_HTS_CCCD]) || - (eventParam->handleValPair.attrHandle == - cy_ble_htsConfigPtr->htss->charInfo[locCharIndex].charHandle)) - { - locCharValue.charIndex = locCharIndex; - locCharValue.value = &eventParam->handleValPair.value; - /* Characteristic value write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_htsConfigPtr->htss->charInfo[locCharIndex].charHandle) - { - /* Validate Measure Interval value */ - if(locCharIndex == CY_BLE_HTS_MEASURE_INTERVAL) - { - uint8_t locAttrValue[CY_BLE_HTS_VRD_LEN]; - uint16_t requestValue; - - requestValue = Cy_BLE_Get16ByPtr(eventParam->handleValPair.value.val); - - if(requestValue != 0u) /* 0 is valid interval value for no periodic measurement */ - { - /* Check Valid range for Measure Interval characteristic value */ - if(Cy_BLE_HTSS_GetCharacteristicDescriptor(eventParam->connHandle, locCharIndex, - CY_BLE_HTS_VRD, CY_BLE_HTS_VRD_LEN, locAttrValue) == - CY_BLE_SUCCESS) - { - uint16_t lowerValue; - uint16_t upperValue; - - lowerValue = Cy_BLE_Get16ByPtr(locAttrValue); - upperValue = Cy_BLE_Get16ByPtr(locAttrValue + sizeof(lowerValue)); - requestValue = Cy_BLE_Get16ByPtr(eventParam->handleValPair.value.val); - if((requestValue != 0u) && ((requestValue < lowerValue) || (requestValue > upperValue))) - { - gattErr = CY_BLE_GATT_ERR_HTS_OUT_OF_RANGE; - } - } - } - } - if(gattErr == CY_BLE_GATT_ERR_NONE) - { /* Store value to database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED, - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSS_WRITE_CHAR, &locCharValue); - } - } - } - else /* Client Characteristic Configuration descriptor write request */ - { - /* Store value to database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - /* Check characteristic properties for Notification */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_htsConfigPtr->htss->charInfo[locCharIndex].charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSS_NOTIFICATION_ENABLED, &locCharValue); - } - else - { - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSS_NOTIFICATION_DISABLED, &locCharValue); - } - } - /* Check characteristic properties for Indication */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_htsConfigPtr->htss->charInfo[locCharIndex].charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSS_INDICATION_ENABLED, &locCharValue); - } - else - { - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSS_INDICATION_DISABLED, &locCharValue); - } - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - locReqHandle = 1u; - } - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_SendNotification -***************************************************************************//** -* -* Sends notification with a characteristic value of the Health Thermometer -* Service, which is a value specified by charIndex, to the Client device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_HTSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_htsConfigPtr->htss->charInfo[charIndex]. - descrHandle[CY_BLE_HTS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_htsConfigPtr->htss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_SendIndication -***************************************************************************//** -* -* Sends indication with a characteristic value of the Health Thermometer -* Service, which is a value specified by charIndex, to the Client device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_HTSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HTS service-specific callback is registered -* (with Cy_BLE_HTS_RegisterAttrCallback): -* * CY_BLE_EVT_HTSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the HTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_htsConfigPtr->htss->charInfo[charIndex]. - descrHandle[CY_BLE_HTS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_htsConfigPtr->htss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&ntfReqParam); - /* Save handle to support service-specific value confirmation response from client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_htssReqHandle = ntfReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* *eventParam - The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_HTSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_stc_ble_hts_char_value_t locCharValue = { .connHandle = *eventParam }; - cy_en_ble_hts_char_index_t locCharIndex; - uint32_t locReqHandle = 0u; - - if((Cy_BLE_HTS_ApplCallback != NULL) && (cy_ble_htssReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_HTS_TEMP_MEASURE; (locCharIndex < CY_BLE_HTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_htssReqHandle == cy_ble_htsConfigPtr->htss->charInfo[locCharIndex].charHandle) - { - locCharValue.charIndex = locCharIndex; - locCharValue.value = NULL; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_htssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSS_INDICATION_CONFIRMED, &locCharValue); - locReqHandle = 1u; - } - } - } -} - - -#endif /* CY_BLE_HTS_SERVER */ - -#ifdef CY_BLE_HTS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_HTSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* HTS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_htscCharUuid[CY_BLE_HTS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_TEMPERATURE_MSMNT, - CY_BLE_UUID_CHAR_TEMPERATURE_TYPE, - CY_BLE_UUID_CHAR_INTERMEDIATE_TEMP, - CY_BLE_UUID_CHAR_MSMNT_INTERVAL - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HTS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = (uint32_t)CY_BLE_HTS_TEMP_MEASURE; i < (uint32_t)CY_BLE_HTS_CHAR_COUNT; i++) - { - if(cy_ble_htscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_htsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - Cy_BLE_CheckStoreCharHandle(cy_ble_htsc[discIdx].charInfo[i]); - lastEndHandle[discIdx] = &cy_ble_htsc[discIdx].charInfo[i].endHandle; - break; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to the Service endHandle. Characteristic endHandle will be updated to declaration - * handler of the following characteristic, in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discoveryCharIndex: The characteristic index which is discovered. -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_HTSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HTS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_HTS_CCCD; - break; - - case CY_BLE_UUID_CHAR_VALID_RANGE: - descIdx = (uint32_t)CY_BLE_HTS_VRD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_htsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_htsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_HTSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_HTS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_HTS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_htsc[discIdx].charInfo[charIdx].endHandle - cy_ble_htsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_htsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_htsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_HTSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HTS service-specific callback is registered -* (with Cy_BLE_HTS_RegisterAttrCallback): -* * CY_BLE_EVT_HTSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hts_char_value_t. -* . -* Otherwise (if the HTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HTS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_htsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_htsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_htscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HTS service-specific callback is registered -* (with Cy_BLE_HTS_RegisterAttrCallback): -* * CY_BLE_EVT_HTSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hts_char_value_t. -* . -* Otherwise (if the HTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HTS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_htsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_htsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_htscReqHandle[discIdx] = cy_ble_htsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the server, -* which is identified by charIndex and descrIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_HTSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_HTSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_HTSS_INDICATION_ENABLED -* * CY_BLE_EVT_HTSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HTS service-specific callback is registered -* (with Cy_BLE_HTS_RegisterAttrCallback): -* * CY_BLE_EVT_HTSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_hts_descr_value_t. -* . -* Otherwise (if the HTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HTS_CHAR_COUNT) || (descrIndex >= CY_BLE_HTS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(descrIndex != CY_BLE_HTS_CCCD) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_htsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_HTS_CCCD], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_htscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic of the -* service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the HTS service-specific callback is registered -* (with Cy_BLE_HTS_RegisterAttrCallback): -* * CY_BLE_EVT_HTSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_hts_descr_value_t. -* . -* Otherwise (if the HTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HTSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_HTS_CHAR_COUNT) || (descrIndex >= CY_BLE_HTS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_htsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_htscReqHandle[discIdx] = cy_ble_htsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_NotificationEventHandler -***************************************************************************//** -* -* Handles Notification Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HTSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - cy_en_ble_hts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HTS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_HTS_TEMP_MEASURE; locCharIndex < CY_BLE_HTS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_htsc[discIdx].charInfo[locCharIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_hts_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_IndicationEventHandler -***************************************************************************//** -* -* Handles Indication Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HTSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - cy_en_ble_hts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HTS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_HTS_TEMP_MEASURE; locCharIndex < CY_BLE_HTS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_htsc[discIdx].charInfo[locCharIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_hts_char_value_t indicationValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles Read Response Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HTSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_en_ble_hts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t locReqHandle = 0u; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HTS_ApplCallback != NULL) && - (cy_ble_htscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_HTS_TEMP_MEASURE; (locCharIndex < CY_BLE_HTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_htscReqHandle[discIdx] == cy_ble_htsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_hts_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - cy_ble_htscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_hts_descr_index_t locDescIndex; - - for(locDescIndex = CY_BLE_HTS_CCCD; (locDescIndex < CY_BLE_HTS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_htscReqHandle[discIdx] == cy_ble_htsc[discIdx].charInfo[locCharIndex]. - descrHandle[locDescIndex]) - { - cy_stc_ble_hts_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = &eventParam->value - }; - - cy_ble_htscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_HTSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_en_ble_hts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - uint32_t locReqHandle = 0u; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_HTS_ApplCallback != NULL) && - (cy_ble_htscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_HTS_TEMP_MEASURE; (locCharIndex < CY_BLE_HTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_htscReqHandle[discIdx] == cy_ble_htsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_hts_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .value = NULL - }; - cy_ble_htscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSC_WRITE_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else if(cy_ble_htscReqHandle[discIdx] == cy_ble_htsc[discIdx].charInfo[locCharIndex]. - descrHandle[CY_BLE_HTS_CCCD]) - { - cy_stc_ble_hts_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .descrIndex = CY_BLE_HTS_CCCD, - .value = NULL - }; - cy_ble_htscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_HTS_ApplCallback((uint32_t)CY_BLE_EVT_HTSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - else /* No other destination for write operation is possible */ - { - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_HTSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles Error Response Event. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_HTSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_htscReqHandle[discIdx]) - { - cy_ble_htscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* (CY_BLE_HTS_CLIENT) */ - -/****************************************************************************** -* Function Name: Cy_BLE_HTS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Health Thermometer Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_HTS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_HTS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_HTSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_HTSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_HTSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_HTS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_HTS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_HTSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_HTSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_HTS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_HTS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_HTSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_HTSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_HTSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_HTSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_HTSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_HTS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_HTS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ - diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hts.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hts.h deleted file mode 100644 index 018e239933..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_hts.h +++ /dev/null @@ -1,276 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_hts.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Health Thermometer Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_HTS_H -#define CY_BLE_HTS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_HTS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_HTS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** HTS Characteristic indexes */ -typedef enum -{ - CY_BLE_HTS_TEMP_MEASURE, /**< Temperature Measurement characteristic index */ - CY_BLE_HTS_TEMP_TYPE, /**< Temperature Type characteristic index */ - CY_BLE_HTS_INTERM_TEMP, /**< Intermediate Temperature characteristic index*/ - CY_BLE_HTS_MEASURE_INTERVAL, /**< Measurement Interval characteristic index */ - CY_BLE_HTS_CHAR_COUNT /**< Total count of HTS characteristics */ -}cy_en_ble_hts_char_index_t; - -/** HTS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_HTS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_HTS_VRD, /**< Valid Range descriptor index */ - CY_BLE_HTS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_hts_descr_index_t; - -/** HTS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_HTS_DESCR_COUNT]; /**< Handle of descriptor */ -} cy_stc_ble_htss_char_t; - -/** Structure with Health Thermometer Service attribute handles */ -typedef struct -{ - /** Health Thermometer Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Health Thermometer Service Characteristic handles */ - cy_stc_ble_htss_char_t charInfo[CY_BLE_HTS_CHAR_COUNT]; -} cy_stc_ble_htss_t; - -/** HTS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_HTS_DESCR_COUNT]; /**< Handle of descriptor */ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of Report characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_htsc_char_t; - -/** Structure with discovered attributes information of Health Thermometer Service */ -typedef struct -{ - /** Characteristics handles array */ - cy_stc_ble_htsc_char_t charInfo[CY_BLE_HTS_CHAR_COUNT]; -} cy_stc_ble_htsc_t; - -/** HTS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_hts_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_hts_char_value_t; - -/** HTS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_hts_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_hts_descr_index_t descrIndex; /**< Index of descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_hts_descr_value_t; - - -/** The IEEE-11073 FLOAT-Type is defined as a 32-bit value - * with a 24-bit mantissa and an 8-bit exponent. */ -typedef struct -{ - int8_t exponent; /**< Base 10 exponent */ - int32_t mantissa; /**< Mantissa, should be using only 24 bits */ -} CY_BLE_HTS_FLOAT32; - -/** Temperature Type measurement indicates where the temperature was measured */ -typedef enum -{ - CY_BLE_HTS_TEMP_TYPE_ARMPIT = 0x01u, /**< Armpit */ - CY_BLE_HTS_TEMP_TYPE_BODY, /**< Body (general) */ - CY_BLE_HTS_TEMP_TYPE_EAR, /**< Ear (usually ear lobe) */ - CY_BLE_HTS_TEMP_TYPE_FINGER, /**< Finger */ - CY_BLE_HTS_TEMP_TYPE_GI_TRACT, /**< Gastro-intestinal Tract */ - CY_BLE_HTS_TEMP_TYPE_MOUTH, /**< Mouth */ - CY_BLE_HTS_TEMP_TYPE_RECTUM, /**< Rectum */ - CY_BLE_HTS_TEMP_TYPE_TOE, /**< Toe */ - CY_BLE_HTS_TEMP_TYPE_TYMPANUM /**< Tympanum (ear drum) */ -}cy_stc_ble_hts_temp_type_t; - -/** Service configuration structure */ -typedef struct -{ - /** Health Thermometer Service GATT DB handles structure */ - const cy_stc_ble_htss_t *htss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_hts_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -/* Valid Range descriptor length */ -#define CY_BLE_HTS_VRD_LEN (0x04u) - -/* Health Thermometer measurement flag bits */ -#define CY_BLE_HTS_MEAS_FLAG_TEMP_UNITS_BIT (0x01u << 0u) -#define CY_BLE_HTS_MEAS_FLAG_TIME_STAMP_BIT (0x01u << 1u) -#define CY_BLE_HTS_MEAS_FLAG_TEMP_TYPE_BIT (0x01u << 2u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_HTS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_HTS_Init(cy_stc_ble_hts_config_t *config); -cy_en_ble_api_result_t Cy_BLE_HTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_HTS_SERVER -/** - * \addtogroup group_ble_service_api_HTS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_HTSS_SetCharacteristicValue(cy_en_ble_hts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSS_GetCharacteristicValue(cy_en_ble_hts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_HTS_SERVER */ - -#ifdef CY_BLE_HTS_CLIENT -/** - * \addtogroup group_ble_service_api_HTS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_HTSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_HTSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_HTSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_hts_char_index_t charIndex, - cy_en_ble_hts_descr_index_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_HTS_CLIENT) */ - - -/*************************************** -* Macro Functions -***************************************/ - -#ifdef CY_BLE_HTS_CLIENT - -#define Cy_BLE_HTSC_CheckCharHandle(handle) \ - do { \ - if((handle).valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \ - { \ - (handle).valueHandle = discCharInfo->valueHandle; \ - (handle).properties = discCharInfo->properties; \ - } \ - else \ - { \ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \ - &(discCharInfo->uuid.uuid16)); \ - } \ - } while(0) - -#define Cy_BLE_HTSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_HTS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_htsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_HTSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_HTS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_HTS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_htsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].descrHandle[descrIndex]) - -#endif /* (CY_BLE_HTS_CLIENT) */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_HTS_CLIENT -extern cy_stc_ble_htsc_t cy_ble_htsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_HTS_CLIENT) */ - -extern cy_stc_ble_hts_config_t cy_ble_htsConfig; -extern cy_stc_ble_hts_config_t *cy_ble_htsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_HTS) */ -#endif /* CY_BLE_HTS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ias.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ias.c deleted file mode 100644 index d4f3374219..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ias.c +++ /dev/null @@ -1,498 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ias.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Immediate Alert Service of the BLE -* Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_IAS)) - -#ifdef CY_BLE_IAS_SERVER -static cy_ble_callback_t Cy_BLE_IAS_ApplCallback = NULL; -#endif /* (CY_BLE_IAS_SERVER) */ - -#ifdef CY_BLE_IAS_CLIENT -/* IAS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_iasc_t cy_ble_iasc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_IAS_CLIENT) */ - -/* The pointer on global BLE IAS Config structure */ -cy_stc_ble_ias_config_t *cy_ble_iasConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_IAS_SERVER -static void Cy_BLE_IASS_DisconnectEventHandler(void); -static void Cy_BLE_IASS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* (CY_BLE_IAS_SERVER) */ - -#ifdef CY_BLE_IAS_CLIENT -static void Cy_BLE_IASC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_IASC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -#endif /* (CY_BLE_IAS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_IAS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_IAS_Init -***************************************************************************//** -* -* This function initializes the Immediate Alert Service. -* -* \param config: Configuration structure for the Immediate Alert Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IAS_Init(cy_stc_ble_ias_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_iasConfigPtr = config; - - /* Registers Event Handler for the IAS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_IAS_EventHandler); - - #ifdef CY_BLE_IAS_SERVER - /* Registers a callback function via config structure */ - if(cy_ble_iasConfigPtr->callbackFunc != NULL) - { - Cy_BLE_IAS_ApplCallback = cy_ble_iasConfigPtr->callbackFunc; - } - #endif /* CY_BLE_IAS_SERVER */ - - #ifdef CY_BLE_IAS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_IAS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_iasc[idx], 0, sizeof(cy_stc_ble_iasc_t)); - cy_ble_serverInfo[idx][CY_BLE_SRVI_IAS].uuid = CY_BLE_UUID_IMMEDIATE_ALERT_SERVICE; - } - } - } - #endif /* (CY_BLE_IAS_CLIENT) */ - } - - return(apiResult); -} - - -#ifdef CY_BLE_IAS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_IAS_RegisterAttrCallback -***************************************************************************//** -* -* Registers callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for IAS Service is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_IASS_NOTIFICATION_ENABLED). -* * eventParam contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_ias_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise -* this data may become corrupted.\n -* Note: -* IAS only has events for the GATT server. There are no events for the GATT -* client since the client sends data without waiting for response. Therefore -* there is no need to register a callback through Cy_BLE_IAS_RegisterAttrCallback -* for an IAS GATT client. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IAS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_IAS_ApplCallback = callbackFunc; - if(cy_ble_iasConfigPtr != NULL) - { - cy_ble_iasConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IASS_DisconnectEventHandler -***************************************************************************//** -* -* Handles the Disconnection Indication Event for the Immediate Alert service. -* -******************************************************************************/ -static void Cy_BLE_IASS_DisconnectEventHandler(void) -{ - uint8_t tmpAlertLevel = CY_BLE_NO_ALERT; - - /* Set alert level to "No Alert" per IAS spec */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_iasConfigPtr->iass->alertLevelCharHandle, - .handleValuePair.value.len = CY_BLE_IAS_ALERT_LEVEL_SIZE, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - dbAttrValInfo.handleValuePair.value.val = &tmpAlertLevel; - - (void)Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IASS_WriteCmdEventHandler -***************************************************************************//** -* -* Handles the Write Without Response Request Event for the Immediate Alert -* Service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t * eventParam: The pointer to a data structure -* specified by the event. -* -******************************************************************************/ -static void Cy_BLE_IASS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - if(Cy_BLE_IAS_ApplCallback != NULL) - { - /* Check if attribute handle is handle of Alert Level characteristic of - * Immediate Alert service. */ - if((cy_ble_iasConfigPtr->iass->alertLevelCharHandle == eventParam->handleValPair.attrHandle) && - (eventParam->handleValPair.value.len == CY_BLE_IAS_ALERT_LEVEL_SIZE) && - (eventParam->handleValPair.value.val[0u] <= CY_BLE_HIGH_ALERT)) - { - /* Input parameters validation passed, so save Alert Level */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_ias_char_value_t wrCmdParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_IAS_ALERT_LEVEL, - .value = &eventParam->handleValPair.value - }; - /* Send callback to user if no error occurred while writing Alert Level */ - Cy_BLE_IAS_ApplCallback((uint32_t)CY_BLE_EVT_IASS_WRITE_CHAR_CMD, (void*)&wrCmdParam); - cy_ble_eventHandlerFlag &= (uint8_t)(~CY_BLE_CALLBACK); - } - } - /* As this handler handles Write Without Response request the error response - * can't be sent for the Client. The erroneous value will be with - * CY_BLE_EVT_GATTS_WRITE_CMD_REQ event. User will decide how to handle it. */ - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IASS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the Alert Level characteristic value of the service, which is identified -* by charIndex. -* -* \param charIndex: The index of the Alert Level characteristic. -* \param attrSize: The size of the Alert Level characteristic value attribute. -* \param attrValue: The pointer to the location where the Alert Level characteristic -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IASS_GetCharacteristicValue(cy_en_ble_ias_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex == CY_BLE_IAS_ALERT_LEVEL) && (attrSize == CY_BLE_IAS_ALERT_LEVEL_SIZE)) - { - /* Get Alert Level characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_iasConfigPtr->iass->alertLevelCharHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_IAS_SERVER) */ - - -#ifdef CY_BLE_IAS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_IASC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event. -* Based on the service UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_IASC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_IAS)) - { - if(discCharInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_ALERT_LEVEL) - { - /* Save Alert Level Characteristic handle */ - Cy_BLE_CheckStoreCharHandle(cy_ble_iasc[discIdx].alertLevelChar); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IASC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_IASC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_IAS) - { - /* IAS does not have any discriptions, return CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE to skip */ - charRangeInfo->range.startHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - charRangeInfo->range.endHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IASC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_IASS_WRITE_CHAR_CMD event is generated. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the Alert Level service characteristic. -* \param attrSize: The size of the Alert Level characteristic value attribute. -* \param attrValue: The pointer to the Alert Level characteristic value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IASC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ias_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (charIndex == CY_BLE_IAS_ALERT_LEVEL) && (attrSize == CY_BLE_IAS_ALERT_LEVEL_SIZE) && - (*attrValue <= CY_BLE_HIGH_ALERT) && - (cy_ble_iasc[discIdx].alertLevelChar.valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Fill all fields of write command request structure ... */ - cy_stc_ble_gattc_write_cmd_req_t wrCmdReq = - { - .handleValPair.attrHandle = cy_ble_iasc[discIdx].alertLevelChar.valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send request to write Alert Level characteristic value */ - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&wrCmdReq); - } - else - { - /* apiResult equals CY_BLE_ERROR_INVALID_PARAMETER */ - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_IAS_CLIENT) */ - -/****************************************************************************** -* Function Name: Cy_BLE_IAS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the the Immediate Alert Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_IAS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_IAS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_IASC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_IASC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_IAS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_IAS_SERVER - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - Cy_BLE_IASS_WriteCmdEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATT_DISCONNECT_IND: - Cy_BLE_IASS_DisconnectEventHandler(); - break; - #endif /* CY_BLE_IAS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_IAS_CLIENT - #endif /* CY_BLE_IAS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_IAS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ias.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ias.h deleted file mode 100644 index e74083bdfe..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ias.h +++ /dev/null @@ -1,143 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ias.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Immediate Alert Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_IAS_H -#define CY_BLE_IAS_H - - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_IAS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_IAS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Immediate Alert Service Characteristic indexes */ -typedef enum -{ - CY_BLE_IAS_ALERT_LEVEL, /**< Alert Level Characteristic index */ - CY_BLE_IAS_CHAR_COUNT /**< Total count of characteristics */ -}cy_en_ble_ias_char_index_t; - -/** Structure with Immediate Alert Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Immediate Alert Service handle*/ - cy_ble_gatt_db_attr_handle_t alertLevelCharHandle; /**< Handle of Alert Level Characteristic */ -} cy_stc_ble_iass_t; - -/** Immediate Alert Service Characteristic Value parameters structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_ias_char_index_t charIndex; /**< Characteristic index of Immediate Alert Service */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Immediate Alert Service characteristic */ -} cy_stc_ble_ias_char_value_t; - -/** Structure with discovered attributes information of Immediate Alert Service */ -typedef struct -{ - /** Handle of Alert Level Characteristic of Immediate Alert Service */ - cy_stc_ble_srvr_char_info_t alertLevelChar; -} cy_stc_ble_iasc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Immediate Alert Service GATT DB handles structure */ - const cy_stc_ble_iass_t *iass; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_ias_config_t; -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ -/** - * \addtogroup group_ble_service_api_IAS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_IAS_Init(cy_stc_ble_ias_config_t *config); -/** @} */ - -#ifdef CY_BLE_IAS_SERVER -/** - * \addtogroup group_ble_service_api_IAS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_IAS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); - -cy_en_ble_api_result_t Cy_BLE_IASS_GetCharacteristicValue(cy_en_ble_ias_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* (CY_BLE_IAS_SERVER) */ - -#ifdef CY_BLE_IAS_CLIENT -/** - * \addtogroup group_ble_service_api_IAS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_IASC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ias_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* (CY_BLE_IAS_CLIENT) */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_IAS_ALERT_LEVEL_SIZE (1u) - - -/*************************************** -* Variables with external linkage -***************************************/ -#ifdef CY_BLE_IAS_CLIENT -extern cy_stc_ble_iasc_t cy_ble_iasc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_IAS_CLIENT) */ - -extern cy_stc_ble_ias_config_t cy_ble_iasConfig; -extern cy_stc_ble_ias_config_t *cy_ble_iasConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_IAS) */ -#endif /* CY_BLE_IAS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ips.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ips.c deleted file mode 100644 index cff53f3803..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ips.c +++ /dev/null @@ -1,2273 +0,0 @@ -/***************************************************************************//** -* \file CY_BLE_ips.c -* \version 2.0 -* -* \brief -* Contains the source code for Indoor Positioning Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_IPS)) - -#ifdef CY_BLE_IPS_CLIENT -/* Server's Indoor Positioning Service characteristics GATT DB handles structure */ -cy_stc_ble_ipsc_t cy_ble_ipsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_ipscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Read Long Descriptors variables */ -static uint8_t *cy_ble_ipscRdLongBuffPtr[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; -static uint16_t cy_ble_ipscRdLongBuffLen[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -static uint16_t cy_ble_ipscCurrLen[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -#endif /* (CY_BLE_IPS_CLIENT) */ - -static cy_ble_callback_t Cy_BLE_IPS_ApplCallback = NULL; - -/* The pointer on global BLE IPS Config structure */ -cy_stc_ble_ips_config_t *cy_ble_ipsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_IPS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_IPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_IPSS_PrepareWriteRequestEventHandler(const cy_stc_ble_gatts_prep_write_req_param_t *eventParam); -static void Cy_BLE_IPSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam); -static void Cy_BLE_IPSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static cy_en_ble_api_result_t Cy_BLE_IPSS_SetAdvertisementData(void); -#endif /* CY_BLE_IPS_SERVER */ - -#ifdef CY_BLE_IPS_CLIENT -static void Cy_BLE_IPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_IPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_IPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_IPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_IPSC_ReadMultipleResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_IPSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_IPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_IPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_IPSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam); -#endif /* CY_BLE_IPS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_IPS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_IPS_Init -***************************************************************************//** -* -* This function initializes the Indoor Positioning Service. -* Initializes the profile internals. -* -* \param config: Configuration structure for the Indoor Positioning Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPS_Init(cy_stc_ble_ips_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_ipsConfigPtr = config; - - /* Registers Event Handler for the IPS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_IPS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_ipsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_IPS_ApplCallback = cy_ble_ipsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_IPS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - cy_ble_ipscRdLongBuffPtr[idx] = NULL; - cy_ble_ipscRdLongBuffLen[idx] = 0u; - cy_ble_ipscCurrLen[idx] = 0u; - - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_IPS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_ipsc[idx], 0, sizeof(cy_stc_ble_ipsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_IPS].uuid = CY_BLE_UUID_IPS_SERVICE; - } - cy_ble_ipscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_IPS_CLIENT */ - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for IPS Service is:\n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode: Indicates the event that triggered this callback -* (e.g. CY_BLE_EVT_IPS_NOTIFICATION_ENABLED). -* * eventParam: Contains the parameters corresponding to the -* current event. (e.g. Pointer to cy_stc_ble_ips_char_value_t -* structure that contains details of the characteristic -* for which the notification enabled event was triggered). -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_IPS_ApplCallback = callbackFunc; - if(cy_ble_ipsConfigPtr != NULL) - { - cy_ble_ipsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_IPS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED -* -* NOTE: when advertisement is active this API uses Cy_BLE_GAPP_UpdateAdvScanData() to -* update the advertisement packet. In the case of successful execution (return value = CY_BLE_SUCCESS) -* the event CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE appears. -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_IPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(Cy_BLE_IPS_ApplCallback != NULL) - { - cy_stc_ble_ips_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .gattErrorCode = CY_BLE_GATT_ERR_NONE - }; - - for(locCharValue.charIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharValue.charIndex < CY_BLE_IPS_CHAR_COUNT; - locCharValue.charIndex++) - { - if((eventParam->handleValPair.attrHandle == - cy_ble_ipsConfigPtr->ipss->charInfo[locCharValue.charIndex].charHandle) || - (eventParam->handleValPair.attrHandle == - cy_ble_ipsConfigPtr->ipss->charInfo[locCharValue.charIndex].descrHandle[CY_BLE_IPS_SCCD]) || - (eventParam->handleValPair.attrHandle == - cy_ble_ipsConfigPtr->ipss->charInfo[locCharValue.charIndex].descrHandle[CY_BLE_IPS_CEPD])) - { - gattErr = Cy_BLE_GATT_DbCheckPermission(eventParam->handleValPair.attrHandle, &eventParam->connHandle, - CY_BLE_GATT_DB_WRITE | CY_BLE_GATT_DB_PEER_INITIATED); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - locCharValue.value = &eventParam->handleValPair.value; - - if(!CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(eventParam->handleValPair.attrHandle, - CY_BLE_GATT_DB_CH_PROP_WRITE)) - { - gattErr = CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED; - } - else if(eventParam->handleValPair.value.len > - CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(eventParam->handleValPair.attrHandle)) - { - gattErr = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - else - { - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSS_WRITE_CHAR, &locCharValue); - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED) - { - gattErr = CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if((gattErr == CY_BLE_GATT_ERR_NONE) && - (eventParam->handleValPair.attrHandle == cy_ble_ipsConfigPtr-> - ipss->charInfo[locCharValue.charIndex].charHandle)) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN - (cy_ble_ipsConfigPtr->ipss->charInfo[locCharValue.charIndex].charHandle, - locCharValue.value->len); - - (void)Cy_BLE_IPSS_SetAdvertisementData(); - } - } - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - - - return(gattErr); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_WriteCmdEventHandler -***************************************************************************//** -* -* Handles the Write Without Response Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* NOTE: when advertisement is active this API uses Cy_BLE_GAPP_UpdateAdvScanData() to -* update the advertisement packet. In the case of successful execution (return value = CY_BLE_SUCCESS) -* the event CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE appears. -* -******************************************************************************/ -static void Cy_BLE_IPSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_ips_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - cy_en_ble_gatt_err_code_t gattErr; - - for(locCharValue.charIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharValue.charIndex < CY_BLE_IPS_CHAR_COUNT; - locCharValue.charIndex++) - { - if((eventParam->handleValPair.attrHandle == - cy_ble_ipsConfigPtr->ipss->charInfo[locCharValue.charIndex].charHandle) && - (Cy_BLE_IPS_ApplCallback != NULL)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSS_WRITE_CHAR, &locCharValue); - (void)Cy_BLE_IPSS_SetAdvertisementData(); - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_PrepareWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Prepare Write Request Event. -* -* \param eventParam: The pointer to the data that comes with a prepare -* write request. -* -******************************************************************************/ -static void Cy_BLE_IPSS_PrepareWriteRequestEventHandler(const cy_stc_ble_gatts_prep_write_req_param_t *eventParam) -{ - cy_en_ble_ips_char_index_t locCharIndex; - - for(locCharIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharIndex < CY_BLE_IPS_CHAR_COUNT; locCharIndex++) - { - if(eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - cy_ble_ipsConfigPtr->ipss->charInfo[locCharIndex].charHandle) - { - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_ExecuteWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Execute Write Request Event. -* -* \param eventParam: The pointer to the data that came with a write request. -* -******************************************************************************/ -static void Cy_BLE_IPSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam) -{ - uint32_t locCount; - cy_stc_ble_ips_char_value_t locCharValue[CY_BLE_IPS_CHAR_COUNT]; - cy_stc_ble_gatt_value_t locGattValue[CY_BLE_IPS_CHAR_COUNT]; - cy_en_ble_ips_char_index_t locCharIndex; - - for(locCharIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharIndex < CY_BLE_IPS_CHAR_COUNT; locCharIndex++) - { - locGattValue[locCharIndex].len = 0u; - locGattValue[locCharIndex].val = NULL; - } - - for(locCount = 0u; locCount < eventParam->prepWriteReqCount; locCount++) - { - for(locCharIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharIndex < CY_BLE_IPS_CHAR_COUNT; locCharIndex++) - { - if(eventParam->baseAddr[locCount].handleValuePair.attrHandle == - cy_ble_ipsConfigPtr->ipss->charInfo[locCharIndex].charHandle) - { - locGattValue[locCharIndex].len = eventParam->baseAddr[locCount].offset + - eventParam->baseAddr[locCount].handleValuePair.value.len; - - if(locGattValue[locCharIndex].val == NULL) - { - locGattValue[locCharIndex].val = eventParam->baseAddr[locCount].handleValuePair.value.val; - } - else if(eventParam->baseAddr[locCount].offset == 0u) - { - /* Case when client wants to rewrite value from beginning */ - locGattValue[locCharIndex].val = eventParam->baseAddr[locCount].handleValuePair.value.val; - } - else - { - /* Do nothing */ - } - } - } - } - - for(locCharIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharIndex < CY_BLE_IPS_CHAR_COUNT; locCharIndex++) - { - if((Cy_BLE_IPS_ApplCallback != NULL) && (locGattValue[locCharIndex].len != 0u) && - (locGattValue[locCharIndex].len <= - CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_ipsConfigPtr->ipss->charInfo[locCharIndex].charHandle))) - { - /* Check the execWriteFlag before execute or cancel write long operation */ - if(eventParam->execWriteFlag == CY_BLE_GATT_EXECUTE_WRITE_EXEC_FLAG) - { - locCharValue[locCharIndex].gattErrorCode = CY_BLE_GATT_ERR_NONE; - locCharValue[locCharIndex].connHandle = eventParam->connHandle; - locCharValue[locCharIndex].charIndex = locCharIndex; - locCharValue[locCharIndex].value = &locGattValue[locCharIndex]; - - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSS_WRITE_CHAR, &locCharValue[locCharIndex]); - - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_ipsConfigPtr->ipss->charInfo[locCharIndex].charHandle, - locGattValue[locCharIndex].len); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the characteristic value of the service in the local database. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param attrSize: The size (in bytes) of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -* NOTE: when advertisement is active this API uses Cy_BLE_GAPP_UpdateAdvScanData() to -* update the advertisement packet. In the case of successful execution (return value = CY_BLE_SUCCESS) -* the event CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE appears. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSS_SetCharacteristicValue(cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - if(charIndex >= CY_BLE_IPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_ipsConfigPtr->ipss->charInfo[charIndex].charHandle) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = Cy_BLE_IPSS_SetAdvertisementData(); - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the characteristic value of the service, which is a value identified by -* charIndex. -* -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is -* absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSS_GetCharacteristicValue(cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check parameters */ - if(charIndex >= CY_BLE_IPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_ipsConfigPtr->ipss->charInfo[charIndex].charHandle) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the Indoor -* Positioning Service from the local GATT database. -* -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSS_GetCharacteristicDescriptor(cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - /* Check parameters */ - if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (descrIndex >= CY_BLE_IPS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_ipsConfigPtr->ipss->charInfo[charIndex]. - descrHandle[descrIndex]) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Set a characteristic descriptor of a specified characteristic of the Indoor -* Positioning Service from the local GATT database. -* -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data to -* be stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSS_SetCharacteristicDescriptor(cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check parameters */ - if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (descrIndex >= CY_BLE_IPS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_ipsConfigPtr->ipss->charInfo[charIndex]. - descrHandle[descrIndex]) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = Cy_BLE_IPSS_SetAdvertisementData(); - } - } - - return(apiResult); -} - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - -/****************************************************************************** -* Function Name: Cy_BLE_IPSS_SetAdvertisementData -***************************************************************************//** -* -* Sets the characteristics values in advertisement packet depending on a value of -* Indoor Positioning Configuration characteristic. -* -* This function must be called when Cy_BLE_GetBleSsState() returns -* CY_BLE_BLESS_STATE_EVENT_CLOSE state. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The advertisement packet collected successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Read operation is not permitted on this -* attribute or on NULL pointer, Data length in input -* parameter exceeds 31 bytes. -* * CY_BLE_ERROR_INVALID_OPERATION - The advertisement packet doesn't contain -* the User List or it is to small or ADV Event is not closed, -* BLESS is active or ADV is not enabled. -* -* -******************************************************************************/ -static cy_en_ble_api_result_t Cy_BLE_IPSS_SetAdvertisementData(void) -{ - uint32_t fFlag; - uint8_t adLength; - uint8_t dataLengthAddress = 0u; - uint8_t byteCounter; - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint8_t ipssConfigFlags; - uint8_t advIndex = 0u; - - do - { - byteCounter = 0u; - fFlag = 0u; - while((byteCounter < cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advDataLen) && (fFlag == 0u)) - { - adLength = cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData[byteCounter]; - - if(adLength != 0u) - { - /* Increment byte counter so that it points to AD type field */ - byteCounter++; - - if(cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData[byteCounter] == CY_BLE_IPS_AD_TYPE) - { - /* Start if a "Indoor Positioning" AD type was found. Set flag and exit the loop. */ - fFlag = 1u; - dataLengthAddress = byteCounter - 1u; - } - else - { - byteCounter += adLength; - } - } - else - { - /* End of advertisement data structure was encountered so exit loop. */ - break; - } - } - - if(fFlag != 0u) - { - /* Get Configuration value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_INDOOR_POSITINING_CONFIG].charHandle; - dbAttrValInfo.handleValuePair.value.len = 1u; - dbAttrValInfo.handleValuePair.value.val = &ipssConfigFlags; - - /* Increment byte counter to point to Indoor Positioning data */ - byteCounter++; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if((ipssConfigFlags & CY_BLE_IPS_CHARACTERISTICS_IN_ADVERTISING) != 0u) - { - cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData[byteCounter] = ipssConfigFlags; - byteCounter++; - - if((ipssConfigFlags & CY_BLE_IPS_COORDINATES_IN_ADVERTISING) != 0u) - { - if((ipssConfigFlags & CY_BLE_IPS_TYPE_OF_COORDINATE_IN_ADVERTISING) == CY_BLE_IPS_WGS84_COORDINATE) - { - /* CY_BLE_IPS_WGS84_COORDINATE - * Latitude - */ - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_LATITUDE].charHandle; - dbAttrValInfo.handleValuePair.value.len = 4u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - - /* Longitude */ - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_LONGITUDE].charHandle; - dbAttrValInfo.handleValuePair.value.len = 4u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - } - else - { /* CY_BLE_IPS_LOCAL_COORDINATE - * North coordinate - */ - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_LOCAL_NORTH_COORDINATE].charHandle; - dbAttrValInfo.handleValuePair.value.len = 2u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - - /* East coordinate */ - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_LOCAL_EAST_COORDINATE].charHandle; - dbAttrValInfo.handleValuePair.value.len = 2u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - } - } - - if((ipssConfigFlags & CY_BLE_IPS_TX_POWER_IN_ADVERTISING) != 0u) - { - cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData[byteCounter] = 0xAAu; - byteCounter++; - } - - if((ipssConfigFlags & CY_BLE_IPS_FLOOR_NUMBER_IN_ADVERTISING) != 0u) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_FLOOR_NUMBER].charHandle; - dbAttrValInfo.handleValuePair.value.len = 1u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - } - - if((ipssConfigFlags & CY_BLE_IPS_ALTITUDE_IN_ADVERTISING) != 0u) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss->charInfo[CY_BLE_IPS_ALTITUDE]. - charHandle; - dbAttrValInfo.handleValuePair.value.len = 2u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - } - - if((ipssConfigFlags & CY_BLE_IPS_UNCERTAINTY_NUMBER_IN_ADVERTISING) != 0u) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_ipsConfigPtr->ipss-> - charInfo[CY_BLE_IPS_UNCERTAINTY].charHandle; - dbAttrValInfo.handleValuePair.value.len = 2u; - dbAttrValInfo.handleValuePair.value.val = &cy_ble_configPtr->discoveryModeInfo[advIndex]. - advData->advData[byteCounter]; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - byteCounter += (uint8_t)dbAttrValInfo.handleValuePair.value.len; - } - } - else /* No CY_BLE_IPS_CHARACTERISTICS_IN_ADVERTISING */ - { - } - - cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advData[dataLengthAddress] = - byteCounter - dataLengthAddress - 1u; - cy_ble_configPtr->discoveryModeInfo[advIndex].advData->advDataLen = byteCounter; - } - - advIndex++; - } - while(advIndex < CY_BLE_GAPP_CONF_COUNT); - - if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING) - { - apiResult = Cy_BLE_GAPP_UpdateAdvScanData(&cy_ble_configPtr->discoveryModeInfo[cy_ble_advIndex]); - } - - return(apiResult); -} - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - -#endif /* CY_BLE_IPS_SERVER */ - -#ifdef CY_BLE_IPS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_SetCharacteristicValueWithoutResponse -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server without response. -* -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_SetCharacteristicValueWithoutResponse(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = connHandle }; - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_ipsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if((mtuParam.mtu - CY_BLE_GATT_WRITE_HEADER_LEN) < attrSize) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_write_cmd_req_t writeCmdReqParam = - { - .handleValPair.attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&writeCmdReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_IPSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* The Write Response just confirms the operation success. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_WRITE_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ips_char_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_EXEC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = connHandle }; - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_ipsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if((mtuParam.mtu - CY_BLE_GATT_WRITE_HEADER_LEN) < attrSize) - { - cy_stc_ble_gattc_prep_write_req_t prepWriteReqParam = - { - .handleValOffsetPair.handleValuePair.attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle, - .handleValOffsetPair.offset = 0u, - .handleValOffsetPair.handleValuePair.value.val = attrValue, - .handleValOffsetPair.handleValuePair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteLongCharacteristicValues(&prepWriteReqParam); - - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_ReliableWriteCharacteristicValue -***************************************************************************//** -* -* This function is used to perform a reliable write command for the -* Indoor Positioning Service (identified by charIndex) value attribute to the server. -* -* The Write response just confirms the operation success. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ips_char_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_EXEC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_ReliableWriteCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_EXTENDED_PROPERTIES & cy_ble_ipsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_reliable_write_req_t prepWriteReqParam = { .connHandle = connHandle }; - cy_stc_ble_gatt_handle_value_offset_param_t handleValOffsetPairParam = - { - .handleValuePair.attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle, - .handleValuePair.value.val = attrValue, - .handleValuePair.value.len = attrSize, - .offset = 0u - }; - prepWriteReqParam.handleValOffsetPair = &handleValOffsetPairParam; - prepWriteReqParam.numOfRequests = 1u; - - apiResult = Cy_BLE_GATTC_ReliableWrites(&prepWriteReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server, -* as identified by its charIndex -* -* The Read Response returns the characteristic Value in the Attribute Value -* parameter. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ips_char_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_ipsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - } - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_GetLongCharacteristicValue -***************************************************************************//** -* -* Sends a request to read a long characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the buffer where the read long characteristic -* descriptor value should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ips_char_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_BLOB_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_GetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((attrSize == 0u) || (attrValue == NULL) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_ipsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_blob_req_t readBlobReqParam = - { - .handleOffset.attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle, - .handleOffset.offset = 0u, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadLongCharacteristicValues(&readBlobReqParam); - } - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].valueHandle; - cy_ble_ipscRdLongBuffLen[discIdx] = attrSize; - cy_ble_ipscRdLongBuffPtr[discIdx] = attrValue; - cy_ble_ipscCurrLen[discIdx] = 0u; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_GetMultipleCharacteristicValues -***************************************************************************//** -* -* This function reads multiple Characteristic Values from a GATT Server when -* the GATT Client knows the Characteristic value handles. This is a -* non-blocking function. -* -* Internally, Read Multiple Request is sent to the peer device in response to -* which Read Multiple Response is received. This results in -* CY_BLE_EVT_GATTC_READ_MULTI_RSP event, which is propagated to the application -* layer. -* -* An Error Response event is sent by the server (CY_BLE_EVT_GATTC_ERROR_RSP) in -* response to the Read Multiple Request if insufficient authentication, -* insufficient authorization, insufficient encryption key size is used by the -* client, or if a read operation is not permitted on any of the Characteristic -* values. The Error Code parameter is set as specified in the Attribute -* Protocol. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.8.4 -* for more details on the sequence of operations. -* -* \param connHandle: Connection handle to identify the peer GATT entity, of type -* cy_stc_ble_conn_handle_t. -* \param charIndexesList: Pointer to a list of Characteristic value handles -* \param numberOfCharIndexes: Number of requested Characteristic handles -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | 'connHandle' value does not represent any existing entry in the Stack -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed -* CY_BLE_ERROR_INVALID_STATE | Connection with the Client is not established. -* CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE | The peer device doesn't have the particular characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_READ_MULTIPLE_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ips_char_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_MULTI_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_GetMultipleCharacteristicValues(cy_stc_ble_conn_handle_t connHandle, - const cy_en_ble_ips_char_index_t *charIndexesList, - uint8_t numberOfCharIndexes) - -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_stc_ble_gattc_read_mult_req_t readMultiReqParam = { .connHandle = connHandle }; - uint16_t valueHandles[CY_BLE_IPS_CHAR_COUNT]; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - uint32_t indexInList; - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - for(indexInList = 0u; ((indexInList < numberOfCharIndexes) && (apiResult == CY_BLE_SUCCESS)); indexInList++) - { - if(cy_ble_ipsc[discIdx].charInfo[charIndexesList[indexInList]].valueHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_ipsc[discIdx].charInfo[charIndexesList[indexInList]].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - valueHandles[indexInList] = cy_ble_ipsc[discIdx].charInfo[charIndexesList[indexInList]].valueHandle; - } - } - - if(apiResult == CY_BLE_SUCCESS) - { - readMultiReqParam.handleListType.listCount = numberOfCharIndexes; - readMultiReqParam.handleListType.handleList = valueHandles; - apiResult = Cy_BLE_GATTC_ReadMultipleCharacteristicValues(&readMultiReqParam); - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic Value to the server, -* as identified by its charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_WRITE_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_ips_descr_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (descrIndex >= CY_BLE_IPS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service specific read response from device */ - cy_ble_ipscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the IPS service-specific callback is registered -* (with Cy_BLE_IPS_RegisterAttrCallback): -* * CY_BLE_EVT_IPSC_READ_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_ips_descr_value_t. -* . -* Otherwise (if the IPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_IPS_CHAR_COUNT) || (descrIndex >= CY_BLE_IPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_ipsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_ipsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ipscReqHandle[discIdx] = cy_ble_ipsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_IPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* User Data Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_ipscCharUuid[CY_BLE_IPS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_INDOOR_POSITINING_CONFIG, /**< Set of characteristic values included in the Indoor Positioning - * Service AD type */ - CY_BLE_UUID_CHAR_LATITUDE, /**< WGS84 North coordinate of the device.*/ - CY_BLE_UUID_CHAR_LONGITUDE, /**< WGS84 East coordinate of the device.*/ - CY_BLE_UUID_CHAR_LOCAL_NORTH_COORDINATE, /**< North coordinate of the device using local coordinate system. */ - CY_BLE_UUID_CHAR_LOCAL_EAST_COORDINATE, /**< East coordinate of the device using local coordinate system. */ - CY_BLE_UUID_CHAR_FLOOR_NUMBER, /**< Describes in which floor the device is installed. */ - CY_BLE_UUID_CHAR_ALTITUDE, /**< Altitude of the device. */ - CY_BLE_UUID_CHAR_UNCERTAINTY, /**< Uncertainty of the location information the device exposes. */ - CY_BLE_UUID_CHAR_LOCATION_NAME /**< Name of the location the device is installed. */ - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_IPS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_IPS_CHAR_COUNT; i++) - { - if(cy_ble_ipscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_ipsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ipsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_ipsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_ipsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_IPS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_IPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_IPS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_SERVER_CONFIG: - descIdx = (uint32_t)CY_BLE_IPS_SCCD; - break; - - case CY_BLE_UUID_CHAR_EXTENDED_PROPERTIES: - descIdx = (uint32_t)CY_BLE_IPS_CEPD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_ipsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ipsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_IPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_IPS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_IPS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_ipsc[discIdx].charInfo[charIdx].endHandle - cy_ble_ipsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_ipsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_ipsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam - The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_IPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_en_ble_ips_char_index_t locCharIndex; - uint32_t locReqHandle = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_IPS_ApplCallback != NULL) && - (cy_ble_ipscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; (locCharIndex < CY_BLE_IPS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - if(cy_ble_ipscReqHandle[discIdx] == cy_ble_ipsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_ips_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_ips_descr_index_t locDescIndex; - - for(locDescIndex = CY_BLE_IPS_SCCD; (locDescIndex < CY_BLE_IPS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_ipscReqHandle[discIdx] == cy_ble_ipsc[discIdx].charInfo[locCharIndex]. - descrHandle[locDescIndex]) - { - cy_stc_ble_ips_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = &eventParam->value - }; - - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam - The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_IPSC_ReadMultipleResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - if(Cy_BLE_IPS_ApplCallback != NULL) - { - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_READ_MULTIPLE_CHAR_RESPONSE, eventParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_ReadLongRespEventHandler -***************************************************************************//** -* -* Handles a Read Long Response event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_IPSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_stc_ble_gattc_stop_cmd_param_t stopCmdParam = { .connHandle = eventParam->connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_IPS_ApplCallback != NULL) && - (cy_ble_ipscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_ips_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - cy_stc_ble_gatt_value_t locGattValue; - /* Go through all long characteristics */ - for(locCharValue.charIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; locCharValue.charIndex < CY_BLE_IPS_CHAR_COUNT; - locCharValue.charIndex++) - { - if(cy_ble_ipsc[discIdx].charInfo[locCharValue.charIndex].valueHandle == cy_ble_ipscReqHandle[discIdx]) - { - uint32_t i; - - /* Update user buffer with received data */ - for(i = 0u; i < eventParam->value.len; i++) - { - if(cy_ble_ipscCurrLen[discIdx] < cy_ble_ipscRdLongBuffLen[discIdx]) - { - cy_ble_ipscRdLongBuffPtr[discIdx][cy_ble_ipscCurrLen[discIdx]] = eventParam->value.val[i]; - cy_ble_ipscCurrLen[discIdx]++; - } - else - { - (void)Cy_BLE_GATTC_StopCmd(&stopCmdParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = eventParam->connHandle }; - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* If received data length is less than MTU size, Read Long - * request is completed or provided user's buffer is full. - */ - locGattValue.val = cy_ble_ipscRdLongBuffPtr[discIdx]; - locGattValue.len = cy_ble_ipscCurrLen[discIdx]; - locCharValue.value = &locGattValue; - - if(((mtuParam.mtu - 1u) > eventParam->value.len)) - { - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_READ_CHAR_RESPONSE, &locCharValue); - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - else - { - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_READ_BLOB_RSP, &locCharValue); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_IPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t locReqHandle = 0u; - cy_en_ble_ips_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_IPS_ApplCallback != NULL) && - (cy_ble_ipscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; (locCharIndex < CY_BLE_IPS_CHAR_COUNT) && - (locReqHandle == 0u); locCharIndex++) - { - if(cy_ble_ipscReqHandle[discIdx] == cy_ble_ipsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_ips_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .value = NULL - }; - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_WRITE_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else - { - cy_en_ble_ips_descr_index_t locDescIndex; - for(locDescIndex = CY_BLE_IPS_SCCD; (locDescIndex < CY_BLE_IPS_DESCR_COUNT) && - (locReqHandle == 0u); locDescIndex++) - { - if(cy_ble_ipscReqHandle[discIdx] == cy_ble_ipsc[discIdx].charInfo[locCharIndex]. - descrHandle[locDescIndex]) - { - cy_stc_ble_ips_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .descrIndex = locDescIndex, - .value = NULL - }; - - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - } - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_ExecuteWriteResponseEventHandler -***************************************************************************//** -* -* Handles a Execute Write Response event for the User Data Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_IPSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam) -{ - cy_stc_ble_ips_char_value_t locCharVal = { .connHandle = eventParam->connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - uint32_t i; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_IPS_ApplCallback != NULL) && - (cy_ble_ipscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(i = 0u; i < ((uint8_t)CY_BLE_IPS_CHAR_COUNT); i++) - { - if(cy_ble_ipsc[discIdx].charInfo[i].valueHandle == cy_ble_ipscReqHandle[discIdx]) - { - locCharVal.charIndex = (cy_en_ble_ips_char_index_t)i; - locCharVal.value = NULL; - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_WRITE_CHAR_RESPONSE, &locCharVal); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_IPSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_IPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(cy_ble_ipscReqHandle[discIdx] == eventParam->errInfo.attrHandle) - { - if((eventParam->errInfo.opCode == CY_BLE_GATT_READ_BLOB_REQ) && - (eventParam->errInfo.errorCode == CY_BLE_GATT_ERR_ATTRIBUTE_NOT_LONG)) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = eventParam->errInfo.attrHandle, - .connHandle = eventParam->connHandle - }; - (void)Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - if(Cy_BLE_IPS_ApplCallback != NULL) - { - cy_stc_ble_ips_char_value_t locGattError = - { - .connHandle = eventParam->connHandle, - .value = NULL, - .gattErrorCode = eventParam->errInfo.errorCode - }; - - for(locGattError.charIndex = CY_BLE_IPS_INDOOR_POSITINING_CONFIG; - locGattError.charIndex < CY_BLE_IPS_CHAR_COUNT; locGattError.charIndex++) - { - if(cy_ble_ipsc[discIdx].charInfo[locGattError.charIndex].valueHandle == - eventParam->errInfo.attrHandle) - { - Cy_BLE_IPS_ApplCallback((uint32_t)CY_BLE_EVT_IPSC_ERROR_RESPONSE, &locGattError); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - - cy_ble_ipscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - } -} - -#endif /* CY_BLE_IPS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_IPS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for Indoor Positioning Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_IPS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_IPS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_IPSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_IPSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_IPSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_IPS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_IPS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_IPSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - Cy_BLE_IPSS_WriteCmdEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - Cy_BLE_IPSS_ExecuteWriteRequestEventHandler((cy_stc_ble_gatts_exec_write_req_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - Cy_BLE_IPSS_PrepareWriteRequestEventHandler((cy_stc_ble_gatts_prep_write_req_param_t*)eventParam); - break; - #endif /* CY_BLE_IPS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_IPS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_IPSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_IPSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_IPSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_MULTI_RSP: - Cy_BLE_IPSC_ReadMultipleResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_BLOB_RSP: - Cy_BLE_IPSC_ReadLongRespEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_EXEC_WRITE_RSP: - Cy_BLE_IPSC_ExecuteWriteResponseEventHandler((cy_stc_ble_gattc_exec_write_rsp_t*)eventParam); - break; - #endif /* CY_BLE_IPS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_IPS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ips.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ips.h deleted file mode 100644 index 4a57e8f31f..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ips.h +++ /dev/null @@ -1,305 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ips.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Indoor Positioning -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_IPS_H -#define CY_BLE_IPS_H - -#include "cy_ble_gatt.h" - -/** - * \addtogroup group_ble_service_api_IPS_definitions - * @{ - */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_IPS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Data Struct Definition -***************************************/ - -/** IPS Characteristic indexes */ -typedef enum -{ - CY_BLE_IPS_INDOOR_POSITINING_CONFIG, /**< Set of characteristic values included in the Indoor Positioning Service AD type. */ - CY_BLE_IPS_LATITUDE, /**< WGS84 North coordinate of the device. */ - CY_BLE_IPS_LONGITUDE, /**< WGS84 East coordinate of the device. */ - CY_BLE_IPS_LOCAL_NORTH_COORDINATE, /**< North coordinate of the device using local coordinate system. */ - CY_BLE_IPS_LOCAL_EAST_COORDINATE, /**< East coordinate of the device using local coordinate system. */ - CY_BLE_IPS_FLOOR_NUMBER, /**< Describes in which floor the device is installed. */ - CY_BLE_IPS_ALTITUDE, /**< Altitude of the device. */ - CY_BLE_IPS_UNCERTAINTY, /**< Uncertainty of the location information the device exposes. */ - CY_BLE_IPS_LOCATION_NAME, /**< Name of the location where the device is installed. */ - CY_BLE_IPS_CHAR_COUNT /**< Total count of IPS characteristics */ -}cy_en_ble_ips_char_index_t; - -/** IPS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_IPS_CEPD, /**< Characteristic Extended Properties descriptor index */ - CY_BLE_IPS_SCCD, /**< Server Characteristic Configuration Descriptor index */ - CY_BLE_IPS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_ips_descr_index_t; - -/** IPS Characteristic with descriptors */ -typedef struct -{ - /** Handles of Characteristic value */ - cy_ble_gatt_db_attr_handle_t charHandle; - - /** Array of Descriptor handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_IPS_DESCR_COUNT]; -} cy_stc_ble_ipss_char_t; - -/** Structure to hold pointer to cy_stc_ble_ipss_char_t */ -typedef struct -{ - /** Pointer to cy_stc_ble_ipss_char_t that holds information about specific - * IP Characteristic - */ - cy_stc_ble_ipss_char_t *charInfoPtr; -} cy_stc_ble_ipss_char_info_ptr_t; - -/** Structure with Indoor Positioning Service attribute handles */ -typedef struct -{ - /** Indoor Positioning Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Indoor Positioning Service Array with pointers to - * Characteristic handles. - */ - cy_stc_ble_ipss_char_t charInfo[CY_BLE_IPS_CHAR_COUNT]; -} cy_stc_ble_ipss_t; - -/** IPS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_IPS_DESCR_COUNT]; /**< Array of Descriptor handles */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_ipsc_char_t; - -/** Structure to hold pointer to cy_stc_ble_ipsc_char_t */ -typedef struct -{ - /** Pointer to cy_stc_ble_ipsc_char_t that holds information about specific IP Characteristic. */ - cy_stc_ble_ipsc_char_t *charInfoPtr; -} cy_stc_ble_ipsc_char_info_ptr_t; - -/** Structure with discovered attributes information of Indoor Positioning Service. */ -typedef struct -{ - /** Indoor Positioning Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Indoor Positioning Service characteristics info array */ - cy_stc_ble_ipsc_char_t charInfo[CY_BLE_IPS_CHAR_COUNT]; -} cy_stc_ble_ipsc_t; - - -/** IPS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ips_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ -} cy_stc_ble_ips_char_value_t; - -/** IPS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ips_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_ips_descr_index_t descrIndex; /**< Index of descriptor */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< Error code received from application (optional) */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_ips_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Indoor Positioning Service GATT DB handles structure */ - const cy_stc_ble_ipss_t *ipss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_ips_config_t; - -/** @} */ - -/*************************************** -* API Constants -***************************************/ -/* IPS specific GATT errors */ -#define CY_BLE_GATT_ERR_WRITE_REQ_REJECTED (0x80u) - - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - -#define CY_BLE_IPS_AD_TYPE (0x25u) -#define CY_BLE_IPS_SERVICE_DATA_LENGTH (0x05u) - -#define CY_BLE_IPS_CHARACTERISTICS_IN_ADVERTISING (0x7Du) -#define CY_BLE_IPS_COORDINATES_IN_ADVERTISING (0x01u) -#define CY_BLE_IPS_COORDINATES_NOT_PRESENT (0u) -#define CY_BLE_IPS_COORDINATES_PRESENT (1u) -#define CY_BLE_IPS_TYPE_OF_COORDINATE_IN_ADVERTISING (0x02u) -#define CY_BLE_IPS_WGS84_COORDINATE (0u) -#define CY_BLE_IPS_LOCAL_COORDINATE (1u) -#define CY_BLE_IPS_TX_POWER_IN_ADVERTISING (0x04u) -#define CY_BLE_IPS_TX_POWER_NOT_PRESENT (0u) -#define CY_BLE_IPS_TX_POWER_PRESENT (1u) -#define CY_BLE_IPS_ALTITUDE_IN_ADVERTISING (0x08u) -#define CY_BLE_IPS_ALTITUDE_NOT_PRESENT (0u) -#define CY_BLE_IPS_ALTITUDE_PRESENT (1u) -#define CY_BLE_IPS_FLOOR_NUMBER_IN_ADVERTISING (0x10u) -#define CY_BLE_IPS_FLOOR_NUMBER_NOT_PRESENT (0u) -#define CY_BLE_IPS_FLOOR_NUMBER_PRESENT (1u) -#define CY_BLE_IPS_UNCERTAINTY_NUMBER_IN_ADVERTISING (0x20u) -#define CY_BLE_IPS_UNCERTAINTY_NUMBER_NOT_PRESENT (0u) -#define CY_BLE_IPS_UNCERTAINTY_NUMBER_PRESENT (1u) -#define CY_BLE_IPS_LOCATION_NAME_IN_GATT_DATABASE (0x40u) -#define CY_BLE_IPS_LOCATION_NAME_NOT_PRESENT (0u) -#define CY_BLE_IPS_LOCATION_NAME_PRESENT (1u) - - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_IPS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_IPS_Init(cy_stc_ble_ips_config_t *config); -cy_en_ble_api_result_t Cy_BLE_IPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_IPS_SERVER -/** - * \addtogroup group_ble_service_api_IPS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_IPSS_SetCharacteristicValue(cy_en_ble_ips_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSS_GetCharacteristicValue(cy_en_ble_ips_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSS_SetCharacteristicDescriptor(cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSS_GetCharacteristicDescriptor(cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - - -#endif /* CY_BLE_IPS_SERVER */ - -/** @} */ - -#ifdef CY_BLE_IPS_CLIENT -/** - * \addtogroup group_ble_service_api_IPS_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_IPSC_SetCharacteristicValueWithoutResponse(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSC_ReliableWriteCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - uint8_t attrSize, uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_IPSC_GetMultipleCharacteristicValues(cy_stc_ble_conn_handle_t connHandle, - const cy_en_ble_ips_char_index_t *charIndexesList, - uint8_t numberOfCharIndexes); - -cy_en_ble_api_result_t Cy_BLE_IPSC_GetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_IPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ips_char_index_t charIndex, - cy_en_ble_ips_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_IPS_CLIENT */ - - -/*************************************** -* Macro Functions -***************************************/ - -#define Cy_BLE_IPS_Get16ByPtr Cy_BLE_Get16ByPtr - -#ifdef CY_BLE_IPS_CLIENT - -#define Cy_BLE_IPSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_IPS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_ipsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_IPSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_IPS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_IPS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_ipsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].descrHandle[descrIndex]) - -#endif /* (CY_BLE_IPS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_IPS_CLIENT -extern cy_stc_ble_ipsc_t cy_ble_ipsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_IPS_CLIENT) */ - -extern cy_stc_ble_ips_config_t cy_ble_ipsConfig; -extern cy_stc_ble_ips_config_t *cy_ble_ipsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_IPS) */ -#endif /* CY_BLE_IPS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lls.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lls.c deleted file mode 100644 index 8560a361e0..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lls.c +++ /dev/null @@ -1,709 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_lls.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Link Loss Service of the BLE -* Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_LLS)) -static cy_ble_callback_t Cy_BLE_LLS_ApplCallback = NULL; - -#ifdef CY_BLE_LLS_CLIENT -/* LLS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_llsc_t cy_ble_llsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_llscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_LLS_CLIENT) */ - -/* The pointer on global BLE LLS Config structure */ -cy_stc_ble_lls_config_t *cy_ble_llsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_LLS_SERVER -static void Cy_BLE_LLSS_ConnectEventHandler(void); -static cy_en_ble_gatt_err_code_t Cy_BLE_LLSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* (CY_BLE_LLS_SERVER) */ - -#ifdef CY_BLE_LLS_CLIENT -static void Cy_BLE_LLSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_LLSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_LLSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_LLSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_LLSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_LLS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_LLS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_LLS_Init -***************************************************************************//** -* -* This function initializes the Link Loss Service. -* -* \param config: Configuration structure for the Link Loss Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LLS_Init(cy_stc_ble_lls_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_llsConfigPtr = config; - - /* Registers Event Handler for the LLS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_LLS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_llsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_LLS_ApplCallback = cy_ble_llsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_LLS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_LLS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_llsc[idx].alertLevelChar.valueHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_LLS].uuid = CY_BLE_UUID_LINK_LOSS_SERVICE; - } - cy_ble_llscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* (CY_BLE_LLS_CLIENT) */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for Link Loss Service is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_LLSS_NOTIFICATION_ENABLED). -* * eventParam contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_lls_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise this -* data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LLS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_LLS_ApplCallback = callbackFunc; - if(cy_ble_llsConfigPtr != NULL) - { - cy_ble_llsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_LLS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_LLSS_ConnectEventHandler -***************************************************************************//** -* -* Handles the Connection Indication event for Link Loss Service. -* -******************************************************************************/ -static void Cy_BLE_LLSS_ConnectEventHandler(void) -{ - uint8_t tmpAlertLevel = CY_BLE_NO_ALERT; - - /* Input parameters validation passed, so save Alert Level */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_llsConfigPtr->llss->alertLevelCharHandle, - .handleValuePair.value.len = CY_BLE_LLS_ALERT_LEVEL_SIZE, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - dbAttrValInfo.handleValuePair.value.val = &tmpAlertLevel; - (void)Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for the Link Loss service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t * eventParam: the pointer to the data structure -* specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t: Function result returns one of the following status values: -* * CY_BLE_GATT_ERR_NONE - The Alert Level Characteristic was written successfully -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred -* * CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN - The Data length for the Alert Level -* Characteristic handle is invalid -* * CY_BLE_GATT_ERR_INVALID_HANDLE - Alert Level Characteristic handle is invalid -* * CY_BLE_GATT_ERR_OUT_OF_RANGE - Value is out of allowed range -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_LLSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(Cy_BLE_LLS_ApplCallback != NULL) - { - if(cy_ble_llsConfigPtr->llss->alertLevelCharHandle == eventParam->handleValPair.attrHandle) - { - /* Check if attribute handle is handle of Alert Level characteristic of - * Link Loss service. */ - if((CY_BLE_HIGH_ALERT >= eventParam->handleValPair.value.val[0u])) - { - if(eventParam->handleValPair.value.len == CY_BLE_LLS_ALERT_LEVEL_SIZE) - { - /* Input parameters validation passed, so save Alert Level */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED, - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - /* Send callback to user if no error occurred while writing Alert Level */ - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_lls_char_value_t wrReqParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_LLS_ALERT_LEVEL, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_LLS_ApplCallback((uint32_t)CY_BLE_EVT_LLSS_WRITE_CHAR_REQ, (void*)&wrReqParam); - } - } - else - { - gattErr = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - } - else - { - gattErr = CY_BLE_GATT_ERR_OUT_OF_RANGE; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets an Alert Level characteristic value of the service, which is identified -* by charIndex. -* -* \param charIndex: The index of an Alert Level characteristic. -* \param attrSize: The size of the Alert Level characteristic value attribute. -* \param attrValue: The pointer to the location where an Alert Level characteristic -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LLSS_GetCharacteristicValue(cy_en_ble_lls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex == CY_BLE_LLS_ALERT_LEVEL) && (attrSize == CY_BLE_LLS_ALERT_LEVEL_SIZE)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_llsConfigPtr->llss->alertLevelCharHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Get Alert Level characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_LLS_SERVER) */ - - -#ifdef CY_BLE_LLS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_LLSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_LLS)) - { - if(discCharInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_ALERT_LEVEL) - { - /* Save Alert Level Characteristic handle */ - Cy_BLE_CheckStoreCharHandle(cy_ble_llsc[discIdx].alertLevelChar); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_LLSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_LLS) - { - /* LLS does not have any discriptions, return CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE */ - charRangeInfo->range.startHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - charRangeInfo->range.endHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param cy_stc_ble_gattc_read_rsp_param_t *eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_LLSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_LLS_ApplCallback != NULL) && - (cy_ble_llscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Fill Link Loss Service read response parameter structure */ - cy_stc_ble_lls_char_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_LLS_ALERT_LEVEL, - .value = &eventParam->value - }; - cy_ble_llscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LLS_ApplCallback((uint32_t)CY_BLE_EVT_LLSC_READ_CHAR_RESPONSE, &rdRspParam); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event for the Link Loss Service. -* -* \param cy_stc_ble_conn_handle_t *eventParam: The pointer to the connection handle. -* -******************************************************************************/ -static void Cy_BLE_LLSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_LLS_ApplCallback != NULL) && - (cy_ble_llsc[discIdx].alertLevelChar.valueHandle == cy_ble_llscReqHandle[discIdx]) && - (cy_ble_llscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_lls_char_value_t wrRspParam = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_LLS_ALERT_LEVEL, - .value = NULL - }; - cy_ble_llscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LLS_ApplCallback((uint32_t)CY_BLE_EVT_LLSC_WRITE_CHAR_RESPONSE, (void*)&wrRspParam); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event for the Link Loss Service. -* -* \param *eventParam: Pointer to the cy_stc_ble_gatt_err_param_t structure. -* -******************************************************************************/ -static void Cy_BLE_LLSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if(cy_ble_llscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_llscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_SetCharacteristicValue -***************************************************************************//** -* -* Sets the Alert Level characteristic value of the Link Loss Service, which is -* identified by charIndex. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_LLSS_WRITE_CHAR_REQ event is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the Alert Level service characteristic. -* \param attrSize: The size of the Alert Level characteristic value attribute. -* \param attrValue: The pointer to the Alert Level characteristic value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LLS service-specific callback is registered -* (with Cy_BLE_LLS_RegisterAttrCallback): -* * CY_BLE_EVT_LLSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_lls_char_value_t. -* . -* Otherwise (if the LLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LLSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lls_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && (charIndex == CY_BLE_LLS_ALERT_LEVEL) && - (attrSize == CY_BLE_LLS_ALERT_LEVEL_SIZE) && (*attrValue <= CY_BLE_HIGH_ALERT) && - (cy_ble_llsc[discIdx].alertLevelChar.valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Fill all fields of write command request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_llsc[discIdx].alertLevelChar.valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send request to write Alert Level characteristic value */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - cy_ble_llscReqHandle[discIdx] = cy_ble_llsc[discIdx].alertLevelChar.valueHandle; - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LLSC_GetCharacteristicValue -***************************************************************************//** -* -* Sends a request to get characteristic value of the Link Loss Service, which -* is identified by charIndex. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_LLSC_READ_CHAR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the Link Loss Service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LLS service-specific callback is registered -* (with Cy_BLE_LLS_RegisterAttrCallback): -* * CY_BLE_EVT_LLSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_lls_char_value_t. -* . -* Otherwise (if the LLS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LLSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lls_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex == CY_BLE_LLS_ALERT_LEVEL) && (discIdx < CY_BLE_CONFIG_GATTC_COUNT)) - { - /* Send request to write Alert Level characteristic value */ - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_llscReqHandle[discIdx], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - cy_ble_llscReqHandle[discIdx] = cy_ble_llsc[discIdx].alertLevelChar.valueHandle; - } - else - { - /* apiResult equals CY_BLE_ERROR_INVALID_PARAMETER */ - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_LLS_CLIENT) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_LLS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Link Loss Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_LLS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_LLS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_LLSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_LLSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_LLS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_LLS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_LLSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - - case CY_BLE_EVT_GATT_CONNECT_IND: - Cy_BLE_LLSS_ConnectEventHandler(); - break; - #endif /* CY_BLE_LLS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_LLS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_LLSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_LLSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_LLSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_LLS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_LLS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lls.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lls.h deleted file mode 100644 index 18fe476543..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lls.h +++ /dev/null @@ -1,145 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_lls.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in the Link -* Loss Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_LLS_H -#define CY_BLE_LLS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_LLS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_LLS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Link Loss Service Characteristic indexes */ -typedef enum -{ - CY_BLE_LLS_ALERT_LEVEL, /**< Alert Level Characteristic index */ - CY_BLE_LLS_CHAR_COUNT /**< Total count of characteristics */ -}cy_en_ble_lls_char_index_t; - -/** Link Loss Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_lls_char_index_t charIndex; /**< Characteristic index of Link Loss Service */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Link Loss Service characteristic */ -} cy_stc_ble_lls_char_value_t; - -/** Structure with Link Loss Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Link Loss Service handle*/ - cy_ble_gatt_db_attr_handle_t alertLevelCharHandle; /**< Handle of Alert Level Characteristic */ -} cy_stc_ble_llss_t; - -/** Structure with discovered attributes information of Link Loss Service */ -typedef struct -{ - cy_stc_ble_srvr_char_info_t alertLevelChar; /**< Handle of Alert Level Characteristic of Link Loss Service */ -} cy_stc_ble_llsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Link Loss Service GATT DB handles structure */ - const cy_stc_ble_llss_t *llss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_lls_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_LLS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_LLS_Init(cy_stc_ble_lls_config_t *config); -cy_en_ble_api_result_t Cy_BLE_LLS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_LLS_SERVER -/** - * \addtogroup group_ble_service_api_LLS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_LLSS_GetCharacteristicValue(cy_en_ble_lls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* (CY_BLE_LLS_SERVER) */ - -#ifdef CY_BLE_LLS_CLIENT -/** - * \addtogroup group_ble_service_api_LLS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_LLSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lls_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LLSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lls_char_index_t charIndex); - -/** @} */ -#endif /* (CY_BLE_LLS_CLIENT) */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_LLS_ALERT_LEVEL_SIZE (1u) - - -/*************************************** -* Variables with external linkage -***************************************/ -#ifdef CY_BLE_LLS_CLIENT -extern cy_stc_ble_llsc_t cy_ble_llsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_LLS_CLIENT) */ - -extern cy_stc_ble_lls_config_t cy_ble_llsConfig; -extern cy_stc_ble_lls_config_t *cy_ble_llsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_LLS) */ -#endif /* CY_BLE_LLS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lns.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lns.c deleted file mode 100644 index 5f6e5a80f8..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lns.c +++ /dev/null @@ -1,1566 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_lns.c -* \version 2.0 -* -* \brief -* This file contains the source code for -* the Location and Navigation Service of the Location and Navigation Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_LNS)) - -static cy_ble_callback_t Cy_BLE_LNS_ApplCallback; - -#ifdef CY_BLE_LNS_SERVER -uint8_t cy_ble_lnsFlag; - -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_lnssReqHandle; -#endif /* CY_BLE_LNS_SERVER */ - -#ifdef CY_BLE_LNS_CLIENT -/* Server's Location and Navigation Service characteristics GATT DB handles structure */ -cy_stc_ble_lnsc_t cy_ble_lnsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check the response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_lnscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_LNS_CLIENT */ - -/* The pointer on global BLE LNS Config structure */ -cy_stc_ble_lns_config_t *cy_ble_lnsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_LNS_SERVER -static void Cy_BLE_LNSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_LNSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_LNS_SERVER */ - -#ifdef CY_BLE_LNS_CLIENT -static void Cy_BLE_LNSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_LNSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo); -static void Cy_BLE_LNSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_LNSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_LNSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_LNSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_LNSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_LNSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_LNS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_LNS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_LNS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for the Location and Navigation Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNS_Init(cy_stc_ble_lns_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_lnsConfigPtr = config; - - /* Registers Event Handler for the LNS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_LNS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_lnsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_LNS_ApplCallback = cy_ble_lnsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_LNS_SERVER - cy_ble_lnsFlag = 0u; - cy_ble_lnssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_LNS_SERVER */ - - #ifdef CY_BLE_LNS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_LNS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_lnsc[idx], 0, sizeof(cy_stc_ble_lnsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_LNS].uuid = CY_BLE_UUID_LOCATION_AND_NAVIGATION_SERVICE; - } - cy_ble_lnscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_LNS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for LNS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise this -* data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_LNS_ApplCallback = callbackFunc; - if(cy_ble_lnsConfigPtr != NULL) - { - cy_ble_lnsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_LNS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the value of the characteristic, as identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSS_SetCharacteristicValue(cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_LNS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - /* Store characteristic value into GATT database */ - .handleValuePair.attrHandle = cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the value of the characteristic, as identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Characteristic value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSS_GetCharacteristicValue(cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_LNS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - /* Get characteristic value from GATT database */ - .handleValuePair.attrHandle = cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Characteristic Descriptor value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - cy_en_ble_lns_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if((charIndex >= CY_BLE_LNS_CHAR_COUNT) || (descrIndex >= CY_BLE_LNS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(((charIndex == CY_BLE_LNS_CP) && (!CY_BLE_LNS_IS_CP_SUPPORTED)) || - ((charIndex == CY_BLE_LNS_NV) && (!CY_BLE_LNS_IS_NV_SUPPORTED))) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - /* Get data from database */ - .handleValuePair.attrHandle = cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified characteristic value, as identified by -* the charIndex. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_LNSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be sent -* to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_LNS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].descrHandle[CY_BLE_LNS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_lnsConfigPtr->lnss->charInfo[charIndex]. - descrHandle[CY_BLE_LNS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_SendIndication -***************************************************************************//** -* -* Sends an indication of the specified characteristic value, as identified by -* the charIndex. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_LNSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be sent -* to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client -* * CY_BLE_ERROR_IND_DISABLED - Indication is disabled for this characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LNS service-specific callback is registered -* (with Cy_BLE_LNS_RegisterAttrCallback): -* * CY_BLE_EVT_LNSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the LNS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_LNS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].descrHandle[CY_BLE_LNS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_lnsConfigPtr->lnss->charInfo[charIndex]. - descrHandle[CY_BLE_LNS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ind_t indParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_lnsConfigPtr->lnss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indParam); - - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific value confirmation response from client */ - cy_ble_lnssReqHandle = indParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles the Value Confirmation request event from the BLE stack. -* -* \param eventParam: Pointer to a structure of type cy_stc_ble_conn_handle_t -* -******************************************************************************/ -static void Cy_BLE_LNSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_LNS_ApplCallback != NULL) && (cy_ble_lnsConfigPtr->lnss->charInfo[CY_BLE_LNS_CP].charHandle == - cy_ble_lnssReqHandle)) - { - cy_stc_ble_lns_char_value_t locCharIndex = { .connHandle = *eventParam }; - - cy_ble_lnssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_lnsFlag &= (uint8_t) ~CY_BLE_LNS_FLAG_PROCESS; - - locCharIndex.charIndex = CY_BLE_LNS_CP; - locCharIndex.value = NULL; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSS_INDICATION_CONFIRMED, &locCharIndex); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_LNSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_lns_char_value_t locCharValue; - - if(Cy_BLE_LNS_ApplCallback != NULL) - { - locCharValue.connHandle = eventParam->connHandle; - - if(eventParam->handleValPair.attrHandle == cy_ble_lnsConfigPtr->lnss->charInfo[CY_BLE_LNS_CP].charHandle) - { - if(CY_BLE_LNS_IS_PROCEDURE_IN_PROGRESS) - { - gattErr = CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_lnsConfigPtr->lnss->charInfo[CY_BLE_LNS_CP]. - descrHandle[CY_BLE_LNS_CCCD])) - { - gattErr = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - locCharValue.charIndex = CY_BLE_LNS_CP; - locCharValue.value = &eventParam->handleValPair.value; - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSS_WRITE_CHAR, &locCharValue); - cy_ble_lnsFlag |= CY_BLE_LNS_FLAG_PROCESS; - } - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - for(locCharValue.charIndex = CY_BLE_LNS_LS; locCharValue.charIndex < CY_BLE_LNS_CHAR_COUNT; - locCharValue.charIndex++) - { - if(locCharValue.charIndex == CY_BLE_LNS_PQ) - { - locCharValue.charIndex++; - } - - if(eventParam->handleValPair.attrHandle == cy_ble_lnsConfigPtr->lnss->charInfo[locCharValue.charIndex]. - descrHandle[CY_BLE_LNS_CCCD]) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - locCharValue.value = NULL; - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - uint32_t eventCode; - - if(locCharValue.charIndex == CY_BLE_LNS_CP) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_LNSS_INDICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_LNSS_INDICATION_DISABLED; - } - } - else - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_LNSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_LNSS_NOTIFICATION_DISABLED; - } - } - - Cy_BLE_LNS_ApplCallback(eventCode, &locCharValue); - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - - return(gattErr); -} - - -#endif /* CY_BLE_LNS_SERVER */ - -#ifdef CY_BLE_LNS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_LNSS_WRITE_CHAR event is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LNS service-specific callback is registered -* (with Cy_BLE_LNS_RegisterAttrCallback): -* * CY_BLE_EVT_LNSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_lns_char_value_t. -* . -* Otherwise (if the LNS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_LNS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_lnsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_lnsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_lnscReqHandle[discIdx] = cy_ble_lnsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server, -* as identified by its charIndex -* -* The Read Response returns the characteristic Value in the Attribute Value -* parameter. -* -* The Read Response only contains the characteristic Value that is less than or -* equal to (MTU - 1) octets in length. If the characteristic Value is greater -* than (MTU - 1) octets in length, the Read Long Characteristic Value procedure -* may be used if the rest of the characteristic Value is required. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LNS service-specific callback is registered -* (with Cy_BLE_LNS_RegisterAttrCallback): -* * CY_BLE_EVT_LNSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_lns_char_value_t. -* . -* Otherwise (if the LNS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_LNS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_lnsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_lnsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle, - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_lnscReqHandle[discIdx] = cy_ble_lnsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic Value to the server, -* as identified by its charIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_LNSS_INDICATION_ENABLED -* * CY_BLE_EVT_LNSS_INDICATION_DISABLED -* * CY_BLE_EVT_LNSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_LNSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LNS service-specific callback is registered -* (with Cy_BLE_LNS_RegisterAttrCallback): -* * CY_BLE_EVT_LNSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_lns_descr_value_t. -* . -* Otherwise (if the LNS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - cy_en_ble_lns_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_LNS_CHAR_COUNT) || (descrIndex >= CY_BLE_LNS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_lnsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific read response from device */ - cy_ble_lnscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the LNS service-specific callback is registered -* (with Cy_BLE_LNS_RegisterAttrCallback): -* * CY_BLE_EVT_LNSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_lns_descr_value_t. -* . -* Otherwise (if the LNS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_LNSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - cy_en_ble_lns_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_LNS_CHAR_COUNT) || (descrIndex >= CY_BLE_LNS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_lnsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_lnsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_lnscReqHandle[discIdx] = cy_ble_lnsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_LNSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* Location and Navigation Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_lnscCharUuid[CY_BLE_LNS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_LN_FEATURE, - CY_BLE_UUID_CHAR_LOCATION_AND_SPEED, - CY_BLE_UUID_CHAR_POSITION_QUALITY, - CY_BLE_UUID_CHAR_LN_CONTROL_POINT, - CY_BLE_UUID_CHAR_NAVIGATION - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_LNS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_LNS_CHAR_COUNT; i++) - { - if(cy_ble_lnscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_lnsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_lnsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_lnsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_lnsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_LNS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_LNSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_LNS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_LNS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_lnsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_lnsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_LNSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_LNS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_LNS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_lnsc[discIdx].charInfo[charIdx].endHandle - cy_ble_lnsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_lnsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_lnsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_LNSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_LNS_ApplCallback != NULL)) - { - cy_stc_ble_lns_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - - if(cy_ble_lnsc[discIdx].charInfo[CY_BLE_LNS_LS].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_LNS_LS; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else if(cy_ble_lnsc[discIdx].charInfo[CY_BLE_LNS_NV].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_LNS_NV; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* Location and Navigation Service doesn't support any other notifications */ - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locCharValue.value = &eventParam->handleValPair.value; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSC_NOTIFICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_IndicationEventHandler -***************************************************************************//** -* -* Handles the Indication Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_LNSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_LNS_ApplCallback != NULL)) - { - if(cy_ble_lnsc[discIdx].charInfo[CY_BLE_LNS_CP].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_lns_char_value_t locCharValue = - { - .charIndex = CY_BLE_LNS_CP, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSC_INDICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam: the pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_LNSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_LNS_ApplCallback != NULL) && - (cy_ble_lnscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_lns_char_index_t i; - - for(i = CY_BLE_LNS_FT; i < CY_BLE_LNS_CHAR_COUNT; i++) - { - if(cy_ble_lnsc[discIdx].charInfo[i].valueHandle == cy_ble_lnscReqHandle[discIdx]) - { - cy_stc_ble_lns_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = i, - .value = &eventParam->value - }; - - cy_ble_lnscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSC_READ_CHAR_RESPONSE, &locCharValue); - } - } - - if(0u != (cy_ble_eventHandlerFlag | CY_BLE_CALLBACK)) - { - for(i = CY_BLE_LNS_FT; i < CY_BLE_LNS_CHAR_COUNT; i++) - { - if(cy_ble_lnsc[discIdx].charInfo[i].descrHandle[CY_BLE_LNS_CCCD] == cy_ble_lnscReqHandle[discIdx]) - { - cy_stc_ble_lns_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = i, - .descrIndex = CY_BLE_LNS_CCCD, - .value = &eventParam->value - }; - - cy_ble_lnscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSC_READ_DESCR_RESPONSE, &locDescrValue); - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_LNSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_LNS_ApplCallback != NULL) && - (cy_ble_lnscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_lnsc[discIdx].charInfo[CY_BLE_LNS_CP].valueHandle == cy_ble_lnscReqHandle[discIdx]) - { - cy_stc_ble_lns_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_LNS_CP, - .value = NULL - }; - - cy_ble_lnscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSC_WRITE_CHAR_RESPONSE, &locCharIndex); - } - else - { - cy_en_ble_lns_char_index_t i; - - for(i = CY_BLE_LNS_FT; i < CY_BLE_LNS_CHAR_COUNT; i++) - { - if(cy_ble_lnsc[discIdx].charInfo[i].descrHandle[CY_BLE_LNS_CCCD] == cy_ble_lnscReqHandle[discIdx]) - { - cy_stc_ble_lns_descr_value_t locDescIndex = - { - .connHandle = *eventParam, - .charIndex = i, - .descrIndex = CY_BLE_LNS_CCCD, - .value = NULL - }; - - cy_ble_lnscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_LNS_ApplCallback((uint32_t)CY_BLE_EVT_LNSC_WRITE_DESCR_RESPONSE, &locDescIndex); - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_LNSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: Pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_LNSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_lnscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_lnscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* CY_BLE_LNS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_LNS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Location and Navigation Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_LNS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_LNS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_LNSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_LNSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_LNSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_LNS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_LNS_SERVER - case CY_BLE_EVT_GATT_DISCONNECT_IND: - (void)Cy_BLE_LNS_Init(cy_ble_lnsConfigPtr); - break; - - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_LNSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - if(eventParam != NULL) - { - Cy_BLE_LNSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - } - break; - #endif /* CY_BLE_LNS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_LNS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_LNSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_LNSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_LNSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_LNSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_LNSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_LNS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} -#endif /* defined(CY_BLE_LNS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lns.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lns.h deleted file mode 100644 index ff04b109e0..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_lns.h +++ /dev/null @@ -1,248 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_lns.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Location And Navigation Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_LNS_H -#define CY_BLE_LNS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_LNS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define CY_BLE_LNS_FLAG_PROCESS (0x01u) - -/** - * \addtogroup group_ble_service_api_LNS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** LNS Service Characteristics indexes */ -typedef enum -{ - CY_BLE_LNS_FT, /**< Location and Navigation Feature characteristic index */ - CY_BLE_LNS_LS, /**< Location and Speed characteristic index */ - CY_BLE_LNS_PQ, /**< Position Quality characteristic index */ - CY_BLE_LNS_CP, /**< Location and Navigation Control Point characteristic index */ - CY_BLE_LNS_NV, /**< Navigation characteristic index */ - CY_BLE_LNS_CHAR_COUNT /**< Total count of LNS characteristics */ -}cy_en_ble_lns_char_index_t; - -/** LNS Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_LNS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_LNS_DESCR_COUNT /**< Total count of LNS descriptors */ -}cy_en_ble_lns_descr_index_t; - -/** Location and Navigation Server Characteristic structure type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_LNS_DESCR_COUNT]; /**< Handle of descriptor */ -}cy_stc_ble_lnss_char_t; - -/** Structure with Location and Navigation Service attribute handles */ -typedef struct -{ - /** Location and Navigation Service handle*/ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Location and Navigation Service characteristics info array */ - cy_stc_ble_lnss_char_t charInfo[CY_BLE_LNS_CHAR_COUNT]; -} cy_stc_ble_lnss_t; - -/** Location and Navigation Client Characteristic structure type */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** Location and Navigation client char. descriptor handle */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_LNS_DESCR_COUNT]; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_lnsc_char_t; - -/** Structure with discovered attributes information of Location and Navigation Service */ -typedef struct -{ - cy_stc_ble_lnsc_char_t charInfo[CY_BLE_LNS_CHAR_COUNT]; /**< Characteristics handle + properties array */ -}cy_stc_ble_lnsc_t; - -/** LNS Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_lns_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_lns_char_value_t; - -/** LNS Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_lns_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_lns_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_lns_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Location and Navigation GATT DB handles structure */ - const cy_stc_ble_lnss_t *lnss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_lns_config_t; - -/** @} -** Service configuration structure -*/ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_LNS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_LNS_Init(cy_stc_ble_lns_config_t *config); -cy_en_ble_api_result_t Cy_BLE_LNS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_LNS_SERVER -/** - * \addtogroup group_ble_service_api_LNS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_LNSS_SetCharacteristicValue(cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LNSS_GetCharacteristicValue(cy_en_ble_lns_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LNSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - cy_en_ble_lns_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LNSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LNSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_LNS_SERVER */ - -#ifdef CY_BLE_LNS_CLIENT -/** - * \addtogroup group_ble_service_api_LNS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_LNSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LNSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_LNSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - cy_en_ble_lns_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_LNSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_lns_char_index_t charIndex, - cy_en_ble_lns_descr_index_t descrIndex); -/** @} */ -#endif /* CY_BLE_LNS_CLIENT */ - - -/* Internal macros */ -#ifdef CY_BLE_LNS_SERVER -#define CY_BLE_LNS_IS_PQ_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_lnsConfigPtr->lnss->charInfo[CY_BLE_LNS_PQ].charHandle) - -#define CY_BLE_LNS_IS_CP_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_lnsConfigPtr->lnss->charInfo[CY_BLE_LNS_CP].charHandle) - -#define CY_BLE_LNS_IS_NV_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_lnsConfigPtr->lnss->charInfo[CY_BLE_LNS_NV].charHandle) - -#define CY_BLE_LNS_IS_PROCEDURE_IN_PROGRESS \ - (0u != (CY_BLE_LNS_FLAG_PROCESS & cy_ble_lnsFlag)) -#endif /* CY_BLE_LNS_SERVER */ - - -#ifdef CY_BLE_LNS_CLIENT -#define Cy_BLE_LNSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_LNS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_lnsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_LNSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_LNS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_LNS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_lnsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].descrHandle[descrIndex]) -#endif /* (CY_BLE_LNS_CLIENT) */ - -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_LNS_SERVER -/* Location and Navigation Service GATT DB handles structure */ -extern uint8_t cy_ble_lnsFlag; -#endif /* CY_BLE_LNSC_SERVER */ - -#ifdef CY_BLE_LNS_CLIENT -/* Location and Navigation Service server's GATT DB handles structure */ -extern cy_stc_ble_lnsc_t cy_ble_lnsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_LNS_CLIENT */ - -extern cy_stc_ble_lns_config_t cy_ble_lnsConfig; -extern cy_stc_ble_lns_config_t *cy_ble_lnsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_LNS) */ -#endif /* CY_BLE_LNS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ndcs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ndcs.c deleted file mode 100644 index 319b5f3b32..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ndcs.c +++ /dev/null @@ -1,504 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ndcs.c -* \version 2.0 -* -* \brief -* Contains the source code for Next DST Change Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_NDCS)) - -#ifdef CY_BLE_NDCS_CLIENT -static cy_ble_callback_t Cy_BLE_NDCS_ApplCallback = NULL; - -/* NDCS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_ndcsc_t cy_ble_ndcsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_ndcscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_NDCS_CLIENT) */ - -/* The pointer on global BLE NDCS Config structure */ -cy_stc_ble_ndcs_config_t *cy_ble_ndcsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#if defined(CY_BLE_NDCS_CLIENT) -static void Cy_BLE_NDCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_NDCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_NDCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -#endif /* (CY_BLE_NDCS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_NDCS_EventHandler(uint32_t eventCode, void *eventParam); - - -/******************************************************************************* -* Function Name: Cy_BLE_NDCS_Init -****************************************************************************//** -* -* This function initializes the Next DST Change Service. -* -* \param config: Configuration structure for the Next DST Change Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_NDCS_Init(cy_stc_ble_ndcs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_ndcsConfigPtr = config; - - /* Registers Event Handler for the ANCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_NDCS_EventHandler); - - #ifdef CY_BLE_NDCS_CLIENT - /* Registers a callback function via config structure */ - if(cy_ble_ndcsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_NDCS_ApplCallback = cy_ble_ndcsConfigPtr->callbackFunc; - } - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_NDCS].range.startHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_ndcsc[idx], 0, sizeof(cy_stc_ble_ndcsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_NDCS].uuid = CY_BLE_UUID_NEXT_DST_CHANGE_SERVICE; - } - cy_ble_ndcscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_NDCS_CLIENT */ - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_NDCS_RegisterAttrCallback -****************************************************************************//** -* -* Registers a callback function for Next DST Change Service specific attribute -* operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for NDCS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_NDCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - -#ifdef CY_BLE_NDCS_CLIENT - Cy_BLE_NDCS_ApplCallback = callbackFunc; - if(cy_ble_ndcsConfigPtr != NULL) - { - cy_ble_ndcsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } -#endif /* CY_BLE_NDCS_CLIENT */ - - return(apiResult); -} - -#if defined(CY_BLE_NDCS_SERVER) - -/******************************************************************************* -* Function Name: Cy_BLE_NDCSS_SetCharacteristicValue -****************************************************************************//** -* -* Sets characteristic value of the Next DST Change Service, which is identified -* by charIndex in the local database. -* -* \param charIndex: The index of a service characteristic of type cy_en_ble_ndcs_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request is handled successfully; -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameters failed. -* -*/ -cy_en_ble_api_result_t Cy_BLE_NDCSS_SetCharacteristicValue(cy_en_ble_ndcs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex == CY_BLE_NDCS_TIME_WITH_DST) - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ndcsConfigPtr->ndcss->timeWithDst, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_NDCSS_GetCharacteristicValue -****************************************************************************//** -* -* Gets a characteristic value of the Next DST Change Service, which is -* identified by charIndex. -* -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_ndcs_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the location where -* characteristic value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request is handled successfully; -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameter failed. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_NDCSS_GetCharacteristicValue(cy_en_ble_ndcs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex == CY_BLE_NDCS_TIME_WITH_DST) - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_ndcsConfigPtr->ndcss->timeWithDst, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED, - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - -#endif /* CY_BLE_NDCS_SERVER */ - - -#if defined(CY_BLE_NDCS_CLIENT) - -/******************************************************************************* -* Function Name: Cy_BLE_NDCSC_DiscoverCharacteristicsEventHandler -****************************************************************************//** -* -* This function is called on receiving the CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -* -*******************************************************************************/ -static void Cy_BLE_NDCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_NDCS)) - { - if(discCharInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_TIME_WITH_DST) - { - /* Using characteristic UUID store handle of requested characteristic */ - if(cy_ble_ndcsc[discIdx].charInfo[CY_BLE_NDCS_TIME_WITH_DST].valueHandle == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_ndcsc[discIdx].charInfo[CY_BLE_NDCS_TIME_WITH_DST].valueHandle = discCharInfo->valueHandle; - cy_ble_ndcsc[discIdx].charInfo[CY_BLE_NDCS_TIME_WITH_DST].properties = discCharInfo->properties; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_NDCSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_NDCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_NDCS) - { - /* NDCS does not have any discriptions, return CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE */ - charRangeInfo->range.startHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - charRangeInfo->range.endHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_NDCSC_ReadResponseEventHandler -****************************************************************************//** -* -* Handles Read Response Event for Next DST Change Service. -* -* \param eventParam: The pointer to the data that came with a read response for NDCS. -* -*******************************************************************************/ -static void Cy_BLE_NDCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_NDCS_ApplCallback != NULL) && - (cy_ble_ndcscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_ndcsc[discIdx].charInfo[CY_BLE_NDCS_TIME_WITH_DST].valueHandle == cy_ble_ndcscReqHandle[discIdx]) - { - /* Fill Reference Time Update Service read response parameter structure with - * characteristic info. - */ - cy_stc_ble_ndcs_char_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_NDCS_TIME_WITH_DST, - .value = &eventParam->value - }; - - Cy_BLE_NDCS_ApplCallback((uint32_t)CY_BLE_EVT_NDCSC_READ_CHAR_RESPONSE, (void*)&rdRspParam); - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_ndcscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_NDCSC_GetCharacteristicValue -****************************************************************************//** -* -* Sends a request to peer device to set characteristic value of the Next -* DST Change Service, which is identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request was sent successfully. -* * CY_BLE_ERROR_INVALID_STATE - connection with the client is not established. -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the NDCS service-specific callback is registered -* (with Cy_BLE_NDCS_RegisterAttrCallback): -* * CY_BLE_EVT_NDCSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_ndcs_char_value_t. -* . -* Otherwise (if the NDCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_NDCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ndcs_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex == CY_BLE_NDCS_TIME_WITH_DST) && (discIdx < CY_BLE_CONFIG_GATTC_COUNT)) - { - /* Send request to read characteristic value */ - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_ndcsc[discIdx].charInfo[CY_BLE_NDCS_TIME_WITH_DST].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_ndcscReqHandle[discIdx] = cy_ble_ndcsc[discIdx].charInfo[CY_BLE_NDCS_TIME_WITH_DST].valueHandle; - } - } - else - { - /* apiResult equals to CY_BLE_ERROR_INVALID_PARAMETER */ - } - - return(apiResult); -} - -#endif /* CY_BLE_NDCS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_NDCS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Next DST Change Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_NDCS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_NDCS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_NDCSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_NDCSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_NDCS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_NDCS_CLIENT - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_NDCSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - #endif /* CY_BLE_NDCS_CLIENT */ - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_NDCS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ndcs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ndcs.h deleted file mode 100644 index 59ed696272..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_ndcs.h +++ /dev/null @@ -1,142 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_ndcs.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Next DST Change -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_NDCS_H -#define CY_BLE_NDCS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_NDCS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include "cy_ble_gatt.h" - -/** - * \addtogroup group_ble_service_api_NDCS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Characteristic indexes */ -typedef enum -{ - CY_BLE_NDCS_TIME_WITH_DST, /**< Time with DST Characteristic index */ - CY_BLE_NDCS_CHAR_COUNT /**< Total count of NDCS Characteristics */ -} cy_en_ble_ndcs_char_index_t; - -/** Next DST Change Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_ndcs_char_index_t charIndex; /**< Index of Next DST Change Service Characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_ndcs_char_value_t; - -/** Structure with Device Information Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Handle of the Next DST Change Service */ - cy_ble_gatt_db_attr_handle_t timeWithDst; /**< Handle of the Time with DST Characteristic */ -} cy_stc_ble_ndcss_t; - -/** Structure with discovered attributes information of Next DST Change Service */ -typedef struct -{ - /** Characteristic handle and properties */ - cy_stc_ble_srvr_char_info_t charInfo[CY_BLE_NDCS_CHAR_COUNT]; -} cy_stc_ble_ndcsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Next DST Change Service GATT DB handles structure */ - const cy_stc_ble_ndcss_t *ndcss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_ndcs_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_NDCS_server_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_NDCS_Init(cy_stc_ble_ndcs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_NDCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); - -/** @} */ - -#if defined(CY_BLE_NDCS_SERVER) -/** - * \addtogroup group_ble_service_api_NDCS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_NDCSS_SetCharacteristicValue(cy_en_ble_ndcs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_NDCSS_GetCharacteristicValue(cy_en_ble_ndcs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_NDCS_SERVER */ - -#if defined(CY_BLE_NDCS_CLIENT) -/** - * \addtogroup group_ble_service_api_NDCS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_NDCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_ndcs_char_index_t charIndex); - -/** @} */ -#endif /* (CY_BLE_NDCS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#if defined(CY_BLE_NDCS_CLIENT) -extern cy_stc_ble_ndcsc_t cy_ble_ndcsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_NDCS_CLIENT) */ - -extern cy_stc_ble_ndcs_config_t cy_ble_ndcsConfig; -extern cy_stc_ble_ndcs_config_t *cy_ble_ndcsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_NDCS) */ -#endif /* CY_BLE_NDCS_H */ - - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_pass.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_pass.c deleted file mode 100644 index a30277487d..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_pass.c +++ /dev/null @@ -1,1335 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_pass.c -* \version 2.0 -* -* \brief -* This file contains the source code for -* the Phone Alert Status Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_PASS)) - -static cy_ble_callback_t Cy_BLE_PASS_ApplCallback; - -#ifdef CY_BLE_PASS_SERVER -uint8_t cy_ble_passFlag; -#endif /* CY_BLE_PASS_SERVER */ - -#ifdef CY_BLE_PASS_CLIENT -/* Server's Phone Alert Status Service characteristics GATT DB handles structure */ -cy_stc_ble_passc_t cy_ble_passc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check the response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_passcReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_PASS_CLIENT */ - -/* The pointer on global BLE PASS Config structure */ -cy_stc_ble_pass_config_t *cy_ble_passConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_PASS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_PASSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_PASSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_PASS_SERVER */ - -#ifdef CY_BLE_PASS_CLIENT -static void Cy_BLE_PASSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_PASSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_PASSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_PASSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_PASSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_PASSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_PASSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_PASS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_PASS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_PASS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for Phone Alert Status Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASS_Init(cy_stc_ble_pass_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_passConfigPtr = config; - - /* Registers Event Handler for the PASS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_PASS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_passConfigPtr->callbackFunc != NULL) - { - Cy_BLE_PASS_ApplCallback = cy_ble_passConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_PASS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_PASS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_passc[idx], 0, sizeof(cy_stc_ble_passc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_PASS].uuid = CY_BLE_UUID_PHONE_ALERT_STATUS_SERVICE; - } - cy_ble_passcReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_GATT_ROLE_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for PASS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_PASS_ApplCallback = callbackFunc; - if(cy_ble_passConfigPtr != NULL) - { - cy_ble_passConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_PASS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the value of a characteristic which is identified by charIndex. -* -* \param charIndex: the index of a service characteristic. -* \param attrSize: the size of the characteristic value attribute. -* \param attrValue: the pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSS_SetCharacteristicValue(cy_en_ble_pass_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - - /* Check the parameters */ - if(charIndex >= CY_BLE_PASS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passConfigPtr->passs->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_passConfigPtr->passs->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the value of a characteristic which is identified by charIndex. -* -* \param charIndex: the index of a service characteristic. -* \param attrSize: the size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSS_GetCharacteristicValue(cy_en_ble_pass_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_PASS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passConfigPtr->passs->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_passConfigPtr->passs->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param attrValue: The pointer to the descriptor value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - cy_en_ble_pass_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if((charIndex >= CY_BLE_PASS_CHAR_COUNT) || (descrIndex >= CY_BLE_PASS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passConfigPtr->passs->charInfo[charIndex].descrHandle[descrIndex] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_passConfigPtr->passs->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified by the charIndex characteristic value. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_PASSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle -* which consists of the device ID and ATT connection ID. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should -* be sent to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the Client -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_PASS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(charIndex > CY_BLE_PASS_RS) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if(cy_ble_passConfigPtr->passs->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, - cy_ble_passConfigPtr->passs->charInfo[charIndex].descrHandle[CY_BLE_PASS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfParam = - { - .handleValPair.attrHandle = cy_ble_passConfigPtr->passs->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to the Client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_PASSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(Cy_BLE_PASS_ApplCallback != NULL) - { - cy_stc_ble_pass_char_value_t locCharIndex; - - for(locCharIndex.charIndex = CY_BLE_PASS_AS; - locCharIndex.charIndex < CY_BLE_PASS_CP; locCharIndex.charIndex++) - { - if(eventParam->handleValPair.attrHandle == cy_ble_passConfigPtr->passs->charInfo[locCharIndex.charIndex]. - descrHandle[CY_BLE_PASS_CCCD]) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - locCharIndex.connHandle = eventParam->connHandle; - locCharIndex.value = NULL; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSS_NOTIFICATION_ENABLED, &locCharIndex); - } - else - { - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSS_NOTIFICATION_DISABLED, &locCharIndex); - } - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSS_WriteCmdEventHandler -***************************************************************************//** -* -* Handles the Write Without Response Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PASSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - if((Cy_BLE_PASS_ApplCallback != NULL) && - (eventParam->handleValPair.attrHandle == cy_ble_passConfigPtr->passs->charInfo[CY_BLE_PASS_CP].charHandle)) - { - cy_en_ble_gatt_err_code_t gattErr; - cy_stc_ble_pass_char_value_t locCharValue = - { - .charIndex = CY_BLE_PASS_CP, - .value = &eventParam->handleValPair.value - }; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSS_WRITE_CHAR, &locCharValue); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -#endif /* CY_BLE_PASS_SERVER */ - -#ifdef CY_BLE_PASS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_PASSS_WRITE_CHAR event is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* \events -* * CY_BLE_EVT_GATTC_WRITE_RSP - The requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - There is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PASS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE_WITHOUT_RSP & cy_ble_passc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_cmd_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_passc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_passcReqHandle[discIdx] = cy_ble_passc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a Server -* which is identified by the charIndex. -* -* The Read Response returns the characteristic Value in the Attribute Value -* parameter. -* -* The Read Response only contains the characteristic Value that is less than or -* equal to (MTU - 1) octets in length. If the characteristic Value is greater -* than (MTU - 1) octets in length, the Read Long Characteristic Value procedure -* may be used if the rest of the characteristic Value is required. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PASS service-specific callback is registered -* (with Cy_BLE_PASS_RegisterAttrCallback): -* * CY_BLE_EVT_PASSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_pass_char_value_t. -* . -* Otherwise (if the PASS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PASS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_passc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_passc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_passcReqHandle[discIdx] = cy_ble_passc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic Value to the server -* which is identified by the charIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_PASSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_PASSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PASS service-specific callback is registered -* (with Cy_BLE_PASS_RegisterAttrCallback): -* * CY_BLE_EVT_PASSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_pass_descr_value_t. -* . -* Otherwise (if the PASS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - cy_en_ble_pass_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PASS_CHAR_COUNT) || (descrIndex >= CY_BLE_PASS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_passc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle, - }; - /* ... and send request to Server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific read response from device */ - cy_ble_passcReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* -* \return -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PASS service-specific callback is registered -* (with Cy_BLE_PASS_RegisterAttrCallback): -* * CY_BLE_EVT_PASSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_pass_descr_value_t. -* . -* Otherwise (if the PASS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PASSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - cy_en_ble_pass_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PASS_CHAR_COUNT) || (descrIndex >= CY_BLE_PASS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_passc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_passc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_passcReqHandle[discIdx] = cy_ble_passc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP" -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: the pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_PASSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* Phone Alert Status Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_passcCharUuid[CY_BLE_PASS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_ALERT_STATUS, - CY_BLE_UUID_CHAR_RINGER_SETTING, - CY_BLE_UUID_CHAR_RINGER_CONTROL_POINT - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_PASS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_PASS_CHAR_COUNT; i++) - { - if(cy_ble_passcCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_passc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_passc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_passc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_passc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_PASS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP" -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_PASSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_PASS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_PASS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_passc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_passc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_PASSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_PASS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_PASS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_passc[discIdx].charInfo[charIdx].endHandle - - cy_ble_passc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_passc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_passc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PASSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PASS_ApplCallback != NULL)) - { - cy_stc_ble_pass_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - for(locCharValue.charIndex = CY_BLE_PASS_AS; locCharValue.charIndex < CY_BLE_PASS_CP; locCharValue.charIndex++) - { - if(cy_ble_passc[discIdx].charInfo[locCharValue.charIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSC_NOTIFICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_PASSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PASS_ApplCallback != NULL) && - (cy_ble_passcReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_pass_char_index_t locCharIndex; - - for(locCharIndex = CY_BLE_PASS_AS; locCharIndex < CY_BLE_PASS_CP; locCharIndex++) - { - if(cy_ble_passc[discIdx].charInfo[locCharIndex].valueHandle == cy_ble_passcReqHandle[discIdx]) - { - cy_stc_ble_pass_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - cy_ble_passcReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSC_READ_CHAR_RESPONSE, &locCharValue); - } - else if(cy_ble_passc[discIdx].charInfo[locCharIndex].descrHandle[CY_BLE_PASS_CCCD] == - cy_ble_passcReqHandle[discIdx]) - { - cy_stc_ble_pass_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = CY_BLE_PASS_CCCD, - .value = &eventParam->value - }; - - cy_ble_passcReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSC_READ_DESCR_RESPONSE, &locDescrValue); - } - else - { - } - - if(cy_ble_passcReqHandle[discIdx] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PASSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PASS_ApplCallback != NULL) && - (cy_ble_passcReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_pass_char_index_t locCharIndex; - - for(locCharIndex = CY_BLE_PASS_AS; locCharIndex < CY_BLE_PASS_CP; locCharIndex++) - { - if(cy_ble_passc[discIdx].charInfo[locCharIndex].descrHandle[CY_BLE_PASS_CCCD] == - cy_ble_passcReqHandle[discIdx]) - { - cy_stc_ble_pass_descr_value_t locDescValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .descrIndex = CY_BLE_PASS_CCCD, - .value = NULL - }; - cy_ble_passcReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PASS_ApplCallback((uint32_t)CY_BLE_EVT_PASSC_WRITE_DESCR_RESPONSE, &locDescValue); - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PASSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: Pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PASSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_passcReqHandle[discIdx]) - { - cy_ble_passcReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -#endif /* CY_BLE_PASS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_PASS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Phone Alert Status Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_PASS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_PASS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_PASSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_PASSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_PASSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_PASS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_PASS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_PASSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - Cy_BLE_PASSS_WriteCmdEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_PASS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_PASS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_PASSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_PASSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_PASSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_PASSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_PASS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_PASS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_pass.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_pass.h deleted file mode 100644 index 3281950e8e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_pass.h +++ /dev/null @@ -1,249 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_pass.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the Phone Alert Status Profile of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_PASS_H -#define CY_BLE_PASS_H - - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_PASS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_PASS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Service Characteristics indexes */ -typedef enum -{ - CY_BLE_PASS_AS, /**< Alert Status characteristic index */ - CY_BLE_PASS_RS, /**< Ringer Setting characteristic index */ - CY_BLE_PASS_CP, /**< Ringer Control Point characteristic index */ - CY_BLE_PASS_CHAR_COUNT /**< Total count of PASS characteristics */ -}cy_en_ble_pass_char_index_t; - -/** Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_PASS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_PASS_DESCR_COUNT /**< Total count of PASS descriptors */ -}cy_en_ble_pass_descr_index_t; - -/** @} */ - -/* Alert Status values */ -#define CY_BLE_PASS_AS_RINGER (0x01) /* Ringer State */ -#define CY_BLE_PASS_AS_VIBRATE (0x02) /* Vibrate State */ -#define CY_BLE_PASS_AS_DISPLAY (0x04) /* Display Alert Status */ - -/** - * \addtogroup group_ble_service_api_PASS_definitions - * @{ - */ - -/** Ringer Setting values */ -typedef enum -{ - CY_BLE_PASS_RS_SILENT, /**< Ringer Silent */ - CY_BLE_PASS_RS_NORMAL /**< Ringer Normal */ -}cy_en_ble_pass_rs_t; - -/** Ringer Control Point values */ -typedef enum -{ - CY_BLE_PASS_CP_SILENT = 1, /**< Silent Mode */ - CY_BLE_PASS_CP_MUTE, /**< Mute Once */ - CY_BLE_PASS_CP_CANCEL /**< Cancel Silent Mode */ -}cy_en_ble_pass_cp_t; - -/** Structure with Phone Alert Status Service characteristics and descriptors attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_PASS_DESCR_COUNT]; /**< Handle of descriptor */ -}cy_stc_ble_passs_char_t; - -/** Structure with Phone Alert Status Service attribute handles */ -typedef struct -{ - /** Phone Alert Status Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Phone Alert Status Service characteristics info array */ - cy_stc_ble_passs_char_t charInfo[CY_BLE_PASS_CHAR_COUNT]; -} cy_stc_ble_passs_t; - -/** Phone Alert Status Client Server's Characteristic structure type */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of Server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** Phone Alert Status Client characteristics descriptors handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_PASS_DESCR_COUNT]; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_passc_char_t; - -/** Structure with discovered attributes information of Phone Alert Status Service */ -typedef struct -{ - cy_stc_ble_passc_char_t charInfo[CY_BLE_PASS_CHAR_COUNT]; /**< Characteristics handle and properties array */ -}cy_stc_ble_passc_t; - -/** Phone Alert Status Service Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_pass_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_pass_char_value_t; - -/** Phone Alert Status Service Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_pass_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_pass_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_pass_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Phone Alert Status Profile GATT DB handles structure */ - const cy_stc_ble_passs_t *passs; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_pass_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_PASS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_PASS_Init(cy_stc_ble_pass_config_t *config); -cy_en_ble_api_result_t Cy_BLE_PASS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_PASS_SERVER -/** - * \addtogroup group_ble_service_api_PASS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_PASSS_SetCharacteristicValue(cy_en_ble_pass_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PASSS_GetCharacteristicValue(cy_en_ble_pass_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PASSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - cy_en_ble_pass_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PASSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); -/** @} */ -#endif /* CY_BLE_PASS_SERVER */ - -#ifdef CY_BLE_PASS_CLIENT -/** - * \addtogroup group_ble_service_api_PASS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_PASSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PASSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_PASSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - cy_en_ble_pass_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PASSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_pass_char_index_t charIndex, - cy_en_ble_pass_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_PASS_CLIENT */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE - * Internal macros - */ -#ifdef CY_BLE_PASS_SERVER -#define CY_BLE_PASS_IS_GMC_SUPPORTED \ - (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_passConfig->passs->charInfo[CY_BLE_PASS_GLMC].charHandle) -#endif /* CY_BLE_PASS_SERVER */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_PASS_SERVER -extern uint8_t cy_ble_passFlag; -#endif /* CY_BLE_PASSC_SERVER */ - -#ifdef CY_BLE_PASS_CLIENT -/* Phone Alert Status Service Server's GATT DB handles structure */ -extern cy_stc_ble_passc_t cy_ble_passc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_PASS_CLIENT */ - -extern cy_stc_ble_pass_config_t cy_ble_passConfig; -extern cy_stc_ble_pass_config_t *cy_ble_passConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_PASS) */ -#endif /* CY_BLE_PASS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_plxs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_plxs.c deleted file mode 100644 index 6ef00fd350..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_plxs.c +++ /dev/null @@ -1,1699 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_plxs.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Pulse Oximeter Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_PLXS)) - -static cy_ble_callback_t Cy_BLE_PLXS_ApplCallback; - -#ifdef CY_BLE_PLXS_SERVER -/* PLXS Server flags */ -uint32_t cy_ble_plxssFlag; - -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_plxssReqHandle; -#endif /* CY_BLE_PLXS_SERVER */ - -#ifdef CY_BLE_PLXS_CLIENT -/* Server's PLX Service characteristics GATT DB handles structure */ -cy_stc_ble_plxsc_t cy_ble_plxsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check the response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_plxscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -/* RACP Procedure Timeout TIMER setting */ -static cy_stc_ble_timer_info_t cy_ble_plxscRacpTimeout[CY_BLE_CONFIG_GATTC_COUNT]; - -/* PLXS Client flags */ -uint32_t cy_ble_plxscFlag[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_PLXS_CLIENT */ - -/* The pointer on global BLE PLXS Config structure */ -cy_stc_ble_plxs_config_t *cy_ble_plxsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_PLXS_SERVER -static void Cy_BLE_PLXSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_PLXSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_PLXS_SERVER */ - -#ifdef CY_BLE_PLXS_CLIENT -static void Cy_BLE_PLXSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_PLXSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_PLXSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_PLXSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_PLXSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_PLXSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_PLXSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_PLXSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_PLXSC_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam); -#endif /* CY_BLE_PLXS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_PLXS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for the Pulse Oximeter Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXS_Init(cy_stc_ble_plxs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_plxsConfigPtr = config; - - /* Registers Event Handler for the PLXS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_PLXS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_plxsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_PLXS_ApplCallback = cy_ble_plxsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_PLXS_SERVER - cy_ble_plxssFlag = 0u; - cy_ble_plxssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_PLXS_SERVER */ - - #ifdef CY_BLE_PLXS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_PLXS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_plxsc[idx], 0, sizeof(cy_stc_ble_plxsc_t)); - - /* initialize UUID */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_PLXS].uuid = CY_BLE_UUID_PULSE_OXIMETER_SERVICE; - } - cy_ble_plxscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_plxscRacpTimeout[idx].timeout = CY_BLE_PLXS_RACP_PROCEDURE_TIMEOUT; - cy_ble_plxscFlag[idx] = 0u; - } - } - #endif /* CY_BLE_PLXS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for PLX Service is: -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \sideeffect The *eventParams in the callback function should not be used -* by the application once the callback function execution is -* finished. Otherwise this data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_PLXS_ApplCallback = callbackFunc; - if(cy_ble_plxsConfigPtr != NULL) - { - cy_ble_plxsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_PLXS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the service, which is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* \events -* None -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSS_SetCharacteristicValue(cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_PLXS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets a characteristic descriptor of a specified characteristic of the service. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_plxs_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_plxs_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data that should -* be stored to the GATT database. -* -* \return -* The return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request is handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex >= CY_BLE_PLXS_CHAR_COUNT) || (descrIndex >= CY_BLE_PLXS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets a characteristic value of the service, which is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: Pointer to the location where Characteristic value data should -* be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSS_GetCharacteristicValue(cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if(charIndex >= CY_BLE_PLXS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param *attrValue: Pointer to the location where the descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check the parameters */ - if((charIndex >= CY_BLE_PLXS_CHAR_COUNT) || (descrIndex >= CY_BLE_PLXS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified characteristic to the client device, -* as defined by the charIndex value. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_PLXSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: Pointer to the Characteristic value data that should be sent -* to Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_PLXS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_plxsConfigPtr->plxss->charInfo[charIndex]. - descrHandle[CY_BLE_PLXS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_SendIndication -***************************************************************************//** -* -* Sends an indication of the specified characteristic to the client device, as -* defined by the charIndex value. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_PLXS_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: Pointer to the Characteristic value data that should be sent -* to Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PLXS service-specific callback is registered -* (with Cy_BLE_PLXS_RegisterAttrCallback): -* * CY_BLE_EVT_PLXSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the PLXS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_PLXS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_plxsConfigPtr->plxss->charInfo[charIndex]. - descrHandle[CY_BLE_PLXS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indParam = - { - .handleValPair.attrHandle = cy_ble_plxsConfigPtr->plxss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indParam); - - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific value confirmation response from client */ - cy_ble_plxssReqHandle = indParam.handleValPair.attrHandle; - } - } - - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles the Value Confirmation request event from the BLE stack. -* -* \param *eventParam: Pointer to a structure of type cy_stc_ble_conn_handle_t -* -******************************************************************************/ -static void Cy_BLE_PLXSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_stc_ble_plxs_char_value_t locCharIndex = { .connHandle = *eventParam, .value = NULL }; - - if(Cy_BLE_PLXS_ApplCallback != NULL) - { - for(locCharIndex.charIndex = CY_BLE_PLXS_SCMT; locCharIndex.charIndex < CY_BLE_PLXS_CHAR_COUNT; - locCharIndex.charIndex++) - { - if(cy_ble_plxsConfigPtr->plxss->charInfo[locCharIndex.charIndex].charHandle == cy_ble_plxssReqHandle) - { - cy_ble_plxssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* We have finish of RACP procedure, so reset flag CY_BLE_PLXS_FLAG_PROCESS */ - if(locCharIndex.charIndex == CY_BLE_PLXS_RACP) - { - cy_ble_plxssFlag &= (uint8_t) ~CY_BLE_PLXS_FLAG_PROCESS; - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSS_INDICATION_CONFIRMED, &locCharIndex); - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param *eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A function return state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_PLXSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_plxs_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - - if(Cy_BLE_PLXS_ApplCallback != NULL) - { - if(cy_ble_plxsConfigPtr->plxss->charInfo[CY_BLE_PLXS_RACP].charHandle == eventParam->handleValPair.attrHandle) - { - if(CY_BLE_PLXSS_IS_PROCEDURE_IN_PROGRESS && (eventParam->handleValPair.value.val[0u] != - (uint8_t)CY_BLE_PLXS_RACP_OPC_ABORT_OPN)) - { - gattErr = CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, cy_ble_plxsConfigPtr->plxss-> - charInfo[CY_BLE_PLXS_RACP].descrHandle[CY_BLE_PLXS_CCCD])) - { - gattErr = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - locCharValue.charIndex = CY_BLE_PLXS_RACP; - locCharValue.value = &eventParam->handleValPair.value; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSS_WRITE_CHAR, &locCharValue); - cy_ble_plxssFlag |= CY_BLE_PLXS_FLAG_PROCESS; - } - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - for(locCharValue.charIndex = CY_BLE_PLXS_SCMT; locCharValue.charIndex < CY_BLE_PLXS_CHAR_COUNT; - locCharValue.charIndex++) - { - if(cy_ble_plxsConfigPtr->plxss->charInfo[locCharValue.charIndex].descrHandle[CY_BLE_PLXS_CCCD] == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - locCharValue.value = NULL; - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - switch(locCharValue.charIndex) - { - /* INDICATION */ - case CY_BLE_PLXS_SCMT: - case CY_BLE_PLXS_RACP: - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSS_INDICATION_ENABLED, - &locCharValue); - } - else - { - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSS_INDICATION_DISABLED, - &locCharValue); - } - break; - - /* NOTIFICATION */ - case CY_BLE_PLXS_CTMT: - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSS_NOTIFICATION_ENABLED, - &locCharValue); - } - else - { - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSS_NOTIFICATION_DISABLED, - &locCharValue); - } - break; - - default: - break; - } - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - - if(gattErr) - { - /* If we have gattErr, so release flag CY_BLE_PLXS_FLAG_PROCESS */ - cy_ble_plxssFlag &= (uint8_t) ~CY_BLE_PLXS_FLAG_PROCESS; - } - - return(gattErr); -} - -#endif /* CY_BLE_PLXS_SERVER */ - -#ifdef CY_BLE_PLXS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_PLXSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param *attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PLXS service-specific callback is registered -* (with Cy_BLE_PLXS_RegisterAttrCallback): -* * CY_BLE_EVT_PLXSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_plxs_char_value_t. -* . -* Otherwise (if the PLXS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PLXS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_plxsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_plxsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle, - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_plxscReqHandle[discIdx] = cy_ble_plxsc[discIdx].charInfo[charIndex].valueHandle; - } - - if(charIndex == CY_BLE_PLXS_RACP) - { - /* Start RACP procedure. It will ends when the Collector sends a confirmation to acknowledge the RACP - * indication sent by the Sensor. A procedure is considered to have timed out if a RACP indication - * (or PLX Spot-check Measurement characteristic indication) is not received within the ATT transaction timeout, - * defined as 5 seconds. CY_BLE_EVT_PLXSC_TIMEOUT event indicate about CP procedure timeout. - */ - apiResult = Cy_BLE_StartTimer(&cy_ble_plxscRacpTimeout[discIdx]); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_plxscFlag[discIdx] |= CY_BLE_PLXS_FLAG_PROCESS; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server -* which is identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PLXS service-specific callback is registered -* (with Cy_BLE_PLXS_RegisterAttrCallback): -* * CY_BLE_EVT_PLXSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_plxs_char_value_t. -* . -* Otherwise (if the PLXS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PLXS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_plxsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_plxsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_plxscReqHandle[discIdx] = cy_ble_plxsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the Characteristic Descriptor of the specified Characteristic. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_PLXSS_INDICATION_ENABLED -* * CY_BLE_EVT_PLXSS_INDICATION_DISABLED -* * CY_BLE_EVT_PLXSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_PLXSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of a service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param *attrValue: Pointer to the characteristic descriptor value data that should -* be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PLXS service-specific callback is registered -* (with Cy_BLE_PLXS_RegisterAttrCallback): -* * CY_BLE_EVT_PLXSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_plxs_descr_value_t. -* . -* Otherwise (if the PLXS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PLXS_CHAR_COUNT) || (descrIndex >= CY_BLE_PLXS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_plxsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific read response from device */ - cy_ble_plxscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the PLXS service-specific callback is registered -* (with Cy_BLE_PLXS_RegisterAttrCallback): -* * CY_BLE_EVT_PLXSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_plxs_descr_value_t. -* . -* Otherwise (if the PLXS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_PLXSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check the parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_PLXS_CHAR_COUNT) || (descrIndex >= CY_BLE_PLXS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_plxsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_plxsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_plxscReqHandle[discIdx] = cy_ble_plxsc[discIdx].charInfo[charIndex].descrHandle[CY_BLE_PLXS_CCCD]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* PLX Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_plxsCharUuid[CY_BLE_PLXS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_PLX_SPOT_CHK_MSRMT, - CY_BLE_UUID_CHAR_PLX_CONTINUOUS_MSRMT, - CY_BLE_UUID_CHAR_PLX_FEATURES, - CY_BLE_UUID_CHAR_RACP - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_PLXS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_PLXS_CHAR_COUNT; i++) - { - if(cy_ble_plxsCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_plxsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_plxsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_plxsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_plxsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_PLXS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param *discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_PLXS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_PLXS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_plxsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_plxsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_PLXS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_PLXS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_plxsc[discIdx].charInfo[charIdx].endHandle - - cy_ble_plxsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_plxsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_plxsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param *eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PLXS_ApplCallback != NULL)) - { - cy_stc_ble_plxs_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - - if(cy_ble_plxsc[discIdx].charInfo[CY_BLE_PLXS_CTMT].valueHandle == - eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_PLXS_CTMT; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - /* PLXS Service doesn't support any other notifications */ - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locCharValue.value = &eventParam->handleValPair.value; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_NOTIFICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_IndicationEventHandler -***************************************************************************//** -* -* Handles the Indication Event. -* -* \param *eventParam: the pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - cy_stc_ble_plxs_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PLXS_ApplCallback != NULL)) - { - if(cy_ble_plxsc[discIdx].charInfo[CY_BLE_PLXS_SCMT].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_PLXS_SCMT; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - if((cy_ble_plxscFlag[discIdx] & CY_BLE_PLXS_FLAG_PROCESS) != 0u) - { - /* Restart RACP timeout timer during RACP procedure(Report stored records)*/ - (void)Cy_BLE_StopTimer(&cy_ble_plxscRacpTimeout[discIdx]); - (void)Cy_BLE_StartTimer(&cy_ble_plxscRacpTimeout[discIdx]); - } - } - else if(cy_ble_plxsc[discIdx].charInfo[CY_BLE_PLXS_RACP].valueHandle == eventParam->handleValPair.attrHandle) - { - locCharValue.charIndex = CY_BLE_PLXS_RACP; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - - /* End of RACP procedure, so stop RACP timeout timer */ - (void)Cy_BLE_StopTimer(&cy_ble_plxscRacpTimeout[discIdx]); - cy_ble_plxscFlag[discIdx] &= ~CY_BLE_PLXS_FLAG_PROCESS; - } - else - { - /* PLXS Service doesn't support any other indications */ - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) == 0u) - { - locCharValue.value = &eventParam->handleValPair.value; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_INDICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param *eventParam: The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PLXS_ApplCallback != NULL) && - (cy_ble_plxscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_plxs_char_index_t charIdx; - uint32_t fFlag = 0u; - - for(charIdx = (cy_en_ble_plxs_char_index_t)0u; (charIdx < CY_BLE_PLXS_CHAR_COUNT) && (fFlag == 0u); charIdx++) - { - if(cy_ble_plxsc[discIdx].charInfo[charIdx].valueHandle == cy_ble_plxscReqHandle[discIdx]) - { - cy_stc_ble_plxs_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = charIdx, - .value = &eventParam->value - }; - cy_ble_plxscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_READ_CHAR_RESPONSE, &locCharValue); - fFlag = 1u; /* instead of break */ - } - else if(cy_ble_plxsc[discIdx].charInfo[charIdx].descrHandle[CY_BLE_PLXS_CCCD] == cy_ble_plxscReqHandle[discIdx]) - { - cy_stc_ble_plxs_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = charIdx, - .descrIndex = CY_BLE_PLXS_CCCD, - .value = &eventParam->value - }; - cy_ble_plxscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_READ_DESCR_RESPONSE, &locDescrValue); - fFlag = 1u; /* instead of break */ - } - else - { - /* nothing else */ - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param *eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_PLXS_ApplCallback != NULL) && - (cy_ble_plxscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_en_ble_plxs_char_index_t charIdx; - uint32_t fFlag = 0u; - - for(charIdx = (cy_en_ble_plxs_char_index_t)0u; (charIdx < CY_BLE_PLXS_CHAR_COUNT) && (fFlag == 0u); charIdx++) - { - if(cy_ble_plxsc[discIdx].charInfo[charIdx].valueHandle == cy_ble_plxscReqHandle[discIdx]) - { - cy_stc_ble_plxs_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = charIdx, - .value = NULL - }; - cy_ble_plxscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_WRITE_CHAR_RESPONSE, &locCharValue); - fFlag = 1u; /* instead of break */ - } - else if(cy_ble_plxsc[discIdx].charInfo[charIdx].descrHandle[CY_BLE_PLXS_CCCD] == - cy_ble_plxscReqHandle[discIdx]) - { - cy_stc_ble_plxs_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = charIdx, - .descrIndex = CY_BLE_PLXS_CCCD, - .value = NULL - }; - cy_ble_plxscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_WRITE_DESCR_RESPONSE, &locDescrValue); - fFlag = 1u; /* instead of break */ - } - else - { - /* nothing else */ - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param *eventParam: Pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_plxscReqHandle[discIdx]) - { - cy_ble_plxscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_PLXSC_TimeOutEventHandler -***************************************************************************//** -* -* Handles Timer Event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_PLXSC_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam) -{ - if(((eventParam)->reasonCode == CY_BLE_GENERIC_APP_TO) && (Cy_BLE_PLXS_ApplCallback != NULL)) - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(((cy_ble_plxscFlag[idx] & CY_BLE_PLXS_FLAG_PROCESS) != 0u) && - (eventParam->timerHandle == cy_ble_plxscRacpTimeout[idx].timerHandle)) - { - cy_stc_ble_plxs_char_value_t timeoutValue = - { - .connHandle = cy_ble_connHandle[cy_ble_discovery[idx].connIndex], - .charIndex = CY_BLE_PLXS_RACP - }; - - cy_ble_plxscFlag[idx] &= (uint8_t) ~CY_BLE_PLXS_FLAG_PROCESS; - cy_ble_plxscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - Cy_BLE_PLXS_ApplCallback((uint32_t)CY_BLE_EVT_PLXSC_TIMEOUT, &timeoutValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - -#endif /* CY_BLE_PLXS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_PLXS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the PLXS Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_PLXS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_PLXS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_PLXSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_PLXSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_PLXSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_PLXS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_PLXS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_PLXSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_PLXSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_PLXS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_PLXS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_PLXSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_PLXSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_PLXSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_PLXSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_PLXSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_TIMEOUT: - Cy_BLE_PLXSC_TimeOutEventHandler((cy_stc_ble_timeout_param_t*)eventParam); - break; - #endif /* CY_BLE_PLXS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_PLXS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_plxs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_plxs.h deleted file mode 100644 index 3a274af9cd..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_plxs.h +++ /dev/null @@ -1,393 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_plxs.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Pulse Oximeter -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_PLXS_H -#define CY_BLE_PLXS_H - -#include "cy_ble_gatt.h" -#include "cy_ble_plxs.h" -/** - * \addtogroup group_ble_service_api_PLXS_definitions - * @{ - */ - - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_PLXS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/*************************************** -* Data Struct Definition -***************************************/ - -/** PLXS Characteristic indexes */ -typedef enum -{ - CY_BLE_PLXS_SCMT, /**< The PLX Spot-check Measurement characteristic, if supported, - * is used to send Spot-check measurements of SpO2 (Percent oxygen - * saturation of hemoglobin) and PR (pulse rate). This - * characteristic is a variable length structure containing the - * Flags field, the SpO2PR-Spot-Check field, and depending on the - * contents of the Flags field, the Timestamp field, the Measurement - * Status field, the Device and Sensor Status field, and/or the - * Pulse Amplitude Index field. */ - - CY_BLE_PLXS_CTMT, /**< The PLX Continuous Measurement characteristic, if supported, - * is used to send periodic pulse oximetry measurements. This - * characteristic is a variable length structure containing the - * Flags field (to indicate presence of optional fields), the - * SpO2PR-Normal field, and depending on the contents of the Flags - * field, the SpO2PR-Fast field, the SpO2PR-Slow field, the - * Measurement Status field, the Device and Sensor Status field, - * and/or the Pulse Amplitude Index field.*/ - - CY_BLE_PLXS_FEAT, /**< The PLX Features characteristic is used to describe the - * supported features of the Server. Included in the characteristic - * is a PLX Features field, and, depending on the contents of the - * PLX Features field, the Measurement Status Support field, and - * the Device and Sensor Status Support field. */ - - CY_BLE_PLXS_RACP, /**< This control point is used with a service to provide basic - * management functionality for the PLX Sensor patient record - * database. This enables functions including counting records, - * transmitting records and clearing records based on filter - * criterion. The filter criterion in the Operand field is defined - * by the service that references this characteristic as is the - * format of a record (that may be comprised of one or more - * characteristics) and the sequence of transferred records.*/ - - CY_BLE_PLXS_CHAR_COUNT /**< Total count of PLXS characteristics */ -}cy_en_ble_plxs_char_index_t; - - -/** PLXS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_PLXS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_PLXS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_plxs_descr_index_t; - -/** PLXS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_PLXS_DESCR_COUNT]; /**< Handle of descriptor */ -} cy_stc_ble_plxss_char_t; - -/** Structure with PLXS attribute handles */ -typedef struct -{ - /** PLXS handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** PLXS Characteristic handles */ - cy_stc_ble_plxss_char_t charInfo[CY_BLE_PLXS_CHAR_COUNT]; -} cy_stc_ble_plxss_t; - -/** PLXS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_PLXS_DESCR_COUNT]; /**< Array of Descriptor handles */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_plxsc_char_t; - -/** Structure with discovered attributes information of Pulse Oximeter Service. */ -typedef struct -{ - /** Pulse Oximeter Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** PLXS characteristics info array */ - cy_stc_ble_plxsc_char_t charInfo[CY_BLE_PLXS_CHAR_COUNT]; -} cy_stc_ble_plxsc_t; - - -/** PLXS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_plxs_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ -} cy_stc_ble_plxs_char_value_t; - -/** PLXS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_plxs_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_plxs_descr_index_t descrIndex; /**< Index of descriptor */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< Error code received from application (optional) */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_plxs_descr_value_t; - -/** Record Access Control Point characteristic fields defines -** Opcode of the Record Access Control Point characteristic value type -*/ -typedef enum -{ - CY_BLE_PLXS_RACP_OPC_RESERVED = 0u, /**< Reserved for future use (Operator:N/A) */ - CY_BLE_PLXS_RACP_OPC_REPORT_REC, /**< Report stored records (Operator: Value from Operator Table) */ - CY_BLE_PLXS_RACP_OPC_DELETE_REC, /**< Delete stored records (Operator: Value from Operator Table) */ - CY_BLE_PLXS_RACP_OPC_ABORT_OPN, /**< Abort operation (Operator: Null 'value of 0x00 from Operator Table') */ - CY_BLE_PLXS_RACP_OPC_REPORT_NUM_REC, /**< Report number of stored records (Operator: Value from Operator Table) */ - CY_BLE_PLXS_RACP_OPC_NUM_REC_RSP, /**< Number of stored records response (Operator: Null 'value of 0x00 from Operator Table') */ - CY_BLE_PLXS_RACP_OPC_RSP_CODE, /**< Response Code (Operator: Null 'value of 0x00 from Operator Table') */ -} cy_en_ble_plxs_racp_opc_t; - -/** Operator of the Record Access Control Point characteristic value type */ -typedef enum -{ - CY_BLE_PLXS_RACP_OPR_NULL = 0u, /**< Null */ - CY_BLE_PLXS_RACP_OPR_ALL, /**< All records */ - CY_BLE_PLXS_RACP_OPR_LESS, /**< Less than or equal to */ - CY_BLE_PLXS_RACP_OPR_GREAT, /**< Greater than or equal to */ - CY_BLE_PLXS_RACP_OPR_WITHIN, /**< Within range of (inclusive) */ - CY_BLE_PLXS_RACP_OPR_FIRST, /**< First record(i.e. oldest record) */ - CY_BLE_PLXS_RACP_OPR_LAST /**< Last record (i.e. most recent record) */ -} cy_en_ble_plxs_racp_opr_t; - -/** Operand of the Record Access Control Point characteristic value type */ -typedef enum -{ - CY_BLE_PLXS_RACP_OPD_NA = 0u, /**< N/A */ - CY_BLE_PLXS_RACP_OPD_1, /**< Filter parameters (as appropriate to Operator and Service) */ - CY_BLE_PLXS_RACP_OPD_2, /**< Filter parameters (as appropriate to Operator and Service) */ - CY_BLE_PLXS_RACP_OPD_NO_INCL, /**< Not included */ - CY_BLE_PLXS_RACP_OPD_4, /**< Filter parameters (as appropriate to Operator and Service) */ - CY_BLE_PLXS_RACP_OPD_NUM_REC, /**< Number of Records (Field size defined per service) */ - CY_BLE_PLXS_RACP_OPD_RSP, /**< Request Op Code, Response Code Value */ -} cy_en_ble_plxs_racp_opd_t; - -/** Operand Response Code Values of the Record Access Control Point characteristic value type */ -typedef enum -{ - CY_BLE_PLXS_RACP_RSP_NA = 0u, /**< N/A */ - CY_BLE_PLXS_RACP_RSP_SUCCESS, /**< Normal response for successful operation */ - CY_BLE_PLXS_RACP_RSP_UNSPRT_OPC, /**< Normal response if unsupported Op Code is received */ - CY_BLE_PLXS_RACP_RSP_INV_OPR, /**< Normal response if Operator received does not meet the - * requirements of the service (e.g. Null was expected) */ - CY_BLE_PLXS_RACP_RSP_UNSPRT_OPR, /**< Normal response if unsupported Operator is received */ - CY_BLE_PLXS_RACP_RSP_INV_OPD, /**< Normal response if Operand received does not meet the - * requirements of the service */ - CY_BLE_PLXS_RACP_RSP_NO_REC, /**< Normal response if request to report stored records - * or request to delete stored records resulted in no - * records meeting criteria. */ - CY_BLE_PLXS_RACP_RSP_UNSUCCESS, /**< Normal response if request for Abort cannot be completed */ - CY_BLE_PLXS_RACP_RSP_NO_COMPL, /**< Normal response if request for Abort cannot be completed */ - CY_BLE_PLXS_RACP_RSP_UNSPRT_OPD /**< Normal response if unsupported Operand is received */ -} cy_en_ble_plxs_racp_rsp_t; - -/** Service configuration structure */ -typedef struct -{ - /** The Pulse Oximeter Service. GATT DB handles structure */ - const cy_stc_ble_plxss_t *plxss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_plxs_config_t; - - -/*************************************** -* API Constants -***************************************/ -/** RACP Procedure Timeout */ -#define CY_BLE_PLXS_RACP_PROCEDURE_TIMEOUT (5u) /**< Seconds */ - -/** PLX internal flag */ -#define CY_BLE_PLXS_FLAG_PROCESS (1u) /**< Flag indicates that RACP is running */ - -/** "Device and Sensor Status" field bits */ -#define CY_BLE_PLXS_DSS_EDU_BIT (0x01u << 0u) /**< Extended Display Update Ongoing bit */ -#define CY_BLE_PLXS_DSS_EMD_BIT (0x01u << 1u) /**< Equipment Malfunction Detected bit */ -#define CY_BLE_PLXS_DSS_SPID_BIT (0x01u << 2u) /**< Signal Processing Irregularity Detected bit */ -#define CY_BLE_PLXS_DSS_ISD_BIT (0x01u << 3u) /**< Inadequite Signal Detected bit */ -#define CY_BLE_PLXS_DSS_PSD_BIT (0x01u << 4u) /**< Poor Signal Detected bit */ -#define CY_BLE_PLXS_DSS_LPD_BIT (0x01u << 5u) /**< Low Perfusion Detected bit */ -#define CY_BLE_PLXS_DSS_ESD_BIT (0x01u << 6u) /**< Erratic Signal Detected bit */ -#define CY_BLE_PLXS_DSS_NSD_BIT (0x01u << 7u) /**< Nonpulsatile Signal Detected bit */ -#define CY_BLE_PLXS_DSS_QPD_BIT (0x01u << 8u) /**< Questionable Pulse Detected bit */ -#define CY_BLE_PLXS_DSS_SA_BIT (0x01u << 9u) /**< Signal Analysis Ongoing bit */ -#define CY_BLE_PLXS_DSS_SID_BIT (0x01u << 10u) /**< Sensor Interface Detected bit */ -#define CY_BLE_PLXS_DSS_SUTU_BIT (0x01u << 11u) /**< Sensor Unconnected to User bit */ -#define CY_BLE_PLXS_DSS_USC_BIT (0x01u << 12u) /**< Unknown Sensor Connected bit */ -#define CY_BLE_PLXS_DSS_SD_BIT (0x01u << 13u) /**< Sensor Displaced bit */ -#define CY_BLE_PLXS_DSS_SM_BIT (0x01u << 14u) /**< Sensor Malfunctioning bit */ -#define CY_BLE_PLXS_DSS_SDISC_BIT (0x01u << 15u) /**< Sensor Disconnected bit */ - -/** "Measurement Status" field bits */ -#define CY_BLE_PLXS_MS_MEAS_BIT (0x01u << 5u) /**< Measurement Ongoing bit */ -#define CY_BLE_PLXS_MS_EED_BIT (0x01u << 6u) /**< Early Estimated Data bit */ -#define CY_BLE_PLXS_MS_VDATA_BIT (0x01u << 7u) /**< Validated Data bit */ -#define CY_BLE_PLXS_MS_FQDATA_BIT (0x01u << 8u) /**< Fully Qualified Data bit */ -#define CY_BLE_PLXS_MS_DFMS_BIT (0x01u << 9u) /**< Data from Measurement Storage bit */ -#define CY_BLE_PLXS_MS_DFDEMO_BIT (0x01u << 10u) /**< Data for Demonstration bit */ -#define CY_BLE_PLXS_MS_DFTEST_BIT (0x01u << 11u) /**< Data for Testing bit */ -#define CY_BLE_PLXS_MS_CALIB_BIT (0x01u << 12u) /**< Calibration Ongoing bit */ -#define CY_BLE_PLXS_MS_MUN_BIT (0x01u << 13u) /**< Measurement Unavailable bit */ -#define CY_BLE_PLXS_MS_QMD_BIT (0x01u << 14u) /**< Questionable Measurement Detected bit */ -#define CY_BLE_PLXS_MS_IMD_BIT (0x01u << 15u) /**< Invalid Measurement Detected bit */ - -/** "Flag" field bits of PLX Spot-Check Measurement characteristic */ -#define CY_BLE_PLXS_SCMT_FLAG_TMSF_BIT (0x01u << 0u) /**< Timestamp field bit */ -#define CY_BLE_PLXS_SCMT_FLAG_MSF_BIT (0x01u << 1u) /**< Measurement Status Field bit */ -#define CY_BLE_PLXS_SCMT_FLAG_DSSF_BIT (0x01u << 2u) /**< Device and Sensor Status Field bit */ -#define CY_BLE_PLXS_SCMT_FLAG_PAIF_BIT (0x01u << 3u) /**< Pulse Amplitude Index field bit */ -#define CY_BLE_PLXS_SCMT_FLAG_DEVCLK_BIT (0x01u << 4u) /**< Device Clock is Not Set bit */ - -/** "Flag" field bits of PLX Continuous Measurement characteristic */ -#define CY_BLE_PLXS_CTMT_FLAG_FAST_BIT (0x01u << 0u) /**< SpO2PR-Fast field bit */ -#define CY_BLE_PLXS_CTMT_FLAG_SLOW_BIT (0x01u << 1u) /**< SpO2PR-Slow field bit */ -#define CY_BLE_PLXS_CTMT_FLAG_MSF_BIT (0x01u << 2u) /**< Measurement Status field bit */ -#define CY_BLE_PLXS_CTMT_FLAG_DSSF_BIT (0x01u << 3u) /**< Device and Sensor Status field bit */ -#define CY_BLE_PLXS_CTMT_FLAG_PAIF_BIT (0x01u << 4u) /**< Pulse Amplitude Index field bit */ - -/** "Supported Features" bits of PLX Features characteristic */ -#define CY_BLE_PLXS_FEAT_SUPPORT_MEAS_BIT (0x01u << 0u) /**< Measurement Status support bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_DSS_BIT (0x01u << 1u) /**< Device and Sensor Status support bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_MSSC_BIT (0x01u << 2u) /**< Measurement Storage for Spot-check measurements bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_TMSF_BIT (0x01u << 3u) /**< Timestamp for Spot-check measurements bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_FAST_BIT (0x01u << 4u) /**< SpO2PR-Fast metric bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_SLOW_BIT (0x01u << 5u) /**< SpO2PR-Slow metric bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_PAI_BIT (0x01u << 6u) /**< Pulse Amplitude Index field bit */ -#define CY_BLE_PLXS_FEAT_SUPPORT_MBS_BIT (0x01u << 7u) /**< Multiple Bonds Supported bit */ - - -/** @} */ - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_PLXS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_PLXS_Init(cy_stc_ble_plxs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_PLXS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); - -/** @} */ - -#ifdef CY_BLE_PLXS_SERVER -/** - * \addtogroup group_ble_service_api_PLXS_server - * @{ - */ - - -cy_en_ble_api_result_t Cy_BLE_PLXSS_SetCharacteristicValue(cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PLXSS_GetCharacteristicValue(cy_en_ble_plxs_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - - -cy_en_ble_api_result_t Cy_BLE_PLXSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PLXSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PLXSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PLXSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_PLXS_SERVER */ - - - -#ifdef CY_BLE_PLXS_CLIENT -/** - * \addtogroup group_ble_service_api_PLXS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_PLXSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PLXSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_PLXSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_PLXSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_plxs_char_index_t charIndex, - cy_en_ble_plxs_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_PLXS_CLIENT */ - -/*************************************** -* Macro Functions -***************************************/ - -#ifdef CY_BLE_PLXS_CLIENT -#define Cy_BLE_PLXSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_PLXS_CHAR_COUNT) ? CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_plxsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_PLXSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_PLXS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_PLXS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_plxsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].descrHandle[descrIndex]) -#endif /* (CY_BLE_PLXS_CLIENT) */ - -#ifdef CY_BLE_PLXS_SERVER -#define CY_BLE_PLXSS_IS_PROCEDURE_IN_PROGRESS ((cy_ble_plxssFlag & CY_BLE_PLXS_FLAG_PROCESS) != 0u) -#endif /* CY_BLE_PLXS_SERVER */ -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_PLXS_SERVER -extern uint32_t cy_ble_plxssFlag; -#endif /* CY_BLE_PLXS_SERVER */ - -#ifdef CY_BLE_PLXS_CLIENT -extern uint32_t cy_ble_plxscFlag[CY_BLE_CONFIG_GATTC_COUNT]; -extern cy_stc_ble_plxsc_t cy_ble_plxsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_PLXS_CLIENT */ - -extern cy_stc_ble_plxs_config_t cy_ble_plxsConfig; -extern cy_stc_ble_plxs_config_t *cy_ble_plxsConfigPtr; - -#ifdef __cplusplus -} - -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_PLXS) */ -#endif /* CY_BLE_PLXS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rscs.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rscs.c deleted file mode 100644 index 17b141834d..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rscs.c +++ /dev/null @@ -1,1677 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_rscs.c -* \version 2.0 -* -* \brief -* Contains the source code for Running Speed and Cadence Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_RSCS)) - -static cy_ble_callback_t Cy_BLE_RSCS_ApplCallback = NULL; - -#if defined(CY_BLE_RSCS_SERVER) -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_rscssReqHandle; -#endif /* CY_BLE_RSCS_SERVER */ - -#if defined(CY_BLE_RSCS_CLIENT) -/* RSCS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_rscsc_t cy_ble_rscsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_rscscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_RSCS_CLIENT) */ - -/* The pointer on global BLE RSCS Config structure */ -cy_stc_ble_rscs_config_t *cy_ble_rscsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#if defined(CY_BLE_RSCS_SERVER) -static cy_en_ble_gatt_err_code_t Cy_BLE_RSCSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_RSCSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -#endif /* CY_BLE_RSCS_SERVER */ - -#if defined(CY_BLE_RSCS_CLIENT) -static void Cy_BLE_RSCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_RSCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_RSCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_RSCSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_RSCSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_RSCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_RSCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_RSCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_RSCS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_RSCS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_RSCS_Init -***************************************************************************//** -* -* This function initializes the Running Speed and Cadence Service. -* -* \param config: Configuration structure for the Running Speed and Cadence Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCS_Init(cy_stc_ble_rscs_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_rscsConfigPtr = config; - - /* Registers Event Handler for the RSCS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_RSCS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_rscsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_RSCS_ApplCallback = cy_ble_rscsConfigPtr->callbackFunc; - } - - #if defined(CY_BLE_RSCS_SERVER) - cy_ble_rscssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_RSCS_SERVER */ - - #ifdef CY_BLE_RSCS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_RSCS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_rscsc[idx], 0, sizeof(cy_stc_ble_rscsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_RSCS].uuid = CY_BLE_UUID_RUNNING_SPEED_AND_CADENCE_SERVICE; - } - cy_ble_rscscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_RSCS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_RSCS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for Running Speed and Cadence Service specific -* attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for RSCS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_RSCS_ApplCallback = callbackFunc; - if(cy_ble_rscsConfigPtr != NULL) - { - cy_ble_rscsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#if defined(CY_BLE_RSCS_SERVER) - -/****************************************************************************** -* Function Name: Cy_BLE_RSCSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for the Running Speed and Cadence Service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t *eventParam: The pointer to the data that came -* with a write request for the -* Running Speed and Cadence Service. -* -* \return -* Return a value of type cy_en_ble_gatt_err_code_t: -* * CY_BLE_GATT_ERR_NONE - Function terminated successfully. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - The handle of a Client Configuration -* Characteristic Descriptor is not valid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The notification or indication -* property of a specific -* Characteristic of Running Speed and -* Cadence Service is disabled. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_RSCSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_stc_ble_rscs_char_value_t wrReqParam = { .connHandle = eventParam->connHandle }; - cy_ble_gatt_db_attr_handle_t tmpHandle; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t event = (uint32_t)CY_BLE_EVT_RSCSS_WRITE_CHAR; - uint32_t handleWasFound = 1u; - - tmpHandle = eventParam->handleValPair.attrHandle; - - if(NULL != Cy_BLE_RSCS_ApplCallback) - { - /* Client Characteristic Configuration Descriptor Write Request */ - if(tmpHandle == cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_RSC_MEASUREMENT].descrHandle[CY_BLE_RSCS_CCCD]) - { - /* Verify that optional notification property is enabled for the Characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_RSC_MEASUREMENT]. - charHandle)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_RSCSS_NOTIFICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_RSCSS_NOTIFICATION_DISABLED; - } - - wrReqParam.charIndex = CY_BLE_RSCS_RSC_MEASUREMENT; - - /* Value is NULL for descriptors */ - wrReqParam.value = NULL; - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else if(tmpHandle == cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_SC_CONTROL_POINT]. - descrHandle[CY_BLE_RSCS_CCCD]) - { - /* Verify that optional indication property is enabled for the Characteristic */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_SC_CONTROL_POINT]. - charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_RSCSS_INDICATION_ENABLED; - } - else - { - event = (uint32_t)CY_BLE_EVT_RSCSS_INDICATION_DISABLED; - } - - wrReqParam.charIndex = CY_BLE_RSCS_SC_CONTROL_POINT; - - /* Value is NULL for descriptors */ - wrReqParam.value = NULL; - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else if(tmpHandle == cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_SC_CONTROL_POINT].charHandle) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE == cy_ble_rscssReqHandle) - { - /* Verify if indication are enabled for SC Control Point Characteristic */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_SC_CONTROL_POINT]. - charHandle)) - { - if(CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_SC_CONTROL_POINT]. - descrHandle[CY_BLE_RSCS_CCCD])) - { - event = (uint32_t)CY_BLE_EVT_RSCSS_WRITE_CHAR; - wrReqParam.charIndex = CY_BLE_RSCS_RSC_MEASUREMENT; - wrReqParam.value = &eventParam->handleValPair.value; - } - else - { - gattErr = CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - } - else - { - gattErr = CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - cy_ble_rscssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - else - { - /* No valid service handles were found */ - handleWasFound = 0u; - } - - if((gattErr == CY_BLE_GATT_ERR_NONE) && (handleWasFound != 0u)) - { - /* Write value to GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_RSCS_ApplCallback(event, &wrReqParam); - } - } - } - - if(CY_BLE_GATT_ERR_NONE != gattErr) - { - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - return(gattErr); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSS_ConfirmationEventHandler -****************************************************************************//** -* -* Handles the Value Confirmation request event from the BLE stack. -* -* \param cy_stc_ble_conn_handle_t *event_params: Pointer to a structure of type -* cy_stc_ble_conn_handle_t. -* -*******************************************************************************/ -static void Cy_BLE_RSCSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_RSCS_ApplCallback != NULL) && (cy_ble_rscssReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_rscssReqHandle == cy_ble_rscsConfigPtr->rscss->charInfo[CY_BLE_RSCS_SC_CONTROL_POINT].charHandle) - { - cy_stc_ble_rscs_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_RSCS_SC_CONTROL_POINT, - .value = NULL - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_rscssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSS_INDICATION_CONFIRMATION, &locCharValue); - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSS_SetCharacteristicValue -****************************************************************************//** -* -* Sets the characteristic value of the Running Speed and Cadence Service in the -* local GATT database. The characteristic is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. Valid values are, -* * CY_BLE_RSCS_RSC_FEATURE -* * CY_BLE_RSCS_SENSOR_LOCATION. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSS_SetCharacteristicValue(cy_en_ble_rscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_RSCS_RSC_FEATURE) || (charIndex == CY_BLE_RSCS_SENSOR_LOCATION)) - { - if(cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSS_GetCharacteristicValue -****************************************************************************//** -* -* Gets the characteristic value of the Running Speed and Cadence Service from -* the GATT database. The characteristic is identified by charIndex. -* -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSS_GetCharacteristicValue(cy_en_ble_rscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex < CY_BLE_RSCS_CHAR_COUNT) - { - if(cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSS_GetCharacteristicDescriptor -****************************************************************************//** -* -* Gets the characteristic descriptor of a specified characteristic of the Running -* Speed and Cadence Service from the GATT database. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic. Valid values are, -* * CY_BLE_RSCS_RSC_MEASUREMENT -* * CY_BLE_RSCS_SC_CONTROL_POINT -* \param descrIndex: The index of a service characteristic descriptor. Valid value is, -* * CY_BLE_RSCS_CCCD -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - cy_en_ble_rscs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(((charIndex == CY_BLE_RSCS_RSC_MEASUREMENT) || (charIndex == CY_BLE_RSCS_SC_CONTROL_POINT)) && - (descrIndex == CY_BLE_RSCS_CCCD)) - { - if(cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].descrHandle[descrIndex] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSS_SendNotification -****************************************************************************//** -* -* Sends a notification with the characteristic value to the Client device. This -* is specified by charIndex of the Running Speed and Cadence Service. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_RSCSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. Valid value is, -* * CY_BLE_RSCS_RSC_MEASUREMENT -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be sent -* to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameter is failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex == CY_BLE_RSCS_RSC_MEASUREMENT) - { - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_rscsConfigPtr->rscss-> - charInfo[charIndex].descrHandle[CY_BLE_RSCS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle, - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSS_SendIndication -****************************************************************************//** -* -* Sends an indication with a characteristic value to the Client device. This is -* specified by charIndex of the Running Speed and Cadence Service. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_RSCSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be sent -* to the client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameter is failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the RSCS service-specific callback is registered -* (with Cy_BLE_RSCS_RegisterAttrCallback): -* * CY_BLE_EVT_RSCSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the RSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if(charIndex == CY_BLE_RSCS_SC_CONTROL_POINT) - { - /* Send Indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_rscsConfigPtr->rscss-> - charInfo[charIndex].descrHandle[CY_BLE_RSCS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - if(cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_rscsConfigPtr->rscss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - /* Save handle to support service-specific value confirmation response from client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_rscssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - return(apiResult); -} - -#endif /* CY_BLE_RSCS_SERVER */ - - -#if defined(CY_BLE_RSCS_CLIENT) - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_DiscoverCharacteristicsEventHandler -****************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* RSCS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_rscscCharUuid[CY_BLE_RSCS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_RSC_MSRMT, - CY_BLE_UUID_CHAR_RSC_FEATURE, - CY_BLE_UUID_CHAR_SENSOR_LOCATION, - CY_BLE_UUID_CHAR_SC_CONTROL_POINT - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_RSCS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = (uint32_t)CY_BLE_RSCS_RSC_MEASUREMENT; i < (uint32_t)CY_BLE_RSCS_CHAR_COUNT; i++) - { - if(cy_ble_rscscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_rscsc[discIdx].characteristics[i].charInfo.valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_rscsc[discIdx].characteristics[i].charInfo.valueHandle = discCharInfo->valueHandle; - cy_ble_rscsc[discIdx].characteristics[i].charInfo.properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_rscsc[discIdx].characteristics[i].endHandle; - break; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initially characteristic endHandle equals to the Service endHandle. - * Characteristic endHandle will be updated to declaration handler of the - * following characteristic,in the following characteristic discovery - * procedure. - */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCS_DiscoverCharDescriptorsEventHandler -****************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* This event is generated when a server successfully sends the data for -* CY_BLE_EVT_GATTC_FIND_INFO_REQ. Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param cy_stc_ble_disc_descr_info_t * discCharInfo: The pointer to a characteristic information -* structure. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t * discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_RSCS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_RSCS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if(cy_ble_rscsc[discIdx].characteristics[charIdx].descriptors[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_rscsc[discIdx].characteristics[charIdx].descriptors[descIdx] = discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_RSCSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_RSCSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_RSCS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_RSCS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_rscsc[discIdx].characteristics[charIdx].endHandle - - cy_ble_rscsc[discIdx].characteristics[charIdx].charInfo.valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_rscsc[discIdx].characteristics[charIdx].charInfo.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_rscsc[discIdx].characteristics[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_NotificationEventHandler -****************************************************************************//** -* -* Handles the Notification Event for the Running Speed and Cadence Service. -* -* \param cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam: The pointer to the -* cy_stc_ble_gattc_handle_value_ntf_param_t -* data structure specified by -* the event. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_RSCS_ApplCallback != NULL)) - { - if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_MEASUREMENT].charInfo.valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_rscs_char_value_t ntfParam = - { - .charIndex = CY_BLE_RSCS_RSC_MEASUREMENT, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSC_NOTIFICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_IndicationEventHandler -****************************************************************************//** -* -* Handles the Indication Event for the Running Speed and Cadence Service. -* -* \param cy_stc_ble_gattc_handle_value_ind_param_t *eventParam: The pointer to the -* cy_stc_ble_gattc_handle_value_ntf_param_t -* data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_RSCS_ApplCallback != NULL)) - { - if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].charInfo.valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_rscs_char_value_t ntfParam = - { - .charIndex = CY_BLE_RSCS_SC_CONTROL_POINT, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value, - }; - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSC_INDICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_ReadResponseEventHandler -****************************************************************************//** -* -* Handles the Read Response Event for the Running Speed and Cadence Service. -* -* \param cy_stc_ble_gattc_read_rsp_param_t *eventParam: The pointer to the data that came -* with a read response for RSCS. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrVal = 0u; - cy_en_ble_rscs_char_index_t idx; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_RSCS_ApplCallback != NULL) && - (cy_ble_rscscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_FEATURE].charInfo.valueHandle == - cy_ble_rscscReqHandle[discIdx]) - { - idx = CY_BLE_RSCS_RSC_FEATURE; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SENSOR_LOCATION].charInfo.valueHandle == - cy_ble_rscscReqHandle[discIdx]) - { - idx = CY_BLE_RSCS_SENSOR_LOCATION; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_MEASUREMENT].descriptors[CY_BLE_RSCS_CCCD] == - cy_ble_rscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - idx = CY_BLE_RSCS_RSC_MEASUREMENT; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].descriptors[CY_BLE_RSCS_CCCD] == - cy_ble_rscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrVal = 1u; - idx = CY_BLE_RSCS_SC_CONTROL_POINT; - } - else - { - /* No RSCS Characteristics were requested for read */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* Read response for characteristic */ - if(attrVal == 0u) - { - /* Fill Running Speed and Cadence Service read response parameter structure with - * Characteristic info. */ - cy_stc_ble_rscs_char_value_t rdRspParam = { .connHandle = eventParam->connHandle }; - - rdRspParam.charIndex = idx; - rdRspParam.value = &eventParam->value; - - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSC_READ_CHAR_RESPONSE, (void*)&rdRspParam); - } - else /* Read response for characteristic descriptor */ - { - /* Fill Running Speed and Cadence Service read response parameter structure with - * Characteristic Descriptor info. */ - cy_stc_ble_rscs_descr_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = idx, - .descrIndex = CY_BLE_RSCS_CCCD, - .value = &eventParam->value - }; - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSC_READ_DESCR_RESPONSE, (void*)&rdRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_rscscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_WriteResponseEventHandler -****************************************************************************//** -* -* Handles the Write Response Event for the Running Speed and Cadence Service. -* -* \param cy_stc_ble_conn_handle_t *eventParam: The pointer to the cy_stc_ble_conn_handle_t data -* structure. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t fFlag = 1u; - uint32_t attrType = 0u; - cy_en_ble_rscs_char_index_t idx; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_RSCS_ApplCallback != NULL) && - (cy_ble_rscscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_FEATURE].charInfo.valueHandle == - cy_ble_rscscReqHandle[discIdx]) - { - idx = CY_BLE_RSCS_RSC_FEATURE; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SENSOR_LOCATION].charInfo.valueHandle == - cy_ble_rscscReqHandle[discIdx]) - { - idx = CY_BLE_RSCS_SENSOR_LOCATION; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].charInfo.valueHandle == - cy_ble_rscscReqHandle[discIdx]) - { - idx = CY_BLE_RSCS_SC_CONTROL_POINT; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_MEASUREMENT].descriptors[CY_BLE_RSCS_CCCD] == - cy_ble_rscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrType = 1u; - idx = CY_BLE_RSCS_RSC_MEASUREMENT; - } - else if(cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].descriptors[CY_BLE_RSCS_CCCD] == - cy_ble_rscscReqHandle[discIdx]) - { - /* Attribute is Characteristic Descriptor */ - attrType = 1u; - idx = CY_BLE_RSCS_SC_CONTROL_POINT; - } - else - { - /* No RSCS Characteristics were requested for write */ - fFlag = 0u; - } - - if(fFlag != 0u) - { - /* This should be cleared before calling to */ - cy_ble_rscscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* Write response for characteristic */ - if(attrType == 0u) - { - /* Fill Running Speed and Cadence Service write response parameter structure with - * Characteristic info. */ - cy_stc_ble_rscs_char_value_t rdRspParam = { .connHandle = *eventParam }; - rdRspParam.charIndex = idx; - rdRspParam.value = NULL; - - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSC_WRITE_CHAR_RESPONSE, (void*)&rdRspParam); - } - else /* Write response for characteristic descriptor */ - { - /* Fill Running Speed and Cadence Service write response parameter structure with - * Characteristic Descriptor info. */ - cy_stc_ble_rscs_descr_value_t rdRspParam = { .connHandle = *eventParam }; - rdRspParam.charIndex = idx; - rdRspParam.descrIndex = CY_BLE_RSCS_CCCD; - rdRspParam.value = NULL; - - Cy_BLE_RSCS_ApplCallback((uint32_t)CY_BLE_EVT_RSCSC_WRITE_DESCR_RESPONSE, (void*)&rdRspParam); - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_ErrorResponseEventHandler -****************************************************************************//** -* -* Handles the Error Response Event for the Running Speed and Cadence Service. -* -* \param *eventParam: The pointer to the cy_stc_ble_gatt_err_param_t structure. -* -*******************************************************************************/ -static void Cy_BLE_RSCSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if(cy_ble_rscscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_rscscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_SetCharacteristicValue -****************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_RSCSS_WRITE_CHAR event is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: Size of the characteristic value attribute. -* \param attrValue: Pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the RSCS service-specific callback is registered -* (with Cy_BLE_RSCS_RegisterAttrCallback): -* * CY_BLE_EVT_RSCSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_rscs_char_value_t. -* . -* Otherwise (if the RSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (charIndex == CY_BLE_RSCS_SC_CONTROL_POINT)) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != - cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].charInfo.valueHandle) - { - /* Fill all fields of write command request structure ... */ - cy_stc_ble_gattc_write_req_t wrReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .handleValPair.attrHandle = cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT]. - charInfo.valueHandle, - .connHandle = connHandle - }; - /* Send request to write characteristic value */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&wrReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_rscscReqHandle[discIdx] = wrReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - /* apiResult equals to CY_BLE_ERROR_INVALID_PARAMETER */ - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_GetCharacteristicValue -****************************************************************************//** -* -* Sends a request to the peer device to set the characteristic value of the -* Running Speed and Cadence Service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the RSCS service-specific callback is registered -* (with Cy_BLE_RSCS_RegisterAttrCallback): -* * CY_BLE_EVT_RSCSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_rscs_char_value_t. -* . -* Otherwise (if the RSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex) -{ - cy_stc_ble_gattc_read_req_t readReqParam = { .connHandle = connHandle }; - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Select characteristic */ - switch(charIndex) - { - case CY_BLE_RSCS_RSC_FEATURE: - readReqParam.attrHandle = cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_FEATURE]. - charInfo.valueHandle; - break; - - case CY_BLE_RSCS_SENSOR_LOCATION: - readReqParam.attrHandle = cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SENSOR_LOCATION]. - charInfo.valueHandle; - break; - - default: - /* Characteristic wasn't found */ - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - break; - } - - if(apiResult == CY_BLE_SUCCESS) - { - if(readReqParam.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Send request to read characteristicW value */ - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_rscscReqHandle[discIdx] = readReqParam.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_SetCharacteristicDescriptor -****************************************************************************//** -* -* Sends a request to the peer device to get the characteristic descriptor of -* the specified characteristic of the Running Speed and Cadence Service. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_RSCSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_RSCSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_RSCSS_INDICATION_ENABLED -* * CY_BLE_EVT_RSCSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a RSCS characteristic. -* \param descrIndex: The index of a RSCS characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request was sent successfully -* * CY_BLE_ERROR_INVALID_STATE - connection with the client is not established -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the RSCS service-specific callback is registered -* (with Cy_BLE_RSCS_RegisterAttrCallback): -* * CY_BLE_EVT_RSCSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_rscs_descr_value_t. -* . -* Otherwise (if the RSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - cy_en_ble_rscs_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((attrValue != NULL) && (descrIndex == CY_BLE_RSCS_CCCD) && (attrSize == CY_BLE_CCCD_LEN)) - { - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && ((charIndex == CY_BLE_RSCS_RSC_MEASUREMENT) || - (charIndex == CY_BLE_RSCS_SC_CONTROL_POINT))) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .connHandle = connHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize - }; - if(charIndex == CY_BLE_RSCS_RSC_MEASUREMENT) - { - writeReqParam.handleValPair.attrHandle = - cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_MEASUREMENT].descriptors[CY_BLE_RSCS_CCCD]; - } - else - { - writeReqParam.handleValPair.attrHandle = - cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].descriptors[CY_BLE_RSCS_CCCD]; - } - - if(writeReqParam.handleValPair.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_rscscReqHandle[discIdx] = - cy_ble_rscsc[discIdx].characteristics[charIndex].descriptors[CY_BLE_RSCS_CCCD]; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - } - else - { - /* alidation of input parameters is failed */ - } - - /* Return the status */ - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RSCSC_GetCharacteristicDescriptor -****************************************************************************//** -* -* Sends a request to the peer device to get characteristic descriptor of the -* specified characteristic of the Running Speed and Cadence Service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a Service Characteristic. -* \param descrIndex: The index of a Service Characteristic Descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_INVALID_OPERATION - Cannot process a request to send PDU due to -* invalid operation performed by the -* application -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Peer device doesn't have a -* particular descriptor -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the RSCS service-specific callback is registered -* (with Cy_BLE_RSCS_RegisterAttrCallback): -* * CY_BLE_EVT_RSCSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_rscs_descr_value_t. -* . -* Otherwise (if the RSCS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RSCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - uint8_t descrIndex) -{ - cy_stc_ble_gattc_read_req_t readReqParam = { .connHandle = connHandle }; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && - ((charIndex == CY_BLE_RSCS_RSC_MEASUREMENT) || (charIndex == CY_BLE_RSCS_SC_CONTROL_POINT)) && - (descrIndex == (uint8_t)CY_BLE_RSCS_CCCD)) - { - if(charIndex == CY_BLE_RSCS_RSC_MEASUREMENT) - { - readReqParam.attrHandle = - cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_RSC_MEASUREMENT].descriptors[CY_BLE_RSCS_CCCD]; - } - else - { - readReqParam.attrHandle = - cy_ble_rscsc[discIdx].characteristics[CY_BLE_RSCS_SC_CONTROL_POINT].descriptors[CY_BLE_RSCS_CCCD]; - } - - if(readReqParam.attrHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_rscscReqHandle[discIdx] = readReqParam.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - else - { - /* Characteristic has not been discovered or had invalid fields */ - } - - return(apiResult); -} - -#endif /* (CY_BLE_RSCS_CLIENT) */ - -/****************************************************************************** -* Function Name: Cy_BLE_RSCS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Running Speed and Cadence Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_RSCS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_RSCS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_RSCSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_RSCSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_RSCSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_RSCS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_RSCS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_RSCSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_RSCSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATT_CONNECT_IND: - (void)Cy_BLE_RSCS_Init(cy_ble_rscsConfigPtr); - break; - #endif /* CY_BLE_RSCS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_RSCS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_RSCSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_RSCSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_RSCSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_RSCSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_RSCSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_RSCS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_RSCS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ - diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rscs.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rscs.h deleted file mode 100644 index 93374ffa73..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rscs.h +++ /dev/null @@ -1,225 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_rscs.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Running Speed and Cadence -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_RSCS_H -#define CY_BLE_RSCS_H - - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_RSCS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_RSCS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** RSCS Characteristic indexes */ -typedef enum -{ - CY_BLE_RSCS_RSC_MEASUREMENT, /**< RSC Measurement Characteristic index */ - CY_BLE_RSCS_RSC_FEATURE, /**< RSC Feature Characteristic index */ - CY_BLE_RSCS_SENSOR_LOCATION, /**< Sensor Location Characteristic index */ - CY_BLE_RSCS_SC_CONTROL_POINT, /**< SC Control Point Characteristic index */ - CY_BLE_RSCS_CHAR_COUNT /**< Total count of RSCS characteristics */ -} cy_en_ble_rscs_char_index_t; - -/** RSCS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_RSCS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_RSCS_DESCR_COUNT /**< Total count of descriptors */ -} cy_en_ble_rscs_descr_index_t; - -/** Running Speed and Cadence Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_rscs_char_index_t charIndex; /**< Index of Running Speed and Cadence Service Characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_rscs_char_value_t; - -/** Running Speed and Cadence Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_rscs_char_index_t charIndex; /**< Characteristic index of the Service */ - cy_en_ble_rscs_descr_index_t descrIndex; /**< Characteristic index Descriptor the Service */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of the Service Characteristic Descriptor */ -} cy_stc_ble_rscs_descr_value_t; - -/** RSCS Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of the characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_RSCS_DESCR_COUNT]; /**< Handle of the descriptor */ -} cy_stc_ble_rscss_char_t; - -/** Structure with Running Speed and Cadence Service attribute handles */ -typedef struct -{ - /** Running Speed and Cadence Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Array of Running Speed and Cadence Service Characteristics + Descriptors handles */ - cy_stc_ble_rscss_char_t charInfo[CY_BLE_RSCS_CHAR_COUNT]; -} cy_stc_ble_rscss_t; - -/** RSCS Service Full characteristic information type */ -typedef struct -{ - /** Characteristic handle + properties */ - cy_stc_ble_srvr_char_info_t charInfo; - - /** Characteristic descriptors handles handle */ - cy_ble_gatt_db_attr_handle_t descriptors[CY_BLE_RSCS_DESCR_COUNT]; - - /** End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t endHandle; -} cy_stc_ble_rscsc_srvr_full_char_info_t; - -/** Structure with discovered attributes information of Running Speed and Cadence Service */ -typedef struct -{ - /** Characteristics handles array */ - cy_stc_ble_rscsc_srvr_full_char_info_t characteristics[CY_BLE_RSCS_CHAR_COUNT]; -} cy_stc_ble_rscsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Running Speed and Cadence Service GATT DB handles structure */ - const cy_stc_ble_rscss_t *rscss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_rscs_config_t; -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_RSCS_INVALID_CHAR_INDEX (0xFFu) - -/* SC Control Point Characteristic Op Codes */ -#define CY_BLE_RSCS_SET_CUMMULATIVE_VALUE (0x01u) -#define CY_BLE_RSCS_START_SENSOR_CALIBRATION (0x02u) -#define CY_BLE_RSCS_UPDATE_SENSOR_LOCATION (0x03u) -#define CY_BLE_RSCS_REQ_SUPPORTED_SENSOR_LOCATION (0x04u) -#define CY_BLE_RSCS_RESPONSE_CODE (0x10u) - -/* SC Control Point Characteristic Response Codes */ -#define CY_BLE_RSCS_ERR_SUCCESS (0x01u) -#define CY_BLE_RSCS_ERR_OP_CODE_NOT_SUPPORTED (0x02u) -#define CY_BLE_RSCS_ERR_INVALID_PARAMETER (0x03u) -#define CY_BLE_RSCS_ERR_OPERATION_FAILED (0x04u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_RSCS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_RSCS_Init(cy_stc_ble_rscs_config_t *config); -cy_en_ble_api_result_t Cy_BLE_RSCS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#if defined(CY_BLE_RSCS_SERVER) -/** - * \addtogroup group_ble_service_api_RSCS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_RSCSS_SetCharacteristicValue(cy_en_ble_rscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RSCSS_GetCharacteristicValue(cy_en_ble_rscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RSCSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - cy_en_ble_rscs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RSCSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RSCSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_RSCS_SERVER */ - -#if defined(CY_BLE_RSCS_CLIENT) -/** - * \addtogroup group_ble_service_api_RSCS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_RSCSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RSCSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_RSCSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - cy_en_ble_rscs_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RSCSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rscs_char_index_t charIndex, - uint8_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_RSCS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#if defined(CY_BLE_RSCS_CLIENT) -extern cy_stc_ble_rscsc_t cy_ble_rscsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_RSCS_CLIENT) */ - -extern cy_stc_ble_rscs_config_t cy_ble_rscsConfig; -extern cy_stc_ble_rscs_config_t *cy_ble_rscsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_RSCS) */ -#endif /* CY_BLE_RSCS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rtus.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rtus.c deleted file mode 100644 index 541673f893..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rtus.c +++ /dev/null @@ -1,678 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_rtus.c -* \version 2.0 -* -* \brief -* Contains the source code for Reference Time Update Service. -* -******************************************************************************** -* -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_RTUS)) -static cy_ble_callback_t Cy_BLE_RTUS_ApplCallback = NULL; - -#if defined(CY_BLE_RTUS_CLIENT) -/* RTUS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_rtusc_t cy_ble_rtusc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_rtuscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_RTUS_CLIENT) */ - -/* The pointer on global BLE RTUS Config structure */ -cy_stc_ble_rtus_config_t *cy_ble_rtusConfigPtr = NULL; - - -/*************************************** -* Private Function Prototypes -***************************************/ -#if defined(CY_BLE_RTUS_SERVER) -static void Cy_BLE_RTUSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_RTUS_SERVER */ - -#if defined(CY_BLE_RTUS_CLIENT) -static void Cy_BLE_RTUSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_RTUSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_RTUSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -#endif /* (CY_BLE_RTUS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_RTUS_EventHandler(uint32_t eventCode, void *eventParam); - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUS_Init -****************************************************************************//** -* -* This function initializes the Reference Time Update Service. -* -* \param config: Configuration structure for Reference Time Update Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RTUS_Init(cy_stc_ble_rtus_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_rtusConfigPtr = config; - - /* Registers Event Handler for the RTUS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_RTUS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_rtusConfigPtr->callbackFunc != NULL) - { - Cy_BLE_RTUS_ApplCallback = cy_ble_rtusConfigPtr->callbackFunc; - } - #ifdef CY_BLE_RTUS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_RTUS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_rtusc[idx], 0, sizeof(cy_stc_ble_rtusc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_RTUS].uuid = CY_BLE_UUID_REF_TIME_UPDATE_SERVICE; - } - cy_ble_rtuscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_RTUS_CLIENT */ - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUS_RegisterAttrCallback -****************************************************************************//** -* -* Registers a callback function for Reference Time Update Service specific -* attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for RTUS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RTUS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_RTUS_ApplCallback = callbackFunc; - if(cy_ble_rtusConfigPtr != NULL) - { - cy_ble_rtusConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#if defined(CY_BLE_RTUS_SERVER) - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSS_WriteEventHandler -****************************************************************************//** -* -* Handles the Write Without Response Request Event for the Reference Time Update -* Service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t * eventParam: The pointer to a data structure -* specified by the event. -* -* -*******************************************************************************/ -static void Cy_BLE_RTUSS_WriteCmdEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - if(Cy_BLE_RTUS_ApplCallback != NULL) - { - /* Check if attribute handle is handle of Time Update Control Point - * Characteristic of Reference Time Update Service. */ - if((cy_ble_rtusConfigPtr->rtuss->timeUpdateCpHandle == eventParam->handleValPair.attrHandle) && - (CY_BLE_RTUS_TIME_UPDATE_CP_SIZE == eventParam->handleValPair.value.len) && - (CY_BLE_RTUS_CANCEL_REF_UPDATE >= eventParam->handleValPair.value.val[0u])) - { - /* Input parameters validation passed, so save Time Update Control Point value */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_rtus_char_value_t wrCmdParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT, - .value = &eventParam->handleValPair.value - }; - /* Send callback to user if no error occurred while writing Time Update Control - * Point. - */ - Cy_BLE_RTUS_ApplCallback((uint32_t)CY_BLE_EVT_RTUSS_WRITE_CHAR_CMD, (void*)&wrCmdParam); - cy_ble_eventHandlerFlag &= (uint8_t)(~CY_BLE_CALLBACK); - } - } - /* As this handler handles Write Without Response request the error response - * can't be sent for the Client. The erroneous value will be with - * CY_BLE_EVT_GATTS_WRITE_CMD_REQ event. User will decide how to handle it. */ - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSS_SetCharacteristicValue -****************************************************************************//** -* -* Sets characteristic value of the Reference Time Update Service, which is -* identified by charIndex in the local database. -* -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_rtus_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value -* data that should be stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request is handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameters failed -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RTUSS_SetCharacteristicValue(cy_en_ble_rtus_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_stc_ble_rtus_time_update_state_t tUState; - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if((CY_BLE_RTUS_CHAR_COUNT > charIndex)) - { - if(charIndex == CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_rtusConfigPtr->rtuss->timeUpdateCpHandle; - - if(*attrValue <= CY_BLE_RTUS_CANCEL_REF_UPDATE) - { - apiResult = CY_BLE_SUCCESS; - } - } - else - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_rtusConfigPtr->rtuss->timeUpdateStateHandle; - - tUState = *(cy_stc_ble_rtus_time_update_state_t*)attrValue; - - if((tUState.result <= CY_BLE_RTUS_RESULT_NO_UPDATE_ATTEMPT) && - (tUState.currentState <= CY_BLE_RTUS_CURR_STATE_UPDATE_PENDING)) - { - apiResult = CY_BLE_SUCCESS; - } - } - /* Store data in database */ - if(apiResult == CY_BLE_SUCCESS) - { - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSS_GetCharacteristicValue -****************************************************************************//** -* -* Gets a characteristic value of the Reference Time Update Service, which -* is identified by charIndex. -* -* \param charIndex: The index of a service characteristic of -* type cy_en_ble_rtus_char_index_t. -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the location where -* characteristic value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request is handled successfully; -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameter failed. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RTUSS_GetCharacteristicValue(cy_en_ble_rtus_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(CY_BLE_RTUS_CHAR_COUNT > charIndex) - { - /* Read characteristic value from database */ - if(charIndex == CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT) - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_rtusConfigPtr->rtuss->timeUpdateCpHandle; - } - else - { - dbAttrValInfo.handleValuePair.attrHandle = cy_ble_rtusConfigPtr->rtuss->timeUpdateStateHandle; - } - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - -#endif /* (CY_BLE_RTUS_SERVER) */ - - -#if defined(CY_BLE_RTUS_CLIENT) - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSC_DiscoverCharacteristicsEventHandler -****************************************************************************//** -* -* This function is called on receiving a "CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP" -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -* -*******************************************************************************/ -static void Cy_BLE_RTUSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* RTUS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_rtusCharUuid[CY_BLE_RTUS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_TIME_UPDATE_CONTROL_POINT, - CY_BLE_UUID_CHAR_TIME_UPDATE_STATE - }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_RTUS)) - { - for(i = 0u; i < (uint32_t)CY_BLE_RTUS_CHAR_COUNT; i++) - { - if(cy_ble_rtusCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_rtusc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_rtusc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_rtusc[discIdx].charInfo[i].properties = discCharInfo->properties; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_RTUSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_RTUSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_RTUS) - { - /* RTUS does not have any discriptions, return CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE */ - charRangeInfo->range.startHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - charRangeInfo->range.endHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSC_ReadResponseEventHandler -****************************************************************************//** -* -* Handles Read Response Event for Reference Time Update Service. -* -* \param eventParam: The pointer to the data that came with a read response for RTUS. -* -* -******************************************************************************/ -static void Cy_BLE_RTUSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_RTUS_ApplCallback != NULL) && - (cy_ble_rtuscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_rtusc[discIdx].charInfo[CY_BLE_RTUS_TIME_UPDATE_STATE].valueHandle == cy_ble_rtuscReqHandle[discIdx]) - { - /* Fill Reference Time Update Service read response parameter structure with - * characteristic info. - */ - cy_stc_ble_rtus_char_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_RTUS_TIME_UPDATE_STATE, - .value = &eventParam->value - }; - Cy_BLE_RTUS_ApplCallback((uint32_t)CY_BLE_EVT_RTUSC_READ_CHAR_RESPONSE, (void*)&rdRspParam); - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_rtuscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSC_SetCharacteristicValue -****************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_RTUSS_WRITE_CHAR_CMD event is generated. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* \param attrSize: Size of the characteristic value attribute. -* \param attrValue: Pointer to the characteristic value data -* that should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RTUSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rtus_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (charIndex == CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT) && - (cy_ble_rtusc[discIdx].charInfo[CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT].valueHandle != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - /* Fill all fields of write command request structure ... */ - cy_stc_ble_gattc_write_cmd_req_t wrReqParam = - { - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .handleValPair.attrHandle = cy_ble_rtusc[discIdx].charInfo[CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT].valueHandle, - .connHandle = connHandle - }; - /* Send request to write characteristic value */ - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&wrReqParam); - } - else - { - /* apiResult equals to CY_BLE_ERROR_INVALID_PARAMETER */ - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_RTUSC_GetCharacteristicValue -****************************************************************************//** -* -* Sends a request to a peer device to set characteristic value of the Reference -* Time Update Service, which is identified by charIndex. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - the request was sent successfully; -* * CY_BLE_ERROR_INVALID_STATE - connection with the Client is not established. -* * CY_BLE_ERROR_INVALID_PARAMETER - validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the RTUS service-specific callback is registered -* (with Cy_BLE_RTUS_RegisterAttrCallback): -* * CY_BLE_EVT_RTUSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_rtus_char_value_t. -* . -* Otherwise (if the RTUS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RTUSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rtus_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(discIdx >= CY_BLE_CONFIG_GATTC_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(charIndex == CY_BLE_RTUS_TIME_UPDATE_STATE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_rtusc[discIdx].charInfo[CY_BLE_RTUS_TIME_UPDATE_STATE].valueHandle, - .connHandle = connHandle - }; - /* Send request to read characteristic value */ - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_rtuscReqHandle[discIdx] = cy_ble_rtusc[discIdx].charInfo[CY_BLE_RTUS_TIME_UPDATE_STATE].valueHandle; - } - } - } - - return(apiResult); -} - - -#endif /* CY_BLE_RTUS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_RTUS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the for Reference Time Update Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_RTUS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_RTUS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_RTUSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_RTUSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_RTUS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_RTUS_SERVER - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - Cy_BLE_RTUSS_WriteCmdEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_RTUS_SERVER */ - - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_RTUS_CLIENT - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_RTUSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - #endif /* CY_BLE_RTUS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_RTUS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rtus.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rtus.h deleted file mode 100644 index 691bc1c807..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_rtus.h +++ /dev/null @@ -1,179 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_rtus.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Reference Time Update -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_RTUS_H -#define CY_BLE_RTUS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_RTUS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_RTUS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** Characteristic indexes */ -typedef enum -{ - CY_BLE_RTUS_TIME_UPDATE_CONTROL_POINT, /**< Time Update Control Point Characteristic index */ - CY_BLE_RTUS_TIME_UPDATE_STATE, /**< Time Update State Characteristic index */ - CY_BLE_RTUS_CHAR_COUNT /**< Total count of RTUS characteristics */ -} cy_en_ble_rtus_char_index_t; - -/** Reference Time Update Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_rtus_char_index_t charIndex; /**< Index of Reference Time Update Service Characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_rtus_char_value_t; - -/** Time Update State Characteristic structure */ -typedef struct -{ - uint8_t currentState; /**< Current state */ - uint8_t result; /**< Result of Time update */ -} cy_stc_ble_rtus_time_update_state_t; - -/** Structure with Reference Time Update Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Handle of the Reference Time Update Service */ - cy_ble_gatt_db_attr_handle_t timeUpdateCpHandle; /**< Handle of the Time Update Control Point Characteristic */ - cy_ble_gatt_db_attr_handle_t timeUpdateStateHandle; /**< Handle of the Time Update State Characteristic */ -} cy_stc_ble_rtuss_t; - -/** Structure with discovered attributes information of Reference Time Update Service */ -typedef struct -{ - /** Characteristic handle and properties */ - cy_stc_ble_srvr_char_info_t charInfo[CY_BLE_RTUS_CHAR_COUNT]; -} cy_stc_ble_rtusc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Reference Time Update Service GATT DB handles structure */ - const cy_stc_ble_rtuss_t *rtuss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_rtus_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_RTUS_TIME_UPDATE_CP_SIZE (0x01u) - -#define CY_BLE_RTUS_INVALID_CHAR_INDEX (0xFFu) - -/* Time Update Control Point Characteristic Values */ -#define CY_BLE_RTUS_GET_REF_UPDATE (0x01u) -#define CY_BLE_RTUS_CANCEL_REF_UPDATE (0x02u) - -/* Time Update State Characteristic Values - * Current State field - */ -#define CY_BLE_RTUS_CURR_STATE_IDLE (0x00u) -#define CY_BLE_RTUS_CURR_STATE_UPDATE_PENDING (0x01u) - -/* Result field */ -#define CY_BLE_RTUS_RESULT_SUCCESSFUL (0x00u) -#define CY_BLE_RTUS_RESULT_CANCELED (0x01u) -#define CY_BLE_RTUS_RESULT_NO_CONN (0x02u) -#define CY_BLE_RTUS_RESULT_REF_ERROR (0x03u) -#define CY_BLE_RTUS_RESULT_TIMEOUT (0x04u) -#define CY_BLE_RTUS_RESULT_NO_UPDATE_ATTEMPT (0x05u) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** - * \addtogroup group_ble_service_api_RTUS_server_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_RTUS_Init(cy_stc_ble_rtus_config_t *config); -cy_en_ble_api_result_t Cy_BLE_RTUS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); - -/** @} */ - -#if defined(CY_BLE_RTUS_SERVER) -/** - * \addtogroup group_ble_service_api_RTUS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_RTUSS_SetCharacteristicValue(cy_en_ble_rtus_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RTUSS_GetCharacteristicValue(cy_en_ble_rtus_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_RTUS_SERVER */ - -#if defined(CY_BLE_RTUS_CLIENT) -/** - * \addtogroup group_ble_service_api_RTUS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_RTUSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rtus_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_RTUSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_rtus_char_index_t charIndex); - -/** @} */ -#endif /* (CY_BLE_RTUS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#if defined(CY_BLE_RTUS_CLIENT) -extern cy_stc_ble_rtusc_t cy_ble_rtusc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_RTUS_CLIENT) */ - -extern cy_stc_ble_rtus_config_t cy_ble_rtusConfig; -extern cy_stc_ble_rtus_config_t *cy_ble_rtusConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_RTUS) */ -#endif /* CY_BLE_RTUS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_scps.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_scps.c deleted file mode 100644 index 95847ff238..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_scps.c +++ /dev/null @@ -1,1170 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_scps.c -* \version 2.0 -* -* \brief -* Contains the source code for the Scan Parameter service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_SCPS)) - -static cy_ble_callback_t Cy_BLE_SCPS_ApplCallback = NULL; - -#ifdef CY_BLE_SCPS_CLIENT -/* SCPS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_scpsc_t cy_ble_scpsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_scpscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -#endif /* CY_BLE_SCPS_SERVER */ - -/* The pointer on global BLE SCPS Config structure */ -cy_stc_ble_scps_config_t *cy_ble_scpsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_SCPS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_SCPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* CY_BLE_SCPS_SERVER */ - -#ifdef CY_BLE_SCPS_CLIENT -static void Cy_BLE_SCPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_SCPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_SCPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_SCPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_SCPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_SCPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_SCPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_SCPS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_SCPS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_SCPS_Init -***************************************************************************//** -* -* This function initializes the SCPS Service. -* -* \param config: Configuration structure for the SCPS Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPS_Init(cy_stc_ble_scps_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_scpsConfigPtr = config; - - /* Registers Event Handler for the SCPS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_SCPS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_scpsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_SCPS_ApplCallback = cy_ble_scpsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_SCPS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_SCPS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_scpsc[idx], 0, sizeof(cy_stc_ble_scpsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_SCPS].uuid = CY_BLE_UUID_SCAN_PARAM_SERVICE; - } - cy_ble_scpscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_SCPS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_SCPS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for ScPS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_SCPS_ApplCallback = callbackFunc; - if(cy_ble_scpsConfigPtr != NULL) - { - cy_ble_scpsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_SCPS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_SCPSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the Scan Parameters service, which is -* identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* * CY_BLE_SCPS_SCAN_INT_WIN - The Scan Interval Window characteristic index -* * CY_BLE_SCPS_SCAN_REFRESH - The Scan Refresh characteristic index -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSS_SetCharacteristicValue(cy_en_ble_scps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_ble_gatt_db_attr_handle_t charValueHandle; - uint16_t scanInterval; - uint16_t locScanWindow; - - if(charIndex >= CY_BLE_SCPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(charIndex == CY_BLE_SCPS_SCAN_INT_WIN) - { - scanInterval = Cy_BLE_Get16ByPtr(attrValue); - locScanWindow = Cy_BLE_Get16ByPtr(attrValue + sizeof(scanInterval)); - if((scanInterval < CY_BLE_SCAN_INTERVAL_WINDOW_MIN) || (scanInterval > CY_BLE_SCAN_INTERVAL_WINDOW_MAX) || - (locScanWindow < CY_BLE_SCAN_INTERVAL_WINDOW_MIN) || (locScanWindow > scanInterval) || - (attrSize > CY_BLE_INTERVAL_WINDOW_CHAR_LEN)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - charValueHandle = cy_ble_scpsConfigPtr->scpss->intervalWindowCharHandle; - } - } - else /* Scan Refresh characteristic */ - { - if(attrSize > CY_BLE_REFRESH_CHAR_LEN) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - charValueHandle = cy_ble_scpsConfigPtr->scpss->refreshCharHandle; - } - } - } - if(apiResult == CY_BLE_SUCCESS) - { - if(charValueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store data in database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = charValueHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSS_GetCharacteristicValue -****************************************************************************//** -* -* Gets a characteristic value of the Scan Parameters service, which is identified -* by charIndex. -* -* \param charIndex: The index of the service characteristic. -* * CY_BLE_SCPS_SCAN_INT_WIN - The Scan Interval Window characteristic index -* * CY_BLE_SCPS_SCAN_REFRESH - The Scan Refresh characteristic index -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSS_GetCharacteristicValue(cy_en_ble_scps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - cy_ble_gatt_db_attr_handle_t charValueHandle; - - if(charIndex >= CY_BLE_SCPS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(charIndex == CY_BLE_SCPS_SCAN_INT_WIN) - { - if(attrSize > CY_BLE_INTERVAL_WINDOW_CHAR_LEN) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - charValueHandle = cy_ble_scpsConfigPtr->scpss->intervalWindowCharHandle; - } - } - else /* Scan Refresh characteristic */ - { - if(attrSize > CY_BLE_REFRESH_CHAR_LEN) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - charValueHandle = cy_ble_scpsConfigPtr->scpss->refreshCharHandle; - } - } - } - if(apiResult == CY_BLE_SUCCESS) - { - if(charValueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Read characteristic value from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = charValueHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSS_GetCharacteristicDescriptor -****************************************************************************//** -* -* Gets a characteristic descriptor of the specified characteristic of the -* Scan Parameters service. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* * CY_BLE_SCPS_SCAN_REFRESH - The Scan Refresh characteristic index -* -* \param descrIndex: The index of the descriptor. -* * CY_BLE_SCPS_SCAN_REFRESH_CCCD - The Client Characteristic -* Configuration descriptor index of the Scan Refresh characteristic -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the location where the characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - cy_en_ble_scps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - if((charIndex != CY_BLE_SCPS_SCAN_REFRESH) || (descrIndex >= CY_BLE_SCPS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(cy_ble_scpsConfigPtr->scpss->refreshCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_scpsConfigPtr->scpss->refreshCccdHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSS_WriteEventHandler -****************************************************************************//** -* -* Handles the Write Request Event for the service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write request handled successfully. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Internal error while writing attribute value -* -*******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_SCPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - cy_stc_ble_scps_char_value_t locChar = { .connHandle = eventParam->connHandle }; - - if(Cy_BLE_SCPS_ApplCallback != NULL) - { - if((eventParam->handleValPair.attrHandle == cy_ble_scpsConfigPtr->scpss->refreshCccdHandle) || - (eventParam->handleValPair.attrHandle == cy_ble_scpsConfigPtr->scpss->intervalWindowCharHandle)) - { - /* Store value to database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - /* Client Characteristic Configuration descriptor write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_scpsConfigPtr->scpss->refreshCccdHandle) - { - uint32_t eventCode; - locChar.charIndex = CY_BLE_SCPS_SCAN_REFRESH; - locChar.value = NULL; - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_SCPSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_SCPSS_NOTIFICATION_DISABLED; - } - Cy_BLE_SCPS_ApplCallback(eventCode, &locChar); - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - else /* Scan Interval Window characteristic write without response request */ - { - locChar.charIndex = CY_BLE_SCPS_SCAN_INT_WIN; - locChar.value = &eventParam->handleValPair.value; - Cy_BLE_SCPS_ApplCallback((uint32_t)CY_BLE_EVT_SCPSS_SCAN_INT_WIN_WRITE_CHAR, &locChar); - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - - return(gattErr); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSS_SendNotification -****************************************************************************//** -* -* This function notifies the client that the server requires the Scan Interval -* Window Characteristic to be written with the latest values upon notification. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_SCPSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle -* -* \param charIndex: The index of the characteristic. -* * CY_BLE_SCPS_SCAN_REFRESH - The Scan Refresh characteristic index -* -* \param attrSize: The size of the characteristic value attribute. -* -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - if((charIndex != CY_BLE_SCPS_SCAN_REFRESH) || (attrSize != CY_BLE_REFRESH_CHAR_LEN)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((cy_ble_scpsConfigPtr->scpss->refreshCccdHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) || - (!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_scpsConfigPtr->scpss->refreshCccdHandle))) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_scpsConfigPtr->scpss->refreshCharHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - - return(apiResult); -} - -#endif /* CY_BLE_SCPS_SERVER */ - -#ifdef CY_BLE_SCPS_CLIENT - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_DiscoverCharacteristicsEventHandler -****************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event. -* Based on the service UUID, an appropriate data structure is populated using the -* data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -* -*******************************************************************************/ -static void Cy_BLE_SCPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_SCPS)) - { - switch(discCharInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_SCAN_REFRESH: - Cy_BLE_CheckStoreCharHandle(cy_ble_scpsc[discIdx].refreshChar); - break; - - case CY_BLE_UUID_CHAR_SCAN_WINDOW: - Cy_BLE_CheckStoreCharHandle(cy_ble_scpsc[discIdx].intervalWindowChar); - break; - - default: - break; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_DiscoverCharDescriptorsEventHandler -****************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* This event is generated when the server successfully sends the data for -* CY_BLE_EVT_GATTC_FIND_INFO_REQ. Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -* -*******************************************************************************/ -static void Cy_BLE_SCPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_SCPS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_scpsc[discIdx].refreshCccdHandle); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_SCPSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_SCPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_SCPS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if(cy_ble_discovery[discIdx].charCount == 0u) - { - /* One descriptor is available per characteristic */ - charRangeInfo->range.startHandle = cy_ble_scpsc[discIdx].refreshChar.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_SCPS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_SetCharacteristicValue -****************************************************************************//** -* -* Sets a characteristic value of the Scan Parameters Service, which is -* identified by charIndex. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_GATTC_WRITE_RSP -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* The CY_BLE_EVT_SCPSS_SCAN_INT_WIN_WRITE_CHAR event is received by the peer -* device on invoking this function. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if((charIndex != CY_BLE_SCPS_SCAN_INT_WIN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(cy_ble_scpsc[discIdx].intervalWindowChar.valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_cmd_req_t writeCmdParam = - { - .handleValPair.attrHandle = cy_ble_scpsc[discIdx].intervalWindowChar.valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteWithoutResponse(&writeCmdParam); - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_SetCharacteristicDescriptor -****************************************************************************//** -* -* Sets characteristic descriptor of specified characteristic of the Scan -* Parameters Service. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_SCPSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_SCPSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the SCPS service-specific callback is registered -* (with Cy_BLE_SCPS_RegisterAttrCallback): -* * CY_BLE_EVT_SCPSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_scps_descr_value_t. -* . -* Otherwise (if the SCPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - cy_en_ble_scps_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex != CY_BLE_SCPS_SCAN_REFRESH) || (descrIndex >= CY_BLE_SCPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(cy_ble_scpsc[discIdx].refreshChar.valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_scpsc[discIdx].refreshCccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_scpscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_GetCharacteristicDescriptor -****************************************************************************//** -* -* Gets characteristic descriptor of specified characteristic of the Scan -* Parameters Service. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_SCPSC_READ_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a Service Characteristic. -* \param descrIndex: The index of a Service Characteristic Descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the SCPS service-specific callback is registered -* (with Cy_BLE_SCPS_RegisterAttrCallback): -* * CY_BLE_EVT_SCPSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_scps_descr_value_t. -* . -* Otherwise (if the SCPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -*******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SCPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - cy_en_ble_scps_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex != CY_BLE_SCPS_SCAN_REFRESH) || (descrIndex >= CY_BLE_SCPS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - if(cy_ble_scpsc[discIdx].refreshChar.valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_scpsc[discIdx].refreshCccdHandle, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_scpscReqHandle[discIdx] = cy_ble_scpsc[discIdx].refreshCccdHandle; - } - } - } - - return(apiResult); -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_NotificationEventHandler -****************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_SCPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_SCPS_ApplCallback != NULL)) - { - if(cy_ble_scpsc[discIdx].refreshChar.valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_scps_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_SCPS_SCAN_REFRESH, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_SCPS_ApplCallback((uint32_t)CY_BLE_EVT_SCPSC_NOTIFICATION, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_ReadResponseEventHandler -****************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_SCPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_SCPS_ApplCallback != NULL) && - (cy_ble_scpscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_scpsc[discIdx].refreshCccdHandle == cy_ble_scpscReqHandle[discIdx]) - { - cy_stc_ble_scps_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_SCPS_SCAN_REFRESH, - .descrIndex = CY_BLE_SCPS_SCAN_REFRESH_CCCD, - .value = &eventParam->value - }; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_scpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_SCPS_ApplCallback((uint32_t)CY_BLE_EVT_SCPSC_READ_DESCR_RESPONSE, &locDescrValue); - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_WriteResponseEventHandler -****************************************************************************//** -* -* Handles the Write Response Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_SCPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_SCPS_ApplCallback != NULL) && - (cy_ble_scpscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_scpsc[discIdx].refreshCccdHandle == cy_ble_scpscReqHandle[discIdx]) - { - cy_stc_ble_scps_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_SCPS_SCAN_REFRESH, - .descrIndex = CY_BLE_SCPS_SCAN_REFRESH_CCCD, - .value = NULL - }; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_scpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_SCPS_ApplCallback((uint32_t)CY_BLE_EVT_SCPSC_WRITE_DESCR_RESPONSE, &locDescrValue); - } - } -} - - -/******************************************************************************* -* Function Name: Cy_BLE_SCPSC_ErrorResponseEventHandler -****************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -*******************************************************************************/ -static void Cy_BLE_SCPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - if(cy_ble_scpscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] == eventParam->errInfo.attrHandle) - { - cy_ble_scpscReqHandle[Cy_BLE_GetDiscoveryIdx(eventParam->connHandle)] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - -#endif /* (CY_BLE_SCPS_CLIENT) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_SCPS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Scan Parameter service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_SCPS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_SCPS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_SCPSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_SCPSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_SCPSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_SCPS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_SCPS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_SCPSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_WRITE_CMD_REQ: - (void)Cy_BLE_SCPSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_SCPS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_SCPS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_SCPSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_SCPSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_SCPSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_SCPSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_SCPS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_SCPS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_scps.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_scps.h deleted file mode 100644 index 08398ffe37..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_scps.h +++ /dev/null @@ -1,210 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_scps.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the Scan Parameter service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_SCPS_H -#define CY_BLE_SCPS_H - - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_SCPS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_SCPS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** ScPS Characteristic indexes */ -typedef enum -{ - CY_BLE_SCPS_SCAN_INT_WIN, /**< Scan Interval Window characteristic index */ - CY_BLE_SCPS_SCAN_REFRESH, /**< Scan Refresh characteristic index */ - CY_BLE_SCPS_CHAR_COUNT /**< Total count of characteristics */ -}cy_en_ble_scps_char_index_t; - -/** ScPS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_SCPS_SCAN_REFRESH_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_SCPS_DESCR_COUNT /**< Total count of descriptors */ -}cy_en_ble_scps_descr_index_t; - -/** Structure with Scan Parameters Service attribute handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Scan Parameter Service handle*/ - cy_ble_gatt_db_attr_handle_t intervalWindowCharHandle; /**< Handle of Scan Interval Window Characteristic */ - cy_ble_gatt_db_attr_handle_t refreshCharHandle; /**< Handle of Scan Refresh Characteristic */ - cy_ble_gatt_db_attr_handle_t refreshCccdHandle; /**< Handle of Client Characteristic Configuration Descriptor */ -} cy_stc_ble_scpss_t; - -/** Structure with discovered attributes information of Scan Parameters Service */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_stc_ble_srvr_char_info_t intervalWindowChar; /**< Handle + properties of Scan Interval Window Characteristic */ - cy_stc_ble_srvr_char_info_t refreshChar; /**< Handle + properties of Scan Refresh Characteristic */ - cy_ble_gatt_db_attr_handle_t refreshCccdHandle; /**< Handle of Client Characteristic Configuration Descriptor */ -} cy_stc_ble_scpsc_t; - -/** Scan Parameters Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_scps_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_scps_char_value_t; - -/** Scan Parameters Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_scps_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_scps_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_scps_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** Scan Parameter service GATT DB handles structure */ - const cy_stc_ble_scpss_t *scpss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_scps_config_t; - -/** @} */ - -/*************************************** -* API Constants -***************************************/ - -#define CY_BLE_SCAN_REFRESH_ENABLED (0x00u) -#define CY_BLE_SCAN_REFRESH_RESERVED (0xFFu) - -#define CY_BLE_REFRESH_CHAR_LEN (0x01u) -#define CY_BLE_INTERVAL_WINDOW_CHAR_LEN (0x04u) - -#define CY_BLE_SCAN_INTERVAL_WINDOW_MIN (0x0004u) -#define CY_BLE_SCAN_INTERVAL_WINDOW_MAX (0x4000u) - - -/*************************************** -* Macro Functions -***************************************/ - -#ifdef CY_BLE_SCPS_CLIENT - -#define Cy_BLE_SCPSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_SCPS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - ((charIndex) == CY_BLE_SCPS_SCAN_INT_WIN) ? \ - cy_ble_scpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].refreshChar.valueHandle : \ - cy_ble_scpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].intervalWindowChar.valueHandle) - -#define Cy_BLE_SCPSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) != CY_BLE_SCPS_SCAN_REFRESH) || \ - ((descrIndex) >= CY_BLE_SCPS_DESCR_COUNT)) ? CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_scpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].refreshCccdHandle) - -#endif /* (CY_BLE_SCPS_CLIENT) */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_SCPS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_SCPS_Init(cy_stc_ble_scps_config_t *config); -cy_en_ble_api_result_t Cy_BLE_SCPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_SCPS_SERVER -/** - * \addtogroup group_ble_service_api_SCPS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_SCPSS_SetCharacteristicValue(cy_en_ble_scps_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_SCPSS_GetCharacteristicValue(cy_en_ble_scps_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_SCPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - cy_en_ble_scps_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_SCPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_SCPS_SERVER */ - -#ifdef CY_BLE_SCPS_CLIENT -/** - * \addtogroup group_ble_service_api_SCPS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_SCPSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, uint8_t attrSize, - uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_SCPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - cy_en_ble_scps_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_SCPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_scps_char_index_t charIndex, - cy_en_ble_scps_descr_index_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_SCPS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_SCPS_CLIENT -extern cy_stc_ble_scpsc_t cy_ble_scpsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_SCPS_SERVER */ - -extern cy_stc_ble_scps_config_t cy_ble_scpsConfig; -extern cy_stc_ble_scps_config_t *cy_ble_scpsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_SCPS) */ -#endif /* CY_BLE_SCPH_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack.h deleted file mode 100644 index ac2a5428af..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack.h +++ /dev/null @@ -1,2160 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack.h -* \version 2.0 -* -* \brief -* This file contains the BLE Stack, which will be updated on the Jenkins -* build and the common structures, APIs. -* -******************************************************************************* -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -******************************************************************************/ - -#ifndef CY_BLE_STACK_H_ -#define CY_BLE_STACK_H_ - -/*************************************** -* Common stack includes -***************************************/ -#include "BLE_config.h" - -/*************************************** -** Constants -***************************************/ - -/** Stack Build Version Constants - It will be updated by Jenkins during build.*/ - -/** Major version number for device firmware. */ -#define CY_BLE_STACK_MAJOR (5u) - -/** Minor version number for device firmware. */ -#define CY_BLE_STACK_MINOR (0u) - -/** Patch version number for device firmware. */ -#define CY_BLE_STACK_PATCH (0u) - -/** Firmware build number. */ -#define CY_BLE_STACK_BUILD (785u) - -/** BT Address Size */ -#define CY_BLE_BD_ADDR_SIZE (0x06u) - -/** BLE Middleware ID */ -#define CY_BLE_ID (0x05ul << 18u) - -/** Memory pool configuration data defines*/ - -/** Size of internal data buffer structures */ -#define CY_BLE_STACK_BUFFER_MGR_UTIL_RAM_SZ (0x1Cu) - -/** Memory extension offset */ -#define CY_BLE_MEM_EXT_SZ (0x08u) - -/** Feature mask for 4.2 features */ -/** DLE feature */ -#define CY_BLE_DLE_FEATURE_MASK (0x01u) -/** Privacy 1.2 feature */ -#define CY_BLE_PRIVACY_1_2_FEATURE_MASK (0x02u) -/** Secured connection feature */ -#define CY_BLE_SECURE_CONN_FEATURE_MASK (0x04u) - -/** Feature mask for Shanghai features */ -#define CY_BLE_PHY_UPDATE_FEATURE_MASK (0x08u) - -/** Feature mask for persistent Store */ -/** Bondlist */ -#define CY_BLE_PERSISTENT_STORE_BONDLIST (0x10u) -/** Resolving list */ -#define CY_BLE_PERSISTENT_STORE_RESOLVING_LIST (0x20u) -/** whiteList */ -#define CY_BLE_PERSISTENT_STORE_WHITELIST (0x40u) -/** Radio power calibration*/ -#define CY_BLE_PERSISTENT_RADIO_CALIBRATION_MASK (0x80u) - -/** Feature mask bit-mask */ -#define CY_BLE_FEATURE_BIT_MASK (0x0FFu) - -/** Default RPA List Entry Size */ -#define CY_BLE_DEFAULT_RPA_LIST_SZ (0x10u) - -/** Default Bonded device List entry size */ -#define CY_BLE_DEFAULT_BONDED_DEVICE_LIST_SZ (0x10u) - -/** Resolving list memory computation - * CY_BLE_MAX_RESOLVABLE_DEVICES: - * It is user configured value for size of resolving list using BLE PDL. - * Range: 1 to 16, 0 if Privacy 1.2 feature is not used. - * Memory required = - * (((CY_BLE_LL_PRIVACY_HEAP_REQ * CY_BLE_MAX_RESOLVABLE_DEVICES) + - CY_BLE_LL_PRIVACY_RETENTION_HEAP_REQ) - * Note: - * This configurable memory should be added to - * CY_BLE_CONTROLLER_DEVICE_SPECIFIC_HEAP_REQ - * static macro value passed to BLE Stack. - */ - -/** Internal RAM required for resolving list retention data - * structure - */ -#define CY_BLE_LL_PRIVACY_RETENTION_HEAP_REQ (0x0Cu) - -/** Internal RAM required for single resolving list entry - */ -#define CY_BLE_LL_PRIVACY_HEAP_REQ (0x44u) - -/** Whitelist list memory computation - * CY_BLE_MAX_WHITELIST_LIST_SZ: - * It is a user-configured value for the size of the Whitelist using the BLE PDL. - * Range: 1 to 16. - * Memory required = - * (((CY_BLE_LL_ONE_WHITELIST_HEAP_REQ * CY_BLE_MAX_WHITELIST_LIST_SZ) + - CY_BLE_LL_WHITELIST_RETENTION_HEAP_REQ) - * Note: - * This configurable memory should be added to - * the CY_BLE_CONTROLLER_DEVICE_SPECIFIC_HEAP_REQ - * static macro value passed to the BLE Stack. - */ - -/** Max WhiteList size supported by BLE Stack */ -#define CY_BLE_MAX_WHITELIST_LIST_SZ (0x10u) - -/** LL Whitelist retention heap requirement */ -#define CY_BLE_LL_WHITELIST_RETENTION_HEAP_REQ (0x08u) - -/** LL whiteList size for one entity */ -#define CY_BLE_LL_ONE_WHITELIST_HEAP_REQ (0x08u) - -/** Convert Octets to Bits. */ -#define CY_BLE_OCTETS_TO_BITS(octets) ((octets) << 3) - -/** Convert LL Data Octets to Time in micro-seconds - 1Mbps */ -#define CY_BLE_DATA_OCTETS_TO_US_1MBPS(octets) (CY_BLE_OCTETS_TO_BITS((octets) + 14)) -/** Convert LL Data Octets to Time in micro-seconds - 2Mbps */ -#define CY_BLE_DATA_OCTETS_TO_US_2MBPS(octets) (CY_BLE_OCTETS_TO_BITS(((octets) + 15) >> 1)) - - -/** Total Command Buffers Chunks for Command Buffer Pool */ -#define CY_BLE_BT_FW_LE_CMD_BUFFERS (0x05u) - -/** Event Buffer Pool 1 */ -#define CY_BLE_BT_FW_LE_EVENT_TYPE1_BUFFERS (0x01u) - -/** Event Buffer Pool 2 */ -#define CY_BLE_BT_FW_LE_EVENT_TYPE2_BUFFERS (0x08u) - -/** Per Connection LL Control PDU Size for Tx */ -#define CY_BLE_BT_FW_TX_LL_PDU_Q_SZ (0x02u) - -/** Per Connection LL Control PDU Size for Rx */ -#define CY_BLE_BT_FW_RX_LL_PDU_Q_SZ (0x02u) - -/** Firmware total LE pdu packets */ -#define CY_BLE_BT_FW_LE_TOTAL_PDU_PKTS (CY_BLE_BT_FW_TX_LL_PDU_Q_SZ + \ - CY_BLE_BT_FW_RX_LL_PDU_Q_SZ) - -/** Encryption and Connection Parameter Update */ -#define CY_BLE_BT_FW_LE_TXN_BUFFERS (0x02u) - - -/** HCI Command Buffers per single Command Buffer Pool*/ -#define CY_BLE_HCI_LE_CMD_BUFFER_SZ (0x50u) - -/** Event packet size - * Max size for HCI LE event is 64 bytes - * Total size = 2 * (64 + 4(Event Header) + 4) - */ -#define CY_BLE_HCI_LE_EVENT_BUFFER_POOL_TYPE1_SZ (0x48u) - -/** Event buffer pool for rest of the le single mode events.*/ -#define CY_BLE_HCI_LE_EVENT_BUFFER_POOL_TYPE2_SZ (0x30u) - -/** - * LL Control Data channel PDU = - * 27 bytes - * MIC = 4 Bytes - * 1 byte llh_connection_index - * Following buffers are reserved for a single connection - * for Multiple connections deciding the actual number of PDU buffers - */ -#define CY_BLE_LL_PDU_MAX_BUFFER_SZ (0x20u) - -/** As of now 64 bytes per txn */ -#define CY_BLE_LL_LE_TXN_BUFFER_SZ (0x40u) - -/** Memory pool item size*/ -#define CY_BLE_MEM_POOL_ITEM_SZ (0x04u) - -/** BLE Dle device param size */ -#define CY_BLE_DLE_DEVICE_PARAM_SZ (0x10u) - -/** controller per connection data struct heap size */ -#define CY_BLE_CONTROLLER_PER_CONN_DATA_STRUCT_HEAP_SZ (0x0110u) - -/** Heap Reserve for Controller Stack */ -#define CY_BLE_BT_FW_HEAP_RESERVE_REQ (0x80u) - -/** Device Specific Pool Memory for BLESS RX FIFO, HCI Command and - * HCI Events memory */ -#define CY_BLE_BT_FW_DEV_SPECIFIC_POOL_REQ (CY_BLE_BT_FW_RX_ACL_MEM_POOL_REQ + \ - CY_BLE_BT_FW_CMD_MEM_POOL_REQ + \ - CY_BLE_BT_FW_EVENT_MEM_POOL_REQ) -/** device specific controller heap requirement */ -#define CY_BLE_CONTROLLER_DEVICE_SPECIFIC_HEAP_REQ \ - ((CY_BLE_BT_FW_LE_EVENT_TYPE1_BUFFERS * \ - (CY_BLE_HCI_LE_EVENT_BUFFER_POOL_TYPE1_SZ + CY_BLE_MEM_POOL_ITEM_SZ)) + \ - (CY_BLE_BT_FW_LE_EVENT_TYPE2_BUFFERS * \ - (CY_BLE_HCI_LE_EVENT_BUFFER_POOL_TYPE2_SZ + CY_BLE_MEM_POOL_ITEM_SZ)) + \ - (CY_BLE_BT_FW_LE_CMD_BUFFERS * \ - (CY_BLE_HCI_LE_CMD_BUFFER_SZ + CY_BLE_MEM_POOL_ITEM_SZ)) + \ - ((CY_BLE_STACK_BUFFER_MGR_UTIL_RAM_SZ * \ - CY_BLE_BT_FW_DEV_SPECIFIC_POOL_REQ) + \ - CY_BLE_BT_FW_HEAP_RESERVE_REQ)) - - -/** Configurable Memory for Stack Manager Buffer Pool Data Structures for - * buffer pools that are created and maintained. - */ - /** Tx acl memory requirement */ -#define CY_BLE_BT_FW_TX_ACL_MEM_POOL_REQ (0x01u) -/** firmware pdu memory requirement */ -#define CY_BLE_BT_FW_PDU_MEM_POOL_REQ (0x02u) -/** firmware transaction memory requirement */ -#define CY_BLE_BT_FW_TXN_MEM_POOL_REQ (0x01u) - -/** Heap required to for buffer pools that are created per connection - * Formula for total pools: - * (4 * no. of connections) - */ -#define CY_BLE_BT_FW_CONN_SPECIFIC_POOL_REQ (CY_BLE_BT_FW_TX_ACL_MEM_POOL_REQ + \ - CY_BLE_BT_FW_PDU_MEM_POOL_REQ + \ - CY_BLE_BT_FW_TXN_MEM_POOL_REQ) -/** controller connection specific heap requirement */ - #define CY_BLE_CONTROLLER_CONN_SPECIFIC_HEAP_REQ \ - ((CY_BLE_BT_FW_LE_TOTAL_PDU_PKTS * \ - (CY_BLE_LL_PDU_MAX_BUFFER_SZ + CY_BLE_MEM_POOL_ITEM_SZ)) + \ - (CY_BLE_BT_FW_LE_TXN_BUFFERS * \ - (CY_BLE_LL_LE_TXN_BUFFER_SZ + CY_BLE_MEM_POOL_ITEM_SZ)) + \ - (CY_BLE_BT_FW_CONN_SPECIFIC_POOL_REQ * \ - CY_BLE_STACK_BUFFER_MGR_UTIL_RAM_SZ) + \ - (CY_BLE_CONTROLLER_PER_CONN_DATA_STRUCT_HEAP_SZ)) - -/** Rx acl memory requirement */ -#define CY_BLE_BT_FW_RX_ACL_MEM_POOL_REQ (0x01u) -/** firmware command memory requirement */ -#define CY_BLE_BT_FW_CMD_MEM_POOL_REQ (0x01u) -/** firmware event memory requirement */ -#define CY_BLE_BT_FW_EVENT_MEM_POOL_REQ (0x02u) - -/** Size of the heap when the BLE Stack is built in HCI mode */ -#define CY_BLE_DEFAULT_CONTROLLER_RAM_SIZE (0u) - -/** Default Max ACL Packet Size for LE-DATA packet both for */ -#define CY_BLE_LL_DEFAULT_MAX_SUPPORTED_ACL_BUFFER_SZ (0xFCu) - -/** Default Max ACL Packet Size for Rx LE-DATA Packet - * Formulae: Default ACL Size (27 bytes) ~ AlignToWord(27) = 28 - * */ -#define CY_BLE_LL_DEFAULT_ACL_MAX_RX_BUFFER_SZ (0x1Cu) - -/** 8 Additional Bytes = (4 bytes of MIC + 4 bytes of HCI header) */ -#define CY_BLE_LL_ACL_DATA_PACKET_OVERHEAD_SZ (0x08u) - -/** Number of Rx ACL Packet buffers, this shall not change - * as this should not be user configurable parameter */ -#define CY_BLE_LL_DEFAULT_NUM_ACL_RX_PACKETS (0x04u) - -/** Number of Tx ACL Packet buffers */ -#define CY_BLE_LL_DEFAULT_NUM_ACL_TX_PACKETS (0x03u) - -/** Default Tx capability. If DLE is not enabled, this is Tx capability*/ -#define CY_BLE_LL_DEFAULT_TX_CAPABILITY (0x1Bu) - -/** Default Rx capability. If DLE is not enabled, this is Rx capability*/ -#define CY_BLE_LL_DEFAULT_RX_CAPABILITY (0x1Bu) - -/** Default Tx capability. If DLE is not enabled, this is Tx capability*/ -#define CY_BLE_MAX_DEFAULT_TX_CAPABILITY (0xFBu) - -/** Default Rx capability. If DLE is not enabled, this is Rx capability*/ -#define CY_BLE_MAX_DEFAULT_RX_CAPABILITY (0xFBu) - -/** Internal heap required for LE Data Length Extension Feature Per - * Connection */ -#define CY_BLE_LL_DLE_HEAP_REQ (0x40u) - -/** DLE heap required for device specific parameters */ -#define CY_BLE_LL_DLE_DEVICE_PARAM_HEAP_REQ (0x10u) - -/** Default RPA List Entry Size - * DKSH: RPA list support is limited to 8 only for time being */ -#define CY_BLE_MAX_RPA_LIST_SZ (0x10u) - -/** CY pipe client IDs for BLE */ -#define CY_BLE_PIPE_BLE_MSG_COMPLETE_ID (0u) /**< msg complete */ -#define CY_BLE_PIPE_BLE_MSG_SEND_ID (1u) /**< msg send */ - -/** Mask to disable all events */ -#define CY_BLE_DISABLE_ALL_EVENTS_MASK (0x00u) - -/** Mask to Enable connection established events */ -#define CY_BLE_CONN_ESTB_EVENT_MASK (0x01u) - -/** Length of mask byte array */ -#define CY_BLE_EVENT_MASK_LENGTH (1u) - -/** Event Mask index 0 */ -#define CY_BLE_EVENT_MASK_INDEX_0 (0u) - -/*************************************** -** Enumerated Types -***************************************/ - -/** - \addtogroup group_ble_common_api_events - @{ -*/ - -/** BLE stack events */ -typedef enum -{ - /** This event is triggered by the BLE stack when the stack is in a bad state. Restarting the stack is the - only way to get out of the state */ - CY_BLE_EVT_INVALID = 0x0000u, - - /* Range for Generic events - 0x1000 to 0x1FFF */ - - /** This event is received when the BLE stack is initialized and turned ON by invoking the Cy_BLE_StackInit () function.*/ - CY_BLE_EVT_STACK_ON = 0x1000u, - - /** This event is received when there is a timeout and the application must handle the event. - Event parameter is of type 'cy_stc_ble_timeout_param_t'. - - If reasonCode is 'CY_BLE_GATT_RSP_TO', then look for connHandle. - - If reasonCode is 'CY_BLE_GENERIC_APP_TO', then look for timerHandle. - - All other cases connHandle or timerHandle is ignored*/ - CY_BLE_EVT_TIMEOUT, /* 0x1001u */ - - /** This event is triggered by host stack whether the BLE stack is busy or not. - The Event Parameter corresponding to this event will indicate the state of BLE stack's internal protocol buffers - for the application to safely initiate data transactions (GATT, GAP Security, and L2CAP transactions) - with the peer BLE device. - Event parameter is of type cy_stc_ble_l2cap_state_info_t. - cy_stc_ble_l2cap_state_info_t contains flowState and Bd handle as parameters - flowState indicates the following state: - * CY_BLE_STACK_STATE_BUSY (0x01) = CY_BLE_STACK_STATE_BUSY indicates to the application that the BLE Stack's internal buffers - * are about to be filled, and the remaining buffers are required to respond to the peer BLE device. - * After this event, the application shall not initiate GATT, GAP Security, or L2CAP data transactions. - * However, the application shall respond to peer initiated transactions to prevent BLE protocol timeouts - * from occuring. - * Application-initiated data transactions can be resumed after the CY_BLE_EVT_STACK_BUSY_STATUS - * event with parameter 'CY_BLE_STACK_STATE_FREE' is received. - * - * CY_BLE_STACK_STATE_FREE (0x00) = CY_BLE_STACK_STATE_FREE indicates to the application that pending transactions are completed - * and sufficient buffers are available to process application-initiated transactions. - * The 'CY_BLE_EVT_STACK_BUSY_STATUS' event with 'CY_BLE_STACK_STATE_FREE' indicates to the - * application whether the BLE Stack's internal buffer state has transitioned from 'CY_BLE_STACK_STATE_BUSY' - * to 'CY_BLE_STACK_STATE_FREE'. - * - Bd handle indicates connection. - To increase the BLE Stack's default queue depth(CY_BLE_L2CAP_STACK_Q_DEPTH_PER_CONN) and achieve better throughput for the attribute MTU greater than 32, - use the AddQdepthPerConn parameter in the Expression view of the Advanced tab. - */ - CY_BLE_EVT_STACK_BUSY_STATUS, /* 0x1002u */ - - /** This event is received when the stack wants the application to provide memory to process a remote request. - The event parameter is of type cy_stc_ble_memory_request_t. - This event is automatically handled by the component for the CY_BLE_PREPARED_WRITE_REQUEST request. - The component allocates sufficient memory for the long write request with the assumption that attribute MTU size - is negotiated to the minimum possible value. The application could use dynamic memory allocation to save static - RAM memory consumption. To enable this event for the application level, set the EnableExternalPrepWriteBuff parameter - in the Expression view of the Advanced tab to be true. - */ - CY_BLE_EVT_MEMORY_REQUEST, /* 0x1003u */ - - /** This event is used to inform the application that a flash write is pending. - Stack internal data structures are modified and require backup. */ - CY_BLE_EVT_PENDING_FLASH_WRITE, /* 0x1004u */ - - /** This event is used to inform the application that persistent data stored in flash memory is corrupted - */ - CY_BLE_EVT_FLASH_CORRUPT, /* 0x1005u */ - - /* Range for HCI events - 0x2000 to 0x2FFF */ - - /** This event indicates that some internal hardware error has occurred. - * Reset of the hardware may be required. - * Event parameter is (uint8 *). The possible error codes for this event are defined - * in cy_ble_stack_host_error.h file. - */ - CY_BLE_EVT_HARDWARE_ERROR = 0x2000, - - /** This event is triggered on successful setting of Authentication Payload timeout in the BLE Controller for - * LE_PING feature. Refer to Bluetooth 4.1 core specification, Volume 6, Part B, - * section 4.6.5 for LE Ping operation. - * Event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is bdHandle (uint8_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_WRITE_AUTH_PAYLOAD_TO_COMPLETE, /* 0x2001u */ - - /** This event carries Authentication Payload timeout in the BLE Controller for the LE_PING feature. - * Refer to Bluetooth 4.1 core specification, Volume 6, Part B, section 4.6.5 for LE Ping operation. - * Event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_auth_payload_info_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_READ_AUTH_PAYLOAD_TO_COMPLETE, /* 0x2002u */ - - /** This event indicates a channel map corresponding to one connection. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_channel_map_info_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_GET_CHANNEL_MAP_COMPLETE, /* 0x2003u */ - - /** This event indicates completion of the Set LE event mask. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_LE_SET_EVENT_MASK_COMPLETE, /* 0x2004u */ - - /** LE PING Authentication Timeout Event to indicate that the peer device has not responded - with the valid MIC packet within the application configured ping authentication time. */ - CY_BLE_EVT_LE_PING_AUTH_TIMEOUT, /* 0x2005u */ - - /** This event indicates completion of the Set data length command. - * Event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is bdHandle (uint8_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_SET_DATA_LENGTH_COMPLETE, /* 0x2006u */ - - /** This event indicates completion of Set suggested data length command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_SUGGESTED_DATA_LENGTH_COMPLETE, /* 0x2007u */ - - /** This event indicates completion of Cy_BLE_GetDataLength API. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is cy_stc_ble_data_length_param_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_GET_DATA_LENGTH_COMPLETE, /* 0x2008u */ - - /** The LE Data Length Change event notifies the Host of a change to either the maximum Payload length or - * the maximum transmission time of Data Channel PDUs in either direction. The values reported are the maximum - * that will actually be used on the connection following the change. - * The event parameter is of type 'cy_stc_ble_data_length_change_event_param_t' - */ - CY_BLE_EVT_DATA_LENGTH_CHANGE, /* 0x2009u */ - - /** This event indicates peer resolvable private address currently used by the BLE Controller. - * Event parameter is (*cy_stc_ble_events_param_generic_t) - * eventParams member of cy_stc_ble_events_param_generic_t is peer resolvable address (uint8_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_GET_PEER_RPA_COMPLETE, /* 0x200Au */ - - /** This event indicates local resolvable private address currently used by the BLE Controller. - * The event parameter is (*cy_stc_ble_events_param_generic_t) - * eventParams member of cy_stc_ble_events_param_generic_t is local resolvable address (uint8_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_GET_LOCAL_RPA_COMPLETE, /* 0x200Bu */ - - /** This event indicates completion of the Set RPA timeout command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_RPA_TO_COMPLETE, /* 0x200Cu */ - - /** This event indicates completion of Set RPA enable command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_RPA_ENABLE_COMPLETE, /* 0x200Du */ - - /** This event indicates completion of the Set host channel command. - * the event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_HOST_CHANNEL_COMPLETE, /* 0x200Eu */ - - /** This event indicates completion of the add device to resolving list command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_ADD_DEVICE_TO_RPA_LIST_COMPLETE, /* 0x200Fu */ - - /** This event indicates completion of the remove device from resolving list command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_REMOVE_DEVICE_FROM_RPA_LIST_COMPLETE, /* 0x2010u */ - - /** This event indicates completion of the add device to white list command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_ADD_DEVICE_TO_WHITE_LIST_COMPLETE, /* 0x2011u */ - - /** This event indicates completion of the remove device from the Whitelist command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_REMOVE_DEVICE_FROM_WHITE_LIST_COMPLETE, /* 0x2012u */ - - /** This event indicates completion of the Cy_BLE_GetPhy API. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_phy_param_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_GET_PHY_COMPLETE, /* 0x2013u */ - - /** This event indicates completion of the Cy_BLE_SetDefaultPhy API. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is NULL - */ - CY_BLE_EVT_SET_DEFAULT_PHY_COMPLETE, /* 0x2014u */ - - /** This event indicates completion of the Cy_BLE_SetPhy API. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is NULL - */ - CY_BLE_EVT_SET_PHY_COMPLETE, /* 0x2015u */ - - /** This event indicates that the Controller has changed the transmitter PHY or receiver PHY in use. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_phy_param_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_PHY_UPDATE_COMPLETE, /* 0x2016u */ - - /** This event indicates completion of the set privacy mode command. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_PRIVACY_MODE_COMPLETE, /* 0x2017u */ - - /* Range for vendor events - 0x3000 to 0x5FFF */ - - /** This event indicates completion of the Cy_BLE_isLLControlProcPending API. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_ll_cntrl_proc_param_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_LL_CNTRL_PROC_PENDING_COMPLETE = 0x3000u, - - /** This event indicates a soft reset completed successfully. - * The event parameter is NULL. - */ - CY_BLE_EVT_SOFT_RESET_COMPLETE, /* 0x3001u */ - - /** This event indicates the set device address command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_DEVICE_ADDR_COMPLETE, /* 0x3002u */ - - /** This event indicates the get device address command completed successfully. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_bd_addrs_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_GET_DEVICE_ADDR_COMPLETE, /* 0x3003u */ - - /** This event indicates the get RSSI command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_rssi_info_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_GET_RSSI_COMPLETE, /* 0x3004u */ - - /** This event indicates the get Tx Power command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is powerLevel (cy_stc_ble_tx_pwr_lvl_info_t*) - * eventParams is valid only if status is success (0x00) - * bdHandle is valid only if bleSsChId is CY_BLE_LL_CONN_CH_TYPE - */ - CY_BLE_EVT_GET_TX_PWR_COMPLETE, /* 0x3005u */ - - /** This event indicates the set Tx Power command completed . - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is powerConfig (cy_stc_ble_tx_pwr_config_param_t*) - * eventParams is valid only if status is success (0x00) - */ - CY_BLE_EVT_SET_TX_PWR_COMPLETE, /* 0x3006u */ - - /** This event indicates the get clockl config command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is powerLevel (cy_stc_ble_bless_clk_cfg_params_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_GET_CLK_CONFIG_COMPLETE, /* 0x3007u */ - - /** This event indicates the set clock config command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_SET_CLK_CONFIG_COMPLETE, /* 0x3008u */ - - /** This event indicates the random number generation command completed successfully. - The event parameter is Pointer to a buffer of size 8 bytes */ - CY_BLE_EVT_RANDOM_NUM_GEN_COMPLETE, /* 0x3009u */ - - /** This event indicates the AES encrypt command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is pointer to encrypted data (128-bit)(uint8_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_AES_ENCRYPT_COMPLETE, /* 0x300Au */ - - /** This event indicates the AES CCM encrypt command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is pointer to cy_stc_ble_aes_ccm_param_t - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_AES_CCM_ENCRYPT_COMPLETE, /* 0x300Bu */ - - /** This event indicates the AES CCM decrypt command completed. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is pointer to cy_stc_ble_aes_ccm_param_t - * eventParams is valid only if status is Success(0x00).eventParams->mic to be ignored. - */ - CY_BLE_EVT_AES_CCM_DECRYPT_COMPLETE, /* 0x300Cu */ - - /* 0x300Du -> Reserved for future*/ - - /* 0x300Eu -> Reserved for future*/ - - /* 0x300Fu -> Reserved for future*/ - - /* 0x3010u -> Reserved for future*/ - - /** This event is triggered for Cy_BLE_GetBatteryLevel API. - * Event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is bdHandle (uint8_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_SET_SLAVE_LATENCY_MODE_COMPLETE = 0x3011u, /* 0x3011u */ - - /** This event is used to inform the application that stack shutdown is completed. - * The event parameter is NULL. - */ - CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE, /* 0x3012u */ - - /** This event is used to inform the application of temperature data as measured. Event parameter is of 'uint16_t' */ - CY_BLE_EVT_RADIO_TEMPERATURE, /* 0x3013u */ - - /** This event is used to inform the application of voltage data as measured. Event parameter is of 'uint16_t' */ - CY_BLE_EVT_RADIO_VOLTAGE_LEVEL, /* 0x3014u */ - - /** This event is used to inform the application that the AES CMAC generation is completed - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_AES_CMAC_GEN_COMPLETE, /* 0x3015 */ - - /** This event is triggered on completion of setting vendor event mask. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * Only status is valid. eventParams is not used - */ - CY_BLE_EVT_SET_EVENT_MASK_COMPLETE, /* 0x3016u */ - - /** This event is triggered on completion of setting vendor event mask. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is bdHandle (uint8_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_SET_CE_LENGTH_COMPLETE, /* 0x3017u */ - - /** This event is triggered on completion of setting vendor event mask. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is bdHandle (uint8_t*) - * eventParams is valid only if status is Success(0x00) - */ - CY_BLE_EVT_SET_CONN_PRIORITY_COMPLETE, /* 0x3018u */ - - /* Range for GAP events - 0x4000 to 0x4FFF */ - - /** This event is triggered every time a device is discovered. A pointer to structure of type - * cy_stc_ble_gapc_adv_report_param_t is returned as the event parameter. - */ - CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT = 0x4000u, - - /** This event is received by Peripheral and Central devices. When it is received by a peripheral, that peripheral - must Call Cy_BLE_GAPP_AuthReqReply() to reply to the authentication request from Central. - - When this event is received by Central, that means the slave has requested Central to initiate authentication - procedure. Central must call Cy_BLE_GAP_AuthReq() to initiate the authentication procedure. - A pointer to structure of type cy_stc_ble_gap_auth_info_t is returned as the event parameter. */ - CY_BLE_EVT_GAP_AUTH_REQ, /* 0x4001u */ - - /** This event indicates that the device must send a passkey to be used during the pairing procedure. - Cy_BLE_GAP_AuthPassKeyReply() is required to be called with valid parameters on receiving this event. - - cy_stc_ble_gap_auth_pk_info_t is returned as the event parameter. bdHandle is the only relevant parameter. - Other parameters should be ignored. */ - CY_BLE_EVT_GAP_PASSKEY_ENTRY_REQUEST, /* 0x4002u */ - - /** This event indicates that the device needs to display a passkey during the pairing procedure. - cy_stc_ble_gap_auth_pk_info_t is returned as the event parameter. bdHandle and passkey are relevant parameters. - Other parameter(s) should be ignored. - The passkey can be any 6-decimal-digit value. */ - CY_BLE_EVT_GAP_PASSKEY_DISPLAY_REQUEST, /* 0x4003u */ - - /** This event indicates that the authentication procedure has been completed. - - The event parameter contains the security information as defined by cy_stc_ble_gap_auth_info_t. - This event is generated at the end of the following three operations: - * Authentication is initiated with a newly connected device - * Encryption is initiated with a connected device that is already bonded - * Re-Encryption is initiated with a connected device with link already encrypted - During encryption/re-encryption, the Encryption Information exchanged during the pairing process - is used to encrypt/re-encrypt the link. As this does not modify any of the authentication - parameters with which the devices were paired, this event is generated with NULL event data - and the result of the encryption operation. */ - CY_BLE_EVT_GAP_AUTH_COMPLETE, /* 0x4004u */ - - /** Authentication process failed between two devices. - cy_stc_ble_gap_auth_info_t is returned as the event parameter. bdHandle provides a handle for the failing device and - authErr provides cy_en_ble_gap_auth_failed_reason_t indicates the reason for failure. - Other parameters should be ignored. */ - CY_BLE_EVT_GAP_AUTH_FAILED, /* 0x4005u */ - - /** Peripheral device has started/stopped advertising. - This event is generated after making a call to the Cy_BLE_GAPP_EnterDiscoveryMode and - Cy_BLE_GAPP_ExitDiscoveryMode functions. The event parameter contains the HCI Status error code, - which is of type 'uint8_t'. - - If the data is '0x00', it indicates 'success'; anything else indicates 'failure'. */ - CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP, /* 0x4006u */ - - /** This event is generated at the GAP Peripheral end after the connection is completed with a peer Central device. - For a GAP Central device, this event is generated as an acknowledgment of receiving this event successfully - by the BLE Controller. After the connection is complete, no other event is required but if connection establishment fails, - 'CY_BLE_EVT_GAP_DEVICE_DISCONNECTED' is passed to the application. The 'CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE' - event is triggered instead of 'CY_BLE_EVT_GAP_DEVICE_CONNECTED', if Link Layer Privacy is enabled in the component customizer. - The event parameter is a pointer to a structure of type cy_stc_ble_gap_connected_param_t. */ - CY_BLE_EVT_GAP_DEVICE_CONNECTED, /* 0x4007u */ - - /** Disconnected from remote device or failed to establish connection. - Parameter is of type 'cy_stc_ble_gap_disconnect_param_t' */ - CY_BLE_EVT_GAP_DEVICE_DISCONNECTED, /* 0x4008u */ - - /** Encryption change event for active connection. - * Event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is (cy_stc_ble_gap_encrypt_change_param_t*) - * eventParams->encryption is valid only if status is Success(0x00) - This is an informative event for the application when there is a change in encryption. - The application may choose to ignore it. */ - CY_BLE_EVT_GAP_ENCRYPT_CHANGE, /* 0x4009u */ - - /** This event is generated at the GAP Central and the Peripheral end after a connection parameter update - is requested from the host to the controller. - The event parameter is a pointer to a structure of type cy_stc_ble_gap_conn_param_updated_in_controller_t. */ - CY_BLE_EVT_GAP_CONNECTION_UPDATE_COMPLETE, /* 0x400Au */ - - /** The Central device has started/stopped scanning. - This event is generated after making a call to the Cy_BLE_GAPC_StartDiscovery and - Cy_BLE_GAPC_StopDiscovery APIs. The event parameter contains the HCI Status error code, - which is of type 'uint8_t'. - - If the data is '0x00', it indicates 'success'; anything else indicates 'failure'. */ - CY_BLE_EVT_GAPC_SCAN_START_STOP, /* 0x400Bu */ - - /** This is an indication that the SMP keys exchange with a peer device is complete. The event handler - is expected to store the peer device keys, especially IRK, which is used to resolve the - peer device after the connection establishment. - The event parameter returns data of type cy_stc_ble_gap_sec_key_param_t containing the peer device keys. */ - CY_BLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT, /* 0x400Cu */ - - /** This event indicates that the device must display a passkey during the - secure connection pairing procedure. Cy_BLE_GAP_AuthPassKeyReply() is - required to be called with valid parameters on receiving this event. - Because no key is entered by the user for Numeric comparison, the - parameter passkey for the function Cy_BLE_GAP_AuthPassKeyReply will be - ignored. - cy_stc_ble_gap_auth_pk_info_t is returned as the event parameter. bdHandle and passkey are relevant parameters. - Other parameter(s) should be ignored. Passkey can be any 6-decimal-digit value. */ - CY_BLE_EVT_GAP_NUMERIC_COMPARISON_REQUEST, /* 0x400Du */ - - /** This event is generated when keypress (Secure connections) is received - from peer device. - cy_stc_ble_gap_sc_kp_notif_info_t is returned as event parameter. */ - CY_BLE_EVT_GAP_KEYPRESS_NOTIFICATION, /* 0x400Eu */ - - /** This event is generated when OOB generation for Secure connections is complete. - The event parameter is of type 'cy_stc_ble_gap_oob_data_param_t' */ - CY_BLE_EVT_GAP_OOB_GENERATED_NOTIFICATION, /* 0x400Fu */ - - /** The LE Enhanced Connection Complete event indicates to the application that a new connection has been created when - Link Layer Privacy is enabled in the component customizer. - The event parameter is of type 'cy_stc_ble_gap_enhance_conn_complete_param_t' */ - CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE, /* 0x4010u */ - - /** The LE Direct Advertising Report event indicates that directed advertisements have been received where - the advertiser is using a resolvable private address for the InitA field in the ADV_DIRECT_IND PDU and the - Scanning_Filter_Policy is equal to 0x02 or 0x03. The event parameter is of type 'cy_stc_ble_gapc_direct_adv_report_param_t' */ - CY_BLE_EVT_GAPC_DIRECT_ADV_REPORT, /* 0x4011u */ - - /** The SMP negotiated auth info event is raised as soon as the SMP has completed pairing properties (feature exchange) - negotiation. The event parameter is cy_stc_ble_gap_auth_info_t. cy_stc_ble_gap_auth_info_t will have the - negotiated parameter. The pairing should either pass with these negotiated parameters or may fail. */ - CY_BLE_EVT_GAP_SMP_NEGOTIATED_AUTH_INFO, /* 0x4012u */ - - /** This event indicates a new Bluetooth device address generated successfully as per an application requirement. - The event parameter is cy_stc_ble_bd_addr_t */ - CY_BLE_EVT_GAP_DEVICE_ADDR_GEN_COMPLETE, /* 0x4013u */ - - /** This event indicates security keys are generated successfully. - The event parameter is cy_stc_ble_gap_sec_key_param_t bdHandle in the parameter should be ignored */ - CY_BLE_EVT_GAP_KEYS_GEN_COMPLETE, /* 0x4014u */ - - /** This event is triggered on completion of Cy_BLE_GAPC_ResolveDevice API. - The event parameter is (cy_stc_ble_events_param_generic_t*)*/ - CY_BLE_EVT_GAP_RESOLVE_DEVICE_COMPLETE, /* 0x4015u */ - - /** This event is triggered on completion of the Cy_BLE_GAP_GenerateSetLocalP256Keys API. - The event parameter is of pointer to cy_stc_ble_gap_smp_local_p256_keys_t that has - generated P256 keys. */ - CY_BLE_EVT_GAP_GEN_SET_LOCAL_P256_KEYS_COMPLETE, /* 0x4016u */ - - /** This event is triggered on completion of the Cy_BLE_GAPC_CancelConnection API. - * The event parameter is (cy_stc_ble_events_param_generic_t*) - * eventParams member of cy_stc_ble_events_param_generic_t is ignored - */ - CY_BLE_EVT_GAP_CREATE_CONN_CANCEL_COMPLETE, /* 0x4017u */ - - /** This event is triggered on completion of connection establishment. - * Event parameter is (cy_stc_ble_conn_estb_param_t*) - */ - CY_BLE_EVT_GAP_CONN_ESTB, /* 0x4018u */ - - /** Peripheral device has started/stopped advertising. - This event is generated after making a call to the Cy_BLE_GAP_UpdateAdvScanData function. - The event parameter contains the HCI Status error code, which is of type 'uint8_t'. - - If the data is '0x00', it indicates 'success'; anything else indicates 'failure'. */ - CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE, /* 0x4019u */ - - /* Range for GATT events - 0x5000 to 0x5FFF */ - - /** The event is received by the Client when the Server cannot perform the requested - operation and sends out an error response. The event parameter is a pointer to a structure - of type cy_stc_ble_gatt_err_param_t. */ - CY_BLE_EVT_GATTC_ERROR_RSP = 0x5000u, - - /** This event is generated at the GAP Peripheral end after a connection is completed with a peer Central device. - For a GAP Central device, this event is generated as in acknowledgment of receiving this event successfully - by the BLE Controller. After connection is complete, no other event is required but if connection establishment fails, - 'CY_BLE_EVT_GATT_DISCONNECT_IND' is passed to the application. - The event parameter is a pointer to a structure of type cy_stc_ble_conn_handle_t. */ - CY_BLE_EVT_GATT_CONNECT_IND, /* 0x5001u */ - - /** GATT is disconnected. - The event parameter is a pointer to a structure of type cy_stc_ble_conn_handle_t. */ - CY_BLE_EVT_GATT_DISCONNECT_IND, /* 0x5002u */ - - /** 'GATT MTU Exchange Request' received from GATT client device. The event parameter - contains the MTU size of type cy_stc_ble_gatt_xchg_mtu_param_t. */ - CY_BLE_EVT_GATTS_XCNHG_MTU_REQ, /* 0x5003u */ - - /** 'GATT MTU Exchange Response' received from server device. The event parameter is a - pointer to a structure of type cy_stc_ble_gatt_xchg_mtu_param_t. */ - CY_BLE_EVT_GATTC_XCHNG_MTU_RSP, /* 0x5004u */ - - /** 'Read by Group Type Response' received from server device. Event parameter - is a pointer to a structure of type cy_stc_ble_gattc_read_by_grp_rsp_param_t. */ - CY_BLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP, /* 0x5005u */ - - /** 'Read by Type Response' received from server device. The event parameter is a - pointer to a structure of type cy_stc_ble_gattc_read_by_type_rsp_param_t. */ - CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP, /* 0x5006u */ - - /** 'Find Information Response' received from server device. The event parameter is - a pointer to a structure of type 'cy_stc_ble_gattc_find_info_rsp_param_t. */ - CY_BLE_EVT_GATTC_FIND_INFO_RSP, /* 0x5007u */ - - /** 'Find by Type Value Response' received from server device. The event parameter is - a pointer to a structure of type cy_stc_ble_gattc_find_by_type_rsp_param_t. */ - CY_BLE_EVT_GATTC_FIND_BY_TYPE_VALUE_RSP, /* 0x5008u */ - - /** 'Read Response' from server device. The event parameter is a pointer to a - structure of type cy_stc_ble_gattc_read_rsp_param_t. */ - CY_BLE_EVT_GATTC_READ_RSP, /* 0x5009u */ - - /** 'Read Blob Response' from server. The event parameter is a pointer to a - structure of type cy_stc_ble_gattc_read_rsp_param_t. */ - CY_BLE_EVT_GATTC_READ_BLOB_RSP, /* 0x500Au */ - - /** 'Read Multiple Responses' from server. The event parameter is a pointer - to a structure of type cy_stc_ble_gattc_read_rsp_param_t. The 'actualLen' field - should be ignored as it is unused in this event response. */ - CY_BLE_EVT_GATTC_READ_MULTI_RSP, /* 0x500Bu */ - - /** 'Write Request' from client device. The event parameter is a pointer to - a structure of type cy_stc_ble_gatt_write_param_t. */ - CY_BLE_EVT_GATTS_WRITE_REQ, /* 0x500Cu */ - - /** 'Write Response' from server device. The event parameter is a pointer - to a structure of type cy_stc_ble_conn_handle_t. */ - CY_BLE_EVT_GATTC_WRITE_RSP, /* 0x500Du */ - - /** 'Write Command' Request from client device. The event parameter is a - pointer to a structure of type cy_stc_ble_gatts_write_cmd_req_param_t. */ - CY_BLE_EVT_GATTS_WRITE_CMD_REQ, /* 0x500Eu */ - - /** 'Prepare Write' Request from client device. The event parameter is a - pointer to a structure of type cy_stc_ble_gatts_prep_write_req_param_t. */ - CY_BLE_EVT_GATTS_PREP_WRITE_REQ, /* 0x500Fu */ - - /** 'Execute Write' request from client device. The event parameter is a - pointer to a structure of type 'cy_stc_ble_gatts_exec_write_req_t'. - This event will be triggered before GATT DB is modified. GATT DB will be updated - only if there is no error condition provided by the application. In case of an error condition triggered - during stack validation, a partial write will occur. The write will be cancelled from that handle where - the error has occurred and an error response corresponding to that handle will be sent to the remote. - If at any point of time 'CY_BLE_GATT_EXECUTE_WRITE_CANCEL_FLAG' is received in - execWriteFlag fields of 'cy_stc_ble_gatts_exec_write_req_t' structure, then all previous - writes are cancelled. For execute cancel scenario, all elements of - 'cy_stc_ble_gatts_exec_write_req_t' should be ignored except execWriteFlag and connHandle. - */ - CY_BLE_EVT_GATTS_EXEC_WRITE_REQ, /* 0x5010u */ - - /** 'Execute Write' response from server device. The event parameter is a - pointer to a structure of type cy_stc_ble_gattc_exec_write_rsp_param_t. */ - CY_BLE_EVT_GATTC_EXEC_WRITE_RSP, /* 0x5011u */ - - /** Notification data received from server device. The event parameter - is a pointer to a structure of type cy_stc_ble_gattc_handle_value_ntf_param_t. */ - CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF, /* 0x5012u */ - - /** Indication data received from server device. The event parameter is - a pointer to a structure of type cy_stc_ble_gattc_handle_value_ind_param_t. */ - CY_BLE_EVT_GATTC_HANDLE_VALUE_IND, /* 0x5013u */ - - /** Confirmation to indication response from client device. The event - parameter is a pointer to a structure of type cy_stc_ble_conn_handle_t. */ - CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF, /* 0x5014u */ - - /** Event indicating GATT signed write command is received from client device. The event - parameter is a pointer to a structure of type cy_stc_ble_gatts_signed_write_cmd_req_param_t. - If value.val parameter is set to Zero, then the signature is not matched and is ignored by the stack */ - CY_BLE_EVT_GATTS_DATA_SIGNED_CMD_REQ, /* 0x5015u */ - - /** Event indicating that GATT group procedure has stopped or completed. This event occurs - only if the application has called the Cy_BLE_GATTC_StopCmd API. - The parameter is a pointer to a structure of type cy_stc_ble_conn_handle_t. */ - CY_BLE_EVT_GATTC_STOP_CMD_COMPLETE, /* 0x5016u */ - - /** The event parameter type is cy_stc_ble_gatts_char_val_read_req_t. It is triggered on the server side - when the client sends a read request and when characteristic has the CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT - property set. This event could be ignored by the application unless it need to respond by an error response, which - must be set in the gattErrorCode field of the event parameter. */ - CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ, /* 0x5017u */ - - /** Event indicating that the GATT long procedure has ended and the stack will not send any further - * requests to the peer. The event parameter is of type 'cy_stc_ble_gattc_long_procedure_end_param_t'. - * Either this event or 'CY_BLE_EVT_GATTC_ERROR_RSP' will be received - * by the application. This event may be triggered for the below GATT long procedures: - * 1. Cy_BLE_GATTC_DiscoverAllPrimaryServices - * 2. Cy_BLE_GATTC_DiscoverPrimaryServiceByUuid - * 3. Cy_BLE_GATTC_FindIncludedServices - * 4. Cy_BLE_GATTC_DiscoverAllCharacteristics - * 5. Cy_BLE_GATTC_DiscoverCharacteristicByUuid - * 6. Cy_BLE_GATTC_DiscoverAllCharacteristicDescriptors - * 7. Cy_BLE_GATTC_ReadLongCharacteristicValues - * 8. Cy_BLE_GATTC_WriteLongCharacteristicValues - * 9. Cy_BLE_GATTC_ReliableWrites - * 10. Cy_BLE_GATTC_ReadLongCharacteristicDescriptors - * 11. Cy_BLE_GATTC_WriteLongCharacteristicDescriptors \n - * The event parameter is ATT opcode for the corresponding long GATT Procedure. - */ - CY_BLE_EVT_GATTC_LONG_PROCEDURE_END, /* 0x5018u */ - - /* Range for L2CAP events - 0x6000 to 0x6FFF */ - - /** This event indicates the connection parameter update has been received - from the remote device. The application is expected to reply to L2CAP using the - Cy_BLE_L2CAP_LeConnectionParamUpdateResponse() function to respond to the remote - device, whether parameters are accepted or rejected. - - The event parameter pointer points to data of type 'cy_stc_ble_gap_conn_update_param_info_t' */ - CY_BLE_EVT_L2CAP_CONN_PARAM_UPDATE_REQ = 0x6000u, - - /** This event indicates the connection parameter update response has been received - from the master. The event parameter is a pointer to a structure of type - cy_stc_ble_l2cap_conn_update_rsp_param_t. */ - CY_BLE_EVT_L2CAP_CONN_PARAM_UPDATE_RSP, /* 0x6001u */ - - /** This event indicates that the request to send over l2cap signaling has been - rejected. The event parameter is a pointer to a structure of type - cy_stc_ble_l2cap_cmd_rej_param_t. */ - CY_BLE_EVT_L2CAP_COMMAND_REJ, /* 0x6002u */ - - /** This event is used to inform the application of the incoming L2CAP CBFC - Connection Request. The event parameter is a pointer to a structure of type - cy_stc_ble_l2cap_cbfc_conn_ind_param_t is returned. */ - CY_BLE_EVT_L2CAP_CBFC_CONN_IND, /* 0x6003u */ - - /** This event is used to inform application of the L2CAP CBFC Connection - Response/Confirmation. The event parameter is a pointer to a structure of - type cy_stc_ble_l2cap_cbfc_conn_cnf_param_t is returned. */ - CY_BLE_EVT_L2CAP_CBFC_CONN_CNF, /* 0x6004u */ - - /** This event is used to inform the application of the L2CAP CBFC Disconnection - Request received from the Peer device. The event parameter is a pointer to - a Local CID of type unit16. */ - CY_BLE_EVT_L2CAP_CBFC_DISCONN_IND, /* 0x6005u */ - - /** This event is used to inform the application of the L2CAP CBFC Disconnection - confirmation/Response received from the Peer device. The event parameter is a - pointer to a structure of type cy_stc_ble_l2cap_cbfc_disconn_cnf_param_t. */ - CY_BLE_EVT_L2CAP_CBFC_DISCONN_CNF, /* 0x6006u */ - - /** This event is used to inform the application of data received over the L2CAP - CBFC channel. The event parameter is a pointer to a structure of type - cy_stc_ble_l2cap_cbfc_rx_param_t. */ - CY_BLE_EVT_L2CAP_CBFC_DATA_READ, /* 0x6007u */ - - /** This event is used to inform the application of receive credits has reached the - low mark. After receiving L2CAP data/payload from a peer device for a - specification Channel, the available credits are calculated. - - If the credit count goes below the low mark, this event is called to inform - the application of the condition, so that if the application wants it can - send more credits to the peer device. - - The event parameter is a pointer to a structure of type - cy_stc_ble_l2cap_cbfc_low_rx_credit_param_t. */ - CY_BLE_EVT_L2CAP_CBFC_RX_CREDIT_IND, /* 0x6008u */ - - /** This event is used to inform the application of having received transmit - credits. This event is called on receiving LE Flow Control Credit from a peer - device. - - The event parameter is a pointer to a structure of type - cy_stc_ble_l2cap_cbfc_low_tx_credit_param_t. - - If the 'result' field of the received data is non-zero, this indicates an - error. If the sum of 'credit' field value and the previously available credit - at the peer device receiving credit information exceeds 65535, it indicates a - 'credit overflow' error. - - If there is an error, the peer device receiving this event should initiate - disconnection of the L2CAP channel by invoking the Cy_BLE_L2CAP_DisconnectReq () - function. */ - CY_BLE_EVT_L2CAP_CBFC_TX_CREDIT_IND, /* 0x6009u */ - - /** This event is used to inform the application that L2CAP CBFC data transmission is scheduled - for transmission in the BLE Controller. The application can send the next data. - The event parameter is of type 'cy_stc_ble_l2cap_cbfc_rx_data_param_t'. - The L2CAP CBFC application must wait for this event before transmitting the next CBFC L2CAP data. - The application can send the next data only when the CY_BLE_EVT_L2CAP_CBFC_DATA_WRITE_IND event is received for - previously sent data and CY_BLE_EVT_STACK_BUSY_STATUS is received with status CY_BLE_STACK_STATE_FREE. */ - CY_BLE_EVT_L2CAP_CBFC_DATA_WRITE_IND, /* 0x600Au */ - - /*Range for qualification events - 0x7000 to 0x7FFF*/ - -#ifdef CY_BLE_HOST_QUALIFICATION - /** Tester to manipulate pairing request or response PDU. The event parameter is a pointer to 1 byte data. - The tester can manipulate the bits of the byte. */ - CY_BLE_EVT_QUAL_SMP_PAIRING_REQ_RSP = 0x7000u, - - /** Tester to manipulate local Public Key. The event parameter is a pointer to local public key of size 64 Bytes. - The tester can manipulate the bits/bytes. */ - CY_BLE_EVT_QUAL_SMP_LOCAL_PUBLIC_KEY, /* 0x7001u */ - - /** Tester to assign pairing failed error code. The event parameter is a pointer to 16 bits value. - The tester should assign an error code to the lower bits. */ - CY_BLE_EVT_QUAL_SMP_PAIRING_FAILED_CMD, /* 0x7002u */ - -#endif /* CY_BLE_HOST_QUALIFICATION */ - - /*##Range for for future use - 0x8000 to 0xFFFE*/ - - - /** Maximum value of cy_en_ble_event_t type */ - CY_BLE_EVT_MAX = 0xFFFF - -} cy_en_ble_event_t; - -/** @} */ - -/** - \addtogroup group_ble_common_api_definitions - @{ -*/ -/** Common error codes received as API result */ -typedef enum -{ - /** No Error occurred */ - CY_BLE_SUCCESS = CY_PDL_STATUS_INFO, - - /** Flash operation in progress*/ - CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS = CY_PDL_STATUS_INFO | CY_BLE_ID | 0x0001ul, - - /** At least one of the input parameters is invalid */ - CY_BLE_ERROR_INVALID_PARAMETER = CY_PDL_STATUS_ERROR | CY_BLE_ID | 0x0001ul, - - /** Operation is not permitted */ - CY_BLE_ERROR_INVALID_OPERATION, - - /** An internal error occurred in the stack */ - CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED, - - /** Insufficient resources to perform requested operation */ - CY_BLE_ERROR_INSUFFICIENT_RESOURCES, - - /** OOB data not available */ - CY_BLE_ERROR_OOB_NOT_AVAILABLE, - - /** Connection is required to perform requested operation. Connection not - present */ - CY_BLE_ERROR_NO_CONNECTION, - - /** No device entity to perform requested operation */ - CY_BLE_ERROR_NO_DEVICE_ENTITY, - - /** Device cannot be added to the Whitelist as it has already been added */ - CY_BLE_ERROR_DEVICE_ALREADY_EXISTS, - - /** Attempted repeat operation is not allowed */ - CY_BLE_ERROR_REPEATED_ATTEMPTS, - - /** GAP role is incorrect */ - CY_BLE_ERROR_GAP_ROLE, - - /** Security operation failed */ - CY_BLE_ERROR_SEC_FAILED, - - /** L2CAP PSM encoding is incorrect */ - CY_BLE_ERROR_L2CAP_PSM_WRONG_ENCODING, - - /** L2CAP PSM has already been registered */ - CY_BLE_ERROR_L2CAP_PSM_ALREADY_REGISTERED, - - /** L2CAP PSM has not been registered */ - CY_BLE_ERROR_L2CAP_PSM_NOT_REGISTERED, - - /** L2CAP connection entity not found */ - CY_BLE_ERROR_L2CAP_CONNECTION_ENTITY_NOT_FOUND, - - /** Specified PSM is out of range */ - CY_BLE_ERROR_L2CAP_PSM_NOT_IN_RANGE, - - /** Unsupported feature or parameter value */ - CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE, - - /** Write to flash is not permitted */ - CY_BLE_ERROR_FLASH_WRITE_NOT_PERMITED, - - /** Error in flash Write */ - CY_BLE_ERROR_FLASH_WRITE, - - /** MIC Authentication failure */ - CY_BLE_ERROR_MIC_AUTH_FAILED, - - /** Controller error codes. These come directly from the controller (not the host stack)*/ - - /** Hardware Failure */ - /** Possible reason - BLE ECO failed to start due to one of the below: - * - LFCLK (WCO, PILO, ILO) not present - * - Radio bus failure */ - CY_BLE_ERROR_HARDWARE_FAILURE, - - /**GATT DB error codes*/ - - /** Invalid attribute handle */ - CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE, - - /* Profile level API_RESULT codes */ - /** Characteristic notifications disabled */ - CY_BLE_ERROR_NTF_DISABLED, - - /** Characteristic indications disabled */ - CY_BLE_ERROR_IND_DISABLED, - - /** \cond IGNORE */ - CY_BLE_ERROR_CHAR_IS_NOT_DISCOVERED, - /** \endcond */ - - /** Controller Busy */ - CY_BLE_ERROR_CONTROLLER_BUSY = CY_PDL_STATUS_ERROR | CY_BLE_ID | 0x00FEul, - - /** The state is not valid for current operation */ - CY_BLE_ERROR_INVALID_STATE, - - /** All other errors not covered in the above list map to this error code */ - CY_BLE_ERROR_MAX = CY_PDL_STATUS_ERROR | CY_BLE_ID | 0xFFFFul, - -} cy_en_ble_api_result_t; - - -/*************************************** -** Exported structures and unions -***************************************/ - -/** Event callback function prototype to receive events from stack */ -typedef void (*cy_ble_app_ev_cb_t)(cy_en_ble_event_t event, void* evParam); - - -/** This structure is used to hold version information of the BLE Stack Library */ -typedef struct -{ - /** The major version of the library */ - uint8_t majorVersion; - - /** The minor version of the library */ - uint8_t minorVersion; - - /** The patch number of the library */ - uint8_t patch; - - /** The build number of the library */ - uint16_t buildNumber; - -} cy_stc_ble_stack_lib_version_t; - - -/** Bluetooth Device Address type */ -typedef struct -{ - /** Bluetooth device address */ - uint8_t bdAddr[CY_BLE_BD_ADDR_SIZE]; - - /** public = 0, Random = 1 */ - uint8_t type; - -} cy_stc_ble_bd_addr_t; - - -/** Configuration structure for Tx and Rx ACL Data Buffers required by the - * BLE Controller Stack, all the configuration specified is valid per - * connection and all the support LL connections will have same capability. - */ -typedef struct -{ - /** - * Tx buffer size configuration for the BLE Controller per the - * LL Connection - */ - uint16_t dleMaxTxCapability; - - /** - * Rx buffer size configuration for the BLE Controller per the - * LL Connection - */ - uint16_t dleMaxRxCapability; - - /** - * Total number of Tx buffer configuration per LL Connection for the - * BLE Controller - */ - uint8_t dleNumTxBuffer; - - /** - * Total number of Rx buffer configuration per LL Connection for - * BLE Controller - */ - uint8_t dleNumRxBuffer; - -} cy_stc_ble_dle_config_param_t; - -/** Configuration structure for the L2CAP buffer for data transmission - * - */ -typedef struct -{ - /** - * This specifies L2CAP stack queue depth per connection for data tx. - * The application must provide heap memory based on the following calculation: - * l2capBufferPerConn * maxBleConnections * CY_BLE_L2CAP_QUEUE_ELEMENT_SIZE - */ - uint8_t l2capBufferPerConn; - -} cy_stc_ble_l2cap_config_param_t; - - -/** Configuration structure for LL Privacy feature */ -typedef struct -{ - /** Maximum number of possible entries in resolving list */ - uint8_t resolvingListSize; - -} cy_stc_ble_privacy_1_2_config_param_t; - -/** Configuration parameter for bonded device list */ -typedef struct -{ - /** Maximum number of possible entries in bonded device list */ - /* The application must provide bonded device list memory as per bondlist size */ - uint8_t bondListSize; - -} cy_stc_ble_bonded_device_list_config_param_t; - -/**Configuration parameter for the WhiteList */ -typedef struct -{ - /** Maximum number of possible entries in the Whitelist */ - uint8_t whiteListSize; - -} cy_stc_ble_white_list_config_param_t; - -/** - * Configuration structure for enabling selective features - * and passing associated parameters. - */ -typedef struct -{ - /** Configuration parameter for DLE feature */ - cy_stc_ble_dle_config_param_t dleConfig; - - /** Configuration parameter for L2CAP buffer */ - cy_stc_ble_l2cap_config_param_t l2capConfig; - - /** Configuration parameter for privacy 1.2 feature */ - cy_stc_ble_privacy_1_2_config_param_t privacyConfig; - - /** Configuration parameter for bonded device list */ - cy_stc_ble_bonded_device_list_config_param_t bondListConfig; - - /** Configuration parameter for whiteList */ - cy_stc_ble_white_list_config_param_t whiteListConfig; - - /** The feature set mask used to control usage of - * specified feature in the BLE stack. If a feature is not selected, - * then associated parameter pointer can be NULL. - * Feature Mask Values : - * B0 : DLE_FEATURE_MASK - * B1 : PRIVACY_1_2_FEATURE_MASK - * B2 : SECURE_CONN_FEATURE_MASK - * B3 : PHY_UPDATE_FEATURE_MASK - * B4 : PERSISTENT_STORE_BONDLIST - * B5 : PERSISTENT_STORE_RESOLVING_LIST - * B6 : PERSISTENT_STORE_WHITELIST - * B7 : PERSISTENT_RADIO_CALIBRATION_MASK - */ - uint16_t featureMask; - - /**Out parameter for returning memory requirement for selected features*/ - uint16_t featureHeapReq; - - - /** Configuration parameter for Maximum number of BLE Connection - * Max possible value is 4 and Min configuration value is 1 - */ - uint8_t maxBleConnections; - -} cy_stc_ble_stack_config_param_t; - - -/** Set of buffers to be allocated by stack for stack operation */ -typedef struct -{ - /** Size of the buffer chunk */ - uint16_t bufferSize; - - /** Number of the buffers units of 'bufferSize' */ - uint16_t bufferUnits; - -} cy_stc_ble_stk_app_data_buff_t; - -/** Structure for passing the connection established - * parameters - */ -typedef struct -{ - /** bd handle of the device */ - uint8_t bdHandle; - - /** Link layer access address */ - uint32_t accessAddr; - -} cy_stc_ble_conn_estb_param_t; - -/** BLE Stack Manager configuration structure for allocating memory pools - * for host and controller operation. - */ -typedef struct -{ - /** Memory Heap pointer */ - uint8_t * memoryHeapPtr; - - /** Set of buffers needed for stack operation */ - cy_stc_ble_stk_app_data_buff_t * dataBuff; - - /** Memory heap pointer size */ - uint16_t totalHeapSz; - - /** Total data buffer pools */ - uint8_t totalDataBufferPools; - - /** Pointer to an array of bytes to be allocated by the BLE component for the storing the - persistent data into the flash. Pointer provided is should be aligned to the flash boundary. */ - const uint8_t * bleStackFlashPointer; - - /** Size of the total flash memory pointed by bleStackFlashPointer */ - uint32_t bleStackFlashSize; - -} cy_stc_ble_stack_mgr_mem_cfg_param_t; - - -/** BLE Stack init parameter */ -typedef struct -{ - /** Application Callback Function Configuration **/ - cy_ble_app_ev_cb_t CyBleAppCbFunc; - - /** Stack Manager Memory Configuration **/ - cy_stc_ble_stack_mgr_mem_cfg_param_t memParam; - - /** Stack configuration parameter **/ - cy_stc_ble_stack_config_param_t stackConfig; - -} cy_stc_ble_stack_init_info_t; - -/** - * Structure containing the parameters required for AES CMAC Generation - */ -typedef struct -{ - - /** pointer to message for which AES CMAC must be calculated, LSB should be first */ - uint8_t *buffer; - /** size of the message buffer */ - uint16_t size; - /** AES CMAC 128-bit Key, LSB should be first */ - uint8_t *key; - /** output-parameter, Buffer to hold generated MAC of 16 bytes. Output is LSB first */ - uint8_t *mac; - -}cy_stc_ble_aes_cmac_generate_param_t; - -/** BLESS Power enum reflecting power level values supported by BLESS radio */ -typedef enum -{ - /** ABS PWR = -20 dBm */ - CY_BLE_LL_PWR_LVL_NEG_20_DBM = -20, - - /** ABS PWR = -16 dBm */ - CY_BLE_LL_PWR_LVL_NEG_16_DBM = -16, - - /** ABS PWR = -12 dBm */ - CY_BLE_LL_PWR_LVL_NEG_12_DBM = -12, - - /** ABS PWR = -6 dBm */ - CY_BLE_LL_PWR_LVL_NEG_6_DBM = -6, - - /** ABS PWR = 0 dBm */ - CY_BLE_LL_PWR_LVL_0_DBM = 0, - - /** ABS PWR = +4 dBm as per silicon */ - CY_BLE_LL_PWR_LVL_MAX = 4 - -} cy_en_ble_bless_pwr_lvl_t; - -/** BLE channel group ID */ -typedef enum -{ - /** Advertisement channel type */ - CY_BLE_LL_ADV_CH_TYPE = 0x00u, - - /** Connection channel type */ - CY_BLE_LL_CONN_CH_TYPE, - - /** Maximum value of the cy_en_ble_bless_phy_ch_grp_id_t type */ - CY_BLE_LL_MAX_CH_TYPE - -} cy_en_ble_bless_phy_ch_grp_id_t; - -/** BLE WCO sleep clock accuracy configuration */ -typedef enum -{ - /** BLE WCO sleep clock accuracy 251 to 500 ppm */ - CY_BLE_LL_SCA_251_TO_500_PPM = 0x00u, - - /** BLE WCO sleep clock accuracy 151 to 250 ppm */ - CY_BLE_LL_SCA_151_TO_250_PPM, - - /** BLE WCO sleep clock accuracy 101 to 150 ppm */ - CY_BLE_LL_SCA_101_TO_150_PPM, - - /** BLE WCO sleep clock accuracy 76 to 100 ppm */ - CY_BLE_LL_SCA_076_TO_100_PPM, - - /** BLE WCO sleep clock accuracy 51 to 75 ppm */ - CY_BLE_LL_SCA_051_TO_075_PPM, - - /** BLE WCO sleep clock accuracy 31 to 50 ppm */ - CY_BLE_LL_SCA_031_TO_050_PPM, - - /** BLE WCO sleep clock accuracy 21 to 30 ppm */ - CY_BLE_LL_SCA_021_TO_030_PPM, - - /** BLE WCO sleep clock accuracy 0 to 20 ppm */ - CY_BLE_LL_SCA_000_TO_020_PPM, - - /** BLE WCO invalid sleep clock accuracy */ - CY_BLE_LL_SCA_IN_PPM_INVALID -} cy_en_ble_bless_wco_sca_cfg_t; - -/** BLE ECO clock divider */ -typedef enum -{ - /** Link Layer clock divider = 1*/ - CY_BLE_LL_ECO_CLK_DIV_1 = 0x00u, - - /** Link Layer clock divider = 2*/ - CY_BLE_LL_ECO_CLK_DIV_2, - - /** Link Layer clock divider = 4*/ - CY_BLE_LL_ECO_CLK_DIV_4, - - /** Link Layer clock divider = 8*/ - CY_BLE_LL_ECO_CLK_DIV_8, - - /** Invalid Link Layer clock divider*/ - CY_BLE_LL_ECO_CLK_DIV_INVALID - -} cy_en_ble_bless_eco_clk_div_t; - -/** BLE clock configuration parameters */ -typedef struct -{ - /** Sleep Clock accuracy in PPM, 32Khz Cycles */ - cy_en_ble_bless_wco_sca_cfg_t bleLlSca; - - /** Link Layer clock divider */ - cy_en_ble_bless_eco_clk_div_t bleLlClockDiv; - -} cy_stc_ble_bless_clk_cfg_params_t; - -/** BLE power modes */ -typedef enum -{ - /** Link Layer engine and Digital modem clocked from ECO. - The CPU can access the BLE Sub-System (BLESS) registers. - This mode collectively denotes Tx Mode, Rx Mode, and - Idle mode of BLESS. - */ - CY_BLE_BLESS_ACTIVE = 0x01u, - - /** The ECO is stopped and WCO is used to maintain link layer - timing. RF transceiver is turned off completely to reduce - leakage current. BLESS logic is kept powered ON from the - SRSS deep sleep regulator for retention. - */ - CY_BLE_BLESS_DEEPSLEEP, - - /** Invalid mode */ - CY_BLE_BLESS_INVALID = 0xFFu -} cy_en_ble_lp_mode_t; - - -/** BLESS Power enum reflecting power states supported by BLESS radio */ -typedef enum -{ - CY_BLE_BLESS_STATE_ACTIVE = 0x01, - CY_BLE_BLESS_STATE_EVENT_CLOSE, - CY_BLE_BLESS_STATE_ECO_ON, - CY_BLE_BLESS_STATE_ECO_STABLE, - CY_BLE_BLESS_STATE_DEEPSLEEP, - CY_BLE_BLESS_STATE_STOPPED, - CY_BLE_BLESS_STATE_INVALID = 0xFFu -} cy_en_ble_bless_state_t; - -/** Sleep mode which controller core is trying to enter */ -typedef enum -{ - CY_BLE_CONTROLLER_SLEEP_MODE_SLEEP = 0x01u, - CY_BLE_CONTROLLER_SLEEP_MODE_DEEPSLEEP -} cy_en_ble_controller_sleep_mode_t; - -/** @} */ - -/** - \addtogroup group_ble_common_api_functions - @{ -*/ -/****************************************************************************** -* Function Name: Cy_BLE_GetStackLibraryVersion -***************************************************************************//** -* -* This function retrieves the version information of the BLE Stack library. This -* is a blocking function. No event is generated on calling this function. -* -* \param param: Pointer to a variable of type cy_stc_ble_stack_lib_version_t -* containing the version information of the CY_BLE Stack library. -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | param is NULL. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetStackLibraryVersion -( - cy_stc_ble_stack_lib_version_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_StackInit -***************************************************************************//** -* -* This function initializes the BLE Stack and must be called from the higher -* layer initialization routine only once before invoking any other BLE Stack -* function. It includes initialization of the BLE Stack Manager, BLE Controller, and -* BLE Host Stack modules that make up the BLE Stack. -* -* For HCI-Mode of operation, this function will not initialize the BLE Host Stack -* module. -* -* This is a non-blocking function. A call to this function results in the generation of following events -* -* | Event Name | Description | -* | ------------------------------ |-------------------------------------------------------------------------- | -* | CY_BLE_EVT_STACK_ON | On successful initialization of Stack | -* | CY_BLE_EVT_HARDWARE_ERROR | Sent by Host if Controller Initialization is failed in Dual Core Configuration | -* | CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE | Sent by Host if Controller Initialization is failed in Dual Core Configuration | -* -* \param param: parameter is of type 'cy_stc_ble_stack_init_info_t'. -* param->CyBLEApplCbFunc: Event callback function to receive events from BLE Stack. -* cy_ble_app_ev_cb_t is a function pointer type. The application is not expected to call -* stack APIs in the stack call back context. Stack execution should be allowed to -* return unless the Stack API explicitly mentions otherwise. -* -* The following APIs should not be called from the BLE Stack callback context but can be called from the -* 'CY_BLE_EVT_GATTC_ERROR_RSP' or 'CY_BLE_EVT_GATTC_LONG_PROCEDURE_END' events -* or any not long procedure events. -* 1. Cy_BLE_GATTC_DiscoverPrimaryServices -* 2. Cy_BLE_GATTC_DiscoverPrimaryServiceByUuid -* 3. Cy_BLE_GATTC_FindIncludedServices -* 4. Cy_BLE_GATTC_DiscoverCharacteristics -* 5. Cy_BLE_GATTC_DiscoverCharacteristicByUuid -* 6. Cy_BLE_GATTC_DiscoverCharacteristicDescriptors -* 7. Cy_BLE_GATTC_ReadLongCharacteristicValues -* 8. Cy_BLE_GATTC_WriteLongCharacteristicValues -* 9. Cy_BLE_GATTC_ReliableWrites -* 10. Cy_BLE_GATTC_ReadLongCharacteristicDescriptors -* 11. Cy_BLE_GATTC_WriteLongCharacteristicDescriptors -* 12. Cy_BLE_GATTC_ReadByTypeReq -* -* param->memParam.memoryHeapPtr: Pointer to an array of bytes to be allocated by the BLE component -* (or the application, if the component's initialization function -* is not used). The size of the memory to be allocated is as -* given below for non-HCI mode build of the BLE Stack. -* -* (CY_BLE_DEFAULT_HOST_RAM_SIZE -* + Accumulative memory for all dataBuff units -* + L2CAP heap requirement -* + CY_BLE_RAM_SECURE_CONNECTIONS_SIZE (Only if Secure Connections feature is enabled) -* + (CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE + CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE) -* * (CY_BLE_MAX_CONNECTION_INSTANCES + param->bondListConfig.bondListSize) -* + CY_BLE_STACK_BUFFER_MGR_UTIL_RAM_SZ * totalDataBufferPools) -* -* Where, CY_BLE_DEFAULT_HOST_RAM_SIZE is a define that is available from -* the BLE Stack. The starting address of the memoryHeapPtr should be four bytes aligned and -* the size of the total memory should be divisible by four. -* -* Accumulative memory for "single databuff instance" = -* (dataBuff.bufferSize * dataBuff.bufferUnits) -* -* L2CAP heap requirement = -* (CY_BLE_L2CAP_QUEUE_ELEMENT_SIZE * stack queue depth per connection * -* maxBleConnections ). -* - CY_BLE_L2CAP_QUEUE_ELEMENT_SIZE is a define available in the BLE stack. -* - Stack queue depth per connection should be equal to or higher than -* CY_BLE_L2CAP_STACK_Q_DEPTH_PER_CONN. -* - maxBleConnections speficies number of connections supported. -* -* totalDataBufferPools is "numOfDataBuffSet" -* -* If HCI mode BLE stack is used, the memory to be allocated should -* be of size 'CY_BLE_DEFAULT_RAM_SIZE_HCI'. -* -* param->memParam.totalHeapSz: Size of the total heap memory pointer by memoryHeapPtr. totalHeapSz shall be -* the accumulated value of every dataBuff elements. To compute total size, each element's -* size shall be rounded to next 4-byte boundary value. -* -* For example, a typical value can be computed in following manner: -* -* Size for buffer pool #1 to be added = -* ((CY_BLE_ALIGN_TO_4(Size of GATT MTU) + CY_BLE_MEM_EXT_SZ + CY_BLE_L2CAP_HDR_SZ) *\ -* noOfBuffer) -* -* Note that the buffer pool size for each chunk may not be 4-byte boundary aligned, -* and it should be as per user configuration. The BLE Stack's buffer management utility -* internally aligns it to a higher 4-byte boundary. -* -* param->memParam.dataBuff: array of structures of type cy_stc_ble_stk_app_data_buff_t. Ignored in case of HCI mode. -* -* param->memParam.totalDataBufferPools: Number of data buffer sets in the array. Ignored in case of HCI mode. -* -* param->memParam.bleStackFlashPointer: Pointer to the flash memory. Ignored in case of HCI mode. -* The size of the memory to be allocated is as given below for a non-HCI mode build of the BLE Stack: -* ( -* (CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE * User configured Bondlist size) -* + (CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE * (CY_BLE_MAX_CONNECTION_INSTANCES + User configured bondlist size)) -* + ((CY_BLE_LL_ONE_WHITELIST_HEAP_REQ * User Configured Whitelist size) + -* CY_BLE_LL_WHITELIST_RETENTION_HEAP_REQ) -* + ((CY_BLE_LL_PRIVACY_HEAP_REQ * User Configured Resolving list size) + -* CY_BLE_LL_PRIVACY_RETENTION_HEAP_REQ) -* ) -* -* param->memParam.bleStackFlashSize: Size of the total flash memory pointed by 'bleStackFlashPointer'. -* Ignored in case of HCI mode. -* -* param->stackConfig: Stack configuration parameters such as featuremask, Bondlist, Whitelist & Resolving list size -* configurarions, max number of connections, L2CAP configuration. -* -* Array dataBuff [totalDataBufferPools] shall provide the information to Stack based on the below table - -* -* Index | Application config. param | bufferSize | noOfBuffer -* ----- | -------------------------- | --------------------------------------------------------------------------------- | --------------- -* 0 | GATT MTU | (GATT MTU + CY_BLE_MEM_EXT_SZ + CY_BLE_L2CAP_HDR_SZ) | 3 -* 1 | Num. of PSM supported | ((CY_BLE_L2CAP_PSM_SIZE + CY_BLE_MEM_EXT_SZ) * no of PSM supported) | No of PSM supported -* 2 | Num. of L2CAP CBFC channels| ((CY_BLE_L2CAP_CBFC_CHANNEL_SIZE + CY_BLE_MEM_EXT_SZ) * No of L2CAP logical channels)| 2 * No of L2cap logical channels -* 3 | L2CAP MTU (0x17 to 0xFFD0u)| (L2CAP MTU + CY_BLE_MEM_EXT_SZ + CY_BLE_L2CAP_HDR_SZ) | 2 * No of L2cap logical channels -* -* Index position is fixed for each data buffer corresponding to configuration parameters. -* First four buffers of with valid size (shall be > 12) corresponding to each field are required -* for BLE_SOC mode operation. Otherwise, the stack will throw an error. -* -* 'dataBuff' will be modified by stack. If the application wants to reuse dataBuff, the application should keep a copy of it. -* -* *No of buffers should be increased from 3 to Stack queue depth. if mtu>32. -* stack queue depth = (stack queue depth per connection - 1) * maxBleConnection -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INVALID_PARAMETER | On passing a "NULL" for 'CyBLEApplCbFunc' parameter if the BLE stack is not built in HCI mode. On passing a "NULL" for 'memoryHeapPtr' parameter. If maxMtuSize is less than 23 or greater than 512 (only if BLE stack is not built in HCI mode). -* CY_BLE_ERROR_REPEATED_ATTEMPTS | On invoking this function more than once without calling Cy_BLE_StackShutdown() function between calls to this function if the BLE stack is not built in HCI mode. -* -******************************************************************************/ -/* Event callback function prototype to receive events from stack */ -cy_en_ble_api_result_t Cy_BLE_StackInit -( - cy_stc_ble_stack_init_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_StackShutdown -***************************************************************************//** -* This function stops any ongoing operation on the BLE Stack and forces the BLE -* Stack to shut down. The only function that can be called after calling this -* function is Cy_BLE_StackInit. On calling this function, BLE Radio is turned -* off; all the data loaded in retention memory are retained and can be used on -* re-initializing the BLE Stack. -* -* Shutdown complete is informed through 'CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE' event. -* Cy_BLE_ProcessEvents must be called to receive this event. -* -* For UART HCI mode: -* This is a blocking function and no event is generated. -* Only CY_BLE_SUCCESS will be returned and other error codes are not applicable. -* The UART interface will be stopped and UART data will not be processed by the stack -* until Cy_BLE_StackInit is invoked. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | On calling shutdown before calling stack init. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StackShutdown -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_StackSoftReset -***************************************************************************//** -* -* This function resets the BLE Stack, including BLE sub-system hardware -* registers. The BLE Stack transitions to idle mode. This function can be used to -* reset the BLE Stack if the BLE Stack turns unresponsive due to incomplete -* transfers with the peer BLE device. -* -* Reset complete is informed through 'CY_BLE_EVT_SOFT_RESET_COMPLETE event'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | On calling this API before calling stack init. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StackSoftReset -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_ProcessEvents -***************************************************************************//** -* -* This function checks the internal task queue in the BLE Stack, and pending -* operation of the BLE Stack, if any. This must be called at least once -* every interval 't' where: -* 1. 't' is equal to connection interval or scan interval, whichever is -* smaller, if the device is in GAP Central mode of operation, or -* 2. 't' is equal to connection interval or advertisement interval, -* whichever is smaller, if the device is in GAP Peripheral mode -* of operation. -* -* On calling every interval 't', all pending operations of the BLE Stack are -* processed. This is a blocking function and returns only after processing all -* pending events of the BLE Stack. Care should be taken to prevent this call -* from any kind of starvation; on starvation, events may be dropped by the -* stack. All the events generated will be propagated to higher layers of the -* BLE Stack and to the Application layer only after making a call to this -* function. -* -* Calling this function can wake BLESS from Low Power Mode, and in the process -* of waking from BLESS Deep Sleep Mode, the BLE Stack puts the CPU into Sleep Mode to -* save power while polling for a wakeup indication from BLESS. This can occur if -* the caller function has pending data or control transactions to be performed -* in the BLE Stack that must be programmed to BLESS in Cy_BLE_ProcessEvents() -* context when BLESS is in Low Power Mode. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_ProcessEvents -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_StackSetFeatureConfig -***************************************************************************//** -* -* This API sets the configuration for Bluetooth 4.2 features in the BLE Stack to -* initialize the corresponding data structures and data buffers to support -* the features. The BLE Stack will create the data buffers for the Data length extension -* feature, LE Privacy 1_2, and Secure connections as specified in the parameters -* during time of initialization in the initialization API. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: parameter of type 'CY_BLE_STACK_SET_CONFIG_PARAM_T' -* param->configParam: parameter of type cy_stc_ble_stack_config_param_t. This structure contains -* pointers to config params for individual features. Individual -* feature configuration structures can be NULL if that feature is -* not selected. -* -* param->featureHeapReq: Out parameter for returning memory requirement for selected features. -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Invalid configuration parameters passed or invalid combination of configParam and featureMask. -* CY_BLE_ERROR_INVALID_OPERATION | Invoked after successful stack initialization. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StackSetFeatureConfig -( - cy_stc_ble_stack_config_param_t * param -); - - -/******************************************************************************* -* Function Name: Cy_BLE_StackGetFeatureConfig -****************************************************************************//** -* -* This API is used to get Bluetooth 4.2 features configuration made to the BLE Stack -* during Stack initialization. For more details about configuration, please -* refer to API Cy_BLE_StackSetFeatureConfig. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: pointer to cy_stc_ble_stack_config_param_t. This structure -* contains pointers to config params for individual -* features. Application shall provide memory for this -* configuration structure. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If param pointer is NULL. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StackGetFeatureConfig -( - cy_stc_ble_stack_config_param_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_EnablePrivacyFeature -***************************************************************************//** -* -* This function Enables Privacy features in the -* BLE Stack. When this function is not called in the application, -* privacy features are disabled and memory space used in the BLE Stack -* is relinquished. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_EnablePrivacyFeature -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_EnableDleFeature -***************************************************************************//** -* -* This function Enables Data Length Extension features in the -* BLE Stack. When this function is not called in the application, -* DLE features are disabled and memory space used in the BLE Stack -* is relinquished. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_EnableDleFeature -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_EnablePhyUpdateFeature -***************************************************************************//** -* -* This function Enables PHY Update (for 2 Mbps bitrate) feature in the -* BLE Stack. When this function is not called in the application, -* the PHY features are disabled and memory space used in the BLE Stack -* is relinquished. -* -* \return -* None. -* -******************************************************************************/ -void Cy_BLE_EnablePhyUpdateFeature -( - void -); - -/****************************************************************************** -* Function Name: Cy_BLE_SetCustomEventMask -***************************************************************************//** -* This API is used to set the mask that will enable/disable custom events -* -* Set Custom Event mask complete is informed through the -* 'CY_BLE_EVT_SET_EVENT_MASK_COMPLETE' event. -* -* \param param: Pointer to a variable of type UINT8 -* containing the mask bits. -* Following are the supported Mask values -* CY_BLE_DISABLE_ALL_EVENTS_MASK - Disables all custom events -* CY_BLE_CONN_ESTB_EVENT_MASK - For connection establishment -* events -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | One of the input parameter is invalid. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ - -cy_en_ble_api_result_t Cy_BLE_SetCustomEventMask -( - uint8_t *param -); - -/****************************************************************************** -* Function Name: Cy_BLE_StackEnterLPM -***************************************************************************//** -* -* This function requests the BLE Stack (which includes the BLE Controller, BLE -* Host Stack, and BLE Stack manger) to enter into one of the supported low power -* modes. BLE driver/application should use this function to put the Bluetooth Low Energy -* Sub-System (BLESS) register to Low Power Mode (LPM). -* -* The BLE Stack enters and exits low power modes based on its current state. -* The application should consider the BLE Stack's current LPM state before configuring -* the CPU or the overall device into LPM. Note that the CPU will not be able to -* access the BLESS registers when BLESS is in deep sleep mode. -* -* BLE Stack has the following power modes: -* 1. Active -* 2. DeepSleep (Low Power Mode) -* -* Note that certain conditions may prevent the BLE sub system from entering a -* particular low power mode. -* -* # Active Mode # -* BLESS has three sub-modes in Active mode: -* 1. Idle -* 2. Transmit Mode, and -* 3. Receive Mode -* CPU has full access to the BLESS registers in this mode. -* -* # Deep Sleep Mode # -* The BLE ECO is stopped (optional) and Watch Crystal Oscillator (WCO) is used to maintain -* link layer timing. All the regulators in the Radio Frequency (RF) transceiver -* are turned off to reduce the leakage current and BLESS logic is kept powered ON -* from the System Resources Sub System (SRSS) deep-sleep regulator for retention -* of current BLESS state information. This mode can be entered from Idle (Active) mode. -* It should be entered when the next scheduled BLE activity instant is greater -* than the BLESS Deep Sleep total wakeup time (typically 2 ms). -* -* NOTE: If application is using the BLE ECO as source of HFCLK for higher clock accuracy -* and calls this API to move BLESS to Deep Sleep mode, then BLE ECO is kept ON even in BLESS -* DeePSleep mode. -* -* Our recommendation is that the application switches the HFCLK to IMO before calling this API -* to achieve lowest possible system DeepSleep current. On system wakeup due to sources other than BLESS, -* the application can switch the HFCLK source to ECO only when BLESS is active. -* Recommended clock switching pseudo code is given below. -* -* Pseudo Code: -* -> Turn on IMO and switch HFCLK to IMO -* Cy_BLE_StackEnterLPM(CY_BLE_BLESS_DEEPSLEEP); -* Cy_SysPm_DeepSleep(); -* -> If exit is not due to BLE, when wait until BLESS is active before switching HFCLK source to ECO. -* while(Cy_BLE_StackGetBleSsState() != CY_BLE_BLESS_DEEPSLEEP); -* -* The following table indicates the allowed sleep modes for the complete system -* (BLE Sub-system and the micro-controller). Modes marked In 'X' are the allowed -* combinations. The application layer should make sure that the invalid modes -* are not entered in to: -* -* -* |-----------|------------------------------------------------| -* |BLE Stack |PSoC 6 BLE Microcontroller Low Power Modes | -* |LPM Modes |________________________________________________| -* | | Active | Sleep | DeepSleep | Hibernate | -* |___________|___________|__________|_____________|___________| -* | Active | X | X | | | -* |___________|___________|__________|_____________|___________| -* | DeepSleep | | | | | -* | (ECO OFF) | X | X | X | | -* |___________|___________|__________|_____________|___________| -* -* -* The application layer is responsible for configuring the BLE Sub-system and the -* microcontroller in the desired low power modes. Upon entering the requested -* low power mode combination, the BLE Sub-system and the microcontroller are woken -* up by a BLESS interrupt (Advertisement interrupt, connection interrupt, -* scan interrupt, etc.). On wakeup, if the application must transmit data, -* the appropriate function(s), including the Stack functions, must be invoked. -* This must be followed by a call to Cy_BLE_ProcessEvents routine, which -* handles all pending transmit and receive operations. The application can now configure -* the complete system back in to one of the low power modes. The application -* should ensure that the above invalid states are never encountered. -* -* The application shall also ensure that the BLE Sub-system's low power entry and -* low power exit interrupts are processed in realtime and not blocked. The BLE Sub-system interrupt must be of higher priority. -* If the BLE Sub-system interrupts are blocked for a longer time ( > 200 us ), -* the BLE Sub-system can enter an undesired state, resulting in BLE connection failures. -* -* This is a blocking function. In the process of entering into BLESS Deep Sleep Mode, -* the BLE Stack puts the CPU into Sleep Mode to save power while polling -* for an entry indication to BLESS DSM. No event is generated on calling this function. -* Based on the return code from this function, the application layer should -* decide on the sleep mode for the complete system. For example, if the return -* code is CY_BLE_BLESS_DEEPSLEEP, the application can choose to call system -* DeepSleep function. -* -* \param pwrMode: The power mode that the BLE Stack is intended to -* enter. The allowed value is CY_BLE_BLESS_DEEPSLEEP -* -* \return -* cy_en_ble_lp_mode_t : The actual power mode to which the BLE Stack is now set. -* -******************************************************************************/ -cy_en_ble_lp_mode_t Cy_BLE_StackEnterLPM(cy_en_ble_lp_mode_t pwrMode); - -/****************************************************************************** -* Function Name: Cy_BLE_StackGetBleSsState -***************************************************************************//** -* -* This function returns the BLE Subsystem's current operational mode. This state -* can be used to manage system level power modes. -* -* \return: -* cy_en_ble_bless_state_t : BLESS's operating mode has one of the following values -* -* BLE Stack Mode | Description -* -------------- | ----------- -* CY_BLE_BLESS_STATE_ACTIVE | BLE Sub System is in active mode, CPU can be in active mode or sleep mode. -* CY_BLE_BLESS_STATE_EVENT_CLOSE| BLE Sub System radio and Link Layer hardware finished Tx/Rx. In this state, the application can try configuring the stack to Deep Sleep State to save power. -* CY_BLE_BLESS_STATE_ECO_STABLE | BLE Sub System is in the process of waking up from Deep Sleep Mode and the BLE ECO is stable. The CPU can be configured in sleep mode. -* CY_BLE_BLESS_STATE_DEEPSLEEP | BLE Sub System is in Deep Sleep Mode. CPU can be configured in deep sleep mode. -* -******************************************************************************/ -cy_en_ble_bless_state_t Cy_BLE_StackGetBleSsState(void); - -/****************************************************************************** -* Function Name: Cy_BLE_IsControllerActive -***************************************************************************//** -* -* This function checks whether any of the hardware engines of the BLE controller are -* active. If either of ADV/SCAN/INIT/CONN engine is active, it returns CY_BLE_SUCCESS. -* -* \param checkForMode: Sleep mode which controller core is trying to enter -* CY_BLE_CONTROLLER_SLEEP_MODE_SLEEP - Check whether controller core can enter Sleep mode -* CY_BLE_CONTROLLER_SLEEP_MODE_DEEPSLEEP - Check whether controller core can enter DeepSleep mode -* -* \return -* cy_en_ble_api_result_t : Returns whether the controller is active or not. -* -* Return value | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | BLE Controller is active. -* CY_BLE_ERROR_INVALID_OPERATION | BLE Controller is not active. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_IsControllerActive(cy_en_ble_controller_sleep_mode_t checkForMode); - - /** @} */ -#endif //CY_BLE_STACK_H_ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap.h deleted file mode 100644 index 7820cd0c6c..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap.h +++ /dev/null @@ -1,1910 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_gap.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of the Generic Access Profile. -* It also specifies the defines, constants, and data structures required for the APIs. -* -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ -#ifndef CY_BLE_STACK_GAP_H_ -#define CY_BLE_STACK_GAP_H_ - -/*************************************** -* Common stack includes -***************************************/ -#include "BLE_config.h" -#include "cy_ble_stack_host_main.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -** GAP Constants -***************************************/ -/** Bluetooth Device Address size */ -#define CY_BLE_GAP_BD_ADDR_SIZE 0x06u - -/** BD Address type flag*/ - -/** Public Device Address */ -#define CY_BLE_GAP_ADDR_TYPE_PUBLIC 0x00u -/** Random Device Address */ -#define CY_BLE_GAP_ADDR_TYPE_RANDOM 0x01u -/** Controller generates the Resolvable Private Address based on the local - * IRK from the resolving list. If the resolving list contains no matching entry, - * uses the public address. */ -#define CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA 0x02u -/** Controller generates the Resolvable Private Address based on the local - * IRK from the resolving list. If the resolving list contains no matching entry, - * uses random address. */ -#define CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA 0x03u - -/** Max data length size */ -#define CY_BLE_GAP_MAX_ADV_DATA_LEN 0x1Fu - -/** Max data length size */ -#define CY_BLE_GAP_MAX_SCAN_RSP_DATA_LEN 0x1Fu - -/** Security modes */ -#define CY_BLE_GAP_SEC_MODE_1 0x10u /**< security mode 1 */ -#define CY_BLE_GAP_SEC_MODE_2 0x20u /**< security mode 2 */ -#define CY_BLE_GAP_SEC_MODE_MASK 0xF0u /**< security mode bit mask */ - - -/** Pairing properties MASK for cy_stc_ble_gap_auth_info_t */ - -/** - * MASK to set MITM in pairing properties for Secure connections. - */ -#define CY_BLE_GAP_SMP_SC_PAIR_PROP_MITM_MASK 0x01u - -/** - * MASK to set keypress in pairing properties for Secure connections. - */ -#define CY_BLE_GAP_SMP_SC_PAIR_PROP_KP_MASK 0x02u - -/** Maximum number of Bonded Devices */ -#define CY_BLE_GAP_MAX_BONDED_DEVICE 0x10u - -/** Out Of Band (OOB) flag*/ -#define CY_BLE_GAP_OOB_ENABLE 0x01u /**< oob enable */ -#define CY_BLE_GAP_OOB_DISABLE 0x00u /**< oob disable */ - -/** SMP Key size */ -#define CY_BLE_GAP_SMP_LTK_SIZE 0x10u /**< LTK size */ -#define CY_BLE_GAP_SMP_IRK_SIZE 0x10u /**< IRK size */ -#define CY_BLE_GAP_SMP_CSRK_SIZE 0x10u /**< CSRK size */ -#define CY_BLE_GAP_SMP_IDADDR_DATA_SIZE 0x07u /**< ID Address data size */ -#define CY_BLE_GAP_SMP_MID_INFO_SIZE 0x0Au /**< Mid info size */ - -/** Key Distribution Flags */ -#define CY_BLE_GAP_SMP_INIT_ENC_KEY_DIST 0x01u /**< Initiator enc key */ -#define CY_BLE_GAP_SMP_INIT_IRK_KEY_DIST 0x02u /**< Initiator IRK */ -#define CY_BLE_GAP_SMP_INIT_CSRK_KEY_DIST 0x04u /**< Initiator CSRK */ -#define CY_BLE_GAP_SMP_RESP_ENC_KEY_DIST 0x10u /**< Peer enc key */ -#define CY_BLE_GAP_SMP_RESP_IRK_KEY_DIST 0x20u /**< Peer IRK */ -#define CY_BLE_GAP_SMP_RESP_CSRK_KEY_DIST 0x40u /**< Peer CSRK */ - -/** SMP P256 Public-Private Key Size */ -#define CY_BLE_GAP_SMP_P256_PUBLIC_KEY_SIZE 0x40u /**< P256 public key size */ -#define CY_BLE_GAP_SMP_P256_PRIVATE_KEY_SIZE 0x20u /**< P256 private key size */ - -/** Passkey Response */ -#define CY_BLE_GAP_REJECT_PASSKEY_REQ 0x00u /**< Reject passkey request */ -#define CY_BLE_GAP_ACCEPT_PASSKEY_REQ 0x01u /**< Accept passkey request */ - -/** Fixed Passkey */ -#define CY_BLE_GAP_PASSKEY_FIXED 0x01u /**< Fixed passkey */ -#define CY_BLE_GAP_PASSKEY_NOT_FIXED 0x00u /**< Non-fixed passkey */ - - -/*************************************** -** Bonding definitions -***************************************/ -/** No Bonding support */ -#define CY_BLE_GAP_BONDING_NONE 0x00u -/** Bonding support */ -#define CY_BLE_GAP_BONDING 0x01u - -/** Encryption key size */ -#define CY_BLE_GAP_ENCRYP_KEY_MIN 0x07u /**< Min Enc key size */ -#define CY_BLE_GAP_ENCRYP_KEY_MAX 0x10u /**< Max Enc key size */ - -/** User Passkey size */ -#define CY_BLE_GAP_USER_PASSKEY_SIZE 0x06u /**< user passkey size */ - -/** Address Masks */ -/** random private resolvable addr mask */ -#define CY_BLE_GAP_RANDOM_PRIV_RESOLVABLE_ADDR_MASK 0x40u -/** random private non-resolvable addr mask */ -#define CY_BLE_GAP_RANDOM_PRIV_NON_RESOLVABLE_ADDR_MASK 0x00u -/** public addr mask */ -#define CY_BLE_GAP_PUBLIC_ADDR_MASK 0x80u -/** random static addr mask */ -#define CY_BLE_GAP_RANDOM_STATIC_ADDR_MASK 0xC0u - -/** Address Masks */ -#define CY_BLE_GAP_RANDOM_NUMBER_SIZE 0x10u - -/** Device Connected as Role. */ -#define CY_BLE_GAP_LL_ROLE_SLAVE 0x01u /**< Slave role */ -#define CY_BLE_GAP_LL_ROLE_MASTER 0x00u /**< Master role */ - -/** Link Level Encryption status */ -#define CY_BLE_GAP_ENCRYPT_ON 0x01u /**< Encryption on */ -#define CY_BLE_GAP_ENCRYPT_OFF 0x00u /**< Encryption off */ - -/** Security Requirements for strict pairing */ -/** No security requirement */ -#define CY_BLE_GAP_NO_SECURITY_REQUIREMENTS (0x00u) -/** Unauthenticated legacy pairing */ -#define CY_BLE_GAP_SEC_UNAUTH_PAIRING (0x01u) -/** Authenticated legacy pairing */ -#define CY_BLE_GAP_SEC_AUTH_PAIRING (0x02u) -/** Unauthenticated SC pairing */ -#define CY_BLE_GAP_SEC_SC_PAIRING_WITH_NO_MITM (0x04u) -/** Authenticated SC pairing */ -#define CY_BLE_GAP_SEC_SC_PAIRING_WITH_MITM (0x08u) -/** Legacy with OOB pairing */ -#define CY_BLE_GAP_SEC_OOB_IN_LEGACY_PAIRING (0x10u) -/** SC with oob pairing */ -#define CY_BLE_GAP_SEC_OOB_IN_SC_PAIRING (0x20u) -/** Security requirement bit mask */ -#define CY_BLE_GAP_SEC_REQ_BIT_MASK (0x3Fu) - - -/*************************************** -** Enumerated Types -***************************************/ -/** - \addtogroup group_ble_common_api_gap_definitions - @{ -*/ - -/** Security Levels */ -typedef enum -{ - /** Level 1 - * Mode 1 - No security (No authentication and no encryption) - */ - CY_BLE_GAP_SEC_LEVEL_1 = 0x00u, - - /** Level 2 - * Mode 1 - Unauthenticated pairing with encryption (No MITM) - * Mode 2 - Unauthenticated pairing with data signing (No MITM) - */ - CY_BLE_GAP_SEC_LEVEL_2, - - /** Level 3 - * Mode 1 - Authenticated pairing with encryption (With MITM) - * Mode 2 - Authenticated pairing with data signing (With MITM) - */ - CY_BLE_GAP_SEC_LEVEL_3, - - /** Level 4 - * Secured Connection - */ - CY_BLE_GAP_SEC_LEVEL_4, - - /** LE Security Level Mask */ - CY_BLE_GAP_SEC_LEVEL_MASK = 0x0Fu - -}cy_en_ble_gap_sec_level_t; - -/** IO capability */ -typedef enum -{ - /** Platform supports only a mechanism to display or convey only a 6-digit number to the user.*/ - CY_BLE_GAP_IOCAP_DISPLAY_ONLY = 0x00u, - - /** The device has a mechanism whereby the user can indicate 'yes' or 'no'.*/ - CY_BLE_GAP_IOCAP_DISPLAY_YESNO, - - /** Platform supports a numeric keyboard that can input the numbers '0' through '9' - and a confirmation key(s) for 'yes' and 'no'. */ - CY_BLE_GAP_IOCAP_KEYBOARD_ONLY, - - /** Platform does not have the ability to display or communicate a 6 digit decimal number.*/ - CY_BLE_GAP_IOCAP_NOINPUT_NOOUTPUT, - - /** Platform supports a mechanism through which 6 digit numeric value can be displayed - and numeric keyboard that can input the numbers '0' through '9'. */ - CY_BLE_GAP_IOCAP_KEYBOARD_DISPLAY - -} cy_en_ble_gap_iocap_t; - -/** Authentication Failed Error Codes */ -typedef enum -{ - /** No Error */ - CY_BLE_GAP_AUTH_ERROR_NONE = 0x00u, - - /** User input of passkey failed. For example, the user cancelled the operation. */ - CY_BLE_GAP_AUTH_ERROR_PASSKEY_ENTRY_FAILED, - - /** Out Of Band data is not available. Applicable if NFC is supported. */ - CY_BLE_GAP_AUTH_ERROR_OOB_DATA_NOT_AVAILABLE, - - /** Pairing procedure cannot be performed as authentication - requirements cannot be met due to IO capabilities of one or both devices. */ - CY_BLE_GAP_AUTH_ERROR_AUTHENTICATION_REQ_NOT_MET, - - /** Confirm value does not match the calculated compare value. */ - CY_BLE_GAP_AUTH_ERROR_CONFIRM_VALUE_NOT_MATCH, - - /** Pairing is not supported by the device. */ - CY_BLE_GAP_AUTH_ERROR_PAIRING_NOT_SUPPORTED, - - /** Insufficient key size for the security requirements of this device, - or if LTK is lost. */ - CY_BLE_GAP_AUTH_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE, - - /** Command received is not supported. */ - CY_BLE_GAP_AUTH_ERROR_COMMAND_NOT_SUPPORTED, - - /** Pairing failed due to an unspecified reason. */ - CY_BLE_GAP_AUTH_ERROR_UNSPECIFIED_REASON, - - /** Pairing or authentication procedure is disallowed because too little time - has elapsed since the last pairing request or security request. */ - CY_BLE_GAP_AUTH_ERROR_REPEATED_ATTEMPTS, - - /** Invalid Parameters in Request - Invalid Command length and Parameter value outside range. */ - CY_BLE_GAP_AUTH_ERROR_INVALID_PARAMETERS , - - /** Indicates to the remote device that the DHKey Check value received doesn't - match the one calculated by the local device. */ - CY_BLE_GAP_AUTH_ERROR_DHKEY_CHECK_FAILED, - - /** Indicates that the confirm values in the numeric comparison protocol - do not match. */ - CY_BLE_GAP_AUTH_ERROR_NUMERIC_COMPARISON_FAILED, - - /** Indicates that the pairing over the LE transport failed due to a Pairing - Request sent over the BR/EDR transport is in process. */ - CY_BLE_GAP_AUTH_ERROR_BR_EDR_PAIRING_IN_PROGRESS, - - /** Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot - be used to derive and distribute keys for LE transport. */ - CY_BLE_GAP_AUTH_ERROR_CROSS_TRANSPORT_KEY_GEN_DER_NOT_ALLOWED, - - /** Authentication process timeout - if pairing timeout happens for the first time, - the application can choose to re-initiate the pairing procedure. If timeout occurs again, - the application may choose to disconnect the peer device. */ - CY_BLE_GAP_AUTH_ERROR_AUTHENTICATION_TIMEOUT = 0x15u, - - /** Link disconnected. */ - CY_BLE_GAP_AUTH_ERROR_LINK_DISCONNECTED = 0x18u - -}cy_en_ble_gap_auth_failed_reason_t; - -/** GAP address type */ -typedef enum -{ - /** Random private non-resolvable address */ - CY_BLE_GAP_RANDOM_PRIV_NON_RESOLVABLE_ADDR = 0x00u, - - /** Random private resolvable address */ - CY_BLE_GAP_RANDOM_PRIV_RESOLVABLE_ADDR = 0x01u, - - /** Public address */ - CY_BLE_GAP_PUBLIC_ADDR = 0x02u, - - /** Random static address */ - CY_BLE_GAP_RANDOM_STATIC_ADDR = 0x03u, - -} cy_en_ble_gap_addr_type_t; - -/** Passkey entry notification types. - These are used for the Cy_BLE_GAP_SecureConnectionKeyNotify API - as well as with the CY_BLE_EVT_GAP_KEYPRESS_NOTIFICATION event parameter. */ -typedef enum -{ - /** Passkey entry started */ - CY_BLE_GAP_PASSKEY_ENTRY_STARTED = 0x00u, - - /** One digit entered */ - CY_BLE_GAP_PASSKEY_DIGIT_ENTERED = 0x01u, - - /** One digit erased */ - CY_BLE_GAP_PASSKEY_DIGIT_ERASED = 0x02u, - - /** All digits cleared */ - CY_BLE_GAP_PASSKEY_CLEARED = 0x03u, - - /** Passkey entry completed */ - CY_BLE_GAP_PASSKEY_ENTRY_COMPLETED = 0x04u - -} cy_en_ble_gap_keypress_notify_type_t; - -/** GAP Direct advertiser address type */ -typedef enum -{ - /** Public device address type */ - CY_BLE_GAP_PUBLIC_ADDR_TYPE, - - /** Random private resolvable address type*/ - CY_BLE_GAP_RANDOM_RESOLVABLE_ADDR_TYPE, - - /** Public Identity address type*/ - CY_BLE_GAP_PUBLIC_IDENTITY_ADDR_TYPE, - - /** Random static Identity Address */ - CY_BLE_GAP_RANDOM_IDENTITY_ADDR_TYPE - -} cy_en_ble_gap_adv_addr_type_t; - -/*************************************** -** Exported structures and unions -***************************************/ - -/** BD Address of device */ -typedef cy_stc_ble_bd_addr_t cy_stc_ble_gap_bd_addr_t; - -/** Out of Band Parameters Information */ -typedef struct -{ - /** bd handle of the remote device */ - uint8_t bdHandle; - - /** OOB data presence flag. Allowed value are: - * CY_BLE_GAP_OOB_DISABLE - * CY_BLE_GAP_OOB_ENABLE - */ - uint8_t oobFlag; - - /** 16 Octet Temporary Key to be used for OOB authentication */ - uint8_t * key; - - /** Pointer to OOB data */ - uint8_t * oobData; - - /** Length of OOB data */ - uint8_t oobDataLen; - -} cy_stc_ble_gap_oob_info_t; - -/** Security requirement of local device used in strict pairing */ -typedef struct -{ - /** Security requirement */ - uint8_t secReq; - - /** Encryption key size */ - uint8_t encKeySize; -} cy_stc_ble_gap_sec_req_t; - -/** Disconnect command information */ -typedef struct -{ - /** Reason for disconnection */ - uint8_t reason; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_gap_disconnect_info_t; - -/** Peer Bluetooth Device Address information */ -typedef struct -{ - /** Bluetooth device address */ - cy_stc_ble_gap_bd_addr_t bdAddr; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_gap_peer_addr_info_t; - -/** Security keys information */ -typedef struct -{ - /** Long Term Key */ - uint8_t ltkInfo[CY_BLE_GAP_SMP_LTK_SIZE]; - - /** Encrypted Diversifier and Random Number */ - uint8_t midInfo[CY_BLE_GAP_SMP_MID_INFO_SIZE]; - - /** Identity Resolving Key */ - uint8_t irkInfo[CY_BLE_GAP_SMP_IRK_SIZE]; - - /** - * Public device/Static Random address type - * idAddrInfo[0] - Address Type - * idAddrInfo[1] to idAddrInfo[6] - Address - */ - uint8_t idAddrInfo[CY_BLE_GAP_SMP_IDADDR_DATA_SIZE]; - - /** Connection Signature Resolving Key */ - uint8_t csrkInfo[CY_BLE_GAP_SMP_CSRK_SIZE]; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -} cy_stc_ble_gap_sec_key_param_t; - -/** Security information */ -typedef struct -{ - /** Security keys information parameter */ - cy_stc_ble_gap_sec_key_param_t SecKeyParam; - - /**This parameter indicates which keys get exchanged with a peer device. - * The following is the bit field mapping for the keys. - * Bit 0: Local Encryption information - * Bit 1: Local Identity information - * Bit 2: Local Signature Key - * Bit 3: Reserved - * Bit 4: Remote Encryption information - * Bit 5: Remote Identity information - * Bit 6: Remote Signature Key - * Bit 7: Reserved - */ - uint8_t exchangeKeysFlag; - - /**This parameter indicates which keys are to be set/generated in the BLE Stack. - * The following is the bit field mapping for the keys. - * Bit 0: Local Encryption information - * Bit 1: Local Identity information - * Bit 2: Local Signature Key - * Bits 3-7: Reserved - */ - uint8_t localKeysFlag; - -} cy_stc_ble_gap_sec_key_info_t; - -/** Bluetooth Device Address information */ -typedef struct -{ - /** Identity Resolving Key */ - uint8_t irkInfo[CY_BLE_GAP_SMP_IRK_SIZE]; - - /** Memory for gapBdAddr. Completion event will - * use this memory as output parameter. - */ - cy_stc_ble_gap_bd_addr_t gapBdAddr; - - /** Device address type */ - cy_en_ble_gap_addr_type_t addrType; - -}cy_stc_ble_gap_bd_addr_info_t; - - -/** Authentication Parameters Information */ -typedef struct -{ - /** Security Mode setting will be value of enum cy_en_ble_gap_sec_level_t as follows: - * (CY_BLE_GAP_SEC_MODE_1 | CY_BLE_GAP_SEC_LEVEL_2) - * (CY_BLE_GAP_SEC_MODE_1 | CY_BLE_GAP_SEC_LEVEL_3) - * (CY_BLE_GAP_SEC_MODE_1 | CY_BLE_GAP_SEC_LEVEL_4) - * (CY_BLE_GAP_SEC_MODE_2 | CY_BLE_GAP_SEC_LEVEL_2) - * (CY_BLE_GAP_SEC_MODE_2 | CY_BLE_GAP_SEC_LEVEL_3) - */ - uint8_t security; - - /** Bonding type setting: - * CY_BLE_GAP_BONDING_NONE - * CY_BLE_GAP_BONDING - */ - uint8_t bonding; - - /** Encryption Key Size (octets) - * Minimum = 7 - * maximum = 16 - For a slave initiated security request, this parameter must be ignored. - */ - uint8_t ekeySize; - - /** Parameter to say whether authentication is accepted or rejected with a reason. - accepted = CY_BLE_GAP_AUTH_ERROR_NONE or error code cy_en_ble_gap_auth_failed_reason_t. */ - cy_en_ble_gap_auth_failed_reason_t authErr; - - /** - * Bit 0: MITM (Applicable only if Secure connections) - * Use CY_BLE_GAP_SMP_SC_PAIR_PROP_MITM_MASK - * Bit 1: Key press (sets Key press bit in authentication requirements flags of - * pairing request/response. Applicable only for secure connections) - * Use CY_BLE_GAP_SMP_SC_PAIR_PROP_KP_MASK - * Bit [2-7]: RFU - */ - uint8_t pairingProperties; - - /** Peer bdHandle */ - uint8_t bdHandle; - -} cy_stc_ble_gap_auth_info_t; - - -/** Authentication Passkey Information */ -typedef struct -{ - /** 6-digit decimal number (authentication passkey) */ - uint32_t passkey; - - /** Accept or reject passkey entry request. Allowed values are, - * CY_BLE_GAP_REJECT_PASSKEY_REQ - * CY_BLE_GAP_ACCEPT_PASSKEY_REQ - */ - uint8_t accept; - - /** bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_gap_auth_pk_info_t; - - -/** Fixed Passkey Parameters Information */ -typedef struct -{ - /** 6-digit decimal number (<=999999). This is used only if isFixed is - set to true, else ignored */ - uint32_t fixedPassKey; - - /** Peer bdHandle */ - uint8_t bdHandle; - - /** Passkey is fixed application, - * CY_BLE_GAP_PASSKEY_FIXED: 'fixedPassKey' will be used by the BLE Stack that is provided by the application. - * CY_BLE_GAP_PASSKEY_NOT_FIXED: 'fixedPassKey' will be ignored and the BLE Stack will generate as per - security procedure. - */ - uint8_t isFixed; - -}cy_stc_ble_gap_auth_fix_pk_info_t; - - -/** GAP Connection Update parameters */ -typedef struct -{ - /** Minimum value for the connection event interval. This shall be less than - or equal to conn_Interval_Max. Minimum connection interval will be - connIntvMin * 1.25 ms - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntvMin; - - /** Maximum value for the connection event interval. This shall be greater - than or equal to conn_Interval_Min. Maximum connection interval will be - connIntvMax * 1.25 ms - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntvMax; - - /** Slave latency for the connection in number of connection events. - * Range: 0x0000 to 0x01F3 - */ - uint16_t connLatency; - - /** Supervision timeout for the LE Link. Supervision timeout will be - supervisionTO * 10 ms - * Time Range: 100 msec to 32 secs - */ - uint16_t supervisionTO; - - /** Peer bdHandle */ - uint8_t bdHandle; - - /** connection length */ - uint16_t ceLength; - -}cy_stc_ble_gap_conn_update_param_info_t; - - -/** Secure connection only mode parameters */ -typedef struct -{ - /** state: 0 - Disable (Device not in secure connections only mode) \n - 1 - Enable (Device is in secure connections only mode) */ - uint8_t state; - -}cy_stc_ble_gap_sc_mode_info_t; - -/** Secure connection key press notification parameters */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** notification type to be sent to remote identified by bdHandle */ - cy_en_ble_gap_keypress_notify_type_t notificationType; - -}cy_stc_ble_gap_sc_kp_notif_info_t; - -/** Secure connection key press notification parameters */ -typedef struct -{ - /** 16 Bytes Random number to be used for generating OOB data */ - uint8_t *rand; - - /** Peer bdHandle */ - uint8_t bdHandle; -}cy_stc_ble_gap_sc_oob_info_t; - - -/** Bluetooth Bonded Device Address list */ -typedef struct -{ - /** Pointer to list of Bluetooth device addresses and corresponding bdHandle of bonded devices */ - cy_stc_ble_gap_peer_addr_info_t * bdHandleAddrList; - - /** Number of bonded devices */ - uint8_t noOfDevices; - -}cy_stc_ble_gap_bonded_device_list_info_t; - -/** SMP P-256 public-private key pair */ -typedef struct -{ - /** P-256 public key */ - uint8_t publicKey[CY_BLE_GAP_SMP_P256_PUBLIC_KEY_SIZE]; - - /** P-256 private key */ - uint8_t privateKey[CY_BLE_GAP_SMP_P256_PRIVATE_KEY_SIZE]; - - /** If it is set to 1, the public key is validated. If it is set to 0, - public key is not validated. This parameter is not applicable for - CY_BLE_EVT_GAP_GEN_SET_LOCAL_P256_KEYS_COMPLETE event. */ - uint8_t isValidateKeys; - -} cy_stc_ble_gap_smp_local_p256_keys_t; - -/** GAP Connection Update parameters */ -typedef struct -{ - - /** connection length */ - uint16_t ceLength; - - /** Peer bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_gap_ce_length_param_info_t; - -/** GAP Connection Update parameters */ -typedef struct -{ - /** Priority of the connection compared to other connection */ - /** 0x00 Highest and 0xFF lowest and default for all the connections */ - uint8_t connPriority; - - /** Peer bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_gap_set_conn_priority_param_t; - -/* --------------------------Structure corresponding to events-------------------- */ - -/** Current Connection Parameters used by controller */ -typedef struct -{ - /** Status corresponding to this event will be the HCI error code - as defined in BLE spec 4.1 */ - uint8_t status; - - /** Connection interval used on this connection. - * Range: 0x0006 to 0x0C80 - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntv; - - /** Slave latency for the connection in a number of connection events. - * Range: 0x0000 to 0x01F3 - */ - uint16_t connLatency; - - /** Supervision timeout for the LE Link. Supervision timeout will be - supervisionTO * 10 ms - * Time Range: 100 msec to 32 secs - */ - uint16_t supervisionTO; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_gap_conn_param_updated_in_controller_t; - -/** Gap Connected Parameters */ -typedef struct -{ - /** status corresponding to this event will be HCI error code - as defined in BLE spec 4.1 */ - uint8_t status; - - /** bd handle of the remote device */ - uint8_t bdHandle; - - /** Connected as - master = CY_BLE_GAP_LL_ROLE_MASTER, - Slave = CY_BLE_GAP_LL_ROLE_SLAVE */ - uint8_t role; - - /** Address type of the Bluetooth device address - - CY_BLE_GAP_ADDR_TYPE_PUBLIC (Public device address) - - CY_BLE_GAP_ADDR_TYPE_RANDOM (Random device address) */ - uint8_t peerAddrType; - - /** Peer Bluetooth device address of size CY_BLE_BD_ADDR_SIZE*/ - uint8_t * peerAddr; - - /** Connection interval used on this connection. - * Range: 0x0006 to 0x0C80 - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntv; - - /** Slave latency for the connection in number of connection events. - * Range: 0x0000 to 0x01F3 - */ - uint16_t connLatency; - - /** Supervision timeout for the LE Link. Supervision timeout will be - supervisionTO * 10 ms - Time Range: 100 msec to 32 secs - */ - uint16_t supervisionTO; - - /** Master Clock Accuracy parameter is only valid for a slave. On a master, - this parameter shall be set to 0x00.*/ - uint8_t masterClockAccuracy; - -}cy_stc_ble_gap_connected_param_t; - -/** OOB data */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** Status corresponding to this event will be HCI error code - as defined in BLE spec 4.2 */ - uint8_t status; - - /** Rand for OOB. This is also stored in stack */ - uint8_t * key; - - /** OOB Data using 'key' and local Public Key */ - uint8_t * oobData; - - /** Length of OOB data which is 16 Bytes for Secure connections */ - uint8_t oobDataLen; - -}cy_stc_ble_gap_oob_data_param_t; - -/** Current Connection Parameters used by controller */ -typedef struct -{ - /** Connection interval used on this connection. - * Range: 0x0006 to 0x0C80 - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntv; - - /** Slave latency for the connection in number of connection events. - * Range: 0x0000 to 0x01F3 - */ - uint16_t connLatency; - - /** Supervision timeout for the LE Link. Supervision timeout will be - * supervisionTO * 10 ms - * Time Range: 100 msec to 32 secs - */ - uint16_t supervisionTo; - - /** Peer Device Address */ - uint8_t * peerBdAddr; - - /** Peer Device Address type */ - cy_en_ble_gap_adv_addr_type_t peerBdAddrType; - - /** Local Resolvable Private Address - * Resolvable Private Address being used by the local device - * for this connection. - * This is valid only when the Own_Address_Type in - * connection/advertisement parameters - * is set to 0x02 or 0x03. For other Own_Address_Type values, - * this will be all zeros. - */ - uint8_t * localResolvablePvtAddr; - - /** Peer Resolvable Private Address - * Resolvable Private Address being used by the peer device - * for this connection. - * This is valid only for the Peer_Address_Type - * 0x02 or 0x03. For other Peer_Address_Type values, - * this will be all zeros. - */ - uint8_t * peerResolvablePvtAddr; - - /** Connected as - master = CY_BLE_GAP_LL_ROLE_MASTER, - Slave = CY_BLE_GAP_LL_ROLE_SLAVE */ - uint8_t role; - - /** Master clock accuracy - * 0x00 -> 500 ppm - * 0x01 -> 250 ppm - * 0x02 -> 150 ppm - * 0x03 -> 100 ppm - * 0x04 -> 75 ppm - * 0x05 -> 50 ppm - * 0x06 -> 30 ppm - * 0x07 -> 20 ppm - */ - uint8_t masterClockAccuracy; - - /** Status corresponding to this event will be HCI error code. - * Values of 0 indicates connection successfully completed. - * Refer BLE spec 4.2,Vol2, Part D for Error codes. - */ - uint8_t status; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_gap_enhance_conn_complete_param_t; - -/** Disconnection Parameters */ -typedef struct -{ - /** HCI error code as defined in Bluetooth 4.1 core specification, Volume 2, - Part D, section 1.3 */ - uint8_t status; - - /** Peer bdHandle */ - uint8_t bdHandle; - - /** Reason for disconnection */ - uint8_t reason; - -}cy_stc_ble_gap_disconnect_param_t; - -/** Encryption Change Parameters */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** Encryption change event for active connection. 'evParam' can be decoded as - encryption = CY_BLE_GAP_ENCRYPT_OFF -> Encryption OFF - encryption = CY_BLE_GAP_ENCRYPT_ON -> Encryption ON */ - uint8_t encryption; - -}cy_stc_ble_gap_encrypt_change_param_t; -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_gap_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetIoCap -***************************************************************************//** -* -* This function sets the input and output capability of the BLE Device that is -* used during authentication procedure. This is a blocking function. No event -* is generated on calling this function. The input capabilities are described -* in the following table: -* -* Capability | Description -* ----------- | ----------- -* No input | Device does not have the ability to indicate "yes" or "no". -* Yes/No | Device has at least two buttons that can be easily mapped to "yes" and "no" or the device has a mechanism whereby the user can indicate either "yes" or "no". -* Keyboard | Device has a numeric keyboard that can input the numbers "0" through "9" and a confirmation. Device also has at least two buttons that can be easily mapped to "yes" and "no" or the device has a mechanism whereby the user can indicate either "yes" or "no". -* -* The output capabilities are described in the following table: -* -* Capability | Description -* ----------- | ----------- -* No output | Device does not have the ability to display or communicate a 6-digit decimal number. -* Numeric output | Device has the ability to display or communicate a 6-digit decimal number. -* -* The combined capability is defined in the following table: -* -* Input Capability | No Output | Numeric Output -* ----------- | ----------- | ------------ -* No input | NoInputNoOutput | DisplayOnly -* Yes/No | NoInputNoOutput | DisplayYesNo -* Keyboard | KeyboardOnly | KeyboardDisplay -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: IO parameter is of type cy_en_ble_gap_iocap_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying invalid input parameter -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetIoCap -( - const cy_en_ble_gap_iocap_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetSecurityRequirements -***************************************************************************//** -* -* This function is used to set the security requirements of local device and encryption -* key size requirement of the local device. This is a blocking function. No event -* is generated on calling this function. It is expected to call this API on host stack -* on, though can be called at any point except when any of SMP procedure is in progress. -* Security requirements are defined in the following table: -* -* Security Requirement | Description -* ---------------------- | ----------- -* CY_BLE_GAP_NO_SECURITY_REQUIREMENTS | Default:Security requirement specifies there are no security requirements -* CY_BLE_GAP_SEC_UNAUTH_PAIRING | Bit 0: Legacy pairing with NO MITM protection -* CY_BLE_GAP_SEC_AUTH_PAIRING | Bit 1: Legacy pairing with MITM protection -* CY_BLE_GAP_SEC_SC_PAIRING_WITH_NO_MITM | Bit 2: Secured Connection pairing with NO MITM protection -* CY_BLE_GAP_SEC_SC_PAIRING_WITH_MITM | Bit 3: Secured Connection pairing with MITM protection -* CY_BLE_GAP_SEC_OOB_IN_LEGACY_PAIRING | Bit 4: Legacy pairing with OOB method -* CY_BLE_GAP_SEC_OOB_IN_SC_PAIRING | Bit 5: Secured Connection pairing with OOB method -* -* After this API is called, the BLE Stack will check whether the received -* security request or pairing request or pairing response satisfies local -* device security requirements that are set using this API. If local device -* security requirements are not met, then pairing is rejected by the BLE stack. -* -* For example: Cy_BLE_GAP_SetSecurityRequirements() is called with secReq as CY_BLE_GAP_SEC_SC_PAIRING_WITH_MITM. -* Now if the BLE Stack receives any pairing request with SC bit and MITM bit are not set, -* then that pairing request will be rejected by the stack. -* -* Note: If the Secured Connection (SC) Only mode is set, then these security requirements are not -* considered during pairing procedure. This is to maintain BWC for SC Only mode. -* -* \param param: Parameter is pointer to type cy_stc_ble_gap_sec_req_t. -* -* secReq: Security requirement is a bit-field parameter. The application can -* set this value with the above defined values in the table. The application can set -* multiple security requirements by ORing them in this parameter. -* For example: If secReq is (CY_BLE_GAP_SEC_UNAUTH_PAIRING | CY_BLE_GAP_SEC_SC_PAIRING_WITH_NO_MITM), -* then the stack allows pairing only if the received pairing request is either Legacy -* pairing with NO MITM or Secured Connection pairing with NO MITM. -* -* encKeySize: Encryption key size requirement of the local device. -* This parameter does not affect anything on the central side. At the peripheral side, -* when encryption key size is set using this API, then after during pairing if -* the negotiated key size is less than the key size set by this API, then the BLE Stack will -* reject that pairing request. -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying invalid input parameter -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetSecurityRequirements -( - cy_stc_ble_gap_sec_req_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetOobData -***************************************************************************//** -* -* This function sets OOB presence flag and data. This function should be used -* by the application layer if it wants to enable OOB bonding procedure for any -* specific device identified by 'bdHandle'. This function should be called -* before initiating authentication or before responding to an authentication -* request to set OOB flag and data. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: parameter is of type cy_stc_ble_gap_oob_info_t. -* param->oobData is ignored in case of the Legacy Pairing procedure. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_NO_DEVICE_ENTITY | 'bdHandle' does not represent known device entity -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetOobData -( - cy_stc_ble_gap_oob_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GenerateBdAddress -***************************************************************************//** -* -* This function generates either public or random address based on 'type' specified by -* 'cy_en_ble_gap_addr_type_t' filed of 'cy_stc_ble_gap_bd_addr_info_t'. -* It uses BLE Controller's random number generator to generate the random part of the -* Bluetooth device address. -* -* This is none blocking function. Generated address is informed through 'CY_BLE_EVT_GAP_DEVICE_ADDR_GEN_COMPLETE' -* -* \param param: Buffer is of type cy_stc_ble_gap_bd_addr_info_t. -* param->irk: Buffer containing 128-bit 'IRK' data. This parameter is only -* used when CY_BLE_GAP_RANDOM_PRIV_RESOLVABLE_ADDR is the value set to -* param->addrType'. type of address to be generated. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -* \note: -* Note1: param should point to valid memory location until completion of API - is indicated via the CY_BLE_EVT_GAP_DEVICE_ADDR_GEN_COMPLETE event. -* Note2: To guarantee that sequential calls to Cy_BLE_GAP_GenerateBdAddress API generate different addresses, -* a call to Cy_BLE_GenerateRandomNumber should be made between calls made -* to the Cy_BLE_GAP_GenerateBdAddress API. These calls to the Cy_BLE_GenerateRandomNumber API -* should use unique seeds for these calls. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GenerateBdAddress -( - cy_stc_ble_gap_bd_addr_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_Disconnect -***************************************************************************//** -* -* This function disconnects the peer device. It is to be used by the device in -* GAP Central mode and may be used by a GAP Peripheral device to send a -* disconnect request. This is a non-blocking function. On disconnection, the -* following events are generated, in order. -* * CY_BLE_EVT_GATT_DISCONNECT_IND -* * CY_BLE_EVT_GAP_DEVICE_DISCONNECTED -* -* \param param: parameter is of type 'cy_stc_ble_gap_disconnect_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' pointer is NULL -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_Disconnect -( - cy_stc_ble_gap_disconnect_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetPeerBdAddr -***************************************************************************//** -* -* This function reads the peer Bluetooth device address that has already been -* fetched by the BLE Stack. 'peerBdAddr' stores the peer's Bluetooth device -* address identified with 'bdHandle'. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: parameter is of type cy_stc_ble_gap_peer_addr_info_t, where -* param->bdHandle: Peer device handle, input parameter -* param->bdAddr: Empty buffer where the peer Bluetooth device address will be stored. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'peerBdAddr'. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Specified device handle does not map to any device handle entry in the BLE stack. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetPeerBdAddr -( - cy_stc_ble_gap_peer_addr_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetPeerBdHandle -***************************************************************************//** -* -* This function reads the device handle of the remote Bluetooth device using -* 'peerBdAddr', which has already been fetched by the BLE Stack. 'bdHandle' -* stores the peer device handle. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: parameter is of type cy_stc_ble_gap_peer_addr_info_t, where -* param->bdHandle: buffer where peer device handle will be stored, output parameter -* param->bdAddr: Peer Bluetooth device address will be stored. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ---------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'peerBdAddr' or 'bdHandle'. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Specified device address does not map to any entry in BLE stack. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetPeerBdHandle -( - cy_stc_ble_gap_peer_addr_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetPeerDevSecurity -***************************************************************************//** -* -* This function enables the application to get the device security of the peer -* device, which has already been fetched by the BLE Stack, identified using -* 'bdHandle' when the peer device is in the trusted list. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: Pointer to a buffer of type 'cy_stc_ble_gap_auth_info_t' into which security -* information will be written. -* param->security: It ignores LE Security mode. Security should be interpreted as MITM and no MITM as -* encryption is always supported if pairing is performed between two devices. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'authInfo'. -* CY_BLE_ERROR_INVALID_OPERATION | An error occurred in the BLE stack. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Specified device handle does not map to any device handle entry in the BLE stack. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetPeerDevSecurity -( - cy_stc_ble_gap_auth_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetPeerDevSecurityKeyInfo -***************************************************************************//** -* -* This function enables the application to know the keys shared by a given peer -* device upon completion of the security sequence (already fetched by the BLE -* Stack). The keys are shared by the peer device on initiation of authentication, which -* is performed using the Cy_BLE_GAP_AuthReq() or Cy_BLE_GAPP_AuthReqReply() -* function. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: buffer is of type cy_stc_ble_gap_sec_key_info_t, where peer device security -* information will be stored. -* param->SecKeyParam.bdHandle: input parameters -* param->localKeysFlag : ignored -* param->exchangeKeysFlag : Keys exchanged by peer (output parameter) -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'keyInfo'. -* CY_BLE_ERROR_INVALID_OPERATION | An error occurred in BLE stack. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetPeerDevSecurityKeyInfo -( - cy_stc_ble_gap_sec_key_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetLocalDevSecurityKeyInfo -***************************************************************************//** -* -* This function gets the local device's keys and key flags. The IRK received from -* this function should be used as the input IRK for the function -* 'Cy_BLE_GAP_GenerateDeviceAddress' to generate Random Private Resolvable address. -* This is a blocking function. No event is generated on calling this function. -* -* \param param: buffer is of type cy_stc_ble_gap_sec_key_info_t, where local device security -* information will be stored. -* param->SecKeyParam.bdHandle: keys corresponding to peer device -* param->localKeysFlag : ignored -* param->exchangeKeysFlag : Key to be sent to peer (output parameter) -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameters -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetLocalDevSecurityKeyInfo -( - cy_stc_ble_gap_sec_key_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetSecurityKeys -***************************************************************************//** -* -* This function sets the security keys that are to be exchanged with a peer -* device during key exchange stage of the authentication procedure and sets it in the -* BLE Stack. The application is expected to set new keys for new connections. By default, -* stack will use 'ZEROs' for the keys if not set by the application. The last set keys will be used -* by the BLE stack during the pairing procedure. -* -* This is a blocking function. No event is generated on calling this function. -* This API should be called before the pairing process begins, preferably after -* 'CY_BLE_EVT_GAP_DEVICE_CONNECTED or CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE' -* is received. -* -* \param param: buffer is of type cy_stc_ble_gap_sec_key_info_t, which contains the -* security keys to be set to BLE Stack. -* param->SecKeyParam.bdHandle: input parameters -* param->exchangeKeysFlag : input parameters -* param->localKeysFlag : input parameters -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'keyInfo' -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist. -* -* \note: -* Note1: idAddrInfo is ignored as it is device level information. -* Use Cy_BLE_GAP_SetIdAddress to set the ID address for the device. -* Note2: 'exchangeKeysFlag' flags will automatically be ignored if this does not match with -* the exchange key flag received for a peer during pairing process. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetSecurityKeys -( - cy_stc_ble_gap_sec_key_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GenerateKeys -***************************************************************************//** -* -* This function generates the security keys as per application requirement. -* -* Generated Keys are informed through 'CY_BLE_EVT_GAP_KEYS_GEN_COMPLETE' -* This API does not generate identity address (keyInfo->idAddrInfo) -* -* \param param: buffer is of type cy_stc_ble_gap_sec_key_info_t, where generated keys are store. -* param->SecKeyParam.bdHandle: parameter ignored -* param->exchangeKeysFlag : parameters ignored -* param->localKeysFlag : input parameter -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'keyInfo' -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -* \note -* Note1: param should point to a valid memory location until completion of API -* is indicated via CY_BLE_EVT_GAP_KEYS_GEN_COMPLETE event. -* Note2: To guarantee that sequential calls to Cy_BLE_GAP_GenerateKeys API generate different keys, -* a call to Cy_BLE_GenerateRandomNumber should be made between calls made -* to Cy_BLE_GAP_GenerateKeys API. These calls to Cy_BLE_GenerateRandomNumber API -* should use unique seeds for these calls. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GenerateKeys -( - cy_stc_ble_gap_sec_key_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_AuthReq -***************************************************************************//** -* -* This function starts authentication/pairing procedure with the peer device. -* It is a non-blocking function. -* -* If the local device is a GAP Central, the pairing request is sent to the GAP -* Peripheral device. On receiving CY_BLE_EVT_GAP_AUTH_REQ event, the GAP -* Peripheral is expected to respond by invoking the Cy_BLE_GAPP_AuthReqReply() -* function. -* -* If the local device is GAP Peripheral, a Security Request is sent to GAP -* Central device. On receiving CY_BLE_EVT_GAP_AUTH_REQ event, the GAP Central -* device is expected to respond by invoking 'Cy_BLE_GAP_AuthReq ()' function. -* -* Events shown in the following table may be received by the application based -* on the authentication result. -* -* Event Name | Description -* ------------ | ----------- -* CY_BLE_EVT_GAP_AUTH_COMPLETE | Pointer to structure of type 'cy_stc_ble_gap_auth_info_t' is returned as parameter to both the peer devices on successful authentication. -* CY_BLE_EVT_GAP_AUTH_FAILED | Received by both GAP Central and Peripheral devices (peers) on authentication failure. Data is of type 'cy_en_ble_gap_auth_failed_reason_t'. -* -* Following events may occur if API result is CY_BLE_SUCCESS: -* -* Event Name | Description -* ------------ | ----------- -* CY_BLE_EVT_GAP_SMP_NEGOTIATED_AUTH_INFO| SMP has completed pairing properties (feature exchange) negotiation. -* CY_BLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT | SMP keys exchange with peer device is completed. -* CY_BLE_EVT_GAP_ENCRYPT_CHANGE | When there is a change in encryption after pairing procedure. -* -* Based on IO capabilities, security modes following events may occur -* during pairing procedure. -* Please refer to the Core spec 4.2 volume 3 part - H section 2.3.5.1 -* to learn more about Selecting Key Generation Method. -* -* | Event Name | -* | ------------------------ | -* | CY_BLE_EVT_GAP_PASSKEY_DISPLAY_REQUEST | -* | CY_BLE_EVT_GAP_KEYPRESS_NOTIFICATION | -* | CY_BLE_EVT_GAP_NUMERIC_COMPARISON_REQUEST | -* -* \param param: Pointer to security information of the device of type -* cy_stc_ble_gap_auth_info_t. Param->security can take the value -* from enum cy_en_ble_gap_sec_level_t. -* NOTE: If the bonding flag in param is set to CY_BLE_GAP_BONDING_NONE, then -* SMP keys will not be distributed even if the application has generated -* and set the keys explicitly. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' pointer is NULL or if any of the element of this structure are invalid -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | On bonded device is full and application tries to initiate pairing with bonding enable -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_AuthReq -( - cy_stc_ble_gap_auth_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_AuthPassKeyReply -***************************************************************************//** -* -* This function sends a passkey for authentication. It is a non-blocking function. -* -* It should be invoked in reply to the authentication request event -* CY_BLE_EVT_GAP_PASSKEY_ENTRY_REQUEST received by the BLE Stack. This function -* is used to accept the passkey request and send the passkey or reject the -* passkey request. -* -* * If the authentication operation succeeds, the CY_BLE_EVT_GAP_AUTH_COMPLETE is -* generated. If the authentication process times out, the CY_BLE_EVT_TIMEOUT -* event is generated. -* * If the authentication fails, the CY_BLE_EVT_GAP_AUTH_FAILED event is generated. -* -* \param param: Pointer to security information of the device of type -* cy_stc_ble_gap_auth_pk_info_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If param pointer is NULL -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist. -* CY_BLE_ERROR_INVALID_OPERATION | If CY_BLE_EVT_GAP_PASSKEY_ENTRY_REQUEST event is not received before this API call -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_AuthPassKeyReply -( - cy_stc_ble_gap_auth_pk_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_FixAuthPassKey -***************************************************************************//** -* Sets or clears a fixed passkey to be used by the SMP procedure. -* This is a blocking function. No event is generated on calling this function. -* \note: -* Note1: The fixed passkey will work only if we are the device displaying the -* passkey and peer has to enter the passkey. -* This will not work for numeric comparison (secure connections) method. -* Note2: The fixed passkey is not persistent across power cycle. -* Note3: This API should not be called during an ongoing SMP procedure. -* Call this API on Stack Init completion. -* -* -* \param param: Parameter is of type 'cy_stc_ble_gap_auth_fix_pk_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If any of input parameters are invalid. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_FixAuthPassKey -( - cy_stc_ble_gap_auth_fix_pk_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetSecureConnectionsOnlyMode -***************************************************************************//** -* -* This API sets the state of the SC Only mode for device. -* If device is in SC Only mode, it will allow pairing to -* complete only with secure connections security. Another kind of pairing will -* lead to pairing failure with reason "Authentication requirement not met" -* You should call this API on host stack on, though it can be called -* at any point. -* SC Only mode is not persistent across power cycles. It is -* persistent across stack shutdown-init cycles. -* -* \param param: Parameter is of type 'cy_stc_ble_gap_sc_mode_info_t' -* bdHandle should be ignored. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | Secure connections feature was not selected in feature config. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'state' value is invalid. -* -* Note: This is device level policy and doesn't depend on bdHandle. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetSecureConnectionsOnlyMode -( - cy_stc_ble_gap_sc_mode_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GenerateSetLocalP256Keys -***************************************************************************//** -* -* This API is used to generate and set P-256 Public-Private key pair to be using during LE Secure connection -* pairing procedure. The application may choose to generate a P-256 public-private key pair before pairing -* process starts. If this API is not called before pairing process starts, the BLE stack will use a default -* public-private key pair. -* Successful completion is informed by CY_BLE_EVT_GAP_GEN_SET_LOCAL_P256_KEYS_COMPLETE event. -* Event parameter contains the keys that are generated and set for LE Secure connection pairing procedure. -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | Pairing is in progress or Secure Connections feature is not enabled. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GenerateSetLocalP256Keys -( - void -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetLocalP256Keys -***************************************************************************//** -* -* This API is used to set a P-256 Public-Private key pair to be used during the LE Secure connection -* pairing procedure. The application may choose to set a P-256 public-private key pair before the pairing -* process starts. If this API is not called before the pairing process starts, the BLE stack will use a default -* public-private key pair. This API is not expected to be called when a pairing procedure is in progress. -* The application can provide a P-256 Public-Private key pair to be set for the LE Secure connection pairing procedure. -* -* \param param: Pointer to structure cy_stc_ble_gap_smp_local_p256_keys_t, that has -* fields for local P-256 public-private key pair. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Parameter is NULL Or Public key is not valid -* CY_BLE_ERROR_INVALID_OPERATION | Pairing is in progress. -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetLocalP256Keys -( - cy_stc_ble_gap_smp_local_p256_keys_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_AuthSendKeyPress -***************************************************************************//** -* -* This API is used to send the LE Secure connections key press notification to a peer device during secure connection pairing. -* This API should be called by the application to inform the stack about the passkey entry process started for each digit: -* Started (0), entered (1), erased (2), cleared (3). Once all the digits are entered, application needs to call -* 'Cy_BLE_GAP_AuthPassKeyReply()' to inform the stack for passkey enter completed. -* An error will be returned if key press entry bit was not set in 'pairingProperties' of cy_stc_ble_gap_auth_info_t -* during the authentication procedure. -* -* \param param: Parameter is of type 'cy_stc_ble_gap_sc_kp_notif_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or notificationType is invalid. -* CY_BLE_ERROR_INVALID_OPERATION | If keypress was not negotiated or Secured Connection is not enabled or passkey entry procedure or pairing procedure is not in progress. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_AuthSendKeyPress -( - cy_stc_ble_gap_sc_kp_notif_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GenerateOobData -***************************************************************************//** -* -* This API is used to generate OOB data based on the input parameter (16 Byte random number) -* This API is called to generate OOB data to be used by peer device. Peer device (or local device with peer's OOB data) -* will use 'Cy_BLE_GAP_SetOobData()' to set the oob data to be used for secure connections pairing. -* API compilation is informed through the 'CY_BLE_EVT_GAP_OOB_GENERATED_NOTIFICATION' event. -* Note: This API must be used only during secured connection pairing. -* -* \param param: parameter is of type 'cy_stc_ble_gap_sc_oob_info_t'. -* If 'param->rand' is NULL, stack will generate 16 Bytes random number and then will generate OOB data. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Sufficient memory is not available to handle this request. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GenerateOobData -( - cy_stc_ble_gap_sc_oob_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetBdAddress -***************************************************************************//** -* -* This function sets the Bluetooth device address into the BLE stack's memory. -* This address shall be used for all BLE procedures unless explicitly changed by the application. -* The application layer must call this function every time an address change is required. -* Bluetooth 4.1 Core specification [3.12] specifies that the Bluetooth device can change its -* private address periodically, with the period being decided by the -* application; there are no limits specified on this period. The application -* layer should maintain its own timers in order to do this. -* -* User should call 'Cy_BLE_GAP_SetIdAddress' API to set identity address if 'Cy_BLE_GAP_SetBdAddress' -* API is used to set public or random static address. -* API compilation is informed through the 'CY_BLE_EVT_SET_DEVICE_ADDR_COMPLETE' event -* -* -* \param param: Bluetooth Device address retrieved from the BLE stack gets stored -* to a variable pointed to by this pointer. The variable is of type -* cy_stc_ble_bd_addr_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetBdAddress -( - cy_stc_ble_gap_bd_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetBdAddress -***************************************************************************//** -* -* This API reads the BD device address from the BLE Controller's memory. This -* address shall be used for BLE procedures unless explicitly indicated by the BLE -* Host through HCI commands. -* The BD Address is informed through event 'CY_BLE_EVT_GET_DEVICE_ADDR_COMPLETE' -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetBdAddress -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetIdAddress -***************************************************************************//** -* -* This function sets the Bluetooth identity address into BLE Stack. Calling this API will change only -* the identity address of the device. If the public address or static random address is changed by the user, this -* API must be called to set the appropriate address as the identity address. -* -* This is a blocking function. No event is generated on calling this function. -* -* \param param: Pointer to the cy_stc_ble_gap_bd_addr_t structure variable. It has two -* fields where, -* * param.addr: Bluetooth Device address buffer that is populated with -* the device address data. -* * param.type: Caller function should fill the "address type" to -* set appropriate address. -* . -* Caller function should use param.type = 0x00 to set the "Public -* Device Address" as identity address.
-* Caller function use param.type = 0x01 to set the "Static Random -* Device Address" as identity address. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetIdAddress -( - const cy_stc_ble_gap_bd_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_GetBondList -***************************************************************************//** -* -* This function returns the count and Bluetooth device address along with BD handles of the devices in -* the bonded device list in the order of Rank*. This is a blocking function. No event is generated on -* calling this function. -* -* Rank: The newest device bonded will be at 0 index. -* -* -* Refer Bluetooth 4.1 core specification, Volume 3, Part C, section 9.4.4 for -* details on bonded devices. -* -* \param param: Buffer to which list of bonded devices will be stored -* of type cy_stc_ble_gap_bonded_device_list_info_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* -* Note : Provide sufficient memory for 'param->bdHandleAddrList' based on 'bondListSize' -* parameter that is passed during Stack Initialization otherwise provided memory might -* be corrupted if memory is not sufficient to store all bonded device information. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_GetBondList -( - cy_stc_ble_gap_bonded_device_list_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_RemoveDeviceFromBondList -***************************************************************************//** -* -* This function removes the device from the bond list. -* -* Successful operation is informed through 'CY_BLE_EVT_PENDING_FLASH_WRITE' event -* -* \param param: Pointer to peer device address, of type cy_stc_ble_gap_bd_addr_t. If the device -* address is set to 0, then all devices shall be removed from trusted white list. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'bdAddr'. -* CY_BLE_ERROR_INVALID_OPERATION | Operation is not permitted when device is in connected state. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_RemoveDeviceFromBondList -( - cy_stc_ble_gap_bd_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_RemoveOldestDeviceFromBondedList -***************************************************************************//** -* -* This function removes the oldest device from the bonded and white lists. -* This API should not be called while in the connected state. -* If the device is connected to the oldest device and this API is called, it will remove the device that is oldest and not -* connected. -* -* Successful operation is informed through 'CY_BLE_EVT_PENDING_FLASH_WRITE' event -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded (0x0000) or failed. -* Following are the possible error codes returned. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MAX | On failure operation. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_RemoveOldestDeviceFromBondedList -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetCeLengthParam -***************************************************************************//** -* -* This function sets the connection event length to be used for a specific connection. -* API completion is informed through the 'CY_BLE_EVT_SET_CE_LENGTH_COMPLETE' event -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded (0x0000) or failed. -* Following are the possible error codes returned. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Incorrect bdHandle. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -* Note1: The primary usage of this API is to allow application to control bandwidth -* by setting connection event lengths for specific connections. -* Note2: Application shall set ceLength to 0xFFFF to allow stack to internally -* use maximum possible bandwidth for this connection. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetCeLengthParam -( - cy_stc_ble_gap_ce_length_param_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAP_SetConnectionPriority -***************************************************************************//** -* -* This function sets the link layer connection priority to be used for a -* connection during arbitration. Link layer arbiter resolves radio contention -* based on the priority level of the contending connections. If one or more contending -* connections have the same priority level (default configuration), then a round-robin -* scheme is used to resolve contention. Priority value of 0x00 corresponds to -* highest priority and 0xFF is the lowest and default priority setting for a -* connection. -* API completion is informed through the 'CY_BLE_EVT_SET_CONN_PRIORITY_COMPLETE' event -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded (0x0000) or failed. -* Following are the possible error codes returned. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Incorrect bdHandle. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAP_SetConnectionPriority -( - cy_stc_ble_gap_set_conn_priority_param_t * param -); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/** @} */ - -#endif /* CY_BLE_STACK_GAP_H_ */ - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap_central.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap_central.h deleted file mode 100644 index 9dfc80251c..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap_central.h +++ /dev/null @@ -1,653 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_gap_central.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of Generic Access Profile - Central Role. -* Also specified the defines, constants, and data structures required for the APIs. -* -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ -#ifndef CY_BLE_STACK_GAP_CENTRAL_H_ -#define CY_BLE_STACK_GAP_CENTRAL_H_ - -/*************************************** -* Common stack includes -***************************************/ - -#include "cy_ble_stack_gap.h" - - -/*************************************** -** GAP Constants -***************************************/ - -/** Observation and discovery procedure */ -#define CY_BLE_GAPC_OBSER_PROCEDURE 0x00u /**< Observation procedure */ -#define CY_BLE_GAPC_LTD_DISC_PROCEDURE 0x01u /**< Limited discovery procedure */ -#define CY_BLE_GAPC_GEN_DISC_PROCEDURE 0x02u /**< General discovery procedure */ - -/** Type of discovery procedure use in cy_stc_ble_gapc_disc_info_t*/ -#define CY_BLE_GAPC_PASSIVE_SCANNING 0x00u /**< passive scan */ -#define CY_BLE_GAPC_ACTIVE_SCANNING 0x01u /**< active scan */ -#define CY_BLE_GAPC_FILTER_DUP_DISABLE 0x00u /**< Filter duplicate disable */ -#define CY_BLE_GAPC_FILTER_DUP_ENABLE 0x01u /**< Filter duplicate enable */ - -/** Scan filter policy */ - -/** Accept all advertisement packets except directed advertising packets not - * addressed to this device - */ -#define CY_BLE_GAPC_ADV_ACCEPT_ALL_PKT 0x00u - -/** Accept only advertisement packets from devices where the advertiser's address - * is in the whitelist. Directed advertising packets that are not addressed for - * this device shall be ignored. - */ -#define CY_BLE_GAPC_ADV_ACCEPT_WHITELIST_PKT 0x01u - -/** 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. - */ -#define CY_BLE_GAPC_ADV_ACCEPT_DIRECTED_RPA_PKT 0x02u - -/** Accept all advertisement packets from devices where the advertiser's address - * is in the whitelist, and directed advertising packets where the initiator address - * is a resolvable private address, and directed advertising packets addressed - * to this device. - */ -#define CY_BLE_GAPC_ADV_ACCEPT_WHITELIST_DIRECTED_RPA_PKT 0x03u - -/** Initiator filter policy*/ -#define CY_BLE_GAPC_CONN_ALL 0x00u /**< Filter policy- connect all */ -#define CY_BLE_GAPC_CONN_WHITELIST 0x01u /**< Filter policy- connect only from whitelist */ - -/** - \addtogroup group_ble_common_api_gap_definitions - @{ -*/ - -/*************************************** -** Enumerated Types -***************************************/ - -/** Advertisement event type */ -typedef enum -{ - /** Connectable undirected advertising */ - CY_BLE_GAPC_CONN_UNDIRECTED_ADV = 0x00u, - - /** Connectable directed advertising */ - CY_BLE_GAPC_CONN_DIRECTED_ADV, - - /** Scannable undirected advertising */ - CY_BLE_GAPC_SCAN_UNDIRECTED_ADV, - - /** Non connectable undirected advertising */ - CY_BLE_GAPC_NON_CONN_UNDIRECTED_ADV, - - /** Scan Response*/ - CY_BLE_GAPC_SCAN_RSP - -}cy_en_ble_gapc_adv_event_t; - -/*************************************** -** Exported structures and unions -***************************************/ - -/** Discovery (scan) parameter */ -typedef struct -{ - /** Observation and discovery procedure. - - CY_BLE_GAPC_OBSER_PROCEDURE (Observation procedure) - - CY_BLE_GAPC_LTD_DISC_PROCEDURE (Limited discovery procedure) - - CY_BLE_GAPC_GEN_DISC_PROCEDURE (General discovery procedure) - */ - uint8_t discProcedure; - - /** Type of scan to perform - - CY_BLE_GAPC_PASSIVE_SCANNING (Passive Scanning) - - CY_BLE_GAPC_ACTIVE_SCANNING (Active scanning) - */ - uint8_t scanType; - - /** The time interval from when last LE scan is started until - next subsequent LE scan. - - Time Range: 2.5 ms to 10.24 sec. - */ - uint16_t scanIntv; - - /** The time duration of scanning to be performed - - Time Range: 2.5 ms to 10.24 sec - */ - uint16_t scanWindow; - - /** Own BD Address Type - - CY_BLE_GAP_ADDR_TYPE_PUBLIC - - CY_BLE_GAP_ADDR_TYPE_RANDOM - - CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA - - CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA - */ - uint8_t ownAddrType; - - /** Filter policies to be applied during scanning procedure - - CY_BLE_GAPC_ADV_ACCEPT_ALL_PKT - - CY_BLE_GAPC_ADV_ACCEPT_WHITELIST_PKT - - CY_BLE_GAPC_ADV_ACCEPT_DIRECTED_RPA_PKT - - CY_BLE_GAPC_ADV_ACCEPT_WHITELIST_DIRECTED_RPA_PKT - */ - uint8_t scanFilterPolicy; - - /** Scan timeout. Timeout is in seconds and none are zero. - If timeout is set as 0, then there will not be any timeout. - scanTo can be used for all GAP timeouts related to Central operation. - */ - uint16_t scanTo; - - /** Filter Duplicate Advertisement. The Filter Duplicates parameter controls whether - the Link Layer shall filter duplicate advertising reports to the Host, or whether the - Link Layer should generate advertising reports for each packet received. - - CY_BLE_GAPC_FILTER_DUP_DISABLE (Duplicate filtering disabled) - - CY_BLE_GAPC_FILTER_DUP_ENABLE (Duplicate filtering enabled) - - By default, duplicate filtering is enabled - */ - uint8_t filterDuplicates; - -} cy_stc_ble_gapc_disc_info_t; - -/** Connection parameter */ -typedef struct -{ - /** The time interval from when last LE scan is started until next - subsequent LE scan. - - Time Range: 2.5 ms to 10.24 sec. - */ - uint16_t scanIntv; - - /** The time duration of scanning to be performed - - Time Range: 2.5 ms to 10.24 sec - */ - uint16_t scanWindow; - - /** Filter policies to be applied during connection procedure - - CY_BLE_GAPC_CONN_ALL (Whitelist is not used to determine with - which advertiser to connect. Peer address is used) - - CY_BLE_GAPC_CONN_WHITELIST (Whitelist is used to determine with - which advertiser to connect. Peer address shall be ignored) - */ - uint8_t initiatorFilterPolicy; - - /** Peer's bd address with whom connection to be established */ - uint8_t peerBdAddr[CY_BLE_GAP_BD_ADDR_SIZE]; - - /** Peer's bd address type - - CY_BLE_GAP_ADDR_TYPE_PUBLIC - - CY_BLE_GAP_ADDR_TYPE_RANDOM - - CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA - - CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA - */ - uint8_t peerAddrType; - - /** Own bd address type - - CY_BLE_GAP_ADDR_TYPE_PUBLIC - - CY_BLE_GAP_ADDR_TYPE_RANDOM - - CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA - - CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA - */ - uint8_t ownAddrType; - - /** Minimum value for the connection event interval. This shall be less than - or equal to conn_Interval_Max. Minimum connection interval will be - connIntvMin * 1.25 ms - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntvMin; - - /** Maximum value for the connection event interval. This shall be greater - than or equal to conn_Interval_Min. Maximum connection interval will be - connIntvMax * 1.25 ms - * Time Range: 7.5 ms to 4 sec - */ - uint16_t connIntvMax; - - /** Slave latency for the connection in number of connection events. - * Range: 0x0000 to 0x01F3 - */ - uint16_t connLatency; - - /** Supervision timeout for the LE Link. Supervision timeout will be - supervisionTO * 10 ms - * Time Range: 100 msec to 32 secs - */ - uint16_t supervisionTO; - - /** Minimum length of connection needed for this LE connection. - * Range: 0x0000 - 0xFFFF - */ - uint16_t minCeLength; - - /** Maximum length of connection needed for this LE connection. - * Range: 0x0000 - 0xFFFF - */ - uint16_t maxCeLength; - -}cy_stc_ble_gapc_conn_info_t; - -/** Resolve peer device parameter */ -typedef struct -{ - /** Peer Bluetooth device address */ - uint8_t * bdAddr; - - /** Peer IRK */ - uint8_t peerIrk[CY_BLE_GAP_SMP_IRK_SIZE]; - -}cy_stc_ble_gapc_resolve_peer_info_t; - -/** Set peer BD Address parameter */ -typedef struct -{ - /** Peer Bluetooth device address */ - cy_stc_ble_gap_bd_addr_t remoteAddr; - - /** Peer bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_gapc_peer_bd_addr_info_t; - - -/* --------------------------Structure corresponding to events-------------------- */ - -/** Advertisement report parameter */ -typedef struct -{ - /** Advertisement event type - - Connectable undirected advertising = 0x00 - - Connectable directed advertising = 0x01 - - Scannable undirected advertising = 0x02 - - Non connectable undirected advertising = 0x03 - - Scan Response = 0x04 - */ - cy_en_ble_gapc_adv_event_t eventType; - - /** bd address type of the device advertising. - - CY_BLE_GAP_ADDR_TYPE_PUBLIC - - CY_BLE_GAP_ADDR_TYPE_RANDOM - - CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA - - CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA - */ - uint8_t peerAddrType; - - /** Public Device Address or Random Device Address for - each device that responded to scanning. */ - uint8_t* peerBdAddr; - - /** length of the data for each device that responded to scanning */ - uint8_t dataLen; - - /** Pointer to advertising or scan response data */ - uint8_t* data; - - /** Rssi of the responding device. - * Range: -85 <= N <= 0 - * Units: dBm */ - int8_t rssi; - -} cy_stc_ble_gapc_adv_report_param_t; - -/** Direct Advertising Report received by GAP Central */ -typedef struct -{ - /** Buffer containing Random Device Address of Scanner (local device) - * This is the address to which the directed advertisements are - * being directed. - */ - uint8_t * localBdAddr; - - /** Buffer containing Device Address of advertiser sending the directed advertisement */ - uint8_t * peerBdAddr; - - /** Device Address type of advertiser sending the directed advertisement */ - cy_en_ble_gap_adv_addr_type_t peerBdAddrType; - - - /** Rssi of the responding device. - * Range: -127 <= N <= +20 - * Units: dBm - * N = 127 -> RSSI not available - */ - int8_t rssi; - -} cy_stc_ble_gapc_direct_adv_report_param_t; -/** @} */ - - - -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_gap_central_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_StartDiscovery -***************************************************************************//** -* -* This function starts the discovery of devices that are advertising. This is a -* non-blocking function. As soon as the discovery operation starts, the -* CY_BLE_EVT_GAPC_SCAN_START_STOP event is generated. -* -* Every Advertisement / Scan response packet received results in a new event, -* CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT. If 'scanInfo->scanTo' is a non-zero value, -* upon commencement of discovery procedure and elapsed time = 'scanInfo->scanTo', -* CY_BLE_EVT_TIMEOUT event is generated with the event parameter indicating -* CY_BLE_GAP_SCAN_TO. -* -* If 'param->scanTo' is equal to zero, the scanning operation is performed -* until the Cy_BLE_GAPC_StopDiscovery() function is invoked. -* -* If 'param->scanFilterPolicy' is set to 0x02 or 0x03, CY_BLE_EVT_GAPC_DIRECT_ADV_REPORT event -* is received to indicate that directed advertisements have been received where -* the advertiser is using a resolvable private address. -* -* There are three discovery procedures that can be specified as a parameter to -* this function. -* -* __Observation procedure__ - -* A device performing the observer role receives only advertisement data from -* devices irrespective of their discoverable mode settings. Advertisement data -* received is provided by the event, -* -* CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT -* -* 'param->scanType' should be set as passive scanning (0x00). -* -* __Limited Discovery procedure__ - -* A device performing the limited discovery procedure receives advertisement -* data and scan response data from devices in the limited discoverable mode only. -* Received data is provided by the event, -* -* CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT -* -* 'param->scanType' should be set as active scanning (0x01). -* -* __General Discovery procedure__ - -* A device performing the general discovery procedure receives the advertisement -* data and scan response data from devices in both limited discoverable mode and -* general discoverable mode. Received data is provided by the event, -* -* CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT -* -* 'param->scanType' should be set as active scanning (0x01). -* -* \param param: Pointer to a variable of type cy_stc_ble_gapc_disc_info_t -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'param' or if any element within 'param' has an invalid value. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_StartDiscovery -( - cy_stc_ble_gapc_disc_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_StopDiscovery -***************************************************************************//** -* -* This function stops the discovery of devices. This is a non-blocking function. -* On stopping discovery operation, the CY_BLE_EVT_GAPC_SCAN_START_STOP event is -* generated. Application layer must keep track of the function call made -* before receiving this event to associate this event with either the start or -* stop discovery function. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_StopDiscovery -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_InitConnection -***************************************************************************//** -* This function instructs the BLE Stack to initiate a connection request to the -* remote device with required connection parameters. The connection request from -* the application is acknowledged by the BLE Controller as -* 'CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE' or 'CY_BLE_EVT_GAP_DEVICE_CONNECTED' -* depending on whether Link Layer Privacy is enabled or not in the component customizer. That -* means, a request is correct, permitted, and all parameters that are part of the -* request are correct. If the parameter validation or request is not permitted, -* then the BLE controller throws the 'CY_BLE_EVT_GAP_DEVICE_CONNECTED' event with error code in the status, -* instead of CY_BLE_EVT_GAP_DEVICE_CONNECTED/CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE. -* For a positive condition, the controller can issue a connect request to a peer. If it fails to establish -* connection, 'CY_BLE_EVT_GAP_DEVICE_DISCONNECTED' is passed to application. -* Once connection is established, CY_BLE_EVT_GAP_CONN_ESTB will be sent to the application -* if the application has set the CY_BLE_CONN_ESTB_EVENT_MASK event mask using Cy_BLE_SetCustomEventMask(). -* The stack supports creating only one master connection at a time. -* -* This API should not be called until the previous call to the API has resulted in a connection -* completion as indicated by the event CY_BLE_EVT_GAP_DEVICE_CONNECTED/ -* CY_BLE_EVT_GAP_DEVICE_CONNECTEDCY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE Or -* Cy_BLE_GAPC_CancelConnection() is not yet completed, which is informed through -* event 'CY_BLE_EVT_GAP_CREATE_CONN_CANCEL_COMPLETE' -* -* The CY_BLE_EVT_GATT_CONNECT_IND event is generated at the GAP Peripheral end after connection is -* completed with a peer Central device. For a GAP Central device, this event is generated as an -* acknowledgment of receiving this event successfully by the BLE Controller. -* -* This is a non-blocking function. This function must be called after -* successfully stopping scanning. Scanning is successfully stopped on invoking -* the Cy_BLE_GAPC_StopDiscovery() function and receiving the event -* CY_BLE_EVT_GAPC_SCAN_START_STOP with the event data of '0x01', -* indicating success. -* -* For details related to connection modes and procedures, refer to Bluetooth -* 4.1 Core Specification, Volume 3, Part C, Section 9.3. -* -* \param param: Structure of type 'cy_stc_ble_gapc_conn_info_t' that contains the -* connection parameters.\n -* Note Any parameter of structure type cy_stc_ble_gapc_conn_info_t, -* if not required by a specific Bluetooth Low Energy profile, may -* be ignored. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'param' or if any element within 'param' has an invalid value. -* CY_BLE_ERROR_INVALID_OPERATION | Operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -* Note: In multi connection use case, the recommended minimum connection interval per connection should be -* greater than N * Max Time taken by individual connections to complete a BLE Connection Event (CE). -* Min_CI = N * Average Time Per CE. -* Average time for each CE is the amount of time taken to complete one BLE Tx and Rx transaction. This -* time varies depending on Link Layer Data Length Extension (DLE) and BLE data rate (1 Mbps or 2 Mbps) -* configuration. The application can use the below timing lookup table for CE value: -* 1. If DLE is enabled and data rate is 1 Mbps, Average time = 6 ms -* 2. If DLE is enabled and data rate is 2 Mbps, Average time = 3.5 ms -* 3. If DLE is disabled and data rate is 1 Mbps, Average time = 2 ms -* 4. If DLE is disabled and data rate is 2 Mbps, Average time = 1.6 ms -* For example, if application supports 4 BLE connections with DLE and 1 Mbps data rate, then the recommended -* minimum connection interval for each of the connections is 4 * 6 = 24 ms. -* Note that connection intervals less than this value will still work, but under certain circumstances, the -* real time control procedures (connection update, channel map update, etc.) with shorter update instances might -* result in link disconnection. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_InitConnection -( - cy_stc_ble_gapc_conn_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_CancelConnection -***************************************************************************//** -* -* Description: -* This function cancels a previously initiated connection with the peer device. -* Operation complete of this API is informed through event 'CY_BLE_EVT_GAP_CREATE_CONN_CANCEL_COMPLETE' -* -* If the devices are already connected, then this function should not be used. -* To disconnect from an existing connection, use the function -* Cy_BLE_GAP_Disconnect(). -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | Operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_CancelConnection -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_ResolveDevice -***************************************************************************//** -* -* This function enables the application to start a resolution procedure for a -* device that is connected using a resolvable private address. This is a non-blocking function. -* The application should use this function when in GAP Central mode. -* -* Refer to Bluetooth 4.1 Core specification, Volume 3, Part C, section 10.8.2.3 -* Resolvable Private Address Resolution Procedure to understand the usage of -* Private addresses. -* Request complete is informed through 'CY_BLE_EVT_GAP_RESOLVE_DEVICE_COMPLETE' -* -* \param param: Parameter is of type cy_stc_ble_gapc_resolve_peer_info_t -* param->bdAddr: Peer Bluetooth device address of length 6 bytes, not -* NULL terminated. -* param->peerIrk: 128-bit IRK to be used for resolving the peer's private -* resolvable address. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter for 'param' or 'bdAddr'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -* Note1: param should point to valid memory location until completion of API -* is indicated via CY_BLE_EVT_GAP_RESOLVE_DEVICE_COMPLETE event. -* Note2: If using whitelist filtering, update the whitelist -* with the new address using Cy_BLE_AddDeviceToWhiteList API. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_ResolveDevice -( - cy_stc_ble_gapc_resolve_peer_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_SetRemoteAddr -***************************************************************************//** -* -* This function allows the application to set the new address of remote device identified by bdHandle. -* This API should be used when: -* 1. A peer device is previously bonded with a public address and changes its bd address to a resolvable private address. -* The application should resolve the device by calling the 'Cy_BLE_GAPC_ResolveDevice()' API and setting the -* new address if successfully resolved. -* 2. A device is previously bonded with a random, the application should call this API to set the new address(public/random). -* -* \param param: Parameter of type 'cy_stc_ble_gapc_peer_bd_addr_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On invalid bdHandle. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_SetRemoteAddr -( - cy_stc_ble_gapc_peer_bd_addr_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPC_ConnectionParamUpdateRequest -***************************************************************************//** -* -* This function sends the connection parameter update command to a local controller. -* This function can be used only from a device connected in the GAP Central role. -* \note: The connection parameter update procedure, defined as part of Bluetooth spec 4.1, is not supported. -* This function will allow the GAP Central application to update the connection parameter for a local controller -* and the local controller will follow the procedure as defined in Bluetooth Core specification 4.0. -* Request complete is informed through 'CY_BLE_EVT_GAP_CONNECTION_UPDATE_COMPLETE' -* -* \param param: Parameter is of type 'cy_stc_ble_gap_conn_update_param_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exist for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPC_ConnectionParamUpdateRequest -( - cy_stc_ble_gap_conn_update_param_info_t * param -); - -/** @} */ - -#endif /* CY_BLE_STACK_GAP_CENTRAL_H_ */ - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap_peripheral.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap_peripheral.h deleted file mode 100644 index fd2cdb2abb..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gap_peripheral.h +++ /dev/null @@ -1,391 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_gap_peripheral.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of Generic Access Profile. -* Also specified the defines, constants, and data structures required for the APIs. -* -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ -#ifndef CY_BLE_STACK_GAP_PERIPHERAL_H_ -#define CY_BLE_STACK_GAP_PERIPHERAL_H_ - - -/*************************************** -* Common stack includes -***************************************/ -#include "cy_ble_stack_gap.h" - -/*************************************** -** GAP Constants -***************************************/ -/** Broadcaster and discoverable mode */ -#define CY_BLE_GAPP_NONE_DISC_BROADCAST_MODE 0x00u /**< Non discoverable, broadcast mode */ -#define CY_BLE_GAPP_LTD_DISC_MODE 0x01u /**< Limited discoverable mode */ -#define CY_BLE_GAPP_GEN_DISC_MODE 0x02u /**< General discoverable mode */ - -/** Limited Discoverable mode timeout max. */ -#define CY_BLE_GAPP_LTD_DISC_MODE_TIME_MAX 180u - -/** Advertising filter policy*/ -#define CY_BLE_GAPP_SCAN_ANY_CONN_ANY 0x00u /**< scan and connect any device */ -#define CY_BLE_GAPP_SCAN_WHITELIST_CONN_ANY 0x01u /**< scan only whitelist and connect any device */ -#define CY_BLE_GAPP_SCAN_ANY_CONN_WHITELIST 0x02u /**< scan any, connect only from whitelist */ -#define CY_BLE_GAPP_SCAN_CONN_WHITELIST_ONLY 0x03u /**< scan and connect only from whitelist */ - -/** - \addtogroup group_ble_common_api_gap_definitions - @{ -*/ - -/*************************************** -** Enumerated Types -***************************************/ - -/** Advertisement type */ -typedef enum -{ - /** Connectable undirected advertising */ - CY_BLE_GAPP_CONNECTABLE_UNDIRECTED_ADV = 0x00u, - - /** Connectable high duty cycle directed advertising */ - CY_BLE_GAPP_CONNECTABLE_HIGH_DC_DIRECTED_ADV, - - /** Scannable undirected advertising */ - CY_BLE_GAPP_SCANNABLE_UNDIRECTED_ADV, - - /** Non connectable undirected advertising */ - CY_BLE_GAPP_NON_CONNECTABLE_UNDIRECTED_ADV, - - /** Connectable low duty cycle directed advertising */ - CY_BLE_GAPP_CONNECTABLE_LOW_DC_DIRECTED_ADV - -}cy_en_ble_gapp_adv_t; - - -/*************************************** -** Exported structures and unions -***************************************/ - -/** Advertising parameters */ -typedef struct -{ - /** Minimum advertising interval for undirected - and low duty cycle directed advertising - - Time Range: 20 ms to 10.24 sec - */ - uint16_t advIntvMin; - - /** Maximum advertising interval for undirected - and low duty cycle directed advertising. - - Time Range: 20 ms to 10.24 sec - */ - uint16_t advIntvMax; - - /** Type of advertisement - - Connectable undirected advertising (0x00) - - Connectable high duty cycle directed advertising (0x01) - - Scannable undirected advertising (0x02) - - Non connectable undirected advertising (0x03) - - Connectable low duty cycle directed advertising (0x04) - */ - cy_en_ble_gapp_adv_t advType; - - /** Own BD Address Type - - CY_BLE_GAP_ADDR_TYPE_PUBLIC - - CY_BLE_GAP_ADDR_TYPE_RANDOM - - CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA - - CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA - */ - uint8_t ownAddrType; - - /** Address type of the Bluetooth device address being used for - directed advertising, not applicable otherwise - - CY_BLE_GAP_ADDR_TYPE_PUBLIC (Public device address) - - CY_BLE_GAP_ADDR_TYPE_RANDOM (Random device address) - */ - uint8_t directAddrType; - - /** This parameter specifies Bluetooth device address of the - device to be connected while using directed advertising. - In case of none direct advertising, parameter will be 0 - */ - uint8_t directAddr[CY_BLE_GAP_BD_ADDR_SIZE]; - - /** Advertising channels that shall be used when transmitting advertising packets. - Channel map selection: - - Enable channel 37 = bitmask. xxxxxxx1b - - Enable channel 38 = bitmask. xxxxxx1xb - - Enable channel 39 = bitmask. xxxxx1xxb - */ - uint8_t advChannelMap; - - /** Advertising Filter Policy - - CY_BLE_GAPP_SCAN_ANY_CONN_ANY (Allow Scan Request from Any, Allow Connect Request - from Any (Default)) - - CY_BLE_GAPP_SCAN_WHITELIST_CONN_ANY (Allow Scan Request from White List Only, - Allow Connect Request) - - CY_BLE_GAPP_SCAN_ANY_CONN_WHITELIST (Allow Scan Request from Any, Allow Connect - Request from White List Only) - - CY_BLE_GAPP_SCAN_CONN_WHITELIST_ONLY (Allow Scan Request from White List Only, - Allow Connect Request from White List Only) - */ - uint8_t advFilterPolicy; - -}cy_stc_ble_gapp_disc_param_t; - -/** Advertising data */ -typedef struct -{ - /**GAP Advertisement Parameters which includes Flags, Service UUIDs and short name*/ - uint8_t advData[CY_BLE_GAP_MAX_ADV_DATA_LEN]; - - /**length of the advertising data. This should be made zero if there is no data */ - uint8_t advDataLen; - -} cy_stc_ble_gapp_disc_data_t; - -/** Scan response data */ -typedef struct -{ - /** Static user data transmitted in scan response. This should be made NULL if - there is no data. Maximum length of the data is equal to 31 bytes */ - uint8_t scanRspData[CY_BLE_GAP_MAX_SCAN_RSP_DATA_LEN]; - - /** Length of the scan response data. This should be made zero if there is no data */ - uint8_t scanRspDataLen; - -} cy_stc_ble_gapp_scan_rsp_data_t; - -/** Advertising information */ -typedef struct -{ - /** Broadcaster and discoverable mode - - CY_BLE_GAPP_NONE_DISC_BROADCAST_MODE - (Applicable for Broadcaster or non-discoverable mode) - - CY_BLE_GAPP_LTD_DISC_MODE (Limited discovery mode) - - CY_BLE_GAPP_GEN_DISC_MODE (General discovery mode) - */ - uint8_t discMode; - - /** Advertisement parameters are not allowed to be modified if ADV is already active - This needs to be NULL, if ADV is active. - */ - cy_stc_ble_gapp_disc_param_t * advParam; - /** Advertisement data */ - cy_stc_ble_gapp_disc_data_t * advData; - /** Scan Response data */ - cy_stc_ble_gapp_scan_rsp_data_t * scanRspData; - - /** Advertisement timeout is in seconds. If timeout is set to 0, - then there will not be any timeout. The parameter 'advTo' can - be used for all GAP timeouts related to peripheral operation. - For General discoverable mode, this timer will be ignored. - The application is expected to exit from discoverable mode - explicitly by calling the Cy_BLE_GAPP_ExitDiscoveryMode() function. - For Limited discoverable mode, 'advTo' should not exceed 180 sec. - */ - uint16_t advTo; - -} cy_stc_ble_gapp_disc_mode_info_t; -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_gap_peripheral_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GAPP_EnterDiscoveryMode -***************************************************************************//** -* -* This function sets the device into discoverable mode. In the discoverable -* mode, based on the parameters passed to this function, the BLE Device starts -* advertisements and can respond to scan requests. This is a non-blocking -* function. It is to be used by the device in the GAP Peripheral mode of operation -* to set parameters essential for starting advertisement procedure. -* -* Note that this API is not allowed if advertisement is already active. -* -* On start of advertisement, the GAP Peripheral receives -* CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP event. The following events can -* occur on invoking this function. -* -* * CY_BLE_EVT_GAP_DEVICE_CONNECTED - If the device connects to a GAP Central and -* Link Layer Privacy is disabled in component customizer. -* * CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE - If the device connects to a GAP Central and -* Link Layer Privacy is enabled in component customizer. -* -* * CY_BLE_EVT_TIMEOUT - If no device in the GAP Central mode connects to this -* device within the specified timeout limit. This event can occur if -* 'param ->discMode' is equal to CY_BLE_GAPP_LTD_DISC_MODE or -* CY_BLE_GAPP_GEN_DISC_MODE. 'param-> advTo' specifies the timeout duration. -* Set the 'param-> advTo' to 0 when 'param -> discMode' is set to -* CY_BLE_GAPP_GEN_DISC_MODE so that the timeout event does not occur and the -* advertisement continues until the Cy_BLE_GAPP_ExitDiscoveryMode() function -* is invoked. If 'param -> discMode' is set to CY_BLE_GAPP_GEN_DISC_MODE, then -* 'param-> advTo' is ignored. -* -* \param param: Structure of type cy_stc_ble_gapp_disc_mode_info_t, which contains the -* advertisement parameters -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for 'param' or if any of the elements of this structure are invalid. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPP_EnterDiscoveryMode -( - cy_stc_ble_gapp_disc_mode_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GAPP_UpdateAdvScanData -***************************************************************************//** -* -* This function sets Advertisement or/and Scan Response data. -* This API can be used during active ADV operation as well. It is expected that the -* application layer ensures the validity of adv data content as per the -* adv parameters being used to while starting the Advertisement. -* -* On completion of this operation, GAP Peripheral receives -* CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE event. -* -* \param param: Structure of type cy_stc_ble_gapp_disc_mode_info_t, - Only cy_stc_ble_gapp_disc_mode_info_t.advData and - cy_stc_ble_gapp_disc_mode_info_t.scanRspData fields will be used. - Other fields in the structure will be ignored and will not be used. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for 'param' or if any of the elements of this structure are invalid. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPP_UpdateAdvScanData -( - cy_stc_ble_gapp_disc_mode_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPP_ExitDiscoveryMode -***************************************************************************//** -* -* This function is used to exit from discoverable mode. This is a non-blocking -* function. After the execution of this function, the device stops advertising. -* -* On stopping advertising, GAP Peripheral receives -* CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP event. It is expected that the -* application layer keeps track of the function call performed before occurrence -* of this event, as this event can occur on making a call to the -* Cy_BLE_GAPP_EnterDiscoveryMode () function as well. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPP_ExitDiscoveryMode -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GAPP_AuthReqReply -***************************************************************************//** -* -* This function is used to pass security information for authentication in reply -* to an authentication request from the master device. It should be invoked on -* receiving the CY_BLE_EVT_GAP_AUTH_REQ event. Events shown in the following table -* may be received by the application based on the authentication result. -* -* Event Name | Description -* ------------ | ----------- -* CY_BLE_EVT_GAP_AUTH_COMPLETE | Pointer to structure of type 'cy_stc_ble_gap_auth_info_t' is returned as parameter to both the peer devices on successful authentication. -* CY_BLE_EVT_GAP_AUTH_FAILED | Received by both GAP Central and Peripheral devices (peers) on authentication failure. Data is of type 'cy_en_ble_gap_auth_failed_reason_t'. -* -* -* Following events may occur if API result is CY_BLE_SUCCESS: -* -* Event Name | Description -* ------------ | ----------- -* CY_BLE_EVT_GAP_SMP_NEGOTIATED_AUTH_INFO| SMP has completed pairing properties (feature exchange) negotiation. -* CY_BLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT | SMP keys exchange with peer device is completed. -* CY_BLE_EVT_GAP_ENCRYPT_CHANGE | When there is a change in encryption after pairing procedure. -* -* Based on IO capabilities, security modes following events may occur -* during pairing procedure. -* Please refer Core spec 4.2 volume 3 part - H section 2.3.5.1 -* to know more about Selecting Key Generation Method. -* -* | Event Name | -* | ------------------------ | -* | CY_BLE_EVT_GAP_PASSKEY_DISPLAY_REQUEST | -* | CY_BLE_EVT_GAP_KEYPRESS_NOTIFICATION | -* | CY_BLE_EVT_GAP_NUMERIC_COMPARISON_REQUEST | -* -* \param param: Pointer to a variable containing security information of the -* device of type cy_stc_ble_gap_auth_info_t. Param->security can take -* the value from enum cy_en_ble_gap_sec_level_t. -* -* NOTE: If the bonding flag in param is set to CY_BLE_GAP_BONDING_NONE then, -* SMP keys will not be distributed even if application has generated -* and set the keys explicitly. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for 'param' or if any of the elements of this structure are invalid. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified using 'bdHandle' does not exist. -* CY_BLE_ERROR_INVALID_OPERATION | Operation is not permitted. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | On bonded device is full and application tries to initiate pairing with bonding enable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GAPP_AuthReqReply -( - cy_stc_ble_gap_auth_info_t * param -); - -/** @} */ - -#endif /* CY_BLE_STACK_GAP_PERIPHERAL_H_ */ - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt.h deleted file mode 100644 index fd0ee9863e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt.h +++ /dev/null @@ -1,585 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_gatt.h -* \version 2.0 -* -* \brief -* This file contains declarations of generic public BLE APIs of Generic Attribute Profile. -* Also specified the defines, constants, and data structures required for the APIs. -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ -#ifndef CY_BLE_STACK_GATT_H_ -#define CY_BLE_STACK_GATT_H_ - - -/*************************************** -* Common stack includes -***************************************/ - -#include "cy_ble_stack_host_main.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -** GATT Constants -***************************************/ - -/** ATT 16-bit UUID Size */ -#define CY_BLE_GATT_16_BIT_UUID_SIZE 0x02u - -/** GATT 128-bit UUID Size */ -#define CY_BLE_GATT_128_BIT_UUID_SIZE 0x10u - -/** GATT Identification for 16-bit UUID Format */ -#define CY_BLE_GATT_16_BIT_UUID_FORMAT 0x01u - -/** GATT Identification for 128-bit UUID Format */ -#define CY_BLE_GATT_128_BIT_UUID_FORMAT 0x02u - -/** GATT MTU Size */ -#define CY_BLE_GATT_DEFAULT_MTU 0x17u /**< Default MTU size */ -#define CY_BLE_GATT_MAX_MTU 0x200u /**< MAX MTU size */ - -/** ATT Execute Write Cancel Flag */ -#define CY_BLE_GATT_EXECUTE_WRITE_CANCEL_FLAG 0x00u - -/** ATT Execute Write Execute Flag */ -#define CY_BLE_GATT_EXECUTE_WRITE_EXEC_FLAG 0x01u - -/** ATT Invalid Attribute Handle Value */ -#define CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE 0x0000u - -/** ATT Attribute Handle Start Range */ -#define CY_BLE_GATT_ATTR_HANDLE_START_RANGE 0x0001u - -/** ATT Attribute Handle End Range */ -#define CY_BLE_GATT_ATTR_HANDLE_END_RANGE 0xFFFFu - -/** - \addtogroup group_ble_common_api_gatt_definitions - @{ -*/ - -/*************************************** -** Enumerated Types -***************************************/ - -/** Opcode that has resulted in the error */ -typedef enum -{ - /** Error Response PDU */ - CY_BLE_GATT_ERROR_RSP = 0x01u, - - /** Exchange GATT MTU Request PDU */ - CY_BLE_GATT_XCNHG_MTU_REQ, - - /** Exchange GATT MTU Response PDU */ - CY_BLE_GATT_XCHNG_MTU_RSP, - - /** Find Information Request PDU */ - CY_BLE_GATT_FIND_INFO_REQ, - - /** Find Information Response PDU */ - CY_BLE_GATT_FIND_INFO_RSP, - - /** Find By Type Value Request PDU */ - CY_BLE_GATT_FIND_BY_TYPE_VALUE_REQ, - - /** Find By Type Value Response PDU */ - CY_BLE_GATT_FIND_BY_TYPE_VALUE_RSP, - - /** Read By Type Request PDU */ - CY_BLE_GATT_READ_BY_TYPE_REQ, - - /** Read By Type Response PDU */ - CY_BLE_GATT_READ_BY_TYPE_RSP, - - /** Read Request PDU */ - CY_BLE_GATT_READ_REQ, - - /** Read Response PDU */ - CY_BLE_GATT_READ_RSP, - - /** Read Blob Request PDU */ - CY_BLE_GATT_READ_BLOB_REQ, - - /** Read Blob Response PDU */ - CY_BLE_GATT_READ_BLOB_RSP, - - /** Read Multiple Request PDU */ - CY_BLE_GATT_READ_MULTIPLE_REQ, - - /** Read Multiple Response PDU */ - CY_BLE_GATT_READ_MULTIPLE_RSP, - - /** Read Group Type Request PDU */ - CY_BLE_GATT_READ_BY_GROUP_REQ, - - /** Read Group Type Response PDU */ - CY_BLE_GATT_READ_BY_GROUP_RSP, - - /** Write Request PDU */ - CY_BLE_GATT_WRITE_REQ, - - /** Write Response PDU */ - CY_BLE_GATT_WRITE_RSP, - - /** Write Command PDU */ - CY_BLE_GATT_WRITE_CMD = 0x52u, - - /** Prepare Write Request PDU */ - CY_BLE_GATT_PREPARE_WRITE_REQ = 0x16u, - - /** Prepare Write Response PDU */ - CY_BLE_GATT_PREPARE_WRITE_RSP, - - /** Execute Write Request PDU */ - CY_BLE_GATT_EXECUTE_WRITE_REQ, - - /** Execute Write Response PDU */ - CY_BLE_GATT_EXECUTE_WRITE_RSP, - - /** Handle Value Notification PDU */ - CY_BLE_GATT_HANDLE_VALUE_NTF = 0x1Bu, - - /** Handle Value Indication PDU */ - CY_BLE_GATT_HANDLE_VALUE_IND = 0x1Du, - - /** Handle Value Confirmation PDU */ - CY_BLE_GATT_HANDLE_VALUE_CNF = 0x1Eu, - - /**Signed Write Command PDU */ - CY_BLE_GATT_SIGNED_WRITE_CMD = 0xD2u, - - /** Unknown or Unhandled PDU */ - CY_BLE_GATT_UNKNOWN_PDU_IND = 0xFFu - -}cy_en_ble_gatt_pdu_t; - -/** GATT error codes */ -typedef enum -{ - /** No Error */ - CY_BLE_GATT_ERR_NONE, - - /** Invalid Handle error code is used when the ATT handle in the - ATT request PDU is invalid. */ - CY_BLE_GATT_ERR_INVALID_HANDLE = 0x0001u, - - /** Read Not Permitted error code is used when the permission to - read the value of an ATT handle is not permitted on the ATT server. */ - CY_BLE_GATT_ERR_READ_NOT_PERMITTED, - - /** Write Not Permitted error code is used when the permission to - write the value of an ATT handle is not permitted on the ATT server. */ - CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED, - - /** Invalid PDU error code is used when the format of the PDU sent - from the ATT Client is incorrect. */ - CY_BLE_GATT_ERR_INVALID_PDU, - - /** Insufficient Authentication error code is used when - an access to a handle is attempted on a un-authenticated link but the - attribute requires that the link be authenticated before a client can access it. */ - CY_BLE_GATT_ERR_INSUFFICIENT_AUTHENTICATION, - - /** Request not supported error code is used when - the server does not support the processing of an ATT request sent from the client. */ - CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED, - - /** Invalid Offset error code is used when - the offset sent by the client in the Read blob/Prepare Write Request is - invalid with respect to the length of the value in the server. */ - CY_BLE_GATT_ERR_INVALID_OFFSET, - - /** Insufficient Authorization error code is used when - the ATT server does not authorize the client and hence prohibits the - client from reading the handle value. */ - CY_BLE_GATT_ERR_INSUFFICIENT_AUTHORIZATION, - - /** Write queue full error code is used when there is no more space left in the - prepare write queue on the server to entertain any more prepare writes from a - client. */ - CY_BLE_GATT_ERR_PREPARE_WRITE_QUEUE_FULL, - - /** Attribute not found error is used when the ATT server cannot find any handle - that belongs to the Attribute type in the given range of handles that the - client specified in its request. This error code can be sent to the client in - response to the following request PDUs - Find Information, Find by Type Value, - Read by Type, and Read by Group Type requests. */ - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND, - - /** Attribute Not Long error code is used when the client tries to read or write - an attribute handle's value that cannot be read or written through Read Blob - or multiple prepare write requests. */ - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_LONG, - - /** Insufficient encryption key size error code is used when the client tries to - access an Attribute Handle's Value for which the link must be encrypted - with a key of certain minimum key size and the current link is encrypted - with a key of smaller size than the minimum required. */ - CY_BLE_GATT_ERR_INSUFFICIENT_ENC_KEY_SIZE, - - /** - Invalid Attribute length error code is used when the attribute value's - length is not correct to process the request containing the value. - */ - CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN, - - /** - Unlikely error is used when the processing of the attribute request has - encountered an error that is not covered by any other error code. - */ - CY_BLE_GATT_ERR_UNLIKELY_ERROR, - - /** Insufficient encryption error code is used when the client tries to read or - write an attribute handle that requires the link to be encrypted and the - link is currently not encrypted. */ - CY_BLE_GATT_ERR_INSUFFICIENT_ENCRYPTION, - - /** Unsupported Group Type error code is used when the attribute type requested - in the Read by Group Type request is not a valid grouping attribute on the - server. */ - CY_BLE_GATT_ERR_UNSUPPORTED_GROUP_TYPE, - - /** Insufficient Resources error code is used when the ATT server does not have - enough resources such as memory, etc., to process the request from the client. */ - CY_BLE_GATT_ERR_INSUFFICIENT_RESOURCE = 0x11u, - - /** Other Error Groups for ATT - GATT - * Reserved: GATT-ATT Error codes 0x12 to 0x7F are reserved for - * Application Specific Error Code Range: 0x80 to 0x9F - * Reserved: 0xA0 to 0xDF - * Common Profile & Service Error Code : 0xE0 to 0xFF - */ - - /** Heart Rate Control Point Not Supported error code is used when a unsupported - code is written into Heart Rate service Control Point characteristic. */ - CY_BLE_GATT_ERR_HEART_RATE_CONTROL_POINT_NOT_SUPPORTED = 0x80u, - - /** The user data access is not permitted (i.e., the user has not given - consent to access the data). */ - CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED = 0x80u, - - /** The notifications of the Cycling Power Vector characteristic cannot be sent - due to inappropriate connection parameters. */ - CY_BLE_GATT_ERR_CPS_INAPPROPRIATE_CONNECTION_PARAMETERS = 0x80u, - - /** The value is considered invalid and outside of the range allowed by - the characteristic. */ - CY_BLE_GATT_ERR_HTS_OUT_OF_RANGE = 0x80u, - - /** Procedure Already in Progress error code is used when a profile or service - request cannot be serviced because an operation that has been previously - triggered is still in progress. */ - CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS = 0x80u, - - /** The Op Code Not Supported error code is used when an unsupported - Op Code is written into the Control Point characteristic. */ - CY_BLE_GATT_ERR_OP_CODE_NOT_SUPPORTED = 0x80u, - - /** The Missing CRC error code is used when the CRC is missed in the - incoming characteristic value. */ - CY_BLE_GATT_ERR_MISSING_CRC = 0x80u, - - /** Client Characteristic Configuration Descriptor Improperly Configured error - code is used when a Client Characteristic Configuration descriptor is not - configured according to the requirements of the profile or service. */ - CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED = 0x81u, - - /** The Operation Failed error code is used when the device is unable to - complete a procedure for any reason. */ - CY_BLE_GATTS_ERR_OPERATION_FAILED = 0x81u, - - /** The Invalid CRC error code is used when the CRC is invalid in the - incoming characteristic value. */ - CY_BLE_GATT_ERR_INVALID_CRC = 0x81u, - - /** An HTTP Control Point request cannot be serviced because content of the URI, - the HTTP Headers, or the HTTP Entity Body characteristics are not set - correctly. */ - CY_BLE_GATTS_ERR_HPS_INVALID_REQUEST = 0x81u, - - /** Network connection not available. */ - CY_BLE_GATTS_ERR_NETWORK_NOT_AVAILABLE = 0x82u, - - /** Command Not Supported used by the Alert Notification Server when the Client - sends an incorrect value of the Command ID or Category ID of to the Alert - Notification Control Point Characteristic. */ - CY_BLE_GATT_ERR_ANS_COMMAND_NOT_SUPPORTED = 0xA0u, - - /** Unknown command error code used by the Apple Notification Center Server when the Client - sends unknown command value of the Apple Notification Center Service Control Point - Characteristic. */ - CY_BLE_GATT_ERR_ANCS_UNKNOWN_COMMAND = 0xA0u, - - /** Invalid command error code used by the Apple Notification Center Server when the Client - sends an invalid command value of the Apple Notification Center Service Control Point - Characteristic. */ - CY_BLE_GATT_ERR_ANCS_INVALID_COMMAND = 0xA1u, - - /** Invalid parameter error code used by the Apple Notification Center Server when the Client - sends an invalid parameter value of the Apple Notification Center Service Control Point - Characteristic. */ - CY_BLE_GATT_ERR_ANCS_INVALID_PARAMETER = 0xA2u, - - /** Action failed error code used by the Apple Notification Center Server when some - Apple Notification Center Service Control Point Characteristic command processing goes wrong. */ - CY_BLE_GATT_ERR_ANCS_ACTION_FAILED = 0xA3u, - - /** Client Characteristic Configuration Descriptor Improperly Configured error - code is used when a Client Characteristic Configuration descriptor is not - configured according to the requirements of the profile or service. */ - CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED = 0xFDu, - - /** The Procedure Already in Progress error code is used when a profile or service - request cannot be serviced because an operation that has been previously - triggered is still in progress. */ - CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS = 0xFEu, - - /** Out of Range error code is used when an attribute value is out of range as - defined by a profile or service specification. */ - CY_BLE_GATT_ERR_OUT_OF_RANGE = 0xFFu - -}cy_en_ble_gatt_err_code_t; - - -/*************************************** -** Exported data structures -***************************************/ - -/** GATT 16 Bit UUID */ -typedef uint16_t cy_ble_uuid16_t; - -/** GATT 128 Bit UUID type */ -typedef struct -{ - /** 128 Bit UUID */ - uint8_t value[CY_BLE_GATT_128_BIT_UUID_SIZE]; -}cy_stc_ble_uuid128_t; - - -/** GATT UUID type*/ -typedef union -{ - /** 16 Bit UUID */ - cy_ble_uuid16_t uuid16; - - /** 128 Bit UUID */ - cy_stc_ble_uuid128_t uuid128; - -}cy_ble_uuid_t; - -/** GATT BD Attribute Handle Type */ -typedef uint16_t cy_ble_gatt_db_attr_handle_t; - -/** Abstracts Variable Length Values for GATT. - - Apart from data and length, actual length is needed so that the GATT can - indicate to the application the actual length of data processed for a PDU. - - This is used in multiple commands - see CY_BLE_GATT_READ_RSP, - CY_BLE_GATT_FIND_BY_TYPE_VALUE_REQ, CY_BLE_GATT_READ_BLOB_RSP, etc. - - In GATT Read Response for example, if the attribute length is 30 octets - and the GATT MTU is 23 octets, then only first 22 octets can be sent by the GATT. - Therefore the actual length will be 22 (GATT MTU-1). - However, if the GATT MTU is configured to be 54 for example, all 30 octets - can be transmitted and the actual length will be 30. - - Actual length should be derived as - - actualLen = length>(GATT MTU-1) ? (GATT MTU-1):len - - In case multiple values are being packed, the actual length processed will - depend on the available GATT MTU. */ -typedef struct -{ - /** Pointer to the value to be packed */ - uint8_t * val; - - /** Length of the Value to be packed */ - uint16_t len; - - /** Out Parameter Indicating Actual Length Packed and sent over the air. Actual length - can be less than or equal to the 'len' parameter value. This provides the - actual length of data that is transmitted over the - air information. Each GATT procedure defines different lengths of data that can be transmitted - over the air. If the application sends more than that, all data may not transmit over the air.*/ - uint16_t actualLen; - -}cy_stc_ble_gatt_value_t; - -/** GATT handle - value pair type */ -typedef struct -{ - /** Attribute Value */ - cy_stc_ble_gatt_value_t value; - - /** Attribute Handle of GATT DB */ - cy_ble_gatt_db_attr_handle_t attrHandle; - -}cy_stc_ble_gatt_handle_value_pair_t; - -/** GATT Attribute Handle Range type */ -typedef struct -{ - /** Start Handle */ - cy_ble_gatt_db_attr_handle_t startHandle; - - /** End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; - -}cy_stc_ble_gatt_attr_handle_range_t; - -/** GATT MTU exchange parameter type */ -typedef struct -{ - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Client/Server Rx/Tx GATT MTU Size */ - uint16_t mtu; - -}cy_stc_ble_gatt_xchg_mtu_param_t; - -/** GATT Handle Value Pair along with offset type */ -typedef struct -{ - /** Attribute Handle & Value to be Written */ - cy_stc_ble_gatt_handle_value_pair_t handleValuePair; - - /** Offset at which Write is to be performed */ - uint16_t offset; - -}cy_stc_ble_gatt_handle_value_offset_param_t; - -/** Write parameter */ -typedef struct -{ - /** handle value pair */ - cy_stc_ble_gatt_handle_value_pair_t handleValPair; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gatt_write_param_t; - -/** Error information */ -typedef struct -{ - /** Attribute Handle in which error is generated */ - cy_ble_gatt_db_attr_handle_t attrHandle; - - /** Opcode which has resulted in Error */ - cy_en_ble_gatt_pdu_t opCode; - - /** Error Code describing cause of error */ - cy_en_ble_gatt_err_code_t errorCode; - -}cy_stc_ble_gatt_err_info_t; - -/** Error parameter*/ -typedef struct -{ - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Error information */ - cy_stc_ble_gatt_err_info_t errInfo; - -}cy_stc_ble_gatt_err_param_t; - -/** Prepare Write parameter */ -typedef struct -{ - /** handle value offset pair */ - cy_stc_ble_gatt_handle_value_offset_param_t handleValOffsetPair; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gatt_prep_write_param_t; - -/* --------------------------Structure corresponding to events-------------------- */ - -/** memory request parameters for prepare write request*/ -typedef struct -{ - /** buffer to which a prepared write queue request will be stored. The - buffer can be calculated as - total buffer = totalAttrValueLength - + prepareWriteQueueSize * sizeof (cy_stc_ble_gatt_handle_value_offset_param_t) */ - uint8_t * queueBuffer; - - /** length of attribute value. This value can be the max attribute value length - or summation of value lengths that support a long write. The value should be multiple of a - 32-bit unsigned integer. */ - uint16_t totalAttrValueLength; - - /** Size of prepareWriteQueue buffer. The application may decide the size based on - (totalAttrValueLength or the max attribute length or the summation of value - lengths that supports long write) /(negotiated or default MTU size - 5). - In case of a reliable write, queue depth should at least be equal to number of handles that have - reliable write support. */ - uint16_t prepareWriteQueueSize; - - /** Connection Handle */ - cy_stc_ble_conn_handle_t connHandle; - -} cy_stc_ble_prepare_write_request_memory_t; - -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_gatt_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GATT_GetMtuSize -***************************************************************************//** -* -* This function provides the correct GATT MTU used by BLE stack. If the function -* is called after the GATT MTU configuration procedure, it will provide the final -* negotiated GATT MTU else default MTU (23 Bytes). -* -* \param param: buffer of type 'cy_stc_ble_gatt_xchg_mtu_param_t'. -* param->connHandle: input parameter -* param->mtu: output parameter -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation -* CY_BLE_ERROR_INVALID_PARAMETER | If NULL or invalid connection handle was passed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATT_GetMtuSize -( - cy_stc_ble_gatt_xchg_mtu_param_t * param -); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/** @} */ - -#endif /* CY_BLE_STACK_GATT_H_ */ - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_client.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_client.h deleted file mode 100644 index 340105b42b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_client.h +++ /dev/null @@ -1,1567 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_gatt_client.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of Generic Attribute Profile - Client Role. -* Also specifies the defines, constants, and data structures required for the APIs. -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_STACK_GATT_CLIENT_H_ -#define CY_BLE_STACK_GATT_CLIENT_H_ - - -/*************************************** -* Common stack includes -***************************************/ - -#include "cy_ble_stack_gatt.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -** Exported data structures -***************************************/ -/** - \addtogroup group_ble_common_api_gatt_definitions - @{ -*/ - -/** Stop command parameter */ -typedef struct -{ - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_stop_cmd_param_t; - -/** GATT Discover primary service request parameter */ -typedef struct -{ - /** Handle Range */ - cy_stc_ble_gatt_attr_handle_range_t range; - - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_by_group_req_t; - -/** GATT Discover primary service by UUID request parameter */ -typedef struct -{ - /** Attribute Value to Find */ - cy_stc_ble_gatt_value_t value; - - /** Handle Range - Start and End Handle */ - cy_stc_ble_gatt_attr_handle_range_t range; - - /** 16-bit UUID to Find */ - cy_ble_uuid16_t uuid; - - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_find_by_type_value_req_t; - -/** GATT read by type request parameter */ -typedef struct -{ - /** Handle Range */ - cy_stc_ble_gatt_attr_handle_range_t range; - - /** GATT UUID type */ - cy_ble_uuid_t uuid; - - /** Format indicating, 16-bit or 128-bit UUIDs - * For 16-bit UUID format - CY_BLE_GATT_16_BIT_UUID_FORMAT (0x01) - * For 128-bit UUID format - CY_BLE_GATT_128_BIT_UUID_FORMAT (0x02) - */ - uint8_t uuidFormat; - - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_by_type_req_t; - -/** GATT find info request parameter */ -typedef cy_stc_ble_gattc_read_by_group_req_t cy_stc_ble_gattc_find_info_req_t; - -/** Read request parameter */ -typedef struct -{ - /** Handle on which Read Blob is requested */ - cy_ble_gatt_db_attr_handle_t attrHandle; - - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_req_t; - -/** Handle-offset pair parameter */ -typedef struct -{ - /** Handle on which Read Blob is requested */ - cy_ble_gatt_db_attr_handle_t attrHandle; - - /** Value Offset from which the Read is Requested */ - uint16_t offset; - -}cy_stc_ble_gattc_handle_offset_pair_t; - -/** Read blob request parameter */ -typedef struct -{ - /** Handle-offset pair parameter */ - cy_stc_ble_gattc_handle_offset_pair_t handleOffset; - - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_blob_req_t; - -/** GATT handle list type */ -typedef struct -{ - /** Handle list where the UUID with value Indicated is found */ - uint16_t * handleList; - - /** Number of Handles in the list */ - uint16_t listCount; - - /** Actual Number of Handles Packed. This is a output parameter */ - uint16_t actualCount; - -}cy_stc_ble_gattc_handle_list_t; - -/** Read multiple request parameter */ -typedef struct -{ - /** GATT handle list type */ - cy_stc_ble_gattc_handle_list_t handleListType; - - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_mult_req_t; - -/** Write request parameter */ -typedef cy_stc_ble_gatt_write_param_t cy_stc_ble_gattc_write_req_t; - -/** Prepare Write request parameter */ -typedef cy_stc_ble_gatt_prep_write_param_t cy_stc_ble_gattc_prep_write_req_t; - -/** Prepare Write request parameter for reliable write request */ -typedef struct -{ - /** handle value offset pair */ - cy_stc_ble_gatt_handle_value_offset_param_t * handleValOffsetPair; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Number of requests. That is, the count of array of structures - of type 'cy_stc_ble_gatt_handle_value_offset_param_t'. Each array element - represents a value and the attribute to which the value has - to be written */ - uint8_t numOfRequests; - -}cy_stc_ble_gattc_reliable_write_req_t; - -/** Execute Write request parameter */ -typedef struct -{ - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Indicates whether Queued Write is to be executed (0x01) or canceled (0x00) */ - uint8_t flag; - -}cy_stc_ble_gattc_exec_write_req_t; - -/** Write command request to be sent to Server */ -typedef cy_stc_ble_gattc_write_req_t cy_stc_ble_gattc_write_cmd_req_t; - -/** Signed Write command request to be sent to Server */ -typedef cy_stc_ble_gattc_write_req_t cy_stc_ble_gattc_signed_write_cmd_req_t; - -/** Signed Write command request to be sent to Server */ -typedef cy_stc_ble_gattc_stop_cmd_param_t cy_stc_ble_gattc_confirmation_req_t; - -/* --------------------------Structure corresponding to events-------------------- */ - -/** Read response parameter type received from server*/ -typedef struct -{ - /** Attribute Value */ - cy_stc_ble_gatt_value_t value; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_rsp_param_t; - -/** Handle value notification data received from server */ -typedef cy_stc_ble_gattc_write_req_t cy_stc_ble_gattc_handle_value_ntf_param_t; - -/** GATT handle value indication parameter received from server type */ -typedef cy_stc_ble_gattc_write_req_t cy_stc_ble_gattc_handle_value_ind_param_t; - -/** Data Element for Group Response */ -typedef struct -{ - /** attribute handle value pair */ - uint8_t * attrValue; - - /** Length of each Attribute Data Element including the Handle Range */ - uint16_t length; - - /** Total Length of Attribute Data */ - uint16_t attrLen; -}cy_stc_ble_gattc_grp_attr_data_list_t; - -/** Read By Group Response received from Server*/ -typedef struct -{ - /** Group attribute data list */ - cy_stc_ble_gattc_grp_attr_data_list_t attrData; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_read_by_grp_rsp_param_t; - -/** GATT read by type response received from server*/ -typedef cy_stc_ble_gattc_read_by_grp_rsp_param_t cy_stc_ble_gattc_read_by_type_rsp_param_t; - -/** GATT find by type value response received from server*/ -typedef struct -{ - /** Handle Range list */ - cy_stc_ble_gatt_attr_handle_range_t * range; - - /** Size of list */ - uint8_t count; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - -}cy_stc_ble_gattc_find_by_type_rsp_param_t; - -/** GATT list of Handle UUID pair parameter type */ -typedef struct -{ - /** Handle - UUID Pair list - This is a packed byte stream, hence it needs to be unpacked and decoded. */ - uint8_t *list; - - /** Number of elements in the list in bytes */ - uint16_t byteCount; - -}cy_stc_ble_gattc_handle_uuid_list_param_t; - -/** GATT find info response received from Server*/ -typedef struct -{ - /** Handle Value list */ - cy_stc_ble_gattc_handle_uuid_list_param_t handleValueList; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Format indicating, 16-bit (0x01) or 128-bit (0x02) UUIDs */ - uint8_t uuidFormat; - -}cy_stc_ble_gattc_find_info_rsp_param_t; - -/** Execute Write result */ -typedef struct -{ - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - - /** Result of the execute write request */ - uint8_t result; - -}cy_stc_ble_gattc_exec_write_rsp_param_t; - -/** Long procedure end indication event parameter */ -typedef struct -{ - /**Connection handle*/ - cy_stc_ble_conn_handle_t connHandle; - - /** Result of the execute write request */ - uint8_t opcode; - -}cy_stc_ble_gattc_long_procedure_end_param_t; - -/** Execute Write response parameter */ -typedef cy_stc_ble_gattc_exec_write_req_t cy_stc_ble_gattc_exec_write_rsp_t; -/** @} */ -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_gatt_client_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_StopCmd -***************************************************************************//** -* -* This function is used by the GATT Client to stop any of the following ongoing -* GATT procedures: -* 1. Cy_BLE_GATTC_DiscoverPrimaryServices() -* 2. Cy_BLE_GATTC_DiscoverPrimaryServiceByUuid() -* 3. Cy_BLE_GATTC_FindIncludedServices() -* 4. Cy_BLE_GATTC_DiscoverCharacteristics() -* 5. Cy_BLE_GATTC_DiscoverCharacteristicByUuid() -* 6. Cy_BLE_GATTC_DiscoverCharacteristicDescriptors() -* 7. Cy_BLE_GATTC_ReadLongCharacteristicValues() -* 8. Cy_BLE_GATTC_WriteLongCharacteristicValues() -* 9. Cy_BLE_GATTC_ReliableWrites() -* 10. Cy_BLE_GATTC_ReadLongCharacteristicDescriptors() -* 11. Cy_BLE_GATTC_WriteLongCharacteristicDescriptors() -* 12. Cy_BLE_GATTC_ReadByTypeReq() -* . -* If none of the above procedures is ongoing, then this command will be ignored. -* This function has no effect on ATT procedures other than those listed above. -* -* If the user intends to start a new GATT procedure including those listed above -* and there is an ongoing GATT procedure (any one from the above list), the user -* needs to call this function to stop the ongoing GATT procedure and then invoke -* the desired GATT procedure. -* This is not a blocking function. Successful operation is informed through event -* 'CY_BLE_EVT_GATTC_STOP_CMD_COMPLETE' if procedure is not already ended. -* -* \param param: parameter is of type cy_stc_ble_gattc_stop_cmd_param_t. -* param->connHandle: Connection handle to identify the peer GATT entity of type -* cy_stc_ble_conn_handle_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_StopCmd -( - cy_stc_ble_gattc_stop_cmd_param_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ExchangeMtuReq -***************************************************************************//** -* -* This function is used by the GATT Client to send Maximum Transmitted Unit -* (GATT MTU) supported by the GATT Client. This is a non-blocking function. -* -* Default GATT MTU size as per Bluetooth 4.1 core specification is 23 bytes. If -* the GATT Client supports a size greater than the default, it has to invoke -* this function with the desired GATT MTU size. This function should be -* initiated only once during a connection. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.3.1 -* for more details on GATT MTU exchange operation. -* -* This function call results in CY_BLE_EVT_GATTS_XCNHG_MTU_REQ event at the -* GATT Server's end in response to which the GATT Server is expected to send -* its GATT MTU size. -* -* The CY_BLE_EVT_GATTC_XCHNG_MTU_RSP event is generated at the -* GATT Client's end on receiving GATT MTU response from the GATT Server. -* -* \param param: parameter is of type CY_BLE_GATT_XCHG_MTU_REQ_PARAM_T. -* param->mtu: Size of GATT MTU. Max GATT MTU supported by BLE stack is 512 Bytes. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid or, 'mtu' value is greater than that set on calling Cy_BLE_StackInit(). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ExchangeMtuReq -( - cy_stc_ble_gatt_xchg_mtu_param_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverPrimaryServices -***************************************************************************//** -* -* This function is used by the GATT Client to discover the primary services as -* per the range provided on a GATT Server to which it is connected. -* This is a non-blocking function. -* -* Internally, this function initiates multiple Read By Group Type Requests to -* the peer device in response to which it receives Read By Group Type Responses. -* Each Read By Group Type Response results in -* CY_BLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP event, which is propagated to the -* application layer for handling. -* -* Primary service discovery is complete when Error Response -* (CY_BLE_EVT_GATTC_ERROR_RSP) is received and the Error Code is set to Attribute -* Not Found or when the End Group Handle in the Read by Group Type Response is -* 0xFFFF. Completion of this operation is notified to the upper layer(s) using -* CY_BLE_EVT_GATTC_ERROR_RSP with error code updated appropriately or with -* CY_BLE_EVT_GATTC_LONG_PROCEDURE_END event -* -* It is permitted to end the above stated sequence of operations early if the -* desired primary service is found prior to discovering all the primary services -* on the GATT Server. This can be achieved by calling the Cy_BLE_GATTC_StopCmd() -* function. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.4.1 for -* more details on this sequence of operations. -* -* \param param: parameter is of type cy_stc_ble_gattc_read_by_group_req_t. -* param->connHandle: Connection handle to identify the peer GATT entity of type -* cy_stc_ble_conn_handle_t. -* param->range: Parameter is of type cy_stc_ble_gatt_attr_handle_range_t where, -* 1. 'range.startHandle' can be set to the start handle of the desired -* primary service. -* 2. 'range.endHandle' can be set to the end handle of the desired -* primary service. -* \note -* 'startHandle' & 'endHandle' should not be zero and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_DiscoverPrimaryServices -( - cy_stc_ble_gattc_read_by_group_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverPrimaryServiceByUuid -***************************************************************************//** -* -* This function is used by the GATT Client to discover a specific primary -* service on a GATT Server, to which it is connected, when only the Service -* UUID is known. -* This is a non-blocking function. -* -* Internally, this function initiates multiple Find By Type Value Requests with -* the Attribute Type parameter set to the UUID for Primary Service and the -* Attribute Value set to the 16-bit Bluetooth UUID or 128-bit UUID for the -* specific primary service. Each Find By Type Value Response received from the -* peer device is passed to the application as -* CY_BLE_EVT_GATTC_FIND_BY_TYPE_VALUE_RSP event. -* -* The sequence of operations is complete when the Error Response is received -* and the Error Code is set to Attribute Not Found or when the End Group -* Handle in the Find By Type Value Response is 0xFFFF. Completion of this -* function is notified to the upper layer using the CY_BLE_EVT_GATTC_ERROR_RSP event -* with the error code updated appropriately or with the CY_BLE_EVT_GATTC_LONG_PROCEDURE_END -* event. -* -* It is permitted to end the function early by calling the Cy_BLE_GATTC_StopCmd() -* function if a desired primary service is found prior to discovery of all the -* primary services of the specified service UUID supported on the GATT Server. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.4.2 -* for more details on this sequence of operations. -* -* \param param: parameter is of type cy_stc_ble_gattc_find_by_type_value_req_t. -* param->connHandle: Connection handle to identify the peer GATT entity of type -* cy_stc_ble_conn_handle_t. -* param->range and param->uuid are ignored in this API. -* param->value: Parameter is of type cy_stc_ble_gatt_value_t, where, -* 1. 'value.val' should point to uint8_t array containing the UUID to -* look for. UUID can be 16 or 128 bit. -* 2. 'value.len' should be set to 2 if the 16-bit UUID is to be found. -* The length should be set to 16 if 128-bit UUID is to be found. -* 3. 'value.actualLen' is an unused parameter and should be ignored -* as it is unused. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_DiscoverPrimaryServiceByUuid -( - cy_stc_ble_gattc_find_by_type_value_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverCharacteristics -***************************************************************************//** -* -* This function is used by the GATT Client to find all characteristic -* declarations within a service definition on a GATT Server connected to it when -* only the service handle range is known. -* This is a non-blocking function. -* -* Internally, multiple Read By Type Requests are sent to the GATT Server in -* response to which Read By Type Responses are received. Each response results -* in the event CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP, which is passed to the -* application layer for handling. -* -* The function may end early by calling the Cy_BLE_GATTC_StopCmd() -* function if a desired characteristic is found prior to discovering all the -* characteristics of the specified service supported on the GATT Server. -* Completion of this function is notified to the upper layer using -* CY_BLE_EVT_GATTC_ERROR_RSP or with the CY_BLE_EVT_GATTC_LONG_PROCEDURE_END -* event. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.6.1 for -* more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_by_type_req_t, -* Where, the following needs to be set: -* param->range.startHandle -* param->range.endHandle -* param->connHandle -* Where, the following needs to be ignored: -* param->uuidFormat (CY_BLE_GATT_16_BIT_UUID_FORMAT or -* CY_BLE_GATT_128_BIT_UUID_FORMAT) -* param->uuid.uuid16 or readByTypeReqParam->uuid.uuid128 -* based on the uuidFormat -* \note -* 'startHandle' & 'endHandle' should not be zero, and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_DiscoverCharacteristics -( - cy_stc_ble_gattc_read_by_type_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverCharacteristicByUuid -***************************************************************************//** -* -* This function is used by the GATT Client to discover service characteristics -* on a GATT Server when only the service handle ranges are known and the -* characteristic UUID is known. -* This is a non-blocking function. -* -* Internally, multiple Read By Type Requests are sent to the peer device in -* response to which Read By Type Responses are received. Each of these responses -* results in the event CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP, which is passed to the -* application layer for further processing. -* -* The function may end early by calling the Cy_BLE_GATTC_StopCmd() -* function if a desired characteristic is found prior to discovering all the -* characteristics for the specified service supported on the GATT Server. -* Completion of this function is notified to the upper layer using -* CY_BLE_EVT_GATTC_ERROR_RSP or with CY_BLE_EVT_GATTC_LONG_PROCEDURE_END -* event. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.6.2 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_by_type_req_t, -* Where, the following must be set: -* param->range.startHandle -* param->range.endHandle -* param->connHandle -* param->uuidFormat (CY_BLE_GATT_16_BIT_UUID_FORMAT or -* CY_BLE_GATT_128_BIT_UUID_FORMAT) -* param->uuid.uuid16 or readByTypeReqParam->uuid.uuid128 -* based on the uuidFormat -* \note -* 'startHandle' & 'endHandle' should not be zero, and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_DiscoverCharacteristicByUuid -( - cy_stc_ble_gattc_read_by_type_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_DiscoverCharacteristicDescriptors -***************************************************************************//** -* -* This function is used by the GATT Client to find all the characteristic -* descriptors. This is a non-blocking function. -* -* Internally, multiple Find Information Requests are sent to the peer device in -* response to which Find Information Responses are received by the GATT Client. -* Each of these responses generate CY_BLE_EVT_GATTC_FIND_INFO_RSP event at the -* GATT Client end which is propagated to the application layer for further -* processing. -* -* The function may end early by calling the Cy_BLE_GATTC_StopCmd() -* function if the desired Characteristic Descriptor is found prior to discovering -* all the characteristic descriptors of the specified characteristic. Completion -* of this function is notified to the upper layer using CY_BLE_EVT_GATTC_ERROR_RSP or -* the CY_BLE_EVT_GATTC_LONG_PROCEDURE_END event. -* -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.7.1 for -* more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_find_info_req_t. -* Where, the following needs to be set: -* param->range.startHandle -* param->range.endHandle -* param->connHandle -* \note -* 'startHandle' & 'endHandle' should not be zero, and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_DiscoverCharacteristicDescriptors -( - cy_stc_ble_gattc_find_info_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_FindIncludedServices -***************************************************************************//** -* -* This function is used by the GATT Client to find Included Service -* declarations within a GATT Service to which it is connected. This is a -* non-blocking function. -* -* Internally, multiple Read By Type Requests are sent to the peer device in -* response to which Read By Type Responses are received -* (CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP) and passed to the application layer. -* -* When Read By Type Response data does not contain the service UUID, -* indicating the service UUID is a 128-bit UUID, the application layer can -* choose to get the service UUID by performing the following steps: -* 1. Stop ongoing GATT operation by invoking Cy_BLE_GATTC_StopCmd() -* 2. Send Read Request by invoking the function -* Cy_BLE_GATTC_ReadCharacteristicValue() with the read request handle set to -* the attribute handle of the included service. Handle associated events. -* 3. Re-initiate Cy_BLE_GATTC_FindIncludedServices function, setting the start -* handle to the attribute handle that is placed next to the one used in -* the above step. -* -* The function may end early if a desired included service is -* found prior to discovering all the included services of the specified -* service supported on the server by calling the Cy_BLE_GATTC_StopCmd() -* function. If the Cy_BLE_GATTC_StopCmd() function is not invoked, completion of -* this function is notified to the upper layer using CY_BLE_EVT_GATTC_ERROR_RSP -* or the CY_BLE_EVT_GATTC_LONG_PROCEDURE_END event. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.5.1 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_by_type_req_t, -* Where, the following needs to be set: -* param->range.startHandle -* param->range.endHandle -* param->connHandle -* Where, the following needs to be ignored: -* param->uuidFormat (CY_BLE_GATT_16_BIT_UUID_FORMAT or -* CY_BLE_GATT_128_BIT_UUID_FORMAT) -* param->uuid.uuid16 or readByTypeReqParam->uuid.uuid128 -* based on the uuidFormat -* \note -* 'startHandle' & 'endHandle' should not be zero, and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_FindIncludedServices -( - cy_stc_ble_gattc_read_by_type_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadByTypeReq -***************************************************************************//** -* -* This function allows the user to send Read by type request to peer server -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.5.1 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_by_type_req_t, -* Where, the following needs to be set: -* param->range.startHandle -* param->range.endHandle -* param->connHandle -* param->uuidFormat (CY_BLE_GATT_16_BIT_UUID_FORMAT or -* CY_BLE_GATT_128_BIT_UUID_FORMAT) -* param->uuid.uuid16 or readByTypeReqParam->uuid.uuid128 -* based on the uuidFormat -* -* \note -* 'startHandle' & 'endHandle' should not be zero, and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadByTypeReq -( - cy_stc_ble_gattc_read_by_type_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadCharacteristicValue -***************************************************************************//** -* -* This function reads a Characteristic Value from a GATT Server when the GATT -* Client knows the Characteristic Value Handle. This is a non-blocking function. -* -* Internally, Read Request is sent to the peer device in response to which Read -* Response is received. This response results in CY_BLE_EVT_GATTC_READ_RSP event -* which is propagated to the application for handling the event data. An Error -* Response (CY_BLE_EVT_GATTC_ERROR_RSP event at the GATT Client's end) is sent -* by the GATT Server in response to the Read Request on insufficient -* authentication or insufficient authorization or insufficient encryption key -* size is caused by the GATT Client, or if a read operation is not permitted on -* the Characteristic Value. The Error Code parameter is set as specified in -* the Attribute Protocol. -* Execution of this API generates CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event -* at GATT server's end if the corresponding characteristic's attribute permission is set -* to CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.8.1 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_req_t. -* Where, the following needs to be set: -* param->attrHandle: Attribute handle to be read -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadCharacteristicValue -( - cy_stc_ble_gattc_read_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadUsingCharacteristicUuid -***************************************************************************//** -* -* This function reads a Characteristic Value from the GATT Server when the GATT -* Client knows only the characteristic UUID and does not know the handle of the -* characteristic. This is a non-blocking function. -* -* Internally, Read By Type Request is sent to the peer device in response to -* which Read By Type Response is received by the GATT Client. This results in -* CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event, which is propagated to the application -* layer for further handling. -* Execution of this API generates the CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event -* at the GATT server's end if the corresponding characteristic's attribute permission has is to -* CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT. -* -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.8.2 for -* more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_by_type_req_t, -* Where, the following needs to be set: -* param->range.startHandle -* param->range.endHandle -* param->connHandle -* param->uuidFormat (CY_BLE_GATT_16_BIT_UUID_FORMAT or -* CY_BLE_GATT_128_BIT_UUID_FORMAT) -* param->uuid.uuid16 or readByTypeReqParam->uuid.uuid128 -* based on the uuidFormat -* \note -* 'startHandle' & 'endHandle' should not be zero, and 'startHandle' shall be less than or equal to the 'endHandle'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadUsingCharacteristicUuid -( - cy_stc_ble_gattc_read_by_type_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadLongCharacteristicValues -***************************************************************************//** -* -* This function reads a Characteristic Value from the GATT Server when the GATT -* Client knows the Characteristic Value Handle and the length of the -* Characteristic Value is longer than can be sent in a single Read Response -* Attribute Protocol message. This is a non-blocking function. -* -* Internally multiple Read Blob Requests are sent to the peer device in response -* to which Read Blob Responses are received. For each Read Blob Request, a Read -* Blob Response event is received (CY_BLE_EVT_GATTC_READ_BLOB_RSP) with a -* portion of the Characteristic Value contained in the Part Attribute Value -* parameter. These events are propagated to the application layer -* for further processing. Each read blob response will return up to (GATT MTU-1) bytes of -* data. If the size of characteristic value field is an integral multiple of (GATT MTU-1) -* then the operation terminates with an error response event, where the error code is -* CY_BLE_GATT_ERR_INVALID_OFFSET. If the size of the characteristic value field is -* not an integral multiple of (GATT MTU-1), the last read blob response will return -* data bytes that are less than (GATT MTU-1). The application must monitor these two -* conditions before proceeding with the initiation of any other GATT operation. -* -* An Error Response event (CY_BLE_EVT_GATTC_ERROR_RSP) is sent by the GATT Server -* in response to the Read Blob Request if insufficient authentication, -* insufficient authorization, insufficient encryption key size is used by the -* client, or if a read operation is not permitted on the Characteristic Value. -* The Error Code parameter is set as specified in the Attribute Protocol. -* -* If the Characteristic Value is not longer than (GATT MTU - 1), an Error Response -* with the Error Code set to Attribute Not Long is received by the GATT Client -* on the first Read Blob Request. -* -* Execution of this API generates the CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event -* at the GATT server's end if the corresponding characteristic's attribute permission is set to -* CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.8.3 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_blob_req_t. -* Where, the following needs to be set: -* param->attrHandle -* param->offset -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadLongCharacteristicValues -( - cy_stc_ble_gattc_read_blob_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadMultipleCharacteristicValues -***************************************************************************//** -* -* This function reads multiple Characteristic Values from a GATT Server when -* the GATT Client knows the Characteristic Value Handles. This is a -* non-blocking function. -* -* Internally, Read Multiple Request is sent to the peer device in response to -* which Read Multiple Response is received. This results in the -* CY_BLE_EVT_GATTC_READ_MULTI_RSP event, which is propagated to the application -* layer. -* -* An Error Response event is sent by the server (CY_BLE_EVT_GATTC_ERROR_RSP) in -* response to the Read Multiple Request if insufficient authentication, -* insufficient authorization, or insufficient encryption key size is used by the -* client, or if a read operation is not permitted on any of the Characteristic -* Values. The Error Code parameter is set as specified in the Attribute -* Protocol. -* -* Execution of this API generates CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event -* at the GATT server's end if corresponding characteristic's attribute permission is set to -* CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.8.4 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_mult_req_t. -* Where, the following needs to be set: -* param->handleList -* param->listCount -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if any of the input parameters are invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadMultipleCharacteristicValues -( - cy_stc_ble_gattc_read_mult_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadCharacteristicDescriptors -***************************************************************************//** -* -* This function reads a characteristic descriptor from a GATT Server when the -* GATT Client knows the Attribute handle from the characteristic descriptor -* declaration. This is a non-blocking function. -* -* Internally, Read Request is sent to the peer device in response to which -* Read Response is received. This response results in CY_BLE_EVT_GATTC_READ_RSP -* event, which is propagated to the application for handling the event data. -* -* An Error Response (the CY_BLE_EVT_GATTC_ERROR_RSP event at the GATT Client's end) -* is sent by the GATT Server in response to the Read Request on insufficient -* authentication or insufficient authorization or insufficient encryption -* key size is caused by the GATT Client, or if a read operation is not -* permitted on the Characteristic Value. The Error Code parameter is set as -* specified in the Attribute Protocol. -* -* -* Execution of this API generates CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event -* at GATT server's end if corresponding attribute's permission has set to -* CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.12.1 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_req_t. -* Where, the following needs to be set: -* param->attrHandle: Attribute handle to be read -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadCharacteristicDescriptors -( - cy_stc_ble_gattc_read_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReadLongCharacteristicDescriptors -***************************************************************************//** -* -* This function reads a characteristic descriptor from a GATT Server when the -* GATT Client knows the Attribute handle from the characteristic descriptor -* declaration and the length of the characteristic descriptor declaration is -* longer than what can be sent in a single Read Response Attribute Protocol -* message. This is a non-blocking function. -* -* Internally multiple Read Blob Requests are sent to the peer device in response -* to which Read Blob Responses are received. For each Read Blob Request, a Read -* Blob Response event is received (CY_BLE_EVT_GATTC_READ_BLOB_RSP) with a portion -* of the Characteristic Value contained in the Part Attribute Value parameter. -* These events are propagated to the application layer for further processing. -* Each read blob response will return up to (GATT MTU-1) bytes of data. If the size of -* characteristic descriptor field is an integral multiple of (GATT MTU-1) then the -* operation terminates with an error response event, where the error code is -* CY_BLE_GATT_ERR_INVALID_OFFSET. If the size of the characteristic descriptor -* field is not an integral multiple of (GATT MTU-1), the last read blob response will -* return data bytes that are less than (GATT MTU-1). The application must monitor -* these two conditions before proceeding with the initiation of any other GATT -* operation. -* -* An Error Response event (CY_BLE_EVT_GATTC_ERROR_RSP) is sent by the GATT Server -* in response to the Read Blob Request if insufficient authentication, -* insufficient authorization, or insufficient encryption key size is used by the -* client, or if a read operation is not permitted on the Characteristic Value. -* The Error Code parameter is set as specified in the Attribute Protocol. If -* the Characteristic Value is not longer than (GATT MTU - 1) an Error Response with -* the Error Code set to Attribute Not Long is received by the GATT Client on -* the first Read Blob Request. -* -* Execution of this API generates CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event -* at the GATT server's end if the corresponding attribute's permission has set to -* CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT. -* -* Refer to Bluetooth 4.1 core specification, -* Volume 3, Part G, section 4.12.2 for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_read_blob_req_t. -* Where, the following needs to be set: -* param->attrHandle -* param->offset -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReadLongCharacteristicDescriptors -( - cy_stc_ble_gattc_read_blob_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_WriteCharacteristicValue -***************************************************************************//** -* -* This function writes a Characteristic Value to a GATT Server when the GATT -* Client knows the Characteristic Value Handle. This is a non-blocking function. -* -* Internally, Write Request is sent to the GATT Server in response to which -* Write Response is received. This results in the event -* CY_BLE_EVT_GATTC_WRITE_RSP, which indicates that the write operation succeeded. -* -* An Error Response event (CY_BLE_EVT_GATTC_ERROR_RSP) is sent by the server in -* response to the Write Request if insufficient authentication, insufficient -* authorization, or insufficient encryption key size is used by the client, or if -* a write operation is not permitted on the Characteristic Value. The Error -* Code parameter is set as specified in the Attribute Protocol. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section -* 4.9.3 for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_write_req_t. -* Where, the following needs to be set: -* param->handleValPair -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero or if 'param->handleValPair.value.len' value is greater than (Effective GATT MTU-3). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_WriteCharacteristicValue -( - cy_stc_ble_gattc_write_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_WriteCharacteristicDescriptors -***************************************************************************//** -* -* This function writes a characteristic descriptor value to a GATT Server -* when the GATT Client knows the characteristic descriptor handle. This is a -* non-blocking function. -* -* Internally, Write Request is sent to the GATT Server in response to which -* Write Response is received. This results in the event -* CY_BLE_EVT_GATTC_WRITE_RSP, which indicates that the write operation succeeded. -* -* An Error Response event (CY_BLE_EVT_GATTC_ERROR_RSP) is sent by the server in -* response to the Write Request if insufficient authentication, insufficient -* authorization, or insufficient encryption key size is used by the client, or if -* a write operation is not permitted on the Characteristic Value. The Error -* Code parameter is set as specified in the Attribute Protocol. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.12.3 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_write_req_t. -* Where, the following needs to be set: -* param->handleValPair -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero or if 'param->handleValPair.value.len' value is greater than (Effective GATT MTU-3). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_WriteCharacteristicDescriptors -( - cy_stc_ble_gattc_write_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_WriteLongCharacteristicValues -***************************************************************************//** -* -* This function writes a Characteristic Value to a GATT Server when the GATT -* Client knows the Characteristic Value Handle but the length of the -* Characteristic Value is longer than GATT MTU size and cannot be sent in a single -* Write Request Attribute Protocol message. This is a non-blocking function. -* -* Internally, multiple Prepare Write Requests are sent to the GATT Server using -* the CY_BLE_EVT_GATTS_PREP_WRITE_REQ event, in response to which Prepare Write Responses -* are received. No events are generated by the BLE Stack during these operations. -* -* Prepare Write Requests are repeated until the complete Characteristic Value -* has been transferred to the GATT Server, after which an Execute Write Request -* is sent to the GATT Server to write the initially transferred value at the -* GATT Server's end. This generates CY_BLE_EVT_GATTS_EXEC_WRITE_REQ at the GATT -* Server's end. -* -* Once the GATT Server responds, CY_BLE_EVT_GATTC_EXEC_WRITE_RSP event -* is generated at the GATT Client's end. The value associated with this event -* has to be checked by the application layer to confirm that the long write -* operation succeeded. -* -* An Error Response event CY_BLE_EVT_GATTC_ERROR_RSP is -* received by the GATT Client in response to the Prepare Write Request if -* insufficient authentication, insufficient authorization, or insufficient -* encryption key size is used by the client, or if a write operation is not -* permitted on the Characteristic Value. The Error Code parameter is set as -* specified in the Attribute Protocol. -* -* Execution of this API generates CY_BLE_EVT_MEMORY_REQUEST event for request -* CY_BLE_PREPARED_WRITE_REQUEST at GATT server's end. GATT server application has to -* allocate memory of type cy_stc_ble_prepare_write_request_memory_t and set configMemory -* in this event parameter to allocated memory. -* -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.9.4 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_prep_write_req_t, -* where 'param->value.val' points to the actual -* data to be written. 'param' and all associated -* variables need to be retained in memory by the calling -* application until the GATT Write Long Characteristic Value -* operation is completed successfully. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_WriteLongCharacteristicValues -( - cy_stc_ble_gattc_prep_write_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_ReliableWrites -***************************************************************************//** -* -* This function writes a Characteristic Value to a GATT Server when the GATT -* Client knows the Characteristic Value Handle, and assurance is required -* that the correct Characteristic Value is going to be written by transferring -* the Characteristic Value to be written in both directions before the write -* is performed. This is a non-blocking function. -* -* Internally, multiple Prepare Write Requests are sent to the GATT Server using -* CY_BLE_EVT_GATTS_PREP_WRITE_REQ event, in response to which Prepare Write Responses -* are received. No events are generated by the BLE Stack during these operations. -* -* Prepare Write Requests are repeated until the complete Characteristic Value -* has been transferred to the GATT Server, after which an Execute Write Request -* is sent to the GATT Server to write the initially transferred value at the -* GATT Server's end. This generates CY_BLE_EVT_GATTS_EXEC_WRITE_REQ at the GATT -* Server's end. -* -* Once the GATT Server responds, a CY_BLE_EVT_GATTC_EXEC_WRITE_RSP event is -* generated at the GATT Client's end. The value associated with this event has -* to be checked by the application layer to confirm that the long write -* operation succeeded. An Error Response event CY_BLE_EVT_GATTC_ERROR_RSP is -* received by the GATT Client in response to the Prepare Write Request if -* insufficient authentication, insufficient authorization, insufficient -* encryption key size is used by the client, or if a write operation is not -* permitted on the Characteristic Value. The Error Code parameter is set as -* specified in the Attribute Protocol. -* -* Execution of this API generates the CY_BLE_EVT_MEMORY_REQUEST event for request -* CY_BLE_PREPARED_WRITE_REQUEST at the GATT server's end. The GATT server application must -* allocate memory of type cy_stc_ble_prepare_write_request_memory_t and set configMemory -* in this event parameter to allocated memory. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.9.5 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_reliable_write_req_t. -* Since more than one writes are performed 'param' and -* all associated variables need to be retained in memory by -* the calling application until the GATT Reliable Write -* operation is completed successfully. -* param->handleValOffsetPair: array of type 'cy_stc_ble_gatt_handle_value_offset_param_t', which -* contains the values to be written, has to be specified. -* param->numOfRequests: Number of requests. That is, the count of array of structures -* of type cy_stc_ble_gatt_handle_value_offset_param_t. Each array element -* represents a value and the attribute to which the value has -* to be written. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' or 'handleValOffsetPair' is NULL or 'connHandle' is invalid, or if 'numOfRequests' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_ReliableWrites -( - cy_stc_ble_gattc_reliable_write_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_WriteLongCharacteristicDescriptors -***************************************************************************//** -* -* This function writes a characteristic descriptor value to a GATT Server -* when the GATT Client knows the characteristic descriptor handle but the -* length of the characteristic descriptor value is longer than what can be -* sent in a single Write Request Attribute Protocol message. This is a -* non-blocking function. -* -* Internally, multiple Prepare Write Requests are sent -* to the GATT Server using CY_BLE_EVT_GATTS_PREP_WRITE_REQ event, in response to -* which Prepare Write Responses are received. No events are generated by the -* BLE Stack during these operations. -* -* Prepare Write Requests are repeated until the complete Characteristic -* Descriptor Value has been transferred to the GATT Server, after which an -* Execute Write Request is sent to the GATT Server to write the initially -* transferred value at the GATT Server's end. This generates -* CY_BLE_EVT_GATTS_EXEC_WRITE_REQ at the GATT Server's end. -* -* Once the GATT Server responds, the CY_BLE_EVT_GATTC_EXEC_WRITE_RSP event is -* generated at the GATT Client's end. The value associated with this event must -* be checked by the application layer to confirm that the long write operation -* succeeded. -* -* An Error Response event CY_BLE_EVT_GATTC_ERROR_RSP is received by the GATT -* Client in response to the Prepare Write Request if insufficient -* authentication, insufficient authorization, or insufficient encryption key -* size is used by the client, or if a write operation is not permitted on the -* Characteristic Value. The Error Code parameter is set as specified in the -* Attribute Protocol. -* -* Execution of this API generates CY_BLE_EVT_MEMORY_REQUEST event for request -* CY_BLE_PREPARED_WRITE_REQUEST at GATT server's end. GATT server application must -* allocate memory of type cy_stc_ble_prepare_write_request_memory_t and set configMemory -* in this event parameter to allocated memory. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, -* Part G, section 4.12.4 for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_prep_write_req_t, -* where 'param->value.val' points to the actual -* data to be written. 'param' and all associated -* variables must be retained in memory by the calling -* application until the GATT Write Long Characteristic Value -* operation is completed successfully. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_WriteLongCharacteristicDescriptors -( - cy_stc_ble_gattc_prep_write_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_SendExecuteWriteReq -***************************************************************************//** -* -* This function allows the user to send execute write request to remote server. -* This function should be called if client has previously initiated long/reliable -* write operation and remote has send error response. Based on error response -* application may choose to execute all pending requests or cancel the request. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_exec_write_req_t. -* param->connHandle: Connection handle to identify the peer GATT entity of type -* cy_stc_ble_conn_handle_t. -* param->flag: Indicates whether Queued Write is to be executed (0x01) or canceled (0x00) -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_SendExecuteWriteReq -( - cy_stc_ble_gattc_exec_write_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_WriteWithoutResponse -***************************************************************************//** -* -* This function writes a Characteristic Value to a GATT Server when the GATT -* Client knows the Characteristic Value Handle and the client does not need an -* acknowledgment that the write was successfully performed. This is a blocking -* function. No event is generated on calling this function. -* -* Internally, Write Command is sent to the GATT Server and nothing is -* received in response from the GATT Server. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.9.1 -* for more details on the sequence of operations. -* -* On the server side CY_BLE_EVT_GATTS_WRITE_CMD_REQ event is sent to application -* to indicate GATT Write Without Response request is received from client. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_write_req_t. -* Where, the following needs to be set: -* param->handleValPair -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid, or if 'attrHandle' is zero or if 'param->handleValPair.value.len' value is greater than (Effective GATT MTU-3). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_WriteWithoutResponse -( - cy_stc_ble_gattc_write_cmd_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_SignedWriteWithoutRsp -***************************************************************************//** -* -* This function writes a Characteristic Value to a server when the client knows -* the Characteristic Value Handle and the ATT Bearer is not encrypted. This -* procedure shall be used only if the Characteristic Properties -* authenticated bit is enabled and the client and server device share a bond -* as defined in Bluetooth Spec4.1 [Vol. 3] Part C, Generic Access Profile. -* -* This function only writes the first (GATT_MTU - 15) octets of an -* Attribute Value. This function cannot be used to write a long Attribute. -* -* Internally, Signed Write Command is used. -* Refer to Bluetooth Spec 4.1 Security Manager [Vol. 3] Part H, Section 2.4.5. -* -* If the authenticated Characteristic Value that is written is the wrong size, -* has an invalid value as defined by the profile, or the signed value does not -* authenticate the client, then the write shall not succeed and no error shall -* be generated by the server. -* -* On the server side CY_BLE_EVT_GATTS_DATA_SIGNED_CMD_REQ event is sent to the application -* to indicate the GATT Signed write cmd is received from the client. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_write_req_t. -* Where, the following needs to be set: -* param->handleValPair -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or if 'attrHandle' is zero. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | 'connHandle.bdHandle' value does not represent any existing entry in the Stack. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_SignedWriteWithoutRsp -( - cy_stc_ble_gattc_signed_write_cmd_req_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTC_Confirmation -***************************************************************************//** -* -* This function sends confirmation to the GATT Server on receiving Handle Value -* Indication event CY_BLE_EVT_GATTC_HANDLE_VALUE_IND at the GATT Client's end. -* This is a non-blocking function. -* -* This function call results in CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF event at the -* GATT Server's end. -* -* Refer to the Bluetooth 4.1 core specification, Volume 3, Part G, section 4.11.1 -* for more details on the sequence of operations. -* -* \param param: Pointer to a variable of type cy_stc_ble_gattc_confirmation_req_t. -* Where, the following needs to be set: -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTC_Confirmation -( - cy_stc_ble_gattc_confirmation_req_t * param -); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/** @} */ - -#endif /* CY_BLE_STACK_GATT_CLIENT_H_ */ - -/* EOF */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_db.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_db.h deleted file mode 100644 index 01992dd53b..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_db.h +++ /dev/null @@ -1,615 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_stack_gatt_db.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of Generic Attribute Profile - GATT DB Access layer. -* Also specified the defines, constants, and data structures required for the APIs. -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_STACK_GATT_DB_H -#define CY_BLE_STACK_GATT_DB_H - - -/*************************************** -* Common stack includes -***************************************/ - -#include "cy_ble_stack_gatt.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -** Macro Definition -***************************************/ - -/** GATT Defined Attributes */ -#define CY_BLE_GATT_PRIMARY_SERVICE (0x2800u) /**< GATT Primary service */ -#define CY_BLE_GATT_SECONDARY_SERVICE (0x2801u) /**< GATT secondary service */ -#define CY_BLE_GATT_INCLUDE_SERVICE (0x2802u) /**< GATT included service */ -#define CY_BLE_GATT_CHARACTERISTIC (0x2803u) /**< GATT characteristic */ -#define CY_BLE_GATT_EXTENDED_PROPERTIES (0x2900u) /**< GATT extended properties */ -#define CY_BLE_GATT_USER_DESCRIPTION (0x2901u) /**< GATT user description */ -#define CY_BLE_GATT_CLIENT_CONFIG (0x2902u) /**< GATT client configuration */ -#define CY_BLE_GATT_SERVER_CONFIG (0x2903u) /**< GATT server configuration */ -#define CY_BLE_GATT_PRESENTATION_FORMAT (0x2904u) /**< GATT presentation format */ -#define CY_BLE_GATT_AGGREGATE_FORMAT (0x2905u) /**< GATT aggregate format */ - -#define CY_BLE_GATT_GAP_SERVICE_UUID (0x1800u) /**< GATT GAP service UUID */ - -/** GATT Database Properties Field Description - 1. Attribute read permissions B0: Bluetooth Spec Defined - 2. Attribute write permissions B1: Bluetooth Spec Defined - 3. Characteristic properties B2: Bluetooth Spec Defined - 4. B3: Implementation Specific */ - -/** Attribute Read Permissions B0: Bluetooth Spec Defined */ -/**\note: It is mandatory to set 'CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_ENCRYPT' bit if either - 'CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_AUTHENTICATE' or 'CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_SC_AUTHENTICATE' - bits are set. Otherwise these bits will be ignored. */ -#define CY_BLE_GATT_DB_ATTR_PROP_READ (0x00000001u) /**< Attribute Read permission */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_ENCRYPT (0x00000002u) /**< Attribute Read with encryption */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_AUTHENTICATE (0x00000004u) /**< Attribute Read with authentication */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_AUTHORIZE (0x00000008u) /**< Attribute Read with authorization */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_SEC_SC_AUTHENTICATE (0x00000010u) /**< Attribute Read with SC authentication */ - -#define CY_BLE_GATT_DB_ATTR_PROP_RD_MASK (0x0000001Fu) /**< Attribute Read property bit mask */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_BIT_SHIFT (0x0u) /**< Attribute Read property bit shift */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_SECURITY_MASK (0x0000001Eu) /**< Attribute Read prop security bit mask */ -#define CY_BLE_GATT_DB_ATTR_PROP_RD_SECURITY_BIT_SHIFT (0x1u) /**< Attribute Read prop security bit shift */ - -/** Attribute Write Permissions B1: Bluetooth Spec Defined */ -/**\note: It is mandatory to set 'CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_ENCRYPT' bit if either - 'CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_AUTHENTICATE' or 'CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_SC_AUTHENTICATE' - bits are set. Otherwise these bits will be ignored. */ -#define CY_BLE_GATT_DB_ATTR_PROP_WRITE (0x00000100u) /**< Attribute Write permission */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_ENCRYPT (0x00000200u) /**< Attribute Write with encryption */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_AUTHENTICATE (0x00000400u) /**< Attribute Write with authentication */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_AUTHORIZE (0x00000800u) /**< Attribute Write with authorization */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_SEC_SC_AUTHENTICATE (0x00001000u) /**< Attribute Write with SC authentication */ - -#define CY_BLE_GATT_DB_ATTR_PROP_WR_MASK (0x00001F00u) /**< Attribute Write property bit mask */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_BIT_SHIFT (0x8u) /**< Attribute Write property bit shift */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_SECURITY_MASK (0x00001E00u) /**< Attribute Write prop security bit mask */ -#define CY_BLE_GATT_DB_ATTR_PROP_WR_SECURITY_BIT_SHIFT (0x9u) /**< Attribute Write prop security bit shift */ - -/** Characteristic properties B2: Bluetooth Spec Defined */ -#define CY_BLE_GATT_DB_CH_PROP_BROADCAST (0x00010000u) /**< characteristic property for broadcast */ -#define CY_BLE_GATT_DB_CH_PROP_READ (0x00020000u) /**< characteristic property for read */ -#define CY_BLE_GATT_DB_CH_PROP_RD_WRITE_WO_RESP (0x00040000u) /**< characteristic property for wtite without response */ -#define CY_BLE_GATT_DB_CH_PROP_WRITE (0x00080000u) /**< characteristic property for write */ -#define CY_BLE_GATT_DB_CH_PROP_NOTIFY (0x00100000u) /**< characteristic property for notify */ -#define CY_BLE_GATT_DB_CH_PROP_INDICATE (0x00200000u) /**< characteristic property for indication */ -#define CY_BLE_GATT_DB_CH_PROP_SEC_AUTH_SIGNED_WRITE (0x00400000u) /**< characteristic property for signed write */ -#define CY_BLE_GATT_DB_CH_PROP_EXT_PROP (0x00800000u) /**< characteristic property for extended properties */ - -#define CY_BLE_GATT_DB_CHAR_PROP_MASK (0x00FF0000u) /**< characteristic property bit mask */ -#define CY_BLE_GATT_DB_CHAR_PROP_BIT_SHIFT (0x10u) /**< characteristic property bit shift */ - -/** Extended properties values.*/ -/**\note: These properties are not - part of the permission field. The peer GATT layer or local GATT - layer must read "Characteristic Extended Properties - Descriptor" value. */ -#define CY_BLE_GATT_DB_CH_PROP_EXT_PROP_RELIABLE_WRITE (0x0001u) /**< extended property of reliable write */ -#define CY_BLE_GATT_DB_CH_PROP_EXT_PROP_WRITABLE_AUX (0x0002u) /**< extended property of writable aux */ - -/** Implementation permissions B3: Implementation specific - defines to access runtime characteristics. */ - -/** Bit Mask */ -/** Characteristic read access event bit */ -#define CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT (0x01000000u) -/** characteristic CCCD bit */ -#define CY_BLE_GATT_DB_CCCD_ATTR (0x02000000u) -/** attribute format */ -#define CY_BLE_GATT_DB_ATTR_UUID_FMT_32 (0x04000000u) -/** attribute format */ -#define CY_BLE_GATT_DB_ATTR_UUID_FMT_128 (0x08000000u) - -/** Encryption Key Size 7 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_7 (0x10000000u) - -/** Encryption Key Size 8 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_8 (0x20000000u) - -/** Encryption Key Size 9 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_9 (0x30000000u) - -/** Encryption Key Size 10 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_10 (0x40000000u) - -/** Encryption Key Size 11 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_11 (0x50000000u) - -/** Encryption Key Size 12 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_12 (0x60000000u) - -/** Encryption Key Size 13 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_13 (0x70000000u) - -/** Encryption Key Size 14 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_14 (0x80000000u) - -/** Encryption Key Size 15 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_15 (0x90000000u) - -/** Encryption Key Size 16 Needed for the Service */ -#define CY_BLE_GATT_DB_SER_ENCRYPT_KEY_SIZE_16 (0xA0000000u) - -/** No Encryption Needed for the Service */ -#define CY_BLE_GATT_DB_SER_NO_ENCRYPT_PROPERTY (0x00000000u) - -/** Encryption Key Size Mask Needed for the Service */ -#define CY_BLE_GATT_DB_ENC_KEY_SIZE_MASK (0xF0000000u) - -/** By default entries in CY_BLE_GATT DB is 16-bit UUID - This mask is defined to decide UUID length */ -#define CY_BLE_GATT_DB_ATTR_UUID_FMT_16_MASK (0x03000000u) - - -/** CY_BLE_GATT Client Configuration values */ -/** Client configuration notification */ -#define CY_BLE_GATT_CLI_CNFG_NOTIFICATION (0x0001u) -/** Client configuration indication */ -#define CY_BLE_GATT_CLI_CNFG_INDICATION (0x0002u) -/** default configuration */ -#define CY_BLE_GATT_CLI_CNFG_DEFAULT (0x0000u) - -/** Unit size is with respect to word (16 bit) */ -#define CY_BLE_GATT_DB_128_BIT_UUID_SZ (0x10u) /**< 128-bit uuid size */ -#define CY_BLE_GATT_DB_32_BIT_UUID_SZ (0x04u) /**< 32-bit uuid size */ -#define CY_BLE_GATT_DB_16_BIT_UUID_SZ (0x02u) /**< 16-bit uuid size */ - -#define CY_BLE_GATT_DB_ATTR_16_BIT_UUID (0x00u) /**< 128-bit uuid */ -#define CY_BLE_GATT_DB_ATTR_32_BIT_UUID (0x01u) /**< 32-bit uuid */ -#define CY_BLE_GATT_DB_ATTR_128_BIT_UUID (0x02u) /**< 16-bit uuid */ - -/** GATT DB attribute property Size */ -#define CY_BLE_GATT_DB_ATTR_PRPTY_SZ (0x01u) - -/** GATT DB attribute Handle Size */ -#define CY_BLE_GATT_DB_ATTR_HANDLE_SZ (0x02u) - -/** Locally initiated operation, needed for local updates based on Attribute - Handles. */ -#define CY_BLE_GATT_DB_LOCALLY_INITIATED (0x00u) - -/** Peer Initiated GATT DB transaction */ -#define CY_BLE_GATT_DB_PEER_INITIATED (0x40u) - -/** Read operation for Attribute */ -#define CY_BLE_GATT_DB_READ (0x01u) - -/** Write operation for Attribute */ -#define CY_BLE_GATT_DB_WRITE (0x02u) - -/** Prepare Write operation for Attribute */ -#define CY_BLE_GATT_DB_PREP_WRITE (0x04u) - -/** Write without response operation for Attribute */ -#define CY_BLE_GATT_DB_WRITE_WITHOUT_RSP (0x80u) - -/*************************************** -** Data Struct Definition -***************************************/ -/** - \addtogroup group_ble_common_api_gatt_definitions - @{ -*/ - -/** Attribute value type used in GATT database */ -typedef struct -{ - /** Length in number of bytes for attGenericVal */ - uint16_t actualLength; - - /** Buffer to the store generic characteristic value based on - length or complete UUID value if the attribute is of type 128-bit - UUID and 32-bit UUID type. */ - void * attGenericVal; - -}cy_stc_ble_gatts_att_gen_val_len_t; - -/** Attribute value type used in the GATT database */ -typedef struct -{ - /** Length in number of bytes for attGenericVal */ - uint16_t maxAttrLength; - - /** Buffer to the store generic characteristic value based on - length or complete UUID value if the attribute is of type 128-bit - UUID and 32-bit UUID type. */ - cy_stc_ble_gatts_att_gen_val_len_t * attGenericValLen; - -}cy_stc_ble_gatts_att_pack_val_len_t; - -/** Attribute value type used in GATT database */ -typedef union -{ - /** Buffer containing 32-bit or 128-bit UUID values for Service and - Characteristic declaration. - Attribute format structure: if entry is for characteristic value format, - then it has the "attribute format value" of pointer type to represent generic - structure to cater wide formats of available list of characteristic formats. */ - cy_stc_ble_gatts_att_pack_val_len_t attFormatValue; - - /** Attribute UUID value */ - uint16_t attValueUuid; - -} cy_stc_ble_gatts_att_value_t; - -/** GATT database structure used in the GATT Server */ -typedef struct -{ - /** Start Handle: Act as an index for querying BLE GATT database */ - uint16_t attHandle; - - /** UUID: 16-bit UUID type for an attribute entry. For 32-bit and - 128-bit UUIDs, the last 16 bits should be stored in this entry - that GATT DB access layer shall retrieve complete 128-bit UUID from the - cy_ble_gatts_att_generic_val_t structure. */ - uint16_t attType; - - /** The permission bits are clubbed in a 32-bit field. These - 32-bits can be grouped in four bytes. The lowest significant byte - is byte 0 (B0) and the most significant byte is byte 3 (B3). The - bytes where the permissions have been grouped is as given below. - * Attribute permissions for read (B0) - * Attribute permissions for write (B1) - * Characteristic properties (B2) - * Implementation specific permission (B3) - If permission is set to CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT, all GATT - characteristic read requests will be indicated to the application using - the CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event. - */ - uint32_t permission; - - /** Attribute end handle, indicating logical boundary of given attribute. */ - uint16_t attEndHandle; - - /** Attribute value format, it can be one of following: - * uint16_t 16bit - UUID for 16-bit service & characteristic declaration - * cy_ble_gatts_att_generic_val_t attFormatValue - Buffer containing 32-bit - or 128-bit UUID values for service & characteristic declaration - * cy_ble_gatts_att_generic_val_t attFormatValue - Buffer containing generic - char definition value, or generic descriptor values - */ - cy_stc_ble_gatts_att_value_t attValue; - - } cy_stc_ble_gatts_db_t; - -/** GATT database information parameters*/ -typedef struct -{ - /** Pointer to GATT DB */ - const cy_stc_ble_gatts_db_t * gattDbPtr; - - /** Total number of entries in GATT DB */ - uint16_t gattDbTotalEntries; - - /**Maximum characteristic value length */ - uint16_t gattDbMaxValue; - -} cy_stc_ble_gatts_db_info_t; - -/** GATT database attribute value parameters*/ -typedef struct -{ - /** handle value pair of type cy_stc_ble_gatt_handle_value_pair_t. - 'handleValuePair.attrHandle' is an input for which a value must be read/written. - 'handleValuePair.value.len' is an input parameter for the length to be read/written. - 'handleValuePair.value.val' is an input parameter for the data buffer when writing and - output parameter when reading. - 'handleValuePair.actualLen' must be ignored as it is unused */ - cy_stc_ble_gatt_handle_value_pair_t handleValuePair; - - /** Offset at which the data (length in number of bytes) is written */ - uint16_t offset; - - /** Connection Handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Attribute permissions. Allowed values are, - - CY_BLE_GATT_DB_LOCALLY_INITIATED - - CY_BLE_GATT_DB_PEER_INITIATED */ - uint8_t flags; - -} cy_stc_ble_gatts_db_attr_val_info_t; - -/** GATT database attribute enable parameters*/ -typedef struct -{ - /** Attribute handle */ - cy_ble_gatt_db_attr_handle_t attrHandle; - -} cy_stc_ble_gatts_db_attr_enable_info_t; - -/** GATT database attribute disable parameters*/ -typedef cy_stc_ble_gatts_db_attr_enable_info_t cy_stc_ble_gatts_db_attr_disable_info_t; - -/** GATT database authorize parameters*/ -typedef struct -{ - /** Setting to '0' turns off authorization on the entire GATT database and all attributes marked - as authorize will return an authorization error. - Setting this to any non-zero value will authorize the entire GATT database and all attributes - marked as authorize can be read / written based on other allowed permissions. */ - uint8_t authorize; - -} cy_stc_ble_gatts_db_authorize_info_t; - -/*************************************** -** Characteristic Descriptors definitions -***************************************/ -/** All descriptors follow the characteristic value definition entries that belong - to a logical group of characteristics shall be in following order: - 1. Characteristic Declaration - 2. Characteristic Value - 3. Characteristic Extended Property (If any) - 4. Characteristic User Description (If any) - 5. Client Characteristic Configuration (If any) - 6. Server Characteristic Configuration (If any) - 7. Characteristic Presentation Format (If any) - 8. Characteristic Aggregate Format (If any) - */ - -/** Characteristic Extended Property */ -typedef cy_stc_ble_gatts_att_value_t cy_stc_ble_char_ext_prprty_t; -/** Characteristic User Description */ -typedef cy_stc_ble_gatts_att_value_t cy_stc_ble_char_user_description_t; -/** Client Characteristic Configuration */ -typedef cy_stc_ble_gatts_att_value_t cy_stc_ble_client_char_config_t; -/** Server Characteristic Configuration */ -typedef cy_stc_ble_gatts_att_value_t cy_stc_ble_server_char_config_t; -/** Characteristic Presentation Format */ -typedef cy_stc_ble_gatts_att_value_t cy_stc_ble_char_present_fmt_t; -/** Characteristic Aggregate Format */ -typedef cy_stc_ble_gatts_att_value_t cy_stc_ble_char_aggregate_fmt_t; -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ - -/** - \addtogroup group_ble_common_api_gatt_server_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_DbRegister -***************************************************************************//** -* -* This function registers the GATT database for the GATT Server. The GATT -* database stores all the attributes used by the GATT server, along with their -* permissions. This is a blocking function. No event is generated on calling -* this function. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_info_t'. -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If the Database has zero entries or is a NULL pointer. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_DbRegister -( - cy_stc_ble_gatts_db_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_WriteAttributeValue -***************************************************************************//** -* -* This function is used to write to the value field of the specified attribute -* in the GATT database of a GATT Server. This is a blocking function. No event -* is generated on calling this function. -* -* If a peer device connected to the GATT Server initiates a write operation, -* this function is executed on the GATT Server. During such a call, the function -* checks for the attribute permissions (flags) before executing the write -* operation. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_attr_val_info_t'. -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation. -* CY_BLE_GATT_ERR_INVALID_HANDLE | 'handleValuePair.attrHandle' is not valid. -* CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED | write operation is not permitted on this attribute (Peer Initiated). -* CY_BLE_GATT_ERR_UNLIKELY_ERROR | Invalid arguments passed. -* CY_BLE_GATT_ERR_INSUFFICIENT_ENCRYPTION | Link is not encrypted (Peer Initiated). -* CY_BLE_GATT_ERR_INSUFFICIENT_ENC_KEY_SIZE | Link is encrypted with insufficient key size (Peer Initiated). -* CY_BLE_GATT_ERR_INSUFFICIENT_AUTHENTICATION | Link is un-authenticated (Peer Initiated). -* CY_BLE_GATT_ERR_INSUFFICIENT_AUTHORIZATION | Peer client is not authorized (Peer Initiated). -* CY_BLE_GATT_ERR_INVALID_OFFSET | param->offset is invalid. -* CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN | handleValuePair.value.len is invalid. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_WriteAttributeValue -( - cy_stc_ble_gatts_db_attr_val_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_ReadAttributeValue -***************************************************************************//** -* -* This function is used to read the value field of the specified attribute from -* the GATT database in a GATT Server. This is a blocking function. No event is -* generated on calling this function. -* -* A peer initiated call to this function results in the function checking for -* attribute permissions before performing this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_attr_val_info_t'. -* param-> offset: not used, to be ignored -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation. -* CY_BLE_GATT_ERR_INVALID_HANDLE | 'handleValuePair.attrHandle' is not valid. -* CY_BLE_GATT_ERR_READ_NOT_PERMITTED | Read operation is not permitted on this attribute (Peer Initiated). -* CY_BLE_GATT_ERR_UNLIKELY_ERROR | Invalid arguments passed. -* CY_BLE_GATT_ERR_INSUFFICIENT_ENCRYPTION | Link is not encrypted (Peer Initiated). -* CY_BLE_GATT_ERR_INSUFFICIENT_ENC_KEY_SIZE | Link is encrypted with insufficient key size (Peer Initiated). -* CY_BLE_GATT_ERR_INSUFFICIENT_AUTHENTICATION | Link is un-authenticated (Peer Initiated). -* CY_BLE_GATT_ERR_INSUFFICIENT_AUTHORIZATION | Peer client is not authorized (Peer Initiated). -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_ReadAttributeValue -( - cy_stc_ble_gatts_db_attr_val_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_EnableAttribute -***************************************************************************//** -* -* This function enables the attribute entry for a service or characteristic -* logical group in the GATT database registered in the BLE Stack. This is a -* blocking function. No event is generated on calling this function. -* -* This function returns an error if the attribute does not belong to any -* service or characteristic logical group. If the attribute entry is already -* enabled, then this function returns status CY_BLE_GATT_ERR_NONE. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_attr_enable_info_t'. -* param->attrHandle: Attribute handle of the registered GATT Database to enable -* particular attribute entry, of type 'cy_ble_gatt_db_attr_handle_t'. -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation. -* CY_BLE_GATT_ERR_INVALID_HANDLE | 'attrHandle' is not valid. -* CY_BLE_GATT_ERR_UNLIKELY_ERROR | NULL pointer as input parameter. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_EnableAttribute -( - cy_stc_ble_gatts_db_attr_enable_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_DisableAttribute -***************************************************************************//** -* -* This function disables the attribute entry for service or characteristic -* logical group in the GATT database registered in the BLE Stack. This is -* a blocking function. No event is generated on calling this function. -* -* This function returns error if the attribute does not belong to a service or -* a characteristic logical group. If attribute entry is already disabled then -* it returns CY_BLE_GATT_ERR_NONE as the status. All the attribute entries are -* enabled in the GATT database during stack initialization. -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_attr_disable_info_t'. -* param->attrHandle: Attribute handle of the registered GATT Database to disable -* particular attribute entry, of type 'cy_ble_gatt_db_attr_handle_t' -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation. -* CY_BLE_GATT_ERR_INVALID_HANDLE | 'attrHandle' is not valid. -* CY_BLE_GATT_ERR_UNLIKELY_ERROR | NULL pointer as input parameter. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_DisableAttribute -( - cy_stc_ble_gatts_db_attr_disable_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_DbAuthorize -***************************************************************************//** -* -* This Function sets or clears authorization permission for the GATT database -* -* \param param: Parameter is of type 'cy_stc_ble_gatts_db_authorize_info_t'. -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_GATT_ERR_NONE | On successful operation. -* CY_BLE_GATT_ERR_UNLIKELY_ERROR | If 'param' is NULL. -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATTS_DbAuthorize -( - cy_stc_ble_gatts_db_authorize_info_t * param -); - -/** @} */ - -/** \cond IGNORE */ -/****************************************************************************** -* Function Name: Cy_BLE_GATT_DbCheckPermission -***************************************************************************//** -* -* This API validates the security permission for the given attribute handle -* -* \param attrhandle: Attribute handle of type 'cy_ble_gatt_db_attr_handle_t' -* \param connHandle: Connection handle of type 'cy_stc_ble_conn_handle_t' -* \param flags: flag to identify if request is peer initiated (CY_BLE_GATT_DB_PEER_INITIATED) -* or local initiated (CY_BLE_GATT_DB_LOCALLY_INITIATED). -* -* \return -* cy_en_ble_gatt_err_code_t : Return value indicates whether the function succeeded or -* failed with GATT error codes. For details, refer to Bluetooth 4.2 spec, vol3, part F, Table 3.3 -* -******************************************************************************/ -cy_en_ble_gatt_err_code_t Cy_BLE_GATT_DbCheckPermission -( - cy_ble_gatt_db_attr_handle_t attrhandle, - cy_stc_ble_conn_handle_t * connHandle, - uint8_t flags -); - -/** \endcond */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /*CY_BLE_STACK_GATT_DB_H*/ - - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_server.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_server.h deleted file mode 100644 index 21641cadc5..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_gatt_server.h +++ /dev/null @@ -1,358 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_gatt_server.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of Generic Attribute Profile - Server Role. -* Also specified the defines, constants, and data structures required for the APIs. -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE__STACK_GATT_SERVER_H_ -#define CY_BLE__STACK_GATT_SERVER_H_ - - -/*************************************** -* Common stack includes -***************************************/ - -#include "cy_ble_stack_gatt.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* GATT Server Constants -***************************************/ -/** - \addtogroup group_ble_common_api_gatt_definitions - @{ -*/ - -/*************************************** -** Exported structures -***************************************/ -/** Notification parameter */ -typedef cy_stc_ble_gatt_write_param_t cy_stc_ble_gatts_handle_value_ntf_t; - -/** Indication parameter */ -typedef cy_stc_ble_gatt_write_param_t cy_stc_ble_gatts_handle_value_ind_t; - -/* --------------------------Structure corresponding to events-------------------- */ - -/** Prepare write request parameter received from Client */ -typedef struct -{ - /** Base address of the queue where data is queued. Queue is of type - cy_stc_ble_gatt_handle_value_offset_param_t. - Each baseAddr[currentPrepWriteReqCount-1].handleValuePair.value.val - provides the current data and baseAddr[0].handleValuePair.value.val - provides the base address of the data buffer where the full value will be stored. - The application can calculate the total length based on each each array element; - i.e., total length up current request = baseAddr[0].handleValuePair.value.len+ - ....+baseAddr[currentPrepWriteReqCount-1].handleValuePair.value.len - */ - cy_stc_ble_gatt_handle_value_offset_param_t * baseAddr; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Current count of prepare requests from remote. This parameter can be used - to access the data from 'baseAddr[]'. Array index will range from 0 to - currentPrepWriteReqCount - 1 */ - uint8_t currentPrepWriteReqCount; - - /** The application provides GATT error code for the procedure. This is an o/p parameter. */ - uint8_t gattErrorCode; - -}cy_stc_ble_gatts_prep_write_req_param_t; - -/** Execute Write result */ -typedef struct -{ - /** Base address of the queue where data is queued. Queue is of type - cy_stc_ble_gatt_handle_value_offset_param_t. - baseAddr[0].handleValuePair.value.val - provides the base address of the total data stored in the prepare write - queue internally by the stack. - The application can calculate the total length based on each each array element; - i.e., total length = baseAddr[0].handleValuePair.value.len+ - ....+baseAddr[prepWriteReqCount-1].handleValuePair.value.len - */ - cy_stc_ble_gatt_handle_value_offset_param_t *baseAddr; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Attribute Handle at which the error occurred. This is an o/p param. */ - cy_ble_gatt_db_attr_handle_t attrHandle; - - /** Total count of prepare requests from remote. This parameter can be used - to access the data from 'baseAddr[]'. The array index will range from 0 to - prepWriteReqCount - 1. */ - uint8_t prepWriteReqCount; - - /** Execute write flag received from remote */ - uint8_t execWriteFlag; - - - /** The application-provided GATT error code for the procedure. This is an o/p param. */ - uint8_t gattErrorCode; - -}cy_stc_ble_gatts_exec_write_req_t; - -/** Write command request parameter received from Client */ -typedef cy_stc_ble_gatt_write_param_t cy_stc_ble_gatts_write_cmd_req_param_t; - -/** Signed Write command request parameter received from Client */ -typedef cy_stc_ble_gatt_write_param_t cy_stc_ble_gatts_signed_write_cmd_req_param_t; - -/** Event parameters for characteristic read value access - * even generated by the BLE Stack upon an access of Characteristic value - * read for the characteristic definition that - * CY_BLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT property set. - **/ -typedef struct -{ - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - - /** Attribute Handle*/ - cy_ble_gatt_db_attr_handle_t attrHandle; - - /** Output Param: Profile/Service specific error code, - * profile or application need to change this - * to service specific error based on service/profile - * requirements. */ - cy_en_ble_gatt_err_code_t gattErrorCode; - -}cy_stc_ble_gatts_char_val_read_req_t; -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_gatt_server_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_Notification -***************************************************************************//** -* -* This function sends a notification to the peer device when the GATT Server -* is configured to notify a Characteristic Value to the GATT Client without -* expecting any Attribute Protocol layer acknowledgment that the notification -* was successfully received. This is a non-blocking function. -* -* On enabling notification successfully for a specific attribute, if the GATT server has an -* updated value to be notified to the GATT Client, it sends out a 'Handle Value -* Notification' which results in CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF event at the -* GATT Client's end. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.10 for -* more details on notifications. -* -* \param param: Pointer to a variable of type cy_stc_ble_gatts_handle_value_ntf_t. -* Where, the following needs to be set: -* param->handleValPair -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid or if 'param->handleValPair.value.len' value is greater than (Effective GATT MTU-3). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -* \note -* This operation is not permitted when the BLE Stack is busy processing previous requests. The 'CY_BLE_ERROR_INVALID_OPERATION' -* error code will be returned if the stack queue is full or for other reasons, the stack cannot process the operation. If the stack -* busy event 'CY_BLE_EVT_STACK_BUSY_STATUS' is triggered with status busy, calling this API will trigger this error code. -* For details refer 'CY_BLE_EVT_STACK_BUSY_STATUS' event. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_Notification -( - cy_stc_ble_gatts_handle_value_ntf_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_Indication -***************************************************************************//** -* -* This function sends an indication to the peer device when the GATT Server is -* configured to indicate a Characteristic Value to the GATT Client and expects -* an Attribute Protocol layer acknowledgment that the indication was -* successfully received. This is a non-blocking function. -* -* On enabling indication successfully, if the GATT server has an updated value to be -* indicated to the GATT Client, it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_GATTC_HANDLE_VALUE_IND event at the GATT Client's end. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.11 for -* more details on Indications. -* -* \param param: Pointer to a variable of type cy_stc_ble_gatts_handle_value_ind_t. -* Where, the following needs to be set: -* param->handleValPair -* param->connHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid or if 'param->handleValPair.value.len' value is greater than (Effective GATT MTU-3). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -* \note -* This operation is not permitted when BLE Stack is busy processing previous requests. The 'CY_BLE_ERROR_INVALID_OPERATION' -* error code will be returned if the stack queue is full or if, for other reasons, the stack cannot process the operation. If the stack -* busy event 'CY_BLE_EVT_STACK_BUSY_STATUS' is triggered with status busy, calling this API will trigger this error code. -* For details, refer to the 'CY_BLE_EVT_STACK_BUSY_STATUS' event. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_Indication -( - cy_stc_ble_gatts_handle_value_ind_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_ErrorRsp -***************************************************************************//** -* -* This function sends an error response to the peer device. The Error Response -* is used to state that a given request cannot be performed, and to provide the -* reason as defined in 'cy_en_ble_gatt_err_code_t'. This is a non-blocking function. -* -* \note:'Write Command' initiated by GATT Client does not generate an -* 'Error Response' from the GATT Server's end. The GATT Client gets the -* CY_BLE_EVT_GATTC_ERROR_RSP event on receiving an error response. -* -* Refer to the Bluetooth 4.1 core specification, Volume 3, Part F, section 3.4.1.1 for -* more details on Error Response operation. -* -* \param param: Pointer to a variable of type cy_stc_ble_gatt_err_param_t. -* Where, the following needs to be set: -* param->opCode -* param->connHandle -* param->attrHandle -* param->errorCode -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_ErrorRsp -( - cy_stc_ble_gatt_err_param_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_ExchangeMtuRsp -***************************************************************************//** -* -* This function sends the GATT Server's GATT MTU size to the GATT Client. This -* function must be invoked in response to an Exchange GATT MTU Request received -* from the GATT Client. The GATT Server's GATT MTU size should be greater than or -* equal to the default GATT MTU size (23 bytes). This is a non-blocking function. -* -* The peer GATT Client receives CY_BLE_EVT_GATTC_XCHNG_MTU_RSP event on executing -* this function on the GATT Server. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part G, section 4.3.1 for -* more details on exchange of GATT MTU. -* -* \param param: parameter is of type CY_BLE_GATT_XCHG_MTU_REQ_PARAM_T. -* param->mtu: Size of GATT MTU. Max GATT MTU supported by the BLE stack is 512 Bytes. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or 'connHandle' is invalid or 'mtu' value is greater than that set on calling Cy_BLE_StackInit(). -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED| Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_ExchangeMtuRsp -( - cy_stc_ble_gatt_xchg_mtu_param_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GATTS_WriteRsp -***************************************************************************//** -* -* This function sends a Write Response from a GATT Server to the GATT Client. -* This is a non-blocking function. This function must be invoked in -* response to a valid Write Request event from the GATT Client -* (CY_BLE_EVT_GATTS_WRITE_REQ) to acknowledge that the attribute has been -* successfully written. -* -* The Write Response must be sent after the attribute value is written or -* saved by the GATT Server. Write Response results in CY_BLE_EVT_GATTC_WRITE_RSP -* event at the GATT Client's end. -* -* \param connHandle: Connection handle to identify the peer GATT entity, of type - cy_stc_ble_conn_handle_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'connHandle' is invalid. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GATTS_WriteRsp -( - cy_stc_ble_conn_handle_t connHandle -); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/** @} */ -#endif /*CY_BLE__STACK_GATT_SERVER_H_*/ - - - /*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_host_error.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_host_error.h deleted file mode 100644 index 6555a74794..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_host_error.h +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_host_error.h -* \version 2.0 -* -* \brief -* This file contains all the spec defined error code in Core Spec 5.0, Vol2, Part D -* -* Related Document: -* BLE Standard Spec - CoreV5.0 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_STACK_HOST_ERROR_H_ -#define CY_BLE_STACK_HOST_ERROR_H_ - -/** - \addtogroup group_ble_common_macros_error - @{ -*/ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -** Constants -***************************************/ -/* HCI Status error code */ - -/** Success */ -#define CY_BLE_HCI_SUCCESS (0x00u) - -/** Unknown HCI Command */ -#define CY_BLE_HCI_ERROR_UNKNOWN_HCI_COMMAND (0x01u) - -/** Unknown Connection Identifier */ -#define CY_BLE_HCI_ERROR_NO_CONNECTION (0x02u) - -/** Hardware Failure */ -#define CY_BLE_HCI_ERROR_HARDWARE_FAILURE (0x03u) - -/** \cond IGNORE */ - -/** Page Timeout */ -#define CY_BLE_HCI_ERROR_PAGE_TIMEOUT (0x04u) - -/** Authentication Failure */ -#define CY_BLE_HCI_ERROR_AUTHENTICATION_FAILURE (0x05u) - -/** PIN or Key Missing */ -#define CY_BLE_HCI_ERROR_KEY_MISSING (0x06u) - -/** \endcond */ - -/** Memory Capacity Exceeded */ -#define CY_BLE_HCI_ERROR_MEMORY_FULL (0x07u) - -/** Connection Timeout */ -#define CY_BLE_HCI_ERROR_CONNECTION_TIMEOUT (0x08u) - -/** Connection Limit Exceeded*/ -#define CY_BLE_HCI_ERROR_MAX_NUMBER_OF_CONNECTIONS (0x09u) - -/** \cond IGNORE */ - -/** Synchronous Connection Limit To A Device Exceeded */ -#define CY_BLE_HCI_ERROR_MAX_NUMBER_OF_SCO_CONNECTIONS (0x0Au) - -/** \endcond */ - -/** ACL Connection Already Exists */ -#define CY_BLE_HCI_ERROR_ACL_CONNECTION_ALREADY_EXISTS (0x0Bu) - -/** Command Disallowed */ -#define CY_BLE_HCI_ERROR_COMMAND_DISALLOWED (0x0Cu) - -/** \cond IGNORE */ - -/** Connection Rejected due to Limited Resources */ -#define CY_BLE_HCI_ERROR_HOST_REJECTED_LIMITED_RESOURCES (0x0Du) - -/** Connection Rejected Due To Security Reasons */ -#define CY_BLE_HCI_ERROR_HOST_REJECTED_SECURITY_REASONS (0x0Eu) - -/** Connection Rejected due to Unacceptable BD_ADDR */ -#define CY_BLE_HCI_ERROR_HOST_REJECTED_PERSONAL_DEVICE (0x0Fu) - -/** Connection Accept Timeout Exceeded */ -#define CY_BLE_HCI_ERROR_HOST_TIMEOUT (0x10u) - -/** Unsupported Feature or Parameter Value */ -#define CY_BLE_HCI_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER (0x11u) - -/** \endcond */ - -/** Invalid HCI Command Parameters */ -#define CY_BLE_HCI_ERROR_INVALID_HCI_COMMAND_PARAMETERS (0x12u) - -/** Remote User Terminated Connection */ -#define CY_BLE_HCI_ERROR_OTHER_END_TERMINATED_USER (0x13u) - -/** Remote Device Terminated Connection due to Low Resources */ -#define CY_BLE_HCI_ERROR_OTHER_END_TERMINATED_LOW_RESOURCES (0x14u) - -/** Remote Device Terminated Connection due to Power Off */ -#define CY_BLE_HCI_ERROR_OTHER_END_TERMINATED_POWER_OFF (0x15u) - -/** Connection Terminated By Local Host */ -#define CY_BLE_HCI_ERROR_CONNECTION_TERMINATED_BY_LOCAL_HOST (0x16u) - -/** Repeated Attempts */ -#define CY_BLE_HCI_ERROR_REPEATED_ATTEMPTS (0x17u) - -/** \cond IGNORE */ - -/** Pairing Not Allowed */ -#define CY_BLE_HCI_ERROR_PAIRING_NOT_ALLOWED (0x18u) - -/** Unknown LMP PDU */ -#define CY_BLE_HCI_ERROR_UNKNOWN_LMP_PDU (0x19u) - -/** Unsupported Remote Feature / Unsupported LMP Feature */ -#define CY_BLE_HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE (0x1Au) - -/** SCO Offset Rejected */ -#define CY_BLE_HCI_ERROR_SCO_OFFSET_REJECTED (0x1Bu) - -/** SCO Interval Rejected */ -#define CY_BLE_HCI_ERROR_SCO_INTERVAL_REJECTED (0x1Cu) - -/** SCO Air Mode Rejected */ -#define CY_BLE_HCI_ERROR_SCO_AIR_MODE_REJECTED (0x1Du) - -/** Invalid LMP Parameters / Invalid LL Parameters */ -#define CY_BLE_HCI_ERROR_INVALID_LMP_PARAMETERS (0x1Eu) - -/** Unspecified Error */ -#define CY_BLE_HCI_ERROR_UNSPECIFIED_ERROR (0x1Fu) - -/** Unsupported LMP Parameter Value / Unsupported LL Parameter Value */ -#define CY_BLE_HCI_ERROR_UNSUPPORTED_LMP_PARAMETER_VALUE (0x20u) - -/** Role Change Not Allowed */ -#define CY_BLE_HCI_ERROR_ROLE_CHANGE_NOT_ALLOWED (0x21u) - -/** LMP Response Timeout / LL Response Timeout */ -#define CY_BLE_HCI_ERROR_LMP_RESPONSE_TIMEOUT (0x22u) - -/** LMP Error Transaction Collision / LL Procedure Collision */ -#define CY_BLE_HCI_ERROR_LMP_ERROR_TRANSACTION_COLLISION (0x23u) - -/** LMP PDU Not Allowed */ -#define CY_BLE_HCI_ERROR_LMP_PDU_NOT_ALLOWED (0x24u) - -/** Encryption Mode Not Acceptable */ -#define CY_BLE_HCI_ERROR_ENCRYPTION_MODE_NOT_ACCEPTABLE (0x25u) - -/** Link Key cannot be Changed */ -#define CY_BLE_HCI_ERROR_LINK_KEY_CANNOT_BE_USED (0x26u) - -/** Requested QoS Not Supported */ -#define CY_BLE_HCI_ERROR_QOS_IS_NOT_SUPPORTED (0x27u) - -/** Instant Passed */ -#define CY_BLE_HCI_ERROR_INSTANT_PASSED (0x28u) - -/** Pairing With Unit Key Not Supported */ -#define CY_BLE_HCI_ERROR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED (0x29u) - -/** Different Transaction Collision */ -#define CY_BLE_HCI_ERROR_DIFFERENT_TRANSACTION_COLLISION (0x2Au) - -/* 0x2B Reserved for Future Use [E6305] */ - -/** QoS Unacceptable Parameter */ -#define CY_BLE_HCI_ERROR_QOS_UNACCEPTABLE_PARAMETER (0x2Cu) - -/** QoS Rejected */ -#define CY_BLE_HCI_ERROR_QOS_REJECTED (0x2Du) - -/** Channel Classification Not Supported */ -#define CY_BLE_HCI_ERROR_CHANNEL_CLASSIFICATION_NOT_SUPPORTED (0x2Eu) - -/** Insufficient Security */ -#define CY_BLE_HCI_ERROR_INSUFFICIENT_SECURITY (0x2Fu) - -/** Parameter Out Of Mandatory Range */ -#define CY_BLE_HCI_ERROR_PARAMETER_OUT_OF_MANDATORY_RANGE (0x30u) - -/* 0x31 Reserved for Future Use */ - -/** Role Switch Pending */ -#define CY_BLE_HCI_ERROR_ROLE_SWITCH_PENDING (0x32u) - -/* 0x33 Reserved for Future Use */ - -/** Reserved Slot Violation */ -#define CY_BLE_HCI_ERROR_RESERVED_SLOT_VIOLATION (0x34u) - -/** Role Switch Failed */ -#define CY_BLE_HCI_ERROR_ROLE_SWITCH_FAILED (0x35u) - -/** Extended Inquiry Response Too Large */ -#define CY_BLE_HCI_ERROR_ENTENDED_INQUIRY_RESPONSE_TOO_LARGE (0x36u) - -/** Secure Simple Pairing Not Supported By Host */ -#define CY_BLE_HCI_ERROR_SECURE_SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST (0x37u) - -/** Host Busy - Pairing */ -#define CY_BLE_HCI_ERROR_HOST_BUSY_PAIRING (0x38u) - -/** Connection Rejected due to No Suitable Channel Found */ -#define CY_BLE_HCI_ERROR_CONNECTION_REJETED_DUE_TO_NO_SUITABLE_SCHANNEL_FOUND (0x39u) - -/** \endcond */ - -/** Controller Busy */ -#define CY_BLE_HCI_ERROR_CONTROLLER_BUSY (0x3Au) - -/** Unacceptable Connection Parameters */ -#define CY_BLE_HCI_ERROR_UNACCEPTEBALE_CONNECTION_INTERVAL (0x3Bu) - -/** Directed Advertising Timeout */ -#define CY_BLE_HCI_ERROR_DIRECTED_ADVERTISING_TIMEOUT (0x3Cu) - -/** Connection Terminated due to MIC Failure */ -#define CY_BLE_HCI_ERROR_CONNECTION_TREMINATED_DUE_TO_MIC_FAILURE (0x3Du) - -/** Connection Failed to be Established */ -#define CY_BLE_HCI_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED (0x3Eu) - -/** MAC Connection Failed */ -#define CY_BLE_HCI_ERROR_MAC_CONNECTION_FAILED (0x3Fu) - -/** Coarse Clock Adjustment Rejected but Will Try to Adjust Using Clock Dragging */ -#define CY_BLE_HCI_ERROR_COARSE_CLK_ADJUSTMENT (0x40u) - -/** Type0 Submap Not Defined */ -#define CY_BLE_HCI_ERROR_TYPE0_SUBMAP_NOT_DEFINED (0x41u) - -/** Unknown Advertising Identifier */ -#define CY_BLE_HCI_ERROR_UNKNOWN_ADV_IDENTIFIER (0x42u) - -/** Limit Reached */ -#define CY_BLE_HCI_ERROR_LIMIT_REACHED (0x43u) - -/** Operation Cancelled by Host */ -#define CY_BLE_HCI_ERROR_OPERATION_CANCELLED_BY_HOST (0x44u) - - -/* Hardware Error event - Error Codes */ - -/** HCI transport sync lost error */ -#define CY_BLE_HW_ERR_SYNC_LOST 0x01 - -/** HCI transport unknown pkt */ -#define CY_BLE_HW_ERR_UNKNOWN_PKT 0x02 - -/** HCI transport pkt length exceeded */ -#define CY_BLE_HW_ERR_LEN_EXCEEDED 0x03 - -/** HCI transport no cmd pkt buffer available */ -#define CY_BLE_HW_ERR_CMD_NO_BUFFER 0X04 - -/** HCI transport no acl pkt buffer available */ -#define CY_BLE_HW_ERR_ACL_NO_BUFFER 0X05 - -/** HCI transport no sync pkt buffer available */ -#define CY_BLE_HW_ERR_SYNC_NO_BUFFER 0X06 - -/** HCI transport cmd pkt length exceeded */ -#define CY_BLE_HW_ERR_CMD_LEN_EXCEEDED 0X07 - -/** HCI transport acl pkt length exceeded */ -#define CY_BLE_HW_ERR_ACL_LEN_EXCEEDED 0X08 - -/** HCI transport sync pkt length exceeded */ -#define CY_BLE_HW_ERR_SYNC_LEN_EXCEEDED 0X09 - -/** HCI transport wrong parameter for acl pkt */ -#define CY_BLE_HW_ERR_WRNG_ACL_DATA_PARAM 0x0A - -/** HCI transport wrong parameter for sync pkt */ -#define CY_BLE_HW_ERR_WRNG_SYNC_DATA_PARAM 0X0B - -/** HW init failure */ -#define CY_BLE_HW_ERR_HW_INIT_FAILURE 0x0C - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -/** @} */ - -#endif /* CY_BLE_STACK_HOST_ERROR_H_ */ - diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_host_main.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_host_main.h deleted file mode 100644 index 07a2572811..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_host_main.h +++ /dev/null @@ -1,2272 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_host_main.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs other than those covered by -* GAP, GATT, and L2CAP specific APIs. Also specified are the defines, constants, -* and data structures required for the APIs. -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_STACK_HOST_MAIN_H_ -#define CY_BLE_STACK_HOST_MAIN_H_ - - -/*************************************** -* Common stack includes -***************************************/ -#include "BLE_config.h" -#include "cy_ble_stack.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -** Constants -***************************************/ -/** Bluetooth Stack busy status */ -#define CY_BLE_STACK_STATE_BUSY (0x01u) /**< stack busy status */ -#define CY_BLE_STACK_STATE_FREE (0x00u) /**< stack free status */ - -/*************************************** -** Memory pool configuration data defines -***************************************/ -/** Maximum number of Connections */ -#define CY_BLE_MAX_CONNECTION_INSTANCES (0x04u) - -/** Size of the heap when GATT MTU, L2CAP MTU, and MPS sizes are specified as 23 Bytes */ -/** An extra 256 bytes is added as we allocate eight chunks of 32 bytes in the buffer pool and - 64 u bytes is the overhead required by mint buf management to store each extra chunk ( 8 chunks * 8 bytes overhead). - 4 bytes of default memory for AES engine, 40u bytes for SMP-AES engine */ -#define CY_BLE_DEFAULT_HOST_RAM_SIZE (16u + 1024u + 824u + 120u + 256u + 64u +4u +40u) - -/** L2CAP Header size */ -#define CY_BLE_L2CAP_HDR_SZ (0x04u) - -/** Buffer size needed for L2cap PSM */ -#define CY_BLE_L2CAP_PSM_SIZE (0x28u) -/** Buffer size needed for L2cap CBFC channels */ -#define CY_BLE_L2CAP_CBFC_CHANNEL_SIZE (0x20u) - -/** Minimum stack queue depth requirement per connection */ -/** The application can choose to give higher queue depth for better throughput. */ -#define CY_BLE_L2CAP_STACK_Q_DEPTH_PER_CONN (0x06u) -/** - * L2cap Queue element size specifies the size of single element to hold L2CAP data. - * The application must provide memory based on the number of queue elements required per connection. - * Ex: if the application needs a stack queue size of five elements per connection and supports four connections, - * then the application must provide memory as per the following calculation - * Memory = CY_BLE_L2CAP_QUEUE_ELEMENT_SIZE * CY_BLE_L2CAP_STACK_Q_DEPTH_PER_CONN * 4; - */ -#define CY_BLE_L2CAP_QUEUE_ELEMENT_SIZE (0x18u) - -/** - * L2cap per connection heap requirement. This memory includes memory for L2cap per connection context alone - */ -#define CY_BLE_RAM_SIZE_L2CAP_SINGLE_CONN (0x90u) - -/** - * HCI per connecton heap requirement . This memory include memory for Hci remote device structure(8 bytes) and hci command queue - * with depth of 6 per connection(0x30 bytes). - */ -#define CY_BLE_RAM_SIZE_HCI_SINGLE_CONN (0x38u) - - /** - * GAP module per connection heap requirement - */ -#define CY_BLE_RAM_SIZE_GAP_SINGLE_CONN (0x04u) - - /** - * GATT and ATT module per connection heap requirement - */ -#define CY_BLE_RAM_SIZE_GATT_SINGLE_CONN (0x104u) - - /** - * AES module per connection heap requirement - */ -#define CY_BLE_RAM_SIZE_AES_SINGLE_CONN (0x08u) - - /** - * SMP module per connection heap requirement includes memory for SMP Context and - * SMP platform context - */ -#define CY_BLE_RAM_SIZE_SMP_SINGLE_CONN (0x132u) - -/** - * Device queue heap requirement per connection. This requirement includes Device Queue and Device queue extension RPA - */ - #define CY_BLE_RAM_SIZE_DEVICE_Q_SINGLE_CONN (CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE + CY_BLE_STACK_DEVICE_Q_EXTN_RPA_SIZE ) - -/** - * Host per connection heap requirement . Application needs to provide memory as per following calculation - * = (CY_BLE_HOST_PER_CONN_HEAP_REQ * CY_BLE_MAX_CONNECTION_INSTANCES) - */ -#define CY_BLE_RAM_SIZE_HOST_SINGLE_CONN (CY_BLE_RAM_SIZE_HCI_SINGLE_CONN \ - + CY_BLE_RAM_SIZE_L2CAP_SINGLE_CONN \ - + CY_BLE_RAM_SIZE_GAP_SINGLE_CONN \ - + CY_BLE_RAM_SIZE_GATT_SINGLE_CONN \ - + CY_BLE_RAM_SIZE_AES_SINGLE_CONN \ - + CY_BLE_RAM_SIZE_SMP_SINGLE_CONN \ - + CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE \ - + CY_BLE_RAM_SIZE_DEVICE_Q_SINGLE_CONN) - -/** Size of the heap required for Secure connection feature - * This includes memory for SMP FSM, SMP Crypto tool box, and ECC - */ -#define CY_BLE_RAM_SIZE_SECURE_SINGLE_CONN (0x3B0u) /**< SC single connection */ -/** SC multiconnection */ -#define CY_BLE_RAM_SIZE_SECURE_CONNECTIONS (CY_BLE_MAX_CONNECTION_INSTANCES * CY_BLE_RAM_SIZE_SECURE_SINGLE_CONN) - -/** Data Buffer Pool identifiers to support configurable parameters for L2CAP and - * GATT in the BLE Stack - * These data buffer pools must be configured during BLE Stack - * initialization. */ - -/** Data Buffer index for ATT/GATT Configured MTU Size */ -#define CY_BLE_STACK_APP_POOL_1_SZ (0x00u) - -/** Data Buffer index for L2CAP configuration for number of PSM Channels - * */ -#define CY_BLE_STACK_APP_POOL_2_SZ (0x01u) - -/** Data Buffer index for L2CAP configuration for number of CBFC Channels - * */ -#define CY_BLE_STACK_APP_POOL_3_SZ (0x02u) - -/** Data Buffer index for L2CAP configured MTU Size */ -#define CY_BLE_STACK_APP_POOL_4_SZ (0x03u) - -/** Maximum Application Pool */ -#define CY_BLE_STACK_APP_MIN_POOL (CY_BLE_STACK_APP_POOL_4_SZ + 1u) - -/** GATT minimum attribute length */ -#define CY_BLE_GATT_MAX_ATTR_LEN_MIN_VAL (0x00u) - -/** GATT minimum attribute length buffers*/ -#define CY_BLE_GATT_MIN_NO_OF_ATT_MTU_BUFF (0x03u) - -/** Max attribute size can be of 0xFFFF but the Stack has a limitation - * on buffer creation as it requires an additional eight bytes and - * L2CAP header size (four bytes) - * */ -#define CY_BLE_GATT_MAX_ATTR_LEN_MAX_VAL (0xFFD0u) - -/** L2CAP MTU minimum value */ -#define CY_BLE_L2CAP_MTU_MIN_VALUE (0x17u) - -/** Max L2CAP MTU or MPS size can be of 0xFFFF, but the Stack has a limitation - * on buffer creation as it requires an additional eight bytes and - * L2CAP header size (four bytes) - * */ -#define CY_BLE_L2CAP_MTU_MAX_VALUE (0xFFD0u) - -/** L2CAP MPS minimum value */ -#define CY_BLE_L2CAP_MPS_MIN_VALUE CY_BLE_L2CAP_MTU_MIN_VALUE - -/** L2CAP MPS maximum value */ -#define CY_BLE_L2CAP_MPS_MAX_VALUE CY_BLE_L2CAP_MTU_MAX_VALUE - -/** Default Bonded device size */ -#define CY_BLE_GAP_DEFAULT_BONDED_DEVICE_SIZE (0x10u) - -/** Size of single bonded device entry*/ -#define CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE (0xA8u) - -/** Size of internal device queue */ - -#define CY_BLE_STACK_DEVICE_Q_EXTN_RPA_SIZE (0x1Cu) - -/** Size of internal device queue */ - -#define CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE (0x10u) - -/** Size of the checksum to be stored in Flash memory */ -#define CY_BLE_STACK_CHECKSUM_SIZE (0x2u) - -/** Flash size is configurable by component; configuration is mentioned below. - * \#define CY_BLE_STACK_FLASH_STORAGE_SIZE CY_BLE_STACK_CHECKSUM_SIZE + (total memory required for - * flash storage based on below calculation) - * - * Bonded device list memory computation - * CY_BLE_GAP_DEFAULT_BONDED_DEVICE_SIZE: - * It is a user-configured value for the size of bondlist using BLE PDL - * Memory required = - *((CY_BLE_STACK_ONE_BONDED_DEVICE_SIZE * User configured bondlist size) - * + (CY_BLE_STACK_ONE_DEVICE_Q_ENTITY_SIZE * User configured bondlist size)) - * - * Whitelist list memory computation - * CY_BLE_MAX_WHITELIST_LIST_SZ: - * It is a user-configured value for the size of whitelist using the BLE PDL. - * Range: 1 to 16. - * Memory required = - * (((CY_BLE_LL_ONE_WHITELIST_HEAP_REQ * CY_BLE_MAX_WHITELIST_LIST_SZ) + - * CY_BLE_LL_WHITELIST_RETENTION_HEAP_REQ) - * - * Resolving list memory computation - * CY_BLE_MAX_RESOLVABLE_DEVICES: - * It is a user-configured value for the size of resolving list using the BLE PDL. - * Range: 1 to 16, 0 if Privacy 1.2 feature is not used. - * Memory required = - * (((CY_BLE_LL_PRIVACY_HEAP_REQ * CY_BLE_MAX_RESOLVABLE_DEVICES) + - * CY_BLE_LL_PRIVACY_RETENTION_HEAP_REQ) - */ - -/** Encryption information */ -/** encryption data size */ -#define CY_BLE_ENCRYPTION_DATA_SIZE (0x10u) -/** encryption key size */ -#define CY_BLE_ENCRYPTION_KEY_SIZE (0x10u) -/** encryption nonce size */ -#define CY_BLE_ENCRYPTION_NONCE_SIZE (0x0Du) -/** BLE MIC size */ -#define CY_BLE_MIC_SIZE (0x04u) - -/** SMP Key size */ -#define CY_BLE_IRK_SIZE (0x10u) - -/** Bitmask values for Flash write */ -#define CY_BLE_PERSISTENT_BOND_LIST_BITMASK (0x01u) /**< Bondlist mask */ -#define CY_BLE_PERSISTENT_RPA_LIST_BITMASK (0x02u) /**< Resolvablelist mask */ -#define CY_BLE_PERSISTENT_WHITELIST_BITMASK (0x04u) /**< whiteList mask */ - -/** Application to provide or free memory */ -#define CY_BLE_ALLOC_MEMORY (0x00u) /**< Allocate memory */ -#define CY_BLE_FREE_MEMORY (0x01u) /**< Free memory */ - -/*************************************** -** Enumerated Types -***************************************/ -/** - \addtogroup group_ble_common_api_definitions - @{ -*/ - -/** Timeout happened reason due to stack started times or application stated timers. - It is the application's responsibility to disconnect or keep the channel on depending on type of timeout; - i.e., GATT procedure timeout: the application may choose to disconnect.*/ -typedef enum -{ - /** Advertisement time set by application has expired */ - CY_BLE_GAP_ADV_TO = 0x01u, - - /** Scan time set by application has expired */ - CY_BLE_GAP_SCAN_TO, - - /** GATT procedure timeout */ - CY_BLE_GATT_RSP_TO, - - /** Application procedure timeout */ - CY_BLE_GENERIC_APP_TO - -}cy_en_ble_to_reason_code_t; - -/** BLE Stack memory request type */ -typedef enum -{ - /** Memory requested for prepare write request */ - CY_BLE_PREPARED_WRITE_REQUEST = 0x00u, - - /** Invalid request */ - CY_BLE_INVALID_REQUEST - -}cy_en_ble_protocol_req_t; - -/** Phy used for the connection */ -typedef enum -{ - /** The transmitter PHY for the connection is LE 1M */ - CY_BLE_PHY_MASK_LE_1M = 0x01u, - - /** The transmitter PHY for the connection is LE 2M */ - CY_BLE_PHY_MASK_LE_2M, - - /** The transmitter PHY for the connection is LE Coded */ - CY_BLE_PHY_MASK_LE_CODED - -}cy_en_ble_phy_mask_t; - - -/** PHY preference masks used for Cy_BLE_SetPhy API. */ -typedef enum -{ - /** All PHY settings are preferred by the host */ - CY_BLE_PHY_NO_PREF_MASK_NONE = 0x00u, - - /** Host has no preference for TX PHY */ - CY_BLE_PHY_NO_PREF_MASK_TX, - - /** Host has no preference for RX PHY */ - CY_BLE_PHY_NO_PREF_MASK_RX, - - /** Host has no preference for both TX & RX PHY */ - CY_BLE_PHY_NO_PREF_MASK_BOTH_TX_RX - -}cy_en_ble_phy_no_pref_mask_t; - - -/** Privacy modes used for Cy_BLE_SetPrivacyMode API. */ -typedef enum -{ - /* Network privacy mode */ - CY_BLE_PRIVACY_MODE_NETWORK = 0x00u, - /* Device privacy mode */ - CY_BLE_PRIVACY_MODE_DEVICE, -}cy_en_ble_privacy_mode_t; - - - -/*************************************** -** Exported structures and unions -***************************************/ - -/** callback function prototype to receive DTM packet from Controller */ -typedef uint16_t (*cy_ble_hci_rx_cb_t)(uint8_t type, uint8_t * packet, uint8_t length); - - -/** Bluetooth Device Addresses */ -typedef struct -{ - /** Public Bluetooth device address of size 6 bytes */ - uint8_t *publicBdAddr; - - /** Private Bluetooth device address of size 6 bytes */ - uint8_t *privateBdAddr; -}cy_stc_ble_bd_addrs_t; - -/** Connection Handle */ -typedef struct -{ - /** Identifies the peer device(s) bonded or in current connection. The Stack supports - CY_BLE_GAP_MAX_BONDED_DEVICE+CY_BLE_MAX_CONNECTION_INSTANCES devices. - first device connected is assigned a value (CY_BLE_GAP_MAX_BONDED_DEVICE - +CY_BLE_MAX_CONNECTION_INSTANCES)-1. If one device is present in the bonded list, - then the current device will be assigned the value - (CY_BLE_GAP_MAX_BONDED_DEVICE+CY_BLE_MAX_CONNECTION_INSTANCES)-2, - else (CY_BLE_GAP_MAX_BONDED_DEVICE+CY_BLE_MAX_CONNECTION_INSTANCES)-1. - */ - uint8_t bdHandle; - - /** Identifies the active ATT connection Instance. - */ - uint8_t attId; - -}cy_stc_ble_conn_handle_t; - -/** Store BLE Application Data parameter into flash */ -typedef struct -{ - /** BIT field to specify the type of list to be stored in flash - * CY_BLE_PERSISTENT_BOND_LIST_BITMASK - B0 Bond List Data - * CY_BLE_PERSISTENT_RPA_LIST_BITMASK - B1 Resolving List Data - * CY_BLE_PERSISTENT_WHITELIST_BITMASK - B2 Whitelist Data - * Bit B3 is internally used by the stack and other bits are reserved for - * future use. - */ - uint8_t bitField; -} cy_stc_ble_stack_flash_param_t; - -/** Timer parameter */ -typedef struct -{ - /** Handle of the started timer */ - uint8_t timerHandle; - - /** Timeout for which timer to be started - * IF MSBit of timeout == 1, then resolution is in milliseconds, - * ELSE resolution is seconds. - * This takes the assumption that no one would call timeout of, - * say, 32000 seconds. - */ - uint8_t timeout; - -} cy_stc_ble_timer_info_t; - -/** - * Configuration structure for enabling selective features - * and passing associated parameters in BLE Stack. - */ -typedef struct -{ - /** Seed for DRBG */ - uint32_t seed; - -}cy_stc_ble_stack_random_num_param_t; - -/** Tx power level configuration parameters */ -typedef struct -{ - /** Channel group ID for which power level is to be read/written */ - cy_en_ble_bless_phy_ch_grp_id_t bleSsChId; - - /** Device handle for which power level is to be read/written */ - uint8_t bdHandle; - -} cy_stc_ble_tx_pwr_config_param_t; - -/** Tx power level parameter */ -typedef struct -{ - /** Power level */ - cy_en_ble_bless_pwr_lvl_t blePwrLevel; - - /** Tx power level configuration parameters */ - cy_stc_ble_tx_pwr_config_param_t pwrConfigParam; - -} cy_stc_ble_tx_pwr_lvl_info_t; - -/** RSSI parameter */ -typedef struct -{ - /** The RSSI value - Range is -85 <= N <= 5 in dBm */ - int8_t rssi; - - /** Peer device handle */ - uint8_t bdHandle; - -}cy_stc_ble_rssi_info_t; - -/** AES encrypt information */ -typedef struct -{ - /** data containing plain text (128-bit) that is to be encrypted */ - uint8_t plainData[CY_BLE_ENCRYPTION_DATA_SIZE]; - - /** Pointer to the AES Key (128-bit) that is to be used for AES encryption*/ - uint8_t aesKey[CY_BLE_ENCRYPTION_KEY_SIZE]; - -}cy_stc_ble_aes_encrypt_info_t; - -/** AES CCM encrypt information */ -typedef struct -{ - /** array of bytes holding the key */ - uint8_t key[CY_BLE_ENCRYPTION_KEY_SIZE]; - - /** array of bytes */ - uint8_t nonce[CY_BLE_ENCRYPTION_NONCE_SIZE]; - - /** Pointer to an array of bytes to be encrypted. The size of the array should be equal to - the value of the 'length' parameter*/ - uint8_t *data; - - /** length of data */ - uint8_t length; - -}cy_stc_ble_aes_ccm_encrypt_info_t; - -/** AES CCM decrypt information */ -typedef struct -{ - /** array of bytes holding the key */ - uint8_t key[CY_BLE_ENCRYPTION_KEY_SIZE]; - - /** array of bytes */ - uint8_t nonce[CY_BLE_ENCRYPTION_NONCE_SIZE]; - - /** Pointer to an array of bytes to be encrypted. Size of the array should be equal to - the value of the 'length' parameter*/ - uint8_t * data; - - /** Pointer to an array of bytes (four Bytes) to provide the MIC value - generated during encryption */ - uint8_t * mic; - - /** length of data */ - uint8_t length; - -}cy_stc_ble_aes_ccm_decrypt_info_t; - -/** authentication payload information */ -typedef struct -{ - /** authentication timeout value */ - uint16_t authPayloadTimeout; - - /** peer device handle */ - uint8_t bdHandle; - -}cy_stc_ble_auth_payload_info_t; - -/** Slave Latency Parameters */ -typedef struct -{ - /** Set or reset the force quick transmit configuration in the BLE Stack. - '1': Set the quick transmit behavior. It gets set immediately and disables - over the air slave latency. This quick transmit setting remains true until - the application gives control to the BLE Stack for controlling the quick transmit bit. - '0': Reset the force quick transmit behavior in BLESS to allow the BLE Stack to control - quick transmit behavior when slave latency is applied. */ - uint8_t setForceQuickTransmit; - - /** remote device identifier */ - uint8_t bdHandle; - -}cy_stc_ble_slave_latency_info_t; - -/** DLE Set Data Length parameter */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** The maximum number of payload octets in a Link Layer Data Channel - * PDU that the local Controller will send on the current connection. - */ - uint16_t connMaxTxOctets; - - /** The maximum time that the local Controller will take to send a Link - * Layer Data Channel PDU on the current connection. - */ - uint16_t connMaxTxTime; - - /** The maximum number of payload octets in a Link Layer Data Channel - * PDU that the local Controller will receive on the current connection. - */ - uint16_t connMaxRxOctets; - - /** The maximum time that the local Controller will take to receive a Link - * Layer Data Channel PDU on the current connection. - */ - uint16_t connMaxRxTime; - -}cy_stc_ble_set_data_length_info_t; - -/** DLE Suggested Data Length parameter */ -typedef struct -{ - /** Controller's maximum transmitted number of payload - * octets to be used for new connections. - */ - uint16_t suggestedTxOctets; - - /** Controller's maximum packet transmission time to be - * used for new connections. - */ - uint16_t suggestedTxTime; - -}cy_stc_ble_suggested_data_length_info_t; - -/** Channel Map Parameters Information */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** This parameter contains five octet byte stream (Least Significant - Byte having the bit fields 0 to 7, most significant byte having - the bit fields 32 to 36). The nth such field (in the range 0 to - 36) contains the value for the link layer channel index n. - Allowed values and their interpretation are, - * Channel 'n' is bad = 0x00u - * Channel 'n' is unknown = 0x01u - The most significant bits (37 to 39) are reserved and will be - set to 0. At least one channel will be marked as unknown. - For example- - expected pattern = XX XX XX XX 1F - not expected = XX XX XX XX 10, XX XX XX XX 2f - MSB 3 bits should be not set. (1F is most significant byte in this case) */ - uint8_t * channelMap; - -}cy_stc_ble_channel_map_info_t; - -/** Resolving list information of one device */ -typedef struct -{ - /** Peer IRK */ - uint8_t peerIrk[CY_BLE_IRK_SIZE]; - - /** Local IRK */ - uint8_t localIrk[CY_BLE_IRK_SIZE]; - - /** Peer Identity device address */ - uint8_t bdAddr[CY_BLE_BD_ADDR_SIZE]; - - /** Peer Identity addr type */ - uint8_t type; /*public = 0, Random = 1*/ - -}cy_stc_ble_resolving_device_info_t; - -/** Configuration Structure for Set Privacy Mode */ -typedef struct -{ - /** Peer Identity device address */ - uint8_t bdAddr[CY_BLE_BD_ADDR_SIZE]; - - /** Peer Identity addr type */ - uint8_t type; /*public = 0, Random = 1*/ - - /** Privacy Mode */ - cy_en_ble_privacy_mode_t privacyMode; - -}cy_stc_ble_privacy_mode_info_t; - - -/** Random number generated from the Stack */ -typedef struct -{ - /** public = 0, Random = 1 */ - uint8_t type; - - /** Bluetooth device address */ - uint8_t bdAddr[CY_BLE_BD_ADDR_SIZE]; - -}cy_stc_ble_peer_id_addr_t; - -/** Random number generated from the Stack */ -typedef struct -{ - /** standard HCI command/data packet */ - uint8_t * data; - - /** length of data */ - uint16_t dataLength; - - /** HCI packet type*/ - uint8_t packetType; - -}cy_stc_ble_hci_tx_packet_info_t; - -/** Set Phy parameter */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** Host preference for PHY setting. Non preferred PHY settings are ignored by the controller */ - cy_en_ble_phy_no_pref_mask_t allPhyMask; - - /** The transmitter PHY for the connection */ - cy_en_ble_phy_mask_t txPhyMask; - - /** The receiver PHY for the connection */ - cy_en_ble_phy_mask_t rxPhyMask; - - /** Parameter to specify coding preference*/ - uint16_t phyOption; - -}cy_stc_ble_set_phy_info_t; - -/** Set Default Phy parameter */ -typedef struct -{ - /** Host preference for PHY setting. Non preferred PHY settings are ignored by the controller */ - cy_en_ble_phy_no_pref_mask_t allPhyMask; - - /** The transmitter PHY for the connection */ - cy_en_ble_phy_mask_t txPhyMask; - - /** The receiver PHY for the connection */ - cy_en_ble_phy_mask_t rxPhyMask; - -}cy_stc_ble_set_suggested_phy_info_t; - -/* --------------------------Structure corresponding to events-------------------- */ - -/** Local suggested or Max 'tx octets' and 'tx time' */ -typedef struct -{ - /** Controller's maximum transmitted number of payload - * octets to be used for new connections - */ - uint16_t suggestedTxOctets; - - /** Controller's maximum packet transmission time to be - * used for new connections. - */ - uint16_t suggestedTxTime; - - /** Maximum number of payload octets that the local Controller supports - * for transmission of a single Link Layer Data Channel PDU. - */ - uint16_t maxTxOctets; - - /** Maximum time, in microseconds, that the local Controller supports for - * transmission of a single Link Layer Data Channel PDU. - */ - uint16_t maxTxTime; - - /** Maximum number of payload octets that the local Controller supports - * for reception of a single Link Layer Data Channel PDU. - */ - uint16_t maxRxOctets; - - /** Maximum time, in microseconds, that the local Controller supports for - * reception of a single Link Layer Data Channel PDU. - */ - uint16_t maxRxTime; - -}cy_stc_ble_data_length_param_t; - -/** LE Data Length Change event parameter */ -typedef struct -{ - /** The maximum number of payload octets in a Link Layer Data Channel - * PDU that the local Controller will send on the current connection. - */ - uint16_t connMaxTxOctets; - - /** The maximum time that the local Controller will take to send a Link - * Layer Data Channel PDU on the current connection. - */ - uint16_t connMaxTxTime; - - /** The maximum number of payload octets in a Link Layer Data Channel - * PDU that the local controller expects to receive on the current connection. - */ - uint16_t connMaxRxOctets; - - /** The maximum time that the local Controller expects to take to receive a - * Link Layer Data Channel PDU on this connection. - */ - uint16_t connMaxRxTime; - - /** Peer bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_data_length_change_event_param_t; - - -/** Memory request parameters */ -typedef struct -{ - /** Protocol Request type*/ - cy_en_ble_protocol_req_t request; - - /** This is an output parameter that the application must fill and pass to the BLE Stack as per below table: - - request | memory - ------------ | ------------ - CY_BLE_PREPARED_WRITE_REQUEST | cy_stc_ble_prepare_write_request_memory_t - */ - void * configMemory; - - /** The event parameter is generated to allocate memory or to free up previously allocated memory - CY_BLE_ALLOC_MEMORY (0) = to allocate memory for request type, - CY_BLE_FREE_MEMORY (1) = free previously allocated memory for the request type*/ - uint8_t allocFree; - - /** Connection handle */ - cy_stc_ble_conn_handle_t connHandle; - -} cy_stc_ble_memory_request_t; - -/** AES CCM encrypted data information */ -typedef struct -{ - /** MIC value generated during encryption */ - uint8_t mic[CY_BLE_MIC_SIZE]; - - /** Pointer to an array of size 'length' where the encrypted/decrypted data - is stored */ - uint8_t *data; - - /** length of data */ - uint8_t length; - -}cy_stc_ble_aes_ccm_param_t; - -/** Timeout event parameter */ -typedef struct -{ - /** Bluetooth device address */ - cy_en_ble_to_reason_code_t reasonCode; - - /** handle */ - union - { - /** Connection Handle */ - cy_stc_ble_conn_handle_t connHandle; - - /* Peer device handle */ - uint8_t bdHandle; - - }CY_BLE_HANDLE; - - /** Handle of the started timer */ - uint8_t timerHandle; - -}cy_stc_ble_timeout_param_t; - -/** Generic Event parameter structure */ -typedef struct -{ - /** HCI error code as defined in Bluetooth 4.1 core specification, Volume 2, - Part D, section 1.3 */ - uint8_t status; - - /** Event Parameter associated to event */ - void *eventParams; - -}cy_stc_ble_events_param_generic_t; - -/** Set Phy parameter */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** The transmitter PHY for the connection */ - cy_en_ble_phy_mask_t txPhyMask; - - /** The receiver PHY for the connection */ - cy_en_ble_phy_mask_t rxPhyMask; - -}cy_stc_ble_phy_param_t; - -/** LL control procedure param structure */ -typedef struct -{ - /** Peer bdHandle */ - uint8_t bdHandle; - - /** LL Control procedure status - TRUE/FALSE */ - uint8_t cntrlProcStatus; - -}cy_stc_ble_ll_cntrl_proc_param_t; - -/** Whitelist information param */ -typedef struct -{ - /** Peer ID Address type, public = 0, Random = 1 */ - uint8_t type; - - /** Peer ID Address */ - uint8_t bdAddr[CY_BLE_BD_ADDR_SIZE]; - -} cy_stc_ble_white_list_t; - -/** Whitelist retention structure */ -typedef struct -{ - /** Size of the Whitelist */ - uint8_t size; - - /** Pointer to Whitelist Array */ - const cy_stc_ble_white_list_t *whiteList; - -} cy_stc_ble_white_list_retention_t ; - -/** Resolving list information param */ -typedef struct -{ - /** Internally used by the Stack */ - uint16_t flags; - - /** Internally used by the Stack */ - uint16_t extendedFlags; - - /** Peer ID Address */ - uint8_t bdAddr[CY_BLE_BD_ADDR_SIZE]; - - /** Peer ID Address type, public = 0, Random = 1 */ - uint8_t type; - - /** Local IRK */ - uint8_t localIrk[CY_BLE_IRK_SIZE]; - - /** Peer IRK */ - uint8_t peerIrk[CY_BLE_IRK_SIZE]; - -}cy_stc_ble_rpa_list_info_t; - -/** Resolving list retention structure */ -typedef struct -{ - /** Size of Resolving List */ - uint8_t size; - - /** Pointer to Resolving List Array */ - cy_stc_ble_rpa_list_info_t *resolvingList; - -}cy_stc_ble_resolving_list_retention_t; -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ -/** - \addtogroup group_ble_common_api_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_StoreStackData -***************************************************************************//** -* -* This function instructs the Stack to backup the Stack internal RAM data into flash. -* This API must be called by the application to back up Stack data. If this API is not -* called appropriately, the Stack internal data structure will not be available on the -* power cycle. -* -* \param param: Parameter is of type 'cy_stc_ble_stack_flash_param_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_INFO_FLASH_WRITE_IN_PROGRESS | Flash write in progress, application needs to call Cy_BLE_StoreStackData to complete the operation. -* CY_BLE_ERROR_FLASH_WRITE | Error in flash Write. -* CY_BLE_ERROR_INVALID_PARAMETER | If param pointer is NULL. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StoreStackData -( - cy_stc_ble_stack_flash_param_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_StartTimer -***************************************************************************//** -* -* This function provides a timer start utility to the BLE-Component. The BLE-Component can -* use this timer for certain operations like deferring writing CCCD to flash. -* This function should not be used for generic purposes as the timer ticks are -* updated only when there are LL activities. The BLE stack internally takes care of the -* timing requirement for GATT, GAP, and L2CAP signaling on-going procedures. -* Maximum timer support for application is restricted to 4. -* -* \param param: parameter of type 'cy_stc_ble_timer_info_t' -* param->timerHandle: output parameter. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Timeout is set to zero. -* CY_BLE_ERROR_INVALID_OPERATION | On failed operation. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StartTimer -( - cy_stc_ble_timer_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_StopTimer -***************************************************************************//** -* -* This function provides a timer stop utility to the BLE-Component. The BLE-Component can -* use this timer for certain operations like deferring writing CCCD to flash. -* This function should not be used for generic purposes as the timer ticks are -* updated only when there are LL activities. The BLE stack internally takes care of the -* timing requirement for GATT, GAP, and L2CAP signaling on-going procedures. -* -* \param param: parameter of type 'cy_stc_ble_timer_info_t' -* param->timeout: to be ignored. -* param->timerHandle: input parameter. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | On failed operation (Timer is already stopped or expired). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_StopTimer -( - cy_stc_ble_timer_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetRssi -***************************************************************************//** -* -* This function reads the recorded Received Signal Strength Indicator (RSSI) -* value for the last successfully received packet from the BLE radio -* sub-system. -* RSSI value is informed thorough 'CY_BLE_EVT_GET_RSSI_COMPLETE' -* -* \param param: Parameter is of type 'cy_stc_ble_rssi_info_t' -* param->rssi: ignore this parameter -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -* Information | Description -* ----------- | ----------- -* Range | -85 <= N <= 5 -* \note: The value is in dBm. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetRssi -( - cy_stc_ble_rssi_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetTxPowerLevel -***************************************************************************//** -* -* This function reads the transmit power of the BLE radio for the given BLE -* sub-system channel group. -* -* Tx power level is informed thorough 'CY_BLE_EVT_GET_TX_PWR_COMPLETE' -* -* \param param: Pointer to a variable of type 'cy_stc_ble_tx_pwr_config_param_t' where, -* * cy_stc_ble_tx_pwr_config_param_t -> bleSsChId indicates Channel group for which -* power level is to be read. The value can be advertisement -* channels (CY_BLE_LL_ADV_CH_TYPE) or data channels -* (CY_BLE_LL_CONN_CH_TYPE). -* * bdHandle indicates peer device handle. This is not applicable for advertisement -* channels (CY_BLE_LL_ADV_CH_TYPE). -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetTxPowerLevel -( - cy_stc_ble_tx_pwr_config_param_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetTxPowerLevel -***************************************************************************//** -* -* This function sets the transmit power of the BLE radio for the given BLE -* sub-system channel group. -* Successful operation is informed through 'CY_BLE_EVT_SET_TX_PWR_COMPLETE' event. -* -* \param param: Parameter is of type 'cy_stc_ble_tx_pwr_lvl_info_t' where, -* * blePwrLevel indicates Output Power level to be set by the function. -* * cy_stc_ble_tx_pwr_config_param_t -> bleSsChId indicates Channel group for which -* power level is to be set. The value can be advertisement -* channels (CY_BLE_LL_ADV_CH_TYPE) or data channels -* (CY_BLE_LL_CONN_CH_TYPE). -* * cy_stc_ble_tx_pwr_config_param_t -> bdHandle indicates peer device handle. This -* is not applicable for advertisement channels (CY_BLE_LL_ADV_CH_TYPE). Set bdHandle to 0xFFu -* to use 'blePwrLevel' as the default power level for all connections. -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetTxPowerLevel -( - cy_stc_ble_tx_pwr_lvl_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetBleClockCfgParam -***************************************************************************//** -* -* This function reads the clock configuration parameter of the BLE sub-system. -* This is not a blocking function. Clock config paramter is informed through -* the 'CY_BLE_EVT_GET_CLK_CONFIG_COMPLETE' event. -* -* The following parameters related to the BLE sub-system clock are read by this -* function: -* -* __Sleep Clock accuracy__ - -* Sleep clock accuracy (SCA) in PPM. This parameter indicates the sleep clock -* accuracy in PPM as described in the following table. It is set in the BLE -* Stack and is used for BLE Connection operation while creating LE connection -* with the peer device. -* -* Sleep Clock Accuracy Enum Field | PPM Range Translation (PPM) -* ------------------------------- | --------------------------- -* CY_BLE_LL_SCA_251_TO_500_PPM | 251 - 500 -* CY_BLE_LL_SCA_151_TO_250_PPM | 151 - 250 -* CY_BLE_LL_SCA_101_TO_150_PPM | 101 - 150 -* CY_BLE_LL_SCA_076_TO_100_PPM | 76 - 100 -* CY_BLE_LL_SCA_051_TO_075_PPM | 51 - 75 -* CY_BLE_LL_SCA_031_TO_050_PPM | 31 - 50 -* CY_BLE_LL_SCA_021_TO_030_PPM | 21 - 30 -* CY_BLE_LL_SCA_000_TO_020_PPM | 0 - 20 -* -* Refer to Bluetooth Core Specification 4.1 Volume 6, Chapter 4.5.7 for more -* details on how the SCA is used. -* -* __Link Layer clock divider__ - -* This input decides the frequency of the clock to the link layer. A lower -* clock frequency results in lower power consumption. Default clock frequency -* for the operation is 24 MHz. BLESS supports 24 MHz, 12 MHz, and 8 MHz clock -* configurations. Based on the end application requirement (how frequent the -* communication is expected to be), this parameter must be set. -* -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. - -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetBleClockCfgParam -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetBleClockCfgParam -***************************************************************************//** -* -* -* This function sets the clock configuration parameter of the BLE sub-system. This -* is a blocking function. -* Successful operation is informed through event 'CY_BLE_EVT_SET_CLK_CONFIG_COMPLETE'. -* The following parameters related to the BLE sub-system clock are set by this -* function: -* -* __Sleep Clock accuracy__ - -* Sleep clock accuracy (SCA) in PPM. This parameter indicates the sleep clock -* accuracy in PPM as described in the following table. It is set in the BLE -* Stack and is used for BLE Connection operation while creating LE connection -* with the peer device. -* -* Sleep Clock Accuracy Enum Field | PPM Range Translation (PPM) -* ------------------------------- | --------------------------- -* CY_BLE_LL_SCA_251_TO_500_PPM | 251 - 500 -* CY_BLE_LL_SCA_151_TO_250_PPM | 151 - 250 -* CY_BLE_LL_SCA_101_TO_150_PPM | 101 - 150 -* CY_BLE_LL_SCA_076_TO_100_PPM | 76 - 100 -* CY_BLE_LL_SCA_051_TO_075_PPM | 51 - 75 -* CY_BLE_LL_SCA_031_TO_050_PPM | 31 - 50 -* CY_BLE_LL_SCA_021_TO_030_PPM | 21 - 30 -* CY_BLE_LL_SCA_000_TO_020_PPM | 0 - 20 -* -* Refer to Bluetooth Core Specification 4.1 Volume 6, Chapter 4.5.7 for more -* details on how the SCA is used. -* -* __Link Layer clock divider__ - -* This input decides the frequency of the clock to the link layer. A lower -* clock frequency results in lower power consumption. Default clock frequency -* for the operation is 24 MHz. BLESS supports 24 MHz, 12 MHz, and 8 MHz clock -* configurations. Based on the end application requirement (how frequent the -* communication is expected to be), this parameter must be set. -* -* \param param: Pointer to a variable of type cy_stc_ble_bless_clk_cfg_params_t -* from which the existing clock configuration is taken. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If param pointer is NULL -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. - -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetBleClockCfgParam -( - cy_stc_ble_bless_clk_cfg_params_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GenerateRandomNumber -***************************************************************************//** -* -* This function sets the application-specific seed for DRBG (Deterministic Random number generator). -* This function generates 8-byte random number that complies with pseudo random -* number generation in accordance with [FIPS PUB 140-2]. Random number -* generation function is used during security procedures documented in Bluetooth -* 4.1 core specification, Volume 3, Part H. -* -* Generated random number is informed through event 'CY_BLE_EVT_RANDOM_NUM_GEN_COMPLETE' -* -* \param param: parameter is of type 'cy_stc_ble_stack_random_num_param_t' -* param->seed: Seed for DRBG. Setting the seed to zero is functionally -* equivalent to not setting the application-specific seed. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GenerateRandomNumber -( - cy_stc_ble_stack_random_num_param_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_AesEncrypt -***************************************************************************//** -* -* This function uses BLE sub-system AES engine to encrypt 128-bit of plain text -* using the given AES key. The output of AES processing is copied to -* encryptedData buffer. Refer to Bluetooth 4.1 core specification, Volume 3, -* Part H, section 2.2 for more details on usage of AES key. -* -* Completion of the API is informed through event 'CY_BLE_EVT_AES_ENCRYPT_COMPLETE' -* -* \param param: Parameter of type 'cy_stc_ble_aes_encrypt_info_t'. -* param->plainData: Pointer to the data containing plain text (128-bit) that is to be encrypted. -* -* param->aesKey: Pointer to the AES Key (128-bit) that is to be used for AES encryption. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | AES engine is being used internally or stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AesEncrypt -( - cy_stc_ble_aes_encrypt_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_AesCcmEncrypt -***************************************************************************//** -* -* This function encrypts the given data. -* -* Encrypted data is informed through event 'CY_BLE_EVT_AES_CCM_ENCRYPT_COMPLETE' -* -* \param param: Parameter is of type 'cy_stc_ble_aes_ccm_encrypt_info_t ' -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | One of the inputs is a null pointer. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AesCcmEncrypt -( - cy_stc_ble_aes_ccm_encrypt_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_AesCcmDecrypt -***************************************************************************//** -* -* This function decrypts the given data. -* -* Decrypted data is informed through event 'CY_BLE_EVT_AES_CCM_DECRYPT_COMPLETE' -* -* \param param: Parameter is of type 'cy_stc_ble_aes_ccm_decrypt_info_t ' -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | One of the inputs is a NULL pointer. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AesCcmDecrypt -( - cy_stc_ble_aes_ccm_decrypt_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GenerateAesCmac -***************************************************************************//** -* -* This API enables the application to generate the AES CMAC of 16 bytes, -* for a given variable length message and CMAC Key. -* -* After this API call, if the return value is CY_BLE_SUCCESS, -* then CY_BLE_EVT_AES_CMAC_GEN_COMPLETE event indicates completion of cmac generation. -* Check the output parameter cmac to get the generated cmac value after completion of CMAC generation. -* -* \param cmacGenParam: Parameter is of type 'cy_stc_ble_aes_cmac_generate_param_t ' -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | One of the inputs is a NULL pointer, the 'buffer' can be NULL only if 'size' is zero. -* CY_BLE_ERROR_INVALID_OPERATION | Application has already initiated AES CMAC operation that is pending completion. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GenerateAesCmac -( - cy_stc_ble_aes_cmac_generate_param_t *cmacGenParam -); - - -/****************************************************************************** -* Function Name: Cy_BLE_WriteAuthPayloadTimeout -***************************************************************************//** -* -* This function sets the Authentication Payload timeout in the BLE Controller for -* LE_PING feature. Refer to Bluetooth 4.1 core specification, Volume 6, Part B, -* section 4.6.5 for LE Ping operation. -* -* The 'CY_BLE_EVT_WRITE_AUTH_PAYLOAD_TO_COMPLETE' event is triggered on successful setting of the Authentication Payload timeout in BLE Controller for -* LE_PING feature. -* -* The 'CY_BLE_EVT_LE_PING_AUTH_TIMEOUT' event is triggered if the peer device has not responded -* with the valid MIC packet within the application configured ping authentication time. -* -* \param param: Parameter is of type 'cy_stc_ble_auth_payload_info_t ' -* param->bdHandle: Peer device handle. -* param->authPayloadTimeout: Variable containing authentication timeout value to be -* written to the BLE Controller. Details on this parameter are -* as given below: -* - Value Range = 0x0001 to 0xFFFF -* - Default Value (N) = 3000 (30 seconds) -* - Time Calculation = N x 10 ms -* - Time Range = 10 ms to 655,350 ms -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WriteAuthPayloadTimeout -( - cy_stc_ble_auth_payload_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_ReadAuthPayloadTimeout -***************************************************************************//** -* -* This function reads the Authentication Payload timeout set in the BLE Controller -* for LE_PING feature. Refer to Bluetooth 4.1 core specification, Volume 6, Part B, -* section 4.6.5 for LE Ping operation. -* -* Timeout is informed through event 'CY_BLE_EVT_READ_AUTH_PAYLOAD_TO_COMPLETE' -* -* \param param: Parameter is of type 'cy_stc_ble_auth_payload_info_t ' -* param->bdHandle: Peer device handle. -* param->authPayloadTimeout: to be ignored. -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_ReadAuthPayloadTimeout -( - cy_stc_ble_auth_payload_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetSlaveLatencyMode -***************************************************************************//** -* -* This function overrides the default BLE Stack behavior for the LE connection that -* is established with non zero slave latency. This API can be used by the application -* to force set quick transmission for a link related to a specified 'bdHandle' during the -* slave latency period. -* -* If the force quick transmit option is selected, the device will always respond to -* all the Connection Events (CE) ignoring the slave latency. To re-enable the BLE Stack -* control quick transmit behavior, the application should call this API with force -* quick transmit option set to zero. -* -* BLE Stack Control Policy: The BLE Stack enables quick transmission whenever any -* data packet is queued in the link layer. Upon successful transmission of a data packet, the -* BLE Stack resets the quick transmit to enable latency for power save. -* -* The BLE Stack also enables quick transmit whenever any real time LL Control PDU -* is received. After the acknowledgement of the PDU is processed, the quick transmit -* option is reset. -* -* Command completion is informed through event 'CY_BLE_EVT_SET_SLAVE_LATENCY_MODE_COMPLETE' -* -* \param param: parameter is of type 'cy_stc_ble_slave_latency_info_t' -* -* \return -* cy_en_ble_api_result_t: Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetSlaveLatencyMode -( - cy_stc_ble_slave_latency_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetDataLength -***************************************************************************//** -* -* This API allows the application to suggest maximum transmission packet size and maximum packet transmission time -* for the current connection. -* This is a non-blocking function. Successful setting of controller operation is -* informed through 'CY_BLE_EVT_SET_DATA_LENGTH_COMPLETE'. -* Actual data length used by controller will be informed through the 'CY_BLE_EVT_DATA_LENGTH_CHANGE' event. -* -* \param param: parameter is of type 'cy_stc_ble_set_data_length_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetDataLength -( - const cy_stc_ble_set_data_length_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetSuggestedDataLength -***************************************************************************//** -* -* This API allows the application to specify its preferred values for the Link -* Layer maximum Tx packet (Data Channel PDU) size (connInitialMaxTxOctets) and -* maximum Tx packet transmission time (connInitialMaxTxTime) to be used for new -* connections. -* This is a non-blocking function. Successful setting of controller operation is -* informed through 'CY_BLE_EVT_SET_SUGGESTED_DATA_LENGTH_COMPLETE'. -* Actual data length used by controller will be informed through the 'CY_BLE_EVT_DATA_LENGTH_CHANGE' event. -* -* \param param: parameter is of type 'cy_stc_ble_suggested_data_length_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetSuggestedDataLength -( - const cy_stc_ble_suggested_data_length_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetDataLength -***************************************************************************//** -* -* This API allows the application to read the suggested and maximum Tx/Rx packet size and -* suggested and maximum Tx/Rx time that the BLE Stack uses. -* -* This is a non-blocking function. -* Current data length parameters are informed through 'CY_BLE_EVT_GET_DATA_LENGTH_COMPLETE' -* -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetDataLength -( - void -); - - -/****************************************************************************** -* Function Name: Cy_BLE_AddDeviceToResolvingList -***************************************************************************//** -* -* This API is used to add a device to the resolving list in the controller for -* resolving Resolvable Private Address (RPA). This API can be used to update -* local and/or peer IRKs for an existing Resolving List entry by passing the -* same peer address type and peer address in the argument. -* -* Completion of operation is informed through the 'CY_BLE_EVT_ADD_DEVICE_TO_RPA_LIST_COMPLETE' event. -* Successful operation triggers the 'CY_BLE_EVT_PENDING_FLASH_WRITE' event. -* -* \param param: parameter is of type 'cy_stc_ble_resolving_device_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or failed. -* Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AddDeviceToResolvingList -( - cy_stc_ble_resolving_device_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetPeerResolvableAddress -***************************************************************************//** -* -* This API is used to get the current peer Resolvable Private Address being used for the corresponding -* peer Public and Random (static) Identity Address. The peer's resolvable address being used may -* change after the command is called. -* -* This is a non-blocking function. -* Peer resolvable address is informed through 'CY_BLE_EVT_GET_PEER_RPA_COMPLETE' -* -* \param param: Buffer that contains the information of peer identity address and address type -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Input parameter is NULL. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetPeerResolvableAddress -( - cy_stc_ble_peer_id_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetLocalResolvableAddress -***************************************************************************//** -* -* This API is used to get the current local Resolvable Private Address being used for the corresponding peer -* Identity Address. The local resolvable address being used may change after the command is called. -* -* This is a non-blocking function. -* Local resolvable address is informed through 'CY_BLE_EVT_GET_LOCAL_RPA_COMPLETE' -* -* \param param: Buffer that contains the information of peer identity address and address type. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Input parameter is NULL. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetLocalResolvableAddress -( - cy_stc_ble_peer_id_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_RemoveDeviceFromResolvingList -***************************************************************************//** -* -* This API is used to remove one device from the list of address translations used to resolve Resolvable -* Private Addresses in the BLE Stack. -* Passing all zero address as parameter clears the resolving list. -* -* Completion of operation is informed through 'CY_BLE_EVT_REMOVE_DEVICE_FROM_RPA_LIST_COMPLETE' event. -* Successful operation triggers the 'CY_BLE_EVT_PENDING_FLASH_WRITE' event. -* -* \param param: Buffer that contains the information of peer ID address and address type. -* If all bytes of peer ID address as well as address type is zero, this API will clear resolving list. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RemoveDeviceFromResolvingList -( - cy_stc_ble_peer_id_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetResolvablePvtAddressTimeOut -***************************************************************************//** -* -* This API is used to set the length of time the controller uses a Resolvable Private Address before a new -* resolvable private address is generated and starts being used. This timeout applies to all addresses -* generated by the BLE Stack. -* -* This is a non-blocking function. -* Request complete is informed through 'CY_BLE_EVT_SET_RPA_TO_COMPLETE' -* -* \param param: RPA_Timeout measured in seconds. -* Range for N: 0x0001 - 0xA1B8 (1 sec - approximately 11.5 hours) -* Default: N= 0x0384 (900 secs or 15 minutes) -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetResolvablePvtAddressTimeOut -( - uint16_t param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetAddressResolutionEnable -***************************************************************************//** -* -* This API is used to enable resolution of Resolvable Private Addresses in the BLE Stack. This causes the -* BLE Stack to use the resolving list whenever the Controller receives a local or peer Resolvable Private Address. -* -* This is a non-blocking function. -* Request complete is informed through 'CY_BLE_EVT_SET_RPA_ENABLE_COMPLETE' -* -* \param param: 0x00 - Address Resolution in controller disabled (default) \n -* 0x01 - Address Resolution in controller enabled \n -* 0x02 - 0xFF Reserved for Future Use -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetAddressResolutionEnable -( - uint8_t param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetResolvingList -***************************************************************************//** -* -* This API is used to get resolving list. -* This API is a blocking call. Hence no event will be generated. -* -* \param param: Pointer to store the base address of resolving list. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_INVALID_OPERATION | If privacy feature is not enabled. -* -* Note : The resolving list memory will be used by the stack. Hence the application -* should not modify the contents using the pointer provided by the stack. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetResolvingList(cy_stc_ble_resolving_list_retention_t const **param); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetPrivacyMode -***************************************************************************//** -* -* This API is used to allow the Host to specify the privacy mode to be used for -* a given entry on the Resolving List. - -* The effect of this setting is specified in [Vol 6] Part B, Section 4.7. -* -* When an entry on the Resolving List is removed, the mode associated with that -* entry shall also be removed. - -* This is not a blocking function. -* Successful operation will be informed through 'CY_BLE_EVT_SET_PRIVACY_MODE_COMPLETE'. - -* -* \param privacyModeInfo: Buffer that contains the information of peer address, peer address type, - and privacy mode. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ - -cy_en_ble_api_result_t Cy_BLE_SetPrivacyMode -( - cy_stc_ble_privacy_mode_info_t *privacyModeInfo -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetLeEventMask -***************************************************************************//** -* -* This API is equivalent of the LE_Set_Event_Mask HCI command -* and is used to control which LE events are generated by the HCI for the Host. -* The host will process these events and will send appropriate events to the application. -* If the bit in the hciLeEventMask is set to a one, then the event -* associated with that bit will be enabled. The Host must -* deal with each event that is generated by an LE Controller. The event mask -* allows the application to control which events will be generated for the host. -* -* This is not a blocking function. -* Successful operation will be informed through 'CY_BLE_EVT_LE_SET_EVENT_MASK_COMPLETE'. -* -* \param param: Pointer to the LE Mask of size 8 bytes. -* Refer Core Spec, Vol2, Part E, 7.8.1 for further information. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetLeEventMask -( - const uint8_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetChannelMap -***************************************************************************//** -* -* This function reads the channel map for data channels. This -* classification persists until it is overwritten by a subsequent call to this -* function or the controller is reset. If this command is used, updates should -* be sent within 10 seconds of the BLE Host knowing that the channel -* classification has changed. The interval between two successive commands sent -* will be at least one second. This command will be used only when the local -* device supports the Master role. -* * -* This is not a blocking function. Successful operation is informed through 'CY_BLE_EVT_GET_CHANNEL_MAP_COMPLETE' -* -* \param param: Pointer to security information of the device of type -* cy_stc_ble_channel_map_info_t. -* param->channelMap: To be ignored. -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | If connection does not exists for corresponding 'bdHandle'. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetChannelMap -( - cy_stc_ble_channel_map_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_SetHostChannelClassification -***************************************************************************//** -* -* This function sets channel classification for data channels. This -* classification persists until it is overwritten by a subsequent call to this -* function or the controller is reset. If this command is used, updates should -* be sent within 10 seconds of the BLE Host knowing that the channel -* classification has changed. The interval between two successive commands sent -* will be at least one second. This command will be used only when the local -* device supports the Master role. -* -* For details, refer to Bluetooth core specification 4.1, Volume 2, part E, -* section 7.8.19. -* -* This is a non blocking function. Successful operation is informed through -* event 'CY_BLE_EVT_SET_HOST_CHANNEL_COMPLETE' -* -* \param param: Pointer of type cy_stc_ble_channel_map_info_t. -* param->bdHandle: To be ignored. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetHostChannelClassification -( - cy_stc_ble_channel_map_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_AddDeviceToWhiteList -***************************************************************************//** -* -* This function adds the device to the Whitelist. The maximum number of devices that -* can be added to the Whitelist is eight including CY_BLE_GAP_MAX_BONDED_DEVICE. -* Refer to Bluetooth 4.1 core specification, Volume 3, Part C, section 9.3.5 for more details on whitelist. -* -* Completion of operation is informed through 'CY_BLE_EVT_ADD_DEVICE_TO_WHITE_LIST_COMPLETE' event. -* Successful operation triggers 'CY_BLE_EVT_PENDING_FLASH_WRITE' event -* -* \param param: Peer device address of type cy_stc_ble_bd_addr_t. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Error codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for 'param' or bdAddr 'type' has an invalid value. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_AddDeviceToWhiteList -( - cy_stc_ble_bd_addr_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_RemoveDeviceFromWhiteList -***************************************************************************//** -* -* This function removes the device from the Whitelist. -* -* Completion of operation is informed through the 'CY_BLE_EVT_REMOVE_DEVICE_FROM_WHITE_LIST_COMPLETE' event. -* Completion operation triggers the 'CY_BLE_EVT_PENDING_FLASH_WRITE' event. -* -* \param param: Pointer to peer device address, of type cy_stc_ble_bd_addr_t. If the device -* address is set to 0, then all devices shall be removed from the trusted Whitelist. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RemoveDeviceFromWhiteList -( - cy_stc_ble_bd_addr_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetWhiteList -***************************************************************************//** -* -* This function is used to get the Whitelist. -* This is a blocking call. Hence no event will be generated. -* -* \param param: Pointer to store the baseaddress of Whitelist. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* -* Note : The Whitelist memory will be used by the stack. Hence the application -* should not modify the contents using the pointer provided by the stack. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetWhiteList(cy_stc_ble_white_list_retention_t const**param); - - -/****************************************************************************** -* Function Name: Cy_BLE_isLLControlProcPending -***************************************************************************//** -* -* This function checks the Link Layer state for any pending real time -* control (LL_CHANNEL_MAP, LL_CONNECTION_UPDATE) procedure. When any such -* procedure is pending in Link layer busy state, it is indicated by the Link Layer. -* -* Completion operation triggers 'CY_BLE_EVT_LL_CNTRL_PROC_PENDING_COMPLETE' event -* -* Applications using specific GAP APIs or L2CAP API that can result -* in initiation of real-time procedures such as LL_CHANNEL_MAP or LL_CONNECTION_UPDATE -* can check the state of the Link Layer to avoid any such rejection from the BLE Stack. -* -* The BLE Stack can reject the new request -* -* \param param: Peer device handle. -* -* \return -* cy_en_ble_api_result_t: Return value indicates the Link Layer status for any pending -* real time procedure. -* -* Errors codes | Description -* ------------- | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified by bdHandle is not present -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_isLLControlProcPending -( - uint8_t param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_RegisterHciCb -***************************************************************************//** -* -* This API will initialize the HCI layer of the BLE Host Stack and will register Rx callback for all hci events and data. -* This API must be called before calling Cy_BLE_HciTransmit. -* This API should not be called during normal stack operation. -* If an application randomly uses hci APIs along with other APIs, behavior will be unpredictable. -* -* \param param: parameter is of type 'cy_ble_hci_rx_cb_t', callback function for Rx packets -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_RegisterHciCb -( - cy_ble_hci_rx_cb_t param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_HciShutdown -***************************************************************************//** -* This function stops any ongoing operation on the BLE Stack and forces the BLE Host HCI and -* the BLE controller to shut down. The only functions that can be called after calling this -* function is Cy_BLE_StackInit or Cy_BLE_RegisterHciCb. On calling one of these functions, the BLE Radio is turned -* off. -* -* No event is generated on calling this function. -* -* \return -* None -* -******************************************************************************/ -void Cy_BLE_HciShutdown -( - void -); - -/****************************************************************************** -* Function Name: Cy_BLE_HciTransmit -***************************************************************************//** -* -* The application must use this API for sending packets. This API -* must be called after calling 'Cy_BLE_RegisterHciCb'. -* -* \param param: parameter is of type 'cy_stc_ble_hci_tx_packet_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_HciTransmit -( - cy_stc_ble_hci_tx_packet_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetPhy -***************************************************************************//** -* -* This API allows application to Sets the PHY for the current connection. -* This is a non-blocking function and successful set to controller operation is -* informed through 'CY_BLE_EVT_SET_PHY_COMPLETE'. -* Actual Phy used by controller will be informed through the 'CY_BLE_EVT_PHY_UPDATE_COMPLETE' event. -* -* \param param: parameter is of type 'cy_stc_ble_set_phy_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified by bdHandle is not present -* CY_BLE_ERROR_INVALID_PARAMETER | Null pointer passed. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetPhy -( - const cy_stc_ble_set_phy_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_SetDefaultPhy -***************************************************************************//** -* -* This API allows the application to set a default PHY for all connections. -* This is a non-blocking function. Successful setting of the controller operation is -* informed through 'CY_BLE_EVT_SET_DEFAULT_PHY_COMPLETE'. -* The actual Phy used by the controller will be informed through the 'CY_BLE_EVT_PHY_UPDATE_COMPLETE' event. -* -* \param param: parameter is of type 'cy_stc_ble_set_suggested_phy_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Null pointer. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_SetDefaultPhy -( - const cy_stc_ble_set_suggested_phy_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_GetPhy -***************************************************************************//** -* -* This API allows the application to read the current PHY for the current connection. -* -* This is a non-blocking function. -* Current Phy for Tx and Rx is informed through 'CY_BLE_EVT_GET_PHY_COMPLETE' -* -* \param param: Peer bdHandle -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | Device identified by bdHandle is not present. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetPhy -( - uint8_t param -); - -/****************************************************************************** -* Function Name: Cy_BLE_GetTemperature -***************************************************************************//** -* -* This API allows the application to read the current temperature from the temperature -* sensor in the BLE radio. -* -* This is a non-blocking function. -* Temperature value is informed through 'CY_BLE_EVT_RADIO_TEMPERATURE' in degreeC units -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetTemperature -( - void -); - -/****************************************************************************** -* Function Name: Cy_BLE_GetBatteryLevel -***************************************************************************//** -* -* This API allows the application to read the current supply voltage of the BLE radio. -* -* This is a non-blocking function. -* Voltage value is informed through 'CY_BLE_EVT_RADIO_VOLTAGE_LEVEL' in milliVolts. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | If Memory allocation failed. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | If Stack resources are unavailable. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_GetBatteryLevel -( - void -); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -/** @} */ - -#endif /* CY_BLE_STACK_HOST_MAIN_H_ */ - - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_l2cap.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_l2cap.h deleted file mode 100644 index 0ab9ce9829..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_l2cap.h +++ /dev/null @@ -1,830 +0,0 @@ -/******************************************************************************* -* \file cy_ble_stack_l2cap.h -* \version 2.0 -* -* \brief -* This file contains declarations of public BLE APIs of L2CAP. -* Also specifies the defines, constants, and data structures required for the APIs. -* -* Related Document: -* BLE Standard Spec - CoreV4.2, CSS, CSAs, ESR05, ESR06 -* -******************************************************************************** -* \copyright -* Copyright 2014-2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_STACK_L2CAP_H_ -#define CY_BLE_STACK_L2CAP_H_ - - -/*************************************** -* Common stack includes -***************************************/ - -#include "cy_ble_stack_gap.h" - - -/*************************************** -** L2CAP Constants -***************************************/ -/** LE IPSP PSM */ -#define CY_BLE_L2CAP_PSM_LE_PSM_IPSP 0x0023u -/** L2CAP Invalid PSM */ -#define CY_BLE_L2CAP_PSM_INVALID 0x0000u - -/** L2CAP Header Size */ -#define CY_BLE_L2CAP_HDR_LEN 0x04u /**< L2CAP header len */ -#define CY_BLE_L2CAP_CREDIT_MODE_HDR_LEN 0x06u /**< L2CAP credit mode header len */ - -/** L2CAP Connect Results */ -/** l2cap connection pending */ -#define CY_BLE_L2CAP_CONNECTION_SUCCESSFUL 0x0000u - /** l2cap connection pending */ -#define CY_BLE_L2CAP_CONNECTION_PENDING 0x0001u -/** l2cap connection refused due to unsupported psm */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_PSM_UNSUPPORTED 0x0002u -/** l2cap connection refused due to security block */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_SECURITY_BLOCK 0x0003u -/** l2cap connection refused due to no resources */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_NO_RESOURCE 0x0004u -/** l2cap connection refused due to insufficient authentication */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_AUTHENTICATION_INSUFFICIENT 0x0005u -/** l2cap connection refused due to insufficient authorization */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_AUTHORIZATION_INSUFFICIENT 0x0006u -/** l2cap connection refused due to insufficient enc key size */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_ENC_KEY_SIZE_INSUFFICIENT 0x0007u -/** l2cap connection refused due to insufficient encryption */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_ENCRYPTION_INSUFFICIENT 0x0008u -/** l2cap connection refused due to source cid is invalid */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_SRC_CID_INVALID 0x0009u -/** l2cap connection refused due to source cid already allocated */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_SRC_CID_ALREADY_ALLOCATED 0x000Au -/** l2cap connection refused due to unacceptable parameters */ -#define CY_BLE_L2CAP_CONNECTION_REFUSED_UNACCEPTABLE_PARAMETERS 0x000Bu - -/**Response codes for Connection parameter update request */ -/** Connection Parameters accepted */ -#define CY_BLE_L2CAP_CONN_PARAM_ACCEPTED 0x0000u -/** Connection Parameters rejected */ -#define CY_BLE_L2CAP_CONN_PARAM_REJECTED 0x0001u - -/** Config Parameter index for PSM */ -#define CY_BLE_L2CAP_CONFIG_POS_PSM 0x00u - -/** Config Parameter index for CBFC Channel */ -#define CY_BLE_L2CAP_CONFIG_POS_CHANNEL 0x01u - -/** Config Parameter index for L2CAP Signalling timeout */ -#define CY_BLE_L2CAP_CONFIG_POS_SIG_TO 0x02u - -/*************************************** -** Enumerated Types -***************************************/ - -/** - \addtogroup group_ble_common_api_l2cap_definitions - @{ -*/ - -/** Reason for command reject event - CY_BLE_EVT_L2CAP_COMMAND_REJ */ -typedef enum -{ - /** Command Not Understood */ - CY_BLE_L2CAP_COMMAND_NOT_UNDERSTOOD = 0x0000u, - - /** Signaling L2CAP MTU exceeded */ - CY_BLE_L2CAP_SIGNALLING_MTU_EXCEEDED, - - /** Invalid Connection Identifier in request */ - CY_BLE_L2CAP_INVALID_CID_IN_REQUEST - -}cy_en_ble_l2cap_command_rej_reason_t; - -/** The result code of call back structures for L2CAP */ -typedef enum -{ - /** Operation Successful */ - CY_BLE_L2CAP_RESULT_SUCCESS = 0x0000u, - - /** Command timeout, if l2cap signaling channel timeout occurs, app should disconnect.*/ - CY_BLE_L2CAP_RESULT_COMMAND_TIMEOUT = 0x2318u, - - /** Invalid sdu length */ - CY_BLE_L2CAP_RESULT_INCORRECT_SDU_LENGTH = 0x2347u, - - /** Not enough credit to perform this operation */ - CY_BLE_L2CAP_RESULT_NOT_ENOUGH_CREDITS = 0x2371u, - - /** Credit overflow. Total credit exceeded 65535 (maximum) */ - CY_BLE_L2CAP_RESULT_CREDIT_OVERFLOW = 0x2373u, - - /** Invalid credit value, receive credit is Zero */ - CY_BLE_L2CAP_RESULT_UNACCEPTABLE_CREDIT_VALUE = 0x2374u - -}cy_en_ble_l2cap_result_param_t; - -/*************************************** -** Exported data structures -***************************************/ - -/** L2CAP Credit based flow Connection parameter */ -typedef struct -{ - /** PSM value of the higher-level protocol */ - uint16_t l2capPsm; - - /** Upper Layer defined Receive Credit Low Mark */ - uint16_t creditLwm; - -}cy_stc_ble_l2cap_cbfc_psm_info_t; - -/** L2CAP Credit based flow Connection parameter */ -typedef struct -{ - /** L2CAP MTU - Maximum SDU Size - - The L2CAP MTU field specifies the maximum SDU size (in octets) that the L2CAP - layer entity sending the LE Credit Based Connection Request can receive - on this channel. L2CAP implementations shall support a minimum L2CAP MTU size - of 23 octets. */ - uint16_t mtu; - - /** MPS - Maximum PDU Size - - The MPS field specifies the maximum payload size (in octets) that the - L2CAP layer entity sending the LE Credit Based Connection Request is - capable of receiving on this channel. L2CAP implementations shall support - a minimum MPS of 23 octets and may support an MPS up to 65488 octets. */ - uint16_t mps; - - /** Initial Number of Credits - - The initial credit value indicates the number of LE-frames that the peer - device can send to the L2CAP layer entity sending the LE Credit Based - Connection Request. The initial credit value shall be in the range of 0 to - 65535. */ - uint16_t credit; - -}cy_stc_ble_l2cap_cbfc_connection_info_t; - -/** Connect request parameter*/ -typedef struct -{ - /** L2CAP Credit based flow Connection parameter */ - cy_stc_ble_l2cap_cbfc_connection_info_t connParam; - - /** Remote PSM value */ - uint16_t remotePsm; - - /** Local PSM value */ - uint16_t localPsm; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_cbfc_conn_req_info_t; - -/** L2cap flow contol state */ -typedef struct -{ - /** - * States indicated by flowState variable - * - * CY_BLE_STACK_STATE_BUSY (0x01) = CY_BLE_STACK_STATE_BUSY indicates to the application that the BLE stack's internal buffers - * are about to be filled, and the remaining buffers are required to respond to the peer BLE device. - * After this event, the application shall not initiate GATT, GAP Security, or L2CAP data transactions. - * However the application shall respond to peer initiated transactions to prevent BLE protocol timeouts - * from occurring. - * Application-initiated data transactions can be resumed after the CY_BLE_EVT_STACK_BUSY_STATUS - * event when parameter 'CY_BLE_STACK_STATE_FREE' is received. - * - * CY_BLE_STACK_STATE_FREE (0x00) = CY_BLE_STACK_STATE_FREE indicates application that pending transactions are completed - * and sufficient buffers are available to process application-initiated transactions. - * The 'CY_BLE_EVT_STACK_BUSY_STATUS' event with 'CY_BLE_STACK_STATE_FREE' indicates to the - * application whether the BLE Stack's internal buffer state has transitioned from 'CY_BLE_STACK_STATE_BUSY' - * to 'CY_BLE_STACK_STATE_FREE'. - */ - uint8_t flowState; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_state_info_t; - -/** Connect response parameter*/ -typedef struct -{ - /** L2CAP Credit based flow Connection parameter */ - cy_stc_ble_l2cap_cbfc_connection_info_t connParam; - - /** This parameter specifies the local L2CAP channel end-point for this new L2CAP channel. - On receipt of L2CAP Connect Request command from the peer, the local L2CAP will temporarily create a channel. - This parameter identifies the new channel. If the upper-layer PSM chooses to reject this connection, - this temporary channel will be closed. */ - uint16_t localCid; - - /** This parameter specifies the response of the upper layer for the new L2CAP channel establishment - request from the peer. It must be set to a value as specified in L2CAP Connect Result Codes. Refer - to Bluetooth 4.1 core specification, Volume 3, Part A, section 4.23 for more details. */ - uint16_t response; - -}cy_stc_ble_l2cap_cbfc_conn_resp_info_t; - -/** Connect response parameter*/ -typedef struct -{ - /** This parameter specifies the local L2CAP channel end-point for this new L2CAP channel. - On receipt of L2CAP Connect Request command from the peer, the local L2CAP will temporarily create a channel. - This parameter identifies the new channel. If the upper-layer PSM chooses to reject this connection, - this temporary channel will be closed. */ - uint16_t localCid; - - /** The credit value field represents number of credits the receiving device can increment. - The credit value field is a number between 1 and 65535.*/ - uint16_t credit; - -}cy_stc_ble_l2cap_cbfc_credit_info_t; - -/** Tx Data parameter*/ -typedef struct -{ - /** Transmit data */ - uint8_t * buffer; - - /** L2CAP Data Packet length. It shall be of lesser the size - of both local L2CAP MTU & peer L2CAP MTU size. */ - uint16_t bufferLength; - - /**This parameter specifies the local channel end-point for the L2CAP - channel. For the initiator of L2CAP channel establishment, this - must be set to the value indicated by the - CY_BLE_EVT_L2CAP_CBFC_CONN_CNF event. For the responder, the upper- - layer protocol obtains this value when it receives the event - CY_BLE_EVT_L2CAP_CBFC_CONN_IND.*/ - uint16_t localCid; - -}cy_stc_ble_l2cap_cbfc_tx_data_info_t; - -/** Disconnect request parameter */ -typedef struct -{ - /**This parameter specifies the local channel end-point for the L2CAP - channel. For the initiator of L2CAP channel establishment, this - must be set to the value indicated by the - CY_BLE_EVT_L2CAP_CBFC_CONN_CNF event. For the responder, the upper- - layer protocol obtains this value when it receives the event - CY_BLE_EVT_L2CAP_CBFC_CONN_IND.*/ - uint16_t localCid; - -}cy_stc_ble_l2cap_cbfc_disconn_req_info_t; - -/** Connection parameter update response parameter */ -typedef struct -{ - /**This field indicates the response to the Connection Parameter Update Request*/ - uint16_t result; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_conn_update_param_rsp_info_t; - -/** L2CAP queue flow control with water level marking */ -typedef struct -{ - /** bd handle of remote device*/ - uint8_t bdHandle; - - /** low water mark level*/ - uint8_t lowWaterMark; - - /** high water level */ - uint8_t highWaterMark; - -} cy_stc_ble_l2cap_queue_flow_control_info_t; - -/* --------------------------Structure corresponding to events-------------------- */ - -/** Connect indication parameter*/ -typedef struct -{ - /** L2CAP Credit based flow Connection parameter */ - cy_stc_ble_l2cap_cbfc_connection_info_t connParam; - - /** Local CID */ - uint16_t lCid; - - /** Local PSM value */ - uint16_t psm; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_cbfc_conn_ind_param_t; - -/** Connect confirmation parameter*/ -typedef struct -{ - /** L2CAP Credit based flow Connection parameter */ - cy_stc_ble_l2cap_cbfc_connection_info_t connParam; - - /** Local CID*/ - uint16_t lCid; - - /** Response codes for Connection parameter update request */ - uint16_t response; - - /** bd handle of the remote device */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_cbfc_conn_cnf_param_t; - -/** Disconnect confirmation parameter */ -typedef struct -{ - /** Local CID */ - uint16_t lCid; - - /** The result field indicates the outcome of the connection request. The result - value of 0x0000 indicates success while a non-zero value indicates the connection - request failed or is pending. */ - cy_en_ble_l2cap_result_param_t result; - -}cy_stc_ble_l2cap_cbfc_disconn_cnf_param_t; - -/** Receive Data parameter */ -typedef struct -{ - /** Received L2cap Data */ - uint8_t * rxData; - - /** Received L2cap Data Length */ - uint16_t rxDataLength; - - /** Local CID */ - uint16_t lCid; - - /** A result value of 0x0000 indicates success, while a non-zero value - indicates an error condition (e.g. peer device violating credit flow, or L2CAP MTU size limit). */ - cy_en_ble_l2cap_result_param_t result; - -}cy_stc_ble_l2cap_cbfc_rx_param_t; - -/** Rx credit info parameter*/ -typedef struct -{ - /** Local CID */ - uint16_t lCid; - - /** The number of credits (LE-frames) */ - uint16_t credit; - -}cy_stc_ble_l2cap_cbfc_low_rx_credit_param_t; - -/** Tx credit info parameter */ -typedef struct -{ - /** Local CID */ - uint16_t lCid; - - /** The number of credits (LE-frames) */ - uint16_t credit; - - /** A result value of 0x0000 indicates success, while a non-zero value - indicates an error condition (e.g. credit overflow, or if total number of credits - crosses specification defined maximum limit of 0xFFFF). */ - cy_en_ble_l2cap_result_param_t result; - -}cy_stc_ble_l2cap_cbfc_low_tx_credit_param_t; - -/** Data Write parameter*/ -typedef struct -{ - /**Local CID*/ - uint16_t lCid; - - /** A result value of 0x0000 indicates success, - while a non-zero value indicates an error condition */ - cy_en_ble_l2cap_result_param_t result; - - /** Currently NULL. For future usage */ - uint8_t * buffer; - - /** Currently 0. For future usage */ - uint16_t bufferLength; - -}cy_stc_ble_l2cap_cbfc_rx_data_param_t; - -/** L2CAP Connection parameters Update response*/ -typedef struct -{ - /** connection parameter update response received from the master. - * Accepted = 0x0000 - * Rejected = 0x0001 */ - uint16_t result; - - /** Peer bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_conn_update_rsp_param_t; - -/** L2CAP command reject parameter */ -typedef struct -{ - /** Reason for command reject */ - cy_en_ble_l2cap_command_rej_reason_t result; - - /** Peer bdHandle */ - uint8_t bdHandle; - -}cy_stc_ble_l2cap_cmd_rej_param_t; - -/** @} */ - -/*************************************** -** Exported APIs -***************************************/ - -/** - \addtogroup group_ble_common_api_l2cap_functions - @{ -*/ - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_CbfcRegisterPsm -***************************************************************************//** -* -* This function registers a new upper-layer protocol or PSM to the L2CAP, along -* with the set of callbacks for the L2CAP Credit Based Flow Control mode. This -* is a blocking function. No event is generated on calling this function. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 3.4 -* for more details about credit based flow control mode of operation. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_psm_info_t' -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | Input param is NULL or 'l2capPsm' is 0. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Cannot register more than one PSM. -* CY_BLE_ERROR_L2CAP_PSM_NOT_IN_RANGE | The PSM is not in range of 0x0001 - 0x00FF. -* CY_BLE_ERROR_L2CAP_PSM_ALREADY_REGISTERED | PSM already Registered. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_CbfcRegisterPsm -( - cy_stc_ble_l2cap_cbfc_psm_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_CbfcUnregisterPsm -***************************************************************************//** -* -* This function de-registers an upper-layer protocol or LE_PSM from the L2CAP for -* the L2CAP Credit Based Flow Control mode. This is a blocking function. No -* event is generated on calling this function. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_psm_info_t' -* param->creditLwm : ignored -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL for input parameter. -* CY_BLE_ERROR_INVALID_OPERATION | Active CID is present with given PSM. -* CY_BLE_ERROR_L2CAP_PSM_NOT_REGISTERED | PSM is not registered. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_CbfcUnregisterPsm -( - cy_stc_ble_l2cap_cbfc_psm_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_CbfcConnectReq -***************************************************************************//** -* -* This L2CAP function initiates the L2CAP channel establishment procedure in Credit -* Based Flow Control (CBFC) mode. Connection establishment is initiated to the -* specified remote Bluetooth device, for the specified PSM representing an -* upper-layer protocol above L2CAP. This is a non-blocking function. -* -* At the receiver's end, a CY_BLE_EVT_L2CAP_CBFC_CONN_IND event is generated. -* In response to this call, a CY_BLE_EVT_L2CAP_CBFC_CONN_CNF event is generated -* at the sender's end. -* -* At the sender's end, the CY_BLE_EVT_L2CAP_COMMAND_REJ event is generated if the receiver -* rejects the connection request. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 4.22 for -* more details about this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_conn_req_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If "param" is NULL. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Insufficient resources. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | 'bdHandle' does not represent known device entity. -* CY_BLE_ERROR_L2CAP_PSM_NOT_REGISTERED | PSM not Registered. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_CbfcConnectReq -( - cy_stc_ble_l2cap_cbfc_conn_req_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_CbfcConnectRsp -***************************************************************************//** -* -* This L2CAP function enables an upper-layer protocol to respond to the L2CAP -* connection request for LE Credit Based Flow Control mode of the specified PSM -* from the specified remote Bluetooth device. This is a non-blocking function. -* The upper-layer PSM must always respond by calling this -* function upon receiving the CBFC Connection Request -* (CY_BLE_EVT_L2CAP_CBFC_CONN_IND) event. -* -* The channel is established (opened) only when the PSM concerned responds -* with an event indicating success (CY_BLE_EVT_L2CAP_CBFC_CONN_CNF, at the peer -* device's end). Otherwise, the channel establishment request from the peer -* will be rejected by the L2CAP with an appropriate result and status as received -* from the upper-layer PSM. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 4.23 -* for more details about this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_conn_resp_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If "param" is NULL. -* CY_BLE_ERROR_L2CAP_CONNECTION_ENTITY_NOT_FOUND | Connection entity is not found. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_CbfcConnectRsp -( - cy_stc_ble_l2cap_cbfc_conn_resp_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_CbfcSendFlowControlCredit -***************************************************************************//** -* -* This L2CAP function enables an upper-layer protocol to send an LE Flow Control -* Credit packet to the peer Bluetooth device when it is capable of receiving -* additional LE-frames. This is a non-blocking function. -* -* This function is invoked when the device is expecting more data from the peer -* device and it gets an event indicating that the peer device is low on credits -* CY_BLE_EVT_L2CAP_CBFC_RX_CREDIT_IND for which it needs to respond by sending -* credits by invoking this function. After the peer device receives these credits, -* it gets the CY_BLE_EVT_L2CAP_CBFC_TX_CREDIT_IND event indicating the same. It is -* the responsibility of the application layer of the device sending the credit -* to keep track of the total number of credits and make sure that it does -* not exceed 65535. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 4.24 for -* more details about this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_credit_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_L2CAP_CONNECTION_ENTITY_NOT_FOUND | L2CAP connection instance is not present. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Insufficient resources. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_CbfcSendFlowControlCredit -( - cy_stc_ble_l2cap_cbfc_credit_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_ChannelDataWrite -***************************************************************************//** -* -* This function sends a data packet on the L2CAP CBFC channel. This is a -* blocking function. -* -* This API generates a 'CY_BLE_EVT_L2CAP_CBFC_DATA_WRITE_IND' event that -* is kept for backward compatibility and the user should handle cy_en_ble_api_result_t -* to determine whether the last data packet was sent properly. -* -* On the peer device, the CY_BLE_EVT_L2CAP_CBFC_DATA_READ event is used to inform the application -* about the data received over the L2CAP CBFC channel. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 3.4 for -* more details about this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_tx_data_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' or 'buffer' is NULL. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_NO_CONNECTION | No Link Layer connection is present. -* CY_BLE_ERROR_L2CAP_CONNECTION_ENTITY_NOT_FOUND | No L2CAP channel found corresponding to CID. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_ChannelDataWrite -( - cy_stc_ble_l2cap_cbfc_tx_data_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_DisconnectReq -***************************************************************************//** -* -* This function initiates the sending of an L2CAP Disconnect Request -* (CY_BLE_EVT_L2CAP_CBFC_DISCONN_IND event received by the peer device) command -* to the remote L2CAP entity to initiate disconnection of the referred L2CAP -* channel. This is a non-blocking function. -* -* Disconnection of the L2CAP channel always succeeds - either by reception of -* the L2CAP Disconnect Response from the peer, or by timeout. In any case, -* L2CAP will confirm disconnection of the channel by calling the -* CY_BLE_EVT_L2CAP_CBFC_DISCONN_CNF event. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 4.6 for -* more details about this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_cbfc_disconn_req_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_OPERATION | No Link Layer connection is present. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_L2CAP_CONNECTION_ENTITY_NOT_FOUND | No connection entity found that can be disconnected. -* CY_BLE_ERROR_INSUFFICIENT_RESOURCES | Insufficient resources. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_DisconnectReq -( - cy_stc_ble_l2cap_cbfc_disconn_req_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_LeConnectionParamUpdateRequest -***************************************************************************//** -* -* This function sends the connection parameter update request to the Master of -* the link. This is a non-blocking function. This function can be used -* only from a device connected in the LE slave role. -* -* To send a connection parameter update request from the master to the slave, -* use the Cy_BLE_GAPC_ConnectionParamUpdateRequest() function. This function -* results in a CY_BLE_EVT_L2CAP_CONN_PARAM_UPDATE_REQ event at the Master's end. -* -* Refer to Bluetooth 4.1 core specification, Volume 3, Part A, section 4.20 for -* more details about this operation. -* -* \param param: Parameter is of type 'cy_stc_ble_gap_conn_update_param_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If "connParam" is NULL. -* CY_BLE_ERROR_INVALID_OPERATION | Connection Parameter Update Request is not allowed. -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_NO_CONNECTION | No Link Layer connection is present. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | 'bdHandle' does not represent known device entity. -* -* Note: Please refer the API documentation of Cy_BLE_GAPC_InitConnection for recommended -* Connection Interval values. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_LeConnectionParamUpdateRequest -( - cy_stc_ble_gap_conn_update_param_info_t * param -); - - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_LeConnectionParamUpdateResponse -***************************************************************************//** -* -* This API sends the connection parameter update response to the slave. This API -* can be used only from a device connected in the LE master role. -* -* This function results in CY_BLE_EVT_L2CAP_CONN_PARAM_UPDATE_RSP event at -* the Slave's end. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_conn_update_param_rsp_info_t'. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'result' is invalid (greater than connection parameter reject code i.e., 0x0001). -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed. -* CY_BLE_ERROR_NO_CONNECTION | No Link Layer connection is present. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | 'bdHandle' does not represent known device entity. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_LeConnectionParamUpdateResponse -( - cy_stc_ble_l2cap_conn_update_param_rsp_info_t * param -); - -/****************************************************************************** -* Function Name: Cy_BLE_L2CAP_SetFlowControlLimits -***************************************************************************//** -* -* This API allows the application to set L2CAP flow control limits using high -* and low water marking for the L2CAP queue. The application can set high and low -* water marking for the L2CAP queue using this API. -* -* During data transmission, when the number of available L2CAP queue entries reaches the -* low water mark level, the application will receive a CY_BLE_EVT_STACK_BUSY_STATUS event with -* status as busy, so that the application can stop queuing data and wait until it -* receives a CY_BLE_EVT_STACK_BUSY_STATUS event with free status. -* -* \param param: Parameter is of type 'cy_stc_ble_l2cap_queue_flow_control_info_t'. -* Min Highwater mark: 1 Max HighWater mark: L2cap queue depth -* Min LowWater mark: 0 Max LowWater mark: (HighWaterMark -1) -* -* Default values set by stack for better throughput is: LowWaterMark 3, HighWaterMark -* (L2CAP queue depth - 1). -* -* Note: If the LowWaterMark is set to less than 3, then do not initiate GATT data -* transmission while pairing procedure is going on. -* -* For GATT data transmission, the difference between HighWaterMark and -* LowWaterMark must not be greater than number of GATT buffers provided during stack-init -* to avoid receiving a memory allocation error for GATT transaction. -* -* \return -* cy_en_ble_api_result_t : Return value indicates whether the function succeeded or -* failed. Following are the possible error codes. -* -* Errors codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | On successful operation. -* CY_BLE_ERROR_INVALID_PARAMETER | If 'param' is NULL or water mark levels are not proper. -* CY_BLE_ERROR_NO_DEVICE_ENTITY | 'bdHandle' does not represent known device entity. -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_L2CAP_SetFlowControlLimits -( - cy_stc_ble_l2cap_queue_flow_control_info_t * param -); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/** @} */ - -#endif /*CY_BLE_STACK_L2CAP_H_*/ - - -/*EOF*/ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_pvt.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_pvt.h deleted file mode 100644 index a2fc4cde20..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_stack_pvt.h +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************//** -* \file cy_ble_stack_pvt.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for the HAL section -* of the BLE component. -* -* Note: -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#ifndef CY_BLE_CY_BLE_STACK_PVT_H -#define CY_BLE_CY_BLE_STACK_PVT_H - -#include "BLE_config.h" -#include "cy_ble_stack.h" -#include "sysclk/cy_sysclk.h" -#include "syspm/cy_syspm.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/* Mapping functions for stack size optimization */ -#if(CY_BLE_MODE_PROFILE) -#if(CY_BLE_SECURE_CONN_FEATURE_ENABLED) - void Cy_BLE_HAL_EccHeapInit(uint8_t *heapMem, uint8_t numOfConn); - void Cy_BLE_HAL_EccHeapDeInit(void); - uint16_t Cy_BLE_HAL_EccGetFeatureHeapReq(uint8_t numOfConn); - cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateSecurityKeypair(uint8_t p_publicKey[], uint8_t p_privateKey[], - uint8_t random[]); - cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateDHKey(const uint8_t p_publicKey[], const uint8_t p_privateKey[], - uint8_t p_secret[], uint8_t ci); - cy_en_ble_api_result_t Cy_BLE_HAL_EccValidPublicKey(const uint8_t p_publicKey[]); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingLocalPublicKeyHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingRemoteKeyHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyCheckHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingKeypressNotificationHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingRandHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingConfirmHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingLrConfirmingHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingLrConfirmingHandler(void *param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxDhkeyGenerateComplete(void* param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateLocalP256PublicKey(uint8_t param); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateDHkey(void *param1, void *param2, uint8_t param3); - cy_en_ble_api_result_t Cy_BLE_HAL_SeSmpScUserPasskeyHandler(void *param1, void *param2); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxLocalPubkeyGenerateComplete(void *param); - void Cy_BLE_HAL_SmpScCmacComplete(uint8_t param); - void Cy_BLE_HAL_EccPointMult(uint8_t param); -#else - void Cy_BLE_HAL_EccHeapInit(uint8_t * heapMem CY_UNUSED, - uint8_t numOfConn CY_UNUSED); - void Cy_BLE_HAL_EccHeapDeInit(void); - uint16_t Cy_BLE_HAL_EccGetFeatureHeapReq(uint8_t numOfConn CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateSecurityKeypair(uint8_t p_publicKey[] CY_UNUSED, - uint8_t p_privateKey[] CY_UNUSED, - uint8_t random[] CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateDHKey(const uint8_t p_publicKey[] CY_UNUSED, - const uint8_t p_privateKey[] CY_UNUSED, - uint8_t p_secret[] CY_UNUSED, uint8_t ci CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_EccValidPublicKey(const uint8_t p_publicKey[] CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingLocalPublicKeyHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingRemoteKeyHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyCheckHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingKeypressNotificationHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingRandHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingConfirmHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingLrConfirmingHandler(void *param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxDhkeyGenerateComplete(void* param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateLocalP256PublicKey(uint8_t param CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateDHkey(void * param1 CY_UNUSED, - void * param2 CY_UNUSED, - uint8_t param3 CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_SeSmpScUserPasskeyHandler(void *param1 CY_UNUSED, - void *param2 CY_UNUSED); - cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxLocalPubkeyGenerateComplete(void *param CY_UNUSED); - void Cy_BLE_HAL_SmpScCmacComplete(uint8_t param CY_UNUSED); - void Cy_BLE_HAL_EccPointMult(uint8_t param CY_UNUSED); -#endif /* (CY_BLE_SECURE_CONN_FEATURE_ENABLED) */ -#endif /* CY_BLE_MODE_PROFILE */ - -#if(CY_BLE_SECURE_CONN_FEATURE_ENABLED) - uint16_t BLE_CMP_FTR_API_lec_hci_handle_read_local_P256_public_key_command(void *param); - uint16_t BLE_CMP_FTR_API_lec_hci_handle_generate_DHkey_command(void *param); -#else - uint16_t BLE_CMP_FTR_API_lec_hci_handle_read_local_P256_public_key_command(void *param CY_UNUSED); - uint16_t BLE_CMP_FTR_API_lec_hci_handle_generate_DHkey_command(void *param CY_UNUSED); -#endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED*/ - - -/*************************************** -* Stack manager prototypes -***************************************/ - -/* Extern definitions for BLE stack ISR handler */ -extern void Cy_BLE_HAL_BlessInterruptHandler(void); - -/* To be used only for HCI_MODE and in Debug mode -* where the logger serial port is enabled -*/ -extern void Cy_BLE_HAL_UartTxCompltHandler(void); - -/* To be used only for HCI_MODE */ -extern void Cy_BLE_HAL_UartRxDataHandler(uint8_t byte); - -/* To be used only for Host MODE */ -extern void Cy_BLE_HAL_HciTransportHandler(char_t packet, uint16_t packet_len); - - -/*************************************** -* Macros -***************************************/ -#define CY_BLE_INTR_TX_SUCCESS 0x00u -#define CY_BLE_INTR_TX_DONE 0x00u -#define CY_BLE_INTR_TX_OVERFLOW 0x01u - -#define CY_BLE_INTR_RX_SUCCESS 0x00u -#define CY_BLE_INTR_RX_NOT_EMPTY 0x00u -#define CY_BLE_INTR_RX_OVERFLOW 0x01u -#define CY_BLE_INTR_RX_FRAME_ERROR 0x02u -#define CY_BLE_INTR_RX_PARITY_ERROR 0x04u - - -/* Align buffer size value to 4 */ -#define CY_BLE_STACK_ALIGN_TO_4(x) ((((x) & 3u) == 0u) ? \ - (x) : \ - (((x) - ((x) & 3u)) + 4u)) -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_CY_BLE_STACK_PVT_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_tps.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_tps.c deleted file mode 100644 index 45d77d9cd8..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_tps.c +++ /dev/null @@ -1,1091 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_tps.c -* \version 2.0 -* -* \brief -* This file contains the source code for the Tx Power Service of the BLE -* Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_TPS)) -static cy_ble_callback_t Cy_BLE_TPS_ApplCallback = NULL; - -#ifdef CY_BLE_TPS_CLIENT -/* TPS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_tpsc_t cy_ble_tpsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_tpscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_TPS_CLIENT */ - -/* The pointer on global BLE TPS Config structure */ -cy_stc_ble_tps_config_t *cy_ble_tpsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_TPS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_TPSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -#endif /* (CY_BLE_TPS_SERVER) */ - -#ifdef CY_BLE_TPS_CLIENT -static void Cy_BLE_TPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_TPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_TPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_TPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_TPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_TPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_TPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* (CY_BLE_TPS_CLIENT) */ -static cy_en_ble_gatt_err_code_t Cy_BLE_TPS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_TPS_Init -***************************************************************************//** -* -* This function initializes the Tx Power Service. -* -* \param config: Configuration structure for TPS. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPS_Init(cy_stc_ble_tps_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_tpsConfigPtr = config; - - /* Registers Event Handler for the TPS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_TPS_EventHandler); - - - /* Registers a callback function via config structure */ - if(cy_ble_tpsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_TPS_ApplCallback = cy_ble_tpsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_TPS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_TPS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset((void*)&cy_ble_tpsc[idx], 0, sizeof(cy_stc_ble_tpsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_TPS].uuid = CY_BLE_UUID_TX_POWER_SERVICE; - } - cy_ble_tpscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_TPS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for TPS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback. -* * eventParam contains the parameters corresponding to the -* current event. -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise this -* data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_TPS_ApplCallback = callbackFunc; - if(cy_ble_tpsConfigPtr != NULL) - { - cy_ble_tpsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_TPS_SERVER - -/****************************************************************************** -* Function Name: cy_ble_TpssWriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event for Tx Power service. -* -* \param cy_stc_ble_gatts_write_cmd_req_param_t * eventParam: The pointer to the data that came -* with a write request for TPS. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write is successful. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - Request is not supported. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - Write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - Offset value is invalid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_TPSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t event = (uint32_t)CY_BLE_EVT_TPSS_NOTIFICATION_DISABLED; - - - /* Check event code if it defines write request */ - if(NULL != Cy_BLE_TPS_ApplCallback) - { - /* Client Characteristic Configuration descriptor write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_tpsConfigPtr->tpss->txPowerLevelCccdHandle) - { - /* Verify that optional notification property is enabled for Tx Power Level characteristic */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_tpsConfigPtr->tpss->txPowerLevelCharHandle)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_TPSS_NOTIFICATION_ENABLED; - } - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_tps_char_value_t wrReqParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_TPS_TX_POWER_LEVEL, - .value = NULL - }; - Cy_BLE_TPS_ApplCallback(event, (void*)&wrReqParam); - } - } - else - { - gattErr = CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED; - } - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: cy_ble_TpssSetCharacteristicValue -***************************************************************************//** -* -* Sets characteristic value of the Tx Power Service, which is identified by -* charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored in the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSS_SetCharacteristicValue(cy_en_ble_tps_char_index_t charIndex, - uint8_t attrSize, - int8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex < CY_BLE_TPS_CHAR_COUNT) - { - /* Set Tx Power Level characteristic value to GATT database. Need to handle return type difference of - * Cy_BLE_GATTS_WriteAttributeValueCCCD() and cy_ble_tpssSetCharacteristicValue(). */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_tpsConfigPtr->tpss->txPowerLevelCharHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = (uint8_t*)attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets characteristic value of the Tx Power Service, which is identified by -* charIndex. -* -* \param charIndex: The index of the Tx Power characteristic. -* \param attrSize: The size of the Tx Power characteristic value attribute. -* \param attrValue: The pointer to the location where Tx Power characteristic -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Characteristic value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSS_GetCharacteristicValue(cy_en_ble_tps_char_index_t charIndex, - uint8_t attrSize, - int8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex == CY_BLE_TPS_TX_POWER_LEVEL) && (attrSize == CY_BLE_TPS_TX_POWER_LEVEL_SIZE)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_tpsConfigPtr->tpss->txPowerLevelCharHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = (uint8_t*)attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Get Tx Power Level characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets characteristic descriptor of specified characteristic of the Tx Power -* Service. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Characteristic Descriptor value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameters failed -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional descriptor is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - cy_en_ble_tps_char_descriptors_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_TPS_TX_POWER_LEVEL) && (descrIndex == CY_BLE_TPS_CCCD)) - { - if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_tpsConfigPtr->tpss->txPowerLevelCccdHandle) - { - /* Set Client Characteristic Configuration Descriptor of Tx Power Level - * characteristic to GATT database. - * Need to handle return type difference of Cy_BLE_GATTS_WriteAttributeValueCCCD() and - * cy_ble_TpssGetCharacteristicDescriptor(). */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_tpsConfigPtr->tpss->txPowerLevelCccdHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = (uint8_t*)attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSS_SendNotification -***************************************************************************//** -* -* Sends a notification with the characteristic value, as specified by charIndex, -* to the Client device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_TPSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this. -* characteristic. -* * CY_BLE_ERROR_INVALID_STATE - Connection with client is not established. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - uint8_t attrSize, - int8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex == CY_BLE_TPS_TX_POWER_LEVEL) && (attrSize == CY_BLE_TPS_TX_POWER_LEVEL_SIZE)) - { - if(CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_tpsConfigPtr->tpss->txPowerLevelCccdHandle)) - { - /* Set Tx Power Level characteristic value to GATT database. - * Need to handle return type difference of Cy_BLE_GATTS_WriteAttributeValueCCCD() and - * cy_ble_tpssSetCharacteristicValue(). */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_tpsConfigPtr->tpss->txPowerLevelCharHandle, - .handleValuePair.value.val = (uint8_t*)attrValue, - .handleValuePair.value.len = attrSize, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = dbAttrValInfo.handleValuePair.attrHandle, - .handleValPair.value.val = dbAttrValInfo.handleValuePair.value.val, - .handleValPair.value.len = dbAttrValInfo.handleValuePair.value.len, - .connHandle = connHandle - }; - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - } - } - else - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - } - - /* Return status */ - return(apiResult); -} - -#endif /* (CY_BLE_GATT_ROLE_SERVER) */ - - -#ifdef CY_BLE_TPS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP event. -* Based on the service UUID, an appropriate data structure is populated using the -* data received as part of the callback. -* -* \param cy_stc_ble_disc_char_info_t * discCharInfo: The pointer to the characteristic -* information structure. -* -* -******************************************************************************/ -static void Cy_BLE_TPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_TPS)) - { - if(discCharInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_TX_POWER_LEVEL) - { - /* Save Tx Power Level Characteristic handle */ - Cy_BLE_CheckStoreCharHandle(cy_ble_tpsc[discIdx].txPowerLevelChar); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* This event is generated when a server successfully sends the data for -* CY_BLE_EVT_GATTC_FIND_INFO_REQ. Based on the service UUID, an appropriate data -* structure is populated to the service with a service callback. -* -* \param cy_stc_ble_disc_descr_info_t * discDescrInfo: The pointer to descriptor information -* structure. -* -******************************************************************************/ -static void Cy_BLE_TPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_TPS) - { - if(discDescrInfo->uuid.uuid16 == CY_BLE_UUID_CHAR_CLIENT_CONFIG) - { - Cy_BLE_CheckStoreCharDescrHandle(cy_ble_tpsc[discIdx].txPowerLevelCccdHandle); - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_TPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_TPS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - if(cy_ble_discovery[discIdx].charCount == 0u) - { - /* One descriptor is available per characteristic */ - charRangeInfo->range.startHandle = cy_ble_tpsc[discIdx].txPowerLevelChar.valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_TPS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event for the Tx Power Service. -* -* \param cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam: The pointer to the data -* structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_TPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_TPS_ApplCallback != NULL)) - { - if(cy_ble_tpsc[discIdx].txPowerLevelChar.valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_tps_char_value_t ntfParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_TPS_TX_POWER_LEVEL, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_TPS_ApplCallback((uint32_t)CY_BLE_EVT_TPSC_NOTIFICATION, (void*)&ntfParam); - cy_ble_eventHandlerFlag &= (uint8_t)(~CY_BLE_CALLBACK); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param cy_stc_ble_gattc_read_rsp_param_t *eventParam: The pointer to the data that came -* with a read response for the Tx -* Power Service. -* -******************************************************************************/ -static void Cy_BLE_TPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_TPS_ApplCallback != NULL) && - (cy_ble_tpscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_tpsc[discIdx].txPowerLevelChar.valueHandle == cy_ble_tpscReqHandle[discIdx]) - { - /* Fill Tx Power Service read response parameter structure for Tx Power Level - * Characteristic. */ - cy_stc_ble_tps_char_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_TPS_TX_POWER_LEVEL, - .value = &eventParam->value - }; - cy_ble_tpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_TPS_ApplCallback((uint32_t)CY_BLE_EVT_TPSC_READ_CHAR_RESPONSE, &rdRspParam); - } - else if(cy_ble_tpsc[discIdx].txPowerLevelCccdHandle == cy_ble_tpscReqHandle[discIdx]) - { - /* Fill Tx Power Service read response parameter structure for Tx Power Level - * Client Characteristic Configuration Descriptor. */ - cy_stc_ble_tps_descr_value_t rdRspParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_TPS_TX_POWER_LEVEL, - .descrIndex = CY_BLE_TPS_CCCD, - .value = &eventParam->value - }; - cy_ble_tpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_TPS_ApplCallback((uint32_t)CY_BLE_EVT_TPSC_READ_DESCR_RESPONSE, &rdRspParam); - } - else - { - /* No TPS characteristic was requested for read */ - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param cy_stc_ble_conn_handle_t *eventParam: The pointer to a cy_stc_ble_conn_handle_t data structure. -* -* -******************************************************************************/ -static void Cy_BLE_TPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_TPS_ApplCallback != NULL) && - (cy_ble_tpsc[discIdx].txPowerLevelCccdHandle == cy_ble_tpscReqHandle[discIdx]) && - (cy_ble_tpscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_tps_descr_value_t wrRspParam = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_TPS_TX_POWER_LEVEL, - .descrIndex = CY_BLE_TPS_CCCD, - .value = NULL - }; - cy_ble_tpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_TPS_ApplCallback((uint32_t)CY_BLE_EVT_TPSC_WRITE_DESCR_RESPONSE, &wrRspParam); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event for the Tx Power Service. -* -* \param cy_stc_ble_gatt_err_param_t *eventParam: The pointer to the -* cy_stc_ble_gatt_err_param_t structure. -* -* \return -* None -* -******************************************************************************/ -static void Cy_BLE_TPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle != cy_ble_tpscReqHandle[discIdx]) - { - cy_ble_tpscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_GetCharacteristicValue -***************************************************************************//** -* -* Gets the characteristic value of the Tx Power Service, which is -* identified by charIndex. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_TPSC_READ_CHAR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the TPS service-specific callback is registered -* (with Cy_BLE_TPS_RegisterAttrCallback): -* * CY_BLE_EVT_TPSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_tps_char_value_t. -* . -* Otherwise (if the TPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - if((charIndex == CY_BLE_TPS_TX_POWER_LEVEL) && (discIdx < CY_BLE_CONFIG_GATTC_COUNT)) - { - /* Send request to write Tx Power Level characteristic value */ - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_tpsc[discIdx].txPowerLevelChar.valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_tpscReqHandle[discIdx] = cy_ble_tpsc[discIdx].txPowerLevelChar.valueHandle; - } - } - else - { - /* apiResult equals CY_BLE_ERROR_INVALID_PARAMETER */ - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_TPSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets a characteristic descriptor value of the Tx Power Service. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_TPSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_TPSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the Characteristic -* \param descrIndex: The index of the TX Power Service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on the -* specified attribute. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the TPS service-specific callback is registered -* (with Cy_BLE_TPS_RegisterAttrCallback): -* * CY_BLE_EVT_TPSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_tps_descr_value_t. -* . -* Otherwise (if the TPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - cy_en_ble_tps_char_descriptors_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (attrValue != NULL) && - (charIndex == CY_BLE_TPS_TX_POWER_LEVEL) && (descrIndex == CY_BLE_TPS_CCCD) && - (attrSize == CY_BLE_CCCD_LEN)) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_tpsc[discIdx].txPowerLevelCccdHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_tpscReqHandle[discIdx] = cy_ble_tpsc[discIdx].txPowerLevelCccdHandle; - } - } - else - { - /* apiResult equals CY_BLE_ERROR_INVALID_PARAMETER */ - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: TpscGetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the Tx Power Service. -* -* This function call can result in generation of the following events based on -* the response from the server device: -* * CY_BLE_EVT_TPSC_READ_DESCR_RESPONSE -* * CY_BLE_EVT_GATTC_ERROR_RSP -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the characteristic descriptor. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The component in in invalid state for current -* operation. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Cannot process request to send PDU due to -* invalid operation performed by the -* application. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the TPS service-specific callback is registered -* (with Cy_BLE_TPS_RegisterAttrCallback): -* * CY_BLE_EVT_TPSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_tps_descr_value_t. -* . -* Otherwise (if the TPS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_TPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - cy_en_ble_tps_char_descriptors_t descrIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (charIndex == CY_BLE_TPS_TX_POWER_LEVEL) && - (descrIndex == CY_BLE_TPS_CCCD)) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_tpsc[discIdx].txPowerLevelCccdHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_tpscReqHandle[discIdx] = cy_ble_tpsc[discIdx].txPowerLevelCccdHandle; - } - } - else - { - /* apiResult equals CY_BLE_ERROR_INVALID_PARAMETER */ - } - - /* Return status */ - return(apiResult); -} - -#endif /* CY_BLE_TPS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_TPS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Tx Power Service of the BLE. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_TPS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_TPS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_TPSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_TPSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_TPSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_TPS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_TPS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_TPSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - #endif /* CY_BLE_TPS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_TPS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_TPSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_TPSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_TPSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_TPSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_TPS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_TPS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_tps.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_tps.h deleted file mode 100644 index cc5a9b6f54..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_tps.h +++ /dev/null @@ -1,206 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_tps.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in the Tx -* Power Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_TPS_H -#define CY_BLE_TPS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_TPS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - -/* Maximum supported Tx Power Services */ -#define CY_BLE_TPS_SERVICE_COUNT (1u) - -/** - * \addtogroup group_ble_service_api_TPS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** TPS Characteristic indexes */ -typedef enum -{ - CY_BLE_TPS_TX_POWER_LEVEL, /**< Tx Power Level characteristic index */ - CY_BLE_TPS_CHAR_COUNT /**< Total count of characteristics */ -}cy_en_ble_tps_char_index_t; - -/** TPS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_TPS_CCCD, /**< Tx Power Level Client Characteristic configuration descriptor index */ - CY_BLE_TPS_DESCR_COUNT /**< Total count of Tx Power Service characteristic descriptors */ -}cy_en_ble_tps_char_descriptors_t; - -/** Tx Power Service Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_tps_char_index_t charIndex; /**< Characteristic index of Tx Power Service */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Tx Power Service characteristic */ -} cy_stc_ble_tps_char_value_t; - -/** Tx Power Service Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Connection handle */ - cy_en_ble_tps_char_index_t charIndex; /**< Characteristic index of Tx Power Service */ - cy_en_ble_tps_char_descriptors_t descrIndex; /**< Characteristic index Descriptor of Tx Power Service */ - cy_stc_ble_gatt_value_t *value; /**< Pointer to value of Tx Power Service characteristic */ -} cy_stc_ble_tps_descr_value_t; - -/** Structure with Tx Power Service attribute handles */ -typedef struct -{ - /** Tx Power Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Tx Power Level Characteristic handle */ - cy_ble_gatt_db_attr_handle_t txPowerLevelCharHandle; - - /** Tx Power Level Client Characteristic Configuration Descriptor handle */ - cy_ble_gatt_db_attr_handle_t txPowerLevelCccdHandle; -} cy_stc_ble_tpss_t; - -/** Structure with discovered attributes information of Tx Power Service */ -typedef struct -{ - /** Tx Power Level Characteristic handle */ - cy_stc_ble_srvr_char_info_t txPowerLevelChar; - - /** Tx Power Level Client Characteristic Configuration Descriptor handle */ - cy_ble_gatt_db_attr_handle_t txPowerLevelCccdHandle; -} cy_stc_ble_tpsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Tx Power Service GATT DB handles structure */ - const cy_stc_ble_tpss_t *tpss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_tps_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_TPS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_TPS_Init(cy_stc_ble_tps_config_t *config); -cy_en_ble_api_result_t Cy_BLE_TPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_TPS_SERVER -/** - * \addtogroup group_ble_service_api_TPS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_TPSS_SetCharacteristicValue(cy_en_ble_tps_char_index_t charIndex, uint8_t attrSize, - int8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_TPSS_GetCharacteristicValue(cy_en_ble_tps_char_index_t charIndex, uint8_t attrSize, - int8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_TPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - cy_en_ble_tps_char_descriptors_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_TPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, uint8_t attrSize, - int8_t *attrValue); - -/** @} */ -#endif /* (CY_BLE_TPS_SERVER) */ - -#ifdef CY_BLE_TPS_CLIENT -/** - * \addtogroup group_ble_service_api_TPS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_TPSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_TPSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - cy_en_ble_tps_char_descriptors_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_TPSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_tps_char_index_t charIndex, - cy_en_ble_tps_char_descriptors_t descrIndex); - -/** @} */ -#endif /* (CY_BLE_TPS_CLIENT) */ - - -/*************************************** -* API Constants -***************************************/ -#define CY_BLE_TPS_TX_POWER_LEVEL_SIZE (1u) - -/*************************************** -* Internal macros -***************************************/ -#ifdef CY_BLE_TPS_CLIENT -#define Cy_BLE_TPSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_TPS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_tpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].txPowerLevelChar.valueHandle) - -#define Cy_BLE_TPSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_TPS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_TPS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_tpsc[Cy_BLE_GetDiscoveryIdx(connHandle)].txPowerLevelCccdHandle) -#endif /* (CY_BLE_TPS_CLIENT) */ - -/*************************************** -* Variables with external linkage -***************************************/ -#ifdef CY_BLE_TPS_CLIENT -extern cy_stc_ble_tpsc_t cy_ble_tpsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_TPS_CLIENT) */ - -extern cy_stc_ble_tps_config_t cy_ble_tpsConfig; -extern cy_stc_ble_tps_config_t *cy_ble_tpsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_TPS) */ -#endif /* CY_BLE_TPS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_uds.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_uds.c deleted file mode 100644 index a8678c7141..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_uds.c +++ /dev/null @@ -1,2099 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_uds.c -* \version 2.0 -* -* \brief -* This file contains the source code for -* the User Data Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_UDS)) - -static cy_ble_callback_t Cy_BLE_UDS_ApplCallback; - -#ifdef CY_BLE_UDS_SERVER -uint8_t cy_ble_udsFlag; - -/* Internal storage for last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_udssReqHandle; -#endif /* CY_BLE_UDS_SERVER */ - -#ifdef CY_BLE_UDS_CLIENT -/* Server's User Data Service characteristics GATT DB handles structure */ -cy_stc_ble_udsc_t cy_ble_udsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Internal storage for last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_udscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -/* Read Long Descriptors variables */ -static uint8_t * cy_ble_udscRdLongBuffPtr[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; -static uint16_t cy_ble_udscRdLongBuffLen[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -static uint8_t cy_ble_udscCurrLen[CY_BLE_CONFIG_GATTC_COUNT] = { 0u }; -#endif /* CY_BLE_UDS_CLIENT */ - -/* The pointer on global BLE UDS Config structure */ -cy_stc_ble_uds_config_t *cy_ble_udsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ - -#ifdef CY_BLE_UDS_SERVER -static void Cy_BLE_UDSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_UDSS_ReadRequestEventHandler(cy_stc_ble_gatts_char_val_read_req_t *eventParam); -static cy_en_ble_gatt_err_code_t Cy_BLE_UDSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_UDSS_PrepareWriteRequestEventHandler(cy_stc_ble_gatts_prep_write_req_param_t *eventParam); -static void Cy_BLE_UDSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam); -#endif /* CY_BLE_UDS_SERVER */ - -#ifdef CY_BLE_UDS_CLIENT -static void Cy_BLE_UDSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_UDSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_UDSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_UDSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_UDSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_UDSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_UDSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_UDSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_UDSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -static void Cy_BLE_UDSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam); -#endif /* CY_BLE_UDS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_UDS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_UDS_Init -***************************************************************************//** -* -* Initializes the profile internals. -* -* \param config: Configuration structure for Uds. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDS_Init(cy_stc_ble_uds_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_udsConfigPtr = config; - - /* Registers Event Handler for the UDS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_UDS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_udsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_UDS_ApplCallback = cy_ble_udsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_UDS_SERVER - cy_ble_udsFlag = 0u; - cy_ble_udssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_UDS_SERVER */ - - #ifdef CY_BLE_UDS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_UDS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_udsc[idx], 0, sizeof(cy_stc_ble_udsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_UDS].uuid = CY_BLE_UUID_USER_DATA_SERVICE; - } - cy_ble_udscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_UDS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service-specific write requests from a peer device will not be handled with -* an unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t for UDS is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, void *eventParam), -* where: -* * eventCode indicates the event that triggered this callback. -* * eventParam contains the parameters corresponding to the current event. -* -* \sideeffect -* The *eventParams in the callback function should not be used by the -* application once the callback function execution is finished. Otherwise this -* data may become corrupted. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_UDS_ApplCallback = callbackFunc; - if(cy_ble_udsConfigPtr != NULL) - { - cy_ble_udsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_UDS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets the value of the characteristic, as identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSS_SetCharacteristicValue(cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check parameters */ - if(charIndex >= CY_BLE_UDS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsConfigPtr->udss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Store characteristic value into GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_udsConfigPtr->udss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_GetCharacteristicValue -***************************************************************************//** -* -* Gets the value of the characteristic, as identified by charIndex. -* -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic -* value data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - A characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSS_GetCharacteristicValue(cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check parameters */ - if(charIndex >= CY_BLE_UDS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsConfigPtr->udss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get characteristic value from GATT database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_udsConfigPtr->udss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets a characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value attribute. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - Characteristic Descriptor value was read successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - A characteristic is absent. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - cy_en_ble_uds_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Check parameters */ - if((charIndex >= CY_BLE_UDS_CHAR_COUNT) || (descrIndex >= CY_BLE_UDS_DESCR_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsConfigPtr->udss->charInfo[charIndex].descrHandle[CY_BLE_UDS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - /* Get data from database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_udsConfigPtr->udss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_SendNotification -***************************************************************************//** -* -* Sends a notification of the specified characteristic value, as identified by -* the charIndex. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_UDSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data -* that should be sent to the client device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_UDS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsConfigPtr->udss->charInfo[charIndex].descrHandle[CY_BLE_UDS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, - cy_ble_udsConfigPtr->udss->charInfo[charIndex].descrHandle[CY_BLE_UDS_CCCD])) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ntf_t ntfParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_udsConfigPtr->udss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_SendIndication -***************************************************************************//** -* -* Sends an indication of the specified characteristic value, as identified by -* the charIndex. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_UDSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle which consist of the device ID and ATT -* connection ID. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be sent -* to the client device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - An optional characteristic is absent. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. -* * CY_BLE_ERROR_IND_DISABLED - Indication is disabled for this characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the UDS service-specific callback is registered -* (with Cy_BLE_UDS_RegisterAttrCallback): -* * CY_BLE_EVT_UDSS_INDICATION_CONFIRMED - If the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the UDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - If the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_UDS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsConfigPtr->udss->charInfo[charIndex].descrHandle[CY_BLE_UDS_CCCD] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, - cy_ble_udsConfigPtr->udss->charInfo[charIndex].descrHandle[CY_BLE_UDS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - cy_stc_ble_gatts_handle_value_ind_t indParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_udsConfigPtr->udss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - /* Send notification to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indParam); - - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific value confirmation response from client */ - cy_ble_udssReqHandle = indParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles the Value Confirmation request event from the BLE stack. -* -* \param eventParam: The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_UDSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_UDS_ApplCallback != NULL) - && (cy_ble_udsConfigPtr->udss->charInfo[CY_BLE_UDS_UCP].charHandle == cy_ble_udssReqHandle)) - { - cy_stc_ble_uds_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_UDS_UCP, - .value = NULL - }; - - cy_ble_udssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_udsFlag &= (uint8_t) ~CY_BLE_UDS_FLAG_PROCESS; - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSS_INDICATION_CONFIRMED, &locCharIndex); - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_ReadRequestEventHandler -***************************************************************************//** -* -* Handles the Read Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_UDSS_ReadRequestEventHandler(cy_stc_ble_gatts_char_val_read_req_t *eventParam) -{ - if(Cy_BLE_UDS_ApplCallback != NULL) - { - cy_stc_ble_uds_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .gattErrorCode = CY_BLE_GATT_ERR_NONE, - .value = NULL - }; - - for(locCharValue.charIndex = CY_BLE_UDS_FNM; - locCharValue.charIndex < CY_BLE_UDS_CHAR_COUNT; - locCharValue.charIndex++) - { - if(locCharValue.charIndex == CY_BLE_UDS_UCP) - { - /* Omit UCP characteristic */ - locCharValue.charIndex = CY_BLE_UDS_LNG; - } - - if(eventParam->attrHandle == cy_ble_udsConfigPtr->udss->charInfo[locCharValue.charIndex].charHandle) - { - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSS_READ_CHAR, &locCharValue); - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED) - { - eventParam->gattErrorCode = CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED; - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_WriteEventHandler -***************************************************************************//** -* -* Handles the Write Request Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* cy_en_ble_gatt_err_code_t - A finction result state if it succeeded -* (CY_BLE_GATT_ERR_NONE) or failed with error codes: -* * CY_BLE_GATTS_ERR_PROCEDURE_ALREADY_IN_PROGRESS -* * CY_BLE_GATTS_ERR_CCCD_IMPROPERLY_CONFIGURED -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_UDSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(Cy_BLE_UDS_ApplCallback != NULL) - { - cy_stc_ble_uds_char_value_t locCharValue; - locCharValue.connHandle = eventParam->connHandle; - locCharValue.gattErrorCode = CY_BLE_GATT_ERR_NONE; - - if((eventParam->handleValPair.attrHandle == - cy_ble_udsConfigPtr->udss->charInfo[CY_BLE_UDS_DCI].descrHandle[CY_BLE_UDS_CCCD]) || - (eventParam->handleValPair.attrHandle == - cy_ble_udsConfigPtr->udss->charInfo[CY_BLE_UDS_UCP].descrHandle[CY_BLE_UDS_CCCD])) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - locCharValue.value = NULL; - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - uint32_t eventCode; - - if(eventParam->handleValPair.attrHandle == cy_ble_udsConfigPtr->udss->charInfo[CY_BLE_UDS_DCI]. - descrHandle[CY_BLE_UDS_CCCD]) - { - locCharValue.charIndex = CY_BLE_UDS_DCI; - - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_UDSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_UDSS_NOTIFICATION_DISABLED; - } - } - else - { - locCharValue.charIndex = CY_BLE_UDS_UCP; - - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_UDSS_INDICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_UDSS_INDICATION_DISABLED; - } - } - - Cy_BLE_UDS_ApplCallback(eventCode, &locCharValue); - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - for(locCharValue.charIndex = CY_BLE_UDS_FNM; - locCharValue.charIndex < CY_BLE_UDS_CHAR_COUNT; - locCharValue.charIndex++) - { - if(eventParam->handleValPair.attrHandle == - cy_ble_udsConfigPtr->udss->charInfo[locCharValue.charIndex].charHandle) - { - gattErr = Cy_BLE_GATT_DbCheckPermission(eventParam->handleValPair.attrHandle, - &eventParam->connHandle, CY_BLE_GATT_DB_WRITE | - CY_BLE_GATT_DB_PEER_INITIATED); - - if((gattErr == CY_BLE_GATT_ERR_NONE) && (locCharValue.charIndex == CY_BLE_UDS_UCP)) - { - if(CY_BLE_UDS_IS_PROCEDURE_IN_PROGRESS) - { - gattErr = CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId, - cy_ble_udsConfigPtr->udss->charInfo[CY_BLE_UDS_UCP]. - descrHandle[CY_BLE_UDS_CCCD])) - { - gattErr = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED; - } - else - { - } - } - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - locCharValue.value = &eventParam->handleValPair.value; - - if(!CY_BLE_GATT_DB_ATTR_CHECK_PRPTY(eventParam->handleValPair.attrHandle, - CY_BLE_GATT_DB_CH_PROP_WRITE)) - { - gattErr = CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED; - } - else if(eventParam->handleValPair.value.len > - CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(eventParam->handleValPair.attrHandle)) - { - gattErr = CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN; - } - else - { - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSS_WRITE_CHAR, &locCharValue); - - if(locCharValue.gattErrorCode == CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED) - { - gattErr = CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED; - } - else - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_udsConfigPtr->udss-> - charInfo[locCharValue.charIndex].charHandle, - locCharValue.value->len); - - if(locCharValue.charIndex == CY_BLE_UDS_UCP) - { - cy_ble_udsFlag |= CY_BLE_UDS_FLAG_PROCESS; - } - } - } - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - - return(gattErr); -} - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_PrepareWriteEventHandler -***************************************************************************//** -* -* Handles the Prepare Write Request Event. -* -* \param eventParam: The pointer to the data that comes with a prepare -* write request. -* -* -******************************************************************************/ -static void Cy_BLE_UDSS_PrepareWriteRequestEventHandler(cy_stc_ble_gatts_prep_write_req_param_t *eventParam) -{ - cy_en_ble_uds_char_index_t locCharIndex; - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = eventParam->connHandle }; - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - for(locCharIndex = CY_BLE_UDS_FNM; locCharIndex <= CY_BLE_UDS_EML; locCharIndex++) - { - if(eventParam->baseAddr[eventParam->currentPrepWriteReqCount - 1u].handleValuePair.attrHandle == - cy_ble_udsConfigPtr->udss->charInfo[locCharIndex].charHandle) - { - if(CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_udsConfigPtr->udss->charInfo[locCharIndex].charHandle) <= - (mtuParam.mtu - CY_BLE_GATT_WRITE_HEADER_LEN)) - { - eventParam->gattErrorCode = (uint8_t)CY_BLE_GATT_ERR_ATTRIBUTE_NOT_LONG; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } -} - -/****************************************************************************** -* Function Name: Cy_BLE_UDSS_ExecuteWriteRequestEventHandler -***************************************************************************//** -* -* Handles the Execute Write Request Event. -* -* \param eventParam: The pointer to the data that came with a write request. -* -******************************************************************************/ -static void Cy_BLE_UDSS_ExecuteWriteRequestEventHandler(cy_stc_ble_gatts_exec_write_req_t *eventParam) -{ - uint32_t locCount; - cy_stc_ble_uds_char_value_t locCharValue[CY_BLE_UDS_LONG_CHAR_COUNT]; - cy_stc_ble_gatt_value_t locGattValue[CY_BLE_UDS_LONG_CHAR_COUNT]; - cy_en_ble_uds_char_index_t locCharIndex; - - for(locCharIndex = CY_BLE_UDS_FNM; locCharIndex <= CY_BLE_UDS_EML; locCharIndex++) - { - locGattValue[locCharIndex].len = 0u; - locGattValue[locCharIndex].val = NULL; - } - - for(locCount = 0u; locCount < eventParam->prepWriteReqCount; locCount++) - { - for(locCharIndex = CY_BLE_UDS_FNM; locCharIndex <= CY_BLE_UDS_EML; locCharIndex++) - { - if(eventParam->baseAddr[locCount].handleValuePair.attrHandle == - cy_ble_udsConfigPtr->udss->charInfo[locCharIndex].charHandle) - { - locGattValue[locCharIndex].len = eventParam->baseAddr[locCount].offset + - eventParam->baseAddr[locCount].handleValuePair.value.len; - - if(locGattValue[locCharIndex].val == NULL) - { - locGattValue[locCharIndex].val = eventParam->baseAddr[locCount].handleValuePair.value.val; - } - else if(eventParam->baseAddr[locCount].offset == 0u) - { - /* Case when client wants to rewrite value from beginning */ - locGattValue[locCharIndex].val = eventParam->baseAddr[locCount].handleValuePair.value.val; - } - else - { - /* Do nothing */ - } - } - } - } - - for(locCharIndex = CY_BLE_UDS_FNM; locCharIndex <= CY_BLE_UDS_EML; locCharIndex++) - { - if((Cy_BLE_UDS_ApplCallback != NULL) && (locGattValue[locCharIndex].len != 0u) && - (locGattValue[locCharIndex].len <= - CY_BLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(cy_ble_udsConfigPtr->udss->charInfo[locCharIndex].charHandle))) - { - /* Check the execWriteFlag before execute or cancel write long operation */ - if(eventParam->execWriteFlag == CY_BLE_GATT_EXECUTE_WRITE_EXEC_FLAG) - { - locCharValue[locCharIndex].gattErrorCode = CY_BLE_GATT_ERR_NONE; - locCharValue[locCharIndex].connHandle = eventParam->connHandle; - locCharValue[locCharIndex].charIndex = locCharIndex; - locCharValue[locCharIndex].value = &locGattValue[locCharIndex]; - - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSS_WRITE_CHAR, &locCharValue[locCharIndex]); - - if(locCharValue[locCharIndex].gattErrorCode == CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED) - { - eventParam->gattErrorCode = (uint8_t)CY_BLE_GATT_ERR_USER_DATA_ACCESS_NOT_PERMITTED; - } - else - { - CY_BLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(cy_ble_udsConfigPtr->udss->charInfo[locCharIndex].charHandle, - locGattValue[locCharIndex].len); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -#endif /* CY_BLE_UDS_SERVER */ - -#ifdef CY_BLE_UDS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_UDSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the UDS service-specific callback is registered -* (with Cy_BLE_UDS_RegisterAttrCallback): -* * CY_BLE_EVT_UDSC_WRITE_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_uds_char_value_t. -* . -* Otherwise (if the UDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = { .connHandle = connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_UDS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_WRITE & cy_ble_udsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else if((mtuParam.mtu - 3u) < attrSize) - { - cy_stc_ble_gattc_prep_write_req_t prepWriteReqParam = - { - .handleValOffsetPair.handleValuePair.attrHandle = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle, - .handleValOffsetPair.offset = 0u, - .handleValOffsetPair.handleValuePair.value.val = attrValue, - .handleValOffsetPair.handleValuePair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteLongCharacteristicValues(&prepWriteReqParam); - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_udscReqHandle[discIdx] = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_udscReqHandle[discIdx] = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read the characteristic Value from a server, -* as identified by its charIndex. As a result a Read Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_UDSS_READ_CHAR events is generated. -* On successful request execution on the Server side the Read Response is -* sent to the Client. -* -* The Read Response only contains the characteristic Value that is less than or -* equal to (MTU - 1) octets in length. If the characteristic Value is greater -* than (MTU - 1) octets in length, the Read Long Characteristic Value procedure -* may be used if the rest of the characteristic Value is required. -* -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the UDS service-specific callback is registered -* (with Cy_BLE_UDS_RegisterAttrCallback): -* * CY_BLE_EVT_UDSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_uds_char_value_t. -* . -* Otherwise (if the UDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_UDS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_udsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - } - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_udscReqHandle[discIdx] = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_GetLongCharacteristicValue -***************************************************************************//** -* -* Sends a request to read a long characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the buffer where the read long characteristic -* descriptor value should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the UDS service-specific callback is registered -* (with Cy_BLE_UDS_RegisterAttrCallback): -* * CY_BLE_EVT_UDSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_uds_char_value_t. -* . -* Otherwise (if the UDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_BLOB_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSC_GetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - uint16_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(((charIndex > CY_BLE_UDS_EML) && (charIndex != CY_BLE_UDS_LNG)) || (attrSize == 0u) || - (attrValue == NULL) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((CY_BLE_CHAR_PROP_READ & cy_ble_udsc[discIdx].charInfo[charIndex].properties) == 0u) - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - else - { - cy_stc_ble_gattc_read_blob_req_t readBlobReqParam = - { - .handleOffset.attrHandle = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle, - .handleOffset.offset = 0u, - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadLongCharacteristicValues(&readBlobReqParam); - } - - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_udscReqHandle[discIdx] = cy_ble_udsc[discIdx].charInfo[charIndex].valueHandle; - cy_ble_udscRdLongBuffLen[discIdx] = attrSize; - cy_ble_udscRdLongBuffPtr[discIdx] = attrValue; - cy_ble_udscCurrLen[discIdx] = 0u; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic Value to the server, -* as identified by its charIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_UDSS_INDICATION_ENABLED -* * CY_BLE_EVT_UDSS_INDICATION_DISABLED -* * CY_BLE_EVT_UDSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_UDSS_NOTIFICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic descriptor value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the UDS service-specific callback is registered -* (with Cy_BLE_UDS_RegisterAttrCallback): -* * CY_BLE_EVT_UDSC_WRITE_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_uds_descr_value_t. -* . -* Otherwise (if the UDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - cy_en_ble_uds_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_UDS_CHAR_COUNT) || (descrIndex >= CY_BLE_UDS_DESCR_COUNT) || - (attrSize != CY_BLE_CCCD_LEN) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - /* Fill all fields of write request structure ... */ - .handleValPair.attrHandle = cy_ble_udsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = CY_BLE_CCCD_LEN, - .connHandle = connHandle - }; - - /* ... and send request to server device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - /* Save handle to support service-specific read response from device */ - cy_ble_udscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Gets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular descriptor. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In the case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the UDS service-specific callback is registered -* (with Cy_BLE_UDS_RegisterAttrCallback): -* * CY_BLE_EVT_UDSC_READ_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_uds_descr_value_t. -* . -* Otherwise (if the UDS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameter -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is some trouble with the -* requested attribute on the peer device, -* the details are provided with an event parameter -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_UDSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - cy_en_ble_uds_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - /* Check parameters */ - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_UDS_CHAR_COUNT) || (descrIndex >= CY_BLE_UDS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_udsc[discIdx].charInfo[charIndex].descrHandle[descrIndex] == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_udsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_udscReqHandle[discIdx] = cy_ble_udsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_UDSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* User Data Service characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_udscCharUuid[CY_BLE_UDS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_FIRST_NAME, - CY_BLE_UUID_CHAR_LAST_NAME, - CY_BLE_UUID_CHAR_EMAIL_ADDRESS, - CY_BLE_UUID_CHAR_AGE, - CY_BLE_UUID_CHAR_DATE_OF_BIRTH, - CY_BLE_UUID_CHAR_GENDER, - CY_BLE_UUID_CHAR_WEIGHT, - CY_BLE_UUID_CHAR_HEIGHT, - CY_BLE_UUID_CHAR_VO2_MAX, - CY_BLE_UUID_CHAR_HEART_RATE_MAX, - CY_BLE_UUID_CHAR_RESTING_HEART_RATE, - CY_BLE_UUID_CHAR_MRH, - CY_BLE_UUID_CHAR_AEROBIC_THRESHOLD, - CY_BLE_UUID_CHAR_ANAEROBIC_THRESHOLD, - CY_BLE_UUID_CHAR_STP, - CY_BLE_UUID_CHAR_DATE_OF_THRESHOLD_ASSESSMENT, - CY_BLE_UUID_CHAR_WAIST_CIRCUMFERENCE, - CY_BLE_UUID_CHAR_HIP_CIRCUNFERENCE, - CY_BLE_UUID_CHAR_FBL, - CY_BLE_UUID_CHAR_FBU, - CY_BLE_UUID_CHAR_AEL, - CY_BLE_UUID_CHAR_AEU, - CY_BLE_UUID_CHAR_ANL, - CY_BLE_UUID_CHAR_ANU, - CY_BLE_UUID_CHAR_FIVE_ZONE_HEART_RATE_LIMITS, - CY_BLE_UUID_CHAR_THREE_ZONE_HEART_RATE_LIMITS, - CY_BLE_UUID_CHAR_TWO_ZONE_HEART_RATE_LIMIT, - CY_BLE_UUID_CHAR_DATABASE_CHANGE_INCREMENT, - CY_BLE_UUID_CHAR_USER_INDEX, - CY_BLE_UUID_CHAR_USER_CONTROL_POINT, - CY_BLE_UUID_CHAR_LANGUAGE - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_UDS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - for(i = 0u; i < (uint32_t)CY_BLE_UDS_CHAR_COUNT; i++) - { - if(cy_ble_udscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_udsc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_udsc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_udsc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_udsc[discIdx].charInfo[i].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo->uuid); - } - } - } - - /* Init characteristic endHandle to Service endHandle. - * Characteristic endHandle will be updated to the declaration - * Handler of the following characteristic, - * in the following characteristic discovery procedure. */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][CY_BLE_SRVI_UDS].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to the characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_UDSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_UDS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_UDS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_udsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_udsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_UDSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_UDS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_UDS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_udsc[discIdx].charInfo[charIdx].endHandle - cy_ble_udsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_udsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_udsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_NotificationEventHandler -***************************************************************************//** -* -* Handles the Notification Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_UDSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_UDS_ApplCallback != NULL) && - (cy_ble_udsc[discIdx].charInfo[CY_BLE_UDS_DCI].valueHandle == eventParam->handleValPair.attrHandle)) - { - cy_stc_ble_uds_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_UDS_DCI, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_NOTIFICATION, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_IndicationEventHandler -***************************************************************************//** -* -* Handles the Indication Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_UDSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_UDS_ApplCallback != NULL)) - { - if(cy_ble_udsc[discIdx].charInfo[CY_BLE_UDS_UCP].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_uds_char_value_t locCharValue = - { - .charIndex = CY_BLE_UDS_UCP, - .connHandle = eventParam->connHandle, - .value = &eventParam->handleValPair.value - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_INDICATION, &locCharValue); - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles the Read Response Event. -* -* \param eventParam - The pointer to the data structure. -* -******************************************************************************/ -static void Cy_BLE_UDSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_udscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(Cy_BLE_UDS_ApplCallback != NULL) - { - cy_en_ble_uds_char_index_t i; - - for(i = CY_BLE_UDS_FNM; i < CY_BLE_UDS_CHAR_COUNT; i++) - { - if(cy_ble_udsc[discIdx].charInfo[i].valueHandle == cy_ble_udscReqHandle[discIdx]) - { - cy_stc_ble_uds_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = i, - .value = &eventParam->value - }; - - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_READ_CHAR_RESPONSE, &locCharValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - for(i = CY_BLE_UDS_FNM; i < CY_BLE_UDS_CHAR_COUNT; i++) - { - if(cy_ble_udsc[discIdx].charInfo[i].descrHandle[CY_BLE_UDS_CCCD] == cy_ble_udscReqHandle[discIdx]) - { - cy_stc_ble_uds_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = i, - .descrIndex = CY_BLE_UDS_CCCD, - .value = &eventParam->value - }; - - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_READ_DESCR_RESPONSE, &locDescrValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - } - - cy_ble_udscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_ReadLongRespEventHandler -***************************************************************************//** -* -* Handles a Read Long Response event. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -* -******************************************************************************/ -static void Cy_BLE_UDSC_ReadLongRespEventHandler(const cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - cy_stc_ble_gattc_stop_cmd_param_t stopCmdParam = { .connHandle = eventParam->connHandle }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_UDS_ApplCallback != NULL) && - (cy_ble_udscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - cy_stc_ble_uds_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - cy_stc_ble_gatt_value_t locGattValue; - - /* Go trough all long characteristics */ - for(locCharValue.charIndex = CY_BLE_UDS_FNM; locCharValue.charIndex < CY_BLE_UDS_CHAR_COUNT; - locCharValue.charIndex++) - { - if(locCharValue.charIndex == CY_BLE_UDS_AGE) - { - locCharValue.charIndex = CY_BLE_UDS_LNG; - } - - if(cy_ble_udsc[discIdx].charInfo[locCharValue.charIndex].valueHandle == cy_ble_udscReqHandle[discIdx]) - { - uint32_t i; - - /* Update user buffer with received data */ - for(i = 0u; i < eventParam->value.len; i++) - { - if(cy_ble_udscCurrLen[discIdx] < cy_ble_udscRdLongBuffLen[discIdx]) - { - cy_ble_udscRdLongBuffPtr[discIdx][cy_ble_udscCurrLen[discIdx]] = eventParam->value.val[i]; - cy_ble_udscCurrLen[discIdx]++; - } - else - { - (void)Cy_BLE_GATTC_StopCmd(&stopCmdParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - - if((cy_ble_eventHandlerFlag & CY_BLE_CALLBACK) != 0u) - { - cy_stc_ble_gatt_xchg_mtu_param_t mtuParam = - { - .connHandle = eventParam->connHandle - }; - - (void)Cy_BLE_GATT_GetMtuSize(&mtuParam); - - /* If received data length is less than MTU size, Read Long - * request is completed or provided user's buffer is full. - */ - if(((mtuParam.mtu - 1u) > eventParam->value.len)) - { - locGattValue.val = cy_ble_udscRdLongBuffPtr[discIdx]; - locGattValue.len = cy_ble_udscCurrLen[discIdx]; - locCharValue.value = &locGattValue; - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_READ_CHAR_RESPONSE, &locCharValue); - cy_ble_udscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles the Write Response Event. -* -* \param eventParam: The pointer to a data structure specified by the event. -* -******************************************************************************/ -static void Cy_BLE_UDSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_UDS_ApplCallback != NULL) && - (cy_ble_udscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_udsc[discIdx].charInfo[CY_BLE_UDS_UCP].valueHandle == cy_ble_udscReqHandle[discIdx]) - { - cy_stc_ble_uds_char_value_t locCharIndex = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_UDS_UCP, - .value = NULL - }; - - cy_ble_udscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_WRITE_CHAR_RESPONSE, &locCharIndex); - } - else - { - cy_en_ble_uds_char_index_t i; - - for(i = CY_BLE_UDS_FNM; i < CY_BLE_UDS_CHAR_COUNT; i++) - { - if(cy_ble_udsc[discIdx].charInfo[i].descrHandle[CY_BLE_UDS_CCCD] == cy_ble_udscReqHandle[discIdx]) - { - cy_stc_ble_uds_descr_value_t locDescIndex = - { - .connHandle = *eventParam, - .charIndex = i, - .descrIndex = CY_BLE_UDS_CCCD, - .value = NULL - }; - - cy_ble_udscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_WRITE_DESCR_RESPONSE, &locDescIndex); - break; - } - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_ExecuteWriteResponseEventHandler -***************************************************************************//** -* -* Handles a Execute Write Response event for the User Data Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_UDSC_ExecuteWriteResponseEventHandler(const cy_stc_ble_gattc_exec_write_rsp_t *eventParam) -{ - uint32_t i; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_UDS_ApplCallback != NULL) && - (cy_ble_udscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(i = 0u; i < ((uint8_t)CY_BLE_UDS_CHAR_COUNT); i++) - { - if(cy_ble_udsc[discIdx].charInfo[i].valueHandle == cy_ble_udscReqHandle[discIdx]) - { - cy_stc_ble_uds_char_value_t locCharVal = - { - .connHandle = eventParam->connHandle, - .charIndex = (cy_en_ble_uds_char_index_t)i, - .value = NULL - }; - - cy_ble_udscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_WRITE_CHAR_RESPONSE, &locCharVal); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_UDSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles the Error Response Event. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* -******************************************************************************/ -static void Cy_BLE_UDSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(cy_ble_udscReqHandle[discIdx] == eventParam->errInfo.attrHandle) - { - if((eventParam->errInfo.opCode == CY_BLE_GATT_READ_BLOB_REQ) && - (eventParam->errInfo.errorCode == CY_BLE_GATT_ERR_ATTRIBUTE_NOT_LONG)) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = eventParam->errInfo.attrHandle, - .connHandle = eventParam->connHandle - }; - - (void)Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - else - { - if(Cy_BLE_UDS_ApplCallback != NULL) - { - cy_stc_ble_uds_char_value_t locGattError = - { - .gattErrorCode = eventParam->errInfo.errorCode, - .connHandle = eventParam->connHandle, - .value = NULL - }; - - for(locGattError.charIndex = CY_BLE_UDS_FNM; locGattError.charIndex < CY_BLE_UDS_CHAR_COUNT; - locGattError.charIndex++) - { - if(cy_ble_udsc[discIdx].charInfo[locGattError.charIndex].valueHandle == - eventParam->errInfo.attrHandle) - { - Cy_BLE_UDS_ApplCallback((uint32_t)CY_BLE_EVT_UDSC_ERROR_RESPONSE, &locGattError); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } - - cy_ble_udscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - } -} - - -#endif /* CY_BLE_UDS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_UDS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the User Data Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_UDS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_UDS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_UDSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_UDSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_UDSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_UDS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_UDS_SERVER - case CY_BLE_EVT_GATT_DISCONNECT_IND: - (void)Cy_BLE_UDS_Init(cy_ble_udsConfigPtr); - break; - - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_UDSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_UDSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_PREP_WRITE_REQ: - Cy_BLE_UDSS_PrepareWriteRequestEventHandler((cy_stc_ble_gatts_prep_write_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_EXEC_WRITE_REQ: - Cy_BLE_UDSS_ExecuteWriteRequestEventHandler((cy_stc_ble_gatts_exec_write_req_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ: - Cy_BLE_UDSS_ReadRequestEventHandler((cy_stc_ble_gatts_char_val_read_req_t*)eventParam); - break; - #endif /* CY_BLE_UDS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_UDS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_UDSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_UDSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_UDSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_UDSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_UDSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_BLOB_RSP: - Cy_BLE_UDSC_ReadLongRespEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_EXEC_WRITE_RSP: - Cy_BLE_UDSC_ExecuteWriteResponseEventHandler((cy_stc_ble_gattc_exec_write_rsp_t*)eventParam); - break; - #endif /* CY_BLE_UDS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_UDS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_uds.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_uds.h deleted file mode 100644 index 680cfd67f3..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_uds.h +++ /dev/null @@ -1,259 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_uds.h -* \version 2.0 -* -* \brief -* This file contains the function prototypes and constants used in -* the User Data Service of the BLE Component. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_UDS_H -#define CY_BLE_UDS_H -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_UDS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define CY_BLE_UDS_FLAG_PROCESS (0x01u) -#define CY_BLE_UDS_LONG_CHAR_COUNT (3u) /* Count of long UDS characteristics */ - -/** - * \addtogroup group_ble_service_api_UDS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** UDS Service Characteristics indexes */ -typedef enum -{ - CY_BLE_UDS_FNM, /**< First Name characteristic index */ - CY_BLE_UDS_LNM, /**< Last Name characteristic index */ - CY_BLE_UDS_EML, /**< Email Address characteristic index */ - CY_BLE_UDS_AGE, /**< Age characteristic index */ - CY_BLE_UDS_DOB, /**< Date of Birth characteristic index */ - CY_BLE_UDS_GND, /**< Gender characteristic index */ - CY_BLE_UDS_WGT, /**< Weight characteristic index */ - CY_BLE_UDS_HGT, /**< Height characteristic index */ - CY_BLE_UDS_VO2, /**< VO2 Max characteristic index */ - CY_BLE_UDS_HRM, /**< Heart Rate Max characteristic index */ - CY_BLE_UDS_RHR, /**< Resting Heart Rate characteristic index */ - CY_BLE_UDS_MRH, /**< Maximum Recommended Heart Rate characteristic index */ - CY_BLE_UDS_AET, /**< Aerobic Threshold characteristic index */ - CY_BLE_UDS_ANT, /**< Anaerobic Threshold characteristic index */ - CY_BLE_UDS_STP, /**< Sport Type for Aerobic and Anaerobic Thresholds characteristic index */ - CY_BLE_UDS_DTA, /**< Date of Threshold Assessment characteristic index */ - CY_BLE_UDS_WCC, /**< Waist Circumference characteristic index */ - CY_BLE_UDS_HCC, /**< Hip Circumference characteristic index */ - CY_BLE_UDS_FBL, /**< Fat Burn Heart Rate Lower Limit characteristic index */ - CY_BLE_UDS_FBU, /**< Fat Burn Heart Rate Upper Limit characteristic index */ - CY_BLE_UDS_AEL, /**< Aerobic Heart Rate Lower Limit characteristic index */ - CY_BLE_UDS_AEU, /**< Aerobic Heart Rate Upper Limit characteristic index */ - CY_BLE_UDS_ANL, /**< Anaerobic Heart Rate Lower Limit characteristic index */ - CY_BLE_UDS_ANU, /**< Anaerobic Heart Rate Upper Limit characteristic index */ - CY_BLE_UDS_5ZL, /**< Five Zone Heart Rate Limits characteristic index */ - CY_BLE_UDS_3ZL, /**< Three Zone Heart Rate Limits characteristic index */ - CY_BLE_UDS_2ZL, /**< Two Zone Heart Rate Limit characteristic index */ - CY_BLE_UDS_DCI, /**< Database Change Increment characteristic index */ - CY_BLE_UDS_UIX, /**< User Index characteristic index */ - CY_BLE_UDS_UCP, /**< User Control Point characteristic index */ - CY_BLE_UDS_LNG, /**< Language characteristic index */ - CY_BLE_UDS_CHAR_COUNT /**< Total count of UDS characteristics */ -}cy_en_ble_uds_char_index_t; - -/** UDS Service Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_UDS_CCCD, /**< Client Characteristic Configuration descriptor index */ - CY_BLE_UDS_DESCR_COUNT /**< Total count of UDS descriptors */ -}cy_en_ble_uds_descr_index_t; - -/** User Data Server Characteristic structure type */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_UDS_DESCR_COUNT]; /**< Handle of descriptor */ -}cy_stc_ble_udss_char_t; - -/** Structure with User Data Service attribute handles */ -typedef struct -{ - /** User Data Service handle*/ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** User Data Service characteristics info array */ - cy_stc_ble_udss_char_t charInfo[CY_BLE_UDS_CHAR_COUNT]; -} cy_stc_ble_udss_t; - -/** User Data Client Characteristic structure type */ -typedef struct -{ - /** Properties for value field */ - uint8_t properties; - - /** Handle of server database attribute value entry */ - cy_ble_gatt_db_attr_handle_t valueHandle; - - /** User Data client char. descriptor handle */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_UDS_DESCR_COUNT]; - - /** Characteristic End Handle */ - cy_ble_gatt_db_attr_handle_t endHandle; -}cy_stc_ble_udsc_char_t; - -/** Structure with discovered attributes information of User Data Service */ -typedef struct -{ - cy_stc_ble_udsc_char_t charInfo[CY_BLE_UDS_CHAR_COUNT]; /**< Characteristics handle + properties array */ -}cy_stc_ble_udsc_t; - -/** UDS Characteristic Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_uds_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ - cy_en_ble_gatt_err_code_t gattErrorCode; /**< GATT error code for access control */ -} cy_stc_ble_uds_char_value_t; - -/** UDS Characteristic Descriptor Value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_uds_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_uds_descr_index_t descrIndex; /**< Index of service characteristic descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Descriptor value */ -} cy_stc_ble_uds_descr_value_t; - -/** Service configuration structure */ -typedef struct -{ - /** User Data Service GATT DB handles structure */ - const cy_stc_ble_udss_t *udss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_uds_config_t; - -/** @} */ - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_UDS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_UDS_Init(cy_stc_ble_uds_config_t *config); -cy_en_ble_api_result_t Cy_BLE_UDS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_UDS_SERVER -/** - * \addtogroup group_ble_service_api_UDS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_UDSS_SetCharacteristicValue(cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSS_GetCharacteristicValue(cy_en_ble_uds_char_index_t charIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - cy_en_ble_uds_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_UDS_SERVER */ - -#ifdef CY_BLE_UDS_CLIENT -/** - * \addtogroup group_ble_service_api_UDS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_UDSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_UDSC_GetLongCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, uint16_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - cy_en_ble_uds_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_UDSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_uds_char_index_t charIndex, - cy_en_ble_uds_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_UDS_CLIENT */ - - -/*************************************** -* Private Function Prototypes -***************************************/ - -/** \cond IGNORE */ - -/* Internal macros */ -#ifdef CY_BLE_UDS_SERVER -#define CY_BLE_UDS_IS_PROCEDURE_IN_PROGRESS (0u != (CY_BLE_UDS_FLAG_PROCESS & cy_ble_udsFlag)) -#endif /* CY_BLE_UDS_SERVER */ -/** \endcond */ - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_UDS_SERVER -extern uint8_t cy_ble_udsFlag; -#endif /* CY_BLE_UDSC_SERVER */ - -#ifdef CY_BLE_UDS_CLIENT -/* User Data Service server's GATT DB handles structure */ -extern cy_stc_ble_udsc_t cy_ble_udsc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_UDS_CLIENT */ - -extern cy_stc_ble_uds_config_t cy_ble_udsConfig; -extern cy_stc_ble_uds_config_t *cy_ble_udsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_UDS) */ -#endif /* CY_BLE_UDS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wpts.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wpts.c deleted file mode 100644 index e2701c8be9..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wpts.c +++ /dev/null @@ -1,1598 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_wpts.c -* \version 2.0 -* -* \brief -* Contains the source code for Wireless Power Transfer Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_WPTS)) - -#ifdef CY_BLE_WPTS_SERVER -static cy_ble_gatt_db_attr_handle_t cy_ble_wptssReqHandle; -#endif /* CY_BLE_WPTS_SERVER */ - -#ifdef CY_BLE_WPTS_CLIENT -/* WPTS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_wptsc_t cy_ble_wptsc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_wptscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; - -/* WPTS characteristics 128-bit UUIDs */ -const cy_stc_ble_uuid128_t cy_ble_wptscCharUuid128[CY_BLE_WPTS_CHAR_COUNT] = -{ - /* PRU Control Characteristic*/ - { { 0x67u, 0x9Au, 0x0Cu, 0x20u, 0x00u, 0x08u, 0x96u, 0x9Eu, 0xE2u, 0x11u, 0x46u, 0xA1u, 0x70u, 0xE6u, 0x55u, 0x64u } }, - /* PTU Static Parameter Characteristic*/ - { { 0x68u, 0x9Au, 0x0Cu, 0x20u, 0x00u, 0x08u, 0x96u, 0x9Eu, 0xE2u, 0x11u, 0x46u, 0xA1u, 0x70u, 0xE6u, 0x55u, 0x64u } }, - /* PRU Alert Characteristic*/ - { { 0x69u, 0x9Au, 0x0Cu, 0x20u, 0x00u, 0x08u, 0x96u, 0x9Eu, 0xE2u, 0x11u, 0x46u, 0xA1u, 0x70u, 0xE6u, 0x55u, 0x64u } }, - /* PRU Static Parameter Characteristic*/ - { { 0x6Au, 0x9Au, 0x0Cu, 0x20u, 0x00u, 0x08u, 0x96u, 0x9Eu, 0xE2u, 0x11u, 0x46u, 0xA1u, 0x70u, 0xE6u, 0x55u, 0x64u } }, - /* PRU Dynamic Parameter Characteristic*/ - { { 0x6Bu, 0x9Au, 0x0Cu, 0x20u, 0x00u, 0x08u, 0x96u, 0x9Eu, 0xE2u, 0x11u, 0x46u, 0xA1u, 0x70u, 0xE6u, 0x55u, 0x64u } } -}; - -#endif /* (CY_BLE_WPTS_CLIENT) */ - -static cy_ble_callback_t Cy_BLE_WPTS_ApplCallback = NULL; - -/* The pointer on global BLE WPTS Config structure */ -cy_stc_ble_wpts_config_t *cy_ble_wptsConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_WPTS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_WPTSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_WPTSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -#endif /* CY_BLE_WPTS_SERVER */ - -#ifdef CY_BLE_WPTS_CLIENT -static void Cy_BLE_WPTSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_WPTSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_WPTSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_WPTSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam); -static void Cy_BLE_WPTSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_WPTSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_WPTSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_WPTSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_WPTS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_WPTS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTS_Init -***************************************************************************//** -* -* This function initializes thr Wireless Power Transfer Service. -* -* \param config: Configuration structure for the Wireless Power Transfer Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTS_Init(cy_stc_ble_wpts_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_wptsConfigPtr = config; - - /* Registers Event Handler for the WPTS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_WPTS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_wptsConfigPtr->callbackFunc != NULL) - { - Cy_BLE_WPTS_ApplCallback = cy_ble_wptsConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_WPTS_SERVER - cy_ble_wptssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_WPTS_SERVER */ - - #ifdef CY_BLE_WPTS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_WPTS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_wptsc[idx], 0, sizeof(cy_stc_ble_wptsc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_WPTS].uuid = CY_BLE_UUID_WIRELESS_POWER_TRANSFER_SERVICE; - } - cy_ble_wptscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_WPTS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_WPTSS_INDICATION_ENABLED). -* * eventParam contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_wpts_char_value_t -* structure that contains details of the characteristic -* for which notification enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_WPTS_ApplCallback = callbackFunc; - if(cy_ble_wptsConfigPtr != NULL) - { - cy_ble_wptsConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_WPTS_SERVER - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a characteristic value of the Wireless Power Transfer Service in the -* local GATT database. The characteristic is identified by charIndex. -* -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was written successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSS_SetCharacteristicValue(cy_en_ble_wpts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex < CY_BLE_WPTS_CHAR_COUNT)) - { - /* Fill the structure */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_GetCharacteristicValue -***************************************************************************//** -* -* Reads a characteristic value of the Wireless Power Transfer Service, which -* is identified by charIndex from the GATT database. -* -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSS_GetCharacteristicValue(cy_en_ble_wpts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((attrValue != NULL) && (charIndex < CY_BLE_WPTS_CHAR_COUNT)) - { - /* Fill the structure */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle, - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Get characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_wpts_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data that should -* be stored to the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_WPTS_CHAR_COUNT) && (descrIndex < CY_BLE_WPTS_DESCR_COUNT) && (attrValue != NULL)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Set characteristic value to database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Reads a characteristic descriptor of a specified characteristic of the -* Wireless Power Transfer Service from the GATT database. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_wpts_descr_index_t. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the location where characteristic descriptor -* value data should be stored. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex < CY_BLE_WPTS_CHAR_COUNT) && (descrIndex < CY_BLE_WPTS_DESCR_COUNT) && (attrValue != NULL)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].descrHandle[descrIndex], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - /* Get descriptor value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_SendNotification -***************************************************************************//** -* -* Sends notification with a characteristic value of the WPTS, which is a value -* specified by charIndex, to the Client device. -* -* On enabling notification successfully for a service characteristic it sends out a -* 'Handle Value Notification' which results in CY_BLE_EVT_WPTSC_NOTIFICATION event -* at the GATT Client's end. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the Client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_NTF_DISABLED - Notification is not enabled by the Client. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_WPTS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((!CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle)) || - (!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_wptsConfigPtr->wptss->charInfo[charIndex]. - descrHandle[CY_BLE_WPTS_CCCD]))) - { - apiResult = CY_BLE_ERROR_NTF_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam = - { - .handleValPair.attrHandle = cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send notification to the Client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam); - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_SendIndication -***************************************************************************//** -* -* Sends an indication with a characteristic value of the Wireless Power Transfer -* Service, which is a value specified by charIndex, to the Client device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_WPTSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the Client device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WPTS service-specific callback is registered -* (with Cy_BLE_WPTS_RegisterAttrCallback): -* * CY_BLE_EVT_WPTSS_INDICATION_CONFIRMED - in case if the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the WPTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - in case if the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - - /* Send Notification if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(charIndex >= CY_BLE_WPTS_CHAR_COUNT) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - else if((!CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle)) || - (!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_wptsConfigPtr->wptss->charInfo[charIndex]. - descrHandle[CY_BLE_WPTS_CCCD]))) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_wptsConfigPtr->wptss->charInfo[charIndex].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to Client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - /* Save handle to support service-specific value confirmation response from Client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wptssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_WriteEventHandler -***************************************************************************//** -* -* Handles Write Request Event for Wireless Power Transfer Service. -* -* \param void *eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write is successful. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - Request is not supported. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - Write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - Offset value is invalid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_WPTSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_wpts_char_index_t locCharIndex; - cy_stc_ble_wpts_char_value_t locCharValue = { .connHandle = eventParam->connHandle }; - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t locReqHandle = 0u; - - if(Cy_BLE_WPTS_ApplCallback != NULL) - { - for(locCharIndex = CY_BLE_WPTS_PRU_CONTROL; (locCharIndex < CY_BLE_WPTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if((eventParam->handleValPair.attrHandle == - cy_ble_wptsConfigPtr->wptss->charInfo[locCharIndex].descrHandle[CY_BLE_WPTS_CCCD]) - || (eventParam->handleValPair.attrHandle == - cy_ble_wptsConfigPtr->wptss->charInfo[locCharIndex].charHandle)) - { - /* Store value to database */ - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - locCharValue.charIndex = locCharIndex; - locCharValue.value = &eventParam->handleValPair.value; - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - /* Characteristic value write request */ - if(eventParam->handleValPair.attrHandle == cy_ble_wptsConfigPtr->wptss->charInfo[locCharIndex]. - charHandle) - { - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSS_WRITE_CHAR, &locCharValue); - } - else /* Client Characteristic Configuration descriptor write request */ - { - /* Check characteristic properties for Notification */ - if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_wptsConfigPtr->wptss->charInfo[locCharIndex].charHandle)) - { - uint32_t eventCode; - if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_WPTSS_NOTIFICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_WPTSS_NOTIFICATION_DISABLED; - } - Cy_BLE_WPTS_ApplCallback(eventCode, &locCharValue); - } - /* Check characteristic properties for Indication */ - if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_wptsConfigPtr->wptss->charInfo[locCharIndex].charHandle)) - { - uint32_t eventCode; - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - eventCode = (uint32_t)CY_BLE_EVT_WPTSS_INDICATION_ENABLED; - } - else - { - eventCode = (uint32_t)CY_BLE_EVT_WPTSS_INDICATION_DISABLED; - } - Cy_BLE_WPTS_ApplCallback(eventCode, &locCharValue); - } - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - } - } - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - locReqHandle = 1u; - } - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* *eventParam - The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_WPTSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - cy_en_ble_wpts_char_index_t locCharIndex; - - uint32_t locReqHandle = 0u; - - if((Cy_BLE_WPTS_ApplCallback != NULL) && (cy_ble_wptssReqHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_WPTS_PRU_CONTROL; (locCharIndex < CY_BLE_WPTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_wptssReqHandle == cy_ble_wptsConfigPtr->wptss->charInfo[locCharIndex].charHandle) - { - /* Fill in event data and inform Application about successfully confirmed indication. */ - cy_stc_ble_wpts_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .value = NULL - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_wptssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSS_INDICATION_CONFIRMED, &locCharValue); - locReqHandle = 1u; - } - } - } -} - -#endif /* CY_BLE_WPTS_SERVER */ - - -#ifdef CY_BLE_WPTS_CLIENT - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_Discovery -***************************************************************************//** -* -* This function discovers the PRU's WPT service and characteristics using the -* GATT Primary Service Handle, received through the WPT Service Data -* within the PRU advertisement payload, together with the handle offsets defined -* A4WP specification. -* -* The PTU may perform service discovery using the Cy_BLE_GATTC_StartDiscovery(). -* This function may be used in response to Service Changed indication or to -* discover services other than the WPT service supported by the PRU. -* -* \param servHandle: GATT Primary Service Handle of the WPT service. -* \param connHandle: BLE peer device connection handle. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - All client instances are used. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSC_Discovery(cy_ble_gatt_db_attr_handle_t servHandle, - cy_stc_ble_conn_handle_t connHandle) -{ - uint32_t discIdx; - cy_en_ble_api_result_t apiResult; - - apiResult = Cy_BLE_GATTC_AddConnHandle(connHandle); - - if(apiResult == CY_BLE_SUCCESS) - { - discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - cy_ble_wptsc[discIdx].serviceHandle = servHandle; - cy_ble_wptsc[discIdx].charInfo[CY_BLE_WPTS_PRU_CONTROL].valueHandle = - servHandle + CY_BLE_WPTS_PRU_CONTROL_CHAR_VALUE_OFFSET; - cy_ble_wptsc[discIdx].charInfo[CY_BLE_WPTS_PTU_STATIC_PAR].valueHandle = - servHandle + CY_BLE_WPTS_PTU_STATIC_PAR_CHAR_VALUE_OFFSET; - cy_ble_wptsc[discIdx].charInfo[CY_BLE_WPTS_PRU_ALERT].valueHandle = - servHandle + CY_BLE_WPTS_PRU_ALERT_PAR_CHAR_VALUE_OFFSET; - cy_ble_wptsc[discIdx].charInfo[CY_BLE_WPTS_PRU_ALERT].descrHandle[CY_BLE_WPTS_CCCD] = - servHandle + CY_BLE_WPTS_PRU_ALERT_PAR_CHAR_CCCD_OFFSET; - cy_ble_wptsc[discIdx].charInfo[CY_BLE_WPTS_PRU_STATIC_PAR].valueHandle = - servHandle + CY_BLE_WPTS_PRU_STATIC_PAR_CHAR_VALUE_OFFSET; - cy_ble_wptsc[discIdx].charInfo[CY_BLE_WPTS_PRU_DYNAMIC_PAR].valueHandle = - servHandle + CY_BLE_WPTS_PRU_DYNAMIC_PAR_CHAR_VALUE_OFFSET; - - Cy_BLE_SetConnectionState(connHandle, CY_BLE_CONN_STATE_CLIENT_DISCOVERED); - } - return(apiResult); -} - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - - /* WPTS service has only characteristics with 128-bit UUIDs */ - if((discCharInfo->uuidFormat == CY_BLE_GATT_128_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_WPTS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - /* Compare common part of characteristics 128-bit UUID (except first byte) */ - if(memcmp(&cy_ble_wptscCharUuid128[CY_BLE_WPTS_PRU_CONTROL].value[1u], - &discCharInfo->uuid.uuid128.value[1u], CY_BLE_GATT_128_BIT_UUID_SIZE - 1u) == 0u) - { - /* Check the range of the first byte to be between the first and last characteristic */ - if((discCharInfo->uuid.uuid128.value[0u] >= cy_ble_wptscCharUuid128[CY_BLE_WPTS_PRU_CONTROL].value[0u]) && - (discCharInfo->uuid.uuid128.value[0u] <= cy_ble_wptscCharUuid128[CY_BLE_WPTS_CHAR_COUNT - 1u].value[0u])) - { - uint32_t locCharIndex; - locCharIndex = (uint32_t)discCharInfo->uuid.uuid128.value[0u] - - cy_ble_wptscCharUuid128[CY_BLE_WPTS_PRU_CONTROL].value[0u]; - /* Verify that characteristic handler is not assigned already */ - if(cy_ble_wptsc[discIdx].charInfo[locCharIndex].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_wptsc[discIdx].charInfo[locCharIndex].valueHandle = discCharInfo->valueHandle; - cy_ble_wptsc[discIdx].charInfo[locCharIndex].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_wptsc[discIdx].charInfo[locCharIndex].endHandle; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Initialize characteristic endHandle to Service endHandle. Characteristic endHandle - * will be updated to the declaration handler of the following characteristic, - * in the following characteristic discovery procedure. - */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_WPTS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_WPTS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_wptsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_wptsc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_WPTS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_WPTS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_wptsc[discIdx].charInfo[charIdx].endHandle - - cy_ble_wptsc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_wptsc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_wptsc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_NotificationEventHandler -***************************************************************************//** -* -* Handles notification event for Wireless Power Transfer Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam) -{ - cy_en_ble_wpts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WPTS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_WPTS_PRU_CONTROL; locCharIndex < CY_BLE_WPTS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_wptsc[discIdx].charInfo[locCharIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_wpts_char_value_t notifValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSC_NOTIFICATION, ¬ifValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an indication event for Wireless Power Transfer Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - cy_en_ble_wpts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WPTS_ApplCallback != NULL)) - { - for(locCharIndex = CY_BLE_WPTS_PRU_CONTROL; locCharIndex < CY_BLE_WPTS_CHAR_COUNT; locCharIndex++) - { - if(cy_ble_wptsc[discIdx].charInfo[locCharIndex].valueHandle == eventParam->handleValPair.attrHandle) - { - cy_stc_ble_wpts_char_value_t indicationValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - break; - } - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event for the Wireless Power Transfer Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint32_t locReqHandle = 0u; - cy_en_ble_wpts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WPTS_ApplCallback != NULL) && - (cy_ble_wptscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_WPTS_PRU_CONTROL; (locCharIndex < CY_BLE_WPTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_wptscReqHandle[discIdx] == cy_ble_wptsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_wpts_char_value_t locCharValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .value = &eventParam->value - }; - cy_ble_wptscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSC_READ_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else if(cy_ble_wptscReqHandle[discIdx] == cy_ble_wptsc[discIdx].charInfo[locCharIndex]. - descrHandle[CY_BLE_WPTS_CCCD]) - { - cy_stc_ble_wpts_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = locCharIndex, - .descrIndex = CY_BLE_WPTS_CCCD, - .value = &eventParam->value - }; - cy_ble_wptscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSC_READ_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - else /* No more descriptors available */ - { - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event for the Wireless Power Transfer Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - uint32_t locReqHandle = 0u; - cy_en_ble_wpts_char_index_t locCharIndex; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - /* Check if service handler was registered and request handle is valid */ - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WPTS_ApplCallback != NULL) && - (cy_ble_wptscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - for(locCharIndex = CY_BLE_WPTS_PRU_CONTROL; (locCharIndex < CY_BLE_WPTS_CHAR_COUNT) && (locReqHandle == 0u); - locCharIndex++) - { - if(cy_ble_wptscReqHandle[discIdx] == cy_ble_wptsc[discIdx].charInfo[locCharIndex].valueHandle) - { - cy_stc_ble_wpts_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .value = NULL - }; - cy_ble_wptscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSC_WRITE_CHAR_RESPONSE, &locCharValue); - locReqHandle = 1u; - } - else if(cy_ble_wptscReqHandle[discIdx] == cy_ble_wptsc[discIdx].charInfo[locCharIndex]. - descrHandle[CY_BLE_WPTS_CCCD]) - { - cy_stc_ble_wpts_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = locCharIndex, - .descrIndex = CY_BLE_WPTS_CCCD, - .value = NULL - }; - cy_ble_wptscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WPTS_ApplCallback((uint32_t)CY_BLE_EVT_WPTSC_WRITE_DESCR_RESPONSE, &locDescrValue); - locReqHandle = 1u; - } - else /* No more descriptors available */ - { - } - } - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event for the Wireless Power Transfer Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WPTSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_wptscReqHandle[discIdx]) - { - cy_ble_wptscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_SetCharacteristicValue -***************************************************************************//** -* -* This function is used to write the characteristic (which is identified by -* charIndex) value attribute in the server. As a result a Write Request is -* sent to the GATT Server and on successful execution of the request on the -* Server side the CY_BLE_EVT_WPTSS_WRITE_CHAR events is generated. -* On successful request execution on the Server side the Write Response is -* sent to the Client. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that -* should be send to the server device. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WPTS service-specific callback is registered -* (with Cy_BLE_WPTS_RegisterAttrCallback): -* * CY_BLE_EVT_WPTSC_WRITE_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_wpts_char_value_t. -* . -* Otherwise (if the WPTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - uint8_t attrSize, - uint8_t * attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WPTS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_wptsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_wptsc[discIdx].charInfo[charIndex].valueHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_WriteCharacteristicValue(&writeReqParam); - /* Save handle to support service-specific write response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wptscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* -* \return -* Return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WPTS service-specific callback is registered -* (with Cy_BLE_WPTS_RegisterAttrCallback): -* * CY_BLE_EVT_WPTSC_READ_CHAR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with event parameter structure -* of type cy_stc_ble_wpts_char_value_t. -* . -* Otherwise (if the WPTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WPTS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_wptsc[discIdx].charInfo[charIndex].valueHandle != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_wptsc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wptscReqHandle[discIdx] = cy_ble_wptsc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the server, -* which is identified by charIndex and descrIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_WPTSS_NOTIFICATION_ENABLED -* * CY_BLE_EVT_WPTSS_NOTIFICATION_DISABLED -* * CY_BLE_EVT_WPTSS_INDICATION_ENABLED -* * CY_BLE_EVT_WPTSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_wpts_descr_index_t. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WPTS service-specific callback is registered -* (with Cy_BLE_WPTS_RegisterAttrCallback): -* * CY_BLE_EVT_WPTSC_WRITE_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_wpts_descr_value_t. -* . -* Otherwise (if the WPTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - in case if the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WPTS_CHAR_COUNT) || (descrIndex >= CY_BLE_WPTS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_wptsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wptscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WPTSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of a service characteristic of type -* cy_en_ble_wpts_char_index_t. -* \param descrIndex: The index of a service characteristic descriptor of type -* cy_en_ble_wpts_descr_index_t. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WPTS service-specific callback is registered -* (with Cy_BLE_WPTS_RegisterAttrCallback): -* * CY_BLE_EVT_WPTSC_READ_DESCR_RESPONSE - in case if the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with event parameter structure -* of type cy_stc_ble_wpts_descr_value_t. -* . -* Otherwise (if the WPTS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - in case if the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - in case if there is some trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WPTSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WPTS_CHAR_COUNT) || (descrIndex >= CY_BLE_WPTS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_wptsc[discIdx].charInfo[charIndex].descrHandle[descrIndex], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wptscReqHandle[discIdx] = cy_ble_wptsc[discIdx].charInfo[charIndex].descrHandle[descrIndex]; - } - } - - return(apiResult); -} - -#endif /* CY_BLE_WPTS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_WPTS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Wireless Power Transfer Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_WPTS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_WPTS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_WPTSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_WPTSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_WPTSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_WPTS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_WPTS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_WPTSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_WPTSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_WPTS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_WPTS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_WPTSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_NTF: - Cy_BLE_WPTSC_NotificationEventHandler((cy_stc_ble_gattc_handle_value_ntf_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_WPTSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_WPTSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_WPTSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_WPTS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_WPTS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wpts.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wpts.h deleted file mode 100644 index 2631d827b2..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wpts.h +++ /dev/null @@ -1,246 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_wpts.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Wireless Power Transfer -* Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_WPTS_H -#define CY_BLE_WPTS_H - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_WPTS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * \addtogroup group_ble_service_api_WPTS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** WPTS Characteristic indexes */ -typedef enum -{ - CY_BLE_WPTS_PRU_CONTROL, /**< PRU Control Characteristic index */ - CY_BLE_WPTS_PTU_STATIC_PAR, /**< PTU Static Parameter Characteristic index */ - CY_BLE_WPTS_PRU_ALERT, /**< PRU Alert Characteristic index */ - CY_BLE_WPTS_PRU_STATIC_PAR, /**< PRU Static Parameter Characteristic index */ - CY_BLE_WPTS_PRU_DYNAMIC_PAR, /**< PRU Dynamic Parameter Characteristic index */ - CY_BLE_WPTS_CHAR_COUNT /**< Total count of WPTS Characteristics */ -}cy_en_ble_wpts_char_index_t; - -/** WPTS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_WPTS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_WPTS_DESCR_COUNT /**< Total count of Descriptors */ -}cy_en_ble_wpts_descr_index_t; - -/** Characteristic with descriptors */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t charHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_WPTS_DESCR_COUNT]; /**< Handle of descriptor */ -} cy_stc_ble_wptss_char_t; - -/** WPTS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_wpts_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_wpts_char_value_t; - -/** WPTS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_wpts_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_wpts_descr_index_t descrIndex; /**< Index of descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_wpts_descr_value_t; - -/** WPTS Server Characteristic structure type */ -typedef struct -{ - /** Wireless Power Transfer Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Wireless Power Transfer Characteristic handles */ - cy_stc_ble_wptss_char_t charInfo[CY_BLE_WPTS_CHAR_COUNT]; -} cy_stc_ble_wptss_t; - -/** Characteristic information structure */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_WPTS_DESCR_COUNT]; /**< Handles of descriptors */ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of a characteristic */ - uint8_t properties; /**< Properties for value field */ -} cy_stc_ble_wptsc_char_t; - -/** WPTS Characteristic with descriptors */ -typedef struct -{ - /** Wireless Power Transfer Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - /** Wireless Power Transfer Service characteristics info structure */ - cy_stc_ble_wptsc_char_t charInfo[CY_BLE_WPTS_CHAR_COUNT]; -} cy_stc_ble_wptsc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Wireless Power Transfer Service GATT DB handles structure */ - const cy_stc_ble_wptss_t *wptss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_wpts_config_t; - -/** @} */ - -/*************************************** -* API Constants -***************************************/ - -/* WPT service handle offsets */ -#define CY_BLE_WPTS_WPT_SERVICE_OFFSET (0x00u) -#define CY_BLE_WPTS_PRU_CONTROL_CHAR_DECL_OFFSET (0x01u) -#define CY_BLE_WPTS_PRU_CONTROL_CHAR_VALUE_OFFSET (0x02u) -#define CY_BLE_WPTS_PTU_STATIC_PAR_CHAR_DECL_OFFSET (0x03u) -#define CY_BLE_WPTS_PTU_STATIC_PAR_CHAR_VALUE_OFFSET (0x04u) -#define CY_BLE_WPTS_PRU_ALERT_PAR_CHAR_DECL_OFFSET (0x05u) -#define CY_BLE_WPTS_PRU_ALERT_PAR_CHAR_VALUE_OFFSET (0x06u) -#define CY_BLE_WPTS_PRU_ALERT_PAR_CHAR_CCCD_OFFSET (0x07u) -#define CY_BLE_WPTS_PRU_STATIC_PAR_CHAR_DECL_OFFSET (0x08u) -#define CY_BLE_WPTS_PRU_STATIC_PAR_CHAR_VALUE_OFFSET (0x09u) -#define CY_BLE_WPTS_PRU_DYNAMIC_PAR_CHAR_DECL_OFFSET (0x0Au) -#define CY_BLE_WPTS_PRU_DYNAMIC_PAR_CHAR_VALUE_OFFSET (0x0Bu) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_WPTS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_WPTS_Init(cy_stc_ble_wpts_config_t *config); -cy_en_ble_api_result_t Cy_BLE_WPTS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_WPTS_SERVER -/** - * \addtogroup group_ble_service_api_WPTS_server - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_WPTSS_SetCharacteristicValue(cy_en_ble_wpts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSS_GetCharacteristicValue(cy_en_ble_wpts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSS_SendNotification(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_WPTS_SERVER */ - -#ifdef CY_BLE_WPTS_CLIENT -/** - * \addtogroup group_ble_service_api_WPTS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_WPTSC_Discovery(cy_ble_gatt_db_attr_handle_t servHandle, - cy_stc_ble_conn_handle_t connHandle); - -cy_en_ble_api_result_t Cy_BLE_WPTSC_SetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, uint8_t attrSize, - uint8_t * attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_WPTSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex, - uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WPTSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wpts_char_index_t charIndex, - cy_en_ble_wpts_descr_index_t descrIndex); - -/** @} */ -#endif /* CY_BLE_WPTS_CLIENT */ - - -/* ##Macro Functions */ -#ifdef CY_BLE_WPTS_CLIENT - -#define Cy_BLE_WPTSC_GetCharacteristicValueHandle(connHandle, charIndex) \ - (((charIndex) >= CY_BLE_WPTS_CHAR_COUNT) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_wptsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].valueHandle) - -#define Cy_BLE_WPTSC_GetCharacteristicDescriptorHandle(connHandle, charIndex, descrIndex) \ - ((((charIndex) >= CY_BLE_WPTS_CHAR_COUNT) || ((descrIndex) >= CY_BLE_WPTS_DESCR_COUNT)) ? \ - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE : \ - cy_ble_wptsc[Cy_BLE_GetDiscoveryIdx(connHandle)].charInfo[charIndex].descrHandle[descrIndex]) - -#endif /* (CY_BLE_WPTS_CLIENT) */ - - -/*************************************** -* External data references -***************************************/ -#ifdef CY_BLE_WPTS_CLIENT -extern cy_stc_ble_wptsc_t cy_ble_wptsc[CY_BLE_CONFIG_GATTC_COUNT]; -extern const cy_stc_ble_uuid128_t cy_ble_wptscCharUuid128[CY_BLE_WPTS_CHAR_COUNT]; -#endif /* CY_BLE_WPTS_CLIENT */ - -extern cy_stc_ble_wpts_config_t cy_ble_wptsConfig; -extern cy_stc_ble_wpts_config_t *cy_ble_wptsConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_WPTS) */ -#endif /* CY_BLE_WPTS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wss.c b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wss.c deleted file mode 100644 index 89d7071be5..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wss.c +++ /dev/null @@ -1,1473 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_wss.c -* \version 2.0 -* -* \brief -* Contains the source code for the Weight Scale Service. -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - -#include "cy_ble_event_handler.h" - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_WSS)) - -#ifdef CY_BLE_WSS_SERVER -/* The internal storage for the last request handle to check response for server */ -static cy_ble_gatt_db_attr_handle_t cy_ble_wsssReqHandle; -#endif /* CY_BLE_WSS_SERVER */ - -#ifdef CY_BLE_WSS_CLIENT -/* WSS Center Service characteristics GATT DB handles structure */ -cy_stc_ble_wssc_t cy_ble_wssc[CY_BLE_CONFIG_GATTC_COUNT]; - -/* The internal storage for the last request handle to check response */ -static cy_ble_gatt_db_attr_handle_t cy_ble_wsscReqHandle[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* (CY_BLE_WSS_CLIENT) */ - -static cy_ble_callback_t Cy_BLE_WSS_ApplCallback = NULL; - -/* The pointer on global BLE WSS Config structure */ -cy_stc_ble_wss_config_t *cy_ble_wssConfigPtr = NULL; - -/*************************************** -* Private Function Prototypes -***************************************/ -#ifdef CY_BLE_WSS_SERVER -static cy_en_ble_gatt_err_code_t Cy_BLE_WSSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam); -static void Cy_BLE_WSSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -#endif /* CY_BLE_WSS_SERVER */ - -#ifdef CY_BLE_WSS_CLIENT -static void Cy_BLE_WSSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo); -static void Cy_BLE_WSSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo); -static void Cy_BLE_WSSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo); -static void Cy_BLE_WSSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam); -static void Cy_BLE_WSSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam); -static void Cy_BLE_WSSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam); -static void Cy_BLE_WSSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam); -#endif /* CY_BLE_WSS_CLIENT */ -static cy_en_ble_gatt_err_code_t Cy_BLE_WSS_EventHandler(uint32_t eventCode, void *eventParam); - - -/****************************************************************************** -* Function Name: Cy_BLE_WSS_Init -***************************************************************************//** -* -* This function initializes Weight Scale Service. -* -* \param config: Configuration structure for the Weight Scale Service. -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes. -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter -* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSS_Init(cy_stc_ble_wss_config_t *config) -{ - cy_en_ble_api_result_t apiResult; - - if(config == NULL) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - /* Registers a pointer to config structure */ - cy_ble_wssConfigPtr = config; - - /* Registers Event Handler for the WSS Service */ - apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_WSS_EventHandler); - - /* Registers a callback function via config structure */ - if(cy_ble_wssConfigPtr->callbackFunc != NULL) - { - Cy_BLE_WSS_ApplCallback = cy_ble_wssConfigPtr->callbackFunc; - } - - #ifdef CY_BLE_WSS_SERVER - cy_ble_wsssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - #endif /* CY_BLE_WSS_SERVER */ - - #ifdef CY_BLE_WSS_CLIENT - { - uint32_t idx; - for(idx = 0u; idx < CY_BLE_CONFIG_GATTC_COUNT; idx++) - { - if(cy_ble_serverInfo[idx][CY_BLE_SRVI_WSS].range.startHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - (void)memset(&cy_ble_wssc[idx], 0, sizeof(cy_stc_ble_wssc_t)); - - /* initialize uuid */ - cy_ble_serverInfo[idx][CY_BLE_SRVI_WSS].uuid = CY_BLE_UUID_WEIGHT_SCALE_SERVICE; - } - cy_ble_wsscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } - #endif /* CY_BLE_WSS_CLIENT */ - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSS_RegisterAttrCallback -***************************************************************************//** -* -* Registers a callback function for service-specific attribute operations. -* Service specific write requests from peer device will not be handled with -* unregistered callback function. -* -* \param callbackFunc: An application layer event callback function to receive -* events from the BLE Component. The definition of -* cy_ble_callback_t is: \n -* typedef void (* cy_ble_callback_t) (uint32_t eventCode, -* void *eventParam) -* * eventCode - Indicates the event that triggered this -* callback (e.g. CY_BLE_EVT_WSSS_INDICATION_ENABLED). -* * eventParam - Contains the parameters corresponding to the -* current event. (e.g. pointer to cy_stc_ble_wss_char_value_t -* structure that contains details of the characteristic -* for which an indication enabled event was triggered). -* -* \return -* cy_en_ble_api_result_t : Return value indicates if the function succeeded or -* failed. The following are possible error codes: -* -* Error Codes | Description -* ------------ | ----------- -* CY_BLE_SUCCESS | The function completed successfully. -* CY_BLE_ERROR_INVALID_OPERATION | This operation is not permitted -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSS_RegisterAttrCallback(cy_ble_callback_t callbackFunc) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS; - - Cy_BLE_WSS_ApplCallback = callbackFunc; - if(cy_ble_wssConfigPtr != NULL) - { - cy_ble_wssConfigPtr->callbackFunc = callbackFunc; - } - else - { - apiResult = CY_BLE_ERROR_INVALID_OPERATION; - } - - return(apiResult); -} - - -#ifdef CY_BLE_WSS_SERVER - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_WriteEventHandler -***************************************************************************//** -* -* Handles Write Request Event for Weight Scale Service. -* -* \param eventParam: The pointer to the data structure specified by the event. -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* * CY_BLE_GATT_ERR_NONE - Write is successful. -* * CY_BLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The request is not supported. -* * CY_BLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid. -* * CY_BLE_GATT_ERR_WRITE_NOT_PERMITTED - The write operation is not permitted on -* this attribute. -* * CY_BLE_GATT_ERR_INVALID_OFFSET - The offset value is invalid. -* * CY_BLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_WSSS_WriteEventHandler(const cy_stc_ble_gatts_write_cmd_req_param_t *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - uint32_t event = (uint32_t)CY_BLE_EVT_WSSS_INDICATION_DISABLED; - - if(Cy_BLE_WSS_ApplCallback != NULL) - { - /* Client Characteristic Configuration descriptor write request */ - if(eventParam->handleValPair.attrHandle == - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD]) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair = eventParam->handleValPair, - .connHandle = eventParam->connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_PEER_INITIATED - }; - - if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val)) - { - event = (uint32_t)CY_BLE_EVT_WSSS_INDICATION_ENABLED; - } - gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo); - - if(gattErr == CY_BLE_GATT_ERR_NONE) - { - cy_stc_ble_wss_char_value_t wrReqParam = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_WSS_WEIGHT_MEASUREMENT, - .value = NULL - }; - Cy_BLE_WSS_ApplCallback(event, &wrReqParam); - } - - #if ((CY_BLE_GAP_ROLE_PERIPHERAL || CY_BLE_GAP_ROLE_CENTRAL) && \ - (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES)) - /* Set flag to store bonding data to flash */ - if(cy_ble_peerBonding[eventParam->connHandle.attId] == CY_BLE_GAP_BONDING) - { - cy_ble_pendingFlashWrite |= CY_BLE_PENDING_CCCD_FLASH_WRITE_BIT; - } - #endif /* (CY_BLE_BONDING_REQUIREMENT == CY_BLE_BONDING_YES) */ - - /* Clear callback flag indicating that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } - - return(gattErr); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_ConfirmationEventHandler -***************************************************************************//** -* -* Handles a Value Confirmation request event from the BLE stack. -* -* \param eventParam: The pointer to a structure of type cy_stc_ble_conn_handle_t. -* -******************************************************************************/ -static void Cy_BLE_WSSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - if((Cy_BLE_WSS_ApplCallback != NULL) && (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_wsssReqHandle)) - { - /* Only Weight Measurement Characteristic has the Indication property. Check if - * the requested handle is the handle of the Descriptor Value Change handle. - */ - if(cy_ble_wsssReqHandle == cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].charHandle) - { - /* Fill in event data and inform Application about successfully - * confirmed indication. - */ - cy_stc_ble_wss_char_value_t locCharValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_WSS_WEIGHT_MEASUREMENT, - .value = NULL - }; - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - cy_ble_wsssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WSS_ApplCallback((uint32_t)CY_BLE_EVT_WSSS_INDICATION_CONFIRMED, &locCharValue); - } - } -} - - -#if (CY_BLE_GAP_ROLE_PERIPHERAL) - -/****************************************************************************** -* Function Name: Cy_BLE_WSS_SetAdUserId -***************************************************************************//** -* -* Sets the User ID List to the advertisement packet. To be able to set the -* User ID List with this function, the advertisement packet should be -* configured in the component GUI to include Weight Scale Service UUID in the -* Service Data field. The Service Data should have enough room to fit the -* User ID List that is planned to be advertised. To reserve the room for the -* User ID List, the Service Data for WSS should be filled with Unknown User -* ID - 0xFF. The amount of 0xFF's should be equal to User List Size that is -* planned to be advertised. -* This function must be called when Cy_BLE_GetBleSsState() returns -* CY_BLE_BLESS_STATE_EVENT_CLOSE state. -* -* \param listSize: The size of the User List. -* \param userIdList: The array contains a User List. -* \param advertisingParamIndex: The index of the peripheral and broadcast -* configuration in customizer. For example: -* * CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX 0x00 -* * CY_BLE_BROADCASTER_CONFIGURATION_0_INDEX 0x01 -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - On NULL pointer, Data length in input -* parameter exceeds maximum advertisement packet length. -* * CY_BLE_ERROR_INVALID_OPERATION - The advertisement packet doesn't contain -* the User List or it is to small or ADV Event is not closed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSS_SetAdUserId(uint8_t listSize, - const uint8_t userIdList[], - uint8_t advertisingParamIndex) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_OPERATION; - uint32_t i; - uint32_t fFlag = 0u; - uint8_t adLength = 0u; - uint8_t byteCounter = 0u; - - if((advertisingParamIndex >= CY_BLE_GAPP_CONF_COUNT) || (userIdList == NULL) || - (listSize > (CY_BLE_GAP_MAX_ADV_DATA_LEN - CY_BLE_AD_SERVICE_DATA_OVERHEAD))) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else - { - while((byteCounter < cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advDataLen) && - (fFlag == 0u)) - { - adLength = cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter]; - - if(adLength != 0u) - { - uint16_t servUuid; - - /* Increment byte counter so that it points to AD type field */ - byteCounter++; - - servUuid = Cy_BLE_Get16ByPtr(&cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData-> - advData[byteCounter + 1u]); - - /* Check if "Service Data" AD type is found and service UUID is WSS UUID */ - if((cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter] == - CY_BLE_AD_TYPE_SERVICE_DATA) && (servUuid == CY_BLE_UUID_WEIGHT_SCALE_SERVICE)) - { - /* WSS Service Data was found. Set flag and exit the loop. */ - fFlag = 1u; - } - else - { - byteCounter += adLength; - } - } - else - { - /* End of advertisement data structure was encountered so exit loop. */ - break; - } - } - if(fFlag != 0u) - { - /* Check if there is enough space to fit user index list */ - if((adLength - CY_BLE_AD_SERVICE_DATA_OVERHEAD) >= listSize) - { - /* Increment byte counter so that it points to data value */ - byteCounter += CY_BLE_AD_SERVICE_DATA_OVERHEAD; - - for(i = 0u; i < ((uint32_t)adLength - CY_BLE_AD_SERVICE_DATA_OVERHEAD); i++) - { - if(i <= listSize) - { - /* Copy user index element to advertisement data byte */ - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter + i] = - userIdList[i]; - } - else - { - /* Fill remaining bytes with "Unknown User" ID */ - cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter + i] = - CY_BLE_WSS_UNKNOWN_USER; - } - } - - /* We are done. Indicate success. */ - apiResult = CY_BLE_SUCCESS; - - if((Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING) && - (cy_ble_advIndex == advertisingParamIndex)) - { - /* Update the advertisement packet if the device is in the advertising mode. */ - apiResult = Cy_BLE_GAPP_UpdateAdvScanData(&cy_ble_configPtr->discoveryModeInfo[cy_ble_advIndex]); - } - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSS_GetAdUserIdListSize -***************************************************************************//** -* -* Returns the size (in bytes) of User ID List in the advertisement packet. -* -* \param advertisingParamIndex: The index of the peripheral and broadcast -* configuration in customizer. For example: -* * CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX 0x00 -* * CY_BLE_BROADCASTER_CONFIGURATION_0_INDEX 0x01 -* -* \return -* Size of User ID List. -* -******************************************************************************/ -uint8_t Cy_BLE_WSS_GetAdUserIdListSize(uint8_t advertisingParamIndex) -{ - uint8_t uiCount = 0u; - uint8_t adLength = 0u; - uint32_t fFlag = 0u; - uint8_t byteCounter = 0u; - - if(advertisingParamIndex >= CY_BLE_GAPP_CONF_COUNT) - { - uiCount = 0u; - } - else - { - while((byteCounter < cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advDataLen)) - { - adLength = cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter]; - - if(adLength != 0u) - { - uint16_t servUuid; - - /* Increment byte counter so that it points to AD type field */ - byteCounter++; - - servUuid = Cy_BLE_Get16ByPtr(&cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData-> - advData[byteCounter + 1u]); - - /* Check if "Service Data" AD type is found and service UUID is WSS UUID */ - if((cy_ble_configPtr->discoveryModeInfo[advertisingParamIndex].advData->advData[byteCounter] == - CY_BLE_AD_TYPE_SERVICE_DATA) && (servUuid == CY_BLE_UUID_WEIGHT_SCALE_SERVICE)) - { - /* WSS Service Data was found. Set flag and exit the loop. */ - fFlag = 1u; - } - else - { - byteCounter += adLength; - } - } - else - { - /* End of advertisement data structure was encountered so exit loop. */ - break; - } - } - if(fFlag != 0u) - { - uiCount = adLength - CY_BLE_AD_SERVICE_DATA_OVERHEAD; - } - } - - return(uiCount); -} - -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_SetCharacteristicValue -***************************************************************************//** -* -* Sets a value for one of two characteristic values of the Weight Scale -* Service. The characteristic is identified by charIndex. -* -* \param charIndex: The index of a Weight Scale Service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* stored to the GATT database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was written successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSS_SetCharacteristicValue(cy_en_ble_wss_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if((attrValue != NULL) && (charIndex < CY_BLE_WSS_CHAR_COUNT)) - { - /* Fill structure */ - if(charIndex == CY_BLE_WSS_WEIGHT_SCALE_FEATURE) - { - dbAttrValInfo.handleValuePair.attrHandle = - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_SCALE_FEATURE].charHandle; - } - else - { - dbAttrValInfo.handleValuePair.attrHandle = - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].charHandle; - } - - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_GetCharacteristicValue -***************************************************************************//** -* -* Reads a characteristic value of the Weight Scale Service, which is identified -* by charIndex from the GATT database. -* -* \param charIndex: The index of the Weight Scale Service characteristic. -* \param attrSize: The size of the Weight Scale Service characteristic value attribute. -* \param attrValue: The pointer to the location where characteristic value data -* should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The characteristic value was read successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSS_GetCharacteristicValue(cy_en_ble_wss_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - - if((attrValue != NULL) && (charIndex < CY_BLE_WSS_CHAR_COUNT)) - { - if(charIndex == CY_BLE_WSS_WEIGHT_SCALE_FEATURE) - { - dbAttrValInfo.handleValuePair.attrHandle = - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_SCALE_FEATURE].charHandle; - } - else - { - dbAttrValInfo.handleValuePair.attrHandle = - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].charHandle; - } - - /* Get characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - - /* Return status */ - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_SetCharacteristicDescriptor -***************************************************************************//** -* -* Sets the characteristic descriptor of the specified characteristic. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the characteristic descriptor attribute. -* \param attrValue: The pointer to the descriptor value data to be stored in the GATT -* database. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_WSS_WEIGHT_MEASUREMENT) && (descrIndex == CY_BLE_WSS_CCCD) && (attrValue != NULL)) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT]. - descrHandle[CY_BLE_WSS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Read characteristic value from database */ - if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - apiResult = CY_BLE_SUCCESS; - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_GetCharacteristicDescriptor -***************************************************************************//** -* -* Reads a a characteristic descriptor of a specified characteristic of the -* Weight Scale Service from the GATT database. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the characteristic. -* \param descrIndex: The index of the descriptor. -* \param attrSize: The size of the descriptor value. -* \param attrValue: The pointer to the location where characteristic descriptor value -* data should be stored. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if((charIndex == CY_BLE_WSS_WEIGHT_MEASUREMENT) && (descrIndex == CY_BLE_WSS_CCCD) && (attrValue != NULL)) - { - if(cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo = - { - .handleValuePair.attrHandle = - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD], - .handleValuePair.value.len = attrSize, - .handleValuePair.value.val = attrValue, - .connHandle = connHandle, - .offset = 0u, - .flags = CY_BLE_GATT_DB_LOCALLY_INITIATED - }; - /* Get characteristic value from GATT database */ - if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) == CY_BLE_GATT_ERR_NONE) - { - /* Indicate success */ - apiResult = CY_BLE_SUCCESS; - } - } - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSS_SendIndication -***************************************************************************//** -* -* Sends an indication with a characteristic value of the Weight Scale Service, -* which is a value specified by charIndex, to the client's device. -* -* On enabling indication successfully it sends out a 'Handle Value Indication' which -* results in CY_BLE_EVT_WSSC_INDICATION or CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if -* service-specific callback function is not registered) event at the GATT Client's end. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic value data that should be -* sent to the client's device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was handled successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the client is not established. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_IND_DISABLED - Indication is not enabled by the client. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WSS service-specific callback is registered -* (with Cy_BLE_WSS_RegisterAttrCallback): -* * CY_BLE_EVT_WSSS_INDICATION_CONFIRMED - If the indication is -* successfully delivered to the peer device. -* . -* Otherwise (if the WSS service-specific callback is not registered): -* * CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - If the indication is -* successfully delivered to the peer device. -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - /* Store new data in database */ - cy_en_ble_api_result_t apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - - if(charIndex == CY_BLE_WSS_WEIGHT_MEASUREMENT) - { - /* Send indication if it is enabled and connected */ - if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, - cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[ - CY_BLE_WSS_CCCD])) - { - apiResult = CY_BLE_ERROR_IND_DISABLED; - } - else - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gatts_handle_value_ind_t indReqParam = - { - .handleValPair.attrHandle = cy_ble_wssConfigPtr->wsss->charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].charHandle, - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* Send indication to client using previously filled structure */ - apiResult = Cy_BLE_GATTS_Indication(&indReqParam); - - /* Save handle to support service-specific value confirmation response from client */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wsssReqHandle = indReqParam.handleValPair.attrHandle; - } - } - } - - return(apiResult); -} - -#endif /* CY_BLE_WSS_SERVER */ - - -#ifdef CY_BLE_WSS_CLIENT - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_DiscoverCharacteristicsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP -* event. Based on the service UUID, an appropriate data structure is populated -* using the data received as part of the callback. -* -* \param discCharInfo: The pointer to a characteristic information structure. -* -******************************************************************************/ -static void Cy_BLE_WSSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo) -{ - /* WSS characteristics UUIDs */ - static const cy_ble_uuid16_t cy_ble_wsscCharUuid[CY_BLE_WSS_CHAR_COUNT] = - { - CY_BLE_UUID_CHAR_WEIGHT_SCALE_FEATURE, - CY_BLE_UUID_CHAR_WEIGHT_MEASUREMENT - }; - static cy_ble_gatt_db_attr_handle_t *lastEndHandle[CY_BLE_CONFIG_GATTC_COUNT] = { NULL }; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discCharInfo->connHandle); - uint32_t i; - - if((discCharInfo->uuidFormat == CY_BLE_GATT_16_BIT_UUID_FORMAT) && - (cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_WSS)) - { - /* Update last characteristic endHandle to declaration handle of this characteristic */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = discCharInfo->charDeclHandle - 1u; - lastEndHandle[discIdx] = NULL; - } - - /* Search through all available characteristics */ - for(i = (uint32_t)CY_BLE_WSS_WEIGHT_SCALE_FEATURE; (i < (uint32_t)CY_BLE_WSS_CHAR_COUNT); i++) - { - if(cy_ble_wsscCharUuid[i] == discCharInfo->uuid.uuid16) - { - if(cy_ble_wssc[discIdx].charInfo[i].valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_wssc[discIdx].charInfo[i].valueHandle = discCharInfo->valueHandle; - cy_ble_wssc[discIdx].charInfo[i].properties = discCharInfo->properties; - lastEndHandle[discIdx] = &cy_ble_wssc[discIdx].charInfo[i].endHandle; - break; - } - else - { - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo); - } - } - } - - /* Init characteristic endHandle to Service endHandle. Characteristic endHandle - * will be updated to the declaration handler of the following characteristic, - * in the following characteristic discovery procedure. - */ - if(lastEndHandle[discIdx] != NULL) - { - *lastEndHandle[discIdx] = cy_ble_serverInfo[discIdx][cy_ble_discovery[discIdx].servCount].range.endHandle; - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_DiscoverCharDescriptorsEventHandler -***************************************************************************//** -* -* This function is called on receiving a CY_BLE_EVT_GATTC_FIND_INFO_RSP event. -* Based on the descriptor UUID, an appropriate data structure is populated using -* the data received as part of the callback. -* -* \param discDescrInfo: The pointer to a descriptor information structure. -* -******************************************************************************/ -static void Cy_BLE_WSSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo) -{ - uint32_t notSupportedDescr = 0u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(discDescrInfo->connHandle); - uint32_t descIdx; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_WSS) - { - switch(discDescrInfo->uuid.uuid16) - { - case CY_BLE_UUID_CHAR_CLIENT_CONFIG: - descIdx = (uint32_t)CY_BLE_WSS_CCCD; - break; - - default: - /* Not supported descriptor */ - notSupportedDescr = 1u; - break; - } - - if(notSupportedDescr == 0u) - { - if(cy_ble_wssc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] == - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_ble_wssc[discIdx].charInfo[cy_ble_discovery[discIdx].charCount].descrHandle[descIdx] = - discDescrInfo->descrHandle; - } - else - { - /* Duplication of the descriptor */ - Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo); - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} - - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_GetCharRange -***************************************************************************//** -* -* Returns a possible range of the current characteristic descriptor via -* input parameter charRangeInfo->range -* -* \param *charRangeInfo: The pointer to a descriptor range information structure. -* \return -* None. -* -******************************************************************************/ -static void Cy_BLE_WSSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(charRangeInfo->connHandle); - uint32_t exitFlag = 0u; - - if(cy_ble_discovery[discIdx].servCount == (uint32_t)CY_BLE_SRVI_WSS) - { - if(charRangeInfo->srviIncIdx != CY_BLE_DISCOVERY_INIT) - { - cy_ble_discovery[discIdx].charCount++; - } - - while((cy_ble_discovery[discIdx].charCount < (uint32_t)CY_BLE_WSS_CHAR_COUNT) && (exitFlag == 0u)) - { - uint32_t charIdx = cy_ble_discovery[discIdx].charCount; - if((cy_ble_wssc[discIdx].charInfo[charIdx].endHandle - cy_ble_wssc[discIdx].charInfo[charIdx].valueHandle) != 0u) - { - /* Read characteristic range */ - charRangeInfo->range.startHandle = cy_ble_wssc[discIdx].charInfo[charIdx].valueHandle + 1u; - charRangeInfo->range.endHandle = cy_ble_wssc[discIdx].charInfo[charIdx].endHandle; - exitFlag = 1u; - } - else - { - cy_ble_discovery[discIdx].charCount++; - } - } - - /* Indicate that request was handled */ - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } -} -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_IndicationEventHandler -***************************************************************************//** -* -* Handles an indication event for Weight Scale Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WSSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam) -{ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WSS_ApplCallback != NULL)) - { - if(cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].valueHandle == - eventParam->handleValPair.attrHandle) - { - cy_stc_ble_wss_char_value_t indicationValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_WSS_WEIGHT_MEASUREMENT, - .value = &eventParam->handleValPair.value - }; - Cy_BLE_WSS_ApplCallback((uint32_t)CY_BLE_EVT_WSSC_INDICATION, &indicationValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_ReadResponseEventHandler -***************************************************************************//** -* -* Handles a Read Response event for the Weight Scale Service. -* -* \param eventParam: The pointer to the data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WSSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam) -{ - uint8_t locReqHandle = 1u; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WSS_ApplCallback != NULL) && - (cy_ble_wsscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if((cy_ble_wsscReqHandle[discIdx] == cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_SCALE_FEATURE].valueHandle) || - (cy_ble_wsscReqHandle[discIdx] == cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].valueHandle)) - { - cy_stc_ble_wss_char_value_t locCharValue; - - if(cy_ble_wsscReqHandle[discIdx] == cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_SCALE_FEATURE].valueHandle) - { - locCharValue.charIndex = CY_BLE_WSS_WEIGHT_SCALE_FEATURE; - } - else - { - locCharValue.charIndex = CY_BLE_WSS_WEIGHT_MEASUREMENT; - } - - locCharValue.connHandle = eventParam->connHandle; - locCharValue.value = &eventParam->value; - cy_ble_wsscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WSS_ApplCallback((uint32_t)CY_BLE_EVT_WSSC_READ_CHAR_RESPONSE, &locCharValue); - } - else if(cy_ble_wsscReqHandle[discIdx] == - cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD]) - { - cy_stc_ble_wss_descr_value_t locDescrValue = - { - .connHandle = eventParam->connHandle, - .charIndex = CY_BLE_WSS_WEIGHT_MEASUREMENT, - .descrIndex = CY_BLE_WSS_CCCD, - .value = &eventParam->value - }; - cy_ble_wsscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WSS_ApplCallback((uint32_t)CY_BLE_EVT_WSSC_READ_DESCR_RESPONSE, &locDescrValue); - } - else - { - locReqHandle = 0u; - } - - if(locReqHandle != 0u) - { - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_WriteResponseEventHandler -***************************************************************************//** -* -* Handles a Write Response event for the Weight Scale Service. -* -* \param eventParam: The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WSSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam) -{ - /* Check if service handler was registered and request handle is valid */ - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(*eventParam); - - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (Cy_BLE_WSS_ApplCallback != NULL) && - (cy_ble_wsscReqHandle[discIdx] != CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)) - { - if(cy_ble_wsscReqHandle[discIdx] == - cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD]) - { - cy_stc_ble_wss_descr_value_t locDescrValue = - { - .connHandle = *eventParam, - .charIndex = CY_BLE_WSS_WEIGHT_MEASUREMENT, - .descrIndex = CY_BLE_WSS_CCCD, - .value = NULL - }; - cy_ble_wsscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - Cy_BLE_WSS_ApplCallback((uint32_t)CY_BLE_EVT_WSSC_WRITE_DESCR_RESPONSE, &locDescrValue); - cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_ErrorResponseEventHandler -***************************************************************************//** -* -* Handles an Error Response event for the Weight Scale Service. -* -* \param eventParam - The pointer to a data structure specified by an event. -* -******************************************************************************/ -static void Cy_BLE_WSSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam) -{ - if(eventParam != NULL) - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(eventParam->connHandle); - if(eventParam->errInfo.attrHandle == cy_ble_wsscReqHandle[discIdx]) - { - cy_ble_wsscReqHandle[discIdx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE; - } - } -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_GetCharacteristicValue -***************************************************************************//** -* -* This function is used to read a characteristic value, which is a value -* identified by charIndex, from the server. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The read request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE - The peer device doesn't have -* the particular characteristic. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_STATE - Connection with the server is not established. -* * CY_BLE_ERROR_INVALID_OPERATION - Operation is invalid for this -* characteristic. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WSS service-specific callback is registered -* (with Cy_BLE_WSS_RegisterAttrCallback): -* * CY_BLE_EVT_WSSC_READ_CHAR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index , value, etc.) are -* provided with an event parameter structure -* of type cy_stc_ble_wss_char_value_t. -* . -* Otherwise (if the WSS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WSS_CHAR_COUNT) || (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_wssc[discIdx].charInfo[charIndex].valueHandle) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_wssc[discIdx].charInfo[charIndex].valueHandle, - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wsscReqHandle[discIdx] = cy_ble_wssc[discIdx].charInfo[charIndex].valueHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_SetCharacteristicDescriptor -***************************************************************************//** -* -* This function is used to write the characteristic descriptor to the server, -* which is identified by charIndex and descrIndex. -* -* Internally, Write Request is sent to the GATT Server and on successful -* execution of the request on the Server side the following events can be -* generated: -* * CY_BLE_EVT_WSSS_INDICATION_ENABLED -* * CY_BLE_EVT_WSSS_INDICATION_DISABLED -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* \param attrSize: The size of the characteristic value attribute. -* \param attrValue: The pointer to the characteristic descriptor value data that -* should be sent to the server device. -* -* \return -* A return value is of type cy_en_ble_api_result_t. -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WSS service-specific callback is registered -* (with Cy_BLE_WSS_RegisterAttrCallback): -* * CY_BLE_EVT_WSSC_WRITE_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index etc.) are -* provided with event parameter structure -* of type cy_stc_ble_wss_descr_value_t. -* . -* Otherwise (if the WSS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_WRITE_RSP - If the requested attribute is -* successfully written on the peer device. -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t descrIndex, - uint8_t attrSize, - uint8_t *attrValue) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WSS_CHAR_COUNT) || (descrIndex >= CY_BLE_WSS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - /* Fill all fields of write request structure ... */ - cy_stc_ble_gattc_write_req_t writeReqParam = - { - .handleValPair.attrHandle = cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT]. - descrHandle[CY_BLE_WSS_CCCD], - .handleValPair.value.val = attrValue, - .handleValPair.value.len = attrSize, - .connHandle = connHandle - }; - /* ... and send request to server's device. */ - apiResult = Cy_BLE_GATTC_WriteCharacteristicDescriptors(&writeReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wsscReqHandle[discIdx] = writeReqParam.handleValPair.attrHandle; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - - -/****************************************************************************** -* Function Name: Cy_BLE_WSSC_GetCharacteristicDescriptor -***************************************************************************//** -* -* Sends a request to get the characteristic descriptor of the specified -* characteristic of the service. -* -* \param connHandle: The connection handle. -* \param charIndex: The index of the service characteristic. Starts with zero. -* \param descrIndex: The index of the service characteristic descriptor. -* -* \return -* * CY_BLE_SUCCESS - The request was sent successfully. -* * CY_BLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed. -* * CY_BLE_ERROR_INVALID_STATE - The state is not valid. -* * CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. -* * CY_BLE_ERROR_INVALID_OPERATION - This operation is not permitted on -* the specified attribute. -* -* \events -* In case of successful execution (return value = CY_BLE_SUCCESS) -* the next events can appear: \n -* If the WSS service-specific callback is registered -* (with Cy_BLE_WSS_RegisterAttrCallback): -* * CY_BLE_EVT_WSSC_READ_DESCR_RESPONSE - If the requested attribute is -* successfully written on the peer device, -* the details (char index, descr index, value, etc.) -* are provided with an event parameter structure -* of type cy_stc_ble_wss_descr_value_t. -* . -* Otherwise (if the WSS service-specific callback is not registered): -* * CY_BLE_EVT_GATTC_READ_RSP - If the requested attribute is -* successfully read on the peer device, -* the details (handle, value, etc.) are -* provided with an event parameters -* structure (cy_stc_ble_gattc_read_rsp_param_t). -* * CY_BLE_EVT_GATTC_ERROR_RSP - If there is trouble with the -* requested attribute on the peer device, -* the details are provided with event parameters -* structure (cy_stc_ble_gatt_err_param_t). -* -******************************************************************************/ -cy_en_ble_api_result_t Cy_BLE_WSSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t descrIndex) -{ - cy_en_ble_api_result_t apiResult; - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(connHandle); - - if(Cy_BLE_GetConnectionState(connHandle) != CY_BLE_CONN_STATE_CLIENT_DISCOVERED) - { - apiResult = CY_BLE_ERROR_INVALID_STATE; - } - else if((charIndex >= CY_BLE_WSS_CHAR_COUNT) || (descrIndex >= CY_BLE_WSS_DESCR_COUNT) || - (discIdx >= CY_BLE_CONFIG_GATTC_COUNT)) - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - else if(cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD] != - CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) - { - cy_stc_ble_gattc_read_req_t readReqParam = - { - .attrHandle = cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT].descrHandle[CY_BLE_WSS_CCCD], - .connHandle = connHandle - }; - apiResult = Cy_BLE_GATTC_ReadCharacteristicDescriptors(&readReqParam); - - /* Save handle to support service-specific read response from device */ - if(apiResult == CY_BLE_SUCCESS) - { - cy_ble_wsscReqHandle[discIdx] = cy_ble_wssc[discIdx].charInfo[CY_BLE_WSS_WEIGHT_MEASUREMENT]. - descrHandle[CY_BLE_WSS_CCCD]; - } - } - else - { - apiResult = CY_BLE_ERROR_INVALID_PARAMETER; - } - - return(apiResult); -} - -#endif /* CY_BLE_WSS_CLIENT */ - -/****************************************************************************** -* Function Name: Cy_BLE_WSS_EventHandler -***************************************************************************//** -* -* Handles the events from the BLE stack for the Weight Scale Service. -* -* \param eventCode: the event code -* \param eventParam: the event parameters -* -* \return -* Return value is of type cy_en_ble_gatt_err_code_t. -* -******************************************************************************/ -static cy_en_ble_gatt_err_code_t Cy_BLE_WSS_EventHandler(uint32_t eventCode, - void *eventParam) -{ - cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE; - - if(eventCode > (uint32_t)CY_BLE_EVT_MAX) - { - /************************************************************************** - * Handling Service Specific Events - ***************************************************************************/ - switch((cy_en_ble_evt_t)eventCode) - { - #ifdef CY_BLE_WSS_CLIENT - /* Discovery Events */ - case CY_BLE_EVT_GATTC_DISC_CHAR: - Cy_BLE_WSSC_DiscoverCharacteristicsEventHandler((cy_stc_ble_disc_char_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR: - Cy_BLE_WSSC_DiscoverCharDescriptorsEventHandler((cy_stc_ble_disc_descr_info_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_DISC_DESCR_GET_RANGE: - Cy_BLE_WSSC_GetCharRange((cy_stc_ble_disc_range_info_t*)eventParam); - break; - #endif /* CY_BLE_WSS_CLIENT */ - - default: - break; - } - } - else - { - switch((cy_en_ble_event_t)eventCode) - { - /************************************************************************** - * Handling GATT Server Events - ***************************************************************************/ - #ifdef CY_BLE_WSS_SERVER - case CY_BLE_EVT_GATTS_WRITE_REQ: - gattErr = Cy_BLE_WSSS_WriteEventHandler((cy_stc_ble_gatts_write_cmd_req_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF: - Cy_BLE_WSSS_ConfirmationEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_WSS_SERVER */ - - /************************************************************************** - * Handling GATT Client Events - ***************************************************************************/ - #ifdef CY_BLE_WSS_CLIENT - case CY_BLE_EVT_GATTC_ERROR_RSP: - { - uint32_t discIdx = Cy_BLE_GetDiscoveryIdx(((cy_stc_ble_gatt_err_param_t*)eventParam)->connHandle); - if((discIdx < CY_BLE_CONFIG_GATTC_COUNT) && (cy_ble_discovery[discIdx].autoDiscoveryFlag == 0u) && - (((cy_stc_ble_gatt_err_param_t*)eventParam)->errInfo.errorCode != - CY_BLE_GATT_ERR_ATTRIBUTE_NOT_FOUND)) - { - Cy_BLE_WSSC_ErrorResponseEventHandler((cy_stc_ble_gatt_err_param_t*)eventParam); - } - } - break; - - case CY_BLE_EVT_GATTC_HANDLE_VALUE_IND: - Cy_BLE_WSSC_IndicationEventHandler((cy_stc_ble_gattc_handle_value_ind_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_READ_RSP: - Cy_BLE_WSSC_ReadResponseEventHandler((cy_stc_ble_gattc_read_rsp_param_t*)eventParam); - break; - - case CY_BLE_EVT_GATTC_WRITE_RSP: - Cy_BLE_WSSC_WriteResponseEventHandler((cy_stc_ble_conn_handle_t*)eventParam); - break; - #endif /* CY_BLE_WSS_CLIENT */ - - default: - break; - } - } - - return(gattErr); -} - -#endif /* defined(CY_BLE_WSS) */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wss.h b/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wss.h deleted file mode 100644 index c9597b5a28..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/device/middleware/ble/cy_ble_wss.h +++ /dev/null @@ -1,219 +0,0 @@ -/***************************************************************************//** -* \file cy_ble_wss.h -* \version 2.0 -* -* \brief -* Contains the function prototypes and constants for Weight Scale Service. -* -* -******************************************************************************** -* \copyright -* Copyright 2017, Cypress Semiconductor Corporation. All rights reserved. -* You may use this file only in accordance with the license, terms, conditions, -* disclaimers, and limitations in the end user license agreement accompanying -* the software package with which this file was provided. -*******************************************************************************/ - - -#ifndef CY_BLE_WSS_H -#define CY_BLE_WSS_H - - -#include "cy_ble_gatt.h" - -#if (CY_BLE_MODE_PROFILE && defined(CY_BLE_WSS)) - -/* C binding of definitions if building with C++ compiler */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*************************************** -* Conditional Compilation Parameters -***************************************/ - - -/** - * \addtogroup group_ble_service_api_WSS_definitions - * @{ - */ - -/*************************************** -* Data Types -***************************************/ - -/** WSS Characteristic indexes */ -typedef enum -{ - CY_BLE_WSS_WEIGHT_SCALE_FEATURE, /**< Weight Scale Feature Characteristic index */ - CY_BLE_WSS_WEIGHT_MEASUREMENT, /**< Weight Measurement Characteristic index */ - CY_BLE_WSS_CHAR_COUNT /**< Total count of WSS Characteristics */ -}cy_en_ble_wss_char_index_t; - -/** WSS Characteristic Descriptors indexes */ -typedef enum -{ - CY_BLE_WSS_CCCD, /**< Client Characteristic Configuration Descriptor index */ - CY_BLE_WSS_DESCR_COUNT /**< Total count of Descriptors */ -}cy_en_ble_wss_descr_index_t; - -/** WSS Characteristic value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_wss_char_index_t charIndex; /**< Index of service characteristic */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_wss_char_value_t; - -/** WSS Characteristic descriptor value parameter structure */ -typedef struct -{ - cy_stc_ble_conn_handle_t connHandle; /**< Peer device handle */ - cy_en_ble_wss_char_index_t charIndex; /**< Index of service characteristic */ - cy_en_ble_wss_descr_index_t descrIndex; /**< Index of descriptor */ - cy_stc_ble_gatt_value_t *value; /**< Characteristic value */ -} cy_stc_ble_wss_descr_value_t; - -/** Structure with Weight Scale Service attribute handles */ -typedef struct -{ - /** Handle of characteristic value */ - cy_ble_gatt_db_attr_handle_t charHandle; - - /** Array of descriptor handles */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_WSS_DESCR_COUNT]; -} cy_stc_ble_wsss_char_t; - -/** WSS Characteristic with descriptors handles */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t serviceHandle; /**< Weight Scale Service handle */ - cy_stc_ble_wsss_char_t charInfo[CY_BLE_WSS_CHAR_COUNT]; /**< Array of characteristics and descriptors handles */ -} cy_stc_ble_wsss_t; - -/** WSS Service Full characteristic information structure */ -typedef struct -{ - cy_ble_gatt_db_attr_handle_t valueHandle; /**< Handle of characteristic value */ - uint8_t properties; /**< Properties for value field */ - cy_ble_gatt_db_attr_handle_t endHandle; /**< End handle of characteristic */ - cy_ble_gatt_db_attr_handle_t descrHandle[CY_BLE_WSS_DESCR_COUNT]; /**< Array of descriptor handles */ -} cy_stc_ble_wssc_char_t; - -/** Structure with discovered attributes information of Weight Scale Service */ -typedef struct -{ - /** Weight Scale Service handle */ - cy_ble_gatt_db_attr_handle_t serviceHandle; - - /** Weight Scale Service characteristics info structure */ - cy_stc_ble_wssc_char_t charInfo[CY_BLE_WSS_CHAR_COUNT]; -} cy_stc_ble_wssc_t; - -/** Service configuration structure */ -typedef struct -{ - /** Weight Scale Service GATT DB handles structure */ - const cy_stc_ble_wsss_t *wsss; - - /** An application layer event callback function to receive service events from the BLE Component. */ - cy_ble_callback_t callbackFunc; -} cy_stc_ble_wss_config_t; - -/** @} */ - - -/*************************************** -* API Constants -***************************************/ -#define CY_BLE_WSS_UNKNOWN_USER (0xFFu) - - -/*************************************** -* Function Prototypes -***************************************/ - -/** \addtogroup group_ble_service_api_WSS_server_client - * @{ - */ -cy_en_ble_api_result_t Cy_BLE_WSS_Init(cy_stc_ble_wss_config_t *config); -cy_en_ble_api_result_t Cy_BLE_WSS_RegisterAttrCallback(cy_ble_callback_t callbackFunc); -/** @} */ - -#ifdef CY_BLE_WSS_SERVER -/** - * \addtogroup group_ble_service_api_WSS_server - * @{ - */ -#if (CY_BLE_GAP_ROLE_PERIPHERAL) -uint8_t Cy_BLE_WSS_GetAdUserIdListSize(uint8_t advertisingParamIndex); - -cy_en_ble_api_result_t Cy_BLE_WSS_SetAdUserId(uint8_t listSize, const uint8_t userIdList[], - uint8_t advertisingParamIndex); -#endif /* (CY_BLE_GAP_ROLE_PERIPHERAL) */ - -cy_en_ble_api_result_t Cy_BLE_WSSS_SetCharacteristicValue(cy_en_ble_wss_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WSSS_GetCharacteristicValue(cy_en_ble_wss_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WSSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WSSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t descrIndex, uint8_t attrSize, - uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WSSS_SendIndication(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, uint8_t attrSize, - uint8_t *attrValue); - -/** @} */ -#endif /* CY_BLE_WSS_SERVER */ - -#ifdef CY_BLE_WSS_CLIENT - -/** - * \addtogroup group_ble_service_api_WSS_client - * @{ - */ - -cy_en_ble_api_result_t Cy_BLE_WSSC_GetCharacteristicValue(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex); - -cy_en_ble_api_result_t Cy_BLE_WSSC_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t - descrIndex, uint8_t attrSize, uint8_t *attrValue); - -cy_en_ble_api_result_t Cy_BLE_WSSC_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle, - cy_en_ble_wss_char_index_t charIndex, - cy_en_ble_wss_descr_index_t - descrIndex); - -/** @} */ -#endif /* CY_BLE_WSS_CLIENT */ - - -/*************************************** -* External data references -***************************************/ - -#ifdef CY_BLE_WSS_CLIENT -extern cy_stc_ble_wssc_t cy_ble_wssc[CY_BLE_CONFIG_GATTC_COUNT]; -#endif /* CY_BLE_WSS_CLIENT */ - -extern cy_stc_ble_wss_config_t cy_ble_wssConfig; -extern cy_stc_ble_wss_config_t *cy_ble_wssConfigPtr; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CY_BLE_MODE_PROFILE && defined(CY_BLE_WSS) */ -#endif /* CY_BLE_WSS_H */ - -/* [] END OF FILE */ diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/gpio_api.c b/targets/TARGET_Cypress/TARGET_PSoC6/gpio_api.c deleted file mode 100644 index 419ccf1a0e..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/gpio_api.c +++ /dev/null @@ -1,153 +0,0 @@ - -#include "cmsis.h" -#include "device.h" -#include "mbed_assert.h" -#include "PeripheralNames.h" -#include "PinNames.h" -#include "PortNames.h" -#include "drivers/peripheral/gpio/cy_gpio.h" - -void _gpio_set_dir_mode(gpio_t *obj); -uint32_t _gpio_get_cy_drive_mode(PinDirection dir, PinMode mode); - - -void gpio_init(gpio_t *obj, PinName pin) -{ - obj->pin = pin; - - MBED_ASSERT(obj->pin != NC); - - GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(CYPRESS_PORT(obj->pin)); - uint32_t ppin = CYPRESS_PIN(obj->pin); - - const cy_stc_gpio_pin_config_t config = { - .outVal = 0x01, // must be 1 for DigitalIn to work. Does not seems to influence DigitalOut. Tested with PullDefault = PullUp - .driveMode = _gpio_get_cy_drive_mode(obj->dir, obj->mode), - .hsiom = HSIOM_SEL_GPIO, - }; - Cy_GPIO_Pin_Init(port, ppin, &config); -} - -void gpio_mode(gpio_t *obj, PinMode mode) -{ - MBED_ASSERT(obj->pin != NC); - - obj->mode = mode; - _gpio_set_dir_mode(obj); -} - -void gpio_dir(gpio_t *obj, PinDirection direction) -{ - MBED_ASSERT(obj->pin != NC); - - obj->dir = direction; - _gpio_set_dir_mode(obj); -} - -void gpio_write(gpio_t *obj, int value) -{ - MBED_ASSERT(obj->pin != NC); - - GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(CYPRESS_PORT(obj->pin)); - uint32_t pin = CYPRESS_PIN(obj->pin); - - Cy_GPIO_Write(port, pin, value); -} - -/* - Return an integer representing the output setting of the pin if it is an - output, or read the input if set as an input. - (From DigitalOut::read) -*/ -int gpio_read(gpio_t *obj) -{ - int ret = 0; - - MBED_ASSERT(obj->pin != NC); - - GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(CYPRESS_PORT(obj->pin)); - uint32_t pin = CYPRESS_PIN(obj->pin); - - switch (obj->dir) { - case PIN_INPUT: - ret = Cy_GPIO_Read(port, pin); - break; - - case PIN_OUTPUT: - ret = Cy_GPIO_ReadOut(port, pin); - break; - } - - return ret; -} - -int gpio_is_connected(const gpio_t *obj) -{ - return obj->pin != NC; -} - -void _gpio_set_dir_mode(gpio_t *obj) -{ - MBED_ASSERT(obj->pin != NC); - - GPIO_PRT_Type *port = Cy_GPIO_PortToAddr(CYPRESS_PORT(obj->pin)); - uint32_t pin = CYPRESS_PIN(obj->pin); - uint32_t cymode = _gpio_get_cy_drive_mode(obj->dir, obj->mode); - - Cy_GPIO_SetDrivemode(port, pin, cymode); -} - -uint32_t _gpio_get_cy_drive_mode(PinDirection dir, PinMode mode) -{ - uint32_t cymode = 0; - - switch (dir) { - case PIN_INPUT: - switch (mode) { - case PullNone: - cymode = CY_GPIO_DM_STRONG; - break; - case PullUp: - cymode = CY_GPIO_DM_PULLUP; - break; - case PullDown: - cymode = CY_GPIO_DM_PULLDOWN; - break; - case OpenDrainPullUp: - cymode = CY_GPIO_DM_OD_DRIVESHIGH; - break; - case OpenDrainNoPull: - cymode = CY_GPIO_DM_STRONG; - break; - case OpenDrainPullDown: - cymode = CY_GPIO_DM_OD_DRIVESLOW; - break; - } - break; - - case PIN_OUTPUT: - switch (mode) { - case PullNone: - cymode = CY_GPIO_DM_STRONG_IN_OFF; - break; - case PullUp: - cymode = CY_GPIO_DM_PULLUP_IN_OFF; - break; - case PullDown: - cymode = CY_GPIO_DM_PULLDOWN_IN_OFF; - break; - case OpenDrainPullUp: - cymode = CY_GPIO_DM_OD_DRIVESHIGH_IN_OFF; - break; - case OpenDrainNoPull: - cymode = CY_GPIO_DM_STRONG_IN_OFF; - break; - case OpenDrainPullDown: - cymode = CY_GPIO_DM_OD_DRIVESLOW_IN_OFF; - break; - } - break; - } - - return cymode; -} diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/objects.h b/targets/TARGET_Cypress/TARGET_PSoC6/objects.h deleted file mode 100644 index 04acee707d..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/objects.h +++ /dev/null @@ -1,120 +0,0 @@ -/* mbed Microcontroller Library - ******************************************************************************* - * Copyright (c) XXXX - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************* - */ - -#ifndef MBED_OBJECTS_H -#define MBED_OBJECTS_H - -#include "cmsis.h" -#include "PeripheralNames.h" -#include "PinNames.h" -#include "PortNames.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - PinName pin; - PinDirection dir; - PinMode mode; -} gpio_t; - -// struct gpio_irq_s { -// IRQn_Type irq_n; -// uint32_t irq_index; -// uint32_t event; -// PinName pin; -// uint32_t pin_index; -// uint32_t pin_num; -// uint32_t port_num; -// uint32_t rise_null; -// uint32_t fall_null; -// }; - -// struct port_s { -// PortName port; -// uint32_t mask; -// PinDirection direction; -// __IO uint32_t *reg_in; -// __IO uint32_t *reg_out; -// }; - -// struct analogin_s { -// ADCName adc; -// PinName pin; -// uint32_t channel; -// }; - -struct serial_s { - CySCB_Type *base; - PinName pin_rx; - PinName pin_tx; -}; - -// struct spi_s { -// SSP_TypeDef *spi; -// }; - -// struct i2c_s { -// I2CName I2Cx; -// PinName sda; -// PinName scl; -// uint16_t ADDRESS; -// uint16_t is_setAddress; -// }; - -// struct pwmout_s { -// PWM_CHn_TypeDef * PWM_CHx; -// PinName pin; -// uint32_t period; -// uint32_t pulse; -// uint32_t PrescalerValue; -// }; - -// struct dac_s { -// DACName dac; -// PinName pin; -// uint32_t channel; -// }; - -// struct can_s { -// CANName can; -// int index; -// }; - -// struct trng_s { -// RNG_HandleTypeDef handle; -// }; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/serial_api.c b/targets/TARGET_Cypress/TARGET_PSoC6/serial_api.c deleted file mode 100644 index 6e3468d8cd..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/serial_api.c +++ /dev/null @@ -1,222 +0,0 @@ - -#if DEVICE_SERIAL - -#include - -#include "cmsis.h" -#include "mbed_assert.h" -#include "mbed_error.h" -#include "PeripheralPins.h" -#include "pinmap.h" - -#include "serial_api.h" - -#include "drivers/peripheral/sysclk/cy_sysclk.h" -#include "drivers/peripheral/gpio/cy_gpio.h" -#include "drivers/peripheral/scb/cy_scb_uart.h" - -serial_t stdio_uart; -int stdio_uart_inited = 0; - - -void serial_init_clock(serial_t *obj, uint32_t baudrate) -{ - uint32_t periClk = 50*1000*1000; // UART uses periClk (50 MHz) - uint32_t oversample = 12; // this must match the cy_stc_scb_uart_config_t cy_UART_config.oversample in serial_init_periph() - - uint32_t divider = periClk/(oversample*baudrate); - - Cy_SysClk_PeriphAssignDivider(PCLK_SCB5_CLOCK, CY_SYSCLK_DIV_16_BIT, 0); - Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_16_BIT, 0, divider); - // Cy_SysClk_PeriphPhaseAlignDivider(CY_SYSCLK_DIV_16_BIT, 0, CY_SYSCLK_DIV_24_5_BIT, 0xFF); -} - -/* - Returns the UART's SCBx_BASE corresponding to the pin, NULL if not found. -*/ -CySCB_Type *pin_to_scb(PinName pin) -{ - switch (pin) { - case P0_2: // P0_2_SCB0_UART_RX - case P0_3: // P0_3_SCB0_UART_TX - return SCB0; - break; - - case P10_0: // P10_0_SCB1_UART_RX - case P10_1: // P10_1_SCB1_UART_TX - return SCB1; - break; - - case P9_0: // P9_0_SCB2_UART_RX - case P9_1: // P9_1_SCB2_UART_TX - return SCB2; - break; - - case P6_0: // P6_0_SCB3_UART_RX - case P6_1: // P6_1_SCB3_UART_TX - return SCB3; - break; - - case P7_0: // P7_0_SCB4_UART_RX - case P7_1: // P7_1_SCB4_UART_TX - case P8_0: // P8_0_SCB4_UART_RX - case P8_1: // P8_1_SCB4_UART_TX - return SCB4; - break; - - case P5_0: // P5_0_SCB5_UART_RX - case P5_1: // P5_1_SCB5_UART_TX - case P11_0: // P11_0_SCB5_UART_RX - case P11_1: // P11_1_SCB5_UART_TX - return SCB5; - break; - - case P12_0: // P12_0_SCB6_UART_RX - case P12_1: // P12_1_SCB6_UART_TX - case P13_0: // P13_0_SCB6_UART_RX - case P13_1: // P13_1_SCB6_UART_TX - case P6_4: // P6_4_SCB6_UART_RX - case P6_5: // P6_5_SCB6_UART_TX - return SCB6; - break; - - case P1_0: // P1_0_SCB7_UART_RX - case P1_1: // P1_1_SCB7_UART_TX - return SCB7; - break; - - default: - return NULL; - break; - } -} - -void serial_init_pins(serial_t *obj, PinName tx, PinName rx) -{ - CySCB_Type *scb_tx = NULL, *scb_rx = NULL; - GPIO_PRT_Type *port = NULL; - uint32_t pin = 0; - - obj->pin_tx = tx; - obj->pin_rx = rx; - - scb_tx = pin_to_scb(tx); - scb_rx = pin_to_scb(rx); - - if ((scb_tx == NULL) || (scb_rx == NULL)) - error("Invalid Serial pinout. Try another TX or RX pin."); - - if (scb_tx != scb_rx) - error("Serial pinout mismatch. Requested pins Rx and Tx can't be used for the same Serial communication."); - - obj->base = scb_tx; - - // init tx - port = Cy_GPIO_PortToAddr(CYPRESS_PORT(obj->pin_tx)); - pin = CYPRESS_PIN(obj->pin_tx); - cy_stc_gpio_pin_config_t config_tx = { - .outVal = 0x01, - .driveMode = 6, - .hsiom = HSIOM_SEL_ACT_6, - }; - Cy_GPIO_Pin_Init(port, pin, &config_tx); - - // init rx - port = Cy_GPIO_PortToAddr(CYPRESS_PORT(obj->pin_rx)); - pin = CYPRESS_PIN(obj->pin_rx); - cy_stc_gpio_pin_config_t config_rx = { - .outVal = 0x01, - .driveMode = 8, - .hsiom = HSIOM_SEL_ACT_6, - }; - Cy_GPIO_Pin_Init(port, pin, &config_rx); -} - -void serial_init_periph(serial_t *obj) -{ - cy_stc_scb_uart_config_t cy_UART_config = - { - .uartMode = CY_SCB_UART_STANDARD, - .enableMutliProcessorMode = false, - .smartCardRetryOnNack = false, - .irdaInvertRx = false, - .irdaEnableLowPowerReceiver = false, - - .oversample = 12UL, - - .enableMsbFirst = false, - .dataWidth = 8UL, - .parity = CY_SCB_UART_PARITY_NONE, - .stopBits = CY_SCB_UART_STOP_BITS_1, - .enableInputFilter = false, - .breakWidth = 11UL, - .dropOnFrameError = false, - .dropOnParityError = false, - - .receiverAddress = 0x0UL, - .receiverAddressMask = 0x0UL, - .acceptAddrInFifo = false, - - .enableCts = false, - .ctsPolarity = CY_SCB_UART_ACTIVE_LOW, - .rtsRxFifoLevel = 0UL, - .rtsPolarity = CY_SCB_UART_ACTIVE_LOW, - - .rxFifoTriggerLevel = 0UL, - .rxFifoIntEnableMask = 0x0UL, - - .txFifoTriggerLevel = 0UL, - .txFifoIntEnableMask = 0x0UL - }; - - Cy_SCB_UART_Init(obj->base, &cy_UART_config, NULL); - Cy_SCB_UART_Enable(obj->base); -} - -void serial_init(serial_t *obj, PinName tx, PinName rx) -{ - if (stdio_uart_inited) - return; - stdio_uart_inited = 1; - - serial_init_clock(obj, 9600); - serial_init_pins(obj, tx, rx); - serial_init_periph(obj); -} - -void serial_baud(serial_t *obj, int baudrate) -{ - serial_init_clock(obj, baudrate); - serial_init_periph(obj); -} - -void serial_putc(serial_t *obj, int c) -{ - while (!serial_writable(obj)) - ; - Cy_SCB_UART_Put(obj->base, c); -} - -int serial_getc(serial_t *obj) -{ - while (!serial_readable(obj)) - ; - return Cy_SCB_UART_Get(obj->base); -} - -int serial_readable(serial_t *obj) -{ - return Cy_SCB_GetNumInRxFifo(obj->base) != 0; -} - -int serial_writable(serial_t *obj) -{ - return Cy_SCB_GetNumInTxFifo(obj->base) != Cy_SCB_GetFifoSize(obj->base); -} - -void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) -{ - -} - -#endif diff --git a/targets/TARGET_Cypress/TARGET_PSoC6/us_ticker.c b/targets/TARGET_Cypress/TARGET_PSoC6/us_ticker.c deleted file mode 100644 index c61f6a94ae..0000000000 --- a/targets/TARGET_Cypress/TARGET_PSoC6/us_ticker.c +++ /dev/null @@ -1,122 +0,0 @@ - -#include -#include -#include "device.h" -#include "PeripheralNames.h" -#include "us_ticker_api.h" - -#include "drivers/peripheral/sysint/cy_sysint.h" -#include "drivers/peripheral/sysclk/cy_sysclk.h" -#include "drivers/peripheral/tcpwm/cy_tcpwm_counter.h" - -/** Each CPU core nn PSoC6 each CPU needs its own usec timer. - ** Although each of TCPWM timers have two compare registers, - ** it has only one interrupt line, so we need to allocate - ** two TCPWM counters for purpose of us_ticker */ - - -#if defined(TARGET_MCU_PSoC6_M0) - -#define TICKER_COUNTER_UNIT TCPWM0 -#define TICKER_COUNTER_NUM 0 -#define TICKER_COUNTER_INTERRUPT_SOURCE tcpwm_0_interrupts_0_IRQn -#define TICKER_COUNTER_NVIC_IRQN NvicMux0_IRQn -#define TICKER_COUNTER_INTERRUPT_PRIORITY 3 - -#elif defined (TARGET_MCU_PSoC6_M4) - -#define TICKER_COUNTER_UNIT TCPWM0 -#define TICKER_COUNTER_NUM 1 -#define TICKER_COUNTER_INTERRUPT_SOURCE tcpwm_0_interrupts_1_IRQn -#define TICKER_COUNTER_NVIC_IRQN TICKER_COUNTER_INTERRUPT_SOURCE -#define TICKER_COUNTER_INTERRUPT_PRIORITY 3 - -#else - #error "Unknown MCU type." -#endif - - - -const cy_stc_sysint_t cy_sysint_cfg = { - .intrSrc = TICKER_COUNTER_INTERRUPT_SOURCE, -#if defined(MCU_PSoC6_M0) - .intrCm0p = TICKER_COUNTER_NVIC_IRQN, -#endif - .intrPriority = TICKER_COUNTER_INTERRUPT_PRIORITY -}; - -int us_ticker_inited = 0; - -const cy_stc_tcpwm_counter_config_t cy_counter_config = -{ - .period = ULONG_MAX, - .clockPrescaler = CY_TCPWM_COUNTER_PRESCALER_DIVBY_1, - .runMode = CY_TCPWM_COUNTER_CONTINUOUS, - .countDirection = CY_TCPWM_COUNTER_COUNT_UP, - .compareOrCapture = CY_TCPWM_COUNTER_MODE_COMPARE, - .enableCompareSwap = false, - .interruptSources = CY_TCPWM_INT_ON_CC, - .countInputMode = CY_TCPWM_INPUT_LEVEL, - .countInput = CY_TCPWM_INPUT_1 -}; - -static void local_irq_handler(void) -{ - us_ticker_clear_interrupt(); - us_ticker_irq_handler(); -} - -void us_ticker_init(void) -{ - - if (us_ticker_inited) - return; - us_ticker_inited = 1; - - /* - Configure the clock - */ - - // us_ticker 1 MHz from PCLK 50 MHz - Cy_SysClk_PeriphAssignDivider(PCLK_TCPWM0_CLOCKS0, CY_SYSCLK_DIV_8_BIT, 0u); - Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT, 0u, 49u); - Cy_SysClk_PeriphEnablePhaseAlignDivider(CY_SYSCLK_DIV_8_BIT, 0u, CY_SYSCLK_DIV_24_5_BIT, 0xFF); - - /* - Configure the counter - */ - - Cy_TCPWM_Counter_Init(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM, &cy_counter_config); - Cy_TCPWM_Counter_Enable(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); - Cy_TCPWM_TriggerStart(TICKER_COUNTER_UNIT, 1UL << TICKER_COUNTER_NUM); - - Cy_SysInt_Init(&cy_sysint_cfg, local_irq_handler); -} - -uint32_t us_ticker_read(void) -{ - if (!us_ticker_inited) - us_ticker_init(); - return Cy_TCPWM_Counter_GetCounter(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM); -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - if (!us_ticker_inited) - us_ticker_init(); - - // Set new output compare value - Cy_TCPWM_Counter_SetCompare0(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM, timestamp); - // Enable int - NVIC_EnableIRQ(TICKER_COUNTER_NVIC_IRQN); -} - -void us_ticker_disable_interrupt(void) -{ - NVIC_DisableIRQ(TICKER_COUNTER_NVIC_IRQN); -} - -void us_ticker_clear_interrupt(void) -{ - Cy_TCPWM_ClearInterrupt(TICKER_COUNTER_UNIT, TICKER_COUNTER_NUM, CY_TCPWM_INT_ON_CC); -}