Contiki 2.6

rftest-tx.c

00001 /*
00002  * Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
00003  * to the MC1322x project (http://mc1322x.devl.org)
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the Institute nor the names of its contributors
00015  *    may be used to endorse or promote products derived from this software
00016  *    without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * This file is part of libmc1322x: see http://mc1322x.devl.org
00031  * for details. 
00032  *
00033  *
00034  */
00035 
00036 #include <mc1322x.h>
00037 #include <board.h>
00038 #include <stdio.h>
00039 
00040 #include "tests.h"
00041 #include "config.h"
00042 
00043 #define LED LED_RED
00044 
00045 /* 802.15.4 PSDU is 127 MAX */
00046 /* 2 bytes are the FCS */
00047 /* therefore 125 is the max payload length */
00048 #define PAYLOAD_LEN 16
00049 #define DELAY 100000
00050 
00051 void fill_packet(volatile packet_t *p) {
00052         static volatile uint8_t count=0;
00053         volatile uint8_t i;
00054         p->length = PAYLOAD_LEN;
00055         p->offset = 0;
00056         for(i=0; i<PAYLOAD_LEN; i++) {
00057                 p->data[i] = count++;
00058         }
00059 
00060         /* acks get treated differently, even in promiscuous mode */
00061         /* setting the third bit makes sure that we never send an ack */
00062         /* or any valid 802.15.4-2006 packet */
00063         p->data[0] |= (1 << 3); 
00064 }
00065 
00066 void main(void) {
00067         volatile uint32_t i;
00068         volatile packet_t *p;
00069 
00070         /* trim the reference osc. to 24MHz */
00071         trim_xtal();
00072 
00073         uart_init(INC, MOD, SAMP);
00074 
00075         vreg_init();
00076 
00077         maca_init();
00078 
00079         set_channel(0); /* channel 11 */
00080 //      set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
00081 //      set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
00082         set_power(0x12); /* 0x12 is the highest, not documented */
00083 
00084         /* sets up tx_on, should be a board specific item */
00085         *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
00086         gpio_pad_dir_set( 1ULL << 44 );
00087 
00088         print_welcome("rftest-tx");
00089 
00090         while(1) {              
00091                         
00092                 /* call check_maca() periodically --- this works around */
00093                 /* a few lockup conditions */
00094                 check_maca();
00095 
00096                 while((p = rx_packet())) {
00097                         if(p) free_packet(p);
00098                 }
00099 
00100                 p = get_free_packet();
00101                 if(p) {
00102                         fill_packet(p);
00103                         
00104                         printf("rftest-tx --- ");
00105                         print_packet(p);
00106 
00107                         tx_packet(p);
00108                         
00109                         for(i=0; i<DELAY; i++) { continue; }
00110                 }
00111                 
00112         }
00113 
00114 }