123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- /*
- * Copyright 2016, yichip Semiconductor(shenzhen office)
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
- * the contents of this file may not be disclosed to third parties, copied
- * or duplicated in any form, in whole or in part, without the prior
- * written permission of Yichip Semiconductor.
- */
-
- /**
- *@file ipc.h
- *@brief ipc support for application.
- */
- #ifndef _YC_IPC_H_
- #define _YC_IPC_H_
- #include <stdio.h>
- #include "yc11xx.h"
- #include "btreg.h"
- #define BUG_FIX
- #ifdef BUG_FIX
- #define FIX_ENTER_LPM 0x01
- #define FIX_ENTER_HIBERNATE 0x03
- #endif
- #define POWERON_WAKE 1
- #define LPM_WAKE 0
- /**
- *@brief IPC protocol data.
- */
- #define IPC_CONTROL_CMD 0x01
- #define IPC_CONTROL_EVT 0x02
- #define IPC_SPP_DATA 0x04
- #define IPC_BLE_DATA 0x05
- #define IPC_ADV_DATA 0x08
- /**
- *@brief IPC unite bluetooth state.
- */
- enum btState {
- STATE_BT_NULL,
- STATE_BT_CONNECTING,
- STATE_BT_PAIRING,
- STATE_BT_CONNECTED,
- STATE_BT_PAGE,
- STATE_BT_DISCV,
- };
- /**
- *@brief IPC unite BLE state.
- */
- enum blestate {
- STATE_BLE_NULL,
- STATE_BLE_CONNECTING,
- STATE_BLE_PAIRING,
- STATE_BLE_CONNECTED,
- STATE_BLE_RECONNECTING,
- STATE_BLE_DISCV,
- };
- /**
- *@brief IPC unite 2.4g state.
- */
- enum privprostate {
- STATE_24G_NULL,
- STATE_24G,
- };
- /**
- *@brief IPC unit mesh state.
- */
- enum meshstate {
- STATE_NULL,
- };
- /**
- *@brief MCU state.
- */
- #define IPC_MCU_STATE_RUNNING 0
- #define IPC_MCU_STATE_HIBERNATE 1
- #define IPC_MCU_STATE_LMP 2
- #define IPC_MCU_STATE_STOP 3
- /**
- *@brief MCU phase type.
- */
- #define IPC_MCU_PHASE_IDLE 0
- #define IPC_MCU_PHASE1_NACK 1
- #define IPC_MCU_PHASE1_ACK 2
- #define IPC_MCU_PHASE2_NACK 3
- #define IPC_MCU_PHASE2_ACK 4
- /**
- *@brief IPC buffer address.
- */
- #define IPC_TX_BUF_START_ADDR IPC_TO_BT_BUF_START_ADDR
- #define IPC_TX_BUF_END_ADDR IPC_TO_BT_BUF_END_ADDR
- #define IPC_TX_WPTR_ADDR IPC_TO_BT_WPTR_ADDR
- #define IPC_TX_RPTR_ADDR IPC_TO_BT_RPTR_ADDR
- #define IPC_RX_WPTR_ADDR IPC_TO_M0_WPTR_ADDR
- #define IPC_RX_RPTR_ADDR IPC_TO_M0_RPTR_ADDR
- #define IPC_RX_BUF_START_ADDR IPC_TO_M0_BUF_START_ADDR
- #define IPC_RX_BUF_END_ADDR IPC_TO_M0_BUF_END_ADDR
- #define IPC_MCU_PHASE mem_ipc_mcu_phase
- #define IPC_MCU_STATE mem_ipc_mcu_state
- /**
- *@brief IPC buffer length.
- */
- #define IPC_TX_BUF_LEN (IPC_TX_BUF_END_ADDR-IPC_TX_BUF_END_ADDR)
- #define IPC_RX_BUF_LEN (IPC_RX_BUF_END_ADDR-IPC_RX_BUF_END_ADDR)
- /**
- *@brief IPC tx hardware address.
- */
- #define IPC_TX_HEAD IPC_TX_BUF_START_ADDR
- #define IPC_TX_END IPC_TX_BUF_END_ADDR
- #define IPC_TX_WRITE_PTR IPC_TX_WPTR_ADDR
- #define IPC_TX_READ_PTR IPC_TX_RPTR_ADDR
- /**
- *@brief IPC rx hardware address.
- */
- #define IPC_RX_HEAD IPC_RX_BUF_START_ADDR
- #define IPC_RX_END IPC_RX_BUF_END_ADDR
- #define IPC_RX_WRITE_PTR IPC_RX_WPTR_ADDR
- #define IPC_RX_READ_PTR IPC_RX_RPTR_ADDR
- /**
- *@brief IPC command type.
- */
- #define IPC_CMD_START_DISCOVERY 1
- #define IPC_CMD_STOP_DISCOVERY 2
- #define IPC_CMD_RECONNECT 3
- #define IPC_CMD_DISCONNECT 4
- #define IPC_CMD_ENTER_SNIFF 5
- #define IPC_CMD_SET_PIN_CODE 10
- #define IPC_CMD_START_INQUIRY 11
- #define IPC_CMD_STOP_INQUIRY 12
- #define IPC_CMD_START_ADV 13
- #define IPC_CMD_STOP_ADV 14
- #define IPC_CMD_START_DIRECT_ADV 15
- #define IPC_CMD_STOP_DIRECT_ADV 16
- #define IPC_CMD_LE_DISCONNECT 17
- #define IPC_CMD_UPDATE_CONN 18
- #define IPC_CMD_START_SCAN 23
- #define IPC_CMD_STOP_SCAN 24
- #define IPC_CMD_ENTER_HIBERNATE 25
- #define IPC_CMD_ROLE_SWITCH 29
- #define IPC_CMD_BB_RECONN_CANCEL 30
- #define IPC_CMD_MTU_EXCHANGE 33
- #define IPC_CMD_STOP_24G 34
- #define IPC_CMD_PAIR_24G 35
- #define IPC_CMD_TEST_24G 36
- #define IPC_CMD_TEST_MODE 37
- #define IPC_CMD_UPDATE_SUPERVISION_TO 40
- #define IPC_CMD_LE_SET_PINCODE 41
- #define IPC_CMD_SET_RECONNECT_INIT 42
- #define IPC_CMD_START_ADV_REC 43
- #define IPC_CMD_REC_PAGE 44
- #define IPC_CMD_LOAD_FLASH_PARAMS 45
- #define IPC_CMD_START_SCAN_ADV 47
- #define IPC_CMD_SEND_WRITE_RESPONSE 50
- /**
- *@brief IPC event type.
- */
- #define IPC_EVT_NULL 0x00
- #define IPC_EVT_BB_CONNECTED 0x01
- #define IPC_EVT_BB_DISCONNECTED 0x02
- #define IPC_EVT_RECONN_STARTED 0x03
- #define IPC_EVT_RECONN_FAILED 0x04
- #define IPC_EVT_SETUP_COMPLETE 0x05
- #define IPC_EVT_HID_CONNECTED 0x06
- #define IPC_EVT_HID_DISCONNECTED 0x07
- #define IPC_EVT_SPP_CONNECTED 0x08
- #define IPC_EVT_SPP_DISCONNECTED 0x09
- #define IPC_EVT_PINCODE_REQ 0x0A
- #define IPC_EVT_ENTER_SNIFF 0x0B
- #define IPC_EVT_EXIT_SNIFF 0x0C
- #define IPC_EVT_ENTER_SNIFF_SUB 0x0D
- #define IPC_EVT_EXIT_SNIFF_SUB 0x0E
- #define IPC_EVT_DISCOVERY_STOPED 0x0F
- #define IPC_EVT_BUTTON_LONG_PRESSED 0x10
- #define IPC_EVT_HID_HANDSHAKE 0x12
- #define IPC_EVT_RECONN_PAGE_TIMEOUT 0x13
- #define IPC_EVT_LE_CONNECTED 0x14
- #define IPC_EVT_LE_DISCONNECTED 0x15
- #define IPC_EVT_ML2CAP_CONN_REFUSED 0x16
- #define IPC_EVT_BUTTON_ENTER_HIBERNATE 0x17
- #define IPC_EVT_LINKKEY_GENERATE 0x18
- #define IPC_EVT_SWITCH_NOT_ACCEPT 0x19
- #define IPC_EVT_SWITCH_ACCEPT 0x20
- #define IPC_EVT_SNIFF_NOT_ACCEPT 0x21
- #define IPC_EVT_SNIFF_ACCEPT 0x22
- #define IPC_EVT_UNSNIFF_ACCEPT 0x23
- #define IPC_EVT_UNSNIFF_NOT_ACCEPT 0x24
- #define IPC_EVT_BUTTON_ADJUST_DPI 0x25
- #define IPC_EVT_SEND_UNSNIFF_ACCEPT 0x26
- #define IPC_EVT_VIRTUAL_CABLE_UNPLUG 0x27
- #define IPC_EVT_LE_WRITE_REQUEST 0x28
- #define IPC_EVT_LE_ENC_INFO 0x29
- #define IPC_EVT_SWITCH_FAIL_MASTER 0x2a
- #define IPC_EVT_SWITCH_SUCCESS_MASTER 0x2b
- #define IPC_EVT_BUTTON_DOWN 0x2c
- #define IPC_EVT_BUTTON_UP 0x2d
- #define IPC_EVT_REMOTE_UNSNIFF 0x2e
- #define IPC_EVT_LE_PAIRING_FAIL 0x30
- #define IPC_EVT_LE_PAIRING_SUCCESS 0x31
- #define IPC_EVT_LE_START_ENC 0x32
- #define IPC_EVT_LE_PAUSE_ENC 0x33
- #define IPC_EVT_LE_TK_GENERATE 0x34
- #define IPC_EVT_BT_GKEY_GENERATE 0x35
- #define IPC_EVT_BT_GET_PASSKEY 0x36
- #define IPC_EVT_BT_PAIRING_FAIL 0x37
- #define IPC_EVT_BT_PAIRING_SUCCESS 0x38
- #define IPC_EVT_LE_GKEY_GENERATE 0x3b
- #define IPC_EVT_24G_PAIRING_COMPLETE 0x3a
- #define IPC_EVT_24G_ATTEMPT_FAIL 0x3b
- #define IPC_EVT_24G_ATTEMPT_SUCCESS 0x3c
- #define IPC_EVT_LE_DISCONNECTED_ABNORMAL 0X3d
- #define IPC_EVT_HFP_CONNECTED 0x60
- #define IPC_EVT_HFP_DISCONNECTED 0x61
- #define IPC_EVT_HFP_INDICATORS_UPDATE 0x62
- #define IPC_EVT_HFP_UP_TO_MAX_VLM 0x63
- #define IPC_EVT_HFP_DOWN_TO_MIN_VLM 0x64
- #define IPC_EVT_RESET 0x65
- #define IPC_EVT_WAKEUP 0x66
- #define IPC_EVT_INDICATE_COMIFIRMATION 0X67
- #define IPC_EVT_ACCEPT_UPDATA_CONN_PARAM 0x68
- #define IPC_EVT_REJECT_UPDATA_CONN_PARAM 0x69
- #define IPC_EVT_SEND_NOTIFY_OK 0x70
- /**
- *@brief IPC event type define.
- */
- #define IPC_EVT_HFP_CONNECTED 0x60
- #define IPC_EVT_HFP_DISCONNECTED 0x61
- #define IPC_EVT_HFP_INDICATORS_UPDATE 0x62
- #define IPC_EVT_HFP_UP_TO_MAX_VLM 0x63
- #define IPC_EVT_HFP_DOWN_TO_MIN_VLM 0x64
- /**
- *@brief IPC event type enum.
- */
- typedef enum
- {
- HFP_EVT_PLUS_CIEV=1,
- HFP_EVT_PLUS_CLIP,
- HFP_EVT_RING,
- HFP_EVT_PLUS_VGS,
- HPF_EVT_PLUS_VGM,
- HFP_EVT_CIND_INDICATOR,
- }HFP_EVT_TYPE;
- /**
- *@brief BLE format.
- */
- typedef struct
- {
- unsigned short mhandle;
- unsigned char data;
- }IPC_BLE_FORMAT;
- /**
- *@brief SPP format.
- */
- typedef struct
- {
- unsigned char data;
- }IPC_SPP_FORMAT;
- /**
- *@brief IPC data format.
- */
- typedef struct
- {
- unsigned char ipctype;
- unsigned char len;
- union
- {
- IPC_BLE_FORMAT uBleData;
- } ipcUnion;
- }IPC_DATA_FORMAT;
- /**
- *@brief IPC type enum.
- */
- #define IPC_TYPE_START 0
- #define IPC_TYPE_NUM 0xd
- typedef void (*tIPCHandleCb)(uint8_t,uint8_t *);
- typedef tIPCHandleCb (*tIPCHandleCbArray)[IPC_TYPE_NUM];
- /**
- *@brief IPC EVT callback function type.
- */
- typedef void (*tIPCEventCb)(uint8_t);
- /**
- *@brief IPC SPP callback function type.
- */
- typedef void (*tIPCSppCb)(uint8_t*, uint16_t);
- /**
- *@brief IPC BLE callback function type.
- */
- typedef void (*tIPCBleCb)(uint8_t*, uint16_t);
- /**
- *@brief IPC timer(1s) callback function type.
- */
- typedef void (*tIPCTimer)(void);
- /**
- *@brief IPC Hid callback function type.
- */
- typedef void (*tIPCHidCb)(uint8_t*, uint16_t);
- /**
- *@brief IPC Hid callback function type.
- */
- typedef void (*tIPCMeshCb)(uint8_t, uint8_t*, uint16_t);
- /**
- *@brief IPC a2dp callback function type.
- */
- typedef void (*tIPCa2dpCb)(uint8_t*, uint16_t);
- /**
- *@brief IPC a2dp callback function type.
- */
- typedef void (*tIPCAdvCb)(uint8_t*, uint16_t);
- /**
- *@brief IPC control block type.
- */
- typedef struct IPCContolBlock {
- tIPCEventCb evtcb; /*< ipc evt call back*/
- tIPCSppCb sppcb; /*< ipc spp call back*/
- tIPCTimer timercb; /*< ipc 1s timer call back*/
- tIPCTimer stimercb; /*< ipc 100ms timer call back */
- tIPCBleCb blecb; /*< ipc ble call back*/
- tIPCHidCb hidcb; /*< ipc hid call back*/
- tIPCMeshCb meshcb; /*< ipc mesh call back*/
- tIPCa2dpCb a2dpcb; /*< ipc audio call back */
- tIPCMeshCb handle; /*< ipc mesh call back*/
- tIPCAdvCb advcb; /*< ipc adv call back*/
- }tIPCControlBlock;
- /**
- *@brief Define 6-bit address.
- */
- #define BT_ADDR_SIZE 6
- typedef uint8_t tBTADDR[BT_ADDR_SIZE];
- /**
- *@brief This function rigist IPC Control Block.
- *@param cb the IPC control block.
- *@return None.
- */
- void IPC_Initialize(tIPCControlBlock *Cb);
- /**
- *@brief This function deal IPC Single process, callback the rigisted IPC control function.
- *@param None.
- *@return None.
- */
- void IPC_DealSingleStep(void);
- /**
- *@brief This function tx control IPC command.
- *@param cmd IPC command want to send.
- *@return None.
- */
- void IPC_TxControlCmd(uint8_t Cmd);
- /**
- *@brief This function tx mult IPC data.
- *@param cmd IPC command want to send.
- *@return None.
- */
- void IPC_TxCommon(uint8_t Type, uint8_t* Dt, uint8_t Len);
- /**
- *@brief This function tx HID IPC command,Cpu will block when TxBuffer is not Empty.
- *@param dt IPC HID data want to send,len length of hid data.
- *@return None.
- */
- #define IPC_TxHidData(dt, len) IPC_TxCommon(IPC_HID_DATA, (dt), (len))
- /**
- *@brief This function tx 24G IPC command,Cpu will block when TxBuffer is not Empty.
- *@param dt IPC HID data want to send,len length of hid data.
- *@return None.
- */
- #define IPC_Tx24GData(dt, len) IPC_TxCommon(IPC_24G_DATA, (dt), (len))
- /**
- *@brief This function tx SPP IPC command,Cpu will block when TxBuffer is not Empty.
- *@param dt IPC SPP data want to send,len length of SPP data.
- *@return None.
- */
- #define IPC_TxSppData(dt, len) IPC_TxCommon(IPC_SPP_DATA, (dt), (len))
- /**
- *@brief This function tx BLE IPC command,Cpu will block when TxBuffer is not Empty.
- *@param dt IPC BLE data want to send,len length of BLE data.
- *@return None.
- */
- #define IPC_TxBleData(dt, len) IPC_TxCommon(IPC_TYPE_BLE, (dt), (len))
- /**
- *@brief This function will do nothing wait enter lpm.
- *@param None.
- *@return None.
- */
- void IPC_WaitLpm(void);
- /**
- *@brief This function will do nothing abandon lpm this time.
- *@param None.
- *@return None.
- */
- void IPC_AbandonLpm(void);
- /**
- *@brief This function check if tx buffer empty.
- *@param None.
- *@return None.
- */
- uint8_t IPC_IsTxBuffEmpty(void);
- /**
- *@brief This function check if rx buffer empty.
- *@param None.
- *@return None.
- */
- uint8_t IPC_IsRxBuffEmpty();
- /**
- *@brief This function will check sdp server connect.
- *@param None.
- *@return None.
- */
- uint8_t IPC_CheckServerConenct(void);
- /**
- *@brief This function will disable lpm function.
- *@param None.
- *@return None.
- */
- void IPC_DisableLpm();
- /**
- *@brief This function will enable lpm function.
- *@param None.
- *@return None.
- */
- void IPC_EnableLpm();
- /**
- *@brief This function prevents IPC txbuffer overflow.
- *@param The length of the data send.
- *@return 1 represents the completion of sending data,return 0 represents txbuffer is empty.
- */
- uint8_t IPC_TxBufferIsEnough(uint8_t Len);
- /**
- *@brief This function waits to be written tx buffer.
- *@param The length of the data send.
- *@return 1 represent the completion of sending data.
- */
- uint8_t IPC_WaitBufferEnough(uint8_t Len);
- /**
- *@brief IPC default callback function.
- *@param len
- *@param dataPtr
- *@return None.
- */
- void IpcDefaultCallBack(uint8_t len,uint8_t *dataPtr);
- /**
- *@brief Accept packages from the handle.
- *@param None.
- *@return None.
- */
- void IPC_HandleRxPacket();
- /**
- *@brief IPC initialization.
- *@param cbArrayPtr callback function.
- *@return None.
- */
- void IPC_init(tIPCHandleCbArray cbArrayPtr);
- /**
- *@brief IPC transport packet.
- *@param packet IPC data.@ref IPC_DATA_FORMAT
- *@return None.
- */
- void IPC_TxPacket(IPC_DATA_FORMAT *packet);
- // /**
- // *@brief IPC set ACK flag.
- // *@param None.
- // *@return None.
- // */
- // void IPC_set_ack_flag();
- // /**
- // *@brief IPC set NACK flag.
- // *@param None.
- // *@return None.
- // */
- // void IPC_set_nack_flag();
- // /**
- // *@brief IPC wait ACK.
- // *@param None.
- // *@return None.
- // */
- // void IPC_wait_ack();
- // /**
- // *@brief IPC clear flag.
- // *@param None.
- // *@return None.
- // */
- // void IPC_clear_flag();
- #endif
|