Library for inclusion of main.cpp -forked

Dependents:   df-2014-workshop-rfid-case-generator-k64f df-2014-rfid-case-gen-k64f-complete df-2014-rfid-case-gen-k64f-exercise

Fork of EndpointMain by Doug Anson

Committer:
ansond
Date:
Wed Sep 17 16:33:39 2014 +0000
Revision:
1:8364052fbe84
Parent:
0:8f99b3f2c3a8
Child:
2:55b1877a3a14
added mac address for keil debugging

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:8f99b3f2c3a8 1 /* Copyright C2014 ARM, MIT License
ansond 0:8f99b3f2c3a8 2 *
ansond 0:8f99b3f2c3a8 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:8f99b3f2c3a8 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:8f99b3f2c3a8 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:8f99b3f2c3a8 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:8f99b3f2c3a8 7 * furnished to do so, subject to the following conditions:
ansond 0:8f99b3f2c3a8 8 *
ansond 0:8f99b3f2c3a8 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:8f99b3f2c3a8 10 * substantial portions of the Software.
ansond 0:8f99b3f2c3a8 11 *
ansond 0:8f99b3f2c3a8 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:8f99b3f2c3a8 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:8f99b3f2c3a8 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:8f99b3f2c3a8 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:8f99b3f2c3a8 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:8f99b3f2c3a8 17 */
ansond 0:8f99b3f2c3a8 18
ansond 0:8f99b3f2c3a8 19 // StatusReporter
ansond 0:8f99b3f2c3a8 20 #include "StatusReporter.h"
ansond 0:8f99b3f2c3a8 21
ansond 0:8f99b3f2c3a8 22 // appboard LCD Panel
ansond 0:8f99b3f2c3a8 23 #if _NXP_PLATFORM
ansond 0:8f99b3f2c3a8 24 #include "C12832_lcd.h"
ansond 0:8f99b3f2c3a8 25 C12832_LCD lcd;
ansond 0:8f99b3f2c3a8 26 #endif
ansond 0:8f99b3f2c3a8 27 #if _UBLOX_PLATFORM
ansond 0:8f99b3f2c3a8 28 #include "C12832.h"
ansond 0:8f99b3f2c3a8 29 C12832 lcd(D11, D13, D12, D7, D10);
ansond 0:8f99b3f2c3a8 30 #endif
ansond 0:8f99b3f2c3a8 31
ansond 0:8f99b3f2c3a8 32 // our Serial port
ansond 0:8f99b3f2c3a8 33 #include "BufferedSerial.h"
ansond 0:8f99b3f2c3a8 34 BufferedSerial pc(USBTX, USBRX);
ansond 0:8f99b3f2c3a8 35
ansond 0:8f99b3f2c3a8 36 // Ethernet
ansond 0:8f99b3f2c3a8 37 #include "EthernetInterface.h"
ansond 0:8f99b3f2c3a8 38 EthernetInterface ethernet;
ansond 0:8f99b3f2c3a8 39
ansond 0:8f99b3f2c3a8 40 // HTTP
ansond 0:8f99b3f2c3a8 41 #include "HTTPClient.h"
ansond 0:8f99b3f2c3a8 42 HTTPClient http;
ansond 0:8f99b3f2c3a8 43
ansond 0:8f99b3f2c3a8 44 // HARD RESET
ansond 1:8364052fbe84 45 extern "C" void HardFault_Handler() { NVIC_SystemReset(); }
ansond 0:8f99b3f2c3a8 46
ansond 1:8364052fbe84 47 #ifdef MAC_ADDRESS
ansond 1:8364052fbe84 48 char mac[6] = {MAC_ADDRESS};
ansond 1:8364052fbe84 49 extern "C" void mbed_mac_address(char *s) { for(int i=0;i<6;++i) s[i] = mac[i]; }
ansond 1:8364052fbe84 50 char fmt_mac[RESOURCE_VALUE_LEN+1];
ansond 1:8364052fbe84 51 #endif
ansond 1:8364052fbe84 52
ansond 0:8f99b3f2c3a8 53 // Main Task...
ansond 0:8f99b3f2c3a8 54 void mainTask(void const *v) {
ansond 0:8f99b3f2c3a8 55 // create our object instances
ansond 0:8f99b3f2c3a8 56 #if _NXP_PLATFORM || _UBLOX_PLATFORM
ansond 0:8f99b3f2c3a8 57 ErrorHandler logger(&pc,&lcd);
ansond 0:8f99b3f2c3a8 58 #endif
ansond 0:8f99b3f2c3a8 59 #if _K64F_PLATFORM
ansond 0:8f99b3f2c3a8 60 ErrorHandler logger(&pc,NULL);
ansond 0:8f99b3f2c3a8 61 #endif
ansond 0:8f99b3f2c3a8 62
ansond 0:8f99b3f2c3a8 63 // announce
ansond 0:8f99b3f2c3a8 64 logger.log("ARM/DreamForce 2014 mbed Status Reporter v%s",APP_VERSION);
ansond 0:8f99b3f2c3a8 65 logger.turnLEDBlue();
ansond 0:8f99b3f2c3a8 66
ansond 0:8f99b3f2c3a8 67 // initialize Ethernet
ansond 0:8f99b3f2c3a8 68 logger.log("Initializing Ethernet...");
ansond 0:8f99b3f2c3a8 69 ethernet.init();
ansond 0:8f99b3f2c3a8 70
ansond 0:8f99b3f2c3a8 71 // get a DHCP address and bring the network interface up
ansond 0:8f99b3f2c3a8 72 logger.log("Getting IP Address...");
ansond 0:8f99b3f2c3a8 73 logger.turnLEDOrange();
ansond 0:8f99b3f2c3a8 74 if (ethernet.connect() == 0) {
ansond 0:8f99b3f2c3a8 75 // log our IP address (DHCP)
ansond 0:8f99b3f2c3a8 76 logger.log("IP Address: %s",ethernet.getIPAddress());
ansond 0:8f99b3f2c3a8 77
ansond 0:8f99b3f2c3a8 78 // create the StatusReporter
ansond 0:8f99b3f2c3a8 79 StatusReporter status_reporter(&logger,(void *)&http);
ansond 0:8f99b3f2c3a8 80
ansond 0:8f99b3f2c3a8 81 // entering main loop
ansond 0:8f99b3f2c3a8 82 logger.log("Entering Main Loop...\r\nScanning...");
ansond 0:8f99b3f2c3a8 83 logger.turnLEDGreen();
ansond 0:8f99b3f2c3a8 84
ansond 0:8f99b3f2c3a8 85 // Enter the main loop
ansond 0:8f99b3f2c3a8 86 while(true) {
ansond 0:8f99b3f2c3a8 87 // check and report on status updates
ansond 0:8f99b3f2c3a8 88 status_reporter.checkAndReportOnStatus();
ansond 0:8f99b3f2c3a8 89 }
ansond 0:8f99b3f2c3a8 90 }
ansond 0:8f99b3f2c3a8 91 else {
ansond 0:8f99b3f2c3a8 92 logger.log("No Network... Exiting...");
ansond 0:8f99b3f2c3a8 93 logger.turnLEDRed();
ansond 0:8f99b3f2c3a8 94 exit(1);
ansond 0:8f99b3f2c3a8 95 }
ansond 0:8f99b3f2c3a8 96
ansond 0:8f99b3f2c3a8 97 // disconnect
ansond 0:8f99b3f2c3a8 98 logger.log("Disconnecting...");
ansond 0:8f99b3f2c3a8 99 logger.turnLEDOrange();
ansond 0:8f99b3f2c3a8 100 ethernet.disconnect();
ansond 0:8f99b3f2c3a8 101
ansond 0:8f99b3f2c3a8 102 // Exit
ansond 0:8f99b3f2c3a8 103 logger.log("Exiting...");
ansond 0:8f99b3f2c3a8 104 logger.turnLEDBlue();
ansond 0:8f99b3f2c3a8 105 exit(1);
ansond 0:8f99b3f2c3a8 106 }
ansond 0:8f99b3f2c3a8 107
ansond 0:8f99b3f2c3a8 108 // main entry
ansond 0:8f99b3f2c3a8 109 int main() {
ansond 0:8f99b3f2c3a8 110 #if _K64F_PLATFORM
ansond 0:8f99b3f2c3a8 111 Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE);
ansond 0:8f99b3f2c3a8 112 while (true) {
ansond 0:8f99b3f2c3a8 113 Thread::wait(10*WAIT_TIME_MS);
ansond 0:8f99b3f2c3a8 114 }
ansond 0:8f99b3f2c3a8 115 #else
ansond 0:8f99b3f2c3a8 116 mainTask(NULL);
ansond 0:8f99b3f2c3a8 117 #endif
ansond 0:8f99b3f2c3a8 118 }