X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fstm25p%2FStm25pLogP.nc;h=e454de79d88c27d03d5b8dafb4aca2e937632343;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=192b01b3eefc7a622e9cceb60dae7859d7b3b029;hpb=337d0b13acf569c2640b3ed7b7f5c7cec35d7ddd;p=tinyos-2.x.git diff --git a/tos/chips/stm25p/Stm25pLogP.nc b/tos/chips/stm25p/Stm25pLogP.nc index 192b01b3..e454de79 100644 --- a/tos/chips/stm25p/Stm25pLogP.nc +++ b/tos/chips/stm25p/Stm25pLogP.nc @@ -161,7 +161,7 @@ implementation { // don't allow appends larger than maximum record size if ( len > MAX_RECORD_SIZE ) - return ESIZE; + return EINVAL; // move to next block if current block doesn't have enough space if ( sizeof( m_header ) + len > bytes_left ) @@ -199,6 +199,18 @@ implementation { } + uint8_t calcSector( uint8_t client, stm25p_addr_t addr ) { + uint8_t sector = call Sector.getNumSectors[ client ](); + return (uint8_t)(( addr >> STM25P_SECTOR_SIZE_LOG2 ) % sector); + } + + stm25p_addr_t calcAddr( uint8_t client, stm25p_addr_t addr ) { + stm25p_addr_t result = calcSector( client, addr ); + result <<= STM25P_SECTOR_SIZE_LOG2; + result |= addr & STM25P_SECTOR_MASK; + return result; + } + event void ClientResource.granted[ uint8_t id ]() { // log never used, need to find start and end of log @@ -228,12 +240,14 @@ implementation { (storage_cookie_t)(writeSector-numSectors) <> STM25P_SECTOR_SIZE_LOG2 ) % sector; - } - - stm25p_addr_t calcAddr( uint8_t client, stm25p_addr_t addr ) { - stm25p_addr_t result = calcSector( client, addr ); - result <<= STM25P_SECTOR_SIZE_LOG2; - result |= addr & STM25P_SECTOR_MASK; - return result; - } - void continueReadOp( uint8_t client ) { stm25p_addr_t read_addr = m_log_info[ client ].read_addr; @@ -290,7 +292,7 @@ implementation { read_addr &= ~BLOCK_MASK; } else { - buf = m_log_state[ client ].buf; + buf = m_log_state[ client ].buf + m_log_state[ client ].len - m_len; // truncate if record is shorter than requested length if ( m_log_info[ client ].remaining < m_len ) len = m_log_info[ client ].remaining; @@ -317,7 +319,7 @@ implementation { switch( m_rw_state ) { case S_SEARCH_BLOCKS: { - uint8_t block = addr >> BLOCK_SIZE_LOG2; + uint16_t block = addr >> BLOCK_SIZE_LOG2; // record potential starting and ending addresses if ( m_addr != STM25P_INVALID_ADDRESS ) { if ( m_addr < log_info->read_addr ) @@ -340,7 +342,7 @@ implementation { else { log_info->write_addr += sizeof( m_addr ); m_rw_state = S_SEARCH_RECORDS; - call Sector.read[ id ]( log_info->write_addr, &m_header, + call Sector.read[ id ]( calcAddr(id, log_info->write_addr), &m_header, sizeof( m_header ) ); } } @@ -355,8 +357,8 @@ implementation { // if header is valid and is on same block, move to next record if ( m_header != INVALID_HEADER && cur_block == new_block ) { log_info->write_addr += sizeof( m_header ) + m_header; - call Sector.read[ id ]( log_info->write_addr, &m_header, - sizeof( m_header ) ); + call Sector.read[ id ]( calcAddr( id, log_info->write_addr ), + &m_header, sizeof( m_header ) ); } // found last record else { @@ -370,8 +372,8 @@ implementation { // searching for last log record to read log_info->read_addr += sizeof( m_header ) + m_header; // if not yet at cookie, keep searching - if ( log_info->read_addr < m_log_state->cookie ) { - call Sector.read[ id ]( log_info->read_addr, &m_header, + if ( log_info->read_addr < m_log_state[ id ].cookie ) { + call Sector.read[ id ]( calcAddr(id, log_info->read_addr), &m_header, sizeof( m_header ) ); } // at or passed cookie, stop @@ -454,7 +456,7 @@ implementation { // (the log could have cycled around) stm25p_addr_t volume_size = STM25P_SECTOR_SIZE * ( call Sector.getNumSectors[ id ]() - 1 ); - if ( m_log_info[ id ].write_addr >= volume_size ) { + if ( m_log_info[ id ].write_addr > volume_size ) { stm25p_addr_t read_addr = m_log_info[ id ].write_addr - volume_size; if ( m_log_info[ id ].read_addr < read_addr ) m_log_info[ id ].read_addr = read_addr;