initial
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/* Copyright (c) 2002, 2003, 2004, 2007 Marek Michalkiewicz
|
||||
Copyright (c) 2005, 2006 Bjoern Haase
|
||||
Copyright (c) 2008 Atmel Corporation
|
||||
Copyright (c) 2008 Wouter van Gulik
|
||||
Copyright (c) 2009 Dmitry Xmelkov
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* Neither the name of the copyright holders nor the names of
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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. */
|
||||
|
||||
/* $Id: eeprom.h,v 1.21.2.13 2009/12/03 18:38:59 arcanum Exp $ */
|
||||
|
||||
#ifndef _AVR_EEPROM_H_
|
||||
#define _AVR_EEPROM_H_ 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
extern uint8_t __eeprom__storage[4096];
|
||||
|
||||
static inline uint8_t eeprom_read_byte (const uint8_t *__p)
|
||||
{
|
||||
return __eeprom__storage[int(__p)];
|
||||
}
|
||||
static inline uint16_t eeprom_read_word (const uint16_t *__p)
|
||||
{
|
||||
return *(uint16_t*)&__eeprom__storage[int(__p)];
|
||||
}
|
||||
static inline uint32_t eeprom_read_dword (const uint32_t *__p)
|
||||
{
|
||||
return *(uint32_t*)&__eeprom__storage[int(__p)];
|
||||
}
|
||||
#define eeprom_read_float eeprom_read_float_
|
||||
static inline float eeprom_read_float_ (const float *__p)
|
||||
{
|
||||
return *(float*)&__eeprom__storage[int(__p)];
|
||||
}
|
||||
static inline void eeprom_read_block (void *__dst, const void *__src, size_t __n)
|
||||
{
|
||||
memcpy(__dst, &__eeprom__storage[int(__src)], __n);
|
||||
}
|
||||
|
||||
static inline void eeprom_write_byte (uint8_t *__p, uint8_t __value)
|
||||
{
|
||||
__eeprom__storage[int(__p)] = __value;
|
||||
}
|
||||
static inline void eeprom_write_word (uint16_t *__p, uint16_t __value)
|
||||
{
|
||||
*(uint16_t*)&__eeprom__storage[int(__p)] = __value;
|
||||
}
|
||||
|
||||
static inline void eeprom_write_dword (uint32_t *__p, uint32_t __value)
|
||||
{
|
||||
*(uint32_t*)&__eeprom__storage[int(__p)] = __value;
|
||||
}
|
||||
|
||||
#define eeprom_write_float eeprom_write_float_
|
||||
static inline void eeprom_write_float_ (float *__p, float __value)
|
||||
{
|
||||
*(float*)&__eeprom__storage[int(__p)] = __value;
|
||||
}
|
||||
|
||||
static inline void eeprom_write_block (const void *__src, void *__dst, size_t __n)
|
||||
{
|
||||
memcpy(&__eeprom__storage[int(__dst)], __src, __n);
|
||||
}
|
||||
|
||||
static inline void eeprom_update_byte (uint8_t *__p, uint8_t __value) {}
|
||||
static inline void eeprom_update_word (uint16_t *__p, uint16_t __value) {}
|
||||
static inline void eeprom_update_dword (uint32_t *__p, uint32_t __value) {}
|
||||
static inline void eeprom_update_float (float *__p, float __value) {}
|
||||
static inline void eeprom_update_block (const void *__src, void *__dst, size_t __n) {}
|
||||
|
||||
#endif /* !_AVR_EEPROM_H_ */
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef _SIM_INTERRUPT_H
|
||||
#define _SIM_INTERRUPT_H
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#define SREG _SFR_IO8(0x3F)
|
||||
#define SREG_I (7)
|
||||
|
||||
static inline void cli() { SREG &=~_BV(SREG_I); }
|
||||
static inline void sei() { SREG |= _BV(SREG_I); }
|
||||
|
||||
#define ISR(vector_name) void vector_name ()
|
||||
#define SIGNAL(vector_name) void vector_name (void)
|
||||
|
||||
#endif//_SIM_INTERRUPT_H
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef _AVR_IO_H_
|
||||
#define _AVR_IO_H_ 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "No C++ compiler, simulated IO requires C++! Force C++ on all files!"
|
||||
#endif
|
||||
|
||||
#include "../../component/delegate.h"
|
||||
|
||||
typedef delegate<uint8_t, uint8_t&> registerDelegate;
|
||||
typedef void (*sim_ms_callback_t)();
|
||||
|
||||
void sim_check_interrupts();
|
||||
void sim_setup(sim_ms_callback_t callback);
|
||||
|
||||
class AVRRegistor
|
||||
{
|
||||
private:
|
||||
uint8_t value;
|
||||
registerDelegate callback;
|
||||
public:
|
||||
AVRRegistor() : value(0), callback() {}
|
||||
~AVRRegistor() {}
|
||||
|
||||
void setCallback(registerDelegate callback) { this->callback = callback; }
|
||||
void forceValue(uint8_t value) { this->value = value; }
|
||||
|
||||
operator uint8_t() const { return value; }
|
||||
AVRRegistor& operator = (const uint32_t v);
|
||||
AVRRegistor& operator |= (const uint32_t n) { *this = (value | n); return *this; }
|
||||
AVRRegistor& operator &= (const uint32_t n) { *this = (value & n); return *this; }
|
||||
|
||||
//volatile uint8_t* operator & () __attribute__((__deprecated__)) { return &value; }
|
||||
};
|
||||
#define __REG_MAP_SIZE 0x200
|
||||
extern AVRRegistor __reg_map[__REG_MAP_SIZE];
|
||||
|
||||
class AVRRegistor16
|
||||
{
|
||||
private:
|
||||
int index;
|
||||
public:
|
||||
AVRRegistor16(int index) : index(index) {}
|
||||
~AVRRegistor16() {}
|
||||
|
||||
AVRRegistor16& operator = (const uint32_t v) { __reg_map[index] = v & 0xFF; __reg_map[index+1] = (v >> 8) & 0xFF; return *this; }
|
||||
operator uint16_t() const { return uint16_t(__reg_map[index]) | (uint16_t(__reg_map[index+1])<<8); /*TODO*/}
|
||||
};
|
||||
|
||||
#define _SFR_MEM8(__n) (__reg_map[(__n)])
|
||||
#define _SFR_MEM16(__n) (AVRRegistor16(__n))
|
||||
#define _SFR_IO8(__n) (__reg_map[((__n) + 0x20)])
|
||||
#define _VECTOR(__n) __vector_ ## __n
|
||||
#define _SFR_BYTE(__n) __n
|
||||
|
||||
#define _BV(bit) (1 << (bit))
|
||||
|
||||
#define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))
|
||||
|
||||
#include "iom2560.h"
|
||||
|
||||
#endif//_AVR_IO_H_
|
||||
@@ -0,0 +1,94 @@
|
||||
/* Copyright (c) 2005 Anatoly Sokolov
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* 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.
|
||||
|
||||
* Neither the name of the copyright holders nor the names of
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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. */
|
||||
|
||||
/* $Id */
|
||||
|
||||
/* avr/iom2560.h - definitions for ATmega2560 */
|
||||
|
||||
#ifndef _AVR_IOM2560_H_
|
||||
#define _AVR_IOM2560_H_ 1
|
||||
|
||||
#include <avr/iomxx0_1.h>
|
||||
|
||||
/* Constants */
|
||||
#define SPM_PAGESIZE 256
|
||||
#define RAMEND 0x21FF
|
||||
#define XRAMEND 0xFFFF
|
||||
#define E2END 0xFFF
|
||||
#define E2PAGESIZE 8
|
||||
#define FLASHEND 0x3FFFF
|
||||
|
||||
|
||||
/* Fuses */
|
||||
|
||||
#define FUSE_MEMORY_SIZE 3
|
||||
|
||||
/* Low Fuse Byte */
|
||||
#define FUSE_CKSEL0 (unsigned char)~_BV(0)
|
||||
#define FUSE_CKSEL1 (unsigned char)~_BV(1)
|
||||
#define FUSE_CKSEL2 (unsigned char)~_BV(2)
|
||||
#define FUSE_CKSEL3 (unsigned char)~_BV(3)
|
||||
#define FUSE_SUT0 (unsigned char)~_BV(4)
|
||||
#define FUSE_SUT1 (unsigned char)~_BV(5)
|
||||
#define FUSE_CKOUT (unsigned char)~_BV(6)
|
||||
#define FUSE_CKDIV8 (unsigned char)~_BV(7)
|
||||
#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
|
||||
|
||||
/* High Fuse Byte */
|
||||
#define FUSE_BOOTRST (unsigned char)~_BV(0)
|
||||
#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
|
||||
#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
|
||||
#define FUSE_EESAVE (unsigned char)~_BV(3)
|
||||
#define FUSE_WDTON (unsigned char)~_BV(4)
|
||||
#define FUSE_SPIEN (unsigned char)~_BV(5)
|
||||
#define FUSE_JTAGEN (unsigned char)~_BV(6)
|
||||
#define FUSE_OCDEN (unsigned char)~_BV(7)
|
||||
#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
|
||||
|
||||
/* Extended Fuse Byte */
|
||||
#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
|
||||
#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
|
||||
#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
|
||||
#define EFUSE_DEFAULT (0xFF)
|
||||
|
||||
|
||||
/* Lock Bits */
|
||||
#define __LOCK_BITS_EXIST
|
||||
#define __BOOT_LOCK_BITS_0_EXIST
|
||||
#define __BOOT_LOCK_BITS_1_EXIST
|
||||
|
||||
|
||||
/* Signature */
|
||||
#define SIGNATURE_0 0x1E
|
||||
#define SIGNATURE_1 0x98
|
||||
#define SIGNATURE_2 0x01
|
||||
|
||||
|
||||
#endif /* _AVR_IOM2560_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
||||
#ifndef AVR_PGMSPACE_H
|
||||
#define AVR_PGMSPACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef char prog_char;
|
||||
|
||||
#define PROGMEM __attribute__(())
|
||||
#define PGM_P const prog_char *
|
||||
#define PSTR(str) (str)
|
||||
#define strcpy_P strcpy
|
||||
#define strlen_P strlen
|
||||
#define strcmp_P strcmp
|
||||
#define sprintf_P sprintf
|
||||
#define strcat_P strcat
|
||||
#define strstr_P strstr
|
||||
#define strncmp_P strncmp
|
||||
#define strncpy_P strncpy
|
||||
#define strchr_P strchr
|
||||
|
||||
static inline uint8_t pgm_read_byte(const void* ptr)
|
||||
{
|
||||
return *(const uint8_t*)ptr;
|
||||
}
|
||||
|
||||
static inline uint16_t pgm_read_word(const void* ptr)
|
||||
{
|
||||
return *(const uint16_t*)ptr;
|
||||
}
|
||||
|
||||
static inline float pgm_read_float(const void* ptr)
|
||||
{
|
||||
return *(const float*)ptr;
|
||||
}
|
||||
|
||||
#define pgm_read_byte_near(n) pgm_read_byte(n)
|
||||
#define pgm_read_word_near(n) pgm_read_word(n)
|
||||
#define pgm_read_float_near(n) pgm_read_float(n)
|
||||
|
||||
/* Cheating some none-standard C functions in here (normally provided by avr-libc), so WString.h of Arduino sees this function */
|
||||
inline static char * ultoa (unsigned long int __val, char *__s, int __radix)
|
||||
{
|
||||
char* c = __s;
|
||||
unsigned long n = __radix;
|
||||
while(n < __val)
|
||||
n *= __radix;
|
||||
n /= __radix;
|
||||
while(n)
|
||||
{
|
||||
int v = (__val / n) % __radix;
|
||||
if (v < 10)
|
||||
*c++ = '0' + v;
|
||||
else
|
||||
*c++ = 'a' + v - 10;
|
||||
n /= __radix;
|
||||
}
|
||||
*c = '\0';
|
||||
return __s;
|
||||
}
|
||||
|
||||
inline static char * utoa (unsigned int __val, char *__s, int __radix)
|
||||
{
|
||||
return ultoa(__val, __s, __radix);
|
||||
}
|
||||
|
||||
|
||||
inline static double square(double __x) { return __x * __x; }
|
||||
|
||||
#endif//AVR_PGMSPACE_H
|
||||
@@ -0,0 +1,128 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "../../Marlin/configuration.h"
|
||||
#include "../../Marlin/pins.h"
|
||||
#include "../../Marlin/fastio.h"
|
||||
|
||||
AVRRegistor __reg_map[__REG_MAP_SIZE];
|
||||
uint8_t __eeprom__storage[4096];
|
||||
sim_ms_callback_t ms_callback;
|
||||
|
||||
unsigned int __bss_end;
|
||||
unsigned int __heap_start;
|
||||
void *__brkval;
|
||||
|
||||
extern void TWI_vect();
|
||||
extern void TIMER0_OVF_vect();
|
||||
extern void TIMER0_COMPB_vect();
|
||||
extern void TIMER1_COMPA_vect();
|
||||
|
||||
unsigned int prevTicks = SDL_GetTicks();
|
||||
unsigned int twiIntStart = 0;
|
||||
|
||||
//After an interrupt we need to set the interrupt flag again, but do this without calling sim_check_interrupts so the interrupt does not fire recursively
|
||||
#define _sei() do { SREG.forceValue(SREG | _BV(SREG_I)); } while(0)
|
||||
|
||||
void sim_check_interrupts()
|
||||
{
|
||||
if (!(SREG & _BV(SREG_I)))
|
||||
return;
|
||||
|
||||
unsigned int ticks = SDL_GetTicks();
|
||||
int tickDiff = ticks - prevTicks;
|
||||
prevTicks = ticks;
|
||||
|
||||
#ifdef ENABLE_ULTILCD2
|
||||
if ((TWCR & _BV(TWEN)) && (TWCR & _BV(TWINT)) && (TWCR & _BV(TWIE)))
|
||||
{
|
||||
//Relay the TWI interrupt by 25ms one time till it gets disabled again. This fakes the LCD refresh rate.
|
||||
if (twiIntStart == 0)
|
||||
twiIntStart = SDL_GetTicks();
|
||||
if (SDL_GetTicks() - twiIntStart > 25)
|
||||
{
|
||||
cli();
|
||||
TWI_vect();
|
||||
_sei();
|
||||
}
|
||||
}
|
||||
if (!(TWCR & _BV(TWEN)) || !(TWCR & _BV(TWIE)))
|
||||
{
|
||||
twiIntStart = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//if (tickDiff > 1)
|
||||
// printf("Ticks slow! %i\n", tickDiff);
|
||||
if (tickDiff > 0)
|
||||
{
|
||||
ms_callback();
|
||||
|
||||
cli();
|
||||
for(int n=0;n<tickDiff;n++)
|
||||
{
|
||||
if (TIMSK0 & _BV(OCIE0B))
|
||||
TIMER0_COMPB_vect();
|
||||
if (TIMSK0 & _BV(TOIE0))
|
||||
TIMER0_OVF_vect();
|
||||
}
|
||||
|
||||
//Timer1 runs at 16Mhz / 8 ticks per second.
|
||||
unsigned int waveformMode = ((TCCR1B & (_BV(WGM13) | _BV(WGM12))) >> 1) | (TCCR1A & (_BV(WGM11) | _BV(WGM10)));
|
||||
unsigned int clockSource = TCCR1B & (_BV(CS12) | _BV(CS11) | _BV(CS10));
|
||||
unsigned int tickCount = F_CPU * tickDiff / 1000;
|
||||
unsigned int ticks = TCNT1;
|
||||
switch(clockSource)
|
||||
{
|
||||
case 0: tickCount = 0; break;
|
||||
case 1: break;
|
||||
case 2: tickCount /= 8; break;
|
||||
case 3: tickCount /= 64; break;
|
||||
case 4: tickCount /= 256; break;
|
||||
case 5: tickCount /= 1024; break;
|
||||
case 6: tickCount = 0; break;
|
||||
case 7: tickCount = 0; break;
|
||||
}
|
||||
|
||||
if (tickCount > 0 && OCR1A > 0)
|
||||
{
|
||||
ticks += tickCount;
|
||||
while(ticks > int(OCR1A))
|
||||
{
|
||||
ticks -= int(OCR1A);
|
||||
if (TIMSK1 & _BV(OCIE1A))
|
||||
TIMER1_COMPA_vect();
|
||||
}
|
||||
TCNT1 = ticks;
|
||||
}
|
||||
_sei();
|
||||
}
|
||||
}
|
||||
|
||||
extern void sim_setup_main();
|
||||
|
||||
//Assignment opperator called on every register write.
|
||||
AVRRegistor& AVRRegistor::operator = (const uint32_t v)
|
||||
{
|
||||
uint8_t n = v;
|
||||
if (!ms_callback) sim_setup_main();
|
||||
callback(value, n);
|
||||
value = n;
|
||||
sim_check_interrupts();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void sim_setup(sim_ms_callback_t callback)
|
||||
{
|
||||
FILE* f = fopen("eeprom.save", "rb");
|
||||
if (f)
|
||||
{
|
||||
fread(__eeprom__storage, sizeof(__eeprom__storage), 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
ms_callback = callback;
|
||||
|
||||
UCSR0A = 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef _AVR_WDT_H_
|
||||
#define _AVR_WDT_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define wdt_reset() do {} while(0)
|
||||
#define wdt_enable(value) do {} while(0)
|
||||
#define wdt_disable() do {} while(0)
|
||||
|
||||
#define WDTO_15MS 0
|
||||
#define WDTO_30MS 1
|
||||
#define WDTO_60MS 2
|
||||
#define WDTO_120MS 3
|
||||
#define WDTO_250MS 4
|
||||
#define WDTO_500MS 5
|
||||
#define WDTO_1S 6
|
||||
#define WDTO_2S 7
|
||||
#define WDTO_4S 8
|
||||
#define WDTO_8S 9
|
||||
|
||||
#endif /* _AVR_WDT_H_ */
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef _SIM_DELAY_H
|
||||
#define _SIM_DELAY_H
|
||||
|
||||
static inline void _delay_ms(int delay) {}
|
||||
static inline void _delay_us(int delay) {}
|
||||
|
||||
#endif//_SIM_DELAY_H
|
||||
Reference in New Issue
Block a user