]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_frayreceive.c
FlexRay receive and transmit blocks modified to send and receive multiple bytes
[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 enum params {
37         channel_IDX                                             = 0,
38         cycleCounterFiltering_IDX               = 1,
39         maxPayload_IDX                                  = 2,
40         msgBufferInterrupt_IDX                  = 3,
41         payloadPreambleIndicatorTr_IDX  = 4,
42         singleTransmit_IDX                              = 5,
43         slotId_IDX                                              = 6,
44         PARAM_COUNT
45 };
46
47 enum outputs {
48         OUTPUT_ERROR_FLAG,
49         OUTPUT_MESSAGE,
50         OUTPUT_LENGTH,
51         OUTPUT_TRIGGER,
52         OUTPUT_COUNT,
53 };
54
55
56 static void mdlInitializeSizes(SimStruct *S)
57 {
58     if(!rppSetNumParams(S, PARAM_COUNT)) {
59         return;
60     }
61
62     /*
63      * Configure input ports: 0
64      */
65     if(!ssSetNumInputPorts(S, 0)) {
66         return;
67     }
68
69
70     /*
71      * Configure output ports: 4
72      *  - Error flag.
73          *  - Message
74          *  - Length (number of received bytes)
75          *  - Trigger
76      */
77     if(!ssSetNumOutputPorts(S, OUTPUT_COUNT)) {
78         return;
79     }
80         rppAddOutputPort(S, OUTPUT_ERROR_FLAG, SS_BOOLEAN);
81         rppAddOutputVectorPort(S, OUTPUT_MESSAGE, SS_UINT8, 2*(int_T)mxGetPr(ssGetSFcnParam(S, 2))[0]);
82         rppAddOutputPort(S, OUTPUT_LENGTH, SS_UINT8);
83         rppAddOutputPort(S, OUTPUT_TRIGGER, SS_BOOLEAN);
84
85     /* Set standard options for this block */
86     rppSetStandardOptions(S);
87 }
88
89
90 #ifdef MATLAB_MEX_FILE
91 #define MDL_CHECK_PARAMETERS
92 static void mdlCheckParameters(SimStruct *S)
93 {
94
95 }
96 #endif
97
98
99 #ifdef MATLAB_MEX_FILE
100 #define MDL_SET_WORK_WIDTHS
101 static void mdlSetWorkWidths(SimStruct *S)
102 {
103     /* Set number of run-time parameters */
104     if(!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
105         return;
106     }
107
108     /* Register the run-time parameter 1 */
109     ssRegDlgParamAsRunTimeParam(S, channel_IDX, channel_IDX, "channel", SS_UINT8);
110     ssRegDlgParamAsRunTimeParam(S, cycleCounterFiltering_IDX, cycleCounterFiltering_IDX, "cycleCounterFiltering", SS_UINT8);
111     ssRegDlgParamAsRunTimeParam(S, maxPayload_IDX, maxPayload_IDX, "maxPayload", SS_UINT8);
112     ssRegDlgParamAsRunTimeParam(S, msgBufferInterrupt_IDX, msgBufferInterrupt_IDX, "msgBufferInterrupt", SS_BOOLEAN);
113     ssRegDlgParamAsRunTimeParam(S, payloadPreambleIndicatorTr_IDX, payloadPreambleIndicatorTr_IDX, "payloadPreambleIndicatorTr", SS_BOOLEAN);
114     ssRegDlgParamAsRunTimeParam(S, singleTransmit_IDX, singleTransmit_IDX, "singleTransmit", SS_BOOLEAN);
115     ssRegDlgParamAsRunTimeParam(S, slotId_IDX, slotId_IDX, "slotId", SS_UINT32);
116 }
117 #endif
118
119
120 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
121 #define UNUSED_MDLOUTPUTS
122 #define UNUSED_MDLTERMINATE
123 #include "trailer.c"