]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_gio_in.tlc
Merge branch 'master' into all-targets
[jenkicar/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_gio_in.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_in.tlc
13 %% Abstract:
14 %%     TLC file for inlining RPP digital input 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_in "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_in_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(input_type, 0)
54
55         %if !SLibCodeGenForSim()
56                 %openfile buffer
57                 uint32_t* din_%<port_par>_%<pin_number_par>_desc = NULL;
58                 %closefile buffer
59                 %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
60
61                 uint32_t din_%<port_par>_%<pin_number_par>_cfg = PORT_CONF_FNC_GPIO|PORT_CONF_DIR_IN;
62                 %if port_par == 1       %% GIOA
63                         %assign name = "GIOA%<pin_number_par>"
64                 %elseif port_par == 2   %% GIOB
65                         %assign name = "GIOB%<pin_number_par>"
66                 %elseif port_par == 3   %% NHET1
67                         %assign name = "NHET1%<pin_number_par>"
68                 %else
69                         %<LibBlockReportError(block, "Bad port identifier: %<port_par>")>
70                 %endif
71
72                 din_%<port_par>_%<pin_number_par>_desc = hal_gpio_pin_get_dsc("%<name>", -1);
73
74                 %if config == 1         %% Tri-state
75                         din_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_MODE_PDIS|PORT_CONF_OD_ON;
76                 %elseif config == 2     %% Pull up
77                         din_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_MODE_PEN|PORT_CONF_OD_OFF|PORT_CONF_MODE_PU;
78                 %elseif config == 3     %% Pull down
79                         din_%<port_par>_%<pin_number_par>_cfg |= PORT_CONF_MODE_PEN|PORT_CONF_OD_OFF|PORT_CONF_MODE_PD;
80                 %else   %% error
81                         %<LibBlockReportError(block, "Bad configuration value: %<config>")>
82                 %endif
83
84                 hal_gpio_pin_conf_set(*din_%<port_par>_%<pin_number_par>_desc, din_%<port_par>_%<pin_number_par>_cfg);
85                 
86         %endif
87
88 %endfunction
89
90
91 %% Function: Outputs ===========================================================
92 %function Outputs(block, system) Output
93
94         %if !SLibCodeGenForSim()
95                 %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
96                 %assign port_par = LibBlockParameterValue(port_type, 0)
97                 %assign pin_number_par = LibBlockParameterValue(pin_number, 0)
98                 uint32_t din_%<port_par>_%<pin_number_par>_val = hal_gpio_pin_get_value(*din_%<port_par>_%<pin_number_par>_desc);
99                 %<digital_in> = din_%<port_par>_%<pin_number_par>_val;
100         %endif
101
102 %endfunction
103
104 %% [EOF]