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

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

## Defines
#define | EEPM0 4
#define | EEPM1 5
## Functions
__interrupt void | eepromHandler (void)
void | eraseTransmitters (void)
## Variables
static uint16_t | bytesToErase
byte | CMACSubkey [CMAC_SUBKEY_SIZE]
byte | cryptoBlock [BLOCK_SIZE]
ReceiveBuffer | receiveBuffer
byte | scheduleBuffer [SCHEDULE_BUFFER_SIZE]
byte | tempKeyStorage [KEY_SIZE]

## Define Documentation

#define EEPM0 4

Definition at line 98 of file memory.c.

Referenced by eraseTransmitters().

#define EEPM1 5

Definition at line 95 of file memory.c.

Referenced by eraseTransmitters().

## Function Documentation

__interrupt void eepromHandler | ( | void |  | ) |

ISR called when EEPROM is ready.

Definition at line 79 of file memory.c.

References bytesToErase.

    00080 {
    00081         if( bytesToErase ) {
    00082                 ++EEAR;
    00083                 EECR |= (1<<EEMPE);
    00084                 EECR |= (1<<EEPE);
    00085                 --bytesToErase;
    00086         } else {
    00087                 EECR &= ~(1<<EERIE); // Disable further interrupts.
    00088         }
    00089 }

void eraseTransmitters | ( | void |  | ) |

Clear array containing transmitter info.

Definition at line 103 of file memory.c.

References bytesToErase, EEPM0, EEPM1, and transmitters().

Referenced by learnMode().

    00104 {
    00105         bytesToErase = sizeof( TransmitterInfo ) * transmitterCount;
    00106         do {} while( EECR & (1<<EEPE) );
    00107         EECR = (0<<EEPM1) | (1<<EEPM0); // Erase-Only Mode.
    00108         EEAR = ((uint16_t) transmitters) - 1;
    00109         EECR |= (1<<EERIE);
    00110         while( bytesToErase ) {
    00111                 __sleep();
    00112         }
    00113         do {} while( EECR & (1<<EEPE) );
    00114         EECR = (0<<EEPM1) | (0<<EEPM0); // Back to Atomic Mode.
    00115         transmitterCount = 0;
    00116 }

Here is the call graph for this function:

## Variable Documentation

uint16_t bytesToErase`[static]`

Number of EEPROM bytes to erase by interrupt controlled erase operation.

Definition at line 73 of file memory.c.

Referenced by eepromHandler(), and eraseTransmitters().

byte CMACSubkey[CMAC_SUBKEY_SIZE]

Precalculated subkey for generating AES-CMAC for a transmitters.

Definition at line 65 of file memory.c.

Referenced by main().

byte cryptoBlock[BLOCK_SIZE]

Workspace for AES encryption and decryption.

Definition at line 64 of file memory.c.

Referenced by main().

ReceiveBuffer receiveBuffer

Buffer containing recevied message frames.

Definition at line 62 of file memory.c.

Referenced by enableReception(), learnMode(), and main().

byte scheduleBuffer[SCHEDULE_BUFFER_SIZE]

Storage for current round key when calculating AES key schedule.

Definition at line 63 of file memory.c.

Referenced by learnMode(), and main().

byte tempKeyStorage[KEY_SIZE]

Stores a copy of a transmitter's secret key from EEPROM.

Definition at line 66 of file memory.c.

Referenced by learnMode(), and main().

@DOC_TITLE@