Contiki 2.5
rftest-tx.c
1 /*
2  * Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
3  * to the MC1322x project (http://mc1322x.devl.org)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the Institute nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * This file is part of libmc1322x: see http://mc1322x.devl.org
31  * for details.
32  *
33  *
34  */
35 
36 #include <mc1322x.h>
37 #include <board.h>
38 #include <stdio.h>
39 
40 #include "tests.h"
41 #include "config.h"
42 
43 #define LED LED_RED
44 
45 /* 802.15.4 PSDU is 127 MAX */
46 /* 2 bytes are the FCS */
47 /* therefore 125 is the max payload length */
48 #define PAYLOAD_LEN 16
49 #define DELAY 100000
50 
51 void fill_packet(volatile packet_t *p) {
52  static volatile uint8_t count=0;
53  volatile uint8_t i;
54  p->length = PAYLOAD_LEN;
55  p->offset = 0;
56  for(i=0; i<PAYLOAD_LEN; i++) {
57  p->data[i] = count++;
58  }
59 
60  /* acks get treated differently, even in promiscuous mode */
61  /* setting the third bit makes sure that we never send an ack */
62  /* or any valid 802.15.4-2006 packet */
63  p->data[0] |= (1 << 3);
64 }
65 
66 void main(void) {
67  volatile uint32_t i;
68  volatile packet_t *p;
69 
70  /* trim the reference osc. to 24MHz */
71  trim_xtal();
72 
73  uart_init(INC, MOD, SAMP);
74 
75  vreg_init();
76 
77  maca_init();
78 
79  set_channel(0); /* channel 11 */
80 // set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
81 // set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
82  set_power(0x12); /* 0x12 is the highest, not documented */
83 
84  /* sets up tx_on, should be a board specific item */
85  *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
86  gpio_pad_dir_set( 1ULL << 44 );
87 
88  print_welcome("rftest-tx");
89 
90  while(1) {
91 
92  /* call check_maca() periodically --- this works around */
93  /* a few lockup conditions */
94  check_maca();
95 
96  while((p = rx_packet())) {
97  if(p) free_packet(p);
98  }
99 
100  p = get_free_packet();
101  if(p) {
102  fill_packet(p);
103 
104  printf("rftest-tx --- ");
105  print_packet(p);
106 
107  tx_packet(p);
108 
109  for(i=0; i<DELAY; i++) { continue; }
110  }
111 
112  }
113 
114 }