newrpl/firmware/sys/fsystem/misalign.c
2016-06-14 20:20:05 -04:00

32 lines
640 B
C

/*
* Copyright (c) 2014-2015, Claudio Lapilli and the newRPL Team
* All rights reserved.
* This file is released under the 3-clause BSD license.
* See the file LICENSE.txt that shipped with this distribution.
*/
// MISALIGNED READ/WRITE 16/32-BIT WORDS
unsigned int ReadInt32(char *ptr)
{
return (ptr[0]) | (ptr[1]<<8) | (ptr[2]<<16) | (ptr[3]<<24);
}
void WriteInt32(char *ptr,int value)
{
*ptr++=value&0xff;
*ptr++=(value>>8)&0xff;
*ptr++=(value>>16)&0xff;
*ptr=(value>>24)&0xff;
}
unsigned int ReadInt16(char *ptr)
{
return (ptr[0]) | (ptr[1]<<8);
}
void WriteInt16(char *ptr,int value)
{
*ptr++=value&0xff;
*ptr=(value>>8)&0xff;
}