/// Initialize memory parameters.
///\return An error object.
XsError HostIoToMemory::GetSize(
    unsigned int const id,             ///< Memory module identifier.
    unsigned int       &rAddressWidth, ///< Address width.
    unsigned int       &rDataWidth     ///< Data width.
    )
{
    XsError error;

    mId           = BitBuffer( id, ID_FIELD_LENGTH ); // Store id for this memory.

    // Query memory for its address and data widths.
    BitBuffer params;
    unsigned int const SKIP_CYCLES = 1;
    error        |= HostIoCmd( mId, SIZE_OPCODE, SIZE_RESULT_LENGTH + SKIP_CYCLES, params );
    params.pop_front( SKIP_CYCLES );
    mAddressWidth = params.front( SIZE_RESULT_LENGTH / 2 ); // First 16 bits contain the address width.
    rAddressWidth = mAddressWidth;
    params.pop_front( SIZE_RESULT_LENGTH / 2 );             // Get rid of the address width.
    mDataWidth    = params.front( SIZE_RESULT_LENGTH / 2 ); // Next 16 bits contain the data width.
    rDataWidth    = mDataWidth;
    mLastError    = error;
    return error;
}
/// Read multiple, sequential addresses from memory device.
///\return An error object.
XsError HostIoToMemory::Read(
    MemoryAddressType const address,   ///< Starting address for reading memory.
    MemoryAddressType const numValues, ///< Number of values to get from memory.
    MemoryDataQueue         &rValues ) ///< Queue for storing values.
{
    assert( numValues > 0 );

    if ( mId.empty() )
    {
        mLastError = XsError( FATAL_XS_ERROR, "Trying to read from memory before querying its parameters!" );
        return mLastError;
    }

    // Now read the values starting from the given address.
    BitBuffer mem_vals;
    mLastError = HostIoCmd( mId, BitBuffer( address, mAddressWidth ) + READ_OPCODE, mDataWidth * ( numValues + 1 ), mem_vals );

    // Convert data bitstream into individual, multi-bit words and place them in output queue.
    mem_vals.pop_front( mDataWidth );
    while ( !mem_vals.empty() )
    {
        rValues.push_back( mem_vals.front( mDataWidth ) );
        mem_vals.pop_front( mDataWidth );
    }
    assert( rValues.size() == numValues );
    return mLastError;
}
/// Write multiple values to sequential addresses in memory device.
///\return An error object.
XsError HostIoToMemory::Write(
    MemoryAddressType const address,   ///< Starting address to write in memory.
    MemoryDataQueue const   &rValues ) ///< Values to write into memory.
{
    assert( rValues.size() > 0 );

    if ( mId.empty() ) // Error if memory parameters not queried before trying to write it.
    {
        mLastError = XsError( FATAL_XS_ERROR, "Trying to write to memory before querying its parameters!" );
        return mLastError;
    }

    // Convert data values into bitstreams.
    BitBuffer values;
    for ( unsigned int i = 0; i < rValues.size(); i++ )
        values.push_back( rValues[i], mDataWidth );

    // Now write data value bitstream to the given memory address.
    BitBuffer null;
    mLastError = HostIoCmd( mId, values + BitBuffer( address, mAddressWidth ) + WRITE_OPCODE, 0, null );
    return mLastError;
}
Example #4
0
void DhcpOption123::decode(uint8_t *input, size_t len)
{
	decode(BitBuffer(input, len));	
}