mirror of
https://github.com/lupyuen/pinephone-nuttx.git
synced 2025-01-13 05:08:32 +08:00
Adding Long Packet
This commit is contained in:
parent
5e33e3d476
commit
e2f6aa6dd7
1 changed files with 34 additions and 28 deletions
62
display.zig
62
display.zig
|
@ -90,43 +90,49 @@ fn compose_long_packet(
|
||||||
) []u8 {
|
) []u8 {
|
||||||
_ = buf;
|
_ = buf;
|
||||||
debug("compose_long_packet: channel={}, cmd={x}, len={}", .{ channel, cmd, len });
|
debug("compose_long_packet: channel={}, cmd={x}, len={}", .{ channel, cmd, len });
|
||||||
// Packet Header (4 bytes):
|
// Data Identifier (DI) (1 byte):
|
||||||
// TODO:
|
// Virtual Channel Identifier (Bits 6 to 7)
|
||||||
// - Data Identifier (DI) (1 byte):
|
// Data Type (Bits 0 to 5)
|
||||||
// Virtual Channel Identifier (Bits 6 to 7)
|
// (Virtual Channel should be 0, I think)
|
||||||
// Data Type (Bits 0 to 5)
|
assert(cmd < (1 << 6));
|
||||||
// (Virtual Channel should be 0, I think)
|
const vc: u8 = 0;
|
||||||
const dc = 0;
|
const dt: u8 = cmd;
|
||||||
|
const di: u8 = (vc << 6) | dt;
|
||||||
|
|
||||||
// - Word Count (WC) (2 bytes):
|
// Word Count (WC) (2 bytes):
|
||||||
// Number of bytes in the Packet Payload
|
// Number of bytes in the Packet Payload
|
||||||
const wc = @intCast(u16, len);
|
const wc: u16 = @intCast(u16, len);
|
||||||
const wcl = @intCast(u8, wc & 0xff);
|
const wcl: u8 = @intCast(u8, wc & 0xff);
|
||||||
const wch = @intCast(u8, wc >> 8);
|
const wch: u8 = @intCast(u8, wc >> 8);
|
||||||
|
|
||||||
// TODO:
|
// TODO: Error Correction Code (ECC) (1 byte):
|
||||||
// - Error Correction Code (ECC) (1 byte):
|
// Allow single-bit errors to be corrected and 2-bit errors to be detected in the Packet Header
|
||||||
// Allow single-bit errors to be corrected and 2-bit errors to be detected in the Packet Header
|
// See "12.3.6.12: Error Correction Code", Page 208:
|
||||||
// See "12.3.6.12: Error Correction Code", Page 208:
|
// https://github.com/sipeed/sipeed2022_autumn_competition/blob/main/assets/BL808_RM_en.pdf)
|
||||||
// https://github.com/sipeed/sipeed2022_autumn_competition/blob/main/assets/BL808_RM_en.pdf)
|
const ecc: u8 = 0;
|
||||||
const ecc = 0;
|
|
||||||
const header = [4]u8 { dc, wcl, wch, ecc };
|
// TODO: Checksum (CS) (2 bytes):
|
||||||
|
// 16-bit Cyclic Redundancy Check (CRC)
|
||||||
|
// See "12.3.6.13: Packet Footer", Page 210:
|
||||||
|
// https://github.com/sipeed/sipeed2022_autumn_competition/blob/main/assets/BL808_RM_en.pdf)
|
||||||
|
const cs: u16 = 0;
|
||||||
|
const csl: u8 = @intCast(u8, cs & 0xff);
|
||||||
|
const csh: u8 = @intCast(u8, cs >> 8);
|
||||||
|
|
||||||
|
// Packet Header (4 bytes): Data Identifier, Word Count, Error Correction COde
|
||||||
|
const header = [4]u8 { di, wcl, wch, ecc };
|
||||||
_ = header;
|
_ = header;
|
||||||
|
|
||||||
// Packet Payload:
|
// Packet Payload:
|
||||||
// - Data (0 to 65,541 bytes):
|
// Data (0 to 65,541 bytes):
|
||||||
// Number of data bytes should match the Word Count (WC)
|
// Number of data bytes should match the Word Count (WC)
|
||||||
assert(len <= 65_541);
|
assert(len <= 65_541);
|
||||||
|
|
||||||
// TODO: Packet Footer:
|
// Packet Footer: Checksum
|
||||||
// - Checksum (CS) (2 bytes):
|
const footer = [2]u8 { csl, csh };
|
||||||
// 16-bit Cyclic Redundancy Check (CRC)
|
|
||||||
// See "12.3.6.13: Packet Footer", Page 210:
|
|
||||||
// https://github.com/sipeed/sipeed2022_autumn_competition/blob/main/assets/BL808_RM_en.pdf)
|
|
||||||
const footer = [2]u8 { 0, 0 };
|
|
||||||
_ = footer;
|
_ = footer;
|
||||||
|
|
||||||
// TODO: Concatenate the header, payload and footer
|
// TODO: Packet = Packet Header + Payload + Packet Footer
|
||||||
var pkt = std.mem.zeroes([1024]u8);
|
var pkt = std.mem.zeroes([1024]u8);
|
||||||
assert(pkt.len >= header.len + len + footer.len); // Increase pkt size
|
assert(pkt.len >= header.len + len + footer.len); // Increase pkt size
|
||||||
std.mem.copy(u8, pkt[0..header.len], &header);
|
std.mem.copy(u8, pkt[0..header.len], &header);
|
||||||
|
|
Loading…
Reference in a new issue