]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_frayreceive.c
f8decdbf36366a1c957bd817c123ac2d7cad5809
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_frayreceive.c
1 /* Copyright (C) 2013, 2014 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 %YAML 1.2
25 ---
26 Name: Configure RX buffer
27 Category: FlexRayin
28 Header: rpp/fr.h
29 Mnemonic: FRC
30
31 Inputs:
32
33 Outputs:
34   - { name: "ErrFlag", type: "bool" }
35   - { name: "Receive", type: "uint8 vector" }
36   - { name: "Length", type: "uint8" }
37   - { name: "Trigger", type: "bool" }
38
39 Parameters:
40   - { name: "channel", type: "uint8" }
41   - { name: "cycleCounterFiltering", type: "uint8" }
42   - { name: "maxPayload", type: "uint8", range: "(in half-words)" }
43   - { name: "msgBufferInterrupt", type: "bool" }
44   - { name: "payloadPreambleIndicatorTr", type: "bool" }
45   - { name: "singleTransmit", type: "bool" }
46   - { name: "slotId", type: "uint32" }
47   - { name: "bufferId", type: "uint32" }
48
49 # Description and Help is in Markdown mark-up
50 Description: &desc |
51
52   This block ...
53
54 Help: *desc
55
56 Status: Beta
57
58 RPP API functions used:
59
60 Relevant demos:
61 ...
62 */
63
64 #define S_FUNCTION_NAME sfunction_frayreceive
65 #include "header.c"
66 #include <stdio.h>
67
68 enum params {
69         channel_IDX                                             = 0,
70         cycleCounterFiltering_IDX               = 1,
71         maxPayload_IDX                                  = 2,
72         msgBufferInterrupt_IDX                  = 3,
73         payloadPreambleIndicatorTr_IDX  = 4,
74         singleTransmit_IDX                              = 5,
75         slotId_IDX                                              = 6,
76         bufferId_IDX                                    = 7,
77         PARAM_COUNT
78 };
79
80 enum outputs {
81         OUTPUT_ERROR_FLAG,
82         OUTPUT_MESSAGE,
83         OUTPUT_LENGTH,
84         OUTPUT_TRIGGER,
85         OUTPUT_COUNT,
86 };
87
88
89 static void mdlInitializeSizes(SimStruct *S)
90 {
91     if (!rppSetNumParams(S, PARAM_COUNT)) {
92         return;
93     }
94
95     /*
96      * Configure input ports: 0
97      */
98     if (!ssSetNumInputPorts(S, 0)) {
99         return;
100     }
101
102
103     /*
104      * Configure output ports: 4
105      *  - Error flag.
106          *  - Message
107          *  - Length (number of received bytes)
108          *  - Trigger
109      */
110     if (!ssSetNumOutputPorts(S, OUTPUT_COUNT)) {
111         return;
112     }
113         rppAddOutputPort(S, OUTPUT_ERROR_FLAG, SS_BOOLEAN);
114         rppAddOutputVectorPort(S, OUTPUT_MESSAGE, SS_UINT8, 2*(int_T)mxGetPr(ssGetSFcnParam(S, 2))[0]);
115         rppAddOutputPort(S, OUTPUT_LENGTH, SS_UINT8);
116         rppAddOutputPort(S, OUTPUT_TRIGGER, SS_BOOLEAN);
117
118     /* Set standard options for this block */
119     rppSetStandardOptions(S);
120 }
121
122
123 #ifdef MATLAB_MEX_FILE
124 #define MDL_CHECK_PARAMETERS
125 static void mdlCheckParameters(SimStruct *S)
126 {
127
128 }
129 #endif
130
131
132 #ifdef MATLAB_MEX_FILE
133 #define MDL_SET_WORK_WIDTHS
134 static void mdlSetWorkWidths(SimStruct *S)
135 {
136     /* Set number of run-time parameters */
137     if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
138         return;
139     }
140
141     /* Register the run-time parameter 1 */
142     ssRegDlgParamAsRunTimeParam(S, channel_IDX, channel_IDX, "channel", SS_UINT8);
143     ssRegDlgParamAsRunTimeParam(S, cycleCounterFiltering_IDX, cycleCounterFiltering_IDX, "cycleCounterFiltering", SS_UINT8);
144     ssRegDlgParamAsRunTimeParam(S, maxPayload_IDX, maxPayload_IDX, "maxPayload", SS_UINT8);
145     ssRegDlgParamAsRunTimeParam(S, msgBufferInterrupt_IDX, msgBufferInterrupt_IDX, "msgBufferInterrupt", SS_BOOLEAN);
146     ssRegDlgParamAsRunTimeParam(S, payloadPreambleIndicatorTr_IDX, payloadPreambleIndicatorTr_IDX, "payloadPreambleIndicatorTr", SS_BOOLEAN);
147     ssRegDlgParamAsRunTimeParam(S, singleTransmit_IDX, singleTransmit_IDX, "singleTransmit", SS_BOOLEAN);
148     ssRegDlgParamAsRunTimeParam(S, slotId_IDX, slotId_IDX, "slotId", SS_UINT32);
149     ssRegDlgParamAsRunTimeParam(S, bufferId_IDX, bufferId_IDX, "bufferId", SS_UINT32);
150 }
151 #endif
152
153
154 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
155 #define UNUSED_MDLOUTPUTS
156 #define UNUSED_MDLTERMINATE
157 #include "trailer.c"