-/* 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>
*
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*
* File : sfunction_gio_out.c
* Abstract:
/*
%YAML 1.2
---
-Name: Global Purpose Digital Output
+Name: General Purpose Digital Output
Category: IO blocks
Header: rpp/gio.h
Mnemonic: GIOOUT
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
+ - board_init_hydctr
...
*/
+/*
+ * Block mask documentation - see sfunction_gio_in.c
+ */
#define S_FUNCTION_NAME sfunction_gio_out
#include "header.c"
/** 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