module gps_decoder(
input rx_clk,
input rx_data,
input reset,
output [7:0] latitude,
output [7:0] longitude,
output [7:0] altitude,
output [7:0] speed,
output [7:0] heading,
output [7:0] utc_hour,
output [7:0] utc_min,
output [7:0] utc_sec,
output [7:0] sat_count,
output [7:0] hdop
);
/*
*定义常量
*/
localparam BYTE_COUNT = 66; //NMEA消息的字节数
localparam DATA_START = 8; //数据开始的字节
/*
*定义寄存器
*/
reg [7:0] buffer [BYTE_COUNT-1:0];
reg [7:0] buffer_pointer = 0;
reg ready = 0;
reg process = 0;
/*
*定义部分GPS消息的字段
*/
reg [2:0] message_id;
reg [7:0] utc_time[3];
reg [7:0] latitude_b[3];
reg [7:0] longitude_b[3];
reg [7:0] altitude_b[3];
reg [7:0] speed_b[3];
reg [7:0] heading_b[3];
reg [7:0] sat_count_b;
reg [7:0] hdop_b[2];
/*
*状态机状态
*/
localparam IDLE = 0;
localparam RX = 1;
localparam PARSE = 2;
localparam ERROR = 3;
reg [1:0] state = IDLE;
/*
*等待启动
*/
always @(posedge rx_clk) begin
if (reset) begin
state <= IDLE;
buffer_pointer <= 0;
ready <= 0;
process <= 0;
end else begin
case(state)
IDLE: begin
if (rx_data == $8A) begin
buffer_pointer <= 0;
state <= RX;
end
end
RX: begin
buffer[buffer_pointer] <= rx_data;
buffer_pointer <= buffer_pointer+1;
state <= (buffer_pointer == BYTE_COUNT) ? PARSE : RX;
end
PARSE: begin
ready <= 1;
state <= IDLE;
process <= 1;
end
ERROR: begin
state <= IDLE;
buffer_pointer <= 0;
end
endcase
end
end
/*
*数据解析
*/
always @(posedge rx_clk) begin
if (process) begin
process <= 0;
if (buffer[3] == 'R' && buffer[4] == 'M' && buffer[5] == 'C') begin
message_id = 0;
sat_count_b = "00000000";
end else if (buffer[3] == 'G' && buffer[4] == 'G' && buffer[5] == 'A') begin
message_id = 1;
sat_count_b = buffer[8];
end else if (buffer[3] == 'G' && buffer[4] == 'L' && buffer[5] == 'L') begin
message_id = 2;
sat_count_b = buffer[8];
end else if (buffer[3] == 'G' && buffer[4] == 'S' && buffer[5] == 'A') begin
message_id = 3;
end else if (buffer[3] == 'G' && buffer[4] == 'S' && buffer[5] == 'V') begin
message_id = 4;
end else if (buffer[3] == 'G' && buffer[4] == 'S' && buffer[5] == 'T') begin
message_id = 5;
end else begin
message_id = -1;
end
case(message_id)
0: begin
//提取速度和航向信息
speed_b[0] = buffer[DATA_START+4];
speed_b[1] = buffer[DATA_START+5];
heading_b[0] = buffer[DATA_START+6];
heading_b[1] = buffer[DATA_START+7];
end
1, 2: begin
//提取UTC时间,纬度,经度,海拔信息
utc_time[0] = buffer[DATA_START];
utc_time[1] = buffer[DATA_START+1];
utc_time[2] = buffer[DATA_START+2];
latitude_b[0] = buffer[DATA_START+2];
latitude_b[1] = buffer[DATA_START+3];
latitude_b[2] = buffer[DATA_START+4];
longitude_b[0] = buffer[DATA_START+5];
longitude_b[1] = buffer[DATA_START+6];
longitude_b[2] = buffer[DATA_START+7];
altitude_b[0] = buffer[DATA_START+8];
altitude_b[1] = buffer[DATA_START+9];
verilog
本文将介绍Verilog语言的基础知识及其在FPGA开发中的应用,包括如何使用Verilog进行逻辑设计、综合与仿真,以及FPGA开发流程的概述。
摘要由CSDN通过智能技术生成