os.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _Shark_OS_H__
  2. #define _Shark_OS_H__
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <time.h>
  9. #ifndef TRUE
  10. #define TRUE 1
  11. #endif
  12. #ifndef FALSE
  13. #define FALSE 0
  14. #endif
  15. typedef uint8_t u8;
  16. typedef uint16_t u16;
  17. typedef uint32_t u24;
  18. typedef uint32_t u32;
  19. typedef uint64_t u64;
  20. typedef int8_t s8;
  21. typedef int16_t s16;
  22. typedef int32_t s24;
  23. typedef int32_t s32;
  24. typedef int64_t s64;
  25. /* These types must be 16-bit, 32-bit or larger integer */
  26. typedef signed int S32;
  27. typedef unsigned int U32;
  28. typedef unsigned long int U64;
  29. /* These types must be 8-bit integer */
  30. typedef signed char S8;
  31. typedef unsigned char U8;
  32. /* These types must be 16-bit integer */
  33. typedef signed short S16;
  34. typedef unsigned short U16;
  35. typedef signed char int8;
  36. typedef signed short int16;
  37. typedef signed int int32;
  38. typedef unsigned char uint8;
  39. typedef unsigned short uint16;
  40. typedef unsigned int uint32;
  41. typedef struct{
  42. uint16_t year; /*YYYY*/
  43. uint8_t month;
  44. uint8_t day;
  45. uint8_t hour;
  46. uint8_t minute;
  47. uint8_t second;
  48. }time_val;
  49. void task_delay(int ms);
  50. void os_udelay(u32 us);
  51. uint32_t calendar_to_utc(time_val *time);
  52. void set_utc_time(time_val *time);
  53. void get_local_time(time_val *out, int8_t tz);
  54. uint32_t get_timestamp(void);
  55. uint32_t get_timestamp_with_time_zone(int8_t tz);
  56. #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
  57. #define min(a,b) (a>b?b:a)
  58. #define delay_us os_udelay
  59. static __inline__ void delay_ms(u32 ms) {
  60. os_udelay(ms*1000);
  61. }
  62. static __inline__ u16 DECODE_U16(u8 *buff) {
  63. return (((U16)(buff[1]) << 8) | buff[0]);
  64. }
  65. static __inline__ u32 DECODE_U24(u8 *buff) {
  66. return ((U32)(buff[2]) << 16 | DECODE_U16(buff));
  67. }
  68. static __inline__ u16 DECODE_U32(u8 *buff) {
  69. return ((U32)(buff[3]) << 24 | DECODE_U24(buff));
  70. }
  71. #endif /* _Shark_OS_H__ */