07-27-2023, 05:10 AM
(This post was last modified: 07-27-2023, 05:33 AM by WhiteHexagon.)
I think I got some kind of CPU thermal value, counting backwards just need to work out what value to use for CPU temperature shutdown, not that I am stressing the device too much yet
PS being able to do this in Zig is really nice, I get type safety on the poke() (saved me twice) and errors every time I miscount the bit flags in the registers, which saves me at least 3 times a day
I am still not sure on the naming scheme still, since the ADDR and REG are pretty much the same thing, but the usage below reads okay I think, and I want to be easily searchable for the register names in the 'User Manual'. Although probably I change the _ADDR to be _REG, and the _REG to be _VAL or _TYPE, not sure yet, will do some more work on the audio side and see what reads best It is not very linux like, but I am still trying to get my head around linux abstractions, device trees, file based drivers, etc etc. Just having some fun for now! Will also probably break down the CCU chapter into smaller manageable units, it's huge as I am sure you noticed!
PS being able to do this in Zig is really nice, I get type safety on the poke() (saved me twice) and errors every time I miscount the bit flags in the registers, which saves me at least 3 times a day
Code:
pub const THS_FILT_CTRL_ADDR = Reg32(THS_FILT_CTRL_REG, THS_BASE_ADDR + THS_FILTER);
pub const THS_FILT_CTRL_REG = packed struct(u32) {
FILTER_TYPE: Filter = Filter.TYPE4,
FILTER_EN: bool = false,
_3: u29 = 0,
pub const Filter = enum(u2) {
TYPE2 = 0b00,
TYPE4 = 0b01,
TYPE8 = 0b10,
TYPE16 = 0b11,
};
};
I am still not sure on the naming scheme still, since the ADDR and REG are pretty much the same thing, but the usage below reads okay I think, and I want to be easily searchable for the register names in the 'User Manual'. Although probably I change the _ADDR to be _REG, and the _REG to be _VAL or _TYPE, not sure yet, will do some more work on the audio side and see what reads best It is not very linux like, but I am still trying to get my head around linux abstractions, device trees, file based drivers, etc etc. Just having some fun for now! Will also probably break down the CCU chapter into smaller manageable units, it's huge as I am sure you noticed!
Code:
var fltr = thermals.THS_FILT_CTRL_ADDR.peek();
fltr.FILTER_TYPE = thermals.THS_FILT_CTRL_REG.Filter.TYPE8;
fltr.FILTER_EN = true;
thermals.THS_FILT_CTRL_ADDR.poke(fltr);