From b43eccd4cffed5bd1017c5821524fb6e49202f78 Mon Sep 17 00:00:00 2001 From: Sandeep Gupta Date: Sun, 18 Jun 2017 23:55:40 +0530 Subject: First commit --- 2.3-1/src/c/hardware/avr/adc/u8AVRADCSetups.c | 43 +++ 2.3-1/src/c/hardware/avr/adc/u8AVRReadADCs.c | 82 +++++ 2.3-1/src/c/hardware/avr/default_files/Makefile | 387 +++++++++++++++++++++ 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalIns.c | 63 ++++ 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalOuts.c | 78 +++++ .../c/hardware/avr/gpio/u8AVRDigitalPortSetups.c | 81 +++++ 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalSetups.c | 70 ++++ .../src/c/hardware/avr/includes/AVRPeripheralADC.h | 27 ++ .../c/hardware/avr/includes/AVRPeripheralGPIO.h | 54 +++ .../src/c/hardware/avr/includes/AVRPeripheralPWM.h | 34 ++ .../c/hardware/avr/includes/AVRPeripheralTimer.h | 32 ++ .../c/hardware/avr/includes/AVRPeripheralUART.h | 59 ++++ 2.3-1/src/c/hardware/avr/includes/AVRUtil.h | 31 ++ .../hardware/avr/interfaces/int_AVRPeripheralADC.h | 32 ++ .../avr/interfaces/int_AVRPeripheralGPIO.h | 40 +++ .../hardware/avr/interfaces/int_AVRPeripheralPWM.h | 39 +++ .../avr/interfaces/int_AVRPeripheralTimer.h | 31 ++ .../avr/interfaces/int_AVRPeripheralUART.h | 57 +++ 2.3-1/src/c/hardware/avr/interfaces/int_AVRUtil.h | 32 ++ 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0SetDutys.c | 24 ++ 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0Setups.c | 50 +++ 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM1SetDutys.c | 31 ++ 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM1Setups.c | 69 ++++ 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM2SetDutys.c | 22 ++ 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM2Setups.c | 47 +++ .../c/hardware/avr/timer/u16AVRGetTimerValues.c | 51 +++ .../src/c/hardware/avr/timer/u8AVRGetTimerValues.c | 63 ++++ 2.3-1/src/c/hardware/avr/timer/u8AVRTimerSetups.c | 110 ++++++ 2.3-1/src/c/hardware/avr/uart/dAVRUARTTransmits.c | 88 +++++ 2.3-1/src/c/hardware/avr/uart/dAVRUARTTransmitu8.c | 21 ++ 2.3-1/src/c/hardware/avr/uart/gAVRUARTTransmita.c | 26 ++ 2.3-1/src/c/hardware/avr/uart/gAVRUARTTransmits.c | 31 ++ 2.3-1/src/c/hardware/avr/uart/gAVRUARTTransmitu8.c | 24 ++ .../src/c/hardware/avr/uart/i16AVRUARTTransmita.c | 27 ++ .../src/c/hardware/avr/uart/i16AVRUARTTransmits.c | 73 ++++ .../src/c/hardware/avr/uart/i16AVRUARTTransmitu8.c | 31 ++ 2.3-1/src/c/hardware/avr/uart/i8AVRUARTTransmita.c | 25 ++ 2.3-1/src/c/hardware/avr/uart/i8AVRUARTTransmits.c | 26 ++ .../src/c/hardware/avr/uart/u16AVRUARTTransmita.c | 28 ++ .../src/c/hardware/avr/uart/u16AVRUARTTransmits.c | 87 +++++ .../src/c/hardware/avr/uart/u16AVRUARTTransmitu8.c | 38 ++ .../c/hardware/avr/uart/u8AVRUARTReceiveCharu8.c | 20 ++ 2.3-1/src/c/hardware/avr/uart/u8AVRUARTSetups.c | 143 ++++++++ 2.3-1/src/c/hardware/avr/uart/u8AVRUARTTransmita.c | 26 ++ 2.3-1/src/c/hardware/avr/uart/u8AVRUARTTransmits.c | 60 ++++ 2.3-1/src/c/hardware/avr/util/u16AVRSleeps.c | 21 ++ 46 files changed, 2534 insertions(+) create mode 100644 2.3-1/src/c/hardware/avr/adc/u8AVRADCSetups.c create mode 100644 2.3-1/src/c/hardware/avr/adc/u8AVRReadADCs.c create mode 100644 2.3-1/src/c/hardware/avr/default_files/Makefile create mode 100644 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalIns.c create mode 100644 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalOuts.c create mode 100644 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalPortSetups.c create mode 100644 2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalSetups.c create mode 100644 2.3-1/src/c/hardware/avr/includes/AVRPeripheralADC.h create mode 100644 2.3-1/src/c/hardware/avr/includes/AVRPeripheralGPIO.h create mode 100644 2.3-1/src/c/hardware/avr/includes/AVRPeripheralPWM.h create mode 100644 2.3-1/src/c/hardware/avr/includes/AVRPeripheralTimer.h create mode 100644 2.3-1/src/c/hardware/avr/includes/AVRPeripheralUART.h create mode 100644 2.3-1/src/c/hardware/avr/includes/AVRUtil.h create mode 100644 2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h create mode 100644 2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h create mode 100644 2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h create mode 100644 2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h create mode 100644 2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralUART.h create mode 100644 2.3-1/src/c/hardware/avr/interfaces/int_AVRUtil.h create mode 100644 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0SetDutys.c create mode 100644 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0Setups.c create mode 100644 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM1SetDutys.c create mode 100644 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM1Setups.c create mode 100644 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM2SetDutys.c create mode 100644 2.3-1/src/c/hardware/avr/pwm/u8AVRPWM2Setups.c create mode 100644 2.3-1/src/c/hardware/avr/timer/u16AVRGetTimerValues.c create mode 100644 2.3-1/src/c/hardware/avr/timer/u8AVRGetTimerValues.c create mode 100644 2.3-1/src/c/hardware/avr/timer/u8AVRTimerSetups.c create mode 100644 2.3-1/src/c/hardware/avr/uart/dAVRUARTTransmits.c create mode 100644 2.3-1/src/c/hardware/avr/uart/dAVRUARTTransmitu8.c create mode 100644 2.3-1/src/c/hardware/avr/uart/gAVRUARTTransmita.c create mode 100644 2.3-1/src/c/hardware/avr/uart/gAVRUARTTransmits.c create mode 100644 2.3-1/src/c/hardware/avr/uart/gAVRUARTTransmitu8.c create mode 100644 2.3-1/src/c/hardware/avr/uart/i16AVRUARTTransmita.c create mode 100644 2.3-1/src/c/hardware/avr/uart/i16AVRUARTTransmits.c create mode 100644 2.3-1/src/c/hardware/avr/uart/i16AVRUARTTransmitu8.c create mode 100644 2.3-1/src/c/hardware/avr/uart/i8AVRUARTTransmita.c create mode 100644 2.3-1/src/c/hardware/avr/uart/i8AVRUARTTransmits.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u16AVRUARTTransmita.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u16AVRUARTTransmits.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u16AVRUARTTransmitu8.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u8AVRUARTReceiveCharu8.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u8AVRUARTSetups.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u8AVRUARTTransmita.c create mode 100644 2.3-1/src/c/hardware/avr/uart/u8AVRUARTTransmits.c create mode 100644 2.3-1/src/c/hardware/avr/util/u16AVRSleeps.c (limited to '2.3-1/src/c/hardware/avr') diff --git a/2.3-1/src/c/hardware/avr/adc/u8AVRADCSetups.c b/2.3-1/src/c/hardware/avr/adc/u8AVRADCSetups.c new file mode 100644 index 00000000..66f491b2 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/adc/u8AVRADCSetups.c @@ -0,0 +1,43 @@ +// Function to initialise ADC of AVR +// +// Calling Sequence +// AVRSetupADC(uint8 prescaler, uint8 adc_ref) +// +// Parameters +// prescaler: prescaler to be used for generating ADC clock (0-7) +// adc_ref : reference voltage to be used for ADC conversion +// 0 -> Voltage on VREF pin +// 1 -> Voltage on AVCC pin +// 2 -> Internal 2.56 reference voltage +// +// Description +// This function initialises ADc of AVR with given parameters. 'prescaler' is +// needed for deciding ADC clock. ADC clock should be between 50KHz and 200KHz +// and it given as (MCU clock/2^prescaler). Select appropriate prescaler depending +// on MCU clock. 'adc_ref' selects one of the available reference voltage sources +// available +// Examples +// AVRADCSetup(128,0) +// +// Authors +// Siddhesh Wani +// Ashish Kamble + +#include "AVRPeripheralADC.h" + + +uint8 u8AVRADCSetups(uint8 prescaler, uint8 adc_ref) +{ +/*Set the prescaler value*/ + ADCSRA |= (prescaler & 0x07); + + /*Set the adc reference voltage*/ + ADMUX |= ((adc_ref & 0x03) << 6); + + /*Enable ADC hardware. Set ADEN bit*/ +ADCSRA |= (1<<7); + +return 0; +} + + diff --git a/2.3-1/src/c/hardware/avr/adc/u8AVRReadADCs.c b/2.3-1/src/c/hardware/avr/adc/u8AVRReadADCs.c new file mode 100644 index 00000000..302f8c82 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/adc/u8AVRReadADCs.c @@ -0,0 +1,82 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +// Function to get voltage on analog pin on AVR +// +// Calling Sequence +// u8AVRReadADCs(channel) +// +// Parameters +// channel : Select which channel is to be read. Values from 0-7 select one +// of the pins ADC0-ADC7. For other possible channel values refer +// datasheet +// Returns-> +// result : Digital value for the voltage present on channel selected +// +// Description +// This function returns digital value for present on adc pins. 'channel' +// selects which of the ADC0-ADC7 is to be used for reading analog value. +// Apart from reading just ADC0-ADC7 other it can also read differential +// voltages between some pins. For channel values for those options, please +// refer datasheet. +// +// Examples +// adc_result = u8AVRReadADC(0) //Read ADC0 +// +// Authors +// Siddhesh Wani +// Ashish Kamble + + +#include "AVRPeripheralADC.h" + +uint8 u8AVRReadADCs(uint8 channel) +{ + +uint8 i; + + ADCH=0x00; + + i=channel&0x07; + ADMUX=i|0x60; //i|0x40 for 10 bits + ADCSRA|=1< +# to submit bug reports. +#AVRDUDE_FLAGS += -v -v + +#Run while cable attached or don't +AVRDUDE_FLAGS += -E reset #keep chip disabled while cable attached +#AVRDUDE_FLAGS += -E noreset + +#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x04:m #run with 8 Mhz clock + +#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x21:m #run with 1 Mhz clock #default clock mode + +#AVRDUDE_WRITE_FLASH = -U lfuse:w:0x01:m #run with 1 Mhz clock no start up time + +# --------------------------------------------------------------------------- + +# Define directories, if needed. +DIRAVR = /usr/lib/avr +DIRAVRBIN = $(DIRAVR)/bin +DIRAVRUTILS = $(DIRAVR)/utils/bin +DIRINC = $(DIRAVR)/include +DIRLIB = $(DIRAVR)/lib + + +# Define programs and commands. +SHELL = sh + +CC = avr-gcc + +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +AR = avr-ar + +# Programming support using avrdude. +AVRDUDE = avrdude + + +REMOVE = rm -f +COPY = cp + +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex +ELFSIZE = $(SIZE) -A $(TARGET).elf + + + +# Define Messages +# English +MSG_ERRORS_NONE = Errors: none +MSG_BEGIN = -------- begin -------- +MSG_END = -------- end -------- +MSG_SIZE_BEFORE = Size before: +MSG_SIZE_AFTER = Size after: +MSG_COFF = Converting to AVR COFF: +MSG_EXTENDED_COFF = Converting to AVR Extended COFF: +MSG_FLASH = Creating load file for Flash: +MSG_EEPROM = Creating load file for EEPROM: +MSG_EXTENDED_LISTING = Creating Extended Listing: +MSG_SYMBOL_TABLE = Creating Symbol Table: +MSG_LINKING = Linking: +MSG_COMPILING = Compiling: +MSG_ASSEMBLING = Assembling: +MSG_CLEANING = Cleaning project: + + + + +# Define all object files. +OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) + +#LOCAL_LIB +LOCAL_LIB = main.a + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + + +# Default target: make program! +all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \ + $(TARGET).lss $(TARGET).sym sizeafter finished end +# $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + +# Eye candy. +# AVR Studio 3.x does not check make's exit code but relies on +# the following magic strings to be generated by the compile job. +begin: + @echo + @echo $(MSG_BEGIN) + +finished: + @echo $(MSG_ERRORS_NONE) + +end: + @echo $(MSG_END) + @echo + + +# Display size of file. +sizebefore: + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi + +sizeafter: + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi + + + +# Display compiler version information. +gccversion : + @$(CC) --version + + + + +# 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: $(TARGET).elf + @echo + @echo $(MSG_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof + + +extcoff: $(TARGET).elf + @echo + @echo $(MSG_EXTENDED_COFF) $(TARGET).cof + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof + + + + +# Program the device. +program: $(TARGET).hex $(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + + + + +# Create final output files (.hex, .eep) from ELF output file. +%.hex: %.elf + @echo + @echo $(MSG_FLASH) $@ + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +%.eep: %.elf + @echo + @echo $(MSG_EEPROM) $@ + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +%.lss: %.elf + @echo + @echo $(MSG_EXTENDED_LISTING) $@ + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + @echo + @echo $(MSG_SYMBOL_TABLE) $@ + avr-nm -n $< > $@ + + + +# Link: create ELF output file from object files. +.SECONDARY : $(TARGET).elf +.PRECIOUS : $(OBJ) +%.elf: %.a + @echo + @echo $(MSG_LINKING) $@ + $(CC) $(ALL_CFLAGS) $(LOCAL_LIB) -o $@ $(LDFLAGS) + +$(LOCAL_LIB): $(OBJ) + $(AR) rcs $@ $(OBJ) + +# Compile: create object files from C source files. +%.o : %.c + @echo + @echo $(MSG_COMPILING) $< + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +%.s : %.c + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +%.o : %.S + @echo + @echo $(MSG_ASSEMBLING) $< + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + + + + +# Target: clean project. +clean: begin clean_list finished end + +clean_list : + @echo + @echo $(MSG_CLEANING) + $(REMOVE) $(TARGET).hex + $(REMOVE) $(TARGET).eep + $(REMOVE) $(TARGET).obj + $(REMOVE) $(TARGET).cof + $(REMOVE) $(TARGET).elf + $(REMOVE) $(TARGET).map + $(REMOVE) $(TARGET).obj + $(REMOVE) $(TARGET).a90 + $(REMOVE) $(TARGET).sym + $(REMOVE) $(TARGET).lnk + $(REMOVE) $(TARGET).lss + $(REMOVE) $(OBJ) + $(REMOVE) $(LST) + $(REMOVE) $(SRC:.c=.s) + $(REMOVE) $(SRC:.c=.d) + $(REMOVE) *~ + +# Automatically generate C source code dependencies. +# (Code originally taken from the GNU make user manual and modified +# (See README.txt Credits).) +# +# Note that this will work with sh (bash) and sed that is shipped with WinAVR +# (see the SHELL variable defined above). +# This may not work with other shells or other seds. +# +%.d: %.c + set -e; $(CC) -MM $(ALL_CFLAGS) $< \ + | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \ + [ -s $@ ] || rm -f $@ + + +# Remove the '-' if you want to see the dependency files generated. +-include $(SRC:.c=.d) + + + +# Listing of phony targets. +.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \ + clean clean_list program diff --git a/2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalIns.c b/2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalIns.c new file mode 100644 index 00000000..a2517b98 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalIns.c @@ -0,0 +1,63 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +// Function to get current state (high\low) of a digital pin on AVR +// +// Calling Sequence +// u8AVRDigitalIns(port,pin) +// +// Parameters +// port : port of microcontroller to be used (1 for PORTA, 2 for PORTB,...) +// pin : pin of port (mentioned above) to be used +// Returns-> +// state : state of the pin (0 for low and 1 for high) +// +// Description +// Each AVR microcontroller has pins which can be configured as digital +// outputs. These are normally divided among some 'ports' (group of pins). +// User has to select one of these port and which pin of that port is to +// be read. Function returns current state of the pin '1' (high) or '0' (low). +// +// +// Examples +// state = u8AVRDigitalIns(1,0) +// +// Authors +// Siddhesh Wani +// + + +#include "AVRPeripheralGPIO.h" + +uint8 u8AVRDigitalIns(uint8 port,uint8 pin) +{ + unsigned int state = 0; + if(port == PORT_A) + { + state = bit_is_clear(PINA,pin); + return !state; + } + if(port == PORT_B) + { + state = bit_is_clear(PINB,pin); + return !state; + } + if(port == PORT_C) + { + state = bit_is_clear(PINC,pin); + return !state; + } + if(port == PORT_D) + { + state = bit_is_clear(PIND,pin); + return !state; + } + +} diff --git a/2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalOuts.c b/2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalOuts.c new file mode 100644 index 00000000..8998fc91 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/gpio/u8AVRDigitalOuts.c @@ -0,0 +1,78 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +// Function to change state (high\low) of a digital output pin on AVR +// +// Calling Sequence +// u8AVRDigitalOuts(port,pin,state) +// +// Parameters +// port : port of microcontroller to be used (1 for PORTA, 2 for PORTB,...) +// pin : pin of port (mentioned above) to be used +// state : state to be outputed on pin (0 for low and 1 for high) +// +// Description +// Each AVR microcontroller has pins which can be configured as digital +// outputs. These are normally divided among some 'ports' (group of pins). +// User has to select one of these port and which pin of that port as +// digital output. Also, desired output state must be specified as +// '1' (high) or '0' (low). +// +// Examples +// u8AVRDigitalOuts(1,0,1) +// +// Authors +// Siddhesh Wani +// Ashish Kamble + + +#include "AVRPeripheralGPIO.h" + +void u8AVRDigitalOuts(uint8 port,uint8 pin,uint8 state) +{ + if(state == LOW) + {/*Make output pin high*/ + if(port == PORT_A) + { + PORTA = PORTA & ~(1< +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//Function prototypes +uint8 u8AVRADCSetups(uint8 prescaler, uint8 adc_ref); + +uint8 u8AVRReadADCs(uint8 channel); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALGPIO_H__ */ diff --git a/2.3-1/src/c/hardware/avr/includes/AVRPeripheralGPIO.h b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralGPIO.h new file mode 100644 index 00000000..9a8d2d65 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralGPIO.h @@ -0,0 +1,54 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __AVRPERIPHERALGPIO_H__ +#define __AVRPERIPHERALGPIO_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#include "types.h" + +//Port definitions +#define PORT_A 1 +#define PORT_B 2 +#define PORT_C 3 +#define PORT_D 4 + +//Direction definitions +#define INPUT 0 +#define OUTPUT 1 + +//Pin state definitions +#define LOW 0 +#define HIGH 1 + +//Function prototypes +void u8AVRDigitalSetups(uint8 port,uint8 pin,uint8 direction); + +uint8 u8AVRDigitalIns(uint8 port,uint8 pin); + +void u8AVRDigitalOuts(uint8 port,uint8 pin,uint8 state); + +uint8 u8AVRDigitalPortSetups(uint8 port,uint8 direction); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALGPIO_H__ */ diff --git a/2.3-1/src/c/hardware/avr/includes/AVRPeripheralPWM.h b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralPWM.h new file mode 100644 index 00000000..2107a5a4 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralPWM.h @@ -0,0 +1,34 @@ +//This file defines functions prototypes related to PWM. +// +// Authors +// Ashish Kamble +// + +#ifndef __AVRPERIPHERALPWM_H__ +#define __AVRPERIPHERALPWM_H__ + +#include +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//Function prototypes +uint8 u8AVRPWM0Setups(uint8 waveform_mode, uint8 output_mode); + +uint8 u8AVRPWM2Setups(uint8 waveform_mode, uint8 output_mode); + +uint8 u8AVRPWM1Setups(uint8 waveform_mode, uint8 output_mode, uint8 output_pin); + +uint8 u8AVRPWM0SetDutys(uint8 duty); + +uint8 u8AVRPWM2SetDutys(uint8 duty); + +uint8 u8AVRPWM1SetDutys(uint8 output_pin, uint16 duty, uint16 Top_Value); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALPWM_H__ */ diff --git a/2.3-1/src/c/hardware/avr/includes/AVRPeripheralTimer.h b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralTimer.h new file mode 100644 index 00000000..ab087692 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralTimer.h @@ -0,0 +1,32 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Ashish Kamble +// Email: toolbox@scilab.in + +#ifndef __AVRPERIPHERALTIMER_H__ +#define __AVRPERIPHERALTIMER_H__ + +#include +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//Function prototypes + +uint16 u8AVRGetTimerValues(uint16 timer); + +uint8 u8AVRTimerSetups(uint8 timer, uint16 prescaler,uint8 clock_source); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALTIMER_H__ */ diff --git a/2.3-1/src/c/hardware/avr/includes/AVRPeripheralUART.h b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralUART.h new file mode 100644 index 00000000..09db3b03 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/includes/AVRPeripheralUART.h @@ -0,0 +1,59 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __AVRPERIPHERALUART_H__ +#define __AVRPERIPHERALUART_H__ + +#include +#include "types.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +//Function prototypes +uint8 u8AVRUARTSetups(uint8 mode, uint32 baudrate, uint8 stopbits, uint8 parity); + +uint8 u8AVRUARTTransmits(uint8 data); + +uint8 gAVRUARTTransmits(char* msg,int size); + +uint8 u16AVRUARTTransmits(uint16 data); + +uint8 i16AVRUARTTransmits(int16 data); + +uint8 i8AVRUARTTransmits(int8 data); + +//uint8 sAVRUARTTransmits(float data); + +uint8 u8AVRUARTTransmita(uint8 *x,int size); + +//uint8 gAVRUARTTransmita(uint8 *x,int size); + +uint8 u16AVRUARTTransmita(uint16 *x,int size); + +uint8 i16AVRUARTTransmita(int16 *x,int size); + +uint8 i8AVRUARTTransmita(int8 *x,int size); + +uint8 u8AVRUSARTReceiveCharu8(); + +uint8 dAVRUARTTransmits(double data); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRUART_H__ */ + + diff --git a/2.3-1/src/c/hardware/avr/includes/AVRUtil.h b/2.3-1/src/c/hardware/avr/includes/AVRUtil.h new file mode 100644 index 00000000..55789bef --- /dev/null +++ b/2.3-1/src/c/hardware/avr/includes/AVRUtil.h @@ -0,0 +1,31 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Siddhesh Wani +// Email: toolbox@scilab.in + +#ifndef __AVRUTIL_H__ +#define __AVRUTIL_H__ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "types.h" +#include "util/delay.h" + +uint8 u16AVRSleeps (uint16 delay); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRUTIL_H__ */ diff --git a/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h new file mode 100644 index 00000000..5d3a48e5 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h @@ -0,0 +1,32 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Aithor: Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __INT_AVRPERIPHERALADC_H__ +#define __INT_AVRPERIPHERALADC_H__ + +#include +#include "AVRPeripheralADC.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRADCSetup(in1,in2) u8AVRADCSetups((uint8) in1,\ + (uint8) in2); + +#define AVRReadADC(in1) u8AVRReadADCs((uint8) in1); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALADC_H__ */ diff --git a/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h new file mode 100644 index 00000000..3fcbb8f5 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h @@ -0,0 +1,40 @@ + +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Siddhesh Wani, Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __INT_AVRPERIPHERALGPIO_H__ +#define __INT_AVRPERIPHERALGPIO_H__ + +#include +#include "AVRPeripheralGPIO.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRDigitalSetup(in1,in2,in3) u8AVRDigitalSetups((uint8) in1,\ + (uint8) in2, (uint8) in3); + +#define AVRDigitalIn(in1,in2) u8AVRDigitalIns((uint8) in1, (uint8) in2); + +#define AVRDigitalOut(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\ + (uint8) in2, (uint8) in3); + +#define AVRDigitalPortSetup(in1,in2) u8AVRDigitalPortSetups((uint8) in1,\ + (uint8) in2); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALGPIO_H__ */ diff --git a/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h new file mode 100644 index 00000000..5c5950bc --- /dev/null +++ b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h @@ -0,0 +1,39 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __INT_AVRPERIPHERALPWM_H__ +#define __INT_AVRPERIPHERALPWM_H__ + +#include +#include "AVRPeripheralPWM.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRPWM0Setup(in1,in2) u8AVRPWM0Setups((uint8) in1, (uint8) in2); + +#define AVRPWM2Setup(in1,in2) u8AVRPWM2Setups((uint8) in1, (uint8) in2); + +#define AVRPWM1Setup(in1,in2,in3) u8AVRPWM1Setups((uint8) in1, (uint8) in2, (uint8) in3); + +#define AVRPWM0SetDuty(in1) u8AVRPWM0SetDutys((uint8) in1); + +#define AVRPWM2SetDuty(in1) u8AVRPWM2SetDutys((uint8) in1); + +#define AVRPWM1SetDuty(in1,in2,in3) u8AVRPWM1SetDutys((uint8) in1,(uint16) in2,(uint16) in3); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALADC_H__ */ diff --git a/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h new file mode 100644 index 00000000..3ec6a7ec --- /dev/null +++ b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h @@ -0,0 +1,31 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Siddhesh Wani, Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __INT_AVRPERIPHERALTIMER_H__ +#define __INT_AVRPERIPHERALTIMER_H__ + +#include +#include "AVRPeripheralTimer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRGetTimerValue(in1) u8AVRGetTimerValues((uint16) in1); + +#define AVRTimerSetup(in1,in2,in3) u8AVRTimerSetups((uint8) in1, (uint16) in2, (uint8) in3); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALADC_H__ */ diff --git a/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralUART.h b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralUART.h new file mode 100644 index 00000000..81b4af68 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/interfaces/int_AVRPeripheralUART.h @@ -0,0 +1,57 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Authors: Siddhesh Wani, Ashish Kamble +// Email: toolbox@scilab.in + + +#ifndef __INT_AVRPERIPHERALUART_H__ +#define __INT_AVRPERIPHERALUART_H__ + +#include +#include "AVRPeripheralUART.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRUARTSetup(in1,in2,in3,in4) u8AVRUARTSetups((uint8) in1,(uint32) in2,(uint8) in3,(uint8) in4); + +#define u80AVRUARTTransmitu80(in1) u8AVRUARTTransmits((uint8) in1); + +#define g2AVRUARTTransmitu80(in1,in2) gAVRUARTTransmits((char*) in1,in2[0]*in2[1]); + +#define u160AVRUARTTransmitu80(in1) u16AVRUARTTransmits((uint16) in1); + +#define i160AVRUARTTransmitu80(in1) i16AVRUARTTransmits((int16) in1); + +#define i80AVRUARTTransmitu80(in1) i8AVRUARTTransmits((int8) in1); + +#define u82AVRUARTTransmitu80(in1,in2) u8AVRUARTTransmita((uint8) in1,in2[0]*in2[1]); + +#define d0AVRUARTTransmitu80(in1) dAVRUARTTransmits((double) in1); + +//#define g2AVRUARTTransmitu80(in1,in2) gAVRUARTTransmita((char*) in1,in2[0]*in2[1]); + +#define u162AVRUARTTransmitu80(in1,in2) u16AVRUARTTransmita((uint16) in1,in2[0]*in2[1]); + +#define i162AVRUARTTransmitu80(in1,in2) i16AVRUARTTransmita((int16) in1,in2[0]*in2[1]); + +#define i82AVRUARTTransmitu80(in1,in2) i8AVRUARTTransmita((int8) in1,in2[0]*in2[1]); + +#define u80AVRUSARTReceiveCharu80() u8AVRUSARTReceiveCharu8(); + +//#define s0AVRUARTTransmitu80(in1) sAVRUARTTransmits((float) in1); + + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALUART_H__ */ diff --git a/2.3-1/src/c/hardware/avr/interfaces/int_AVRUtil.h b/2.3-1/src/c/hardware/avr/interfaces/int_AVRUtil.h new file mode 100644 index 00000000..51cbce58 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/interfaces/int_AVRUtil.h @@ -0,0 +1,32 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Author: Siddhesh Wani +// Email: toolbox@scilab.in + + +#ifndef __INT_AVRUTIL_H__ +#define __INT_AVRUTIL_H__ + +#include +#include "AVRUtil.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//#define d0sleepu80(in1) u16AVRSleeps ((uint16) in1); + +#define AVRSleep(in1) u16AVRSleeps ((uint16) in1); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALGPIO_H__ */ diff --git a/2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0SetDutys.c b/2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0SetDutys.c new file mode 100644 index 00000000..106a872e --- /dev/null +++ b/2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0SetDutys.c @@ -0,0 +1,24 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ashish Kamble + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ +//Function to Set Duty cycle of PWM Output generated by Timer0 at OC0 pin. + + +#include "AVRPeripheralPWM.h" + +uint8 u8AVRPWM0SetDutys(uint8 duty) +{ + uint8 duty_value = 0; + duty_value = (((uint16)(duty * 0xff))/100); + OCR0 = duty_value; + return 0; +} + diff --git a/2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0Setups.c b/2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0Setups.c new file mode 100644 index 00000000..131ee68b --- /dev/null +++ b/2.3-1/src/c/hardware/avr/pwm/u8AVRPWM0Setups.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ashish Kamble + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ +//Function to Setup PWM output for OC0 pin. + + +#include "AVRPeripheralPWM.h" + + +uint8 u8AVRPWM0Setups(uint8 waveform_mode, uint8 output_mode) +{ + switch(waveform_mode) + { + case 0: + TCCR0 |= (1< + + +uint16 u8AVRGetTimerValues(uint16 timer) +{ + uint16_t x; + switch(timer) + { + case 0: + { + x = TCNT0; + break; + } + + case 1: + { + unsigned char sreg; + unsigned int val; + sreg = SREG; + cli(); + val = TCNT1; + SREG = sreg; + sei(); + x = val; + break; + } + + case 2: + { + x = TCNT2; + break; + } + } +return x; +} + diff --git a/2.3-1/src/c/hardware/avr/timer/u8AVRGetTimerValues.c b/2.3-1/src/c/hardware/avr/timer/u8AVRGetTimerValues.c new file mode 100644 index 00000000..e08bb3a6 --- /dev/null +++ b/2.3-1/src/c/hardware/avr/timer/u8AVRGetTimerValues.c @@ -0,0 +1,63 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + + +// Function to get timer count +// +// Calling Sequence +// u8AVRGetTimerValues(timer) +// +// Parameters +// timer: timer whose current count is to be returned (0,1,2) +// ***Refer datasheet for more description about timer +// +// Description +// This function returns the count of timer specified +// +// +// Authors +// Ashish Kamble +// + + +#include "AVRPeripheralTimer.h" +#include + + +uint16 u8AVRGetTimerValues(uint16 timer) +{ uint16_t x; + switch(timer) + { + case 0: + { + x = TCNT0; + break; + } + case 1: + { + unsigned char sreg; + unsigned int val; + sreg = SREG; + cli(); + val = TCNT1; + SREG = sreg; + sei(); + x = val; + break; + } + case 2: + { + x = TCNT2; + break; + } + } +return x; +} + diff --git a/2.3-1/src/c/hardware/avr/timer/u8AVRTimerSetups.c b/2.3-1/src/c/hardware/avr/timer/u8AVRTimerSetups.c new file mode 100644 index 00000000..6ee8d2af --- /dev/null +++ b/2.3-1/src/c/hardware/avr/timer/u8AVRTimerSetups.c @@ -0,0 +1,110 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ashish Kamble + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ +//Function selects the clock source and timer with prescaler. + +#include "AVRPeripheralTimer.h" + +uint8 u8AVRTimerSetups(uint8 timer,uint16 prescaler,uint8 clock_source) +{ + + if(clock_source==0) + { + if(timer==0) + { + switch(prescaler) + { + case 1: TCCR0 |= (1< + + +uint8 dAVRUARTTransmits(double data) +{ + //Extract integer part + long int intpart = (long int)data; + //Extract double part + //double floatpart = data - (double)intpart; + char* str; + int i = 0; + while(intpart) + { + str[i] = (intpart%10) + '0'; + intpart = intpart/10; + i++; + } + str[i]='\0'; + /* + int j = 0; + int k = i-1; + char temp; + while(j