Reincarnate the sensinode/cc2430 port

This commit is contained in:
George Oikonomou 2012-03-05 16:28:06 +00:00
parent c78b5bad5c
commit b7674c3636
114 changed files with 10044 additions and 3068 deletions

View file

@ -27,87 +27,174 @@
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: button-sensor.c,v 1.1 2009/09/08 20:06:28 zdshelby Exp $
*/
#include "lib/sensors.h"
/*#include "dev/hwconf.h"*/
#include "dev/button-sensor.h"
#include "dev/leds.h"
const struct sensors_sensor button_sensor;
static struct timer debouncetimer;
/*
HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
*/
* Portions of this file build on button-sensor.c in platforms sky and esb
* This file contains ISRs: Keep it in the HOME bank.
*/
#include "dev/models.h"
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/sensinode-sensors.h"
#if BUTTON_SENSOR_ON
static uint8_t p0ien;
static uint8_t p2ien;
static __data struct timer debouncetimer[2];
#ifdef MODEL_N740
HWCONF_PIN(BUTTON_1, 1, 0)
HWCONF_PORT_1_IRQ(BUTTON_1, 0)
HWCONF_PIN(BUTTON_2, 0, 4)
HWCONF_PORT_0_IRQ(BUTTON_2, 4)
#endif /* MODEL_N740 */
#ifdef MODEL_N711
HWCONF_PIN(BUTTON_1, 0, 6)
HWCONF_PORT_0_IRQ(BUTTON_1, 6)
HWCONF_PIN(BUTTON_2, 0, 7)
HWCONF_PORT_0_IRQ(BUTTON_2, 7)
#endif /* MODEL_N711 */
/*---------------------------------------------------------------------------*/
static void
init(void)
static
int value_b1(int type)
{
timer_set(&debouncetimer, 0);
BUTTON_IRQ_EDGE_SELECTD();
BUTTON_SELECT();
BUTTON_MAKE_INPUT();
return BUTTON_1_READ() || !timer_expired(&debouncetimer[0]);
}
/*---------------------------------------------------------------------------*/
static int
irq(void)
static
int status_b1(int type)
{
if(BUTTON_CHECK_IRQ()) {
if(timer_expired(&debouncetimer)) {
timer_set(&debouncetimer, CLOCK_SECOND / 4);
sensors_changed(&button_sensor);
return 1;
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return BUTTON_1_IRQ_ENABLED();
}
return 0;
}
/*---------------------------------------------------------------------------*/
static
int configure_b1(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
/* Generates INT when pressed */
BUTTON_1_IRQ_EDGE_SELECTD();
BUTTON_1_SELECT();
BUTTON_1_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!BUTTON_1_IRQ_ENABLED()) {
timer_set(&debouncetimer[0], 0);
BUTTON_1_IRQ_FLAG_OFF();
BUTTON_1_ENABLE_IRQ();
}
} else {
BUTTON_1_DISABLE_IRQ();
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static
int value_b2(int type)
{
return BUTTON_2_READ() || !timer_expired(&debouncetimer[1]);
}
/*---------------------------------------------------------------------------*/
static
int status_b2(int type)
{
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return BUTTON_2_IRQ_ENABLED();
}
return 0;
}
/*---------------------------------------------------------------------------*/
static
int configure_b2(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
/* Generates INT when released */
/* BUTTON_2_IRQ_EDGE_SELECTD(); */
BUTTON_2_SELECT();
BUTTON_2_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!BUTTON_2_IRQ_ENABLED()) {
timer_set(&debouncetimer[1], 0);
BUTTON_2_IRQ_FLAG_OFF();
BUTTON_2_ENABLE_IRQ();
}
} else {
BUTTON_2_DISABLE_IRQ();
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
void
port_0_ISR(void) __interrupt (P0INT_VECTOR)
{
EA = 0;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/* This ISR is for the entire port. Check if the interrupt was caused by our
* button's pin. */
/* Check B1 for N711 */
#ifdef MODEL_N711
if(BUTTON_1_CHECK_IRQ()) {
if(timer_expired(&debouncetimer[0])) {
timer_set(&debouncetimer[0], CLOCK_SECOND / 4);
sensors_changed(&button_1_sensor);
}
}
#endif /* MODEL_N711 */
if(BUTTON_2_CHECK_IRQ()) {
if(timer_expired(&debouncetimer[1])) {
timer_set(&debouncetimer[1], CLOCK_SECOND / 4);
sensors_changed(&button_2_sensor);
}
}
P0IFG = 0;
IRCON_P0IF = 0;
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
EA = 1;
}
/*---------------------------------------------------------------------------*/
/* We only need this ISR for N740 */
#ifdef MODEL_N740
void
port_1_ISR(void) __interrupt (P1INT_VECTOR)
{
EA = 0;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
return 0;
/* This ISR is for the entire port. Check if the interrupt was caused by our
* button's pin. This can only be B1 for N740 */
if(BUTTON_1_CHECK_IRQ()) {
if(timer_expired(&debouncetimer[0])) {
timer_set(&debouncetimer[0], CLOCK_SECOND / 4);
sensors_changed(&button_1_sensor);
}
}
P1IFG = 0;
IRCON2_P1IF = 0;
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
EA = 1;
}
/*---------------------------------------------------------------------------*/
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
active(void)
{
return BUTTON_IRQ_ENABLED();
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type)
{
return BUTTON_READ() || !timer_expired(&debouncetimer);
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, void *c)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static void *
status(int type)
{
return NULL;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
init, irq, activate, deactivate, active,
value, configure, status);
#endif /* MODEL_N740 */
SENSORS_SENSOR(button_1_sensor, BUTTON_1_SENSOR, value_b1, configure_b1, status_b1);
SENSORS_SENSOR(button_2_sensor, BUTTON_2_SENSOR, value_b2, configure_b2, status_b2);
#endif /* BUTTON_SENSOR_ON */