Compare commits

...

69 Commits

Author SHA1 Message Date
alan c261d0e6b7 I2C test 2019-07-03 10:26:29 +08:00
alan 462303f805 I2C test 2019-07-03 10:16:09 +08:00
alan 660794b440 I2C test 2019-07-03 10:10:58 +08:00
alan 9f09b99497 I2C test 2019-07-03 10:09:31 +08:00
alan 958ba6023b I2C test 2019-07-02 15:51:49 +08:00
alan f892c6ff74 I2C test 2019-07-02 15:45:36 +08:00
alan 204ce16619 I2C test 2019-07-02 15:38:10 +08:00
alan eb66f2f0d8 I2C test 2019-07-02 15:36:18 +08:00
alan 9e7a181dd9 I2C test 2019-07-02 15:28:18 +08:00
alan 26afcee651 I2C test 2019-07-02 15:21:47 +08:00
alan 4534401280 I2C test 2019-07-02 15:18:59 +08:00
alan 98b3b38e32 I2C test 2019-07-02 15:02:25 +08:00
alan 6762d0badd I2C test 2019-07-02 14:58:54 +08:00
alan d8113d3d06 I2C test 2019-07-02 12:45:01 +08:00
alan 0b9af54525 I2C test 2019-07-02 11:45:16 +08:00
alan e8b7167d4e I2C test 2019-07-02 11:23:38 +08:00
alan 1320417dc7 I2C test 2019-07-02 11:15:09 +08:00
alan ad4991bf25 I2C test 2019-07-02 11:10:12 +08:00
alan 754d8349e3 read neulive2.0 2019-06-06 11:09:56 +08:00
alan de243ead44 flush neulive20 SPI 2019-06-06 10:51:27 +08:00
alan a7717888a7 SPI close 2019-05-23 14:38:39 +08:00
alan 86b465ff49 SPI close 2019-05-23 14:31:38 +08:00
alan 0bbf69074b SPI close 2019-05-23 14:27:46 +08:00
alan a4dfcf151b SPI close 2019-05-23 14:22:40 +08:00
alan a3e69bf4fc SPI close 2019-05-23 13:36:45 +08:00
alan 0b2ae152d1 SPI close 2019-05-23 12:06:45 +08:00
alan c8826c8695 SPI close 2019-05-23 12:05:33 +08:00
alan ff39cb1387 SPI close 2019-05-23 12:01:32 +08:00
alan 5c0c748f77 SPI close 2019-05-23 11:58:07 +08:00
alan 8fdfa4fb00 SPI close 2019-05-23 11:49:57 +08:00
alan 1a76b46674 SPI close 2019-05-23 11:41:19 +08:00
alan 7d4c2dca57 SPI close 2019-05-23 11:35:32 +08:00
alan 09f740d00e SPI close 2019-05-23 11:24:42 +08:00
alan 6464f5c882 SPI close 2019-05-23 11:20:35 +08:00
alan 7707d61d6b SPI close 2019-05-23 11:18:23 +08:00
alan 97622e2120 master 2019-05-23 09:30:39 +08:00
alan 58cab41cb7 master 2019-05-23 09:30:29 +08:00
alan f7c15a89e1 master 2019-05-23 09:17:35 +08:00
alan 075b34feab master 2019-05-23 09:11:11 +08:00
alan ee757bd45d master 2019-05-23 09:03:59 +08:00
alan 61b58489df master 2019-05-23 08:54:06 +08:00
alan 2581fdde13 master 2019-05-22 18:34:28 +08:00
alan 332e848488 master 2019-05-22 18:25:02 +08:00
alan b1796a72fa master 2019-05-22 18:20:40 +08:00
alan 58d2a25473 master 2019-05-22 18:14:51 +08:00
alan f18270d0f8 master 2019-05-22 17:54:03 +08:00
alan 7cf1a1273a master LED test 2019-05-22 17:32:27 +08:00
alan f39f831f15 master 2019-05-22 17:14:35 +08:00
alan e673fe653c master 2019-05-22 17:05:26 +08:00
alan 8112becef9 master 2019-05-22 17:04:08 +08:00
alan b500b6aac2 product number 2019-05-22 16:39:01 +08:00
alan 6207fafd9f CIS = 70 2019-05-22 16:30:26 +08:00
YiChin 576f394d54 ok 2019-05-10 10:51:25 +08:00
YiChin c02bc1bfbf Merge branch 'neulive2.0/master' of https://bitbucket.org/YiChin2018/bioprocc2650 into neulive2.0/master 2019-05-10 10:15:42 +08:00
YiChin 06d56724c4 bug fix 2019-05-10 10:15:16 +08:00
alan 8b36dd8769 SPI flush 2019-05-10 10:14:15 +08:00
alan 66dc3fbcb7 Merge remote-tracking branch 'origin/neulive2.0/master' into neulive2.0/master 2019-05-10 10:03:29 +08:00
YiChin dc6de2a68f master 2019-05-10 10:02:50 +08:00
alan 7cebd52bee spi master 2019-05-10 09:54:01 +08:00
alan 213238c895 add SPI flush after transmit 2019-05-07 12:26:01 +08:00
YiChin c5671223b7 rebuild 2019-05-07 11:47:35 +08:00
alan 859165be25 Merge remote-tracking branch 'origin/neulive2.0/master' into neulive2.0/master 2019-05-07 11:19:54 +08:00
YiChin b894d686b4 MASTER SPI 2019-05-07 11:18:55 +08:00
alan b2426f0910 SPI u16 * 3 2019-05-07 11:08:10 +08:00
Ta-Shun Su 287c2c6afa Merge branch 'master' into neulive2.0/master 2019-05-06 13:46:52 +08:00
Ta-Shun Su 79c614d078 Merge branch 'master' into neulive2.0/master 2019-05-06 11:35:57 +08:00
Ta-Shun Su 0c63b3af62 pull 2019-05-06 11:09:44 +08:00
Ta-Shun Su 8b4f3b7b50 copy from Neulive2_alan 2019-04-30 18:07:57 +08:00
Ta-Shun Su b5035963f5 copy from Neulive_test_version_alan 2019-04-30 18:07:49 +08:00
160 changed files with 57689 additions and 2960 deletions
@@ -1,9 +1,10 @@
/*
** Stack Frontier Generator 1.1.0 (2016-03-28 14:11:07.308000)
** Stack Frontier Generator 1.1.0 (2019-05-07 11:29:05.233000)
**
** WARNING - Auto-generated file. Modifications could be lost!
*/
--define=ICALL_STACK0_ADDR=0xe001
--define=ICALL_STACK0_START=0xe000
--define=ICALL_RAM0_START=0x20004368
--define=ICALL_STACK0_ADDR=0xf001
--define=ICALL_STACK0_START=0xf000
--define=ICALL_RAM0_START=0x20004320
@@ -1,9 +1,10 @@
/*
** Stack Frontier Generator 1.1.0 (2016-03-28 14:11:07.308000)
** Stack Frontier Generator 1.1.0 (2019-05-07 11:29:05.233000)
**
** WARNING - Auto-generated file. Modifications could be lost!
*/
--define=ICALL_RAM0_START=0x20004368
--define=ICALL_STACK0_START=0xe000
--define=ICALL_STACK0_ADDR=0xe001
--define=ICALL_RAM0_START=0x20004320
--define=ICALL_STACK0_START=0xf000
--define=ICALL_STACK0_ADDR=0xf001
@@ -4,5 +4,5 @@
*/
"C:\ti\simplelink\ble_sdk_2_02_02_25\blelib\host\host_pxxx.a"
"C:\ti\simplelink\ble_sdk_2_02_02_25\blelib\ctrl\cc2640\cc2640_ctrl_pxxx_ext.a"
"C:\ti\simplelink\ble_sdk_2_02_02_25\blelib\hci_tl\cc26xx\cc26xx_hci_tl_none_v41_v42.a"
"C:\ti\simplelink\ble_sdk_2_02_02_25\blelib\ctrl\cc2640\cc2640_ctrl_pxxx.a"
"C:\ti\simplelink\ble_sdk_2_02_02_25\blelib\hci_tl\cc26xx\cc26xx_hci_tl_none.a"
@@ -16,7 +16,7 @@
# sources were generated) is:
# C:\ti\simplelink\ble_sdk_2_02_02_25\examples\cc2650lp\simple_peripheral\ccs\config\src
#
GEN_SRC_DIR ?= ../../config/src
GEN_SRC_DIR ?= ../../../../../ti/simplelink/ble_sdk_2_02_02_25/examples/cc2650lp/simple_peripheral/ccs/config/src
ifeq (,$(wildcard $(GEN_SRC_DIR)))
$(error "ERROR: GEN_SRC_DIR must be set to the directory containing the generated sources")
@@ -16,11 +16,11 @@ BIOS_INC = -I"C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/pa
TARGET_INC = -I"C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/"
INCS = $(BIOS_INC) $(TARGET_INC) --include_path="C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/include" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/icall/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/dev_info" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/heapmgr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/controller/cc26xx/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/target" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/osal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/sdata" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/saddr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/icall/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/rom" --include_path="C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/cc26xxware_2_24_03_17272" -IC:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/
INCS = $(BIOS_INC) $(TARGET_INC) --include_path="C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/include" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/npi" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/icall/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/dev_info" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/heapmgr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/controller/cc26xx/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/target" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/osal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/sdata" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/saddr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/icall/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/rom" --include_path="C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/cc26xxware_2_24_03_17272" -IC:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/
CC = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/include
ASM = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/include
AR = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/bin/armar rq
CC = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/include
ASM = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/include
AR = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/bin/armar rq
DEL = C:/ti/xdctools_3_32_00_06_core/packages/../bin/rm -f
CP = C:/ti/xdctools_3_32_00_06_core/packages/../bin/cp -f
@@ -74,13 +74,18 @@
#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
ADC_EOC | PIN_INPUT_EN | PIN_PULLDOWN,
LSK_CS | PIN_INPUT_EN | PIN_PULLDOWN, // SPI0_LSK
ASK_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, // SPI1_ASK
ADC_CLK | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // ADC_CLK
PWR_CHECK | PIN_INPUT_EN | PIN_PULLDOWN,
LSK_CLK | PIN_INPUT_EN | PIN_PULLDOWN, // after lsk and lsk_manchester xor lsk_clk
LSK | PIN_INPUT_EN | PIN_PULLDOWN, // SPI0 to receive LSK
CLOCK_8M | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
ASK | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // SPI1 to transmit ASK
RESET | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
TRIGGER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
@@ -205,7 +210,7 @@ const UDMACC26XX_Config UDMACC26XX_config[] = {
SPICC26XXDMA_Object spiCC26XXDMAObjects[BOOSTXL_CC2650MA_SPICOUNT];
/* SPI configuration structure, describing which pins are to be used */
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_UDMACOUNT] = {
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_SPICOUNT] = {
{
.baseAddr = SSI0_BASE,
.intNum = INT_SSI0_COMB,
@@ -220,6 +225,20 @@ const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[BOOSTXL_CC2650MA_UDMACOUNT] = {
.clkPin = Board_SPI0_CLK,
.csnPin = Board_SPI0_CS
},
{
.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
},
};
/* SPI configuration structure */
@@ -81,6 +81,22 @@ extern const PIN_Config BoardGpioInitTable[];
#define DIO13 IOID_13
#define DIO14 IOID_14
/*
* Mapping of DIOs to Neulive pcb boards ( recording to schematic )
*/
#define ADC_EOC IOID_2
#define LSK_CS IOID_3 // SPI1_LSK
#define ASK_CS IOID_4 // SPI0_ASK
#define ADC_CLK IOID_6 // ADC_CLK
#define PWR_CHECK IOID_8
#define LSK_CLK IOID_9 // after lsk and lsk_manchester xor lsk_clk
#define LSK IOID_10 // SPI1 to receive LSK
#define CLOCK_8M IOID_11
#define ASK IOID_12 // SPI0 to transmit ASK
#define RESET IOID_13
#define TRIGGER IOID_14
/* Mapping of pins to board signals using general board aliases
* <board signal alias> <pin mapping>
*/
@@ -146,10 +162,15 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_UART_RX Board_BP_UART_Tx /* TXD */
/* 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
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI ASK
#define Board_SPI0_CLK PIN_UNASSIGNED
#define Board_SPI0_CS ASK_CS
#define Board_SPI1_MISO PIN_UNASSIGNED
#define Board_SPI1_MOSI LSK
#define Board_SPI1_CLK LSK_CLK
#define Board_SPI1_CS LSK_CS
/* Power Management Board */
#define Board_SRDY Board_BP_Pin_J2_19
@@ -158,8 +179,8 @@ extern const PIN_Config BoardGpioInitTable[];
/* PWM outputs */
#define Board_PWMPIN0 PIN_UNASSIGNED
#define Board_PWMPIN1 PIN_UNASSIGNED
#define Board_PWMPIN2 PIN_UNASSIGNED
#define Board_PWMPIN3 PIN_UNASSIGNED
#define Board_PWMPIN2 CLOCK_8M
#define Board_PWMPIN3 ADC_CLK
#define Board_PWMPIN4 PIN_UNASSIGNED
#define Board_PWMPIN5 PIN_UNASSIGNED
#define Board_PWMPIN6 PIN_UNASSIGNED
@@ -170,6 +191,7 @@ extern const PIN_Config BoardGpioInitTable[];
* ==========================================================================*/
/* Generic SPI instance identifiers */
#define Board_SPI0 BOOSTXL_CC2650MA_SPI0
#define Board_SPI1 BOOSTXL_CC2650MA_SPI1
/* Generic UART instance identifiers */
#define Board_UART BOOSTXL_CC2650MA_UART0
/* Generic TRNG instance identiifer */
@@ -214,6 +236,7 @@ typedef enum BOOSTXL_CC2650MA_CryptoName {
*/
typedef enum BOOSTXL_CC2650MA_SPIName {
BOOSTXL_CC2650MA_SPI0 = 0,
BOOSTXL_CC2650MA_SPI1 ,
BOOSTXL_CC2650MA_SPICOUNT
} BOOSTXL_CC2650MA_SPIName;
@@ -243,7 +266,6 @@ typedef enum BOOSTXL_CC2650MA_UARTName {
*/
typedef enum BOOSTXL_CC2650MA_UdmaName {
BOOSTXL_CC2650MA_UDMA0 = 0,
BOOSTXL_CC2650MA_UDMACOUNT
} BOOSTXL_CC2650MA_UdmaName;
@@ -223,6 +223,20 @@ const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC2650DK_5XD_SPICOUNT] = {
.misoPin = Board_SPI0_MISO,
.clkPin = Board_SPI0_CLK,
.csnPin = Board_SPI0_CSN
},
{
.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_CSN
}
};
@@ -233,7 +247,10 @@ const SPI_Config SPI_config[] = {
.object = &spiCC26XXDMAObjects[0],
.hwAttrs = &spiCC26XXDMAHWAttrs[0]
},
{NULL, NULL, NULL}
{ .fxnTablePtr = &SPICC26XXDMA_fxnTable,
.object = &spiCC26XXDMAObjects[1],
.hwAttrs = &spiCC26XXDMAHWAttrs[1]
}
};
/*
* ========================== SPI DMA end =====================================
@@ -100,13 +100,17 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_SPI0_MOSI IOID_11 /* P1.18 */
#define Board_SPI0_CLK IOID_10 /* P1.16 */
#define Board_SPI0_CSN PIN_UNASSIGNED
#define Board_SPI1_MISO IOID_6
#define Board_SPI1_MOSI IOID_5
#define Board_SPI1_CLK IOID_4
#define Board_SPI1_CSN PIN_UNASSIGNED
/* Power Board */
#define Board_3V3_EN IOID_14 /* P1.15 */
/* PWM outputs */
#define Board_PWMPIN0 Board_DK_LED3
#define Board_PWMPIN1 Board_DK_LED4
#define Board_PWMPIN2 PIN_UNASSIGNED
#define Board_PWMPIN3 PIN_UNASSIGNED
#define Board_PWMPIN0 PIN_UNASSIGNED
#define Board_PWMPIN1 PIN_UNASSIGNED
#define Board_PWMPIN2 Board_DK_LED3
#define Board_PWMPIN3 Board_DK_LED4
#define Board_PWMPIN4 PIN_UNASSIGNED
#define Board_PWMPIN5 PIN_UNASSIGNED
#define Board_PWMPIN6 PIN_UNASSIGNED
@@ -117,6 +121,7 @@ extern const PIN_Config BoardGpioInitTable[];
* ==========================================================================*/
/* Generic SPI instance identifiers */
#define Board_SPI0 CC2650DK_5XD_SPI0
#define Board_SPI1 CC2650DK_5XD_SPI1
/* Generic UART instance identifiers */
#define Board_UART CC2650DK_5XD_UART0
/* Generic Crypto instance identifiers */
@@ -161,6 +166,7 @@ typedef enum CC2650DK_5XD_CryptoName {
*/
typedef enum CC2650DK_5XD_SPIName {
CC2650DK_5XD_SPI0 = 0,
CC2650DK_5XD_SPI1,
CC2650DK_5XD_SPICOUNT
} CC2650DK_5XD_SPIName;
@@ -81,10 +81,22 @@ const PIN_Config BoardGpioInitTable[] = {
Board_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */
Board_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */
Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */
Board_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */
Board_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */
Board_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */
// Board_SPI0_MOSI | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
// Board_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,
// Board_SPI0_CLK | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
// Board_SPI0_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
// Board_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */
// Board_SPI0_MISO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* SPI master in - slave out */
// Board_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */
// Board_SPI0_CSN | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
//
// Board_PWMPIN2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
/* Board_SPI1_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, SPI master out - slave in */
/* Board_SPI1_MISO | PIN_INPUT_EN | PIN_PULLDOWN, SPI master in - slave out */
/* Board_SPI1_CLK | PIN_INPUT_EN | PIN_PULLDOWN, SPI clock */
/* UMC_reset | PIN_INPUT_EN | PIN_PULLUP, */
PIN_TERMINATE
};
@@ -224,6 +236,7 @@ const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC2650_LAUNCHXL_SPICOUNT] = {
.misoPin = Board_SPI0_MISO,
.clkPin = Board_SPI0_CLK,
.csnPin = Board_SPI0_CSN
// .csnPin = Board_SPI0_CS
},
{
.baseAddr = SSI1_BASE,
@@ -74,7 +74,7 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_LED_OFF 0
/* Discrete inputs */
#define Board_BTN1 IOID_13
#define Board_BTN1 PIN_UNASSIGNED
#define Board_BTN2 IOID_14
/* UART Board */
@@ -87,12 +87,15 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_SPI0_MISO IOID_8 /* RF1.20 */
#define Board_SPI0_MOSI IOID_9 /* RF1.18 */
#define Board_SPI0_CLK IOID_10 /* RF1.16 */
#define Board_SPI0_CSN PIN_UNASSIGNED
#define Board_SPI0_CSN IOID_23 // IOID_23
//#define Board_SPI0_CS IOID_23
#define Board_SPI1_MISO PIN_UNASSIGNED
#define Board_SPI1_MOSI PIN_UNASSIGNED
#define Board_SPI1_CLK PIN_UNASSIGNED
#define Board_SPI1_CSN PIN_UNASSIGNED
/* I2C */
#define Board_I2C0_SCL0 IOID_4
#define Board_I2C0_SDA0 IOID_5
@@ -130,15 +133,19 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_LCD_CS_OFF 0
/* PWM outputs */
#define Board_PWMPIN0 Board_RLED
#define Board_PWMPIN1 Board_GLED
#define Board_PWMPIN2 PIN_UNASSIGNED
#define Board_PWMPIN3 PIN_UNASSIGNED
#define Board_PWMPIN0 PIN_UNASSIGNED
#define Board_PWMPIN1 PIN_UNASSIGNED
#define Board_PWMPIN2 IOID_15
#define Board_PWMPIN3 Board_GLED
#define Board_PWMPIN4 PIN_UNASSIGNED
#define Board_PWMPIN5 PIN_UNASSIGNED
#define Board_PWMPIN6 PIN_UNASSIGNED
#define Board_PWMPIN7 PIN_UNASSIGNED
#define TRIGGER IOID_21
#define RESET IOID_22
//#define SPI0_CS IOID_23
/** ============================================================================
* Instance identifiers
* ==========================================================================*/
View File
@@ -0,0 +1,157 @@
/******************************************************************************
@file cc26xx_app.cmd
@brief CC2650F128 linker configuration file for TI-RTOS with Code Composer
Studio.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
Copyright (c) 2013-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.
******************************************************************************
Release Name: ble_sdk_2_02_01_18
Release Date: 2016-10-26 15:20:04
*****************************************************************************/
/* Retain interrupt vector table variable */
--retain=g_pfnVectors
/* Override default entry point. */
--entry_point ResetISR
/* Suppress warnings and errors: */
/* - 10063: Warning about entry point not being _c_int00 */
/* - 16011, 16012: 8-byte alignment errors. Observed when linking in object */
/* files compiled using Keil (ARM compiler) */
--diag_suppress=10063,16011,16012
/* The following command line options are set as part of the CCS project. */
/* If you are building using the command line, or for some reason want to */
/* define them here, you can uncomment and modify these lines as needed. */
/* If you are using CCS for building, it is probably better to make any such */
/* modifications in your CCS project and leave this file alone. */
/* */
/* --heap_size=0 */
/* --stack_size=256 */
/* --library=rtsv7M3_T_le_eabi.lib */
/* The starting address of the application. Normally the interrupt vectors */
/* must be located at the beginning of the application. Flash is 128KB, with */
/* sector length of 4KB */
#define FLASH_APP_BASE 0x00000000
#define FLASH_LEN 0x20000
#define FLASH_PAGE_LEN 0x1000
/* Last page of Flash is allocated to App: 0x1F000 - 0x1FFFF */
#define FLASH_LAST_PAGE_START FLASH_LEN - FLASH_PAGE_LEN
/* RAM starts at 0x20000000 and is 20KB */
#define RAM_APP_BASE 0x20000000
#define RAM_LEN 0x5000
/* RAM reserved by ROM code starts. */
#define RAM_RESERVED_OFFSET 0x4F00
/* RAM starts at 0x20000000 and is 2KB */
#define AUX_RAM_BASE 0x400E0000
#define AUX_RAM_LEN 0x800
/* System memory map */
MEMORY
{
/* EDITOR'S NOTE:
* the FLASH and SRAM lengths can be changed by defining
* ICALL_STACK0_START or ICALL_RAM0_START in
* Properties->ARM Linker->Advanced Options->Command File Preprocessing.
*/
/* Application stored in and executes from internal flash */
/* Flash Size 128 KB */
#ifdef ICALL_STACK0_START
FLASH (RX) : origin = FLASH_APP_BASE, length = ICALL_STACK0_START - FLASH_APP_BASE
#else // default
FLASH (RX) : origin = FLASH_APP_BASE, length = FLASH_LEN - FLASH_PAGE_LEN
#endif
// CCFG Page, contains .ccfg code section and some application code.
FLASH_LAST_PAGE (RX) : origin = FLASH_LAST_PAGE_START, length = FLASH_PAGE_LEN
/* Application uses internal RAM for data */
/* RAM Size 16 KB */
#ifdef ICALL_RAM0_START
SRAM (RWX) : origin = RAM_APP_BASE, length = ICALL_RAM0_START - RAM_APP_BASE
#else //default
SRAM (RWX) : origin = RAM_APP_BASE, length = RAM_RESERVED_OFFSET
#endif
AUXRAM (RWX) : origin = AUX_RAM_BASE, length = AUX_RAM_LEN
}
/* Section allocation in memory */
SECTIONS
{
.intvecs : > FLASH_APP_BASE
.text : >> FLASH | FLASH_LAST_PAGE
.const : >> FLASH | FLASH_LAST_PAGE
.constdata : >> FLASH | FLASH_LAST_PAGE
.rodata : >> FLASH | FLASH_LAST_PAGE
.cinit : > FLASH | FLASH_LAST_PAGE
.pinit : >> FLASH | FLASH_LAST_PAGE
.init_array : >> FLASH | FLASH_LAST_PAGE
.emb_text : >> FLASH | FLASH_LAST_PAGE
.ccfg : > FLASH_LAST_PAGE (HIGH)
GROUP > SRAM
{
.data
.bss
.vtable
.vtable_ram
vtable_ram
.sysmem
.nonretenvar
} LOAD_END(heapStart)
.stack : > SRAM (HIGH) LOAD_START(heapEnd)
.aux_ram : > AUXRAM
}
/* Create global constant that points to top of stack */
/* CCS: Change stack size under Project Properties */
__STACK_TOP = __stack + __STACK_SIZE;
/* Allow main() to take args */
--args 0x8
@@ -0,0 +1,148 @@
/*
* Filename: cc26xx_app_gpram.cmd
*
* Description: CCS linker file to define GPRAM region
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/* Retain interrupt vector table variable */
--retain=g_pfnVectors
/* Override default entry point. */
--entry_point ResetISR
/* Suppress warnings and errors: */
/* - 10063: Warning about entry point not being _c_int00 */
/* - 16011, 16012: 8-byte alignment errors. Observed when linking in object */
/* files compiled using Keil (ARM compiler) */
--diag_suppress=10063,16011,16012
/* The following command line options are set as part of the CCS project. */
/* If you are building using the command line, or for some reason want to */
/* define them here, you can uncomment and modify these lines as needed. */
/* If you are using CCS for building, it is probably better to make any such */
/* modifications in your CCS project and leave this file alone. */
/* */
/* --heap_size=0 */
/* --stack_size=256 */
/* --library=rtsv7M3_T_le_eabi.lib */
/* The starting address of the application. Normally the interrupt vectors */
/* must be located at the beginning of the application. Flash is 128KB, with */
/* sector length of 4KB */
#define FLASH_APP_BASE 0x00000000
#define FLASH_LEN 0x20000
#define FLASH_PAGE_LEN 0x1000
/* Last page of Flash is allocated to App: 0x1F000 - 0x1FFFF */
#define FLASH_LAST_PAGE_START FLASH_LEN - FLASH_PAGE_LEN
/* RAM starts at 0x20000000 and is 20KB */
#define RAM_APP_BASE 0x20000000
#define RAM_LEN 0x5000
/* RAM reserved by ROM code starts. */
#define RAM_RESERVED_OFFSET 0x4F00
/* GPRAM starts at 0x11000000 and is 8KB */
#define GPRAM_BASE 0x11000000
#define GPRAM_SIZE 0x2000
/* System memory map */
MEMORY
{
/* EDITOR'S NOTE:
* the FLASH and SRAM lengths can be changed by defining
* ICALL_STACK0_START or ICALL_RAM0_START in
* Properties->ARM Linker->Advanced Options->Command File Preprocessing.
*/
/* Application stored in and executes from internal flash */
/* Flash Size 128 KB */
#ifdef ICALL_STACK0_START
FLASH (RX) : origin = FLASH_APP_BASE, length = ICALL_STACK0_START - FLASH_APP_BASE
#else // default
FLASH (RX) : origin = FLASH_APP_BASE, length = FLASH_LEN - FLASH_PAGE_LEN
#endif
// CCFG Page, contains .ccfg code section and some application code.
FLASH_LAST_PAGE (RX) : origin = FLASH_LAST_PAGE_START, length = FLASH_PAGE_LEN
/* Application uses internal RAM for data */
/* RAM Size 16 KB */
#ifdef ICALL_RAM0_START
SRAM (RWX) : origin = RAM_APP_BASE, length = ICALL_RAM0_START - RAM_APP_BASE
#else //default
SRAM (RWX) : origin = RAM_APP_BASE, length = RAM_RESERVED_OFFSET
#endif
GPRAM (RWX) : origin = GPRAM_BASE, length = GPRAM_SIZE
}
/* Section allocation in memory */
SECTIONS
{
.intvecs : > FLASH_APP_BASE
.text : >> FLASH | FLASH_LAST_PAGE
.const : >> FLASH | FLASH_LAST_PAGE
.constdata : >> FLASH | FLASH_LAST_PAGE
.rodata : >> FLASH | FLASH_LAST_PAGE
.cinit : > FLASH | FLASH_LAST_PAGE
.pinit : >> FLASH | FLASH_LAST_PAGE
.init_array : >> FLASH | FLASH_LAST_PAGE
.emb_text : >> FLASH | FLASH_LAST_PAGE
.ccfg : > FLASH_LAST_PAGE (HIGH)
.bss : > GPRAM
GROUP > SRAM
{
.data
.vtable
.vtable_ram
vtable_ram
.sysmem
.nonretenvar
} LOAD_END(heapStart)
.stack : > SRAM (HIGH) LOAD_START(heapEnd)
}
/* Create global constant that points to top of stack */
/* CCS: Change stack size under Project Properties */
__STACK_TOP = __stack + __STACK_SIZE;
/* Allow main() to take args */
--args 0x8
View File
View File
View File
@@ -0,0 +1,170 @@
/*
* Filename: cc26xx_app_gpram.icf
*
* Description: IAR linker file to define GPRAM region
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
////////////////////////////////////////////////////////////////////////////////
// Memory Sizes
////////////////////////////////////////////////////////////////////////////////
define symbol RAM_SIZE = 0x00005000; // 20K
define symbol FLASH_SIZE = 0x00020000; // 128K
define symbol ROM_SIZE = 0x0001C000; // 115K
////////////////////////////////////////////////////////////////////////////////
// Memory Definitions
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// RAM
//
define symbol RAM_START = 0x20000000;
define symbol RAM_RESERVED_START = 0x20004F00;
if ( isdefinedsymbol(ICALL_RAM0_START) )
{
define symbol RAM_END = (ICALL_RAM0_START-1);
}
else // default
{
define symbol RAM_END = RAM_RESERVED_START - 1;
}
////////////////////////////////////////////////////////////////////////////////
// Flash
//
define symbol FLASH_START = 0x00000000;
if ( isdefinedsymbol(ICALL_STACK0_START) )
{
define symbol FLASH_END = (ICALL_STACK0_START-1);
}
else // default
{
// Default includes all but last page, which is defined later.
define symbol FLASH_END = FLASH_START + FLASH_SIZE - 0x1001;
}
////////////////////////////////////////////////////////////////////////////////
// Stack
//
define symbol STACK_SIZE = 0x400;
define symbol STACK_START = RAM_END + 1;
define symbol STACK_END = STACK_START - STACK_SIZE;
//
define symbol STACK_TOP = RAM_END + 1;
export symbol STACK_TOP;
////////////////////////////////////////////////////////////////////////////////
// RAM
//
define symbol GPRAM_START = 0x11000000;
define symbol GPRAM_SIZE = 8096;
define symbol GPRAM_END = GPRAM_START + GPRAM_SIZE;
////////////////////////////////////////////////////////////////////////////////
// Flash Interrupt Vector Table
//
define symbol INTVEC_NUM_ENTRIES = 50 + 1; // first entry is stack location
define symbol INTVEC_SIZE = INTVEC_NUM_ENTRIES + 4;
////////////////////////////////////////////////////////////////////////////////
// Memory Regions
////////////////////////////////////////////////////////////////////////////////
define memory mem with size = 4G;
define region RAM = mem:[from RAM_START to RAM_END];
define region FLASH_LAST_PAGE = mem:[from(FLASH_SIZE) - 0x1000 to FLASH_SIZE-1];
define region FLASH = mem:[from FLASH_START to FLASH_END] |
FLASH_LAST_PAGE;
define region GPRAM = mem:[from GPRAM_START to GPRAM_END];
////////////////////////////////////////////////////////////////////////////////
// Memory Placement
////////////////////////////////////////////////////////////////////////////////
// Code and RO Data
place in FLASH { readonly };
// CCFG
place at end of FLASH_LAST_PAGE { readonly section .ccfg };
keep { section .ccfg };
// Interrupt Vector Table
place at address mem:FLASH_START { readonly section .intvec };
keep { readonly section .intvec };
// RAM Vector Table
place at start of RAM { section .vtable_ram };
// Runtime Stack
define block CSTACK with alignment = 8, size = STACK_SIZE { section .stack };
place at end of RAM { block CSTACK };
// RW Data
define block RWDATA { rw };
place in RAM { block RWDATA };
// GPRAM
define block GPDATA { section .bss };
place in GPRAM { block GPDATA };
////////////////////////////////////////////////////////////////////////////////
// Initialization
////////////////////////////////////////////////////////////////////////////////
initialize by copy { readwrite };
do not initialize
{
section .noinit,
section .stack,
};
////////////////////////////////////////////////////////////////////////////////
// The USE_TIRTOS_ROM symbol is defined internally in the build flow (using
// --config_def USE_TIRTOS_ROM=1) for TI-RTOS applications whose appBLE.cfg file
// specifies to use the ROM.
//
if (isdefinedsymbol(USE_TIRTOS_ROM)) {
include "TIRTOS_ROM.icf";
}
View File
View File
View File
@@ -0,0 +1,480 @@
/*
* Copyright (c) 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.
*/
/* -----------------------------------------------------------------------------
* Includes
* ------------------------------------------------------------------------------
*/
// TI RTOS drivers
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/SPI.h>
#include <xdc/runtime/Log.h>
#include <xdc/runtime/System.h>
#include <ti/mw/grlib/grlib.h>
#include <ti/mw/display/Display.h>
#include <ti/mw/display/DisplaySharp.h>
#include <ti/mw/lcd/SharpGrLib.h>
/* -----------------------------------------------------------------------------
* Constants and macros
* ------------------------------------------------------------------------------
*/
// Timeout of semaphore that controls exclusive to the LCD (infinite)
#define ACCESS_TIMEOUT BIOS_WAIT_FOREVER
/* -----------------------------------------------------------------------------
* Type definitions
* ------------------------------------------------------------------------------
*/
/* -----------------------------------------------------------------------------
* Local variables
* ------------------------------------------------------------------------------
*/
/* Display function table for sharp implementation */
const Display_FxnTable DisplaySharp_fxnTable = {
DisplaySharp_open,
DisplaySharp_clear,
DisplaySharp_clearLines,
DisplaySharp_put5,
DisplaySharp_close,
DisplaySharp_control,
DisplaySharp_getType,
};
/* -----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------------
*/
/*!
* @fn DisplaySharp_open
*
* @brief Initialize the LCD
*
* @descr Initializes the pins used by the LCD, creates resource access
* protection semaphore, turns on the LCD device, initializes the
* frame buffer, initializes to white background/dark foreground,
* and finally clears the object->displayColor.
*
* @param hDisplay - pointer to Display_Config struct
* @param params - display parameters
*
* @return Pointer to Display_Config struct
*/
Display_Handle DisplaySharp_open(Display_Handle hDisplay,
Display_Params *params)
{
DisplaySharp_HWAttrs *hwAttrs = (DisplaySharp_HWAttrs *)hDisplay->hwAttrs;
DisplaySharp_Object *object = (DisplaySharp_Object *)hDisplay->object;
PIN_Config pinTable[4 + 1];
object->lineClearMode = params->lineClearMode;
uint32_t i = 0;
if (hwAttrs->csPin != PIN_TERMINATE)
{
pinTable[i++] = hwAttrs->csPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX;
}
if (hwAttrs->extcominPin != PIN_TERMINATE)
{
pinTable[i++] = hwAttrs->extcominPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX;
}
if (hwAttrs->powerPin != PIN_TERMINATE)
{
pinTable[i++] = hwAttrs->powerPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX;
}
if (hwAttrs->enablePin != PIN_TERMINATE)
{
pinTable[i++] = hwAttrs->enablePin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX;
}
pinTable[i++] = PIN_TERMINATE;
object->hPins = PIN_open(&object->pinState, pinTable);
if (object->hPins == NULL)
{
Log_error0("Couldn't open pins for Sharp96x96");
return NULL;
}
SPI_Params spiParams;
SPI_Params_init(&spiParams);
spiParams.bitRate = 4000000;
object->hSpi = SPI_open(hwAttrs->spiIndex, &spiParams);
if (object->hSpi == NULL)
{
Log_error0("Couldn't open SPI driver for Sharp96x96");
PIN_close(object->hPins);
object->hPins = NULL;
return NULL;
}
// Init colors
object->displayColor.bg = ClrBlack;
object->displayColor.fg = ClrWhite;
// Exclusive access
Semaphore_Params semParams;
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&object->semLCD, 1, &semParams);
// Grab LCD
Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT);
// Initialize the GrLib back-end transport
SharpGrLib_init(object->hSpi, object->hPins, hwAttrs->csPin);
object->g_sDisplay.lSize = sizeof(tDisplay);
object->g_sDisplay.pFxns = &g_sharpFxns;
object->g_sDisplay.pvDisplayData = object->displayBuffer;
object->g_sDisplay.usHeight = hwAttrs->pixelHeight;
object->g_sDisplay.usWidth = hwAttrs->pixelWidth;
object->g_sDisplay.pvDisplayData = hwAttrs->displayBuf;
// Graphics library init
GrContextInit(&object->g_sContext, &object->g_sDisplay, &g_sharpFxns);
// Graphics properties
GrContextForegroundSet(&object->g_sContext, object->displayColor.fg);
GrContextBackgroundSet(&object->g_sContext, object->displayColor.bg);
GrContextFontSet(&object->g_sContext, &g_sFontFixed6x8);
// Clear display
GrClearDisplay(&object->g_sContext);
GrFlush(&object->g_sContext);
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
return hDisplay;
}
/*!
* @fn DisplaySharp_clear
*
* @brief Clears the display
*
* @param hDisplay - pointer to Display_Config struct
*
* @return void
*/
void DisplaySharp_clear(Display_Handle hDisplay)
{
DisplaySharp_Object *object = (DisplaySharp_Object *)hDisplay->object;
if (object->hPins == NULL)
{
return;
}
// Grab LCD
if (Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT))
{
GrClearDisplay(&object->g_sContext);
GrFlush(&object->g_sContext);
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
}
}
/*!
* @fn DisplaySharp_clearLines
*
* @brief Clears lines lineFrom-lineTo of the display, inclusive
*
* @param hDisplay - pointer to Display_Config struct
* @param lineFrom - line index (0 .. )
* @param lineTo - line index (0 .. )
*
* @return void
*/
void DisplaySharp_clearLines(Display_Handle hDisplay,
uint8_t lineFrom, uint8_t lineTo)
{
DisplaySharp_Object *object = (DisplaySharp_Object *)hDisplay->object;
if (lineTo <= lineFrom)
{
lineTo = lineFrom;
}
tRectangle rect = {
.sXMin = 0,
.sXMax = object->g_sContext.sClipRegion.sXMax,
.sYMin = lineFrom * object->g_sContext.pFont->ucHeight,
.sYMax = (lineTo + 1) * object->g_sContext.pFont->ucHeight - 1,
};
GrContextForegroundSet(&object->g_sContext, object->displayColor.bg);
GrRectFill(&object->g_sContext, &rect);
GrContextForegroundSet(&object->g_sContext, object->displayColor.fg);
GrFlush(&object->g_sContext);
}
/*!
* @fn DisplaySharp_put5
*
* @brief Write a text string to a specific line/column of the display
*
* @param hDisplay - pointer to Display_Config struct
* @param line - line index (0..)
* @param column - column index (0..)
* @param fmt - format string
* @param aN - optional format arguments
*
* @return void
*/
void DisplaySharp_put5(Display_Handle hDisplay, uint8_t line,
uint8_t column, uintptr_t fmt, uintptr_t a0,
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4)
{
DisplaySharp_Object *object = (DisplaySharp_Object *)hDisplay->object;
uint8_t xp, yp, clearStartX, clearEndX;
char dispStr[23];
if (object->hPins == NULL)
{
return;
}
// Grab LCD
if (Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT))
{
xp = column * object->g_sContext.pFont->ucMaxWidth + 1;
yp = line * object->g_sContext.pFont->ucHeight + 0;
clearStartX = clearEndX = xp;
switch (object->lineClearMode)
{
case DISPLAY_CLEAR_LEFT:
clearStartX = 0;
break;
case DISPLAY_CLEAR_RIGHT:
clearEndX = object->g_sContext.sClipRegion.sXMax;
break;
case DISPLAY_CLEAR_BOTH:
clearStartX = 0;
clearEndX = object->g_sContext.sClipRegion.sXMax;
break;
case DISPLAY_CLEAR_NONE:
default:
break;
}
if (clearStartX != clearEndX)
{
tRectangle rect = {
.sXMin = clearStartX,
.sXMax = clearEndX,
.sYMin = yp,
.sYMax = yp + object->g_sContext.pFont->ucHeight - 1,
};
GrContextForegroundSet(&object->g_sContext, object->displayColor.bg);
GrRectFill(&object->g_sContext, &rect);
GrContextForegroundSet(&object->g_sContext, object->displayColor.fg);
}
System_snprintf(dispStr, sizeof(dispStr), (xdc_CString)fmt, a0, a1, a2, a3, a4);
// Draw a text on the display
GrStringDraw(&object->g_sContext,
dispStr,
AUTO_STRING_LENGTH,
xp,
yp,
OPAQUE_TEXT);
GrFlush(&object->g_sContext);
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
}
}
/*!
* @fn DisplaySharp_close
*
* @brief Turns of the display and releases the LCD control pins
*
* @param hDisplay - pointer to Display_Config struct
*
* @return void
*/
void DisplaySharp_close(Display_Handle hDisplay)
{
DisplaySharp_HWAttrs *hwAttrs = (DisplaySharp_HWAttrs *)hDisplay->hwAttrs;
DisplaySharp_Object *object = (DisplaySharp_Object *)hDisplay->object;
if (object->hPins == NULL)
{
return;
}
// Grab LCD
if (Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT))
{
// Turn off the display
PIN_setOutputValue(object->hPins, hwAttrs->enablePin, 0);
// Release resources
PIN_close(object->hPins);
object->hPins = NULL;
SPI_close(object->hSpi);
object->hSpi = NULL;
// Deconfigure GrLib back-end
SharpGrLib_init(NULL, NULL, PIN_UNASSIGNED);
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
}
}
/*!
* @fn DisplaySharp_control
*
* @brief Function for setting control parameters of the Display driver
* after it has been opened.
*
* @param hDisplay - pointer to Display_Config struct
* @param cmd - command to execute, supported commands are:
* | Command | Description |
* |------------------------------- |-------------------------|
* | ::DISPLAY_CMD_TRANSPORT_CLOSE | Close SPI but leave control pins |
* | ::DISPLAY_CMD_TRANSPORT_OPEN | Re-open SPI driver |
* @param arg - argument to the command
*
* @return ::DISPLAY_STATUS_SUCCESS if success, or error code if error.
*/
int DisplaySharp_control(Display_Handle hDisplay, unsigned int cmd, void *arg)
{
DisplaySharp_HWAttrs *hwAttrs = (DisplaySharp_HWAttrs *)hDisplay->hwAttrs;
DisplaySharp_Object *object = (DisplaySharp_Object *)hDisplay->object;
/* Initialize return value */
int ret = DISPLAY_STATUS_ERROR;
/* Perform command */
switch(cmd)
{
case DISPLAY_CMD_TRANSPORT_CLOSE:
// Grab LCD
if (Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT))
{
if (object->hSpi)
{
// Close SPI and tell back-end there is no SPI
SPI_close(object->hSpi);
SharpGrLib_init(NULL, object->hPins, hwAttrs->csPin);
object->hSpi = NULL;
ret = DISPLAY_STATUS_SUCCESS;
}
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
}
break;
case DISPLAY_CMD_TRANSPORT_OPEN:
// Grab LCD
if (Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT))
{
if (NULL == object->hSpi)
{
// Re-open SPI and re-init back-end
SPI_Params spiParams;
SPI_Params_init(&spiParams);
spiParams.bitRate = 4000000;
object->hSpi = SPI_open(hwAttrs->spiIndex, &spiParams);
SharpGrLib_init(object->hSpi, object->hPins, hwAttrs->csPin);
ret = DISPLAY_STATUS_SUCCESS;
}
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
}
break;
case DISPLAYSHARP_CMD_SET_COLORS:
// Grab LCD
if (Semaphore_pend((Semaphore_Handle) & object->semLCD, ACCESS_TIMEOUT))
{
object->displayColor = *(DisplaySharpColor_t *)arg;
GrContextForegroundSet(&object->g_sContext, object->displayColor.fg);
GrContextBackgroundSet(&object->g_sContext, object->displayColor.bg);
// Release LCD
Semaphore_post((Semaphore_Handle) & object->semLCD);
// Return success
ret = DISPLAY_STATUS_SUCCESS;
}
break;
default:
/* The command is not defined */
ret = SPI_STATUS_UNDEFINEDCMD;
break;
}
return ret;
}
/*!
* @fn DisplaySharp_getType
*
* @brief Returns type of transport
*
* @return Display type define LCD
*/
unsigned int DisplaySharp_getType(void)
{
return Display_Type_LCD | Display_Type_GRLIB;
}
@@ -0,0 +1,331 @@
/*
* Copyright (c) 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.
*/
/* -----------------------------------------------------------------------------
* Includes
* -----------------------------------------------------------------------------
*/
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/drivers/UART.h>
#include <xdc/runtime/Log.h>
#include <xdc/runtime/Diags.h>
#include <xdc/runtime/System.h>
#include <ti/mw/display/Display.h>
#include <ti/mw/display/DisplayUart.h>
#include <string.h>
/* -----------------------------------------------------------------------------
* Constants and macros
* -----------------------------------------------------------------------------
*/
#ifndef MIN
# define MIN(n, m) (((n) > (m)) ? (m) : (n))
#endif
#define DISPLAY_UART_ESC_INITIAL "\x1b\x63" /* Reset terminal */ \
"\x1b[2J" /* Clear screen */ \
"\x1b[10r" /* Scrolling region from line 10 */ \
"\x1b[11;1H" /* Set initial cursor to line 11 */
#define DISPLAY_UART_ESC_MOVEPOS_FMT "\x1b\x37" /* Save cursor position */ \
"\x1b[10r" /* Retransmit scroll */ \
"\x1b[%d;%dH" /* Move cursor fmt str */
#define DISPLAY_UART_ESC_RESTOREPOS "\x1b\x38" /* Restore saved cursor pos */
#define DISPLAY_UART_ESC_CLEAR_SCREEN "\x1b[2J" /* Clear screen */
#define DISPLAY_UART_ESC_CLEAR_CUR_LEFT "\x1b[1K" /* Clear cursor left */
#define DISPLAY_UART_ESC_CLEAR_CUR_RIGHT "\x1b[0K" /* Clear cursor right */
#define DISPLAY_UART_ESC_CLEAR_BOTH "\x1b[2K" /* Clear line */
#define DISPLAY_UART_ESC_CLEARSEQ_LEN 4
/* -----------------------------------------------------------------------------
* Type definitions
* -----------------------------------------------------------------------------
*/
/* -----------------------------------------------------------------------------
* Local variables
* -----------------------------------------------------------------------------
*/
/* Display function table for UART implementation */
const Display_FxnTable DisplayUart_fxnTable = {
DisplayUart_open,
DisplayUart_clear,
DisplayUart_clearLines,
DisplayUart_put5,
DisplayUart_close,
DisplayUart_control,
DisplayUart_getType,
};
/* -----------------------------------------------------------------------------
* Functions
* -----------------------------------------------------------------------------
*/
/*!
* @fn DisplayUart_open
*
* @brief Initialize the UART transport
*
* @descr Opens the UART index specified in the HWAttrs, and creates a
* mutex semaphore
*
* @param hDisplay - pointer to Display_Config struct
* @param params - display parameters
*
* @return Pointer to Display_Config struct
*/
Display_Handle DisplayUart_open(Display_Handle hDisplay,
Display_Params *params)
{
DisplayUart_HWAttrs *hwAttrs = (DisplayUart_HWAttrs *)hDisplay->hwAttrs;
DisplayUart_Object *object = (DisplayUart_Object *)hDisplay->object;
UART_Params uartParams;
UART_Params_init(&uartParams);
uartParams.baudRate = hwAttrs->baudRate;
uartParams.writeMode = UART_MODE_BLOCKING;
Semaphore_Params semParams;
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&object->mutex, 1, &semParams);
switch (params->lineClearMode)
{
case DISPLAY_CLEAR_BOTH: object->lineClearSeq = DISPLAY_UART_ESC_CLEAR_BOTH; break;
case DISPLAY_CLEAR_LEFT: object->lineClearSeq = DISPLAY_UART_ESC_CLEAR_CUR_LEFT; break;
case DISPLAY_CLEAR_RIGHT: object->lineClearSeq = DISPLAY_UART_ESC_CLEAR_CUR_RIGHT; break;
default: /* fall-through */
case DISPLAY_CLEAR_NONE: object->lineClearSeq = NULL; break;
}
object->hUart = UART_open(hwAttrs->uartIdx, &uartParams);
if (NULL == object->hUart)
{
Log_print0(Diags_USER1, "DisplayUart.c: Couldn't open UART");
return NULL;
}
/* Send VT100 initial config to terminal */
UART_write(object->hUart, DISPLAY_UART_ESC_INITIAL, sizeof DISPLAY_UART_ESC_INITIAL - 1);
return hDisplay;
}
/*!
* @fn DisplayUart_clear
*
* @brief Does nothing, as output is stateless.
*
* @param hDisplay - pointer to Display_Config struct
*
* @return void
*/
void DisplayUart_clear(Display_Handle hDisplay)
{
DisplayUart_Object *object = (DisplayUart_Object *)hDisplay->object;
DisplayUart_HWAttrs *hwAttrs = (DisplayUart_HWAttrs *)hDisplay->hwAttrs;
if (Semaphore_pend((Semaphore_Handle) & object->mutex, hwAttrs->mutexTimeout))
{
UART_write(object->hUart, DISPLAY_UART_ESC_CLEAR_SCREEN, 4);
Semaphore_post((Semaphore_Handle) & object->mutex);
}
}
/*!
* @fn DisplayUart_clearLines
*
* @brief Does nothing, as output is stateless.
*
* @param hDisplay - pointer to Display_Config struct
* @param lineFrom - line index (0 .. )
* @param lineTo - line index (0 .. )
*
* @return void
*/
void DisplayUart_clearLines(Display_Handle hDisplay,
uint8_t lineFrom, uint8_t lineTo)
{
DisplayUart_Object *object = (DisplayUart_Object *)hDisplay->object;
DisplayUart_HWAttrs *hwAttrs = (DisplayUart_HWAttrs *)hDisplay->hwAttrs;
uint32_t strSize = 0;
uint32_t curLine = 0;
const uint8_t uartClearLineMoveDown[] = "\x1b[2K\x1b\x45";
if (lineTo <= lineFrom)
{
lineTo = lineFrom;
}
if (Semaphore_pend((Semaphore_Handle) & object->mutex, hwAttrs->mutexTimeout))
{
strSize += System_snprintf(hwAttrs->strBuf, hwAttrs->strBufLen,
DISPLAY_UART_ESC_MOVEPOS_FMT, lineFrom + 1, 0);
for (curLine = lineFrom + 1;
curLine < lineTo + 2 &&
hwAttrs->strBufLen - strSize > sizeof DISPLAY_UART_ESC_RESTOREPOS - 1;
curLine++)
{
memcpy(hwAttrs->strBuf + strSize, uartClearLineMoveDown, sizeof uartClearLineMoveDown - 1);
strSize += sizeof uartClearLineMoveDown - 1;
}
memcpy(hwAttrs->strBuf + strSize, DISPLAY_UART_ESC_RESTOREPOS, sizeof DISPLAY_UART_ESC_RESTOREPOS - 1);
strSize += sizeof DISPLAY_UART_ESC_RESTOREPOS - 1;
UART_write(object->hUart, hwAttrs->strBuf, strSize);
Semaphore_post((Semaphore_Handle) & object->mutex);
}
}
/*!
* @fn DisplayUart_put5
*
* @brief Write a text string to UART with return and newline.
*
* @param hDisplay - pointer to Display_Config struct
* @param line - line index (0..)
* @param column - column index (0..)
* @param fmt - format string
* @param aN - optional format arguments
*
* @return void
*/
void DisplayUart_put5(Display_Handle hDisplay, uint8_t line,
uint8_t column, uintptr_t fmt, uintptr_t a0,
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4)
{
DisplayUart_Object *object = (DisplayUart_Object *)hDisplay->object;
DisplayUart_HWAttrs *hwAttrs = (DisplayUart_HWAttrs *)hDisplay->hwAttrs;
uint32_t strSize = 0;
char *strBuf = hwAttrs->strBuf;
const uint16_t bufLen = hwAttrs->strBufLen;
if (Semaphore_pend((Semaphore_Handle) & object->mutex, hwAttrs->mutexTimeout))
{
if (line != DisplayUart_SCROLLING)
{
/* Add cursor movement escape sequence */
strSize += System_snprintf(strBuf + strSize, bufLen - strSize - 2,
DISPLAY_UART_ESC_MOVEPOS_FMT, line + 1, column + 1);
/* Add line clearing escape sequence */
if (object->lineClearSeq)
{
memcpy(strBuf + strSize, object->lineClearSeq, DISPLAY_UART_ESC_CLEARSEQ_LEN);
strSize += DISPLAY_UART_ESC_CLEARSEQ_LEN;
}
}
strSize += System_snprintf(strBuf + strSize, bufLen - strSize - 2, (xdc_CString)fmt, a0, a1, a2, a3, a4);
if (line != DisplayUart_SCROLLING)
{
memcpy(strBuf + strSize, DISPLAY_UART_ESC_RESTOREPOS, sizeof DISPLAY_UART_ESC_RESTOREPOS - 1);
strSize += 2;
}
else
{
strBuf[strSize++] = '\r';
strBuf[strSize++] = '\n';
}
UART_write(object->hUart, strBuf, strSize);
Semaphore_post((Semaphore_Handle) & object->mutex);
}
}
/*!
* @fn DisplayUart_close
*
* @brief Closes the UART handle
*
* @param hDisplay - pointer to Display_Config struct
*
* @return void
*/
void DisplayUart_close(Display_Handle hDisplay)
{
DisplayUart_Object *object = (DisplayUart_Object *)hDisplay->object;
// Not sure what happens if someone is writing
UART_close(object->hUart);
object->hUart = NULL;
// Not sure what happens if someone is pending
Semaphore_destruct(&object->mutex);
}
/*!
* @fn DisplayUart_control
*
* @brief Function for setting control parameters of the Display driver
* after it has been opened.
*
* @param hDisplay - pointer to Display_Config struct
* @param cmd - command to execute
* @param arg - argument to the command
*
* @return ::DISPLAY_STATUS_UNDEFINEDCMD because no commands are supported
*/
int DisplayUart_control(Display_Handle hDisplay, unsigned int cmd, void *arg)
{
return DISPLAY_STATUS_UNDEFINEDCMD;
}
/*!
* @fn DisplayUart_getType
*
* @brief Returns type of transport
*
* @return Display type UART
*/
unsigned int DisplayUart_getType(void)
{
return Display_Type_UART;
}
@@ -0,0 +1,80 @@
/*
* Copyright (c) 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.
*/
#ifndef _DISPLAY_UART_H_
#define _DISPLAY_UART_H_
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/drivers/UART.h>
#include <ti/mw/display/Display.h>
#include <stdint.h>
extern const Display_FxnTable DisplayUart_fxnTable;
/*
* @brief Line number for text to appear in scrolling region
*/
#define DisplayUart_SCROLLING 0xFF
typedef struct DisplayUart_HWAttrs
{
unsigned int uartIdx;
unsigned int baudRate;
unsigned int mutexTimeout;
char *strBuf;
uint16_t strBufLen;
} DisplayUart_HWAttrs;
typedef struct DisplayUart_Object
{
UART_Handle hUart;
Semaphore_Struct mutex;
uint8_t *lineClearSeq;
} DisplayUart_Object, *DisplayUart_Handle;
Display_Handle DisplayUart_open(Display_Handle,
Display_Params * params);
void DisplayUart_clear(Display_Handle handle);
void DisplayUart_clearLines(Display_Handle handle,
uint8_t fromLine,
uint8_t toLine);
void DisplayUart_put5(Display_Handle handle, uint8_t line,
uint8_t column, uintptr_t fmt, uintptr_t a0,
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4);
void DisplayUart_close(Display_Handle);
int DisplayUart_control(Display_Handle handle, unsigned int cmd, void *arg);
unsigned int DisplayUart_getType(void);
#endif // _DISPLAY_UART_H_
@@ -55,7 +55,7 @@ extern "C"
// includes
// ****************************************************************************
#include "hal_types.h"
#include "npi/src/inc/npi_config.h"
#include "inc/npi_config.h"
// ****************************************************************************
// defines
@@ -0,0 +1,122 @@
/******************************************************************************
@file npi_config.h
This file contains the Network Processor Interface (NPI),
which abstracts the physical link between the Application
Processor (AP) and the Network Processor (NP). The NPI
serves as the HAL's client for the SPI and UART drivers, and
provides API and callback services for its client.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
#ifndef SDI_CONFIG_H
#define SDI_CONFIG_H
#ifdef __cplusplus
extern "C"
{
#endif
// ****************************************************************************
// includes
// ****************************************************************************
#include "Board.h"
// ****************************************************************************
// defines
// ****************************************************************************
#if !defined(NPI_SPI_CONFIG)
#define NPI_SPI_CONFIG Board_SPI1
#endif
#ifdef POWER_SAVING
# if defined(NPI_USE_SPI)
# if (NPI_SPI_CONFIG == Board_SPI1)
# define MRDY_PIN Board_KEY_UP
# define SRDY_PIN Board_KEY_DOWN
# else
# error "ERROR: You must choose Board_SPI1 SPI module for NPI."
# endif
# elif defined(SDI_USE_UART)
# define MRDY_PIN Board_BUTTON0
# define SRDY_PIN Board_BUTTON1
# endif
# define SRDY_ENABLE() PIN_setOutputValue(hSdiHandshakePins, SRDY_PIN, 0) /* RTS low */
# define SRDY_DISABLE() PIN_setOutputValue(hSdiHandshakePins, SRDY_PIN, 1) /* RTS high */
#else // ! POWER_SAVING
# define SRDY_ENABLE()
# define SRDY_DISABLE()
#endif
#define SDI_TL_BUF_SIZE 270
#define SDI_SPI_PAYLOAD_SIZE 255
#define SDI_SPI_HDR_LEN 4
#ifdef NPI_USE_SPI
# if (NPI_TL_BUF_SIZE - NPI_SPI_HDR_LEN) < NPI_SPI_PAYLOAD_SIZE
# define NPI_MAX_FRAG_SIZE (NPI_TL_BUF_SIZE - NPI_SPI_HDR_LEN)
# else
# define NPI_MAX_FRAG_SIZE NPI_SPI_PAYLOAD_SIZE
# endif
#elif SDI_USE_UART
# define SDI_MAX_FRAG_SIZE SDI_TL_BUF_SIZE
#else
# error "ERROR: SDI_USE_UART or NPI_USE_SPI must be defined."
#endif
// ****************************************************************************
// typedefs
// ****************************************************************************
//*****************************************************************************
// globals
//*****************************************************************************
//*****************************************************************************
// function prototypes
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* NPI_CONFIG_H */
@@ -0,0 +1,109 @@
/******************************************************************************
@file npi_data.h
SDI Data structures
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
#ifndef SDIDATA_H
#define SDIDATA_H
#ifdef __cplusplus
extern "C"
{
#endif
// ****************************************************************************
// includes
// ****************************************************************************
#include <stdint.h>
// ****************************************************************************
// defines
// ****************************************************************************
// External Events for RTOS application
#define UART_DATA_EVT 0x0010
#define UART_ERROR_EVT 0x0020
// ****************************************************************************
// typedefs
// ****************************************************************************
//! \brief SDI Command IDs.
//!
typedef enum
{
SDIMSG_Type_ASYNC = 0x00,
SDIMSG_Type_SYNCREQ = 0x01,
SDIMSG_Type_SYNCRSP = 0x02
} SDIMSG_Type;
//! \brief Structure to send an SDI message to the stack thread.
//!
typedef struct _npimsg_t
{
// Msg Type
uint_least8_t msgType;
// message buffer size
uint8_t pBufSize;
// message buffer
uint8_t *pBuf;
} SDIMSG_msg_t;
//*****************************************************************************
// globals
//*****************************************************************************
//*****************************************************************************
// function prototypes
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* SDIDATA_H */
@@ -0,0 +1,111 @@
/******************************************************************************
@file npi_rxbuf.h
SDI RX Buffer and utilities
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
//******************************************************************************
#ifndef SDIRXBUF_H
#define SDIRXBUF_H
#ifdef __cplusplus
extern "C"
{
#endif
// ****************************************************************************
// includes
// ****************************************************************************
#include "hal_types.h"
#include "OSAL.h"
#include "sdi_config.h"
// ****************************************************************************
// defines
// ****************************************************************************
// ****************************************************************************
// typedefs
// ****************************************************************************
//*****************************************************************************
// globals
//*****************************************************************************
//*****************************************************************************
// function prototypes
//*****************************************************************************
// -----------------------------------------------------------------------------
//! \brief SDIRxBuf_Read
//!
//! \param[in] len -
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_Read(uint16);
// -----------------------------------------------------------------------------
//! \brief Returns number of bytes that are unparsed in RxBuf
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_GetRxBufCount();
// -----------------------------------------------------------------------------
//! \brief Returns number of bytes that are available in RxBuf
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_GetRxBufAvail();
// -----------------------------------------------------------------------------
//! \brief SDIRxBuf_ReadFromRxBuf
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_ReadFromRxBuf(uint8_t *buf, uint16 len);
#ifdef __cplusplus
}
#endif
#endif /* SDIRXBUF_H */
@@ -0,0 +1,131 @@
/******************************************************************************
@file sdi_task.h
SDI is a TI RTOS Application Thread that provides a
common Network Processor Interface framework
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
#ifndef _SDITask_H
#define _SDITask_H
#ifdef __cplusplus
extern "C"
{
#endif
// ****************************************************************************
// includes
// ****************************************************************************
#include "inc/sdi_data.h"
#include <ti/sysbios/knl/Semaphore.h>
// ****************************************************************************
// defines
// ****************************************************************************
#define DEBUG(x) SDITask_sendToUART(x, strlen((const char*)x));
#define DEBUG_NEWLINE() DEBUG("\n\r")
// ****************************************************************************
// typedefs
// ****************************************************************************
// -----------------------------------------------------------------------------
//! \brief Typedef for call back function mechanism to reroute incoming SDI
//! messages.
//! NOTE: Definer MUST copy contents to local buffer. SDI task will
//! free this memory.
//! NOTE: The contained message buffer does NOT include any "framing"
//! bytes, ie. SOF, FCS etc.
//! \param[in] pMsg Pointer to "unframed" message buffer.
//!
//! \return void
// -----------------------------------------------------------------------------
typedef void (*sdiIncomingEventCBack_t)(uint8_t event, uint8_t *pMsg, uint8_t len);
//*****************************************************************************
// globals
//*****************************************************************************
//*****************************************************************************
// function prototypes
//*****************************************************************************
// -----------------------------------------------------------------------------
//! \brief SDI task creation function
//!
//! \return void
// -----------------------------------------------------------------------------
Void SDITask_createTask(void);
// -----------------------------------------------------------------------------
//! \brief Register callback function to reroute incoming (from UART)
//! SDI messages.
//!
//! \param[in] appRxCB Callback fucntion.
//!
//! \return void
// -----------------------------------------------------------------------------
extern void SDITask_registerIncomingRXEventAppCB(sdiIncomingEventCBack_t appRxCB);
// -----------------------------------------------------------------------------
//! \brief API for application task to send a message to the Host.
//! NOTE: It's assumed all message traffic to the stack will use
//! other (ICALL) APIs/Interfaces.
//!
//! \param[in] pMsg Pointer to "unframed" message buffer.
//! \param[in] length Length of buffer
//!
//! \return void
// -----------------------------------------------------------------------------
extern void SDITask_sendToUART(uint8_t *pMsg, uint16_t length);
// -----------------------------------------------------------------------------
//! \brief API for application task to set packet data size to send over the air.
//!
//! \param[in] mtuSize GATT MTU size.
//!
//! \return void
// -----------------------------------------------------------------------------
extern void SDITask_setAppDataSize(uint16_t mtuSize);
#ifdef __cplusplus
{
#endif // extern "C"
#endif // end of _SDITask_H definition
@@ -0,0 +1,185 @@
/******************************************************************************
@file sdi_tl.h
SDI Transport Layer API
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
#ifndef SDI_TL_H
#define SDI_TL_H
#ifdef __cplusplus
extern "C"
{
#endif
// ****************************************************************************
// includes
// ****************************************************************************
#include "hal_types.h"
#include "inc/sdi_config.h"
// ****************************************************************************
// defines
// ****************************************************************************
#if defined(SDI_USE_UART)
#define transportInit SDITLUART_initializeTransport
#define transportRead SDITLUART_readTransport
#define transportWrite SDITLUART_writeTransport
#define transportStopTransfer SDITLUART_stopTransfer
#define transportMrdyEvent SDITLUART_handleMrdyEvent
#elif defined(NPI_USE_SPI)
#define transportInit NPITLSPI_initializeTransport
#define transportRead NPITLSPI_readTransport
#define transportWrite NPITLSPI_writeTransport
#define transportStopTransfer NPITLSPI_stopTransfer
#define transportMrdyEvent NPITLSPI_handleMrdyEvent
#endif
// ****************************************************************************
// typedefs
// ****************************************************************************
// -----------------------------------------------------------------------------
//! \brief Typedef for call back function mechanism to notify SDI Task that
//! an SDI transaction has occured
//! \param[in] int number of bytes either received or transmitted
//!
//! \return void
// -----------------------------------------------------------------------------
typedef void (*sdiRtosCB_t)(int size);
// -----------------------------------------------------------------------------
//! \brief Typedef for call back function mechanism to notify SDI Task that
//! an MRDY edge has occured
//! \param[in] void
//! \return void
// -----------------------------------------------------------------------------
typedef void (*sdiMrdyRtosCB_t)();
//*****************************************************************************
// globals
//*****************************************************************************
//*****************************************************************************
// function prototypes
//*****************************************************************************
// -----------------------------------------------------------------------------
//! \brief This routine initializes the transport layer and opens the port
//! of the device. Note that based on project defines, either the
//! UART, USB (CDC), or SPI driver can be used.
//!
//! \param[in] sdiCBTx - Call back function for TX complete event
//! \param[in] sdiCBRx - Call back function for RX event
//! \param[in] sdiCBMrdy - Call back function for MRDY event
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITL_initTL(sdiRtosCB_t sdiCBTx, sdiRtosCB_t sdiCBRx, sdiRtosCB_t sdiCBMrdy);
// -----------------------------------------------------------------------------
//! \brief This routine reads data from the transport layer based on len,
//! and places it into the buffer.
//!
//! \param[in] buf - Pointer to buffer to place read data.
//! \param[in] len - Number of bytes to read.
//!
//! \return uint16 - the number of bytes read from transport
// -----------------------------------------------------------------------------
uint16 SDITL_readTL(uint8 *buf, uint16 len);
// -----------------------------------------------------------------------------
//! \brief This routine writes data from the buffer to the transport layer.
//!
//! \param[in] buf - Pointer to buffer to write data from.
//! \param[in] len - Number of bytes to write.
//!
//! \return uint16 - the number of bytes written to transport
// -----------------------------------------------------------------------------
uint16 SDITL_writeTL(uint8 *buf, uint16 len);
// -----------------------------------------------------------------------------
//! \brief This routine is used to handle an MRDY edge from the application
//! context. Certain operations such as UART_read() cannot be
//! performed from the actual MRDY hwi handler
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITL_handleMrdyEvent(void);
// -----------------------------------------------------------------------------
//! \brief This routine returns the max size receive buffer.
//!
//! \return uint16 - max size of the receive buffer
// -----------------------------------------------------------------------------
uint16 SDITL_getMaxRxBufSize(void);
// -----------------------------------------------------------------------------
//! \brief This routine returns the max size transmit buffer.
//!
//! \return uint16 - max size of the transmit buffer
// -----------------------------------------------------------------------------
uint16 SDITL_getMaxTxBufSize(void);
// -----------------------------------------------------------------------------
//! \brief Returns number of bytes that are unread in RxBuf
//!
//! \return uint16 - number of unread bytes
// -----------------------------------------------------------------------------
uint16 SDITL_getRxBufLen(void);
// -----------------------------------------------------------------------------
//! \brief This routine returns the state of transmission on SDI
//!
//! \return bool - state of SDI transmission - 1 - active, 0 - not active
// -----------------------------------------------------------------------------
bool SDITL_checkSdiBusy(void);
/*******************************************************************************
*/
#ifdef __cplusplus
}
#endif
#endif /* SDI_TL_H */
@@ -0,0 +1,171 @@
/******************************************************************************
@file sdi_tl_uart.h
SDI Transport Layer Module for UART
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
#ifndef SDI_TL_UART_H
#define SDI_TL_UART_H
#ifdef __cplusplus
extern "C"
{
#endif
// ****************************************************************************
// includes
// ****************************************************************************
#include <ti/drivers/UART.h>
// ****************************************************************************
// defines
// ****************************************************************************
#define SDI_UART_FC_THRESHOLD 48
#define SDI_UART_IDLE_TIMEOUT 6
#define SDI_UART_INT_ENABLE TRUE
#if !defined(SDI_UART_BR)
#define SDI_UART_BR 115200
#endif // !SDI_UART_BR
// UART ISR Buffer define
#define UART_ISR_BUF_SIZE 128
#define UART_ISR_BUF_CNT 2
// ****************************************************************************
// typedefs
// ****************************************************************************
// -----------------------------------------------------------------------------
//! \brief Typedef for call back function mechanism to notify SDI TL that
//! an SDI transaction has occured
//! \param[in] uint16 number of bytes received
//! \param[in] uint16 number of bytes transmitted
//!
//! \return void
// -----------------------------------------------------------------------------
typedef void (*sdiCB_t)(uint16 Rxlen, uint16 Txlen);
// -----------------------------------------------------------------------------
//! \brief Typedef for call back function mechanism to reroute incoming SDI
//! messages.
//! NOTE: Definer MUST copy contents to local buffer. SDI task will
//! free this memory.
//! NOTE: The contained message buffer does NOT include any "framing"
//! bytes, ie. SOF, FCS etc.
//! \param[in] pMsg Pointer to "unframed" message buffer.
//!
//! \return void
// -----------------------------------------------------------------------------
typedef void (*sdiTLIncomingEventCBack_t)(uint8_t event, uint8_t *pMsg, uint8_t len);
//*****************************************************************************
// globals
//*****************************************************************************
extern UART_Params paramsUART;
//*****************************************************************************
// function prototypes
//*****************************************************************************
uint8 SDITLUART_configureUARTParams(UART_Params *initParams);
// -----------------------------------------------------------------------------
//! \brief This routine initializes the transport layer and opens the port
//! of the device.
//!
//! \param[in] tRxBuf - pointer to SDI TL Tx Buffer
//! \param[in] tTxBuf - pointer to SDI TL Rx Buffer
//! \param[in] sdiCBack - SDI TL call back function to be invoked at the end of
//! a UART transaction
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_initializeTransport(Char *tRxBuf, Char *tTxBuf, sdiCB_t sdiCBack);
void SDITLUART_closeUART(void);
// -----------------------------------------------------------------------------
//! \brief Register callback function to reroute incoming (from UART)
//! SDI messages.
//!
//! \param[in] appRxCB Callback fucntion.
//!
//! \return void
// -----------------------------------------------------------------------------
extern void SDITLUART_registerIncomingRXErrorStatusAppCB(sdiTLIncomingEventCBack_t appRxErrStatusCB);
// -----------------------------------------------------------------------------
//! \brief This routine reads data from the UART
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_readTransport(void);
// -----------------------------------------------------------------------------
//! \brief This routine writes copies buffer addr to the transport layer.
//!
//! \param[in] len - Number of bytes to write.
//!
//! \return uint16 - number of bytes written to transport
// -----------------------------------------------------------------------------
uint16 SDITLUART_writeTransport(uint16);
// -----------------------------------------------------------------------------
//! \brief This routine stops any pending reads
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_stopTransfer(void);
// -----------------------------------------------------------------------------
//! \brief This routine is called from the application context when MRDY is
//! de-asserted
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_handleMrdyEvent(void);
#ifdef __cplusplus
}
#endif
#endif /* SDI_TL_UART_H */
@@ -0,0 +1,148 @@
/******************************************************************************
@file sdi_rxbuf.c
SDI RX Buffer and utilities
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
// ****************************************************************************
// includes
// ****************************************************************************
#include <string.h>
#include <xdc/std.h>
#include "Board.h"
#include "hal_types.h"
#include "inc/sdi_config.h"
#include "inc/sdi_tl.h"
// ****************************************************************************
// defines
// ****************************************************************************
#define SDIRXBUF_RXHEAD_INC(x) RxBufHead += x; \
RxBufHead %= SDI_TL_BUF_SIZE;
#define SDIRXBUF_RXTAIL_INC(x) RxBufTail += x; \
RxBufTail %= SDI_TL_BUF_SIZE;
// ****************************************************************************
// typedefs
// ****************************************************************************
//*****************************************************************************
// globals
//*****************************************************************************
//Recieve Buffer for all SDI messages
static uint8 RxBuf[SDI_TL_BUF_SIZE];
static uint16 RxBufHead = 0;
static uint16 RxBufTail = 0;
//*****************************************************************************
// function prototypes
//*****************************************************************************
// -----------------------------------------------------------------------------
//! \brief SDIRxBuf_Read
//!
//! \param[in] len -
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_Read(uint16 len)
{
uint16 partialLen = 0;
// Need to make two reads due to wrap around of circular buffer
if ((len + RxBufTail) > SDI_TL_BUF_SIZE)
{
partialLen = SDI_TL_BUF_SIZE - RxBufTail;
SDITL_readTL(&RxBuf[RxBufTail],partialLen);
len -= partialLen;
RxBufTail = 0;
}
// Read remainder of data from Transport Layer
SDITL_readTL(&RxBuf[RxBufTail],len);
SDIRXBUF_RXTAIL_INC(len);
// Return len to original size
len += partialLen;
return len;
}
// -----------------------------------------------------------------------------
//! \brief Returns number of bytes that are unparsed in RxBuf
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_GetRxBufCount(void)
{
return ((RxBufTail - RxBufHead) + SDI_TL_BUF_SIZE) % SDI_TL_BUF_SIZE;
}
// -----------------------------------------------------------------------------
//! \brief Returns number of bytes that are available in RxBuf
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_GetRxBufAvail(void)
{
return (SDI_TL_BUF_SIZE - SDIRxBuf_GetRxBufCount());
}
// -----------------------------------------------------------------------------
//! \brief SDIRxBuf_ReadFromRxBuf
//!
//! \return uint16 -
// -----------------------------------------------------------------------------
uint16 SDIRxBuf_ReadFromRxBuf(uint8_t *buf, uint16 len)
{
uint16_t idx;
for (idx = 0; idx < len; idx++)
{
*buf++ = RxBuf[RxBufHead];
SDIRXBUF_RXHEAD_INC(1)
}
return len;
}
@@ -0,0 +1,525 @@
/******************************************************************************
* Filename: sdi_task.c
SDI is a TI RTOS Application Thread that provides a common serial data interface
framework
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
// ****************************************************************************
// includes
// ****************************************************************************
#include <xdc/std.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <string.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include "inc/sdi_task.h"
#include "inc/sdi_data.h"
#include "inc/sdi_rxbuf.h"
#include "inc/sdi_tl.h"
// ****************************************************************************
// defines
// ****************************************************************************
//! \brief Transport layer RX Event (ie. bytes received, RX ISR etc.)
#define SDITASK_TRANSPORT_RX_EVENT Event_Id_00
//! \brief Transmit Complete Event (likely associated with TX ISR etc.)
#define SDITASK_TRANSPORT_TX_DONE_EVENT Event_Id_01
//! \brief A framed message buffer is ready to be sent to the transport layer.
#define SDITASK_TX_READY_EVENT Event_Id_02
//! \brief MRDY Received Event
#define SDITASK_MRDY_EVENT Event_Id_03
//! \brief Size of stack created for SDI RTOS task
#ifndef Display_DISABLE_ALL
#ifdef __TI_COMPILER_VERSION__
#define SDITASK_STACK_SIZE 752 /* in order to optimize memory, this value should be a multiple of 8 bytes */
#else // !__TI_COMPILER_VERSION__
#define SDITASK_STACK_SIZE 656 /* in order to optimize memory, this value should be a multiple of 8 bytes */
#endif // __TI_COMPILER_VERSION__
#else // Display_DISABLE_ALL
#ifdef __TI_COMPILER_VERSION__
#define SDITASK_STACK_SIZE 752 /* in order to optimize memory, this value should be a multiple of 8 bytes */
#else // !__TI_COMPILER_VERSION__
#define SDITASK_STACK_SIZE 608 /* in order to optimize memory, this value should be a multiple of 8 bytes */
#endif // __TI_COMPILER_VERSION__
#endif // Display_DISABLE_ALL
//! \brief Task priority for SDI RTOS task
#define SDITASK_PRIORITY 2
//! \brief Max bytes received from UART send to App
#define DEFAULT_APP_DATA_LENGTH 20
// ****************************************************************************
// typedefs
// ****************************************************************************
//! \brief Queue record structure
//!
typedef struct SDI_QueueRec_t
{
Queue_Elem _elem;
SDIMSG_msg_t *sdiMsg;
} SDI_QueueRec;
//*****************************************************************************
// globals
//*****************************************************************************
//! \brief RTOS task structure for SDI task
//!
static Task_Struct sdiTaskStruct;
//! \brief Allocated memory block for SDI task's stack
//!
#if defined __TI_COMPILER_VERSION__
#pragma DATA_ALIGN(sdiTaskStack, 8)
#else
#pragma data_alignment=8
#endif
uint8_t sdiTaskStack[SDITASK_STACK_SIZE];
//! \brief Handle for the ASYNC TX Queue
//!
static Queue_Handle sdiTxQueue;
//! \brief Pointer to last tx message. This is free'd once confirmation is
//! is received that the buffer has been transmitted
//! (ie. SDITASK_TRANSPORT_TX_DONE_EVENT)
//!
static uint8_t *lastQueuedTxMsg;
Event_Struct uartEvent;
Event_Handle hUartEvent; //!< Event used to control the UART thread
//! \brief Pointer to Application RX event callback function for optional
//! rerouting of messages to application.
//!
static sdiIncomingEventCBack_t incomingRXEventAppCBFunc = NULL;
//! \brief Data buffer to send to application
//!
static uint8 buf[SDI_TL_BUF_SIZE] ={0x00,};
static uint16 length;
static uint8 lengthRead;
//! \brief Size of data to send to application
//!
static uint16 maxAppDataSize = DEFAULT_APP_DATA_LENGTH;
//*****************************************************************************
// function prototypes
//*****************************************************************************
//! \brief SDI main event processing loop.
//!
static void SDITask_process(void);
//! \brief Callback function registered with Transport Layer
//!
static void SDITask_transportRXCallBack(int size);
//! \brief Callback function registered with Transport Layer
//!
static void SDITask_transportTxDoneCallBack(int size);
//! \brief Callback function registered with Transport Layer
//!
static void SDITask_MRDYEventCB(int size);
//! \brief ASYNC TX Q Processing function.
//!
static void SDITask_ProcessTXQ(void);
// -----------------------------------------------------------------------------
//! \brief Initialization for the SDI Thread
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITask_setAppDataSize(uint16 mtuSize)
{
maxAppDataSize = mtuSize - 3; //subtract GATT Notification overhead: 1 byte opcode, 2 bytes conn. handle
}
// -----------------------------------------------------------------------------
//! \brief Initialization for the SDI Thread
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITask_inititializeTask(void)
{
lastQueuedTxMsg = NULL;
// create a Tx Queue instance
sdiTxQueue = Queue_create(NULL, NULL);
Event_Params evParams;
Event_Params_init(&evParams);
Event_construct(&uartEvent, &evParams);
hUartEvent = Event_handle(&uartEvent);
// Initialize Network Processor Interface (SDI) and Transport Layer
SDITL_initTL( &SDITask_transportTxDoneCallBack,
&SDITask_transportRXCallBack,
&SDITask_MRDYEventCB );
}
// -----------------------------------------------------------------------------
//! \brief SDI main event processing loop.
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITask_process(void)
{
UInt postedEvents;
/* Forever loop */
for (;; )
{
/* Wait for response message */
postedEvents = Event_pend(hUartEvent, Event_Id_NONE, SDITASK_MRDY_EVENT | SDITASK_TX_READY_EVENT | SDITASK_TRANSPORT_RX_EVENT | SDITASK_TRANSPORT_TX_DONE_EVENT, BIOS_WAIT_FOREVER);
{
// Capture the ISR events flags now within this task loop.
// MRDY event
if (postedEvents & SDITASK_MRDY_EVENT)
{
#ifdef POWER_SAVING
SDITL_handleMrdyEvent();
#endif //POWER_SAVING
}
// An ASYNC message is ready to send to the Host
if(postedEvents & SDITASK_TX_READY_EVENT)
{
if ((!Queue_empty(sdiTxQueue)) && !SDITL_checkSdiBusy())
{
SDITask_ProcessTXQ();
}
if (Queue_empty(sdiTxQueue))
{
// Q is empty, no action.
}
else
{
// Q is not empty, there's more to handle so preserve the
// flag and repost to the task event.
Event_post(hUartEvent, SDITASK_TX_READY_EVENT);
}
}
// The Transport Layer has received some bytes
if(postedEvents & SDITASK_TRANSPORT_RX_EVENT)
{
length = SDIRxBuf_GetRxBufCount();
if(length > maxAppDataSize)
{
lengthRead = (maxAppDataSize & 0xFF);
}else
{
lengthRead = (length & 0xFF);
}
//Do custom app processing
SDIRxBuf_ReadFromRxBuf(buf, lengthRead);
//Echo back via UART
//SDITask_sendToUART(buf, length);
if (incomingRXEventAppCBFunc != NULL)
{
incomingRXEventAppCBFunc( UART_DATA_EVT , buf, lengthRead);
}
if(length > maxAppDataSize)
{
// Additional bytes to collect, preserve the flag and repost
// to the event
Event_post(hUartEvent, SDITASK_TRANSPORT_RX_EVENT);
}
}
// The last transmission to the host has completed.
if(postedEvents & SDITASK_TRANSPORT_TX_DONE_EVENT)
{
// Current TX is done.
if (!Queue_empty(sdiTxQueue))
{
// There are pending ASYNC messages waiting to be sent
// to the host. Post to event.
Event_post(hUartEvent, SDITASK_TX_READY_EVENT);
}
}
}
}
}
// -----------------------------------------------------------------------------
//! \brief SDI Task function called from within SDITask_Fxn
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITask_task(void)
{
// Initialize application
SDITask_inititializeTask();
// No return from TestProfile2 process
SDITask_process();
}
// -----------------------------------------------------------------------------
// Exported Functions
// -----------------------------------------------------------------------------
//! \brief SDI task entry point.
//!
//! \return void
// -----------------------------------------------------------------------------
Void SDITask_Fxn(UArg a0, UArg a1)
{
SDITask_task();
}
// -----------------------------------------------------------------------------
//! \brief Task creation function for SDI
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITask_createTask(void)
{
memset(&sdiTaskStack, 0xDD, sizeof(sdiTaskStack));
// Configure and create the SDI task.
Task_Params sdiTaskParams;
Task_Params_init(&sdiTaskParams);
sdiTaskParams.stack = sdiTaskStack;
sdiTaskParams.stackSize = SDITASK_STACK_SIZE;
sdiTaskParams.priority = SDITASK_PRIORITY;
Task_construct(&sdiTaskStruct, SDITask_Fxn, &sdiTaskParams, NULL);
}
// -----------------------------------------------------------------------------
//! \brief Register callback function to reroute incoming (from UART)
//! SDI messages.
//!
//! \param[in] appRxCB Callback fucntion.
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITask_registerIncomingRXEventAppCB(sdiIncomingEventCBack_t appRxCB)
{
incomingRXEventAppCBFunc = appRxCB;
}
// -----------------------------------------------------------------------------
//! \brief API for application task to send a message to the Host.
//! NOTE: It's assumed all message traffic to the stack will use
//! other (ICALL) APIs/Interfaces.
//!
//! \param[in] pMsg Pointer to "unframed" message buffer.
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITask_sendToUART(uint8_t *pMsg, uint16 length)
{
ICall_CSState key;
SDI_QueueRec *recPtr;
SDIMSG_msg_t *pSDIMsg =(SDIMSG_msg_t *)ICall_malloc( sizeof(SDIMSG_msg_t));
key = ICall_enterCriticalSection();
if(pSDIMsg)
{
pSDIMsg->msgType = SDIMSG_Type_ASYNC;
pSDIMsg->pBuf = (uint8 *)ICall_allocMsg(length);
pSDIMsg->pBufSize = length;
if(pSDIMsg->pBuf)
{
// Payload
memcpy(pSDIMsg->pBuf, pMsg, length);
}
recPtr = ICall_malloc(sizeof(SDI_QueueRec));
recPtr->sdiMsg = pSDIMsg;
}
switch (pSDIMsg->msgType)
{
case SDIMSG_Type_ASYNC:
{
Queue_enqueue(sdiTxQueue, &recPtr->_elem);
Event_post(hUartEvent, SDITASK_TX_READY_EVENT);
break;
}
default:
{
//error
break;
}
}
ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief Dequeue next message in the ASYNC TX Queue and send to serial
//! interface.
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITask_ProcessTXQ(void)
{
ICall_CSState key;
SDI_QueueRec *recPtr = NULL;
// Processing of any TX Queue should only be done
// in a critical section since any application
// task can enqueue items freely
key = ICall_enterCriticalSection();
if (!Queue_empty(sdiTxQueue))
{
recPtr = Queue_dequeue(sdiTxQueue);
if (recPtr != NULL)
{
lastQueuedTxMsg = recPtr->sdiMsg->pBuf;
SDITL_writeTL(recPtr->sdiMsg->pBuf, recPtr->sdiMsg->pBufSize);
//free the Queue record
ICall_free(recPtr->sdiMsg);
ICall_free(recPtr);
}
}
ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
// Call Back Functions
// -----------------------------------------------------------------------------
//! \brief Call back function for TX Done event from transport layer.
//!
//! \param[in] size Number of bytes transmitted.
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITask_transportTxDoneCallBack(int size)
{
if(lastQueuedTxMsg)
{
//Deallocate most recent message being transmitted.
ICall_freeMsg(lastQueuedTxMsg);
lastQueuedTxMsg = NULL;
}
// Post the event to the SDI task thread.
Event_post(hUartEvent, SDITASK_TRANSPORT_TX_DONE_EVENT);
}
// -----------------------------------------------------------------------------
//! \brief RX Callback provided to Transport Layer for RX Event (ie.Bytes
//! received).
//!
//! \param[in] size Number of bytes received.
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITask_transportRXCallBack(int size)
{
if ( size < SDIRxBuf_GetRxBufAvail() )
{
SDIRxBuf_Read(size);
}
else
{
// Trap here for pending buffer overflow. If SDI_FLOW_CTRL is
// enabled, increase size of RxBuf to handle larger frames from host.
for(;;);
}
Event_post(hUartEvent, SDITASK_TRANSPORT_RX_EVENT);
}
// -----------------------------------------------------------------------------
//! \brief RX Callback provided to Transport Layer for MRDY Event
//!
//! \param[in] size N/A
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITask_MRDYEventCB(int size)
{
Event_post(hUartEvent, SDITASK_MRDY_EVENT);
}
@@ -0,0 +1,475 @@
/******************************************************************************
@file sdi_tl.c
SDI Transport Layer API
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
// ****************************************************************************
// includes
// ****************************************************************************
#include <string.h>
#include <xdc/std.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Swi.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "Board.h"
#include "ICall.h"
#include "hal_types.h"
#include "inc/sdi_tl.h"
#include "inc/sdi_config.h"
// ****************************************************************************
// defines
// ****************************************************************************
#if defined(SDI_USE_SPI)
#include "inc/sdi_tl_spi.h"
#elif defined(SDI_USE_UART)
#include "inc/sdi_tl_uart.h"
#else
#error Must define an underlying serial bus for SDI
#endif
// ****************************************************************************
// typedefs
// ****************************************************************************
//*****************************************************************************
// globals
//*****************************************************************************
//! \brief Flag for low power mode
static volatile bool sdiPMSetConstraint = FALSE;
//! \brief Flag for ongoing SDI TX
static volatile bool sdiTxActive = FALSE;
//! \brief The packet that was being sent when HWI of MRDY going low was received
static volatile uint32 mrdyPktStamp = 0;
//! \brief Packets transmitted counter
static uint32 txPktCount = 0;
//! \brief SDI Transport Layer receive buffer
static Char sdiRxBuf[SDI_TL_BUF_SIZE];
//! \brief Index to last byte written into SDI Transport Layer receive buffer
static uint16_t sdiRxBufTail = 0;
//! \brief Index to first byte to be read from SDI Transport Layer receive buffer
static uint16_t sdiRxBufHead = 0;
//! \brief SDI Transport Layer transmit buffer
static Char sdiTxBuf[SDI_TL_BUF_SIZE];
//! \brief Number of bytes in SDI Transport Layer transmit buffer
static uint16_t sdiTxBufLen = 0;
//! \brief Call back function in SDI Task for transmit complete
static sdiRtosCB_t taskTxCB = NULL;
//! \brief Call back function in SDI Task for receive complete
static sdiRtosCB_t taskRxCB = NULL;
//! \brief The remainder of any message that is fragmented
static uint8 *msgFrag = NULL;
//! \brief The length of the remaining message fragment
static uint16 msgFragLen = 0;
#ifdef POWER_SAVING
//! \brief Call back function in SDI Task for MRDY hardware interrupt
static sdiMrdyRtosCB_t taskMrdyCB = NULL;
//! \brief PIN Config for Mrdy and Srdy signals
static PIN_Config sdiHandshakePinsCfg[] =
{
MRDY_PIN | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
SRDY_PIN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
//! \brief PIN State for Mrdy and Srdy signals
static PIN_State sdiHandshakePins;
//! \brief PIN Handles for Mrdy and Srdy signals
static PIN_Handle hSdiHandshakePins;
//! \brief No way to detect whether positive or negative edge with PIN Driver
//! Use a flag to keep track of state
static uint8 mrdy_state;
#endif
//*****************************************************************************
// function prototypes
//*****************************************************************************
//! \brief Call back function provided to underlying serial interface to be
// invoked upon the completion of a transmission
static void SDITL_transmissionCallBack(uint16 Rxlen, uint16 Txlen);
#ifdef POWER_SAVING
//! \brief HWI interrupt function for MRDY
static void SDITL_MRDYPinHwiFxn(PIN_Handle hPin, PIN_Id pinId);
#endif
// -----------------------------------------------------------------------------
//! \brief This routine initializes the transport layer and opens the port
//! of the device. Note that based on project defines, either the
//! UART, or SPI driver can be used.
//!
//! \param[in] sdiCBTx - Call back function for TX complete event
//! \param[in] sdiCBRx - Call back function for RX event
//! \param[in] sdiCBMrdy - Call back function for MRDY event
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITL_initTL(sdiRtosCB_t sdiCBTx, sdiRtosCB_t sdiCBRx, sdiRtosCB_t sdiCBMrdy)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
taskTxCB = sdiCBTx;
taskRxCB = sdiCBRx;
#ifdef POWER_SAVING
taskMrdyCB = sdiCBMrdy;
#endif
transportInit(sdiRxBuf,sdiTxBuf, SDITL_transmissionCallBack);
#ifdef POWER_SAVING
SRDY_DISABLE();
// Initialize SRDY/MRDY. Enable int after callback registered
hSdiHandshakePins = PIN_open(&sdiHandshakePins, sdiHandshakePinsCfg);
PIN_registerIntCb(hSdiHandshakePins, SDITL_MRDYPinHwiFxn);
PIN_setConfig(hSdiHandshakePins, PIN_BM_IRQ, MRDY_PIN | PIN_IRQ_BOTHEDGES);
// Enable wakeup
PIN_setConfig(hSdiHandshakePins, PINCC26XX_BM_WAKEUP, MRDY_PIN | PINCC26XX_WAKEUP_NEGEDGE);
mrdy_state = PIN_getInputValue(MRDY_PIN);
#endif // ! POWER_SAVING
#ifndef POWER_SAVING
// This call will start repeated Uart Reads when Power Savings is disabled
transportRead();
#endif //!POWER_SAVING
ICall_leaveCriticalSection(key);
return;
}
// -----------------------------------------------------------------------------
//! \brief This routine returns the state of transmission on SDI
//!
//! \return bool - state of SDI transmission - 1 - active, 0 - not active
// -----------------------------------------------------------------------------
bool SDITL_checkSdiBusy(void)
{
#ifdef POWER_SAVING
return !PIN_getOutputValue(SRDY_PIN);
#else
return sdiTxActive;
#endif
}
#ifdef POWER_SAVING
// -----------------------------------------------------------------------------
//! \brief This routine is used to set constraints on power manager
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITL_setPM(void)
{
if( sdiPMSetConstraint )
{
return;
}
// set constraints for Standby and idle mode
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
sdiPMSetConstraint = TRUE;
}
#endif
#ifdef POWER_SAVING
// -----------------------------------------------------------------------------
//! \brief This routine is used to release constraints on power manager
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITL_relPM(void)
{
if ( ! sdiPMSetConstraint )
{
return;
}
// release constraints for Standby and idle mode
Power_releaseConstraint(PowerCC26XX_SB_DISALLOW);
Power_releaseConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
sdiPMSetConstraint = FALSE;
}
#endif
#ifdef POWER_SAVING
// -----------------------------------------------------------------------------
//! \brief This routine is used to handle an MRDY transition from a task
//! context. Certain operations such as UART_read() cannot be
//! performed from a HWI context
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITL_handleMrdyEvent(void)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
// Check to make sure this event is not occuring during the next packet
// transmission
if ( PIN_getInputValue(MRDY_PIN) == 0 ||
(sdiTxActive && mrdyPktStamp == txPktCount ) )
{
transportMrdyEvent();
SRDY_ENABLE();
}
ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief This is a HWI function handler for the MRDY pin. Some MRDY
//! functionality can execute from this HWI context. Others
//! must be executed from task context hence the taskMrdyCB()
//!
//! \param[in] hPin - PIN Handle
//! \param[in] pinId - ID of pin that triggered HWI
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITL_MRDYPinHwiFxn(PIN_Handle hPin, PIN_Id pinId)
{
// The pin driver does not currently support returning whether the int
// was neg or pos edge so we must use a variable to keep track of state.
// If the physical state of the pin was used then a very quick toggle of
// of MRDY could be missed.
mrdy_state ^= 1;
if(mrdy_state == 0)
{
mrdyPktStamp = txPktCount;
SDITL_setPM();
if ( taskMrdyCB )
{
taskMrdyCB();
}
}
else
{
transportStopTransfer();
}
}
#endif
// -----------------------------------------------------------------------------
//! \brief This callback is invoked on the completion of one transmission
//! to/from the host MCU. Any bytes receives will be [0,Rxlen) in
//! sdiRxBuf.
//! If bytes were receives or transmitted, this function notifies
//! the SDI task via registered call backs
//!
//! \param[in] Rxlen - lenth of the data received
//! \param[in] Txlen - length of the data transferred
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITL_transmissionCallBack(uint16 Rxlen, uint16 Txlen)
{
sdiRxBufHead = 0;
sdiRxBufTail = Rxlen;
if(Rxlen)
{
if ( taskRxCB )
{
taskRxCB(Rxlen);
}
}
if(Txlen)
{
sdiTxActive = FALSE;
// Only perform call back if SDI Task has been registered
// and if there is not another fragment to send of this message
if ( taskTxCB && !msgFragLen )
{
taskTxCB(Txlen);
}
}
#ifdef POWER_SAVING
// Reset mrdy state in case of missed HWI
mrdy_state = PIN_getInputValue(MRDY_PIN);
SDITL_relPM();
SRDY_DISABLE();
#endif
// If there is another fragment to send, begin write without notifying
// higher level tasks
if ( msgFragLen )
{
SDITL_writeTL(msgFrag,msgFragLen);
}
}
// -----------------------------------------------------------------------------
//! \brief This routine reads data from the transport layer based on len,
//! and places it into the buffer.
//!
//! \param[in] buf - Pointer to buffer to place read data.
//! \param[in] len - Number of bytes to read.
//!
//! \return uint16 - the number of bytes read from transport
// -----------------------------------------------------------------------------
uint16 SDITL_readTL(uint8 *buf, uint16 len)
{
// Only copy the lowest number between len and bytes remaining in buffer
len = (len > SDITL_getRxBufLen()) ? SDITL_getRxBufLen() : len;
memcpy(buf, &sdiRxBuf[sdiRxBufHead], len);
sdiRxBufHead += len;
return len;
}
// -----------------------------------------------------------------------------
//! \brief This routine writes data from the buffer to the transport layer.
//!
//! \param[in] buf - Pointer to buffer to write data from.
//! \param[in] len - Number of bytes to write.
//!
//! \return uint16 - the number of bytes written to transport
// -----------------------------------------------------------------------------
uint16 SDITL_writeTL(uint8 *buf, uint16 len)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
// Writes are atomic at transport layer
if ( SDITL_checkSdiBusy() )
{
ICall_leaveCriticalSection(key);
return 0;
}
// If len of message is greater than fragment size
// then message must be sent over the span of multiple
// fragments
if ( len > SDI_MAX_FRAG_SIZE )
{
msgFrag = buf + SDI_MAX_FRAG_SIZE;
msgFragLen = len - SDI_MAX_FRAG_SIZE;
len = SDI_MAX_FRAG_SIZE;
}
else
{
msgFrag = NULL;
msgFragLen = 0;
}
memcpy(sdiTxBuf, buf, len);
sdiTxBufLen = len;
sdiTxActive = TRUE;
txPktCount++;
len = transportWrite(sdiTxBufLen);
#ifdef POWER_SAVING
SRDY_ENABLE();
#endif
ICall_leaveCriticalSection(key);
return len;
}
// -----------------------------------------------------------------------------
//! \brief This routine returns the max size receive buffer.
//!
//! \return uint16 - max size of the receive buffer
// -----------------------------------------------------------------------------
uint16 SDITL_getMaxRxBufSize(void)
{
return(SDI_TL_BUF_SIZE);
}
// -----------------------------------------------------------------------------
//! \brief This routine returns the max size transmit buffer.
//!
//! \return uint16 - max size of the transmit buffer
// -----------------------------------------------------------------------------
uint16 SDITL_getMaxTxBufSize(void)
{
return(SDI_TL_BUF_SIZE);
}
// -----------------------------------------------------------------------------
//! \brief Returns number of bytes that are unread in RxBuf
//!
//! \return uint16 - number of unread bytes
// -----------------------------------------------------------------------------
uint16 SDITL_getRxBufLen(void)
{
return ((sdiRxBufTail - sdiRxBufHead) + SDI_TL_BUF_SIZE) % SDI_TL_BUF_SIZE;
}
@@ -0,0 +1,497 @@
/******************************************************************************
@file sdi_tl_uart.c
SDI Transport Layer Module for UART
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
// ****************************************************************************
// includes
// ****************************************************************************
#include <string.h>
#include <xdc/std.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "ICall.h"
#include "Board.h"
#include "hal_types.h"
#include "bcomdef.h"
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Swi.h>
#include "inc/sdi_config.h"
#include "inc/sdi_tl_uart.h"
#include "inc/sdi_data.h"
#include <ti/drivers/uart/UARTCC26XX.h>
// ****************************************************************************
// defines
// ****************************************************************************
// ****************************************************************************
// typedefs
// ****************************************************************************
//*****************************************************************************
// globals
//*****************************************************************************
//! \brief UART Handle for UART Driver
static UART_Handle uartHandle;
//! \brief UART ISR Rx Buffer
static Char isrRxBuf[UART_ISR_BUF_SIZE];
//! \brief SDI TL call back function for the end of a UART transaction
static sdiCB_t sdiTransmitCB = NULL;
#ifdef POWER_SAVING
//! \brief Flag signalling receive in progress
static uint8 RxActive = FALSE;
//! \brief Flag signalling transmit in progress
static uint8 TxActive = FALSE;
//! \brief Value of MRDY SDI TL pin
static uint8 mrdy_flag = 1;
#endif //POWER_SAVING
//! \brief Pointer to SDI TL TX Buffer
static Char* TransportRxBuf;
//! \brief Length of bytes received
static uint16 TransportRxLen = 0;
//! \brief Pointer to SDI TL RX Buffer
static Char* TransportTxBuf;
//! \brief Length of bytes to send from SDI TL Tx Buffer
static uint16 TransportTxLen = 0;
//! \brief UART Object. Initialized in board specific files
extern UARTCC26XX_Object uartCC26XXObjects[];
UART_Params paramsUART;
//! \brief Pointer to Application RX event callback function for optional
//! rerouting of messages to application.
//!
static sdiTLIncomingEventCBack_t incomingRXErrorStatusAppCBFunc = NULL;
//*****************************************************************************
// function prototypes
//*****************************************************************************
//! \brief UART ISR function. Invoked upon specific threshold of UART RX FIFO size
static uint16 SDITLUART_readIsrBuf(size_t size);
//! \brief UART Callback invoked after UART write completion
static void SDITLUART_writeCallBack(UART_Handle handle, void *ptr, size_t size);
//! \brief UART Callback invoked after readsize has been read or timeout
static void SDITLUART_readCallBack(UART_Handle handle, void *ptr, size_t size);
void SDITLUART_registerIncomingRXErrorStatusAppCB(sdiTLIncomingEventCBack_t appRxErrStatusCB)
{
incomingRXErrorStatusAppCBFunc = appRxErrStatusCB;
}
void SDITLUART_closeUART(void)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
// Cancel any pending reads
UART_readCancel(uartHandle);
// Close / power off the UART.
UART_close(uartHandle);
ICall_leaveCriticalSection(key);
}
uint8 SDITLUART_configureUARTParams(UART_Params *initParams)
{
uint8 status = SUCCESS;
ICall_CSState key;
SDITLUART_closeUART();
key = ICall_enterCriticalSection();
// Open / power on the UART.
uartHandle = UART_open(Board_UART, &paramsUART);
if(uartHandle != NULL)
{
//DEBUG("UART_open successful");
}else{
//DEBUG("ERROR in UART_open");
status = FAILURE;
}
//Enable Partial Reads on all subsequent UART_read()
status = UART_control(uartHandle, UARTCC26XX_RETURN_PARTIAL_ENABLE, NULL);
ICall_leaveCriticalSection(key);
#ifndef POWER_SAVING
//Initiate first read to start polling UART
SDITLUART_readTransport();
#endif //POWER_SAVING
return status;
}
// -----------------------------------------------------------------------------
//! \brief This routine initializes the transport layer and opens the port
//! of the device.
//!
//! \param[in] tRxBuf - pointer to SDI TL Tx Buffer
//! \param[in] tTxBuf - pointer to SDI TL Rx Buffer
//! \param[in] sdiCBack - SDI TL call back function to be invoked at the end of
//! a UART transaction
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_initializeTransport(Char *tRxBuf, Char *tTxBuf, sdiCB_t sdiCBack)
{
// Set UART transport callbacks
TransportRxBuf = tRxBuf;
TransportTxBuf = tTxBuf;
sdiTransmitCB = sdiCBack;
// Configure UART parameters.
UART_Params_init(&paramsUART);
paramsUART.baudRate = SDI_UART_BR;
paramsUART.readDataMode = UART_DATA_BINARY;
paramsUART.writeDataMode = UART_DATA_BINARY;
paramsUART.dataLength = UART_LEN_8;
paramsUART.stopBits = UART_STOP_ONE;
paramsUART.readMode = UART_MODE_CALLBACK;
paramsUART.writeMode = UART_MODE_CALLBACK;
paramsUART.readEcho = UART_ECHO_OFF;
paramsUART.readCallback = SDITLUART_readCallBack;
paramsUART.writeCallback = SDITLUART_writeCallBack;
//paramsUART.readReturnMode = UART_RETURN_FULL;
// Open / power on the UART.
uartHandle = UART_open(Board_UART, &paramsUART);
if(uartHandle != NULL)
{
//DEBUG("ERROR in UART_open");
}
//Enable Partial Reads on all subsequent UART_read()
UART_control(uartHandle, UARTCC26XX_RETURN_PARTIAL_ENABLE, NULL);
return;
}
#ifdef POWER_SAVING
// -----------------------------------------------------------------------------
//! \brief This routine stops any pending reads
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_stopTransfer(void)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
mrdy_flag = 1;
// If we have no bytes in FIFO yet we must assume there was nothing to read
// or that the FIFO has already been read for this UART_read()
// In either case UART_readCancel will call the read CB function and it will
// invoke sdiTransmitCB with the appropriate number of bytes read
if (!UARTCharsAvail(((UARTCC26XX_HWAttrsV1 const *)(uartHandle->hwAttrs))->baseAddr))
{
RxActive = FALSE;
UART_readCancel(uartHandle);
}
ICall_leaveCriticalSection(key);
return;
}
#endif //POWER_SAVING
#ifdef POWER_SAVING
// -----------------------------------------------------------------------------
//! \brief This routine is called from the application context when MRDY is
//! de-asserted
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_handleMrdyEvent(void)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
mrdy_flag = 0;
// If we haven't already begun reading, now is the time before Master
// potentially starts to send data
// The !TxActive condition is because we will call UART_sdiRead() prior to setting
// TxActive true. There is the possibility that MRDY gets set high which
// clears RxActive prior to us getting to this event. This will cause us to
// read twice per transaction which will cause the transaction to never
// complete
if ( !RxActive && !TxActive )
{
SDITLUART_readTransport();
}
// If we have something to write, then the Master has signalled it is ready
// to receive. Time to write.
if ( TxActive )
{
// Check to see if transport is successful. If not, reset TxLen to allow
// another write to be processed
if ( UART_write(uartHandle, TransportTxBuf, TransportTxLen) == UART_ERROR )
{
TxActive = FALSE;
TransportTxLen = 0;
}
}
ICall_leaveCriticalSection(key);
return;
}
#endif //POWER_SAVING
// -----------------------------------------------------------------------------
//! \brief This callback is invoked on Write completion
//!
//! \param[in] handle - handle to the UART port
//! \param[in] ptr - pointer to data to be transmitted
//! \param[in] size - size of the data
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITLUART_writeCallBack(UART_Handle handle, void *ptr, size_t size)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
uint8 errStatus = 0;
if (errStatus = ((UARTCC26XX_Handle)handle->object)->status)
{
//report UART error status to application
if(incomingRXErrorStatusAppCBFunc != NULL)
incomingRXErrorStatusAppCBFunc(UART_ERROR_EVT, &errStatus, sizeof(errStatus));
}
#ifdef POWER_SAVING
if ( !RxActive )
{
UART_readCancel(uartHandle);
if ( sdiTransmitCB )
{
sdiTransmitCB(TransportRxLen,TransportTxLen);
}
}
TxActive = FALSE;
#else
if ( sdiTransmitCB )
{
sdiTransmitCB(0,TransportTxLen);
}
#endif //POWER_SAVING
ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief This callback is invoked on Read completion of readSize/receive
//! timeout
//!
//! \param[in] handle - handle to the UART port
//! \param[in] ptr - pointer to buffer to read data into
//! \param[in] size - size of the data
//!
//! \return void
// -----------------------------------------------------------------------------
static void SDITLUART_readCallBack(UART_Handle handle, void *ptr, size_t size)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
uint8 errStatus = 0;
if (errStatus = ((UARTCC26XX_Handle)handle->object)->status)
{
//report UART error status to application
if(incomingRXErrorStatusAppCBFunc != NULL)
incomingRXErrorStatusAppCBFunc(UART_ERROR_EVT, &errStatus, sizeof(errStatus));
}
if (size)
{
if (size != SDITLUART_readIsrBuf(size))
{
// Buffer overflow imminent. Cancel read and pass to higher layers
// for handling
#ifdef POWER_SAVING
RxActive = FALSE;
#endif //POWER_SAVING
if ( sdiTransmitCB )
{
sdiTransmitCB(SDI_TL_BUF_SIZE,TransportTxLen);
}
}
}
#ifdef POWER_SAVING
// Read has been cancelled by transport layer, or bus timeout and no bytes in FIFO
// - do not invoke another read
if ( !UARTCharsAvail(((UARTCC26XX_HWAttrsV1 const *)(uartHandle->hwAttrs))->baseAddr) &&
mrdy_flag )
{
RxActive = FALSE;
// If TX has also completed then we are safe to issue call back
if ( !TxActive && sdiTransmitCB )
{
sdiTransmitCB(TransportRxLen,TransportTxLen);
}
}
else
{
UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
}
#else
if ( sdiTransmitCB )
{
sdiTransmitCB(size,0);
}
TransportRxLen = 0;
UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
#endif //POWER_SAVING
ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief This routine reads data from the transport layer based on len,
//! and places it into the buffer.
//!
//! \param[in] size - amount of bytes in UART ISR Rx Buffer
//!
//! \return uint16 - number of bytes read from transport
// -----------------------------------------------------------------------------
static uint16 SDITLUART_readIsrBuf(size_t size)
{
uint8_t i = 0;
// Copy the UART buffer to the application buffer
// Do not allow overflow of buffer. Instead pass up to SDI module and allow
// it to handle
for (; (i < size) && (TransportRxLen < SDI_TL_BUF_SIZE); i++)
{
TransportRxBuf[TransportRxLen++] = isrRxBuf[i];
isrRxBuf[i] = 0;
}
return i;
}
// -----------------------------------------------------------------------------
//! \brief This routine reads data from the UART
//!
//! \return void
// -----------------------------------------------------------------------------
void SDITLUART_readTransport(void)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
#ifdef POWER_SAVING
RxActive = TRUE;
#endif //POWER_SAVING
TransportRxLen = 0;
UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief This routine writes copies buffer addr to the transport layer.
//!
//! \param[in] len - Number of bytes to write.
//!
//! \return uint8 - number of bytes written to transport
// -----------------------------------------------------------------------------
uint16 SDITLUART_writeTransport(uint16 len)
{
ICall_CSState key;
key = ICall_enterCriticalSection();
TransportTxLen = len;
#ifdef POWER_SAVING
TxActive = TRUE;
// Start reading prior to impending write transaction
// We can only call UART_write() once MRDY has been signaled from Master
// device
SDITLUART_readTransport();
#else
// Check to see if transport is successful. If not, reset TxLen to allow
// another write to be processed
if(UART_write(uartHandle, TransportTxBuf, TransportTxLen) == UART_ERROR )
{
TransportTxLen = 0;
}
#endif //POWER_SAVING
ICall_leaveCriticalSection(key);
return TransportTxLen;
}
View File
View File
View File
View File
View File
View File
@@ -0,0 +1,273 @@
/*
Copyright (c) 2013-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.
*/
/*
* ======== lcdSmartRF06EB.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <driverlib/ioc.h>
/* TI-RTOS Header files */
#include <ti/mw/lcd/LCDDogm1286.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <inc/hw_fcfg1.h>
#include "Board.h"
// RF Driver
#include <ti/drivers/rf/RF.h>
#include "smartrf_settings.h"
/***** Defines *****/
#define BEACON_TASK_STACK_SIZE 1024
#define BEACON_TASK_PRIORITY 2
/* TX Configuration */
#define NUMBER_OF_PACKETS 1000
#define PAYLOAD_LENGTH 30
#define PACKET_INTERVAL 50*4000 //50 ms @ 4 MHz
#define BBEACON_DELAY 4000*4000 //4 seconds @4 MHz
#define ABEACON_COUNT 20
#define ADV_PERIOD (8000 * 4000) - ((PACKET_INTERVAL * ABEACON_COUNT) + BBEACON_DELAY)
#define ADVLEN 31
/***** Prototypes *****/
static void beaconTaskFunction(UArg arg0, UArg arg1);
/***** Variable declarations *****/
static Task_Params beaconTaskParams;
static Task_Struct beaconTask;
static uint8_t beaconTaskStack[BEACON_TASK_STACK_SIZE];
static RF_Object rfObject;
static RF_Handle rfHandle;
uint32_t time;
static uint8_t advCount = 1;
static char aBeaconData[ADVLEN] =
{
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
0xAA,
};
static char bBeaconData[ADVLEN] =
{
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
0xBB,
};
void beaconTask_init(void) {
Task_Params_init(&beaconTaskParams);
beaconTaskParams.stackSize = BEACON_TASK_STACK_SIZE;
beaconTaskParams.priority = BEACON_TASK_PRIORITY;
beaconTaskParams.stack = &beaconTaskStack;
beaconTaskParams.arg0 = (UInt)1000000;
Task_construct(&beaconTask, beaconTaskFunction, &beaconTaskParams, NULL);
}
static void beaconTaskFunction(UArg arg0, UArg arg1)
{
uint32_t time;
RF_Params rfParams;
RF_Params_init(&rfParams);
/* Request access to the radio */
rfHandle = RF_open(&rfObject, &RF_ble, (RF_RadioSetup*)&RF_cmdBleRadioSetup, &rfParams);
/* Get current time */
time = RF_getCurrentTime();
while(1)
{
#ifdef EVERY_OTHER
if (advCount)
{
//set adv data
RF_cmdAdvNc0.pParams->pAdvData = (uint8_t*)aBeaconData;
RF_cmdAdvNc0.pParams->advLen = ADVLEN;
//switch
advCount = 0;
}
else
{
//set advertising data
RF_cmdAdvNc0.pParams->pAdvData = (uint8_t*)bBeaconData;
RF_cmdAdvNc0.pParams->advLen = ADVLEN;
//switch
advCount = 1;
}
time += PACKET_INTERVAL;
#elif // periodic use case
if (advCount == 1) //first aBeacon packet
{
//set adv data
RF_cmdAdvNc0.pParams->pAdvData = (uint8_t*)aBeaconData;
RF_cmdAdvNc0.pParams->advLen = ADVLEN;
//increment aBeacon counter
advCount++;
//set time to next advertisement
time += PACKET_INTERVAL;
}
else if (advCount < ABEACON_COUNT) // aBeacon packet
{
//set time for next packet
time += PACKET_INTERVAL;
//increment aBeacon counter
advCount++;
}
else if (advCount == ABEACON_COUNT) //last aBeacon packet
{
//delay before bBeacon packet
time += BBEACON_DELAY;
//set advertising data
RF_cmdAdvNc0.pParams->pAdvData = (uint8_t*)bBeaconData;
RF_cmdAdvNc0.pParams->advLen = ADVLEN;
//increment aBeacon counter
advCount++;
}
else //bBeacon packet
{
//reset aBeacon counter
advCount = 1;
//don't advertise again until end of period
time += ADV_PERIOD;
}
#endif
RF_cmdAdvNc0.startTime = time;
/* Send packet */
RF_EventMask result = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdAdvNc0, RF_PriorityNormal, NULL, 0);
if (!(result & RF_EventLastCmdDone))
{
/* Error */
while(1);
}
}
}
/*
* ======== main ========
*
*/
int main(void)
{
/* Call board init functions. */
PIN_init(BoardGpioInitTable);
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif //POWER_SAVING
/* Initialize task */
beaconTask_init();
/* Start BIOS */
BIOS_start();
return (0);
}
@@ -0,0 +1,187 @@
/*
* Filename: smartrf_settings.c
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
//*********************************************************************************
// These settings have been manually typed for use with ble non-connectable advertising on CC26xx with tirtos rf driver
//
//*********************************************************************************
//*********************************************************************************
#include <driverlib/rf_mailbox.h>
#include <driverlib/rf_common_cmd.h>
#include <driverlib/rf_ble_cmd.h>
#include <ti/drivers/rf/RF.h>
#include <rf_patches/rf_patch_cpe_ble.h>
#include <rf_patches/rf_patch_rfe_ble.h>
#include "smartrf_settings.h"
//Advertisment payload length in bytes
#define ADVLEN 31
// Advertisment data. Must be global for other files to access it.
char advData[ADVLEN] = {0};
static uint64_t devAddress = { 0xEEEEEEEEEEEE };
//#pragma data_alignment=4
//rfCoreHal_bleAdvOutput_t advOutput = {0};
// TI-RTOS RF Mode Object
RF_Mode RF_ble =
{
.rfMode = RF_MODE_BLE,
.cpePatchFxn = &rf_patch_cpe_ble,
.mcePatchFxn = 0,
#ifdef ADV_NC_OPTIMIZED
.rfePatchFxn = 0,
#else
.rfePatchFxn = &rf_patch_rfe_ble,
#endif
};
// Overrides for CMD_RADIO_SETUP
uint32_t pOverrides[] =
{
#ifndef ADV_NC_OPTIMIZED
0x00001007, // Remove if RFE patch is not applied.
0x00456088, // Adjust AGC reference level
#endif
0x00354038, // Synth: Set RTRIM (POTAILRESTRIM) to 5
0x4001402D, // Synth: Correct CKVD latency setting (address)
0x00608402, // Synth: Correct CKVD latency setting (value)
0x4001405D, // Synth: Set ANADIV DIV_BIAS_MODE to PG1 (address)
0x1801F800, // Synth: Set ANADIV DIV_BIAS_MODE to PG1 (value)
0x000784A3, // Synth: Set FREF = 3.43 MHz (24 MHz / 7)
0xA47E0583, // Synth: Set loop bandwidth after lock to 80 kHz (K2)
0xEAE00603, // Synth: Set loop bandwidth after lock to 80 kHz (K3, LSB)
0x00010623, // Synth: Set loop bandwidth after lock to 80 kHz (K3, MSB)
0x013800C3, // Use enhanced BLE shape
/* Spur fix */
0x02010403, // Synth: Use 24 MHz XOSC as synth clock, enable phase error discard feature
0x40014035, // Synth: Set phase error error discard count to 1 (default 2) to get faster settling in TX (address)
0x177F0408, // Synth: Set phase error error discard count to 1 (default 2) to get faster settling in TX (value)
0x38000463, // Synth: Modify phase error discard threshold factor and offset
/* Increase tone length due to spur fix */
0x036052AC, // Add 6 us to tone in front of packet
0x01AD02A3, // Compensate for 6 us added to tone in front of packet
0x01680263, // Compensate for 6 us added to tone in front of packet
0xFFFFFFFF, // End of override list
};
// CMD_RADIO_SETUP
//#pragma data_alignment=4
rfc_CMD_RADIO_SETUP_t RF_cmdBleRadioSetup =
{
.commandNo = CMD_RADIO_SETUP,
.pNextOp = NULL,
.startTrigger.triggerType = TRIG_NOW,
.condition.rule = COND_ALWAYS,
.pRegOverride = pOverrides,
.config.frontEndMode = 0x0, // Differential
.config.biasMode = 0x0, // Internal bias
// .txPower = 0x3161, // 0 dbm
.txPower = 0x9330, // 5 dbm
.mode = 0, // BLE mode
};
/*
{ TX_POWER_0_DBM, GEN_TX_POWER_VAL( 0x21, 1, 0x31 ) },
{ TX_POWER_5_DBM, GEN_TX_POWER_VAL( 0x30, 0, 0x93 ) } };
#define GEN_TX_POWER_VAL( ib, gc, tc ) \
(uint16)(((ib) & 0x3F) | (((gc) & 0x03) << 6) | (((tc)&0xFF) << 8))
0 dBm = 0x0021 | 0x0080 | 0x3100 = 0x3161
5 dBm = 0x0030 | 0x0000 | 0x9300 = 0x9330
*/
rfc_bleAdvPar_t cmdAdvParam = {
.advLen = ADVLEN,
.pAdvData = (uint8_t*)advData,
.pDeviceAddress = (uint16_t*)&devAddress,
// .endTrigger.triggerType = TRIG_NEVER,
};
// CMD_ADV_NC (Beacon channel 37)
rfc_CMD_BLE_ADV_NC_t RF_cmdAdvNc0 =
{
.commandNo = CMD_BLE_ADV_NC,
.status = 0x0000,
.pNextOp = (rfc_radioOp_t*)&RF_cmdAdvNc1,
.startTime = 0x00000000,
.startTrigger.triggerType = TRIG_ABSTIME,
.condition.rule = COND_ALWAYS,
.channel = 37,
.whitening = 0, // Use default
.pParams = &cmdAdvParam,
.pOutput = 0,
};
// CMD_ADV_NC (Beacon channel 38)
rfc_CMD_BLE_ADV_NC_t RF_cmdAdvNc1 =
{
.commandNo = CMD_BLE_ADV_NC,
.status = 0x0000,
.pNextOp = (rfc_radioOp_t*)&RF_cmdAdvNc2,
.startTime = 0x00000000,
.startTrigger.triggerType = TRIG_NOW,
.condition.rule = COND_ALWAYS,
.channel = 38,
.whitening = 0, // Use default
.pParams = &cmdAdvParam,
.pOutput = 0,
};
// CMD_ADV_NC (Beacon channel 39)
rfc_CMD_BLE_ADV_NC_t RF_cmdAdvNc2 =
{
.commandNo = CMD_BLE_ADV_NC,
.status = 0x0000,
.pNextOp = NULL,
.startTime = 0x00000000,
.startTrigger.triggerType = TRIG_NOW,
.condition.rule = COND_NEVER,
.channel = 39,
.whitening = 0, // Use default
.pParams = &cmdAdvParam,
.pOutput = 0,
};
@@ -0,0 +1,58 @@
/*
Copyright (c) 2013-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.
*/
#ifndef SMARTRF_SETTINGS_H
#define SMARTRF_SETTINGS_H
//*********************************************************************************
// These settings has been ported for use with TI-RTOS RF driver and cc26xxware
//
//*********************************************************************************
#include <driverlib/rf_mailbox.h>
#include <driverlib/rf_common_cmd.h>
#include <driverlib/rf_ble_cmd.h>
#include <ti/drivers/rf/RF.h>
// TI-RTOS RF Mode Object
extern RF_Mode RF_ble;
// RF Core API commands
extern rfc_CMD_RADIO_SETUP_t RF_cmdBleRadioSetup;
extern rfc_CMD_BLE_ADV_NC_t RF_cmdAdvNc0; // Non connectable advertising ch. 37
extern rfc_CMD_BLE_ADV_NC_t RF_cmdAdvNc1; // Non connectable advertising ch. 38
extern rfc_CMD_BLE_ADV_NC_t RF_cmdAdvNc2; // Non connectable advertising ch. 39
#endif // SMARTRF_SETTINGS_H
@@ -0,0 +1,87 @@
/******************************************************************************
@file central_to_multiperipheral.h
@brief This file contains the Simple BLE Central sample application
definitions and prototypes.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
Copyright (c) 2013-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.
******************************************************************************
Release Name: ble_sdk_2_02_01_18
Release Date: 2016-10-26 15:20:04
*****************************************************************************/
#ifndef CENTRALTOMULTIPERIPHERAL_H
#define CENTRALTOMULTIPERIPHERAL_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Task creation function for the Simple BLE Central.
*/
extern void central_to_multiperipheral_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* CENTRALTOMULTIPERIPHERAL_H */
@@ -0,0 +1,239 @@
/******************************************************************************
@file main.c
@brief main entry of the BLE stack sample application.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
Copyright (c) 2013-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.
******************************************************************************
Release Name: ble_sdk_2_02_00_31_s
Release Date: 2016-06-16 18:59:11
*****************************************************************************/
/*******************************************************************************
* INCLUDES
*/
#include <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "hal_assert.h"
#include "central.h"
#include "central_to_multiperipheral.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
#include <ti/mw/display/Display.h>
/*******************************************************************************
* MACROS
*/
/*******************************************************************************
* CONSTANTS
*/
/*******************************************************************************
* TYPEDEFS
*/
/*******************************************************************************
* LOCAL VARIABLES
*/
/*******************************************************************************
* GLOBAL VARIABLES
*/
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
extern Display_Handle dispHandle;
/*******************************************************************************
* @fn Main
*
* @brief Application Main
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
int main()
{
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif //POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPCentralRole_createTask();
/* Kick off application - Priority 1 */
central_to_multiperipheral_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
/*******************************************************************************
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
* in the stack.
*
* input parameters
*
* @param assertCause - Assert cause as defined in hal_assert.h.
* @param assertSubcause - Optional assert subcause (see hal_assert.h).
*
* output parameters
*
* @param None.
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
// Open the display if the app has not already done so
if ( !dispHandle )
{
dispHandle = Display_open(Display_Type_LCD, NULL);
}
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
}
else
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
HAL_ASSERT_SPINLOCK;
break;
default:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
HAL_ASSERT_SPINLOCK;
}
return;
}
/*******************************************************************************
* @fn smallErrorHook
*
* @brief Error handler to be hooked into TI-RTOS.
*
* input parameters
*
* @param eb - Pointer to Error Block.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void smallErrorHook(Error_Block *eb)
{
for (;;);
}
/*******************************************************************************
*/
@@ -0,0 +1,227 @@
/******************************************************************************
@file osal_icall_ble.c
@brief This file contains function that allows user setup tasks
Group: WCS, BTS
$Target Device: DEVICES $
******************************************************************************
Copyright (c) 2013-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.
*****************************************************************************/
/**************************************************************************************************
* INCLUDES
**************************************************************************************************/
#include <icall.h>
#include "hal_types.h"
#include "hal_mcu.h"
#include "osal.h"
#include "osal_tasks.h"
#include "osal_snv.h"
/* LL */
#include "ll.h"
#if defined ( OSAL_CBTIMER_NUM_TASKS )
#include "osal_cbtimer.h"
#endif
/* L2CAP */
#include "l2cap.h"
/* gap */
#include "gap.h"
#if defined ( GAP_BOND_MGR )
#include "gapbondmgr.h"
#endif
/* GATT */
#include "gatt.h"
/* Application */
#include "hci_tl.h"
#include "gattservapp.h"
#include "ble_user_config.h"
#include "ble_dispatch.h"
/*********************************************************************
* GLOBAL VARIABLES
*/
// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] =
{
LL_ProcessEvent, // task 0
HCI_ProcessEvent, // task 1
#if defined ( OSAL_CBTIMER_NUM_TASKS )
OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ), // task 2
#endif
L2CAP_ProcessEvent, // task 3
GAP_ProcessEvent, // task 4
SM_ProcessEvent, // task 5
GATT_ProcessEvent, // task 6
GATTServApp_ProcessEvent, // task 7
#if defined ( GAP_BOND_MGR )
GAPBondMgr_ProcessEvent, // task 8
#endif
bleDispatch_ProcessEvent // task 9
};
const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;
/*********************************************************************
* FUNCTIONS
*********************************************************************/
/*********************************************************************
* @fn osalInitTasks
*
* @brief This function invokes the initialization function for each task.
*
* @param void
*
* @return none
*/
void osalInitTasks( void )
{
ICall_EntityID entity;
ICall_Semaphore sem;
uint8 taskID = 0;
uint8 i;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
/* LL Task */
LL_Init( taskID++ );
/* HCI Task */
HCI_Init( taskID++ );
#if defined ( OSAL_CBTIMER_NUM_TASKS )
/* Callback Timer Tasks */
osal_CbTimerInit( taskID );
taskID += OSAL_CBTIMER_NUM_TASKS;
#endif
/* L2CAP Task */
L2CAP_Init( taskID++ );
/* GAP Task */
GAP_Init( taskID++ );
/* SM Task */
SM_Init( taskID++ );
/* GATT Task */
GATT_Init( taskID++ );
/* GATT Server App Task */
GATTServApp_Init( taskID++ );
#if defined ( GAP_BOND_MGR )
/* Bond Manager Task */
GAPBondMgr_Init( taskID++ );
#endif
/* ICall BLE Dispatcher Task */
bleDispatch_Init( taskID );
// ICall enrollment
/* Enroll the service that this stack represents */
ICall_enrollService(ICALL_SERVICE_CLASS_BLE, NULL, &entity, &sem);
/* Enroll the obtained dispatcher entity and OSAL task ID of HCI Ext App
* to OSAL so that OSAL can route the dispatcher message into
* the appropriate OSAL task.
*/
osal_enroll_dispatchid(taskID, entity);
/* Register all other OSAL tasks to use the registered dispatcher entity
* ID as the source of dispatcher messages, even though the other OSAL
* tasks didn't register themselves to receive messages from application.
*/
for (i = 0; i < taskID; i++)
{
osal_enroll_senderid(i, entity);
}
}
/**
* Main entry function for the stack image
*/
int stack_main( void *arg )
{
/* User reconfiguration of BLE Controller and Host variables */
setBleUserConfig( (bleUserCfg_t *)arg );
/* Establish OSAL for a stack service that requires accompanying
* messaging service */
if (ICall_enrollService(ICALL_SERVICE_CLASS_BLE_MSG,
(ICall_ServiceFunc) osal_service_entry,
&osal_entity, &osal_semaphore) !=
ICALL_ERRNO_SUCCESS)
{
/* abort */
ICall_abort();
}
halIntState_t state;
HAL_ENTER_CRITICAL_SECTION(state);
// Turn off interrupts
//osal_int_disable( INTS_ALL );
// Initialize NV System
osal_snv_init( );
// Initialize the operating system
osal_init_system();
// Allow interrupts
//osal_int_enable( INTS_ALL );
HAL_EXIT_CRITICAL_SECTION(state);
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
}
/*********************************************************************
*********************************************************************/
@@ -0,0 +1,740 @@
/*
* Filename: hidemukbdlp.c
*
* Description: This is the simple_peripheral example modified to send
* data over BLE at a high throughput.
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/*********************************************************************
* INCLUDES
*/
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Queue.h>
#include "gatt.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "gatt_profile_uuid.h"
#include "devinfoservice.h"
#include "battservice.h"
#include "hidkbdservice.h"
#include "hiddev.h"
#include "peripheral.h"
#include "gapbondmgr.h"
#include "osal_snv.h"
#include "icall_apimsg.h"
#include "util.h"
#include <ti/mw/display/Display.h>
#include "board_key.h"
#include "board.h"
#include "hidemukbdlp.h"
/*********************************************************************
* MACROS
*/
#define KEY_NONE 0x00
// Selected HID LED bitmaps
#define LED_NUM_LOCK 0x01
#define LED_CAPS_LOCK 0x02
// Selected HID mouse button values
#define MOUSE_BUTTON_1 0x01
#define MOUSE_BUTTON_NONE 0x00
// HID keyboard input report length
#define HID_KEYBOARD_IN_RPT_LEN 8
// HID LED output report length
#define HID_LED_OUT_RPT_LEN 1
// HID mouse input report length
#define HID_MOUSE_IN_RPT_LEN 5
/*********************************************************************
* CONSTANTS
*/
// HID idle timeout in msec; set to zero to disable timeout
#define DEFAULT_HID_IDLE_TIMEOUT 60000
// Minimum connection interval (units of 1.25ms) if automatic parameter update
// request is enabled.
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 8
// Maximum connection interval (units of 1.25ms) if automatic parameter update
// request is enabled.
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 8
// Slave latency to use if automatic parameter update request is enabled
#define DEFAULT_DESIRED_SLAVE_LATENCY 50
// Supervision timeout value (units of 10ms) if automatic parameter update
// request is enabled.
#define DEFAULT_DESIRED_CONN_TIMEOUT 500
// Whether to enable automatic parameter update request when a connection is
// formed.
#define DEFAULT_ENABLE_UPDATE_REQUEST GAPROLE_LINK_PARAM_UPDATE_INITIATE_BOTH_PARAMS
// Connection Pause Peripheral time value (in seconds)
#define DEFAULT_CONN_PAUSE_PERIPHERAL 10
// Default passcode
#define DEFAULT_PASSCODE 0
// Default GAP pairing mode
#define DEFAULT_PAIRING_MODE GAPBOND_PAIRING_MODE_INITIATE
// Default MITM mode (TRUE to require passcode or OOB when pairing)
#define DEFAULT_MITM_MODE FALSE
// Default bonding mode, TRUE to bond
#define DEFAULT_BONDING_MODE TRUE
// Default GAP bonding I/O capabilities
#define DEFAULT_IO_CAPABILITIES GAPBOND_IO_CAP_NO_INPUT_NO_OUTPUT
// Battery level is critical when it is less than this %
#define DEFAULT_BATT_CRITICAL_LEVEL 6
// Task configuration
#define HIDEMUKBD_TASK_PRIORITY 1
#ifndef HIDEMUKBD_TASK_STACK_SIZE
#define HIDEMUKBD_TASK_STACK_SIZE 644
#endif
// Task Events
#define HIDEMUKBD_KEY_CHANGE_EVT 0x0001
/*********************************************************************
* TYPEDEFS
*/
// App event passed from profiles.
typedef struct
{
appEvtHdr_t hdr; // Event header
} hidEmuKbdEvt_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
// Display Interface
Display_Handle dispHandle = NULL;
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
// Entity ID globally used to check for source and/or destination of messages
static ICall_EntityID selfEntity;
// Semaphore globally used to post events to the application thread
static ICall_Semaphore sem;
// Queue object used for app messages
static Queue_Struct appMsg;
static Queue_Handle appMsgQueue;
// Task configuration
Task_Struct hidEmuKbdTask;
Char hidEmuKbdTaskStack[HIDEMUKBD_TASK_STACK_SIZE];
// GAP Profile - Name attribute for SCAN RSP data
static uint8_t scanData[] =
{
0x0E, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE, // AD Type = Complete local name
'H',
'I',
'D',
' ',
'L',
'a',
'u',
'n',
'c',
'h',
'p',
'a',
'd'
};
// Advertising data
static uint8_t advData[] =
{
// flags
0x02, // length of this data
GAP_ADTYPE_FLAGS,
GAP_ADTYPE_FLAGS_LIMITED | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// appearance
0x03, // length of this data
GAP_ADTYPE_APPEARANCE,
LO_UINT16(GAP_APPEARE_HID_KEYBOARD),
HI_UINT16(GAP_APPEARE_HID_KEYBOARD),
// service UUIDs
0x05, // length of this data
GAP_ADTYPE_16BIT_MORE,
LO_UINT16(HID_SERV_UUID),
HI_UINT16(HID_SERV_UUID),
LO_UINT16(BATT_SERV_UUID),
HI_UINT16(BATT_SERV_UUID)
};
// Device name attribute value
static CONST uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "HID Launchpad";
// HID Dev configuration
static hidDevCfg_t hidEmuKbdCfg =
{
DEFAULT_HID_IDLE_TIMEOUT, // Idle timeout
HID_KBD_FLAGS // HID feature flags
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
// Application task and event processing.
static void HidEmuKbd_init(void);
static void HidEmuKbd_taskFxn(UArg a0, UArg a1);
static void HidEmuKbd_processAppMsg(hidEmuKbdEvt_t *pMsg);
static void HidEmuKbd_processStackMsg(ICall_Hdr *pMsg);
static void HidEmuKbd_processGattMsg(gattMsgEvent_t *pMsg);
static uint8_t HidEmuKbd_enqueueMsg(uint16_t event, uint8_t state);
// Key press.
static void HidEmuKbd_keyPressHandler(uint8_t keys);
static void HidEmuKbd_handleKeys(uint8_t shift, uint8_t keys);
// HID reports.
static void HidEmuKbd_sendReport(uint8_t keycode);
static uint8_t HidEmuKbd_receiveReport(uint8_t len, uint8_t *pData);
static uint8_t HidEmuKbd_reportCB(uint8_t id, uint8_t type, uint16_t uuid,
uint8_t oper, uint16_t *pLen, uint8_t *pData);
static void HidEmuKbd_hidEventCB(uint8_t evt);
/*********************************************************************
* PROFILE CALLBACKS
*/
static hidDevCB_t hidEmuKbdHidCBs =
{
HidEmuKbd_reportCB,
HidEmuKbd_hidEventCB,
NULL
};
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn HidEmuKbd_createTask
*
* @brief Task creation function for the HID emulated keyboard.
*
* @param none
*
* @return none
*/
void HidEmuKbd_createTask(void)
{
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = hidEmuKbdTaskStack;
taskParams.stackSize = HIDEMUKBD_TASK_STACK_SIZE;
taskParams.priority = HIDEMUKBD_TASK_PRIORITY;
Task_construct(&hidEmuKbdTask, HidEmuKbd_taskFxn, &taskParams, NULL);
}
/*********************************************************************
* @fn HidEmuKbd_init
*
* @brief Initialization function for the HidEmuKbd App Task.
* This is called during initialization and should contain
* any application specific initialization (ie. hardware
* initialization/setup, table initialization, power up
* notification ...).
*
* @param none
*
* @return none
*/
void HidEmuKbd_init(void)
{
// ******************************************************************
// N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
// ******************************************************************
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntity, &sem);
// Hard code the DB Address till CC2650 board gets its own IEEE address
//uint8 bdAddress[B_ADDR_LEN] = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x5A };
//HCI_EXT_SetBDADDRCmd(bdAddress);
// Set device's Sleep Clock Accuracy
//HCI_EXT_SetSCACmd(40);
// Create an RTOS queue for message from profile to be sent to app.
appMsgQueue = Util_constructQueue(&appMsg);
// Setup the GAP
VOID GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL,
DEFAULT_CONN_PAUSE_PERIPHERAL);
// Setup the GAP Peripheral Role Profile
{
uint8_t initial_advertising_enable = TRUE;
// By setting this to zero, the device will go into the waiting state after
// being discoverable for 30.72 second, and will not being advertising again
// until the enabler is set back to TRUE
uint16_t gapRole_AdvertOffTime = 0;
uint8_t enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
uint16_t desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
uint16_t desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
uint16_t desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
uint16_t desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;
// Set the GAP Role Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initial_advertising_enable);
GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),
&gapRole_AdvertOffTime);
GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advData), advData);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanData), scanData);
GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t),
&enable_update_request);
GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t),
&desired_min_interval);
GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t),
&desired_max_interval);
GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t),
&desired_slave_latency);
GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t),
&desired_conn_timeout);
}
// Set the GAP Characteristics
GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN,
(void *)attDeviceName);
// Setup the GAP Bond Manager
{
uint32_t passkey = DEFAULT_PASSCODE;
uint8_t pairMode = DEFAULT_PAIRING_MODE;
uint8_t mitm = DEFAULT_MITM_MODE;
uint8_t ioCap = DEFAULT_IO_CAPABILITIES;
uint8_t bonding = DEFAULT_BONDING_MODE;
GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),
&passkey);
GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
}
// Setup Battery Characteristic Values
{
uint8_t critical = DEFAULT_BATT_CRITICAL_LEVEL;
Batt_SetParameter(BATT_PARAM_CRITICAL_LEVEL, sizeof (uint8_t), &critical);
}
// Set up HID keyboard service
HidKbd_AddService();
// Register for HID Dev callback
HidDev_Register(&hidEmuKbdCfg, &hidEmuKbdHidCBs);
// Start the GAP Role and Register the Bond Manager.
HidDev_StartDevice();
Board_initKeys(HidEmuKbd_keyPressHandler);
}
/*********************************************************************
* @fn HidEmuKbd_taskFxn
*
* @brief HidEmuKbd Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param a0, a1 - not used.
*
* @return none
*/
void HidEmuKbd_taskFxn(UArg a0, UArg a1)
{
// Initialize the application.
HidEmuKbd_init();
// Application main loop.
for (;;)
{
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
// ICall_signal() function is called onto the semaphore.
ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
if (errno == ICALL_ERRNO_SUCCESS)
{
ICall_EntityID dest;
ICall_ServiceEnum src;
ICall_HciExtEvt *pMsg = NULL;
if (ICall_fetchServiceMsg(&src, &dest,
(void **)&pMsg) == ICALL_ERRNO_SUCCESS)
{
if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
{
// Process inter-task message
HidEmuKbd_processStackMsg((ICall_Hdr *)pMsg);
}
if (pMsg)
{
ICall_freeMsg(pMsg);
}
}
// If RTOS queue is not empty, process app message.
while (!Queue_empty(appMsgQueue))
{
hidEmuKbdEvt_t *pMsg = (hidEmuKbdEvt_t *)Util_dequeueMsg(appMsgQueue);
if (pMsg)
{
// Process message.
HidEmuKbd_processAppMsg(pMsg);
// Free the space from the message.
ICall_free(pMsg);
}
}
}
}
}
/*********************************************************************
* @fn HidEmuKbd_processStackMsg
*
* @brief Process an incoming stack message.
*
* @param pMsg - message to process
*
* @return none
*/
static void HidEmuKbd_processStackMsg(ICall_Hdr *pMsg)
{
switch (pMsg->event)
{
case GATT_MSG_EVENT:
HidEmuKbd_processGattMsg((gattMsgEvent_t *) pMsg);
break;
default:
// Do nothing
break;
}
}
/*********************************************************************
* @fn HidEmuKbd_processGattMsg
*
* @brief Process GATT messages
*
* @return none
*/
static void HidEmuKbd_processGattMsg(gattMsgEvent_t *pMsg)
{
GATT_bm_free(&pMsg->msg, pMsg->method);
}
/*********************************************************************
* @fn HidEmuKbd_processAppMsg
*
* @brief Process an incoming task message.
*
* @param pMsg - message to process
*
* @return none
*/
static void HidEmuKbd_processAppMsg(hidEmuKbdEvt_t *pMsg)
{
switch (pMsg->hdr.event)
{
case HIDEMUKBD_KEY_CHANGE_EVT:
HidEmuKbd_handleKeys(0, pMsg->hdr.state);
break;
default:
//Do nothing.
break;
}
}
/*********************************************************************
* @fn HidKEmukbd_keyPressHandler
*
* @brief Key event handler function.
*
* @param a0 - ignored
*
* @return none
*/
static void HidEmuKbd_keyPressHandler(uint8_t keys)
{
// Enqueue the event.
HidEmuKbd_enqueueMsg(HIDEMUKBD_KEY_CHANGE_EVT, keys);
}
/*********************************************************************
* @fn HidEmuKbd_handleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* KEY_LEFT
* KEY_RIGHT
*
* @return none
*/
static void HidEmuKbd_handleKeys(uint8_t shift, uint8_t keys)
{
(void)shift; // Intentionally unreferenced parameter
if (keys & KEY_LEFT)
{
// Key Press.
HidEmuKbd_sendReport(HID_KEYBOARD_LEFT_ARROW);
// Key Release.
// NB: releasing a key press will not propagate a signal to this function,
// so a "key release" is reported immediately afterwards here.
HidEmuKbd_sendReport(KEY_NONE);
}
if (keys & KEY_RIGHT)
{
// Key Press.
HidEmuKbd_sendReport(HID_KEYBOARD_RIGHT_ARROW);
// Key Release
// NB: releasing a key press will not propagate a signal to this function,
// so a "key release" is reported immediately afterwards here.
HidEmuKbd_sendReport(KEY_NONE);
}
}
/*********************************************************************
* @fn HidEmuKbd_sendReport
*
* @brief Build and send a HID keyboard report.
*
* @param keycode - HID keycode.
*
* @return none
*/
static void HidEmuKbd_sendReport(uint8_t keycode)
{
uint8_t buf[HID_KEYBOARD_IN_RPT_LEN];
buf[0] = 0; // Modifier keys
buf[1] = 0; // Reserved
buf[2] = keycode; // Keycode 1
buf[3] = 0; // Keycode 2
buf[4] = 0; // Keycode 3
buf[5] = 0; // Keycode 4
buf[6] = 0; // Keycode 5
buf[7] = 0; // Keycode 6
HidDev_Report(HID_RPT_ID_KEY_IN, HID_REPORT_TYPE_INPUT,
HID_KEYBOARD_IN_RPT_LEN, buf);
}
/*********************************************************************
* @fn HidEmuKbd_receiveReport
*
* @brief Process an incoming HID keyboard report.
*
* @param len - Length of report.
* @param pData - Report data.
*
* @return status
*/
static uint8_t HidEmuKbd_receiveReport(uint8_t len, uint8_t *pData)
{
// Verify data length
if (len == HID_LED_OUT_RPT_LEN)
{
return SUCCESS;
}
else
{
return ATT_ERR_INVALID_VALUE_SIZE;
}
}
/*********************************************************************
* @fn HidEmuKbd_reportCB
*
* @brief HID Dev report callback.
*
* @param id - HID report ID.
* @param type - HID report type.
* @param uuid - attribute uuid.
* @param oper - operation: read, write, etc.
* @param len - Length of report.
* @param pData - Report data.
*
* @return GATT status code.
*/
static uint8_t HidEmuKbd_reportCB(uint8_t id, uint8_t type, uint16_t uuid,
uint8_t oper, uint16_t *pLen, uint8_t *pData)
{
uint8_t status = SUCCESS;
// Write
if (oper == HID_DEV_OPER_WRITE)
{
if (uuid == REPORT_UUID)
{
// Process write to LED output report; ignore others
if (type == HID_REPORT_TYPE_OUTPUT)
{
status = HidEmuKbd_receiveReport(*pLen, pData);
}
}
if (status == SUCCESS)
{
status = HidKbd_SetParameter(id, type, uuid, *pLen, pData);
}
}
// Read
else if (oper == HID_DEV_OPER_READ)
{
uint8_t len;
status = HidKbd_GetParameter(id, type, uuid, &len, pData);
if (status == SUCCESS)
{
*pLen = len;
}
}
return status;
}
/*********************************************************************
* @fn HidEmuKbd_hidEventCB
*
* @brief HID Dev event callback.
*
* @param evt - event ID.
*
* @return HID response code.
*/
static void HidEmuKbd_hidEventCB(uint8_t evt)
{
// Process enter/exit suspend or enter/exit boot mode
return;
}
/*********************************************************************
* @fn HidEmuKbd_enqueueMsg
*
* @brief Creates a message and puts the message in RTOS queue.
*
* @param event - message event.
* @param state - message state.
*
* @return TRUE or FALSE
*/
static uint8_t HidEmuKbd_enqueueMsg(uint16_t event, uint8_t state)
{
hidEmuKbdEvt_t *pMsg;
// Create dynamic pointer to message.
if (pMsg = ICall_malloc(sizeof(hidEmuKbdEvt_t)))
{
pMsg->hdr.event = event;
pMsg->hdr.state = state;
// Enqueue the message.
return Util_enqueueMsg(appMsgQueue, sem, (uint8_t *)pMsg);
}
return FALSE;
}
/*********************************************************************
*********************************************************************/
@@ -0,0 +1,85 @@
/******************************************************************************
@file hidemukbd.h
@brief This file contains the HID emulated keyboard sample application
definitions and prototypes.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
Copyright (c) 2011-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.
*****************************************************************************/
#ifndef HIDEMUKBD_H
#define HIDEMUKBD_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
/*
* Task creation function for the HID emulated keyboard.
*/
extern void HidEmuKbd_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /*HIDEMUKBD_H */
File diff suppressed because it is too large Load Diff
@@ -9,7 +9,7 @@
Target Device: CC2650, CC2640
******************************************************************************
Copyright (c) 2013-2018, Texas Instruments Incorporated
All rights reserved.
@@ -49,37 +49,16 @@
#define HOSTESTAPP_H
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Task creation function for the Host Test App.
*/
extern void HostTestApp_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* HOSTESTAPP_H */
#endif
@@ -8,7 +8,7 @@
Target Device: CC2650, CC2640
******************************************************************************
Copyright (c) 2013-2018, Texas Instruments Incorporated
All rights reserved.
@@ -44,26 +44,29 @@
Release Date: 2018-04-02 18:03:35
*****************************************************************************/
/*******************************************************************************
* INCLUDES
*/
#include <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "hal_assert.h"
#include "board.h"
#include "hal_assert.h"
#include "icall.h"
#include "inc/npi_task.h"
#include "host_test_app.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#include <inc/hw_memmap.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
@@ -71,70 +74,12 @@
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
#endif // USE_DEFAULT_USER_CFG
#include <ti/mw/display/Display.h>
#ifdef USE_FPGA
#include <inc/hw_prcm.h>
#endif // USE_FPGA
/*******************************************************************************
* MACROS
*/
/*******************************************************************************
* CONSTANTS
*/
#if defined( USE_FPGA )
#define RFC_MODE_BLE PRCM_RFCMODESEL_CURR_MODE1
#define RFC_MODE_ANT PRCM_RFCMODESEL_CURR_MODE4
#define RFC_MODE_EVERYTHING_BUT_ANT PRCM_RFCMODESEL_CURR_MODE5
#define RFC_MODE_EVERYTHING PRCM_RFCMODESEL_CURR_MODE6
//
#define SET_RFC_BLE_MODE(mode) HWREG( PRCM_BASE + PRCM_O_RFCMODESEL ) = (mode)
#endif // USE_FPGA
/*******************************************************************************
* TYPEDEFS
*/
/*******************************************************************************
* LOCAL VARIABLES
*/
/*******************************************************************************
* GLOBAL VARIABLES
*/
#ifdef CC1350_LAUNCHXL
#ifdef POWER_SAVING
// Power Notify Object for wake-up callbacks
Power_NotifyObj rFSwitchPowerNotifyObj;
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
uint32_t *clientArg);
#endif //POWER_SAVING
PIN_State radCtrlState;
PIN_Config radCtrlCfg[] =
{
Board_DIO1_RFSW | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4GHz path*/
Board_DIO30_SWPWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Power to the RF Switch */
PIN_TERMINATE
};
PIN_Handle radCtrlHandle;
#endif //CC1350_LAUNCHXL
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
extern Display_Handle dispHandle;
/*******************************************************************************
/*
* @fn Main
*
* @brief Application Main
@@ -149,68 +94,38 @@ extern Display_Handle dispHandle;
*
* @return None.
*/
int main()
{
#if defined( USE_FPGA )
HWREG(PRCM_BASE + PRCM_O_PDCTL0) &= ~PRCM_PDCTL0_RFC_ON;
HWREG(PRCM_BASE + PRCM_O_PDCTL1) &= ~PRCM_PDCTL1_RFC_ON;
#endif // USE_FPGA
int main() {
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
PIN_init(BoardGpioInitTable);
#ifdef CC1350_LAUNCHXL
// Enable 2.4GHz Radio
radCtrlHandle = PIN_open(&radCtrlState, radCtrlCfg);
// Enable iCache prefetching
VIMSConfigure(VIMS_BASE, TRUE, TRUE);
#ifdef POWER_SAVING
Power_registerNotify(&rFSwitchPowerNotifyObj,
PowerCC26XX_ENTERING_STANDBY | PowerCC26XX_AWAKE_STANDBY,
(Power_NotifyFxn) rFSwitchNotifyCb, NULL);
#endif //POWER_SAVING
#endif //CC1350_LAUNCHXL
// Enable cache
VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
#if defined( USE_FPGA )
// set RFC mode to support BLE
// Note: This must be done before the RF Core is released from reset!
SET_RFC_BLE_MODE(RFC_MODE_BLE);
#endif // USE_FPGA
/* Initialize ICall module */
ICall_init();
// Enable iCache prefetching
VIMSConfigure(VIMS_BASE, TRUE, TRUE);
/* Start tasks of external images */
ICall_createRemoteTasks();
// Enable cache
VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
/* Kick off application */
HostTestApp_createTask();
#if !defined( POWER_SAVING ) || defined( USE_FPGA )
/* Set constraints for Standby, powerdown and idle mode */
// PowerCC26XX_SB_DISALLOW may be redundant
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif // POWER_SAVING | USE_FPGA
/* Kick off NPI */
NPITask_createTask(ICALL_SERVICE_CLASS_BLE);
/* Initialize ICall module */
ICall_init();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
/* Start tasks of external images */
ICall_createRemoteTasks();
/* Kick off application */
HostTestApp_createTask();
/* Kick off NPI */
NPITask_createTask(ICALL_SERVICE_CLASS_BLE);
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
return 0;
}
/*******************************************************************************
/*
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
@@ -246,57 +161,9 @@ int main()
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
// Open the display if the app has not already done so
if ( !dispHandle )
{
dispHandle = Display_open(Display_Type_LCD, NULL);
}
void AssertHandler(uint8 assertCause, uint8 assertSubcause) {}
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// check the assert cause
switch (assertCause)
{
// This assert is raised from the BLE Stack when a malloc failure occurs.
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
}
else
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
}
break;
// An assert originating from an ICall failure.
case HAL_ASSERT_CAUSE_ICALL_ABORT:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
HAL_ASSERT_SPINLOCK;
break;
default:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
HAL_ASSERT_SPINLOCK;
}
return;
}
/*******************************************************************************
/*
* @fn exceptionHandler
*
* @brief Generic spinlock to trap RTOS raised errors.
@@ -311,13 +178,11 @@ void AssertHandler(uint8 assertCause, uint8 assertSubcause)
*
* @return None.
*/
void exceptionHandler( void )
{
volatile uint8 i = 1;
while(i);
void exceptionHandler(void) {
for (;;);
}
/*******************************************************************************
/*
* @fn smallErrorHook
*
* @brief Error handler to be hooked into TI-RTOS.
@@ -332,45 +197,6 @@ void exceptionHandler( void )
*
* @return None.
*/
void smallErrorHook(Error_Block *eb)
{
for (;;);
void smallErrorHook(Error_Block *eb) {
for (;;);
}
#if defined (CC1350_LAUNCHXL) && defined (POWER_SAVING)
/*******************************************************************************
* @fn rFSwitchNotifyCb
*
* @brief Power driver callback to toggle RF switch on Power state
* transitions.
*
* input parameters
*
* @param eventType - The state change.
* @param eventArg - Not used.
* @param clientArg - Not used.
*
* @return Power_NOTIFYDONE to indicate success.
*/
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
uint32_t *clientArg)
{
if (eventType == PowerCC26XX_ENTERING_STANDBY)
{
// Power down RF Switch
PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 0);
}
else if (eventType == PowerCC26XX_AWAKE_STANDBY)
{
// Power up RF Switch
PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 1);
}
// Notification handled successfully
return Power_NOTIFYDONE;
}
#endif //CC1350_LAUNCHXL || POWER_SAVING
/*******************************************************************************
*/
@@ -0,0 +1,429 @@
/*
* Filename: board.c
*
* This file is responsible for setting up the board specific items for the
* SRF06EB with the CC2650EM_7ID board.
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/*
* ====================== Includes ============================================
*/
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <inc/hw_memmap.h>
#include <inc/hw_ints.h>
#include <driverlib/ioc.h>
#include <driverlib/udma.h>
#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
const PIN_Config BoardGpioInitTable[] = {
Board_DK_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_DK_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_DK_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_DK_LED4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
Board_KEY_SELECT | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* Button is active low */
Board_KEY_UP | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* Button is active low */
Board_KEY_DOWN | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* Button is active low */
Board_KEY_LEFT | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* Button is active low */
Board_KEY_RIGHT | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* Button is active low */
Board_3V3_EN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, /* 3V3 domain off initially */
Board_LCD_MODE | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* LCD pin high initially */
Board_LCD_RST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* LCD pin high initially */
Board_LCD_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* LCD CSn deasserted initially */
Board_ALS_PWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, /* ALS power off initially */
Board_ACC_PWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, /* ACC power off initially */
Board_ACC_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* ACC CSn deasserted initially */
Board_SDCARD_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* SDCARD CSn deasserted initially */
Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX pin at inactive level */
PIN_TERMINATE /* Terminate list */
};
const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = {
.intPriority = ~0,
.swiPriority = 0
};
/*============================================================================*/
/*
* ============================= Power begin ===================================
*/
const PowerCC26XX_Config PowerCC26XX_config = {
.policyInitFxn = NULL,
.policyFxn = &PowerCC26XX_standbyPolicy,
.calibrateFxn = &PowerCC26XX_calibrate,
.enablePolicy = TRUE,
.calibrateRCOSC_LF = TRUE,
.calibrateRCOSC_HF = TRUE,
};
/*
* ============================= Power end ===================================
*/
/*
* ============================= UART begin ===================================
*/
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(UART_config, ".const:UART_config")
#pragma DATA_SECTION(uartCC26XXHWAttrs, ".const:uartCC26XXHWAttrs")
#endif
/* Include drivers */
#include <ti/drivers/UART.h>
#include <ti/drivers/uart/UARTCC26XX.h>
/* UART objects */
UARTCC26XX_Object uartCC26XXObjects[CC2650DK_7ID_UARTCOUNT];
/* UART hardware parameter structure, also used to assign UART pins */
const UARTCC26XX_HWAttrsV1 uartCC26XXHWAttrs[CC2650DK_7ID_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
}
};
/* UART configuration structure */
const UART_Config UART_config[] = {
{
.fxnTablePtr = &UARTCC26XX_fxnTable,
.object = &uartCC26XXObjects[0],
.hwAttrs = &uartCC26XXHWAttrs[0]
},
{NULL, NULL, NULL}
};
/*
* ============================= UART end =====================================
*/
/*
* ============================= UDMA begin ===================================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(UDMACC26XX_config, ".const:UDMACC26XX_config")
#pragma DATA_SECTION(udmaHWAttrs, ".const:udmaHWAttrs")
#endif
/* Include drivers */
#include <ti/drivers/dma/UDMACC26XX.h>
/* UDMA objects */
UDMACC26XX_Object udmaObjects[CC2650DK_7ID_UDMACOUNT];
/* UDMA configuration structure */
const UDMACC26XX_HWAttrs udmaHWAttrs[CC2650DK_7ID_UDMACOUNT] = {
{
.baseAddr = UDMA0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_UDMA,
.intNum = INT_DMA_ERR,
.intPriority = ~0
}
};
/* UDMA configuration structure */
const UDMACC26XX_Config UDMACC26XX_config[] = {
{
.object = &udmaObjects[0],
.hwAttrs = &udmaHWAttrs[0]
},
{NULL, NULL}
};
/*
* ============================= UDMA end =====================================
*/
/*
* ========================== 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
/* Include drivers */
#include <ti/drivers/spi/SPICC26XXDMA.h>
/* SPI objects */
#if defined(__IAR_SYSTEMS_ICC__)
#ifdef CACHE_AS_RAM
#pragma location = ".gpram"
#endif //CACHE_AS_RAM
#elif defined(__TI_COMPILER_VERSION__)
//todo
#endif //compiler version
SPICC26XXDMA_Object spiCC26XXDMAObjects[CC2650DK_7ID_SPICOUNT];
/* SPI configuration structure, describing which pins are to be used */
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC2650DK_7ID_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 = Board_SPI0_CSN
},
{
.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_CSN
}
};
/* 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 DMA end =====================================
*/
/*
* ========================== LCD begin =======================================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(LCD_config, ".const:LCD_config")
#pragma DATA_SECTION(lcdHWAttrs, ".const:lcdHWAttrs")
#endif
/* Include lcd middleware */
#include <ti/mw/lcd/LCDDogm1286.h>
/* LCD object */
LCD_Object lcdObject;
/* LCD hardware attribute structure */
const LCD_HWAttrs lcdHWAttrs = {
.LCD_initCmd = &LCD_initCmd,
.lcdResetPin = Board_LCD_RST, /* LCD reset pin */
.lcdModePin = Board_LCD_MODE, /* LCD mode pin */
.lcdCsnPin = Board_LCD_CSN, /* LCD CSn pin */
.spiIndex = Board_SPI0
};
/* LCD configuration structure */
const LCD_Config LCD_config = {
.object = &lcdObject,
.hwAttrs = &lcdHWAttrs
};
/*
* ========================== LCD end =========================================
*/
/*
* ========================== Crypto begin ====================================
* NOTE: The Crypto implementation should be considered experimental
* and not validated!
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(CryptoCC26XX_config, ".const:CryptoCC26XX_config")
#pragma DATA_SECTION(cryptoCC26XXHWAttrs, ".const:cryptoCC26XXHWAttrs")
#endif
/* Include drivers */
#include <ti/drivers/crypto/CryptoCC26XX.h>
/* Crypto objects */
CryptoCC26XX_Object cryptoCC26XXObjects[CC2650DK_7ID_CRYPTOCOUNT];
/* Crypto configuration structure, describing which pins are to be used */
const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC2650DK_7ID_CRYPTOCOUNT] = {
{
.baseAddr = CRYPTO_BASE,
.powerMngrId = PowerCC26XX_PERIPH_CRYPTO,
.intNum = INT_CRYPTO_RESULT_AVAIL_IRQ,
.intPriority = ~0,
}
};
/* Crypto configuration structure */
const CryptoCC26XX_Config CryptoCC26XX_config[] = {
{
.object = &cryptoCC26XXObjects[0],
.hwAttrs = &cryptoCC26XXHWAttrs[0]
},
{NULL, NULL}
};
/*
* ========================== Crypto end =========================================
*/
/*
* ========================= RF driver begin ==============================================
*/
/* Include drivers */
#include <ti/drivers/rf/RF.h>
/* RF hwi and swi priority */
const RFCC26XX_HWAttrs RFCC26XX_hwAttrs = {
.hwiCpe0Priority = ~0,
.hwiHwPriority = ~0,
.swiCpe0Priority = 5,
.swiHwPriority = 5,
};
/*
* ========================== RF driver 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(displayDogm1286HWattrs, ".const:displayDogm1286HWAttrs")
#pragma DATA_SECTION(displayUartHWAttrs, ".const:displayUartHWAttrs")
#endif
#include <ti/mw/display/Display.h>
#include <ti/mw/display/DisplayDogm1286.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 DOGM1286 */
#if defined(__IAR_SYSTEMS_ICC__)
#ifdef CACHE_AS_RAM
#pragma location = ".gpram"
#endif //CACHE_AS_RAM
#elif defined(__TI_COMPILER_VERSION__)
//todo
#endif //compiler version
DisplayDogm1286_Object displayDogm1286Object;
const DisplayDogm1286_HWAttrs displayDogm1286HWattrs = {
.lcdHandle = (LCD_Handle) & LCD_config,
.powerPin = Board_3V3_EN
};
/* 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 = &DisplayDogm1286_fxnTable,
.object = &displayDogm1286Object,
.hwAttrs = &displayDogm1286HWattrs
},
#endif
{ NULL, NULL, NULL } // Terminator
};
/*
* ========================= Display end ======================================
*/
@@ -0,0 +1,257 @@
/*
* Filename: main.c
*
* Description: main entry of the BLE stack sample application.
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/*******************************************************************************
* INCLUDES
*/
#include <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "hal_assert.h"
#include "multi.h"
#include "multi_role.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
#include <ti/mw/display/Display.h>
/*******************************************************************************
* MACROS
*/
/*******************************************************************************
* CONSTANTS
*/
/*******************************************************************************
* TYPEDEFS
*/
/*******************************************************************************
* LOCAL VARIABLES
*/
/*******************************************************************************
* GLOBAL VARIABLES
*/
void execHandlerHook(Hwi_ExcContext *ctx)
{
for(;;);
}
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
extern Display_Handle dispHandle;
/*******************************************************************************
* @fn Main
*
* @brief Application Main
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
int main()
{
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
#if !defined( POWER_SAVING )
/* Set constraints for Standby, powerdown and idle mode */
// PowerCC26XX_SB_DISALLOW may be redundant
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif // POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPRole_createTask();
/* Kick off application - Priority 1 */
multi_role_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
/*******************************************************************************
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
* in the stack. When EXT_HAL_ASSERT is defined in the Stack
* project this function will be called when an assert is raised,
* and can be used to observe or trap a violation from expected
* behavior.
*
* As an example, for Heap allocation failures the Stack will raise
* HAL_ASSERT_CAUSE_OUT_OF_MEMORY as the assertCause and
* HAL_ASSERT_SUBCAUSE_NONE as the assertSubcause. An application
* developer could trap any malloc failure on the stack by calling
* HAL_ASSERT_SPINLOCK under the matching case.
*
* An application developer is encouraged to extend this function
* for use by their own application. To do this, add hal_assert.c
* to your project workspace, the path to hal_assert.h (this can
* be found on the stack side). Asserts are raised by including
* hal_assert.h and using macro HAL_ASSERT(cause) to raise an
* assert with argument assertCause. the assertSubcause may be
* optionally set by macro HAL_ASSERT_SET_SUBCAUSE(subCause) prior
* to asserting the cause it describes. More information is
* available in hal_assert.h.
*
* input parameters
*
* @param assertCause - Assert cause as defined in hal_assert.h.
* @param assertSubcause - Optional assert subcause (see hal_assert.h).
*
* output parameters
*
* @param None.
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
// Open the display if the app has not already done so
if ( !dispHandle )
{
dispHandle = Display_open(Display_Type_LCD, NULL);
}
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
}
else
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
HAL_ASSERT_SPINLOCK;
break;
default:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
HAL_ASSERT_SPINLOCK;
}
return;
}
/*******************************************************************************
* @fn smallErrorHook
*
* @brief Error handler to be hooked into TI-RTOS.
*
* input parameters
*
* @param eb - Pointer to Error Block.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void smallErrorHook(Error_Block *eb)
{
for (;;);
}
/*******************************************************************************
*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,79 @@
/******************************************************************************
* @file simple_ble_topology.c
*
* @description Definitions and prototypes for the Simple Topology example
*
*
Copyright (c) 2013-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.
*
*****************************************************************************/
#ifndef SIMPLEBLETOPOLOGY_H
#define SIMPLEBLETOPOLOGY_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Task creation function for the Simple BLE Peripheral.
*/
extern void multi_role_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* SIMPLEBLETOPOLOGY_H */
@@ -0,0 +1,221 @@
/*
* Filename: osal_icall_ble.c
*
* Description: This file contains function that allows user setup tasks
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/**************************************************************************************************
* INCLUDES
**************************************************************************************************/
#include <icall.h>
#include "hal_types.h"
#include "hal_mcu.h"
#include "osal.h"
#include "osal_tasks.h"
#include "osal_snv.h"
/* LL */
#include "ll.h"
#if defined ( OSAL_CBTIMER_NUM_TASKS )
#include "osal_cbtimer.h"
#endif
/* L2CAP */
#include "l2cap.h"
/* gap */
#include "gap.h"
#if defined ( GAP_BOND_MGR )
#include "gapbondmgr.h"
#endif
/* GATT */
#include "gatt.h"
/* Application */
#include "hci_tl.h"
#include "gattservapp.h"
#include "ble_user_config.h"
#include "ble_dispatch.h"
/*********************************************************************
* GLOBAL VARIABLES
*/
// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] =
{
LL_ProcessEvent, // task 0
HCI_ProcessEvent, // task 1
#if defined ( OSAL_CBTIMER_NUM_TASKS )
OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ), // task 2
#endif
L2CAP_ProcessEvent, // task 3
GAP_ProcessEvent, // task 4
SM_ProcessEvent, // task 5
GATT_ProcessEvent, // task 6
GATTServApp_ProcessEvent, // task 7
#if defined ( GAP_BOND_MGR )
GAPBondMgr_ProcessEvent, // task 8
#endif
bleDispatch_ProcessEvent // task 9
};
const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;
/*********************************************************************
* FUNCTIONS
*********************************************************************/
/*********************************************************************
* @fn osalInitTasks
*
* @brief This function invokes the initialization function for each task.
*
* @param void
*
* @return none
*/
void osalInitTasks( void )
{
ICall_EntityID entity;
ICall_Semaphore sem;
uint8 taskID = 0;
uint8 i;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
/* LL Task */
LL_Init( taskID++ );
/* HCI Task */
HCI_Init( taskID++ );
#if defined ( OSAL_CBTIMER_NUM_TASKS )
/* Callback Timer Tasks */
osal_CbTimerInit( taskID );
taskID += OSAL_CBTIMER_NUM_TASKS;
#endif
/* L2CAP Task */
L2CAP_Init( taskID++ );
/* GAP Task */
GAP_Init( taskID++ );
/* SM Task */
SM_Init( taskID++ );
/* GATT Task */
GATT_Init( taskID++ );
/* GATT Server App Task */
GATTServApp_Init( taskID++ );
#if defined ( GAP_BOND_MGR )
/* Bond Manager Task */
GAPBondMgr_Init( taskID++ );
#endif
/* ICall BLE Dispatcher Task */
bleDispatch_Init( taskID );
// ICall enrollment
/* Enroll the service that this stack represents */
ICall_enrollService(ICALL_SERVICE_CLASS_BLE, NULL, &entity, &sem);
/* Enroll the obtained dispatcher entity and OSAL task ID of HCI Ext App
* to OSAL so that OSAL can route the dispatcher message into
* the appropriate OSAL task.
*/
osal_enroll_dispatchid(taskID, entity);
/* Register all other OSAL tasks to use the registered dispatcher entity
* ID as the source of dispatcher messages, even though the other OSAL
* tasks didn't register themselves to receive messages from application.
*/
for (i = 0; i < taskID; i++)
{
osal_enroll_senderid(i, entity);
}
}
/**
* Main entry function for the stack image
*/
int stack_main( void *arg )
{
/* User reconfiguration of BLE Controller and Host variables */
setBleUserConfig( (bleUserCfg_t *)arg );
/* Establish OSAL for a stack service that requires accompanying
* messaging service */
if (ICall_enrollService(ICALL_SERVICE_CLASS_BLE_MSG,
(ICall_ServiceFunc) osal_service_entry,
&osal_entity, &osal_semaphore) !=
ICALL_ERRNO_SUCCESS)
{
/* abort */
ICall_abort();
}
// Disable interrupts
halIntState_t state;
HAL_ENTER_CRITICAL_SECTION(state);
// Initialize NV System
osal_snv_init( );
// Initialize the operating system
osal_init_system();
// Allow interrupts
HAL_EXIT_CRITICAL_SECTION(state);
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
}
/*********************************************************************
*********************************************************************/
@@ -0,0 +1,181 @@
/**
@file main.c
@brief main entry of the BLE stack sample application.
Copyright (c) 2013-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 <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "hal_assert.h"
#include "central.h"
#include "security_examples_central.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
#if defined( TI_DRIVERS_DISPLAY_INCLUDED )
#include "board_display.h"
#endif // TI_DRIVERS_DISPLAY_INCLUDED
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
/*
* ======== main ========
*/
int main()
{
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(Power_SB_DISALLOW);
Power_setConstraint(Power_IDLE_PD_DISALLOW);
#endif //POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPCentralRole_createTask();
/* Kick off application - Priority 1 */
security_examples_central_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
/**
* Error handled to be hooked into TI-RTOS
*/
Void smallErrorHook(Error_Block *eb)
{
for (;;);
}
/*******************************************************************************
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
* in the stack.
*
* input parameters
*
* @param assertCause - Assert cause as defined in hal_assert.h.
* @param assertSubcause - Optional assert subcause (see hal_assert.h).
*
* output parameters
*
* @param None.
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_openDisplay(BOARD_DISPLAY_TYPE_LCD);
Board_writeString(">>>STACK ASSERT", 0);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> OUT OF MEMORY!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> INTERNAL FW ERROR!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
}
else
{
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> INTERNAL ERROR!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> ICALL ABORT!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
HAL_ASSERT_SPINLOCK;
break;
default:
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> DEFAULT SPINLOCK!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
HAL_ASSERT_SPINLOCK;
}
return;
}
@@ -0,0 +1,100 @@
/**************************************************************************************************
Filename: security_examples_central.h
Revised: $Date$
Revision: $Revision$
Description: This file contains the security examples central sample application
definitions and prototypes.
Copyright (c) 2013-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.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
#ifndef SECURITY_EXAMPLES_CENTRAL_H
#define SECURITY_EXAMPLES_CENTRAL_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* CONSTANTS
*/
#define OOB_LE 0x01 // out of band legacy
#define OOB_SC 0x02 // out of band secure connections
#define JUSTWORKS 0x03 // just works
#define PASSCODE 0x04 // passcode
#define NUMCOMP 0x05 // numeric comparison
#define PAIRING JUSTWORKS
#define STATIC_PASSCODE 0x01
#define STATIC_KEYS 0x01
#if !defined( PAIRING )
#warning No Pairing mode selected!
#elif (PAIRING > NUMCOMP) || (PAIRING == 0)
#warning Invalid pairing mode!
#endif
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Task creation function for the security examples central.
*/
extern void security_examples_central_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* SECURITY_EXAMPLES_CENTRAL_H */
@@ -0,0 +1,227 @@
/******************************************************************************
@file osal_icall_ble.c
@brief This file contains function that allows user setup tasks
Group: WCS, BTS
$Target Device: DEVICES $
******************************************************************************
Copyright (c) 2013-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.
*****************************************************************************/
/**************************************************************************************************
* INCLUDES
**************************************************************************************************/
#include <icall.h>
#include "hal_types.h"
#include "hal_mcu.h"
#include "osal.h"
#include "osal_tasks.h"
#include "osal_snv.h"
/* LL */
#include "ll.h"
#if defined ( OSAL_CBTIMER_NUM_TASKS )
#include "osal_cbtimer.h"
#endif
/* L2CAP */
#include "l2cap.h"
/* gap */
#include "gap.h"
#if defined ( GAP_BOND_MGR )
#include "gapbondmgr.h"
#endif
/* GATT */
#include "gatt.h"
/* Application */
#include "hci_tl.h"
#include "gattservapp.h"
#include "ble_user_config.h"
#include "ble_dispatch.h"
/*********************************************************************
* GLOBAL VARIABLES
*/
// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] =
{
LL_ProcessEvent, // task 0
HCI_ProcessEvent, // task 1
#if defined ( OSAL_CBTIMER_NUM_TASKS )
OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ), // task 2
#endif
L2CAP_ProcessEvent, // task 3
GAP_ProcessEvent, // task 4
SM_ProcessEvent, // task 5
GATT_ProcessEvent, // task 6
GATTServApp_ProcessEvent, // task 7
#if defined ( GAP_BOND_MGR )
GAPBondMgr_ProcessEvent, // task 8
#endif
bleDispatch_ProcessEvent // task 9
};
const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;
/*********************************************************************
* FUNCTIONS
*********************************************************************/
/*********************************************************************
* @fn osalInitTasks
*
* @brief This function invokes the initialization function for each task.
*
* @param void
*
* @return none
*/
void osalInitTasks( void )
{
ICall_EntityID entity;
ICall_Semaphore sem;
uint8 taskID = 0;
uint8 i;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
/* LL Task */
LL_Init( taskID++ );
/* HCI Task */
HCI_Init( taskID++ );
#if defined ( OSAL_CBTIMER_NUM_TASKS )
/* Callback Timer Tasks */
osal_CbTimerInit( taskID );
taskID += OSAL_CBTIMER_NUM_TASKS;
#endif
/* L2CAP Task */
L2CAP_Init( taskID++ );
/* GAP Task */
GAP_Init( taskID++ );
/* SM Task */
SM_Init( taskID++ );
/* GATT Task */
GATT_Init( taskID++ );
/* GATT Server App Task */
GATTServApp_Init( taskID++ );
#if defined ( GAP_BOND_MGR )
/* Bond Manager Task */
GAPBondMgr_Init( taskID++ );
#endif
/* ICall BLE Dispatcher Task */
bleDispatch_Init( taskID );
// ICall enrollment
/* Enroll the service that this stack represents */
ICall_enrollService(ICALL_SERVICE_CLASS_BLE, NULL, &entity, &sem);
/* Enroll the obtained dispatcher entity and OSAL task ID of HCI Ext App
* to OSAL so that OSAL can route the dispatcher message into
* the appropriate OSAL task.
*/
osal_enroll_dispatchid(taskID, entity);
/* Register all other OSAL tasks to use the registered dispatcher entity
* ID as the source of dispatcher messages, even though the other OSAL
* tasks didn't register themselves to receive messages from application.
*/
for (i = 0; i < taskID; i++)
{
osal_enroll_senderid(i, entity);
}
}
/**
* Main entry function for the stack image
*/
int stack_main( void *arg )
{
/* User reconfiguration of BLE Controller and Host variables */
setBleUserConfig( (bleUserCfg_t *)arg );
/* Establish OSAL for a stack service that requires accompanying
* messaging service */
if (ICall_enrollService(ICALL_SERVICE_CLASS_BLE_MSG,
(ICall_ServiceFunc) osal_service_entry,
&osal_entity, &osal_semaphore) !=
ICALL_ERRNO_SUCCESS)
{
/* abort */
ICall_abort();
}
halIntState_t state;
HAL_ENTER_CRITICAL_SECTION(state);
// Turn off interrupts
//osal_int_disable( INTS_ALL );
// Initialize NV System
osal_snv_init( );
// Initialize the operating system
osal_init_system();
// Allow interrupts
//osal_int_enable( INTS_ALL );
HAL_EXIT_CRITICAL_SECTION(state);
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
}
/*********************************************************************
*********************************************************************/
@@ -0,0 +1,179 @@
/**
@file main.c
@brief main entry of the BLE stack sample application.
Copyright (c) 2013-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 <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "bcomdef.h"
#include "peripheral.h"
#include "security_examples_peripheral.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
#if defined( TI_DRIVERS_DISPLAY_INCLUDED )
#include "board_display.h"
#endif // TI_DRIVERS_DISPLAY_INCLUDED
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
/*
* ======== main ========
*/
int main()
{
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(Power_SB_DISALLOW);
Power_setConstraint(Power_IDLE_PD_DISALLOW);
#endif // POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPRole_createTask();
security_examples_peripheral_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
/**
* Error handled to be hooked into TI-RTOS
*/
Void smallErrorHook(Error_Block *eb)
{
for (;;);
}
/*******************************************************************************
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
* in the stack.
*
* input parameters
*
* @param assertCause - Assert cause as defined in hal_assert.h.
* @param assertSubcause - Optional assert subcause (see hal_assert.h).
*
* output parameters
*
* @param None.
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_openDisplay(BOARD_DISPLAY_TYPE_LCD);
Board_writeString(">>>STACK ASSERT", 0);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> OUT OF MEMORY!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> INTERNAL FW ERROR!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
}
else
{
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> INTERNAL ERROR!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> ICALL ABORT!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
HAL_ASSERT_SPINLOCK;
break;
default:
#ifdef TI_DRIVERS_DISPLAY_INCLUDED
Board_writeString("***ERROR***", 1);
Board_writeString(">> DEFAULT SPINLOCK!", 2);
#endif // TI_DRIVERS_DISPLAY_INCLUDED
HAL_ASSERT_SPINLOCK;
}
return;
}
@@ -0,0 +1,995 @@
/**************************************************************************************************
Filename: just_works.c
Revised: $Date$
Revision: $Revision$
Description: This file contains the basic sample peripheral application to implement
legacy just works pairing for use with the CC2650 Bluetooth
Low Energy Protocol Stack.
Copyright (c) 2013-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.
**************************************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include <string.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Queue.h>
#include "gatt.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "simple_gatt_profile.h"
#include "devinfoservice.h"
#include "hci_tl.h"
#include "peripheral.h"
#include "gapbondmgr.h"
#include "osal_snv.h"
#include "icall_apimsg.h"
#include <ti/mw/display/Display.h>
#include "util.h"
#include "board_key.h"
#include "board.h"
#include "security_examples_peripheral.h"
#include <ti/mw/lcd/LCDDogm1286.h>
/*********************************************************************
* CONSTANTS
*/
// Advertising interval when device is discoverable (units of 625us, 160=100ms)
#define DEFAULT_ADVERTISING_INTERVAL 160
// Limited discoverable mode advertises for 30.72s, and then stops
// General discoverable mode advertises indefinitely
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
// Minimum connection interval (units of 1.25ms, 80=100ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 80
// Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 800
// Task configuration
#define SEP_TASK_PRIORITY 1
#ifndef SEP_TASK_STACK_SIZE
#define SEP_TASK_STACK_SIZE 644
#endif
// Internal Events for RTOS application
#define SEP_PAIRING_STATE_EVT 0x0001
#define SEP_KEY_CHANGE_EVT 0x0002
#define SEP_STATE_CHANGE_EVT 0x0004
#define SEP_PASSCODE_NEEDED_EVT 0x0008
/*********************************************************************
* TYPEDEFS
*/
// App event passed from profiles.
typedef struct
{
appEvtHdr_t hdr; // event header.
uint8_t *pData; // event data
} sepEvt_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
// Display Interface
Display_Handle dispHandle = NULL;
/*********************************************************************
* LOCAL VARIABLES
*/
/*********************************************************************
* LOCAL VARIABLES
*/
// Entity ID globally used to check for source and/or destination of messages
static ICall_EntityID selfEntity;
// Semaphore globally used to post events to the application thread
static ICall_Semaphore sem;
// Queue object used for app messages
static Queue_Struct appMsg;
static Queue_Handle appMsgQueue;
// Task configuration
Task_Struct sepTask;
Char sepTaskStack[SEP_TASK_STACK_SIZE];
// GAP - SCAN RSP data (max size = 31 bytes)
static uint8_t scanRspData[] =
{
// complete name
0x14, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
0x53, // 'S'
0x69, // 'i'
0x6d, // 'm'
0x70, // 'p'
0x6c, // 'l'
0x65, // 'e'
0x42, // 'B'
0x4c, // 'L'
0x45, // 'E'
0x50, // 'P'
0x65, // 'e'
0x72, // 'r'
0x69, // 'i'
0x70, // 'p'
0x68, // 'h'
0x65, // 'e'
0x72, // 'r'
0x61, // 'a'
0x6c, // 'l'
// connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
LO_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL), // 100ms
HI_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL),
LO_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL), // 1s
HI_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL),
// Tx power level
0x02, // length of this data
GAP_ADTYPE_POWER_LEVEL,
0 // 0dBm
};
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8_t advertData[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED
};
// Connection handle of current connection
static uint16_t connHandle = GAP_CONNHANDLE_INIT;
// GAP GATT Attributes
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "Security Ex Periph";
//oob data needed for either type of OOB pairing
#if ((PAIRING == OOB_SC) || (PAIRING == OOB_LE))
//OOB data from remote
gapBondOobSC_t oobRemoteData =
{
.addr = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
.confirm = {0x38, 0xc0, 0x4d, 0x01, 0xe8, 0xb1, 0x7b, 0x90, 0x28, 0xad, 0x99,
0x48, 0xad, 0x89, 0x79, 0x4c },
.oob = {0xA3, 0xDE, 0xBB, 0x31, 0xE6, 0x42, 0x4E, 0x2F, 0x39, 0x7F, 0xF2,
0xD2, 0xC4, 0x89, 0xC6, 0xA7}
};
#endif
//ECC keys needed when using static keys with OOB secure connections pairing
#if ((PAIRING == OOB_SC) && (STATIC_KEYS))
//LOCAL KEYS
gapBondEccKeys_t eccKeys =
{
.privateKey = {0x15, 0x99, 0x87, 0x83, 0xc7, 0x84, 0x05, 0x92, 0x35, 0x9e,
0x54, 0x2c, 0x77, 0x61, 0xb5, 0xd6, 0x0a, 0x80, 0x67, 0x5d,
0xe8, 0x62, 0xd5, 0xe0, 0xeb, 0xce, 0x76, 0xc7, 0x7b, 0xc2,
0xfb, 0x43},
.publicKeyX = {0xca, 0x42, 0x2f, 0xc3, 0x4c, 0xe5, 0x03, 0x9a, 0x94, 0x06,
0x26, 0x6d, 0xd8, 0x22, 0x51, 0x30, 0xe6, 0x04, 0xd7, 0x4b,
0x9b, 0xc3, 0x1e, 0x45, 0xde, 0x5e, 0x3d, 0x5d, 0xb0, 0x1a,
0xe4, 0xaa},
.publicKeyY = {0x03, 0xc8, 0xbf, 0xd1, 0x00, 0xc6, 0x10, 0xb5, 0xec, 0x33,
0x0c, 0x39, 0x8d, 0xa9, 0xcf, 0x87, 0x36, 0x27, 0xe9, 0x02,
0x27, 0x28, 0xad, 0xc1, 0xb0, 0x40, 0xae, 0x97, 0x47, 0x66,
0x8f, 0xb4}
};
#endif
//needed for all types of pairing besides OOB
#if !(((PAIRING == OOB_SC) || (PAIRING == OOB_LE)))
// Passcode variables
static uint8_t judgeNumericComparison = FALSE;
static uint8_t waiting_for_passcode = FALSE;
static uint32_t passcode = 0;
static uint32_t passcode_multiplier = 100000;
static uint16_t passcode_connHandle = 0xFFFF;
#endif
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void security_examples_peripheral_init( void );
static void security_examples_peripheral_taskFxn(UArg a0, UArg a1);
static void security_examples_peripheral_handleKeys(uint8_t shift, uint8_t keys);
static void security_examples_peripheral_processAppMsg(sepEvt_t *pMsg);
static void security_examples_peripheral_processPasscode(uint16_t connectionHandle,
gapPasskeyNeededEvent_t *pData);
static void security_examples_peripheral_processStateChangeEvt(gaprole_States_t newState);
static void security_examples_peripheral_stateChangeCB(gaprole_States_t newState);
static uint8_t security_examples_peripheral_enqueueMsg(uint8_t event, uint8_t status,
uint8_t *pData);
static void security_examples_peripheral_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison);
static void security_examples_peripheral_pairStateCB(uint16_t connHandle, uint8_t state,
uint8_t status);
void security_examples_peripheral_keyChangeHandler(uint8 keys);
static void security_examples_peripheral_processPairState(uint8_t state, uint8_t status);
static void security_examples_peripheral_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison);
static uint8_t security_example_peripheral_processStackMsg(ICall_Hdr *pMsg);
/*********************************************************************
* PROFILE CALLBACKS
*/
// GAP Role Callbacks
static gapRolesCBs_t security_examples_peripheral_gapRoleCBs =
{
security_examples_peripheral_stateChangeCB // Profile State Change Callbacks
};
// GAP Bond Manager Callbacks
static gapBondCBs_t security_examples_peripheral_BondMgrCBs =
{
(pfnPasscodeCB_t)security_examples_peripheral_passcodeCB, // Passcode callback
security_examples_peripheral_pairStateCB // Pairing / Bonding state Callback (not used by application)
};
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn security_examples_peripheral_createTask
*
* @brief Task creation function for the Simple BLE Peripheral.
*
* @param None.
*
* @return None.
*/
void security_examples_peripheral_createTask(void)
{
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = sepTaskStack;
taskParams.stackSize = SEP_TASK_STACK_SIZE;
taskParams.priority = SEP_TASK_PRIORITY;
Task_construct(&sepTask, security_examples_peripheral_taskFxn, &taskParams, NULL);
}
/*********************************************************************
* @fn security_examples_peripheral_init
*
* @brief Called during initialization and contains application
* specific initialization (ie. hardware initialization/setup,
* table initialization, power up notification, etc), and
* profile initialization/setup.
*
* @param None.
*
* @return None.
*/
static void security_examples_peripheral_init(void)
{
// ******************************************************************
// N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
// ******************************************************************
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntity, &sem);
uint8 bdAddr[] = {0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB};
HCI_EXT_SetBDADDRCmd(bdAddr);
// Create an RTOS queue for message from profile to be sent to app.
appMsgQueue = Util_constructQueue(&appMsg);
Board_initKeys(security_examples_peripheral_keyChangeHandler);
dispHandle = Display_open(Display_Type_LCD, NULL);
// Setup the GAP Peripheral Role Profile
{
// For all hardware platforms, device starts advertising upon initialization
uint8_t initialAdvertEnable = TRUE;
// By setting this to zero, the device will go into the waiting state after
// being discoverable for 30.72 second, and will not being advertising again
// until the enabler is set back to TRUE
uint16_t advertOffTime = 0;
// Set the GAP Role Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initialAdvertEnable);
GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),
&advertOffTime);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData),
scanRspData);
GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
}
// Set the GAP Characteristics
GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);
// Set advertising interval
{
uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;
GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt);
GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt);
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt);
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
}
//Setup the Gap Bond Manager
{
//common GAPBondMgr params
uint8_t pairMode = GAPBOND_PAIRING_MODE_INITIATE;
uint8_t bonding = FALSE;
GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
//initializtion for secure connections OOB
#if (PAIRING == OOB_SC)
uint8_t scMode = GAPBOND_SECURE_CONNECTION_ONLY;
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &scMode);
#if STATIC_KEYS
GAPBondMgr_SetParameter(GAPBOND_ECC_KEYS, sizeof(gapBondEccKeys_t), &eccKeys);
#endif
//initialization for legacy OOB pairing
#elif (PAIRING == OOB_LE)
uint8_t scMode = GAPBOND_SECURE_CONNECTION_NONE;
uint8_t oobEnabled = TRUE;
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &scMode);
GAPBondMgr_SetParameter(GAPBOND_OOB_DATA, sizeof(uint8_t) * KEYLEN, oobRemoteData.oob);
GAPBondMgr_SetParameter(GAPBOND_OOB_ENABLED, sizeof(uint8_t), &oobEnabled );
//initialization for numeric comparison pairing (only possible with secure connections)
#elif (PAIRING == NUMCOMP)
uint8_t mitm = TRUE;
uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_YES_NO;
uint8_t scMode = GAPBOND_SECURE_CONNECTION_ONLY;
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &scMode);
//initialization for passcode entry pairing
#elif (PAIRING == PASSCODE)
uint8_t mitm = TRUE;
uint8_t ioCap = GAPBOND_IO_CAP_KEYBOARD_ONLY;
uint8_t scMode = GAPBOND_SECURE_CONNECTION_ALLOW;
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &scMode);
//initialization for just works pairing
#elif (PAIRING == JUSTWORKS)
uint8_t mitm = FALSE;
uint8_t scMode = GAPBOND_SECURE_CONNECTION_ALLOW;
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &scMode);
#endif
}
// Initialize GATT attributes
GGS_AddService(GATT_ALL_SERVICES); // GAP
DevInfo_AddService(); // Device Information Service
SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile
// Start the Device
VOID GAPRole_StartDevice(&security_examples_peripheral_gapRoleCBs);
// Start Bond Manager
VOID GAPBondMgr_Register(&security_examples_peripheral_BondMgrCBs);
// Register with GAP for HCI/Host messages
GAP_RegisterForMsgs(selfEntity);
// pass OOB data to GAPBondMgr for OOB SC pairing
#if (PAIRING == OOB_SC)
#if (STATIC_KEYS) // We already have the keys...get the confirm value
SM_GetScConfirmOob(eccKeys.publicKeyX, oobRemoteData.oob, oobRemoteData.confirm);
uint8_t oobEnabled = TRUE;
GAPBondMgr_SetParameter(GAPBOND_REMOTE_OOB_SC_ENABLED, sizeof(uint8_t), &oobEnabled );
GAPBondMgr_SetParameter(GAPBOND_REMOTE_OOB_SC_DATA, sizeof(gapBondOobSC_t), &oobRemoteData);
#else //keys will be returned from the stack
// Register to receive SM messages
SM_RegisterTask(selfEntity);
// Get ECC Keys - response comes in through callback.
SM_GetEccKeys();
#endif //STATIC_KEYS
#endif //OOB_SC
Display_print0(dispHandle, LCD_PAGE0, 0, "Security Ex Periph");
}
/*********************************************************************
* @fn security_examples_peripheral_taskFxn
*
* @brief Application task entry point for the Simple BLE Peripheral.
*
* @param a0, a1 - not used.
*
* @return None.
*/
static void security_examples_peripheral_taskFxn(UArg a0, UArg a1)
{
// Initialize application
security_examples_peripheral_init();
// Application main loop
for (;;)
{
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
// ICall_signal() function is called onto the semaphore.
ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
if (errno == ICALL_ERRNO_SUCCESS)
{
ICall_EntityID dest;
ICall_ServiceEnum src;
ICall_HciExtEvt *pMsg = NULL;
if (ICall_fetchServiceMsg(&src, &dest,
(void **)&pMsg) == ICALL_ERRNO_SUCCESS)
{
uint8 safeToDealloc = TRUE;
if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
{
ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg;
// Check for BLE stack events first
if (pEvt->signature != 0xffff)
{
// Process inter-task message
safeToDealloc = security_example_peripheral_processStackMsg((ICall_Hdr *)pMsg);
}
}
if (pMsg && safeToDealloc)
{
ICall_freeMsg(pMsg);
}
}
// If RTOS queue is not empty, process app message.
while (!Queue_empty(appMsgQueue))
{
sepEvt_t *pMsg = (sepEvt_t *)Util_dequeueMsg(appMsgQueue);
if (pMsg)
{
// Process message.
security_examples_peripheral_processAppMsg(pMsg);
// Free the space from the message.
ICall_free(pMsg);
}
}
}
}
}
/*********************************************************************
* @fn security_examples_peripheral_processAppMsg
*
* @brief Process an incoming callback from a profile.
*
* @param pMsg - message to process
*
* @return None.
*/
static void security_examples_peripheral_processAppMsg(sepEvt_t *pMsg)
{
switch (pMsg->hdr.event)
{
case SEP_STATE_CHANGE_EVT:
security_examples_peripheral_processStateChangeEvt((gaprole_States_t)pMsg->
hdr.state);
break;
case SEP_KEY_CHANGE_EVT:
security_examples_peripheral_handleKeys(0, pMsg->hdr.state);
break;
// Pairing event
case SEP_PAIRING_STATE_EVT:
{
security_examples_peripheral_processPairState(pMsg->hdr.state, *pMsg->pData);
ICall_free(pMsg->pData);
break;
}
// Passcode event
case SEP_PASSCODE_NEEDED_EVT:
{
security_examples_peripheral_processPasscode(connHandle, (gapPasskeyNeededEvent_t *)pMsg->pData);
ICall_free(pMsg->pData);
break;
}
default:
// Do nothing.
break;
}
}
/*********************************************************************
* @fn security_examples_peripheral_stateChangeCB
*
* @brief Callback from GAP Role indicating a role state change.
*
* @param newState - new state
*
* @return None.
*/
static void security_examples_peripheral_stateChangeCB(gaprole_States_t newState)
{
security_examples_peripheral_enqueueMsg(SEP_STATE_CHANGE_EVT, newState, NULL);
}
/*********************************************************************
* @fn security_examples_peripheral_processStateChangeEvt
*
* @brief Process a pending GAP Role state change event.
*
* @param newState - new state
*
* @return None.
*/
static void security_examples_peripheral_processStateChangeEvt(gaprole_States_t newState)
{
switch ( newState )
{
case GAPROLE_STARTED:
{
uint8_t ownAddress[B_ADDR_LEN];
uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];
GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
// use 6 bytes of device address for 8 bytes of system ID value
systemId[0] = ownAddress[0];
systemId[1] = ownAddress[1];
systemId[2] = ownAddress[2];
// set middle bytes to zero
systemId[4] = 0x00;
systemId[3] = 0x00;
// shift three bytes up
systemId[7] = ownAddress[5];
systemId[6] = ownAddress[4];
systemId[5] = ownAddress[3];
DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
// Display device address
Display_print0(dispHandle, LCD_PAGE1, 0, Util_convertBdAddr2Str(ownAddress));
Display_print0(dispHandle, LCD_PAGE2, 0, "Initialized");
}
break;
case GAPROLE_ADVERTISING:
Display_print0(dispHandle, LCD_PAGE2, 0, "Advertising");
break;
case GAPROLE_CONNECTED:
{
uint8_t peerAddress[B_ADDR_LEN];
GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress);
GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connHandle);
Display_print0(dispHandle, LCD_PAGE2, 0, "Connected");
Display_print0(dispHandle, LCD_PAGE3, 0, Util_convertBdAddr2Str(peerAddress));
}
break;
case GAPROLE_CONNECTED_ADV:
Display_print0(dispHandle, LCD_PAGE2, 0, "Connected Advertising");
break;
case GAPROLE_WAITING:
Display_print0(dispHandle, LCD_PAGE2, 0, "Disconnected");
// Clear remaining lines
Display_print0(dispHandle, LCD_PAGE3, 0, "");
Display_print0(dispHandle, LCD_PAGE4, 0, "");
Display_print0(dispHandle, LCD_PAGE5, 0, "");
break;
case GAPROLE_WAITING_AFTER_TIMEOUT:
Display_print0(dispHandle, LCD_PAGE2, 0, "Timed Out");
// Clear remaining lines
Display_print0(dispHandle, LCD_PAGE3, 0, "");
Display_print0(dispHandle, LCD_PAGE4, 0, "");
Display_print0(dispHandle, LCD_PAGE5, 0, "");
break;
case GAPROLE_ERROR:
Display_print0(dispHandle, LCD_PAGE2, 0, "Error");
break;
default:
Display_print0(dispHandle, LCD_PAGE2, 0, "");
break;
}
}
/*********************************************************************
* @fn security_examples_peripheral_processPairState
*
* @brief Process the new paring state.
*
* @return none
*/
static void security_examples_peripheral_processPairState(uint8_t state, uint8_t status)
{
if (state == GAPBOND_PAIRING_STATE_STARTED)
{
Display_print0(dispHandle, LCD_PAGE2, 0, "Pairing started");
}
else if (state == GAPBOND_PAIRING_STATE_COMPLETE)
{
if (status == SUCCESS)
{
Display_print0(dispHandle, LCD_PAGE2, 0, "Pairing success");
}
else
{
Display_print1(dispHandle, LCD_PAGE2, 0, "Pairing fail: %d", status);
}
}
else if (state == GAPBOND_PAIRING_STATE_BONDED)
{
if (status == SUCCESS)
{
Display_print0(dispHandle, LCD_PAGE2, 0, "Bonding success");
}
}
else if (state == GAPBOND_PAIRING_STATE_BOND_SAVED)
{
if (status == SUCCESS)
{
Display_print0(dispHandle, LCD_PAGE2, 0, "Bond save success");
}
else
{
Display_print1(dispHandle, LCD_PAGE2, 0, "Bond save failed: %d", status);
}
}
}
/*********************************************************************
* @fn security_examples_peripheral_handleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void security_examples_peripheral_handleKeys(uint8_t shift, uint8_t keys)
{
//needed for all types of pairing besides OOB
#if !(((PAIRING == OOB_SC) || (PAIRING == OOB_LE)))
(void)shift; // Intentionally unreferenced parameter
if (keys & KEY_RIGHT)
{
if (waiting_for_passcode)
{
//increment passcode digit
passcode += passcode_multiplier;
Display_print1(dispHandle, LCD_PAGE5, 0, "%d",passcode);
return;
}
else if (judgeNumericComparison)
{
judgeNumericComparison = FALSE;
// overload 3rd parameter as TRUE when instead of the passcode when
// numeric comparisons is used.
GAPBondMgr_PasscodeRsp(connHandle, SUCCESS, TRUE);
Display_print0(dispHandle, LCD_PAGE5, 0, "Codes Match!");
return;
}
}
if ((keys & KEY_DOWN) && (waiting_for_passcode))
{
// incrememnt passcode multiplier
passcode_multiplier = passcode_multiplier / 10;
if (passcode_multiplier == 0)
{
//send pascode response
GAPBondMgr_PasscodeRsp(passcode_connHandle, SUCCESS, passcode);
//reset variables
passcode_multiplier = 100000;
passcode = 0;
waiting_for_passcode = FALSE;
passcode_connHandle = 0xFFFF;
}
return;
}
#endif
}
/*********************************************************************
* @fn security_examples_peripheral_processPasscode
*
* @brief Process the Passcode request.
*
* @return none
*/
static void security_examples_peripheral_processPasscode(uint16_t connectionHandle,
gapPasskeyNeededEvent_t *pData)
{
//needed for all types of pairing besides OOB
#if !(((PAIRING == OOB_SC) || (PAIRING == OOB_LE)))
if (pData->numComparison) //numeric comparison
{
#if STATIC_PASSCODE
// Send passcode response
GAPBondMgr_PasscodeRsp(connectionHandle, SUCCESS, TRUE);
#else
judgeNumericComparison = TRUE;
#endif
//Display passcode
Display_print1(dispHandle, LCD_PAGE4, 0, "Num Cmp: %d", pData->numComparison);
}
else //passkey entry
{
if (pData->uiInputs) // if we are to enter passkey
{
#if STATIC_PASSCODE
passcode = 111111;
// Send passcode response
GAPBondMgr_PasscodeRsp(connectionHandle, SUCCESS, passcode);
#else
// user will enter passcode
waiting_for_passcode = TRUE;
passcode_connHandle = connectionHandle;
#endif
Display_print0(dispHandle, LCD_PAGE4, 0, "Enter Passcode:");
Display_print1(dispHandle, LCD_PAGE5, 0, "%d", passcode);
}
else if (pData->uiOutputs) // if we are to display passkey
{
#if STATIC_PASSCODE
passcode = 111111;
#else
// Create random passcode
passcode = Util_GetTRNG();
passcode %= 1000000;
#endif
Display_print1(dispHandle, LCD_PAGE4, 0, "Passcode: %d", passcode);
// Send passcode response
GAPBondMgr_PasscodeRsp(connectionHandle, SUCCESS, passcode);
}
else
{
//shouldn't get here
}
}
#endif
}
/*********************************************************************
* @fn security_examples_peripheral_pairStateCB
*
* @brief Pairing state callback.
*
* @return none
*/
static void security_examples_peripheral_pairStateCB(uint16_t connHandle, uint8_t state,
uint8_t status)
{
uint8_t *pData;
// Allocate space for the event data.
if ((pData = ICall_malloc(sizeof(uint8_t))))
{
*pData = status;
// Queue the event.
security_examples_peripheral_enqueueMsg(SEP_PAIRING_STATE_EVT, state, pData);
}
}
/*********************************************************************
* @fn security_examples_peripheral_passcodeCB
*
* @brief Passcode callback.
*
* @return none
*/
static void security_examples_peripheral_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison)
{
gapPasskeyNeededEvent_t *pData;
// Allocate space for the passcode event.
if ((pData = ICall_malloc(sizeof(gapPasskeyNeededEvent_t))))
{
memcpy(pData->deviceAddr, deviceAddr, B_ADDR_LEN);
pData->connectionHandle = connHandle;
pData->uiInputs = uiInputs;
pData->uiOutputs = uiOutputs;
pData->numComparison = numComparison;
// Enqueue the event.
security_examples_peripheral_enqueueMsg(SEP_PASSCODE_NEEDED_EVT, 0, (uint8_t *) pData);
}
}
/***********************************************************************
* @fn security_examples_peripheral_keyChangeHandler
*
* @brief Key event handler function
*
* @param a0 - ignored
*
* @return none
*/
void security_examples_peripheral_keyChangeHandler(uint8 keys)
{
security_examples_peripheral_enqueueMsg(SEP_KEY_CHANGE_EVT, keys, NULL);
}
/*********************************************************************
* @fn security_examples_peripheral_enqueueMsg
*
* @brief Creates a message and puts the message in RTOS queue.
*
* @param event - message event.
* @param state - message state.
*
* @return None.
*/
static uint8_t security_examples_peripheral_enqueueMsg(uint8_t event, uint8_t state,
uint8_t *pData)
{
sepEvt_t *pMsg = ICall_malloc(sizeof(sepEvt_t));
// Create dynamic pointer to message.
if (pMsg)
{
pMsg->hdr.event = event;
pMsg->hdr.state = state;
pMsg->pData = pData;
// Enqueue the message.
return Util_enqueueMsg(appMsgQueue, sem, (uint8_t *)pMsg);
}
return FALSE;
}
/*********************************************************************
*********************************************************************/
/*********************************************************************
* @fn SimpleBLEPeripheral_processStackMsg
*
* @brief Process an incoming stack message.
*
* @param pMsg - message to process
*
* @return TRUE if safe to deallocate incoming message, FALSE otherwise.
*/
static uint8_t security_example_peripheral_processStackMsg(ICall_Hdr *pMsg)
{
uint8_t safeToDealloc = TRUE;
switch (pMsg->event)
{
#ifdef BROKEN
case GATT_MSG_EVENT:
// Process GATT message
safeToDealloc = SimpleBLEPeripheral_processGATTMsg((gattMsgEvent_t *)pMsg);
break;
#endif // Broken
//receive keys from stack for OOB SC pairing without static keys
#if ((PAIRING == OOB_SC) && !(STATIC_KEYS))
case SM_MSG_EVENT:
{
//check for correct event
if (pMsg->status == SM_ECC_KEYS_EVENT)
{
smEccKeysEvt_t* eccKeys = (smEccKeysEvt_t*)pMsg;
uint8_t oobEnabled = TRUE;
// Get the confirm value
SM_GetScConfirmOob(eccKeyspublicKeyX, oobRemoteData.oob, oobRemoteData.confirm);
//pass OOB data to GAPBondMgr
GAPBondMgr_SetParameter(GAPBOND_REMOTE_OOB_SC_ENABLED, sizeof(uint8_t), &oobEnabled );
GAPBondMgr_SetParameter(GAPBOND_REMOTE_OOB_SC_DATA, sizeof(gapBondOobSC_t), &oobRemoteData);
}
}
break;
#endif
default:
// do nothing
break;
}
return (safeToDealloc);
}
@@ -0,0 +1,98 @@
/**************************************************************************************************
Filename: security_examples_peripheral.h
Revised: $Date$
Revision: $Revision$
Description: This file contains the security examples peripheral sample application
definitions and prototypes.
Copyright (c) 2013-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.
**************************************************************************************************/
#ifndef SECURITY_EXAMPLES_PERIPHERAL_H
#define SECURITY_EXAMPLES_PERIPHERAL_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* CONSTANTS
*/
#define OOB_LE 0x01 // out of band legacy
#define OOB_SC 0x02 // out of band secure connections
#define JUSTWORKS 0x03 // just works
#define PASSCODE 0x04 // passcode
#define NUMCOMP 0x05 // numeric comparison
#define PAIRING JUSTWORKS
#define STATIC_PASSCODE 0x01
#define STATIC_KEYS 0x01
#if !defined( PAIRING )
#warning No Pairing mode selected!
#elif (PAIRING > NUMCOMP) || (PAIRING == 0)
#warning Invalid pairing mode!
#endif
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Task creation function for the security examples peripheral.
*/
extern void security_examples_peripheral_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* SECURITY_EXAMPLES_PERIPHERAL_H */
@@ -0,0 +1,226 @@
/******************************************************************************
@file osal_icall_ble.c
@brief This file contains function that allows user setup tasks
Group: WCS, BTS
$Target Device: DEVICES $
******************************************************************************
Copyright (c) 2013-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.
*****************************************************************************/
/**************************************************************************************************
* INCLUDES
**************************************************************************************************/
#include <icall.h>
#include "hal_types.h"
#include "hal_mcu.h"
#include "osal.h"
#include "osal_tasks.h"
#include "osal_snv.h"
/* LL */
#include "ll.h"
#if defined ( OSAL_CBTIMER_NUM_TASKS )
#include "osal_cbtimer.h"
#endif
/* L2CAP */
#include "l2cap.h"
/* gap */
#include "gap.h"
#if defined ( GAP_BOND_MGR )
#include "gapbondmgr.h"
#endif
/* GATT */
#include "gatt.h"
/* Application */
#include "hci_tl.h"
#include "gattservapp.h"
#include "ble_user_config.h"
#include "ble_dispatch.h"
/*********************************************************************
* GLOBAL VARIABLES
*/
// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] =
{
LL_ProcessEvent, // task 0
HCI_ProcessEvent, // task 1
#if defined ( OSAL_CBTIMER_NUM_TASKS )
OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ), // task 2
#endif
L2CAP_ProcessEvent, // task 3
GAP_ProcessEvent, // task 4
SM_ProcessEvent, // task 5
GATT_ProcessEvent, // task 6
GATTServApp_ProcessEvent, // task 7
#if defined ( GAP_BOND_MGR )
GAPBondMgr_ProcessEvent, // task 8
#endif
bleDispatch_ProcessEvent // task 9
};
const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;
/*********************************************************************
* FUNCTIONS
*********************************************************************/
/*********************************************************************
* @fn osalInitTasks
*
* @brief This function invokes the initialization function for each task.
*
* @param void
*
* @return none
*/
void osalInitTasks( void )
{
ICall_EntityID entity;
ICall_Semaphore sem;
uint8 taskID = 0;
uint8 i;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
/* LL Task */
LL_Init( taskID++ );
/* HCI Task */
HCI_Init( taskID++ );
#if defined ( OSAL_CBTIMER_NUM_TASKS )
/* Callback Timer Tasks */
osal_CbTimerInit( taskID );
taskID += OSAL_CBTIMER_NUM_TASKS;
#endif
/* L2CAP Task */
L2CAP_Init( taskID++ );
/* GAP Task */
GAP_Init( taskID++ );
/* SM Task */
SM_Init( taskID++ );
/* GATT Task */
GATT_Init( taskID++ );
/* GATT Server App Task */
GATTServApp_Init( taskID++ );
#if defined ( GAP_BOND_MGR )
/* Bond Manager Task */
GAPBondMgr_Init( taskID++ );
#endif
/* ICall BLE Dispatcher Task */
bleDispatch_Init( taskID );
// ICall enrollment
/* Enroll the service that this stack represents */
ICall_enrollService(ICALL_SERVICE_CLASS_BLE, NULL, &entity, &sem);
/* Enroll the obtained dispatcher entity and OSAL task ID of HCI Ext App
* to OSAL so that OSAL can route the dispatcher message into
* the appropriate OSAL task.
*/
osal_enroll_dispatchid(taskID, entity);
/* Register all other OSAL tasks to use the registered dispatcher entity
* ID as the source of dispatcher messages, even though the other OSAL
* tasks didn't register themselves to receive messages from application.
*/
for (i = 0; i < taskID; i++)
{
osal_enroll_senderid(i, entity);
}
}
/**
* Main entry function for the stack image
*/
int stack_main( void *arg )
{
/* User reconfiguration of BLE Controller and Host variables */
setBleUserConfig( (bleUserCfg_t *)arg );
/* Establish OSAL for a stack service that requires accompanying
* messaging service */
if (ICall_enrollService(ICALL_SERVICE_CLASS_BLE_MSG,
(ICall_ServiceFunc) osal_service_entry,
&osal_entity, &osal_semaphore) !=
ICALL_ERRNO_SUCCESS)
{
/* abort */
ICall_abort();
}
halIntState_t state;
HAL_ENTER_CRITICAL_SECTION(state);
// Turn off interrupts
//osal_int_disable( INTS_ALL );
// Initialize NV System
osal_snv_init( );
// Initialize the operating system
osal_init_system();
// Allow interrupts
//osal_int_enable( INTS_ALL );
HAL_EXIT_CRITICAL_SECTION(state);
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
}
/*********************************************************************
*********************************************************************/
@@ -0,0 +1,997 @@
/*
* Filename: simple_beacon.c
*
* Description: This file contains the Simple Beacon sample application for use
* with the CC2650 Bluetooth Low Energy Protocol Stack.
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/*********************************************************************
* INCLUDES
*/
#include <string.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Queue.h>
#include "hci_tl.h"
#include "gatt.h"
#include "linkdb.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "devinfoservice.h"
#include "simple_gatt_profile.h"
#if defined(FEATURE_OAD) || defined(IMAGE_INVALIDATE)
#include "oad_target.h"
#include "oad.h"
#endif //FEATURE_OAD || IMAGE_INVALIDATE
#include "peripheral.h"
#include "gapbondmgr.h"
#include "osal_snv.h"
#include "icall_apimsg.h"
#include "util.h"
#ifdef USE_RCOSC
#include "rcosc_calibration.h"
#endif //USE_RCOSC
#include <ti/mw/display/Display.h>
#include "board.h"
#include "simple_peripheral.h"
// DriverLib
#include <driverlib/aon_batmon.h>
/*********************************************************************
* CONSTANTS
*/
// Advertising interval when device is discoverable (units of 625us, 160=100ms)
#define DEFAULT_ADVERTISING_INTERVAL 160
// Limited discoverable mode advertises for 30.72s, and then stops
// General discoverable mode advertises indefinitely
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
#ifndef FEATURE_OAD
// Minimum connection interval (units of 1.25ms, 80=100ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 80
// Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 800
#else //!FEATURE_OAD
// Minimum connection interval (units of 1.25ms, 8=10ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 8
// Maximum connection interval (units of 1.25ms, 8=10ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 8
#endif // FEATURE_OAD
// Slave latency to use if automatic parameter update request is enabled
#define DEFAULT_DESIRED_SLAVE_LATENCY 0
// Supervision timeout value (units of 10ms, 1000=10s) if automatic parameter
// update request is enabled
#define DEFAULT_DESIRED_CONN_TIMEOUT 1000
// Whether to enable automatic parameter update request when a connection is
// formed
#define DEFAULT_ENABLE_UPDATE_REQUEST TRUE
// Connection Pause Peripheral time value (in seconds)
#define DEFAULT_CONN_PAUSE_PERIPHERAL 6
#ifdef FEATURE_OAD
// The size of an OAD packet.
#define OAD_PACKET_SIZE ((OAD_BLOCK_SIZE) + 2)
#endif // FEATURE_OAD
// Task configuration
#define SIB_TASK_PRIORITY 1
#ifndef SIB_TASK_STACK_SIZE
#define SIB_TASK_STACK_SIZE 644
#endif
// Internal Events for RTOS application
#define SIB_STATE_CHANGE_EVT 0x0001
#define SIB_CONN_EVT_END_EVT 0x0008
#define SIB_CHAR_CHANGE_EVT 0x0010
#define SIB_ADV_COMPLETE_EVT 0x0020
#define beacon_PACKET_SIZE 30
/*********************************************************************
* TYPEDEFS
*/
// App event passed from profiles.
typedef struct
{
appEvtHdr_t hdr; // event header.
} sibEvt_t;
typedef struct
{
uint8_t length1; // 2
uint8_t dataType1; // for Flags data type (0x01)
uint8_t data1; // for Flags data (0x06)
uint8_t length2; // 0x1A
uint8_t dataType2; // 0xFF
uint8_t data2; // Company ID LSB (0x4C)
uint8_t data3; // Company ID MSB (0x00)
uint8_t data4; // Beacon Type LSB (0x02)
uint8_t data5; // Beacon Type MSB (0x15)
uint8_t data6; //UUID LSB
uint8_t data7; //UUID
uint8_t data8; //UUID
uint8_t data9; //UUID
uint8_t data10; //UUID
uint8_t data11; //UUID
uint8_t data12; //UUID
uint8_t data13; //UUID
uint8_t data14; //UUID
uint8_t data15; //UUID
uint8_t data16; //UUID
uint8_t data17; //UUID
uint8_t data18; //UUID
uint8_t data19; //UUID
uint8_t data20; //UUID
uint8_t data21; //UUID MSB
uint8_t data22; //Major LSB
uint8_t data23; //Major MSB
uint8_t data24; //Minor LSB
uint8_t data25; //Minor MSB
uint8_t data26; //Measured power
} beaconAdvData_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
// Display Interface
Display_Handle dispHandle = NULL;
/*********************************************************************
* LOCAL VARIABLES
*/
// Entity ID globally used to check for source and/or destination of messages
static ICall_EntityID selfEntity;
// Semaphore globally used to post events to the application thread
static ICall_Semaphore sem;
// Clock instances for internal periodic events.
static Clock_Struct periodicClock;
// Queue object used for app messages
static Queue_Struct appMsg;
static Queue_Handle appMsgQueue;
#if defined(FEATURE_OAD)
// Event data from OAD profile.
static Queue_Struct oadQ;
static Queue_Handle hOadQ;
#endif //FEATURE_OAD
// Task configuration
Task_Struct sibTask;
Char sibTaskStack[SIB_TASK_STACK_SIZE];
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static beaconAdvData_t beaconAdv =
{
// Flags; this sets the device to use general discoverable mode
0x02, // length of this data
GAP_ADTYPE_FLAGS,
0x06,
0x1A, // length of this data including the data type byte
0xFF, // type
0x4C, // company ID[0]
0x00, // company ID[1]
0x02, // beacon type[0]
0x15, // beacon type[1]
0xA3, // UUID LSB
0x22,
0x37,
0xE7,
0x3E,
0xC0,
0xC5,
0x84,
0x86,
0x4B,
0xB9,
0x99,
0xF9,
0x82,
0x03,
0xF7, // UUID MSB
0x00, //major[0] (major and minor fields can be set as desired)
0x00, //major[1]
0x00, //minor[0]
0x00, //minor[1]
0x00 //measured power (can be set later)
};
// GAP - SCAN RSP data (max size = 31 bytes)
static uint8_t scanRspData[] =
{
// complete name
0x0E, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
'S',
'i',
'm',
'p',
'l',
'e',
' ',
'B',
'e',
'a',
'c',
'o',
'n',
// connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
LO_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL), // 100ms
HI_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL),
LO_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL), // 1s
HI_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL),
};
// GAP GATT Attributes
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "Simple Beacon";
// Globals used for ATT Response retransmission
static gattMsgEvent_t *pAttRsp = NULL;
static uint8_t rspTxRetry = 0;
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void SimpleBeacon_init(void);
static void SimpleBeacon_taskFxn(UArg a0, UArg a1);
static uint8_t SimpleBeacon_processStackMsg(ICall_Hdr *pMsg);
static uint8_t SimpleBeacon_processGATTMsg(gattMsgEvent_t *pMsg);
static void SimpleBeacon_processAppMsg(sibEvt_t *pMsg);
static void SimpleBeacon_processStateChangeEvt(gaprole_States_t newState);
static void SimpleBeacon_sendAttRsp(void);
static void SimpleBeacon_freeAttRsp(uint8_t status);
static void SimpleBeacon_stateChangeCB(gaprole_States_t newState);
static void SimpleBeacon_startRegularAdv(void);
static void SimpleBeacon_enqueueMsg(uint8_t event, uint8_t state);
#ifdef FEATURE_OAD
void SimpleBeacon_processOadWriteCB(uint8_t event, uint16_t connHandle,
uint8_t *pData);
#endif //FEATURE_OAD
/*********************************************************************
* PROFILE CALLBACKS
*/
// GAP Role Callbacks
static gapRolesCBs_t SimpleBeacon_gapRoleCBs =
{
SimpleBeacon_stateChangeCB // Profile State Change Callbacks
};
// GAP Bond Manager Callbacks
static gapBondCBs_t SimpleBeacon_BondMgrCBs =
{
NULL, // Passcode callback (not used by application)
NULL // Pairing / Bonding state Callback (not used by application)
};
#ifdef FEATURE_OAD
static oadTargetCBs_t SimpleBeacon_oadCBs =
{
SimpleBeacon_processOadWriteCB // Write Callback.
};
#endif //FEATURE_OAD
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn SimpleBLEPeripheral_createTask
*
* @brief Task creation function for the Simple Beacon.
*
* @param None.
*
* @return None.
*/
void SimpleBLEPeripheral_createTask(void)
{
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = sibTaskStack;
taskParams.stackSize = SIB_TASK_STACK_SIZE;
taskParams.priority = SIB_TASK_PRIORITY;
Task_construct(&sibTask, SimpleBeacon_taskFxn, &taskParams, NULL);
}
/*********************************************************************
* @fn SimpleBeacon_init
*
* @brief Initialization function for the Simple Beacon App
* Task. This is called during initialization and should contain
* any application specific initialization (ie. hardware
* initialization/setup, table initialization, power up
* notification ...).
*
* @param none
*
* @return none
*/
static void SimpleBeacon_init(void)
{
// ******************************************************************
// N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
// ******************************************************************
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntity, &sem);
#ifdef USE_RCOSC
RCOSC_enableCalibration();
#endif // USE_RCOSC
// Create an RTOS queue for message from profile to be sent to app.
appMsgQueue = Util_constructQueue(&appMsg);
dispHandle = Display_open(Display_Type_LCD, NULL);
// Setup the GAP
GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);
// Setup the GAP Peripheral Role Profile
{
uint8_t initialAdvertEnable = FALSE;
uint8_t initialNonConnAdvEnable = TRUE;
// By setting this to zero, the device will go into the waiting state after
// being discoverable for 30.72 second, and will not being advertising again
// until the enabler is set back to TRUE
uint16_t advertOffTime = 0;
uint8_t enableUpdateRequest = DEFAULT_ENABLE_UPDATE_REQUEST;
uint16_t desiredMinInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
uint16_t desiredMaxInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
uint16_t desiredSlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY;
uint16_t desiredConnTimeout = DEFAULT_DESIRED_CONN_TIMEOUT;
// Set the GAP Role Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initialAdvertEnable);
GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8_t),
&initialNonConnAdvEnable);
GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),
&advertOffTime);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData),
scanRspData);
GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t),
&enableUpdateRequest);
GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t),
&desiredMinInterval);
GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t),
&desiredMaxInterval);
GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t),
&desiredSlaveLatency);
GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t),
&desiredConnTimeout);
}
// Set the GAP Characteristics
GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);
// Register an event for adv completion
HCI_EXT_AdvEventNoticeCmd(selfEntity, SIB_ADV_COMPLETE_EVT);
// Setup the GAP Bond Manager
{
uint32_t passkey = 0; // passkey "000000"
uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
uint8_t mitm = TRUE;
uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
uint8_t bonding = TRUE;
GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),
&passkey);
GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
}
// Initialize GATT attributes
GGS_AddService(GATT_ALL_SERVICES); // GAP
GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes
DevInfo_AddService(); // Device Information Service
// Start the Device
VOID GAPRole_StartDevice(&SimpleBeacon_gapRoleCBs);
// Start Bond Manager
VOID GAPBondMgr_Register(&SimpleBeacon_BondMgrCBs);
// Register with GAP for HCI/Host messages
GAP_RegisterForMsgs(selfEntity);
// Register for GATT local events and ATT Responses pending for transmission
GATT_RegisterForMsgs(selfEntity);
}
/*********************************************************************
* @fn SimpleBeacon_startRegularAdv
*
* @brief Start regular advertise.
* If configuration mode was on going, stop it.
*
* @param none
*
* @return none
*/
static void SimpleBeacon_startRegularAdv(void)
{
uint8 advertEnabled = FALSE;
uint8 advType = GAP_ADTYPE_ADV_NONCONN_IND;
// Stop connectable advertising
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&advertEnabled);
advertEnabled = TRUE;
GAPRole_SetParameter(GAPROLE_ADV_EVENT_TYPE, sizeof(uint8_t), &advType);
GAPRole_SetParameter(GAPROLE_ADVERT_DATA,
beacon_PACKET_SIZE,
&beaconAdv);
GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8_t),
&advertEnabled);
}
/*********************************************************************
* @fn SimpleBeacon_taskFxn
*
* @brief Application task entry point for the Simple Beacon.
*
* @param a0, a1 - not used.
*
* @return None.
*/
static void SimpleBeacon_taskFxn(UArg a0, UArg a1)
{
// Initialize application
SimpleBeacon_init();
// Application main loop
for (;;)
{
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
// ICall_signal() function is called onto the semaphore.
ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
if (errno == ICALL_ERRNO_SUCCESS)
{
ICall_EntityID dest;
ICall_ServiceEnum src;
ICall_HciExtEvt *pMsg = NULL;
if (ICall_fetchServiceMsg(&src, &dest,
(void **)&pMsg) == ICALL_ERRNO_SUCCESS)
{
uint8 safeToDealloc = TRUE;
if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
{
ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg;
// Check for BLE stack events first
if (pEvt->signature == 0xffff)
{
if (pEvt->event_flag & SIB_CONN_EVT_END_EVT)
{
// Try to retransmit pending ATT Response (if any)
SimpleBeacon_sendAttRsp();
}
}
else
{
// Process inter-task message
safeToDealloc = SimpleBeacon_processStackMsg((ICall_Hdr *)pMsg);
}
}
if (pMsg && safeToDealloc)
{
ICall_freeMsg(pMsg);
}
}
// If RTOS queue is not empty, process app message.
while (!Queue_empty(appMsgQueue))
{
sibEvt_t *pMsg = (sibEvt_t *)Util_dequeueMsg(appMsgQueue);
if (pMsg)
{
// Process message.
SimpleBeacon_processAppMsg(pMsg);
// Free the space from the message.
ICall_free(pMsg);
}
}
}
#ifdef FEATURE_OAD
while (!Queue_empty(hOadQ))
{
oadTargetWrite_t *oadWriteEvt = Queue_dequeue(hOadQ);
// Identify new image.
if (oadWriteEvt->event == OAD_WRITE_IDENTIFY_REQ)
{
OAD_imgIdentifyWrite(oadWriteEvt->connHandle, oadWriteEvt->pData);
}
// Write a next block request.
else if (oadWriteEvt->event == OAD_WRITE_BLOCK_REQ)
{
OAD_imgBlockWrite(oadWriteEvt->connHandle, oadWriteEvt->pData);
}
// Free buffer.
ICall_free(oadWriteEvt);
}
#endif //FEATURE_OAD
}
}
/*********************************************************************
* @fn SimpleBeacon_processStackMsg
*
* @brief Process an incoming stack message.
*
* @param pMsg - message to process
*
* @return TRUE if safe to deallocate incoming message, FALSE otherwise.
*/
static uint8_t SimpleBeacon_processStackMsg(ICall_Hdr *pMsg)
{
uint8_t safeToDealloc = TRUE;
switch (pMsg->event)
{
case GATT_MSG_EVENT:
// Process GATT message
safeToDealloc = SimpleBeacon_processGATTMsg((gattMsgEvent_t *)pMsg);
break;
case HCI_GAP_EVENT_EVENT:
{
// Process HCI message
switch(pMsg->status)
{
case HCI_COMMAND_COMPLETE_EVENT_CODE:
// Process HCI Command Complete Event
break;
default:
break;
}
}
break;
default:
// do nothing
break;
}
return (safeToDealloc);
}
/*********************************************************************
* @fn SimpleBeacon_processGATTMsg
*
* @brief Process GATT messages and events.
*
* @return TRUE if safe to deallocate incoming message, FALSE otherwise.
*/
static uint8_t SimpleBeacon_processGATTMsg(gattMsgEvent_t *pMsg)
{
// See if GATT server was unable to transmit an ATT response
if (pMsg->hdr.status == blePending)
{
// No HCI buffer was available. Let's try to retransmit the response
// on the next connection event.
if (HCI_EXT_ConnEventNoticeCmd(pMsg->connHandle, selfEntity,
SIB_CONN_EVT_END_EVT) == SUCCESS)
{
// First free any pending response
SimpleBeacon_freeAttRsp(FAILURE);
// Hold on to the response message for retransmission
pAttRsp = pMsg;
// Don't free the response message yet
return (FALSE);
}
}
else if (pMsg->method == ATT_FLOW_CTRL_VIOLATED_EVENT)
{
// ATT request-response or indication-confirmation flow control is
// violated. All subsequent ATT requests or indications will be dropped.
// The app is informed in case it wants to drop the connection.
// Display the opcode of the message that caused the violation.
Display_print1(dispHandle, 5, 0, "FC Violated:", pMsg->msg.flowCtrlEvt.opcode);
}
else if (pMsg->method == ATT_MTU_UPDATED_EVENT)
{
// MTU size updated
Display_print1(dispHandle, 5, 0, "FC Violated:", pMsg->msg.mtuEvt.MTU);
}
// Free message payload. Needed only for ATT Protocol messages
GATT_bm_free(&pMsg->msg, pMsg->method);
// It's safe to free the incoming message
return (TRUE);
}
/*********************************************************************
* @fn SimpleBeacon_sendAttRsp
*
* @brief Send a pending ATT response message.
*
* @param none
*
* @return none
*/
static void SimpleBeacon_sendAttRsp(void)
{
// See if there's a pending ATT Response to be transmitted
if (pAttRsp != NULL)
{
uint8_t status;
// Increment retransmission count
rspTxRetry++;
// Try to retransmit ATT response till either we're successful or
// the ATT Client times out (after 30s) and drops the connection.
status = GATT_SendRsp(pAttRsp->connHandle, pAttRsp->method, &(pAttRsp->msg));
if ((status != blePending) && (status != MSG_BUFFER_NOT_AVAIL))
{
// Disable connection event end notice
HCI_EXT_ConnEventNoticeCmd(pAttRsp->connHandle, selfEntity, 0);
// We're done with the response message
SimpleBeacon_freeAttRsp(status);
}
else
{
// Continue retrying
Display_print1(dispHandle, 5, 0, "Rsp send retry:", rspTxRetry);
}
}
}
/*********************************************************************
* @fn SimpleBeacon_freeAttRsp
*
* @brief Free ATT response message.
*
* @param status - response transmit status
*
* @return none
*/
static void SimpleBeacon_freeAttRsp(uint8_t status)
{
// See if there's a pending ATT response message
if (pAttRsp != NULL)
{
// See if the response was sent out successfully
if (status == SUCCESS)
{
Display_print1(dispHandle, 5, 0, "Rsp sent retry: %d", rspTxRetry);
}
else
{
// Free response payload
GATT_bm_free(&pAttRsp->msg, pAttRsp->method);
Display_print1(dispHandle, 5, 0, "Rsp retry failed: %d", rspTxRetry);
}
// Free response message
ICall_freeMsg(pAttRsp);
// Reset our globals
pAttRsp = NULL;
rspTxRetry = 0;
}
}
/*********************************************************************
* @fn SimpleBeacon_processAppMsg
*
* @brief Process an incoming callback from a profile.
*
* @param pMsg - message to process
*
* @return None.
*/
static void SimpleBeacon_processAppMsg(sibEvt_t *pMsg)
{
switch (pMsg->hdr.event)
{
case SIB_STATE_CHANGE_EVT:
SimpleBeacon_processStateChangeEvt((gaprole_States_t)pMsg->
hdr.state);
break;
default:
// Do nothing.
break;
}
}
/*********************************************************************
* @fn SimpleBeacon_stateChangeCB
*
* @brief Callback from GAP Role indicating a role state change.
*
* @param newState - new state
*
* @return None.
*/
static void SimpleBeacon_stateChangeCB(gaprole_States_t newState)
{
SimpleBeacon_enqueueMsg(SIB_STATE_CHANGE_EVT, newState);
}
/*********************************************************************
* @fn SimpleBeacon_processStateChangeEvt
*
* @brief Process a pending GAP Role state change event.
*
* @param newState - new state
*
* @return None.
*/
static void SimpleBeacon_processStateChangeEvt(gaprole_States_t newState)
{
switch ( newState )
{
case GAPROLE_STARTED:
{
uint8_t ownAddress[B_ADDR_LEN];
uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];
GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
// use 6 bytes of device address for 8 bytes of system ID value
systemId[0] = ownAddress[0];
systemId[1] = ownAddress[1];
systemId[2] = ownAddress[2];
// set middle bytes to zero
systemId[4] = 0x00;
systemId[3] = 0x00;
// shift three bytes up
systemId[7] = ownAddress[5];
systemId[6] = ownAddress[4];
systemId[5] = ownAddress[3];
DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
// Display device address
Display_print0(dispHandle, 1, 0, Util_convertBdAddr2Str(ownAddress));
Display_print0(dispHandle, 2, 0, "Initialized");
// Start advertising
SimpleBeacon_startRegularAdv();
}
break;
case GAPROLE_ADVERTISING:
Display_print0(dispHandle, 2, 0, "Config Mode");
break;
case GAPROLE_ADVERTISING_NONCONN:
{
SimpleBeacon_freeAttRsp(bleNotConnected);
Display_print0(dispHandle, 2, 0, "Advertising beacon");
Display_print0(dispHandle, 3, 0, "");
break;
}
case GAPROLE_CONNECTED:
{
linkDBInfo_t linkInfo;
uint8_t numActive = 0;
numActive = linkDB_NumActive();
// Use numActive to determine the connection handle of the last
// connection
if ( linkDB_GetInfo( numActive - 1, &linkInfo ) == SUCCESS )
{
Display_print1(dispHandle, 2, 0, "Num Conns: %d", (uint16_t)numActive);
Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(linkInfo.addr));
}
else
{
uint8_t peerAddress[B_ADDR_LEN];
GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress);
Display_print0(dispHandle, 2, 0, "Connected");
Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(peerAddress));
}
}
break;
case GAPROLE_WAITING:
case GAPROLE_WAITING_AFTER_TIMEOUT:
SimpleBeacon_freeAttRsp(bleNotConnected);
SimpleBeacon_startRegularAdv();
break;
case GAPROLE_ERROR:
Display_print0(dispHandle, 2, 0, "Error");
break;
default:
Display_clearLine(dispHandle, 2);
break;
}
}
#ifdef FEATURE_OAD
/*********************************************************************
* @fn SimpleBeacon_processOadWriteCB
*
* @brief Process a write request to the OAD profile.
*
* @param event - event type:
* OAD_WRITE_IDENTIFY_REQ
* OAD_WRITE_BLOCK_REQ
* @param connHandle - the connection Handle this request is from.
* @param pData - pointer to data for processing and/or storing.
*
* @return None.
*/
void SimpleBeacon_processOadWriteCB(uint8_t event, uint16_t connHandle,
uint8_t *pData)
{
oadTargetWrite_t *oadWriteEvt = ICall_malloc( sizeof(oadTargetWrite_t) + \
sizeof(uint8_t) * OAD_PACKET_SIZE);
if ( oadWriteEvt != NULL )
{
oadWriteEvt->event = event;
oadWriteEvt->connHandle = connHandle;
oadWriteEvt->pData = (uint8_t *)(&oadWriteEvt->pData + 1);
memcpy(oadWriteEvt->pData, pData, OAD_PACKET_SIZE);
Queue_enqueue(hOadQ, (Queue_Elem *)oadWriteEvt);
// Post the application's semaphore.
Semaphore_post(sem);
}
else
{
// Fail silently.
}
}
#endif //FEATURE_OAD
/*********************************************************************
* @fn SimpleBeacon_enqueueMsg
*
* @brief Creates a message and puts the message in RTOS queue.
*
* @param event - message event.
* @param state - message state.
*
* @return None.
*/
static void SimpleBeacon_enqueueMsg(uint8_t event, uint8_t state)
{
sibEvt_t *pMsg;
// Create dynamic pointer to message.
if ((pMsg = ICall_malloc(sizeof(sibEvt_t))))
{
pMsg->hdr.event = event;
pMsg->hdr.state = state;
// Enqueue the message.
Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
}
}
/*********************************************************************
*********************************************************************/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,519 @@
/*
============
program flow
============
periodic event
--------------
1. headstage_gptimer_main_handle
1. headstage_periodic_handle
*. [rec/arm mode]
1. @update_ins_rec_buffer
update channel and ADC clock bits.
1. @spi_transact_rec_instruction
spi_txbuf -> Headstage -> spi_rxbuf
1. collect_data
spi_rxbuf -> not_buf
1. [buff full] send_notify
SimpleProfile_SetParameter(not_buf -> 4)
*. [sti mode]
1. @update_ins_sti_buffer
#. @spi_transact_sti_instruction
characteristic change event
---------------------------
1. headstage_instruction_update_handle
SimpleProfile_GetParameter(3 -> ins_buf)
1. update_instruction
#. headstage_gptimer_set_frequency
#. update_ins_buffer
INSTRUCTION -> spi_txbuf
*/
#ifndef HEADSTAGE_H
#error "headstage.h not include"
#endif
#ifdef HEADSTAGE_H_H
#error "headstage_*.h has be included"
#endif
#ifndef HEADSTAGE_TNI_H
#define HEADSTAGE_H_H
#define HEADSTAGE_TNI_H
// product information
#define DEVICE_NAME "Elite-v0.2"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 1
#define MAJOR_VERSION_NUMBER 0
#define MINOR_VERSION_NUMBER 1
// header
#include <ti/drivers/PIN.h>
#include "board.h"
/*============
==== SPI ====
===========*/
/* application use SPI parameters and buffers */
#define SPI_BUFFER_SIZE 16
static uint8_t spi_txbuf[SPI_BUFFER_SIZE] = {0};
static uint8_t spi_rxbuf[SPI_BUFFER_SIZE] = {0};
static SPI_Handle spi_handle = NULL;
static SPI_Transaction spi_transaction;
#define headstage_spi_transaction(length, spi_txbuf, spi_rxbuf) \
do { \
if (spi_handle != NULL) { \
spi_transaction.count = (length); \
spi_transaction.txBuf = (spi_txbuf); \
spi_transaction.rxBuf = (spi_rxbuf); \
SPI_transfer(spi_handle, &spi_transaction); \
} \
} while (0)
/*=============================
==== headstage variable ====
============================*/
PIN_Handle pin_handle;
static PIN_State DBS_rst;
// DBS reset pin
const PIN_Config BLE_IO[] = {
//
IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, // S2P_RST
IOID_13 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,// P2S_RST
PIN_TERMINATE //
};
/**
* ADC clock switch signal.
*/
static bool adc_clock_signal = FALSE;
/*
* amplifier reset
*/
static bool amp_rst = FALSE;
/**
* stimulation frequency fixed-value table.
*/
static uint32_t sti_freq_table[] = {
15,
25,
40,
50,
100,
250,
400,
500,
1000,
2500,
4000,
5000,
5000, // 12
5000, // 13
5000, // 14
5000, // 15
};
/**
* ADC clock/sampling rate fixed-value table
*/
static uint32_t adc_clock_table[] = {
30,
50,
80,
100,
200,
500,
800,
1000,
2000,
5000,
8000,
10000,
10000, // 12
10000, // 13
10000, // 14
10000, // 15
};
/*=============================
==== ramp data generating ====
============================*/
static uint16_t ramp_data_counter = 0;
static void create_ramp(uint8_t *buff) {
buff[0] = 0b10110000 | (0b00001111 & (uint8_t)(ramp_data_counter >> 6));
buff[1] = (uint8_t)(ramp_data_counter << 2);
ramp_data_counter += 1;
}
/*=======================================
==== headstage function implemented ====
======================================*/
static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t ins_op, uint8_t ins_len, uint8_t *ins);
static uint8 swap_gain(uint8 gain){
return 0x03 & (((gain & 0b10) >> 1) | ((gain & 0b01) << 1));
}
static uint8 swap_lbf(uint8 lbf){
return 0x07 & (((lbf & 0b100) >> 2) | ((lbf & 0b010)) | ((lbf & 0b001) << 2));
}
static uint8 swap_sti_volt(uint8 sti_volt){
return 0x1f & (((sti_volt & 0b10000) >> 4) | ((sti_volt & 0b01000) >> 2) | (sti_volt & 0b00100) | ((sti_volt & 0b00010) << 2) | ((sti_volt & 0b00001) << 4));
}
/**
*
* change channel value to little endian
*/
static uint8 encode_channel(uint8 channel) {
return 0x0F & (((channel & 0b1000) >> 3) | //
((channel & 0b0100) >> 1) | //
((channel & 0b0010) << 1) | //
((channel & 0b0001) << 3));
}
/**
* initialize parameter and device.
*/
static void headstage_init() {
// spi init
SPI_Params spi_params;
SPI_init();
SPI_Params_init(&spi_params);
spi_params.dataSize = 8;
spi_params.frameFormat = SPI_POL0_PHA1;
spi_params.bitRate = 12000000;
spi_params.mode = SPI_MASTER;
spi_handle = SPI_open(Board_SPI0, &spi_params);
// init gptimer
headstage_gptimer_init();
// update instruction callback
set_update_instruction_callback(headstage_tni_update_instruction_callback);
// initialize the DBS reset pin
pin_handle = PIN_open(&DBS_rst, BLE_IO);
PIN_setOutputValue(pin_handle, IOID_9, 1);
}
/**
* change the recording clock bit in the instruction buffer.
*/
static void update_ins_rec_clock(uint8_t *buf, bool adc_clock_signal) {
buf[3] = (buf[3] & 0b11110000) | ((adc_clock_signal) ? 0b1000 : 0);
}
/**
* change the recording channel bit in the instruction buffer.
*/
static void update_ins_rec_channel(uint8_t *buf, uint8 channel) {
buf[1] = (buf[1] & 0b00001111) | (encode_channel(channel) << 4);
}
/**
* change the stimulation enable bit in the instruction buffer.
*/
static void update_ins_sti_enable(uint8_t *buf, bool enable) {
buf[1] = (buf[1] & 0b11111101) | ((enable) ? 0b10 : 0);
}
/**
* change the stimulating channel bit in the instruction buffer.
*/
static void update_ins_sti_channel(uint8_t *buf, uint8 sti_chp, uint8 sti_chn) {
buf[2] = (buf[2] & 0b11110000) | encode_channel(sti_chp);
buf[3] = (buf[3] & 0b00001111) | (encode_channel(sti_chn) << 4);
}
static void update_ins_buffer() {
uint8 header = 0b10100000;
uint8 amp_gain = (swap_gain(INSTRUCTION.amp_gain) & 0b11) << 3;
uint8 amp_lbf = swap_lbf(INSTRUCTION.amp_low_band_freq) & 0b111;
uint8 channel = 0; // should be call update_ins_channel to modify this value
uint8 chopper = (INSTRUCTION.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (INSTRUCTION.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (INSTRUCTION.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (swap_sti_volt(INSTRUCTION.sti_volt) & 0b10000) >> 4;
uint8 sti_volt_h = (swap_sti_volt(INSTRUCTION.sti_volt) & 0b01111) << 4;
uint8 sti_chp = INSTRUCTION.sti_channel_pmos & 0b1111;
uint8 sti_chn = (INSTRUCTION.sti_channel_nmos & 0b1111) << 4;
uint8 clk_signal = 0; // should be call update_ins_clock to modify this value
if(amp_rst){
amp_rst = 0;
fast_settle = 0b0001000;
}
spi_txbuf[0] = header | amp_gain | amp_lbf;
spi_txbuf[1] = channel | chopper | fast_settle | sti_enable | sti_volt_l;
spi_txbuf[2] = sti_volt_h | sti_chp;
spi_txbuf[3] = sti_chn | clk_signal;
}
static bool next_active_channel() {
// find next enable channel
channel_pointer += 1;
while (channel_pointer < CHANNEL_COUNT && !channel_table[channel_pointer]) {
channel_pointer++;
}
if (channel_pointer >= CHANNEL_COUNT) {
// channel to to the end of the channel_table, set to the beginning and re-search enable channel.
channel_pointer = 0;
while (channel_pointer < CHANNEL_COUNT && !channel_table[channel_pointer]) {
channel_pointer++;
}
if (channel_pointer >= CHANNEL_COUNT) {
// no channel enable, return directly
channel_pointer = -1;
return false;
}
}
return true;
}
static bool update_ins_rec_buffer() {
adc_clock_signal = (adc_clock_signal) ? FALSE : TRUE; // switch adc_clock
update_ins_rec_clock(spi_txbuf, adc_clock_signal);
if (adc_clock_signal) {
// change to next channel
display_ch = channel_pointer;
if (next_active_channel()) {
update_ins_rec_channel(spi_txbuf, channel_pointer);
} else {
// no channel active
return false;
}
}
return true;
}
/**
* Change the instruction content for SPI buffer, which is depended on the
* work_mode. Expend the remind instruction according to the base instruction
* which allocated at the beginning 4 bytes of the SPI buffer.
*
* ========= ===========
* work_mode ins pattern
* ========= ===========
* POS, NEG 4 F D 0
* P2N, N2P 4 4' F D
* AWF not impl
* ========= ===========
*
* pattern *4*
* stimulation instruction.
*
* pattern *F*
* set pmos channel to 0xF, release the remain voltage in the capacitance.
*
* pattern *D*
* disable stimulation
*
* pattern *0*
* nop.
*
* @param: buf: pointer of the SPI buffer.
*/
static void update_ins_sti_buffer() {
switch (INSTRUCTION.work_mode) {
case STI_MODE_POS:
case STI_MODE_NEG:
// copy [4:7]
spi_txbuf[4] = spi_txbuf[0];
spi_txbuf[5] = spi_txbuf[1];
spi_txbuf[6] = spi_txbuf[2];
spi_txbuf[7] = spi_txbuf[3];
// copy [8:B]
spi_txbuf[8] = spi_txbuf[0];
spi_txbuf[9] = spi_txbuf[1];
spi_txbuf[10] = spi_txbuf[2];
spi_txbuf[11] = spi_txbuf[3];
// reset [C:F]
spi_txbuf[12] = 0;
spi_txbuf[13] = 0;
spi_txbuf[14] = 0;
spi_txbuf[15] = 0;
// change content
update_ins_sti_enable(spi_txbuf, TRUE);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, 0xF, INSTRUCTION.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, FALSE);
break;
case STI_MODE_P2N:
case STI_MODE_N2P:
// copy [4:7]
spi_txbuf[4] = spi_txbuf[0];
spi_txbuf[5] = spi_txbuf[1];
spi_txbuf[6] = spi_txbuf[2];
spi_txbuf[7] = spi_txbuf[3];
// copy [8:B]
spi_txbuf[8] = spi_txbuf[0];
spi_txbuf[9] = spi_txbuf[1];
spi_txbuf[10] = spi_txbuf[2];
spi_txbuf[11] = spi_txbuf[3];
// copy [C:F]
spi_txbuf[12] = spi_txbuf[0];
spi_txbuf[13] = spi_txbuf[1];
spi_txbuf[14] = spi_txbuf[2];
spi_txbuf[15] = spi_txbuf[3];
// change content
update_ins_sti_enable(spi_txbuf + 0, TRUE);
update_ins_sti_channel(spi_txbuf + 0, INSTRUCTION.sti_channel_pmos, INSTRUCTION.sti_channel_nmos);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, INSTRUCTION.sti_channel_nmos, INSTRUCTION.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, TRUE);
update_ins_sti_channel(spi_txbuf + 8, 0xF, INSTRUCTION.sti_channel_nmos);
// ins buf [C:F]
update_ins_sti_enable(spi_txbuf + 12, FALSE);
break;
case STI_MODE_AWF:
// XXX define the voltage change
break;
default:
// do nothing
break;
}
}
static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t ins_op, uint8_t ins_len, uint8_t *ins) {
switch (ins_type) {
case INS_TYPE_VIS: {
switch (ins_op) {
// reset
case VIS_RST:
// reset. reset all variable
adc_clock_signal = FALSE;
memset(spi_txbuf, 0, SPI_BUFFER_SIZE);
break;
// interrupt
case VIS_INT:
// stop. reset channel table
ramp_data_counter = 0;
memset(spi_txbuf, 0, SPI_BUFFER_SIZE);
break;
}
}
}
// update_clock_period
uint32_t frequency = 0;
if (INSTRUCTION.frequency_mode == FREQ_MODE_INDEX) {
if (IS_REC_MODE(INSTRUCTION.work_mode) || IS_ARM_MODE(INSTRUCTION.work_mode)) {
// recording mode
frequency = adc_clock_table[INSTRUCTION.frequency];
} else if (IS_STI_MODE(INSTRUCTION.work_mode)) {
// stimulation mode
frequency = sti_freq_table[INSTRUCTION.frequency];
}
} else {
frequency = INSTRUCTION.frequency;
}
if (frequency > 0) {
headstage_gptimer_set_frequency(frequency);
}
// update instruction buffer
update_ins_buffer();
}
static void spi_transact_rec_instruction() {
if (IS_REC_MODE(INSTRUCTION.work_mode)) {
PIN_setOutputValue(pin_handle, IOID_13, 1); // DBS_P2S turn on
headstage_spi_transaction(SPI_BUFFER_SIZE, spi_txbuf, spi_rxbuf);
PIN_setOutputValue(pin_handle, IOID_13, 0); // DBS_P2S turn off
} else if (IS_ARM_MODE(INSTRUCTION.work_mode) && !adc_clock_signal) {
create_ramp(spi_rxbuf);
}
if (!adc_clock_signal) {
if(adc_clock_table[INSTRUCTION.frequency] >= 1000){
collect_data(spi_rxbuf);
} // high sampling rate data format
else{
collect_low_freq_data(spi_rxbuf);// low sampling rate data format check
}
}
}
static void headstage_periodic_handle() {
if (!flag_start) return;
if (IS_REC_MODE(INSTRUCTION.work_mode) || IS_ARM_MODE(INSTRUCTION.work_mode)) {
// recording mode or artifact recording mode
if (update_ins_rec_buffer()) {
spi_transact_rec_instruction();
}
} else if (IS_STI_MODE(INSTRUCTION.work_mode)) {
// stimulation mode
update_ins_sti_buffer();
headstage_spi_transaction(16, spi_txbuf, NULL);
}
}
static void reset_amp(){
amp_rst = 1;
}
#endif
@@ -0,0 +1,10 @@
@startuml
(*) --> "check input"
If "input is verbose" then
--> [Yes] "turn on verbosity"
--> "run command"
else
--> "run command"
Endif
-->(*)
@enduml
@@ -0,0 +1,407 @@
{
"name": "Elite",
"version": "0.1",
"match_rule": {
"local_name_pattern": "Elite.*",
"major_product_number": 0,
"minor_product_number": 1,
"major_version_number": 0,
"minor_version_number": 1
},
"constant": {
"REC_CHANNEL_COUNT": 16,
"STI_CHANNEL_COUNT": 15,
"ADC_SAMPLE_RATE_LIST": [
15,
25,
40,
50,
100,
250,
500,
1000,
2500,
4000,
5000
],
"STI_FREQ_LIST": [
15,
25,
40,
50,
100,
250,
500,
1000,
2500,
4000,
5000
]
},
"parameters": {
"MODE": {
"description": "working mode",
"domain": [
3
],
"value": [
"Recording Mode",
"Stimulation Mode",
"Artifact Mode"
]
},
"CHANNEL_NUMBER": {
"description": "record channels",
"record_meta": true,
"value": [
1,
4,
8,
16
]
},
"CHANNEL": {
"description": "record channels",
"record_meta": true,
"domain": "phanton",
"value": {
"expression": "CHANNEL_NUMBER",
"when": {
0:[1],
1:[1,2,3,4],
2:[1,2,3,4,5,6,7,8],
3:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
}
}
},
"SAMPLE_RATE": {
"alias": "ADC_RATE",
"description": "sampling rate",
"record_meta": true,
"domain": [
{
"expression": "len(ADC_SAMPLE_RATE_LIST)"
}
],
"value": {
"expression": "ADC_SAMPLE_RATE_LIST[VALUE]"
}
},
"AMP_GAIN": {
"description": "",
"record_meta": true,
"domain": [
3
],
"value": [
400,
1000,
2000
]
},
"LOW_FREQ_BAND": {
"description": "",
"record_meta": true,
"domain": [
7
]
},
"STI_MODE": {
"description": "stimulation mode",
"domain": [
5
],
"value": [
"Positive Pulse",
"Negative Pulse",
"Pos to Neg Pulse",
"Neg to Pos Pulse",
"Arbitrary Waveform"
]
},
"STI_VOLT": {
"description": "stimulation voltage",
"type": "float",
"domain": [
32
],
"value": {
"expression": "2 + 3 * VALUE / 31"
}
},
"STI_FREQ": {
"description": "stimulation frequency",
"type": "int",
"domain": [
{
"expression": "len(STI_FREQ_LIST)"
}
],
"value": {
"expression": "ADC_SAMPLE_RATE_LIST[VALUE]"
}
},
"STI_PMOS": {
"description": "stimulation PMOS channel",
"domain": [
"STI_CHANNEL_COUNT"
],
"guard": {
"expression": "VALUE != STI_NMOS"
}
},
"STI_NMOS": {
"description": "stimulation NMOS channel",
"domain": [
"STI_CHANNEL_COUNT"
],
"guard": {
"expression": "VALUE != STI_PMOS"
}
},
"CHOPPER": {
"description": "",
"domain": "bool"
},
"FAST_SETTLE": {
"description": "",
"domain": "bool"
}
},
"instruction": {
"reset": [
"IIS_NOT_OFF",
"VIS_RST"
],
"start": [
{
"expression": "MODE",
"when": {
"0": "start_recording",
"1": "start_stimulation",
"2": "start_artifact"
}
},
"VIS_STI"
],
"start_recording": [
{
"expression": "len(CHANNEL) > 0",
"raise": "no recording channel"
},
"IIS_NOT_ON",
"start_recording0",
"IIS_SYNC_START_DATA"
],
"start_artifact": [
{
"expression": "len(CHANNEL) > 0",
"raise": "no recording channel"
},
"IIS_NOT_ON",
"start_artifact0",
"IIS_SYNC_START_DATA"
],
"start_recording0": {
"type": "RIS",
"foreach-parameter": {
"parameter": "CHANNEL",
"variable": [
"a",
"b",
"c",
"d"
]
},
"data": [
"3b110#recording header;2bAMP_GAIN;3bLOW_FREQ_BAND",
"4bSAMPLE_RATE;1ba?;1bb?;1bc?;1bd?",
"4ba?:0;4bb?:0",
"4bc?:0;4bd?:0"
]
},
"start_artifact0": {
"type": "RIS",
"foreach-parameter": {
"parameter": "CHANNEL",
"variable": [
"a",
"b",
"c",
"d"
]
},
"data": [
"3b100#artifact mode header;2b0;3b001",
"4bSAMPLE_RATE;1ba?;1bb?;1bc?;1bd?",
"4ba?:0;4bb?:0",
"4bc?:0;4bd?:0"
]
},
"start_stimulation": [
"start_artifact0",
"IIS_SYNC_START"
],
"start_stimulation0": {
"type": "RIS",
"guard": {
"expression": "STI_PMOS != STI_NMOS",
"raise": "same N/PMos channel"
},
"data": [
"3b111#stimulation header;2b0;3bSTI_MODE",
"4bSTI_FREQ;1bCHOPPER;1bFAST_SETTLE;2b0",
"4bSTI_PMOS;4bSTI_NMOS",
"5bSTI_VOLT;3b0"
]
}
},
"event": {
},
"view": {
"stage": "canvas",
"root": {
"name": "root",
"text": "Elite Parameter Setting",
"content": [
"MODE",
"chip-parameter"
]
},
"parameter": {
"MODE": {
"name": "chip-mode",
"text": "Chip working mode"
},
"CHANNEL_NUMBER": {
"name": "channel-number",
"text": "chip recording channel number"
},
"CHANNEL": {
"name": "chip-channel",
"text": "chip recording channels"
},
"SAMPLE_RATE": {
"name": "chip-adc-clock",
"text": "recording sampling rate",
"unit": "Hz",
"value": [
"15",
"25",
"40",
"50",
"100",
"250",
"500",
"1K",
"2.5K",
"4K",
"5K"
]
},
"LOW_FREQ_BAND": {
"name": "chip-low-freq-band",
"text": "low frequency band",
"value": [
"1 (highest)",
"2",
"3",
"4",
"5",
"6",
"7 (lowest)"
]
},
"AMP_GAIN": {
"name": "chip-amp-gain",
"text": "AMP gain"
},
"STI_MODE": {
"name": "chip-sti-mode",
"text": "stimulation shape"
},
"STI_PMOS": {
"name": "chip-sti-channel-pmos",
"text": "stimulation PMos channel"
},
"STI_NMOS": {
"name": "chip-sti-channel-nmos",
"text": "stimulation NMos channel"
},
"STI_VOLT": {
"name": "chip-sti-volt",
"text": "stimulation voltage",
"unit": "mV",
"continuous": true
},
"STI_FREQ": {
"name": "chip-sti-freq",
"text": "stimulation frequency",
"unit": "Hz",
"value": [
"15",
"25",
"40",
"50",
"100",
"250",
"500",
"1K",
"2.5K",
"4K",
"5K"
]
},
"FAST_SETTLE": {
"name": "chip-sti-fast-settle",
"text": "fast settle"
},
"CHOPPER": {
"name": "chip-sti-chopper",
"text": "chopper"
}
},
"component": {
"chip-parameter": {
"parameter": "MODE",
"content": [
{
"expression": "MODE",
"when": {
"1": "chip-stimulation",
"*": "chip-recording"
}
}
]
},
"chip-recording": {
"text": "Recording Parameter",
"content": [
"CHANNEL_NUMBER",
"chip_channel",
"SAMPLE_RATE",
"LOW_FREQ_BAND",
"AMP_GAIN"
]
},
"chip-stimulation": {
"text": "Stimulation Parameter",
"content": [
"STI_MODE",
"STI_PMOS",
"STI_NMOS",
"STI_VOLT",
"STI_FREQ",
"FAST_SETTLE",
"CHOPPER"
]
},
"chip-channel": {
"parameter": "CHANNEL_NUMBER",
"content": [
"CHANNEL"
]
},
}
}
}
@@ -0,0 +1,10 @@
@startuml
(*) --> "check input"
If "input is verbose" then
--> [Yes] "turn on verbosity"
--> "run command"
else
--> "run command"
Endif
-->(*)
@enduml
@@ -136,7 +136,7 @@ PIN_Handle radCtrlHandle;
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
extern Display_Handle dispHandle;
//extern Display_Handle dispHandle;
/*******************************************************************************
* @fn Main
@@ -205,7 +205,6 @@ int main()
GAPRole_createTask();
SimpleBLEPeripheral_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
@@ -252,47 +251,47 @@ int main()
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
// Open the display if the app has not already done so
if ( !dispHandle )
{
dispHandle = Display_open(Display_Type_LCD, NULL);
}
// if ( !dispHandle )
// {
// dispHandle = Display_open(Display_Type_LCD, NULL);
// }
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
}
else
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
HAL_ASSERT_SPINLOCK;
break;
default:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
HAL_ASSERT_SPINLOCK;
}
// switch (assertCause)
// {
// case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
// Display_print0(dispHandle, 0, 0, "***ERROR***");
// Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
// break;
//
// case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// // check the subcause
// if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
// {
// Display_print0(dispHandle, 0, 0, "***ERROR***");
// Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
// }
// else
// {
// Display_print0(dispHandle, 0, 0, "***ERROR***");
// Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
// }
// break;
//
// case HAL_ASSERT_CAUSE_ICALL_ABORT:
// Display_print0(dispHandle, 0, 0, "***ERROR***");
// Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
// HAL_ASSERT_SPINLOCK;
// break;
//
// default:
// Display_print0(dispHandle, 0, 0, "***ERROR***");
// Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
// HAL_ASSERT_SPINLOCK;
// }
return;
}
@@ -77,8 +77,6 @@ extern "C"
* Task creation function for the Simple BLE Peripheral.
*/
extern void SimpleBLEPeripheral_createTask(void);
/*********************************************************************
*********************************************************************/
@@ -0,0 +1,299 @@
/******************************************************************************
@file main.c
@brief main entry of the BLE stack sample application.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
Copyright (c) 2013-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.
*****************************************************************************/
/*******************************************************************************
* INCLUDES
*/
#include <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "hal_assert.h"
#include "bcomdef.h"
#include "peripheral_observer.h"
#include "simple_peripheral_observer.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
#include <ti/mw/display/Display.h>
/*******************************************************************************
* MACROS
*/
/*******************************************************************************
* CONSTANTS
*/
/*******************************************************************************
* TYPEDEFS
*/
/*******************************************************************************
* LOCAL VARIABLES
*/
/*******************************************************************************
* GLOBAL VARIABLES
*/
#ifdef CC1350_LAUNCHXL
#ifdef POWER_SAVING
// Power Notify Object for wake-up callbacks
Power_NotifyObj rFSwitchPowerNotifyObj;
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
uint32_t *clientArg);
#endif //POWER_SAVING
PIN_State radCtrlState;
PIN_Config radCtrlCfg[] =
{
Board_DIO1_RFSW | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4GHz path*/
Board_DIO30_SWPWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Power to the RF Switch */
PIN_TERMINATE
};
PIN_Handle radCtrlHandle;
#endif //CC1350_LAUNCHXL
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
extern Display_Handle dispHandle;
/*******************************************************************************
* @fn Main
*
* @brief Application Main
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
int main()
{
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
#ifdef CC1350_LAUNCHXL
// Enable 2.4GHz Radio
radCtrlHandle = PIN_open(&radCtrlState, radCtrlCfg);
#ifdef POWER_SAVING
Power_registerNotify(&rFSwitchPowerNotifyObj,
PowerCC26XX_ENTERING_STANDBY | PowerCC26XX_AWAKE_STANDBY,
(Power_NotifyFxn) rFSwitchNotifyCb, NULL);
#endif //POWER_SAVING
#endif //CC1350_LAUNCHXL
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif // POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPRole_createTask();
SimpleBLEPeripheral_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
/*******************************************************************************
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
* in the stack.
*
* input parameters
*
* @param assertCause - Assert cause as defined in hal_assert.h.
* @param assertSubcause - Optional assert subcause (see hal_assert.h).
*
* output parameters
*
* @param None.
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
// Open the display if the app has not already done so
if ( !dispHandle )
{
dispHandle = Display_open(Display_Type_LCD, NULL);
}
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
}
else
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
HAL_ASSERT_SPINLOCK;
break;
default:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
HAL_ASSERT_SPINLOCK;
}
return;
}
/*******************************************************************************
* @fn smallErrorHook
*
* @brief Error handler to be hooked into TI-RTOS.
*
* input parameters
*
* @param eb - Pointer to Error Block.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void smallErrorHook(Error_Block *eb)
{
for (;;);
}
#if defined (CC1350_LAUNCHXL) && defined (POWER_SAVING)
/*******************************************************************************
* @fn rFSwitchNotifyCb
*
* @brief Power driver callback to toggle RF switch on Power state
* transitions.
*
* input parameters
*
* @param eventType - The state change.
* @param eventArg - Not used.
* @param clientArg - Not used.
*
* @return Power_NOTIFYDONE to indicate success.
*/
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
uint32_t *clientArg)
{
if (eventType == PowerCC26XX_ENTERING_STANDBY)
{
// Power down RF Switch
PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 0);
}
else if (eventType == PowerCC26XX_AWAKE_STANDBY)
{
// Power up RF Switch
PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 1);
}
// Notification handled successfully
return Power_NOTIFYDONE;
}
#endif //CC1350_LAUNCHXL || POWER_SAVING
/*******************************************************************************
*/
@@ -1,49 +1,42 @@
/******************************************************************************
@file simple_peripheral.c
@brief This file contains the Simple BLE Peripheral sample application for use
with the CC2650 Bluetooth Low Energy Protocol Stack.
Group: WCS, BTS
Target Device: CC2650, CC2640
******************************************************************************
Copyright (c) 2013-2018, 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.
******************************************************************************
Release Name: ble_sdk_2_02_02_25
Release Date: 2018-04-02 18:03:35
*****************************************************************************/
/*
* Filename: simple_peripheral_observer.c
*
* Description: This is the simple_central example modified to receive
* data over BLE at a high throughput.
*
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
*
*
* 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.
*
*/
/*********************************************************************
* INCLUDES
@@ -55,14 +48,6 @@
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Queue.h>
#include <driverlib/ssi.h>
#include "board.h"
#include <ti/drivers/SPI.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/spi/SPICC26XXDMA.h>
#include <ti/drivers/dma/UDMACC26XX.h>
#include "hci_tl.h"
#include "gatt.h"
#include "linkdb.h"
@@ -76,7 +61,7 @@
#include "oad.h"
#endif //FEATURE_OAD || IMAGE_INVALIDATE
#include "peripheral.h"
#include "peripheral_observer.h"
#include "gapbondmgr.h"
#include "osal_snv.h"
@@ -93,12 +78,8 @@
#include "board.h"
#include "simple_peripheral.h"
#include <C:\Users\s8807\workspace_v8\simple_peripheral_cc2650lp_app\SPI_INTERFACE.h>
#include "simple_peripheral_observer.h"
#if defined( USE_FPGA ) || defined( DEBUG_SW_TRACE )
#include <driverlib/ioc.h>
#endif // USE_FPGA | DEBUG_SW_TRACE
/*********************************************************************
* CONSTANTS
@@ -138,13 +119,38 @@
// Whether to enable automatic parameter update request when a connection is
// formed
#define DEFAULT_ENABLE_UPDATE_REQUEST GAPROLE_LINK_PARAM_UPDATE_INITIATE_BOTH_PARAMS
#define DEFAULT_ENABLE_UPDATE_REQUEST TRUE
// Connection Pause Peripheral time value (in seconds)
#define DEFAULT_CONN_PAUSE_PERIPHERAL 6
// How often to perform periodic event (in msec)
#define SBP_PERIODIC_EVT_PERIOD 1000
#define SBP_PERIODIC_EVT_PERIOD 5000
#ifdef PLUS_OBSERVER
// Maximum number of scan responses
#define DEFAULT_MAX_SCAN_RES 50//8
// Scan duration in ms
#define DEFAULT_SCAN_DURATION 5000
// Scan interval in ms
#define DEFAULT_SCAN_INTERVAL 10
// Scan interval in ms
#define DEFAULT_SCAN_WINDOW 5
// Discovey mode (limited, general, all)
#define DEFAULT_DISCOVERY_MODE DEVDISC_MODE_ALL
// TRUE to use active scan
#define DEFAULT_DISCOVERY_ACTIVE_SCAN TRUE
// TRUE to use white list during discovery
#define DEFAULT_DISCOVERY_WHITE_LIST FALSE
#endif //#ifdef PLUS_OBSERVER
#ifdef FEATURE_OAD
// The size of an OAD packet.
@@ -165,10 +171,10 @@
#define SBP_PERIODIC_EVT 0x0004
#define SBP_CONN_EVT_END_EVT 0x0008
// Instruction type for DBS
#define REAL_INSTR 0x30
#define VIRTUAL_INSTR 0xC0
#define DATA_RECEIVE 0XA0
#ifdef PLUS_OBSERVER
#define SBP_KEY_CHANGE_EVT 0x0010
#define SBP_OBSERVER_STATE_CHANGE_EVT 0x0020
#endif
/*********************************************************************
* TYPEDEFS
@@ -178,10 +184,11 @@
typedef struct
{
appEvtHdr_t hdr; // event header.
#ifdef PLUS_OBSERVER
uint8 *pData; // event data pointer
#endif
} sbpEvt_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
@@ -189,26 +196,6 @@ typedef struct
// Display Interface
Display_Handle dispHandle = NULL;
// just transmit ten sample of data
uint8 transmit_time = 0;
// to make adc clock switch
bool clk_count = 0;
// DBS instruction data by ble
int DBS_ins = 0;
// DBS reset pin
const PIN_Config BLE_IO[] = {
Board_DIO0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
PIN_TERMINATE
};
PIN_Handle pin_handle;
static PIN_State DBS_rst;
/*********************************************************************
* LOCAL VARIABLES
*/
@@ -239,9 +226,6 @@ static uint16_t events;
Task_Struct sbpTask;
Char sbpTaskStack[SBP_TASK_STACK_SIZE];
Task_Struct spiTask;
Char spiTaskStack[SBP_TASK_STACK_SIZE];
// Profile state and parameters
//static gaprole_States_t gapProfileState = GAPROLE_INIT;
@@ -249,31 +233,38 @@ Char spiTaskStack[SBP_TASK_STACK_SIZE];
static uint8_t scanRspData[] =
{
// complete name
// local complete name
0x0F, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
'B',
'P',
'S',
' ',
'H',
'e',
'a',
'd',
'S',
't',
'a',
'g',
'e',
'e',
0x13, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
'P',
'e',
'r',
'i',
'p',
'h',
'e',
'r',
'a',
'l',
'O',
'b',
's',
'e',
'r',
'v',
'e',
'r',
// connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
LO_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL), // 100ms
HI_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL),
LO_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL), // 1s
HI_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL),
// Manufacturer specific information
0x05,
GAP_ADTYPE_MANUFACTURER_SPECIFIC,
0x42,
0x95,
0x05,
0x23,
// Tx power level
0x02, // length of this data
GAP_ADTYPE_POWER_LEVEL,
0 // 0dBm
};
// GAP - Advertisement data (max size = 31 bytes, though this is
@@ -306,27 +297,36 @@ static uint8_t advertData[] =
};
// GAP GATT Attributes
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "Simple BLE Peripheral";
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "Peripheral Observer";
// Globals used for ATT Response retransmission
static gattMsgEvent_t *pAttRsp = NULL;
static uint8_t rspTxRetry = 0;
#ifdef PLUS_OBSERVER
static bool scanningStarted = FALSE;
static uint8_t deviceInfoCnt = 0;
#endif
const char *AdvTypeStrings[] = {"Connectable undirected","Connectable directed", "Scannable undirected", "Non-connectable undirected", "Scan response"};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void SimpleBLEPeripheral_init( void );
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1);
static void SPI_MAIN(UArg a0, UArg a1);
static uint8_t SimpleBLEPeripheral_processStackMsg(ICall_Hdr *pMsg);
static uint8_t SimpleBLEPeripheral_processGATTMsg(gattMsgEvent_t *pMsg);
static void SimpleBLEPeripheral_processAppMsg(sbpEvt_t *pMsg);
static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState);
static void SimpleBLEPeripheral_processCharValueChangeEvt(uint8_t paramID);
static void SimpleBLEPeripheral_performPeriodicTask(uint8_t* rxbuf,uint8_t* txbuf);
static void SimpleBLEPeripheral_performPeriodicTask(void);
static void SimpleBLEPeripheral_clockHandler(UArg arg);
#ifdef PLUS_OBSERVER
void SimpleBLEPeripheral_keyChangeHandler(uint8 keysPressed);
static void SimpleBLEPeripheral_ObserverStateChangeCB(gapPeripheralObserverRoleEvent_t *pEvent);
#endif
static void SimpleBLEPeripheral_sendAttRsp(void);
static void SimpleBLEPeripheral_freeAttRsp(uint8_t status);
@@ -335,22 +335,13 @@ static void SimpleBLEPeripheral_stateChangeCB(gaprole_States_t newState);
#ifndef FEATURE_OAD_ONCHIP
static void SimpleBLEPeripheral_charValueChangeCB(uint8_t paramID);
#endif //!FEATURE_OAD_ONCHIP
static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state);
static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state, uint8_t *pData);
#ifdef FEATURE_OAD
void SimpleBLEPeripheral_processOadWriteCB(uint8_t event, uint16_t connHandle,
uint8_t *pData);
#endif //FEATURE_OAD
// SPI interface
static SPI_Handle spiHandle = NULL;
static SPI_Params spiParams;
static SPI_Transaction transaction;
/*********************************************************************
* EXTERN FUNCTIONS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
/*********************************************************************
* PROFILE CALLBACKS
@@ -360,6 +351,10 @@ extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
static gapRolesCBs_t SimpleBLEPeripheral_gapRoleCBs =
{
SimpleBLEPeripheral_stateChangeCB // Profile State Change Callbacks
#ifdef PLUS_OBSERVER
,SimpleBLEPeripheral_ObserverStateChangeCB
#endif
};
// GAP Bond Manager Callbacks
@@ -400,22 +395,14 @@ static oadTargetCBs_t simpleBLEPeripheral_oadCBs =
void SimpleBLEPeripheral_createTask(void)
{
Task_Params taskParams;
Task_Params spitaskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = sbpTaskStack;
taskParams.stackSize = SBP_TASK_STACK_SIZE;
taskParams.priority = 2;
Task_Params_init(&spitaskParams);
spitaskParams.stack = spiTaskStack;
spitaskParams.stackSize = SBP_TASK_STACK_SIZE;
spitaskParams.priority = 1;
taskParams.priority = SBP_TASK_PRIORITY;
Task_construct(&sbpTask, SimpleBLEPeripheral_taskFxn, &taskParams, NULL);
Task_construct(&spiTask, SPI_MAIN ,&spitaskParams , NULL);
}
/*********************************************************************
@@ -443,34 +430,39 @@ static void SimpleBLEPeripheral_init(void)
RCOSC_enableCalibration();
#endif // USE_RCOSC
#if defined( USE_FPGA )
// configure RF Core SMI Data Link
IOCPortConfigureSet(IOID_12, IOC_PORT_RFC_GPO0, IOC_STD_OUTPUT);
IOCPortConfigureSet(IOID_11, IOC_PORT_RFC_GPI0, IOC_STD_INPUT);
// configure RF Core SMI Command Link
IOCPortConfigureSet(IOID_10, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_OUT, IOC_STD_OUTPUT);
IOCPortConfigureSet(IOID_9, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_IN, IOC_STD_INPUT);
// configure RF Core tracer IO
IOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT);
#else // !USE_FPGA
#if defined( DEBUG_SW_TRACE )
// configure RF Core tracer IO
IOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT | IOC_CURRENT_4MA | IOC_SLEW_ENABLE);
#endif // DEBUG_SW_TRACE
#endif // USE_FPGA
// Create an RTOS queue for message from profile to be sent to app.
appMsgQueue = Util_constructQueue(&appMsg);
// SPI_INTERFACE_AddService();
// Create one-shot clocks for internal periodic events.
Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler,
SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT);
dispHandle = Display_open(Display_Type_LCD, NULL);
#ifdef PLUS_OBSERVER
Board_initKeys(SimpleBLEPeripheral_keyChangeHandler);
#endif
dispHandle = Display_open(Display_Type_UART, NULL); //ZH change to UART for LP UART support
#ifdef PLUS_OBSERVER
//Setup GAP Observer params
{
uint8_t scanRes = DEFAULT_MAX_SCAN_RES;
GAPRole_SetParameter(GAPROLE_MAX_SCAN_RES, sizeof(uint8_t),
&scanRes);
// Set the GAP Characteristics
GAP_SetParamValue(TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION); //how long to scan (in scan state)
GAP_SetParamValue(TGAP_LIM_DISC_SCAN, DEFAULT_SCAN_DURATION);
//Set scan interval
GAP_SetParamValue(TGAP_GEN_DISC_SCAN_INT, (DEFAULT_SCAN_INTERVAL)/(0.625)); //period for one scan channel
//Set scan window
GAP_SetParamValue(TGAP_GEN_DISC_SCAN_WIND, (DEFAULT_SCAN_WINDOW)/(0.625)); //active scanning time within scan interval
}
#endif
// Setup the GAP
GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);
@@ -567,18 +559,18 @@ static void SimpleBLEPeripheral_init(void)
{
uint8_t charValue1 = 1;
uint8_t charValue2 = 2;
uint8_t charValue3[SIMPLEPROFILE_CHAR3_LEN] = { 0 };
uint8_t charValue4[SIMPLEPROFILE_CHAR4_LEN] = { 0 };
uint8_t charValue3 = 3;
uint8_t charValue4 = 4;
uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(uint8_t),
&charValue1);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint8_t),
&charValue2);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, SIMPLEPROFILE_CHAR3_LEN,
charValue3);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, SIMPLEPROFILE_CHAR4_LEN,
charValue4);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, sizeof(uint8_t),
&charValue3);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t),
&charValue4);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN,
charValue5);
}
@@ -607,8 +599,12 @@ static void SimpleBLEPeripheral_init(void)
#else
Display_print0(dispHandle, 0, 0, "BLE Peripheral B");
#endif // HAL_IMAGE_A
#else
#ifdef PLUS_OBSERVER
Display_print0(dispHandle, 0, 0, "BLE Peripheral Observer");
#else
Display_print0(dispHandle, 0, 0, "BLE Peripheral");
#endif
#endif // FEATURE_OAD
}
@@ -621,22 +617,20 @@ static void SimpleBLEPeripheral_init(void)
*
* @return None.
*/
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
{
// Initialize application
SimpleBLEPeripheral_init();
// Application main loop
for (;;)
{
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
// ICall_signal() function is called onto the semaphore.
ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
if (errno == ICALL_ERRNO_SUCCESS)
{
ICall_EntityID dest;
@@ -682,6 +676,7 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
{
// Process message.
SimpleBLEPeripheral_processAppMsg(pMsg);
// Free the space from the message.
ICall_free(pMsg);
}
@@ -694,12 +689,14 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
Util_startClock(&periodicClock);
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask();
}
#ifdef FEATURE_OAD
while (!Queue_empty(hOadQ))
{
oadTargetWrite_t *oadWriteEvt = Queue_get(hOadQ);
oadTargetWrite_t *oadWriteEvt = Queue_dequeue(hOadQ);
// Identify new image.
if (oadWriteEvt->event == OAD_WRITE_IDENTIFY_REQ)
@@ -719,6 +716,95 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
}
}
/*********************************************************************
* @fn Util_convertBytes2Str
*
* @brief Convert bytes to string. Used to print advertising data.
*
*
* @param pData - data
*
* @return Adv/Scan data as a string
*/
char *Util_convertBytes2Str(uint8_t *pData, uint8_t length)
{
uint8_t charCnt;
char hex[] = "0123456789ABCDEF";
static char str[(3*31)+1];
char *pStr = str;
//*pStr++ = '0';
//*pStr++ = 'x';
for (charCnt = 0; charCnt < length; charCnt++)
{
*pStr++ = hex[*pData >> 4];
*pStr++ = hex[*pData++ & 0x0F];
*pStr++ = ':';
}
pStr = NULL;
return str;
}
#ifdef PLUS_OBSERVER
/*********************************************************************
* @fn SimpleBLECentral_processRoleEvent
*
* @brief Central role event processing function.
*
* @param pEvent - pointer to event structure
*
* @return none
*/
static void SimpleBLEPeripheralObserver_processRoleEvent(gapPeripheralObserverRoleEvent_t *pEvent)
{
switch (pEvent->gap.opcode)
{
case GAP_DEVICE_INFO_EVENT:
{
//Print scan response data otherwise advertising data
if(pEvent->deviceInfo.eventType == GAP_ADRPT_SCAN_RSP)
{
Display_print1(dispHandle, 4, 0, "Scan Response Addr: %s", Util_convertBdAddr2Str(pEvent->deviceInfo.addr));
Display_print1(dispHandle, 5, 0, "Scan Response Data: %s", Util_convertBytes2Str(pEvent->deviceInfo.pEvtData, pEvent->deviceInfo.dataLen));
}
else
{
deviceInfoCnt++;
Display_print2(dispHandle, 6, 0, "Advertising Addr: %s Advertising Type: %s", Util_convertBdAddr2Str(pEvent->deviceInfo.addr), AdvTypeStrings[pEvent->deviceInfo.eventType]);
Display_print1(dispHandle, 7, 0, "Advertising Data: %s", Util_convertBytes2Str(pEvent->deviceInfo.pEvtData, pEvent->deviceInfo.dataLen));
}
ICall_free(pEvent->deviceInfo.pEvtData);
ICall_free(pEvent);
}
break;
case GAP_DEVICE_DISCOVERY_EVENT:
{
// discovery complete
scanningStarted = FALSE;
deviceInfoCnt = 0;
//Display_print0(dispHandle, 7, 0, "GAP_DEVICE_DISC_EVENT");
Display_print1(dispHandle, 5, 0, "Devices discovered: %d", pEvent->discCmpl.numDevs);
Display_print0(dispHandle, 4, 0, "Scanning Off");
ICall_free(pEvent->discCmpl.pDevList);
ICall_free(pEvent);
}
break;
default:
break;
}
}
#endif
/*********************************************************************
* @fn SimpleBLEPeripheral_processStackMsg
*
@@ -734,6 +820,12 @@ static uint8_t SimpleBLEPeripheral_processStackMsg(ICall_Hdr *pMsg)
switch (pMsg->event)
{
#ifdef PLUS_OBSERVER
case GAP_MSG_EVENT:
// Process GATT message
SimpleBLEPeripheralObserver_processRoleEvent((gapPeripheralObserverRoleEvent_t *)pMsg);
break;
#endif
case GATT_MSG_EVENT:
// Process GATT message
safeToDealloc = SimpleBLEPeripheral_processGATTMsg((gattMsgEvent_t *)pMsg);
@@ -748,12 +840,6 @@ static uint8_t SimpleBLEPeripheral_processStackMsg(ICall_Hdr *pMsg)
// Process HCI Command Complete Event
break;
case HCI_BLE_HARDWARE_ERROR_EVENT_CODE:
{
AssertHandler(HAL_ASSERT_CAUSE_HARDWARE_ERROR,0);
}
break;
default:
break;
}
@@ -891,6 +977,74 @@ static void SimpleBLEPeripheral_freeAttRsp(uint8_t status)
}
}
#ifdef PLUS_OBSERVER
/*********************************************************************
* @fn SimpleBLECentral_handleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void SimpleBLEPeripheral_handleKeys(uint8_t shift, uint8_t keys)
{
(void)shift; // Intentionally unreferenced parameter
if (keys & KEY_RIGHT)
{
uint8 status;
if(scanningStarted == TRUE)
{
status = GAPObserverRole_CancelDiscovery();
if(status == SUCCESS)
{
scanningStarted = FALSE;
Display_print0(dispHandle, 4, 0, "Scanning Off");
}
else
{
Display_print0(dispHandle, 4, 0, "Scanning Off Fail");
}
}
return;
}
if (keys & KEY_LEFT)
{
uint8 status;
//Start scanning if not already scanning
if((scanningStarted == FALSE))
{
status = GAPObserverRole_StartDiscovery(DEFAULT_DISCOVERY_MODE,
DEFAULT_DISCOVERY_ACTIVE_SCAN,
DEFAULT_DISCOVERY_WHITE_LIST);
if(status == SUCCESS)
{
scanningStarted = TRUE;
Display_print0(dispHandle, 4, 0, "Scanning On");
}
else
{
Display_print1(dispHandle, 4, 0, "Scanning failed: %d", status);
}
}
return;
}
}
#endif //#ifdef PLUS_OBSERVER
/*********************************************************************
* @fn SimpleBLEPeripheral_processAppMsg
*
@@ -913,12 +1067,103 @@ static void SimpleBLEPeripheral_processAppMsg(sbpEvt_t *pMsg)
SimpleBLEPeripheral_processCharValueChangeEvt(pMsg->hdr.state);
break;
#ifdef PLUS_OBSERVER
case SBP_KEY_CHANGE_EVT:
SimpleBLEPeripheral_handleKeys(0, pMsg->hdr.state);
break;
case SBP_OBSERVER_STATE_CHANGE_EVT:
SimpleBLEPeripheral_processStackMsg((ICall_Hdr *)pMsg->pData);
break;
#endif
default:
// Do nothing.
break;
}
}
#ifdef PLUS_OBSERVER
/*********************************************************************
* @fn SimpleBLEPeripheral_keyChangeHandler
*
* @brief Key event handler function
*
* @param a0 - ignored
*
* @return none
*/
void SimpleBLEPeripheral_keyChangeHandler(uint8 keys)
{
SimpleBLEPeripheral_enqueueMsg(SBP_KEY_CHANGE_EVT, keys, NULL);
}
/*********************************************************************
* @fn SimpleBLEPeripheral_ObserverStateChangeCB
*
* @brief Peripheral observer event callback function.
*
* @param pEvent - pointer to event structure
*
* @return TRUE if safe to deallocate event message, FALSE otherwise.
*/
static void SimpleBLEPeripheral_ObserverStateChangeCB(gapPeripheralObserverRoleEvent_t *pEvent)
{
sbpEvt_t *pMsg;
// Create dynamic pointer to message.
if ((pMsg = ICall_malloc(sizeof(sbpEvt_t))))
{
pMsg->hdr.event = SBP_OBSERVER_STATE_CHANGE_EVT;
pMsg->hdr.state = SUCCESS;
switch(pEvent->gap.opcode)
{
case GAP_DEVICE_INFO_EVENT:
{
gapDeviceInfoEvent_t *pDevInfoMsg;
pDevInfoMsg = ICall_malloc(sizeof(gapDeviceInfoEvent_t));
memcpy(pDevInfoMsg, pEvent, sizeof(gapDeviceInfoEvent_t));
pDevInfoMsg->pEvtData = ICall_malloc(pEvent->deviceInfo.dataLen);
memcpy(pDevInfoMsg->pEvtData, pEvent->deviceInfo.pEvtData, pEvent->deviceInfo.dataLen);
pMsg->pData = (uint8 *)pDevInfoMsg;
}
break;
case GAP_DEVICE_DISCOVERY_EVENT:
{
gapDevDiscEvent_t *pDevDiscMsg;
pDevDiscMsg = ICall_malloc(sizeof(gapDevDiscEvent_t));
memcpy(pDevDiscMsg, pEvent, sizeof(gapDevDiscEvent_t));
pDevDiscMsg->pDevList = ICall_malloc((pEvent->discCmpl.numDevs)*sizeof(gapDevRec_t));
memcpy(pDevDiscMsg->pDevList, pEvent->discCmpl.pDevList, (pEvent->discCmpl.numDevs)*sizeof(gapDevRec_t));
pMsg->pData = (uint8 *)pDevDiscMsg;
}
break;
default:
break;
}
// Enqueue the message.
Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
}
// Free the stack message
ICall_freeMsg(pEvent);
}
#endif
/*********************************************************************
* @fn SimpleBLEPeripheral_stateChangeCB
*
@@ -930,7 +1175,7 @@ static void SimpleBLEPeripheral_processAppMsg(sbpEvt_t *pMsg)
*/
static void SimpleBLEPeripheral_stateChangeCB(gaprole_States_t newState)
{
SimpleBLEPeripheral_enqueueMsg(SBP_STATE_CHANGE_EVT, newState);
SimpleBLEPeripheral_enqueueMsg(SBP_STATE_CHANGE_EVT, newState, NULL);
}
/*********************************************************************
@@ -991,7 +1236,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
*/
case GAPROLE_ADVERTISING_NONCONN:
{
uint8_t advertEnabled = true;//do some change to experiment
uint8_t advertEnabled = FALSE;
// Disable non-connectable advertising.
GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8_t),
@@ -1115,7 +1360,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
*/
static void SimpleBLEPeripheral_charValueChangeCB(uint8_t paramID)
{
SimpleBLEPeripheral_enqueueMsg(SBP_CHAR_CHANGE_EVT, paramID);
SimpleBLEPeripheral_enqueueMsg(SBP_CHAR_CHANGE_EVT, paramID, NULL);
}
#endif //!FEATURE_OAD_ONCHIP
@@ -1168,19 +1413,20 @@ static void SimpleBLEPeripheral_processCharValueChangeEvt(uint8_t paramID)
*
* @return None.
*/
static void SimpleBLEPeripheral_performPeriodicTask(uint8_t* rxbuf,uint8_t* txbuf)
static void SimpleBLEPeripheral_performPeriodicTask(void)
{
#ifndef FEATURE_OAD_ONCHIP
uint8_t valueToCopy;
// Call to retrieve the value of the third characteristic in the profile
if (SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, txbuf) == SUCCESS)
if (SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, &valueToCopy) == SUCCESS)
{
// Call to set that value of the fourth characteristic in the profile.
// Note that if notifications of the fourth characteristic have been
// enabled by a GATT client device, then a notification will be sent
// every time this function is called.
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, SIMPLEPROFILE_CHAR4_LEN,
rxbuf);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t),
&valueToCopy);
}
#endif //!FEATURE_OAD_ONCHIP
}
@@ -1214,7 +1460,7 @@ void SimpleBLEPeripheral_processOadWriteCB(uint8_t event, uint16_t connHandle,
oadWriteEvt->pData = (uint8_t *)(&oadWriteEvt->pData + 1);
memcpy(oadWriteEvt->pData, pData, OAD_PACKET_SIZE);
Queue_put(hOadQ, (Queue_Elem *)oadWriteEvt);
Queue_enqueue(hOadQ, (Queue_Elem *)oadWriteEvt);
// Post the application's semaphore.
Semaphore_post(sem);
@@ -1254,7 +1500,7 @@ static void SimpleBLEPeripheral_clockHandler(UArg arg)
*
* @return None.
*/
static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state)
static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state, uint8_t *pData)
{
sbpEvt_t *pMsg;
@@ -1271,96 +1517,3 @@ static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state)
/*********************************************************************
*********************************************************************/
static void SPI_MAIN(UArg a0, UArg a1)
{
uint8_t txbuf[8] = {0};
uint8_t rxbuf[8] = {0};
SPI_init();
// Application main loops
SPI_Params_init(&spiParams);
spiParams.bitRate = 1000000;
spiParams.mode = SPI_MASTER;
spiParams.dataSize = 8;
spiParams.frameFormat = SPI_POL0_PHA1;
spiHandle = SPI_open(Board_SPI0,&spiParams);
pin_handle = PIN_open(&DBS_rst,BLE_IO);
PIN_setOutputEnable(pin_handle,Board_DIO0,1);
while(1)
{
transaction.count = 8;
clk_count = (clk_count)?FALSE:TRUE;
transaction.rxBuf = rxbuf;
txbuf[3] = (clk_count)?0x88:0x80;
txbuf[1] = 0xF0 | txbuf[1];
transaction.txBuf = txbuf;
PIN_setOutputValue(pin_handle,Board_DIO0,1);
SPI_transfer(spiHandle,&transaction);
PIN_setOutputValue(pin_handle,Board_DIO0,0);
// SPI_close(spiHandle);
// PIN_close(pin_handle);
if(transmit_time < 10)
{
transmit_time++;
rxbuf[0] = 0xBF;
rxbuf[1] = 0xF0;
rxbuf[2] = 0x00;
rxbuf[3] = 0x00;
rxbuf[4] = 0x00;
rxbuf[5] = 0x00;
rxbuf[6] = 0x00;
rxbuf[7] = transmit_time;
}
else
{
transmit_time++;
rxbuf[2] = 0x00;
rxbuf[3] = 0x00;
rxbuf[4] = 0x00;
rxbuf[5] = 0x00;
rxbuf[6] = 0x00;
rxbuf[7] = transmit_time;
}
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask(rxbuf,txbuf);
switch(txbuf[0]){
case REAL_INSTR:
{
int i = 0;
uint8_t j = txbuf[1];
while(i < SIMPLEPROFILE_CHAR3_LEN)
{
uint8_t k = (uint8_t) i;
if(k < j)
txbuf[i] = txbuf[i+2];
else
txbuf[i] = 0x00;
i++;
}
break;
// txbuf[1] imply the instruction length (in bytes) we will receive
// e.g. : txbuf[1] == 0x04 , it means the data length is four bytes
}
case VIRTUAL_INSTR:
break;
default:
break;
}
}
}
@@ -0,0 +1,86 @@
/******************************************************************************
@file simple_peripheral_observer.h
@brief This file contains the Simple BLE Peripheral sample application
definitions and prototypes.
Group: WCS, BTS
Target Device: CC2650, CC2640, CC1350
******************************************************************************
Copyright (c) 2013-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.
*****************************************************************************/
#ifndef SIMPLEBLEPERIPHERAL_H
#define SIMPLEBLEPERIPHERAL_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* MACROS
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Task creation function for the Simple BLE Peripheral.
*/
extern void SimpleBLEPeripheral_createTask(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* SIMPLEBLEPERIPHERAL_H */
@@ -0,0 +1,244 @@
/******************************************************************************
@file main.c
@brief main entry of the BLE stack sample application.
Group: WCS, BTS
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2013 $
*****************************************************************************/
/*******************************************************************************
* INCLUDES
*/
#include <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include "icall.h"
#include "hal_assert.h"
#include "bcomdef.h"
#include "central.h"
#include "spp_ble_client.h"
#include "inc/sdi_task.h"
/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
/*******************************************************************************
* MACROS
*/
/*******************************************************************************
* CONSTANTS
*/
/*******************************************************************************
* TYPEDEFS
*/
/*******************************************************************************
* LOCAL VARIABLES
*/
/*******************************************************************************
* GLOBAL VARIABLES
*/
/*******************************************************************************
* EXTERNS
*/
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
extern uint16 dispHandle;
/*******************************************************************************
* @fn Main
*
* @brief Application Main
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
int main()
{
/* Register Application callback to trap asserts raised in the Stack */
RegisterAssertCback(AssertHandler);
PIN_init(BoardGpioInitTable);
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif // POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPCentralRole_createTask();
/* SDI UART Example Task - Priority 2 */
SDITask_createTask();
/* Kick off application - Priority 1 */
SPPBLEClient_createTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
/*******************************************************************************
* @fn AssertHandler
*
* @brief This is the Application's callback handler for asserts raised
* in the stack.
*
* input parameters
*
* @param assertCause - Assert cause as defined in hal_assert.h.
* @param assertSubcause - Optional assert subcause (see hal_assert.h).
*
* output parameters
*
* @param None.
*
* @return None.
*/
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
// Open the display if the app has not already done so
if ( !dispHandle )
{
//dispHandle = Display_open(Display_Type_LCD, NULL);
}
Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
// check the assert cause
switch (assertCause)
{
case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
break;
case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
// check the subcause
if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
}
else
{
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
}
break;
case HAL_ASSERT_CAUSE_ICALL_ABORT:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
HAL_ASSERT_SPINLOCK;
break;
default:
Display_print0(dispHandle, 0, 0, "***ERROR***");
Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
HAL_ASSERT_SPINLOCK;
}
return;
}
/*******************************************************************************
* @fn smallErrorHook
*
* @brief Error handler to be hooked into TI-RTOS.
*
* input parameters
*
* @param eb - Pointer to Error Block.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void smallErrorHook(Error_Block *eb)
{
for (;;);
}
#if defined (CC1350_LAUNCHXL) && defined (POWER_SAVING)
/*******************************************************************************
* @fn rFSwitchNotifyCb
*
* @brief Power driver callback to toggle RF switch on Power state
* transitions.
*
* input parameters
*
* @param eventType - The state change.
* @param eventArg - Not used.
* @param clientArg - Not used.
*
* @return Power_NOTIFYDONE to indicate success.
*/
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
uint32_t *clientArg)
{
if (eventType == PowerCC26XX_ENTERING_STANDBY)
{
// Power down RF Switch
PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 0);
}
else if (eventType == PowerCC26XX_AWAKE_STANDBY)
{
// Power up RF Switch
PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 1);
}
// Notification handled successfully
return Power_NOTIFYDONE;
}
#endif //CC1350_LAUNCHXL || POWER_SAVING
/*******************************************************************************
*/

Some files were not shown because too many files have changed in this diff Show More