This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! This program splits a kernel image file that has Device Tree Blobs (DTBs) appended to it. | |
//! It extracts the main kernel part and each DTB into separate files. | |
//! The kernel is saved as "kernel". DTBs are saved as "dtbdump_1.dtb", "dtbdump_2.dtb", etc. | |
const std = @import("std"); | |
const fs = std.fs; | |
const mem = std.mem; | |
const heap = std.heap; | |
const fmt = std.fmt; | |
const process = std.process; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const max_output_bytes = 4096; | |
pub fn main() !void { | |
var arena_state = std.heap.ArenaAllocator.init(std.heap.smp_allocator); | |
defer arena_state.deinit(); | |
const arena = arena_state.allocator(); | |
var file = try std.fs.openFileAbsolute("/dev/smd7", .{ .mode = .read_write }); | |
defer file.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const mem = std.mem; | |
const linux = std.os.linux; | |
const posix = std.posix; | |
const assert = std.debug.assert; | |
const testing = std.testing; | |
const AttrDataType = enum(u14) { | |
unspec, | |
u8, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allocation-free event loop inspired by uloop: fixed arrays, no heap allocations. | |
const std = @import("std"); | |
const mem = std.mem; | |
const posix = std.posix; | |
const linux = std.os.linux; | |
const testing = std.testing; | |
const log = std.log.scoped(.event_loop); | |
pub const MAX_EVENTS = 64; | |
pub const MAX_HANDLERS = 128; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn main() !void { | |
// Use the debug allocator. | |
var gpa_state: std.heap.DebugAllocator(.{}) = .init; | |
defer _ = gpa_state.deinit(); | |
const gpa = gpa_state.allocator(); | |
// Expect two arguments: <elf_file> and <prefix> | |
const args = try std.process.argsAlloc(gpa); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const file_version = &[_]u8{ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 }; | |
pub fn main() !void { | |
var gpa_state: std.heap.GeneralPurposeAllocator(.{}) = .init; | |
defer _ = gpa_state.deinit(); | |
const gpa = gpa_state.allocator(); | |
var raw = std.ArrayList(u8).init(gpa); | |
defer raw.deinit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const testing = std.testing; | |
const assert = std.debug.assert; | |
const IMEI = struct { | |
raw: [26]u8, | |
pub fn parse(imei_str: []const u8) !IMEI { | |
var imei: IMEI = undefined; | |
assert(imei_str.len == 15); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const mem = std.mem; | |
const hdlc = @This(); | |
const escape_char = '\x7d'; | |
const trailer_char = '\x7e'; | |
const Crc16Ccitt = std.hash.crc.Crc(u16, .{ | |
.polynomial = 0x11021, | |
.initial = 0x0000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <stdbool.h> | |
// Constants for HDLC framing | |
#define ESCAPE_CHAR 0x7D | |
#define TRAILER_CHAR 0x7E |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <libserialport.h> | |
int main() { | |
struct sp_port *port; | |
enum sp_return result; | |
// Open the serial port | |
const char *port_name = "/dev/ttyS0"; // Replace with your serial port name | |
result = sp_get_port_by_name(port_name, &port); |
NewerOlder