s600.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #pragma once
  2. #include "s600_config.h"
  3. #include "stdio.h"
  4. #define CAN_PIN_MAP_PA11_PA12 1
  5. #define CAN_PIN_MAP_PB8_PB9 2
  6. #define CAN_PIN_MAP_PD0_PD1 3
  7. #ifdef CONFIG_BOARD_S600
  8. #define CONFIG_BOARD_NAME "S600"
  9. #define CONFIG_CAN_ID 0x41
  10. #define CONFIG_CAN_PIN_MAP CAN_PIN_MAP_PA11_PA12
  11. #elif defined(CONFIG_BOARD_C200)
  12. #define CONFIG_BOARD_NAME "C200"
  13. #define CONFIG_CAN_ID 0x43
  14. #define CONFIG_CAN_PIN_MAP CAN_PIN_MAP_PB8_PB9
  15. #elif defined(CONFIG_BOARD_G580)
  16. #define CONFIG_BOARD_NAME "G580"
  17. #define CONFIG_CAN_ID 0x50
  18. #define CONFIG_CAN_PIN_MAP CAN_PIN_MAP_PB8_PB9
  19. #elif defined(CONFIG_BOARD_PS300)
  20. #define CONFIG_BOARD_NAME "PS300"
  21. #define CONFIG_CAN_ID 0x43
  22. #define CONFIG_CAN_PIN_MAP CAN_PIN_MAP_PB8_PB9
  23. #elif defined(CONFIG_BOARD_PS100)
  24. #define CONFIG_BOARD_NAME "PS100"
  25. #define CONFIG_CAN_ID 0x42
  26. #define CONFIG_CAN_PIN_MAP CAN_PIN_MAP_PB8_PB9
  27. #else
  28. #error "Invalid Board!"
  29. #endif
  30. #ifdef GD32E10X_H
  31. #define CONFIG_GD32E10X 1
  32. #define FMC_PAGE_SIZE 1024
  33. #endif
  34. #ifdef GD32F10X_H
  35. #define CONFIG_GD32F10X 1
  36. #ifdef GD32F10X_MD
  37. #define FMC_PAGE_SIZE 1024
  38. #else
  39. #define FMC_PAGE_SIZE 2048
  40. #endif
  41. #endif
  42. #define NELEM(a) \
  43. (sizeof(a) / sizeof((a)[0]))
  44. #define LAST_ELEM(a) \
  45. ((a)[NELEM(a) - 1])
  46. #define KB(value) \
  47. ((value) << 10)
  48. #define MB(value) \
  49. ((value) << 20)
  50. #define SYSTICK_SECONDS(value) \
  51. (SystemCoreClock * (value))
  52. #define SYSTICK_MSECONDS(value) \
  53. (SYSTICK_SECONDS(value) / 1000)
  54. #if S600_UART_PRINT
  55. #define println(fmt, args ...) \
  56. printf(fmt "\r\n", ##args)
  57. #define pr_pos_info() \
  58. println("%s:%d", __FILE__, __LINE__)
  59. #else
  60. #define println(fmt, args ...)
  61. #define pr_pos_info()
  62. #endif
  63. #define U32(value) \
  64. ((u32) (value))
  65. #define PU32(value) \
  66. ((u32 *) (value))
  67. #define U16(value) \
  68. ((u16) (value))
  69. #define PU16(value) \
  70. ((u16 *) (value))
  71. #define U8(value) \
  72. ((u8) (value))
  73. #define PU8(value) \
  74. ((u8 *) (value))
  75. #define DECODE_U16(buff) \
  76. (U16(buff[1]) << 8 | buff[0])
  77. #define DECODE_U24(buff) \
  78. (U32(buff[2]) << 16 | DECODE_U16(buff))
  79. #define DECODE_U32(buff) \
  80. (U32(buff[3]) << 24 | DECODE_U24(buff))
  81. typedef uint32_t u32;
  82. typedef int32_t s32;
  83. typedef uint16_t u16;
  84. typedef int16_t s16;
  85. typedef uint8_t u8;
  86. typedef int8_t s8;
  87. typedef void (*s600_command_t)(void);
  88. #ifdef CONFIG_GD32E10X
  89. typedef enum {
  90. false,
  91. true,
  92. } bool;
  93. #else
  94. #define true TRUE
  95. #define false FALSE
  96. #endif
  97. extern uint32_t SystemCoreClock;
  98. extern const u8 s600_value_char_map[];
  99. extern u32 s600_iap_100ms;
  100. u16 s600_get_avg_value(const u16 *values, u16 size);
  101. u32 s600_checksum_put(u32 checksum, const u8 *data, u16 size);
  102. u32 s600_checksum_put_value(u32 checksum, u16 value);
  103. u16 s600_checksum_finish(u32 checksum);
  104. u8 s600_char2value(char ch);
  105. u8 s600_month2value(const char *text);
  106. u16 s600_decode_u16(const u8 *buff);
  107. u32 s600_decode_u24(const u8 *buff);
  108. u32 s600_decode_u32(const u8 *buff);
  109. void s600_encode_u16(u8 *buff, u16 value);
  110. void s600_encode_u24(u8 *buff, u32 value);
  111. void s600_encode_u32(u8 *buff, u32 value);