Skip to content

Commit

Permalink
tools/pbstate: Add clear/set API for board regs
Browse files Browse the repository at this point in the history
This commits adds a clear/set function that takes a clear and set mask.
This may be useful in situations where only modification if specific
bits is desired.

It might be dangerous to first call the read_board_reg function, perform
modifciations and then call the set_board_reg function since another
process might have done modifications to the register. The
clear_set_board_reg function will acquire the lock read/modify/write and
then release the lock.
  • Loading branch information
jonasblixt committed Sep 1, 2023
1 parent d58b280 commit dcabe0d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/pbstate/src/pbstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,19 @@ int pbstate_write_board_reg(unsigned int index, uint32_t value)

return close_and_save_state(fd, true);
}

int pbstate_clear_set_board_reg(unsigned int index, uint32_t clear, uint32_t set)
{
if (index > (PB_STATE_NO_OF_BOARD_REGS - 1))
return -EINVAL;

int fd = open_and_load_state(true);

if (fd < 0)
return fd;

state.board_regs[PB_STATE_NO_OF_BOARD_REGS - index - 1] &= ~clear;
state.board_regs[PB_STATE_NO_OF_BOARD_REGS - index - 1] |= set;

return close_and_save_state(fd, true);
}
12 changes: 12 additions & 0 deletions tools/pbstate/src/pbstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ int pbstate_read_board_reg(unsigned int index, uint32_t *value);
*/
int pbstate_write_board_reg(unsigned int index, uint32_t value);

/**
* Clear/set board register bits
*
* @param[in] index Board register index
* @param[in] clear Bits to clear
* @param[in] set Bits to set
*
* @return 0 on success
* -EINVAL on invalid index
*/
int pbstate_clear_set_board_reg(unsigned int index, uint32_t clear, uint32_t set);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit dcabe0d

Please sign in to comment.