Contiki 3.x
ds323-test.c
1 #include <stdio.h>
2 #include "contiki.h"
3 #include "dev/i2cmaster.h" // Include IC driver
4 #include "dev/ds3231-sensor.h" // Include sensor driver
5 
6 #define TMP102_READ_INTERVAL (CLOCK_SECOND/2) // Poll the sensor every 500 ms
7 
8 PROCESS (temp_process, "Test Temperature process");
9 AUTOSTART_PROCESSES (&temp_process);
10 /*---------------------------------------------------------------------------*/
11 static struct etimer et;
12 
13 
14 static uint32_t
15 get_time(void)
16 {
17  uint32_t time;
18  time = (uint32_t)ds3231_sensor.value(DS3231_SENSOR_GET_EPOCH_SECONDS_MSB) << 16;
19  time |= (uint32_t)ds3231_sensor.value(DS3231_SENSOR_GET_EPOCH_SECONDS_LSB);
20  return(time);
21 }
22 
23 PROCESS_THREAD (temp_process, ev, data)
24 {
25  PROCESS_BEGIN ();
26 
27  {
28  int16_t tempint;
29  uint16_t tempfrac;
30  int16_t raw;
31  uint16_t absraw;
32  int16_t sign;
33  char minus = ' ';
34 
35  tmp102_init();
36 
37  while (1)
38  {
39  etimer_set(&et, TMP102_READ_INTERVAL); // Set the timer
40  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); // wait for its expiration
41 
42  sign = 1;
43 
44  printf ("RTC = %lu\n", ds3231_get_epoch_seconds());
45  }
46  }
47  PROCESS_END ();
48 }
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
void tmp102_init(void)
Initialiser for the TMP102 sensor driver.
Definition: tmp102.c:59
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120