From 96b51a5ded447676d493be9721e4480065a5ae7e Mon Sep 17 00:00:00 2001 From: siddhu8990 Date: Fri, 11 Dec 2015 18:28:43 +0530 Subject: AVR ADC checked after some modifications --- includes/sci2clib.h | 7 +-- macros/CCodeGeneration/C_InitHeader.bin | Bin 14056 -> 14064 bytes macros/CCodeGeneration/C_InitHeader.sci | 12 ++--- macros/Hardware/AVR/AVRADCSetup.bin | Bin 4168 -> 4168 bytes macros/Hardware/AVR/AVRADCSetup.sci | 2 +- macros/Hardware/AVR/AVRPWMSetup.bin | Bin 0 -> 5760 bytes macros/Hardware/AVR/AVRPWMSetup.sci | 39 ++++++++++++++ macros/Hardware/AVR/lib | Bin 836 -> 860 bytes macros/Hardware/AVR/names | 1 + .../ToolInitialization/INIT_FillSCI2LibCDirs.bin | Bin 929056 -> 932856 bytes .../ToolInitialization/INIT_FillSCI2LibCDirs.sci | 28 ++++++++++- macros/findDeps/getAllHeaders.bin | Bin 24080 -> 24256 bytes macros/findDeps/getAllHeaders.sci | 1 + macros/findDeps/getAllInterfaces.bin | Bin 25384 -> 25584 bytes macros/findDeps/getAllInterfaces.sci | 1 + macros/findDeps/getAllSources.bin | Bin 152368 -> 152368 bytes macros/findDeps/getAllSources.sci | 2 +- src/c/hardware/avr/includes/AVRUtil.h | 6 +-- .../avr/interfaces/int_AVRPeripheralGPIO.h | 4 ++ src/c/hardware/avr/interfaces/int_AVRUtil.h | 2 +- src/c/hardware/avr/pwm/u8AVRADCSetups.c | 56 +++++++++++++++++++++ src/c/hardware/avr/util/U16AVRSleeps.c | 14 ------ src/c/hardware/avr/util/u16AVRSleeps.c | 14 ++++++ src/c/scilab-arduino/default_files/Makefile | 4 +- 24 files changed, 161 insertions(+), 32 deletions(-) create mode 100644 macros/Hardware/AVR/AVRPWMSetup.bin create mode 100644 macros/Hardware/AVR/AVRPWMSetup.sci create mode 100644 src/c/hardware/avr/pwm/u8AVRADCSetups.c delete mode 100644 src/c/hardware/avr/util/U16AVRSleeps.c create mode 100644 src/c/hardware/avr/util/u16AVRSleeps.c diff --git a/includes/sci2clib.h b/includes/sci2clib.h index b9820bc..c1c82a3 100644 --- a/includes/sci2clib.h +++ b/includes/sci2clib.h @@ -330,7 +330,7 @@ #include "types.h" /*Scilab-arduino toolbox*/ -#ifdef ARDUINO +#ifdef Arduino1 #include "int_cmd_digital_out.h" #include "cmd_digital_out.h" #include "int_cmd_digital_in.h" @@ -344,12 +344,13 @@ #endif /*AVR*/ -#ifdef AVR +#ifdef AVR1 #include "int_AVRPeripheralGPIO.h" #include "AVRPeripheralGPIO.h" #include "int_AVRPeripheralADC.h" #include "AVRPeripheralADC.h" - +#include "int_AVRUtil.h" +#include "AVRUtil.h" #endif #endif /* !__SCI2CLIB_H__ */ diff --git a/macros/CCodeGeneration/C_InitHeader.bin b/macros/CCodeGeneration/C_InitHeader.bin index 4513310..642e75c 100644 Binary files a/macros/CCodeGeneration/C_InitHeader.bin and b/macros/CCodeGeneration/C_InitHeader.bin differ diff --git a/macros/CCodeGeneration/C_InitHeader.sci b/macros/CCodeGeneration/C_InitHeader.sci index 1d67b60..dffb972 100644 --- a/macros/CCodeGeneration/C_InitHeader.sci +++ b/macros/CCodeGeneration/C_InitHeader.sci @@ -34,6 +34,12 @@ C_SCI2CHeader(HeaderFileName); PrintStringInfo('#ifndef '+tmpfname+'_h',HeaderFileName,'file','y'); PrintStringInfo('#define '+tmpfname+'_h',HeaderFileName,'file','y'); PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('** ----- Target ------ ',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); +PrintStringInfo('# define ' + OutFormat + '1 1' ,HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); PrintStringInfo('** ----------------------- ',HeaderFileName,'file','y'); PrintStringInfo('** --- SCI2C Includes. --- ',HeaderFileName,'file','y'); PrintStringInfo('** ----------------------- ',HeaderFileName,'file','y'); @@ -51,12 +57,6 @@ PrintStringInfo('extern ""C"" {',HeaderFileName,'file','y'); PrintStringInfo('#endif',HeaderFileName,'file','y'); PrintStringInfo('/*',HeaderFileName,'file','y'); PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); -PrintStringInfo('** ----- Target ------ ',HeaderFileName,'file','y'); -PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); -PrintStringInfo('*/',HeaderFileName,'file','y'); -PrintStringInfo('# define ' + OutFormat + '1' ,HeaderFileName,'file','y'); -PrintStringInfo('/*',HeaderFileName,'file','y'); -PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); PrintStringInfo('** --- Prototypes. --- ',HeaderFileName,'file','y'); PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); PrintStringInfo('*/',HeaderFileName,'file','y'); diff --git a/macros/Hardware/AVR/AVRADCSetup.bin b/macros/Hardware/AVR/AVRADCSetup.bin index 6cf45dc..44e3d79 100644 Binary files a/macros/Hardware/AVR/AVRADCSetup.bin and b/macros/Hardware/AVR/AVRADCSetup.bin differ diff --git a/macros/Hardware/AVR/AVRADCSetup.sci b/macros/Hardware/AVR/AVRADCSetup.sci index d9897fc..ce9117d 100644 --- a/macros/Hardware/AVR/AVRADCSetup.sci +++ b/macros/Hardware/AVR/AVRADCSetup.sci @@ -2,7 +2,7 @@ function AVRADCSetup(prescalar,adc_ref) // Function to initialise ADC of AVR // // Calling Sequence -// AVRSetupADC(uint8 prescalar, uint8 adc_ref) +// AVRADCSetup(uint8 prescalar, uint8 adc_ref) // // Parameters // prescalar: prescalar to be used for generating ADC clock (0-7) diff --git a/macros/Hardware/AVR/AVRPWMSetup.bin b/macros/Hardware/AVR/AVRPWMSetup.bin new file mode 100644 index 0000000..6ae56fd Binary files /dev/null and b/macros/Hardware/AVR/AVRPWMSetup.bin differ diff --git a/macros/Hardware/AVR/AVRPWMSetup.sci b/macros/Hardware/AVR/AVRPWMSetup.sci new file mode 100644 index 0000000..7e1c234 --- /dev/null +++ b/macros/Hardware/AVR/AVRPWMSetup.sci @@ -0,0 +1,39 @@ +function AVRPWMSetup(timer, prescalar, waveform_mode, output_mode) +// Function to initialise PWM of AVR +// +// Calling Sequence +// AVRSetupADC(timer, prescalar, waveform_mode, output_mode) +// +// Parameters +// timer: timer to be used for PWM generation (0,1,2) +// prescalar: prescalar to be used for generating PWM waveform (0-7) +// waveform_mode: decides type of waveform generation +// 0 -> Normal mode +// 1 -> Phase correct mode +// 2 -> CTC mode +// 3 -> Fase PWM mode +// output_mode: decides the compare output mode. (0-3) +// behaviour of the output is different for different inputs +// depending upon 'waveform_mode' chosen. +// ***Refer datasheet for more description about above modes +// +// Description +// This function initialises PWM of AVR with given parameters. 'timer' +// decides which of the three (0,1,2) timers available to be used. The +// 'prescalar' is needed for deciding PWM clock. Select appropriate prescalar +// depending on MCU clock. Choose required pwmmode using 'waveform_generation' +// and 'output_mode'. Please refer datasheet for more description of 'wafefom_mode' +// and 'output mode'. +// Examples +// AVRPWMSetup(0,1,2,2) +// +// See also +// AVRPMWSetDuty +// +// Authors +// Siddhesh Wani +// + +// This is curretly dummy function. It provides no functionality but is required +// for providing support for generating C code for AVR. +endfunction diff --git a/macros/Hardware/AVR/lib b/macros/Hardware/AVR/lib index d08afbd..aa4d611 100644 Binary files a/macros/Hardware/AVR/lib and b/macros/Hardware/AVR/lib differ diff --git a/macros/Hardware/AVR/names b/macros/Hardware/AVR/names index 6e5b61b..afd171e 100644 --- a/macros/Hardware/AVR/names +++ b/macros/Hardware/AVR/names @@ -2,6 +2,7 @@ AVRADCSetup AVRDigitalIn AVRDigitalOut AVRDigitalSetup +AVRPWMSetup AVRReadADC GetAVRSupportFunctions GetPeripheral diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin index b2642d4..f790c5e 100644 Binary files a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin and b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin differ diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci index 6d829ce..c642353 100644 --- a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci +++ b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci @@ -982,7 +982,6 @@ ClassName = 'Max'; // --- Class Annotation. --- -disp("Inside Max Function"); PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y'); ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls); PrintStringInfo('NIN= 1',ClassFileName,'file','y'); @@ -4032,6 +4031,33 @@ PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file', INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun); INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun); +//------------------------------------ +//---- Class AVRDigitalOut ----------- +//------------------------------------ +ClassName = 'AVRDigitalIn'; + +// --- Class Annotation. --- +PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y'); +ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls); +PrintStringInfo('NIN= 2',ClassFileName,'file','y'); +PrintStringInfo('NOUT= 1 ',ClassFileName,'file','y'); +PrintStringInfo('OUT(1).TP= ''u8''',ClassFileName,'file','y'); +PrintStringInfo('OUT(1).SZ(1)= ''1''',ClassFileName,'file','y'); +PrintStringInfo('OUT(1).SZ(2)= ''1''',ClassFileName,'file','y'); + +// --- Function List Class. --- +ClassFileName = fullfile(SCI2CLibCFLClsDir,ClassName+ExtensionCFuncListCls); +PrintStringInfo('d0d0'+ArgSeparator+'u80',ClassFileName,'file','y'); +PrintStringInfo('d0u80'+ArgSeparator+'u80',ClassFileName,'file','y'); + +// --- Annotation Function And Function List Function. --- +FunctionName = 'AVRDigitalIn'; +PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y'); +INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun); +INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun); + + + //------------------------------------ //---- Class AVRADCSetup ----------- //------------------------------------ diff --git a/macros/findDeps/getAllHeaders.bin b/macros/findDeps/getAllHeaders.bin index 4314c53..50ce832 100644 Binary files a/macros/findDeps/getAllHeaders.bin and b/macros/findDeps/getAllHeaders.bin differ diff --git a/macros/findDeps/getAllHeaders.sci b/macros/findDeps/getAllHeaders.sci index f5c74bd..697a0fa 100644 --- a/macros/findDeps/getAllHeaders.sci +++ b/macros/findDeps/getAllHeaders.sci @@ -139,6 +139,7 @@ function allHeaders = getAllHeaders(OutFormat) AVR_headers = [ "src/c/hardware/avr/includes/AVRPeripheralGPIO.h" "src/c/hardware/avr/includes/AVRPeripheralADC.h" + "src/c/hardware/avr/includes/AVRUtil.h" ]; if OutFormat == "StandAlone" diff --git a/macros/findDeps/getAllInterfaces.bin b/macros/findDeps/getAllInterfaces.bin index b49fdbf..c28ac33 100644 Binary files a/macros/findDeps/getAllInterfaces.bin and b/macros/findDeps/getAllInterfaces.bin differ diff --git a/macros/findDeps/getAllInterfaces.sci b/macros/findDeps/getAllInterfaces.sci index 5b52c71..14249d0 100644 --- a/macros/findDeps/getAllInterfaces.sci +++ b/macros/findDeps/getAllInterfaces.sci @@ -133,6 +133,7 @@ function allInterfaces = getAllInterfaces(OutFormat) AVR_interfaces = [ "src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h" "src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h" + "src/c/hardware/avr/interfaces/int_AVRUtil.h" ]; if OutFormat == "StandAlone" diff --git a/macros/findDeps/getAllSources.bin b/macros/findDeps/getAllSources.bin index 4943977..b1591ac 100644 Binary files a/macros/findDeps/getAllSources.bin and b/macros/findDeps/getAllSources.bin differ diff --git a/macros/findDeps/getAllSources.sci b/macros/findDeps/getAllSources.sci index 956f7be..325d4b2 100644 --- a/macros/findDeps/getAllSources.sci +++ b/macros/findDeps/getAllSources.sci @@ -831,7 +831,7 @@ function allSources = getAllSources(OutFormat) "src/c/hardware/avr/gpio/u8AVRDigitalIns.c" "src/c/hardware/avr/adc/u8AVRADCSetups.c" "src/c/hardware/avr/adc/u8AVRReadADCs.c" - "src/c/scilab-arduino/sleep/u16sleeps.c" + "src/c/hardware/avr/util/u16AVRSleeps.c" ]; diff --git a/src/c/hardware/avr/includes/AVRUtil.h b/src/c/hardware/avr/includes/AVRUtil.h index 2e6d9ae..0aa1923 100644 --- a/src/c/hardware/avr/includes/AVRUtil.h +++ b/src/c/hardware/avr/includes/AVRUtil.h @@ -13,10 +13,10 @@ extern "C" { #endif -#include "Types.h" -#include "avr/util.h" +#include "types.h" +#include "util/delay.h" -uint8 U16AVRSleeps (uint16 delay); +uint8 u16AVRSleeps (uint16 delay); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h index a4f9b91..439532d 100644 --- a/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h +++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h @@ -23,6 +23,10 @@ extern "C" { #define d0d0d0AVRDigitalOutu80(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\ (uint8) in2, (uint8) in3); +#define d0d0u80AVRDigitalOutu80(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\ + (uint8) in2, (uint8) in3); + + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/c/hardware/avr/interfaces/int_AVRUtil.h b/src/c/hardware/avr/interfaces/int_AVRUtil.h index ce96951..2d6bbef 100644 --- a/src/c/hardware/avr/interfaces/int_AVRUtil.h +++ b/src/c/hardware/avr/interfaces/int_AVRUtil.h @@ -14,7 +14,7 @@ extern "C" { #endif -#define d0sleepu80(in1) U16AVRSleeps ((uint16) in1); +#define d0sleepu80(in1) u16AVRSleeps ((uint16) in1); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/c/hardware/avr/pwm/u8AVRADCSetups.c b/src/c/hardware/avr/pwm/u8AVRADCSetups.c new file mode 100644 index 0000000..cd1d12b --- /dev/null +++ b/src/c/hardware/avr/pwm/u8AVRADCSetups.c @@ -0,0 +1,56 @@ +// Function to initialise PWM of AVR +// +// Calling Sequence +// u8AVRPWMSetups(uint8 timer, uint8 prescalar, uint8 waveform_mode, uint8 output_mode) +// +// Parameters +// timer: timer to be used for PWM generation (0,1,2) +// prescalar: prescalar to be used for generating PWM waveform (0-7) +// waveform_mode: decides type of waveform generation +// 0 -> Normal mode +// 1 -> Phase correct mode +// 2 -> CTC mode +// 3 -> Fase PWM mode +// output_mode: decides the compare output mode. (0-3) +// behaviour of the output is different for different inputs +// depending upon 'waveform_mode' chosen. +// ***Refer datasheet for more description about above modes +// +// Description +// This function initialises PWM of AVR with given parameters. 'timer' +// decides which of the three (0,1,2) timers available to be used. The +// 'prescalar' is needed for deciding PWM clock. Select appropriate prescalar +// depending on MCU clock. Choose required pwmmode using 'waveform_generation' +// and 'output_mode'. Please refer datasheet for more description of 'wafefom_mode' +// and 'output mode'. +// Examples +// AVRPWMSetup(0,1,2,2) +// +// Authors +// Siddhesh Wani +// + +#include "AVRPeripheralPWM.h" + + +uint8 u8AVRPWMSetups(uint8 timer, uint8 prescalar, uint8 waveform_mode, uint8 output_mode) +{ + switch(timer) + { + case 0: + TCCR0|= (prescalar & 0x07); //Select clock source + //Select waveform generation mode + TCCR0|= ((waveform_mode & 0x04) << 4); + //Select compare output mode + TCCR0 |= ((output_mode & 0x01) << 3); //WGM0 + TCCR0 |= ((output_mode & 0x02) << 6); //WGM1 + break; + case 1: + break; + case 2: + break; + } + + return 0; +} + diff --git a/src/c/hardware/avr/util/U16AVRSleeps.c b/src/c/hardware/avr/util/U16AVRSleeps.c deleted file mode 100644 index f214471..0000000 --- a/src/c/hardware/avr/util/U16AVRSleeps.c +++ /dev/null @@ -1,14 +0,0 @@ -//Function to introduce specific delay in milliseconds -// -//Authors -// Siddhesh Wani -// - -#include "AVRUtil.h" - -uint8 U16AVRSleeps (uint16 delay) -{ - _delay_ms(delay); - - retrun 0; -} diff --git a/src/c/hardware/avr/util/u16AVRSleeps.c b/src/c/hardware/avr/util/u16AVRSleeps.c new file mode 100644 index 0000000..4d81c96 --- /dev/null +++ b/src/c/hardware/avr/util/u16AVRSleeps.c @@ -0,0 +1,14 @@ +//Function to introduce specific delay in milliseconds +// +//Authors +// Siddhesh Wani +// + +#include "AVRUtil.h" + +uint8 u16AVRSleeps (uint16 delay) +{ + _delay_ms(delay); + + return 0; +} diff --git a/src/c/scilab-arduino/default_files/Makefile b/src/c/scilab-arduino/default_files/Makefile index 2b888f0..5432fcf 100644 --- a/src/c/scilab-arduino/default_files/Makefile +++ b/src/c/scilab-arduino/default_files/Makefile @@ -4,7 +4,7 @@ ARDUINO_DIR = /usr/share/arduino ARDMK_DIR = /usr/share/arduino AVR_TOOLS_DIR = /usr BOARD_TAG = uno -USER_LIB_PATH = ../../ -ARDUINO_LIBS = src/c includes interfaces ../Temp +USER_LIB_PATH = ../ +ARDUINO_LIBS = ../src/c ../includes ../interfaces ../ ARDUINO_PORT = /dev/ttyACM0 include /usr/share/arduino/Arduino.mk -- cgit