From 44c93fcd9362a574bf2367c7af4b244acb917900 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Wed, 28 May 2008 13:17:08 +0000 Subject: [PATCH] cleared lock semantics --- platform/msb430/dev/msb430-uart1.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/platform/msb430/dev/msb430-uart1.c b/platform/msb430/dev/msb430-uart1.c index 468e47112..17075e515 100644 --- a/platform/msb430/dev/msb430-uart1.c +++ b/platform/msb430/dev/msb430-uart1.c @@ -143,16 +143,18 @@ uart_set_handler(unsigned mode, fp_uart_handler fpHandler) int uart_lock(unsigned mode) { - // already locked? - if (uart_mode != mode && uart_lockcnt > 0) { - return 0; + if (uart_mode == mode) { + uart_lockcnt++; + return 1; } - // increase lock count - uart_lockcnt++; - // switch mode (if neccessary) - uart_set_mode(mode); - return 1; + if (uart_lockcnt == 0) { + uart_set_mode(mode); + uart_lockcnt++; + return 1; + } + + return 0; } /*---------------------------------------------------------------------------*/ int @@ -167,22 +169,14 @@ uart_lock_wait(unsigned mode) int uart_unlock(unsigned mode) { - if ((uart_lockcnt == 0) || (mode != uart_mode)) { - uart_lockcnt = 0; - uart_set_mode(UART_MODE_DEFAULT); + if (uart_lockcnt == 0 || mode != uart_mode) { return 0; } - // decrement lock - if (uart_lockcnt > 0) { - uart_lockcnt--; - // if no more locks, switch back to default mode - if (uart_lockcnt == 0) { + if (--uart_lockcnt == 0) { uart_set_mode(UART_MODE_DEFAULT); - } - return 1; } - return 0; + return 1; } /*---------------------------------------------------------------------------*/ void @@ -196,7 +190,6 @@ uart_set_mode(unsigned mode) IE2 &= ~(URXIE1 | UTXIE1); // disable irq uart_configure(mode); // configure uart parameters uart_mode = mode; - uart_lockcnt = 0; if (uart_handler[mode] != NULL) { IE2 |= URXIE1; // Enable USART1 RX interrupt