]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_frayreceive.c
FlexRay basic library add, demo for basic communication add
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_frayreceive.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Michal Horn <hornimch@fel.cvut.cz>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * File : sfunction_frayreceive.c
20  * Abstract:
21  *     C-MEX S-function block for RPP FlexRay RX buffer configuration and message receiving.
22  *
23  * References:
24  *     header.c
25  *     trailer.c
26  *
27  * Compile with:
28  *     <matlabroot>/bin/mex sfunction_frayreceive.c
29  */
30
31
32 #define S_FUNCTION_NAME sfunction_frayreceive
33 #include "header.c"
34 #include <stdio.h>
35
36 #define channel_IDX                                             0
37 #define cycleCounterFiltering_IDX               1
38 #define maxPayload_IDX                                  2
39 #define msgBufferInterrupt_IDX                  3
40 #define payloadPreambleIndicatorTr_IDX  4
41 #define singleTransmit_IDX                              5
42 #define slotId_IDX                                              6
43
44
45 static void mdlInitializeSizes(SimStruct *S)
46 {
47     /*
48      * Configure parameters: 25
49          * channel (0 - A, 1 - B, 2 - AB)
50          * cycleCounterFiltering
51          * maxPayload
52          * msgBufferInterrupt
53          * payloadPreambleIndicatorTr
54          * singleTransmit
55          * slotId
56      */
57     if(!rppSetNumParams(S, 7)) {
58         return;
59     }
60
61     /*
62      * Configure input ports: 0
63      */
64     if(!ssSetNumInputPorts(S, 0)) {
65         return;
66     }
67
68
69     /*
70      * Configure output ports: 4
71      *  - Error flag.
72          *  - Message
73          *  - Length (number of received bytes)
74          *  - Trigger
75      */
76     if(!ssSetNumOutputPorts(S, 4U)) {
77         return;
78     }
79     rppAddOutputPort(S, 0, SS_BOOLEAN);
80     rppAddOutputPort(S, 1, SS_UINT8);
81     rppAddOutputPort(S, 2, SS_UINT8);
82     rppAddOutputPort(S, 3, SS_BOOLEAN);
83
84     /* Set standard options for this block */
85     rppSetStandardOptions(S);
86 }
87
88
89 #ifdef MATLAB_MEX_FILE
90 #define MDL_CHECK_PARAMETERS
91 static void mdlCheckParameters(SimStruct *S)
92 {
93
94 }
95 #endif
96
97
98 #ifdef MATLAB_MEX_FILE
99 #define MDL_SET_WORK_WIDTHS
100 static void mdlSetWorkWidths(SimStruct *S)
101 {
102     /* Set number of run-time parameters */
103     if(!ssSetNumRunTimeParams(S, 7)) {
104         return;
105     }
106
107     /* Register the run-time parameter 1 */
108         ssRegDlgParamAsRunTimeParam(S, channel_IDX, channel_IDX, "channel", SS_UINT8);
109         ssRegDlgParamAsRunTimeParam(S, cycleCounterFiltering_IDX, cycleCounterFiltering_IDX, "cycleCounterFiltering", SS_UINT8);
110         ssRegDlgParamAsRunTimeParam(S, maxPayload_IDX, maxPayload_IDX, "maxPayload", SS_UINT8);
111         ssRegDlgParamAsRunTimeParam(S, msgBufferInterrupt_IDX, msgBufferInterrupt_IDX, "msgBufferInterrupt", SS_BOOLEAN);
112         ssRegDlgParamAsRunTimeParam(S, payloadPreambleIndicatorTr_IDX, payloadPreambleIndicatorTr_IDX, "payloadPreambleIndicatorTr", SS_BOOLEAN);
113         ssRegDlgParamAsRunTimeParam(S, singleTransmit_IDX, singleTransmit_IDX, "singleTransmit", SS_BOOLEAN);
114         ssRegDlgParamAsRunTimeParam(S, slotId_IDX, slotId_IDX, "slotId", SS_UINT32);
115 }
116 #endif
117
118
119 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
120 #define UNUSED_MDLOUTPUTS
121 #define UNUSED_MDLTERMINATE
122 #include "trailer.c"