Skip to content

Commit 83e96dc

Browse files
committed
SoCkit port
1 parent 10e2b6c commit 83e96dc

12 files changed

+711
-350
lines changed

Readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Template core for [SoCkit (MiSTer) Platform](https://github.com/sockitfpga/MiSTer_SoCkit)
2+
3+
Ported by @somhi from https://github.com/MiSTer-devel/Template_MiSTer
4+
5+
Follows original README.
6+
17
# Template core for MiSTer
28

39
## General description

mycore.qsf

+18-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
1313
set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
1414
set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
1515

16-
set_global_assignment -name LAST_QUARTUS_VERSION "17.0.2 Standard Edition"
16+
set_global_assignment -name LAST_QUARTUS_VERSION "17.1.0 Lite Edition"
1717

1818
set_global_assignment -name GENERATE_RBF_FILE ON
1919
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
2020
set_global_assignment -name NUM_PARALLEL_PROCESSORS ALL
2121
set_global_assignment -name SAVE_DISK_SPACE OFF
2222
set_global_assignment -name SMART_RECOMPILE ON
23-
set_global_assignment -name MIN_CORE_JUNCTION_TEMP "-40"
24-
set_global_assignment -name MAX_CORE_JUNCTION_TEMP 100
23+
set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
24+
set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
2525
set_global_assignment -name POWER_PRESET_COOLING_SOLUTION "23 MM HEAT SINK WITH 200 LFPM AIRFLOW"
2626
set_global_assignment -name POWER_BOARD_THERMAL_MODEL "NONE (CONSERVATIVE)"
2727
set_global_assignment -name TIMEQUEST_MULTICORNER_ANALYSIS OFF
@@ -50,6 +50,16 @@ set_global_assignment -name PHYSICAL_SYNTHESIS_ASYNCHRONOUS_SIGNAL_PIPELINING ON
5050
set_global_assignment -name ALM_REGISTER_PACKING_EFFORT MEDIUM
5151
set_global_assignment -name SEED 1
5252

53+
set_global_assignment -name ENABLE_OCT_DONE OFF
54+
set_global_assignment -name STRATIXV_CONFIGURATION_SCHEME "PASSIVE SERIAL"
55+
set_global_assignment -name USE_CONFIGURATION_DEVICE ON
56+
set_global_assignment -name CRC_ERROR_OPEN_DRAIN ON
57+
set_global_assignment -name OUTPUT_IO_TIMING_NEAR_END_VMEAS "HALF VCCIO" -rise
58+
set_global_assignment -name OUTPUT_IO_TIMING_NEAR_END_VMEAS "HALF VCCIO" -fall
59+
set_global_assignment -name OUTPUT_IO_TIMING_FAR_END_VMEAS "HALF SIGNAL SWING" -rise
60+
set_global_assignment -name OUTPUT_IO_TIMING_FAR_END_VMEAS "HALF SIGNAL SWING" -fall
61+
set_global_assignment -name ACTIVE_SERIAL_CLOCK FREQ_100MHZ
62+
5363
#set_global_assignment -name VERILOG_MACRO "MISTER_FB=1"
5464

5565
#enable it only if 8bit indexed mode is used in core
@@ -70,4 +80,8 @@ set_global_assignment -name SEED 1
7080
source sys/sys.tcl
7181
source sys/sys_analog.tcl
7282
source files.qip
73-
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
83+
84+
set_global_assignment -name VERILOG_FILE sys/I2C_Controller.v
85+
set_global_assignment -name VERILOG_FILE sys/I2C_AV_Config.v
86+
87+
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top

mycore_Q13.qpf

-2
This file was deleted.

mycore_Q13.qsf

-46
This file was deleted.

mycore_Q13.srf

-28
This file was deleted.

sys/I2C_AV_Config.v

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//Legal Notice: (C)2006 Altera Corporation. All rights reserved. Your
2+
//use of Altera Corporation's design tools, logic functions and other
3+
//software and tools, and its AMPP partner logic functions, and any
4+
//output files any of the foregoing (including device programming or
5+
//simulation files), and any associated documentation or information are
6+
//expressly subject to the terms and conditions of the Altera Program
7+
//License Subscription Agreement or other applicable license agreement,
8+
//including, without limitation, that your use is for the sole purpose
9+
//of programming logic devices manufactured by Altera and sold by Altera
10+
//or its authorized distributors. Please refer to the applicable
11+
//agreement for further details.
12+
13+
module I2C_AV_Config ( //Host Side
14+
iCLK,
15+
iRST_N,
16+
// I2C Side
17+
oI2C_SCLK,
18+
oI2C_SDAT
19+
);
20+
21+
// Host Side
22+
input iCLK;
23+
input iRST_N;
24+
// I2C Side
25+
output oI2C_SCLK;
26+
inout oI2C_SDAT;
27+
// Internal Registers/Wires
28+
reg [15:0] mI2C_CLK_DIV;
29+
reg [23:0] mI2C_DATA;
30+
reg mI2C_CTRL_CLK;
31+
reg mI2C_GO;
32+
wire mI2C_END;
33+
wire mI2C_ACK;
34+
reg [15:0] LUT_DATA;
35+
reg [3:0] LUT_INDEX;
36+
reg [1:0] mSetup_ST;
37+
38+
// Clock Setting
39+
parameter CLK_Freq = 24000000; // 24 MHz
40+
parameter I2C_Freq = 20000; // 20 KHz
41+
// LUT Data Number
42+
parameter LUT_SIZE = 11;
43+
// Audio Data Index
44+
parameter Dummy_DATA = 0;
45+
parameter SET_LIN_L = 1;
46+
parameter SET_LIN_R = 2;
47+
parameter SET_HEAD_L = 3;
48+
parameter SET_HEAD_R = 4;
49+
parameter A_PATH_CTRL = 5;
50+
parameter D_PATH_CTRL = 6;
51+
parameter POWER_ON = 7;
52+
parameter SET_FORMAT = 8;
53+
parameter SAMPLE_CTRL = 9;
54+
parameter SET_ACTIVE = 10;
55+
56+
57+
58+
///////////////////// I2C Control Clock ////////////////////////
59+
always@(posedge iCLK or negedge iRST_N) begin
60+
if(!iRST_N) begin
61+
mI2C_CTRL_CLK <= 1'd0;
62+
mI2C_CLK_DIV <= 16'd0;
63+
end else begin
64+
if (mI2C_CLK_DIV < (CLK_Freq/I2C_Freq))
65+
mI2C_CLK_DIV <= mI2C_CLK_DIV + 16'd1;
66+
else begin
67+
mI2C_CLK_DIV <= 16'd0;
68+
mI2C_CTRL_CLK <= ~mI2C_CTRL_CLK;
69+
end
70+
end
71+
end
72+
73+
////////////////////////////////////////////////////////////////////
74+
I2C_Controller u0 (
75+
.CLOCK(mI2C_CTRL_CLK), // Controller Work Clock
76+
.I2C_SCLK(oI2C_SCLK), // I2C CLOCK
77+
.I2C_SDAT(oI2C_SDAT), // I2C DATA
78+
.I2C_DATA(mI2C_DATA), // DATA:[SLAVE_ADDR,SUB_ADDR,DATA]
79+
.GO(mI2C_GO), // GO transfor
80+
.END(mI2C_END), // END transfor
81+
.ACK(mI2C_ACK), // ACK
82+
.RESET(iRST_N)
83+
);
84+
////////////////////////////////////////////////////////////////////
85+
86+
87+
////////////////////// Config Control ////////////////////////////
88+
always@(posedge mI2C_CTRL_CLK or negedge iRST_N) begin
89+
if(!iRST_N) begin
90+
LUT_INDEX <= 4'd0;
91+
mSetup_ST <= 2'd0;
92+
mI2C_GO <= 1'd0;
93+
end else begin
94+
if(LUT_INDEX < LUT_SIZE) begin
95+
case(mSetup_ST)
96+
0: begin
97+
mI2C_DATA <= {8'h34,LUT_DATA};
98+
mI2C_GO <= 1'd1;
99+
mSetup_ST <= 2'd1;
100+
end
101+
1: begin
102+
if(mI2C_END) begin
103+
if(!mI2C_ACK)
104+
mSetup_ST <= 2'd2;
105+
else
106+
mSetup_ST <= 2'd0;
107+
mI2C_GO <= 1'd0;
108+
end
109+
end
110+
2: begin
111+
LUT_INDEX <= LUT_INDEX + 4'd1;
112+
mSetup_ST <= 2'd0;
113+
end
114+
endcase
115+
end
116+
end
117+
end
118+
////////////////////////////////////////////////////////////////////
119+
120+
121+
///////////////////// Config Data LUT //////////////////////////
122+
always @ (*)
123+
begin
124+
case(LUT_INDEX)
125+
// Audio Config Data
126+
Dummy_DATA : LUT_DATA <= 16'h0000;
127+
SET_LIN_L : LUT_DATA <= 16'h009A;//16'h001A; //R0 LINVOL = 1Ah (+4.5bB)
128+
SET_LIN_R : LUT_DATA <= 16'h029A;//16'h021A; //R1 RINVOL = 1Ah (+4.5bB)
129+
SET_HEAD_L : LUT_DATA <= 16'h0479; //R2 LHPVOL = 7Bh (+2dB)
130+
SET_HEAD_R : LUT_DATA <= 16'h0679; //R3 RHPVOL = 7Bh (+2dB)
131+
A_PATH_CTRL : LUT_DATA <= 16'h08D2;//16'h08F8; //R4 DACSEL = 1
132+
D_PATH_CTRL : LUT_DATA <= 16'h0A06; //R5 DEEMP = 11 (48 KHz)
133+
//POWER_ON : LUT_DATA <= 16'h0C00; //R6 all powered ON
134+
POWER_ON : LUT_DATA <= 16'h0C20; //R6 internal oscilator MCLK powered down
135+
//SET_FORMAT : LUT_DATA <= 16'h0E01; //R7 FORMAT=01,16 bit format left justified
136+
SET_FORMAT : LUT_DATA <= 16'h0E02; //R7 FORMAT=10,16 bit format I2S
137+
//SAMPLE_CTRL : LUT_DATA <= 16'h1009; //R8 48KHz,USB-mode
138+
SAMPLE_CTRL : LUT_DATA <= 16'h1008; //R8 48KHz,Normal mode, clkdiv2=0
139+
SET_ACTIVE : LUT_DATA <= 16'h1201; //R9 ACTIVE
140+
default : LUT_DATA <= 16'h0000;
141+
endcase
142+
end
143+
////////////////////////////////////////////////////////////////////
144+
145+
146+
endmodule
147+

sys/I2C_Controller.v

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//Legal Notice: (C)2006 Altera Corporation. All rights reserved. Your
2+
//use of Altera Corporation's design tools, logic functions and other
3+
//software and tools, and its AMPP partner logic functions, and any
4+
//output files any of the foregoing (including device programming or
5+
//simulation files), and any associated documentation or information are
6+
//expressly subject to the terms and conditions of the Altera Program
7+
//License Subscription Agreement or other applicable license agreement,
8+
//including, without limitation, that your use is for the sole purpose
9+
//of programming logic devices manufactured by Altera and sold by Altera
10+
//or its authorized distributors. Please refer to the applicable
11+
//agreement for further details.
12+
13+
module I2C_Controller (
14+
CLOCK,
15+
I2C_SCLK, //I2C CLOCK
16+
I2C_SDAT, //I2C DATA
17+
I2C_DATA, //DATA:[SLAVE_ADDR,SUB_ADDR,DATA]
18+
GO, //GO transfor
19+
END, //END transfor
20+
ACK, //ACK
21+
RESET,
22+
//TEST
23+
SD_COUNTER,
24+
SDO
25+
);
26+
27+
input CLOCK;
28+
input [23:0]I2C_DATA;
29+
input GO;
30+
input RESET;
31+
inout I2C_SDAT;
32+
output I2C_SCLK;
33+
output END;
34+
output ACK;
35+
//TEST
36+
output [5:0] SD_COUNTER;
37+
output SDO;
38+
39+
reg SDO;
40+
reg SCLK;
41+
reg END;
42+
reg [23:0]SD;
43+
reg [5:0]SD_COUNTER;
44+
45+
wire I2C_SCLK=SCLK | ( ((SD_COUNTER >= 4) & (SD_COUNTER <=30))? ~CLOCK : 1'd0 );
46+
wire I2C_SDAT=SDO ? 1'bz : 1'b0 ;
47+
48+
reg ACK1,ACK2,ACK3;
49+
wire ACK=ACK1 | ACK2 |ACK3;
50+
51+
//--I2C COUNTER
52+
always @(negedge RESET or posedge CLOCK ) begin
53+
if (!RESET) SD_COUNTER=6'b111111;
54+
else begin
55+
if (GO==0)
56+
SD_COUNTER=0;
57+
else
58+
if (SD_COUNTER < 6'b111111) SD_COUNTER=SD_COUNTER + 6'd1;
59+
end
60+
end
61+
//----
62+
63+
always @(negedge RESET or posedge CLOCK ) begin
64+
if (!RESET) begin SCLK=1;SDO=1; ACK1=0;ACK2=0;ACK3=0; END=1; end
65+
else
66+
case (SD_COUNTER)
67+
6'd0 : begin ACK1=0 ;ACK2=0 ;ACK3=0 ; END=0; SDO=1; SCLK=1;end
68+
//start
69+
6'd1 : begin SD=I2C_DATA;SDO=0;end
70+
6'd2 : SCLK=0;
71+
//SLAVE ADDR
72+
6'd3 : SDO=SD[23];
73+
6'd4 : SDO=SD[22];
74+
6'd5 : SDO=SD[21];
75+
6'd6 : SDO=SD[20];
76+
6'd7 : SDO=SD[19];
77+
6'd8 : SDO=SD[18];
78+
6'd9 : SDO=SD[17];
79+
6'd10 : SDO=SD[16];
80+
6'd11 : SDO=1'b1;//ACK
81+
82+
//SUB ADDR
83+
6'd12 : begin SDO=SD[15]; ACK1=I2C_SDAT; end
84+
6'd13 : SDO=SD[14];
85+
6'd14 : SDO=SD[13];
86+
6'd15 : SDO=SD[12];
87+
6'd16 : SDO=SD[11];
88+
6'd17 : SDO=SD[10];
89+
6'd18 : SDO=SD[9];
90+
6'd19 : SDO=SD[8];
91+
6'd20 : SDO=1'b1;//ACK
92+
93+
//DATA
94+
6'd21 : begin SDO=SD[7]; ACK2=I2C_SDAT; end
95+
6'd22 : SDO=SD[6];
96+
6'd23 : SDO=SD[5];
97+
6'd24 : SDO=SD[4];
98+
6'd25 : SDO=SD[3];
99+
6'd26 : SDO=SD[2];
100+
6'd27 : SDO=SD[1];
101+
6'd28 : SDO=SD[0];
102+
6'd29 : SDO=1'b1;//ACK
103+
104+
//stop
105+
6'd30 : begin SDO=1'b0; SCLK=1'b0; ACK3=I2C_SDAT; end
106+
6'd31 : SCLK=1'b1;
107+
6'd32 : begin SDO=1'b1; END=1; end
108+
109+
endcase
110+
end
111+
endmodule
112+

0 commit comments

Comments
 (0)