diff options
71 files changed, 1340 insertions, 399 deletions
diff --git a/etc/scilab2c.start b/etc/scilab2c.start index 47554ab..6925900 100644 --- a/etc/scilab2c.start +++ b/etc/scilab2c.start @@ -20,7 +20,8 @@ sci2c_GenFunctionslib = lib(pathmacros + "GeneralFunctions" + filesep()); sci2c_SymbolTablelib = lib(pathmacros + "SymbolTable" + filesep()); sci2c_ToolInitlib = lib(pathmacros + "ToolInitialization" + filesep()); sci2c_finDeps = lib(pathmacros + "findDeps" + filesep()); -sci2c_AVRlib = lib(pathmacros + "Hardware\AVR" + filesep()); +sci2c_AVRlib = lib(pathmacros + "Hardware\AVR" + filesep()); +sci2c_ScilabArduinolib = lib(pathmacros + "Scilab-Arduino" + filesep()); clear pathmacros; // Load and add help chapter diff --git a/includes/sci2clib.h b/includes/sci2clib.h index b9820bc..3dc5820 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" @@ -339,17 +339,23 @@ #include "cmd_analog_out.h" #include "int_cmd_analog_in.h" #include "cmd_analog_in.h" +#include "int_cmd_dcmotor.h" +#include "cmd_dcmotor_run.h" +#include "cmd_dcmotor_setup.h" #include "int_sleep.h" #include "sleep.h" #endif /*AVR*/ -#ifdef AVR +#ifdef AVR1 #include "int_AVRPeripheralGPIO.h" #include "AVRPeripheralGPIO.h" #include "int_AVRPeripheralADC.h" #include "AVRPeripheralADC.h" - +#include "int_AVRPeripheralPWM.h" +#include "AVRPeripheralPWM.h" +#include "int_AVRUtil.h" +#include "AVRUtil.h" #endif #endif /* !__SCI2CLIB_H__ */ diff --git a/macros/ASTManagement/AST_HandleEndGenFun.bin b/macros/ASTManagement/AST_HandleEndGenFun.bin Binary files differindex 8b3ce65..d5d2e4a 100644 --- a/macros/ASTManagement/AST_HandleEndGenFun.bin +++ b/macros/ASTManagement/AST_HandleEndGenFun.bin diff --git a/macros/ASTManagement/AST_HandleEndGenFun.sci b/macros/ASTManagement/AST_HandleEndGenFun.sci index f9515cd..f6ae58e 100644 --- a/macros/ASTManagement/AST_HandleEndGenFun.sci +++ b/macros/ASTManagement/AST_HandleEndGenFun.sci @@ -46,7 +46,11 @@ ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; Pass1HeaderFileName = FileInfo.Funct(nxtscifunnumber).Pass1HeaderFileName; FunInfoDatDir = FileInfo.FunctionList.FunInfoDatDir; CGblDeclarFileName = FileInfo.Funct(nxtscifunnumber).CGblDeclarFileName; -PeripheralInitListFile = FileInfo.PeripheralInitListFile; +if(SharedInfo.OutFormat == 'AVR') + PeripheralInitListFile = FileInfo.PeripheralInitListFile; +elseif (SharedInfo.OutFormat == 'Arduino') + SetupListFile = FileInfo.SetupListFile; +end Flag_FunAlreadyCalled = 0; // #RNU_RES_B @@ -67,382 +71,395 @@ global STACKDEDUG //NUT: verifica se ASTFunType e' veramente importante // #RNU_RES_E [ASTFunName,InArg,NInArg,OutArg,NOutArg] = AST_GetFuncallPrm(FileInfo,SharedInfo,ASTFunType); -if (ASTFunName == 'OpIns') - SharedInfo.SkipNextEqual = 1; - SharedInfo.Equal.Nins = SharedInfo.Equal.Nins + 1; - //NUT: Force ins to have 0 args. Double check it. - NOutArg = 0; - // #RNU_RES_B - //NUT: io aumenterei qui gli argomenti in ingresso della ins cosi qui vengono fatte tutte le modifiche del - //NUT: caso e la C_FunCall non se ne deve preoccupare, vedi se lo stesso vale per le altre funzioni - //NUT: speciali presenti nell C_FunCall. - - // 1 more input argument containing the values to be inserted in the matrix. - // #RNU_RES_E - NInArg = NInArg + 1; - InArg(NInArg).Name = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Name; - InArg(NInArg).Scope = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Scope; -elseif (ASTFunName == 'global') - SharedInfo.SkipNextEqual = 1; - SharedInfo.SkipNextFun = 1; - if (NInArg ~= 1) - PrintStringInfo(' ',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: Multiple declaration of global variables is not allowed.',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: See example below:',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: global var1 var2; //NOT ALLOWED',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: global var1; //ALLOWED',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: global var2; //ALLOWED',ReportFileName,'both','y'); - PrintStringInfo(' ',ReportFileName,'both','y'); - error(9999, 'SCI2CERROR: Multiple declaration of global variables is not allowed.'); - end - if (NOutArg ~= 1) - PrintStringInfo(' ',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: Unexpected number of output arguments for global function.',ReportFileName,'both','y'); - PrintStringInfo('SCI2CERROR: Please report this error to: http://forge.scilab.org/index.php/p/scilab2c/issues/',ReportFileName,'both','y'); - PrintStringInfo(' ',ReportFileName,'both','y'); - error(9999, 'SCI2CERROR: Unexpected number of output arguments for global function.'); - end -//elseif(IsAVRSupportFunction(ASTFunName)) - //Get the peripheral from function name and input arguements, insert it in - //list of used peripherals. - // PeripheralUsed=GetPeripheral(ASTFunName,InArg); - // InsertPeripheralInList(PeripheralUsed,PeripheralInitListFile); -end -// #RNU_RES_B -// -------------------------------------- -// --- Read the function annotations. --- -// -------------------------------------- -// #RNU_RES_E -if (ASTFunName == 'OpEqual') - FunTypeAnnot = ''; - FunSizeAnnot = ''; -else - [FunTypeAnnot,FunSizeAnnot] = FA_GetFunAnn(NInArg,NOutArg,ASTFunName,FileInfo,SharedInfo); -end + if (ASTFunName == 'OpIns') + SharedInfo.SkipNextEqual = 1; + SharedInfo.Equal.Nins = SharedInfo.Equal.Nins + 1; + //NUT: Force ins to have 0 args. Double check it. + NOutArg = 0; + // #RNU_RES_B + //NUT: io aumenterei qui gli argomenti in ingresso della ins cosi qui vengono fatte tutte le modifiche del + //NUT: caso e la C_FunCall non se ne deve preoccupare, vedi se lo stesso vale per le altre funzioni + //NUT: speciali presenti nell C_FunCall. -// #RNU_RES_B -// ------------------------------------------------------------------------------------------- -// --- Search for Equal Lhs and precision specifier to be applied to the current function. --- -// ------------------------------------------------------------------------------------------- -// #RNU_RES_E -[LhsArg,NLhsArg,FunPrecSpecifier,SharedInfo] = AST_GetPrecAndLhsArg(OutArg,NOutArg,ASTFunName,FunTypeAnnot,FunSizeAnnot,ASTFunType,FileInfo,SharedInfo); -//NUT: questa funzione contiene troppi parametri e mi sembra disordinata. + // 1 more input argument containing the values to be inserted in the matrix. + // #RNU_RES_E + NInArg = NInArg + 1; + InArg(NInArg).Name = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Name; + InArg(NInArg).Scope = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Scope; + elseif (ASTFunName == 'global') + SharedInfo.SkipNextEqual = 1; + SharedInfo.SkipNextFun = 1; + if (NInArg ~= 1) + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Multiple declaration of global variables is not allowed.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: See example below:',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: global var1 var2; //NOT ALLOWED',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: global var1; //ALLOWED',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: global var2; //ALLOWED',ReportFileName,'both','y'); + PrintStringInfo(' ',ReportFileName,'both','y'); + error(9999, 'SCI2CERROR: Multiple declaration of global variables is not allowed.'); + end + if (NOutArg ~= 1) + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Unexpected number of output arguments for global function.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Please report this error to: http://forge.scilab.org/index.php/p/scilab2c/issues/',ReportFileName,'both','y'); + PrintStringInfo(' ',ReportFileName,'both','y'); + error(9999, 'SCI2CERROR: Unexpected number of output arguments for global function.'); + end + //elseif(IsAVRSupportFunction(ASTFunName)) + //Get the peripheral from function name and input arguements, insert it in + //list of used peripherals. + // PeripheralUsed=GetPeripheral(ASTFunName,InArg); + // InsertPeripheralInList(PeripheralUsed,PeripheralInitListFile); + end -// #RNU_RES_B -// -------------------------------- -// --- Input Arguments Section. --- -// -------------------------------- -// --- Get Input Arguments info from their numerical value or from the symbol table. --- -// #RNU_RES_E -if (ASTFunName == 'global') - [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ... - ST_GetSymbolInfo(InArg(1).Name,FileInfo,SharedInfo); - if (TBFlagfound == 1) - InArg(1).Type = TBType; - InArg(1).Size = TBSize; - InArg(1).Value = TBValue; - InArg(1).FindLike = TBFindLike; - InArg(1).Dimension = TBDimension; - InArg(1).Scope = TBScope; - IndentLevelGlobal = 0; //NUT: forced always to 1 - FlagExt = 1; - C_GenDeclarations(InArg(1),CGblDeclarFileName,IndentLevelGlobal,ReportFileName,FlagExt,SharedInfo.ResizeApproach); - else - // #RNU_RES_B - // That means it is the first time we encounter - // this global variable and in C this means that - // we don't have to do nothing. - // #RNU_RES_E - // SharedInfo.SkipNextFun = SharedInfo.SkipNextFun + 1; - SharedInfo.SkipNextFun = 1; - - InArg(1).Type = 'GBLToBeDefined'; - InArg(1).Size(1) = 'GBLToBeDefined'; - InArg(1).Size(2) = 'GBLToBeDefined'; - InArg(1).Value = %nan; - InArg(1).FindLike = %nan; - InArg(1).Dimension = %nan; - InArg(1).Scope = 'Global'; - - // #RNU_RES_B - PrintStringInfo('***Putting global variable in the symbol table***',ReportFileName,'file','y'); - PrintStringInfo(' Symbol ""'+InArg(1).Name+'""',ReportFileName,'file','y'); - - PrintStringInfo(' Type: '+InArg(1).Type,ReportFileName,'file','y'); - PrintStringInfo(' Size(1): '+string(InArg(1).Size(1)),ReportFileName,'file','y'); - PrintStringInfo(' Size(2): '+string(InArg(1).Size(2)),ReportFileName,'file','y'); - PrintStringInfo(' Value: '+string(InArg(1).Value),ReportFileName,'file','y'); - PrintStringInfo(' FindLike: '+string(InArg(1).FindLike),ReportFileName,'file','y'); - PrintStringInfo(' Dimension: '+string(InArg(1).Dimension),ReportFileName,'file','y'); - PrintStringInfo(' Scope: '+string(InArg(1).Scope),ReportFileName,'file','y'); - PrintStringInfo(' ',ReportFileName,'file','y'); - // #RNU_RES_E - - ST_Set(InArg(1).Name,... - InArg(1).Type,... - InArg(1).Size,... - InArg(1).Value,... - InArg(1).FindLike,... - InArg(1).Dimension,... - FileInfo.GlobalVarFileName); - end -else - [InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo); -end + // #RNU_RES_B + // -------------------------------------- + // --- Read the function annotations. --- + // -------------------------------------- + // #RNU_RES_E + if (ASTFunName == 'OpEqual') + FunTypeAnnot = ''; + FunSizeAnnot = ''; + else + [FunTypeAnnot,FunSizeAnnot] = FA_GetFunAnn(NInArg,NOutArg,ASTFunName,FileInfo,SharedInfo); + end -// #RNU_RES_B -// ------------------------------------------------------------------- -// --- Change info of Input Argument according to resize approach. --- -// ------------------------------------------------------------------- -//RNU toglimi nella versione da dare ad hartes. -//RNU per ora gestisco solo la resize all con tutte realloc. -//RNU global variables are still coded with fixed size. -// #RNU_RES_E -if (SharedInfo.ResizeApproach=='REALLOC_ALL_RESIZE_ALL') - for cntin = 1:NInArg - if ((InArg(cntin).Dimension > 0)) - // if ((InArg(cntin).Dimension > 0) & (InArg(cntin).Scope ~= 'Global')) - InArg(cntin).Size(1) = '__'+InArg(cntin).Name+'Size[0]'; - InArg(cntin).Size(2) = '__'+InArg(cntin).Name+'Size[1]'; - end - //#RNUREM_MERNU vedi se la seguente fa casino l'ho aggiunta in modo che agia=ones(1,3) sia generata come realloc ma non ho verificato. - tmpscope = InArg(cntin).Scope; - lengthNumber = length('Number_'); - if (part(tmpscope,1:lengthNumber) == 'Number_') - //#RNUREM_ME RNU il problema e' che ones(3,1) allora l'output e' 3,1 e come faccio a trasformare 3 e 1 in simboli in modo tale che realloco anziche' allocare - InArg(cntin).Value = %nan; //RNU non va bene dove per esempio hai problemi di 1:3:4 se al posto dei numeri metti nan ti impalli - //#RNUREM_ME Credo che dove c'e' uan allocazione secca ones(3,1) non vada lasciata cosi' ma tutto vada ricondotto a realloc - //#RNUREM_ME quindi devo vedere nella dichiarazione delle variabili come forzare la dichiarazione dei null pointer. - //#RNUREM_ME successivamente devo vedere come fare a riscrivere la size dell'output. - else - end - end -end + // #RNU_RES_B + // ------------------------------------------------------------------------------------------- + // --- Search for Equal Lhs and precision specifier to be applied to the current function. --- + // ------------------------------------------------------------------------------------------- + // #RNU_RES_E + [LhsArg,NLhsArg,FunPrecSpecifier,SharedInfo] = AST_GetPrecAndLhsArg(OutArg,NOutArg,ASTFunName,FunTypeAnnot,FunSizeAnnot,ASTFunType,FileInfo,SharedInfo); + //NUT: questa funzione contiene troppi parametri e mi sembra disordinata. -// #RNU_RES_B -// --------------------------------- -// --- Output Arguments Section. --- -// --------------------------------- -// --- Update Out arg structure with info stored in the function annotations. --- -// #RNU_RES_E -if (ASTFunName == 'OpEqual') - for cntin = 1:NInArg - OutArg(cntin).Type = InArg(cntin).Type; - OutArg(cntin).Size = InArg(cntin).Size; - OutArg(cntin).Dimension = InArg(cntin).Dimension; - OutArg(cntin).Value = InArg(cntin).Value; - OutArg(cntin).FindLike = InArg(cntin).FindLike; - //NUT: forse qui occorre aggiungere lo scope che dovrebbe essere local or global. - //NUT: per ora lo scope viene settato da AST_ParseEqualStruct - end -elseif ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0)&(InArg(1).Scope == 'Number')) - // #RNU_RES_B - // --- Manage OpMinus when applied to scalars. --- - // -1 is not translated as tmp = OpMinus(1), but - // it is considered as a single entity "-1" - // #RNU_RES_E - SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI - OutArg(1).Type = InArg(1).Type; - OutArg(1).Size = InArg(1).Size; - OutArg(1).Dimension = InArg(1).Dimension; - OutArg(1).Value = -InArg(1).Value; - OutArg(1).FindLike = InArg(1).FindLike; - OutArg(1).Scope = 'Number_'+InArg(1).Type; -elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - // #RNU_RES_B - // --- Manage OpMinus when applied to scalars. --- - // -1 is not translated as tmp = OpMinus(1), but - // it is considered as a single entity "-1" - // #RNU_RES_E - SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI - OutArg(1).Type = InArg(1).Type; - OutArg(1).Size = InArg(1).Size; - OutArg(1).Dimension = InArg(1).Dimension; - OutArg(1).Value = InArg(1).Value; - OutArg(1).FindLike = InArg(1).FindLike; - OutArg(1).Scope = 'Number_s'; -elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - // #RNU_RES_B - // --- Manage OpMinus when applied to scalars. --- - // -1 is not translated as tmp = OpMinus(1), but - // it is considered as a single entity "-1" - // #RNU_RES_E - SharedInfo.SkipNextFun = 1; - //RN: SISTEMAMI - SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI - OutArg(1).Type = InArg(1).Type; - OutArg(1).Size = InArg(1).Size; - OutArg(1).Dimension = InArg(1).Dimension; - OutArg(1).Value = InArg(1).Value; - OutArg(1).FindLike = InArg(1).FindLike; - OutArg(1).Scope = 'Number_d'; -else - OutArg = FA_GetOutArgInfo(InArg,NInArg,OutArg,NOutArg,SharedInfo,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,ReportFileName); -end + // #RNU_RES_B + // -------------------------------- + // --- Input Arguments Section. --- + // -------------------------------- + // --- Get Input Arguments info from their numerical value or from the symbol table. --- + // #RNU_RES_E + if (ASTFunName == 'global') + [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ... + ST_GetSymbolInfo(InArg(1).Name,FileInfo,SharedInfo); + if (TBFlagfound == 1) + InArg(1).Type = TBType; + InArg(1).Size = TBSize; + InArg(1).Value = TBValue; + InArg(1).FindLike = TBFindLike; + InArg(1).Dimension = TBDimension; + InArg(1).Scope = TBScope; + IndentLevelGlobal = 0; //NUT: forced always to 1 + FlagExt = 1; + C_GenDeclarations(InArg(1),CGblDeclarFileName,IndentLevelGlobal,ReportFileName,FlagExt,SharedInfo.ResizeApproach); + else + // #RNU_RES_B + // That means it is the first time we encounter + // this global variable and in C this means that + // we don't have to do nothing. + // #RNU_RES_E + // SharedInfo.SkipNextFun = SharedInfo.SkipNextFun + 1; + SharedInfo.SkipNextFun = 1; -// #RNU_RES_B -// --- Generate the names for the output arguments. --- -// Update of OutArg.Name and OutArg.Scope fields. -// #RNU_RES_E -if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - OutArg(1).Name = string(OutArg(1).Value); -elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - OutArg(1).Name = string(OutArg(1).Value); -elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - OutArg(1).Name = string(OutArg(1).Value); -else - [OutArg,SharedInfo] = GenOutArgNames(ASTFunName,InArg,NInArg,OutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo); -end + InArg(1).Type = 'GBLToBeDefined'; + InArg(1).Size(1) = 'GBLToBeDefined'; + InArg(1).Size(2) = 'GBLToBeDefined'; + InArg(1).Value = %nan; + InArg(1).FindLike = %nan; + InArg(1).Dimension = %nan; + InArg(1).Scope = 'Global'; -// #RNU_RES_B -// --- Push in the AST stack the Output arguments. --- -// #RNU_RES_E -if (ASTFunName == 'OpEqual') - // Do nothing -else - for counteroutargs = 1:NOutArg - tmppushstack = OutArg(counteroutargs).Scope+': '+OutArg(counteroutargs).Name; - // #RNU_RES_B - PrintStringInfo(' Pushing in the AST stack: ""'+tmppushstack+'"".',ReportFileName,'file','y'); - // #RNU_RES_E - AST_PushASTStack(tmppushstack); - end -end + // #RNU_RES_B + PrintStringInfo('***Putting global variable in the symbol table***',ReportFileName,'file','y'); + PrintStringInfo(' Symbol ""'+InArg(1).Name+'""',ReportFileName,'file','y'); -// #RNU_RES_B -//NUT: verificare se si puo' accorpare qualcosa qui sotto -//RN: non capisco come mai analizzo lo scope dopo che faccio il push nello stack dove lo utilizzo!!! -// --- Scope analysis of the output arguments. --- -// #RNU_RES_E -if (ASTFunName == 'OpMinus' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - // Scope already set above. -elseif (ASTFunName == 'float' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - // Scope already set above. -elseif (ASTFunName == 'double' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - // Scope already set above. -else - OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo); -end - -//#RNUREM_ME --- Check if the current function is handling for counter variables. --- -[OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo); - -//#RNUREM_ME --- Store the while condition variable (if any). --- -SharedInfo = GetWhileCondVariable(OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo); - -//#RNUREM_ME --- Update Symbol Table with output arguments. --- -if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - //#RNUREM_ME A number is not inserted in the symbol table. -elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - //#RNUREM_ME A number is not inserted in the symbol table. -elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) - //#RNUREM_ME A number is not inserted in the symbol table. -else - ST_InsOutArg(OutArg,NOutArg,FileInfo,SharedInfo,'all'); -end -//#RNUREM_ME NUT: per risparmiare tempo di esecuzione puoi mettere delle if sulle funzioni che devono -//#RNUREM_ME NUT: essere skippate. - -//#RNU_RES_B -// -------------------------------------------- -// --- Generate the C name of the function. --- -// -------------------------------------------- -//#RNU_RES_E - -CFunName = C_GenerateFunName(ASTFunName,InArg,NInArg,OutArg,NOutArg); -//#RNU_RES_B -PrintStringInfo(' C Function Name: '+CFunName,ReportFileName,'file','y'); -// ------------------------------------------------------------------------- -// --- Determine which library the function belongs to: USER2C or SCI2C. --- -// ------------------------------------------------------------------------- -//#RNU_RES_E -if SCI2Cfileexist(FileInfo.SCI2CLibCAnnFun,ASTFunName+'.ann') - LibTypeInfo = 'SCI2C'; -else - LibTypeInfo = 'USER2C'; -end - -//#RNU_RES_B -// ------------------------------------------------------------------------------------ -// --- Check whether the function has been already called in the current .sci file. --- -// ------------------------------------------------------------------------------------ -//#RNU_RES_E -if (sum(SharedInfo.CFunctsAlreadyCalled == CFunName) == 1) - Flag_FunAlreadyCalled = 1; -else - - //#RNUREM_ME Add the C function name to the list of C functions called in the current .sci file. - SharedInfo.CFunctsAlreadyCalled(size(SharedInfo.CFunctsAlreadyCalled,1)+1) = CFunName; -end - -//#RNU_RES_B -// ---------------------------------- -// --- Generate FunInfo dat file. --- -// ---------------------------------- -//NUT: questo .dat deve essere generato sempre perche' cambiano i nomi degli argomenti mentre il resto dovrebbe -//NUT: essere tutto uguale -//NUT: magari posso fare una funzione che inserisce solo i campi diversi e fa un check su quelli che -//NUT: dovrebbero essere identici. -//#RNU_RES_E -GenCFunDatFiles(ASTFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,CFunName,LibTypeInfo,FunInfoDatDir); - -//#RNU_RES_B -// ----------------------------------- -// --- Update SCI2C Function List. --- -// ----------------------------------- -// Functions that are not already available in C are stored -// in the SCI2C Function List and converted in C at the end of -// the translation of the current .sci file. -//NUT: il problema della d0d0OpEqual dovrebbe essere legato al fatto che cerco di fare la opequal legata alla ins... -//NUT: devo evitare di scriveral dentro la lsista delle funzioni da tradurre. -//#RNU_RES_E -SharedInfo = FL_UpdateToBeConv(ASTFunName,CFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,FileInfo,SharedInfo); - -//#RNU_RES_B -// ----------------------------------------------- -// --- Check on common input/output arguments. --- -// ----------------------------------------------- -//#RNU_RES_E -if (((ASTFunName=='OpEqual') & (SharedInfo.SkipNextEqual == 1)) | ... - SharedInfo.SkipNextFun > 0 | ... - ((sum(mtlb_strcmp(ASTFunName,SharedInfo.Annotations.DataPrec)) > 0) & (SharedInfo.SkipNextPrec == 1))) - // Do nothing -else - AST_CheckCommonInOutArgs(InArg,NInArg,OutArg,NOutArg,ReportFileName); -end - -//#RNU_RES_B -// ----------------------------- -// --- C Generation Section. --- -// ----------------------------- -// --- Load FunInfo structure. --- -//#RNU_RES_E -FunInfoDatFileName = fullfile(FunInfoDatDir,CFunName+'.dat'); -load(FunInfoDatFileName,'FunInfo'); - -//#RNU_RES_B -// --- Generate include. --- -//#RNU_RES_E -if ((Flag_FunAlreadyCalled == 0) & (FunInfo.LibTypeInfo == 'USER2C') & (SharedInfo.NextCFunName ~= CFunName)) - // (SharedInfo.NextCFunName ~= CFunName) I don't want an include in the same file. Ex. in main.h I don't want include "main.h" - // #RNU_RES_B - PrintStringInfo('Adding include',ReportFileName,'file','y'); - PrintStringInfo('#include ""'+CFunName+'.h""',... - ReportFileName,'file','y'); - // #RNU_RES_E - PrintStringInfo('#include ""'+CFunName+'.h""',... - Pass1HeaderFileName,'file','y'); -end - -//#RNU_RES_B -// --- Generate the C code for the current function. --- -//#RNU_RES_E -FlagCall = 1; -SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall); -//#RNU_RES_B -//NUT: anziche farla fare alla cfuncall l'aggiornamento delle skip metti qui una funzione dedicata a cio' -//NUT: e' piu' ordinato. -//#RNU_RES_E + PrintStringInfo(' Type: '+InArg(1).Type,ReportFileName,'file','y'); + PrintStringInfo(' Size(1): '+string(InArg(1).Size(1)),ReportFileName,'file','y'); + PrintStringInfo(' Size(2): '+string(InArg(1).Size(2)),ReportFileName,'file','y'); + PrintStringInfo(' Value: '+string(InArg(1).Value),ReportFileName,'file','y'); + PrintStringInfo(' FindLike: '+string(InArg(1).FindLike),ReportFileName,'file','y'); + PrintStringInfo(' Dimension: '+string(InArg(1).Dimension),ReportFileName,'file','y'); + PrintStringInfo(' Scope: '+string(InArg(1).Scope),ReportFileName,'file','y'); + PrintStringInfo(' ',ReportFileName,'file','y'); + // #RNU_RES_E + + ST_Set(InArg(1).Name,... + InArg(1).Type,... + InArg(1).Size,... + InArg(1).Value,... + InArg(1).FindLike,... + InArg(1).Dimension,... + FileInfo.GlobalVarFileName); + end + else + [InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo); + end + + // #RNU_RES_B + // ------------------------------------------------------------------- + // --- Change info of Input Argument according to resize approach. --- + // ------------------------------------------------------------------- + //RNU toglimi nella versione da dare ad hartes. + //RNU per ora gestisco solo la resize all con tutte realloc. + //RNU global variables are still coded with fixed size. + // #RNU_RES_E + if (SharedInfo.ResizeApproach=='REALLOC_ALL_RESIZE_ALL') + for cntin = 1:NInArg + if ((InArg(cntin).Dimension > 0)) + // if ((InArg(cntin).Dimension > 0) & (InArg(cntin).Scope ~= 'Global')) + InArg(cntin).Size(1) = '__'+InArg(cntin).Name+'Size[0]'; + InArg(cntin).Size(2) = '__'+InArg(cntin).Name+'Size[1]'; + end + //#RNUREM_MERNU vedi se la seguente fa casino l'ho aggiunta in modo che agia=ones(1,3) sia generata come realloc ma non ho verificato. + tmpscope = InArg(cntin).Scope; + lengthNumber = length('Number_'); + if (part(tmpscope,1:lengthNumber) == 'Number_') + //#RNUREM_ME RNU il problema e' che ones(3,1) allora l'output e' 3,1 e come faccio a trasformare 3 e 1 in simboli in modo tale che realloco anziche' allocare + InArg(cntin).Value = %nan; //RNU non va bene dove per esempio hai problemi di 1:3:4 se al posto dei numeri metti nan ti impalli + //#RNUREM_ME Credo che dove c'e' uan allocazione secca ones(3,1) non vada lasciata cosi' ma tutto vada ricondotto a realloc + //#RNUREM_ME quindi devo vedere nella dichiarazione delle variabili come forzare la dichiarazione dei null pointer. + //#RNUREM_ME successivamente devo vedere come fare a riscrivere la size dell'output. + else + end + end + end + + // #RNU_RES_B + // --------------------------------- + // --- Output Arguments Section. --- + // --------------------------------- + // --- Update Out arg structure with info stored in the function annotations. --- + // #RNU_RES_E + if (ASTFunName == 'OpEqual') + for cntin = 1:NInArg + OutArg(cntin).Type = InArg(cntin).Type; + OutArg(cntin).Size = InArg(cntin).Size; + OutArg(cntin).Dimension = InArg(cntin).Dimension; + OutArg(cntin).Value = InArg(cntin).Value; + OutArg(cntin).FindLike = InArg(cntin).FindLike; + //NUT: forse qui occorre aggiungere lo scope che dovrebbe essere local or global. + //NUT: per ora lo scope viene settato da AST_ParseEqualStruct + end + elseif ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0)&(InArg(1).Scope == 'Number')) + // #RNU_RES_B + // --- Manage OpMinus when applied to scalars. --- + // -1 is not translated as tmp = OpMinus(1), but + // it is considered as a single entity "-1" + // #RNU_RES_E + SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI + OutArg(1).Type = InArg(1).Type; + OutArg(1).Size = InArg(1).Size; + OutArg(1).Dimension = InArg(1).Dimension; + OutArg(1).Value = -InArg(1).Value; + OutArg(1).FindLike = InArg(1).FindLike; + OutArg(1).Scope = 'Number_'+InArg(1).Type; + elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + // #RNU_RES_B + // --- Manage OpMinus when applied to scalars. --- + // -1 is not translated as tmp = OpMinus(1), but + // it is considered as a single entity "-1" + // #RNU_RES_E + SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI + OutArg(1).Type = InArg(1).Type; + OutArg(1).Size = InArg(1).Size; + OutArg(1).Dimension = InArg(1).Dimension; + OutArg(1).Value = InArg(1).Value; + OutArg(1).FindLike = InArg(1).FindLike; + OutArg(1).Scope = 'Number_s'; + elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + // #RNU_RES_B + // --- Manage OpMinus when applied to scalars. --- + // -1 is not translated as tmp = OpMinus(1), but + // it is considered as a single entity "-1" + // #RNU_RES_E + SharedInfo.SkipNextFun = 1; + //RN: SISTEMAMI + SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI + OutArg(1).Type = InArg(1).Type; + OutArg(1).Size = InArg(1).Size; + OutArg(1).Dimension = InArg(1).Dimension; + OutArg(1).Value = InArg(1).Value; + OutArg(1).FindLike = InArg(1).FindLike; + OutArg(1).Scope = 'Number_d'; + else + OutArg = FA_GetOutArgInfo(InArg,NInArg,OutArg,NOutArg,SharedInfo,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,ReportFileName); + end + + // #RNU_RES_B + // --- Generate the names for the output arguments. --- + // Update of OutArg.Name and OutArg.Scope fields. + // #RNU_RES_E + if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + OutArg(1).Name = string(OutArg(1).Value); + elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + OutArg(1).Name = string(OutArg(1).Value); + elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + OutArg(1).Name = string(OutArg(1).Value); + else + [OutArg,SharedInfo] = GenOutArgNames(ASTFunName,InArg,NInArg,OutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo); + end + + // #RNU_RES_B + // --- Push in the AST stack the Output arguments. --- + // #RNU_RES_E + if (ASTFunName == 'OpEqual') + // Do nothing + else + for counteroutargs = 1:NOutArg + tmppushstack = OutArg(counteroutargs).Scope+': '+OutArg(counteroutargs).Name; + // #RNU_RES_B + PrintStringInfo(' Pushing in the AST stack: ""'+tmppushstack+'"".',ReportFileName,'file','y'); + // #RNU_RES_E + AST_PushASTStack(tmppushstack); + end + end + + // #RNU_RES_B + //NUT: verificare se si puo' accorpare qualcosa qui sotto + //RN: non capisco come mai analizzo lo scope dopo che faccio il push nello stack dove lo utilizzo!!! + // --- Scope analysis of the output arguments. --- + // #RNU_RES_E + if (ASTFunName == 'OpMinus' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + // Scope already set above. + elseif (ASTFunName == 'float' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + // Scope already set above. + elseif (ASTFunName == 'double' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + // Scope already set above. + else + OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo); + end + + //#RNUREM_ME --- Check if the current function is handling for counter variables. --- + [OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo); + + //#RNUREM_ME --- Store the while condition variable (if any). --- + SharedInfo = GetWhileCondVariable(OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo); + + //#RNUREM_ME --- Update Symbol Table with output arguments. --- + if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + //#RNUREM_ME A number is not inserted in the symbol table. + elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + //#RNUREM_ME A number is not inserted in the symbol table. + elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number')) + //#RNUREM_ME A number is not inserted in the symbol table. + else + ST_InsOutArg(OutArg,NOutArg,FileInfo,SharedInfo,'all'); + end + //#RNUREM_ME NUT: per risparmiare tempo di esecuzione puoi mettere delle if sulle funzioni che devono + //#RNUREM_ME NUT: essere skippate. + + //#RNU_RES_B + // -------------------------------------------- + // --- Generate the C name of the function. --- + // -------------------------------------------- + //#RNU_RES_E + + CFunName = C_GenerateFunName(ASTFunName,InArg,NInArg,OutArg,NOutArg); + //#RNU_RES_B + PrintStringInfo(' C Function Name: '+CFunName,ReportFileName,'file','y'); + if(IsArduinoFunction(ASTFunName)) + if(IsArduinoSetupFunction(ASTFunName)) + //If current function is an arduino setup function (like 'dc_motor_setup'), it + //should not be converted and inserted here. It is inserted in a list now and + //added to 'setup_arduino.c' later + InsertSetupInList(CFunName,InArg,NInArg,SetupListFile,'Setup'); + SharedInfo.SkipNextFun = SharedInfo.SkipNextFun + 1; + else //Currnet arduino function is not a setup function, so init function must be added + InsertSetupInList(ASTFunName,InArg,NInArg,SetupListFile,'Init'); + end + end + + // ------------------------------------------------------------------------- + // --- Determine which library the function belongs to: USER2C or SCI2C. --- + // ------------------------------------------------------------------------- + //#RNU_RES_E + if SCI2Cfileexist(FileInfo.SCI2CLibCAnnFun,ASTFunName+'.ann') + LibTypeInfo = 'SCI2C'; + else + LibTypeInfo = 'USER2C'; + end + + //#RNU_RES_B + // ------------------------------------------------------------------------------------ + // --- Check whether the function has been already called in the current .sci file. --- + // ------------------------------------------------------------------------------------ + //#RNU_RES_E + if (sum(SharedInfo.CFunctsAlreadyCalled == CFunName) == 1) + Flag_FunAlreadyCalled = 1; + else + + //#RNUREM_ME Add the C function name to the list of C functions called in the current .sci file. + SharedInfo.CFunctsAlreadyCalled(size(SharedInfo.CFunctsAlreadyCalled,1)+1) = CFunName; + end + + //#RNU_RES_B + // ---------------------------------- + // --- Generate FunInfo dat file. --- + // ---------------------------------- + //NUT: questo .dat deve essere generato sempre perche' cambiano i nomi degli argomenti mentre il resto dovrebbe + //NUT: essere tutto uguale + //NUT: magari posso fare una funzione che inserisce solo i campi diversi e fa un check su quelli che + //NUT: dovrebbero essere identici. + //#RNU_RES_E + GenCFunDatFiles(ASTFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,CFunName,LibTypeInfo,FunInfoDatDir); + + //#RNU_RES_B + // ----------------------------------- + // --- Update SCI2C Function List. --- + // ----------------------------------- + // Functions that are not already available in C are stored + // in the SCI2C Function List and converted in C at the end of + // the translation of the current .sci file. + //NUT: il problema della d0d0OpEqual dovrebbe essere legato al fatto che cerco di fare la opequal legata alla ins... + //NUT: devo evitare di scriveral dentro la lsista delle funzioni da tradurre. + //#RNU_RES_E + SharedInfo = FL_UpdateToBeConv(ASTFunName,CFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,FileInfo,SharedInfo); + + //#RNU_RES_B + // ----------------------------------------------- + // --- Check on common input/output arguments. --- + // ----------------------------------------------- + //#RNU_RES_E + if (((ASTFunName=='OpEqual') & (SharedInfo.SkipNextEqual == 1)) | ... + SharedInfo.SkipNextFun > 0 | ... + ((sum(mtlb_strcmp(ASTFunName,SharedInfo.Annotations.DataPrec)) > 0) & (SharedInfo.SkipNextPrec == 1))) + // Do nothing + else + AST_CheckCommonInOutArgs(InArg,NInArg,OutArg,NOutArg,ReportFileName); + end + + //#RNU_RES_B + // ----------------------------- + // --- C Generation Section. --- + // ----------------------------- + // --- Load FunInfo structure. --- + //#RNU_RES_E + FunInfoDatFileName = fullfile(FunInfoDatDir,CFunName+'.dat'); + load(FunInfoDatFileName,'FunInfo'); + + //#RNU_RES_B + // --- Generate include. --- + //#RNU_RES_E + if ((Flag_FunAlreadyCalled == 0) & (FunInfo.LibTypeInfo == 'USER2C') & (SharedInfo.NextCFunName ~= CFunName)) + // (SharedInfo.NextCFunName ~= CFunName) I don't want an include in the same file. Ex. in main.h I don't want include "main.h" + // #RNU_RES_B + PrintStringInfo('Adding include',ReportFileName,'file','y'); + PrintStringInfo('#include ""'+CFunName+'.h""',... + ReportFileName,'file','y'); + // #RNU_RES_E + PrintStringInfo('#include ""'+CFunName+'.h""',... + Pass1HeaderFileName,'file','y'); + end + + //#RNU_RES_B + // --- Generate the C code for the current function. --- + //#RNU_RES_E + FlagCall = 1; + SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall); + //#RNU_RES_B + //NUT: anziche farla fare alla cfuncall l'aggiornamento delle skip metti qui una funzione dedicata a cio' + //NUT: e' piu' ordinato. + //#RNU_RES_E endfunction diff --git a/macros/CCodeGeneration/C_InitHeader.bin b/macros/CCodeGeneration/C_InitHeader.bin Binary files differindex 4513310..642e75c 100644 --- a/macros/CCodeGeneration/C_InitHeader.bin +++ b/macros/CCodeGeneration/C_InitHeader.bin 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/FunctionList/FL_ExtractFuncList.sci b/macros/FunctionList/FL_ExtractFuncList.sci index 9e951d9..cbc1465 100644 --- a/macros/FunctionList/FL_ExtractFuncList.sci +++ b/macros/FunctionList/FL_ExtractFuncList.sci @@ -34,7 +34,7 @@ SCI2CNInArgCheck(argn(2),5,5); tmppwd = pwd();
cd(FunctionDir);
// funfiles = ls();
-funfiles = listfiles(); +funfiles = listfiles();
cd(tmppwd);
NFunFiles = size(funfiles,1);
diff --git a/macros/Hardware/AVR/AVRADCSetup.bin b/macros/Hardware/AVR/AVRADCSetup.bin Binary files differindex 6cf45dc..44e3d79 100644 --- a/macros/Hardware/AVR/AVRADCSetup.bin +++ b/macros/Hardware/AVR/AVRADCSetup.bin 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/AVRGetTimerValue.bin b/macros/Hardware/AVR/AVRGetTimerValue.bin Binary files differnew file mode 100644 index 0000000..26b4b47 --- /dev/null +++ b/macros/Hardware/AVR/AVRGetTimerValue.bin diff --git a/macros/Hardware/AVR/AVRGetTimerValue.sci b/macros/Hardware/AVR/AVRGetTimerValue.sci new file mode 100644 index 0000000..ab0146a --- /dev/null +++ b/macros/Hardware/AVR/AVRGetTimerValue.sci @@ -0,0 +1,31 @@ +function counts = AVRGetTimerValue(timer) +// Function to set the prescalar for timer. +// +// Calling Sequence +// AVRgetTimerValue(timer, prescalar) +// +// Parameters +// timer: timer to be set up (0,1,2) +// prescalar: prescalar to be used for generating PWM waveform (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/AVRPWMSetDuty.bin b/macros/Hardware/AVR/AVRPWMSetDuty.bin Binary files differnew file mode 100644 index 0000000..f3c9e3e --- /dev/null +++ b/macros/Hardware/AVR/AVRPWMSetDuty.bin diff --git a/macros/Hardware/AVR/AVRPWMSetDuty.sci b/macros/Hardware/AVR/AVRPWMSetDuty.sci new file mode 100644 index 0000000..0042540 --- /dev/null +++ b/macros/Hardware/AVR/AVRPWMSetDuty.sci @@ -0,0 +1,24 @@ +function AVRPWMSetDuty(timer, duty) +// Function to set duty for PWM of AVR +// +// Calling Sequence +// AVRPWMSetDuty(uint8 timer, uint8 duty) +// +// Parameters +// timer: timer to be used for PWM generation (0,1,2) +// duty: duty for PWM waveform (0-100) +// +// Description +// This function sets duty for PWM waveform according to given parameters. +// +// Examples +// AVRPWMSetDuty(0,10) //Sets 10% duty for timer 0 output. +// +// 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/AVRPWMSetup.bin b/macros/Hardware/AVR/AVRPWMSetup.bin Binary files differnew file mode 100644 index 0000000..971e43e --- /dev/null +++ b/macros/Hardware/AVR/AVRPWMSetup.bin diff --git a/macros/Hardware/AVR/AVRPWMSetup.sci b/macros/Hardware/AVR/AVRPWMSetup.sci new file mode 100644 index 0000000..1bee050 --- /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 +// AVRPWMSetup(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/AVRTimerSetup.bin b/macros/Hardware/AVR/AVRTimerSetup.bin Binary files differnew file mode 100644 index 0000000..65e8f45 --- /dev/null +++ b/macros/Hardware/AVR/AVRTimerSetup.bin diff --git a/macros/Hardware/AVR/AVRTimerSetup.sci b/macros/Hardware/AVR/AVRTimerSetup.sci new file mode 100644 index 0000000..6316cdd --- /dev/null +++ b/macros/Hardware/AVR/AVRTimerSetup.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 generating PWM waveform (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/lib b/macros/Hardware/AVR/lib Binary files differindex d08afbd..b198682 100644 --- a/macros/Hardware/AVR/lib +++ b/macros/Hardware/AVR/lib diff --git a/macros/Hardware/AVR/names b/macros/Hardware/AVR/names index 6e5b61b..126da77 100644 --- a/macros/Hardware/AVR/names +++ b/macros/Hardware/AVR/names @@ -2,7 +2,11 @@ AVRADCSetup AVRDigitalIn AVRDigitalOut AVRDigitalSetup +AVRGetTimerValue +AVRPWMSetDuty +AVRPWMSetup AVRReadADC +AVRTimerSetup GetAVRSupportFunctions GetPeripheral InsertPeripheralInList diff --git a/macros/Scilab-Arduino/GenerateSetupFunction.bin b/macros/Scilab-Arduino/GenerateSetupFunction.bin Binary files differnew file mode 100644 index 0000000..7a5052d --- /dev/null +++ b/macros/Scilab-Arduino/GenerateSetupFunction.bin diff --git a/macros/Scilab-Arduino/GenerateSetupFunction.sci b/macros/Scilab-Arduino/GenerateSetupFunction.sci new file mode 100644 index 0000000..db96e19 --- /dev/null +++ b/macros/Scilab-Arduino/GenerateSetupFunction.sci @@ -0,0 +1,34 @@ +function GenerateSetupFunction(FileInfo) + +SetupListFile = FileInfo.SetupListFile; + +load(SetupListFile,'SetupList'); + +SetupArduinoFile = fullfile(FileInfo.CStyleOutCCCodeDir,'setup_arduino.c'); +C_SCI2CHeader(SetupArduinoFile); + +PrintStringInfo('#include ""setup_arduino.h""',SetupArduinoFile,'file','y'); +PrintStringInfo(' ',SetupArduinoFile,'file','y'); +PrintStringInfo('int setup_arduino()',SetupArduinoFile,'file','y'); +PrintStringInfo('{',SetupArduinoFile,'file','y'); + +nelements=size(SetupList); + +for i=1:nelements + funcall = ' '; + funcall = funcall + SetupList(i)(1); + funcall = funcall + '('; + NInArg = size(SetupList(i))-1; + for j=1:NInArg-1 + funcall = funcall + SetupList(i)(j+1); + funcall = funcall + ', '; + end + funcall = funcall + SetupList(i)(NInArg+1); + funcall = funcall + ');'; + PrintStringInfo(funcall,SetupArduinoFile,'file','y'); +end +PrintStringInfo(' ',SetupArduinoFile,'file','y'); +PrintStringInfo(' return (0); ',SetupArduinoFile,'file','y'); +PrintStringInfo('}',SetupArduinoFile,'file','y'); + +endfunction diff --git a/macros/Scilab-Arduino/GetArduinoFunctions.bin b/macros/Scilab-Arduino/GetArduinoFunctions.bin Binary files differnew file mode 100644 index 0000000..82b0d45 --- /dev/null +++ b/macros/Scilab-Arduino/GetArduinoFunctions.bin diff --git a/macros/Scilab-Arduino/GetArduinoFunctions.sci b/macros/Scilab-Arduino/GetArduinoFunctions.sci new file mode 100644 index 0000000..19d59ca --- /dev/null +++ b/macros/Scilab-Arduino/GetArduinoFunctions.sci @@ -0,0 +1,22 @@ +function ArduinoFunctions = GetArduinoFunctions() +// ----------------------------------------------------------------- +// Get list of Arduino functions supported +// +// Input data: +// None +// +// Output data: +// List of Arduino functions supported +// +// Author: Siddhesh Wani +// ----------------------------------------------------------------- + +ArduinoFunctions = [ + "cmd_digital_out" + "cmd_digital_in" + "cmd_analog_out" + "cmd_analog_in" + "cmd_dcmotor_setup" + "cmd_dcmotor_run"]; + +endfunction diff --git a/macros/Scilab-Arduino/GetArduinoSetupFunctions.bin b/macros/Scilab-Arduino/GetArduinoSetupFunctions.bin Binary files differnew file mode 100644 index 0000000..048da7d --- /dev/null +++ b/macros/Scilab-Arduino/GetArduinoSetupFunctions.bin diff --git a/macros/Scilab-Arduino/GetArduinoSetupFunctions.sci b/macros/Scilab-Arduino/GetArduinoSetupFunctions.sci new file mode 100644 index 0000000..f377d38 --- /dev/null +++ b/macros/Scilab-Arduino/GetArduinoSetupFunctions.sci @@ -0,0 +1,17 @@ +function ArduinoSetupFunctions = GetArduinoSetupFunctions() +// ----------------------------------------------------------------- +// Get list of Arduino setup functions supported +// +// Input data: +// None +// +// Output data: +// List of Arduino setup functions supported +// +// Author: Siddhesh Wani +// ----------------------------------------------------------------- + +ArduinoSetupFunctions = [ + "cmd_dcmotor_setup"]; + +endfunction diff --git a/macros/Scilab-Arduino/InsertSetupInList.bin b/macros/Scilab-Arduino/InsertSetupInList.bin Binary files differnew file mode 100644 index 0000000..41c1a3f --- /dev/null +++ b/macros/Scilab-Arduino/InsertSetupInList.bin diff --git a/macros/Scilab-Arduino/InsertSetupInList.sci b/macros/Scilab-Arduino/InsertSetupInList.sci new file mode 100644 index 0000000..5c6be8b --- /dev/null +++ b/macros/Scilab-Arduino/InsertSetupInList.sci @@ -0,0 +1,58 @@ +function InsertSetupInList(FunName,InArg,NInArg,SetupListFile,FunType) + +load(SetupListFile,'SetupList'); + +//Check first if current input function already exists in the list +nelements = size(SetupList); +found=%F; + +if(FunType=='Setup') + for i=1:nelements + if(SetupList(i)(1) == FunName) + for j=1:NInArg + if(SetupList(i)(j+1) ~= InArg(j).Name) + found = %F + break; + else + found = %T; + end + end + end + if (found == %T) + break; //One match found. No need to check further. + end + end + + if(found == %F) + temp = list(FunName); + for i=1:NInArg + temp($+1) = InArg(i).Name; + end + end + SetupList($+1) = temp; +elseif((FunType=='Init')&((FunName=='cmd_digital_out')|(FunName=='cmd_analog_out')|(FunName=='cmd_digital_in'))) + for i=1:nelements + if(SetupList(i)(1) == FunName) + if(SetupList(i)(2) == InArg(2).Name) + found = %T + break; + else + found = %F; + end + end + end + + if(found == %F) + temp = list('pinMode'); + temp($+1) = InArg(2).Name; + if ((FunName=='cmd_digital_out')|(FunName=='cmd_analog_out')) + temp($+1) = 'OUTPUT'; + elseif (FunName == 'cmd_digital_in') + temp($+1) = 'INPUT'; + end + end + SetupList($+1) = temp; +end + +save(SetupListFile,'SetupList'); +endfunction diff --git a/macros/Scilab-Arduino/IsArduinoFunction.bin b/macros/Scilab-Arduino/IsArduinoFunction.bin Binary files differnew file mode 100644 index 0000000..5dbfaca --- /dev/null +++ b/macros/Scilab-Arduino/IsArduinoFunction.bin diff --git a/macros/Scilab-Arduino/IsArduinoFunction.sci b/macros/Scilab-Arduino/IsArduinoFunction.sci new file mode 100644 index 0000000..de1c770 --- /dev/null +++ b/macros/Scilab-Arduino/IsArduinoFunction.sci @@ -0,0 +1,22 @@ +function Output = IsArduinoFunction(FunName) +// ----------------------------------------------------------------- +// Check whether input function name is an Arduino function or not. +// +// Input data: +// FunName: Name of the function to be checked +// +// Output data: +// Output: True or False depending whether given function is an +// Arduino function or not +// +// Author: Siddhesh Wani +// ----------------------------------------------------------------- + +//Get list of supported functions for Arduino +ArduinoFunctions = GetArduinoFunctions(); + +//Check whether input function is present in above list or not +FunNameInArduino = members(FunName,ArduinoFunctions); +Output = bool2s(FunNameInArduino~=0); + +endfunction diff --git a/macros/Scilab-Arduino/IsArduinoSetupFunction.bin b/macros/Scilab-Arduino/IsArduinoSetupFunction.bin Binary files differnew file mode 100644 index 0000000..8948d1a --- /dev/null +++ b/macros/Scilab-Arduino/IsArduinoSetupFunction.bin diff --git a/macros/Scilab-Arduino/IsArduinoSetupFunction.sci b/macros/Scilab-Arduino/IsArduinoSetupFunction.sci new file mode 100644 index 0000000..fae7f62 --- /dev/null +++ b/macros/Scilab-Arduino/IsArduinoSetupFunction.sci @@ -0,0 +1,22 @@ +function Output = IsArduinoSetupFunction(FunName) +// ----------------------------------------------------------------- +// Check whether input function name is an Arduino setup function or not. +// +// Input data: +// FunName: Name of the function to be checked +// +// Output data: +// Output: True or False depending whether given function is an +// Arduino setup function or not +// +// Author: Siddhesh Wani +// ----------------------------------------------------------------- + +//Get list of supported functions for Arduino +ArduinoSetupFunctions = GetArduinoSetupFunctions(); + +//Check whether input function is present in above list or not +FunNameInArduinoSetup = members(FunName,ArduinoSetupFunctions); +Output = bool2s(FunNameInArduinoSetup~=0); + +endfunction diff --git a/macros/Scilab-Arduino/buildmacros.sce b/macros/Scilab-Arduino/buildmacros.sce new file mode 100644 index 0000000..dfeb475 --- /dev/null +++ b/macros/Scilab-Arduino/buildmacros.sce @@ -0,0 +1,29 @@ +// This file is released into the public domain + +Directories = [ "ASTManagement", ... + "CCodeGeneration", ... + "ErrorMessages", ... + "findDeps", ... + "FunctionAnnotation", ... + "FunctionList", ... + "GeneralFunctions", ... + "SymbolTable", ... + "ToolInitialization"... + "Hardware/AVR"... + "Scilab-Arduino" ]; + + +current_path_buildmacros = get_absolute_file_path("buildmacros.sce"); + +for K=1:size(Directories,"*") + myfile = current_path_buildmacros + filesep() + Directories(K) + filesep() + "buildmacros.sce"; + if isfile(myfile) then + exec(myfile); + end +end + +clear current_path_buildmacros; + +tbx_build_macros(TOOLBOX_NAME, get_absolute_file_path('buildmacros.sce')); + +clear tbx_build_macros; diff --git a/macros/Scilab-Arduino/lib b/macros/Scilab-Arduino/lib Binary files differnew file mode 100644 index 0000000..bd0cb70 --- /dev/null +++ b/macros/Scilab-Arduino/lib diff --git a/macros/Scilab-Arduino/names b/macros/Scilab-Arduino/names new file mode 100644 index 0000000..55eb6fe --- /dev/null +++ b/macros/Scilab-Arduino/names @@ -0,0 +1,6 @@ +GenerateSetupFunction +GetArduinoFunctions +GetArduinoSetupFunctions +InsertSetupInList +IsArduinoFunction +IsArduinoSetupFunction diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin Binary files differindex b2642d4..be0c48f 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 6d829ce..c3981a4 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');
@@ -3953,6 +3952,56 @@ INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,Ex //------------------------------------
+//---- Class cmd_dcmotor_setup -------
+//------------------------------------
+ClassName = 'cmd_dcmotor_setup';
+
+// --- Class Annotation. ---
+PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y');
+ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls);
+PrintStringInfo('NIN= 5',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('d0d0d0d0d0'+ArgSeparator+'u80',ClassFileName,'file','y');
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'cmd_dcmotor_setup';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
+//------------------------------------
+//---- Class cmd_dcmotor_run -------
+//------------------------------------
+ClassName = 'cmd_dcmotor_run';
+
+// --- Class Annotation. ---
+PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y');
+ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls);
+PrintStringInfo('NIN= 3',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('d0d0d0'+ArgSeparator+'u80',ClassFileName,'file','y');
+PrintStringInfo('d0d0i160'+ArgSeparator+'u80',ClassFileName,'file','y');
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'cmd_dcmotor_run';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
+
+//------------------------------------
//---- Class Sleep -------------------
//------------------------------------
ClassName = 'sleep';
@@ -4033,6 +4082,33 @@ INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,E 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 -----------
//------------------------------------
ClassName = 'AVRADCSetup';
@@ -4083,6 +4159,57 @@ INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,E INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+//------------------------------------
+//---- Class AVRPWMSetup -------------
+//------------------------------------
+ClassName = 'AVRPWMSetup';
+
+// --- Class Annotation. ---
+PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y');
+ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls);
+PrintStringInfo('NIN= 4',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('d0d0d0d0'+ArgSeparator+'u80',ClassFileName,'file','y');
+
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'AVRPWMSetup';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
+//------------------------------------
+//---- Class AVRPWMSetDuty -----------
+//------------------------------------
+ClassName = 'AVRPWMSetDuty';
+
+// --- 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');
+
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'AVRPWMSetDuty';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
+
// ////////////////////////////////////////////
// /////PARTE INTRODOTTA DA ALBERTO MOREA
// /////////////////////////////////////////////
diff --git a/macros/ToolInitialization/INIT_GenFileInfo.bin b/macros/ToolInitialization/INIT_GenFileInfo.bin Binary files differindex 8f114a7..a8d4722 100644 --- a/macros/ToolInitialization/INIT_GenFileInfo.bin +++ b/macros/ToolInitialization/INIT_GenFileInfo.bin diff --git a/macros/ToolInitialization/INIT_GenFileInfo.sci b/macros/ToolInitialization/INIT_GenFileInfo.sci index 753509e..21fe7a7 100644 --- a/macros/ToolInitialization/INIT_GenFileInfo.sci +++ b/macros/ToolInitialization/INIT_GenFileInfo.sci @@ -113,5 +113,5 @@ FileInfo.MakefileFilename = fullfile(FileInfo.CStyleOutCCCodeDir,'Makefile'); //----Hardware related-----
//-------------------------
FileInfo.PeripheralInitListFile = fullfile(FileInfo.WorkingDir,'PeripheralInit.dat');
-
+FileInfo.SetupListFile = fullfile(FileInfo.WorkingDir,'SetupList.dat');
endfunction
diff --git a/macros/ToolInitialization/INIT_LoadLibraries.bin b/macros/ToolInitialization/INIT_LoadLibraries.bin Binary files differindex 4cf0283..c85aac6 100644 --- a/macros/ToolInitialization/INIT_LoadLibraries.bin +++ b/macros/ToolInitialization/INIT_LoadLibraries.bin diff --git a/macros/ToolInitialization/INIT_LoadLibraries.sci b/macros/ToolInitialization/INIT_LoadLibraries.sci index 1ef9ee0..28eb34f 100644 --- a/macros/ToolInitialization/INIT_LoadLibraries.sci +++ b/macros/ToolInitialization/INIT_LoadLibraries.sci @@ -49,7 +49,7 @@ ToBeConverted(1).CFunctionName = SharedInfo.NextCFunName; // --- Read the list of library functions available. ---
[SCI2CAvailableC,SCI2CNElem] = FL_ExtractFuncList(FileInfo.SCI2CLibCFLFun,FileInfo.SCI2CLibCFLCls,...
SharedInfo.Annotations.FUNCLASS,SharedInfo.Extension.FuncListClasses,FileInfo.GeneralReport);
-
+//disp (SCI2CAvailable);
[USER2CAvailableC,USER2CNElem] = FL_ExtractFuncList(FileInfo.USER2CLibCFLFun,FileInfo.USER2CLibCFLCls,...
SharedInfo.Annotations.FUNCLASS,SharedInfo.Extension.FuncListClasses,FileInfo.GeneralReport);
diff --git a/macros/ToolInitialization/INIT_SCI2C.bin b/macros/ToolInitialization/INIT_SCI2C.bin Binary files differindex 72623b2..c6141d6 100644 --- a/macros/ToolInitialization/INIT_SCI2C.bin +++ b/macros/ToolInitialization/INIT_SCI2C.bin diff --git a/macros/ToolInitialization/INIT_SCI2C.sci b/macros/ToolInitialization/INIT_SCI2C.sci index 0340d6f..6dde05d 100644 --- a/macros/ToolInitialization/INIT_SCI2C.sci +++ b/macros/ToolInitialization/INIT_SCI2C.sci @@ -147,8 +147,13 @@ anscounter = 0; //--------------------------------------------
//---Hardware related initialisation----------
//--------------------------------------------
-PeripheralList = list();
-save(FileInfo.PeripheralInitListFile, 'PeripheralList');
+if (OutFormat == 'AVR')
+ PeripheralList = list();
+ save(FileInfo.PeripheralInitListFile, 'PeripheralList');
+elseif (OutFormat == 'Arduino')
+ SetupList = list();
+ save(FileInfo.SetupListFile, 'SetupList');
+end
endfunction
// #RNU_RES_B
diff --git a/macros/ToolInitialization/ManageNextConversion.bin b/macros/ToolInitialization/ManageNextConversion.bin Binary files differindex a34ee4f..bf43562 100644 --- a/macros/ToolInitialization/ManageNextConversion.bin +++ b/macros/ToolInitialization/ManageNextConversion.bin diff --git a/macros/ToolInitialization/ManageNextConversion.sci b/macros/ToolInitialization/ManageNextConversion.sci index 04ec9db..a152476 100644 --- a/macros/ToolInitialization/ManageNextConversion.sci +++ b/macros/ToolInitialization/ManageNextConversion.sci @@ -49,6 +49,7 @@ C_FinalizeCode(FileInfo,SharedInfo); // --- Identify the next function to translate. ---
// ------------------------------------------------
SharedInfo.NFilesToTranslate = SharedInfo.NFilesToTranslate - 1;
+
if (SharedInfo.NFilesToTranslate >= 1)
// Remove the translated C function from the ToBeConverted list
ToBeConverted(1) = [];
diff --git a/macros/buildmacros.sce b/macros/buildmacros.sce index 627e638..dfeb475 100644 --- a/macros/buildmacros.sce +++ b/macros/buildmacros.sce @@ -9,7 +9,8 @@ Directories = [ "ASTManagement", ... "GeneralFunctions", ... "SymbolTable", ... "ToolInitialization"... - "Hardware" ]; + "Hardware/AVR"... + "Scilab-Arduino" ]; current_path_buildmacros = get_absolute_file_path("buildmacros.sce"); diff --git a/macros/findDeps/getAllHeaders.bin b/macros/findDeps/getAllHeaders.bin Binary files differindex 4314c53..4ed973e 100644 --- a/macros/findDeps/getAllHeaders.bin +++ b/macros/findDeps/getAllHeaders.bin diff --git a/macros/findDeps/getAllHeaders.sci b/macros/findDeps/getAllHeaders.sci index f5c74bd..7cddce2 100644 --- a/macros/findDeps/getAllHeaders.sci +++ b/macros/findDeps/getAllHeaders.sci @@ -134,11 +134,15 @@ function allHeaders = getAllHeaders(OutFormat) "src/c/scilab-arduino/includes/cmd_digital_in.h" "src/c/scilab-arduino/includes/cmd_analog_out.h" "src/c/scilab-arduino/includes/cmd_analog_in.h" + "src/c/scilab-arduino/includes/cmd_dcmotor_setup.h" + "src/c/scilab-arduino/includes/cmd_dcmotor_run.h" "src/c/scilab-arduino/includes/sleep.h"]; AVR_headers = [ "src/c/hardware/avr/includes/AVRPeripheralGPIO.h" "src/c/hardware/avr/includes/AVRPeripheralADC.h" + "src/c/hardware/avr/includes/AVRPeripheralPWM.h" + "src/c/hardware/avr/includes/AVRUtil.h" ]; if OutFormat == "StandAlone" diff --git a/macros/findDeps/getAllInterfaces.bin b/macros/findDeps/getAllInterfaces.bin Binary files differindex b49fdbf..368b84a 100644 --- a/macros/findDeps/getAllInterfaces.bin +++ b/macros/findDeps/getAllInterfaces.bin diff --git a/macros/findDeps/getAllInterfaces.sci b/macros/findDeps/getAllInterfaces.sci index 5b52c71..7813809 100644 --- a/macros/findDeps/getAllInterfaces.sci +++ b/macros/findDeps/getAllInterfaces.sci @@ -127,12 +127,15 @@ function allInterfaces = getAllInterfaces(OutFormat) "src/c/scilab-arduino/interfaces/int_cmd_digital_in.h" "src/c/scilab-arduino/interfaces/int_cmd_analog_out.h" "src/c/scilab-arduino/interfaces/int_cmd_analog_in.h" + "src/c/scilab-arduino/interfaces/int_cmd_dcmotor.h" "src/c/scilab-arduino/interfaces/int_sleep.h"]; //Interface files required for "AVR" output 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_AVRUtil.h" ]; if OutFormat == "StandAlone" diff --git a/macros/findDeps/getAllSources.bin b/macros/findDeps/getAllSources.bin Binary files differindex 4943977..a81e474 100644 --- a/macros/findDeps/getAllSources.bin +++ b/macros/findDeps/getAllSources.bin diff --git a/macros/findDeps/getAllSources.sci b/macros/findDeps/getAllSources.sci index 956f7be..c8d6d0b 100644 --- a/macros/findDeps/getAllSources.sci +++ b/macros/findDeps/getAllSources.sci @@ -822,6 +822,8 @@ function allSources = getAllSources(OutFormat) "src/c/scilab-arduino/cmd_digital_in/u8cmd_digital_ins.c" "src/c/scilab-arduino/cmd_analog_out/u8cmd_analog_outs.c" "src/c/scilab-arduino/cmd_analog_in/u8cmd_analog_ins.c" + "src/c/scilab-arduino/cmd_dcmotor_setup/u8cmd_dcmotor_setups.c" + "src/c/scilab-arduino/cmd_dcmotor_run/u8cmd_dcmotor_runs.c" "src/c/scilab-arduino/sleep/u16sleeps.c"]; //Files to be inserted only if output format selected is 'AVR'. @@ -831,7 +833,9 @@ 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/pwm/u8AVRPWMSetups.c" + "src/c/hardware/avr/pwm/u8AVRPWMSetDutys.c" + "src/c/hardware/avr/util/u16AVRSleeps.c" ]; diff --git a/macros/findDeps/getArduinoFiles.bin b/macros/findDeps/getArduinoFiles.bin Binary files differindex f8937bf..651b8f3 100644 --- a/macros/findDeps/getArduinoFiles.bin +++ b/macros/findDeps/getArduinoFiles.bin diff --git a/macros/findDeps/getArduinoFiles.sci b/macros/findDeps/getArduinoFiles.sci index a51d9b5..89033d0 100644 --- a/macros/findDeps/getArduinoFiles.sci +++ b/macros/findDeps/getArduinoFiles.sci @@ -12,6 +12,7 @@ function arduinoFiles = getArduinoFiles() arduinoFiles = [ + "src/c/scilab-arduino/default_files/setup_arduino.h" "src/c/scilab-arduino/default_files/Makefile" "src/c/scilab-arduino/default_files/sci2c_arduino.ino"]; endfunction diff --git a/macros/runsci2c.bin b/macros/runsci2c.bin Binary files differindex afe6e7d..6c09823 100644 --- a/macros/runsci2c.bin +++ b/macros/runsci2c.bin diff --git a/macros/runsci2c.sci b/macros/runsci2c.sci index 9158703..4620705 100644 --- a/macros/runsci2c.sci +++ b/macros/runsci2c.sci @@ -133,12 +133,15 @@ end //default folder, else generate makefile for standalone c code
if (OutFormat == 'Arduino')
+
+ GenerateSetupFunction(FileInfo);
mkdir(SCI2COutputPath+"/arduino/");
mkdir(SCI2COutputPath+"/arduino/sci2c_arduino");
//Copy arduino makefile
arduinoFiles = SCI2CHOME + "/" + getArduinoFiles();
PrintStepInfo('Copying arduino files', FileInfo.GeneralReport,'both');
- for i = 1:size(arduinoFiles, "*")
+ copyfile(arduinoFiles(1), SCI2COutputPath);
+ for i = 2:size(arduinoFiles, "*")
// DEBUG only
//disp("Copying "+arduinoFiles(i)+" in "+SCI2COutputPath+"/arduino/sci2carduino");
copyfile(arduinoFiles(i), SCI2COutputPath+"/arduino/sci2c_arduino/");
diff --git a/src/c/hardware/avr/includes/AVRPeripheralPWM.h b/src/c/hardware/avr/includes/AVRPeripheralPWM.h new file mode 100644 index 0000000..80b29f3 --- /dev/null +++ b/src/c/hardware/avr/includes/AVRPeripheralPWM.h @@ -0,0 +1,27 @@ +//This file defines functions prototypes related to PWM. +// +// Authors +// Siddhesh Wani +// + +#ifndef __AVRPERIPHERALPWM_H__ +#define __AVRPERIPHERALPWM_H__ + +#include <avr/io.h> +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//Function prototypes +uint8 u8AVRPWMSetups(uint8 timer, uint8 prescalar, uint8 waveform_mode, uint8 output_mode); + +uint8 u8AVRPWMSetDuty(uint8 timer, uint8 duty); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALPWM_H__ */ 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_AVRPeripheralPWM.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h new file mode 100644 index 0000000..7368619 --- /dev/null +++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h @@ -0,0 +1,26 @@ +//This file defines constants corresponding to gpios. +// +// Authors +// Siddhesh Wani +// + +#ifndef __INT_AVRPERIPHERALPWM_H__ +#define __INT_AVRPERIPHERALPWM_H__ + +#include <avr/io.h> +#include "AVRPeripheralPWM.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define d0d0d0d0AVRPWMSetupu80(in1,in2) u8AVRPWMSetups((uint8) in1,\ + (uint8) in2, (uint8) in3, (uint8) in4); + +#define d0d0AVRPWMSetDuty(in1,in2) u8AVRPWMSetDutys((uint8) in1, (uint8) in2); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !__AVRPERIPHERALADC_H__ */ 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/u8AVRPWMSetDutys.c b/src/c/hardware/avr/pwm/u8AVRPWMSetDutys.c new file mode 100644 index 0000000..adb186a --- /dev/null +++ b/src/c/hardware/avr/pwm/u8AVRPWMSetDutys.c @@ -0,0 +1,39 @@ +// Function to set duty for PWM of AVR +// +// Calling Sequence +// u8AVRPWMSetDutys(uint8 timer, uint8 duty) +// +// Parameters +// timer: timer to be used for PWM generation (0,1,2) +// duty: duty for PWM waveform (0-100) +// +// Description +// This function sets duty for PWM waveform according to given parameters. +// +// Examples +// u8AVRPWMSetDutys(0,10) //Sets 10% duty for timer 0 output. +// +// Authors +// Siddhesh Wani +// + +#include "AVRPeripheralPWM.h" + +uint8 u8AVRPWMSetDutys(uint8 timer, uint8 duty) +{ + uint8 duty_value=0; + + switch(timer) + { + case 0: + duty_value = (uint8)(((uint16)(duty * 0xff))/100); + OCR0 = duty_value; + break; + case 2: + duty_value = (uint8)(((uint16)(duty * 0xff))/100); + OCR2 = duty_value; + break; + } + + +} diff --git a/src/c/hardware/avr/pwm/u8AVRPWMSetups.c b/src/c/hardware/avr/pwm/u8AVRPWMSetups.c new file mode 100644 index 0000000..5110d81 --- /dev/null +++ b/src/c/hardware/avr/pwm/u8AVRPWMSetups.c @@ -0,0 +1,62 @@ +// 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: + TCCR2|= (prescalar & 0x07); //Select clock source + //Select waveform generation mode + TCCR2|= ((waveform_mode & 0x04) << 4); + //Select compare output mode + TCCR2 |= ((output_mode & 0x01) << 3); //WGM0 + TCCR2 |= ((output_mode & 0x02) << 6); //WGM1 + break; + } + + return 0; +} + diff --git a/src/c/hardware/avr/util/U16AVRSleeps.c b/src/c/hardware/avr/util/u16AVRSleeps.c index f214471..4d81c96 100644 --- a/src/c/hardware/avr/util/U16AVRSleeps.c +++ b/src/c/hardware/avr/util/u16AVRSleeps.c @@ -6,9 +6,9 @@ #include "AVRUtil.h" -uint8 U16AVRSleeps (uint16 delay) +uint8 u16AVRSleeps (uint16 delay) { _delay_ms(delay); - retrun 0; + return 0; } diff --git a/src/c/scilab-arduino/cmd_dcmotor_run/u8cmd_dcmotor_runs.c b/src/c/scilab-arduino/cmd_dcmotor_run/u8cmd_dcmotor_runs.c new file mode 100644 index 0000000..93905c9 --- /dev/null +++ b/src/c/scilab-arduino/cmd_dcmotor_run/u8cmd_dcmotor_runs.c @@ -0,0 +1,59 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008 - INRIA - Arnaud TORSET + * + * 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 + * + */ + +#include "cmd_dcmotor_run.h" + +uint8 u8cmd_dcmotor_runs(uint8 board_no, uint8 motor_no, int16 duty) +{ + uint8 direction = 1; + if(duty >= 0) + { + direction = 1; + } + else + { + direction = 0; + duty = -duty; + } + + if(duty > 255) duty = 255; + + if (dcm_mode[motor_no] == 3) //L293 + { + if(direction == 1) + { + analogWrite(dcm_pin_1[motor_no],duty); + analogWrite(dcm_pin_2[motor_no],0); + } + else + { + analogWrite(dcm_pin_2[motor_no],duty); + analogWrite(dcm_pin_1[motor_no],0); + } + } + else + { + if(direction == 1) + { + digitalWrite(dcm_pin_1[motor_no],HIGH); + digitalWrite(dcm_pin_2[motor_no],LOW); + } + else + { + digitalWrite(dcm_pin_2[motor_no],HIGH); + digitalWrite(dcm_pin_1[motor_no],LOW); + } + } + + return 0; +} + diff --git a/src/c/scilab-arduino/cmd_dcmotor_setup/u8cmd_dcmotor_setups.c b/src/c/scilab-arduino/cmd_dcmotor_setup/u8cmd_dcmotor_setups.c new file mode 100644 index 0000000..30b4b9b --- /dev/null +++ b/src/c/scilab-arduino/cmd_dcmotor_setup/u8cmd_dcmotor_setups.c @@ -0,0 +1,42 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008 - INRIA - Arnaud TORSET + * + * 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 + * + */ + +#include "cmd_dcmotor_setup.h" + +uint8 dcm_pin_1[4], dcm_pin_2[4], dcm_mode[4]; + +uint8 u8cmd_dcmotor_setups(uint8 board_no, uint8 driver_type, uint8 motor_no,\ + uint8 pin_1, uint8 pin_2) +{ + dcm_pin_1[motor_no] = pin_1; + dcm_pin_2[motor_no] = pin_2; + dcm_mode[motor_no] = driver_type; + + //Initialise pins + pinMode(pin_1,OUTPUT); + pinMode(pin_2,OUTPUT); + + //Set output to low. + if(driver_type == 3) + { + analogWrite(pin_1,0); + analogWrite(pin_2,0); + } + else + { + digitalWrite(pin_1,LOW); + digitalWrite(pin_2,LOW); + } + + 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 diff --git a/src/c/scilab-arduino/default_files/sci2c_arduino.ino b/src/c/scilab-arduino/default_files/sci2c_arduino.ino index 9e9d9b6..2b30456 100644 --- a/src/c/scilab-arduino/default_files/sci2c_arduino.ino +++ b/src/c/scilab-arduino/default_files/sci2c_arduino.ino @@ -1,11 +1,13 @@ #include "Arduino.h" #include <loop_arduino.h> +#include <setup_arduino.h> void setup() { //Please write appropriate setup functions here. + setup_arduino(); } -int i = 0; + void loop() { loop_arduino(); diff --git a/src/c/scilab-arduino/default_files/setup_arduino.h b/src/c/scilab-arduino/default_files/setup_arduino.h new file mode 100644 index 0000000..9eb0ed4 --- /dev/null +++ b/src/c/scilab-arduino/default_files/setup_arduino.h @@ -0,0 +1,64 @@ +/* +** ************************************************ +** This file has been generated using +** Scilab2C (Version 2.3) +** +** Please visit following links for more informations: +** Atoms Module: http://atoms.scilab.org/toolboxes/scilab2c +** Scilab2C Forge: http://forge.scilab.org/index.php/p/scilab2c/ +** Scilab2C ML: http://forge.scilab.org/index.php/p/scilab2c/ +** ************************************************ +*/ + + +#ifndef setup_arduino_h +#define setup_arduino_h +/* +** ------------------- +** ----- Target ------ +** ------------------- +*/ +# define Arduino1 1 +/* +** ----------------------- +** --- SCI2C Includes. --- +** ----------------------- +*/ +#include "sci2clib.h" +/* +** --------------------------- +** --- End SCI2C Includes. --- +** --------------------------- +*/ + + +#ifdef __cplusplus +extern "C" { +#endif +/* +** ------------------- +** --- Prototypes. --- +** ------------------- +*/ +int setup_arduino(); +/* +** ----------------------- +** --- End Prototypes. --- +** ----------------------- +*/ + + +/* +** ------------------------ +** --- USER2C Includes. --- +** ------------------------ +*/ +/* +** ---------------------------- +** --- End USER2C Includes. --- +** ---------------------------- +*/ +#ifdef __cplusplus +} /* extern "C" */ +#endif +#endif diff --git a/src/c/scilab-arduino/includes/cmd_dcmotor_run.h b/src/c/scilab-arduino/includes/cmd_dcmotor_run.h new file mode 100644 index 0000000..7631761 --- /dev/null +++ b/src/c/scilab-arduino/includes/cmd_dcmotor_run.h @@ -0,0 +1,32 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008 - INRIA - Arnaud TORSET + * + * 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 + * + */ + + +#ifndef __CMD_DCMOTOR_RUN_H__ +#define __CMD_DCMOTOR_RUN_H__ + +#include "types.h" +#include "Arduino.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint8 dcm_pin_1[4], dcm_pin_2[4], dcm_mode[4]; + +uint8 u8cmd_dc_motor_runs(uint8 board_no, uint8 motor_no, int16 duty); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __CMD_DCMOTOR_SETUP_H__ */ diff --git a/src/c/scilab-arduino/includes/cmd_dcmotor_setup.h b/src/c/scilab-arduino/includes/cmd_dcmotor_setup.h new file mode 100644 index 0000000..94f5a16 --- /dev/null +++ b/src/c/scilab-arduino/includes/cmd_dcmotor_setup.h @@ -0,0 +1,33 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008 - INRIA - Arnaud TORSET + * + * 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 + * + */ + + +#ifndef __CMD_DCMOTOR_SETUP_H__ +#define __CMD_DCMOTOR_SETUP_H__ + +#include "types.h" +#include "Arduino.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint8 dcm_pin_1[4], dcm_pin_2[4], dcm_mode[4]; + +uint8 u8cmd_dc_motor_setups(uint8 board_no, uint8 driver_type, uint8 motor_no,\ + uint8 pin_1, uint8 pin_2); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __CMD_DCMOTOR_SETUP_H__ */ diff --git a/src/c/scilab-arduino/interfaces/int_cmd_dcmotor.h b/src/c/scilab-arduino/interfaces/int_cmd_dcmotor.h new file mode 100644 index 0000000..b35583d --- /dev/null +++ b/src/c/scilab-arduino/interfaces/int_cmd_dcmotor.h @@ -0,0 +1,39 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008 - INRIA - Arnaud TORSET + * + * 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 + * + */ + + +#ifndef __INT_CMD_DCMOTOR_H__ +#define __INT_CMD_DCMOTOR_H__ + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define d0d0d0d0d0cmd_dcmotor_setupu80(in1,in2,in3,in4,in5)\ + u8cmd_dcmotor_setups((uint8)in1,(uint8)in2,(uint8)in3,\ + (uint8)in4,(uint8)in5) + +#define d0d0d0cmd_dcmotor_runu80(in1,in2,in3) u8cmd_dcmotor_runs((uint8)in1,\ + (uint8)in2, (int16)in3); + + +#define d0d0u160cmd_dcmotor_runu80(in1,in2,in3) u8cmd_dcmotor_runs((uint8)in1,\ + (uint8)in2, (int16)in3); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __INT_CMD_DCMOTOR_H__ */ |