ming_node 3.0.2 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/extlib/MingExcelTool.js +75 -0
  2. package/index.js +4 -10
  3. package/output/ming_api_mock/ming_api_mock.js +3251 -0
  4. package/output/ming_api_mock/mock.bat +21 -0
  5. package/output/ming_api_mock/mock.sh +15 -0
  6. package/output/npr/npr.bat +7 -0
  7. package/output/npr/npr_plugins/MakeModelsim/index.js +157 -0
  8. package/output/npr/npr_plugins/Modelsim/index.js +72 -0
  9. package/output/npr/npr_plugins/common/ming_node.js +58 -0
  10. package/output/npr/npr_plugins/demo/index.js +1 -0
  11. package/output/npr/npr_plugins/hello/index.js +1 -0
  12. package/output/npr/npr_plugins/install/index.js +27 -0
  13. package/output/npr/npr_plugins/list/index.js +20 -0
  14. package/output/npr/npr_plugins/verilog/Readme.md +1 -0
  15. package/output/npr/npr_plugins/verilog/breath_led/breath_led.v +99 -0
  16. package/output/npr/npr_plugins/verilog/breath_led/tb.v +39 -0
  17. package/output/npr/npr_plugins/verilog/demo/led.v +12 -0
  18. package/output/npr/npr_plugins/verilog/demo/sims/Makefile +25 -0
  19. package/output/npr/npr_plugins/verilog/demo/sims/filelist.f +1 -0
  20. package/output/npr/npr_plugins/verilog/demo/sims/run.do +3 -0
  21. package/output/npr/npr_plugins/verilog/demo/tb.v +30 -0
  22. package/output/npr/npr_plugins/verilog/index.js +25 -0
  23. package/output/npr/npr_plugins/verilog/key_led/key_debounce.v +57 -0
  24. package/output/npr/npr_plugins/verilog/key_led/tb.v +78 -0
  25. package/output/npr/npr_plugins/verilog/key_led/toggle_pin.v +35 -0
  26. package/output/npr/npr_plugins/verilog/led/led.v +12 -0
  27. package/output/npr/npr_plugins/verilog/led/tb.v +30 -0
  28. package/output/npr/npr_plugins/verilog/modelsim_tcl/filelist.f +2 -0
  29. package/output/npr/npr_plugins/verilog/modelsim_tcl/restart.tcl +1 -0
  30. package/output/npr/npr_plugins/verilog/modelsim_tcl/run.do +3 -0
  31. package/output/npr/npr_plugins/verilog/modelsim_tcl//346/216/247/345/210/266/345/217/260_Makefile +24 -0
  32. package/output/npr/npr_plugins/verilog/modelsim_tcl//347/252/227/345/217/243_Makefile +24 -0
  33. package/output/npr/npr_plugins/verilog/simple_verilog/sims/C_Makefile +27 -0
  34. package/output/npr/npr_plugins/verilog/simple_verilog/sims/Makefile +25 -0
  35. package/output/npr/npr_plugins/verilog/simple_verilog/sims/W_Makefile +24 -0
  36. package/output/npr/npr_plugins/verilog/simple_verilog/sims/filelist.f +1 -0
  37. package/output/npr/npr_plugins/verilog/simple_verilog/sims/run.do +3 -0
  38. package/output/npr/npr_plugins/verilog/simple_verilog/tb/led.sv +72 -0
  39. package/output/npr/npr_plugins/verilog/simple_verilog/tb/tb.sv +54 -0
  40. package/output/npr/npr_plugins/verilog/smg/HC_FPGA_Demo_Top.v +29 -0
  41. package/output/npr/npr_plugins/verilog/smg/digital_tube.v +93 -0
  42. package/output/npr/npr_plugins/verilog/smg/tb.v +56 -0
  43. package/output/npr/npr_plugins/verilog/uart/calc.js +4 -0
  44. package/output/npr/npr_plugins/verilog/uart/tb.v +35 -0
  45. package/output/npr/npr_plugins/verilog/uart/top_UART_RX.v +37 -0
  46. package/output/npr/npr_plugins/verilog/uart/top_UART_TX.v +41 -0
  47. package/output/npr/npr_plugins/verilog/uart/uart_rx.v +148 -0
  48. package/output/npr/npr_plugins/verilog/uart/uart_rx_led.v +23 -0
  49. package/output/npr/npr_plugins/verilog/uart/uart_tx.v +121 -0
  50. package/output/npr/npr_plugins/verilog/uart/uart_tx_count.v +72 -0
  51. package/output/npr/readme.md +7 -0
  52. package/package.json +1 -1
  53. package/plugins/Modelsim/Modelsim.js +29 -0
  54. package/plugins/Modelsim/run.bat +6 -0
  55. package/plugins/Modelsim/top.do +6 -0
@@ -0,0 +1,21 @@
1
+ @ECHO OFF
2
+ TITLE mock
3
+
4
+ SET curPath=%cd%
5
+
6
+ :start
7
+ set p1=%1%
8
+ set p2=%2%
9
+ set port=8888
10
+ set serverfile=""
11
+ set swi=0
12
+ echo %p1%|findstr /be "[0-9]*" >nul && set swi=1 || set swi=2
13
+
14
+
15
+ if %swi%==1 set port=%p1%
16
+ if %swi%==2 set serverfile=%p1%
17
+ if %swi%==2 set port=%p2%
18
+ if %swi%==2 (if not "%1" == "" curl %serverfile% > server.js)
19
+ echo port=%port%
20
+ echo serverfile=%serverfile%
21
+ node "%~dp0/ming_api_mock.js" "%curPath%/" %port% "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+ #port=8888
3
+ serverfile=""
4
+ sw=`echo $1 | sed 's/[0-9]//g' | sed 's/-//g'`
5
+ if [ ${#sw} -eq 0 ];then
6
+ port=$1
7
+ else
8
+ serverfile=$1
9
+ port=$2
10
+ curl $serverfile > server.js
11
+ fi
12
+
13
+ echo port=$port
14
+ echo serverfile=$serverfile
15
+ node $(cd $(dirname ${BASH_SOURCE:-$0});pwd)/ming_api_mock.js $(pwd)/ $port $@
@@ -0,0 +1,7 @@
1
+ @ECHO OFF
2
+ TITLE npr
3
+ :start
4
+ set p1=%1%
5
+ set p2=%2%
6
+ set curPath=%cd%
7
+ node "%~dp0/npr_plugins/%1/index.js" "%curPath%/" "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"
@@ -0,0 +1,157 @@
1
+ /**
2
+ build/CUR_DIR
3
+ led/tb.v led.v
4
+ */
5
+ const child_process = require('child_process');
6
+ const fs = require('fs');
7
+ var args = process.argv.splice(2)
8
+ let argsPath=args[0] || "./";
9
+
10
+
11
+ const M={};
12
+ M.exec = function (comand) {
13
+ let promise = new Promise(function (reslove, reject) {
14
+ child_process.exec(comand, function (err, stdout, stderr) {
15
+ if (err || stderr) console.error(err, stderr);
16
+ reslove(stdout);
17
+ });
18
+
19
+ })
20
+ return promise;
21
+ }
22
+
23
+
24
+
25
+
26
+ async function install(){
27
+ await M.exec(`mkdir doc`);
28
+ await M.exec(`mkdir opt`);
29
+ await M.exec(`mkdir sims`);
30
+ await M.exec(`mkdir src`);
31
+ await M.exec(`mkdir tb`);
32
+
33
+ fs.writeFileSync('doc/Readme.md',
34
+ `# led
35
+ led test`
36
+ );
37
+
38
+ fs.writeFileSync('sims/filelist.f',
39
+ `"../src/led.v"
40
+ "../tb/tb.v"`
41
+ );
42
+
43
+
44
+ fs.writeFileSync('sims/Makefile',
45
+ `#setting parameter
46
+ work= work
47
+ output= ../opt
48
+ vsimbatch0= -do "run -all"
49
+
50
+
51
+ #commandbegin
52
+ all:compile vsim
53
+ lib:
54
+ \techo "start compile for Questasim10.6c"
55
+ \tvlib $(work)
56
+ \tvmap work $(work)
57
+ vlog :
58
+ \tvlog -f filelist.f -l $(output)/compile.log
59
+ compile: lib vlog
60
+ run:
61
+ \tmodelsim -do ./run.do
62
+ #make clean
63
+ clean:
64
+ \tdel *.wlf
65
+ \tdel vsim_stacktrace.vstf
66
+ \tdel transcript
67
+ \tdel modelsim.ini
68
+ \trmdir /s /q work
69
+ `
70
+ );
71
+
72
+ fs.writeFileSync('sims/run.do',
73
+ `vsim -voptargs=+acc work.tb
74
+ add wave -position insertpoint sim:/tb/*
75
+ run 100ns`
76
+ );
77
+
78
+
79
+ fs.writeFileSync('src/led.v',
80
+ `module led(
81
+ input key ,
82
+
83
+ output led
84
+ );
85
+
86
+
87
+ assign led =key;
88
+
89
+ endmodule`
90
+ );
91
+
92
+ fs.writeFileSync('tb/tb.v',
93
+ `\`timescale 1ns / 1ns //仿真单位/仿真精度
94
+
95
+ module tb();
96
+
97
+
98
+
99
+ reg key;
100
+ wire led;
101
+
102
+
103
+ initial begin
104
+ key <= 1'b1;
105
+ #12
106
+ key <= 1'b1;
107
+ #3
108
+ key <= 1'b0;
109
+ #2
110
+ key <= 1'b1;
111
+ #2
112
+ key <= 1'b0;
113
+ #2
114
+ key <= 1'b1;
115
+ #3
116
+ key <= 1'b0;
117
+ #2
118
+ key <= 1'b1;
119
+ #2
120
+ key <= 1'b0;
121
+ end
122
+
123
+ //例化led模块
124
+ led u_led(
125
+ .key (key),
126
+ .led (led)
127
+ );
128
+
129
+ endmodule
130
+
131
+ `
132
+ );
133
+
134
+ console.log("MakeModelsim install success!")
135
+ }
136
+
137
+ function help(){
138
+ console.log(
139
+ `
140
+ cd sims;
141
+ make compile
142
+ make run
143
+ `)
144
+ }
145
+
146
+ function main(){
147
+
148
+ switch (args[2]){
149
+ case "": install();break;
150
+ case "help": help();break;
151
+ }
152
+
153
+ }
154
+
155
+
156
+ main()
157
+
@@ -0,0 +1,72 @@
1
+ /**
2
+ build/CUR_DIR
3
+ led/tb.v led.v
4
+ */
5
+ const child_process = require('child_process');
6
+ const fs = require('fs');
7
+ var args = process.argv.splice(2)
8
+ let argsPath=args[0] || "./";
9
+
10
+
11
+ const M={};
12
+ M.exec = function (comand) {
13
+ let promise = new Promise(function (reslove, reject) {
14
+ child_process.exec(comand, function (err, stdout, stderr) {
15
+ if (err || stderr) console.error(err, stderr);
16
+ reslove(stdout);
17
+ });
18
+
19
+ })
20
+ return promise;
21
+ }
22
+
23
+
24
+
25
+
26
+ async function install(){
27
+ await M.exec(`mkdir build`);
28
+ fs.writeFileSync('build/run.bat',
29
+
30
+ `rmdir /s /q work
31
+ del vsim.wlf
32
+ del transcript
33
+ set MY_PARAM=%1%
34
+ modelsim -do top.do`
35
+
36
+ );
37
+
38
+
39
+ fs.writeFileSync('build/top.do',
40
+
41
+ `vlib work
42
+ vmap work work
43
+ vlog ../$::env(MY_PARAM)/*v
44
+ vsim -voptargs=+acc work.tb
45
+ add wave -position insertpoint sim:/tb/*
46
+ run 100ns`
47
+
48
+ );
49
+
50
+ console.log("Modelsim install success!")
51
+ }
52
+
53
+ function help(){
54
+ console.log(
55
+ `
56
+ build/$:run led
57
+ led/tb.v led.v
58
+ `)
59
+ }
60
+
61
+ function main(){
62
+
63
+ switch (args[2]){
64
+ case "": install();break;
65
+ case "help": help();break;
66
+ }
67
+
68
+ }
69
+
70
+
71
+ main()
72
+
@@ -0,0 +1,58 @@
1
+ const child_process = require('child_process');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const M={};
6
+ M.exec = function (comand) {
7
+ let promise = new Promise(function (reslove, reject) {
8
+ child_process.exec(comand, function (err, stdout, stderr) {
9
+ if (err || stderr) console.error(err, stderr);
10
+ reslove(stdout);
11
+ });
12
+
13
+ })
14
+ return promise;
15
+ }
16
+
17
+ M.copyFile= (relfile)=>{
18
+ let dir=path.parse(relfile).dir;
19
+ if (!fs.existsSync(dir)) {
20
+ fs.mkdirSync(dir);
21
+ }
22
+ let srcText= fs.readFileSync(path.join(CUR_DIR,relfile), "utf-8");
23
+ fs.writeFileSync(relfile,srcText);
24
+ return true;
25
+ }
26
+ const checkDirectory = function (src, dst, callback) {
27
+ fs.access(dst, fs.constants.F_OK, (err) => {
28
+ if (err) {
29
+ fs.mkdirSync(dst);
30
+ callback(src, dst);
31
+ } else {
32
+ callback(src, dst);
33
+ }
34
+ });
35
+ };
36
+
37
+ M.copyDir = function (src, dst) {
38
+ if (!fs.existsSync(dst)) {
39
+ fs.mkdirSync(dst);
40
+ }
41
+ let paths = fs.readdirSync(src); //同步读取当前目录
42
+ paths.forEach(function (path) {
43
+ let _src = src + '/' + path;
44
+ let _dst = dst + '/' + path;
45
+ fs.stat(_src, function (err, stats) { //stats 该对�? 包含文件属�?
46
+ if (err) throw err;
47
+ if (stats.isFile()) { //如果是个文件则拷�?
48
+ let readable = fs.createReadStream(_src);//创建读取�?
49
+ let writable = fs.createWriteStream(_dst);//创建写入�?
50
+ readable.pipe(writable);
51
+ } else if (stats.isDirectory()) { //是目录则 递归
52
+ checkDirectory(_src, _dst, M.copyDir);
53
+ }
54
+ });
55
+ });
56
+ }
57
+
58
+ module.exports = M;
@@ -0,0 +1 @@
1
+ console.log("demo111")
@@ -0,0 +1 @@
1
+ console.log("hello word")
@@ -0,0 +1,27 @@
1
+ const child_process = require('child_process');
2
+ var args = process.argv.splice(2)
3
+ const M={};
4
+ M.exec = function (comand) {
5
+ let promise = new Promise(function (reslove, reject) {
6
+ child_process.exec(comand, function (err, stdout, stderr) {
7
+ if (err || stderr) console.error(err, stderr);
8
+ reslove(stdout);
9
+ });
10
+
11
+ })
12
+ return promise;
13
+ }
14
+ M.getFileNameByUrl=function (url){
15
+ let split= url.split("/");
16
+ return split[split.length-1]
17
+ }
18
+
19
+ async function main(){
20
+ let npr_pluginsPath=process.argv[1].replaceAll("\\install\\index.js","");
21
+ let fileName=M.getFileNameByUrl(args[2]).replace(".js","");
22
+ await M.exec(`mkdir ${npr_pluginsPath}\\${fileName}`)
23
+ await M.exec(`curl ${args[2]} > ${npr_pluginsPath}\\${fileName}\\index.js`)
24
+ console.log(fileName+" install success!")
25
+ }
26
+
27
+ main()
@@ -0,0 +1,20 @@
1
+ const child_process = require('child_process');
2
+
3
+ const M={};
4
+ M.exec = function (comand) {
5
+ let promise = new Promise(function (reslove, reject) {
6
+ child_process.exec(comand, function (err, stdout, stderr) {
7
+ if (err || stderr) console.error(err, stderr);
8
+ reslove(stdout);
9
+ });
10
+
11
+ })
12
+ return promise;
13
+ }
14
+
15
+ async function main(){
16
+ let npr_pluginsPath=process.argv[1].replaceAll("\\list\\index.js","");
17
+ let r= await M.exec("dir /b "+ npr_pluginsPath);
18
+ console.log(r.replaceAll(".idea",""));
19
+ }
20
+ main()
@@ -0,0 +1 @@
1
+ demo����򵥵ķ�������
@@ -0,0 +1,99 @@
1
+
2
+ module breath_led(
3
+ input clk , //系统时钟 50MHz
4
+ input rst_n , //系统复位,低电平有效
5
+ output reg led //LED灯
6
+ );
7
+
8
+
9
+ parameter CNT_2US_MAX = 7'd100;
10
+ parameter CNT_2MS_MAX = 10'd1000;
11
+ parameter CNT_2S_MAX = 10'd1000;
12
+
13
+ //reg define
14
+ reg [6:0] cnt_2us=0;
15
+ reg [9:0] cnt_2ms=0;
16
+ reg [9:0] cnt_2s=0;
17
+ reg inc_dec_flag; //亮度递增/递减 0:递增 1:递减
18
+
19
+ wire add_cnt_2us;
20
+ wire end_cnt_2us;
21
+ wire add_cnt_2ms;
22
+ wire end_cnt_2ms;
23
+ wire add_cnt_2s;
24
+ wire end_cnt_2s;
25
+
26
+
27
+ assign add_cnt_2us = 1;
28
+ assign end_cnt_2us = add_cnt_2us && cnt_2us== CNT_2US_MAX-1;
29
+
30
+ assign add_cnt_2ms= end_cnt_2us;
31
+ assign end_cnt_2ms= add_cnt_2ms && cnt_2ms == CNT_2MS_MAX - 1;
32
+
33
+ assign add_cnt_2s= end_cnt_2ms;
34
+ assign end_cnt_2s= add_cnt_2s && cnt_2s == CNT_2S_MAX - 1;
35
+
36
+
37
+ //cnt_2us:计数2us
38
+ always @(posedge clk or negedge rst_n)begin
39
+ if(!rst_n)begin
40
+ cnt_2us <= 0;
41
+ end
42
+ else if(add_cnt_2us)begin
43
+ if(end_cnt_2us)
44
+ cnt_2us <= 0;
45
+ else
46
+ cnt_2us <= cnt_2us + 1;
47
+ end
48
+ end
49
+
50
+ //cnt_2ms:计数2ms
51
+ always@(posedge clk or negedge rst_n) begin
52
+ if(!rst_n)
53
+ cnt_2ms <= 10'b0;
54
+ else if(add_cnt_2ms) begin
55
+ if(end_cnt_2ms)
56
+ cnt_2ms <= 10'b0;
57
+ else
58
+ cnt_2ms <= cnt_2ms + 1;
59
+ end
60
+ end
61
+
62
+ //cnt_2s:计数2s
63
+ always@(posedge clk or negedge rst_n) begin
64
+ if(!rst_n)
65
+ cnt_2s <= 0;
66
+ else if(add_cnt_2s) begin
67
+ if(end_cnt_2s)
68
+ cnt_2s <= 10'b0;
69
+ else
70
+ cnt_2s <= cnt_2s + 1;
71
+ end
72
+ end
73
+
74
+
75
+
76
+
77
+
78
+
79
+ //inc_dec_flag为低电平,led灯由暗变亮,inc_dec_flag为高电平,led灯由亮变暗
80
+ always@(posedge clk or negedge rst_n) begin
81
+ if(!rst_n)
82
+ inc_dec_flag <= 1'b0;
83
+ else if(end_cnt_2s && end_cnt_2ms && end_cnt_2us)
84
+ inc_dec_flag <= ~inc_dec_flag;
85
+ else
86
+ inc_dec_flag <= inc_dec_flag;
87
+ end
88
+
89
+ //led:输出信号连接到外部的led灯
90
+ always@(posedge clk or negedge rst_n) begin
91
+ if(!rst_n)
92
+ led <= 1'b0;
93
+ else if((inc_dec_flag == 1'b1 && cnt_2ms >= cnt_2s) || (inc_dec_flag == 1'b0 && cnt_2ms <= cnt_2s))
94
+ led <= 1'b1;
95
+ else
96
+ led <= 1'b0;
97
+ end
98
+
99
+ endmodule
@@ -0,0 +1,39 @@
1
+ `timescale 1ns / 1ns
2
+
3
+ module tb;
4
+
5
+ // 10ns
6
+ parameter PERIOD = 10 ;
7
+ parameter CNT_2US_MAX = 7'd10 ;
8
+ parameter CNT_2MS_MAX = 10'd100;
9
+ parameter CNT_2S_MAX = 10'd100;
10
+
11
+ // breath_led Inputs
12
+ reg sys_clk = 0 ;
13
+ reg sys_rst_n = 0 ;
14
+
15
+ // breath_led Outputs
16
+ wire led ;
17
+
18
+
19
+ initial
20
+ begin
21
+ forever #(PERIOD/2) sys_clk=~sys_clk;
22
+ end
23
+
24
+ initial
25
+ begin
26
+ #(PERIOD*2) sys_rst_n = 1;
27
+ end
28
+
29
+ breath_led #(
30
+ .CNT_2US_MAX ( CNT_2US_MAX ),
31
+ .CNT_2MS_MAX ( CNT_2MS_MAX ),
32
+ .CNT_2S_MAX ( CNT_2S_MAX ))
33
+ u_breath_led (
34
+ .clk ( sys_clk ),
35
+ .rst_n ( sys_rst_n ),
36
+ .led ( led )
37
+ );
38
+
39
+ endmodule
@@ -0,0 +1,12 @@
1
+
2
+
3
+ module led(
4
+ input key ,
5
+
6
+ output led
7
+ );
8
+
9
+
10
+ assign led = ~key;
11
+
12
+ endmodule
@@ -0,0 +1,25 @@
1
+ #setting parameter
2
+ work= work
3
+ output= ./
4
+ vsimbatch0= -do "run -all"
5
+
6
+
7
+ #commandbegin
8
+ all:compile vsim
9
+ lib:
10
+ echo "start compile for Questasim10.6c"
11
+ vlib $(work)
12
+ vmap work $(work)
13
+ vlog :
14
+ vlog -f filelist.f -l $(output)/compile.log
15
+ compile: lib vlog
16
+ run:
17
+ modelsim -do ./run.do
18
+ #make clean
19
+ clean:
20
+ del *.wlf
21
+ del vsim_stacktrace.vstf
22
+ del transcript
23
+ del compile.log
24
+ del modelsim.ini
25
+ rmdir /s /q work
@@ -0,0 +1,3 @@
1
+ vsim -voptargs=+acc work.tb
2
+ add wave -position insertpoint sim:/tb/*
3
+ run 100ns
@@ -0,0 +1,30 @@
1
+ `timescale 1ns / 1ns //���浥λ/���澫��
2
+
3
+ module tb();
4
+
5
+
6
+
7
+ reg key;
8
+ wire led;
9
+
10
+
11
+ initial begin
12
+ key <= 1'b1;
13
+ #2
14
+ key <= 1'b1;
15
+ #3
16
+ key <= 1'b0;
17
+ #2
18
+ key <= 1'b1;
19
+ #2
20
+ key <= 1'b0;
21
+ end
22
+
23
+ //����ledģ��
24
+ led u_led(
25
+ .key (key),
26
+ .led (led)
27
+ );
28
+
29
+ endmodule
30
+
@@ -0,0 +1,25 @@
1
+ const path = require('path');
2
+ var args = process.argv.splice(2)
3
+ var CUR_DIR=path.parse(process.argv[1]).dir;
4
+ const M=require("../common/ming_node");
5
+ async function install(dir){
6
+ M.copyDir(path.join(CUR_DIR,dir),dir);
7
+ }
8
+ async function help(){
9
+ let r=await M.exec("dir "+CUR_DIR);
10
+ console.log(r);
11
+ }
12
+
13
+ function main(){
14
+ switch (args[2]){
15
+ case "": install("led");break;
16
+ case "help": help();break;
17
+ default:{
18
+ install(args[2]);break;
19
+ }
20
+ }
21
+
22
+ }
23
+
24
+ main();
25
+
@@ -0,0 +1,57 @@
1
+ module key_debounce(
2
+ input clk,
3
+ input rst_n,
4
+ input key_in ,
5
+ output reg key_out
6
+ );
7
+
8
+ //计算器值
9
+ parameter MAX_CNT =10 ;
10
+ reg[7:0] cnt=0;
11
+ wire add_cnt;
12
+ wire end_cnt;
13
+ reg key_d0; //将按键信号延迟一个时钟周期
14
+ reg key_d1; //将按键信号延迟两个时钟周期
15
+
16
+ always @ (posedge clk or negedge rst_n) begin
17
+ if(!rst_n) begin
18
+ key_d0 <= 1'b1;
19
+ key_d1 <= 1'b1;
20
+ end
21
+ else begin
22
+ key_d0 <= key_in;
23
+ key_d1 <= key_d0;
24
+ end
25
+ end
26
+
27
+
28
+ //第一段:同步时序always模块,格式化描述次态寄存器迁移到现态寄存器(不需更改)
29
+ always @(posedge clk or negedge rst_n)begin
30
+ if(!rst_n)begin
31
+ cnt <= 0;
32
+ end
33
+ else if(add_cnt)begin
34
+ if(end_cnt)
35
+ cnt <= 0;
36
+ else
37
+ cnt <= cnt + 1;
38
+ end
39
+ end
40
+
41
+
42
+ //第二段:设计转移条件
43
+ assign add_cnt = cnt<MAX_CNT;
44
+ assign end_cnt = (add_cnt && cnt== MAX_CNT-1)||key_d1!=key_d0 ;
45
+
46
+
47
+ //第三段:同步时序always模块,输出
48
+ always @(posedge clk or negedge rst_n)begin
49
+ if(rst_n==1'b0)
50
+ key_out<=1'b1;
51
+ else if(cnt==MAX_CNT-1)
52
+ key_out<=key_d1;
53
+ end
54
+
55
+
56
+
57
+ endmodule