Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 273 → Rev 274

/bots/Pulse-Stretcher/Uart.h
0,0 → 1,23
/****************************************************************************
*
* uart.h
*
* Code for abstracting the UART interface (uses polled I/O)
*
****************************************************************************/
 
#if !defined( UART_H )
#define UART_H
 
#if !defined( TYPES_H )
# include "Types.h"
#endif
 
void UART_Init( void );
uns8 UART_GetChar( void );
void UART_PutChar( uns8 ch );
void UART_PutStr( const char *str );
int UART_IsCharAvailable( void );
int UART_IsTxBufferEmpty( void );
 
#endif // UART_H
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Hardware.h
===================================================================
--- Pulse-Stretcher/Hardware.h (nonexistent)
+++ Pulse-Stretcher/Hardware.h (revision 274)
@@ -0,0 +1,120 @@
+/****************************************************************************
+*
+* Hardware.h
+*
+* This header file contains all of the hardware definitions for the chip.
+* By centralizing everything in one header file, it allows us to keep
+* track of what's being used by whom.
+*
+****************************************************************************/
+
+#if !defined( HARDWARE_H )
+#define HARDWARE_H
+
+#define ENABLE_BIT_DEFINITIONS
+#include <avr/io.h>
+
+#define CPU_CLOCK 16000000
+
+//--------------------------------------------------------------------------
+// MCUCR - Control Register
+//
+// Bit 7 SE Sleep Enable
+// Bit 4-6 SM0-2 Sleep Mode
+// Bit 2,3 ISC10,1 Interrupt 1 Sense Control
+// Bit 0,1 ISC00,1 Interrupt 0 Sense Control
+//
+
+#define MCUCR_IRQ0_RISING_EDGE ( BV( ISC01 ) | BV( ISC00 ))
+#define MCUCR_IRQ1_RISING_EDGE ( BV( ISC11 ) | BV( ISC10 ))
+
+#define MCUCR_INIT ( MCUCR_IRQ0_RISING_EDGE | MCUCR_IRQ1_RISING_EDGE )
+
+//--------------------------------------------------------------------------
+// GICR - Global Interrupt Control Register
+
+#define GICR_INIT ( BV( INT1 ) | BV( INT0 ))
+
+//--------------------------------------------------------------------------
+// Timer/Counter 2
+//
+// We run Timer 2 in free running mode, 8us/tick
+
+#define TCCR2_CLK_DIV_128 ( BV( CS22 ) | BV( CS20 ))
+
+#define TCCR2_INIT TCCR2_CLK_DIV_128
+
+//--------------------------------------------------------------------------
+// UART settings
+
+#define BAUD_RATE 38400
+
+#define DATA_BIT_8 ( 1 << UCSZ1 ) | ( 1 << UCSZ0 )
+#define PARITY_NONE ( 0 << UPM1 ) | ( 0 << UPM0 )
+#define STOP_BIT_1 ( 1 << USBS )
+
+#define UBRR_INIT (( CPU_CLOCK / 16 / BAUD_RATE ) - 1 )
+#define UCSRA_INIT 0
+#define UCSRB_INIT ( 1 << RXEN ) | ( 1 << TXEN )
+#define UCSRC_INIT ( 1 << URSEL ) | DATA_BIT_8 | PARITY_NONE | STOP_BIT_1
+
+//--------------------------------------------------------------------------
+// Port B
+
+enum
+{
+ MotorA_Dir = 0, //
+ MotorA_PWM = 1, //
+
+ MotorB_PWM = 2, //
+ MotorB_Dir = 5, //
+
+ GreenLEDPin = 3, // out
+ BlueLEDPin = 4, // out
+
+ // 6 & 7 are used for the 16 MHz Oscillator
+};
+
+#define DDRB_INIT ( BV( BlueLEDPin ) | BV( GreenLEDPin ) )
+#define PORTB_INIT 0
+
+//--------------------------------------------------------------------------
+// Port C - ADC Channels are just numbers (passed to a2d)
+
+enum
+{
+ ADC_0 = 0,
+
+// EyeL = 6,
+// EyeR = 7,
+
+
+};
+
+#define DDRC_INIT 0
+#define PORTC_INIT 0
+
+//--------------------------------------------------------------------------
+// Port D
+
+enum
+{
+ UartRxD = 0, // in RXD - no pullup
+ UartTxD = 1, // out TXD
+
+ RC_Pulse_In_0 = 2, // in INT0 - pullup enabled
+ RC_Pulse_In_1 = 3, // in INT1 - pullup enabled
+};
+
+#define DDRD_INIT ( BV( UartTxD ) )
+#define PORTD_INIT ( BV( RC_Pulse_In_0 ) | BV( RC_Pulse_In_1 ) )
+
+//--------------------------------------------------------------------------
+
+extern inline void BeginCritical(void) { asm volatile("cli\n"); }
+extern inline void EndCritical(void) { asm volatile("sei\n"); }
+
+void InitHardware( void );
+
+#endif // HARDWARE_H
+
/Pulse-Stretcher/Hardware.h
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/RCPulse.h
===================================================================
--- Pulse-Stretcher/RCPulse.h (nonexistent)
+++ Pulse-Stretcher/RCPulse.h (revision 274)
@@ -0,0 +1,31 @@
+/****************************************************************************
+*
+* RCPulse.h
+*
+****************************************************************************/
+
+#if !defined( RCPULSE_H )
+#define RCPULSE_H
+
+#if !defined( TYPES_H )
+# include "Types.h"
+#endif
+
+typedef struct
+{
+ // The order/size of the first 3 fields MUST NOT BE CHANGED without
+ // a corresponding change in RCPulseIrq.S
+
+ uns8 start;
+ uns8 end;
+ uns8 done;
+
+ uns8 width;
+
+} RCPulse;
+
+extern RCPulse RC0;
+extern RCPulse RC1;
+
+#endif // RCPULSE_H
+
/Pulse-Stretcher/RCPulse.h
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/x.c
===================================================================
--- Pulse-Stretcher/x.c (nonexistent)
+++ Pulse-Stretcher/x.c (revision 274)
@@ -0,0 +1,6 @@
+extern int RC0;
+
+int foo( void )
+{
+ return RC0;
+}
/Pulse-Stretcher/x.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/LED.h
===================================================================
--- Pulse-Stretcher/LED.h (nonexistent)
+++ Pulse-Stretcher/LED.h (revision 274)
@@ -0,0 +1,44 @@
+/****************************************************************************
+*
+* LED.h
+*
+*
+****************************************************************************/
+
+#if !defined( LED_H )
+#define LED_H
+
+#if !defined( HARDWARE_H )
+# include "Hardware.h"
+#endif
+
+static inline void InitLED()
+{
+ DDRB |= ( BV( BlueLEDPin ) | BV( GreenLEDPin ));
+}
+
+static inline void BlueLED( int onOff )
+{
+ if ( onOff )
+ {
+ PORTB |= BV( BlueLEDPin );
+ }
+ else
+ {
+ PORTB &= ~BV( BlueLEDPin );
+ }
+}
+
+static inline void GreenLED( int onOff )
+{
+ if ( onOff )
+ {
+ PORTB |= BV( GreenLEDPin );
+ }
+ else
+ {
+ PORTB &= ~BV( GreenLEDPin );
+ }
+}
+
+#endif // LED_H
/Pulse-Stretcher/LED.h
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Pulse-Stretcher.c
===================================================================
--- Pulse-Stretcher/Pulse-Stretcher.c (nonexistent)
+++ Pulse-Stretcher/Pulse-Stretcher.c (revision 274)
@@ -0,0 +1,285 @@
+/****************************************************************************
+*
+* Pulse-Stretcher.c
+*
+* Code for stretching out an RC pulse
+*
+****************************************************************************/
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#include "Debug.h"
+#include "Hardware.h"
+#include "LED.h"
+#include "RCPulse.h"
+#include "Uart.h"
+
+#include <stdlib.h>
+
+typedef struct
+{
+ uns8 start;
+ uns8 mid;
+ uns8 end;
+} SetPoint;
+
+// 0 - Channel 1 Input
+// 1 - Channel 2 Input
+// 3 - Channel 1 Output
+// 4 - Channel 2 Output
+
+SetPoint gSetPoint[ 4 ] =
+{
+ {
+ 123, // 0.984 msec - Forward
+ 181, // 1.448 msec
+ 207, // 1.656 msec - Reverse
+ },
+
+ {
+ 149, // 1.192 msec - Left
+ 191, // 1.528 msec - Straight
+ 237, // 1.896 msec - Right
+ },
+
+ {
+ 125, // 1.000 msec
+ 187, // 1.496 msec
+ 250, // 2.000 msec
+ },
+
+ {
+ 125, // 1.000 msec
+ 187, // 1.496 msec
+ 250, // 2.000 msec
+ },
+};
+
+char gMsg[ 80 ];
+char *gMsgGet = gMsg;
+char *gMsgPut = gMsg;
+
+/***************************************************************************/
+/**
+* Format a number of 8us ticks into a string
+*/
+
+void FormatRCTicks( uns8 ticks, char **strPtr )
+{
+ uns16 usecs = ticks;
+ usecs *= 8;
+ char *digitStr = "0123456789";
+ char *s = *strPtr;
+
+ uns8 digit;
+
+ digit = 0;
+ while ( usecs >= 1000 )
+ {
+ digit++;
+ usecs -= 1000;
+ }
+ *s++ = digitStr[ digit ];
+ *s++ = '.';
+
+ digit = 0;
+ while ( usecs >= 100 )
+ {
+ digit++;
+ usecs -= 100;
+ }
+ *s++ = digitStr[ digit ];
+
+ digit = 0;
+ while ( usecs >= 10 )
+ {
+ digit++;
+ usecs -= 10;
+ }
+ *s++ = digitStr[ digit ];
+ *s++ = digitStr[ usecs ];
+ *s = '\0';
+
+ *strPtr = s;
+
+} // FormatRCTicks
+
+/***************************************************************************/
+/**
+* Format a string into a string
+*/
+
+void FormatStr( const char *inStr, char **strPtr )
+{
+ char *s = *strPtr;
+
+ while ( *inStr != '\0' )
+ {
+ *s++ = *inStr++;
+ }
+ *s = '\0';
+
+ *strPtr = s;
+
+} // FormatStr
+
+/***************************************************************************/
+/**
+* Maps an input channel to an output channel
+*/
+
+uns8 MapPulse( uns8 pulse, SetPoint *in, SetPoint *out )
+{
+ int16 inPulse;
+ int16 outPulse;
+ int16 inWidth;
+ int16 outWidth;
+
+ if ( pulse < in->mid )
+ {
+ // out->mid - ( in->mid - pulse ) / ( in->mid - in->start ) * ( out->mid - out->start )
+
+ inWidth = (int16)in->mid - (int16)in->start;
+ outWidth = (int16)out->mid - (int16)out->start;
+ inPulse = (int16)in->mid - (int16)pulse;
+
+ outPulse = (int16)out->mid - (( inPulse * outWidth ) / inWidth );
+ }
+ else
+ {
+ // out->mid + ( pulse - in->mid ) / ( in->end - in->mid ) * ( out->end - out->mid )
+
+ inWidth = (int16)in->end - (int16)in->mid;
+ outWidth = (int16)out->end - (int16)out->mid;
+ inPulse = (int16)pulse - (int16)in->mid;
+
+ outPulse = (int16)out->mid + (( inPulse * outWidth ) / inWidth );
+ }
+
+ return outPulse;
+
+} // MapPulse
+
+/***************************************************************************/
+/**
+* Generates a pulse of the indicated width on the indicated pin
+*/
+
+void GeneratePulse( uns8 width, int pin )
+{
+ // Wait for the timer/counter to roll over
+
+ while ( TCNT2 != 0xFF )
+ {
+ ;
+ }
+
+ // Wait for the 0xFF --> 0x00 rollover
+
+ while ( TCNT2 != 0 )
+ {
+ ;
+ }
+
+ PORTD |= BV( pin );
+
+ // Now wait for the width of the pulse
+
+ while ( TCNT2 < width )
+ {
+ ;
+ }
+
+ PORTD &= ~BV( pin );
+
+} // GeneratePulse
+
+
+// Throttle (Channel 0)
+// Off: 1.448
+// Full: 0.984
+// Rev: 1.656
+//
+// Steering (Channel 1)
+// Left: 1.192
+// Straight: 1.528
+// Right: 1.896
+
+/***************************************************************************/
+/**
+* Main program for the Mini Sumo
+*/
+
+int main( void )
+{
+ int pulseCount = 0;
+
+ // Initialization
+
+ InitHardware();
+
+ BlueLED( 1 );
+
+#if DEBUG
+ UART_PutStr( "\r\n\r\n" );
+ UART_PutStr( "*****************************\r\n" );
+ UART_PutStr( "** **\r\n" );
+ UART_PutStr( "** Pulse Stretcher Program **\r\n" );
+ UART_PutStr( "** **\r\n" );
+ UART_PutStr( "*****************************\r\n\r\n" );
+#endif
+
+ sei(); // Enable interrupts
+
+ while ( 1 )
+ {
+ if ( RC0.done && RC1.done )
+ {
+ BeginCritical();
+ {
+ RC0.width = RC0.end - RC0.start;
+ RC1.width = RC1.end - RC1.start;
+
+ RC0.done = FALSE;
+ RC1.done = FALSE;
+ }
+ EndCritical();
+
+ pulseCount++;
+
+ GeneratePulse( MapPulse( RC0.width, &gSetPoint[ 0 ], &gSetPoint[ 2 ]), 5 );
+ GeneratePulse( MapPulse( RC1.width, &gSetPoint[ 1 ], &gSetPoint[ 3 ]), 6 );
+ }
+
+ if ( gMsgGet == gMsgPut )
+ {
+ gMsgGet = gMsg;
+ gMsgPut = gMsg;
+
+ FormatStr( "\r0: ", &gMsgPut );
+ FormatRCTicks( RC0.width, &gMsgPut );
+ FormatStr( "ms 1: ", &gMsgPut );
+ FormatRCTicks( RC1.width, &gMsgPut );
+ FormatStr( "ms", &gMsgPut );
+
+ pulseCount = 0;
+ }
+ else
+ {
+ if ( pulseCount > 10 )
+ {
+ if ( UART_IsTxBufferEmpty() )
+ {
+ UART_PutChar( *gMsgGet++ );
+ }
+ }
+ }
+ }
+
+ return 0;
+
+} // main
+
+/** @} */
+
/Pulse-Stretcher/Pulse-Stretcher.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/RCPulseIrq.S
===================================================================
--- Pulse-Stretcher/RCPulseIrq.S (nonexistent)
+++ Pulse-Stretcher/RCPulseIrq.S (revision 274)
@@ -0,0 +1,92 @@
+;
+; RCpulse.s
+;
+; This file was taken from the OSMC project for the MOB board.
+;
+; STACK: 4
+; INTERRUPT Latency: ~16 cycles
+;
+; Assembly code for the RC pulse measuring interrupts. These run
+; outside of AvrX and are carefully coded to use the minimum stack
+; space and minimum interrupt latency. Each can interrupt the other.
+;
+; The GCC coded versions are about twice as slow and use about twice
+; as much stack (v3.0). This is an issue since each task stack needs
+; to have enough room to accomodate any usage by these routines.
+;
+
+#include <avr/io.h>
+
+;
+; Offsets into the RC data structure (RCPulse.h)
+;
+
+ .global RC0
+ .global RC1
+
+#define RC_START 0 // These are all bytes in the struct.
+#define RC_END 1
+#define RC_DONE 2
+
+
+ .global SIG_INTERRUPT0
+ .func SIG_INTERRUPT0
+SIG_INTERRUPT0:
+ push R16
+ in R16, _SFR_IO_ADDR( SREG ) ; Stash context
+ push R16
+
+ in R16, _SFR_IO_ADDR( MCUCR ) ; Determine rising/falling edge
+ sbrs R16, ISC00
+ rjmp 1f
+
+ cbr R16, BV( ISC00 ) ; Rising, switch to fall
+ out _SFR_IO_ADDR( MCUCR ), R16
+ in R16, _SFR_IO_ADDR( TCNT2 )
+ sts RC0+RC_START, R16 ; Stash the start time.
+ rjmp 2f
+1:
+ sbr R16, BV(ISC00) ; Falling, switch to rising
+ out _SFR_IO_ADDR( MCUCR ), R16
+ in R16, _SFR_IO_ADDR( TCNT2 )
+ sts RC0+RC_END, R16 ; Stash the end time
+ ldi R16, 1
+ sts RC0+RC_DONE, R16
+2:
+ pop R16 ; Restore context
+ out _SFR_IO_ADDR( SREG ), R16
+ pop R16
+ reti
+ .endfunc
+
+ .global SIG_INTERRUPT1
+ .func SIG_INTERRUPT1
+SIG_INTERRUPT1:
+ push R16
+ in R16, _SFR_IO_ADDR( SREG )
+ push R16
+
+ in R16, _SFR_IO_ADDR( MCUCR )
+ sbrs R16, ISC10
+ rjmp 1f
+
+ cbr R16, BV(ISC10)
+ out _SFR_IO_ADDR( MCUCR ), R16
+ in R16, _SFR_IO_ADDR( TCNT2 )
+ sts RC1+RC_START, R16
+ rjmp 2f
+1:
+ sbr R16, BV(ISC10)
+ out _SFR_IO_ADDR( MCUCR ), R16
+ in R16, _SFR_IO_ADDR( TCNT2 )
+ sts RC1+RC_END, R16
+ ldi R16, 1
+ sts RC1+RC_DONE, R16
+2:
+ pop R16
+ out _SFR_IO_ADDR( SREG ), R16
+ pop R16
+ reti
+ .endfunc
+
+
/Pulse-Stretcher/RCPulseIrq.S
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Types.h
===================================================================
--- Pulse-Stretcher/Types.h (nonexistent)
+++ Pulse-Stretcher/Types.h (revision 274)
@@ -0,0 +1,28 @@
+/****************************************************************************
+*
+* Types.h
+*
+****************************************************************************/
+
+#if !defined( TYPES_H )
+#define TYPES_H
+
+#if !defined( __INTTYPES_H_ )
+#include <inttypes.h>
+#endif
+
+typedef int8_t int8;
+typedef int16_t int16;
+typedef int32_t int32;
+
+typedef uint8_t uns8;
+typedef uint16_t uns16;
+typedef uint32_t uns32;
+
+#define TRUE 1
+#define FALSE 0
+
+#define ClearBits( val, bits ) ( (val) &= ~(bits) )
+#define SetBits( val, bits ) ( (val) |= (bits) )
+
+#endif // TYPES_H
/Pulse-Stretcher/Types.h
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Config.h
===================================================================
--- Pulse-Stretcher/Config.h (nonexistent)
+++ Pulse-Stretcher/Config.h (revision 274)
@@ -0,0 +1,16 @@
+/****************************************************************************
+*
+* Config.h
+*
+* Contains configuration information.
+*
+****************************************************************************/
+
+#if !defined( CONFIG_H )
+#define CONFIG_H
+
+#define CFG_CPU_CLOCK 16000000
+
+#endif // CONFIG_H
+
+
/Pulse-Stretcher/Config.h
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Debug.h
===================================================================
--- Pulse-Stretcher/Debug.h (nonexistent)
+++ Pulse-Stretcher/Debug.h (revision 274)
@@ -0,0 +1,23 @@
+/****************************************************************************
+*
+* Debug.h
+*
+* Debug control
+*
+****************************************************************************/
+
+#if !defined( DEBUG_H )
+#define DEBUG_H
+
+#if !defined( DEBUG )
+#define DEBUG 1
+#endif
+
+#if DEBUG
+# define DBG(x) x
+#else
+# define DBG(x)
+#endif
+
+#endif // DEBUG_H
+
/Pulse-Stretcher/Debug.h
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Uart.c
===================================================================
--- Pulse-Stretcher/Uart.c (nonexistent)
+++ Pulse-Stretcher/Uart.c (revision 274)
@@ -0,0 +1,91 @@
+/****************************************************************************
+*
+* uart.c
+*
+* Code for abstracting the UART interface (uses polled I/O)
+*
+****************************************************************************/
+
+#include "Uart.h"
+#include <avr/io.h>
+
+/***************************************************************************/
+/**
+* Reads a character from the UART (waits until a character is available)
+*/
+
+uns8 UART_GetChar( void )
+{
+ // Wait until chcracter is available
+
+ while ( !UART_IsCharAvailable() )
+ {
+ ;
+ }
+
+ // Read it and return it
+
+ return UDR;
+
+} // UART_GetChar
+
+/***************************************************************************/
+/**
+* Writes a character to the UART
+*/
+
+void UART_PutChar( uns8 ch )
+{
+ // Wait for empty transmit buffer
+
+ while ( !UART_IsTxBufferEmpty() )
+ {
+ ;
+ }
+
+ // Send the character
+
+ UDR = ch;
+
+} // UART_PutChar
+
+/***************************************************************************/
+/**
+* Writes a string to the uart.
+*/
+
+void UART_PutStr( const char *str )
+{
+ while ( *str != '\0' )
+ {
+ UART_PutChar( *str );
+
+ str++;
+ }
+
+} // UART_PutStr
+
+/***************************************************************************/
+/**
+* Determines if a character is available in the receive buffer.
+*/
+
+int UART_IsCharAvailable( void )
+{
+ return ( UCSRA & ( 1 << RXC )) != 0;
+
+} // UART_IsCharAvailable
+
+/***************************************************************************/
+/**
+* Determines if a character is available in the receive buffer.
+*/
+
+int UART_IsTxBufferEmpty( void )
+{
+ // Wait for empty transmit buffer
+
+ return (( UCSRA & ( 1 << UDRE )) != 0 );
+
+} // UART_IsTxBufferEmpty
+
/Pulse-Stretcher/Uart.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/irq.c
===================================================================
--- Pulse-Stretcher/irq.c (nonexistent)
+++ Pulse-Stretcher/irq.c (revision 274)
@@ -0,0 +1,6 @@
+#include <avr/signal.h>
+
+SIGNAL(SIG_INTERRUPT0)
+{
+
+}
/Pulse-Stretcher/irq.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Makefile
===================================================================
--- Pulse-Stretcher/Makefile (nonexistent)
+++ Pulse-Stretcher/Makefile (revision 274)
@@ -0,0 +1,152 @@
+MCU_TARGET = atmega8
+MCU_PROG_TARGET = m8
+OPTIMIZE = -O2
+
+DEFS =
+LIBS =
+OBJ_DIR = obj
+
+# You should not have to change anything below here.
+
+CC = avr-gcc
+AS = avr-gcc
+
+# Override is only needed by avr-lib build system.
+
+override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
+override ASFLAGS = -g -Wall -mmcu=$(MCU_TARGET) $(DEFS)
+override LDFLAGS = -Wl,-Map,Pulse-Stretcher.map
+
+OBJCOPY = avr-objcopy
+OBJDUMP = avr-objdump
+PROGRAMMER = avrdude
+
+PROGRAMMER_OPTS = -p $(MCU_PROG_TARGET) -c avrisp -P COM1
+
+.PHONY: Pulse-Stretcher
+
+ASM_FILES = RCPulseIrq.S
+
+SRC_FILES = \
+ Hardware.c \
+ Pulse-Stretcher.c \
+ RCPulse.c \
+ Uart.c
+
+DEP_FILES = $(addprefix $(OBJ_DIR)/,$(SRC_FILES:.c=.d))
+OBJ_FILES = $(addprefix $(OBJ_DIR)/,$(SRC_FILES:.c=.o)) $(addprefix $(OBJ_DIR)/,$(ASM_FILES:.S=.o))
+
+all: Pulse-Stretcher
+
+xxx:
+ echo OBJ_FILES = '$(OBJ_FILES)'
+
+Pulse-Stretcher: Pulse-Stretcher.hex
+
+$(OBJ_DIR)/Pulse-Stretcher.elf : $(OBJ_FILES)
+
+FORCE:
+
+clean:
+ rm -rf $(OBJ_DIR)/*
+ rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
+
+d download: Pulse-Stretcher.dld
+
+$(OBJ_DIR)/%.elf :
+ @echo "Linking $@ ..."
+ @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+%.dld : %.hex
+ $(PROGRAMMER) $(PROGRAMMER_OPTS) -e -U flash:w:$<
+
+%.cod: %.c FORCE
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -g -Wa,-ahdl=$@ -o $(@:.cod=.o) $<
+
+%.pp: %.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -E -Wp,-dN,-C -o $@ $<
+
+$(OBJ_DIR)/%.o: %.c
+ @echo "Compiling $< ..."
+ @$(COMPILE.c) $(OUTPUT_OPTION) $<
+
+$(OBJ_DIR)/%.o: %.S
+ @echo "Assembling $< ..."
+ $(COMPILE.S) $(OUTPUT_OPTION) $<
+
+
+lst: $(PRG).lst
+
+%.lst: %.elf
+ $(OBJDUMP) -h -S $< > $@
+
+# Rules for building the .text rom images
+
+text: hex bin srec
+
+hex: $(PRG).hex
+bin: $(PRG).bin
+srec: $(PRG).srec
+
+%.hex: $(OBJ_DIR)/%.elf
+ @echo Creating $@ ...
+ @$(OBJCOPY) -j .text -j .data -O ihex $< $@
+
+%.srec: $(OBJ_DIR)/%.elf
+ $(OBJCOPY) -j .text -j .data -O srec $< $@
+
+%.bin: $(OBJ_DIR)/%.elf
+ $(OBJCOPY) -j .text -j .data -O binary $< $@
+
+# Rules for building the .eeprom rom images
+
+eeprom: ehex ebin esrec
+
+ehex: $(PRG)_eeprom.hex
+ebin: $(PRG)_eeprom.bin
+esrec: $(PRG)_eeprom.srec
+
+%_eeprom.hex: $(OBJ_DIR)/%.elf
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
+
+%_eeprom.srec: $(OBJ_DIR)/%.elf
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
+
+%_eeprom.bin: $(OBJ_DIR)/%.elf
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
+
+# Every thing below here is used by avr-libc's build system and can be ignored
+# by the casual user.
+
+FIG2DEV = fig2dev
+EXTRA_CLEAN_FILES = *.hex *.bin *.srec
+
+dox: eps png pdf
+
+eps: $(PRG).eps
+png: $(PRG).png
+pdf: $(PRG).pdf
+
+%.eps: %.fig
+ $(FIG2DEV) -L eps $< $@
+
+%.pdf: %.fig
+ $(FIG2DEV) -L pdf $< $@
+
+%.png: %.fig
+ $(FIG2DEV) -L png $< $@
+
+#
+# Dependency file generation
+#
+
+$(OBJ_DIR)/%.d : %.c
+ @echo "Creating Dependency file for $< ..."
+ @set -e; avr-cpp -M $< | sed 's=$(*F).o[ :]*=$(@:.d=.o) $@ : =g' > $@; [ -s $@ ] || ( rm -f $@; exit 1 )
+
+ifneq ($(DEP_FILES),)
+ifeq ($(strip $(filter clean% exec print-%, $(MAKECMDGOALS))),)
+-include $(DEP_FILES)
+endif
+endif
+
/Pulse-Stretcher/Makefile
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/Hardware.c
===================================================================
--- Pulse-Stretcher/Hardware.c (nonexistent)
+++ Pulse-Stretcher/Hardware.c (revision 274)
@@ -0,0 +1,40 @@
+/****************************************************************************
+*
+* Hardware.c
+*
+* This header file contains all of the hardware definitions for the chip.
+* By centralizing everything in one header file, it allows us to keep
+* track of what's being used by whom.
+*
+****************************************************************************/
+
+#include "Hardware.h"
+
+void InitHardware( void )
+{
+ MCUCR = MCUCR_INIT;
+ TCCR2 = TCCR2_INIT;
+ GICR = GICR_INIT;
+
+ // Initialize the Ports
+
+ DDRB = DDRB_INIT;
+ PORTB = PORTB_INIT;
+
+ DDRC = DDRC_INIT;
+ PORTC = PORTC_INIT;
+
+ DDRD = DDRD_INIT;
+ PORTD = PORTD_INIT;
+
+ // Initialize the UART
+
+ UBRRH = UBRR_INIT >> 8;
+ UBRRL = UBRR_INIT & 0xFF;
+
+ UCSRA = UCSRA_INIT;
+ UCSRB = UCSRB_INIT;
+ UCSRC = UCSRC_INIT;
+
+
+} // InitHardware
/Pulse-Stretcher/Hardware.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Pulse-Stretcher/RCPulse.c
===================================================================
--- Pulse-Stretcher/RCPulse.c (nonexistent)
+++ Pulse-Stretcher/RCPulse.c (revision 274)
@@ -0,0 +1,12 @@
+/****************************************************************************
+*
+* RCPulse.c
+*
+****************************************************************************/
+
+#include "RCPulse.h"
+
+// The following globals are referenced by the interrupt handler.
+
+RCPulse RC0;
+RCPulse RC1;
/Pulse-Stretcher/RCPulse.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property