Moved the ADC configuration to sky-sensors.c and sensors now only need to specify their sample channel. This helps to avoid conflicts when using multiple sensors.
This commit is contained in:
parent
d06a1ecc0c
commit
198db63c3b
|
@ -1,11 +1,11 @@
|
||||||
# $Id: Makefile.jcreate,v 1.2 2010/05/27 12:42:49 nifi Exp $
|
# $Id: Makefile.jcreate,v 1.3 2010/08/25 19:34:42 nifi Exp $
|
||||||
|
|
||||||
# Some drivers such as ds2411.c only compile under platform sky
|
# Some drivers such as ds2411.c only compile under platform sky
|
||||||
CFLAGS += -DCONTIKI_TARGET_SKY
|
CFLAGS += -DCONTIKI_TARGET_SKY
|
||||||
|
|
||||||
CONTIKI_TARGET_SOURCEFILES += contiki-jcreate-platform.c \
|
CONTIKI_TARGET_SOURCEFILES += contiki-jcreate-platform.c \
|
||||||
battery-sensor.c radio-sensor.c \
|
battery-sensor.c radio-sensor.c \
|
||||||
acc-sensor.c ext-sensor.c
|
temperature-sensor.c acc-sensor.c ext-sensor.c
|
||||||
|
|
||||||
include $(CONTIKI)/platform/sky/Makefile.common
|
include $(CONTIKI)/platform/sky/Makefile.common
|
||||||
|
|
||||||
|
|
|
@ -26,67 +26,41 @@
|
||||||
* 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: acc-sensor.c,v 1.1 2010/05/03 21:57:35 nifi Exp $
|
* $Id: acc-sensor.c,v 1.2 2010/08/25 19:34:42 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: 2010/05/03 21:57:35 $
|
* Updated : $Date: 2010/08/25 19:34:42 $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dev/acc-sensor.h"
|
#include "dev/acc-sensor.h"
|
||||||
#include "dev/sky-sensors.h"
|
#include "dev/sky-sensors.h"
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
|
||||||
|
/* Configure ADC12_2 to sample channel 4, 5, 6 and use */
|
||||||
|
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
||||||
|
#define INPUT_CHANNEL ((1 << INCH_4) | (1 << INCH_5) | (1 << INCH_6))
|
||||||
|
#define INPUT_REFERENCE SREF_1
|
||||||
|
#define ACC_MEM_X ADC12MEM4 /* Xout */
|
||||||
|
#define ACC_MEM_Y ADC12MEM5 /* Yout */
|
||||||
|
#define ACC_MEM_Z ADC12MEM6 /* Zout */
|
||||||
|
|
||||||
const struct sensors_sensor acc_sensor;
|
const struct sensors_sensor acc_sensor;
|
||||||
static uint8_t active;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
activate(void)
|
|
||||||
{
|
|
||||||
P2DIR |= 0x48;
|
|
||||||
P2OUT |= 0x48;
|
|
||||||
|
|
||||||
/* stop converting immediately */
|
|
||||||
ADC12CTL0 &= ~ENC;
|
|
||||||
ADC12CTL1 &= ~CONSEQ_3;
|
|
||||||
|
|
||||||
while(ADC12CTL1 & ADC12BUSY);
|
|
||||||
|
|
||||||
/* Configure ADC12_2 to sample channel 4, 5, 6 and use */
|
|
||||||
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
|
||||||
ADC12MCTL2 = (INCH_4 + SREF_1);
|
|
||||||
ADC12MCTL3 = (INCH_5 + SREF_1);
|
|
||||||
ADC12MCTL4 = (INCH_6 + SREF_1);
|
|
||||||
/* internal temperature can be read as value(3) */
|
|
||||||
ADC12MCTL5 = (INCH_10 + SREF_1);
|
|
||||||
|
|
||||||
active = 1;
|
|
||||||
sky_sensors_activate(0x70);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
deactivate(void)
|
|
||||||
{
|
|
||||||
sky_sensors_deactivate(0x70);
|
|
||||||
active = 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case 0:
|
case ACC_SENSOR_X:
|
||||||
return ADC12MEM2;
|
return ACC_MEM_X;
|
||||||
case 1:
|
case ACC_SENSOR_Y:
|
||||||
return ADC12MEM3;
|
return ACC_MEM_Y;
|
||||||
case 2:
|
case ACC_SENSOR_Z:
|
||||||
return ADC12MEM4;
|
return ACC_MEM_Z;
|
||||||
case 3:
|
|
||||||
return ADC12MEM5;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -94,28 +68,31 @@ value(int type)
|
||||||
static int
|
static int
|
||||||
configure(int type, int c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
switch(type) {
|
if(type == SENSORS_ACTIVE) {
|
||||||
case SENSORS_ACTIVE:
|
/* Sleep Mode P2.3 */
|
||||||
if (c) {
|
if(c) {
|
||||||
if(!active) {
|
P2OUT |= 0x08;
|
||||||
activate();
|
P2DIR |= 0x08;
|
||||||
}
|
} else {
|
||||||
} else if(active) {
|
/* Sensor deactivated. Changed to sleep mode. */
|
||||||
deactivate();
|
P2OUT &= ~0x08;
|
||||||
}
|
}
|
||||||
|
} else if(type == ACC_SENSOR_SENSITIVITY) {
|
||||||
|
/* g-Select1 P2.0, g-Select2 P2.1 */
|
||||||
|
P2DIR |= 0x03;
|
||||||
|
P2OUT &= ~0x03;
|
||||||
|
P2OUT |= c & 0x03;
|
||||||
}
|
}
|
||||||
return 0;
|
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
if(type == ACC_SENSOR_SENSITIVITY) {
|
||||||
case SENSORS_ACTIVE:
|
return (P2OUT & P2DIR) & 0x03;
|
||||||
case SENSORS_READY:
|
|
||||||
return active;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
SENSORS_SENSOR(acc_sensor, ACC_SENSOR, value, configure, status);
|
SENSORS_SENSOR(acc_sensor, ACC_SENSOR, value, configure, status);
|
||||||
|
|
|
@ -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: acc-sensor.h,v 1.1 2010/05/03 21:57:35 nifi Exp $
|
* $Id: acc-sensor.h,v 1.2 2010/08/25 19:34:42 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: 2010/05/03 21:57:35 $
|
* Updated : $Date: 2010/08/25 19:34:42 $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __ACC_SENSOR_H__
|
#ifndef __ACC_SENSOR_H__
|
||||||
|
@ -45,4 +45,18 @@ extern const struct sensors_sensor acc_sensor;
|
||||||
|
|
||||||
#define ACC_SENSOR "Acc"
|
#define ACC_SENSOR "Acc"
|
||||||
|
|
||||||
|
#define ACC_SENSOR_X 0
|
||||||
|
#define ACC_SENSOR_Y 1
|
||||||
|
#define ACC_SENSOR_Z 2
|
||||||
|
|
||||||
|
/*
|
||||||
|
Sensitivity configuration (g-Select1 and g-Select2)
|
||||||
|
Value g-Range Sensitivity
|
||||||
|
0 1.5g 800mV/g
|
||||||
|
1 2g 600mV/g
|
||||||
|
2 4g 300mV/g
|
||||||
|
3 6g 200mV/g
|
||||||
|
*/
|
||||||
|
#define ACC_SENSOR_SENSITIVITY 10
|
||||||
|
|
||||||
#endif /* __ACC_SENSOR_H__ */
|
#endif /* __ACC_SENSOR_H__ */
|
||||||
|
|
|
@ -26,15 +26,15 @@
|
||||||
* 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: ext-sensor.c,v 1.1 2010/05/03 21:57:35 nifi Exp $
|
* $Id: ext-sensor.c,v 1.2 2010/08/25 19:34:42 nifi Exp $
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------
|
* -----------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Marcus Lundén,
|
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Marcus Lundén,
|
||||||
* Jesper Karlsson
|
* Jesper Karlsson
|
||||||
* Created : 2005-11-01
|
* Created : 2005-11-01
|
||||||
* Updated : $Date: 2010/05/03 21:57:35 $
|
* Updated : $Date: 2010/08/25 19:34:42 $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
@ -42,23 +42,38 @@
|
||||||
#include "dev/ext-sensor.h"
|
#include "dev/ext-sensor.h"
|
||||||
#include "dev/sky-sensors.h"
|
#include "dev/sky-sensors.h"
|
||||||
|
|
||||||
|
/* SREF_0 is AVCC */
|
||||||
|
/* SREF_1 is Vref+ */
|
||||||
|
/* ADC0 == P6.0/A0 == port "under" logo */
|
||||||
|
/* ADC1 == P6.1/A1 == port "over" logo */
|
||||||
|
/* ADC2 == P6.2/A2, bottom expansion port */
|
||||||
|
/* ADC3 == P6.1/A3, bottom expansion port, End Of (ADC-)Sequence */
|
||||||
|
|
||||||
|
#define INPUT_CHANNEL ((1 << INCH_0) | (1 << INCH_1) | \
|
||||||
|
(1 << INCH_2) | (1 << INCH_3))
|
||||||
|
#define INPUT_REFERENCE SREF_0
|
||||||
|
#define EXT_MEM0 ADC12MEM0
|
||||||
|
#define EXT_MEM1 ADC12MEM1
|
||||||
|
#define EXT_MEM2 ADC12MEM2
|
||||||
|
#define EXT_MEM3 ADC12MEM3
|
||||||
|
|
||||||
const struct sensors_sensor ext_sensor;
|
const struct sensors_sensor ext_sensor;
|
||||||
static uint8_t active;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
/* ADC0 corresponds to the port under the logo, ADC1 to the port over the logo,
|
/* ADC0 corresponds to the port under the logo, ADC1 to the port
|
||||||
ADC2 and ADC3 corresponds to port on the JCreate bottom expansion port) */
|
over the logo, ADC2 and ADC3 corresponds to port on the JCreate
|
||||||
|
bottom expansion port) */
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case ADC0:
|
case ADC0:
|
||||||
return ADC12MEM6;
|
return EXT_MEM0;
|
||||||
case ADC1:
|
case ADC1:
|
||||||
return ADC12MEM7;
|
return EXT_MEM1;
|
||||||
case ADC2:
|
case ADC2:
|
||||||
return ADC12MEM8;
|
return EXT_MEM2;
|
||||||
case ADC3:
|
case ADC3:
|
||||||
return ADC12MEM9;
|
return EXT_MEM3;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -66,40 +81,13 @@ value(int type)
|
||||||
static int
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, int c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
switch(type) {
|
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
if(c) {
|
|
||||||
if(!status(SENSORS_ACTIVE)) {
|
|
||||||
/* SREF_1 is Vref+ */
|
|
||||||
/* MemReg6 == P6.0/A0 == port "under" logo */
|
|
||||||
ADC12MCTL6 = (INCH_0 + SREF_0);
|
|
||||||
/* MemReg7 == P6.1/A1 == port "over" logo */
|
|
||||||
ADC12MCTL7 = (INCH_1 + SREF_0);
|
|
||||||
/* MemReg8 == P6.2/A2, bottom expansion port */
|
|
||||||
ADC12MCTL8 = (INCH_2 + SREF_0);
|
|
||||||
/* MemReg9 == P6.1/A3, bottom expansion port, End Of (ADC-)Sequence */
|
|
||||||
ADC12MCTL9 = (INCH_3 + SREF_0);
|
|
||||||
|
|
||||||
sky_sensors_activate(0x0F);
|
|
||||||
active = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sky_sensors_deactivate(0x0F);
|
|
||||||
active = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
SENSORS_SENSOR(ext_sensor, "Ext", value, configure, status);
|
SENSORS_SENSOR(ext_sensor, "Ext", value, configure, status);
|
||||||
|
|
|
@ -26,72 +26,44 @@
|
||||||
* 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.10 2010/02/03 20:30:07 nifi Exp $
|
* $Id: battery-sensor.c,v 1.11 2010/08/25 19:30:52 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: 2010/02/03 20:30:07 $
|
* Updated : $Date: 2010/08/25 19:30:52 $
|
||||||
* $Revision: 1.10 $
|
* $Revision: 1.11 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dev/battery-sensor.h"
|
#include "dev/battery-sensor.h"
|
||||||
#include "dev/sky-sensors.h"
|
#include "dev/sky-sensors.h"
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
|
||||||
|
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
|
||||||
|
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
||||||
|
#define INPUT_CHANNEL (1 << INCH_11)
|
||||||
|
#define INPUT_REFERENCE SREF_1
|
||||||
|
#define BATTERY_MEM ADC12MEM11
|
||||||
|
|
||||||
const struct sensors_sensor battery_sensor;
|
const struct sensors_sensor battery_sensor;
|
||||||
static uint8_t active;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
activate(void)
|
|
||||||
{
|
|
||||||
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
|
|
||||||
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
|
||||||
ADC12MCTL2 = (INCH_11 + SREF_1);
|
|
||||||
|
|
||||||
sky_sensors_activate(0x80);
|
|
||||||
|
|
||||||
active = 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
deactivate(void)
|
|
||||||
{
|
|
||||||
sky_sensors_deactivate(0x80);
|
|
||||||
active = 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
return ADC12MEM2/*battery_value*/;
|
return BATTERY_MEM;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, int c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
switch(type) {
|
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
if(c) {
|
|
||||||
activate();
|
|
||||||
} else {
|
|
||||||
deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
|
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
||||||
value, configure, status);
|
|
||||||
|
|
|
@ -28,16 +28,23 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: light-sensor.c,v 1.6 2010/02/08 00:02:39 nifi Exp $
|
* @(#)$Id: light-sensor.c,v 1.7 2010/08/25 19:30:53 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <io.h>
|
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
#include "dev/sky-sensors.h"
|
#include "dev/sky-sensors.h"
|
||||||
#include "dev/light-sensor.h"
|
#include "dev/light-sensor.h"
|
||||||
|
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
/* Photodiode 1 (P64) on INCH_4 */
|
||||||
|
/* Photodiode 2 (P65) on INCH_5 */
|
||||||
|
#define INPUT_CHANNEL ((1 << INCH_4) | (1 << INCH_5))
|
||||||
|
#define INPUT_REFERENCE SREF_0
|
||||||
|
#define PHOTOSYNTHETIC_MEM ADC12MEM4
|
||||||
|
#define TOTAL_SOLAR_MEM ADC12MEM5
|
||||||
|
|
||||||
const struct sensors_sensor light_sensor;
|
const struct sensors_sensor light_sensor;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -47,11 +54,11 @@ value(int type)
|
||||||
switch(type) {
|
switch(type) {
|
||||||
/* Photosynthetically Active Radiation. */
|
/* Photosynthetically Active Radiation. */
|
||||||
case LIGHT_SENSOR_PHOTOSYNTHETIC:
|
case LIGHT_SENSOR_PHOTOSYNTHETIC:
|
||||||
return ADC12MEM0;
|
return PHOTOSYNTHETIC_MEM;
|
||||||
|
|
||||||
/* Total Solar Radiation. */
|
/* Total Solar Radiation. */
|
||||||
case LIGHT_SENSOR_TOTAL_SOLAR:
|
case LIGHT_SENSOR_TOTAL_SOLAR:
|
||||||
return ADC12MEM1;
|
return TOTAL_SOLAR_MEM;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -59,34 +66,13 @@ value(int type)
|
||||||
static int
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
return (ADC12CTL0 & (ADC12ON + REFON)) == (ADC12ON + REFON);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
configure(int type, int c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
switch(type) {
|
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
if(c) {
|
|
||||||
if(!status(SENSORS_ACTIVE)) {
|
|
||||||
|
|
||||||
ADC12MCTL0 = (INCH_4 + SREF_0); // photodiode 1 (P64)
|
|
||||||
ADC12MCTL1 = (INCH_5 + SREF_0); // photodiode 2 (P65)
|
|
||||||
|
|
||||||
sky_sensors_activate(0x30);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sky_sensors_deactivate(0x30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
SENSORS_SENSOR(light_sensor, "Light",
|
SENSORS_SENSOR(light_sensor, "Light", value, configure, status);
|
||||||
value, configure, status);
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: radio-sensor.c,v 1.6 2010/01/14 20:01:19 nifi Exp $
|
* @(#)$Id: radio-sensor.c,v 1.7 2010/08/25 19:30:53 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
|
@ -36,6 +36,7 @@
|
||||||
#include "dev/radio-sensor.h"
|
#include "dev/radio-sensor.h"
|
||||||
|
|
||||||
const struct sensors_sensor radio_sensor;
|
const struct sensors_sensor radio_sensor;
|
||||||
|
static int active;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
|
@ -53,12 +54,21 @@ value(int type)
|
||||||
static int
|
static int
|
||||||
configure(int type, int c)
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
|
if(type == SENSORS_ACTIVE) {
|
||||||
|
active = c;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return active;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -28,68 +28,127 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: sky-sensors.c,v 1.2 2010/02/06 18:28:26 joxe Exp $
|
* $Id: sky-sensors.c,v 1.3 2010/08/25 19:30:53 nifi Exp $
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------
|
* -----------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Author : Joakim Eriksson
|
* Author : Joakim Eriksson
|
||||||
* Created : 2010-02-02
|
* Created : 2010-02-02
|
||||||
* Updated : $Date: 2010/02/06 18:28:26 $
|
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <io.h>
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
static uint8_t adc_on;
|
#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
|
||||||
|
|
||||||
|
static uint16_t adc_on;
|
||||||
|
static uint16_t ready;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
static CC_INLINE void
|
||||||
sky_sensors_activate(uint8_t type)
|
start(void)
|
||||||
{
|
{
|
||||||
uint8_t pre = adc_on;
|
uint16_t c, last;
|
||||||
|
|
||||||
adc_on |= type;
|
/* Set up the ADC. */
|
||||||
P6SEL |= type;
|
P6DIR = 0xff;
|
||||||
|
P6OUT = 0x00;
|
||||||
|
|
||||||
if(pre == 0 && adc_on > 0) {
|
/* Setup ADC12, ref., sampling time */
|
||||||
P6DIR = 0xff;
|
/* XXX Note according to the specification a minimum of 17 ms should
|
||||||
P6OUT = 0x00;
|
be allowed after turn on of the internal reference generator. */
|
||||||
|
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC + REFON;
|
||||||
|
/* Use sampling timer, repeat-sequence-of-channels */
|
||||||
|
ADC12CTL1 = SHP + CONSEQ_3;
|
||||||
|
|
||||||
/* if nothing was started before, start up the ADC system */
|
last = 15;
|
||||||
/* Set up the ADC. */
|
for(c = 0; c < 16; c++) {
|
||||||
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; /* Setup ADC12, ref., sampling time */
|
/* Clear all end-of-sequences */
|
||||||
ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; /* Use sampling timer, repeat-sequenc-of-channels */
|
ADC12MCTL_NO(c) &= ~EOS;
|
||||||
/* convert up to MEM4 */
|
if(adc_on & (1 << c)) {
|
||||||
ADC12MCTL9 |= EOS;
|
if(last == 15) {
|
||||||
|
/* Set new start of sequence to lowest active memory holder */
|
||||||
ADC12CTL0 |= ADC12ON + REFON;
|
ADC12CTL1 |= (c * CSTARTADD_1);
|
||||||
ADC12CTL0 |= ENC; /* enable conversion */
|
}
|
||||||
ADC12CTL0 |= ADC12SC; /* sample & convert */
|
last = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set highest end-of-sequence. */
|
||||||
|
ADC12MCTL_NO(last) |= EOS;
|
||||||
|
|
||||||
|
ADC12CTL0 |= ADC12ON;
|
||||||
|
ADC12CTL0 |= ENC; /* enable conversion */
|
||||||
|
ADC12CTL0 |= ADC12SC; /* sample & convert */
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
static CC_INLINE void
|
||||||
sky_sensors_deactivate(uint8_t type)
|
stop(void)
|
||||||
{
|
{
|
||||||
adc_on &= ~type;
|
/* stop converting immediately, turn off reference voltage, etc. */
|
||||||
|
|
||||||
if(adc_on == 0) {
|
ADC12CTL0 &= ~ENC;
|
||||||
/* stop converting immediately, turn off reference voltage, etc. */
|
/* need to remove CONSEQ_3 if not EOS is configured */
|
||||||
/* wait for conversion to stop */
|
ADC12CTL1 &= ~CONSEQ_3;
|
||||||
|
|
||||||
ADC12CTL0 &= ~ENC;
|
/* wait for conversion to stop */
|
||||||
/* need to remove CONSEQ_3 if not EOS is configured */
|
while(ADC12CTL1 & ADC12BUSY);
|
||||||
ADC12CTL1 &= ~CONSEQ_3;
|
|
||||||
|
|
||||||
while(ADC12CTL1 & ADC12BUSY);
|
/* clear any pending interrupts */
|
||||||
|
ADC12IFG = 0;
|
||||||
ADC12CTL0 = 0;
|
}
|
||||||
ADC12CTL1 = 0;
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
P6DIR = 0x00;
|
sky_sensors_status(uint16_t input, int type)
|
||||||
P6OUT = 0x00;
|
{
|
||||||
P6SEL = 0x00;
|
if(type == SENSORS_ACTIVE) {
|
||||||
}
|
return (adc_on & input) == input;
|
||||||
|
}
|
||||||
|
if(type == SENSORS_READY) {
|
||||||
|
ready |= ADC12IFG & adc_on & input;
|
||||||
|
return (ready & adc_on & input) == input;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
sky_sensors_configure(uint16_t input, uint8_t ref, int type, int value)
|
||||||
|
{
|
||||||
|
uint16_t c;
|
||||||
|
|
||||||
|
if(type == SENSORS_ACTIVE) {
|
||||||
|
stop();
|
||||||
|
|
||||||
|
if(value) {
|
||||||
|
adc_on |= input;
|
||||||
|
P6SEL |= input & 0xff;
|
||||||
|
|
||||||
|
/* Set ADC config */
|
||||||
|
for(c = 0; c < 16; c++) {
|
||||||
|
if(input & (1 << c)) {
|
||||||
|
ADC12MCTL_NO(c) = (c * INCH_1) | ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
adc_on &= ~input;
|
||||||
|
ready &= ~input;
|
||||||
|
P6SEL &= ~(input & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(adc_on == 0) {
|
||||||
|
P6DIR = 0x00;
|
||||||
|
P6SEL = 0x00;
|
||||||
|
|
||||||
|
/* Turn off ADC and internal reference generator */
|
||||||
|
ADC12CTL0 = 0;
|
||||||
|
ADC12CTL1 = 0;
|
||||||
|
} else {
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -27,20 +27,21 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
* $Id: sky-sensors.h,v 1.1 2010/02/02 20:59:45 joxe Exp $
|
* $Id: sky-sensors.h,v 1.2 2010/08/25 19:30:53 nifi Exp $
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------
|
* -----------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Author : Joakim Eriksson
|
* Author : Joakim Eriksson
|
||||||
* Created : 2010-02-02
|
* Created : 2010-02-02
|
||||||
* Updated : $Date: 2010/02/02 20:59:45 $
|
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __SKY_SENSORS_H__
|
#ifndef __SKY_SENSORS_H__
|
||||||
#define __SKY_SENSORS_H__
|
#define __SKY_SENSORS_H__
|
||||||
|
|
||||||
void sky_sensors_activate(uint8_t);
|
int sky_sensors_status(uint16_t input, int type);
|
||||||
void sky_sensors_deactivate(uint8_t);
|
int sky_sensors_configure(uint16_t input, uint8_t reference,
|
||||||
|
int type, int value);
|
||||||
|
|
||||||
#endif /* __SKY_SENSORS_H__ */
|
#endif /* __SKY_SENSORS_H__ */
|
||||||
|
|
Loading…
Reference in a new issue