2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2013-06-21 22:36:48 +02:00
|
|
|
* Copyright (C) 2009 Freie Universität Berlin
|
2014-02-11 18:15:43 +01:00
|
|
|
* Copyright (C) 2013 INRIA
|
2013-06-21 22:36:48 +02:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-11-27 16:28:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-10-19 13:47:19 +02:00
|
|
|
* @ingroup drivers_cc110x_legacy
|
2013-06-21 22:36:48 +02:00
|
|
|
* @{
|
2013-11-27 17:54:30 +01:00
|
|
|
* @file cc110x-tx.c
|
|
|
|
* @brief Functions for packet transmission on cc110x
|
|
|
|
*
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
2013-06-21 22:36:48 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2010-11-26 10:23:46 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-10-19 13:47:19 +02:00
|
|
|
#include "cc110x_legacy.h"
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "cc110x-internal.h"
|
|
|
|
|
|
|
|
#include "irq.h"
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-11-23 14:03:26 +01:00
|
|
|
int8_t cc110x_send(cc110x_packet_t *packet)
|
2013-06-21 22:36:48 +02:00
|
|
|
{
|
|
|
|
volatile uint32_t abort_count;
|
2010-11-26 10:23:46 +01:00
|
|
|
uint8_t size;
|
|
|
|
/* TODO: burst sending */
|
2013-06-21 22:36:48 +02:00
|
|
|
radio_state = RADIO_SEND_BURST;
|
|
|
|
rflags.LL_ACK = 0;
|
2010-11-26 10:23:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of bytes to send is:
|
|
|
|
* length of phy payload (packet->length)
|
|
|
|
* + size of length field (1 byte)
|
|
|
|
*/
|
|
|
|
size = packet->length + 1;
|
|
|
|
|
2013-06-21 22:36:48 +02:00
|
|
|
/* The number of bytes to be transmitted must be smaller
|
|
|
|
* or equal to PACKET_LENGTH (62 bytes). So the receiver
|
|
|
|
* can put the whole packet in its RX-FIFO (with appended
|
|
|
|
* packet status bytes).*/
|
2013-06-24 22:37:35 +02:00
|
|
|
if (size > PACKET_LENGTH) {
|
2010-11-26 10:23:46 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-11 12:09:20 +01:00
|
|
|
packet->phy_src = cc110x_get_address();
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Disables RX interrupt etc. */
|
|
|
|
cc110x_before_send();
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-06-21 22:36:48 +02:00
|
|
|
/* But CC1100 in IDLE mode to flush the FIFO */
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_strobe(CC1100_SIDLE);
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Flush TX FIFO to be sure it is empty */
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_strobe(CC1100_SFTX);
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Write packet into TX FIFO */
|
|
|
|
cc110x_writeburst_reg(CC1100_TXFIFO, (char *) packet, size);
|
|
|
|
/* Switch to TX mode */
|
2010-11-26 10:23:46 +01:00
|
|
|
abort_count = 0;
|
|
|
|
unsigned int cpsr = disableIRQ();
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_strobe(CC1100_STX);
|
2013-06-21 22:36:48 +02:00
|
|
|
|
|
|
|
/* Wait for GDO2 to be set -> sync word transmitted */
|
2013-06-24 22:37:35 +02:00
|
|
|
while (cc110x_get_gdo2() == 0) {
|
2013-06-21 22:36:48 +02:00
|
|
|
abort_count++;
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (abort_count > CC1100_SYNC_WORD_TX_TIME) {
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Abort waiting. CC1100 maybe in wrong mode */
|
|
|
|
/* e.g. sending preambles for always */
|
|
|
|
puts("[CC1100 TX] fatal error\n");
|
|
|
|
break;
|
|
|
|
}
|
2010-11-26 10:23:46 +01:00
|
|
|
}
|
2013-06-21 22:36:48 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
restoreIRQ(cpsr);
|
|
|
|
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Wait for GDO2 to be cleared -> end of packet */
|
2013-06-24 22:37:35 +02:00
|
|
|
while (cc110x_get_gdo2() != 0);
|
2013-06-21 22:36:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Experimental - TOF Measurement */
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_after_send();
|
|
|
|
cc110x_statistic.raw_packets_out++;
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Store number of transmission retries */
|
|
|
|
rflags.TX = 0;
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-06-21 22:36:48 +02:00
|
|
|
/* Go to mode after TX (CONST_RX -> RX, WOR -> WOR) */
|
|
|
|
cc110x_switch_to_rx();
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-11-23 14:03:26 +01:00
|
|
|
return size;
|
2010-11-26 10:23:46 +01:00
|
|
|
}
|