From 261fc325f87a09610a6c827ab796db327aa1f7d0 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Fri, 5 Jun 2009 19:59:55 +0000 Subject: [PATCH] initial import --- uc/Makefile | 289 +++++++++++++++++++++ uc/calibration.pde | 182 +++++++++++++ uc/calibration.pde.c | 1 + uc/main.1mhz.c | 276 ++++++++++++++++++++ uc/main.1mhz.h | 53 ++++ uc/main.cxx | 14 + uc/main.pde | 1 + uc/wiring/binary.h | 515 +++++++++++++++++++++++++++++++++++++ uc/wiring/serial.c | 212 +++++++++++++++ uc/wiring/wiring.h | 121 +++++++++ uc/wiring/wiring_private.h | 58 +++++ 11 files changed, 1722 insertions(+) create mode 100755 uc/Makefile create mode 100644 uc/calibration.pde create mode 120000 uc/calibration.pde.c create mode 100644 uc/main.1mhz.c create mode 100644 uc/main.1mhz.h create mode 100755 uc/main.cxx create mode 120000 uc/main.pde create mode 100644 uc/wiring/binary.h create mode 100755 uc/wiring/serial.c create mode 100755 uc/wiring/wiring.h create mode 100755 uc/wiring/wiring_private.h diff --git a/uc/Makefile b/uc/Makefile new file mode 100755 index 0000000..abe2f2a --- /dev/null +++ b/uc/Makefile @@ -0,0 +1,289 @@ +# Arduino 0011 Makefile +# Arduino adaptation by mellis, eighthave, oli.keller +# +# This makefile allows you to build sketches from the command line +# without the Arduino environment (or Java). +# +# Detailed instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. There should be a +# file with the extension .pde (e.g. foo.pde) +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "INSTALL_DIR" to point to the directory that +# contains the Arduino installation (for example, under Mac OS X, this +# might be /Applications/arduino-0011). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. Set the line containing "MCU" to match your board's processor. +# Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth +# or Diecimila have the atmega168. If you're using a LilyPad Arduino, +# change F_CPU to 8000000. +# +# 6. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 7. Type "make" and press enter to compile/verify your program. +# +# 8. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id$ + +############################################################################### +# +# project specific settings: WEE! +# +TARGET = main +ARDUINO_VERSION = 0011 +INSTALL_DIR = /home/icarus75/arduino/arduino-$(ARDUINO_VERSION) +############################################################################### + + +############################################################################### +# +# serial uploader settings +# +PORT = /dev/ttyUSB* +UPLOAD_RATE = 19200 +AVRDUDE_PROGRAMMER = usbtiny +# BVDM; changed from stk500v1. Will probably give us a permissions error + +# HINT: If you want to use the automatic reset feature which comes with Arduino +# Diecimila, put the follwoing in your avrdude.conf: +# (Use the systemwide $(INSTALL_DIR)/tools/avr/etc/avrdude.conf or create a +# local $HOME/.avrduderc file) +# +# programmer +# id = "arduino"; +# desc = "Arduino Serial Bootloader"; +# type = stk500; +# reset = 7; +# # since Arduino Diecimila the serial DTR line can be used to trigger a reset! +# ; +# +# After this you can specify AVRDUDE_PROGRAMMER = arduino, above. +# On older boards you can manually ad this reset feature. Wire a cable from the +# FTDI 232 Chip's DTR pin (the number differs from package to package, see datasheet) +# to the RESET line of the ATmega. Inbetween this connection must be a 100nF capacitor. +##################################################################################### + + +##################################################################################### +# +# hardware dependent settings +# +MCU = atmega48 +F_CPU = 1000000 +# F_CPU sets the clock speed in Hz. For LilyPad Arduino, change F_CPU to 8000000. +##################################################################################### + + +##################################################################################### +# +# Below here nothing should be changed... +# +##################################################################################### + +ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino +AVR_TOOLS_PATH = /usr/bin +#SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ +$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ +$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \ +$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c +#CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp +SRC = wiring/serial.c +FORMAT = ihex + + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Place -I options here +#CINCS = -I$(ARDUINO) +#CXXINCS = -I$(ARDUINO) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = -lm + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:bin/$(TARGET).hex +AVRDUDE_WRITE_EEPROM = -U eeprom:w:bin/$(TARGET).eep +AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -b $(UPLOAD_RATE) + +# Program settings +CC = $(AVR_TOOLS_PATH)/avr-gcc +CXX = $(AVR_TOOLS_PATH)/avr-g++ +OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy +OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump +AR = $(AVR_TOOLS_PATH)/avr-ar +SIZE = $(AVR_TOOLS_PATH)/avr-size +NM = $(AVR_TOOLS_PATH)/avr-nm +AVRDUDE = $(INSTALL_DIR)/hardware/tools/avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: bin_files build sizeafter + +build: elf hex eep + +bin_files: $(TARGET).pde + # Here is the "preprocessing". + # It creates a .cpp file based with the same name as the .pde file. + # On top of the new .cpp file comes the WProgram.h header. + # At the end there is a generic main() function attached. + # Then the .cpp file will be compiled. Errors during compile will + # refer to this new, automatically generated, file. + # Not the original .pde file you actually edit... + test -d bin || mkdir bin + #echo '#include "WProgram.h"' > bin/$(TARGET).cpp + cat $(TARGET).pde > bin/$(TARGET).c + #cat main.cxx >> bin/$(TARGET).cpp + +elf: bin/$(TARGET).elf +hex: bin/$(TARGET).hex +eep: bin/$(TARGET).eep +lss: bin/$(TARGET).lss +sym: bin/$(TARGET).sym + +# Program the device. +upload: bin/$(TARGET).hex + sudo $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) +# sudo $(AVRDUDE) -c usbtiny -p atmega168 -b $(UPLOAD_RATE) -U lock:w:0x0F:m + + + # Display size of file. +HEXSIZE = $(SIZE) --target=$(FORMAT) bin/$(TARGET).hex +ELFSIZE = $(SIZE) bin/$(TARGET).elf +sizebefore: + @if [ -f bin/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi + +sizeafter: + @if [ -f bin/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: bin/$(TARGET).elf + $(COFFCONVERT) -O coff-avr bin/$(TARGET).elf $(TARGET).cof + + +extcoff: $(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr bin/$(TARGET).elf $(TARGET).cof + +.SUFFIXES: .elf .hex .eep .lss .sym + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + # Link: create ELF output file from library. +bin/$(TARGET).elf: $(TARGET).pde bin/core.a + $(CC) $(ALL_CFLAGS) -o $@ bin/$(TARGET).c -L. bin/core.a $(LDFLAGS) + +bin/core.a: $(OBJ) + @for i in $(OBJ); do echo $(AR) rcs bin/core.a $$i; $(AR) rcs bin/core.a $$i; done + + + +# Compile: create object files from C++ source files. +.cpp.o: + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +# Target: clean project. +clean: + $(REMOVE) bin/$(TARGET).hex bin/$(TARGET).eep bin/$(TARGET).cof bin/$(TARGET).elf \ + bin/$(TARGET).map bin/$(TARGET).sym bin/$(TARGET).lss bin/$(TARGET).c bin/core.a \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend bin_files sizebefore sizeafter diff --git a/uc/calibration.pde b/uc/calibration.pde new file mode 100644 index 0000000..b356e68 --- /dev/null +++ b/uc/calibration.pde @@ -0,0 +1,182 @@ +// Copyright (c) 2008 jokamajo.org +// $Id: main.pde 1 2008-08-19 00:40:00Z icarus75 $ + +// define section, move to main.h later on + +// macro's +#ifndef __AVR_ATmega168__ + #define __AVR_ATmega168__ +#endif + +#define METER0 "cccccccccccccccccccccccccccccccc" +#define METER1 "dddddddddddddddddddddddddddddddd" +#define METER2 "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" +#define METER3 "ffffffffffffffffffffffffffffffff" + +#define START 0 +#define END3 0xffffffff +#define END2 0xeeeeeeee +#define END1 0xdddddddd +#define END0 0xcccccccc + +// pin definitions +#define METER0PIN 2 +#define METER1PIN 3 +#define METER2PIN 4 +#define METER3PIN 9 + +#define POTPIN0 6 +#define POTPIN1 7 +#define POTPIN2 8 + +#define LEDPIN 13 + +// end of define + + +// pin/register/ISR definitions +#include + +// eeprom library +#include + +// watchdog timer library +#include + +// variable declarations +uint16_t i; + +typedef struct { + boolean pulse0; + boolean toggle0; + boolean pulse1; + boolean toggle1; + boolean pulse2; + boolean toggle2; + boolean pulse3; + boolean toggle3; +} struct_aux; + +volatile struct_aux aux = {false, false, false, false, false, false, false, false}; + + +typedef struct { + char meter[513]; //don't forget to reserve a byte for a terminating NULL +} struct_meas; + +volatile struct_meas EEMEM EEPROM_measurements; +volatile struct_meas measurements; + + +// interrupt service routine for analog comparator +ISR(ANALOG_COMP_vect) { + digitalWrite(LEDPIN, HIGH); // sets the LED on + UCSR0B &= ~((1< moved the call to this function to start of the main loop, before init + + // clock settings: divide by 8 to get a 1Mhz clock, allows us to set the BOD level to 1.8V (DS p.37) + CLKPR = (1< +#include + +#include "wiring/wiring_private.h" + +#include "main.1mhz.h" + +#include +// pin/register/ISR definitions +#include + +// eeprom library +#include + +// watchdog timer library +#include + +// variable declarations +volatile struct state aux[4] = {{false, false, START}, {false, false, START}, {false, false, START}, {false, false, START}}; + +volatile struct sensor EEMEM EEPROM_measurements[4] = {{SENSOR0, START}, {SENSOR1, START}, {SENSOR2, START}, {SENSOR3, START}}; +volatile struct sensor measurements[4]; + + +// interrupt service routine for INT0 +ISR(INT0_vect) { + measurements[0].value++; + aux[0].pulse = true; +} + +// interrupt service routine for INT1 +ISR(INT1_vect) { + measurements[1].value++; + aux[1].pulse = true; +} + +// interrupt service routine for PCI2 (PCINT20 = pin4) +ISR(PCINT2_vect) { + if (aux[2].toggle == false) { + aux[2].toggle = true; + } + else { + measurements[2].value++; + aux[2].pulse = true; + aux[2].toggle = false; + } +} + +// interrupt service routine for PCI0 (PCINT1 = pin9) +ISR(PCINT0_vect) { + if (aux[3].toggle == false) { + aux[3].toggle = true; + } + else { + measurements[3].value++; + aux[3].pulse = true; + aux[3].toggle = false; + } +} + +ISR(TIMER2_OVF_vect) { + // read ADC result + // add to nano(Wh) counter + aux[0].nano += (uint32_t)METERCONST * ADC; + if (aux[0].nano > 1000000000) { + printString("msg ADC0 sample value: "); + printIntegerInBase((unsigned long)ADC, 10); + printString("\n"); + //debugging + measurements[0].value++; + aux[0].pulse = true; + aux[0].nano -= 1000000000; + } + // start a new ADC conversion + ADCSRA |= (1< moved the call to this function to start of the main loop, before init + + // clock settings: divide by 8 to get a 1Mhz clock, allows us to set the BOD level to 1.8V (DS p.37) + CLKPR = (1< fTOV2 = 1000kHz / 256 / 32 = 122.07Hz + TCCR2B |= (1< 1000kHz / 8 = 125kHz + ADCSRA |= (1<value, buffer, 10); + length = strlen(buffer); + + strcpy(buffer, "pls "); + strcpy(&buffer[4], measurement->id); + strcpy(&buffer[36], ":"); + // insert leading 0's + for (i=0; i<10-length; i++) strcpy(&buffer[37+i], "0"); + ltoa(measurement->value, &buffer[47-length], 10); + strcpy(&buffer[47], "\n"); + + printString(buffer); + + // blink the green LED + PORTB |= (1<> 8; + UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1); + + // enable rx and tx + sbi(UCSR0B, RXEN0); + sbi(UCSR0B, TXEN0); + + // enable interrupt on complete reception of a byte + sbi(UCSR0B, RXCIE0); +#else + UBRRH = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8; + UBRRL = ((F_CPU / 16 + baud / 2) / baud - 1); + + // enable rx and tx + sbi(UCSRB, RXEN); + sbi(UCSRB, TXEN); + + // enable interrupt on complete reception of a byte + sbi(UCSRB, RXCIE); +#endif + + // defaults to 8-bit, no parity, 1 stop bit +} + +void serialWrite(unsigned char c) +{ +#if defined(__AVR_ATmega168__) | defined(__AVR_ATmega88__) | defined(__AVR_ATmega48__) + while (!(UCSR0A & (1 << UDRE0))) + ; + + UDR0 = c; +#else + while (!(UCSRA & (1 << UDRE))) + ; + + UDR = c; +#endif +} + +int serialAvailable() +{ + return (RX_BUFFER_SIZE + rx_buffer_head - rx_buffer_tail) % RX_BUFFER_SIZE; +} + +int serialRead() +{ + // if the head isn't ahead of the tail, we don't have any characters + if (rx_buffer_head == rx_buffer_tail) { + return -1; + } else { + unsigned char c = rx_buffer[rx_buffer_tail]; + rx_buffer_tail = (rx_buffer_tail + 1) % RX_BUFFER_SIZE; + return c; + } +} + +void serialFlush() +{ + // don't reverse this or there may be problems if the RX interrupt + // occurs after reading the value of rx_buffer_head but before writing + // the value to rx_buffer_tail; the previous value of rx_buffer_head + // may be written to rx_buffer_tail, making it appear as if the buffer + // were full, not empty. + rx_buffer_head = rx_buffer_tail; +} + +#if defined(__AVR_ATmega168__) | defined(__AVR_ATmega88__) | defined(__AVR_ATmega48__) +SIGNAL(SIG_USART_RECV) +#else +SIGNAL(SIG_UART_RECV) +#endif +{ +#if defined(__AVR_ATmega168__) | defined(__AVR_ATmega88__) | defined(__AVR_ATmega48__) + unsigned char c = UDR0; +#else + unsigned char c = UDR; +#endif + + int i = (rx_buffer_head + 1) % RX_BUFFER_SIZE; + + // if we should be storing the received character into the location + // just before the tail (meaning that the head would advance to the + // current location of the tail), we're about to overflow the buffer + // and so we don't write the character or advance the head. + if (i != rx_buffer_tail) { + rx_buffer[rx_buffer_head] = c; + rx_buffer_head = i; + } +} + +void printMode(int mode) +{ + // do nothing, we only support serial printing, not lcd. +} + +void printByte(unsigned char c) +{ + serialWrite(c); +} + +void printNewline() +{ + printByte('\n'); +} + +void printString(const char *s) +{ + while (*s) + printByte(*s++); +} + +void printIntegerInBase(unsigned long n, unsigned long base) +{ + unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. + unsigned long i = 0; + + if (n == 0) { + printByte('0'); + return; + } + + while (n > 0) { + buf[i++] = n % base; + n /= base; + } + + for (; i > 0; i--) + printByte(buf[i - 1] < 10 ? + '0' + buf[i - 1] : + 'A' + buf[i - 1] - 10); +} + +void printInteger(long n) +{ + if (n < 0) { + printByte('-'); + n = -n; + } + + printIntegerInBase(n, 10); +} + +void printHex(unsigned long n) +{ + printIntegerInBase(n, 16); +} + +void printOctal(unsigned long n) +{ + printIntegerInBase(n, 8); +} + +void printBinary(unsigned long n) +{ + printIntegerInBase(n, 2); +} + +/* Including print() adds approximately 1500 bytes to the binary size, + * so we replace it with the smaller and less-confusing printString(), + * printInteger(), etc. +void print(const char *format, ...) +{ + char buf[256]; + va_list ap; + + va_start(ap, format); + vsnprintf(buf, 256, format, ap); + va_end(ap); + + printString(buf); +} +*/ diff --git a/uc/wiring/wiring.h b/uc/wiring/wiring.h new file mode 100755 index 0000000..6a0c058 --- /dev/null +++ b/uc/wiring/wiring.h @@ -0,0 +1,121 @@ +/* + wiring.h - Partial implementation of the Wiring API for the ATmega8. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 387 2008-03-08 21:30:00Z mellis $ +*/ + +#ifndef Wiring_h +#define Wiring_h + +#include +#include "binary.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#define HIGH 0x1 +#define LOW 0x0 + +#define INPUT 0x0 +#define OUTPUT 0x1 + +#define true 0x1 +#define false 0x0 + +#define PI 3.14159265 +#define HALF_PI 1.57079 +#define TWO_PI 6.283185 +#define DEG_TO_RAD 0.01745329 +#define RAD_TO_DEG 57.2957786 + +#define SERIAL 0x0 +#define DISPLAY 0x1 + +#define LSBFIRST 0 +#define MSBFIRST 1 + +#define CHANGE 1 +#define FALLING 2 +#define RISING 3 + +#define INTERNAL 3 +#define DEFAULT 1 +#define EXTERNAL 0 + +// undefine stdlib's abs if encountered +#ifdef abs +#undef abs +#endif + +#define int(x) ((int)(x)) +#define char(x) ((char)(x)) +#define long(x) ((long)(x)) +#define byte(x) ((uint8_t)(x)) +#define float(x) ((float)(x)) +#define boolean(x) ((uint8_t)((x)==0?0:1)) + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define abs(x) ((x)>0?(x):-(x)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +#define interrupts() sei() +#define noInterrupts() cli() + +#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) + +typedef uint8_t boolean; +typedef uint8_t byte; + +void init(void); + +void beginSerial(long); +void serialWrite(unsigned char); +int serialAvailable(void); +int serialRead(void); +void serialFlush(void); +void printMode(int); +void printByte(unsigned char c); +void printNewline(void); +void printString(const char *s); +void printInteger(long n); +void printHex(unsigned long n); +void printOctal(unsigned long n); +void printBinary(unsigned long n); +void printIntegerInBase(unsigned long n, unsigned long base); + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val); + +void setup(void); +void loop(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif diff --git a/uc/wiring/wiring_private.h b/uc/wiring/wiring_private.h new file mode 100755 index 0000000..f2dc83f --- /dev/null +++ b/uc/wiring/wiring_private.h @@ -0,0 +1,58 @@ +/* + wiring_private.h - Internal header file. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ +*/ + +#ifndef WiringPrivate_h +#define WiringPrivate_h + +#include +#include +#include +#include +#include + +#include "wiring.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#ifndef cbi +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#endif +#ifndef sbi +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#endif + +#define EXTERNAL_INT_0 0 +#define EXTERNAL_INT_1 1 + +#define EXTERNAL_NUM_INTERRUPTS 2 + +typedef void (*voidFuncPtr)(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif