tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Waiting for a bit in a register to be cleared: which strategy?



Hello!
In order to read register A, I need to wait that a bit is cleared in
register B (which announces that the computation is over and the result
is available in register A). Both the registers are mapped in kernel
virtual address space through the bus_space(9) framework. This check is
inside a driver file.

As a temporary solution, I chose a brutal while with a brutal 32 bit
wise check:

#define NOT_CLEARED	0x0000001

while ((bus_space_read_4(mytag, myhandle, REG_A))
	& (uint32_t) NOT_CLEARED) {
}

result = bus_space_read_4(mytag, myhandle, REG_B);

This works only because REG_A has all 0s except the LSB: when the LSB
becomes 0, too, the while exits. But I am actually interested only in
the LSB and would like to disregard the other 7 bits in the register.
What could it be the most efficient way to accomplish this?

When a bit must be set, there's the macro __BIT(n) in

 <https://nxr.netbsd.org/xref/src/sys/sys/cdefs.h#640>

Is there something similar for when just a single bit must be read?

This way, if for some reason the LSB in REG_A is never cleared (the
device is not working, or similar), the while never exits. Is it
available, inside the kernel, some function like sleep, or wait, so
that a maximum timeout can be set?

Summarising, my guess for the best solution in this case is: reading a
single bit with something similar to __BIT and set a maximum amount of
time for the while cycle. If better solutions are available, I'm ready
to follow any suggestion.

Bye!

Rocky


Home | Main Index | Thread Index | Old Index