No changes between revisions
/Designs/GPSRL02A/SW/buffer/Makefile |
---|
0,0 → 1,51 |
NAME := gpsrl |
HEX := $(NAME).hex |
OUT := $(NAME).out |
MAP := $(NAME).map |
SOURCES := $(wildcard *.c) |
HEADERS := $(wildcard *.h) |
OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) |
MCU := atmega8 |
MCU_AVRDUDE := m8 |
CC := avr-gcc |
OBJCOPY := avr-objcopy |
SIZE := avr-size -A |
DOXYGEN := doxygen |
CFLAGS := -Wall -pedantic -mmcu=$(MCU) -std=c99 -g -Os |
all: $(HEX) |
clean: |
rm -f $(HEX) $(OUT) $(MAP) $(OBJECTS) |
rm -rf doc/html |
flash: $(HEX) |
avrdude -y -p $(MCU_AVRDUDE) -P /dev/ttyUSB0 -c stk500v2 -U flash:w:$(HEX) |
$(HEX): $(OUT) |
$(OBJCOPY) -R .eeprom -O ihex $< $@ |
$(OUT): $(OBJECTS) |
$(CC) $(CFLAGS) -o $@ -Wl,-Map,$(MAP) $^ |
@echo |
@$(SIZE) $@ |
@echo |
%.o: %.c $(HEADERS) |
$(CC) $(CFLAGS) -c -o $@ $< |
%.pp: %.c |
$(CC) $(CFLAGS) -E -o $@ $< |
%.ppo: %.c |
$(CC) $(CFLAGS) -E $< |
doc: $(HEADERS) $(SOURCES) Doxyfile |
$(DOXYGEN) Doxyfile |
.PHONY: all clean flash doc |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/a2d.c |
---|
0,0 → 1,115 |
/*! \file a2d.c \brief Analog-to-Digital converter function library. */ |
//***************************************************************************** |
// |
// File Name : 'a2d.c' |
// Title : Analog-to-digital converter functions |
// Author : Pascal Stang - Copyright (C) 2002 |
// Created : 2002-04-08 |
// Revised : 2002-09-30 |
// Version : 1.1 |
// Target MCU : Atmel AVR series |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include "global.h" |
#include "a2d.h" |
// global variables |
//! Software flag used to indicate when |
/// the a2d conversion is complete. |
volatile unsigned char a2dCompleteFlag; |
// functions |
// initialize a2d converter |
void a2dInit(void) |
{ |
sbi(ADCSR, ADEN); // enable ADC (turn on ADC power) |
cbi(ADCSR, ADFR); // default to single sample convert mode |
a2dSetPrescaler(ADC_PRESCALE); // set default prescaler |
a2dSetReference(ADC_REFERENCE); // set default reference |
cbi(ADMUX, ADLAR); // set to right-adjusted result |
sbi(ADCSR, ADIE); // enable ADC interrupts |
a2dCompleteFlag = FALSE; // clear conversion complete flag |
sei(); // turn on interrupts (if not already on) |
} |
// turn off a2d converter |
void a2dOff(void) |
{ |
cbi(ADCSR, ADIE); // disable ADC interrupts |
cbi(ADCSR, ADEN); // disable ADC (turn off ADC power) |
} |
// configure A2D converter clock division (prescaling) |
void a2dSetPrescaler(unsigned char prescale) |
{ |
outb(ADCSR, ((inb(ADCSR) & ~ADC_PRESCALE_MASK) | prescale)); |
} |
// configure A2D converter voltage reference |
void a2dSetReference(unsigned char ref) |
{ |
outb(ADMUX, ((inb(ADMUX) & ~ADC_REFERENCE_MASK) | (ref<<6))); |
} |
// sets the a2d input channel |
void a2dSetChannel(unsigned char ch) |
{ |
outb(ADMUX, (inb(ADMUX) & ~ADC_MUX_MASK) | (ch & ADC_MUX_MASK)); // set channel |
} |
// start a conversion on the current a2d input channel |
void a2dStartConvert(void) |
{ |
sbi(ADCSR, ADIF); // clear hardware "conversion complete" flag |
sbi(ADCSR, ADSC); // start conversion |
} |
// return TRUE if conversion is complete |
u08 a2dIsComplete(void) |
{ |
return bit_is_set(ADCSR, ADSC); |
} |
// Perform a 10-bit conversion |
// starts conversion, waits until conversion is done, and returns result |
unsigned short a2dConvert10bit(unsigned char ch) |
{ |
a2dCompleteFlag = FALSE; // clear conversion complete flag |
outb(ADMUX, (inb(ADMUX) & ~ADC_MUX_MASK) | (ch & ADC_MUX_MASK)); // set channel |
sbi(ADCSR, ADIF); // clear hardware "conversion complete" flag |
sbi(ADCSR, ADSC); // start conversion |
//while(!a2dCompleteFlag); // wait until conversion complete |
//while( bit_is_clear(ADCSR, ADIF) ); // wait until conversion complete |
while( bit_is_set(ADCSR, ADSC) ); // wait until conversion complete |
// CAUTION: MUST READ ADCL BEFORE ADCH!!! |
return (inb(ADCL) | (inb(ADCH)<<8)); // read ADC (full 10 bits); |
} |
// Perform a 8-bit conversion. |
// starts conversion, waits until conversion is done, and returns result |
unsigned char a2dConvert8bit(unsigned char ch) |
{ |
// do 10-bit conversion and return highest 8 bits |
return a2dConvert10bit(ch)>>2; // return ADC MSB byte |
} |
//! Interrupt handler for ADC complete interrupt. |
SIGNAL(SIG_ADC) |
{ |
// set the a2d conversion flag to indicate "complete" |
a2dCompleteFlag = TRUE; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/a2d.h |
---|
0,0 → 1,151 |
/*! \file a2d.h \brief Analog-to-Digital converter function library. */ |
//***************************************************************************** |
// |
// File Name : 'a2d.h' |
// Title : Analog-to-digital converter functions |
// Author : Pascal Stang - Copyright (C) 2002 |
// Created : 4/08/2002 |
// Revised : 4/30/2002 |
// Version : 1.1 |
// Target MCU : Atmel AVR series |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
/// \ingroup driver_avr |
/// \defgroup a2d A/D Converter Function Library (a2d.c) |
/// \code #include "a2d.h" \endcode |
/// \par Overview |
/// This library provides an easy interface to the analog-to-digital |
/// converter available on many AVR processors. Updated to support |
/// the ATmega128. |
// |
//**************************************************************************** |
//@{ |
#ifndef A2D_H |
#define A2D_H |
// defines |
// A2D clock prescaler select |
// *selects how much the CPU clock frequency is divided |
// to create the A2D clock frequency |
// *lower division ratios make conversion go faster |
// *higher division ratios make conversions more accurate |
#define ADC_PRESCALE_DIV2 0x00 ///< 0x01,0x00 -> CPU clk/2 |
#define ADC_PRESCALE_DIV4 0x02 ///< 0x02 -> CPU clk/4 |
#define ADC_PRESCALE_DIV8 0x03 ///< 0x03 -> CPU clk/8 |
#define ADC_PRESCALE_DIV16 0x04 ///< 0x04 -> CPU clk/16 |
#define ADC_PRESCALE_DIV32 0x05 ///< 0x05 -> CPU clk/32 |
#define ADC_PRESCALE_DIV64 0x06 ///< 0x06 -> CPU clk/64 |
#define ADC_PRESCALE_DIV128 0x07 ///< 0x07 -> CPU clk/128 |
// default value |
#define ADC_PRESCALE ADC_PRESCALE_DIV64 |
// do not change the mask value |
#define ADC_PRESCALE_MASK 0x07 |
// A2D voltage reference select |
// *this determines what is used as the |
// full-scale voltage point for A2D conversions |
#define ADC_REFERENCE_AREF 0x00 ///< 0x00 -> AREF pin, internal VREF turned off |
#define ADC_REFERENCE_AVCC 0x01 ///< 0x01 -> AVCC pin, internal VREF turned off |
#define ADC_REFERENCE_RSVD 0x02 ///< 0x02 -> Reserved |
#define ADC_REFERENCE_256V 0x03 ///< 0x03 -> Internal 2.56V VREF |
// default value |
#define ADC_REFERENCE ADC_REFERENCE_AVCC |
// do not change the mask value |
#define ADC_REFERENCE_MASK 0xC0 |
// bit mask for A2D channel multiplexer |
#define ADC_MUX_MASK 0x1F |
// channel defines (for reference and use in code) |
// these channels supported by all AVRs with A2D |
#define ADC_CH_ADC0 0x00 |
#define ADC_CH_ADC1 0x01 |
#define ADC_CH_ADC2 0x02 |
#define ADC_CH_ADC3 0x03 |
#define ADC_CH_ADC4 0x04 |
#define ADC_CH_ADC5 0x05 |
#define ADC_CH_ADC6 0x06 |
#define ADC_CH_ADC7 0x07 |
#define ADC_CH_122V 0x1E ///< 1.22V voltage reference |
#define ADC_CH_AGND 0x1F ///< AGND |
// these channels supported only in ATmega128 |
// differential with gain |
#define ADC_CH_0_0_DIFF10X 0x08 |
#define ADC_CH_1_0_DIFF10X 0x09 |
#define ADC_CH_0_0_DIFF200X 0x0A |
#define ADC_CH_1_0_DIFF200X 0x0B |
#define ADC_CH_2_2_DIFF10X 0x0C |
#define ADC_CH_3_2_DIFF10X 0x0D |
#define ADC_CH_2_2_DIFF200X 0x0E |
#define ADC_CH_3_2_DIFF200X 0x0F |
// differential |
#define ADC_CH_0_1_DIFF1X 0x10 |
#define ADC_CH_1_1_DIFF1X 0x11 |
#define ADC_CH_2_1_DIFF1X 0x12 |
#define ADC_CH_3_1_DIFF1X 0x13 |
#define ADC_CH_4_1_DIFF1X 0x14 |
#define ADC_CH_5_1_DIFF1X 0x15 |
#define ADC_CH_6_1_DIFF1X 0x16 |
#define ADC_CH_7_1_DIFF1X 0x17 |
#define ADC_CH_0_2_DIFF1X 0x18 |
#define ADC_CH_1_2_DIFF1X 0x19 |
#define ADC_CH_2_2_DIFF1X 0x1A |
#define ADC_CH_3_2_DIFF1X 0x1B |
#define ADC_CH_4_2_DIFF1X 0x1C |
#define ADC_CH_5_2_DIFF1X 0x1D |
// compatibility for new Mega processors |
// ADCSR hack apparently no longer necessary in new AVR-GCC |
#ifdef ADCSRA |
#ifndef ADCSR |
#define ADCSR ADCSRA |
#endif |
#endif |
#ifdef ADATE |
#define ADFR ADATE |
#endif |
// function prototypes |
//! Initializes the A/D converter. |
/// Turns ADC on and prepares it for use. |
void a2dInit(void); |
//! Turn off A/D converter |
void a2dOff(void); |
//! Sets the division ratio of the A/D converter clock. |
/// This function is automatically called from a2dInit() |
/// with a default value. |
void a2dSetPrescaler(unsigned char prescale); |
//! Configures which voltage reference the A/D converter uses. |
/// This function is automatically called from a2dInit() |
/// with a default value. |
void a2dSetReference(unsigned char ref); |
//! sets the a2d input channel |
void a2dSetChannel(unsigned char ch); |
//! start a conversion on the current a2d input channel |
void a2dStartConvert(void); |
//! return TRUE if conversion is complete |
u08 a2dIsComplete(void); |
//! Starts a conversion on A/D channel# ch, |
/// returns the 10-bit value of the conversion when it is finished. |
unsigned short a2dConvert10bit(unsigned char ch); |
//! Starts a conversion on A/D channel# ch, |
/// returns the 8-bit value of the conversion when it is finished. |
unsigned char a2dConvert8bit(unsigned char ch); |
#endif |
//@} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/a2dtest.c |
---|
0,0 → 1,104 |
//***************************************************************************** |
// File Name : a2dtest.c |
// |
// Title : example usage of some avr library functions |
// Revision : 1.0 |
// Notes : |
// Target MCU : Atmel AVR series |
// Editor Tabs : 4 |
// |
// Revision History: |
// When Who Description of change |
// ----------- ----------- ----------------------- |
// 20-Oct-2002 pstang Created the program |
//***************************************************************************** |
//----- Include Files --------------------------------------------------------- |
#include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
#include <avr/interrupt.h> // include interrupt support |
#include "global.h" // include our global settings |
#include "uart.h" // include uart function library |
#include "rprintf.h" // include printf function library |
#include "timer.h" // include timer function library (timing, PWM, etc) |
#include "a2d.h" // include A/D converter function library |
#include "vt100.h" // include VT100 terminal support |
//----- Begin Code ------------------------------------------------------------ |
int main(void) |
{ |
u16 a=0; |
u08 i=0; |
// initialize our libraries |
// initialize the UART (serial port) |
uartInit(); |
// make all rprintf statements use uart for output |
rprintfInit(uartSendByte); |
// initialize the timer system |
timerInit(); |
// turn on and initialize A/D converter |
a2dInit(); |
// print a little intro message so we know things are working |
/* vt100ClearScreen(); |
vt100SetCursorPos(1,1); |
rprintf("Welcome to the a2d test!\r\n");*/ |
// configure a2d port (PORTA) as input |
// so we can receive analog signals |
DDRC = 0x00; |
// make sure pull-up resistors are turned off |
PORTC = 0x00; |
// set the a2d prescaler (clock division ratio) |
// - a lower prescale setting will make the a2d converter go faster |
// - a higher setting will make it go slower but the measurements |
// will be more accurate |
// - other allowed prescale values can be found in a2d.h |
a2dSetPrescaler(ADC_PRESCALE_DIV32); |
// set the a2d reference |
// - the reference is the voltage against which a2d measurements are made |
// - other allowed reference values can be found in a2d.h |
a2dSetReference(ADC_REFERENCE_AVCC); |
// use a2dConvert8bit(channel#) to get an 8bit a2d reading |
// use a2dConvert10bit(channel#) to get a 10bit a2d reading |
while(1) |
{ |
u08 c=0; |
u08 n; |
char radka[100]; |
for(n=0;n<100;n++) radka[n]=0; |
n=0; |
while(uartReceiveByte(&c)) |
{ |
radka[n]=c; |
n++; |
} |
n=0; |
while (0!=radka[n]) |
{ |
uartSendByte(radka[n]); |
n++; |
timerPause(31); |
} |
/* // sample all a2d channels and print them to the terminal |
vt100SetCursorPos(2,1); |
for(i=0; i<6; i++) |
{ |
rprintf("Channel %d: %d \r\n", i, a2dConvert8bit(i)); |
timerPause(1000); |
} |
// print the sample number so far |
rprintf("Sample # : %d \r\n", a++);*/ |
} |
return 0; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/avrlibdefs.h |
---|
0,0 → 1,83 |
/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */ |
//***************************************************************************** |
// |
// File Name : 'avrlibdefs.h' |
// Title : AVRlib global defines and macros include file |
// Author : Pascal Stang |
// Created : 7/12/2001 |
// Revised : 9/30/2002 |
// Version : 1.1 |
// Target MCU : Atmel AVR series |
// Editor Tabs : 4 |
// |
// Description : This include file is designed to contain items useful to all |
// code files and projects, regardless of specific implementation. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#ifndef AVRLIBDEFS_H |
#define AVRLIBDEFS_H |
// Code compatibility to new AVR-libc |
// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli() |
#ifndef outb |
#define outb(addr, data) addr = (data) |
#endif |
#ifndef inb |
#define inb(addr) (addr) |
#endif |
#ifndef outw |
#define outw(addr, data) addr = (data) |
#endif |
#ifndef inw |
#define inw(addr) (addr) |
#endif |
#ifndef BV |
#define BV(bit) (1<<(bit)) |
#endif |
#ifndef cbi |
#define cbi(reg,bit) reg &= ~(BV(bit)) |
#endif |
#ifndef sbi |
#define sbi(reg,bit) reg |= (BV(bit)) |
#endif |
#ifndef cli |
#define cli() __asm__ __volatile__ ("cli" ::) |
#endif |
#ifndef sei |
#define sei() __asm__ __volatile__ ("sei" ::) |
#endif |
// support for individual port pin naming in the mega128 |
// see port128.h for details |
#ifdef __AVR_ATmega128__ |
// not currently necessary due to inclusion |
// of these defines in newest AVR-GCC |
// do a quick test to see if include is needed |
#ifndef PD0 |
#include "port128.h" |
#endif |
#endif |
// use this for packed structures |
// (this is seldom necessary on an 8-bit architecture like AVR, |
// but can assist in code portability to AVR) |
#define GNUC_PACKED __attribute__((packed)) |
// port address helpers |
#define DDR(x) ((x)-1) // address of data direction register of port x |
#define PIN(x) ((x)-2) // address of input register of port x |
// MIN/MAX/ABS macros |
#define MIN(a,b) ((a<b)?(a):(b)) |
#define MAX(a,b) ((a>b)?(a):(b)) |
#define ABS(x) ((x>0)?(x):(-x)) |
// constants |
#define PI 3.14159265359 |
#endif |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/avrlibtypes.h |
---|
0,0 → 1,84 |
/*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */ |
//***************************************************************************** |
// |
// File Name : 'avrlibtypes.h' |
// Title : AVRlib global types and typedefines include file |
// Author : Pascal Stang |
// Created : 7/12/2001 |
// Revised : 9/30/2002 |
// Version : 1.0 |
// Target MCU : Atmel AVR series |
// Editor Tabs : 4 |
// |
// Description : Type-defines required and used by AVRlib. Most types are also |
// generally useful. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#ifndef AVRLIBTYPES_H |
#define AVRLIBTYPES_H |
#ifndef WIN32 |
// true/false defines |
#define FALSE 0 |
#define TRUE -1 |
#endif |
// datatype definitions macros |
typedef unsigned char u08; |
typedef signed char s08; |
typedef unsigned short u16; |
typedef signed short s16; |
typedef unsigned long u32; |
typedef signed long s32; |
typedef unsigned long long u64; |
typedef signed long long s64; |
/* use inttypes.h instead |
// C99 standard integer type definitions |
typedef unsigned char uint8_t; |
typedef signed char int8_t; |
typedef unsigned short uint16_t; |
typedef signed short int16_t; |
typedef unsigned long uint32_t; |
typedef signed long int32_t; |
typedef unsigned long uint64_t; |
typedef signed long int64_t; |
*/ |
// maximum value that can be held |
// by unsigned data types (8,16,32bits) |
#define MAX_U08 255 |
#define MAX_U16 65535 |
#define MAX_U32 4294967295 |
// maximum values that can be held |
// by signed data types (8,16,32bits) |
#define MIN_S08 -128 |
#define MAX_S08 127 |
#define MIN_S16 -32768 |
#define MAX_S16 32767 |
#define MIN_S32 -2147483648 |
#define MAX_S32 2147483647 |
#ifndef WIN32 |
// more type redefinitions |
typedef unsigned char BOOL; |
typedef unsigned char BYTE; |
typedef unsigned int WORD; |
typedef unsigned long DWORD; |
typedef unsigned char UCHAR; |
typedef unsigned int UINT; |
typedef unsigned short USHORT; |
typedef unsigned long ULONG; |
typedef char CHAR; |
typedef int INT; |
typedef long LONG; |
#endif |
#endif |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/buffer.c |
---|
0,0 → 1,149 |
/*! \file buffer.c \brief Multipurpose byte buffer structure and methods. */ |
//***************************************************************************** |
// |
// File Name : 'buffer.c' |
// Title : Multipurpose byte buffer structure and methods |
// Author : Pascal Stang - Copyright (C) 2001-2002 |
// Created : 9/23/2001 |
// Revised : 9/23/2001 |
// Version : 1.0 |
// Target MCU : any |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#include "buffer.h" |
#include "global.h" |
#include "avr/io.h" |
#ifndef CRITICAL_SECTION_START |
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli() |
#define CRITICAL_SECTION_END SREG = _sreg |
#endif |
// global variables |
// initialization |
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size) |
{ |
// begin critical section |
CRITICAL_SECTION_START; |
// set start pointer of the buffer |
buffer->dataptr = start; |
buffer->size = size; |
// initialize index and length |
buffer->dataindex = 0; |
buffer->datalength = 0; |
// end critical section |
CRITICAL_SECTION_END; |
} |
// access routines |
unsigned char bufferGetFromFront(cBuffer* buffer) |
{ |
unsigned char data = 0; |
// begin critical section |
CRITICAL_SECTION_START; |
// check to see if there's data in the buffer |
if(buffer->datalength) |
{ |
// get the first character from buffer |
data = buffer->dataptr[buffer->dataindex]; |
// move index down and decrement length |
buffer->dataindex++; |
if(buffer->dataindex >= buffer->size) |
{ |
buffer->dataindex -= buffer->size; |
} |
buffer->datalength--; |
} |
// end critical section |
CRITICAL_SECTION_END; |
// return |
return data; |
} |
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes) |
{ |
// begin critical section |
CRITICAL_SECTION_START; |
// dump numbytes from the front of the buffer |
// are we dumping less than the entire buffer? |
if(numbytes < buffer->datalength) |
{ |
// move index down by numbytes and decrement length by numbytes |
buffer->dataindex += numbytes; |
if(buffer->dataindex >= buffer->size) |
{ |
buffer->dataindex -= buffer->size; |
} |
buffer->datalength -= numbytes; |
} |
else |
{ |
// flush the whole buffer |
buffer->datalength = 0; |
} |
// end critical section |
CRITICAL_SECTION_END; |
} |
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index) |
{ |
// begin critical section |
CRITICAL_SECTION_START; |
// return character at index in buffer |
unsigned char data = buffer->dataptr[(buffer->dataindex+index)%(buffer->size)]; |
// end critical section |
CRITICAL_SECTION_END; |
return data; |
} |
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data) |
{ |
// begin critical section |
CRITICAL_SECTION_START; |
// make sure the buffer has room |
if(buffer->datalength < buffer->size) |
{ |
// save data byte at end of buffer |
buffer->dataptr[(buffer->dataindex + buffer->datalength) % buffer->size] = data; |
// increment the length |
buffer->datalength++; |
// end critical section |
CRITICAL_SECTION_END; |
// return success |
return -1; |
} |
// end critical section |
CRITICAL_SECTION_END; |
// return failure |
return 0; |
} |
unsigned short bufferIsNotFull(cBuffer* buffer) |
{ |
// begin critical section |
CRITICAL_SECTION_START; |
// check to see if the buffer has room |
// return true if there is room |
unsigned short bytesleft = (buffer->size - buffer->datalength); |
// end critical section |
CRITICAL_SECTION_END; |
return bytesleft; |
} |
void bufferFlush(cBuffer* buffer) |
{ |
// begin critical section |
CRITICAL_SECTION_START; |
// flush contents of the buffer |
buffer->datalength = 0; |
// end critical section |
CRITICAL_SECTION_END; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/buffer.h |
---|
0,0 → 1,74 |
/*! \file buffer.h \brief Multipurpose byte buffer structure and methods. */ |
//***************************************************************************** |
// |
// File Name : 'buffer.h' |
// Title : Multipurpose byte buffer structure and methods |
// Author : Pascal Stang - Copyright (C) 2001-2002 |
// Created : 9/23/2001 |
// Revised : 11/16/2002 |
// Version : 1.1 |
// Target MCU : any |
// Editor Tabs : 4 |
// |
/// \ingroup general |
/// \defgroup buffer Circular Byte-Buffer Structure and Function Library (buffer.c) |
/// \code #include "buffer.h" \endcode |
/// \par Overview |
/// This byte-buffer structure provides an easy and efficient way to store |
/// and process a stream of bytes. You can create as many buffers as you |
/// like (within memory limits), and then use this common set of functions to |
/// access each buffer. The buffers are designed for FIFO operation (first |
/// in, first out). This means that the first byte you put in the buffer |
/// will be the first one you get when you read out the buffer. Supported |
/// functions include buffer initialize, get byte from front of buffer, add |
/// byte to end of buffer, check if buffer is full, and flush buffer. The |
/// buffer uses a circular design so no copying of data is ever necessary. |
/// This buffer is not dynamically allocated, it has a user-defined fixed |
/// maximum size. This buffer is used in many places in the avrlib code. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
//@{ |
#ifndef BUFFER_H |
#define BUFFER_H |
// structure/typdefs |
//! cBuffer structure |
typedef struct struct_cBuffer |
{ |
unsigned char *dataptr; ///< the physical memory address where the buffer is stored |
unsigned short size; ///< the allocated size of the buffer |
unsigned short datalength; ///< the length of the data currently in the buffer |
unsigned short dataindex; ///< the index into the buffer where the data starts |
} cBuffer; |
// function prototypes |
//! initialize a buffer to start at a given address and have given size |
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size); |
//! get the first byte from the front of the buffer |
unsigned char bufferGetFromFront(cBuffer* buffer); |
//! dump (discard) the first numbytes from the front of the buffer |
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes); |
//! get a byte at the specified index in the buffer (kind of like array access) |
// ** note: this does not remove the byte that was read from the buffer |
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index); |
//! add a byte to the end of the buffer |
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data); |
//! check if the buffer is full/not full (returns zero value if full) |
unsigned short bufferIsNotFull(cBuffer* buffer); |
//! flush (clear) the contents of the buffer |
void bufferFlush(cBuffer* buffer); |
#endif |
//@} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/global.h |
---|
0,0 → 1,42 |
//***************************************************************************** |
// |
// File Name : 'global.h' |
// Title : AVR project global include |
// Author : Pascal Stang |
// Created : 7/12/2001 |
// Revised : 9/30/2002 |
// Version : 1.1 |
// Target MCU : Atmel AVR series |
// Editor Tabs : 4 |
// |
// Description : This include file is designed to contain items useful to all |
// code files and projects. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#ifndef GLOBAL_H |
#define GLOBAL_H |
// global AVRLIB defines |
#include "avrlibdefs.h" |
// global AVRLIB types definitions |
#include "avrlibtypes.h" |
// project/system dependent defines |
#define UART_RX_BUFFER_SIZE 0x00FF |
// CPU clock speed |
//#define F_CPU 16000000 // 16MHz processor |
//#define F_CPU 14745000 // 14.745MHz processor |
#define F_CPU 8000000 // 8MHz processor |
//#define F_CPU 7372800 // 7.37MHz processor |
//#define F_CPU 4000000 // 4MHz processor |
//#define F_CPU 3686400 // 3.69MHz processor |
#define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond |
#endif |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/gpsrl.hex |
---|
0,0 → 1,265 |
:100000003BC055C054C015C64DC5E6C58BC5B7C568 |
:100010001CC5C8C44CC09DC64AC0DFC683C047C00B |
:1000200046C045C044C030313233343536373839B4 |
:1000300041424344454600000001000800400000E2 |
:1000400001000400000100080020004000800000C2 |
:100050000100041B5B25643B256448001B5B3F32A9 |
:10006000356C001B5B3F323568001B5B25646D00FF |
:100070001B5B324A001B630011241FBECFE5D4E096 |
:10008000DEBFCDBF10E0A0E6B0E0EEE7F0E102C0D9 |
:1000900005900D92A036B107D9F711E0A0E6B0E0C7 |
:1000A00001C01D92A23DB107E1F759D0E7C7A8CF23 |
:1000B00033983798089596B1987F982B96B90895FC |
:1000C00097B18295880F880F807C9F73982B97B982 |
:1000D000089597B18F71907E892B87B90895349ACE |
:1000E000369A089586B19927807490700895109279 |
:1000F000B10197B18F71907E892B87B9349A369A66 |
:100100003699FECF24B185B19927982F88273327B8 |
:10011000822B932B0895EBDF96958795969587957F |
:10012000992708951F920F920FB60F9211248F9363 |
:100130008FEF8093B1018F910F900FBE0F901F90A2 |
:100140001895379A359886B1887F866086B981E0A0 |
:10015000B7DF3D98339A1092B10178940895CAEFB1 |
:10016000D3E0DEBFCDBFB6D68FE896E0E6D08ED521 |
:10017000E8DF14BA15BA85E09EDF81E0A1DF92E0E6 |
:10018000C92ED12CCC0EDD1E86E6882E912C8C0E2D |
:100190009D1E5E010894A11CB11CF6011192E81588 |
:1001A000F905E1F7198200E010E005C0F601EF0D56 |
:1001B000F11D89818083F02EC50145D60F5F1F4F49 |
:1001C0008823A1F700E010E004C0A9D58FE190E0FA |
:1001D00000D3F601E00FF11D80810F5F1F4F8823D0 |
:1001E000A1F7DBCFFC018FB7F89471836083538351 |
:1001F000428317821682158214828FBF0895CF938F |
:10020000DF93DC014FB7F894EC018C819D81892B41 |
:1002100011F4E0E01CC0FD0186819781ED91FC9115 |
:100220001197E80FF91FE0810196ED019F838E83FE |
:100230002A813B818217930720F0821B930B9F83B7 |
:100240008E83ED018C819D8101979D838C834FBFAF |
:100250008E2F9927DF91CF910895FC014FB7F89425 |
:100260008481958168177907B0F486819781860F1C |
:10027000971F97838683228133818217930720F00B |
:10028000821B930B9783868384819581861B970BB2 |
:100290009583848302C0158214824FBF0895FC01A8 |
:1002A000CB014FB7F8942681378162817381820F29 |
:1002B000931F93D60190F081E02DE80FF91F808104 |
:1002C0004FBF992708951F93CF93DF93EC01162F0B |
:1002D0004FB7F8942C813D816A817B8126173707BF |
:1002E00098F48E819F81820F931F77D6E881F981E0 |
:1002F000E80FF91F10838C819D8101969D838C836B |
:100300004FBF8FEF90E003C04FBF80E090E0DF91E0 |
:10031000CF911F910895FC018FB7F8948FBF828110 |
:10032000938124813581821B930B0895FC018FB743 |
:10033000F894158214828FBF089590936100809382 |
:10034000600008951F93182F8A3031F4E091600007 |
:10035000F09161008DE00995E0916000F0916100FD |
:10036000812F09951F910895CF93DF93EC01892B7D |
:1003700019F405C02196E6DF88818823D9F7DF913B |
:10038000CF910895EF92FF920F931F93CF93DF9336 |
:100390007A010097C1F0EC01680F791FC617D707E3 |
:1003A00019F089918823D1F700E010E009C0888115 |
:1003B000882311F0219601C080E2C4DF0F5F1F4F38 |
:1003C0000E151F05A1F7DF91CF911F910F91FF909F |
:1003D000EF900895CF93DF93EC01892B11F406C0C1 |
:1003E000B1DFFE01219684918823D1F7DF91CF916F |
:1003F00008958AE0A7DF0895E82FFF27EF70F070D7 |
:10040000EA5DFF4FE4918E2F9DDF08951F93182F13 |
:1004100082958F70F1DF812FEFDF1F9108950F9389 |
:100420001F938C01812F9927F1DF802FEFDF1F9120 |
:100430000F910895EF92FF920F931F937B018C0110 |
:10044000C801AA27BB27EBDFC701E9DF1F910F9186 |
:10045000FF90EF9008952F923F924F925F926F928C |
:100460007F928F929F92AF92BF92CF92DF92EF9244 |
:10047000FF920F931F93CF93DF93CDB7DEB7A4976F |
:100480000FB6F894DEBF0FBECDBF4BA32CA3270140 |
:100490003801442351F017FF08C0EE24FF248701E0 |
:1004A000E418F5080609170902C08301720169A35F |
:1004B00090E02BA1211191E0E9A1E91BE150EAA311 |
:1004C00018A2882E992487FC9094A92CB92CC801D5 |
:1004D000B701A501940195D5FB01EF70F070EA5DBD |
:1004E000FF4F64916F8FC801B701A501940189D5B1 |
:1004F00069017A012EE1222E312C2C0E3D1E20C0E6 |
:10050000C114D104E104F104A9F0C701B601A501A9 |
:10051000940177D5FB01EF70F070EA5DFF4F6491B5 |
:10052000F1016083C701B601A50194016AD5690193 |
:100530007A0103C02CA1F10120830894210831081D |
:1005400081010F5F1F4F8AA181508AA38F3FC1F69F |
:100550009BA19923B1F077FE03C081018DE20AC00F |
:10056000411451046104710419F081018BE202C04D |
:10057000810180E2F801808304C0F80181918F013C |
:10058000E1DEF9A1F150F9A3FF3FB9F7A4960FB648 |
:10059000F894DEBF0FBECDBFDF91CF911F910F91B9 |
:1005A000FF90EF90DF90CF90BF90AF909F908F9093 |
:1005B0007F906F905F904F903F902F9008959F9203 |
:1005C000AF92BF92CF92DF92EF92FF920F931F9361 |
:1005D000CF93DF93CDB7DEB722970FB6F894DEBF87 |
:1005E0000FBECDBF9888C988DA88CE0143969A831A |
:1005F000898304C0882309F465C0A4DE96012F5FB7 |
:100600003F4F992021F0F6016901849103C0F60162 |
:1006100080816901853271F72F5F3F4F992021F06A |
:10062000F6016901849103C0F60180816901843675 |
:10063000A1F0883719F0833601F707C0E12C60E19B |
:10064000F62E50E1A52EB12C0FC0E981FA81329629 |
:10065000FA83E98332978081D0CF40E1E42E47E2EC |
:10066000F42E3AE0A32EB12CE981FA813296FA8376 |
:10067000E983129102918436A1F417FF0BC0109503 |
:1006800001951F4F8DE25EDE05C0C7016AE070E094 |
:10069000A4D47B01F2E0EF16F10418F00E151F054B |
:1006A000A0F3C801B70199D4CB01A6DEC801B701F8 |
:1006B00094D48C01C701B50190D47B01672B09F458 |
:1006C0009DCFEFCF80E090E022960FB6F894DEBF8A |
:1006D0000FBECDBFDF91CF911F910F91FF90EF9093 |
:1006E000DF90CF90BF90AF909F900895089583B70B |
:1006F000887F826083BF12BE89B7816089BF1092F4 |
:10070000B2011092B3011092B4011092B501089594 |
:100710008EB5887F83608EBD1DBC1CBC89B784608C |
:1007200089BF089585B5887F846085BD14BC89B76D |
:10073000806489BF1092BA011092BB011092BC0173 |
:100740001092BD01089593B7987F982B93BF089599 |
:100750009EB5987F982B9EBD089595B5987F982B50 |
:1007600095BD0895E3B7FF27E770F070EE0FFF1F08 |
:10077000E95CFF4F859194910895EEB5FF27E770EE |
:10078000F070EE0FFF1FE95CFF4F85919491089583 |
:10079000E5B5FF27E770F070EE0FFF1FED5BFF4F31 |
:1007A000859194910895873040F4E82FFF27EE0F4C |
:1007B000FF1FEE59FF4F718360830895873040F427 |
:1007C000E82FFF27EE0FFF1FEE59FF4F1182108217 |
:1007D0000895EF92FF920F931F93CF93DF93EC0155 |
:1007E00012B71092B6011092B7011092B801109290 |
:1007F000B901B8DF9C014427552760E072E18AE720 |
:1008000090E021D4CA01B901693B2DE8720726E0C6 |
:10081000820720E0920770F427E2C131D20750F43A |
:100820009E0144275527BAD328EE33E040E050E03C |
:10083000E8D321C028EE33E040E050E0E2D3CA0123 |
:10084000B9019E0144275527A9D39B01AC0113C0D0 |
:100850008091B6019091B701A091B801B091B90112 |
:1008600085B78F7885BF85B7806885BF889585B740 |
:100870008F7785BF06C0210F311D411D511D7901A4 |
:100880008A012091B6013091B7014091B801509191 |
:10089000B90182B79927AA27BB27542F432F322F9C |
:1008A0002227822B932BA42BB52B8E159F05A007F7 |
:1008B000B10770F2DF91CF911F910F91FF90EF90F0 |
:1008C00008951092B2011092B3011092B4011092E7 |
:1008D000B50108956091B2017091B3018091B401A6 |
:1008E0009091B50108951092BA011092BB01109237 |
:1008F000BC011092BD0108956091BA017091BB01D5 |
:100900008091BC019091BD010895893031F48FB57B |
:1009100082608FBD8FB58E7F0AC08A3019F48FB583 |
:10092000826002C08FB58D7F8FBD8FB581608FBD16 |
:100930001BBC1ABC19BC18BC08952FB52E7F2FBD47 |
:100940002FB522602FBD2EB528602EBD2EB520619B |
:100950002EBD97BD86BD1BBC1ABC19BC18BC089522 |
:100960008FB580688FBD8FB58F7B8FBD08958FB594 |
:1009700080628FBD8FB58F7E8FBD08958FB58F77C5 |
:100980008FBD8FB58F7B8FBD08958FB58F7D8FBD48 |
:100990008FB58F7E8FBD08959BBD8ABD089599BD8B |
:1009A00088BD08951F920F920FB60F9211242F93B6 |
:1009B0003F934F935F936F937F938F939F93AF93E7 |
:1009C000BF93EF93FF938091B2019091B301A091F7 |
:1009D000B401B091B5010196A11DB11D8093B20182 |
:1009E0009093B301A093B401B093B5018091B60187 |
:1009F0009091B701A091B801B091B9010196A11DE4 |
:100A0000B11D8093B6019093B701A093B801B09344 |
:100A1000B9018091620090916300892B29F0E091E7 |
:100A20006200F09163000995FF91EF91BF91AF9142 |
:100A30009F918F917F916F915F914F913F912F91F6 |
:100A40000F900FBE0F901F9018951F920F920FB628 |
:100A50000F9211242F933F934F935F936F937F9344 |
:100A60008F939F93AF93BF93EF93FF938091640015 |
:100A700090916500892B29F0E0916400F091650068 |
:100A80000995FF91EF91BF91AF919F918F917F91C8 |
:100A90006F915F914F913F912F910F900FBE0F90EB |
:100AA0001F9018951F920F920FB60F9211242F933B |
:100AB0003F934F935F936F937F938F939F93AF93E6 |
:100AC000BF93EF93FF938091BA019091BB01A091E6 |
:100AD000BC01B091BD010196A11DB11D8093BA0169 |
:100AE0009093BB01A093BC01B093BD0180916C00B9 |
:100AF00090916D00892B29F0E0916C00F0916D00D0 |
:100B00000995FF91EF91BF91AF919F918F917F9147 |
:100B10006F915F914F913F912F910F900FBE0F906A |
:100B20001F9018951F920F920FB60F9211242F93BA |
:100B30003F934F935F936F937F938F939F93AF9365 |
:100B4000BF93EF93FF938091660090916700892B8C |
:100B500029F0E0916600F09167000995FF91EF910F |
:100B6000BF91AF919F918F917F916F915F914F91C5 |
:100B70003F912F910F900FBE0F901F9018951F92CD |
:100B80000F920FB60F9211242F933F934F935F93C1 |
:100B90006F937F938F939F93AF93BF93EF93FF9345 |
:100BA0008091680090916900892B29F0E09168009C |
:100BB000F09169000995FF91EF91BF91AF919F91DD |
:100BC0008F917F916F915F914F913F912F910F90F6 |
:100BD0000FBE0F901F9018951F920F920FB60F9295 |
:100BE00011242F933F934F935F936F937F938F9332 |
:100BF0009F93AF93BF93EF93FF9380916A0090917F |
:100C00006B00892B29F0E0916A00F0916B00099547 |
:100C1000FF91EF91BF91AF919F918F917F916F91D4 |
:100C20005F914F913F912F910F900FBE0F901F90AA |
:100C300018951F920F920FB60F9211242F933F9386 |
:100C40004F935F936F937F938F939F93AF93BF93D4 |
:100C5000EF93FF9380916E0090916F00892B29F0A4 |
:100C6000E0916E00F0916F000995FF91EF91BF91B7 |
:100C7000AF919F918F917F916F915F914F913F9134 |
:100C80002F910F900FBE0F901F90189580E090E06D |
:100C9000FC01EE0FFF1FEE59FF4F118210820196EB |
:100CA00087309105A9F723DD33DD3CDD7894089585 |
:100CB0008FB58D7F8FBD8FB58E7F8FBD8FB58F77B1 |
:100CC0008FBD8FB58F7B8FBD8FB58F7D8FBD8FB55E |
:100CD0008F7E8FBD08959093B0018093AF010895EA |
:100CE000F3E0660F771F881F991FFA95D1F79B01D4 |
:100CF000AC01220F331F441F551F60507E4E8548A4 |
:100D00009F4F7FD12150304029B9232F332720BD59 |
:100D100008958FEB91E0089588EC91E00895982F65 |
:100D20008091BE018823E1F39CB91092BE01089521 |
:100D30001092C4011092C30108958091C301909153 |
:100D4000C401892B19F48FEF90E0089580E090E0C2 |
:100D500008951F920F920FB60F9211242F933F9375 |
:100D60004F935F936F937F938F939F93AF93BF93B3 |
:100D7000EF93FF936CB18091AF019091B001892BFB |
:100D800039F0E091AF01F091B001862F09950EC0C6 |
:100D90008FEB91E098DA882349F48091D00190910B |
:100DA000D10101969093D1018093D001FF91EF91F1 |
:100DB000BF91AF919F918F917F916F915F914F9173 |
:100DC0003F912F910F900FBE0F901F901895682F95 |
:100DD00088EC91E078DA992708951F920F920FB668 |
:100DE0000F9211242F933F934F935F936F937F93B1 |
:100DF0008F939F93AF93BF93EF93FF938091C7011E |
:100E0000882369F08091CC019091CD01892B29F044 |
:100E100088EC91E0F4D98CB905C01092C7018FEF2E |
:100E20008093BE01FF91EF91BF91AF919F918F9100 |
:100E30007F916F915F914F913F912F910F900FBED6 |
:100E40000F901F901895CF93DF93EC018091C10113 |
:100E50009091C201892B69F08091C3019091C401E6 |
:100E6000892B39F08FEB91E0CAD988838FEF90E01E |
:100E700002C080E090E0DF91CF910895CF93DF939F |
:100E8000CDB7DEB721970FB6F894DEBF0FBECDBF4A |
:100E9000CE010196D8DF882319F48FEF9FEF02C0AF |
:100EA0008981992721960FB6F894DEBF0FBECDBF7A |
:100EB000DF91CF9108954FEF50E060E770E08FEB46 |
:100EC00091E090D940E450E06FE671E088EC91E069 |
:100ED00089D90895F0DF1092B0011092AF0188ED2A |
:100EE0008AB960E875E280E090E0FADE8FEF8093E7 |
:100EF000BE011092C7011092D1011092D0017894D6 |
:100F000008958FEF8093C70188EC91E078D9982FEE |
:100F10008091BE018823E1F39CB91092BE0108952F |
:100F200077277F936F9399279F938F9383E590E023 |
:100F30009F938F9381E08F9342DB8DB79EB7079687 |
:100F40000FB6F8949EBF0FBE8DBF0895882319F089 |
:100F500083E690E002C08CE590E09F938F9381E060 |
:100F60008F932DDB0F900F900F90089599279F93EB |
:100F70008F938AE690E09F938F9381E08F931FDB9E |
:100F80000F900F900F900F900F90089580E790E0D2 |
:100F900021DA089585E790E01DDA0895629FD00177 |
:100FA000739FF001829FE00DF11D649FE00DF11D24 |
:100FB000929FF00D839FF00D749FF00D659FF00DD3 |
:100FC0009927729FB00DE11DF91F639FB00DE11DC0 |
:100FD000F91FBD01CF0111240895AA1BBB1B51E1CC |
:100FE00007C0AA1FBB1FA617B70710F0A61BB70B99 |
:100FF000881F991F5A95A9F780959095BC01CD013E |
:101000000895A1E21A2EAA1BBB1BFD010DC0AA1F49 |
:10101000BB1FEE1FFF1FA217B307E407F50720F061 |
:10102000A21BB30BE40BF50B661F771F881F991FDC |
:101030001A9469F760957095809590959B01AC0125 |
:10104000BD01CF01089597FB092E05260ED057FD4F |
:1010500004D0D7DF0AD0001C38F450954095309565 |
:1010600021953F4F4F4F5F4F0895F6F7909580952C |
:0E107000709561957F4F8F4F9F4F0895FFCF72 |
:00000001FF |
/Designs/GPSRL02A/SW/buffer/gpsrl.map |
---|
0,0 → 1,516 |
Archive member included because of file (symbol) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_mulsi3.o) |
timer.o (__mulsi3) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodhi4.o) |
buffer.o (__udivmodhi4) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodsi4.o) |
rprintf.o (__udivmodsi4) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_divmodsi4.o) |
timer.o (__divmodsi4) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o (exit) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_copy_data.o) |
a2d.o (__do_copy_data) |
/usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_clear_bss.o) |
a2d.o (__do_clear_bss) |
Allocating common symbols |
Common symbol size file |
uartReadyTx 0x1 uart.o |
Timer0Reg0 0x4 timer.o |
uartRxBuffer 0x8 uart.o |
TimerPauseReg 0x4 timer.o |
Timer2Reg0 0x4 timer.o |
uartBufferedTx 0x1 uart.o |
a2dCompleteFlag 0x1 a2d.o |
uartTxBuffer 0x8 uart.o |
uartRxOverflow 0x2 uart.o |
Memory Configuration |
Name Origin Length Attributes |
text 0x00000000 0x00002000 xr |
data 0x00800060 0x0000ffa0 rw !x |
eeprom 0x00810000 0x00010000 rw !x |
fuse 0x00820000 0x00000400 rw !x |
lock 0x00830000 0x00000400 rw !x |
signature 0x00840000 0x00000400 rw !x |
*default* 0x00000000 0xffffffff |
Linker script and memory map |
LOAD /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
LOAD a2d.o |
LOAD a2dtest.o |
LOAD buffer.o |
LOAD rprintf.o |
LOAD timer.o |
LOAD uart.o |
LOAD vt100.o |
LOAD /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a |
LOAD /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/libc.a |
LOAD /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a |
.hash |
*(.hash) |
.dynsym |
*(.dynsym) |
.dynstr |
*(.dynstr) |
.gnu.version |
*(.gnu.version) |
.gnu.version_d |
*(.gnu.version_d) |
.gnu.version_r |
*(.gnu.version_r) |
.rel.init |
*(.rel.init) |
.rela.init |
*(.rela.init) |
.rel.text |
*(.rel.text) |
*(.rel.text.*) |
*(.rel.gnu.linkonce.t*) |
.rela.text |
*(.rela.text) |
*(.rela.text.*) |
*(.rela.gnu.linkonce.t*) |
.rel.fini |
*(.rel.fini) |
.rela.fini |
*(.rela.fini) |
.rel.rodata |
*(.rel.rodata) |
*(.rel.rodata.*) |
*(.rel.gnu.linkonce.r*) |
.rela.rodata |
*(.rela.rodata) |
*(.rela.rodata.*) |
*(.rela.gnu.linkonce.r*) |
.rel.data |
*(.rel.data) |
*(.rel.data.*) |
*(.rel.gnu.linkonce.d*) |
.rela.data |
*(.rela.data) |
*(.rela.data.*) |
*(.rela.gnu.linkonce.d*) |
.rel.ctors |
*(.rel.ctors) |
.rela.ctors |
*(.rela.ctors) |
.rel.dtors |
*(.rel.dtors) |
.rela.dtors |
*(.rela.dtors) |
.rel.got |
*(.rel.got) |
.rela.got |
*(.rela.got) |
.rel.bss |
*(.rel.bss) |
.rela.bss |
*(.rela.bss) |
.rel.plt |
*(.rel.plt) |
.rela.plt |
*(.rela.plt) |
.text 0x00000000 0x107e |
*(.vectors) |
.vectors 0x00000000 0x26 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
0x00000000 __vectors |
0x00000000 __vector_default |
*(.vectors) |
*(.progmem.gcc*) |
*(.progmem*) |
.progmem.data 0x00000026 0x11 rprintf.o |
.progmem.data 0x00000037 0x1c timer.o |
0x00000043 TimerRTCPrescaleFactor |
0x00000037 TimerPrescaleFactor |
.progmem.data 0x00000053 0x25 vt100.o |
0x00000078 . = ALIGN (0x2) |
0x00000078 __trampolines_start = . |
*(.trampolines) |
.trampolines 0x00000078 0x0 linker stubs |
*(.trampolines*) |
0x00000078 __trampolines_end = . |
*(.jumptables) |
*(.jumptables*) |
*(.lowtext) |
*(.lowtext*) |
0x00000078 __ctors_start = . |
*(.ctors) |
0x00000078 __ctors_end = . |
0x00000078 __dtors_start = . |
*(.dtors) |
0x00000078 __dtors_end = . |
SORT(*)(.ctors) |
SORT(*)(.dtors) |
*(.init0) |
.init0 0x00000078 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
0x00000078 __init |
*(.init0) |
*(.init1) |
*(.init1) |
*(.init2) |
.init2 0x00000078 0xc /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
*(.init2) |
*(.init3) |
*(.init3) |
*(.init4) |
.init4 0x00000084 0x16 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_copy_data.o) |
0x00000084 __do_copy_data |
.init4 0x0000009a 0x10 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_clear_bss.o) |
0x0000009a __do_clear_bss |
*(.init4) |
*(.init5) |
*(.init5) |
*(.init6) |
*(.init6) |
*(.init7) |
*(.init7) |
*(.init8) |
*(.init8) |
*(.init9) |
.init9 0x000000aa 0x4 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
*(.init9) |
*(.text) |
.text 0x000000ae 0x2 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
0x000000ae __vector_1 |
0x000000ae __vector_12 |
0x000000ae __bad_interrupt |
0x000000ae __vector_17 |
0x000000ae __vector_2 |
0x000000ae __vector_15 |
0x000000ae __vector_10 |
0x000000ae __vector_16 |
0x000000ae __vector_18 |
.text 0x000000b0 0xae a2d.o |
0x000000e4 a2dIsComplete |
0x00000116 a2dConvert8bit |
0x000000b0 a2dOff |
0x000000b6 a2dSetPrescaler |
0x000000ee a2dConvert10bit |
0x00000142 a2dInit |
0x000000c0 a2dSetReference |
0x00000124 __vector_14 |
0x000000d2 a2dSetChannel |
0x000000de a2dStartConvert |
.text 0x0000015e 0x86 a2dtest.o |
0x0000015e main |
.text 0x000001e4 0x156 buffer.o |
0x00000316 bufferIsNotFull |
0x000001fe bufferGetFromFront |
0x0000029e bufferGetAtIndex |
0x0000025a bufferDumpFromFront |
0x000001e4 bufferInit |
0x000002c6 bufferAddToEnd |
0x0000032c bufferFlush |
.text 0x0000033a 0x3b2 rprintf.o |
0x000005be rprintf1RamRom |
0x0000040c rprintfu08 |
0x00000434 rprintfu32 |
0x00000368 rprintfStr |
0x00000384 rprintfStrLen |
0x000003d4 rprintfProgStr |
0x0000041e rprintfu16 |
0x0000033a rprintfInit |
0x00000344 rprintfChar |
0x000003f2 rprintfCRLF |
0x000003f8 rprintfu04 |
0x00000456 rprintfNum |
.text 0x000006ec 0x5ea timer.o |
0x000008f8 timer2GetOverflowCount |
0x000007bc timerDetach |
0x00000750 timer1SetPrescaler |
0x0000098a timer1PWMBOff |
0x00000790 timer2GetPrescaler |
0x00000b24 __vector_6 |
0x000006ee timer0Init |
0x0000097c timer1PWMAOff |
0x0000099e timer1PWMBSet |
0x00000c32 __vector_3 |
0x0000093a timer1PWMInitICR |
0x00000764 timer0GetPrescaler |
0x00000b7e __vector_7 |
0x000008d4 timer0GetOverflowCount |
0x00000bd8 __vector_5 |
0x00000c8c timerInit |
0x0000075a timer2SetPrescaler |
0x00000960 timer1PWMAOn |
0x00000746 timer0SetPrescaler |
0x000006ec delay_us |
0x00000aa4 __vector_4 |
0x000008c2 timer0ClearOverflowCount |
0x000009a4 __vector_9 |
0x00000710 timer1Init |
0x0000090a timer1PWMInit |
0x0000096e timer1PWMBOn |
0x00000724 timer2Init |
0x00000a4a __vector_8 |
0x00000998 timer1PWMASet |
0x000007a6 timerAttach |
0x00000cb0 timer1PWMOff |
0x0000077a timer1GetPrescaler |
0x000008e6 timer2ClearOverflowCount |
0x000007d2 timerPause |
.text 0x00000cd6 0x24a uart.o |
0x00000f02 uartSendTxBuffer |
0x00000d1e uartSendByte |
0x00000eb6 uartInitBuffers |
0x00000e46 uartReceiveByte |
0x00000dce uartAddToTxBuffer |
0x00000d52 __vector_11 |
0x00000cd6 uartSetRxHandler |
0x00000dda __vector_13 |
0x00000d30 uartFlushReceiveBuffer |
0x00000ed4 uartInit |
0x00000d3a uartReceiveBufferIsEmpty |
0x00000ce0 uartSetBaudRate |
0x00000d18 uartGetTxBuffer |
0x00000e7c uartGetByte |
0x00000d12 uartGetRxBuffer |
.text 0x00000f20 0x7c vt100.o |
0x00000f94 vt100Init |
0x00000f6c vt100SetAttr |
0x00000f4c vt100SetCursorMode |
0x00000f20 vt100SetCursorPos |
0x00000f8c vt100ClearScreen |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_mulsi3.o) |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodhi4.o) |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodsi4.o) |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_divmodsi4.o) |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_copy_data.o) |
.text 0x00000f9c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_clear_bss.o) |
0x00000f9c . = ALIGN (0x2) |
*(.text.*) |
.text.libgcc 0x00000f9c 0x3e /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_mulsi3.o) |
0x00000f9c __mulsi3 |
.text.libgcc 0x00000fda 0x28 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodhi4.o) |
0x00000fda __udivmodhi4 |
.text.libgcc 0x00001002 0x44 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodsi4.o) |
0x00001002 __udivmodsi4 |
.text.libgcc 0x00001046 0x36 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_divmodsi4.o) |
0x00001046 __divmodsi4 |
.text.libgcc 0x0000107c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
.text.libgcc 0x0000107c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_copy_data.o) |
.text.libgcc 0x0000107c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_clear_bss.o) |
0x0000107c . = ALIGN (0x2) |
*(.fini9) |
.fini9 0x0000107c 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
0x0000107c exit |
0x0000107c _exit |
*(.fini9) |
*(.fini8) |
*(.fini8) |
*(.fini7) |
*(.fini7) |
*(.fini6) |
*(.fini6) |
*(.fini5) |
*(.fini5) |
*(.fini4) |
*(.fini4) |
*(.fini3) |
*(.fini3) |
*(.fini2) |
*(.fini2) |
*(.fini1) |
*(.fini1) |
*(.fini0) |
.fini0 0x0000107c 0x2 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
*(.fini0) |
0x0000107e _etext = . |
.data 0x00800060 0x0 load address 0x0000107e |
0x00800060 PROVIDE (__data_start, .) |
*(.data) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
.data 0x00800060 0x0 a2d.o |
.data 0x00800060 0x0 a2dtest.o |
.data 0x00800060 0x0 buffer.o |
.data 0x00800060 0x0 rprintf.o |
.data 0x00800060 0x0 timer.o |
.data 0x00800060 0x0 uart.o |
.data 0x00800060 0x0 vt100.o |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_mulsi3.o) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodhi4.o) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodsi4.o) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_divmodsi4.o) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_copy_data.o) |
.data 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_clear_bss.o) |
*(.data*) |
*(.rodata) |
*(.rodata*) |
*(.gnu.linkonce.d*) |
0x00800060 . = ALIGN (0x2) |
0x00800060 _edata = . |
0x00800060 PROVIDE (__data_end, .) |
.bss 0x00800060 0x172 load address 0x0000107e |
0x00800060 PROVIDE (__bss_start, .) |
*(.bss) |
.bss 0x00800060 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
.bss 0x00800060 0x0 a2d.o |
.bss 0x00800060 0x0 a2dtest.o |
.bss 0x00800060 0x0 buffer.o |
.bss 0x00800060 0x2 rprintf.o |
.bss 0x00800062 0xe timer.o |
.bss 0x00800070 0x141 uart.o |
.bss 0x008001b1 0x0 vt100.o |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_mulsi3.o) |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodhi4.o) |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_udivmodsi4.o) |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_divmodsi4.o) |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_exit.o) |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_copy_data.o) |
.bss 0x008001b1 0x0 /usr/lib/gcc/avr/4.2.2/avr4/libgcc.a(_clear_bss.o) |
*(.bss*) |
*(COMMON) |
COMMON 0x008001b1 0x1 a2d.o |
0x008001b1 a2dCompleteFlag |
COMMON 0x008001b2 0xc timer.o |
0x008001b2 Timer0Reg0 |
0x008001b6 TimerPauseReg |
0x008001ba Timer2Reg0 |
COMMON 0x008001be 0x14 uart.o |
0x008001be uartReadyTx |
0x008001bf uartRxBuffer |
0x008001c7 uartBufferedTx |
0x008001c8 uartTxBuffer |
0x008001d0 uartRxOverflow |
0x008001d2 PROVIDE (__bss_end, .) |
0x0000107e __data_load_start = LOADADDR (.data) |
0x0000107e __data_load_end = (__data_load_start + SIZEOF (.data)) |
.noinit 0x008001d2 0x0 |
0x008001d2 PROVIDE (__noinit_start, .) |
*(.noinit*) |
0x008001d2 PROVIDE (__noinit_end, .) |
0x008001d2 _end = . |
0x008001d2 PROVIDE (__heap_start, .) |
.eeprom 0x00810000 0x0 |
*(.eeprom*) |
0x00810000 __eeprom_end = . |
.fuse |
*(.fuse) |
*(.lfuse) |
*(.hfuse) |
*(.efuse) |
.lock |
*(.lock*) |
.signature |
*(.signature*) |
.stab 0x00000000 0x39c0 |
*(.stab) |
.stab 0x00000000 0x378 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
.stab 0x00000378 0x7a4 a2d.o |
0x7b0 (size before relaxing) |
.stab 0x00000b1c 0x3c0 a2dtest.o |
0x660 (size before relaxing) |
.stab 0x00000edc 0x660 buffer.o |
0x924 (size before relaxing) |
.stab 0x0000153c 0x9c0 rprintf.o |
0xcf0 (size before relaxing) |
.stab 0x00001efc 0xf54 timer.o |
0x129c (size before relaxing) |
.stab 0x00002e50 0x834 uart.o |
0xb04 (size before relaxing) |
.stab 0x00003684 0x33c vt100.o |
0x684 (size before relaxing) |
.stabstr 0x00000000 0x1a9b |
*(.stabstr) |
.stabstr 0x00000000 0x1a9b /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr4/crtm8.o |
.stab.excl |
*(.stab.excl) |
.stab.exclstr |
*(.stab.exclstr) |
.stab.index |
*(.stab.index) |
.stab.indexstr |
*(.stab.indexstr) |
.comment |
*(.comment) |
.debug |
*(.debug) |
.line |
*(.line) |
.debug_srcinfo |
*(.debug_srcinfo) |
.debug_sfnames |
*(.debug_sfnames) |
.debug_aranges |
*(.debug_aranges) |
.debug_pubnames |
*(.debug_pubnames) |
.debug_info |
*(.debug_info) |
*(.gnu.linkonce.wi.*) |
.debug_abbrev |
*(.debug_abbrev) |
.debug_line |
*(.debug_line) |
.debug_frame |
*(.debug_frame) |
.debug_str |
*(.debug_str) |
.debug_loc |
*(.debug_loc) |
.debug_macinfo |
*(.debug_macinfo) |
OUTPUT(gpsrl.out elf32-avr) |
LOAD linker stubs |
/Designs/GPSRL02A/SW/buffer/gpsrl.out |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/rprintf.c |
---|
0,0 → 1,782 |
/*! \file rprintf.c \brief printf routine and associated routines. */ |
//***************************************************************************** |
// |
// File Name : 'rprintf.c' |
// Title : printf routine and associated routines |
// Author : Pascal Stang - Copyright (C) 2000-2002 |
// Created : 2000.12.26 |
// Revised : 2003.5.1 |
// Version : 1.0 |
// Target MCU : Atmel AVR series and other targets |
// Editor Tabs : 4 |
// |
// NOTE: This code is currently below version 1.0, and therefore is considered |
// to be lacking in some functionality or documentation, or may not be fully |
// tested. Nonetheless, you can expect most functions to work. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#include <avr/pgmspace.h> |
//#include <string-avr.h> |
//#include <stdlib.h> |
#include <stdarg.h> |
#include "global.h" |
#include "rprintf.h" |
#ifndef TRUE |
#define TRUE -1 |
#define FALSE 0 |
#endif |
#define INF 32766 // maximum field size to print |
#define READMEMBYTE(a,char_ptr) ((a)?(pgm_read_byte(char_ptr)):(*char_ptr)) |
#ifdef RPRINTF_COMPLEX |
static unsigned char buf[128]; |
#endif |
// use this to store hex conversion in RAM |
//static char HexChars[] = "0123456789ABCDEF"; |
// use this to store hex conversion in program memory |
//static prog_char HexChars[] = "0123456789ABCDEF"; |
static char __attribute__ ((progmem)) HexChars[] = "0123456789ABCDEF"; |
#define hexchar(x) pgm_read_byte( HexChars+((x)&0x0f) ) |
//#define hexchar(x) ((((x)&0x0F)>9)?((x)+'A'-10):((x)+'0')) |
// function pointer to single character output routine |
static void (*rputchar)(unsigned char c); |
// *** rprintf initialization *** |
// you must call this function once and supply the character output |
// routine before using other functions in this library |
void rprintfInit(void (*putchar_func)(unsigned char c)) |
{ |
rputchar = putchar_func; |
} |
// *** rprintfChar *** |
// send a character/byte to the current output device |
void rprintfChar(unsigned char c) |
{ |
// do LF -> CR/LF translation |
if(c == '\n') |
rputchar('\r'); |
// send character |
rputchar(c); |
} |
// *** rprintfStr *** |
// prints a null-terminated string stored in RAM |
void rprintfStr(char str[]) |
{ |
// send a string stored in RAM |
// check to make sure we have a good pointer |
if (!str) return; |
// print the string until a null-terminator |
while (*str) |
rprintfChar(*str++); |
} |
// *** rprintfStrLen *** |
// prints a section of a string stored in RAM |
// begins printing at position indicated by <start> |
// prints number of characters indicated by <len> |
void rprintfStrLen(char str[], unsigned int start, unsigned int len) |
{ |
register int i=0; |
// check to make sure we have a good pointer |
if (!str) return; |
// spin through characters up to requested start |
// keep going as long as there's no null |
while((i++<start) && (*str++)); |
// for(i=0; i<start; i++) |
// { |
// // keep steping through string as long as there's no null |
// if(*str) str++; |
// } |
// then print exactly len characters |
for(i=0; i<len; i++) |
{ |
// print data out of the string as long as we haven't reached a null yet |
// at the null, start printing spaces |
if(*str) |
rprintfChar(*str++); |
else |
rprintfChar(' '); |
} |
} |
// *** rprintfProgStr *** |
// prints a null-terminated string stored in program ROM |
void rprintfProgStr(const prog_char str[]) |
{ |
// print a string stored in program memory |
register char c; |
// check to make sure we have a good pointer |
if (!str) return; |
// print the string until the null-terminator |
while((c = pgm_read_byte(str++))) |
rprintfChar(c); |
} |
// *** rprintfCRLF *** |
// prints carriage return and line feed |
void rprintfCRLF(void) |
{ |
// print CR/LF |
//rprintfChar('\r'); |
// LF -> CR/LF translation built-in to rprintfChar() |
rprintfChar('\n'); |
} |
// *** rprintfu04 *** |
// prints an unsigned 4-bit number in hex (1 digit) |
void rprintfu04(unsigned char data) |
{ |
// print 4-bit hex value |
// char Character = data&0x0f; |
// if (Character>9) |
// Character+='A'-10; |
// else |
// Character+='0'; |
rprintfChar(hexchar(data)); |
} |
// *** rprintfu08 *** |
// prints an unsigned 8-bit number in hex (2 digits) |
void rprintfu08(unsigned char data) |
{ |
// print 8-bit hex value |
rprintfu04(data>>4); |
rprintfu04(data); |
} |
// *** rprintfu16 *** |
// prints an unsigned 16-bit number in hex (4 digits) |
void rprintfu16(unsigned short data) |
{ |
// print 16-bit hex value |
rprintfu08(data>>8); |
rprintfu08(data); |
} |
// *** rprintfu32 *** |
// prints an unsigned 32-bit number in hex (8 digits) |
void rprintfu32(unsigned long data) |
{ |
// print 32-bit hex value |
rprintfu16(data>>16); |
rprintfu16(data); |
} |
// *** rprintfNum *** |
// special printf for numbers only |
// see formatting information below |
// Print the number "n" in the given "base" |
// using exactly "numDigits" |
// print +/- if signed flag "isSigned" is TRUE |
// use the character specified in "padchar" to pad extra characters |
// |
// Examples: |
// uartPrintfNum(10, 6, TRUE, ' ', 1234); --> " +1234" |
// uartPrintfNum(10, 6, FALSE, '0', 1234); --> "001234" |
// uartPrintfNum(16, 6, FALSE, '.', 0x5AA5); --> "..5AA5" |
void rprintfNum(char base, char numDigits, char isSigned, char padchar, long n) |
{ |
// define a global HexChars or use line below |
//static char HexChars[16] = "0123456789ABCDEF"; |
char *p, buf[32]; |
unsigned long x; |
unsigned char count; |
// prepare negative number |
if( isSigned && (n < 0) ) |
{ |
x = -n; |
} |
else |
{ |
x = n; |
} |
// setup little string buffer |
count = (numDigits-1)-(isSigned?1:0); |
p = buf + sizeof (buf); |
*--p = '\0'; |
// force calculation of first digit |
// (to prevent zero from not printing at all!!!) |
*--p = hexchar(x%base); x /= base; |
// calculate remaining digits |
while(count--) |
{ |
if(x != 0) |
{ |
// calculate next digit |
*--p = hexchar(x%base); x /= base; |
} |
else |
{ |
// no more digits left, pad out to desired length |
*--p = padchar; |
} |
} |
// apply signed notation if requested |
if( isSigned ) |
{ |
if(n < 0) |
{ |
*--p = '-'; |
} |
else if(n > 0) |
{ |
*--p = '+'; |
} |
else |
{ |
*--p = ' '; |
} |
} |
// print the string right-justified |
count = numDigits; |
while(count--) |
{ |
rprintfChar(*p++); |
} |
} |
#ifdef RPRINTF_FLOAT |
// *** rprintfFloat *** |
// floating-point print |
void rprintfFloat(char numDigits, double x) |
{ |
unsigned char firstplace = FALSE; |
unsigned char negative; |
unsigned char i, digit; |
double place = 1.0; |
// save sign |
negative = (x<0); |
// convert to absolute value |
x = (x>0)?(x):(-x); |
// find starting digit place |
for(i=0; i<15; i++) |
{ |
if((x/place) < 10.0) |
break; |
else |
place *= 10.0; |
} |
// print polarity character |
if(negative) |
rprintfChar('-'); |
else |
rprintfChar('+'); |
// print digits |
for(i=0; i<numDigits; i++) |
{ |
digit = (x/place); |
if(digit | firstplace | (place == 1.0)) |
{ |
firstplace = TRUE; |
rprintfChar(digit+0x30); |
} |
else |
rprintfChar(' '); |
if(place == 1.0) |
{ |
rprintfChar('.'); |
} |
x -= (digit*place); |
place /= 10.0; |
} |
} |
#endif |
#ifdef RPRINTF_SIMPLE |
// *** rprintf1RamRom *** |
// called by rprintf() - does a simple printf (supports %d, %x, %c) |
// Supports: |
// %d - decimal |
// %x - hex |
// %c - character |
int rprintf1RamRom(unsigned char stringInRom, const char *format, ...) |
{ |
// simple printf routine |
// define a global HexChars or use line below |
//static char HexChars[16] = "0123456789ABCDEF"; |
char format_flag; |
unsigned int u_val, div_val, base; |
va_list ap; |
va_start(ap, format); |
for (;;) |
{ |
while ((format_flag = READMEMBYTE(stringInRom,format++) ) != '%') |
{ // Until '%' or '\0' |
if (!format_flag) |
{ |
va_end(ap); |
return(0); |
} |
rprintfChar(format_flag); |
} |
switch (format_flag = READMEMBYTE(stringInRom,format++) ) |
{ |
case 'c': format_flag = va_arg(ap,int); |
default: rprintfChar(format_flag); continue; |
case 'd': base = 10; div_val = 10000; goto CONVERSION_LOOP; |
// case 'x': base = 16; div_val = 0x10; |
case 'x': base = 16; div_val = 0x1000; |
CONVERSION_LOOP: |
u_val = va_arg(ap,int); |
if (format_flag == 'd') |
{ |
if (((int)u_val) < 0) |
{ |
u_val = - u_val; |
rprintfChar('-'); |
} |
while (div_val > 1 && div_val > u_val) div_val /= 10; |
} |
do |
{ |
//rprintfChar(pgm_read_byte(HexChars+(u_val/div_val))); |
rprintfu04(u_val/div_val); |
u_val %= div_val; |
div_val /= base; |
} while (div_val); |
} |
} |
va_end(ap); |
} |
#endif |
#ifdef RPRINTF_COMPLEX |
// *** rprintf2RamRom *** |
// called by rprintf() - does a more powerful printf (supports %d, %u, %o, %x, %c, %s) |
// Supports: |
// %d - decimal |
// %u - unsigned decimal |
// %o - octal |
// %x - hex |
// %c - character |
// %s - strings |
// and the width,precision,padding modifiers |
// **this printf does not support floating point numbers |
int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...) |
{ |
register unsigned char *f, *bp; |
register long l; |
register unsigned long u; |
register int i; |
register int fmt; |
register unsigned char pad = ' '; |
int flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0; |
int sign = 0; |
va_list ap; |
va_start(ap, sfmt); |
f = (unsigned char *) sfmt; |
for (; READMEMBYTE(stringInRom,f); f++) |
{ |
if (READMEMBYTE(stringInRom,f) != '%') |
{ // not a format character |
// then just output the char |
rprintfChar(READMEMBYTE(stringInRom,f)); |
} |
else |
{ |
f++; // if we have a "%" then skip it |
if (READMEMBYTE(stringInRom,f) == '-') |
{ |
flush_left = 1; // minus: flush left |
f++; |
} |
if (READMEMBYTE(stringInRom,f) == '0' |
|| READMEMBYTE(stringInRom,f) == '.') |
{ |
// padding with 0 rather than blank |
pad = '0'; |
f++; |
} |
if (READMEMBYTE(stringInRom,f) == '*') |
{ // field width |
f_width = va_arg(ap, int); |
f++; |
} |
else if (Isdigit(READMEMBYTE(stringInRom,f))) |
{ |
f_width = atoiRamRom(stringInRom, (char *) f); |
while (Isdigit(READMEMBYTE(stringInRom,f))) |
f++; // skip the digits |
} |
if (READMEMBYTE(stringInRom,f) == '.') |
{ // precision |
f++; |
if (READMEMBYTE(stringInRom,f) == '*') |
{ |
prec = va_arg(ap, int); |
f++; |
} |
else if (Isdigit(READMEMBYTE(stringInRom,f))) |
{ |
prec = atoiRamRom(stringInRom, (char *) f); |
while (Isdigit(READMEMBYTE(stringInRom,f))) |
f++; // skip the digits |
} |
} |
if (READMEMBYTE(stringInRom,f) == '#') |
{ // alternate form |
hash = 1; |
f++; |
} |
if (READMEMBYTE(stringInRom,f) == 'l') |
{ // long format |
do_long = 1; |
f++; |
} |
fmt = READMEMBYTE(stringInRom,f); |
bp = buf; |
switch (fmt) { // do the formatting |
case 'd': // 'd' signed decimal |
if (do_long) |
l = va_arg(ap, long); |
else |
l = (long) (va_arg(ap, int)); |
if (l < 0) |
{ |
sign = 1; |
l = -l; |
} |
do { |
*bp++ = l % 10 + '0'; |
} while ((l /= 10) > 0); |
if (sign) |
*bp++ = '-'; |
f_width = f_width - (bp - buf); |
if (!flush_left) |
while (f_width-- > 0) |
rprintfChar(pad); |
for (bp--; bp >= buf; bp--) |
rprintfChar(*bp); |
if (flush_left) |
while (f_width-- > 0) |
rprintfChar(' '); |
break; |
case 'o': // 'o' octal number |
case 'x': // 'x' hex number |
case 'u': // 'u' unsigned decimal |
if (do_long) |
u = va_arg(ap, unsigned long); |
else |
u = (unsigned long) (va_arg(ap, unsigned)); |
if (fmt == 'u') |
{ // unsigned decimal |
do { |
*bp++ = u % 10 + '0'; |
} while ((u /= 10) > 0); |
} |
else if (fmt == 'o') |
{ // octal |
do { |
*bp++ = u % 8 + '0'; |
} while ((u /= 8) > 0); |
if (hash) |
*bp++ = '0'; |
} |
else if (fmt == 'x') |
{ // hex |
do { |
i = u % 16; |
if (i < 10) |
*bp++ = i + '0'; |
else |
*bp++ = i - 10 + 'a'; |
} while ((u /= 16) > 0); |
if (hash) |
{ |
*bp++ = 'x'; |
*bp++ = '0'; |
} |
} |
i = f_width - (bp - buf); |
if (!flush_left) |
while (i-- > 0) |
rprintfChar(pad); |
for (bp--; bp >= buf; bp--) |
rprintfChar((int) (*bp)); |
if (flush_left) |
while (i-- > 0) |
rprintfChar(' '); |
break; |
case 'c': // 'c' character |
i = va_arg(ap, int); |
rprintfChar((int) (i)); |
break; |
case 's': // 's' string |
bp = va_arg(ap, unsigned char *); |
if (!bp) |
bp = (unsigned char *) "(nil)"; |
f_width = f_width - strlen((char *) bp); |
if (!flush_left) |
while (f_width-- > 0) |
rprintfChar(pad); |
for (i = 0; *bp && i < prec; i++) |
{ |
rprintfChar(*bp); |
bp++; |
} |
if (flush_left) |
while (f_width-- > 0) |
rprintfChar(' '); |
break; |
case '%': // '%' character |
rprintfChar('%'); |
break; |
} |
flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0; |
sign = 0; |
pad = ' '; |
} |
} |
va_end(ap); |
return 0; |
} |
unsigned char Isdigit(char c) |
{ |
if((c >= 0x30) && (c <= 0x39)) |
return TRUE; |
else |
return FALSE; |
} |
int atoiRamRom(unsigned char stringInRom, char *str) |
{ |
int num = 0;; |
while(Isdigit(READMEMBYTE(stringInRom,str))) |
{ |
num *= 10; |
num += ((READMEMBYTE(stringInRom,str++)) - 0x30); |
} |
return num; |
} |
#endif |
//****************************************************************************** |
// code below this line is commented out and can be ignored |
//****************************************************************************** |
/* |
char* sprintf(const char *sfmt, ...) |
{ |
register unsigned char *f, *bp, *str; |
register long l; |
register unsigned long u; |
register int i; |
register int fmt; |
register unsigned char pad = ' '; |
int flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0; |
int sign = 0; |
va_list ap; |
va_start(ap, sfmt); |
str = bufstring; |
f = (unsigned char *) sfmt; |
for (; *f; f++) |
{ |
if (*f != '%') |
{ // not a format character |
*str++ = (*f); // then just output the char |
} |
else |
{ |
f++; // if we have a "%" then skip it |
if (*f == '-') |
{ |
flush_left = 1; // minus: flush left |
f++; |
} |
if (*f == '0' || *f == '.') |
{ |
// padding with 0 rather than blank |
pad = '0'; |
f++; |
} |
if (*f == '*') |
{ // field width |
f_width = va_arg(ap, int); |
f++; |
} |
else if (Isdigit(*f)) |
{ |
f_width = atoi((char *) f); |
while (Isdigit(*f)) |
f++; // skip the digits |
} |
if (*f == '.') |
{ // precision |
f++; |
if (*f == '*') |
{ |
prec = va_arg(ap, int); |
f++; |
} |
else if (Isdigit(*f)) |
{ |
prec = atoi((char *) f); |
while (Isdigit(*f)) |
f++; // skip the digits |
} |
} |
if (*f == '#') |
{ // alternate form |
hash = 1; |
f++; |
} |
if (*f == 'l') |
{ // long format |
do_long = 1; |
f++; |
} |
fmt = *f; |
bp = buf; |
switch (fmt) { // do the formatting |
case 'd': // 'd' signed decimal |
if (do_long) |
l = va_arg(ap, long); |
else |
l = (long) (va_arg(ap, int)); |
if (l < 0) |
{ |
sign = 1; |
l = -l; |
} |
do { |
*bp++ = l % 10 + '0'; |
} while ((l /= 10) > 0); |
if (sign) |
*bp++ = '-'; |
f_width = f_width - (bp - buf); |
if (!flush_left) |
while (f_width-- > 0) |
*str++ = (pad); |
for (bp--; bp >= buf; bp--) |
*str++ = (*bp); |
if (flush_left) |
while (f_width-- > 0) |
*str++ = (' '); |
break; |
case 'o': // 'o' octal number |
case 'x': // 'x' hex number |
case 'u': // 'u' unsigned decimal |
if (do_long) |
u = va_arg(ap, unsigned long); |
else |
u = (unsigned long) (va_arg(ap, unsigned)); |
if (fmt == 'u') |
{ // unsigned decimal |
do { |
*bp++ = u % 10 + '0'; |
} while ((u /= 10) > 0); |
} |
else if (fmt == 'o') |
{ // octal |
do { |
*bp++ = u % 8 + '0'; |
} while ((u /= 8) > 0); |
if (hash) |
*bp++ = '0'; |
} |
else if (fmt == 'x') |
{ // hex |
do { |
i = u % 16; |
if (i < 10) |
*bp++ = i + '0'; |
else |
*bp++ = i - 10 + 'a'; |
} while ((u /= 16) > 0); |
if (hash) |
{ |
*bp++ = 'x'; |
*bp++ = '0'; |
} |
} |
i = f_width - (bp - buf); |
if (!flush_left) |
while (i-- > 0) |
*str++ = (pad); |
for (bp--; bp >= buf; bp--) |
*str++ = ((int) (*bp)); |
if (flush_left) |
while (i-- > 0) |
*str++ = (' '); |
break; |
case 'c': // 'c' character |
i = va_arg(ap, int); |
*str++ = ((int) (i)); |
break; |
case 's': // 's' string |
bp = va_arg(ap, unsigned char *); |
if (!bp) |
bp = (unsigned char *) "(nil)"; |
f_width = f_width - strlen((char *) bp); |
if (!flush_left) |
while (f_width-- > 0) |
*str++ = (pad); |
for (i = 0; *bp && i < prec; i++) |
{ |
*str++ = (*bp); |
bp++; |
} |
if (flush_left) |
while (f_width-- > 0) |
*str++ = (' '); |
break; |
case '%': // '%' character |
*str++ = ('%'); |
break; |
} |
flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0; |
sign = 0; |
pad = ' '; |
} |
} |
va_end(ap); |
// terminate string with null |
*str++ = '\0'; |
return bufstring; |
} |
*/ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/rprintf.h |
---|
0,0 → 1,191 |
/*! \file rprintf.h \brief printf routine and associated routines. */ |
//**************************************************************************** |
// |
// File Name : 'rprintf.h' |
// Title : printf routine and associated routines |
// Author : Pascal Stang - Copyright (C) 2000-2002 |
// Created : 2000.12.26 |
// Revised : 2003.5.1 |
// Version : 1.0 |
// Target MCU : Atmel AVR series and other targets |
// Editor Tabs : 4 |
// |
// NOTE: This code is currently below version 1.0, and therefore is considered |
// to be lacking in some functionality or documentation, or may not be fully |
// tested. Nonetheless, you can expect most functions to work. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
/// \ingroup general |
/// \defgroup rprintf printf() Function Library (rprintf.c) |
/// \code #include "rprintf.h" \endcode |
/// \par Overview |
/// The rprintf function library provides a simplified (reduced) version of |
/// the common C printf() function. See the code files for details about |
/// which printf features are supported. Also in this library are a |
/// variety of functions for fast printing of certain common data types |
/// (variable types). Functions include print string from RAM, print |
/// string from ROM, print string snippet, print hex byte/short/long, and |
/// a custom-formatted number print, as well as an optional floating-point |
/// print routine. |
/// |
/// \note All output from the rprintf library can be directed to any device |
/// or software which accepts characters. This means that rprintf output |
/// can be sent to the UART (serial port) or can be used with the LCD |
/// display libraries to print formatted text on the screen. |
// |
//**************************************************************************** |
//@{ |
#ifndef RPRINTF_H |
#define RPRINTF_H |
// needed for use of PSTR below |
#include <avr/pgmspace.h> |
// configuration |
// defining RPRINTF_SIMPLE will compile a smaller, simpler, and faster printf() function |
// defining RPRINTF_COMPLEX will compile a larger, more capable, and slower printf() function |
#ifndef RPRINTF_COMPLEX |
#define RPRINTF_SIMPLE |
#endif |
// Define RPRINTF_FLOAT to enable the floating-point printf function: rprintfFloat() |
// (adds +4600bytes or 2.2Kwords of code) |
// defines/constants |
#define STRING_IN_RAM 0 |
#define STRING_IN_ROM 1 |
// make a putchar for those that are used to using it |
//#define putchar(c) rprintfChar(c); |
// functions |
//! Initializes the rprintf library for an output stream. |
/// You must call this initializer once before using any other rprintf function. |
/// The argument must be a character stream output function. |
void rprintfInit(void (*putchar_func)(unsigned char c)); |
//! prints a single character to the current output device |
void rprintfChar(unsigned char c); |
//! prints a null-terminated string stored in RAM |
void rprintfStr(char str[]); |
//! Prints a section of a string stored in RAM. |
/// Begins printing at position indicated by <start>, |
/// and prints number of characters indicated by <len>. |
void rprintfStrLen(char str[], unsigned int start, unsigned int len); |
//! prints a string stored in program rom |
/// \note This function does not actually store your string in |
/// program rom, but merely reads it assuming you stored it properly. |
void rprintfProgStr(const prog_char str[]); |
//! Using the function rprintfProgStrM(...) automatically causes |
/// your string to be stored in ROM, thereby not wasting precious RAM. |
/// Example usage: |
/// \code |
/// rprintfProgStrM("Hello, this string is stored in program rom"); |
/// \endcode |
#define rprintfProgStrM(string) (rprintfProgStr(PSTR(string))) |
//! Prints a carriage-return and line-feed. |
/// Useful when printing to serial ports/terminals. |
void rprintfCRLF(void); |
// Prints the number contained in "data" in hex format |
// u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively |
void rprintfu04(unsigned char data); ///< Print 4-bit hex number. Outputs a single hex character. |
void rprintfu08(unsigned char data); ///< Print 8-bit hex number. Outputs two hex characters. |
void rprintfu16(unsigned short data); ///< Print 16-bit hex number. Outputs four hex characters. |
void rprintfu32(unsigned long data); ///< Print 32-bit hex number. Outputs eight hex characters. |
//! A flexible integer-number printing routine. |
/// Print the number "n" in the given "base", using exactly "numDigits". |
/// Print +/- if signed flag "isSigned" is TRUE. |
/// The character specified in "padchar" will be used to pad extra characters. |
/// |
/// Examples: |
/// \code |
/// uartPrintfNum(10, 6, TRUE, ' ', 1234); --> " +1234" |
/// uartPrintfNum(10, 6, FALSE, '0', 1234); --> "001234" |
/// uartPrintfNum(16, 6, FALSE, '.', 0x5AA5); --> "..5AA5" |
/// \endcode |
void rprintfNum(char base, char numDigits, char isSigned, char padchar, long n); |
#ifdef RPRINTF_FLOAT |
//! floating-point print routine |
void rprintfFloat(char numDigits, double x); |
#endif |
// NOTE: Below you'll see the function prototypes of rprintf1RamRom and |
// rprintf2RamRom. rprintf1RamRom and rprintf2RamRom are both reduced versions |
// of the regular C printf() command. However, they are modified to be able |
// to read their text/format strings from RAM or ROM in the Atmel microprocessors. |
// Unless you really intend to, do not use the "RamRom" versions of the functions |
// directly. Instead use the #defined function versions: |
// |
// printfx("text/format",args) ...to keep your text/format string stored in RAM |
// - or - |
// printfxROM("text/format",args) ...to keep your text/format string stored in ROM |
// |
// where x is either 1 or 2 for the simple or more powerful version of printf() |
// |
// Since there is much more ROM than RAM available in the Atmel microprocessors, |
// and nearly all text/format strings are constant (never change in the course |
// of the program), you should try to use the ROM printf version exclusively. |
// This will ensure you leave as much RAM as possible for program variables and |
// data. |
//! \fn int rprintf(const char *format, ...); |
/// A reduced substitute for the usual C printf() function. |
/// This function actually points to either rprintf1RamRom or rprintf2RamRom |
/// depending on the user's selection. Rprintf1 is a simple small fast print |
/// routine while rprintf2 is larger and slower but more capable. To choose |
/// the routine you would like to use, define either RPRINTF_SIMPLE or |
/// RPRINTF_COMPLEX in global.h. |
#ifdef RPRINTF_SIMPLE |
//! A simple printf routine. |
/// Called by rprintf() - does a simple printf (supports %d, %x, %c). |
/// Supports: |
/// - %d - decimal |
/// - %x - hex |
/// - %c - character |
int rprintf1RamRom(unsigned char stringInRom, const char *format, ...); |
// #defines for RAM or ROM operation |
#define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args) |
#define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args) |
// *** Default rprintf(...) *** |
// this next line determines what the the basic rprintf() defaults to: |
#define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args) |
#endif |
#ifdef RPRINTF_COMPLEX |
//! A more powerful printf routine. |
/// Called by rprintf() - does a more powerful printf (supports %d, %u, %o, %x, %c, %s). |
/// Supports: |
/// - %d - decimal |
/// - %u - unsigned decimal |
/// - %o - octal |
/// - %x - hex |
/// - %c - character |
/// - %s - strings |
/// - and the width,precision,padding modifiers |
/// \note This printf does not support floating point numbers. |
int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...); |
// #defines for RAM or ROM operation |
#define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args) |
#define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args) |
// *** Default rprintf(...) *** |
// this next line determines what the the basic rprintf() defaults to: |
#define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args) |
#endif |
#endif |
//@} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/timer.c |
---|
0,0 → 1,469 |
/*! \file timer.c \brief System Timer function library. */ |
//***************************************************************************** |
// |
// File Name : 'timer.c' |
// Title : System Timer function library |
// Author : Pascal Stang - Copyright (C) 2000-2002 |
// Created : 11/22/2000 |
// Revised : 07/09/2003 |
// Version : 1.1 |
// Target MCU : Atmel AVR Series |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/sleep.h> |
#include "global.h" |
#include "timer.h" |
#include "rprintf.h" |
// Program ROM constants |
// the prescale division values stored in order of timer control register index |
// STOP, CLK, CLK/8, CLK/64, CLK/256, CLK/1024 |
unsigned short __attribute__ ((progmem)) TimerPrescaleFactor[] = {0,1,8,64,256,1024}; |
// the prescale division values stored in order of timer control register index |
// STOP, CLK, CLK/8, CLK/32, CLK/64, CLK/128, CLK/256, CLK/1024 |
unsigned short __attribute__ ((progmem)) TimerRTCPrescaleFactor[] = {0,1,8,32,64,128,256,1024}; |
// Global variables |
// time registers |
volatile unsigned long TimerPauseReg; |
volatile unsigned long Timer0Reg0; |
volatile unsigned long Timer2Reg0; |
typedef void (*voidFuncPtr)(void); |
volatile static voidFuncPtr TimerIntFunc[TIMER_NUM_INTERRUPTS]; |
// delay for a minimum of <us> microseconds |
// the time resolution is dependent on the time the loop takes |
// e.g. with 4Mhz and 5 cycles per loop, the resolution is 1.25 us |
void delay_us(unsigned short time_us) |
{ |
unsigned short delay_loops; |
register unsigned short i; |
delay_loops = (time_us+3)/5*CYCLES_PER_US; // +3 for rounding up (dirty) |
// one loop takes 5 cpu cycles |
for (i=0; i < delay_loops; i++) {}; |
} |
/* |
void delay_ms(unsigned char time_ms) |
{ |
unsigned short delay_count = F_CPU / 4000; |
unsigned short cnt; |
asm volatile ("\n" |
"L_dl1%=:\n\t" |
"mov %A0, %A2\n\t" |
"mov %B0, %B2\n" |
"L_dl2%=:\n\t" |
"sbiw %A0, 1\n\t" |
"brne L_dl2%=\n\t" |
"dec %1\n\t" "brne L_dl1%=\n\t":"=&w" (cnt) |
:"r"(time_ms), "r"((unsigned short) (delay_count)) |
); |
} |
*/ |
void timerInit(void) |
{ |
u08 intNum; |
// detach all user functions from interrupts |
for(intNum=0; intNum<TIMER_NUM_INTERRUPTS; intNum++) |
timerDetach(intNum); |
// initialize all timers |
timer0Init(); |
timer1Init(); |
#ifdef TCNT2 // support timer2 only if it exists |
timer2Init(); |
#endif |
// enable interrupts |
sei(); |
} |
void timer0Init() |
{ |
// initialize timer 0 |
timer0SetPrescaler( TIMER0PRESCALE ); // set prescaler |
outb(TCNT0, 0); // reset TCNT0 |
sbi(TIMSK, TOIE0); // enable TCNT0 overflow interrupt |
timer0ClearOverflowCount(); // initialize time registers |
} |
void timer1Init(void) |
{ |
// initialize timer 1 |
timer1SetPrescaler( TIMER1PRESCALE ); // set prescaler |
outb(TCNT1H, 0); // reset TCNT1 |
outb(TCNT1L, 0); |
sbi(TIMSK, TOIE1); // enable TCNT1 overflow |
} |
#ifdef TCNT2 // support timer2 only if it exists |
void timer2Init(void) |
{ |
// initialize timer 2 |
timer2SetPrescaler( TIMER2PRESCALE ); // set prescaler |
outb(TCNT2, 0); // reset TCNT2 |
sbi(TIMSK, TOIE2); // enable TCNT2 overflow |
timer2ClearOverflowCount(); // initialize time registers |
} |
#endif |
void timer0SetPrescaler(u08 prescale) |
{ |
// set prescaler on timer 0 |
outb(TCCR0, (inb(TCCR0) & ~TIMER_PRESCALE_MASK) | prescale); |
} |
void timer1SetPrescaler(u08 prescale) |
{ |
// set prescaler on timer 1 |
outb(TCCR1B, (inb(TCCR1B) & ~TIMER_PRESCALE_MASK) | prescale); |
} |
#ifdef TCNT2 // support timer2 only if it exists |
void timer2SetPrescaler(u08 prescale) |
{ |
// set prescaler on timer 2 |
outb(TCCR2, (inb(TCCR2) & ~TIMER_PRESCALE_MASK) | prescale); |
} |
#endif |
u16 timer0GetPrescaler(void) |
{ |
// get the current prescaler setting |
return (pgm_read_word(TimerPrescaleFactor+(inb(TCCR0) & TIMER_PRESCALE_MASK))); |
} |
u16 timer1GetPrescaler(void) |
{ |
// get the current prescaler setting |
return (pgm_read_word(TimerPrescaleFactor+(inb(TCCR1B) & TIMER_PRESCALE_MASK))); |
} |
#ifdef TCNT2 // support timer2 only if it exists |
u16 timer2GetPrescaler(void) |
{ |
//TODO: can we assume for all 3-timer AVR processors, |
// that timer2 is the RTC timer? |
// get the current prescaler setting |
return (pgm_read_word(TimerRTCPrescaleFactor+(inb(TCCR2) & TIMER_PRESCALE_MASK))); |
} |
#endif |
void timerAttach(u08 interruptNum, void (*userFunc)(void) ) |
{ |
// make sure the interrupt number is within bounds |
if(interruptNum < TIMER_NUM_INTERRUPTS) |
{ |
// set the interrupt function to run |
// the supplied user's function |
TimerIntFunc[interruptNum] = userFunc; |
} |
} |
void timerDetach(u08 interruptNum) |
{ |
// make sure the interrupt number is within bounds |
if(interruptNum < TIMER_NUM_INTERRUPTS) |
{ |
// set the interrupt function to run nothing |
TimerIntFunc[interruptNum] = 0; |
} |
} |
/* |
u32 timerMsToTics(u16 ms) |
{ |
// calculate the prescaler division rate |
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0))); |
// calculate the number of timer tics in x milliseconds |
return (ms*(F_CPU/(prescaleDiv*256)))/1000; |
} |
u16 timerTicsToMs(u32 tics) |
{ |
// calculate the prescaler division rate |
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0))); |
// calculate the number of milliseconds in x timer tics |
return (tics*1000*(prescaleDiv*256))/F_CPU; |
} |
*/ |
void timerPause(unsigned short pause_ms) |
{ |
// pauses for exactly <pause_ms> number of milliseconds |
u08 timerThres; |
u32 ticRateHz; |
u32 pause; |
// capture current pause timer value |
timerThres = inb(TCNT0); |
// reset pause timer overflow count |
TimerPauseReg = 0; |
// calculate delay for [pause_ms] milliseconds |
// prescaler division = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0))) |
ticRateHz = F_CPU/timer0GetPrescaler(); |
// precision management |
// prevent overflow and precision underflow |
// -could add more conditions to improve accuracy |
if( ((ticRateHz < 429497) && (pause_ms <= 10000)) ) |
pause = (pause_ms*ticRateHz)/1000; |
else |
pause = pause_ms*(ticRateHz/1000); |
// loop until time expires |
while( ((TimerPauseReg<<8) | inb(TCNT0)) < (pause+timerThres) ) |
{ |
if( TimerPauseReg < (pause>>8)); |
{ |
// save power by idling the processor |
set_sleep_mode(SLEEP_MODE_IDLE); |
sleep_mode(); |
} |
} |
/* old inaccurate code, for reference |
// calculate delay for [pause_ms] milliseconds |
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0))); |
u32 pause = (pause_ms*(F_CPU/(prescaleDiv*256)))/1000; |
TimerPauseReg = 0; |
while(TimerPauseReg < pause); |
*/ |
} |
void timer0ClearOverflowCount(void) |
{ |
// clear the timer overflow counter registers |
Timer0Reg0 = 0; // initialize time registers |
} |
long timer0GetOverflowCount(void) |
{ |
// return the current timer overflow count |
// (this is since the last timer0ClearOverflowCount() command was called) |
return Timer0Reg0; |
} |
#ifdef TCNT2 // support timer2 only if it exists |
void timer2ClearOverflowCount(void) |
{ |
// clear the timer overflow counter registers |
Timer2Reg0 = 0; // initialize time registers |
} |
long timer2GetOverflowCount(void) |
{ |
// return the current timer overflow count |
// (this is since the last timer2ClearOverflowCount() command was called) |
return Timer2Reg0; |
} |
#endif |
void timer1PWMInit(u08 bitRes) |
{ |
// configures timer1 for use with PWM output |
// on OC1A and OC1B pins |
// enable timer1 as 8,9,10bit PWM |
if(bitRes == 9) |
{ // 9bit mode |
sbi(TCCR1A,PWM11); |
cbi(TCCR1A,PWM10); |
} |
else if( bitRes == 10 ) |
{ // 10bit mode |
sbi(TCCR1A,PWM11); |
sbi(TCCR1A,PWM10); |
} |
else |
{ // default 8bit mode |
cbi(TCCR1A,PWM11); |
sbi(TCCR1A,PWM10); |
} |
// clear output compare value A |
outb(OCR1AH, 0); |
outb(OCR1AL, 0); |
// clear output compare value B |
outb(OCR1BH, 0); |
outb(OCR1BL, 0); |
} |
#ifdef WGM10 |
// include support for arbitrary top-count PWM |
// on new AVR processors that support it |
void timer1PWMInitICR(u16 topcount) |
{ |
// set PWM mode with ICR top-count |
cbi(TCCR1A,WGM10); |
sbi(TCCR1A,WGM11); |
sbi(TCCR1B,WGM12); |
sbi(TCCR1B,WGM13); |
// set top count value |
ICR1 = topcount; |
// clear output compare value A |
OCR1A = 0; |
// clear output compare value B |
OCR1B = 0; |
} |
#endif |
void timer1PWMOff(void) |
{ |
// turn off timer1 PWM mode |
cbi(TCCR1A,PWM11); |
cbi(TCCR1A,PWM10); |
// set PWM1A/B (OutputCompare action) to none |
timer1PWMAOff(); |
timer1PWMBOff(); |
} |
void timer1PWMAOn(void) |
{ |
// turn on channel A (OC1A) PWM output |
// set OC1A as non-inverted PWM |
sbi(TCCR1A,COM1A1); |
cbi(TCCR1A,COM1A0); |
} |
void timer1PWMBOn(void) |
{ |
// turn on channel B (OC1B) PWM output |
// set OC1B as non-inverted PWM |
sbi(TCCR1A,COM1B1); |
cbi(TCCR1A,COM1B0); |
} |
void timer1PWMAOff(void) |
{ |
// turn off channel A (OC1A) PWM output |
// set OC1A (OutputCompare action) to none |
cbi(TCCR1A,COM1A1); |
cbi(TCCR1A,COM1A0); |
} |
void timer1PWMBOff(void) |
{ |
// turn off channel B (OC1B) PWM output |
// set OC1B (OutputCompare action) to none |
cbi(TCCR1A,COM1B1); |
cbi(TCCR1A,COM1B0); |
} |
void timer1PWMASet(u16 pwmDuty) |
{ |
// set PWM (output compare) duty for channel A |
// this PWM output is generated on OC1A pin |
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM |
// pwmDuty should be in the range 0-511 for 9bit PWM |
// pwmDuty should be in the range 0-1023 for 10bit PWM |
//outp( (pwmDuty>>8), OCR1AH); // set the high 8bits of OCR1A |
//outp( (pwmDuty&0x00FF), OCR1AL); // set the low 8bits of OCR1A |
OCR1A = pwmDuty; |
} |
void timer1PWMBSet(u16 pwmDuty) |
{ |
// set PWM (output compare) duty for channel B |
// this PWM output is generated on OC1B pin |
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM |
// pwmDuty should be in the range 0-511 for 9bit PWM |
// pwmDuty should be in the range 0-1023 for 10bit PWM |
//outp( (pwmDuty>>8), OCR1BH); // set the high 8bits of OCR1B |
//outp( (pwmDuty&0x00FF), OCR1BL); // set the low 8bits of OCR1B |
OCR1B = pwmDuty; |
} |
//! Interrupt handler for tcnt0 overflow interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW0) |
{ |
Timer0Reg0++; // increment low-order counter |
// increment pause counter |
TimerPauseReg++; |
// if a user function is defined, execute it too |
if(TimerIntFunc[TIMER0OVERFLOW_INT]) |
TimerIntFunc[TIMER0OVERFLOW_INT](); |
} |
//! Interrupt handler for tcnt1 overflow interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW1) |
{ |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER1OVERFLOW_INT]) |
TimerIntFunc[TIMER1OVERFLOW_INT](); |
} |
#ifdef TCNT2 // support timer2 only if it exists |
//! Interrupt handler for tcnt2 overflow interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW2) |
{ |
Timer2Reg0++; // increment low-order counter |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER2OVERFLOW_INT]) |
TimerIntFunc[TIMER2OVERFLOW_INT](); |
} |
#endif |
#ifdef OCR0 |
// include support for Output Compare 0 for new AVR processors that support it |
//! Interrupt handler for OutputCompare0 match (OC0) interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE0) |
{ |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER0OUTCOMPARE_INT]) |
TimerIntFunc[TIMER0OUTCOMPARE_INT](); |
} |
#endif |
//! Interrupt handler for CutputCompare1A match (OC1A) interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1A) |
{ |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER1OUTCOMPAREA_INT]) |
TimerIntFunc[TIMER1OUTCOMPAREA_INT](); |
} |
//! Interrupt handler for OutputCompare1B match (OC1B) interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1B) |
{ |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER1OUTCOMPAREB_INT]) |
TimerIntFunc[TIMER1OUTCOMPAREB_INT](); |
} |
//! Interrupt handler for InputCapture1 (IC1) interrupt |
TIMER_INTERRUPT_HANDLER(SIG_INPUT_CAPTURE1) |
{ |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER1INPUTCAPTURE_INT]) |
TimerIntFunc[TIMER1INPUTCAPTURE_INT](); |
} |
//! Interrupt handler for OutputCompare2 match (OC2) interrupt |
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE2) |
{ |
// if a user function is defined, execute it |
if(TimerIntFunc[TIMER2OUTCOMPARE_INT]) |
TimerIntFunc[TIMER2OUTCOMPARE_INT](); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/timer.h |
---|
0,0 → 1,314 |
/*! \file timer.h \brief System Timer function library. */ |
//***************************************************************************** |
// |
// File Name : 'timer.h' |
// Title : System Timer function library |
// Author : Pascal Stang - Copyright (C) 2000-2002 |
// Created : 11/22/2000 |
// Revised : 02/10/2003 |
// Version : 1.1 |
// Target MCU : Atmel AVR Series |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
/// \ingroup driver_avr |
/// \defgroup timer Timer Function Library (timer.c) |
/// \code #include "timer.h" \endcode |
/// \par Overview |
/// This library provides functions for use with the timers internal |
/// to the AVR processors. Functions include initialization, set prescaler, |
/// calibrated pause function (in milliseconds), attaching and detaching of |
/// user functions to interrupts, overflow counters, PWM. Arbitrary |
/// frequency generation has been moved to the Pulse Library. |
/// |
/// \par About Timers |
/// The Atmel AVR-series processors each contain at least one |
/// hardware timer/counter. Many of the processors contain 2 or 3 |
/// timers. Generally speaking, a timer is a hardware counter inside |
/// the processor which counts at a rate related to the main CPU clock |
/// frequency. Because the counter value increasing (counting up) at |
/// a precise rate, we can use it as a timer to create or measure |
/// precise delays, schedule events, or generate signals of a certain |
/// frequency or pulse-width. |
/// \par |
/// As an example, the ATmega163 processor has 3 timer/counters. |
/// Timer0, Timer1, and Timer2 are 8, 16, and 8 bits wide respectively. |
/// This means that they overflow, or roll over back to zero, at a |
/// count value of 256 for 8bits or 65536 for 16bits. A prescaler is |
/// avaiable for each timer, and the prescaler allows you to pre-divide |
/// the main CPU clock rate down to a slower speed before feeding it to |
/// the counting input of a timer. For example, if the CPU clock |
/// frequency is 3.69MHz, and Timer0's prescaler is set to divide-by-8, |
/// then Timer0 will "tic" at 3690000/8 = 461250Hz. Because Timer0 is |
/// an 8bit timer, it will count to 256 in just 256/461250Hz = 0.555ms. |
/// In fact, when it hits 255, it will overflow and start again at |
/// zero. In this case, Timer0 will overflow 461250/256 = 1801.76 |
/// times per second. |
/// \par |
/// Timer0 can be used a number of ways simultaneously. First, the |
/// value of the timer can be read by accessing the CPU register \c TCNT0. |
/// We could, for example, figure out how long it takes to execute a |
/// C command by recording the value of \c TCNT0 before and after |
/// execution, then subtract (after-before) = time elapsed. Or we can |
/// enable the overflow interrupt which goes off every time T0 |
/// overflows and count out longer delays (multiple overflows), or |
/// execute a special periodic function at every overflow. |
/// \par |
/// The other timers (Timer1 and Timer2) offer all the abilities of |
/// Timer0 and many more features. Both T1 and T2 can operate as |
/// general-purpose timers, but T1 has special hardware allowing it to |
/// generate PWM signals, while T2 is specially designed to help count |
/// out real time (like hours, minutes, seconds). See the |
/// Timer/Counter section of the processor datasheet for more info. |
/// |
//***************************************************************************** |
//@{ |
#ifndef TIMER_H |
#define TIMER_H |
#include "global.h" |
// constants/macros/typdefs |
// processor compatibility fixes |
#ifdef __AVR_ATmega323__ |
// redefinition for the Mega323 |
#define CTC1 CTC10 |
#endif |
#ifndef PWM10 |
// mega128 PWM bits |
#define PWM10 WGM10 |
#define PWM11 WGM11 |
#endif |
// Timer/clock prescaler values and timer overflow rates |
// tics = rate at which the timer counts up |
// 8bitoverflow = rate at which the timer overflows 8bits (or reaches 256) |
// 16bit [overflow] = rate at which the timer overflows 16bits (65536) |
// |
// overflows can be used to generate periodic interrupts |
// |
// for 8MHz crystal |
// 0 = STOP (Timer not counting) |
// 1 = CLOCK tics= 8MHz 8bitoverflow= 31250Hz 16bit= 122.070Hz |
// 2 = CLOCK/8 tics= 1MHz 8bitoverflow= 3906.25Hz 16bit= 15.259Hz |
// 3 = CLOCK/64 tics= 125kHz 8bitoverflow= 488.28Hz 16bit= 1.907Hz |
// 4 = CLOCK/256 tics= 31250Hz 8bitoverflow= 122.07Hz 16bit= 0.477Hz |
// 5 = CLOCK/1024 tics= 7812.5Hz 8bitoverflow= 30.52Hz 16bit= 0.119Hz |
// 6 = External Clock on T(x) pin (falling edge) |
// 7 = External Clock on T(x) pin (rising edge) |
// for 4MHz crystal |
// 0 = STOP (Timer not counting) |
// 1 = CLOCK tics= 4MHz 8bitoverflow= 15625Hz 16bit= 61.035Hz |
// 2 = CLOCK/8 tics= 500kHz 8bitoverflow= 1953.125Hz 16bit= 7.629Hz |
// 3 = CLOCK/64 tics= 62500Hz 8bitoverflow= 244.141Hz 16bit= 0.954Hz |
// 4 = CLOCK/256 tics= 15625Hz 8bitoverflow= 61.035Hz 16bit= 0.238Hz |
// 5 = CLOCK/1024 tics= 3906.25Hz 8bitoverflow= 15.259Hz 16bit= 0.060Hz |
// 6 = External Clock on T(x) pin (falling edge) |
// 7 = External Clock on T(x) pin (rising edge) |
// for 3.69MHz crystal |
// 0 = STOP (Timer not counting) |
// 1 = CLOCK tics= 3.69MHz 8bitoverflow= 14414Hz 16bit= 56.304Hz |
// 2 = CLOCK/8 tics= 461250Hz 8bitoverflow= 1801.758Hz 16bit= 7.038Hz |
// 3 = CLOCK/64 tics= 57625.25Hz 8bitoverflow= 225.220Hz 16bit= 0.880Hz |
// 4 = CLOCK/256 tics= 14414.063Hz 8bitoverflow= 56.305Hz 16bit= 0.220Hz |
// 5 = CLOCK/1024 tics= 3603.516Hz 8bitoverflow= 14.076Hz 16bit= 0.055Hz |
// 6 = External Clock on T(x) pin (falling edge) |
// 7 = External Clock on T(x) pin (rising edge) |
// for 32.768KHz crystal on timer 2 (use for real-time clock) |
// 0 = STOP |
// 1 = CLOCK tics= 32.768kHz 8bitoverflow= 128Hz |
// 2 = CLOCK/8 tics= 4096kHz 8bitoverflow= 16Hz |
// 3 = CLOCK/32 tics= 1024kHz 8bitoverflow= 4Hz |
// 4 = CLOCK/64 tics= 512Hz 8bitoverflow= 2Hz |
// 5 = CLOCK/128 tics= 256Hz 8bitoverflow= 1Hz |
// 6 = CLOCK/256 tics= 128Hz 8bitoverflow= 0.5Hz |
// 7 = CLOCK/1024 tics= 32Hz 8bitoverflow= 0.125Hz |
#define TIMER_CLK_STOP 0x00 ///< Timer Stopped |
#define TIMER_CLK_DIV1 0x01 ///< Timer clocked at F_CPU |
#define TIMER_CLK_DIV8 0x02 ///< Timer clocked at F_CPU/8 |
#define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 |
#define TIMER_CLK_DIV256 0x04 ///< Timer clocked at F_CPU/256 |
#define TIMER_CLK_DIV1024 0x05 ///< Timer clocked at F_CPU/1024 |
#define TIMER_CLK_T_FALL 0x06 ///< Timer clocked at T falling edge |
#define TIMER_CLK_T_RISE 0x07 ///< Timer clocked at T rising edge |
#define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask |
#define TIMERRTC_CLK_STOP 0x00 ///< RTC Timer Stopped |
#define TIMERRTC_CLK_DIV1 0x01 ///< RTC Timer clocked at F_CPU |
#define TIMERRTC_CLK_DIV8 0x02 ///< RTC Timer clocked at F_CPU/8 |
#define TIMERRTC_CLK_DIV32 0x03 ///< RTC Timer clocked at F_CPU/32 |
#define TIMERRTC_CLK_DIV64 0x04 ///< RTC Timer clocked at F_CPU/64 |
#define TIMERRTC_CLK_DIV128 0x05 ///< RTC Timer clocked at F_CPU/128 |
#define TIMERRTC_CLK_DIV256 0x06 ///< RTC Timer clocked at F_CPU/256 |
#define TIMERRTC_CLK_DIV1024 0x07 ///< RTC Timer clocked at F_CPU/1024 |
#define TIMERRTC_PRESCALE_MASK 0x07 ///< RTC Timer Prescaler Bit-Mask |
// default prescale settings for the timers |
// these settings are applied when you call |
// timerInit or any of the timer<x>Init |
#define TIMER0PRESCALE TIMER_CLK_DIV8 ///< timer 0 prescaler default |
#define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default |
#define TIMER2PRESCALE TIMERRTC_CLK_DIV64 ///< timer 2 prescaler default |
// interrupt macros for attaching user functions to timer interrupts |
// use these with timerAttach( intNum, function ) |
#define TIMER0OVERFLOW_INT 0 |
#define TIMER1OVERFLOW_INT 1 |
#define TIMER1OUTCOMPAREA_INT 2 |
#define TIMER1OUTCOMPAREB_INT 3 |
#define TIMER1INPUTCAPTURE_INT 4 |
#define TIMER2OVERFLOW_INT 5 |
#define TIMER2OUTCOMPARE_INT 6 |
#ifdef OCR0 // for processors that support output compare on Timer0 |
#define TIMER0OUTCOMPARE_INT 7 |
#define TIMER_NUM_INTERRUPTS 8 |
#else |
#define TIMER_NUM_INTERRUPTS 7 |
#endif |
// default type of interrupt handler to use for timers |
// *do not change unless you know what you're doing |
// Value may be SIGNAL or INTERRUPT |
#ifndef TIMER_INTERRUPT_HANDLER |
#define TIMER_INTERRUPT_HANDLER SIGNAL |
#endif |
// functions |
#define delay delay_us |
#define delay_ms timerPause |
void delay_us(unsigned short time_us); |
//! initializes timing system (all timers) |
// runs all timer init functions |
// sets all timers to default prescale values #defined in systimer.c |
void timerInit(void); |
// default initialization routines for each timer |
void timer0Init(void); ///< initialize timer0 |
void timer1Init(void); ///< initialize timer1 |
#ifdef TCNT2 // support timer2 only if it exists |
void timer2Init(void); ///< initialize timer2 |
#endif |
// Clock prescaler set/get commands for each timer/counter |
// For setting the prescaler, you should use one of the #defines |
// above like TIMER_CLK_DIVx, where [x] is the division rate |
// you want. |
// When getting the current prescaler setting, the return value |
// will be the [x] division value currently set. |
void timer0SetPrescaler(u08 prescale); ///< set timer0 prescaler |
u16 timer0GetPrescaler(void); ///< get timer0 prescaler |
void timer1SetPrescaler(u08 prescale); ///< set timer1 prescaler |
u16 timer1GetPrescaler(void); ///< get timer0 prescaler |
#ifdef TCNT2 // support timer2 only if it exists |
void timer2SetPrescaler(u08 prescale); ///< set timer2 prescaler |
u16 timer2GetPrescaler(void); ///< get timer2 prescaler |
#endif |
// TimerAttach and Detach commands |
// These functions allow the attachment (or detachment) of any user function |
// to a timer interrupt. "Attaching" one of your own functions to a timer |
// interrupt means that it will be called whenever that interrupt happens. |
// Using attach is better than rewriting the actual INTERRUPT() function |
// because your code will still work and be compatible if the timer library |
// is updated. Also, using Attach allows your code and any predefined timer |
// code to work together and at the same time. (ie. "attaching" your own |
// function to the timer0 overflow doesn't prevent timerPause from working, |
// but rather allows you to share the interrupt.) |
// |
// timerAttach(TIMER1OVERFLOW_INT, myOverflowFunction); |
// timerDetach(TIMER1OVERFLOW_INT) |
// |
// timerAttach causes the myOverflowFunction() to be attached, and therefore |
// execute, whenever an overflow on timer1 occurs. timerDetach removes the |
// association and executes no user function when the interrupt occurs. |
// myOverflowFunction must be defined with no return value and no arguments: |
// |
// void myOverflowFunction(void) { ... } |
//! Attach a user function to a timer interrupt |
void timerAttach(u08 interruptNum, void (*userFunc)(void) ); |
//! Detach a user function from a timer interrupt |
void timerDetach(u08 interruptNum); |
// timing commands |
/// A timer-based delay/pause function |
/// @param pause_ms Number of integer milliseconds to wait. |
void timerPause(unsigned short pause_ms); |
// overflow counters |
void timer0ClearOverflowCount(void); ///< Clear timer0's overflow counter. |
long timer0GetOverflowCount(void); ///< read timer0's overflow counter |
#ifdef TCNT2 // support timer2 only if it exists |
void timer2ClearOverflowCount(void); ///< clear timer2's overflow counter |
long timer2GetOverflowCount(void); ///< read timer0's overflow counter |
#endif |
/// @defgroup timerpwm Timer PWM Commands |
/// @ingroup timer |
/// These commands control PWM functionality on timer1 |
// PWM initialization and set commands for timer1 |
// timer1PWMInit() |
// configures the timer1 hardware for PWM mode on pins OC1A and OC1B. |
// bitRes should be 8,9,or 10 for 8,9,or 10bit PWM resolution |
// |
// timer1PWMOff() |
// turns off all timer1 PWM output and set timer mode to normal state |
// |
// timer1PWMAOn() and timer1PWMBOn() |
// turn on output of PWM signals to OC1A or OC1B pins |
// NOTE: Until you define the OC1A and OC1B pins as outputs, and run |
// this "on" command, no PWM output will be output |
// |
// timer1PWMAOff() and timer1PWMBOff() |
// turn off output of PWM signals to OC1A or OC1B pins |
// |
// timer1PWMASet() and timer1PWMBSet() |
// sets the PWM duty cycle for each channel |
// NOTE: <pwmDuty> should be in the range 0-255 for 8bit PWM |
// <pwmDuty> should be in the range 0-511 for 9bit PWM |
// <pwmDuty> should be in the range 0-1023 for 10bit PWM |
// NOTE: the PWM frequency can be controlled in increments by setting the |
// prescaler for timer1 |
//@{ |
/// Enter standard PWM Mode on timer1. |
/// \param bitRes indicates the period/resolution to use for PWM output in timer bits. |
/// Must be either 8, 9, or 10 bits corresponding to PWM periods of 256, 512, or 1024 timer tics. |
void timer1PWMInit(u08 bitRes); |
/// Enter PWM Mode on timer1 with a specific top-count value. |
/// \param topcount indicates the desired PWM period in timer tics. |
/// Can be a number between 1 and 65535 (16-bit). |
void timer1PWMInitICR(u16 topcount); |
/// Turn off all timer1 PWM output and set timer mode to normal. |
void timer1PWMOff(void); |
/// Turn on/off Timer1 PWM outputs. |
void timer1PWMAOn(void); ///< Turn on timer1 Channel A (OC1A) PWM output. |
void timer1PWMBOn(void); ///< Turn on timer1 Channel B (OC1B) PWM output. |
void timer1PWMAOff(void); ///< turn off timer1 Channel A (OC1A) PWM output |
void timer1PWMBOff(void); ///< turn off timer1 Channel B (OC1B) PWM output |
void timer1PWMASet(u16 pwmDuty); ///< set duty of timer1 Channel A (OC1A) PWM output |
void timer1PWMBSet(u16 pwmDuty); ///< set duty of timer1 Channel B (OC1B) PWM output |
//@} |
//@} |
// Pulse generation commands have been moved to the pulse.c library |
#endif |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/uart.c |
---|
0,0 → 1,283 |
/*! \file uart.c \brief UART driver with buffer support. */ |
// ***************************************************************************** |
// |
// File Name : 'uart.c' |
// Title : UART driver with buffer support |
// Author : Pascal Stang - Copyright (C) 2000-2002 |
// Created : 11/22/2000 |
// Revised : 06/09/2003 |
// Version : 1.3 |
// Target MCU : ATMEL AVR Series |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
// ***************************************************************************** |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include "buffer.h" |
#include "uart.h" |
// UART global variables |
// flag variables |
volatile u08 uartReadyTx; ///< uartReadyTx flag |
volatile u08 uartBufferedTx; ///< uartBufferedTx flag |
// receive and transmit buffers |
cBuffer uartRxBuffer; ///< uart receive buffer |
cBuffer uartTxBuffer; ///< uart transmit buffer |
unsigned short uartRxOverflow; ///< receive overflow counter |
#ifndef UART_BUFFERS_EXTERNAL_RAM |
// using internal ram, |
// automatically allocate space in ram for each buffer |
static char uartRxData[UART_RX_BUFFER_SIZE]; |
static char uartTxData[UART_TX_BUFFER_SIZE]; |
#endif |
typedef void (*voidFuncPtru08)(unsigned char); |
volatile static voidFuncPtru08 UartRxFunc; |
// enable and initialize the uart |
void uartInit(void) |
{ |
// initialize the buffers |
uartInitBuffers(); |
// initialize user receive handler |
UartRxFunc = 0; |
// enable RxD/TxD and interrupts |
outb(UCR, BV(RXCIE)|BV(TXCIE)|BV(RXEN)|BV(TXEN)); |
// set default baud rate |
uartSetBaudRate(UART_DEFAULT_BAUD_RATE); |
// initialize states |
uartReadyTx = TRUE; |
uartBufferedTx = FALSE; |
// clear overflow count |
uartRxOverflow = 0; |
// enable interrupts |
sei(); |
} |
// create and initialize the uart transmit and receive buffers |
void uartInitBuffers(void) |
{ |
#ifndef UART_BUFFERS_EXTERNAL_RAM |
// initialize the UART receive buffer |
bufferInit(&uartRxBuffer, uartRxData, UART_RX_BUFFER_SIZE); |
// initialize the UART transmit buffer |
bufferInit(&uartTxBuffer, uartTxData, UART_TX_BUFFER_SIZE); |
#else |
// initialize the UART receive buffer |
bufferInit(&uartRxBuffer, (u08*) UART_RX_BUFFER_ADDR, UART_RX_BUFFER_SIZE); |
// initialize the UART transmit buffer |
bufferInit(&uartTxBuffer, (u08*) UART_TX_BUFFER_ADDR, UART_TX_BUFFER_SIZE); |
#endif |
} |
// redirects received data to a user function |
void uartSetRxHandler(void (*rx_func)(unsigned char c)) |
{ |
// set the receive interrupt to run the supplied user function |
UartRxFunc = rx_func; |
} |
// set the uart baud rate |
void uartSetBaudRate(u32 baudrate) |
{ |
// calculate division factor for requested baud rate, and set it |
u16 bauddiv = ((F_CPU+(baudrate*8L))/(baudrate*16L)-1); |
outb(UBRRL, bauddiv); |
#ifdef UBRRH |
outb(UBRRH, bauddiv>>8); |
#endif |
} |
// returns the receive buffer structure |
cBuffer* uartGetRxBuffer(void) |
{ |
// return rx buffer pointer |
return &uartRxBuffer; |
} |
// returns the transmit buffer structure |
cBuffer* uartGetTxBuffer(void) |
{ |
// return tx buffer pointer |
return &uartTxBuffer; |
} |
// transmits a byte over the uart |
void uartSendByte(u08 txData) |
{ |
// wait for the transmitter to be ready |
while(!uartReadyTx); |
// send byte |
outb(UDR, txData); |
// set ready state to FALSE |
uartReadyTx = FALSE; |
} |
// gets a single byte from the uart receive buffer (getchar-style) |
int uartGetByte(void) |
{ |
u08 c; |
if(uartReceiveByte(&c)) |
return c; |
else |
return -1; |
} |
// gets a byte (if available) from the uart receive buffer |
u08 uartReceiveByte(u08* rxData) |
{ |
// make sure we have a receive buffer |
if(uartRxBuffer.size) |
{ |
// make sure we have data |
if(uartRxBuffer.datalength) |
{ |
// get byte from beginning of buffer |
*rxData = bufferGetFromFront(&uartRxBuffer); |
return TRUE; |
} |
else |
{ |
// no data |
return FALSE; |
} |
} |
else |
{ |
// no buffer |
return FALSE; |
} |
} |
// flush all data out of the receive buffer |
void uartFlushReceiveBuffer(void) |
{ |
// flush all data from receive buffer |
//bufferFlush(&uartRxBuffer); |
// same effect as above |
uartRxBuffer.datalength = 0; |
} |
// return true if uart receive buffer is empty |
u08 uartReceiveBufferIsEmpty(void) |
{ |
if(uartRxBuffer.datalength == 0) |
{ |
return TRUE; |
} |
else |
{ |
return FALSE; |
} |
} |
// add byte to end of uart Tx buffer |
u08 uartAddToTxBuffer(u08 data) |
{ |
// add data byte to the end of the tx buffer |
return bufferAddToEnd(&uartTxBuffer, data); |
} |
// start transmission of the current uart Tx buffer contents |
void uartSendTxBuffer(void) |
{ |
// turn on buffered transmit |
uartBufferedTx = TRUE; |
// send the first byte to get things going by interrupts |
uartSendByte(bufferGetFromFront(&uartTxBuffer)); |
} |
/* |
// transmit nBytes from buffer out the uart |
u08 uartSendBuffer(char *buffer, u16 nBytes) |
{ |
register u08 first; |
register u16 i; |
// check if there's space (and that we have any bytes to send at all) |
if((uartTxBuffer.datalength + nBytes < uartTxBuffer.size) && nBytes) |
{ |
// grab first character |
first = *buffer++; |
// copy user buffer to uart transmit buffer |
for(i = 0; i < nBytes-1; i++) |
{ |
// put data bytes at end of buffer |
bufferAddToEnd(&uartTxBuffer, *buffer++); |
} |
// send the first byte to get things going by interrupts |
uartBufferedTx = TRUE; |
uartSendByte(first); |
// return success |
return TRUE; |
} |
else |
{ |
// return failure |
return FALSE; |
} |
} |
*/ |
// UART Transmit Complete Interrupt Handler |
UART_INTERRUPT_HANDLER(SIG_UART_TRANS) |
{ |
// check if buffered tx is enabled |
if(uartBufferedTx) |
{ |
// check if there's data left in the buffer |
if(uartTxBuffer.datalength) |
{ |
// send byte from top of buffer |
outb(UDR, bufferGetFromFront(&uartTxBuffer)); |
} |
else |
{ |
// no data left |
uartBufferedTx = FALSE; |
// return to ready state |
uartReadyTx = TRUE; |
} |
} |
else |
{ |
// we're using single-byte tx mode |
// indicate transmit complete, back to ready |
uartReadyTx = TRUE; |
} |
} |
// UART Receive Complete Interrupt Handler |
UART_INTERRUPT_HANDLER(SIG_UART_RECV) |
{ |
u08 c; |
// get received char |
c = inb(UDR); |
// if there's a user function to handle this receive event |
if(UartRxFunc) |
{ |
// call it and pass the received data |
UartRxFunc(c); |
} |
else |
{ |
// otherwise do default processing |
// put received char in buffer |
// check if there's space |
if( !bufferAddToEnd(&uartRxBuffer, c) ) |
{ |
// no space in buffer |
// count overflow |
uartRxOverflow++; |
} |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/uart.h |
---|
0,0 → 1,232 |
/*! \file uart.h \brief UART driver with buffer support. */ |
//***************************************************************************** |
// |
// File Name : 'uart.h' |
// Title : UART driver with buffer support |
// Author : Pascal Stang - Copyright (C) 2000-2002 |
// Created : 11/22/2000 |
// Revised : 02/01/2004 |
// Version : 1.3 |
// Target MCU : ATMEL AVR Series |
// Editor Tabs : 4 |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
/// \ingroup driver_avr |
/// \defgroup uart UART Driver/Function Library (uart.c) |
/// \code #include "uart.h" \endcode |
/// \par Overview |
/// This library provides both buffered and unbuffered transmit and receive |
/// functions for the AVR processor UART. Buffered access means that the |
/// UART can transmit and receive data in the "background", while your code |
/// continues executing. Also included are functions to initialize the |
/// UART, set the baud rate, flush the buffers, and check buffer status. |
/// |
/// \note For full text output functionality, you may wish to use the rprintf |
/// functions along with this driver. |
/// |
/// \par About UART operations |
/// Most Atmel AVR-series processors contain one or more hardware UARTs |
/// (aka, serial ports). UART serial ports can communicate with other |
/// serial ports of the same type, like those used on PCs. In general, |
/// UARTs are used to communicate with devices that are RS-232 compatible |
/// (RS-232 is a certain kind of serial port). |
/// \par |
/// By far, the most common use for serial communications on AVR processors |
/// is for sending information and data to a PC running a terminal program. |
/// Here is an exmaple: |
/// \code |
/// uartInit(); // initialize UART (serial port) |
/// uartSetBaudRate(9600); // set UART speed to 9600 baud |
/// rprintfInit(uartSendByte); // configure rprintf to use UART for output |
/// rprintf("Hello World\r\n"); // send "hello world" message via serial port |
/// \endcode |
/// |
/// \warning The CPU frequency (F_CPU) must be set correctly in \c global.h |
/// for the UART library to calculate correct baud rates. Furthermore, |
/// certain CPU frequencies will not produce exact baud rates due to |
/// integer frequency division round-off. See your AVR processor's |
/// datasheet for full details. |
// |
//***************************************************************************** |
//@{ |
#ifndef UART_H |
#define UART_H |
#include "global.h" |
#include "buffer.h" |
//! Default uart baud rate. |
/// This is the default speed after a uartInit() command, |
/// and can be changed by using uartSetBaudRate(). |
#define UART_DEFAULT_BAUD_RATE 9600 |
// buffer memory allocation defines |
// buffer sizes |
#ifndef UART_TX_BUFFER_SIZE |
//! Number of bytes for uart transmit buffer. |
/// Do not change this value in uart.h, but rather override |
/// it with the desired value defined in your project's global.h |
#define UART_TX_BUFFER_SIZE 0x0040 |
#endif |
#ifndef UART_RX_BUFFER_SIZE |
//! Number of bytes for uart receive buffer. |
/// Do not change this value in uart.h, but rather override |
/// it with the desired value defined in your project's global.h |
#define UART_RX_BUFFER_SIZE 0x0040 |
#endif |
// define this key if you wish to use |
// external RAM for the UART buffers |
//#define UART_BUFFER_EXTERNAL_RAM |
#ifdef UART_BUFFER_EXTERNAL_RAM |
// absolute address of uart buffers |
#define UART_TX_BUFFER_ADDR 0x1000 |
#define UART_RX_BUFFER_ADDR 0x1100 |
#endif |
//! Type of interrupt handler to use for uart interrupts. |
/// Value may be SIGNAL or INTERRUPT. |
/// \warning Do not change unless you know what you're doing. |
#ifndef UART_INTERRUPT_HANDLER |
#define UART_INTERRUPT_HANDLER SIGNAL |
#endif |
// compatibility with most newer processors |
#ifdef UCSRB |
#define UCR UCSRB |
#endif |
// compatibility with old Mega processors |
#if defined(UBRR) && !defined(UBRRL) |
#define UBRRL UBRR |
#endif |
// compatibility with megaXX8 processors |
#if defined(__AVR_ATmega88__) || \ |
defined(__AVR_ATmega168__) || \ |
defined(__AVR_ATmega644__) |
#define UDR UDR0 |
#define UCR UCSR0B |
#define RXCIE RXCIE0 |
#define TXCIE TXCIE0 |
#define RXC RXC0 |
#define TXC TXC0 |
#define RXEN RXEN0 |
#define TXEN TXEN0 |
#define UBRRL UBRR0L |
#define UBRRH UBRR0H |
#define SIG_UART_TRANS SIG_USART_TRANS |
#define SIG_UART_RECV SIG_USART_RECV |
#define SIG_UART_DATA SIG_USART_DATA |
#endif |
// compatibility with mega169 processors |
#if defined(__AVR_ATmega169__) |
#define SIG_UART_TRANS SIG_USART_TRANS |
#define SIG_UART_RECV SIG_USART_RECV |
#define SIG_UART_DATA SIG_USART_DATA |
#endif |
// compatibility with dual-uart processors |
// (if you need to use both uarts, please use the uart2 library) |
#if defined(__AVR_ATmega161__) |
#define UDR UDR0 |
#define UCR UCSR0B |
#define UBRRL UBRR0 |
#define SIG_UART_TRANS SIG_UART0_TRANS |
#define SIG_UART_RECV SIG_UART0_RECV |
#define SIG_UART_DATA SIG_UART0_DATA |
#endif |
#if defined(__AVR_ATmega128__) |
#ifdef UART_USE_UART1 |
#define UDR UDR1 |
#define UCR UCSR1B |
#define UBRRL UBRR1L |
#define UBRRH UBRR1H |
#define SIG_UART_TRANS SIG_UART1_TRANS |
#define SIG_UART_RECV SIG_UART1_RECV |
#define SIG_UART_DATA SIG_UART1_DATA |
#else |
#define UDR UDR0 |
#define UCR UCSR0B |
#define UBRRL UBRR0L |
#define UBRRH UBRR0H |
#define SIG_UART_TRANS SIG_UART0_TRANS |
#define SIG_UART_RECV SIG_UART0_RECV |
#define SIG_UART_DATA SIG_UART0_DATA |
#endif |
#endif |
// functions |
//! Initializes uart. |
/// \note After running this init function, the processor |
/// I/O pins that used for uart communications (RXD, TXD) |
/// are no long available for general purpose I/O. |
void uartInit(void); |
//! Initializes transmit and receive buffers. |
/// Automatically called from uartInit() |
void uartInitBuffers(void); |
//! Redirects received data to a user function. |
/// |
void uartSetRxHandler(void (*rx_func)(unsigned char c)); |
//! Sets the uart baud rate. |
/// Argument should be in bits-per-second, like \c uartSetBaudRate(9600); |
void uartSetBaudRate(u32 baudrate); |
//! Returns pointer to the receive buffer structure. |
/// |
cBuffer* uartGetRxBuffer(void); |
//! Returns pointer to the transmit buffer structure. |
/// |
cBuffer* uartGetTxBuffer(void); |
//! Sends a single byte over the uart. |
/// \note This function waits for the uart to be ready, |
/// therefore, consecutive calls to uartSendByte() will |
/// go only as fast as the data can be sent over the |
/// serial port. |
void uartSendByte(u08 data); |
//! Gets a single byte from the uart receive buffer. |
/// Returns the byte, or -1 if no byte is available (getchar-style). |
int uartGetByte(void); |
//! Gets a single byte from the uart receive buffer. |
/// Function returns TRUE if data was available, FALSE if not. |
/// Actual data is returned in variable pointed to by "data". |
/// Example usage: |
/// \code |
/// char myReceivedByte; |
/// uartReceiveByte( &myReceivedByte ); |
/// \endcode |
u08 uartReceiveByte(u08* data); |
//! Returns TRUE/FALSE if receive buffer is empty/not-empty. |
/// |
u08 uartReceiveBufferIsEmpty(void); |
//! Flushes (deletes) all data from receive buffer. |
/// |
void uartFlushReceiveBuffer(void); |
//! Add byte to end of uart Tx buffer. |
/// Returns TRUE if successful, FALSE if failed (no room left in buffer). |
u08 uartAddToTxBuffer(u08 data); |
//! Begins transmission of the transmit buffer under interrupt control. |
/// |
void uartSendTxBuffer(void); |
//! Sends a block of data via the uart using interrupt control. |
/// \param buffer pointer to data to be sent |
/// \param nBytes length of data (number of bytes to sent) |
u08 uartSendBuffer(char *buffer, u16 nBytes); |
#endif |
//@} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/vt100.c |
---|
0,0 → 1,69 |
/*! \file vt100.c \brief VT100 terminal function library. */ |
//***************************************************************************** |
// |
// File Name : 'vt100.c' |
// Title : VT100 terminal function library |
// Author : Pascal Stang - Copyright (C) 2002 |
// Created : 2002.08.27 |
// Revised : 2002.08.27 |
// Version : 0.1 |
// Target MCU : Atmel AVR Series |
// Editor Tabs : 4 |
// |
// NOTE: This code is currently below version 1.0, and therefore is considered |
// to be lacking in some functionality or documentation, or may not be fully |
// tested. Nonetheless, you can expect most functions to work. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include "global.h" |
#include "rprintf.h" |
#include "vt100.h" |
// Program ROM constants |
// Global variables |
// Functions |
void vt100Init(void) |
{ |
// initializes terminal to "power-on" settings |
// ESC c |
rprintfProgStrM("\x1B\x63"); |
} |
void vt100ClearScreen(void) |
{ |
// ESC [ 2 J |
rprintfProgStrM("\x1B[2J"); |
} |
void vt100SetAttr(u08 attr) |
{ |
// ESC [ Ps m |
rprintf("\x1B[%dm",attr); |
} |
void vt100SetCursorMode(u08 visible) |
{ |
if(visible) |
// ESC [ ? 25 h |
rprintf("\x1B[?25h"); |
else |
// ESC [ ? 25 l |
rprintf("\x1B[?25l"); |
} |
void vt100SetCursorPos(u08 line, u08 col) |
{ |
// ESC [ Pl ; Pc H |
rprintf("\x1B[%d;%dH",line,col); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/GPSRL02A/SW/buffer/vt100.h |
---|
0,0 → 1,72 |
/*! \file vt100.h \brief VT100 terminal function library. */ |
//***************************************************************************** |
// |
// File Name : 'vt100.h' |
// Title : VT100 terminal function library |
// Author : Pascal Stang - Copyright (C) 2002 |
// Created : 2002.08.27 |
// Revised : 2002.08.27 |
// Version : 0.1 |
// Target MCU : Atmel AVR Series |
// Editor Tabs : 4 |
// |
// NOTE: This code is currently below version 1.0, and therefore is considered |
// to be lacking in some functionality or documentation, or may not be fully |
// tested. Nonetheless, you can expect most functions to work. |
// |
/// \ingroup general |
/// \defgroup vt100 VT100 Terminal Function Library (vt100.c) |
/// \code #include "vt100.h" \endcode |
/// \par Overview |
/// This library provides functions for sending VT100 escape codes to |
/// control a connected VT100 or ANSI terminal. Commonly useful functions |
/// include setting the cursor position, clearing the screen, setting the text |
/// attributes (bold, inverse, blink, etc), and setting the text color. This |
/// library will slowly be expanded to include support for codes as needed and |
/// may eventually receive VT100 escape codes too. |
// |
// This code is distributed under the GNU Public License |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
// |
//***************************************************************************** |
#ifndef VT100_H |
#define VT100_H |
#include "global.h" |
// constants/macros/typdefs |
// text attributes |
#define VT100_ATTR_OFF 0 |
#define VT100_BOLD 1 |
#define VT100_USCORE 4 |
#define VT100_BLINK 5 |
#define VT100_REVERSE 7 |
#define VT100_BOLD_OFF 21 |
#define VT100_USCORE_OFF 24 |
#define VT100_BLINK_OFF 25 |
#define VT100_REVERSE_OFF 27 |
// functions |
//! vt100Init() initializes terminal and vt100 library |
/// Run this init routine once before using any other vt100 function. |
void vt100Init(void); |
//! vt100ClearScreen() clears the terminal screen |
void vt100ClearScreen(void); |
//! vt100SetAttr() sets the text attributes like BOLD or REVERSE |
/// Text written to the terminal after this function is called will have |
/// the desired attribuutes. |
void vt100SetAttr(u08 attr); |
//! vt100SetCursorMode() sets the cursor to visible or invisible |
void vt100SetCursorMode(u08 visible); |
//! vt100SetCursorPos() sets the cursor position |
/// All text which is written to the terminal after a SetCursorPos command |
/// will begin at the new location of the cursor. |
void vt100SetCursorPos(u08 line, u08 col); |
#endif |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |