/** * @file event_fifo.h * @brief Handle Event Fifo operations. * @note * * ------------------------------------------------------------------ Copyright (c) 2023 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE. IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ */ #ifndef INCLUDE_EVENT_BUFFER_H_ #define INCLUDE_EVENT_BUFFER_H_ #include "ltcusb.h" #include "trb_fifo.h" #include "rv_delay.h" #include "time.h" #include "initialization_on_USB_reset.h" #include "Initialization_on_Connect_Done.h" #include typedef enum Events_enum { device_event_DisconnEvt = 0, device_event_USBRst = 1, device_event_ConnectDone = 2, device_event_ULStChng = 3, device_event_EvntOverflow = 11, ep_event_XferComplete = 21, ep_event_XferInProgress = 22, ep_event_XferNotReady = 23, event_invalid = 255, }Events; /** * @brief Holding the Event Buffer Content for Device Endpoint-Specific * Events(Event[0] = 0x0) */ typedef struct DEPEVT_event_struct { /**@brief bit 0, Indicates that this is an endpoint-specific event.*/ uint32_t endpoint_specific_event : 1; /**@brief bit 5:1, Physical Endpoint Number.*/ uint32_t physical_endpoint_number : 5; /**@brief bit 9:6, Events*/ uint32_t event_9_6: 4; /**@brief bit 11:10, Reserved.*/ uint32_t reserved_11_10 : 2; /**@brief bit 15:12, Event Status.*/ uint32_t EventStatus : 4; /**@brief bit 31:16, Event Parameters.*/ uint32_t EventParam : 16; }DEPEVT_event; /** * @brief Holding the Event Buffer Content for Device-Specific Events * (Event[0] = 0x1, Event[7:1] = 0x00) */ typedef struct DEVT_event_struct { /**@brief bit 0, Non-Endpoint-Specific Event.*/ uint32_t non_endpoint_specific_event : 1; /**@brief bit 7:1, Device Specific Event.*/ uint32_t device_specific_event : 7; /**@brief bit 12:8, Events */ uint32_t event_12_8: 5; /**@brief bit 15:13, Reserved.*/ uint32_t reserved_15_13 : 3; /**@brief bit 19:16, Link State.Indicates link state at the time of the * event. */ uint32_t EvtInfo_Link_State : 4; /** * @brief bit 20, SuperSpeed event. Set to 1 for SS; Set to 0 for non-SS. */ uint32_t EvtInfo_SuperSpeed_Event : 1; /** * @brief bit 24:21 HIRD value received from the LPM token (valid for a * Hibernation Request Event) */ uint32_t EvtInfo_HIRD : 4; /**@brief bit 31:25, Reserved.*/ uint32_t reserved_31_25 : 7; }DEVT_event; /** * @brief Get the Event from Event FIFO. * @param EvtInfo_LinkState If device specific event occure then link state * @param ep If endpoint specific event occure then endpoint number. * @param event_read Event read from event fifo. * @return Events */ extern Events event(uint8_t* EvtInfo_LinkState, uint8_t* ep, uint32_t event_read); /** * @brief Set the DCTL register according to Disconnect Event. * @return 0 on success. * @retval -1 DCTL write failed for Disconnect Event. */ extern int Disconnect_Event(); /** * @brief This will poll for different Events by reading the Event Buffer * data. Keep Checking the Event FIFO untill the required event occurs * @param event_to_get Type of event need to poll. * @param EvtInfo_LinkState If device specific event occure then link state * @param ep If endpoint specific event occure then endpoint number. * @return 0 on Success. * @retval -1 getting event failed. * @retval -2 Required Event did not occur, retry count reached. */ extern int event_while(Events event_to_get, uint8_t EvtInfo_LinkState, uint8_t ep); /** * @brief This will clear the Event Buffer Size. * @return 0 on success. * @retval -1 gevntcount_get failed. * @retval -2 gevntcount_init failed. */ extern int event_buffer_size_clear(); /** * @brief This will check for different Events by reading the Event Buffer * data for the required event. * @param event_to_get Type of event need to poll. * @param EvtInfo_LinkState If device specific event occure then link * state. * @param ep If endpoint specific event occure then endpoint number. * @return 0 on Success. * @retval -1 Event mismatched. */ extern int event_check(uint32_t event_low,uint32_t event_high, Events event_to_get,uint8_t EvtInfo_LinkState,uint8_t ep); /** * @brief Check for different Event when an interrupt occurs. * @return 0 on success. * @retval -1 ltcusb_event_fifo_read failed. * @retval -2 event_buffer_size_clear failed. * @retval -3 Disconnect_Event failed. * @retval -4 interrupt_out_ep_10 failed. * @retval -5 interrupt_in_ep_11 failed. * @retval -6 bulk_out_ep_2 failed. * @retval -7 bulk_in_ep_3 failed. * @retval -8 Suspend_Resume Mode event failed. * @retval -9 event_buffer_size_clear failed. * @retval -10 Initialization_on_USB_Reset failed. * @retval -11 Initialization_onConnect_Done failed. */ extern int bulk_interrupt_transfer(); /** * @brief This will complete interrupt out transfer on EP 10. * @return 0 on success. * @retval -1 DEPENDXFER command for Interrupt OUT EP 10 failed. * @retval -2 ltcusb_trb_write for Interrupt OUT EP 10 failed. * @retval -3 DEPSTRTXFER command for Interrupt OUT EP 10 failed. * @retval -4 XferComplete event for Interrupt OUT EP 10 failed. * @retval -5 TRB_control_setup for Interrupt OUT EP 10 failed. */ extern int interrupt_out_ep_10(); /** * @brief This will complete interrupt in transfer on EP 10. * @return 0 on success. * @retval -1 DEPENDXFER command for Interrupt IN EP 11 failed. * @retval -2 ltcusb_trb_write for Interrupt IN EP 11 failed. * @retval -3 DEPSTRTXFER command for Interrupt IN EP 11 failed. * @retval -4 XferComplete event for Interrupt IN EP 11 failed. * @retval -5 TRB_control_setup for Interrupt IN EP 11 failed. */ extern int interrupt_in_ep_11(); /** * @brief This will complete bulk out transfer on EP 2. * @return 0 on success. * @retval -1 DEPENDXFER command for BULK OUT EP 2 failed. * @retval -2 ltcusb_trb_write for BULK OUT EP 2 failed. * @retval -3 DEPSTRTXFER command for BULK OUT EP 2 failed. * @retval -4 XferComplete event for BULK OUT EP 2 failed. * @retval -5 TRB_control_setup for BULK OUT EP 2 failed. */ extern int bulk_out_ep_2(); /** * @brief This will complete bulk in transfer on EP 3. * @return 0 on success. * @retval -1 DEPENDXFER command for BULK IN EP 3 failed. * @retval -2 ltcusb_trb_write for BULK IN EP 3 failed. * @retval -3 DEPSTRTXFER command for BULK IN EP 3 failed. * @retval -4 XferComplete event for BULK IN EP 3 failed. * @retval -5 TRB_control_setup for BULK IN EP 3 failed. */ extern int bulk_in_ep_3(); #endif /* INCLUDE_EVENT_BUFFER_H_ */