2015-02-04 22:13:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
2015-11-12 16:29:41 +01:00
|
|
|
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
2015-02-04 22:13:44 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2016-09-01 16:08:01 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-02-04 22:13:44 +01:00
|
|
|
/**
|
2015-11-12 16:29:41 +01:00
|
|
|
* \addtogroup zoul
|
2015-02-04 22:13:44 +01:00
|
|
|
* @{
|
|
|
|
*
|
2015-11-12 16:29:41 +01:00
|
|
|
* \defgroup zoul-examples Zoul examples
|
2015-02-04 22:13:44 +01:00
|
|
|
* @{
|
|
|
|
*
|
2015-11-12 16:29:41 +01:00
|
|
|
* \defgroup zoul-demo Zoul demo application
|
2015-02-04 22:13:44 +01:00
|
|
|
*
|
2015-11-12 16:29:41 +01:00
|
|
|
* Example project demonstrating the Zoul module on the RE-Mote and Firefly
|
|
|
|
* platforms.
|
2015-02-04 22:13:44 +01:00
|
|
|
*
|
|
|
|
* - Boot sequence: LEDs flashing (Red, then yellow, finally green)
|
|
|
|
*
|
|
|
|
* - etimer/clock : Every LOOP_INTERVAL clock ticks (LOOP_PERIOD secs) the LED
|
|
|
|
* defined as LEDS_PERIODIC will turn on
|
|
|
|
* - rtimer : Exactly LEDS_OFF_HYSTERISIS rtimer ticks later,
|
|
|
|
* LEDS_PERIODIC will turn back off
|
|
|
|
* - ADC sensors : On-chip VDD / 3, temperature, and Phidget sensor
|
|
|
|
* values are printed over UART periodically.
|
|
|
|
* - UART : Every LOOP_INTERVAL the Remote will print something over
|
|
|
|
* the UART. Receiving an entire line of text over UART (ending
|
|
|
|
* in \\r) will cause LEDS_SERIAL_IN to toggle
|
|
|
|
* - Radio comms : BTN_USER sends a rime broadcast. Reception of a rime
|
|
|
|
* packet will toggle LEDs defined as LEDS_RF_RX
|
|
|
|
* - Button : Keeping the button pressed will print a counter that
|
|
|
|
* increments every BUTTON_PRESS_EVENT_INTERVAL ticks
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* \file
|
2015-11-12 16:29:41 +01:00
|
|
|
* Example demonstrating the Zoul module on the RE-Mote & Firefly platforms
|
2015-02-04 22:13:44 +01:00
|
|
|
*/
|
2016-09-01 16:08:01 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-02-04 22:13:44 +01:00
|
|
|
#include "contiki.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "sys/etimer.h"
|
|
|
|
#include "sys/rtimer.h"
|
|
|
|
#include "dev/leds.h"
|
|
|
|
#include "dev/uart.h"
|
|
|
|
#include "dev/button-sensor.h"
|
2016-01-17 23:04:34 +01:00
|
|
|
#include "dev/adc-zoul.h"
|
2015-11-12 16:29:41 +01:00
|
|
|
#include "dev/zoul-sensors.h"
|
2015-02-04 22:13:44 +01:00
|
|
|
#include "dev/watchdog.h"
|
|
|
|
#include "dev/serial-line.h"
|
|
|
|
#include "dev/sys-ctrl.h"
|
2015-12-22 15:16:55 +01:00
|
|
|
#include "net/netstack.h"
|
2015-02-04 22:13:44 +01:00
|
|
|
#include "net/rime/broadcast.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#define LOOP_PERIOD 8
|
|
|
|
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
|
|
|
|
#define LEDS_OFF_HYSTERISIS ((RTIMER_SECOND * LOOP_PERIOD) >> 1)
|
|
|
|
#define LEDS_PERIODIC LEDS_BLUE
|
|
|
|
#define LEDS_BUTTON LEDS_RED
|
|
|
|
#define LEDS_SERIAL_IN LEDS_GREEN
|
|
|
|
#define LEDS_REBOOT LEDS_ALL
|
|
|
|
#define LEDS_RF_RX (LEDS_YELLOW | LEDS_RED)
|
|
|
|
#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND)
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static struct etimer et;
|
|
|
|
static struct rtimer rt;
|
2015-11-12 16:29:41 +01:00
|
|
|
static uint16_t counter;
|
2015-02-04 22:13:44 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-12 16:29:41 +01:00
|
|
|
PROCESS(zoul_demo_process, "Zoul demo process");
|
|
|
|
AUTOSTART_PROCESSES(&zoul_demo_process);
|
2015-02-04 22:13:44 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
|
|
|
|
{
|
|
|
|
leds_toggle(LEDS_RF_RX);
|
|
|
|
printf("*** Received %u bytes from %u:%u: '0x%04x'\n", packetbuf_datalen(),
|
|
|
|
from->u8[0], from->u8[1], *(uint16_t *)packetbuf_dataptr());
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static const struct broadcast_callbacks bc_rx = { broadcast_recv };
|
|
|
|
static struct broadcast_conn bc;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-01-19 22:23:30 +01:00
|
|
|
static void
|
2015-02-04 22:13:44 +01:00
|
|
|
rt_callback(struct rtimer *t, void *ptr)
|
|
|
|
{
|
|
|
|
leds_off(LEDS_PERIODIC);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-12 16:29:41 +01:00
|
|
|
PROCESS_THREAD(zoul_demo_process, ev, data)
|
2015-02-04 22:13:44 +01:00
|
|
|
{
|
|
|
|
PROCESS_EXITHANDLER(broadcast_close(&bc))
|
|
|
|
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
|
|
|
counter = 0;
|
2015-12-22 15:16:55 +01:00
|
|
|
|
|
|
|
/* Disable the radio duty cycle and keep the radio on */
|
|
|
|
NETSTACK_MAC.off(1);
|
|
|
|
|
2015-02-04 22:13:44 +01:00
|
|
|
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
|
|
|
|
|
2015-11-12 16:29:41 +01:00
|
|
|
/* Configure the user button */
|
2015-02-04 22:13:44 +01:00
|
|
|
button_sensor.configure(BUTTON_SENSOR_CONFIG_TYPE_INTERVAL,
|
|
|
|
BUTTON_PRESS_EVENT_INTERVAL);
|
|
|
|
|
2015-11-12 16:29:41 +01:00
|
|
|
/* Configure the ADC ports */
|
2016-01-17 23:04:34 +01:00
|
|
|
adc_zoul.configure(SENSORS_HW_INIT, ZOUL_SENSORS_ADC_ALL);
|
2015-02-04 22:13:44 +01:00
|
|
|
|
2015-11-12 16:29:41 +01:00
|
|
|
printf("Zoul test application\n");
|
2015-02-04 22:13:44 +01:00
|
|
|
|
|
|
|
etimer_set(&et, LOOP_INTERVAL);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
|
|
|
PROCESS_YIELD();
|
|
|
|
|
|
|
|
if(ev == PROCESS_EVENT_TIMER) {
|
|
|
|
leds_on(LEDS_PERIODIC);
|
|
|
|
|
|
|
|
printf("-----------------------------------------\n"
|
|
|
|
"Counter = 0x%08x\n", counter);
|
|
|
|
|
|
|
|
printf("VDD = %d mV\n",
|
|
|
|
vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
|
|
|
|
|
|
|
printf("Temperature = %d mC\n",
|
|
|
|
cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
|
|
|
|
2015-11-12 16:29:41 +01:00
|
|
|
printf("ADC1 = %d raw\n",
|
2016-01-17 23:04:34 +01:00
|
|
|
adc_zoul.value(ZOUL_SENSORS_ADC1));
|
2015-02-04 22:13:44 +01:00
|
|
|
|
2015-11-12 16:29:41 +01:00
|
|
|
printf("ADC3 = %d raw\n",
|
2016-01-17 23:04:34 +01:00
|
|
|
adc_zoul.value(ZOUL_SENSORS_ADC3));
|
2015-02-04 22:13:44 +01:00
|
|
|
|
|
|
|
etimer_set(&et, LOOP_INTERVAL);
|
|
|
|
rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
|
|
|
|
rt_callback, NULL);
|
|
|
|
counter++;
|
2016-01-17 23:04:34 +01:00
|
|
|
|
2015-02-04 22:13:44 +01:00
|
|
|
} else if(ev == sensors_event) {
|
|
|
|
if(data == &button_sensor) {
|
|
|
|
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
|
|
|
|
BUTTON_SENSOR_PRESSED_LEVEL) {
|
2015-11-12 16:29:41 +01:00
|
|
|
printf("Button pressed\n");
|
2015-02-04 22:13:44 +01:00
|
|
|
packetbuf_copyfrom(&counter, sizeof(counter));
|
|
|
|
broadcast_send(&bc);
|
|
|
|
} else {
|
2015-11-12 16:29:41 +01:00
|
|
|
printf("...and released!\n");
|
2015-02-04 22:13:44 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-17 23:04:34 +01:00
|
|
|
|
2015-02-04 22:13:44 +01:00
|
|
|
} else if(ev == serial_line_event_message) {
|
|
|
|
leds_toggle(LEDS_SERIAL_IN);
|
|
|
|
} else if(ev == button_press_duration_exceeded) {
|
|
|
|
printf("Button pressed for %d ticks [%u events]\n",
|
|
|
|
(*((uint8_t *)data) * BUTTON_PRESS_EVENT_INTERVAL),
|
|
|
|
button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|
2016-09-01 16:08:01 +02:00
|
|
|
|