Program that uses the QuickStart Library to interface a SmartMesh IP mote: Connects to the default network and starts publishing a random walk value every 5 seconds.
Fork of QSL_SimplePublish by
QSL SimplePublish
SmartMesh IP QuickStart Library
- GitHub repository
- Current release used: REL-1.0.2.2
- Documentation
- Discussion
dn_time.cpp@4:0285bcbbc855, 2016-09-08 (annotated)
- Committer:
- jhbr
- Date:
- Thu Sep 08 14:26:15 2016 +0000
- Revision:
- 4:0285bcbbc855
- Parent:
- 3:fb2c485306d1
- Child:
- 8:8eb144b9ada3
Replaced sleep() with simple wait_ms(), as board seems to not always wake up or go to sleep as it should.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhbr | 0:d3f5fdf2e6da | 1 | /* |
jhbr | 0:d3f5fdf2e6da | 2 | Copyright (c) 2016, Dust Networks. All rights reserved. |
jhbr | 0:d3f5fdf2e6da | 3 | |
jhbr | 0:d3f5fdf2e6da | 4 | Port of the time module to the NUCLEO-L053R8. |
jhbr | 0:d3f5fdf2e6da | 5 | |
jhbr | 0:d3f5fdf2e6da | 6 | \license See attached DN_LICENSE.txt. |
jhbr | 0:d3f5fdf2e6da | 7 | */ |
jhbr | 0:d3f5fdf2e6da | 8 | |
jhbr | 0:d3f5fdf2e6da | 9 | #include "dn_time.h" |
jhbr | 0:d3f5fdf2e6da | 10 | #include "mbed.h" |
jhbr | 0:d3f5fdf2e6da | 11 | #include "dn_debug.h" |
jhbr | 0:d3f5fdf2e6da | 12 | |
jhbr | 4:0285bcbbc855 | 13 | //=========================== defines ========================================= |
jhbr | 4:0285bcbbc855 | 14 | |
jhbr | 4:0285bcbbc855 | 15 | |
jhbr | 0:d3f5fdf2e6da | 16 | //=========================== variables ======================================= |
jhbr | 0:d3f5fdf2e6da | 17 | |
jhbr | 0:d3f5fdf2e6da | 18 | static Timer myTimer; |
jhbr | 0:d3f5fdf2e6da | 19 | |
jhbr | 0:d3f5fdf2e6da | 20 | //=========================== prototypes ====================================== |
jhbr | 0:d3f5fdf2e6da | 21 | |
jhbr | 0:d3f5fdf2e6da | 22 | |
jhbr | 0:d3f5fdf2e6da | 23 | //=========================== public ========================================== |
jhbr | 0:d3f5fdf2e6da | 24 | |
jhbr | 0:d3f5fdf2e6da | 25 | uint32_t dn_time_ms(void) |
jhbr | 0:d3f5fdf2e6da | 26 | { |
jhbr | 0:d3f5fdf2e6da | 27 | static bool started = FALSE; |
jhbr | 4:0285bcbbc855 | 28 | time_t seconds; |
jhbr | 3:fb2c485306d1 | 29 | uint32_t ms; |
jhbr | 3:fb2c485306d1 | 30 | |
jhbr | 0:d3f5fdf2e6da | 31 | if (!started) |
jhbr | 0:d3f5fdf2e6da | 32 | { |
jhbr | 0:d3f5fdf2e6da | 33 | myTimer.start(); |
jhbr | 4:0285bcbbc855 | 34 | /* |
jhbr | 4:0285bcbbc855 | 35 | Uncomment the command below to set RTC time to 1th Jan 2016 00:00:00. |
jhbr | 4:0285bcbbc855 | 36 | Otherwise, time() will just return seconds since boot |
jhbr | 4:0285bcbbc855 | 37 | */ |
jhbr | 4:0285bcbbc855 | 38 | //set_time(1451606400); |
jhbr | 0:d3f5fdf2e6da | 39 | started = TRUE; |
jhbr | 0:d3f5fdf2e6da | 40 | } |
jhbr | 3:fb2c485306d1 | 41 | /* |
jhbr | 3:fb2c485306d1 | 42 | mbed timers are based on 32-bit int microsecond counters, resulting in |
jhbr | 3:fb2c485306d1 | 43 | read_ms() to wrap around long before the max value of a uint32_t. |
jhbr | 3:fb2c485306d1 | 44 | Therefore, the seconds from time() is used to fully extend the range, and |
jhbr | 3:fb2c485306d1 | 45 | we cast read_ms() to an uint32_t and only use the millisecond part. |
jhbr | 3:fb2c485306d1 | 46 | */ |
jhbr | 4:0285bcbbc855 | 47 | seconds = time(NULL); |
jhbr | 3:fb2c485306d1 | 48 | ms = (uint32_t)seconds*1000 + (uint32_t)(myTimer.read_ms()) % 1000; |
jhbr | 3:fb2c485306d1 | 49 | |
jhbr | 3:fb2c485306d1 | 50 | return ms; |
jhbr | 0:d3f5fdf2e6da | 51 | } |
jhbr | 0:d3f5fdf2e6da | 52 | |
jhbr | 0:d3f5fdf2e6da | 53 | void dn_sleep_ms(uint32_t milliseconds) |
jhbr | 0:d3f5fdf2e6da | 54 | { |
jhbr | 4:0285bcbbc855 | 55 | /* |
jhbr | 4:0285bcbbc855 | 56 | A simple delay is used for simplicity in this example. |
jhbr | 4:0285bcbbc855 | 57 | To save power, we could instead have initialized a timer to fire an |
jhbr | 4:0285bcbbc855 | 58 | interrupt after the set number of milliseconds, followed by entering |
jhbr | 4:0285bcbbc855 | 59 | a low-power sleep mode. Upon wake up, we would have to check that we |
jhbr | 4:0285bcbbc855 | 60 | were indeed woken by said interrupt (and e.g. not an USART interrupt) |
jhbr | 4:0285bcbbc855 | 61 | to decide if we should go back to sleep or not. |
jhbr | 4:0285bcbbc855 | 62 | */ |
jhbr | 4:0285bcbbc855 | 63 | wait_ms(milliseconds); |
jhbr | 0:d3f5fdf2e6da | 64 | } |
jhbr | 0:d3f5fdf2e6da | 65 | |
jhbr | 0:d3f5fdf2e6da | 66 | //=========================== private ========================================= |
jhbr | 0:d3f5fdf2e6da | 67 | |
jhbr | 0:d3f5fdf2e6da | 68 | |
jhbr | 0:d3f5fdf2e6da | 69 | //=========================== helpers ========================================= |
jhbr | 0:d3f5fdf2e6da | 70 |