summaryrefslogtreecommitdiff
path: root/lmx2487lib.lua
blob: 1034e0f59a10aeed8290f7f6be0a89b2ae865f2b (plain)
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
-- there are 8 registers to track for lmx2487
-- labeled R0, R1, ..., R7 in the manual
lmx2487_registers   = {0, 0, 0, 0, 0, 0, 0, 0}
-- if need update set to true updater script will resend this register
lmx2487_need_update = {false, false, false, false, false, false, false, false} 

function set_lmx2487register(value, register)
	-- register labeled 0, 1, 2, ..., 7
	if (lmx2487_registers[register+1] ~= value) then
		-- this is new value and thus needs to be updated in hardware
		lmx2487_registers[register+1] = value
		lmx2487_need_update[register+1] = true
		print("updating register " .. register .. " with value " .. value)
	end
	-- otherwise we do nothing
end

function get_lmx2487register(register)
	-- register labeled 0, 1, 2, ..., 7
	local value = (lmx2487_registers[register+1])
	print("register " .. register .. " is set to " .. value)
	return value
end

function send_register_lmx2487(register)
	if ( lmx2487_need_update[register +1] ) then
		print("sending register " .. register .. " with value " .. get_lmx2487register( register ) )
		-- do hardware talking
		microwire_send_data( get_lmx2487register( register ) )
		lmx2487_need_update[register+1]=false
	end
end

function update_lmx2487state() 
	for register=7,0,-1 do
		-- going over registers
		-- manual suggest to send R0 as last one
		send_register_lmx2487( register )
	end
end


function set_lmx2487_board_to_default_state()
	-- this defaults are historic and borrowed from lmx2487lib.tcl
	-- defaults (set RF freq to 6.83468635e9 GHz and lock it to 10MHz oscillator)
	set_lmx2487register(11197502  , 0)
	set_lmx2487register(4352515   , 1)
	set_lmx2487register(8560613   , 2)
	set_lmx2487register(15925287  , 3)
	set_lmx2487register(10618633  , 4)
	set_lmx2487register(393579    , 5)
	set_lmx2487register(8126541   , 6)
	set_lmx2487register(10639     , 7)

	update_lmx2487state()
end