/********************************************************************************* File: opentcp.c Date: 22.1.2004 Version: 0.1 Author: Jari Lahti (jari.lahti@violasystems.com) Description: General definions, bindings and includes of OpenTCP. Processor depended stuff like enable/disable IRQs. Helper functions. Version Info: 22.1.2004 - First version (JaL) *********************************************************************************/ #include "opentcp.h" /* Our network interface */ struct netif localmachine; /* TX buffer */ UINT8 otcp_netbuf[NETWORK_TX_BUFFER_SIZE]; /* Network transmit buffer */ /******************************************************************************** Function: otcp_strlen Parameters: UINT8* str - start address of string buffer UINT16 len - buffer length Return val: INT16 - (-1) Not a string (>=0) Length of string Date: 12.8.2002 Desc: Calculates the length of given string *********************************************************************************/ INT16 otcp_strlen (UINT8* buf, UINT16 len) { UINT16 i; for(i=0; i=0) Start of matched string from startadr Date: 12.7.2002 Desc: Seeks given string from given buffer *********************************************************************************/ INT16 otcp_bufsearch (UINT8* startadr, UINT16 len, UINT8* str, UINT8 caps) { UINT16 i; INT16 position; UINT8 matchesneeded; UINT8 matchesnow; UINT8* target; UINT8* key; target = startadr; position = -1; key = str; matchesnow = 0; matchesneeded = 0; /* How many matches we need? */ while( *key++ != '\0' ) { /* Break possible deadlock */ matchesneeded++; if(matchesneeded > 30) return(-1); } /* Search for first mark and continue searching if found */ key = str; for(i=0; i 96) ) return(ch - 32); return(ch); } /******************************************************************************** Function: otcp_tolower Parameters: UINT8 ch - ASCII character to be converted lowercase Return val: UINT8 - converted character Date: 21.8.2002 Desc: If ch is UPPERCASE letter it is converted to lowercase and returned. Otherwise original character is returned *********************************************************************************/ UINT8 otcp_tolower (UINT8 ch) { if( (ch < 91) && (ch > 64) ) return(ch + 32); return(ch); } /* Convert ASCII character to numerical */ /* e.g. '1' -> 0x01, 'A' ->0x0A */ UINT8 otcp_asciitohex (UINT8 ch) { if( (ch < 58) && (ch > 47) ) return(ch - 48); if( (ch < 71 ) && (ch > 64) ) return(ch - 55); return(0); } /* Take one byte and return its two ASCII */ /* values for both nibbles */ UINT16 otcp_hextoascii (UINT8 c) { UINT8 ch = c; UINT8 as1; UINT8 as2; /* take the char and turn it to ASCII */ as1 = ch; as1 >>= 4; as1 &= 0x0F; if ( as1<10 ) as1 += 48; else as1 += 55; as2 = ch; as2 &= 0x0F; if ( as2<10 ) as2 += 48; else as2 += 55; return( ((UINT16)(as1)<<8) + as2 ); } /* Is the given ASCII code numerical */ /* e.g. '0','1','2' ... '9' */ UINT8 otcp_isnumeric (UINT8 ch) { if( (ch < 58) && (ch > 47) ) return(1); return(0); } void otcp_ltoa (UINT32 nmbr, UINT8 *ch ) { /* Transforms value of long word to ASCII string */ /* Makes it iterative */ UINT16 multiple; UINT32 decade,comp; UINT8 i,found; /* Init String */ for( i=0; i<10;i++ ) *ch++ = '0'; ch -= 10; /* See if Zero */ if(nmbr == 0) { *ch++ = '0'; *ch = '\0'; } decade = 1000000000; found = FALSE; for( i=0; i<10; i++) { if(i != 0) decade /= 10; for( multiple=9; multiple>0; multiple--) { if( (i==0) && (multiple > 2) ) continue; comp = decade * multiple; if(nmbr >= comp) { *ch = otcp_hextoascii(multiple); nmbr -= comp; found = TRUE; break; /* Still processing */ } } if( found == TRUE) ch++; } *ch = '\0'; /* EOL */ } /* EOF */