]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
RPP layer created, config functions not yet implemented.
authorMichal Horn <hornmich@fel.cvut.cz>
Wed, 14 Aug 2013 15:23:21 +0000 (17:23 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Wed, 14 Aug 2013 15:23:21 +0000 (17:23 +0200)
rpp/include/rpp/fr.h
rpp/src/rpp/fr.c

index 12a2f6470e609eb16a7a073988a19f5c97654cc0..56b1dd3de4aa48a04569c7c8a4ad6e46f4cde287 100644 (file)
 #ifndef __RPP_FR_H
 #define __RPP_FR_H
 
+#include "drv/Fr_GeneralTypes.h"
+#include "drv/fr_tms570.h"
+
+typedef enum {
+       RPP_FR_UNKNOWN,
+       RPP_FR_CONFIGURED,
+       RPP_FR_NOT_INITIALIZED,
+       RPP_FR_DRV_INITIALIZED,
+       RPP_FR_CTR_INITIALIZED,
+       RPP_FR_RUNNING,
+       RPP_FR_HALTED,
+       RPP_FR_ABORTED
+} rpp_fr_state_t;
+
+/**
+ * Store cluster configuration parameters.
+ *
+ * This functions provides a mechanism to do the user FlexRay configuration.
+ * The function parses the string with parameters and stores them into an
+ * internal structure.
+ * For complete user configuration also rpp_fr_config_node_params and
+ * rpp_fr_config_static_buffer have to be called to configure local
+ * FlexRay parameters and at least one static buffer.
+ *
+ * The string with configuration contains hexadecimal numbers separated by spaces.
+ * Each number stands for one parameter in this order:
+ * gColdStartAttempts
+ * gdActionPointOffset
+ * gdCASRxLowMax
+ * gdDynamicSlotIdlePhase
+ * gdMinislot
+ * gdMinislotActionPointOffset
+ * gdStaticSlot
+ * gdTSSTransmitter
+ * gdWakeupSymbolRxIdle
+ * gdWakeupSymbolRxLow
+ * gdWakeupSymbolRxWindow
+ * gdWakeupSymbolTxIdle
+ * gdWakeupSymbolTxLow
+ * gListenNoise
+ * gMacroPerCycle
+ * gMaxWithoutClockCorrectionFatal
+ * gMaxWithoutClockCorrectionPassive
+ * gNumberOfMinislots
+ * gNumberOfStaticSlots
+ * gOffsetCorrectionStart
+ * gPayloadLengthStatic
+ * gSyncNodeMax
+ * gdNIT
+ * gdSampleClockPeriod
+ * gNetworkManagementVectorLength
+ *
+ * For example:
+ * "0x2 0xF 0x15E0 0xF 0xF 0xC 0x15A 0x8 0xAE4 0x9 0xF 0x4 0x43 0x1 0x4 0x2 0xAE3 0x0 0x56 0xA 0x12 0x12 0x4C 0xB4 0x3C"
+ *
+ * @param [in] params Address of the string with configuration parameters
+ *
+ * @return SUCCESS if configuration successful.
+ *         FAILURE if parameter parsing fails.
+ */
+int8_t rpp_fr_config_cluster_params(const char* params);
+
+/**
+ * Store node configuration parameters.
+ *
+ * This functions provides a mechanism to do the user FlexRay configuration.
+ * The function parses the string with parameters and stores them into an
+ * internal structure.
+ * For complete user configuration also rpp_fr_config_cluster_params and
+ * rpp_fr_config_static_buffer have to be called to configure global
+ * FlexRay parameters and at least one static buffer.
+ *
+ * The string with configuration contains hexadecimal numbers separated by spaces.
+ * Each number stands for one parameter in this order:
+ * pAllowHaltDueToClock
+ * pAllowPassiveToActive
+ * pChannels (0 - A, 1 - B, 2 - AB)
+ * pClusterDriftDamping
+ * pDelayCompensationA
+ * pDelayCompensationB
+ * pExternOffsetCorrection
+ * pExternRateCorrection
+ * pKeySlotUsedForStartup
+ * pKeySlotUsedForSync
+ * pLatestTx
+ * pMacroInitialOffsetA
+ * pMacroInitialOffsetB
+ * pMicroInitialOffsetA
+ * pMicroInitialOffsetB
+ * pMicroPerCycle
+ * pRateCorrectionOut
+ * pOffsetCorrectionOut
+ * pSamplesPerMicrotick
+ * pSingleSlotEnabled
+ * pWakeupChannel (0 - A, 1 - B)
+ * pWakeupPattern
+ * pdAcceptedStartupRange
+ * pdListenTimeout
+ * pdMaxDrift
+ * pDecodingCorrection
+ * syncFramePayloadMultiplexEnabled
+ * secureBuffers (0 - FR_SB_RECONFIG_ENABLED, 1 - FR_SB_STAT_REC_DISABLED_STAT_TR_DISABLED, 2 - FR_SB_ALL_REC_DISABLED, 3 - FR_SB_ALL_REC_DISABLED_STAT_TR_DISABLED)
+ *
+ * For example:
+ * "0x0 0x0 0x2 0x1 0x3 0x3 0x0 0x0 0x1 0x1 0x10D 0x6 0x6 0x18 0x18 0x36B00 0xCD 0x151 0x0 0x1 0x0 0x2 0x81 0x36DA2 0x151 0x33 0x0 0x0"
+ *
+ * @param [in] params Address of the string with configuration parameters
+ *
+ * @return SUCCESS if configuration successful.
+ *         FAILURE if parameter parsing fails.
+ */
+int8_t rpp_fr_config_node_params(const char* params);
+
+/**
+ * Add new static buffer configuration into the list of buffers.
+ *
+ * This functions provides a mechanism to do the user FlexRay configuration.
+ * The function parses the string with parameters and stores them into an
+ * internal structure.
+ * For complete user configuration also rpp_fr_config_cluster_params and
+ * rpp_fr_config_node_params have to be called to configure global and local
+ * FlexRay parameters.
+ * At least one static buffer must be configured as TX. For sync and coldstart nodes
+ * the first buffer should be configured as TX.
+ *
+ * The string with configuration contains hexadecimal numbers or strings separated by spaces.
+ * Each number or string stands for one parameter in this order:
+ * channel (0 - A, 1 - B, 2 - AB)
+ * cycleCounterFiltering
+ * isTx
+ * maxPayload
+ * msgBufferInterrupt
+ * payloadPreambleIndicatorTr
+ * singleTransmit
+ * slotId
+ *
+ * For example:
+ * "0x2 0x0 0x1 0x9 0x1 0x0 0x0 0x1"
+ *
+ * @param [in] params Address of the string with configuration parameters
+ *
+ * @return SUCCESS if configuration successful.
+ *         FAILURE if parameter parsing fails.
+ */
+int8_t rpp_fr_config_static_buffer(const char* params);
+
+/**
+ * Add new dynamic buffer configuration into the list of buffers.
+ *
+ * This functions provides a mechanism to do the user FlexRay configuration.
+ * The function parses the string with parameters and stores them into an
+ * internal structure.
+ * For complete user configuration also rpp_fr_config_cluster_params,
+ * rpp_fr_config_node_params and rpp_fr_config_static_buffer have to be called
+ * to configure global, local FlexRay parameters and at least one static buffer.
+ *
+ * The string with configuration contains hexadecimal numbers or strings separated by spaces.
+ * Each number or string stands for one parameter in this order:
+ * channel (0 - A, 1 - B)
+ * cycleCounterFiltering
+ * isTx
+ * maxPayload
+ * msgBufferInterrupt
+ * singleTransmit
+ * slotId
+ *
+ * For example:
+ * "0x0 0x0 0x1 0x9 0x1 0x0 0x1"
+ *
+ * @param [in] params Address of the string with configuration parameters
+ *
+ * @return SUCCESS if configuration successful.
+ *         FAILURE if parameter parsing fails.
+ */
+int8_t rpp_fr_config_dynamic_buffer(const char* params);
+
+/**
+ * Configures new RX FIFO buffer configuration into the list of buffers.
+ *
+ * This functions provides a mechanism to do the user FlexRay configuration.
+ * The function parses the string with parameters and stores them into an
+ * internal structure.
+ * For complete user configuration also rpp_fr_config_cluster_params,
+ * rpp_fr_config_node_params and rpp_fr_config_static_buffer have to be called
+ * to configure global, local FlexRay parameters and at least one static buffer.
+ * Only one RX FIFO buffer with specified depth can be configured.
+ *
+ * The string with configuration contains hexadecimal numbers or strings separated by spaces.
+ * Each number or string stands for one parameter in this order:
+ * depth
+ * channel (0 - A, 1 - B, 2 - AB)
+ * cycleCounterFiltering
+ * maxPayload
+ * rejectNullFrames
+ * rejectStaticSegment
+ * slotId (zero means no frame will be rejected)
+ *
+ * For example:
+ * "0x5 0x2 0x0 0x40 0x1 0x0 0x0"
+ *
+ * @param [in] params Address of the string with configuration parameters
+ *
+ * @return SUCCESS if configuration successful.
+ *         FAILURE if parameter parsing fails.
+ */
+int8_t rpp_fr_config_fifo_buffer(const char* params);
+
 /**
  * FR module initialization.
  *
  */
 int8_t rpp_fr_init();
 
+/**
+ * FlexRay driver initialization.
+ *
+ * This method should be called after rpp_fr_init and before any
+ * other function from this module, except rpp_fr_config functions.
+ *
+ * The functions copies configuration data into drivers internal
+ * structures and initializes the driver.
+ *
+ * There are two ways how to configure FlexRay.
+ * 1) Passing address of the config structure as an argument from the application
+ * 2) Using rpp_fr_config functions to create user configuration. Then the argument
+ * for this function has to be NULL and configuration functions have to be called before
+ * this function.
+ *
+ * After successful driver initialization, the FlexRay is ready for:
+ * rpp_fr_init_controller
+ * rpp_fr_get_poc_status
+ * rpp_fr_get_wakeup_rx_status
+ * rpp_fr_get_timer_irq_status
+ *
+ * @param [in] Fr_ConfigPtr Address of the structure with all FlexRay
+ * configuration parameters. If it is NULL, then default structure,
+ * filled by rpp_fr_config functions, is used.
+ * @param [out] error Address where error flags will be stored. The flags
+ * definitions can be found in fr_tms570h, with ERR_PARAM prefix.
+ *
+ * @return SUCCESS if initialization successful.
+ *         FAILURE if module already initialized.
+ *
+ */
+int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error);
+
+/**
+ * FlexRay controller initialization.
+ *
+ * This method should be called after rpp_fr_init_driver and before any
+ * other function from this module.
+ *
+ * The functions checks configuration parameters and configures FlexRay
+ * controller registers.
+ *
+ * After successful controller initialization, the FlexRay is ready for:
+ * rpp_fr_init_controller
+ * rpp_fr_get_poc_status
+ * rpp_fr_get_wakeup_rx_status
+ * rpp_fr_get_timer_irq_status
+ * rpp_fr_start_communication
+ * rpp_fr_send_wup
+ * rpp_fr_set_wu_channel
+ * rpp_fr_get_global_time
+ * rpp_fr_get_network_management_vector
+ * rpp_fr_get_channel_status
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] error Address where error flags will be stored. The flags
+ * definitions can be found in fr_tms570h, with ERR_PARAM and FR_INIT_ERR
+ * prefix.
+ *
+ * @return SUCCESS if initialization successful.
+ *         FAILURE if module already initialized.
+ *
+ */
+int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error);
+
+/**
+ * FlexRay start communication
+ *
+ * This method should be called after rpp_fr_init_controller and attempt
+ * to sending or receiving messages
+ *
+ * For coldstarter the function tries to listen and join an existing network.
+ * If it fails, it tries to initiate the new one.
+ * For regular node it only listens on the bus and tries to join to
+ * some existing network.
+ *
+ * After successful communication start, the FlexRay is ready for:
+ * rpp_fr_init_controller
+ * rpp_fr_get_poc_status
+ * rpp_fr_get_wakeup_rx_status
+ * rpp_fr_get_timer_irq_status
+ * rpp_fr_start_communication
+ * rpp_fr_send_wup
+ * rpp_fr_set_wu_channel
+ * rpp_fr_get_global_time
+ * rpp_fr_get_network_management_vector
+ * rpp_fr_get_channel_status
+ * rpp_fr_all_slots
+ * rpp_fr_halt_communication
+ * rpp_fr_abort_communication
+ * rpp_fr_transmit_lpdu
+ * rpp_fr_cancel_transmit_lpdu
+ * rpp_fr_receive_lpdu
+ * rpp_fr_check_tx_lpdu_status
+ * rpp_fr_disable_lpdu
+ * rpp_fr_get_clock_correction
+ * rpp_fr_get_sync_frame_list
+ * rpp_fr_set_timer
+ * rpp_fr_cancel_timer
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] error Address where error flags will be stored. The flags
+ * definitions can be found in fr_tms570h, with FR_STARTUP_ERR prefix.
+ *
+ * @return SUCCESS if initialization successful.
+ *         FAILURE if module already initialized.
+ *
+ */
+int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t* error);
+
+/**
+ * FlexRay allow communication on all slots
+ *
+ * The FlexRay node can be configured to communicate only on key frames
+ * after the startup. Using this function the communication on all
+ * configured slots can be allowed.
+ *
+ * The function should be called only when the communication is running.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ *
+ * @return SUCCESS if started successfully.
+ *         FAILURE if timeout reached.
+ *
+ */
+int8_t rpp_fr_all_slots(uint8_t ctrl);
+
+/**
+ * FlexRay stop communication after the end of the cycle.
+ *
+ * The function should be called only when the communication is running.
+ *
+ * After the communication is stopped, only those functions are allowed:
+ * rpp_fr_get_global_time
+ * rpp_fr_get_network_management_vector
+ * rpp_fr_get_channel_status
+ * rpp_fr_get_clock_correction
+ * rpp_fr_get_sync_frame_list
+ * rpp_fr_get_wakeup_rx_status
+ * rpp_fr_get_poc_status
+ *
+ * To establish new communication, reset the device.
+
+ * @param [in] ctrl Not used, set always to zero.
+ *
+ * @return SUCCESS if command passed successfully.
+ *         FAILURE if command rejectred.
+ *
+ */
+int8_t rpp_fr_halt_communication(uint8_t ctrl);
+
+/**
+ * FlexRay stop communication immediately.
+ *
+ * The function should be called only when the communication is running.
+ *
+ * After the communication is stopped, only those functions are allowed:
+ * rpp_fr_get_global_time
+ * rpp_fr_get_network_management_vector
+ * rpp_fr_get_channel_status
+ * rpp_fr_get_clock_correction
+ * rpp_fr_get_sync_frame_list
+ * rpp_fr_get_wakeup_rx_status
+ * rpp_fr_get_poc_status
+ *
+ * To establish new communication, reset the device.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ *
+ * @return SUCCESS if command passed successfully.
+ *         FAILURE if command rejectred.
+ *
+ */
+int8_t rpp_fr_abort_communication(uint8_t ctrl);
+
+/**
+ * FlexRay send wakeup pattern.
+ *
+ * The function should be called after FlexRay controller is initialized
+ * and before the communication start.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ *
+ * @return SUCCESS if command passed successfully.
+ *         FAILURE if command rejectred.
+ *
+ */
+int8_t rpp_fr_send_wup(uint8_t ctrl);
+
+/**
+ * FlexRay set channel for wakeup pattern sending.
+ *
+ * The function should be called after FlexRay controller is initialized
+ * and before the communication start.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ *
+ * @return SUCCESS if command passed successfully.
+ *         FAILURE if command rejectred.
+ *
+ */
+int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel);
+
+/**
+ * Get FlexRay POC state
+ *
+ * The function can be called any time after driver is initialized.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @parap [out] poc_status_ptr Address where status will be stored.
+ *
+ * @return SUCCESS if status retrieved successfully.
+ *         FAILURE if something failed.
+ *
+ */
+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 can be called any time when communication is running
+ * (Fr_StartCommunication was called).
+ *
+ * If the buffer assigned to the frame is in continuous mode, this
+ * functions starts periodical message sending. The transmission can
+ * be stopped by rpp_fr_cancel_transmit_lpdu.
+ * If the buffer assigned to the frame is in single-shot mode, the
+ * message is sent only once.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] lpdu_idx Index of the frame, where the message will be sent.
+ * @param [in] lsdu Address of the first byte of the message.
+ * @param [in] lsdu_length Number of bytes of the message.
+ *
+ * @return SUCCESS if message was transmitted.
+ *         FAILURE if something failed.
+ *
+ */
 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 can be called any time when communication is running
+ * (Fr_StartCommunication was called).
+ *
+ * This is one way to stop transmission for buffers configured
+ * in continuous mode.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] lpdu_idx Index of the frame, where the message transmission will be stopped.
+ *
+ * @return SUCCESS if the transmission was stopped.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
+
+/**
+ * Receive a message from the bus in the specified frame
+ *
+ * The function can be called any time when communication is running
+ * (Fr_StartCommunication was called).
+ *
+ * If new message was received in static or dynamic buffer into some RX buffer,
+ * this function can retrieve it.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] lpdu_idx Index of the frame where message will be received from.
+ * @param [out] lsdu Address of the first byte of the buffer, where message will be stored.
+ * @param [out] lpdu_status Address where the status will be stored. It can be:
+ * FR_NOT_RECEIVED, FR_RECEIVED, FR_RECEIVED_MORE_DATA_AVAILABLE - for FIFO only.
+ * @param [out] lsdu_length Number of bytes of the message.
+ *
+ * @return SUCCESS if message was received.
+ *         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);
+
+/**
+ * Check TX buffer status
+ *
+ * The function can be called any time when communication is running
+ * (Fr_StartCommunication was called).
+ *
+ * If buffer configured in single-shot mode, the transmission request (TXR)
+ * is pending until the message is send.
+ * For buffers configured in continuous mode, the transmission request is
+ * always pending.
+ *
+ * The TXR pending or not pending is the status of the buffer.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] lpdu_idx Index of the frame to which the buffer is assigned.
+ * @param [out] lpdu_status Address of the status. It can be FR_TRANSMITTED,
+ * which means the TXR is not pending, or FR_NOT_TRANSMITTED which means that
+ * TXR is pending.
+ *
+ * @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_TxLPduStatusType* lpdu_status);
+
+/**
+ * Disable FlexRay buffer
+ *
+ * The function can be called any time when communication is running
+ * (Fr_StartCommunication was called).
+ *
+ * This functions resets the configuration of the selected buffer.
+ * The disabled buffer is not usable any more.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] lpdu_idx Index of the frame to which the buffer is assigned.
+ *
+ * @return SUCCESS if buffer was disabled.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
+
+/**
+ * Get FlexRay global time
+ *
+ * The function can be called any time after controller is initialized.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] cycle Adress where the number of actual cycle will be stored.
+ * @param [out] macroticks Address where offset in the cycle will be stored.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks);
+
+/**
+ * Get Network management vector.
+ *
+ * The function can be called any time after controller is initialized.
+ *
+ * The FlexRay controller updates the vector at the end of every cycle by
+ * doing bit-wise or on every network managemet vectors received from all nodes.
+ *
+ * The NM vector can be sent to a frame by a buffer with payloadPreambleIndicatorTr
+ * set. Those frames are automatically processed by the controller. But sending the
+ * vector has to be done manually by copying the NM vector data (obtainable by
+ * this function) into the TX buffer (using rpp_fr_transmit_lpdu function).
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] nm_vector Address where the vector will be stored. The size of the buffer has to be at least gNetworkManagementVectorLength.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t* nm_vector);
+
+/**
+ * Get Channel status.
+ *
+ * The function can be called any time after controller is initialized.
+ *
+ * The output of the function is bitcoded in this way:
+ * Bit 0: Channel A/B aggregated channel status vSS!ValidFrame
+ * Bit 1: Channel A/B aggregated channel status vSS!SyntaxError
+ * Bit 2: Channel A/B aggregated channel status vSS!ContentError
+ * Bit 3: Channel A/B aggregated channel status additional communication
+ * Bit 4: Channel A/B aggregated channel status vSS!Bviolation
+ * Bit 5: Channel A/B aggregated channel status vSS!TxConflict
+ * Bit 6: Not used (0)
+ * Bit 7: Not used (0)
+ * Bit 8: Channel A/B symbol window status data vSS!ValidMTS
+ * Bit 9: Channel A/B symbol window status data vSS!SyntaxError
+ * Bit 10: Channel A/B symbol window status data vSS!Bviolation
+ * Bit 11: Channel A/B symbol window status data vSS!TxConflict
+ * Bit 12: Channel A/B NIT status data vSS!SyntaxError
+ * Bit 13: Channel A/B NIT status data vSS!Bviolation
+ * Bit 14: Not used (0)
+ * Bit 15: Not used (0)
+ *
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] channel_a_status Address where the bitcoded status of the channel A will be stored.
+ * @param [out] channel_b_status Address where the bitcoded status of the channel B will be stored.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+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 can be called while communication is running or was stopped.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] rate_correction Address where the rate will be stored.
+ * @param [out] offset_correction Address where the offset will be stored.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32_t* offset_correction);
+
+/**
+ * Get clock correction.
+ *
+ * The function can be called while communication is running or was stopped.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] rate_correction Address where the rate will be stored.
+ * @param [out] offset_correction Address where the offset will be stored.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+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_bodd_list);
+
+/**
+ * Get the status of WUP receiving
+ *
+ * The function can be called any time after controller is initialized.
+ *
+ * If Wake Up Pattern was received on some channel, the flag is set in status address.
+ * Bit 0: Wakeup received on channel A indicator
+ * Bit 1: Wakeup received on channel B indicator
+ * Bit 2-7: Unused
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [out] status Address where the status will be stored.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t* status);
+
+/**
+ * Set an absolute timer and start it.
+ *
+ * The function can be called any time after communication is running.
+ * The FlexRay controller has two absolute timers. Each of them can be
+ * configured to request the interrupt, when the global time reaches
+ * configured cycle and offset.
+ *
+ * Timer interrupt request can be detected by rpp_fr_get_timer_irq_status.
+ * Timer interrupt request can be cleared by rpp_fr_clear_timer_irq
+ * Timer can be canceled by rpp_fr_cancel_timer.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] timer_idx Index of the timer (0,1).
+ * @param [in] cycle_threshold Number of the cycle.
+ * @param [in] offset_threshold Offset in the cycle in mactroticks.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_threshold, uint16_t offset_threshold);
+
+/**
+ * Stops an absolute timer, clear IRQ.
+ *
+ * The function can be called any time after communication is running.
+ *
+ * The FlexRay controller has two absolute timers. Each of them can be
+ * configured to request the interrupt, when the global time reaches
+ * configured cycle and offset. This function stops the timer and clears
+ * the interrupt request.
+ *
+ * Timer interrupt request can be detected by rpp_fr_get_timer_irq_status.
+ * Timer interrupt request can be cleared by rpp_fr_clear_timer_irq
+ * Timer can be started by rpp_fr_set_timer.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] timer_idx Index of the timer (0,1).
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx);
+
+/**
+ * Clear IRQ flag of the absolute timer
+ *
+ * The function can be called any time after communication is running.
+ *
+ * The FlexRay controller has two absolute timers. Each of them can be
+ * configured to request the interrupt, when the global time reaches
+ * configured cycle and offset. This function clears the IRQ flag.
+ *
+ * Timer interrupt request can be detected by rpp_fr_get_timer_irq_status.
+ * Timer can be started by rpp_fr_set_timer.
+ * Timer can be canceled by rpp_fr_cancel_timer.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] timer_idx Index of the timer (0,1).
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx);
+
+/**
+ * Get IRQ flag of the absolute timer
+ *
+ * The function can be called any time after communication is running.
+ *
+ * The FlexRay controller has two absolute timers. Each of them can be
+ * configured to request the interrupt, when the global time reaches
+ * configured cycle and offset. Using this function the IRQ can be detected.
+ *
+ * Timer interrupt request can be cleared by rpp_fr_clear_timer_irq
+ * Timer can be started by rpp_fr_set_timer.
+ * Timer can be canceled by rpp_fr_cancel_timer.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] timer_idx Index of the timer (0,1).
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+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 can be called any time.
+ *
+ * @param [out] version Address, where the information will be stored.
+ *
+ * @return always SUCCESS
+ *
+ */
+int8_t rpp_fr_get_driver_version(Std_VersionInfoType* version);
+
+/**
+ * Get configuration parameter value from the internal driver structures.
+ *
+ * The function can be called any time.
+ *
+ * @param [in] ctrl Not used, set always to zero.
+ * @param [in] param_idx The index if the parameter. You can find the indexes in Fr_GeneralTypes.h file with FR_CIDX prefix.
+ * @param [out] param_value Address, where the information will be stored.
+ *
+ * @return SUCCESS if everything is OK.
+ *         FAILURE if something failed.
+ *
+ */
+int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t* param_value);
+
 #endif /* __RPP_FR_H */
 
index fec3b346ba63484105e00222d192adfa1261c347..3da6a64550cf4b73bf95cab8eea93ba220930c5d 100644 (file)
@@ -2,6 +2,7 @@
  *
  * Authors:
  *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *     - Michal Horn <hornmich@fel.cvut.cz>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 
 #include "rpp/rpp.h"
+#include "stdio.h"
 
 #if rppCONFIG_INCLUDE_FR == 1
 
-static boolean_t initialized = FALSE;
+rpp_fr_state_t rpp_fr_state = RPP_FR_NOT_INITIALIZED;  /**< Stores the actual state of the FlexRay module */
 
-int8_t rpp_fr_init()
-{
-    if(initialized) {
-        return FAILURE;
-    }
-    initialized = TRUE;
+int8_t rpp_fr_config_cluster_params(const char* params) {
 
-    // FIXME: Implement.
+}
+
+int8_t rpp_fr_config_node_params(const char* params) {
+
+}
+
+int8_t rpp_fr_config_static_buffer(const char* params) {
+
+}
+
+int8_t rpp_fr_config_dynamic_buffer(const char* params) {
+
+}
+
+int8_t rpp_fr_config_fifo_buffer(const char* params) {
+
+}
+
+int8_t rpp_fr_init() {
+       /* Not used by FlexRay, initialization is started from the
+        * application by calling rpp_fr_init_driver and
+        * rpp_fr_init_controller.
+        */
    return SUCCESS;
 }
 
+int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error) {
+       if (rpp_fr_state <= RPP_FR_DRV_INITIALIZED) {
+               if (config_ptr == NULL) {       // Use user configuration created before by rpp_fr_config functions
+                       if (rpp_fr_state == RPP_FR_CONFIGURED) {
+                               rpp_fr_state = RPP_FR_DRV_INITIALIZED;
+                       }
+                       else {
+                               *error = FR_INIT_ERR_BAD_PARAM;
+                               return FAILURE;
+                       }
+               }
+               else {  // Use configuration from the structure from parameter.
+                       Fr_Init(config_ptr);
+               }
+               rpp_fr_state = RPP_FR_DRV_INITIALIZED;
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error) {
+       Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+       if (rpp_fr_state == RPP_FR_DRV_INITIALIZED) {
+               retVal = Fr_ControllerInit(ctrl);
+               if (retVal & E_OK) {
+                       rpp_fr_state = RPP_FR_CTR_INITIALIZED;
+                       return SUCCESS;
+               }
+               else {
+                       *error = retVal;
+                       return FAILURE;
+               }
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t* error) {
+       Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+       if (rpp_fr_state == RPP_FR_CTR_INITIALIZED) {
+               retVal = Fr_StartCommunication(ctrl);
+               if (retVal & E_OK) {
+                       rpp_fr_state = RPP_FR_RUNNING;
+                       return SUCCESS;
+               }
+               else {
+                       *error = retVal;
+                       return FAILURE;
+               }
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_all_slots(uint8_t ctrl) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_AllSlots(ctrl) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_halt_communication(uint8_t ctrl) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_HaltCommunication(ctrl) & E_OK) {
+               rpp_fr_state = RPP_FR_HALTED;
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_abort_communication(uint8_t ctrl) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_AbortCommunication(ctrl) & E_OK) {
+               rpp_fr_state = RPP_FR_ABORTED;
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_send_wup(uint8_t ctrl) {
+       if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SendWUP(ctrl) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel) {
+       if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SetWakeupChannel(ctrl, channel) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType* poc_status_ptr) {
+       if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetPOCStatus(ctrl, poc_status_ptr) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t* lsdu, uint8_t lsdu_length) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_TransmitTxLPdu(ctrl, lpdu_idx, lsdu, lsdu_length) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelTxLPdu(ctrl, lpdu_idx) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t* lsdu, Fr_RxLPduStatusType* lpdu_status, uint8_t* lsdu_length) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_ReceiveRxLPdu(ctrl, lpdu_idx, lsdu, lpdu_status, lsdu_length) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType* lpdu_status) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_CheckTxLPduStatus(ctrl, lpdu_idx, lpdu_status) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_DisableLPdu(ctrl, lpdu_idx) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t* cycle, uint16_t* macroticks) {
+       if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetGlobalTime(ctrl, cycle, macroticks) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t* nm_vector) {
+       if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetNmVector(ctrl, nm_vector) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t* channel_a_status, uint16_t* channel_b_status) {
+       if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetChannelStatus(ctrl, channel_a_status, channel_b_status) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t* rate_correction, int32_t* offset_correction) {
+       if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetClockCorrection(ctrl, rate_correction, offset_correction) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+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) {
+       if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetSyncFrameList(ctrl, list_size, channel_a_even_list, channel_b_even_list, channel_a_odd_list, channel_b_odd_list) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t* status) {
+       if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetWakeupRxStatus(ctrl, status) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_threshold, uint16_t offset_threshold) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_SetAbsoluteTimer(ctrl, timer_idx, cycle_threshold, offset_threshold) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx) {
+       if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelAbsoluteTimer(ctrl, timer_idx) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx) {
+       if (rpp_fr_state == RPP_FR_DRV_INITIALIZED && Fr_AckAbsoluteTimerIRQ(ctrl, timer_idx) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t* irq_pending) {
+       if (rpp_fr_state == RPP_FR_DRV_INITIALIZED && Fr_GetAbsoluteTimerIRQStatus(ctrl, timer_idx, irq_pending) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
+int8_t rpp_fr_get_driver_version(Std_VersionInfoType* version) {
+       Fr_GetVersionInfo(version);
+       return SUCCESS;
+}
+
+int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t* param_value) {
+       if (Fr_ReadCCConfig(ctrl, param_idx, param_value) & E_OK) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+
 
 #endif /* rppCONFIG_INCLUDE_FR */