Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Clock frequency detection

  • Loading branch information...
commit f6f42293d1a289c6db3dc9a0373169520d50f569 1 parent 4d754db
Sébastien Bourdeauducq authored May 22, 2012
10  milkymist/identifier/__init__.py
@@ -16,17 +16,21 @@ def encode_version(version):
16 16
 	return r
17 17
 
18 18
 class Identifier:
19  
-	def __init__(self, address, sysid, version):
  19
+	def __init__(self, address, sysid, version, frequency):
20 20
 		self.sysid = sysid
21 21
 		self.version = encode_version(version)
  22
+		self.frequency = frequency
22 23
 		
23 24
 		self._r_sysid = RegisterField("sysid", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
24 25
 		self._r_version = RegisterField("version", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
25  
-		self.bank = csrgen.Bank([self._r_sysid, self._r_version], address=address)
  26
+		self._r_frequency = RegisterField("frequency", 32, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
  27
+		regs = [self._r_sysid, self._r_version, self._r_frequency]
  28
+		self.bank = csrgen.Bank(regs, address=address)
26 29
 		
27 30
 	def get_fragment(self):
28 31
 		comb = [
29 32
 			self._r_sysid.field.w.eq(self.sysid),
30  
-			self._r_version.field.w.eq(self.version)
  33
+			self._r_version.field.w.eq(self.version),
  34
+			self._r_frequency.field.w.eq(self.frequency)
31 35
 		]
32 36
 		return self.bank.get_fragment() + Fragment(comb)
2  software/bios/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/include.mak
3 3
 
4  
-OBJECTS=crt0.o isr.o ddrinit.o timer.o main.o microudp.o tftp.o boot-helper.o boot.o
  4
+OBJECTS=crt0.o isr.o ddrinit.o main.o microudp.o tftp.o boot-helper.o boot.o
5 5
 
6 6
 all: bios.bin
7 7
 
2  software/bios/boot.c
@@ -24,11 +24,11 @@
24 24
 #include <sfl.h>
25 25
 #include <string.h>
26 26
 #include <irq.h>
  27
+#include <timer.h>
27 28
 
28 29
 #include <hw/flash.h>
29 30
 #include <hw/mem.h>
30 31
 
31  
-#include "timer.h"
32 32
 #include "microudp.h"
33 33
 #include "tftp.h"
34 34
 #include "boot.h"
2  software/bios/main.c
@@ -24,12 +24,12 @@
24 24
 #include <irq.h>
25 25
 #include <version.h>
26 26
 #include <extra/crc.h>
  27
+#include <timer.h>
27 28
 
28 29
 #include <hw/flash.h>
29 30
 #include <hw/minimac.h>
30 31
 
31 32
 #include "ddrinit.h"
32  
-#include "timer.h"
33 33
 #include "boot.h"
34 34
 
35 35
 enum {
0  software/bios/timer.h → software/include/base/timer.h
File renamed without changes
6  software/include/hw/id.h
@@ -26,6 +26,10 @@
26 26
 #define CSR_ID_SYSTEMH		ID_CSR(0x00)
27 27
 #define CSR_ID_SYSTEML		ID_CSR(0x04)
28 28
 #define CSR_ID_VERSIONH		ID_CSR(0x08)
29  
-#define CSR_ID_VERSIONL		ID_CSR(0x0c)
  29
+#define CSR_ID_VERSIONL		ID_CSR(0x0C)
  30
+#define CSR_ID_FREQ3		ID_CSR(0x10)
  31
+#define CSR_ID_FREQ2		ID_CSR(0x14)
  32
+#define CSR_ID_FREQ1		ID_CSR(0x18)
  33
+#define CSR_ID_FREQ0		ID_CSR(0x1C)
30 34
 
31 35
 #endif /* __HW_ID_H */
2  software/libbase/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/include.mak
3 3
 
4  
-OBJECTS=divsi3.o libc.o console.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
  4
+OBJECTS=divsi3.o libc.o console.o timer.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
5 5
 
6 6
 all: libbase.a
7 7
 
4  software/libbase/board.c
@@ -21,6 +21,7 @@
21 21
 #include <stdlib.h>
22 22
 #include <string.h>
23 23
 #include <version.h>
  24
+#include <timer.h>
24 25
 #include <board.h>
25 26
 
26 27
 static const struct board_desc boards[1] = {
@@ -106,7 +107,8 @@ void board_init(void)
106 107
 	}
107 108
 	rev = get_pcb_revision();
108 109
 	get_soc_version_formatted(soc_version);
109  
-	printf("Detected SoC %s on %s (PCB revision %d)\n", soc_version, brd_desc->name, rev);
  110
+	printf("Detected SoC %s at %dMHz on %s (PCB revision %d)\n", soc_version, get_system_frequency()/1000000,
  111
+	       brd_desc->name, rev);
110 112
 	if(strcmp(soc_version, VERSION) != 0)
111 113
 		printf("SoC and BIOS versions do not match!\n");
112 114
 	if(rev > 2)
6  software/bios/timer.c → software/libbase/timer.c
@@ -16,12 +16,16 @@
16 16
  */
17 17
 
18 18
 #include <hw/timer.h>
  19
+#include <hw/id.h>
19 20
 
20 21
 #include "timer.h"
21 22
 
22 23
 unsigned int get_system_frequency(void)
23 24
 {
24  
-	return 83333333; /* TODO */
  25
+	return (CSR_ID_FREQ3 << 24)
  26
+		|(CSR_ID_FREQ2 << 16)
  27
+		|(CSR_ID_FREQ1 << 8)
  28
+		|CSR_ID_FREQ0;
25 29
 }
26 30
 
27 31
 void timer_enable(int en)
2  top.py
@@ -120,7 +120,7 @@ def get():
120 120
 	# CSR
121 121
 	#
122 122
 	uart0 = uart.UART(csr_offset("UART"), clk_freq, baud=115200)
123  
-	identifier0 = identifier.Identifier(csr_offset("ID"), 0x4D31, version)
  123
+	identifier0 = identifier.Identifier(csr_offset("ID"), 0x4D31, version, int(clk_freq))
124 124
 	timer0 = timer.Timer(csr_offset("TIMER0"))
125 125
 	csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
126 126
 		uart0.bank.interface,

0 notes on commit f6f4229

Please sign in to comment.
Something went wrong with that request. Please try again.