]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/include/rpp/fr.h
Removed the artificial constraints on the number of message buffers
[pes-rpp/rpp-lib.git] / rpp / include / rpp / fr.h
index 4b97dc7ffb459c98b2d1835df3876d92fd05bc49..9c6157a0eadab09d6c576ca92aff9eaa91b267e1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * @file fr.h
  *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
+ * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague
  *
  * @author Carlos Jenkins <carlos@jenkins.co.cr>
  * @author Michal Horn <hornmich@fel.cvut.cz>
  * Enumeration of states for the FlexRay
  */
 typedef enum {
-       RPP_FR_UNKNOWN, /**< FlexRay is in unknown state, this should not happen */
+       RPP_FR_UNKNOWN, /**< FlexRay is in unknown state, this should not happen */
        RPP_FR_NOT_INITIALIZED, /**< FlexRay driver was not yet configured and initialized, communication is not running. This is the default state after reset */
        RPP_FR_DRV_INITIALIZED, /**< FlexRay driver was initialized, communication is not running, Driver is ready for controller initialization */
        RPP_FR_CTR_INITIALIZED, /**< FlexRay controller was initlized, communicatin is not running, but can be started */
-       RPP_FR_RUNNING, /**< Communication is running */
-       RPP_FR_HALTED,  /**< Communication was halted, controller is ready for reconfiguration and restart of the communication */
-       RPP_FR_ABORTED  /**< Communication was aborted, controller is ready for reconfiguration and restart of the communication */
+       RPP_FR_RUNNING, /**< Communication is running */
+       RPP_FR_HALTED,  /**< Communication was halted, controller is ready for reconfiguration and restart of the communication */
+       RPP_FR_ABORTED  /**< Communication was aborted, controller is ready for reconfiguration and restart of the communication */
 } rpp_fr_state_t;
 
-#define RPP_FR_MAX_STATIC_BUF_CNT      32      /**< Maximum number of the buffers for static segment of the communication cycle */
-#define RPP_FR_MAX_DYNAMIC_BUF_CNT     32      /**< Maximum number of the buffers for dynamic segment of the communication cycle */
-#define RPP_FR_MAX_FIFO_BUF_DEPTH      32      /**< Maximal depth of the RX FIFO buffer */
+#define RPP_FR_MAX_STATIC_BUF_CNT   128  /**< Maximum number of the buffers for static segment of the communication cycle */
+#define RPP_FR_MAX_DYNAMIC_BUF_CNT  128  /**< Maximum number of the buffers for dynamic segment of the communication cycle */
+#define RPP_FR_MAX_FIFO_BUF_DEPTH   128  /**< Maximal depth of the RX FIFO buffer */
 
 /* AUTOSAR-like API */
 
 /**
  * FlexRay driver initialization.
  *
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
  * This method should be called before any other function from this
  * module.
  *
@@ -59,11 +61,14 @@ typedef enum {
  *         FAILURE if module already initialized.
  *
  */
-int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error);
+int8_t rpp_fr_init_driver(const Fr_ConfigType *config_ptr, uint32_t *error);
 
 /**
  * FlexRay controller initialization.
  *
+ * The function is thread safe, unless compiled with
+ * -DRPP_THREADSAFE=0.
+ *
  * This method should be called after rpp_fr_init_driver(), rpp_fr_halt_communication() or
  * rpp_fr_abort_communication() and before any other function from this module.
  *
@@ -96,11 +101,14 @@ int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error);
  *         FAILURE if module already initialized.
  */
 
-int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_terror);
+int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t *error);
 
 /**
  * Start communication
  *
+ * The function is thread safe, unless compiled with
+ * -DRPP_THREADSAFE=0.
+ *
  * This method should be called after rpp_fr_init_controller() and
  * before any attempt to send or receive messages.
  *
@@ -140,11 +148,13 @@ int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error);
  *         FAILURE if module already initialized.
  *
  */
-int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_terror);
+int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t *error);
 
 /**
  * Allow communication on all slots
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The FlexRay node can be configured to communicate only on key
  * frames after the startup. If this is the case, after calling this
  * function, communication on all configured slots is allowed.
@@ -162,6 +172,8 @@ int8_t rpp_fr_all_slots(uint8_t ctrl);
 /**
  * Stop communication after the end of the communication cycle.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function should be called only after
  * rpp_fr_start_communication() has been called.
  *
@@ -193,6 +205,8 @@ int8_t rpp_fr_halt_communication(uint8_t ctrl);
 /**
  * Stop communication immediately.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function should be called only after
  * rpp_fr_start_communication() has been called.
  *
@@ -223,6 +237,8 @@ int8_t rpp_fr_abort_communication(uint8_t ctrl);
 /**
  * Send wakeup pattern.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function should be called after FlexRay controller is initialized
  * and before the communication start.
  *
@@ -237,6 +253,8 @@ int8_t rpp_fr_send_wup(uint8_t ctrl);
 /**
  * Set channel for wakeup pattern sending.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * This allows to change the configuration passed to the
  * rpp_fr_init_driver().
  *
@@ -255,6 +273,8 @@ int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel);
 /**
  * Get FlexRay POC state
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after the driver is
  * initialized.
  *
@@ -265,11 +285,13 @@ int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusTypepoc_status_ptr);
+int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType *poc_status_ptr);
 
 /**
  * Send a message on the bus in the specified frame
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time when communication is running
  * (rpp_fr_start_communication() was called).
  *
@@ -288,11 +310,13 @@ int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType* poc_status_ptr);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_tlsdu, uint8_t lsdu_length);
+int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t *lsdu, uint8_t lsdu_length);
 
 /**
  * Cancel a transmission of the message.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time when communication is running
  * (rpp_fr_start_communication() was called).
  *
@@ -311,11 +335,21 @@ int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
 /**
  * Receive a message from the bus from the specified frame.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time when communication is running
  * (rpp_fr_start_communication() was called).
  *
  * If a new message was received in a buffer configured for the static
- * or dynamic segment, this function can retrieve it.
+ * and dynamic segment or FIFO, this function can retrieve it.
+ *
+ * The buffers with lower index (specified in configuration) have higher
+ * priority in retrieving process. This means for example if some buffer is
+ * configured to accept messages from slot 2 on channel A and another buffer
+ * accepts from slot 2 on channel B, the message from the first buffer
+ * will be retrieved first. If there is a FIFO buffer configured to accept
+ * messages from slot 2 in different cyclesets then other buffers, those
+ * messages accepted by the FIFO will be retrieved at the end of the process.
  *
  * @param [in] ctrl Not used, set always to zero.
  * @param [in] lpdu_idx Index of the frame where message will be received from.
@@ -328,11 +362,13 @@ int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t* lsdu, Fr_RxLPduStatusType* lpdu_status, uint8_t* lsdu_length);
+int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t *lsdu, Fr_RxLPduStatusType *lpdu_status, uint8_t *lsdu_length);
 
 /**
  * Check TX buffer status
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time when communication is running
  * (rpp_fr_start_communication() was called).
  *
@@ -353,12 +389,14 @@ int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t* lsdu, Fr_Rx
  * @return SUCCESS if everything is OK.
  *         FAILURE if something failed.
  */
-int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusTypelpdu_status);
+int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType *lpdu_status);
 
 
 /**
  * Reconfigure buffer
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time when after controller was initialized
  * (rpp_fr_init_controller() was called).
  *
@@ -376,17 +414,21 @@ int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduSta
  * @param [in] lpdu_idx Index of the frame, where reconfigured buffer is communicating.
  * @param [in] frame_id Frame ID, where the buffer will be communicating after the reconfiguration.
  * @param [in] channel Channel, where the buffer will be communicating. For dynamic segment it should not be AB.
- * @param [in] cycle Cycle rejection filter.
- * @param [in] payload Maximum payload for the reconfigured buffer in half-word. Must not be higher than the original payload.
+ * @param [in] cycle_set Cycle set value for cycle filtering. Can be 1, 2, 4, 8, 16, 32, 64.
+ * @param [in] cycle_offset Cycle offset value for cycle filtering. Must be 0 - cycle_set-1
+ * @param [in] payload Maximum payload for the reconfigured buffer in bytes. Must not be higher than the original payload, defined in half-words.
+ * @param [in] header_crc Not used, set to zero. The CRC is calculated automaticaly inside the function.
  *
  * @return SUCCESS if everything is OK.
  *         FAILURE if something failed.
  */
-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);
+int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle_set, uint8_t cycle_offset, uint8_t payload, uint16_t header_crc);
 
 /**
  * Disable a FlexRay buffer
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time when communication is running
  * (rpp_fr_start_communication() was called).
  *
@@ -405,6 +447,8 @@ int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
 /**
  * Get FlexRay global time
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after the controller is initialized.
  *
  * @param [in] ctrl Not used, set always to zero.
@@ -415,11 +459,13 @@ int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks);
+int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t *cycle, uint16_t *macroticks);
 
 /**
  * Get Network management vector.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after the controller is initialized.
  *
  * The FlexRay controller updates the vector at the end of every cycle
@@ -438,11 +484,13 @@ int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks
  * @return SUCCESS if everything is OK.
  *         FAILURE if something failed.
  */
-int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_tnm_vector);
+int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t *nm_vector);
 
 /**
  * Get channel status.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after the controller is
  * initialized.
  *
@@ -472,11 +520,13 @@ int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t* nm_vector);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t* channel_a_status, uint16_t* channel_b_status);
+int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t *channel_a_status, uint16_t *channel_b_status);
 
 /**
  * Get clock correction.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called while the communication is running or
  * was stopped.
  *
@@ -488,11 +538,13 @@ int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t* channel_a_status, uint1
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32_t* offset_correction);
+int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t *rate_correction, int32_t *offset_correction);
 
 /**
  * Gets a list of syncframes received or transmitted on channel A and channel B via the even and odd communication cycle.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called while communication is running or was stopped.
  *
  * @param [in] ctrl Not used, set always to zero.
@@ -517,12 +569,14 @@ int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_tchannel_a_even_list,
-                                 uint16_t* channel_b_even_list, uint16_t* channel_a_odd_list, uint16_t* channel_b_odd_list);
+int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t *channel_a_even_list,
+                                                                 uint16_t *channel_b_even_list, uint16_t *channel_a_odd_list, uint16_t *channel_b_odd_list);
 
 /**
  * Get the status of WUP receiving
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after controller is initialized.
  *
  * If the Wake Up Pattern was received on some channel, the flag is set in status address.
@@ -537,11 +591,13 @@ int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t* cha
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_tstatus);
+int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t *status);
 
 /**
  * Set the absolute timer and start it.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after communication is running.
  *
  * The FlexRay controller has two absolute timers. Each of them can be
@@ -567,6 +623,8 @@ int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint
 /**
  * Stop the absolute timer, clear IRQ.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after communication is running.
  *
  * The FlexRay controller has two absolute timers. Each of them can be
@@ -591,6 +649,8 @@ int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx);
 /**
  * Clear the IRQ flag of the absolute timer
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after communication is running.
  *
  * The FlexRay controller has two absolute timers. Each of them can be
@@ -613,6 +673,8 @@ int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx);
 /**
  * Get IRQ flag of the absolute timer
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time after communication is running.
  *
  * The FlexRay controller has two absolute timers. Each of them can be
@@ -631,11 +693,13 @@ int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_tirq_pending);
+int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t *irq_pending);
 
 /**
  * Get information about the driver vendor, module and version.
  *
+ * The function is thread safe
+ *
  * The function can be called any time.
  *
  * @param [out] version Address, where the information will be stored.
@@ -643,11 +707,13 @@ int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t* i
  * @return always SUCCESS
  *
  */
-int8_t rpp_fr_get_driver_version(Std_VersionInfoTypeversion);
+int8_t rpp_fr_get_driver_version(Std_VersionInfoType *version);
 
 /**
  * Get configuration parameter value from the internal driver structures.
  *
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
  * The function can be called any time.
  *
  * @param [in] ctrl Not used, set always to zero.
@@ -658,6 +724,6 @@ int8_t rpp_fr_get_driver_version(Std_VersionInfoType* version);
  *         FAILURE if something failed.
  *
  */
-int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_tparam_value);
+int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t *param_value);
 
 #endif /* __RPP_FR_H */