use synchronous transmission.

This commit is contained in:
nvt-se 2007-12-17 15:26:47 +00:00
parent 2a0351afb4
commit 5f1ca4ccdf
3 changed files with 51 additions and 78 deletions

View file

@ -90,6 +90,8 @@ static volatile uint8_t rssi;
// callback when a packet has been received // callback when a packet has been received
static uint8_t cc1020_pa_power = PA_POWER; static uint8_t cc1020_pa_power = PA_POWER;
static int dma_done;
static void (*receiver_callback)(const struct radio_driver *); static void (*receiver_callback)(const struct radio_driver *);
const struct radio_driver cc1020_driver = const struct radio_driver cc1020_driver =
@ -101,7 +103,11 @@ const struct radio_driver cc1020_driver =
cc1020_off cc1020_off
}; };
PROCESS(cc1020_sender_process, "CC1020 sender"); static void
dma_callback(void)
{
dma_done = 1;
}
void void
cc1020_init(const uint8_t *config) cc1020_init(const uint8_t *config)
@ -127,7 +133,7 @@ cc1020_init(const uint8_t *config)
// power down // power down
cc1020_setupPD(); cc1020_setupPD();
process_start(&cc1020_sender_process, NULL); dma_subscribe(0, dma_callback);
} }
void void
@ -236,8 +242,38 @@ cc1020_send(const void *buf, unsigned short len)
cc1020_txbuf[cc1020_txlen++] = TAIL; cc1020_txbuf[cc1020_txlen++] = TAIL;
cc1020_txbuf[cc1020_txlen++] = TAIL; cc1020_txbuf[cc1020_txlen++] = TAIL;
//process_poll(&cc1020_sender_process); cc1020_set_rx();
process_post_synch(&cc1020_sender_process, PROCESS_EVENT_POLL, NULL);
if ((cc1020_state & CC1020_RX_SEARCHING) == 0) {
// Wait until the receiver is idle.
while (cc1020_state & CC1020_RX_SEARCHING);
// Wait for the medium to become idle.
while (cc1020_carrier_sense());
// Then wait for a short pseudo-random time before sending.
clock_delay(1 + 10 * (random_rand() & 0xff));
}
// Switch to transceive mode.
cc1020_set_tx();
// Initiate radio transfer.
dma_done = 0;
dma_transfer(&TXBUF0, cc1020_txbuf, cc1020_txlen);
while (!dma_done);
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
RIMESTATS_ADD(lltx);
// clean up
cc1020_txlen = 0;
if (cc1020_state & CC1020_TURN_OFF) {
CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_SEARCHING);
cc1020_off();
} else {
cc1020_set_rx();
}
return len; return len;
} }
@ -418,62 +454,6 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
} }
} }
PROCESS_THREAD(cc1020_sender_process, ev, data)
{
int i;
PROCESS_BEGIN();
dma_subscribe(0, &cc1020_sender_process);
while (1) {
PROCESS_WAIT_UNTIL(cc1020_txlen > 0 && cc1020_state != CC1020_OFF);
cc1020_set_rx();
if((cc1020_state & CC1020_RX_SEARCHING) == 0) {
// Wait until the receiver is idle.
PROCESS_WAIT_UNTIL(cc1020_state & CC1020_RX_SEARCHING);
// Wait for the medium to become idle.
while (cc1020_carrier_sense());
// Then wait for a short pseudo-random time before sending.
clock_delay(1 + 10 * (random_rand() & 0xff));
}
// Switch to transceive mode.
cc1020_set_tx();
#if 0
U0CTL &= ~SWRST;
for (i = 0; i < cc1020_txlen; i++) {
UART0_TX = cc1020_txbuf[i];
UART0_WAIT_TX();
}
#endif
// Initiate radio transfer.
dma_transfer(&TXBUF0, cc1020_txbuf, cc1020_txlen);
// wait for DMA0 to finish
PROCESS_WAIT_UNTIL(ev == dma_event);
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
RIMESTATS_ADD(lltx);
// clean up
cc1020_txlen = 0;
if (cc1020_state & CC1020_TURN_OFF) {
CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_SEARCHING);
cc1020_off();
} else {
cc1020_set_rx();
}
}
PROCESS_END();
}
static void static void
cc1020_write_reg(uint8_t addr, uint8_t adata) cc1020_write_reg(uint8_t addr, uint8_t adata)
{ {

View file

@ -44,31 +44,30 @@
#include "dev/cc1020.h" #include "dev/cc1020.h"
#include "dev/dma.h" #include "dev/dma.h"
static struct process *subscribers[DMA_LINES]; static void (*callbacks[DMA_LINES])(void);
process_event_t dma_event;
interrupt(DACDMA_VECTOR) irq_dacdma(void) interrupt(DACDMA_VECTOR) irq_dacdma(void)
{ {
if (DMA0CTL & DMAIFG) { if (DMA0CTL & DMAIFG) {
DMA0CTL &= ~(DMAIFG | DMAIE); DMA0CTL &= ~(DMAIFG | DMAIE);
if (subscribers[0] != NULL) { if (callbacks[0] != NULL) {
process_post(subscribers[0], dma_event, NULL); callbacks[0]();
} }
LPM_AWAKE(); LPM_AWAKE();
} }
if (DMA1CTL & DMAIFG) { if (DMA1CTL & DMAIFG) {
DMA1CTL &= ~(DMAIFG | DMAIE); DMA1CTL &= ~(DMAIFG | DMAIE);
if (subscribers[1] != NULL) { if (callbacks[1] != NULL) {
process_post(subscribers[1], dma_event, NULL); callbacks[1]();
} }
LPM_AWAKE(); LPM_AWAKE();
} }
if (DMA2CTL & DMAIFG) { if (DMA2CTL & DMAIFG) {
DMA2CTL &= ~(DMAIFG | DMAIE); DMA2CTL &= ~(DMAIFG | DMAIE);
if (subscribers[2] != NULL) { if (callbacks[2] != NULL) {
process_post(subscribers[2], dma_event, NULL); callbacks[2]();
} }
LPM_AWAKE(); LPM_AWAKE();
} }
@ -82,19 +81,13 @@ interrupt(DACDMA_VECTOR) irq_dacdma(void)
} }
} }
void
dma_init(void)
{
dma_event = process_alloc_event();
}
int int
dma_subscribe(int line, struct process *p) dma_subscribe(int line, void (*callback)(void))
{ {
if (line >= DMA_LINES) if (line >= DMA_LINES)
return -1; return -1;
subscribers[line] = p; callbacks[line] = callback;
return 0; return 0;
} }

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: dma.h,v 1.5 2007/11/06 15:08:56 nvt-se Exp $ * $Id: dma.h,v 1.6 2007/12/17 15:26:47 nvt-se Exp $
*/ */
#ifndef DMA_H #ifndef DMA_H
@ -37,7 +37,7 @@
#define DMA_LINES 2 #define DMA_LINES 2
void dma_init(void); void dma_init(void);
int dma_subscribe(int, struct process *); int dma_subscribe(int, void (*)(void));
void dma_transfer(unsigned char *, unsigned char *, unsigned); void dma_transfer(unsigned char *, unsigned char *, unsigned);
extern process_event_t dma_event; extern process_event_t dma_event;