Shvets04 wrote:
Octocontrabass wrote:
You shouldn't copy someone else's code if you don't understand it.I suspect this mistake originates
in the wiki, where the example function reads 16-bit words despite configuration mechanism 1 functioning exclusively in 32-bit dwords.
where can i find correct function definition?
I take it there's a problem with this line?
Code:
tmp = (u16)((inw(0xCFC) >> ((offset & 2) * 8)) & 0xffff);
My guess would probably be inw, which is defined as u16 inw(u16 port) in your port.h. Those ports read and write 32 bits, so you read the full int and then break it up. This is how I do it in my OS, but my code isn't C/C++.
Code:
let (device_id, vendor_id) = read_2_words(address, 0x00);
fn read_2_words(address: u32, offset: u32) -> (u16, u16) {
let value = read_offset(address, offset);
let high_word = (value >> 16) as u16;
let low_word = value as u16;
(high_word, low_word)
}
fn read_offset(mut address: u32, offset: u32) -> u32 {
let mut config_address = Port::new(CONFIG_ADDRESS);
let mut data_address = Port::new(DATA_ADDRESS);
address |= offset & 0xFC;
unsafe {
config_address.write(address);
data_address.read()
}
}