Remote Access Control


memory.c File Reference


Detailed Description

Source file for EEPROM and SRAM variables and support functions.

This file contains the variables in EEPROM and SRAM that er common to most of the application. Refer to the memory.h file for more details.

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 memory.c.

#include "memory.h"
#include "common.h"
#include "config.h"

Include dependency graph for memory.c:

Go to the source code of this file.

Functions

void createMessage (COMMAND_CODE_TYPE commandCode)
__interrupt void eepromReadyHandler (void)
void initializeMessage (void)
void startCounterUpdate ()
void waitForCounterUpdate ()

Variables

static volatile byte counterBytesLeft = 0
byte cryptoBlock [BLOCK_SIZE+1]
SharedBlock sharedBlock


Function Documentation

void createMessage ( COMMAND_CODE_TYPE  commandCode  ) 

Prepare non-constant fields for message payload in 'sharedBlock'.

Definition at line 79 of file memory.c.

References MessagePayload::commandCode, MessagePayload::counterValue, SharedBlock::messagePayload, and sharedBlock.

Referenced by transmitCommandMessage().

00080 {
00081         sharedBlock.messagePayload.commandCode = commandCode;
00082         sharedBlock.messagePayload.counterValue = nextCounterValue;
00083 }

__interrupt void eepromReadyHandler ( void   ) 

Interrupt handler for EEPROM ready.

Definition at line 117 of file memory.c.

References counterBytesLeft.

00118 {
00119         // If previous byte wrapped to 0x00, increase address.
00120         if( EEDR == 0x00 ) {
00121                 ++EEAR;
00122         }
00123 
00124         // Read old value.
00125         EECR |= (1<<EERE);
00126         // Increase.
00127         ++EEDR;
00128         // If no overflow, no bytes left to update.
00129         if( EEDR != 0x00 ) {
00130                 counterBytesLeft = 0;
00131                 EECR &= ~(1<<EERIE); // Disable further interrupts.
00132         } else {
00133                 --counterBytesLeft;
00134         }
00135         
00136         // Start writing.
00137         EECR |= (1<<EEMWE);
00138         EECR |= (1<<EEWE);
00139 }

void initializeMessage ( void   ) 

Prepare constant fields for message payload in 'sharedBlock'.

Definition at line 69 of file memory.c.

References SharedBlock::messagePayload, MessagePayload::preamble, MessagePayload::serialNo, and sharedBlock.

Referenced by main(), and transmitTeachMessage().

00070 {
00071         // The preamble is used as a synch-and-start indicator for
00072         // the RF receiver.
00073         sharedBlock.messagePayload.preamble = 0xfe; // 11111110
00074         sharedBlock.messagePayload.serialNo = serialNo;
00075 }

void startCounterUpdate (  ) 

Start interrupt controlled update of 'nextCounterValue' in EEPROM.

Definition at line 92 of file memory.c.

References counterBytesLeft, and SEQ_COUNTER_BYTES.

Referenced by transmitCommandMessage().

00093 {
00094         // Make sure EEPROM is ready.
00095         do {} while( EECR & (1<<EEWE) );
00096         // Prepare control variables.
00097         EEDR = 0xff; // 0xff indicates that we just started.
00098         EEAR = (uint16_t) &nextCounterValue;
00099         counterBytesLeft = SEQ_COUNTER_BYTES;
00100         // Enable EEPROM Ready Interrupt.
00101         EECR |= (1<<EERIE);
00102 }

void waitForCounterUpdate (  ) 

Wait for counter value update to finish.

Definition at line 106 of file memory.c.

References counterBytesLeft.

Referenced by transmitCommandMessage().

00107 {
00108         while( counterBytesLeft ) { __sleep(); }
00109 }


Variable Documentation

volatile byte counterBytesLeft = 0 [static]

Number of bytes left during update of counter value in EEPROM.

Definition at line 88 of file memory.c.

Referenced by eepromReadyHandler(), startCounterUpdate(), and waitForCounterUpdate().

byte cryptoBlock[BLOCK_SIZE+1]

Common workspace for encrypting and decrypting.

Definition at line 62 of file memory.c.

Referenced by main(), transmitCommandMessage(), and transmitTeachMessage().

union SharedBlock sharedBlock

Common workspace for message payloads and a second crypto block.

Definition at line 63 of file memory.c.

Referenced by createMessage(), initializeMessage(), transmitCommandMessage(), and transmitTeachMessage().

@DOC_TITLE@
Generated on Fri Aug 8 11:03:28 2008 for AVR411 Secure Rolling Code Algorithm (Transmitter) by doxygen 1.4.7