#ifndef __USB_OTG_FS_H__ #define __USB_OTG_FS_H__ #include "usb_otg.h" class USB_OTG_FS : public USB_OTG { public: static const int ENDPOINTS = 3; static const int EP0_PACKET_SIZE = 64; static const int HOST_CHANNELS = 8; protected: bool is_device; ep_state_t ep0_state; Uint8 *ep0_rw_buf; Uint16 ep0_rw_size; CallbackFunctor *ep0_callback; bool address_changed; Uint16 ep_rx_size_check(const Uint8 &out_index) const; Uint16 ep_rx_size_check(const Uint8 &out_index, const Uint16 &max_size) const; Uint16 ep_tx_size_check(const Uint8 &in_index) const; Uint16 ep_tx_size_check(const Uint8 &in_index, const Uint16 &max_size) const; void handle_ep0(); void suspend(); void resume(); void reset(); virtual int interfaces() const = 0; virtual bool descriptor( const Uint16 wValue, const Uint16 wIndex, unsigned char **buf, int *size) = 0; virtual bool setup( const int &configuration) = 0; void init_core(); public: USB_OTG_FS( bool _is_device = true); virtual ~USB_OTG_FS(); void ep0_tx(const void *buf, const Uint16 &size); void ep0_tx(const void *buf, const Uint16 &size, CallbackFunctor &callback); void ep0_rx(void *buf, const Uint16 &size); void ep0_rx(void *buf, const Uint16 &size, CallbackFunctor &callback); USB::ep_state_t get_ep_state(const Uint8 &ep_index) const; USB::ep_state_t set_ep_state(const Uint8 &ep_index, const ep_state_t &state); virtual void init(); virtual Uint16 read(const Uint8 &out_index, void *buf, const Uint16 &size); virtual Uint16 read_skip(const Uint8 &out_index, const Uint16 &size); virtual Uint16 write(const Uint8 &in_index, const void *buf, const Uint16 &size); virtual Uint16 write_fill(const Uint8 &in_index, const Uint8 c, const Uint16 &size); void handle_isr(); #if 0 public: enum dma_protocol_t { TRANSPARENT = 0, RNDIS = 1, LINUX_CDC = 2, GENERIC_RNDIS = 3, }; enum dma_queue_t { QUEUE_RX_READY_OR_FREE = 0, QUEUE_TX1_SUBMIT = 16, QUEUE_TX2_SUBMIT = 18, QUEUE_TX3_SUBMIT = 20, QUEUE_TX4_SUBMIT = 22, QUEUE_TX_COMPLETE = 24, QUEUE_RX_COMPLETE = 26, QUEUE_UNASSIGNED = 28, }; struct DMA_HostDescriptor { template static Uint32 mask(){ Uint32 res(0); for(int i(length); i > 0; i--){ res <<= 1; res |= 1; } res <<= shift; return res; } #define access_atr(fname) \ Uint32 fname() const; \ void fname(const Uint32 &v); struct word0_t { Uint32 word; access_atr(descriptor_type); access_atr(protocol_specific_valid_word_count); access_atr(packet_length); } word0; struct word1_t { Uint32 word; access_atr(src_port); access_atr(src_channel); access_atr(src_subchannel); access_atr(dst); } word1; struct word2_t { Uint32 word; access_atr(error); access_atr(type); access_atr(is_zero_length); access_atr(protocol_specific); access_atr(return_policy); access_atr(is_on_chip); access_atr(return_queue_mgr); access_atr(return_queue); } word2; Uint32 word3_buf_length; Uint32 word4_buf_address; Uint32 word5_next_ptr; Uint32 word6_org_buf_length; Uint32 word7_org_buf_address; #undef access_atr void init_common(const Uint16 &return_queue, Uint32 *buf, const Uint32 &buf_length); void init_tx_packet( const Uint32 &packet_length, const Uint8 &endpoint, const Uint16 &return_queue, Uint32 *buf, const Uint32 &buf_length); void init_tx_packet( const Uint32 &packet_length, const Uint8 &endpoint, const Uint16 &return_queue); void init_tx_buffer( DMA_HostDescriptor &previous, const Uint16 &return_queue, Uint32 *buf, const Uint32 &buf_length); void init_tx_buffer( DMA_HostDescriptor &previous, const Uint16 &return_queue); void init_rx_buffer( const Uint16 &return_queue, Uint32 *buf, const Uint32 &buf_length); void init_rx_buffer( const Uint16 &return_queue); }; protected: void init_dma( const Uint16 rx_submit_queues[ENDPOINTS], const Uint16 rx_complete_queues[ENDPOINTS]); void init_dma(); void set_dma_protocol( const Uint8 &ep_index, const dma_protocol_t &protocol, const Uint32 &generic_RNDIS_packet_size = 0); void dma_push_queue(const Uint16 &queueNum, const void *descriptor); void *dma_pop_queue(const Uint16 &queueNum); void dma_enable(const Uint8 &ep_index); void dma_disable(const Uint8 &ep_index); #endif virtual void handle_isr_dma(); }; #endif /*__USB_OTG_FS_H__ */