Skip to content

Commit f6f4229

Browse files
author
Sebastien Bourdeauducq
committedMay 22, 2012
Clock frequency detection
1 parent 4d754db commit f6f4229

File tree

10 files changed

+25
-11
lines changed

10 files changed

+25
-11
lines changed
 

‎milkymist/identifier/__init__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ def encode_version(version):
1616
return r
1717

1818
class Identifier:
19-
def __init__(self, address, sysid, version):
19+
def __init__(self, address, sysid, version, frequency):
2020
self.sysid = sysid
2121
self.version = encode_version(version)
22+
self.frequency = frequency
2223

2324
self._r_sysid = RegisterField("sysid", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
2425
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)
2629

2730
def get_fragment(self):
2831
comb = [
2932
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)
3135
]
3236
return self.bank.get_fragment() + Fragment(comb)

‎software/bios/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
M2DIR=../..
22
include $(M2DIR)/software/include.mak
33

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
55

66
all: bios.bin
77

‎software/bios/boot.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#include <sfl.h>
2525
#include <string.h>
2626
#include <irq.h>
27+
#include <timer.h>
2728

2829
#include <hw/flash.h>
2930
#include <hw/mem.h>
3031

31-
#include "timer.h"
3232
#include "microudp.h"
3333
#include "tftp.h"
3434
#include "boot.h"

‎software/bios/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include <irq.h>
2525
#include <version.h>
2626
#include <extra/crc.h>
27+
#include <timer.h>
2728

2829
#include <hw/flash.h>
2930
#include <hw/minimac.h>
3031

3132
#include "ddrinit.h"
32-
#include "timer.h"
3333
#include "boot.h"
3434

3535
enum {
File renamed without changes.

‎software/include/hw/id.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#define CSR_ID_SYSTEMH ID_CSR(0x00)
2727
#define CSR_ID_SYSTEML ID_CSR(0x04)
2828
#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)
3034

3135
#endif /* __HW_ID_H */

‎software/libbase/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
M2DIR=../..
22
include $(M2DIR)/software/include.mak
33

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
55

66
all: libbase.a
77

‎software/libbase/board.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdlib.h>
2222
#include <string.h>
2323
#include <version.h>
24+
#include <timer.h>
2425
#include <board.h>
2526

2627
static const struct board_desc boards[1] = {
@@ -106,7 +107,8 @@ void board_init(void)
106107
}
107108
rev = get_pcb_revision();
108109
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);
110112
if(strcmp(soc_version, VERSION) != 0)
111113
printf("SoC and BIOS versions do not match!\n");
112114
if(rev > 2)

‎software/bios/timer.c ‎software/libbase/timer.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
*/
1717

1818
#include <hw/timer.h>
19+
#include <hw/id.h>
1920

2021
#include "timer.h"
2122

2223
unsigned int get_system_frequency(void)
2324
{
24-
return 83333333; /* TODO */
25+
return (CSR_ID_FREQ3 << 24)
26+
|(CSR_ID_FREQ2 << 16)
27+
|(CSR_ID_FREQ1 << 8)
28+
|CSR_ID_FREQ0;
2529
}
2630

2731
void timer_enable(int en)

‎top.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get():
120120
# CSR
121121
#
122122
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))
124124
timer0 = timer.Timer(csr_offset("TIMER0"))
125125
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
126126
uart0.bank.interface,

0 commit comments

Comments
 (0)
Please sign in to comment.