utils.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. *
  3. *
  4. */
  5. #ifndef _ULT_H_
  6. #define _ULT_H_
  7. #include "time.h"
  8. /*************************************************************************************************/
  9. #ifndef FALSE
  10. #define FALSE 0
  11. #endif
  12. #ifndef TRUE
  13. //#define TRUE !(FALSE)
  14. #define TRUE 1
  15. #endif
  16. typedef union _u32_u8a_{
  17. uint32_t u32Data;
  18. uint8_t u8Data[4];
  19. }uConverterUint2Bytes;
  20. typedef union _u16_u8a_{
  21. uint32_t u16Data;
  22. uint8_t u8Data[2];
  23. }uConverterUshort2Bytes;
  24. typedef union _float_u8a_{
  25. float f32Data;
  26. uint8_t u8Data[4];
  27. }uConverterFloat2Bytes;
  28. #pragma pack(4)
  29. typedef struct _st_timer_
  30. {
  31. uint16_t flag;
  32. uint16_t enabled;
  33. uint16_t count;
  34. uint16_t limit;
  35. }stTickTimer,*pTickTimer;
  36. #pragma pack()
  37. /*
  38. typedef struct _rtc_time {
  39. uint16_t tm_sec;
  40. uint16_t tm_min;
  41. uint16_t tm_hour;
  42. uint16_t tm_mday;
  43. uint16_t tm_mon;
  44. uint16_t tm_year;
  45. uint16_t tm_wday;
  46. uint16_t tm_yday;
  47. }stRtcTime;*/
  48. typedef struct tm stRtcTime;
  49. typedef struct _time_set_value_
  50. {
  51. uint32_t tickReceived;
  52. uint32_t timeValue;
  53. }stTimeSetValue;
  54. #define SYS_Delay(us) Delay_us(us)
  55. /*************************************************************************************************/
  56. extern volatile stTickTimer keyScanTimer;
  57. extern volatile stTickTimer rakTimer;
  58. extern volatile stTickTimer senderTimer;
  59. extern volatile stTickTimer recordTimer;
  60. extern volatile stTickTimer tcpFlushTimer;
  61. extern volatile stTickTimer secondTimer;
  62. extern volatile stTickTimer halfMntTimer;
  63. extern stRtcTime rtcTime;
  64. extern volatile stTimeSetValue g_stTimeValue;
  65. /*************************************************************************************************/
  66. void RefreshTimer(void);
  67. void StartTimer(pTickTimer timer, uint32_t period);
  68. void StopTimer(pTickTimer timer);
  69. void ClearTimer(pTickTimer timer );
  70. void Systick_Init (unsigned char SYSCLK);
  71. void Delay_s( unsigned int time_s );
  72. void Delay_us(unsigned int time_us);
  73. void Delay_ms(unsigned int time_ms);
  74. unsigned short ATOI(char* str, unsigned char base); /* Convert a string to integer number */
  75. unsigned int ATOI32(char* str, unsigned char base); /* Convert a string to integer number */
  76. void itoa(unsigned int n, char* str, unsigned char len);
  77. int ValidATOI(char* str, int base, int* ret); /* Verify character string and Convert it to (hexa-)decimal. */
  78. char C2D(unsigned char c); /* Convert a character to HEX */
  79. unsigned short swaps(unsigned short i);
  80. unsigned int swapl(unsigned int l);
  81. void replacetochar(char * str, char oldchar, char newchar);
  82. void mid(char* src, char* s1, char* s2, char* sub);
  83. void inet_addr_(unsigned char* addr,unsigned char *ip);
  84. void rtcBySecondFromCentry(unsigned int time, stRtcTime *tm);
  85. void secondsFromCentry(const stRtcTime *tm, unsigned int * time);
  86. uint8_t BCC_CheckSum(uint8_t *buf, uint8_t len);
  87. unsigned int CalculateCRC16(unsigned char *updata, unsigned int len);
  88. int CRC16_Start();
  89. int CRC16_AddData(unsigned char *updata, unsigned int len);
  90. int CRC16_Finish();
  91. /*************************************************************************************************/
  92. #endif