+/rtos
git clone https://git.julia.blue/+/rtos
326af29
master
1//***************************************************************************** 2// 3// usblibpriv.h - Private header file used to share internal variables and 4// function prototypes between the various modules in the USB 5// library. This header MUST NOT be used by application code. 6// 7// Copyright (c) 2008-2017 Texas Instruments Incorporated. All rights reserved. 8// Software License Agreement 9// 10// Texas Instruments (TI) is supplying this software for use solely and 11// exclusively on TI's microcontroller products. The software is owned by 12// TI and/or its suppliers, and is protected under applicable copyright 13// laws. You may not combine this software with "viral" open-source 14// software in order to form a larger program. 15// 16// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. 17// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT 18// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY 20// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 21// DAMAGES, FOR ANY REASON WHATSOEVER. 22// 23// This is part of revision 2.1.4.178 of the Tiva USB Library. 24// 25//***************************************************************************** 26 27#ifndef __USBLIBPRIV_H__ 28#define __USBLIBPRIV_H__ 29 30#include "usblib/usblib.h" 31#include <stdint.h> 32 33//***************************************************************************** 34// 35// If building with a C++ compiler, make all of the definitions in this header 36// have a C binding. 37// 38//***************************************************************************** 39#ifdef __cplusplus 40extern "C" { 41#endif 42 43//***************************************************************************** 44// 45//! \addtogroup usblib_dma_api 46//! @{ 47// 48//***************************************************************************** 49 50//***************************************************************************** 51// 52// Internal interrupt handlers called from the main vectors in device and 53// host mode. 54// 55//***************************************************************************** 56extern void USBDeviceIntHandlerInternal (uint32_t ui32Index , 57uint32_t ui32Status ); 58extern void USBHostIntHandlerInternal (uint32_t ui32Index ,uint32_t ui32Status ); 59 60//***************************************************************************** 61// 62// The maximum number of tick handlers that can be registered in a system. 63// 64//***************************************************************************** 65#define MAX_USB_TICK_HANDLERS 6 66 67//***************************************************************************** 68// 69// This value defines the number of SOF ticks that must pass before a call 70// is made to InternalUSBStartOfFrameTick. The value 5 ensures that the 71// function is called every 5 milliseconds assuming that SOF interrupts are 72// enabled and SOF is present. 73// 74//***************************************************************************** 75#define USB_SOF_TICK_DIVIDE 5 76 77//***************************************************************************** 78// 79// Tick handler function pointer type. 80// 81//***************************************************************************** 82typedef void (* tUSBTickHandler )(void * pvInstance ,uint32_t ui32TicksmS ); 83 84//***************************************************************************** 85// 86// Internal functions use to initialize the tick handler and register tick 87// callbacks. 88// 89//***************************************************************************** 90extern void InternalUSBTickInit (void ); 91extern void InternalUSBTickReset (void ); 92extern int32_t InternalUSBRegisterTickHandler (tUSBTickHandler pfnHandler , 93void * pvInstance ); 94extern void InternalUSBStartOfFrameTick (uint32_t ui32TicksmS ); 95extern void InternalUSBHCDSendEvent (uint32_t ui32Index ,tEventInfo * psEvent , 96uint32_t ui32EvFlag ); 97 98//***************************************************************************** 99// 100// g_ui32CurrentUSBTick holds the elapsed time in milliseconds since the 101// tick module was first initialized based on calls to the function 102// InternalUSBStartOfFrameTick. The granularity is USB_SOF_TICK_DIVIDE 103// milliseconds. 104// 105//***************************************************************************** 106extern uint32_t g_ui32CurrentUSBTick ; 107 108//***************************************************************************** 109// 110// g_ui32USBSOFCount is a global counter for Start of Frame interrupts. It is 111// incremented by the low level device- or host-mode interrupt handlers. 112// 113//***************************************************************************** 114extern uint32_t g_ui32USBSOFCount ; 115 116//***************************************************************************** 117// 118// InternalUSBGetTime is a macro which will return the system time in 119// milliseconds as calculated based on calls to the function 120// InternalUSBStartOfFrameTick. The granularity is USB_SOF_TICK_DIVIDE 121// milliseconds. 122// 123// Currently, this merely returns the value of a global variable. 124// 125//***************************************************************************** 126#define InternalUSBGetTime () g_ui32CurrentUSBTick 127 128//***************************************************************************** 129// 130// Macros to convert between USB controller base address and an index. These 131// are currently trivial but are included to allow for the possibility of 132// supporting more than one controller in the future. 133// 134//***************************************************************************** 135#define USBBaseToIndex (BaseAddr ) (0) 136#define USBIndexToBase (Index ) (USB0_BASE) 137 138// 139// Maximum number of channels for Type 0 USB controllers. 140// 141#define USB_MAX_DMA_CHANNELS_0 6 142 143// 144// Maximum number of channels for all other USB controllers. 145// 146#define USB_MAX_DMA_CHANNELS 8 147 148//***************************************************************************** 149// 150// Values returned by the USBLibDMAChannelStatus() function. 151// 152//***************************************************************************** 153#define USBLIBSTATUS_DMA_IDLE 0x00000000 154#define USBLIBSTATUS_DMA_COMPLETE 0x00000001 155#define USBLIBSTATUS_DMA_ERROR 0x00000002 156#define USBLIBSTATUS_DMA_PENDING 0x00000004 157 158//***************************************************************************** 159// 160// DMA endpoint types used with the USBLibDMAChannelAllocate() function. 161// 162//***************************************************************************** 163#define USB_DMA_EP_RX 0x00000080 164#define USB_DMA_EP_TX 0x00000000 165#define USB_DMA_EP_HOST 0x00000040 166#define USB_DMA_EP_DEVICE 0x00000000 167#define USB_DMA_EP_TYPE_CTRL 0x00000000 168#define USB_DMA_EP_TYPE_ISOC 0x00000001 169#define USB_DMA_EP_TYPE_BULK 0x00000002 170#define USB_DMA_EP_TYPE_INT 0x00000003 171#define USB_DMA_EP_TYPE_M 0x00000003 172 173//***************************************************************************** 174// 175// This is the internal instance data for the DMA functions and should not 176// be modified outside the usbdma.c file. 177// 178//***************************************************************************** 179struct tUSBDMAInstance { 180uint32_t ui32Base ; 181 182uint32_t ui32IntNum ; 183 184uint32_t pui32Config [USB_MAX_DMA_CHANNELS ]; 185 186uint32_t pui32MaxPacketSize [USB_MAX_DMA_CHANNELS ]; 187 188uint32_t * ppui32Data [USB_MAX_DMA_CHANNELS ]; 189 190uint32_t pui32Count [USB_MAX_DMA_CHANNELS ]; 191 192uint8_t pui8Endpoint [USB_MAX_DMA_CHANNELS ]; 193 194uint32_t pui32EPDMAMode0 [USB_MAX_DMA_CHANNELS ]; 195 196uint32_t pui32EPDMAMode1 [USB_MAX_DMA_CHANNELS ]; 197 198uint32_t ui32Pending ; 199 200uint32_t ui32Complete ; 201 202void (* pfnArbSizeSet )(tUSBDMAInstance * psUSBDMAInst ,uint32_t ui32Channel , 203uint32_t ui32ArbSize ); 204uint32_t (* pfnChannelAllocate )(tUSBDMAInstance * psUSBDMAInst , 205uint8_t ui8Endpoint , 206uint32_t ui32MaxPacketSize , 207uint32_t ui32Config ); 208void (* pfnChannelEnable )(tUSBDMAInstance * psUSBDMAInst , 209uint32_t ui32Channel ); 210void (* pfnChannelDisable )(tUSBDMAInstance * psUSBDMAInst , 211uint32_t ui32Channel ); 212void (* pfnChannelRelease )(tUSBDMAInstance * psUSBDMAInst , 213uint8_t ui8Endpoint ); 214uint32_t (* pfnChannelStatus )(tUSBDMAInstance * psUSBDMAInst , 215uint32_t ui32Channel ); 216void (* pfnChannelIntDisable )(tUSBDMAInstance * psUSBDMAInst , 217uint32_t ui32Channel ); 218void (* pfnChannelIntEnable )(tUSBDMAInstance * psUSBDMAInst , 219uint32_t ui32Channel ); 220void (* pfnIntHandler )(tUSBDMAInstance * psUSBDMAInst ,uint32_t ui32Status ); 221uint32_t (* pfnIntStatus )(tUSBDMAInstance * psUSBDMAInst ); 222void (* pfnIntStatusClear )(tUSBDMAInstance * psUSBDMAInst , 223uint32_t ui32Status ); 224uint32_t (* pfnStatus )(tUSBDMAInstance * psUSBDMAInst ); 225uint32_t (* pfnTransfer )(tUSBDMAInstance * psUSBDMAInst ,uint32_t ui32Channel , 226void * pvBuffer ,uint32_t ui32Size ); 227void (* pfnUnitSizeSet )(tUSBDMAInstance * psUSBDMAInst ,uint32_t ui32Channel , 228uint32_t ui32BitSize ); 229}; 230 231//***************************************************************************** 232// 233// These are the USB libraries DMA functions. 234// 235//***************************************************************************** 236extern tUSBDMAInstance * USBLibDMAInit (uint32_t ui32Index ); 237extern void * USBLibDMAAddrGet (tUSBDMAInstance * psUSBDMAInst , 238uint32_t ui32Channel ); 239extern uint32_t USBLibDMASizeGet (tUSBDMAInstance * psUSBDMAInst , 240uint32_t ui32Channel ); 241 242//***************************************************************************** 243// 244//! This function returns the current DMA status for a given DMA channel. 245//! 246//! \param psUSBDMAInst is the DMA structure pointer for this instance. 247//! \param ui32Channel is the DMA channel number used to retrieve the DMA 248//! status. 249//! 250//! This function returns the current status of a DMA transfer on a given 251//! DMA channel. The DMA channel is specified by the \e ui32Channel parameter. 252//! 253//! \return This function returns one of the \b USBLIBSTATUS_DMA_* values. 254// 255//***************************************************************************** 256#define USBLibDMAChannelStatus (psUSBDMAInst ,ui32Channel ) \ 257 psUSBDMAInst->pfnChannelStatus(psUSBDMAInst, ui32Channel) 258 259//***************************************************************************** 260// 261//! This function is used to return any global status information for USB DMA. 262//! 263//! \param psUSBDMAInst is a generic instance pointer that can be used to 264//! distinguish between different hardware instances. 265//! 266//! This function performs returns the global status for the USB DMA 267//! interface. 268//! 269//! \return Always returns 0. 270// 271//***************************************************************************** 272#define USBLibDMAStatus (psUSBDMAInst ) psUSBDMAInst->pfnStatus(psUSBDMAInst) 273 274//***************************************************************************** 275// 276//! This function returns the current DMA interrupt status. 277//! 278//! \param psUSBDMAInst is the DMA structure pointer for this instance. 279//! 280//! This function returns the interrupt status for all DMA channels. The value 281//! returned is a per channel interrupt mapping with the DMA channels mapped 282//! into bits 0-31 by channel number with channel 1 starting at bit 0. 283//! 284//! \note This function does not return an endpoint interrupt status, but the 285//! interrupt status for the DMA interface used with the USB controller. 286//! 287//! \return This function returns the pending DMA interrupts. 288// 289//***************************************************************************** 290#define USBLibDMAIntStatus (psUSBDMAInst ) \ 291 psUSBDMAInst->pfnIntStatus(psUSBDMAInst) 292 293//***************************************************************************** 294// 295//! This function clears the requested DMA interrupt status. 296//! 297//! \param psUSBDMAInst is the DMA structure pointer for this instance. 298//! \param ui32Status contains the interrupts to clear. 299//! 300//! This function clears the current DMA interrupt status for the 301//! controller specified by the \e ui32Instance parameter. The \e ui32Status 302//! value has the same format as the value returned from the 303//! USBLibDMAIntStatus() function which is a per channel interrupt mapping. 304//! The DMA channels are mapped into bits 0-31 by channel number with channel 1 305//! starting at bit 0. 306//! 307//! \return None. 308// 309//***************************************************************************** 310#define USBLibDMAIntStatusClear (psUSBDMAInst ,ui32Status ) \ 311 psUSBDMAInst->pfnIntStatusClear(psUSBDMAInst, ui32Status) 312 313//***************************************************************************** 314// 315//! This function enables DMA for a given channel. 316//! 317//! \param psUSBDMAInst is the DMA structure pointer for this instance. 318//! \param ui32Channel is the DMA channel to enable. 319//! 320//! This function enables DMA on the channel number passed in the 321//! \e ui32Channel parameter. 322//! 323//! \return None. 324// 325//***************************************************************************** 326#define USBLibDMAChannelEnable (psUSBDMAInst ,ui32Channel ) \ 327 psUSBDMAInst->pfnChannelEnable(psUSBDMAInst, ui32Channel) 328 329//***************************************************************************** 330// 331//! This function disables DMA for a given DMA channel. 332//! 333//! \param psUSBDMAInst is the DMA structure pointer for this instance. 334//! \param ui32Channel is the DMA channel to disable. 335//! 336//! This function disables DMA on the channel number passed in the 337//!\e ui32Channel parameter. 338//! 339//! \return None. 340// 341//***************************************************************************** 342#define USBLibDMAChannelDisable (psUSBDMAInst ,ui32Channel ) \ 343 psUSBDMAInst->pfnChannelDisable(psUSBDMAInst, ui32Channel) 344 345//***************************************************************************** 346// 347//! This function is configures a USB transfer on a given DMA channel. 348//! 349//! \param psUSBDMAInst is the DMA structure pointer for this instance. 350//! \param ui32Channel is the DMA channel to use. 351//! \param pvBuffer is a pointer to the buffer to use for the transfer. 352//! \param ui32Size is the size of the data to be transferred in bytes. 353//! 354//! This function is called to configure a transfer using the USB 355//! controller depending on the parameters. The \e ui32Channel parameter 356//! holds the channel number to use for this transfer which must have already 357//! been allocated with a call to the USBLibDMAChannelAllocate() function. The 358//! transaction is configured to transfer \e ui32Size bytes to/from the buffer 359//! held in the \e pvBuffer pointer. 360//! 361//! \return This function returns the number of bytes scheduled to be 362//! transferred. 363// 364//***************************************************************************** 365#define USBLibDMATransfer (psUSBDMAInst ,ui32Channel ,pvBuffer ,ui32Size ) \ 366 psUSBDMAInst->pfnTransfer(psUSBDMAInst, ui32Channel, pvBuffer, ui32Size) 367 368//***************************************************************************** 369// 370//! This function is called by the USB interrupt handler. 371//! 372//! \param psUSBDMAInst is the DMA structure pointer for this instance. 373//! \param ui32Status is the DMA interrupt status. 374//! 375//! This function is called by the USB interrupt handler to allow the DMA 376//! interface to handle interrupts outside of the context of the normal USB 377//! interrupt handler. The \e ui32Status is the current DMA interrupt status 378//! at the time of the USB interrupt. Since some DMA controller interrupts are 379//! cleared automatically when read, this value must be retrieved by calling 380//! the USBLibDMAIntStatus() function and passed into this function. 381//! 382//! \return None. 383// 384//***************************************************************************** 385#define USBLibDMAIntHandler (psUSBDMAInst ,ui32Status ) \ 386 psUSBDMAInst->pfnIntHandler(psUSBDMAInst, ui32Status) 387 388//***************************************************************************** 389// 390//! This function is used to assign a DMA channel to an endpoint. 391//! 392//! \param psUSBDMAInst is the DMA instance data for a USB controller. 393//! \param ui8Endpoint is the endpoint number to assign a DMA channel. 394//! \param ui32MaxPacketSize is the maximum packet size for the endpoint 395//! assigned that is being assigned to the DMA channel. 396//! \param ui32Config are the basic configuration options for the DMA channel. 397//! 398//! This function assigns a DMA channel to a given endpoint. The 399//! \e ui8Endpoint parameter is the zero based endpoint number that is assigned 400//! a DMA channel. The \e ui32Config parameter contains any configuration 401//! options for the DMA channel. The current options include the following: 402//! - \b USB_DMA_EP_TX - this request is for a transmit DMA channel. 403//! - \b USB_DMA_EP_RX - this request is for a receive DMA channel. 404//! 405//! \note The maximum number of available DMA channels to endpoints varies 406//! between devices. 407//! 408//! \return Zero or the DMA channel assigned to the endpoint. 409// 410//***************************************************************************** 411#define USBLibDMAChannelAllocate (psUSBDMAInst ,ui8Endpoint ,ui32MaxPacketSize , \ 412ui32Config ) \ 413 psUSBDMAInst->pfnChannelAllocate(psUSBDMAInst, ui8Endpoint, \ 414 ui32MaxPacketSize, ui32Config) 415 416//***************************************************************************** 417// 418//! This function is used to free a DMA channel that was assigned to an 419//! endpoint. 420//! 421//! \param psUSBDMAInst is the DMA instance data for a USB controller. 422//! \param ui8Endpoint is the DMA channel number to free up. 423//! 424//! This function frees up a DMA channel that was allocated to an endpoint 425//! by the USBLibDMAChannelAllocate() function. 426//! 427//! \return None. 428// 429//***************************************************************************** 430#define USBLibDMAChannelRelease (psUSBDMAInst ,ui8Endpoint ) \ 431 psUSBDMAInst->pfnChannelRelease(psUSBDMAInst, ui8Endpoint) 432 433//***************************************************************************** 434// 435//! This function is used to set the individual transfer size of a DMA channel. 436//! 437//! \param psUSBDMAInst is the DMA instance data for a USB controller. 438//! \param ui32Channel is the DMA channel number to modify. 439//! \param ui32BitSize is the individual transfer size in bits(8, 16 or 32). 440//! 441//! This function configures the individual transfer size of the DMA channel 442//! provided in the \e ui32Channel parameter. The \e ui32Channel must already 443//! be allocated to an endpoint by calling the USBLibDMAChannelAllocate() 444//! function. The \e ui32BitSize parameter should be on of the following 445//! values: 8, 16 or 32. 446//! 447//! \return None. 448// 449//***************************************************************************** 450#define USBLibDMAUnitSizeSet (psUSBDMAInst ,ui32Channel ,ui32BitSize ) \ 451 psUSBDMAInst->pfnUnitSizeSet(psUSBDMAInst, ui32Channel, ui32BitSize); 452 453//***************************************************************************** 454// 455//! This function is used to set the arbitration size for a DMA channel. 456//! 457//! \param psUSBDMAInst is the DMA instance data for a USB controller. 458//! \param ui32Channel is the DMA channel number to modify. 459//! \param ui32ArbSize is the transfer arbitration size in bytes. 460//! 461//! This function configures the individual transfer size of the DMA channel 462//! provided in the \e ui32Channel parameter. The \e ui32Channel must already 463//! be allocated to an endpoint by calling the USBLibDMAChannelAllocate() 464//! function. 465//! 466//! \return None. 467// 468//***************************************************************************** 469#define USBLibDMAArbSizeSet (psUSBDMAInst ,ui32Channel ,ui32ArbSize ) \ 470 psUSBDMAInst->pfnArbSizeSet(psUSBDMAInst, ui32Channel, ui32ArbSize); 471 472//***************************************************************************** 473// 474//! This function enables the DMA interrupt for a given channel. 475//! 476//! \param psUSBDMAInst is the DMA structure pointer for this instance. 477//! \param ui32Channel is the DMA channel interrupt to enable. 478//! 479//! This function enables DMA interrupt on the channel number passed in the 480//! \e ui32Channel parameter. 481//! 482//! \return None. 483// 484//***************************************************************************** 485#define USBLibDMAChannelIntEnable (psUSBDMAInst ,ui32Channel ) \ 486 psUSBDMAInst->pfnChannelIntEnable(psUSBDMAInst, ui32Channel) 487 488//***************************************************************************** 489// 490//! This function disables DMA interrupt for a given DMA channel. 491//! 492//! \param psUSBDMAInst is the DMA structure pointer for this instance. 493//! \param ui32Channel is the DMA channel interrupt to disable. 494//! 495//! This function disables the DMA interrupt on the channel number passed in 496//! the \e ui32Channel parameter. 497//! 498//! \return None. 499// 500//***************************************************************************** 501#define USBLibDMAChannelIntDisable (psUSBDMAInst ,ui32Channel ) \ 502 psUSBDMAInst->pfnChannelIntDisable(psUSBDMAInst, ui32Channel) 503 504//***************************************************************************** 505// 506// Mark the end of the C bindings section for C++ compilers. 507// 508//***************************************************************************** 509#ifdef __cplusplus 510} 511#endif 512 513//***************************************************************************** 514// 515// Close the Doxygen group. 516//! @} 517// 518//***************************************************************************** 519 520#endif // __USBLIBPRIV_H__