avr

package module
v0.0.0-...-869bd27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2018 License: MIT Imports: 1 Imported by: 0

README

PLEASE NOTE: I no longer actively maintain this project. Pull requests are welcome, but development has halted and issues are unlikely to gain a response.

avr

avr is an implementation of Atmel's AVR microprocessor specification in the Go programming language.

Note: this package is a work-in-progress. More to come shortly.

Features

  • Implements entire AVR instruction set, with the exception of BREAK, DES, SLEEP, SPM and WDR.
  • Emulates various hardware modules:
    • digital GPIO pins
    • timer/counter
  • Accurately supports individual MCUs:
    • ATtiny4/5/9/10
    • ATmega48/88/168
    • more to come soon!

Installation

avr is go-gettable:

# go get github.com/kierdavis/avr/cmd/avrem

Usage

The avrem command (in the "cmd" subdirectory) is a command-line interface to the emulator. To try it out, run it with an Intel HEX file like so:

# avrem program.hex

Flags include -mcu to specify the name of the MCU spec to use, -mcus to list the names of all available MCU specs, and -freq to specify the execution frequency.

The "programs" subdirectory contains example programs. Many of these are Arduino programs, and have precompiled IHEX program files for a number of MCUs present in the same directory.

Running the "blink" example for a 16 MHz ATmega168:

# avrem -mcu mega168 -freq 16 programs/blink/blink-atmega168.hex

Note: currently, running the blink program (and probably other programs, when they are added) will produce about 20 "access of unmapped I/O port" warnings. This is simply due to the program initialising hardware subsystems that are not yet implemented in the emulator.

Performance

The maximum unthrottled clock rate approaches 35 MHz on my 2.3 GHz Intel i7 processor. Real AVR microprocessors range from 1 to 20 MHz, so this software can in theory simulate an mid-range AVR processor almost twice as quickly as the physical implementation.

Packages

  • github.com/kierdavis/avr - miscellaneous shared code
  • github.com/kierdavis/avr/clock - manages synchronisation between concurrent processes of emulator
  • github.com/kierdavis/avr/emulator - implementation of CPU emulator
  • github.com/kierdavis/avr/hardware/gpio - implementation of digital GPIO pins
  • github.com/kierdavis/avr/hardware/timer - implementation of timer/counter module
  • github.com/kierdavis/avr/loader/ihexloader - links Intel HEX file parser with loading programs into emulators
  • github.com/kierdavis/avr/spec - specifications of the many different models of AVR processor (MCUs)

License

This source code is distributed under the MIT license.

Documentation

Index

Constants

View Source
const NumInstructions = int(XCH) + 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag int

A CPU status flag.

const (
	// Carry
	FlagC Flag = iota
	// Zero
	FlagZ
	// Negative
	FlagN
	// Overflow
	FlagV
	// Sign
	FlagS
	// Half-carry
	FlagH
	// Stored bit
	FlagT
	// Interrupts enabled
	FlagI
)

func (Flag) String

func (i Flag) String() string

type Instruction

type Instruction int8
const (
	ADC Instruction = iota
	ADD
	ADIW
	AND
	ANDI
	ASR
	BCLR
	BLD
	BRBC
	BRBS
	BREAK
	BSET
	BST
	CALL
	CBI
	COM
	CP
	CPC
	CPI
	CPSE
	DEC
	DES
	EICALL
	EIJMP
	ELPM_R0
	ELPM
	ELPM_INC
	EOR
	FMUL
	FMULS
	FMULSU
	ICALL
	IJMP
	IN
	INC
	JMP
	LAC
	LAS
	LAT
	LD_X
	LD_X_INC
	LD_X_DEC
	LD_Y
	LD_Y_INC
	LD_Y_DEC
	LDD_Y
	LD_Z
	LD_Z_INC
	LD_Z_DEC
	LDD_Z
	LDI
	LDS
	LDS_SHORT
	LPM_R0
	LPM
	LPM_INC
	LSR
	MOV
	MOVW
	MUL
	MULS
	MULSU
	NEG
	NOP
	OR
	ORI
	OUT
	POP
	PUSH
	RCALL
	RET
	RETI
	RJMP
	ROR
	SBC
	SBCI
	SBI
	SBIC
	SBIS
	SBIW
	SBRC
	SBRS
	SLEEP
	SPM
	SPM_2
	ST_X
	ST_X_INC
	ST_X_DEC
	ST_Y
	ST_Y_INC
	ST_Y_DEC
	STD_Y
	ST_Z
	ST_Z_INC
	ST_Z_DEC
	STD_Z
	STS
	STS_SHORT
	SUB
	SUBI
	SWAP
	WDR
	XCH
)

func (Instruction) IsTwoWord

func (inst Instruction) IsTwoWord() bool

func (Instruction) String

func (i Instruction) String() string

type PortRef

type PortRef struct {
	BankNum uint
	Index   uint16
}

A reference to an I/O port. It consists of a bank number (referring to a bank defined in the relevant MCUSpec) and an index within the bank.

Directories

Path Synopsis
cmd
avrmakedec
avrmakedec is a tool to emit an efficient AVR instruction decoder from a specification of the binary syntax of the instruction set.
avrmakedec is a tool to emit an efficient AVR instruction decoder from a specification of the binary syntax of the instruction set.
automatically generated by avrmakedec -output decode_gen.go -pkg emulator -kind lutc DO NOT EDIT
automatically generated by avrmakedec -output decode_gen.go -pkg emulator -kind lutc DO NOT EDIT
hardware
gpio
Package gpio implements a general purpose digital I/O port.
Package gpio implements a general purpose digital I/O port.
timer
Package gpio implements a timer/counter unit.
Package gpio implements a timer/counter unit.
loader
ihexloader
Package ihexloader encapsulates loading of IHEX files into an Emulator.
Package ihexloader encapsulates loading of IHEX files into an Emulator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL