| Remote Access Control | |||||
This file contains the function implementation for the communications control functions. Refer to the comms.h file for more details.
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 comms.c.
#include "comms.h"
#include "common.h"
#include "config.h"
#include "timer.h"
#include "radio.h"
Include dependency graph for comms.c:

Go to the source code of this file.
Functions | |
| void | enableReception (byte messageSize) |
| bool | initReceiver (void) |
| byte | messageBytesReceived (void) |
| bool | messageComplete (void) |
| bool | receiverTimedOut (void) |
| __interrupt void | rxClockLineHandler (void) |
Variables | |
| static volatile byte | messageBitCount |
| static volatile byte * | messageBufferPtr |
| static volatile byte | messageByteCount |
| static volatile byte | messageBytesLeft |
| static volatile byte | messageCurrentByte |
| static volatile bool | messageWaitForStartBit |
| void enableReception | ( | byte | messageSize | ) |
Prepare for interrupt controlled reception of 'messageSize' bytes.
Definition at line 250 of file comms.c.
References receiveBuffer, RF_CLOCK_PCINT_MASK_BIT, and RF_CLOCK_PCINT_MASK_REG.
Referenced by learnMode(), and main().
00251 { 00252 messageBufferPtr = (byte *) &receiveBuffer; 00253 messageBytesLeft = messageSize; 00254 messageByteCount = 0; 00255 messageCurrentByte = 0; 00256 messageBitCount = 0; 00257 messageWaitForStartBit = true; 00258 RF_CLOCK_PCINT_MASK_REG |= (1<<RF_CLOCK_PCINT_MASK_BIT); 00259 }
| bool initReceiver | ( | void | ) |
Setup RF recevier and return true if it succeeded.
Definition at line 219 of file comms.c.
References rx_OPMODE_t::amplitudeModulation, rx_OPMODE_t::baudRateRange, rx_OPMODE_t::bitCheck, INIT_RX_CLOCK, INIT_RX_DATA, rx_LIMIT_t::limMax, rx_LIMIT_t::limMin, rx_OPMODE_t::noiseSuppression, RF_CLOCK_PCINT_ENABLE_BIT, RX_LIM_MAX, RX_LIM_MIN, rx_WriteVerifySleep(), rx_OPMODE_t::sleepExtension, and rx_OPMODE_t::sleepValue.
Referenced by main().
00220 { 00221 INIT_RX_DATA(); 00222 INIT_RX_CLOCK(); 00223 00224 PCICR |= (1<<RF_CLOCK_PCINT_ENABLE_BIT); 00225 00226 // Consult receiver datasheet for details on settings. 00227 rx_OPMODE_t opmode; 00228 opmode.baudRateRange = 2; // XLim = 3.2 - 5.6 kBaud 00229 opmode.bitCheck = 1; // 3 valid 1-bits required to wake up receiver. 00230 #ifdef FSK 00231 opmode.amplitudeModulation = false; 00232 #endif 00233 #ifdef ASK 00234 opmode.amplitudeModulation = true; 00235 #endif 00236 opmode.sleepValue = 1; // ~2ms sleep. 00237 opmode.sleepExtension = false; 00238 opmode.noiseSuppression = true; 00239 00240 rx_LIMIT_t limit; 00241 limit.limMin = RX_LIM_MIN; // 4800 Baud - 20% 00242 limit.limMax = RX_LIM_MAX; // 4800 Baud + 20% 00243 00244 bool success = rx_WriteVerifySleep( &opmode, &limit ); 00245 return success; 00246 }
Here is the call graph for this function:

| byte messageBytesReceived | ( | void | ) |
Returns number of currently received.
Definition at line 270 of file comms.c.
Referenced by main().
00271 { 00272 return messageByteCount; 00273 }
| bool messageComplete | ( | void | ) |
Returns true if all bytes have been received successfully.
Definition at line 263 of file comms.c.
Referenced by learnMode(), main(), and receiverTimedOut().
00264 { 00265 return messageBytesLeft == 0; 00266 }
| bool receiverTimedOut | ( | void | ) |
Returns true if reception timed out.
Definition at line 277 of file comms.c.
References messageComplete(), RF_CLOCK_PCINT_MASK_BIT, RF_CLOCK_PCINT_MASK_REG, rx_WriteOFF(), and shortTimeout.
Referenced by learnMode(), and main().
00278 { 00279 if( shortTimeout == true && !messageComplete() && !messageWaitForStartBit ) { 00280 // Disable reception. 00281 RF_CLOCK_PCINT_MASK_REG &= ~(1<<RF_CLOCK_PCINT_MASK_BIT); 00282 rx_WriteOFF( false ); 00283 // Indicate timeout. 00284 return true; 00285 } else { 00286 return false; 00287 } 00288 }
Here is the call graph for this function:

| __interrupt void rxClockLineHandler | ( | void | ) |
ISR called when RF receiver clock line changes.
Definition at line 175 of file comms.c.
References GET_RX_CLOCK, GET_RX_DATA, RF_CLOCK_PCINT_MASK_BIT, RF_CLOCK_PCINT_MASK_REG, rx_WriteOFF(), and startShortTimeout().
00176 { 00177 // Return if it was not a rising edge in clock input pin. 00178 if( GET_RX_CLOCK() == 0 ) { 00179 return; 00180 } 00181 00182 // Check that data is 0 if we are waiting for start bit. 00183 if( messageWaitForStartBit ) { 00184 if( GET_RX_DATA() == 0 ) { 00185 messageWaitForStartBit = false; 00186 startShortTimeout(); 00187 } 00188 return; 00189 } 00190 00191 // Insert bit into current byte and copy to buffer if 8 bits are received. 00192 messageCurrentByte <<= 1; 00193 #ifdef INVERTED_MANCHESTER 00194 if( GET_RX_DATA() != 0 ) { 00195 #else 00196 if( GET_RX_DATA() == 0 ) { 00197 #endif 00198 messageCurrentByte |= 0x01; 00199 } 00200 if( ++messageBitCount == 8 ) { 00201 *messageBufferPtr++ = messageCurrentByte; 00202 messageCurrentByte = 0; 00203 messageBitCount = 0; 00204 ++messageByteCount; 00205 00206 // Disable further interrupts if all bytes are received, 00207 // else restart the timeout for next byte. 00208 if( --messageBytesLeft == 0 ) { 00209 RF_CLOCK_PCINT_MASK_REG &= ~(1<<RF_CLOCK_PCINT_MASK_BIT); 00210 rx_WriteOFF( false ); 00211 } else { 00212 startShortTimeout(); 00213 } 00214 } 00215 }
Here is the call graph for this function:

volatile byte messageBitCount [static] |
volatile byte* messageBufferPtr [static] |
volatile byte messageByteCount [static] |
volatile byte messageBytesLeft [static] |
volatile byte messageCurrentByte [static] |
volatile bool messageWaitForStartBit [static] |
Generated on Fri Aug 8 11:03:58 2008 for AVR411 Secure Rolling Code Algorithm (Receiver) by 1.4.7
|