| Remote Access Control |

# comms.h File Reference

## Detailed Description

Header file for communications public functions.

This file contains the prototypes for the communications control functions. The implementation is found in the comms.c file. The communication is interrupt-controlled and is enabled with the enableReception() function. The driver then waits for incoming data from the RF receiver. It receives until either the required number of bytes has been received or the reception times out in the middle of the packet. Functions from the files timer.h and timer.c is used to implement the time-out functionality.

- File: comms.h
- Compiler: IAR EWAVR 4.11B
- Supported devices: ATtiny45/85
- AppNote: AVR411 - Secure Rolling Code Algorithm for Wireless Link

Author:
  Atmel Corporation: http://www.atmel.com
  Support email: avr@atmel.com

Name

Revision
  1193

Date
  2006-10-31 14:21:08 +0100 (ti, 31 okt 2006)

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.h.

`#include "common.h"`
`#include "config.h"`

Include dependency graph for comms.h:

This graph shows which files directly or indirectly include this file:

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)

## Function Documentation

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:

@DOC_TITLE@