Skeleton going up

This commit is contained in:
Michael Moon 2010-01-15 14:38:56 +11:00
parent 77c4b0eb6b
commit 4ed0ef3e73
12 changed files with 2449 additions and 872 deletions

View File

@ -34,7 +34,7 @@ F_CPU = 16000000L
ARCH = avr- ARCH = avr-
OPTIMIZE = -Os OPTIMIZE = -Os
CFLAGS = -g -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(F_CPU) $(DEFS) -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -save-temps CFLAGS = -g -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(F_CPU) $(DEFS) -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -save-temps
LDFLAGS = -Wl,-u,vfprintf -lprintf_min -Wl,--as-needed -Wl,--gc-sections -finline-functions-called-once LDFLAGS = -lprintf_min -Wl,--as-needed -Wl,--gc-sections -finline-functions-called-once
CC = $(ARCH)gcc CC = $(ARCH)gcc
OBJDUMP = $(ARCH)objdump OBJDUMP = $(ARCH)objdump

View File

@ -1,595 +0,0 @@
/****************************************************************************
Title : HD44780U LCD library
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
File: $Id: lcd.c,v 1.14.2.1 2006/01/29 12:16:41 peter Exp $
Software: AVR-GCC 3.3
Target: any AVR device, memory mapped mode only for AT90S4414/8515/Mega
DESCRIPTION
Basic routines for interfacing a HD44780U-based text lcd display
Originally based on Volker Oth's lcd library,
changed lcd_init(), added additional constants for lcd_command(),
added 4-bit I/O mode, improved and optimized code.
Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in
4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.
Memory mapped mode compatible with Kanda STK200, but supports also
generation of R/W signal through A8 address line.
USAGE
See the C include lcd.h file for a description of each function
*****************************************************************************/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "lcd.h"
/*
** constants/macros
*/
#define DDR(x) (*(&x - 1)) /* address of data direction register of port x */
#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
/* on ATmega64/128 PINF is on port 0x00 and not 0x60 */
#define PIN(x) ( &PORTF==&(x) ? _SFR_IO8(0x00) : (*(&x - 2)) )
#else
#define PIN(x) (*(&x - 2)) /* address of input register of port x */
#endif
#if LCD_IO_MODE
#define lcd_e_delay() __asm__ __volatile__( "rjmp 1f\n 1:" );
#define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN);
#define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN);
#define lcd_e_toggle() toggle_e()
#define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN)
#define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN)
#define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN)
#define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN)
#endif
#if LCD_IO_MODE
#if LCD_LINES==1
#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE
#else
#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES
#endif
#else
#if LCD_LINES==1
#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE
#else
#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES
#endif
#endif
#if LCD_CONTROLLER_KS0073
#if LCD_LINES==4
#define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x24 /* |0|010|0100 4-bit mode extension-bit RE = 1 */
#define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x20 /* |0|000|1001 4 lines mode */
#define KS0073_4LINES_MODE 0x09 /* |0|001|0000 4-bit mode, extension-bit RE = 0 */
#endif
#endif
/*
** function prototypes
*/
#if LCD_IO_MODE
static void toggle_e(void);
#endif
/*
** local functions
*/
/*************************************************************************
delay loop for small accurate delays: 16-bit counter, 4 cycles/loop
*************************************************************************/
static inline void _delayFourCycles(unsigned int __count)
{
if ( __count == 0 )
__asm__ __volatile__( "rjmp 1f\n 1:" ); // 2 cycles
else
__asm__ __volatile__ (
"1: sbiw %0,1" "\n\t"
"brne 1b" // 4 cycles/loop
: "=w" (__count)
: "0" (__count)
);
}
/*************************************************************************
delay for a minimum of <us> microseconds
the number of loops is calculated at compile-time from MCU clock frequency
*************************************************************************/
#define delay(us) _delayFourCycles( ( ( 1*(XTAL/4000) )*us)/1000 )
#if LCD_IO_MODE
/* toggle Enable Pin to initiate write */
static void toggle_e(void)
{
lcd_e_high();
lcd_e_delay();
lcd_e_low();
}
#endif
/*************************************************************************
Low-level function to write byte to LCD controller
Input: data byte to write to LCD
rs 1: write data
0: write instruction
Returns: none
*************************************************************************/
#if LCD_IO_MODE
static void lcd_write(uint8_t data,uint8_t rs)
{
if (rs) { /* write data (RS=1, RW=0) */
lcd_rs_high();
} else { /* write instruction (RS=0, RW=0) */
lcd_rs_low();
}
lcd_rw_low();
if (
(&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT)
&& (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)
)
{
/* configure data pins as output */
DDR(LCD_DATA0_PORT) |= 0x0F;
/* output high nibble first */
LCD_DATA0_PORT = (LCD_DATA0_PORT & 0xF0) | ((data >> 4) & 0x0F);
lcd_e_toggle();
/* output low nibble */
LCD_DATA0_PORT = (LCD_DATA0_PORT & 0xF0) | (data & 0x0F);
lcd_e_toggle();
/* all data pins high (inactive) */
LCD_DATA0_PORT = (LCD_DATA0_PORT & 0xF0) | 0x0F;
}
else
{
/* configure data pins as output */
DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
/* output high nibble first */
LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
if(data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
if(data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
if(data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
if(data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
lcd_e_toggle();
/* output low nibble */
LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
if(data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
if(data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
if(data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
if(data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
lcd_e_toggle();
/* all data pins high (inactive) */
LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
}
}
#else
#define lcd_write(d,rs) if (rs) *(volatile uint8_t*)(LCD_IO_DATA) = d; else *(volatile uint8_t*)(LCD_IO_FUNCTION) = d;
/* rs==0 -> write instruction to LCD_IO_FUNCTION */
/* rs==1 -> write data to LCD_IO_DATA */
#endif
/*************************************************************************
Low-level function to read byte from LCD controller
Input: rs 1: read data
0: read busy flag / address counter
Returns: byte read from LCD controller
*************************************************************************/
#if LCD_IO_MODE
static uint8_t lcd_read(uint8_t rs)
{
uint8_t data;
if (rs)
lcd_rs_high(); /* RS=1: read data */
else
lcd_rs_low(); /* RS=0: read busy flag */
lcd_rw_high(); /* RW=1 read mode */
if (
(&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT)
&& (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)
)
{
DDR(LCD_DATA0_PORT) &= 0xF0; /* configure data pins as input */
lcd_e_high();
lcd_e_delay();
data = PIN(LCD_DATA0_PORT) << 4; /* read high nibble first */
lcd_e_low();
lcd_e_delay(); /* Enable 500ns low */
lcd_e_high();
lcd_e_delay();
data |= PIN(LCD_DATA0_PORT) & 0x0F; /* read low nibble */
lcd_e_low();
}
else
{
/* configure data pins as input */
DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN);
DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN);
DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN);
DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN);
/* read high nibble first */
lcd_e_high();
lcd_e_delay();
data = 0;
if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x10;
if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x20;
if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x40;
if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x80;
lcd_e_low();
lcd_e_delay(); /* Enable 500ns low */
/* read low nibble */
lcd_e_high();
lcd_e_delay();
if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x01;
if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x02;
if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x04;
if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x08;
lcd_e_low();
}
return data;
}
#else
#define lcd_read(rs) (rs) ? *(volatile uint8_t*)(LCD_IO_DATA+LCD_IO_READ) : *(volatile uint8_t*)(LCD_IO_FUNCTION+LCD_IO_READ)
/* rs==0 -> read instruction from LCD_IO_FUNCTION */
/* rs==1 -> read data from LCD_IO_DATA */
#endif
/*************************************************************************
loops while lcd is busy, returns address counter
*************************************************************************/
static uint8_t lcd_waitbusy(void)
{
/* wait until busy flag is cleared */
for (; lcd_read(0) & (1 << LCD_BUSY); );
/* the address counter is updated 4us after the busy flag is cleared */
delay(2);
/* now read the address counter */
return (lcd_read(0)); // return address counter
}/* lcd_waitbusy */
/*************************************************************************
Move cursor to the start of next line or to the first line if the cursor
is already on the last line.
*************************************************************************/
static inline void lcd_newline(uint8_t pos)
{
register uint8_t addressCounter;
#if LCD_LINES==1
addressCounter = 0;
#endif
#if LCD_LINES==2
if ( pos < (LCD_START_LINE2) )
addressCounter = LCD_START_LINE2;
else
addressCounter = LCD_START_LINE1;
#endif
#if LCD_LINES==4
#if KS0073_4LINES_MODE
if ( pos < LCD_START_LINE2 )
addressCounter = LCD_START_LINE2;
else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3) )
addressCounter = LCD_START_LINE3;
else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4) )
addressCounter = LCD_START_LINE4;
else
addressCounter = LCD_START_LINE1;
#else
if ( pos < LCD_START_LINE3 )
addressCounter = LCD_START_LINE2;
else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4) )
addressCounter = LCD_START_LINE3;
else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2) )
addressCounter = LCD_START_LINE4;
else
addressCounter = LCD_START_LINE1;
#endif
#endif
lcd_command((1 << LCD_DDRAM) + addressCounter);
}/* lcd_newline */
/*
** PUBLIC FUNCTIONS
*/
/*************************************************************************
Send LCD controller instruction command
Input: instruction to send to LCD controller, see HD44780 data sheet
Returns: none
*************************************************************************/
void lcd_command(uint8_t cmd)
{
lcd_waitbusy();
lcd_write(cmd,0);
}
/*************************************************************************
Send data byte to LCD controller
Input: data to send to LCD controller, see HD44780 data sheet
Returns: none
*************************************************************************/
void lcd_data(uint8_t data)
{
lcd_waitbusy();
lcd_write(data,1);
}
/*************************************************************************
Set cursor to specified position
Input: x horizontal position (0: left most position)
y vertical position (0: first line)
Returns: none
*************************************************************************/
void lcd_gotoxy(uint8_t x, uint8_t y)
{
#if LCD_LINES==1
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
#endif
#if LCD_LINES==2
if ( y==0 )
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
else
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
#endif
#if LCD_LINES==4
if ( y==0 )
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
else if ( y==1)
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
else if ( y==2)
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE3 + x);
else /* y==3 */
lcd_command((1 << LCD_DDRAM) + LCD_START_LINE4 + x);
#endif
}/* lcd_gotoxy */
/*************************************************************************
*************************************************************************/
int lcd_getxy(void)
{
return lcd_waitbusy();
}
/*************************************************************************
Clear display and set cursor to home position
*************************************************************************/
void lcd_clrscr(void)
{
lcd_command(1 << LCD_CLR);
}
/*************************************************************************
Set cursor to home position
*************************************************************************/
void lcd_home(void)
{
lcd_command(1 << LCD_HOME);
}
/*************************************************************************
Display character at current cursor position
Input: character to be displayed
Returns: none
*************************************************************************/
void lcd_putc(char c)
{
uint8_t pos;
pos = lcd_waitbusy(); // read busy-flag and address counter
if (c=='\n')
lcd_newline(pos);
else
{
#if LCD_WRAP_LINES==1
#if LCD_LINES==1
if ( pos == LCD_START_LINE1 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1,0);
#elif LCD_LINES==2
if ( pos == LCD_START_LINE1 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2,0);
else if ( pos == LCD_START_LINE2 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1,0);
#elif LCD_LINES==4
if ( pos == LCD_START_LINE1 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2,0);
else if ( pos == LCD_START_LINE2 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE3,0);
else if ( pos == LCD_START_LINE3 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE4,0);
else if ( pos == LCD_START_LINE4 + LCD_DISP_LENGTH )
lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1,0);
#endif
lcd_waitbusy();
#endif
lcd_write(c, 1);
}
}/* lcd_putc */
/*************************************************************************
Display string without auto linefeed
Input: string to be displayed
Returns: none
*************************************************************************/
void lcd_puts(const char *s)
/* print string on lcd (no auto linefeed) */
{
register char c;
while ( (c = *s++) ) {
lcd_putc(c);
}
}/* lcd_puts */
/*************************************************************************
Display string from program memory without auto linefeed
Input: string from program memory be be displayed
Returns: none
*************************************************************************/
void lcd_puts_p(const char *progmem_s)
/* print string from program memory on lcd (no auto linefeed) */
{
register char c;
while ( (c = pgm_read_byte(progmem_s++)) ) {
lcd_putc(c);
}
}/* lcd_puts_p */
/*************************************************************************
Initialize display and select type of cursor
Input: dispAttr LCD_DISP_OFF display off
LCD_DISP_ON display on, cursor off
LCD_DISP_ON_CURSOR display on, cursor on
LCD_DISP_CURSOR_BLINK display on, cursor on flashing
Returns: none
*************************************************************************/
void lcd_init(uint8_t dispAttr)
{
#if LCD_IO_MODE
/*
* Initialize LCD to 4 bit I/O mode
*/
if (
( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
&& ( &LCD_RS_PORT == &LCD_DATA0_PORT) && ( &LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT)
)
{
/* configure all port bits as output (all LCD lines on same port) */
DDR(LCD_DATA0_PORT) |= (1 << LCD_DATA0_PIN) | (1 << LCD_DATA1_PIN) | (1 << LCD_DATA2_PIN) | (1 << LCD_DATA3_PIN) | (1 << LCD_RS_PIN) | (1 << LCD_RW_PIN) | (1 << LCD_E_PIN);
}
else if (
( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
)
{
/* configure all port bits as output (all LCD data lines on same port, but control lines on different ports) */
DDR(LCD_DATA0_PORT) |= (1 << LCD_DATA0_PIN) | (1 << LCD_DATA1_PIN) | (1 << LCD_DATA2_PIN) | (1 << LCD_DATA3_PIN);
DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
}
else
{
/* configure all port bits as output (LCD data and control lines on different ports */
DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
}
delay(16000); /* wait 16ms or more after power-on */
/* initial write to lcd is 8bit */
LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); // _BV(LCD_FUNCTION)>>4;
LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // _BV(LCD_FUNCTION_8BIT)>>4;
lcd_e_toggle();
delay(4992); /* delay, busy flag can't be checked here */
/* repeat last command */
lcd_e_toggle(); delay(64); /* delay, busy flag can't be checked here */
/* repeat last command a third time */
lcd_e_toggle(); delay(64); /* delay, busy flag can't be checked here */
/* now configure for 4bit mode */
LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4
lcd_e_toggle();
delay(64); /* some displays need this additional delay */
/* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */
#else
/*
* Initialize LCD to 8 bit memory mapped mode
*/
/* enable external SRAM (memory mapped lcd) and one wait state */
MCUCR = _BV(SRE) | _BV(SRW);
/* reset LCD */
delay(16000); /* wait 16ms after power-on */
lcd_write(LCD_FUNCTION_8BIT_1LINE,0); /* function set: 8bit interface */
delay(4992); /* wait 5ms */
lcd_write(LCD_FUNCTION_8BIT_1LINE,0); /* function set: 8bit interface */
delay(64); /* wait 64us */
lcd_write(LCD_FUNCTION_8BIT_1LINE,0); /* function set: 8bit interface */
delay(64); /* wait 64us */
#endif
#if KS0073_4LINES_MODE
/* Display with KS0073 controller requires special commands for enabling 4 line mode */
lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON);
lcd_command(KS0073_4LINES_MODE);
lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
#else
lcd_command(LCD_FUNCTION_DEFAULT); /* function set: display lines */
#endif
lcd_command(LCD_DISP_OFF); /* display off */
lcd_clrscr(); /* display clear */
lcd_command(LCD_MODE_DEFAULT); /* set entry mode */
lcd_command(dispAttr); /* display/cursor control */
}/* lcd_init */

View File

@ -1,263 +0,0 @@
#ifndef LCD_H
#define LCD_H
/*************************************************************************
Title : C include file for the HD44780U LCD library (lcd.c)
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
File: $Id: lcd.h,v 1.13.2.2 2006/01/30 19:51:33 peter Exp $
Software: AVR-GCC 3.3
Hardware: any AVR device, memory mapped mode only for AT90S4414/8515/Mega
***************************************************************************/
/**
@defgroup pfleury_lcd LCD library
@code #include <lcd.h> @endcode
@brief Basic routines for interfacing a HD44780U-based text LCD display
Originally based on Volker Oth's LCD library,
changed lcd_init(), added additional constants for lcd_command(),
added 4-bit I/O mode, improved and optimized code.
Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in
4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.
Memory mapped mode compatible with Kanda STK200, but supports also
generation of R/W signal through A8 address line.
@author Peter Fleury pfleury@gmx.ch http://jump.to/fleury
@see The chapter <a href="http://homepage.sunrise.ch/mysunrise/peterfleury/avr-lcd44780.html" target="_blank">Interfacing a HD44780 Based LCD to an AVR</a>
on my home page.
*/
/*@{*/
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
#error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
#endif
#include <inttypes.h>
#include <avr/pgmspace.h>
/**
* @name Definitions for MCU Clock Frequency
* Adapt the MCU clock frequency in Hz to your target.
*/
#define XTAL F_CPU /**< clock frequency in Hz, used to calculate delay timer */
/**
* @name Definition for LCD controller type
* Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
*/
#define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
/**
* @name Definitions for Display Size
* Change these definitions to adapt setting to your display
*/
#define LCD_LINES 2 /**< number of visible lines of the display */
#define LCD_DISP_LENGTH 16 /**< visibles characters per line of the display */
#define LCD_LINE_LENGTH 0x40 /**< internal line length of the display */
#define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */
#define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */
#define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */
#define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */
#define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */
#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */
#if LCD_IO_MODE
/**
* @name Definitions for 4-bit IO mode
* Change LCD_PORT if you want to use a different port for the LCD pins.
*
* The four LCD data lines and the three control lines RS, RW, E can be on the
* same port or on different ports.
* Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
* different ports.
*
* Normally the four data lines should be mapped to bit 0..3 on one port, but it
* is possible to connect these data lines in different order or even on different
* ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
* */
#define LCD_PORT PORTB /**< port for the LCD lines */
#define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN 0 /**< pin for 4bit data bit 0 */
#define LCD_DATA1_PIN 1 /**< pin for 4bit data bit 1 */
#define LCD_DATA2_PIN 2 /**< pin for 4bit data bit 2 */
#define LCD_DATA3_PIN 3 /**< pin for 4bit data bit 3 */
#define LCD_RS_PORT PORTD /**< port for RS line */
#define LCD_RS_PIN 2 /**< pin for RS line */
#define LCD_RW_PORT PORTD /**< port for RW line */
#define LCD_RW_PIN 3 /**< pin for RW line */
#define LCD_E_PORT PORTD /**< port for Enable line */
#define LCD_E_PIN 4 /**< pin for Enable line */
#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || \
defined(__AVR_ATmega8515__)|| defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || \
defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
/*
* memory mapped mode is only supported when the device has an external data memory interface
*/
#define LCD_IO_DATA 0xC000 /* A15=E=1, A14=RS=1 */
#define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0 */
#define LCD_IO_READ 0x0100 /* A8 =R/W=1 (R/W: 1=Read, 0=Write */
#else
#error "external data memory interface not available for this device, use 4-bit IO port mode"
#endif
/**
* @name Definitions for LCD command instructions
* The constants define the various LCD controller instructions which can be passed to the
* function lcd_command(), see HD44780 data sheet for a complete description.
*/
/* instruction register bit positions, see HD44780U data sheet */
#define LCD_CLR 0 /* DB0: clear display */
#define LCD_HOME 1 /* DB1: return to home position */
#define LCD_ENTRY_MODE 2 /* DB2: set entry mode */
#define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */
#define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */
#define LCD_ON 3 /* DB3: turn lcd/cursor on */
#define LCD_ON_DISPLAY 2 /* DB2: turn display on */
#define LCD_ON_CURSOR 1 /* DB1: turn cursor on */
#define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */
#define LCD_MOVE 4 /* DB4: move cursor/display */
#define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */
#define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */
#define LCD_FUNCTION 5 /* DB5: function set */
#define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */
#define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */
#define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */
#define LCD_CGRAM 6 /* DB6: set CG RAM address */
#define LCD_DDRAM 7 /* DB7: set DD RAM address */
#define LCD_BUSY 7 /* DB7: LCD is busy */
/* set entry mode: display shift on/off, dec/inc cursor move direction */
#define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */
#define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */
#define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */
#define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */
/* display on/off, cursor on/off, blinking char at cursor position */
#define LCD_DISP_OFF 0x08 /* display off */
#define LCD_DISP_ON 0x0C /* display on, cursor off */
#define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */
#define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */
#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */
/* move cursor/shift display */
#define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */
#define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */
#define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */
#define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */
/* function set: set interface data length and number of display lines */
#define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */
#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */
#define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */
#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */
#define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )
/**
* @name Functions
*/
/**
@brief Initialize display and select type of cursor
@param dispAttr \b LCD_DISP_OFF display off\n
\b LCD_DISP_ON display on, cursor off\n
\b LCD_DISP_ON_CURSOR display on, cursor on\n
\b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing
@return none
*/
void lcd_init(uint8_t dispAttr);
/**
@brief Clear display and set cursor to home position
@param void
@return none
*/
void lcd_clrscr(void);
/**
@brief Set cursor to home position
@param void
@return none
*/
void lcd_home(void);
/**
@brief Set cursor to specified position
@param x horizontal position\n (0: left most position)
@param y vertical position\n (0: first line)
@return none
*/
void lcd_gotoxy(uint8_t x, uint8_t y);
/**
@brief Display character at current cursor position
@param c character to be displayed
@return none
*/
void lcd_putc(char c);
/**
@brief Display string without auto linefeed
@param s string to be displayed
@return none
*/
void lcd_puts(const char *s);
/**
@brief Display string from program memory without auto linefeed
@param s string from program memory be be displayed
@return none
@see lcd_puts_P
*/
void lcd_puts_p(const char *progmem_s);
/**
@brief Send LCD controller instruction command
@param cmd instruction to send to LCD controller, see HD44780 data sheet
@return none
*/
void lcd_command(uint8_t cmd);
/**
@brief Send data byte to LCD controller
Similar to lcd_putc(), but without interpreting LF
@param data byte to send to LCD controller, see HD44780 data sheet
@return none
*/
void lcd_data(uint8_t data);
/**
@brief macros for automatically storing string constant in program memory
*/
#define lcd_puts_P(__s) lcd_puts_p(PSTR(__s))
/*@}*/
#endif //LCD_H

View File

@ -6,14 +6,6 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include "serial.h" #include "serial.h"
#include "lcd.h"
// write to lcd function for fdev_setup_stream
// static int lcd_putc_fdev(char c, FILE *stream)
// {
// lcd_putc(c);
// return 0;
// }
int serial_putc_fdev(char c, FILE *stream) int serial_putc_fdev(char c, FILE *stream)
{ {
@ -27,9 +19,21 @@ int serial_getc_fdev(FILE *stream)
return (int) serial_popchar(); return (int) serial_popchar();
} }
// static FILE lcdo = FDEV_SETUP_STREAM(lcd_putc_fdev, NULL, _FDEV_SETUP_WRITE);
static FILE serio = FDEV_SETUP_STREAM(serial_putc_fdev, serial_getc_fdev, _FDEV_SETUP_RW); static FILE serio = FDEV_SETUP_STREAM(serial_putc_fdev, serial_getc_fdev, _FDEV_SETUP_RW);
volatile uint32_t xpos;
volatile uint32_t ypos;
volatile uint32_t zpos;
volatile uint32_t edelta;
uint32_t xtarget;
uint32_t ytarget;
uint32_t ztarget;
uint16_t xspeed;
uint16_t yspeed;
uint16_t zspeed;
int main (void) int main (void)
{ {
// set up STDIN/OUT/ERR // set up STDIN/OUT/ERR
@ -38,7 +42,7 @@ int main (void)
stderr = &serio; stderr = &serio;
// set up serial // set up serial
serial_init(19200); serial_init();
sei(); sei();

505
mendel/mendel.i Normal file
View File

@ -0,0 +1,505 @@
# 1 "mendel.c"
# 1 "/home/triffid/ATmega-Skeleton/mendel//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "mendel.c"
# 1 "/usr/lib/gcc/avr/4.4.1/include/stddef.h" 1 3 4
# 149 "/usr/lib/gcc/avr/4.4.1/include/stddef.h" 3 4
typedef int ptrdiff_t;
# 211 "/usr/lib/gcc/avr/4.4.1/include/stddef.h" 3 4
typedef unsigned int size_t;
# 323 "/usr/lib/gcc/avr/4.4.1/include/stddef.h" 3 4
typedef int wchar_t;
# 2 "mendel.c" 2
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 1 3
# 44 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 1 3
# 37 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 1 3
# 121 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 142 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
# 159 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_least8_t;
typedef uint8_t uint_least8_t;
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
# 213 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_fast8_t;
typedef uint8_t uint_fast8_t;
typedef int16_t int_fast16_t;
typedef uint16_t uint_fast16_t;
typedef int32_t int_fast32_t;
typedef uint32_t uint_fast32_t;
typedef int64_t int_fast64_t;
typedef uint64_t uint_fast64_t;
# 273 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# 38 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 2 3
# 77 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;
typedef uint32_t uint_farptr_t;
# 45 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/include/stdarg.h" 1 3 4
# 40 "/usr/lib/gcc/avr/4.4.1/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 102 "/usr/lib/gcc/avr/4.4.1/include/stdarg.h" 3 4
typedef __gnuc_va_list va_list;
# 46 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/include/stddef.h" 1 3 4
# 50 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 2 3
# 242 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
struct __file {
char *buf;
unsigned char unget;
uint8_t flags;
# 261 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
int size;
int len;
int (*put)(char, struct __file *);
int (*get)(struct __file *);
void *udata;
};
# 405 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern struct __file *__iob[];
# 417 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern struct __file *fdevopen(int (*__put)(char, struct __file*), int (*__get)(struct __file*));
# 434 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int fclose(struct __file *__stream);
# 608 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int vfprintf(struct __file *__stream, const char *__fmt, va_list __ap);
extern int vfprintf_P(struct __file *__stream, const char *__fmt, va_list __ap);
extern int fputc(int __c, struct __file *__stream);
extern int putc(int __c, struct __file *__stream);
extern int putchar(int __c);
# 649 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int printf(const char *__fmt, ...);
extern int printf_P(const char *__fmt, ...);
extern int vprintf(const char *__fmt, va_list __ap);
extern int sprintf(char *__s, const char *__fmt, ...);
extern int sprintf_P(char *__s, const char *__fmt, ...);
# 685 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int snprintf(char *__s, size_t __n, const char *__fmt, ...);
extern int snprintf_P(char *__s, size_t __n, const char *__fmt, ...);
extern int vsprintf(char *__s, const char *__fmt, va_list ap);
extern int vsprintf_P(char *__s, const char *__fmt, va_list ap);
# 713 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int vsnprintf(char *__s, size_t __n, const char *__fmt, va_list ap);
extern int vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list ap);
extern int fprintf(struct __file *__stream, const char *__fmt, ...);
extern int fprintf_P(struct __file *__stream, const char *__fmt, ...);
extern int fputs(const char *__str, struct __file *__stream);
extern int fputs_P(const char *__str, struct __file *__stream);
extern int puts(const char *__str);
extern int puts_P(const char *__str);
# 762 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern size_t fwrite(const void *__ptr, size_t __size, size_t __nmemb,
struct __file *__stream);
extern int fgetc(struct __file *__stream);
extern int getc(struct __file *__stream);
extern int getchar(void);
# 810 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int ungetc(int __c, struct __file *__stream);
# 822 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern char *fgets(char *__str, int __size, struct __file *__stream);
extern char *gets(char *__str);
# 840 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern size_t fread(void *__ptr, size_t __size, size_t __nmemb,
struct __file *__stream);
extern void clearerr(struct __file *__stream);
# 857 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int feof(struct __file *__stream);
# 868 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
extern int ferror(struct __file *__stream);
extern int vfscanf(struct __file *__stream, const char *__fmt, va_list __ap);
extern int vfscanf_P(struct __file *__stream, const char *__fmt, va_list __ap);
extern int fscanf(struct __file *__stream, const char *__fmt, ...);
extern int fscanf_P(struct __file *__stream, const char *__fmt, ...);
extern int scanf(const char *__fmt, ...);
extern int scanf_P(const char *__fmt, ...);
extern int vscanf(const char *__fmt, va_list __ap);
extern int sscanf(const char *__buf, const char *__fmt, ...);
extern int sscanf_P(const char *__buf, const char *__fmt, ...);
# 938 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h" 3
static __inline__ int fflush(struct __file *stream __attribute__((unused)))
{
return 0;
}
# 3 "mendel.c" 2
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 1 3
# 99 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 1 3
# 100 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 224 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 1 3
# 36 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iomx8.h" 1 3
# 37 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 2 3
# 225 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 334 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/portpins.h" 1 3
# 335 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/common.h" 1 3
# 337 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/version.h" 1 3
# 339 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h" 1 3
# 234 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h" 3
typedef struct
{
unsigned char low;
unsigned char high;
unsigned char extended;
} __fuse_t;
# 342 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/lock.h" 1 3
# 345 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 6 "mendel.c" 2
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/interrupt.h" 1 3
# 7 "mendel.c" 2
# 1 "serial.h" 1
# 1 "ringbuffer.h" 1
typedef struct {
uint16_t read_pointer;
uint16_t write_pointer;
uint16_t size;
uint8_t data[];
} ringbuffer;
void ringbuffer_init(ringbuffer *buf, int bufsize);
uint16_t ringbuffer_canread(ringbuffer *buf);
uint16_t ringbuffer_canwrite(ringbuffer *buf);
uint8_t ringbuffer_readchar(ringbuffer *buf);
uint8_t ringbuffer_peekchar(ringbuffer *buf, uint16_t index);
uint16_t ringbuffer_readblock(ringbuffer *buf, uint8_t *newbuf, int size);
void ringbuffer_writechar(ringbuffer *buf, uint8_t data);
uint16_t ringbuffer_writeblock(ringbuffer *buf, uint8_t *data, int size);
# 8 "serial.h" 2
extern volatile uint8_t _rx_buffer[];
extern volatile uint8_t _tx_buffer[];
void serial_init(void);
uint16_t serial_rxchars(void);
uint16_t serial_txchars(void);
uint8_t serial_popchar(void);
void serial_writechar(uint8_t data);
uint16_t serial_recvblock(uint8_t *block, int blocksize);
void serial_writeblock(uint8_t *data, int datalen);
# 9 "mendel.c" 2
int serial_putc_fdev(char c, struct __file *stream)
{
serial_writechar((uint8_t) c);
return 0;
}
int serial_getc_fdev(struct __file *stream)
{
for (;serial_rxchars() == 0;);
return (int) serial_popchar();
}
static struct __file serio = { .put = serial_putc_fdev, .get = serial_getc_fdev, .flags = (0x0001|0x0002), .udata = 0, };
int main (void)
{
(__iob[0]) = &serio;
(__iob[1]) = &serio;
(__iob[2]) = &serio;
serial_init();
__asm__ __volatile__ ("sei" ::);
for (;;)
{
}
}

195
mendel/mendel.s Normal file
View File

@ -0,0 +1,195 @@
.file "mendel.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.stabs "/home/triffid/ATmega-Skeleton/mendel/",100,0,2,.Ltext0
.stabs "mendel.c",100,0,2,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.",60,0,0,0
.stabs "int:t(0,1)=r(0,1);-32768;32767;",128,0,1,0
.stabs "char:t(0,2)=@s8;r(0,2);0;255;",128,0,1,0
.stabs "long int:t(0,3)=@s32;r(0,3);020000000000;017777777777;",128,0,1,0
.stabs "unsigned int:t(0,4)=r(0,4);0;0177777;",128,0,1,0
.stabs "long unsigned int:t(0,5)=@s32;r(0,5);0;037777777777;",128,0,1,0
.stabs "long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,1,0
.stabs "long long unsigned int:t(0,7)=@s64;r(0,7);0;01777777777777777777777;",128,0,1,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,1,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;0177777;",128,0,1,0
.stabs "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,1,0
.stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,1,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,1,0
.stabs "double:t(0,13)=r(0,1);4;0;",128,0,1,0
.stabs "long double:t(0,14)=r(0,1);4;0;",128,0,1,0
.stabs "void:t(0,15)=(0,15)",128,0,1,0
.stabs "/usr/lib/gcc/avr/4.4.1/include/stddef.h",130,0,0,0
.stabs "ptrdiff_t:t(1,1)=(0,1)",128,0,149,0
.stabs "size_t:t(1,2)=(0,4)",128,0,211,0
.stabs "wchar_t:t(1,3)=(0,1)",128,0,323,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdio.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h",130,0,0,0
.stabs "int8_t:t(4,1)=(0,10)",128,0,121,0
.stabs "uint8_t:t(4,2)=(0,11)",128,0,122,0
.stabs "int16_t:t(4,3)=(0,1)",128,0,123,0
.stabs "uint16_t:t(4,4)=(0,4)",128,0,124,0
.stabs "int32_t:t(4,5)=(0,3)",128,0,125,0
.stabs "uint32_t:t(4,6)=(0,5)",128,0,126,0
.stabs "int64_t:t(4,7)=(0,6)",128,0,128,0
.stabs "uint64_t:t(4,8)=(0,7)",128,0,129,0
.stabs "intptr_t:t(4,9)=(4,3)",128,0,142,0
.stabs "uintptr_t:t(4,10)=(4,4)",128,0,147,0
.stabs "int_least8_t:t(4,11)=(4,1)",128,0,159,0
.stabs "uint_least8_t:t(4,12)=(4,2)",128,0,164,0
.stabs "int_least16_t:t(4,13)=(4,3)",128,0,169,0
.stabs "uint_least16_t:t(4,14)=(4,4)",128,0,174,0
.stabs "int_least32_t:t(4,15)=(4,5)",128,0,179,0
.stabs "uint_least32_t:t(4,16)=(4,6)",128,0,184,0
.stabs "int_least64_t:t(4,17)=(4,7)",128,0,192,0
.stabs "uint_least64_t:t(4,18)=(4,8)",128,0,199,0
.stabs "int_fast8_t:t(4,19)=(4,1)",128,0,213,0
.stabs "uint_fast8_t:t(4,20)=(4,2)",128,0,218,0
.stabs "int_fast16_t:t(4,21)=(4,3)",128,0,223,0
.stabs "uint_fast16_t:t(4,22)=(4,4)",128,0,228,0
.stabs "int_fast32_t:t(4,23)=(4,5)",128,0,233,0
.stabs "uint_fast32_t:t(4,24)=(4,6)",128,0,238,0
.stabs "int_fast64_t:t(4,25)=(4,7)",128,0,246,0
.stabs "uint_fast64_t:t(4,26)=(4,8)",128,0,253,0
.stabs "intmax_t:t(4,27)=(4,7)",128,0,273,0
.stabs "uintmax_t:t(4,28)=(4,8)",128,0,278,0
.stabn 162,0,0,0
.stabs "int_farptr_t:t(3,1)=(4,5)",128,0,77,0
.stabs "uint_farptr_t:t(3,2)=(4,6)",128,0,81,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/include/stdarg.h",130,0,0,0
.stabs "__gnuc_va_list:t(5,1)=(5,2)=*(0,15)",128,0,40,0
.stabs "va_list:t(5,3)=(5,1)",128,0,102,0
.stabn 162,0,0,0
.stabs "__file:T(2,1)=s14buf:(2,2)=*(0,2),0,16;unget:(0,11),16,8;flags:(4,2),24,8;size:(0,1),32,16;len:(0,1),48,16;put:(2,3)=*(2,4)=f(0,1),64,16;get:(2,5)=*(2,6)=f(0,1),80,16;udata:(2,7)=*(0,15),96,16;;",128,0,0,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h",130,0,0,0
.stabs "__fuse_t:t(7,1)=(7,2)=s3low:(0,11),0,8;high:(0,11),8,8;extended:(0,11),16,8;;",128,0,239,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "serial.h",130,0,0,0
.stabs "ringbuffer.h",130,0,0,0
.stabs "ringbuffer:t(9,1)=(9,2)=s6read_pointer:(4,4),0,16;write_pointer:(4,4),16,16;size:(4,4),32,16;;",128,0,12,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.section .text.main,"ax",@progbits
.stabs "main:F(0,1)",36,0,24,main
.global main
.type main, @function
main:
.stabd 46,0,0
.stabn 68,0,25,.LM0-.LFBB1
.LM0:
.LFBB1:
/* prologue: function */
/* frame size = 0 */
.stabn 68,0,27,.LM1-.LFBB1
.LM1:
ldi r24,lo8(serio)
ldi r25,hi8(serio)
sts (__iob)+1,r25
sts __iob,r24
.stabn 68,0,28,.LM2-.LFBB1
.LM2:
sts (__iob+2)+1,r25
sts __iob+2,r24
.stabn 68,0,29,.LM3-.LFBB1
.LM3:
sts (__iob+4)+1,r25
sts __iob+4,r24
.stabn 68,0,32,.LM4-.LFBB1
.LM4:
call serial_init
.stabn 68,0,34,.LM5-.LFBB1
.LM5:
/* #APP */
; 34 "mendel.c" 1
sei
; 0 "" 2
/* #NOAPP */
.L2:
rjmp .L2
.size main, .-main
.Lscope1:
.stabs "",36,0,0,.Lscope1-.LFBB1
.stabd 78,0,0
.section .text.serial_getc_fdev,"ax",@progbits
.stabs "serial_getc_fdev:F(0,1)",36,0,16,serial_getc_fdev
.stabs "stream:P(0,16)=*(2,1)",64,0,16,24
.global serial_getc_fdev
.type serial_getc_fdev, @function
serial_getc_fdev:
.stabd 46,0,0
.stabn 68,0,17,.LM6-.LFBB2
.LM6:
.LFBB2:
/* prologue: function */
/* frame size = 0 */
.L6:
.stabn 68,0,18,.LM7-.LFBB2
.LM7:
call serial_rxchars
sbiw r24,0
breq .L6
.stabn 68,0,19,.LM8-.LFBB2
.LM8:
call serial_popchar
.stabn 68,0,20,.LM9-.LFBB2
.LM9:
ldi r25,lo8(0)
/* epilogue start */
ret
.size serial_getc_fdev, .-serial_getc_fdev
.Lscope2:
.stabs "",36,0,0,.Lscope2-.LFBB2
.stabd 78,0,0
.section .text.serial_putc_fdev,"ax",@progbits
.stabs "serial_putc_fdev:F(0,1)",36,0,10,serial_putc_fdev
.stabs "c:P(0,2)",64,0,10,24
.stabs "stream:P(0,16)",64,0,10,22
.global serial_putc_fdev
.type serial_putc_fdev, @function
serial_putc_fdev:
.stabd 46,0,0
.stabn 68,0,11,.LM10-.LFBB3
.LM10:
.LFBB3:
/* prologue: function */
/* frame size = 0 */
.stabn 68,0,12,.LM11-.LFBB3
.LM11:
call serial_writechar
.stabn 68,0,14,.LM12-.LFBB3
.LM12:
ldi r24,lo8(0)
ldi r25,hi8(0)
/* epilogue start */
ret
.size serial_putc_fdev, .-serial_putc_fdev
.Lscope3:
.stabs "",36,0,0,.Lscope3-.LFBB3
.stabd 78,0,0
.data
.type serio, @object
.size serio, 14
serio:
.skip 3,0
.byte 3
.skip 4,0
.word gs(serial_putc_fdev)
.word gs(serial_getc_fdev)
.word 0
.stabs "serio:S(2,1)",38,0,22,serio
.text
.stabs "",100,0,0,.Letext0
.Letext0:

274
mendel/ringbuffer.i Normal file
View File

@ -0,0 +1,274 @@
# 1 "ringbuffer.c"
# 1 "/home/triffid/ATmega-Skeleton/mendel//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "ringbuffer.c"
# 1 "ringbuffer.h" 1
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 1 3
# 121 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 142 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
# 159 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_least8_t;
typedef uint8_t uint_least8_t;
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
# 213 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_fast8_t;
typedef uint8_t uint_fast8_t;
typedef int16_t int_fast16_t;
typedef uint16_t uint_fast16_t;
typedef int32_t int_fast32_t;
typedef uint32_t uint_fast32_t;
typedef int64_t int_fast64_t;
typedef uint64_t uint_fast64_t;
# 273 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# 5 "ringbuffer.h" 2
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/interrupt.h" 1 3
# 38 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/interrupt.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 1 3
# 99 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 1 3
# 126 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 1 3
# 77 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;
typedef uint32_t uint_farptr_t;
# 127 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 2 3
# 100 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 224 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 1 3
# 36 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iomx8.h" 1 3
# 37 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 2 3
# 225 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 334 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/portpins.h" 1 3
# 335 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/common.h" 1 3
# 337 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/version.h" 1 3
# 339 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h" 1 3
# 234 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h" 3
typedef struct
{
unsigned char low;
unsigned char high;
unsigned char extended;
} __fuse_t;
# 342 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/lock.h" 1 3
# 345 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 39 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/interrupt.h" 2 3
# 6 "ringbuffer.h" 2
typedef struct {
uint16_t read_pointer;
uint16_t write_pointer;
uint16_t size;
uint8_t data[];
} ringbuffer;
void ringbuffer_init(ringbuffer *buf, int bufsize);
uint16_t ringbuffer_canread(ringbuffer *buf);
uint16_t ringbuffer_canwrite(ringbuffer *buf);
uint8_t ringbuffer_readchar(ringbuffer *buf);
uint8_t ringbuffer_peekchar(ringbuffer *buf, uint16_t index);
uint16_t ringbuffer_readblock(ringbuffer *buf, uint8_t *newbuf, int size);
void ringbuffer_writechar(ringbuffer *buf, uint8_t data);
uint16_t ringbuffer_writeblock(ringbuffer *buf, uint8_t *data, int size);
# 2 "ringbuffer.c" 2
uint16_t _rb_mod(uint16_t num, uint16_t denom)
{
for (; num >= denom; num -= denom);
return num;
}
void ringbuffer_init(ringbuffer *buf, int bufsize)
{
buf->read_pointer = 0;
buf->write_pointer = 0;
buf->size = bufsize - sizeof(ringbuffer);
}
uint16_t ringbuffer_canread(ringbuffer *buf)
{
return _rb_mod(buf->write_pointer + buf->size + buf->size - buf->read_pointer, buf->size);
}
uint16_t ringbuffer_canwrite(ringbuffer *buf)
{
return _rb_mod(buf->read_pointer + buf->size + buf->size - buf->write_pointer - 1, buf->size);
}
uint8_t ringbuffer_readchar(ringbuffer *buf)
{
uint8_t r = 0;
if (ringbuffer_canread(buf))
{
r = buf->data[buf->read_pointer];
buf->read_pointer = _rb_mod(buf->read_pointer + 1, buf->size);
}
return r;
}
void ringbuffer_writechar(ringbuffer *buf, uint8_t data)
{
if (ringbuffer_canwrite(buf))
{
buf->data[buf->write_pointer] = data;
buf->write_pointer = _rb_mod(buf->write_pointer + 1, buf->size);
}
}
uint8_t ringbuffer_peekchar(ringbuffer *buf, uint16_t index)
{
return buf->data[_rb_mod(buf->read_pointer + index, buf->size)];
}
uint16_t ringbuffer_readblock(ringbuffer *buf, uint8_t *newbuf, int size)
{
uint16_t nc, i;
uint8_t *rp, *ms;
if ((nc = ringbuffer_canread(buf)) < size)
size = nc;
if (size)
{
for (i = 0, rp = buf->data + buf->read_pointer, ms = buf->data + buf->size; i < size; i++, rp++)
{
if (rp >= ms)
rp = buf->data;
newbuf[i] = *rp;
}
buf->read_pointer = rp - buf->data;
}
return size;
}
uint16_t ringbuffer_writeblock(ringbuffer *buf, uint8_t *data, int size)
{
uint16_t nc, i;
uint8_t *wp, *ms;
if ((nc = ringbuffer_canwrite(buf)) < size)
size = nc;
if (size)
{
for (i = 0, wp = buf->write_pointer + buf->data, ms = buf->data + buf->size; i < size; i++, wp++)
{
if (wp >= ms)
wp = buf->data;
*wp = data[i];
}
buf->write_pointer = wp - buf->data;
}
return size;
}

738
mendel/ringbuffer.s Normal file
View File

@ -0,0 +1,738 @@
.file "ringbuffer.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.stabs "/home/triffid/ATmega-Skeleton/mendel/",100,0,2,.Ltext0
.stabs "ringbuffer.c",100,0,2,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.",60,0,0,0
.stabs "int:t(0,1)=r(0,1);-32768;32767;",128,0,1,0
.stabs "char:t(0,2)=@s8;r(0,2);0;255;",128,0,1,0
.stabs "long int:t(0,3)=@s32;r(0,3);020000000000;017777777777;",128,0,1,0
.stabs "unsigned int:t(0,4)=r(0,4);0;0177777;",128,0,1,0
.stabs "long unsigned int:t(0,5)=@s32;r(0,5);0;037777777777;",128,0,1,0
.stabs "long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,1,0
.stabs "long long unsigned int:t(0,7)=@s64;r(0,7);0;01777777777777777777777;",128,0,1,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,1,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;0177777;",128,0,1,0
.stabs "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,1,0
.stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,1,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,1,0
.stabs "double:t(0,13)=r(0,1);4;0;",128,0,1,0
.stabs "long double:t(0,14)=r(0,1);4;0;",128,0,1,0
.stabs "void:t(0,15)=(0,15)",128,0,1,0
.stabs "ringbuffer.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h",130,0,0,0
.stabs "int8_t:t(2,1)=(0,10)",128,0,121,0
.stabs "uint8_t:t(2,2)=(0,11)",128,0,122,0
.stabs "int16_t:t(2,3)=(0,1)",128,0,123,0
.stabs "uint16_t:t(2,4)=(0,4)",128,0,124,0
.stabs "int32_t:t(2,5)=(0,3)",128,0,125,0
.stabs "uint32_t:t(2,6)=(0,5)",128,0,126,0
.stabs "int64_t:t(2,7)=(0,6)",128,0,128,0
.stabs "uint64_t:t(2,8)=(0,7)",128,0,129,0
.stabs "intptr_t:t(2,9)=(2,3)",128,0,142,0
.stabs "uintptr_t:t(2,10)=(2,4)",128,0,147,0
.stabs "int_least8_t:t(2,11)=(2,1)",128,0,159,0
.stabs "uint_least8_t:t(2,12)=(2,2)",128,0,164,0
.stabs "int_least16_t:t(2,13)=(2,3)",128,0,169,0
.stabs "uint_least16_t:t(2,14)=(2,4)",128,0,174,0
.stabs "int_least32_t:t(2,15)=(2,5)",128,0,179,0
.stabs "uint_least32_t:t(2,16)=(2,6)",128,0,184,0
.stabs "int_least64_t:t(2,17)=(2,7)",128,0,192,0
.stabs "uint_least64_t:t(2,18)=(2,8)",128,0,199,0
.stabs "int_fast8_t:t(2,19)=(2,1)",128,0,213,0
.stabs "uint_fast8_t:t(2,20)=(2,2)",128,0,218,0
.stabs "int_fast16_t:t(2,21)=(2,3)",128,0,223,0
.stabs "uint_fast16_t:t(2,22)=(2,4)",128,0,228,0
.stabs "int_fast32_t:t(2,23)=(2,5)",128,0,233,0
.stabs "uint_fast32_t:t(2,24)=(2,6)",128,0,238,0
.stabs "int_fast64_t:t(2,25)=(2,7)",128,0,246,0
.stabs "uint_fast64_t:t(2,26)=(2,8)",128,0,253,0
.stabs "intmax_t:t(2,27)=(2,7)",128,0,273,0
.stabs "uintmax_t:t(2,28)=(2,8)",128,0,278,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/interrupt.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h",130,0,0,0
.stabs "int_farptr_t:t(6,1)=(2,5)",128,0,77,0
.stabs "uint_farptr_t:t(6,2)=(2,6)",128,0,81,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h",130,0,0,0
.stabs "__fuse_t:t(7,1)=(7,2)=s3low:(0,11),0,8;high:(0,11),8,8;extended:(0,11),16,8;;",128,0,239,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "ringbuffer:t(1,1)=(1,2)=s6read_pointer:(2,4),0,16;write_pointer:(2,4),16,16;size:(2,4),32,16;;",128,0,12,0
.stabn 162,0,0,0
.section .text._rb_mod,"ax",@progbits
.stabs "_rb_mod:F(2,4)",36,0,3,_rb_mod
.stabs "num:P(2,4)",64,0,3,18
.stabs "denom:P(2,4)",64,0,3,22
.global _rb_mod
.type _rb_mod, @function
_rb_mod:
.stabd 46,0,0
.stabn 68,0,4,.LM0-.LFBB1
.LM0:
.LFBB1:
/* prologue: function */
/* frame size = 0 */
movw r18,r24
.stabn 68,0,5,.LM1-.LFBB1
.LM1:
rjmp .L2
.L3:
sub r18,r22
sbc r19,r23
.L2:
cp r18,r22
cpc r19,r23
brsh .L3
.stabn 68,0,7,.LM2-.LFBB1
.LM2:
movw r24,r18
/* epilogue start */
ret
.size _rb_mod, .-_rb_mod
.Lscope1:
.stabs "",36,0,0,.Lscope1-.LFBB1
.stabd 78,0,0
.section .text.ringbuffer_init,"ax",@progbits
.stabs "ringbuffer_init:F(0,15)",36,0,9,ringbuffer_init
.stabs "buf:P(0,16)=*(1,1)",64,0,9,30
.stabs "bufsize:P(0,1)",64,0,9,22
.global ringbuffer_init
.type ringbuffer_init, @function
ringbuffer_init:
.stabd 46,0,0
.stabn 68,0,10,.LM3-.LFBB2
.LM3:
.LFBB2:
/* prologue: function */
/* frame size = 0 */
movw r30,r24
.stabn 68,0,11,.LM4-.LFBB2
.LM4:
std Z+1,__zero_reg__
st Z,__zero_reg__
.stabn 68,0,12,.LM5-.LFBB2
.LM5:
std Z+3,__zero_reg__
std Z+2,__zero_reg__
.stabn 68,0,13,.LM6-.LFBB2
.LM6:
subi r22,lo8(-(-6))
sbci r23,hi8(-(-6))
std Z+5,r23
std Z+4,r22
/* epilogue start */
.stabn 68,0,14,.LM7-.LFBB2
.LM7:
ret
.size ringbuffer_init, .-ringbuffer_init
.Lscope2:
.stabs "",36,0,0,.Lscope2-.LFBB2
.stabd 78,0,0
.section .text.ringbuffer_canread,"ax",@progbits
.stabs "ringbuffer_canread:F(2,4)",36,0,16,ringbuffer_canread
.stabs "buf:P(0,16)",64,0,16,30
.global ringbuffer_canread
.type ringbuffer_canread, @function
ringbuffer_canread:
.stabd 46,0,0
.stabn 68,0,17,.LM8-.LFBB3
.LM8:
.LFBB3:
/* prologue: function */
/* frame size = 0 */
movw r30,r24
.stabn 68,0,18,.LM9-.LFBB3
.LM9:
ldd r20,Z+4
ldd r21,Z+5
ldd r18,Z+2
ldd r19,Z+3
add r18,r20
adc r19,r21
add r18,r20
adc r19,r21
ld r24,Z
ldd r25,Z+1
sub r18,r24
sbc r19,r25
rjmp .L9
.L10:
.LBB20:
.LBB21:
.stabn 68,0,5,.LM10-.LFBB3
.LM10:
sub r18,r20
sbc r19,r21
.L9:
cp r18,r20
cpc r19,r21
brsh .L10
.LBE21:
.LBE20:
.stabn 68,0,19,.LM11-.LFBB3
.LM11:
movw r24,r18
/* epilogue start */
ret
.size ringbuffer_canread, .-ringbuffer_canread
.stabs "num:r(2,4)",64,0,18,18
.stabn 192,0,0,.LBB20-.LFBB3
.stabn 224,0,0,.LBE20-.LFBB3
.Lscope3:
.stabs "",36,0,0,.Lscope3-.LFBB3
.stabd 78,0,0
.section .text.ringbuffer_canwrite,"ax",@progbits
.stabs "ringbuffer_canwrite:F(2,4)",36,0,21,ringbuffer_canwrite
.stabs "buf:P(0,16)",64,0,21,30
.global ringbuffer_canwrite
.type ringbuffer_canwrite, @function
ringbuffer_canwrite:
.stabd 46,0,0
.stabn 68,0,22,.LM12-.LFBB4
.LM12:
.LFBB4:
/* prologue: function */
/* frame size = 0 */
movw r30,r24
.stabn 68,0,23,.LM13-.LFBB4
.LM13:
ldd r20,Z+4
ldd r21,Z+5
ld r18,Z
ldd r19,Z+1
add r18,r20
adc r19,r21
subi r18,lo8(-(-1))
sbci r19,hi8(-(-1))
add r18,r20
adc r19,r21
ldd r24,Z+2
ldd r25,Z+3
sub r18,r24
sbc r19,r25
rjmp .L13
.L14:
.LBB22:
.LBB23:
.stabn 68,0,5,.LM14-.LFBB4
.LM14:
sub r18,r20
sbc r19,r21
.L13:
cp r18,r20
cpc r19,r21
brsh .L14
.LBE23:
.LBE22:
.stabn 68,0,24,.LM15-.LFBB4
.LM15:
movw r24,r18
/* epilogue start */
ret
.size ringbuffer_canwrite, .-ringbuffer_canwrite
.stabs "num:r(2,4)",64,0,23,18
.stabn 192,0,0,.LBB22-.LFBB4
.stabn 224,0,0,.LBE22-.LFBB4
.Lscope4:
.stabs "",36,0,0,.Lscope4-.LFBB4
.stabd 78,0,0
.section .text.ringbuffer_readchar,"ax",@progbits
.stabs "ringbuffer_readchar:F(2,2)",36,0,26,ringbuffer_readchar
.stabs "buf:P(0,16)",64,0,26,30
.global ringbuffer_readchar
.type ringbuffer_readchar, @function
ringbuffer_readchar:
.stabd 46,0,0
.stabn 68,0,27,.LM16-.LFBB5
.LM16:
.LFBB5:
/* prologue: function */
/* frame size = 0 */
movw r30,r24
.LBB24:
.LBB25:
.stabn 68,0,18,.LM17-.LFBB5
.LM17:
ldd r20,Z+4
ldd r21,Z+5
ld r22,Z
ldd r23,Z+1
ldd r18,Z+2
ldd r19,Z+3
add r18,r20
adc r19,r21
add r18,r20
adc r19,r21
sub r18,r22
sbc r19,r23
rjmp .L17
.L18:
.LBB26:
.LBB27:
.stabn 68,0,5,.LM18-.LFBB5
.LM18:
sub r18,r20
sbc r19,r21
.L17:
cp r18,r20
cpc r19,r21
brsh .L18
.LBE27:
.LBE26:
.LBE25:
.LBE24:
.stabn 68,0,29,.LM19-.LFBB5
.LM19:
cp r18,__zero_reg__
cpc r19,__zero_reg__
brne .L19
ldi r24,lo8(0)
ret
.L19:
.stabn 68,0,31,.LM20-.LFBB5
.LM20:
movw r26,r30
add r26,r22
adc r27,r23
adiw r26,6
ld r24,X
sbiw r26,6
.stabn 68,0,32,.LM21-.LFBB5
.LM21:
movw r18,r22
subi r18,lo8(-(1))
sbci r19,hi8(-(1))
rjmp .L21
.L22:
.LBB28:
.LBB29:
.stabn 68,0,5,.LM22-.LFBB5
.LM22:
sub r18,r20
sbc r19,r21
.L21:
cp r18,r20
cpc r19,r21
brsh .L22
.LBE29:
.LBE28:
.stabn 68,0,32,.LM23-.LFBB5
.LM23:
std Z+1,r19
st Z,r18
.stabn 68,0,35,.LM24-.LFBB5
.LM24:
ret
.size ringbuffer_readchar, .-ringbuffer_readchar
.stabs "r:r(2,2)",64,0,28,24
.stabn 192,0,0,.LFBB5-.LFBB5
.stabs "num:r(2,4)",64,0,18,18
.stabn 192,0,0,.LBB26-.LFBB5
.stabn 224,0,0,.LBE26-.LFBB5
.stabs "num:r(2,4)",64,0,32,18
.stabn 192,0,0,.LBB28-.LFBB5
.stabn 224,0,0,.LBE28-.LFBB5
.stabn 224,0,0,.Lscope5-.LFBB5
.Lscope5:
.stabs "",36,0,0,.Lscope5-.LFBB5
.stabd 78,0,0
.section .text.ringbuffer_writechar,"ax",@progbits
.stabs "ringbuffer_writechar:F(0,15)",36,0,37,ringbuffer_writechar
.stabs "buf:P(0,16)",64,0,37,16
.stabs "data:P(2,2)",64,0,37,22
.global ringbuffer_writechar
.type ringbuffer_writechar, @function
ringbuffer_writechar:
.stabd 46,0,0
.stabn 68,0,38,.LM25-.LFBB6
.LM25:
.LFBB6:
push r16
push r17
push r29
push r28
push __tmp_reg__
in r28,__SP_L__
in r29,__SP_H__
/* prologue: function */
/* frame size = 1 */
movw r16,r24
.stabn 68,0,39,.LM26-.LFBB6
.LM26:
std Y+1,r22
call ringbuffer_canwrite
ldd r22,Y+1
sbiw r24,0
breq .L28
.stabn 68,0,41,.LM27-.LFBB6
.LM27:
movw r30,r16
ldd r24,Z+2
ldd r25,Z+3
add r30,r24
adc r31,r25
std Z+6,r22
.stabn 68,0,42,.LM28-.LFBB6
.LM28:
adiw r24,1
movw r30,r16
ldd r18,Z+4
ldd r19,Z+5
rjmp .L26
.L27:
.LBB30:
.LBB31:
.stabn 68,0,5,.LM29-.LFBB6
.LM29:
sub r24,r18
sbc r25,r19
.L26:
cp r24,r18
cpc r25,r19
brsh .L27
.LBE31:
.LBE30:
.stabn 68,0,42,.LM30-.LFBB6
.LM30:
movw r30,r16
std Z+3,r25
std Z+2,r24
.L28:
/* epilogue start */
.stabn 68,0,44,.LM31-.LFBB6
.LM31:
pop __tmp_reg__
pop r28
pop r29
pop r17
pop r16
ret
.size ringbuffer_writechar, .-ringbuffer_writechar
.stabs "num:r(2,4)",64,0,42,24
.stabn 192,0,0,.LBB30-.LFBB6
.stabn 224,0,0,.LBE30-.LFBB6
.Lscope6:
.stabs "",36,0,0,.Lscope6-.LFBB6
.stabd 78,0,0
.section .text.ringbuffer_peekchar,"ax",@progbits
.stabs "ringbuffer_peekchar:F(2,2)",36,0,47,ringbuffer_peekchar
.stabs "buf:P(0,16)",64,0,47,30
.stabs "index:P(2,4)",64,0,47,22
.global ringbuffer_peekchar
.type ringbuffer_peekchar, @function
ringbuffer_peekchar:
.stabd 46,0,0
.stabn 68,0,48,.LM32-.LFBB7
.LM32:
.LFBB7:
/* prologue: function */
/* frame size = 0 */
movw r30,r24
.stabn 68,0,49,.LM33-.LFBB7
.LM33:
ld r24,Z
ldd r25,Z+1
add r22,r24
adc r23,r25
ldd r24,Z+4
ldd r25,Z+5
rjmp .L30
.L31:
.LBB32:
.LBB33:
.stabn 68,0,5,.LM34-.LFBB7
.LM34:
sub r22,r24
sbc r23,r25
.L30:
cp r22,r24
cpc r23,r25
brsh .L31
add r30,r22
adc r31,r23
.LBE33:
.LBE32:
.stabn 68,0,50,.LM35-.LFBB7
.LM35:
ldd r24,Z+6
/* epilogue start */
ret
.size ringbuffer_peekchar, .-ringbuffer_peekchar
.stabs "num:r(2,4)",64,0,49,22
.stabn 192,0,0,.LBB32-.LFBB7
.stabn 224,0,0,.LBE32-.LFBB7
.Lscope7:
.stabs "",36,0,0,.Lscope7-.LFBB7
.stabd 78,0,0
.section .text.ringbuffer_readblock,"ax",@progbits
.stabs "ringbuffer_readblock:F(2,4)",36,0,52,ringbuffer_readblock
.stabs "buf:P(0,16)",64,0,52,30
.stabs "newbuf:P(0,17)=*(2,2)",64,0,52,22
.stabs "size:P(0,1)",64,0,52,20
.global ringbuffer_readblock
.type ringbuffer_readblock, @function
ringbuffer_readblock:
.stabd 46,0,0
.stabn 68,0,53,.LM36-.LFBB8
.LM36:
.LFBB8:
push r12
push r13
push r15
push r16
push r17
push r28
push r29
/* prologue: function */
/* frame size = 0 */
movw r30,r24
.LBB34:
.LBB35:
.stabn 68,0,18,.LM37-.LFBB8
.LM37:
ldd r18,Z+4
ldd r19,Z+5
ld r26,Z
ldd r27,Z+1
ldd r24,Z+2
ldd r25,Z+3
add r24,r18
adc r25,r19
add r24,r18
adc r25,r19
sub r24,r26
sbc r25,r27
rjmp .L34
.L35:
.LBB36:
.LBB37:
.stabn 68,0,5,.LM38-.LFBB8
.LM38:
sub r24,r18
sbc r25,r19
.L34:
cp r24,r18
cpc r25,r19
brsh .L35
.LBE37:
.LBE36:
.LBE35:
.LBE34:
.stabn 68,0,56,.LM39-.LFBB8
.LM39:
cp r24,r20
cpc r25,r21
brsh .L36
.stabn 68,0,57,.LM40-.LFBB8
.LM40:
movw r20,r24
.L36:
.stabn 68,0,58,.LM41-.LFBB8
.LM41:
cp r20,__zero_reg__
cpc r21,__zero_reg__
breq .L37
.stabn 68,0,60,.LM42-.LFBB8
.LM42:
adiw r26,6
add r26,r30
adc r27,r31
subi r18,lo8(-(6))
sbci r19,hi8(-(6))
add r18,r30
adc r19,r31
.stabn 68,0,63,.LM43-.LFBB8
.LM43:
ldi r24,lo8(6)
mov r12,r24
mov r13,__zero_reg__
add r12,r30
adc r13,r31
ldi r24,lo8(0)
ldi r25,hi8(0)
.stabn 68,0,60,.LM44-.LFBB8
.LM44:
rjmp .L38
.L40:
.stabn 68,0,62,.LM45-.LFBB8
.LM45:
cp r26,r18
cpc r27,r19
brlo .L39
movw r26,r12
.L39:
.stabn 68,0,64,.LM46-.LFBB8
.LM46:
movw r16,r22
add r16,r24
adc r17,r25
ld r15,X+
movw r28,r16
st Y,r15
.stabn 68,0,60,.LM47-.LFBB8
.LM47:
adiw r24,1
.L38:
cp r24,r20
cpc r25,r21
brlo .L40
.stabn 68,0,66,.LM48-.LFBB8
.LM48:
movw r24,r30
adiw r24,6
sub r26,r24
sbc r27,r25
std Z+1,r27
st Z,r26
.L37:
.stabn 68,0,69,.LM49-.LFBB8
.LM49:
movw r24,r20
/* epilogue start */
pop r29
pop r28
pop r17
pop r16
pop r15
pop r13
pop r12
ret
.size ringbuffer_readblock, .-ringbuffer_readblock
.stabs "nc:r(2,4)",64,0,54,24
.stabs "i:r(2,4)",64,0,54,24
.stabs "rp:r(0,17)",64,0,55,26
.stabs "ms:r(0,17)",64,0,55,18
.stabn 192,0,0,.LFBB8-.LFBB8
.stabn 224,0,0,.Lscope8-.LFBB8
.Lscope8:
.stabs "",36,0,0,.Lscope8-.LFBB8
.stabd 78,0,0
.section .text.ringbuffer_writeblock,"ax",@progbits
.stabs "ringbuffer_writeblock:F(2,4)",36,0,71,ringbuffer_writeblock
.stabs "buf:P(0,16)",64,0,71,28
.stabs "data:P(0,17)",64,0,71,16
.stabs "size:P(0,1)",64,0,71,14
.global ringbuffer_writeblock
.type ringbuffer_writeblock, @function
ringbuffer_writeblock:
.stabd 46,0,0
.stabn 68,0,72,.LM50-.LFBB9
.LM50:
.LFBB9:
push r14
push r15
push r16
push r17
push r28
push r29
/* prologue: function */
/* frame size = 0 */
movw r28,r24
movw r16,r22
movw r14,r20
.stabn 68,0,76,.LM51-.LFBB9
.LM51:
call ringbuffer_canwrite
cp r24,r14
cpc r25,r15
brsh .L43
.stabn 68,0,77,.LM52-.LFBB9
.LM52:
movw r14,r24
.L43:
.stabn 68,0,78,.LM53-.LFBB9
.LM53:
cp r14,__zero_reg__
cpc r15,__zero_reg__
breq .L44
.stabn 68,0,80,.LM54-.LFBB9
.LM54:
ldd r30,Y+2
ldd r31,Y+3
adiw r30,6
add r30,r28
adc r31,r29
ldd r24,Y+4
ldd r25,Y+5
adiw r24,6
add r24,r28
adc r25,r29
.stabn 68,0,83,.LM55-.LFBB9
.LM55:
movw r20,r28
subi r20,lo8(-(6))
sbci r21,hi8(-(6))
ldi r18,lo8(0)
ldi r19,hi8(0)
.stabn 68,0,80,.LM56-.LFBB9
.LM56:
rjmp .L45
.L47:
.stabn 68,0,82,.LM57-.LFBB9
.LM57:
cp r30,r24
cpc r31,r25
brlo .L46
movw r30,r20
.L46:
.stabn 68,0,84,.LM58-.LFBB9
.LM58:
movw r26,r16
add r26,r18
adc r27,r19
ld r22,X
st Z+,r22
.stabn 68,0,80,.LM59-.LFBB9
.LM59:
subi r18,lo8(-(1))
sbci r19,hi8(-(1))
.L45:
cp r18,r14
cpc r19,r15
brlo .L47
.stabn 68,0,86,.LM60-.LFBB9
.LM60:
movw r24,r28
adiw r24,6
sub r30,r24
sbc r31,r25
std Y+3,r31
std Y+2,r30
.L44:
.stabn 68,0,89,.LM61-.LFBB9
.LM61:
movw r24,r14
/* epilogue start */
pop r29
pop r28
pop r17
pop r16
pop r15
pop r14
ret
.size ringbuffer_writeblock, .-ringbuffer_writeblock
.stabs "nc:r(2,4)",64,0,73,24
.stabs "i:r(2,4)",64,0,73,18
.stabs "wp:r(0,17)",64,0,74,30
.stabs "ms:r(0,17)",64,0,74,24
.stabn 192,0,0,.LFBB9-.LFBB9
.stabn 224,0,0,.Lscope9-.LFBB9
.Lscope9:
.stabs "",36,0,0,.Lscope9-.LFBB9
.stabd 78,0,0
.text
.stabs "",100,0,0,.Letext0
.Letext0:

View File

@ -8,7 +8,7 @@
volatile uint8_t _rx_buffer[BUFSIZE]; volatile uint8_t _rx_buffer[BUFSIZE];
volatile uint8_t _tx_buffer[BUFSIZE]; volatile uint8_t _tx_buffer[BUFSIZE];
void serial_init(uint16_t baud) void serial_init()
{ {
ringbuffer_init(rx_buffer, BUFSIZE); ringbuffer_init(rx_buffer, BUFSIZE);
ringbuffer_init(tx_buffer, BUFSIZE); ringbuffer_init(tx_buffer, BUFSIZE);
@ -17,7 +17,7 @@ void serial_init(uint16_t baud)
UCSR0B = (1 << RXEN0) | (1 << TXEN0); UCSR0B = (1 << RXEN0) | (1 << TXEN0);
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
UBRR0 = ((F_CPU / 16) / baud) - 1; UBRR0 = ((F_CPU / 16) / BAUD) - 1;
UCSR0B |= (1 << RXCIE0) | (1 << UDRIE0); UCSR0B |= (1 << RXCIE0) | (1 << UDRIE0);
} }

View File

@ -12,7 +12,7 @@
extern volatile uint8_t _rx_buffer[]; extern volatile uint8_t _rx_buffer[];
extern volatile uint8_t _tx_buffer[]; extern volatile uint8_t _tx_buffer[];
void serial_init(uint16_t baud); void serial_init(void);
uint16_t serial_rxchars(void); uint16_t serial_rxchars(void);
uint16_t serial_txchars(void); uint16_t serial_txchars(void);

280
mendel/serial.i Normal file
View File

@ -0,0 +1,280 @@
# 1 "serial.c"
# 1 "/home/triffid/ATmega-Skeleton/mendel//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "serial.c"
# 1 "serial.h" 1
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 1 3
# 121 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 142 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
# 159 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_least8_t;
typedef uint8_t uint_least8_t;
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
# 213 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_fast8_t;
typedef uint8_t uint_fast8_t;
typedef int16_t int_fast16_t;
typedef uint16_t uint_fast16_t;
typedef int32_t int_fast32_t;
typedef uint32_t uint_fast32_t;
typedef int64_t int_fast64_t;
typedef uint64_t uint_fast64_t;
# 273 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h" 3
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# 5 "serial.h" 2
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 1 3
# 99 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 1 3
# 126 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 1 3
# 77 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;
typedef uint32_t uint_farptr_t;
# 127 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h" 2 3
# 100 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 224 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 1 3
# 36 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iomx8.h" 1 3
# 37 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/iom168.h" 2 3
# 225 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 334 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/portpins.h" 1 3
# 335 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/common.h" 1 3
# 337 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/version.h" 1 3
# 339 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h" 1 3
# 234 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h" 3
typedef struct
{
unsigned char low;
unsigned char high;
unsigned char extended;
} __fuse_t;
# 342 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/lock.h" 1 3
# 345 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h" 2 3
# 6 "serial.h" 2
# 1 "ringbuffer.h" 1
# 1 "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/interrupt.h" 1 3
# 6 "ringbuffer.h" 2
typedef struct {
uint16_t read_pointer;
uint16_t write_pointer;
uint16_t size;
uint8_t data[];
} ringbuffer;
void ringbuffer_init(ringbuffer *buf, int bufsize);
uint16_t ringbuffer_canread(ringbuffer *buf);
uint16_t ringbuffer_canwrite(ringbuffer *buf);
uint8_t ringbuffer_readchar(ringbuffer *buf);
uint8_t ringbuffer_peekchar(ringbuffer *buf, uint16_t index);
uint16_t ringbuffer_readblock(ringbuffer *buf, uint8_t *newbuf, int size);
void ringbuffer_writechar(ringbuffer *buf, uint8_t data);
uint16_t ringbuffer_writeblock(ringbuffer *buf, uint8_t *data, int size);
# 8 "serial.h" 2
extern volatile uint8_t _rx_buffer[];
extern volatile uint8_t _tx_buffer[];
void serial_init(void);
uint16_t serial_rxchars(void);
uint16_t serial_txchars(void);
uint8_t serial_popchar(void);
void serial_writechar(uint8_t data);
uint16_t serial_recvblock(uint8_t *block, int blocksize);
void serial_writeblock(uint8_t *data, int datalen);
# 2 "serial.c" 2
volatile uint8_t _rx_buffer[64 + sizeof(ringbuffer)];
volatile uint8_t _tx_buffer[64 + sizeof(ringbuffer)];
void serial_init()
{
ringbuffer_init(((ringbuffer *) _rx_buffer), 64 + sizeof(ringbuffer));
ringbuffer_init(((ringbuffer *) _tx_buffer), 64 + sizeof(ringbuffer));
(*(volatile uint8_t *)(0xC0)) = 0;
(*(volatile uint8_t *)(0xC1)) = (1 << 4) | (1 << 3);
(*(volatile uint8_t *)(0xC2)) = (1 << 2) | (1 << 1);
(*(volatile uint16_t *)(0xC4)) = ((16000000L / 16) / 19200) - 1;
(*(volatile uint8_t *)(0xC1)) |= (1 << 7) | (1 << 5);
}
void __vector_18 (void) __attribute__ ((signal,used, externally_visible)) ; void __vector_18 (void)
{
ringbuffer_writechar(((ringbuffer *) _rx_buffer), (*(volatile uint8_t *)(0xC6)));
}
void __vector_19 (void) __attribute__ ((signal,used, externally_visible)) ; void __vector_19 (void)
{
if (ringbuffer_canread(((ringbuffer *) _tx_buffer)))
{
(*(volatile uint8_t *)(0xC6)) = ringbuffer_readchar(((ringbuffer *) _tx_buffer));
}
else
{
(*(volatile uint8_t *)(0xC1)) &= ~(1 << 5);
}
}
uint16_t serial_rxchars()
{
return ringbuffer_canread(((ringbuffer *) _rx_buffer));
}
uint16_t serial_txchars()
{
return ringbuffer_canread(((ringbuffer *) _tx_buffer));
}
uint8_t serial_popchar()
{
return ringbuffer_readchar(((ringbuffer *) _rx_buffer));
}
uint16_t serial_recvblock(uint8_t *block, int blocksize)
{
return ringbuffer_readblock(((ringbuffer *) _rx_buffer), block, blocksize);
}
void serial_writechar(uint8_t data)
{
ringbuffer_writechar(((ringbuffer *) _tx_buffer), data);
(*(volatile uint8_t *)(0xC1)) |= (1 << 5);
}
void serial_writeblock(uint8_t *data, int datalen)
{
ringbuffer_writeblock(((ringbuffer *) _tx_buffer), data, datalen);
(*(volatile uint8_t *)(0xC1)) |= (1 << 5);
}

439
mendel/serial.s Normal file
View File

@ -0,0 +1,439 @@
.file "serial.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.stabs "/home/triffid/ATmega-Skeleton/mendel/",100,0,2,.Ltext0
.stabs "serial.c",100,0,2,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.",60,0,0,0
.stabs "int:t(0,1)=r(0,1);-32768;32767;",128,0,1,0
.stabs "char:t(0,2)=@s8;r(0,2);0;255;",128,0,1,0
.stabs "long int:t(0,3)=@s32;r(0,3);020000000000;017777777777;",128,0,1,0
.stabs "unsigned int:t(0,4)=r(0,4);0;0177777;",128,0,1,0
.stabs "long unsigned int:t(0,5)=@s32;r(0,5);0;037777777777;",128,0,1,0
.stabs "long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,1,0
.stabs "long long unsigned int:t(0,7)=@s64;r(0,7);0;01777777777777777777777;",128,0,1,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,1,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;0177777;",128,0,1,0
.stabs "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,1,0
.stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,1,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,1,0
.stabs "double:t(0,13)=r(0,1);4;0;",128,0,1,0
.stabs "long double:t(0,14)=r(0,1);4;0;",128,0,1,0
.stabs "void:t(0,15)=(0,15)",128,0,1,0
.stabs "serial.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/stdint.h",130,0,0,0
.stabs "int8_t:t(2,1)=(0,10)",128,0,121,0
.stabs "uint8_t:t(2,2)=(0,11)",128,0,122,0
.stabs "int16_t:t(2,3)=(0,1)",128,0,123,0
.stabs "uint16_t:t(2,4)=(0,4)",128,0,124,0
.stabs "int32_t:t(2,5)=(0,3)",128,0,125,0
.stabs "uint32_t:t(2,6)=(0,5)",128,0,126,0
.stabs "int64_t:t(2,7)=(0,6)",128,0,128,0
.stabs "uint64_t:t(2,8)=(0,7)",128,0,129,0
.stabs "intptr_t:t(2,9)=(2,3)",128,0,142,0
.stabs "uintptr_t:t(2,10)=(2,4)",128,0,147,0
.stabs "int_least8_t:t(2,11)=(2,1)",128,0,159,0
.stabs "uint_least8_t:t(2,12)=(2,2)",128,0,164,0
.stabs "int_least16_t:t(2,13)=(2,3)",128,0,169,0
.stabs "uint_least16_t:t(2,14)=(2,4)",128,0,174,0
.stabs "int_least32_t:t(2,15)=(2,5)",128,0,179,0
.stabs "uint_least32_t:t(2,16)=(2,6)",128,0,184,0
.stabs "int_least64_t:t(2,17)=(2,7)",128,0,192,0
.stabs "uint_least64_t:t(2,18)=(2,8)",128,0,199,0
.stabs "int_fast8_t:t(2,19)=(2,1)",128,0,213,0
.stabs "uint_fast8_t:t(2,20)=(2,2)",128,0,218,0
.stabs "int_fast16_t:t(2,21)=(2,3)",128,0,223,0
.stabs "uint_fast16_t:t(2,22)=(2,4)",128,0,228,0
.stabs "int_fast32_t:t(2,23)=(2,5)",128,0,233,0
.stabs "uint_fast32_t:t(2,24)=(2,6)",128,0,238,0
.stabs "int_fast64_t:t(2,25)=(2,7)",128,0,246,0
.stabs "uint_fast64_t:t(2,26)=(2,8)",128,0,253,0
.stabs "intmax_t:t(2,27)=(2,7)",128,0,273,0
.stabs "uintmax_t:t(2,28)=(2,8)",128,0,278,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/io.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/sfr_defs.h",130,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/inttypes.h",130,0,0,0
.stabs "int_farptr_t:t(5,1)=(2,5)",128,0,77,0
.stabs "uint_farptr_t:t(5,2)=(2,6)",128,0,81,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "/usr/lib/gcc/avr/4.4.1/../../../../avr/include/avr/fuse.h",130,0,0,0
.stabs "__fuse_t:t(6,1)=(6,2)=s3low:(0,11),0,8;high:(0,11),8,8;extended:(0,11),16,8;;",128,0,239,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "ringbuffer.h",130,0,0,0
.stabs "ringbuffer:t(7,1)=(7,2)=s6read_pointer:(2,4),0,16;write_pointer:(2,4),16,16;size:(2,4),32,16;;",128,0,12,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.section .text.serial_writeblock,"ax",@progbits
.stabs "serial_writeblock:F(0,15)",36,0,68,serial_writeblock
.stabs "data:P(0,16)=*(2,2)",64,0,68,18
.stabs "datalen:P(0,1)",64,0,68,20
.global serial_writeblock
.type serial_writeblock, @function
serial_writeblock:
.stabd 46,0,0
.stabn 68,0,69,.LM0-.LFBB1
.LM0:
.LFBB1:
/* prologue: function */
/* frame size = 0 */
movw r18,r24
movw r20,r22
.stabn 68,0,70,.LM1-.LFBB1
.LM1:
ldi r24,lo8(_tx_buffer)
ldi r25,hi8(_tx_buffer)
movw r22,r18
call ringbuffer_writeblock
.stabn 68,0,71,.LM2-.LFBB1
.LM2:
ldi r30,lo8(193)
ldi r31,hi8(193)
ld r24,Z
ori r24,lo8(32)
st Z,r24
/* epilogue start */
.stabn 68,0,72,.LM3-.LFBB1
.LM3:
ret
.size serial_writeblock, .-serial_writeblock
.Lscope1:
.stabs "",36,0,0,.Lscope1-.LFBB1
.stabd 78,0,0
.section .text.serial_writechar,"ax",@progbits
.stabs "serial_writechar:F(0,15)",36,0,62,serial_writechar
.stabs "data:P(2,2)",64,0,62,22
.global serial_writechar
.type serial_writechar, @function
serial_writechar:
.stabd 46,0,0
.stabn 68,0,63,.LM4-.LFBB2
.LM4:
.LFBB2:
/* prologue: function */
/* frame size = 0 */
mov r22,r24
.stabn 68,0,64,.LM5-.LFBB2
.LM5:
ldi r24,lo8(_tx_buffer)
ldi r25,hi8(_tx_buffer)
call ringbuffer_writechar
.stabn 68,0,65,.LM6-.LFBB2
.LM6:
ldi r30,lo8(193)
ldi r31,hi8(193)
ld r24,Z
ori r24,lo8(32)
st Z,r24
/* epilogue start */
.stabn 68,0,66,.LM7-.LFBB2
.LM7:
ret
.size serial_writechar, .-serial_writechar
.Lscope2:
.stabs "",36,0,0,.Lscope2-.LFBB2
.stabd 78,0,0
.section .text.__vector_18,"ax",@progbits
.stabs "__vector_18:F(0,15)",36,0,25,__vector_18
.global __vector_18
.type __vector_18, @function
__vector_18:
.stabd 46,0,0
.stabn 68,0,26,.LM8-.LFBB3
.LM8:
.LFBB3:
push __zero_reg__
push r0
in r0,__SREG__
push r0
clr __zero_reg__
push r18
push r19
push r20
push r21
push r22
push r23
push r24
push r25
push r26
push r27
push r30
push r31
/* prologue: Signal */
/* frame size = 0 */
.stabn 68,0,27,.LM9-.LFBB3
.LM9:
lds r22,198
ldi r24,lo8(_rx_buffer)
ldi r25,hi8(_rx_buffer)
call ringbuffer_writechar
/* epilogue start */
.stabn 68,0,28,.LM10-.LFBB3
.LM10:
pop r31
pop r30
pop r27
pop r26
pop r25
pop r24
pop r23
pop r22
pop r21
pop r20
pop r19
pop r18
pop r0
out __SREG__,r0
pop r0
pop __zero_reg__
reti
.size __vector_18, .-__vector_18
.Lscope3:
.stabs "",36,0,0,.Lscope3-.LFBB3
.stabd 78,0,0
.section .text.serial_recvblock,"ax",@progbits
.stabs "serial_recvblock:F(2,4)",36,0,57,serial_recvblock
.stabs "block:P(0,16)",64,0,57,18
.stabs "blocksize:P(0,1)",64,0,57,20
.global serial_recvblock
.type serial_recvblock, @function
serial_recvblock:
.stabd 46,0,0
.stabn 68,0,58,.LM11-.LFBB4
.LM11:
.LFBB4:
/* prologue: function */
/* frame size = 0 */
movw r18,r24
movw r20,r22
.stabn 68,0,59,.LM12-.LFBB4
.LM12:
ldi r24,lo8(_rx_buffer)
ldi r25,hi8(_rx_buffer)
movw r22,r18
call ringbuffer_readblock
/* epilogue start */
.stabn 68,0,60,.LM13-.LFBB4
.LM13:
ret
.size serial_recvblock, .-serial_recvblock
.Lscope4:
.stabs "",36,0,0,.Lscope4-.LFBB4
.stabd 78,0,0
.section .text.serial_popchar,"ax",@progbits
.stabs "serial_popchar:F(2,2)",36,0,52,serial_popchar
.global serial_popchar
.type serial_popchar, @function
serial_popchar:
.stabd 46,0,0
.stabn 68,0,53,.LM14-.LFBB5
.LM14:
.LFBB5:
/* prologue: function */
/* frame size = 0 */
.stabn 68,0,54,.LM15-.LFBB5
.LM15:
ldi r24,lo8(_rx_buffer)
ldi r25,hi8(_rx_buffer)
call ringbuffer_readchar
/* epilogue start */
.stabn 68,0,55,.LM16-.LFBB5
.LM16:
ret
.size serial_popchar, .-serial_popchar
.Lscope5:
.stabs "",36,0,0,.Lscope5-.LFBB5
.stabd 78,0,0
.section .text.serial_txchars,"ax",@progbits
.stabs "serial_txchars:F(2,4)",36,0,47,serial_txchars
.global serial_txchars
.type serial_txchars, @function
serial_txchars:
.stabd 46,0,0
.stabn 68,0,48,.LM17-.LFBB6
.LM17:
.LFBB6:
/* prologue: function */
/* frame size = 0 */
.stabn 68,0,49,.LM18-.LFBB6
.LM18:
ldi r24,lo8(_tx_buffer)
ldi r25,hi8(_tx_buffer)
call ringbuffer_canread
/* epilogue start */
.stabn 68,0,50,.LM19-.LFBB6
.LM19:
ret
.size serial_txchars, .-serial_txchars
.Lscope6:
.stabs "",36,0,0,.Lscope6-.LFBB6
.stabd 78,0,0
.section .text.serial_rxchars,"ax",@progbits
.stabs "serial_rxchars:F(2,4)",36,0,42,serial_rxchars
.global serial_rxchars
.type serial_rxchars, @function
serial_rxchars:
.stabd 46,0,0
.stabn 68,0,43,.LM20-.LFBB7
.LM20:
.LFBB7:
/* prologue: function */
/* frame size = 0 */
.stabn 68,0,44,.LM21-.LFBB7
.LM21:
ldi r24,lo8(_rx_buffer)
ldi r25,hi8(_rx_buffer)
call ringbuffer_canread
/* epilogue start */
.stabn 68,0,45,.LM22-.LFBB7
.LM22:
ret
.size serial_rxchars, .-serial_rxchars
.Lscope7:
.stabs "",36,0,0,.Lscope7-.LFBB7
.stabd 78,0,0
.section .text.__vector_19,"ax",@progbits
.stabs "__vector_19:F(0,15)",36,0,30,__vector_19
.global __vector_19
.type __vector_19, @function
__vector_19:
.stabd 46,0,0
.stabn 68,0,31,.LM23-.LFBB8
.LM23:
.LFBB8:
push __zero_reg__
push r0
in r0,__SREG__
push r0
clr __zero_reg__
push r18
push r19
push r20
push r21
push r22
push r23
push r24
push r25
push r26
push r27
push r30
push r31
/* prologue: Signal */
/* frame size = 0 */
.stabn 68,0,32,.LM24-.LFBB8
.LM24:
ldi r24,lo8(_tx_buffer)
ldi r25,hi8(_tx_buffer)
call ringbuffer_canread
sbiw r24,0
breq .L16
.stabn 68,0,34,.LM25-.LFBB8
.LM25:
ldi r24,lo8(_tx_buffer)
ldi r25,hi8(_tx_buffer)
call ringbuffer_readchar
sts 198,r24
rjmp .L18
.L16:
.stabn 68,0,38,.LM26-.LFBB8
.LM26:
lds r24,193
andi r24,lo8(-33)
sts 193,r24
.L18:
/* epilogue start */
.stabn 68,0,40,.LM27-.LFBB8
.LM27:
pop r31
pop r30
pop r27
pop r26
pop r25
pop r24
pop r23
pop r22
pop r21
pop r20
pop r19
pop r18
pop r0
out __SREG__,r0
pop r0
pop __zero_reg__
reti
.size __vector_19, .-__vector_19
.Lscope8:
.stabs "",36,0,0,.Lscope8-.LFBB8
.stabd 78,0,0
.section .text.serial_init,"ax",@progbits
.stabs "serial_init:F(0,15)",36,0,11,serial_init
.global serial_init
.type serial_init, @function
serial_init:
.stabd 46,0,0
.stabn 68,0,12,.LM28-.LFBB9
.LM28:
.LFBB9:
/* prologue: function */
/* frame size = 0 */
.stabn 68,0,13,.LM29-.LFBB9
.LM29:
ldi r24,lo8(_rx_buffer)
ldi r25,hi8(_rx_buffer)
ldi r22,lo8(70)
ldi r23,hi8(70)
call ringbuffer_init
.stabn 68,0,14,.LM30-.LFBB9
.LM30:
ldi r24,lo8(_tx_buffer)
ldi r25,hi8(_tx_buffer)
ldi r22,lo8(70)
ldi r23,hi8(70)
call ringbuffer_init
.stabn 68,0,16,.LM31-.LFBB9
.LM31:
sts 192,__zero_reg__
.stabn 68,0,17,.LM32-.LFBB9
.LM32:
ldi r30,lo8(193)
ldi r31,hi8(193)
ldi r24,lo8(24)
st Z,r24
.stabn 68,0,18,.LM33-.LFBB9
.LM33:
ldi r24,lo8(6)
sts 194,r24
.stabn 68,0,20,.LM34-.LFBB9
.LM34:
ldi r24,lo8(51)
ldi r25,hi8(51)
sts (196)+1,r25
sts 196,r24
.stabn 68,0,22,.LM35-.LFBB9
.LM35:
ld r24,Z
ori r24,lo8(-96)
st Z,r24
/* epilogue start */
.stabn 68,0,23,.LM36-.LFBB9
.LM36:
ret
.size serial_init, .-serial_init
.Lscope9:
.stabs "",36,0,0,.Lscope9-.LFBB9
.stabd 78,0,0
.comm _rx_buffer,70,1
.comm _tx_buffer,70,1
.stabs "_rx_buffer:G(0,17)=ar(0,18)=r(0,18);0;0177777;;0;69;(0,19)=B(2,2)",32,0,8,0
.stabs "_tx_buffer:G(0,17)",32,0,9,0
.text
.stabs "",100,0,0,.Letext0
.Letext0: