Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial C12832 EndpointMain-rfid EthernetInterface Logger StatusReporter-df2014 mbed-rtos mbed
Fork of df-2014-workshop-rfid-case-generator-k64f by
main.cpp@27:9bb430dd6c07, 2014-09-07 (annotated)
- Committer:
- ansond
- Date:
- Sun Sep 07 22:19:30 2014 +0000
- Revision:
- 27:9bb430dd6c07
- Parent:
- 25:89a505a8e61c
- Child:
- 28:892a6668365f
changed main invocation to threaded for K64F
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ansond | 0:df2aa79c64f2 | 1 | /* Copyright C2014 ARM, MIT License |
| ansond | 0:df2aa79c64f2 | 2 | * |
| ansond | 0:df2aa79c64f2 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| ansond | 0:df2aa79c64f2 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
| ansond | 0:df2aa79c64f2 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| ansond | 0:df2aa79c64f2 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| ansond | 0:df2aa79c64f2 | 7 | * furnished to do so, subject to the following conditions: |
| ansond | 0:df2aa79c64f2 | 8 | * |
| ansond | 0:df2aa79c64f2 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| ansond | 0:df2aa79c64f2 | 10 | * substantial portions of the Software. |
| ansond | 0:df2aa79c64f2 | 11 | * |
| ansond | 0:df2aa79c64f2 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| ansond | 0:df2aa79c64f2 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| ansond | 0:df2aa79c64f2 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| ansond | 0:df2aa79c64f2 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| ansond | 0:df2aa79c64f2 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| ansond | 0:df2aa79c64f2 | 17 | */ |
| ansond | 0:df2aa79c64f2 | 18 | |
| ansond | 13:2561e3855a81 | 19 | // StatusReporter |
| ansond | 13:2561e3855a81 | 20 | #include "StatusReporter.h" |
| ansond | 22:1b9e29933ab3 | 21 | |
| ansond | 22:1b9e29933ab3 | 22 | // appboard LCD Panel |
| ansond | 25:89a505a8e61c | 23 | #if _NXP_PLATFORM |
| ansond | 22:1b9e29933ab3 | 24 | #include "C12832_lcd.h" |
| ansond | 25:89a505a8e61c | 25 | C12832_LCD lcd; |
| ansond | 25:89a505a8e61c | 26 | #endif |
| ansond | 25:89a505a8e61c | 27 | #if _UBLOX_PLATFORM |
| ansond | 25:89a505a8e61c | 28 | #include "C12832.h" |
| ansond | 25:89a505a8e61c | 29 | C12832 lcd(D11, D13, D12, D7, D10); |
| ansond | 22:1b9e29933ab3 | 30 | #endif |
| ansond | 0:df2aa79c64f2 | 31 | |
| ansond | 0:df2aa79c64f2 | 32 | // our Serial port |
| ansond | 0:df2aa79c64f2 | 33 | #include "Serial.h" |
| ansond | 0:df2aa79c64f2 | 34 | Serial pc(USBTX, USBRX); |
| ansond | 0:df2aa79c64f2 | 35 | |
| ansond | 3:03108e424931 | 36 | // Ethernet |
| ansond | 3:03108e424931 | 37 | #include "EthernetInterface.h" |
| ansond | 3:03108e424931 | 38 | EthernetInterface ethernet; |
| ansond | 3:03108e424931 | 39 | |
| ansond | 20:f548e2de5b0b | 40 | // HTTP |
| ansond | 20:f548e2de5b0b | 41 | #include "HTTPClient.h" |
| ansond | 20:f548e2de5b0b | 42 | HTTPClient http; |
| ansond | 20:f548e2de5b0b | 43 | |
| ansond | 6:427c387b10e7 | 44 | // HARD RESET |
| ansond | 6:427c387b10e7 | 45 | extern "C" void HardFault_Handler() { NVIC_SystemReset(); } |
| ansond | 6:427c387b10e7 | 46 | |
| ansond | 27:9bb430dd6c07 | 47 | // WEAK Function for debugging |
| ansond | 27:9bb430dd6c07 | 48 | extern "C" void mbed_mac_address(char * mac) { |
| ansond | 27:9bb430dd6c07 | 49 | mac[0] = 0x44; |
| ansond | 27:9bb430dd6c07 | 50 | mac[1] = 0x45; |
| ansond | 27:9bb430dd6c07 | 51 | mac[2] = 0x56; |
| ansond | 27:9bb430dd6c07 | 52 | mac[3] = 0x67; |
| ansond | 27:9bb430dd6c07 | 53 | mac[4] = 0x78; |
| ansond | 27:9bb430dd6c07 | 54 | mac[5] = 0x89; |
| ansond | 27:9bb430dd6c07 | 55 | pc.printf("MAC " ); |
| ansond | 27:9bb430dd6c07 | 56 | for(int i=0;i<6;++i) pc.printf(":%.2x",mac[i]); |
| ansond | 27:9bb430dd6c07 | 57 | pc.printf("\r\n"); |
| ansond | 27:9bb430dd6c07 | 58 | } |
| ansond | 27:9bb430dd6c07 | 59 | |
| ansond | 27:9bb430dd6c07 | 60 | // Main Task... |
| ansond | 27:9bb430dd6c07 | 61 | void mainTask(void const *v) { |
| ansond | 22:1b9e29933ab3 | 62 | // create our object instances |
| ansond | 22:1b9e29933ab3 | 63 | #if _NXP_PLATFORM || _UBLOX_PLATFORM |
| ansond | 13:2561e3855a81 | 64 | ErrorHandler logger(&pc,&lcd); |
| ansond | 22:1b9e29933ab3 | 65 | #endif |
| ansond | 22:1b9e29933ab3 | 66 | #if _K64F_PLATFORM |
| ansond | 22:1b9e29933ab3 | 67 | ErrorHandler logger(&pc,NULL); |
| ansond | 22:1b9e29933ab3 | 68 | #endif |
| ansond | 0:df2aa79c64f2 | 69 | |
| ansond | 0:df2aa79c64f2 | 70 | // announce |
| ansond | 13:2561e3855a81 | 71 | logger.log("ARM/DreamForce 2014 mbed Status Reporter v%s",APP_VERSION); |
| ansond | 19:341ce6a43a84 | 72 | logger.turnLEDBlue(); |
| ansond | 0:df2aa79c64f2 | 73 | |
| ansond | 3:03108e424931 | 74 | // initialize Ethernet |
| ansond | 3:03108e424931 | 75 | logger.log("Initializing Ethernet..."); |
| ansond | 3:03108e424931 | 76 | ethernet.init(); |
| ansond | 0:df2aa79c64f2 | 77 | |
| ansond | 3:03108e424931 | 78 | // get a DHCP address and bring the network interface up |
| ansond | 3:03108e424931 | 79 | logger.log("Getting IP Address..."); |
| ansond | 19:341ce6a43a84 | 80 | logger.turnLEDOrange(); |
| ansond | 3:03108e424931 | 81 | if (ethernet.connect() == 0) { |
| ansond | 3:03108e424931 | 82 | // log our IP address (DHCP) |
| ansond | 3:03108e424931 | 83 | logger.log("IP Address: %s",ethernet.getIPAddress()); |
| ansond | 3:03108e424931 | 84 | |
| ansond | 13:2561e3855a81 | 85 | // create the StatusReporter |
| ansond | 20:f548e2de5b0b | 86 | StatusReporter status_reporter(&logger,(void *)&http); |
| ansond | 3:03108e424931 | 87 | |
| ansond | 8:fefcecb66463 | 88 | // entering main loop |
| ansond | 8:fefcecb66463 | 89 | logger.log("Entering Main Loop...\r\nScanning..."); |
| ansond | 19:341ce6a43a84 | 90 | logger.turnLEDGreen(); |
| ansond | 8:fefcecb66463 | 91 | |
| ansond | 3:03108e424931 | 92 | // Enter the main loop |
| ansond | 3:03108e424931 | 93 | while(true) { |
| ansond | 13:2561e3855a81 | 94 | // check and report on status updates |
| ansond | 13:2561e3855a81 | 95 | status_reporter.checkAndReportOnStatus(); |
| ansond | 3:03108e424931 | 96 | |
| ansond | 3:03108e424931 | 97 | // wait a bit and look again |
| ansond | 3:03108e424931 | 98 | wait_ms(WAIT_TIME_MS); |
| ansond | 3:03108e424931 | 99 | } |
| ansond | 3:03108e424931 | 100 | } |
| ansond | 3:03108e424931 | 101 | else { |
| ansond | 3:03108e424931 | 102 | logger.log("No Network... Exiting..."); |
| ansond | 19:341ce6a43a84 | 103 | logger.turnLEDRed(); |
| ansond | 6:427c387b10e7 | 104 | exit(1); |
| ansond | 3:03108e424931 | 105 | } |
| ansond | 3:03108e424931 | 106 | |
| ansond | 3:03108e424931 | 107 | // disconnect |
| ansond | 4:46459ed734f3 | 108 | logger.log("Disconnecting..."); |
| ansond | 19:341ce6a43a84 | 109 | logger.turnLEDOrange(); |
| ansond | 3:03108e424931 | 110 | ethernet.disconnect(); |
| ansond | 4:46459ed734f3 | 111 | |
| ansond | 4:46459ed734f3 | 112 | // Exit |
| ansond | 6:427c387b10e7 | 113 | logger.log("Exiting..."); |
| ansond | 19:341ce6a43a84 | 114 | logger.turnLEDBlue(); |
| ansond | 6:427c387b10e7 | 115 | exit(1); |
| ansond | 27:9bb430dd6c07 | 116 | } |
| ansond | 27:9bb430dd6c07 | 117 | |
| ansond | 27:9bb430dd6c07 | 118 | // main entry |
| ansond | 27:9bb430dd6c07 | 119 | int main() { |
| ansond | 27:9bb430dd6c07 | 120 | #if _K64F_PLATFORM |
| ansond | 27:9bb430dd6c07 | 121 | Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE); |
| ansond | 27:9bb430dd6c07 | 122 | while (true) Thread::wait(10*WAIT_TIME_MS); |
| ansond | 27:9bb430dd6c07 | 123 | #else |
| ansond | 27:9bb430dd6c07 | 124 | mainTask(NULL); |
| ansond | 27:9bb430dd6c07 | 125 | #endif |
| ansond | 0:df2aa79c64f2 | 126 | } |

