2010-05-08 17:03:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
|
|
|
|
* to the MC1322x project (http://mc1322x.devl.org)
|
|
|
|
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
|
|
|
|
*
|
|
|
|
* This file is part of libmc1322x: see http://mc1322x.devl.org
|
|
|
|
* for details.
|
|
|
|
*
|
2011-02-12 23:12:45 +00:00
|
|
|
*
|
2010-05-08 17:03:36 +00:00
|
|
|
*/
|
|
|
|
|
2010-02-26 23:27:58 +00:00
|
|
|
#include <mc1322x.h>
|
|
|
|
#include <board.h>
|
2010-03-02 22:52:31 +00:00
|
|
|
#include <stdio.h>
|
2009-04-02 18:54:02 +00:00
|
|
|
|
2010-02-26 23:27:58 +00:00
|
|
|
#include "tests.h"
|
|
|
|
#include "config.h"
|
2009-04-02 18:54:02 +00:00
|
|
|
|
2010-03-07 21:49:57 +00:00
|
|
|
#define LED LED_RED
|
2009-04-02 18:54:02 +00:00
|
|
|
|
2010-03-07 23:48:36 +00:00
|
|
|
/* 802.15.4 PSDU is 127 MAX */
|
|
|
|
/* 2 bytes are the FCS */
|
|
|
|
/* therefore 125 is the max payload length */
|
|
|
|
#define PAYLOAD_LEN 16
|
2010-03-08 23:13:48 +00:00
|
|
|
#define DELAY 100000
|
2009-04-13 22:19:13 +00:00
|
|
|
|
2010-03-07 21:49:57 +00:00
|
|
|
void fill_packet(volatile packet_t *p) {
|
|
|
|
static volatile uint8_t count=0;
|
|
|
|
volatile uint8_t i;
|
|
|
|
p->length = PAYLOAD_LEN;
|
2010-03-07 22:04:30 +00:00
|
|
|
p->offset = 0;
|
2010-03-08 20:22:37 +00:00
|
|
|
for(i=0; i<PAYLOAD_LEN; i++) {
|
2010-03-07 21:49:57 +00:00
|
|
|
p->data[i] = count++;
|
2010-03-08 20:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* acks get treated differently, even in promiscuous mode */
|
2010-03-08 23:27:52 +00:00
|
|
|
/* setting the third bit makes sure that we never send an ack */
|
2010-03-08 20:22:37 +00:00
|
|
|
/* or any valid 802.15.4-2006 packet */
|
2010-03-08 23:27:52 +00:00
|
|
|
p->data[0] |= (1 << 3);
|
2009-04-13 22:19:13 +00:00
|
|
|
}
|
|
|
|
|
2009-04-02 18:54:02 +00:00
|
|
|
void main(void) {
|
|
|
|
volatile uint32_t i;
|
2010-03-07 21:49:57 +00:00
|
|
|
volatile packet_t *p;
|
|
|
|
|
2010-03-08 19:49:31 +00:00
|
|
|
/* trim the reference osc. to 24MHz */
|
2010-03-16 14:40:25 +00:00
|
|
|
trim_xtal();
|
2009-04-02 18:54:02 +00:00
|
|
|
|
2012-10-24 01:50:32 +00:00
|
|
|
uart_init(UART1, 115200);
|
2009-04-16 21:59:00 +00:00
|
|
|
|
2009-04-13 22:19:13 +00:00
|
|
|
vreg_init();
|
2009-04-02 22:05:13 +00:00
|
|
|
|
2010-03-08 19:49:31 +00:00
|
|
|
maca_init();
|
2010-03-01 18:01:51 +00:00
|
|
|
|
2010-03-08 19:49:31 +00:00
|
|
|
set_channel(0); /* channel 11 */
|
2010-03-07 23:48:36 +00:00
|
|
|
// set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
|
|
|
|
// set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
|
2010-03-08 19:49:31 +00:00
|
|
|
set_power(0x12); /* 0x12 is the highest, not documented */
|
|
|
|
|
|
|
|
/* sets up tx_on, should be a board specific item */
|
|
|
|
*GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
|
2010-03-17 02:03:38 +00:00
|
|
|
gpio_pad_dir_set( 1ULL << 44 );
|
2010-03-08 19:49:31 +00:00
|
|
|
|
|
|
|
print_welcome("rftest-tx");
|
2009-04-13 22:19:13 +00:00
|
|
|
|
2009-04-02 18:54:02 +00:00
|
|
|
while(1) {
|
2010-03-07 21:49:57 +00:00
|
|
|
|
2010-04-06 21:10:28 +00:00
|
|
|
/* call check_maca() periodically --- this works around */
|
|
|
|
/* a few lockup conditions */
|
|
|
|
check_maca();
|
|
|
|
|
2010-09-06 15:26:26 +00:00
|
|
|
while((p = rx_packet())) {
|
2014-02-07 19:51:01 +00:00
|
|
|
if(p) maca_free_packet(p);
|
2010-09-06 15:26:26 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 21:49:57 +00:00
|
|
|
p = get_free_packet();
|
|
|
|
if(p) {
|
|
|
|
fill_packet(p);
|
2009-04-13 22:19:13 +00:00
|
|
|
|
2010-03-07 21:49:57 +00:00
|
|
|
printf("rftest-tx --- ");
|
|
|
|
print_packet(p);
|
2010-03-08 23:39:08 +00:00
|
|
|
|
2010-03-07 21:49:57 +00:00
|
|
|
tx_packet(p);
|
|
|
|
|
|
|
|
for(i=0; i<DELAY; i++) { continue; }
|
2009-04-13 22:19:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 21:49:57 +00:00
|
|
|
}
|
2009-04-13 22:19:13 +00:00
|
|
|
|
2009-04-02 18:54:02 +00:00
|
|
|
}
|