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.

Dependencies:   mbed millis

Fork of QSL_SimplePublish by Jon-Håkon Bøe Røli

QSL SimplePublish

SmartMesh IP QuickStart Library

dn_time.cpp

Committer:
jhbr
Date:
2016-09-08
Revision:
4:0285bcbbc855
Parent:
3:fb2c485306d1
Child:
8:8eb144b9ada3

File content as of revision 4:0285bcbbc855:

/*
Copyright (c) 2016, Dust Networks. All rights reserved.

Port of the time module to the NUCLEO-L053R8.

\license See attached DN_LICENSE.txt.
*/

#include "dn_time.h"
#include "mbed.h"
#include "dn_debug.h"

//=========================== defines =========================================


//=========================== variables =======================================

static Timer myTimer;

//=========================== prototypes ======================================


//=========================== public ==========================================

uint32_t dn_time_ms(void)
{
	static bool started = FALSE;
	time_t seconds;
	uint32_t ms;
	
	if (!started)
	{
		myTimer.start();
		/*
		Uncomment the command below to set RTC time to 1th Jan 2016 00:00:00.
		Otherwise, time() will just return seconds since boot
		*/
		//set_time(1451606400);
		started = TRUE;
	}
	/*
	mbed timers are based on 32-bit int microsecond counters, resulting in
	read_ms() to wrap around long before the max value of a uint32_t.
	Therefore, the seconds from time() is used to fully extend the range, and
	we cast read_ms() to an uint32_t and only use the millisecond part.
	 */
	seconds = time(NULL);
	ms = (uint32_t)seconds*1000 + (uint32_t)(myTimer.read_ms()) % 1000;
	
	return ms;
}

void dn_sleep_ms(uint32_t milliseconds)
{
	 /*
	 A simple delay is used for simplicity in this example.
	 To save power, we could instead have initialized a timer to fire an
	 interrupt after the set number of milliseconds, followed by entering
	 a low-power sleep mode. Upon wake up, we would have to check that we
	 were indeed woken by said interrupt (and e.g. not an USART interrupt)
	 to decide if we should go back to sleep or not.
	 */
	 wait_ms(milliseconds);
}

//=========================== private =========================================


//=========================== helpers =========================================