background image

Interconnectivity

Page 21 of 22

Firmware Programming Guide for PDIUSBD12

Philips Semiconductors - Asia Product Innovation Centre

Visit  

http://www.flexiusb.com

8.3 DMA Configuration Register

The D12's DMA operation is controlled by its DMA Configuration Register, which is set by the command Set
DMA. Not all the bits inside the register are related to the DMA operation. Bit 4 (Interrupt Pin Mode) together
with Bit 7 of Clock Division Factor (SOF-ONLY) controls D12 sources of interrupt.

The table below is a summary of the recommended register programming:

Bit

Name

DMA Mode

Non-DMA Mode

0 & 1

DMA Burst

‘1’ & ‘1’

Don’t care

2

DMA Enable

‘1’

‘0’

3

DMA Direction

‘1’ for IN token;
‘0’ for OUT token

Don’t care

4

Auto Reload

‘0’

Don’t care

5

Interrupt Pin Mode

‘0’

‘0’

6

Endpoint 4 Interrupt Enable

‘0’

‘1’

7

Endpoint 5 Interrupt Enable

‘0’

‘1’

By default, both D12 and DMAC are not in auto-reload mode. We do not want the device's DMA "auto-restart"
because this is a protocol-based operation, that is, under host's control. At EOT, both of D12 and DMA
controller's DMA will be disabled. The firmware needs to re-enable them to restart DMA transfer upon
receiving Setup DMA Request from the host.

Please also note that the interrupt from endpoints 4 and 5 are disabled in DMA mode. Servicing interrupt on
these endpoints is unnecessary and has a potential flaw during the DMA transfer. DMA can be treated as the
highest "interrupt" that happens between any CPU instructions, even inside ISR. Any routines that may want to
be used to check DMA status are not reliable because the DMA status during the transfer may change at any
time.

8.4 Setup DMA Request

Setup DMA request is a vendor request that is sent through control pipe. In PDIUSBD12 sample firmware and
Applet, this is done by IOCTL_WRITE_REGISTER, which is defined by Microsoft Still Image USB Interface
in Windows 98 DDK. The device's request is described below.

Offset

Field

Size

Value

Comments

0

BmRequestType

1

0x40

Vendor request, device to host

1

Brequest

1

0x0C

Fixed value for IOCTL_WRITE_REGISTER

2

Wvalue

2

0

Offset, set to zero

4

Windex

2

0x0471

Fixed value of Setup DMA Request

6

Wlength

2

6

Data length of Setup DMA Request

The details requested by the DMA operation are sent in the data phase after the device's request. The sample
firmware and Applet use a proprietary definition, which is shown below:

Offset

Field

Comments

0

Address [7:0]

The start address of requested DMA transfer.

1

Address [15:8]

2

Address [23:16]

3

Size [7:0]

The size of transfer.

4

Size [15:8]

5

Command

Bit 7: ‘1’ start DMA transfer
Bit 0: ‘1’ IN token; ‘0’ OUT token

Summary of Contents for PDIUSBD12

Page 1: ...____________________________________________________________________________________________ Philips Semiconductors Asia Product Innovation Centre Visit http www flexiusb com 23 September 1998 Firmware Programming Guide for PDIUSBD12 Version 1 0 ...

Page 2: ...HILIPS SEMICONDUCTORS FURTHER DISCLAIMS ALL WARRANTIES INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF MERCHANT ABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT THE ENTIRE RISK ARISING OUT OF THE USE OR PERFORMANCE OF THE PRODUCT AND DOCUMENTATION REMAINS WITH THE RECIPIENT TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW IN NO EVENT SHALL PHILIPS SEMICONDUCTORS OR ITS SUPPLIER...

Page 3: ...ER CPU PLATFORM 6 2 3 USING THE FIRMWARE IN POLLING MODE 6 3 HARDWARE ABSTRACTION LAYER 7 4 PDIUSBD12 COMMAND INTERFACE 7 5 INTERRUPT SERVICE ROUTINE 8 5 1 BUS RESET AND SUSPEND CHANGE 9 5 2 CONTROL ENDPOINT HANDLER 10 5 3 GENERIC ENDPOINT HANDLER 13 5 4 MAIN ENDPOINT HANDLER 13 5 5 EOT HANDLER 13 6 MAIN LOOP 14 7 CHAPTER 9 PROTOCOL 15 7 1 CLEAR FEATURE REQUEST 15 7 2 GET STATUS REQUEST 16 7 3 SET...

Page 4: ...d to the CPU and the CPU will service ISR immediately Inside the ISR the firmware moves the data packet to the circular buffer from PDIUSBD12 s internal buffer and then clears the PDIUSBD12 s internal buffer to enable PDIUSBD12 to receive new packet The CPU can continue its current foreground task until completion e g printing current page Then it returns to the main loop checks the circular buffe...

Page 5: ...de always needs modifications or additions 2 1 2 PDIUSBD12 Command Interface D12CI C To further simplify programming with PDIUSBD12 the firmware defines a set of command interfaces which encapsulate all the functions used to access PDIUSBD12 2 1 3 Interrupt Service Routine ISR C This part of the code handles interrupt generated by PDIUSBD12 It retrieves data from PDIUSBD12 s internal FIFO to CPU m...

Page 6: ...Chapter 9 Only Product Level EPPHAL C Port to hardware specific Port to hardware specific D12CI C No change No change CHAP_9 C No change Product specific USB descriptors PROTODMA C No change Add vendor request supports if necessary ISR C No change Add product specific processing on Generic and Main endpoints MAINLOOP C Depends on the CPU and system ports timer and interrupt initialization need to ...

Page 7: ...essary to be implemented in target application void eppAwrite unsigned char A_data void program_cpld unsigned short uSize unsigned char bCommand 4 PDIUSBD12 Command Interface The following functions are defined as PDIUSBD12 command interface to simplify device programming They are simple implementations of the PDIUSBD12 command set which is defined in the data sheet void D12_SetAddressEnable unsig...

Page 8: ...n to dispatch it to the appropriate subroutines for processing ISR ISR Entry Read D12 Interrupt Register Reset Idle Timer Bus Reset Suspend Change DMA EOT Control In Done Control Out Done Generic In Done Generic Out Done Main In Done Main Out Done Send EOI to Interrupt Controller End of ISR No No No No No No No No No Set Bus Reset Flag Yes Set Suspend Changed Flag DMA EOT handler Subroutine Contro...

Page 9: ...t unsigned short wValue unsigned short wIndex unsigned short wLength DEVICE_REQUEST typedef struct _control_xfer DEVICE_REQUEST DeviceRequest unsigned short wLength unsigned short wCount unsigned char pData unsigned char dataBuffer MAX_CONTROLDATA_SIZE CONTROL_XFER The task splitting between Main Loop and ISR is that ISR collects data from D12 and Main Loop will process the data The ISR will only ...

Page 10: ...trol transfer always begins with the SETUP stage and then followed later by an optional DATA stage It then ends with the STATUS stage The diagram below shows the various states of transitions on the Control endpoints The firmware uses these 3 states to handle Control transfer correctly IDLE TRANSMIT RECEIVE No data Control return Status Control Write Status Control Read Status INs OUTs ...

Page 11: ... to extract the content of the setup packet through Select Control Out Endpoint to determine whether this endpoint is full or empty If the control endpoint is full MCU will then read the content from the buffer and save the content to its memory After that it will validate the host device s request from the memory If it is a valid request MCU must send the Acknowledge Setup command to the Control ...

Page 12: ... check its current and remaining size of the data to be sent to the host If the remaining bytes are greater than 16 bytes MCU will send the first 16 bytes and then subtract the reference length requested length by 16 When the next Control_In token comes MCU will determine whether the remaining bytes is zero If there is no more data to send MCU will need to send an empty packet to inform the host t...

Page 13: ...en configured to send the information of the button activity as a byte to the host 5 4 Main Endpoint Handler Since the Main In Out Endpoints are configured to the DMA mode and the interrupts are disabled for these endpoints no ISR services are normally required for these endpoints However for safer code implementation we have put in place clear interrupt routine here 5 5 EOT Handler For more infor...

Page 14: ... only A 1mSec timer is programmed to activate the routine to check for any button pressed on the evaluation board When the polling reaches the check Setup packet it verifies the setup flag set previously by the interrupt service routine If the setup flag is set it will dispatch a device request to the protocol layer for processing The flowchart above shows the main program executing on the foregro...

Page 15: ...s an interface Feature selectors are used when enabling or setting features specific to the device or endpoint such as remote wakeup When the recipient is a device MCU will need to disable the remote wakeup function if this function has been enabled If the recipient is the endpoint the MCU will have to unstall the specific endpoint through the Set Endpoint Status command Is recipient a device Is r...

Page 16: ...ata will be 0x0003 If the recipient is an interface then MCU should return 0x0000 to the host 7 3 Set Address Request In the Set address request the device will get the new address from the content of the setup packet Note that this set address request does not have a data phase Therefore MCU will need to write a zero length data packet to the host as the acknowledgment phase Get_Status Return Dev...

Page 17: ...e device is configured 7 5 Get Descriptor Request For the Get Descriptor request MCU must return the specific descriptor if the descriptor exists Firstly MCU will determine whether the descriptor type request is for the device or the configuration It will then send the first 16 bytes of device descriptor if the descriptor type is for device The reason for controlling the size of returning bytes is...

Page 18: ...eed to set the configuration flag Once the flag is set MCU will also need to send the zero data packet to the host for the acknowledgment phase 7 7 Get Set Interface Request or Get Interface request MCU will just need to send one zero data packet to the host as our evaluation board only supports one type of interface For Set Interface request on our evaluation board MCU need not do anything except...

Page 19: ... to the feature selector on the setup packet Again there is no support for the Interface recipient For example if the feature selector is 0 which means enabling endpoint the D12 specific endpoint will have to be stalled through D12_SetEndpoint status command Is recipient a device Is recipient an Interface Is recipient an endpoint Set device feature according to Feature Selector Yes No Yes No Yes U...

Page 20: ...and allow the device to program the DMAC with DMA transfer direction start address and size of transfer 2 Send or receive data packets on the main endpoint 8 2 Device s DMA States The Setup DMA Request is sent from the host as vendor request using control pipe The device s response and action depend on its internal states of DMA operation The diagram above shows 3 DMA states in the device IDLE RUN...

Page 21: ...at the interrupt from endpoints 4 and 5 are disabled in DMA mode Servicing interrupt on these endpoints is unnecessary and has a potential flaw during the DMA transfer DMA can be treated as the highest interrupt that happens between any CPU instructions even inside ISR Any routines that may want to be used to check DMA status are not reliable because the DMA status during the transfer may change a...

Page 22: ...points with a single thread IOCTL_WRITE_REGISTER and IOCTL_READ_REGISTER use structure IO_BLOCK to exchange data with the device driver Below structure definition is part of Microsoft Still Image USB Interface typedef struct _IO_BLOCK IN unsigned uOffset IN unsigned uLength IN OUT PUCHAR pbyData IN unsigned uIndex IO_BLOCK PIO_BLOCK IO_REQUEST structure is a proprietary definition that contains de...

Reviews: