]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_gio_out.tlc
Rename DIN and DOUT to GIO IN and GIO OUT
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_gio_out.tlc
1 %% Copyright (C) 2013 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %%     - Michal Horn <hornmich@fel.cvut.cz>
6 %%
7 %% This document contains proprietary information belonging to Czech
8 %% Technical University in Prague. Passing on and copying of this
9 %% document, and communication of its contents is not permitted
10 %% without prior written authorization.
11 %%
12 %% File : sfunction_gio_out.tlc
13 %% Abstract:
14 %%     TLC file for inlining RPP digital output block.
15 %%
16 %% References:
17 %%     BlockTypeSetup() : rtw_tlc.pdf p. 277
18 %%     Start()          : rtw_tlc.pdf p. 279
19 %%     Outputs()        : rtw_tlc.pdf p. 281
20
21
22 %implements sfunction_gio_out "C"
23
24 %include "common.tlc"
25
26
27 %% Function: BlockTypeSetup ====================================================
28 %function BlockTypeSetup(block, system) void
29
30         %% Ensure required header files are included
31         %<RppCommonBlockTypeSetup(block, system)>
32         %<LibAddToCommonIncludes("rpp/rpp.h")>
33         %assign ::rpp_gio_out_present = 1
34
35 %endfunction
36
37 %function BlockInstanceSetup(block, system) void
38         %assign port_par = LibBlockParameterValue(port_type, 0)
39         %assign pin_number_par = LibBlockParameterValue(pin_number, 0)
40
41         %% Ensure that every pin is configured only once
42         %if EXISTS("::rpp_%<port_par>_%<pin_number_par>_present") == 0
43                 %assign ::rpp_%<port_par>_%<pin_number_par>_present = 1
44         %else
45                 %<LibBlockReportError(block, "GPIO pin %<pin_number_par> on port %<port_par> has already been configred.")>
46         %endif
47 %endfunction
48
49 %% Function: Start =============================================================
50 %function Start(block, system) Output
51         %assign port_par = LibBlockParameterValue(port_type, 0)
52         %assign pin_number_par = LibBlockParameterValue(pin_number, 0)
53         %assign config = LibBlockParameterValue(output_type, 0)
54         %assign init_val = LibBlockParameterValue(default_output, 0)
55
56         %if !SLibCodeGenForSim()
57                 %openfile buffer
58                 uint32_t* dout_%<port_par>_%<pin_number_par>_desc = NULL;
59                 %closefile buffer
60                 %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
61
62
63
64                 uint32_t dout_%<port_par>_%<pin_number_par>_cfg = PORT_CONF_FNC_GPIO|PORT_CONF_DIR_OUT;
65                 %if port_par == 1       %% GIOA
66                         %assign name = "GIOA%<pin_number_par>"
67                 %elseif port_par == 2   %% GIOB
68                         %assign name = "GIOB%<pin_number_par>"
69                 %elseif port_par == 3   %% NHET1
70                         %assign name = "NHET1%<pin_number_par>"
71                 %else
72                         %<LibBlockReportError(block, "Bad port identifier: %<port_par>")>
73                 %endif
74
75                 dout_%<port_par>_%<pin_number_par>_desc = hal_gpio_pin_get_dsc("%<name>", -1);
76
77                 %if init_val == 0
78                         dout_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_INIT_LOW | PORT_CONF_MODE_PD;
79                 %elseif init_val == 1
80                         dout_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_INIT_HIGH | PORT_CONF_MODE_PU;
81                 %else
82                         %<LibBlockReportError(block, "Bad init output value: %<init_val>")>
83                 %endif          
84
85                 %if config == 1         %% Open drain
86                         dout_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_MODE_PDIS|PORT_CONF_OD_ON;
87                 %elseif config == 2     %% push/pull
88                         dout_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_MODE_PEN|PORT_CONF_OD_OFF;
89                 %else   %% error
90                         %<LibBlockReportError(block, "Bad configuration value: %<config>")>
91                 %endif
92
93                 hal_gpio_pin_conf_set(*dout_%<port_par>_%<pin_number_par>_desc, dout_%<port_par>_%<pin_number_par>_cfg);
94                 
95         %endif
96
97 %endfunction
98
99
100 %% Function: Outputs ===========================================================
101 %function Outputs(block, system) Output
102
103         %if !SLibCodeGenForSim()
104                 %assign digital_out = LibBlockInputSignal(0, "", "", 0)
105                 %assign port_par = LibBlockParameterValue(port_type, 0)
106                 %assign pin_number_par = LibBlockParameterValue(pin_number, 0)
107                 hal_gpio_pin_set_value(*dout_%<port_par>_%<pin_number_par>_desc, (uint32_t) %<digital_out>);
108         %endif
109
110 %endfunction
111
112 %% [EOF]