cleared lock semantics

This commit is contained in:
nvt-se 2008-05-28 13:17:08 +00:00
parent 7ca33e2285
commit 44c93fcd93

View file

@ -143,16 +143,18 @@ uart_set_handler(unsigned mode, fp_uart_handler fpHandler)
int int
uart_lock(unsigned mode) uart_lock(unsigned mode)
{ {
// already locked? if (uart_mode == mode) {
if (uart_mode != mode && uart_lockcnt > 0) { uart_lockcnt++;
return 0; return 1;
} }
// increase lock count if (uart_lockcnt == 0) {
uart_lockcnt++;
// switch mode (if neccessary)
uart_set_mode(mode); uart_set_mode(mode);
uart_lockcnt++;
return 1; return 1;
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
@ -167,22 +169,14 @@ uart_lock_wait(unsigned mode)
int int
uart_unlock(unsigned mode) uart_unlock(unsigned mode)
{ {
if ((uart_lockcnt == 0) || (mode != uart_mode)) { if (uart_lockcnt == 0 || mode != uart_mode) {
uart_lockcnt = 0;
uart_set_mode(UART_MODE_DEFAULT);
return 0; return 0;
} }
// decrement lock if (--uart_lockcnt == 0) {
if (uart_lockcnt > 0) {
uart_lockcnt--;
// if no more locks, switch back to default mode
if (uart_lockcnt == 0) {
uart_set_mode(UART_MODE_DEFAULT); uart_set_mode(UART_MODE_DEFAULT);
} }
return 1; return 1;
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -196,7 +190,6 @@ uart_set_mode(unsigned mode)
IE2 &= ~(URXIE1 | UTXIE1); // disable irq IE2 &= ~(URXIE1 | UTXIE1); // disable irq
uart_configure(mode); // configure uart parameters uart_configure(mode); // configure uart parameters
uart_mode = mode; uart_mode = mode;
uart_lockcnt = 0;
if (uart_handler[mode] != NULL) { if (uart_handler[mode] != NULL) {
IE2 |= URXIE1; // Enable USART1 RX interrupt IE2 |= URXIE1; // Enable USART1 RX interrupt