cs2200.h File Reference


Detailed Description

Driver for the Cirrus Logic CS2200 clock synthesizer.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file cs2200.h.

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

Go to the source code of this file.

Defines

#define _32_BITS_RATIO(frequency)   ((int)(((float)frequency/FOSC0)*(1<<20)))
 Build the 32-bits ratio constant to be loaded in the CS2200 to make the desired frequency.
#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.
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_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
#define CS2200_REG_TEST_MODE_1_ADDR   0x00
#define CS2200_REG_TEST_MODE_2_ADDR   0x77

Functions

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.
void cs2200_freq_clk_adjust (U16 lsw_ratio)
 Function used to adjust the CLK_OUT frequency (LSW only).
void cs2200_freq_clk_out (U32 ratio)
 Function used to program the CLK_OUT frequency.
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 (U8 address, void *buffer, U8 len)
 Reads data from the CS2200 chip.
 CS2200_READ1 (FUNCT_CFG_2)
 CS2200_READ1 (FUNCT_CFG_1)
 CS2200_READ1 (GLOBAL_CFG)
 CS2200_READ1 (DEVICE_CFG_1)
 CS2200_READ1 (DEVICE_CTRL)
 CS2200_READ1 (DEVICE_ID)
 CS2200_READ4 (32_BITS_RATIO)
void cs2200_set_new_freq_clk_out (U32 ratio)
 Function used to program the CLK_OUT frequency and wait that the PLL is locked.
Bool cs2200_setup (U32 out_freq)
 Function used to initialize the chip and communication interface.
void cs2200_switch_off (void)
void cs2200_switch_on (void)
void cs2200_write (U8 address, const void *buffer, U8 len)
 Writes data into the CS2200 chip.
 CS2200_WRITE1 (TEST_MODE_2)
 CS2200_WRITE1 (TEST_MODE_1)
 CS2200_WRITE1 (FUNCT_CFG_2)
 CS2200_WRITE1 (FUNCT_CFG_1)
 CS2200_WRITE1 (LSB_RATIO)
 CS2200_WRITE1 (GLOBAL_CFG)
 CS2200_WRITE1 (DEVICE_CFG_1)
 CS2200_WRITE1 (DEVICE_CTRL)
 CS2200_WRITE4 (32_BITS_RATIO)
int cs2200_write_ex (U8 address, const void *buffer, U8 len)
 Writes data into the CS2200 chip using the non blocking release of the TWI driver.


Define Documentation

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

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

Definition at line 64 of file cs2200.h.

Referenced by cs2200_setup(), and main().

#define CS2200_INTERFACE_SPI   1

Definition at line 59 of file cs2200.h.

#define CS2200_INTERFACE_TWI   2

Definition at line 60 of file cs2200.h.

#define CS2200_READ ( name   ) 

Value:

static inline void CS2200_READ_##name(void *data, size_t len)                  \
{                                                                              \
  cs2200_read(CS2200_REG_##name##_ADDR, data, len);                            \
}

Definition at line 143 of file cs2200.h.

#define CS2200_READ1 ( name   ) 

Value:

static inline U8 CS2200_READ_##name(void)                                      \
{                                                                              \
  U8 data;                                                                     \
  cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data));                  \
  return data;                                                                 \
}

Definition at line 149 of file cs2200.h.

#define CS2200_READ2 ( name   ) 

Value:

static inline U16 CS2200_READ_##name(void)                                     \
{                                                                              \
  U16 data;                                                                    \
  cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data));                  \
  return data;                                                                 \
}

Definition at line 157 of file cs2200.h.

#define CS2200_READ4 ( name   ) 

Value:

static inline U32 CS2200_READ_##name(void)                                     \
{                                                                              \
  U32 data;                                                                    \
  cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data));                  \
  return data;                                                                 \
}

Definition at line 165 of file cs2200.h.

#define CS2200_REG_32_BITS_RATIO_ADDR   0x06

Definition at line 206 of file cs2200.h.

#define CS2200_REG_DEVICE_CFG_1_ADDR   0x03

Definition at line 204 of file cs2200.h.

#define CS2200_REG_DEVICE_CTRL_ADDR   0x02

Definition at line 203 of file cs2200.h.

#define CS2200_REG_DEVICE_ID_ADDR   0x01

Definition at line 202 of file cs2200.h.

#define CS2200_REG_FUNCT_CFG_1_ADDR   0x16

Definition at line 209 of file cs2200.h.

#define CS2200_REG_FUNCT_CFG_2_ADDR   0x17

Definition at line 210 of file cs2200.h.

#define CS2200_REG_GLOBAL_CFG_ADDR   0x05

Definition at line 205 of file cs2200.h.

#define CS2200_REG_LSB_RATIO_ADDR   0x09

Definition at line 208 of file cs2200.h.

#define CS2200_REG_LSW_RATIO_ADDR   0x08

Definition at line 207 of file cs2200.h.

Referenced by cs2200_freq_clk_adjust().

#define CS2200_REG_TEST_MODE_1_ADDR   0x00

Definition at line 201 of file cs2200.h.

#define CS2200_REG_TEST_MODE_2_ADDR   0x77

Definition at line 211 of file cs2200.h.

#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);                           \
}

Definition at line 173 of file cs2200.h.

#define CS2200_WRITE1 ( name   ) 

Value:

static inline void CS2200_WRITE_##name(U8 data)                                \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data));                 \
}

Definition at line 179 of file cs2200.h.

#define CS2200_WRITE2 ( name   ) 

Value:

static inline void CS2200_WRITE_##name(U16 data)                               \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data));                 \
}

Definition at line 185 of file cs2200.h.

#define CS2200_WRITE4 ( name   ) 

Value:

static inline void CS2200_WRITE_##name(U32 data)                               \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data));                 \
}

Definition at line 191 of file cs2200.h.

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

Compute the PPM of a number.

Definition at line 67 of file cs2200.h.

Referenced by main().

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

Add x PPM to a value.

Definition at line 70 of file cs2200.h.

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

Remove x PPM to a value.

Definition at line 73 of file cs2200.h.


Function Documentation

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.

Definition at line 136 of file cs2200.c.

Referenced by cs2200_setup().

00137 {
00138   CS2200_WRITE_TEST_MODE_1(0x99); // Unlock
00139   CS2200_WRITE_TEST_MODE_2(0x80); // force_normal state
00140 }

void cs2200_freq_clk_adjust ( U16  lsw_ratio  ) 

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

Definition at line 156 of file cs2200.c.

References CS2200_REG_LSW_RATIO_ADDR, and cs2200_write_ex().

Referenced by main().

00157 {
00158   static U16 s_ratio;
00159   s_ratio=lsh_ratio;
00160   cs2200_write_ex(CS2200_REG_LSW_RATIO_ADDR, &s_ratio, sizeof(lsh_ratio));
00161 }

void cs2200_freq_clk_out ( U32  ratio  ) 

Function used to program the CLK_OUT frequency.

Definition at line 150 of file cs2200.c.

Referenced by main().

00151 {
00152   CS2200_WRITE_32_BITS_RATIO(ratio);
00153 }

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.

Definition at line 143 of file cs2200.c.

00144 {
00145   CS2200_WRITE_TEST_MODE_2(0x00); // test mode default setting
00146   CS2200_WRITE_TEST_MODE_1(0x00); // Lock
00147 }

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

Reads data from the CS2200 chip.

CS2200_READ1 ( FUNCT_CFG_2   ) 

CS2200_READ1 ( FUNCT_CFG_1   ) 

CS2200_READ1 ( GLOBAL_CFG   ) 

CS2200_READ1 ( DEVICE_CFG_1   ) 

CS2200_READ1 ( DEVICE_CTRL   ) 

CS2200_READ1 ( DEVICE_ID   ) 

CS2200_READ4 ( 32_BITS_RATIO   ) 

void cs2200_set_new_freq_clk_out ( U32  ratio  ) 

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

Bool cs2200_setup ( U32  out_freq  ) 

Function used to initialize the chip and communication interface.

Definition at line 98 of file cs2200.c.

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().

00099 {
00100   int device_id;
00101   int nb_tries = CS2200_NB_TRIES;
00102 
00103   do
00104   {
00105     device_id = (CS2200_READ_DEVICE_ID() & CS2200_DEVICE_ID_REG_MASK) >> CS2200_DEVICE_ID_REG_OFFSET;
00106   // Make sure the chip is functional.
00107   } while ((device_id != CS2200_EXPECTED_DEVICE_ID)
00108          && --nb_tries);
00109 
00110   // If number of tries is over, return an error.
00111   if (!nb_tries)
00112     return FALSE;
00113 
00114   // Freeze chip during the programmation
00115   CS2200_WRITE_GLOBAL_CFG(1<<3);
00116 
00117   CS2200_WRITE_DEVICE_CTRL(0x00); // AUX_OUT output driver enabled. CLK_OUT output driver enabled.
00118   CS2200_WRITE_DEVICE_CFG_1( 0 << 5 // Left-shift R-value by 0 (x 1).
00119                            | 0 << 1 // RefClk: is the source of the AUX_OUT signal
00120                            );
00121   CS2200_WRITE_32_BITS_RATIO(_32_BITS_RATIO(out_freq)); // Program a default clock.
00122   CS2200_WRITE_FUNCT_CFG_1( 0x00 << 6 // Push-Pull, Active High (output ‘high’ for unlocked condition, ‘low’ for locked condition).
00123                           | 0x02 << 3 // Reference Clock Input Divider: ÷ 1 [8 MHz to 18.75 MHz]
00124                           );
00125   CS2200_WRITE_FUNCT_CFG_2( 0x00 << 4 // Clock outputs are driven ‘low’ when PLL is unlocked.
00126                           );
00127 
00128   // Unleash chip
00129   CS2200_WRITE_GLOBAL_CFG( 0x00 << 3 // Freeze
00130                          | 0x01 << 0 // EnDevCfg2
00131                          );
00132   cs2200_enter_test_mode();
00133   return TRUE;
00134 }

void cs2200_switch_off ( void   ) 

Definition at line 94 of file cs2200.c.

00095 {
00096 }

void cs2200_switch_on ( void   ) 

Definition at line 90 of file cs2200.c.

00091 {
00092 }

void cs2200_write ( U8  address,
const void *  buffer,
U8  len 
)

Writes data into the CS2200 chip.

CS2200_WRITE1 ( TEST_MODE_2   ) 

CS2200_WRITE1 ( TEST_MODE_1   ) 

CS2200_WRITE1 ( FUNCT_CFG_2   ) 

CS2200_WRITE1 ( FUNCT_CFG_1   ) 

CS2200_WRITE1 ( LSB_RATIO   ) 

CS2200_WRITE1 ( GLOBAL_CFG   ) 

CS2200_WRITE1 ( DEVICE_CFG_1   ) 

CS2200_WRITE1 ( DEVICE_CTRL   ) 

CS2200_WRITE4 ( 32_BITS_RATIO   ) 

int cs2200_write_ex ( U8  address,
const void *  buffer,
U8  len 
)

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

Referenced by cs2200_freq_clk_adjust().


Generated on Fri Feb 19 02:23:29 2010 for AVR32 - CLOCK_SYNTHESIZER CS2200 by  doxygen 1.5.5