fixes for the wsn430

fixed vtimer for the msp430
added spi module for the wsn430 v1.3b
changed some variables to uintXX_t, fixes overflow on msp430
This commit is contained in:
Milan Babel 2013-05-24 02:20:54 +02:00
parent 01f2cb2115
commit edb34b73c0
9 changed files with 47 additions and 31 deletions

View File

@ -9,12 +9,12 @@
#ifndef __QUEUE_H #ifndef __QUEUE_H
#define __QUEUE_H #define __QUEUE_H
#include "queue.h" #include <stdlib.h>
typedef struct queue_node_t { typedef struct queue_node_t {
struct queue_node_t *next; struct queue_node_t *next;
unsigned int data; unsigned int data;
unsigned int priority; uint32_t priority;
} queue_node_t; } queue_node_t;
queue_node_t* queue_remove_head(queue_node_t* root); queue_node_t* queue_remove_head(queue_node_t* root);

View File

@ -89,12 +89,12 @@ void queue_print(queue_node_t* node) {
printf("queue:\n"); printf("queue:\n");
while (node->next != NULL) { while (node->next != NULL) {
node = node->next; node = node->next;
printf("Data: %u Priority: %u\n", node->data, node->priority); printf("Data: %u Priority: %lu\n", node->data, node->priority);
} }
} }
void queue_print_node(queue_node_t *node) { void queue_print_node(queue_node_t *node) {
printf("Data: %u Priority: %u Next: %u\n", (unsigned int)node->data, node->priority, (unsigned int)node->next); printf("Data: %u Priority: %lu Next: %u\n", (unsigned int)node->data, node->priority, (unsigned int)node->next);
} }
/* /*

View File

@ -36,6 +36,8 @@ and the mailinglist (subscription via web site)
void (*int_handler)(int); void (*int_handler)(int);
extern void timerA_init(void); extern void timerA_init(void);
uint16_t overflow_interrupt[ARCH_MAXTIMERS+1];
uint16_t timer_round;
static void TA0_disable_interrupt(short timer) { static void TA0_disable_interrupt(short timer) {
volatile unsigned int *ptr = &TA0CCTL0 + (timer); volatile unsigned int *ptr = &TA0CCTL0 + (timer);
@ -67,12 +69,13 @@ void TA0_unset(short timer) {
} }
unsigned long hwtimer_arch_now() { unsigned long hwtimer_arch_now() {
return TA0R; return ((uint32_t)timer_round << 16)+TA0R;
} }
void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu) { void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu) {
timerA_init(); timerA_init();
int_handler = handler; int_handler = handler;
TA0_enable_interrupt(0);
} }
void hwtimer_arch_enable_interrupt(void) { void hwtimer_arch_enable_interrupt(void) {
@ -88,12 +91,14 @@ void hwtimer_arch_disable_interrupt(void) {
} }
void hwtimer_arch_set(unsigned long offset, short timer) { void hwtimer_arch_set(unsigned long offset, short timer) {
unsigned int value = hwtimer_arch_now() + offset; unsigned long value = hwtimer_arch_now() + offset;
hwtimer_arch_set_absolute(value, timer); hwtimer_arch_set_absolute(value, timer);
} }
void hwtimer_arch_set_absolute(unsigned long value, short timer) { void hwtimer_arch_set_absolute(unsigned long value, short timer) {
TA0_set(value,timer); uint16_t small_value = value % 0xFFFF;
overflow_interrupt[timer] = (uint16_t)(value >> 16);
TA0_set(small_value,timer);
} }
void hwtimer_arch_unset(short timer) { void hwtimer_arch_unset(short timer) {

View File

@ -51,6 +51,6 @@ and the mailinglist (subscription via web site)
#endif #endif
#define HWTIMER_SPEED 32768 #define HWTIMER_SPEED 32768
#define HWTIMER_MAXTICKS (0xFFFF) #define HWTIMER_MAXTICKS (0xFFFFFFFF)
#endif // __HWTIMER_CPU_H #endif // __HWTIMER_CPU_H

View File

@ -7,17 +7,20 @@ static uint32_t ticks = 0;
extern void (*int_handler)(int); extern void (*int_handler)(int);
extern void TA0_unset(short timer); extern void TA0_unset(short timer);
extern uint16_t overflow_interrupt[ARCH_MAXTIMERS+1];
extern uint16_t timer_round;
void timerA_init(void) void timerA_init(void)
{ {
ticks = 0; // Set tick counter value to 0 ticks = 0; // Set tick counter value to 0
timer_round = 0; // Set to round 0
TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set ACLK TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set ACLK
TA0CTL &= ~TAIFG; // Clear the IFG TA0CTL &= ~TAIFG; // Clear the IFG
TA0CTL &= ~TAIE; // Clear the IFG TA0CTL &= ~TAIE; // Clear the IFG
volatile unsigned int *ccr = &TA0CCR0;
volatile unsigned int *ctl = &TA0CCTL0;
for (int i = 0; i < ARCH_MAXTIMERS; i++) { for (int i = 0; i < ARCH_MAXTIMERS; i++) {
volatile unsigned int *ccr = &TA0CCR0 + (i);
volatile unsigned int *ctl = &TA0CCTL0 + (i);
*ccr = 0; *ccr = 0;
*ctl &= ~(CCIFG); *ctl &= ~(CCIFG);
*ctl &= ~(CCIE); *ctl &= ~(CCIE);
@ -27,11 +30,11 @@ void timerA_init(void)
interrupt(TIMERA0_VECTOR) __attribute__ ((naked)) timer_isr_ccr0(void) { interrupt(TIMERA0_VECTOR) __attribute__ ((naked)) timer_isr_ccr0(void) {
__enter_isr(); __enter_isr();
//TA0_unset(0);
TA0_unset(0); //int_handler(0);
int_handler(0); timer_round += 1;
__exit_isr(); __exit_isr();
} }
interrupt(TIMERA1_VECTOR) __attribute__ ((naked)) timer_isr(void) { interrupt(TIMERA1_VECTOR) __attribute__ ((naked)) timer_isr(void) {
@ -42,13 +45,15 @@ interrupt(TIMERA1_VECTOR) __attribute__ ((naked)) timer_isr(void) {
if (taiv & TAIFG) { if (taiv & TAIFG) {
// puts("msp430/hwtimer_cpu TAIFG set!"); // puts("msp430/hwtimer_cpu TAIFG set!");
// TA0CTL &= ~TAIFG; // TA0CTL &= ~TAIFG;
// ticks += 0xFFFF; // timer_round += 1;
} else { } else {
short timer = (taiv/2); short timer = (taiv/2);
TA0_unset(timer); if(overflow_interrupt[timer] == timer_round)
int_handler(timer); {
TA0_unset(timer);
int_handler(timer);
}
} }
__exit_isr(); __exit_isr();
} }

View File

@ -8,6 +8,9 @@ endif
ifneq (,$(findstring msba2,$(BOARD))) ifneq (,$(findstring msba2,$(BOARD)))
DIRS += spi DIRS += spi
endif endif
ifneq (,$(findstring wsn430-v1_3b,$(BOARD)))
DIRS += spi
endif
all: $(BINDIR)$(MODULE).a all: $(BINDIR)$(MODULE).a
@for i in $(DIRS) ; do $(MAKE) -C $$i ; done ; @for i in $(DIRS) ; do $(MAKE) -C $$i ; done ;

View File

@ -34,7 +34,7 @@ create_hashtable(uint32_t minsize,
struct hashtable *h; struct hashtable *h;
unsigned int pindex, size = primes[0]; unsigned int pindex, size = primes[0];
/* Check requested hashtable isn't too large */ /* Check requested hashtable isn't too large */
if (minsize > (1u << 30)) return NULL; if (minsize > (1UL << 30)) return NULL;
/* Enforce size as prime */ /* Enforce size as prime */
for (pindex=0; pindex < prime_table_length; pindex++) { for (pindex=0; pindex < prime_table_length; pindex++) {
if (primes[pindex] > minsize) { size = primes[pindex]; break; } if (primes[pindex] > minsize) { size = primes[pindex]; break; }
@ -59,7 +59,7 @@ hash(struct hashtable *h, void *k)
{ {
/* Aim to protect against poor hash functions by adding logic here /* Aim to protect against poor hash functions by adding logic here
* - logic taken from java 1.4 hashtable source */ * - logic taken from java 1.4 hashtable source */
unsigned int i = h->hashfn(k); uint32_t i = h->hashfn(k);
i += ~(i << 9); i += ~(i << 9);
i ^= ((i >> 14) | (i << 18)); /* >>> */ i ^= ((i >> 14) | (i << 18)); /* >>> */
i += (i << 4); i += (i << 4);

View File

@ -69,7 +69,7 @@ void _cc110x_ng_send_handler(char *pkt) {
p.dst = addr; p.dst = addr;
mesg.type = SND_PKT; mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd; mesg.content.ptr = (char*) &tcmd;
printf("[cc110x] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data); printf("[cc110x] Sending packet of length %u to %u: %s\n", p.length, p.dst, (char*) p.data);
msg_send_receive(&mesg, &mesg, transceiver_pid); msg_send_receive(&mesg, &mesg, transceiver_pid);
response = mesg.content.value; response = mesg.content.value;
printf("[cc110x] Packet sent: %lu\n", response); printf("[cc110x] Packet sent: %lu\n", response);

View File

@ -13,11 +13,11 @@
#include <debug.h> #include <debug.h>
#define VTIMER_THRESHOLD 20U #define VTIMER_THRESHOLD 20UL
#define VTIMER_BACKOFF 10U #define VTIMER_BACKOFF 10UL
#define SECONDS_PER_TICK (4096U) #define SECONDS_PER_TICK (4096U)
#define MICROSECONDS_PER_TICK (4096U * 1000000) #define MICROSECONDS_PER_TICK (4096UL * 1000000)
void vtimer_callback(void *ptr); void vtimer_callback(void *ptr);
void vtimer_tick(void *ptr); void vtimer_tick(void *ptr);
@ -58,16 +58,16 @@ static int update_shortterm(void) {
hwtimer_next_absolute = shortterm_queue_root.next->priority; hwtimer_next_absolute = shortterm_queue_root.next->priority;
unsigned int next = hwtimer_next_absolute + longterm_tick_start; uint32_t next = hwtimer_next_absolute + longterm_tick_start;
unsigned int now = hwtimer_now(); uint32_t now = HWTIMER_TICKS_TO_US(hwtimer_now());
if((next - VTIMER_THRESHOLD - now) > MICROSECONDS_PER_TICK ) { if((next - HWTIMER_TICKS_TO_US(VTIMER_THRESHOLD) - now) > MICROSECONDS_PER_TICK ) {
next = now + VTIMER_BACKOFF; next = now + HWTIMER_TICKS_TO_US(VTIMER_BACKOFF);
} }
hwtimer_id = hwtimer_set_absolute(next, vtimer_callback, NULL); hwtimer_id = hwtimer_set_absolute(HWTIMER_TICKS(next), vtimer_callback, NULL);
DEBUG("update_shortterm: Set hwtimer to %lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now()); DEBUG("update_shortterm: Set hwtimer to %lu (now=%lu)\n", next, HWTIMER_TICKS_TO_US(hwtimer_now()));
return 0; return 0;
} }
@ -150,6 +150,7 @@ static int vtimer_set(vtimer_t *timer) {
normalize_to_tick(&(timer->absolute)); normalize_to_tick(&(timer->absolute));
DEBUG("vtimer_set(): Absolute: %lu %lu\n", timer->absolute.seconds, timer->absolute.microseconds); DEBUG("vtimer_set(): Absolute: %lu %lu\n", timer->absolute.seconds, timer->absolute.microseconds);
DEBUG("vtimer_set(): NOW: %lu %lu\n", vtimer_now().seconds, vtimer_now().microseconds);
int result = 0; int result = 0;
@ -185,7 +186,7 @@ static int vtimer_set(vtimer_t *timer) {
} }
timex_t vtimer_now() { timex_t vtimer_now() {
timex_t t = timex_set(seconds, hwtimer_now()-longterm_tick_start); timex_t t = timex_set(seconds, HWTIMER_TICKS_TO_US(hwtimer_now())-longterm_tick_start);
return t; return t;
} }
@ -194,6 +195,8 @@ int vtimer_init() {
int state = disableIRQ(); int state = disableIRQ();
seconds = 0; seconds = 0;
longterm_tick_start = 0;
longterm_tick_timer.action = vtimer_tick; longterm_tick_timer.action = vtimer_tick;
longterm_tick_timer.arg = NULL; longterm_tick_timer.arg = NULL;