dna.c 780 Bytes
Newer Older
1
#include "board.h"
2
#include "syscon.h"
3 4 5 6 7 8

#define DNA_DATA 1
#define DNA_CLK 4
#define DNA_SHIFT 3
#define DNA_READ 2

9
void dna_read(uint32_t * lo, uint32_t * hi)
10
{
11 12
	uint64_t dna = 0;
	int i;
13

14 15 16 17 18 19 20 21
	gpio_out(DNA_DATA, 0);
	delay(10);
	gpio_out(DNA_CLK, 0);
	delay(10);
	gpio_out(DNA_READ, 1);
	delay(10);
	gpio_out(DNA_SHIFT, 0);
	delay(10);
22

23 24 25 26 27 28 29 30 31 32 33
	delay(10);
	gpio_out(DNA_CLK, 1);
	delay(10);
	if (gpio_in(DNA_DATA))
		dna |= 1;
	delay(10);
	gpio_out(DNA_CLK, 0);
	delay(10);
	gpio_out(DNA_READ, 0);
	gpio_out(DNA_SHIFT, 1);
	delay(10);
34

35 36 37 38 39 40 41 42 43 44 45 46
	for (i = 0; i < 57; i++) {
		dna <<= 1;
		delay(10);
		delay(10);
		gpio_out(DNA_CLK, 1);
		delay(10);
		if (gpio_in(DNA_DATA))
			dna |= 1;
		delay(10);
		gpio_out(DNA_CLK, 0);
		delay(10);
	}
47

48 49
	*hi = (uint32_t) (dna >> 32);
	*lo = (uint32_t) dna;
50
}