Microchip® Advanced Software Framework

cs2200.h File Reference
#include <avr32/io.h>
#include "compiler.h"
#include "conf_cs2200.h"

Macros

#define _32_BITS_RATIO(frequency, fosc)   ((int)(((float)frequency/(fosc))*(1<<20)))
 Build the 32-bits ratio constant to be loaded in the CS2200 to make the desired frequency. More...
 
#define CS2200_TWI_ADDR   (0x9C >> 1)
 
#define PPM(value, ppm)   ( ((int)( (long long)value*(ppm)/1000000) ) )
 Compute the PPM of a number. More...
 
#define PPM_ADD(value, ppm)   ( ((int)(value + (long long)value*(ppm)/1000000)) )
 Add x PPM to a value. More...
 
#define PPM_SUB(value, ppm)   ( ((int)(value - (long long)value*(ppm)/1000000)) )
 Remove x PPM to a value. More...
 
Communication Interfaces
#define CS2200_INTERFACE_SPI   1
 
#define CS2200_INTERFACE_TWI   2
 
Macro Constructors

These macros create inline functions to access the cs2200 registers.

#define CS2200_READ(name)
 
#define CS2200_READ1(name)
 
#define CS2200_READ2(name)
 
#define CS2200_READ4(name)
 
#define CS2200_WRITE(name)
 
#define CS2200_WRITE1(name)
 
#define CS2200_WRITE2(name)
 
#define CS2200_WRITE4(name)
 
Register Addresses
#define CS2200_REG_TEST_MODE_1_ADDR   0x00
 
#define CS2200_REG_DEVICE_ID_ADDR   0x01
 
#define CS2200_REG_DEVICE_CTRL_ADDR   0x02
 
#define CS2200_REG_DEVICE_CFG_1_ADDR   0x03
 
#define CS2200_REG_GLOBAL_CFG_ADDR   0x05
 
#define CS2200_REG_32_BITS_RATIO_ADDR   0x06
 
#define CS2200_REG_LSW_RATIO_ADDR   0x08
 
#define CS2200_REG_LSB_RATIO_ADDR   0x09
 
#define CS2200_REG_FUNCT_CFG_1_ADDR   0x16
 
#define CS2200_REG_FUNCT_CFG_2_ADDR   0x17
 
#define CS2200_REG_TEST_MODE_2_ADDR   0x77
 

Functions

void cs2200_enter_power_down_mode (void)
 Enter power down mode and stop twi comms. More...
 
void cs2200_enter_test_mode (void)
 Enter into the test mode. More...
 
void cs2200_freq_clk_adjust (uint16_t lsw_ratio)
 Function used to adjust the CLK_OUT frequency (LSW only). More...
 
void cs2200_freq_clk_out (uint32_t ratio)
 Function used to program the CLK_OUT frequency. More...
 
void cs2200_leave_power_down_mode (void)
 Leave power down mode and twi comms can be restarted. More...
 
void cs2200_leave_test_mode (void)
 Leave the test mode. More...
 
void cs2200_read (uint8_t address, void *buffer, uint8_t len)
 Reads data from the CS2200 chip. More...
 
 CS2200_READ1 (DEVICE_ID)
 
 CS2200_READ1 (DEVICE_CTRL)
 
 CS2200_READ1 (DEVICE_CFG_1)
 
 CS2200_READ1 (GLOBAL_CFG)
 
 CS2200_READ1 (FUNCT_CFG_1)
 
 CS2200_READ1 (FUNCT_CFG_2)
 
 CS2200_READ4 (32_BITS_RATIO)
 
void cs2200_set_new_freq_clk_out (uint32_t ratio)
 Function used to program the CLK_OUT frequency and wait that the PLL is locked. More...
 
bool cs2200_setup (uint32_t out_freq, uint32_t fosc)
 Function used to initialize the chip and communication interface. More...
 
void cs2200_switch_off (void)
 
void cs2200_switch_on (void)
 
void cs2200_write (uint8_t address, const void *buffer, uint8_t len)
 Writes data into the CS2200 chip. More...
 
 CS2200_WRITE1 (DEVICE_CTRL)
 
 CS2200_WRITE1 (DEVICE_CFG_1)
 
 CS2200_WRITE1 (GLOBAL_CFG)
 
 CS2200_WRITE1 (LSB_RATIO)
 
 CS2200_WRITE1 (FUNCT_CFG_1)
 
 CS2200_WRITE1 (FUNCT_CFG_2)
 
 CS2200_WRITE1 (TEST_MODE_1)
 
 CS2200_WRITE1 (TEST_MODE_2)
 
 CS2200_WRITE4 (32_BITS_RATIO)
 
int cs2200_write_ex (uint8_t address, const void *buffer, uint8_t len)
 Writes data into the CS2200 chip using the non blocking release of the TWI driver. More...
 

#define _32_BITS_RATIO (   frequency,
  fosc 
)    ((int)(((float)frequency/(fosc))*(1<<20)))

Build the 32-bits ratio constant to be loaded in the CS2200 to make the desired frequency.

Referenced by aic23b_codec_setup(), cs2200_setup(), usb_stream_input(), and usb_stream_resync().

#define CS2200_INTERFACE_SPI   1
#define CS2200_INTERFACE_TWI   2
#define CS2200_READ (   name)
Value:
static inline void CS2200_READ_##name(void *data, size_t len) \
{ \
cs2200_read(CS2200_REG_##name##_ADDR, data, len); \
}
void cs2200_read(uint8_t address, void *buffer, uint8_t len)
Reads data from the CS2200 chip.
Definition: cs2200.c:181
#define CS2200_READ1 (   name)
Value:
static inline uint8_t CS2200_READ_##name(void) \
{ \
uint8_t data; \
cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \
return data; \
}
void cs2200_read(uint8_t address, void *buffer, uint8_t len)
Reads data from the CS2200 chip.
Definition: cs2200.c:181
#define CS2200_READ2 (   name)
Value:
static inline uint16_t CS2200_READ_##name(void) \
{ \
uint16_t data; \
cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \
return data; \
}
void cs2200_read(uint8_t address, void *buffer, uint8_t len)
Reads data from the CS2200 chip.
Definition: cs2200.c:181
#define CS2200_READ4 (   name)
Value:
static inline uint32_t CS2200_READ_##name(void) \
{ \
uint32_t data; \
cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \
return data; \
}
void cs2200_read(uint8_t address, void *buffer, uint8_t len)
Reads data from the CS2200 chip.
Definition: cs2200.c:181
#define CS2200_REG_32_BITS_RATIO_ADDR   0x06
#define CS2200_REG_DEVICE_CFG_1_ADDR   0x03
#define CS2200_REG_DEVICE_CTRL_ADDR   0x02
#define CS2200_REG_DEVICE_ID_ADDR   0x01
#define CS2200_REG_FUNCT_CFG_1_ADDR   0x16
#define CS2200_REG_FUNCT_CFG_2_ADDR   0x17
#define CS2200_REG_GLOBAL_CFG_ADDR   0x05
#define CS2200_REG_LSB_RATIO_ADDR   0x09
#define CS2200_REG_LSW_RATIO_ADDR   0x08

Referenced by cs2200_freq_clk_adjust().

#define CS2200_REG_TEST_MODE_1_ADDR   0x00
#define CS2200_REG_TEST_MODE_2_ADDR   0x77
#define CS2200_TWI_ADDR   (0x9C >> 1)
#define CS2200_WRITE (   name)
Value:
static inline void CS2200_WRITE_##name(const void *data, size_t len) \
{ \
cs2200_write(CS2200_REG_##name##_ADDR, data, len); \
}
void cs2200_write(uint8_t address, const void *buffer, uint8_t len)
Writes data into the CS2200 chip.
Definition: cs2200.c:197
#define CS2200_WRITE1 (   name)
Value:
static inline void CS2200_WRITE_##name(uint8_t data) \
{ \
cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \
}
void cs2200_write(uint8_t address, const void *buffer, uint8_t len)
Writes data into the CS2200 chip.
Definition: cs2200.c:197
#define CS2200_WRITE2 (   name)
Value:
static inline void CS2200_WRITE_##name(uint16_t data) \
{ \
cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \
}
void cs2200_write(uint8_t address, const void *buffer, uint8_t len)
Writes data into the CS2200 chip.
Definition: cs2200.c:197
#define CS2200_WRITE4 (   name)
Value:
static inline void CS2200_WRITE_##name(uint32_t data) \
{ \
cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \
}
void cs2200_write(uint8_t address, const void *buffer, uint8_t len)
Writes data into the CS2200 chip.
Definition: cs2200.c:197
#define PPM (   value,
  ppm 
)    ( ((int)( (long long)value*(ppm)/1000000) ) )

Compute the PPM of a number.

#define PPM_ADD (   value,
  ppm 
)    ( ((int)(value + (long long)value*(ppm)/1000000)) )

Add x PPM to a value.

#define PPM_SUB (   value,
  ppm 
)    ( ((int)(value - (long long)value*(ppm)/1000000)) )

Remove x PPM to a value.

void cs2200_enter_power_down_mode ( void  )

Enter power down mode and stop twi comms.

void cs2200_enter_test_mode ( void  )

Enter into the test mode.

Referenced by cs2200_setup().

void cs2200_freq_clk_adjust ( uint16_t  lsw_ratio)

Function used to adjust the CLK_OUT frequency (LSW only).

References CS2200_REG_LSW_RATIO_ADDR, and cs2200_write_ex().

Referenced by usb_stream_resync().

void cs2200_freq_clk_out ( uint32_t  ratio)

Function used to program the CLK_OUT frequency.

Referenced by aic23b_codec_setup(), and usb_stream_input().

void cs2200_leave_power_down_mode ( void  )

Leave power down mode and twi comms can be restarted.

void cs2200_leave_test_mode ( void  )

Leave the test mode.

void cs2200_read ( uint8_t  address,
void *  buffer,
uint8_t  len 
)

Reads data from the CS2200 chip.

TWI chip address to communicate with.

Register address/commands inside the slave chip.

Length of the TWI data address segment (1-3 bytes).

Where to find the data to be written.

How many bytes do we want to write.

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, CS2200_TWI, CS2200_TWI_SLAVE_ADDRESS, twi_package_t::length, twi_master_read(), and TWI_SUCCESS.

CS2200_READ1 ( DEVICE_ID  )
CS2200_READ1 ( DEVICE_CTRL  )
CS2200_READ1 ( DEVICE_CFG_1  )
CS2200_READ1 ( GLOBAL_CFG  )
CS2200_READ1 ( FUNCT_CFG_1  )
CS2200_READ1 ( FUNCT_CFG_2  )
CS2200_READ4 ( 32_BITS_RATIO  )
void cs2200_set_new_freq_clk_out ( uint32_t  ratio)

Function used to program the CLK_OUT frequency and wait that the PLL is locked.

bool cs2200_setup ( uint32_t  out_freq,
uint32_t  fosc 
)

Function used to initialize the chip and communication interface.

References _32_BITS_RATIO, CS2200_DEVICE_ID_REG_MASK, CS2200_DEVICE_ID_REG_OFFSET, cs2200_enter_test_mode(), CS2200_EXPECTED_DEVICE_ID, and CS2200_NB_TRIES.

Referenced by main().

void cs2200_switch_off ( void  )
void cs2200_switch_on ( void  )
void cs2200_write ( uint8_t  address,
const void *  buffer,
uint8_t  len 
)

Writes data into the CS2200 chip.

TWI chip address to communicate with.

Register address/commands inside the slave chip + auto increment.

Length of the TWI data address segment (1-3 bytes).

Where to find the data to be written.

How many bytes do we want to write.

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, CS2200_TWI, CS2200_TWI_SLAVE_ADDRESS, twi_package_t::length, twi_master_write(), and TWI_SUCCESS.

CS2200_WRITE1 ( DEVICE_CTRL  )
CS2200_WRITE1 ( DEVICE_CFG_1  )
CS2200_WRITE1 ( GLOBAL_CFG  )
CS2200_WRITE1 ( LSB_RATIO  )
CS2200_WRITE1 ( FUNCT_CFG_1  )
CS2200_WRITE1 ( FUNCT_CFG_2  )
CS2200_WRITE1 ( TEST_MODE_1  )
CS2200_WRITE1 ( TEST_MODE_2  )
CS2200_WRITE4 ( 32_BITS_RATIO  )
int cs2200_write_ex ( uint8_t  address,
const void *  buffer,
uint8_t  len 
)

Writes data into the CS2200 chip using the non blocking release of the TWI driver.

TWI chip address to communicate with.

Register address/commands inside the slave chip + auto increment.

Length of the TWI data address segment (1-3 bytes).

Where to find the data to be written.

How many bytes do we want to write.

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, CS2200_TWI, CS2200_TWI_SLAVE_ADDRESS, twi_package_t::length, and twi_master_write_ex().

Referenced by cs2200_freq_clk_adjust().