FreeHIL
Loading...
Searching...
No Matches
FH_CAN05.c
Go to the documentation of this file.
1/**
2 * @file
3 * @brief
4 * <b>File Map:</b>\n
5 * <b>FH_Functions</b>, Section <b>FH_CAN</b> (CAN), Peripheral <b>FH_CAN05</b> (CAN 05)\n
6 * (The <b>CAN05 (CAN 05)</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported)\n
7 *
8 * @note To have a clean code, <b>FH</b> user should have the implementation of the initialization and send functions of the <b>CAN 05</b> in a separate c file\n
9 * Then <b>FH</b> user should include the header file <b>(.h)</b> of the related source file <b>(.c)</b> here\n
10 * This header file shall include the following items:\n
11 * The declaration of the initialization function of the <b>CAN 05</b>\n
12 * The declaration of the send function of the <b>CAN 05</b>\n\n
13 *
14 * <b>FH</b> user shall use <b>FH_CAN05_ReceiveBuf</b> and <b>FH_CAN05_ReceiveBufIndex</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file\n
15 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there\n
16 * In other word, <b>FH_CAN05_ReceiveBuf</b> array shall receive every byte of the received data there with <b>FH_CAN05_ReceiveBufIndex</b> as index of the array
17 *
18 * <b>FH_CAN05_SharedDataBuf_8Bits</b>, <b>FH_CAN05_SharedDataBuf_16Bits</b> and <b>FH_CAN05_SharedDataBuf_32Bits</b> are optional and could be left intact\n
19 * They could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> , ...\n
20 * They are controllable with some commands (described in this file) through <b>RobotFramework</b>\n
21 *
22 * @attention There are a total number of <b>3 attentions</b> (<b>FH</b> user defined code) in this file where <b>FH</b> user shall insert some code\n
23 * Other parts could be left intact
24 *
25 *******************************************************************************
26 * SPDX-License-Identifier: Apache-2.0
27 *
28 * Copyright 2026 Vahid Hasirchi
29 *
30 * Licensed under the Apache License, Version 2.0 (the "License");
31 * you may not use this file except in compliance with the License.
32 * You may obtain a copy of the License at
33 *
34 * http://www.apache.org/licenses/LICENSE-2.0
35 *
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an "AS IS" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
41 ********************************************************************************
42
43 *
44 * <b>For more information refer to FreeHIL.com</b>
45 *
46*/
47/* Primary Includes ------------------------------------------------------------------*/
48// Attention 1: FH user defined code (include the mentioned header file here)
49
50//
52
53#ifdef FH_CAN05 // It is configurable in FH_CAN_Configs.h
54
55#if FH_CAN_MaxPeripheralNumber > 0 // It is configurable in FH_DevicePeripherals.h
56
57/* Secondary Includes ------------------------------------------------------------------*/
63
64/*!
65 <b>FH</b> user shall use <b>FH_CAN05_ReceiveBuf</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file\n
66 For this to happen, FH user shall just include FH_CAN05_GlobalVariables.h there\n
67 In other word, <b>FH_CAN05_ReceiveBuf</b> array shall receive every byte of the received data there\n
68 It is configurable in FH_CAN05_Configs.h
69*/
71
72/*!
73 <b>FH_CAN05_ReceiveBufIndex</b> is the index of <b>FH_CAN05_ReceiveBuf</b>
74*/
75volatile uint16_t FH_CAN05_ReceiveBufIndex = 0;
76
77/*!
78 <b>FH_CAN05_SharedDataBuf_8Bits</b> is optional and could be left intact\n
79 It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> , ...
80 It are controllable with some commands (described in this file) through <b>RobotFramework</b>\n
81 It is configurable in FH_CAN05_Configs.h
82*/
84
85/*!
86 <b>FH_CAN05_SharedDataBuf_16Bits</b> is optional and could be left intact\n
87 It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> , ...
88 It are controllable with some commands (described in this file) through <b>RobotFramework</b>\n
89 It is configurable in FH_CAN05_Configs.h
90*/
92/*!
93 <b>FH_CAN05_SharedDataBuf_32Bits</b> is optional and could be left intact\n
94 It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> , ...
95 It are controllable with some commands (described in this file) through <b>RobotFramework</b>\n
96 It is configurable in FH_CAN05_Configs.h
97*/
99
100/**
101 * @brief This function initializes the <b>CAN 05</b>\n
102 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
103 * <b>FH</b> user should call the initialization function of the interested CAN here
104 *
105 * @param fh_RFCommunication_Message
106 * The message frame set by <b>RobotFramework</b>
107 *
108 * @return FH_ErrorInfo is returned
109 *
110 * @note
111 * To have a clean code, just include the related header file\n
112 * Then just call the function here
113 *
114 * @verbatim
115 ==============================================================================
116 ##### RobotFramework Example #####
117 ==============================================================================
118 @{MessageData} = Create List ${CAN05}
119 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_Init} Data=@{MessageData}
120 ${Result} SendMessage &{Message}
121
122 Comments:
123
124 CAN05 => It indicates the CAN 05
125 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
126 Function_CAN => It is the function in the message frame
127 CAN_Commands_Init => It is the command of the function in the message frame
128 @endverbatim
129 *
130 *
131 * @warning
132 * To be able to send or receive data through the <b>CAN 05</b> of the micro-controller on which <b>FH</b> source code is ported, this function shall be invoked once by <b>RobotFramework</b> firstly\n
133 * In other words, before invoking for example <b>FH_CAN_Send_CAN05</b> or <b>FH_CAN_Receive_CAN05</b> functions or ... from <b>RobotFramework</b>, this function shall be invoked in order to initialize the CAN
134 *
135
136*/
138{
139 FH_ErrorInfo fh_ErrorInfo; // Error Information
140 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
141
142 // Attention 2: FH user defined code (call the initialization function of the CAN 05 here)
143
144 // YourInitializationFunctionName ();
145
146 //
147
148 return fh_ErrorInfo;
149}
150
151/**
152 * @brief This function sends data through the <b>CAN 05</b>\n
153 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
154 * <b>FH</b> user should call the send function of the interested CAN here
155 *
156 * @param fh_RFCommunication_Message
157 * The message frame set by <b>RobotFramework</b>
158 *
159 * @return FH_ErrorInfo is returned
160 *
161 * @note
162 * To have a clean code, just include the related header file\n
163 * Then just call the function here
164 *
165 * @verbatim
166 ==============================================================================
167 ##### RobotFramework Example #####
168 ==============================================================================
169 @{MessageData} = Create List ${CAN05} 02 B1 FF
170 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_Send} Data=@{MessageData}
171 ${Result} SendMessage &{Message}
172
173 Comments:
174
175 CAN05 => It indicates the CAN 05
176 B1 FF => Example data (0xB1, 0xFF) to be sent (or apart from the data to be sent, it may include some other data like ID, Filter, ... to be processed too, if need be) through the <b>CAN 05</b>\n
177 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
178 Function_CAN => It is the function in the message frame
179 CAN_Commands_Send => It is the command of the function in the message frame
180 @endverbatim
181 *
182 *
183 * @warning
184 * To be able to send data through the <b>CAN 05</b> of the micro-controller on which <b>FH</b> source code is ported, the <b>FH_CAN_Init_CAN05</b> function shall be invoked once by <b>RobotFramework</b> firstly\n
185 * In other words, before invoking <b>FH_CAN_Send_CAN05</b> function from <b>RobotFramework</b>, <b>FH_CAN_Init_CAN05</b> function shall be invoked in order to initialize the CAN
186 *
187
188*/
190{
191 FH_ErrorInfo fh_ErrorInfo; // Error Information
192 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
193
194 // Attention 3: FH user defined code (call the send process function of the CAN 05 here with &fh_RFCommunication_Message -> Data[UART_Send_Data] and Send_DataLength as argument)
195 // Hint: The prototype of the send process function should be something like YourSendProcessFunctionName(uint8_t* Data, uint8_t DataLength);
196
197 // YourSendProcessFunctionName (&fh_RFCommunication_Message -> Data[UART_Send_Data], fh_RFCommunication_Message -> Data[CAN_Send_DataLength]);
198
199 //
200
201 return fh_ErrorInfo;
202}
203
204/**
205 * @brief This function retrieves the <b>ISR</b> (Interrupt Service Routine) receive buffer (<b>FH_CAN05_ReceiveBuf</b>) of the <b>CAN 05</b>\n
206 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
207 * <b>FH</b> user could left the present source code here intact
208 *
209 * @param fh_RFCommunication_Message
210 * The message frame set by <b>RobotFramework</b>
211 * @param DataSize
212 * *DataSize will be set to the <b>ISR</b> (Interrupt Service Routine) receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) of the <b>CAN 05</b>
213 * @param Data
214 * *Data will be set to the <b>ISR</b> (Interrupt Service Routine) receive buffer (<b>FH_CAN05_ReceiveBuf</b>) of the <b>CAN 05</b>
215 *
216 * @return FH_ErrorInfo is returned
217 *
218 * @note
219 * <b>FH</b> user shall use <b>FH_CAN05_ReceiveBuf</b> and <b>FH_CAN05_ReceiveBufIndex</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file\n
220 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there\n
221 * In other word, <b>FH_CAN05_ReceiveBuf</b> array shall receive every byte of the received data there with <b>FH_CAN05_ReceiveBufIndex</b> as index of the array
222 *
223 * @verbatim
224 ==============================================================================
225 ##### RobotFramework Example #####
226 ==============================================================================
227 @{MessageData} = Create List ${CAN05}
228 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_Receive} Data=@{MessageData}
229 ${Result} SendMessage &{Message}
230
231 Comments:
232
233 CAN05 => It indicates the CAN 05
234 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
235 Function_CAN => It is the function in the message frame
236 CAN_Commands_Receive => It is the command of the function in the message frame
237 @endverbatim
238 *
239 *
240 * @warning
241 * To be able to receive data through the <b>CAN 05</b> of the micro-controller on which <b>FH</b> source code is ported, the <b>FH_CAN_Init_CAN05</b> function shall be invoked once by <b>RobotFramework</b> firstly\n
242 * In other words, before invoking <b>FH_CAN_Receive_CAN05</b> function from <b>RobotFramework</b>, <b>FH_CAN_Init_CAN05</b> function shall be invoked in order to initialize the CAN
243 *
244 * @note
245 * The only solution for resetting the receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) is using <b>FH_CAN_ResetRB_CAN05</b> function\n
246 * In other words, <b>FH_CAN05_ReceiveBufIndex</b> may have been already increased if any data has been already received\n
247 * So it is normally required to invoke <b>FH_CAN_ResetRB_CAN05</b> through <b>RobotFramework</b> to reset the receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) before invoking <b>FH_CAN_Receive_CAN05</b>
248 *
249
250*/
252{
253 FH_ErrorInfo fh_ErrorInfo; // Error Information
254 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
255
256 if (FH_CAN05_ReceiveBufIndex > 0) // If there is at least one byte of data received in the ISR (Interrupt Service Routine) of the CAN 05
257 {
258 *DataSize = FH_CAN05_ReceiveBufIndex; // The number of the received bytes in the ISR (Interrupt Service Routine) of the CAN 05
259 for (uint8_t i = 0; i < FH_CAN05_ReceiveBufIndex; i++)
260 {
261 *(Data + i) = FH_CAN05_ReceiveBuf[i]; // The data received in the ISR (Interrupt Service Routine) of the CAN 05
262 }
263 }
264 *DataSize = FH_CAN05_ReceiveBufIndex; // The number of the received bytes in the ISR (Interrupt Service Routine) of the CAN 05
265
266 return fh_ErrorInfo;
267}
268
269/**
270 * @brief This function waits to receive the specified number of bytes of data through the <b>ISR</b> (Interrupt Service Routine) receive buffer (<b>FH_CAN05_ReceiveBuf</b>) of the <b>CAN 05</b>\n
271 * A maximum timeout is specified too\n
272 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
273 * <b>FH</b> user could left the present source code here intact
274 *
275 * @param fh_RFCommunication_Message
276 * The message frame set by <b>RobotFramework</b>
277 * @param DataSize
278 * *DataSize will be set to the <b>ISR</b> (Interrupt Service Routine) receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) of the <b>CAN 05</b>
279 * @param Data
280 * *Data will be set to the <b>ISR</b> (Interrupt Service Routine) receive buffer (<b>FH_CAN05_ReceiveBuf</b>) of the <b>CAN 05</b>
281 *
282 * @return FH_ErrorInfo is returned
283 *
284 * @note
285 * <b>FH</b> user shall use <b>FH_CAN05_ReceiveBuf</b> and <b>FH_CAN05_ReceiveBufIndex</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file\n
286 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there\n
287 * In other word, <b>FH_CAN05_ReceiveBuf</b> array shall receive every byte of the received data there with <b>FH_CAN05_ReceiveBufIndex</b> as index of the array
288 *
289 * @verbatim
290 ==============================================================================
291 ##### RobotFramework Example #####
292 ==============================================================================
293 @{MessageData} = Create List ${CAN05} 05 00 00 0B B8
294 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_ReceiveW} Data=@{MessageData}
295 ${Result} SendMessage &{Message}
296
297 Comments:
298
299 CAN05 => It indicates the CAN 05
300 05 => The expected number of bytes of data to be received through the <b>ISR</b> (Interrupt Service Routine) receive buffer (FH_CAN05_ReceiveBuf) of the <b>CAN 05</b>
301 00 00 0B B8 => Example data (0x00000BB8 mili-seconds) as timeout of receiving the expected number of bytes
302 FH_GlobalTimeCounter which is a global variable is utilized to calculate the timeout
303 FH_GlobalTimeCounter shall be incremented every <b>1 mili-second</b> in an interested timer <b>ISR</b> (Interrupt Service Routine) by <b>FH</b> user
304 For this to happen, <b>FH_GlobalTimerCount.h</b> shall be included in the interested timer <b>ISR</b> (Interrupt Service Routine) file
305 If the expected number of bytes are received, the function does not wait anymore for the remaining time of the timeout
306 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
307 Function_CAN => It is the function in the message frame
308 CAN_Commands_ReceiveW => It is the command of the function in the message frame
309 @endverbatim
310 *
311 * @warning
312 * To be able to receive data through the <b>CAN 05</b> of the micro-controller on which <b>FH</b> source code is ported, the <b>FH_CAN_Init_CAN05</b> function shall be invoked once by <b>RobotFramework</b> firstly\n
313 * In other words, before invoking <b>FH_CAN_ReceiveW_CAN05</b> function from <b>RobotFramework</b>, <b>FH_CAN_Init_CAN05</b> function shall be invoked in order to initialize the CAN
314 *
315 * @note
316 * The only solution for resetting the receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) is using <b>FH_CAN_ResetRB_CAN05</b> function\n
317 * In other words, <b>FH_CAN05_ReceiveBufIndex</b> may have been already increased if any data has been already received\n
318 * So it is normally required to invoke <b>FH_CAN_ResetRB_CAN05</b> through <b>RobotFramework</b> to reset the receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) before invoking <b>FH_CAN_ReceiveW_CAN05</b>
319 *
320
321*/
323{
324 FH_ErrorInfo fh_ErrorInfo; // Error Information
325 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
326
327 uint8_t ExpectedDataLength;
328 ExpectedDataLength = fh_RFCommunication_Message -> Data[CAN_ReceiveW_ExpectedDataLength]; // The expected number of bytes to be received through the ISR (Interrupt Service Routine) receive buffer (FH_CAN05_ReceiveBuf) of the CAN 05
329
330 uint32_t MaxTimerCount = FH_ConvertUint8ToUint32(&fh_RFCommunication_Message -> Data[CAN_ReceiveW_MaxTimerCount]); // The timeout of receiving the expected number of bytes
331
332 FH_GlobalTimeCounter = 0; // The global variable is utilized to calculate the timeout
333 // Wait till the expected number of bytes are received or timeout happens
334 while (FH_CAN05_ReceiveBufIndex < ExpectedDataLength && FH_GlobalTimeCounter < MaxTimerCount)
335 {
336 }
337
338 if (FH_CAN05_ReceiveBufIndex > 0) // If there is at least one byte of data received in the ISR (Interrupt Service Routine) of the CAN 05
339 {
340 *DataSize = FH_CAN05_ReceiveBufIndex;
341 for (uint8_t i = 0; i < FH_CAN05_ReceiveBufIndex; i++)
342 {
343 *(Data + i) = FH_CAN05_ReceiveBuf[i];
344 }
345 }
346 *DataSize = FH_CAN05_ReceiveBufIndex; // The number of the received bytes in the ISR (Interrupt Service Routine) of the CAN 05
347
348 return fh_ErrorInfo;
349}
350
351/**
352 * @brief This function resets the <b>ISR</b> (Interrupt Service Routine) receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) of the <b>CAN 05</b>\n
353 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
354 * <b>FH</b> user could left the present source code here intact
355 *
356 * @param fh_RFCommunication_Message
357 * The message frame set by <b>RobotFramework</b>
358 *
359 * @return FH_ErrorInfo is returned
360 *
361 * @note
362 * <b>FH</b> user shall use <b>FH_CAN05_ReceiveBuf</b> and <b>FH_CAN05_ReceiveBufIndex</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file\n
363 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there\n
364 * In other word, <b>FH_CAN05_ReceiveBuf</b> array shall receive every byte of the received data there with <b>FH_CAN05_ReceiveBufIndex</b> as index of the array
365 *
366 * @verbatim
367 ==============================================================================
368 ##### RobotFramework Example #####
369 ==============================================================================
370 @{MessageData} = Create List ${CAN05}
371 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_ResetRB} Data=@{MessageData}
372 ${Result} SendMessage &{Message}
373
374 Comments:
375
376 CAN05 => It indicates the CAN 05
377 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
378 Function_CAN => It is the function in the message frame
379 CAN_Commands_ResetRB => It is the command of the function in the message frame
380 @endverbatim
381 *
382 * @warning
383 * The only solution for resetting the receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) is using <b>FH_CAN_ResetRB_CAN05</b> function\n
384 * In other words, <b>FH_CAN05_ReceiveBufIndex</b> may have been already increased if any data has been already received\n
385 * So it is normally required to invoke <b>FH_CAN_ResetRB_CAN05</b> through <b>RobotFramework</b> to reset the receive buffer index (<b>FH_CAN05_ReceiveBufIndex</b>) before invoking <b>FH_CAN_Receive_CAN05</b> or <b>FH_CAN_ReceiveW_CAN05</b> or ...
386 *
387
388*/
390{
391 FH_ErrorInfo fh_ErrorInfo; // Error Information
392 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
393
394 FH_CAN05_ReceiveBufIndex = 0; // The receive buffer index of the ISR (Interrupt Service Routine) of the CAN 05
395
396 return fh_ErrorInfo;
397}
398
399/**
400 * @brief This function sets the shared data buffer (<b>FH_CAN05_SharedDataBuf_8Bits</b>) of the <b>CAN 05</b>\n
401 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
402 * <b>FH_CAN05_SharedDataBuf_8Bits</b> is a shared global 8 bit array which is a data bridge between <b>RobotFramework</b> and <b>FH</b> user code\n
403 * <b>FH_CAN05_SharedDataBuf_8Bits</b> is optional\n
404 * It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> or ...
405 *
406 * <b>FH</b> user could left the present source code here intact
407 *
408 * @param fh_RFCommunication_Message
409 * The message frame set by <b>RobotFramework</b>
410 *
411 * @return FH_ErrorInfo is returned
412 *
413 * @note
414 * <b>FH</b> user could use <b>FH_CAN05_SharedDataBuf_8Bits</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file or anywhere else interested\n
415 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there
416 *
417 * @verbatim
418 ==============================================================================
419 ##### RobotFramework Example #####
420 ==============================================================================
421 @{MessageData} = Create List ${CAN05} 04 AA BB CC DD
422 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_SSD8} Data=@{MessageData}
423 ${Result} SendMessage &{Message}
424
425 Comments:
426
427 CAN05 => It indicates the CAN 05
428 04 => Example interested length of the 8 bit data to be set
429 AA BB CC DD => Example data (0xAA, 0xBB, 0xCC, 0xDD) to be set in <b>FH_CAN05_SharedDataBuf_8Bits</b>
430 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
431 Function_CAN => It is the function in the message frame
432 CAN_Commands_SSD8 => It is the command of the function in the message frame
433 @endverbatim
434 *
435
436*/
438{
439 FH_ErrorInfo fh_ErrorInfo; // Error Information
440 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
441
442 if (fh_RFCommunication_Message -> Data[CAN_SSD8_SharedDataLength] > FH_CAN05_SharedDataBufLength_8Bits) // The length of the 8 bit data to be set
443 {
444 fh_ErrorInfo.error_code = FH_ERROR_Functions; // FH User Defined Function Error
445 return fh_ErrorInfo;
446 }
447
448 for (uint8_t i = 0; i < fh_RFCommunication_Message -> Data[CAN_SSD8_SharedDataLength] ; i++)
449 {
450 FH_CAN05_SharedDataBuf_8Bits[i] = fh_RFCommunication_Message -> Data[CAN_SSD8_SharedData+i]; // Set data to FH_CAN05_SharedDataBuf_8Bits
451 }
452 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no Error
453
454 return fh_ErrorInfo;
455}
456
457/**
458 * @brief This function sets the shared data buffer (<b>FH_CAN05_SharedDataBuf_16Bits</b>) of the <b>CAN 05</b>\n
459 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
460 * <b>FH_CAN05_SharedDataBuf_16Bits</b> is a shared global 8 bit array which is a data bridge between <b>RobotFramework</b> and <b>FH</b> user code\n
461 * <b>FH_CAN05_SharedDataBuf_16Bits</b> is optional\n
462 * It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> or ...
463 *
464 * <b>FH</b> user could left the present source code here intact
465 *
466 * @param fh_RFCommunication_Message
467 * The message frame set by <b>RobotFramework</b>
468 *
469 * @return FH_ErrorInfo is returned
470 *
471 * @note
472 * <b>FH</b> user could use <b>FH_CAN05_SharedDataBuf_16Bits</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file or anywhere else interested\n
473 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there
474 *
475 * @verbatim
476 ==============================================================================
477 ##### RobotFramework Example #####
478 ==============================================================================
479 @{MessageData} = Create List ${CAN05} 02 AA BB CC DD
480 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_SSD16} Data=@{MessageData}
481 ${Result} SendMessage &{Message}
482
483 Comments:
484
485 CAN05 => It indicates the CAN 05
486 02 => Example interested length of the 16 bit data to be set
487 AA BB CC DD => Example data (0xAABB and 0xCCDD) to be set in <b>FH_CAN05_SharedDataBuf_16Bits</b>
488 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
489 Function_CAN => It is the function in the message frame
490 CAN_Commands_SSD16 => It is the command of the function in the message frame
491 @endverbatim
492 *
493
494*/
496{
497 FH_ErrorInfo fh_ErrorInfo; // Error Information
498 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
499
500 if (fh_RFCommunication_Message -> Data[CAN_SSD16_SharedDataLength] > (FH_CAN05_SharedDataBufLength_16Bits * 2)) // The length of the 16 bit data to be set
501 {
502 fh_ErrorInfo.error_code = FH_ERROR_Functions; // FH User Defined Function Error
503 return fh_ErrorInfo;
504 }
505
506 uint8_t i = 0;
507 uint8_t SharedDataIndex = CAN_SSD16_SharedData; // Shared Data Index in FH_CAN_Commandelements_SSD16
508 do
509 {
510 FH_CAN05_SharedDataBuf_16Bits[i] = FH_ConvertUint8ToUint16(&fh_RFCommunication_Message -> Data[SharedDataIndex]); // Set data to FH_CAN05_SharedDataBuf_16Bits
511 SharedDataIndex = SharedDataIndex + 2;
512 i = i + 1;
513 }while (i < fh_RFCommunication_Message -> Data[CAN_SSD16_SharedDataLength]); // The length of the 16 bit data to be set
514 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no Error
515
516 return fh_ErrorInfo;
517}
518
519/**
520 * @brief This function sets the shared data buffer (<b>FH_CAN05_SharedDataBuf_32Bits</b>) of the <b>CAN 05</b>\n
521 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
522 * <b>FH_CAN05_SharedDataBuf_32Bits</b> is a shared global 8 bit array which is a data bridge between <b>RobotFramework</b> and <b>FH</b> user code\n
523 * <b>FH_CAN05_SharedDataBuf_32Bits</b> is optional\n
524 * It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> or ...
525 *
526 * <b>FH</b> user could left the present source code here intact
527 *
528 * @param fh_RFCommunication_Message
529 * The message frame set by <b>RobotFramework</b>
530 *
531 * @return FH_ErrorInfo is returned
532 *
533 * @note
534 * <b>FH</b> user could use <b>FH_CAN05_SharedDataBuf_32Bits</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file or anywhere else interested\n
535 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there
536 *
537 * @verbatim
538 ==============================================================================
539 ##### RobotFramework Example #####
540 ==============================================================================
541 @{MessageData} = Create List ${CAN05} 02 AA BB CC DD 01 02 03 04
542 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_SSD32} Data=@{MessageData}
543 ${Result} SendMessage &{Message}
544
545 Comments:
546
547 CAN05 => It indicates the CAN 05
548 02 => Example interested length of the 32 bit data to be set
549 AA BB CC DD 01 02 03 04 => Example data (0xAABBCCDD and 0x01020304) to be set in <b>FH_CAN05_SharedDataBuf_32Bits</b>
550 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
551 Function_CAN => It is the function in the message frame
552 CAN_Commands_SSD32 => It is the command of the function in the message frame
553 @endverbatim
554 *
555
556*/
558{
559 FH_ErrorInfo fh_ErrorInfo; // Error Information
560 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
561
562 if (fh_RFCommunication_Message -> Data[CAN_SSD32_SharedDataLength] > (FH_CAN05_SharedDataBufLength_32Bits * 4)) // The length of the 32 bit data to be set
563 {
564 fh_ErrorInfo.error_code = FH_ERROR_Functions; // FH User Defined Function Error
565 return fh_ErrorInfo;
566 }
567
568 uint8_t i = 0;
569 uint8_t SharedDataIndex = CAN_SSD32_SharedData; // Shared Data Index in FH_CAN_Commandelements_SSD32
570 do
571 {
572 FH_CAN05_SharedDataBuf_32Bits[i] = FH_ConvertUint8ToUint32(&fh_RFCommunication_Message -> Data[SharedDataIndex]); // Set data to FH_CAN05_SharedDataBuf_32Bits
573 SharedDataIndex = SharedDataIndex + 4;
574 i = i + 1;
575 }while (i < fh_RFCommunication_Message -> Data[CAN_SSD32_SharedDataLength]); // The length of the 32 bit data to be set
576
577 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no Error
578
579 return fh_ErrorInfo;
580}
581
582/**
583 * @brief This function gets the shared data buffer (<b>FH_CAN05_SharedDataBuf_8Bits</b>) of the <b>CAN 05</b>\n
584 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
585 * <b>FH_CAN05_SharedDataBuf_8Bits</b> is a shared global 8 bit array which is a data bridge between <b>RobotFramework</b> and <b>FH</b> user code\n
586 * <b>FH_CAN05_SharedDataBuf_8Bits</b> is optional\n
587 * It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> or ...
588 *
589 * <b>FH</b> user could left the present source code here intact
590 *
591 * @param fh_RFCommunication_Message
592 * The message frame set by <b>RobotFramework</b>
593 * @param SharedDataLength
594 * *SharedDataLength will be set to <b>FH_CAN05_SharedDataBufLength_8Bits</b>
595 * @param SharedData
596 * *SharedData will be set to <b>FH_CAN05_SharedDataBuf_8Bits</b>
597 *
598 * @return FH_ErrorInfo is returned
599 *
600 * @note
601 * <b>FH</b> user could use <b>FH_CAN05_SharedDataBuf_8Bits</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file or anywhere else interested\n
602 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there
603 *
604 * @verbatim
605 ==============================================================================
606 ##### RobotFramework Example #####
607 ==============================================================================
608 @{MessageData} = Create List ${CAN05}
609 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_GSD8} Data=@{MessageData}
610 ${Result} SendMessage &{Message}
611
612 Comments:
613
614 CAN05 => It indicates the CAN 05
615 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
616 Function_CAN => It is the function in the message frame
617 CAN_Commands_GSD8 => It is the command of the function in the message frame
618 @endverbatim
619 *
620
621*/
623{
624 FH_ErrorInfo fh_ErrorInfo; // Error Information
625 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
626
627 for (uint8_t i = 0; i < FH_CAN05_SharedDataBufLength_8Bits; i++)
628 {
629 *(SharedData + i) = FH_CAN05_SharedDataBuf_8Bits[i];
630 }
631 *SharedDataLength = FH_CAN05_SharedDataBufLength_8Bits; // The length of the 8 bit data to be set
632 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no Error
633
634 return fh_ErrorInfo;
635}
636
637/**
638 * @brief This function gets the shared data buffer (<b>FH_CAN05_SharedDataBuf_16Bits</b>) of the <b>CAN 05</b>\n
639 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
640 * <b>FH_CAN05_SharedDataBuf_16Bits</b> is a shared global 16 bit array which is a data bridge between <b>RobotFramework</b> and <b>FH</b> user code\n
641 * <b>FH_CAN05_SharedDataBuf_16Bits</b> is optional\n
642 * It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> or ...
643 *
644 * <b>FH</b> user could left the present source code here intact
645 *
646 * @param fh_RFCommunication_Message
647 * The message frame set by <b>RobotFramework</b>
648 * @param SharedDataLength
649 * *SharedDataLength will be set to <b>FH_CAN05_SharedDataBufLength_16Bits</b>
650 * @param SharedData
651 * *SharedData will be set to <b>FH_CAN05_SharedDataBuf_16Bits</b>
652 *
653 * @return FH_ErrorInfo is returned
654 *
655 * @note
656 * <b>FH</b> user could use <b>FH_CAN05_SharedDataBuf_16Bits</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file or anywhere else interested\n
657 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there
658 *
659 * @verbatim
660 ==============================================================================
661 ##### RobotFramework Example #####
662 ==============================================================================
663 @{MessageData} = Create List ${CAN05}
664 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_GSD16} Data=@{MessageData}
665 ${Result} SendMessage &{Message}
666
667 Comments:
668
669 CAN05 => It indicates the CAN 05
670 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
671 Function_CAN => It is the function in the message frame
672 CAN_Commands_GSD16 => It is the command of the function in the message frame
673 @endverbatim
674 *
675
676*/
678{
679 FH_ErrorInfo fh_ErrorInfo; // Error Information
680 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
681
682 FH_Uint8Uint16 fh_Uint8Uint16; // Union to access 4 uint8_t out of 1 uint16_t
683 uint8_t SharedDataIndex = 0;
684 for (uint8_t i = 0; i < FH_CAN05_SharedDataBufLength_16Bits; i++)
685 {
686 fh_Uint8Uint16.value = FH_CAN05_SharedDataBuf_16Bits[i];
687 *(SharedData + SharedDataIndex++) = fh_Uint8Uint16.bytes[1];
688 *(SharedData + SharedDataIndex++) = fh_Uint8Uint16.bytes[0];
689 }
690 *SharedDataLength = FH_CAN05_SharedDataBufLength_16Bits; // The length of the 16 bit data to be set
691 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no Error
692
693 return fh_ErrorInfo;
694}
695
696/**
697 * @brief This function gets the shared data buffer (<b>FH_CAN05_SharedDataBuf_32Bits</b>) of the <b>CAN 05</b>\n
698 * The <b>CAN 05</b> could be any interested CAN of the micro-controller on which <b>FH</b> source code is ported\n
699 * <b>FH_CAN05_SharedDataBuf_32Bits</b> is a shared global 32 bit array which is a data bridge between <b>RobotFramework</b> and <b>FH</b> user code\n
700 * <b>FH_CAN05_SharedDataBuf_32Bits</b> is optional\n
701 * It could be used by <b>FH</b> user to set some special data like receive filters on <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> or ...
702 *
703 * <b>FH</b> user could left the present source code here intact
704 *
705 * @param fh_RFCommunication_Message
706 * The message frame set by <b>RobotFramework</b>
707 * @param SharedDataLength
708 * *SharedDataLength will be set to <b>FH_CAN05_SharedDataBufLength_32Bits</b>
709 * @param SharedData
710 * *SharedData will be set to <b>FH_CAN05_SharedDataBuf_32Bits</b>
711 *
712 * @return FH_ErrorInfo is returned
713 *
714 * @note
715 * <b>FH</b> user could use <b>FH_CAN05_SharedDataBuf_32Bits</b> in the receive <b>ISR</b> (Interrupt Service Routine) of the <b>CAN 05</b> in a separate c file or anywhere else interested\n
716 * For this to happen, <b>FH</b> user shall just include <b>FH_CAN05_GlobalVariables.h</b> there
717 *
718 * @verbatim
719 ==============================================================================
720 ##### RobotFramework Example #####
721 ==============================================================================
722 @{MessageData} = Create List ${CAN05}
723 &{Message} = Create Dictionary DeviceAddress=${DeviceAddress_01} Function=${Function_CAN} Command=${CAN_Commands_GSD32} Data=@{MessageData}
724 ${Result} SendMessage &{Message}
725
726 Comments:
727
728 CAN05 => It indicates the CAN 05
729 DeviceAddress_01 => It shall be equal to the address of the device: FH_RFCommunication_DeviceAddress
730 Function_CAN => It is the function in the message frame
731 CAN_Commands_GSD32 => It is the command of the function in the message frame
732 @endverbatim
733 *
734
735*/
737{
738 FH_ErrorInfo fh_ErrorInfo; // Error Information
739 FH_ResetErrorInfo(&fh_ErrorInfo); // Reset Error Information to default
740
741 FH_Uint8Uint32 fh_Uint8Uint32; // Union to access 4 uint8_t out of 1 uint32_t
742 uint8_t SharedDataIndex = 0;
743 for (uint8_t i = 0; i < FH_CAN05_SharedDataBufLength_32Bits; i++)
744 {
745 fh_Uint8Uint32.value = FH_CAN05_SharedDataBuf_32Bits[i];
746 *(SharedData + SharedDataIndex++) = fh_Uint8Uint32.bytes[3];
747 *(SharedData + SharedDataIndex++) = fh_Uint8Uint32.bytes[2];
748 *(SharedData + SharedDataIndex++) = fh_Uint8Uint32.bytes[1];
749 *(SharedData + SharedDataIndex++) = fh_Uint8Uint32.bytes[0];
750 }
751 *SharedDataLength = FH_CAN05_SharedDataBufLength_32Bits; // The length of the 32 bit data to be set
752
753 fh_ErrorInfo.error_code = FH_ERROR_OK; // There is no Error
754 return fh_ErrorInfo;
755}
756
757#endif
758
759#endif