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: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
src/main.cpp@58:a4422d19b2ea, 2016-09-14 (annotated)
- Committer:
- davidjhoward
- Date:
- Wed Sep 14 18:54:23 2016 +0000
- Revision:
- 58:a4422d19b2ea
- Parent:
- 57:5f18ae91c7c7
- Child:
- 59:c68c5bc9d077
adding EEPROM drivers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 0:65cfa4873284 | 1 | /****************************************************************************** |
jmarkel44 | 3:8ea4db957749 | 2 | * |
jmarkel44 | 0:65cfa4873284 | 3 | * File: main.cpp |
jmarkel44 | 0:65cfa4873284 | 4 | * Desciption: main ICE driver routine |
jmarkel44 | 0:65cfa4873284 | 5 | * |
jmarkel44 | 0:65cfa4873284 | 6 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 7 | #include "mbed.h" |
jmarkel44 | 0:65cfa4873284 | 8 | #include "rtos.h" |
jmarkel44 | 0:65cfa4873284 | 9 | #include <stdio.h> |
jmarkel44 | 0:65cfa4873284 | 10 | #include "mDot.h" |
jmarkel44 | 0:65cfa4873284 | 11 | #include "global.h" |
jmarkel44 | 0:65cfa4873284 | 12 | #include "ConfigurationHandler.h" |
jmarkel44 | 0:65cfa4873284 | 13 | #include "AnalyticsLogger.h" |
jmarkel44 | 0:65cfa4873284 | 14 | #include "ModbusMaster.h" |
jmarkel44 | 0:65cfa4873284 | 15 | #include "BLEDataHandler.h" |
davidjhoward | 16:7f6599312962 | 16 | #include "LoRaInit.h" |
jmarkel44 | 20:653923c2f37a | 17 | #include "ControlTask.h" |
jmarkel44 | 48:1c7861d80d16 | 18 | #include "OutputTask.h" |
jmarkel44 | 20:653923c2f37a | 19 | #include "CloudDataHandler.h" |
jmarkel44 | 0:65cfa4873284 | 20 | |
jmarkel44 | 0:65cfa4873284 | 21 | // main thread identifier (for signaling) |
jmarkel44 | 0:65cfa4873284 | 22 | osThreadId mainThreadId = NULL; |
jmarkel44 | 0:65cfa4873284 | 23 | int sig_continue = 0x1; |
jmarkel44 | 0:65cfa4873284 | 24 | |
jmarkel44 | 0:65cfa4873284 | 25 | // data handler to configuration hanlder mailbox |
jmarkel44 | 0:65cfa4873284 | 26 | Mail<Message_t, 16> MailBox; |
davidjhoward | 31:4b1587034318 | 27 | Mail<Message_t, 16> ModbusMasterMailBox; |
jmarkel44 | 51:66b820f203a5 | 28 | Mail<OutputControlReq_t, 16> OutputMasterMailBox; |
davidjhoward | 58:a4422d19b2ea | 29 | Mail<AnalyticsLoggerReq_t, 16> AnalyticsLoggerMailBox; |
jmarkel44 | 0:65cfa4873284 | 30 | |
jmarkel44 | 0:65cfa4873284 | 31 | // local function prototypes |
jmarkel44 | 0:65cfa4873284 | 32 | static void banner(void); |
jmarkel44 | 0:65cfa4873284 | 33 | |
davidjhoward | 7:c0c03193612d | 34 | // for file system access outside of main() |
jmarkel44 | 13:c80c283f9db2 | 35 | mDot *GLOBAL_mdot; |
jmarkel44 | 13:c80c283f9db2 | 36 | |
jmarkel44 | 34:f345fdec711d | 37 | Thread *GLOBAL_analyticsLogger_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 38 | Thread *GLOBAL_modbusMaster_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 39 | Thread *GLOBAL_BLE_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 40 | Thread *GLOBAL_CDH_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 41 | Thread *GLOBAL_configHandler_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 42 | Thread *GLOBAL_controlTask_thread = NULL; |
jmarkel44 | 48:1c7861d80d16 | 43 | Thread *GLOBAL_outputTask_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 44 | |
jmarkel44 | 13:c80c283f9db2 | 45 | // store modbus register information |
jmarkel44 | 13:c80c283f9db2 | 46 | std::map<std::string,ModbusRegister> ModbusRegisterMap; |
davidjhoward | 7:c0c03193612d | 47 | |
davidjhoward | 58:a4422d19b2ea | 48 | I2C i2c_instance(I2C_SDA, I2C_SCL); |
davidjhoward | 58:a4422d19b2ea | 49 | I2C* i2c; |
davidjhoward | 58:a4422d19b2ea | 50 | |
jmarkel44 | 0:65cfa4873284 | 51 | /***************************************************************************** |
jmarkel44 | 0:65cfa4873284 | 52 | * Function: banner() |
jmarkel44 | 0:65cfa4873284 | 53 | * Description: Display the application boot banner |
jmarkel44 | 0:65cfa4873284 | 54 | * |
jmarkel44 | 0:65cfa4873284 | 55 | * @param none |
jmarkel44 | 0:65cfa4873284 | 56 | * @return none |
jmarkel44 | 0:65cfa4873284 | 57 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 58 | static void banner( void ) |
jmarkel44 | 0:65cfa4873284 | 59 | { |
jmarkel44 | 35:6235ef67faa1 | 60 | printf("\n\n\r\nWelcome to Project: ICE v0.0.35\n"); |
jmarkel44 | 0:65cfa4873284 | 61 | printf("\rThe Intelligent Connected Experience\n"); |
jmarkel44 | 0:65cfa4873284 | 62 | printf("\rCopyright 2016 Nalco Water, an Ecolab Company\n"); |
jmarkel44 | 0:65cfa4873284 | 63 | |
jmarkel44 | 0:65cfa4873284 | 64 | printf("\r\t _____ _____ ______ \n"); |
jmarkel44 | 0:65cfa4873284 | 65 | printf("\r\t |_ _| / ____| | ____|\n"); |
jmarkel44 | 0:65cfa4873284 | 66 | printf("\r\t | | | | | |__ \n"); |
jmarkel44 | 0:65cfa4873284 | 67 | printf("\r\t | | | | | __| \n"); |
jmarkel44 | 0:65cfa4873284 | 68 | printf("\r\t _| |_ | |____ | |____ \n"); |
jmarkel44 | 0:65cfa4873284 | 69 | printf("\r\t |_____| \\_____| |______|\n"); |
jmarkel44 | 0:65cfa4873284 | 70 | |
jmarkel44 | 0:65cfa4873284 | 71 | printf("\r\n\r\n\r\r\n"); |
jmarkel44 | 0:65cfa4873284 | 72 | } |
jmarkel44 | 0:65cfa4873284 | 73 | |
jmarkel44 | 0:65cfa4873284 | 74 | /***************************************************************************** |
jmarkel44 | 0:65cfa4873284 | 75 | * Function: banner() |
jmarkel44 | 0:65cfa4873284 | 76 | * Description: Display the application boot banner |
jmarkel44 | 0:65cfa4873284 | 77 | * |
jmarkel44 | 0:65cfa4873284 | 78 | * @param none |
jmarkel44 | 0:65cfa4873284 | 79 | * @return none |
jmarkel44 | 0:65cfa4873284 | 80 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 81 | int main( void ) |
jmarkel44 | 0:65cfa4873284 | 82 | { |
jmarkel44 | 0:65cfa4873284 | 83 | mDot *dot; |
davidjhoward | 16:7f6599312962 | 84 | |
jmarkel44 | 48:1c7861d80d16 | 85 | // singleton object instatiation |
davidjhoward | 21:85c69494c0ff | 86 | GLOBAL_mdot = dot = mDot::getInstance(); |
davidjhoward | 21:85c69494c0ff | 87 | mDotRadioInit( dot ); |
davidjhoward | 58:a4422d19b2ea | 88 | |
davidjhoward | 58:a4422d19b2ea | 89 | i2c = &i2c_instance; |
davidjhoward | 21:85c69494c0ff | 90 | |
jmarkel44 | 13:c80c283f9db2 | 91 | // for signaling from the configuration handler |
jmarkel44 | 0:65cfa4873284 | 92 | mainThreadId = osThreadGetId(); |
jmarkel44 | 3:8ea4db957749 | 93 | |
jmarkel44 | 0:65cfa4873284 | 94 | banner(); |
jmarkel44 | 0:65cfa4873284 | 95 | printf("\rMultiTech mDot library version: %s\n", dot->getId().c_str()); |
jmarkel44 | 3:8ea4db957749 | 96 | |
jmarkel44 | 3:8ea4db957749 | 97 | // start the configuration handler |
jmarkel44 | 35:6235ef67faa1 | 98 | Thread configHandler_thread(ConfigurationHandler, NULL, osPriorityNormal, 3072, NULL); |
jmarkel44 | 48:1c7861d80d16 | 99 | Thread outputTask_thread(OutputTask, NULL, osPriorityNormal, 3072, NULL); |
jmarkel44 | 20:653923c2f37a | 100 | Thread controlTask_thread(ControlTask); |
jmarkel44 | 3:8ea4db957749 | 101 | |
jmarkel44 | 0:65cfa4873284 | 102 | // wait for the configuration handler to signal us |
jmarkel44 | 0:65cfa4873284 | 103 | osSignalWait(sig_continue, osWaitForever); |
jmarkel44 | 3:8ea4db957749 | 104 | |
jmarkel44 | 0:65cfa4873284 | 105 | printf("\r%s: continuing to initialize...\n", __func__); |
jmarkel44 | 3:8ea4db957749 | 106 | |
jmarkel44 | 34:f345fdec711d | 107 | Thread analyticsLoggerThread(AnalyticsLogger); |
davidjhoward | 57:5f18ae91c7c7 | 108 | Thread modbusMaster_thread(ModbusMaster, NULL, osPriorityHigh, 10000, NULL); |
jmarkel44 | 3:8ea4db957749 | 109 | Thread BLE_thread(BLEDataHandler); |
davidjhoward | 49:0456ee2271be | 110 | Thread CDH_thread(CloudDataHandler, NULL, osPriorityNormal, 8000, NULL); |
jmarkel44 | 34:f345fdec711d | 111 | |
jmarkel44 | 35:6235ef67faa1 | 112 | // assign globals |
jmarkel44 | 34:f345fdec711d | 113 | GLOBAL_analyticsLogger_thread = &analyticsLoggerThread; |
jmarkel44 | 34:f345fdec711d | 114 | GLOBAL_modbusMaster_thread = &modbusMaster_thread; |
jmarkel44 | 34:f345fdec711d | 115 | GLOBAL_BLE_thread = & BLE_thread; |
jmarkel44 | 34:f345fdec711d | 116 | GLOBAL_CDH_thread = & CDH_thread; |
jmarkel44 | 34:f345fdec711d | 117 | GLOBAL_configHandler_thread = &configHandler_thread; |
jmarkel44 | 34:f345fdec711d | 118 | GLOBAL_controlTask_thread = &controlTask_thread; |
jmarkel44 | 48:1c7861d80d16 | 119 | GLOBAL_outputTask_thread = &outputTask_thread; |
jmarkel44 | 3:8ea4db957749 | 120 | |
jmarkel44 | 1:057d8fc6cb2f | 121 | Thread::wait(1000); |
jmarkel44 | 3:8ea4db957749 | 122 | |
jmarkel44 | 3:8ea4db957749 | 123 | // display free memory on the heap |
jmarkel44 | 18:9cf694a764c0 | 124 | printf("\r\n"); |
jmarkel44 | 3:8ea4db957749 | 125 | __heapstats((__heapprt)fprintf,stdout); |
jmarkel44 | 3:8ea4db957749 | 126 | |
jmarkel44 | 3:8ea4db957749 | 127 | printf("\r\n"); |
jmarkel44 | 13:c80c283f9db2 | 128 | Thread::wait(1000); |
jmarkel44 | 0:65cfa4873284 | 129 | printf("\r\n"); |
jmarkel44 | 20:653923c2f37a | 130 | |
jmarkel44 | 3:8ea4db957749 | 131 | // start the command shell |
jmarkel44 | 0:65cfa4873284 | 132 | ntshell_execute(&ntshell, func_read, func_write, func_cb_ntshell); |
jmarkel44 | 3:8ea4db957749 | 133 | } |