SimAVR
AVR Simulator
AVR Simulation

Data Structures

struct  avr_trace_data_t
 This is only ever used if CONFIG_SIMAVR_TRACE is defined. More...
 
struct  avr_t
 Main AVR instance. More...
 
struct  avr_kind_t
 Static constructor for each of the AVR devices. More...
 
struct  avr_symbol_t
 Symbol loaded from the .elf file. More...
 

Macros

#define AVR_LOG(avr, level, ...)
 
#define AVR_TRACE(avr, ...)   AVR_LOG(avr, LOG_TRACE, __VA_ARGS__)
 
#define IO_START_ADDRESS   0x20
 IOs are located just after the register file (32 registers) More...
 
#define AVR_IO_TO_DATA(v)   ((v) + IO_START_ADDRESS)
 Map an IO address to the SRAM address space, i.e. add the register file offset to the address. More...
 
#define AVR_DATA_TO_IO(v)   ((v) - IO_START_ADDRESS)
 Unmap an IO address from the address SRAM, i.e. subtract the register file offset to the address. More...
 

Typedefs

typedef uint32_t avr_flashaddr_t
 
typedef uint8_t(* avr_io_read_t) (struct avr_t *avr, avr_io_addr_t addr, void *param)
 
typedef void(* avr_io_write_t) (struct avr_t *avr, avr_io_addr_t addr, uint8_t v, void *param)
 
typedef void(* avr_run_t) (struct avr_t *avr)
 
typedef struct avr_t avr_t
 Main AVR instance. More...
 
typedef struct avr_kind_t avr_kind_t
 Static constructor for each of the AVR devices. More...
 
typedef struct avr_symbol_t avr_symbol_t
 Symbol loaded from the .elf file. More...
 
typedef void(* avr_logger_p) (struct avr_t *avr, const int level, const char *format, va_list ap)
 Type for custom logging functions. More...
 

Enumerations

enum  { LOG_OUTPUT = 0, LOG_ERROR, LOG_WARNING, LOG_TRACE }
 Logging macros and associated log levels. More...
 
enum  {
  S_C = 0, S_Z, S_N, S_V,
  S_S, S_H, S_T, S_I,
  R_XL = 0x1a, R_XH, R_YL, R_YH,
  R_ZL, R_ZH, R_SPL = AVR_IO_TO_DATA(0x3d), R_SPH,
  R_SREG = AVR_IO_TO_DATA(0x3f), MAX_IOs = 280
}
 
enum  {
  cpu_Limbo = 0, cpu_Stopped, cpu_Running, cpu_Sleeping,
  cpu_Step, cpu_StepDone, cpu_Done, cpu_Crashed
}
 Core states. More...
 

Functions

avr_tavr_make_mcu_by_name (const char *name)
 Locate the maker for mcu "name" and allocates a new avr instance. More...
 
int avr_init (avr_t *avr)
 Initializes a new AVR instance. Will call the IO registers init(), and then reset() More...
 
avr_tavr_core_allocate (const avr_t *core, uint32_t coreLen)
 Used by the cores, allocated a mutable avr_t from the const global. More...
 
void avr_reset (avr_t *avr)
 Resets the AVR, and the IO modules. More...
 
int avr_run (avr_t *avr)
 Run one cycle of the AVR, sleep if necessary. More...
 
void avr_terminate (avr_t *avr)
 Finish any pending operations. More...
 
void avr_set_command_register (avr_t *avr, avr_io_addr_t addr)
 Set an IO register to receive commands from the AVR firmware it's optional, and uses the ELF tags. More...
 
void avr_set_console_register (avr_t *avr, avr_io_addr_t addr)
 Specify the "console register" – output sent to this register is printed on the simulator console, without using a UART. More...
 
void avr_loadcode (avr_t *avr, uint8_t *code, uint32_t size, avr_flashaddr_t address)
 Load code in the "flash". More...
 
void avr_core_watch_write (avr_t *avr, uint16_t addr, uint8_t v)
 These are accessors for avr->data but allows watchpoints to be set for gdb IO modules use that to set values to registers, and the AVR core decoder uses that to register "public" read by instructions. More...
 
uint8_t avr_core_watch_read (avr_t *avr, uint16_t addr)
 
void avr_sadly_crashed (avr_t *avr, uint8_t signal)
 Called when the core has detected a crash somehow. More...
 
void avr_global_logger (struct avr_t *avr, const int level, const char *format,...)
 Logs a message using the current logger. More...
 
void avr_global_logger_set (avr_logger_p logger)
 Sets a global logging function in place of the default. More...
 
avr_logger_p avr_global_logger_get (void)
 Gets the current global logger function. More...
 
void avr_callback_sleep_gdb (avr_t *avr, avr_cycle_count_t howLong)
 These are callbacks for the two 'main' behaviour in simavr. More...
 
void avr_callback_run_gdb (avr_t *avr)
 
void avr_callback_sleep_raw (avr_t *avr, avr_cycle_count_t howLong)
 
void avr_callback_run_raw (avr_t *avr)
 
uint32_t avr_pending_sleep_usec (avr_t *avr, avr_cycle_count_t howLong)
 Accumulates sleep requests (and returns a sleep time of 0) until a minimum count of requested sleep microseconds are reached (low amounts cannot be handled accurately). More...
 

Detailed Description

Macro Definition Documentation

#define AVR_DATA_TO_IO (   v)    ((v) - IO_START_ADDRESS)

Unmap an IO address from the address SRAM, i.e. subtract the register file offset to the address.

#define AVR_IO_TO_DATA (   v)    ((v) + IO_START_ADDRESS)

Map an IO address to the SRAM address space, i.e. add the register file offset to the address.

#define AVR_LOG (   avr,
  level,
  ... 
)
Value:
do { \
avr_global_logger(avr, level, __VA_ARGS__); \
} while(0)
avr_t * avr
Definition: run_avr.c:54
void avr_global_logger(struct avr_t *avr, const int level, const char *format,...)
Logs a message using the current logger.
Definition: sim_avr.c:54
#define AVR_TRACE (   avr,
  ... 
)    AVR_LOG(avr, LOG_TRACE, __VA_ARGS__)
#define IO_START_ADDRESS   0x20

IOs are located just after the register file (32 registers)

Typedef Documentation

typedef uint32_t avr_flashaddr_t
typedef uint8_t(* avr_io_read_t) (struct avr_t *avr, avr_io_addr_t addr, void *param)
typedef void(* avr_io_write_t) (struct avr_t *avr, avr_io_addr_t addr, uint8_t v, void *param)
typedef struct avr_kind_t avr_kind_t

Static constructor for each of the AVR devices.

typedef void(* avr_logger_p) (struct avr_t *avr, const int level, const char *format, va_list ap)

Type for custom logging functions.

typedef void(* avr_run_t) (struct avr_t *avr)
typedef struct avr_symbol_t avr_symbol_t

Symbol loaded from the .elf file.

typedef struct avr_t avr_t

Main AVR instance.

Some of these fields are set by the AVR "Core" definition files the rest is runtime data (as little as possible)

Enumeration Type Documentation

anonymous enum

Logging macros and associated log levels.

The current log level is kept in avr->log.

Enumerator
LOG_OUTPUT 
LOG_ERROR 
LOG_WARNING 
LOG_TRACE 
anonymous enum
Enumerator
S_C 

SREG bit indexes.

S_Z 
S_N 
S_V 
S_S 
S_H 
S_T 
S_I 
R_XL 

16 bits register pairs

R_XH 
R_YL 
R_YH 
R_ZL 
R_ZH 
R_SPL 

stack pointer

R_SPH 
R_SREG 

real SREG

MAX_IOs 

Bigger AVRs need more than 256-32 (mega1280)

anonymous enum

Core states.

Enumerator
cpu_Limbo 

before initialization is finished

cpu_Stopped 

all is stopped, timers included

cpu_Running 

we're free running

cpu_Sleeping 

we're now sleeping until an interrupt

cpu_Step 

run ONE instruction, then...

cpu_StepDone 

tell gdb it's all OK, and give it registers

cpu_Done 

avr software stopped gracefully

cpu_Crashed 

avr software crashed (watchdog fired)

Function Documentation

void avr_callback_run_gdb ( avr_t avr)

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_callback_run_raw ( avr_t avr)

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_callback_sleep_gdb ( avr_t avr,
avr_cycle_count_t  howLong 
)

These are callbacks for the two 'main' behaviour in simavr.

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_callback_sleep_raw ( avr_t avr,
avr_cycle_count_t  howLong 
)

Here is the call graph for this function:

Here is the caller graph for this function:

avr_t* avr_core_allocate ( const avr_t core,
uint32_t  coreLen 
)

Used by the cores, allocated a mutable avr_t from the const global.

Here is the caller graph for this function:

uint8_t avr_core_watch_read ( avr_t avr,
uint16_t  addr 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_core_watch_write ( avr_t avr,
uint16_t  addr,
uint8_t  v 
)

These are accessors for avr->data but allows watchpoints to be set for gdb IO modules use that to set values to registers, and the AVR core decoder uses that to register "public" read by instructions.

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_global_logger ( struct avr_t avr,
const int  level,
const char *  format,
  ... 
)

Logs a message using the current logger.

avr_logger_p avr_global_logger_get ( void  )

Gets the current global logger function.

void avr_global_logger_set ( avr_logger_p  logger)

Sets a global logging function in place of the default.

Here is the call graph for this function:

int avr_init ( avr_t avr)

Initializes a new AVR instance. Will call the IO registers init(), and then reset()

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_loadcode ( avr_t avr,
uint8_t *  code,
uint32_t  size,
avr_flashaddr_t  address 
)

Load code in the "flash".

Here is the caller graph for this function:

avr_t* avr_make_mcu_by_name ( const char *  name)

Locate the maker for mcu "name" and allocates a new avr instance.

Here is the caller graph for this function:

uint32_t avr_pending_sleep_usec ( avr_t avr,
avr_cycle_count_t  howLong 
)

Accumulates sleep requests (and returns a sleep time of 0) until a minimum count of requested sleep microseconds are reached (low amounts cannot be handled accurately).

This function is an utility function for the sleep callbacks

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_reset ( avr_t avr)

Resets the AVR, and the IO modules.

Here is the call graph for this function:

Here is the caller graph for this function:

int avr_run ( avr_t avr)

Run one cycle of the AVR, sleep if necessary.

Here is the caller graph for this function:

void avr_sadly_crashed ( avr_t avr,
uint8_t  signal 
)

Called when the core has detected a crash somehow.

This might activate gdb server

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_set_command_register ( avr_t avr,
avr_io_addr_t  addr 
)

Set an IO register to receive commands from the AVR firmware it's optional, and uses the ELF tags.

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_set_console_register ( avr_t avr,
avr_io_addr_t  addr 
)

Specify the "console register" – output sent to this register is printed on the simulator console, without using a UART.

Here is the call graph for this function:

Here is the caller graph for this function:

void avr_terminate ( avr_t avr)

Finish any pending operations.

Here is the call graph for this function:

Here is the caller graph for this function: