From: Michal Sojka Date: Sat, 3 Oct 2015 06:06:41 +0000 (+0200) Subject: gio blocks: Allow users to select the pin from a list X-Git-Tag: eaton-0.7~14 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-simulink.git/commitdiff_plain/0e3f258a310e15dcdb1da9e7627c8dc31245addc gio blocks: Allow users to select the pin from a list This (target-specific) list is updated by rpp_setup. --- diff --git a/Makefile b/Makefile index f0b90f4..e9e3f4f 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ RELEASE_LIB_GIT_FILES = \ os/$(rpp_lib_OS)/include/ \ rpp/include/ -RELEASE_LIB_GEN_FILES = Makefile.config rpp-lib.lib +RELEASE_LIB_GEN_FILES = Makefile.config rpp-lib.lib build/gio_names.txt $(RELEASE_BASENAME):: LIB_RELEASE_BASENAME:=$(shell make -C rpp/lib --silent print-release-basename) $(RELEASE_BASENAME):: release-lib diff --git a/rpp/blocks/.gitattributes b/rpp/blocks/.gitattributes index 9acd345..a545b45 100644 --- a/rpp/blocks/.gitattributes +++ b/rpp/blocks/.gitattributes @@ -16,6 +16,7 @@ /rpp_sci_printf.slx eaton /rpp_sci_rx.slx eaton /rpp_sci_tx.slx eaton +/rpp_update_blocks_for_target.m eaton /rpp_update_doc.m eaton /sfunction_ain.c eaton /sfunction_canreceive.c eaton diff --git a/rpp/blocks/rpp_gio_in.slx b/rpp/blocks/rpp_gio_in.slx index 23d9287..a9075ed 100644 Binary files a/rpp/blocks/rpp_gio_in.slx and b/rpp/blocks/rpp_gio_in.slx differ diff --git a/rpp/blocks/rpp_gio_out.slx b/rpp/blocks/rpp_gio_out.slx index 747c350..21f17a8 100644 Binary files a/rpp/blocks/rpp_gio_out.slx and b/rpp/blocks/rpp_gio_out.slx differ diff --git a/rpp/blocks/rpp_update_blocks_for_target.m b/rpp/blocks/rpp_update_blocks_for_target.m new file mode 100644 index 0000000..44897e7 --- /dev/null +++ b/rpp/blocks/rpp_update_blocks_for_target.m @@ -0,0 +1,21 @@ +function rpp_update_blocks_for_target +%RPP_UPDATE_BLOCKS_FOR_TARGET Update blocks for use with the particular target hardware + +% Update GIO pin names + update_gio_names('rpp_gio_in') + update_gio_names('rpp_gio_out') +end + +function update_gio_names(lib) + block_lib = load_system(lib); + set_param(block_lib, 'Lock', 'off'); + block = find_system(block_lib, 'Type', 'block'); + params = get_param(block, 'ObjectParameters'); + p = Simulink.Mask.get(block); + param = p.getParameter('pin'); + gio_names_txt = fullfile(getpref('rpp', 'RppLibRoot'), 'build', 'gio_names.txt'); + param.TypeOptions = [{'---'}; textread(gio_names_txt, '%s')]; + set_param(block_lib, 'Lock', 'on'); + save_system(block_lib); + close_system(block_lib); +end diff --git a/rpp/blocks/sfunction_gio_in.c b/rpp/blocks/sfunction_gio_in.c index 168fbb9..00238c6 100644 --- a/rpp/blocks/sfunction_gio_in.c +++ b/rpp/blocks/sfunction_gio_in.c @@ -33,26 +33,26 @@ Inputs: Outputs: - { name: "Digital Input value", type: "bool" } Parameters: - - { name: "Port type", type: "Choice", range: "GIOA, GIOB, NHET1" } - - { name: "Pin number", type: "int8", range: "[0–7]", note: "(depends on selected port)" } + - { name: "Pin", type: "Choice", range: "Target dependent pin names or '---'" } + - { name: "Pin name", type: "String", note: "Pin name as defined in gio_def.h. This parameter is only visible if *Pin* is '---'." } - { name: "Input Type", type: "Choice", range: "Tri-state, Pull Up, Pull Down" } # Description is in Markdown mark-up Description: &desc | - Reads a value from a GPIO pin. The block supports GIOA, GIOB and NHET1 ports. - Any pin can be configured as tri-state, pull up or pull down. + Reads value from a GIO pin. Which pins are supported depends on the + target board. The selected pin can be configured as tri-state, pull + up or pull down. - It is not allowed to read from one pin by using more then one GIOIN blocks. - It is not allowed to use GIOIN and DOUT blocks together configured for one GPIO pin. + When the pin is used in multiple GIOIN or GIOOUT blocks, an error is + signaled. Help: *desc Status: Stable RPP API functions used: - - hal_gpio_pin_get_dsc - - hal_gpio_pin_get_value - - hal_gpio_pin_conf_set + - rpp_gio_setup + - rpp_gio_get Relevant demos: - gio_demo @@ -63,25 +63,13 @@ Relevant demos: #define S_FUNCTION_NAME sfunction_gio_in #include "header.c" -#define PARAM_NAME_PORT_TYPE "port_type" -#define PARAM_NAME_PIN_NUMBER "pin_number" -#define PARAM_NAME_INPUT_TYPE "input_type" - /** Identifiers of the block parameters */ enum params{ - PARAM_PORT_TYPE, - PARAM_PIN_NUMBER, + PARAM_PIN_NAME, PARAM_INPUT_TYPE, PARAMS_COUNT }; -enum port_types{ - PORT_UNKNOWN, - PORT_GIOA, - PORT_GIOB, - PORT_NHET1 -}; - enum outputs{ OUT_PIN_VALUE, OUTPUTS_COUNT @@ -89,12 +77,6 @@ enum outputs{ static void mdlInitializeSizes(SimStruct *S) { - /* - * Configure parameters: 3 - * - Port type - * - Pin number - * - Input type - */ if (!rppSetNumParams(S, PARAMS_COUNT)) { return; } @@ -123,42 +105,33 @@ static void mdlInitializeSizes(SimStruct *S) #define MDL_CHECK_PARAMETERS static void mdlCheckParameters(SimStruct *S) { - if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) { - if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) { - return; - } - } - else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) { - if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) { - return; - } - } - else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) { - if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) { - return; - } - } - else { - return; - } + if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) { + ssSetErrorStatus(S, "Parameter to S-function must be a string."); + } } #endif -#ifdef MATLAB_MEX_FILE -#define MDL_SET_WORK_WIDTHS -static void mdlSetWorkWidths(SimStruct *S) +#if defined(MATLAB_MEX_FILE) +#define MDL_RTW +static void mdlRTW(SimStruct *S) { - /* Set number of run-time parameters */ - if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) { - return; - } - /* Register the run-time parameter 1 */ - ssRegDlgParamAsRunTimeParam(S, PARAM_PORT_TYPE, PARAM_PORT_TYPE, PARAM_NAME_PORT_TYPE, SS_INT8); - ssRegDlgParamAsRunTimeParam(S, PARAM_PIN_NUMBER, PARAM_PIN_NUMBER, PARAM_NAME_PIN_NUMBER, SS_INT8); - ssRegDlgParamAsRunTimeParam(S, PARAM_INPUT_TYPE, PARAM_INPUT_TYPE, PARAM_NAME_INPUT_TYPE, SS_INT8); + char_T pin_name[80]; + int8_T pull_type = mxGetPr(ssGetSFcnParam(S, PARAM_INPUT_TYPE))[0]; + + if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) { + ssSetErrorStatus(S,"mxGetString error in mdlRTW"); + return; + } + + if (!ssWriteRTWParamSettings(S, 2, + SSWRITE_VALUE_STR, "PinName", pin_name, + SSWRITE_VALUE_DTYPE_NUM, "PullType", &pull_type, DTINFO(SS_INT8, COMPLEX_NO))) { + ssSetErrorStatus(S, "ssWriteRTWParamSettings failed"); + } } -#endif +#endif /* MDL_RTW */ + #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT diff --git a/rpp/blocks/sfunction_gio_out.c b/rpp/blocks/sfunction_gio_out.c index b5ee09e..3b62b3f 100644 --- a/rpp/blocks/sfunction_gio_out.c +++ b/rpp/blocks/sfunction_gio_out.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2013, 2014 Czech Technical University in Prague +/* Copyright (C) 2013, 2014, 2015 Czech Technical University in Prague * * Authors: * - Carlos Jenkins @@ -33,31 +33,30 @@ Inputs: Outputs: Parameters: - - { name: "Port type", type: "Choice", range: "GIOA, GIOB, NHET1" } - - { name: "Pin number", type: "int8", range: "[0–7]", note: "(depends on selected port)" } + - { name: "Pin", type: "Choice", range: "Target dependent pin names or '---'" } + - { name: "Pin name", type: "String", note: "Pin name as defined in gio_def.h. This parameter is only visible if *Pin* is '---'." } - { name: "Initial output value", type: "uint8", range: "[0,1]" } - { name: "Output Type", type: "Choice", range: "Open Drain, Push/Pull" } # Description is in Markdown mark-up Description: &desc | - Writes a value to a GPIO pin. The block supports GIOA, GIOB and NHET1 ports. - Any pin can be configured as open drain or push/pull and initial output value - can be specified. The initial value is a value, which will appear on the pin - when the GPIO module is initialized and stays there until the first - block execution. + Sets a GIO pin to a given value. Which pins are supported depends on + the target board. Any pin can be configured as open drain or + push/pull and initial output value can be specified. The initial + value is a value, which will appear on the pin when the GPIO module + is initialized and stays there until the first block execution. - It is not allowed to write to one pin by using more then one GIOOUT blocks. - It is not allowed to use GIOOUT and DIN blocks on one GPIO pin. + When the pin is used in multiple GIOIN or GIOOUT blocks, an error is + signaled. Help: *desc Status: Stable RPP API functions used: - - hal_gpio_pin_get_dsc - - hal_gpio_pin_set_value - - hal_gpio_pin_conf_set + - rpp_gio_setup + - rpp_gio_set Relevant demos: - gio_demo @@ -75,20 +74,12 @@ Relevant demos: /** Identifiers of the block parameters */ enum params{ - PARAM_PORT_TYPE, - PARAM_PIN_NUMBER, + PARAM_PIN_NAME, PARAM_DEFAULT_OUTPUT, PARAM_OUTPUT_TYPE, PARAMS_COUNT }; -enum port_types{ - PORT_UNKNOWN, - PORT_GIOA, - PORT_GIOB, - PORT_NHET1 -}; - enum inputs{ IN_PIN_VALUE, INPUTS_COUNT @@ -96,13 +87,6 @@ enum inputs{ static void mdlInitializeSizes(SimStruct *S) { - /* - * Configure parameters: 4 - * - Port type - * - Pin number - * - Default output value - * - Output type - */ if (!rppSetNumParams(S, PARAMS_COUNT)) { return; } @@ -132,47 +116,37 @@ static void mdlInitializeSizes(SimStruct *S) #define MDL_CHECK_PARAMETERS static void mdlCheckParameters(SimStruct *S) { - if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) { - if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) { - return; - } - } - else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) { - if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) { - return; - } - } - else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) { - if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) { - return; - } - } - else { - return; - } - + if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) { + ssSetErrorStatus(S, "Parameter to S-function must be a string."); + } if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) { return; } } #endif - -#ifdef MATLAB_MEX_FILE -#define MDL_SET_WORK_WIDTHS -static void mdlSetWorkWidths(SimStruct *S) +#if defined(MATLAB_MEX_FILE) +#define MDL_RTW +static void mdlRTW(SimStruct *S) { - /* Set number of run-time parameters */ - if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) { - return; - } - /* Register the run-time parameter 1 */ - ssRegDlgParamAsRunTimeParam(S, PARAM_PORT_TYPE, PARAM_PORT_TYPE, PARAM_NAME_PORT_TYPE, SS_INT8); - ssRegDlgParamAsRunTimeParam(S, PARAM_PIN_NUMBER, PARAM_PIN_NUMBER, PARAM_NAME_PIN_NUMBER, SS_INT8); - ssRegDlgParamAsRunTimeParam(S, PARAM_DEFAULT_OUTPUT, PARAM_DEFAULT_OUTPUT, PARAM_NAME_DEFAULT_OUTPUT, SS_BOOLEAN); - ssRegDlgParamAsRunTimeParam(S, PARAM_OUTPUT_TYPE, PARAM_OUTPUT_TYPE, PARAM_NAME_OUTPUT_TYPE, SS_INT8); + char_T pin_name[80]; + int8_T def_out = mxGetPr(ssGetSFcnParam(S, PARAM_DEFAULT_OUTPUT))[0]; + int8_T out_type = mxGetPr(ssGetSFcnParam(S, PARAM_OUTPUT_TYPE))[0]; + + if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) { + ssSetErrorStatus(S,"mxGetString error in mdlRTW"); + return; + } + + if (!ssWriteRTWParamSettings(S, 3, + SSWRITE_VALUE_STR, "PinName", pin_name, + SSWRITE_VALUE_DTYPE_NUM, "DefOut", &def_out, DTINFO(SS_INT8, COMPLEX_NO), + SSWRITE_VALUE_DTYPE_NUM, "OutType", &out_type, DTINFO(SS_INT8, COMPLEX_NO))) { + ssSetErrorStatus(S, "ssWriteRTWParamSettings failed"); + } } -#endif +#endif /* MDL_RTW */ + #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT diff --git a/rpp/blocks/tlc_c/sfunction_gio_in.tlc b/rpp/blocks/tlc_c/sfunction_gio_in.tlc index 2229578..7190fd8 100644 --- a/rpp/blocks/tlc_c/sfunction_gio_in.tlc +++ b/rpp/blocks/tlc_c/sfunction_gio_in.tlc @@ -35,42 +35,30 @@ %endfunction %function BlockInstanceSetup(block, system) void - %assign port_par = LibBlockParameterValue(port_type, 0) - %assign pin_number_par = LibBlockParameterValue(pin_number, 0) + %assign pin_name = SFcnParamSettings.PinName %% Ensure that every pin is configured only once - %if EXISTS("::rpp_gio_%_%_present") == 0 - %assign ::rpp_gio_%_%_present = 1 + %if EXISTS("::rpp_gio_%_present") == 0 + %assign ::rpp_gio_%_present = 1 %else - % on port % has already been configured.")> + % has already been configured.")> %endif %endfunction %% Function: Start ============================================================= %function Start(block, system) Output - %assign port_par = LibBlockParameterValue(port_type, 0) - %assign pin_number_par = LibBlockParameterValue(pin_number, 0) - %assign config = LibBlockParameterValue(input_type, 0) + %assign pin_name = SFcnParamSettings.PinName + %assign pull_type = SFcnParamSettings.PullType %if !SLibCodeGenForSim() - %if port_par == 1 %% GIOA - %assign pin = "PIN_GIOA%" - %elseif port_par == 2 %% GIOB - %assign pin = "PIN_GIOB%" - %elseif port_par == 3 %% NHET1 - %assign pin = "PIN_NHET1%" - %else - %")> - %endif - - %if config == 1 %% Tri-state - rpp_gio_setup(%, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, FALSE); - %elseif config == 2 %% Pull up - rpp_gio_setup(%, RPP_GIO_IN, RPP_GIO_MODE_PULLUP, FALSE); - %elseif config == 3 %% Pull down - rpp_gio_setup(%, RPP_GIO_IN, RPP_GIO_MODE_PULLDOWN, FALSE); + %if pull_type == 1 %% Tri-state + rpp_gio_setup(PIN_%, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, FALSE); + %elseif pull_type == 2 %% Pull up + rpp_gio_setup(PIN_%, RPP_GIO_IN, RPP_GIO_MODE_PULLUP, FALSE); + %elseif pull_type == 3 %% Pull down + rpp_gio_setup(PIN_%, RPP_GIO_IN, RPP_GIO_MODE_PULLDOWN, FALSE); %else %% error - %")> + %")> %endif %endif @@ -82,19 +70,9 @@ %if !SLibCodeGenForSim() %assign digital_in = LibBlockOutputSignal(0, "", "", 0) - %assign port_par = LibBlockParameterValue(port_type, 0) - %assign pin_number_par = LibBlockParameterValue(pin_number, 0) - %if port_par == 1 %% GIOA - %assign pin = "PIN_GIOA%" - %elseif port_par == 2 %% GIOB - %assign pin = "PIN_GIOB%" - %elseif port_par == 3 %% NHET1 - %assign pin = "PIN_NHET1%" - %else - %")> - %endif + %assign pin_name = SFcnParamSettings.PinName /% TODO: Handle FAILURE (add error output?) %/ - % = rpp_gio_get(%) ? TRUE : FALSE; + % = rpp_gio_get(PIN_%) ? TRUE : FALSE; %endif %endfunction diff --git a/rpp/blocks/tlc_c/sfunction_gio_out.tlc b/rpp/blocks/tlc_c/sfunction_gio_out.tlc index 14f2caa..dcee298 100644 --- a/rpp/blocks/tlc_c/sfunction_gio_out.tlc +++ b/rpp/blocks/tlc_c/sfunction_gio_out.tlc @@ -35,46 +35,34 @@ %endfunction %function BlockInstanceSetup(block, system) void - %assign port_par = LibBlockParameterValue(port_type, 0) - %assign pin_number_par = LibBlockParameterValue(pin_number, 0) + %assign pin_name = SFcnParamSettings.PinName %% Ensure that every pin is configured only once - %if EXISTS("::rpp_gio_%_%_present") == 0 - %assign ::rpp_gio_%_%_present = 1 + %if EXISTS("::rpp_gio_%_present") == 0 + %assign ::rpp_gio_%_present = 1 %else - % on port % has already been configred.")> + % has already been configured.")> %endif %endfunction %% Function: Start ============================================================= %function Start(block, system) Output - %assign port_par = LibBlockParameterValue(port_type, 0) - %assign pin_number_par = LibBlockParameterValue(pin_number, 0) - %assign config = LibBlockParameterValue(output_type, 0) - %assign init_val = LibBlockParameterValue(default_output, 0) + %assign pin_name = SFcnParamSettings.PinName + %assign config = SFcnParamSettings.OutType + %assign init_val = SFcnParamSettings.DefOut %if !SLibCodeGenForSim() - %if port_par == 1 %% GIOA - %assign pin = "PIN_GIOA%" - %elseif port_par == 2 %% GIOB - %assign pin = "PIN_GIOB%" - %elseif port_par == 3 %% NHET1 - %assign pin = "PIN_NHET1%" - %else - %")> - %endif - %if config == 1 %% Open drain - rpp_gio_setup(%, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, TRUE); + rpp_gio_setup(PIN_%, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, TRUE); %elseif config == 2 %% push/pull - rpp_gio_setup(%, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, FALSE); + rpp_gio_setup(PIN_%, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, FALSE); %else %% error %")> %endif %if init_val == 0 - rpp_gio_set(%, FALSE); + rpp_gio_set(PIN_%, FALSE); %elseif init_val == 1 - rpp_gio_set(%, TRUE); + rpp_gio_set(PIN_%, TRUE); %else %")> %endif @@ -85,25 +73,11 @@ %% Function: Outputs =========================================================== %function Outputs(block, system) Output - - %if !SLibCodeGenForSim() - %assign digital_out = LibBlockInputSignal(0, "", "", 0) - %assign port_par = LibBlockParameterValue(port_type, 0) - %assign pin_number_par = LibBlockParameterValue(pin_number, 0) - - %if port_par == 1 %% GIOA - %assign pin = "PIN_GIOA%" - %elseif port_par == 2 %% GIOB - %assign pin = "PIN_GIOB%" - %elseif port_par == 3 %% NHET1 - %assign pin = "PIN_NHET1%" - %else - %")> - %endif - - rpp_gio_set(%, %); - %endif - + %if !SLibCodeGenForSim() + %assign pin_name = SFcnParamSettings.PinName + %assign digital_out = LibBlockInputSignal(0, "", "", 0) + rpp_gio_set(PIN_%, %); + %endif %endfunction %% [EOF] diff --git a/rpp/lib b/rpp/lib index b9c1422..87cafbf 160000 --- a/rpp/lib +++ b/rpp/lib @@ -1 +1 @@ -Subproject commit b9c14221d9d95c415ea02c0ba34dbf87d90ddbaf +Subproject commit 87cafbf47799a5aefe54edf0a7ec5d9fa9fba22f diff --git a/rpp/rpp/rpp_setup.m b/rpp/rpp/rpp_setup.m index 2271c53..e402b48 100644 --- a/rpp/rpp/rpp_setup.m +++ b/rpp/rpp/rpp_setup.m @@ -94,6 +94,7 @@ function rpp_setup(varargin) % Generate blocks and library cd('../blocks'); compile_blocks(); + rpp_update_blocks_for_target() rpp_generate_lib(); cd(currentPath);