Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 260 → Rev 261

/shark/trunk/ports/tftp/include/endn.h
0,0 → 1,20
#ifndef __ENDIAN_H__
#define __ENDIAN_H__
 
/******************************************************************************
FUNCTION: SwapEndian
PURPOSE: Swap the byte order of a structure
EXAMPLE: float F=123.456;; SWAP_FLOAT(F);
******************************************************************************/
 
#define SWAP_SHORT(Var) Var = *(short*) SwapEndian((void*)&Var, sizeof(short))
#define SWAP_USHORT(Var) Var = *(unsigned short*)SwapEndian((void*)&Var, sizeof(short))
#define SWAP_LONG(Var) Var = *(long*) SwapEndian((void*)&Var, sizeof(long))
#define SWAP_ULONG(Var) Var = *(unsigned long*) SwapEndian((void*)&Var, sizeof(long))
#define SWAP_FLOAT(Var) Var = *(float*) SwapEndian((void*)&Var, sizeof(float))
#define SWAP_DOUBLE(Var) Var = *(double*) SwapEndian((void*)&Var, sizeof(double))
 
void *SwapEndian(void* Addr, const int Nb);
 
#endif
 
/shark/trunk/ports/tftp/endn.c
0,0 → 1,49
#include "endn.h"
 
/******************************************************************************
FUNCTION: SwapEndian
PURPOSE: Swap the byte order of a structure
EXAMPLE: float F=123.456;; SWAP_FLOAT(F);
******************************************************************************/
 
void *SwapEndian(void* Addr, const int Nb) {
static char Swapped[16];
switch (Nb) {
case 2: Swapped[0]=*((char*)Addr+1);
Swapped[1]=*((char*)Addr );
break;
case 4: Swapped[0]=*((char*)Addr+3);
Swapped[1]=*((char*)Addr+2);
Swapped[2]=*((char*)Addr+1);
Swapped[3]=*((char*)Addr );
break;
case 8: Swapped[0]=*((char*)Addr+7);
Swapped[1]=*((char*)Addr+6);
Swapped[2]=*((char*)Addr+5);
Swapped[3]=*((char*)Addr+4);
Swapped[4]=*((char*)Addr+3);
Swapped[5]=*((char*)Addr+2);
Swapped[6]=*((char*)Addr+1);
Swapped[7]=*((char*)Addr );
break;
case 16:Swapped[0]=*((char*)Addr+15);
Swapped[1]=*((char*)Addr+14);
Swapped[2]=*((char*)Addr+13);
Swapped[3]=*((char*)Addr+12);
Swapped[4]=*((char*)Addr+11);
Swapped[5]=*((char*)Addr+10);
Swapped[6]=*((char*)Addr+9);
Swapped[7]=*((char*)Addr+8);
Swapped[8]=*((char*)Addr+7);
Swapped[9]=*((char*)Addr+6);
Swapped[10]=*((char*)Addr+5);
Swapped[11]=*((char*)Addr+4);
Swapped[12]=*((char*)Addr+3);
Swapped[13]=*((char*)Addr+2);
Swapped[14]=*((char*)Addr+1);
Swapped[15]=*((char*)Addr );
break;
}
return (void*)Swapped;
}
 
/shark/trunk/ports/tftp/makefile
0,0 → 1,20
# TFTP
 
ifndef BASE
BASE=../..
endif
 
include $(BASE)/config/config.mk
 
LIBRARY = tftp
 
OBJS_PATH = $(BASE)/drivers/tftp
 
OBJS = tftp.o endn.o
 
OTHERINCL += -I$(BASE)/drivers/tftp/include
 
include $(BASE)/config/lib.mk
 
clean::
rm -f *.o