Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

usb_drv.h

Go to the documentation of this file.
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 #ifndef _USB_DRV_H_ 00016 #define _USB_DRV_H_ 00017 00018 //_____ I N C L U D E S ____________________________________________________ 00019 #include "conf\conf_usb.h" 00020 00021 typedef enum endpoint_parameter{ep_num, ep_type, ep_direction, ep_size, ep_bank, nyet_status} t_endpoint_parameter; 00022 00023 #ifndef NO_SUPPORT_USB_PING_PONG 00024 extern bdata bit rx_bank; 00025 #endif 00026 00027 //_____ M A C R O S ________________________________________________________ 00028 00029 #define EP_CONTROL 0 00030 #define EP_1 1 00031 #define EP_2 2 00032 #define EP_3 3 00033 #define EP_4 4 00034 #define EP_5 5 00035 #define EP_6 6 00036 #define EP_7 7 00037 00038 #define MSK_EP_DIR 0x7F 00039 00042 #define TYPE_CONTROL 0 00043 #define TYPE_ISOCHRONOUS 1 00044 #define TYPE_BULK 2 00045 #define TYPE_INTERRUPT 3 00046 00047 #define DIRECTION_OUT 0 00048 #define DIRECTION_IN 1 00049 00050 #define SIZE_8 0 00051 #define SIZE_16 1 00052 #define SIZE_32 2 00053 #define SIZE_64 3 00054 #define SIZE_128 4 00055 #define SIZE_256 5 00056 #define SIZE_512 6 00057 #define SIZE_1024 7 00058 00059 #define ONE_BANK 0 00060 #define TWO_BANKS 1 00061 00062 #define NYET_ENABLED 0 00063 #define NYET_DISABLED 1 00064 00065 #define Usb_build_ep_config0(type, dir, nyet) ((type<<6) | (nyet<<1) | (dir)) 00066 #define Usb_build_ep_config1(size, bank ) ((size<<4) | (bank<<2) ) 00067 #define usb_configure_endpoint(num, type, dir, size, bank, nyet) \ 00068 ( Usb_select_endpoint(num), \ 00069 usb_config_ep(Usb_build_ep_config0(type, dir, nyet),\ 00070 Usb_build_ep_config1(size, bank) )) 00071 00072 00075 00076 #define Usb_enable() (USBCON |= MSK_USBE) 00077 #define Usb_disable() (USBCON &= ~MSK_USBE) 00078 #define Usb_select_device() // compatibility 00079 #define Usb_select_host() // compatibility 00080 #define Usb_freeze_clock() (USBCON |= MSK_SUSPCLK) 00081 #define Usb_unfreeze_clock() (USBCON &= ~MSK_SUSPCLK) 00082 #define Usb_enable_id_interrupt() // compatibility 00083 #define Usb_disable_id_interrupt() // compatibility 00084 #define Usb_enable_vbus_interrupt() // compatibility 00085 #define Usb_disable_vbus_interrupt() // compatibility 00086 #define Is_usb_enabled() (USBCON & MSK_USBE == MSK_USBE) 00087 #define Is_usb_host_enabled() (FALSE)// compatibility 00088 #define Is_usb_clock_freezed() (USBCON & MSK_SUSPCLK == MSK_SUSPCLK) 00089 00090 #define Is_usb_vbus_high() (TRUE)// compatibility 00091 #define Is_usb_high_speed() (FALSE)// compatibility 00092 #define Is_usb_id_device() (TRUE)// compatibility 00093 00094 #define Usb_ack_id_transition() // compatibility 00095 #define Usb_ack_vbus_transition() // compatibility 00096 #define Is_usb_id_transition() (FALSE) // compatibility 00097 #define Is_usb_vbus_transition() (FALSE) // compatibility 00098 00099 #define Usb_enter_dpram_mode() // compatibility 00100 #define Usb_exit_dpram_mode() // compatibility 00101 #define Usb_set_dpram_address(addr) // compatibility 00102 00103 #define Usb_enable_vbus() // compatibility 00104 #define Usb_disable_vbus() // compatibility 00105 #define Usb_device_initiate_hnp() // compatibility 00106 #define Usb_host_accept_hnp() // compatibility 00107 #define Usb_host_reject_hnp() // compatibility 00108 #define Usb_device_initiate_srp() // compatibility 00109 #define Usb_select_vbus_srp_method() // compatibility 00110 #define Usb_select_data_srp_method() // compatibility 00111 #define Usb_enable_vbus_hw_control() // compatibility 00112 #define Usb_disable_vbus_hw_control() // compatibility 00113 #define Is_usb_vbus_enabled() (TRUE) // compatibility 00114 #define Is_usb_hnp() (FALSE) // compatibility 00115 #define Is_usb_device_srp() (FALSE) // compatibility 00116 00117 #define Usb_enable_suspend_time_out_interrupt() // compatibility 00118 #define Usb_enable_hnp_error_interrupt() // compatibility 00119 #define Usb_enable_role_exchange_interrupt() // compatibility 00120 #define Usb_enable_bconnection_error_interrupt() // compatibility 00121 #define Usb_enable_vbus_error_interrupt() // compatibility 00122 #define Usb_enable_srp_interrupt() // compatibility 00123 #define Usb_disable_suspend_time_out_interrupt() // compatibility 00124 #define Usb_disable_hnp_error_interrupt() // compatibility 00125 #define Usb_disable_role_exchange_interrupt() // compatibility 00126 #define Usb_disable_bconnection_error_interrupt() // compatibility 00127 #define Usb_disable_vbus_error_interrupt() // compatibility 00128 #define Usb_disable_srp_interrupt() // compatibility 00129 00130 #define Usb_ack_suspend_time_out_interrupt() // compatibility 00131 #define Usb_ack_hnp_error_interrupt() // compatibility 00132 #define Usb_ack_role_exchange_interrupt() // compatibility 00133 #define Usb_ack_bconnection_error_interrupt() // compatibility 00134 #define Usb_ack_vbus_error_interrupt() // compatibility 00135 #define Usb_ack_srp_interrupt() // compatibility 00136 #define Is_usb_suspend_time_out_interrupt() (FALSE) // compatibility 00137 #define Is_usb_hnp_error_interrupt() (FALSE) // compatibility 00138 #define Is_usb_role_exchange_interrupt() (FALSE) // compatibility 00139 #define Is_usb_bconnection_error_interrupt() (FALSE) // compatibility 00140 #define Is_usb_vbus_error_interrupt() (FALSE) // compatibility 00141 #define Is_usb_srp_interrupt() (FALSE) // compatibility 00142 00143 00147 00148 #define Usb_initiate_remote_wake_up() (USBCON |= MSK_SDRMWKUP) 00149 #define Usb_detach() (USBCON |= MSK_DETACH) 00150 #define Usb_attach() (USBCON &= ~MSK_DETACH) 00151 #define Is_usb_pending_remote_wake_up() (USBCON & MSK_UPRSM == MSK_UPRSM) 00152 #define Is_usb_detached() (USBCON & MSK_DETACH == MSK_DETACH) 00153 00154 #define Usb_ack_remote_wake_up_start() (USBCON &= ~MSK_SDRMWUP) 00155 #define Usb_ack_resume() (USBINT &= ~MSK_WUPCPU) 00156 #define Usb_ack_wake_up() (USBINT &= ~MSK_WUPCPU) 00157 #define Usb_ack_reset() (USBINT &= ~MSK_EORINT) 00158 #define Usb_ack_sof() (USBINT &= ~MSK_SOFINT) 00159 #define Usb_ack_micro_sof() // compatibility 00160 #define Usb_ack_suspend() (USBINT &= ~MSK_SPINT) 00161 #define Is_usb_remote_wake_up_start() (USBCON & MSK_SDRMWUP) 00162 #define Is_usb_resume() (USBINT & MSK_WUPCPU) 00163 #define Is_usb_wake_up() (USBINT & MSK_WUPCPU) 00164 #define Is_usb_reset() (USBINT & MSK_EORINT) 00165 #define Is_usb_sof() (USBINT & MSK_SOFINT) 00166 #define Is_usb_micro_sof() (FALSE) // compatibiliy 00167 #define Is_usb_suspend() (USBINT & MSK_SPINT == MSK_SPINT) 00168 00169 #define Usb_enable_remote_wake_up_interrupt() // compatibility 00170 #define Usb_enable_resume_interrupt() (USBIEN |= MSK_EWUPCPU) 00171 #define Usb_enable_wake_up_interrupt() (USBIEN |= MSK_EWUPCPU) 00172 #define Usb_enable_reset_interrupt() (USBIEN |= MSK_EEORINT) 00173 #define Usb_enable_sof_interrupt() (USBIEN |= MSK_ESOFINT) 00174 #define Usb_enable_micro_sof_interrupt() // compatibility 00175 #define Usb_enable_suspend_interrupt() (USBIEN |= MSK_ESPINT) 00176 #define Usb_disable_remote_wake_up_interrupt() // compatibility 00177 #define Usb_disable_resume_interrupt() (USBIEN &= ~MSK_EWUPCPU) 00178 #define Usb_disable_wake_up_interrupt() (USBIEN &= ~MSK_EWUPCPU) 00179 #define Usb_disable_reset_interrupt() (USBIEN &= ~MSK_EEORINT) 00180 #define Usb_disable_sof_interrupt() (USBIEN &= ~MSK_ESOFINT) 00181 #define Usb_disable_micro_sof_interrupt() // compatibility 00182 #define Usb_disable_suspend_interrupt() (USBIEN &= ~MSK_ESPINT) 00183 00184 #define Usb_enable_address() (USBADDR |= MSK_FEN) 00185 #define Usb_disable_address() (USBADDR &= ~MSK_FEN) 00186 #define Usb_configure_address(addr) (Usb_disable_address(), USBADDR = (U8)addr) 00187 00188 #define Usb_frame_number() ((U16)((((U16)UFNUMH & 0x07) << 8) | ((U16)UDNUML))) 00189 #define Usb_micro_frame_number() (0) // compatibility 00190 #define Is_usb_frame_number_crc_error() (UFNUMH & MSK_CRCERR == MSK_CRCERR) 00191 00192 #define Usb_enter_test_packet_mode() // compatibility 00193 #define Usb_enter_test_k_mode() // compatibility 00194 #define Usb_enter_test_j_mode() // compatibility 00195 #define Usb_force_normal_speed() // compatibility 00196 #define Usb_force_full_speed() // compatibility 00197 #define Usb_force_high_speed() // compatibility 00198 #define Usb_force_full_speed_utmi() // compatibility 00199 #define Usb_exit_test_packet_mode() // compatibility 00200 #define Usb_exit_test_k_mode() // compatibility 00201 #define Usb_exit_test_j_mode() // compatibility 00202 00203 #define Usb_set_loopback_mode() // compatibility 00204 00208 00209 #define Usb_select_endpoint(ep) (UEPNUM = (U8)ep) 00210 #define Usb_select_endpoint_dfc(ep) (UEPNUM = (U8)ep) // compatibility 00211 00212 #define Usb_reset_endpoint(ep) (UEPRST = 1 << (U8)ep, UEPRST = 0) 00213 00214 #define Usb_enable_endpoint() (UEPCONX |= MSK_EPEN) 00215 #define Usb_enable_stall_handshake() (UEPSTAX |= MSK_STALLRQ) 00216 #define Usb_reset_data_toggle() // compatibility 00217 #define Usb_select_epnum_for_dfc() // compatibility 00218 #define Usb_enable_dfc() // compatibility 00219 #define Usb_disable_endpoint() (UEPCONX &= ~MSK_EPEN) 00220 #define Usb_disable_stall_handshake() (UEPSTAX &= ~MSK_STALLRQ) 00221 #define Usb_select_epnum_for_cpu() // compatibility 00222 #define Usb_disable_dfc() // compatibility 00223 #define Is_usb_endpoint_enabled() (UEPCONX & MSK_EPEN) 00224 #define Is_usb_endpoint_stall_requested() (UEPSTAX & MSK_STALLRQ) 00225 00226 #define Usb_configure_endpoint_type(type) (UEPCONX = (UEPCONX & ~MSK_EPTYPE) | ((U8)type)) 00227 #define Usb_enable_iso_autoswitch() // compatibility 00228 #define Usb_enable_autoswitch() // compatibility 00229 #define Usb_enable_nyet() // compatibility 00230 #define Usb_disable_iso_autoswitch() // compatibility 00231 #define Usb_disable_autoswitch() // compatibility 00232 #define Usb_disable_nyet() // compatibility 00233 #define Usb_configure_endpoint_direction(dir) (UEPCONX = (UEPCONX & ~MSK_EPDIR) | ((U8)dir << 2)) 00234 00235 #define Usb_configure_endpoint_size(size) // compatibility 00236 #define Usb_configure_endpoint_bank(bank) // compatibility 00237 #define Usb_allocate_memory() // compatibility 00238 #define Usb_unallocate_memory() // compatibility 00239 00240 #define Usb_ack_overflow_interrupt() // compatibility 00241 #define Usb_ack_underflow_interrupt() // compatibility 00242 #define Usb_ack_zlp() // compatibility 00243 #define Usb_data_toggle() // compatibility 00244 #define Usb_nb_busy_bank() (0xFF) 00245 #define Is_usb_one_bank_busy() (FALSE) 00246 #define Is_endpoint_configured() (UEPCONX & MSK_EPEN == MSK_EPEN) 00247 #define Is_usb_overflow() (FALSE) 00248 #define Is_usb_underflow() (FALSE) 00249 #define Is_usb_zlp() (FALSE) 00250 00251 #define Usb_control_direction() (UEPCONX & MSK_EPDIR) 00252 #define Usb_current_bank() (0xFF) 00253 00254 #define Usb_ack_fifocon() // compatibility 00255 #define Usb_ack_nak_in() // compatibility 00256 #define Usb_ack_nak_out() // compatibility 00257 #define Usb_ack_receive_setup() (UEPSTAX &= ~MSK_RXSETUP) 00258 #define Usb_ack_receive_out() (UEPSTAX &= ~MSK_RXOUT) 00259 #define Usb_ack_stalled() (UEPSTAX &= ~MSK_STALLED) 00260 #define Usb_ack_in_ready() (UEPSTAX &= ~MSK_TXCMPL) 00261 #define Usb_kill_last_in_bank() // compatibility 00262 #define Is_usb_read_enabled() (TRUE)// compatibility 00263 #define Is_usb_write_enabled() (TRUE)// compatibility 00264 #define Is_usb_read_control_enabled() (UEPSTAX & MSK_TXCMPL) // compatibility 00265 #define Is_usb_receive_setup() (UEPSTAX & MSK_RXSETUP) 00266 #define Is_usb_receive_out() (UEPSTAX & MSK_RXOUTB0B1) 00267 #ifdef NO_SUPPORT_USB_PING_PONG 00268 #define Usb_ack_receive_out_ms() Usb_ack_receive_out() 00269 #define Is_usb_receive_out_ms() Is_usb_receive_out() 00270 #else 00271 #define Usb_ack_receive_out_ms() {if(rx_bank){UEPSTAX&=~MSK_RXOUTB1;}else{UEPSTAX&=(~MSK_RXOUTB0);}rx_bank=~rx_bank;} 00272 #define Is_usb_receive_out_ms() Is_usb_receive_out() 00273 #endif 00274 #ifdef NO_SUPPORT_USB_PING_PONG 00275 #define Usb_ack_receive_out_hid() Usb_ack_receive_out() 00276 #define Is_usb_receive_out_hid() Is_usb_receive_out() 00277 #else 00278 #define Usb_ack_receive_out_hid() {if(rx_bank){UEPSTAX&=~MSK_RXOUTB1;}else{UEPSTAX&=(~MSK_RXOUTB0);}rx_bank=~rx_bank;} 00279 #define Is_usb_receive_out_hid() Is_usb_receive_out() 00280 #endif 00281 #define Is_usb_in_ready() (UEPSTAX & MSK_TXCMPL) 00282 #define Usb_send_in() UEPSTAX |= MSK_TXRDY; while(!Is_usb_in_ready());Usb_ack_in_ready() 00283 #define Usb_send_control_in() (UEPSTAX |= MSK_TXRDY) 00284 #define Usb_free_out_bank() (UEPSTAX |= MSK_RXOUT) 00285 #define Usb_ack_control_out() (UEPSTAX |= MSK_RXOUT) 00286 00287 #define Usb_set_DIR() (UEPSTAX |= MSK_DIR) 00288 00289 00290 #define Usb_enable_flow_error_interrupt() // compatibility 00291 #define Usb_enable_nak_in_interrupt() // compatibility 00292 #define Usb_enable_nak_out_interrupt() // compatibility 00293 #define Usb_enable_receive_setup_interrupt() // compatibility 00294 #define Usb_enable_receive_out_interrupt() // compatibility 00295 #define Usb_enable_stalled_interrupt() // compatibility 00296 #define Usb_enable_in_ready_interrupt() // compatibility 00297 #define Usb_disable_flow_error_interrupt() // compatibility 00298 #define Usb_disable_nak_in_interrupt() // compatibility 00299 #define Usb_disable_nak_out_interrupt() // compatibility 00300 #define Usb_disable_receive_setup_interrupt() // compatibility 00301 #define Usb_disable_receive_out_interrupt() // compatibility 00302 #define Usb_disable_stalled_interrupt() // compatibility 00303 #define Usb_disable_in_ready_interrupt() // compatibility 00304 00305 #define Usb_read_byte() (UEPDATX) 00306 #define Usb_write_byte(byte) (UEPDATX = (U8)byte) 00307 00308 #define Usb_byte_counter() ((((U16)UBYCTHX) << 8) | (UBYCTLX)) 00309 #define Usb_byte_counter_8() ((U8)UBYCTLX) 00310 00311 #define Usb_interrupt_flags() (UEPINT != 0x00) 00312 #define Is_usb_endpoint_event() (Usb_interrupt_flags()) 00313 00314 // ADVANCED MACROS 00315 00316 #define Usb_select_ep_for_cpu(ep) // compatibility 00317 #define Usb_select_ep_for_dfc(ep) // compatibility 00318 00319 #define Usb_set_cfg0(cfg0) (cfg0 = cfg0)//(UECFG0X = cfg0) 00320 #define Usb_set_cfg1(cfg1) (cfg1 = cfg1)//(UECFG1X = (UECFG1X & MSK_ALLOC) | cfg1) 00321 00322 00329 00330 #define wSWAP(x) \ 00331 ( (((x)>>8)&0x00FF) \ 00332 | (((x)<<8)&0xFF00) \ 00333 ) 00334 00335 00342 #if 0 00343 #define dwSWAP(x) \ 00344 ( (((x)>>24)&0x000000FF) \ 00345 | (((x)>> 8)&0x0000FF00) \ 00346 | (((x)<<24)&0xFF000000) \ 00347 | (((x)<< 8)&0x00FF0000) \ 00348 ) 00349 #endif 00350 00351 #define PLL_3MHz 0xF0 00352 #define PLL_4MHz 0xC0 00353 #define PLL_6MHz 0x70 00354 #define PLL_8MHz 0x50 00355 #define PLL_12MHz 0x30 00356 #define PLL_16MHz 0x20 00357 #define PLL_18MHz 0x72 00358 #define PLL_20MHz 0xB4 00359 #define PLL_24MHz 0x10 00360 #define PLL_32MHz 0x21 00361 #define PLL_40MHz 0xB9 00362 00363 #define Pll_stop() (PLLCON &= ~MSK_PLLEN) 00364 #define Pll_set_div(n) (PLLDIV = n) 00365 #define Pll_enable() (PLLCON |= MSK_PLLEN) 00366 00367 00368 00369 00370 //_____ D E C L A R A T I O N ______________________________________________ 00371 00372 U8 usb_config_ep (U8, U8); 00373 U8 usb_select_enpoint_interrupt (void); 00374 U16 usb_get_nb_byte_epw (void); 00375 U8 usb_send_packet (U8 , U8*, U8); 00376 U8 usb_read_packet (U8 , U8*, U8); 00377 void usb_halt_endpoint (U8); 00378 void usb_reset_endpoint (U8); 00379 U8 usb_init_device (void); 00380 00381 void usb_generate_clock (void); 00382 00383 #endif // _USB_DRV_H_ 00384

Generated on Mon Apr 10 17:23:30 2006 for Atmel by doxygen 1.3.7