repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
tinyos-io/tinyos-3.x-contrib | nxtmote/tos/platforms/nxtmote/AT91SAM7S256_extra.h | /**
* Adapted for nxtmote.
* @author <NAME>
*/
#ifndef AT91SAM7S256_EXTRA_H
#define AT91SAM7S256_EXTRA_H
#define CPSR_I_BIT (0x80)
#define CPSR_F_BIT (0x40)
#define ARM_CPSR_INT_MASK (0x000000C0)
#define GPIO_pin_bit(_pin) (1 << _pin)
//TODO: Same
#define AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL ((unsigned int) 0x0 << 5) // (AIC) Internal Sources Code Label High-level Sensitive
#define AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL ((unsigned int) 0x0 << 5) // (AIC) External Sources Code Label Low-level Sensitive
#endif
|
tinyos-io/tinyos-3.x-contrib | vu/apps/TestPacketTimestamp/TestPacketTimestamp.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef TEST_PACKET_TIMESTAMP_H
#define TEST_PACKET_TIMESTAMP_H
typedef nx_struct ping_msg {
nx_uint16_t pinger;
nx_uint32_t ping_counter;
nx_uint32_t prev_ping_counter;
nx_uint8_t prev_ping_tx_timestamp_is_valid;
nx_uint32_t prev_ping_tx_timestamp;
} ping_msg_t;
typedef nx_struct pong_msg {
nx_uint16_t ponger;
nx_uint16_t pinger;
nx_uint32_t ping_counter;
nx_uint8_t ping_rx_timestamp_is_valid;
nx_uint32_t ping_rx_timestamp;
} pong_msg_t;
enum {
AM_PING_MSG = 16,
AM_PONG_MSG = 17,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/lib6lowpan/iovec.c | #include <stdint.h>
#include <stdio.h>
#include "lib6lowpan.h"
#include "iovec.h"
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
/**
* read len bytes starting at offset into the buffer pointed to by buf
*
*
*/
int iov_read(struct ip_iovec *iov, int offset, int len, uint8_t *buf) {
int cur_offset = 0, written = 0;
// printf("iov_read iov: %p offset: %i len: %i buf: %p\n", iov, offset, len, buf);
while (iov != NULL && cur_offset + iov->iov_len <= offset) {
cur_offset += iov->iov_len;
iov = iov->iov_next;
}
if (!iov) goto done;
while (len > 0) {
int start, len_here;
start = offset - cur_offset;
len_here = MIN(iov->iov_len - start, len);
// copy
memcpy(buf, iov->iov_base + start, len_here);
// printf("iov_read: %i/%i\n", len_here, len);
cur_offset += start + len_here;
offset += len_here;
written += len_here;
len -= len_here;
buf += len_here;
iov = iov->iov_next;
if (!iov) {
goto done;
}
}
done:
return written;
}
int iov_len(struct ip_iovec *iov) {
int rv = 0;
while (iov) {
rv += iov->iov_len;
iov = iov->iov_next;
}
return rv;
}
void iov_prefix(struct ip_iovec *iov, struct ip_iovec *new, uint8_t *buf, size_t len) {
new->iov_base = buf;
new->iov_len = len;
new->iov_next = iov;
}
|
tinyos-io/tinyos-3.x-contrib | yuceg/tos/system/job.h | /* Copyright (c) 2008, Computer Engineering Group, Yazd University , Iran .
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*/
#ifndef JOB_H
#define JOB_H
enum {
NULL_STATE = 0, //Initial state
READY_STATE = 1, //ready for execution
RUNNING_STATE = 2, // running job
};
/** @brief job structure definition */
typedef struct job_s {
/** @brief Stack pointer */
volatile uint16_t *sp;
/** @brief job state */
volatile uint8_t state;
/**@brief job ID */
volatile uint8_t id;
} job_t;
#define STACK_TOP(stack) \
(&(((uint16_t *)stack)[(sizeof(stack) / sizeof(uint16_t)) - 1]))
#endif
|
tinyos-io/tinyos-3.x-contrib | ethz/nodule/tos/chips/at32uc3b/pins/at32uc3b_gpio.h | <filename>ethz/nodule/tos/chips/at32uc3b/pins/at32uc3b_gpio.h<gh_stars>0
/* $Id: at32uc3b_gpio.h,v 1.1 2008/03/09 16:36:17 yuecelm Exp $ */
/* @author <NAME> <<EMAIL>> */
#ifndef __AT32UC3B_GPIO_H__
#define __AT32UC3B_GPIO_H__
#include "at32uc3b.h"
#define PORTA_OFFSET 0x00000000
#define PORTB_OFFSET 0x00000100
#define AVR32_GPIO_PORTA_BASEADDRESS (AVR32_GPIO_ADDRESS + PORTA_OFFSET)
#define AVR32_GPIO_PORTB_BASEADDRESS (AVR32_GPIO_ADDRESS + PORTB_OFFSET)
#define get_avr32_gpio_baseaddress(gpio) ((gpio < 32) ? AVR32_GPIO_PORTA_BASEADDRESS : AVR32_GPIO_PORTB_BASEADDRESS)
#define AVR32_GPIO_LOCALBUS_ADDRESS 0x40000000
#define AVR32_GPIO_LOCALBUS_PORTA_BASEADDRESS (AVR32_GPIO_LOCALBUS_ADDRESS + PORTA_OFFSET)
#define AVR32_GPIO_LOCALBUS_PORTB_BASEADDRESS (AVR32_GPIO_LOCALBUS_ADDRESS + PORTB_OFFSET)
#define get_avr32_gpio_baseaddress_local(gpio) ((gpio < 32) ? AVR32_GPIO_LOCALBUS_PORTA_BASEADDRESS : AVR32_GPIO_LOCALBUS_PORTB_BASEADDRESS)
#define get_avr32_gpio_bit(gpio) (gpio % 32)
#endif /*__AT32UC3B_GPIO_H__*/
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/util/tinyrely/TinyStream.h | #include "TinyRely.h"
#ifndef TINYSTREAM_H_INCLUDED
#define TINYSTREAM_H_INCLUDED
#ifndef TS_BUF_LENGTH
#define TS_BUF_LENGTH 200
#endif
typedef struct TSStr {
bool lock;
bool valid;
bool sending;
uint8_t uid;
uint8_t txdata[TS_BUF_LENGTH];
uint8_t rxdata[TS_BUF_LENGTH];
uint16_t txhead;
uint16_t txtail;
uint16_t rxhead;
uint16_t rxtail;
} TSStr;
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/tinynode_2/DS2770.h | <gh_stars>1-10
//This code is a modified version of code from the Heliomote project
#ifndef _DS2770_h_
#define _DS2770_H_
#endif
|
tinyos-io/tinyos-3.x-contrib | tcd/powertossim-z/tinyos_files/tinyos-2.0.2/tos/lib/tossim/heap.c | // $Id: heap.c,v 1.1 2014/11/26 19:31:35 carbajor Exp $
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/* Authors: <NAME>
*
*/
/*
* FILE: heap.h
* AUTHOR: <NAME> <<EMAIL>>
* DESC: Simple array-based priority heap for discrete event simulation.
*/
#include <heap.h>
#include <string.h> // For memcpy(3)
#include <stdlib.h> // for rand(3)
#include <stdio.h> // For printf(3)
const int STARTING_SIZE = 511;
#define HEAP_NODE(heap, index) (((node_t*)(heap->data))[index])
typedef struct node {
void* data;
long long int key;
} node_t;
void down_heap(heap_t* heap, int findex);
void up_heap(heap_t* heap, int findex);
void swap(node_t* first, node_t* second);
node_t* prev(node_t* node);
node_t* next(node_t* next);
void init_node(node_t* node) {
node->data = NULL;
node->key = -1;
}
void init_heap(heap_t* heap) {
heap->size = 0;
heap->private_size = STARTING_SIZE;
heap->data = malloc(sizeof(node_t) * heap->private_size);
}
int heap_size(heap_t* heap) {
return heap->size;
}
int is_empty(heap_t* heap) {
return heap->size == 0;
}
int heap_is_empty(heap_t* heap) {
return is_empty(heap);
}
long long int heap_get_min_key(heap_t* heap) {
if (is_empty(heap)) {
return -1;
}
else {
return HEAP_NODE(heap, 0).key;
}
}
void* heap_peek_min_data(heap_t* heap) {
if (is_empty(heap)) {
return NULL;
}
else {
return HEAP_NODE(heap, 0).data;
}
}
void* heap_pop_min_data(heap_t* heap, long long int* key) {
int last_index = heap->size - 1;
void* data = HEAP_NODE(heap, 0).data;
if (key != NULL) {
*key = HEAP_NODE(heap, 0).key;
}
HEAP_NODE(heap, 0).data = HEAP_NODE(heap, last_index).data;
HEAP_NODE(heap, 0).key = HEAP_NODE(heap, last_index).key;
heap->size--;
down_heap(heap, 0);
return data;
}
void expand_heap(heap_t* heap) {
int new_size = (heap->private_size * 2) + 1;
void* new_data = malloc(sizeof(node_t) * new_size);
//dbg(DBG_SIM, "Resized heap from %i to %i.\n", heap->private_size, new_size);
memcpy(new_data, heap->data, (sizeof(node_t) * heap->private_size));
free(heap->data);
heap->data = new_data;
heap->private_size = new_size;
}
void heap_insert(heap_t* heap, void* data, long long int key) {
int findex = heap->size;
if (findex == heap->private_size) {
expand_heap(heap);
}
findex = heap->size;
HEAP_NODE(heap, findex).key = key;
HEAP_NODE(heap, findex).data = data;
up_heap(heap, findex);
heap->size++;
}
void swap(node_t* first, node_t* second) {
long long int key;
void* data;
key = first->key;
first->key = second->key;
second->key = key;
data = first->data;
first->data = second->data;
second->data = data;
}
void down_heap(heap_t* heap, int findex) {
int right_index = ((findex + 1) * 2);
int left_index = (findex * 2) + 1;
if (right_index < heap->size) { // Two children
long long int left_key = HEAP_NODE(heap, left_index).key;
long long int right_key = HEAP_NODE(heap, right_index).key;
int min_key_index = (left_key < right_key)? left_index : right_index;
if (HEAP_NODE(heap, min_key_index).key < HEAP_NODE(heap, findex).key) {
swap(&(HEAP_NODE(heap, findex)), &(HEAP_NODE(heap, min_key_index)));
down_heap(heap, min_key_index);
}
}
else if (left_index >= heap->size) { // No children
return;
}
else { // Only left child
long long int left_key = HEAP_NODE(heap, left_index).key;
if (left_key < HEAP_NODE(heap, findex).key) {
swap(&(HEAP_NODE(heap, findex)), &(HEAP_NODE(heap, left_index)));
return;
}
}
}
void up_heap(heap_t* heap, int findex) {
int parent_index;
if (findex == 0) {
return;
}
parent_index = (findex - 1) / 2;
if (HEAP_NODE(heap, parent_index).key > HEAP_NODE(heap, findex).key) {
swap(&(HEAP_NODE(heap, findex)), &(HEAP_NODE(heap, parent_index)));
up_heap(heap, parent_index);
}
}
|
tinyos-io/tinyos-3.x-contrib | ethz/meshbean900/tos/platforms/meshbean/chips/ds2411/PlatformIeeeEui64.h | <gh_stars>1-10
#ifndef PLATFORM_IEEE_EUI64_H
#define PLATFORM_IEEE_EUI64_H
/*
* Copyright (c) 2007, Vanderbilt University
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author: <NAME>
*/
/* For now, let us set the company ID to 'M' 'E' 'S' (MeshNetics), and the first two bytes
* of the serial ID to 'M' 'B' (MeshBean900). The last three bytes of the serial ID are read
* from the DS2411 chip.
*/
enum {
IEEE_EUI64_COMPANY_ID_0 = 'M',
IEEE_EUI64_COMPANY_ID_1 = 'E',
IEEE_EUI64_COMPANY_ID_2 = 'S',
IEEE_EUI64_SERIAL_ID_0 = 'M',
IEEE_EUI64_SERIAL_ID_1 = 'B',
};
#endif /* PLATFORM_IEEE_EUI64_H */
|
tinyos-io/tinyos-3.x-contrib | diku/common/tools/daq/calibrate.c | /**
* Calibration program.
*
* Does the same as DEMO19.C
*
* In order to calibrate the board, perform the following steps:
*
* Step 1: Apply 0V to channel 0
* Step 2: Apply 4.996V to channel 1
* Step 3: Apply 4.996mV to channel 2
* Step 4: Adjust VR101 until CAL:0 = 0x7FF or 0x800.
* Step 5: Adjust VR100 until CAL:1 = 0xFFE or 0xFFF.
* Step 6: Repeat step 4 and 5 until both values are fine.
* Step 7: Adjust VR2 until CAL:2 = 0x000 or 0x001.
* Step 8: Adjust VR1 until CAL:3 = 0xFFE or 0xFFF.
*
*/
#include <stdio.h>
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include "daq_lib.h"
void sigint(int signum)
{
endwin();
exit(0);
}
int main(int argc, char *argv[])
{
daq_card_t daq;
int count = 0;
struct sigaction act;
if (argc != 2) {
fprintf(stderr, "Too few arguments\n");
return 1;
}
if (daq_open(argv[1], &daq)) {
perror("Error opening daq device");
return 1;
}
if (daq_clear_scan(&daq)) {
perror("Error cleaning scan");
return 1;
}
if (daq_stop_scan(&daq)) {
perror("Error cleaning scan");
return 1;
}
/* Setup signal handler */
act.sa_handler = sigint;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGINT, &act, 0);
initscr();
nonl();
cbreak();
noecho();
move(1,1);
printw("A/D Calibration Program:\n");
printw("step 1: apply 0V to channel 0.\n");
printw("step 2: apply 4.996V to channel 1.\n");
printw("step 3: apply 4.996mV to channel 2.\n");
printw("step 4: adjust VR101 until CAL:0 = 0x7ff or 0x800.\n");
printw("step 5: adjust VR100 until CAL:1 = 0xffe or 0xfff.\n");
printw("step 6: repeat step 4 and step 5 until all OK.\n");
printw("step 7: adjust VR2 until CAL:2 = 0x000 or 0x001.\n");
printw("step 8: adjust VR1 until CAL:3 = 0xffe or 0xfff.\n");
while(1) {
int res;
uint16_t sample;
move(11, 5);
printw("Count=%ld\n", count++);
res = daq_config_channel(&daq, 0, DG_1, DR_BIPOL5V);
res += daq_get_sample(&daq, &sample);
if (!res) {
move(12, 5);
printw("CAL:0=0x%04x\n", sample);
} else {
endwin();
printf("(5.0V Range, CH:0) Error reading sample\n");
exit(1);
}
res = daq_config_channel(&daq, 1, DG_1, DR_BIPOL5V);
res += daq_get_sample(&daq, &sample);
if (!res) {
move(13, 5);
printw("CAL:1=0x%04x\n", sample);
} else {
endwin();
printf("(5.0V Range, CH:1) Error reading sample\n");
exit(1);
}
res = daq_config_channel(&daq, 0, DG_1, DR_UNIPOL10V);
res += daq_get_sample(&daq, &sample);
if (!res) {
move(14, 5);
printw("CAL:2=0x%04x\n", sample);
} else {
endwin();
printf("(10.0V Range, CH:0) Error reading sample\n");
exit(1);
}
res = daq_config_channel(&daq, 2, DG_1000, DR_BIPOL5V);
res += daq_get_sample(&daq, &sample);
if (!res) {
move(15, 5);
printw("CAL:3=0x%04x\n", sample);
} else {
endwin();
printf("(5.0V Range, CH:2) Error reading sample\n");
exit(1);
}
move(17, 1);
printw("Press CTRL+C to exit\n");
refresh();
// daq_wait_usec(&daq, 500);
}
endwin();
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | eon/apps/turtle_snapper/impl/tinynode/beacon.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef BEACON_H_
#define BEACON_H_
//#define BEACON_COUNT 2L
//#define BEACON_COUNT 0L /* This means one beacon */
// BEACON COUNT is now deprecated. Only send one -mdc
#define BEACON_IVAL 1000L
#define ACTIVE_IVAL 2000L
#define ACTIVE_PRE 333L
#define ACTIVE_WND 333L
#define ACTIVE_MAX (ACTIVE_IVAL - ACTIVE_WND - ACTIVE_PRE)
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/tos/lib/tossim/radio.c | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
/*
* "Copyright (c) 2005 Stanford University. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
*
* C++ implementation of the gain-based TOSSIM radio model.
*
* @author <NAME>
* @date Dec 10 2005
*/
/**
*
* Modified to accomodate simplified radio model w/energy stuff added for eon simulations
*
* @author <NAME>
* @date Sep 18 2008
*/
#include <radio.h>
#include <sim_radio.h>
Radio::Radio() {}
Radio::~Radio() {}
void Radio::add(int src, int dest, int cap, double energy_per_pkt, sim_time_t expires) {
sim_radio_add(src, dest, cap, energy_per_pkt,expires);
}
int Radio::capacity(int src, int dest) {
return sim_radio_capacity(src, dest);
}
bool Radio::connected(int src, int dest) {
return sim_radio_connected(src, dest);
}
void Radio::remove(int src, int dest) {
sim_radio_remove(src, dest);
}
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/platforms/nano/platform_message.h |
#ifndef PLATFORM_MESSAGE_H
#define PLATFORM_MESSAGE_H
#include <CC2420.h>
typedef union message_header {
cc2420_header_t cc2420;
// serial_header_t serial;
} message_header_t;
typedef union TOSRadioFooter {
cc2420_footer_t cc2420;
} message_footer_t;
typedef union TOSRadioMetadata {
cc2420_metadata_t cc2420;
} message_metadata_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/cc2430/adc/Adc.h | <filename>diku/mcs51/tos/chips/cc2430/adc/Adc.h
/*
* Copyright (c) 2007 University of Copenhagen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of University of Copenhagen nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
* OF COPENHAGEN OR ITS 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.
*/
/******************************************************************************
******************* ADC macros/functions *******************
*******************************************************************************
These functions/macros simplifies usage of the ADC.
******************************************************************************/
// Macro for setting up a single conversion. If ADCCON1.STSEL = 11, using this
// macro will also start the conversion.
#define ADC_SINGLE_CONVERSION(settings) \
do{ ADCCON3 = settings; }while(0)
// Macro for setting up a single conversion
#define ADC_SEQUENCE_SETUP(settings) \
do{ ADCCON2 = settings; }while(0)
// Where _settings_ are the following:
// Reference voltage:
#define ADC_REF_1_25_V 0x00 // Internal 1.25V reference
#define ADC_REF_P0_7 0x40 // External reference on AIN7 pin
#define ADC_REF_AVDD 0x80 // AVDD_SOC pin
#define ADC_REF_P0_6_P0_7 0xC0 // External reference on AIN6-AIN7 differential input
// Resolution (decimation rate):
#define ADC_8_BIT 0x00 // 64 decimation rate
#define ADC_10_BIT 0x10 // 128 decimation rate
#define ADC_12_BIT 0x20 // 256 decimation rate
#define ADC_14_BIT 0x30 // 512 decimation rate
// Input channel:
#define ADC_AIN0 0x00 // single ended P0_0
#define ADC_AIN1 0x01 // single ended P0_1
#define ADC_AIN2 0x02 // single ended P0_2
#define ADC_AIN3 0x03 // single ended P0_3
#define ADC_AIN4 0x04 // single ended P0_4
#define ADC_AIN5 0x05 // single ended P0_5
#define ADC_AIN6 0x06 // single ended P0_6
#define ADC_AIN7 0x07 // single ended P0_7
#define ADC_AIN0_AIN1 0x08 // differential input P0_0-P0_1
#define ADC_AIN2_AIN3 0x09 // differential input P0_2-P0_3
#define ADC_AIN4_AIN5 0x0A // differential input P0_4-P0_5
#define ADC_AIN6_AIN7 0x0B // differential input P0_6-P0_7
#define ADC_GND 0x0C // Ground
#define ADC_PVR 0x0D // Positive voltage reference
#define ADC_TEMP_SENS 0x0E // on-chip temperature sensor
#define ADC_VDD_3 0x0F // (vdd/3)
//-----------------------------------------------------------------------------
// Macro for starting the ADC in continuous conversion mode
#define ADC_SAMPLE_CONTINUOUS() \
do { ADCCON1 &= ~0x30; ADCCON1 |= 0x10; } while (0)
// Macro for stopping the ADC in continuous mode (and setting the ADC to be
// started manually by ADC_SAMPLE_SINGLE() )
#define ADC_STOP() \
do { ADCCON1 |= 0x30; } while (0)
// Macro for initiating a single sample in single-conversion mode (ADCCON1.STSEL = 11).
#define ADC_SAMPLE_SINGLE() \
do { ADC_STOP(); ADCCON1 |= 0x40; } while (0)
// Macro for configuring the ADC to be started from T1 channel 0. (T1 ch 0 must be in compare mode!!)
#define ADC_TRIGGER_FROM_TIMER1() do { ADC_STOP(); ADCCON1 &= ~0x10; } while (0)
// Expression indicating whether a conversion is finished or not.
#define ADC_SAMPLE_READY() (ADCCON1 & 0x80)
// Macro for setting/clearing a channel as input of the ADC
#define ADC_ENABLE_CHANNEL(ch) ADCCFG |= (0x01<<ch)
#define ADC_DISABLE_CHANNEL(ch) ADCCFG &= ~(0x01<<ch)
|
tinyos-io/tinyos-3.x-contrib | antlab-polimi/sensors/intermediateNode/config.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Author: <NAME>
* contact: <EMAIL>
*/
#ifndef RADIOINTER_H
#define RADIOINTER_H
#define VIDEO_HEADER_LENGTH 3
#define PHOTO_HEADER_LENGTH 2
#define BIGMSG_DATA_SHIFT 6
#define PHOTO_DATA_LENGTH 40//(1<<BIGMSG_DATA_SHIFT)
#define VIDEO_DATA_LENGTH 40//64
//#define TOSH_DATA_LENGTH (BIGMSG_HEADER_LENGTH+VIDEO_DATA_LENGTH)
#define DEST 0
#define SRC 10
#define MAX_RTX 5
typedef nx_struct radio_count_msg {
nx_uint16_t counter;
} radio_count_msg_t;
enum {
AM_RADIO_IMGSTAT_R = 127,
AM_RADIO_PHOTO_R = 128,
AM_RADIO_VIDEO_R = 129,
AM_RADIO_TIME_TEST_R = 130,
AM_RADIO_PKT_TEST_R = 131,
AM_RADIO_CMD_S = 120,
AM_RADIO_CMD_R = 120,
AM_RADIO_IMGSTAT_S = 127,
AM_RADIO_PHOTO_S = 128,
AM_RADIO_VIDEO_S = 129,
AM_RADIO_TIME_TEST_S =130,
AM_RADIO_PKT_TEST_S = 131,
AM_RADIO_QUEUE_TEST = 132,
};
typedef nx_struct video_radio_part{
nx_uint8_t frame_id;
nx_uint16_t part_id;
nx_uint8_t buf[VIDEO_DATA_LENGTH];
} video_radio_part_t;
typedef struct video_queue{
video_radio_part_t msg;
uint8_t sent;
} video_queue_t;
typedef nx_struct photo_radio_part{
nx_uint16_t part_id;
nx_uint8_t buf[PHOTO_DATA_LENGTH];
} photo_radio_part_t;
typedef nx_struct cmd_msg{
nx_uint8_t cmd;
nx_uint16_t val1;
nx_uint16_t val2;
} cmd_msg_t;
typedef nx_struct pkt_test_msg{
nx_uint32_t rcv_inter_pkts;
nx_uint32_t rcv_bs_pkts;
nx_uint32_t rtx_camera_count;
nx_uint32_t rtx_inter_count;
nx_uint32_t frame_num;
} pkt_test_msg_t;
typedef nx_struct time_test_msg{
nx_uint32_t acquire;
nx_uint32_t process;
nx_uint32_t sending;
nx_uint32_t send_size;
nx_uint32_t id;
nx_uint32_t acq_period;
nx_uint32_t pause_time;
} time_test_msg_t;
typedef nx_struct queue_test_msg{
nx_uint16_t tx_pause;
nx_uint16_t queue_size;
nx_uint16_t queue_delta;
} queue_test_msg_t;
typedef nx_struct img_stat{
nx_uint8_t type;
nx_uint16_t width;
nx_uint16_t height;
nx_uint32_t data_size;
nx_uint32_t timeAcq;
nx_uint32_t timeProc;
nx_uint32_t tmp1;
nx_uint32_t tmp2;
nx_uint32_t tmp3;
nx_uint32_t tmp4;
} img_stat_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | antlab-polimi/dpcm_C/dpcm_encoder.h | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
#include <stdio.h>
#include <stdlib.h>
#include "diff_idctfstBlk.h"
#include "diff_dctfstBlk.h"
#include "codeZeros.h"
#include "huffmanCompress.h"
#include "jpeghdr.h"
int dpcm_encode
(uint8_t* input,uint16_t width,uint16_t height,uint8_t qual,
char * filename,uint8_t frame_num,uint32_t bandwidthLimit) {
FILE* fdB=NULL;
FILE* fdImg=NULL;
char* file_buffer = "buffer_sender";
uint8_t buffer[400000];
/************************ RESCALED
uint16_t W = width;
uint16_t H = height;
uint16_t width = width/2;
uint16_t height = height/2;
int k,r,temp;
*********************************/
uint8_t diff[width*height];
int8_t dct_output[width*height];
uint8_t tmpOut[width*height];
int8_t recovered[width*height];
uint8_t dataOut[width*height];
char frame_num_str[10];
int i,j;
code_header_t *header = (code_header_t *)dataOut;
uint8_t *dct_code_data = &dataOut[CODE_HEADER_SIZE];
uint32_t dataSize=width*height;
uint32_t idx=0;
uint16_t dcSize = dataSize/64;
uint count;
uint8_t line[1024];
printf("Start encoding.\n");
//creating name of the coded file
strcat(filename,"_coded_");
sprintf(frame_num_str,"%d",frame_num);
strcat(filename,frame_num_str);
strcat(filename,".dpcm");
// read the buffer
if( frame_num > 0 && (fdB = fopen(file_buffer, "r"))!=NULL ){
while( (count=fread(line, 1, 1024, fdB))>0)
{
memcpy(&(buffer[dataSize]),line,count);
dataSize+=count;
}
fclose(fdB);
}
else if( frame_num > 0 && (fdB = fopen(file_buffer, "r"))==NULL ){
printf("Error reading buffer\n");
return -1;
}
// find number of blocks
uint8_t w_blocks= width >> 3;
uint8_t h_blocks= height >> 3;
uint16_t total_blocks= w_blocks*h_blocks;
// bytes per pixel settings
int bufShift=1; // B&W
/**************************************** RESCALED
//compute the difference
temp=0;
k=0;
r=0;
j=0;
i=0;
if(frame_num==0){
while(i<H*W){
temp=0;
for(k=0;k<2;k++){
temp=temp+0.25*input[i+k]+0.25*input[i+320+k];
}
diff[j]=temp;//-128;
j++;
i=i+2;
if(i%320==0){
r++;
i=i+320;
}
}
}
else if(frame_num>0){
while(i<W*H){
temp=0;
for(k=0;k<4;k++){
temp=temp+0.25*input[i+k];
}
diff[j]=(temp-buffer[j])/2;
j++;
i=i+4;
}
}
if ((fdImg = fopen("print_rescaled.pgm", "w")))
{
fprintf(fdImg, "P5\n\n%d %d\n255\n", half_width, half_height);
fwrite(diff,1,half_width*half_height,fdImg);
fclose(fdImg);
printf("Rescaled image written.\n");
}
else {
pritnf("Error opening (w) fdImg\n");
return -1;
}
return 0;
*********************************************************************************/
// compute the difference
i=0;
if(frame_num==0){
while(i<height*width){
diff[i]=input[i]-128; //bound the diff[i] in a int8_t variable
i++;
}
}
else if(frame_num>0){
while(i<height*width){
diff[i]=(input[i]-buffer[i])/2; // helved to bound the diff[i] in a int8_t var
i++;
}
}
// compress the difference
if (bandwidthLimit<(CODE_HEADER_SIZE+dataSize/64))
return 0;
for (i=0; i<w_blocks; i++)
for (j=0; j<h_blocks; j++)
{
diff_dctQuantBlock(i, j, total_blocks,
(int8_t *)diff, bufShift, dct_output,
QUANT_TABLE,qual, width);
diff_idctNew(i,j,total_blocks,
dct_output,recovered,bufShift,
QUANT_TABLE,qual,width);
}
//build header
header->width=width;
header->height=height;
header->quality=qual;
header->is_color = 0;
// entropy compression
idx=codeDC((uint8_t *)dct_output, tmpOut, dcSize);
idx+=codeZeros(((uint8_t*)&dct_output[dcSize]), &tmpOut[dcSize], dataSize-dcSize, bandwidthLimit-dcSize);
header->sizeRLE = (uint16_t)idx;
idx=Huffman_Compress(tmpOut,dct_code_data,idx);
header->sizeHUF = (uint16_t)idx;
header->totalSize = idx;
//write difference
if ( (fdImg = fopen(filename, "w")) )
{
printf("Writing coded difference.\n");
fwrite(dataOut,1,idx+CODE_HEADER_SIZE,fdImg);
fclose(fdImg);
}
else {
printf("Error opening (w) fdImg.");
return -1;
}
//update buffer
if(frame_num == 0) {
for(i=0;i<width*height;i++){
buffer[i]=recovered[i]+128;
}
}
else {
for(i=0;i<width*height;i++){
if(buffer[i]+recovered[i]*2<0){
buffer[i]=0;
}
else if(buffer[i]+recovered[i]*2>255) {
buffer[i]=255;
}
else buffer[i]=buffer[i]+recovered[i]*2;
}
}
// write the new buffer
if ((fdB = fopen(file_buffer, "w"))) {
fwrite(buffer,1,width*height,fdB);
fclose(fdB);
}
else{
printf("Error writing buffer.\n");
return -1;
}
printf("Buffer updated.\n");
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/mcs51/keil_stdint.h | <reponame>tinyos-io/tinyos-3.x-contrib<filename>diku/mcs51/tos/chips/mcs51/keil_stdint.h<gh_stars>1-10
/*
* Copyright (c) 2007 University of Copenhagen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of University of Copenhagen nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
* OF COPENHAGEN OR ITS 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.
*/
/**
*
* The sizes are slightly diffrent in Keil than avr-gcc
*
* See "Data Storage Formats"
* http://www.keil.com/support/man/docs/c51/c51_ap_datastorage.htm
*
* @author <NAME> <<EMAIL>>
*
*/
#ifndef _KEIL_STDINT_H
#define _KEIL_STDINT_H 1
/* Signed. */
typedef signed char int8_t;
typedef short int16_t;
// In Keil both are 16 bit, but not to Nesc!
//typedef int int16_t;
typedef long int32_t;
/* This will be removed later Keil does not support 64 bit types */
typedef long long int int64_t;
/* Unsigned. */
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
// In Keil in is 16 bit
//typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
/* This will be removed later Keil does not support 64 bit types*/
typedef unsigned long long int uint64_t;
#endif //_KEIL_STDINT_H 1
|
tinyos-io/tinyos-3.x-contrib | diku/common/lib/usb/usb-cdc.h |
#include <usb.h>
#ifndef _H_usb_cdc_H
#define _H_usb_cdc_H
// CDC ACM class specifc requests
#define SEND_ENCAPSULATED_COMMAND 0x00
#define GET_ENCAPSULATED_RESPONSE 0x01
#define SET_LINE_CODING 0x20
#define GET_LINE_CODING 0x21
#define SET_CONTROL_LINE_STATE 0x22
#define SEND_BREAK 0x23
typedef struct {
uint32_t rate; // Data terminal rate (baudrate), in bits per second
uint8_t stopbit; // Stop bits: 0 - 1 Stop bit, 1 - 1.5 Stop bits, 2 - 2 Stop bits
uint8_t parity; // Parity: 0 - None, 1 - Odd, 2 - Even, 3 - Mark, 4 - Space
uint8_t databit; // Data bits: 5, 6, 7, 8, 16
} line_coding_t;
const line_coding_t cdc_230400_8n1 __attribute__((code)) = {
hostToUsb32(230400), // baudrate
0, // stop bit: 1
0, // parity: none
8 // data bits: 8
};
const line_coding_t cdc_9600_8n1 __attribute__((code)) = {
hostToUsb32(9600), // baudrate
0, // stop bit: 1
0, // parity: none
8 // data bits: 8
};
#endif //_H_usb_cdc_H
|
tinyos-io/tinyos-3.x-contrib | uni_valencia/ema/tos/chips/cc2420/sync/NeighbourSync.h | /* Copyright (c) 2007 ETH Zurich.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*
* For additional information see http://www.btnode.ethz.ch/
*
* @author: <NAME> <<EMAIL>>
*
*/
#ifndef NEIGHBOURSYNC_H
#define NEIGHBOURSYNC_H
#include <AM.h>
#include "CC2420.h"
enum {
NEIGHBOURSYNCTABLESIZE = 8, // size of sync neighbour table
TABLE_UPDATE_DELAY = 100, // the neighbour table is updated after this delay [ms], or when radio is off
MEASURE_HISTORY_SIZE = 4,
NO_VALID_OFFSET = 0xffffffff,
NO_VALID_DRIFT = 32767,
NO_SYNC = 0xffffffff,
T32KHZ_TO_TMILLI_SHIFT = 5, // factor for conversion TMilli > T32khz
RADIO_STARTUP_OFFSET = 170, // jiffys until the radio is started and FIFO is loaded, should be calculated from packet length
REVERSE_SEND_OFFSET = 104, //use 104 if no initial backoff // less means: transmission begins earlier
NO_COMPENSATION_OFFSET = 100, // less means: transmission begins later. This offset is used to begin transmission earlier when no compensation is done
ALARM_OFFSET = RADIO_STARTUP_OFFSET,
AGING_PERIOD = 10,
TOTAL_AGING_PERIOD = NEIGHBOURSYNCTABLESIZE * AGING_PERIOD, // after AGING_PERIOD packets, each usageCounter is decremented by AGING_PERIOD / 16
SYNC_FAIL_THRESHOLD = 10, // after SYNC_FAIL_THRESHOLD non-acked packets, sync information is not valid anymore
REQ_SYNC_FLAG = 0x8000,
MORE_FLAG = 0x4000,
SYNC_TIMER_PERIOD = 30000UL, // period to gather sync-requests in milliseconds
DRIFT_CHANGE_LIMIT = 50, // value >> 21 that a new measured drift is allowed to differ from the last average
// 50 is about 23ppm
MAX_DRIFT_ERRORS = 5, // number of false drifts until history is cleared, e.g. when neihgbour node has resetted
MIN_MEASUREMENT_PERIOD = 131072UL, // 4s, minimal drift measurement period in ticks
RESYNC_AM_TYPE = 26,
};
typedef struct { // 18 + MEASURE_HISTORY_SIZE * 4 bytes
am_addr_t address; // 0
uint32_t wakeupTimestamp[MEASURE_HISTORY_SIZE]; // 2
uint32_t newTimestamp; // 4
uint32_t wakeupAverage; // 20
bool odd; // 24
uint8_t measurementCount; // 25
uint16_t usageCount; // 26
uint8_t failCount; // 28
uint8_t driftLimitCount; // 29
uint32_t lplPeriod; // in ticks 30
int16_t drift; // 34
bool dirty; // 36
// align to word address -> struct size = 38, when MEASURE_HISTORY_SIZE==4
} neighbour_sync_item_t;
typedef nx_struct {
nx_uint32_t wakeupOffset; // time that has passed between senders wakeup and the time the sfd was sent
nx_uint16_t lplPeriod; // this field contains lpl information and the flags
// REQ_SYNC_FLAG (highest bit)
// MORE_FLAG (second highest bit)
// lplperiod can be at max 2^14 binary ms ~ 16s
// but wakeupOffset is in ticks that can represent max 2 seconds -> this is currently the limit
} neighbour_sync_header_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | rincon/tos/lib/blackbook/core/BlackbookConst.h | <filename>rincon/tos/lib/blackbook/core/BlackbookConst.h<gh_stars>1-10
/*
* Copyright (c) 2005-2006 Rincon Research Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Rincon Research Corporation nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* ARCHED ROCK OR ITS 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
*/
/**
* Blackbook Constants
* These values can be modified here or at compile time
* to change the RAM consumption and behavior of the
* Blackbook file system
* @author <NAME> - <EMAIL>
*/
#ifndef BLACKBOOKCONST_H
#define BLACKBOOKCONST_H
/**
* FILENAME_LENGTH must be an even number for word alignment
* Each file on RAM (MAX_FILES worth of files) contains
* a filename. And each filemeta written to flash contains
* a filename. By using a smaller filename length,
* you're saving memory on flash and RAM while making it
* more difficult to come up with unique and insightful names
* for your files.
*
* If you change the filename length, the
* flash needs to be completely erased before starting up blackbook
* the next time. Otherwise, Blackbook won't know how to handle the
* previous versions of filemeta existing on flash.
*
* The last character is always '\0', leaving FILENAME_LENGTH-1
* characters for the actual filename
*/
#ifndef FILENAME_LENGTH
#define FILENAME_LENGTH 8
#endif
/**
* The following is the maximum number of files on
* our file system
*
* The amount of RAM used by Blackbook to store file info
* can be expressed by:
* MAX_FILES * NODES_PER_FILE * sizeof(node_t)
*/
#ifndef MAX_FILES
#define MAX_FILES 19
#endif
/**
* The following is the maximum number of nodes
* each file can use. If the file system
* boots and finds more files on flash than the
* RAM can support, the file system will be locked and
* unusable. This can only happen if an application is
* compiled with lots of RAM allocated to Blackbook and
* fills up a bunch of nodes on flash, and then another
* application is compiled and installed to the mote
* that doesn't allocate as much RAM.
*
* The amount of RAM used by Blackbook to store file info
* can be expressed by:
* MAX_FILES * NODES_PER_FILE * sizeof(node)
* + MAX_FILES * sizeof(file)
*/
#ifndef NODES_PER_FILE
#define NODES_PER_FILE 2
#endif
/**
* The Checkpoint file is actually a Dictionary file in
* disguise. If it is very small, new Checkpoint
* files will have to be created more often, and
* sometimes a file may not be able to be created
* if lots of other files are open for writing on
* the system. If the Checkpoint file is larger,
* new Checkpoint files will be created less often,
* but it may take longer to boot up due to the key
* search in the file.
* A good tradeoff is to dedicate around 10 pages of
* flash to the checkpoint file. That's about 158 checkpoints.
* Feel free to alter it to meet your application's needs.
*/
#ifndef CHECKPOINT_DEDICATED_PAGES
#define CHECKPOINT_DEDICATED_PAGES 10
#endif
/**
* Each client of the Dictionary component can
* have files open at the same time. Each open file
* can have a cache of the latest written keys for
* quick retrieval. We can speed up key retrieval by
* allocating more space in RAM for the key caches,
* or we can decrease search time and increase energy
* consumption by allocating less RAM.
*
* The amount of RAM used by the cache is defined by:
* uniqueCount["BDictionary"]*MAX_KEY_CACHE*12
*/
#ifndef MAX_KEY_CACHE
#define MAX_KEY_CACHE 5
#endif
/**
* When a Dictionary becomes full from inserting values,
* we must evaluate the file to see if we can create
* extra space by copying the valid values to a new dictionary
* file. But because the values can have variable sizes
* from 1 byte to 256 bytes, BDictionaryM needs a buffer
* to copy data. The buffer can be pretty small to save
* on RAM, or large to make the copy process go faster and
* use less energy when larger values are in the file.
* The buffer also doubles as a filename when creating the
* new file.
* So, the minimum buffer length is FILENAME_LENGTH
* If you want to make it larger for faster and more energy
* efficient copies at the expense of RAM, go for it.
*/
#ifndef VALUE_COPY_BUFFER_LENGTH
#define VALUE_COPY_BUFFER_LENGTH FILENAME_LENGTH
#endif
#ifndef UQ_BLACKBOOKSTORAGE
#define UQ_BLACKBOOKSTORAGE "Blackbook.Storage"
#endif
/* Upon bootup, the mote recreates the file system. While doing so,
* it checks to see if the node has been written to since its last
* save. To do this, it reads in MAX_CHECK_BYTES bytes after the
* dataLength of the node and before the reserveLength.
*/
#ifndef MAX_CHECK_BYTES
#define MAX_CHECK_BYTES 20
#endif
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/apps/server-e/impl/stargate/usermarshall.h | #ifndef USERMARSHAL_H_INCLUDED
#define USERMARSHAL_H_INCLUDED
#include "ServerE.h"
//int marshall_RequestMsg(int cid, RequestMsg data);
int unmarshall_RequestMsg(int cid, RequestMsg *data);
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/client/sfaccess/telossource.h | <filename>eon/eon/src/client/sfaccess/telossource.h
#ifndef TELOSSOURCE_H
#define TELOSSOURCE_H
//THis acts as a layer above sfsource.(c | h)
#include <stdint.h>
typedef struct {
uint8_t length;
uint8_t dsn;
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t *data;
} telospacket;
#define TELOS_MIN_SIZE 10
#define TOS_DATA_LENGTH 60
int open_telos_source(const char *host, int port);
int init_telos_source(int fd);
telospacket *read_telos_packet(int fd);
int write_telos_packet(int fd, const telospacket *packet);
int free_telos_packet(telospacket **pkt);
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/quanto/tos/lib/quanto/ResourceContexts.h | #ifndef _RESOURCE_CONTEXTS_H
#define _RESOURCE_CONTEXTS_H
/* These are globally known resource ids */
/* Resources represent energy sinks, peripherals that can independently spend energy.
* These are NOT activities, or contexts, but get attributed activities over time */
enum {
CPU_RESOURCE_ID = 0,
LED0_RESOURCE_ID = 0x50,
LED1_RESOURCE_ID = 0x51,
LED2_RESOURCE_ID = 0x52,
SHT11_RESOURCE_ID = 0x60,
CC2420_RESOURCE_ID = 0x40,
CC2420_SPI_RESOURCE_ID = 0x42,
MSP430_USART0_ID = 0x30,
MSP430_USART1_ID = 0x31,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | intelmote2/support/sdk/c/compress/idctApp.c | /*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS 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.
*/
/**
* @author <NAME> (<EMAIL>)
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "tinyos_macros.h"
#include "jpeghdr.h"
#include "jpegTOS.h"
#include "jpegUncompress.h"
#include "quanttables.h"
int getBytes(char* filename, uint8_t *dataIn)
{
FILE *fdIn;
if (!(fdIn = fopen(filename, "r")) ){
printf("Can't open %s for reading\n", filename);
return 0;
}
uint8_t line[1024];
int count, dataSize=0;
dataSize=0;
while( (count=fread(line, 1, 1024, fdIn))>0)
{
memcpy(&(dataIn[dataSize]),line,count);
dataSize+=count;
}
fclose(fdIn);
return dataSize;
}
int main(int argc, char **argv)
{
char filename[1024];
if (argc == 2)
sprintf(filename,argv[1]);
else
sprintf(filename,"coded.huf");
uint8_t recovered[320*240*3];
memset(recovered,0,sizeof(recovered));
code_header_t header;
//decodeJpegFile("coded.huf", recovered, &header);
uint8_t in[320*240*3];
uint32_t size=getBytes(filename,in);
decodeJpegBytes(in, size, recovered, &header);
printf("decoded header: W=%d H=%d qual=%d COL=%d size2=%d\n",
header.width, header.height, header.quality, header.is_color, header.totalSize);
if (header.is_color)
{
FILE *fdOut = fopen("testOut.ppm", "w");
fprintf(fdOut,"%s","P6\n\n320 240\n255\n");
fwrite(recovered,1,header.width*header.height*3,fdOut);
fclose(fdOut);printf("written .ppm file");
}
else
{
FILE *fdOut = fopen("testOut.pgm", "w");
fprintf(fdOut,"%s","P5\n\n320 240\n255\n");
fwrite(recovered,1,header.width*header.height,fdOut);
fclose(fdOut); printf("written .pgm file");
}
return 1;
}
|
tinyos-io/tinyos-3.x-contrib | tcd/tinyhop/apps/TinyHopTest-v.1.0/TinyHopTest.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Copyright (c) 2009 Trinity College Dublin.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Trinity College Dublin nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRINITY
* COLLEGE DUBLIN OR ITS 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.
*/
/**
* @author <NAME> <carbajor {tcd.ie}>
* @date February 13 2009
* Computer Science
* Trinity College Dublin
*/
/****************************************************************/
/* Demo application on how to use the TinyHop routing layer */
/* */
/* TinyHop: */
/* An end-to-end on-demand reliable ad hoc routing protocol */
/* for Wireless Sensor Networks intended for P2P communication */
/* See: http://portal.acm.org/citation.cfm?id=1435467.1435469 */
/*--------------------------------------------------------------*/
/* This version has been tested with TinyOS 2.1.0 and 2.1.1 */
/****************************************************************/
typedef nx_struct TOS_TinyHopTestMsg {
nx_uint8_t type;
nx_uint16_t reading;
nx_uint16_t seqControl;
} TOS_TinyHopTestMsg;
enum {
TEMPERATURE=0x1,
PRESSURE=0x2,
HUMIDITY=0x3,
POSITION_CHANGE=0x4
};
enum {
AM_TOS_TINYHOPTESTMSG = 17
};
|
tinyos-io/tinyos-3.x-contrib | vu/tos/chips/atm128/uart/Atm128Usart.h | // $Id: Atm128Usart.h,v 1.1 2009/12/03 21:44:25 sallai Exp $
/*
* Copyright (c) 2004-2005 Crossbow Technology, Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS BE LIABLE TO
* ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS.
*/
// @author <NAME> <<EMAIL>>
#ifndef _H_Atm1281Uart_h
#define _H_Atm1281Uart_h
//====================== UART Bus ==================================
typedef uint8_t Atm1281_UDR0_t; //!< USART0 I/O Data Register
typedef uint8_t Atm1281_UDR1_t; //!< USART0 I/O Data Register
/* UART Control and Status Register A */
typedef union {
struct Atm1281_UCSRA_t {
uint8_t mpcm : 1; //!< UART Multiprocessor Communication Mode
uint8_t u2x : 1; //!< UART Double Transmission Speed
uint8_t upe : 1; //!< UART Parity Error
uint8_t dor : 1; //!< UART Data Overrun
uint8_t fe : 1; //!< UART Frame Error
uint8_t udre : 1; //!< USART Data Register Empty
uint8_t txc : 1; //!< USART Transfer Complete
uint8_t rxc : 1; //!< USART Receive Complete
} bits;
uint8_t flat;
} Atm1281UartControlA_t;
typedef Atm1281UartControlA_t Atm1281_UCSR0A_t; //!< UART 0
typedef Atm1281UartControlA_t Atm1281_UCSR1A_t; //!< UART 1
/* UART Control and Status Register B */
typedef union {
struct Atm1281_UCSRB_t {
uint8_t txb8 : 1; //!< UART Transmit Data Bit 8
uint8_t rxb8 : 1; //!< UART Receive Data Bit 8
uint8_t ucsz2 : 1; //!< UART Character Size (Bit 2)
uint8_t txen : 1; //!< UART Transmitter Enable
uint8_t rxen : 1; //!< UART Receiver Enable
uint8_t udrie : 1; //!< USART Data Register Enable
uint8_t txcie : 1; //!< UART TX Complete Interrupt Enable
uint8_t rxcie : 1; //!< UART RX Complete Interrupt Enable
} bits;
uint8_t flat;
} Atm1281UartControlB_t;
typedef Atm1281UartControlB_t Atm1281_UCSR0B_t; //!< UART 0
typedef Atm1281UartControlB_t Atm1218_UCSR1B_t; //!< UART 1
enum {
ATM128_UART_MODE_NORMAL_ASYNC,
ATM128_UART_MODE_DOUBLE_SPEED_ASYNC,
ATM128_UART_MODE_MASTER_SYNC,
ATM128_UART_MODE_SLAVE_SYNC,
};
enum {
ATM128_UART_DATA_SIZE_5_BITS,
ATM128_UART_DATA_SIZE_6_BITS,
ATM128_UART_DATA_SIZE_7_BITS,
ATM128_UART_DATA_SIZE_8_BITS,
};
enum {
ATM128_UART_PARITY_NONE,
ATM128_UART_PARITY_EVEN,
ATM128_UART_PARITY_ODD,
};
enum {
ATM128_UART_STOP_BITS_ONE,
ATM128_UART_STOP_BITS_TWO,
};
/* UART Control and Status Register C */
typedef union {
uint8_t flat;
struct Atm1281_UCSRC_t {
uint8_t ucpol : 1; //!< UART Clock Polarity
uint8_t ucsz : 2; //!< UART Character Size (Bits 0 and 1)
uint8_t usbs : 1; //!< UART Stop Bit Select
uint8_t upm : 2; //!< UART Parity Mode
uint8_t umsel : 2; //!< USART Mode Select
} bits;
} Atm1281UartControlC_t;
typedef Atm1281UartControlC_t Atm1281_UCSR0C_t; //!< UART 0
typedef Atm1281UartControlC_t Atm1281_UCSR1C_t; //!< UART 1
typedef uint16_t Atm128UartBaudRate_t;
typedef uint16_t Atm128_UBRR0_t; //!< UART 0 Baud Register
typedef uint16_t Atm128_UBRR1_t; //!< UART 0 Baud Register
#endif //_H_Atm128UART_h
|
tinyos-io/tinyos-3.x-contrib | rincon/tools/ft232r/d2xx/zag.c | /***********************************************************************
* zag.c -- Blink app for the UM232R
*
* Binary counting using bit-banging on 3 FT232R lines:
* D0 is bit 0
* D4 is bit 1 (it's right next to D0)
* D2 is bit 2 (it's right next to D4)
*
* Building:
* - Uninstall ALL existing FTDI drivers
* - Plug in the UM232R
* - Install the FTDI CDM (D2XX+VCP combined) driver per the instructions
* - Copy ftd2xx.h from the unpacked driver folder
* - Copy ftd2xx.lib from i386/ under the unpacked driver folder
* - Open a cygwin window
* - Compile with gcc -mno-cygwin -I/usr/include/w32api -Wall -O -o zag.exe zag.c ftd2xx.lib
* - Run ./zag with a DVM strapped to the UM232R
*/
#include <windows.h>
#include <stdio.h>
#include "ftd2xx.h"
int main(int argc, char *argv[]) {
FT_HANDLE f;
int rc = 1, i;
// open the device
if (!FT_SUCCESS(FT_Open(0, &f))) {
printf("FT_Open: fail\n");
return 1;
}
// reset it
if (!FT_SUCCESS(FT_ResetDevice(f))) {
printf("FT_ResetDevice: fail\n");
goto out;
}
// disable flow control
if (!FT_SUCCESS(FT_SetFlowControl(f, FT_FLOW_NONE, 0, 0))) {
printf("FT_SetFlowControl: fail\n");
goto out;
}
// set to 9600 bps
if (!FT_SUCCESS(FT_SetBaudRate(f, FT_BAUD_9600))) {
printf("FT_SetBaudRate: fail\n");
goto out;
}
// set to 8N1
if (!FT_SUCCESS(FT_SetDataCharacteristics(f,
FT_BITS_8,
FT_STOP_BITS_1,
FT_PARITY_NONE))) {
printf("FT_SetDataCharacteristics: fail\n");
goto out;
}
// enable bit-banging mode
if (!FT_SUCCESS(FT_SetBitMode(f, (UCHAR) 0x15, (UCHAR) 0x01))) {
printf("FT_SetBitMode: fail\n");
goto out;
}
// write some data
for (i = 0; i < 32; i++) {
UCHAR v;
DWORD nw;
volatile int j;
// alternate pins D0, D4, D2 on and off
v = (i & 1) | // bit 0 -> D0
((i & 2) << 3) | // bit 1 -> D4
(i & 4); // bit 2 -> D2
// set the pins
if (!FT_SUCCESS(FT_Write(f, &v, 1, &nw))) {
printf("FT_Write: fail\n");
goto out;
} else {
printf("%d: %d\n", i, v); fflush(stdout);
}
// waste some time
for (j = 0; j < 100000000; j++)
;
}
// success (so far)
rc = 0;
out:
// get out of bit-banging mode
if (!FT_SUCCESS(FT_SetBitMode(f, (UCHAR) 0x00, (UCHAR) 0x00))) {
printf("FT_SetBitMode: fail (exit)\n");
rc = 1;
}
printf("done -- rc = %d\n", rc);
// release the device
FT_Close(f);
return rc;
}
/*** EOF zag.c */
|
tinyos-io/tinyos-3.x-contrib | gems/wmtp/tinyos/apps/tests/TestWMTP/TestWmtp.h | /*
* WMTP - Wireless Modular Transport Protocol
*
* Copyright (c) 2008 <NAME> and IT - Instituto de Telecomunicacoes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Address:
* Instituto Superior Tecnico - Taguspark Campus
* Av. Prof. Dr. <NAME>, 2744-016 Porto Salvo
*
* E-Mail:
* <EMAIL>
*/
#ifndef __TESTWMTP_H__
#define __TESTWMTP_H__
#define LOGGER_DURATION 60
#define LOGGER_PERIOD (1024*2)
#define LOGGER_NUM_MONITORED_CONNECTIONS 3
#define LOGGER_WAIT_TIME 30720
enum {
AM_EVENTMSG = 8,
};
// Event structure
typedef nx_struct EventRecord {
nx_uint32_t time;
nx_uint16_t nodeAddress; // The local node's address;
nx_uint8_t minQueueAvailability; // Minimum queue availability.
nx_uint16_t sntWmtpMsgCnt; // Number of sent WMTP Msgs.
nx_uint16_t rcvdWmtpMsgCnt; // Number of received WMTP Msgs.
nx_uint16_t genMsgCnt; // Number of generated messages.
nx_uint16_t rcvdMsgCnts[LOGGER_NUM_MONITORED_CONNECTIONS]; // Number of received messages.
} EventRecord_t;
typedef nx_struct EventMsg {
EventRecord_t EventRecord;
} EventMsg_t;
#define REPORTER_PERIOD 10240
#define REPORTER_NUM_MONITORED_CONNECTIONS 8
#endif // #define __TESTWMTP_H__ |
tinyos-io/tinyos-3.x-contrib | ethz/meshbean900/tos/platforms/meshbean900/platform_message.h | /*
* Copyright (c) 2007, Vanderbilt University
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
*/
#ifndef PLATFORM_MESSAGE_H
#define PLATFORM_MESSAGE_H
#include <RF212Radio.h>
#include <Serial.h>
typedef union message_header {
rf212packet_header_t rf212;
serial_header_t serial;
} message_header_t;
typedef union message_footer {
rf212packet_footer_t rf212;
} message_footer_t;
typedef union message_metadata {
rf212packet_metadata_t rf212;
} message_metadata_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/libusb_driver.h | /* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LIBUSB_DRIVER_H__
#define __LIBUSB_DRIVER_H__
#ifdef __GNUC__
#include <ddk/usb100.h>
#include <ddk/usbdi.h>
#include <ddk/winddk.h>
#include "usbdlib_gcc.h"
#else
#include <wdm.h>
#include "usbdi.h"
#include "usbdlib.h"
#endif
#include <wchar.h>
#include <initguid.h>
#undef interface
#include "driver_debug.h"
#include "driver_api.h"
/* some missing defines */
#ifdef __GNUC__
#define USBD_TRANSFER_DIRECTION_OUT 0
#define USBD_TRANSFER_DIRECTION_BIT 0
#define USBD_TRANSFER_DIRECTION_IN (1 << USBD_TRANSFER_DIRECTION_BIT)
#define USBD_SHORT_TRANSFER_OK_BIT 1
#define USBD_SHORT_TRANSFER_OK (1 << USBD_SHORT_TRANSFER_OK_BIT)
#define USBD_START_ISO_TRANSFER_ASAP_BIT 2
#define USBD_START_ISO_TRANSFER_ASAP (1 << USBD_START_ISO_TRANSFER_ASAP_BIT)
#endif
#define USB_RECIP_DEVICE 0x00
#define USB_RECIP_INTERFACE 0x01
#define USB_RECIP_ENDPOINT 0x02
#define USB_RECIP_OTHER 0x03
#define USB_TYPE_STANDARD 0x00
#define USB_TYPE_CLASS 0x01
#define USB_TYPE_VENDOR 0x02
#define LIBUSB_NT_DEVICE_NAME L"\\Device\\libusb0"
#define LIBUSB_SYMBOLIC_LINK_NAME L"\\DosDevices\\libusb0-"
#define LIBUSB_MAX_NUMBER_OF_ENDPOINTS 32
#define LIBUSB_MAX_NUMBER_OF_INTERFACES 32
#define LIBUSB_DEFAULT_TIMEOUT 5000
#define LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT 5000
#ifndef __GNUC__
#define DDKAPI
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!(FALSE))
#endif
typedef int bool_t;
#include <pshpack1.h>
typedef struct
{
unsigned char length;
unsigned char type;
} usb_descriptor_header_t;
#include <poppack.h>
typedef struct
{
long usage_count;
int remove_pending;
KEVENT event;
} libusb_remove_lock_t;
typedef struct
{
int address;
USBD_PIPE_HANDLE handle;
} libusb_endpoint_t;
typedef struct
{
int valid;
int claimed;
libusb_endpoint_t endpoints[LIBUSB_MAX_NUMBER_OF_ENDPOINTS];
} libusb_interface_t;
typedef struct
{
DEVICE_OBJECT *self;
DEVICE_OBJECT *physical_device_object;
DEVICE_OBJECT *next_stack_device;
DEVICE_OBJECT *target_device;
libusb_remove_lock_t remove_lock;
LONG ref_count;
bool_t is_filter;
bool_t is_started;
bool_t surprise_removal_ok;
int id;
struct {
USBD_CONFIGURATION_HANDLE handle;
int value;
libusb_interface_t interfaces[LIBUSB_MAX_NUMBER_OF_INTERFACES];
} config;
POWER_STATE power_state;
DEVICE_POWER_STATE device_power_states[PowerSystemMaximum];
} libusb_device_t;
NTSTATUS DDKAPI add_device(DRIVER_OBJECT *driver_object,
DEVICE_OBJECT *physical_device_object);
NTSTATUS DDKAPI dispatch(DEVICE_OBJECT *device_object, IRP *irp);
NTSTATUS dispatch_pnp(libusb_device_t *dev, IRP *irp);
NTSTATUS dispatch_power(libusb_device_t *dev, IRP *irp);
NTSTATUS dispatch_ioctl(libusb_device_t *dev, IRP *irp);
NTSTATUS complete_irp(IRP *irp, NTSTATUS status, ULONG info);
NTSTATUS call_usbd(libusb_device_t *dev, void *urb,
ULONG control_code, int timeout);
NTSTATUS pass_irp_down(libusb_device_t *dev, IRP *irp,
PIO_COMPLETION_ROUTINE completion_routine,
void *context);
bool_t accept_irp(libusb_device_t *dev, IRP *irp);
bool_t get_pipe_handle(libusb_device_t *dev, int endpoint_address,
USBD_PIPE_HANDLE *pipe_handle);
void clear_pipe_info(libusb_device_t *dev);
bool_t update_pipe_info(libusb_device_t *dev,
USBD_INTERFACE_INFORMATION *interface_info);
void remove_lock_initialize(libusb_device_t *dev);
NTSTATUS remove_lock_acquire(libusb_device_t *dev);
void remove_lock_release(libusb_device_t *dev);
void remove_lock_release_and_wait(libusb_device_t *dev);
NTSTATUS set_configuration(libusb_device_t *dev,
int configuration, int timeout);
NTSTATUS get_configuration(libusb_device_t *dev,
unsigned char *configuration, int *ret,
int timeout);
NTSTATUS set_interface(libusb_device_t *dev,
int interface, int altsetting, int timeout);
NTSTATUS get_interface(libusb_device_t *dev,
int interface, unsigned char *altsetting,
int *ret, int timeout);
NTSTATUS set_feature(libusb_device_t *dev,
int recipient, int index, int feature, int timeout);
NTSTATUS clear_feature(libusb_device_t *dev,
int recipient, int index, int feature, int timeout);
NTSTATUS get_status(libusb_device_t *dev, int recipient,
int index, char *status, int *ret, int timeout);
NTSTATUS set_descriptor(libusb_device_t *dev,
void *buffer, int size,
int type, int recipient, int index, int language_id,
int *sent, int timeout);
NTSTATUS get_descriptor(libusb_device_t *dev, void *buffer, int size,
int type, int recipient, int index, int language_id,
int *received, int timeout);
USB_CONFIGURATION_DESCRIPTOR *
get_config_descriptor(libusb_device_t *dev, int value, int *size);
NTSTATUS transfer(libusb_device_t *dev, IRP *irp,
int direction, int urb_function, int endpoint,
int packet_size, MDL *buffer, int size);
NTSTATUS vendor_class_request(libusb_device_t *dev,
int type, int recipient,
int request, int value, int index,
void *buffer, int size, int direction,
int *ret, int timeout);
NTSTATUS abort_endpoint(libusb_device_t *dev, int endpoint, int timeout);
NTSTATUS reset_endpoint(libusb_device_t *dev, int endpoint, int timeout);
NTSTATUS reset_device(libusb_device_t *dev, int timeout);
NTSTATUS claim_interface(libusb_device_t *dev, int interface);
NTSTATUS release_interface(libusb_device_t *dev, int interface);
NTSTATUS release_all_interfaces(libusb_device_t *dev);
bool_t reg_get_hardware_id(DEVICE_OBJECT *physical_device_object,
char *data, int size);
bool_t reg_get_properties(libusb_device_t *dev);
void power_set_device_state(libusb_device_t *dev,
DEVICE_POWER_STATE device_state, bool_t block);
USB_INTERFACE_DESCRIPTOR *
find_interface_desc(USB_CONFIGURATION_DESCRIPTOR *config_desc,
unsigned int size, int interface_number, int altsetting);
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/lib6lowpan/6lowpan.h | <filename>berkeley/blip-2.0/support/sdk/c/blip/lib6lowpan/6lowpan.h<gh_stars>1-10
/*
* "Copyright (c) 2008,2010 The Regents of the University of California.
* All rights reserved."
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
/*
* Header file for the 6lowpan/IPv6 stack.
*
* @author <NAME>
*
*/
#ifndef __6LOWPAN_H__
#define __6LOWPAN_H__
/*
* lengths of different lowpan headers
*/
enum {
LOWMSG_MESH_LEN = 5,
LOWMSG_BCAST_LEN = 2,
LOWMSG_FRAG1_LEN = 4,
LOWMSG_FRAGN_LEN = 5,
};
enum {
INET_MTU = 1280,
LIB6LOWPAN_MAX_LEN = 100,
LOWPAN_LINK_MTU = 109,
/*
* The time, in binary milliseconds, after which we stop waiting for
* fragments and report a failed receive. We
*/
FRAG_EXPIRE_TIME = 4096,
};
/*
* magic numbers from rfc4944; some of them shifted: mostly dispatch values.
*/
enum {
LOWPAN_NALP_PATTERN = 0x0,
LOWPAN_MESH_PATTERN = 0x2,
LOWPAN_FRAG1_PATTERN = 0x18,
LOWPAN_FRAGN_PATTERN = 0x1c,
LOWPAN_BCAST_PATTERN = 0x50,
};
enum {
LOWPAN_MESH_V_MASK = 0x20,
LOWPAN_MESH_F_MASK = 0x10,
LOWPAN_MESH_HOPS_MASK = 0x0f,
};
/*
* values for LOWPAN_IPHC from draft-ietf-6lowpan-hc-06
*/
enum {
LOWPAN_DISPATCH_BYTE_MASK = 0xe0,
LOWPAN_DISPATCH_BYTE_VAL = 0x60,
LOWPAN_IPHC_TF_MASK = 0x18,
LOWPAN_IPHC_TF_NONE = 0x18,
LOWPAN_IPHC_TF_ECN_DSCP = 0x10,
LOWPAN_IPHC_TF_ECN_FL = 0x08,
LOWPAN_IPHC_TF_ECN_DSCP_FL = 0x00,
LOWPAN_IPHC_NH_MASK = 0x04,
LOWPAN_IPHC_NH_INLINE = 0,
LOWPAN_IPHC_HLIM_MASK = 0x03,
LOWPAN_IPHC_HLIM_NONE = 0x00,
LOWPAN_IPHC_HLIM_1 = 0x01,
LOWPAN_IPHC_HLIM_64 = 0x02,
LOWPAN_IPHC_HLIM_255 = 0x03,
LOWPAN_IPHC_CID_MASK = 0x80,
LOWPAN_IPHC_CID_PRESENT = 0x80,
LOWPAN_IPHC_SAM_SHIFT = 4,
LOWPAN_IPHC_M = 0x08,
LOWPAN_IPHC_DAM_SHIFT = 0,
LOWPAN_IPHC_AC_CONTEXT = 0x04,
LOWPAN_IPHC_AM_MASK = 0x3,
LOWPAN_IPHC_AM_128 = 0x0,
LOWPAN_IPHC_AM_64 = 0x1,
LOWPAN_IPHC_AM_16 = 0x2,
LOWPAN_IPHC_AM_0 = 0x3,
LOWPAN_IPHC_AM_M = 0x08,
LOWPAN_IPHC_AM_M_128 = 0x0,
LOWPAN_IPHC_AM_M_48 = 0x1,
LOWPAN_IPHC_AM_M_32 = 0x2,
LOWPAN_IPHC_AM_M_8 = 0x3,
};
/*
* values for LOWPAN_IPNH from draft-ietf-6lowpan-hc-06
*/
enum {
LOWPAN_NHC_IPV6_MASK = 0xf0,
LOWPAN_NHC_IPV6_PATTERN = 0xe0,
LOWPAN_NHC_EID_SHIFT = 0x1,
LOWPAN_NHC_EID_MASK = 0xe,
LOWPAN_NHC_EID_HOP = 0x0 << LOWPAN_NHC_EID_SHIFT,
LOWPAN_NHC_EID_ROUTING = 0x1 << LOWPAN_NHC_EID_SHIFT,
LOWPAN_NHC_EID_FRAG = 0x2 << LOWPAN_NHC_EID_SHIFT,
LOWPAN_NHC_EID_DEST = 0x3 << LOWPAN_NHC_EID_SHIFT,
LOWPAN_NHC_EID_MOBILE = 0x4 << LOWPAN_NHC_EID_SHIFT,
LOWPAN_NHC_EID_IPV6 = 0x7 << LOWPAN_NHC_EID_SHIFT,
LOWPAN_NHC_NH = 0x1,
LOWPAN_NHC_UDP_MASK = 0xf8,
LOWPAN_NHC_UDP_PATTERN = 0xf0,
LOWPAN_NHC_UDP_CKSUM = 0x4,
LOWPAN_NHC_UDP_PORT_MASK = 0x3,
LOWPAN_NHC_UDP_PORT_FULL = 0x0,
LOWPAN_NHC_UDP_PORT_SRC_FULL = 0x1,
LOWPAN_NHC_UDP_PORT_DST_FULL = 0x2,
LOWPAN_NHC_UDP_PORT_SHORT = 0x3,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | uob/tossdr/ucla/gnuradio-802.15.4-demodulation/sos/modules/pong/pong.c | <filename>uob/tossdr/ucla/gnuradio-802.15.4-demodulation/sos/modules/pong/pong.c
/* -*- Mode: C; tab-width:4 -*- */
/* ex: set ts=4 shiftwidth=4 softtabstop=4 cindent: */
/**
* @brief
*/
/**
* Module needs to include <module.h>
*/
#include <sys_module.h>
#include <module.h>
#define LED_DEBUG
#include <led_dbg.h>
#define PONG_TIMER_INTERVAL 1024L
#define PONG_TID 0
#define PONGER_ID DFLT_APP_ID0
#define MSG_TEST MOD_MSG_START
/**
* Module can define its own state
*/
typedef struct {
uint8_t pid;
} app_state_t;
/**
* Module state and ID declaration.
* All modules should call the fallowing to macros to help the linker add
* module specific meta data to the resulting binary image. Note that the
* parameters my be different.
*/
/**
* Pong module
*
* @param msg Message being delivered to the module
* @return int8_t SOS status message
*
* Modules implement a module function that acts as a message handler. The
* module function is typically implemented as a switch acting on the message
* type.
*
* All modules should included a handler for MSG_INIT to initialize module
* state, and a handler for MSG_FINAL to release module resources.
*/
static int8_t module(void *start, Message *e);
/**
* This is the only global variable one can have.
*/
static mod_header_t mod_header SOS_MODULE_HEADER = {
.mod_id = DFLT_APP_ID0,
.state_size = sizeof(app_state_t),
.num_timers = 0,
.num_sub_func = 0,
.num_prov_func = 0,
.platform_type = HW_TYPE /* or PLATFORM_ANY */,
.processor_type = MCU_TYPE,
.code_id = ehtons(DFLT_APP_ID0),
.module_handler = module,
};
static int8_t module(void *state, Message *msg)
{
/**
* The module is passed in a void* that contains its state. For easy
* reference it is handy to typecast this variable to be of the
* applications state type. Note that since we are running as a module,
* this state is not accessible in the form of a global or static
* variable.
*/
app_state_t *s = (app_state_t*)state;
/**
* Switch to the correct message handler
*/
switch (msg->type){
/**
* MSG_INIT is used to initialize module state the first time the
* module is used. Many modules set timers at this point, so that
* they will continue to receive periodic (or one shot) timer events.
*/
case MSG_INIT:
{
LED_DBG(LED_YELLOW_TOGGLE);
s->pid = msg->did;
DEBUG("Pong Start\n");
break;
}
/**
* MSG_FINAL is used to shut modules down. Modules should release all
* resources at this time and take care of any final protocol
* shutdown.
*/
case MSG_FINAL:
{
DEBUG("Pong Stop\n");
break;
}
case MSG_TEST:
{
uint8_t* seq;
//MsgParam* params = (MsgParam*)(msg->data);
seq = (int8_t*) msg->data;
LED_DBG(LED_GREEN_TOGGLE);
post_net(PONGER_ID, PONGER_ID, MSG_TEST, sizeof(uint8_t), seq, SOS_MSG_HIGH_PRIORITY, BCAST_ADDRESS);
DEBUG("Recv Packet\n");
break;
}
/**
* The default handler is used to catch any messages that the module
* does no know how to handle.
*/
default:
return -EINVAL;
}
/**
* Return SOS_OK for those handlers that have successfully been handled.
*/
return SOS_OK;
}
#ifndef _MODULE_
mod_header_ptr pong_get_header()
{
return sos_get_header_address(mod_header);
}
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/tinyos/nodequeue.h |
#ifndef NODE_Q_H_INCLUDED
#define NODE_Q_H_INCLUDED
/**************************
* The queues in the run time system represent pending
* incoming edges in the graph.
**************************/
#define QUEUE_DELAY 100
#define QUEUE_LENGTH 15
#define NEXT_IDX(X) ((X + 1) % QUEUE_LENGTH)
typedef struct EdgeIn
{
uint8_t src_id; //This limits the number of nodes to 2^8.
uint8_t dst_id;
bool src;
uint8_t idx;
//these are being removed to allow better concurrency management
//uint8_t *invar;
//uint8_t *outvar;
} EdgeIn;
typedef struct EdgeQueue
{
uint8_t head, tail;
//uint16_t lock;
EdgeIn edges[QUEUE_LENGTH];
} EdgeQueue;
result_t
queue_init (EdgeQueue * q)
{
q->head = 0;
q->tail = 0;
return SUCCESS;
}
bool
isqueueempty (EdgeQueue * q)
{
return (q->tail == q->head);
}
bool
enqueue (EdgeQueue * q, EdgeIn edge)
{
bool result = FALSE;
if (NEXT_IDX (q->tail) == q->head)
{
//queue is full
result = FALSE;
} else {
memcpy (&q->edges[q->tail], &edge, sizeof (EdgeIn));
q->tail = NEXT_IDX (q->tail);
result = TRUE;
}
return result;
}
bool
dequeue (EdgeQueue * q, EdgeIn * edge)
{
bool result = FALSE;
if (q->tail == q->head)
{
//queue is empty
result = FALSE;
} else {
memcpy (edge, &q->edges[q->head], sizeof (EdgeIn));
q->head = NEXT_IDX (q->head);
result = TRUE;
}
return result;
}
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/util/collect/sfcollect.c | <reponame>tinyos-io/tinyos-3.x-contrib
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdint.h>
//#include <curses.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <poll.h>
#include <sys/types.h>
#include "sfsource.h"
#include <time.h>
#ifndef TOSH_DATA_LENGTH
#define TOSH_DATA_LENGTH 31
#define BUNDLE_ACK_DATA_LENGTH TOSH_DATA_LENGTH-4
#endif
#ifndef _REENTRANT
#define _REENTRANT
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
//#define TRUE (! FALSE)
#define TRUE -1
#endif
#define SRC_ADDR 1
#define AM_BEGIN_TRAVERSAL_MSG 17
#define AM_GO_NEXT_MSG 18
#define AM_GET_NEXT_CHUNK 19
#define AM_GET_BUNDLE_MSG 20
#define AM_DELETE_BUNDLE_MSG 21
#define AM_DELETE_ALL_BUNDLES_MSG 22
#define AM_END_DATA_COLLECTION_SESSION 23
#define AM_BUNDLE_INDEX_ACK 24
#define AM_RADIO_HI_POWER 25
#define AM_RADIO_LO_POWER 26
#define AM_DEADLOCK_MSG 27
#define AM_DELETE_ALL_ACK 28
#define MAX_RETRYS 100
#define MSG_HEADER_OFFSET 5
#define MSG_DATA_OFFSET MSG_HEADER_OFFSET+6
#define MSG_STATUS_OFFSET MSG_HEADER_OFFSET+5
#define MSG_BUNDLE_OFFSET MSG_HEADER_OFFSET+2
#define MSG_CHUNK_OFFSET MSG_HEADER_OFFSET+4
#define MAX_CHUNKS 20
#define HDR_CHUNK 0xFF
///////////////////////////////////////////////////////////////////////////////////////////////////
// TYPEDEFS
///////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct TOS_Msg
{
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
int8_t data[TOSH_DATA_LENGTH];
uint16_t crc;
} TOS_Msg;
typedef uint8_t bool;
///////////////////////////////////////////////////////////////////////////////////////////////////
// TINYOS COMM STRUCTS
///////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct BeginTraversalMsg {
uint16_t src_addr;
uint8_t seq_num;
} BeginTraversalMsg_t;
typedef struct GoNextMsg {
uint16_t src_addr;
uint8_t seq_num;
} GoNextMsg_t;
typedef struct GetBundleMsg {
uint16_t src_addr;
uint8_t seq_num;
} GetBundleMsg_t;
typedef struct DeleteBundleMsg {
uint16_t src_addr;
uint8_t seq_num;
} DeleteBundleMsg_t;
typedef struct BundleIndexAck {
uint16_t src_addr;
bool success;
uint8_t seq_num;
char data[BUNDLE_ACK_DATA_LENGTH];
} BundleIndexAck_t;
typedef struct GetNextChunk{
uint16_t src_addr;
uint8_t seq_num;
} GetNextChunk_t;
typedef struct EndCollectionSession{
uint16_t src_addr;
uint8_t seq_num;
} EndCollectionSession_t;
///////////////////////////////////////////////////////////////////////////////////////////////////
// WRAPPERS
///////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct w_BT {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint8_t seq_num;
} w_BT_t;
typedef struct w_GN {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint8_t seq_num;
} w_GN_t;
typedef struct w_GB {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint8_t seq_num;
} w_GB_t;
typedef struct w_DB {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint8_t seq_num;
} w_DB_t;
typedef struct w_GNC {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint8_t seq_num;
} w_GNC_t;
typedef struct w_ECS {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint8_t seq_num;
} w_ECS_t;
typedef struct gen_msg {
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
uint16_t src_addr;
uint16_t bundle;
} gen_msg_t;
#pragma pack(1)
typedef struct TOS_write
{
int fd;
int mote_addr;
} TOS_write_t;
#define TOS_MSG_SIZE 2*sizeof(uint16_t) + 5*sizeof(uint8_t)
#define MSG_TIMEOUT 500
void* get_packet( gen_msg_t *tos)
{
void *ret = malloc(TOS_MSG_SIZE);
int offset = 0;
memcpy(ret+offset, &tos->addr, sizeof(uint16_t) );
offset += sizeof(uint16_t);
memcpy(ret+offset, &tos->type, sizeof(uint8_t) );
offset += sizeof(uint8_t);
memcpy(ret+offset, &tos->group, sizeof(uint8_t) );
offset += sizeof(uint8_t);
memcpy(ret+offset, &tos->length, sizeof(uint8_t) );
offset += sizeof(uint8_t);
memcpy(ret+offset, &tos->src_addr, sizeof(uint16_t) );
offset += sizeof(uint16_t);
memcpy(ret+offset, &tos->bundle, sizeof(uint8_t) );
return ret;
}
/*void* mote_write(void *buf)
{
TOS_write_t *tos = (TOS_write_t *) buf;
uint8_t seq_num = 0;
gen_msg_t msg;
char *my_string;
int nbytes = 100;
int bytes_read;
msg.addr = tos->mote_addr;
msg.group = 0x7d;
msg.length = sizeof(uint16_t)+sizeof(uint8_t);
msg.src_addr = SRC_ADDR;
printf("What would you like to do: \n");
printf("bd: Bundle Delete \n");
printf("gb: Get Bundle \n");
printf("gc: Get Next Chunk \n");
printf("bt: Begin Traversal \n");
printf("gn: Go Next \n");
printf("ec: End Collection Session\n");
while (1)
{
int w_ret = 0;
void *data;
my_string = (char *) malloc (nbytes + 1);
bytes_read = getline (&my_string, &nbytes, stdin);
if (my_string[0] == 's' && my_string[1] == 'n')
{
seq_num++;
printf ("Sequence Number incremented: %d\n",seq_num);
}
if (my_string[0] == 'b' && my_string[1] == 'd')
{
msg.seq_num = seq_num;
msg.type = AM_DELETE_BUNDLE_MSG;
data = get_packet(&msg);
w_ret = write_sf_packet(tos->fd, data, TOS_MSG_SIZE);
free(data);
}
if (my_string[0] == 'g' && my_string[1] == 'b')
{
msg.seq_num = seq_num;
msg.type = AM_GET_BUNDLE_MSG;
data = get_packet(&msg);
w_ret = write_sf_packet(tos->fd, data, TOS_MSG_SIZE);
free(data);
}
if (my_string[0] == 'g' && my_string[1] == 'c')
{
msg.seq_num = seq_num;
msg.type = AM_GET_NEXT_CHUNK;
data = get_packet(&msg);
w_ret = write_sf_packet(tos->fd, data, TOS_MSG_SIZE);
free(data);
}
if (my_string[0] == 'b' && my_string[1] == 't')
{
msg.seq_num = seq_num;
msg.type = AM_BEGIN_TRAVERSAL_MSG;
data = get_packet(&msg);
w_ret = write_sf_packet(tos->fd, data, TOS_MSG_SIZE);
free(data);
}
if (my_string[0] == 'g' && my_string[1] == 'n')
{
msg.seq_num = seq_num;
msg.type = AM_GO_NEXT_MSG;
data = get_packet(&msg);
w_ret = write_sf_packet(tos->fd, data, TOS_MSG_SIZE);
free(data);
}
if (my_string[0] == 'e' && my_string[1] == 'c')
{
msg.seq_num = seq_num;
msg.type = AM_END_DATA_COLLECTION_SESSION;
data = get_packet(&msg);
w_ret = write_sf_packet(tos->fd, data, TOS_MSG_SIZE);
free(data);
}
if (w_ret == -1)
{
printf("error writing to socket... exiting\n");
exit (0);
}
}
return NULL;
}*/
void mote_read(void *buf)
{
TOS_write_t *tos = (TOS_write_t *) buf;
for (;;)
{
int len, i;
struct pollfd pl;
pl.fd = tos->fd;
pl.events = POLLIN;
//if (poll(&pl, 1, 3000))
if (poll(&pl, 1, 1500))
{
printf("about to read: \n");
}
else
{
printf("timed out \n");
}
const unsigned char *packet = read_sf_packet(tos->fd, &len);
if (!packet)
exit(0);
for (i = 0; i < len; i++)
{
if (i == 5 || i== 9)
printf("| ");
printf("%02x ", packet[i]);
}
putchar('\n');
fflush(stdout);
free((void *)packet);
}
}
/*enum
{
STATE_START_TRAVERSAL,
STATE_GET_BUNDLE,
STATE_GET_NEXT_CHUNK,
STATE_G0_NEXT_BUNDLE,
STATE_END_COLLECTION
};*/
enum
{
STATE_WAKE,
STATE_GET_BUNDLES,
STATE_SLEEP,
};
bool listen_for_message(const unsigned char **packet, int fd, int *length)
{
struct pollfd pl;
int len;
pl.fd = fd;
pl.events = POLLIN;
if (poll(&pl, 1, MSG_TIMEOUT))
{
// read that packet;
*packet = read_sf_packet(fd, &len);
// we got a packet but it's not the kind we were expecting...
if ( (*packet)[2] != 24)
{
free(*packet);
*packet = NULL;
return listen_for_message(packet, fd, length);
}
else
{
//print_received_message(*packet, fd, len);
*length = len;
return TRUE;
}
}
else
{
*length = -1;
return FALSE;
}
//return packet;
}
void print_received_message(const unsigned char *packet, int len)
{
int i;
for (i = 0; i < len; i++)
{
if (i == MSG_HEADER_OFFSET || i == MSG_DATA_OFFSET)
printf("| ");
printf("%02x ", packet[i]);
}
printf("\n");
}
void print_data_message(const unsigned char *packet, int len, FILE *Fp)
{
int i;
for (i = 0; i < len; i++)
{
//if (i == MSG_HEADER_OFFSET || i == MSG_DATA_OFFSET)
// printf("| ");
fprintf(Fp, "%02x ", packet[i]);
}
fprintf(Fp, "\n");
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// This is where the Magic Happens
///////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
///////////////////////////////////////////////////////////////////////////////////////////////
// Communication Variables
///////////////////////////////////////////////////////////////////////////////////////////////
int fd;
int mote_addr;
TOS_write_t tos_write;
struct pollfd pl;
///////////////////////////////////////////////////////////////////////////////////////////////
// Collection Variables
///////////////////////////////////////////////////////////////////////////////////////////////
gen_msg_t msg;
int state = STATE_GET_BUNDLES;
int bundle_offset = 0;
int num_retrys = 0;
int total_msgs;
uint32_t num_bundles = 0;
uint32_t curr_nundle_num = 0;
FILE *Fp;
///////////////////////////////////////////////////////////////////////////////////////////////
// Thread Variables
///////////////////////////////////////////////////////////////////////////////////////////////
pthread_t *read_thread;
pthread_t *write_thread;
pthread_attr_t pthread_custom_attr;
pthread_attr_init(&pthread_custom_attr);
read_thread = (pthread_t *) malloc(sizeof(pthread_t));
write_thread = (pthread_t *) malloc(sizeof(pthread_t));
if (argc != 4)
{
fprintf(stderr, "Usage: %s <host> <port> <mote_addr> - dump packets from a serial forwarder %d \n", argv[0], argc);
exit(2);
}
fd = open_sf_source(argv[1], atoi(argv[2]));
if (fd < 0)
{
fprintf(stderr, "Couldn't open serial forwarder at %s:%s\n", argv[1], argv[2]);
exit(1);
}
Fp = fopen("data.txt", "w+");
mote_addr = atoi(argv[3]);
msg.addr = mote_addr;
msg.group = 0x7d;
msg.length = sizeof(uint16_t)+sizeof(uint8_t);
msg.src_addr = SRC_ADDR;
pl.fd = fd;
pl.events = POLLIN;
int chunk_vector[MAX_CHUNKS];
int numchunks;
memset(chunk_vector, 0, sizeof(chunk_vector));
numchunks = -1;
while (1337)
{
int w_ret;
void *data;
int len;
int i=0;
bool done = FALSE;
const unsigned char *packet;
int timeouts;
bool endfound = FALSE;
switch (state) {
case STATE_GET_BUNDLES:
printf ("Sending GET_BUNDLE_MSG Message \n");
msg.bundle = bundle_offset;
msg.type = AM_GET_BUNDLE_MSG;
msg.length = 4;
data = get_packet(&msg);
w_ret = write_sf_packet(fd, data, TOS_MSG_SIZE);
timeouts = 0;
while (!done)
{
printf("listen_for_message\n");
if ( listen_for_message(&packet, fd, &len) )
{
printf("got packet (len=%d)\n", len);
int pkt_bundle = (packet[MSG_BUNDLE_OFFSET+1] << 8) | packet[MSG_BUNDLE_OFFSET];
printf("for bundle: %d (%d,%d)\n", pkt_bundle,packet[MSG_BUNDLE_OFFSET+1],packet[MSG_BUNDLE_OFFSET]);
//is this for the bundle I'm interested in?
if (pkt_bundle == bundle_offset)
{
// success?
if (packet[MSG_STATUS_OFFSET] == 0x02)
{
//is it the header?
if (packet[MSG_CHUNK_OFFSET] == HDR_CHUNK)
{
uint16_t turtle_num;
uint16_t bundle_num;
num_retrys = 0;
timeouts = 0;
printf ("Got Bundle Header \n");
print_received_message(packet, len);
memcpy(&turtle_num, &packet[MSG_DATA_OFFSET], sizeof(uint16_t) );
memcpy(&bundle_num, &packet[MSG_DATA_OFFSET+2], sizeof(uint16_t) );
fprintf(Fp, "Turtle: %d Bundle: %d\n", turtle_num, bundle_num);
} else {
//its a chunk
num_retrys = 0;
timeouts = 0;
chunk_vector[packet[MSG_CHUNK_OFFSET]] = 1;
printf ("Got a chunk : %d \n", packet[MSG_CHUNK_OFFSET]);
print_data_message(packet, len, Fp);
}
}
else if (packet[MSG_STATUS_OFFSET] == 0x03) // end of something
{
if (packet[MSG_CHUNK_OFFSET] == HDR_CHUNK)
{
//no valid chunk here
num_retrys = 0;
timeouts = 0;
printf("Bundle is not valid.\n");
bundle_offset++;
} else {
num_retrys = 0;
timeouts = 0;
endfound = TRUE;
numchunks = packet[MSG_CHUNK_OFFSET];
printf ("End of bundle reached : %d chunks\n", numchunks);
//check the vector
done = TRUE;
int j;
for (j=0; j < numchunks; j++)
{
if (chunk_vector[j] != 1)
{
done = FALSE;
printf("X");
} else {
printf(".");
}
}
printf("\n");
if (done)
{
numchunks = -1;
memset(chunk_vector, 0, sizeof(chunk_vector));
bundle_offset++;
}
done = TRUE;
}
}
else if (packet[MSG_STATUS_OFFSET] == 0x01) // end of something
{
printf("That's all of the bundles.\n");
state = STATE_SLEEP;
done = TRUE;
}
else // BAD
{
if (num_retrys > MAX_RETRYS)
{
printf ("GetBundle FAILED.. EXITING \n");
exit(0);
}
num_retrys++;
printf ("ERROR: GetBundle failed... trying again \n");
}
}
free(packet);
} else {
//do done check
/*if (numchunks != -1)
{
done = TRUE;
int j;
for (j=0; j < numchunks; j++)
{
if (chunk_vector[j] != 1)
{
done = FALSE;
printf("X");
} else {
printf(".");
}
}
printf("\n");
if (done)
{
numchunks = -1;
memset(chunk_vector, 0, sizeof(chunk_vector));
bundle_offset++;
}
done = TRUE;
}*/
timeouts++;
if (timeouts > 2)
{
break;
}
}
}//while
printf("Broke out\n");
free (data);
break;
default:
printf("ERROR: %d is not a known state\n", state);
exit(0);
break;
}
if (w_ret == -1)
{
printf("error writing to socket... exiting\n");
exit (0);
}
}
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | berkeley/quanto/tos/lib/quanto/MultiContext/MultiContext.h | #ifndef MULTI_ACTIVITY_H
#define MULTI_ACTIVITY_H
#define MULTI_CONTEXT_UNIQUE "Multi.Context.Unique"
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/quanto/tools/quanto/labjack/QuantoLogger.c | <filename>berkeley/quanto/tools/quanto/labjack/QuantoLogger.c
/**
* Captures data on EIO and FIO on an external trigger and streams the
* data over a TCP stream. The required message exchanges between the
* host the LabJack device is as follows:
*
* 1. Host ----[StreamConfig]---> LabJack // Command
* 2. Host <---[StreamConfig]---- LabJack // Response
* 3. Host ----[StreamStart]----> LabJack // Command
* 4. Host <---[StreamData]------ LabJack // Response
* ... ... ...
* ... ... ...
* ... ... ...
* 7. Host <---[StreamData]------ LabJack // Response
* 8. Host ----[StreamStop]-----> LabJack // Command
* 9. Host <---[StreamStop]------ LabJack // Response
*
*/
#include "ue9.h"
#include <signal.h>
char *ipAddress;
const int porta = 52360;
const int portb = 52361;
const int ainResolution = 12;
const uint8 NumChannels = 1;
int StreamConfig(int sfd);
int StreamStart(int sfd);
int StreamData(int sfda, int sfdb, ue9CalibrationInfo *caliInfo);
int StreamStop(int sfda, int displayError);
int flushStream(int sfd);
int flush(int sfda);
/**
* Closes the control and data streams to the LabJack.
* @param sda the socket descriptor for the control stream.
* @param sdb the socket descriptor for the data stream.
*/
int StreamClose(int sda, int sdb) {
return closeTCPConnection(sda) + closeTCPConnection(sdb);
}
/**
* Stops the stream and then flushes the stream buffer.
* @param sd the socket descriptor to flush.
*/
int flush(int sd) {
fprintf(stderr, "Flushing stream.\n");
StreamStop(sd, 0);
flushStream(sd);
return 0;
}
void cleanup(int s) {
fflush(stdout);
exit(s);
}
int main(int argc, char **argv) {
ue9CalibrationInfo caliInfo;
int fda, fdb;
fda = -1;
fdb = -1;
signal(SIGINT, cleanup);
if(argc != 2) {
fprintf(stderr, "Usage: QuantoLogger <remote-address>\n");
exit(0);
}
ipAddress = argv[1];
if( (fda = openTCPConnection(ipAddress, porta)) < 0) {
exit(0);
}
flush(fda);
if( (fdb = openTCPConnection(ipAddress, portb)) < 0) {
StreamClose(fda, fdb);
}
if(StreamConfig(fda) != 0) {
StreamClose(fda, fdb);
}
if(StreamStart(fda) != 0) {
StreamClose(fda, fdb);
}
StreamData(fda, fdb, &caliInfo);
StreamStop(fda, 1);
exit(0);
}
/**
* Configures LabJack to capture EIO and FIO on FIOx falling edge.
* @param sfd socket connected to the control stream.
*/
int StreamConfig(int sfd) {
int sendBuffSize;
uint8 *sendBuff;
uint8 recBuff[8];
int sendChars, recChars;
uint16 checksumTotal, scanInterval;
sendBuffSize = 12 + 2*NumChannels;
sendBuff = malloc(sizeof(uint8)*sendBuffSize);
sendBuff[1] = (uint8)(0xF8); //command byte
sendBuff[2] = NumChannels + 3; //number of data words : NumChannels + 3
sendBuff[3] = (uint8)(0x11); //extended command number
sendBuff[6] = (uint8)NumChannels; //NumChannels
sendBuff[7] = ainResolution; //resolution
sendBuff[8] = 0; //SettlingTime = 0
sendBuff[9] = 0x40; //Ext trig
scanInterval = 4000;
sendBuff[10] = (uint8)(scanInterval & 0x00FF); //scan interval (low byte)
sendBuff[11] = (uint8)(scanInterval / 256); //scan interval (high byte)
sendBuff[12] = 193;
sendBuff[13] = 0;
extendedChecksum(sendBuff, sendBuffSize);
// Send command to UE9
sendChars = send(sfd, sendBuff, sendBuffSize, 0);
if(sendChars < sendBuffSize) {
if(sendChars == -1) {
fprintf(stderr,"Error : send failed (StreamConfig)\n");
}
else {
fprintf(stderr, "Error : did not send all of the buffer (StreamConfig)\n");
free(sendBuff);
sendBuff = NULL;
return -1;
}
}
// Receive response from UE9
recChars = recv(sfd, recBuff, 8, 0);
if(recChars < 8) {
if(recChars == -1) {
fprintf(stderr, "Error : receive failed (StreamConfig)\n");
}
else {
fprintf(stderr, "Error : did not receive all of the buffer (StreamConfig)\n");
}
free(sendBuff);
sendBuff = NULL;
}
checksumTotal = extendedChecksum16(recBuff, 8);
if( (uint8)((checksumTotal / 256) & 0xff) != recBuff[5]) {
fprintf(stderr, "Error : received buffer has bad checksum16(MSB) (StreamConfig)\n");
free(sendBuff);
sendBuff = NULL;
return -1;
}
if( (uint8)(checksumTotal & 0xff) != recBuff[4]) {
fprintf(stderr, "Error : received buffer has bad checksum16(LBS) (StreamConfig)\n");
free(sendBuff);
sendBuff = NULL;
return -1;
}
if( extendedChecksum8(recBuff) != recBuff[0]) {
fprintf(stderr, "Error : received buffer has bad checksum8 (StreamConfig)\n");
free(sendBuff);
sendBuff = NULL;
return -1;
}
if(recBuff[1] != (uint8)(0xF8) ||
recBuff[2] != (uint8)(0x01) ||
recBuff[3] != (uint8)(0x11) ||
recBuff[7] != (uint8)(0x00)) {
fprintf(stderr, "Error : received buffer has wrong command bytes (StreamConfig)\n");
free(sendBuff);
sendBuff = NULL;
return -1;
}
if(recBuff[6] != 0) {
fprintf(stderr, "Errorcode # %d from StreamConfig received.\n",
(unsigned int)recBuff[6]);
free(sendBuff);
sendBuff = NULL;
return -1;
}
return 0;
}
/**
* Send command to start streaming.
* @param sfd socket connected to control stream.
*/
int StreamStart(int sfd) {
uint8 sendBuff[2], recBuff[4];
int sendChars, recChars;
sendBuff[0] = (uint8)(0xA8); //CheckSum8
sendBuff[1] = (uint8)(0xA8); //command byte
// Send command to UE9
sendChars = send(sfd, sendBuff, 2, 0);
if(sendChars < 2) {
if(sendChars == -1) {
fprintf(stderr, "Error : send failed\n");
}
else {
fprintf(stderr, "Error : did not send all of the buffer\n");
}
return -1;
}
// Receive response from UE9
recChars = recv(sfd, recBuff, 4, 0);
if(recChars < 4) {
if(recChars == -1) {
fprintf(stderr, "Error : receive failed\n");
}
else {
fprintf(stderr, "Error : did not receive all of the buffer\n");
}
return -1;
}
if( recBuff[1] != (uint8)(0xA9) || recBuff[3] != (uint8)(0x00) ) {
fprintf(stderr, "Error : received buffer has wrong command bytes \n");
return -1;
}
if(recBuff[2] != 0) {
fprintf(stderr, "Errorcode # %d from StreamStart received.\n",
(unsigned int)recBuff[2]);
return -1;
}
return 0;
}
/**
* Reads the StreamData.
*/
int StreamData(int sfda, int sfdb, ue9CalibrationInfo *caliInfo) {
uint8_t j, cnt, start_frame, first, sync;
uint8_t buf[46];
first = 1;
sync = 0;
fprintf(stderr, "QuantoLogger: Reading StreamData\n");
while(1) {
//for (i = 0 ; i < 100; i++) {
cnt = 0;
do {
cnt += recv(sfdb, &buf[cnt], 46-cnt, 0);
} while(cnt < 46);
//printf("%d : ", buf[10]);
for (j = 12; j < 44; j = j+1) {
if (!(j % 2)) {
//control byte
start_frame = (buf[j] & 0x2);
if (!sync && start_frame)
sync = 1;
if (first) {
start_frame = 0;
first = 0;
}
} else {
if (sync) {
if (start_frame) {
printf("\n");
fflush(stdout);
}
printf("%02X ", buf[j]);
} else {
//skipping bytes, not synchronized
fprintf(stderr,".");
}
}
}
}
return 0;
}
/**
* Sends a StreamStop low-level command to stop streaming.
* @param sfd socket to control stream.
*/
int StreamStop(int sfd, int displayError) {
uint8 sendBuff[2], recBuff[4];
int sendChars, recChars;
sendBuff[0] = (uint8)(0xB0); //CheckSum8
sendBuff[1] = (uint8)(0xB0); //command byte
sendChars = send(sfd, sendBuff, 2, 0);
if(sendChars < 2) {
if(displayError) {
if(sendChars == -1) {
fprintf(stderr, "Error : send failed (StreamStop)\n");
}
else {
fprintf(stderr, "Error : did not send all of the buffer (StreamStop)\n");
}
return -1;
}
}
//Receiving response from UE9
recChars = recv(sfd, recBuff, 4, 0);
if(recChars < 4) {
if(displayError) {
if(recChars == -1) {
fprintf(stderr, "Error : receive failed (StreamStop)\n");
}
else {
fprintf(stderr, "Error : did not receive all of the buffer (StreamStop)\n");
}
}
return -1;
}
if( recBuff[1] != (uint8)(0xB1) || recBuff[3] != (uint8)(0x00) ) {
if(displayError) {
fprintf(stderr, "Error : received buffer has wrong command bytes (StreamStop)\n");
}
return -1;
}
if(recBuff[2] != 0) {
if(displayError)
fprintf(stderr, "Errorcode # %d from StreamStop received.\n",
(unsigned int)recBuff[2]);
return -1;
}
return 0;
}
/**
* Sends a command to clear the stream buffer.
* @param sfd socket to control stream.
*/
int flushStream(int sfd) {
uint8 sendBuff[2], recBuff[2];
int sendChars, recChars;
sendBuff[0] = (uint8)(0x08); //CheckSum8
sendBuff[1] = (uint8)(0x08); //command byte
// Send command to UE9
sendChars = send(sfd, sendBuff, 2, 0);
if(sendChars < 2) {
if(sendChars == -1) {
fprintf(stderr, "Error : send failed (flushStream)\n");
}
else {
fprintf(stderr, "Error : did not send all of the buffer (flushStream)\n");
}
return -1;
}
// Receive response from UE9
recChars = recv(sfd, recBuff, 4, 0);
if(recChars < 2) {
if(recChars == -1) {
fprintf(stderr, "Error : receive failed (flushStream)\n");
}
else {
fprintf(stderr, "Error : did not receive all of the buffer (flushStream)\n");
}
return -1;
}
if(recBuff[0] != (uint8)(0x08) || recBuff[1] != (uint8)(0x08)) {
fprintf(stderr, "Error : received buffer has wrong command bytes (flushStream)\n");
return -1;
}
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | ethz/snpk/tos/lib/dsn/DSN.h | #ifndef DSN_H
#define DSN_H
enum {
LOG_DELIMITER = '\n',
MSP430_ID_ADDR = 0xfe00,
RXBUFFERSIZE = 128,
NO_ID = 0xffff,
LOG_NR_BUFFERSIZE = 32,
RX_TIMEOUT_MILLI = 5,
};
typedef struct VarStruct {
void * pointer;
uint8_t length;
uint8_t * description;
} VarStruct;
#ifndef BUFFERSIZE
#define BUFFERSIZE 1024
#endif
// define DBG macro
//#define DSN_DBG_MACRO
#ifdef DSN_DBG_MACRO
#ifdef dbg
#undef dbg
#endif
#define dbg(a,b) DSN.logDebug("#b");
#endif
#endif
|
tinyos-io/tinyos-3.x-contrib | kasetsart/tos/chips/mrf24j40/mrf24.h | #ifndef __MRF24_H__
#define __MRF24_H__
#ifndef TFRAMES_ENABLED
#define MRF24_IFRAME_TYPE
#endif
#ifndef TOSH_DATA_LENGTH
#define TOSH_DATA_LENGTH 28
#endif
#ifndef MRF24_DEF_CHANNEL
#define MRF24_DEF_CHANNEL 26
#endif
/**
* The 6LowPAN NALP ID for a TinyOS network is 63 (TEP 125).
*/
#ifndef TINYOS_6LOWPAN_NETWORK_ID
#define TINYOS_6LOWPAN_NETWORK_ID 0x3f
#endif
#define CHANNEL(x) (0x2|((x-11)<<4))
#define LOW_BYTE(x) (x & 0xFF)
#define HIGH_BYTE(x) (x >> 8)
typedef nx_struct mrf24_header
{
nxle_uint16_t frame_ctrl;
nxle_uint8_t frame_id;
nxle_uint16_t dstpan;
nxle_uint16_t dst;
//nxle_uint16_t srcpan; --> Not used in intra-PAN
nxle_uint16_t src;
/*** IEEE 802.15.4 data payload starts here ***/
#ifdef MRF24_IFRAME_TYPE
nxle_uint8_t network;
#endif
nxle_uint8_t type;
} mrf24_header_t;
typedef nx_struct mrf24_footer
{
} mrf24_footer_t;
typedef nx_struct mrf24_metadata
{
nxle_uint8_t payload_len;
nxle_uint8_t lqi;
nxle_uint8_t rssi;
nxle_uint8_t num_retries;
nx_bool cca_fail;
nx_bool acked;
} mrf24_metadata_t;
typedef enum ShortRegAddress
{
RXMCR = 0x00,
PANIDL = 0x01,
PANIDH = 0x02,
SADRL = 0x03,
SADRH = 0x04,
EADR0 = 0x05,
EADR1 = 0x06,
EADR2 = 0x07,
EADR3 = 0x08,
EADR4 = 0x09,
EADR5 = 0x0A,
EADR6 = 0x0B,
EADR7 = 0x0C,
RXFLUSH = 0x0D,
ORDER = 0x10,
TXMCR = 0x11,
ACKTMOUT = 0x12,
ESLOTG1 = 0x13,
SYMTICKL = 0x14,
SYMTICKH = 0x15,
PACON0 = 0x16,
PACON1 = 0x17,
PACON2 = 0x18,
TXBCON0 = 0x1A,
TXNCON = 0x1B,
TXG1CON = 0x1C,
TXG2CON = 0x1D,
ESLOTG23 = 0x1E,
ESLOTG45 = 0x1F,
ESLOTG67 = 0x20,
TXPEND = 0x21,
WAKECON = 0x22,
FRMOFFSET = 0x23,
TXSTAT = 0x24,
TXBCON1 = 0x25,
GATECLK = 0x26,
TXTIME = 0x27,
HSYMTMRL = 0x28,
HSYMTMRH = 0x29,
SOFTRST = 0x2A,
SECCON0 = 0x2C,
SECCON1 = 0x2D,
TXSTBL = 0x2E,
RXSR = 0x30,
INTSTAT = 0x31,
INTCON = 0x32,
GPIO = 0x33,
TRISGPIO = 0x34,
SLPACK = 0x35,
RFCTL = 0x36,
SECCR2 = 0x37,
BBREG0 = 0x38,
BBREG1 = 0x39,
BBREG2 = 0x3A,
BBREG3 = 0x3B,
BBREG4 = 0x3C,
BBREG6 = 0x3E,
CCAEDTH = 0x3F
} ShortRegAddr;
typedef enum LongRegAddress
{
RFCON0 = 0x200,
RFCON1 = 0x201,
RFCON2 = 0x202,
RFCON3 = 0x203,
RFCON5 = 0x205,
RFCON6 = 0x206,
RFCON7 = 0x207,
RFCON8 = 0x208,
SLPCAL0 = 0x209,
SLPCAL1 = 0x20A,
SLPCAL2 = 0x20B,
RFSTATE = 0x20F,
RSSI = 0x210,
SLPCON0 = 0x211,
SLPCON1 = 0x220,
Reserved = 0x221,
WAKETIMEL = 0x222,
WAKETIMEH = 0x223,
REMCNTL = 0x224,
REMCNTH = 0x225,
MAINCNT0 = 0x226,
MAINCNT1 = 0x227,
MAINCNT2 = 0x228,
MAINCNT3 = 0x229,
TESTMODE = 0x22F,
ASSOEADR0 = 0x230,
ASSOEADR1 = 0x231,
ASSOEADR2 = 0x232,
ASSOEADR3 = 0x233,
ASSOEADR4 = 0x234,
ASSOEADR5 = 0x235,
ASSOEADR6 = 0x236,
ASSOEADR7 = 0x237,
ASSOSADR0 = 0x238,
ASSOSADR1 = 0x239,
UPNONCE0 = 0x240,
UPNONCE1 = 0x241,
UPNONCE2 = 0x242,
UPNONCE3 = 0x243,
UPNONCE4 = 0x244,
UPNONCE5 = 0x245,
UPNONCE6 = 0x246,
UPNONCE7 = 0x247,
UPNONCE8 = 0x248,
UPNONCE9 = 0x249,
UPNONCE10 = 0x24A,
UPNONCE11 = 0x24B,
UPNONCE12 = 0x24C,
RXFRMLEN = 0x300,
RXSRCADDRL = 0x30A
} LongRegAddr;
enum
{
MRF24_TX_NORMAL_FIFO = 0x000,
MRF24_RX_NORMAL_FIFO = 0x300
};
/////////////////////////////////////////////////
// INTSTAT: Interrupt Status Register (page 51)
/////////////////////////////////////////////////
typedef union
{
uint8_t flat;
struct
{
uint8_t txnif : 1;
uint8_t txg1ie : 1;
uint8_t txg2ie : 1;
uint8_t rxif : 1;
uint8_t secie : 1;
uint8_t hsymtmrie : 1;
uint8_t wakeie : 1;
uint8_t slpie : 1;
} bits;
} Mrf24_INTSTAT_t;
/////////////////////////////////////////////////
// TXSTAT: TX MAC Status Register (page 41)
/////////////////////////////////////////////////
typedef union
{
uint8_t flat;
struct
{
uint8_t txnstat : 1;
uint8_t txg1stat : 1;
uint8_t txg2stat : 1;
uint8_t txg1fnt : 1;
uint8_t txg2fnt : 1;
uint8_t ccafail : 1;
uint8_t txnretry : 2;
} bits;
} Mrf24_TXSTAT_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | uoit/mda300ca/mda300.h | #ifndef _MDA300_H
#define _MDA300_H
#define UQ_ADC_RESOURCE "mts300.ADC"
#define UQ_DIO_RESOURCE "mts300.DIO"
#define UQ_SHT15_RESOURCE "mts300.SHT15"
#define UQ_ARBITER_RESOURCE "mts300.arbiter"
enum
{
TOS_SHT15_DATA_POT_ADDR = 0x5A,
TOS_SHT15_CLK_POT_ADDR = 0x58,
};
// debug leds
//#define _DEBUG_LEDS
#ifdef _DEBUG_LEDS
#define DEBUG_LEDS(X) X.DebugLeds -> LedsC
#else
#define DEBUG_LEDS(X) X.DebugLeds -> NoLedsC
#endif
#endif /* _MDA300_H */
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/client/sfaccess/telossource.c |
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "sfsource.h"
#include "telossource.h"
#include "teloscomm.h"
uint32_t platform;
uint8_t telos_dsn = 0;
pthread_mutex_t sfreadmutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t sfwritemutex = PTHREAD_MUTEX_INITIALIZER;
int open_telos_source(const char *host, int port)
{
int result;
pthread_mutex_lock(&sfwritemutex);
//add any telos specific code here
result = open_sf_source(host,port);
pthread_mutex_unlock(&sfwritemutex);
return result;
}
extern uint32_t platform;
int init_telos_source(int fd)
{
int result;
pthread_mutex_lock(&sfwritemutex);
//add any telos specific code here
result = init_sf_source(fd);
pthread_mutex_unlock(&sfwritemutex);
return result;
}
int free_telos_packet(telospacket **pkt)
{
free((*pkt)->data);
free(*pkt);
*pkt = NULL;
return 0;
}
telospacket *read_telos_packet(int fd)
{
int length;
telospacket *packet;
int i;
const unsigned char *rawpkt;
//make sure I'm the only one reading the serial port
//pthread_mutex_lock(&sfreadmutex);
rawpkt = read_sf_packet(fd, &length);
dbg(TSRC,"read_sf_packet returned (rawpkt=%X, length=%i).\n",(int)rawpkt, length);
if (rawpkt == NULL)
{
dbg(TSRC,"rawpkt is NULL\n");
return NULL;
}
printf("Got data...\n");
for (i=0; i < length; i++)
printf("%X ", rawpkt[i]);
printf("\nGet done.\n");
//pthread_mutex_unlock(&sfreadmutex);
if (length < 10)
{
dbg(TSRC,"too short.\n");
free((void*)rawpkt);
return NULL;
}
packet = malloc(sizeof(telospacket));
//get header information
packet->length = rawpkt[0];
packet->dsn = rawpkt[3];
packet->type = rawpkt[8];
packet->group = rawpkt[9];
packet->addr = rawpkt[6] | (rawpkt[7] << 8);
packet->data = malloc(packet->length);
if (!packet->data)
{
printf("Out of memory!\n");
free(packet);
}
printf("addr=%X\n",packet->addr);
memcpy(packet->data, rawpkt+10, packet->length);
free((void*)rawpkt);
return packet;
}
int write_telos_packet(int fd, const telospacket *packet)
/* Effects: writes len byte packet to serial forwarder on file descriptor
fd
Returns: 0 if packet successfully written, -1 otherwise
*/
{
unsigned char l;
uint8_t *buffer;
int result;
int i;
if (packet->length > TOS_DATA_LENGTH)
{
dbg(TSRC,"packet too long! (%i bytes)\n",packet->length);
return -1;
}
buffer = malloc(packet->length + 10);
buffer[0] = packet->length;
buffer[1] = 0x01;
buffer[2] = 0x08;
buffer[3] = telos_dsn;
telos_dsn++;
buffer[4] = 0xff;
buffer[5] = 0xff;
buffer[6] = packet->addr & 0x0F;
buffer[7] = (packet->addr >> 8) & 0x0F;
buffer[8] = packet->type;
buffer[9] = packet->group;
memcpy(buffer+10, packet->data, packet->length);
printf("Sending data...\n");
for (i=0; i < packet->length + 10; i++)
printf("%X ", buffer[i]);
printf("\nSend done.\n");
l = packet->length + 10;
pthread_mutex_lock(&sfwritemutex);
result = write_sf_packet(fd, (void*)buffer, packet->length+10);
pthread_mutex_unlock(&sfwritemutex);
free((void*)buffer);
return result;
}
|
tinyos-io/tinyos-3.x-contrib | wustl/upma/lib/macs/scp-wustl/ScpSyncMsg.h | /*
* "Copyright (c) 2007 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
#ifndef __SCPSYNCMSG_H
#define __SCPSYNCMSG_H
#include "ScpConstants.h"
typedef nx_struct ScpSyncMsg
{
nx_uint16_t time;
} ScpSyncMsg;
enum
{
AM_SCPSYNCMSG = AM_PREAMBLEPACKET - 1,
AM_SCPBOOTMSG = AM_SCPSYNCMSG - 1,
};
#endif /* __SCPSYNCMSG_H */
|
tinyos-io/tinyos-3.x-contrib | tinybt/apps/BluetoothTester/src/bttester.h | #ifndef BTTESTER_H
#define BTTESTER_H
#include "bluetooth.h"
#ifndef FLUREC_SIZE
#define FLUREC_SIZE 20
#endif
typedef struct flurec_t {
bool occupied;
bdaddr_t baddr;
uint32_t start;
uint32_t end;
bool dropped;
} flurec_t;
enum {
AM_FLUREC_T = 42,
AM_BASEADDR = 0xff,
};
#endif /* BTTESTER_H */
|
tinyos-io/tinyos-3.x-contrib | diku/common/tools/daq/view-data.c | <filename>diku/common/tools/daq/view-data.c
/**
* Calibration program.
*
* Does the same as DEMO19.C
*
* In order to calibrate the board, perform the following steps:
*
* Step 1: Apply 0V to channel 0
* Step 2: Apply 4.996V to channel 1
* Step 3: Apply 4.996mV to channel 2
* Step 4: Adjust VR101 until CAL:0 = 0x7FF or 0x800.
* Step 5: Adjust VR100 until CAL:1 = 0xFFE or 0xFFF.
* Step 6: Repeat step 4 and 5 until both values are fine.
* Step 7: Adjust VR2 until CAL:2 = 0x000 or 0x001.
* Step 8: Adjust VR1 until CAL:3 = 0xFFE or 0xFFF.
*
*/
#include <stdio.h>
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include "daq_lib.h"
void sigint(int signum)
{
endwin();
exit(0);
}
struct config {
int channel;
daq_gain_t gain;
daq_range_t range;
};
struct config cfg[2] = { { 0, DG_1, DR_BIPOL5V },
{ 16, DG_1000, DR_UNIPOL10V } };
const int cfgs = sizeof(cfg) / sizeof(struct config);
int main(int argc, char *argv[])
{
daq_card_t daq;
int count = 0;
int res;
int i;
struct sigaction act;
if (argc != 2) {
fprintf(stderr, "Too few arguments\n");
return 1;
}
if (daq_open(argv[1], &daq)) {
perror("Error opening daq device");
return 1;
}
/* Setup signal handler */
act.sa_handler = sigint;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGINT, &act, 0);
initscr();
nonl();
cbreak();
noecho();
nodelay(stdscr, true);
move(1,1);
/* Setup the scan */
if (daq_clear_scan(&daq)) {
perror("Error clearing the scan");
return 1;
}
res = 0;
for (i = 0; i < cfgs; ++i)
res += daq_add_scan(&daq, cfg[i].channel, cfg[i].gain, cfg[i].range);
if (res) {
perror("Error configuring scan");
return 1;
}
if (daq_start_scan(&daq, 0xFFFF)) {
perror("Error starting scan");
return 1;
}
double volts, amps;
struct timeval start_time;
int last_count = count;
bool sec_interval = true;
gettimeofday(start_time);
while(1) {
uint16_t sample;
move(11, 5);
printw("Count=%ld\n", count++);
for (i = 0; i < cfgs; ++i) {
res = daq_get_scan_sample(&daq, &sample);
if (!res) {
move(12 + i, 5);
printw("CAL:%d=0x%04x VAL:%d=%02.6f", cfg[i].channel,
sample, cfg[i].channel,
daq_convert_result(&daq, sample, cfg[i].gain, cfg[i].range));
if (i == 0) {
volts += daq_convert_result(&daq, sample, cfg[i].gain, cfg[i].range);
} if (i == 1) {
amps += daq_convert_result(&daq, sample, cfg[i].gain, cfg[i].range);
struct timeval now;
gettimeofday(&now);
if (sec_interval || now.tv_sec != start_time.tv_sec) {
int diff = count - last_count;
printw(" Power Consumption: %02.6f mW ", (volts / diff) * (amps / diff) * 1000.0);
start_time.tv_sec = now.tv_sec;
last_count = count;
volts = 0;
amps = 0;
}
}
} else {
endwin();
printf("Error reading sample (Cfg=%d, Count=%d, res=%d)\n", i, count, res);
perror("exiting");
exit(1);
}
}
move(17, 1);
printw("Press CTRL+C to exit\n");
// usleep(10);
refresh();
int key = getch();
if (key != ERR) {
sec_interval = !sec_interval;
}
// usleep(500);
}
endwin();
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | csm/tos/lib/tossim/sim_serial_packet.c | /*
* "Copyright (c) 2005 Stanford University. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
*
* TOSSIM packet abstract data type, so C++ code can call into nesC
* code that does the native-to-network type translation.
*
* @author <NAME>
* @author <NAME>
* @date July 15 2007
*/
// $Id: sim_serial_packet.c,v 1.2 2007/11/04 00:36:44 hiro Exp $
#include <sim_serial_packet.h>
#include <message.h>
#include <platform_message.h>
// NOTE: This function is defined in lib/tossim/ActiveMessageC. It
// has to be predeclared here because it is defined within that component.
void serial_active_message_deliver(int node, message_t* m, sim_time_t t);
static serial_header_t* getSerialHeader(message_t* msg) {
return (serial_header_t*)(msg->data - sizeof(serial_header_t));
}
void sim_serial_packet_set_destination(sim_serial_packet_t* msg, uint16_t dest)__attribute__ ((C, spontaneous)) {
serial_header_t* hdr = getSerialHeader((message_t*)msg);
hdr->dest = dest;
}__attribute__ ((C, spontaneous))
uint16_t sim_serial_packet_destination(sim_serial_packet_t* msg)__attribute__ ((C, spontaneous)) {
serial_header_t* hdr = getSerialHeader((message_t*)msg);
return hdr->dest;
}
void sim_serial_packet_set_source(sim_serial_packet_t* msg, uint16_t src)__attribute__ ((C, spontaneous)) {
serial_header_t* hdr = getSerialHeader((message_t*)msg);
hdr->src = src;
}__attribute__ ((C, spontaneous))
uint16_t sim_serial_packet_source(sim_serial_packet_t* msg)__attribute__ ((C, spontaneous)) {
serial_header_t* hdr = getSerialHeader((message_t*)msg);
return hdr->src;
}
void sim_serial_packet_set_length(sim_serial_packet_t* msg, uint8_t length)__attribute__ ((C, spontaneous)) {
serial_header_t* hdr = getSerialHeader((message_t*)msg);
hdr->length = length;
}
uint16_t sim_serial_packet_length(sim_serial_packet_t* msg)__attribute__ ((C, spontaneous)) {
serial_header_t* hdr = getSerialHeader((message_t*)msg);
return hdr->length;
}
void sim_serial_packet_set_type(sim_serial_packet_t* msg, uint8_t type) __attribute__ ((C, spontaneous)){
serial_header_t* hdr = getSerialHeader((message_t*)msg);
hdr->type = type;
}
uint8_t sim_serial_packet_type(sim_serial_packet_t* msg) __attribute__ ((C, spontaneous)){
serial_header_t* hdr = getSerialHeader((message_t*)msg);
return hdr->type;
}
uint8_t* sim_serial_packet_data(sim_serial_packet_t* p) __attribute__ ((C, spontaneous)){
message_t* msg = (message_t*)p;
return (uint8_t*)&msg->data;
}
void sim_serial_packet_deliver(int node, sim_serial_packet_t* msg, sim_time_t t) __attribute__ ((C, spontaneous)){
if (t < sim_time()) {
t = sim_time();
}
dbg("Packet", "sim_serial_packet.c: Delivering packet %p to %i at %llu\n", msg, node, t);
serial_active_message_deliver(node, (message_t*)msg, t);
}
uint8_t sim_serial_packet_max_length(sim_serial_packet_t* msg) __attribute__ ((C, spontaneous)){
return TOSH_DATA_LENGTH;
}
sim_serial_packet_t* sim_serial_packet_allocate () __attribute__ ((C, spontaneous)){
return (sim_serial_packet_t*)malloc(sizeof(message_t));
}
void sim_serial_packet_free(sim_serial_packet_t* p) __attribute__ ((C, spontaneous)) {
printf("sim_serial_packet.c: Freeing packet %p\n", p);
free(p);
}
|
tinyos-io/tinyos-3.x-contrib | berkeley/quanto/tos/lib/compression/BitBuffer.h | <gh_stars>1-10
#ifndef _BIT_BUFFER_H
#define _BIT_BUFFER_H
#define INVALID_BIT 255
typedef struct {
uint16_t size_in_bits;
uint16_t pos; //position in bits where to write next bit
uint16_t rpos; //position in bits where to read next bit
uint8_t buf[];
} bitBuf;
/* Functions to manipulate the bitBuf.
You should really be using the BitBuffer interface to play
with your bitBuffer. These functions are here because
EliasGamma needs them, and it gets the pointer to the
buffer. */
inline uint16_t bitBuf_getFreeBits(bitBuf* buf) {
return buf->size_in_bits - buf->pos;
}
inline error_t bitBuf_putBit(bitBuf* buf, uint8_t bit) {
uint16_t B;
uint8_t b, mask;
if (buf->pos == (buf->size_in_bits))
return FALSE;
if (bit) {
B = buf->pos >> 3;
b = buf->pos - (B << 3);
mask = 1 << b;
buf->buf[B] |= mask;
}
buf->pos++;
return TRUE;
}
inline uint8_t bitBuf_getNextBit(bitBuf *buf)
{
uint16_t B;
uint8_t b, mask;
if (buf->rpos == buf->pos)
return INVALID_BIT;
B = buf->rpos >> 3;
b = buf->rpos - (B << 3);
mask = 1 << b;
buf->rpos++;
return (buf->buf[B] & mask)?1:0;
}
#endif
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/mcs51/mcs51hardware.h | /*
* Copyright (c) 2007 University of Copenhagen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of University of Copenhagen nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
* OF COPENHAGEN OR ITS 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.
*/
/**
*
* Ported to 8051 by <NAME>, <NAME> & <NAME>,
* Dept of Computer Science, University of Copenhagen
*
* @author <NAME> <<EMAIL>>
* @author <NAME>,
* @authro <NAME>
*/
#ifndef _H_mcs51hardware_H
#define _H_mcs51hardware_H
#include <io8051.h>
// At some point someone is probably going to use these from avrlibc =]
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
// Borrow these from atm128hardware
// Using these for IO seems rather silly as IO ports are bit accessible as
// Px_y (where x is the port and y is the pin)
#define SET_BIT(port, bit) ((port) |= _BV(bit))
#define CLR_BIT(port, bit) ((port) &= ~_BV(bit))
#define READ_BIT(port, bit) (((port) & _BV(bit)) != 0)
#define FLIP_BIT(port, bit) ((port) ^= _BV(bit))
// Define the input/output direction of the Px_DIR registers
// this is the classic 8051 implementation, some variants
// have other definitions
#define MAKE_IO_PIN_OUTPUT(dir_reg, pin) dir_reg |= _BV(pin)
#define MAKE_IO_PIN_INPUT(dir_reg, pin) dir_reg &= ~_BV(pin)
// Test whether an IO pin is set to input or output
#define IS_IO_PIN_OUTPUT(dir_reg, pin) dir_reg | _BV(pin)
#define IS_IO_PIN_INPUT(dir_reg, pin) !(dir_reg & _BV(pin))
/*
* We need slightly different defs than SIGNAL, INTERRUPT
* See gcc manual for explenation of gcc-attributes
* See nesC Language Reference Manual for nesc attributes
*
* signal: Interrupts are disabled inside function.
* interrupt: Sets up interrupt vector, but doesn't disable interrupts
* spontaneous: nesc attribute to indicate that there are "inisible" calls to this
* function i.e. interrupts
* It seems that 8051 compilers only define the interrupt keyword (not
* signal). It is unclear wether interrupts are disabled or enabled by
* default.
* We use AVR-like syntax so the mangle script looks for something like:
* void __vector_9() __attribute((interrupt))) {
*
* Which is mangled to
* void __vector interrupt 9 () {
*
* NOTE: This means that the interrupt number is passed as part of the
* name - so don't change it! This name is further passed to the
* CIL-inliner script in order for it to leave it there.
*/
// Interrupt: interrupts are enabled (probably =)
#define MCS51_INTERRUPT(signame) \
void signame() __attribute((interrupt, spontaneous, C))
// atomic statement runtime support
typedef uint8_t __nesc_atomic_t;
inline void __nesc_disable_interrupt() { EA=0; }
inline void __nesc_enable_interrupt() { EA=1; }
inline __nesc_atomic_t __nesc_atomic_start(void) __attribute((spontaneous)) {
__nesc_atomic_t tmp = EA;
EA = 0;
return tmp;
}
inline void __nesc_atomic_end(__nesc_atomic_t oldSreg) __attribute__((spontaneous)) {
EA = oldSreg;
}
#endif //_H_mcs51hardware_H
|
tinyos-io/tinyos-3.x-contrib | usc/senzip/SenZip_v1.0/senzip/Senzip.h | /*
* @ author <NAME>
* @ affiliation Autonomous Networks Research Group
* @ institution University of Southern California
*/
#ifndef SENZIP_H
#define SENZIP_H
#include <message.h>
#define AGG_BEACON_INTERVAL 50
#define COMP_PACKET_COUNT 20
#define MAX_NUM_CHILDREN 10
enum {
AM_SENZIP_AGG_HEADER = 40,
AM_SENZIP_START_MSG = 45,
AM_TRIALLOG = 20,
};
enum {
AGG_TABLE_SIZE = 10,
AGG_BEACON_COUNT = 10,
};
typedef struct {
message_t msg;
uint16_t dest;
} agg_queue_entry_t;
typedef nx_struct senzip_agg_header {
nx_uint8_t type;
nx_uint16_t src;
nx_uint8_t relPos;
nx_uint8_t hops;
nx_uint16_t forNode;
nx_uint8_t weight;
//nx_uint16_t childIds[MAX_NUM_CHILDREN];
//nx_uint8_t numGrandchildren[MAX_NUM_CHILDREN];
} agg_header_t;
// start
enum {
FLOOD_START = 1,
QUERY_PARENT_START = 2,
REPLY_PARENT_START = 3,
};
typedef nx_struct senzip_start_msg {
nx_uint8_t type;
nx_uint8_t epochNumber;
} senzip_start_msg_t;
typedef nx_struct TrialLog{
nx_uint16_t sender;
nx_uint16_t receiver;
nx_uint8_t type;
nx_uint8_t counter;
} TrialLog;
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/quanto/tos/lib/quanto/QuantoLog/my_message.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef MY_MESSAGE_H
#define MY_MESSAGE_H
#define MY_MESSAGE_LENGTH 121
//#include "serial.h"
typedef uint8_t my_message_t[MY_MESSAGE_LENGTH];
#endif
|
tinyos-io/tinyos-3.x-contrib | stanford-sing/s4-tinyos-2.x/tos/lib/linkestimator/LinkEstimator.h | // ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: LinkEstimator.h,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: <NAME>
* Date Last Modified: 2005/05/26
*/
#ifndef LINK_ESTIMATOR_H
#define LINK_ESTIMATOR_H
enum {
AM_LE_REVERSE_LINK_ESTIMATION_MSG = 59, //0x3B
};
/*Timers*/
enum {
I_UPDATE_LINK_INTERVAL = 30000u, //Link estimator
I_REVERSE_LINK_PERIOD = 17500u, //Reverse link information
I_REVERSE_LINK_JITTER = 17500u,
};
enum {
#ifdef LE_CACHE_SIZE
N_CACHE_SIZE = LE_CACHE_SIZE,
#else
N_CACHE_SIZE = 18,
#endif
MAX_QUALITY = 255,
AGE_THRESHOLD = 5, //This is when to remove a neighbor*
LINK_ESTIMATOR_FILTER_BY_STRENGTH = 0,
#ifdef PLATFORM_PC
SIGNAL_STRENGTH_FILTER_THRESHOLD = 60,
#else
SIGNAL_STRENGTH_FILTER_THRESHOLD = 350,
#endif
//Rodrigo: changed from 30 to 100, changed hist,new,sum
EWMA_HIST = 3, //These are not in effect. Look in LinkEstimatorM for details
EWMA_NEW = 1,
EWMA_SUM = 4,
LINK_ESTIMATOR_MIN_PACKETS = 3, //This is the minimum number of packets expected from a neighbor
//in a I_UPDATE_LINK_INTERVAL
//=I_UPDATE_LINK_INTERVAL/(I_BEACON_INTERVAL+I_BEACON_JITTER/2)
LINK_ESTIMATOR_PROBATION = 4, //4 for more stability,
//Number of iterations so that the link estimation converges to within
//10% of a constant value. For a given
//alpha (the weight of history in the ewma),
//find n > log(0.1)/log(alpha). This grows
//pretty fast as alpha gets close to 1.
//Some approximate values:
// (alpha->c): 0.5->3, 0.6->4, 0.75->7
LINK_ESTIMATOR_REPLACE_THRESH = 50, //Don't replace a node if the quality is >= this (20% of 255)
LINK_ESTIMATOR_RECEIVE_WINDOW = 3,
LINK_ESTIMATOR_MAX_PACKETS = 254, //Maximum valid number stored by each received and sent slots
LINK_ESTIMATOR_INVALID_PACKETS = 255, //Invalid setting for sent and received slots
//added by <NAME> on Mar 08
//LINK_QUALITY_THRESHOLD = 64,
LINK_QUALITY_THRESHOLD = 80,//50% threshold
};
// * Age is used to remove a neighbor. It is the number of consecutive
// link update timers that windows the
// node has not sent any messages
//Masks for the bits in neighbor state
enum {
ACTIVE_MASK = 1,
VALID_ADDR_MASK = 2,
VALID_QUALITY_MASK = 4,
VALID_SEQNO_MASK = 8,
VALID_STRENGTH_MASK = 16,
VALID_REVERSE_MASK = 32,
REMOVE_MASK = 64
};
//This table is the 1-hop neighbor cache, and holds link information basically
typedef nx_struct LinkNeighbor {
nx_uint8_t state;
nx_uint16_t addr;
nx_uint8_t reverse_quality; //The link quality TO this neighbor
nx_uint8_t reverse_expiration;
nx_uint8_t quality; //Our assessment of the incoming link from n
nx_uint16_t strength;
nx_uint16_t last_seqno; //The last sequence number we got from this neighbor
nx_uint8_t missed[LINK_ESTIMATOR_RECEIVE_WINDOW];
nx_uint8_t received[LINK_ESTIMATOR_RECEIVE_WINDOW];
nx_uint8_t age; //Number of windows with no packets
nx_uint8_t chances; //Number of remaining periods in which this neighbor is in probation
} LinkNeighbor, *LinkNeighbor_ptr;
/* Link Estimator Header */
typedef nx_struct {
nx_uint16_t last_hop;//where this active message came from
nx_uint16_t seqno; //seqno is a routing layer *per node* sequence, used
//to estimate link quality. If messages are to be used
//as link estimators, don't use for other purposes, such
//as application level sequence numbers.
} LEHeader;
#endif
|
tinyos-io/tinyos-3.x-contrib | tinybt/tos/lib/bluetooth/additional_hci.h | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
/*
* additional HCI
*/
#ifndef __ADDITIONAL_HCI_H
#define __ADDITIONAL_HCI_H
/* ----- HCI Commands ----- */
/* Additional OGF & OCF values */
//Inquiry result format with RSSI 7.3.54
#define OCF_WRITE_INQUIRY_MODE 0x0045
#define STD_INQ_RESULT 0x00
#define RSSI_INQ_RESULT 0x01
#define OCF_WRITE_INQUIRY_SCAN_TYPE 0x0043
#define OCF_WRITE_DEFAULT_LINK_POLICY 0x000F
typedef struct {
uint16_t policy;
} __attribute__ ((packed)) write_default_link_policy_cp;
#define WRITE_DEFAULT_LINK_POLICY_CP_SIZE 2
#define OCF_PERIODIC_INQ_MODE 0x0003
typedef struct {
uint16_t max_period_len;
uint16_t min_period_len;
uint8_t lap[3];
uint8_t inq_len;
uint8_t num_responses;
} __attribute__ ((packed)) periodic_inq_mode_cp;
#define PERIODIC_INQ_MODE_CP_SIZE 9
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/tinyos2/StatusMsg.h |
enum
{
AM_STATUS_MSG = 10,
AM_SLEEP_MSG = 11,
AM_PATHDONE_MSG = 12
};
typedef struct
{
bool sleepy; //indicates that the stargate has started sleep sequence
uint16_t load;
} StatusMsg_t;
typedef struct
{
bool finishload;
} SleepMsg_t;
typedef struct
{
uint16_t pathnum;
uint32_t elapsed_us; //time
} PathDoneMsg_t;
|
tinyos-io/tinyos-3.x-contrib | stanford-lgl/libs/BigMsgCTP/BigMsgCTP.h | <gh_stars>1-10
/*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS 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.
*/
/**
* @author <NAME> (<EMAIL>)
*/
#ifndef _BIGMSG_H_
#define _BIGMSG_H_
#define BIGMSG_HEADER_LENGTH 4
#define BIGMSG_DATA_SHIFT 6
#define BIGMSG_DATA_LENGTH (1<<BIGMSG_DATA_SHIFT)
#if TOSH_DATA_LENGTH < (BIGMSG_HEADER_LENGTH+BIGMSG_DATA_LENGTH)
!!!! error -- please set TOSH_DATA_LENGTH large enough in your app/Makefile
#endif
enum
{
AM_CTP_BIGMSG_FRAME_PART=0x5E
};
typedef nx_struct bigmsg_frame_part{
nx_uint16_t part_id;
nx_uint16_t node_id;
nx_uint8_t buf[BIGMSG_DATA_LENGTH];
} bigmsg_frame_part_t;
typedef nx_struct bigmsg_frame_request{
nx_uint16_t part_id;
nx_uint16_t node_id;
nx_uint16_t send_next_n_parts;
} bigmsg_frame_request_t;
#endif //_BIGMSG_H_
|
tinyos-io/tinyos-3.x-contrib | stanford-sing/sensorboards/PowerNetDriver/ADE7753.h | /*
* Register definitions for the ADE7753 power chip.
* Some ideas borrowed from the Berkeley ACMeter.
*
* @author <NAME> <<EMAIL>>
* @date Oct 2, 2008
*
*/
// Addresses of registers we care about
//active power integrated over time
#define AENERGY 0x02
//active power, reset register to 0 after reading
#define RAENERGY 0x03
// access chip functionality, eg. set temperature bit
#define MODE 0x09
// adjust gain for analog input
#define GAIN 0x0F
// latest temperature conversion
#define TEMP 0x26
// interupt enable register
#define IRQ 0x0A
// waveform register
#define WAVE 0x01
// GAIN value
#define ADE7753_GAIN_VAL 0x21
// MODE register value (default)
#define ADE7753_MODE_VAL 0x000C
enum {
SETREG = 1,
GETREG = 2,
};
enum {
ON = 1,
OFF = 0,
};
typedef struct {
unsigned int ubr: 16; //Clock division factor (>=0x0002)
unsigned int :1;
unsigned int mm: 1; //Master mode (0=slave; 1=master)
unsigned int :1;
unsigned int listen: 1; //Listen enable (0=disabled; 1=enabled, feed tx back to receiver)
unsigned int clen: 1; //Character length (0=7-bit data; 1=8-bit data)
unsigned int: 3;
unsigned int:1;
unsigned int stc: 1; //Slave transmit (0=4-pin SPI && STE enabled; 1=3-pin SPI && STE disabled)
unsigned int:2;
unsigned int ssel: 2; //Clock source (00=external UCLK [slave]; 01=ACLK [master]; 10=SMCLK [master] 11=SMCLK [master]);
unsigned int ckpl: 1; //Clock polarity (0=inactive is low && data at rising edge; 1=inverted)
unsigned int ckph: 1; //Clock phase (0=normal; 1=half-cycle delayed)
unsigned int :0;
} my_msp430_spi_config_t;
typedef struct {
uint16_t ubr;
uint8_t uctl;
uint8_t utctl;
} my_msp430_spi_registers_t;
typedef union {
my_msp430_spi_config_t spiConfig;
my_msp430_spi_registers_t spiRegisters;
} my_msp430_spi_union_config_t;
// Setting bits in the uxTCTL register so SPI works.
// Clock Phase Select must be 0, which is not the default for the MSP430, so set
// it here.
my_msp430_spi_union_config_t my_msp430_spi_default_config = {
{
ubr : 0x0002,
ssel : 0x03,
clen : 1,
listen : 0,
mm : 1,
ckph : 0,
ckpl : 0,
stc : 1
}
};
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/linuxsim/simworld/callshims.c | #include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <values.h>
#include <stdarg.h>
#include <string.h>
#include "simworld.h"
#define __USE_GNU
//#include "/usr/include/dlfcn.h"
#include <dlfcn.h>
void __attribute__ ((constructor)) myinit(void);
int (*old_pthread_create)() = 0;
void (*old_pthread_exit)() = 0;
int (*old_usleep)() = 0;
unsigned int (*old_sleep)() = 0;
typedef void *(*__threadfunc) (void *);
typedef struct thread_struct
{
__threadfunc func;
void *arg;
} thread_struct_t;
#define MAX_TDS 20
#define ENERGY_TIME 5
#define IDLE_POWER 1000 //uW
#define GPS_POWER 300000 //uW
#define FLASH_POWER 100000 //uW
#define RADIO_LST_POWER 1000 //uW
#define RADIO_RX_POWER 18000 //uW
#define RADIO_TX_POWER 270000 //uW
#define GPS_MIN_TIME 30 //seconds
#define GPS_MAX_TIME 200 //seconds
#define RADIO_RX_TIME 3000 //us
#define RADIO_TX_TIME 3000 //us
/********DEFINED ACTIONS*************************/
#define ACTION_SENSOR 11
#define ACTION_RADIORX 12
#define ACTION_RADIOTX 13
#define ACTION_RADIOLSTN 14
#define ACTION_ENERGYIN 15
#define ACTION_ENERGYOUT 16
#define ACTION_ENERGYBATT 17
#define ACTION_SETCALLBACK 18
#define ACTION_USER 10
/********END DEFINED ACTIONS*********************/
typedef struct td_entry
{
int valid;
pthread_t id;
int asleep;
unsigned int waketime;
pthread_cond_t cond;
} td_entry;
pthread_mutex_t __td_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t __log_mutex = PTHREAD_MUTEX_INITIALIZER;
td_entry __tds[MAX_TDS];
unsigned int __current_time; //in hundredths of a second
unsigned int __scale_factor;
__energyfunc the_energyfunc = NULL;
pthread_t energy_tid;
//MESSAGING VARS
int __inbox_full=0;
int __inbox_value;
//LOG FILE
FILE* __log_file = NULL;
char __log_file_name[512];
int __uselog = 0;
int __log_sys_evts = 0;
int __log_level;
/**********************************
Energy accounting variables
***********************************/
unsigned int __battery_uJ;
unsigned int __capacity_uJ;
int __outuW;
int __inuW;
int __outuJ;
int __inuJ;
pthread_t maint_tid;
int lastgpstime = GPS_MIN_TIME;
/*************************************
API
Here are the functions the user can call
*************************************/
void log_output(int action, const char *template, ...)
{
va_list ap;
if (__log_sys_evts == 0 && action > __log_level)
{
//don't log system events
return;
}
pthread_mutex_lock(&__log_mutex);
va_start(ap,template);
if (__uselog)
{
__log_file = fopen(__log_file_name, "a");
fprintf(__log_file,"@@:%d:%u:",action, __current_time);
vfprintf(__log_file, template, ap);
fprintf(__log_file, "\n");
fclose(__log_file);
} else {
printf("@@:%d:%u:",action, __current_time);
vprintf(template, ap);
printf("\n");
}
va_end(ap);
pthread_mutex_unlock(&__log_mutex);
return;
}
int set_energy_callback(__energyfunc func)
{
log_output(ACTION_SETCALLBACK,"%d", (int)func);
the_energyfunc = func;
return 0;
}
int get_sensor_reading()
{
static int __reading = 0;
int sleeptime;
if (__battery_uJ <= 0) return -1;
pthread_mutex_lock(&__td_mutex);
__outuW += GPS_POWER;
pthread_mutex_unlock(&__td_mutex);
__reading++;
sleeptime = ((rand() >> 4) % (GPS_MAX_TIME - GPS_MIN_TIME)) + GPS_MIN_TIME;
sleep(sleeptime);
log_output(ACTION_SENSOR,"%d",__reading);
pthread_mutex_lock(&__td_mutex);
__outuW -= GPS_POWER;
pthread_mutex_unlock(&__td_mutex);
return __reading;
}
int recv_network_int(unsigned int to_seconds, int *timedout)
{
unsigned int time_so_far = to_seconds;
int rxval = -1;
int rxed = 0;
int limit = 0;
if (__battery_uJ <= 0)
{
if (timedout != NULL)
{
*timedout = 1;
}
return -1;
}
if (to_seconds > 0)
{
limit = to_seconds;
}
pthread_mutex_lock(&__td_mutex);
__outuW += RADIO_LST_POWER;
pthread_mutex_unlock(&__td_mutex);
log_output(ACTION_RADIOLSTN,"%d:%u",to_seconds,(int)timedout);
while (!limit || time_so_far > 0)
{
if (__inbox_full && __battery_uJ > 0)
{
rxval = __inbox_value;
rxed = 1;
pthread_mutex_lock(&__td_mutex);
__outuW += RADIO_RX_POWER;
pthread_mutex_unlock(&__td_mutex);
usleep(RADIO_RX_TIME);
log_output(ACTION_RADIORX,"%d",rxval);
pthread_mutex_lock(&__td_mutex);
__outuW -= RADIO_RX_POWER;
pthread_mutex_unlock(&__td_mutex);
break;
}
sleep(3);
if (limit)
{
time_so_far -= 3;
}
}
pthread_mutex_lock(&__td_mutex);
__outuW -= RADIO_RX_POWER;
__outuW -= RADIO_LST_POWER;
pthread_mutex_unlock(&__td_mutex);
if (!rxed && timedout != NULL)
{
*timedout = 1;
}
if (rxed && timedout != NULL)
{
*timedout = 0;
}
return rxval;
}
void send_network_int(int value)
{
if (__battery_uJ <= 0) return;
pthread_mutex_lock(&__td_mutex);
__outuW += RADIO_RX_POWER;
pthread_mutex_unlock(&__td_mutex);
usleep(RADIO_TX_TIME);
log_output(ACTION_RADIOTX, "%d",value);
pthread_mutex_lock(&__td_mutex);
__outuW -= RADIO_RX_POWER;
pthread_mutex_unlock(&__td_mutex);
}
/****************************************
End API Calls
******************************************/
unsigned int consume_energy(unsigned int __uJ)
{
printf("consume_energy(%u) -> (%u, %u)\n", __uJ, __outuJ, __battery_uJ);
__outuJ += __uJ;
if (__uJ <= __battery_uJ)
{
__battery_uJ -= __uJ;
} else {
__battery_uJ = 0;
}
return __battery_uJ;
}
unsigned int harvest_energy(unsigned int __uJ)
{
__inuJ += __uJ;
__battery_uJ += __uJ;
if (__battery_uJ > __capacity_uJ)
{
__battery_uJ = __capacity_uJ;
}
return __battery_uJ;
}
int getnextentry(pthread_t tid)
{
int i;
int theindex = -1;
pthread_mutex_lock(&__td_mutex);
for (i=0; i < MAX_TDS; i++)
{
if (__tds[i].valid == 0 && theindex == -1)
{
__tds[i].valid = 1;
__tds[i].id = tid;
__tds[i].asleep = 0;
__tds[i].waketime = 0;
pthread_cond_init(&__tds[i].cond, NULL);
theindex = i;
break;
}
}
pthread_mutex_unlock(&__td_mutex);
return theindex;
}
void removeentry(pthread_t tid)
{
int i;
pthread_mutex_lock(&__td_mutex);
for (i=0; i < MAX_TDS; i++)
{
if (__tds[i].valid == 1 && pthread_equal(__tds[i].id, tid) != 0)
{
__tds[i].valid = 0;
pthread_cond_destroy(&__tds[i].cond);
}
}
pthread_mutex_unlock(&__td_mutex);
}
int lookupentry(pthread_t tid)
{
int theindex = -1;
int i;
for (i=0; i < MAX_TDS; i++)
{
if (__tds[i].valid == 1 && pthread_equal(__tds[i].id, tid) != 0)
{
theindex = i;
break;
}
}
return theindex;
}
void clearentries()
{
int i;
pthread_mutex_lock(&__td_mutex);
for (i=0; i < MAX_TDS; i++)
{
__tds[i].valid = 0;
}
pthread_mutex_unlock(&__td_mutex);
}
int sleepy()
{
int imsleepy = 1;
int i;
pthread_mutex_lock(&__td_mutex);
for (i=0; i < MAX_TDS; i++)
{
if (__tds[i].valid == 1 && __tds[i].asleep == 0)
{
imsleepy = 0;
}
}
pthread_mutex_unlock(&__td_mutex);
return imsleepy;
}
unsigned int getnexttime()
{
int i;
unsigned int ntime = UINT_MAX;
pthread_mutex_lock(&__td_mutex);
printf("getnexttime\n");
for (i=0; i < MAX_TDS; i++)
{
if (__tds[i].valid == 1 && __tds[i].waketime < ntime && __tds[i].waketime >= __current_time)
{
ntime = __tds[i].waketime;
}
}
pthread_mutex_unlock(&__td_mutex);
return ntime;
}
int realsleep(unsigned int waketime)
{
unsigned int delta;
unsigned int realdelta;
int i;
delta = waketime - __current_time;
//actual time to sleep
realdelta = (delta * 100)/__scale_factor;
printf("realdelta = %u\n",realdelta);
pthread_mutex_lock(&__td_mutex);
for (i=0; i < MAX_TDS; i++)
{
if (__tds[i].valid == 1 && __tds[i].waketime == waketime)
{
__tds[i].asleep = 0;
pthread_cond_signal(&__tds[i].cond);
}
}
consume_energy((__outuW * delta) / 100);
if (realdelta < 1000)
{
//from hs to us
old_usleep(realdelta * 10000);
} else {
old_sleep(realdelta / 100);
}
if (waketime == UINT_MAX)
{
__current_time =0;
} else {
__current_time = waketime;
}
pthread_mutex_unlock(&__td_mutex);
return realdelta;
}
void *__m_thread_routine (void *arg)
{
unsigned int nexttime;
unsigned int delta;
while (1)
{
//check to see if all threads are asleep
if (sleepy())
{
printf("sleepy-pre(%u)\n",nexttime);
nexttime = getnexttime();
printf("sleepy-post(%u)\n",nexttime);
delta = realsleep(nexttime);
}
old_usleep(10);
}
return NULL;
}
void *__energy_thread_routine (void *arg)
{
printf("energy thread!\n");
while (1)
{
printf("energy thread! sleeping!\n");
sleep(ENERGY_TIME);
//printf("__outuJ = %u (%u)\n", __outuJ, __battery_uJ);
log_output(ACTION_ENERGYIN,"%d",__inuJ);
log_output(ACTION_ENERGYOUT,"%d",__outuJ);
log_output(ACTION_ENERGYBATT,"%u",__battery_uJ);
if (the_energyfunc != NULL)
{
printf("calling func\n");
//add noise
int innoise;
int outnoise;
unsigned int battnoise;
innoise = ((rand() >> 4) % 600) - 300; //+/- 60uW accuracy
outnoise = ((rand() >> 4) % 600) - 300;
battnoise = (rand() >> 4) & 0x0000000f;
the_energyfunc(__inuJ+innoise, __outuJ+outnoise, (__battery_uJ & 0xFFFFFFF0) | battnoise);
}
__inuJ = 0;
__outuJ = 0;
}
return NULL;
}
void myinit(void)
{
pthread_t self = pthread_self();
int entry;
clearentries();
entry = getnextentry(self);
__current_time= 0;
__outuW = IDLE_POWER;
//READ IN ENVIRONMENT VARIABLES
char *str_factor = getenv("SIM_TIME_FACTOR");
if (str_factor == NULL)
{
__scale_factor = 100;
} else {
__scale_factor = atoi(str_factor);
}
char *str_bsize = getenv("BATTERY_SIZE");
if (str_bsize == NULL)
{
__capacity_uJ = 10000000L;
} else {
__capacity_uJ= atoi(str_bsize);
}
__battery_uJ = __capacity_uJ / 2;
char *str_fname = getenv("SIM_LOG_FILE");
if (str_fname == NULL)
{
__log_file = NULL;
printf("Logging to stdout\n");
} else {
strncpy(__log_file_name, str_fname, 500);
__log_file = fopen(str_fname,"w");
if (__log_file != NULL)
{
__uselog = 1;
}
fclose(__log_file);
printf("Logging to file:%s(%d)\n",__log_file_name, __uselog);
}
char *str_ll = getenv("SIM_LOG_LEVEL");
if (str_ll == NULL)
{
__log_level = ACTION_USER;
} else {
__log_level = atoi(str_ll);
}
printf("Log Level=%d\n", __log_level);
//END OF READING ENVINRONMENT VARIABLES
old_pthread_create = (int (*)()) dlsym(RTLD_NEXT, "pthread_create");
if (old_pthread_create == NULL)
{
fprintf(stderr, "dlsym: %s\n", dlerror());
} else {
int ret;
ret = old_pthread_create(&maint_tid, NULL, __m_thread_routine, NULL);
}
old_pthread_exit = (void (*)()) dlsym(RTLD_NEXT, "pthread_exit");
if (old_pthread_exit == NULL)
{
fprintf(stderr, "dlsym: %s\n", dlerror());
}
old_sleep = (unsigned int (*)()) dlsym(RTLD_NEXT, "sleep");
if (old_sleep == NULL)
{
fprintf(stderr, "dlsym: %s\n", dlerror());
}
old_usleep = (int (*)()) dlsym(RTLD_NEXT, "usleep");
if (old_usleep == NULL)
{
fprintf(stderr, "dlsym: %s\n", dlerror());
}
pthread_create(&energy_tid, NULL, __energy_thread_routine, NULL);
printf("libsimworld init! (entry=%d, scale=%u)\n", entry, __scale_factor);
}
void *__thread_routine (void *arg)
{
void *ret;
thread_struct_t *tst = (thread_struct_t*)arg;
if (getnextentry(pthread_self()) == -1)
{
//could not find a free slot
printf("TOO MANY THREADS! Killing this one.\n");
pthread_exit(NULL);
}
ret = tst->func(tst->arg);
pthread_exit(ret);
}
int pthread_create (pthread_t *__restrict __threadp,
__const pthread_attr_t *__restrict __attr,
void *(*__start_routine) (void *),
void *__restrict __arg)
{
int ret;
thread_struct_t *tst = malloc(sizeof(thread_struct_t));
//printf ("shim: called pthread_create()\n");
tst->func = __start_routine;
tst->arg = __arg;
ret = old_pthread_create(__threadp, __attr, __thread_routine, (void*)tst);
return ret;
}
void __attribute__((noreturn)) pthread_exit(void *value_ptr)
{
//clean up monitoring data here
//printf ("shim: called pthread_exit()\n");
removeentry(pthread_self());
old_pthread_exit(value_ptr);
//never reached, but necessary to convince GCC that it won't return;
exit(1);
}
unsigned int sleep (unsigned int __seconds)
{
unsigned int realdelta;
int idx;
printf ("shim: called sleep(%u)\n", __seconds);
pthread_mutex_lock(&__td_mutex);
realdelta = __seconds * 100;
idx = lookupentry(pthread_self());
if (idx == -1)
{
printf("AAAH. I have no record of this thread...BUG!\n");
exit(1);
}
__tds[idx].waketime = __current_time + realdelta;
__tds[idx].asleep = 1;
printf ("pre-wait\n");
pthread_cond_wait(&__tds[idx].cond, &__td_mutex);
printf ("post-wait\n");
//printf ("shim: sleep returned(%u, %u)\n", __tds[idx].waketime, __current_time);
pthread_mutex_unlock(&__td_mutex);
return __seconds;
}
int usleep (__useconds_t __useconds)
{
unsigned int realdelta;
int idx;
//printf ("shim: called usleep()\n");
pthread_mutex_lock(&__td_mutex);
realdelta = __useconds / 10000;
idx = lookupentry(pthread_self());
if (idx == -1)
{
printf("AAAH. I have no record of this thread...BUG!\n");
exit(1);
}
__tds[idx].waketime = __current_time + realdelta;
__tds[idx].asleep = 1;
pthread_cond_wait(&__tds[idx].cond, &__td_mutex);
pthread_mutex_unlock(&__td_mutex);
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/stargate/rt_handler.c |
#include "rt_handler.h"
#include "sfaccess/telossource.h"
#define PATHDONEMSGSIZE 3
extern int curstate;
extern float curgrade;
enum
{
AM_PATHDONE_MSG = 0xd2
};
int sendPathDonePacket(rt_data _pdata);
bool isFunctionalState(int8_t state)
{
return (curstate >= state);
}
void reportError(uint16_t nodeid, uint8_t error, rt_data _pdata)
{
printf("ERROR: %i:%i\n",nodeid, _pdata.weight);
reportExit(_pdata);
}
void reportExit(rt_data _pdata)
{
int result;
printf("Flow done: %i\n",_pdata.weight);
result = sendPathDonePacket(_pdata);
if (result)
{
printf("ERROR sending path done packet\n");
}
}
int sendPathStartPacket(int id)
{
telospacket packet;
uint8_t data[PATHDONEMSGSIZE];
int err, fd;
packet.length = PATHDONEMSGSIZE;
packet.addr = TOS_BCAST_ADDR;
packet.type = AM_PATHDONE_MSG;
packet.data = data;
packet.data[0] = 1;
packet.data[1] = id;
packet.data[2] = 0;
fd = open_telos_source("localhost", 9000);
if (fd <= 0)
{
printf("sendPathDonePacket: o_t_s failed! (fd=%i)\n",fd);
return 1;
}
err = write_telos_packet(fd, &packet);
if (err)
{
printf("AAAH! Could not send status packet.\n");
return -1;
}
close(fd);
return 0;
}
int sendPathDonePacket(rt_data _pdata)
{
telospacket packet;
uint8_t data[PATHDONEMSGSIZE];
int err, fd;
packet.length = PATHDONEMSGSIZE;
packet.addr = TOS_BCAST_ADDR;
packet.type = AM_PATHDONE_MSG;
packet.data = data;
packet.data[0] = 0;
packet.data[1] = _pdata.sessionID;
packet.data[2] = _pdata.weight;
fd = open_telos_source("localhost", 9000);
if (fd <= 0)
{
printf("sendPathDonePacket: o_t_s failed! (fd=%i)\n",fd);
return 1;
}
err = write_telos_packet(fd, &packet);
if (err)
{
printf("AAAH! Could not send status packet.\n");
return -1;
}
close(fd);
return 0;
}
int getNextSession()
{
static int session= 0;
session++;
return session;
}
|
tinyos-io/tinyos-3.x-contrib | sensorscheme/tos/lib/SensorScheme/implementation.h | <filename>sensorscheme/tos/lib/SensorScheme/implementation.h
#define DEF_COMPONENTS(name, pr) components pr as PR_##name;
#define SIMPLE_PRIM_CONFIG(name, pr) App.Primitive[name] -> PR_##name;
#define EVAL_PRIM_CONFIG(name, pr) App.Eval[name] -> PR_##name;
#define APPLY_PRIM_CONFIG(name, pr) App.Apply[name] -> PR_##name;
#define SEND_PRIM_CONFIG(name, pr) App.Sender[name] -> PR_##name;
#define RECEIVER_CONFIG(name, pr) App.Receiver[name] -> PR_##name;
implementation {
components SensorSchemeC as App, MainC;
components new PoolC(message_t, POOL_SIZE);
components LedsC;
components new TimerMilliC();
SIMPLE_PRIM_LIST(DEF_COMPONENTS)
EVAL_PRIM_LIST(DEF_COMPONENTS)
APPLY_PRIM_LIST(DEF_COMPONENTS)
SEND_PRIM_LIST(DEF_COMPONENTS)
RECEIVER_LIST(DEF_COMPONENTS)
App.Boot -> MainC;
App.Pool -> PoolC;
App.Leds -> LedsC;
App.Timer -> TimerMilliC;
SIMPLE_PRIM_LIST(SIMPLE_PRIM_CONFIG)
EVAL_PRIM_LIST(EVAL_PRIM_CONFIG)
APPLY_PRIM_LIST(APPLY_PRIM_CONFIG)
SEND_PRIM_LIST(SEND_PRIM_CONFIG)
RECEIVER_LIST(RECEIVER_CONFIG)
}
|
tinyos-io/tinyos-3.x-contrib | tub/tos/lib/tinycops/TinyCOPS.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Copyright (c) 2007, Technische Universitaet Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Technische Universitaet Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER 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.
*
* - Revision -------------------------------------------------------------
* $Revision: 1.1 $
* $Date: 2008/02/15 13:58:59 $
* @author: <NAME> <<EMAIL>>
* ========================================================================
*/
#ifndef __TINYCOPS_H
#define __TINYCOPS_H
#include "message.h"
#define MAX_SUBSCRIPTION_SIZE (TOSH_DATA_LENGTH-10)
typedef uint8_t attribute_id_t; //typedef nx_uint8_t attribute_id_t;
typedef nx_uint8_t operation_t;
typedef nx_struct constraint
{
nx_uint8_t attributeID;
operation_t operationID;
nx_uint8_t value[0];
} constraint_t;
typedef nx_struct avpair
{
nx_uint8_t attributeID;
nx_int8_t value[0];
} avpair_t;
enum {
PSITEM_ITEM = 0x80,
PSITEM_CONSTRAINT = 0x40,
PSITEM_SIZE_MASK = 0x3F,
};
typedef nx_struct ps_item {
// "control"-field:
//
// 0 1 2 3 4 5 6 7
// +-+-+-+-+-+-+-+-+
// | Size |C|I|
// +-+-+-+-+-+-+-+-+
//
// Size = the size of the complete ps_item (in bytes) if I = 1
// or the available size left in the message if I = 0
// C = constraint-flag: if set the item is a constraint,
// otherwise it's an avpair
// I = item-flag: if set this is a valid ps_item, otherwise
// it's the termination byte that shows how many bytes are
// left in the message
nx_uint8_t control;
nx_union {
avpair_t avpair;
constraint_t constraint;
};
} ps_item_t;
typedef nx_struct subscription
{
nx_uint8_t data[0]; // ps_item_t
} subscription_t;
typedef nx_struct notification
{
nx_uint8_t data[0]; // ps_item_t
} notification_t;
typedef struct { } CSEC_INBOUND;
typedef struct { } CSEC_OUTBOUND;
typedef subscription_t *subscription_handle_t;
typedef notification_t *notification_handle_t;
typedef uint32_t add_up_32_t __attribute__((combine(add32combine)));
uint32_t add32combine(uint32_t s1,uint32_t s2)
{
return (s1 + s2);
}
enum {
AM_NOTIFICATION = 155,
AM_SUBSCRIPTION = 156,
};
#define ATTRIBUTE_COLLECTION_ID "Attribute.Collection.ID"
#define PSCLIENT_ID "PublishSubscribe.PSClient.ID"
#define ATTRIBUTECLIENT_ID "PublishSubscribe.AttributeClient.ID"
#define PSBRIDGE_CLIENT_ID "PublishSubscribe.SubscriberBridge.ID"
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/get_status.c | <filename>nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/get_status.c
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "libusb_driver.h"
NTSTATUS get_status(libusb_device_t *dev, int recipient,
int index, char *status, int *ret, int timeout)
{
NTSTATUS _status = STATUS_SUCCESS;
URB urb;
DEBUG_PRINT_NL();
DEBUG_MESSAGE("get_status(): recipient %02d", recipient);
DEBUG_MESSAGE("get_status(): index %04d", index);
DEBUG_MESSAGE("get_status(): timeout %d", timeout);
memset(&urb, 0, sizeof(URB));
switch(recipient)
{
case USB_RECIP_DEVICE:
urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_DEVICE;
break;
case USB_RECIP_INTERFACE:
urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_INTERFACE;
break;
case USB_RECIP_ENDPOINT:
urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_ENDPOINT;
break;
case USB_RECIP_OTHER:
urb.UrbHeader.Function = URB_FUNCTION_GET_STATUS_FROM_OTHER;
break;
default:
DEBUG_ERROR("get_status(): invalid recipient");
return STATUS_INVALID_PARAMETER;
}
urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST);
urb.UrbControlGetStatusRequest.TransferBufferLength = 2;
urb.UrbControlGetStatusRequest.TransferBuffer = status;
urb.UrbControlGetStatusRequest.Index = (USHORT)index;
_status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
if(!NT_SUCCESS(_status) || !USBD_SUCCESS(urb.UrbHeader.Status))
{
DEBUG_ERROR("get_status(): getting status failed: "
"status: 0x%x, urb-status: 0x%x",
_status, urb.UrbHeader.Status);
*ret = 0;
}
else
{
*ret = urb.UrbControlGetStatusRequest.TransferBufferLength;
}
return _status;
}
|
tinyos-io/tinyos-3.x-contrib | intelmote2/support/sdk/c/camera_cmd/bigmsg_frame_part.h | /**
* This file is automatically generated by mig. DO NOT EDIT THIS FILE.
* This file defines the layout of the 'bigmsg_frame_part' message type.
*/
#ifndef BIGMSG_FRAME_PART_H
#define BIGMSG_FRAME_PART_H
#include <message.h>
enum {
/** The default size of this message type in bytes. */
BIGMSG_FRAME_PART_SIZE = 68,
/** The Active Message type associated with this message. */
BIGMSG_FRAME_PART_AM_TYPE = 110,
/* Field part_id: type uint16_t, offset (bits) 0, size (bits) 16 */
/** Offset (in bytes) of the field 'part_id' */
BIGMSG_FRAME_PART_PART_ID_OFFSET = 0,
/** Offset (in bits) of the field 'part_id' */
BIGMSG_FRAME_PART_PART_ID_OFFSETBITS = 0,
/** Size (in bytes) of the field 'part_id' */
BIGMSG_FRAME_PART_PART_ID_SIZE = 2,
/** Size (in bits) of the field 'part_id' */
BIGMSG_FRAME_PART_PART_ID_SIZEBITS = 16,
/* Field node_id: type uint16_t, offset (bits) 16, size (bits) 16 */
/** Offset (in bytes) of the field 'node_id' */
BIGMSG_FRAME_PART_NODE_ID_OFFSET = 2,
/** Offset (in bits) of the field 'node_id' */
BIGMSG_FRAME_PART_NODE_ID_OFFSETBITS = 16,
/** Size (in bytes) of the field 'node_id' */
BIGMSG_FRAME_PART_NODE_ID_SIZE = 2,
/** Size (in bits) of the field 'node_id' */
BIGMSG_FRAME_PART_NODE_ID_SIZEBITS = 16,
/* Field buf: type uint8_t[], element size (bits) 8 */
/** Elementsize (in bytes) of the field 'buf' */
BIGMSG_FRAME_PART_BUF_ELEMENTSIZE = 1,
/** Elementsize (in bits) of the field 'buf' */
BIGMSG_FRAME_PART_BUF_ELEMENTSIZEBITS = 8,
/** The number of dimensions in the array 'buf'. */
BIGMSG_FRAME_PART_BUF_NUMDIMENSIONS = 1,
/** Number of elements in dimension 1 of array 'buf'. */
BIGMSG_FRAME_PART_BUF_NUMELEMENTS_1 = 64,
/** Total number of elements in the array 'buf'. */
BIGMSG_FRAME_PART_BUF_NUMELEMENTS = 64,
};
/**
* Return the value of the field 'part_id'
*/
uint16_t bigmsg_frame_part_part_id_get(tmsg_t *msg);
/**
* Set the value of the field 'part_id'
*/
void bigmsg_frame_part_part_id_set(tmsg_t *msg, uint16_t value);
/**
* Return the value of the field 'node_id'
*/
uint16_t bigmsg_frame_part_node_id_get(tmsg_t *msg);
/**
* Set the value of the field 'node_id'
*/
void bigmsg_frame_part_node_id_set(tmsg_t *msg, uint16_t value);
/**
* Return the byte offset of an element of array 'buf'
*/
size_t bigmsg_frame_part_buf_offset(size_t index1);
/**
* Return an element of the array 'buf'
*/
uint8_t bigmsg_frame_part_buf_get(tmsg_t *msg, size_t index1);
/**
* Set an element of the array 'buf'
*/
void bigmsg_frame_part_buf_set(tmsg_t *msg, size_t index1, uint8_t value);
/**
* Return the bit offset of an element of array 'buf'
*/
size_t bigmsg_frame_part_buf_offsetbits(size_t index1);
#endif
|
tinyos-io/tinyos-3.x-contrib | tinymulle/tos/chips/m16c62p/bits.h | /*
* Copyright (c) 2008, Embedded Internet System technology bothnia AB (EISTEC AB)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of EISTEC AB 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 EISTEC AB ``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 EISTEC AB 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.
*/
#ifndef __BITS_H__
#define __BITS_H__
#define BIT0 0x1
#define BIT1 0x2
#define BIT2 0x4
#define BIT3 0x8
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
#define BIT8 0x100
#define BIT9 0x200
#define BIT10 0x400
#define BIT11 0x800
#define BIT12 0x1000
#define BIT13 0x2000
#define BIT14 0x4000
#define BIT15 0x8000
#define BIT16 0x10000
#define BIT17 0x20000
#define BIT18 0x40000
#define BIT19 0x80000
#define BIT20 0x100000
#define BIT21 0x200000
#define BIT22 0x400000
#define BIT23 0x800000
#define BIT24 0x1000000
#define BIT25 0x2000000
#define BIT26 0x4000000
#define BIT27 0x8000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000
#endif /* __BITS_H__ */
|
tinyos-io/tinyos-3.x-contrib | eon/apps/eserver/impl/stargate/mImpl.h | #ifndef _MIMPL_H_
#define _MIMPL_H_
#include "mNodes.h"
#include "runtime/rt_structs.h"
#include "mStructs.h"
void init (int argc, char **argv);
int Reply (Reply_in * in, Reply_out * out);
int ReadRequest (ReadRequest_in * in, ReadRequest_out * out);
void BadRequest (ReadRequest_in * in, int err);
int Handler (Handler_in * in, Handler_out * out);
int Listen (Listen_out * out);
int Page (Page_in * in, Page_out * out);
int ReadWrite (ReadWrite_in * in, ReadWrite_out * out);
void FourOhFor (ReadWrite_in * in, int err);
int Unavailable (Unavailable_in * in, Unavailable_out * out);
#endif // _MIMPL_H_
|
tinyos-io/tinyos-3.x-contrib | wsu/telosw/ccxx00/lpl/Wor.h | /*
* Copyright (c) 2005-2006 Rincon Research Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Rincon Research Corporation nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* RINCON RESEARCH OR ITS 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
*/
/**
* Make sure we aren't trying to compile multiple LPL directories into the
* radio stack
*/
#ifndef WOR_H
#define WOR_H
/**
* The crystal used for the radio must be defined for WoR calculations
*/
#ifndef CCXX00_CRYSTAL_KHZ
#define CCXX00_CRYSTAL_KHZ 26000
#endif
/**
* The radio seems to forget it's supposed to be duty cycling sometimes.
* The kick timer reminds the radio periodically to enable WoR.
* If the radio doesn't receive any packets while it's supposed to be in
* WoR mode, how else is the microcontroller supposed to know to fix the
* problem?
*/
#ifndef WOR_KICK_TIMER
#define WOR_KICK_TIMER 15360
#endif
/**
* WORCTRL register bitfields
*/
enum ccxx00_worctrl_register {
CCXX00_WORCTRL_RC_PD = 7,
CCXX00_WORCTRL_EVENT1 = 4,
CCXX00_WORCTRL_RC_CAL = 3,
CCXX00_WORCTRL_WOR_RES = 0,
};
/**
* MCSM2 register bitfields
*/
enum ccxx00_mcsm2_register {
CCXX00_MCSM2_RX_TIME_RSSI = 4,
CCXX00_MCSM2_RX_TIME_QUAL = 3,
CCXX00_MCSM2_RX_TIME = 0,
};
/**
* Mask the fields to 0
*/
enum ccxx00_mcsm2_mask {
CCXX00_MCSM2_RX_TIME_RSSI_MASK = 0xEF,
CCXX00_MCSM2_RX_TIME_QUAL_MASK = 0xF7,
CCXX00_MCSM2_RX_TIME_MASK = 0xF8,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/telos/rt_structs.h | #ifndef RT_STRUCTS_H_INCLUDED
#define RT_STRUCTS_H_INCLUDED
typedef struct rt_data
{
uint16_t sessionID;
uint32_t starttime;
uint16_t weight;
uint8_t minstate;
uint8_t wake;
uint32_t elapsed_us;
} rt_data;
typedef struct GenericNode
{
rt_data _pdata;
} GenericNode;
typedef uint8_t request_t[50];
#endif
|
tinyos-io/tinyos-3.x-contrib | diku/freescale/tos/lib/Debug.h | /* Copyright (c) 2006, <NAME> <<EMAIL>>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the University of Copenhagen nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT OWNER 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.
*/
/*
@author <NAME> <<EMAIL>>
*/
#if DBG_LEVEL && DBG_LEVEL > 0
#ifndef DBG_MIN_LEVEL
#define DBG_MIN_LEVEL 1
#endif
#define DBG_STR(str,lvl) \
if (DBG_LEVEL >= lvl && lvl >= DBG_MIN_LEVEL) {\
call Debug.debugStr(str,lvl);\
}
#define DBG_STR_CLEAN(str,lvl) \
if (DBG_LEVEL >= lvl && lvl >= DBG_MIN_LEVEL) {\
call Debug.debugStrClean(str);\
}
#define DBG_INT(int,lvl) \
if (DBG_LEVEL >= lvl && lvl >= DBG_MIN_LEVEL) {\
call Debug.debugInt(((uint8_t*)&int),sizeof(int),lvl);\
}
#define DBG_INT_CLEAN(int,lvl) \
if (DBG_LEVEL >= lvl && lvl >= DBG_MIN_LEVEL) {\
call Debug.debugIntClean(((uint8_t*)&int),sizeof(int));\
}
#define DBG_STRINT(str,int,lvl) \
if (DBG_LEVEL >= lvl && lvl >= DBG_MIN_LEVEL) {\
call Debug.debugStrInt(str,((uint8_t*)&int),sizeof(int),lvl);\
}
#define DBG_DUMP(dmp,len,lvl) \
if (DBG_LEVEL >= lvl && lvl >= DBG_MIN_LEVEL) {\
call Debug.debugInt(dmp,len,lvl);\
}
#else
#define DBG_STR(str,lvl)
#define DBG_INT(int,lvl)
#define DBG_STR_CLEAN(str,lvl)
#define DBG_INT_CLEAN(int,lvl)
#define DBG_STRINT(str,int,lvl)
#define DBG_DUMP(dmp,len,lvl)
#endif
#define DBG_STR_TMP(str) call Debug.debugStr(str,0)
#define DBG_INT_TMP(int) call Debug.debugInt(((uint8_t*)&int),sizeof(int),0)
|
tinyos-io/tinyos-3.x-contrib | usc/senzip/SenZip_v1.0/senzip/FixedRouting.h | /*
* @ author <NAME>
* @ affiliation Autonomous Networks Research Group
* @ institution University of Southern California
*/
#ifndef FIXEDROUTING_H
#define FIXEDROUTING_H
enum {
AM_FIXRT_MSG = 29,
};
typedef nx_struct fixrt_msg {
nx_uint8_t type;
nx_uint16_t parent;
nx_uint8_t numHops;
} FixRtMsg;
#endif |
tinyos-io/tinyos-3.x-contrib | blaze/tos/chips/ccxx00_single/radios/cc2500/CC2500.h | /*
* Copyright (c) 2005-2006 Rincon Research Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Rincon Research Corporation nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* RINCON RESEARCH OR ITS 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
*/
/**
* 250 kBaud Manchester (2-FSK)
*/
/**
* All frequency settings assume a 26 MHz crystal.
* If you have a 27 MHz crystal, you'll need to fix the defined FREQ registers
*
* @author <NAME>
* @author <NAME>
* @author <NAME>
*/
#ifndef CC2500_H
#define CC2500_H
#include "Blaze.h"
enum {
CC2500_RADIO_ID = unique( UQ_BLAZE_RADIO ),
};
/**
* This helps calculate new FREQx register settings at runtime.
* The frequency is in MHz.
*/
#define CC2500_CRYSTAL_MHZ 26
/**
* All default channels and FREQx registers obtained from SmartRF studio. We
* are not trying to define channel frequencies to match up with any sort of
* specification; instead, we want flexibility. If you want to align with
* specs, then go for it.
*
* Note you can setup the CC2500 to match your antenna characteristics.
* Maybe your antenna is tuned to +/- 20 MHz around 2442.4 MHz
* You want your center frequency to be 2442.4 MHz, and your lower edge to be
* 2422.4 MHz and your upper edge to be 2462.4 MHz.
*
* Lower Channel Calculation:
* CC2500_CHANNEL_MIN = [(2422400 desired kHz) - (CC2500_LOWEST_FREQ)]
* ---------------------------------------------
* 324 kHz channel spacing
*
* Where CC2500_LOWEST_FREQ is 2400998 kHz and 324 kHz is
* approximately the channel spacing, CC2500_CHANNEL_WIDTH
*
* CC2500_CHANNEL_MIN ~= 66
*
*
* Upper Channel Calculation:
* CC2500_CHANNEL_MAX = [(320000 desired kHz) - (CC2500_LOWEST_FREQ)]
* ---------------------------------------------
* 324 kHz channel spacing
*
* CC2500_CHANNEL_MAX ~= 189
*
* Incidentally, (189+66)/2 ~= 128, which is our default center channel.
*
* When you apply the MAX and MIN values, the radio stack will automatically
* make sure you're within bounds when you set the frequency or channel during
* runtime.
*
* We defined the channel spacing below so all channels from 0 to 255 fit
* within the 2.400 - 2.483 GHz band.
*/
/***************** 2.4 GHz Matching Network ****************/
// Default channel is at 2441.565277 MHz
#ifndef CC2500_DEFAULT_CHANNEL
#define CC2500_DEFAULT_CHANNEL 125
#endif
#ifndef CC2500_CHANNEL_MIN
#define CC2500_CHANNEL_MIN 0
#endif
#ifndef CC2500_CHANNEL_MAX
#define CC2500_CHANNEL_MAX 255
#endif
enum {
CC2500_LOWEST_FREQ = 2400998, // kHz
CC2500_DEFAULT_FREQ2 = 0x5C,
CC2500_DEFAULT_FREQ1 = 0x58,
CC2500_DEFAULT_FREQ0 = 0x9D,
};
/**
* These values calculated using TI smart RF studio
*/
enum{
CC2500_PA_PLUS_1 = 0xFF,
CC2500_PA_MINUS_4 = 0xA9,
CC2500_PA_MINUS_10 = 0x97,
};
#ifndef CC2500_PA
#define CC2500_PA CC2500_PA_PLUS_1
#endif
/**
* These are used for calculating channels at runtime
*/
#define CC2500_CHANNEL_WIDTH 324 // kHz : Do not edit
enum cc2500_config_reg_state_enums {
/** GDO2 is CHIP_RDY, even when the chip is first powered */
CC2500_CONFIG_IOCFG2 = 0x29,
/** GDO1 is High Impedance */
CC2500_CONFIG_IOCFG1 = 0x2E,
/** GDO0 asserts when there is data in the RX FIFO */
CC2500_CONFIG_IOCFG0 = 0x01,
CC2500_CONFIG_FIFOTHR = 0xE,
CC2500_CONFIG_SYNC1 = 0xD3,
CC2500_CONFIG_SYNC0 = 0x91,
/** Maximum variable packet length is 61 per Errata */
CC2500_CONFIG_PKTLEN = 0x3D,
/** No hw address recognition for better ack rate, append 2 status bytes */
CC2500_CONFIG_PKTCTRL1 = 0x24,
/** CRC appending, variable length packets */
CC2500_CONFIG_PKTCTRL0 = 0x45,
CC2500_CONFIG_ADDR = 0x00,
CC2500_CONFIG_CHANNR = CC2500_DEFAULT_CHANNEL,
CC2500_CONFIG_FSCTRL1 = 0x10,
CC2500_CONFIG_FSCTRL0 = 0x00,
CC2500_CONFIG_FREQ2 = CC2500_DEFAULT_FREQ2,
CC2500_CONFIG_FREQ1 = CC2500_DEFAULT_FREQ1,
CC2500_CONFIG_FREQ0 = CC2500_DEFAULT_FREQ0,
CC2500_CONFIG_MDMCFG4 = 0x2D,
CC2500_CONFIG_MDMCFG3 = 0x3B,
CC2500_CONFIG_MDMCFG2 = 0x0B,
CC2500_CONFIG_MDMCFG1 = 0x22,
CC2500_CONFIG_MDMCFG0 = 0xF8,
CC2500_CONFIG_DEVIATN = 0x44,
CC2500_CONFIG_MCSM2 = 0x07,
/** TX on CCA; Stay in Rx after Rx and Tx */
CC2500_CONFIG_MCSM1 = 0x3F,
CC2500_CONFIG_MCSM0 = 0x18,
CC2500_CONFIG_FOCCFG = 0x1D,
CC2500_CONFIG_BSCFG = 0x1C,
CC2500_CONFIG_AGCTRL2 = 0xC7, // LNA's
CC2500_CONFIG_AGCTRL1 = 0x00, // CCA threshold definition
CC2500_CONFIG_AGCTRL0 = 0xB0,
CC2500_CONFIG_WOREVT1 = 0x87,
CC2500_CONFIG_WOREVT0 = 0x6B,
CC2500_CONFIG_WORCTRL = 0xF8,
CC2500_CONFIG_FREND1 = 0xB6,
CC2500_CONFIG_FREND0 = 0x10,
CC2500_CONFIG_FSCAL3 = 0xEA,
CC2500_CONFIG_FSCAL2 = 0x0A,
CC2500_CONFIG_FSCAL1 = 0x00,
CC2500_CONFIG_FSCAL0 = 0x11,
CC2500_CONFIG_RCCTRL1 = 0x41,
CC2500_CONFIG_RCCTRL0 = 0x00,
CC2500_CONFIG_FSTEST = 0x59,
CC2500_CONFIG_PTEST = 0x7F,
CC2500_CONFIG_AGCTST = 0x3F,
CC2500_CONFIG_TEST2 = 0x88,
CC2500_CONFIG_TEST1 = 0x31,
CC2500_CONFIG_TEST0 = 0x0B,
};
#ifndef CCXX00_RADIO_DEFINED
#define CCXX00_RADIO_DEFINED
#endif
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/power.c | /* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "libusb_driver.h"
static NTSTATUS DDKAPI
on_power_state_complete(DEVICE_OBJECT *device_object,
IRP *irp,
void *context);
static void DDKAPI
on_power_set_device_state_complete(DEVICE_OBJECT *device_object,
UCHAR minor_function,
POWER_STATE power_state,
void *context,
IO_STATUS_BLOCK *io_status);
NTSTATUS dispatch_power(libusb_device_t *dev, IRP *irp)
{
IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
POWER_STATE power_state;
NTSTATUS status;
status = remove_lock_acquire(dev);;
if(!NT_SUCCESS(status))
{
irp->IoStatus.Status = status;
PoStartNextPowerIrp(irp);
IoCompleteRequest(irp, IO_NO_INCREMENT);
return status;
}
if(stack_location->MinorFunction == IRP_MN_SET_POWER)
{
power_state = stack_location->Parameters.Power.State;
if(stack_location->Parameters.Power.Type == SystemPowerState)
{
DEBUG_MESSAGE("dispatch_power(): IRP_MN_SET_POWER: S%d",
power_state.SystemState - PowerSystemWorking);
}
else
{
DEBUG_MESSAGE("dispatch_power(): IRP_MN_SET_POWER: D%d",
power_state.DeviceState - PowerDeviceD0);
if(power_state.DeviceState > dev->power_state.DeviceState)
{
/* device is powered down, report device state to the */
/* Power Manager before sending the IRP down */
/* (power up is handled by the completion routine) */
PoSetPowerState(dev->self, DevicePowerState, power_state);
}
}
/* TODO: should PoStartNextPowerIrp() be called here or from the */
/* completion routine? */
PoStartNextPowerIrp(irp);
IoCopyCurrentIrpStackLocationToNext(irp);
IoSetCompletionRoutine(irp,
on_power_state_complete,
dev,
TRUE, /* on success */
TRUE, /* on error */
TRUE);/* on cancel */
return PoCallDriver(dev->next_stack_device, irp);
}
else
{
/* pass all other power IRPs down without setting a completion routine */
PoStartNextPowerIrp(irp);
IoSkipCurrentIrpStackLocation(irp);
status = PoCallDriver(dev->next_stack_device, irp);
remove_lock_release(dev);
return status;
}
}
static NTSTATUS DDKAPI
on_power_state_complete(DEVICE_OBJECT *device_object,
IRP *irp,
void *context)
{
libusb_device_t *dev = context;
IO_STACK_LOCATION *stack_location = IoGetCurrentIrpStackLocation(irp);
POWER_STATE power_state = stack_location->Parameters.Power.State;
DEVICE_POWER_STATE dev_power_state;
if(irp->PendingReturned)
{
IoMarkIrpPending(irp);
}
if(NT_SUCCESS(irp->IoStatus.Status))
{
if(stack_location->Parameters.Power.Type == SystemPowerState)
{
DEBUG_MESSAGE("on_power_state_complete(): S%d",
power_state.SystemState - PowerSystemWorking);
/* save current system state */
dev->power_state.SystemState = power_state.SystemState;
/* set device power status correctly */
/* dev_power_state = power_state.SystemState == PowerSystemWorking ? */
/* PowerDeviceD0 : PowerDeviceD3; */
/* get supported device power state from the array reported by */
/* IRP_MN_QUERY_CAPABILITIES */
dev_power_state = dev->device_power_states[power_state.SystemState];
/* set the device power state, but don't block the thread */
power_set_device_state(dev, dev_power_state, FALSE);
}
else /* DevicePowerState */
{
DEBUG_MESSAGE("on_power_state_complete(): D%d",
power_state.DeviceState - PowerDeviceD0);
if(power_state.DeviceState <= dev->power_state.DeviceState)
{
/* device is powered up, */
/* report device state to Power Manager */
PoSetPowerState(dev->self, DevicePowerState, power_state);
}
/* save current device state */
dev->power_state.DeviceState = power_state.DeviceState;
}
}
else
{
DEBUG_MESSAGE("on_power_state_complete(): failed");
}
remove_lock_release(dev);
return STATUS_SUCCESS;
}
static void DDKAPI
on_power_set_device_state_complete(DEVICE_OBJECT *device_object,
UCHAR minor_function,
POWER_STATE power_state,
void *context,
IO_STATUS_BLOCK *io_status)
{
KeSetEvent((KEVENT *)context, EVENT_INCREMENT, FALSE);
}
void power_set_device_state(libusb_device_t *dev,
DEVICE_POWER_STATE device_state, bool_t block)
{
NTSTATUS status;
KEVENT event;
POWER_STATE power_state;
power_state.DeviceState = device_state;
if(block) /* wait for IRP to complete */
{
KeInitializeEvent(&event, NotificationEvent, FALSE);
/* set the device power state and wait for completion */
status = PoRequestPowerIrp(dev->physical_device_object,
IRP_MN_SET_POWER,
power_state,
on_power_set_device_state_complete,
&event, NULL);
if(status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
}
}
else
{
PoRequestPowerIrp(dev->physical_device_object, IRP_MN_SET_POWER,
power_state, NULL, NULL, NULL);
}
}
|
tinyos-io/tinyos-3.x-contrib | mc/raven/tos/platforms/raven/raven.h | <filename>mc/raven/tos/platforms/raven/raven.h
/*
* Copyright (c) 2012 <NAME>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of INSERT_AFFILIATION_NAME_HERE nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS 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.
*/
/**
* Commands for controlling platform coprocessor (atmega3290) via Uart0 (SIPC - serial inter-platform communication).
*
* @author <NAME>
*
*/
#ifndef RAVEN_H
#define RAVEN_H
typedef enum {
// Symbols
SIPC_CMD_ID_LCD_SYMB_RAVEN_ON = 0x00,
SIPC_CMD_ID_LCD_SYMB_RAVEN_OFF = 0x01,
SIPC_CMD_ID_LCD_SYMB_BELL_ON = 0x02,
SIPC_CMD_ID_LCD_SYMB_BELL_OFF = 0x03,
SIPC_CMD_ID_LCD_SYMB_TONE_ON = 0x04,
SIPC_CMD_ID_LCD_SYMB_TONE_OFF = 0x05,
SIPC_CMD_ID_LCD_SYMB_MIC_ON = 0x06,
SIPC_CMD_ID_LCD_SYMB_MIC_OFF = 0x07,
SIPC_CMD_ID_LCD_SYMB_SPEAKER_ON = 0x08,
SIPC_CMD_ID_LCD_SYMB_SPEAKER_OFF = 0x09,
SIPC_CMD_ID_LCD_SYMB_KEY_ON = 0x0a,
SIPC_CMD_ID_LCD_SYMB_KEY_OFF = 0x0b,
SIPC_CMD_ID_LCD_SYMB_ATT_ON = 0x0c,
SIPC_CMD_ID_LCD_SYMB_ATT_OFF = 0x0d,
SIPC_CMD_ID_LCD_SYMB_SPACE_SUN = 0x0e,
SIPC_CMD_ID_LCD_SYMB_SPACE_MOON = 0x0f,
SIPC_CMD_ID_LCD_SYMB_SPACE_OFF = 0x10,
SIPC_CMD_ID_LCD_SYMB_CLOCK_AM = 0x11,
SIPC_CMD_ID_LCD_SYMB_CLOCK_PM = 0x12,
SIPC_CMD_ID_LCD_SYMB_CLOCK_OFF = 0x13,
SIPC_CMD_ID_LCD_SYMB_TRX_RX = 0x14,
SIPC_CMD_ID_LCD_SYMB_TRX_TX = 0x15,
SIPC_CMD_ID_LCD_SYMB_TRX_OFF = 0x16,
SIPC_CMD_ID_LCD_SYMB_IP_ON = 0x17,
SIPC_CMD_ID_LCD_SYMB_IP_OFF = 0x18,
SIPC_CMD_ID_LCD_SYMB_PAN_ON = 0x19,
SIPC_CMD_ID_LCD_SYMB_PAN_OFF = 0x1a,
SIPC_CMD_ID_LCD_SYMB_ZLINK_ON = 0x1b,
SIPC_CMD_ID_LCD_SYMB_ZLINK_OFF = 0x1c,
SIPC_CMD_ID_LCD_SYMB_ZIGBEE_ON = 0x1d,
SIPC_CMD_ID_LCD_SYMB_ZIGBEE_OFF = 0x1e,
SIPC_CMD_ID_LCD_SYMB_ANTENNA_LEVEL_0 = 0x1f,
SIPC_CMD_ID_LCD_SYMB_ANTENNA_LEVEL_1 = 0x20,
SIPC_CMD_ID_LCD_SYMB_ANTENNA_LEVEL_2 = 0x21,
SIPC_CMD_ID_LCD_SYMB_ANTENNA_OFF = 0x22,
//SIPC_CMD_ID_LCD_SYMB_BAT // bettery symbol is controlled by ATMega3290...
SIPC_CMD_ID_LCD_SYMB_ENV_OPEN = 0x23,
SIPC_CMD_ID_LCD_SYMB_ENV_CLOSE = 0x24,
SIPC_CMD_ID_LCD_SYMB_ENV_OFF = 0x25,
SIPC_CMD_ID_LCD_SYMB_TEMP_CELSIUS = 0x26,
SIPC_CMD_ID_LCD_SYMB_TEMP_FAHRENHEIT = 0x27,
SIPC_CMD_ID_LCD_SYMB_TEMP_OFF = 0x28,
SIPC_CMD_ID_LCD_SYMB_MINUS_ON = 0x29,
SIPC_CMD_ID_LCD_SYMB_MINUS_OFF = 0x2a,
SIPC_CMD_ID_LCD_SYMB_DOT_ON = 0x2b,
SIPC_CMD_ID_LCD_SYMB_DOT_OFF = 0x2c,
SIPC_CMD_ID_LCD_SYMB_COL_ON = 0x2d,
SIPC_CMD_ID_LCD_SYMB_COL_OFF = 0x2e,
// Led
SIPC_CMD_ID_LED_ON = 0x2f,
SIPC_CMD_ID_LED_TOGGLE = 0x30,
SIPC_CMD_ID_LED_OFF = 0x31,
// Commands total number.
SIPC_CMD_ID_LCD_MAX = 0x32,
// Messages
SIPC_CMD_ID_MSG = 0x33, // print text message
SIPC_CMD_ID_HEX = 0x34, // print hex number (experimental, TODO: not fully implemented)
SIPC_CMD_WITH_ANSWER = 0x7f,
//Sensor read commands
SIPC_CMD_ID_READ_TEMPERATURE = 0x80,
SIPC_CMD_ID_READ_BATTERY = 0x81,
} SipcCmdId_t;
typedef enum {
SIPC_ANSWER_ID_TEMPERATURE = 1,
SIPC_ANSWER_ID_BATTERY = 2,
} SipcAnswerId_t;
typedef enum {
SIPC_SOF = 0x02, //!< Unique start of frame delimiter.
SIPC_EOF = 0x03, //!< Unique end of frame delimiter.
SIPC_ESC = 0x17, //!< Unique byte used to indicate a stuffed byte.
SIPC_ESC_MASK = 0x40 //!< Value used to OR together with the stuffed byte.
} SipcCtl_t;
typedef enum { // TODO: not implemented
SIPC_HEX1 = 0x01,
SIPC_HEX2 = 0x02,
SIPC_HEX3 = 0x04,
SIPC_HEX4 = 0x08,
SIPC_HEXNONE = 0x00,
SIPC_HEXAUTO = 0x10,
SIPC_HEXALL = SIPC_HEX1 | SIPC_HEX2 | SIPC_HEX3 | SIPC_HEX4
} SipcHexMask_t;
#define SIPC_PACKET_SIZE (256) //!< Maximum packet size that SIPC can handle.
#endif //RAVEN_H
|
tinyos-io/tinyos-3.x-contrib | uob/apps/UDPServices/Service.h | <gh_stars>1-10
#ifndef _SERVICE_H
#define _SERVICE_H
enum {
MAX_NAME_LENGTH = 20,
MAX_SNAME_LENGTH = 10,
MAX_DATA_LENGTH = 16,
};
/* enum{ */
/* INVALID_SERVICE_TYPE = 0, */
/* SOURCE_SERVICE_TYPE = 1, */
/* SINK_SERVICE_TYPE = 2, */
/* PROCESSING_SERVICE_TYPE = 3, */
/* }; */
/* nx_struct service_t { */
/* nx_uint16_t type; */
/* nx_uint8_t name[MAX_NAME_LENGTH]; */
/* }; */
enum {
TYPE_SRV = 0x0021,
TYPE_AAAA = 0x001c,
FLAG_RESPONSE = 0x8000,
FLAG_STANDARD_QUERY = 0x0000, // more details
FLAG_AUTHORATIVE = 0x0400,
FLAG_TRUNCATED = 0x0200,
FLAG_RECURSION_DESIRED = 0x0100,
FLAG_RECURSION_AVAILABLE = 0x0080,
FLAG_RESERVED = 0x0040,
FLAG_AUTHENTICATED = 0x0020,
FLAG_ERROR = 0x0010, // more details
CLASS_IN = 0x0001,
CACHE_FLUSH_TRUE = 0x8000,
};
typedef nx_struct {
nx_uint8_t name[MAX_NAME_LENGTH];
nx_uint16_t type;
nx_uint16_t class;
nx_uint32_t ttl;
nx_uint16_t data_length;
nx_uint16_t prio;
nx_uint16_t weight;
nx_uint16_t port;
nx_uint8_t target[MAX_SNAME_LENGTH];
} mdns_srv_answer_t;
typedef nx_struct {
nx_uint8_t name[MAX_SNAME_LENGTH];
nx_uint16_t type;
nx_uint16_t class;
nx_uint32_t ttl;
nx_uint16_t data_length;
nx_uint8_t addr[MAX_DATA_LENGTH];
} mdns_aaaa_answer_t;
nx_struct mdns_service_t {
nx_uint16_t transaction_id;
nx_uint16_t flags;
nx_uint16_t questions;
nx_uint16_t answer_rr;
nx_uint16_t auth_rr;
nx_uint16_t additional_rr;
mdns_srv_answer_t srv_answer;
mdns_aaaa_answer_t a4_answer;
} ;
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/tests/testlibusb_win.c | /* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2004 <NAME> <<EMAIL>>
* Copyright (c) 2000-2004 <NAME> <<EMAIL>>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef __GNUC__
#define WINVER 0x0500
#endif
#define INITGUID
#include <windows.h>
#include <dbt.h>
#include <stdio.h>
#include <initguid.h>
#include "usb.h"
#define LIBUSB_WINDOW_CLASS "LIBUSB_WINDOW_CLASS"
#define LIBUSB_BUTTON_HEIGHT 30
#define LIBUSB_BUTTON_WIDTH 70
#define LIBUSB_BORDER 10
DEFINE_GUID(GUID_DEVINTERFACE_USB_HUB, 0xf18a0e88, 0xc30c, 0x11d0, 0x88, \
0x15, 0x00, 0xa0, 0xc9, 0x06, 0xbe, 0xd8);
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, \
0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
#define EDIT_BUF_INCREMENT 1024
enum {
ID_EXIT = 100,
ID_REFRESH,
ID_EDIT
};
static char *edit_buffer = NULL;
static int edit_buffer_size = 0;
static int edit_buffer_pos = 0;
static HWND main_win;
static HWND exit_button;
static HWND refresh_button;
static HWND edit_box;
static HDEVNOTIFY notification_handle_hub, notification_handle_dev;
LRESULT CALLBACK win_proc(HWND handle, UINT message, WPARAM w_param,
LPARAM l_param);
static void on_size(int width, int height);
static void on_refresh(void);
static void edit_printf_init(void);
static void edit_printf_free(void);
static void edit_printf(const char *s, ...);
static void print_configuration(struct usb_config_descriptor *config);
static void print_interface(struct usb_interface *interface);
static void print_altsetting(struct usb_interface_descriptor *interface);
static void print_endpoint(struct usb_endpoint_descriptor *endpoint);
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev_instance,
LPSTR cmd_line, int cmd_show)
{
MSG msg;
WNDCLASSEX win_class;
DEV_BROADCAST_DEVICEINTERFACE dev_if;
LoadLibrary("comctl32.dll");
win_class.cbSize = sizeof(WNDCLASSEX);
win_class.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS ;
win_class.lpfnWndProc = win_proc;
win_class.cbClsExtra = 0;
win_class.cbWndExtra = 0;
win_class.hInstance = instance;
win_class.hIcon = NULL;
win_class.hCursor = LoadCursor(NULL, IDC_ARROW);
win_class.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
win_class.lpszMenuName = NULL;
win_class.lpszClassName = LIBUSB_WINDOW_CLASS;
win_class.hIconSm = NULL;
RegisterClassEx(&win_class);
main_win = CreateWindowEx(WS_EX_APPWINDOW| WS_EX_CONTROLPARENT,
LIBUSB_WINDOW_CLASS,
"TestLibUsb - Windows Version",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
| WS_DLGFRAME,
CW_USEDEFAULT, 0, 500, 500, NULL, NULL,
instance, NULL);
if(!main_win)
{
return FALSE;
}
exit_button = CreateWindow("BUTTON", "Exit",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10, 10,
LIBUSB_BUTTON_WIDTH, LIBUSB_BUTTON_HEIGHT,
main_win, (HMENU) ID_EXIT, instance, NULL);
refresh_button = CreateWindow("BUTTON", "Refresh",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10, 100,
LIBUSB_BUTTON_WIDTH, LIBUSB_BUTTON_HEIGHT,
main_win, (HMENU) ID_REFRESH, instance,
NULL);
edit_box = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL
| ES_AUTOHSCROLL | ES_READONLY,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
main_win, (HMENU) ID_EDIT, instance, NULL);
SendMessage(edit_box, WM_SETFONT, (WPARAM) CreateFont(13, 8, 0, 0,
400, 0, 0, 0,
0, 1, 2, 1,
49, "Courier"), 0);
ShowWindow(main_win, cmd_show);
UpdateWindow(main_win);
BringWindowToTop(main_win);
usb_set_debug(4);
usb_init();
usb_find_busses();
on_refresh();
dev_if.dbcc_size = sizeof(dev_if);
dev_if.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_HUB;
notification_handle_hub = RegisterDeviceNotification(main_win, &dev_if, 0);
dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
notification_handle_dev = RegisterDeviceNotification(main_win, &dev_if, 0);
while(GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DestroyWindow(main_win);
UnregisterClass(LIBUSB_WINDOW_CLASS, instance);
return 0;
}
LRESULT CALLBACK win_proc(HWND win, UINT message, WPARAM w_param,
LPARAM l_param)
{
DEV_BROADCAST_HDR *hdr = (DEV_BROADCAST_HDR *) l_param;
switch(message)
{
case WM_DESTROY:
if(notification_handle_hub)
UnregisterDeviceNotification(notification_handle_hub);
if(notification_handle_dev)
UnregisterDeviceNotification(notification_handle_dev);
PostQuitMessage(0);
break;
case WM_SIZE:
on_size(LOWORD(l_param), HIWORD(l_param));
break;
case WM_COMMAND:
switch(LOWORD(w_param))
{
case ID_EXIT:
PostQuitMessage(0);
break;
case ID_REFRESH:
on_refresh();
break;
default:
return DefWindowProc(win, message, w_param, l_param );
}
break;
case WM_DEVICECHANGE:
switch(w_param)
{
case DBT_DEVICEREMOVECOMPLETE:
if(hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
on_refresh();
break;
case DBT_DEVICEARRIVAL:
if(hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
on_refresh();
break;
default:
;
}
break;
default:
return DefWindowProc(win, message, w_param, l_param);
}
return 0;
}
static void on_size(int width, int height)
{
int _width, _height, _x, _y;
_width = LIBUSB_BUTTON_WIDTH;
_height = LIBUSB_BUTTON_HEIGHT;
_x = width - LIBUSB_BORDER - LIBUSB_BUTTON_WIDTH;
_y = height - LIBUSB_BORDER - LIBUSB_BUTTON_HEIGHT;
SetWindowPos(exit_button, HWND_TOP, _x, _y, _width, _height,
SWP_SHOWWINDOW);
_x -= LIBUSB_BUTTON_WIDTH + LIBUSB_BORDER;
SetWindowPos(refresh_button, HWND_TOP, _x, _y, _width, _height,
SWP_SHOWWINDOW);
_width = width - 2 * LIBUSB_BORDER;
_height = height - 4 * LIBUSB_BORDER - LIBUSB_BUTTON_HEIGHT;
_y = LIBUSB_BORDER;
_x = LIBUSB_BORDER;
SetWindowPos(edit_box, HWND_TOP, _x, _y, _width, _height,
SWP_SHOWWINDOW);
}
static void on_refresh(void)
{
struct usb_bus *bus;
struct usb_device *dev;
const struct usb_version *version;
edit_printf_init();
usb_find_devices();
version = usb_get_version();
if(version)
{
edit_printf("DLL version:\t%d.%d.%d.%d\r\n",
version->dll.major, version->dll.minor,
version->dll.micro, version->dll.nano);
edit_printf("Driver version:\t%d.%d.%d.%d\r\n\r\n",
version->driver.major, version->driver.minor,
version->driver.micro, version->driver.nano);
}
edit_printf("bus/device idVendor/idProduct\r\n");
for (bus = usb_get_busses(); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
int ret, i;
char string[256];
usb_dev_handle *udev;
edit_printf("%s/%s %04X/%04X\r\n", bus->dirname, dev->filename,
dev->descriptor.idVendor, dev->descriptor.idProduct);
udev = usb_open(dev);
if (udev) {
if (dev->descriptor.iManufacturer) {
ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer,
string, sizeof(string));
if (ret > 0)
edit_printf("- Manufacturer : %s\r\n", string);
else
edit_printf("- Unable to fetch manufacturer string\r\n");
}
if (dev->descriptor.iProduct) {
ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string,
sizeof(string));
if (ret > 0)
edit_printf("- Product : %s\r\n", string);
else
edit_printf("- Unable to fetch product string\r\n");
}
if (dev->descriptor.iSerialNumber) {
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber,
string, sizeof(string));
if (ret > 0)
edit_printf("- Serial Number: %s\r\n", string);
else
edit_printf("- Unable to fetch serial number string\r\n");
}
usb_close (udev);
}
if (!dev->config) {
edit_printf(" Couldn't retrieve descriptors\r\n");
continue;
}
for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
print_configuration(&dev->config[i]);
}
}
SendMessage(edit_box, WM_SETTEXT, 0, (LPARAM) edit_buffer);
edit_printf_free();
}
static void edit_printf_init(void)
{
if(edit_buffer)
{
free(edit_buffer);
}
edit_buffer = malloc(EDIT_BUF_INCREMENT);
if(edit_buffer)
{
edit_buffer_size = EDIT_BUF_INCREMENT;
}
edit_buffer_size = 0;
edit_buffer_pos = 0;
}
static void edit_printf_free(void)
{
if(edit_buffer)
{
free(edit_buffer);
}
edit_buffer = NULL;
edit_buffer_size = 0;
edit_buffer_pos = 0;
}
static void edit_printf(const char *s, ...)
{
va_list args;
va_start(args, s);
if(edit_buffer_size - edit_buffer_pos < EDIT_BUF_INCREMENT)
{
char *tmp = realloc(edit_buffer,
edit_buffer_size + EDIT_BUF_INCREMENT);
if(tmp)
{
edit_buffer = tmp;
edit_buffer_size += EDIT_BUF_INCREMENT;
}
else
{
return;
}
}
edit_buffer_pos += vsnprintf(edit_buffer + edit_buffer_pos,
EDIT_BUF_INCREMENT - 1, s, args);
va_end(args);
}
static void print_endpoint(struct usb_endpoint_descriptor *endpoint)
{
edit_printf(" bEndpointAddress: %02xh\r\n", endpoint->bEndpointAddress);
edit_printf(" bmAttributes: %02xh\r\n", endpoint->bmAttributes);
edit_printf(" wMaxPacketSize: %d\r\n", endpoint->wMaxPacketSize);
edit_printf(" bInterval: %d\r\n", endpoint->bInterval);
edit_printf(" bRefresh: %d\r\n", endpoint->bRefresh);
edit_printf(" bSynchAddress: %d\r\n", endpoint->bSynchAddress);
}
static void print_altsetting(struct usb_interface_descriptor *interface)
{
int i;
edit_printf(" bInterfaceNumber: %d\r\n", interface->bInterfaceNumber);
edit_printf(" bAlternateSetting: %d\r\n", interface->bAlternateSetting);
edit_printf(" bNumEndpoints: %d\r\n", interface->bNumEndpoints);
edit_printf(" bInterfaceClass: %d\r\n", interface->bInterfaceClass);
edit_printf(" bInterfaceSubClass: %d\r\n", interface->bInterfaceSubClass);
edit_printf(" bInterfaceProtocol: %d\r\n", interface->bInterfaceProtocol);
edit_printf(" iInterface: %d\r\n", interface->iInterface);
for (i = 0; i < interface->bNumEndpoints; i++)
print_endpoint(&interface->endpoint[i]);
}
static void print_interface(struct usb_interface *interface)
{
int i;
for (i = 0; i < interface->num_altsetting; i++)
print_altsetting(&interface->altsetting[i]);
}
static void print_configuration(struct usb_config_descriptor *config)
{
int i;
edit_printf(" wTotalLength: %d\r\n", config->wTotalLength);
edit_printf(" bNumInterfaces: %d\r\n", config->bNumInterfaces);
edit_printf(" bConfigurationValue: %d\r\n", config->bConfigurationValue);
edit_printf(" iConfiguration: %d\r\n", config->iConfiguration);
edit_printf(" bmAttributes: %02xh\r\n", config->bmAttributes);
edit_printf(" MaxPower: %d\r\n", config->MaxPower);
for (i = 0; i < config->bNumInterfaces; i++)
print_interface(&config->interface[i]);
}
|
tinyos-io/tinyos-3.x-contrib | berkeley/quanto/tos/chips/cc2420/CC2420Quanto.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef _CC2420_QUANTO_H
#define _CC2420_QUANTO_H
/* Quanto constants for the CC2420 */
/* Power states for the radio:
* OFF/LISTEN/RX/TX
* States are set on the msB of the powerstate_t
* Powerlevels are set on the lower 5 bits of the lsB
*/
enum {
ACT_PXY_CC2420_RX = 0x50,
CC2420_PW_STOPPED = 0x0000, //set by CC2420Csma. override others
CC2420_PW_STARTING = 0x0100, //set by CC2420Csma. override others. unused.
CC2420_PW_LISTEN = 0x0200, //set by CC2420Csma. override others
CC2420_PW_RX = 0x0400, //set by CC2420Transmit on SFD & !Tx
CC2420_PW_TX = 0x0800, //set by CC2420Transmit on attemptSend successful
CC2420_PW_STOPPING = 0x1000, //set by CC2420Csma. override others. unused
CC2420_PW_RXFIFO = 0x2000, //set by CC2420Receive
CC2420_PW_TXFIFO = 0x4000, //set by CC2420Transmit
CC2420_POWERSTATE_MASK = 0xFF00u, //mask
CC2420_POWERSTATE_OFF = 8 , //offset
CC2420_POWERLEVEL_MASK = 0x001F, //mask this is set when the state is TX
CC2420_POWERLEVEL_OFF = 0 , //offset
};
#endif
|
tinyos-io/tinyos-3.x-contrib | tinymulle/apps/IRSensorTest/TestAdc.h | <gh_stars>1-10
#ifndef TEST_ADC_H
#define TEST_ADC_H
typedef nx_struct test_serial_msg {
nx_uint16_t data;
} adc_msg_t;
enum {
AM_ADC_MSG = 8,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/libusb_driver.c | <reponame>tinyos-io/tinyos-3.x-contrib
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define __LIBUSB_DRIVER_C__
#include "libusb_driver.h"
extern int debug_level;
static void DDKAPI unload(DRIVER_OBJECT *driver_object);
static NTSTATUS DDKAPI on_usbd_complete(DEVICE_OBJECT *device_object,
IRP *irp,
void *context);
NTSTATUS DDKAPI DriverEntry(DRIVER_OBJECT *driver_object,
UNICODE_STRING *registry_path)
{
int i;
DEBUG_MESSAGE("DriverEntry(): loading driver");
/* initialize global variables */
debug_level = LIBUSB_DEBUG_MSG;
/* initialize the driver object's dispatch table */
for(i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
{
driver_object->MajorFunction[i] = dispatch;
}
driver_object->DriverExtension->AddDevice = add_device;
driver_object->DriverUnload = unload;
return STATUS_SUCCESS;
}
NTSTATUS DDKAPI add_device(DRIVER_OBJECT *driver_object,
DEVICE_OBJECT *physical_device_object)
{
NTSTATUS status;
DEVICE_OBJECT *device_object = NULL;
libusb_device_t *dev;
ULONG device_type;
UNICODE_STRING nt_device_name;
UNICODE_STRING symbolic_link_name;
WCHAR tmp_name_0[128];
WCHAR tmp_name_1[128];
char id[256];
int i;
/* get the hardware ID from the registry */
if(!reg_get_hardware_id(physical_device_object, id, sizeof(id)))
{
DEBUG_ERROR("add_device(): unable to read registry");
return STATUS_SUCCESS;
}
/* only attach the (filter) driver to USB devices, skip hubs */
/* and interfaces of composite devices */
if(!strstr(id, "usb\\") || strstr(id, "hub") || strstr(id, "&mi_"))
{
return STATUS_SUCCESS;
}
/* retrieve the type of the lower device object */
device_object = IoGetAttachedDeviceReference(physical_device_object);
if(device_object)
{
device_type = device_object->DeviceType;
ObDereferenceObject(device_object);
}
else
{
device_type = FILE_DEVICE_UNKNOWN;
}
/* try to create a new device object */
for(i = 1; i < LIBUSB_MAX_NUMBER_OF_DEVICES; i++)
{
/* initialize some unicode strings */
_snwprintf(tmp_name_0, sizeof(tmp_name_0)/sizeof(WCHAR), L"%s%04d",
LIBUSB_NT_DEVICE_NAME, i);
_snwprintf(tmp_name_1, sizeof(tmp_name_1)/sizeof(WCHAR), L"%s%04d",
LIBUSB_SYMBOLIC_LINK_NAME, i);
RtlInitUnicodeString(&nt_device_name, tmp_name_0);
RtlInitUnicodeString(&symbolic_link_name, tmp_name_1);
/* create the object */
status = IoCreateDevice(driver_object,
sizeof(libusb_device_t),
&nt_device_name, device_type, 0, FALSE,
&device_object);
if(NT_SUCCESS(status))
{
DEBUG_MESSAGE("add_device(): device #%d created", i);
break;
}
device_object = NULL;
/* continue until an unused device name is found */
}
if(!device_object)
{
DEBUG_ERROR("add_device(): creating device failed");
return status;
}
status = IoCreateSymbolicLink(&symbolic_link_name, &nt_device_name);
if(!NT_SUCCESS(status))
{
DEBUG_ERROR("add_device(): creating symbolic link failed");
IoDeleteDevice(device_object);
return status;
}
/* setup the "device object" */
dev = device_object->DeviceExtension;
memset(dev, 0, sizeof(libusb_device_t));
/* attach the newly created device object to the stack */
dev->next_stack_device =
IoAttachDeviceToDeviceStack(device_object, physical_device_object);
if(!dev->next_stack_device)
{
DEBUG_ERROR("add_device(): attaching to device stack failed");
IoDeleteSymbolicLink(&symbolic_link_name);
IoDeleteDevice(device_object);
return STATUS_NO_SUCH_DEVICE;
}
dev->self = device_object;
dev->physical_device_object = physical_device_object;
dev->id = i;
/* set initial power states */
dev->power_state.DeviceState = PowerDeviceD0;
dev->power_state.SystemState = PowerSystemWorking;
/* get device properties from the registry */
reg_get_properties(dev);
if(dev->is_filter)
{
/* send all USB requests to the PDO in filter driver mode */
dev->target_device = dev->physical_device_object;
/* use the same flags as the underlying object */
device_object->Flags |= dev->next_stack_device->Flags
& (DO_BUFFERED_IO | DO_DIRECT_IO | DO_POWER_PAGABLE);
}
else
{
/* send all USB requests to the lower object in device driver mode */
dev->target_device = dev->next_stack_device;
device_object->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
}
clear_pipe_info(dev);
remove_lock_initialize(dev);
device_object->Flags &= ~DO_DEVICE_INITIALIZING;
return status;
}
VOID DDKAPI unload(DRIVER_OBJECT *driver_object)
{
DEBUG_MESSAGE("unload(): unloading driver");
}
NTSTATUS complete_irp(IRP *irp, NTSTATUS status, ULONG info)
{
irp->IoStatus.Status = status;
irp->IoStatus.Information = info;
IoCompleteRequest(irp, IO_NO_INCREMENT);
return status;
}
NTSTATUS call_usbd(libusb_device_t *dev, void *urb, ULONG control_code,
int timeout)
{
KEVENT event;
NTSTATUS status;
IRP *irp;
IO_STACK_LOCATION *next_irp_stack;
LARGE_INTEGER _timeout;
IO_STATUS_BLOCK io_status;
if(timeout > LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT)
{
timeout = LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT;
}
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest(control_code, dev->target_device,
NULL, 0, NULL, 0, TRUE,
NULL, &io_status);
if(!irp)
{
return STATUS_NO_MEMORY;
}
next_irp_stack = IoGetNextIrpStackLocation(irp);
next_irp_stack->Parameters.Others.Argument1 = urb;
next_irp_stack->Parameters.Others.Argument2 = NULL;
IoSetCompletionRoutine(irp, on_usbd_complete, &event, TRUE, TRUE, TRUE);
status = IoCallDriver(dev->target_device, irp);
if(status == STATUS_PENDING)
{
_timeout.QuadPart = -(timeout * 10000);
if(KeWaitForSingleObject(&event, Executive, KernelMode,
FALSE, &_timeout) == STATUS_TIMEOUT)
{
DEBUG_ERROR("call_usbd(): request timed out");
IoCancelIrp(irp);
}
}
/* wait until completion routine is called */
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = irp->IoStatus.Status;
/* complete the request */
IoCompleteRequest(irp, IO_NO_INCREMENT);
return status;
}
static NTSTATUS DDKAPI on_usbd_complete(DEVICE_OBJECT *device_object,
IRP *irp, void *context)
{
KeSetEvent((KEVENT *) context, IO_NO_INCREMENT, FALSE);
return STATUS_MORE_PROCESSING_REQUIRED;
}
NTSTATUS pass_irp_down(libusb_device_t *dev, IRP *irp,
PIO_COMPLETION_ROUTINE completion_routine,
void *context)
{
if(completion_routine)
{
IoCopyCurrentIrpStackLocationToNext(irp);
IoSetCompletionRoutine(irp, completion_routine, context,
TRUE, TRUE, TRUE);
}
else
{
IoSkipCurrentIrpStackLocation(irp);
}
return IoCallDriver(dev->next_stack_device, irp);
}
bool_t accept_irp(libusb_device_t *dev, IRP *irp)
{
/* check if the IRP is sent to libusb's device object or to */
/* the lower one. This check is neccassary since the device object */
/* might be a filter */
if(irp->Tail.Overlay.OriginalFileObject)
{
return irp->Tail.Overlay.OriginalFileObject->DeviceObject
== dev->self ? TRUE : FALSE;
}
return FALSE;
}
bool_t get_pipe_handle(libusb_device_t *dev, int endpoint_address,
USBD_PIPE_HANDLE *pipe_handle)
{
int i, j;
*pipe_handle = NULL;
for(i = 0; i < LIBUSB_MAX_NUMBER_OF_INTERFACES; i++)
{
if(dev->config.interfaces[i].valid)
{
for(j = 0; j < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; j++)
{
if(dev->config.interfaces[i].endpoints[j].address
== endpoint_address)
{
*pipe_handle = dev->config.interfaces[i].endpoints[j].handle;
return !*pipe_handle ? FALSE : TRUE;
}
}
}
}
return FALSE;
}
void clear_pipe_info(libusb_device_t *dev)
{
memset(dev->config.interfaces, 0 , sizeof(dev->config.interfaces));
}
bool_t update_pipe_info(libusb_device_t *dev,
USBD_INTERFACE_INFORMATION *interface_info)
{
int i;
int number;
if(!interface_info)
{
return FALSE;
}
number = interface_info->InterfaceNumber;
if(interface_info->InterfaceNumber >= LIBUSB_MAX_NUMBER_OF_INTERFACES)
{
return FALSE;
}
DEBUG_MESSAGE("update_pipe_info(): interface %d", number);
dev->config.interfaces[number].valid = TRUE;
for(i = 0; i < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; i++)
{
dev->config.interfaces[number].endpoints[i].address = 0;
dev->config.interfaces[number].endpoints[i].handle = NULL;
}
if(interface_info)
{
for(i = 0; i < (int)interface_info->NumberOfPipes
&& i < LIBUSB_MAX_NUMBER_OF_ENDPOINTS; i++)
{
DEBUG_MESSAGE("update_pipe_info(): endpoint address 0x%02x",
interface_info->Pipes[i].EndpointAddress);
dev->config.interfaces[number].endpoints[i].handle
= interface_info->Pipes[i].PipeHandle;
dev->config.interfaces[number].endpoints[i].address =
interface_info->Pipes[i].EndpointAddress;
}
}
return TRUE;
}
void remove_lock_initialize(libusb_device_t *dev)
{
KeInitializeEvent(&dev->remove_lock.event, NotificationEvent, FALSE);
dev->remove_lock.usage_count = 1;
dev->remove_lock.remove_pending = FALSE;
}
NTSTATUS remove_lock_acquire(libusb_device_t *dev)
{
InterlockedIncrement(&dev->remove_lock.usage_count);
if(dev->remove_lock.remove_pending)
{
if(InterlockedDecrement(&dev->remove_lock.usage_count) == 0)
{
KeSetEvent(&dev->remove_lock.event, 0, FALSE);
}
return STATUS_DELETE_PENDING;
}
return STATUS_SUCCESS;
}
void remove_lock_release(libusb_device_t *dev)
{
if(InterlockedDecrement(&dev->remove_lock.usage_count) == 0)
{
KeSetEvent(&dev->remove_lock.event, 0, FALSE);
}
}
void remove_lock_release_and_wait(libusb_device_t *dev)
{
dev->remove_lock.remove_pending = TRUE;
remove_lock_release(dev);
remove_lock_release(dev);
KeWaitForSingleObject(&dev->remove_lock.event, Executive, KernelMode,
FALSE, NULL);
}
USB_INTERFACE_DESCRIPTOR *
find_interface_desc(USB_CONFIGURATION_DESCRIPTOR *config_desc,
unsigned int size, int interface_number, int altsetting)
{
usb_descriptor_header_t *desc = (usb_descriptor_header_t *)config_desc;
char *p = (char *)desc;
USB_INTERFACE_DESCRIPTOR *if_desc = NULL;
if(!config_desc || (size < config_desc->wTotalLength))
return NULL;
while(size && desc->length <= size)
{
if(desc->type == USB_INTERFACE_DESCRIPTOR_TYPE)
{
if_desc = (USB_INTERFACE_DESCRIPTOR *)desc;
if((if_desc->bInterfaceNumber == (UCHAR)interface_number)
&& (if_desc->bAlternateSetting == (UCHAR)altsetting))
{
return if_desc;
}
}
size -= desc->length;
p += desc->length;
desc = (usb_descriptor_header_t *)p;
}
return NULL;
}
|
tinyos-io/tinyos-3.x-contrib | sensorscheme/tos/lib/SensorScheme/Macros.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef MACROS_H
#define MACROS_H
/**
* Macros.h: defines macros that are used as functions inside the SSeval function, but cannot be
* defined as functions because they jump to labels.
*/
/*-- auxillary functions that need to be implemented as macro --*/
#define incFree (freeCell.idx += sizeof(ss_cell_t))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define first(c) car(c)
#define second(c) first (cdr(c))
#define third(c) second(cdr(c))
#define fourth(c) third (cdr(c))
#define rest(c) cdr(c)
/*-- auxillary functions to handle evaluation functions --*/
#define do_call(a, b, c, d) ({ \
stack = cons(cons(makePrimitive(c), d), stack); \
args = b; \
goto a; \
})
#define do_return(v) ({ \
value = v; \
goto OP_RETURN; \
})
//#define do_retbool(b) do_return(b ? SYM_TRUE : SYM_FALSE)
/* error detection and handling macros */
#define do_assert(p, v) \
if (!(p)) do_error(v)
#define do_error(v) ({ \
dbgerror("SensorSchemeC", "error %hu in %s line %u\n", v, __FILE__, __LINE__); \
call SSRuntime.error(v);})
// checked versions of standard cell operations
#define assertPair(c) do_assert(isPair(c), ERROR_ARG_NOT_PAIR)
#define assertSymbol(c) do_assert(isSymbol(c), ERROR_ARG_NOT_SYMBOL)
#define assertNumber(c) do_assert(isNumber(c), ERROR_ARG_NOT_NUMBER)
#define C_car(c) ({assertPair(c); car(c);})
#define C_cdr(c) ({assertPair(c); cdr(c);})
#define C_symVal(c) ({assertSymbol(c); symVal(c);})
//#define C_numVal(c) ({assertNumber(c); ss_numVal(c);})
#define C_first(c) C_car(c)
#define C_second(c) C_first(C_cdr(c))
#define C_third(c) C_second(C_cdr(c))
#define C_fourth(c) C_third(C_cdr(c))
#define C_rest(c) C_cdr(c)
/* -------- some shortcuts for common SSRuntime operations ------------ */
#define arg_1 (call SSRuntime.ckArg1())
#define arg_2 (call SSRuntime.ckArg2())
#define ss_args (call SSRuntime.getArgs())
#define ss_value (call SSRuntime.getValue())
#define ss_envir (call SSRuntime.getEnvir())
#define ss_stack (call SSRuntime.getStack())
#define ss_set_args(n) (call SSRuntime.setArgs(n))
#define ss_set_value(n) (call SSRuntime.setValue(n))
#define ss_set_envir(n) (call SSRuntime.setEnvir(n))
#define ss_set_stack(n) (call SSRuntime.setStack(n))
#define ss_timerQueue (call SSRuntime.getTimerQueue())
#define ss_set_timerQueue(n) (call SSRuntime.setTimerQueue(n))
#define ss_cons(a, b) (call SSRuntime.cons(a, b))
#define ss_makeNum(n) (call SSRuntime.makeNum(n))
#define ss_numVal(c) (call SSRuntime.numVal(c))
#define C_numVal(c) (call SSRuntime.ckNumVal(c))
/* ---------------- reading and writing tokens ----------------------- */
#define TOK_SYM makeSymbol(0x00)
#define TOK_NUM makeSymbol(0x01)
#define TOK_BROPEN makeSymbol(0x02)
#define TOK_BRCLOSE makeSymbol(0x03)
#define TOK_NIBBLE TOK_SYM
#define TOK_BYTE TOK_NUM
#define TOK_WORD TOK_BROPEN
#define TOK_DWORD TOK_BRCLOSE
/* ---------------- various 'structure' constructors and accessors ----------------------- */
#define MSGSEQ_START (1<<7)
#define MSGSEQ_END (MSGSEQ_START >> 1)
#define MSGSEQ_NUMMASK (~(MSGSEQ_START | MSGSEQ_END))
#define nextSeqNo(n) (((n + 1) & MSGSEQ_NUMMASK) | ((n) & MSGSEQ_END))
#define newSeqNo(n) ((nextSeqNo(n) & (~MSGSEQ_END))| MSGSEQ_START)
#define eqSeqNo(a, b) ((a & MSGSEQ_NUMMASK) == (b & MSGSEQ_NUMMASK))
#define makeRcvQItem(tm, src, seq, b, bc, rt) cons(ss_makeNum(call SSRuntime.now() + tm), \
cons(ss_makeNum(src), \
cons(makeSmallnum(nextSeqNo(seq)), \
cons(makeSmallnum(rt << 10 | b << 2 | bc), ss_stack))))
#define rcvQItemTime(q) ss_numVal(first(q))
#define rcvQItemSrc(q) (am_addr_t)ss_numVal(second(q))
#define rcvQItemSeqNo(q) (ss_numVal(third(q)) & 0xff)
#define rcvQItemBits(q) (uint8_t)(smallnumVal(fourth(q)) >> 2)
#define rcvQItemBitCount(q) (smallnumVal(fourth(q)) & 3)
#define rcvQItemRoutine(q) (smallnumVal(fourth(q)) >> 10)
#define rcvQItemStack(q) cdr(cdr(cdr(cdr(q))))
#define makeSendQItem(seq, b, rt) ss_cons(makeSmallnum(seq | (rt - FIRST_SEND_PRIM) << 8), \
ss_cons(b, ss_cons(ss_args, ss_cons(ss_stack, ss_value))))
#define sendQItemSeq(q) (uint8_t)smallnumVal(first(q))
#define sendQItemRoutine(q) ((smallnumVal(first(q)) >> 8) + FIRST_SEND_PRIM)
#define sendQItemBytes(q) second(q)
#define sendQItemArgs(q) third(q)
#define sendQItemStack(q) fourth(q)
#define sendQItemCont(q) cdr(cdr(cdr(cdr(q))))
#define makeTimerQItem(tm, fn) ss_cons(ss_makeNum(tm), fn)
#define timerQItemTime(q) car(q)
#define timerQItemFunc(q) cdr(q)
#define timerQItemEnvir(q) cdr(cdr(cdr(q)))
#endif
|
tinyos-io/tinyos-3.x-contrib | unlpt/FireSim/tos/lib/tossim/sim_fire.c | /*
* Copyright (c) 2007 New University of Lisbon - Faculty of Sciences and
* Technology.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of New University of Lisbon - Faculty of Sciences and
* Technology nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS 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.
*/
/**
* @author <NAME>
*/
#include <stdio.h>
#include <tos.h>
#include <sim_fire.h>
int ignition[13][13];
int grid[13][13];
int x=0;
int y=0;
int grid_x=0;
int grid_y=0;
int my_posx=0;
int my_posy=0;
int getPositionXFromValue(int val,int *posx) {
int i;
int j;
int idx = 0;
for (i = 0; i < 12; i++) {
for (j= 0; j < 12; j++) {
if (ignition[i][j] == val) {
posx[idx] = i;
//printf("posx is %d\n",i);
idx++;
}
}
}
return idx;
}
int getPositionYFromValue(int val,int *posy) {
int i;
int j;
int idx = 0;
for (i = 0; i < 12; i++) {
for (j= 0; j < 12; j++) {
if (ignition[i][j] == val) {
posy[idx] = j;
//printf("posj is %d\n",j);
idx++;
}
}
}
return idx;
}
void getNodeFromXY(int *valx,int xsize, int *valy,int ysize,int* nodes_grid) {
int i;
for (i = 0; i < xsize; i++) {
/*printf("valx[%d] is %d\n",i,valx[i]);
printf("valy[%d] is %d\n",i,valy[i]);
printf("grid[%d][%d] is %d\n",valx[i],valy[i],grid[valx[i]][valy[i]]);*/
nodes_grid[i] = grid[valx[i]][valy[i]];
}
}
void printGridIgnition() {
int i;
int j;
for (i = 0; i < 12; i++) {
for (j= 0; j < 12; j++) {
printf("ignition[%d][%d]=%d\n",j,i,ignition[j][i]);
}
}
for (i = 0; i < 12; i++) {
for (j= 0; j < 12; j++) {
printf("grid[%d][%d]=%d\n",i,j,grid[i][j]);
}
}
}
void getMyPos() {
int i;
int j;
for (i = 0; i < 12; i++) {
for (j= 0; j < 12; j++) {
if (grid[i][j] == TOS_NODE_ID) {
my_posx = i;
my_posy = j;
}
}
}
/*printf("My position x is %d\n",my_posx);
printf("My position y is %d\n",my_posy);*/
}
bool checkYellow(int *valx, int *valy,int size) {
int i;
getMyPos();
for (i = 0; i < size; i++) {
/*printf("valx is %d\n",valx[i]);
printf("valy is %d\n",valy[i]);
printf("abs posx is %d\n",abs(my_posx-valx[i]));
printf("abs posy is %d\n",abs(my_posy-valy[i]));*/
if (abs(my_posx-valx[i]) < 3 && abs(my_posy-valy[i]) < 3) {
//printf("In yellow!\n");
return TRUE;
}
}
return FALSE;
}
bool checkRed(int *valx, int *valy,int size) {
int i;
getMyPos();
for (i = 0; i < size; i++) {
if (abs(my_posx-valx[i]) < 2 && abs(my_posy-valy[i]) < 2) {
//printf("In red!\n");
return TRUE;
}
}
return FALSE;
}
void setFireGrid(int val) {
int i,j;
//printf("Grid val %d\n",val);
if (grid_x < 12) {
grid[grid_x][grid_y] = val;
grid_x++;
return;
}
else {
if (grid_y < 12) {
grid_x=0;
grid_y++;
grid[grid_x][grid_y] = val;
return;
}
//printf("grid matrix loaded\n");
}
}
void setFireIgnition(int val) {
int i,j;
//printf("Ignition[%d][%d] val %d\n",x,y,val);
if (x < 12) {
ignition[x][y] = val;
x++;
return;
}
else {
if (y < 12) {
x=0;
y++;
ignition[x][y] = val;
return;
}
//printf("ignition matrix loaded\n");
}
/*for (i = 0; i < 12; i++) {
for (j= 0; j < 12; j++) {
//printf("ignition[%d][%d]=%d\n",i,j,ignition[i][j]);
}
}*/
}
|
tinyos-io/tinyos-3.x-contrib | berkeley/apps/AIIT_tutorials/3_PrintSerial/PrintSerial.h | <filename>berkeley/apps/AIIT_tutorials/3_PrintSerial/PrintSerial.h
#ifndef PRINT_SERIAL_H
#define PRINT_SERIAL_H
#include "message.h"
typedef nx_struct print_serial_msg {
//nx_uint16_t counter;
nx_uint8_t buffer[TOSH_DATA_LENGTH];
} print_serial_msg_t;
enum {
AM_PRINT_SERIAL_MSG = 0x0A,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | uob/tossdr/ucla/gnuradio-802.15.4-demodulation/src/lib/ucla_interleave.h | /* -*- c++ -*- */
/*
* Copyright 2004 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/**
* This is a modification of the gr_interleave from GNURadio.
*
* Modified by: <NAME> <<EMAIL>>
*/
#ifndef INCLUDED_UCLA_INTERLEAVE_H
#define INCLUDED_UCLA_INTERLEAVE_H
#include <gr_sync_interpolator.h>
class ucla_interleave;
typedef boost::shared_ptr<ucla_interleave> ucla_interleave_sptr;
ucla_interleave_sptr gr_make_interleave (size_t itemsize);
/*!
* \brief interleave N inputs to a single output
* \ingroup block
*/
class ucla_interleave : public gr_block
{
friend ucla_interleave_sptr ucla_make_interleave (size_t itemsize);
size_t d_itemsize;
ucla_interleave (size_t itemsize);
public:
~ucla_interleave ();
int work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
// gr_sync_block overrides these to assist work
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif /* INCLUDED_UCLA_INTERLEAVE_H */
|
tinyos-io/tinyos-3.x-contrib | diku/common/tools/compression/simple/simple_decomp.c | <reponame>tinyos-io/tinyos-3.x-contrib
#include <inttypes.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "../buffer.h"
#include <stdlib.h>
uint8_t membuffer[MEMBUFSIZE];
uint8_t *data;
uint8_t read_count;
uint16_t buffer;
static uint8_t read_bits(uint8_t len)
{
uint8_t res;
// Fill the buffer
while (read_count < len) {
buffer <<= 8;
buffer |= *data++;
read_count += 8;
}
res = (buffer >> (read_count - len)) & ((1 << len) - 1);
read_count -= len;
buffer &= (1 << read_count) - 1;
return res;
}
uint16_t bits_left()
{
uint16_t res = MEMBUFSIZE - (data - membuffer); // Amount of unread data;
/*
printf("Length: %d, data: %p, data_start: %p, diff: %d\n",
length, data, data_start, data - data_start);
*/
res *= 8;
res += read_count; // Bits read, but not outputted yet.
// printf("Bits left: %d\n", res);
return res;
}
void fill_buffer()
{
if (fread(membuffer, MEMBUFSIZE, 1, stdin) != 1) {
fprintf(stderr, "Error reading from stdin: %s\n",
strerror(errno));
exit(1);
}
read_count = 0;
buffer = 0;
data = membuffer;
}
#define SHORT_BITS 4
int16_t read_value()
{
int16_t res = 0;
res |= read_bits(4) << 8;
res |= read_bits(8);
if (res & 0x0800)
res |= 0xF000;
return res;
}
int16_t get_value(int16_t old_value)
{
uint8_t tmp = read_bits(1);
int16_t res = 0;
if (tmp) {
// fprintf(stderr, "Reading short\n");
res = read_bits(SHORT_BITS);
if (res & (1 << (SHORT_BITS - 1))) {
res |= ~((1 << SHORT_BITS) - 1);
}
res += old_value;
} else {
res = read_value();
}
// fprintf(stderr, "Returning %d\n", res);
return res;
}
int decompress_sample(int16_t *digi_x, int16_t *digi_y,
int16_t *digi_z, uint16_t *analog_x,
uint16_t *analog_y)
{
static int first = 1;
static int16_t last_vals[3];
if (first) {
first = 0;
fill_buffer();
*digi_x = last_vals[0] = read_value();
*digi_y = last_vals[1] = read_value();
*digi_z = last_vals[2] = read_value();
} else {
int i;
if (bits_left() < 3 * 13) {
fill_buffer();
}
for (i = 0; i < 3; i++) {
last_vals[i] = get_value(last_vals[i]);
}
*digi_x = last_vals[0];
*digi_y = last_vals[1];
*digi_z = last_vals[2];
}
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/cc2430/CC2430_CSP.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Copyright (c) 2007 University of Copenhagen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of University of Copenhagen nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
* OF COPENHAGEN OR ITS 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.
*/
/**
* Command Strobe Processor (CSP) instructions
*
* @author <NAME> <<EMAIL>>
*/
#define _CC2430_SNOP 0xC0
// Immediate command strobes
#define _CC2430_ISSTOP 0xFF
#define _CC2430_ISSTART 0xFE
#define _CC2430_ISTXCALN 0xE1
#define _CC2430_ISRXON 0xE2
#define _CC2430_ISTXON 0xE3
#define _CC2430_ISTXONCCA 0xE4
#define _CC2430_ISRFOFF 0xE5
#define _CC2430_ISFLUSHRX 0xE6
#define _CC2430_ISFLUSHTX 0xE7
#define _CC2430_ISACK 0xE8
#define _CC2430_ISACKPEND 0xE9
// Conditions _c_ for the RPT and SKIP instructions of the CSP
#define _CCA_TRUE 0x00
#define _RECEIVING 0x01
#define _MCU_BIT_IS_1 0x02
#define _COMMAND_BUF_EMPT 0x03
#define _REGX_IS_0 0x04
#define _REGY_IS_0 0x05
#define _REGZ_IS_0 0x06
#define _NO_OP 0x07
|
tinyos-io/tinyos-3.x-contrib | skel/tos/platforms/skel/hardware.h | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
#ifndef HARDWARE_H
#define HARDWARE_H
inline void __nesc_enable_interrupt() { }
inline void __nesc_disable_interrupt() { }
typedef uint8_t __nesc_atomic_t;
inline __nesc_atomic_t __nesc_atomic_start(void) @spontaneous() {
return 0;
}
inline void __nesc_atomic_end(__nesc_atomic_t x) @spontaneous() { }
#endif
|
tinyos-io/tinyos-3.x-contrib | tcd/powertossim-z/tinyos_files/tinyos-2.0.2/tos/lib/tossim/sim_csma.h | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>0
/*
* "Copyright (c) 2005 Stanford University. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
*
* Configuration parameters for a CSMA link.
*
* @author <NAME>
* @date Dec 10 2005
*/
// $Id: sim_csma.h,v 1.1 2014/11/26 19:31:35 carbajor Exp $
#ifndef SIM_CSMA_H_INCLUDED
#define SIM_CSMA_H_INCLUDED
#ifndef SIM_CSMA_INIT_HIGH
#define SIM_CSMA_INIT_HIGH 640
#endif
#ifndef SIM_CSMA_INIT_LOW
#define SIM_CSMA_INIT_LOW 20
#endif
#ifndef SIM_CSMA_HIGH
#define SIM_CSMA_HIGH 160
#endif
#ifndef SIM_CSMA_LOW
#define SIM_CSMA_LOW 20
#endif
#ifndef SIM_CSMA_SYMBOLS_PER_SEC
#define SIM_CSMA_SYMBOLS_PER_SEC 65536
#endif
#ifndef SIM_CSMA_BITS_PER_SYMBOL
#define SIM_CSMA_BITS_PER_SYMBOL 4
#endif
#ifndef SIM_CSMA_PREAMBLE_LENGTH
#define SIM_CSMA_PREAMBLE_LENGTH 12
#endif
#ifndef SIM_CSMA_MAX_ITERATIONS
#define SIM_CSMA_MAX_ITERATIONS 0
#endif
#ifndef SIM_CSMA_EXPONENT_BASE
#define SIM_CSMA_EXPONENT_BASE 1
#endif
#ifndef SIM_CSMA_MIN_FREE_SAMPLES
#define SIM_CSMA_MIN_FREE_SAMPLES 1
#endif
// 500 us ~= 32 symbols
#ifndef SIM_CSMA_RXTX_DELAY
#define SIM_CSMA_RXTX_DELAY 11
#endif
// 12 symbol delay + 11 bytes length * (2 bytes/symbol) = 34 symbols
#ifndef SIM_CSMA_ACK_TIME
#define SIM_CSMA_ACK_TIME 34
#endif
#ifdef __cplusplus
extern "C" {
#endif
int sim_csma_init_high();
int sim_csma_init_low();
int sim_csma_high();
int sim_csma_low();
int sim_csma_symbols_per_sec();
int sim_csma_bits_per_symbol();
int sim_csma_preamble_length(); // in symbols
int sim_csma_exponent_base();
int sim_csma_max_iterations();
int sim_csma_min_free_samples();
int sim_csma_rxtx_delay();
int sim_csma_ack_time(); // in symbols
void sim_csma_set_init_high(int val);
void sim_csma_set_init_low(int val);
void sim_csma_set_high(int val);
void sim_csma_set_low(int val);
void sim_csma_set_symbols_per_sec(int val);
void sim_csma_set_bits_per_symbol(int val);
void sim_csma_set_preamble_length(int val); // in symbols
void sim_csma_set_exponent_base(int val);
void sim_csma_set_max_iterations(int val);
void sim_csma_set_min_free_samples(int val);
void sim_csma_set_rxtx_delay(int val);
void sim_csma_set_ack_time(int val); // in symbols
#ifdef __cplusplus
}
#endif
#endif // SIM_TOSSIM_H_INCLUDED
|
tinyos-io/tinyos-3.x-contrib | diku/common/lib/compression/huffman_whole_diff.h | #define CODESET "../../tools/compression/huffman/huffman_whole_diff_codes.h"
#include "../../tools/compression/huffman/huffman_comp.c"
|
tinyos-io/tinyos-3.x-contrib | stanford-sing/s4-tinyos-2.x/tos/lib/interfaces/BVRSend.h | #ifndef BVRSEND_H
#define BVRSEND_H
#include "message.h"
#endif
|
tinyos-io/tinyos-3.x-contrib | tcd/powertossim-z/tinyos_files/tinyos-2.0.2/tos/chips/atm128/Atm128Power.h | // $Id: Atm128Power.h,v 1.1 2014/11/26 19:31:33 carbajor Exp $
/*
* Copyright (c) 2004-2005 Crossbow Technology, Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS BE LIABLE TO
* ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS.
*/
// @author <NAME> <<EMAIL>>
#ifndef _H_Atm128Power_h
#define _H_Atm128Power_h
//================== ATmega128 Power Management ==========================
/* MCU Control Register */
typedef struct
{
uint8_t ivce : 1; //!< Interrupt Vector Change Enable
uint8_t ivsel : 1; //!< Interrupt Vector Select
uint8_t stdby : 1; //!< Standby Enable (sm2)
uint8_t sm : 2; //!< Sleep Mode
uint8_t se : 1; //!< Sleep Enable
uint8_t srw10 : 1; //!< SRAM wait state enable
uint8_t srw : 1; //!< External SRAM enable
} Atm128_MCUCR_t;
#endif //_H_Atm128Power_h
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/stargate/rt_marshall.c |
#include "rt_marshall.h"
#include "rt_structs.h"
#include <stdint.h>
#include "sfaccess/tinystream.h"
int unmarshall_start(int cid, uint16_t *nodeid)
{
uint8_t dtype;
uint8_t data[2];
int result;
dbg(APP,"unmarsh,start:");
result = tinystream_read(cid, &dtype, 1);
if (result)
{
dbg(APP,"read_error getting type\n");
return -1;
}
if (dtype != TYPE_START)
{
dbg(APP,"type_error\n");
return -1;
}
result = tinystream_read(cid, data, 2);
if (result)
{
dbg(APP,"read_error getting data\n");
return -1;
}
*nodeid = ((uint16_t)data[0] << 8) + data[1];
dbg(APP,"nodeid = %i\n",*nodeid);
return 0;
}
int unmarshall_end(int cid, uint16_t *nodeid)
{
uint8_t dtype;
uint8_t data[2];
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_END)
{
return -1;
}
result = tinystream_read(cid, data, 2);
if (result)
{
return -1;
}
*nodeid = ((uint16_t)data[0] << 8) + data[1];
return 0;
}
int unmarshall_session(int cid, rt_data *_pdata)
{
int result;
dbg(APP,"umarsh_session:\n");
result = unmarshall_uint16_t(cid, &_pdata->sessionID);
if (result) return -1;
dbg(APP,"id=%i\n",_pdata->sessionID);
result = unmarshall_uint32_t(cid, &_pdata->starttime);
if (result) return -1;
dbg(APP,"t=%i\n",_pdata->starttime);
result = unmarshall_uint16_t(cid, &_pdata->weight);
if (result) return -1;
dbg(APP,"w=%i\n",_pdata->weight);
result = unmarshall_uint8_t(cid, &_pdata->minstate);
if (result) return -1;
dbg(APP,"ms=%i\n",_pdata->minstate);
result = unmarshall_bool(cid, &_pdata->wake);
if (result) return -1;
dbg(APP,"wake=%i\ndone.",_pdata->wake);
return 0;
}
int unmarshall_uint8_t(int cid, uint8_t *data)
{
uint8_t dtype;
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_UINT8)
{
return -1;
}
result = tinystream_read(cid, data, 1);
if (result)
{
return -1;
}
return 0;
}
int unmarshall_int8_t(int cid, int8_t *data)
{
uint8_t dtype;
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_INT8)
{
return -1;
}
result = tinystream_read(cid, data, 1);
if (result)
{
return -1;
}
return 0;
}
int unmarshall_uint16_t(int cid, uint16_t *data)
{
uint8_t dtype;
uint8_t buf[2];
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_UINT16)
{
return -1;
}
result = tinystream_read(cid, buf, 2);
if (result)
{
return -1;
}
*data = ((uint16_t)buf[0] << 8) + buf[1];
return 0;
}
int unmarshall_int16_t(int cid, int16_t *data)
{
uint8_t dtype;
uint8_t buf[2];
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_INT16)
{
return -1;
}
result = tinystream_read(cid, buf, 2);
if (result)
{
return -1;
}
*data = ((int16_t)buf[0] << 8) + buf[1];
return 0;
}
int unmarshall_uint32_t(int cid, uint32_t *data)
{
uint8_t dtype;
uint8_t buf[4];
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_UINT32)
{
return -1;
}
result = tinystream_read(cid, buf, 4);
if (result)
{
return -1;
}
*data = ((uint32_t)buf[0] << 24) + ((uint32_t)buf[1] << 16) +
((uint32_t)buf[2] << 8) + buf[3];
return 0;
}
int unmarshall_int32_t(int cid, int32_t *data)
{
uint8_t dtype;
uint8_t buf[4];
int result;
result = tinystream_read(cid, &dtype, 1);
if (result)
{
return -1;
}
if (dtype != TYPE_INT32)
{
return -1;
}
result = tinystream_read(cid, buf, 4);
if (result)
{
return -1;
}
*data = ((int32_t)buf[0] << 24) + ((int32_t)buf[1] << 16) +
((int32_t)buf[2] << 8) + buf[3];
return 0;
}
int unmarshall_bool(int cid, bool *data)
{
return unmarshall_int8_t(cid, data);
}
int unmarshall_request_t(int cid, request_t* data)
{
return MARSH_OK;
}
//************************************************
//MARSHALLING FUNCS
//************************************************/
int marshall_start(int cid, uint16_t nodeid)
{
uint8_t type = TYPE_START;
uint8_t buf[2];
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf[0] = nodeid >> 8;
buf[1] = nodeid && 0xFF;
result = tinystream_write(cid, buf, 2);
if (result) return -1;
return MARSH_OK;
}
int marshall_session(int cid, rt_data _pdata)
{
return MARSH_OK;
}
int marshall_int8_t(int cid, int8_t data)
{
uint8_t type = TYPE_INT8;
int8_t buf;
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf = data;
result = tinystream_write(cid, &buf, 1);
if (result) return -1;
return MARSH_OK;
}
int marshall_uint8_t(int cid, uint8_t data)
{
uint8_t type = TYPE_UINT8;
uint8_t buf;
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf = data;
result = tinystream_write(cid, &buf, 1);
if (result) return -1;
return MARSH_OK;
}
int marshall_int16_t(int cid, int16_t data)
{
uint8_t type = TYPE_INT16;
uint8_t buf[2];
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf[0] = data >> 8;
buf[1] = data && 0xFF;
result = tinystream_write(cid, buf, 2);
if (result) return -1;
return MARSH_OK;
}
int marshall_uint16_t(int cid, uint16_t data)
{
uint8_t type = TYPE_UINT16;
uint8_t buf[2];
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf[0] = data >> 8;
buf[1] = data && 0xFF;
result = tinystream_write(cid, buf, 2);
if (result) return -1;
return MARSH_OK;
}
int marshall_int32_t(int cid, int32_t data)
{
uint8_t type = TYPE_INT32;
uint8_t buf[4];
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf[0] = (data >> 24) && 0xFF;
buf[1] = (data >> 16) && 0xFF;
buf[2] = (data >> 8) && 0xFF;
buf[3] = data && 0xFF;
result = tinystream_write(cid, buf, 4);
if (result) return -1;
return MARSH_OK;
}
int marshall_uint32_t(int cid, uint32_t data)
{
uint8_t type = TYPE_UINT32;
uint8_t buf[4];
int result;
result = tinystream_write(cid, &type, 1);
if (result) return -1;
buf[0] = (data >> 24) && 0xFF;
buf[1] = (data >> 16) && 0xFF;
buf[2] = (data >> 8) && 0xFF;
buf[3] = data && 0xFF;
result = tinystream_write(cid, buf, 4);
if (result) return -1;
return MARSH_OK;
}
int marshall_char(int cid, char data)
{
return marshall_int8_t(cid,(int8_t)data);
}
int marshall_bool(int cid, bool data)
{
return marshall_int8_t(cid, (int8_t)data);
}
int marshall_request_t(int cid, request_t data)
{
return MARSH_OK;
}
|
tinyos-io/tinyos-3.x-contrib | antlab-polimi/dpcm_C/dpcmDecodeApp.c |
/**
* @author <NAME> <EMAIL>
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tinyos_macros.h"
#include "dpcm_decoder.h"
int main(int argc, char **argv)
{
char filename[1024];
uint frame_num=0;
if (argc > 2) {
sprintf(filename,argv[1]);
frame_num = (uint8_t) atoi(argv[2]);
} else {
printf("USAGE: ./dpcmDecodeApp input_file (uint8_t) frame_num\n");
return -1;
}
char* tmp_name = NULL;
char* tmp_name2 =NULL;
int name_size=0;
char output_name[1024];
// extract file name without path
tmp_name = strrchr(filename,'/');
//skip the / char
if(tmp_name == NULL)
tmp_name = filename;
else tmp_name = tmp_name +1;
printf("TMP: %s\n",tmp_name);
tmp_name2 = strrchr(tmp_name,'.');
// strcat(tmp_name,"\0");
name_size = tmp_name2-tmp_name;
strncpy(output_name,tmp_name,name_size);
printf("File name: %s\n",output_name);
//printf("Decode.\n");
dpcm_decode(filename,frame_num,output_name);
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/telos/adcs.h | <reponame>tinyos-io/tinyos-3.x-contrib
enum
{
TOS_ADC_A0_PORT = unique("ADCPort"),
TOSH_ACTUAL_ADC_A0_PORT = ASSOCIATE_ADC_CHANNEL (INPUT_CHANNEL_A0,
REFERENCE_VREFplus_AVss,
REFVOLT_LEVEL_1_5),
VREF = 2600,
TIMERRES = (uint32_t)32768
};
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/linuxsim/energymgr.h | <filename>eon/eon/src/runtime/linuxsim/energymgr.h
#ifndef __ENERGY_MGR_H
#define __ENERGY_MGR_H
#include "simworld.h"
#include <stdint.h>
#define EVAL_COUNT (3600 / ENERGY_TIME)
typedef struct
{
int energy_state;
double state_grade;
int64_t cost_of_reevaluation;
} energy_evaluation_struct_t;
void start_energy_mgr();
energy_evaluation_struct_t *reevaluate_energy_level(int64_t battery_state, int64_t battery_capacity);
void start_path(unsigned int session);
void end_path(unsigned int session, unsigned int pathid);
#endif
|
tinyos-io/tinyos-3.x-contrib | wsu/telosw/ADC/Sensor.h | <filename>wsu/telosw/ADC/Sensor.h
/*
enum {
ENERGY_REQUEST = 0,
BATTERY_REQUEST = 1,
LIGHT_REQUEST= 2,
ACC_REQUEST1 = 3,
ACC_REQUEST2 = 4,
ACC_REQUEST3 = 5,
};
*/
enum {
ACC_REQUEST1 = 0,
ACC_REQUEST2 = 1,
ACC_REQUEST3 = 2,
LIGHT_REQUEST= 3,
ENERGY_REQUEST = 4,
BATTERY_REQUEST = 5,
};
enum{
LIGHT_WAKEUP_THRESHOLD = 2,
LIGHT_SLEEP_THRESHOLD = 10,
//active mode
INST_BYTE_ADC0 = 0x10,
INST_BYTE_ADC1 = 0x90,
};
|
tinyos-io/tinyos-3.x-contrib | eon/apps/server-e/impl/stargate/ServerE.h |
#ifndef SERVERE_H_INCLUDED
#define SERVERE_H_INCLUDED
#include <stdint.h>
#include "runtime/rt_structs.h"
#define TOSH_DATA_LENGTH 60
#ifndef HEADER_LENGTH
#define HEADER_LENGTH 4
#endif
#ifndef DATA_HEADER_LENGTH
#define DATA_HEADER_LENGTH 8
#endif
#ifndef URL_LENGTH
#define URL_LENGTH (TOSH_DATA_LENGTH-HEADER_LENGTH)
#endif
#ifndef DATA_LENGTH
#define DATA_LENGTH (TOSH_DATA_LENGTH-DATA_HEADER_LENGTH)
#endif
typedef struct RequestMsg {
uint16_t src;
uint16_t suid; //chosen by connection requestor
uint8_t url[URL_LENGTH];
} RequestMsg;
typedef struct RedirectMsg {
uint16_t src;
uint16_t suid;
uint16_t port;
uint16_t delay_ms;
} RedirectMsg;
typedef struct MetaMsg {
uint16_t src;
uint16_t suid;
uint32_t size;
uint16_t error;
} MetaMsg;
typedef struct DataMsg {
uint16_t src;
uint16_t suid;
uint16_t segment;
uint16_t size;
uint8_t data[DATA_LENGTH];
} DataMsg;
typedef struct DataAck {
uint16_t src;
uint16_t suid;
uint16_t segment;
} DataAck;
enum {
AM_REQUESTMSG = 0x14,
AM_REDIRECTMSG = 0x15,
AM_METAMSG = 0x16,
AM_DATAMSG = 0x17,
AM_DATAACK = 0x18
};
typedef RequestMsg* RequestMsgPtr;
typedef RedirectMsg* RedirectMsgPtr;
typedef MetaMsg* MetaMsgPtr;
typedef DataMsg* DataMsgPtr;
typedef DataAck* DataAckPtr;
#endif
|
tinyos-io/tinyos-3.x-contrib | intelmote2/support/sdk/c/camera_cmd/camera_cmd.h | #ifndef CAMERA_CMD_H
#define CAMERA_CMD_H
#include <stdio.h>
#include <stdlib.h>
#include "sfsource.h"
int sf_fd;
enum {
IMG_TYPE_COL=1,
IMG_TYPE_JPG=2,
};
typedef struct{
int node_id;
int type;
int is_progressive;
int data_size;
int width;
int height;
} img_stat_t;
typedef struct {
int packet_size;
int num_packets;
unsigned char *is_received;
unsigned char *data;
} packet_buffer_t;
void comm_init(char* host, int port);
int send_img_cmd(int node_id, int type);
int receive_img(int session_id, int progressive, char *filename, void (*_callback)(int, char *));
int save_img_jpg(char *filebase, unsigned char *img_buffer, int width, int height, int is_color);
int receive_ctp_info_pckts();
int send_CTP_info_cmd(int node_id);
int is_parent_process();
const unsigned char *receive_ctp_info_packet();
#endif //CAMERA_CMD_H
|
tinyos-io/tinyos-3.x-contrib | osu/platforms/psi/hardware.h | #ifndef _H_hardware_h
#define _H_hardware_h
#include "msp430hardware.h"
//#include "MSP430ADC12.h"
//#include "CC2420Const.h"
//#include "AM.h"
/**
* Copyright (c) 2007 - The Ohio State University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs, and the author attribution appear in all copies of this
* software.
*
* IN NO EVENT SHALL THE OHIO STATE UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE OHIO STATE
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE OHIO STATE UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE OHIO STATE UNIVERSITY HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
@author
<NAME> <<EMAIL>>
<NAME> <<EMAIL>>
$Date: 2007/10/20 18:16:32 $
Porting TinyOS to Intel PSI motes
*/
/******************************************
Port 1
*******************************************/
TOSH_ASSIGN_PIN(SPI_CS0, 1, 7);
TOSH_ASSIGN_PIN(GPIO_17, 1, 6);
TOSH_ASSIGN_PIN(IM2_INTR, 1, 5);
TOSH_ASSIGN_PIN(RED_LED, 1, 4);
TOSH_ASSIGN_PIN(SPI_CS1_INT, 1, 3);
TOSH_ASSIGN_PIN(RADIO_SFD, 1, 2);
TOSH_ASSIGN_PIN(PROG_RX, 1, 1);
TOSH_ASSIGN_PIN(RADIO_FIFO, 1, 0);
//TOSH_ASSIGN_PIN(RADIO_GIO0, 1, 0);
/******************************************
Port 2
*******************************************/
TOSH_ASSIGN_PIN(RADIO_CCA, 2, 7);
//TOSH_ASSIGN_PIN(RADIO_GIO1, 2, 7);
TOSH_ASSIGN_PIN(RADIO_FIFOP, 2, 6);
TOSH_ASSIGN_PIN(RADIO_ROSC, 2, 5);
TOSH_ASSIGN_PIN(SPI_NIRQ, 2, 4);
TOSH_ASSIGN_PIN(YELLOW_LED, 2, 3);
TOSH_ASSIGN_PIN(PROG_TX, 2, 2);
TOSH_ASSIGN_PIN(GPIO_25_INT, 2, 1);
TOSH_ASSIGN_PIN(GPIO_24_INT, 2, 0);
/******************************************
Port 3
*******************************************/
TOSH_ASSIGN_PIN(IM2_FF_RXD, 3, 7);
TOSH_ASSIGN_PIN(IM2_FF_TXD, 3, 6);
TOSH_ASSIGN_PIN(IM2_STD_RXD, 3, 5);
TOSH_ASSIGN_PIN(IM2_STD_TXD, 3, 4);
TOSH_ASSIGN_PIN(COMM_SPI_I2C_CLK, 3, 3);
TOSH_ASSIGN_PIN(RADIO_SO, 3, 2);
TOSH_ASSIGN_PIN(COMM_SPI_I2C_DATA, 3, 1);
TOSH_ASSIGN_PIN(RADIO_CSN, 3, 0);
/******************************************
Port 4
*******************************************/
TOSH_ASSIGN_PIN(ONEWIRE, 4, 7);
TOSH_ASSIGN_PIN(IM2_SSP2_SFRM, 4, 6);
TOSH_ASSIGN_PIN(ACCEL_SLEEP_N, 4, 5);
TOSH_ASSIGN_PIN(IM2_FF_RTS, 4, 4);
TOSH_ASSIGN_PIN(IM2_FF_CTS, 4, 3);
TOSH_ASSIGN_PIN(IM2_RESET, 4, 2);
TOSH_ASSIGN_PIN(RADIO_SFD_R, 4, 1);
TOSH_ASSIGN_PIN(I2C_EN, 4, 0);
/******************************************
Port 5
*******************************************/
TOSH_ASSIGN_PIN(RADIO_RESET, 5, 7);
TOSH_ASSIGN_PIN(RADIO_VREF, 5, 6);
TOSH_ASSIGN_PIN(IM2_GPIO_94, 5, 5);
TOSH_ASSIGN_PIN(GREEN_LED, 5, 4);
TOSH_ASSIGN_PIN(UCLK0, 5, 3);
TOSH_ASSIGN_PIN(SOMI0, 5, 2);
TOSH_ASSIGN_PIN(SIMO0, 5, 1);
TOSH_ASSIGN_PIN(SPI_CS1, 5, 0);
/******************************************
Port 6
*******************************************/
TOSH_ASSIGN_PIN(TP45, 6, 7);
TOSH_ASSIGN_PIN(SPI_CS2, 6, 6);
TOSH_ASSIGN_PIN(ADC5, 6, 5);
TOSH_ASSIGN_PIN(ADC4, 6, 4);
TOSH_ASSIGN_PIN(ADC3, 6, 3);
TOSH_ASSIGN_PIN(HUM_SDA, 6, 2);
TOSH_ASSIGN_PIN(HUM_SCL, 6, 1);
TOSH_ASSIGN_PIN(HUM_PWR, 6, 0);
// No external FLASH in the PSI motes, so it doesn't really matter
TOSH_ASSIGN_PIN(FLASH_PWR, 6, 7);
TOSH_ASSIGN_PIN(FLASH_CS, 6, 7);
TOSH_ASSIGN_PIN(FLASH_HOLD, 6, 7);
//so is the humidity sensor
void HUMIDITY_MAKE_CLOCK_OUTPUT() { TOSH_MAKE_HUM_SCL_OUTPUT(); }
void HUMIDITY_MAKE_CLOCK_INPUT() { TOSH_MAKE_HUM_SCL_INPUT(); }
void HUMIDITY_CLEAR_CLOCK() { TOSH_CLR_HUM_SCL_PIN(); }
void HUMIDITY_SET_CLOCK() { TOSH_SET_HUM_SCL_PIN(); }
void HUMIDITY_MAKE_DATA_OUTPUT() { TOSH_MAKE_HUM_SDA_OUTPUT(); }
void HUMIDITY_MAKE_DATA_INPUT() { TOSH_MAKE_HUM_SDA_INPUT(); }
void HUMIDITY_CLEAR_DATA() { TOSH_CLR_HUM_SDA_PIN(); }
void HUMIDITY_SET_DATA() { TOSH_SET_HUM_SDA_PIN(); }
char HUMIDITY_GET_DATA() { return TOSH_READ_HUM_SDA_PIN(); }
#define HUMIDITY_TIMEOUT_MS 30
#define HUMIDITY_TIMEOUT_TRIES 20
enum {
// Sensirion Humidity addresses and commands
TOSH_HUMIDITY_ADDR = 5,
TOSH_HUMIDTEMP_ADDR = 3,
TOSH_HUMIDITY_RESET = 0x1E
};
// need to undef atomic inside header files or nesC ignores the directive
#undef atomic
#endif // _H_hardware_h
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/interface/tun_dev.h | /*
* "Copyright (c) 2008 The Regents of the University of California.
* All rights reserved."
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
/*
* Copyright (c) 2007 <NAME>
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER 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.
*/
#ifndef _TUN_DEV_H
#define _TUN_DEV_H
#include <lib6lowpan/ip.h>
int tun_open(char *dev);
int tun_close(int fd, char *dev);
int tun_setup(char *dev, ieee154_laddr_t addr);
// int tun_write(int fd, struct split_ip_msg *msg);
int tun_read(int fd, char *buf, int len);
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/registry.h | <gh_stars>1-10
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __USB_REGISTRY_H__
#define __USB_REGISTRY_H__
#include <windows.h>
#include <setupapi.h>
#define LIBUSB_DRIVER_NAME_NT "libusb0"
#define LIBUSB_DRIVER_NAME_9X "libusb0.sys"
typedef int bool_t;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!(FALSE))
#endif
#define REGISTRY_BUF_SIZE 512
bool_t usb_registry_is_nt(void);
bool_t usb_registry_restart_device(HDEVINFO dev_info,
SP_DEVINFO_DATA *dev_info_data);
bool_t usb_registry_stop_device(HDEVINFO dev_info,
SP_DEVINFO_DATA *dev_info_data);
bool_t usb_registry_start_device(HDEVINFO dev_info,
SP_DEVINFO_DATA *dev_info_data);
bool_t usb_registry_get_property(DWORD which, HDEVINFO dev_info,
SP_DEVINFO_DATA *dev_info_data,
char *buf, int size);
bool_t usb_registry_set_property(DWORD which, HDEVINFO dev_info,
SP_DEVINFO_DATA *dev_info_data,
char *buf, int size);
bool_t usb_registry_restart_all_devices(void);
bool_t usb_registry_insert_class_filter(void);
bool_t usb_registry_remove_class_filter(void);
bool_t usb_registry_remove_device_filter(void);
void usb_registry_stop_libusb_devices(void);
void usb_registry_start_libusb_devices(void);
bool_t usb_registry_match(HDEVINFO dev_info, SP_DEVINFO_DATA *dev_info_data);
bool_t usb_registry_get_mz_value(const char *key, const char *value,
char *buf, int size);
bool_t usb_registry_set_mz_value(const char *key, const char *value,
char *buf, int size);
int usb_registry_mz_string_size(const char *src);
char *usb_registry_mz_string_find(const char *src, const char *str);
char *usb_registry_mz_string_find_sub(const char *src, const char *str);
bool_t usb_registry_mz_string_insert(char *src, const char *str);
bool_t usb_registry_mz_string_remove(char *src, const char *str);
void usb_registry_mz_string_lower(char *src);
#endif
|
tinyos-io/tinyos-3.x-contrib | antlab-polimi/dpcm_C/codeZeros.h | static inline uint32_t codeZeros(uint8_t *dataIn, uint8_t *dataOut, uint32_t dataSize,
uint32_t bandwidth)
{
uint32_t i;
uint32_t idx=0;
uint16_t zeroSeqLength=0, numZeroFreqs=0;
for (i=0; (i<dataSize && idx<(bandwidth-3)); i++)
{
if (dataIn[i]==0)
{
if (zeroSeqLength++==0xFF)
{
++numZeroFreqs;
zeroSeqLength=1;
}
}
else
{
if (zeroSeqLength>0)
{
while (numZeroFreqs>0)
{
numZeroFreqs--;
dataOut[idx++] = 0;
dataOut[idx++] = 0xFF;
}
dataOut[idx++] = 0;
dataOut[idx++] = zeroSeqLength;
zeroSeqLength = 0;
}
dataOut[idx++] = dataIn[i];
}// else
}
// doppio zero, indica zeri fino alla fine del file
dataOut[idx++]=0;
dataOut[idx++]=0;
return idx;//*/
}
static inline uint32_t codeDC(uint8_t *dataIn, uint8_t *dataOut, uint16_t dataSize)
{
uint16_t i;
dataOut[0]=dataIn[0];
for (i=1; i<dataSize; i++)
{
dataOut[i]=dataIn[i-1]-dataIn[i];
}
return dataSize;
}
|
tinyos-io/tinyos-3.x-contrib | ethz/snpk/apps/DSNBoot/msp430baudrates.h | //$Id: msp430baudrates.h,v 1.1 2007/02/23 14:51:45 rlim Exp $
//@author <NAME> <<EMAIL>>
#ifndef _H_msp430baudrates_h
#define _H_msp430baudrates_h
/**
Parameters for HPLUSARTControl.setClockRate() that generate some standard baud rates.
Usage is setClockRate(UBR_CLOCK_BAUDRATE, UMCTL_CLOCK_BAUDRATE), see HPLUARTM.nc for an example.
The calculations were performed using the msp-uart.pl script:
# msp-uart.pl -- calculates the uart registers for MSP430
#
# Copyright (C) 2002 - <NAME> - pzn dot debian dot org
**/
enum {
//Using ACLK=32768Hz
UBR_ACLK_1200=0x001B, UMCTL_ACLK_1200=0x94,
UBR_ACLK_1800=0x0012, UMCTL_ACLK_1800=0x84,
UBR_ACLK_2400=0x000D, UMCTL_ACLK_2400=0x6D,
UBR_ACLK_4800=0x0006, UMCTL_ACLK_4800=0x77,
UBR_ACLK_9600=0x0003, UMCTL_ACLK_9600=0x29,
//Using SMCLK=1048576Hz
UBR_SMCLK_1200=0x0369, UMCTL_SMCLK_1200=0x7B,
UBR_SMCLK_1800=0x0246, UMCTL_SMCLK_1800=0x55,
UBR_SMCLK_2400=0x01B4, UMCTL_SMCLK_2400=0xDF,
UBR_SMCLK_4800=0x00DA, UMCTL_SMCLK_4800=0xAA,
UBR_SMCLK_9600=0x006D, UMCTL_SMCLK_9600=0x44,
UBR_SMCLK_19200=0x0036, UMCTL_SMCLK_19200=0xB5,
UBR_SMCLK_38400=0x001B, UMCTL_SMCLK_38400=0x94,
UBR_SMCLK_57600=0x0012, UMCTL_SMCLK_57600=0x84,
UBR_SMCLK_76800=0x000D, UMCTL_SMCLK_76800=0x6D,
UBR_SMCLK_115200=0x0009, UMCTL_SMCLK_115200=0x10,
UBR_SMCLK_230400=0x0004, UMCTL_SMCLK_230400=0x55,
};
#endif//_H_msp430baudrates_h
|
tinyos-io/tinyos-3.x-contrib | tinymulle/tos/chips/m16c62p/timer/M16c62pTimer.h | <filename>tinymulle/tos/chips/m16c62p/timer/M16c62pTimer.h
#ifndef __M16C62PTIMER_H__
#define __M16C62PTIMER_H__
/*
* Precations when using Timer A1 and Timer A2.
* Read hardware manual page 139.
*
* Precations when using Timer B2.
* Read hardware manual page 156.
*/
enum
{
TMR_TIMER_MODE,
TMR_COUNTER_MODE,
TMR_ONE_SHOT_MODE
};
/* Timer mode */
typedef struct
{
uint8_t output_pulse:1; // TAiMR: MR0 . TAiOUT pin is a pulse output pin if bit is set. No effect on TimerB.
uint8_t gate_func:2; // TAiMR: MR1, MR2 [ NO_GATE | TAiIN_LOW | TAiIN_HIGH ] . No effect on TimerB.
uint8_t count_src:2; // T*iMR: TCK0, TCK1 [ F1_2 | F8 | F32 | FC32 ]
} st_timer;
// "gate_func"
enum
{
M16C_TMR_TMR_GF_NO_GATE = 0x0,
M16C_TMR_TMR_GF_TAiIN_LOW = 0x2,
M16C_TMR_TMR_GF_TAiIN_HIGH = 0x3
};
/* TimerA Counter mode */
typedef struct
{
uint8_t two_phase_pulse_mode:1; // Use two phase mode, only availible for timers A2, A3 and A4, will be ignored else.
// Flags active in two-phase mode
uint8_t two_phase_processing:1; // TAiMR: TCK1 [ NORMAL | MULTIPLY_BY_4 ] Only active for Timer A3.
// Flags active when not using two-phase mode.
uint8_t output_pulse:1; // TAIMR: MR0 . TAiOUT is N-channel open drain output when bit is set.
uint8_t count_rising_edge:1; // TAiMR: MR1 . Active when event_trigger = TAiIN
uint8_t up_down_switch:1; // TAiMR: MR2 [ UDF | TAiOUT ]
uint8_t up_count:1; // UDF: TAiUD . Active when up_down_switch = UDF
uint8_t event_source:2; // ONSF/TRGS: TAiTG [ TAiIN | TB2 | TA_PREV | TA_NEXT ]
// Flags active in both modes
uint8_t operation_type:1; // TAiMR: TCK0 [ RELOAD | FREE_RUN ]
} sta_counter;
// "operation_type"
enum
{
M16C_TMR_CTR_OT_RELOAD = 0x0,
M16C_TMR_CTR_OT_FREE_RUN = 0x1
};
// "up_down_switch"
enum
{
M16C_TMR_CTR_UDS_UDF = 0x0,
M16C_TMR_CTR_UDS_TAiOUT = 0x1
};
// "two_phase_processing"
enum
{
M16C_TMR_CTR_TPP_NORMAL = 0x0,
M16C_TMR_CTR_TPP_MULTIPLY_BY_4 = 0x1
};
/* TimerA one shot mode. */
typedef struct
{
uint8_t output_pulse:1; // TAiMR: MR0 . TAiOUT pin is a pulse output pin if bit is set.
uint8_t ext_trigger_rising_edge:1;// TAiMR: MR1 . Trigger on rising edge of input signal to TAiIN if bit is set. Active when TAiTG = 00b.
uint8_t trigger:1; // TAiMR: MR2 [ TAiOS | TAiTG ]
uint8_t count_src:2; // TAiMR: TCK0, TCK1 [ F1_2 | F8 | F32 | FC32 ]
uint8_t TAiTG_trigger_source:2; // ONSF/TRGS: TAiTG [ TAiIN | TB2 | TA_PREV | TA_NEXT ]. Active if trigger = TAiTG
} sta_one_shot;
// "trigger"
enum
{
M16C_TMRA_OS_T_TAiOS = 0x00,
M16C_TMRA_OS_T_TAiTG = 0x01
};
/* TimerB Counter mode. */
typedef struct
{
uint8_t count_polarity:2; // TBiMR: MR0, MR1 [ EXT_FALLING_EDGE | EXT_RISING_EDGE | EXT_BOTH ] . Effective if event_source = TBiIN.
uint8_t event_source:1; // TBiMR: TCK1 [ TBiIN | TBj ] . j = i-1, except j = 2 if i = 0 and j = 5 if i = 3.
} stb_counter;
// "counter_polarity"
enum
{
M16C_TMRB_CTR_CP_EXT_FALLING_EDGE = 0x0,
M16C_TMRB_CTR_CP_EXT_RISING_EDGE = 0x1,
M16C_TMRB_CTR_CP_EXT_BOTH = 0x2,
};
// "event_source"
enum
{
M16C_TMRB_CTR_ES_TBiIN = 0x0,
M16C_TMRB_CTR_ES_TBj = 0x1
};
/* Common settings */
// TimerA One Shot "TAiTG_trigger_source" , TimerA Counter "event_source"
enum
{
M16C_TMRA_TES_TAiIN = 0x0,
M16C_TMRA_TES_TB2 = 0x1,
M16C_TMRA_TES_TA_PREV = 0x2,
M16C_TMRA_TES_TA_NEXT = 0x3
};
// TimerA/B, TimerA One Shot : "count_src"
enum
{
M16C_TMR_CS_F1_2 = 0x0,
M16C_TMR_CS_F8 = 0x1,
M16C_TMR_CS_F32 = 0x2,
M16C_TMR_CS_FC32 = 0x3
};
#endif // __M16C62PTMR_H__
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/stargatehelper/pgm_util.h | #ifndef _PGM_UTIL_H_
#define _PGM_UTIL_H_
#if defined(PLATFORM_PC)
#define PROGMEM
inline int32_t read_pgm_int32(int32_t* pptr)
{
int32_t result;
memcpy((void*)&result, pptr, sizeof(int32_t));
return result;
}
inline int16_t read_pgm_int16(int16_t* pptr)
{
int16_t result;
memcpy(&result, pptr, sizeof(int16_t));
return result;
}
inline int8_t read_pgm_int8(int8_t* pptr)
{
int8_t result;
memcpy(&result, pptr, sizeof(int8_t));
return result;
}
#else
inline int32_t read_pgm_int32(int32_t* pptr)
{
int32_t result;
memcpy_P((void*)&result, pptr, sizeof(int32_t));
return result;
}
inline int16_t read_pgm_int16(int16_t* pptr)
{
int16_t result;
memcpy_P(&result, pptr, sizeof(int16_t));
return result;
}
inline int8_t read_pgm_int8(int8_t* pptr)
{
int8_t result;
memcpy_P(&result, pptr, sizeof(int8_t));
return result;
}
#endif
#endif
|
tinyos-io/tinyos-3.x-contrib | uni_valencia/Gatherer/GathererReport.h | /* Copyright (c) 2011 Universitat de Valencia.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) 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.
*
* For additional information see http://www.uv.es/varimos/
*
*/
/**
* @author <NAME>
*/
#ifndef _GATHERERREPORT_H
#define _GATHERERREPORT_H
enum{
INTERVALO_TIEMPO_MEDIDAS = 30720UL,
NUM_MEDIDAS = 20, //20
TAM_BUFFER = 72, //12 horas de datos
RESET = 44298240UL, //12 horas y 1 minuto
};
typedef nx_struct gatherer_report {
nx_uint32_t temperatura;
nx_uint32_t humedad;
nx_uint16_t voltaje;
nx_uint8_t total_medidas;
nx_uint8_t num_sec;
} gatherer_report;
typedef nx_struct gatherer_packet{
nx_uint16_t id_nodo;
nx_uint8_t anterior;
nx_uint8_t num_medias;
nx_uint16_t parent;
nx_uint16_t etx;
nx_struct gatherer_report payload[6];
} gatherer_packet;
#endif
|
tinyos-io/tinyos-3.x-contrib | rincon/tos/lib/industrialCtp/Ctp.h |
/*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS 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.
*/
/*
* Header file that declares the AM types, message formats, and
* constants for the TinyOS reference implementation of the
* Collection Tree Protocol (CTP), as documented in TEP 123.
*
* @author <NAME>
*/
#ifndef CTP_H
#define CTP_H
#warning "Using IndustrialCtp"
#include "AM.h"
#define UQ_CTP_CLIENT "CtpSenderC.CollectId"
typedef nx_uint8_t nx_ctp_options_t;
typedef uint8_t ctp_options_t;
typedef uint8_t collection_id_t;
typedef nx_uint8_t nx_collection_id_t;
/** Number of entries in the neighbor table */
#ifndef NEIGHBOR_TABLE_SIZE
#define NEIGHBOR_TABLE_SIZE 20
#endif
#ifndef FORWARD_COUNT
#define FORWARD_COUNT 12
#endif
#ifndef CACHE_SIZE
#define CACHE_SIZE 5
#endif
/*
* These timings are in milliseconds, and are used by
* ForwardingEngineP. Each pair of values represents a range of
* [OFFSET - (OFFSET + WINDOW)]. The ForwardingEngine uses these
* values to determine when to send the next packet after an
* event. FAIL refers to a send fail (an error from the radio below),
* NOACK refers to the previous packet not being acknowledged,
* OK refers to an acknowledged packet, and LOOPY refers to when
* a loop is detected.
*
* The default value works well with networks implementing low power listening.
* If you are not implementing low power listening, try a value of 4 for
* CC2420 radios.
*/
#ifndef FORWARD_PACKET_TIME
#define FORWARD_PACKET_TIME 1024
#endif
enum {
SENDDONE_FAIL_OFFSET = 512,
SENDDONE_NOACK_OFFSET = FORWARD_PACKET_TIME << 2,
SENDDONE_OK_OFFSET = FORWARD_PACKET_TIME << 2,
LOOPY_OFFSET = FORWARD_PACKET_TIME << 4,
SENDDONE_FAIL_WINDOW = SENDDONE_FAIL_OFFSET - 1,
LOOPY_WINDOW = LOOPY_OFFSET - 1,
SENDDONE_NOACK_WINDOW = SENDDONE_NOACK_OFFSET - 1,
SENDDONE_OK_WINDOW = SENDDONE_OK_OFFSET - 1,
CONGESTED_WAIT_OFFSET = FORWARD_PACKET_TIME << 2,
CONGESTED_WAIT_WINDOW = CONGESTED_WAIT_OFFSET - 1,
};
/*
* The number of times the ForwardingEngine will try to
* transmit a packet before giving up if the link layer
* supports acknowledgments. If the link layer does
* not support acknowledgments it sends the packet once.
*/
enum {
MAX_RETRIES = 30
};
enum {
// AM types:
AM_CTP_DATA = 23,
AM_CTP_ROUTING = 24,
AM_CTP_DEBUG = 25,
// CTP Options:
CTP_OPT_PULL = 0x80, // TEP 123: P field
CTP_OPT_ECN = 0x40, // TEP 123: C field
};
typedef nx_struct {
nx_ctp_options_t options;
nx_uint8_t thl;
nx_uint16_t etx;
nx_am_addr_t origin;
nx_uint8_t originSeqNo;
nx_collection_id_t type;
nx_uint8_t data[0];
} ctp_data_header_t;
typedef nx_struct {
nx_ctp_options_t options;
nx_am_addr_t parent;
nx_uint16_t etx;
nx_uint8_t data[0];
} ctp_routing_header_t;
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.