bootloader_smbus.c File Reference


Detailed Description

SMBus Bootloader for ATmega406.

Application note:
AVR453: Smart Battery Reference Design
Documentation:
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Original author: Rob G. Fries - Apt Inc.
$Name$
Revision
$RCSfile$
Date

Definition in file bootloader_smbus.c.

#include <inavr.h>
#include "bootldr.h"
#include "iom406.h"
#include "flash.h"

Go to the source code of this file.

Defines

#define BADPARAM   2
#define BUSY   1
#define CRCERROR   3
#define FAILURE   0xFF
#define HIGHEST_SMB_CMD   0x3F
#define MODULE_BOOTLDR
#define SMB_GenBusTimeout   1
#define SMB_GotCmdData   4
#define SMB_SetUpReply   2
#define SUCCESS   0
#define TWC_GO   0x85
#define TWC_READ_NoACK   0x85
#define TWC_RESTART   0xB5
#define TWC_START   0xA5
#define TWC_STOP   0x94
#define TWS_BERR   0x00
#define TWS_FINAL   0xC8
#define TWS_LOST_ARB   0x38
#define TWS_MASK   0xF8
#define TWS_NSTAT   0xF8
#define TWS_RACK   0xB8
#define TWS_RCMD   0x80
#define TWS_RDATA   0x80
#define TWS_READ_ACK   0x40
#define TWS_READ_NAK   0x48
#define TWS_REPEAT   0xA0
#define TWS_RESTART   0x10
#define TWS_RNAK   0xC0
#define TWS_RSTOP   0xA0
#define TWS_RXDATA_ACK   0x50
#define TWS_RXDATA_NACK   0x58
#define TWS_SLA_R   0xA8
#define TWS_SLA_W   0x60
#define TWS_START   0x08
#define TWS_TXDATA_ACK   0x28
#define TWS_TXDATA_NAK   0x30
#define TWS_WRITE_ACK   0x18
#define TWS_WRITE_NAK   0x20

Enumerations

enum  {
  TW_IDLE = 0, TW_Wait4Cmd, TW_Wait4RW, TW_Wait4Data,
  TW_ReplyData, TW_MSLA_W, TW_MCMD_W, TW_MDATA_W
}

Functions

void __low_level_init (void)
unsigned char EEbusy (void)
void EEerase (unsigned int address)
unsigned char EEget (unsigned int address)
void EEwrite (unsigned int address, unsigned char data)
unsigned char FastCRC (unsigned char LastCRC, unsigned char newbyte)
void init_boot (void)
void LoopMemory (void)
void main (void)
void SMB_BusTimeout (void)
void SMB_CmdInterpreter (void)
void SMB_Reply (void)
void SMB_RestoreBus (void)
void TWI_handler (void)

Variables

unsigned char BigData
__flash unsigned char crctable [16] = {0,0x07,0x0E,0x90, 0x1c,0x1b,0x12,0x15, 0x38,0x3F,0x36,0x31, 0x24,0x23,0x2A,0x2D}
__flash unsigned char crctable2 [16] = {0,0x70,0xE0,0x90, 0xC1,0xB1,0x21,0x51, 0x83,0xF3,0x63,0x13, 0x42,0x32,0xA2,0xD2}
unsigned char ctr
unsigned char dest_i
unsigned int eptr
unsigned char __flash * fptr
unsigned char himemptr
unsigned char lomemptr
unsigned char LoopFlag
unsigned char SRAMbuffer [128]
unsigned char src_i
unsigned char Status
unsigned char TW_RxBuf [36]
unsigned char TW_RxBufCnt
unsigned char TW_RxBufIndex
unsigned char TW_state
unsigned char TW_TxBuf [36]
unsigned char TW_TxBufCnt
unsigned char TW_TxBufIndex
unsigned char TWI_CmdFlags
unsigned char UsePEC


Define Documentation

#define BADPARAM   2

Definition at line 152 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

#define BUSY   1

Definition at line 151 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

#define CRCERROR   3

Definition at line 153 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

#define FAILURE   0xFF

Definition at line 154 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

#define HIGHEST_SMB_CMD   0x3F

Definition at line 65 of file bootloader_smbus.c.

Referenced by TWI_ISR().

#define MODULE_BOOTLDR

Definition at line 46 of file bootloader_smbus.c.

#define SMB_GenBusTimeout   1

Definition at line 144 of file bootloader_smbus.c.

Referenced by main(), SMB_CmdInterpreter(), TWI_handler(), and TWI_ISR().

#define SMB_GotCmdData   4

Definition at line 146 of file bootloader_smbus.c.

Referenced by main(), SMB_CmdInterpreter(), TWI_handler(), and TWI_ISR().

#define SMB_SetUpReply   2

Definition at line 145 of file bootloader_smbus.c.

Referenced by main(), SMB_CmdInterpreter(), TWI_handler(), and TWI_ISR().

#define SUCCESS   0

Definition at line 150 of file bootloader_smbus.c.

Referenced by init_boot(), LoopMemory(), and SMB_CmdInterpreter().

#define TWC_GO   0x85

Definition at line 105 of file bootloader_smbus.c.

#define TWC_READ_NoACK   0x85

Definition at line 106 of file bootloader_smbus.c.

#define TWC_RESTART   0xB5

Definition at line 109 of file bootloader_smbus.c.

#define TWC_START   0xA5

Definition at line 107 of file bootloader_smbus.c.

#define TWC_STOP   0x94

Definition at line 108 of file bootloader_smbus.c.

#define TWS_BERR   0x00

Definition at line 100 of file bootloader_smbus.c.

#define TWS_FINAL   0xC8

Definition at line 99 of file bootloader_smbus.c.

#define TWS_LOST_ARB   0x38

Definition at line 82 of file bootloader_smbus.c.

#define TWS_MASK   0xF8

Definition at line 72 of file bootloader_smbus.c.

#define TWS_NSTAT   0xF8

Definition at line 73 of file bootloader_smbus.c.

#define TWS_RACK   0xB8

Definition at line 97 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_RCMD   0x80

Definition at line 94 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_RDATA   0x80

Definition at line 93 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_READ_ACK   0x40

Definition at line 84 of file bootloader_smbus.c.

#define TWS_READ_NAK   0x48

Definition at line 85 of file bootloader_smbus.c.

#define TWS_REPEAT   0xA0

Definition at line 96 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_RESTART   0x10

Definition at line 77 of file bootloader_smbus.c.

#define TWS_RNAK   0xC0

Definition at line 98 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_RSTOP   0xA0

Definition at line 95 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_RXDATA_ACK   0x50

Definition at line 86 of file bootloader_smbus.c.

#define TWS_RXDATA_NACK   0x58

Definition at line 87 of file bootloader_smbus.c.

#define TWS_SLA_R   0xA8

Definition at line 92 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_SLA_W   0x60

Definition at line 91 of file bootloader_smbus.c.

Referenced by TWI_handler(), and TWI_ISR().

#define TWS_START   0x08

Definition at line 76 of file bootloader_smbus.c.

Referenced by TWI_ISR().

#define TWS_TXDATA_ACK   0x28

Definition at line 80 of file bootloader_smbus.c.

Referenced by TWI_ISR().

#define TWS_TXDATA_NAK   0x30

Definition at line 81 of file bootloader_smbus.c.

#define TWS_WRITE_ACK   0x18

Definition at line 78 of file bootloader_smbus.c.

Referenced by TWI_ISR().

#define TWS_WRITE_NAK   0x20

Definition at line 79 of file bootloader_smbus.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
TW_IDLE 
TW_Wait4Cmd 
TW_Wait4RW 
TW_Wait4Data 
TW_ReplyData 
TW_MSLA_W 
TW_MCMD_W 
TW_MDATA_W 

Definition at line 516 of file bootloader_smbus.c.


Function Documentation

void __low_level_init ( void   ) 

Todo:
EXCEPTION: if the Watchdog flag is asserted, there is a POSSIBILITY that there's a problem with the App code image. It is left to the user to determine if this is the case and to take remedial action.

Todo:
Add code here to handle Wdog reset.

Definition at line 174 of file bootloader_smbus.c.

unsigned char EEbusy ( void   ) 

Definition at line 735 of file bootloader_smbus.c.

Referenced by LoopMemory().

void EEerase ( unsigned int  address  ) 

Definition at line 750 of file bootloader_smbus.c.

Referenced by LoopMemory().

unsigned char EEget ( unsigned int  address  ) 

Definition at line 742 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

void EEwrite ( unsigned int  address,
unsigned char  data 
)

Definition at line 758 of file bootloader_smbus.c.

Referenced by LoopMemory().

unsigned char FastCRC ( unsigned char  LastCRC,
unsigned char  newbyte 
)

Definition at line 1081 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter(), SMB_Master(), and SMB_Reply().

void init_boot ( void   ) 

Definition at line 202 of file bootloader_smbus.c.

References BigData, LoopFlag, SMB_RestoreBus(), Status, SUCCESS, TW_RxBufCnt, TW_RxBufIndex, TW_state, TW_TxBufCnt, TW_TxBufIndex, and UsePEC.

Referenced by main().

void LoopMemory ( void   ) 

Definition at line 772 of file bootloader_smbus.c.

References ctr, dest_i, EEbusy(), EEerase(), EEwrite(), eptr, LoopFlag, SRAMbuffer, Status, and SUCCESS.

Referenced by main().

void main ( void   ) 

Definition at line 458 of file bootloader_smbus.c.

References init_boot(), LoopFlag, LoopMemory(), SMB_BusTimeout(), SMB_CmdInterpreter(), SMB_GenBusTimeout, SMB_GotCmdData, SMB_Reply(), SMB_SetUpReply, TWI_CmdFlags, and TWI_handler().

void SMB_BusTimeout ( void   ) 

Definition at line 692 of file bootloader_smbus.c.

References SMB_RestoreBus().

Referenced by main(), and SMB_CmdInterpreter().

void SMB_CmdInterpreter ( void   ) 

Todo:
Add code here if encryption is desired.

Todo:
Add code here if encryption is desired.

Definition at line 804 of file bootloader_smbus.c.

References _ENABLE_RWW_SECTION, _FILL_TEMP_WORD, _PAGE_ERASE, _PAGE_WRITE, _WAIT_FOR_SPM, BADPARAM, BigData, BUSY, CRCERROR, ctr, dest_i, EEget(), eptr, FAILURE, FastCRC(), fptr, himemptr, lomemptr, LoopFlag, SMB_BusTimeout(), SRAMbuffer, src_i, Status, SUCCESS, TW_RxBuf, TW_RxBufCnt, TW_RxBufIndex, TWRX_BLKCNT, TWRX_CMD, TWRX_DATA, TWRX_HIADDR, TWRX_LOADDR, TWRX_MEM, TWRX_OFFSET, TWRX_SIZE, and UsePEC.

Referenced by main().

void SMB_Reply ( void   ) 

Definition at line 703 of file bootloader_smbus.c.

References FastCRC(), SMBV_Opt5, Status, TW_TxBuf, TW_TxBufCnt, TW_TxBufIndex, and TWI_CmdFlags.

Referenced by main().

void SMB_RestoreBus ( void   ) 

Definition at line 1051 of file bootloader_smbus.c.

References TW_IDLE, and TW_state.

Referenced by generictimer0expired(), init_boot(), InitSMBus(), and SMB_BusTimeout().

void TWI_handler ( void   ) 

Definition at line 518 of file bootloader_smbus.c.

References SMB_GenBusTimeout, SMB_GotCmdData, SMB_SetUpReply, SMBV_Opt5, Status, TW_IDLE, TW_ReplyData, TW_RxBuf, TW_RxBufCnt, TW_RxBufIndex, TW_state, TW_TxBuf, TW_TxBufCnt, TW_TxBufIndex, TW_Wait4Cmd, TW_Wait4Data, TW_Wait4RW, TWI_CmdFlags, TWS_RACK, TWS_RCMD, TWS_RDATA, TWS_REPEAT, TWS_RNAK, TWS_RSTOP, TWS_SLA_R, TWS_SLA_W, and UsePEC.

Referenced by main().


Variable Documentation

unsigned char BigData

Definition at line 127 of file bootloader_smbus.c.

Referenced by init_boot(), and SMB_CmdInterpreter().

__flash unsigned char crctable[16] = {0,0x07,0x0E,0x90, 0x1c,0x1b,0x12,0x15, 0x38,0x3F,0x36,0x31, 0x24,0x23,0x2A,0x2D}

Definition at line 1078 of file bootloader_smbus.c.

__flash unsigned char crctable2[16] = {0,0x70,0xE0,0x90, 0xC1,0xB1,0x21,0x51, 0x83,0xF3,0x63,0x13, 0x42,0x32,0xA2,0xD2}

Definition at line 1079 of file bootloader_smbus.c.

unsigned char ctr

Definition at line 130 of file bootloader_smbus.c.

Referenced by CCarray_Average(), FillResponseStr(), LoopMemory(), and SMB_CmdInterpreter().

unsigned char dest_i

Definition at line 129 of file bootloader_smbus.c.

Referenced by LoopMemory(), and SMB_CmdInterpreter().

unsigned int eptr

Definition at line 134 of file bootloader_smbus.c.

Referenced by LoopMemory(), and SMB_CmdInterpreter().

unsigned char __flash* fptr

Definition at line 133 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

unsigned char himemptr

Definition at line 132 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

unsigned char lomemptr

Definition at line 131 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

unsigned char LoopFlag

Definition at line 126 of file bootloader_smbus.c.

Referenced by init_boot(), LoopMemory(), main(), and SMB_CmdInterpreter().

unsigned char SRAMbuffer[128]

Definition at line 136 of file bootloader_smbus.c.

Referenced by LoopMemory(), and SMB_CmdInterpreter().

unsigned char src_i

Definition at line 128 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter().

unsigned char Status

Definition at line 149 of file bootloader_smbus.c.

Referenced by init_boot(), LoopMemory(), SMB_CmdInterpreter(), SMB_Reply(), TWI_handler(), and TWI_ISR().

unsigned char TW_RxBuf[36]

Definition at line 119 of file bootloader_smbus.c.

Referenced by SMB_CmdInterpreter(), SMBW_AtRate(), SMBW_BattMode(), SMBW_MfrAccess(), SMBW_Opt4(), SMBW_RemCapAlm(), SMBW_RemTimeAlm(), TWI_handler(), and TWI_ISR().

unsigned char TW_RxBufCnt

Definition at line 120 of file bootloader_smbus.c.

Referenced by init_boot(), SMB_CmdInterpreter(), TWI_handler(), and TWI_ISR().

unsigned char TW_RxBufIndex

Definition at line 121 of file bootloader_smbus.c.

Referenced by init_boot(), SMB_CmdInterpreter(), SMBW_AtRate(), SMBW_BattMode(), SMBW_MfrAccess(), SMBW_Opt4(), SMBW_RemCapAlm(), SMBW_RemTimeAlm(), TWI_handler(), and TWI_ISR().

unsigned char TW_state

Definition at line 123 of file bootloader_smbus.c.

Referenced by init_boot(), SMB_RestoreBus(), and TWI_handler().

unsigned char TW_TxBuf[36]

Definition at line 115 of file bootloader_smbus.c.

Referenced by FillResponseInt(), FillResponseStr(), SMB_CmdInterpreter(), SMB_Reply(), TWI_handler(), and TWI_ISR().

unsigned char TW_TxBufCnt

Definition at line 116 of file bootloader_smbus.c.

Referenced by FillResponseInt(), FillResponseStr(), init_boot(), SMB_CmdInterpreter(), SMB_Reply(), TWI_handler(), and TWI_ISR().

unsigned char TW_TxBufIndex

Definition at line 117 of file bootloader_smbus.c.

Referenced by FillResponseInt(), FillResponseStr(), init_boot(), SMB_CmdInterpreter(), SMB_Reply(), TWI_handler(), and TWI_ISR().

unsigned char TWI_CmdFlags

Definition at line 143 of file bootloader_smbus.c.

Referenced by main(), SMB_CmdInterpreter(), SMB_Reply(), TWI_handler(), and TWI_ISR().

unsigned char UsePEC

Definition at line 124 of file bootloader_smbus.c.

Referenced by init_boot(), SMB_CmdInterpreter(), SMB_Master(), TWI_handler(), and TWI_ISR().


Generated on Mon Nov 12 15:59:58 2007 for AVR453 Smart Battery Reference Design by  doxygen 1.5.3