Updated to match the new sensors API

This commit is contained in:
nifi 2010-01-14 17:39:35 +00:00
parent d9900a474a
commit 24f28f0f1c
16 changed files with 603 additions and 429 deletions

View file

@ -32,12 +32,6 @@
of two (see clock.c for details). */ of two (see clock.c for details). */
#define CLOCK_CONF_SECOND 64 #define CLOCK_CONF_SECOND 64
#define IRQ_PORT1_VECTOR 1
#define IRQ_PORT1 0x01
#define IRQ_PORT2 0x02
#define IRQ_ADC 0x03
#define NODE_ID_EEPROM_OFFSET 0x0010 /* - 0x0014 */ #define NODE_ID_EEPROM_OFFSET 0x0010 /* - 0x0014 */
#define CFS_EEPROM_CONF_OFFSET 0x0040 #define CFS_EEPROM_CONF_OFFSET 0x0040

View file

@ -26,14 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: battery-sensor.c,v 1.4 2007/05/22 21:06:57 adamdunkels Exp $ * $Id: battery-sensor.c,v 1.5 2010/01/14 17:39:35 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01 * Created : 2005-11-01
* Updated : $Date: 2007/05/22 21:06:57 $ * Updated : $Date: 2010/01/14 17:39:35 $
* $Revision: 1.4 $ * $Revision: 1.5 $
*/ */
#include "dev/battery-sensor.h" #include "dev/battery-sensor.h"
@ -43,12 +43,6 @@
const struct sensors_sensor battery_sensor; const struct sensors_sensor battery_sensor;
static unsigned int battery_value; static unsigned int battery_value;
/*---------------------------------------------------------------------------*/
static void
init(void)
{
battery_value = 0;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void) irq(void)
@ -57,43 +51,42 @@ irq(void)
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void
activate(void)
{
irq_adc12_activate(&battery_sensor, 6, (INCH_4 + SREF_0));
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
irq_adc12_deactivate(&battery_sensor, 6);
battery_value = 0;
}
/*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return irq_adc12_active(6);
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
return ADC12MEM6/*battery_value*/; return ADC12MEM6/*battery_value*/;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
switch (type) {
case SENSORS_HW_INIT:
battery_value = 0;
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!irq_adc12_active(6)) {
irq_adc12_activate(6, (INCH_4 + SREF_0), irq);
}
} else {
irq_adc12_deactivate(6);
}
return 1;
}
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return NULL; switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return irq_adc12_active(6);
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,10 +28,12 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: button-sensor.c,v 1.3 2006/06/18 08:07:31 adamdunkels Exp $ * @(#)$Id: button-sensor.c,v 1.4 2010/01/14 17:39:35 nifi Exp $
*/ */
#include "contiki-esb.h" #include "dev/button-sensor.h"
#include "dev/hwconf.h"
#include <signal.h>
const struct sensors_sensor button_sensor; const struct sensors_sensor button_sensor;
@ -41,68 +43,61 @@ HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7); HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void interrupt(PORT2_VECTOR)
init(void) irq_p2(void)
{ {
timer_set(&debouncetimer, 0); ENERGEST_ON(ENERGEST_TYPE_IRQ);
BUTTON_IRQ_EDGE_SELECTD();
BUTTON_SELECT();
BUTTON_MAKE_INPUT();
}
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
if(BUTTON_CHECK_IRQ()) { if(BUTTON_CHECK_IRQ()) {
if(timer_expired(&debouncetimer)) { if(timer_expired(&debouncetimer)) {
timer_set(&debouncetimer, CLOCK_SECOND / 4); timer_set(&debouncetimer, CLOCK_SECOND / 4);
sensors_changed(&button_sensor); sensors_changed(&button_sensor);
return 1; LPM4_EXIT;
} }
} }
P2IFG = 0x00;
return 0; ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
sensors_add_irq(&button_sensor, BUTTON_IRQ_PORT());
BUTTON_ENABLE_IRQ();
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
BUTTON_DISABLE_IRQ();
sensors_remove_irq(&button_sensor, BUTTON_IRQ_PORT());
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return BUTTON_IRQ_ENABLED();
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
return BUTTON_READ() || !timer_expired(&debouncetimer); return BUTTON_READ() || !timer_expired(&debouncetimer);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
switch (type) {
case SENSORS_HW_INIT:
BUTTON_IRQ_EDGE_SELECTD();
BUTTON_SELECT();
BUTTON_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!BUTTON_IRQ_ENABLED()) {
timer_set(&debouncetimer, 0);
BUTTON_ENABLE_IRQ();
}
} else {
BUTTON_DISABLE_IRQ();
}
return 1;
}
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return NULL; switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return BUTTON_IRQ_ENABLED();
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: ctsrts-sensor.c,v 1.1 2006/06/18 07:49:33 adamdunkels Exp $ * @(#)$Id: ctsrts-sensor.c,v 1.2 2010/01/14 17:39:35 nifi Exp $
*/ */
/** /**
@ -40,7 +40,10 @@
* handshake but as said, that is not implemented yet. * handshake but as said, that is not implemented yet.
*/ */
#include "contiki-esb.h" #include "dev/ctsrts-sensor.h"
#include "dev/irq.h"
#include "dev/hwconf.h"
#include <signal.h>
const struct sensors_sensor ctsrts_sensor; const struct sensors_sensor ctsrts_sensor;
@ -49,83 +52,21 @@ HWCONF_PIN(RS232RTS, 1, 7);
HWCONF_PIN(RS232CTS, 1, 6); HWCONF_PIN(RS232CTS, 1, 6);
HWCONF_IRQ(RS232CTS, 1, 6); HWCONF_IRQ(RS232CTS, 1, 6);
/*---------------------------------------------------------------------------*/
static void
init(void)
{
RS232RTS_SELECT();
RS232RTS_MAKE_OUTPUT();
RS232RTS_CLEAR();
RS232CTS_SELECT();
RS232CTS_MAKE_INPUT();
}
/**
* Indicate to host/client we are NOT ready to receive data. Sets the RTS pin
* to low.
*/
void ctsrts_rts_clear(void) {
RS232RTS_CLEAR();
}
/**
* Request host/client to send data. Sets the RTS pin to high.
*/
void ctsrts_rts_set(void) {
RS232RTS_SET();
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void) irq(void)
{ {
if(RS232CTS_CHECK_IRQ()) { /* Change the flank triggering for the irq so we will detect next shift. */
/* Change the flank triggering for the irq so we will detect next
shift. */
if(RS232CTS_READ()) {
RS232CTS_IRQ_EDGE_SELECTD();
} else {
RS232CTS_IRQ_EDGE_SELECTU();
}
sensors_changed(&ctsrts_sensor);
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
/*
* Check current status on the CTS pin and set IRQ flank so we will detect
* a shift.
*/
if(RS232CTS_READ()) { if(RS232CTS_READ()) {
RS232CTS_IRQ_EDGE_SELECTD(); RS232CTS_IRQ_EDGE_SELECTD();
} else { } else {
RS232CTS_IRQ_EDGE_SELECTU(); RS232CTS_IRQ_EDGE_SELECTU();
} }
sensors_changed(&ctsrts_sensor);
sensors_add_irq(&ctsrts_sensor, RS232CTS_IRQ_PORT()); return 1;
RS232CTS_ENABLE_IRQ();
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
RS232CTS_DISABLE_IRQ();
sensors_remove_irq(&ctsrts_sensor, RS232CTS_IRQ_PORT());
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return RS232CTS_IRQ_ENABLED();
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
/* /*
@ -135,21 +76,71 @@ value(int type)
* the PC I set RTS which is coupled to the CTS on the esb and I read a 0. * the PC I set RTS which is coupled to the CTS on the esb and I read a 0.
* Maybe RTS is defined active LOW on the PC? //Kalle * Maybe RTS is defined active LOW on the PC? //Kalle
*/ */
return RS232CTS_READ()?0:1; return RS232CTS_READ() ? 0 : 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
switch (type) {
case SENSORS_HW_INIT:
RS232RTS_SELECT();
RS232RTS_MAKE_OUTPUT();
RS232RTS_CLEAR();
RS232CTS_SELECT();
RS232CTS_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!RS232CTS_IRQ_ENABLED()) {
/*
* Check current status on the CTS pin and set IRQ flank so we
* will detect a shift.
*/
if(RS232CTS_READ()) {
RS232CTS_IRQ_EDGE_SELECTD();
} else {
RS232CTS_IRQ_EDGE_SELECTU();
}
irq_port1_activate(RS232CTS_IRQ_PORT(), irq);
RS232CTS_ENABLE_IRQ();
}
} else {
RS232CTS_DISABLE_IRQ();
irq_port1_deactivate(RS232CTS_IRQ_PORT());
}
return 1;
}
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return NULL; switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return RS232CTS_IRQ_ENABLED();
}
return 0;
}
/*---------------------------------------------------------------------------*/
/**
* Indicate to host/client we are NOT ready to receive data. Sets the RTS pin
* to low.
*/
void ctsrts_rts_clear(void) {
RS232RTS_CLEAR();
}
/*---------------------------------------------------------------------------*/
/**
* Request host/client to send data. Sets the RTS pin to high.
*/
void ctsrts_rts_set(void) {
RS232RTS_SET();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(ctsrts_sensor, CTSRTS_SENSOR, SENSORS_SENSOR(ctsrts_sensor, CTSRTS_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: ctsrts-sensor.h,v 1.1 2006/06/18 07:49:33 adamdunkels Exp $ * @(#)$Id: ctsrts-sensor.h,v 1.2 2010/01/14 17:39:35 nifi Exp $
*/ */
/** /**
@ -42,7 +42,7 @@
#ifndef __CTSRTS_SENSOR_H__ #ifndef __CTSRTS_SENSOR_H__
#define __CTSRTS_SENSOR_H__ #define __CTSRTS_SENSOR_H__
#include "contiki-esb.h" #include "lib/sensors.h"
extern const struct sensors_sensor ctsrts_sensor; extern const struct sensors_sensor ctsrts_sensor;

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: esb-sensors.c,v 1.2 2007/03/19 00:34:43 adamdunkels Exp $ * $Id: esb-sensors.c,v 1.3 2010/01/14 17:39:35 nifi Exp $
*/ */
/** /**
@ -41,7 +41,9 @@
* sufficient for now. * sufficient for now.
*/ */
#include "contiki-esb.h" #include "dev/hwconf.h"
#include "dev/irq.h"
#include "sys/energest.h"
HWCONF_PIN(SENSORSWITCH, 5, 5); HWCONF_PIN(SENSORSWITCH, 5, 5);
@ -51,6 +53,8 @@ esb_sensors_init(void)
{ {
SENSORSWITCH_SELECT(); SENSORSWITCH_SELECT();
SENSORSWITCH_MAKE_OUTPUT(); SENSORSWITCH_MAKE_OUTPUT();
irq_init();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void

218
platform/esb/dev/irq.c Normal file
View file

@ -0,0 +1,218 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: irq.c,v 1.4 2010/01/14 17:39:35 nifi Exp $
*/
#include "lib/sensors.h"
#include "dev/irq.h"
#include "dev/lpm.h"
#include <signal.h>
#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
static int (* adc12_irq[8])(void);
static int (* port1_irq[8])(void);
static unsigned char adcflags;
/*---------------------------------------------------------------------------*/
interrupt(PORT1_VECTOR)
irq_p1(void)
{
int i;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
for(i = 0; i < 8; i++) {
if((P1IFG & (1 << i)) && port1_irq[i] != NULL) {
if((port1_irq[i])()) {
LPM4_EXIT;
}
}
}
P1IFG = 0x00;
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
interrupt (ADC_VECTOR)
irq_adc(void)
{
int i;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
for(i = 0; i < 8; i++) {
if(adc12_irq[i] != NULL) {
if((adc12_irq[i])()) {
LPM4_EXIT;
}
}
}
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
void
irq_init(void)
{
int i;
adcflags = 0;
for(i = 0; i < 8; i++) {
adc12_irq[i] = NULL;
port1_irq[i] = NULL;
}
/* Setup ADC12, ref., sampling time */
ADC12CTL0 = REF2_5V | SHT0_10 | SHT1_10 | MSC;
/* Use sampling timer, repeat-sequence-of-channels */
/* ADC12CTL1 = SHP | CONSEQ_3 | ADC12DIV_3; */
ADC12CTL1 = SHP | CONSEQ_3 | ADC12DIV_7;
}
/*---------------------------------------------------------------------------*/
void
irq_port1_activate(unsigned char irqno, int (* irq)(void))
{
if(irqno < 8) {
port1_irq[irqno] = irq;
}
}
/*---------------------------------------------------------------------------*/
void
irq_port1_deactivate(unsigned char irqno)
{
if(irqno < 8) {
port1_irq[irqno] = NULL;
}
}
/*---------------------------------------------------------------------------*/
/* Set lowest ADC to be start in sequence and highest to be interrupt
enabled and set end-of-sequence on the highest active ADC */
static void
sethilo(void)
{
int c;
/* Clear start of sequence */
ADC12CTL1 &= ~(CSTARTADD_15);
/* Set new start of sequence to lowest active memory holder */
for(c = 0; c < 8; c++) {
if(adcflags & (1 << c)) {
ADC12CTL1 |= (c * CSTARTADD_1);
break;
}
}
/* Clear all interrupts and end-of-sequences */
ADC12IE = 0;
for(c = 0; c < 8; c++) {
ADC12MCTL_NO(c) &= ~EOS;
}
/* Set highest interrupt and end-of-sequence. This will generate one
interrupt for each sequence of conversions. */
for(c = 0; c < 8; c++) {
if(adcflags & (128 >> c)) {
ADC12IE |= 128 >> c;
ADC12MCTL_NO(7 - c) |= EOS;
break;
}
}
}
/*---------------------------------------------------------------------------*/
void
irq_adc12_activate(unsigned char adcno, unsigned char config,
int (* irq)(void))
{
if(adcno >= 8) {
return;
}
/* stop converting */
ADC12CTL0 &= ~ENC;
/* wait for conversion to stop */
while(ADC12CTL0 & ADC12BUSY);
ADC12CTL0 &= ~(ADC12ON | REFON);
ADC12IE = 0;
/* clear any pending interrupts */
ADC12IFG = 0;
adcflags |= (1 << adcno);
ADC12MCTL_NO(adcno) = config;
sethilo();
ADC12CTL0 |= ADC12ON | REFON;
adc12_irq[adcno] = irq;
/* Delay */
clock_delay(20000);
ADC12CTL0 |= ENC | ADC12SC;
}
/*---------------------------------------------------------------------------*/
void
irq_adc12_deactivate(unsigned char adcno)
{
if(adcno >= 8) {
return;
}
/* stop converting */
ADC12CTL0 &= ~ENC;
/* wait for conversion to stop */
while(ADC12CTL0 & ADC12BUSY);
ADC12CTL0 &= ~(ADC12ON | REFON);
ADC12IE = 0;
/* clear any pending interrupts */
ADC12IFG = 0;
adcflags &= ~(1 << adcno);
ADC12MCTL_NO(adcno) = 0;
sethilo();
adc12_irq[adcno] = NULL;
if(adcflags) {
/* Turn on the ADC12 */
ADC12CTL0 |= (ADC12ON | REFON);
/* Delay */
clock_delay(20000);
/* Still active. Turn on the conversion. */
ADC12CTL0 |= ENC | ADC12SC;
}
}
/*---------------------------------------------------------------------------*/
int
irq_adc12_active(unsigned char adcno)
{
return adcflags & (1 << adcno) ? 1 : 0;
}
/*---------------------------------------------------------------------------*/

47
platform/esb/dev/irq.h Normal file
View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: irq.h,v 1.3 2010/01/14 17:39:35 nifi Exp $
*/
#ifndef __IRQ_H__
#define __IRQ_H__
void irq_init(void);
void irq_port1_activate(unsigned char irqno, int (* irq)(void));
void irq_port1_deactivate(unsigned char irqno);
void irq_adc12_activate(unsigned char adcno, unsigned char config,
int (* irq)(void));
void irq_adc12_deactivate(unsigned char adcno);
int irq_adc12_active(unsigned char adcno);
#endif /* __IRQ_H__ */

View file

@ -28,85 +28,70 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: pir-sensor.c,v 1.2 2006/10/09 21:08:51 nifi Exp $ * @(#)$Id: pir-sensor.c,v 1.3 2010/01/14 17:39:35 nifi Exp $
*/ */
#include "contiki-esb.h" #include "dev/pir-sensor.h"
#include "dev/irq.h"
#include "dev/hwconf.h"
const struct sensors_sensor pir_sensor; const struct sensors_sensor pir_sensor;
static unsigned int pir; static unsigned int pir;
static unsigned char flags;
HWCONF_PIN(PIR, 1, 3); #define PIR_IRQ() 3
HWCONF_IRQ(PIR, 1, 3); HWCONF_PIN(PIR, 1, PIR_IRQ());
HWCONF_IRQ(PIR, 1, PIR_IRQ());
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void) irq(void)
{ {
if(PIR_CHECK_IRQ()) { ++pir;
++pir; sensors_changed(&pir_sensor);
if(flags & PIR_ENABLE_EVENT) { return 1;
sensors_changed(&pir_sensor);
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void
init(void)
{
flags = PIR_ENABLE_EVENT;
pir = 0;
PIR_SELECT();
PIR_MAKE_INPUT();
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
sensors_add_irq(&pir_sensor, PIR_IRQ_PORT());
PIR_ENABLE_IRQ();
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
PIR_DISABLE_IRQ();
sensors_remove_irq(&pir_sensor, PIR_IRQ_PORT());
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return PIR_IRQ_ENABLED();
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
return pir; return pir;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
if(c) { switch (type) {
flags |= type & 0xff; case SENSORS_HW_INIT:
} else { pir = 0;
flags &= ~type & 0xff; PIR_SELECT();
PIR_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!PIR_IRQ_ENABLED()) {
irq_port1_activate(PIR_IRQ(), irq);
PIR_ENABLE_IRQ();
}
} else {
PIR_DISABLE_IRQ();
irq_port1_deactivate(PIR_IRQ());
}
return 1;
} }
return 1; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return (void *) (((int) (flags & type)) & 0xff); switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return PIR_IRQ_ENABLED();
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(pir_sensor, PIR_SENSOR, SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,17 +28,15 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: pir-sensor.h,v 1.2 2006/10/09 21:08:51 nifi Exp $ * @(#)$Id: pir-sensor.h,v 1.3 2010/01/14 17:39:35 nifi Exp $
*/ */
#ifndef __PIR_SENSOR_H__ #ifndef __PIR_SENSOR_H__
#define __PIR_SENSOR_H__ #define __PIR_SENSOR_H__
#include "contiki-esb.h" #include "lib/sensors.h"
extern const struct sensors_sensor pir_sensor; extern const struct sensors_sensor pir_sensor;
#define PIR_SENSOR "PIR" #define PIR_SENSOR "PIR"
#define PIR_ENABLE_EVENT 1
#endif /* __PIR_SENSOR_H__ */ #endif /* __PIR_SENSOR_H__ */

View file

@ -28,56 +28,26 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: radio-sensor.c,v 1.3 2007/11/28 21:26:35 nifi Exp $ * @(#)$Id: radio-sensor.c,v 1.4 2010/01/14 17:39:35 nifi Exp $
*/ */
#include "contiki-esb.h" #include "dev/radio-sensor.h"
#include "dev/irq.h" #include "dev/irq.h"
#include <io.h>
#include "dev/tr1001.h" #include "dev/tr1001.h"
const struct sensors_sensor radio_sensor; const struct sensors_sensor radio_sensor;
unsigned int radio_sensor_signal; unsigned int radio_sensor_signal;
/*---------------------------------------------------------------------------*/
static void
init(void)
{
/* Initialization of ADC12 done by irq */
radio_sensor_signal = 0;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void) irq(void)
{ {
radio_sensor_signal = ADC12MEM5; radio_sensor_signal = ADC12MEM5;
/* sensors_changed(&radio_sensor);*/
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void
activate(void)
{
irq_adc12_activate(&radio_sensor, 5, INCH_5 + SREF_0);
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
irq_adc12_deactivate(&radio_sensor, 5);
radio_sensor_signal = 0;
}
/*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return irq_adc12_active(5);
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
switch(type) { switch(type) {
@ -85,22 +55,42 @@ value(int type)
return tr1001_sstrength(); return tr1001_sstrength();
case RADIO_SENSOR_LAST_VALUE: case RADIO_SENSOR_LAST_VALUE:
default: default:
return ADC12MEM5; /* radio_sensor_signal; */ return radio_sensor_signal;
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
switch (type) {
case SENSORS_HW_INIT:
/* Initialization of ADC12 done by irq */
radio_sensor_signal = 0;
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!irq_adc12_active(5)) {
irq_adc12_activate(5, (INCH_5 + SREF_0), irq);
}
} else {
irq_adc12_deactivate(5);
radio_sensor_signal = 0;
}
return 1;
}
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return NULL; switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return irq_adc12_active(5);
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR, SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,10 +28,10 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: sound-sensor.c,v 1.3 2008/07/08 12:35:05 nifi Exp $ * @(#)$Id: sound-sensor.c,v 1.4 2010/01/14 17:39:35 nifi Exp $
*/ */
#include <stdlib.h> #include <stdlib.h>
#include "contiki-esb.h" #include "dev/sound-sensor.h"
#include "dev/irq.h" #include "dev/irq.h"
#define MIC_MIN_SENS 150 #define MIC_MIN_SENS 150
@ -40,7 +40,6 @@
const struct sensors_sensor sound_sensor; const struct sensors_sensor sound_sensor;
static unsigned int sound, micdiff, micmax, avgmax; static unsigned int sound, micdiff, micmax, avgmax;
char sound_pause;
static int8_t mode; static int8_t mode;
static int8_t sample_div; static int8_t sample_div;
static int8_t ctr; static int8_t ctr;
@ -48,35 +47,25 @@ static int16_t *sample_buffer;
static int buffer_size; static int buffer_size;
static int buf_pos; static int buf_pos;
/*---------------------------------------------------------------------------*/
static void
init(void)
{
/* Initialization of ADC12 done by irq */
mode = 0;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void) irq(void)
{ {
micdiff = micdiff + abs(ADC12MEM4 - sound) - (micdiff >> 3);
sound = ADC12MEM4;
if (!sound_pause) { if(mode == SAMPLE) {
micdiff = micdiff + abs(ADC12MEM4 - sound) - (micdiff >> 3); ctr++;
if(ctr >= sample_div) {
if(mode == SAMPLE) { ctr = 0;
leds_invert(LEDS_RED); sample_buffer[buf_pos++] = sound;
ctr++; if(buf_pos >= buffer_size) {
if(ctr >= sample_div) { mode = 0;
ctr = 0; sensors_changed(&sound_sensor);
sample_buffer[buf_pos++] = ADC12MEM4; return 1;
if(buf_pos >= buffer_size) {
mode = 0;
leds_off(LEDS_RED);
sensors_changed(&sound_sensor);
}
} }
} }
}
/* if (micdiff > MIC_MIN_SENS) { */ /* if (micdiff > MIC_MIN_SENS) { */
/* sensors_changed(&sound_sensor); */ /* sensors_changed(&sound_sensor); */
@ -91,8 +80,6 @@ irq(void)
/* if (micmax < micdiff) { */ /* if (micmax < micdiff) { */
/* micmax = micdiff; */ /* micmax = micdiff; */
/* } */ /* } */
}
/* if (micdiff > 2000) { */ /* if (micdiff > 2000) { */
/* leds_on(LEDS_GREEN); */ /* leds_on(LEDS_GREEN); */
@ -104,37 +91,10 @@ irq(void)
/* leds_on(LEDS_RED); */ /* leds_on(LEDS_RED); */
/* } */ /* } */
sound = ADC12MEM4;
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void
activate(void)
{
sound = micdiff = micmax = 0;
sound_pause = 0;
mode = 0;
ctr = 0;
sample_div = 0;
buf_pos = 0;
avgmax = 5000;
irq_adc12_activate(&sound_sensor, 4, INCH_0 + SREF_0);
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
irq_adc12_deactivate(&sound_sensor, 4);
}
/*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return irq_adc12_active(4);
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
/* try returning the max to see what values we get... */ /* try returning the max to see what values we get... */
@ -146,34 +106,62 @@ value(int type)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
if(type == SOUND_SET_BUFFER_PTR) { switch (type) {
sample_buffer = (int16_t *) c; case SENSORS_HW_INIT:
} else if (type == SOUND_SET_BUFFER_SIZE) { /* Initialization of ADC12 done by irq */
buffer_size = (int) c; mode = 0;
} else if (type == SOUND_SET_DIV) { buffer_size = 0;
sample_div = (int) c & 0xff; return 1;
} else if(type == SOUND_START_SAMPLE) { case SENSORS_ACTIVE:
if(buffer_size > 0) { if (value) {
leds_on(LEDS_RED); if(!irq_adc12_active(4)) {
buf_pos = 0; sound = micdiff = micmax = 0;
ctr = 0; mode = 0;
mode = SAMPLE; ctr = 0;
sample_div = 0;
buf_pos = 0;
avgmax = 5000;
irq_adc12_activate(4, (INCH_0 + SREF_0), irq);
}
} else {
irq_adc12_deactivate(4);
} }
return 1;
} }
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
if(type == SOUND_SAMPLING) { switch (type) {
return (void *) (mode == SAMPLE); case SENSORS_ACTIVE:
return irq_adc12_active(4);
case SENSORS_READY:
return (mode != SAMPLE) && irq_adc12_active(4);
} }
return NULL; return 0;
}
/*---------------------------------------------------------------------------*/
void
sound_sensor_start_sample(void)
{
if(buffer_size > 0) {
buf_pos = 0;
ctr = 0;
mode = SAMPLE;
}
}
/*---------------------------------------------------------------------------*/
void
sound_sensor_set_buffer(int16_t *buffer, int buf_size, int divider)
{
sample_buffer = buffer;
buffer_size = buf_size;
sample_div = divider;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(sound_sensor, SOUND_SENSOR, SENSORS_SENSOR(sound_sensor, SOUND_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,20 +28,18 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: sound-sensor.h,v 1.2 2008/04/25 15:55:37 joxe Exp $ * @(#)$Id: sound-sensor.h,v 1.3 2010/01/14 17:39:35 nifi Exp $
*/ */
#ifndef __SOUND_SENSOR_H__ #ifndef __SOUND_SENSOR_H__
#define __SOUND_SENSOR_H__ #define __SOUND_SENSOR_H__
#include "contiki-esb.h" #include "lib/sensors.h"
extern const struct sensors_sensor sound_sensor; extern const struct sensors_sensor sound_sensor;
#define SOUND_SENSOR "Sound" #define SOUND_SENSOR "Sound"
#define SOUND_SET_BUFFER_PTR 1
#define SOUND_SET_BUFFER_SIZE 2 void sound_sensor_start_sample();
#define SOUND_START_SAMPLE 3 void sound_sensor_set_buffer(int16_t *buffer, int buf_size, int divider);
#define SOUND_SET_DIV 4
#define SOUND_SAMPLING 1
#endif /* __SOUND_SENSOR_H__ */ #endif /* __SOUND_SENSOR_H__ */

View file

@ -26,76 +26,66 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: temperature-sensor.c,v 1.1 2006/06/18 07:49:33 adamdunkels Exp $ * $Id: temperature-sensor.c,v 1.2 2010/01/14 17:39:35 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01 * Created : 2005-11-01
* Updated : $Date: 2006/06/18 07:49:33 $ * Updated : $Date: 2010/01/14 17:39:35 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
#include "dev/temperature-sensor.h" #include "dev/temperature-sensor.h"
#include "dev/ds1629.h" #include "dev/ds1629.h"
const struct sensors_sensor temperature_sensor; const struct sensors_sensor temperature_sensor;
static unsigned char flags; static int active;
/*---------------------------------------------------------------------------*/
static void
init(void)
{
flags = 0;
ds1629_init();
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
flags |= 1;
ds1629_start();
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
flags &= ~1;
}
/*---------------------------------------------------------------------------*/
static int
active(void)
{
return (flags & 1);
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
unsigned int temp; unsigned int temp;
signed int t = ds1629_temperature(); signed int t;
t = ds1629_temperature();
temp = ((t / 128) * 50); temp = ((t / 128) * 50);
return temp; return temp;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
switch (type) {
case SENSORS_HW_INIT:
active = 0;
ds1629_init();
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!active) {
active = 1;
ds1629_start();
}
} else {
active = 0;
}
return 1;
}
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return NULL; switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return active;
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR, SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,85 +28,70 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: vib-sensor.c,v 1.3 2007/03/28 09:58:47 nifi Exp $ * @(#)$Id: vib-sensor.c,v 1.4 2010/01/14 17:39:35 nifi Exp $
*/ */
#include "contiki-esb.h" #include "dev/vib-sensor.h"
#include "dev/irq.h"
#include "dev/hwconf.h"
const struct sensors_sensor vib_sensor; const struct sensors_sensor vib_sensor;
static unsigned int vib; static unsigned int vib;
static unsigned char flags;
HWCONF_PIN(VIB, 1, 4); #define VIB_IRQ() 4
HWCONF_IRQ(VIB, 1, 4); HWCONF_PIN(VIB, 1, VIB_IRQ());
HWCONF_IRQ(VIB, 1, VIB_IRQ());
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
irq(void) irq(void)
{ {
if(VIB_CHECK_IRQ()) { ++vib;
++vib; sensors_changed(&vib_sensor);
if(flags & VIB_ENABLE_EVENT) { return 1;
sensors_changed(&vib_sensor);
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void
init(void)
{
flags = VIB_ENABLE_EVENT;
vib = 0;
VIB_SELECT();
VIB_MAKE_INPUT();
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
sensors_add_irq(&vib_sensor, VIB_IRQ_PORT());
VIB_ENABLE_IRQ();
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
VIB_DISABLE_IRQ();
sensors_remove_irq(&vib_sensor, VIB_IRQ_PORT());
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
active(void)
{
return VIB_IRQ_ENABLED();
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type) value(int type)
{ {
return vib; return vib;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, void *c) configure(int type, int value)
{ {
if(c) { switch (type) {
flags |= type & 0xff; case SENSORS_HW_INIT:
} else { vib = 0;
flags &= ~type & 0xff; VIB_SELECT();
VIB_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if (value) {
if(!VIB_IRQ_ENABLED()) {
irq_port1_activate(VIB_IRQ(), irq);
VIB_ENABLE_IRQ();
}
} else {
VIB_DISABLE_IRQ();
irq_port1_deactivate(VIB_IRQ());
}
return 1;
} }
return 1; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void * static int
status(int type) status(int type)
{ {
return (void *) (((int) (flags & type)) & 0xff); switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return VIB_IRQ_ENABLED();
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(vib_sensor, VIB_SENSOR, SENSORS_SENSOR(vib_sensor, VIB_SENSOR,
init, irq, activate, deactivate, active, value, configure, status);
value, configure, status);

View file

@ -28,17 +28,15 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: vib-sensor.h,v 1.2 2006/10/09 21:08:51 nifi Exp $ * @(#)$Id: vib-sensor.h,v 1.3 2010/01/14 17:39:35 nifi Exp $
*/ */
#ifndef __VIB_SENSOR_H__ #ifndef __VIB_SENSOR_H__
#define __VIB_SENSOR_H__ #define __VIB_SENSOR_H__
#include "contiki-esb.h" #include "lib/sensors.h"
extern const struct sensors_sensor vib_sensor; extern const struct sensors_sensor vib_sensor;
#define VIB_SENSOR "Vibration" #define VIB_SENSOR "Vibration"
#define VIB_ENABLE_EVENT 1
#endif /* __VIB_SENSOR_H__ */ #endif /* __VIB_SENSOR_H__ */