16 #define MAX_TICK_ELAPSE 0x7FFFFFFF // Maximum elapse time you can set
18 typedef struct alarm_node_t {
19 struct alarm_node_t *next;
26 static alarm_node *alst = NULL;
29 static const int8 MimeBase64[] = {
30 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
31 'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
32 'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
33 'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
34 'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
35 'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
36 'w',
'x',
'y',
'z',
'0',
'1',
'2',
'3',
37 '4',
'5',
'6',
'7',
'8',
'9',
'+',
'/'
41 static int32 DecodeMimeBase64[256] = {
42 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
43 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
44 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
45 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
46 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
47 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
48 -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
49 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
50 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
51 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
52 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
53 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
54 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
55 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
56 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
57 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
80 alarm_node *aptr, **adbl;
82 if(time > MAX_TICK_ELAPSE || cb == NULL)
return RET_NOK;
88 while(*adbl && (*adbl)->time <= time) {
89 adbl = &(*adbl)->next;
93 *adbl = calloc(1,
sizeof(alarm_node));
96 ERRA(
"calloc fail - size(%d)",
sizeof(alarm_node));
100 (*adbl)->time = time;
122 alarm_node *aptr, **adbl = &alst;
125 if( (cb == NULL || (cb != NULL && ((*adbl)->cb == cb))) &&
126 (arg == -1 || (arg >= 0 && ((*adbl)->arg == arg))) )
130 DBGA(
"Del: CB(%p),ARG(%d)", (
void*)aptr->cb, aptr->arg);
133 }
else adbl = &(*adbl)->next;
154 alarm_node **adbl = &alst;
157 if( (cb == NULL || (cb != NULL && ((*adbl)->cb == cb))) &&
158 (arg == -1 || (arg >= 0 && ((*adbl)->arg == arg))) )
160 DBGA(
"Chk: CB(%p),ARG(%d)", (
void*)(*adbl)->cb, (*adbl)->arg);
163 adbl = &(*adbl)->next;
177 alarm_node *aptr = alst;
209 for(i=0; i<255; i++) {
212 if(dgt == 0)
return len;
235 if(method == NULL || str == NULL || *str == 0)
239 if(!method((
int)*str))
return RET_NOK;
257 int8 *
strsep(
register int8 **stringp,
register const int8 *delim)
260 register const int8 *spanp;
261 register int32 c, sc;
264 if ((s = *stringp) == NULL)
270 if ((sc = *spanp++) == c) {
290 uint8 *tp = (uint8*)buf;
292 uint16 line = len / 0x10;
293 uint16 left = len % 0x10;
295 LOG(
"===========================================================");
296 LOG(
"-ADDR----0--1--2--3--4--5--6--7----8--9--A--B--C--D--E--F--");
297 for(i=0; i<line; i++) {
298 LOGA(
"0x%04x %02x %02x %02x %02x %02x %02x %02x %02x"
299 " %02x %02x %02x %02x %02x %02x %02x %02x", 0x10*i,
300 tp[0x10*i+0x0], tp[0x10*i+0x1], tp[0x10*i+0x2], tp[0x10*i+0x3],
301 tp[0x10*i+0x4], tp[0x10*i+0x5], tp[0x10*i+0x6], tp[0x10*i+0x7],
302 tp[0x10*i+0x8], tp[0x10*i+0x9], tp[0x10*i+0xA], tp[0x10*i+0xB],
303 tp[0x10*i+0xC], tp[0x10*i+0xD], tp[0x10*i+0xE], tp[0x10*i+0xF]);
306 LOGFA(
"0x%04x ", 0x10*line);
307 for(i=0; i<left; i++)
LOGFA(
"%02x ", tp[0x10*line + i]);
310 LOG(
"===========================================================");
321 uint16 sum, tsum, i, j;
327 for(i = 0; i < j; i++) {
340 sum = ~(sum + (lsum >> 16));
368 int32 space_idx = 0, phase;
375 for ( cp = text; *cp !=
'\0'; ++cp ) {
376 d = DecodeMimeBase64[(int32) *cp];
383 c = ( ( prev_d << 2 ) | ( ( d & 0x30 ) >> 4 ) );
384 if ( space_idx < numBytes )
385 dst[space_idx++] = c;
389 c = ( ( ( prev_d & 0xf ) << 4 ) | ( ( d & 0x3c ) >> 2 ) );
390 if ( space_idx < numBytes )
391 dst[space_idx++] = c;
395 c = ( ( ( prev_d & 0x03 ) << 6 ) | d );
396 if ( space_idx < numBytes )
397 dst[space_idx++] = c;
419 uint8 input[3] = {0,0,0};
420 uint8 output[4] = {0,0,0,0};
424 plen = text + numBytes - 1;
427 for (i = 0, p = text;p <= plen; i++, p++) {
431 if (index == 2 || p == plen) {
432 output[0] = ((input[0] & 0xFC) >> 2);
433 output[1] = ((input[0] & 0x3) << 4) | ((input[1] & 0xF0) >> 4);
434 output[2] = ((input[1] & 0xF) << 2) | ((input[2] & 0xC0) >> 6);
435 output[3] = (input[2] & 0x3F);
437 encodedText[j++] = MimeBase64[output[0]];
438 encodedText[j++] = MimeBase64[output[1]];
439 encodedText[j++] = index == 0?
'=' : MimeBase64[output[2]];
440 encodedText[j++] = index < 2?
'=' : MimeBase64[output[3]];
442 input[0] = input[1] = input[2] = 0;
446 encodedText[j] =
'\0';
453 #ifdef USE_FULL_ASSERT
460 void assert_failed(uint8* file, uint32 line)