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

simplify UART locking to reflect single thread of control #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
56 changes: 25 additions & 31 deletions Scan/UARTConnect/connect_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,6 @@
} \
}

// Macros for locking/unlock Tx buffers
#define uart_lockTx( uartNum ) \
{ \
/* First, secure place in line for the resource */ \
while ( uart_tx_status[ uartNum ].lock ); \
uart_tx_status[ uartNum ].lock = 1; \
/* Next, wait unit the UART is ready */ \
while ( uart_tx_status[ uartNum ].status != UARTStatus_Ready ); \
uart_tx_status[ uartNum ].status = UARTStatus_Wait; \
}

#define uart_lockBothTx( uartNum1, uartNum2 ) \
{ \
/* First, secure place in line for the resource */ \
while ( uart_tx_status[ uartNum1 ].lock || uart_tx_status[ uartNum2 ].lock ); \
uart_tx_status[ uartNum1 ].lock = 1; \
uart_tx_status[ uartNum2 ].lock = 1; \
/* Next, wait unit the UARTs are ready */ \
while ( uart_tx_status[ uartNum1 ].status != UARTStatus_Ready || uart_tx_status[ uartNum2 ].status != UARTStatus_Ready ); \
uart_tx_status[ uartNum1 ].status = UARTStatus_Wait; \
uart_tx_status[ uartNum2 ].status = UARTStatus_Wait; \
}

#define uart_unlockTx( uartNum ) \
{ \
/* Ready the UART */ \
uart_tx_status[ uartNum ].status = UARTStatus_Ready; \
/* Unlock the resource */ \
uart_tx_status[ uartNum ].lock = 0; \
}



// ----- Function Declarations -----
Expand Down Expand Up @@ -194,6 +163,31 @@ UARTRingBuf uart_tx_buf [UART_Num_Interfaces];
UARTStatusTx uart_tx_status[UART_Num_Interfaces];


// -- Functions for locking/unlocking Tx buffers --

// Note that these functions are mere placeholders, as the UARTs are not
// currently used by multiple execution contexts. If/when they are,
// they should be replaced by some sort of platform lock (such as a CAS
// and yield, or whatever lock the executive might provide).

static inline void uart_lockTx( int uartNum )
{
uart_tx_status[ uartNum ].lock = 1;
}

static inline void uart_lockBothTx( int uartNum1, int uartNum2 )
{
uart_lockTx( uartNum1 );
uart_lockTx( uartNum2 );
}

static inline void uart_unlockTx( int uartNum )
{
// FIXME: Is this necessary? Certainly it should be before unlock ...
uart_tx_status[ uartNum ].status = UARTStatus_Ready;
uart_tx_status[ uartNum ].lock = 0;
}

// -- Ring Buffer Convenience Functions --

void Connect_addBytes( uint8_t *buffer, uint8_t count, uint8_t uart )
Expand Down