Library for inclusion of main.cpp
main.cpp@2:5cf9c9324f85, 2014-09-17 (annotated)
- Committer:
- ansond
- Date:
- Wed Sep 17 16:37:12 2014 +0000
- Revision:
- 2:5cf9c9324f85
- Parent:
- 0:8f99b3f2c3a8
- Child:
- 4:582f7ce2f930
initial checkin;
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:5cf9c9324f85 | 19 | #include "Definitions.h" |
ansond | 2:5cf9c9324f85 | 20 | #include "ErrorHandler.h" |
ansond | 2:5cf9c9324f85 | 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 | 2:5cf9c9324f85 | 45 | extern "C" void HardFault_Handler() { NVIC_SystemReset(); } |
ansond | 0:8f99b3f2c3a8 | 46 | |
ansond | 2:5cf9c9324f85 | 47 | #ifdef MAC_ADDRESS |
ansond | 2:5cf9c9324f85 | 48 | char mac[6] = {MAC_ADDRESS}; |
ansond | 2:5cf9c9324f85 | 49 | extern "C" void mbed_mac_address(char *s) { for(int i=0;i<6;++i) s[i] = mac[i]; } |
ansond | 2:5cf9c9324f85 | 50 | char fmt_mac[RESOURCE_VALUE_LEN+1]; |
ansond | 2:5cf9c9324f85 | 51 | #endif |
ansond | 2:5cf9c9324f85 | 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 | 2:5cf9c9324f85 | 64 | logger.log("ARM/DreamForce 2014 Hello salesforce 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 | 2:5cf9c9324f85 | 78 | // allocate something here... |
ansond | 0:8f99b3f2c3a8 | 79 | |
ansond | 0:8f99b3f2c3a8 | 80 | // entering main loop |
ansond | 2:5cf9c9324f85 | 81 | logger.log("Entering Main Loop...\r\nStarting main loop..."); |
ansond | 0:8f99b3f2c3a8 | 82 | logger.turnLEDGreen(); |
ansond | 0:8f99b3f2c3a8 | 83 | |
ansond | 0:8f99b3f2c3a8 | 84 | // Enter the main loop |
ansond | 0:8f99b3f2c3a8 | 85 | while(true) { |
ansond | 2:5cf9c9324f85 | 86 | // Do work with something here... |
ansond | 2:5cf9c9324f85 | 87 | Thread::wait(10*WAIT_TIME_MS);; |
ansond | 0:8f99b3f2c3a8 | 88 | } |
ansond | 0:8f99b3f2c3a8 | 89 | } |
ansond | 0:8f99b3f2c3a8 | 90 | else { |
ansond | 0:8f99b3f2c3a8 | 91 | logger.log("No Network... Exiting..."); |
ansond | 0:8f99b3f2c3a8 | 92 | logger.turnLEDRed(); |
ansond | 0:8f99b3f2c3a8 | 93 | exit(1); |
ansond | 0:8f99b3f2c3a8 | 94 | } |
ansond | 0:8f99b3f2c3a8 | 95 | |
ansond | 0:8f99b3f2c3a8 | 96 | // disconnect |
ansond | 0:8f99b3f2c3a8 | 97 | logger.log("Disconnecting..."); |
ansond | 0:8f99b3f2c3a8 | 98 | logger.turnLEDOrange(); |
ansond | 0:8f99b3f2c3a8 | 99 | ethernet.disconnect(); |
ansond | 0:8f99b3f2c3a8 | 100 | |
ansond | 0:8f99b3f2c3a8 | 101 | // Exit |
ansond | 0:8f99b3f2c3a8 | 102 | logger.log("Exiting..."); |
ansond | 0:8f99b3f2c3a8 | 103 | logger.turnLEDBlue(); |
ansond | 0:8f99b3f2c3a8 | 104 | exit(1); |
ansond | 0:8f99b3f2c3a8 | 105 | } |
ansond | 0:8f99b3f2c3a8 | 106 | |
ansond | 0:8f99b3f2c3a8 | 107 | // main entry |
ansond | 0:8f99b3f2c3a8 | 108 | int main() { |
ansond | 0:8f99b3f2c3a8 | 109 | #if _K64F_PLATFORM |
ansond | 0:8f99b3f2c3a8 | 110 | Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE); |
ansond | 0:8f99b3f2c3a8 | 111 | while (true) { |
ansond | 0:8f99b3f2c3a8 | 112 | Thread::wait(10*WAIT_TIME_MS); |
ansond | 0:8f99b3f2c3a8 | 113 | } |
ansond | 0:8f99b3f2c3a8 | 114 | #else |
ansond | 0:8f99b3f2c3a8 | 115 | mainTask(NULL); |
ansond | 0:8f99b3f2c3a8 | 116 | #endif |
ansond | 0:8f99b3f2c3a8 | 117 | } |