blob: 2d40b1f82d8fbc8955eb98591d4a9ab2106715cc [file] [log] [blame]
/**********************************************************************
* All Rights Reserved
*
* MARVELL CONFIDENTIAL
* Copyright 2012 Marvell International Ltd All Rights Reserved.
* The source code contained or described herein and all documents related to
* the source code ("Material") are owned by Marvell International Ltd or its
* suppliers or licensors. Title to the Material remains with Marvell International Ltd
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Marvell or its suppliers and
* licensors. The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used, copied,
* reproduced, modified, published, uploaded, posted, transmitted, distributed,
* or disclosed in any way without Marvell's prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Marvell in writing.
*
**********************************************************************/
/*! \file gps_msocket.c
\brief .
*/
#ifndef _GPS_MSOCKET_H_
#define _GPS_MSOCKET_H_
#include "gps_types.h"
#include "gps_oal.h"
/*Share memory buffer size cut header size*/
#define MAX_SHM_PL_SIZE 4072
#define MAX_SHM_MSG_SIZE (MAX_SHM_PL_SIZE-12)
#define GPS_MSOCK_TX_DATA_READY 1
#define GPS_MSOCK_TX_DATA_EMPT 2
#define GPS_DATA_TX_DISCARD_CNT 20
#define GPS_DATA_TX_LEN_LWM 8192 /*8K*/
#define GPS_DATA_TX_LEN_HWM 10240 /*10K*/
#define GPS_DATA_TX_LINK_LWM 18
#define GPS_DATA_TX_LINK_HWM 20
#define GPS_SHM_API_MSG_LEN 12
#define GPS_MSOCK_TX_TRY_CNT 3
#define MSOCKET_IOC_MAGIC 0xD0
#define MSOCKET_IOC_BIND _IO(MSOCKET_IOC_MAGIC, 1)
#define MSOCKET_IOC_UP _IO(MSOCKET_IOC_MAGIC, 2)
#define MSOCKET_IOC_DOWN _IO(MSOCKET_IOC_MAGIC, 3)
#define MSOCKET_IOC_PMIC_QUERY _IOR(MSOCKET_IOC_MAGIC, 4, int)
#define MSOCKET_IOC_CONNECT _IO(MSOCKET_IOC_MAGIC, 5)
#define MSOCKET_IOC_RESET_CP_REQUEST _IO(MSOCKET_IOC_MAGIC, 6)
#define MSOCKET_IOC_ERRTO _IO(MSOCKET_IOC_MAGIC, 7)
#define MSOCKET_IOC_RECOVERY _IO(MSOCKET_IOC_MAGIC, 8)
#define GPS_MSOCK_RPT_ERR 0xFFFE /*cm3 crash, re-download happens, msocket ports receiv procId=0xFFFE message*/
#define GPS_MSOCK_RPT_RCV 0xFFFD /*cm3 crash, re-download finish, msocket ports receiv procId=0xFFFD message*/
enum
{
/*service ID*/
GPS_DIAG_PORT_GPS = 16, //16
GPS_SENSOR_HUB_DATA_PORT = 17,//17
GPS_SENSOR_HUB_CMD_PORT = 18, //18
GPS_DIAG_PORT_LPM = 19,
GPS_DIAG_PORT_MAX,
/*used to maintain msocket database*/
GPS_DIAG_PORT_GAP = 16,
GPS_DIAG_PORT_TOTAL = GPS_DIAG_PORT_MAX - GPS_DIAG_PORT_GAP,
};
typedef enum
{
GPS_MSOCK_STAT_OK = 0,
GPS_MSOCK_STAT_HIGH_WM, // The message WAS added to the queue.
GPS_MSOCK_STAT_LINK_DOWN, // The message was NOT added to the queue.
GPS_MSOCK_STAT_Q_FULL, // The message was NOT added to the queue.
GPS_MSOCK_STAT_ILLEGAL_PARAM,
GPS_MSOCK_STAT_NO_MEMORY
} gpsMsockStat_t ;
typedef enum
{
GPS_MSOCK_CLOSED,
GPS_MSOCK_NEAR_SIDE_READY,
GPS_MSOCK_FAR_SIDE_READY,
GPS_MSOCK_CONNECTED
} gpsMsockLinkState_t;
typedef enum
{
GPS_MSOCK_DO_NOTHING, // No action is required before send or after receive.
GPS_MSOCK_HANDLE_CACHE, // Tx: Clean cache before sending / Rx: Invalidate cache before receive.
GPS_MSOCK_COPY // Tx: Copy to shared memory before sending / Rx: Currently not supported.
} gpsMsockAction_t;
typedef struct gpsPkgDataHdr
{
int svcId;
int procId;
int msglen;
} gpsPkgDataHdr_t;
/*message block stored in share memmory*/
typedef struct gpsPkgData
{
gpsPkgDataHdr_t apiMsg;
U8 rawData[MAX_SHM_MSG_SIZE];
} gpsPkgData_t;
typedef struct
{
void (*gpsMsockRxIndCB)(void*, U32) ; // Data indication (Pointer to the data & its length).
void (*gpsMsockLinkStatusIndCB)(U32) ; // Link status (TRUE=Up, FALSE=Down).
void (*gpsMsockLowWmIndCB)(void) ; // Low water mark indication - can restart sending.
void (*gpsMsockTxDoneCnfCB)(void*) ; // Tx complete (Pointer to buffer) - can free the buffer.
void (*gpsMsockTxFailCnfCB)(void*) ; // Tx fail (Pointer to buffer) - can free the buffer.
} gpsMsockCB_t;
typedef struct gpsMSockDataNode
{
struct gpsMSockDataNode* pNext, *pPrev;
U32 ServiceId; /*identify it's GPS or Sensor message*/
U32 Length; /*gps message length*/
U32 segCnt; /*total block number of big message*/
void* pData; /*save gps raw message*/
} gpsMSockDataNode_t;
typedef struct gpsMSockDataBase
{
//gpsMsockConfig_t Config ;
U8 LowWmIndNeeded, HighWmReached;
//gpsMsockLinkState_t LinkState ;
U8 HighWm ;
U8 LowWm ;
gpsMsockCB_t CallBackFunc ;
//U8 FuncExtAvailable;
U8 ServiceBusy;
/* attributes for rx */
gpsMSockDataNode_t* pRxDataLinkHeader, *pRxDataLinkTail;
gpsMutexT rxDataMutex;
U32 rxDataLinkCnt;
U32 rxDiscardCount;
U32 rxDataLength;
U32 rxDataTotalLen;
/* attributes for tx */
gpsMSockDataNode_t* pTxDataLinkHeader, *pTxDataLinkTail;
gpsMutexT txDataMutex;
U32 txDataLinkCnt;
U32 txDiscardCount;
U32 txDataLength; /* raw gps data length in tx database*/
U32 txDataTotalLen; /*total data length has been sent*/
//U8 TxPriority;
/* the sibling in same priority */
//struct gpsMSockDataBase* pTxNextSibling, *pTxPrevSibling;
/* attributes for Tx flow control */
U32 TxDataCountHwm;
U32 TxDataCountLwm;
U32 TxDataLengthHwm;
U32 TxDataLengthLwm;
//void* TxSemaphore;
U8 TxIsWaiting;
/* attributes for big packet */
gpsMSockDataNode_t* pCurrentDataNode;
U32 RxOffset;
U32 rxPlOffset;
/* statistics */
U32 Send; /*records how many msg blocks have been send*/
U32 TotalRxBytes;
U32 TotalTxBytes;
} gpsMSockDataBase_t;
extern void gpsMsockPutsMsg(U8* data, U16 len, U32 flags);
extern void gpsMockMsgProcThread(U32 priv);
extern void gpsMsockTxThread(U32 parameter);
extern void gpsMsockRead(void);
extern void gpsMsockResourceInit(void);
#endif