FreeHIL
Loading...
Searching...
No Matches
FH_RFCommunication_Configs.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief
4 * <b>File Map:</b>\n
5 * <b>FH_Setup</b>, Section <b>FH_RFCommunication</b>\n
6 * The micro-controller on which <b>FH</b> source code is ported, could be simply utilized in a <b>RS485 network</b>\n
7 * In other word, multiple devices or multiple cards could be simply utilized where every device or every card has its own address\n
8 * Address of the device (or card) for every device (or card) is set by <b>FH</b> user in <b>FH_DeviceAddress.h</b>\n
9 * An interested UART (called <b>Communication Dedicated UART</b>) by the <b>FH</b> user for the communication between <b>RobotFramework</b> and the micro-controller on which <b>FH</b> source code is ported, shall be dedicated\n
10 * Different configuration on the communication between <b>RobotFramework</b> and the micro-controller are defined here
11 *
12 * @attention <b>FH</b> user could left this file intact
13 *
14 *******************************************************************************
15 * SPDX-License-Identifier: Apache-2.0
16 *
17 * Copyright 2026 Vahid Hasirchi
18 *
19 * Licensed under the Apache License, Version 2.0 (the "License");
20 * you may not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
22 *
23 * http://www.apache.org/licenses/LICENSE-2.0
24 *
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS,
27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
30 ********************************************************************************
31
32 *
33 * <b>For more information refer to FreeHIL.com</b>
34 *
35*/
36
37/* Define to prevent recursive inclusion -------------------------------------*/
38#ifndef FH_RFCommunication_Configs_H
39#define FH_RFCommunication_Configs_H
40
41/* Includes ------------------------------------------------------------------*/
43
44/*!
45 <b>FH_RFCommunication_MinCommandSize</b> is the minimum size of the message frame (<b>FH_RFCommunication_Message</b>) from <b>RobotFramework</b> (When DataLength is zero and there is no Data)\n
46 The minimum size includes the following items:
47 1 - DeviceAddress (1 byte)
48 2 - Function (1 byte)
49 3 - Command (1 byte)
50 4 - DataLength (1 byte) which is 0 for minimum size message
51 5 - Data (0 byte) which is not available for minimum size message
52 6 - Checksum (1 byte)
53 => Total 5 bytes of data
54*/
55#define FH_RFCommunication_MinCommandSize 5
56
57/*!
58 <b>FH_RFCommunication_ReceiveBufLength</b> is the receive buffer length of the buffer which is filled in the ISR (Interrupt Service Routine) <b>Communication Dedicated UART</b>\n
59 255 is added to FH_RFCommunication_MinCommandSize to guarantee the maximum possible Data Length of 255 bytes in the Data part of the message
60*/
61#define FH_RFCommunication_ReceiveBufLength 255 + FH_RFCommunication_MinCommandSize
62
63/*!
64 If at least one byte of data is received through the <b>ISR</b> (Interrupt Service Routine) of the <b>Communication Dedicated UART</b> by the <b>FH</b> user, a complete message shall be received in a maximum defined timeout\n
65 The received data in the <b>ISR</b> (Interrupt Service Routine) will be ignored if the complete message will not be received within the defined timeout\nFor this to happen, <b>FH_GlobalTimeCounter</b> is utilized to calculate the maximum timeout\n
66 FH_RFCommunication_ReceiveBufMaxTimeout</b> is the defined maximum timeout for every byte\n
67 In the <b>ISR</b> (Interrupt Service Routine) of the <b>Communication Dedicated UART</b> by the <b>FH</b> user, <b>FH_GlobalTimeCounter</b> shall be reset after receiving every byte of data\n
68 For example, 100 is set to have 100ms timeout (When the heart beat of the system is 1 mili-second) to receive a complete message when there is no longer any data being received
69*/
70#define FH_RFCommunication_ReceiveBufMaxTimeout 100
71
72#define FH_RFCommunication_SendBufLength 255 + FH_RFCommunication_MinCommandSize
73
74/*!
75 <b>FH_RFCommunication_Commandelements</b> includes the position of different parts of the message in the message frame (<b>FH_RFCommunication_Message</b>)
76 Since the Data part may have different sizes, the checksum position may be different
77*/
79{
80 /*!
81 The 1st data in the message frame is the <b>DeviceAddress</b>\n
82 If a message (from <b>RobotFramework</b>) with a different <b>DeviceAddress</b> than the one set in <b>FH_DeviceAddress.h</b> is received, it will be ignored and not processed
83 */
85 /*!
86 The 2nd data in the message frame is the <b>Function</b>\n
87 <b>Function</b> could be <b>DO</b> (Digital Output), <b>DI</b> (Digital Input), <b>AO</b> (Anolog Output), <b>AI</b> (Analog Input), <b>UART</b>, <b>CAN</b> , ... in <b>FH_RFCommunication_Function<b>
88 */
90 /*!
91 The 3rd data in the message frame is the <b>Command</b>\n
92 There are different commands for <b>DO</b> (Digital Output), <b>DI</b> (Digital Input), <b>AO</b> (Anolog Output), <b>AI</b> (Analog Input), <b>UART</b>, <b>CAN</b> , ...\n
93 For example for <b>DO</b> (Digital Output), different commands are available in <b>FH_DO_Configs.h</b>
94 */
96 /*!
97 The 4th data in the message frame is the <b>DataLength</b>\n
98 It is the length of the Data in the message frame\n
99 Since DataLength is just one byte, <b>Data</b> bytes can't be more than 255
100 */
102 /*!
103 The <b>Data</b> could be from 0 byte to up to (FH_RFCommunication_ReceiveBufLength - FH_RFCommunication_MinCommandSize) bytes\n
104 Since DataLength is just one byte, <b>Data</b> bytes can't be more than 255\n
105 <b>FH_RFCommunication_ReceiveBufLength</b> and <b>FH_RFCommunication_MinCommandSize</b> are configurable in this file (<b>FH_RFCommunication_Configs.h</b>)
106 */
108 /*!
109 The checksum of the message\n
110 */
111 // RFCommunication_Checksum = ?
112};
113
114/*!
115 <b>FH_RFCommunication_Function</b> includes different possible functions of the message in the message frame (<b>FH_RFCommunication_Message</b>)
116*/
118{
119 /*!
120 <b>DO</b> (Digital Output)
121 */
123 /*!
124 <b>DI</b> (Digital Input)
125 */
127 /*!
128 <b>AO</b> (Analog Output)
129 */
131 /*!
132 <b>AI</b> (Analog Input)
133 */
135 /*!
136 <b>PWMO</b> (PWM Output)
137 */
139 /*!
140 <b>PWMI</b> (PWM Input)
141 */
143 /*!
144 <b>UART</b>
145 */
147 /*!
148 <b>CAN</b>
149 */
151};
152
153/*!
154 <b>FH_RFCommunication_Message</b> is the structure for receiving the message frame from <b>RobotFramework</b>\n
155 <b>FH_RFCommunication_State</b> is the enumeration utilized as state machine to collect the different blocks of the message frame from <b>RobotFramework</b>\n
156 It is initialized with <b>RFCommunication_STATE_IDLE</b> to be ready to collect a new message from <b>RobotFramework</b>
157*/
158typedef enum
159{
160 /*!
161 State to receive a new message
162 */
164 /*!
165 State to receive DeviceAddress
166 */
168 /*!
169 State to receive Function
170 */
172 /*!
173 State to receive Command
174 */
176 /*!
177 State to receive DataLength
178 */
180 /*!
181 State to receive Data
182 */
184 /*!
185 State to receive Checksum
186 */
188 /*!
189 State to indicate a complete message is already received
190 */
193
194#endif