Main Page Data Structures File List Data Fields Globals Related Pages

# vs1001.cpp File Reference

`#include <stdlib.h>`
`#include <stdio.h>`
`#include "amd186.h"`
`#include "clib/hwapi.h"`
`#include "clib/rtos.h"`
`#include "misc.h"`
`#include "vs1001.h"`

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions
void | SCI_Write (unsigned data)
unsigned | SCI_Read ()
unsigned | SCI_ReadReg (int address)
void | SCI_WriteReg (int address, unsigned data)
void interrupt | DmaHandler (...)
| Interrupt handler for DMA channel terminal count.
bool | VS_IsPlaying ()
| Check asynchronous playback status.
void | VS_PlayMpegAsync (char *data, unsigned len, void(*function)(void *), void *param)
| Asynchronously play a block of MPEG data.
int | VS_PlayMpegSync (char *data, unsigned len)
| Play a block of MPEG Data, and wait for completion.
void | SDI_WriteZeros (unsigned length)
| Send a stream of zeros to the VS1001.
void | VS_Stop ()
| Stop playback of current stream.
void | VS_SetVolume (int left, int right)
| Set the output volume for both channels.
void | VS_GetMPEGHeader (unsigned long *header)
| Get MPEG Header information.
void | VS_SetClockFreq (long frequency)
| Set Clock frequency.
void | VS_SetBassBoost (bool onoff)
| Enable bass and treble enhancement (VS1001k only).
void | VS_SDITest ()
| Test SDI Interface - generate short beeps.
void | VS_SCITest ()
| Test SCI Interface - generate snapping sounds.
void | VS_Dump ()
| Dump all SCI register contents.
void | VS_Reset ()
| Initiate a software reset.
void | VS_Init ()
| Set up hardware resources for the VS1001 interface.
void | VS_Done ()
| Free all resources used by the VS1001 interface.
## Variables
int | lastVolLeft
int | lastVolRight
long | lastFrequency
bool | lastBassBoost
void interrupt(* | oldDmaHandler )(...)
void(* | callbackFunction )(void *)
void * | callbackParam

## Function Documentation

void interrupt DmaHandler | ( | ... |  | ) | `[static]`

| Interrupt handler for DMA channel terminal count. This handler will call the user specified callback function, after the playback of a data block has finished. Definition at line 109 of file vs1001.cpp. References callbackFunction, callbackParam, and oldDmaHandler. Referenced by VS_Init().

unsigned SCI_Read | ( |  | ) | `[static]`

| Definition at line 63 of file vs1001.cpp. References AMD_GetPio(), AMD_PioHigh(), AMD_PioLow(), SCI_SCLKPIO, and SCI_SOPIO. Referenced by SCI_ReadReg().

unsigned SCI_ReadReg | ( | int | address | ) | `[static]`

| Definition at line 76 of file vs1001.cpp. References AMD_EnableDrq(), AMD_PioHigh(), AMD_PioLow(), SCI_Read(), SCI_SCLKPIO, SCI_Write(), SCI_XCSPIO, SDI_DMACHANNEL, and usleep(). Referenced by VS_Dump(), VS_GetMPEGHeader(), VS_Reset(), and VS_SetBassBoost().

void SCI_Write | ( | unsigned | data | ) | `[static]`

| Definition at line 50 of file vs1001.cpp. References AMD_PioHigh(), AMD_PioLow(), SCI_SCLKPIO, and SCI_SIPIO. Referenced by SCI_ReadReg(), and SCI_WriteReg().

void SCI_WriteReg | ( | int | address,
|  | unsigned | data
| ) | `[static]`

| Definition at line 90 of file vs1001.cpp. References AMD_EnableDrq(), AMD_PioHigh(), AMD_PioLow(), SCI_SCLKPIO, SCI_Write(), SCI_XCSPIO, SDI_DMACHANNEL, and usleep(). Referenced by VS_Reset(), VS_SetBassBoost(), VS_SetClockFreq(), and VS_SetVolume().

void SDI_WriteZeros | ( | unsigned | length | ) |

  | Send a stream of zeros to the VS1001. This function can be used to flush the internal bitstream buffer of the 1001. Parameters:
  length | number of zeros to write.
Definition at line 200 of file vs1001.cpp. References VS_PlayMpegSync(). Referenced by VS_Reset().

void VS_Done | ( |  | ) |

| Free all resources used by the VS1001 interface. Definition at line 417 of file vs1001.cpp. References oldDmaHandler, and VS_Stop(). Referenced by main().

void VS_Dump | ( |  | ) |

| Dump all SCI register contents. Definition at line 338 of file vs1001.cpp. References SCI_A1ADDR, SCI_A1CTRL0, SCI_A1CTRL1, SCI_A1CTRL2, SCI_AUDATA, SCI_CLOCKF, SCI_DECTIME, SCI_HDAT0, SCI_HDAT1, SCI_MODE, SCI_ReadReg(), SCI_STATUS, and SCI_VOL.

void VS_GetMPEGHeader | ( | unsigned long * | header | ) |

  | Get MPEG Header information. Returns the current header for the stream being decoded. Right after reset, 0 will be returned, indicating that no data has been found yet. Parameters:
  pointer | to MpegHeader structure to fill out
Definition at line 250 of file vs1001.cpp. References SCI_HDAT0, SCI_HDAT1, and SCI_ReadReg().

void VS_Init | ( |  | ) |

| Set up hardware resources for the VS1001 interface. Definition at line 384 of file vs1001.cpp. References DmaHandler(), lastBassBoost, lastFrequency, lastVolLeft, lastVolRight, oldDmaHandler, pfe_enable_bus(), pfe_enable_pcs(), pfe_enable_pio(), PIO_IPU, PIO_O0, PIO_O1, SCI_SCLKPIO, SCI_SIPIO, SCI_SOPIO, SCI_XCSPIO, SDI_DATAREG, VS_CLOCK, and VS_Reset(). Referenced by main().

bool VS_IsPlaying | ( |  | ) |

| Check asynchronous playback status. Returns: true if playing, false if stopped. Definition at line 122 of file vs1001.cpp. References AMD_GetDmaInfo(), DmaInfo::control, DCON_ST, and SDI_DMACHANNEL. Referenced by BUF_Play(), http_get(), and VS_PlayMpegSync().

void VS_PlayMpegAsync | ( | char * | data,
|  | unsigned | len,
|  | void(* | function)(void *),
|  | void * | param
| ) |

  | Asynchronously play a block of MPEG data. You can either specify a callback function, or poll the transfer status using VS_IsPlaying() Note: according to the VS1001 documentation, you should keep an eye on the data rate. If DREQ is either always asserted, or always inactive, the decoder most probably choked on some bad mpeg-stream. Parameters:
  data | Pointer to mpeg data
  len | Length of data block
  function | function to call after transfer has finished. May be NULL.
  param | user defined parameter that is passed to the callback function. May be NULL.
Definition at line 149 of file vs1001.cpp. References AMD_EnableDrq(), AMD_StartDma(), callbackFunction, callbackParam, DmaInfo::control, DCON_DSYNC, DCON_INT, DCON_SINC, DCON_SMIO, DCON_TC, DmaInfo::dstPort, DmaInfo::length, SDI_DATAREG, SDI_DMACHANNEL, and DmaInfo::srcMem. Referenced by BUF_Play(), http_get(), and VS_PlayMpegSync().

int VS_PlayMpegSync | ( | char * | data,
|  | unsigned | len
| ) |

  | Play a block of MPEG Data, and wait for completion. Note: you should call VS_Reset after a failed transfer. Most probably the VS1001 choked on some bad mpeg stream, and will continue to work after an reset. Parameters:
  data | Pointer to mpeg data
  len | Length of data block
Todo: (re)implement timeout checking, using RTX_Get_System_Ticks() Definition at line 184 of file vs1001.cpp. References VS_IsPlaying(), VS_OK, and VS_PlayMpegAsync(). Referenced by SDI_WriteZeros(), and VS_SDITest().

void VS_Reset | ( |  | ) |

| Initiate a software reset. All previous VS1001 settings are automatically restored by this function. Definition at line 362 of file vs1001.cpp. References AMD_EnableDrq(), lastBassBoost, lastFrequency, lastVolLeft, lastVolRight, SCI_MODE, SCI_ReadReg(), SCI_WriteReg(), SDI_DMACHANNEL, SDI_WriteZeros(), SM_RESET, usleep(), VS_SetBassBoost(), VS_SetClockFreq(), and VS_SetVolume(). Referenced by http_get(), and VS_Init().

void VS_SCITest | ( |  | ) |

| Test SCI Interface - generate snapping sounds. Definition at line 320 of file vs1001.cpp. References RTX_Sleep_Time(), and VS_SetVolume().

void VS_SDITest | ( |  | ) |

| Test SDI Interface - generate short beeps. Note: the test will be very loud. Do not keep your headphones on while conducting this test. Definition at line 299 of file vs1001.cpp. References RTX_Sleep_Time(), and VS_PlayMpegSync().

void VS_SetBassBoost | ( | bool | onoff | ) |

  | Enable bass and treble enhancement (VS1001k only). Parameters:
  onoff | enable or disable enhancements
Definition at line 284 of file vs1001.cpp. References lastBassBoost, SCI_MODE, SCI_ReadReg(), SCI_WriteReg(), and SM_BASS. Referenced by VS_Reset().

void VS_SetClockFreq | ( | long | frequency | ) |

  | Set Clock frequency. This function needs to be called if the chip is running at something else than 24.576MHz. The Clock frequency may be between 0 .. 65.534 MHz, although hardware limits the highest possible speed. Note: the clock doubler is activated for frequencies <18,432 MHz. This should be reasonable for all operation conditions. Parameters:
  frequency | Clock frequency in Hz
Definition at line 269 of file vs1001.cpp. References lastFrequency, SCI_CLOCKF, and SCI_WriteReg(). Referenced by VS_Reset().

void VS_SetVolume | ( | int | left,
|  | int | right
| ) |

  | Set the output volume for both channels. 255 is the maximum volume, 0 the minimum. Note that a volume setting of 0 will enter the analog powersave mode, and causes a slight snapping sound. If you want to avoid this, set the volume to 1 instead of 0. Parameters:
  left | left volume 0..255
  right | right volume 0..255
Definition at line 234 of file vs1001.cpp. References lastVolLeft, lastVolRight, SCI_VOL, and SCI_WriteReg(). Referenced by VS_Reset(), and VS_SCITest().

void VS_Stop | ( |  | ) |

| Stop playback of current stream. Definition at line 217 of file vs1001.cpp. References AMD_StopDma(), and SDI_DMACHANNEL. Referenced by VS_Done().

## Variable Documentation

void(* callbackFunction)(void *)`[static]`

| Definition at line 46 of file vs1001.cpp. Referenced by DmaHandler(), and VS_PlayMpegAsync().

void* callbackParam`[static]`

| Definition at line 47 of file vs1001.cpp. Referenced by DmaHandler(), and VS_PlayMpegAsync().

bool lastBassBoost`[static]`

| Definition at line 38 of file vs1001.cpp. Referenced by VS_Init(), VS_Reset(), and VS_SetBassBoost().

long lastFrequency`[static]`

| Definition at line 37 of file vs1001.cpp. Referenced by VS_Init(), VS_Reset(), and VS_SetClockFreq().

int lastVolLeft`[static]`

| Definition at line 36 of file vs1001.cpp. Referenced by VS_Init(), VS_Reset(), and VS_SetVolume().

int lastVolRight`[static]`

| Definition at line 36 of file vs1001.cpp. Referenced by VS_Init(), VS_Reset(), and VS_SetVolume().

void interrupt(* oldDmaHandler)(...)`[static]`

| Definition at line 42 of file vs1001.cpp. Referenced by DmaHandler(), VS_Done(), and VS_Init().