AVR Z-LINKŪ | |||||
Copyright (c) 2006, Atmel Corporation 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. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ATMEL ``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 EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
Definition in file wireless_uart.c.
#include <stdint.h>
#include <stdbool.h>
#include "config_uart.h"
#include "compiler.h"
#include "at86rf230_registermap.h"
#include "hal.h"
#include "tat.h"
#include "com.h"
Include dependency graph for wireless_uart.c:
Go to the source code of this file.
Functions | |
static void | avr_init (void) |
This function configure the necessary IO modules on the AVR. | |
void | main (void) |
static void | rx_pool_init (void) |
This function initialize the rx_pool. The rx_pool is in essence a FIFO. | |
static void | trx_end_handler (uint32_t time_stamp) |
This function is the TRX_END event handler that is called from the TRX isr if assigned. | |
static bool | trx_init (void) |
This function is used to initialize the TRX. | |
Variables | |
static uint8_t | debug_data_received [] = "\r--->Rx:\r" |
Debug Text. | |
static uint8_t | debug_data_sent [] = "<---TX OK.\r\n" |
Debug Text. | |
static uint8_t | debug_fatal_error [] = "A fatal error. System must be reset.\r\n" |
Debug Text. | |
static uint8_t | debug_lqi [] = "LQI: " |
Debug Text. | |
static uint8_t | debug_pll_transition [] = "State transition failed\r\n" |
Debug Text. | |
static uint8_t | debug_rx_pool_overflow [] = "RX Buffer Overflow!\r\n" |
Debug Text. | |
static uint8_t | debug_transmission_failed [] = "TX Failed!\r\n" |
Debug Text. | |
static uint8_t | debug_transmission_length [] = "Typed Message too long!!\r\n" |
Debug Text. | |
static uint8_t | debug_type_message [] = "\r<---Type Message:\r\n" |
Debug Text. | |
static bool | rx_flag |
Flag used to mask between the two possible TRX_END events. | |
static hal_rx_frame_t | rx_pool [RX_POOL_SIZE] |
Pool of hal_rx_frame_t's. | |
static hal_rx_frame_t * | rx_pool_end |
Pointer to end of pool. | |
static hal_rx_frame_t * | rx_pool_head |
Pointer to next hal_rx_frame_t it is possible to write. | |
static uint8_t | rx_pool_items_free |
Number of free items (hal_rx_frame_t) in the pool. | |
static uint8_t | rx_pool_items_used |
static bool | rx_pool_overflow_flag |
Flag that is used to signal a pool overflow. | |
static hal_rx_frame_t * | rx_pool_start |
Pointer to start of pool. | |
static hal_rx_frame_t * | rx_pool_tail |
Pointer to next hal_rx_frame_t that can be read from the pool. |
static void avr_init | ( | void | ) | [static] |
This function configure the necessary IO modules on the AVR.
Definition at line 127 of file wireless_uart.c.
References BR_38400, and com_init().
Referenced by main().
Here is the call graph for this function:
void main | ( | void | ) |
Definition at line 181 of file wireless_uart.c.
References avr_init(), com_get_number_of_received_bytes(), com_get_received_data(), com_reset_receiver(), COM_RX_BUFFER_SIZE, com_send_hex(), com_send_string(), debug_data_received, debug_data_sent, debug_fatal_error, debug_lqi, debug_pll_transition, debug_rx_pool_overflow, debug_transmission_failed, debug_transmission_length, debug_type_message, rx_flag, rx_pool_end, rx_pool_init(), rx_pool_items_free, rx_pool_items_used, rx_pool_overflow_flag, rx_pool_start, rx_pool_tail, and trx_init().
00181 { 00182 00183 static uint8_t length_of_received_data = 0; 00184 rx_flag = true; 00185 00186 rx_pool_init( ); 00187 avr_init( ); 00188 trx_init( ); 00189 00190 //Set system state to RX_ON 00191 if (tat_set_trx_state( RX_ON ) != TAT_SUCCESS) { 00192 com_send_string( debug_fatal_error, sizeof( debug_fatal_error ) ); 00193 } // end: if (tat_set_trx_state( RX_ON ) != TAT_SUCCESS) ... 00194 00195 sei( ); 00196 00197 //Give the user an indication that the system is ready. 00198 com_send_string( debug_type_message, sizeof( debug_type_message ) ); 00199 00200 /*Enter Normal Program Flow: 00201 - Check for newly received frames. Print them if something is received. 00202 - Notify on rx_pool overflow. 00203 - Try to send data on air interface, if something is received on UART/USB. 00204 - Notify if the typed message was too long. 00205 */ 00206 while (true) { 00207 00208 //Check if we have received something on the air interface. 00209 if (rx_pool_items_used != 0) { 00210 00211 //Handle wrapping of rx_pool. 00212 if (rx_pool_tail == rx_pool_end) { 00213 rx_pool_tail = rx_pool_start; 00214 } else { 00215 ++rx_pool_tail; 00216 } // end: if (rx_pool_tail == rx_pool_end) ... 00217 00218 //Turn interrupts off for a short while to protect when status 00219 //information about the rx_pool is updated. 00220 cli( ); 00221 00222 ++rx_pool_items_free; 00223 --rx_pool_items_used; 00224 00225 sei( ); 00226 00227 //Send the frame to the user: 00228 com_send_string( debug_data_received, sizeof( debug_data_received ) ); 00229 com_send_string( rx_pool_tail->data, ((rx_pool_tail->length) - 2 ) ); 00230 com_send_string( debug_lqi, sizeof( debug_lqi ) ); 00231 com_send_hex( rx_pool_tail->lqi ); 00232 com_send_string( debug_type_message, sizeof( debug_type_message ) ); 00233 } // end: if (rx_pool_items_used != 0) ... 00234 00235 //Check for rx_pool overflow. 00236 if (rx_pool_overflow_flag == true) { 00237 00238 cli(); 00239 rx_pool_init( ); 00240 com_send_string( debug_rx_pool_overflow, sizeof( debug_rx_pool_overflow ) ); 00241 sei(); 00242 } // end: if (rx_pool_overflow_flag == true) ... 00243 00244 //Check for new data on the serial interface. 00245 //Check if data is ready to be sent. 00246 length_of_received_data = com_get_number_of_received_bytes( ); 00247 00248 if (length_of_received_data == 1) { 00249 00250 //length_of_received_data == 1 indicates a buffer overflow. Received data too long. 00251 com_send_string( debug_transmission_length, sizeof( debug_transmission_length ) ); 00252 com_reset_receiver( ); 00253 } else { 00254 00255 if ((length_of_received_data >= 3) && (length_of_received_data <= COM_RX_BUFFER_SIZE)) { 00256 00257 //Change state to PLL_ON and send data if the state transition was successful. 00258 if (tat_set_trx_state( PLL_ON ) == TAT_SUCCESS) { 00259 00260 uint8_t *rx_frame = com_get_received_data( ); 00261 00262 rx_flag = false; // Set the flag false, so that the TRX_END event is not misinterpreted. 00263 00264 if (tat_send_data( length_of_received_data, rx_frame ) == TAT_SUCCESS) { 00265 com_send_string( debug_data_sent, sizeof( debug_data_sent ) ); 00266 } else { 00267 com_send_string( debug_transmission_failed, sizeof( debug_transmission_failed ) ); 00268 } // end: if (tat_send_data_with_retry( tx_frame_length, tx_frame, 1 ) ... 00269 00270 //Wait for the TRX FSM to go back to PLL_ON. 00271 while (tat_get_trx_state( ) != PLL_ON) {;} 00272 } else { 00273 com_send_string( debug_pll_transition, sizeof( debug_pll_transition ) ); 00274 } // end: if (tat_set_trx_state( PLL_ON ) == TAT_SUCCESS) ... 00275 00276 if (tat_set_trx_state( RX_ON ) != TAT_SUCCESS) { 00277 com_send_string( debug_fatal_error, sizeof( debug_fatal_error ) ); 00278 } // end: if (tat_set_trx_state( RX_ON ) != TAT_SUCCESS) ... 00279 00280 rx_flag = true; // Set the flag back again. Only used to protec the frame transmission. 00281 com_reset_receiver( ); 00282 com_send_string( debug_type_message, sizeof( debug_type_message ) ); 00283 } // end: 00284 } // end: if (length_of_received_data == 1) ... 00285 } // emd: while (true) ... 00286 }
Here is the call graph for this function:
static void rx_pool_init | ( | void | ) | [static] |
This function initialize the rx_pool. The rx_pool is in essence a FIFO.
Definition at line 133 of file wireless_uart.c.
References rx_pool, rx_pool_end, rx_pool_head, rx_pool_items_free, rx_pool_items_used, rx_pool_overflow_flag, RX_POOL_SIZE, rx_pool_start, and rx_pool_tail.
Referenced by main().
00133 { 00134 00135 rx_pool_start = rx_pool; 00136 rx_pool_end = &rx_pool[ RX_POOL_SIZE - 1 ]; 00137 00138 rx_pool_head = rx_pool_start; 00139 rx_pool_tail = rx_pool_end; 00140 00141 rx_pool_items_free = RX_POOL_SIZE; 00142 rx_pool_items_used = 0; 00143 00144 rx_pool_overflow_flag = false; 00145 }
static void trx_end_handler | ( | uint32_t | time_stamp | ) | [static] |
This function is the TRX_END event handler that is called from the TRX isr if assigned.
[in] | time_stamp | Interrupt timestamp in IEEE 802.15.4 symbols. |
Definition at line 152 of file wireless_uart.c.
References rx_flag, rx_pool_end, rx_pool_head, rx_pool_items_free, rx_pool_items_used, rx_pool_overflow_flag, and rx_pool_start.
Referenced by trx_init().
00152 { 00153 00154 if (rx_flag == true) { 00155 00156 //Check if these is space left in the rx_pool. 00157 if (rx_pool_items_free == 0) { 00158 rx_pool_overflow_flag = true; 00159 } else { 00160 00161 //Space left, so upload the received frame. 00162 hal_frame_read( rx_pool_head ); 00163 00164 //Then check the CRC. Will not store frames with invalid CRC. 00165 if (rx_pool_head->crc == true) { 00166 00167 //Handle wrapping of rx_pool. 00168 if (rx_pool_head == rx_pool_end) { 00169 rx_pool_head = rx_pool_start; 00170 } else { 00171 ++rx_pool_head; 00172 } // end: if (rx_pool_head == rx_pool_end) ... 00173 00174 --rx_pool_items_free; 00175 ++rx_pool_items_used; 00176 } // end: if (rx_pool_head->crc == true) ... 00177 } // end: if (rx_pool_items_free == 0) ... 00178 } // end: if (rx_flag == true) ... 00179 }
static bool trx_init | ( | void | ) | [static] |
This function is used to initialize the TRX.
true | if the TRX was successfully configured. | |
false | if the TRX was not configured properly. |
Definition at line 104 of file wireless_uart.c.
References OPERATING_CHANNEL, and trx_end_handler().
Referenced by main().
00104 { 00105 00106 static bool status; 00107 00108 if (tat_init( ) != TAT_SUCCESS) { 00109 status = false; 00110 } else if (tat_set_operating_channel( OPERATING_CHANNEL ) != TAT_SUCCESS) { 00111 status = false; 00112 } else if (tat_set_clock_speed( true, CLKM_DISABLED ) != TAT_SUCCESS) { 00113 status = false; 00114 } else{ 00115 00116 tat_use_auto_tx_crc( true ); //Automatic CRC must be enabled. 00117 hal_set_trx_end_event_handler( trx_end_handler ); // Event handler for TRX_END events. 00118 00119 status = true; 00120 } // end: if (tat_init( ) != TAT_SUCCESS) ... 00121 00122 return status; 00123 }
Here is the call graph for this function:
uint8_t debug_data_received[] = "\r--->Rx:\r" [static] |
uint8_t debug_data_sent[] = "<---TX OK.\r\n" [static] |
uint8_t debug_fatal_error[] = "A fatal error. System must be reset.\r\n" [static] |
uint8_t debug_lqi[] = "LQI: " [static] |
uint8_t debug_pll_transition[] = "State transition failed\r\n" [static] |
uint8_t debug_rx_pool_overflow[] = "RX Buffer Overflow!\r\n" [static] |
uint8_t debug_transmission_failed[] = "TX Failed!\r\n" [static] |
uint8_t debug_transmission_length[] = "Typed Message too long!!\r\n" [static] |
uint8_t debug_type_message[] = "\r<---Type Message:\r\n" [static] |
bool rx_flag [static] |
Flag used to mask between the two possible TRX_END events.
Definition at line 82 of file wireless_uart.c.
Referenced by main(), and trx_end_handler().
hal_rx_frame_t rx_pool[RX_POOL_SIZE] [static] |
Pool of hal_rx_frame_t's.
Definition at line 73 of file wireless_uart.c.
Referenced by rx_pool_init().
hal_rx_frame_t* rx_pool_end [static] |
Pointer to end of pool.
Definition at line 75 of file wireless_uart.c.
Referenced by main(), rx_pool_init(), and trx_end_handler().
hal_rx_frame_t* rx_pool_head [static] |
Pointer to next hal_rx_frame_t it is possible to write.
Definition at line 76 of file wireless_uart.c.
Referenced by rx_pool_init(), and trx_end_handler().
uint8_t rx_pool_items_free [static] |
Number of free items (hal_rx_frame_t) in the pool.
Definition at line 78 of file wireless_uart.c.
Referenced by main(), rx_pool_init(), and trx_end_handler().
uint8_t rx_pool_items_used [static] |
Definition at line 79 of file wireless_uart.c.
Referenced by main(), rx_pool_init(), and trx_end_handler().
bool rx_pool_overflow_flag [static] |
Flag that is used to signal a pool overflow.
Definition at line 80 of file wireless_uart.c.
Referenced by main(), rx_pool_init(), and trx_end_handler().
hal_rx_frame_t* rx_pool_start [static] |
Pointer to start of pool.
Definition at line 74 of file wireless_uart.c.
Referenced by main(), rx_pool_init(), and trx_end_handler().
hal_rx_frame_t* rx_pool_tail [static] |
Pointer to next hal_rx_frame_t that can be read from the pool.
Definition at line 77 of file wireless_uart.c.
Referenced by main(), and rx_pool_init().
Generated on Wed Jul 25 21:15:50 2007 for AVR2001 Software Programmer's Manual by ![]() |