]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_frayreceive.c
Merge branch 'master' of rtime:jenkicar/rpp-simulink
[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 document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : sfunction_frayreceive.c
12  * Abstract:
13  *     C-MEX S-function block for RPP FlexRay RX buffer configuration and message receiving.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_frayreceive.c
21  */
22
23
24 #define S_FUNCTION_NAME sfunction_frayreceive
25 #include "header.c"
26 #include <stdio.h>
27
28 enum params {
29         channel_IDX                                             = 0,
30         cycleCounterFiltering_IDX               = 1,
31         maxPayload_IDX                                  = 2,
32         msgBufferInterrupt_IDX                  = 3,
33         payloadPreambleIndicatorTr_IDX  = 4,
34         singleTransmit_IDX                              = 5,
35         slotId_IDX                                              = 6,
36         PARAM_COUNT
37 };
38
39 enum outputs {
40         OUTPUT_ERROR_FLAG,
41         OUTPUT_MESSAGE,
42         OUTPUT_LENGTH,
43         OUTPUT_TRIGGER,
44         OUTPUT_COUNT,
45 };
46
47
48 static void mdlInitializeSizes(SimStruct *S)
49 {
50     if (!rppSetNumParams(S, PARAM_COUNT)) {
51         return;
52     }
53
54     /*
55      * Configure input ports: 0
56      */
57     if (!ssSetNumInputPorts(S, 0)) {
58         return;
59     }
60
61
62     /*
63      * Configure output ports: 4
64      *  - Error flag.
65          *  - Message
66          *  - Length (number of received bytes)
67          *  - Trigger
68      */
69     if (!ssSetNumOutputPorts(S, OUTPUT_COUNT)) {
70         return;
71     }
72         rppAddOutputPort(S, OUTPUT_ERROR_FLAG, SS_BOOLEAN);
73         rppAddOutputVectorPort(S, OUTPUT_MESSAGE, SS_UINT8, 2*(int_T)mxGetPr(ssGetSFcnParam(S, 2))[0]);
74         rppAddOutputPort(S, OUTPUT_LENGTH, SS_UINT8);
75         rppAddOutputPort(S, OUTPUT_TRIGGER, SS_BOOLEAN);
76
77     /* Set standard options for this block */
78     rppSetStandardOptions(S);
79 }
80
81
82 #ifdef MATLAB_MEX_FILE
83 #define MDL_CHECK_PARAMETERS
84 static void mdlCheckParameters(SimStruct *S)
85 {
86
87 }
88 #endif
89
90
91 #ifdef MATLAB_MEX_FILE
92 #define MDL_SET_WORK_WIDTHS
93 static void mdlSetWorkWidths(SimStruct *S)
94 {
95     /* Set number of run-time parameters */
96     if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
97         return;
98     }
99
100     /* Register the run-time parameter 1 */
101     ssRegDlgParamAsRunTimeParam(S, channel_IDX, channel_IDX, "channel", SS_UINT8);
102     ssRegDlgParamAsRunTimeParam(S, cycleCounterFiltering_IDX, cycleCounterFiltering_IDX, "cycleCounterFiltering", SS_UINT8);
103     ssRegDlgParamAsRunTimeParam(S, maxPayload_IDX, maxPayload_IDX, "maxPayload", SS_UINT8);
104     ssRegDlgParamAsRunTimeParam(S, msgBufferInterrupt_IDX, msgBufferInterrupt_IDX, "msgBufferInterrupt", SS_BOOLEAN);
105     ssRegDlgParamAsRunTimeParam(S, payloadPreambleIndicatorTr_IDX, payloadPreambleIndicatorTr_IDX, "payloadPreambleIndicatorTr", SS_BOOLEAN);
106     ssRegDlgParamAsRunTimeParam(S, singleTransmit_IDX, singleTransmit_IDX, "singleTransmit", SS_BOOLEAN);
107     ssRegDlgParamAsRunTimeParam(S, slotId_IDX, slotId_IDX, "slotId", SS_UINT32);
108 }
109 #endif
110
111
112 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
113 #define UNUSED_MDLOUTPUTS
114 #define UNUSED_MDLTERMINATE
115 #include "trailer.c"