Merge pull request #1196 from otcshare/x86
New platform: Intel Galileo Board
This commit is contained in:
commit
ca919ab0b0
77 changed files with 6872 additions and 269 deletions
18
examples/galileo/Makefile
Normal file
18
examples/galileo/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
TARGET=galileo
|
||||
|
||||
KNOWN_EXAMPLES = gpio-input gpio-output gpio-interrupt i2c-LSM9DS0
|
||||
|
||||
ifneq ($(filter $(EXAMPLE),$(KNOWN_EXAMPLES)),)
|
||||
CONTIKI_PROJECT = $(EXAMPLE)
|
||||
else
|
||||
CONTIKI_PROJECT = help
|
||||
endif
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../..
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
||||
help:
|
||||
@echo -e "\nSet the variable EXAMPLE to one of the following Galileo-specific examples:"
|
||||
@for EXAMPLE in $(KNOWN_EXAMPLES); do echo $$EXAMPLE; done
|
73
examples/galileo/README
Normal file
73
examples/galileo/README
Normal file
|
@ -0,0 +1,73 @@
|
|||
Galileo Specific Examples
|
||||
=======================
|
||||
|
||||
This directory contains galileo-specific example applications to illustrate
|
||||
how to use galileo APIs.
|
||||
|
||||
In order to build a application, you should set the EXAMPLE environment
|
||||
variable to the name of the application you want to build. For instance, if
|
||||
you want to build gpio-output application, run the following command:
|
||||
$ make TARGET=galileo EXAMPLE=gpio-output
|
||||
|
||||
============
|
||||
= GPIO =
|
||||
============
|
||||
|
||||
GPIO Output
|
||||
===========
|
||||
|
||||
This application shows how to use the GPIO driver APIs to manipulate output
|
||||
pins. This application sets the GPIO 4 pin as output pin and toggles its
|
||||
state at every half second.
|
||||
|
||||
For a visual effect, you should wire shield pin IO1 to a led in a protoboard.
|
||||
Once the application is running, you should see a blinking LED.
|
||||
|
||||
GPIO Input
|
||||
==========
|
||||
|
||||
This application shows how to use the GPIO driver APIs to manipulate input
|
||||
pins. This application uses default galileo pinmux initialization and sets
|
||||
the GPIO 5 (IO2) as output pin and GPIO 6 (IO3) as input. It toggles the
|
||||
output pin state at every half second and checks the value on input pin.
|
||||
|
||||
GPIO Interrupt
|
||||
==============
|
||||
|
||||
This application shows how to use the GPIO driver APIs to manipulate interrupt
|
||||
pins. This application uses default galileo pinmux initialization and sets
|
||||
the GPIO 5 (IO2) as output pin and GPIO 6 (IO3) as interrupt. It toggles the
|
||||
output pin stat at every half second in order to emulate an interrupt. This
|
||||
triggers an interrupt and the application callback is called. You can confirm
|
||||
that though the UART output.
|
||||
|
||||
=======
|
||||
= I2C =
|
||||
=======
|
||||
|
||||
I2C LSM9DS0
|
||||
===========
|
||||
This application shows how to use I2C driver APIs to configure I2C Master
|
||||
controller and communicate with LSM9DS0 sensor. At every 5 seconds, the
|
||||
application reads the "who am I" register from gyroscope sensor and prints if
|
||||
the register value matches the expected value described in the spec [1].
|
||||
|
||||
According to the sensor spec, to read the value in "who am I" register, we
|
||||
should first perform an i2c write operation to select the register we want
|
||||
to read from and then we perform the i2c read operation to actually read
|
||||
the register contents.
|
||||
|
||||
The wiring setup is as follows (left column from Galileo and right column from LSM9DS0):
|
||||
- 3.3v and Vin
|
||||
- GND and GND
|
||||
- GND and SDOG
|
||||
- 3.3v and CSG
|
||||
- SDA and SDA
|
||||
- SCL and SCL
|
||||
|
||||
==============
|
||||
= References =
|
||||
==============
|
||||
|
||||
[1] http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00087365.pdf
|
||||
|
96
examples/galileo/gpio-input.c
Normal file
96
examples/galileo/gpio-input.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (C) 2015, Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/ctimer.h"
|
||||
|
||||
#include "galileo-pinmux.h"
|
||||
#include "gpio.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#define PIN_OUTPUT 5
|
||||
#define PIN_INPUT 6
|
||||
|
||||
static uint32_t value;
|
||||
static struct ctimer timer;
|
||||
static struct quarkX1000_i2c_config i2c_config;
|
||||
|
||||
PROCESS(gpio_input_process, "GPIO Input Process");
|
||||
AUTOSTART_PROCESSES(&gpio_input_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
timeout(void *data)
|
||||
{
|
||||
uint8_t value_in;
|
||||
|
||||
/* toggle pin state */
|
||||
value = !value;
|
||||
quarkX1000_gpio_write(PIN_OUTPUT, value);
|
||||
|
||||
quarkX1000_gpio_read(PIN_INPUT, &value_in);
|
||||
|
||||
if (value == value_in)
|
||||
printf("GPIO pin value match!\n");
|
||||
else
|
||||
printf("GPIO pin value DOESN'T match!\n");
|
||||
|
||||
ctimer_reset(&timer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(gpio_input_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
i2c_config.speed = QUARKX1000_I2C_SPEED_STANDARD;
|
||||
i2c_config.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT;
|
||||
|
||||
quarkX1000_i2c_init();
|
||||
quarkX1000_i2c_configure(&i2c_config);
|
||||
|
||||
/* use default pinmux configuration */
|
||||
galileo_pinmux_initialize();
|
||||
|
||||
quarkX1000_gpio_init();
|
||||
quarkX1000_gpio_config(PIN_OUTPUT, QUARKX1000_GPIO_OUT);
|
||||
quarkX1000_gpio_config(PIN_INPUT, QUARKX1000_GPIO_IN);
|
||||
|
||||
quarkX1000_gpio_clock_enable();
|
||||
|
||||
ctimer_set(&timer, CLOCK_SECOND / 2, timeout, NULL);
|
||||
|
||||
printf("GPIO input example is running\n");
|
||||
PROCESS_YIELD();
|
||||
|
||||
quarkX1000_gpio_clock_disable();
|
||||
|
||||
PROCESS_END();
|
||||
}
|
94
examples/galileo/gpio-interrupt.c
Normal file
94
examples/galileo/gpio-interrupt.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (C) 2015, Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/ctimer.h"
|
||||
|
||||
#include "gpio.h"
|
||||
#include "i2c.h"
|
||||
#include "galileo-pinmux.h"
|
||||
|
||||
#define PIN_OUTPUT 5
|
||||
#define PIN_INTR 6
|
||||
|
||||
static struct ctimer timer;
|
||||
static struct quarkX1000_i2c_config i2c_config;
|
||||
|
||||
PROCESS(gpio_interrupt_process, "GPIO Interrupt Process");
|
||||
AUTOSTART_PROCESSES(&gpio_interrupt_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
timeout(void *data)
|
||||
{
|
||||
/* emulate an interrupt */
|
||||
quarkX1000_gpio_write(PIN_OUTPUT, 0);
|
||||
quarkX1000_gpio_write(PIN_OUTPUT, 1);
|
||||
|
||||
ctimer_reset(&timer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
callback(uint32_t status)
|
||||
{
|
||||
printf("GPIO interrupt callback called, status: %d\n", status);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(gpio_interrupt_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
i2c_config.speed = QUARKX1000_I2C_SPEED_STANDARD;
|
||||
i2c_config.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT;
|
||||
|
||||
quarkX1000_i2c_init();
|
||||
quarkX1000_i2c_configure(&i2c_config);
|
||||
|
||||
/* use default pinmux configuration */
|
||||
galileo_pinmux_initialize();
|
||||
|
||||
quarkX1000_gpio_init();
|
||||
quarkX1000_gpio_config(PIN_OUTPUT, QUARKX1000_GPIO_OUT);
|
||||
quarkX1000_gpio_config(PIN_INTR, QUARKX1000_GPIO_INT | QUARKX1000_GPIO_ACTIVE_HIGH | QUARKX1000_GPIO_EDGE);
|
||||
|
||||
quarkX1000_gpio_set_callback(callback);
|
||||
|
||||
quarkX1000_gpio_clock_enable();
|
||||
|
||||
ctimer_set(&timer, CLOCK_SECOND / 2, timeout, NULL);
|
||||
|
||||
printf("GPIO interrupt example is running\n");
|
||||
PROCESS_YIELD();
|
||||
|
||||
quarkX1000_gpio_clock_disable();
|
||||
|
||||
PROCESS_END();
|
||||
}
|
73
examples/galileo/gpio-output.c
Normal file
73
examples/galileo/gpio-output.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2015, Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/ctimer.h"
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
#define PIN 4 /* IO1 */
|
||||
|
||||
static uint32_t value;
|
||||
static struct ctimer timer;
|
||||
|
||||
PROCESS(gpio_output_process, "GPIO Output Process");
|
||||
AUTOSTART_PROCESSES(&gpio_output_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
timeout(void *data)
|
||||
{
|
||||
/* toggle pin state */
|
||||
value = !value;
|
||||
quarkX1000_gpio_write(PIN, value);
|
||||
|
||||
ctimer_reset(&timer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(gpio_output_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
quarkX1000_gpio_init();
|
||||
quarkX1000_gpio_config(PIN, QUARKX1000_GPIO_OUT);
|
||||
|
||||
quarkX1000_gpio_clock_enable();
|
||||
|
||||
ctimer_set(&timer, CLOCK_SECOND / 2, timeout, NULL);
|
||||
|
||||
printf("GPIO output example is running\n");
|
||||
PROCESS_YIELD();
|
||||
|
||||
quarkX1000_gpio_clock_disable();
|
||||
|
||||
PROCESS_END();
|
||||
}
|
108
examples/galileo/i2c-LSM9DS0.c
Normal file
108
examples/galileo/i2c-LSM9DS0.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (C) 2015, Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/ctimer.h"
|
||||
|
||||
#include "galileo-pinmux.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#define LSM9DS0_I2C_ADDR 0x6A
|
||||
#define WHO_AM_I_ADDR 0x0F
|
||||
#define WHO_AM_I_ANSWER 0xD4
|
||||
|
||||
static uint8_t tx_data = WHO_AM_I_ADDR;
|
||||
static uint8_t rx_data = 0;
|
||||
static struct ctimer timer;
|
||||
static struct quarkX1000_i2c_config cfg;
|
||||
|
||||
PROCESS(i2c_lsm9ds0_process, "I2C LSM9DS0 Who Am I Process");
|
||||
AUTOSTART_PROCESSES(&i2c_lsm9ds0_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
rx(void)
|
||||
{
|
||||
if (rx_data == WHO_AM_I_ANSWER)
|
||||
printf("Who am I register value match!\n");
|
||||
else
|
||||
printf("Who am I register value DOESN'T match! %u\n", rx_data);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tx(void)
|
||||
{
|
||||
rx_data = 0;
|
||||
|
||||
quarkX1000_i2c_read(&rx_data, sizeof(rx_data), LSM9DS0_I2C_ADDR);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
err(void)
|
||||
{
|
||||
printf("Something went wrong. err() callback has been called.\n");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
timeout(void *data)
|
||||
{
|
||||
quarkX1000_i2c_write(&tx_data, sizeof(tx_data), LSM9DS0_I2C_ADDR);
|
||||
|
||||
ctimer_reset(&timer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(i2c_lsm9ds0_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
cfg.speed = QUARKX1000_I2C_SPEED_STANDARD;
|
||||
cfg.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT;
|
||||
|
||||
quarkX1000_i2c_init();
|
||||
quarkX1000_i2c_configure(&cfg);
|
||||
|
||||
galileo_pinmux_initialize();
|
||||
|
||||
cfg.cb_rx = rx;
|
||||
cfg.cb_tx = tx;
|
||||
cfg.cb_err = err;
|
||||
|
||||
quarkX1000_i2c_configure(&cfg);
|
||||
|
||||
ctimer_set(&timer, CLOCK_SECOND * 5, timeout, NULL);
|
||||
|
||||
printf("I2C LSM9DS0 example is running\n");
|
||||
|
||||
PROCESS_YIELD();
|
||||
|
||||
PROCESS_END();
|
||||
}
|
5
examples/timers/Makefile
Normal file
5
examples/timers/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
CONTIKI_PROJECT = all-timers
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../..
|
||||
include $(CONTIKI)/Makefile.include
|
131
examples/timers/all-timers.c
Normal file
131
examples/timers/all-timers.c
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (C) 2015, Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "sys/stimer.h"
|
||||
#include "sys/timer.h"
|
||||
#include "sys/rtimer.h"
|
||||
|
||||
PROCESS(process1, "ETimer x Timer x STimer Process");
|
||||
PROCESS(process2, "CTimer Process 2");
|
||||
PROCESS(process3, "RTimer Process 3");
|
||||
AUTOSTART_PROCESSES(&process1, &process2, &process3);
|
||||
|
||||
static int counter_etimer;
|
||||
static int counter_timer;
|
||||
static int counter_stimer;
|
||||
static int counter_ctimer;
|
||||
static int counter_rtimer;
|
||||
static struct timer timer_timer;
|
||||
static struct stimer timer_stimer;
|
||||
static struct ctimer timer_ctimer;
|
||||
static struct rtimer timer_rtimer;
|
||||
static rtimer_clock_t timeout_rtimer = RTIMER_SECOND / 2;
|
||||
|
||||
void
|
||||
do_timeout1()
|
||||
{
|
||||
counter_etimer++;
|
||||
if(timer_expired(&timer_timer)) {
|
||||
counter_timer++;
|
||||
}
|
||||
|
||||
if(stimer_expired(&timer_stimer)) {
|
||||
counter_stimer++;
|
||||
}
|
||||
|
||||
printf("\nProcess 1: %s", counter_timer == counter_etimer
|
||||
&& counter_timer == counter_stimer ? "SUCCESS" : "FAIL");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
do_timeout2()
|
||||
{
|
||||
ctimer_reset(&timer_ctimer);
|
||||
printf("\nProcess 2: CTimer callback called");
|
||||
counter_ctimer++;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
do_timeout3(struct rtimer *timer, void *ptr)
|
||||
{
|
||||
counter_rtimer++;
|
||||
|
||||
printf("\nProcess 3: RTimer callback called");
|
||||
|
||||
/* Re-arm rtimer */
|
||||
rtimer_set(&timer_rtimer, RTIMER_NOW() + timeout_rtimer, 0, do_timeout3,
|
||||
NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(process1, ev, data)
|
||||
{
|
||||
static struct etimer timer_etimer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
timer_set(&timer_timer, 3 * CLOCK_SECOND);
|
||||
stimer_set(&timer_stimer, 3);
|
||||
etimer_set(&timer_etimer, 3 * CLOCK_SECOND);
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
|
||||
do_timeout1();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(process2, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
ctimer_set(&timer_ctimer, 5 * CLOCK_SECOND, do_timeout2, NULL);
|
||||
PROCESS_YIELD();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(process3, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
rtimer_set(&timer_rtimer, RTIMER_NOW() + timeout_rtimer, 0,
|
||||
do_timeout3, NULL);
|
||||
PROCESS_YIELD();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue