From 702a1368dc77a4deaf47fab5faafdc1ca754022d Mon Sep 17 00:00:00 2001 From: regehr Date: Tue, 3 Jun 2008 03:00:59 +0000 Subject: [PATCH] safe tinyos annotations --- tos/chips/atm128/Atm128UartP.nc | 4 ++-- tos/chips/atm128/adc/AdcStreamP.nc | 22 +++++++++++------- tos/chips/atm128/spi/Atm128SpiP.nc | 27 ++++++++++++---------- tos/chips/atm128/timer/HplAtm128Timer1P.nc | 8 +++---- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/tos/chips/atm128/Atm128UartP.nc b/tos/chips/atm128/Atm128UartP.nc index 2b904b41..527e264e 100644 --- a/tos/chips/atm128/Atm128UartP.nc +++ b/tos/chips/atm128/Atm128UartP.nc @@ -59,8 +59,8 @@ generic module Atm128UartP(){ implementation{ - norace uint8_t *m_tx_buf, *m_rx_buf; norace uint16_t m_tx_len, m_rx_len; + norace uint8_t *COUNT_NOK(m_tx_len) m_tx_buf, * COUNT_NOK(m_rx_len) m_rx_buf; norace uint16_t m_tx_pos, m_rx_pos; norace uint16_t m_byte_time; norace uint8_t m_rx_intr; @@ -159,8 +159,8 @@ implementation{ else if ( m_tx_buf ) return EBUSY; - m_tx_buf = buf; m_tx_len = len; + m_tx_buf = buf; m_tx_pos = 0; m_tx_intr = 1; call HplUart.enableTxIntr(); diff --git a/tos/chips/atm128/adc/AdcStreamP.nc b/tos/chips/atm128/adc/AdcStreamP.nc index 6bc47bc1..7d3701cc 100644 --- a/tos/chips/atm128/adc/AdcStreamP.nc +++ b/tos/chips/atm128/adc/AdcStreamP.nc @@ -68,13 +68,15 @@ implementation { /* Stream data */ struct list_entry_t { uint16_t count; - struct list_entry_t *next; + struct list_entry_t * ONE_NOK next; }; struct list_entry_t *bufferQueue[NSTREAM]; - struct list_entry_t **bufferQueueEnd[NSTREAM]; - uint16_t *lastBuffer, lastCount; + struct list_entry_t * ONE_NOK * bufferQueueEnd[NSTREAM]; + uint16_t * ONE_NOK lastBuffer, lastCount; - norace uint16_t *buffer, *pos, count; + norace uint16_t count; + norace uint16_t * COUNT_NOK(count) buffer; + norace uint16_t * FAT_NOK(buffer, buffer+count) pos; norace uint32_t now, period; @@ -108,7 +110,7 @@ implementation { return ESIZE; atomic { - struct list_entry_t *newEntry = (struct list_entry_t *)buf; + struct list_entry_t * ONE newEntry = TCAST(struct list_entry_t * ONE, buf); if (!bufferQueueEnd[c]) // Can't post right now. return FAIL; @@ -141,8 +143,10 @@ implementation { uint8_t c = client; atomic entry = bufferQueue[c]; - for (; entry; entry = entry->next) - signal ReadStream.bufferDone[c](FAIL, (uint16_t *)entry, entry->count); + for (; entry; entry = entry->next){ + uint16_t tmp_count = entry->count; + signal ReadStream.bufferDone[c](FAIL, TCAST(uint16_t * COUNT_NOK(tmp_count),entry), entry->count); + } atomic { @@ -200,11 +204,13 @@ implementation { } else { + uint16_t tmp_count; bufferQueue[client] = entry->next; if (!bufferQueue[client]) bufferQueueEnd[client] = &bufferQueue[client]; - pos = buffer = (uint16_t *)entry; count = entry->count; + tmp_count = count; + pos = buffer = TCAST(uint16_t * COUNT_NOK(tmp_count), entry); nextAlarm(); } } diff --git a/tos/chips/atm128/spi/Atm128SpiP.nc b/tos/chips/atm128/spi/Atm128SpiP.nc index da7f0629..ffa653cc 100644 --- a/tos/chips/atm128/spi/Atm128SpiP.nc +++ b/tos/chips/atm128/spi/Atm128SpiP.nc @@ -87,9 +87,9 @@ module Atm128SpiP { } } implementation { - uint8_t* txBuffer; - uint8_t* rxBuffer; uint16_t len; + uint8_t* COUNT_NOK(len) txBuffer; + uint8_t* COUNT_NOK(len) rxBuffer; uint16_t pos; enum { @@ -162,10 +162,12 @@ implementation { error_t sendNextPart() { uint16_t end; uint16_t tmpPos; - uint8_t* tx; - uint8_t* rx; + uint16_t myLen; + uint8_t* COUNT_NOK(myLen) tx; + uint8_t* COUNT_NOK(myLen) rx; atomic { + myLen = len; tx = txBuffer; rx = rxBuffer; tmpPos = pos; @@ -203,13 +205,14 @@ implementation { task void zeroTask() { - uint8_t* rx; - uint8_t* tx; uint16_t myLen; + uint8_t* COUNT_NOK(myLen) rx; + uint8_t* COUNT_NOK(myLen) tx; + atomic { + myLen = len; rx = rxBuffer; tx = txBuffer; - myLen = len; rxBuffer = NULL; txBuffer = NULL; len = 0; @@ -240,9 +243,9 @@ implementation { uint16_t bufLen) { uint8_t discard; atomic { + len = bufLen; txBuffer = writeBuf; rxBuffer = readBuf; - len = bufLen; pos = 0; } if (bufLen > 0) { @@ -279,15 +282,15 @@ implementation { sendNextPart(); } else { - uint8_t* rx; - uint8_t* tx; - uint16_t myLen; uint8_t discard; + uint16_t myLen; + uint8_t* COUNT_NOK(myLen) rx; + uint8_t* COUNT_NOK(myLen) tx; atomic { + myLen = len; rx = rxBuffer; tx = txBuffer; - myLen = len; rxBuffer = NULL; txBuffer = NULL; len = 0; diff --git a/tos/chips/atm128/timer/HplAtm128Timer1P.nc b/tos/chips/atm128/timer/HplAtm128Timer1P.nc index adaa66de..91f6ebf6 100644 --- a/tos/chips/atm128/timer/HplAtm128Timer1P.nc +++ b/tos/chips/atm128/timer/HplAtm128Timer1P.nc @@ -66,13 +66,13 @@ implementation //=== Read the control registers. ===================================== async command Atm128TimerCtrlCompare_t TimerCtrl.getCtrlCompare() { - return *(Atm128TimerCtrlCompare_t*)&TCCR1A; + return *(Atm128TimerCtrlCompare_t*ONE)&TCCR1A; } async command Atm128TimerCtrlCapture_t TimerCtrl.getCtrlCapture() { - return *(Atm128TimerCtrlCapture_t*)&TCCR1B; + return *(Atm128TimerCtrlCapture_t*ONE)&TCCR1B; } async command Atm128TimerCtrlClock_t TimerCtrl.getCtrlClock() { - return *(Atm128TimerCtrlClock_t*)&TCCR1C; + return *(Atm128TimerCtrlClock_t*ONE)&TCCR1C; } @@ -107,7 +107,7 @@ implementation //=== Read the interrupt flags. ===================================== async command Atm128_ETIFR_t TimerCtrl.getInterruptFlag() { - return *(Atm128_ETIFR_t*)&ETIFR; + return *(Atm128_ETIFR_t*ONE)&ETIFR; } //=== Write the interrupt flags. ==================================== -- 2.39.2