Si5351C.h 2.11 KB
Newer Older
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
@file	Si5351C.h
@brief	Header for Si5351C.cpp
@author	Lime Microsystems
*/

#ifndef SI5351C_MODULE
#define SI5351C_MODULE

#include <stdio.h>
#include <string>
using namespace std;
//---------------------------------------------------------------------------

enum eSi_CLOCK_INPUT
{
    Si_CLKIN,
    Si_XTAL,
    Si_CMOS
};

struct Si5351_Channel
{
    Si5351_Channel() : outputDivider(1), outputFreqHz(1), multisynthDivider(1), pllSource(0),
        phaseOffset(0), powered(true), inverted(false), int_mode(false) {};
    int outputDivider;
    unsigned long outputFreqHz;
    float multisynthDivider;
    int pllSource;
    float phaseOffset;
    bool powered;
    bool inverted;
    bool int_mode;
};

struct Si5351_PLL
{
    Si5351_PLL() : inputFreqHz(0), VCO_Hz(0), feedbackDivider(0), CLKIN_DIV(1), CLK_SRC(1) {}
    unsigned long inputFreqHz;
    float VCO_Hz;
    float feedbackDivider;
    int CLKIN_DIV;
    int CLK_SRC; //0-XTAL, 1-CLKIN
};

class LMScomms;
class Si5351C
{
public:
    enum Status
    {
        SUCCESS,
        FAILED,
    };

    struct StatusBits
    {
        StatusBits() : sys_init(0), sys_init_stky(0), lol_b(0), lol_b_stky(0), lol_a(0), lol_a_stky(0), los(0), los_stky(0)
        {

        }
        int sys_init;
        int sys_init_stky;
        int lol_b;
        int lol_b_stky;
        int lol_a;
        int lol_a_stky;
        int los;
        int los_stky;
    };

    StatusBits GetStatusBits();
    Status ClearStatus();

	Si5351C();
	~Si5351C();
	void Initialize(LMScomms *mng);
	bool LoadRegValuesFromFile(string FName);

    void SetPLL(unsigned char id, unsigned long CLKIN_Hz, int CLK_SRC);
    void SetClock(unsigned char id, unsigned long fOut_Hz, bool enabled = true, bool inverted = false);

    Status UploadConfiguration();
    Status ConfigureClocks();
	void Reset();
    
private:
    void FindVCO(Si5351_Channel *clocks, Si5351_PLL *plls, const unsigned long Fmin, const unsigned long Fmax);
    LMScomms *device;

    Si5351_PLL PLL[2];
    Si5351_Channel CLK[8];

	static const unsigned char m_defaultConfiguration[];
	unsigned char m_newConfiguration[255];


};

#endif // SI5351C_MODULE