Contiki 3.x
ds3231-test.c
1 /* test rtc temp sensor
2 */
3 #include <stdio.h>
4 #include "contiki.h"
5 #include "dev/i2cmaster.h" // Include IC driver
6 #include "dev/ds3231-sensor.h" // RTC contains a T sensor
7 
8 // temp sensor on rtc only updates every 64s
9 #define READ_INTERVAL (CLOCK_SECOND)
10 
11 static struct etimer et;
12 
13 static uint32_t
14 get_time(void)
15 {
16  uint32_t time;
17  time = (uint32_t)ds3231_sensor.value(DS3231_SENSOR_GET_EPOCH_SECONDS_MSB) << 1;
18  time |= (uint32_t)ds3231_sensor.value(DS3231_SENSOR_GET_EPOCH_SECONDS_LSB);
19  return(time);
20 }
21 
22 PROCESS (kirks_process, "ds3231 Temp process");
23 AUTOSTART_PROCESSES (&kirks_process);
24 /*---------------------------------------------------------------------------*/
25 static struct etimer et;
26 
27 PROCESS_THREAD (kirks_process, ev, data)
28 {
29  PROCESS_BEGIN ();
30 
31  {
32  int rtctemp;
33 
34 
35  while (1)
36  {
37  etimer_set(&et, READ_INTERVAL); // Set the timer
38  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); // wait for its expiration
39  if( ev == PROCESS_EVENT_TIMER) {
40  rtctemp = ds3231_temperature();
41  printf("rtc temp * 100 %d\n",rtctemp);
42  }
43  }
44  }
45  PROCESS_END ();
46 }
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition: etimer.c:177
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
static struct etimer et
NIC receiver thread.
Definition: lanc111.c:1133
A timer.
Definition: etimer.h:76
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Definition: process.h:157
Sensors for DS3231 (RTC with Temperature Sensor).
const struct sensors_sensor ds3231_sensor
Export the DS3231 sensor object.
Definition: ds3231-sensor.c:82
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
Definition: etimer.c:213
int ds3231_temperature(void)
ds3231_temperature
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120