ipc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /*
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. /**
  11. *@file ipc.h
  12. *@brief ipc support for application.
  13. */
  14. #ifndef _YC_IPC_H_
  15. #define _YC_IPC_H_
  16. #include <stdio.h>
  17. #include "yc11xx.h"
  18. #include "btreg.h"
  19. #define BUG_FIX
  20. #ifdef BUG_FIX
  21. #define FIX_ENTER_LPM 0x01
  22. #define FIX_ENTER_HIBERNATE 0x03
  23. #endif
  24. #define POWERON_WAKE 1
  25. #define LPM_WAKE 0
  26. /**
  27. *@brief IPC protocol data.
  28. */
  29. #define IPC_CONTROL_CMD 0x01
  30. #define IPC_CONTROL_EVT 0x02
  31. #define IPC_SPP_DATA 0x04
  32. #define IPC_BLE_DATA 0x05
  33. #define IPC_ADV_DATA 0x08
  34. /**
  35. *@brief IPC unite bluetooth state.
  36. */
  37. enum btState {
  38. STATE_BT_NULL,
  39. STATE_BT_CONNECTING,
  40. STATE_BT_PAIRING,
  41. STATE_BT_CONNECTED,
  42. STATE_BT_PAGE,
  43. STATE_BT_DISCV,
  44. };
  45. /**
  46. *@brief IPC unite BLE state.
  47. */
  48. enum blestate {
  49. STATE_BLE_NULL,
  50. STATE_BLE_CONNECTING,
  51. STATE_BLE_PAIRING,
  52. STATE_BLE_CONNECTED,
  53. STATE_BLE_RECONNECTING,
  54. STATE_BLE_DISCV,
  55. };
  56. /**
  57. *@brief IPC unite 2.4g state.
  58. */
  59. enum privprostate {
  60. STATE_24G_NULL,
  61. STATE_24G,
  62. };
  63. /**
  64. *@brief IPC unit mesh state.
  65. */
  66. enum meshstate {
  67. STATE_NULL,
  68. };
  69. /**
  70. *@brief MCU state.
  71. */
  72. #define IPC_MCU_STATE_RUNNING 0
  73. #define IPC_MCU_STATE_HIBERNATE 1
  74. #define IPC_MCU_STATE_LMP 2
  75. #define IPC_MCU_STATE_STOP 3
  76. /**
  77. *@brief MCU phase type.
  78. */
  79. #define IPC_MCU_PHASE_IDLE 0
  80. #define IPC_MCU_PHASE1_NACK 1
  81. #define IPC_MCU_PHASE1_ACK 2
  82. #define IPC_MCU_PHASE2_NACK 3
  83. #define IPC_MCU_PHASE2_ACK 4
  84. /**
  85. *@brief IPC buffer address.
  86. */
  87. #define IPC_TX_BUF_START_ADDR IPC_TO_BT_BUF_START_ADDR
  88. #define IPC_TX_BUF_END_ADDR IPC_TO_BT_BUF_END_ADDR
  89. #define IPC_TX_WPTR_ADDR IPC_TO_BT_WPTR_ADDR
  90. #define IPC_TX_RPTR_ADDR IPC_TO_BT_RPTR_ADDR
  91. #define IPC_RX_WPTR_ADDR IPC_TO_M0_WPTR_ADDR
  92. #define IPC_RX_RPTR_ADDR IPC_TO_M0_RPTR_ADDR
  93. #define IPC_RX_BUF_START_ADDR IPC_TO_M0_BUF_START_ADDR
  94. #define IPC_RX_BUF_END_ADDR IPC_TO_M0_BUF_END_ADDR
  95. #define IPC_MCU_PHASE mem_ipc_mcu_phase
  96. #define IPC_MCU_STATE mem_ipc_mcu_state
  97. /**
  98. *@brief IPC buffer length.
  99. */
  100. #define IPC_TX_BUF_LEN (IPC_TX_BUF_END_ADDR-IPC_TX_BUF_END_ADDR)
  101. #define IPC_RX_BUF_LEN (IPC_RX_BUF_END_ADDR-IPC_RX_BUF_END_ADDR)
  102. /**
  103. *@brief IPC tx hardware address.
  104. */
  105. #define IPC_TX_HEAD IPC_TX_BUF_START_ADDR
  106. #define IPC_TX_END IPC_TX_BUF_END_ADDR
  107. #define IPC_TX_WRITE_PTR IPC_TX_WPTR_ADDR
  108. #define IPC_TX_READ_PTR IPC_TX_RPTR_ADDR
  109. /**
  110. *@brief IPC rx hardware address.
  111. */
  112. #define IPC_RX_HEAD IPC_RX_BUF_START_ADDR
  113. #define IPC_RX_END IPC_RX_BUF_END_ADDR
  114. #define IPC_RX_WRITE_PTR IPC_RX_WPTR_ADDR
  115. #define IPC_RX_READ_PTR IPC_RX_RPTR_ADDR
  116. /**
  117. *@brief IPC command type.
  118. */
  119. #define IPC_CMD_START_DISCOVERY 1
  120. #define IPC_CMD_STOP_DISCOVERY 2
  121. #define IPC_CMD_RECONNECT 3
  122. #define IPC_CMD_DISCONNECT 4
  123. #define IPC_CMD_ENTER_SNIFF 5
  124. #define IPC_CMD_SET_PIN_CODE 10
  125. #define IPC_CMD_START_INQUIRY 11
  126. #define IPC_CMD_STOP_INQUIRY 12
  127. #define IPC_CMD_START_ADV 13
  128. #define IPC_CMD_STOP_ADV 14
  129. #define IPC_CMD_START_DIRECT_ADV 15
  130. #define IPC_CMD_STOP_DIRECT_ADV 16
  131. #define IPC_CMD_LE_DISCONNECT 17
  132. #define IPC_CMD_UPDATE_CONN 18
  133. #define IPC_CMD_START_SCAN 23
  134. #define IPC_CMD_STOP_SCAN 24
  135. #define IPC_CMD_ENTER_HIBERNATE 25
  136. #define IPC_CMD_ROLE_SWITCH 29
  137. #define IPC_CMD_BB_RECONN_CANCEL 30
  138. #define IPC_CMD_MTU_EXCHANGE 33
  139. #define IPC_CMD_STOP_24G 34
  140. #define IPC_CMD_PAIR_24G 35
  141. #define IPC_CMD_TEST_24G 36
  142. #define IPC_CMD_TEST_MODE 37
  143. #define IPC_CMD_UPDATE_SUPERVISION_TO 40
  144. #define IPC_CMD_LE_SET_PINCODE 41
  145. #define IPC_CMD_SET_RECONNECT_INIT 42
  146. #define IPC_CMD_START_ADV_REC 43
  147. #define IPC_CMD_REC_PAGE 44
  148. #define IPC_CMD_LOAD_FLASH_PARAMS 45
  149. #define IPC_CMD_START_SCAN_ADV 47
  150. #define IPC_CMD_SEND_WRITE_RESPONSE 50
  151. /**
  152. *@brief IPC event type.
  153. */
  154. #define IPC_EVT_NULL 0x00
  155. #define IPC_EVT_BB_CONNECTED 0x01
  156. #define IPC_EVT_BB_DISCONNECTED 0x02
  157. #define IPC_EVT_RECONN_STARTED 0x03
  158. #define IPC_EVT_RECONN_FAILED 0x04
  159. #define IPC_EVT_SETUP_COMPLETE 0x05
  160. #define IPC_EVT_HID_CONNECTED 0x06
  161. #define IPC_EVT_HID_DISCONNECTED 0x07
  162. #define IPC_EVT_SPP_CONNECTED 0x08
  163. #define IPC_EVT_SPP_DISCONNECTED 0x09
  164. #define IPC_EVT_PINCODE_REQ 0x0A
  165. #define IPC_EVT_ENTER_SNIFF 0x0B
  166. #define IPC_EVT_EXIT_SNIFF 0x0C
  167. #define IPC_EVT_ENTER_SNIFF_SUB 0x0D
  168. #define IPC_EVT_EXIT_SNIFF_SUB 0x0E
  169. #define IPC_EVT_DISCOVERY_STOPED 0x0F
  170. #define IPC_EVT_BUTTON_LONG_PRESSED 0x10
  171. #define IPC_EVT_HID_HANDSHAKE 0x12
  172. #define IPC_EVT_RECONN_PAGE_TIMEOUT 0x13
  173. #define IPC_EVT_LE_CONNECTED 0x14
  174. #define IPC_EVT_LE_DISCONNECTED 0x15
  175. #define IPC_EVT_ML2CAP_CONN_REFUSED 0x16
  176. #define IPC_EVT_BUTTON_ENTER_HIBERNATE 0x17
  177. #define IPC_EVT_LINKKEY_GENERATE 0x18
  178. #define IPC_EVT_SWITCH_NOT_ACCEPT 0x19
  179. #define IPC_EVT_SWITCH_ACCEPT 0x20
  180. #define IPC_EVT_SNIFF_NOT_ACCEPT 0x21
  181. #define IPC_EVT_SNIFF_ACCEPT 0x22
  182. #define IPC_EVT_UNSNIFF_ACCEPT 0x23
  183. #define IPC_EVT_UNSNIFF_NOT_ACCEPT 0x24
  184. #define IPC_EVT_BUTTON_ADJUST_DPI 0x25
  185. #define IPC_EVT_SEND_UNSNIFF_ACCEPT 0x26
  186. #define IPC_EVT_VIRTUAL_CABLE_UNPLUG 0x27
  187. #define IPC_EVT_LE_WRITE_REQUEST 0x28
  188. #define IPC_EVT_LE_ENC_INFO 0x29
  189. #define IPC_EVT_SWITCH_FAIL_MASTER 0x2a
  190. #define IPC_EVT_SWITCH_SUCCESS_MASTER 0x2b
  191. #define IPC_EVT_BUTTON_DOWN 0x2c
  192. #define IPC_EVT_BUTTON_UP 0x2d
  193. #define IPC_EVT_REMOTE_UNSNIFF 0x2e
  194. #define IPC_EVT_LE_PAIRING_FAIL 0x30
  195. #define IPC_EVT_LE_PAIRING_SUCCESS 0x31
  196. #define IPC_EVT_LE_START_ENC 0x32
  197. #define IPC_EVT_LE_PAUSE_ENC 0x33
  198. #define IPC_EVT_LE_TK_GENERATE 0x34
  199. #define IPC_EVT_BT_GKEY_GENERATE 0x35
  200. #define IPC_EVT_BT_GET_PASSKEY 0x36
  201. #define IPC_EVT_BT_PAIRING_FAIL 0x37
  202. #define IPC_EVT_BT_PAIRING_SUCCESS 0x38
  203. #define IPC_EVT_LE_GKEY_GENERATE 0x3b
  204. #define IPC_EVT_24G_PAIRING_COMPLETE 0x3a
  205. #define IPC_EVT_24G_ATTEMPT_FAIL 0x3b
  206. #define IPC_EVT_24G_ATTEMPT_SUCCESS 0x3c
  207. #define IPC_EVT_LE_DISCONNECTED_ABNORMAL 0X3d
  208. #define IPC_EVT_HFP_CONNECTED 0x60
  209. #define IPC_EVT_HFP_DISCONNECTED 0x61
  210. #define IPC_EVT_HFP_INDICATORS_UPDATE 0x62
  211. #define IPC_EVT_HFP_UP_TO_MAX_VLM 0x63
  212. #define IPC_EVT_HFP_DOWN_TO_MIN_VLM 0x64
  213. #define IPC_EVT_RESET 0x65
  214. #define IPC_EVT_WAKEUP 0x66
  215. #define IPC_EVT_INDICATE_COMIFIRMATION 0X67
  216. #define IPC_EVT_ACCEPT_UPDATA_CONN_PARAM 0x68
  217. #define IPC_EVT_REJECT_UPDATA_CONN_PARAM 0x69
  218. #define IPC_EVT_SEND_NOTIFY_OK 0x70
  219. /**
  220. *@brief IPC event type define.
  221. */
  222. #define IPC_EVT_HFP_CONNECTED 0x60
  223. #define IPC_EVT_HFP_DISCONNECTED 0x61
  224. #define IPC_EVT_HFP_INDICATORS_UPDATE 0x62
  225. #define IPC_EVT_HFP_UP_TO_MAX_VLM 0x63
  226. #define IPC_EVT_HFP_DOWN_TO_MIN_VLM 0x64
  227. /**
  228. *@brief IPC event type enum.
  229. */
  230. typedef enum
  231. {
  232. HFP_EVT_PLUS_CIEV=1,
  233. HFP_EVT_PLUS_CLIP,
  234. HFP_EVT_RING,
  235. HFP_EVT_PLUS_VGS,
  236. HPF_EVT_PLUS_VGM,
  237. HFP_EVT_CIND_INDICATOR,
  238. }HFP_EVT_TYPE;
  239. /**
  240. *@brief BLE format.
  241. */
  242. typedef struct
  243. {
  244. unsigned short mhandle;
  245. unsigned char data;
  246. }IPC_BLE_FORMAT;
  247. /**
  248. *@brief SPP format.
  249. */
  250. typedef struct
  251. {
  252. unsigned char data;
  253. }IPC_SPP_FORMAT;
  254. /**
  255. *@brief IPC data format.
  256. */
  257. typedef struct
  258. {
  259. unsigned char ipctype;
  260. unsigned char len;
  261. union
  262. {
  263. IPC_BLE_FORMAT uBleData;
  264. } ipcUnion;
  265. }IPC_DATA_FORMAT;
  266. /**
  267. *@brief IPC type enum.
  268. */
  269. #define IPC_TYPE_START 0
  270. #define IPC_TYPE_NUM 0xd
  271. typedef void (*tIPCHandleCb)(uint8_t,uint8_t *);
  272. typedef tIPCHandleCb (*tIPCHandleCbArray)[IPC_TYPE_NUM];
  273. /**
  274. *@brief IPC EVT callback function type.
  275. */
  276. typedef void (*tIPCEventCb)(uint8_t);
  277. /**
  278. *@brief IPC SPP callback function type.
  279. */
  280. typedef void (*tIPCSppCb)(uint8_t*, uint16_t);
  281. /**
  282. *@brief IPC BLE callback function type.
  283. */
  284. typedef void (*tIPCBleCb)(uint8_t*, uint16_t);
  285. /**
  286. *@brief IPC timer(1s) callback function type.
  287. */
  288. typedef void (*tIPCTimer)(void);
  289. /**
  290. *@brief IPC Hid callback function type.
  291. */
  292. typedef void (*tIPCHidCb)(uint8_t*, uint16_t);
  293. /**
  294. *@brief IPC Hid callback function type.
  295. */
  296. typedef void (*tIPCMeshCb)(uint8_t, uint8_t*, uint16_t);
  297. /**
  298. *@brief IPC a2dp callback function type.
  299. */
  300. typedef void (*tIPCa2dpCb)(uint8_t*, uint16_t);
  301. /**
  302. *@brief IPC a2dp callback function type.
  303. */
  304. typedef void (*tIPCAdvCb)(uint8_t*, uint16_t);
  305. /**
  306. *@brief IPC control block type.
  307. */
  308. typedef struct IPCContolBlock {
  309. tIPCEventCb evtcb; /*< ipc evt call back*/
  310. tIPCSppCb sppcb; /*< ipc spp call back*/
  311. tIPCTimer timercb; /*< ipc 1s timer call back*/
  312. tIPCTimer stimercb; /*< ipc 100ms timer call back */
  313. tIPCBleCb blecb; /*< ipc ble call back*/
  314. tIPCHidCb hidcb; /*< ipc hid call back*/
  315. tIPCMeshCb meshcb; /*< ipc mesh call back*/
  316. tIPCa2dpCb a2dpcb; /*< ipc audio call back */
  317. tIPCMeshCb handle; /*< ipc mesh call back*/
  318. tIPCAdvCb advcb; /*< ipc adv call back*/
  319. }tIPCControlBlock;
  320. /**
  321. *@brief Define 6-bit address.
  322. */
  323. #define BT_ADDR_SIZE 6
  324. typedef uint8_t tBTADDR[BT_ADDR_SIZE];
  325. /**
  326. *@brief This function rigist IPC Control Block.
  327. *@param cb the IPC control block.
  328. *@return None.
  329. */
  330. void IPC_Initialize(tIPCControlBlock *Cb);
  331. /**
  332. *@brief This function deal IPC Single process, callback the rigisted IPC control function.
  333. *@param None.
  334. *@return None.
  335. */
  336. void IPC_DealSingleStep(void);
  337. /**
  338. *@brief This function tx control IPC command.
  339. *@param cmd IPC command want to send.
  340. *@return None.
  341. */
  342. void IPC_TxControlCmd(uint8_t Cmd);
  343. /**
  344. *@brief This function tx mult IPC data.
  345. *@param cmd IPC command want to send.
  346. *@return None.
  347. */
  348. void IPC_TxCommon(uint8_t Type, uint8_t* Dt, uint8_t Len);
  349. /**
  350. *@brief This function tx HID IPC command,Cpu will block when TxBuffer is not Empty.
  351. *@param dt IPC HID data want to send,len length of hid data.
  352. *@return None.
  353. */
  354. #define IPC_TxHidData(dt, len) IPC_TxCommon(IPC_HID_DATA, (dt), (len))
  355. /**
  356. *@brief This function tx 24G IPC command,Cpu will block when TxBuffer is not Empty.
  357. *@param dt IPC HID data want to send,len length of hid data.
  358. *@return None.
  359. */
  360. #define IPC_Tx24GData(dt, len) IPC_TxCommon(IPC_24G_DATA, (dt), (len))
  361. /**
  362. *@brief This function tx SPP IPC command,Cpu will block when TxBuffer is not Empty.
  363. *@param dt IPC SPP data want to send,len length of SPP data.
  364. *@return None.
  365. */
  366. #define IPC_TxSppData(dt, len) IPC_TxCommon(IPC_SPP_DATA, (dt), (len))
  367. /**
  368. *@brief This function tx BLE IPC command,Cpu will block when TxBuffer is not Empty.
  369. *@param dt IPC BLE data want to send,len length of BLE data.
  370. *@return None.
  371. */
  372. #define IPC_TxBleData(dt, len) IPC_TxCommon(IPC_TYPE_BLE, (dt), (len))
  373. /**
  374. *@brief This function will do nothing wait enter lpm.
  375. *@param None.
  376. *@return None.
  377. */
  378. void IPC_WaitLpm(void);
  379. /**
  380. *@brief This function will do nothing abandon lpm this time.
  381. *@param None.
  382. *@return None.
  383. */
  384. void IPC_AbandonLpm(void);
  385. /**
  386. *@brief This function check if tx buffer empty.
  387. *@param None.
  388. *@return None.
  389. */
  390. uint8_t IPC_IsTxBuffEmpty(void);
  391. /**
  392. *@brief This function check if rx buffer empty.
  393. *@param None.
  394. *@return None.
  395. */
  396. uint8_t IPC_IsRxBuffEmpty();
  397. /**
  398. *@brief This function will check sdp server connect.
  399. *@param None.
  400. *@return None.
  401. */
  402. uint8_t IPC_CheckServerConenct(void);
  403. /**
  404. *@brief This function will disable lpm function.
  405. *@param None.
  406. *@return None.
  407. */
  408. void IPC_DisableLpm();
  409. /**
  410. *@brief This function will enable lpm function.
  411. *@param None.
  412. *@return None.
  413. */
  414. void IPC_EnableLpm();
  415. /**
  416. *@brief This function prevents IPC txbuffer overflow.
  417. *@param The length of the data send.
  418. *@return 1 represents the completion of sending data,return 0 represents txbuffer is empty.
  419. */
  420. uint8_t IPC_TxBufferIsEnough(uint8_t Len);
  421. /**
  422. *@brief This function waits to be written tx buffer.
  423. *@param The length of the data send.
  424. *@return 1 represent the completion of sending data.
  425. */
  426. uint8_t IPC_WaitBufferEnough(uint8_t Len);
  427. /**
  428. *@brief IPC default callback function.
  429. *@param len
  430. *@param dataPtr
  431. *@return None.
  432. */
  433. void IpcDefaultCallBack(uint8_t len,uint8_t *dataPtr);
  434. /**
  435. *@brief Accept packages from the handle.
  436. *@param None.
  437. *@return None.
  438. */
  439. void IPC_HandleRxPacket();
  440. /**
  441. *@brief IPC initialization.
  442. *@param cbArrayPtr callback function.
  443. *@return None.
  444. */
  445. void IPC_init(tIPCHandleCbArray cbArrayPtr);
  446. /**
  447. *@brief IPC transport packet.
  448. *@param packet IPC data.@ref IPC_DATA_FORMAT
  449. *@return None.
  450. */
  451. void IPC_TxPacket(IPC_DATA_FORMAT *packet);
  452. // /**
  453. // *@brief IPC set ACK flag.
  454. // *@param None.
  455. // *@return None.
  456. // */
  457. // void IPC_set_ack_flag();
  458. // /**
  459. // *@brief IPC set NACK flag.
  460. // *@param None.
  461. // *@return None.
  462. // */
  463. // void IPC_set_nack_flag();
  464. // /**
  465. // *@brief IPC wait ACK.
  466. // *@param None.
  467. // *@return None.
  468. // */
  469. // void IPC_wait_ack();
  470. // /**
  471. // *@brief IPC clear flag.
  472. // *@param None.
  473. // *@return None.
  474. // */
  475. // void IPC_clear_flag();
  476. #endif