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
|
||||
CFLAGS += -DCONTIKI_TARGET_SKY
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += contiki-jcreate-platform.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
|
||||
|
||||
|
|
|
@ -26,67 +26,41 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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
|
||||
* Created : 2005-11-01
|
||||
* Updated : $Date: 2010/05/03 21:57:35 $
|
||||
* $Revision: 1.1 $
|
||||
* Updated : $Date: 2010/08/25 19:34:42 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#include "dev/acc-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include <io.h>
|
||||
|
||||
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);
|
||||
#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;
|
||||
|
||||
active = 1;
|
||||
sky_sensors_activate(0x70);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
sky_sensors_deactivate(0x70);
|
||||
active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case 0:
|
||||
return ADC12MEM2;
|
||||
case 1:
|
||||
return ADC12MEM3;
|
||||
case 2:
|
||||
return ADC12MEM4;
|
||||
case 3:
|
||||
return ADC12MEM5;
|
||||
case ACC_SENSOR_X:
|
||||
return ACC_MEM_X;
|
||||
case ACC_SENSOR_Y:
|
||||
return ACC_MEM_Y;
|
||||
case ACC_SENSOR_Z:
|
||||
return ACC_MEM_Z;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -94,28 +68,31 @@ value(int type)
|
|||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
/* Sleep Mode P2.3 */
|
||||
if(c) {
|
||||
if(!active) {
|
||||
activate();
|
||||
P2OUT |= 0x08;
|
||||
P2DIR |= 0x08;
|
||||
} else {
|
||||
/* Sensor deactivated. Changed to sleep mode. */
|
||||
P2OUT &= ~0x08;
|
||||
}
|
||||
} else if(active) {
|
||||
deactivate();
|
||||
} 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
|
||||
status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
if(type == ACC_SENSOR_SENSITIVITY) {
|
||||
return (P2OUT & P2DIR) & 0x03;
|
||||
}
|
||||
return 0;
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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
|
||||
* 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
|
||||
* Created : 2005-11-01
|
||||
* Updated : $Date: 2010/05/03 21:57:35 $
|
||||
* $Revision: 1.1 $
|
||||
* Updated : $Date: 2010/08/25 19:34:42 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#ifndef __ACC_SENSOR_H__
|
||||
|
@ -45,4 +45,18 @@ extern const struct sensors_sensor acc_sensor;
|
|||
|
||||
#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__ */
|
||||
|
|
|
@ -26,15 +26,15 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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,
|
||||
* Jesper Karlsson
|
||||
* Created : 2005-11-01
|
||||
* Updated : $Date: 2010/05/03 21:57:35 $
|
||||
* $Revision: 1.1 $
|
||||
* Updated : $Date: 2010/08/25 19:34:42 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#include <io.h>
|
||||
|
@ -42,23 +42,38 @@
|
|||
#include "dev/ext-sensor.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;
|
||||
static uint8_t active;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
/* ADC0 corresponds to the port under the logo, ADC1 to the port over the logo,
|
||||
ADC2 and ADC3 corresponds to port on the JCreate bottom expansion port) */
|
||||
/* ADC0 corresponds to the port under the logo, ADC1 to the port
|
||||
over the logo, ADC2 and ADC3 corresponds to port on the JCreate
|
||||
bottom expansion port) */
|
||||
switch(type) {
|
||||
case ADC0:
|
||||
return ADC12MEM6;
|
||||
return EXT_MEM0;
|
||||
case ADC1:
|
||||
return ADC12MEM7;
|
||||
return EXT_MEM1;
|
||||
case ADC2:
|
||||
return ADC12MEM8;
|
||||
return EXT_MEM2;
|
||||
case ADC3:
|
||||
return ADC12MEM9;
|
||||
return EXT_MEM3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,40 +81,13 @@ value(int type)
|
|||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
}
|
||||
return 0;
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
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;
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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
|
||||
* 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
|
||||
* Created : 2005-11-01
|
||||
* Updated : $Date: 2010/02/03 20:30:07 $
|
||||
* $Revision: 1.10 $
|
||||
* Updated : $Date: 2010/08/25 19:30:52 $
|
||||
* $Revision: 1.11 $
|
||||
*/
|
||||
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include <io.h>
|
||||
|
||||
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);
|
||||
#define INPUT_CHANNEL (1 << INCH_11)
|
||||
#define INPUT_REFERENCE SREF_1
|
||||
#define BATTERY_MEM ADC12MEM11
|
||||
|
||||
sky_sensors_activate(0x80);
|
||||
|
||||
active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
sky_sensors_deactivate(0x80);
|
||||
active = 0;
|
||||
}
|
||||
const struct sensors_sensor battery_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return ADC12MEM2/*battery_value*/;
|
||||
return BATTERY_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
}
|
||||
return 0;
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
|
||||
value, configure, status);
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
||||
|
|
|
@ -28,16 +28,23 @@
|
|||
*
|
||||
* 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 "lib/sensors.h"
|
||||
#include "dev/sky-sensors.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;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -47,11 +54,11 @@ value(int type)
|
|||
switch(type) {
|
||||
/* Photosynthetically Active Radiation. */
|
||||
case LIGHT_SENSOR_PHOTOSYNTHETIC:
|
||||
return ADC12MEM0;
|
||||
return PHOTOSYNTHETIC_MEM;
|
||||
|
||||
/* Total Solar Radiation. */
|
||||
case LIGHT_SENSOR_TOTAL_SOLAR:
|
||||
return ADC12MEM1;
|
||||
return TOTAL_SOLAR_MEM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,34 +66,13 @@ value(int type)
|
|||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return (ADC12CTL0 & (ADC12ON + REFON)) == (ADC12ON + REFON);
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
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;
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(light_sensor, "Light",
|
||||
value, configure, status);
|
||||
SENSORS_SENSOR(light_sensor, "Light", value, configure, status);
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* 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"
|
||||
|
@ -36,6 +36,7 @@
|
|||
#include "dev/radio-sensor.h"
|
||||
|
||||
const struct sensors_sensor radio_sensor;
|
||||
static int active;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
|
@ -53,12 +54,21 @@ value(int type)
|
|||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
active = c;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -28,68 +28,127 @@
|
|||
*
|
||||
* 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
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/02/06 18:28:26 $
|
||||
* $Revision: 1.2 $
|
||||
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <io.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
|
||||
sky_sensors_activate(uint8_t type)
|
||||
static CC_INLINE void
|
||||
start(void)
|
||||
{
|
||||
uint8_t pre = adc_on;
|
||||
uint16_t c, last;
|
||||
|
||||
adc_on |= type;
|
||||
P6SEL |= type;
|
||||
|
||||
if(pre == 0 && adc_on > 0) {
|
||||
/* Set up the ADC. */
|
||||
P6DIR = 0xff;
|
||||
P6OUT = 0x00;
|
||||
|
||||
/* if nothing was started before, start up the ADC system */
|
||||
/* Set up the ADC. */
|
||||
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; /* Setup ADC12, ref., sampling time */
|
||||
ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; /* Use sampling timer, repeat-sequenc-of-channels */
|
||||
/* convert up to MEM4 */
|
||||
ADC12MCTL9 |= EOS;
|
||||
/* Setup ADC12, ref., sampling time */
|
||||
/* XXX Note according to the specification a minimum of 17 ms should
|
||||
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;
|
||||
|
||||
ADC12CTL0 |= ADC12ON + REFON;
|
||||
last = 15;
|
||||
for(c = 0; c < 16; c++) {
|
||||
/* Clear all end-of-sequences */
|
||||
ADC12MCTL_NO(c) &= ~EOS;
|
||||
if(adc_on & (1 << c)) {
|
||||
if(last == 15) {
|
||||
/* Set new start of sequence to lowest active memory holder */
|
||||
ADC12CTL1 |= (c * CSTARTADD_1);
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set highest end-of-sequence. */
|
||||
ADC12MCTL_NO(last) |= EOS;
|
||||
|
||||
ADC12CTL0 |= ADC12ON;
|
||||
ADC12CTL0 |= ENC; /* enable conversion */
|
||||
ADC12CTL0 |= ADC12SC; /* sample & convert */
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
sky_sensors_deactivate(uint8_t type)
|
||||
static CC_INLINE void
|
||||
stop(void)
|
||||
{
|
||||
adc_on &= ~type;
|
||||
|
||||
if(adc_on == 0) {
|
||||
/* stop converting immediately, turn off reference voltage, etc. */
|
||||
/* wait for conversion to stop */
|
||||
|
||||
ADC12CTL0 &= ~ENC;
|
||||
/* need to remove CONSEQ_3 if not EOS is configured */
|
||||
ADC12CTL1 &= ~CONSEQ_3;
|
||||
|
||||
/* wait for conversion to stop */
|
||||
while(ADC12CTL1 & ADC12BUSY);
|
||||
|
||||
ADC12CTL0 = 0;
|
||||
ADC12CTL1 = 0;
|
||||
|
||||
P6DIR = 0x00;
|
||||
P6OUT = 0x00;
|
||||
P6SEL = 0x00;
|
||||
}
|
||||
/* clear any pending interrupts */
|
||||
ADC12IFG = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sky_sensors_status(uint16_t input, int type)
|
||||
{
|
||||
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.
|
||||
*
|
||||
* 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
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/02/02 20:59:45 $
|
||||
* $Revision: 1.1 $
|
||||
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#ifndef __SKY_SENSORS_H__
|
||||
#define __SKY_SENSORS_H__
|
||||
|
||||
void sky_sensors_activate(uint8_t);
|
||||
void sky_sensors_deactivate(uint8_t);
|
||||
int sky_sensors_status(uint16_t input, int type);
|
||||
int sky_sensors_configure(uint16_t input, uint8_t reference,
|
||||
int type, int value);
|
||||
|
||||
#endif /* __SKY_SENSORS_H__ */
|
||||
|
|
Loading…
Reference in a new issue