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

ONEWIRE: Change "variable style" by "pointer style" #514

Merged
merged 1 commit into from
Feb 27, 2023
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
4 changes: 2 additions & 2 deletions sw/lib/include/neorv32.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ enum NEORV32_GPTMR_CTRL_enum {
**************************************************************************/
/**@{*/
/** ONEWIRE module prototype */
typedef struct __attribute__((packed,aligned(4))) {
typedef volatile struct __attribute__((packed,aligned(4))) {
uint32_t CTRL; /**< offset 0: control register (#NEORV32_ONEWIRE_CTRL_enum) */
uint32_t DATA; /**< offset 4: transmission data register (#NEORV32_ONEWIRE_DATA_enum) */
} neorv32_onewire_t;
Expand All @@ -890,7 +890,7 @@ typedef struct __attribute__((packed,aligned(4))) {
#define NEORV32_ONEWIRE_BASE (0xFFFFFF70U)

/** ONEWIRE module hardware access (#neorv32_onewire_t) */
#define NEORV32_ONEWIRE (*((volatile neorv32_onewire_t*) (NEORV32_ONEWIRE_BASE)))
#define NEORV32_ONEWIRE ((neorv32_onewire_t*) (NEORV32_ONEWIRE_BASE))

/** ONEWIRE control register bits */
enum NEORV32_ONEWIRE_CTRL_enum {
Expand Down
40 changes: 20 additions & 20 deletions sw/lib/source/neorv32_onewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ int neorv32_onewire_available(void) {
int neorv32_onewire_setup(uint32_t t_base) {

// reset
NEORV32_ONEWIRE.CTRL = 0;
NEORV32_ONEWIRE.DATA = 0;
NEORV32_ONEWIRE->CTRL = 0;
NEORV32_ONEWIRE->DATA = 0;

const uint32_t PRSC_LUT[4] = {2, 4, 8, 64}; // subset of system clock prescalers

Expand Down Expand Up @@ -101,7 +101,7 @@ int neorv32_onewire_setup(uint32_t t_base) {
ctrl |= 1 << ONEWIRE_CTRL_EN; // module enable
ctrl |= (clk_prsc_sel & 0x3) << ONEWIRE_CTRL_PRSC0; // clock prescaler
ctrl |= ((clkdiv - 1) & 0xff) << ONEWIRE_CTRL_CLKDIV0; // clock divider
NEORV32_ONEWIRE.CTRL = ctrl;
NEORV32_ONEWIRE->CTRL = ctrl;

return (int)((t_clock_x250ps / 4) * PRSC_LUT[clk_prsc_sel] * clkdiv);
}
Expand All @@ -112,7 +112,7 @@ int neorv32_onewire_setup(uint32_t t_base) {
**************************************************************************/
void neorv32_onewire_enable(void) {

NEORV32_ONEWIRE.CTRL |= (1 << ONEWIRE_CTRL_EN);
NEORV32_ONEWIRE->CTRL |= (1 << ONEWIRE_CTRL_EN);
}


Expand All @@ -121,7 +121,7 @@ void neorv32_onewire_enable(void) {
**************************************************************************/
void neorv32_onewire_disable(void) {

NEORV32_ONEWIRE.CTRL &= ~(1 << ONEWIRE_CTRL_EN);
NEORV32_ONEWIRE->CTRL &= ~(1 << ONEWIRE_CTRL_EN);
}


Expand All @@ -132,7 +132,7 @@ void neorv32_onewire_disable(void) {
**************************************************************************/
int neorv32_onewire_sense(void) {

if (NEORV32_ONEWIRE.CTRL & (1 << ONEWIRE_CTRL_SENSE)) {
if (NEORV32_ONEWIRE->CTRL & (1 << ONEWIRE_CTRL_SENSE)) {
return 1;
}
else {
Expand All @@ -156,7 +156,7 @@ int neorv32_onewire_sense(void) {
int neorv32_onewire_busy(void) {

// check busy flag
if (NEORV32_ONEWIRE.CTRL & (1 << ONEWIRE_CTRL_BUSY)) {
if (NEORV32_ONEWIRE->CTRL & (1 << ONEWIRE_CTRL_BUSY)) {
return 1;
}
else {
Expand All @@ -173,7 +173,7 @@ int neorv32_onewire_busy(void) {
void neorv32_onewire_reset(void) {

// trigger reset-pulse operation
NEORV32_ONEWIRE.CTRL |= 1 << ONEWIRE_CTRL_TRIG_RST;
NEORV32_ONEWIRE->CTRL |= 1 << ONEWIRE_CTRL_TRIG_RST;
}


Expand All @@ -187,7 +187,7 @@ void neorv32_onewire_reset(void) {
int neorv32_onewire_reset_get_presence(void) {

// check presence bit
if (NEORV32_ONEWIRE.CTRL & (1 << ONEWIRE_CTRL_PRESENCE)) {
if (NEORV32_ONEWIRE->CTRL & (1 << ONEWIRE_CTRL_PRESENCE)) {
return 0;
}
else {
Expand All @@ -204,10 +204,10 @@ int neorv32_onewire_reset_get_presence(void) {
void neorv32_onewire_read_bit(void) {

// output all-one
NEORV32_ONEWIRE.DATA = 0xff;
NEORV32_ONEWIRE->DATA = 0xff;

// trigger bit operation
NEORV32_ONEWIRE.CTRL |= (1 << ONEWIRE_CTRL_TRIG_BIT);
NEORV32_ONEWIRE->CTRL |= (1 << ONEWIRE_CTRL_TRIG_BIT);
}


Expand All @@ -221,7 +221,7 @@ void neorv32_onewire_read_bit(void) {
uint8_t neorv32_onewire_read_bit_get(void) {

// return read bit
if (NEORV32_ONEWIRE.DATA & (1 << 7)) { // LSB first -> read bit is in MSB
if (NEORV32_ONEWIRE->DATA & (1 << 7)) { // LSB first -> read bit is in MSB
return 1;
}
else {
Expand All @@ -241,14 +241,14 @@ void neorv32_onewire_write_bit(uint8_t bit) {

// set replicated bit
if (bit) {
NEORV32_ONEWIRE.DATA = 0xff;
NEORV32_ONEWIRE->DATA = 0xff;
}
else {
NEORV32_ONEWIRE.DATA = 0x00;
NEORV32_ONEWIRE->DATA = 0x00;
}

// trigger bit operation
NEORV32_ONEWIRE.CTRL |= (1 << ONEWIRE_CTRL_TRIG_BIT);
NEORV32_ONEWIRE->CTRL |= (1 << ONEWIRE_CTRL_TRIG_BIT);
}


Expand All @@ -260,10 +260,10 @@ void neorv32_onewire_write_bit(uint8_t bit) {
void neorv32_onewire_read_byte(void) {

// output all-one
NEORV32_ONEWIRE.DATA = 0xff;
NEORV32_ONEWIRE->DATA = 0xff;

//trigger byte operation
NEORV32_ONEWIRE.CTRL |= (1 << ONEWIRE_CTRL_TRIG_BYTE);
NEORV32_ONEWIRE->CTRL |= (1 << ONEWIRE_CTRL_TRIG_BYTE);
}


Expand All @@ -277,7 +277,7 @@ void neorv32_onewire_read_byte(void) {
uint8_t neorv32_onewire_read_byte_get(void) {

// return read bit
return (uint8_t)(NEORV32_ONEWIRE.DATA);
return (uint8_t)(NEORV32_ONEWIRE->DATA);
}


Expand All @@ -291,10 +291,10 @@ uint8_t neorv32_onewire_read_byte_get(void) {
void neorv32_onewire_write_byte(uint8_t byte) {

// TX data
NEORV32_ONEWIRE.DATA = (uint32_t)byte;
NEORV32_ONEWIRE->DATA = (uint32_t)byte;

// and trigger byte operation
NEORV32_ONEWIRE.CTRL |= (1 << ONEWIRE_CTRL_TRIG_BYTE);
NEORV32_ONEWIRE->CTRL |= (1 << ONEWIRE_CTRL_TRIG_BYTE);
}


Expand Down