2 * FlexRay Communication RPP API header file.
6 * @copyright Copyright (C) 2013 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
9 * @author Michal Horn <hornmich@fel.cvut.cz>
16 #include "drv/Fr_GeneralTypes.h"
17 #include "drv/fr_tms570.h"
22 RPP_FR_NOT_INITIALIZED,
23 RPP_FR_DRV_INITIALIZED,
24 RPP_FR_CTR_INITIALIZED,
30 #define RPP_FR_MAX_STATIC_BUF_CNT 32
31 #define RPP_FR_MAX_DYNAMIC_BUF_CNT 32
32 #define RPP_FR_MAX_FIFO_BUF_DEPTH 32
34 /* AUTOSAR-like API */
37 * FlexRay driver initialization.
39 * This method should be called before any other function from this
40 * module, except rpp_fr_config_* functions.
42 * The function copies configuration data into drivers internal
43 * structures and initializes the driver.
45 * There are two ways how to configure FlexRay.
46 * 1) Passing address of the config structure as an argument from the application.
47 * 2) Using rpp_fr_config_* functions to create configuration at run-time. Then the argument
48 * for this function has to be NULL and configuration functions have to be called before
51 * After a successful driver initialization, the driver is ready for calling:
52 * - rpp_fr_init_controller()
53 * - rpp_fr_get_poc_status()
54 * - rpp_fr_get_wakeup_rx_status()
55 * - rpp_fr_get_timer_irq_status()
57 * @param [in] config_ptr Address of the structure with all FlexRay
58 * configuration parameters. If it is NULL, then the default structure,
59 * filled by rpp_fr_config functions, is used.
60 * @param [out] error Address where error flags will be stored. The flags
61 * definitions can be found in fr_tms570h, with ERR_PARAM prefix.
63 * @return SUCCESS if initialization successful.
64 * FAILURE if module already initialized.
67 int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error);
70 * FlexRay controller initialization.
72 * This method should be called after rpp_fr_init_driver() or rpp_fr_halt_communication() and
73 * rpp_fr_abort_communication() and before any other function from this module.
75 * To restart communication after halt or abort functions were called, this sequence should be used:
76 * - rpp_fr_init_controller
77 * - rpp_fr_start_communication
78 * -rpp_fr_all_slots (optionally)
80 * The functions checks configuration parameters and configures FlexRay
81 * controller registers.
83 * After successful controller initialization, the FlexRay driver is ready for calling:
84 * - rpp_fr_get_poc_status()
85 * - rpp_fr_get_wakeup_rx_status()
86 * - rpp_fr_get_timer_irq_status()
87 * - rpp_fr_start_communication()
89 * - rpp_fr_set_wu_channel()
90 * - rpp_fr_get_global_time()
91 * - rpp_fr_get_network_management_vector()
92 * - rpp_fr_get_channel_status()
94 * @param [in] ctrl Not used, set always to zero.
95 * @param [out] error Address where error flags will be stored. The flags
96 * definitions can be found in fr_tms570h, with ERR_PARAM and FR_INIT_ERR
99 * @return SUCCESS if initialization if successful.
100 * FAILURE if module already initialized.
103 int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error);
106 * FlexRay start communication
108 * This method should be called after rpp_fr_init_controller() and
109 * before any attempt to send or receive messages.
111 * For coldstarter node the function tries to listen and join an
112 * existing network. If it fails, it tries to initiate the new one.
113 * For regular node it only listens on the bus and tries to join to
114 * some existing network.
116 * After successful communication start, the FlexRay is ready for:
117 * - rpp_fr_get_poc_status()
118 * - rpp_fr_get_wakeup_rx_status()
119 * - rpp_fr_get_timer_irq_status()
120 * - rpp_fr_set_wu_channel()
121 * - rpp_fr_get_global_time()
122 * - rpp_fr_get_network_management_vector()
123 * - rpp_fr_get_channel_status()
124 * - rpp_fr_all_slots()
125 * - rpp_fr_halt_communication()
126 * - rpp_fr_abort_communication()
127 * - rpp_fr_transmit_lpdu()
128 * - rpp_fr_cancel_transmit_lpdu()
129 * - rpp_fr_receive_lpdu()
130 * - rpp_fr_check_tx_lpdu_status()
131 * - rpp_fr_disable_lpdu()
132 * - rpp_fr_get_clock_correction()
133 * - rpp_fr_get_sync_frame_list()
134 * - rpp_fr_set_timer()
135 * - rpp_fr_cancel_timer()
137 * @param [in] ctrl Not used, set always to zero.
138 * @param [out] error Address where error flags will be stored. The flags
139 * definitions can be found in fr_tms570h, with FR_STARTUP_ERR prefix.
141 * @return SUCCESS if initialization successful.
142 * FAILURE if module already initialized.
145 int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t* error);
148 * FlexRay allow communication on all slots
150 * The FlexRay node can be configured to communicate only on key
151 * frames after the startup. If this is the case, after calling this
152 * function, communication on all configured slots is allowed.
154 * The function should be called only after rpp_fr_start_communication() has been called.
156 * @param [in] ctrl Not used, set always to zero.
158 * @return SUCCESS if started successfully.
159 * FAILURE if timeout reached.
162 int8_t rpp_fr_all_slots(uint8_t ctrl);
165 * FlexRay stop communication after the end of the communication cycle.
167 * The function should be called only after
168 * rpp_fr_start_communication() has been called.
170 * After the communication is stopped, only those functions are allowed to be called:
171 * - rpp_fr_set_wu_channel()
172 * - rpp_fr_get_global_time()
173 * - rpp_fr_get_network_management_vector()
174 * - rpp_fr_get_channel_status()
175 * - rpp_fr_get_clock_correction()
176 * - rpp_fr_get_sync_frame_list()
177 * - rpp_fr_get_wakeup_rx_status()
178 * - rpp_fr_get_poc_status()
179 * - rpp_fr_start_communication()
181 * To reestablish the communication, the rpp_fr_start_communication() function
184 * @param [in] ctrl Not used, set always to zero.
186 * @return SUCCESS if command passed successfully.
187 * FAILURE if command rejected.
190 int8_t rpp_fr_halt_communication(uint8_t ctrl);
193 * FlexRay stop communication immediately.
195 * The function should be called only after
196 * rpp_fr_start_communication() has been called.
198 * After the communication is stopped, only those functions are allowed to be called:
199 * - rpp_fr_set_wu_channel()
200 * - rpp_fr_get_global_time()
201 * - rpp_fr_get_network_management_vector()
202 * - rpp_fr_get_channel_status()
203 * - rpp_fr_get_clock_correction()
204 * - rpp_fr_get_sync_frame_list()
205 * - rpp_fr_get_wakeup_rx_status()
206 * - rpp_fr_get_poc_status()
207 * - rpp_fr_start_communication()
209 * To reestablish the communication, the rpp_fr_start_communication() function
212 * @param [in] ctrl Not used, set always to zero.
214 * @return SUCCESS if command passed successfully.
215 * FAILURE if command rejected.
218 int8_t rpp_fr_abort_communication(uint8_t ctrl);
221 * FlexRay send wakeup pattern.
223 * The function should be called after FlexRay controller is initialized
224 * and before the communication start.
226 * @param [in] ctrl Not used, set always to zero.
228 * @return SUCCESS if command passed successfully.
229 * FAILURE if command rejected.
232 int8_t rpp_fr_send_wup(uint8_t ctrl);
235 * FlexRay set channel for wakeup pattern sending.
237 * This allows to change the configuration passed to the
238 * rpp_fr_init_driver().
240 * The function should be called after FlexRay controller is initialized
241 * and before the communication start.
243 * @param [in] ctrl Not used, set always to zero.
244 * @param [in] channel Channel selector, where wakeup pattern will be sent
246 * @return SUCCESS if command passed successfully.
247 * FAILURE if command rejected.
250 int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel);
253 * Get FlexRay POC state
255 * The function can be called any time after the driver is
258 * @param [in] ctrl Not used, set always to zero.
259 * @param [out] poc_status_ptr Address where status will be stored.
261 * @return SUCCESS if status retrieved successfully.
262 * FAILURE if something failed.
265 int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType* poc_status_ptr);
268 * Send a message on the bus in the specified frame
270 * The function can be called any time when communication is running
271 * (rpp_fr_start_communication() was called).
273 * If the buffer assigned to the frame is configured for continuous
274 * mode, this functions starts sending the message periodically. The
275 * transmission can be stopped by rpp_fr_cancel_transmit_lpdu(). If
276 * the buffer assigned to the frame is configured for single-shot
277 * mode, the message is sent only once.
279 * @param [in] ctrl Not used, set always to zero.
280 * @param [in] lpdu_idx Index of the frame, where the message will be sent.
281 * @param [in] lsdu Address of the first byte of the message.
282 * @param [in] lsdu_length Number of bytes of the message.
284 * @return SUCCESS if message was transmitted.
285 * FAILURE if something failed.
288 int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t* lsdu, uint8_t lsdu_length);
291 * Cancel a transmission of the message.
293 * The function can be called any time when communication is running
294 * (rpp_fr_start_communication() was called).
296 * This is one way to stop transmission for buffers configured for
297 * continuous mode. The other way is to use rpp_fr_disable_lpdu().
299 * @param [in] ctrl Not used, set always to zero.
300 * @param [in] lpdu_idx Index of the frame, where the message transmission will be stopped.
302 * @return SUCCESS if the transmission was stopped.
303 * FAILURE if something failed.
306 int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
309 * Receive a message from the bus from the specified frame.
311 * The function can be called any time when communication is running
312 * (rpp_fr_start_communication() was called).
314 * If a new message was received in a buffer configured for the static
315 * or dynamic segment, this function can retrieve it.
317 * @param [in] ctrl Not used, set always to zero.
318 * @param [in] lpdu_idx Index of the frame where message will be received from.
319 * @param [out] lsdu Address of the first byte of the buffer, where message will be stored.
320 * @param [out] lpdu_status Address where the status will be stored. It can be:
321 * FR_NOT_RECEIVED, FR_RECEIVED, FR_RECEIVED_MORE_DATA_AVAILABLE - for FIFO only.
322 * @param [out] lsdu_length Number of bytes of the message.
324 * @return SUCCESS if message was received.
325 * FAILURE if something failed.
328 int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t* lsdu, Fr_RxLPduStatusType* lpdu_status, uint8_t* lsdu_length);
331 * Check TX buffer status
333 * The function can be called any time when communication is running
334 * (rpp_fr_start_communication() was called).
336 * The status says whether a transmission request (TXR) is pending or
339 * If the buffer is configured for single-shot mode, the (TXR) is
340 * pending until the message is sent. For buffers configured in
341 * continuous mode, the transmission request is always pending.
344 * @param [in] ctrl Not used, set always to zero.
345 * @param [in] lpdu_idx Index of the frame to which the buffer is assigned.
346 * @param [out] lpdu_status Address of the status. It can be FR_TRANSMITTED,
347 * which means the TXR is not pending, or FR_NOT_TRANSMITTED which means that
350 * @return SUCCESS if everything is OK.
351 * FAILURE if something failed.
353 int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType* lpdu_status);
359 * The function can be called any time when after controller was initialized
360 * (rpp_fr_init_controller() was called).
362 * If the node is configured to allow buffer reconfiguration, some of the buffers
363 * can be reconfigured in runtime. Buffers used for synchronization and buffers
364 * assigned to the FIFO can not be reconfigured.
366 * It is not possible to change the direction (TX/RX) of the buffer or to change
367 * the mode (single-shot/continuous).
369 * @param [in] ctrl Not used, set always to zero.
370 * @param [in] lpdu_idx Index of the frame, where reconfigured buffer is communicating.
371 * @param [in] frame_id Frame ID, where the buffer will be communicating after the reconfiguration.
372 * @param [in] channel Channel, where the buffer will be communicating. For dynamic segment it should not be AB.
373 * @param [in] cycle Cycle rejection filter.
374 * @param [in] payload Maximum payload for the reconfigured buffer in half-word. Must not be higher than the original payload.
376 * @return SUCCESS if everything is OK.
377 * FAILURE if something failed.
379 int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle, uint8_t payload);
382 * Disable a FlexRay buffer
384 * The function can be called any time when communication is running
385 * (rpp_fr_start_communication() was called).
387 * This functions resets the configuration of the selected buffer.
388 * The disabled buffer is not usable any more.
390 * @param [in] ctrl Not used, set always to zero.
391 * @param [in] lpdu_idx Index of the frame to which the buffer is assigned.
393 * @return SUCCESS if buffer was disabled.
394 * FAILURE if something failed.
397 int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
400 * Get FlexRay global time
402 * The function can be called any time after the controller is initialized.
404 * @param [in] ctrl Not used, set always to zero.
405 * @param [out] cycle Adress where the number of actual cycle will be stored.
406 * @param [out] macroticks Address where offset in the cycle will be stored.
408 * @return SUCCESS if everything is OK.
409 * FAILURE if something failed.
412 int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks);
415 * Get Network management vector.
417 * The function can be called any time after the controller is initialized.
419 * The FlexRay controller updates the vector at the end of every cycle
420 * by doing bit-wise OR on every network managemet (NM) vectors
421 * received from all nodes.
423 * The NM vector can be sent in a frame by a buffer with the
424 * payloadPreambleIndicatorTr parameter set. Those frames are
425 * automatically processed by all the receiving controllers. But
426 * sending the vector has to be done manually by copying the NM vector
427 * data (obtainable by this function) into the TX buffer (using the
428 * rpp_fr_transmit_lpdu() function).
430 * @param [in] ctrl Not used, set always to zero.
431 * @param [out] nm_vector Address where the vector will be stored. The size of the buffer has to be at least gNetworkManagementVectorLength.
433 * @return SUCCESS if everything is OK.
434 * FAILURE if something failed.
436 int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t* nm_vector);
439 * Get Channel status.
441 * The function can be called any time after the controller is
444 * The output of the function is bitcoded in this way:
445 * - Bit 0: Channel A/B aggregated channel status vSS!ValidFrame
446 * - Bit 1: Channel A/B aggregated channel status vSS!SyntaxError
447 * - Bit 2: Channel A/B aggregated channel status vSS!ContentError
448 * - Bit 3: Channel A/B aggregated channel status additional communication
449 * - Bit 4: Channel A/B aggregated channel status vSS!Bviolation
450 * - Bit 5: Channel A/B aggregated channel status vSS!TxConflict
451 * - Bit 6: Not used (0)
452 * - Bit 7: Not used (0)
453 * - Bit 8: Channel A/B symbol window status data vSS!ValidMTS
454 * - Bit 9: Channel A/B symbol window status data vSS!SyntaxError
455 * - Bit 10: Channel A/B symbol window status data vSS!Bviolation
456 * - Bit 11: Channel A/B symbol window status data vSS!TxConflict
457 * - Bit 12: Channel A/B NIT status data vSS!SyntaxError
458 * - Bit 13: Channel A/B NIT status data vSS!Bviolation
459 * - Bit 14: Not used (0)
460 * - Bit 15: Not used (0)
462 * @param [in] ctrl Not used, set always to zero.
463 * @param [out] channel_a_status Address where the bitcoded status of the channel A will be stored.
464 * @param [out] channel_b_status Address where the bitcoded status of the channel B will be stored.
466 * @return SUCCESS if everything is OK.
467 * FAILURE if something failed.
470 int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t* channel_a_status, uint16_t* channel_b_status);
473 * Get clock correction.
475 * The function can be called while the communication is running or
478 * @param [in] ctrl Not used, set always to zero.
479 * @param [out] rate_correction Address where the rate will be stored.
480 * @param [out] offset_correction Address where the offset will be stored.
482 * @return SUCCESS if everything is OK.
483 * FAILURE if something failed.
486 int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32_t* offset_correction);
489 * Gets a list of syncframes received or transmitted on channel A and channel B via the even and odd communication cycle.
491 * The function can be called while communication is running or was stopped.
493 * @param [in] ctrl Not used, set always to zero.
494 * @param [in] list_size Size of the arrays passed via parameters:
495 * @param [out] channel_a_even_list Address the list of syncframes on channel A within the
496 * even communication cycle is written to. The exact
497 * number of elements written to the list is limited by
498 * parameter Fr_ListSize.
499 * Unused list elements are filled with the value '0' to indicate that no more syncframe has been seen.
500 * @param [out] channel_b_even_list Address the list of syncframes on channel B within the
501 * even communication cycle is written to. The exact
502 * number of elements written to the list is limited by
503 * parameter Fr_ListSize.
504 * @param [out] channel_a_odd_list Address the list of syncframes on channel A within the
505 * odd communication cycle is written to. The exact number
506 * of elements written to the list is limited by parameter
508 * Unused list elements are filled with the value '0' to indicate that no more syncframe has been seen.
509 * @param [out] channel_b_odd_list Address the list of syncframes on channel B within the
511 * @return SUCCESS if everything is OK.
512 * FAILURE if something failed.
515 int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t* channel_a_even_list,
516 uint16_t* channel_b_even_list, uint16_t* channel_a_odd_list, uint16_t* channel_b_odd_list);
519 * Get the status of WUP receiving
521 * The function can be called any time after controller is initialized.
523 * If the Wake Up Pattern was received on some channel, the flag is set in status address.
524 * Bit 0: Wakeup received on channel A indicator
525 * Bit 1: Wakeup received on channel B indicator
528 * @param [in] ctrl Not used, set always to zero.
529 * @param [out] status Address where the status will be stored.
531 * @return SUCCESS if everything is OK.
532 * FAILURE if something failed.
535 int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t* status);
538 * Set an absolute timer and start it.
540 * The function can be called any time after communication is running.
541 * The FlexRay controller has two absolute timers. Each of them can be
542 * configured to request the interrupt, when the global time reaches
543 * configured cycle set and offset.
545 * Timer interrupt request can be detected by
546 * rpp_fr_get_timer_irq_status(). The timer interrupt request can be
547 * cleared by rpp_fr_clear_timer_irq(). The timer can be canceled by
548 * rpp_fr_cancel_timer().
550 * @param [in] ctrl Not used, set always to zero.
551 * @param [in] timer_idx Index of the timer (0,1).
552 * @param [in] cycle_set Determines the set of cycles that trigger the interrupt (see Table 23-6 in TMS570 datasheet (SPNU499))
553 * @param [in] offset_threshold Offset in the cycle in mactroticks.
555 * @return SUCCESS if everything is OK.
556 * FAILURE if something failed.
559 int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint16_t offset_threshold);
562 * Stops an absolute timer, clear IRQ.
564 * The function can be called any time after communication is running.
566 * The FlexRay controller has two absolute timers. Each of them can be
567 * configured to request the interrupt, when the global time reaches
568 * configured cycle and offset. This function stops the timer and clears
569 * the interrupt request.
571 * Timer interrupt request can be detected by
572 * rpp_fr_get_timer_irq_status(). Timer interrupt request can be
573 * cleared by rpp_fr_clear_timer_irq() Timer can be started by
574 * rpp_fr_set_timer().
576 * @param [in] ctrl Not used, set always to zero.
577 * @param [in] timer_idx Index of the timer (0,1).
579 * @return SUCCESS if everything is OK.
580 * FAILURE if something failed.
583 int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx);
586 * Clear the IRQ flag of the absolute timer
588 * The function can be called any time after communication is running.
590 * The FlexRay controller has two absolute timers. Each of them can be
591 * configured to request the interrupt, when the global time reaches
592 * configured cycle and offset. This function clears the IRQ flag.
594 * Timer interrupt request can be detected by rpp_fr_get_timer_irq_status().
595 * The timer can be started by rpp_fr_set_timer().
596 * The timer can be canceled by rpp_fr_cancel_timer().
598 * @param [in] ctrl Not used, set always to zero.
599 * @param [in] timer_idx Index of the timer (0,1).
601 * @return SUCCESS if everything is OK.
602 * FAILURE if something failed.
605 int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx);
608 * Get IRQ flag of the absolute timer
610 * The function can be called any time after communication is running.
612 * The FlexRay controller has two absolute timers. Each of them can be
613 * configured to request the interrupt, when the global time reaches
614 * configured cycle and offset. Using this function the IRQ can be detected.
616 * Timer interrupt request can be cleared by rpp_fr_clear_timer_irq().
617 * The timer can be started by rpp_fr_set_timer().
618 * The timer can be canceled by rpp_fr_cancel_timer().
620 * @param [in] ctrl Not used, set always to zero.
621 * @param [in] timer_idx Index of the timer (0,1).
622 * @param [out] irq_pending Address, where status of the IRQ flag will be stored.
624 * @return SUCCESS if everything is OK.
625 * FAILURE if something failed.
628 int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t* irq_pending);
631 * Get information about the driver vendor, module and version.
633 * The function can be called any time.
635 * @param [out] version Address, where the information will be stored.
637 * @return always SUCCESS
640 int8_t rpp_fr_get_driver_version(Std_VersionInfoType* version);
643 * Get configuration parameter value from the internal driver structures.
645 * The function can be called any time.
647 * @param [in] ctrl Not used, set always to zero.
648 * @param [in] param_idx The index if the parameter. You can find the indexes in Fr_GeneralTypes.h file with FR_CIDX prefix.
649 * @param [out] param_value Address, where the information will be stored.
651 * @return SUCCESS if everything is OK.
652 * FAILURE if something failed.
655 int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t* param_value);
657 #endif /* __RPP_FR_H */