Keil Logo

usb asynchronous

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
usbtom usbtom
Posted
17-Sep-2011 05:34 GMT
Toolset
ARM
New! usb asynchronous

How do I set the usb audio code up for usb asynchronous transfers.

Do I just have to change bmAttributes

USB_ENDPOINT_TYPE_ISOCHRONOUS,

to

USB_ENDPOINT_SYNC_ASYNCHRONOUS

or is it more complexed than that.

Read-Only
Author
Andrew Neil
Posted
17-Sep-2011 13:36 GMT
Toolset
ARM
New! RE: the (sic) usb audio code

What "usb audio code" ?

Read-Only
Author
Hans-Bernhard Broeker
Posted
17-Sep-2011 15:54 GMT
Toolset
ARM
New! RE: the (sic) usb audio code

What "usb audio code" ?

Odds are the OP is just another new alias of that ... well, let's call it a "person", who recently so thoroughly expressed their belief that the best way of getting help was to spew verbal abuse here in dozens of sequential postings.

Read-Only
Author
usbtom usbtom
Posted
18-Sep-2011 00:07 GMT
Toolset
ARM
New! asynchronous examples?? documentation??

This code, I have looked and looked can't not seem to find much support on this subject, asynchronous transfers.

http://www.keil.com/download/files/lpc2368_usbaudio.zip

Read-Only
Author
Tsuneo Chinzei
Posted
18-Sep-2011 08:15 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

Here is a descriptor readout of a typical Async Sink device (Ayre QB9),
taken from http://list.voyage.hk/pipermail/voyage-linux/2011-April/013449.html

Compare it with the example's

lsusb -v

Bus 001 Device 004: ID 21b4:0130
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x21b4
  idProduct          0x0130
  bcdDevice            1.71
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          134
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0
      iInterface              7
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength           30
        bInCollection           1
        baInterfaceNr( 0)       1
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             6
        wTerminalType      0x0301 Speaker
        bAssocTerminal          0
        bSourceID               1
        iTerminal               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              9
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              8
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           1
        bDelay                  1 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                20
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           3
        bBitResolution         24
        bSamFreqType            4 Discrete
        tSamFreq[ 0]        44100
        tSamFreq[ 1]        48000
        tSamFreq[ 2]        88200
        tSamFreq[ 3]        96000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0246  1x 582 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress         129
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x01
            Sampling Frequency
          bLockDelayUnits         2 Decoded PCM samples
          wLockDelay              0 Decoded PCM samples
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0003  1x 3 bytes
        bInterval               1
        bRefresh                1
        bSynchAddress           0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       254 Application Specific Interface
      bInterfaceSubClass      1 Device Firmware Update
      bInterfaceProtocol      0
      iInterface             14
      Device Firmware Upgrade Interface Descriptor:
        bLength                             7
        bDescriptorType                    33
        bmAttributes                        7
          Will Not Detach
          Manifestation Tolerant
          Upload Supported
          Download Supported
        wDetachTimeout                    250 milliseconds
        wTransferSize                      64 bytes

Tsuneo

Read-Only
Author
Tsuneo Chinzei
Posted
18-Sep-2011 08:40 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

The terms, Asynchronous / Synchronous / Adaptive on USB audio class mean the synchronization type.
It suggests the place where the original sampling clock sits on.

- Asynchronous: the sampling clock is generated on the device side.
- Synchronous: the clock derives from USB SOF by PLL
- Adaptive: the clock is generated on the host side.

For Asynchronous Sink (output) device, like a speaker,
the device has to notify to host on its sampling clock, to synchronize the host. For this purpose, a feedback endpoint (isoc IN) is associated to the isoc OUT endpoint of the audio stream, like above QB9

For Asynchronous Source (input) device, like a microphone,
The sampling rate on the device is shown as the number of the samples in each isoc packet on the audio stream. The number is relative to the SOF frequency. Therefore, any feedback endpoint is not required.

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
18-Sep-2011 18:34 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

I have changed it to

* Endpoint - Standard Descriptor */
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_OUT(3),                  /* bEndpointAddress */
  //USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  0x05,
  WBVAL(64),                            /* wMaxPacketSize */
  0x01,                                 /* bInterval */
  0x00,                                 /* bRefresh */
  0x00,                                 /* bSynchAddress */

and it worked, I don't understand who ever wrote the bmAttributes in Endpoint Descriptor expected it to be wrote?

/* bmAttributes in Endpoint Descriptor */
#define USB_ENDPOINT_TYPE_MASK                 0x03
#define USB_ENDPOINT_TYPE_CONTROL              0x00
#define USB_ENDPOINT_TYPE_ISOCHRONOUS          0x01
#define USB_ENDPOINT_TYPE_BULK                 0x02
#define USB_ENDPOINT_TYPE_INTERRUPT            0x03
#define USB_ENDPOINT_SYNC_MASK                 0x0C
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION   0x00
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS         0x04
#define USB_ENDPOINT_SYNC_ADAPTIVE             0x08
#define USB_ENDPOINT_SYNC_SYNCHRONOUS          0x0C
#define USB_ENDPOINT_USAGE_MASK                0x30
#define USB_ENDPOINT_USAGE_DATA                0x00
#define USB_ENDPOINT_USAGE_FEEDBACK            0x10
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK   0x20
#define USB_ENDPOINT_USAGE_RESERVED            0x30

of the keil code working

0 bLength 1 09h
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 03h 3 Out
3 bmAttributes 1 05h Isochronous, Asynchronous, Data
 1..0: Transfer Type  ......01  Isochronous
 3..2: Sync Type  ....01..  Asynchronous
 5..4: Usage Type  ..00....  Data
 7..6: Reserved  00......
4 wMaxPacketSize 2 0040h 64 bytes
6 bInterval 1 01h 1 ms
7 bRefresh 1 00h
8 bSynchAddress 1 00h

Because of stuff like the above, I can not figure out how to change the isoch transfer size,bytes buffer, bytes data. I can not understand the code of the person who wrote it.

Read-Only
Author
Tsuneo Chinzei
Posted
20-Sep-2011 17:31 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

> I have changed it to ... and it worked,

Did you add an isoc IN endpoint for feedback?
Windows and MacOSX ignore Asynchronous bits on the bmAttributes, if the streaming OUT endpoint isn't associated with a feedback IN endpoint. Without any feedback EP, these audio drivers "work" the device as a Synchronous one.

Here is an outline of the feedback endpoint of Async Sink.

                           Host side <---- | ----> Device side
                                                                                Counter
                          +---------- synch IN EP <------ shift to    <-------- gated by SOF
                          |                               10.10 format               ^
                          |                                                          |
                          |                                                      Base clock
                       Feedback                                                      |
                          |                                                       Divider
                          |                                                          |
                          V                                                          V
Audio Source ===(rate conversion)===> isoc OUT EP =============> buffer ==========> DAC ===> Speaker

For the details, refer to this chapter on the USB2.0 spec (usb_20.pdf, in http://www.usb.org/developers/docs/usb_20_071411.zip )
5.12.4.2 Feedback



> I can not figure out how to change the isoch transfer size,bytes buffer, bytes data.

The format of the streaming packet is defined on the descriptor on your device.
Above QB-9 declares these descriptors on the streaming interface.

      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           1
        bDelay                  1 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                20
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           3
        bBitResolution         24
        bSamFreqType            4 Discrete
        tSamFreq[ 0]        44100
        tSamFreq[ 1]        48000
        tSamFreq[ 2]        88200
        tSamFreq[ 3]        96000

This descriptors declare,
- Type I PCM (wFormatTag / bFormatType)
- 2ch (L/R) (bNrChannels)
- 3 bytes, 24bits (bSubframeSize / bBitResolution)
- 44.1, 48, 88.2, 96 kHz (tSamFreq[])

For 96 kHz, every isoc OUT packet has the size, 3 bytes * 2 ch * 96 samples = 576 bytes, primarily.
However, the sampling frequency of the device is not exactly 96 times of the SOF frequency.
The crystal which sources 96 kHz has some tolerance. Also, USB spec defines the tolerance of Frame interval as 1.000 ms +/-500 ns

Therefore, actual packet size may have plus/minus by one sample
3 bytes * 2 ch * (96 + 1) samples = 582 bytes
In this reason, above QB-9 example sets wMaxPacketSize to 582

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
20-Sep-2011 19:01 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

>Did you add an isoc IN endpoint for feedback?

I believe so yes?

/* Audio Input Terminal */
  AUDIO_INPUT_TERMINAL_DESC_SIZE,       /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_CONTROL_INPUT_TERMINAL,         /* bDescriptorSubtype */
  0x01,                                 /* bTerminalID */
  WBVAL(AUDIO_TERMINAL_USB_STREAMING),  /* wTerminalType */
  0x00,                                 /* bAssocTerminal */
  0x01,                                 /* bNrChannels */
  WBVAL(AUDIO_CHANNEL_M),               /* wChannelConfig */
  0x00,                                 /* iChannelNames */
  0x00,                                 /* iTerminal */
/* Audio Feature Unit */
  AUDIO_FEATURE_UNIT_DESC_SZ(1,1),      /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_CONTROL_FEATURE_UNIT,           /* bDescriptorSubtype */
  0x02,                                 /* bUnitID */
  0x01,                                 /* bSourceID */
  0x01,                                 /* bControlSize */
  AUDIO_CONTROL_MUTE |
  AUDIO_CONTROL_VOLUME,                 /* bmaControls(0) */
  0x00,                                 /* bmaControls(1) */
  0x00,                                 /* iTerminal */
/* Audio Output Terminal */
  AUDIO_OUTPUT_TERMINAL_DESC_SIZE,      /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_CONTROL_OUTPUT_TERMINAL,        /* bDescriptorSubtype */
  0x03,                                 /* bTerminalID */
  WBVAL(AUDIO_TERMINAL_SPEAKER),        /* wTerminalType */
  0x00,                                 /* bAssocTerminal */
  0x02,                                 /* bSourceID */
  0x00,                                 /* iTerminal */
/* Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith */
  USB_INTERFACE_DESC_SIZE,              /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
  AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
  AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
/* Interface 1, Alternate Setting 1, Audio Streaming - Operational */
  USB_INTERFACE_DESC_SIZE,              /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x01,                                 /* bAlternateSetting */
  0x01,                                 /* bNumEndpoints */
  USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
  AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
  AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
/* Audio Streaming Interface */
  AUDIO_STREAMING_INTERFACE_DESC_SIZE,  /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_STREAMING_GENERAL,              /* bDescriptorSubtype */
  0x01,                                 /* bTerminalLink */
  0x01,                                 /* bDelay */
  WBVAL(AUDIO_FORMAT_PCM),              /* wFormatTag */
/* Audio Type I Format */
  AUDIO_FORMAT_TYPE_I_DESC_SZ(1),       /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_STREAMING_FORMAT_TYPE,          /* bDescriptorSubtype */
  AUDIO_FORMAT_TYPE_I,                  /* bFormatType */
  0x01,                                 /* bNrChannels */
  0x02,                                 /* bSubFrameSize */
  16,                                   /* bBitResolution */
  0x01,                                 /* bSamFreqType */
  B3VAL(32000),                         /* tSamFreq */
/* Endpoint - Standard Descriptor */
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_OUT(3),                  /* bEndpointAddress */
  //USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  0x05,
  WBVAL(64),                            /* wMaxPacketSize */
  0x04,                                 /* bInterval */
  0x00,                                 /* bRefresh */
  0x00,                                 /* bSynchAddress */

I still am not sure how to change the isoch transfer with the keil code.

But I think it is 10 * 64 = 640. I did change WBVAL(64), to WBVAL(128), but it is still only 640

Interface 1 / Alt 1     Audio, 1 pipe
Endpoint 03h    3 Out, Isochronous 128 bytes

Endpoint 03h    3 Out, Isochronous

Bytes to Transfer       280h (640)

Read-Only
Author
Tsuneo Chinzei
Posted
20-Sep-2011 22:52 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

>> Did you add an isoc IN endpoint for feedback?
> I believe so yes?

Not yet.
Add a descriptor of the feedback EP,
Modify the standard / class-specific EP descriptors.
Your Type I descriptor declares PCM of 2 bytes (16bits), single channel, 32kHz sampling.
Therefore, wMaxPacketSize of the isoc OUT EP is 66 bytes.
2 bytes * 1 ch * (32 + 1) samples = 66 bytes

/* Endpoint - Standard Descriptor */
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_OUT(3),                  /* bEndpointAddress */
  //USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  0x05,                    // <----- USB_ENDPOINT_TYPE_ISOCHRONOUS | USB_ENDPOINT_SYNC_ASYNCHRONOUS
  WBVAL(64),                            /* wMaxPacketSize */ // <----- WBVAL(66)
  0x04,                                 /* bInterval */      // <----- 0x01 (every 1ms)
  0x00,                                 /* bRefresh */
  0x00,                                 /* bSynchAddress */  // <----- 0x83 (IN 3)

/* Endpoint - Audio Streaming */
  AUDIO_STREAMING_ENDPOINT_DESC_SIZE,   /* bLength */
  AUDIO_ENDPOINT_DESCRIPTOR_TYPE,       /* bDescriptorType */
  AUDIO_ENDPOINT_GENERAL,               /* bDescriptor */
  0x00,                                 /* bmAttributes */
  0x00,                                 /* bLockDelayUnits */ // <----- 0x02 (Decoded PCM samples)
  WBVAL(0x0000),                        /* wLockDelay */

/* Endpoint - Standard Descriptor */                       // <-------- additional feedback EP
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_IN(3),                   /* bEndpointAddress */
  USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  WBVAL(3),                             /* wMaxPacketSize */
  0x01,                                 /* bInterval */
  0x01,                                 /* bRefresh, every 2ms */
  0x00,                                 /* bSynchAddress */

/* Terminator */
  0                                     /* bLength */
};

With this addition of the feedback EP, the wTotalLength on the Config descriptor is modified, as follows

/* Configuration 1 */
  USB_CONFIGUARTION_DESC_SIZE,          /* bLength */
  USB_CONFIGURATION_DESCRIPTOR_TYPE,    /* bDescriptorType */
  WBVAL(                                /* wTotalLength */
    USB_CONFIGUARTION_DESC_SIZE         +
    USB_INTERFACE_DESC_SIZE             +
    AUDIO_CONTROL_INTERFACE_DESC_SZ(1)  +
    AUDIO_INPUT_TERMINAL_DESC_SIZE      +
    AUDIO_FEATURE_UNIT_DESC_SZ(1,1)     +
    AUDIO_OUTPUT_TERMINAL_DESC_SIZE     +
    USB_INTERFACE_DESC_SIZE             +
    USB_INTERFACE_DESC_SIZE             +
    AUDIO_STREAMING_INTERFACE_DESC_SIZE +
    AUDIO_FORMAT_TYPE_I_DESC_SZ(1)      +
    AUDIO_STANDARD_ENDPOINT_DESC_SIZE   +
    AUDIO_STREAMING_ENDPOINT_DESC_SIZE  +              // <----------
    AUDIO_STANDARD_ENDPOINT_DESC_SIZE                  // <----------
  ),

The feedback endpoint is supplied with the frequency ratio (master sampling / SOF frequency) in 10.10 fixed-point format on 3 bytes (left-justified, ie. 10.14 format).

In this example, 32kHz master clock derives from PCLK, divided by (VPB_CLOCK/DATA_FREQ) at Timer0.
To generate feedback value,
- Run another timer on PCLK in free run
- At USB_SOF_Event() (usbuser.c),
- - read this timer count.
- - Calculate this value
((current_timer_count - last_timer_count) << 14) / (VPB_CLOCK / DATA_FREQ)
- - Write the LSB 3 bytes of this calculated value (LSB first) into the IN 3 EP, using USB_WriteEP()
- - Save current_timer_count into last_timer_count

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
21-Sep-2011 12:19 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

>- Run another timer on PCLK in free run

Is this what you mean by free run, just leaving it blank? What is this (VPB_CLOCK) you talk of.

void TIMER1_IRQHandler(void)
{

LPC_TIM1->IR = 1;                         /* Clear Interrupt Flag */




LPC_SC->PCONP |= 1 << 2;     // Power on Timer'

  LPC_TIM1->MR0 = pclk/DATA_FREQ - 1;   /* TC0 Match Value 0 */
  LPC_TIM1->MCR = 3;                                    /* TCO Interrupt and Reset on MR0 */
  LPC_TIM1->TCR = 1;                                    /* TC0 Enable */
  NVIC_EnableIRQ(TIMER0_IRQn);


   }
Read-Only
Author
usbtom usbtom
Posted
21-Sep-2011 13:00 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

>- At USB_SOF_Event() (usbuser.c),
> - - read this timer count.
> - - Calculate this value

I have been goolge but have not found out how to do this yet, I had a go at it.

uint32_t current_timer_count

uint32_t last_timer_count

#if USB_SOF_EVENT
void USB_SOF_Event (void) {
#if TIMER1_IRQHandler > 0
current_timer_count = TIMER1
else if
current_timer_count = TIMER1
TIMER1 = last_timer_count
#if USB_SOF_EVENT
void USB_SOF_Event (void) {
#if TIMER1_IRQHandler > 0
current_timer_count = TIMER1
else if
#if TIMER1_IRQHandler < 1000
TIMER1 = last_timer_count

LPC_TIM1->MR0 =  1000;
Read-Only
Author
usbtom usbtom
Posted
21-Sep-2011 13:46 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

Unsure about LSB but is this close or not

#if USB_SOF_EVENT
void USB_SOF_Event (void) {
#if USB_DMA == 1


>Calculate this value, Write the LSB 3 bytes of this calculated value (LSB first) into the IN 3 EP, using USB_WriteEP()
if (USB_WriteEP(0x83,((current_timer_count - last_timer_count) << 14) / pclk/DATA_FREQ - 1;

> - - Save current_timer_count into last_timer_count

current_timer_count = last_timer_count


LPC_USB->USBDMARSet = 1 << EPAdr(0x83);
Read-Only
Author
usbtom usbtom
Posted
21-Sep-2011 14:16 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

I put timer counter in main.c like this

void TIMER1_IRQHandler(void)
{

if TIMER1_IRQHandler > 0
current_timer_count = TIMER1
else if TIMER1_IRQHandler < 1000
TIMER1 = last_timer_count


LPC_TIM1->IR = 1;                         /* Clear Interrupt Flag */




  LPC_SC->PCONP |= 1 << 2;     // Power on Timer'

  LPC_TIM1->MR0 =  1000; // 1us


  LPC_TIM1->MCR = 3;                                    /* TCO Interrupt and Reset on MR0 */
  LPC_TIM1->TCR = 1;                                    /* TC0 Enable */
  NVIC_EnableIRQ(TIMER0_IRQn);

Read-Only
Author
Tsuneo Chinzei
Posted
22-Sep-2011 19:35 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

In above post, I've missed to pick up this mods to the streaming interface descriptor.

/* Interface 1, Alternate Setting 1, Audio Streaming - Operational */
  USB_INTERFACE_DESC_SIZE,              /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x01,                                 /* bAlternateSetting */
  0x01,                                 /* bNumEndpoints */    <----- 0x02 (plus one, for the feedback EP)
  USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
  AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
  AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
  0x00,                                 /* iInterface */

>> - Run another timer on PCLK in free run
> Is this what you mean by free run, just leaving it blank? What is this (VPB_CLOCK) you talk of.

Just enable the Timer1 on the default setting. No interrupt is required for the Timer1

current_timer_count is a readout of Timer1 register (T1TC), at the entry of USB_SOF_Event() callback.
It represents the SOF timing measured on the PCLK, which is also the master sampling clock for DAC.
Unfortunately, USB engines on LPC family don't have hardware SOF trigger to Timers. As a workaround, the timer value at the SOF timing is captured by the firmware at SOF (FRAME) interrupt.

> if (USB_WriteEP(0x83,((current_timer_count - last_timer_count) << 14) / pclk/DATA_FREQ - 1;

"- 1" is not required.
The example sets up Timer0 match register with "VPB_CLOCK/DATA_FREQ - 1"

demo.c
int main(void)
{
  ...
  /* Setup Timer Counter 0: Periodic Timer with Interrupt at DATA_FREQ Rate */
  T0MR0 = VPB_CLOCK/DATA_FREQ - 1;          /* TC0 Match Value 0 */


It's because the full-count of the timer is less than the total count by one
For the calculation of feedback value, the total count (VPB_CLOCK/DATA_FREQ) is applied.
Also, round bracket is recommended around (pclk/DATA_FREQ), to control the calculation order.

Tsuneo

Read-Only
Author
Tsuneo Chinzei
Posted
22-Sep-2011 19:57 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

Ah, the second parameter of USB_WriteEP() takes a buffer, not a value.

uint32_t feedback_value;
feedback_value = ((current_timer_count - last_timer_count) << 14) / (VPB_CLOCK/DATA_FREQ);
USB_WriteEP( 0x83, &feedback_value, 3 );

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
23-Sep-2011 02:35 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

>current_timer_count - last_timer_count

You have not explain why you have wrote this, I not sure how to read Timer and the examples don't have any values like the above, so if you could explain more it would help. Was the main.c I wrote correct of wrong?

Read-Only
Author
Tsuneo Chinzei
Posted
24-Sep-2011 06:58 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

On the startup section of the main(), just enable Timer1 on the default setting.

demo.c

/* Main Program */

int main (void) {
  ...
  ...
  /* Setup Timer Counter 0 Interrupt */
  VICVectAddr4 = (unsigned long)tc0_isr;    /* TC0 Interrupt -> Vector 4   */
  VICVectCntl4 = 0x02;                      /* TC0 Interrupt -> Priority 2 */
  VICIntEnable = 1 << 4;                    /* Enable TC0 Interrupt */

  /* Setup Timer1 for rate feedback */
  T1TCR = 1;                                /* TC1 Enable */

  lcd_init();
  ...

Here is mods for USB_SOF_Event(). For rate feedback, the extra code (in red) is inserted

usbuser.c

/*
 *  USB Start of Frame Event Callback
 *   Called automatically on USB Start of Frame Event
 */

DWORD last_timer_count;

#if USB_SOF_EVENT
void USB_SOF_Event (void) {
  DWORD current_timer_count;
  DWORD feedback_value;
                                                // feedback
  current_timer_count = T1TC;                   // capture current SOF timing on the Timer1
  if ( USB_AltSetting[1] == 1 ) {               // When interface 1 / alt 1 is enabled,
                                                // calculate master/SOF frequency ratio in 10.10 (10.14) format
    feedback_value = ((current_timer_count - last_timer_count) << 14) / (VPB_CLOCK/DATA_FREQ);
                                                // and send it to the feedback IN EP
    USB_WriteEP( 0x83, (BYTE*)&feedback_value, 3 );
  }
  last_timer_count = current_timer_count;       // update the last SOF timing

#if USB_DMA == 0
  ...

> current_timer_count - last_timer_count

This subtraction calculates SOF interval, on the tick of PCLK

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
24-Sep-2011 23:20 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

My friend come down and we test with his board, but the code is different.

So we make modifaction to his code, it's working but I am not sure if I have done it yet.

Was I supposed to change the Timer to 1 here

/*
 * Timer Counter 0 Interrupt Service Routine
 *   executed each 31.25us (32kHz frequency)
 */

void TIMER1_IRQHandler(void){

if (DataRun) {                            /* Data Stream is running */
    val = DataBuf[DataOut];                 /* Get Audio Sample */
    cnt = (DataIn - DataOut) & (B_S - 1);   /* Buffer Data Count */
    if (cnt == (B_S - P_C*P_S)) {           /* Too much Data in Buffer */
      DataOut++;                            /* Skip one Sample */

Unsure about if current_timer_count = LPC_TIM1->TCR timer control register is right or not? or should it be LPC_TIM1->CCR the capture control register?

uint32_t last_timer_count;

#if USB_SOF_EVENT
void USB_SOF_Event (void) {
uint32_t current_timer_count;
  uint32_t feedback_value;
  uint32_t pclk;
                                                // feedback
  current_timer_count = LPC_TIM1->TCR;                   // capture current SOF timing on the Timer1
  if ( USB_AltSetting[1] == 1 ) {               // When interface 1 / alt 1 is enabled,
                                                // calculate master/SOF frequency ratio in 10.10 (10.14) format
    feedback_value = ((current_timer_count - last_timer_count) << 14) / (pclk/DATA_FREQ);
                                                // and send it to the feedback IN EP
    USB_WriteEP( 0x83, (uint8_t *)&feedback_value, 3 );
  }
  last_timer_count = current_timer_count;       // update the last SOF timing
#if USB_DMA == 0

LPC_TIM1->MR0 = pclk/DATA_FREQ;   /* TC0 Match Value 0 */
  LPC_TIM1->MCR = 3;                                    /* TCO Interrupt and Reset on MR0 */
  LPC_TIM1->TCR = 1;                                    /* TC0 Enable */
  NVIC_EnableIRQ(TIMER1_IRQn);

/* Setup Timer1 for rate feedback */
  //T1TCR = 1;                                /* TC1 Enable */
  LPC_SC->PCONP |= 1 << 2;     // Power on Timer'
  //LPC_TIM1->TCR = 1;

Ok thanks for any help as I say code is different to my board.

Read-Only
Author
usbtom usbtom
Posted
24-Sep-2011 23:43 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

We can not figure out how to increase the isoch tranfer size it's still 640, have to do all manaul with his board no easy configwizard

/* Audio Definitions */
#define DATA_FREQ 32000                 /* Audio Data Frequency */
#define P_S       32                    /* Packet Size */
#if USB_DMA
#define P_C       4                     /* Packet Count */
#else
#define P_C       1                     /* Packet Count */
#endif
#define B_S       (8*P_C*P_S)           /* Buffer Size */
/* USB RAM Definitions */
#define USB_RAM_ADR     0x20080000  /* USB RAM Start Address */
#define USB_RAM_SZ      0x00004000  /* USB RAM Size (4kB) */

/* DMA Endpoint Descriptors */
#define DD_NISO_CNT             16  /* Non-Iso EP DMA Descr. Count (max. 32) */
#define DD_ISO_CNT               8  /* Iso EP DMA Descriptor Count (max. 32) */
#define DD_NISO_SZ    (DD_NISO_CNT * 16)    /* Non-Iso DMA Descr. Size */
#define DD_ISO_SZ     (DD_ISO_CNT  * 20)    /* Iso DMA Descriptor Size */
#define DD_NISO_ADR   (USB_RAM_ADR + 128)   /* Non-Iso DMA Descr. Address */
#define DD_ISO_ADR    (DD_NISO_ADR + DD_NISO_SZ) /* Iso DMA Descr. Address */
#define DD_SZ                 (128 + DD_NISO_SZ + DD_ISO_SZ) /* Descr. Size */

/* DMA Buffer Memory Definitions */
#define DMA_BUF_ADR   (USB_RAM_ADR + DD_SZ) /* DMA Buffer Start Address */
#define DMA_BUF_SZ    (USB_RAM_SZ  - DD_SZ) /* DMA Buffer Size */

#if USB_DMA


#pragma arm section zidata = "USB_RAM" uint32_t UDCA[USB_EP_NUM]; /* UDCA in USB RAM */
uint32_t DD_NISO_Mem[4*DD_NISO_CNT]; /* Non-Iso DMA Descriptor Memory */ uint32_t DD_ISO_Mem [5*DD_ISO_CNT]; /* Iso DMA Descriptor Memory */ #pragma arm section zidata uint32_t udca[USB_EP_NUM]; /* UDCA saved values */
uint32_t DDMemMap[2]; /* DMA Descriptor Memory Usage */
#endif
#if USB_DMA
uint32_t *InfoBuf = (uint32_t *)(DMA_BUF_ADR);
short *DataBuf = (short *)(DMA_BUF_ADR + 4*P_C);
#else
uint32_t InfoBuf[P_C];
short DataBuf[B_S];                         /* Data Buffer */
#endif

Not sure where to make the modification here, am I limited to a 640 transfer? ok thanks.

I check and it was TCR timer control register I needed so the above posted post code above was right then?

Read-Only
Author
Tsuneo Chinzei
Posted
25-Sep-2011 03:00 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

> Was I supposed to change the Timer to 1 here

Leave the Timer0 code alone.
You don't need to touch to Timer0 code at all.

Timer0 divides PCLK to make sampling frequency for DAC.
Timer1 counts SOF interval with SOF interrupt, independently from Timer0.

> We can not figure out how to increase the isoch tranfer size

What do you mean?
The example has these features,
- 32kHz sampling
- single channel (monaural)
- 16bits PCM

These feature determines the packet size on each USB frame, and transfer size, after all.
Windows binds 10 packets into single "transfer".

Do you want to change sampling frequency, stereo or 24bits?

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
25-Sep-2011 15:21 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

we have try changing bSubFrameSize 0x03 and WBVAL to 96 and it won't work. I want to send more than 640 bytes, data
3 * 32 = 96 so 10 * 96 = 960 so I would like the isoch tranfer to be 960 instead of 640, is this possible. Only want 16 bit resolution and mono.

thanks.

Read-Only
Author
Tsuneo Chinzei
Posted
26-Sep-2011 06:52 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

> Only want 16 bit resolution and mono.

Increase the sampling frequency from 32kHz to 48kHz.
And then, you'll get transfer size of 960 bytes.

Set the sampling frequency
- tSamFreq field of the Type I Format descriptor
- DATA_FREQ macro (demo.h)

As the packet size increases, you have to touch to these parameters, too.
- wMaxPacketSize of the endpoint descriptor
- P_S macro (demo.h)

usbdesc.c

/* Audio Type I Format */
  AUDIO_FORMAT_TYPE_I_DESC_SZ(1),       /* bLength */
  AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_STREAMING_FORMAT_TYPE,          /* bDescriptorSubtype */
  AUDIO_FORMAT_TYPE_I,                  /* bFormatType */
  0x01,                                 /* bNrChannels */
  0x02,                                 /* bSubFrameSize */
  16,                                   /* bBitResolution */
  0x01,                                 /* bSamFreqType */
  B3VAL(32000),                         /* tSamFreq */       // <----- B3VAL(48000)
/* Endpoint - Standard Descriptor */
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_OUT(3),                  /* bEndpointAddress */
  //USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  USB_ENDPOINT_TYPE_ISOCHRONOUS | USB_ENDPOINT_SYNC_ASYNCHRONOUS,
  WBVAL(66),                            /* wMaxPacketSize */ // <----- WBVAL(98)
  0x01,                                 /* bInterval */
  0x00,                                 /* bRefresh */
  0x83,                                 /* bSynchAddress */
demo.h
/* Audio Definitions */
#define DATA_FREQ 32000                 /* Audio Data Frequency */ // <--- 48000
#define P_S       32                    /* Packet Size */          // <--- 48

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
27-Sep-2011 00:53 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

We did what you say and it no work?

AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
  AUDIO_STREAMING_FORMAT_TYPE,          /* bDescriptorSubtype */
  AUDIO_FORMAT_TYPE_I,                  /* bFormatType */
  0x01,                                 /* bNrChannels */
  0x02,                                 /* bSubFrameSize */
  16,                                   /* bBitResolution */
  0x01,                                 /* bSamFreqType */
  B3VAL(48000),                         /* tSamFreq */
/* Endpoint - Standard Descriptor */
  AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
  USB_ENDPOINT_OUT(3),                  /* bEndpointAddress */
  //USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* bmAttributes */
  0x05,
  WBVAL(98),                            /* wMaxPacketSize */
  0x01,                                 /* bInterval */
  0x00,                                 /* bRefresh */
  0x83,                                 /* bSynchAddress */


/* Audio Definitions */
#define DATA_FREQ 48000                 /* Audio Data Frequency */
#define P_S       48                    /* Packet Size */
#if USB_DMA
#define P_C       4                     /* Packet Count */
#else
#define P_C       1                     /* Packet Count */
#endif
#define B_S       (8*P_C*P_S)           /* Buffer Size */

Read-Only
Author
Tsuneo Chinzei
Posted
28-Sep-2011 07:37 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

> We did what you say and it no work?

Hmmm..
I tested it on my MCB2300, and surely the board doesn't play any sound.
But on a Hardware USB analyzer, everything works fine.
- The device enumerates successfully
- 96 bytes isoc OUT transactions on every frame,
- 3 bytes feedback, which holds around 96 in 10.14 format (ex. 0x0C0041) on every 8 frames

Maybe the buffering and DAC part of the code require more retouch.
I'm busy today, so it takes for a while to look into the problem.
Meanwhile, check these code on your side, too.

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
29-Sep-2011 13:45 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

we seem to be getting some unsuccessful tranfers as well, do you know how to fix.

  URB Isoch Transfer failed
Device Object   0000008e
Driver Object   usbccgp

URB Function    URB_FUNCTION_ISOCH_TRANSFER
URB Status      USBD_STATUS_ISOCH_REQUEST_FAILED

Endpoint 83h    3 In, Isochronous


Start Frame     4598208
Number of Packets       1
Error Count     1
Read-Only
Author
Tsuneo Chinzei
Posted
30-Sep-2011 03:43 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

Found it.

The buffering part of the code expects the buffer size, B_S (ie. P_S), as a number of power of 2, like 2, 4, 8, 16, 32, 64, ...
The code abuses "mask" method to keep the buffer indices (DataIn/DataOut) within the array range. For example,

    DataIn += P_S;                          /* Update Data In Index */
    DataIn &= B_S - 1;                      /* Adjust Data In Index */


As we sets P_S to 48, not a number of power of 2, this method failed.
Rewrite the buffering code, so that it accept ANY number.

usbuser.c

void USB_SOF_Event (void) {
  DWORD cnt;
  ...
  ...
#if USB_DMA == 0
  if (USB_ReadEP(0x03, (BYTE *)&DataBuf[DataIn])) {
    /* Data Available */
    DataIn += P_S;                          /* Update Data In Index */
//    DataIn &= B_S - 1;                      /* Adjust Data In Index */
    if ( DataIn >= B_S ) {
      DataIn -= B_S;
    }
//    if (((DataIn - DataOut) & (B_S - 1)) == (B_S/2)) {
    if ( DataIn >= DataOut ) {
      cnt = DataIn - DataOut;
    } else {
      cnt = B_S + DataIn - DataOut;
    }
    if ( cnt == (B_S/2)) {
      DataRun = 1;                          /* Data Stream running */
    }
  } else {
    /* No Data */
    DataRun  = 0;                           /* Data Stream not running */
    DataOut  = DataIn;                      /* Initialize Data Indexes */
  }
#endif
}
#endif


void USB_EndPoint3 (DWORD event) {
#if USB_DMA
  USB_DMA_DESCRIPTOR DD;
  DWORD cnt;

  if (event & USB_EVT_OUT_DMA_EOT) {
    /* End of Transfer */
    if (USB_DMA_BufAdr(0x03) != ((DWORD)DataBuf + 2*DataIn)) {
      /* Data Available */
      DataIn += P_C*P_S;                    /* Update Data In Index */
//      DataIn &= B_S - 1;                    /* Adjust Data In Index */
      if ( DataIn >= B_S ) {
        DataIn -= B_S;
      }
//      if (((DataIn - DataOut) & (B_S - 1)) == (B_S/2)) {
    if ( DataIn >= DataOut ) {
      cnt = DataIn - DataOut;
    } else {
      cnt = B_S + DataIn - DataOut;
    }
    if ( cnt == (B_S/2)) {
        DataRun = 1;                        /* Data Stream running */
      }
    } else {
      /* No Data */
      DataRun = 0;                          /* Data Stream not running */
      DataOut = DataIn;                     /* Initialize Data Indexes */
    }
  }
demo.c


void tc0_isr (void) __irq { long val; DWORD cnt;
if (DataRun) { /* Data Stream is running */ val = DataBuf[DataOut]; /* Get Audio Sample */ // cnt = (DataIn - DataOut) & (B_S - 1); /* Buffer Data Count */ if ( DataIn >= DataOut ) { /* Buffer Data Count */ cnt = DataIn - DataOut; } else { cnt = B_S + DataIn - DataOut; } if (cnt == (B_S - P_C*P_S)) { /* Too much Data in Buffer */ DataOut++; /* Skip one Sample */ } if (cnt > (P_C*P_S)) { /* Still enough Data in Buffer */ DataOut++; /* Update Data Out Index */ } // DataOut &= B_S - 1; /* Adjust Buffer Out Index */ if ( DataOut >= B_S ) /* Adjust Buffer Out Index */ DataOut -= B_S;

Tsuneo

Read-Only
Author
usbtom usbtom
Posted
1-Oct-2011 18:25 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

Ok great it worked, but I still have this problem with the code I am writing. I am writing code much like a reverse effects guitar pedal. But it is usb sound card as well and plays windows sound in reverse and you can plug guitar in and mix with windows sounds. My problem is with the timer0 at the moment anything above 8000khz and I get skipping audio becuase the timer is ticking too fast for the audio I think. Do you have any ideas as to how I can fix the skipping audio at 32khz and above.

Here is the code.

/*
 * Timer Counter 0 Interrupt Service Routine
 *   executed each 31.25us (32kHz frequency)
 */

void TIMER0_IRQHandler(void)
{
  long  val;
  uint32_t cnt;
  unsigned short PlaySample;

  if (DataRun) {                            /* Data Stream is running */
    val = DataBuf[DataOut];                 /* Get Audio Sample */
   // cnt = (DataIn - DataOut) & (B_S - 1);   /* Buffer Data Count */
    if ( DataIn >= DataOut ) {              /* Buffer Data Count */
      cnt = DataIn - DataOut;
    } else {
      cnt = B_S + DataIn - DataOut;
    }
        if (cnt == (B_S - P_C*P_S)) {           /* Too much Data in Buffer */
      DataOut++;                            /* Skip one Sample */
    }
    if (cnt > (P_C*P_S)) {                  /* Still enough Data in Buffer */
      DataOut++;                            /* Update Data Out Index */
    }
   // DataOut &= B_S - 1;
   if ( DataOut >= B_S )                   /* Adjust Buffer Out Index */
      DataOut -= B_S;
    //if (val < 0) VUM -= val;                /* Accumulate Neg Value */
    //else         VUM += val;                /* Accumulate Pos Value */
    val  *= Volume;                         /* Apply Volume Level */
    val >>= 6;                             /* Adjust Value */
    val  += 0x8000;                         /* Add Bias */
    val  &= 0xFFFF;                         /* Mask Value */
  } else {
    val = 0x8000;                           /* DAC Middle Point */
  }

  if (Mute) {
    val = 0x8000;                           /* DAC Middle Point */
  }
  //if (Mute){
//semihost_powerdown();}

  /* ADAMGR: Inserting my May 30th reversing code here!!! */
  {
    static const unsigned int   BufferSize = 10 * 1024 ;
    static unsigned short Buffer[BufferSize];

    static int           Index = 0;
    static int           Direction = 1;
    static int           Playback = FALSE;
    static int           ChunkSize = BufferSize;

    unsigned short       ReadSample;

    /* Default PlaySample to the current sample from USB buffer. */
    PlaySample = val;



    /* Read out the sample from the buffer to be played back */
    if (Playback)
    {
        PlaySample = Buffer[Index];
    }

    /* Obtain current audio sample from the USB buffer. */
    ReadSample = (unsigned short)val;

    /* Record the sample into the buffer right where a space was freed up from the PlaySample read above */
    Buffer[Index] = ReadSample;

     /* Increment the buffer pointer */
    Index += Direction;

    /* Check to see if the chunk has been filled */
    if (Index < 0)
    {
        /* Now have a chunk to be played back */
        Playback = TRUE;
        /* Reverse the direction of playback and recording */
        Direction *= -1;//Direction;
        Index = 0;
    }
    else if (Index >= ChunkSize)



        {
       /* Now have a chunk to be played back */
        Playback = TRUE;
        /* Reverse the direction of playback and recording */
        Direction *= -1;//Direction;
        Index = ChunkSize - 1;
    }
  }

  LPC_DAC->DACR = PlaySample & 0xFFC0;      /* Set Speaker Output */

  //if ((Tick++ & 0x03FF) == 0) {             /* On every 1024th Tick */
    //get_potval();                           /* Get Potenciometer Value */
    if (VolCur == 0x8000) {                 /* Check for Minimum Level */
      Volume = 0;                           /* No Sound */
    } else {
      Volume = VolCur ;//* PotVal;             /* Chained Volume Level */
    }
    //val = VUM >> 20;                        /* Scale Accumulated Value */
    //VUM = 0;                                /* Clear VUM */
    //if (val > 7) val = 7;                   /* Limit Value */


  LPC_TIM0->IR = 1;                         /* Clear Interrupt Flag */

   }
Read-Only
Author
Usbtom tome
Posted
6-Oct-2011 00:02 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

Tsuneo,

I don't have debugger or fancy scope or a fancy jitter scope, or a hardware usb analyser, I am just guessing at this problem, I thought increasing the iso transfer might help, only going all the way down to 8000khz does. because the ticker is increased to I don't know above 60 us perhaps

Does anybody have any suggestion of what to do here. I know if I could separate the code and have two timers might work or if I could store the audio in memory

have a timer on the original code and then store this data in a big memory thing and then another timer on the other code that reads the memory.

but then would be more of a delay..

ideas anyone.

Read-Only
Author
Usbtom tom
Posted
6-Oct-2011 01:10 GMT
Toolset
ARM
New! RE: asynchronous examples?? documentation??

I think I got the answer anyway don't want to ruin this thread maybe you should delete the last couple of posts

use a ringbuffer and read and write in opposite directions.
DMA can only do one direction AFAIK (counting up) so you need to write a buffer in reverse direction in software and let the DMA do the playback part. You can use two buffers and switch them on the 'end-of-DMA' interrupt for example. You can also use a simple ticker interrupt and read and write a ringbuffer on each 'tick', again with opposite directions.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.