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: DataStore JobScheduler NetworkServices W5500Interface nanopb protocol
source/main.cpp@2:661c545d718e, 2017-07-13 (annotated)
- Committer:
- sgnezdov
- Date:
- Thu Jul 13 20:59:59 2017 +0000
- Revision:
- 2:661c545d718e
- Parent:
- 1:eebe442fc126
- Child:
- 4:b360d4f0bf34
added W5500 network stack
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgnezdov | 0:2c57ed6943f7 | 1 | #include "mbed.h" |
sgnezdov | 0:2c57ed6943f7 | 2 | |
sgnezdov | 0:2c57ed6943f7 | 3 | #include "mbed-trace/mbed_trace.h" |
sgnezdov | 0:2c57ed6943f7 | 4 | #define TRACE_GROUP "main" |
sgnezdov | 0:2c57ed6943f7 | 5 | |
sgnezdov | 1:eebe442fc126 | 6 | #include "scheduler.h" |
sgnezdov | 1:eebe442fc126 | 7 | #include "schedules.h" |
sgnezdov | 1:eebe442fc126 | 8 | #include "jobService.h" |
sgnezdov | 1:eebe442fc126 | 9 | #include "jobTestPrint.h" |
sgnezdov | 2:661c545d718e | 10 | #include "netstack.h" |
sgnezdov | 1:eebe442fc126 | 11 | |
sgnezdov | 0:2c57ed6943f7 | 12 | // These are necessary only if thread safety is needed |
sgnezdov | 0:2c57ed6943f7 | 13 | static Mutex TracingLock; |
sgnezdov | 0:2c57ed6943f7 | 14 | static void tracingWait() |
sgnezdov | 0:2c57ed6943f7 | 15 | { |
sgnezdov | 0:2c57ed6943f7 | 16 | TracingLock.lock(); |
sgnezdov | 0:2c57ed6943f7 | 17 | } |
sgnezdov | 0:2c57ed6943f7 | 18 | static void tracingRelease() |
sgnezdov | 0:2c57ed6943f7 | 19 | { |
sgnezdov | 0:2c57ed6943f7 | 20 | TracingLock.unlock(); |
sgnezdov | 0:2c57ed6943f7 | 21 | } |
sgnezdov | 0:2c57ed6943f7 | 22 | |
sgnezdov | 0:2c57ed6943f7 | 23 | int main() |
sgnezdov | 0:2c57ed6943f7 | 24 | { |
sgnezdov | 0:2c57ed6943f7 | 25 | printf("\n==Borsch==\n"); |
sgnezdov | 2:661c545d718e | 26 | |
sgnezdov | 2:661c545d718e | 27 | uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x45, 0x56, 0x67}; |
sgnezdov | 2:661c545d718e | 28 | |
sgnezdov | 0:2c57ed6943f7 | 29 | /* Setup tracing */ |
sgnezdov | 0:2c57ed6943f7 | 30 | mbed_trace_mutex_wait_function_set( tracingWait ); // only if thread safety is needed |
sgnezdov | 0:2c57ed6943f7 | 31 | mbed_trace_mutex_release_function_set( tracingRelease ); // only if thread safety is needed |
sgnezdov | 0:2c57ed6943f7 | 32 | mbed_trace_init(); // initialize the trace library |
sgnezdov | 0:2c57ed6943f7 | 33 | |
sgnezdov | 0:2c57ed6943f7 | 34 | tr_info("**Started**"); //-> "[INFO][main]: this is an info msg" |
sgnezdov | 2:661c545d718e | 35 | |
sgnezdov | 2:661c545d718e | 36 | NetworkInterface* nif = initNetworkStack(mac_addr); |
sgnezdov | 2:661c545d718e | 37 | if (nif == NULL) { |
sgnezdov | 2:661c545d718e | 38 | tr_error("**Terminated**"); |
sgnezdov | 2:661c545d718e | 39 | exit(0); |
sgnezdov | 2:661c545d718e | 40 | } |
sgnezdov | 0:2c57ed6943f7 | 41 | |
sgnezdov | 1:eebe442fc126 | 42 | JobScheduler::JobService js; |
sgnezdov | 1:eebe442fc126 | 43 | JobScheduler::Scheduler scheduler(&js); |
sgnezdov | 1:eebe442fc126 | 44 | |
sgnezdov | 1:eebe442fc126 | 45 | JobTestPrint jtp; |
sgnezdov | 1:eebe442fc126 | 46 | js.Register(1, JobTestPrint::RunAdapter, &jtp); |
sgnezdov | 0:2c57ed6943f7 | 47 | |
sgnezdov | 1:eebe442fc126 | 48 | scheduler.Start(); |
sgnezdov | 1:eebe442fc126 | 49 | |
sgnezdov | 1:eebe442fc126 | 50 | // inject test case |
sgnezdov | 1:eebe442fc126 | 51 | time_t nowSecs = time(NULL); |
sgnezdov | 1:eebe442fc126 | 52 | JobScheduler::Response<JobScheduler::JobID> res = |
sgnezdov | 1:eebe442fc126 | 53 | scheduler.JobAdd(1, new JobScheduler::RunOnceSchedule(nowSecs + 2), NULL); |
sgnezdov | 1:eebe442fc126 | 54 | |
sgnezdov | 1:eebe442fc126 | 55 | // block forever unless there is a job that calls scheduler.Stop() |
sgnezdov | 1:eebe442fc126 | 56 | scheduler.WaitToStop(); |
sgnezdov | 1:eebe442fc126 | 57 | |
sgnezdov | 1:eebe442fc126 | 58 | // indicate clean app termination |
sgnezdov | 0:2c57ed6943f7 | 59 | tr_info("**Finished**"); //-> "[INFO][main]: this is an info msg" |
sgnezdov | 0:2c57ed6943f7 | 60 | exit(0); |
sgnezdov | 0:2c57ed6943f7 | 61 | } |