#
# The code is compiled "optimized" to the max.
#
-# The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
+# The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
# is used to tell the linker not to discard the .mmcu section,
# otherwise the --gc-sections will delete it.
#
# The code is compiled "optimized" to the max.
#
-# The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
+# The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
# is used to tell the linker not to discard the .mmcu section,
# otherwise the --gc-sections will delete it.
With thanks to Luki <humbell@ethz.ch>
This sample code is derivated from a patch sent by Luki, however it was mostly
-in german, and was usinf the SDL library. Also the implementation of the LCD
+in german, and was using the SDL library. Also the implementation of the LCD
itself had several shortcomings.
Therefore it was almost entirely rewritten from scratch the LCD was extended
for (;;) { /* main event loop */
/* If our internal ideal of which keys are down is different from the one that has been
- updated cia the interupts, we start counting. If the 'different' key(s) stays the same for
- 50ms, we declare it an 'event' and update the internsl key state
+ updated via the interrupts, we start counting. If the 'different' key(s) stays the same for
+ 50ms, we declare it an 'event' and update the internal key state
*/
if (keyState != lastKeyValue) {
for (uint8_t ki = 0; ki < KEY_MAX; ki++)
#include "avr/iom128.h"
/*
- * This is a template for all of the 128 devices, hopefuly
+ * This is a template for all of the 128 devices, hopefully
*/
const struct mcu_t {
avr_t core;
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom164.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax4.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom168.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax8.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom16m1.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megaxm1.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom324.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax4.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom328p.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax8.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom48.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax8.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom644.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax4.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom8.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom88.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_megax8.h"
static avr_t * make()
void mx_reset(struct avr_t * avr);
/*
- * This is a template for all of the 8/32/64 devices, hopefuly
+ * This is a template for all of the 8/32/64 devices, hopefully
*/
struct mcu_t {
avr_t core;
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iotn24.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_tinyx4.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iotn25.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_tinyx5.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iotn44.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_tinyx4.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iotn45.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_tinyx5.h"
static avr_t * make()
#define __ASSEMBLER__
#include "avr/iotn84.h"
#define HFUSE_DEFAULT FUSE_HFUSE_DEFAULT
-// instanciate the new core
+// instantiate the new core
#include "sim_tinyx4.h"
static avr_t * make()
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iotn85.h"
-// instanciate the new core
+// instantiate the new core
#include "sim_tinyx5.h"
static avr_t * make()
ADC_MUX_NONE = 0, // Nothing. return 0
ADC_MUX_NOISE, // Nothing. return something random
ADC_MUX_SINGLE, // Normal ADC pin reading
- ADC_MUX_DIFF, // differencial channels (src-diff)
+ ADC_MUX_DIFF, // differential channels (src-diff)
ADC_MUX_TEMP, // internal temp sensor
ADC_MUX_REF, // reference voltage (in src * 100)
ADC_MUX_VCC4, // VCC/4
int down = irq->value && !value;
switch (mode) {
case 0:
- // unsuported
+ // unsupported
break;
case 1:
if (up || down)
if (r->bit.mask == 0xff)
r->irq[o++] = &p->io.irq[IOPORT_IRQ_PIN_ALL];
else {
- // otherwise fil up the ones needed
+ // otherwise fill up the ones needed
for (int bi = 0; bi < 8; bi++)
if (r->bit.mask & (1 << bi))
r->irq[o++] = &p->io.irq[r->bit.bit + bi];
lbrr, baud);
p->uart.usec_per_byte = 1000000 / (baud / word_size);
- printf("Roughtly %d usec per bytes\n", (int) p->uart.usec_per_byte);
+ printf("Roughly %d usec per bytes\n", (int) p->uart.usec_per_byte);
}
static void
avr_spi_t * p = (avr_spi_t *)param;
avr_t * avr = p->io.avr;
- // check to see fi receiver is enabled
+ // check to see if receiver is enabled
if (!avr_regbit_get(avr, p->spe))
return;
// this involves some magicking
// cancel the current timers, recalculate the "base" we should be at, reset the
- // timer base as it should, and re-shedule the timers using that base.
+ // timer base as it should, and re-schedule the timers using that base.
avr_cycle_timer_cancel(avr, avr_timer_tov, p);
avr_cycle_timer_cancel(avr, avr_timer_compa, p);
uint16_t oldv[AVR_TIMER_COMP_COUNT];
int target = -1;
- /* vheck to see if the OCR values actualy changed */
+ /* check to see if the OCR values actually changed */
for (int oi = 0; oi < AVR_TIMER_COMP_COUNT; oi++)
oldv[oi] = _timer_get_ocr(p, oi);
avr_core_watch_write(avr, addr, v);
// Get the internal IRQ corresponding to the INT
#define AVR_IOCTL_TIMER_GETIRQ(_name) AVR_IOCTL_DEF('t','m','r',(_name))
-// Waweform generation modes
+// Waveform generation modes
enum {
avr_timer_wgm_none = 0, // invalid mode
avr_timer_wgm_normal,
/****************************************************************************
TWI State codes
****************************************************************************/
-// General TWI Master staus codes
+// General TWI Master status codes
#define TWI_START 0x08 // START has been transmitted
#define TWI_REP_START 0x10 // Repeated START has been transmitted
#define TWI_ARB_LOST 0x38 // Arbitration lost
-// TWI Master Transmitter staus codes
-#define TWI_MTX_ADR_ACK 0x18 // SLA+W has been tramsmitted and ACK received
-#define TWI_MTX_ADR_NACK 0x20 // SLA+W has been tramsmitted and NACK received
-#define TWI_MTX_DATA_ACK 0x28 // Data byte has been tramsmitted and ACK received
-#define TWI_MTX_DATA_NACK 0x30 // Data byte has been tramsmitted and NACK received
+// TWI Master Transmitter status codes
+#define TWI_MTX_ADR_ACK 0x18 // SLA+W has been transmitted and ACK received
+#define TWI_MTX_ADR_NACK 0x20 // SLA+W has been transmitted and NACK received
+#define TWI_MTX_DATA_ACK 0x28 // Data byte has been transmitted and ACK received
+#define TWI_MTX_DATA_NACK 0x30 // Data byte has been transmitted and NACK received
-// TWI Master Receiver staus codes
-#define TWI_MRX_ADR_ACK 0x40 // SLA+R has been tramsmitted and ACK received
-#define TWI_MRX_ADR_NACK 0x48 // SLA+R has been tramsmitted and NACK received
-#define TWI_MRX_DATA_ACK 0x50 // Data byte has been received and ACK tramsmitted
-#define TWI_MRX_DATA_NACK 0x58 // Data byte has been received and NACK tramsmitted
+// TWI Master Receiver status codes
+#define TWI_MRX_ADR_ACK 0x40 // SLA+R has been transmitted and ACK received
+#define TWI_MRX_ADR_NACK 0x48 // SLA+R has been transmitted and NACK received
+#define TWI_MRX_DATA_ACK 0x50 // Data byte has been received and ACK transmitted
+#define TWI_MRX_DATA_NACK 0x58 // Data byte has been received and NACK transmitted
-// TWI Slave Transmitter staus codes
+// TWI Slave Transmitter status codes
#define TWI_STX_ADR_ACK 0xA8 // Own SLA+R has been received; ACK has been returned
#define TWI_STX_ADR_ACK_M_ARB_LOST 0xB0 // Arbitration lost in SLA+R/W as Master; own SLA+R has been received; ACK has been returned
#define TWI_STX_DATA_ACK 0xB8 // Data byte in TWDR has been transmitted; ACK has been received
#define TWI_STX_DATA_NACK 0xC0 // Data byte in TWDR has been transmitted; NOT ACK has been received
#define TWI_STX_DATA_ACK_LAST_BYTE 0xC8 // Last data byte in TWDR has been transmitted (TWEA = �0�); ACK has been received
-// TWI Slave Receiver staus codes
+// TWI Slave Receiver status codes
#define TWI_SRX_ADR_ACK 0x60 // Own SLA+W has been received ACK has been returned
#define TWI_SRX_ADR_ACK_M_ARB_LOST 0x68 // Arbitration lost in SLA+R/W as Master; own SLA+W has been received; ACK has been returned
#define TWI_SRX_GEN_ACK 0x70 // General call address has been received; ACK has been returned
}
/*
- * prevent code from rewriting out status bits, since we actualy use them!
+ * prevent code from rewriting out status bits, since we actually use them!
*/
static void
avr_twi_write_status(
avr_twi_t * port);
/*
- * Create a message value for twi incuding the 'msg' bitfield,
+ * Create a message value for twi including the 'msg' bitfield,
* 'addr' and data. This value is what is sent as the IRQ value
*/
static inline uint32_t
p->name, val, baud, avr_regbit_get(avr, p->u2x)?2:1, db, sb);
// TODO: Use the divider value and calculate the straight number of cycles
p->usec_per_byte = 1000000 / (baud / word_size);
- printf("Roughtly %d usec per bytes\n", (int)p->usec_per_byte);
+ printf("Roughly %d usec per bytes\n", (int)p->usec_per_byte);
}
static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param)
}
}
TRACE(printf("UDR%c(%02x) = %02x\n", p->name, addr, v);)
- // tell other modules we are "outputing" a byte
+ // tell other modules we are "outputting" a byte
if (avr_regbit_get(avr, p->txen))
avr_raise_irq(p->io.irq + UART_IRQ_OUTPUT, v);
}
avr_uart_t * p = (avr_uart_t *)param;
avr_t * avr = p->io.avr;
- // check to see fi receiver is enabled
+ // check to see if receiver is enabled
if (!avr_regbit_get(avr, p->rxen))
return;
avr_cycle_timer_cancel(avr, avr_uart_txc_raise, p);
uart_fifo_reset(&p->input);
- // DEBUG allow printf without fidding with enabling the uart
+ // DEBUG allow printf without fiddling with enabling the uart
avr_regbit_set(avr, p->txen);
p->usec_per_byte = 100;
}
/*
* The method of "connecting" the the UART from external code is to use 4 IRQS.
- * The easy one is UART->YOU, where you will be called with the byte everytime
+ * The easy one is UART->YOU, where you will be called with the byte every time
* the AVR firmware sends one. Do whatever you like with it.
*
* The slightly more tricky one is the INPUT part. Since the AVR is quite a bit
epstate->ueconx.stallrq = 0;
// teensy actually depends on this (fails to ack rxouti on usb
- // control read status stage) even if the datasheet clarely states
+ // control read status stage) even if the datasheet clearly states
// that one should do so.
epstate->ueintx.rxouti = 0;
// cpu is in limbo before init is finished.
avr->state = cpu_Limbo;
- avr->frequency = 1000000; // can be overriden via avr_mcu_section
+ avr->frequency = 1000000; // can be overridden via avr_mcu_section
if (avr->special_init)
avr->special_init(avr);
if (avr->init)
avr->interrupts.pending_wait++;
avr->i_shadow = avr->sreg[S_I];
- // run the cycle timers, get the suggested sleeo time
+ // run the cycle timers, get the suggested sleep time
// until the next timer is due
avr_cycle_count_t sleep = avr_cycle_timer_process(avr);
void (*init)(struct avr_t * avr);
// called at init time (for special purposes like using a memory mapped file as flash see: simduino)
void (*special_init)(struct avr_t * avr);
- // called at termination time ( to clean special initalizations)
+ // called at termination time ( to clean special initializations)
void (*special_deinit)(struct avr_t * avr);
// called at reset time
void (*reset)(struct avr_t * avr);
// Mirror of the SREG register, to facilitate the access to bits
// in the opcode decoder.
- // This array is re-synthetized back/forth when SREG changes
+ // This array is re-synthesized back/forth when SREG changes
uint8_t sreg[8];
uint8_t i_shadow; // used to detect edges on I flag
avr_flashaddr_t address);
/*
- * these are accessors for avr->data but allows watchpoints to be set for gdb
+ * 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.
*/
/*
- * These are callbacks for the two 'main' bahaviour in simavr
+ * These are callbacks for the two 'main' behaviour in simavr
*/
void avr_callback_sleep_gdb(avr_t * avr, avr_cycle_count_t howLong);
void avr_callback_run_gdb(avr_t * avr);
#define REG_ISTOUCHED(a, r) ((a)->trace_data->touched[(r) >> 5] & (1 << ((r) & 0x1f)))
/*
- * This allows a "special case" to skip indtruction tracing when in these
- * symbols. since printf() is useful to have, but generates a lot of cycles
+ * This allows a "special case" to skip instruction tracing when in these
+ * symbols since printf() is useful to have, but generates a lot of cycles.
*/
int dont_trace(const char * name)
{
/*
* Set a register (r < 256)
- * if it's an IO regisrer (> 31) also (try to) call any callback that was
+ * if it's an IO register (> 31) also (try to) call any callback that was
* registered to track changes to that register.
*/
static inline void _avr_set_r(avr_t * avr, uint8_t r, uint8_t v)
* + It also doesn't check whether the core it's
* emulating is supposed to have the fancy instructions, like multiply and such.
*
- * The nunber of cycles taken by instruction has been added, but might not be
+ * The number of cycles taken by instruction has been added, but might not be
* entirely accurate.
*/
avr_flashaddr_t avr_run_one(avr_t * avr)
/*
* DEBUG bits follow
- * These will diseapear when gdb arrives
+ * These will disappear when gdb arrives
*/
void avr_dump_state(avr_t * avr);
when += avr->cycle;
- // find it's place int the list
+ // find its place in the list
int inserti = 0;
while (inserti < pool->count && pool->timer[inserti].when > when)
inserti++;
}
/*
- * run thru all the timers, call the ones that needs it,
+ * run through all the timers, call the ones that needs it,
* clear the ones that wants it, and calculate the next
* potential cycle we could sleep for...
*/
memset(firmware->codeline,0, bitesize);
#endif
- /* this is actualy mandatory !! otherwise elf_begin() fails */
+ /* this is actually mandatory !! otherwise elf_begin() fails */
if (elf_version(EV_CURRENT) == EV_NONE) {
/* library out of date - recover from error */
}
#endif
/* these are the addresses the gnu linker uses to
- * "fake" a non-harward addressign space for the AVR
+ * "fake" a non-Harvard addressing space for the AVR
*/
#define AVR_SEGMENT_OFFSET_FLASH 0
#define AVR_SEGMENT_OFFSET_EEPROM 0x00810000
case 'z': {
uint32_t kind, addr, len;
sscanf(cmd, "%d,%x,%x", &kind, &addr, &len);
-// printf("breakbpoint %d, %08x, %08x\n", kind, addr, len);
+// printf("breakpoint %d, %08x, %08x\n", kind, addr, len);
switch (kind) {
case 0: // software breakpoint
case 1: // hardware breakpoint
}
uint16_t addr = (bline[1] << 8) | bline[2];
if (base == ~0) {
- base = addr; // stadt address
+ base = addr; // start address
}
if (addr != base + size) {
fprintf(stderr, "%s: %s, offset out of bounds %04x expected %04x\n", __FUNCTION__, fname, addr, base+size);
// get the IRQ for an absolute IO address
// this allows any code to hook an IRQ in any io address, for example
// tracing changes of values into a register
-// Note that the values do not "magicaly" change, they change only
+// Note that the values do not "magically" change, they change only
// when the AVR code attempt to read and write at that address
//
// the "index" is a bit number, or ALL bits if index == 8
*/
typedef struct avr_irq_pool_t {
int count; //!< number of irqs living in the pool
- struct avr_irq_t ** irq; //!< irqs belongging in this pool
+ struct avr_irq_t ** irq; //!< irqs belonging in this pool
} avr_irq_pool_t;
/*!
* Value Change dump module for simavr.
*
* This structure registers IRQ change hooks to various "source" IRQs
- * and dumps their values (if changed) at certains intervals into the VCD file
+ * and dumps their values (if changed) at certain intervals into the VCD file
*/
#define AVR_VCD_MAX_SIGNALS 32