Compare commits

...

16 Commits

Author SHA1 Message Date
Roy b649c22231 [update] fix uart message 2023-07-10 12:48:07 +08:00
Roy f0f36b3259 [update] fix unstable connection 2023-06-29 13:50:48 +08:00
Roy aacc263447 [update] reset_status_register 0x41 2023-06-28 10:31:48 +08:00
Roy 99f502f5ca [update] fix connect ack and disconnect ack 2023-06-19 17:35:45 +08:00
Roy f54dbd330f [update] rename parameter 2023-06-19 13:53:54 +08:00
Roy 54ab777871 [update] integrate green/red data code 2023-06-16 17:11:20 +08:00
Roy 047acb1e99 [update] integrate code 2023-06-16 11:53:17 +08:00
Roy 1b842a5cd9 [update] integrate code 2023-06-16 08:49:42 +08:00
Roy 0161fe1868 Refactor: refactor function 2023-06-08 11:43:59 +08:00
Roy 9e285b43fb Doc: new IDE setting image & clean unused function 2023-06-07 17:18:03 +08:00
ROY 334a68c6fe [update] fix 1 to 8 process 2022-09-27 14:56:25 +08:00
ROY 627b5f0b59 [update] fix 1 to 8 process 2022-09-27 13:36:20 +08:00
Roy 94e82768d2 [update] fix ti sample code, in order to using TI v20.2.5LTS 2022-05-19 10:13:58 +08:00
Roy 4957142e08 [update] don't use GPT_MODE_PERIODIC_DOWN 2022-05-18 15:19:19 +08:00
Roy 08490df886 [info] ti predefined 2022-05-18 14:58:26 +08:00
Roy ac0662bc9d [copy] copy 16da986f3e6459f0d58b184f106c7c6838a7e093 version from past_code_cc2650 project 2022-05-18 14:50:07 +08:00
38 changed files with 2728 additions and 1703 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

@@ -36,10 +36,11 @@
* CC2650 Booster Pack.
*/
/*
* ====================== Includes ============================================
*/
// clang-format off
#include <xdc/std.h>
#include <xdc/runtime/System.h>
@@ -56,16 +57,46 @@
#include <inc/hw_ints.h>
#include <driverlib/ioc.h>
#include <driverlib/udma.h>
// clang-format on
#include "Board.h"
///*
// * ========================= IO driver initialization =========================
// * From main, PIN_init(BoardGpioInitTable) should be called to setup safe
// * settings for this board.
// * When a pin is allocated and then de-allocated, it will revert to the state
// * configured in this table.
// */
//
///* Place into subsections to allow the TI linker to remove items properly */
//#if defined(__TI_COMPILER_VERSION__)
//#pragma DATA_SECTION(BoardGpioInitTable, ".const:BoardGpioInitTable")
//#pragma DATA_SECTION(PINCC26XX_hwAttrs, ".const:PINCC26XX_hwAttrs")
//#endif
//
//PIN_Config BoardGpioInitTable[] = { //
// PIN_MEM_INS | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
// PIN_MEM_REQ | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
// PIN_MEM_BZY | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
// PIN_MEM_SEL | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// PIN_MEM_TEST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
// PIN_TERMINATE};
//
//const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
// //
// .intPriority = ~0,
// .swiPriority = 0
// //
//};
/*
* ========================= IO driver initialization =========================
* From main, PIN_init(BoardGpioInitTable) should be called to setup safe
* settings for this board.
* When a pin is allocated and then de-allocated, it will revert to the state
* configured in this table.
*/
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
@@ -73,20 +104,22 @@
#pragma DATA_SECTION(PINCC26XX_hwAttrs, ".const:PINCC26XX_hwAttrs")
#endif
const PIN_Config BoardGpioInitTable[] = {
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX */
Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX */
Board_SRDY | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* SRDY */
Board_MRDY | PIN_INPUT_EN | PIN_PULLDOWN, /* MRDY */
PIN_TERMINATE
};
const PIN_Config BoardGpioInitTable[] = { //
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX */
Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX */
Board_SRDY | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* SRDY */
Board_MRDY | PIN_INPUT_EN | PIN_PULLDOWN, /* MRDY */
PIN_TERMINATE};
const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
//
.intPriority = ~0,
.swiPriority = 0
//
};
/*============================================================================*/
/*
@@ -96,13 +129,14 @@ const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(PowerCC26XX_config, ".const:PowerCC26XX_config")
#endif
const PowerCC26XX_Config PowerCC26XX_config = {
.policyInitFxn = NULL,
.policyFxn = &PowerCC26XX_standbyPolicy,
.calibrateFxn = &PowerCC26XX_calibrate,
.enablePolicy = TRUE,
.calibrateRCOSC_LF = TRUE,
.calibrateRCOSC_HF = TRUE,
.policyInitFxn = NULL,
.policyFxn = &PowerCC26XX_standbyPolicy,
.calibrateFxn = &PowerCC26XX_calibrate,
.enablePolicy = TRUE,
.calibrateRCOSC_LF = TRUE,
.calibrateRCOSC_HF = TRUE,
};
/*
* ============================= Power end ====================================
@@ -126,28 +160,32 @@ UARTCC26XX_Object uartCC26XXObjects[BOOSTXL_CC2650MA_UARTCOUNT];
/* UART hardware parameter structure, also used to assign UART pins */
const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[BOOSTXL_CC2650MA_UARTCOUNT] = {
//
{
.baseAddr = UART0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_UART0,
.intNum = INT_UART0_COMB,
.intPriority = ~0,
.swiPriority = 0,
.txPin = Board_UART_TX,
.rxPin = Board_UART_RX,
.ctsPin = PIN_UNASSIGNED,
.rtsPin = PIN_UNASSIGNED
.baseAddr = UART0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_UART0,
.intNum = INT_UART0_COMB,
.intPriority = ~0,
.swiPriority = 0,
.txPin = Board_UART_TX,
.rxPin = Board_UART_RX,
.ctsPin = PIN_UNASSIGNED,
.rtsPin = PIN_UNASSIGNED
//
}
//
};
/* UART configuration structure */
const UART_Config UART_config[] = {
const UART_Config UART_config[] = { //
{
//
.fxnTablePtr = &UARTCC26XX_fxnTable,
.object = &uartCC26XXObjects[0],
.hwAttrs = &uartCC26XXHWAttrs[0]
//
},
{NULL, NULL, NULL}
};
{NULL, NULL, NULL}};
/*
* ============================= UART end =====================================
*/
@@ -169,22 +207,27 @@ UDMACC26XX_Object udmaObjects[BOOSTXL_CC2650MA_UDMACOUNT];
/* UDMA configuration structure */
const UDMACC26XX_HWAttrs udmaHWAttrs[BOOSTXL_CC2650MA_UDMACOUNT] = {
//
{
//
.baseAddr = UDMA0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_UDMA,
.intNum = INT_DMA_ERR,
.intPriority = ~0
//
}
//
};
/* UDMA configuration structure */
const UDMACC26XX_Config UDMACC26XX_config[] = {
const UDMACC26XX_Config UDMACC26XX_config[] = { //
{
.object = &udmaObjects[0],
.hwAttrs = &udmaHWAttrs[0]
//
.object = &udmaObjects[0],
.hwAttrs = &udmaHWAttrs[0]
//
},
{NULL, NULL}
};
{NULL, NULL}};
/*
* ============================= UDMA end =====================================
*/
@@ -193,53 +236,77 @@ const UDMACC26XX_Config UDMACC26XX_config[] = {
* ========================== SPI DMA begin ===================================
*/
/* Place into subsections to allow the TI linker to remove items properly */
// #if defined(__TI_COMPILER_VERSION__)
// #pragma DATA_SECTION(SPI_config, ".const:SPI_config")
// #pragma DATA_SECTION(spiCC26XXDMAHWAttrs, ".const:spiCC26XXDMAHWAttrs")
// #endif
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
#pragma DATA_SECTION(spiCC26XXDMAHWAttrs, ".const:spiCC26XXDMAHWAttrs")
#endif
// /* Include drivers */
// #include <ti/drivers/spi/SPICC26XXDMA.h>
/* Include drivers */
#include <ti/drivers/spi/SPICC26XXDMA.h>
// /* SPI objects */
// SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
/* SPI objects */
SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
// /* SPI configuration structure, describing which pins are to be used */
// const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_UDMACOUNT] = {
// {
// .baseAddr = SSI0_BASE,
// .intNum = INT_SSI0_COMB,
// .intPriority = ~0,
// .swiPriority = 0,
// .powerMngrId = PowerCC26XX_PERIPH_SSI0,
// .defaultTxBufValue = 0,
// .rxChannelBitMask = 1<<UDMA_CHAN_SSI0_RX,
// .txChannelBitMask = 1<<UDMA_CHAN_SSI0_TX,
// .mosiPin = Board_SPI0_MOSI,
// .misoPin = Board_SPI0_MISO,
// .clkPin = Board_SPI0_CLK,
// .csnPin = Board_SPI0_CS
// },
// };
/* SPI configuration structure, describing which pins are to be used */
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_SPICOUNT] = {
//
{
//
.baseAddr = SSI0_BASE,
.intNum = INT_SSI0_COMB,
.intPriority = ~0,
.swiPriority = 0,
.powerMngrId = PowerCC26XX_PERIPH_SSI0,
.defaultTxBufValue = 0,
.rxChannelBitMask = 1 << UDMA_CHAN_SSI0_RX,
.txChannelBitMask = 1 << UDMA_CHAN_SSI0_TX,
.mosiPin = Board_SPI0_MOSI,
.misoPin = Board_SPI0_MISO,
.clkPin = Board_SPI0_CLK,
.csnPin = PIN_UNASSIGNED
//
},
#ifdef HEADSTAGE_MA_USE_SPI2
{
//
.baseAddr = SSI1_BASE,
.intNum = INT_SSI1_COMB,
.intPriority = ~0,
.swiPriority = 0,
.powerMngrId = PowerCC26XX_PERIPH_SSI1,
.defaultTxBufValue = 0,
.rxChannelBitMask = 1 << UDMA_CHAN_SSI1_RX,
.txChannelBitMask = 1 << UDMA_CHAN_SSI1_TX,
.mosiPin = Board_SPI1_MOSI,
.misoPin = Board_SPI1_MISO,
.clkPin = Board_SPI1_CLK,
.csnPin = Board_SPI1_CS //
},
#endif
};
// /* SPI configuration structure */
// const SPI_Config SPI_config[] = {
// {
// .fxnTablePtr = &SPICC26XXDMA_fxnTable,
// .object = &spiCC26XXDMAObjects[0],
// .hwAttrs = &spiCC26XXDMAHWAttrs[0]
// },
// {
// .fxnTablePtr = &SPICC26XXDMA_fxnTable,
// .object = &spiCC26XXDMAObjects[1],
// .hwAttrs = &spiCC26XXDMAHWAttrs[1]
// },
// {NULL, NULL, NULL}
// };
/* SPI configuration structure */
const SPI_Config SPI_config[] = { //
{
//
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
.object = &spiCC26XXDMAObjects[0],
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
//
},
#ifdef HEADSTAGE_MA_USE_SPI2
{
//
.fxnTablePtr = &SPICC26XXDMA_fxnTable,
.object = &spiCC26XXDMAObjects[1],
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
//
},
#endif
{NULL, NULL, NULL}};
/*
* ========================== SPI DMA end =====================================
*/
*/
/*
* ========================== Crypto begin ====================================
@@ -259,28 +326,28 @@ const UDMACC26XX_Config UDMACC26XX_config[] = {
CryptoCC26XX_Object cryptoCC26XXObjects[BOOSTXL_CC2650MA_CRYPTOCOUNT];
/* Crypto configuration structure, describing which pins are to be used */
const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[BOOSTXL_CC2650MA_CRYPTOCOUNT] = {
{
.baseAddr = CRYPTO_BASE,
.powerMngrId = PowerCC26XX_PERIPH_CRYPTO,
.intNum = INT_CRYPTO_RESULT_AVAIL_IRQ,
.intPriority = ~0,
}
};
const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[BOOSTXL_CC2650MA_CRYPTOCOUNT] = {{
//
.baseAddr = CRYPTO_BASE,
.powerMngrId = PowerCC26XX_PERIPH_CRYPTO,
.intNum = INT_CRYPTO_RESULT_AVAIL_IRQ,
.intPriority = ~0,
//
}};
/* Crypto configuration structure */
const CryptoCC26XX_Config CryptoCC26XX_config[] = {
const CryptoCC26XX_Config CryptoCC26XX_config[] = { //
{
.object = &cryptoCC26XXObjects[0],
.hwAttrs = &cryptoCC26XXHWAttrs[0]
//
.object = &cryptoCC26XXObjects[0],
.hwAttrs = &cryptoCC26XXHWAttrs[0]
//
},
{NULL, NULL}
};
{NULL, NULL}};
/*
* ========================== Crypto end ======================================
*/
/*
* ========================= RF driver begin ==================================
*/
@@ -294,10 +361,12 @@ const CryptoCC26XX_Config CryptoCC26XX_config[] = {
/* RF hwi and swi priority */
const RFCC26XX_HWAttrs RFCC26XX_hwAttrs = {
//
.hwiCpe0Priority = ~0,
.hwiHwPriority = ~0,
.swiCpe0Priority = 5,
.swiHwPriority = 5,
.swiCpe0Priority = 5,
.swiHwPriority = 5,
//
};
/*
@@ -320,20 +389,21 @@ const RFCC26XX_HWAttrs RFCC26XX_hwAttrs = {
TRNGCC26XX_Object trngCC26XXObjects[BOOSTXL_CC2650MA_TRNGCOUNT];
/* TRNG configuration structure, describing which pins are to be used */
const TRNGCC26XX_HWAttrs TRNGCC26XXHWAttrs[BOOSTXL_CC2650MA_TRNGCOUNT] = {
{
.powerMngrId = PowerCC26XX_PERIPH_TRNG,
}
};
const TRNGCC26XX_HWAttrs TRNGCC26XXHWAttrs[BOOSTXL_CC2650MA_TRNGCOUNT] = {{
//
.powerMngrId = PowerCC26XX_PERIPH_TRNG,
//
}};
/* TRNG configuration structure */
const TRNGCC26XX_Config TRNGCC26XX_config[] = {
const TRNGCC26XX_Config TRNGCC26XX_config[] = { //
{
.object = &trngCC26XXObjects[0],
.hwAttrs = &TRNGCC26XXHWAttrs[0]
//
.object = &trngCC26XXObjects[0],
.hwAttrs = &TRNGCC26XXHWAttrs[0]
//
},
{NULL, NULL}
};
{NULL, NULL}};
/*
* ========================= TRNG end ====================================
@@ -351,14 +421,62 @@ const TRNGCC26XX_Config TRNGCC26XX_config[] = {
/* GPTimer hardware attributes, one per timer part (Timer 0A, 0B, 1A, 1B..) */
const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[BOOSTXL_CC2650MA_GPTIMERPARTSCOUNT] = {
{ .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, },
{ .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, },
{ .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, },
{ .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, },
{ .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, },
{ .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, },
{ .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, },
{ .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, },
{
.baseAddr = GPT0_BASE,
.intNum = INT_GPT0A,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT0,
.pinMux = GPT_PIN_0A,
},
{
.baseAddr = GPT0_BASE,
.intNum = INT_GPT0B,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT0,
.pinMux = GPT_PIN_0B,
},
{
.baseAddr = GPT1_BASE,
.intNum = INT_GPT1A,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT1,
.pinMux = GPT_PIN_1A,
},
{
.baseAddr = GPT1_BASE,
.intNum = INT_GPT1B,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT1,
.pinMux = GPT_PIN_1B,
},
{
.baseAddr = GPT2_BASE,
.intNum = INT_GPT2A,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT2,
.pinMux = GPT_PIN_2A,
},
{
.baseAddr = GPT2_BASE,
.intNum = INT_GPT2B,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT2,
.pinMux = GPT_PIN_2B,
},
{
.baseAddr = GPT3_BASE,
.intNum = INT_GPT3A,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT3,
.pinMux = GPT_PIN_3A,
},
{
.baseAddr = GPT3_BASE,
.intNum = INT_GPT3B,
.intPriority = (~0),
.powerMngrId = PowerCC26XX_PERIPH_GPT3,
.pinMux = GPT_PIN_3B,
},
};
/* GPTimer objects, one per full-width timer (A+B) (Timer 0, Timer 1..) */
@@ -366,14 +484,15 @@ GPTimerCC26XX_Object gptimerCC26XXObjects[BOOSTXL_CC2650MA_GPTIMERCOUNT];
/* GPTimer configuration (used as GPTimer_Handle by driver and application) */
const GPTimerCC26XX_Config GPTimerCC26XX_config[BOOSTXL_CC2650MA_GPTIMERPARTSCOUNT] = {
{ &gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[0], GPT_A },
{ &gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[1], GPT_B },
{ &gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[2], GPT_A },
{ &gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[3], GPT_B },
{ &gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[4], GPT_A },
{ &gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[5], GPT_B },
{ &gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[6], GPT_A },
{ &gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[7], GPT_B },
//
{&gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[0], GPT_A},
{&gptimerCC26XXObjects[0], &gptimerCC26xxHWAttrs[1], GPT_B},
{&gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[2], GPT_A},
{&gptimerCC26XXObjects[1], &gptimerCC26xxHWAttrs[3], GPT_B},
{&gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[4], GPT_A},
{&gptimerCC26XXObjects[2], &gptimerCC26xxHWAttrs[5], GPT_B},
{&gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[6], GPT_A},
{&gptimerCC26XXObjects[3], &gptimerCC26xxHWAttrs[7], GPT_B},
};
/*
@@ -391,14 +510,15 @@ const GPTimerCC26XX_Config GPTimerCC26XX_config[BOOSTXL_CC2650MA_GPTIMERPARTSCOU
#endif
/* PWM configuration, one per PWM output. */
PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[BOOSTXL_CC2650MA_PWMCOUNT] = {
{ .pwmPin = Board_PWMPIN0, .gpTimerUnit = Board_GPTIMER0A },
{ .pwmPin = Board_PWMPIN1, .gpTimerUnit = Board_GPTIMER0B },
{ .pwmPin = Board_PWMPIN2, .gpTimerUnit = Board_GPTIMER1A },
{ .pwmPin = Board_PWMPIN3, .gpTimerUnit = Board_GPTIMER1B },
{ .pwmPin = Board_PWMPIN4, .gpTimerUnit = Board_GPTIMER2A },
{ .pwmPin = Board_PWMPIN5, .gpTimerUnit = Board_GPTIMER2B },
{ .pwmPin = Board_PWMPIN6, .gpTimerUnit = Board_GPTIMER3A },
{ .pwmPin = Board_PWMPIN7, .gpTimerUnit = Board_GPTIMER3B },
//
{.pwmPin = Board_PWMPIN0, .gpTimerUnit = Board_GPTIMER0A},
{.pwmPin = Board_PWMPIN1, .gpTimerUnit = Board_GPTIMER0B},
{.pwmPin = Board_PWMPIN2, .gpTimerUnit = Board_GPTIMER1A},
{.pwmPin = Board_PWMPIN3, .gpTimerUnit = Board_GPTIMER1B},
{.pwmPin = Board_PWMPIN4, .gpTimerUnit = Board_GPTIMER2A},
{.pwmPin = Board_PWMPIN5, .gpTimerUnit = Board_GPTIMER2B},
{.pwmPin = Board_PWMPIN6, .gpTimerUnit = Board_GPTIMER3A},
{.pwmPin = Board_PWMPIN7, .gpTimerUnit = Board_GPTIMER3B},
};
/* PWM object, one per PWM output */
@@ -408,18 +528,300 @@ extern const PWM_FxnTable PWMTimerCC26XX_fxnTable;
/* PWM configuration (used as PWM_Handle by driver and application) */
const PWM_Config PWM_config[BOOSTXL_CC2650MA_PWMCOUNT + 1] = {
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[0], &pwmtimerCC26xxHWAttrs[0] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[1], &pwmtimerCC26xxHWAttrs[1] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[2], &pwmtimerCC26xxHWAttrs[2] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[3], &pwmtimerCC26xxHWAttrs[3] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[4], &pwmtimerCC26xxHWAttrs[4] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[5], &pwmtimerCC26xxHWAttrs[5] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[6], &pwmtimerCC26xxHWAttrs[6] },
{ &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[7], &pwmtimerCC26xxHWAttrs[7] },
{ NULL, NULL, NULL }
};
//
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[0], &pwmtimerCC26xxHWAttrs[0]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[1], &pwmtimerCC26xxHWAttrs[1]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[2], &pwmtimerCC26xxHWAttrs[2]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[3], &pwmtimerCC26xxHWAttrs[3]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[4], &pwmtimerCC26xxHWAttrs[4]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[5], &pwmtimerCC26xxHWAttrs[5]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[6], &pwmtimerCC26xxHWAttrs[6]},
{&PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[7], &pwmtimerCC26xxHWAttrs[7]},
{NULL, NULL, NULL}};
/*
* ============================= PWM end ======================================
*/
/*
* ============================= I2C Begin=====================================
*/
#ifdef HEADSTAGE_LED_USE_I2C
#define Board_I2C0_SCL0 IOID_10
#define Board_I2C0_SDA0 IOID_11
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
#pragma DATA_SECTION(i2cCC26xxHWAttrs, ".const:i2cCC26xxHWAttrs")
#endif
/* Include drivers */
#include <ti/drivers/i2c/I2CCC26XX.h>
/* I2C objects */
I2CCC26XX_Object i2cCC26xxObjects[BOOSTXL_CC2650MA_I2CCOUNT];
/* I2C configuration structure, describing which pins are to be used */
const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[BOOSTXL_CC2650MA_I2CCOUNT] = {
{
.baseAddr = I2C0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_I2C0,
.intNum = INT_I2C_IRQ,
.intPriority = ~0,
.swiPriority = 0,
.sdaPin = Board_I2C0_SDA0,
.sclPin = Board_I2C0_SCL0,
}
};
/* I2C configuration structure */
const I2C_Config I2C_config[] = {
{
.fxnTablePtr = &I2CCC26XX_fxnTable,
.object = &i2cCC26xxObjects[0],
.hwAttrs = &i2cCC26xxHWAttrs[0]
},
{NULL, NULL, NULL}
};
#endif
/*
* ========================== I2C end =========================================
*/
/*
* ========================= Display begin ====================================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(Display_config, ".const:Display_config")
#pragma DATA_SECTION(displaySharpHWattrs, ".const:displaySharpHWattrs")
#pragma DATA_SECTION(displayUartHWAttrs, ".const:displayUartHWAttrs")
#endif
#include <ti/mw/display/Display.h>
#include <ti/mw/display/DisplaySharp.h>
#include <ti/mw/display/DisplayUart.h>
/* Structures for UartPlain Blocking */
DisplayUart_Object displayUartObject;
#ifndef BOARD_DISPLAY_UART_STRBUF_SIZE
#define BOARD_DISPLAY_UART_STRBUF_SIZE 128
#endif
static char uartStringBuf[BOARD_DISPLAY_UART_STRBUF_SIZE];
const DisplayUart_HWAttrs displayUartHWAttrs = {
.uartIdx = Board_UART,
.baudRate = 115200,
.mutexTimeout = BIOS_WAIT_FOREVER,
.strBuf = uartStringBuf,
.strBufLen = BOARD_DISPLAY_UART_STRBUF_SIZE,
};
/* Structures for SHARP */
DisplaySharp_Object displaySharpObject;
#ifndef BOARD_DISPLAY_SHARP_SIZE
#define BOARD_DISPLAY_SHARP_SIZE 96 // 96->96x96 is the most common board, alternative is 128->128x128.
#endif
static uint8_t sharpDisplayBuf[BOARD_DISPLAY_SHARP_SIZE * BOARD_DISPLAY_SHARP_SIZE / 8];
const DisplaySharp_HWAttrs displaySharpHWattrs = {
.spiIndex = Board_SPI0,
.csPin = Board_LCD_CS,
.extcominPin = Board_LCD_EXTCOMIN,
.powerPin = Board_LCD_POWER,
.enablePin = Board_LCD_ENABLE,
.pixelWidth = BOARD_DISPLAY_SHARP_SIZE,
.pixelHeight = BOARD_DISPLAY_SHARP_SIZE,
.displayBuf = sharpDisplayBuf,
};
/* Array of displays */
const Display_Config Display_config[] = {
#if !defined(BOARD_DISPLAY_EXCLUDE_UART)
{
.fxnTablePtr = &DisplayUart_fxnTable,
.object = &displayUartObject,
.hwAttrs = &displayUartHWAttrs,
},
#endif
#if !defined(BOARD_DISPLAY_EXCLUDE_LCD)
{
.fxnTablePtr = &DisplaySharp_fxnTable,
.object = &displaySharpObject,
.hwAttrs = &displaySharpHWattrs
},
#endif
{ NULL, NULL, NULL } // Terminator
};
/*
* ========================= Display end ======================================
*/
/*
* ============================= Watchdog begin =====================================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
#pragma DATA_SECTION(wdCC26XXHWAttrs, ".const:wdCC26XXHWAttrs")
#endif
#include <ti/drivers/watchdog/WatchdogCC26XX.h>
WatchdogCC26XX_Object wdCC26XXObject[BOOSTXL_CC2650MA_WATCHDOGCOUNT];
const WatchdogCC26XX_HWAttrs wdCC26XXHWAttrs[] = {
{
.baseAddr = WDT_BASE,
.intNum = INT_WDT_IRQ,
.reloadValue = 100
}
};
/* I2S configuration structure */
const Watchdog_Config Watchdog_config[] = {
{
.fxnTablePtr = &WatchdogCC26XX_fxnTable,
.object = &wdCC26XXObject[0],
.hwAttrs = &wdCC26XXHWAttrs[0]
},
{NULL, NULL, NULL}
};
/*
* ============================= Watchdog end =====================================
*/
/*
* ================================ ADC begin ======================================
*/
#ifdef HEADSTAGE_RECORD_BATTERY
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(ADC_config, ".const:ADC_config")
#pragma DATA_SECTION(adcCC26xxHWAttrs, ".const:adcCC26xxHWAttrs")
#endif
#include <ti/drivers/ADC.h>
#include <ti/drivers/adc/ADCCC26XX.h>
/* ADC objects */
ADCCC26XX_Object adcCC26xxObjects[BOOSTXL_CC2650MA_ADCCOUNT];
const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[BOOSTXL_CC2650MA_ADCCOUNT] = {
{
.adcDIO = Board_DIO0_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO7,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO1_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO6,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO2_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO5,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO3_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO4,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO4_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO3,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO5_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO2,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO6_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO1,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = Board_DIO7_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO0,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = PIN_UNASSIGNED,
.adcCompBInput = ADC_COMPB_IN_DCOUPL,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = PIN_UNASSIGNED,
.adcCompBInput = ADC_COMPB_IN_VSS,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
},
{
.adcDIO = PIN_UNASSIGNED,
.adcCompBInput = ADC_COMPB_IN_VDDS,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL
}
};
const ADC_Config ADC_config[] = {
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[0], &adcCC26xxHWAttrs[0]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[1], &adcCC26xxHWAttrs[1]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[2], &adcCC26xxHWAttrs[2]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[3], &adcCC26xxHWAttrs[3]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[4], &adcCC26xxHWAttrs[4]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[5], &adcCC26xxHWAttrs[5]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[6], &adcCC26xxHWAttrs[6]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[7], &adcCC26xxHWAttrs[7]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[8], &adcCC26xxHWAttrs[8]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[9], &adcCC26xxHWAttrs[9]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[10], &adcCC26xxHWAttrs[10]},
{NULL, NULL, NULL},
};
/*
* ================================ ADC end ========================================
*/
#endif
@@ -89,25 +89,25 @@ extern const PIN_Config BoardGpioInitTable[];
*/
/* Connector J1 */
#define Board_BP_Pin_J1_2 DIO7
#define Board_BP_Pin_J1_3 DIO0
#define Board_BP_Pin_J1_4 DIO1
#define Board_BP_Pin_J1_5 DIO2
#define Board_BP_Pin_J1_6 DIO3
#define Board_BP_Pin_J1_7 DIO10
#define Board_BP_Pin_J1_8 DIO4
#define Board_BP_Pin_J1_9 DIO5
#define Board_BP_Pin_J1_10 DIO6
#define Board_BP_Pin_J1_2 IOID_UNUSED
#define Board_BP_Pin_J1_3 IOID_UNUSED
#define Board_BP_Pin_J1_4 IOID_UNUSED
#define Board_BP_Pin_J1_5 IOID_UNUSED
#define Board_BP_Pin_J1_6 IOID_UNUSED
#define Board_BP_Pin_J1_7 IOID_UNUSED
#define Board_BP_Pin_J1_8 IOID_UNUSED
#define Board_BP_Pin_J1_9 IOID_UNUSED
#define Board_BP_Pin_J1_10 IOID_UNUSED
/* Connector J2 */
#define Board_BP_Pin_J2_19 DIO8
#define Board_BP_Pin_J2_18 DIO9 /* CS */
#define Board_BP_Pin_J2_17 IOID_UNUSED /* NC */
#define Board_BP_Pin_J2_15 DIO11 /* MOSI */
#define Board_BP_Pin_J2_14 DIO12 /* MISO */
#define Board_BP_Pin_J2_13 DIO13
#define Board_BP_Pin_J2_12 DIO14
#define Board_BP_Pin_J2_11 IOID_UNUSED /* NC */
#define Board_BP_Pin_J2_19 IOID_UNUSED
#define Board_BP_Pin_J2_18 IOID_UNUSED /* CS */
#define Board_BP_Pin_J2_17 IOID_UNUSED /* NC */
#define Board_BP_Pin_J2_15 IOID_UNUSED /* MOSI */
#define Board_BP_Pin_J2_14 IOID_UNUSED /* MISO */
#define Board_BP_Pin_J2_13 IOID_UNUSED
#define Board_BP_Pin_J2_12 IOID_UNUSED
#define Board_BP_Pin_J2_11 IOID_UNUSED /* NC */
/* Mapping of BoosterPack Connector Pins to BoosterPack Standard Functions (reflecting the BoosterPack Standard)
*/
@@ -133,27 +133,74 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_BP_SPI_CS_Other Board_BP_Pin_J2_12
#define Board_BP_GPIO_2 Board_BP_Pin_J2_11
/* Mapping of application specific functionality of the BoosterPack to BoosterPack Pins (application dependent)
*/
/* UART Board */
#define Board_UART_TX DIO1 /* RXD */
#define Board_UART_RX DIO0 /* TXD */
/*
* interface with control box
*/
#if defined(MODA_MEMORY_BOARD)
#define Board_SPI0_MISO DIO12
#define Board_SPI0_MOSI DIO11
#define Board_SPI0_CLK DIO10
#define Board_SPI_CS DIO9
#define PIN_RAM_SEL DIO8 /* layout: MEM_SEL */
#define PIN_MEM_SEL DIO4 /* layout: MEM_RST */
#define PIN_MEM_BZY DIO13 /* layout: MEM_BZY */
#define PIN_MEM_REQ DIO14 /* layout: MEM_REQ */
#define PIN_MEM_TEST DIO7 /* layout: SPARE */
/* On-board LEDs */
#define Board_GLED PIN_UNASSIGNED /* Green LED */
#define Board_RLED PIN_UNASSIGNED /* Red LED */
#elif defined(MODA_BOOSTER_PACK)
#define Board_SPI0_MISO DIO7
#define Board_SPI0_MOSI DIO8
#define Board_SPI0_CLK DIO9
#define Board_SPI_CS DIO10
#define PIN_MEM_INS DIO1
#define PIN_MEM_SEL DIO2
#define PIN_MEM_BZY DIO12
#define PIN_MEM_REQ DIO0
#define PIN_MEM_TEST DIO4
/* On-board LEDs */
#define Board_GLED DIO2 /* Green LED */
#define Board_RLED DIO4 /* Red LED */
/* UART Board */
#define Board_UART_TX Board_BP_UART_Rx /* RXD */
#define Board_UART_RX Board_BP_UART_Tx /* TXD */
#else
#error "please define BOOSTXL_CC2650MA on BoosterPack or MemoryBoard"
#endif
//#define PIN_MEM_INS PIN_UNASSIGNED
//#define PIN_MEM_BZY PIN_UNASSIGNED
//#define PIN_MEM_REQ PIN_UNASSIGNED
//#define PIN_MEM_SEL DIO4
//#define PIN_MEM_TEST DIO2
// /* SPI Board */
// #define Board_SPI0_MISO Board_BP_SPI_MISO
// #define Board_SPI0_MOSI Board_BP_SPI_MOSI
// #define Board_SPI0_CLK Board_BP_SPI_CLK
// #define Board_SPI0_CS Board_BP_SPI_CS_Wireless
/*
* unused SPI
*/
#define Board_SPI1_MISO PIN_UNASSIGNED
#define Board_SPI1_MOSI PIN_UNASSIGNED
#define Board_SPI1_CLK PIN_UNASSIGNED
#define Board_SPI1_CS PIN_UNASSIGNED
#define Board_LCD_CS PIN_UNASSIGNED
#define Board_LCD_EXTCOMIN PIN_UNASSIGNED
#define Board_LCD_POWER PIN_UNASSIGNED
#define Board_LCD_ENABLE PIN_UNASSIGNED
/* Power Management Board */
#define Board_SRDY Board_BP_Pin_J2_19
#define Board_MRDY Board_BP_Pin_J1_2
#define Board_SRDY PIN_UNASSIGNED
#define Board_MRDY PIN_UNASSIGNED
/* PWM outputs */
#define Board_PWMPIN0 PIN_UNASSIGNED
@@ -165,16 +212,24 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_PWMPIN6 PIN_UNASSIGNED
#define Board_PWMPIN7 PIN_UNASSIGNED
/** ============================================================================
* Instance identifiers
* ==========================================================================*/
/* Generic SPI instance identifiers */
#define Board_SPI0 BOOSTXL_CC2650MA_SPI0
#ifdef HEADSTAGE_MA_USE_SPI2
#define Board_SPI1 BOOSTXL_CC2650MA_SPI1
#endif
/* Generic UART instance identifiers */
#define Board_UART BOOSTXL_CC2650MA_UART0
/* Generic TRNG instance identiifer */
#define Board_TRNG BOOSTXL_CC2650MA_TRNG0
/* Generic GPTimer instance identifiers */
#define Board_GPTIMER0A BOOSTXL_CC2650MA_GPTIMER0A
#define Board_GPTIMER0B BOOSTXL_CC2650MA_GPTIMER0B
@@ -184,6 +239,17 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_GPTIMER2B BOOSTXL_CC2650MA_GPTIMER2B
#define Board_GPTIMER3A BOOSTXL_CC2650MA_GPTIMER3A
#define Board_GPTIMER3B BOOSTXL_CC2650MA_GPTIMER3B
/* Generic ADC instance identifiers */
#define Board_DIO0_ANALOG PIN_UNASSIGNED
#define Board_DIO1_ANALOG PIN_UNASSIGNED
#define Board_DIO2_ANALOG PIN_UNASSIGNED
#define Board_DIO3_ANALOG PIN_UNASSIGNED
#define Board_DIO4_ANALOG PIN_UNASSIGNED
#define Board_DIO5_ANALOG PIN_UNASSIGNED
#define Board_DIO6_ANALOG PIN_UNASSIGNED
#define Board_DIO7_ANALOG PIN_UNASSIGNED
/* Generic PWM instance identifiers */
#define Board_PWM0 BOOSTXL_CC2650MA_PWM0
#define Board_PWM1 BOOSTXL_CC2650MA_PWM1
@@ -198,6 +264,16 @@ extern const PIN_Config BoardGpioInitTable[];
* Number of peripherals and their names
* ==========================================================================*/
/*
* @def BOOSTXL_CC2650MA_I2C
* @brief Enum of I2C names on the cc2650 dev board
*/
typedef enum BOOSTXL_CC2650MA_I2CName{
BOOSTXL_CC2650MA_I2C0 = 0,
BOOSTXL_CC2650MA_I2CCOUNT
} BOOSTXL_CC2650MA_I2CName;
/*!
* @def BOOSTXL_CC2650MA_CryptoName
* @brief Enum of Crypto names on the CC2650 Booster Pack
@@ -209,15 +285,19 @@ typedef enum BOOSTXL_CC2650MA_CryptoName {
} BOOSTXL_CC2650MA_CryptoName;
// /*!
// * @def BOOSTXL_CC2650MA_SPIName
// * @brief Enum of SPI names on the CC2650 Booster Pack
// */
// typedef enum BOOSTXL_CC2650MA_SPIName {
// BOOSTXL_CC2650MA_SPI0 = 0,
/*!
* @def BOOSTXL_CC2650MA_SPIName
* @brief Enum of SPI names on the CC2650 Booster Pack
*/
typedef enum BOOSTXL_CC2650MA_SPIName {
BOOSTXL_CC2650MA_SPI0 = 0,
// BOOSTXL_CC2650MA_SPICOUNT
// } BOOSTXL_CC2650MA_SPIName;
#ifdef HEADSTAGE_MA_USE_SPI2
BOOSTXL_CC2650MA_SPI1 ,
#endif
BOOSTXL_CC2650MA_SPICOUNT
} BOOSTXL_CC2650MA_SPIName;
/*!
* @def BOOSTXL_CC2650MA_TRNGName
@@ -295,6 +375,35 @@ typedef enum BOOSTXL_CC2650MA_PWM
BOOSTXL_CC2650MA_PWMCOUNT
} BOOSTXL_CC2650MA_PWM;
typedef enum BOOSTXL_CC2650MA_WATCHDOG
{
BOOSTXL_CC2650MA_WATCHDOG0 = 0,
BOOSTXL_CC2650MA_WATCHDOGCOUNT
} BOOSTXL_CC2650MA_WATCHDOG;
#ifdef HEADSTAGE_MA_USE_ADC
/*!
* @def BOOSTXL_CC2650MA_ADCName
* @brief Enum of ADCs
*/
typedef enum BOOSTXL_CC2650MA_ADCName {
BOOSTXL_CC2650MA_ADC0 = 0,
BOOSTXL_CC2650MA_ADC1,
BOOSTXL_CC2650MA_ADC2,
BOOSTXL_CC2650MA_ADC3,
BOOSTXL_CC2650MA_ADC4,
BOOSTXL_CC2650MA_ADC5,
BOOSTXL_CC2650MA_ADC6,
BOOSTXL_CC2650MA_ADC7,
BOOSTXL_CC2650MA_ADCDCOUPL,
BOOSTXL_CC2650MA_ADCVSS,
BOOSTXL_CC2650MA_ADCVDDS,
BOOSTXL_CC2650MA_ADCCOUNT
} BOOSTXL_CC2650MA_ADCName;
#endif
#ifdef __cplusplus
}
#endif
@@ -78,16 +78,19 @@ static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId);
/*******************************************************************************
* EXTERNAL VARIABLES
*/
extern bool procedureInProgress;
/*********************************************************************
* LOCAL VARIABLES
*/
PIN_State keyPins;
PIN_Handle hKeyPins;
// Value of keys Pressed
static uint8_t keysPressed;
uint8_t keysPressed;
// Key debounce clock
static Clock_Struct keyChangeClock;
Clock_Struct keyChangeClock;
// Pointer to application callback
keysPressedCB_t appKeyChangeHandler = NULL;
@@ -101,18 +104,30 @@ PIN_Config keyPinsCfg[] =
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
Board_BTN1 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_BTN2 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_UART_RX_IRQ | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
Board_KEY_SELECT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_UP | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_DOWN | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_LEFT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_RIGHT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
#elif defined(BOOSTXL_CC2650MA)
PIN_MEM_SEL | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
PIN_MEM_REQ | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
PIN_MEM_BZY | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
PIN_RAM_SEL | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
Board_SPI_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
PIN_MEM_TEST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,
#if defined(MODA_BOOSTER_PACK)
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
#endif
#endif
PIN_TERMINATE
};
PIN_State keyPins;
PIN_Handle hKeyPins;
extern uint16_t EventMask;
/*********************************************************************
* PUBLIC FUNCTIONS
@@ -128,38 +143,21 @@ PIN_Handle hKeyPins;
*/
void Board_initKeys(keysPressedCB_t appKeyCB)
{
// Initialize KEY pins. Enable int after callback registered
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
PIN_registerIntCb(hKeyPins, Board_keyCallback);
// Initialize KEY pins. Enable int after callback registered
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
PIN_registerIntCb(hKeyPins, Board_keyCallback);
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1 | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_NEGEDGE);
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_SELECT | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_UP | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_DOWN | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_LEFT | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_RIGHT | PIN_IRQ_NEGEDGE);
#endif
#if defined (BOOSTXL_CC2650MA)
// PIN_setConfig(hKeyPins, PIN_BM_IRQ, PIN_MEM_SEL | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, PIN_MEM_REQ | PIN_IRQ_NEGEDGE);
#ifdef POWER_SAVING
//Enable wakeup
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN1 | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN2 | PINCC26XX_WAKEUP_NEGEDGE);
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_SELECT | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_UP | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_DOWN | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_LEFT | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_RIGHT | PINCC26XX_WAKEUP_NEGEDGE);
#elif defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1 | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_NEGEDGE);
#endif
#endif //POWER_SAVING
// Setup keycallback for keys
Util_constructClock(&keyChangeClock, Board_keyChangeHandler,
KEY_DEBOUNCE_TIMEOUT, 0, false, 0);
Util_constructClock(&keyChangeClock, Board_keyChangeHandler, KEY_DEBOUNCE_TIMEOUT, 0, false, 0);
// Set the application callback
appKeyChangeHandler = appKeyCB;
@@ -176,47 +174,24 @@ void Board_initKeys(keysPressedCB_t appKeyCB)
*/
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)
{
keysPressed = 0;
keysPressed = 0;
#if defined (BOOSTXL_CC2650MA)
// if (PIN_getInputValue(PIN_MEM_REQ) == 0 && !procedureInProgress) {
// keysPressed |= KEY_REQ;
// flag_enable(EVT_PIN_REQST);
// }
#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
if ( PIN_getInputValue(Board_BTN1) == 0 )
{
keysPressed |= KEY_LEFT;
}
#elif defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)
if (PIN_getInputValue(Board_BTN1) == 0) {
keysPressed |= KEY_LEFT;
}
if ( PIN_getInputValue(Board_BTN2) == 0 )
{
keysPressed |= KEY_RIGHT;
}
#elif defined (CC2650DK_7ID) || defined (CC1350DK_7XD)
if ( PIN_getInputValue(Board_KEY_SELECT) == 0 )
{
keysPressed |= KEY_SELECT;
}
if ( PIN_getInputValue(Board_KEY_UP) == 0 )
{
keysPressed |= KEY_UP;
}
if ( PIN_getInputValue(Board_KEY_DOWN) == 0 )
{
keysPressed |= KEY_DOWN;
}
if ( PIN_getInputValue(Board_KEY_LEFT) == 0 )
{
keysPressed |= KEY_LEFT;
}
if ( PIN_getInputValue(Board_KEY_RIGHT) == 0 )
{
keysPressed |= KEY_RIGHT;
}
if (PIN_getInputValue(Board_BTN2) == 0) {
keysPressed |= KEY_RIGHT;
}
#endif
Util_startClock(&keyChangeClock);
Util_startClock(&keyChangeClock);
}
/*********************************************************************
@@ -55,11 +55,10 @@ extern "C" {
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
extern uint8_t KEY_INSTEAD_UART;
/*********************************************************************
* CONSTANTS
*/
@@ -68,9 +67,11 @@ extern "C" {
#define KEY_DOWN 0x0004
#define KEY_LEFT 0x0008
#define KEY_RIGHT 0x0010
#define KEY_UART_EN 0x0020
#define KEY_REQ 0x0040
// Debounce timeout in milliseconds
#define KEY_DEBOUNCE_TIMEOUT 200
#define KEY_DEBOUNCE_TIMEOUT 0
/*********************************************************************
* TYPEDEFS
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2015-2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated 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 OWNER 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 <ti/drivers/timer/GPTimerCC26XX.h>
#include <xdc/runtime/Types.h>
#include <ti/sysbios/BIOS.h>
#include "board.h"
#include "mem_board_central.h"
#define CLOCK_FREQ 4800 // clock freq = 0.1 ms(4800)
static void __timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
{
// interrupt callback code goes here. Minimize processing in interrupt.
elite_100us_task();
return;
}
void elite_gptimer_open(void)
{
GPTimerCC26XX_Handle hTimer;
GPTimerCC26XX_Params params;
GPTimerCC26XX_Params_init(&params);
params.width = GPT_CONFIG_16BIT;
params.mode = GPT_MODE_PERIODIC_UP;
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
hTimer = GPTimerCC26XX_open(Board_GPTIMER0A, &params);
if (hTimer == NULL) {
Task_exit();
}
Types_FreqHz freq;
BIOS_getCpuFreq(&freq);
//GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999 = 1ms
GPTimerCC26XX_Value loadVal = CLOCK_FREQ; //0.1ms
GPTimerCC26XX_setLoadValue(hTimer, loadVal);
GPTimerCC26XX_registerInterrupt(hTimer, __timerCallback, GPT_INT_TIMEOUT);
GPTimerCC26XX_start(hTimer);
return;
}
@@ -56,6 +56,7 @@
#include "icall.h"
#include "hal_assert.h"
#include "board.h"
#include "central.h"
#include "simple_central.h"
@@ -0,0 +1,13 @@
#ifndef __MEM_BOARD_CENTAL_H
#define __MEM_BOARD_CENTAL_H
#ifdef __cplusplus
extern "C" {
#endif
void elite_100us_task(void);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,336 @@
/*
* Reference web page https://github.com/ti-simplelink/ble_examples/tree/ble_examples-2.2
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_20_00_06/
* exports/tirtos_full_2_20_00_06/products/tidrivers_cc13xx_cc26xx_2_20_00_08/docs/
* doxygen/html/_u_a_r_t_c_c26_x_x_8h.html
*/
#ifndef MEM_BOARD_CENTRAL
#define MEM_BOARD_CENTRAL
#include <ti/sysbios/knl/Clock.h>
// GPT counter
struct gp_timer_t
{
uint32_t gp_timer_now;
uint32_t gp_timer_last;
uint8_t gp_timer_delta;
uint32_t gp_timer_switch_ram;
};
#define PIN_HIGH (5)
#define PIN_LOW (-5)
struct gp_timer_t gpt = {0};
#include "mem_central_handle_notify.h"
#define BLE_CHAR3_HANDLE 0x0024 // send instruction
#define BLE_CHAR4_CONFIG_HANDLE 0x0028 // notify enable: 0100=enable; 0000=disable
#define CIS_DATA_LEN 50
static uint16_t recv_regular_data_len = 0;
static char recv_regular_data[CIS_DATA_LEN];
static void mem_event_callback();
static void mem_connect_device(uint8_t addrType, uint8_t *peerAddr);
static void write_gatt_msg(uint16_t hadnle, uint8_t *value);
static void read_gatt_msg(uint8_t handle);
static void mem_board_init(void){
mem_sel_signal = central_pin_input(PIN_MEM_SEL);
mem_req_signal = central_pin_input(PIN_MEM_REQ);
elite_gptimer_open();
mem_uart_init();
mem_spi_init();
ram_select(0);
reset_status_register();
ram_select(1);
reset_status_register();
ram_select(0);
flag_enable(EVT_MEM_UART_ROUTINE);
}
static EventTableEntry EVENT_TABLE[] = { //
{EVT_ALL, &mem_event_callback},
// terminated
{0, NULL}
};
static void gatt_msg_rsp()
{
/*
* CIS data formate:
* Elite send to central:
* +------------+------------------+
* | Header(1B) | Payload(nB) |
* +------------+------------------+
* |d0(recv_len)| d1, d2, d3, ... |
* +------------+------------------+
* ex: | 0x03 | 0x10,0xC0,0x01 | <--- barrery data
* +------------+------------------+
*
* central send to controller:
* +--------------------+------------------+
* | Header(3B) | Payload |
* +---+---+------------+------------------+
* | 4 | 0 | ret_length | d1, d2, d3, ... |
* +---+---+------------+------------------+
* ex: | 4 | 0 | 0x14 | 0x10,0xC0,0x01 | <--- barrery data
* +---+---+------------+------------------+
*
*/
#define MSG_RSP_LEN (recv_regular_data_len+3)
char msg_rsp[CIS_DATA_LEN] = {0};
msg_rsp[0] = 4;
msg_rsp[1] = 0;
msg_rsp[2] = recv_regular_data_len;
memcpy(msg_rsp+3, recv_regular_data, recv_regular_data_len);
UART_write(uart_handle, msg_rsp, MSG_RSP_LEN);
}
/**
* system event handle. It go through [EVENT_TABLE] and invoke event callback
* if event_mask bits set.
*/
static void mem_event_handle() {
for (EventTableEntry *entry = EVENT_TABLE; EventMask && entry->event_mask; entry++) {
if (entry->event_callback && flag_mask(entry->event_mask)) {
entry->event_callback();
}
}
}
static void mem_event_callback() {
if(flag_mask(EVT_MEM_NOTIFY_HANDLE)){
flag_disable(EVT_MEM_NOTIFY_HANDLE);
central_handle_notify();
}
if(flag_mask(EVT_MEM_UART_ROUTINE)){
flag_disable(EVT_MEM_UART_ROUTINE);
int rxBytes = UART_read(uart_handle, UART_rxBuf, 1);
}
if(flag_mask(EVT_MEM_INS_CHECK_SURVIVE)){
flag_disable(EVT_MEM_INS_CHECK_SURVIVE);
char ACK[4] = {4,0,1,3}; //ack success
UART_write(uart_handle, ACK, sizeof(ACK)/sizeof(ACK[0]));
}
if(flag_mask(EVT_MEM_INS_SCAN)){
flag_disable(EVT_MEM_INS_SCAN);
SimpleBLECentral_discoverDevices();
}
if(flag_mask(EVT_MEM_INS_CONNECT)){
flag_disable(EVT_MEM_INS_CONNECT);
mem_connect_device(store_rxBuf[2], store_rxBuf+3);
}
if(flag_mask(EVT_MEM_INS_WRITE)){
flag_disable(EVT_MEM_INS_WRITE);
if(state == BLE_STATE_CONNECTED){
// This is done by SimpleBLECentral_processRoleEvent() in the case "GAP_LINK_ESTABLISHED_EVENT"
write_gatt_msg(store_rxBuf[2], store_rxBuf+3);
}
}
if(flag_mask(EVT_MEM_INS_READ)){
flag_disable(EVT_MEM_INS_READ);
if(state == BLE_STATE_CONNECTED){
read_gatt_msg(store_rxBuf[2]);
}
}
if(flag_mask(EVT_MEM_INS_DISCONNECT)){
flag_disable(EVT_MEM_INS_DISCONNECT);
GAPCentralRole_TerminateLink(connHandle);
state = BLE_STATE_DISCONNECTING;
}
if(flag_mask(EVT_MEM_RETURN_DATA)){
flag_disable(EVT_MEM_RETURN_DATA);
gatt_msg_rsp();
}
}
static void mem_connect_device(uint8_t addrType, uint8_t *peerAddr) {
uint8_t Addr[B_ADDR_LEN];
for(int i=0 ; i<B_ADDR_LEN ; i++){
Addr[5-i] = *(peerAddr+i);
}
// UART_write(uart_handle, Addr, 6);
state = BLE_STATE_CONNECTING;
Util_startClock(&connectingClock);
GAPCentralRole_EstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE,
DEFAULT_LINK_WHITE_LIST,
addrType, Addr);
}
static void write_gatt_msg(uint16_t handle, uint8_t *value){
if (state == BLE_STATE_CONNECTED &&
charHdl != 0 &&
procedureInProgress == FALSE)
{
uint8_t status;
// Do a read or write as long as no other read or write is in progress
// Do a write
attWriteReq_t req;
// enable notify
req.handle = handle;
req.len = 19;
if(handle == BLE_CHAR3_HANDLE){
// RIS, VIS, CIS instruction
req.len = 19;
}
else if(handle == BLE_CHAR4_CONFIG_HANDLE){
// notify enable
req.len = 2;
}
else{
uint8_t error_handle[13] = "error handle";
UART_write(uart_handle, error_handle, 13);
status = bleMemAllocError;
return;
}
req.pValue = GATT_bm_alloc(connHandle, ATT_WRITE_REQ, req.len, NULL);
if ( req.pValue != NULL )
{
// send instruction
for(int i=0 ; i < req.len ; i++){
req.pValue[i] = *(value+i);
}
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue(connHandle, &req, selfEntity);
// uncomment GATT_WriteLongCharValue if we need a long instruction;
// However, there are some error to fix when using GATT_WriteLongCharValue
// status = GATT_WriteLongCharValue(connHandle, &req, selfEntity);
if ( status != SUCCESS )
{
GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
}
}
else
{
uint8_t error_msg[10] = "err";
error_msg[3] = req.handle;
error_msg[4] = *value;
error_msg[5] = *(value+1);
error_msg[6] = *(value+2);
error_msg[7] = *(value+3);
error_msg[8] = *(value+4);
error_msg[9] = *(value+5);
UART_write(uart_handle, error_msg, 10);
status = bleMemAllocError;
}
if (status == SUCCESS)
{
procedureInProgress = TRUE;
}
}
}
static void read_gatt_msg(uint8_t handle){
// get the actual CIS data from simple_central.c > SimpleBLECentral_processGATTMsg()
if (state == BLE_STATE_CONNECTED &&
charHdl != 0 &&
procedureInProgress == FALSE)
{
uint8_t status;
// send read command
attReadReq_t read_cis_req;
read_cis_req.handle = handle;
status = GATT_ReadCharValue(connHandle, &read_cis_req, selfEntity);
if (status == SUCCESS)
{
procedureInProgress = TRUE;
}
}
}
void elite_100us_task(void)
{
//read signal
static int mem_sel_times = 0;
static int mem_req_times = 0;
gpt.gp_timer_now++;
events |= SBC_PERIODIC_EVT;
mem_sel_times += central_pin_input(PIN_MEM_SEL) ? 1 : -1;
if (mem_sel_times >= PIN_HIGH) {
mem_sel_times = PIN_HIGH;
mem_sel_signal = TRUE;
mem_req_times = 0;
} else if (mem_sel_times <= PIN_LOW) {
mem_sel_times = PIN_LOW;
mem_sel_signal = FALSE;
}
if (mem_sel_signal == FALSE) {
mem_req_times += central_pin_input(PIN_MEM_REQ) ? 1 : -1;
if (mem_req_times >= PIN_HIGH) {
mem_req_times = PIN_HIGH;
mem_req_signal = TRUE;
} else if (mem_req_times <= PIN_LOW) {
mem_req_times = PIN_LOW;
mem_req_signal = FALSE;
}
}
Semaphore_post(sem);
}
void periodic_evevnt()
{
static bool ram_event = FALSE;
gpt.gp_timer_delta = gpt.gp_timer_now - gpt.gp_timer_last;
gpt.gp_timer_last = gpt.gp_timer_now;
if (!ram_event && mem_sel_signal == FALSE) {
if (mem_req_signal != ram_sel_signal) {
ram_event = TRUE;
gpt.gp_timer_switch_ram = 0;
}
}
if (ram_event) {
gpt.gp_timer_switch_ram++;
if (gpt.gp_timer_switch_ram >= 1000) {
gpt.gp_timer_switch_ram = 0;
ram_event = FALSE;
write_green_data_and_switch_ram();
}
}
}
#endif
@@ -0,0 +1,150 @@
#ifndef CENTRAL_NOTIFY
#define CENTRAL_NOTIFY
#define MEM_BUFFER_SIZE 250
static uint16_t elite_pkg_length = 0;
static uint8_t recv_elite_data[MEM_BUFFER_SIZE] = {0}; // recv data from elite
void write_green_data_and_switch_ram();
#define MEM_REG_WRITE 0x01
#define MEM_INS_WRITE 0x02
#define MEM_INS_READ 0x03
#define RAM_INS_LEN 3
#define RAM_RED_HDR_LEN 3
#define ELITE_PKG_LEN 40
#define RAM_RED_TAILER_LEN 5
#define RAM_RED_CHECK_SUM_LEN 1
#define RAM_RED_DATA_LEN (RAM_RED_HDR_LEN + ELITE_PKG_LEN + RAM_RED_TAILER_LEN + RAM_RED_CHECK_SUM_LEN)
#define RAM_RED_CTX_LEN (RAM_INS_LEN + RAM_RED_DATA_LEN)
#define RAM_GREEN_DATA_LEN 12
#define RAM_GREEN_CTX_LEN (RAM_INS_LEN + RAM_GREEN_DATA_LEN)
static uint16_t write_ram_addr = RAM_GREEN_DATA_LEN; // writing pointer, where to write on RAM
static uint8_t green_wrong = 0;
static uint8_t green_retry_cnt = 0;
static void reset_status_register()
{
uint8_t status_register_buf[2] = {MEM_REG_WRITE, 0b01000001};
central_spi_send(status_register_buf, 2);
}
uint8_t check_sum(uint8_t message[], int nBytes)
{
uint8_t sum = 0;
while (nBytes-- > 0) {
sum += *(message++);
}
return sum;
}
static void central_handle_notify()
{
int index = 0;
bool write_again = false;
uint8_t write_limit = 0;
static uint8_t red_wrong = 0;
static uint8_t red_retry_cnt = 0;
static uint8_t mem_pkg_sequence = 0; // increase when receiving data from elite
uint8_t write_ins[RAM_INS_LEN] = {MEM_INS_WRITE, (uint8_t)(write_ram_addr >> 8), (uint8_t)(write_ram_addr)};
uint8_t red_hdr[RAM_RED_HDR_LEN] = {0xFF, mem_pkg_sequence, elite_pkg_length};
uint8_t red_tailer[RAM_RED_TAILER_LEN] = {red_wrong, red_retry_cnt, green_wrong, green_retry_cnt, ram_sel_signal};
uint8_t write_ram_ins[RAM_RED_CTX_LEN] = {0};
uint8_t read_ram_ins[RAM_RED_CTX_LEN] = {MEM_INS_READ, (uint8_t)(write_ram_addr >> 8), (uint8_t)(write_ram_addr)};
uint8_t read_ram_buf[RAM_RED_CTX_LEN] = {0};
memcpy(write_ram_ins, write_ins, RAM_INS_LEN);
index += RAM_INS_LEN;
memcpy(write_ram_ins+index, red_hdr, RAM_RED_HDR_LEN);
index += RAM_RED_HDR_LEN;
memcpy(write_ram_ins+index, recv_elite_data, ELITE_PKG_LEN);
index += ELITE_PKG_LEN;
memcpy(write_ram_ins+index, red_tailer, RAM_RED_TAILER_LEN);
index += RAM_RED_TAILER_LEN;
write_ram_ins[index] = check_sum(write_ram_ins+RAM_INS_LEN, RAM_RED_HDR_LEN+ELITE_PKG_LEN+RAM_RED_TAILER_LEN);
while (1) {
write_again = false;
central_spi_send(write_ram_ins, RAM_RED_CTX_LEN);
central_spi_recv(read_ram_ins, read_ram_buf);
// compare check_sum
if (read_ram_buf[RAM_RED_CTX_LEN-1] != write_ram_ins[RAM_RED_CTX_LEN-1]) {
write_again = true;
red_retry_cnt++;
write_limit++;
reset_status_register();
}
if (!write_again)
break;
if (write_limit >= 5) {
red_wrong++;
reset_status_register();
break;
}
}
if (write_ram_addr > 7500)
write_ram_addr = write_ram_addr;
else
write_ram_addr += RAM_RED_DATA_LEN;
mem_pkg_sequence++;
}
void write_green_data_and_switch_ram()
{
uint8_t write_ram_ins[RAM_GREEN_CTX_LEN] = {
MEM_INS_WRITE, 0, 0,
(uint8_t)(write_ram_addr >> 8), (uint8_t)(write_ram_addr), 0xA5, 0x5A,
(uint8_t)(write_ram_addr >> 8), (uint8_t)(write_ram_addr), 0xA5, 0x5A,
(uint8_t)(write_ram_addr >> 8), (uint8_t)(write_ram_addr), 0xA5, 0x5A};
uint8_t read_ram_ins[RAM_GREEN_CTX_LEN] = {MEM_INS_READ, 0, 0};
uint8_t read_ram_buf[RAM_GREEN_CTX_LEN] = {0};
uint8_t write_limit = 0;
bool write_again = false;
while (1) {
write_again = false;
central_spi_send(write_ram_ins, RAM_GREEN_CTX_LEN);
central_spi_recv(read_ram_ins, read_ram_buf);
// compare data
for (int i=3; i<RAM_GREEN_CTX_LEN; i++) {
if (write_ram_ins[i] != read_ram_buf[i]) {
write_again = true;
green_retry_cnt++;
write_limit++;
reset_status_register();
break;
}
}
if (!write_again)
break;
if (write_limit >= 5) {
green_wrong++;
reset_status_register();
break;
}
}
// switch RAM
ram_select(!ram_sel_signal);
CPUdelay(10 * 16); // 10us
write_ram_addr = RAM_GREEN_DATA_LEN; //reset ram_addr
}
#endif
@@ -0,0 +1,23 @@
#ifndef MEM_CENTRAL_PIN
#define MEM_CENTRAL_PIN
//extern PIN_State keyPins;
extern PIN_Handle hKeyPins;
#define central_pin_output(pin, value) PIN_setOutputValue(hKeyPins, PIN_ID(pin), (value))
#define central_pin_input(pin) PIN_getInputValue(PIN_ID(pin))
void ram_select(bool value)
{
ram_sel_signal = value;
central_pin_output(PIN_RAM_SEL, (ram_sel_signal) ? 1 : 0);
if (ram_sel_signal) {
central_pin_output(PIN_MEM_TEST, 1);
} else {
central_pin_output(PIN_MEM_TEST, 0);
}
}
#endif
@@ -0,0 +1,45 @@
#ifndef CENTRAL_SPI_H
#define CENTRAL_SPI_H
// clang-format off
#include <ti/drivers/SPI.h>
#include <ti/drivers/dma/UDMACC26XX.h>
#include <ti/drivers/spi/SPICC26XXDMA.h>
// clang-format on
static SPI_Handle central_spi_handle;
static SPI_Transaction central_spi_transaction;
void mem_spi_init() {
SPI_init();
SPI_Params spi_parameter;
SPI_Params_init(&spi_parameter);
spi_parameter.transferMode = SPI_MODE_BLOCKING;
spi_parameter.mode = SPI_MASTER;
spi_parameter.bitRate = 12000000;
spi_parameter.transferTimeout = 1000;
spi_parameter.dataSize = 8;
spi_parameter.frameFormat = SPI_POL0_PHA0;
central_spi_handle = SPI_open(Board_SPI0, &spi_parameter);
}
#define central_spi_send(data, len) \
do { \
central_spi_transaction.txBuf = data; \
central_spi_transaction.rxBuf = NULL; \
central_spi_transaction.count = (len); \
central_pin_output(Board_SPI_CS, 0); \
SPI_transfer(central_spi_handle, &central_spi_transaction); \
central_pin_output(Board_SPI_CS, 1); \
} while (0)
#define central_spi_recv(ins, data) \
do { \
central_spi_transaction.txBuf = ins; \
central_spi_transaction.rxBuf = data; \
central_pin_output(Board_SPI_CS, 0); \
SPI_transfer(central_spi_handle, &central_spi_transaction); \
central_pin_output(Board_SPI_CS, 1); \
} while (0)
#endif // CENTRAL_SPI_H
@@ -0,0 +1,50 @@
#ifndef MEM_EVENT_H
#define MEM_EVENT_H
/**
* test event [flag] has been enabled.
*/
#define flag_mask(flag) ((EventMask & (flag)) != 0)
/**
* disable event [flag].
*/
#define flag_disable(flag) \
do { \
uint8 __key = Hwi_disable(); \
EventMask &= ~((uint16_t)(flag)); \
Hwi_restore(__key); \
} while (0)
/**
* enable event [flag].
*/
#define flag_enable(flag) \
do { \
uint8 __key = Hwi_disable(); \
EventMask |= (uint16_t)(flag); \
Hwi_restore(__key); \
Semaphore_post(sem); \
} while (0)
uint16_t EventMask = 0;
/**
* event table entry.
*/
typedef struct {
/**
* event mask.
*/
uint16_t event_mask;
/**
* event callback. invoked by system when system [EVENT_MASK] set with
* [event_mask] bits.
*/
void (*event_callback)();
} EventTableEntry;
#endif
@@ -0,0 +1,149 @@
#ifndef MEM_UART
#define MEM_UART
/*
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/
* 2_20_00_06/exports/tirtos_full_2_20_00_06/products/tidrivers_cc13xx_cc26xx_2_20_00_08/
* docs/doxygen/html/_u_a_r_t_c_c26_x_x_8h.html
*/
#include <ti/drivers/UART.h>
#include <ti/drivers/uart/UARTCC26XX.h>
#define UART_BUFF_SIZE 25
static UART_Handle uart_handle;
static UART_Params params;
static uint8_t UART_rxBuf[UART_BUFF_SIZE];
static uint8_t store_rxBuf[UART_BUFF_SIZE];
typedef enum{
INS_IDLE,
INS_RESET,
INS_KEY,
INS_SCAN,
INS_SCAN_RESPONSE,
INS_CONNECT,
INS_WRITE,
INS_READ,
INS_DISCONNECT,
INS_PREPARE_CONNECT,
INS_CHECK_SURVIVE
} Control_Ins;
static Control_Ins ins = INS_IDLE;
/** event */
#define EVT_ALL 0xFFFF
#define EVT_MEM_RETURN_DATA 0x0010
#define EVT_MEM_NOTIFY_HANDLE 0x0040
#define EVT_MEM_UART_ROUTINE 0x0080
#define EVT_MEM_INS_SCAN 0x0100
#define EVT_MEM_INS_CONNECT 0x0200
#define EVT_MEM_INS_WRITE 0x0400
#define EVT_MEM_INS_READ 0x0800
#define EVT_MEM_INS_DISCONNECT 0x1000
#define EVT_MEM_INS_CHECK_SURVIVE 0x2000
#define IS_EVT_MEM_DECODE_INS(_b) ((_b)[0] == INS_SCAN || \
(_b)[0] == INS_CONNECT || \
(_b)[0] == INS_WRITE || \
(_b)[0] == INS_READ || \
(_b)[0] == INS_DISCONNECT || \
(_b)[0] == INS_CHECK_SURVIVE)
// Callback function
static void uart_recv_callback(UART_Handle handle, void *rxBuf, size_t size)
{
uint8_t *uart_rxBuf = (uint8_t *)rxBuf;
static int index = 0;
static int length = 0;
static bool rx_fi = false;
if (rx_fi) {
memset(store_rxBuf, 0, UART_BUFF_SIZE);
rx_fi = false;
}
if (IS_EVT_MEM_DECODE_INS(uart_rxBuf) && index == 0) {
store_rxBuf[0] = uart_rxBuf[0];
index++;
} else if (IS_EVT_MEM_DECODE_INS(store_rxBuf) && index == 1) {
store_rxBuf[1] = uart_rxBuf[0];
length = uart_rxBuf[0];
index++;
} else if (IS_EVT_MEM_DECODE_INS(store_rxBuf) && index > 1) {
store_rxBuf[index] = uart_rxBuf[0];
if (index >= length + 2) { //num = 0 when over length
store_rxBuf[index] = 0;
}
index++;
}
//0xF1 = 241
if(index > 1 && store_rxBuf[0] == INS_SCAN && store_rxBuf[length + 1] == 0xF1 ) {
index = 0;
length = 0;
flag_enable(EVT_MEM_INS_SCAN);
flag_enable(EVT_MEM_UART_ROUTINE);
rx_fi = true;
return;
} else if (index > 1 && store_rxBuf[0] == INS_CONNECT && store_rxBuf[length + 1] == 0xF1) {
index = 0;
length = 0;
flag_enable(EVT_MEM_INS_CONNECT);
flag_enable(EVT_MEM_UART_ROUTINE);
rx_fi = true;
return;
} else if (index > 1 && store_rxBuf[0] == INS_WRITE && store_rxBuf[length + 1] == 0xF1) {
index = 0;
length = 0;
flag_enable(EVT_MEM_INS_WRITE);
flag_enable(EVT_MEM_UART_ROUTINE);
rx_fi = true;
return;
} else if (index > 1 && store_rxBuf[0] == INS_READ && store_rxBuf[length + 1] == 0xF1) {
index = 0;
length = 0;
flag_enable(EVT_MEM_INS_READ);
flag_enable(EVT_MEM_UART_ROUTINE);
rx_fi = true;
return;
} else if (index > 1 && store_rxBuf[0] == INS_DISCONNECT && store_rxBuf[length + 1] == 0xF1) {
index = 0;
length = 0;
flag_enable(EVT_MEM_INS_DISCONNECT);
flag_enable(EVT_MEM_UART_ROUTINE);
rx_fi = true;
return;
} else if (index > 1 && store_rxBuf[0] == INS_CHECK_SURVIVE && store_rxBuf[length + 1] == 0xF1) {
index = 0;
length = 0;
flag_enable(EVT_MEM_INS_CHECK_SURVIVE);
flag_enable(EVT_MEM_UART_ROUTINE);
rx_fi = true;
return;
}
flag_enable(EVT_MEM_UART_ROUTINE);
}
static void mem_uart_init(){
// Init UART and specify non-default parameters
UART_Params_init(&params);
params.baudRate = 115200;
params.writeDataMode = UART_DATA_BINARY;
params.readMode = UART_MODE_CALLBACK;
params.readDataMode = UART_DATA_BINARY;
params.readCallback = uart_recv_callback;
// Open the UART and do the read
uart_handle = UART_open(Board_UART, &params);
return;
}
#endif
File diff suppressed because it is too large Load Diff
@@ -24,7 +24,7 @@ static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_In
GPTimerCC26XX_Params params; \
GPTimerCC26XX_Params_init(&params); \
params.width = GPT_CONFIG_16BIT; \
params.mode = GPT_MODE_PERIODIC_DOWN; \
params.mode = GPT_MODE_PERIODIC_UP; \
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; \
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, &params); \
Types_FreqHz freq; \
@@ -50,6 +50,7 @@
*/
#include <string.h>
// clang-format off
#include "bcomdef.h"
#include "osal.h"
#include "linkdb.h"
@@ -58,61 +59,21 @@
#include "gatt_uuid.h"
#include "gattservapp.h"
#include "gapbondmgr.h"
// clang-format on
#include "simple_gatt_profile.h"
/*********************************************************************
* MACROS
*/
#define _UUID(_uuid) \
{ LO_UINT16(_uuid), HI_UINT16(_uuid) }
/*********************************************************************
* CONSTANTS
*/
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_SERV_UUID); // Simple GATT Profile Service UUID: 0xFFF0
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR1_UUID); // Characteristic 1 UUID: 0xFFF1
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR2_UUID); // Characteristic 2 UUID: 0xFFF2
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR3_UUID); // Characteristic 3 UUID: 0xFFF3
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR4_UUID); // Characteristic 4 UUID: 0xFFF4
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] = _UUID(SIMPLEPROFILE_CHAR5_UUID); // Characteristic 5 UUID: 0xFFF5
#define SERVAPP_NUM_ATTR_SUPPORTED 17
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
// Simple GATT Profile Service UUID: 0xFFF0
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID)
};
// Characteristic 1 UUID: 0xFFF1
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR1_UUID), HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
};
// Characteristic 2 UUID: 0xFFF2
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR2_UUID), HI_UINT16(SIMPLEPROFILE_CHAR2_UUID)
};
// Characteristic 3 UUID: 0xFFF3
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR3_UUID), HI_UINT16(SIMPLEPROFILE_CHAR3_UUID)
};
// Characteristic 4 UUID: 0xFFF4
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR4_UUID), HI_UINT16(SIMPLEPROFILE_CHAR4_UUID)
};
// Characteristic 5 UUID: 0xFFF5
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR5_UUID), HI_UINT16(SIMPLEPROFILE_CHAR5_UUID)
};
#undef _UUID
/*********************************************************************
* EXTERNAL VARIABLES
@@ -133,50 +94,30 @@ static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
*/
// Simple Profile Service attribute
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };
static CONST gattAttrType_t simpleProfileService = {ATT_BT_UUID_SIZE, simpleProfileServUUID};
// Simple Profile Characteristic 1 Properties
// static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE;
/*user insert*/
static uint8 simpleProfileChar1Props = GATT_PROP_READ;
// Characteristic 1 Value
// static uint8 simpleProfileChar1 = 0;
/*user insert*/
#define SIMPLEPROFILE_CHAR1_LEN 20
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = {0};
// Simple Profile Characteristic 1 User Description
static uint8 simpleProfileChar1UserDesp[17] = "Characteristic 1";
// Simple Profile Characteristic 2 Properties
static uint8 simpleProfileChar2Props = GATT_PROP_READ;
// Characteristic 2 Value
// static uint8 simpleProfileChar2 = 0;
/*user insert*/
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = {0};
// Simple Profile Characteristic 2 User Description
static uint8 simpleProfileChar2UserDesp[17] = "Characteristic 2";
// Simple Profile Characteristic 3 Properties
static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
// Characteristic 3 Value
// static uint8 simpleProfileChar3 = 0;
/*user insert*/
static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = {0};
// Simple Profile Characteristic 3 User Description
static uint8 simpleProfileChar3UserDesp[17] = "Characteristic 3";
// Simple Profile Characteristic 4 Properties
static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
// Characteristic 4 Value
// static uint8 simpleProfileChar4 = 0;
/*user insert*/
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
// Simple Profile Characteristic 4 Configuration Each client has its own
@@ -185,175 +126,89 @@ static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
// that client and writes only affect the configuration of that client.
static gattCharCfg_t *simpleProfileChar4Config;
// Simple Profile Characteristic 4 User Description
static uint8 simpleProfileChar4UserDesp[17] = "Characteristic 4";
// Simple Profile Characteristic 5 Properties
static uint8 simpleProfileChar5Props = GATT_PROP_READ;
static uint8 simpleProfileChar5Props = GATT_PROP_READ | GATT_PROP_WRITE;
// Characteristic 5 Value
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = { 0, 0, 0, 0, 0 };
// Simple Profile Characteristic 5 User Description
static uint8 simpleProfileChar5UserDesp[17] = "Characteristic 5";
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = {0};
/*********************************************************************
* Profile Attributes - Table
*/
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
{
// Simple Profile Service
{
{ ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
GATT_PERMIT_READ, /* permissions */
0, /* handle */
(uint8 *)&simpleProfileService /* pValue */
},
#define SERVAPP_NUM_ATTR_SUPPORTED 17
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] = {
// Simple Profile Service
{{ATT_BT_UUID_SIZE, primaryServiceUUID}, GATT_PERMIT_READ, 0, (uint8 *)&simpleProfileService},
// Characteristic 1 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar1Props
},
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar1Props},
// Characteristic Value 1
{
{ ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
GATT_PERMIT_READ,
0,
simpleProfileChar1
},
// Characteristic Value 1
{{ATT_BT_UUID_SIZE, simpleProfilechar1UUID}, GATT_PERMIT_READ, 0, simpleProfileChar1},
// Characteristic 1 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar1UserDesp
},
// Characteristic 1 User Description
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "FS"},
// Characteristic 2 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar2Props
},
// Characteristic Value 2
{
{ ATT_BT_UUID_SIZE, simpleProfilechar2UUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2
},
// Characteristic 2 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2UserDesp
},
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar2Props},
// Characteristic Value 2
{{ATT_BT_UUID_SIZE, simpleProfilechar2UUID}, GATT_PERMIT_READ, 0, simpleProfileChar2},
// Characteristic 2 User Description
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "CR"},
// Characteristic 3 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar3Props
},
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar3Props},
// Characteristic Value 3
{
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
GATT_PERMIT_WRITE,
0,
simpleProfileChar3
},
{{ATT_BT_UUID_SIZE, simpleProfilechar3UUID}, GATT_PERMIT_WRITE, 0, simpleProfileChar3},
// Characteristic 3 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar3UserDesp
},
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "IS"},
// Characteristic 4 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar4Props
},
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar4Props},
// Characteristic Value 4
{
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
0,
0,
simpleProfileChar4
},
{{ATT_BT_UUID_SIZE, simpleProfilechar4UUID}, 0, 0, simpleProfileChar4},
// Characteristic 4 configuration
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&simpleProfileChar4Config
},
{{ATT_BT_UUID_SIZE, clientCharCfgUUID}, GATT_PERMIT_READ | GATT_PERMIT_WRITE, 0, (uint8 *)&simpleProfileChar4Config},
// Characteristic 4 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar4UserDesp
},
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "Nt"},
// Characteristic 5 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar5Props
},
{{ATT_BT_UUID_SIZE, characterUUID}, GATT_PERMIT_READ, 0, &simpleProfileChar5Props},
// Characteristic Value 5
{
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
GATT_PERMIT_AUTHEN_READ,
0,
simpleProfileChar5
},
{{ATT_BT_UUID_SIZE, simpleProfilechar5UUID}, GATT_PERMIT_READ | GATT_PERMIT_WRITE, 0, simpleProfileChar5},
// GATT_PERMIT_AUTHEN_READ,
// Characteristic 5 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar5UserDesp
},
{{ATT_BT_UUID_SIZE, charUserDescUUID}, GATT_PERMIT_READ, 0, "Dg"},
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t *pLen,
uint16_t offset, uint16_t maxLen,
uint8_t method);
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t len,
uint16_t offset, uint8_t method);
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, //
gattAttribute_t *pAttr,
uint8_t * pValue,
uint16_t * pLen,
uint16_t offset,
uint16_t maxLen,
uint8_t method);
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, //
gattAttribute_t *pAttr,
uint8_t * pValue,
uint16_t len,
uint16_t offset,
uint8_t method);
/*********************************************************************
* PROFILE CALLBACKS
@@ -367,11 +222,10 @@ static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
// pfnAuthorizeAttrCB to check a client's authorization prior to calling
// pfnReadAttrCB or pfnWriteAttrCB, so no checks for authorization need to be
// made within these functions.
CONST gattServiceCBs_t simpleProfileCBs =
{
simpleProfile_ReadAttrCB, // Read callback function pointer
simpleProfile_WriteAttrCB, // Write callback function pointer
NULL // Authorization callback function pointer
CONST gattServiceCBs_t simpleProfileCBs = {
simpleProfile_ReadAttrCB, // Read callback function pointer
simpleProfile_WriteAttrCB, // Write callback function pointer
NULL // Authorization callback function pointer
};
/*********************************************************************
@@ -389,35 +243,29 @@ CONST gattServiceCBs_t simpleProfileCBs =
*
* @return Success or Failure
*/
bStatus_t SimpleProfile_AddService( uint32 services )
{
uint8 status;
bStatus_t SimpleProfile_AddService(uint32 services) {
uint8 status;
// Allocate Client Characteristic Configuration table
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkDBNumConns );
if ( simpleProfileChar4Config == NULL )
{
return ( bleMemAllocError );
}
// Allocate Client Characteristic Configuration table
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) * linkDBNumConns);
if (simpleProfileChar4Config == NULL) {
return (bleMemAllocError);
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar4Config );
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg(INVALID_CONNHANDLE, simpleProfileChar4Config);
if ( services & SIMPLEPROFILE_SERVICE )
{
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService( simpleProfileAttrTbl,
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
GATT_MAX_ENCRYPT_KEY_SIZE,
&simpleProfileCBs );
}
else
{
status = SUCCESS;
}
if (services & SIMPLEPROFILE_SERVICE) {
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService(simpleProfileAttrTbl, //
GATT_NUM_ATTRS(simpleProfileAttrTbl),
GATT_MAX_ENCRYPT_KEY_SIZE,
&simpleProfileCBs);
} else {
status = SUCCESS;
}
return ( status );
return (status);
}
/*********************************************************************
@@ -430,18 +278,14 @@ bStatus_t SimpleProfile_AddService( uint32 services )
*
* @return SUCCESS or bleAlreadyInRequestedMode
*/
bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks )
{
if ( appCallbacks )
{
simpleProfile_AppCBs = appCallbacks;
bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks) {
if (appCallbacks) {
simpleProfile_AppCBs = appCallbacks;
return ( SUCCESS );
}
else
{
return ( bleAlreadyInRequestedMode );
}
return (SUCCESS);
} else {
return (bleAlreadyInRequestedMode);
}
}
/*********************************************************************
@@ -458,76 +302,60 @@ bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks )
*
* @return bStatus_t
*/
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
{
bStatus_t ret = SUCCESS;
switch ( param )
{
case SIMPLEPROFILE_CHAR1:
if ( len <= SIMPLEPROFILE_CHAR1_LEN )
{
memcpy(simpleProfileChar1, value, len);
// simpleProfileChar1 = *((uint8*)value);
}
else
{
ret = bleInvalidRange;
}
break;
bStatus_t SimpleProfile_SetParameter(uint8 param, uint8 len, void *value) {
switch (param) {
case SIMPLEPROFILE_CHAR1:
if (len <= SIMPLEPROFILE_CHAR1_LEN) {
memcpy(simpleProfileChar1, value, len);
return SUCCESS;
} else {
return bleInvalidRange;
}
case SIMPLEPROFILE_CHAR2:
if (len <= SIMPLEPROFILE_CHAR2_LEN)
{
memcpy(simpleProfileChar2, value, len);
// simpleProfileChar2 = *((uint8*)value);
}
else
{
ret = bleInvalidRange;
}
break;
case SIMPLEPROFILE_CHAR2:
if (len <= SIMPLEPROFILE_CHAR2_LEN) {
memcpy(simpleProfileChar2, value, len);
return SUCCESS;
} else {
return bleInvalidRange;
}
case SIMPLEPROFILE_CHAR3:
if (len <= SIMPLEPROFILE_CHAR3_LEN)
{
memcpy(simpleProfileChar3, value, len);
}
else
{
ret = bleInvalidRange;
}
break;
case SIMPLEPROFILE_CHAR3:
if (len <= SIMPLEPROFILE_CHAR3_LEN) {
memcpy(simpleProfileChar3, value, len);
return SUCCESS;
} else {
return bleInvalidRange;
}
case SIMPLEPROFILE_CHAR4:
if (len <= SIMPLEPROFILE_CHAR4_LEN)
{
memcpy(simpleProfileChar4, value, len);
case SIMPLEPROFILE_CHAR4:
if (len <= SIMPLEPROFILE_CHAR4_LEN) {
memcpy(simpleProfileChar4, value, len);
// See if Notification has been enabled
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, simpleProfileChar4, FALSE, simpleProfileAttrTbl, GATT_NUM_ATTRS(simpleProfileAttrTbl), INVALID_TASK_ID, simpleProfile_ReadAttrCB);
}
else
{
ret = bleInvalidRange;
}
break;
// See if Notification has been enabled
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, //
simpleProfileChar4,
FALSE,
simpleProfileAttrTbl,
GATT_NUM_ATTRS(simpleProfileAttrTbl),
INVALID_TASK_ID,
simpleProfile_ReadAttrCB);
return SUCCESS;
} else {
return bleInvalidRange;
}
case SIMPLEPROFILE_CHAR5:
if (len == SIMPLEPROFILE_CHAR5_LEN) {
VOID memcpy(simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN);
}
else
{
ret = bleInvalidRange;
}
break;
case SIMPLEPROFILE_CHAR5:
if (len <= SIMPLEPROFILE_CHAR5_LEN) {
memcpy(simpleProfileChar5, value, len);
return SUCCESS;
} else {
return bleInvalidRange;
}
default:
ret = INVALIDPARAMETER;
break;
}
return ( ret );
default:
return INVALIDPARAMETER;
}
}
/*********************************************************************
@@ -544,36 +372,32 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
* @return bStatus_t
*/
bStatus_t SimpleProfile_GetParameter(uint8 param, void *value) {
bStatus_t ret = SUCCESS;
switch (param) {
case SIMPLEPROFILE_CHAR1:
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
// *((uint8*)value) = simpleProfileChar1;
break;
case SIMPLEPROFILE_CHAR1:
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
break;
case SIMPLEPROFILE_CHAR2:
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
// *((uint8*)value) = simpleProfileChar2;
break;
case SIMPLEPROFILE_CHAR2:
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
break;
case SIMPLEPROFILE_CHAR3:
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
break;
case SIMPLEPROFILE_CHAR3:
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
break;
case SIMPLEPROFILE_CHAR4:
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
break;
case SIMPLEPROFILE_CHAR4:
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
break;
case SIMPLEPROFILE_CHAR5:
VOID memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
break;
case SIMPLEPROFILE_CHAR5:
memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
break;
default:
ret = INVALIDPARAMETER;
break;
default:
return INVALIDPARAMETER;
}
return (ret);
return SUCCESS;
}
/*********************************************************************
@@ -591,7 +415,13 @@ bStatus_t SimpleProfile_GetParameter(uint8 param, void *value) {
*
* @return SUCCESS, blePending or Failure
*/
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t *pLen, uint16_t offset, uint16_t maxLen, uint8_t method) {
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, //
gattAttribute_t *pAttr,
uint8_t * pValue,
uint16_t * pLen,
uint16_t offset,
uint16_t maxLen,
uint8_t method) {
bStatus_t status = SUCCESS;
// Make sure it's not a blob operation (no attributes in the profile are long)
@@ -603,42 +433,31 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *
// 16-bit UUID
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch (uuid) {
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
// gattserverapp handles those reads
case SIMPLEPROFILE_CHAR1_UUID:
*pLen = SIMPLEPROFILE_CHAR1_LEN;
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN);
break;
// characteristics 1 and 2 have read permissions
// characteritisc 3 does not have read permissions; therefore it is not
// included here
// characteristic 4 does not have read permissions, but because it
// can be sent as a notification, it is included here
case SIMPLEPROFILE_CHAR1_UUID:
*pLen = SIMPLEPROFILE_CHAR1_LEN;
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN);
break;
case SIMPLEPROFILE_CHAR2_UUID:
*pLen = SIMPLEPROFILE_CHAR2_LEN;
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN);
break;
case SIMPLEPROFILE_CHAR2_UUID:
// *pLen = 1;
// pValue[0] = *pAttr->pValue;
case SIMPLEPROFILE_CHAR4_UUID:
*pLen = SIMPLEPROFILE_CHAR4_LEN;
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN);
break;
*pLen = SIMPLEPROFILE_CHAR2_LEN;
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN);
break;
case SIMPLEPROFILE_CHAR5_UUID:
*pLen = SIMPLEPROFILE_CHAR5_LEN;
memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN);
break;
case SIMPLEPROFILE_CHAR4_UUID:
*pLen = SIMPLEPROFILE_CHAR4_LEN;
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN);
break;
// case SIMPLEPROFILE_CHAR5_UUID:
// *pLen = SIMPLEPROFILE_CHAR5_LEN;
// VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
// break;
default:
// Should never get here! (characteristics 3 and 4 do not have read permissions)
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
break;
default:
// Should never get here! (characteristics 3 and 4 do not have read permissions)
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
} else {
// 128-bit UUID
@@ -663,71 +482,73 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *
*
* @return SUCCESS, blePending or Failure
*/
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method) {
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, //
gattAttribute_t *pAttr,
uint8_t * pValue,
uint16_t len,
uint16_t offset,
uint8_t method) {
bStatus_t status = SUCCESS;
uint8 notifyApp = 0xFF;
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
// 16-bit UUID
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch (uuid) {
// Validate the value
// Make sure it's not a blob oper
/*
if ( offset == 0 )
{
if ( len != 1 )
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
case SIMPLEPROFILE_CHAR3_UUID:
//Write the value
if ( status == SUCCESS )
{
uint8 *pCurValue = (uint8 *)pAttr->pValue;
*pCurValue = pValue[0];
if( pAttr->pValue == &simpleProfileChar1 )
{
notifyApp = SIMPLEPROFILE_CHAR1;
}
}
break;
*/
case SIMPLEPROFILE_CHAR3_UUID:
if (offset == 0) {
if (len > SIMPLEPROFILE_CHAR3_LEN) {
status = ATT_ERR_INVALID_VALUE_SIZE;
// Validate the value
// Make sure it's not a blob oper
if (offset == 0) {
if (len >= SIMPLEPROFILE_CHAR3_LEN) {
status = ATT_ERR_INVALID_VALUE_SIZE;
}
} else {
status = ATT_ERR_ATTR_NOT_LONG;
}
} else {
status = ATT_ERR_ATTR_NOT_LONG;
}
// Write the value
if (status == SUCCESS) {
// Copy pValue into the variable we point to from the attribute table.
memcpy(pAttr->pValue + offset, pValue, len);
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR3_LEN - len);
// Write the value
if (status == SUCCESS) {
// Copy pValue into the variable we point to from the attribute table.
memcpy(pAttr->pValue + offset, pValue, len);
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR3_LEN - len);
if (pAttr->pValue == simpleProfileChar3) {
notifyApp = SIMPLEPROFILE_CHAR3;
if (pAttr->pValue == simpleProfileChar3) {
notifyApp = SIMPLEPROFILE_CHAR3;
}
}
}
break;
case GATT_CLIENT_CHAR_CFG_UUID:
status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY);
break;
default:
// Should never get here! (characteristics 2 and 4 do not have write permissions)
status = ATT_ERR_ATTR_NOT_FOUND;
break;
break;
case SIMPLEPROFILE_CHAR5_UUID:
if (offset == 0) {
if (len >= SIMPLEPROFILE_CHAR5_LEN) {
status = ATT_ERR_INVALID_VALUE_SIZE;
}
} else {
status = ATT_ERR_ATTR_NOT_LONG;
}
// Write the value
if (status == SUCCESS) {
// Copy pValue into the variable we point to from the attribute table.
memcpy(pAttr->pValue + offset, pValue, len);
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR5_LEN - len);
if (pAttr->pValue == simpleProfileChar5) {
notifyApp = SIMPLEPROFILE_CHAR5;
}
}
break;
case GATT_CLIENT_CHAR_CFG_UUID:
status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY);
break;
default:
// Should never get here! (characteristics 2 and 4 do not have write permissions)
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
} else {
// 128-bit UUID
@@ -9,7 +9,7 @@
Target Device: CC2650, CC2640
******************************************************************************
Copyright (c) 2010-2018, Texas Instruments Incorporated
All rights reserved.
@@ -49,8 +49,7 @@
#define SIMPLEGATTPROFILE_H
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
/*********************************************************************
@@ -62,36 +61,37 @@ extern "C"
*/
// Profile Parameters
#define SIMPLEPROFILE_CHAR1 0 // RW uint8 - Profile Characteristic 1 value
#define SIMPLEPROFILE_CHAR2 1 // RW uint8 - Profile Characteristic 2 value
#define SIMPLEPROFILE_CHAR3 2 // RW uint8 - Profile Characteristic 3 value
#define SIMPLEPROFILE_CHAR4 3 // RW uint8 - Profile Characteristic 4 value
#define SIMPLEPROFILE_CHAR5 4 // RW uint8 - Profile Characteristic 4 value
#define SIMPLEPROFILE_CHAR1 0 // RW uint8 - Profile Characteristic 1 value
#define SIMPLEPROFILE_CHAR2 1 // RW uint8 - Profile Characteristic 2 value
#define SIMPLEPROFILE_CHAR3 2 // RW uint8 - Profile Characteristic 3 value
#define SIMPLEPROFILE_CHAR4 3 // RW uint8 - Profile Characteristic 4 value
#define SIMPLEPROFILE_CHAR5 4 // RW uint8 - Profile Characteristic 4 value
// Simple Profile Service UUID
#define SIMPLEPROFILE_SERV_UUID 0xFFF0
#define SIMPLEPROFILE_SERV_UUID 0xFFF0
// Key Pressed UUID
#define SIMPLEPROFILE_CHAR1_UUID 0xFFF1
#define SIMPLEPROFILE_CHAR2_UUID 0xFFF2
#define SIMPLEPROFILE_CHAR3_UUID 0xFFF3
#define SIMPLEPROFILE_CHAR4_UUID 0xFFF4
#define SIMPLEPROFILE_CHAR5_UUID 0xFFF5
#define SIMPLEPROFILE_CHAR1_UUID 0xFFF1
#define SIMPLEPROFILE_CHAR2_UUID 0xFFF2
#define SIMPLEPROFILE_CHAR3_UUID 0xFFF3
#define SIMPLEPROFILE_CHAR4_UUID 0xFFF4
#define SIMPLEPROFILE_CHAR5_UUID 0xFFF5
// Simple Keys Profile Services bit fields
#define SIMPLEPROFILE_SERVICE 0x00000001
#define SIMPLEPROFILE_SERVICE 0x00000001
// Length of Characteristic 5 in bytes
#define SIMPLEPROFILE_CHAR5_LEN 5
/*user insert*/
#define SIMPLEPROFILE_CHAR4_LEN 40
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20
#define SIMPLEPROFILE_CHAR1_LEN 2
#define SIMPLEPROFILE_CHAR2_LEN 10
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR4_LEN 200
//#define SIMPLEPROFILE_CHAR4_LEN 20
#define SIMPLEPROFILE_CHAR5_LEN 20
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* MACROS
*/
@@ -101,20 +101,16 @@ extern "C"
*/
// Callback when a characteristic value has changed
typedef void (*simpleProfileChange_t)( uint8 paramID );
typedef void (*simpleProfileChange_t)(uint8 paramID);
typedef struct
{
simpleProfileChange_t pfnSimpleProfileChange; // Called when characteristic value changes
typedef struct {
simpleProfileChange_t pfnSimpleProfileChange; // Called when characteristic value changes
} simpleProfileCBs_t;
/*********************************************************************
* API FUNCTIONS
*/
/*
* SimpleProfile_AddService- Initializes the Simple GATT Profile service by registering
* GATT attributes with the GATT server.
@@ -123,7 +119,7 @@ typedef struct
* contain more than one service.
*/
extern bStatus_t SimpleProfile_AddService( uint32 services );
extern bStatus_t SimpleProfile_AddService(uint32 services);
/*
* SimpleProfile_RegisterAppCBs - Registers the application callback function.
@@ -131,7 +127,7 @@ extern bStatus_t SimpleProfile_AddService( uint32 services );
*
* appCallbacks - pointer to application callbacks.
*/
extern bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks );
extern bStatus_t SimpleProfile_RegisterAppCBs(simpleProfileCBs_t *appCallbacks);
/*
* SimpleProfile_SetParameter - Set a Simple GATT Profile parameter.
@@ -143,7 +139,7 @@ extern bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks
* data type (example: data type of uint16 will be cast to
* uint16 pointer).
*/
extern bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value );
extern bStatus_t SimpleProfile_SetParameter(uint8 param, uint8 len, void *value);
/*
* SimpleProfile_GetParameter - Get a Simple GATT Profile parameter.
@@ -154,8 +150,7 @@ extern bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value
* data type (example: data type of uint16 will be cast to
* uint16 pointer).
*/
extern bStatus_t SimpleProfile_GetParameter( uint8 param, void *value );
extern bStatus_t SimpleProfile_GetParameter(uint8 param, void *value);
/*********************************************************************
*********************************************************************/