NetBurner 3.5.6
PDF Version
coldfire/include/basictypes.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
10/*
11 * Defintions of the basic data types.
12 */
13
14#ifndef _BASICTYPES_H_
15#define _BASICTYPES_H_
16#include <stddef.h>
17
18typedef unsigned char BOOL;
19typedef unsigned char BOOLEAN;
20typedef volatile unsigned char VBOOLEAN;
21typedef VBOOLEAN *PVBOOLEAN;
22typedef BOOLEAN *PBOOLEAN;
23typedef const BOOLEAN *PCBOOLEAN;
24
25typedef const char *PCSTR;
26typedef char *PSTR;
27
28#ifdef TRUE
29#undef TRUE
30#endif
31#define TRUE (1)
32#ifdef FALSE
33#undef FALSE
34#endif
35#define FALSE (0)
36#ifdef NULL
37#undef NULL
38#endif
39#define NULL (0)
40
41typedef signed char int8_t;
42typedef unsigned char uint8_t;
43typedef volatile signed char vint8_t;
44typedef volatile unsigned char vuint8_t;
45
46typedef signed short int16_t;
47typedef unsigned short uint16_t;
48typedef volatile signed short vint16_t;
49typedef volatile unsigned short vuint16_t;
50
51typedef signed long int32_t;
52typedef unsigned long uint32_t;
53typedef volatile signed long vint32_t;
54typedef volatile unsigned long vuint32_t;
55
56typedef signed long long int64_t;
57typedef unsigned long long uint64_t;
58typedef volatile signed long long vint64_t;
59typedef volatile unsigned long long vuint64_t;
60
61typedef signed char INT8;
62typedef unsigned char UINT8;
63typedef volatile signed char VINT8;
64typedef volatile unsigned char VUINT8;
65
66typedef signed short INT16;
67typedef unsigned short UINT16;
68typedef volatile signed short VINT16;
69typedef volatile unsigned short VUINT16;
70
71typedef signed long INT32;
72typedef unsigned long UINT32;
73typedef volatile signed long VINT32;
74typedef volatile unsigned long VUINT32;
75
76typedef vuint8_t *pvuint8_t;
77typedef vint8_t *pvint8_t;
78typedef vint16_t *pvint16_t;
79typedef vuint16_t *pvuint16_t;
80typedef vuint32_t *pvuint32_t;
81typedef vint32_t *pvint32_t;
82
83typedef unsigned char *puint8_t;
84typedef signed char *pint8_t;
85typedef signed short *pint16_t;
86typedef unsigned short *puint16_t;
87typedef unsigned long *puint32_t;
88typedef signed long *pint32_t;
89
90typedef const unsigned char *pcuint8_t;
91typedef const signed char *pcint8_t;
92typedef const signed short *pcint16_t;
93typedef const unsigned short *pcuint16_t;
94typedef const unsigned long *pcuint32_t;
95typedef const signed long *pcint32_t;
96
97#define beint16_t int16_t
98#define beuint16_t uint16_t
99#define beuint32_t uint32_t
100#define beint32_t int32_t
101
102#define pbeint16_t pint16_t
103#define pbeuint16_t puint16_t
104#define pbeuint32_t puint32_t
105#define pbeint32_t pint32_t
106
107#define vbeint16_t vint16_t
108#define vbeuint16_t vuint16_t
109#define vbeuint32_t vuint32_t
110#define vbeint32_t vint32_t
111
112#define pvbeint16_t pvint16_t
113#define pvbeuint16_t pvuint16_t
114#define pvbeuint32_t pvuint32_t
115#define pvbeint32_t pvint32_t
116
117typedef float befloat;
118typedef double bedouble;
119typedef volatile float vbefloat;
120typedef volatile double vbedouble;
121typedef float *pbefloat;
122typedef double *pbedouble;
123typedef volatile float *pvbefloat;
124typedef volatile double *pvbedouble;
125
126#ifdef __cplusplus
127typedef volatile bool vbool_t;
128typedef bool *pbool_t;
129typedef vbool_t *pvbool_t;
130
131inline uint16_t __REV16(uint16_t v)
132{
133 return ((v >> 8) & 0xFF) + ((v << 8) & 0xFF00);
134}
135inline int16_t __REVSH(int16_t v)
136{
137 return ((v >> 8) & 0xFF) + ((v << 8) & 0xFF00);
138};
139inline uint32_t __REV(uint32_t v)
140{
141 return ((v >> 24) & 0XFF) + ((v >> 8) & 0XFF00) + ((v << 24) & 0XFF000000) + ((v << 8) & 0x00FF0000);
142};
143inline int32_t __REV(int32_t v)
144{
145 return ((v >> 24) & 0XFF) + ((v >> 8) & 0XFF00) + ((v << 24) & 0XFF000000) + ((v << 8) & 0x00FF0000);
146};
147
148extern "C"
149void * memcpy(void *,const void*,size_t);
150inline float __REV(float f)
151{
152 uint32_t v;
153 memcpy(&v, &f, sizeof(float));
154 v = ((v >> 24) & 0XFF) + ((v >> 8) & 0XFF00) + ((v << 24) & 0XFF000000) + ((v << 8) & 0x00FF0000);
155 memcpy(&f, &v, sizeof(float));
156// f = *(float *)&v;
157 return f;
158}
159
160template<typename T>
161class LEu16
162{
163 T val;
164
165 public:
166 LEu16() = default;
167 // inline LEu16() : val(0) {}
168 inline LEu16(T rhs) : val(__REV16(rhs)) {}
169 inline LEu16(uint32_t &rhs) : val(__REV16((uint16_t)rhs)) {}
170 inline T operator=(T rhs)
171 {
172 val = __REV16(rhs);
173 return rhs;
174 }
175 inline operator T() const { return __REV16(val); }
176 inline explicit operator uint32_t() const { return __REV16(val); }
177 inline T getMem() { return val; }
178
179 inline T operator^=(T rhs)
180 {
181 val ^= __REV16(rhs);
182 return __REV16(val);
183 }
184 inline T operator|=(T rhs)
185 {
186 val |= __REV16(rhs);
187 return __REV16(val);
188 }
189 inline T operator&=(T rhs)
190 {
191 val &= __REV16(rhs);
192 return __REV16(val);
193 }
194 inline T operator%=(T rhs)
195 {
196 T ret = __REV16(val) % rhs;
197 val = __REV16(ret);
198 return ret;
199 }
200 inline T operator+=(T rhs)
201 {
202 T ret = __REV16(val) + rhs;
203 val = __REV16(ret);
204 return ret;
205 }
206 inline T operator-=(T rhs)
207 {
208 T ret = __REV16(val) - rhs;
209 val = __REV16(ret);
210 return ret;
211 }
212
213 inline T operator++()
214 {
215 T ret = __REV16(val) + 1;
216 val = __REV16(ret);
217 return ret;
218 }
219 inline T operator--()
220 {
221 T ret = __REV16(val) - 1;
222 val = __REV16(ret);
223 return ret;
224 }
225 inline T operator++(int)
226 {
227 T ret = __REV16(val);
228 val = __REV16(ret + 1);
229 return ret;
230 }
231 inline T operator--(int)
232 {
233 T ret = __REV16(val);
234 val = __REV16(ret - 1);
235 return ret;
236 }
237} __attribute__((packed));
238
239template<typename T>
240class LEs16
241{
242 T val;
243
244 public:
245 LEs16() = default;
246 // inline LEs16() : val(0) {}
247 inline LEs16(T rhs) : val(__REV16(rhs)) {}
248 inline LEs16(int32_t &rhs) : val(__REVSH((int16_t)rhs)) {}
249 inline T operator=(T rhs)
250 {
251 val = __REVSH(rhs);
252 return rhs;
253 }
254 inline operator T() const { return __REVSH(val); }
255 inline explicit operator int32_t() const { return (int32_t)(__REV16(val)); }
256 inline T getMem() { return val; }
257
258 inline T operator^=(T rhs)
259 {
260 val ^= __REVSH(rhs);
261 return __REVSH(val);
262 }
263 inline T operator|=(T rhs)
264 {
265 val |= __REVSH(rhs);
266 return __REVSH(val);
267 }
268 inline T operator&=(T rhs)
269 {
270 val &= __REVSH(rhs);
271 return __REVSH(val);
272 }
273 inline T operator%=(T rhs)
274 {
275 T ret = __REVSH(val) % rhs;
276 val = __REVSH(ret);
277 return ret;
278 }
279 inline T operator+=(T rhs)
280 {
281 T ret = __REVSH(val) + rhs;
282 val = __REVSH(ret);
283 return ret;
284 }
285 inline T operator-=(T rhs)
286 {
287 T ret = __REVSH(val) - rhs;
288 val = __REVSH(ret);
289 return ret;
290 }
291
292 inline T operator++()
293 {
294 T ret = __REVSSH(val) + 1;
295 val = __REV16(ret);
296 return ret;
297 }
298 inline T operator--()
299 {
300 T ret = __REVSH(val) - 1;
301 val = __REVSH(ret);
302 return ret;
303 }
304 inline T operator++(int)
305 {
306 T ret = __REVSH(val);
307 val = __REVSH(ret + 1);
308 return ret;
309 }
310 inline T operator--(int)
311 {
312 T ret = __REVSH(val);
313 val = __REVSH(ret - 1);
314 return ret;
315 }
316} __attribute__((packed));
317
318template<typename T>
319class LE32
320{
321 T val;
322
323 public:
324 LE32() = default;
325 // inline LE32() : val(0) {}
326 inline LE32(T rhs) : val(__REV(rhs)) {}
327 // LE32(IPADDR4 rhs);
328 inline T operator=(T rhs)
329 {
330 val = __REV(rhs);
331 return rhs;
332 }
333 inline operator T() const { return __REV(val); }
334 inline T getMem() { return val; }
335
336 inline T operator^=(T rhs)
337 {
338 val ^= __REV(rhs);
339 return __REV(val);
340 }
341 inline T operator|=(T rhs)
342 {
343 val |= __REV(rhs);
344 return __REV(val);
345 }
346 inline T operator&=(T rhs)
347 {
348 val &= __REV(rhs);
349 return __REV(val);
350 }
351 inline T operator%=(T rhs)
352 {
353 T ret = __REV(val) % rhs;
354 val = __REV(ret);
355 return ret;
356 }
357 inline T operator+=(T rhs)
358 {
359 T ret = __REV(val) + rhs;
360 val = __REV(ret);
361 return ret;
362 }
363 inline T operator-=(T rhs)
364 {
365 T ret = __REV(val) - rhs;
366 val = __REV(ret);
367 return ret;
368 }
369
370 inline T operator++()
371 {
372 T ret = __REVSSH(val) + 1;
373 val = __REV16(ret);
374 return ret;
375 }
376 inline T operator--()
377 {
378 T ret = __REV(val) - 1;
379 val = __REV(ret);
380 return ret;
381 }
382 inline T operator++(int)
383 {
384 T ret = __REV(val);
385 val = __REV(ret + 1);
386 return ret;
387 }
388 inline T operator--(int)
389 {
390 T ret = __REV(val);
391 val = __REV(ret - 1);
392 return ret;
393 }
394
395} __attribute__((packed));
396
397class LE_Float
398{
399 union {
400 float val;
401 uint8_t valBuf[4];
402 };
403
404 public:
405 LE_Float() = default;
406 // inline BE32() : val(0) {}
407 inline LE_Float(float rhs) : val(__REV(rhs)) {}
408 // BE32(IPADDR4 rhs);
409 inline float operator=(float rhs)
410 {
411 val = __REV(rhs);
412 return rhs;
413 }
414 inline operator float() const { return __REV(val); }
415 inline float getMem() { return val; }
416
417 inline float operator+=(float rhs)
418 {
419 float ret = __REV(val) + rhs;
420 val = __REV(ret);
421 return ret;
422 }
423 inline float operator-=(float rhs)
424 {
425 float ret = __REV(val) - rhs;
426 val = __REV(ret);
427 return ret;
428 }
429
430 inline float operator++()
431 {
432 float ret = __REV(val) + 1;
433 val = __REV16(ret);
434 return ret;
435 }
436 inline float operator--()
437 {
438 float ret = __REV(val) - 1;
439 val = __REV(ret);
440 return ret;
441 }
442 inline float operator++(int)
443 {
444 float ret = __REV(val);
445 val = __REV(ret + 1);
446 return ret;
447 }
448 inline float operator--(int)
449 {
450 float ret = __REV(val);
451 val = __REV(ret - 1);
452 return ret;
453 }
454
455 inline float operator=(float rhs) volatile
456 {
457 val = __REV(rhs);
458 return rhs;
459 }
460 inline float getMem() volatile { return val; }
461 inline operator float() const volatile { return __REV(val); }
462
463 inline float operator+=(float rhs) volatile
464 {
465 float ret = __REV(val) + rhs;
466 val = __REV(ret);
467 return ret;
468 }
469 inline float operator-=(float rhs) volatile
470 {
471 float ret = __REV(val) - rhs;
472 val = __REV(ret);
473 return ret;
474 }
475
476 inline float operator++() volatile
477 {
478 float ret = __REV(val) + 1;
479 val = __REV16(ret);
480 return ret;
481 }
482 inline float operator--() volatile
483 {
484 float ret = __REV(val) - 1;
485 val = __REV(ret);
486 return ret;
487 }
488 inline float operator++(int) volatile
489 {
490 float ret = __REV(val);
491 val = __REV(ret + 1);
492 return ret;
493 }
494 inline float operator--(int) volatile
495 {
496 float ret = __REV(val);
497 val = __REV(ret - 1);
498 return ret;
499 }
500
501 // friend inline float operator<<(BE32<T> lhs, unsigned int shift)
502 // { return (__REV(lhs.val)) << shift; }
503 // friend inline float operator>>(BE32<T> lhs, unsigned int shift)
504 // { return (__REV(lhs.val)) >> shift; }
505} __attribute__((packed));
506
507class LE_Double
508{
509 union {
510 double val;
511 uint8_t valBuf[8];
512 };
513
514 public:
515 LE_Double() = default;
516 // inline BE32() : val(0) {}
517 inline LE_Double(double rhs)
518 :valBuf{
519 (uint8_t)(((uint64_t)rhs)>>56),(uint8_t)(((uint64_t)rhs)>>48),
520 (uint8_t)(((uint64_t)rhs)>>40),(uint8_t)(((uint64_t)rhs)>>32),
521 (uint8_t)(((uint64_t)rhs)>>24),(uint8_t)(((uint64_t)rhs)>>16),
522 (uint8_t)(((uint64_t)rhs)>> 8),(uint8_t)(((uint64_t)rhs)>> 0)
523 }
524 { }
525 // BE32(IPADDR4 rhs);
526 inline double operator=(double rhs)
527 {
528 valBuf[0] = (uint8_t)(((uint64_t)rhs)>>56);
529 valBuf[1] = (uint8_t)(((uint64_t)rhs)>>48),
530 valBuf[2] = (uint8_t)(((uint64_t)rhs)>>40);
531 valBuf[3] = (uint8_t)(((uint64_t)rhs)>>32);
532 valBuf[4] = (uint8_t)(((uint64_t)rhs)>>24);
533 valBuf[5] = (uint8_t)(((uint64_t)rhs)>>16);
534 valBuf[6] = (uint8_t)(((uint64_t)rhs)>> 8);
535 valBuf[7] = (uint8_t)(((uint64_t)rhs)>> 0);
536 return rhs;
537 }
538 inline operator double() const
539 {
540 return (double)
541 (
542 (((uint64_t)valBuf[0])<<56) | (((uint64_t)valBuf[0])<<48)
543 | (((uint64_t)valBuf[0])<<40) | (((uint64_t)valBuf[0])<<32)
544 | (((uint64_t)valBuf[0])<<24) | (((uint64_t)valBuf[0])<<16)
545 | (((uint64_t)valBuf[0])<< 8) | (((uint64_t)valBuf[0])<< 0)
546 );
547 }
548 inline double getMem() { return val; }
549
550 inline double operator+=(double rhs)
551 {
552 double ret = ((double)(*this)) + rhs;
553 *this = ret;
554 return ret;
555 }
556 inline double operator-=(double rhs)
557 {
558 double ret = ((double)(*this)) - rhs;
559 *this = ret;
560 return ret;
561 }
562
563 inline double operator++()
564 {
565 double ret = ((double)(*this)) + 1;
566 *this = ret;
567 return ret;
568 }
569 inline double operator--()
570 {
571 double ret = ((double)(*this)) - 1;
572 *this = ret;
573 return ret;
574 }
575 inline double operator++(int)
576 {
577 double ret = ((double)(*this));
578 *this = ret + 1;
579 return ret;
580 }
581 inline double operator--(int)
582 {
583 double ret = ((double)(*this));
584 *this = ret - 1;
585 return ret;
586 }
587
588 inline double operator=(double rhs) volatile
589 {
590 valBuf[0] = (uint8_t)(((uint64_t)rhs)>>56);
591 valBuf[1] = (uint8_t)(((uint64_t)rhs)>>48),
592 valBuf[2] = (uint8_t)(((uint64_t)rhs)>>40);
593 valBuf[3] = (uint8_t)(((uint64_t)rhs)>>32);
594 valBuf[4] = (uint8_t)(((uint64_t)rhs)>>24);
595 valBuf[5] = (uint8_t)(((uint64_t)rhs)>>16);
596 valBuf[6] = (uint8_t)(((uint64_t)rhs)>> 8);
597 valBuf[7] = (uint8_t)(((uint64_t)rhs)>> 0);
598 return rhs;
599 }
600 inline double getMem() volatile { return val; }
601 inline operator double() const volatile
602 {
603 return (double)
604 (
605 (((uint64_t)valBuf[0])<<56) | (((uint64_t)valBuf[0])<<48)
606 | (((uint64_t)valBuf[0])<<40) | (((uint64_t)valBuf[0])<<32)
607 | (((uint64_t)valBuf[0])<<24) | (((uint64_t)valBuf[0])<<16)
608 | (((uint64_t)valBuf[0])<< 8) | (((uint64_t)valBuf[0])<< 0)
609 );
610 }
611
612 inline double operator+=(double rhs) volatile
613 {
614 double ret = ((double)(*this)) + rhs;
615 *this = ret;
616 return ret;
617 }
618 inline double operator-=(double rhs) volatile
619 {
620 double ret = ((double)(*this)) - rhs;
621 *this = ret;
622 return ret;
623 }
624
625 inline double operator++() volatile
626 {
627 double ret = ((double)(*this)) + 1;
628 *this = ret;
629 return ret;
630 }
631 inline double operator--() volatile
632 {
633 double ret = ((double)(*this)) - 1;
634 *this = ret;
635 return ret;
636 }
637 inline double operator++(int) volatile
638 {
639 double ret = ((double)(*this));
640 *this = ret + 1;
641 return ret;
642 }
643 inline double operator--(int) volatile
644 {
645 double ret = ((double)(*this));
646 *this = ret - 1;
647 return ret;
648 }
649
650 // friend inline double operator<<(BE32<T> lhs, unsigned int shift)
651 // { return (__REV(lhs.val)) << shift; }
652 // friend inline double operator>>(BE32<T> lhs, unsigned int shift)
653 // { return (__REV(lhs.val)) >> shift; }
654} __attribute__((packed));
655
656typedef LEs16<int16_t> leint16_t;
657typedef LEu16<uint16_t> leuint16_t;
658typedef LE32<uint32_t> leuint32_t;
659typedef LE32<uint32_t> leint32_t;
660
661typedef LEs16<int16_t> *pleint16_t;
662typedef LEu16<uint16_t> *pleuint16_t;
663typedef LE32<uint32_t> *pleuint32_t;
664typedef LE32<uint32_t> *pleint32_t;
665
666typedef LEs16<volatile int16_t> vleint16_t;
667typedef LEu16<volatile uint16_t> vleuint16_t;
668typedef LE32<volatile uint32_t> vleuint32_t;
669typedef LE32<volatile uint32_t> vleint32_t;
670
671typedef LEs16<volatile int16_t> *pvleint16_t;
672typedef LEu16<volatile uint16_t> *pvleuint16_t;
673typedef LE32<volatile uint32_t> *pvleuint32_t;
674typedef LE32<volatile uint32_t> *pvleint32_t;
675
676typedef LE_Float lefloat;
677typedef LE_Double ledouble;
678typedef volatile LE_Float vlefloat;
679typedef volatile LE_Double vledouble;
680typedef LE_Float *plefloat;
681typedef LE_Double *pledouble;
682typedef volatile LE_Float *pvlefloat;
683typedef volatile LE_Double *pvledouble;
684
685#ifdef MAKE_LEINT_TEST
686#include <stdio.h>
687void LEINT_TEST()
688{
689 uint8_t buf[4];
690 buf[0] = 0x01;
691 buf[1] = 0x23;
692 buf[2] = 0x45;
693 buf[3] = 0x67;
694
695 iprintf("int16_t=%08X\r\n", (int)(*((int16_t *)buf)));
696 iprintf("uint16_t=%08X\r\n", (unsigned int)(*((uint16_t *)buf)));
697 iprintf("int32_t=%08X\r\n", (int)(*((int32_t *)buf)));
698 iprintf("uint32_t=%08X\r\n", (unsigned int)(*((uint32_t *)buf)));
699
700 iprintf("leint16_t=%08X\r\n", (int)(*((leint16_t *)buf)));
701 iprintf("leuint16_t=%08X\r\n", (unsigned int)(*((leuint16_t *)buf)));
702 iprintf("leint32_t=%08X\r\n", (int)(*((leint32_t *)buf)));
703 iprintf("leuint32_t=%08X\r\n", (unsigned int)(*((leuint32_t *)buf)));
704}
705#endif
706#endif
707
708#define uint32_t_max (0xFFFFFFFF)
709
710#define HTONS(x) (x) // HTOBES(x)
711#define HTONL(x) (x) // HTOBEL(x)
712#define NTOHL(x) (x) // HTOBEL(x)
713#define NTOHS(x) (x) // HTOBES(x)
714
715#endif /* _BASICTYPES_H_ */