sysmgr(5076).h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #ifndef _SYSMGR_H_
  2. #define _SYSMGR_H_
  3. #include "nrf_drv_spi.h"
  4. #include "app_util_platform.h"
  5. #include "nrf_gpio.h"
  6. #include "nrf_delay.h"
  7. #include "boards.h"
  8. #include "app_error.h"
  9. #include <string.h>
  10. #include "nrf_log.h"
  11. #include "nrf_log_ctrl.h"
  12. #include "nrf_log_default_backends.h"
  13. #include "ble_gap.h"
  14. #include "fds.h"
  15. #include "nrf_fstorage.h"
  16. struct stSystemTimer__ {
  17. volatile int MS_1;
  18. volatile int UART_LAST_RECV_TIMER;
  19. volatile int SEND_TEST_TIMER;
  20. volatile int LED_TOGGLE_TIMER;
  21. volatile int TMR_SYS_OFF;
  22. volatile int SEND_TIMER;
  23. volatile int BUZZER_TIMER;
  24. char EMG_SEND_RUN;
  25. volatile int TIM_KEY;
  26. volatile int SLEEP_TIMER;
  27. };
  28. typedef struct stSystemTimer__ stSystemTimer;
  29. struct stSystemManager__ {
  30. char EmgSendButton;
  31. char TestSendButton;
  32. char RxEvent;
  33. char SendRepeat;
  34. char SendFlag;
  35. int BleConnectTime;
  36. int SendRepeatTimerLimit;
  37. char BuzzerType;
  38. char BuzzerBusy;
  39. unsigned char Batt;
  40. char BleSendReady;
  41. char BleSendStatus;
  42. char BleConnected;
  43. char BleSendRetry;
  44. char PeerAddr[6];
  45. char StrPeerAddr[15];
  46. char RegPeerAddr[6];
  47. char StrRegPeerAddr[15];
  48. char SysReady;
  49. char SleepEnter;
  50. char FWUpdate;
  51. char GpReg;
  52. char GoSleep;
  53. uint32_t ResetReason;
  54. char AesEncData[16];
  55. };
  56. typedef struct stSystemManager__ stSystemManager;
  57. #define SC16IS750_ADDRESS_AA (0X90)
  58. #define SC16IS750_ADDRESS_AB (0X92)
  59. #define SC16IS750_ADDRESS_AC (0X94)
  60. #define SC16IS750_ADDRESS_AD (0X96)
  61. #define SC16IS750_ADDRESS_BA (0X98)
  62. #define SC16IS750_ADDRESS_BB (0X9A)
  63. #define SC16IS750_ADDRESS_BC (0X9C)
  64. #define SC16IS750_ADDRESS_BD (0X9E)
  65. #define SC16IS750_ADDRESS_CA (0XA0)
  66. #define SC16IS750_ADDRESS_CB (0XA2)
  67. #define SC16IS750_ADDRESS_CC (0XA4)
  68. #define SC16IS750_ADDRESS_CD (0XA6)
  69. #define SC16IS750_ADDRESS_DA (0XA8)
  70. #define SC16IS750_ADDRESS_DB (0XAA)
  71. #define SC16IS750_ADDRESS_DC (0XAC)
  72. #define SC16IS750_ADDRESS_DD (0XAE)
  73. //General Registers
  74. #define SC16IS750_REG_RHR (0x00)
  75. #define SC16IS750_REG_THR (0X00)
  76. #define SC16IS750_REG_IER (0X01)
  77. #define SC16IS750_REG_FCR (0X02)
  78. #define SC16IS750_REG_IIR (0X02)
  79. #define SC16IS750_REG_LCR (0X03)
  80. #define SC16IS750_REG_MCR (0X04)
  81. #define SC16IS750_REG_LSR (0X05)
  82. #define SC16IS750_REG_MSR (0X06)
  83. #define SC16IS750_REG_SPR (0X07)
  84. #define SC16IS750_REG_TCR (0X06)
  85. #define SC16IS750_REG_TLR (0X07)
  86. #define SC16IS750_REG_TXLVL (0X08)
  87. #define SC16IS750_REG_RXLVL (0X09)
  88. #define SC16IS750_REG_IODIR (0X0A)
  89. #define SC16IS750_REG_IOSTATE (0X0B)
  90. #define SC16IS750_REG_IOINTENA (0X0C)
  91. #define SC16IS750_REG_IOCONTROL (0X0E)
  92. #define SC16IS750_REG_EFCR (0X0F)
  93. //Special Registers
  94. #define SC16IS750_REG_DLL (0x00)
  95. #define SC16IS750_REG_DLH (0X01)
  96. //Enhanced Registers
  97. #define SC16IS750_REG_EFR (0X02)
  98. #define SC16IS750_REG_XON1 (0X04)
  99. #define SC16IS750_REG_XON2 (0X05)
  100. #define SC16IS750_REG_XOFF1 (0X06)
  101. #define SC16IS750_REG_XOFF2 (0X07)
  102. //
  103. #define SC16IS750_INT_CTS (0X80)
  104. #define SC16IS750_INT_RTS (0X40)
  105. #define SC16IS750_INT_XOFF (0X20)
  106. #define SC16IS750_INT_SLEEP (0X10)
  107. #define SC16IS750_INT_MODEM (0X08)
  108. #define SC16IS750_INT_LINE (0X04)
  109. #define SC16IS750_INT_THR (0X02)
  110. #define SC16IS750_INT_RHR (0X01)
  111. //Application Related
  112. #define SC16IS750_CRYSTCAL_FREQ (14745600UL)
  113. //#define SC16IS750_CRYSTCAL_FREQ (1843200UL)
  114. //#define SC16IS750_CRYSTCAL_FREQ (16000000UL)
  115. //#define SC16IS750_DEBUG_PRINT (0)
  116. #define SC16IS750_PROTOCOL_I2C (0)
  117. #define SC16IS750_PROTOCOL_SPI (1)
  118. #define AES_ENC_CAR 1
  119. #define AES_ENC_EMG 2
  120. #define AES_ENC_PCA 3
  121. #define AES_ENC_WES_EMG 4
  122. #define AES_ENC_WES_ALV 5
  123. #define AES_ENC_WES_TST 6
  124. #define AES_ENC_WES_REG 7
  125. /* A dummy structure to save in flash. */
  126. #define CONFIG_FILE (0x8010)
  127. #define CONFIG_REC_KEY (0x7010)
  128. typedef struct
  129. {
  130. uint32_t boot_count;
  131. char device_name[16];
  132. bool config1_on;
  133. bool config2_on;
  134. } configuration_t;
  135. typedef struct
  136. {
  137. char Mac[10][15];
  138. int Count;
  139. }RegMacPool_t;
  140. void SC16IS750_ResetDevice(void);
  141. void SC16IS750_WriteRegister(unsigned char reg_addr, unsigned char val);
  142. unsigned char SC16IS750_ReadRegister(unsigned char reg_addr);
  143. void SC16IS750_FIFOEnable(unsigned char fifo_enable);
  144. int16_t SC16IS750_SetBaudrate(uint32_t baudrate);
  145. void SC16IS750_SetLine(uint8_t data_length, uint8_t parity_select, uint8_t stop_length );
  146. void SC16IS750_WriteByte(uint8_t val);
  147. int DBGPrint(const char *fmt, ...);
  148. void ParkSysInit();
  149. void ParkPowerOff();
  150. void SendEmgData(void);
  151. extern stSystemTimer SystemTimer;
  152. extern stSystemManager SystemManager;
  153. #define KEY_SELECT 0
  154. #define KEY_UP 1
  155. #define KEY_DOWN 3
  156. #define KEY_BACK 2
  157. typedef struct tsHSKey{
  158. unsigned char onFlag;
  159. unsigned char softRelease;
  160. unsigned char pressedSec;
  161. unsigned int pressTime;
  162. unsigned int longPressTimeOne;
  163. unsigned int longPressTimeKeep;
  164. unsigned int prevTime;
  165. }HSKey;
  166. void ReadKEY(void);
  167. void KeyInit(void);
  168. void KeySelectLongPressedOne(void);
  169. void m_standby_counter_clerar();
  170. void PortInputCfg(void);
  171. void lfclk_config(void);
  172. void rtc_config(void);
  173. void SaveReceiverMac(char* mac);
  174. void LoadReceiverMac();
  175. void FlashTest();
  176. void WesEncryptEcb(uint8_t* in);
  177. extern ble_gap_addr_t old_ble_addr;
  178. extern ble_gap_addr_t new_ble_addr;
  179. extern RegMacPool_t RegMacPool;
  180. #endif