diff options
22 files changed, 300 insertions, 36 deletions
diff --git a/macros/CCodeGeneration/C_GenerateFunName.bin b/macros/CCodeGeneration/C_GenerateFunName.bin Binary files differindex 6551c7f..4f3c591 100644 --- a/macros/CCodeGeneration/C_GenerateFunName.bin +++ b/macros/CCodeGeneration/C_GenerateFunName.bin diff --git a/macros/CCodeGeneration/C_GenerateFunName.sci b/macros/CCodeGeneration/C_GenerateFunName.sci index 9d40d2b..657258a 100644 --- a/macros/CCodeGeneration/C_GenerateFunName.sci +++ b/macros/CCodeGeneration/C_GenerateFunName.sci @@ -23,22 +23,30 @@ function CFunName = C_GenerateFunName(FunctionName,InArg,NInArg,OutArg,NOutArg) // ------------------------------ SCI2CNInArgCheck(argn(2),5,5); CFunName = ''; +if(IsAVRSupportFunction(FunctionName)) +//If current function is an AVR function, then function name can be just plain +//function name without any input/output arguments types -for tmpcnt = 1:NInArg - if (InArg(tmpcnt).Dimension == 1) - CFunName = CFunName+InArg(tmpcnt).Type+'2'; - else - CFunName = CFunName+InArg(tmpcnt).Type+SCI2Cstring(InArg(tmpcnt).Dimension); - end -end + CFunName = CFunName+FunctionName; + +else + + for tmpcnt = 1:NInArg + if (InArg(tmpcnt).Dimension == 1) + CFunName = CFunName+InArg(tmpcnt).Type+'2'; + else + CFunName = CFunName+InArg(tmpcnt).Type+SCI2Cstring(InArg(tmpcnt).Dimension); + end + end -CFunName = CFunName+FunctionName; + CFunName = CFunName+FunctionName; -for tmpcnt = 1:NOutArg - if (OutArg(tmpcnt).Dimension == 1) - CFunName = CFunName+OutArg(tmpcnt).Type+'2'; - else - CFunName = CFunName+OutArg(tmpcnt).Type+SCI2Cstring(OutArg(tmpcnt).Dimension); - end + for tmpcnt = 1:NOutArg + if (OutArg(tmpcnt).Dimension == 1) + CFunName = CFunName+OutArg(tmpcnt).Type+'2'; + else + CFunName = CFunName+OutArg(tmpcnt).Type+SCI2Cstring(OutArg(tmpcnt).Dimension); + end + end end endfunction diff --git a/macros/Hardware/AVR/AVRTimerSetup.bin b/macros/Hardware/AVR/AVRTimerSetup.bin Binary files differindex 65e8f45..4a49b86 100644 --- a/macros/Hardware/AVR/AVRTimerSetup.bin +++ b/macros/Hardware/AVR/AVRTimerSetup.bin diff --git a/macros/Hardware/AVR/AVRTimerSetup.sci b/macros/Hardware/AVR/AVRTimerSetup.sci index 6316cdd..1529c34 100644 --- a/macros/Hardware/AVR/AVRTimerSetup.sci +++ b/macros/Hardware/AVR/AVRTimerSetup.sci @@ -6,7 +6,7 @@ function AVRTimerSetup(timer, prescalar) // // Parameters // timer: timer to be set up (0,1,2) -// prescalar: prescalar to be used for generating PWM waveform (0-7) +// prescalar: prescalar to be used for timer (0-7) // ***Refer datasheet for more description about timer // // Description diff --git a/macros/Hardware/AVR/AVRUARTSetup.sci b/macros/Hardware/AVR/AVRUARTSetup.sci new file mode 100644 index 0000000..1529c34 --- /dev/null +++ b/macros/Hardware/AVR/AVRUARTSetup.sci @@ -0,0 +1,31 @@ +function AVRTimerSetup(timer, prescalar) +// Function to set the prescalar for timer. +// +// Calling Sequence +// AVRTimerSetup(timer, prescalar) +// +// Parameters +// timer: timer to be set up (0,1,2) +// prescalar: prescalar to be used for timer (0-7) +// ***Refer datasheet for more description about timer +// +// Description +// This function sets prescalr for timers. 'timer' decides which of the +// three (0,1,2) timers available to be used. The 'prescalar' is needed for +// deciding timer clock. Select appropriate prescalar depending on MCU clock +// and requirement. +// +// +// Examples +// AVRTimerSetup(0,1) //Timer 0 with no scaling +// +// See also +// AVRGetTimerValue +// +// 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/GetAVRSupportFunctions.bin b/macros/Hardware/AVR/GetAVRSupportFunctions.bin Binary files differindex eed8be3..0aa7587 100644 --- a/macros/Hardware/AVR/GetAVRSupportFunctions.bin +++ b/macros/Hardware/AVR/GetAVRSupportFunctions.bin diff --git a/macros/Hardware/AVR/GetAVRSupportFunctions.sci b/macros/Hardware/AVR/GetAVRSupportFunctions.sci index 50a913f..cce49f9 100644 --- a/macros/Hardware/AVR/GetAVRSupportFunctions.sci +++ b/macros/Hardware/AVR/GetAVRSupportFunctions.sci @@ -11,6 +11,15 @@ function AVRSupportFunctions = GetAVRSupportFunctions() // Author: Siddhesh Wani // ----------------------------------------------------------------- -AVRSupportFunctions = ["AVRDigitalOut"]; +AVRSupportFunctions = [ + "AVRADCSetup" + "AVRDigitalIn" + "AVRDigitalOut" + "AVRDigitalSetup" + "AVRGetTimerValue" + "AVRPWMSetDuty" + "AVRPWMSetup" + "AVRReadADC" + "AVRTimerSetup"]; endfunction diff --git a/macros/Scilab-Arduino/GenerateSetupFunction.sci b/macros/Scilab-Arduino/GenerateSetupFunction.sci index db96e19..7322cea 100644 --- a/macros/Scilab-Arduino/GenerateSetupFunction.sci +++ b/macros/Scilab-Arduino/GenerateSetupFunction.sci @@ -4,7 +4,7 @@ SetupListFile = FileInfo.SetupListFile; load(SetupListFile,'SetupList'); -SetupArduinoFile = fullfile(FileInfo.CStyleOutCCCodeDir,'setup_arduino.c'); +SetupArduinoFile = fullfile(FileInfo.CStyleOutCCCodeDir,'setup_arduino.cpp'); C_SCI2CHeader(SetupArduinoFile); PrintStringInfo('#include ""setup_arduino.h""',SetupArduinoFile,'file','y'); diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin Binary files differindex be0c48f..2653039 100644 --- a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin +++ b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci index aa783b1..629b3ee 100644 --- a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci +++ b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci @@ -4267,8 +4267,8 @@ PrintStringInfo('OUT(1).SZ(2)= ''1''',ClassFileName,'file','y'); // --- Function List Class. ---
ClassFileName = fullfile(SCI2CLibCFLClsDir,ClassName+ExtensionCFuncListCls);
-PrintStringInfo('d0d0d0d0'+ArgSeparator+'u80',ClassFileName,'file','y');
-
+//PrintStringInfo('d0d0d0d0'+ArgSeparator+'u80',ClassFileName,'file','y');
+PrintStringInfo(''+ArgSeparator+'',ClassFileName,'file','y');
// --- Annotation Function And Function List Function. ---
FunctionName = 'AVRPWMSetup';
@@ -4292,8 +4292,8 @@ 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('d0d0'+ArgSeparator+'u80',ClassFileName,'file','y');
+PrintStringInfo(''+ArgSeparator+'',ClassFileName,'file','y');
// --- Annotation Function And Function List Function. ---
FunctionName = 'AVRPWMSetDuty';
diff --git a/macros/ToolInitialization/UpdateSCI2CInfo.sci b/macros/ToolInitialization/UpdateSCI2CInfo.sci index 445507b..253299a 100644 --- a/macros/ToolInitialization/UpdateSCI2CInfo.sci +++ b/macros/ToolInitialization/UpdateSCI2CInfo.sci @@ -61,7 +61,12 @@ FileInfo.Funct(funnumber).PfxP1WhileEpilFileName = fullfile(FileInfo.WorkingDir, FileInfo.Funct(funnumber).CPass1FreeFileName = fullfile(FileInfo.WorkingDir,funname,SharedInfo.NextCFunName+'_pass1free.c'); FileInfo.Funct(funnumber).CPass2FileName = fullfile(FileInfo.WorkingDir,funname,SharedInfo.NextCFunName+'_pass2.c'); FileInfo.Funct(funnumber).Pass1HeaderFileName = fullfile(FileInfo.WorkingDir,funname,SharedInfo.NextCFunName+'.h'); -FileInfo.Funct(funnumber).FinalCFileName = fullfile(FileInfo.OutCCCodeDir,SharedInfo.NextCFunName+'.c'); +if (SharedInfo.OutFormat == 'Arduino') +//In case of "Arduino" target, *.cpp files should be generated, not *.c files. + FileInfo.Funct(funnumber).FinalCFileName = fullfile(FileInfo.OutCCCodeDir,SharedInfo.NextCFunName+'.cpp'); +else + FileInfo.Funct(funnumber).FinalCFileName = fullfile(FileInfo.OutCCCodeDir,SharedInfo.NextCFunName+'.c'); +end FileInfo.Funct(funnumber).FinalHeaderFileName = fullfile(FileInfo.OutCCCodeDir,SharedInfo.NextCFunName+'.h'); FileInfo.Funct(funnumber).CInitVarsFileName = fullfile(FileInfo.WorkingDir,funname,SharedInfo.NextCFunName+'_initvars.c'); FileInfo.Funct(funnumber).CDeclarationFileName = fullfile(FileInfo.WorkingDir,funname,SharedInfo.NextCFunName+'_declarations.c'); diff --git a/macros/findDeps/getAllInterfaces.sci b/macros/findDeps/getAllInterfaces.sci index 8b5df6f..65ee174 100644 --- a/macros/findDeps/getAllInterfaces.sci +++ b/macros/findDeps/getAllInterfaces.sci @@ -135,7 +135,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_AVRPeripheralADC.h" + "src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h" "src/c/hardware/avr/interfaces/int_AVRUtil.h" ]; diff --git a/src/c/hardware/avr/includes/AVRPeripheralPWM.h b/src/c/hardware/avr/includes/AVRPeripheralPWM.h index 80b29f3..7371dd7 100644 --- a/src/c/hardware/avr/includes/AVRPeripheralPWM.h +++ b/src/c/hardware/avr/includes/AVRPeripheralPWM.h @@ -17,7 +17,7 @@ extern "C" { //Function prototypes uint8 u8AVRPWMSetups(uint8 timer, uint8 prescalar, uint8 waveform_mode, uint8 output_mode); -uint8 u8AVRPWMSetDuty(uint8 timer, uint8 duty); +uint8 u8AVRPWMSetDutys(uint8 timer, uint8 duty); #ifdef __cplusplus diff --git a/src/c/hardware/avr/includes/AVRPeripheralTimer.h b/src/c/hardware/avr/includes/AVRPeripheralTimer.h new file mode 100644 index 0000000..78b04aa --- /dev/null +++ b/src/c/hardware/avr/includes/AVRPeripheralTimer.h @@ -0,0 +1,27 @@ +//This file defines functions prototypes related to Timer. +// +// Authors +// Siddhesh Wani +// + +#ifndef __AVRPERIPHERALTIMER_H__ +#define __AVRPERIPHERALTIMER_H__ + +#include <avr/io.h> +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//Function prototypes +uint8 u8AVRTimerSetups(uint8 timer, uint8 prescalar); + +uint8 u8AVRGetTimerValue(uint8 timer); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALTIMER_H__ */ diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h index 0aafb8c..425b03f 100644 --- a/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h +++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h @@ -14,10 +14,10 @@ extern "C" { #endif -#define d0d0AVRADCSetupu80(in1,in2) u8AVRADCSetups((uint8) in1,\ +#define AVRADCSetup(in1,in2) u8AVRADCSetups((uint8) in1,\ (uint8) in2); -#define d0AVRReadADCu160(in1) u8AVRReadADCs((uint8) in1); +#define AVRReadADC(in1) u8AVRReadADCs((uint8) in1); #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 439532d..c034718 100644 --- a/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h +++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h @@ -14,19 +14,14 @@ extern "C" { #endif -#define d0d0d0AVRDigitalSetupu80(in1,in2,in3) u8AVRDigitalSetups((uint8) in1,\ +#define AVRDigitalSetup(in1,in2,in3) u8AVRDigitalSetups((uint8) in1,\ (uint8) in2, (uint8) in3); -#define d0d0AVRDigitalInu80(in1,in2) u8AVRDigitalIns((uint8) in1,\ - (uint8) in2); +#define AVRDigitalIn(in1,in2) u8AVRDigitalIns((uint8) in1, (uint8) in2); -#define d0d0d0AVRDigitalOutu80(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\ +#define AVRDigitalOut(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_AVRPeripheralPWM.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h index 7368619..2d5e5cb 100644 --- a/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h +++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h @@ -14,10 +14,10 @@ extern "C" { #endif -#define d0d0d0d0AVRPWMSetupu80(in1,in2) u8AVRPWMSetups((uint8) in1,\ +#define AVRPWMSetup(in1,in2,in3,in4) u8AVRPWMSetups((uint8) in1,\ (uint8) in2, (uint8) in3, (uint8) in4); -#define d0d0AVRPWMSetDuty(in1,in2) u8AVRPWMSetDutys((uint8) in1, (uint8) in2); +#define AVRPWMSetDuty(in1,in2) u8AVRPWMSetDutys((uint8) in1, (uint8) in2); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h new file mode 100644 index 0000000..b4b66ba --- /dev/null +++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h @@ -0,0 +1,25 @@ +//This file defines constants corresponding to gpios. +// +// Authors +// Siddhesh Wani +// + +#ifndef __INT_AVRPERIPHERALTIMER_H__ +#define __INT_AVRPERIPHERALTIMER_H__ + +#include <avr/io.h> +#include "AVRPeripheralTimer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AVRTimerSetup(in1,in2) u8AVRTimerSetups((uint8) in1, (uint8) in2); + +#define AVRGetTimerValue(in1) u8AVRGetTimerValues((uint8) in1); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALADC_H__ */ diff --git a/src/c/hardware/avr/timer/u8AVRGetTimerValues.c b/src/c/hardware/avr/timer/u8AVRGetTimerValues.c new file mode 100644 index 0000000..c542c18 --- /dev/null +++ b/src/c/hardware/avr/timer/u8AVRGetTimerValues.c @@ -0,0 +1,37 @@ +// 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 +// Siddhesh Wani +// + + +#include "AVRPeripheralTimer.h" + + +uint8 u8AVRGetTimerValues(uint8 timer) +{ + switch(timer) + { + case 0: + return TCNT0; + + case 1: + break; + case 2: + return TCNT2; + } + + return 0; +} + diff --git a/src/c/hardware/avr/timer/u8AVRTimerSetups.c b/src/c/hardware/avr/timer/u8AVRTimerSetups.c new file mode 100644 index 0000000..1d93429 --- /dev/null +++ b/src/c/hardware/avr/timer/u8AVRTimerSetups.c @@ -0,0 +1,42 @@ +// Function to setup timer on AVR +// +// Calling Sequence +// u8AVRTimerSetups(timer, prescalar) +// +// Parameters +// timer: timer to be set up (0,1,2) +// prescalar: prescalar to be used for timer (0-7) +// ***Refer datasheet for more description about timer +// +// Description +// This function sets prescalr for timers. 'timer' decides which of the +// three (0,1,2) timers available to be used. The 'prescalar' is needed for +// deciding timer clock. Select appropriate prescalar depending on MCU clock +// and requirement. +// +// +// Authors +// Siddhesh Wani +// + + +#include "AVRPeripheralTimer.h" + + +uint8 u8AVRTimerSetups(uint8 timer,uint8 prescalar) +{ + switch(timer) + { + case 0: + TCCR0|= (prescalar & 0x07); //Select clock source + break; + case 1: + break; + case 2: + TCCR2|= (prescalar & 0x07); //Select clock source + break; + } + + return 0; +} + diff --git a/src/c/hardware/avr/uart/u8AVRUARTSetups.c b/src/c/hardware/avr/uart/u8AVRUARTSetups.c new file mode 100644 index 0000000..f311500 --- /dev/null +++ b/src/c/hardware/avr/uart/u8AVRUARTSetups.c @@ -0,0 +1,84 @@ +// Function to initialise uart interface of AVR +// +// Calling Sequence +// u8AVRUARTSetups(uint8 mode, uint8 baudrate, uint8 stopbits, uint8 parity) +// +// Parameters +// mode : Mode of usart interface (0-Normal mode, 1-Double speed mode, +// 2-Synchronous master mode) +// baudrate : Baudrate for communication. Refer AVRPeripheralUART.h +// for available options) +// stopbits : No. of stopbits (0-1) for stopbits 1 and 2 resp. +// parity: set parity bit. (0-disabled, 1-Even parity, 2-Odd parity) +// +// +// Description +// This function initialises uart interface for AVR. Available modes are +// Normal mode (0), Double speed mode (1), Synchronous master mode(2). 'baudrate' +// decides baudrate for communication. For baudrate settings, variable +// 'XTAL_FREQUENCY' is required. 'stopbits' sets no of stopbits for data +// packet. 0 for 1 stopbit and 1 for 2 stopbits. 'parity' decides parity bit +// for communication. 0 for disabling parity bit, 1 for even parity and 2 +// for odd parity. +// +// Authors +// Siddhesh Wani +// + +#include "AVRPeripheralUART.h" + +uint8 u8AVRUARTSetups(uint8 mode, uint8 baudrate, uint8 stopbits, uint8 parity) +{ + switch (mode) //According to mode set bits UMSEL and U2X + { + case 0: //Normal mode + UCSRC &= ~(1<<6); //Clear bit 6 UMSEL + break; + + case 1: //Double speed mode + UCSRC &= ~(1<<6); //Clear bit 6 UMSEL + break; + + case 2: //Synchronous master mode + UCSRC |= (1<<6); //Set bit 6 UMSEL + break; + } + + if(stopbits == 0) + { // 1 stopbit + UCSRC &= ~(1<<3); + } + else + { // 2 stopbits + UCSRC |= (1<<3); + } + + //Set parity bit settings + switch(parity) + { + case 0: // Parity disabled + UCSRC &= ~(3<<4); //UPM1:0=0 + break; + case 1:// Even parity + UCSRC |= (1<<5); //UPM1:0 = 2 + UCSRC &= ~(1<<4); + break; + case 2:// Odd parity + UCSRC |= (1<<5); //UPM1:1 = 3 + UCSRC |= (1<<4); + break; + } + + //Set baud rate + # define BAUD baudrate + #include "util/setbaud.h" + UBRRH = UBRRH_VALUE; + UBRRL = UBRRL_VALUE; + #if USE_2X + UCSRA |= (1 << U2X); + #else + UCSRA &= ~(1 << U2X); + #endif + return 0; +} + diff --git a/src/c/scilab-arduino/cmd_digital_out/u8cmd_digital_outs.c b/src/c/scilab-arduino/cmd_digital_out/u8cmd_digital_outs.c index 09dffd6..621afc8 100644 --- a/src/c/scilab-arduino/cmd_digital_out/u8cmd_digital_outs.c +++ b/src/c/scilab-arduino/cmd_digital_out/u8cmd_digital_outs.c @@ -12,6 +12,7 @@ #include "cmd_digital_out.h" + uint8 u8cmd_digital_outs(uint8 board_no, uint8 pin, uint8 value) { digitalWrite(pin,value); |