From ac4fd8e8340886f455add8cf92ee1c8458b8ae19 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sun, 16 Mar 2014 14:31:22 +0200 Subject: Add ek-tm4c1294xl example projects --- boards/ek-tm4c1294xl/qs_iot/Makefile | 112 ++ boards/ek-tm4c1294xl/qs_iot/ccs/.ccsimportspec | 18 + boards/ek-tm4c1294xl/qs_iot/ccs/.ccsproject | 10 + boards/ek-tm4c1294xl/qs_iot/ccs/.cproject | 209 ++++ boards/ek-tm4c1294xl/qs_iot/ccs/.project | 140 +++ .../ccs/.settings/org.eclipse.cdt.codan.core.prefs | 3 + boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.bin | Bin 0 -> 48752 bytes boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.out | Bin 0 -> 832286 bytes boards/ek-tm4c1294xl/qs_iot/ccs/macros.ini_initial | 1 + .../ek-tm4c1294xl/qs_iot/ccs/target_config.ccxml | 13 + boards/ek-tm4c1294xl/qs_iot/commands.c | 464 ++++++++ boards/ek-tm4c1294xl/qs_iot/commands.h | 68 ++ boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.bin | Bin 0 -> 44988 bytes boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.out | Bin 0 -> 693176 bytes boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.axf | Bin 0 -> 130093 bytes boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.bin | Bin 0 -> 49976 bytes boards/ek-tm4c1294xl/qs_iot/lwipopts.h | 446 ++++++++ boards/ek-tm4c1294xl/qs_iot/qs_iot.c | 1151 ++++++++++++++++++++ boards/ek-tm4c1294xl/qs_iot/qs_iot.ewd | 614 +++++++++++ boards/ek-tm4c1294xl/qs_iot/qs_iot.ewp | 857 +++++++++++++++ boards/ek-tm4c1294xl/qs_iot/qs_iot.h | 105 ++ boards/ek-tm4c1294xl/qs_iot/qs_iot.icf | 78 ++ boards/ek-tm4c1294xl/qs_iot/qs_iot.ld | 57 + boards/ek-tm4c1294xl/qs_iot/qs_iot.sct | 47 + boards/ek-tm4c1294xl/qs_iot/qs_iot.uvopt | 541 +++++++++ boards/ek-tm4c1294xl/qs_iot/qs_iot.uvproj | 514 +++++++++ boards/ek-tm4c1294xl/qs_iot/qs_iot_ccs.cmd | 70 ++ boards/ek-tm4c1294xl/qs_iot/readme.txt | 58 + boards/ek-tm4c1294xl/qs_iot/requests.c | 349 ++++++ boards/ek-tm4c1294xl/qs_iot/requests.h | 84 ++ boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.axf | Bin 0 -> 445960 bytes boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.bin | Bin 0 -> 45916 bytes boards/ek-tm4c1294xl/qs_iot/startup_ccs.c | 278 +++++ boards/ek-tm4c1294xl/qs_iot/startup_ewarm.c | 309 ++++++ boards/ek-tm4c1294xl/qs_iot/startup_gcc.c | 325 ++++++ boards/ek-tm4c1294xl/qs_iot/startup_rvmdk.S | 334 ++++++ boards/ek-tm4c1294xl/qs_iot/stats.c | 174 +++ boards/ek-tm4c1294xl/qs_iot/stats.h | 117 ++ boards/ek-tm4c1294xl/qs_iot/tictactoe.c | 718 ++++++++++++ boards/ek-tm4c1294xl/qs_iot/tictactoe.h | 64 ++ 40 files changed, 8328 insertions(+) create mode 100644 boards/ek-tm4c1294xl/qs_iot/Makefile create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/.ccsimportspec create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/.ccsproject create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/.cproject create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/.project create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/.settings/org.eclipse.cdt.codan.core.prefs create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.bin create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.out create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/macros.ini_initial create mode 100644 boards/ek-tm4c1294xl/qs_iot/ccs/target_config.ccxml create mode 100644 boards/ek-tm4c1294xl/qs_iot/commands.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/commands.h create mode 100644 boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.bin create mode 100644 boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.out create mode 100644 boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.axf create mode 100644 boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.bin create mode 100644 boards/ek-tm4c1294xl/qs_iot/lwipopts.h create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.ewd create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.ewp create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.h create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.icf create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.ld create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.sct create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.uvopt create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot.uvproj create mode 100644 boards/ek-tm4c1294xl/qs_iot/qs_iot_ccs.cmd create mode 100644 boards/ek-tm4c1294xl/qs_iot/readme.txt create mode 100644 boards/ek-tm4c1294xl/qs_iot/requests.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/requests.h create mode 100644 boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.axf create mode 100644 boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.bin create mode 100644 boards/ek-tm4c1294xl/qs_iot/startup_ccs.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/startup_ewarm.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/startup_gcc.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/startup_rvmdk.S create mode 100644 boards/ek-tm4c1294xl/qs_iot/stats.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/stats.h create mode 100644 boards/ek-tm4c1294xl/qs_iot/tictactoe.c create mode 100644 boards/ek-tm4c1294xl/qs_iot/tictactoe.h (limited to 'boards/ek-tm4c1294xl/qs_iot') diff --git a/boards/ek-tm4c1294xl/qs_iot/Makefile b/boards/ek-tm4c1294xl/qs_iot/Makefile new file mode 100644 index 0000000..2a1b155 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/Makefile @@ -0,0 +1,112 @@ +#****************************************************************************** +# +# Makefile - Rules for building the Quickstart application to talk to a cloud server.. +# +# 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 EK-TM4C1294XL Firmware Package. +# +#****************************************************************************** + +# +# Defines the part type that this project uses. +# +PART=TM4C1294NCPDT + +# +# 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+=../../../../third_party/exosite +VPATH+=../../../../utils + +# +# Where to find header files that do not live in the source directory. +# +IPATH=. +IPATH+=.. +IPATH+=../../../.. +IPATH+=../../../../third_party/lwip-1.4.1/apps +IPATH+=../../../../third_party/exosite +IPATH+=../../../../third_party/lwip-1.4.1/ports/tiva-tm4c129/include +IPATH+=../../../../third_party/lwip-1.4.1/src/include +IPATH+=../../../../third_party/lwip-1.4.1/src/include/ipv4 +IPATH+=../../../../third_party + +# +# The default rule, which causes the Quickstart application to talk to a cloud server. to be built. +# +all: ${COMPILER} +all: ${COMPILER}/qs_iot.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 Quickstart application to talk to a cloud server.. +# +${COMPILER}/qs_iot.axf: ${COMPILER}/buttons.o +${COMPILER}/qs_iot.axf: ${COMPILER}/cmdline.o +${COMPILER}/qs_iot.axf: ${COMPILER}/commands.o +${COMPILER}/qs_iot.axf: ${COMPILER}/eth_client_lwip.o +${COMPILER}/qs_iot.axf: ${COMPILER}/exosite.o +${COMPILER}/qs_iot.axf: ${COMPILER}/exosite_hal_lwip.o +${COMPILER}/qs_iot.axf: ${COMPILER}/exosite_meta.o +${COMPILER}/qs_iot.axf: ${COMPILER}/flash_pb.o +${COMPILER}/qs_iot.axf: ${COMPILER}/http.o +${COMPILER}/qs_iot.axf: ${COMPILER}/locator.o +${COMPILER}/qs_iot.axf: ${COMPILER}/lwiplib.o +${COMPILER}/qs_iot.axf: ${COMPILER}/pinout.o +${COMPILER}/qs_iot.axf: ${COMPILER}/qs_iot.o +${COMPILER}/qs_iot.axf: ${COMPILER}/requests.o +${COMPILER}/qs_iot.axf: ${COMPILER}/ringbuf.o +${COMPILER}/qs_iot.axf: ${COMPILER}/startup_${COMPILER}.o +${COMPILER}/qs_iot.axf: ${COMPILER}/stats.o +${COMPILER}/qs_iot.axf: ${COMPILER}/tictactoe.o +${COMPILER}/qs_iot.axf: ${COMPILER}/uartstdio.o +${COMPILER}/qs_iot.axf: ${COMPILER}/ustdlib.o +${COMPILER}/qs_iot.axf: ${ROOT}/driverlib/${COMPILER}/libdriver.a +${COMPILER}/qs_iot.axf: qs_iot.ld +SCATTERgcc_qs_iot=qs_iot.ld +ENTRY_qs_iot=ResetISR +CFLAGSgcc=-DTARGET_IS_TM4C129_RA0 -DLWIP_1_4_1 -DUSE_HTTP_1_0 -DUART_BUFFERED + +# +# Include the automatically generated dependency files. +# +ifneq (${MAKECMDGOALS},clean) +-include ${wildcard ${COMPILER}/*.d} __dummy__ +endif diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/.ccsimportspec b/boards/ek-tm4c1294xl/qs_iot/ccs/.ccsimportspec new file mode 100644 index 0000000..b26ca50 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/.ccsimportspec @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/.ccsproject b/boards/ek-tm4c1294xl/qs_iot/ccs/.ccsproject new file mode 100644 index 0000000..ac3158a --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/.ccsproject @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/.cproject b/boards/ek-tm4c1294xl/qs_iot/ccs/.cproject new file mode 100644 index 0000000..96645e7 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/.cproject @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/.project b/boards/ek-tm4c1294xl/qs_iot/ccs/.project new file mode 100644 index 0000000..c596ce0 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/.project @@ -0,0 +1,140 @@ + + + qs_iot + + + + + + 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 + + + + commands.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/commands.c + + + qs_iot.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/qs_iot.c + + + qs_iot_ccs.cmd + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/qs_iot_ccs.cmd + + + requests.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/requests.c + + + startup_ccs.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/startup_ccs.c + + + stats.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/stats.c + + + tictactoe.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/qs_iot/tictactoe.c + + + drivers/buttons.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/drivers/buttons.c + + + drivers/eth_client_lwip.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/drivers/eth_client_lwip.c + + + drivers/exosite_hal_lwip.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/drivers/exosite_hal_lwip.c + + + drivers/http.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/drivers/http.c + + + drivers/pinout.c + 1 + SW_ROOT/examples/boards/ek-tm4c1294xl/drivers/pinout.c + + + utils/cmdline.c + 1 + SW_ROOT/utils/cmdline.c + + + utils/flash_pb.c + 1 + SW_ROOT/utils/flash_pb.c + + + utils/locator.c + 1 + SW_ROOT/utils/locator.c + + + utils/lwiplib.c + 1 + SW_ROOT/utils/lwiplib.c + + + utils/ringbuf.c + 1 + SW_ROOT/utils/ringbuf.c + + + utils/uartstdio.c + 1 + SW_ROOT/utils/uartstdio.c + + + utils/ustdlib.c + 1 + SW_ROOT/utils/ustdlib.c + + + third_party/exosite/exosite.c + 1 + SW_ROOT/third_party/exosite/exosite.c + + + third_party/exosite/exosite_meta.c + 1 + SW_ROOT/third_party/exosite/exosite_meta.c + + + + + SW_ROOT + $%7BPARENT-5-PROJECT_LOC%7D + + + diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/.settings/org.eclipse.cdt.codan.core.prefs b/boards/ek-tm4c1294xl/qs_iot/ccs/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..98b6350 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +inEditor=false +onBuild=false diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.bin b/boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.bin new file mode 100644 index 0000000..d9dce9f Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.bin differ diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.out b/boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.out new file mode 100644 index 0000000..0dedc8f Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/ccs/Debug/qs_iot.out differ diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/macros.ini_initial b/boards/ek-tm4c1294xl/qs_iot/ccs/macros.ini_initial new file mode 100644 index 0000000..31214b5 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/macros.ini_initial @@ -0,0 +1 @@ +SW_ROOT = ../../../../.. diff --git a/boards/ek-tm4c1294xl/qs_iot/ccs/target_config.ccxml b/boards/ek-tm4c1294xl/qs_iot/ccs/target_config.ccxml new file mode 100644 index 0000000..7a583d5 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/ccs/target_config.ccxml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/boards/ek-tm4c1294xl/qs_iot/commands.c b/boards/ek-tm4c1294xl/qs_iot/commands.c new file mode 100644 index 0000000..f478475 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/commands.c @@ -0,0 +1,464 @@ +//***************************************************************************** +// +// commands.c - Command line functions for the qs-cloud demo +// +// Copyright (c) YEAR 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#include +#include +#include "driverlib/sysctl.h" +#include "utils/cmdline.h" +#include "utils/uartstdio.h" +#include "utils/ustdlib.h" +#include "drivers/exosite_hal_lwip.h" +#include "drivers/eth_client_lwip.h" +#include "exosite.h" +#include "stats.h" +#include "qs_iot.h" +#include "commands.h" +#include "tictactoe.h" + +//***************************************************************************** +// +// This is the table that holds the command names, implementing functions, and +// brief description. +// +//***************************************************************************** +tCmdLineEntry g_psCmdTable[] = +{ + { "help", Cmd_help, ": Display list of commands" }, + { "h", Cmd_help, ": alias for help" }, + { "?", Cmd_help, ": alias for help" }, + { "stats", Cmd_stats, ": Display collected stats for this" + " board" }, + { "activate", Cmd_activate, ": Get a CIK from exosite"}, + { "clear", Cmd_clear, ": Clear the display "}, + { "led", Cmd_led, ": Toggle LEDs. Type \"led help\" for " + "more info."}, + { "connect", Cmd_connect, ": Tries to establish a connection with " + "exosite."}, + { "getmac", Cmd_getmac, ": Prints the current MAC address."}, + { "setproxy", Cmd_setproxy, ": Setup or change proxy configuration."}, + { "setemail", Cmd_setemail, ": Change the email address used for " + "alerts."}, + { "alert", Cmd_alert, ": Send an alert to the saved email " + "address."}, + { "tictactoe", Cmd_tictactoe, ": Play tic-tac-toe!"}, + { 0, 0, 0 } +}; + +//***************************************************************************** +// +// Array of possible alert messages. +// +//***************************************************************************** +char *g_ppcAlertMessages[] = +{ + "Hello World!!", + "Testing Exosite scripting features.", + "Log into Exosite for a quick game of tic-tac-toe!" +}; + +#define NUM_ALERTS sizeof(g_ppcAlertMessages)/sizeof(char *) + +//***************************************************************************** +// +// This function implements the "help" command. It prints a simple list of the +// available commands with a brief description. +// +//***************************************************************************** +int +Cmd_help(int argc, char *argv[]) +{ + tCmdLineEntry *pEntry; + + // + // Print some header text. + // + UARTprintf("\nAvailable commands\n"); + UARTprintf("------------------\n"); + + // + // Point at the beginning of the command table. + // + pEntry = &g_psCmdTable[0]; + + // + // Enter a loop to read each entry from the command table. The end of the + // table has been reached when the command name is NULL. + // + while(pEntry->pcCmd) + { + // + // Print the command name and the brief description. + // + UARTprintf("%15s%s\n", pEntry->pcCmd, pEntry->pcHelp); + + // + // Advance to the next entry in the table. + // + pEntry++; + } + + // + // Return success. + // + return(0); +} + +//***************************************************************************** +// +// This function prints a list of local statistics for this board. +// +//***************************************************************************** +int +Cmd_stats(int argc, char *argv[]) +{ + // + // Set the global flag to enable printing of statistics to the UART + // console. The actual printing should be taken care of in a different + // context. + // + g_bPrintingData = true; + + return 0; +} + + +//***************************************************************************** +// +// Connects to Exosite and attempts to obtain a CIK. If no connection is made +// Cmd_activate will return and report the failure. +// +//***************************************************************************** +int +Cmd_activate(int argc, char *argv[]) +{ + // + // Attempt to acquire a new CIK from Exosite. If successful, update the + // global state variables to notify the main application. + // + if(ProvisionCIK()) + { + // + // Set the state to "online" with zero missed sync operations. + // + g_bOnline = true; + g_ui32LinkRetries = 0; + } + + return 0; +} + +//***************************************************************************** +// +// The "led" command can be used to manually set the state of the two on-board +// LEDs. The new LED state will also be transmitted back to the exosite server, +// so the cloud representation of the LEDs should stay in sync with the board's +// actual behavior. +// +//***************************************************************************** +int +Cmd_led(int argc, char *argv[]) +{ + uint32_t *pui32LEDValue; + + // + // If we have too few arguments, or the second argument starts with 'h' + // (like the first character of help), print out information about the + // usage of this command. + // + if(argc < 3 || ((argc == 2) && (argv[1][0] == 'h'))) + { + UARTprintf("LED command usage:\n\n"); + UARTprintf("Specify an LED name (d1 or d2) and a state (on or off),\n"); + UARTprintf("separated by a space.\n\n"); + UARTprintf("For example:\n"); + UARTprintf(" led d1 on\n"); + UARTprintf(" led d2 off\n"); + return 0; + } + + else if(argv[1][1] == '1') + { + // + // If the second letter of the second argument is a 3, assume the user + // is trying to interact with led d3. + // + pui32LEDValue = &g_ui32LEDD1; + g_sLEDD1.eReadWriteType = READ_WRITE; + } + else if(argv[1][1] == '2') + { + // + // If the second letter of the second argument is a 4, assume the user + // is trying to interact with led d4. + // + pui32LEDValue = &g_ui32LEDD2; + g_sLEDD2.eReadWriteType = READ_WRITE; + } + else + { + UARTprintf("Invalid LED name.\n"); + return 0; + } + + // + // If the second letter of the third argument is the "n" of "on", turn the + // LED on. Otherwise, turn it off. + // + *pui32LEDValue = (argv[2][1] == 'n') ? 1 : 0; + + return 0; +} + +//***************************************************************************** +// +// The "connect" command alerts the main application that it should attempt to +// re-establish a link with the exosite server. +// +//***************************************************************************** +int +Cmd_connect(int argc, char *argv[]) +{ + // + // Set the flags to restart the connection to exosite. The main application + // loop should handle the actual connection. + // + if(g_bOnline) + { + UARTprintf("Already connected. "); + UARTprintf("Type 'stats' to see data for this board.\n"); + } + else + { + UARTprintf("Connecting to Exosite...\r"); + + // + // If a CIK was found, try to sync with Exosite. This should tell us if + // the CIK is valid or not. + // + if(SyncWithExosite(g_psDeviceStatistics)) + { + // + // If the sync worked, the CIK is valid. Alert the caller. + // + UARTprintf("Connected! Type 'stats' to see data for this board."); + g_bOnline = true; + g_ui32LinkRetries = 0; + return 0; + } + else + { + UARTprintf("Sync failed. \n"); + } + } + + return 0; +} + +//***************************************************************************** +// +// The "clear" command sends an ascii control code to the UART that should +// clear the screen for most PC-side terminals. +// +//***************************************************************************** +int +Cmd_clear(int argc, char *argv[]) +{ + UARTprintf("\033[2J\033[H"); + return 0; +} + +//***************************************************************************** +// +// The "getmac" command prints the user's current MAC address to the UART. +// +//***************************************************************************** +int +Cmd_getmac(int argc, char *argv[]) +{ + PrintMac(); + return 0; +} + +//***************************************************************************** +// +// The "setproxy" command allows the user to change their proxy behavior +// +//***************************************************************************** +int +Cmd_setproxy(int argc, char *argv[]) +{ + char pcProxyPort[10]; + + // + // Check the number of arguments. + // + if((argc == 2) && (ustrcmp("off",argv[1]) == 0 )) + { + g_bUseProxy = false; + g_pcProxyAddress[0] = 0; + g_ui16ProxyPort = 0; + + UARTprintf("Attempting to re-establish link with Exosite.\n\n"); + g_bOnline = LocateValidCIK(); + } + else if(argc == 3) + { + // + // Otherwise, copy the user-defined location into the global variable. + // + ustrncpy(g_pcProxyAddress, argv[1], 49); + ustrncpy(pcProxyPort, argv[2], 9); + + // + // Make sure that the global string remains terminated with a zero. + // + g_pcProxyAddress[49] = 0; + pcProxyPort[9] = 0; + g_ui16ProxyPort = ustrtoul(pcProxyPort, NULL, 0); + g_bUseProxy = true; + + UARTprintf("New Proxy Address: %s\n", g_pcProxyAddress); + UARTprintf("New Proxy Port: %d\n\n", g_ui16ProxyPort); + + UARTprintf("Attempting to re-establish link with Exosite.\n\n"); + g_bOnline = LocateValidCIK(); + + } + else + { + UARTprintf("\nProxy configuration help:\n"); + UARTprintf(" The setproxy command changes the proxy behavior of" + "this board.\n"); + UARTprintf(" To disable the proxy, type:\n\n"); + UARTprintf(" setproxy off\n\n"); + UARTprintf(" To enable the proxy with a specific proxy name and " + "port, type\n"); + UARTprintf(" setproxy . For " + "example:\n\n"); + UARTprintf(" setproxy your.proxy.address 80\n\n"); + } + + return 0; +} + +//***************************************************************************** +// +// The tictactoe command allows users to play a game of tic-tac-toe. +// +//***************************************************************************** +int +Cmd_tictactoe(int argc, char *argv[]) +{ + g_bGameActive = 1; + + GameInit(); + + return 0; +} + +//***************************************************************************** +// +// The setemail command allows the user to set a contact email address to be +// used for alert messages. +// +//***************************************************************************** +int +Cmd_setemail(int argc, char *argv[]) +{ + // + // Check the number of arguments. + // + if(argc < 2) + { + // + // If there was no second term, prompt the user to enter one next time. + // + UARTprintf("Not enough arguments. Please enter an email address.\n"); + UARTprintf("For example \"setemail yourname@example.com\""); + } + else + { + // + // Otherwise, copy the user-defined location into the global variable. + // + ustrncpy(g_pcContactEmail, argv[1], 100); + + // + // Make sure that the global string remains terminated with a zero. + // + g_pcContactEmail[99] = 0; + + // + // Mark the location as READ_WRITE, so it will get uploaded to the + // server on the next sync. + // + g_sContactEmail.eReadWriteType = READ_WRITE; + + UARTprintf("Email set to: %s\n\n", g_pcContactEmail); + } + + return 0; +} + +//***************************************************************************** +// +// The alert command allows the user to send an alert message to the saved +// email address. +// +//***************************************************************************** +int +Cmd_alert(int argc, char *argv[]) +{ + uint32_t ui32Index; + + // + // Check the number of arguments. + // + if(argc < 2) + { + // + // If there was no second term, prompt the user to enter one next time. + // + UARTprintf("Please specify the alert you want to send:\n"); + for(ui32Index = 0; ui32Index < NUM_ALERTS; ui32Index++) + { + // + // Print a list of the available alert messages. + // + UARTprintf("alert %d: %s\n", ui32Index, + g_ppcAlertMessages[ui32Index]); + } + } + else + { + ui32Index = ustrtoul(argv[1], NULL, 0); + ustrncpy(g_pcAlert, g_ppcAlertMessages[ui32Index], 140); + g_sAlert.eReadWriteType = READ_WRITE; + + UARTprintf("Alert message set. Sending to the server " + "on the next sync operation."); + } + + return 0; +} diff --git a/boards/ek-tm4c1294xl/qs_iot/commands.h b/boards/ek-tm4c1294xl/qs_iot/commands.h new file mode 100644 index 0000000..0a59077 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/commands.h @@ -0,0 +1,68 @@ +//***************************************************************************** +// +// commands.h - Header file for commandline functions in qs-cloud +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#ifndef __COMMANDS_H__ +#define __COMMANDS_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Forward declarations for command-line operations. +// +//***************************************************************************** +extern int Cmd_help(int argc, char *argv[]); +extern int Cmd_stats(int argc, char *argv[]); +extern int Cmd_activate(int argc, char *argv[]); +extern int Cmd_read(int argc, char *argv[]); +extern int Cmd_clear(int argc, char *argv[]); +extern int Cmd_sync(int argc, char *argv[]); +extern int Cmd_led(int argc, char *argv[]); +extern int Cmd_connect(int argc, char *argv[]); +extern int Cmd_getmac(int argc, char *argv[]); +extern int Cmd_setlocation(int argc, char *argv[]); +extern int Cmd_setproxy(int argc, char *argv[]); +extern int Cmd_setemail(int argc, char *argv[]); +extern int Cmd_alert(int argc, char *argv[]); +extern int Cmd_tictactoe(int argc, char *argv[]); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __COMMANDS_H__ diff --git a/boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.bin b/boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.bin new file mode 100644 index 0000000..517f68b Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.bin differ diff --git a/boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.out b/boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.out new file mode 100644 index 0000000..39b43cb Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/ewarm/Exe/qs_iot.out differ diff --git a/boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.axf b/boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.axf new file mode 100644 index 0000000..d9de7ef Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.axf differ diff --git a/boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.bin b/boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.bin new file mode 100644 index 0000000..da389fd Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/gcc/qs_iot.bin differ diff --git a/boards/ek-tm4c1294xl/qs_iot/lwipopts.h b/boards/ek-tm4c1294xl/qs_iot/lwipopts.h new file mode 100644 index 0000000..3e329f8 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/lwipopts.h @@ -0,0 +1,446 @@ +//***************************************************************************** +// +// lwipopts.h - Configuration file for lwIP +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** +// +// NOTE: This file has been derived from the lwIP/src/include/lwip/opt.h +// header file. +// +// For additional details, refer to the original "opt.h" file, and lwIP +// documentation. +// +//***************************************************************************** +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#include + +//***************************************************************************** +// +// ---------- Stellaris / lwIP Port Options ---------- +// +//***************************************************************************** +#define HOST_TMR_INTERVAL 100 // default is 0 +//#define DHCP_EXPIRE_TIMER_MSECS (60 * 1000) +//#define LWIP_HTTPD_SSI 1 +//#define LWIP_HTTPD_CGI 1 +#define LWIP_HTTPD_DYNAMIC_HEADERS 1 +//#define EMAC_PHY_CONFIG EMAC_PHY_TYPE_EXTERNAL_RMII +//#define PHY_PHYS_ADDR 1 +#define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN | \ + EMAC_PHY_AN_100B_T_FULL_DUPLEX) +#define PHY_PHYS_ADDR 0 +#define NUM_TX_DESCRIPTORS 8 +#define NUM_RX_DESCRIPTORS 8 + +//***************************************************************************** +// +// ---------- Platform specific locking ---------- +// +//***************************************************************************** +#define SYS_LIGHTWEIGHT_PROT 1 // default is 0 +#define NO_SYS 1 // default is 0 +//#define MEMCPY(dst,src,len) memcpy(dst,src,len) +//#define SMEMCPY(dst,src,len) memcpy(dst,src,len) + +//***************************************************************************** +// +// ---------- Memory options ---------- +// +//***************************************************************************** +//#define MEM_LIBC_MALLOC 0 +#define MEM_ALIGNMENT 4 +#define MEM_SIZE (32 * 1024) +//#define MEMP_OVERFLOW_CHECK 0 +//#define MEMP_SANITY_CHECK 0 +//#define MEM_USE_POOLS 0 +//#define MEMP_USE_CUSTOM_POOLS 0 + +//***************************************************************************** +// +// ---------- Internal Memory Pool Sizes ---------- +// +//***************************************************************************** +#define MEMP_NUM_PBUF 16 // Default 16, was 16 +//#define MEMP_NUM_RAW_PCB 4 +//#define MEMP_NUM_UDP_PCB 4 +#define MEMP_NUM_TCP_PCB 16 +//#define MEMP_NUM_TCP_PCB_LISTEN 8 +//#define MEMP_NUM_TCP_SEG 16 +//#define MEMP_NUM_REASSDATA 5 +//#define MEMP_NUM_ARP_QUEUE 30 +//#define MEMP_NUM_IGMP_GROUP 8 +#define MEMP_NUM_SYS_TIMEOUT 6 //5 +//#define MEMP_NUM_NETBUF 2 +//#define MEMP_NUM_NETCONN 4 +//#define MEMP_NUM_TCPIP_MSG_API 8 +//#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#define PBUF_POOL_SIZE 16 // Default 16 + +//***************************************************************************** +// +// ---------- ARP options ---------- +// +//***************************************************************************** +//#define LWIP_ARP 1 +//#define ARP_TABLE_SIZE 10 +//#define ARP_QUEUEING 1 +//#define ETHARP_TRUST_IP_MAC 1 + +//***************************************************************************** +// +// ---------- IP options ---------- +// +//***************************************************************************** +//#define IP_FORWARD 0 +//#define IP_OPTIONS_ALLOWED 1 +#define IP_REASSEMBLY 0 // default is 1 +#define IP_FRAG 0 // default is 1 +//#define IP_REASS_MAXAGE 3 +//#define IP_REASS_MAX_PBUFS 10 +//#define IP_FRAG_USES_STATIC_BUF 1 +//#define IP_FRAG_MAX_MTU 1500 +//#define IP_DEFAULT_TTL 255 + +//***************************************************************************** +// +// ---------- ICMP options ---------- +// +//***************************************************************************** +//#define LWIP_ICMP 1 +//#define ICMP_TTL (IP_DEFAULT_TTL) + +//***************************************************************************** +// +// ---------- RAW options ---------- +// +//***************************************************************************** +//#define LWIP_RAW 1 +//#define RAW_TTL (IP_DEFAULT_TTL) + +//***************************************************************************** +// +// ---------- DHCP options ---------- +// +//***************************************************************************** +#define LWIP_DHCP 1 // default is 0 +//#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) + +//***************************************************************************** +// +// ---------- UPNP options ---------- +// +//***************************************************************************** +//#define LWIP_UPNP 0 + +//***************************************************************************** +// +// ---------- PTPD options ---------- +// +//***************************************************************************** +//#define LWIP_PTPD 0 + +//***************************************************************************** +// +// ---------- AUTOIP options ---------- +// +//***************************************************************************** +#define LWIP_AUTOIP 1 // default is 0 +#define LWIP_DHCP_AUTOIP_COOP ((LWIP_DHCP) && (LWIP_AUTOIP)) + // default is 0 +#define LWIP_DHCP_AUTOIP_COOP_TRIES 5 // default is 9 + +//***************************************************************************** +// +// ---------- SNMP options ---------- +// +//***************************************************************************** +//#define LWIP_SNMP 0 +//#define SNMP_CONCURRENT_REQUESTS 1 +//#define SNMP_TRAP_DESTINATIONS 1 +//#define SNMP_PRIVATE_MIB 0 +//#define SNMP_SAFE_REQUESTS 1 + +//***************************************************************************** +// +// ---------- IGMP options ---------- +// +//***************************************************************************** +//#define LWIP_IGMP 0 + +//***************************************************************************** +// +// ---------- DNS options ----------- +// +//***************************************************************************** +#define LWIP_DNS 1 +#define DNS_TABLE_SIZE 4 +#define DNS_MAX_NAME_LENGTH 256 +#define DNS_MAX_SERVERS 2 +#define DNS_DOES_NAME_CHECK 1 +#define DNS_USES_STATIC_BUF 1 +#define DNS_MSG_SIZE 512 + +//***************************************************************************** +// +// ---------- UDP options ---------- +// +//***************************************************************************** +//#define LWIP_UDP 1 +//#define LWIP_UDPLITE 0 +//#define UDP_TTL (IP_DEFAULT_TTL) + +//***************************************************************************** +// +// ---------- TCP options ---------- +// +//***************************************************************************** +#define LWIP_TCP 1 +//#define TCP_TTL (IP_DEFAULT_TTL) +#define TCP_WND 4096 // default is 2048 +//#define TCP_MAXRTX 12 +//#define TCP_SYNMAXRTX 6 +//#define TCP_QUEUE_OOSEQ 1 +#define TCP_MSS 1500 // default is 128 +//#define TCP_CALCULATE_EFF_SEND_MSS 1 +#define TCP_SND_BUF (4 * TCP_MSS) + // default is 256, was 6 * +//#define TCP_SND_QUEUELEN (4 * (TCP_SND_BUF/TCP_MSS)) +//#define TCP_SNDLOWAT (TCP_SND_BUF/2) +//#define TCP_LISTEN_BACKLOG 0 +//#define TCP_DEFAULT_LISTEN_BACKLOG 0xff + +//***************************************************************************** +// +// ---------- API options ---------- +// +//***************************************************************************** +//#define LWIP_EVENT_API 0 +//#define LWIP_CALLBACK_API 1 + +//***************************************************************************** +// +// ---------- Pbuf options ---------- +// +//***************************************************************************** +#define PBUF_LINK_HLEN 16 // default is 14 +#define PBUF_POOL_BUFSIZE 512 + // default is LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN) +#define ETH_PAD_SIZE 0 // default is 0 + +//***************************************************************************** +// +// ---------- Network Interfaces options ---------- +// +//***************************************************************************** +//#define LWIP_NETIF_HOSTNAME 0 +//#define LWIP_NETIF_API 0 +//#define LWIP_NETIF_STATUS_CALLBACK 0 +//#define LWIP_NETIF_LINK_CALLBACK 0 +//#define LWIP_NETIF_HWADDRHINT 0 + +//***************************************************************************** +// +// ---------- LOOPIF options ---------- +// +//***************************************************************************** +//#define LWIP_HAVE_LOOPIF 0 +//#define LWIP_LOOPIF_MULTITHREADING 1 + +//***************************************************************************** +// +// ---------- Thread options ---------- +// +//***************************************************************************** +//#define TCPIP_THREAD_NAME "tcpip_thread" +//#define TCPIP_THREAD_STACKSIZE 0 +//#define TCPIP_THREAD_PRIO 1 +//#define TCPIP_MBOX_SIZE 0 +//#define SLIPIF_THREAD_NAME "slipif_loop" +//#define SLIPIF_THREAD_STACKSIZE 0 +//#define SLIPIF_THREAD_PRIO 1 +//#define PPP_THREAD_NAME "pppMain" +//#define PPP_THREAD_STACKSIZE 0 +//#define PPP_THREAD_PRIO 1 +//#define DEFAULT_THREAD_NAME "lwIP" +//#define DEFAULT_THREAD_STACKSIZE 0 +//#define DEFAULT_THREAD_PRIO 1 +//#define DEFAULT_RAW_RECVMBOX_SIZE 0 +//#define DEFAULT_UDP_RECVMBOX_SIZE 0 +//#define DEFAULT_TCP_RECVMBOX_SIZE 0 +//#define DEFAULT_ACCEPTMBOX_SIZE 0 + +//***************************************************************************** +// +// ---------- Sequential layer options ---------- +// +//***************************************************************************** +//#define LWIP_TCPIP_CORE_LOCKING 0 +#define LWIP_NETCONN 0 // default is 1 + +//***************************************************************************** +// +// ---------- Socket Options ---------- +// +//***************************************************************************** +#define LWIP_SOCKET 0 // default is 1 +//#define LWIP_COMPAT_SOCKETS 1 +//#define LWIP_POSIX_SOCKETS_IO_NAMES 1 +//#define LWIP_TCP_KEEPALIVE 0 +//#define LWIP_SO_RCVTIMEO 0 +//#define LWIP_SO_RCVBUF 0 +//#define SO_REUSE 0 + +//***************************************************************************** +// +// ---------- Statistics options ---------- +// +//***************************************************************************** +//#define LWIP_STATS 1 +//#define LWIP_STATS_DISPLAY 0 +//#define LINK_STATS 1 +//#define ETHARP_STATS (LWIP_ARP) +//#define IP_STATS 1 +//#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) +//#define ICMP_STATS 1 +//#define IGMP_STATS (LWIP_IGMP) +//#define UDP_STATS (LWIP_UDP) +//#define TCP_STATS (LWIP_TCP) +//#define MEM_STATS 1 +//#define MEMP_STATS 1 +//#define SYS_STATS 1 + +//***************************************************************************** +// +// ---------- PPP options ---------- +// +//***************************************************************************** +//#define PPP_SUPPORT 0 +//#define PPPOE_SUPPORT 0 +//#define PPPOS_SUPPORT PPP_SUPPORT + +#if PPP_SUPPORT +//#define NUM_PPP 1 +//#define PAP_SUPPORT 0 +//#define CHAP_SUPPORT 0 +//#define MSCHAP_SUPPORT 0 +//#define CBCP_SUPPORT 0 +//#define CCP_SUPPORT 0 +//#define VJ_SUPPORT 0 +//#define MD5_SUPPORT 0 +//#define FSM_DEFTIMEOUT 6 +//#define FSM_DEFMAXTERMREQS 2 +//#define FSM_DEFMAXCONFREQS 10 +//#define FSM_DEFMAXNAKLOOPS 5 +//#define UPAP_DEFTIMEOUT 6 +//#define UPAP_DEFREQTIME 30 +//#define CHAP_DEFTIMEOUT 6 +//#define CHAP_DEFTRANSMITS 10 +//#define LCP_ECHOINTERVAL 0 +//#define LCP_MAXECHOFAILS 3 +//#define PPP_MAXIDLEFLAG 100 + +//#define PPP_MAXMTU 1500 +//#define PPP_DEFMRU 296 +#endif + +//***************************************************************************** +// +// ---------- checksum options ---------- +// +//***************************************************************************** +#define CHECKSUM_GEN_IP 0 +#define CHECKSUM_GEN_ICMP 0 +#define CHECKSUM_GEN_UDP 0 +#define CHECKSUM_GEN_TCP 0 +#define CHECKSUM_CHECK_IP 0 +#define CHECKSUM_CHECK_UDP 0 +#define CHECKSUM_CHECK_TCP 0 + +//***************************************************************************** +// +// ---------- Debugging options ---------- +// +//***************************************************************************** +#ifdef DEBUG +#define U8_F "c" +#define S8_F "c" +#define X8_F "02x" +#define U16_F "u" +#define S16_F "d" +#define X16_F "x" +#define U32_F "u" +#define S32_F "d" +#define X32_F "x" +extern void UARTprintf(const char *pcString, ...); +#define LWIP_PLATFORM_DIAG(msg) UARTprintf msg +#define LWIP_PLATFORM_ASSERT(msg) \ + UARTprintf("ASSERT FAIL at line %d of %s:\ %s\n", __LINE__, __FILE__, msg) +#define LWIP_DEBUG 1 +#endif + +//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF +//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_WARNING +//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_SERIOUS +//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_SEVERE + +//#define LWIP_DBG_TYPES_ON LWIP_DBG_ON +//#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE| \ + LWIP_DBG_STATE|LWIP_DBG_FRESH) + +//#define ETHARP_DEBUG LWIP_DBG_ON // default is OFF +#define NETIF_DEBUG LWIP_DBG_OFF +//#define PBUF_DEBUG LWIP_DBG_OFF +//#define API_LIB_DEBUG LWIP_DBG_OFF +//#define API_MSG_DEBUG LWIP_DBG_OFF +//#define SOCKETS_DEBUG LWIP_DBG_OFF +#define HTTPD_DEBUG LWIP_DBG_OFF +//#define ICMP_DEBUG LWIP_DBG_OFF +//#define IGMP_DEBUG LWIP_DBG_OFF +//#define INET_DEBUG LWIP_DBG_OFF +//#define IP_DEBUG LWIP_DBG_ON +//#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +//#define MEM_DEBUG LWIP_DBG_OFF +//#define MEMP_DEBUG LWIP_DBG_OFF +//#define SYS_DEBUG LWIP_DBG_OFF +//#define TCP_DEBUG LWIP_DBG_ON +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +//#define TCP_FR_DEBUG LWIP_DBG_OFF +//#define TCP_RTO_DEBUG LWIP_DBG_OFF +//#define TCP_CWND_DEBUG LWIP_DBG_OFF +//#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +//#define TCP_RST_DEBUG LWIP_DBG_OFF +//#define TCP_QLEN_DEBUG LWIP_DBG_OFF +//#define UDP_DEBUG LWIP_DBG_ON // default is OFF +//#define TCPIP_DEBUG LWIP_DBG_ON +//#define PPP_DEBUG LWIP_DBG_OFF +//#define SLIP_DEBUG LWIP_DBG_OFF +//#define DHCP_DEBUG LWIP_DBG_ON // default is OFF +//#define AUTOIP_DEBUG LWIP_DBG_OFF +//#define SNMP_MSG_DEBUG LWIP_DBG_OFF +//#define SNMP_MIB_DEBUG LWIP_DBG_OFF +//#define DNS_DEBUG LWIP_DBG_OFF + +#endif /* __LWIPOPTS_H__ */ diff --git a/boards/ek-tm4c1294xl/qs_iot/qs_iot.c b/boards/ek-tm4c1294xl/qs_iot/qs_iot.c new file mode 100644 index 0000000..0f622a8 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.c @@ -0,0 +1,1151 @@ +//***************************************************************************** +// +// qs_iot.c - Quickstart application that connects to a cloud server. +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#include +#include +#include +#include "inc/hw_memmap.h" +#include "inc/hw_types.h" +#include "inc/hw_ints.h" +#include "inc/hw_adc.h" +#include "driverlib/adc.h" +#include "driverlib/gpio.h" +#include "driverlib/pin_map.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/sysctl.h" +#include "driverlib/systick.h" +#include "driverlib/uart.h" +#include "driverlib/interrupt.h" +#include "driverlib/timer.h" +#include "utils/cmdline.h" +#include "utils/uartstdio.h" +#include "utils/ustdlib.h" +#include "utils/lwiplib.h" +#include "drivers/pinout.h" +#include "drivers/buttons.h" +#include "drivers/exosite_hal_lwip.h" +#include "drivers/eth_client_lwip.h" +#include "exosite.h" +#include "stats.h" +#include "qs_iot.h" +#include "requests.h" +#include "commands.h" +#include "tictactoe.h" + +//***************************************************************************** +// +//! \addtogroup example_list +//!

Internet of Things Quickstart (qs_iot)

+//! +//! +//! This application records various information about user activity on the +//! board, and periodically reports it to a cloud server managed by Exosite. In +//! order to use all of the features of this application, you will need to have +//! an account with Exosite, and make sure that the device you are using is +//! registered to your Exosite profile with its original MAC address from the +//! factory. +//! +//! If you do not yet have an Exosite account, you can create one at +//! http://ti.exosite.com. The web interface there will help guide you through +//! the account creation process. There is also information in the Quickstart +//! document that is shipped along with the EK-TM4C1294XL evaluation kit. +//! +//! This application uses a command-line based interface through a virtual COM +//! port on UART 0, with the settings 115,200-8-N-1. This application also +//! requires a wired Ethernet connection with internet access to perform +//! cloud-connected activities. +//! +//! Once the application is running you should be able to see program output +//! over the virtual COM port, and interact with the command-line. The command +//! line will allow you to see the information being sent to and from Exosite's +//! servers, change the state of LEDs, and play a game of tic-tac-toe. If you +//! have internet connectivity issues, need to find your MAC address, or need +//! to re-activate your EK-TM4C1294XL board with Exosite, the command line +//! interface also has options to support these operations. Type +//! 'help' at the command prompt to see a list of available commands. +//! +//! If your local internet connection requires the use of a proxy server, you +//! will need to enter a command over the virtual COM port terminal before the +//! device will be able to connect to Exosite. When prompted by the +//! application, type 'setproxy help' for information on how to configure the +//! proxy. Alternatively, you may uncomment the define statements below for +//! "CUSTOM_PROXY" settings, fill in the correct information for your local +//! http proxy server, and recompile this example. This will permanently set +//! your proxy as the default connection point. +//! +// +//***************************************************************************** + +//***************************************************************************** +// +// The error routine that is called if the driver library encounters an error. +// +//***************************************************************************** +#ifdef DEBUG +void +__error__(char *pcFilename, uint32_t ui32Line) +{ +} +#endif + +//***************************************************************************** +// +// Global macro definitions. +// +//***************************************************************************** +#define MAX_SYNC_RETRIES 10 + +// #define CUSTOM_PROXY +// #define PROXY_ADDRESS "your.proxy.address" +// #define PROXY_PORT 80 + +//***************************************************************************** +// +// Global variables that will be linked to Exosite. +// +//***************************************************************************** +uint32_t g_ui32SW1Presses = 0; +uint32_t g_ui32SW2Presses = 0; +uint32_t g_ui32InternalTempF = 0; +uint32_t g_ui32InternalTempC = 0; +uint32_t g_ui32TimerIntCount = 0; +uint32_t g_ui32SecondsOnTime = 0; +uint32_t g_ui32LEDD1 = 0; +uint32_t g_ui32LEDD2 = 0; +char g_pcLocation[50] = ""; +char g_pcContactEmail[100] = ""; +char g_pcAlert[140] = ""; + +//***************************************************************************** +// +// Global structures used to interface with Exosite. +// +//***************************************************************************** +tStat g_sSW1Presses = + {"SW1-presses", &g_ui32SW1Presses, "usrsw1", INT, WRITE_ONLY}; + +tStat g_sSW2Presses = + {"SW2-presses", &g_ui32SW2Presses, "usrsw2", INT, WRITE_ONLY}; + +tStat g_sInternalTempF = + {"Temp(F)", &g_ui32InternalTempF, 0, INT, WRITE_ONLY}; + +tStat g_sInternalTempC = + {"Temp(C)", &g_ui32InternalTempC, "jtemp", INT, WRITE_ONLY}; + +tStat g_sSecondsOnTime = + {"Time since reset", &g_ui32SecondsOnTime, "ontime", INT, WRITE_ONLY}; + +tStat g_sLEDD1 = + {"LED D1", &g_ui32LEDD1, "ledd1", INT, READ_WRITE}; + +tStat g_sLEDD2 = + {"LED D2", &g_ui32LEDD2, "ledd2", INT, READ_WRITE}; + +tStat g_sLocation = + {"Location", g_pcLocation, "location", STRING, READ_ONLY}; + +tStat g_sBoardState = + {NULL, &g_ui32BoardState, "gamestate", HEX, WRITE_ONLY}; + +tStat g_sContactEmail = + {"Contact Email", g_pcContactEmail, "emailaddr", STRING, READ_WRITE}; + +tStat g_sAlert = + {"Alert Message", g_pcAlert, "alert", STRING, NONE}; + +//***************************************************************************** +// +// Global array of pointers to all tStat structures to be synced with Exosite. +// +//***************************************************************************** +tStat *g_psDeviceStatistics[NUM_STATS]= +{ + &g_sSW1Presses, + &g_sSW2Presses, + &g_sInternalTempF, + &g_sInternalTempC, + &g_sSecondsOnTime, + &g_sLEDD1, + &g_sLEDD2, + &g_sLocation, + &g_sBoardState, + &g_sContactEmail, + &g_sAlert, + NULL +}; + +//***************************************************************************** +// +// Global variable to keep track of the system clock. +// +//***************************************************************************** +uint32_t g_ui32SysClock = 0; + +//***************************************************************************** +// +// Flags to keep track of application state. +// +//***************************************************************************** +bool g_bPrintingData = false; +bool g_bGameActive = false; +volatile bool g_bOnline = false; +uint32_t g_ui32LinkRetries = 0; + +//***************************************************************************** +// +// Input buffer for the command line interpreter. +// +//***************************************************************************** +char g_cInput[APP_INPUT_BUF_SIZE]; + +//***************************************************************************** +// +// Given a list of statistics, prints each item to the UART. +// +//***************************************************************************** +void +PrintStats(tStat **psStats) +{ + uint32_t ui32Index; + char pcStatValue[256]; + char *pcStatName; + + // + // Loop over all statistics in the list. + // + for(ui32Index = 0; psStats[ui32Index] != NULL; ui32Index++) + { + if(psStats[ui32Index]->pcName) + { + // + // For each statistic, print the name and current value to the UART. + // + pcStatName = psStats[ui32Index]->pcName; + StatPrintValue(psStats[ui32Index], pcStatValue); + + UARTprintf("%25s= %s\n", pcStatName, pcStatValue); + } + } +} + +//***************************************************************************** +// +// Prints the current MAC address to the UART. +// +//***************************************************************************** +void +PrintMac(void) +{ + uint8_t ui8Idx; + uint8_t pui8MACAddr[6]; + + // + // Get the MAC address from the Ethernet Client layer. + // + EthClientMACAddrGet(pui8MACAddr); + + UARTprintf("Current MAC: "); + + // + // Extract each pair of characters and print them to the UART. + // + for(ui8Idx = 0; ui8Idx < 6; ui8Idx++) + { + UARTprintf("%02x", pui8MACAddr[ui8Idx]); + } + + UARTprintf("\n"); +} + +//***************************************************************************** +// +// This function prints a list of local statistics for this board. +// +//***************************************************************************** +void +PrintAllData(void) +{ + char cExositeCIK[CIK_LENGTH]; + + if(UARTPeek('\r') != -1) + { + g_bPrintingData = false; + + // + // Get a user command back + // + UARTgets(g_cInput, APP_INPUT_BUF_SIZE); + + // + // Print a prompt + // + UARTprintf("\n> "); + + return; + } + + UARTprintf("\033[2J\033[H"); + UARTprintf("Welcome to the Connected LaunchPad!!\n"); + UARTprintf("Internet of Things Demo\n"); + UARTprintf("Type 'help' for help.\n\n"); + + // + // Print out the MAC address for reference + // + PrintMac(); + + // + // Check to see if we already have a CIK, and print it to the UART + // + if(Exosite_GetCIK(cExositeCIK)) + { + UARTprintf("Current CIK: %s\n", cExositeCIK); + } + else + { + UARTprintf("No CIK found. Connect to Exosite to obtain one.\n"); + } + + // + // Check to see how many times (if any) we've failed to connect to the + // server. + // + if((g_ui32LinkRetries == 0) && g_bOnline) + { + // + // For zero failures, report a "Link OK" + // + UARTprintf("Link Status: OK\n"); + } + else if((g_ui32LinkRetries < MAX_SYNC_RETRIES) && g_bOnline) + { + // + // For the first few failures, report that we are trying to + // re-establish a link. + // + UARTprintf("Link Status: Lost (Retries: %d)\n", g_ui32LinkRetries); + } + else + { + // + // If we have exceeded the maximum number of retries, show status as + // offline. + // + UARTprintf("Link Status: Offline"); + } + + // + // Print some header text. + // + UARTprintf("\nCollected Statistics\n"); + UARTprintf("--------------------\n"); + + PrintStats(g_psDeviceStatistics); + + UARTprintf("\nPress Enter to return to the command prompt...\n"); + + UARTFlushTx(0); + + return; +} + +//***************************************************************************** +// +// Prints a help message to the UART to help with troubleshooting Exosite +// connection issues. +// +//***************************************************************************** +void +PrintConnectionHelp(void) +{ + UARTprintf("Troubleshooting Exosite Connection:\n\n"); + + UARTprintf(" + Make sure you are connected to the internet.\n\n"); + + UARTprintf(" + Make sure you have created an Exosite profile.\n\n"); + + UARTprintf(" + Make sure you have a \"Connected Launchpad\" device\n"); + UARTprintf(" created in your Exosite profile.\n\n"); + + UARTprintf(" + Make sure your that your board's MAC address is\n"); + UARTprintf(" correctly registered with your exosite profile.\n\n"); + + UARTprintf(" + If you have a CIK, make sure it matches the CIK for\n"); + UARTprintf(" this device in your online profile with Exosite.\n\n"); + + UARTprintf(" + If you have a proxy, make sure to configure it using\n"); + UARTprintf(" this terminal. Type 'setproxy help' to get started.\n"); + UARTprintf(" Once the proxy is set, type 'activate' to obtain a\n"); + UARTprintf(" new CIK, or 'connect' to connect to exosite using an\n"); + UARTprintf(" existing CIK.\n\n"); + + UARTprintf(" + Make sure your device is available for provisioning.\n"); + UARTprintf(" If you are not sure that provisioning is enabled,\n"); + UARTprintf(" check the Read Me First documentation or the online\n"); + UARTprintf(" exosite portal for more information.\n\n"); +} + +//***************************************************************************** +// +// Attempts to find a CIK in the EEPROM. Reports the status of this operation +// to the UART. +// +//***************************************************************************** +bool +GetEEPROMCIK(void) +{ + char pcExositeCIK[50]; + + // + // Try to read the CIK from EEPROM, and alert the user based on what we + // find. + // + if(Exosite_GetCIK(pcExositeCIK)) + { + // + // If a CIK is found, continue on to make sure that the CIK is valid. + // + UARTprintf("CIK found in EEPROM storage.\n\nCIK: %s\n\n", + pcExositeCIK); + } + else + { + // + // If a CIK was not found, return immediately and indicate the failure. + // + UARTprintf("No CIK found in EEPROM.\n"); + return 0; + } + + UARTprintf("Connecting to Exosite...\r"); + + // + // If a CIK was found, try to sync with Exosite. This should tell us if + // the CIK is valid or not. + // + if(SyncWithExosite(g_psDeviceStatistics)) + { + // + // If the sync worked, the CIK is valid. Alert the caller. + // + UARTprintf("Connected! Type 'stats' to see data for this board."); + return 1; + } + else + { + // + // If the sync failed, the CIK is probably invalid, so pass the error + // back to the caller. + // + UARTprintf("Initial sync failed. CIK may be invalid.\n"); + return 0; + } +} + +//***************************************************************************** +// +// Attempts to provision a new CIK through a request to Exosite's servers. This +// should be used when Exosite's CIK does not match the CIK for this device, or +// when a CIK is not found in EEPROM. +// +//***************************************************************************** +bool +ProvisionCIK(void) +{ + uint32_t ui32Idx; + char pcExositeCIK[50]; + + // + // If we get here, no CIK was found in EEPROM storage. We may need to + // obtain a CIK from the server. + // + UARTprintf("Connecting to exosite to obtain a new CIK... \n"); + + // + // Try to activate with Exosite a few times. If we succeed move on with the + // new CIK. Otherwise, fail. + // + for(ui32Idx = 0; ui32Idx < 1; ui32Idx++) + { + if(Exosite_Activate()) + { + // + // If exosite gives us a CIK, send feedback to the user + // + UARTprintf("CIK acquired!\n\n"); + + if(Exosite_GetCIK(pcExositeCIK)) + { + UARTprintf("CIK: %s\n\n", pcExositeCIK); + UARTprintf("Connected! "); + UARTprintf("Type 'stats' to see data for this board."); + } + else + { + // + // This shouldn't ever happen, but print an error message in + // case it does. + // + UARTprintf("ERROR reading new CIK from EEPROM.\n"); + } + + // + // Return "true" indicating that we found a valid CIK. + // + return true; + } + else + { + // + // If the activation fails, wait at least one second before + // retrying. + // + //ROM_SysCtlDelay(g_ui32SysClock/3); + if(Exosite_StatusCode() == EXO_STATUS_CONFLICT) + { + // + // This can occur if the MAC address for this board has already + // been activated, and the device has not been re-enabled for a + // new CIK. + // + UARTprintf("\nExosite reported that this device is not\n"); + UARTprintf("available for provisioning. Check to make sure\n"); + UARTprintf("that you have the correct MAC address, and that\n"); + UARTprintf("this device is enabled for provisioning in your\n"); + UARTprintf("Exosite profile.\n\n"); + + return false; + } + } + } + + // + // Exosite didn't respond, so let the user know. + // + UARTprintf("No CIK could be obtained.\n\n"); + + PrintConnectionHelp(); + + // + // Return "false", indicating that no CIK was found. + // + return false; +} + +//***************************************************************************** +// +// Attempts to provision a new CIK through a request to Exosite's servers. This +// should be used when Exosite's CIK does not match the CIK for this device, or +// when a CIK is not found in EEPROM. +// +//***************************************************************************** +bool +LocateValidCIK(void) +{ + // + // Try to obtain a valid CIK. + // + UARTprintf("Locating CIK... "); + + // + // Check the EEPROM for a valid CIK first. If none can be found + // there, try to provision a CIK from exosite. If we can obtain a + // CIK, make sure to set the global state variable that indicates + // that we can connect to exosite. + // + if(GetEEPROMCIK()) + { + return true; + } + else if(ProvisionCIK()) + { + return true; + } + else + { + // + // If both cases above fail, return false, indicating that we did not + // find a CIK. + // + return false; + } +} + +//***************************************************************************** +// +// Takes a reading from the internal temperature sensor, and updates the +// corresponding global statistics. +// +//***************************************************************************** +void +UpdateInternalTemp(void) +{ + uint32_t pui32ADC0Value[1], ui32TempValueC, ui32TempValueF; + + // + // Take a temperature reading with the ADC. + // + ROM_ADCProcessorTrigger(ADC0_BASE, 3); + + // + // Wait for the ADC to finish taking the sample + // + while(!ROM_ADCIntStatus(ADC0_BASE, 3, false)) + { + } + + // + // Clear the interrupt + // + ROM_ADCIntClear(ADC0_BASE, 3); + + // + // Read the analog voltage measurement. + // + ROM_ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); + + // + // Convert the measurement to degrees Celcius and Fahrenheit, and save to + // the global state variables. + // + ui32TempValueC = ((1475 * 4096) - (2250 * pui32ADC0Value[0])) / 40960; + g_ui32InternalTempC = ui32TempValueC; + ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; + g_ui32InternalTempF = ui32TempValueF; +} + +//***************************************************************************** +// +// Polls the buttons, and updates global state accordingly. +// +//***************************************************************************** +void +UpdateButtons(void) +{ + uint8_t ui8Buttons, ui8ButtonsChanged; + + // + // Check the current debounced state of the buttons. + // + ui8Buttons = ButtonsPoll(&ui8ButtonsChanged,0); + + // + // If either button has been pressed, record that status to the + // corresponding global variable. + // + if(BUTTON_PRESSED(USR_SW1, ui8Buttons, ui8ButtonsChanged)) + { + g_ui32SW1Presses++; + } + else if(BUTTON_PRESSED(USR_SW2, ui8Buttons, ui8ButtonsChanged)) + { + g_ui32SW2Presses++; + } +} + +//***************************************************************************** +// +// Turns LEDs on or off based on global state variables. +// +//***************************************************************************** +void +UpdateLEDs(void) +{ + // + // If either LED's global flag is set, turn that LED on. Otherwise, turn + // them off. + // + if(g_ui32LEDD1) + { + ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1); + } + else + { + ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0); + } + + if(g_ui32LEDD2) + { + ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); + } + else + { + ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); + } +} + +//***************************************************************************** +// +// Prompts the user for a command, and blocks while waiting for the user's +// input. This function will return after the execution of a single command. +// +//***************************************************************************** +void +CheckForUserCommands(void) +{ + int iStatus; + + // + // Peek to see if a full command is ready for processing + // + if(UARTPeek('\r') == -1) + { + // + // If not, return so other functions get a chance to run. + // + return; + } + + // + // If we do have commands, process them immediately in the order they were + // received. + // + while(UARTPeek('\r') != -1) + { + // + // Get a user command back + // + UARTgets(g_cInput, APP_INPUT_BUF_SIZE); + + // + // Process the received command + // + iStatus = CmdLineProcess(g_cInput); + + // + // Handle the case of bad command. + // + if(iStatus == CMDLINE_BAD_CMD) + { + UARTprintf("Bad command!\n"); + } + + // + // Handle the case of too many arguments. + // + else if(iStatus == CMDLINE_TOO_MANY_ARGS) + { + UARTprintf("Too many arguments for command processor!\n"); + } + } + + // + // Print a prompt + // + UARTprintf("\n> "); + +} + + +//***************************************************************************** +// +// Interrupt handler for Timer0A. +// +// This function will be called periodically on the expiration of Timer0A It +// performs periodic tasks, such as looking for input on the physical buttons, +// and reporting usage statistics to the cloud. +// +//***************************************************************************** +void +Timer0IntHandler(void) +{ + // + // Clear the timer interrupt. + // + ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); + + // + // Keep track of the number of times this interrupt handler has been + // called. + // + g_ui32TimerIntCount++; + + // + // Poll the GPIOs for the buttons to check for press events. Update global + // variables as necessary. + // + UpdateButtons(); + + if((!g_bPrintingData) && (!g_bGameActive)) + { + CheckForUserCommands(); + } + + // + // Once per second, perform the following operations. + // + if(!(g_ui32TimerIntCount % APP_TICKS_PER_SEC)) + { + // + // Keep track of the total seconds of on-time + // + g_ui32SecondsOnTime++; + + // + // Take a reading from the internal temperature sensor. + // + UpdateInternalTemp(); + + // + // Set the LEDs to the correct state. + // + UpdateLEDs(); + + // + // Check to see if we have any on-going actions that require the UART + // + if(g_bPrintingData) + { + // + // If the user has requested a data print-out, perform that here. + // + PrintAllData(); + } + else if(g_bGameActive) + { + // + // If the user is playing a game of tic-tac-toe, enter the game + // state machine here. + // + if(AdvanceGameState()) + { + // + // When the tic-tac-toe game state function returns a '1', the + // game is over. Print a newline, remove the 'g_bGameActive' + // flag, and resume normal operation. + // + UARTprintf("\n> "); + g_bGameActive = 0; + } + } + } + + // + // Make sure the running tally of the number of interrupts doesn't + // overflow. + // + if(g_ui32TimerIntCount == (20 * APP_TICKS_PER_SEC)) + { + // + // Reset the interrupt count to zero. + // + g_ui32TimerIntCount = 0; + + } + +} + +//***************************************************************************** +// +// Configures Timer 0 as a general purpose, periodic timer for handling button +// presses. +// +//***************************************************************************** +void +ConfigureTimer0(void) +{ + // + // Enable the peripherals used by this example. + // + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); + + // + // Configure the two 32-bit periodic timers. + // + ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); + ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock / APP_TICKS_PER_SEC); + + // + // Lower the priority of this interrupt + // + ROM_IntPriorityGroupingSet(4); + ROM_IntPrioritySet(INT_TIMER0A, 0xE0); + + // + // Setup the interrupts for the timer timeouts. + // + ROM_IntEnable(INT_TIMER0A); + ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); +} + +//***************************************************************************** +// +// Enables and configures ADC0 to read the internal temperature sensor into +// sample sequencer 3. +// +//***************************************************************************** +void +ConfigureADC0(void) +{ + // + // Enable clock to ADC0. + // + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); + + // + // Configure ADC0 Sample Sequencer 3 for processor trigger operation. + // + ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); + + // + // Increase the hold time of this sample sequencer to account for the + // temperature sensor erratum (ADC#09). + // + HWREG(ADC0_BASE + ADC_O_SSTSH3) = 0x4; + + // + // Configure ADC0 sequencer 3 for a single sample of the temperature + // sensor. + // + ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | + ADC_CTL_END); + + // + // Enable the sequencer. + // + ROM_ADCSequenceEnable(ADC0_BASE, 3); + + // + // Clear the interrupt bit for sequencer 3 to make sure it is not set + // before the first sample is taken. + // + ROM_ADCIntClear(ADC0_BASE, 3); +} + +//***************************************************************************** +// +// Main function. +// +//***************************************************************************** +int +main(void) +{ + uint32_t ui32Timeout; + + // + // Run from the PLL at 120 MHz. + // + g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | + SYSCTL_OSC_MAIN | + SYSCTL_USE_PLL | + SYSCTL_CFG_VCO_480), 120000000); + + // + // Set the pinout for the board, including required pins for Ethernet + // operation. + // + PinoutSet(1,0); + + // + // Enable the UART, clear the terminal, and print a brief message. + // + UARTStdioConfig(0, 115200, g_ui32SysClock); + + // + // Configure necessary peripherals. + // + ConfigureTimer0(); + ConfigureADC0(); + + // + // Take an initial reading of the internal temperature + // + UpdateInternalTemp(); + + // + // Initialize the buttons + // + ButtonsInit(); + + // + // If a proxy has been pre-defined, enable it here. + // +#ifdef CUSTOM_PROXY + usprintf(g_pcProxyAddress, PROXY_ADDRESS); + g_ui16ProxyPort = PROXY_PORT; + g_bUseProxy = true; +#endif + + // + // Clear the screen, and print a welcome message. + // + UARTprintf("\033[2J\033[H"); + UARTprintf("Welcome to the Connected LaunchPad!!\n"); + UARTprintf("Internet of Things Demo\n"); + UARTprintf("Type \'help\' for help.\n\n"); + + // + // Initialize Exosite layer to allow Exosite-based user commands later. + // + Exosite_Init("texasinstruments", "ek-tm4c1294xl", IF_ENET, 0); + + // + // Start with the assumption that we are not online yet. + // + g_bOnline = false; + + // + // Print the MAC address, which users will need to register with Exosite. + // + PrintMac(); + + // + // Notify the user that we are obtaining an IP address. + // + UARTprintf("Obtaining IP... "); + + // + // Loop a few times to make sure that DHCP has time to find an IP. + // + for(ui32Timeout = 10; ui32Timeout > 0; ui32Timeout--) + { + // + // Check to see if we have an IP yet. + // + if((lwIPLocalIPAddrGet() != 0xffffffff) && + (lwIPLocalIPAddrGet() != 0x00000000)) + { + // + // Report that we found an IP address. + // + UARTprintf("IP Address Found.\n"); + + // + // If we can find and validate a CIK with Exosite, set the flag to + // indicate have a valid connection to the cloud. + // + g_bOnline = LocateValidCIK(); + + break; + } + else if(ui32Timeout == 0) + { + // + // Alert the user if it takes a long time to find an IP address. An + // IP address can still be found later, so this is not an + // indication of failure. + // + UARTprintf("No IP address found, continuing \n" + "to search in the background\n"); + } + + // + // Delay a second to allow DHCP to find us an IP address. + // + ROM_SysCtlDelay(g_ui32SysClock / 3); + } + + // + // If we don't have a valid exosite connection, let the user know that the + // device is "offline" and not performing any data synchronization with the + // cloud. + // + if(!g_bOnline) + { + UARTprintf("Continuing in offline mode.\n\n"); + } + + // + // Print a prompt + // + UARTprintf("\n> "); + + // + // Enable interrupts and start the timer. This will enable the UART console + // input, and also enable updates to the various cloud-enabled variables. + // + ROM_IntMasterEnable(); + ROM_TimerEnable(TIMER0_BASE, TIMER_A); + + // + // Main application loop. + // + while(1) + { + // + // Only run the following loop if we have a valid connection to + // Exosite. + // + if(g_bOnline) + { + // + // Attempt to sync data with Exosite + // + if(SyncWithExosite(g_psDeviceStatistics)) + { + // + // If the sync is successful, reset the "retries" count to zero + // + g_ui32LinkRetries = 0; + } + else if(Exosite_StatusCode() == EXO_STATUS_NOAUTH) + { + // + // Check to see if we failed for having an old CIK. If we did, + // flush the UART output, and stop any data-printing operation. + // + g_bPrintingData = 0; + UARTFlushTx(0); + + // + // Alert the user of the expired CIK. + // + UARTprintf("\nCIK no longer valid. "); + UARTprintf("Please try typing 'activate'.\n"); + UARTprintf("If this does not work, "); + UARTprintf("log in to exosite to check on\n"); + UARTprintf("the status of your devices.\n"); + UARTprintf("\n> "); + + // + // We did connect to Exosite, so the link is still valid, but + // data syncing will not work. Do not increment the number of + // link retries, but do consider the board "offline" for data + // syncing. + // + g_ui32LinkRetries = 0; + g_bOnline = false; + } + else + { + // + // If the sync fails for some other reason, make sure to record + // the failure. + // + g_ui32LinkRetries++; + + // + // If there are too many failures, assume that the connection + // was dropped. + // + if(g_ui32LinkRetries > MAX_SYNC_RETRIES) + { + g_bOnline = false; + } + } + } + } +} diff --git a/boards/ek-tm4c1294xl/qs_iot/qs_iot.ewd b/boards/ek-tm4c1294xl/qs_iot/qs_iot.ewd new file mode 100644 index 0000000..9c3f3df --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.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/ek-tm4c1294xl/qs_iot/qs_iot.ewp b/boards/ek-tm4c1294xl/qs_iot/qs_iot.ewp new file mode 100644 index 0000000..3c9373d --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.ewp @@ -0,0 +1,857 @@ + + + + 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 + + + + Source + + $PROJ_DIR$\..\drivers\buttons.c + + + $PROJ_DIR$\..\..\..\..\utils\cmdline.c + + + $PROJ_DIR$\commands.c + + + $PROJ_DIR$\..\drivers\eth_client_lwip.c + + + $PROJ_DIR$\..\..\..\..\third_party\exosite\exosite.c + + + $PROJ_DIR$\..\drivers\exosite_hal_lwip.c + + + $PROJ_DIR$\..\..\..\..\third_party\exosite\exosite_meta.c + + + $PROJ_DIR$\..\..\..\..\utils\flash_pb.c + + + $PROJ_DIR$\..\drivers\http.c + + + $PROJ_DIR$\..\..\..\..\utils\locator.c + + + $PROJ_DIR$\..\..\..\..\utils\lwiplib.c + + + $PROJ_DIR$\..\drivers\pinout.c + + + $PROJ_DIR$\qs_iot.c + + + $PROJ_DIR$\requests.c + + + $PROJ_DIR$\..\..\..\..\utils\ringbuf.c + + + $PROJ_DIR$\startup_ewarm.c + + + $PROJ_DIR$\stats.c + + + $PROJ_DIR$\tictactoe.c + + + $PROJ_DIR$\..\..\..\..\utils\uartstdio.c + + + $PROJ_DIR$\..\..\..\..\utils\ustdlib.c + + + diff --git a/boards/ek-tm4c1294xl/qs_iot/qs_iot.h b/boards/ek-tm4c1294xl/qs_iot/qs_iot.h new file mode 100644 index 0000000..be9667b --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.h @@ -0,0 +1,105 @@ +//***************************************************************************** +// +// qs_iot.h - EK-TM4C1294XL Quick start application +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#ifndef __QS_IOT_H_ +#define __QS_IOT_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Globally defined constants +// +//***************************************************************************** +#define APP_TICKS_PER_SEC 100 +#define APP_INPUT_BUF_SIZE 1024 +#define NUM_STATS 12 + +bool SyncWithExosite(tStat **psStats); +void PrintAllData(void); +bool ProvisionCIK(void); + +//***************************************************************************** +// +// Global structure to hold information about the application. If a variable +// corresponds to an Exosite dataport, the alias of that dataport is also +// stored here +// +//***************************************************************************** +extern uint32_t g_ui32SW1Presses; +extern uint32_t g_ui32SW2Presses; +extern uint32_t g_ui32InternalTempF; +extern uint32_t g_ui32InternalTempC; +extern uint32_t g_ui32TimerIntCount; +extern uint32_t g_ui32SecondsOnTime; +extern uint32_t g_ui32LEDD1; +extern uint32_t g_ui32LEDD2; +extern uint32_t g_ui32BoardState; + +extern char g_pcLocation[50]; +extern char g_pcContactEmail[100]; +extern char g_pcAlert[140]; + +extern tStat *g_psDeviceStatistics[NUM_STATS]; + +extern tStat g_sLEDD1; +extern tStat g_sLEDD2; +extern tStat g_sLocation; +extern tStat g_sBoardState; +extern tStat g_sContactEmail; +extern tStat g_sAlert; + +extern char g_cInput[APP_INPUT_BUF_SIZE]; + +extern bool g_bPrintingData; +extern bool g_bGameActive; +extern volatile bool g_bOnline; +extern uint32_t g_ui32LinkRetries; + +extern uint32_t g_ui32SysClock; + +extern void PrintMac(void); +extern void PrintStats(tStat **psStats); +extern void PrintConnectionHelp(void); +extern bool LocateValidCIK(void); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __QS_IOT_H__ diff --git a/boards/ek-tm4c1294xl/qs_iot/qs_iot.icf b/boards/ek-tm4c1294xl/qs_iot/qs_iot.icf new file mode 100644 index 0000000..c6ed0c7 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.icf @@ -0,0 +1,78 @@ +//***************************************************************************** +// +// qs_iot.icf - Linker configuration file for qs_iot. +// +// 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 EK-TM4C1294XL 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/ek-tm4c1294xl/qs_iot/qs_iot.ld b/boards/ek-tm4c1294xl/qs_iot/qs_iot.ld new file mode 100644 index 0000000..b870ff2 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.ld @@ -0,0 +1,57 @@ +/****************************************************************************** + * + * qs_iot.ld - Linker configuration file for qs_iot. + * + * 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 EK-TM4C1294XL 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/ek-tm4c1294xl/qs_iot/qs_iot.sct b/boards/ek-tm4c1294xl/qs_iot/qs_iot.sct new file mode 100644 index 0000000..427d09d --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.sct @@ -0,0 +1,47 @@ +;****************************************************************************** +; +; qs_iot.sct - Linker configuration file for qs_iot. +; +; 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 EK-TM4C1294XL 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/ek-tm4c1294xl/qs_iot/qs_iot.uvopt b/boards/ek-tm4c1294xl/qs_iot/qs_iot.uvopt new file mode 100644 index 0000000..e82d0b5 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.uvopt @@ -0,0 +1,541 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + + + + 0 + 0 + + + + qs_iot + 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\TM4C1294NCPDT.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 + ..\drivers\buttons.c + buttons.c + + + 1 + 2 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\cmdline.c + cmdline.c + + + 1 + 3 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\commands.c + commands.c + + + 1 + 4 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\eth_client_lwip.c + eth_client_lwip.c + + + 1 + 5 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\third_party\exosite\exosite.c + exosite.c + + + 1 + 6 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\exosite_hal_lwip.c + exosite_hal_lwip.c + + + 1 + 7 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\third_party\exosite\exosite_meta.c + exosite_meta.c + + + 1 + 8 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\flash_pb.c + flash_pb.c + + + 1 + 9 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\http.c + http.c + + + 1 + 10 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\locator.c + locator.c + + + 1 + 11 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\lwiplib.c + lwiplib.c + + + 1 + 12 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\drivers\pinout.c + pinout.c + + + 1 + 13 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\qs_iot.c + qs_iot.c + + + 1 + 14 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\requests.c + requests.c + + + 1 + 15 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\ringbuf.c + ringbuf.c + + + 1 + 16 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\startup_rvmdk.S + startup_rvmdk.S + + + 1 + 17 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\stats.c + stats.c + + + 1 + 18 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + .\tictactoe.c + tictactoe.c + + + 1 + 19 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\uartstdio.c + uartstdio.c + + + 1 + 20 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\utils\ustdlib.c + ustdlib.c + + + + + Libraries + 1 + 0 + 0 + + 2 + 21 + 4 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + ..\..\..\..\driverlib\rvmdk\driverlib.lib + driverlib.lib + + + + + Documentation + 1 + 0 + 0 + + 3 + 22 + 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/ek-tm4c1294xl/qs_iot/qs_iot.uvproj b/boards/ek-tm4c1294xl/qs_iot/qs_iot.uvproj new file mode 100644 index 0000000..cff15fd --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot.uvproj @@ -0,0 +1,514 @@ + + + + 1.1 + +
### uVision Project, (C) Keil Software
+ + + + qs_iot + 0x4 + ARM-ADS + + + TM4C1294NCPDT + 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\ + qs_iot + 1 + 0 + 0 + 1 + 1 + .\rvmdk\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 1 + 0 + fromelf --bin --output .\rvmdk\qs_iot.bin .\rvmdk\qs_iot.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_TM4C1294NCPDT TARGET_IS_TM4C129_RA0 LWIP_1_4_1 USE_HTTP_1_0 UART_BUFFERED + + .;..;..\..\..\..;..\..\..\..\third_party\lwip-1.4.1\apps;..\..\..\..\third_party\exosite;..\..\..\..\third_party\lwip-1.4.1\ports\tiva-tm4c129\include;..\..\..\..\third_party\lwip-1.4.1\src\include;..\..\..\..\third_party\lwip-1.4.1\src\include\ipv4;..\..\..\..\third_party; + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + qs_iot.sct + + + --entry Reset_Handler + + + + + + + + Source + + + buttons.c + 1 + ..\drivers\buttons.c + + + cmdline.c + 1 + ..\..\..\..\utils\cmdline.c + + + commands.c + 1 + .\commands.c + + + eth_client_lwip.c + 1 + ..\drivers\eth_client_lwip.c + + + exosite.c + 1 + ..\..\..\..\third_party\exosite\exosite.c + + + exosite_hal_lwip.c + 1 + ..\drivers\exosite_hal_lwip.c + + + exosite_meta.c + 1 + ..\..\..\..\third_party\exosite\exosite_meta.c + + + flash_pb.c + 1 + ..\..\..\..\utils\flash_pb.c + + + http.c + 1 + ..\drivers\http.c + + + locator.c + 1 + ..\..\..\..\utils\locator.c + + + lwiplib.c + 1 + ..\..\..\..\utils\lwiplib.c + + + pinout.c + 1 + ..\drivers\pinout.c + + + qs_iot.c + 1 + .\qs_iot.c + + + requests.c + 1 + .\requests.c + + + ringbuf.c + 1 + ..\..\..\..\utils\ringbuf.c + + + startup_rvmdk.S + 2 + .\startup_rvmdk.S + + + stats.c + 1 + .\stats.c + + + tictactoe.c + 1 + .\tictactoe.c + + + uartstdio.c + 1 + ..\..\..\..\utils\uartstdio.c + + + ustdlib.c + 1 + ..\..\..\..\utils\ustdlib.c + + + + + Libraries + + + driverlib.lib + 4 + ..\..\..\..\driverlib\rvmdk\driverlib.lib + + + + + Documentation + + + readme.txt + 5 + .\readme.txt + + + + + + + +
diff --git a/boards/ek-tm4c1294xl/qs_iot/qs_iot_ccs.cmd b/boards/ek-tm4c1294xl/qs_iot/qs_iot_ccs.cmd new file mode 100644 index 0000000..b6dd2f8 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/qs_iot_ccs.cmd @@ -0,0 +1,70 @@ +/****************************************************************************** + * + * qs_iot_ccs.cmd - CCS linker configuration file for qs_iot. + * + * 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 EK-TM4C1294XL 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 + 4096; diff --git a/boards/ek-tm4c1294xl/qs_iot/readme.txt b/boards/ek-tm4c1294xl/qs_iot/readme.txt new file mode 100644 index 0000000..e111359 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/readme.txt @@ -0,0 +1,58 @@ +Internet of Things Quickstart + + +This application records various information about user activity on the +board, and periodically reports it to a cloud server managed by Exosite. In +order to use all of the features of this application, you will need to have +an account with Exosite, and make sure that the device you are using is +registered to your Exosite profile with its original MAC address from the +factory. + +If you do not yet have an Exosite account, you can create one at +http://ti.exosite.com. The web interface there will help guide you through +the account creation process. There is also information in the Quickstart +document that is shipped along with the EK-TM4C1294XL evaluation kit. + +This application uses a command-line based interface through a virtual COM +port on UART 0, with the settings 115,200-8-N-1. This application also +requires a wired Ethernet connection with internet access to perform +cloud-connected activities. + +Once the application is running you should be able to see program output +over the virtual COM port, and interact with the command-line. The command +line will allow you to see the information being sent to and from Exosite's +servers, change the state of LEDs, and play a game of tic-tac-toe. If you +have internet connectivity issues, need to find your MAC address, or need +to re-activate your EK-TM4C1294XL board with Exosite, the command line +interface also has options to support these operations. Type +'help' at the command prompt to see a list of available commands. + +If your local internet connection requires the use of a proxy server, you +will need to enter a command over the virtual COM port terminal before the +device will be able to connect to Exosite. When prompted by the +application, type 'setproxy help' for information on how to configure the +proxy. Alternatively, you may uncomment the define statements below for +"CUSTOM_PROXY" settings, fill in the correct information for your local +http proxy server, and recompile this example. This will permanently set +your proxy as the default connection point. + + +------------------------------------------------------------------------------- + +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 EK-TM4C1294XL Firmware Package. diff --git a/boards/ek-tm4c1294xl/qs_iot/requests.c b/boards/ek-tm4c1294xl/qs_iot/requests.c new file mode 100644 index 0000000..b59aa4b --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/requests.c @@ -0,0 +1,349 @@ +//***************************************************************************** +// +// requests.c - Functions for formatting requests to sync data with Exosite +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#include +#include + +#include "driverlib/rom.h" +#include "utils/ustdlib.h" +#include "exosite.h" +#include "stats.h" +#include "qs_iot.h" +#include "requests.h" + +//***************************************************************************** +// +// Buffers for writing and reading exosite data. +// +//***************************************************************************** +char g_pcWriteRequest[REQUEST_BUFFER_SIZE]; +char g_pcReadRequest[REQUEST_BUFFER_SIZE]; +char g_pcResponse[255]; + +//***************************************************************************** +// +// Syncs an individual stat with Exosite based on its read/write settings. +// +//***************************************************************************** +bool +AddSyncRequest(tStat *psStat) +{ + char pcFormattedRequest[100]; + char *pcStatAlias; + int eStatRWType; + + pcStatAlias = psStat->pcCloudAlias; + eStatRWType = psStat->eReadWriteType; + + // + // Only interact with the server if the stat has an alias + // + if(pcStatAlias == 0) + { + return 1; + } + + // + // Check to see if we write this stat to the server. + // + if((eStatRWType == WRITE_ONLY) || (eStatRWType == READ_WRITE)) + { + // + // Format a request to write the current value of this stat. + // + StatRequestFormat(psStat, pcFormattedRequest); + + // + // If the request didn't fit, report failure. + // + if(!AddRequest(pcFormattedRequest, g_pcWriteRequest, + ustrlen(pcFormattedRequest))) + { + return 0; + } + + } + else if(eStatRWType == READ_ONLY) + { + // + // If the request didn't fit, report failure. + // + if(!AddRequest(pcStatAlias, g_pcReadRequest, + ustrlen(pcStatAlias))) + { + return 0; + } + + } + + // + // Shouldn't get here... + // + return 1; +} + +bool +AddRequest(char *pcNewRequest, char *pcRequestBuffer, uint32_t ui32Size) +{ + uint32_t ui32BufferOffset; + + // + // Set the buffer offset to the location of the first null character in the + // string. + // + ui32BufferOffset = ustrlen(pcRequestBuffer); + + + // + // Check to make sure that the buffer is not full. + // + if(ui32BufferOffset >= REQUEST_BUFFER_SIZE) + { + // + // If the buffer was already full, return a zero to indicate failure. + // + pcRequestBuffer[REQUEST_BUFFER_SIZE - 1] = 0; + return 0; + } + + // + // Check to make sure that the new request is small enough to fit in the + // buffer, even if we have to add an ampersand and a null terminator. + // + if(ui32Size < (REQUEST_BUFFER_SIZE - ui32BufferOffset - 2)) + { + if(ui32BufferOffset != 0) + { + // + // If the buffer has any data in it, add an ampersand to separate + // this request from any previous requests. + // + pcRequestBuffer[ui32BufferOffset++] = '&'; + } + + // + // Append the data from the new request to the request buffer, and make + // sure to put a terminator after it. + // + ustrncpy(&pcRequestBuffer[ui32BufferOffset], pcNewRequest, ui32Size); + pcRequestBuffer[ui32BufferOffset + ui32Size] = 0; + return 1; + } + else + { + // + // If the input string is too long, return a zero. + // + return 0; + } +} + +bool +ExtractValueByAlias(char *pcAlias, char *pcBuffer, char *pcDestString, + uint32_t ui32MaxSize) +{ + char pcSearchString[100]; + char *pcValueStart; + uint32_t ui32Idx; + + // + // Set the search string to be the desired alias with an equals-sign + // appended. This should help us distinguish between a real alias and a + // string value made up of the same letters. + // + usprintf(pcSearchString, "%s=", pcAlias); + + // + // Find the desired alias in the buffer. + // + pcValueStart = ustrstr(pcBuffer, pcAlias); + + // + // If we couldn't find it, return a zero. Otherwise, continue extracting + // the value. + // + if(!pcValueStart) + { + return false; + } + + // + // Find the equals-sign, which should be just before the start of the + // value. + // + pcValueStart = ustrstr(pcValueStart, "="); + + if(!pcValueStart) + { + return false; + } + + // + // Advance to the first character of the value. + // + pcValueStart++; + + // + // Loop through the input value from the buffer, and copy characters to the + // destination string. + // + ui32Idx = 0; + while(ui32Idx < ui32MaxSize) + { + // + // Check for the end of the value string. + // + if((pcValueStart[ui32Idx] == '&') || + (pcValueStart[ui32Idx] == 0)) + { + // + // If we have reached the end of the value, null-terminate the + // destination string, and return. + // + pcDestString[ui32Idx] = 0; + return 1; + } + else + { + pcDestString[ui32Idx] = pcValueStart[ui32Idx]; + } + + ui32Idx++; + } + + pcDestString[ui32MaxSize - 1] = 0; + return 1; +} + +//***************************************************************************** +// +// Given a list of statistics, sync each of them with Exosite's server. +// +//***************************************************************************** +bool +SyncWithExosite(tStat **psStats) +{ + int eStatRWType[NUM_STATS]; + char pcServerValue[100]; + uint32_t ui32Index; + tStat *psStat; + + // + // Clear the request buffers + // + g_pcWriteRequest[0] = 0; + g_pcReadRequest[0] = 0; + + // + // Loop over all statistics in the list, and add them to the request + // buffer. + // + for(ui32Index = 0; psStats[ui32Index] != NULL; ui32Index++) + { + // + // Record the read/write behavior of each stat before sending the + // request. If a particular stat is set to "READ_WRITE", we need to + // know that now. + // + eStatRWType[ui32Index] = psStats[ui32Index]->eReadWriteType; + if(AddSyncRequest(psStats[ui32Index]) == 0) + { + return false; + } + } + + // + // Perform the write, and wait for a response from the server. If exosite + // doesn't respond, return "false", and assume that no data got through. + // + if(ustrlen(g_pcWriteRequest)) + { + if(!Exosite_Write(g_pcWriteRequest, ustrlen(g_pcWriteRequest))) + { + return false; + } + } + + // + // Perform the read, and wait for a response from the server. If exosite + // doesn't respond, return "false", and assume that no data got through. + // + if(ustrlen(g_pcReadRequest)) + { + if(!Exosite_Read(g_pcReadRequest, g_pcResponse, 255)) + { + return false; + } + } + + // + // If execution reaches this point, we can assume that the server has + // accepted the data just sent. Update the information for each stat + // accordingly. + // + for(ui32Index = 0; psStats[ui32Index] != NULL; ui32Index++) + { + psStat = psStats[ui32Index]; + + // + // Disable interrupts to avoid data disturbances in other interupt + // contexts. + // + ROM_IntMasterDisable(); + + // + // Check the read/write status of this stat. + // + if(psStat->eReadWriteType == READ_ONLY) + { + // + // If a stat is CURRENTLY marked as READ_ONLY, then update its + // value to match the new value from the server. + // + ExtractValueByAlias(psStat->pcCloudAlias, g_pcResponse, + pcServerValue, 100); + StatSetVal(psStat, pcServerValue); + } + else if(eStatRWType[ui32Index] == READ_WRITE) + { + // + // If a stat was PREVIOUSLY marked as READ_WRITE at the time that + // the most recent request was sent, then update its status to + // READ_ONLY. + // + psStat->eReadWriteType = READ_ONLY; + } + + // + // Re-enable interrupts. + // + ROM_IntMasterEnable(); + } + + // + // Successfully updated all stats. + // + return true; +} + diff --git a/boards/ek-tm4c1294xl/qs_iot/requests.h b/boards/ek-tm4c1294xl/qs_iot/requests.h new file mode 100644 index 0000000..be93855 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/requests.h @@ -0,0 +1,84 @@ +//***************************************************************************** +// +// requests.h - Header for requests.c file. Provides definitions for formatting +// requests for Exosite. +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#ifndef __REQUESTS_H__ +#define __REQUESTS_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Determines how much memory to reserve for sending requests to Exosite. +// +//***************************************************************************** +#define REQUEST_BUFFER_SIZE 255 + +//***************************************************************************** +// +// Buffers for holding request data before sending them to exosite. +// +//***************************************************************************** +extern char g_pcWriteRequest[REQUEST_BUFFER_SIZE]; +extern char g_pcReadRequest[REQUEST_BUFFER_SIZE]; + +//***************************************************************************** +// +// Buffer for holding responses from Exosite's servers until they can be +// parsed. +// +//***************************************************************************** +extern char g_pcResponse[255]; + +//***************************************************************************** +// +// Function prototypes. +// +//***************************************************************************** +extern bool AddSyncRequest(tStat *psStat); +extern bool AddRequest(char *pcNewRequest, char *pcRequestBuffer, + uint32_t ui32Size); +extern bool ExtractValueByAlias(char *pcAlias, char *pcBuffer, + char *pcDestString, uint32_t ui32MaxSize); +extern bool SyncWithExosite(tStat **psStats); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __REQUESTS_H__ diff --git a/boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.axf b/boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.axf new file mode 100644 index 0000000..47de3ae Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.axf differ diff --git a/boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.bin b/boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.bin new file mode 100644 index 0000000..604ba26 Binary files /dev/null and b/boards/ek-tm4c1294xl/qs_iot/rvmdk/qs_iot.bin differ diff --git a/boards/ek-tm4c1294xl/qs_iot/startup_ccs.c b/boards/ek-tm4c1294xl/qs_iot/startup_ccs.c new file mode 100644 index 0000000..df0cb15 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/startup_ccs.c @@ -0,0 +1,278 @@ +//***************************************************************************** +// +// 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 EK-TM4C1294XL 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 lwIPEthernetIntHandler(void); +extern void SysTickIntHandler(void); +extern void Timer0IntHandler(void); +extern void UARTStdioIntHandler(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 + UARTStdioIntHandler, // 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 + IntDefaultHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + Timer0IntHandler, // 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 + lwIPEthernetIntHandler, // 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 + IntDefaultHandler, // 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/ek-tm4c1294xl/qs_iot/startup_ewarm.c b/boards/ek-tm4c1294xl/qs_iot/startup_ewarm.c new file mode 100644 index 0000000..db8b010 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/startup_ewarm.c @@ -0,0 +1,309 @@ +//***************************************************************************** +// +// 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 EK-TM4C1294XL 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 lwIPEthernetIntHandler(void); +extern void SysTickIntHandler(void); +extern void Timer0IntHandler(void); +extern void UARTStdioIntHandler(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[1024] @ ".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 + UARTStdioIntHandler, // 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 + IntDefaultHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + Timer0IntHandler, // 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 + lwIPEthernetIntHandler, // 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 + IntDefaultHandler, // 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/ek-tm4c1294xl/qs_iot/startup_gcc.c b/boards/ek-tm4c1294xl/qs_iot/startup_gcc.c new file mode 100644 index 0000000..120db0d --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/startup_gcc.c @@ -0,0 +1,325 @@ +//***************************************************************************** +// +// 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 EK-TM4C1294XL 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 lwIPEthernetIntHandler(void); +extern void SysTickIntHandler(void); +extern void Timer0IntHandler(void); +extern void UARTStdioIntHandler(void); + +//***************************************************************************** +// +// The entry point for the application. +// +//***************************************************************************** +extern int main(void); + +//***************************************************************************** +// +// Reserve space for the system stack. +// +//***************************************************************************** +static uint32_t pui32Stack[1024]; + +//***************************************************************************** +// +// 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 + UARTStdioIntHandler, // 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 + IntDefaultHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + Timer0IntHandler, // 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 + lwIPEthernetIntHandler, // 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 + IntDefaultHandler, // 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/ek-tm4c1294xl/qs_iot/startup_rvmdk.S b/boards/ek-tm4c1294xl/qs_iot/startup_rvmdk.S new file mode 100644 index 0000000..440a396 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/startup_rvmdk.S @@ -0,0 +1,334 @@ +; <<< 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 EK-TM4C1294XL Firmware Package. +; +;****************************************************************************** + +;****************************************************************************** +; +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; +;****************************************************************************** +Stack EQU 0x00001000 + +;****************************************************************************** +; +; 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 lwIPEthernetIntHandler + EXTERN SysTickIntHandler + EXTERN Timer0IntHandler + EXTERN UARTStdioIntHandler + +;****************************************************************************** +; +; 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 UARTStdioIntHandler ; 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 IntDefaultHandler ; ADC Sequence 3 + DCD IntDefaultHandler ; Watchdog timer + DCD Timer0IntHandler ; 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 lwIPEthernetIntHandler ; 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 IntDefaultHandler ; 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 diff --git a/boards/ek-tm4c1294xl/qs_iot/stats.c b/boards/ek-tm4c1294xl/qs_iot/stats.c new file mode 100644 index 0000000..4da8932 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/stats.c @@ -0,0 +1,174 @@ +//***************************************************************************** +// +// stats.c - Implements structures and functions for cloud-connected statistics +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#include +#include + +#include "driverlib/rom.h" +#include "utils/ustdlib.h" +#include "stats.h" + +//***************************************************************************** +// +// Sets the value of a tStat structure based on a formatted string input. +// +//***************************************************************************** +void +StatSetVal(tStat *psStat, char *pcInputValue) +{ + if((psStat->eValueType) == STRING) + { + ustrncpy(StatStringVal(*psStat), pcInputValue, MAX_STAT_STRING); + } + else if((psStat->eValueType == INT) || + (psStat->eValueType == HEX)) + { + StatIntVal(*psStat) = ustrtoul(pcInputValue, NULL, 0); + } +} + +//***************************************************************************** +// +// Given a destination buffer and a tStat pointer, this function will produce a +// formatted "request string" that can be used in the Exosite_Write function. +// +//***************************************************************************** +void +StatRequestFormat(tStat *psStat, char *pcRequestBuffer) +{ + if((psStat->eValueType) == STRING) + { + // + // Disable interrupts to avoid changes to the string during the copy + // operation. + // + ROM_IntMasterDisable(); + + usprintf(pcRequestBuffer, "%s=%s", + psStat->pcCloudAlias, + StatStringVal(*psStat)); + + ROM_IntMasterEnable(); + } + else if((psStat->eValueType) == INT) + { + usprintf(pcRequestBuffer, "%s=%d", + psStat->pcCloudAlias, + StatIntVal(*psStat)); + } + else if((psStat->eValueType) == HEX) + { + usprintf(pcRequestBuffer, "%s=0x%x", + psStat->pcCloudAlias, + StatIntVal(*psStat)); + } +} + +//***************************************************************************** +// +// Given a pointer to a tStat and a destination string, this function will +// print the value of the tStat to the string. +// +//***************************************************************************** +void +StatPrintValue(tStat *psStat, char *pcValueString) +{ + char *pcSourceString; + char pcPercentString[3]; + uint32_t ui32CharValue; + uint8_t ui8Index; + // + // Check the type of data that is stored in this psStat variable. + // + if((psStat->eValueType) == STRING) + { + // + // If this is a string, perform a little processing to remove + // percent-encoded characters. First, copy the original string pointer + // for ease of use. + // + pcSourceString = StatStringVal(*psStat); + + + // + // Loop through the characters in the string one by one. + // + ui8Index = 0; + while(*pcSourceString != 0) + { + // + // If the character is a percent sign, calculate the correct + // percent-encoding substitution. + // + if(*pcSourceString == '%') + { + // + // The next two characters should be a hexadecimal + // representation of the actual character that should be + // printed. Convert them to an integer here. + // + ustrncpy(pcPercentString, (pcSourceString + 1), 2); + + pcPercentString[2] = 0; + + ui32CharValue = ustrtoul((pcPercentString), NULL, 16); + + // + // Increment the source pointer past the escaped characters. + // + pcSourceString = pcSourceString + 3; + + // + // Copy the converted value into the destination string. + // + pcValueString[ui8Index] = ui32CharValue; + + } + else + { + // + // If the character was not a percent sign, it can be copied + // directly. + // + pcValueString[ui8Index] = *pcSourceString; + pcSourceString++; + } + + // + // Increment the index. + // + ui8Index++; + } + + pcValueString[ui8Index] = 0; + } + else if((psStat->eValueType) == INT) + { + // + // If this is an integer value, just print the value as text into the + // destination string. + // + usprintf(pcValueString, "%d", StatIntVal(*psStat)); + } +} diff --git a/boards/ek-tm4c1294xl/qs_iot/stats.h b/boards/ek-tm4c1294xl/qs_iot/stats.h new file mode 100644 index 0000000..768d58f --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/stats.h @@ -0,0 +1,117 @@ +//***************************************************************************** +// +// stats.h - Header file for saving cloud-connected statistics +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#ifndef __STATS_H__ +#define __STATS_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Types used for recording general statistics +// +//***************************************************************************** +typedef struct +{ + // + // Name of the item + // + char *pcName; + + // + // Numerical value + // + void *pvValue; + + // + // Exosite alias of the item + // + char *pcCloudAlias; + + // + // Write/Read status of the item + // + enum + { + STRING, + INT, + HEX + } + eValueType; + + // + // Write/Read status of the item + // + enum + { + READ_ONLY, + WRITE_ONLY, + READ_WRITE, + NONE + } + eReadWriteType; +} +tStat; + +//***************************************************************************** +// +// Useful macros for manipulating cloud variables. +// +//***************************************************************************** +#define StatIntVal(sStat) (*((uint32_t *)((sStat).pvValue))) +#define StatStringVal(sStat) ((char *)((sStat).pvValue)) + +#define MAX_STAT_STRING 32 + +//***************************************************************************** +// +// External function protos +// +//***************************************************************************** +extern void StatSetVal(tStat *psStat, char *pcInputValue); +extern void StatRequestFormat(tStat *psStat, char *pcRequestBuffer); +extern void StatPrintValue(tStat *psStat, char *pcValueString); + + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __STATS_H__ + diff --git a/boards/ek-tm4c1294xl/qs_iot/tictactoe.c b/boards/ek-tm4c1294xl/qs_iot/tictactoe.c new file mode 100644 index 0000000..5557487 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/tictactoe.c @@ -0,0 +1,718 @@ +//***************************************************************************** +// +// tictactoe.c - Provides additional functionality for the qs-cloud 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#include +#include +#include "utils/ustdlib.h" +#include "utils/uartstdio.h" +#include "stats.h" +#include "commands.h" +#include "qs_iot.h" +#include "tictactoe.h" + +//***************************************************************************** +// +// Definitions related to the representation of the game state. +// +//***************************************************************************** +#define PLAYER_BIT 0x80000000 // Indicates current player number. +#define REMOTE_PLAYER 0x40000000 // Setting allows remote play. + +//***************************************************************************** +// +// Information relating to the current TicTacToe game state +// +//***************************************************************************** +uint32_t g_ui32BoardState = 0; +uint32_t g_ui32LastState = 0; +uint32_t g_ui32Row = 0; +uint32_t g_ui32Col = 0; +uint32_t g_ui32Player = 0; +uint32_t g_ui32Mode = 0; + +//***************************************************************************** +// +// State variable for keeping track of the game flow +// +//***************************************************************************** +enum +{ + NEW_GAME, + SET_MODE, + PLAY_TURN, + GET_ROW, + GET_COLUMN, + REMOTE_PLAY +} +g_ui32GameState; + +//***************************************************************************** +// +// Input buffer for UART input to the TicTacToe game. +// +//***************************************************************************** +#define GAME_INPUT_SIZE 10 +char g_pcGameInput[GAME_INPUT_SIZE]; + +//***************************************************************************** +// +// Global array to track all possible winning configurations of tic-tac-toe. +// +//***************************************************************************** +uint32_t g_ui32WinConditions[] = +{ + 0x7, + 0x38, + 0x1C0, + 0x49, + 0x92, + 0x124, + 0x111, + 0x54 +}; + +#define NUM_WIN_CONDITIONS (sizeof(g_ui32WinConditions)/sizeof(uint32_t)) + +//***************************************************************************** +// +// Turn prompts a user to play a single turn of tic-tac-toe, and updates the +// global game state variable accordingly. Turn will prevent collisions between +// two separate players on individual squares of the game board, and will +// re-prompt the same player in the event of invalid input. +// +//***************************************************************************** +bool +ProcessTurn(void) +{ + uint32_t ui32Move; + + // + // + // If the chosen coordinates are out of range, try asking for a new set + // of coordinates. + // + if(g_ui32Row > 2 || g_ui32Col > 2) + { + UARTprintf("Invalid, try again.\n"); + return false; + } + + // + // Otherwise, convert the coordinates to the format used by the global + // state variable. + // + ui32Move = 1; + ui32Move = ui32Move << (g_ui32Row * 3); + ui32Move = ui32Move << (g_ui32Col * 1); + + // + // If this space was already occupied, prompt the player for a + // different move. + // + if((ui32Move & g_ui32BoardState) || + ((ui32Move << 16) & g_ui32BoardState)) + { + UARTprintf("Invalid, try again (space occupied).\n"); + return false; + } + else + { + // + // Otherwise, the move is valid. Add it to the global state. + // + g_ui32BoardState |= (ui32Move << (g_ui32Player * 16)); + + // + // Also flip the player bit, to indicate that the next player should + // move. + // + g_ui32BoardState ^= PLAYER_BIT; + g_ui32Player = (g_ui32BoardState & PLAYER_BIT) ? 1 : 0; + + return true; + } +} + +//***************************************************************************** +// +// ShowBoard prints an ASCII representation of the current tic-tac-toe board to +// the UART +// +//***************************************************************************** +void +ShowBoard(void) +{ + uint32_t ui32RowNum; + uint32_t ui32ColNum; + uint32_t ui32MaskX; + uint32_t ui32MaskO; + + // + // Clear the terminal + // + UARTprintf("\033[2J\033[H"); + + UARTprintf("'%c' Player's turn.\n\n", (g_ui32Player ? 'O' : 'X')); + + // + // Print out column numbers + // + UARTprintf(" 0 1 2\n"); + + // + // Loop over rows, starting with zero + // + for(ui32RowNum = 0; ui32RowNum < 3; ui32RowNum++) + { + // + // Print the row number + // + UARTprintf(" %d ", ui32RowNum); + + // + // Loop thorugh the columns + // + for(ui32ColNum = 0; ui32ColNum < 3; ui32ColNum++) + { + // + // Convert the row/column number into the format used by the global + // game-state variable. + // + ui32MaskX = 1 << (ui32RowNum * 3); + ui32MaskX = ui32MaskX << (ui32ColNum * 1); + ui32MaskO = ui32MaskX << 16; + + // + // If a player has a token in this row and column, print the + // corresponding symbol + // + if(g_ui32BoardState & ui32MaskX) + { + UARTprintf("X"); + } + else if(g_ui32BoardState & ui32MaskO) + { + UARTprintf("O"); + } + else + { + UARTprintf(" "); + } + + // + // Print column separators where necessary. + // + if(ui32ColNum < 2) + { + UARTprintf("|"); + } + } + + // + // End this row. + // + UARTprintf("\n", ui32RowNum); + + // + // Add a row separator if necessary. + // + if(ui32RowNum < 2) + { + UARTprintf(" -+-+-\n"); + } + + } + + // + // Print an extra empty line after the last row. + // + UARTprintf("\n"); +} + +//***************************************************************************** +// +// CheckWinner checks the global state variable to see if either player has +// won, or if the game has ended in a tie. Returns a 1 if the game is over, or +// a 0 if the game should continue. +// +//***************************************************************************** +bool +CheckWinner(void) +{ + uint32_t ui32Idx; + uint32_t ui32WinMask0; + uint32_t ui32WinMask1; + uint32_t ui32CatCheck; + uint32_t ui32QuitCheck; + + // + // Loop through the table of win-conditions. + // + for(ui32Idx = 0; ui32Idx < NUM_WIN_CONDITIONS; ui32Idx++) + { + // + // Get a winning board configuration from the global table, and create + // bit masks for each player corresponding to that win condition. + // + ui32WinMask0 = g_ui32WinConditions[ui32Idx]; + ui32WinMask1 = g_ui32WinConditions[ui32Idx] << 16; + + // + // If a player's pieces line up with the winning configuration, count + // this as a win. + // + if((g_ui32BoardState & ui32WinMask0) == ui32WinMask0) + { + UARTprintf("'X' Wins!\n", (g_ui32Player ? 'O' : 'X')); + return 1; + } + else if((g_ui32BoardState & ui32WinMask1) == ui32WinMask1) + { + UARTprintf("'O' Wins!\n", (g_ui32Player ? 'O' : 'X')); + return 1; + } + } + + // + // AND together the position bits for both players to see how many spaces + // are occupied. + // + ui32CatCheck = ((g_ui32BoardState | (g_ui32BoardState >> 16)) & 0x1FF); + + // + // The server will signify a "quit" request by setting all of a single + // player's bits high. Check for one of these states, and print a message + // if it is found. + // + ui32QuitCheck = (g_ui32BoardState & 0x01FF); + if(ui32QuitCheck == 0x01FF) + { + UARTprintf("Game ended by other player.\n"); + return 1; + } + + ui32QuitCheck = (g_ui32BoardState & 0x01FF0000); + if(ui32QuitCheck == 0x01FF0000) + { + UARTprintf("Game ended by other player.\n"); + return 1; + } + + // + // If all spaces are full, and no winner was detected, declare this a tie. + // + if(ui32CatCheck == 0x1FF) + { + UARTprintf("It's a tie.\n"); + return 1; + } + + // + // If the player's pieces do not line up with a known winning + // configuration, return a zero, indicating that no winner was found. + // + return 0; +} + +//***************************************************************************** +// +// SetGameMode reads the user input to determine whether TicTacToe will be +// played locally or online, and whether the local player will play first or +// second. This function will return a 1 if the user-selected mode setting was +// valid, or a 0 if the mode could not be selected. +// +//***************************************************************************** +bool +SetGameMode(void) +{ + uint32_t ui32InputMode; + + // + // If there wasn't any user input, return immediately. + // + if(UARTPeek('\r') == -1) + { + return 0; + } + + // + // Pull the user input from the UART, and convert it to an integer. + // + UARTgets(g_pcGameInput, GAME_INPUT_SIZE); + ui32InputMode = ustrtoul(g_pcGameInput, 0, 0); + + // + // Check to make sure we have a valid mode selection. + // + if(ui32InputMode == 3) + { + // + // If the selected mode is "online, remote player first", set the state + // variables accordingly. + // + g_ui32Mode = ui32InputMode; + + // + // Setting the REMOTE_PLAYER bit will alert the remote user interface + // that they should make the first move. Setting the global variable + // for the old state allows the state machine to detect when the remote + // play has happened. + // + g_ui32LastState = REMOTE_PLAYER; + g_ui32BoardState = REMOTE_PLAYER; + g_sBoardState.eReadWriteType = READ_WRITE; + + return 1; + } + else if((ui32InputMode > 0) && (ui32InputMode < 4)) + { + // + // If the user entered a different valid choice, set up the game mode, + // but don't request a play from the remote interface. + // + g_ui32Mode = ui32InputMode; + g_ui32LastState = 0x0; + g_ui32BoardState = 0x0; + g_sBoardState.eReadWriteType = WRITE_ONLY; + + return 1; + } + else + { + // + // Invalid input. + // + UARTprintf("Invalid input. Try again: "); + + return 0; + } +} + +//***************************************************************************** +// +// This function implements a state machine for the tic-tac-toe gameplay. +// +//***************************************************************************** +bool +AdvanceGameState(void) +{ + // + // If the user has typed a Q, skip straight to ending the game. + // + if((UARTPeek('Q') >= 0) && (UARTPeek('\r') >=0)) + { + // + // Remove the Q from the buffer. + // + UARTgets(g_pcGameInput, GAME_INPUT_SIZE); + + // + // This board state signals a 'quit' condition to the server. + // + g_ui32BoardState = 0x01FF01FF; + g_sBoardState.eReadWriteType = WRITE_ONLY; + + // + // Print a quit message. + // + UARTprintf("\nGame Over.\n"); + return 1; + } + + // + // This switch statement controls the main flow of the game. + // + switch(g_ui32GameState) + { + case NEW_GAME: + { + // + // For a new game, the first step is to determine the game mode. + // Prompt the user for a game mode via UART, and advance the state + // to wait for the user's response. + // + UARTprintf("\033[2J\033[H"); + UARTprintf("New Game!\n"); + UARTprintf(" 1 - play locally\n"); + UARTprintf(" 2 - play online, local user starts\n"); + UARTprintf(" 3 - play online, remote user starts\n"); + UARTprintf(" Q - Enter Q at any time during play to quit.\n\n"); + UARTprintf("Select an option (1-3 or Q): "); + + g_ui32GameState = SET_MODE; + break; + } + + case SET_MODE: + { + // + // Only continue if we have input from the user. + // + if(UARTPeek('\r') != -1) + { + // + // Attempt to use the user's input to set the game mode. + // + if(SetGameMode()) + { + // + // If the user input was valid, show the game board and + // advance the state to start the first turn. + // + ShowBoard(); + g_ui32GameState = PLAY_TURN; + } + } + + break; + } + + case PLAY_TURN: + { + // + // Check to see if we need input from the local user. This will + // always be true for a local game, and should be true for only a + // single player's turns for an online game. + // + if(!(g_ui32BoardState & REMOTE_PLAYER)) + { + // + // If we're playing a local game, prompt for a row number and + // advance the state to wait for a response. + // + UARTprintf("Enter Row: "); + g_ui32GameState = GET_ROW; + } + else + { + // + // If the local player is not supposed to move for this turn, + // print a message to let the player know that we are waiting + // on input from a remote player. + // + UARTprintf("Waiting for remote player....\n"); + g_ui32GameState = REMOTE_PLAY; + } + + break; + } + + case GET_ROW: + { + // + // Only continue if we have input from the user. + // + if(UARTPeek('\r') != -1) + { + // + // Convert the user's input to an integer, and store it as the + // new row number. + // + UARTgets(g_pcGameInput, GAME_INPUT_SIZE); + g_ui32Row = ustrtoul(g_pcGameInput, 0, 0); + + // + // Prompt for a column number, and advance the state to wait + // for a response. + // + UARTprintf("Enter Column: "); + g_ui32GameState = GET_COLUMN; + } + + break; + } + + case GET_COLUMN: + { + // + // Only continue if we have input from the user. + // + if(UARTPeek('\r') != -1) + { + // + // Convert the user's input to an integer, and store it as the + // new column number. + // + UARTgets(g_pcGameInput, GAME_INPUT_SIZE); + g_ui32Col = ustrtoul(g_pcGameInput, 0, 0); + + // + // Try to process the recorded row and column numbers as a + // "move" for the current player. + // + if(ProcessTurn()) + { + // + // The user's input was successfully processed and added to + // the game state. Show the board with the new move + // applied. + // + ShowBoard(); + + // + // Check to see if this was a winning move. + // + if(CheckWinner()) + { + // + // If so, return a 1 to signal the end of the game. + // + return 1; + } + else + { + + // + // Otherwise, the game must go on. Check to see if we + // have a remote player. + // + if(g_ui32Mode != 1) + { + // + // We have a remote player, so toggle the bit to + // signal that the remote player should take their + // turn. + // + g_ui32BoardState ^= REMOTE_PLAYER; + } + + // + // Remember the board state, so we can tell when it + // gets changed. + // + g_ui32LastState = g_ui32BoardState; + + // + // Set the board state to sync with the server. + // + g_sBoardState.eReadWriteType = READ_WRITE; + + // + // Finally, set the game state for the next turn. + // + g_ui32GameState = PLAY_TURN; + } + } + else + { + // + // Something was wrong with the user's input. Try prompting + // them again. + // + UARTprintf("Enter Row: "); + g_ui32GameState = GET_ROW; + } + } + + break; + } + + case REMOTE_PLAY: + { + // + // If we are waiting on a remote player, check to see if the board + // state variable has changed. + // + if(g_ui32BoardState != g_ui32LastState) + { + // + // Set the board state to stop reading from the server. + // + g_sBoardState.eReadWriteType = WRITE_ONLY; + + // + // Record the new state, so we know that it has already been + // seen once. This is important to prevent an infinite loop if + // the server doesn't clear the "REMOTE_PLAYER" bit. + // + g_ui32LastState = g_ui32BoardState; + + // + // Make sure that the player variable is up-to-date. + // + g_ui32Player = (g_ui32BoardState & PLAYER_BIT) ? 1 : 0; + + // + // If the state has changed, assume that the remote player has + // made their move. + // + ShowBoard(); + + // + // Check to see if this was a winning move. + // + if(CheckWinner()) + { + // + // If so, return a 1 to signal the end of the game. + // + return 1; + } + else + { + // + // Otherwise, update the last valid state, advance to the + // next turn. + // + g_ui32GameState = PLAY_TURN; + } + } + + break; + } + } + + // + // The actions for the current state have been processed, and the game has + // not met an ending condition. Return a zero to indicate that the game is + // not yet finished. + // + return 0; +} + +//***************************************************************************** +// +// Clears the game state, and prepares the global variables to start a new game +// of tic-tac-toe +// +//***************************************************************************** +void +GameInit(void) +{ + // + // Set the global board state tStat variable to WRITE_ONLY, to make sure + // that it doesn't get overwritten by content from the server side. + // + g_sBoardState.eReadWriteType = WRITE_ONLY; + + // + // Empty the board, set the player value to zero (for 'X'), and set the + // main state machine to start a new game on the next call to + // AdvanceGameState(). + // + g_ui32BoardState = 0; + g_ui32Player = 0; + g_ui32GameState = NEW_GAME; +} + diff --git a/boards/ek-tm4c1294xl/qs_iot/tictactoe.h b/boards/ek-tm4c1294xl/qs_iot/tictactoe.h new file mode 100644 index 0000000..4e423b5 --- /dev/null +++ b/boards/ek-tm4c1294xl/qs_iot/tictactoe.h @@ -0,0 +1,64 @@ +//***************************************************************************** +// +// tictactoe.h - Provides definitions and prototypes for tictactoe.c +// +// 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 EK-TM4C1294XL Firmware Package. +// +//***************************************************************************** + +#ifndef __TICTACTOE_H__ +#define __TICTACTOE_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Global variables +// +//***************************************************************************** +extern uint32_t g_ui32BoardState; +extern tStat g_sBoardState; + +//***************************************************************************** +// +// Function prototypes +// +//***************************************************************************** +extern bool AdvanceGameState(void); +extern void GameInit(void); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __TICTACTOE_H__ -- cgit v1.3.1