From c3e4c9a25c2910d2d66d52215b3406b13d5b23d5 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sun, 29 Jun 2014 12:34:32 +0300 Subject: Add more board models --- boards/dk-tm4c129x/ble_central/Makefile | 94 + boards/dk-tm4c129x/ble_central/ble_central.c | 2551 ++++++++++++++++++++ boards/dk-tm4c129x/ble_central/ble_central.ewd | 614 +++++ boards/dk-tm4c129x/ble_central/ble_central.ewp | 810 +++++++ boards/dk-tm4c129x/ble_central/ble_central.icf | 78 + boards/dk-tm4c129x/ble_central/ble_central.ld | 57 + boards/dk-tm4c129x/ble_central/ble_central.sct | 47 + boards/dk-tm4c129x/ble_central/ble_central.uvopt | 401 +++ boards/dk-tm4c129x/ble_central/ble_central.uvproj | 464 ++++ boards/dk-tm4c129x/ble_central/ble_central_ccs.cmd | 70 + boards/dk-tm4c129x/ble_central/ccs/.ccsimportspec | 10 + boards/dk-tm4c129x/ble_central/ccs/.ccsproject | 10 + boards/dk-tm4c129x/ble_central/ccs/.cproject | 191 ++ boards/dk-tm4c129x/ble_central/ccs/.project | 85 + .../ccs/.settings/org.eclipse.cdt.codan.core.prefs | 3 + .../ble_central/ccs/Debug/ble_central.bin | Bin 0 -> 47088 bytes .../ble_central/ccs/Debug/ble_central.out | Bin 0 -> 387039 bytes .../dk-tm4c129x/ble_central/ccs/macros.ini_initial | 1 + .../ble_central/ccs/target_config.ccxml | 13 + .../ble_central/ewarm/Exe/ble_central.bin | Bin 0 -> 44044 bytes .../ble_central/ewarm/Exe/ble_central.out | Bin 0 -> 372024 bytes boards/dk-tm4c129x/ble_central/gap.c | 371 +++ boards/dk-tm4c129x/ble_central/gcc/ble_central.axf | Bin 0 -> 116065 bytes boards/dk-tm4c129x/ble_central/gcc/ble_central.bin | Bin 0 -> 47533 bytes boards/dk-tm4c129x/ble_central/hci.h | 329 +++ boards/dk-tm4c129x/ble_central/readme.txt | 94 + .../dk-tm4c129x/ble_central/rvmdk/ble_central.axf | Bin 0 -> 297060 bytes .../dk-tm4c129x/ble_central/rvmdk/ble_central.bin | Bin 0 -> 45124 bytes boards/dk-tm4c129x/ble_central/startup_ccs.c | 277 +++ boards/dk-tm4c129x/ble_central/startup_ewarm.c | 308 +++ boards/dk-tm4c129x/ble_central/startup_gcc.c | 324 +++ boards/dk-tm4c129x/ble_central/startup_rvmdk.S | 333 +++ 32 files changed, 7535 insertions(+) create mode 100644 boards/dk-tm4c129x/ble_central/Makefile create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.c create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.ewd create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.ewp create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.icf create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.ld create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.sct create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.uvopt create mode 100644 boards/dk-tm4c129x/ble_central/ble_central.uvproj create mode 100644 boards/dk-tm4c129x/ble_central/ble_central_ccs.cmd create mode 100644 boards/dk-tm4c129x/ble_central/ccs/.ccsimportspec create mode 100644 boards/dk-tm4c129x/ble_central/ccs/.ccsproject create mode 100644 boards/dk-tm4c129x/ble_central/ccs/.cproject create mode 100644 boards/dk-tm4c129x/ble_central/ccs/.project create mode 100644 boards/dk-tm4c129x/ble_central/ccs/.settings/org.eclipse.cdt.codan.core.prefs create mode 100644 boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.bin create mode 100644 boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.out create mode 100644 boards/dk-tm4c129x/ble_central/ccs/macros.ini_initial create mode 100644 boards/dk-tm4c129x/ble_central/ccs/target_config.ccxml create mode 100644 boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.bin create mode 100644 boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.out create mode 100644 boards/dk-tm4c129x/ble_central/gap.c create mode 100644 boards/dk-tm4c129x/ble_central/gcc/ble_central.axf create mode 100644 boards/dk-tm4c129x/ble_central/gcc/ble_central.bin create mode 100644 boards/dk-tm4c129x/ble_central/hci.h create mode 100644 boards/dk-tm4c129x/ble_central/readme.txt create mode 100644 boards/dk-tm4c129x/ble_central/rvmdk/ble_central.axf create mode 100644 boards/dk-tm4c129x/ble_central/rvmdk/ble_central.bin create mode 100644 boards/dk-tm4c129x/ble_central/startup_ccs.c create mode 100644 boards/dk-tm4c129x/ble_central/startup_ewarm.c create mode 100644 boards/dk-tm4c129x/ble_central/startup_gcc.c create mode 100644 boards/dk-tm4c129x/ble_central/startup_rvmdk.S (limited to 'boards/dk-tm4c129x/ble_central') diff --git a/boards/dk-tm4c129x/ble_central/Makefile b/boards/dk-tm4c129x/ble_central/Makefile new file mode 100644 index 0000000..600c267 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/Makefile @@ -0,0 +1,94 @@ +#****************************************************************************** +# +# Makefile - Rules for building the ble central example. +# +# Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +# Software License Agreement +# +# Texas Instruments (TI) is supplying this software for use solely and +# exclusively on TI's microcontroller products. The software is owned by +# TI and/or its suppliers, and is protected under applicable copyright +# laws. You may not combine this software with "viral" open-source +# software in order to form a larger program. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +# NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +# NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +# CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +# DAMAGES, FOR ANY REASON WHATSOEVER. +# +# This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +# +#****************************************************************************** + +# +# Defines the part type that this project uses. +# +PART=TM4C129XNCZAD + +# +# The base directory for TivaWare. +# +ROOT=../../../.. + +# +# Include the common make definitions. +# +include ${ROOT}/makedefs + +# +# Where to find source files that do not live in this directory. +# +VPATH=../drivers +VPATH+=../../../../utils + +# +# Where to find header files that do not live in the source directory. +# +IPATH=.. +IPATH+=../../../.. + +# +# The default rule, which causes the ble central example to be built. +# +all: ${COMPILER} +all: ${COMPILER}/ble_central.axf + +# +# The rule to clean out all the build products. +# +clean: + @rm -rf ${COMPILER} ${wildcard *~} + +# +# The rule to create the target directory. +# +${COMPILER}: + @mkdir -p ${COMPILER} + +# +# Rules for building the ble central example. +# +${COMPILER}/ble_central.axf: ${COMPILER}/ble_central.o +${COMPILER}/ble_central.axf: ${COMPILER}/frame.o +${COMPILER}/ble_central.axf: ${COMPILER}/gap.o +${COMPILER}/ble_central.axf: ${COMPILER}/kentec320x240x16_ssd2119.o +${COMPILER}/ble_central.axf: ${COMPILER}/pinout.o +${COMPILER}/ble_central.axf: ${COMPILER}/startup_${COMPILER}.o +${COMPILER}/ble_central.axf: ${COMPILER}/touch.o +${COMPILER}/ble_central.axf: ${COMPILER}/uartstdio.o +${COMPILER}/ble_central.axf: ${COMPILER}/ustdlib.o +${COMPILER}/ble_central.axf: ${ROOT}/grlib/${COMPILER}/libgr.a +${COMPILER}/ble_central.axf: ${ROOT}/driverlib/${COMPILER}/libdriver.a +${COMPILER}/ble_central.axf: ble_central.ld +SCATTERgcc_ble_central=ble_central.ld +ENTRY_ble_central=ResetISR +CFLAGSgcc=-DTARGET_IS_TM4C129_RA0 + +# +# Include the automatically generated dependency files. +# +ifneq (${MAKECMDGOALS},clean) +-include ${wildcard ${COMPILER}/*.d} __dummy__ +endif diff --git a/boards/dk-tm4c129x/ble_central/ble_central.c b/boards/dk-tm4c129x/ble_central/ble_central.c new file mode 100644 index 0000000..3d8b695 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.c @@ -0,0 +1,2551 @@ +//***************************************************************************** +// +// ble_central.c - Demonstration of BLE central device. +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#include +#include +#include +#include +#include "inc/hw_ints.h" +#include "inc/hw_memmap.h" +#include "inc/hw_types.h" +#include "driverlib/debug.h" +#include "driverlib/gpio.h" +#include "driverlib/interrupt.h" +#include "driverlib/sysctl.h" +#include "driverlib/systick.h" +#include "driverlib/uart.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/pin_map.h" +#include "grlib/grlib.h" +#include "grlib/widget.h" +#include "drivers/kentec320x240x16_ssd2119.h" +#include "drivers/frame.h" +#include "drivers/pinout.h" +#include "drivers/touch.h" +#include "utils/uartstdio.h" +#include "utils/ustdlib.h" +#include "hci.h" + +//***************************************************************************** +// +//! \addtogroup example_list +//!

BLE Central Device Demonstration (ble_central)

+//! +//! This application provides a demonstration use of Bluetooth Low Energy +//! central device by utilizing TI’s BLE CC2540 Evaluation Module and +//! SesorTags. +//! +//! By connecting a CC2540 EM board to the EM header on the TM4C129X development +//! board, the TM4C129X can communicate with the CC2540 by means of +//! vendor-specific HCI commands using the UART interface. This application can +//! discover up to three SensorTag devices, it can connect to any one of them, +//! perform pairing and bonding, read some sensor data and RSSI data from the +//! slave, and display the information on the LCD display. +//! +//! This application can discover any BLE device although it may not be +//! able to make a connection to a device other than a SensorTag/CC2540 as the +//! bonding process will likely fail due to the use of a default passcode. +//! We have tested this application with SensorTag and CC2540 Development +//! boards (SmartRF05EB + CC2540 EM) with the SimpleBLEPeripheral +//! sample application programmed. It can successfully bond with both boards +//! since the same default passcode is expected. Both SensorTag and CC2540 +//! devices have BLE Stack 1.4.0 release code programmed. +//! +//! CC2540 device should be programmed with the HostTestRelease +//! (Network Processor) application. A hex file containing the this application +//! can be found in the BLE stack 1.4.0 release under +//! C:\\...\\BLE-CC254x-1.4.0\\Accessories\\HexFiles\\ +//! CC2540_SmartRF_HostTestRelease_All.hex. Please refer to the Bluetooth Low +//! Energy CC2540 Development Kit User's Guide for information on how to load +//! the hex file to the CC2540. This User's Guide can be found in +//! http://www.ti.com/lit/ug/swru301a/swru301a.pdf +//! +//! On the TM4C129X development board, make sure that jumpers PJ0 and PJ1 +//! are connected to the "EM_UART" side which allows UART3 TX and RX signals to +//! be routed to the EM header. UART3 is used as the communication channel +//! between the CC2540 device and the TM4C129X device. +//! +//! Once the application starts, it will verify the serial connection by +//! sending the CC2540 device a vendor-specific HCI command, and waiting for the +//! expected responses within a short time period. Once the physical connection +//! between TM4C129X and CC2540 is verified, the device will automatically +//! start to discover BLE peripheral device. If no devices are found within 20 +//! seconds, the application will timeout and display "No Device Found", +//! otherwise the discovered device names will be shown on the display. +//! Touching any of the device names will start the process of establishing a +//! connection with that device. This sample application always tries to make +//! a secure connection by pairing the device with default passcode "00000". +//! Upon successfully linking and pairing, application will start querying +//! sensor data, including IR temperature, ambient temperature, humidity and +//! RSSI. +//! +//! Whe run inside, IR and ambient temperature should typically be in the low +//! 20s (Celsius). You can place the SensorTag near a hot object (such as a +//! cup of coffee) to verify that the IR temperature increases. You can move +//! the SensorTag further from the TM4C129X development board to verify that +//! its RSSI reading will decrease. +//! +//! At any time after the connection is established, you can touch the +//! "disconnect" button on the bottom of the screen to terminate the +//! connection with the peripheral device. +//! +//! In order to make the SensorTag discoverable by a central device, the +//! SensorTag needs to be in the discovery mode. The LED in the middle of the +//! board will blink periodically if the SensorTag is in discovery mode. If the +//! LED is not blinking, pressing the side button on the SensorTag should +//! place it in discovery mode. Once it is connected to a central device, +//! the LED should be off, pressing the side button while it is connected will +//! terminate the connection and put the SensorTag in discovery mode again. +//! For more information on SensorTag, please visit +//! http://processors.wiki.ti.com/index.php/Bluetooth_SensorTag +//! +//! Every HCI command and event are output to the UART console for +//! debugging purpose. The UART terminal should be configured in 115,200 baud, +//! 8-n-1 mode. +//! +// +//***************************************************************************** + + +//***************************************************************************** +// +// A set of flags. The flag bits are defined as follows: +// +// 0 -> An indicator that a second has occurred. +// 1 -> A complete RX Packet has been received. +// 2 -> Whether to draw a circle or not on the display. +// 3 -> Sensors on the SensorTag are configured or not. +// +//***************************************************************************** +#define FLAG_EVERY_SECOND 0 +#define FLAG_HCI_MSG_COMPLETE 1 +#define FLAG_DRAW_CIRCLE 2 +#define FLAG_SENSOR_CFGD 3 +static volatile uint32_t g_ui32Flags; + +//***************************************************************************** +// +// A system tick counter, incremented every SYSTICKMS. +// +//***************************************************************************** +volatile uint32_t g_ui32TickCounter = 0; + +//***************************************************************************** +// +// The delay count for timeout. It decrements to 1 to indicate timeout. Setting +// it to 0 means no timeout has been set. +// +//***************************************************************************** +volatile uint32_t g_ui32Delay; + +//***************************************************************************** +// +// The application's graphics context. +// +//***************************************************************************** +tContext g_sContext; + +//***************************************************************************** +// +// Flag that informs that the user has requested an action via GUI. +// +//***************************************************************************** +static volatile bool g_bDiscoveryReq = false; +static volatile bool g_bEstLinkReq = false; +static volatile bool g_bTermLinkReq = false; + +//***************************************************************************** +// +// Flag to enable pairing, change to false to diable the pairing. +// +//***************************************************************************** +static bool g_bInitPairReq = true; + +//***************************************************************************** +// +// The width and height of the LCD display +// +//***************************************************************************** +uint32_t g_ui32Width, g_ui32Height; + +//***************************************************************************** +// +// The screen offset of the upper left hand corner where we start to draw. +// +//***************************************************************************** +#define X_OFFSET 8 +#define Y_OFFSET 24 + + +//***************************************************************************** +// +// The maximum number of slaves that we can discover. +// +//***************************************************************************** +#define MAX_SLAVE_NUM 3 + +//***************************************************************************** +// +// The RX receive circular buffer size. +// +//***************************************************************************** +#define BUF_SIZE 128 + + +//***************************************************************************** +// +// The circular buffer used to store the received HCI message from the CC2540. +// +//***************************************************************************** +typedef struct +{ + volatile uint8_t pui8RXBuf[BUF_SIZE]; + volatile uint8_t ui8Rd; + volatile uint8_t ui8Wr; + volatile uint8_t ui8Count; +} tCirBuf; + +tCirBuf g_sRxBuf; + +//***************************************************************************** +// +// The state defination of BLE statemachine. +// +//***************************************************************************** +volatile enum +{ + STATE_DEV_INIT, + STATE_GET_PARAM, + STATE_START_DISCOVERY, + STATE_SET_PARAM, + STATE_READY_FOR_LINK_REQ, + STATE_LINK, + STATE_LINKED, + STATE_SEND_PASSKEY, + STATE_IDLE, + STATE_TERM, + STATE_TERMED, + STATE_ERROR, +}g_iState = STATE_IDLE; + +//***************************************************************************** +// +// The paramers of the central device. +// +//***************************************************************************** +uint16_t g_ui16Param[4]; +uint8_t g_ui8ParamWrIdx = 0; + +//***************************************************************************** +// +// The complete HCI message and its length that we have received from BLE +// stack. +// +//***************************************************************************** +uint8_t g_pui8Msg[200]; +uint8_t g_ui8MsgLen; + +//***************************************************************************** +// +// Received Signal Strength Indication(RSSI). +// +//***************************************************************************** +int8_t g_i8RSSI = 0; + +//***************************************************************************** +// +// Sensor data, IR temperature, humidity etc. Only available on SensorTag +// +//***************************************************************************** +uint8_t g_pui8IRTemp[4]; // RAW data +uint8_t g_pui8Humidity[4]; // RAW data +double g_dIRTemp = 0; +double g_dAmbTemp = 0; +double g_dHumidity = 0; + +//***************************************************************************** +// +// The HCI message information, used for verifying expected response from +// stack. +// +//***************************************************************************** +uint16_t g_ui16CmdStatusOpcode; +uint16_t g_ui16Event; +uint16_t g_ui16Handle; + +//***************************************************************************** +// +// The structure of BLE slave information. +// +//***************************************************************************** +typedef struct +{ + // + // Device Address + // + uint8_t pui8Addr[HCI_BDADDR_LEN]; + // + // Address Type + // + uint8_t ui8AddrType; + // + // Device Name + // + char pcName[32]; + // + // Long Term Key Data, used for bonding. + // + tLTKData sSaveKey; +} tBLEDeviceInfo; + +tBLEDeviceInfo g_psDev[MAX_SLAVE_NUM]; + +//***************************************************************************** +// +// The number of devices discovered. +// +//***************************************************************************** +uint8_t g_ui8DevFound; + +//***************************************************************************** +// +// The index of device to be connected. +// +//***************************************************************************** +uint8_t g_ui8DevConnect; + +//***************************************************************************** +// +// The positions of the circles in the animation used while discovering devices +// +//***************************************************************************** +const int32_t g_ppi32CirclePos[][2] = +{ + { + 12, 0 + }, + { + 8, -9 + }, + { + 0, -12 + }, + { + -8, -9 + }, + { + -12, 0 + }, + { + -8, 9 + }, + { + 0, 12 + }, + { + 8, 9 + } +}; + +//***************************************************************************** +// +// The colors of the circles in the animation used while discovering devices +// +//***************************************************************************** +const uint32_t g_pui32CircleColor[] = +{ + 0x111111, + 0x333333, + 0x555555, + 0x777777, + 0x999999, + 0xbbbbbb, + 0xdddddd, + 0xffffff, +}; + +//***************************************************************************** +// +// The current color index for the animation used while discovering devices +// +//***************************************************************************** +uint32_t g_ui32ColorIdx; + +//***************************************************************************** +// +// The strings that are displayed in the center and bottom of the display +// +//***************************************************************************** +typedef enum +{ + iInitializing = 0, + iScanning, + iScan, + iNoBLE, + iConnect, + iConnecting, + iDisconnect, + iDisconnecting +} eDisplayUpdateIdx; + +// +// eDisplayUpdateIdx is used as index to the following table +// +static char *ppcString[][2] = +{ // Middle of screen, Bottom of screen + {"Initializing", 0}, + {"Discovering", "timeout in 20s"}, + {"No Device Found", "scan"}, + {"CC2540 EM not present", 0}, + {0, "scan again"}, + {0, "connecting" }, + {0, "disconnect" }, + {0, "disconnecting"}, +}; + +//***************************************************************************** +// +// Forward reference to local functions. +// +//***************************************************************************** +void DrawCircle(void); +bool MessageComplete(uint8_t *pui8Buf, uint8_t *pui8Len); +void HandleTemp(void); +void HandleHumidity(void); +void DisplayTemp(uint32_t ui32X, uint32_t ui32Y); +void DisplayHumidity(uint32_t ui32X, uint32_t ui32Y); +void DisplayRSSI(uint32_t ui32X, uint32_t ui32Y); + +//***************************************************************************** +// +// The error routine that is called if the driver library encounters an error. +// +//***************************************************************************** +#ifdef DEBUG +void +__error__(char *pcFilename, uint32_t ui32Line) +{ +} +#endif + +//***************************************************************************** +// +// The interrupt handler for the SysTick interrupt. +// +//***************************************************************************** +void +SysTickIntHandler(void) +{ + // + // Increment the system tick count. + // + g_ui32TickCounter++; + + // + // After the current message has been processed, + // check the message buffer to see if we have received another complete + // message. + // + if(HWREGBITW(&g_ui32Flags, FLAG_HCI_MSG_COMPLETE) == 0) + { + if(MessageComplete(g_pui8Msg, &g_ui8MsgLen) == true) + { + HWREGBITW(&g_ui32Flags, FLAG_HCI_MSG_COMPLETE) = 1; + } + } + + // + // Decrement g_ui32Delay to 1, if it is 1 already, + // meaning it has timed out. + // + if(g_ui32Delay > 1) + { + g_ui32Delay--; + } + + // + // Draw a circle every 100ms + // + if(HWREGBITW(&g_ui32Flags, FLAG_DRAW_CIRCLE) == 1) + { + if(g_ui32TickCounter % 10 == 0) + { + DrawCircle(); + } + } + + // + // set FLAG_EVERY_SECOND every second. + // Systick interrupt is every 10ms, so a second is every 100 interrupts. + // + if(g_ui32TickCounter % 100 == 0) + { + HWREGBITW(&g_ui32Flags, FLAG_EVERY_SECOND) = 1; + } +} + +//***************************************************************************** +// +// The UART interrupt handler. +// +//***************************************************************************** +void +UART3IntHandler(void) +{ + uint32_t ui32Status; + + // + // Get the interrrupt status. + // + ui32Status = ROM_UARTIntStatus(UART3_BASE, true); + + // + // Clear the asserted interrupts. + // + ROM_UARTIntClear(UART3_BASE, ui32Status); + + // + // Loop while there are characters in the receive FIFO. + // + while(ROM_UARTCharsAvail(UART3_BASE)) + { + // + // Check for buffer overflow case, this shouldn't happen + // + if((g_sRxBuf.ui8Wr == g_sRxBuf.ui8Rd) && g_sRxBuf.ui8Count) + { + UARTprintf("\nOF!!! Wr %d, Rd %d, Count %d\n", g_sRxBuf.ui8Wr, g_sRxBuf.ui8Rd, g_sRxBuf.ui8Count); + } + + // + // Read the next character from the UART and place it in the RX buffer. + // + g_sRxBuf.pui8RXBuf[g_sRxBuf.ui8Wr++] = UARTCharGetNonBlocking(UART3_BASE); + + // + // Check for the RX buffer wrap. + // + if(g_sRxBuf.ui8Wr >= BUF_SIZE) + { + g_sRxBuf.ui8Wr = 0; + } + + // + // Increment the total count. + // + g_sRxBuf.ui8Count++; + + } +} + +//***************************************************************************** +// +// The touch screen driver calls this function to report all state changes. +// +//***************************************************************************** +static int32_t +TouchCallback(uint32_t ui32Message, int32_t i32X, int32_t i32Y) +{ + uint8_t ui8Loop; + + if(ui32Message == WIDGET_MSG_PTR_UP) + { + // + // Check if the bottom of the screen is touched. + // + if(i32Y >= (200 - 8) && i32Y < (200 + 8)) + { + if( (g_iState == STATE_READY_FOR_LINK_REQ) || + (g_iState == STATE_START_DISCOVERY)) + { + g_bDiscoveryReq = true; + } + else if(g_iState == STATE_LINKED) + { + g_bTermLinkReq = true; + } + } + + + // + // Check if any of three device names is touched when it is ready + // to connect + // + if(g_iState == STATE_READY_FOR_LINK_REQ) + { + for(ui8Loop = 0; ui8Loop < g_ui8DevFound; ui8Loop++) + { + if((g_ui8DevFound >= ui8Loop + 1) && + (i32Y >= (60 + 40*ui8Loop - 20)) && + (i32Y < (60 + 40*ui8Loop + 20))) + { + // + // save the device index and + // set flag to connect the device. + // + g_ui8DevConnect = ui8Loop; + g_bEstLinkReq = true; + break; + } + } + } + } + + return(0); +} + +//***************************************************************************** +// +// Send a command to the UART. +// +//***************************************************************************** +void +UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) +{ + // + // Loop while there are more characters to send. + // + while(ui32Count--) + { + // + // Write the next character to the UART. + // + ROM_UARTCharPut(UART3_BASE, *pui8Buffer++); + } +} + +//***************************************************************************** +// +// Simple function to dump the buffer contents to the UART debug port. +// +//***************************************************************************** +void +DumpBuffer(uint8_t *pui8Buf, uint32_t ui32Len, bool bTX) +{ + uint32_t ui32Idx = 0; + + UARTprintf("\n%s: %d\n", (bTX?"TX":"RX"), ui32Len); + for(ui32Idx = 0; ui32Idx < ui32Len; ui32Idx++) + { + if(ui32Idx && (ui32Idx % 16 == 0)) + { + UARTprintf("\n"); + } + UARTprintf("%02x ", pui8Buf[ui32Idx]); + } + UARTprintf("\n\n"); +} + +//***************************************************************************** +// +// This function looks in the RX buffer and returns true if there is a complete +// message, otherwise it returns false. The complete message will be taken out +// from the RX buffer, and message itself and its length will be returned to +// to the caller. +// This function doesn't block, can be called from interrupt context. +// +//***************************************************************************** +bool +MessageComplete(uint8_t *pui8Buf, uint8_t *pui8Len) +{ + uint8_t ui8Idx; + + if(g_sRxBuf.ui8Count < 7 ) + { + // + // Minimum size of a message is 7+ bytes + // + return false; + } + + // + // Byte 0: Type + // 1: EventCode + // 2: Data Length + // 3: Event LSB + // 4: Event MSB + // 5: Status + // ... + // + + // + // Get the index of the Data Length, it is the byte[2] + // + ui8Idx = g_sRxBuf.ui8Rd+2; + + // + // Check for buffer wrap + // + if(ui8Idx > BUF_SIZE -1) + { + ui8Idx -= BUF_SIZE; + } + + // + // The whole message length should 3+Datalength + // + if(g_sRxBuf.ui8Count < (g_sRxBuf.pui8RXBuf[ui8Idx] + 3)) + { + return false; + } + + // + // Got a complete message. + // Return the length of the message + // + *pui8Len = g_sRxBuf.pui8RXBuf[ui8Idx] + 3; + + // + // Take the rx data out of the buffer and return to caller. + // + for(ui8Idx = 0; ui8Idx < *pui8Len; ui8Idx++) + { + pui8Buf[ui8Idx] = g_sRxBuf.pui8RXBuf[g_sRxBuf.ui8Rd++]; + // + // Check for buffer wrap + // + if(g_sRxBuf.ui8Rd >= BUF_SIZE) + { + g_sRxBuf.ui8Rd = 0; + } + } + g_sRxBuf.ui8Count -= *pui8Len; + + return true; +} + +//***************************************************************************** +// +// This function validates and parses the received message and return true +// if it is valid message, it also return the command status of the message. +// If the message is not valid, the function returns false. +// +//***************************************************************************** +bool +ProcessRxData( uint8_t *pui8CmdStatus) +{ + uint8_t ui8Idx; + uint16_t ui16Val; + + // + // Printout the complete message + // + DumpBuffer(g_pui8Msg, g_ui8MsgLen, false); + + // + // Quick check on the first and third bytes. + // The first byte should be 0x4(EVENT) + // The third byte should be the data length. + // + if((g_pui8Msg[0] != HCI_EVENT_PACKET) || + ((g_pui8Msg[2] + 3) != g_ui8MsgLen)) + { + // + // Invalid message, toss it + // + return false; + } + + // + // Parse the message: + // The second byte is event code, it is either vendor specific event code + // 0xFF(HCI_VE_EVENT_CODE) or any BLE event code. + // 3rd and 4th byte are the event + // + if(g_pui8Msg[1] == HCI_VE_EVENT_CODE) + { + //BLE Ext Event + g_ui16Event = (g_pui8Msg[3] | (g_pui8Msg[4]<<8)); + } + else + { + //BLE Event + g_ui16Event = g_pui8Msg[1]; + } + + // + // Get the status in the response(5th byte) + // + if(g_pui8Msg[1] == HCI_VE_EVENT_CODE) + { + //BLE Ext Event + *pui8CmdStatus = g_pui8Msg[5]; + } + else + { + //BLE Event + *pui8CmdStatus = g_pui8Msg[6]; + } + + switch(g_ui16Event) + { + case GAP_HCI_EVENT_EXT_CMD_STATUS: + // + // CommandStatus Event + // Get the command opcode + // + g_ui16CmdStatusOpcode = (g_pui8Msg[6] | (g_pui8Msg[7]<<8)); + if(g_ui16CmdStatusOpcode == HCI_VE_GAP_GET_PARAM_OPCODE) + { + // + // Save the parameters. + // + g_ui16Param[g_ui8ParamWrIdx++] = (g_pui8Msg[9] | (g_pui8Msg[10]<<8)); + } + break; + + case GAP_HCI_EVENT_EXT_DEVICE_INIT_DONE: + // + // DeviceInitDone Event + // + break; + + case GAP_HCI_EVENT_EXT_DEVICE_INFO: + // + // Device Information Event + // parse the scan response + // + if(g_pui8Msg[6] == GAP_ADTYPE_SCAN_RSP_IND) + { + if(g_ui8DevFound < MAX_SLAVE_NUM) + { + // + // Save the device address + // + g_psDev[g_ui8DevFound].ui8AddrType = g_pui8Msg[7]; + memcpy(g_psDev[g_ui8DevFound].pui8Addr, g_pui8Msg + 8, HCI_BDADDR_LEN); + + // + // Get the device name + // Skip the first ht(0x9) char. + // + memcpy(g_psDev[g_ui8DevFound].pcName, &g_pui8Msg[18], (g_pui8Msg[16]-1)); + + // + // Null terminate the name string + // + g_psDev[g_ui8DevFound].pcName[g_pui8Msg[16] -1] = 0; + + // + // Increment the number of devices found. + // + g_ui8DevFound++; + } + else + { + UARTprintf("More than %d device found, ignor this device\n", MAX_SLAVE_NUM); + } + + } + break; + + case GAP_HCI_EVENT_EXT_DEVICE_DISC_DONE: + // + // Device Discover Done Event + // print out devices' info + // + UARTprintf("%d Devices found\n", g_pui8Msg[6]); + for(ui8Idx = 0; ui8Idx < g_ui8DevFound; ui8Idx++) + { + UARTprintf("Device Name: %s\n", g_psDev[ui8Idx].pcName); + UARTprintf(" -Addr Type: %02x\n", g_psDev[ui8Idx].ui8AddrType); + UARTprintf(" -Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", + g_psDev[ui8Idx].pui8Addr[5], + g_psDev[ui8Idx].pui8Addr[4], + g_psDev[ui8Idx].pui8Addr[3], + g_psDev[ui8Idx].pui8Addr[2], + g_psDev[ui8Idx].pui8Addr[1], + g_psDev[ui8Idx].pui8Addr[0]); + } + break; + + case GAP_HCI_EVENT_EXT_DEVICE_LINK_DONE: + // + // Device EstablishLink Event + // + g_ui16Handle = (g_pui8Msg[13] | (g_pui8Msg[14] << 8)); + UARTprintf("Device connected: %s\n", g_psDev[g_ui8DevConnect].pcName); + UARTprintf(" -Handle: %04x\n", g_ui16Handle); + UARTprintf(" -Addr Type: %04x\n", g_psDev[g_ui8DevConnect].ui8AddrType); + UARTprintf(" -Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", + g_psDev[g_ui8DevConnect].pui8Addr[5], + g_psDev[g_ui8DevConnect].pui8Addr[4], + g_psDev[g_ui8DevConnect].pui8Addr[3], + g_psDev[g_ui8DevConnect].pui8Addr[2], + g_psDev[g_ui8DevConnect].pui8Addr[1], + g_psDev[g_ui8DevConnect].pui8Addr[0]); + + break; + + case GAP_HCI_EVENT_EXT_DEVICE_TERM_LINK_DONE: + // + // Device TerminateLink Event + // + UARTprintf("Device Disconnected, reason: %02x\n", g_pui8Msg[8]); + break; + case GAP_HCI_EVENT_EXT_DEVICE_PASSKEY_NEEDED: + break; + + case GAP_HCI_EVENT_EXT_DEVICE_AUTHENTICATE_DONE: + // + // Save the LongTermKey for bond request + // + g_psDev[g_ui8DevConnect].sSaveKey.bValid = true; + ui8Idx = 37; // The DSInf.Enable field is at index 37 in the byte string. + g_psDev[g_ui8DevConnect].sSaveKey.bAuth = g_pui8Msg[ui8Idx++]; + + // + // Next byte is LTK size, followed by the LTK + // + g_psDev[g_ui8DevConnect].sSaveKey.ui8LTKSize = g_pui8Msg[ui8Idx++]; + memcpy(g_psDev[g_ui8DevConnect].sSaveKey.pui8LTK, + g_pui8Msg + ui8Idx, + g_psDev[g_ui8DevConnect].sSaveKey.ui8LTKSize); + ui8Idx += g_psDev[g_ui8DevConnect].sSaveKey.ui8LTKSize; + + // + // 2 bytes of DIV, followed by 8 bytes of Random number + // + g_psDev[g_ui8DevConnect].sSaveKey.pui8DIV[0] = g_pui8Msg[ui8Idx++]; + g_psDev[g_ui8DevConnect].sSaveKey.pui8DIV[1] = g_pui8Msg[ui8Idx++]; + memcpy(g_psDev[g_ui8DevConnect].sSaveKey.pui8Rand, g_pui8Msg + ui8Idx, 8); + + break; + case GAP_HCI_EVENT_EXT_DEVICE_BOND_DONE: + UARTprintf("Bonded\n"); + break; + + case GAP_HCI_EVENT_EXT_ATT_WRITE_RSP: + break; + + case GAP_HCI_EVENT_EXT_ATT_READ_RSP: + // + // this is the IR temperature response + // + memcpy(g_pui8IRTemp, g_pui8Msg + 9, 4); + HandleTemp(); + break; + + case HCI_ATT_ERROR_RSP_EVENT: + UARTprintf("Error Response event: \n"); + break; + + case GAP_HCI_EVENT_CMD_COMPLETE: + // + // Get the command opcode + // + g_ui16CmdStatusOpcode = (g_pui8Msg[4] | (g_pui8Msg[5]<<8)); + if(g_ui16CmdStatusOpcode == HCI_READ_RSSI_OPCODE) + { + // + // RSSI reading response + // + g_i8RSSI = (int8_t)g_pui8Msg[9]; + UARTprintf("RSSI = %d 0x%x\n", g_i8RSSI, g_pui8Msg[9]); + + // + // Display the data when it is only in LINKED state + // + if(g_iState == STATE_LINKED) + { + DisplayRSSI(g_ui32Width / 2 + 80, 80 + 40); + } + } + break; + + case GAP_HCI_EVENT_HANDLE_VALUE_NOTIFY: + if(g_pui8Msg[8] > 2) //PduLen + { + ui16Val = g_pui8Msg[9] | (g_pui8Msg[10] <<8); + switch(ui16Val) + { + case GATT_IRTEMP_DATA_UUID_HANDLE: + // + // Temperatur Sensor data + // + memcpy(g_pui8IRTemp, g_pui8Msg + 11, 4); + + // + // Display the data when it is LINKED state + // + if(g_iState == STATE_LINKED) + { + HandleTemp(); + } + break; + + case GATT_HUMIDITY_DATA_UUID_HANDLE: + // + // Humidity Sensor data + // + memcpy(g_pui8Humidity, g_pui8Msg + 11, 4); + + // + // Display the data when it is LINKED state + // + if(g_iState == STATE_LINKED) + { + HandleHumidity(); + } + break; + + default: + UARTprintf("unexpected handle: %04x, fix me\n", ui16Val); + break; + + } + } + break; + + default: + UARTprintf("unexpected event: %04x, fix me\n", g_ui16Event); + break; + + } + + return true; +} + +//***************************************************************************** +// +// This function verifies if the received response is expected, and return +// true if it is, false otherwise. +// +//***************************************************************************** +bool +VerifyMsg(uint16_t ui16ExpectedEvent, uint16_t ui16ExpectedEventParam, + uint8_t *pui8Status) +{ + uint8_t ui8CmdStatus; + + if(ProcessRxData(&ui8CmdStatus) == 0) + { + // + // Message is not valid + // + return false; + } + + if(ui8CmdStatus != SUCCESS) + { + // + // Message return non-success status code + // + UARTprintf("Command Status return failure: %02x\n", ui8CmdStatus); + } + + // + // Pass the status code to the caller if a location is provided. + if(pui8Status) + { + *pui8Status = ui8CmdStatus; + } + + // + // check the received event + // + UARTprintf("RX: event 0x%04x\n", g_ui16Event); + if(ui16ExpectedEvent) + { + // + // We are expecting a specific event, check it. + // + if(g_ui16Event == ui16ExpectedEvent) + { + // + // Validate Event param if supplied. + // + if(ui16ExpectedEventParam) + { + if(ui16ExpectedEventParam == g_ui16CmdStatusOpcode) + { + return true; + } + } + else + { + // + // No need to verify EventParam + // + return true; + } + } + } + else + { + // + // We are NOT expecting any specific event, just return true. + // + return true; + } + + return false; +} + +//***************************************************************************** +// +// This function sets the timeout and waits for the given event, the function +// will return true when the expected event has been received before the +// timeout; or return false when the expected event has not been received +// before the timeout. +// +//***************************************************************************** +bool +WaitForRsp(uint16_t ui16ExpectedEvent, uint16_t ui16ExpectedParam, + uint32_t ui32TimeoutMs, uint8_t *pui8Status) +{ + bool bRet = false; + + // + // Set the timeout if non zero + // i32Timeout is in ms, convert it to number of systicks. + // Systick timer is every 10ms, so ui32TimeoutMs/10 + 1 + // + g_ui32Delay = ui32TimeoutMs?(ui32TimeoutMs/10 + 1):0; + + // + // Block until there is a response or timeout + // + while(g_ui32Delay > 1) + { + if(HWREGBITW(&g_ui32Flags, FLAG_HCI_MSG_COMPLETE) == 1) + { + // + // Got a response + // + bRet = VerifyMsg(ui16ExpectedEvent, ui16ExpectedParam, pui8Status); + if(bRet) + { + // + // Got what we expected, disable timeout, and exit the loop + // + g_ui32Delay = 0; + } + + // + // Clear the flag to indicate we are ready to receive the next + // complete message + // + HWREGBITW(&g_ui32Flags, FLAG_HCI_MSG_COMPLETE) = 0; + } + } + + // + // Check for timeout + // + if(g_ui32Delay == 1) + { + UARTprintf("\nTimeout waiting for response..%04x.\n", + ui16ExpectedEvent); + } + + return bRet; +} + +//***************************************************************************** +// +// This function checks if there are any events in the queue to be processed. +// Such as notify event, it will be sent from slave periodically. +// +//***************************************************************************** +bool +CheckForMsg() +{ + bool bSuccess = false; + + if(HWREGBITW(&g_ui32Flags, FLAG_HCI_MSG_COMPLETE) == 1) + { + // + // Got a response + // + bSuccess = VerifyMsg(0, 0, 0); + if(g_ui16Event == GAP_HCI_EVENT_EXT_DEVICE_TERM_LINK_DONE) + { + UARTprintf("Slave terminated the link\n"); + + // + // Sensor will be turned off by the slave + // + HWREGBITW(&g_ui32Flags, FLAG_SENSOR_CFGD) = 0; + + // + // Go back to TERMED state + // + g_iState = STATE_TERMED; + } + + // + // Clear the flag to indicate we are ready to receive the next + // complete message + // + HWREGBITW(&g_ui32Flags, FLAG_HCI_MSG_COMPLETE) = 0; + } + + return bSuccess; + +} + +//***************************************************************************** +// +// This function configures the sensor profiles. +// +//***************************************************************************** +void +ConfigureSensors(void) +{ + uint8_t pui8Byte[2]; + uint8_t ui8Status; + bool bSuccess; + + // + // Enable IR Sensor and Measurements if it is not yet configured. + // + if(HWREGBITW(&g_ui32Flags, FLAG_SENSOR_CFGD) == 1) + { + return; + } + + UARTprintf("Send Temp sensor wake cmd...\n"); + pui8Byte[0] = 0x01; + GAPWriteCharValue(g_ui16Handle, GATT_IRTEMP_CFG_UUID_HANDLE, pui8Byte, 1); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 500ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 500, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + + // + // Humidity Sensor + // + UARTprintf("Send humidity sensor wake cmd...\n"); + GAPWriteCharValue(g_ui16Handle, GATT_HUMIDITY_CFG_UUID_HANDLE, pui8Byte, 1); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 500ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 500, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + + UARTprintf("Send Temp sensor notify cmd...\n"); + pui8Byte[0] = 0x01; + pui8Byte[1] = 0x00; + GAPWriteCharValue(g_ui16Handle, GATT_IRTEMP_NOTIFY_UUID_HANDLE, pui8Byte, 2); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + + // + // Humidity Sensor + // + UARTprintf("Send Humidity sensor notify cmd...\n"); + GAPWriteCharValue(g_ui16Handle, GATT_HUMIDITY_NOTIDY_UUID_HANDLE, pui8Byte, 2); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("ConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + + // + // Set the flag that sensors are configured. + // + HWREGBITW(&g_ui32Flags, FLAG_SENSOR_CFGD) = 1; +} + +//***************************************************************************** +// +// This function deconfigures the sensor profiles. +// +//***************************************************************************** +void +DeConfigureSensors(void) +{ + uint8_t pui8Byte[2]; + uint8_t ui8Status; + bool bSuccess; + + if(HWREGBITW(&g_ui32Flags, FLAG_SENSOR_CFGD) == 0) + { + // Do nothing if the sensors have not been configured. + return; + } + + // + // TM006 IR and Ambient temperature sensor + // + UARTprintf("Send Temp sensor stop notify cmd...\n"); + pui8Byte[0] = 0x00; + pui8Byte[1] = 0x00; + GAPWriteCharValue(g_ui16Handle, GATT_IRTEMP_NOTIFY_UUID_HANDLE, pui8Byte, 2); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Humidity Sensor + // + UARTprintf("Send Humidity sensor stop notify cmd...\n"); + GAPWriteCharValue(g_ui16Handle, GATT_HUMIDITY_NOTIDY_UUID_HANDLE, pui8Byte, 2); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + + // + // Put IR Sensor and Measurements to sleep + // + UARTprintf("Send IR Temp sensor sleep cmd...\n"); + pui8Byte[0] = 0x00; + GAPWriteCharValue(g_ui16Handle, GATT_IRTEMP_CFG_UUID_HANDLE, pui8Byte, 1); + + // + // Wait for CommandStatus response, timeout after 500ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 500, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + + UARTprintf("Send Humidity sensor sleep cmd...\n"); + GAPWriteCharValue(g_ui16Handle, GATT_HUMIDITY_CFG_UUID_HANDLE, pui8Byte, 1); + + // + // Wait for CommandStatus response, timeout after 500ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE, 500, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for CommandStatus error\n"); + } + + // + // Wait for ATT_WriteRsp event, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_ATT_WRITE_RSP, 0, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("DeConfigureSensors: Wait for ATT_WriteRsp error\n"); + } + HWREGBITW(&g_ui32Flags, FLAG_SENSOR_CFGD) = 0; + +} + +//***************************************************************************** +// +// This function queries the parameters of the central device. +// +//***************************************************************************** +bool +GetParam(void) +{ + uint8_t ui8Status; + bool bSuccess; + + UARTprintf("Get Param...\n"); + + // + // Start Parameter write index with 0 + // + g_ui8ParamWrIdx = 0; + + // + // Get the Minimum Link Layer connection interval + // + GAPGetParam(TGAP_CONN_EST_INT_MIN); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_GET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("Get Param %x failed\n", TGAP_CONN_EST_INT_MIN); + } + + // + // Get the Maximum Link Layer connection interval + // + GAPGetParam(TGAP_CONN_EST_INT_MAX); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_GET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("Get Param %x failed\n", TGAP_CONN_EST_INT_MAX); + } + + // + // Get the Link Layer connection slave latency + // + GAPGetParam(TGAP_CONN_EST_LATENCY); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_GET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("Get Param %x failed\n", TGAP_CONN_EST_LATENCY); + } + + // + // Get the Link Layer connection supervision timeout + // + GAPGetParam(TGAP_CONN_EST_SUPERV_TIMEOUT); + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_GET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + UARTprintf("Get Param %x failed\n", TGAP_CONN_EST_SUPERV_TIMEOUT); + } + + if(g_ui16Param[0] != 0 && g_ui16Param[1] != 0 && g_ui16Param[3] != 0) + { + return true; + } + else + { + return false; + } +} + +//***************************************************************************** +// +// This function set the parameters of the central device. +// +//***************************************************************************** +bool +SetParam(void) +{ + uint8_t ui8Status; + bool bSuccess; + + UARTprintf("Set Param...\n"); + + // + // Set the Minimum Link Layer connection interval + // + GAPSetParam(TGAP_CONN_EST_INT_MIN, g_ui16Param[0]); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_SET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + + UARTprintf("Set Param %x failed\n", TGAP_CONN_EST_INT_MIN); + } + + // + // Set the Maximum Link Layer connection interval + // + GAPSetParam(TGAP_CONN_EST_INT_MAX, g_ui16Param[1]); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_SET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + + UARTprintf("Set Param %x failed\n", TGAP_CONN_EST_INT_MAX); + } + + // + // Set the Link Layer connection slave latency + // + GAPSetParam(TGAP_CONN_EST_LATENCY, g_ui16Param[2]); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_SET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + + UARTprintf("Set Param %x failed\n", TGAP_CONN_EST_LATENCY); + } + + // + // Set the Link Layer connection supervision timeout + // + GAPSetParam(TGAP_CONN_EST_SUPERV_TIMEOUT, g_ui16Param[3]); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_SET_PARAM_OPCODE, 200, &ui8Status); + if(!bSuccess || ui8Status) + { + + UARTprintf("Set Param %x failed\n", TGAP_CONN_EST_SUPERV_TIMEOUT); + } + + return bSuccess; +} + +//***************************************************************************** +// +// This function authenticates with the slave device. +// +//***************************************************************************** +bool +Authenticate(void) +{ + bool bSuccess = false; + uint8_t ui8Status; + + if(g_psDev[g_ui8DevConnect].sSaveKey.bValid == false) + { + UARTprintf("Initiate Pairing Request...\n"); + GAPAuthenticate(g_ui16Handle); + + // + // Wait for CommandStatus response, timeout after 100ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_AUTHENTICATE_OPCODE, 100, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Wait for PasskeyNeeded event, timeout after 1s + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_PASSKEY_NEEDED, 0, 1000, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Got PasskeyNeeded event, send the key + // + GAPPassKeyUpdate(g_ui16Handle, "000000"); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_PASSKEY_UPDATE_OPCODE, 200, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Wait for AuthenticationComplete event, timeout after 5s + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_AUTHENTICATE_DONE, 0, 5000, &ui8Status); + } + } + } + } + else + { + UARTprintf("Bond Request...\n"); + GAPBond(g_ui16Handle, &g_psDev[g_ui8DevConnect].sSaveKey); + + // + // Wait for CommandStatus response, timeout after 100ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_BOND_OPCODE, 100, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Wait for BondComplete event, timeout after 1s + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_BOND_DONE, 0, 1000, &ui8Status); + } + } + + if(ui8Status != SUCCESS) + { + UARTprintf("Authenticate failure 0x%x\n", ui8Status); + return false; + } + return bSuccess; +} + +//***************************************************************************** +// +// This function establishes link to the slave. +// +//***************************************************************************** +bool +EstablishLink(uint8_t ui8DevIdx) +{ + bool bSuccess = false; + uint8_t ui8Status; + + UARTprintf("Link Request on device %d...\n", ui8DevIdx); + + GAPEstLinkReq(false, false, g_psDev[ui8DevIdx].ui8AddrType, g_psDev[ui8DevIdx].pui8Addr); + + // + // Wait for CommandStatus response, timeout after 100ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_EST_LINK_REQ_OPCODE, 100, &ui8Status); + if(bSuccess && (ui8Status == SUCCESS || ui8Status == bleAlreadyInRequestedMode)) + { + // + // Wait for EstablishLink response, timeout after 15s + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_LINK_DONE, 0, 15000, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Got DeviceInitDone response, go to the next state + // + if(g_bInitPairReq == true) + { + bSuccess = Authenticate(); + } + } + } + + if(ui8Status != SUCCESS) + { + return false; + } + return bSuccess; +} + +//***************************************************************************** +// +// This function terminates the link. +// +//***************************************************************************** +bool +TerminateLink(void) +{ + bool bSuccess = false; + uint8_t ui8Status; + + UARTprintf("Terminate Link Request...\n"); + + DeConfigureSensors(); + + // + // Send TeminateLink request + // + GAPTerLinkReq(g_ui16Handle, HCI_DISCONNECT_REMOTE_USER_TERM); + + // + // Wait for CommandStatus response, timeout after 200ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_TER_LINK_REQ_OPCODE, 200, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Wait for TerminateLink event, timeout after 1s + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_TERM_LINK_DONE, 0, 1000, &ui8Status); + } + + if(ui8Status != SUCCESS) + { + return false; + } + return bSuccess; +} + +//***************************************************************************** +// +// This function draws the animated circle during discovery state +// +//***************************************************************************** +void +DrawCircle(void) +{ + uint32_t ui32Idx; + + // + // Loop through the circles in the animation. + // + for(ui32Idx = 0; ui32Idx < 8; ui32Idx++) + { + // + // Draw this circle. + // + GrContextForegroundSet(&g_sContext, + g_pui32CircleColor[(g_ui32ColorIdx + + ui32Idx) & 7]); + GrCircleFill(&g_sContext, + (g_ui32Width / 2) + g_ppi32CirclePos[ui32Idx][0], + (g_ui32Height / 2) + g_ppi32CirclePos[ui32Idx][1] + 24, + 2); + } + + // + // Increment the color index. + // + g_ui32ColorIdx++; +} + +//***************************************************************************** +// +// Clear the screen +// +//***************************************************************************** +void ClearScreen(void) +{ + tRectangle sRect; + + // + // Clear the display. + // + sRect.i16XMin = 0; + sRect.i16YMin = 0; + sRect.i16XMax = g_ui32Width - 1; + sRect.i16YMax = g_ui32Height - 1; + GrContextForegroundSet(&g_sContext, ClrBlack); + GrRectFill(&g_sContext, &sRect); + GrContextForegroundSet(&g_sContext, ClrWhite); +} + +//***************************************************************************** +// +// Update the display. +// +//***************************************************************************** +void +UpdateDisplay(eDisplayUpdateIdx eUpdate) +{ + uint8_t ui8Loop; + char pcBuf[20]; + + // + // Clear the middle section of the display + // + ClearScreen(); + + // + // Update the middle of screen + // + if(eUpdate == iConnecting) + { + // + // show the to be connected device only + // + GrStringDrawCentered(&g_sContext, g_psDev[g_ui8DevConnect].pcName, -1, + g_ui32Width / 2, 60 + (40*g_ui8DevConnect), false); + + // + // Convert the device address into a string. + // + usprintf(pcBuf, "(%02x:%02x:%02x:%02x:%02x:%02x)", + g_psDev[g_ui8DevConnect].pui8Addr[5], + g_psDev[g_ui8DevConnect].pui8Addr[4], + g_psDev[g_ui8DevConnect].pui8Addr[3], + g_psDev[g_ui8DevConnect].pui8Addr[2], + g_psDev[g_ui8DevConnect].pui8Addr[1], + g_psDev[g_ui8DevConnect].pui8Addr[0]); + GrContextFontSet(&g_sContext, g_psFontCm14); + GrStringDrawCentered(&g_sContext, pcBuf, -1, + g_ui32Width / 2, 60 + (40*g_ui8DevConnect + 16), false); + GrContextFontSet(&g_sContext, g_psFontCmss16b); + + } + else if(eUpdate == iDisconnect) + { + GrStringDraw(&g_sContext, "IR Temperature:", -1, + (g_ui32Width / 2) - 110, 80, false); + GrStringDraw(&g_sContext, "Ambient Temperature:", -1, + (g_ui32Width / 2) - 110, 80 + 20, false); + GrStringDraw(&g_sContext, "RSSI:", -1, + (g_ui32Width / 2) - 110, 80 + 40, false); + GrStringDraw(&g_sContext, "Humidity:", -1, + (g_ui32Width / 2) - 110, 80 + 60, false); + + // + // clear the sensor date + // + g_dIRTemp = 0; + g_dAmbTemp = 0; + g_dHumidity = 0; + g_i8RSSI = 0; + + DisplayTemp(g_ui32Width / 2 + 80, 80); + DisplayRSSI(g_ui32Width / 2 + 80, 80 + 40); + DisplayHumidity(g_ui32Width / 2 + 80, 80 + 60); + } + else + { + if(ppcString[eUpdate][0]) + { + GrStringDrawCentered(&g_sContext, ppcString[eUpdate][0], -1, + g_ui32Width / 2, (g_ui32Height / 2) - 18, false); + } + else + { + + for(ui8Loop = 0; ui8Loop < g_ui8DevFound; ui8Loop++) + { + GrStringDrawCentered(&g_sContext, g_psDev[ui8Loop].pcName, -1, + g_ui32Width / 2, 60 + (40*ui8Loop), false); + + // + // Convert the device address into a string. + // + usprintf(pcBuf, "(%02x:%02x:%02x:%02x:%02x:%02x)", + g_psDev[ui8Loop].pui8Addr[5], + g_psDev[ui8Loop].pui8Addr[4], + g_psDev[ui8Loop].pui8Addr[3], + g_psDev[ui8Loop].pui8Addr[2], + g_psDev[ui8Loop].pui8Addr[1], + g_psDev[ui8Loop].pui8Addr[0]); + GrContextFontSet(&g_sContext, g_psFontCm14); + GrStringDrawCentered(&g_sContext, pcBuf, -1, + g_ui32Width / 2, 60 + (40*ui8Loop + 16), false); + GrContextFontSet(&g_sContext, g_psFontCmss16b); + } + } + } + + // + // Update the bottom text. + // + if(ppcString[eUpdate][1]) + { + GrStringDrawCentered(&g_sContext, ppcString[eUpdate][1], -1, + g_ui32Width / 2, 200, false); + } +} + +//***************************************************************************** +// +// Calculate the object temperature from TMP006 reading. +// Refer to TMP006 data sheet. +// +//***************************************************************************** +double +calculateTemp(int16_t i16Tdie, int16_t i16Vobj) +{ + double Vobj2 = (double)i16Vobj*.00000015625; + double i16Tdie2 = (double)i16Tdie*.03125 + 273.15; + double S0 = 6.40*pow(10,-14); + double a1 = 1.75*pow(10,-3); + double a2 = -1.678*pow(10,-5); + double b0 = -2.94*pow(10,-5); + double b1 = -5.70*pow(10,-8); + double b2 = 4.63*pow(10,-10); + double c2 = 13.4; + double Tref = 298.15; + double S = S0*(1+a1*(i16Tdie2 - Tref)+a2*pow((i16Tdie2 - Tref),2)); + double Vos = b0 + b1*(i16Tdie2 - Tref) + b2*pow((i16Tdie2 - Tref),2); + double fObj = (Vobj2 - Vos) + c2*pow((Vobj2 - Vos),2); + double Tobj = pow(pow(i16Tdie2,4) + (fObj/S),.25); + return (Tobj - 273.15); +} + +//***************************************************************************** +// +// This function converts the raw temperature reading to actual temperature in +// C and displays the temperatures on the display. +// +//***************************************************************************** +void +HandleTemp(void) +{ + int16_t i16VObj, i16TDie; + + UARTprintf("IR %02x %02x %02x %02x\n", g_pui8IRTemp[0], g_pui8IRTemp[1], + g_pui8IRTemp[2], g_pui8IRTemp[3]); + // + // The first two bytes are Object Voltage, + // the last two bytes are Die temperature + // + i16VObj = (int16_t)(g_pui8IRTemp[0] | (g_pui8IRTemp[1]<<8)); + i16TDie = (int16_t)(g_pui8IRTemp[2] | (g_pui8IRTemp[3]<<8)); + if(i16VObj && i16TDie) + { + g_dIRTemp = calculateTemp(i16TDie>>2, i16VObj); + g_dAmbTemp = (double)i16TDie /128.0; + DisplayTemp(g_ui32Width / 2 + 80, 80); + } +} + +//***************************************************************************** +// +// This function converts the raw humidity to humidity in rH and displays it +// on the display. +// +//***************************************************************************** +void +HandleHumidity(void) +{ + uint16_t ui16RawH; + + // + // The first two bytes are temperature(ignored) + // the last two bytes are humitity + // + ui16RawH = (g_pui8Humidity[2] | (g_pui8Humidity[3]<<8)); + UARTprintf("Humidity %04x\n", ui16RawH); + + // + // Conversion algorithm for Humidity + // + ui16RawH &= ~0x0003; // clear bits [1..0] (status bits) + g_dHumidity = -6.0 + (125.0 *(double)ui16RawH)/65536; // RH= -6 + 125 * SRH/2^16 + DisplayHumidity(g_ui32Width / 2 + 80, 80 + 60); +} + +//***************************************************************************** +// +// Display IR and Ambient temperatures on the display. +// +//***************************************************************************** +void +DisplayTemp(uint32_t ui32X, uint32_t ui32Y) +{ + char pcBuf[16]; + int16_t i16IRInt, i16IRFrac; + tRectangle sRect; + + i16IRInt = ((int16_t)(g_dIRTemp*100))/100; + i16IRFrac = (int16_t)(g_dIRTemp*100) - i16IRInt*100; + UARTprintf("IR temp = %d.%d\n", i16IRInt, i16IRFrac); + + // + // Convert the temperature into a string. + // + usprintf(pcBuf, "%d.%dC", i16IRInt, i16IRFrac); + + // + // Clear the previous reading. + // + sRect.i16XMin = ui32X; + sRect.i16YMin = ui32Y; + sRect.i16XMax = ui32X + 60; + sRect.i16YMax = ui32Y + 20; + GrContextForegroundSet(&g_sContext, ClrBlack); + GrRectFill(&g_sContext, &sRect); + GrContextForegroundSet(&g_sContext, ClrWhite); + + // + // Display the IR temperature. + // + GrStringDraw(&g_sContext, pcBuf, -1, ui32X, ui32Y, false); + + i16IRInt = ((int16_t)(g_dAmbTemp*100))/100; + i16IRFrac = (int16_t)(g_dAmbTemp*100) - i16IRInt*100; + UARTprintf("Ambient temp = %d.%d\n", i16IRInt, i16IRFrac); + + // + // Convert the temperature into a string. + // + usprintf(pcBuf, "%d.%dC", i16IRInt, i16IRFrac); + + // + // Clear the previous temperature. + // + sRect.i16XMin = ui32X; + sRect.i16YMin = ui32Y + 20; + sRect.i16XMax = ui32X + 60; + sRect.i16YMax = ui32Y + 40; + GrContextForegroundSet(&g_sContext, ClrBlack); + GrRectFill(&g_sContext, &sRect); + GrContextForegroundSet(&g_sContext, ClrWhite); + + // + // Display the Ambient temperatur. + // + GrStringDraw(&g_sContext, pcBuf, -1, ui32X, ui32Y + 20, false); +} + +//***************************************************************************** +// +// Display RSSI on the display. +// +//***************************************************************************** +void +DisplayRSSI(uint32_t ui32X, uint32_t ui32Y) +{ + char pcBuf[16]; + tRectangle sRect; + + // + // Convert the RSSI data into a string. + // + if(g_i8RSSI >= 0) + { + // + // RSSI has to be negative value, discard the nonvalid data. + // + return; + } + usprintf(pcBuf, "%ddBm", g_i8RSSI); + + // + // Clear the previous reading. + // + sRect.i16XMin = ui32X; + sRect.i16YMin = ui32Y; + sRect.i16XMax = ui32X + 60; + sRect.i16YMax = ui32Y + 20; + GrContextForegroundSet(&g_sContext, ClrBlack); + GrRectFill(&g_sContext, &sRect); + GrContextForegroundSet(&g_sContext, ClrWhite); + + // + // Display on the screen. + // + GrStringDraw(&g_sContext, pcBuf, -1, ui32X, ui32Y, false); +} + +//***************************************************************************** +// +// Display Humidity on the display. +// +//***************************************************************************** +void +DisplayHumidity(uint32_t ui32X, uint32_t ui32Y) +{ + char pcBuf[16]; + tRectangle sRect; + uint16_t ui8Int, ui8Frac; + + ui8Int = (uint16_t)(g_dHumidity); + ui8Frac = (uint16_t)(g_dHumidity*10) - ui8Int*10; + UARTprintf("Humidity = %02d.%01d\n", ui8Int, ui8Frac); + + // + // Convert the humidity into a string. + // + usprintf(pcBuf, "%d.%01d%%rH", ui8Int, ui8Frac); + + // + // Clear the previous reading. + // + sRect.i16XMin = ui32X; + sRect.i16YMin = ui32Y; + sRect.i16XMax = ui32X + 70; + sRect.i16YMax = ui32Y + 20; + GrContextForegroundSet(&g_sContext, ClrBlack); + GrRectFill(&g_sContext, &sRect); + GrContextForegroundSet(&g_sContext, ClrWhite); + + // + // Display on the screen. + // + GrStringDraw(&g_sContext, pcBuf, -1, ui32X, ui32Y, false); +} + +//***************************************************************************** +// +// This example demonstrates how to communicate a BLE slave using TI's CC2540 +// EM on TM4C129X Development board. +// +//***************************************************************************** +int +main(void) +{ + uint32_t ui32SysClock; + bool bSuccess; + uint8_t ui8Status; + uint8_t pui8IRKOrCSRK[16]; + + // + // Run from the PLL at 120 MHz. + // + ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | + SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | + SYSCTL_CFG_VCO_480), 120000000); + + // + // Configure the device pins. + // + PinoutSet(); + + // + // Initialize the display driver. + // + Kentec320x240x16_SSD2119Init(ui32SysClock); + + // + // Initialize the graphics context. + // + GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); + + // + // Draw the application frame. + // + FrameDraw(&g_sContext, "ble-central"); + GrContextFontSet(&g_sContext, g_psFontCmss16b); + + // + // Initialize the touch screen driver + // + TouchScreenInit(ui32SysClock); + TouchScreenCallbackSet(TouchCallback); + + // + // UART 0 is used for debugging message console. + // + UARTStdioConfig(0, 115200, ui32SysClock); + + UARTprintf("\nBLE Central demo running...\n"); + + // + // Get the width and height of the display. + // + g_ui32Width = GrContextDpyWidthGet(&g_sContext); + g_ui32Height = GrContextDpyHeightGet(&g_sContext); + + // + // UART3 is used to communicate with CC2540, configure the pins. + // PJ0, 1, 4, 5 are used for UART3. + // + ROM_GPIOPinConfigure(GPIO_PJ0_U3RX); + ROM_GPIOPinConfigure(GPIO_PJ1_U3TX); + ROM_GPIOPinConfigure(GPIO_PJ4_U3RTS); + ROM_GPIOPinConfigure(GPIO_PJ5_U3CTS); + ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1 | + GPIO_PIN_4 | GPIO_PIN_5); + + // + // EnableUART3 + // + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); + + // + // Configure the UART3 for 115,200, 8-N-1 operation. + // + ROM_UARTConfigSetExpClk(UART3_BASE, ui32SysClock, 115200, + (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | + UART_CONFIG_PAR_NONE)); + + // + // Configure UART3 to use hardware flow control. + // + UARTFlowControlSet(UART3_BASE, UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX); + + // + // Enable processor interrupts. + // + IntMasterEnable(); + + // + // Enable the UART interrupt. + // + ROM_IntEnable(INT_UART3); + ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); + + + // + // Clear timeout value + // + g_ui32Delay = 0; + + // + // Configure SysTick for a periodic interrupt at 10ms. + // + ROM_SysTickPeriodSet(ui32SysClock / 100); + ROM_SysTickEnable(); + ROM_SysTickIntEnable(); + + // + // clear the device info and RX buffer + // + memset(g_psDev, 0, sizeof(g_psDev)); + memset(&g_sRxBuf, 0, sizeof(tCirBuf)); + + // + // Start the state machine with initial state + // + g_iState = STATE_DEV_INIT; + + // + // Display "Initializing" on the bottom of screen + // + UpdateDisplay(iInitializing); + + while(1) + { + switch(g_iState) + { + case STATE_DEV_INIT: + + UARTprintf("Device Init...\n"); + + // + // Send GAP_DeviceInit command + // + memset(pui8IRKOrCSRK, 0, 16); + GAPDeviceInit(GAP_PROFILE_CENTRAL, 5, pui8IRKOrCSRK, pui8IRKOrCSRK, 1); + + // + // Wait for CommandStatus response, timeout after 500ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_INIT_OPCODE, 500, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Wait for DeviceInitDone response, timeout after 500ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_INIT_DONE, 0, 500, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Got DeviceInitDone response, go to the next state + // + g_iState = STATE_GET_PARAM; + } + } + else + { + UARTprintf("CC2540 EM board is not connected to the DK\n"); + UpdateDisplay(iNoBLE); + + // + // Hang forever + // + while(1); + } + break; + + case STATE_GET_PARAM: + if(GetParam()) + { + // + // Query parameter successful, go to the discovery state + // + g_bDiscoveryReq = true; + g_iState = STATE_START_DISCOVERY; + UARTprintf("Ready to scan devices\n"); + + // + // Update display + // + UpdateDisplay(iScanning); + } + else + { + // + // cannot query parameters on CC2540, something wrong, + // go to the error state + // + g_iState = STATE_ERROR; + } + break; + + case STATE_START_DISCOVERY: + if(g_bDiscoveryReq) + { + UARTprintf("Start Discovery...\n"); + + // + // Clear the number of devices discovered + // + g_ui8DevFound = 0; + + // + // Start to draw circle periodically + // + HWREGBITW(&g_ui32Flags, FLAG_DRAW_CIRCLE) = 1; + + // + // Send Discovery command + // + GAPDiscoveryReq(DEVDISC_MODE_ALL, true, false); + + // + // Wait for CommandStatus response, timeout after 100ms + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_CMD_STATUS, HCI_VE_GAP_DEVICE_DISC_REQ_OPCODE, 100, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Wait for DiscoveryDone response, timeout after 20s + // + bSuccess = WaitForRsp(GAP_HCI_EVENT_EXT_DEVICE_DISC_DONE, 0, 20000, &ui8Status); + if(bSuccess && ui8Status == SUCCESS) + { + // + // Have we discovered any device? + // + if(g_ui8DevFound) + { + // + // Got DiscoveryDone response, go to the next state + // + g_iState = STATE_SET_PARAM; + } + else + { + // + // No device found: + // Stop drawing the circles. + // + HWREGBITW(&g_ui32Flags, FLAG_DRAW_CIRCLE) = 0; + + // + // show the scan button on the bottom of the + // screen in order to repeat the scanning. + // + UpdateDisplay(iScan); + } + g_bDiscoveryReq = false; + } + } + } + break; + + case STATE_SET_PARAM: + if(SetParam()) + { + // + // Configure parameters are successful, + // go to the next state + // + g_iState = STATE_READY_FOR_LINK_REQ; + UARTprintf("Discovery done\n"); + + HWREGBITW(&g_ui32Flags, FLAG_DRAW_CIRCLE) = 0; + UpdateDisplay(iConnect); + } + else + { + // + // Failed to configure the parameters, + // go to the error state + // + g_iState = STATE_ERROR; + } + break; + + case STATE_READY_FOR_LINK_REQ: + // + // Wait for user to connect any device + // + if(g_bEstLinkReq == true) + { + // + // Received connect command from user, + // go to the next state to connect the device + // + UpdateDisplay(iConnecting); + g_iState = STATE_LINK; + g_bEstLinkReq = false; + } + + // + // Wait for user to do discovery/scan again + // + if(g_bDiscoveryReq == true) + { + // + // Discovery/scan is requested by user + // + g_iState = STATE_START_DISCOVERY; + + // + // Update display + // + UpdateDisplay(iScanning); + } + break; + + case STATE_LINK: + // + // Connect to the device + // + if( EstablishLink(g_ui8DevConnect)) + { + // + // Connected the device without errors. + // go to the next state. + // + g_iState = STATE_LINKED; + + // + // Display the sensor information. + // + UpdateDisplay(iDisconnect); + } + else + { + // + // Link failed, go back to STATE_READY_FOR_LINK_REQ. + // + UARTprintf("Link failed, go back to ready for link state\n"); + g_iState = STATE_READY_FOR_LINK_REQ; + UpdateDisplay(iConnect); + } + break; + + case STATE_LINKED: + // + // Handle Terminate request if any + // + if(g_bTermLinkReq == true) + { + g_iState = STATE_TERM; + UpdateDisplay(iDisconnecting); + break; + } + + // + // Configure the sensor profiles. + // + ConfigureSensors(); + + // + // Check for any sensor notify event + // + CheckForMsg(); + + // + // We will read the device's RSSI every second. + // + if(HWREGBITW(&g_ui32Flags, FLAG_EVERY_SECOND) == 1) + { + HWREGBITW(&g_ui32Flags, FLAG_EVERY_SECOND) = 0; + + // + // Read RSSI + // + HCIReadRSSI(g_ui16Handle); + } + break; + + case STATE_TERM: + // + // We are told to termniate the link. + // + if(TerminateLink()) + { + // + // Terminate success, go to the next state + // + g_iState = STATE_TERMED; + g_bTermLinkReq = false; + } + else + { + //TODO + g_iState = STATE_TERMED; + g_bTermLinkReq = false; + + } + break; + + case STATE_TERMED: + // + // Terminated, go to the next state + // + g_iState = STATE_READY_FOR_LINK_REQ; + UpdateDisplay(iConnect); + break; + + case STATE_IDLE: + default: + // + // Check any messages. + // + CheckForMsg(); + break; + } + } +} diff --git a/boards/dk-tm4c129x/ble_central/ble_central.ewd b/boards/dk-tm4c129x/ble_central/ble_central.ewd new file mode 100644 index 0000000..484e41a --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.ewd @@ -0,0 +1,614 @@ + + + + 1 + + Debug + + ARM + + 1 + + C-SPY + 2 + + 15 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + ARMSIM_ID + 2 + + 1 + 1 + 1 + + + + + + + + ANGEL_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + + GDBSERVER_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + IARROM_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + JLINK_ID + 2 + + 9 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LMIFTDI_ID + 2 + + 1 + 1 + 1 + + + + + + + + MACRAIGOR_ID + 2 + + 2 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + RDI_ID + 2 + + 1 + 1 + 1 + + + + + + + + + + + + + + + + + THIRDPARTY_ID + 2 + + 0 + 1 + 1 + + + + + + + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxArmPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxTinyArmPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\embOS\embOSPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\OSE\OseEpsilonPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\PowerPac\PowerPacRTOS.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\ThreadX\ThreadXArmPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\uCOS-II\uCOS-II-KA-CSpy.ewplugin + 0 + + + $EW_DIR$\common\plugins\CodeCoverage\CodeCoverage.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\Orti\Orti.ENU.ewplugin + 0 + + + $EW_DIR$\common\plugins\Profiling\Profiling.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\Stack\Stack.ENU.ewplugin + 1 + + + + diff --git a/boards/dk-tm4c129x/ble_central/ble_central.ewp b/boards/dk-tm4c129x/ble_central/ble_central.ewp new file mode 100644 index 0000000..5388441 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.ewp @@ -0,0 +1,810 @@ + + + + 1 + + Debug + + ARM + + 1 + + General + 3 + + 14 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 19 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 7 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 5 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + + Libraries + + $PROJ_DIR$\..\..\..\..\driverlib\ewarm\Exe\driverlib.a + + + $PROJ_DIR$\..\..\..\..\grlib\ewarm\Exe\grlib.a + + + + Source + + $PROJ_DIR$\ble_central.c + + + $PROJ_DIR$\..\drivers\frame.c + + + $PROJ_DIR$\gap.c + + + $PROJ_DIR$\..\drivers\kentec320x240x16_ssd2119.c + + + $PROJ_DIR$\..\drivers\pinout.c + + + $PROJ_DIR$\startup_ewarm.c + + + $PROJ_DIR$\..\drivers\touch.c + + + $PROJ_DIR$\..\..\..\..\utils\uartstdio.c + + + $PROJ_DIR$\..\..\..\..\utils\ustdlib.c + + + diff --git a/boards/dk-tm4c129x/ble_central/ble_central.icf b/boards/dk-tm4c129x/ble_central/ble_central.icf new file mode 100644 index 0000000..681cc5a --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.icf @@ -0,0 +1,78 @@ +//***************************************************************************** +// +// ble_central.icf - Linker configuration file for ble_central. +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +// +// Define a memory region that covers the entire 4 GB addressible space of the +// processor. +// +define memory mem with size = 4G; + +// +// Define a region for the on-chip flash. +// +define region FLASH = mem:[from 0x00000000 to 0x000fffff]; + +// +// Define a region for the on-chip SRAM. +// +define region SRAM = mem:[from 0x20000000 to 0x2003ffff]; + +// +// Define a block for the heap. The size should be set to something other +// than zero if things in the C library that require the heap are used. +// +define block HEAP with alignment = 8, size = 0x00000000 { }; + +// +// Indicate that the read/write values should be initialized by copying from +// flash. +// +initialize by copy { readwrite }; + +// +// Indicate that the noinit values should be left alone. This includes the +// stack, which if initialized will destroy the return address from the +// initialization code, causing the processor to branch to zero and fault. +// +do not initialize { section .noinit }; + +// +// Place the interrupt vectors at the start of flash. +// +place at start of FLASH { readonly section .intvec }; + +// +// Place the remainder of the read-only items into flash. +// +place in FLASH { readonly }; + +// +// Place the RAM vector table at the start of SRAM. +// +place at start of SRAM { section VTABLE }; + +// +// Place all read/write items into SRAM. +// +place in SRAM { readwrite, block HEAP }; diff --git a/boards/dk-tm4c129x/ble_central/ble_central.ld b/boards/dk-tm4c129x/ble_central/ble_central.ld new file mode 100644 index 0000000..c528e4b --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.ld @@ -0,0 +1,57 @@ +/****************************************************************************** + * + * ble_central.ld - Linker configuration file for ble_central. + * + * Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. + * Software License Agreement + * + * Texas Instruments (TI) is supplying this software for use solely and + * exclusively on TI's microcontroller products. The software is owned by + * TI and/or its suppliers, and is protected under applicable copyright + * laws. You may not combine this software with "viral" open-source + * software in order to form a larger program. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. + * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT + * NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY + * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES, FOR ANY REASON WHATSOEVER. + * + * This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. + * + *****************************************************************************/ + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000 + SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000 +} + +SECTIONS +{ + .text : + { + _text = .; + KEEP(*(.isr_vector)) + *(.text*) + *(.rodata*) + _etext = .; + } > FLASH + + .data : AT(ADDR(.text) + SIZEOF(.text)) + { + _data = .; + *(vtable) + *(.data*) + _edata = .; + } > SRAM + + .bss : + { + _bss = .; + *(.bss*) + *(COMMON) + _ebss = .; + } > SRAM +} diff --git a/boards/dk-tm4c129x/ble_central/ble_central.sct b/boards/dk-tm4c129x/ble_central/ble_central.sct new file mode 100644 index 0000000..b1e6c8a --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.sct @@ -0,0 +1,47 @@ +;****************************************************************************** +; +; ble_central.sct - Linker configuration file for ble_central. +; +; Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +; Software License Agreement +; +; Texas Instruments (TI) is supplying this software for use solely and +; exclusively on TI's microcontroller products. The software is owned by +; TI and/or its suppliers, and is protected under applicable copyright +; laws. You may not combine this software with "viral" open-source +; software in order to form a larger program. +; +; THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +; NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +; NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +; CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +; DAMAGES, FOR ANY REASON WHATSOEVER. +; +; This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +; +;****************************************************************************** + +LR_IROM 0x00000000 0x00100000 +{ + ; + ; Specify the Execution Address of the code and the size. + ; + ER_IROM 0x00000000 0x00100000 + { + *.o (RESET, +First) + * (InRoot$$Sections, +RO) + } + + ; + ; Specify the Execution Address of the data area. + ; + RW_IRAM 0x20000000 0x00040000 + { + ; + ; Uncomment the following line in order to use IntRegister(). + ; + ;* (vtable, +First) + * (+RW, +ZI) + } +} diff --git a/boards/dk-tm4c129x/ble_central/ble_central.uvopt b/boards/dk-tm4c129x/ble_central/ble_central.uvopt new file mode 100644 index 0000000..90855bc --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.uvopt @@ -0,0 +1,401 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + + + + 0 + 0 + + + + ble_central + 0x4 + ARM-ADS + + 25000000 + + 1 + 1 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\rvmdk\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + + 0 + Data Sheet + DATASHTS\Luminary\TM4C129XNCZAD.PDF + + + + SARMCM3.DLL + -MPU + DCM.DLL + -pCM4 + SARMCM3.DLL + -MPU + TCM.DLL + -pCM4 + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 0 + 0 + 4 + + + + + + + + + + + BIN\lmidk-agdi.dll + + + + 0 + lmidk-agdi + -O4614 -S1 -FO29 + + + 0 + DLGTARM + + + + 0 + ARMDBGFLAGS + + + + + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + Source + 1 + 0 + 0 + + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\ble_central.c + ble_central.c + + + 1 + 2 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\frame.c + frame.c + + + 1 + 3 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\gap.c + gap.c + + + 1 + 4 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\kentec320x240x16_ssd2119.c + kentec320x240x16_ssd2119.c + + + 1 + 5 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\pinout.c + pinout.c + + + 1 + 6 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\startup_rvmdk.S + startup_rvmdk.S + + + 1 + 7 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\touch.c + touch.c + + + 1 + 8 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\uartstdio.c + uartstdio.c + + + 1 + 9 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\ustdlib.c + ustdlib.c + + + + + Libraries + 1 + 0 + 0 + + 2 + 10 + 4 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\driverlib\rvmdk\driverlib.lib + driverlib.lib + + + 2 + 11 + 4 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\grlib\rvmdk\grlib.lib + grlib.lib + + + + + Documentation + 1 + 0 + 0 + + 3 + 12 + 5 + 0 + 1 + 0 + 0 + 1 + 1 + 0 + .\readme.txt + readme.txt + + 44 + 0 + 1 + + -1 + -1 + + + -1 + -1 + + + 0 + 0 + 729 + 300 + + + + + + + 1 + 0 + + 100 + 0 + + + .\readme.txt + 0 + 1 + 1 + + + + + +
diff --git a/boards/dk-tm4c129x/ble_central/ble_central.uvproj b/boards/dk-tm4c129x/ble_central/ble_central.uvproj new file mode 100644 index 0000000..11a43fa --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central.uvproj @@ -0,0 +1,464 @@ + + + + 1.1 + +
### uVision Project, (C) Keil Software
+ + + + ble_central + 0x4 + ARM-ADS + + + TM4C129XNCZAD + Texas Instruments + IRAM(0x20000000-0x2003FFFF) IROM(0-0xFFFFF) CLOCK(25000000) CPUTYPE("Cortex-M4") FPU2 + + "STARTUP\Luminary\Startup.s" ("Luminary Startup Code") + UL2CM3(-O207 -S0 -C0 -FO7 -FD20000000 -FC800 -FN1 -FF0LM4F_1024 -FS00 -FL0100000) + 5919 + LM4Fxxxx.H + + + + + + + + + + 0 + + + + Luminary\ + Luminary\ + + 0 + 0 + 0 + 0 + 1 + + .\rvmdk\ + ble_central + 1 + 0 + 0 + 1 + 1 + .\rvmdk\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 1 + 0 + fromelf --bin --output .\rvmdk\ble_central.bin .\rvmdk\ble_central.axf + + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + + + SARMCM3.DLL + -MPU + DCM.DLL + -pCM4 + SARMCM3.DLL + -MPU + TCM.DLL + -pCM4 + + + + 1 + 0 + 0 + 0 + 16 + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + + + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + + 0 + 4 + + + + + + + + + + + + + + BIN\lmidk-agdi.dll + + + + + 1 + 0 + 0 + 0 + 1 + 4099 + + BIN\lmidk-agdi.dll + + + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M4" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 2 + 0 + 0 + 8 + 1 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x40000 + + + 1 + 0x0 + 0x100000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x100000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + + + + 0 + 3 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + + --c99 + rvmdk PART_TM4C129XNCZAD TARGET_IS_TM4C129_RA0 + + ..;..\..\..\..; + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + ble_central.sct + + + --entry Reset_Handler + + + + + + + + Source + + + ble_central.c + 1 + .\ble_central.c + + + frame.c + 1 + ..\drivers\frame.c + + + gap.c + 1 + .\gap.c + + + kentec320x240x16_ssd2119.c + 1 + ..\drivers\kentec320x240x16_ssd2119.c + + + pinout.c + 1 + ..\drivers\pinout.c + + + startup_rvmdk.S + 2 + .\startup_rvmdk.S + + + touch.c + 1 + ..\drivers\touch.c + + + uartstdio.c + 1 + ..\..\..\..\utils\uartstdio.c + + + ustdlib.c + 1 + ..\..\..\..\utils\ustdlib.c + + + + + Libraries + + + driverlib.lib + 4 + ..\..\..\..\driverlib\rvmdk\driverlib.lib + + + grlib.lib + 4 + ..\..\..\..\grlib\rvmdk\grlib.lib + + + + + Documentation + + + readme.txt + 5 + .\readme.txt + + + + + + + +
diff --git a/boards/dk-tm4c129x/ble_central/ble_central_ccs.cmd b/boards/dk-tm4c129x/ble_central/ble_central_ccs.cmd new file mode 100644 index 0000000..96f68e9 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ble_central_ccs.cmd @@ -0,0 +1,70 @@ +/****************************************************************************** + * + * ble_central_ccs.cmd - CCS linker configuration file for ble_central. + * + * Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. + * Software License Agreement + * + * Texas Instruments (TI) is supplying this software for use solely and + * exclusively on TI's microcontroller products. The software is owned by + * TI and/or its suppliers, and is protected under applicable copyright + * laws. You may not combine this software with "viral" open-source + * software in order to form a larger program. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. + * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT + * NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY + * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES, FOR ANY REASON WHATSOEVER. + * + * This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. + * + *****************************************************************************/ + +--retain=g_pfnVectors + +/* 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. */ +#define APP_BASE 0x00000000 +#define RAM_BASE 0x20000000 + +/* System memory map */ + +MEMORY +{ + /* Application stored in and executes from internal flash */ + FLASH (RX) : origin = APP_BASE, length = 0x00100000 + /* Application uses internal RAM for data */ + SRAM (RWX) : origin = 0x20000000, length = 0x00040000 +} + +/* Section allocation in memory */ + +SECTIONS +{ + .intvecs: > APP_BASE + .text : > FLASH + .const : > FLASH + .cinit : > FLASH + .pinit : > FLASH + .init_array : > FLASH + + .vtable : > RAM_BASE + .data : > SRAM + .bss : > SRAM + .sysmem : > SRAM + .stack : > SRAM +} + +__STACK_TOP = __stack + 1024; diff --git a/boards/dk-tm4c129x/ble_central/ccs/.ccsimportspec b/boards/dk-tm4c129x/ble_central/ccs/.ccsimportspec new file mode 100644 index 0000000..45bc2ed --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/.ccsimportspec @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/boards/dk-tm4c129x/ble_central/ccs/.ccsproject b/boards/dk-tm4c129x/ble_central/ccs/.ccsproject new file mode 100644 index 0000000..59a3400 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/.ccsproject @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/boards/dk-tm4c129x/ble_central/ccs/.cproject b/boards/dk-tm4c129x/ble_central/ccs/.cproject new file mode 100644 index 0000000..4e1735b --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/.cproject @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/boards/dk-tm4c129x/ble_central/ccs/.project b/boards/dk-tm4c129x/ble_central/ccs/.project new file mode 100644 index 0000000..0c9843d --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/.project @@ -0,0 +1,85 @@ + + + ble_central + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.ti.ccstudio.core.ccsNature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + ble_central.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/ble_central/ble_central.c + + + ble_central_ccs.cmd + 1 + SW_ROOT/examples/boards/dk-tm4c129x/ble_central/ble_central_ccs.cmd + + + gap.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/ble_central/gap.c + + + startup_ccs.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/ble_central/startup_ccs.c + + + drivers/frame.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/drivers/frame.c + + + drivers/kentec320x240x16_ssd2119.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/drivers/kentec320x240x16_ssd2119.c + + + drivers/pinout.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/drivers/pinout.c + + + drivers/touch.c + 1 + SW_ROOT/examples/boards/dk-tm4c129x/drivers/touch.c + + + utils/uartstdio.c + 1 + SW_ROOT/utils/uartstdio.c + + + utils/ustdlib.c + 1 + SW_ROOT/utils/ustdlib.c + + + + + SW_ROOT + $%7BPARENT-5-PROJECT_LOC%7D + + + diff --git a/boards/dk-tm4c129x/ble_central/ccs/.settings/org.eclipse.cdt.codan.core.prefs b/boards/dk-tm4c129x/ble_central/ccs/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.bin b/boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.bin new file mode 100644 index 0000000..e0dd72c Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.bin differ diff --git a/boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.out b/boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.out new file mode 100644 index 0000000..77f2e2e Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/ccs/Debug/ble_central.out differ diff --git a/boards/dk-tm4c129x/ble_central/ccs/macros.ini_initial b/boards/dk-tm4c129x/ble_central/ccs/macros.ini_initial new file mode 100644 index 0000000..31214b5 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/macros.ini_initial @@ -0,0 +1 @@ +SW_ROOT = ../../../../.. diff --git a/boards/dk-tm4c129x/ble_central/ccs/target_config.ccxml b/boards/dk-tm4c129x/ble_central/ccs/target_config.ccxml new file mode 100644 index 0000000..6e5ef45 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/ccs/target_config.ccxml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.bin b/boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.bin new file mode 100644 index 0000000..4759a71 Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.bin differ diff --git a/boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.out b/boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.out new file mode 100644 index 0000000..6c8f670 Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/ewarm/Exe/ble_central.out differ diff --git a/boards/dk-tm4c129x/ble_central/gap.c b/boards/dk-tm4c129x/ble_central/gap.c new file mode 100644 index 0000000..086b21c --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/gap.c @@ -0,0 +1,371 @@ +//***************************************************************************** +// +// gap.c - GAP configuration and control APIs +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#include +#include +#include +#include "hci.h" +#include "utils/uartstdio.h" + +//***************************************************************************** +// +// TX buffer used by all APIs. +// +//***************************************************************************** +uint8_t g_pui8TXBuf[64]; +uint8_t g_ui8TXLen; + +//***************************************************************************** +// +// Forward reference of functions used in this file. +// +//***************************************************************************** +extern void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count); +extern void DumpBuffer(uint8_t *pui8Buf, uint32_t ui32Len, bool bTX); + +//***************************************************************************** +// +// GAP Device Initialization Request +// +//***************************************************************************** +void +GAPDeviceInit(uint8_t ui8ProfileRole, + uint8_t ui8MaxScanRsps, + uint8_t *pui8IRK, + uint8_t *pui8SRK, + uint32_t ui32SignCounter) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_INIT_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (HCI_VE_GAP_DEVICE_INIT_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 38; + g_pui8TXBuf[g_ui8TXLen++] = ui8ProfileRole; + g_pui8TXBuf[g_ui8TXLen++] = ui8MaxScanRsps; + memcpy(g_pui8TXBuf + g_ui8TXLen, pui8IRK, 16); + g_ui8TXLen +=16; + memcpy(g_pui8TXBuf + g_ui8TXLen, pui8SRK, 16); + g_ui8TXLen +=16; + g_pui8TXBuf[g_ui8TXLen++] = ui32SignCounter & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui32SignCounter >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui32SignCounter >> 16) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui32SignCounter >> 24) & 0xFF; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// GAP Get Parameter Request. +// +//***************************************************************************** +void +GAPGetParam(uint8_t ui8ParamID) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_GET_PARAM_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (HCI_VE_GAP_GET_PARAM_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 1; + g_pui8TXBuf[g_ui8TXLen++] = ui8ParamID; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// GAP Set Parameter request. +// +//***************************************************************************** +void +GAPSetParam(uint8_t ui8ParamID, uint16_t ui16Value) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_SET_PARAM_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (HCI_VE_GAP_SET_PARAM_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 3; + g_pui8TXBuf[g_ui8TXLen++] = ui8ParamID; + g_pui8TXBuf[g_ui8TXLen++] = ui16Value & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16Value >> 8) & 0xFF; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// Start Discovery Request. +// +//***************************************************************************** +void +GAPDiscoveryReq(uint8_t ui8Mode, bool bActiveScan, bool bWhiteList) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_DISC_REQ_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (HCI_VE_GAP_DEVICE_DISC_REQ_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 3; + g_pui8TXBuf[g_ui8TXLen++] = ui8Mode; + g_pui8TXBuf[g_ui8TXLen++] = bActiveScan; + g_pui8TXBuf[g_ui8TXLen++] = bWhiteList; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// Establish Link Request. +// +//***************************************************************************** +void +GAPEstLinkReq(bool bHighDutyCycle, bool bWhiteList, + uint8_t ui8AddrType, uint8_t *pui8DevAddr) +{ + uint8_t ui8Idx; + + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_EST_LINK_REQ_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = + (HCI_VE_GAP_DEVICE_EST_LINK_REQ_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 9; + g_pui8TXBuf[g_ui8TXLen++] = bHighDutyCycle; + g_pui8TXBuf[g_ui8TXLen++] = bWhiteList; + g_pui8TXBuf[g_ui8TXLen++] = ui8AddrType; + for(ui8Idx = 0; ui8Idx < HCI_BDADDR_LEN; ui8Idx++) + { + g_pui8TXBuf[g_ui8TXLen++] = pui8DevAddr[ui8Idx]; + } + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// Terminate Link Request. +// +//***************************************************************************** +void +GAPTerLinkReq(uint16_t ui16ConnHandle, uint8_t ui8Reason) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_TER_LINK_REQ_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = + (HCI_VE_GAP_DEVICE_TER_LINK_REQ_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 3; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16ConnHandle >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = ui8Reason; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// Start Pairing Request. +// +//***************************************************************************** +void +GAPAuthenticate(uint16_t ui16ConnHandle) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_AUTHENTICATE_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = + (HCI_VE_GAP_DEVICE_AUTHENTICATE_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 29; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16ConnHandle >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 0x04; //KeyboardDisplay + g_pui8TXBuf[g_ui8TXLen++] = 0x00; //oob false + memset(&g_pui8TXBuf[g_ui8TXLen], 0, 16); + g_ui8TXLen +=16; + g_pui8TXBuf[g_ui8TXLen++] = 0x05; //AuthReq + g_pui8TXBuf[g_ui8TXLen++] = 0x10; // MaxEKeySize + g_pui8TXBuf[g_ui8TXLen++] = 0x3F; // KeyDist + g_pui8TXBuf[g_ui8TXLen++] = 0x00; // Pair.enable + g_pui8TXBuf[g_ui8TXLen++] = 0x03; // Pair.ioCaps + g_pui8TXBuf[g_ui8TXLen++] = 0x00; // Pair.oobDFlag + + g_pui8TXBuf[g_ui8TXLen++] = 0x01; // Pair.authReq + g_pui8TXBuf[g_ui8TXLen++] = 0x10; // MaxEKeySize + g_pui8TXBuf[g_ui8TXLen++] = 0x3F; // KeyDist + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// PASS key during Authentication. +// +//***************************************************************************** +void +GAPPassKeyUpdate(uint16_t ui16ConnHandle, char *pcPassCode) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_PASSKEY_UPDATE_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = + (HCI_VE_GAP_DEVICE_PASSKEY_UPDATE_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 8; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16ConnHandle >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = pcPassCode[0]; + g_pui8TXBuf[g_ui8TXLen++] = pcPassCode[1]; + g_pui8TXBuf[g_ui8TXLen++] = pcPassCode[2]; + g_pui8TXBuf[g_ui8TXLen++] = pcPassCode[3]; + g_pui8TXBuf[g_ui8TXLen++] = pcPassCode[4]; + g_pui8TXBuf[g_ui8TXLen++] = pcPassCode[5]; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// GAP Bonding Request. +// +//***************************************************************************** +void +GAPBond(uint16_t ui16ConnHandle, tLTKData *psSavedKey) +{ + uint8_t ui8Loop; + + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_BOND_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (HCI_VE_GAP_DEVICE_BOND_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 30; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16ConnHandle >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = psSavedKey->bAuth; + for(ui8Loop = 0; ui8Loop < psSavedKey->ui8LTKSize; ui8Loop++) + { + g_pui8TXBuf[g_ui8TXLen++] = psSavedKey->pui8LTK[ui8Loop]; + } + g_pui8TXBuf[g_ui8TXLen++] = psSavedKey->pui8DIV[0]; + g_pui8TXBuf[g_ui8TXLen++] = psSavedKey->pui8DIV[1]; + for(ui8Loop = 0; ui8Loop < 8; ui8Loop++) + { + g_pui8TXBuf[g_ui8TXLen++] = psSavedKey->pui8Rand[ui8Loop]; + } + g_pui8TXBuf[g_ui8TXLen++] = psSavedKey->ui8LTKSize; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// Read Characteristic Value. +// +//***************************************************************************** +void +GAPReadCharValue(uint16_t ui16ConnHandle, uint16_t ui16Handle) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_READ_CHAR_VAL_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = + (HCI_VE_GAP_DEVICE_READ_CHAR_VAL_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 4; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = ui16Handle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16Handle >> 8) & 0xFF; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; + +} + +//***************************************************************************** +// +// Write Characteristic Value request. +// +//***************************************************************************** +void +GAPWriteCharValue(uint16_t ui16ConnHandle, uint16_t ui16Handle, + uint8_t *pui8Buf, uint8_t ui8Len) +{ + uint8_t ui8Loop; + + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = + (HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 4 + ui8Len; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = ui16Handle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16Handle >> 8) & 0xFF; + for(ui8Loop = 0; ui8Loop < ui8Len; ui8Loop++) + { + g_pui8TXBuf[g_ui8TXLen++] = pui8Buf[ui8Loop]; + } + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} + +//***************************************************************************** +// +// Read RSSI Value Request. +// +//***************************************************************************** +void +HCIReadRSSI(uint16_t ui16ConnHandle) +{ + g_ui8TXLen = 0; + g_pui8TXBuf[g_ui8TXLen++] = HCI_CMD_PACKET; + g_pui8TXBuf[g_ui8TXLen++] = HCI_READ_RSSI_OPCODE & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (HCI_READ_RSSI_OPCODE >> 8) & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = 2; + g_pui8TXBuf[g_ui8TXLen++] = ui16ConnHandle & 0xFF; + g_pui8TXBuf[g_ui8TXLen++] = (ui16ConnHandle >>8) & 0xFF; + + DumpBuffer((uint8_t*)g_pui8TXBuf, g_ui8TXLen, true); + UARTSend((const uint8_t*)g_pui8TXBuf, g_ui8TXLen); + return; +} diff --git a/boards/dk-tm4c129x/ble_central/gcc/ble_central.axf b/boards/dk-tm4c129x/ble_central/gcc/ble_central.axf new file mode 100644 index 0000000..ea891ff Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/gcc/ble_central.axf differ diff --git a/boards/dk-tm4c129x/ble_central/gcc/ble_central.bin b/boards/dk-tm4c129x/ble_central/gcc/ble_central.bin new file mode 100644 index 0000000..a1b24e6 Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/gcc/ble_central.bin differ diff --git a/boards/dk-tm4c129x/ble_central/hci.h b/boards/dk-tm4c129x/ble_central/hci.h new file mode 100644 index 0000000..c5680cf --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/hci.h @@ -0,0 +1,329 @@ +//***************************************************************************** +// +// hci.h - This file contains the types, contants, external functions +// etc. for the BLE HCI Transport Layer. +// This file copied most of #defines from BLE-Stack 1.3.2 release +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#ifndef HCI_H +#define HCI_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +// +// Long Term Key info +// +typedef struct +{ + bool bValid; + bool bAuth; + uint8_t ui8LTKSize; + uint8_t pui8LTK[16]; + uint8_t pui8DIV[2]; + uint8_t pui8Rand[8]; +} tLTKData; + +#define HCI_BDADDR_LEN 6 + +// +// HCI Packet Types +// +#define HCI_CMD_PACKET 0x01 +#define HCI_ACL_DATA_PACKET 0x02 +#define HCI_SCO_DATA_PACKET 0x03 +#define HCI_EVENT_PACKET 0x04 + +// +// Vendor Specific Command Opcode +// +#define HCI_VE_GAP_DEVICE_INIT_OPCODE 0xFE00 +#define HCI_VE_GAP_DEVICE_DISC_REQ_OPCODE 0xFE04 +#define HCI_VE_GAP_DEVICE_EST_LINK_REQ_OPCODE 0xFE09 +#define HCI_VE_GAP_DEVICE_TER_LINK_REQ_OPCODE 0xFE0A +#define HCI_VE_GAP_DEVICE_AUTHENTICATE_OPCODE 0xFE0B +#define HCI_VE_GAP_DEVICE_PASSKEY_UPDATE_OPCODE 0xFE0C +#define HCI_VE_GAP_DEVICE_BOND_OPCODE 0xFE0F +#define HCI_VE_GAP_SET_PARAM_OPCODE 0xFE30 +#define HCI_VE_GAP_GET_PARAM_OPCODE 0xFE31 +#define HCI_VE_GAP_DEVICE_READ_CHAR_VAL_OPCODE 0xFD8A +#define HCI_VE_GAP_DEVICE_WRITE_CHAR_VAL_OPCODE 0xFD92 + +// +// BLE Command Opcode +// +#define HCI_READ_RSSI_OPCODE 0x1405 + +// +// Characteristic Value Handle +// +#define GATT_IRTEMP_DATA_UUID_HANDLE 0x25 +#define GATT_IRTEMP_NOTIFY_UUID_HANDLE 0x26 +#define GATT_IRTEMP_CFG_UUID_HANDLE 0x29 +#define GATT_HUMIDITY_DATA_UUID_HANDLE 0x38 +#define GATT_HUMIDITY_NOTIDY_UUID_HANDLE 0x39 +#define GATT_HUMIDITY_CFG_UUID_HANDLE 0x3C + +// +// GAP Profile Roles Bit mask values +// +#define GAP_PROFILE_BROADCASTER 0x01 //A device that sends advertising events only. +#define GAP_PROFILE_OBSERVER 0x02 //A device that receives advertising events only. +#define GAP_PROFILE_PERIPHERAL 0x04 //A device that accepts the establishment of an LE physical link using the connection establishment procedure +#define GAP_PROFILE_CENTRAL 0x08 //A device that supports the Central role initiates the establishment of a physical connection + + +// +// GAP_PARAMETER_ID_DEFINES GAP Parameter IDs +// +#define TGAP_GEN_DISC_ADV_MIN 0 //!< Minimum time to remain advertising, when in Discoverable mode (mSec). Setting this parameter to 0 turns off the timeout (default). +#define TGAP_LIM_ADV_TIMEOUT 1 //!< Maximum time to remain advertising, when in Limited Discoverable mode. In seconds (default 180 seconds) +#define TGAP_GEN_DISC_SCAN 2 //!< Minimum time to perform scanning, when performing General Discovery proc (mSec) +#define TGAP_LIM_DISC_SCAN 3 //!< Minimum time to perform scanning, when performing Limited Discovery proc (mSec) +#define TGAP_CONN_EST_ADV_TIMEOUT 4 //!< Advertising timeout, when performing Connection Establishment proc (mSec) +#define TGAP_CONN_PARAM_TIMEOUT 5 //!< Link Layer connection parameter update notification timer, connection parameter update proc (mSec) + +// Constants +#define TGAP_LIM_DISC_ADV_INT_MIN 6 //!< Minimum advertising interval, when in limited discoverable mode (n * 0.625 mSec) +#define TGAP_LIM_DISC_ADV_INT_MAX 7 //!< Maximum advertising interval, when in limited discoverable mode (n * 0.625 mSec) +#define TGAP_GEN_DISC_ADV_INT_MIN 8 //!< Minimum advertising interval, when in General discoverable mode (n * 0.625 mSec) +#define TGAP_GEN_DISC_ADV_INT_MAX 9 //!< Maximum advertising interval, when in General discoverable mode (n * 0.625 mSec) +#define TGAP_CONN_ADV_INT_MIN 10 //!< Minimum advertising interval, when in Connectable mode (n * 0.625 mSec) +#define TGAP_CONN_ADV_INT_MAX 11 //!< Maximum advertising interval, when in Connectable mode (n * 0.625 mSec) +#define TGAP_CONN_SCAN_INT 12 //!< Scan interval used during Link Layer Initiating state, when in Connectable mode (n * 0.625 mSec) +#define TGAP_CONN_SCAN_WIND 13 //!< Scan window used during Link Layer Initiating state, when in Connectable mode (n * 0.625 mSec) +#define TGAP_CONN_HIGH_SCAN_INT 14 //!< Scan interval used during Link Layer Initiating state, when in Connectable mode, high duty scan cycle scan paramaters (n * 0.625 mSec) +#define TGAP_CONN_HIGH_SCAN_WIND 15 //!< Scan window used during Link Layer Initiating state, when in Connectable mode, high duty scan cycle scan paramaters (n * 0.625 mSec) +#define TGAP_GEN_DISC_SCAN_INT 16 //!< Scan interval used during Link Layer Scanning state, when in General Discovery proc (n * 0.625 mSec) +#define TGAP_GEN_DISC_SCAN_WIND 17 //!< Scan window used during Link Layer Scanning state, when in General Discovery proc (n * 0.625 mSec) +#define TGAP_LIM_DISC_SCAN_INT 18 //!< Scan interval used during Link Layer Scanning state, when in Limited Discovery proc (n * 0.625 mSec) +#define TGAP_LIM_DISC_SCAN_WIND 19 //!< Scan window used during Link Layer Scanning state, when in Limited Discovery proc (n * 0.625 mSec) +#define TGAP_CONN_EST_ADV 20 //!< Advertising interval, when using Connection Establishment proc (n * 0.625 mSec). Obsolete - Do not use. +#define TGAP_CONN_EST_INT_MIN 21 //!< Minimum Link Layer connection interval, when using Connection Establishment proc (n * 1.25 mSec) +#define TGAP_CONN_EST_INT_MAX 22 //!< Maximum Link Layer connection interval, when using Connection Establishment proc (n * 1.25 mSec) +#define TGAP_CONN_EST_SCAN_INT 23 //!< Scan interval used during Link Layer Initiating state, when using Connection Establishment proc (n * 0.625 mSec) +#define TGAP_CONN_EST_SCAN_WIND 24 //!< Scan window used during Link Layer Initiating state, when using Connection Establishment proc (n * 0.625 mSec) +#define TGAP_CONN_EST_SUPERV_TIMEOUT 25 //!< Link Layer connection supervision timeout, when using Connection Establishment proc (n * 10 mSec) +#define TGAP_CONN_EST_LATENCY 26 //!< Link Layer connection slave latency, when using Connection Establishment proc (in number of connection events) +#define TGAP_CONN_EST_MIN_CE_LEN 27 //!< Local informational parameter about min len of connection needed, when using Connection Establishment proc (n * 0.625 mSec) +#define TGAP_CONN_EST_MAX_CE_LEN 28 //!< Local informational parameter about max len of connection needed, when using Connection Establishment proc (n * 0.625 mSec) +#define TGAP_PRIVATE_ADDR_INT 29 //!< Minimum Time Interval between private (resolvable) address changes. In minutes (default 15 minutes) +#define TGAP_CONN_PAUSE_CENTRAL 30 //!< Central idle timer. In seconds (default 1 second) +#define TGAP_CONN_PAUSE_PERIPHERAL 31 //!< Minimum time upon connection establishment before the peripheral starts a connection update procedure. In seconds (default 5 seconds) + +// Proprietary +#define TGAP_SM_TIMEOUT 32 //!< SM Message Timeout (milliseconds). Default 30 seconds. +#define TGAP_SM_MIN_KEY_LEN 33 //!< SM Minimum Key Length supported. Default 7. +#define TGAP_SM_MAX_KEY_LEN 34 //!< SM Maximum Key Length supported. Default 16. +#define TGAP_FILTER_ADV_REPORTS 35 //!< Filter duplicate advertising reports. Default TRUE. +#define TGAP_SCAN_RSP_RSSI_MIN 36 //!< Minimum RSSI required for scan responses to be reported to the app. Default -127. + +// +// GAP Device Discovery Modes +// +#define DEVDISC_MODE_NONDISCOVERABLE 0x00 //!< No discoverable setting +#define DEVDISC_MODE_GENERAL 0x01 //!< General Discoverable devices +#define DEVDISC_MODE_LIMITED 0x02 //!< Limited Discoverable devices +#define DEVDISC_MODE_ALL 0x03 //!< Not filtered + +// +// GAP Address Types +// +#define ADDRTYPE_PUBLIC 0x00 //!< Use the BD_ADDR +#define ADDRTYPE_STATIC 0x01 //!< Static address +#define ADDRTYPE_PRIVATE_NONRESOLVE 0x02 //!< Generate Non-Resolvable Private Address +#define ADDRTYPE_PRIVATE_RESOLVE 0x03 //!< Generate Resolvable Private Address + +// +// GAP Advertiser Event Types +// +#define GAP_ADTYPE_ADV_IND 0x00 //!< Connectable undirected advertisement +#define GAP_ADTYPE_ADV_DIRECT_IND 0x01 //!< Connectable directed advertisement +#define GAP_ADTYPE_ADV_DISCOVER_IND 0x02 //!< Discoverable undirected advertisement +#define GAP_ADTYPE_ADV_NONCONN_IND 0x03 //!< Non-Connectable undirected advertisement +#define GAP_ADTYPE_SCAN_RSP_IND 0x04 //!< Only used in gapDeviceInfoEvent_t + +// +// Vendor Specific Event Code +// +#define HCI_VE_EVENT_CODE 0xFF + +// Vendor Specific Event +#define GAP_HCI_EVENT_EXT_CMD_STATUS 0x067F +#define GAP_HCI_EVENT_EXT_DEVICE_INIT_DONE 0x0600 +#define GAP_HCI_EVENT_EXT_DEVICE_INFO 0x060D +#define GAP_HCI_EVENT_EXT_DEVICE_DISC_DONE 0x0601 +#define GAP_HCI_EVENT_EXT_DEVICE_LINK_DONE 0x0605 +#define GAP_HCI_EVENT_EXT_DEVICE_TERM_LINK_DONE 0x0606 +#define GAP_HCI_EVENT_EXT_DEVICE_PASSKEY_NEEDED 0x060B +#define GAP_HCI_EVENT_EXT_DEVICE_AUTHENTICATE_DONE 0x060A +#define GAP_HCI_EVENT_EXT_DEVICE_BOND_DONE 0x060E +#define GAP_HCI_EVENT_EXT_ATT_READ_RSP 0x050B +#define GAP_HCI_EVENT_EXT_ATT_WRITE_RSP 0x0513 +#define GAP_HCI_EVENT_CMD_COMPLETE 0x0E +#define HCI_ATT_ERROR_RSP_EVENT 0x0501 +#define GAP_HCI_EVENT_HANDLE_VALUE_NOTIFY 0x051B + +/* +** HCI Status +** +** Per the Bluetooth Core Specification, V4.0.0, Vol. 2, Part D. +*/ +#define HCI_SUCCESS 0x00 +#define HCI_ERROR_CODE_UNKNOWN_HCI_CMD 0x01 +#define HCI_ERROR_CODE_UNKNOWN_CONN_ID 0x02 +#define HCI_ERROR_CODE_HW_FAILURE 0x03 +#define HCI_ERROR_CODE_PAGE_TIMEOUT 0x04 +#define HCI_ERROR_CODE_AUTH_FAILURE 0x05 +#define HCI_ERROR_CODE_PIN_KEY_MISSING 0x06 +#define HCI_ERROR_CODE_MEM_CAP_EXCEEDED 0x07 +#define HCI_ERROR_CODE_CONN_TIMEOUT 0x08 +#define HCI_ERROR_CODE_CONN_LIMIT_EXCEEDED 0x09 +#define HCI_ERROR_CODE_SYNCH_CONN_LIMIT_EXCEEDED 0x0A +#define HCI_ERROR_CODE_ACL_CONN_ALREADY_EXISTS 0x0B +#define HCI_ERROR_CODE_CMD_DISALLOWED 0x0C +#define HCI_ERROR_CODE_CONN_REJ_LIMITED_RESOURCES 0x0D +#define HCI_ERROR_CODE_CONN_REJECTED_SECURITY_REASONS 0x0E +#define HCI_ERROR_CODE_CONN_REJECTED_UNACCEPTABLE_BDADDR 0x0F +#define HCI_ERROR_CODE_CONN_ACCEPT_TIMEOUT_EXCEEDED 0x10 +#define HCI_ERROR_CODE_UNSUPPORTED_FEATURE_PARAM_VALUE 0x11 +#define HCI_ERROR_CODE_INVALID_HCI_CMD_PARAMS 0x12 +#define HCI_ERROR_CODE_REMOTE_USER_TERM_CONN 0x13 +#define HCI_ERROR_CODE_REMOTE_DEVICE_TERM_CONN_LOW_RESOURCES 0x14 +#define HCI_ERROR_CODE_REMOTE_DEVICE_TERM_CONN_POWER_OFF 0x15 +#define HCI_ERROR_CODE_CONN_TERM_BY_LOCAL_HOST 0x16 +#define HCI_ERROR_CODE_REPEATED_ATTEMPTS 0x17 +#define HCI_ERROR_CODE_PAIRING_NOT_ALLOWED 0x18 +#define HCI_ERROR_CODE_UNKNOWN_LMP_PDU 0x19 +#define HCI_ERROR_CODE_UNSUPPORTED_REMOTE_FEATURE 0x1A +#define HCI_ERROR_CODE_SCO_OFFSET_REJ 0x1B +#define HCI_ERROR_CODE_SCO_INTERVAL_REJ 0x1C +#define HCI_ERROR_CODE_SCO_AIR_MODE_REJ 0x1D +#define HCI_ERROR_CODE_INVALID_LMP_PARAMS 0x1E +#define HCI_ERROR_CODE_UNSPECIFIED_ERROR 0x1F +#define HCI_ERROR_CODE_UNSUPPORTED_LMP_PARAM_VAL 0x20 +#define HCI_ERROR_CODE_ROLE_CHANGE_NOT_ALLOWED 0x21 +#define HCI_ERROR_CODE_LMP_LL_RESP_TIMEOUT 0x22 +#define HCI_ERROR_CODE_LMP_ERR_TRANSACTION_COLLISION 0x23 +#define HCI_ERROR_CODE_LMP_PDU_NOT_ALLOWED 0x24 +#define HCI_ERROR_CODE_ENCRYPT_MODE_NOT_ACCEPTABLE 0x25 +#define HCI_ERROR_CODE_LINK_KEY_CAN_NOT_BE_CHANGED 0x26 +#define HCI_ERROR_CODE_REQ_QOS_NOT_SUPPORTED 0x27 +#define HCI_ERROR_CODE_INSTANT_PASSED 0x28 +#define HCI_ERROR_CODE_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29 +#define HCI_ERROR_CODE_DIFFERENT_TRANSACTION_COLLISION 0x2A +#define HCI_ERROR_CODE_RESERVED1 0x2B +#define HCI_ERROR_CODE_QOS_UNACCEPTABLE_PARAM 0x2C +#define HCI_ERROR_CODE_QOS_REJ 0x2D +#define HCI_ERROR_CODE_CHAN_ASSESSMENT_NOT_SUPPORTED 0x2E +#define HCI_ERROR_CODE_INSUFFICIENT_SECURITY 0x2F +#define HCI_ERROR_CODE_PARAM_OUT_OF_MANDATORY_RANGE 0x30 +#define HCI_ERROR_CODE_RESERVED2 0x31 +#define HCI_ERROR_CODE_ROLE_SWITCH_PENDING 0x32 +#define HCI_ERROR_CODE_RESERVED3 0x33 +#define HCI_ERROR_CODE_RESERVED_SLOT_VIOLATION 0x34 +#define HCI_ERROR_CODE_ROLE_SWITCH_FAILED 0x35 +#define HCI_ERROR_CODE_EXTENDED_INQUIRY_RESP_TOO_LARGE 0x36 +#define HCI_ERROR_CODE_SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST 0x37 +#define HCI_ERROR_CODE_HOST_BUSY_PAIRING 0x38 +#define HCI_ERROR_CODE_CONN_REJ_NO_SUITABLE_CHAN_FOUND 0x39 +#define HCI_ERROR_CODE_CONTROLLER_BUSY 0x3A +#define HCI_ERROR_CODE_UNACCEPTABLE_CONN_INTERVAL 0x3B +#define HCI_ERROR_CODE_DIRECTED_ADV_TIMEOUT 0x3C +#define HCI_ERROR_CODE_CONN_TERM_MIC_FAILURE 0x3D +#define HCI_ERROR_CODE_CONN_FAILED_TO_ESTABLISH 0x3E +#define HCI_ERROR_CODE_MAC_CONN_FAILED 0x3F + +// +// Generic Status Return Values +// +#define SUCCESS 0x00 +#define FAILURE 0x01 +#define INVALIDPARAMETER 0x02 +#define INVALID_TASK 0x03 +#define MSG_BUFFER_NOT_AVAIL 0x04 +#define INVALID_MSG_POINTER 0x05 +#define INVALID_EVENT_ID 0x06 +#define INVALID_INTERRUPT_ID 0x07 +#define NO_TIMER_AVAIL 0x08 +#define NV_ITEM_UNINIT 0x09 +#define NV_OPER_FAILED 0x0A +#define INVALID_MEM_SIZE 0x0B +#define NV_BAD_ITEM_LEN 0x0C + +#define bleNotReady 0x10 //!< Not ready to perform task +#define bleAlreadyInRequestedMode 0x11 //!< Already performing that task +#define bleIncorrectMode 0x12 //!< Not setup properly to perform that task +#define bleMemAllocError 0x13 //!< Memory allocation error occurred +#define bleNotConnected 0x14 //!< Can't perform function when not in a connection +#define bleNoResources 0x15 //!< There are no resource available +#define blePending 0x16 //!< Waiting +#define bleTimeout 0x17 //!< Timed out performing function +#define bleInvalidRange 0x18 //!< A parameter is out of range +#define bleLinkEncrypted 0x19 //!< The link is already encrypted +#define bleProcedureComplete 0x1A //!< The Procedure is completed + +// GAP Status Return Values - returned as bStatus_t +#define bleGAPUserCanceled 0x30 //!< The user canceled the task +#define bleGAPConnNotAcceptable 0x31 //!< The connection was not accepted +#define bleGAPBondRejected 0x32 //!< The bound information was rejected. + +// ATT Status Return Values - returned as bStatus_t +#define bleInvalidPDU 0x40 //!< The attribute PDU is invalid +#define bleInsufficientAuthen 0x41 //!< The attribute has insufficient authentication +#define bleInsufficientEncrypt 0x42 //!< The attribute has insufficient encryption +#define bleInsufficientKeySize 0x43 //!< The attribute has insufficient encryption key size + +// Disconnect Reasons +#define HCI_DISCONNECT_AUTH_FAILURE HCI_ERROR_CODE_AUTH_FAILURE +#define HCI_DISCONNECT_REMOTE_USER_TERM HCI_ERROR_CODE_REMOTE_USER_TERM_CONN +#define HCI_DISCONNECT_REMOTE_DEV_LOW_RESOURCES HCI_ERROR_CODE_REMOTE_DEVICE_TERM_CONN_LOW_RESOURCES +#define HCI_DISCONNECT_REMOTE_DEV_POWER_OFF HCI_ERROR_CODE_REMOTE_DEVICE_TERM_CONN_POWER_OFF +#define HCI_DISCONNECT_UNSUPPORTED_REMOTE_FEATURE HCI_ERROR_CODE_UNSUPPORTED_REMOTE_FEATURE +#define HCI_DISCONNECT_KEY_PAIRING_NOT_SUPPORTED HCI_ERROR_CODE_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED +#define HCI_DISCONNECT_UNACCEPTABLE_CONN_INTERVAL HCI_ERROR_CODE_UNACCEPTABLE_CONN_INTERVAL + +extern void GAPDeviceInit(uint8_t ui8ProfileRole, + uint8_t ui8MaxScanRsps, + uint8_t *pui8IRK, + uint8_t *pui8SRK, + uint32_t ui32SignCounter); +extern void GAPGetParam(uint8_t ui8ParamID); +extern void GAPSetParam(uint8_t ui8ParamID, uint16_t ui16Value); +extern void GAPDiscoveryReq(uint8_t ui8Mode, bool bActiveScan, bool bWhiteList); +extern void GAPEstLinkReq(bool bHighDutyCycle, bool bWhiteList, + uint8_t ui8AddrType, uint8_t *pui8DevAddr); +extern void GAPTerLinkReq(uint16_t ui16ConnHandle, uint8_t ui8Reason); +extern void GAPAuthenticate(uint16_t ui16ConnHandle); +extern void GAPPassKeyUpdate(uint16_t ui16ConnHandle, char *pcPassCode); +extern void GAPBond(uint16_t ui16ConnHandle, tLTKData *psSavedKey); +extern void GAPReadCharValue(uint16_t ui16ConnHandle, uint16_t ui16Handle); +extern void GAPWriteCharValue(uint16_t ui16ConnHandle, uint16_t ui16Handle, + uint8_t *pui8Buf, uint8_t ui8Len); +extern void HCIReadRSSI(uint16_t ui16ConnHandle); +#ifdef __cplusplus +} +#endif + +#endif /* HCI_H */ diff --git a/boards/dk-tm4c129x/ble_central/readme.txt b/boards/dk-tm4c129x/ble_central/readme.txt new file mode 100644 index 0000000..b703699 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/readme.txt @@ -0,0 +1,94 @@ +BLE Central Device Demonstration + +This application provides a demonstration use of Bluetooth Low Energy +central device by utilizing TI’s BLE CC2540 Evaluation Module and +SesorTags. + +By connecting a CC2540 EM board to the EM header on the TM4C129X development +board, the TM4C129X can communicate with the CC2540 by means of +vendor-specific HCI commands using the UART interface. This application can +discover up to three SensorTag devices, it can connect to any one of them, +perform pairing and bonding, read some sensor data and RSSI data from the +slave, and display the information on the LCD display. + +This application can discover any BLE device although it may not be +able to make a connection to a device other than a SensorTag/CC2540 as the +bonding process will likely fail due to the use of a default passcode. +We have tested this application with SensorTag and CC2540 Development +boards (SmartRF05EB + CC2540 EM) with the SimpleBLEPeripheral +sample application programmed. It can successfully bond with both boards +since the same default passcode is expected. Both SensorTag and CC2540 +devices have BLE Stack 1.4.0 release code programmed. + +CC2540 device should be programmed with the HostTestRelease +(Network Processor) application. A hex file containing the this application +can be found in the BLE stack 1.4.0 release under +C:\\...\\BLE-CC254x-1.4.0\\Accessories\\HexFiles\\ +CC2540_SmartRF_HostTestRelease_All.hex. Please refer to the Bluetooth Low +Energy CC2540 Development Kit User's Guide for information on how to load +the hex file to the CC2540. This User's Guide can be found in +http://www.ti.com/lit/ug/swru301a/swru301a.pdf + +On the TM4C129X development board, make sure that jumpers PJ0 and PJ1 +are connected to the "EM_UART" side which allows UART3 TX and RX signals to +be routed to the EM header. UART3 is used as the communication channel +between the CC2540 device and the TM4C129X device. + +Once the application starts, it will verify the serial connection by +sending the CC2540 device a vendor-specific HCI command, and waiting for the +expected responses within a short time period. Once the physical connection +between TM4C129X and CC2540 is verified, the device will automatically +start to discover BLE peripheral device. If no devices are found within 20 +seconds, the application will timeout and display "No Device Found", +otherwise the discovered device names will be shown on the display. +Touching any of the device names will start the process of establishing a +connection with that device. This sample application always tries to make +a secure connection by pairing the device with default passcode "00000". +Upon successfully linking and pairing, application will start querying +sensor data, including IR temperature, ambient temperature, humidity and +RSSI. + +Whe run inside, IR and ambient temperature should typically be in the low +20s (Celsius). You can place the SensorTag near a hot object (such as a +cup of coffee) to verify that the IR temperature increases. You can move +the SensorTag further from the TM4C129X development board to verify that +its RSSI reading will decrease. + +At any time after the connection is established, you can touch the +"disconnect" button on the bottom of the screen to terminate the +connection with the peripheral device. + +In order to make the SensorTag discoverable by a central device, the +SensorTag needs to be in the discovery mode. The LED in the middle of the +board will blink periodically if the SensorTag is in discovery mode. If the +LED is not blinking, pressing the side button on the SensorTag should +place it in discovery mode. Once it is connected to a central device, +the LED should be off, pressing the side button while it is connected will +terminate the connection and put the SensorTag in discovery mode again. +For more information on SensorTag, please visit +http://processors.wiki.ti.com/index.php/Bluetooth_SensorTag + +Every HCI command and event are output to the UART console for +debugging purpose. The UART terminal should be configured in 115,200 baud, +8-n-1 mode. + + +------------------------------------------------------------------------------- + +Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +Software License Agreement + +Texas Instruments (TI) is supplying this software for use solely and +exclusively on TI's microcontroller products. The software is owned by +TI and/or its suppliers, and is protected under applicable copyright +laws. You may not combine this software with "viral" open-source +software in order to form a larger program. + +THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, FOR ANY REASON WHATSOEVER. + +This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. diff --git a/boards/dk-tm4c129x/ble_central/rvmdk/ble_central.axf b/boards/dk-tm4c129x/ble_central/rvmdk/ble_central.axf new file mode 100644 index 0000000..03e170b Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/rvmdk/ble_central.axf differ diff --git a/boards/dk-tm4c129x/ble_central/rvmdk/ble_central.bin b/boards/dk-tm4c129x/ble_central/rvmdk/ble_central.bin new file mode 100644 index 0000000..2a4a4ba Binary files /dev/null and b/boards/dk-tm4c129x/ble_central/rvmdk/ble_central.bin differ diff --git a/boards/dk-tm4c129x/ble_central/startup_ccs.c b/boards/dk-tm4c129x/ble_central/startup_ccs.c new file mode 100644 index 0000000..156d185 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/startup_ccs.c @@ -0,0 +1,277 @@ +//***************************************************************************** +// +// startup_ccs.c - Startup code for use with TI's Code Composer Studio. +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#include +#include "inc/hw_nvic.h" +#include "inc/hw_types.h" + +//***************************************************************************** +// +// Forward declaration of the default fault handlers. +// +//***************************************************************************** +void ResetISR(void); +static void NmiSR(void); +static void FaultISR(void); +static void IntDefaultHandler(void); + +//***************************************************************************** +// +// External declaration for the reset handler that is to be called when the +// processor is started +// +//***************************************************************************** +extern void _c_int00(void); + +//***************************************************************************** +// +// Linker variable that marks the top of the stack. +// +//***************************************************************************** +extern uint32_t __STACK_TOP; + +//***************************************************************************** +// +// External declarations for the interrupt handlers used by the application. +// +//***************************************************************************** +extern void TouchScreenIntHandler(void); +extern void SysTickIntHandler(void); +extern void UART3IntHandler(void); + +//***************************************************************************** +// +// The vector table. Note that the proper constructs must be placed on this to +// ensure that it ends up at physical address 0x0000.0000 or at the start of +// the program if located at a start address other than 0. +// +//***************************************************************************** +#pragma DATA_SECTION(g_pfnVectors, ".intvecs") +void (* const g_pfnVectors[])(void) = +{ + (void (*)(void))((uint32_t)&__STACK_TOP), + // The initial stack pointer + ResetISR, // The reset handler + NmiSR, // The NMI handler + FaultISR, // The hard fault handler + IntDefaultHandler, // The MPU fault handler + IntDefaultHandler, // The bus fault handler + IntDefaultHandler, // The usage fault handler + 0, // Reserved + 0, // Reserved + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // SVCall handler + IntDefaultHandler, // Debug monitor handler + 0, // Reserved + IntDefaultHandler, // The PendSV handler + SysTickIntHandler, // The SysTick handler + IntDefaultHandler, // GPIO Port A + IntDefaultHandler, // GPIO Port B + IntDefaultHandler, // GPIO Port C + IntDefaultHandler, // GPIO Port D + IntDefaultHandler, // GPIO Port E + IntDefaultHandler, // UART0 Rx and Tx + IntDefaultHandler, // UART1 Rx and Tx + IntDefaultHandler, // SSI0 Rx and Tx + IntDefaultHandler, // I2C0 Master and Slave + IntDefaultHandler, // PWM Fault + IntDefaultHandler, // PWM Generator 0 + IntDefaultHandler, // PWM Generator 1 + IntDefaultHandler, // PWM Generator 2 + IntDefaultHandler, // Quadrature Encoder 0 + IntDefaultHandler, // ADC Sequence 0 + IntDefaultHandler, // ADC Sequence 1 + IntDefaultHandler, // ADC Sequence 2 + TouchScreenIntHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + IntDefaultHandler, // Timer 0 subtimer A + IntDefaultHandler, // Timer 0 subtimer B + IntDefaultHandler, // Timer 1 subtimer A + IntDefaultHandler, // Timer 1 subtimer B + IntDefaultHandler, // Timer 2 subtimer A + IntDefaultHandler, // Timer 2 subtimer B + IntDefaultHandler, // Analog Comparator 0 + IntDefaultHandler, // Analog Comparator 1 + IntDefaultHandler, // Analog Comparator 2 + IntDefaultHandler, // System Control (PLL, OSC, BO) + IntDefaultHandler, // FLASH Control + IntDefaultHandler, // GPIO Port F + IntDefaultHandler, // GPIO Port G + IntDefaultHandler, // GPIO Port H + IntDefaultHandler, // UART2 Rx and Tx + IntDefaultHandler, // SSI1 Rx and Tx + IntDefaultHandler, // Timer 3 subtimer A + IntDefaultHandler, // Timer 3 subtimer B + IntDefaultHandler, // I2C1 Master and Slave + IntDefaultHandler, // CAN0 + IntDefaultHandler, // CAN1 + IntDefaultHandler, // Ethernet + IntDefaultHandler, // Hibernate + IntDefaultHandler, // USB0 + IntDefaultHandler, // PWM Generator 3 + IntDefaultHandler, // uDMA Software Transfer + IntDefaultHandler, // uDMA Error + IntDefaultHandler, // ADC1 Sequence 0 + IntDefaultHandler, // ADC1 Sequence 1 + IntDefaultHandler, // ADC1 Sequence 2 + IntDefaultHandler, // ADC1 Sequence 3 + IntDefaultHandler, // External Bus Interface 0 + IntDefaultHandler, // GPIO Port J + IntDefaultHandler, // GPIO Port K + IntDefaultHandler, // GPIO Port L + IntDefaultHandler, // SSI2 Rx and Tx + IntDefaultHandler, // SSI3 Rx and Tx + UART3IntHandler, // UART3 Rx and Tx + IntDefaultHandler, // UART4 Rx and Tx + IntDefaultHandler, // UART5 Rx and Tx + IntDefaultHandler, // UART6 Rx and Tx + IntDefaultHandler, // UART7 Rx and Tx + IntDefaultHandler, // I2C2 Master and Slave + IntDefaultHandler, // I2C3 Master and Slave + IntDefaultHandler, // Timer 4 subtimer A + IntDefaultHandler, // Timer 4 subtimer B + IntDefaultHandler, // Timer 5 subtimer A + IntDefaultHandler, // Timer 5 subtimer B + IntDefaultHandler, // FPU + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // I2C4 Master and Slave + IntDefaultHandler, // I2C5 Master and Slave + IntDefaultHandler, // GPIO Port M + IntDefaultHandler, // GPIO Port N + 0, // Reserved + IntDefaultHandler, // Tamper + IntDefaultHandler, // GPIO Port P (Summary or P0) + IntDefaultHandler, // GPIO Port P1 + IntDefaultHandler, // GPIO Port P2 + IntDefaultHandler, // GPIO Port P3 + IntDefaultHandler, // GPIO Port P4 + IntDefaultHandler, // GPIO Port P5 + IntDefaultHandler, // GPIO Port P6 + IntDefaultHandler, // GPIO Port P7 + IntDefaultHandler, // GPIO Port Q (Summary or Q0) + IntDefaultHandler, // GPIO Port Q1 + IntDefaultHandler, // GPIO Port Q2 + IntDefaultHandler, // GPIO Port Q3 + IntDefaultHandler, // GPIO Port Q4 + IntDefaultHandler, // GPIO Port Q5 + IntDefaultHandler, // GPIO Port Q6 + IntDefaultHandler, // GPIO Port Q7 + IntDefaultHandler, // GPIO Port R + IntDefaultHandler, // GPIO Port S + IntDefaultHandler, // SHA/MD5 0 + IntDefaultHandler, // AES 0 + IntDefaultHandler, // DES3DES 0 + IntDefaultHandler, // LCD Controller 0 + IntDefaultHandler, // Timer 6 subtimer A + IntDefaultHandler, // Timer 6 subtimer B + IntDefaultHandler, // Timer 7 subtimer A + IntDefaultHandler, // Timer 7 subtimer B + IntDefaultHandler, // I2C6 Master and Slave + IntDefaultHandler, // I2C7 Master and Slave + IntDefaultHandler, // HIM Scan Matrix Keyboard 0 + IntDefaultHandler, // One Wire 0 + IntDefaultHandler, // HIM PS/2 0 + IntDefaultHandler, // HIM LED Sequencer 0 + IntDefaultHandler, // HIM Consumer IR 0 + IntDefaultHandler, // I2C8 Master and Slave + IntDefaultHandler, // I2C9 Master and Slave + IntDefaultHandler // GPIO Port T +}; + +//***************************************************************************** +// +// This is the code that gets called when the processor first starts execution +// following a reset event. Only the absolutely necessary set is performed, +// after which the application supplied entry() routine is called. Any fancy +// actions (such as making decisions based on the reset cause register, and +// resetting the bits in that register) are left solely in the hands of the +// application. +// +//***************************************************************************** +void +ResetISR(void) +{ + // + // Jump to the CCS C initialization routine. This will enable the + // floating-point unit as well, so that does not need to be done here. + // + __asm(" .global _c_int00\n" + " b.w _c_int00"); +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a NMI. This +// simply enters an infinite loop, preserving the system state for examination +// by a debugger. +// +//***************************************************************************** +static void +NmiSR(void) +{ + // + // Enter an infinite loop. + // + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a fault +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void +FaultISR(void) +{ + // + // Enter an infinite loop. + // + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives an unexpected +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void +IntDefaultHandler(void) +{ + // + // Go into an infinite loop. + // + while(1) + { + } +} diff --git a/boards/dk-tm4c129x/ble_central/startup_ewarm.c b/boards/dk-tm4c129x/ble_central/startup_ewarm.c new file mode 100644 index 0000000..9852a56 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/startup_ewarm.c @@ -0,0 +1,308 @@ +//***************************************************************************** +// +// startup_ewarm.c - Startup code for use with IAR's Embedded Workbench, +// version 5. +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#include +#include "inc/hw_nvic.h" +#include "inc/hw_types.h" + +//***************************************************************************** +// +// Enable the IAR extensions for this source file. +// +//***************************************************************************** +#pragma language=extended + +//***************************************************************************** +// +// Forward declaration of the default fault handlers. +// +//***************************************************************************** +void ResetISR(void); +static void NmiSR(void); +static void FaultISR(void); +static void IntDefaultHandler(void); + +//***************************************************************************** +// +// External declarations for the interrupt handlers used by the application. +// +//***************************************************************************** +extern void TouchScreenIntHandler(void); +extern void SysTickIntHandler(void); +extern void UART3IntHandler(void); + +//***************************************************************************** +// +// The entry point for the application startup code. +// +//***************************************************************************** +extern void __iar_program_start(void); + +//***************************************************************************** +// +// Reserve space for the system stack. +// +//***************************************************************************** +static uint32_t pui32Stack[256] @ ".noinit"; + +//***************************************************************************** +// +// A union that describes the entries of the vector table. The union is needed +// since the first entry is the stack pointer and the remainder are function +// pointers. +// +//***************************************************************************** +typedef union +{ + void (*pfnHandler)(void); + uint32_t ui32Ptr; +} +uVectorEntry; + +//***************************************************************************** +// +// The vector table. Note that the proper constructs must be placed on this to +// ensure that it ends up at physical address 0x0000.0000. +// +//***************************************************************************** +__root const uVectorEntry __vector_table[] @ ".intvec" = +{ + { .ui32Ptr = (uint32_t)pui32Stack + sizeof(pui32Stack) }, + // The initial stack pointer + ResetISR, // The reset handler + NmiSR, // The NMI handler + FaultISR, // The hard fault handler + IntDefaultHandler, // The MPU fault handler + IntDefaultHandler, // The bus fault handler + IntDefaultHandler, // The usage fault handler + 0, // Reserved + 0, // Reserved + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // SVCall handler + IntDefaultHandler, // Debug monitor handler + 0, // Reserved + IntDefaultHandler, // The PendSV handler + SysTickIntHandler, // The SysTick handler + IntDefaultHandler, // GPIO Port A + IntDefaultHandler, // GPIO Port B + IntDefaultHandler, // GPIO Port C + IntDefaultHandler, // GPIO Port D + IntDefaultHandler, // GPIO Port E + IntDefaultHandler, // UART0 Rx and Tx + IntDefaultHandler, // UART1 Rx and Tx + IntDefaultHandler, // SSI0 Rx and Tx + IntDefaultHandler, // I2C0 Master and Slave + IntDefaultHandler, // PWM Fault + IntDefaultHandler, // PWM Generator 0 + IntDefaultHandler, // PWM Generator 1 + IntDefaultHandler, // PWM Generator 2 + IntDefaultHandler, // Quadrature Encoder 0 + IntDefaultHandler, // ADC Sequence 0 + IntDefaultHandler, // ADC Sequence 1 + IntDefaultHandler, // ADC Sequence 2 + TouchScreenIntHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + IntDefaultHandler, // Timer 0 subtimer A + IntDefaultHandler, // Timer 0 subtimer B + IntDefaultHandler, // Timer 1 subtimer A + IntDefaultHandler, // Timer 1 subtimer B + IntDefaultHandler, // Timer 2 subtimer A + IntDefaultHandler, // Timer 2 subtimer B + IntDefaultHandler, // Analog Comparator 0 + IntDefaultHandler, // Analog Comparator 1 + IntDefaultHandler, // Analog Comparator 2 + IntDefaultHandler, // System Control (PLL, OSC, BO) + IntDefaultHandler, // FLASH Control + IntDefaultHandler, // GPIO Port F + IntDefaultHandler, // GPIO Port G + IntDefaultHandler, // GPIO Port H + IntDefaultHandler, // UART2 Rx and Tx + IntDefaultHandler, // SSI1 Rx and Tx + IntDefaultHandler, // Timer 3 subtimer A + IntDefaultHandler, // Timer 3 subtimer B + IntDefaultHandler, // I2C1 Master and Slave + IntDefaultHandler, // CAN0 + IntDefaultHandler, // CAN1 + IntDefaultHandler, // Ethernet + IntDefaultHandler, // Hibernate + IntDefaultHandler, // USB0 + IntDefaultHandler, // PWM Generator 3 + IntDefaultHandler, // uDMA Software Transfer + IntDefaultHandler, // uDMA Error + IntDefaultHandler, // ADC1 Sequence 0 + IntDefaultHandler, // ADC1 Sequence 1 + IntDefaultHandler, // ADC1 Sequence 2 + IntDefaultHandler, // ADC1 Sequence 3 + IntDefaultHandler, // External Bus Interface 0 + IntDefaultHandler, // GPIO Port J + IntDefaultHandler, // GPIO Port K + IntDefaultHandler, // GPIO Port L + IntDefaultHandler, // SSI2 Rx and Tx + IntDefaultHandler, // SSI3 Rx and Tx + UART3IntHandler, // UART3 Rx and Tx + IntDefaultHandler, // UART4 Rx and Tx + IntDefaultHandler, // UART5 Rx and Tx + IntDefaultHandler, // UART6 Rx and Tx + IntDefaultHandler, // UART7 Rx and Tx + IntDefaultHandler, // I2C2 Master and Slave + IntDefaultHandler, // I2C3 Master and Slave + IntDefaultHandler, // Timer 4 subtimer A + IntDefaultHandler, // Timer 4 subtimer B + IntDefaultHandler, // Timer 5 subtimer A + IntDefaultHandler, // Timer 5 subtimer B + IntDefaultHandler, // FPU + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // I2C4 Master and Slave + IntDefaultHandler, // I2C5 Master and Slave + IntDefaultHandler, // GPIO Port M + IntDefaultHandler, // GPIO Port N + 0, // Reserved + IntDefaultHandler, // Tamper + IntDefaultHandler, // GPIO Port P (Summary or P0) + IntDefaultHandler, // GPIO Port P1 + IntDefaultHandler, // GPIO Port P2 + IntDefaultHandler, // GPIO Port P3 + IntDefaultHandler, // GPIO Port P4 + IntDefaultHandler, // GPIO Port P5 + IntDefaultHandler, // GPIO Port P6 + IntDefaultHandler, // GPIO Port P7 + IntDefaultHandler, // GPIO Port Q (Summary or Q0) + IntDefaultHandler, // GPIO Port Q1 + IntDefaultHandler, // GPIO Port Q2 + IntDefaultHandler, // GPIO Port Q3 + IntDefaultHandler, // GPIO Port Q4 + IntDefaultHandler, // GPIO Port Q5 + IntDefaultHandler, // GPIO Port Q6 + IntDefaultHandler, // GPIO Port Q7 + IntDefaultHandler, // GPIO Port R + IntDefaultHandler, // GPIO Port S + IntDefaultHandler, // SHA/MD5 0 + IntDefaultHandler, // AES 0 + IntDefaultHandler, // DES3DES 0 + IntDefaultHandler, // LCD Controller 0 + IntDefaultHandler, // Timer 6 subtimer A + IntDefaultHandler, // Timer 6 subtimer B + IntDefaultHandler, // Timer 7 subtimer A + IntDefaultHandler, // Timer 7 subtimer B + IntDefaultHandler, // I2C6 Master and Slave + IntDefaultHandler, // I2C7 Master and Slave + IntDefaultHandler, // HIM Scan Matrix Keyboard 0 + IntDefaultHandler, // One Wire 0 + IntDefaultHandler, // HIM PS/2 0 + IntDefaultHandler, // HIM LED Sequencer 0 + IntDefaultHandler, // HIM Consumer IR 0 + IntDefaultHandler, // I2C8 Master and Slave + IntDefaultHandler, // I2C9 Master and Slave + IntDefaultHandler // GPIO Port T +}; + +//***************************************************************************** +// +// This is the code that gets called when the processor first starts execution +// following a reset event. Only the absolutely necessary set is performed, +// after which the application supplied entry() routine is called. Any fancy +// actions (such as making decisions based on the reset cause register, and +// resetting the bits in that register) are left solely in the hands of the +// application. +// +//***************************************************************************** +void +ResetISR(void) +{ + // + // Enable the floating-point unit. This must be done here to handle the + // case where main() uses floating-point and the function prologue saves + // floating-point registers (which will fault if floating-point is not + // enabled). Any configuration of the floating-point unit using DriverLib + // APIs must be done here prior to the floating-point unit being enabled. + // + // Note that this does not use DriverLib since it might not be included in + // this project. + // + HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) & + ~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) | + NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL); + + // + // Call the application's entry point. + // + __iar_program_start(); +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a NMI. This +// simply enters an infinite loop, preserving the system state for examination +// by a debugger. +// +//***************************************************************************** +static void +NmiSR(void) +{ + // + // Enter an infinite loop. + // + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a fault +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void +FaultISR(void) +{ + // + // Enter an infinite loop. + // + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives an unexpected +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void +IntDefaultHandler(void) +{ + // + // Go into an infinite loop. + // + while(1) + { + } +} diff --git a/boards/dk-tm4c129x/ble_central/startup_gcc.c b/boards/dk-tm4c129x/ble_central/startup_gcc.c new file mode 100644 index 0000000..851b511 --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/startup_gcc.c @@ -0,0 +1,324 @@ +//***************************************************************************** +// +// startup_gcc.c - Startup code for use with GNU tools. +// +// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +// +//***************************************************************************** + +#include +#include "inc/hw_nvic.h" +#include "inc/hw_types.h" + +//***************************************************************************** +// +// Forward declaration of the default fault handlers. +// +//***************************************************************************** +void ResetISR(void); +static void NmiSR(void); +static void FaultISR(void); +static void IntDefaultHandler(void); + +//***************************************************************************** +// +// External declarations for the interrupt handlers used by the application. +// +//***************************************************************************** +extern void TouchScreenIntHandler(void); +extern void SysTickIntHandler(void); +extern void UART3IntHandler(void); + +//***************************************************************************** +// +// The entry point for the application. +// +//***************************************************************************** +extern int main(void); + +//***************************************************************************** +// +// Reserve space for the system stack. +// +//***************************************************************************** +static uint32_t pui32Stack[256]; + +//***************************************************************************** +// +// The vector table. Note that the proper constructs must be placed on this to +// ensure that it ends up at physical address 0x0000.0000. +// +//***************************************************************************** +__attribute__ ((section(".isr_vector"))) +void (* const g_pfnVectors[])(void) = +{ + (void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)), + // The initial stack pointer + ResetISR, // The reset handler + NmiSR, // The NMI handler + FaultISR, // The hard fault handler + IntDefaultHandler, // The MPU fault handler + IntDefaultHandler, // The bus fault handler + IntDefaultHandler, // The usage fault handler + 0, // Reserved + 0, // Reserved + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // SVCall handler + IntDefaultHandler, // Debug monitor handler + 0, // Reserved + IntDefaultHandler, // The PendSV handler + SysTickIntHandler, // The SysTick handler + IntDefaultHandler, // GPIO Port A + IntDefaultHandler, // GPIO Port B + IntDefaultHandler, // GPIO Port C + IntDefaultHandler, // GPIO Port D + IntDefaultHandler, // GPIO Port E + IntDefaultHandler, // UART0 Rx and Tx + IntDefaultHandler, // UART1 Rx and Tx + IntDefaultHandler, // SSI0 Rx and Tx + IntDefaultHandler, // I2C0 Master and Slave + IntDefaultHandler, // PWM Fault + IntDefaultHandler, // PWM Generator 0 + IntDefaultHandler, // PWM Generator 1 + IntDefaultHandler, // PWM Generator 2 + IntDefaultHandler, // Quadrature Encoder 0 + IntDefaultHandler, // ADC Sequence 0 + IntDefaultHandler, // ADC Sequence 1 + IntDefaultHandler, // ADC Sequence 2 + TouchScreenIntHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + IntDefaultHandler, // Timer 0 subtimer A + IntDefaultHandler, // Timer 0 subtimer B + IntDefaultHandler, // Timer 1 subtimer A + IntDefaultHandler, // Timer 1 subtimer B + IntDefaultHandler, // Timer 2 subtimer A + IntDefaultHandler, // Timer 2 subtimer B + IntDefaultHandler, // Analog Comparator 0 + IntDefaultHandler, // Analog Comparator 1 + IntDefaultHandler, // Analog Comparator 2 + IntDefaultHandler, // System Control (PLL, OSC, BO) + IntDefaultHandler, // FLASH Control + IntDefaultHandler, // GPIO Port F + IntDefaultHandler, // GPIO Port G + IntDefaultHandler, // GPIO Port H + IntDefaultHandler, // UART2 Rx and Tx + IntDefaultHandler, // SSI1 Rx and Tx + IntDefaultHandler, // Timer 3 subtimer A + IntDefaultHandler, // Timer 3 subtimer B + IntDefaultHandler, // I2C1 Master and Slave + IntDefaultHandler, // CAN0 + IntDefaultHandler, // CAN1 + IntDefaultHandler, // Ethernet + IntDefaultHandler, // Hibernate + IntDefaultHandler, // USB0 + IntDefaultHandler, // PWM Generator 3 + IntDefaultHandler, // uDMA Software Transfer + IntDefaultHandler, // uDMA Error + IntDefaultHandler, // ADC1 Sequence 0 + IntDefaultHandler, // ADC1 Sequence 1 + IntDefaultHandler, // ADC1 Sequence 2 + IntDefaultHandler, // ADC1 Sequence 3 + IntDefaultHandler, // External Bus Interface 0 + IntDefaultHandler, // GPIO Port J + IntDefaultHandler, // GPIO Port K + IntDefaultHandler, // GPIO Port L + IntDefaultHandler, // SSI2 Rx and Tx + IntDefaultHandler, // SSI3 Rx and Tx + UART3IntHandler, // UART3 Rx and Tx + IntDefaultHandler, // UART4 Rx and Tx + IntDefaultHandler, // UART5 Rx and Tx + IntDefaultHandler, // UART6 Rx and Tx + IntDefaultHandler, // UART7 Rx and Tx + IntDefaultHandler, // I2C2 Master and Slave + IntDefaultHandler, // I2C3 Master and Slave + IntDefaultHandler, // Timer 4 subtimer A + IntDefaultHandler, // Timer 4 subtimer B + IntDefaultHandler, // Timer 5 subtimer A + IntDefaultHandler, // Timer 5 subtimer B + IntDefaultHandler, // FPU + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // I2C4 Master and Slave + IntDefaultHandler, // I2C5 Master and Slave + IntDefaultHandler, // GPIO Port M + IntDefaultHandler, // GPIO Port N + 0, // Reserved + IntDefaultHandler, // Tamper + IntDefaultHandler, // GPIO Port P (Summary or P0) + IntDefaultHandler, // GPIO Port P1 + IntDefaultHandler, // GPIO Port P2 + IntDefaultHandler, // GPIO Port P3 + IntDefaultHandler, // GPIO Port P4 + IntDefaultHandler, // GPIO Port P5 + IntDefaultHandler, // GPIO Port P6 + IntDefaultHandler, // GPIO Port P7 + IntDefaultHandler, // GPIO Port Q (Summary or Q0) + IntDefaultHandler, // GPIO Port Q1 + IntDefaultHandler, // GPIO Port Q2 + IntDefaultHandler, // GPIO Port Q3 + IntDefaultHandler, // GPIO Port Q4 + IntDefaultHandler, // GPIO Port Q5 + IntDefaultHandler, // GPIO Port Q6 + IntDefaultHandler, // GPIO Port Q7 + IntDefaultHandler, // GPIO Port R + IntDefaultHandler, // GPIO Port S + IntDefaultHandler, // SHA/MD5 0 + IntDefaultHandler, // AES 0 + IntDefaultHandler, // DES3DES 0 + IntDefaultHandler, // LCD Controller 0 + IntDefaultHandler, // Timer 6 subtimer A + IntDefaultHandler, // Timer 6 subtimer B + IntDefaultHandler, // Timer 7 subtimer A + IntDefaultHandler, // Timer 7 subtimer B + IntDefaultHandler, // I2C6 Master and Slave + IntDefaultHandler, // I2C7 Master and Slave + IntDefaultHandler, // HIM Scan Matrix Keyboard 0 + IntDefaultHandler, // One Wire 0 + IntDefaultHandler, // HIM PS/2 0 + IntDefaultHandler, // HIM LED Sequencer 0 + IntDefaultHandler, // HIM Consumer IR 0 + IntDefaultHandler, // I2C8 Master and Slave + IntDefaultHandler, // I2C9 Master and Slave + IntDefaultHandler // GPIO Port T +}; + +//***************************************************************************** +// +// The following are constructs created by the linker, indicating where the +// the "data" and "bss" segments reside in memory. The initializers for the +// for the "data" segment resides immediately following the "text" segment. +// +//***************************************************************************** +extern uint32_t _etext; +extern uint32_t _data; +extern uint32_t _edata; +extern uint32_t _bss; +extern uint32_t _ebss; + +//***************************************************************************** +// +// This is the code that gets called when the processor first starts execution +// following a reset event. Only the absolutely necessary set is performed, +// after which the application supplied entry() routine is called. Any fancy +// actions (such as making decisions based on the reset cause register, and +// resetting the bits in that register) are left solely in the hands of the +// application. +// +//***************************************************************************** +void +ResetISR(void) +{ + uint32_t *pui32Src, *pui32Dest; + + // + // Copy the data segment initializers from flash to SRAM. + // + pui32Src = &_etext; + for(pui32Dest = &_data; pui32Dest < &_edata; ) + { + *pui32Dest++ = *pui32Src++; + } + + // + // Zero fill the bss segment. + // + __asm(" ldr r0, =_bss\n" + " ldr r1, =_ebss\n" + " mov r2, #0\n" + " .thumb_func\n" + "zero_loop:\n" + " cmp r0, r1\n" + " it lt\n" + " strlt r2, [r0], #4\n" + " blt zero_loop"); + + // + // Enable the floating-point unit. This must be done here to handle the + // case where main() uses floating-point and the function prologue saves + // floating-point registers (which will fault if floating-point is not + // enabled). Any configuration of the floating-point unit using DriverLib + // APIs must be done here prior to the floating-point unit being enabled. + // + // Note that this does not use DriverLib since it might not be included in + // this project. + // + HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) & + ~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) | + NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL); + + // + // Call the application's entry point. + // + main(); +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a NMI. This +// simply enters an infinite loop, preserving the system state for examination +// by a debugger. +// +//***************************************************************************** +static void +NmiSR(void) +{ + // + // Enter an infinite loop. + // + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a fault +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void +FaultISR(void) +{ + // + // Enter an infinite loop. + // + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives an unexpected +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void +IntDefaultHandler(void) +{ + // + // Go into an infinite loop. + // + while(1) + { + } +} diff --git a/boards/dk-tm4c129x/ble_central/startup_rvmdk.S b/boards/dk-tm4c129x/ble_central/startup_rvmdk.S new file mode 100644 index 0000000..af8433a --- /dev/null +++ b/boards/dk-tm4c129x/ble_central/startup_rvmdk.S @@ -0,0 +1,333 @@ +; <<< Use Configuration Wizard in Context Menu >>> +;****************************************************************************** +; +; startup_rvmdk.S - Startup code for use with Keil's uVision. +; +; Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved. +; Software License Agreement +; +; Texas Instruments (TI) is supplying this software for use solely and +; exclusively on TI's microcontroller products. The software is owned by +; TI and/or its suppliers, and is protected under applicable copyright +; laws. You may not combine this software with "viral" open-source +; software in order to form a larger program. +; +; THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +; NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +; NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +; CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +; DAMAGES, FOR ANY REASON WHATSOEVER. +; +; This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package. +; +;****************************************************************************** + +;****************************************************************************** +; +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; +;****************************************************************************** +Stack EQU 0x00000400 + +;****************************************************************************** +; +; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> +; +;****************************************************************************** +Heap EQU 0x00000000 + +;****************************************************************************** +; +; Allocate space for the stack. +; +;****************************************************************************** + AREA STACK, NOINIT, READWRITE, ALIGN=3 +StackMem + SPACE Stack +__initial_sp + +;****************************************************************************** +; +; Allocate space for the heap. +; +;****************************************************************************** + AREA HEAP, NOINIT, READWRITE, ALIGN=3 +__heap_base +HeapMem + SPACE Heap +__heap_limit + +;****************************************************************************** +; +; Indicate that the code in this file preserves 8-byte alignment of the stack. +; +;****************************************************************************** + PRESERVE8 + +;****************************************************************************** +; +; Place code into the reset code section. +; +;****************************************************************************** + AREA RESET, CODE, READONLY + THUMB + +;****************************************************************************** +; +; External declarations for the interrupt handlers used by the application. +; +;****************************************************************************** + EXTERN TouchScreenIntHandler + EXTERN SysTickIntHandler + EXTERN UART3IntHandler + +;****************************************************************************** +; +; The vector table. +; +;****************************************************************************** + EXPORT __Vectors +__Vectors + DCD StackMem + Stack ; Top of Stack + DCD Reset_Handler ; Reset Handler + DCD NmiSR ; NMI Handler + DCD FaultISR ; Hard Fault Handler + DCD IntDefaultHandler ; The MPU fault handler + DCD IntDefaultHandler ; The bus fault handler + DCD IntDefaultHandler ; The usage fault handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD IntDefaultHandler ; SVCall handler + DCD IntDefaultHandler ; Debug monitor handler + DCD 0 ; Reserved + DCD IntDefaultHandler ; The PendSV handler + DCD SysTickIntHandler ; The SysTick handler + DCD IntDefaultHandler ; GPIO Port A + DCD IntDefaultHandler ; GPIO Port B + DCD IntDefaultHandler ; GPIO Port C + DCD IntDefaultHandler ; GPIO Port D + DCD IntDefaultHandler ; GPIO Port E + DCD IntDefaultHandler ; UART0 Rx and Tx + DCD IntDefaultHandler ; UART1 Rx and Tx + DCD IntDefaultHandler ; SSI0 Rx and Tx + DCD IntDefaultHandler ; I2C0 Master and Slave + DCD IntDefaultHandler ; PWM Fault + DCD IntDefaultHandler ; PWM Generator 0 + DCD IntDefaultHandler ; PWM Generator 1 + DCD IntDefaultHandler ; PWM Generator 2 + DCD IntDefaultHandler ; Quadrature Encoder 0 + DCD IntDefaultHandler ; ADC Sequence 0 + DCD IntDefaultHandler ; ADC Sequence 1 + DCD IntDefaultHandler ; ADC Sequence 2 + DCD TouchScreenIntHandler ; ADC Sequence 3 + DCD IntDefaultHandler ; Watchdog timer + DCD IntDefaultHandler ; Timer 0 subtimer A + DCD IntDefaultHandler ; Timer 0 subtimer B + DCD IntDefaultHandler ; Timer 1 subtimer A + DCD IntDefaultHandler ; Timer 1 subtimer B + DCD IntDefaultHandler ; Timer 2 subtimer A + DCD IntDefaultHandler ; Timer 2 subtimer B + DCD IntDefaultHandler ; Analog Comparator 0 + DCD IntDefaultHandler ; Analog Comparator 1 + DCD IntDefaultHandler ; Analog Comparator 2 + DCD IntDefaultHandler ; System Control (PLL, OSC, BO) + DCD IntDefaultHandler ; FLASH Control + DCD IntDefaultHandler ; GPIO Port F + DCD IntDefaultHandler ; GPIO Port G + DCD IntDefaultHandler ; GPIO Port H + DCD IntDefaultHandler ; UART2 Rx and Tx + DCD IntDefaultHandler ; SSI1 Rx and Tx + DCD IntDefaultHandler ; Timer 3 subtimer A + DCD IntDefaultHandler ; Timer 3 subtimer B + DCD IntDefaultHandler ; I2C1 Master and Slave + DCD IntDefaultHandler ; CAN0 + DCD IntDefaultHandler ; CAN1 + DCD IntDefaultHandler ; Ethernet + DCD IntDefaultHandler ; Hibernate + DCD IntDefaultHandler ; USB0 + DCD IntDefaultHandler ; PWM Generator 3 + DCD IntDefaultHandler ; uDMA Software Transfer + DCD IntDefaultHandler ; uDMA Error + DCD IntDefaultHandler ; ADC1 Sequence 0 + DCD IntDefaultHandler ; ADC1 Sequence 1 + DCD IntDefaultHandler ; ADC1 Sequence 2 + DCD IntDefaultHandler ; ADC1 Sequence 3 + DCD IntDefaultHandler ; External Bus Interface 0 + DCD IntDefaultHandler ; GPIO Port J + DCD IntDefaultHandler ; GPIO Port K + DCD IntDefaultHandler ; GPIO Port L + DCD IntDefaultHandler ; SSI2 Rx and Tx + DCD IntDefaultHandler ; SSI3 Rx and Tx + DCD UART3IntHandler ; UART3 Rx and Tx + DCD IntDefaultHandler ; UART4 Rx and Tx + DCD IntDefaultHandler ; UART5 Rx and Tx + DCD IntDefaultHandler ; UART6 Rx and Tx + DCD IntDefaultHandler ; UART7 Rx and Tx + DCD IntDefaultHandler ; I2C2 Master and Slave + DCD IntDefaultHandler ; I2C3 Master and Slave + DCD IntDefaultHandler ; Timer 4 subtimer A + DCD IntDefaultHandler ; Timer 4 subtimer B + DCD IntDefaultHandler ; Timer 5 subtimer A + DCD IntDefaultHandler ; Timer 5 subtimer B + DCD IntDefaultHandler ; FPU + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD IntDefaultHandler ; I2C4 Master and Slave + DCD IntDefaultHandler ; I2C5 Master and Slave + DCD IntDefaultHandler ; GPIO Port M + DCD IntDefaultHandler ; GPIO Port N + DCD 0 ; Reserved + DCD IntDefaultHandler ; Tamper + DCD IntDefaultHandler ; GPIO Port P (Summary or P0) + DCD IntDefaultHandler ; GPIO Port P1 + DCD IntDefaultHandler ; GPIO Port P2 + DCD IntDefaultHandler ; GPIO Port P3 + DCD IntDefaultHandler ; GPIO Port P4 + DCD IntDefaultHandler ; GPIO Port P5 + DCD IntDefaultHandler ; GPIO Port P6 + DCD IntDefaultHandler ; GPIO Port P7 + DCD IntDefaultHandler ; GPIO Port Q (Summary or Q0) + DCD IntDefaultHandler ; GPIO Port Q1 + DCD IntDefaultHandler ; GPIO Port Q2 + DCD IntDefaultHandler ; GPIO Port Q3 + DCD IntDefaultHandler ; GPIO Port Q4 + DCD IntDefaultHandler ; GPIO Port Q5 + DCD IntDefaultHandler ; GPIO Port Q6 + DCD IntDefaultHandler ; GPIO Port Q7 + DCD IntDefaultHandler ; GPIO Port R + DCD IntDefaultHandler ; GPIO Port S + DCD IntDefaultHandler ; SHA/MD5 0 + DCD IntDefaultHandler ; AES 0 + DCD IntDefaultHandler ; DES3DES 0 + DCD IntDefaultHandler ; LCD Controller 0 + DCD IntDefaultHandler ; Timer 6 subtimer A + DCD IntDefaultHandler ; Timer 6 subtimer B + DCD IntDefaultHandler ; Timer 7 subtimer A + DCD IntDefaultHandler ; Timer 7 subtimer B + DCD IntDefaultHandler ; I2C6 Master and Slave + DCD IntDefaultHandler ; I2C7 Master and Slave + DCD IntDefaultHandler ; HIM Scan Matrix Keyboard 0 + DCD IntDefaultHandler ; One Wire 0 + DCD IntDefaultHandler ; HIM PS/2 0 + DCD IntDefaultHandler ; HIM LED Sequencer 0 + DCD IntDefaultHandler ; HIM Consumer IR 0 + DCD IntDefaultHandler ; I2C8 Master and Slave + DCD IntDefaultHandler ; I2C9 Master and Slave + DCD IntDefaultHandler ; GPIO Port T + +;****************************************************************************** +; +; This is the code that gets called when the processor first starts execution +; following a reset event. +; +;****************************************************************************** + EXPORT Reset_Handler +Reset_Handler + ; + ; Enable the floating-point unit. This must be done here to handle the + ; case where main() uses floating-point and the function prologue saves + ; floating-point registers (which will fault if floating-point is not + ; enabled). Any configuration of the floating-point unit using + ; DriverLib APIs must be done here prior to the floating-point unit + ; being enabled. + ; + ; Note that this does not use DriverLib since it might not be included + ; in this project. + ; + MOVW R0, #0xED88 + MOVT R0, #0xE000 + LDR R1, [R0] + ORR R1, #0x00F00000 + STR R1, [R0] + + ; + ; Call the C library enty point that handles startup. This will copy + ; the .data section initializers from flash to SRAM and zero fill the + ; .bss section. + ; + IMPORT __main + B __main + +;****************************************************************************** +; +; This is the code that gets called when the processor receives a NMI. This +; simply enters an infinite loop, preserving the system state for examination +; by a debugger. +; +;****************************************************************************** +NmiSR + B NmiSR + +;****************************************************************************** +; +; This is the code that gets called when the processor receives a fault +; interrupt. This simply enters an infinite loop, preserving the system state +; for examination by a debugger. +; +;****************************************************************************** +FaultISR + B FaultISR + +;****************************************************************************** +; +; This is the code that gets called when the processor receives an unexpected +; interrupt. This simply enters an infinite loop, preserving the system state +; for examination by a debugger. +; +;****************************************************************************** +IntDefaultHandler + B IntDefaultHandler + +;****************************************************************************** +; +; Make sure the end of this section is aligned. +; +;****************************************************************************** + ALIGN + +;****************************************************************************** +; +; Some code in the normal code section for initializing the heap and stack. +; +;****************************************************************************** + AREA |.text|, CODE, READONLY + +;****************************************************************************** +; +; The function expected of the C library startup code for defining the stack +; and heap memory locations. For the C library version of the startup code, +; provide this function so that the C library initialization code can find out +; the location of the stack and heap. +; +;****************************************************************************** + IF :DEF: __MICROLIB + EXPORT __initial_sp + EXPORT __heap_base + EXPORT __heap_limit + ELSE + IMPORT __use_two_region_memory + EXPORT __user_initial_stackheap +__user_initial_stackheap + LDR R0, =HeapMem + LDR R1, =(StackMem + Stack) + LDR R2, =(HeapMem + Heap) + LDR R3, =StackMem + BX LR + ENDIF + +;****************************************************************************** +; +; Make sure the end of this section is aligned. +; +;****************************************************************************** + ALIGN + +;****************************************************************************** +; +; Tell the assembler that we're done. +; +;****************************************************************************** + END -- cgit v1.3.1