This (target-specific) list is updated by rpp_setup.
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
/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
--- /dev/null
+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
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
#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
static void mdlInitializeSizes(SimStruct *S)
{
- /*
- * Configure parameters: 3
- * - Port type
- * - Pin number
- * - Input type
- */
if (!rppSetNumParams(S, PARAMS_COUNT)) {
return;
}
#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
-/* Copyright (C) 2013, 2014 Czech Technical University in Prague
+/* Copyright (C) 2013, 2014, 2015 Czech Technical University in Prague
*
* Authors:
* - Carlos Jenkins <carlos@jenkins.co.cr>
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
/** 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
static void mdlInitializeSizes(SimStruct *S)
{
- /*
- * Configure parameters: 4
- * - Port type
- * - Pin number
- * - Default output value
- * - Output type
- */
if (!rppSetNumParams(S, PARAMS_COUNT)) {
return;
}
#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
%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_%<port_par>_%<pin_number_par>_present") == 0
- %assign ::rpp_gio_%<port_par>_%<pin_number_par>_present = 1
+ %if EXISTS("::rpp_gio_%<pin_name>_present") == 0
+ %assign ::rpp_gio_%<pin_name>_present = 1
%else
- %<LibBlockReportError(block, "GIO pin %<pin_number_par> on port %<port_par> has already been configured.")>
+ %<LibBlockReportError(block, "GIO pin %<pin_name> 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%<pin_number_par>"
- %elseif port_par == 2 %% GIOB
- %assign pin = "PIN_GIOB%<pin_number_par>"
- %elseif port_par == 3 %% NHET1
- %assign pin = "PIN_NHET1%<pin_number_par>"
- %else
- %<LibBlockReportError(block, "Bad port identifier: %<port_par>")>
- %endif
-
- %if config == 1 %% Tri-state
- rpp_gio_setup(%<pin>, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, FALSE);
- %elseif config == 2 %% Pull up
- rpp_gio_setup(%<pin>, RPP_GIO_IN, RPP_GIO_MODE_PULLUP, FALSE);
- %elseif config == 3 %% Pull down
- rpp_gio_setup(%<pin>, RPP_GIO_IN, RPP_GIO_MODE_PULLDOWN, FALSE);
+ %if pull_type == 1 %% Tri-state
+ rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, FALSE);
+ %elseif pull_type == 2 %% Pull up
+ rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_IN, RPP_GIO_MODE_PULLUP, FALSE);
+ %elseif pull_type == 3 %% Pull down
+ rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_IN, RPP_GIO_MODE_PULLDOWN, FALSE);
%else %% error
- %<LibBlockReportError(block, "Bad configuration value: %<config>")>
+ %<LibBlockReportError(block, "Bad pull_type value: %<pull_type>")>
%endif
%endif
%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%<pin_number_par>"
- %elseif port_par == 2 %% GIOB
- %assign pin = "PIN_GIOB%<pin_number_par>"
- %elseif port_par == 3 %% NHET1
- %assign pin = "PIN_NHET1%<pin_number_par>"
- %else
- %<LibBlockReportError(block, "Bad port identifier: %<port_par>")>
- %endif
+ %assign pin_name = SFcnParamSettings.PinName
/% TODO: Handle FAILURE (add error output?) %/
- %<digital_in> = rpp_gio_get(%<pin>) ? TRUE : FALSE;
+ %<digital_in> = rpp_gio_get(PIN_%<pin_name>) ? TRUE : FALSE;
%endif
%endfunction
%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_%<port_par>_%<pin_number_par>_present") == 0
- %assign ::rpp_gio_%<port_par>_%<pin_number_par>_present = 1
+ %if EXISTS("::rpp_gio_%<pin_name>_present") == 0
+ %assign ::rpp_gio_%<pin_name>_present = 1
%else
- %<LibBlockReportError(block, "GIO pin %<pin_number_par> on port %<port_par> has already been configred.")>
+ %<LibBlockReportError(block, "GIO pin %<pin_name> 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%<pin_number_par>"
- %elseif port_par == 2 %% GIOB
- %assign pin = "PIN_GIOB%<pin_number_par>"
- %elseif port_par == 3 %% NHET1
- %assign pin = "PIN_NHET1%<pin_number_par>"
- %else
- %<LibBlockReportError(block, "Bad port identifier: %<port_par>")>
- %endif
-
%if config == 1 %% Open drain
- rpp_gio_setup(%<pin>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, TRUE);
+ rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, TRUE);
%elseif config == 2 %% push/pull
- rpp_gio_setup(%<pin>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, FALSE);
+ rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, FALSE);
%else %% error
%<LibBlockReportError(block, "Bad configuration value: %<config>")>
%endif
%if init_val == 0
- rpp_gio_set(%<pin>, FALSE);
+ rpp_gio_set(PIN_%<pin_name>, FALSE);
%elseif init_val == 1
- rpp_gio_set(%<pin>, TRUE);
+ rpp_gio_set(PIN_%<pin_name>, TRUE);
%else
%<LibBlockReportError(block, "Bad init output value: %<init_val>")>
%endif
%% 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%<pin_number_par>"
- %elseif port_par == 2 %% GIOB
- %assign pin = "PIN_GIOB%<pin_number_par>"
- %elseif port_par == 3 %% NHET1
- %assign pin = "PIN_NHET1%<pin_number_par>"
- %else
- %<LibBlockReportError(block, "Bad port identifier: %<port_par>")>
- %endif
-
- rpp_gio_set(%<pin>, %<digital_out>);
- %endif
-
+ %if !SLibCodeGenForSim()
+ %assign pin_name = SFcnParamSettings.PinName
+ %assign digital_out = LibBlockInputSignal(0, "", "", 0)
+ rpp_gio_set(PIN_%<pin_name>, %<digital_out>);
+ %endif
%endfunction
%% [EOF]
-Subproject commit b9c14221d9d95c415ea02c0ba34dbf87d90ddbaf
+Subproject commit 87cafbf47799a5aefe54edf0a7ec5d9fa9fba22f
% Generate blocks and library
cd('../blocks');
compile_blocks();
+ rpp_update_blocks_for_target()
rpp_generate_lib();
cd(currentPath);