Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix volatile warnings #3240

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/python/pyhal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@

lib.hal_link.argtypes = [c_char_p, c_char_p]

lib.hal_port_read.argtypes = [c_int, c_char_p, c_uint]
lib.hal_port_read.argtypes = [POINTER(c_int), c_char_p, c_uint]
lib.hal_port_read.restype = c_bool

lib.hal_port_peek.argtypes = [c_int, c_char_p, c_uint]
lib.hal_port_peek.argtypes = [POINTER(c_int), c_char_p, c_uint]
lib.hal_port_peek.restype = c_bool

lib.hal_port_peek_commit.argtypes = [c_int, c_char_p, c_uint]
lib.hal_port_peek_commit.argtypes = [POINTER(c_int), c_char_p, c_uint]
lib.hal_port_peek.restype = c_bool

lib.hal_port_write.argtypes = [c_int, c_char_p, c_uint]
lib.hal_port_write.argtypes = [POINTER(c_int), c_char_p, c_uint]
lib.hal_port_write.restype = c_bool

lib.hal_port_readable.argtypes = [c_int]
lib.hal_port_readable.argtypes = [POINTER(c_int)]
lib.hal_port_readable.restype = c_uint

lib.hal_port_writable.argtypes = [c_int]
lib.hal_port_writable.argtypes = [POINTER(c_int)]
lib.hal_port_writable.restype = c_uint

lib.hal_port_buffer_size.argtypes = [c_int]
lib.hal_port_buffer_size.argtypes = [POINTER(c_int)]
lib.hal_port_buffer_size.restype = c_uint

lib.hal_port_clear.argtypes = [c_int]
lib.hal_port_clear.argtypes = [POINTER(c_int)]

lib.hal_port_wait_readable.argtypes = [POINTER(POINTER(c_int)), c_uint, c_int]
lib.hal_port_wait_writable.argtypes = [POINTER(POINTER(c_int)), c_uint, c_int]
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, component, name, type, dir, data_ptr):

@property
def __port(self):
return self.data_ptr.contents.contents.value
return self.data_ptr.contents

def read(self, count):
if self.dir != pinDir.IN:
Expand Down
22 changes: 11 additions & 11 deletions src/hal/components/raster.comp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool float_eq(hal_float_t a, hal_float_t b) {
return fabs(a-b) < epsilon;
}

bool read_float(hal_port_t port, hal_float_t* value) {
bool read_float(const hal_port_t *port, hal_float_t* value) {
char data[32];
int available = hal_port_readable(port);
char* pos;
Expand All @@ -110,7 +110,7 @@ bool read_float(hal_port_t port, hal_float_t* value) {
return true;
}

bool read_int(hal_port_t port, hal_s32_t* value) {
bool read_int(const hal_port_t *port, hal_s32_t* value) {
char data[10];
long val;
int available = hal_port_readable(port);
Expand Down Expand Up @@ -148,7 +148,7 @@ bool read_int(hal_port_t port, hal_s32_t* value) {
pixels bpp must be defined in increments of 4.
a pixel value with all 1 bits is a special value considered "off" for the raster and no power will be output
*/
bool read_pixel_data(hal_port_t port, int bits_per_pixel, hal_float_t* power) {
bool read_pixel_data(const hal_port_t *port, int bits_per_pixel, hal_float_t* power) {
char data[8];
long value = 0;
unsigned int off = 0xFFFFFFFF >> (32 - bits_per_pixel);
Expand Down Expand Up @@ -190,7 +190,7 @@ FUNCTION(_) {
state = IDLE;
fault = 0;
fault_code = ERROR_NONE;
hal_port_clear(program);
hal_port_clear(program_ptr);
} else if (state == FAULT) {
fault = 1;
} else if (state == IDLE) {
Expand All @@ -202,19 +202,19 @@ FUNCTION(_) {
//when run is asserted, the port must be full of 1 line of raster data
if(run) {

if(!read_float(program, &program_offset)) {
if(!read_float(program_ptr, &program_offset)) {
state = FAULT;
fault_code = ERROR_INVALID_OFFSET;
} else if(!read_int(program, &bpp) || (bpp == 0) || (bpp > 32) || ((bpp % 4) != 0)) {
} else if(!read_int(program_ptr, &bpp) || (bpp == 0) || (bpp > 32) || ((bpp % 4) != 0)) {
state = FAULT;
fault_code = ERROR_INVALID_BPP;
} else if(!read_float(program, &ppu) || (ppu <= 0.0)) {
} else if(!read_float(program_ptr, &ppu) || (ppu <= 0.0)) {
state = FAULT;
fault_code = ERROR_INVALID_PPU;
} else if(!read_int(program, &count) || (count < 2)) {
} else if(!read_int(program_ptr, &count) || (count < 2)) {
state = FAULT;
fault_code = ERROR_INVALID_COUNT;
} else if(hal_port_readable(program) != ((bpp / 4) * count)) {
} else if(hal_port_readable(program_ptr) != ((bpp / 4) * count)) {
state = FAULT;
fault_code = ERROR_PROGWRONGSIZE;
} else {
Expand All @@ -227,7 +227,7 @@ FUNCTION(_) {

if(!run) {
state = IDLE;
hal_port_clear(program);
hal_port_clear(program_ptr);
} else {
enabled = 1;

Expand All @@ -236,7 +236,7 @@ FUNCTION(_) {
current_pixel_index = current_pixel_index+1;
previous_pixel_value = current_pixel_value;

if(!read_pixel_data(program, bpp, &current_pixel_value)) {
if(!read_pixel_data(program_ptr, bpp, &current_pixel_value)) {
state = FAULT;
fault_code = ERROR_BADPIXELDATA;
return;
Expand Down
16 changes: 8 additions & 8 deletions src/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ extern int hal_set_constructor(int comp_id, constructor make);
true: count bytes were read into dest
false: no bytes were read into dest
*/
extern bool hal_port_read(hal_port_t port, char* dest, unsigned count);
extern bool hal_port_read(const hal_port_t *port, char* dest, unsigned count);


/** hal_port_peek operates the same as hal_port_read but no bytes are consumed
Expand All @@ -876,7 +876,7 @@ extern bool hal_port_read(hal_port_t port, char* dest, unsigned count);
true: count bytes were read into dest
false: no bytes were read into dest
*/
extern bool hal_port_peek(hal_port_t port, char* dest, unsigned count);
extern bool hal_port_peek(const hal_port_t *port, char* dest, unsigned count);

/** hal_port_peek_commit advances the read position in the port buffer
by count bytes. A hal_port_peek followed by a hal_port_peek_commit
Expand All @@ -887,7 +887,7 @@ extern bool hal_port_peek(hal_port_t port, char* dest, unsigned count);
true: count readable bytes were skipped and are no longer accessible
false: no bytes wer skipped
*/
extern bool hal_port_peek_commit(hal_port_t port, unsigned count);
extern bool hal_port_peek_commit(const hal_port_t *port, unsigned count);

/** hal_port_write writes count bytes from src into the port.
This function should only be called by the component that owns
Expand All @@ -897,28 +897,28 @@ extern bool hal_port_peek_commit(hal_port_t port, unsigned count);
false: no bytes were written into dest

*/
extern bool hal_port_write(hal_port_t port, const char* src, unsigned count);
extern bool hal_port_write(const hal_port_t *port, const char* src, unsigned count);

/** hal_port_readable returns the number of bytes available
for reading from the port.
*/
extern unsigned hal_port_readable(hal_port_t port);
extern unsigned hal_port_readable(const hal_port_t *port);

/** hal_port_writable returns the number of bytes that
can be written into the port
*/
extern unsigned hal_port_writable(hal_port_t port);
extern unsigned hal_port_writable(const hal_port_t *port);

/** hal_port_buffer_size returns the total number of bytes
that a port can buffer
*/
extern unsigned hal_port_buffer_size(hal_port_t port);
extern unsigned hal_port_buffer_size(const hal_port_t *port);

/** hal_port_clear emptys a given port of all data
without consuming any of it.
hal_port_clear should only be called by a reader
*/
extern void hal_port_clear(hal_port_t port);
extern void hal_port_clear(const hal_port_t *port);


#ifdef ULAPI
Expand Down
68 changes: 35 additions & 33 deletions src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -3844,29 +3844,34 @@ static bool hal_port_compute_copy(unsigned read,
}


hal_port_t hal_port_alloc(unsigned size) {
int hal_port_alloc(unsigned size, hal_port_t *port) {
if(!port)
return -EINVAL;

hal_port_shm_t* new_port = shmalloc_up(sizeof(hal_port_shm_t) + size);

memset(new_port, 0, sizeof(hal_port_shm_t));
if(!new_port)
return -ENOMEM;

memset(new_port, 0, sizeof(hal_port_shm_t));
new_port->size = size;

return SHMOFF(new_port);
*port = SHMOFF(new_port);
return 0;
}


bool hal_port_read(hal_port_t port, char* dest, unsigned count) {
bool hal_port_read(const hal_port_t *port, char* dest, unsigned count) {
unsigned read,
write,
end_bytes_to_read, //number of bytes to read after read position and before end of buffer
beg_bytes_to_read, //number of bytes to read at beginning of buffer
final_pos; //final position after read
hal_port_shm_t* port_shm = SHMPTR(port);


if(!port || !count) {
if(!port || !*port || !count) {
return false;
} else {
hal_port_shm_t* port_shm = SHMPTR(*port);
hal_port_atomic_load(port_shm, &read, &write);

if(hal_port_compute_copy(read,
Expand All @@ -3888,17 +3893,17 @@ bool hal_port_read(hal_port_t port, char* dest, unsigned count) {
}


bool hal_port_peek(hal_port_t port, char* dest, unsigned count) {
bool hal_port_peek(const hal_port_t *port, char* dest, unsigned count) {
unsigned read,
write,
end_bytes_to_read, //number of bytes to read after read position and before end of buffer
beg_bytes_to_read, //number of bytes to read at beginning of buffer
final_pos; //final position of read
hal_port_shm_t* port_shm = SHMPTR(port);

if(!port || !count) {
if(!port || !*port || !count) {
return false;
} else {
hal_port_shm_t* port_shm = SHMPTR(*port);
hal_port_atomic_load(port_shm, &read, &write);

if(hal_port_compute_copy(read,
Expand All @@ -3919,17 +3924,17 @@ bool hal_port_peek(hal_port_t port, char* dest, unsigned count) {
}


bool hal_port_peek_commit(hal_port_t port, unsigned count) {
bool hal_port_peek_commit(const hal_port_t *port, unsigned count) {
unsigned read,
write,
end_bytes_to_read, //number of bytes to read after read position and before end of buffer
beg_bytes_to_read, //number of bytes to read at beginning of buffer
final_pos; //final position of read
hal_port_shm_t* port_shm = SHMPTR(port);

if(!port || !count) {
if(!port || !*port || !count) {
return false;
} else {
hal_port_shm_t* port_shm = SHMPTR(*port);
hal_port_atomic_load(port_shm, &read, &write);

if(hal_port_compute_copy(read,
Expand All @@ -3949,20 +3954,19 @@ bool hal_port_peek_commit(hal_port_t port, unsigned count) {
}


bool hal_port_write(hal_port_t port, const char* src, unsigned count) {
bool hal_port_write(const hal_port_t *port, const char* src, unsigned count) {
unsigned read,
write,
bytes_avail,
end_bytes_avail,
end_bytes_to_write,
beg_bytes_to_write,
final_pos;

hal_port_shm_t* port_shm = SHMPTR(port);

if(!port || !count) {
if(!port || !*port || !count) {
return false;
} else {
hal_port_shm_t* port_shm = SHMPTR(*port);
hal_port_atomic_load(port_shm, &read, &write);
bytes_avail = hal_port_bytes_writable(read, write, port_shm->size);

Expand Down Expand Up @@ -4002,42 +4006,40 @@ bool hal_port_write(hal_port_t port, const char* src, unsigned count) {
}


unsigned hal_port_readable(hal_port_t port) {
hal_port_shm_t* port_shm = SHMPTR(port);

if(!port) {
unsigned hal_port_readable(const hal_port_t *port) {
if(!port || !*port) {
return 0;
} else {
hal_port_shm_t* port_shm = SHMPTR(*port);
return hal_port_bytes_readable(port_shm->read, port_shm->write, port_shm->size);
}
}


unsigned hal_port_writable(hal_port_t port) {
hal_port_shm_t* port_shm = SHMPTR(port);

if(!port) {
unsigned hal_port_writable(const hal_port_t *port) {
if(!port || !*port) {
return 0;
} else {
hal_port_shm_t* port_shm = SHMPTR(*port);
return hal_port_bytes_writable(port_shm->read, port_shm->write, port_shm->size);
}
}


unsigned hal_port_buffer_size(hal_port_t port) {
if(!port) {
unsigned hal_port_buffer_size(const hal_port_t *port) {
if(!port || !*port) {
return 0;
} else {
return ((hal_port_shm_t*)SHMPTR(port))->size;
return ((hal_port_shm_t*)SHMPTR(*port))->size;
}
}


void hal_port_clear(hal_port_t port) {
void hal_port_clear(const hal_port_t *port) {
unsigned read,write;
hal_port_shm_t* port_shm = SHMPTR(port);

if(port) {
if(port && *port) {
hal_port_shm_t* port_shm = SHMPTR(*port);
hal_port_atomic_load(port_shm, &read, &write);
hal_port_atomic_store_read(port_shm, write);
}
Expand All @@ -4046,14 +4048,14 @@ void hal_port_clear(hal_port_t port) {

#ifdef ULAPI
void hal_port_wait_readable(hal_port_t** port, unsigned count, sig_atomic_t* stop) {
while((hal_port_readable(**port) < count) && (!stop || !*stop)) {
while((hal_port_readable(*port) < count) && (!stop || !*stop)) {
rtapi_delay(10000000);
}
}


void hal_port_wait_writable(hal_port_t** port, unsigned count, sig_atomic_t* stop) {
while((hal_port_writable(**port) < count) && (!stop || !*stop)) {
while((hal_port_writable(*port) < count) && (!stop || !*stop)) {
rtapi_delay(10000000);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/hal/hal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,11 @@ extern hal_pin_t *halpr_find_pin_by_sig(hal_sig_t * sig, hal_pin_t * start);


/** hal_port_alloc allocates a new empty hal_port having a buffer of size bytes.
returns a negative value on failure or a hal_port_t which can be used with
all other hal_port functions.
Returns a negative value on failure. On success zero (0) is returned and
the newly allocated hal_port_t is returned in the port argument and can be
used with all other hal_port functions.
*/
extern hal_port_t hal_port_alloc(unsigned size);
extern int hal_port_alloc(unsigned size, hal_port_t *port);



Expand Down
Loading