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 _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_READ | ( | name | ) |
Value:
static inline void CS2200_READ_##name(void *data, size_t len) \ { \ cs2200_read(CS2200_REG_##name##_ADDR, data, len); \ }
#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; \ }
#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; \ }
#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; \ }
#define CS2200_REG_LSW_RATIO_ADDR 0x08 |
#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); \ }
#define CS2200_WRITE1 | ( | name | ) |
Value:
static inline void CS2200_WRITE_##name(U8 data) \ { \ cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \ }
#define CS2200_WRITE2 | ( | name | ) |
Value:
static inline void CS2200_WRITE_##name(U16 data) \ { \ cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \ }
#define CS2200_WRITE4 | ( | name | ) |
Value:
static inline void CS2200_WRITE_##name(U32 data) \ { \ cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data)); \ }
#define PPM | ( | value, | |||
ppm | ) | ( ((int)( (long long)value*(ppm)/1000000) ) ) |
#define PPM_ADD | ( | value, | |||
ppm | ) | ( ((int)(value + (long long)value*(ppm)/1000000)) ) |
#define PPM_SUB | ( | value, | |||
ppm | ) | ( ((int)(value - (long long)value*(ppm)/1000000)) ) |
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 | ) |
void cs2200_leave_power_down_mode | ( | void | ) |
Leave power down mode and twi comms can be restarted.
void cs2200_leave_test_mode | ( | void | ) |
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_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().