[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/cp/ps/driver/src/public/inc/io_request.h b/cp/ps/driver/src/public/inc/io_request.h
new file mode 100644
index 0000000..1d143ce
--- /dev/null
+++ b/cp/ps/driver/src/public/inc/io_request.h
@@ -0,0 +1,335 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name:io_request.h
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: 1.0
+ * Author: geanfeng
+ * Date: 2013-09-25
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ ********************************************************************************/
+
+#ifndef _IO_REQUEST_H
+#define _IO_REQUEST_H
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_list.h"
+#include "ring_queue.h"
+#include "request_queue.h"
+/****************************************************************************
+* Macros
+****************************************************************************/
+/****************************************************************************
+* Types
+****************************************************************************/
+typedef enum _T_DONE_STATE {
+ REQUEST_SUCCESS = 0,
+ REQUEST_NODEV,
+ REQUEST_ERROR,
+}T_DONE_STATE;
+
+typedef enum _T_IO_HND_STATE
+{
+ IO_REQUEST_UNCREATED = 0,
+ IO_REQUEST_CREATED,
+ IO_REQUEST_FORCE_EXIT,
+}
+T_IO_HND_STATE;
+
+typedef enum _T_IO_REQUEST_STATE
+{
+ IO_REQUEST_STOP = 0,
+ IO_REQUEST_START,
+ IO_REQUEST_START_TO_SUSPEND,
+ IO_REQUEST_STOP_TO_SUSPEND,
+}
+T_IO_REQUEST_STATE;
+
+
+typedef enum _T_IO_REQUEST_DIRECTION
+{
+ IO_REQUEST_READ = 0,
+ IO_REQUEST_WRITE,
+ IO_REQUEST_READ_WRITE,
+}
+T_IO_REQUEST_DIRECTION;
+
+
+typedef enum _T_IO_REQUEST_BLOCK_TYPE
+{
+ IO_REQUEST_NO_WAIT = 0,
+ IO_REQUEST_WAIT_FOREVER,
+}
+T_IO_REQUEST_BLOCK_TYPE;
+
+typedef struct _T_IO_RequestOps
+{
+ SINT32 (*hal_enable)(VOID *reqHndData);
+ SINT32 (*hal_disable)(VOID *reqHndData);
+ SINT32 (*start_request)(VOID *reqHndData, T_IO_REQUEST_DIRECTION reqDirection);
+ VOID (*free_request) (VOID *reqHndData, T_IO_REQUEST_DIRECTION reqDirection, T_Request *req);
+ SINT32 (*request_done)(VOID *reqHndData, T_Request *req, T_DONE_STATE doneState);
+}
+T_IO_RequestOps;
+
+typedef struct _T_Request_SgList
+{
+ UINT8 *reqBuffer;
+ UINT32 reqCount;
+}
+T_Request_SgList;
+
+
+typedef struct _T_IO_RequestHnd T_IO_RequestHnd;
+
+typedef SINT32 (*RequestDoneHnd)(T_IO_RequestHnd *, T_Request_SgList *, T_DONE_STATE);
+
+
+typedef struct _T_IO_RequestHnd
+{
+ struct list_head node; /* node*/
+ UINT8 *name;
+ T_IO_REQUEST_DIRECTION reqDirection;
+ UINT32 reqSize;
+ volatile T_IO_HND_STATE hndState;
+ UINT32 isSuspend;
+ UINT32 halEnabled;
+ T_IO_RequestOps *ops;
+ VOID *reqHndData;
+
+ /*read*/
+ UINT32 readReqCount;
+ T_Request_Queue *readQ;
+ T_Ring_Queue *readDoneBuffer;
+ T_IO_REQUEST_STATE readReqState;
+ ZOSS_SEMAPHORE_ID readReqSem;
+ RequestDoneHnd readDoneFn;
+ T_Request_SgList readSgList;
+ UINT32 readSgListMaxCount;
+ UINT32 readFreeCnt;
+
+ /*write*/
+ UINT32 writeReqCount;
+ T_Request_Queue *writeQ;
+ T_IO_REQUEST_STATE writeReqState;
+ ZOSS_SEMAPHORE_ID writeReqSem;
+ RequestDoneHnd writeDoneFn;
+ T_Request_SgList writeSgList;
+ UINT32 writeSgListMaxCount;
+ UINT32 writeFreeCnt;
+
+}
+T_IO_RequestHnd;
+
+
+/****************************************************************************
+* Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+/****************************************************************************
+* Function Prototypes
+****************************************************************************/
+
+/*******************************************************************************
+ * Function: IORequest_Create
+ * Description:create the IO request handle, configure the params.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:.
+ ********************************************************************************/
+T_IO_RequestHnd * IORequest_Create(UINT8* name,
+ T_IO_REQUEST_DIRECTION reqDirection, UINT32 reqSize,
+ VOID *reqHndData, T_IO_RequestOps *ops,
+ UINT32 readReqCount, UINT32 readSgListMaxCount,
+ UINT32 writeReqCount, UINT32 writeSgListMaxCount);
+
+/*******************************************************************************
+ * Function: IORequest_SubmitReadRequest
+ * Description:submit the read request.
+ * Input:
+ * reqHnd: the handle of request.
+ * req: the submit request.
+ * Output:None
+ *
+ * Returns:
+ * DRV_SUCCESS: success
+ ********************************************************************************/
+SINT32 IORequest_SubmitReadRequest(T_IO_RequestHnd *reqHnd, T_Request *req);
+
+/*******************************************************************************
+ * Function: IORequest_FetchDoneRequest
+ * Description:fetch the completed read request.
+ * Input:
+ * reqHnd: the handle of request.
+ * blockType: the block type of this operation. no wait or wait forever.
+ * Output:None
+ * req: the complete read request.
+ * Returns:
+ * DRV_SUCCESS: success
+ * DRV_ERROR_AGAIN: no wait, need fetch again.
+ * DRV_ERROR_ABORT: force exit.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_FetchDoneRequest(T_IO_RequestHnd *reqHnd, T_Request *req, T_IO_REQUEST_BLOCK_TYPE blockType);
+
+/*******************************************************************************
+ * Function: IORequest_SubmitWriteRequest
+ * Description:submit the write request.
+ * Input:
+ * reqHnd: the handle of request.
+ * req: the submit request.
+ * blockType: the block type of this operation. no wait or wait forever.
+ * Output:None
+ *
+ * Returns:
+ * DRV_SUCCESS: success
+ * DRV_ERROR_AGAIN: no wait, submit again.
+ * DRV_ERROR_ABORT: force exit.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_SubmitWriteRequest(T_IO_RequestHnd *reqHnd, T_Request *req, T_IO_REQUEST_BLOCK_TYPE blockType);
+
+/*******************************************************************************
+ * Function: IORequest_WaitRequestDone
+ * Description:wait the write request done.
+ * Input:
+ * reqHnd: the handle of request.
+ * Output:None
+ *
+ * Returns:
+ * DRV_SUCCESS: success
+ * DRV_ERROR_ABORT: force exit.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_WaitRequestDone(T_IO_RequestHnd *reqHnd);
+
+/*******************************************************************************
+ * Function: IORequest_GetSgList
+ * Description:get the current requests scatter list.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ T_Request_SgList* : success.
+ NULL: error
+ * Others:
+ ********************************************************************************/
+T_Request_SgList* IORequest_GetSgList(T_IO_RequestHnd *reqHnd, T_IO_REQUEST_DIRECTION reqDirection);
+
+/*******************************************************************************
+ * Function: IORequest_Done
+ * Description:has complete the request, take next proccess .
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:×¢Òâ:µ÷Óô˽ӿڵÄÓÅÏȼ¶Ò»¶¨¸ßÓÚÄ£¿éÄ򵀮äËû½Ó¿Ú£¬²»¿É±»´ò¶Ï¡£
+ ********************************************************************************/
+SINT32 IORequest_Done(T_IO_RequestHnd *reqHnd, T_IO_REQUEST_DIRECTION reqDirection);
+
+/*******************************************************************************
+ * Function: IORequest_Suspend
+ * Description:suspend the request process, stop the hal operation.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_Suspend(T_IO_RequestHnd *reqHnd);
+
+/*******************************************************************************
+ * Function: IORequest_Resume
+ * Description:resume the request process, and restart the stopped hal operation.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+VOID IORequest_Resume(T_IO_RequestHnd *reqHnd);
+
+/*******************************************************************************
+ * Function: IORequest_ForceExit
+ * Description: force the higher process exit.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+VOID IORequest_ForceExit(T_IO_RequestHnd *reqHnd);
+/*******************************************************************************
+ * Function: IORequest_CancelExit
+ * Description: cancel exit mode, alloc higher process enter iorequest module.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ * Others:
+ ********************************************************************************/
+VOID IORequest_CancelExit(T_IO_RequestHnd *reqHnd);
+/*******************************************************************************
+ * Function: IORequest_Destroy
+ * Description:release the IO Request Handle, and inform the higher layer.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:×¢Òâ:º¯Êý²»¸ºÔðÊÍ·ÅreqHnd¿Õ¼ä£¬½öÉèÖúÏÊÊ״̬.
+ ÔÚÉϲãÈ·±£Ê±»ú°²È«ºó£¬²Å¿ÉÊͷŸÿռ䡣
+ ********************************************************************************/
+VOID IORequest_Destroy(T_IO_RequestHnd *reqHnd);
+
+/*******************************************************************************
+ * Function: IORequest_Print
+ * Description:print the debug info.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+VOID IORequest_Print(T_IO_RequestHnd *reqHnd);
+
+/*******************************************************************************
+ * Function: IORequest_PrintAll
+ * Description:print the debug info.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+VOID IORequest_PrintAll(VOID);
+
+#endif/*_IO_REQUEST_H*/
+
diff --git a/cp/ps/driver/src/public/inc/qalloc.h b/cp/ps/driver/src/public/inc/qalloc.h
new file mode 100644
index 0000000..98ab2b4
--- /dev/null
+++ b/cp/ps/driver/src/public/inc/qalloc.h
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name:hal_qalloc.h
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: 1.0
+ * Author: geanfeng
+ * Date: 2013-09-25
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ ********************************************************************************/
+
+#ifndef _HAL_QALLOC_H
+#define _HAL_QALLOC_H
+
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+#include "drvs_list.h"
+/****************************************************************************
+* Macros
+****************************************************************************/
+
+/****************************************************************************
+* Types
+****************************************************************************/
+/*
+ * General purpose special memory pool descriptor.
+ */
+typedef struct _T_Quick_Pool {
+ struct list_head node; /* node*/
+ struct list_head chunks; /* list of chunks in this pool */
+ UINT32 count;
+ UINT8* name;
+}T_Quick_Pool;
+
+/****************************************************************************
+* Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+/****************************************************************************
+* Function Prototypes
+****************************************************************************/
+
+/**
+ * QPool_Create - create a new special memory pool
+*
+ * Create a new special memory pool that can be used to manage special purpose
+ * memory not managed by the regular kmalloc/kfree interface.
+ */
+T_Quick_Pool *QPool_Create(UINT8* name);
+
+/**
+ * QPool_AddVirt - add a new chunk of special memory to the pool
+ * @pool: pool to add new memory chunk to
+ * @virt: virtual starting address of memory chunk to add to pool
+ * @phys: physical starting address of memory chunk to add to pool
+ * @size: size in bytes of the memory chunk to add to pool
+ *
+ * Add a new chunk of special memory to the specified pool.
+ *
+ * Returns 0 on success or a -ve errno on failure.
+ */
+SINT32 QPool_AddVirt(T_Quick_Pool *pool,UINT32 virt, UINT32 size,
+ UINT32 page_size, UINT32 max_alloc_order);
+
+/**
+ * QPool_Alloc - allocate special memory from the pool
+ * @pool: pool to allocate from
+ * @size: number of bytes to allocate from the pool
+ * @debug_info: some debug info
+ *
+ * Allocate the requested number of bytes from the specified pool.
+ * Uses a first-fit algorithm.
+ */
+UINT32 QPool_Alloc(T_Quick_Pool *pool, UINT32 size, VOID *debug_info);
+
+/**
+ * QPool_Free - free allocated special memory back to the pool
+ * @pool: pool to free to
+ * @addr: starting address of memory to free back to pool
+ * @size: size in bytes of memory to free
+ *
+ */
+VOID QPool_Free(T_Quick_Pool *pool, UINT32 addr, VOID *debug_info);
+
+/**
+ * QPool_Destroy - destroy a special memory pool
+ *
+ * Destroy the specified special memory pool. Verifies that there are no
+ * outstanding allocations.
+ */
+VOID QPool_Destroy(T_Quick_Pool *pool);
+
+/**
+ * gen_pool_avail - get available free space of the pool
+ * @pool: pool to get available free space
+ *
+ * Return available free space of the specified pool.
+ */
+UINT32 QPool_Avail(T_Quick_Pool *pool);
+
+/**
+ * QPool_Size - get size in bytes of memory managed by the pool
+ * @pool: pool to get size
+ *
+ * Return size in bytes of memory managed by the pool.
+ */
+UINT32 QPool_Size(T_Quick_Pool *pool);
+
+/**
+ * QPool_Print - print the pool debug info.
+ * @pool: pool to print
+ *
+ */
+VOID QPool_Print(T_Quick_Pool *pool);
+
+/**
+ * QPool_PrintAll - print the all pool debug info.
+ *
+ */
+VOID QPool_PrintAll(VOID);
+
+#endif/*_HAL_TCLK_REG_H*/
+
diff --git a/cp/ps/driver/src/public/inc/random.h b/cp/ps/driver/src/public/inc/random.h
new file mode 100644
index 0000000..4c5de4d
--- /dev/null
+++ b/cp/ps/driver/src/public/inc/random.h
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name:random.h
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: 1.0
+ * Author: geanfeng
+ * Date: 2013-09-25
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ ********************************************************************************/
+
+#ifndef _RANDOM_H
+#define _RANDOM_H
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+/****************************************************************************
+* Macros
+****************************************************************************/
+
+/****************************************************************************
+* Types
+****************************************************************************/
+
+
+/****************************************************************************
+* Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+/****************************************************************************
+* Function Prototypes
+****************************************************************************/
+/*******************************************************************************
+ * Function: random32
+ * Description:
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ UINT32: value
+ * Others:
+ ********************************************************************************/
+UINT32 random32(VOID);
+
+
+
+#endif/*_RING_QUEUE_H*/
+
diff --git a/cp/ps/driver/src/public/inc/request_queue.h b/cp/ps/driver/src/public/inc/request_queue.h
new file mode 100644
index 0000000..357694a
--- /dev/null
+++ b/cp/ps/driver/src/public/inc/request_queue.h
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name:request_queue.h
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: 1.0
+ * Author: geanfeng
+ * Date: 2013-09-25
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ ********************************************************************************/
+
+#ifndef _REQUEST_QUEUE_H
+#define _REQUEST_QUEUE_H
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+#include "ring_queue.h"
+/****************************************************************************
+* Macros
+****************************************************************************/
+
+/****************************************************************************
+* Types
+****************************************************************************/
+typedef enum _T_QUEUE_STATE{
+ QUEUE_IDLE,
+ QUEUE_SUBMITING,
+ QUEUE_SUSPEND,
+ QUEUE_WORKING,
+}T_QUEUE_STATE;
+
+
+typedef struct _T_Request_Queue T_Request_Queue;
+typedef struct _T_Request T_Request;
+
+typedef SINT32 (*queue_notify)(T_Request_Queue *);
+
+
+/*
+ * request state
+ */
+typedef struct _T_Request_Queue {
+ T_Ring_Queue *queue;
+
+ T_QUEUE_STATE work_state;
+ T_QUEUE_STATE process_state;
+
+ queue_notify notify_fn;
+ VOID *queue_data;
+}T_Request_Queue;
+
+/*
+ * request
+ */
+typedef struct _T_Request {
+ VOID *data;
+}T_Request;
+
+
+
+/****************************************************************************
+* Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+/****************************************************************************
+* Function Prototypes
+****************************************************************************/
+T_Request_Queue *requestQueue_Create(unsigned long req_count, unsigned long req_size, queue_notify notify_fn, VOID* queue_data);
+
+SINT32 requestQueue_SubmitRequest(T_Request_Queue *q, T_Request *req);
+
+SINT32 requestQueue_FetchRequest(T_Request_Queue *q, T_Request *req);
+
+SINT32 requestQueue_Suspend(T_Request_Queue *q);
+
+SINT32 requestQueue_Resume(T_Request_Queue *q);
+
+VOID requestQueue_Destroy(T_Request_Queue *q);
+
+#endif/*_REQUEST_QUEUE_H*/
+
diff --git a/cp/ps/driver/src/public/inc/ring_queue.h b/cp/ps/driver/src/public/inc/ring_queue.h
new file mode 100644
index 0000000..1da1af3
--- /dev/null
+++ b/cp/ps/driver/src/public/inc/ring_queue.h
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name:ring_queue.h
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: 1.0
+ * Author: geanfeng
+ * Date: 2013-09-25
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ ********************************************************************************/
+
+#ifndef _RING_QUEUE_H
+#define _RING_QUEUE_H
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+/****************************************************************************
+* Macros
+****************************************************************************/
+
+/****************************************************************************
+* Types
+****************************************************************************/
+typedef enum _T_USER_PROTECT_POLICY {
+ QUEUE_PROTECT_RAW = 0,
+ QUEUE_PROTECT_MUTEX,
+ QUEUE_PROTECT_IRQ,
+}T_USER_PROTECT_POLICY;
+
+typedef struct _T_Ring_Queue {
+ UINT8 *unit_buffer;
+ UINT32 unit_buffer_size;
+ UINT32 unit_size;
+ UINT32 unit_count;
+ UINT32 write_pos;
+ UINT32 read_pos;
+
+ T_USER_PROTECT_POLICY multi_user_protect;
+ ZOSS_SEMAPHORE_ID lock;
+}T_Ring_Queue;
+
+/****************************************************************************
+* Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+/****************************************************************************
+* Function Prototypes
+****************************************************************************/
+T_Ring_Queue *ringQueue_Create(UINT32 unit_count, UINT32 unit_size, T_USER_PROTECT_POLICY multi_user_protect);
+
+SINT32 ringQueue_Init(T_Ring_Queue *queue, UINT8 *unit_buffer,
+ UINT32 unit_count, UINT32 unit_size, T_USER_PROTECT_POLICY protect_policy);
+
+SINT32 ringQueue_Enqueue(T_Ring_Queue *queue, VOID *unit);
+
+SINT32 ringQueue_Dequeue(T_Ring_Queue *queue, VOID *unit);
+
+SINT32 ringQueue_Empty(T_Ring_Queue *queue);
+
+SINT32 ringQueue_Full(T_Ring_Queue *queue);
+
+VOID ringQueue_Fush(T_Ring_Queue *queue);
+
+VOID ringQueue_Destroy(T_Ring_Queue *queue);
+
+
+#endif/*_RING_QUEUE_H*/
+
diff --git a/cp/ps/driver/src/public/src/config/hal_config.c b/cp/ps/driver/src/public/src/config/hal_config.c
new file mode 100644
index 0000000..4c76b26
--- /dev/null
+++ b/cp/ps/driver/src/public/src/config/hal_config.c
@@ -0,0 +1,23 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: hal_config.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-04-03
+********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#define DRV_CONFIG_C_DEFINE
+
+#include "drvs_general.h"
+
+/*define config variable start*/
+#include "drvs_config.h"
+/*define config variable end*/
+
diff --git a/cp/ps/driver/src/public/src/config/hal_init.c b/cp/ps/driver/src/public/src/config/hal_init.c
new file mode 100644
index 0000000..d831369
--- /dev/null
+++ b/cp/ps/driver/src/public/src/config/hal_init.c
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (C) 2013, ZTE Corporation.
+ *
+ * File Name: hal_init.c
+ * File Mark:
+ * Description: hal layer initialization
+ * Others:
+ * Version: 1.0
+ * Author: lmf
+ * Date:
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ ********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+#include "drvs_sys.h" /* for sys function */
+#include "NvConfig.h"
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+/*define the numbers of device that will be init firstly.*/
+#define HAL_DEV_INIT_NUM_MAX 64
+#if (defined _HAL_TEST)
+extern VOID Hal_TestInit( VOID );
+#define HAL_TEST() Hal_TestInit()
+#else
+#define HAL_TEST()
+#endif
+/****************************************************************************
+* Local Types
+****************************************************************************/
+
+typedef struct
+{
+ SINT32 (*Init)(VOID);
+}
+T_Hal_DevRegister;
+
+
+/****************************************************************************
+* Local Constants
+****************************************************************************/
+
+/****************************************************************************
+* Local Function Prototypes
+****************************************************************************/
+extern SINT32 zDrv_Product_Halinit(VOID);
+extern SINT32 zDrvRtc_Initiate(VOID);
+extern SINT32 zDrvNand_Read(UINT32 dwStart, UINT32 dwLen, UINT8* to);
+/****************************************************************************
+* Global Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+#ifdef _CORE_ARM_PS
+static T_Hal_DevRegister gHal_PlatDev_RegisterTbl[] =
+ {
+ /*00 config*/ {zDrvConfig_Initiate},
+ /*01 io dev*/ {zDrvIODev_Initiate},
+ /*02 rtc*/ //{zDrvRtc_Initiate},
+ {NULL}
+ };
+#endif /*_CORE_ARM_PS*/
+
+#ifdef _CORE_ARM_PHY
+static T_Hal_DevRegister gHal_PlatDev_RegisterTbl[] =
+ {
+ /*Number Device Name Device Init*/
+ /*00 ramlog*/ {zDrvRamLog_Initiate},
+ /*01 io dev*/ {zDrvIODev_Initiate},
+ /*02 Timer*/ {zDrvTimer_Initiate},
+ /*03 Dma */ {zDrvDma_Initiate},
+ /*04 icp */ {zDrvIcp_Initiate},
+ {NULL}
+ };
+#endif /*_CORE_ARM_PHY*/
+
+
+static UINT32 gHal_PlatDev_Num = (sizeof(gHal_PlatDev_RegisterTbl)/sizeof(T_Hal_DevRegister)) - 1;
+
+/****************************************************************************
+* Global Function Prototypes
+****************************************************************************/
+
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+
+/*******************************************************************************
+ * Function: zDrv_Halinit
+ * Description: Initialize device drivers in hal
+ * Parameters:
+ * Input:
+ *
+ * Output:
+ *
+ * Returns:
+ *
+ *
+ * Others:
+ ********************************************************************************/
+SINT32 zDrv_Halinit(VOID)
+{
+ UINT32 dev_index = 0;
+ SINT32 nRet;
+
+ /* if (gHal_PlatDev_Num > HAL_DEV_INIT_NUM_MAX)
+ {
+ return DRV_ERROR;
+ }*/
+
+ for (; dev_index<gHal_PlatDev_Num; dev_index++)
+ {
+
+ if (gHal_PlatDev_RegisterTbl[dev_index].Init !=NULL)
+ {
+
+ nRet = gHal_PlatDev_RegisterTbl[dev_index].Init();
+ if (nRet != DRV_SUCCESS)
+ {
+ zOss_RamLog("Hal_init:init fail,dev_index=%d!\n", dev_index);
+ zOss_RamLog("Hal_init:ret=%d!\n", nRet);
+ zOss_ASSERT(0);
+ return nRet;
+ }
+ }
+ }
+#ifdef _CORE_ARM_PS
+ /*ÐͺŻúÏà¹ØµÄHal²ã³õʼ»¯added by limeifeng 2013.10.15*/
+ nRet = zDrv_Product_Halinit();
+ if (nRet != DRV_SUCCESS)
+ {
+ return nRet;
+ }
+#endif
+
+ HAL_TEST();
+
+ return DRV_SUCCESS;
+}
+
+/*******************************************************************************
+ * Function: zDrv_Halinit
+ * Description: Initialize device drivers in hal
+ * Parameters:
+ * Input:
+ *
+ * Output:
+ *
+ * Returns:
+ *
+ *
+ * Others:
+ ********************************************************************************/
+SINT32 ARM1_Init(VOID)
+{
+ return DRV_SUCCESS;
+}
+
+/* added by lmf 2013/09/05*/
+#if defined (_CORE_ARM_PS)
+
+/**************************************************************************
+* Function: zDrvNand_PhyNvReadToRam
+* Description:´ÓNand °áÔË LTE/TDS/GGE У׼NVÊý¾Ýµ½Ram,
+* Parameters:
+* Input:None
+* Output: None
+* Returns:None
+**************************************************************************/
+SINT32 zDrvNand_PhyNvReadToRam(VOID)
+{
+ UINT32 index = 0;
+ SINT32 ret = DRV_ERROR;
+ #ifndef _USE_AMT
+ while(g_PhyNVCfg[index].uNVFlashBaseAddr != PHY_NV_CFG_END)
+ {
+ ret = zDrvNand_Read(g_PhyNVCfg[index].uNVFlashBaseAddr, g_PhyNVCfg[index].uNVSize , (UINT8*)g_PhyNVCfg[index].uNVRamBaseAddr);
+ if(ret != 0)
+ return DRV_ERROR;
+ index++;
+ }
+ #endif/*_USE_AMT*/
+ return DRV_SUCCESS;
+}
+
+#endif/*_CORE_ARM_PS*/
+
diff --git a/cp/ps/driver/src/public/src/config/makefile b/cp/ps/driver/src/public/src/config/makefile
new file mode 100644
index 0000000..e6036e8
--- /dev/null
+++ b/cp/ps/driver/src/public/src/config/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/04/03 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = config
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/debug/debug_print.c b/cp/ps/driver/src/public/src/debug/debug_print.c
new file mode 100644
index 0000000..295025e
--- /dev/null
+++ b/cp/ps/driver/src/public/src/debug/debug_print.c
@@ -0,0 +1,148 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: debug_print.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-12-16
+********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+#define DEBUG_PRINTF_MAX_LEN 224
+
+/****************************************************************************
+* Local Types
+****************************************************************************/
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+/*10×Ö½ÚÓÃÓÚ´æ·Åindex,2×Ö½Ú´æ·Å±ê¼Ç·û*/
+static char s_debugPrintfBuf[DEBUG_PRINTF_MAX_LEN+1]=
+ {
+ 0
+ };
+
+volatile T_DRV_DEBUG_PRINT_CHANNEL g_debugPrintChnSel;
+/****************************************************************************
+* macro Definitions
+****************************************************************************/
+
+extern SINT32 vsnformat(char *pcBuffer, UINT32 dwMaxCount, const char *pcParamFormat, va_list vaList);
+
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+/*******************************************************************************
+* Function:dcc_print
+* Description:
+* Parameters:
+* pFormat:
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+static void dcc_print(const char * data, int size)
+{
+ int len = 0;
+ unsigned long ch, k;
+
+ while (len < size)
+ {
+ ch = data[len];
+
+ /* Wait for Terminal Ready */
+ do
+ {
+#ifdef __GNUC__
+ asm(
+ "mrc 14, 0, %0, c0, c1\n"
+ : "=r" (k)
+ :
+ );
+#endif
+
+#ifdef __ARMCC_VERSION
+ __asm
+ {
+ MRC p14, 0, k, c0, c1;
+ }
+#endif
+
+ }
+ while (k & (0x1<<29));
+
+ /* Write */
+
+#ifdef __GNUC__
+ asm(
+ "mrc 14, 0, %0, c0, c5\n"
+ :: "r" (ch)
+ );
+#endif
+
+#ifdef __ARMCC_VERSION
+ __asm
+ {
+ MCR p14, 0, ch, c0, c5;
+ }
+#endif
+
+
+ len++;
+ }
+}
+/*******************************************************************************
+* Function:zDrvDebug_Print
+* Description: log´òÓ¡
+* Parameters:
+* pFormat:¸ñʽ»¯×Ö·û´®
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+SINT32 debug_Print(const VOID *pFormat, ... )
+{
+ va_list ap;
+ UINT32 printfCnt;
+
+ ZOSS_DISABLE_IRQ();
+
+ if (g_debugPrintChnSel == DRV_DEBUG_PRINT_DCC)
+ {
+
+ dcc_print("\n\r", 2);
+
+ va_start(ap,pFormat);
+ printfCnt=vsnformat(s_debugPrintfBuf, DEBUG_PRINTF_MAX_LEN, pFormat, ap);
+ va_end(ap);
+
+ dcc_print(s_debugPrintfBuf, printfCnt);
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+
+ ZOSS_ENABLE_IRQ();
+
+ return DRV_SUCCESS;
+}
+
+
+
diff --git a/cp/ps/driver/src/public/src/debug/makefile b/cp/ps/driver/src/public/src/debug/makefile
new file mode 100644
index 0000000..ff23c53
--- /dev/null
+++ b/cp/ps/driver/src/public/src/debug/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = debug
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/hisr/hisr.c b/cp/ps/driver/src/public/src/hisr/hisr.c
new file mode 100644
index 0000000..2d82bd6
--- /dev/null
+++ b/cp/ps/driver/src/public/src/hisr/hisr.c
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name:
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: null
+ * Author: huji
+ * Date: 2007-12-4
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ ********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+
+#ifdef _OS_OSE_
+#ifndef FAST_SEM
+#define FAST_SEM
+#endif
+#endif
+
+#if 0
+#ifndef _OS_ARENA
+#ifndef FAST_SEM
+#define FAST_SEM
+#endif
+#endif
+#endif
+
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+#ifndef FAST_SEM
+#define HISR_SEM_NAME "hisr_sem/%d"
+#endif
+
+/****************************************************************************
+* Local Types
+****************************************************************************/
+
+/****************************************************************************
+* Local Constants
+****************************************************************************/
+
+/****************************************************************************
+* Local Function Prototypes
+****************************************************************************/
+
+/****************************************************************************
+* Global Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+static UINT32 ignore = 0;
+/****************************************************************************
+* Global Function Prototypes
+****************************************************************************/
+
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+SINT32 zDrv_HisrCreate(T_Drv_Hisr * hisr, CHAR *name, SINT32 stackSize, SINT32 priority, FUNC_HISRENTRY hisrEntry, VOID *hisrDevice)
+{
+
+ assert(hisr != NULL);
+ if (hisr == NULL)
+ {
+ return DRV_ERR_INVALID_PARAM;
+ }
+
+ hisr->active = 0;
+ hisr->event = 0;
+ hisr->devPtr = (void *)hisrDevice;
+
+#ifndef FAST_SEM
+{
+ CHAR semName[32];
+ static UINT8 i=0;
+
+ memset(semName, 0, 32);
+
+ sprintf((char *)semName, HISR_SEM_NAME, i++);
+
+ hisr->semid = zOss_CreateSemaphore(semName, 0);
+}
+#endif
+ hisr->pid= zOss_CreateThread(name, hisrEntry, (SINT32)hisrDevice, ( UINT32 )stackSize, ( UINT32 )priority, 0, 1);
+
+ if (hisr->pid == NULL)
+ {
+ return DRV_ERR_HISR_CREATE_FAIL;
+ }
+
+ return DRV_SUCCESS;
+}
+
+VOID zDrv_HisrFree(T_Drv_Hisr * hisr)
+{
+ UINT32 nRet;
+ if (hisr == NULL)
+ return;
+ if (hisr->pid != NULL)
+ {
+ nRet = zOss_DeleteThread(hisr->pid);
+ if ( ZOSS_SUCCESS != nRet )
+ {
+
+ }
+ }
+#ifndef FAST_SEM
+ if (hisr->semid != NULL)
+ {
+ nRet = zOss_DeleteSemaphore(hisr->semid);
+ if ( ZOSS_SUCCESS != nRet )
+ {
+
+ }
+ }
+#endif
+
+ return;
+}
+
+VOID zDrv_HisrStart(T_Drv_Hisr * hisr, UINT32 event)
+{
+ UINT32 state = 0;
+ assert(hisr != NULL);
+
+ LOCK_SAVE(state);
+
+ if ((hisr->event & event) != event)
+ {
+ hisr->event |= event;
+ if (!hisr->active)
+ {
+ LOCK_RESTORE(state);
+ zDrv_HisrActivate(hisr);
+ return;
+ }
+ }
+
+ LOCK_RESTORE(state);
+ state = state>0?0:1;
+ return;
+}
+
+VOID zDrv_HisrResetEvent(T_Drv_Hisr *hisr, UINT32 event)
+{
+ UINT32 state = 0;
+ assert(hisr != NULL);
+
+ LOCK_SAVE(state);
+ hisr->event &= ~event;
+ LOCK_RESTORE(state);
+ state = state>0?0:1;
+ return;
+}
+
+
+SINT32 zDrv_HisrInitSem(T_Drv_Hisr * hisr)
+{
+#ifdef FAST_SEM
+ PROCESS pid= 0;
+
+ assert(hisr != NULL);
+ if (hisr == NULL)
+ {
+ return DRV_ERR_INVALID_PARAM;
+ }
+ pid = current_process();
+ hisr->pid = (ZOSS_SEMAPHORE_ID)pid;
+
+ set_fsem(0, (PROCESS)hisr->pid);
+#endif
+ return DRV_SUCCESS;
+}
+
+VOID zDrv_HisrActivate(T_Drv_Hisr * hisr)
+{
+
+ assert(hisr != NULL);
+
+#ifdef FAST_SEM
+ signal_fsem((UINT32)hisr->pid);
+#else
+ ignore = zOss_PutSemaphore(hisr->semid);
+#endif
+ return;
+}
+
+VOID zDrv_HisrWaitSem(T_Drv_Hisr * hisr)
+{
+#ifdef FAST_SEM
+ wait_fsem(1);
+#else
+ assert(hisr != NULL);
+ ignore = zOss_GetSemaphore(hisr->semid, ZOSS_WAIT_FOREVER);
+#endif
+ if ( ignore )
+ {}
+ return;
+}
+
diff --git a/cp/ps/driver/src/public/src/hisr/makefile b/cp/ps/driver/src/public/src/hisr/makefile
new file mode 100644
index 0000000..f0f2684
--- /dev/null
+++ b/cp/ps/driver/src/public/src/hisr/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = hisr
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/ioRequest/io_request.c b/cp/ps/driver/src/public/src/ioRequest/io_request.c
new file mode 100644
index 0000000..e30ed55
--- /dev/null
+++ b/cp/ps/driver/src/public/src/ioRequest/io_request.c
@@ -0,0 +1,1113 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: io_request.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-10-21
+********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+#include "drvs_assert.h"
+#include "io_request.h"
+#include "drvs_debug.h"
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+
+
+/****************************************************************************
+* Local Types
+****************************************************************************/
+VOID IORequest_PrintAll(VOID);
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+LIST_HEAD(g_IORequestHnd);
+UINT32 g_IORequest_Cmd_Init = 0;
+
+/****************************************************************************
+* macro Definitions
+****************************************************************************/
+
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+/*******************************************************************************
+ * Function: fill_SgList
+ * Description:fill the current request scatter list.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error, no request to deal.
+ * Others:
+ ********************************************************************************/
+static SINT32 fill_SgList(T_Request_Queue *reqQ, UINT32 reqSize, T_Request_SgList *sgList, UINT32 sgListMaxCount)
+{
+ UINT32 index = 0;
+ SINT32 ret = 0;
+ UINT32 reqBufferPos = 0;
+
+ while (index < sgListMaxCount)
+ {
+ ret = requestQueue_FetchRequest(reqQ, (T_Request *)&sgList->reqBuffer[reqBufferPos]);
+ if (ret == DRV_ERROR_EMPTY)
+ {
+ break;
+ }
+ else if (ret == DRV_SUCCESS)
+ {
+ index++;
+ reqBufferPos += reqSize;
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+ }
+
+ sgList->reqCount = index;
+
+ if (sgList->reqCount)
+ return DRV_SUCCESS;
+ else
+ return DRV_ERROR;
+}
+/*******************************************************************************
+ * Function: free_Request
+ * Description: free the request.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+* Others:
+ ********************************************************************************/
+static SINT32 free_Request(T_IO_RequestHnd * reqHnd, T_IO_REQUEST_DIRECTION reqDirection, T_Request *req)
+{
+ if (reqDirection == IO_REQUEST_READ)
+ {
+ reqHnd->readFreeCnt++;
+ }
+ else if (reqDirection == IO_REQUEST_WRITE)
+ {
+ reqHnd->writeFreeCnt++;
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+ reqHnd->ops->free_request(reqHnd->reqHndData, reqDirection, req);
+ return DRV_SUCCESS;
+}
+/*******************************************************************************
+ * Function: free_AllRequest
+ * Description:free all requests in IORequest module.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+static SINT32 free_AllRequest(T_IO_RequestHnd * reqHnd)
+{
+ SINT32 ret = DRV_SUCCESS;
+ T_Request *req = NULL;
+
+ if (reqHnd == NULL || reqHnd->reqSize == 0)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ req = (T_Request *)zOss_Malloc(reqHnd->reqSize);
+ zDrv_ASSERT(req != NULL);
+
+ ret = DRV_SUCCESS;
+ if (reqHnd->readQ)
+ {
+ requestQueue_Suspend(reqHnd->readQ);
+ while (ret == DRV_SUCCESS)
+ {
+ ret = requestQueue_FetchRequest(reqHnd->readQ, req);
+ if (ret == DRV_SUCCESS)
+ {
+ if (reqHnd->ops->request_done)
+ reqHnd->ops->request_done(reqHnd->reqHndData, req, REQUEST_NODEV);
+ free_Request(reqHnd, IO_REQUEST_READ, req);
+ }
+ }
+ }
+
+ ret = DRV_SUCCESS;
+ if (reqHnd->writeQ)
+ {
+ requestQueue_Suspend(reqHnd->writeQ);
+ while (ret == DRV_SUCCESS)
+ {
+ ret = requestQueue_FetchRequest(reqHnd->writeQ, req);
+ if (ret == DRV_SUCCESS)
+ {
+ if (reqHnd->ops->request_done)
+ reqHnd->ops->request_done(reqHnd->reqHndData, req, REQUEST_NODEV);
+ free_Request(reqHnd, IO_REQUEST_WRITE, req);
+ }
+ }
+ }
+
+ ret = DRV_SUCCESS;
+ if (reqHnd->readDoneBuffer)
+ {
+ while (ret == DRV_SUCCESS)
+ {
+ ret = ringQueue_Dequeue(reqHnd->readDoneBuffer, req);
+ if (ret == DRV_SUCCESS)
+ {
+ if (reqHnd->ops->request_done)
+ reqHnd->ops->request_done(reqHnd->reqHndData, req, REQUEST_NODEV);
+ free_Request(reqHnd, IO_REQUEST_READ, req);
+ }
+ }
+ }
+
+ if (reqHnd->readReqState == IO_REQUEST_START || reqHnd->readReqState == IO_REQUEST_START_TO_SUSPEND)
+ {
+ ret = reqHnd->readDoneFn(reqHnd, &reqHnd->readSgList, REQUEST_NODEV);
+ }
+ if (reqHnd->writeReqState == IO_REQUEST_START || reqHnd->writeReqState == IO_REQUEST_START_TO_SUSPEND)
+ {
+ ret = reqHnd->writeDoneFn(reqHnd, &reqHnd->writeSgList, REQUEST_NODEV);
+ }
+
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: read_Start
+ * Description:start the read process.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+static SINT32 read_Start(T_Request_Queue *queue)
+{
+ T_IO_RequestHnd * reqHnd = NULL;
+ SINT32 ret = 0;
+
+ reqHnd = (T_IO_RequestHnd*)queue->queue_data;
+
+ if (reqHnd->readReqState == IO_REQUEST_START)
+ return 0;
+
+ if (reqHnd->readReqState == IO_REQUEST_STOP || reqHnd->readReqState == IO_REQUEST_STOP_TO_SUSPEND)
+ {
+ ret = fill_SgList(reqHnd->readQ, reqHnd->reqSize, &reqHnd->readSgList, reqHnd->readSgListMaxCount);
+ if (ret != DRV_SUCCESS)
+ {
+ reqHnd->readReqState = IO_REQUEST_STOP;
+ return DRV_ERROR;
+ }
+ }
+ reqHnd->readReqState = IO_REQUEST_START;
+
+ zDrv_ASSERT(reqHnd->halEnabled);
+ ret = reqHnd->ops->start_request(reqHnd->reqHndData, IO_REQUEST_READ);
+
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: read_Done
+ * Description:asynchronous read process done, put the requests to the done queue and start the next request if it is necessarily .
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+static SINT32 read_Done(T_IO_RequestHnd *reqHnd, T_Request_SgList * reqSgList, T_DONE_STATE state)
+{
+ SINT32 ret = 0;
+ T_Request *req = NULL;
+ UINT32 index = 0;
+
+ if (reqHnd == NULL || reqSgList == NULL || reqSgList->reqCount == 0)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (state == REQUEST_SUCCESS)
+ {
+ zDrv_ASSERT(reqHnd->readReqState == IO_REQUEST_START);
+ zDrv_ASSERT(reqHnd->readDoneBuffer != NULL);
+
+ /*add to the done request buffer*/
+ while (index < reqSgList->reqCount)
+ {
+ req = (T_Request *)(&reqSgList->reqBuffer[index*reqHnd->reqSize]);
+ ret = ringQueue_Enqueue(reqHnd->readDoneBuffer, req);
+ zDrv_ASSERT(ret == DRV_SUCCESS);
+ if (reqHnd->ops->request_done)
+ reqHnd->ops->request_done(reqHnd->reqHndData, req, state);
+ index++;
+ }
+
+ /*¼ÌÐøÏÂÒ»´ÎÇëÇó*/
+ ret = fill_SgList(reqHnd->readQ, reqHnd->reqSize, &reqHnd->readSgList, reqHnd->readSgListMaxCount);
+ if (ret == DRV_SUCCESS)
+ {
+ ret = reqHnd->ops->start_request(reqHnd->reqHndData, IO_REQUEST_READ);
+ }
+ else
+ {
+ reqHnd->readReqState = IO_REQUEST_STOP;
+ }
+ if (zOss_GetSemaphoreCount(reqHnd->writeReqSem) <= 0)
+ {
+ zOss_PutSemaphore(reqHnd->readReqSem);
+ }
+ }
+ else if (state == REQUEST_NODEV)
+ {
+ /*free the request*/
+ while (index < reqSgList->reqCount)
+ {
+ req = (T_Request *)(&reqSgList->reqBuffer[index*reqHnd->reqSize]);
+ if (reqHnd->ops->request_done)
+ reqHnd->ops->request_done(reqHnd->reqHndData, req, state);
+ free_Request(reqHnd, IO_REQUEST_READ, req);
+ index++;
+ }
+ }
+
+ return ret;
+}
+/*******************************************************************************
+ * Function: write_Start
+ * Description:start the write process.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+static SINT32 write_Start(T_Request_Queue *queue)
+{
+ T_IO_RequestHnd * reqHnd = NULL;
+ SINT32 ret = 0;
+
+ reqHnd = (T_IO_RequestHnd*)queue->queue_data;
+
+ if (reqHnd->writeReqState == IO_REQUEST_START)
+ return 0;
+
+ if (reqHnd->writeReqState == IO_REQUEST_STOP || reqHnd->writeReqState == IO_REQUEST_STOP_TO_SUSPEND)
+ {
+ ret = fill_SgList(reqHnd->writeQ, reqHnd->reqSize, &reqHnd->writeSgList, reqHnd->writeSgListMaxCount);
+ if (ret != DRV_SUCCESS)
+ {
+ reqHnd->writeReqState = IO_REQUEST_STOP;
+ return DRV_ERROR;
+ }
+ }
+ reqHnd->writeReqState = IO_REQUEST_START;
+
+ zDrv_ASSERT(reqHnd->halEnabled);
+ ret = reqHnd->ops->start_request(reqHnd->reqHndData, IO_REQUEST_WRITE);
+
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: write_Done
+ * Description:asynchronous write process done, free the requests and start the next request if it is necessarily .
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+static SINT32 write_Done(T_IO_RequestHnd *reqHnd, T_Request_SgList * reqSgList, T_DONE_STATE state)
+{
+ SINT32 ret = 0;
+ T_Request *req = NULL;
+ UINT32 index = 0;
+
+ if (reqHnd == NULL || reqSgList == NULL || reqSgList->reqCount == 0)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ /*free the request*/
+ while (index < reqSgList->reqCount)
+ {
+ req = (T_Request *)(&reqSgList->reqBuffer[index*reqHnd->reqSize]);
+ if (reqHnd->ops->request_done)
+ reqHnd->ops->request_done(reqHnd->reqHndData, req, state);
+ free_Request(reqHnd, IO_REQUEST_WRITE, req);
+ index++;
+ }
+
+ if (state == REQUEST_SUCCESS)
+ {
+ zDrv_ASSERT(reqHnd->writeReqState == IO_REQUEST_START);
+ /*¼ÌÐøÏÂÒ»´ÎÇëÇó*/
+ ret = fill_SgList(reqHnd->writeQ, reqHnd->reqSize, &reqHnd->writeSgList, reqHnd->writeSgListMaxCount);
+ if (ret == DRV_SUCCESS)
+ {
+ ret = reqHnd->ops->start_request(reqHnd->reqHndData, IO_REQUEST_WRITE);
+ }
+ else
+ {
+ reqHnd->writeReqState = IO_REQUEST_STOP;
+ }
+
+ if (zOss_GetSemaphoreCount(reqHnd->writeReqSem) <= 0)
+ {
+ zOss_PutSemaphore(reqHnd->writeReqSem);
+ }
+ }
+
+ return ret;
+}
+
+
+
+/*******************************************************************************
+ * Function: drvIORequest_CmdEntry
+ * Description:add IO Request debug cmd.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID drvIORequest_CmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ IORequest_PrintAll();
+ return ;
+}
+/*******************************************************************************
+ * Function: IORequest_Create
+ * Description:create the IO request handle, configure the params.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:.
+ ********************************************************************************/
+T_IO_RequestHnd * IORequest_Create(UINT8* name,
+ T_IO_REQUEST_DIRECTION reqDirection, UINT32 reqSize,
+ VOID *reqHndData, T_IO_RequestOps *ops,
+ UINT32 readReqCount, UINT32 readSgListMaxCount,
+ UINT32 writeReqCount, UINT32 writeSgListMaxCount)
+{
+ T_IO_RequestHnd *reqHnd = NULL;
+
+ reqHnd = (T_IO_RequestHnd *)zOss_Malloc(sizeof(T_IO_RequestHnd));
+ if (!reqHnd || (reqSize & 0x3))
+ {
+ zDrv_ASSERT(0);
+ return NULL;
+ }
+ if (!ops || !ops->hal_enable ||!ops->hal_disable ||!ops->free_request || !ops->start_request)
+ {
+ zDrv_ASSERT(0);
+ return NULL;
+ }
+
+ zOss_Memset((VOID*)reqHnd, 0x0, sizeof(T_IO_RequestHnd));
+
+ reqHnd->name = name;
+ reqHnd->reqDirection = reqDirection;
+ reqHnd->reqSize = reqSize;
+ reqHnd->reqHndData = reqHndData;
+ reqHnd->ops = ops;
+ reqHnd->readSgListMaxCount = readSgListMaxCount;
+ reqHnd->writeSgListMaxCount = writeSgListMaxCount;
+ zDrv_ASSERT((reqHnd->reqSize) > sizeof(T_Request));
+
+ /*read initialize*/
+ if (reqHnd->reqDirection == IO_REQUEST_READ || reqHnd->reqDirection == IO_REQUEST_READ_WRITE)
+ {
+ reqHnd->readReqCount = readReqCount;
+ reqHnd->readQ = requestQueue_Create(reqHnd->readReqCount, reqHnd->reqSize, read_Start, reqHnd);
+ if (!reqHnd->readQ || ((UINT32)reqHnd->readQ & 0x3))
+ goto error;
+ reqHnd->readDoneBuffer = ringQueue_Create(reqHnd->readReqCount + reqHnd->readSgListMaxCount, reqHnd->reqSize, QUEUE_PROTECT_RAW);
+ if (!reqHnd->readDoneBuffer || ((UINT32)reqHnd->readDoneBuffer & 0x3))
+ goto error;
+ reqHnd->readSgList.reqBuffer = (UINT8 *)zOss_Malloc(reqHnd->reqSize * reqHnd->readSgListMaxCount);
+ if (!reqHnd->readSgList.reqBuffer || ((UINT32)reqHnd->readSgList.reqBuffer & 0x3))
+ goto error;
+ reqHnd->readReqSem = zOss_CreateSemaphore("readReqSem", 0x0);
+ if (!reqHnd->readReqSem)
+ goto error;
+
+ reqHnd->readReqState = IO_REQUEST_STOP;
+ reqHnd->readDoneFn = read_Done;
+ }
+
+ /*write initialize*/
+ if (reqHnd->reqDirection == IO_REQUEST_WRITE || reqHnd->reqDirection == IO_REQUEST_READ_WRITE)
+ {
+ reqHnd->writeReqCount = writeReqCount;
+ reqHnd->writeQ = requestQueue_Create(reqHnd->writeReqCount, reqHnd->reqSize, write_Start, reqHnd);
+ if (!reqHnd->writeQ || ((UINT32)reqHnd->writeQ & 0x3))
+ goto error;
+ reqHnd->writeSgList.reqBuffer = (UINT8 *)zOss_Malloc(reqHnd->reqSize * reqHnd->writeSgListMaxCount);
+ if (!reqHnd->writeSgList.reqBuffer || ((UINT32)reqHnd->writeSgList.reqBuffer & 0x3))
+ goto error;
+ reqHnd->writeReqSem = zOss_CreateSemaphore("writeReqSem", 0x0);
+ if (!reqHnd->writeReqSem)
+ goto error;
+
+ reqHnd->writeReqState= IO_REQUEST_STOP;
+ reqHnd->writeDoneFn = write_Done;
+ }
+
+ /*enable hal operations*/
+ if (reqHnd->ops && reqHnd->ops->hal_enable)
+ reqHnd->ops->hal_enable(reqHnd->reqHndData);
+ reqHnd->halEnabled = TRUE;
+
+ reqHnd->isSuspend = FALSE;
+ reqHnd->hndState = IO_REQUEST_CREATED;
+
+ list_add(&reqHnd->node, &g_IORequestHnd);
+
+ if (!g_IORequest_Cmd_Init)
+ {
+ zOss_AddShellCmd("iorequest", drvIORequest_CmdEntry, "DRV IO Request Info");
+ g_IORequest_Cmd_Init = 1;
+ }
+
+ return reqHnd;
+
+error:
+ if (reqHnd->readQ)
+ requestQueue_Destroy(reqHnd->readQ);
+ if (reqHnd->readDoneBuffer)
+ ringQueue_Destroy(reqHnd->readDoneBuffer);
+ if (reqHnd->readReqSem)
+ zOss_DeleteSemaphore(reqHnd->readReqSem);
+ if (reqHnd->writeSgList.reqBuffer)
+ zOss_Free(reqHnd->writeSgList.reqBuffer);
+
+ if (reqHnd->writeQ)
+ requestQueue_Destroy(reqHnd->readQ);
+ if (reqHnd->writeReqSem)
+ zOss_DeleteSemaphore(reqHnd->writeReqSem);
+ if (reqHnd->readSgList.reqBuffer)
+ zOss_Free(reqHnd->readSgList.reqBuffer);
+
+ zDrv_ASSERT(0);
+ return NULL;
+}
+
+/*******************************************************************************
+ * Function: IORequest_SubmitReadRequest
+ * Description:submit the read request.
+ * Input:
+ * reqHnd: the handle of request.
+ * req: the submit request.
+ * Output:None
+ *
+ * Returns:
+ * DRV_SUCCESS: success
+ ********************************************************************************/
+SINT32 IORequest_SubmitReadRequest(T_IO_RequestHnd *reqHnd, T_Request *req)
+{
+ SINT32 ret = 0;
+
+ if (reqHnd == NULL || req == NULL || reqHnd->reqDirection == IO_REQUEST_WRITE || reqHnd->hndState == IO_REQUEST_UNCREATED)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ ret = requestQueue_SubmitRequest(reqHnd->readQ, req);
+ zDrv_ASSERT(ret == DRV_SUCCESS);
+
+ return ret;
+}
+/*******************************************************************************
+ * Function: IORequest_FetchDoneRequest
+ * Description:fetch the completed read request.
+ * Input:
+ * reqHnd: the handle of request.
+ * blockType: the block type of this operation. no wait or wait forever.
+ * Output:None
+ * req: the complete read request.
+ * Returns:
+ * DRV_SUCCESS: success
+ * DRV_ERROR_AGAIN: no wait, need fetch again.
+ * DRV_ERROR_ABORT: force exit.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_FetchDoneRequest(T_IO_RequestHnd *reqHnd, T_Request *req, T_IO_REQUEST_BLOCK_TYPE blockType)
+{
+ SINT32 ret = DRV_SUCCESS;
+
+ if (reqHnd == NULL || req == NULL || reqHnd->reqDirection == IO_REQUEST_WRITE || reqHnd->hndState == IO_REQUEST_UNCREATED)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ while (1)
+ {
+ ret = ringQueue_Dequeue(reqHnd->readDoneBuffer, req);
+ if (ret == DRV_ERROR_EMPTY)
+ {
+ if (blockType == IO_REQUEST_NO_WAIT)
+ {
+ return DRV_ERROR_AGAIN;
+ }
+ else
+ {
+ zOss_GetSemaphore(reqHnd->readReqSem, ZOSS_WAIT_FOREVER);
+ if (reqHnd->hndState == IO_REQUEST_FORCE_EXIT)
+ {
+ return DRV_ERROR_ABORT;
+ }
+ }
+ }
+ else if (ret == DRV_SUCCESS)
+ {
+ break; /*¶Á³É¹¦*/
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+ }
+
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: IORequest_SubmitWriteRequest
+ * Description:submit the write request.
+ * Input:
+ * reqHnd: the handle of request.
+ * req: the submit request.
+ * blockType: the block type of this operation. no wait or wait forever.
+ * Output:None
+ *
+ * Returns:
+ * DRV_SUCCESS: success
+ * DRV_ERROR_AGAIN: no wait, submit again.
+ * DRV_ERROR_ABORT: force exit.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_SubmitWriteRequest(T_IO_RequestHnd *reqHnd, T_Request *req, T_IO_REQUEST_BLOCK_TYPE blockType)
+{
+ SINT32 ret = 0;
+
+ if (reqHnd == NULL || req == NULL || reqHnd->reqDirection == IO_REQUEST_READ || reqHnd->hndState == IO_REQUEST_UNCREATED)
+ {
+ zDrv_ASSERT(0);
+ return 0;
+ }
+
+ while (1)
+ {
+ ret = requestQueue_SubmitRequest(reqHnd->writeQ, req);
+ if (ret == DRV_ERROR_FULL)
+ {
+ /*ÇëÇóÌύʧ°Ü*/
+ if (blockType == IO_REQUEST_NO_WAIT)
+ {
+ return DRV_ERROR_AGAIN; /*request queue is full*/
+ }
+ else
+ {
+ zOss_GetSemaphore(reqHnd->writeReqSem, ZOSS_WAIT_FOREVER);
+ if (reqHnd->hndState == IO_REQUEST_FORCE_EXIT)
+ {
+ return DRV_ERROR_ABORT;
+ }
+ }
+ }
+ else if (ret == DRV_SUCCESS)
+ {
+ break;
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+ }
+
+ return ret;
+}
+/*******************************************************************************
+ * Function: IORequest_WaitRequestDone
+ * Description:wait the write request done.
+ * Input:
+ * reqHnd: the handle of request.
+ * Output:None
+ *
+ * Returns:
+ * DRV_SUCCESS: success
+ * DRV_ERROR_ABORT: force exit.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_WaitRequestDone(T_IO_RequestHnd *reqHnd)
+{
+
+ if (reqHnd == NULL || reqHnd->reqDirection == IO_REQUEST_READ || reqHnd->hndState == IO_REQUEST_UNCREATED)
+ {
+ zDrv_ASSERT(0);
+ return 0;
+ }
+
+ /*µÈ´ýÇëÇó½áÊø*/
+ while (reqHnd->writeReqState != IO_REQUEST_STOP)
+ {
+ zOss_GetSemaphore(reqHnd->writeReqSem, ZOSS_WAIT_FOREVER);
+ if (reqHnd->hndState == IO_REQUEST_FORCE_EXIT)
+ {
+ return DRV_ERROR_ABORT;
+ }
+ }
+
+ return DRV_SUCCESS;
+}
+
+/*******************************************************************************
+ * Function: IORequest_GetSgList
+ * Description:get the current requests scatter list.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ T_Request_SgList* : success.
+ NULL: error
+ * Others:
+ ********************************************************************************/
+T_Request_SgList* IORequest_GetSgList(T_IO_RequestHnd *reqHnd, T_IO_REQUEST_DIRECTION reqDirection)
+{
+ if (reqHnd == NULL || reqHnd->halEnabled != TRUE || reqHnd->hndState == IO_REQUEST_UNCREATED)
+ {
+ zDrv_ASSERT(0);
+ return 0;
+ }
+
+ if (reqDirection == IO_REQUEST_READ)
+ {
+ return &reqHnd->readSgList;
+ }
+ else if (reqDirection == IO_REQUEST_WRITE)
+ {
+ return &reqHnd->writeSgList;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+/*******************************************************************************
+ * Function: IORequest_Done
+ * Description:has complete the request, take next proccess .
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:×¢Òâ:µ÷Óô˽ӿڵÄÓÅÏȼ¶Ò»¶¨¸ßÓÚÄ£¿éÄ򵀮äËû½Ó¿Ú£¬²»¿É±»´ò¶Ï¡£
+ ********************************************************************************/
+SINT32 IORequest_Done(T_IO_RequestHnd *reqHnd, T_IO_REQUEST_DIRECTION reqDirection)
+{
+ SINT32 ret = 0;
+
+ if (reqHnd == NULL || !reqHnd->halEnabled || reqHnd->isSuspend || reqHnd->hndState == IO_REQUEST_UNCREATED)
+ {
+ zDrv_ASSERT(0);
+ return 0;
+ }
+
+ if (reqDirection == IO_REQUEST_READ)
+ {
+ if (reqHnd->readDoneFn == NULL)
+ {
+ zDrv_ASSERT(0);
+ return 0;
+ }
+ ret = reqHnd->readDoneFn(reqHnd, &reqHnd->readSgList, REQUEST_SUCCESS);
+ }
+ else if (reqDirection == IO_REQUEST_WRITE)
+ {
+ if (reqHnd->writeDoneFn == NULL)
+ {
+ zDrv_ASSERT(0);
+ return 0;
+ }
+ ret = reqHnd->writeDoneFn(reqHnd, &reqHnd->writeSgList, REQUEST_SUCCESS);
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: IORequest_Suspend
+ * Description:suspend the request process, stop the hal operation.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+SINT32 IORequest_Suspend(T_IO_RequestHnd *reqHnd)
+{
+ SINT32 ret = DRV_SUCCESS;
+
+ if (!reqHnd || reqHnd->hndState != IO_REQUEST_CREATED)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (reqHnd->isSuspend)
+ {
+ return DRV_SUCCESS;
+ }
+
+ /*suspend the request queue*/
+ if (reqHnd->readQ)
+ {
+ requestQueue_Suspend(reqHnd->readQ);
+ }
+ if (reqHnd->writeQ)
+ {
+ requestQueue_Suspend(reqHnd->writeQ);
+ }
+
+ /*disable hal operations*/
+ if (reqHnd->ops && reqHnd->ops->hal_disable)
+ {
+ ret = reqHnd->ops->hal_disable(reqHnd->reqHndData);
+ }
+ if (ret != DRV_SUCCESS)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+ reqHnd->halEnabled = FALSE;
+
+ /*read request state*/
+ if (reqHnd->readReqState == IO_REQUEST_START)
+ {
+ reqHnd->readReqState = IO_REQUEST_START_TO_SUSPEND;
+ }
+ else if (reqHnd->readReqState == IO_REQUEST_STOP)
+ {
+ reqHnd->readReqState = IO_REQUEST_STOP_TO_SUSPEND;
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+
+ /*write request state*/
+ if (reqHnd->writeReqState == IO_REQUEST_START)
+ {
+ reqHnd->writeReqState = IO_REQUEST_START_TO_SUSPEND;
+ }
+ else if (reqHnd->writeReqState == IO_REQUEST_STOP)
+ {
+ reqHnd->writeReqState = IO_REQUEST_STOP_TO_SUSPEND;
+ }
+ else
+ {
+ zDrv_ASSERT(0);
+ }
+
+ reqHnd->isSuspend = TRUE;
+ return DRV_SUCCESS;
+}
+/*******************************************************************************
+ * Function: IORequest_Resume
+ * Description:resume the request process, and restart the stopped hal operation.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+VOID IORequest_Resume(T_IO_RequestHnd *reqHnd)
+{
+ if (!reqHnd || !reqHnd->isSuspend || reqHnd->hndState != IO_REQUEST_CREATED)
+ {
+ zDrv_ASSERT(0);
+ return ;
+ }
+
+ /*enable hal operations*/
+ if (reqHnd->ops && reqHnd->ops->hal_enable)
+ reqHnd->ops->hal_enable(reqHnd->reqHndData);
+ reqHnd->halEnabled = TRUE;
+
+ reqHnd->isSuspend = FALSE;
+
+ /*can submit request to hal*/
+ if (reqHnd->readQ)
+ {
+ requestQueue_Resume(reqHnd->readQ);
+ }
+ if (reqHnd->writeQ)
+ {
+ requestQueue_Resume(reqHnd->writeQ);
+ }
+
+ return ;
+}
+/*******************************************************************************
+ * Function: IORequest_ForceExit
+ * Description: force the higher process exit.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+VOID IORequest_ForceExit(T_IO_RequestHnd *reqHnd)
+{
+
+ if (!reqHnd || reqHnd->isSuspend || reqHnd->hndState != IO_REQUEST_CREATED)
+ {
+ zDrv_ASSERT(0);
+ return ;
+ }
+
+ reqHnd->hndState = IO_REQUEST_FORCE_EXIT;
+
+ if (reqHnd->readReqSem)
+ {
+ zOss_PutSemaphore(reqHnd->readReqSem);
+ }
+ if (reqHnd->writeReqSem)
+ {
+ zOss_PutSemaphore(reqHnd->writeReqSem);
+ }
+
+ return ;
+}
+/*******************************************************************************
+ * Function: IORequest_CancelExit
+ * Description: cancel exit mode, alloc higher process enter iorequest module.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ * Others:
+ ********************************************************************************/
+VOID IORequest_CancelExit(T_IO_RequestHnd *reqHnd)
+{
+
+ if (!reqHnd || reqHnd->isSuspend || reqHnd->hndState != IO_REQUEST_FORCE_EXIT)
+ {
+ zDrv_ASSERT(0);
+ return ;
+ }
+
+ reqHnd->hndState = IO_REQUEST_CREATED;
+ return ;
+}
+/*******************************************************************************
+ * Function: IORequest_Destroy
+ * Description:release the IO Request Handle.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ×¢Òâ:Îñ±Ø±£Ö¤Ã»ÓÐÆäËûÏß³ÌÔÚʹÓÃIORequestµÄ½Ó¿Ú¡£
+ ÈôÓÐÆäËûÏß³ÌÔÚʹÓÃIORequest½Ó¿Ú£¬Ê¹ÓÃForceExitÇ¿ÖÆÏß³ÌÍ˳ö¡£
+ Ïß³ÌÈ«²¿Í˳öºó£¬ÔÙµ÷ÓÃDestroy½Ó¿Ú½øÐÐÏú»Ù¡£
+ ********************************************************************************/
+VOID IORequest_Destroy(T_IO_RequestHnd *reqHnd)
+{
+ SINT32 ret = DRV_SUCCESS;
+
+ if (!reqHnd || reqHnd->isSuspend )
+ {
+ zDrv_ASSERT(0);
+ return ;
+ }
+
+ /*disable hal operations*/
+ if (reqHnd->ops && reqHnd->ops->hal_disable)
+ {
+ ret = reqHnd->ops->hal_disable(reqHnd->reqHndData);
+ zDrv_ASSERT(ret == DRV_SUCCESS);
+ }
+
+ reqHnd->halEnabled = FALSE;
+
+ /*free queue resource*/
+ free_AllRequest(reqHnd);
+
+ /*free memory resource*/
+ if (reqHnd->readQ)
+ requestQueue_Destroy(reqHnd->readQ);
+ if (reqHnd->readDoneBuffer)
+ ringQueue_Destroy(reqHnd->readDoneBuffer);
+ if (reqHnd->readReqSem)
+ zOss_DeleteSemaphore(reqHnd->readReqSem);
+ if (reqHnd->readSgList.reqBuffer)
+ zOss_Free(reqHnd->readSgList.reqBuffer);
+
+ if (reqHnd->writeQ)
+ requestQueue_Destroy(reqHnd->writeQ);
+ if (reqHnd->writeReqSem)
+ zOss_DeleteSemaphore(reqHnd->writeReqSem);
+ if (reqHnd->writeSgList.reqBuffer)
+ zOss_Free(reqHnd->writeSgList.reqBuffer);
+
+ list_del(&reqHnd->node);
+
+ reqHnd->hndState = IO_REQUEST_UNCREATED;
+
+ zOss_Free(reqHnd);
+
+ return ;
+}
+/*******************************************************************************
+ * Function: IORequest_Print
+ * Description:print the debug info.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+VOID IORequest_Print(T_IO_RequestHnd *reqHnd)
+{
+ UINT32 reqCount = 0;
+
+ if (!reqHnd)
+ return ;
+
+ zDrvDebug_Printf("----------IO REQUEST DEBUG INFO (%s)----------", reqHnd->name);
+
+ if (reqHnd->reqDirection == IO_REQUEST_READ)
+ {
+ zDrvDebug_Printf("IO direciton: read only");
+ }
+ else if (reqHnd->reqDirection == IO_REQUEST_WRITE)
+ {
+ zDrvDebug_Printf("IO direciton: write only");
+ }
+ else if (reqHnd->reqDirection == IO_REQUEST_READ_WRITE)
+ {
+ zDrvDebug_Printf("IO direciton: read and write");
+ }
+ else
+ {
+ zDrvDebug_Printf("IO direciton: error");
+ }
+
+ zDrvDebug_Printf("IO request size: %d", reqHnd->reqSize);
+
+ if (reqHnd->hndState == IO_REQUEST_CREATED)
+ {
+ if (reqHnd->readReqCount)
+ {
+ zDrvDebug_Printf( "[ IO Read Info ]");
+ zDrvDebug_Printf( "Request Max Count: %d", reqHnd->readReqCount);
+ zDrvDebug_Printf( "Request State: %d", reqHnd->readReqState);
+ zDrvDebug_Printf( "Read Request Semaphore Count: %d,", zOss_GetSemaphoreCount(reqHnd->readReqSem));
+ reqCount = (reqHnd->readQ->queue->write_pos + reqHnd->readQ->queue->unit_buffer_size - reqHnd->readQ->queue->read_pos) % reqHnd->readQ->queue->unit_buffer_size;
+ reqCount = reqCount / reqHnd->readQ->queue->unit_size;
+ zDrvDebug_Printf( "Read Request Queue Count: %d,", reqCount);
+ reqCount = (reqHnd->readDoneBuffer->write_pos + reqHnd->readDoneBuffer->unit_buffer_size - reqHnd->readDoneBuffer->read_pos) % reqHnd->readDoneBuffer->unit_buffer_size;
+ reqCount = reqCount / reqHnd->readDoneBuffer->unit_size;
+ zDrvDebug_Printf( "Read Done Buffer Count: %d", reqCount);
+ }
+
+ if (reqHnd->writeReqCount)
+ {
+ zDrvDebug_Printf( "[ IO Write Info ]");
+ zDrvDebug_Printf( "Request Max Count: %d", reqHnd->writeReqCount);
+ zDrvDebug_Printf( "Request State: %d ", reqHnd->writeReqState);
+ zDrvDebug_Printf( "Write Request Semaphore Count: %d,", zOss_GetSemaphoreCount(reqHnd->writeReqSem));
+ reqCount = (reqHnd->writeQ->queue->write_pos + reqHnd->writeQ->queue->unit_buffer_size - reqHnd->writeQ->queue->read_pos) % reqHnd->writeQ->queue->unit_buffer_size;
+ reqCount = reqCount / reqHnd->writeQ->queue->unit_size;
+ zDrvDebug_Printf( "Write Request Queue Count: %d", reqCount);
+ }
+ }
+
+
+
+}
+
+/*******************************************************************************
+ * Function: IORequest_PrintAll
+ * Description:print the debug info.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+VOID IORequest_PrintAll(VOID)
+{
+ struct list_head *_reqhnd, *_next_reqhnd;
+ T_IO_RequestHnd *reqHnd;
+
+ if (list_empty(&g_IORequestHnd))
+ {
+ zDrvDebug_Printf( "IO Request: no request handle to print !!!");
+ return ;
+ }
+
+ list_for_each_safe(_reqhnd, _next_reqhnd, &g_IORequestHnd)
+ {
+ reqHnd = list_entry(_reqhnd, T_IO_RequestHnd, node);
+ IORequest_Print(reqHnd);
+ }
+
+}
+
diff --git a/cp/ps/driver/src/public/src/ioRequest/makefile b/cp/ps/driver/src/public/src/ioRequest/makefile
new file mode 100644
index 0000000..0940a34
--- /dev/null
+++ b/cp/ps/driver/src/public/src/ioRequest/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = ioRequest
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/iodev/io_dev.c b/cp/ps/driver/src/public/src/iodev/io_dev.c
new file mode 100644
index 0000000..107284e
--- /dev/null
+++ b/cp/ps/driver/src/public/src/iodev/io_dev.c
@@ -0,0 +1,1704 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: io_dev.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-10-21
+********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+#include "drvs_bitops.h"
+
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+#define DEVICE_NAME_LENGTH (32)
+
+#define DEVICE_MAGIC_FLAG (0x12340000)
+#define DEVICE_MAGIC(x) (DEVICE_MAGIC_FLAG | ((UINT32)x & 0x0000FFFF))
+
+#define BIT_DISCONNECT (0x0)
+#define BIT_CLOSED (0x1)
+
+#ifdef _OS_WIN
+#define LOCK_SAVE(x) x=0
+#define LOCK_RESTORE(x)
+#endif
+/****************************************************************************
+* Local Types
+****************************************************************************/
+typedef enum _T_DRVIO_CONNECT_STATE
+{
+ DRVIO_DEVICE_DISCONNECT=0,
+ DRVIO_DEVICE_PRE_DISCONNECT,
+ DRVIO_DEVICE_CONNECT,
+} T_DRVIO_CONNECT_STATE;
+
+typedef enum _T_DRVIO_DEV_STATE
+{
+ DRVIO_DEVICE_CLOSED=0,
+ DRVIO_DEVICE_OPENED,
+ DRVIO_DEVICE_CLOSING,
+} T_DRVIO_DEV_STATE;
+
+typedef struct _T_ZDrvIODev_Entry
+{
+ struct list_head node; /* node*/
+ char name[DEVICE_NAME_LENGTH];
+ UINT32 magic;
+ T_ZDRVIO_FLAGS flags;
+
+ volatile T_DRVIO_CONNECT_STATE devConnectState;
+ volatile T_DRVIO_DEV_STATE userOpenState;
+ volatile T_DRVIO_DEV_STATE devOpenState;
+ volatile UINT32 refCount;
+
+ volatile UINT32 bitCtrl;
+ volatile UINT32 readDepth;
+ volatile UINT32 writeDepth;
+ volatile UINT32 ctrlDepth;
+ volatile SINT32 disallowDisconnect;
+
+ ZOSS_SEMAPHORE_ID waitConnectSem;
+ ZOSS_MUTEX_ID waitConnectMutex;
+
+ ZOSS_MUTEX_ID devProtectMutex;
+
+ ZOSS_SEMAPHORE_ID waitDisconnectSem;
+ ZOSS_SEMAPHORE_ID waitCloseSem;
+
+ T_ZDrvIO_DevNotify notify;
+
+ T_ZDrvIODev_Ops *ops;
+ VOID *devData;
+}
+T_ZDrvIODev_Entry;
+
+
+typedef struct _T_zDrvIO_GNotify
+{
+ struct list_head node; /* node*/
+ T_ZDrvIO_GNotifyCallBack notifyFn;
+}
+T_zDrvIO_GNotify;
+
+typedef struct _T_zDrvIO_TAB
+{
+ struct list_head devList;
+ ZOSS_SEMAPHORE_ID opMutex;
+ UINT32 devListCount;
+
+ struct list_head notifyChain;
+ UINT32 notifyCount;
+}
+T_zDrvIO_TAB;
+
+
+T_zDrvIO_TAB g_drvIOTable = {0,};
+
+#define DEVICE_LIST_LOCK() zOss_GetMutex(g_drvIOTable.opMutex, ZOSS_WAIT_FOREVER)
+#define DEVICE_LIST_UNLOCK() zOss_PutMutex(g_drvIOTable.opMutex)
+
+volatile T_ZDrvIODev_Entry *g_ioDevCurrentDisconnectIoEntry = NULL;
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+/****************************************************************************
+* macro Definitions
+****************************************************************************/
+
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+/*******************************************************************************
+ * Function: _IO_GetDevStatus
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static T_DRVIO_DEV_STATUS _IO_GetDevStatus(T_ZDrvIODev_Entry *pIOEntry)
+{
+ T_DRVIO_DEV_STATUS status = {0,};
+
+ if (pIOEntry->devConnectState == DRVIO_DEVICE_CONNECT)
+ {
+ status.CONNECT = 1;
+ }
+ return status;
+}
+
+/*******************************************************************************
+ * Function: _IO_WaitDevConnect
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static SINT32 _IO_WaitDevConnect(T_ZDrvIODev_Entry *pIOEntry)
+{
+
+ zOss_GetMutex(pIOEntry->waitConnectMutex, ZOSS_WAIT_FOREVER);
+
+ while (pIOEntry->devConnectState != DRVIO_DEVICE_CONNECT)
+ {
+ zOss_GetSemaphore(pIOEntry->waitConnectSem, ZOSS_WAIT_FOREVER);
+ }
+
+ zOss_PutMutex(pIOEntry->waitConnectMutex);
+
+ return DRV_SUCCESS;
+}
+/*******************************************************************************
+ * Function: _IO_WakeupProcess
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID _IO_WakeupProcess(T_ZDrvIODev_Entry *pIOEntry)
+{
+ UINT32 bitCtrl = pIOEntry->bitCtrl;
+
+ if (bitCtrl & (0x1 << BIT_DISCONNECT))
+ zOss_PutSemaphore(pIOEntry->waitDisconnectSem);
+
+ if (bitCtrl & (0x1 << BIT_CLOSED))
+ zOss_PutSemaphore(pIOEntry->waitCloseSem);
+}
+/*******************************************************************************
+ * Function: _IO_AllocDev
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static T_ZDrvIODev_Entry* _IO_AllocDev(const char *name)
+{
+ T_ZDrvIODev_Entry *pIOEntry = NULL;
+ UINT32 len = 0;
+
+ pIOEntry = (T_ZDrvIODev_Entry*)zOss_Malloc(sizeof(T_ZDrvIODev_Entry));
+ if (!pIOEntry)
+ {
+ zDrv_ASSERT(0);
+ return NULL;
+ }
+
+ zOss_Memset((void*)pIOEntry, 0x0, sizeof(T_ZDrvIODev_Entry));
+
+ len = strlen(name);
+ if ((len + 1) <= DEVICE_NAME_LENGTH)
+ {
+ zOss_Memcpy(pIOEntry->name, name, len+1);
+ }
+ else
+ {
+ zOss_Memcpy(pIOEntry->name, name, DEVICE_NAME_LENGTH);
+ pIOEntry->name[DEVICE_NAME_LENGTH-1]='\0';
+ }
+
+ pIOEntry->waitConnectSem = zOss_CreateSemaphore("Connect Wait Sema", 0);
+ pIOEntry->waitConnectMutex= zOss_CreateMutex("Wait Mutex", ZOSS_INHERIT);
+ pIOEntry->devProtectMutex= zOss_CreateMutex("Protect Mutex", ZOSS_INHERIT);
+
+ pIOEntry->waitDisconnectSem = zOss_CreateSemaphore("Disconnect Sema", 0);
+ pIOEntry->waitCloseSem= zOss_CreateSemaphore("Clos Sema", 0);
+
+ pIOEntry->devConnectState = DRVIO_DEVICE_DISCONNECT;
+ pIOEntry->userOpenState = DRVIO_DEVICE_CLOSED;
+ pIOEntry->devOpenState = DRVIO_DEVICE_CLOSED;
+ set_bit(BIT_DISCONNECT, &pIOEntry->bitCtrl);
+ set_bit(BIT_CLOSED, &pIOEntry->bitCtrl);
+ pIOEntry->refCount = 0;
+ pIOEntry->magic = DEVICE_MAGIC(pIOEntry);
+
+ return pIOEntry;
+}
+
+/*******************************************************************************
+ * Function: _IO_FreeDev
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID _IO_FreeDev(T_ZDrvIODev_Entry* pIOEntry)
+{
+
+ if (pIOEntry->waitConnectSem)
+ zOss_DeleteSemaphore(pIOEntry->waitConnectSem);
+ if (pIOEntry->waitConnectMutex)
+ zOss_DeleteMutex(pIOEntry->waitConnectMutex);
+ if (pIOEntry->devProtectMutex)
+ zOss_DeleteMutex(pIOEntry->devProtectMutex);
+ if (pIOEntry->waitDisconnectSem)
+ zOss_DeleteSemaphore(pIOEntry->waitDisconnectSem);
+ if (pIOEntry->waitCloseSem)
+ zOss_DeleteSemaphore(pIOEntry->waitCloseSem);
+
+ pIOEntry->magic = 0x0;
+
+ zOss_Free(pIOEntry);
+
+ return ;
+}
+
+/*******************************************************************************
+ * Function: _IO_DelDev
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID _IO_DelDev(T_ZDrvIODev_Entry* pIOEntry)
+{
+ DEVICE_LIST_LOCK();
+
+ if (pIOEntry->userOpenState == DRVIO_DEVICE_CLOSED && pIOEntry->devConnectState == DRVIO_DEVICE_DISCONNECT)
+ {
+ zDrv_ASSERT(pIOEntry->devOpenState == DRVIO_DEVICE_CLOSED);
+ list_del(&pIOEntry->node);
+ g_drvIOTable.devListCount--;
+ _IO_FreeDev(pIOEntry);
+ }
+
+ DEVICE_LIST_UNLOCK();
+}
+/*******************************************************************************
+ * Function: _IO_SearchDev
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static T_ZDrvIODev_Entry* _IO_SearchDev(const char *name)
+{
+ struct list_head *_entry, *_next_entry;
+ T_ZDrvIODev_Entry *pIOEntry = ZDRVIO_INVALID_HANDLE;
+ T_ZDrvIODev_Entry *pEntry = NULL;
+
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.devList)
+ {
+ pEntry = list_entry(_entry, T_ZDrvIODev_Entry, node);
+ if (!strcmp(name, pEntry->name))
+ {
+ pIOEntry = pEntry;
+ break;
+ }
+ }
+
+ return pIOEntry;
+}
+/*******************************************************************************
+ * Function: _IO_GetDev
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID _IO_GetDev(T_ZDrvIODev_Entry* pIOEntry)
+{
+ zOss_GetMutex(pIOEntry->devProtectMutex, ZOSS_WAIT_FOREVER);
+}
+/*******************************************************************************
+ * Function: _IO_PutDev
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID _IO_PutDev(T_ZDrvIODev_Entry* pIOEntry)
+{
+ zOss_PutMutex(pIOEntry->devProtectMutex);
+}
+/*******************************************************************************
+ * Function: _IO_Ret
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static SINT32 _IO_Ret(UINT32 ctrlVal)
+{
+ if (ctrlVal & (0x1 << BIT_DISCONNECT))
+ {
+ return DRV_ERROR_NOCONNECT;
+ }
+ else if (ctrlVal & (0x1 << BIT_CLOSED))
+ {
+ return DRV_ERR_NOT_OPENED;
+ }
+ else
+ {
+ return DRV_ERROR;
+ }
+}
+
+/*******************************************************************************
+ * Function: _IO_Ctrl
+ * Description:.
+ * Input:
+ name:
+ flags:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static SINT32 _IO_Ctrl(T_ZDrvIODev_Entry* pIOEntry, T_DRVIO_CTRL_KEY function, VOID *arg)
+{
+ SINT32 ret = DRV_SUCCESS;
+ UINT32 old_intr;
+
+ /*IO DAL control function*/
+ switch (function)
+ {
+ case IOCTL_IODEV_REGISTER_NOTIFY:
+ pIOEntry->notify =* (T_ZDrvIO_DevNotify*)arg;
+ break;
+
+ case IOCTL_IODEV_GET_DEV_STATUS:
+ *(T_DRVIO_DEV_STATUS*)arg = _IO_GetDevStatus(pIOEntry);
+ break;
+
+ case IOCTL_IODEV_WAIT_CONNECT:
+ ret = _IO_WaitDevConnect(pIOEntry);
+ break;
+
+ case IOCTL_IODEV_DISALLOW_DISCONNECT:
+ LOCK_SAVE(old_intr);
+ pIOEntry->disallowDisconnect++;
+ LOCK_RESTORE(old_intr);
+ break;
+
+ case IOCTL_IODEV_ALLOW_DISCONNECT:
+ LOCK_SAVE(old_intr);
+ pIOEntry->disallowDisconnect--;
+ LOCK_RESTORE(old_intr);
+
+ zDrv_ASSERT(pIOEntry->disallowDisconnect>=0);
+
+ if (pIOEntry->bitCtrl)
+ {
+ _IO_WakeupProcess(pIOEntry);
+ }
+ break;
+
+ default:
+ zDrv_ASSERT(0);
+ break;
+ }
+
+ return ret;
+}
+/*******************************************************************************
+ * Function: zDrvIO_Open
+ * Description:search device by device name, open it, and set the action flags.
+ * Input:
+ name: device name.
+ flags: open flags, control the device action.
+ * Output:None
+ *
+ * Returns:
+ T_ZDrvIO_Handle: the opened device handle. if error happened, return NULL.
+ * Others:
+ ********************************************************************************/
+T_ZDrvIO_Handle zDrvIO_Open(const char *name, T_ZDRVIO_FLAGS flags)
+{
+ T_ZDrvIODev_Entry *pIOEntry = ZDRVIO_INVALID_HANDLE;
+
+ if (name == NULL)
+ {
+ zDrv_ASSERT(0);
+ return ZDRVIO_INVALID_HANDLE;
+ }
+
+ DEVICE_LIST_LOCK();
+
+ pIOEntry = _IO_SearchDev(name);
+ if (pIOEntry == ZDRVIO_INVALID_HANDLE)
+ {
+ pIOEntry = _IO_AllocDev(name);
+
+ list_add(&pIOEntry->node, &g_drvIOTable.devList);
+ g_drvIOTable.devListCount++;
+ }
+
+ _IO_GetDev(pIOEntry);
+
+ if (pIOEntry->userOpenState == DRVIO_DEVICE_OPENED)
+ {
+ zDrv_ASSERT(pIOEntry->flags.SHARED);
+ zDrv_ASSERT(pIOEntry->flags.READ == flags.READ);
+ zDrv_ASSERT(pIOEntry->flags.WRITE == flags.WRITE);
+ zDrv_ASSERT(pIOEntry->flags.MULTI_READ == flags.MULTI_READ);
+ zDrv_ASSERT(pIOEntry->flags.MULTI_WRITE == flags.MULTI_WRITE);
+ }
+
+ pIOEntry->flags = flags;
+ pIOEntry->userOpenState = DRVIO_DEVICE_OPENED;
+ clear_bit(BIT_CLOSED,&pIOEntry->bitCtrl);
+
+ pIOEntry->refCount++;
+
+ DEVICE_LIST_UNLOCK();
+
+
+ if (pIOEntry->devConnectState == DRVIO_DEVICE_CONNECT && pIOEntry->devOpenState == DRVIO_DEVICE_CLOSED)
+ {
+ if (pIOEntry->ops && pIOEntry->ops->open)
+ {
+ pIOEntry->ops->open(pIOEntry->devData, flags);
+ }
+ pIOEntry->devOpenState = DRVIO_DEVICE_OPENED;
+ }
+
+ _IO_PutDev(pIOEntry);
+
+ return (T_ZDrvIO_Handle)pIOEntry;
+}
+
+/*******************************************************************************
+ * Function: zDrvIO_Read
+ * Description:read data from device.
+ * Input:
+ handle:the device handle for read.
+ buffer: the read data buffer. the buffer space supplied by high layer.
+ length:the data length need to read.
+ * Output:None
+ *
+ * Returns:
+ ret >= 0: return the actual read length.
+ DRV_ERROR_NOCONNECT: the device disconnect event happend, need return error to inform higher user.
+ other: other error maked by device.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIO_Read(T_ZDrvIO_Handle handle, UINT8* buffer, UINT32 length)
+{
+ SINT32 ret = 0;
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ UINT32 old_intr;
+ UINT32 bitCtrl;
+
+ if (pIOEntry == NULL || pIOEntry->magic != DEVICE_MAGIC(pIOEntry))
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ LOCK_SAVE(old_intr);
+ if (pIOEntry->bitCtrl)
+ {
+ bitCtrl = pIOEntry->bitCtrl;
+ LOCK_RESTORE(old_intr);
+ return _IO_Ret(bitCtrl);
+ }
+ pIOEntry->readDepth++;
+ LOCK_RESTORE(old_intr);
+
+ /*start read operations*/
+ if (pIOEntry->ops && pIOEntry->ops->read)
+ {
+ ret = pIOEntry->ops->read(pIOEntry->devData, buffer, length);
+ }
+
+ LOCK_SAVE(old_intr);
+ pIOEntry->readDepth--;
+ LOCK_RESTORE(old_intr);
+
+ if (pIOEntry->bitCtrl)
+ {
+ _IO_WakeupProcess(pIOEntry);
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: zDrvIO_Write
+ * Description:write data to IO handle
+ * Input:
+ handle:the device handle for write.
+ buffer: the write data buffer. the buffer space supplied by high layer.
+ length:the write data length.
+* Output:None
+ *
+ * Returns:
+ ret >= 0: return the actual write length.
+ DRV_ERROR_NOCONNECT: the device disconnect event happend, need return error to inform higher user.
+ other: other error maked by device.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIO_Write(T_ZDrvIO_Handle handle, UINT8* buffer, UINT32 length)
+{
+ SINT32 ret = 0;
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ UINT32 old_intr;
+ UINT32 bitCtrl;
+
+ if (pIOEntry == NULL || pIOEntry->magic != DEVICE_MAGIC(pIOEntry))
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ LOCK_SAVE(old_intr);
+ if (pIOEntry->bitCtrl)
+ {
+ bitCtrl = pIOEntry->bitCtrl;
+ LOCK_RESTORE(old_intr);
+ return _IO_Ret(bitCtrl);
+ }
+ pIOEntry->writeDepth++;
+ LOCK_RESTORE(old_intr);
+
+ /*start write operations*/
+ if (pIOEntry->ops && pIOEntry->ops->write)
+ {
+ ret = pIOEntry->ops->write(pIOEntry->devData, buffer, length);
+ }
+
+ LOCK_SAVE(old_intr);
+ pIOEntry->writeDepth--;
+ LOCK_RESTORE(old_intr);
+
+ if (pIOEntry->bitCtrl)
+ {
+ _IO_WakeupProcess(pIOEntry);
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: zDrvIO_BRead
+ * Description:read data from device.
+ * Input:
+ handle:the device handle for read.
+ buffer: the read data buffer. the buffer space supplied by high layer.
+ blkCnt:the data block count need to read.
+ pos:the read data position in device storage space.
+ * Output:None
+ *
+ * Returns:
+ ret >= 0: return the actual read length.
+ DRV_ERROR_NOCONNECT: the device disconnect event happend, need return error to inform higher user.
+ other: other error maked by device.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIO_BRead(T_ZDrvIO_Handle handle, UINT8* buffer, UINT32 blkCnt, UINT32 pos)
+{
+ SINT32 ret = 0;
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ UINT32 old_intr;
+ UINT32 bitCtrl;
+
+ if (pIOEntry == NULL || pIOEntry->magic != DEVICE_MAGIC(pIOEntry))
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ LOCK_SAVE(old_intr);
+ if (pIOEntry->bitCtrl)
+ {
+ bitCtrl = pIOEntry->bitCtrl;
+ LOCK_RESTORE(old_intr);
+ return _IO_Ret(bitCtrl);
+ }
+ pIOEntry->readDepth++;
+ LOCK_RESTORE(old_intr);
+
+ /*start read operations*/
+ if (pIOEntry->ops && pIOEntry->ops->bread)
+ {
+ ret = pIOEntry->ops->bread(pIOEntry->devData, buffer, blkCnt, pos);
+ }
+
+ LOCK_SAVE(old_intr);
+ pIOEntry->readDepth--;
+ LOCK_RESTORE(old_intr);
+
+ if (pIOEntry->bitCtrl)
+ {
+ _IO_WakeupProcess(pIOEntry);
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: zDrvIO_BWrite
+ * Description:write data to IO handle
+ * Input:
+ handle:the device handle for write.
+ buffer: the write data buffer. the buffer space supplied by high layer.
+ blkCnt:the write data block count.
+ pos:the write data position in device storage space.
+* Output:None
+ *
+ * Returns:
+ ret >= 0: return the actual write length.
+ DRV_ERROR_NOCONNECT: the device disconnect event happend, need return error to inform higher user.
+ other: other error maked by device.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIO_BWrite(T_ZDrvIO_Handle handle, UINT8* buffer, UINT32 blkCnt, UINT32 pos)
+{
+ SINT32 ret = 0;
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ UINT32 old_intr;
+ UINT32 bitCtrl;
+
+ if (pIOEntry == NULL || pIOEntry->magic != DEVICE_MAGIC(pIOEntry))
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ LOCK_SAVE(old_intr);
+ if (pIOEntry->bitCtrl)
+ {
+ bitCtrl = pIOEntry->bitCtrl;
+ LOCK_RESTORE(old_intr);
+ return _IO_Ret(bitCtrl);
+ }
+ pIOEntry->writeDepth++;
+ LOCK_RESTORE(old_intr);
+
+ /*start write operations*/
+ if (pIOEntry->ops && pIOEntry->ops->bwrite)
+ {
+ ret = pIOEntry->ops->bwrite(pIOEntry->devData, buffer, blkCnt, pos);
+ }
+
+ LOCK_SAVE(old_intr);
+ pIOEntry->writeDepth--;
+ LOCK_RESTORE(old_intr);
+
+ if (pIOEntry->bitCtrl)
+ {
+ _IO_WakeupProcess(pIOEntry);
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: zDrvIO_Ctrl
+ * Description:control device.
+ * Input:
+ handle:the device handle for control.
+ function:the control function.
+ handle:the control function arguments.
+* Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIO_Ctrl(T_ZDrvIO_Handle handle, T_DRVIO_CTRL_KEY function, VOID *arg)
+{
+ SINT32 ret = DRV_ERROR;
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ UINT32 old_intr;
+ UINT32 bitCtrl;
+
+ if (pIOEntry == NULL || pIOEntry->magic != DEVICE_MAGIC(pIOEntry))
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (function < IOCTL_IODEV_VENDOR)
+ {
+ return _IO_Ctrl(pIOEntry, function, arg);
+ }
+
+ LOCK_SAVE(old_intr);
+ if (pIOEntry->bitCtrl)
+ {
+ bitCtrl = pIOEntry->bitCtrl;
+ LOCK_RESTORE(old_intr);
+ return _IO_Ret(bitCtrl);
+ }
+ pIOEntry->ctrlDepth++;
+ LOCK_RESTORE(old_intr);
+
+ /*start device ctrl operations*/
+ if (pIOEntry->ops && pIOEntry->ops->ctrl)
+ {
+ ret = pIOEntry->ops->ctrl(pIOEntry->devData, function, arg);
+ }
+
+ LOCK_SAVE(old_intr);
+ pIOEntry->ctrlDepth--;
+ LOCK_RESTORE(old_intr);
+
+ if (pIOEntry->bitCtrl)
+ {
+ _IO_WakeupProcess(pIOEntry);
+ }
+ return ret;
+}
+
+/*******************************************************************************
+ * Function: zDrvIO_Close
+ * Description:close the device
+ * Input:
+ handle:the device handle to be closed.
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIO_Close(T_ZDrvIO_Handle handle)
+{
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ SINT32 ret = DRV_SUCCESS;
+
+ if (pIOEntry == NULL || pIOEntry->magic != DEVICE_MAGIC(pIOEntry))
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ zDrv_ASSERT(pIOEntry->userOpenState == DRVIO_DEVICE_OPENED);
+
+ _IO_GetDev(pIOEntry);
+
+ pIOEntry->refCount--;
+
+ if (pIOEntry->refCount == 0)
+ {
+ pIOEntry->userOpenState = DRVIO_DEVICE_CLOSING;
+ set_bit(BIT_CLOSED,&pIOEntry->bitCtrl);
+
+ if (pIOEntry->devConnectState == DRVIO_DEVICE_CONNECT)
+ {
+ zDrv_ASSERT(pIOEntry->disallowDisconnect == 0);
+ while (pIOEntry->readDepth || pIOEntry->writeDepth || pIOEntry->ctrlDepth)
+ {
+ zDrvDebug_Printf("DRVIO(%d): closed %s, wait finish...", zOss_GetTickCount(), pIOEntry->name);
+ zOss_GetSemaphore(pIOEntry->waitCloseSem, ZOSS_WAIT_FOREVER); //wait device operation exist
+ }
+
+ if (pIOEntry->devOpenState == DRVIO_DEVICE_OPENED)
+ {
+ if (pIOEntry->ops && pIOEntry->ops->close)
+ {
+ ret = pIOEntry->ops->close(pIOEntry->devData);
+ }
+ pIOEntry->devOpenState = DRVIO_DEVICE_CLOSED;
+ }
+ }
+
+ pIOEntry->notify.notify_fn = NULL;
+ pIOEntry->userOpenState = DRVIO_DEVICE_CLOSED;
+ }
+ _IO_PutDev(pIOEntry);
+
+ _IO_DelDev(pIOEntry);
+ return ret;
+}
+/*******************************************************************************
+ * Function: zDrvIO_RegisterGlobalNotify
+ * Description: register global notifier.
+ * Input:
+ * globalNotifyFn: global noitifier callback function
+ * Output:None
+ *
+ * Returns:
+ * T_ZDrvIO_GNotifyHandle : the global notifier handler.
+ * Others:
+ ********************************************************************************/
+T_ZDrvIO_GNotifyHandle zDrvIO_RegisterGlobalNotify(T_ZDrvIO_GNotifyCallBack globalNotifyFn)
+{
+ struct list_head *_entry, *_next_entry;
+ T_ZDrvIODev_Entry *pEntry = NULL;
+ T_zDrvIO_GNotify *pNotify = NULL;
+
+ pNotify = (T_zDrvIO_GNotify *)zOss_Malloc(sizeof(T_zDrvIO_GNotify));
+ if (!pNotify)
+ return NULL;
+
+ zOss_Memset((void*)pNotify, 0x0, sizeof(T_zDrvIO_GNotify));
+
+ pNotify->notifyFn= globalNotifyFn;
+
+ DEVICE_LIST_LOCK();
+
+ list_add(&pNotify->node, &g_drvIOTable.notifyChain);
+ g_drvIOTable.notifyCount++;
+
+ DEVICE_LIST_UNLOCK();
+
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.devList)
+ {
+ pEntry = list_entry(_entry, T_ZDrvIODev_Entry, node);
+ if (pNotify->notifyFn)
+ {
+ if(pEntry->devConnectState == DRVIO_DEVICE_CONNECT)
+ pNotify->notifyFn(pEntry->name, DRVIO_EV_CONNECT);
+ else
+ pNotify->notifyFn(pEntry->name, DRVIO_EV_DISCONNECT);
+ }
+ }
+
+
+ return (T_ZDrvIO_GNotifyHandle)pNotify;
+}
+/*******************************************************************************
+ * Function: zDrvIO_UnregisterGlobalNotify
+ * Description: unregister global notifier.
+ * Input:
+ * gNotifyHandle: the global notifier handler
+ * Output:None
+ *
+ * Returns:
+ *
+ * Others:
+ ********************************************************************************/
+VOID zDrvIO_UnregisterGlobalNotify(T_ZDrvIO_GNotifyHandle gNotifyHandle)
+{
+ T_zDrvIO_GNotify *pNotify = (T_zDrvIO_GNotify*)gNotifyHandle;
+
+ if (!pNotify)
+ return ;
+
+ DEVICE_LIST_LOCK();
+
+ list_del(&pNotify->node);
+ g_drvIOTable.notifyCount--;
+
+ DEVICE_LIST_UNLOCK();
+
+ zOss_Free(pNotify);
+ return ;
+}
+/*******************************************************************************
+ * Function: zDrvIODev_Connect
+ * Description:install and connect io device to device table.
+ * Input:
+ name: the device name to connect.
+ devData: the device private data to be combined.
+ ops: the device I/O operation.
+ * Output:None
+ *
+ * Returns:
+ T_ZDrvIODev_Handle: none zero.
+ NULL: error.
+ * Others:
+ ********************************************************************************/
+T_ZDrvIODev_Handle zDrvIODev_Connect(const char *name, VOID *devData, T_ZDrvIODev_Ops *ops)
+{
+ struct list_head *_entry, *_next_entry;
+ T_ZDrvIODev_Entry *pIOEntry = NULL;
+ T_zDrvIO_GNotify *pNotify = NULL;
+
+ if (name == NULL || g_drvIOTable.opMutex == NULL)
+ {
+ zDrv_ASSERT(0);
+ return NULL;
+ }
+
+ DEVICE_LIST_LOCK();
+
+ pIOEntry = _IO_SearchDev(name);
+ if (pIOEntry == NULL)
+ {
+ pIOEntry = _IO_AllocDev(name);
+ list_add(&pIOEntry->node, &g_drvIOTable.devList);
+ g_drvIOTable.devListCount++;
+ }
+ zDrv_ASSERT(pIOEntry->devConnectState == DRVIO_DEVICE_DISCONNECT);
+
+ _IO_GetDev(pIOEntry);
+
+ pIOEntry->devData = devData;
+ pIOEntry->ops = ops;
+ pIOEntry->devConnectState = DRVIO_DEVICE_CONNECT;
+
+ DEVICE_LIST_UNLOCK();
+
+
+ if (pIOEntry->userOpenState == DRVIO_DEVICE_OPENED && pIOEntry->devOpenState == DRVIO_DEVICE_CLOSED)
+ {
+ if (pIOEntry->ops && pIOEntry->ops->open)
+ {
+ pIOEntry->ops->open(pIOEntry->devData, pIOEntry->flags);
+ }
+ pIOEntry->devOpenState = DRVIO_DEVICE_OPENED;
+ }
+
+ clear_bit(BIT_DISCONNECT, &pIOEntry->bitCtrl);
+
+ _IO_PutDev(pIOEntry);
+
+ /*notify current device user*/
+ zOss_PutSemaphore(pIOEntry->waitConnectSem);
+
+ /*notify device user*/
+ if (pIOEntry->notify.notify_fn)
+ {
+ pIOEntry->notify.notify_fn(pIOEntry->notify.privData, DRVIO_EV_CONNECT);
+ }
+
+ /*notify all*/
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.notifyChain)
+ {
+ pNotify = list_entry(_entry, T_zDrvIO_GNotify, node);
+ if (pNotify->notifyFn)
+ pNotify->notifyFn(pIOEntry->name, DRVIO_EV_CONNECT);
+ }
+
+ return (T_ZDrvIODev_Handle)pIOEntry;
+}
+
+/*******************************************************************************
+ * Function: zDrvIODev_Disconnect
+ * Description:uninstall the io device.
+ * Input:
+ handle: the device handle to disconnect.
+ * Output:None
+ *
+ * Returns:
+ NULL: error.
+ * Others:
+ ********************************************************************************/
+VOID zDrvIODev_Disconnect(T_ZDrvIODev_Handle handle)
+{
+ T_ZDrvIODev_Entry *pIOEntry = (T_ZDrvIODev_Entry *)handle;
+ struct list_head *_entry, *_next_entry;
+ T_zDrvIO_GNotify *pNotify = NULL;
+ UINT32 param;
+
+ if (!handle || pIOEntry->devConnectState != DRVIO_DEVICE_CONNECT)
+ {
+ //zDrv_ASSERT(0);
+ return ;
+ }
+
+ g_ioDevCurrentDisconnectIoEntry = pIOEntry;
+
+ _IO_GetDev(pIOEntry);
+ pIOEntry->devConnectState = DRVIO_DEVICE_PRE_DISCONNECT;
+ set_bit(BIT_DISCONNECT, &pIOEntry->bitCtrl);
+ _IO_PutDev(pIOEntry);
+
+ /*notify current device user*/
+ if (pIOEntry->notify.notify_fn)
+ {
+ pIOEntry->notify.notify_fn(pIOEntry->notify.privData, DRVIO_EV_PRE_DISCONNECT);
+ }
+ /*notify all*/
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.notifyChain)
+ {
+ pNotify = list_entry(_entry, T_zDrvIO_GNotify, node);
+ if (pNotify->notifyFn)
+ pNotify->notifyFn(pIOEntry->name, DRVIO_EV_PRE_DISCONNECT);
+ }
+
+ _IO_GetDev(pIOEntry);
+ if (pIOEntry->devOpenState == DRVIO_DEVICE_OPENED && pIOEntry->ops->ctrl)
+ {
+ param = ZOSS_NO_WAIT;
+ pIOEntry->ops->ctrl(pIOEntry->devData, IOCTL_IODEV_SET_BLOCKTIME, (VOID*)¶m);
+ }
+ _IO_PutDev(pIOEntry);
+
+ /*notify current device user*/
+ if (pIOEntry->notify.notify_fn)
+ {
+ pIOEntry->notify.notify_fn(pIOEntry->notify.privData, DRVIO_EV_DISCONNECT);
+ }
+
+ /*notify all*/
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.notifyChain)
+ {
+ pNotify = list_entry(_entry, T_zDrvIO_GNotify, node);
+ if (pNotify->notifyFn)
+ pNotify->notifyFn(pIOEntry->name, DRVIO_EV_DISCONNECT);
+ }
+
+ while (pIOEntry->readDepth || pIOEntry->writeDepth || pIOEntry->ctrlDepth || pIOEntry->disallowDisconnect)
+ {
+ zDrvDebug_Printf("DRVIO(%d): disconnect %s, wait finish...", zOss_GetTickCount(), pIOEntry->name);
+ zDrvDebug_Printf("readDepth=%d, writeDepth=%d, ctrlDepth=%d, disallowDisconnect=%d", pIOEntry->readDepth, pIOEntry->writeDepth, pIOEntry->ctrlDepth, pIOEntry->disallowDisconnect);
+ zOss_GetSemaphore(pIOEntry->waitDisconnectSem, ZOSS_WAIT_FOREVER);
+ }
+
+
+ _IO_GetDev(pIOEntry);
+ if (pIOEntry->devOpenState == DRVIO_DEVICE_OPENED)
+ {
+ if (pIOEntry->ops && pIOEntry->ops->close)
+ {
+ pIOEntry->ops->close(pIOEntry->devData);
+ }
+ pIOEntry->devOpenState = DRVIO_DEVICE_CLOSED;
+ }
+ pIOEntry->devConnectState = DRVIO_DEVICE_DISCONNECT;
+ pIOEntry->devData = NULL;
+ pIOEntry->ops = NULL;
+ _IO_PutDev(pIOEntry);
+
+ _IO_DelDev(pIOEntry);
+ return ;
+}
+
+/*******************************************************************************
+ * Function: printBuffer
+ * Description:.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID printBuffer(UINT8 *pBuf, UINT32 len)
+{
+ UINT32 printPos = 0;
+ UINT8 tmpCh = 0;
+
+ while(printPos < len)
+ {
+ tmpCh = pBuf[printPos+96];
+ pBuf[printPos+96] = '\0';
+ zDrvDebug_Printf("%s", &pBuf[printPos]);
+ pBuf[printPos+96] = tmpCh;
+ printPos += 96;
+ }
+
+}
+
+/*******************************************************************************
+ * Function: printDevList
+ * Description:show the device debug information.
+ * Input:
+ * Output:None
+ *
+ * Returns:None
+ * Others:
+ ********************************************************************************/
+static VOID printDevList(VOID)
+{
+ struct list_head *_entry, *_next_entry;
+ T_ZDrvIODev_Entry *pIOEntry = NULL;
+
+ zDrvDebug_Printf("----------DRVIO DEVICE LIST----------");
+
+ DEVICE_LIST_LOCK();
+
+ zDrvDebug_Printf("Device List Count: %d", g_drvIOTable.devListCount);
+
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.devList)
+ {
+ pIOEntry = list_entry(_entry, T_ZDrvIODev_Entry, node);
+
+ zDrvDebug_Printf("[%s]", pIOEntry->name);
+ }
+
+ DEVICE_LIST_UNLOCK();
+
+ return ;
+}
+
+/*******************************************************************************
+ * Function: printDevDebugInfo
+ * Description:show the device debug information.
+ * Input:
+ * Output:None
+ *
+ * Returns:None
+ * Others:
+ ********************************************************************************/
+static VOID printDevDebugInfo(VOID)
+{
+ struct list_head *_entry, *_next_entry;
+ T_ZDrvIODev_Entry *pIOEntry = NULL;
+
+ zDrvDebug_Printf("----------DRVIO DEBUG INFO----------");
+
+ DEVICE_LIST_LOCK();
+
+ zDrvDebug_Printf("Device List Count: %d", g_drvIOTable.devListCount);
+
+ list_for_each_safe(_entry, _next_entry, &g_drvIOTable.devList)
+ {
+ pIOEntry = list_entry(_entry, T_ZDrvIODev_Entry, node);
+
+ zDrvDebug_Printf("[%s] INFO:", pIOEntry->name);
+
+ if (pIOEntry->devConnectState == DRVIO_DEVICE_CONNECT)
+ {
+ zDrvDebug_Printf("Device is connect");
+ }
+ else
+ {
+ zDrvDebug_Printf("Device is disconnect");
+ }
+
+ if (pIOEntry->userOpenState > DRVIO_DEVICE_CLOSED)
+ {
+ zDrvDebug_Printf("Device is user opend");
+ }
+ else
+ {
+ zDrvDebug_Printf("Device is user closed");
+ }
+
+ if (pIOEntry->devOpenState > DRVIO_DEVICE_CLOSED)
+ {
+ zDrvDebug_Printf("Device is dev opend");
+ }
+ else
+ {
+ zDrvDebug_Printf("Device is dev closed");
+ }
+
+ zDrvDebug_Printf("Device Refer Count: %d", pIOEntry->refCount);
+ zDrvDebug_Printf("Device Read Depth: %d", pIOEntry->readDepth);
+ zDrvDebug_Printf("Device Write Depth: %d", pIOEntry->writeDepth);
+ zDrvDebug_Printf("Device Control Depth: %d", pIOEntry->ctrlDepth);
+ zDrvDebug_Printf("Device Disallow Disconnect: %d", pIOEntry->disallowDisconnect);
+ zDrvDebug_Printf("\n");
+ }
+
+ DEVICE_LIST_UNLOCK();
+
+ return ;
+}
+
+/*******************************************************************************
+ * Function: lsDevCmdEntry
+ * Description:add DRV IO debug cmd.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID lsDevCmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ UINT32 i = 0;
+
+ if (CmdMsg->paraCount == 0)
+ {
+ zDrvDebug_Printf("lsdev support arg:");
+ zDrvDebug_Printf(" -l: show the io devices list");
+ zDrvDebug_Printf(" -d: show the io devices debug info");
+ printDevList();
+ return;
+ }
+
+ for (i=0; i<CmdMsg->paraCount; i++)
+ {
+ if (strcmp((const char*)CmdMsg->para[i], "-l") == 0)
+ {
+ printDevList();
+ }
+ else if (strcmp((const char*)CmdMsg->para[i], "-d") == 0)
+ {
+ printDevDebugInfo();
+ }
+ else
+ {
+ zDrvDebug_Printf("Unknown para!!!");
+ }
+ }
+ return ;
+}
+/*******************************************************************************
+ * Function: catCDevCmdEntry
+ * Description:add DRV IO debug cmd.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+
+static VOID catCDevCmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ T_ZDrvIO_Handle pIOHnd = NULL;
+ T_ZDRVIO_FLAGS flags = {0};
+ UINT32 i = 0;
+ UINT8 *pBuf = NULL;
+ UINT8 *pChBuf = NULL;
+ SINT32 ret = DRV_SUCCESS;
+ SINT32 readLen = 0;
+ UINT32 cnt = 0;
+ UINT32 chPos = 0;
+
+ if (CmdMsg->paraCount == 0)
+ {
+ zDrvDebug_Printf("example: catdev uart/0 200");
+ return;
+ }
+
+ if (CmdMsg->paraCount != 2)
+ {
+ zDrvDebug_Printf("catdev invalid param !!!");
+ return ;
+ }
+
+ pBuf = (UINT8*)zOss_Malloc(2048);
+ pChBuf = (UINT8*)zOss_Malloc(4096);
+ if (!pBuf || !pChBuf)
+ {
+ if (pChBuf)
+ zOss_Free(pChBuf);
+ if (pBuf)
+ zOss_Free(pBuf);
+ zDrvDebug_Printf("malloc buffer fail !!!");
+ return ;
+ }
+
+ flags.READ = 1;
+ flags.WRITE = 1;
+
+ pIOHnd = zDrvIO_Open((const char*)CmdMsg->para[0], flags);
+ if (pIOHnd == NULL)
+ {
+ zDrvDebug_Printf("Open Device %s Error !!!", CmdMsg->para[0]);
+ zOss_Free(pChBuf);
+ zOss_Free(pBuf);
+ return ;
+ }
+
+ sscanf(CmdMsg->para[1], "%d", (int*)&readLen);
+ zDrvDebug_Printf("Start Read Device Length %d", readLen);
+
+ while(cnt<readLen)
+ {
+ ret = zDrvIO_Read(pIOHnd, pBuf, 2048);
+ if (ret <= 0)
+ {
+ zDrvDebug_Printf("Read Error Ret = %d !!!\n", ret);
+ goto exit;
+ }
+ zDrvDebug_Printf("\nRead Length %d", ret);
+
+ zDrvDebug_Printf("ASCII:");
+ pChBuf[ret]='\0';
+ for (i=0; i<ret; i++)
+ {
+ if (pBuf[i] >= 32 && pBuf[i] <= 126)
+ pChBuf[i] = pBuf[i];
+ else
+ pChBuf[i] = 32;
+ }
+ printBuffer(pChBuf, ret);
+
+ zDrvDebug_Printf("HEX:");
+ chPos = 0;
+ for (i=0; i<ret; i++)
+ {
+ sprintf((char*)&pChBuf[chPos],"%02x ", pBuf[i]);
+ chPos += 3;
+ }
+ printBuffer(pChBuf, chPos + 1);
+ cnt += ret;
+ }
+
+exit:
+ zOss_Free(pChBuf);
+ zOss_Free(pBuf);
+ zDrvIO_Close(pIOHnd);
+
+ return ;
+}
+/*******************************************************************************
+ * Function: catBDevCmdEntry
+ * Description:add DRV IO debug cmd.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID catBDevCmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ T_ZDrvIO_Handle pIOHnd = NULL;
+ T_ZDRVIO_FLAGS flags = {0};
+ UINT32 i = 0;
+ UINT8 *pBuf = NULL;
+ UINT8 *pChBuf = NULL;
+ SINT32 ret = DRV_SUCCESS;
+ SINT32 readCnt = 0;
+ SINT32 readBase = 0;
+ UINT32 cnt = 0;
+ T_BlkDev_Info blkDevInfo = {0};
+ UINT32 chPos = 0;
+
+ if (CmdMsg->paraCount == 0)
+ {
+ zDrvDebug_Printf("example: catbdev sd 200 1");
+ return;
+ }
+
+ if (CmdMsg->paraCount != 3)
+ {
+ zDrvDebug_Printf("catdev invalid param !!!");
+ return ;
+ }
+
+ pBuf = (UINT8*)zOss_Malloc(2048);
+ pChBuf = (UINT8*)zOss_Malloc(6144);
+ if (!pBuf || !pChBuf)
+ {
+ if (pChBuf)
+ zOss_Free(pChBuf);
+ if (pBuf)
+ zOss_Free(pBuf);
+ zDrvDebug_Printf("malloc buffer fail !!!");
+ return ;
+ }
+
+ flags.READ = 1;
+ flags.WRITE = 1;
+
+ pIOHnd = zDrvIO_Open((const char*)CmdMsg->para[0], flags);
+ if (pIOHnd == NULL)
+ {
+ zDrvDebug_Printf("Open Device %s Error !!!", CmdMsg->para[0]);
+ zOss_Free(pChBuf);
+ zOss_Free(pBuf);
+ return ;
+ }
+
+ zDrvIO_Ctrl(pIOHnd,IOCTL_BLKDEV_GET_INFO,&blkDevInfo);
+ if (blkDevInfo.blkSize > 2048 || blkDevInfo.blkSize == 0)
+ {
+ zDrvDebug_Printf("Error Block Size %d !!!", blkDevInfo.blkSize);
+ goto exit;
+ }
+
+ sscanf(CmdMsg->para[1], "%d", (int*)&readBase);
+ sscanf(CmdMsg->para[2], "%d", (int*)&readCnt);
+
+ zDrvDebug_Printf("Start Read Device Block Cnt %d, Base %d", readCnt, readBase);
+
+ while(cnt < readCnt)
+ {
+ ret = zDrvIO_BRead(pIOHnd, pBuf, 1, readBase + cnt);
+ if (ret <= 0)
+ {
+ zDrvDebug_Printf("Read Error Ret = %d !!!\n", ret);
+ goto exit;
+ }
+ zDrvDebug_Printf("\nRead Block Cnt 1, Length %d", blkDevInfo.blkSize);
+
+ zDrvDebug_Printf("ASCII:");
+ for (i=0; i<blkDevInfo.blkSize; i++)
+ {
+ if (pBuf[i] >= 32 && pBuf[i] <= 126)
+ pChBuf[i] = pBuf[i];
+ else
+ pChBuf[i] = 32;
+ }
+ printBuffer(pChBuf, blkDevInfo.blkSize);
+
+ zDrvDebug_Printf("HEX:");
+ chPos = 0;
+ for (i=0; i<blkDevInfo.blkSize; i++)
+ {
+ sprintf((char*)&pChBuf[chPos],"%02x ", pBuf[i]);
+ chPos += 3;
+ }
+ printBuffer(pChBuf, chPos + 1);
+ cnt++;
+ }
+
+exit:
+ zOss_Free(pChBuf);
+ zOss_Free(pBuf);
+ zDrvIO_Close(pIOHnd);
+
+ return ;
+}
+
+/*******************************************************************************
+ * Function: echoCDevCmdEntry
+ * Description:add DRV IO debug cmd.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID echoCDevCmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ T_ZDrvIO_Handle pIOHnd = NULL;
+ T_ZDRVIO_FLAGS flags = {0};
+ SINT32 ret = DRV_SUCCESS;
+ SINT32 writeLen = 0;
+ UINT32 len = 0;
+ UINT8 *pBuf = NULL;
+
+ if (CmdMsg->paraCount == 0)
+ {
+ zDrvDebug_Printf("example: echodev uart/0 test ");
+ return;
+ }
+
+ if (CmdMsg->paraCount != 2)
+ {
+ zDrvDebug_Printf("echodev invalid param !!!");
+ return ;
+ }
+
+ flags.READ = 1;
+ flags.WRITE = 1;
+
+ pIOHnd = zDrvIO_Open((const char*)CmdMsg->para[0], flags);
+ if (pIOHnd == NULL)
+ {
+ zDrvDebug_Printf("Open Device %s Error !!!", CmdMsg->para[0]);
+ return ;
+ }
+
+ writeLen = strlen(CmdMsg->para[1]);
+ pBuf = (UINT8*)CmdMsg->para[1];
+
+ while(len < writeLen)
+ {
+ ret = zDrvIO_Write(pIOHnd, &pBuf[len], writeLen);
+ if (ret <= 0)
+ {
+ zDrvDebug_Printf("Write Error Ret = %d !!!\n", ret);
+ goto exit;
+ }
+ zDrvDebug_Printf("Write Length %d", ret);
+ len += ret;
+ }
+
+exit:
+ zDrvIO_Close(pIOHnd);
+
+ return ;
+}
+/*******************************************************************************
+ * Function: echoBDevCmdEntry
+ * Description:add DRV IO debug cmd.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID echoBDevCmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ T_ZDrvIO_Handle pIOHnd = NULL;
+ T_ZDRVIO_FLAGS flags = {0};
+ SINT32 ret = DRV_SUCCESS;
+ SINT32 writeLen = 0;
+ UINT32 cnt = 0;
+ UINT32 writeBase = 0;
+ UINT8 *pBuf = NULL;
+ UINT8 *pWBuf = NULL;
+ T_BlkDev_Info blkDevInfo = {0};
+ UINT32 blockCnt = 0;
+
+ if (CmdMsg->paraCount == 0)
+ {
+ zDrvDebug_Printf("example: echobdev sd 200 Teststring ");
+ return;
+ }
+
+ if (CmdMsg->paraCount != 3)
+ {
+ zDrvDebug_Printf("echodev invalid param !!!");
+ return ;
+ }
+ pWBuf = (UINT8*)zOss_Malloc(2048);
+ if (pWBuf == NULL)
+ {
+ zDrvDebug_Printf("malloc buffer fail !!!");
+ return ;
+ }
+ zOss_Memset(pWBuf, 0x0, 2048);
+
+ flags.READ = 1;
+ flags.WRITE = 1;
+
+ pIOHnd = zDrvIO_Open((const char*)CmdMsg->para[0], flags);
+ if (pIOHnd == NULL)
+ {
+ zOss_Free(pWBuf);
+ zDrvDebug_Printf("Open Device %s Error !!!", CmdMsg->para[0]);
+ return ;
+ }
+
+ sscanf(CmdMsg->para[1], "%d", (int*)&writeBase);
+
+ writeLen = strlen(CmdMsg->para[2]);
+ pBuf = (UINT8*)CmdMsg->para[2];
+ zOss_Memcpy(pWBuf, pBuf, writeLen);
+
+ zDrvIO_Ctrl(pIOHnd,IOCTL_BLKDEV_GET_INFO,&blkDevInfo);
+ if (blkDevInfo.blkSize > 2048 || blkDevInfo.blkSize == 0)
+ {
+ zDrvDebug_Printf("Error Block Size %d !!!", blkDevInfo.blkSize);
+ goto exit;
+ }
+ blockCnt = writeLen/blkDevInfo.blkSize;
+ blockCnt += writeLen % blkDevInfo.blkSize ? 1: 0;
+
+ while(cnt < blockCnt)
+ {
+ ret = zDrvIO_BWrite(pIOHnd, &pWBuf[cnt*blkDevInfo.blkSize], 1, writeBase + cnt);
+ if (ret <= 0)
+ {
+ zDrvDebug_Printf("Write Error Ret = %d !!!\n", ret);
+ goto exit;
+ }
+ zDrvDebug_Printf("Write Length %d", ret);
+ cnt++;
+ }
+
+exit:
+ zDrvIO_Close(pIOHnd);
+
+ //if (pWBuf != NULL)
+ {
+ zOss_Free(pWBuf);
+ }
+
+ return ;
+}
+
+/*******************************************************************************
+ * Function: notifier
+ * Description:.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+
+ * Others:
+ ********************************************************************************/
+static VOID notifier(const char* devName, T_DRVIO_EVENT event)
+{
+ if (event == DRVIO_EV_CONNECT)
+ {
+ zDrvDebug_Printf("DRVIO(%d): Device [%s] connect", zOss_GetTickCount(), devName);
+ }
+ else if (event == DRVIO_EV_PRE_DISCONNECT)
+ {
+ zDrvDebug_Printf("DRVIO(%d): Device [%s] pre disconnect", zOss_GetTickCount(), devName);
+ }
+ else if (event == DRVIO_EV_DISCONNECT)
+ {
+ zDrvDebug_Printf("DRVIO(%d): Device [%s] disconnect", zOss_GetTickCount(), devName);
+ }
+ else
+ {
+ zDrvDebug_Printf("DRVIO(%d): Device [%s] unknown event", zOss_GetTickCount(), devName);
+ }
+
+}
+
+/*******************************************************************************
+ * Function: zDrvIODev_Initiate
+ * Description:initialize the io base structure.
+ * Input:
+ * Output:None
+ *
+ * Returns:
+ DRV_SUCCESS: success.
+ DRV_ERROR: error.
+ * Others:
+ ********************************************************************************/
+SINT32 zDrvIODev_Initiate(VOID)
+{
+ if (g_drvIOTable.opMutex)
+ {
+ return DRV_SUCCESS;
+ }
+
+ g_drvIOTable.opMutex = zOss_CreateMutex("IO table mutex", ZOSS_INHERIT);
+ g_drvIOTable.devListCount = 0;
+ INIT_LIST_HEAD(&g_drvIOTable.devList);
+ g_drvIOTable.notifyCount= 0;
+ INIT_LIST_HEAD(&g_drvIOTable.notifyChain);
+
+ zOss_AddShellCmd("lsdev", lsDevCmdEntry, "²é¿´IOÉ豸Áбí");
+ zOss_AddShellCmd("catcdev", catCDevCmdEntry, "¶Á×Ö·ûÉ豸");
+ zOss_AddShellCmd("catbdev", catBDevCmdEntry, "¶Á¿éÉ豸");
+ zOss_AddShellCmd("echocdev", echoCDevCmdEntry, "д×Ö·ûÉ豸");
+ zOss_AddShellCmd("echobdev", echoBDevCmdEntry, "д¿éÉ豸");
+
+ zDrvIO_RegisterGlobalNotify(notifier);
+
+ return DRV_SUCCESS;
+}
+
+
diff --git a/cp/ps/driver/src/public/src/iodev/makefile b/cp/ps/driver/src/public/src/iodev/makefile
new file mode 100644
index 0000000..f1bb717
--- /dev/null
+++ b/cp/ps/driver/src/public/src/iodev/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = iodev
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/qalloc/makefile b/cp/ps/driver/src/public/src/qalloc/makefile
new file mode 100644
index 0000000..a7eb04e
--- /dev/null
+++ b/cp/ps/driver/src/public/src/qalloc/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = qalloc
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/qalloc/qalloc.c b/cp/ps/driver/src/public/src/qalloc/qalloc.c
new file mode 100644
index 0000000..cba9609
--- /dev/null
+++ b/cp/ps/driver/src/public/src/qalloc/qalloc.c
@@ -0,0 +1,869 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: qalloc.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-09-24
+********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "qalloc.h"
+#include "drvs_general.h"
+#include "drvs_assert.h"
+#include "drvs_debug.h"
+
+
+#define CPU_CACHE_LINE_SIZE 32
+
+#define QALLOC_LOCK ZOSS_DISABLE_IRQ_FAST
+#define QALLOC_UNLOCK ZOSS_ENABLE_IRQ_FAST
+
+#define QALLOC_BLOCK_FLAG (0x0FFF0000)
+
+#define QALLOC_INIT_BLOCK(block_ptr, block_order, block_status) { block_ptr->order = block_order; block_ptr->status = block_status;}
+
+#define DEBUG_STATISTIC_COUNT 100
+
+typedef enum _T_QALLOC_BLOCK_STATUS {
+ QALLOC_BLOCK_FREE = QALLOC_BLOCK_FLAG,
+ QALLOC_BLOCK_ALLOC,
+ QALLOC_BLOCK_IN_MERGE,
+} T_QALLOC_BLOCK_STATUS;
+
+
+/*
+* General purpose special memory block descriptor.
+*/
+typedef struct _T_Quick_Block
+{
+ struct list_head node; /* free block chain*/
+ UINT32 num;
+ UINT32 order;
+ VOID *debug_info;
+ T_QALLOC_BLOCK_STATUS status;
+}
+T_Quick_Block;
+
+/*
+* General purpose free block list descriptor.
+*/
+typedef struct _T_Free_Block_List
+{
+ struct list_head head; /* free block chain*/
+ UINT32 block_cnt;
+}
+T_Free_Block_List;
+
+/*
+ * General purpose special memory pool chunk descriptor.
+ */
+typedef struct _T_Quick_Pool_Chunk
+{
+ struct list_head next_chunk; /* next chunk in pool */
+ T_Quick_Pool *top_pool;
+ UINT32 start_addr; /* starting address of memory chunk */
+ UINT32 end_addr; /* ending address of memory chunk */
+ T_Quick_Block *block_map; /*the block map of chunk*/
+ T_Free_Block_List *block_free; /*the block free list of chunk in order*/
+ UINT32 page_size; /*define the page size. the min alloc size is one page.*/
+ UINT32 max_alloc_order; /*the max alloc page order*/
+ UINT32 page_count;
+ UINT32 avail_page_count;
+}
+T_Quick_Pool_Chunk;
+
+typedef struct _T_Quick_Pool_Alloc_Debug
+{
+ VOID *alloc_owner_info;
+ UINT32 alloc_count;
+}
+T_Quick_Pool_Alloc_Debug;
+
+VOID QPool_PrintAll(VOID);
+
+volatile T_Quick_Pool_Chunk *g_assert_chunk = NULL;
+volatile T_Quick_Block *g_assert_block = NULL;
+UINT32 g_QPool_Cmd_Init = 0;
+
+LIST_HEAD(g_QPool);
+
+/**
+ * fls - find last (most-significant) bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
+ */
+
+static inline SINT32 fls(SINT32 x)
+{
+ SINT32 r = 32;
+
+ if (!x)
+ return 0;
+ if (!(x & 0xffff0000u))
+ {
+ x <<= 16;
+ r -= 16;
+ }
+ if (!(x & 0xff000000u))
+ {
+ x <<= 8;
+ r -= 8;
+ }
+ if (!(x & 0xf0000000u))
+ {
+ x <<= 4;
+ r -= 4;
+ }
+ if (!(x & 0xc0000000u))
+ {
+ x <<= 2;
+ r -= 2;
+ }
+ if (!(x & 0x80000000u))
+ {
+ x <<= 1;
+ r -= 1;
+ }
+ return r;
+}
+/**
+ * cal_order - calculate the order value
+ * @count: the count to calculate
+ */
+static inline UINT32 cal_order(UINT32 count)
+{
+ UINT32 order = 0;
+
+ order = fls(count) - 1;
+ return order;
+}
+
+
+/**
+ * chunk_AddBlk - add one block to free list
+ * @chunk: the chunk of this function operated in.
+ * @block: the block to added
+*/
+static inline VOID chunk_AddBlk(T_Quick_Pool_Chunk *chunk, T_Quick_Block *block)
+{
+ UINT32 order =block->order;
+
+ zDrv_ASSERT(block->status == QALLOC_BLOCK_FREE);
+ zDrv_ASSERT(!(block->num & ((1 << order) -1)));
+
+ list_add(&block->node, &(chunk->block_free[order].head));
+ chunk->block_free[order].block_cnt++;
+ chunk->avail_page_count += 1 << block->order;
+}
+
+/**
+ * chunk_DeleteBlk - delete one block from the order free list
+ * @chunk: the chunk of this function operated in.
+ * @block: the block to added
+*/
+static inline T_Quick_Block * chunk_DeleteBlk(T_Quick_Pool_Chunk *chunk, UINT32 order)
+{
+ T_Quick_Block *order_block = NULL;
+ struct list_head *order_block_head = NULL;
+
+ order_block_head = &chunk->block_free[order].head;
+
+ if (list_empty(order_block_head))
+ return NULL; /*is empty*/
+
+ order_block = list_first_entry(order_block_head, T_Quick_Block, node);
+ list_del(&order_block->node);
+
+ chunk->block_free[order].block_cnt--;
+ chunk->avail_page_count -= 1 << order_block->order;
+ zDrv_ASSERT(order_block->status == QALLOC_BLOCK_FREE);
+ zDrv_ASSERT(!(order_block->num & ((1 << order) -1)));
+
+ return order_block;
+}
+
+/**
+ * chunk_InitBlk - recursive initialize the block.
+ * @chunk: the chunk of this function operated in.
+ * @block_pos: the current position in process.
+ * @order: the initialize order of chunk.
+*/
+static UINT32 chunk_InitBlk (T_Quick_Pool_Chunk *chunk, UINT32 block_pos, UINT32 order)
+{
+ UINT32 block_size = 0;
+ T_Quick_Block *block = NULL;
+
+ zDrv_ASSERT(chunk != NULL);
+
+ block_size = 1 << order;
+ while ((block_pos < chunk->page_count) && (chunk->page_count - block_pos) >= (block_size))
+ {
+ block = &chunk->block_map[block_pos];
+ QALLOC_INIT_BLOCK(block, order, QALLOC_BLOCK_FREE);
+ chunk_AddBlk(chunk, &(chunk->block_map[block_pos]));
+ block_pos += block_size;
+ }
+
+ if (chunk->page_count == block_pos)
+ return 0;
+
+ if (block_pos > chunk->page_count)
+ block_pos -= block_size;
+
+ return block_pos;
+}
+
+/**
+ * chunk_SplitBlk - split the block and insert to the free list.
+ * @chunk: the chunk of this function operated in.
+ * @block: the block to need split.
+*/
+static VOID chunk_SplitBlk(T_Quick_Pool_Chunk *chunk, T_Quick_Block * block)
+{
+ UINT32 right_order = 0;
+ T_Quick_Block *new_block = NULL;
+
+ right_order = block->order -1;
+
+ new_block = block + (0x1 << right_order);
+ QALLOC_INIT_BLOCK(new_block, right_order, QALLOC_BLOCK_FREE);
+ chunk_AddBlk(chunk, new_block);
+
+ block->order--;
+ return;
+}
+
+/**
+ * chunk_MergeBlk - merge some block to one block.
+ * @chunk: the chunk of this function operated in.
+ * @block: the free block.
+*/
+static T_Quick_Block * chunk_MergeBlk(T_Quick_Pool_Chunk *chunk, T_Quick_Block * block)
+{
+ UINT32 order = 0;
+ UINT32 block_num = 0;
+ UINT32 max_order = chunk->max_alloc_order;
+ UINT32 left_block_num = 0;
+ UINT32 right_block_num = 0;
+ UINT32 merge_block_num = 0;
+ T_Quick_Block *left_block = NULL;
+ T_Quick_Block *right_block = NULL;
+ T_Quick_Block *merge_block = NULL;
+
+ order = block->order;
+ if (order == max_order)
+ goto add;
+
+ block_num = block->num;
+ left_block_num = (block_num >> (order + 1)) << (order + 1);
+ right_block_num = left_block_num + (1 << order);
+
+ if (block_num == left_block_num)
+ {
+ merge_block_num = right_block_num;
+ }
+ else
+ {
+ merge_block_num = left_block_num;
+ }
+
+ merge_block = chunk->block_map + merge_block_num;
+
+ if ( (merge_block->status == QALLOC_BLOCK_FREE) && (merge_block->order == order) )
+ {
+
+ list_del(&merge_block->node);
+ chunk->avail_page_count -= 1 << merge_block->order;
+
+ right_block = chunk->block_map + right_block_num;
+ QALLOC_INIT_BLOCK(right_block, 0x0, 0x0);
+ left_block = chunk->block_map + left_block_num;
+ QALLOC_INIT_BLOCK(left_block, (order + 1), QALLOC_BLOCK_IN_MERGE);
+ return left_block;
+ }
+
+add:
+ /*cant merge, add this block to free list*/
+ QALLOC_INIT_BLOCK(block, order, QALLOC_BLOCK_FREE);
+ chunk_AddBlk(chunk, block);
+
+ return NULL;
+}
+
+
+/**
+ * chunk_AllocBlk - allocate one block.
+ * @chunk: the chunk of this function operated in.
+ * @size: the allocate size.
+*/
+static UINT32 chunk_AllocBlk(T_Quick_Pool_Chunk *chunk, UINT32 size, VOID *debug_info)
+{
+ UINT32 alloc_order = 0;
+ UINT32 tmp_order = 0;
+ UINT32 max_order = 0;
+ T_Quick_Block * alloc_block = NULL;
+ UINT32 addr = 0;
+ UINT32 page_alloc_count = 0;
+
+ if (chunk->max_alloc_order == 0)
+ {
+ /*order == 0*/
+ if (size > chunk->page_size)
+ return 0x0;
+
+ alloc_block = chunk_DeleteBlk(chunk, 0);
+ if (alloc_block == NULL)
+ return 0;
+ alloc_order = 0;
+ }
+ else
+ {
+ /*order > 0*/
+ page_alloc_count = (size /chunk->page_size);
+ if ((page_alloc_count * chunk->page_size) < size)
+ page_alloc_count++;
+ if (size == 0 || page_alloc_count > (0x1 << chunk->max_alloc_order))
+ return 0x0;
+
+ alloc_order = cal_order(page_alloc_count);
+ if (page_alloc_count > (0x1 << (alloc_order)))
+ alloc_order++;
+
+ /*get the free block*/
+ max_order = chunk->max_alloc_order;
+ tmp_order = alloc_order;
+ while (tmp_order <= max_order)
+ {
+ alloc_block = chunk_DeleteBlk(chunk, tmp_order);
+ if (alloc_block)
+ break;
+ else
+ tmp_order++;
+ }
+
+ if (alloc_block == NULL)
+ return 0x0;
+
+ /*split the block*/
+ while (alloc_order != alloc_block->order)
+ {
+ chunk_SplitBlk(chunk, alloc_block);
+ }
+ }
+
+ QALLOC_INIT_BLOCK(alloc_block, alloc_order, QALLOC_BLOCK_ALLOC);
+ alloc_block->debug_info = debug_info;
+
+ /*calc the block address*/
+ addr = chunk->start_addr + (alloc_block->num * chunk->page_size); /*calc address*/
+
+ return addr;
+}
+
+
+/**
+ * chunk_FreeBlk - free the space to free list.
+ * @chunk: the chunk of this function operated in.
+ * @addr: the address to free.
+*/
+static VOID chunk_FreeBlk(T_Quick_Pool_Chunk *chunk, UINT32 addr, VOID *debug_info)
+{
+ T_Quick_Block * free_block = NULL;
+ UINT32 block_num = 0;
+ T_Quick_Block * new_free_block = NULL;
+
+ block_num = (addr - chunk->start_addr) / chunk->page_size;
+ free_block = chunk->block_map + block_num;
+
+ if (free_block->status != QALLOC_BLOCK_ALLOC)
+ {
+ g_assert_chunk = chunk;
+ g_assert_block= free_block;
+ zDrv_ASSERT(0);
+ return ;
+ }
+
+ free_block->debug_info = debug_info;
+ if (chunk->max_alloc_order == 0)
+ {
+ /*no need merge, add this block to free list*/
+ QALLOC_INIT_BLOCK(free_block, 0x0, QALLOC_BLOCK_FREE);
+ chunk_AddBlk(chunk, free_block);
+ }
+ else
+ {
+ new_free_block = chunk_MergeBlk(chunk, free_block);
+ while (new_free_block)
+ {
+ new_free_block = chunk_MergeBlk(chunk, new_free_block);
+ }
+ }
+ return ;
+}
+
+/**
+ * chunk_PrintInfo.
+ * @:
+*/
+static VOID chunk_PrintInfo(T_Quick_Pool_Chunk *chunk, T_Quick_Pool_Alloc_Debug * debug_info)
+{
+ UINT32 i = 0;
+ UINT32 j = 0;
+ UINT32 page_count = 0;
+ UINT32 page_sum = 0;
+ UINT32 block_owner = 0;
+
+ zDrv_ASSERT(chunk != NULL && debug_info != NULL);
+
+ zOss_Memset(debug_info, 0x0, sizeof(T_Quick_Pool_Alloc_Debug) * DEBUG_STATISTIC_COUNT);
+
+ for (i = 0; i < chunk->page_count; i++)
+ {
+
+ if (chunk->block_map[i].status == QALLOC_BLOCK_ALLOC)
+ {
+ /*¶ÔÒÑ·ÖÅä¿é´óС½øÐÐͳ¼Æ*/
+ if (page_count != page_sum)
+ {
+ zDrvDebug_Printf( "Error: alloc block %d, record=%d actual=%d!!!", block_owner, 1<< chunk->block_map[block_owner].order, page_sum);
+ }
+ block_owner = i;
+ page_count = 1<< chunk->block_map[block_owner].order;
+ page_sum = 1;
+
+ /*¶ÔÕ¼ÓÐÕß½øÐÐͳ¼Æ*/
+ for (j = 0; j < DEBUG_STATISTIC_COUNT; j++)
+ {
+ if (debug_info[j].alloc_owner_info == chunk->block_map[i].debug_info)
+ {
+ debug_info[j].alloc_count += page_count;
+ break;
+ }
+ else if (debug_info[j].alloc_count == 0x0)
+ {
+ debug_info[j].alloc_owner_info = chunk->block_map[i].debug_info;
+ debug_info[j].alloc_count += page_count;
+ break;
+ }
+ }
+
+ }
+ else if (chunk->block_map[i].status == QALLOC_BLOCK_FREE)
+ {
+ /*¶Ô¿ÕÏпé´óС½øÐÐͳ¼Æ*/
+ if (page_count != page_sum)
+ {
+ zDrvDebug_Printf( "Error: free block %d, record=%d actual=%d!!!", block_owner, 1<< chunk->block_map[block_owner].order, page_sum);
+ }
+ block_owner = i;
+ page_count = 1<< chunk->block_map[block_owner].order;
+ page_sum = 1;
+
+ }
+ else if (chunk->block_map[i].status == QALLOC_BLOCK_IN_MERGE)
+ {
+ zDrvDebug_Printf( "Error: In Merge block %d!!!", i);
+ }
+ else
+ {
+ page_sum++;
+ }
+ }
+
+ /*print debug info*/
+ for (j = 0; j < DEBUG_STATISTIC_COUNT; j++)
+ {
+ if (debug_info[j].alloc_count)
+ {
+ zDrvDebug_Printf( "(FUN) %s alloc count = %d", debug_info[j].alloc_owner_info, debug_info[j].alloc_count);
+ }
+ else
+ {
+ break ;
+ }
+ }
+
+ if (i == DEBUG_STATISTIC_COUNT)
+ {
+ zDrvDebug_Printf( "statistic to max count !!!");
+ }
+
+ return ;
+}
+
+/**
+ * drvPool_CmdEntry.
+ * @:
+*/
+static VOID drvPool_CmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ QPool_PrintAll();
+ return ;
+}
+
+
+/**
+ * QPool_Create - create a new special memory pool
+*
+ * Create a new special memory pool that can be used to manage special purpose
+ * memory not managed by the regular kmalloc/kfree interface.
+ */
+T_Quick_Pool *QPool_Create(UINT8* name)
+{
+ T_Quick_Pool *pool = NULL;
+
+ pool = (T_Quick_Pool *)zOss_Malloc(sizeof(T_Quick_Pool));
+ if (pool == NULL)
+ {
+ zDrv_ASSERT(0);
+ return NULL;
+ }
+ INIT_LIST_HEAD(&pool->chunks);
+ pool->count = 0;
+ pool->name = name;
+
+ list_add(&pool->node, &g_QPool);
+
+ if (!g_QPool_Cmd_Init)
+ {
+ zOss_AddShellCmd("drvpool", drvPool_CmdEntry, "DRV Pool Debug Info");
+ g_QPool_Cmd_Init = 1;
+ }
+
+ return pool;
+}
+
+
+/**
+ * QPool_AddVirt - add a new chunk of special memory to the pool
+ * @pool: pool to add new memory chunk to
+ * @virt: virtual starting address of memory chunk to add to pool
+ * @size: size in bytes of the memory chunk to add to pool
+ * @page_size: the page size of
+ * @size: size in bytes of the memory chunk to add to pool
+ * Add a new chunk of special memory to the specified pool.
+ *
+ * Returns 0 on success or a -ve errno on failure.
+ */
+SINT32 QPool_AddVirt(T_Quick_Pool *pool, UINT32 virt, UINT32 size,
+ UINT32 page_size, UINT32 max_alloc_order)
+{
+ T_Quick_Pool_Chunk *chunk = NULL;
+ SINT32 i = 0;
+ UINT32 block_pos = 0;
+ UINT32 order = 0;
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *iter_chunk;
+
+ zDrv_ASSERT((virt % CPU_CACHE_LINE_SIZE) == 0);
+ zDrv_ASSERT((size % CPU_CACHE_LINE_SIZE) == 0);
+ zDrv_ASSERT(pool != NULL && pool->chunks.next != NULL);
+
+ chunk = (T_Quick_Pool_Chunk *)zOss_Malloc(sizeof(T_Quick_Pool_Chunk));
+ if (chunk == NULL)
+ goto error;
+
+ zOss_Memset(chunk, 0x0, sizeof(T_Quick_Pool_Chunk));
+
+ chunk->start_addr = virt;
+ chunk->page_size = page_size;
+ chunk->max_alloc_order = max_alloc_order;
+ chunk->block_free = (T_Free_Block_List *)zOss_Malloc((chunk->max_alloc_order + 1) * sizeof(T_Free_Block_List));
+ if (chunk->block_free == NULL)
+ goto error;
+
+ for (i = 0; i <= chunk->max_alloc_order; i++)
+ {
+ INIT_LIST_HEAD(&(chunk->block_free[i].head));
+ chunk->block_free[i].block_cnt = 0;
+ }
+
+ chunk->page_count = (size / ((1 << chunk->max_alloc_order) * chunk->page_size)) * (1 << chunk->max_alloc_order);
+ zDrv_ASSERT(chunk->page_count != 0);
+ if (chunk->page_count == 0)
+ goto error;
+
+ chunk->block_map = (T_Quick_Block *)zOss_Malloc(chunk->page_count * sizeof(T_Quick_Block));
+ if (chunk->block_map == NULL)
+ goto error;
+
+ zOss_Memset(chunk->block_map, 0x0, chunk->page_count * sizeof(T_Quick_Block));
+
+ /*initialize the block number*/
+ for (i = 0; i < chunk->page_count; i++)
+ {
+ chunk->block_map[i].num = i;
+ }
+
+ /*initialize the block free list*/
+ chunk->avail_page_count = 0x0;
+ order = chunk->max_alloc_order;
+ block_pos = 0;
+ do
+ {
+ block_pos = chunk_InitBlk(chunk, block_pos, order);
+ order--;
+ }
+ while (block_pos); /*when block_pos change to zero, init end*/
+
+ chunk->end_addr = virt + chunk->page_count * chunk->page_size;
+
+ /*sort the chunk by page size*/
+ if (list_empty(&pool->chunks))
+ {
+ list_add(&chunk->next_chunk, &pool->chunks);
+ }
+ else
+ {
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ iter_chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ if (iter_chunk->page_size < chunk->page_size)
+ {
+ list_add(&chunk->next_chunk, &iter_chunk->next_chunk);
+ }
+ }
+ }
+
+ pool->count++;
+ chunk->top_pool = pool;
+
+ return 0;
+error:
+ if (chunk->block_free)
+ zOss_Free(chunk->block_free);
+ if (chunk->block_map)
+ zOss_Free(chunk->block_map);
+ return -1;
+}
+
+
+/**
+ * QPool_Alloc - allocate special memory from the pool
+ * @pool: pool to allocate from
+ * @size: number of bytes to allocate from the pool
+ * @debug_info: some debug info
+ *
+ * Allocate the requested number of bytes from the specified pool.
+ * Uses a first-fit algorithm.
+ */
+UINT32 QPool_Alloc(T_Quick_Pool *pool, UINT32 size, VOID *debug_info)
+{
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *chunk;
+ UINT32 addr = 0;
+ ZOSS_INTR old_intr;
+
+ zDrv_ASSERT(pool->count != 0);
+
+ QALLOC_LOCK();
+
+ /*first search the best match page_size*/
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ if (size == chunk->page_size)
+ {
+ addr = chunk_AllocBlk(chunk, size, debug_info);
+ if (addr)
+ {
+ QALLOC_UNLOCK();
+ return addr;
+ }
+ }
+ }
+
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ if (size != chunk->page_size)
+ {
+ addr = chunk_AllocBlk(chunk, size, debug_info);
+ if (addr)
+ {
+ QALLOC_UNLOCK();
+ return addr;
+ }
+ }
+ }
+
+ QALLOC_UNLOCK();
+ return addr;
+}
+
+
+/**
+ * QPool_Free - free allocated special memory back to the pool
+ * @pool: pool to free to
+ * @addr: starting address of memory to free back to pool
+ * @size: size in bytes of memory to free
+ *
+ */
+VOID QPool_Free(T_Quick_Pool *pool, UINT32 addr, VOID *debug_info)
+{
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *chunk;
+ ZOSS_INTR old_intr;
+
+ QALLOC_LOCK();
+
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ if (addr >= chunk->start_addr && addr < chunk->end_addr)
+ {
+ chunk_FreeBlk(chunk, addr, debug_info);
+ QALLOC_UNLOCK();
+ return;
+ }
+ }
+
+ QALLOC_UNLOCK();
+}
+
+
+/**
+ * QPool_Destroy - destroy a special memory pool
+ *
+ * Destroy the specified special memory pool. Verifies that there are no
+ * outstanding allocations.
+ */
+VOID QPool_Destroy(T_Quick_Pool *pool)
+{
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *chunk;
+
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ list_del(&chunk->next_chunk);
+ zOss_Free(chunk->block_free);
+ zOss_Free(chunk->block_map);
+ zOss_Memset(chunk, 0x0, sizeof(T_Quick_Pool_Chunk));
+ zOss_Free(chunk);
+ }
+
+ list_del(&pool->node);
+ zOss_Memset(pool, 0x0, sizeof(T_Quick_Pool));
+ zOss_Free(pool);
+
+ return;
+}
+
+/**
+ * QPool_Avail - get available free space of the pool
+ * @pool: pool to get available free space
+ *
+ * Return available free space of the specified pool.
+ */
+UINT32 QPool_Avail(T_Quick_Pool *pool)
+{
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *chunk;
+ UINT32 avail = 0;
+ ZOSS_INTR old_intr;
+
+ QALLOC_LOCK();
+
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ avail += chunk->avail_page_count * chunk->page_size;
+ }
+
+ QALLOC_UNLOCK();
+ return avail;
+}
+
+/**
+ * QPool_Size - get size in bytes of memory managed by the pool
+ * @pool: pool to get size
+ *
+ * Return size in bytes of memory managed by the pool.
+ */
+UINT32 QPool_Size(T_Quick_Pool *pool)
+{
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *chunk;
+ UINT32 size = 0;
+ ZOSS_INTR old_intr;
+
+ QALLOC_LOCK();
+
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+ size += chunk->end_addr - chunk->start_addr;
+ }
+
+ QALLOC_UNLOCK();
+ return size;
+}
+
+/**
+ * QPool_Print - print the pool debug info.
+ * @pool: pool to print
+ *
+ */
+VOID QPool_Print(T_Quick_Pool *pool)
+{
+ struct list_head *_chunk, *_next_chunk;
+ T_Quick_Pool_Chunk *chunk;
+ T_Quick_Pool_Alloc_Debug *debug_info = NULL;
+ UINT32 i = 0;
+
+ zDrvDebug_Printf( "----------QUICK POOL DEBUG INFO (%s)----------", pool->name);
+
+ debug_info = (T_Quick_Pool_Alloc_Debug *)zOss_Malloc(sizeof(T_Quick_Pool_Alloc_Debug) * DEBUG_STATISTIC_COUNT);
+
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks)
+ {
+ chunk = list_entry(_chunk, T_Quick_Pool_Chunk, next_chunk);
+
+ zDrvDebug_Printf( "CHUNK %d INFO:", i++);
+ zDrvDebug_Printf( "start address = 0x%x", chunk->start_addr);
+ zDrvDebug_Printf( "end address = 0x%x", chunk->end_addr);
+ zDrvDebug_Printf( "page size = %d", chunk->page_size);
+ zDrvDebug_Printf( "page count = %d", chunk->page_count);
+ zDrvDebug_Printf( "page available = %d", chunk->avail_page_count);
+ zDrvDebug_Printf( "max allocate page count = %d", 0x1 << chunk->max_alloc_order);
+
+ if (debug_info)
+ {
+ chunk_PrintInfo(chunk, debug_info);
+ }
+ }
+
+ free(debug_info);
+}
+
+
+/**
+ * QPool_PrintAll - print the all pool debug info.
+ *
+ */
+VOID QPool_PrintAll(VOID)
+{
+ struct list_head *_pool, *_next_pool;
+ T_Quick_Pool *qPool;
+
+ if (list_empty(&g_QPool))
+ {
+ zDrvDebug_Printf( "Quick Pool: no memory pool to print !!!");
+ return ;
+ }
+
+ list_for_each_safe(_pool, _next_pool, &g_QPool)
+ {
+ qPool = list_entry(_pool, T_Quick_Pool, node);
+ QPool_Print(qPool);
+ }
+}
diff --git a/cp/ps/driver/src/public/src/queue/makefile b/cp/ps/driver/src/public/src/queue/makefile
new file mode 100644
index 0000000..042b14e
--- /dev/null
+++ b/cp/ps/driver/src/public/src/queue/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = queue
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/queue/ring_queue.c b/cp/ps/driver/src/public/src/queue/ring_queue.c
new file mode 100644
index 0000000..d1350ad
--- /dev/null
+++ b/cp/ps/driver/src/public/src/queue/ring_queue.c
@@ -0,0 +1,303 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: ring_queue.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-09-24
+********************************************************************************/
+
+#include "drvs_general.h"
+#include "drvs_assert.h"
+#include "ring_queue.h"
+
+UINT32 g_ringQueueMsr = 0;
+
+/**
+ * queue_lock
+ */
+static SINT32 queue_lock(T_Ring_Queue *queue)
+{
+ UINT32 old_intr;
+
+ if (queue->multi_user_protect == QUEUE_PROTECT_MUTEX)
+ {
+ zOss_GetSemaphore(queue->lock , ZOSS_WAIT_FOREVER);
+ }
+ else if (queue->multi_user_protect == QUEUE_PROTECT_IRQ)
+ {
+ LOCK_SAVE(old_intr);
+ g_ringQueueMsr = old_intr;
+ }
+
+ return 0;
+}
+
+/**
+ * queue_unlock
+ */
+static void queue_unlock(T_Ring_Queue *queue)
+{
+ UINT32 old_intr;
+
+ if (queue->multi_user_protect == QUEUE_PROTECT_MUTEX)
+ {
+ zOss_PutSemaphore(queue->lock );
+ }
+ else if (queue->multi_user_protect == QUEUE_PROTECT_IRQ)
+ {
+ old_intr = g_ringQueueMsr;
+ LOCK_RESTORE(old_intr);
+ }
+}
+
+
+/**
+ * ringQueue_Create - create a new ring queue.
+ *
+ * Create a new special ring queue.
+ */
+T_Ring_Queue *ringQueue_Create(UINT32 unit_count, UINT32 unit_size, T_USER_PROTECT_POLICY multi_user_protect)
+{
+ T_Ring_Queue *queue = NULL;
+ UINT8 *buffer = NULL;
+
+ queue = (T_Ring_Queue*)zOss_Malloc(sizeof(T_Ring_Queue));
+ if (!queue)
+ return NULL;
+
+ zOss_Memset(queue, 0x0, sizeof(T_Ring_Queue));
+
+ buffer = (UINT8 *)zOss_Malloc((unit_count + 1) * unit_size);
+ if (!buffer)
+ {
+ zOss_Free(queue);
+ return NULL;
+ }
+
+ queue->unit_buffer = buffer;
+ queue->unit_buffer_size = (unit_count +1) * unit_size;
+ queue->read_pos = 0;
+ queue->write_pos = 0;
+ queue->unit_size = unit_size;
+ queue->unit_count = unit_count + 1;
+ queue->multi_user_protect = multi_user_protect;
+
+ if (queue->multi_user_protect == QUEUE_PROTECT_MUTEX)
+ {
+ queue->lock = zOss_CreateSemaphore("ring queue lock", 1);
+ zDrv_ASSERT(queue->lock );
+ }
+
+ return queue;
+}
+
+/**
+ * ringQueue_Init - initialize a new ring queue.
+ *
+ *
+ */
+SINT32 ringQueue_Init(T_Ring_Queue *queue, UINT8 *unit_buffer,
+ UINT32 unit_count, UINT32 unit_size, T_USER_PROTECT_POLICY protect_policy)
+{
+
+ if (queue == NULL || unit_buffer == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ zOss_Memset(queue, 0x0, sizeof(T_Ring_Queue));
+
+ queue->unit_buffer = unit_buffer;
+ queue->unit_buffer_size = unit_count * unit_size;
+ queue->read_pos = 0;
+ queue->write_pos = 0;
+ queue->unit_size = unit_size;
+ queue->unit_count = unit_count;
+ queue->multi_user_protect = protect_policy;
+
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ {
+ queue->lock = zOss_CreateSemaphore("ring queue lock", 1);
+ zDrv_ASSERT(queue->lock );
+ }
+
+ return 0;
+}
+
+/**
+ * ringQueue_Enqueue
+ *
+ *
+ */
+SINT32 ringQueue_Enqueue(T_Ring_Queue *queue, void *unit)
+{
+ UINT32 pos;
+ SINT32 ret = 0;
+
+ if (queue == NULL || unit == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ queue_lock(queue);
+
+ pos = queue->write_pos + queue->unit_size;
+ if (pos >= queue->unit_buffer_size)
+ pos = 0;
+
+ if (pos == queue->read_pos)
+ {
+ ret = DRV_ERROR_FULL; /*full*/
+ goto quit;
+ }
+
+ zOss_Memcpy(&queue->unit_buffer[queue->write_pos], unit, queue->unit_size);
+
+ queue->write_pos = pos;
+
+ ret = DRV_SUCCESS;
+quit:
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ queue_unlock(queue);
+ return ret;
+}
+
+/**
+ * ringQueue_Dequeue
+ *
+ *
+ */
+SINT32 ringQueue_Dequeue(T_Ring_Queue *queue, void *unit)
+{
+ SINT32 ret = 0;
+
+ if (queue == NULL || unit == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ queue_lock(queue);
+
+ if (queue->read_pos == queue->write_pos)
+ {
+ ret = DRV_ERROR_EMPTY; /*empty*/
+ goto quit;
+ }
+
+ zOss_Memcpy(unit, &queue->unit_buffer[queue->read_pos], queue->unit_size);
+
+ if ((queue->read_pos + queue->unit_size) >= queue->unit_buffer_size)
+ queue->read_pos = 0;
+ else
+ queue->read_pos += queue->unit_size;
+
+ ret = DRV_SUCCESS;
+quit:
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ queue_unlock(queue);
+ return ret;
+}
+
+/**
+ * ringQueue_Empty
+ *
+ *
+ */
+SINT32 ringQueue_Empty(T_Ring_Queue *queue)
+{
+
+ if (queue == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (queue->read_pos == queue->write_pos)
+ return 1;
+ else
+ return 0;
+}
+
+/**
+ * ringQueue_Full
+ *
+ *
+ */
+SINT32 ringQueue_Full(T_Ring_Queue *queue)
+{
+ UINT32 pos;
+
+ if (queue == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ pos = queue->write_pos + queue->unit_size;
+ if (pos >= queue->unit_buffer_size)
+ pos = 0;
+
+ if (pos == queue->read_pos)
+ return 1;
+ else
+ return 0;
+}
+
+/**
+ * ringQueue_Fush
+ * attention: Ðè±£Ö¤Óëring_queue_dequeue»¥³â
+ *
+ */
+void ringQueue_Fush(T_Ring_Queue *queue)
+{
+ if (queue == NULL)
+ {
+ //zDrv_ASSERT(0);
+ return ;
+ }
+
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ queue_lock(queue);
+
+ queue->read_pos = queue->write_pos;
+
+ if (queue->multi_user_protect > QUEUE_PROTECT_RAW)
+ queue_unlock(queue);
+ return ;
+}
+
+/**
+ * ringQueue_Destroy
+ *
+ *
+ */
+void ringQueue_Destroy(T_Ring_Queue *queue)
+{
+
+ if (queue == NULL)
+ {
+ //zDrv_ASSERT(0);
+ return ;
+ }
+
+ if (queue->multi_user_protect == QUEUE_PROTECT_MUTEX)
+ {
+ zOss_DeleteSemaphore(queue->lock );
+ }
+
+ zOss_Free(queue->unit_buffer);
+ zOss_Memset(queue, 0x0, sizeof(T_Ring_Queue));
+ zOss_Free(queue);
+
+ return ;
+}
+
diff --git a/cp/ps/driver/src/public/src/ramlog/hal_ramlog.c b/cp/ps/driver/src/public/src/ramlog/hal_ramlog.c
new file mode 100644
index 0000000..8600730
--- /dev/null
+++ b/cp/ps/driver/src/public/src/ramlog/hal_ramlog.c
@@ -0,0 +1,995 @@
+/*******************************************************************************
+* Copyright (C) 2009, ZTE Corporation.
+*
+* File Name: hal_ramlog.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: yuxiang
+* Date: 2009-11-06
+* History 1:
+* Date: 2010-01-06
+* Version: V1.1
+* Author: yuxiang
+* Modification:added ramlog record variable, be used for look up log buffer address when sys dead.
+* History 2:
+********************************************************************************/
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include "drvs_general.h"
+#include "drvs_ramlog.h"
+
+#ifdef _USE_RAMLOG
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+/*×î´ó´òÓ¡³¤¶ÈΪ244, zOss_PrintfµÄ×î´ó³¤¶ÈΪ255*/
+#define RAMLOG_PRINTF_MAX_LEN 224
+
+/*ASCIIÂëSOH,²»¿É¼û×Ö·û,×÷Ϊ·Ö¸ô·û*/
+#define RAMLOG_LOG_SEP_FLAG '\1'
+
+/*ASCIIÂëSTX,²»¿É¼û×Ö·û,×÷Ϊ½áÊø·û*/
+#define RAMLOG_LOG_END_FLAG '\2'
+
+/*shellÃüÁî*/
+#define RAMLOG_LOG_SHELL_CMD "ramlog"
+
+#define HAL_NML_TRACE(s...) zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, s)
+#define HAL_ERR_TRACE(s...) zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_ABNORMAL, s)
+#define HAL_LOG_TRACE(s...) zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_DEBUG, s)
+
+#define RAMLOG_DEBUG 0
+
+/****************************************************************************
+* Local Types
+****************************************************************************/
+typedef struct _T_Ramlog_ModuleItem
+{
+ T_ZOss_Node node;
+ UINT16 modNo; /*´òÓ¡Ä£¿éºÅ*/
+ volatile SINT32 curlogCnt; /*LOG¼ÆÊý*/
+ volatile SINT32 logBufAddrCnt; /*LOG»º³åÇøµØÖ·*/
+ SINT32 logBufSize; /*LOG»º³åÇø´óС*/
+ BOOL isLoopPrint; /*ÊÇ·ñÑ»·´òÓ¡*/
+ char *pLogBuf; /*LOG»º³åÇøÖ¸Õë*/
+ UINT32 lossLogCnt; /*¶ªÊ§LOGͳ¼Æ*/
+}
+T_Ramlog_ModuleItem;
+
+typedef struct _T_Ramlog_RamlogItem
+{
+ T_ZOss_List modList;
+ volatile SINT32 gblcurLogCnt;
+ BOOL isInPrint;
+}
+T_Ramlog_RamlogItem;
+
+typedef struct _T_Ramlog_ModCfg
+{
+ UINT16 nModNo; /*´òÓ¡Ä£¿éºÅ*/
+ char *szShellCmd; /*shellÃüÁî*/
+ SINT32 nBufSize; /*LOG»º³åÇø´óС*/
+ BOOL bIsLoopPrint; /*ÊÇ·ñÑ»·´òÓ¡*/
+ BOOL bIsReg; /*ÊÇ·ñ×¢²á*/
+}
+T_Ramlog_ModCfg;
+
+typedef struct _T_Ramlog_SortItem
+{
+ SINT32 sortGblLogIdx;
+ char *sortLogBuf;
+ UINT16 sortModNo;
+ SINT32 sortModLogIdx;
+}
+T_Ramlog_SortItem;
+
+/*´òÓ¡Ä£¿éµÄÐÅÏ¢¼Ç¼, Ö÷ҪΪģ¿éÃû³Æ, BufferµÄÆðʼºÍÖÕÖ¹µØÖ·¼°´óС*/
+typedef struct _T_Ramlog_Record
+{
+ char* rdModName;
+ char* rdBufPtrStart;
+ char* rdBufPtrEnd;
+ UINT32 rdBufSize;
+}
+T_Ramlog_Record;
+
+/****************************************************************************
+* Local Constants
+****************************************************************************/
+
+/****************************************************************************
+* Local Function Prototypes
+****************************************************************************/
+static SINT32 ramlog_RegModule(UINT16 nModNo, char* pShellCmd, UINT32 nBufSize, BOOL bIsLoop);
+/* no used
+static SINT32 ramlog_UnRegModule(UINT16 nModNo);
+*/
+static SINT32 ramlog_InsertSort(T_Ramlog_SortItem item[],UINT32 cnt);
+static SINT32 ramlog_ShowLog2WinTrace(UINT16 modItem[], UINT32 nModCnt, BOOL bIsSort);
+
+static SINT32 ramlog_ShowLog2WinTrace2(UINT16 modItem);
+static VOID ramlog_ShellCmdEntry2(T_Shell_CommandMessage *CmdMsg);
+VOID ramlog_ShellCmdEntry(T_Shell_CommandMessage *CmdMsg);
+
+extern SINT32 vsnformat(char *pcBuffer, UINT32 dwMaxCount, const char *pcParamFormat, va_list vaList);
+/****************************************************************************
+* Global Constants
+****************************************************************************/
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+/*´òÓ¡Ä£¿éÁ´±í*/
+static T_Ramlog_RamlogItem *s_pRamlogList = NULL;
+
+/*³õʼ»¯±ê¼Ç*/
+static BOOL s_ramlogInitFlag = FALSE;
+
+/*´òÓ¡LOGµ½WINTRACE±ê¼Ç*/
+static volatile BOOL s_ramlogShowFlag = FALSE;
+
+
+/*10×Ö½ÚÓÃÓÚ´æ·Åindex,2×Ö½Ú´æ·Å±ê¼Ç·û*/
+static char s_szPrintfBuf[RAMLOG_PRINTF_MAX_LEN+1]=
+ {
+ 0
+ };
+
+/*ËùÓдòÓ¡Ä£¿é³õʼ»¯Áбí,ÈçÐèÔö¼Ó´òÓ¡Ä£¿éÇëÔÚ´ËÌí¼Ó*/
+static T_Ramlog_ModCfg s_modCfgList[]=
+ {
+ {RAMLOG_MOD_NO1, RAMLOG_MOD_NO1_SHELL, RAMLOG_MOD_NO1_BUF_SIZE, RAMLOG_MOD_NO1_LOOP_ON, RAMLOG_MOD_NO1_REG},
+ {RAMLOG_MOD_NO2, RAMLOG_MOD_NO2_SHELL, RAMLOG_MOD_NO2_BUF_SIZE, RAMLOG_MOD_NO2_LOOP_ON, RAMLOG_MOD_NO2_REG},
+ {RAMLOG_MOD_NO3, RAMLOG_MOD_NO3_SHELL, RAMLOG_MOD_NO3_BUF_SIZE, RAMLOG_MOD_NO3_LOOP_ON, RAMLOG_MOD_NO3_REG},
+ {RAMLOG_MOD_NO4, RAMLOG_MOD_NO4_SHELL, RAMLOG_MOD_NO4_BUF_SIZE, RAMLOG_MOD_NO4_LOOP_ON, RAMLOG_MOD_NO4_REG},
+ {RAMLOG_MOD_NO5, RAMLOG_MOD_NO5_SHELL, RAMLOG_MOD_NO5_BUF_SIZE, RAMLOG_MOD_NO5_LOOP_ON, RAMLOG_MOD_NO5_REG},
+ {RAMLOG_MOD_NO6, RAMLOG_MOD_NO6_SHELL, RAMLOG_MOD_NO6_BUF_SIZE, RAMLOG_MOD_NO6_LOOP_ON, RAMLOG_MOD_NO6_REG},
+ {RAMLOG_MOD_NO7, RAMLOG_MOD_NO7_SHELL, RAMLOG_MOD_NO7_BUF_SIZE, RAMLOG_MOD_NO7_LOOP_ON, RAMLOG_MOD_NO7_REG},
+ {RAMLOG_MOD_NO8, RAMLOG_MOD_NO8_SHELL, RAMLOG_MOD_NO8_BUF_SIZE, RAMLOG_MOD_NO8_LOOP_ON, RAMLOG_MOD_NO8_REG},
+ {RAMLOG_MOD_NO9, RAMLOG_MOD_NO9_SHELL, RAMLOG_MOD_NO9_BUF_SIZE, RAMLOG_MOD_NO9_LOOP_ON, RAMLOG_MOD_NO9_REG},
+ {RAMLOG_MOD_NO10, RAMLOG_MOD_NO10_SHELL, RAMLOG_MOD_NO10_BUF_SIZE, RAMLOG_MOD_NO10_LOOP_ON, RAMLOG_MOD_NO10_REG},
+ {RAMLOG_MOD_NO11, RAMLOG_MOD_NO11_SHELL, RAMLOG_MOD_NO11_BUF_SIZE, RAMLOG_MOD_NO11_LOOP_ON, RAMLOG_MOD_NO11_REG},
+ {RAMLOG_MOD_NO12, RAMLOG_MOD_NO12_SHELL, RAMLOG_MOD_NO12_BUF_SIZE, RAMLOG_MOD_NO12_LOOP_ON, RAMLOG_MOD_NO12_REG},
+ {RAMLOG_MOD_NO13, RAMLOG_MOD_NO13_SHELL, RAMLOG_MOD_NO13_BUF_SIZE, RAMLOG_MOD_NO13_LOOP_ON, RAMLOG_MOD_NO13_REG},
+ {RAMLOG_MOD_NO14, RAMLOG_MOD_NO14_SHELL, RAMLOG_MOD_NO14_BUF_SIZE, RAMLOG_MOD_NO14_LOOP_ON, RAMLOG_MOD_NO14_REG},
+ {RAMLOG_MOD_NO15, RAMLOG_MOD_NO15_SHELL, RAMLOG_MOD_NO15_BUF_SIZE, RAMLOG_MOD_NO15_LOOP_ON, RAMLOG_MOD_NO15_REG},
+ {RAMLOG_MOD_NO16, RAMLOG_MOD_NO16_SHELL, RAMLOG_MOD_NO16_BUF_SIZE, RAMLOG_MOD_NO16_LOOP_ON, RAMLOG_MOD_NO16_REG},
+ {RAMLOG_MOD_NO17, RAMLOG_MOD_NO17_SHELL, RAMLOG_MOD_NO17_BUF_SIZE, RAMLOG_MOD_NO17_LOOP_ON, RAMLOG_MOD_NO17_REG}
+ };
+
+/*¼Ç¼´òÓ¡Ä£¿éÐÅÏ¢, ÓÃÓÚϵͳ¹Òµôºó, ²é¿´ramlogÄÚ´æµØÖ·*/
+static volatile T_Ramlog_Record s_ramlogRecord[RAMLOG_MOD_MAX];
+#endif
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+
+/*******************************************************************************
+* Function:
+* Description: ´òÓ¡Ä£¿é³õʼ»¯
+* Parameters:
+* Input:
+*
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+SINT32 zDrvRamLog_Initiate(VOID)
+{
+#ifdef _USE_RAMLOG
+
+ T_Ramlog_ModCfg *pCfgItem = NULL;
+ UINT16 modNum;
+ UINT16 modIdx;
+ SINT32 ret;
+
+ if ( s_ramlogInitFlag )
+ {
+ return DRV_ERR_OPEN_TIMES;
+ }
+
+ /*³õʼ»¯´òÓ¡Ä£¿éÁ´±í*/
+ if ( NULL == s_pRamlogList )
+ {
+ s_pRamlogList = zOss_Malloc( sizeof( T_Ramlog_RamlogItem ) );
+ if ( NULL == s_pRamlogList )
+ {
+ return DRV_ERR_MEM_ALLOC;
+ }
+ else
+ {
+ zOss_Memset( ( VOID * )s_pRamlogList, 0 , sizeof( T_Ramlog_RamlogItem ) );
+
+ zOss_ListInit( &s_pRamlogList->modList );
+ }
+ }
+
+ s_pRamlogList->isInPrint = FALSE;
+
+ /*×¢²á´òÓ¡Ä£¿é*/
+ modNum = sizeof(s_modCfgList)/sizeof(T_Ramlog_ModCfg);
+
+ for (modIdx=0; modIdx < modNum; modIdx++)
+ {
+ pCfgItem = &s_modCfgList[modIdx];
+ if (pCfgItem->bIsReg)
+ {
+ ret = ramlog_RegModule( pCfgItem->nModNo, pCfgItem->szShellCmd, pCfgItem->nBufSize, pCfgItem->bIsLoopPrint );
+ if (ret)
+ return ret;
+ }
+ }
+
+ /*×¢²áshellÃüÁî*/
+ ret = zOss_AddShellCmd(RAMLOG_LOG_SHELL_CMD, ramlog_ShellCmdEntry2, "´òÓ¡Çý¶¯µ÷ÊÔÐÅÏ¢");
+ if ( ZOSS_SUCCESS != ret )
+ return DRV_ERROR;
+
+ s_ramlogInitFlag = TRUE;
+
+#endif
+ return DRV_SUCCESS;
+}
+
+/*******************************************************************************
+* Function:
+* Description: log´òÓ¡
+* Parameters:
+* Input: nModNo:Ä£¿éºÅ
+* pFormat:¸ñʽ»¯×Ö·û´®
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+SINT32 ramlog_Printf( UINT16 nModNo, const VOID *pFormat, ... )
+{
+#ifdef _USE_RAMLOG
+
+ T_ZOss_Node *pCurNode = NULL;
+ T_Ramlog_ModuleItem *pModItem = NULL;
+ char *pCurBuf = NULL;
+
+ va_list ap;
+ UINT32 printfCnt;
+ UINT32 cnt;
+ UINT32 msr;
+
+ /*ÊÇ·ñ³õʼ»¯*/
+ if (!s_ramlogInitFlag)
+ {
+ return DRV_ERR_NOT_OPENED;
+ }
+ /*ÔÚ´òÓ¡LOGµ½WINTRACEʱ,´Ëº¯Êý²»ÔÙ´òÓ¡²¢·µ»ØDRV_ERR_BUSY*/
+ if (s_ramlogShowFlag)
+ {
+ return DRV_ERR_BUSY;
+ }
+ /*²ÎÊý¼ì²é*/
+ if ( NULL == pFormat )
+ {
+ return DRV_ERR_INVALID_PARAM;
+ }
+
+ /*´ÓÁбí²éѯµ±Ç°Ä£¿é*/
+ pCurNode = zOss_ListFirst(&s_pRamlogList->modList);
+ while ( pCurNode != NULL )
+ {
+ pModItem = ( T_Ramlog_ModuleItem * )pCurNode;
+ /*±È½Ï×ÓÄ£¿éºÅ*/
+ if ( pModItem->modNo == nModNo )
+ {
+ break;
+ }
+ pCurNode = zOss_ListNext( pCurNode );
+ }
+ /*²éÎÞ´Ë¿é*/
+ if ( pCurNode == NULL)
+ {
+ return DRV_ERR_INVALID_PARAM;
+ }
+
+ LOCK_SAVE(msr);
+ if (s_pRamlogList->isInPrint)
+ {
+ pModItem->lossLogCnt++;
+ LOCK_RESTORE(msr);
+ return DRV_ERROR;
+ }
+ s_pRamlogList->isInPrint = TRUE;
+ LOCK_RESTORE(msr);
+
+ va_start(ap,pFormat);
+ /*printfCnt=vsprintf(s_szPrintfBuf, pFormat,ap);*/
+
+ /*ÁôÏÂ12×Ö½Ú,10×Ö½ÚÓÃÓÚ´æ·Åindex,2×Ö½Ú´æ·Å±ê¼Ç·û*/
+ printfCnt=vsnformat(s_szPrintfBuf, RAMLOG_PRINTF_MAX_LEN, pFormat, ap);
+ va_end(ap);
+
+ /*³¬³ö×î´ó´òÓ¡¿Õ¼ä,ÊÇ·ñÑ»·´òÓ¡,10Byte´æ·ÅÐòºÅ,2Byte´æ·Å·Ö¸ô·ûÓë½áÊø·û,1×Ö½ÚNULL½áÊø·û*/
+ if ( pModItem->logBufAddrCnt+printfCnt+12+1 >= pModItem->logBufSize )
+ {
+ /*loop print*/
+ if (pModItem->isLoopPrint == TRUE)
+ {
+ pModItem->logBufAddrCnt=0;
+ pModItem->curlogCnt=0;
+ }
+ else
+ {
+ LOCK_SAVE(msr);
+ s_pRamlogList->isInPrint = FALSE;
+ LOCK_RESTORE(msr);
+ return DRV_ERROR;
+ }
+ }
+ /*»ñÈ¡ÄÚ´æµØÖ·*/
+ pCurBuf = &pModItem->pLogBuf[pModItem->logBufAddrCnt];
+
+ /*indexÒÔ10½øÖÆ·½Ê½×ª³É×Ö·û´®ÐÎʽ±£´æ*/
+ sprintf(pCurBuf,"%d",(int)s_pRamlogList->gblcurLogCnt);
+
+ /*¼ÆËã×Ö·û´®³¤¶È*/
+ cnt = strlen(pCurBuf);
+
+ /*Ìí¼Ó·Ö¸ô·û*/
+ //strncat(pCurBuf, "\1", 1);
+ pCurBuf += cnt;
+ memcpy(pCurBuf, "\1", 1);
+
+ /*Ìí¼Ó´òÓ¡LOG×Ö·û´®*/
+ //strncat(pCurBuf, s_szPrintfBuf, printfCnt);
+ pCurBuf += 1;
+ memcpy(pCurBuf, s_szPrintfBuf, printfCnt);
+
+ /*Ìí¼Ó½áÊø·û,×îºó×Ö·û´®Èç" 123 \1 stringlog \2 " */
+ //strncat(pCurBuf, "\2", 1);
+ pCurBuf += printfCnt;
+ memcpy(pCurBuf, "\2", 1);
+
+ /*ÒÑ´æ×Ö½ÚÊý*/
+ pModItem->logBufAddrCnt += cnt+printfCnt+2;
+
+ /*LOG¼ÆÊý*/
+ pModItem->curlogCnt++;
+
+ /*È«¾ÖLOG¼ÆÊý*/
+ s_pRamlogList->gblcurLogCnt++;
+
+ /*Òç³ö,ÖÃ0*/
+ if (s_pRamlogList->gblcurLogCnt < 0)
+ {
+ s_pRamlogList->gblcurLogCnt = 0;
+ }
+
+ LOCK_SAVE(msr);
+ s_pRamlogList->isInPrint = FALSE;
+ LOCK_RESTORE(msr);
+
+#endif
+ return DRV_SUCCESS;
+}
+
+#ifdef _USE_RAMLOG
+
+/*******************************************************************************
+* Function:
+* Description: ×¢²á´òÓ¡Ä£¿é
+* Parameters:
+* Input: nMode:Ä£¿éºÅ
+* nBufSize:LOG»º³åÇø´óС
+* bIsLoop:ÊÇ·ñÑ»·´òÓ¡
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+static SINT32 ramlog_RegModule(UINT16 nModNo, char* pShellCmd, UINT32 nBufSize, BOOL bIsLoop)
+{
+ T_ZOss_Node *pCurNode = NULL;
+ T_Ramlog_ModuleItem *pModItem = NULL;
+
+ UINT16 recordIdx = 0;
+
+ /*Á´±íûÓгõʼ»¯*/
+ if ( s_pRamlogList == NULL )
+ {
+ return DRV_ERROR;
+ }
+
+ /*ÏȲéѯµ±Ç°Ä£¿éÊÇ·ñÒѾ±»×¢²áʹÓÃ*/
+ pCurNode = zOss_ListFirst( &s_pRamlogList->modList );
+ while ( pCurNode != NULL )
+ {
+ pModItem = ( T_Ramlog_ModuleItem * )pCurNode;
+ /*Èç¹ûÒѾע²á·µ»Ø³É¹¦*/
+ if ( pModItem->modNo == nModNo )
+ {
+ return DRV_SUCCESS;
+ }
+ pCurNode = zOss_ListNext( pCurNode );
+ }
+
+ /*Ä£¿é»¹Ã»ÓÐ×¢²á*/
+ pModItem = zOss_Malloc( sizeof( T_Ramlog_ModuleItem ) );
+
+ if ( NULL == pModItem )
+ {
+ return DRV_ERR_MEM_ALLOC;
+ }
+ else
+ {
+ zOss_Memset( ( VOID * )pModItem, 0 , sizeof( T_Ramlog_ModuleItem ) );
+ }
+
+ /*³õʼ»¯ÅäÖÃÐÅÏ¢*/
+ pModItem->modNo = nModNo;
+ pModItem->logBufSize = nBufSize;
+ pModItem->isLoopPrint = bIsLoop;
+ pModItem->lossLogCnt = 0;
+ pModItem->pLogBuf = (char *)zOss_Malloc( sizeof(char)*nBufSize );
+
+ if ( NULL == pModItem->pLogBuf)
+ {
+ zOss_Free(pModItem);
+ return DRV_ERR_MEM_ALLOC;
+ }
+ else
+ {
+ zOss_Memset( ( VOID * )pModItem->pLogBuf, 0 , sizeof(char)*nBufSize );
+ }
+ /*Ìí¼Óµ½Á´±í*/
+ zOss_ListAdd( &s_pRamlogList->modList,( T_ZOss_Node * )pModItem );
+
+ /*¼Ç¼´òÓ¡Ä£¿éÐÅÏ¢*/
+ if(s_pRamlogList->modList.count <= RAMLOG_MOD_MAX)
+ {
+ recordIdx = s_pRamlogList->modList.count-1;
+ s_ramlogRecord[recordIdx].rdModName = pShellCmd;
+ s_ramlogRecord[recordIdx].rdBufPtrStart= pModItem->pLogBuf;
+ s_ramlogRecord[recordIdx].rdBufPtrEnd = pModItem->pLogBuf + nBufSize - 1;
+ s_ramlogRecord[recordIdx].rdBufSize = nBufSize;
+ }
+
+ return DRV_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function:
+* Description: Ð¶ÔØ´òÓ¡Ä£¿é
+* Parameters:
+* Input:
+*
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+#if 0 /*no used*/
+static SINT32 ramlog_UnRegModule(UINT16 nModNo)
+{
+ T_ZOss_Node *pCurNode = NULL;
+ T_Ramlog_ModuleItem *pModItem = NULL;
+
+ /*Á´±íûÓгõʼ»¯*/
+ if ( s_pRamlogList == NULL )
+ {
+ return DRV_ERROR;
+ }
+
+ /*ÏȲéѯµ±Ç°Ä£¿éÊÇ·ñÒѾ±»×¢²áʹÓÃ*/
+ pCurNode = zOss_ListFirst( &s_pRamlogList->modList );
+ while ( pCurNode != NULL )
+ {
+ pModItem = ( T_Ramlog_ModuleItem * )pCurNode;
+ /*Èç¹ûÒѾע²á·µ»Ø³É¹¦*/
+ if ( pModItem->modNo == nModNo )
+ {
+ /*ÊÍ·ÅLOG»º³åÇøÄÚ´æ*/
+ zOss_Free( pModItem->pLogBuf );
+
+ /*ÊÍ·Å´òÓ¡Ä£¿é½ÚµãÄÚ´æ*/
+ zOss_Free( pModItem );
+
+ /*´Ó´òÓ¡Ä£¿éÁ´±íÖÐɾ³ý*/
+ zOss_ListDelete( &s_pRamlogList->modList, pCurNode );
+ return DRV_SUCCESS;
+ }
+ pCurNode = zOss_ListNext( pCurNode );
+ }
+ /*²éÎÞ´Ë¿é*/
+ if ( pCurNode == NULL)
+ {
+ return DRV_ERR_INVALID_PARAM;
+ }
+
+ return DRV_SUCCESS;
+}
+#endif
+/*******************************************************************************
+ * Function:
+ * Description: ²åÈëÅÅÐò
+ * Parameters:
+ * Input:
+ *
+ * Output:
+ *
+ * Returns:
+ *
+ *
+ * Others:
+ ********************************************************************************/
+static SINT32 ramlog_InsertSort(T_Ramlog_SortItem item[],UINT32 cnt)
+{
+ SINT32 i,j;
+ volatile T_Ramlog_SortItem temp;
+
+ for (i=1; i < cnt; i++)
+ {
+ temp = item[i];
+ for (j=i; j>0 && temp.sortGblLogIdx < item[j-1].sortGblLogIdx; j--)
+ item[j]=item[j-1];
+ if (j!=i)
+ item[j] = temp;
+ }
+ return DRV_SUCCESS;
+}
+/*******************************************************************************
+* Function:
+* Description: ÏÔʾģ¿éµÄ´òÓ¡ÐÅÏ¢
+* Parameters:
+* Input: modItem:ÐèÒª´òÓ¡µÄÄ£¿éºÅÊý×éÖ¸Õë
+* nModCnt:ÐèÒª´òÓ¡Ä£¿éÊý
+* bIsSort:ÊÇ·ñÅÅÐò
+* Output:
+*
+* Returns:
+*
+*
+* Others:
+********************************************************************************/
+static SINT32 ramlog_ShowLog2WinTrace(UINT16 modItem[], UINT32 nModCnt, BOOL bIsSort)
+{
+ T_ZOss_Node *pCurNode = NULL;
+ T_Ramlog_ModuleItem *pModItem = NULL;
+ T_Ramlog_SortItem *pSortItem = NULL;
+ char *pStart = NULL;
+ char *pEnd = NULL;
+
+ char logBuf[RAMLOG_PRINTF_MAX_LEN+1];
+ UINT32 modIdx=0;
+ UINT32 modLogIdx=0;
+ UINT32 sortLogNum=0;
+ UINT32 sortLogIdx=0;
+ UINT32 modBufIdx=0;
+
+ T_Ramlog_ModuleItem *pModArray[8];
+ UINT32 modArrIdx=0;
+ UINT32 modArrCnt=0;
+ UINT32 index = 0;
+ //BOOL skipFlag = FALSE;
+
+ s_ramlogShowFlag = TRUE;
+
+
+
+ if ( nModCnt >= 1 )
+ {
+ for (modIdx=0; modIdx < nModCnt; modIdx++)
+ {
+ /*´ÓÁбí²éѯµ±Ç°Ä£¿é*/
+ pCurNode = zOss_ListFirst(&s_pRamlogList->modList);
+ while ( pCurNode != NULL )
+ {
+ pModItem = ( T_Ramlog_ModuleItem * )pCurNode;
+ /*±È½Ï×ÓÄ£¿éºÅ*/
+ if ( pModItem->modNo == modItem[modIdx] )
+ {
+ /*¼ÆËã×ÜLOGÊý*/
+ sortLogNum += pModItem->curlogCnt;
+ pModArray[modArrCnt] = pModItem;
+
+ modArrCnt++;
+ break;
+ }
+ pCurNode = zOss_ListNext( pCurNode );
+ }
+ /*²éÎÞ´Ë¿é*/
+ if ( pCurNode == NULL)
+ {
+ HAL_ERR_TRACE("ERROR: Module %d is not registered!", modItem[modIdx]);
+ s_ramlogShowFlag = FALSE;
+ return DRV_ERR_INVALID_PARAM;
+ }
+ }
+
+ if (!sortLogNum)
+ {
+ HAL_ERR_TRACE("No log to print!");
+ s_ramlogShowFlag = FALSE;
+ return DRV_ERROR;
+ }
+
+ HAL_LOG_TRACE("Mod Log Loss Count = %d\n", pModItem->lossLogCnt);
+
+ pSortItem = (T_Ramlog_SortItem*)zOss_Malloc( sizeof(T_Ramlog_SortItem)*sortLogNum );
+
+ /*ÄÚ´æÉêÇëʧ°Ü*/
+ if (pSortItem == NULL)
+ {
+ zOss_Free(pSortItem);
+ HAL_ERR_TRACE("ERROR: Memory malloc fail, Pls decrease the size of log buffer or num of module!");
+ s_ramlogShowFlag = FALSE;
+ return DRV_ERR_MEM_ALLOC;
+ }
+
+ zOss_Memset( ( VOID * )pSortItem, 0, sizeof(T_Ramlog_SortItem)*sortLogNum );
+
+ //°ÑËùÓÐlogÈ¡³ö´æÈëÅÅÐòÊý¾Ý×éÖÐ
+ for (modArrIdx=0; modArrIdx < modArrCnt; modArrIdx++)
+ {
+ pModItem = pModArray[modArrIdx];
+
+ pStart = pModItem->pLogBuf;
+ modLogIdx = 0;
+ modBufIdx = 0;
+
+ while ( modBufIdx < pModItem->logBufAddrCnt && sortLogIdx < sortLogNum )
+ {
+ /*Ìø¹ýÓÉÓÚ¶àÏß³ÌÔì³ÉLOG»º³åÇø´íÎó*/
+ /*
+ if(skipFlag == TRUE)
+ {
+ while(pEnd == NULL && modBufIdx < pModItem->logBufAddrCnt)
+ {
+ pEnd = strchr(pStart, RAMLOG_LOG_END_FLAG);
+ if (pEnd == NULL )
+ {
+ pStart++;
+ modBufIdx++;
+ }
+ else
+ {
+ modBufIdx += pEnd-pStart+1;
+ pStart = pEnd+1;
+ }
+
+ }
+ skipFlag = FALSE;
+ }
+ */
+ /*²éÕÒ·Ö¸ô·û*/
+ pEnd = strchr(pStart, RAMLOG_LOG_SEP_FLAG);
+ if (pEnd == NULL )
+ {
+ pStart++;
+ modBufIdx++;
+ //skipFlag = TRUE;
+ continue;
+ }
+
+ pSortItem[sortLogIdx].sortLogBuf = pEnd+1;
+
+ /*³õʼ»¯×Ö·ûÊý×é, ±£Áô1×Ö½ÚNULL*/
+ memset(logBuf, 0, RAMLOG_PRINTF_MAX_LEN+1);
+ if (pEnd-pStart < RAMLOG_PRINTF_MAX_LEN)
+ {
+ /*LOGÐòºÅ×Ö·û´®´æÈëÁÙʱ»º³åÇø*/
+ memcpy(logBuf, pStart, pEnd-pStart);
+ }
+
+ modBufIdx += pEnd-pStart+1;
+ pStart = pEnd+1;
+
+ /*²éÕÒ½áÊø·û*/
+ pEnd = strchr(pStart, RAMLOG_LOG_END_FLAG);
+ if (pEnd == NULL )
+ {
+ pStart++;
+ modBufIdx++;
+ //skipFlag = TRUE;
+ continue;
+ }
+
+ modBufIdx += pEnd-pStart+1;
+ pStart= pEnd+1;
+
+ /*LOGÈ«¾Öindex*/
+ sscanf(logBuf, "%d",(int*) &index);
+ pSortItem[sortLogIdx].sortGblLogIdx = index;
+
+ /*»ñÈ¡´òÓ¡Ä£¿éºÅ*/
+ pSortItem[sortLogIdx].sortModNo = pModItem->modNo;
+
+ /*LOGÄ£¿éindex*/
+ pSortItem[sortLogIdx].sortModLogIdx = modLogIdx;
+
+ modLogIdx++;
+ sortLogIdx++;
+ }
+ }
+
+ /*»ñȡʵ¼ÊµÄLOGÊý*/
+ sortLogNum = sortLogIdx;
+
+ if (bIsSort == TRUE)
+ {
+ /*LOGÅÅÐò*/
+ ramlog_InsertSort(pSortItem, sortLogNum);
+ }
+
+ for (sortLogIdx=0; sortLogIdx < sortLogNum; sortLogIdx++)
+ {
+ if ((sortLogIdx+1) % 30 == 0)
+ {
+ zOss_Sleep(300);
+ }
+ /*´òÓ¡ÅÅÐòºóµÄLOGÐÅÏ¢*/
+ pStart = pSortItem[sortLogIdx].sortLogBuf;
+ pEnd = strchr(pStart, RAMLOG_LOG_END_FLAG);
+ memset(logBuf, 0, RAMLOG_PRINTF_MAX_LEN+1);
+ if (pEnd-pStart < RAMLOG_PRINTF_MAX_LEN)
+ {
+ memcpy(logBuf, pStart, pEnd-pStart);
+ }
+ /*È¥³ý×Ö·û´®½áβ\n*/
+ if(logBuf[pEnd-pStart-1] == '\n')
+ {
+ logBuf[pEnd-pStart-1] = 0;
+ }
+
+ #if RAMLOG_DEBUG
+ /*µÚÒ»¸ö²ÎÊý:´òÓ¡Ä£¿éºÅ,µÚ¶þ¸ö²ÎÊý:Ä£¿éÄÚLOGÐòºÅ,µÚÈý¸ö²ÎÊý:ËùÓÐÄ£¿éÈ«¾ÖLOGÐòºÅ*/
+ HAL_LOG_TRACE("RAMLOG(%d,%d,%d):%s",
+ pSortItem[sortLogIdx].sortModNo,
+ pSortItem[sortLogIdx].sortModLogIdx,
+ pSortItem[sortLogIdx].sortGblLogIdx,
+ logBuf);
+ #else
+ HAL_LOG_TRACE("RAMLOG(%d):%s", pSortItem[sortLogIdx].sortModLogIdx,logBuf);
+ #endif
+ }
+ zOss_Free(pSortItem);
+ }
+ /*´òÓ¡Íê½áÊøºó,ÔÙÖÃFALSE,·ÀÖ¹LOG»º³åÇøÊä³öʱ±»ÐÞ¸Ä*/
+ s_ramlogShowFlag = FALSE;
+ return DRV_SUCCESS;
+}
+
+/*******************************************************************************
+ * Function:
+ * Description: shellÃüÁî´¦Àí
+ * Parameters:
+ * Input: CmdMsg:shellÃüÁî
+ *
+ * Output:
+ *
+ * Returns:
+ *
+ *
+ * Others:
+ ********************************************************************************/
+VOID ramlog_ShellCmdEntry(T_Shell_CommandMessage *CmdMsg)
+{
+ UINT32 itemIdx=0, itemNum=0;
+ UINT32 paraIdx=0;
+
+ /*×î´óÔÊÐí´ø8¸ö²ÎÊý*/
+ UINT16 mdls[8];
+ UINT16 modIdx=0;
+
+ BOOL bIsShow = TRUE;
+ T_Ramlog_ModCfg *pItem = NULL;
+
+ itemNum = sizeof(s_modCfgList)/sizeof(T_Ramlog_ModCfg);
+
+ if (CmdMsg->paraCount == 0)
+ {
+ /*show menu item*/
+ HAL_NML_TRACE("/*----------------------------------------------------------------*/");
+ HAL_NML_TRACE("/*--Now, we'll begin to print ramlog, pls selet the module item --*/");
+ HAL_NML_TRACE("/*----------------------------------------------------------------*/");
+
+ itemNum = sizeof(s_modCfgList)/sizeof(T_Ramlog_ModCfg);
+
+ for (itemIdx=0; itemIdx<itemNum; itemIdx++)
+ {
+ pItem = &s_modCfgList[itemIdx];
+ if(pItem->bIsReg)
+ {
+ HAL_NML_TRACE("(%d) %s module: please input [%s %s] to print log",
+ itemIdx+1, pItem->szShellCmd, RAMLOG_LOG_SHELL_CMD, pItem->szShellCmd);
+ }
+ }
+ return;
+ }
+
+ if (CmdMsg->paraCount >= 1)
+ {
+ /*calc total ram logs*/
+ for (paraIdx=0; paraIdx < CmdMsg->paraCount; paraIdx++)
+ {
+ for (itemIdx=0; itemIdx<itemNum; itemIdx++)
+ {
+ if (strcmp((const char *)(CmdMsg->para[paraIdx]), (const char *)(s_modCfgList[itemIdx].szShellCmd)) == 0)
+ {
+ mdls[modIdx++]=s_modCfgList[itemIdx].nModNo;
+ break;
+ }
+ }
+ if (itemIdx == itemNum)
+ {
+ bIsShow = FALSE;
+
+ HAL_ERR_TRACE("ERROR: %s is a invalid command!",CmdMsg->para[paraIdx]);
+ break;
+ }
+ }
+
+ if (bIsShow == TRUE)
+ {
+ ramlog_ShowLog2WinTrace(mdls, modIdx, TRUE);
+ }
+ }
+
+}
+
+static SINT32 ramlog_ShowLog2WinTrace2(UINT16 modItem)
+{
+ T_ZOss_Node *pCurNode = NULL;
+ T_Ramlog_ModuleItem *pModItem = NULL;
+
+ char *logBuf = NULL;
+ char s_TmpBuffer[200] = {0};
+
+ UINT32 i,j = 0;
+
+ s_ramlogShowFlag = TRUE;
+
+ /*´ÓÁбí²éѯµ±Ç°Ä£¿é*/
+ pCurNode = zOss_ListFirst(&s_pRamlogList->modList);
+ while ( pCurNode != NULL )
+ {
+ pModItem = ( T_Ramlog_ModuleItem * )pCurNode;
+ /*±È½Ï×ÓÄ£¿éºÅ*/
+ if ( pModItem->modNo == modItem )
+ {
+ break;
+ }
+ pCurNode = zOss_ListNext( pCurNode );
+ }
+ /*²éÎÞ´Ë¿é*/
+ if ( pCurNode == NULL)
+ {
+ HAL_ERR_TRACE("ERROR: Module %d is not registered!", modItem);
+ s_ramlogShowFlag = FALSE;
+ return DRV_ERR_INVALID_PARAM;
+ }
+
+ logBuf = zOss_Malloc( pModItem->logBufSize);
+
+ if(logBuf == NULL)
+ {
+ HAL_ERR_TRACE("ERROR: logBuf malloc failed!");
+ return DRV_ERR_INVALID_PARAM;
+ }
+
+ zOss_Memset(logBuf, 0, pModItem->logBufSize);
+
+ zOss_Memcpy(logBuf, &pModItem->pLogBuf[0], pModItem->logBufSize);
+
+ for(i=pModItem->logBufAddrCnt;i<pModItem->logBufSize;i++)
+ {
+ s_TmpBuffer[j++] = logBuf[i];
+ if(j==200) j=0;/*·ÀÖ¹´òӡΪ¿Õʱ£¬³öÏÖÊý×éÔ½½ç*/
+ if(RAMLOG_LOG_END_FLAG == logBuf[i])/*ÿ´Î»»Ðзû´òÓ¡Ò»´Î*/
+ {
+ HAL_ERR_TRACE("%s",s_TmpBuffer);
+ zOss_Memset(&s_TmpBuffer, 0, sizeof(s_TmpBuffer));
+ j = 0;
+ }
+
+ if(i == pModItem->logBufSize - 1)
+ {
+ HAL_ERR_TRACE("%s",s_TmpBuffer);
+ zOss_Memset(&s_TmpBuffer, 0, sizeof(s_TmpBuffer));
+ j = 0;
+ }
+ }
+
+ for(i=0;i<pModItem->logBufAddrCnt;i++)
+ {
+ s_TmpBuffer[j++] = logBuf[i];
+ if(j==200) j=0;/*·ÀÖ¹´òӡΪ¿Õʱ£¬³öÏÖÊý×éÔ½½ç*/
+ if(RAMLOG_LOG_END_FLAG == logBuf[i])/*ÿ´Î»»Ðзû´òÓ¡Ò»´Î*/
+ {
+ HAL_ERR_TRACE("%s",s_TmpBuffer);
+ zOss_Memset(&s_TmpBuffer, 0, sizeof(s_TmpBuffer));
+ j = 0;
+ }
+ }
+
+ zOss_Free(logBuf);
+
+ /*´òÓ¡Íê½áÊøºó,ÔÙÖÃFALSE,·ÀÖ¹LOG»º³åÇøÊä³öʱ±»ÐÞ¸Ä*/
+ s_ramlogShowFlag = FALSE;
+ return DRV_SUCCESS;
+}
+
+
+static VOID ramlog_ShellCmdEntry2(T_Shell_CommandMessage *CmdMsg)
+{
+ UINT32 itemIdx=0, itemNum=0;
+
+ /*×î´óÔÊÐí´ø8¸ö²ÎÊý*/
+ UINT16 mdls=0;
+
+ BOOL bIsShow = TRUE;
+ T_Ramlog_ModCfg *pItem = NULL;
+
+ itemNum = sizeof(s_modCfgList)/sizeof(T_Ramlog_ModCfg);
+
+ if (CmdMsg->paraCount == 0)
+ {
+ /*show menu item*/
+ HAL_NML_TRACE("/*----------------------------------------------------------------*/");
+ HAL_NML_TRACE("/*--Now, we'll begin to print ramlog, pls selet the module item --*/");
+ HAL_NML_TRACE("/*----------------------------------------------------------------*/");
+
+ itemNum = sizeof(s_modCfgList)/sizeof(T_Ramlog_ModCfg);
+
+ for (itemIdx=0; itemIdx<itemNum; itemIdx++)
+ {
+ pItem = &s_modCfgList[itemIdx];
+ if(pItem->bIsReg)
+ {
+ HAL_NML_TRACE("(%d) %s module: please input [%s %s] to print log",
+ itemIdx+1, pItem->szShellCmd, RAMLOG_LOG_SHELL_CMD, pItem->szShellCmd);
+ }
+ }
+ return;
+ }
+
+ if (CmdMsg->paraCount > 1)
+ {
+ HAL_NML_TRACE("Parameter more than one, invalid!");
+ }
+
+ if (CmdMsg->paraCount == 1)
+ {
+ /*calc total ram logs*/
+ for (itemIdx=0; itemIdx < itemNum; itemIdx++)
+ {
+
+ if (strcmp((const char *)(CmdMsg->para[0]), (const char *)(s_modCfgList[itemIdx].szShellCmd)) == 0)
+ {
+ mdls=s_modCfgList[itemIdx].nModNo;
+ break;
+ }
+ }
+
+ if (bIsShow == TRUE)
+ {
+ ramlog_ShowLog2WinTrace2(mdls);
+ }
+ }
+
+}
+
+
+#endif
+
diff --git a/cp/ps/driver/src/public/src/ramlog/makefile b/cp/ps/driver/src/public/src/ramlog/makefile
new file mode 100644
index 0000000..32c4a22
--- /dev/null
+++ b/cp/ps/driver/src/public/src/ramlog/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2009/11/16 V1.0 yuxiang create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = ramlog
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/random/makefile b/cp/ps/driver/src/public/src/random/makefile
new file mode 100644
index 0000000..d307531
--- /dev/null
+++ b/cp/ps/driver/src/public/src/random/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = random
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/random/random.c b/cp/ps/driver/src/public/src/random/random.c
new file mode 100644
index 0000000..70bf644
--- /dev/null
+++ b/cp/ps/driver/src/public/src/random/random.c
@@ -0,0 +1,94 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: random.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-09-24
+********************************************************************************/
+#include "random.h"
+
+struct rnd_state
+{
+ UINT32 s1, s2, s3;
+};
+
+struct rnd_state g_drvRandState;
+
+/*
+ * Handle minimum values for seeds
+ */
+static UINT32 __seed(UINT32 x, UINT32 m)
+{
+ return (x < m) ? x + m : x;
+}
+
+
+/**
+ * prandom32 - seeded pseudo-random number generator.
+ * @state: pointer to state structure holding seeded state.
+ *
+ * This is used for pseudo-randomness with no outside seeding.
+ * For more random results, use random32().
+ */
+UINT32 prandom32(struct rnd_state *state)
+{
+#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
+
+ state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
+ state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
+ state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
+
+ return (state->s1 ^ state->s2 ^ state->s3);
+}
+
+
+/*
+ * Generate some initially weak seeding values to allow
+ * to start the random32() engine.
+ */
+static int random32_init(VOID)
+{
+
+ struct rnd_state *state = &g_drvRandState;
+
+#define LCG(x) ((x) * 69069) /* super-duper LCG */
+ state->s1 = __seed(LCG(0 + 100), 1);
+ state->s2 = __seed(LCG(state->s1), 7);
+ state->s3 = __seed(LCG(state->s2), 15);
+
+ /* "warm it up" */
+ prandom32(state);
+ prandom32(state);
+ prandom32(state);
+ prandom32(state);
+ prandom32(state);
+ prandom32(state);
+ return 0;
+}
+
+/**
+ * random32 - pseudo random number generator
+ *
+ * A 32 bit pseudo-random number is generated using a fast
+ * algorithm suitable for simulation. This algorithm is NOT
+ * considered safe for cryptographic use.
+ */
+static UINT32 s_randomInit;
+UINT32 random32(VOID)
+{
+ UINT32 r;
+ struct rnd_state *state = &g_drvRandState;
+
+ if (!s_randomInit)
+ {
+ random32_init();
+ s_randomInit = 1;
+ }
+ r = prandom32(state);
+ return r;
+}
+
diff --git a/cp/ps/driver/src/public/src/requestQueue/makefile b/cp/ps/driver/src/public/src/requestQueue/makefile
new file mode 100644
index 0000000..c5b96e0
--- /dev/null
+++ b/cp/ps/driver/src/public/src/requestQueue/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2009,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2013/09/24 V1.0 geanfeng create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = requestQueue
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH) \
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/requestQueue/request_queue.c b/cp/ps/driver/src/public/src/requestQueue/request_queue.c
new file mode 100644
index 0000000..595103c
--- /dev/null
+++ b/cp/ps/driver/src/public/src/requestQueue/request_queue.c
@@ -0,0 +1,161 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: request_queue.c
+* File Mark:
+* Description:
+* Others:
+* Version: V1.0
+* Author: geanfeng
+* Date: 2013-09-24
+********************************************************************************/
+
+#include "drvs_general.h"
+#include "drvs_assert.h"
+#include "ring_queue.h"
+#include "request_queue.h"
+
+
+/**
+ * requestQueue_Create - create a new request queue.
+ *
+ * Create a new special request queue.
+ */
+T_Request_Queue *requestQueue_Create(UINT32 req_count, UINT32 req_size, queue_notify notify_fn, VOID* queue_data)
+{
+ T_Request_Queue *q = NULL;
+
+ q = (T_Request_Queue*)zOss_Malloc(sizeof(T_Request_Queue));
+ if (!q)
+ return NULL;
+
+ q->queue = ringQueue_Create(req_count, req_size, QUEUE_PROTECT_RAW);
+ if (!q->queue)
+ {
+ free(q);
+ return NULL;
+ }
+ q->notify_fn = notify_fn;
+ q->process_state = QUEUE_IDLE;
+ q->work_state = QUEUE_WORKING;
+ q->queue_data = queue_data;
+ return q;
+}
+
+
+/**
+ * requestQueue_SubmitRequest - submit a new request.
+ *
+ *
+ */
+SINT32 requestQueue_SubmitRequest(T_Request_Queue *q, T_Request *req)
+{
+ SINT32 ret = 0;
+
+ if (q == NULL || req == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+ zDrv_ASSERT(q->process_state == QUEUE_IDLE);
+
+ ret = ringQueue_Enqueue(q->queue, (VOID *)req);
+ if (ret)
+ {
+ q->process_state = QUEUE_IDLE;
+ return ret;
+ }
+
+ /*ÏÈÖÃprocess_state£¬ÔÙÅжÏwork_state£¬Ë³ÐòÖØÒª*/
+ q->process_state = QUEUE_SUBMITING;
+
+ if (q->work_state == QUEUE_SUSPEND)
+ {
+ q->process_state = QUEUE_IDLE;
+ return 0;
+ }
+
+ if (q->notify_fn)
+ q->notify_fn(q);
+
+ q->process_state = QUEUE_IDLE;
+ return 0;
+}
+
+/**
+ * requestQueue_FetchRequest - fetch a new request.
+ *
+ *
+ */
+SINT32 requestQueue_FetchRequest(T_Request_Queue *q, T_Request *req)
+{
+ SINT32 ret = 0;
+
+ if (q == NULL || req == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+ ret = ringQueue_Dequeue(q->queue, (VOID*)req);
+ return ret;
+}
+
+/**
+ * suspend_request_queue - suspend a request queue.
+ *
+ *
+ */
+SINT32 requestQueue_Suspend(T_Request_Queue *q)
+{
+ if (q == NULL)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ q->work_state = QUEUE_SUSPEND;
+
+ while (q->process_state == QUEUE_SUBMITING)
+ {
+ zOss_Sleep(1);
+ }
+
+ return 0;
+}
+
+/**
+ * requestQueue_Resume - resume a suspend request queue.
+ *
+ *
+ */
+SINT32 requestQueue_Resume(T_Request_Queue *q)
+{
+ zDrv_ASSERT(q != NULL);
+
+ if (q->work_state != QUEUE_SUSPEND)
+ {
+ zDrv_ASSERT(0);
+ return DRV_ERROR;
+ }
+
+ if (q->notify_fn)
+ {
+ q->notify_fn(q);
+ }
+
+ q->work_state = QUEUE_WORKING;
+ return 0;
+}
+
+/**
+ * requestQueue_Destroy - destroy a suspend request queue.
+ *
+ *
+ */
+VOID requestQueue_Destroy(T_Request_Queue *q)
+{
+ zDrv_ASSERT(q != NULL);
+ ringQueue_Destroy(q->queue);
+ q->queue = NULL;
+ zOss_Free(q);
+}
diff --git a/cp/ps/driver/src/public/src/ring/hal_ring.c b/cp/ps/driver/src/public/src/ring/hal_ring.c
new file mode 100755
index 0000000..8b291e3
--- /dev/null
+++ b/cp/ps/driver/src/public/src/ring/hal_ring.c
Binary files differ
diff --git a/cp/ps/driver/src/public/src/ring/makefile b/cp/ps/driver/src/public/src/ring/makefile
new file mode 100755
index 0000000..e0820d7
--- /dev/null
+++ b/cp/ps/driver/src/public/src/ring/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2001,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2008/11/17 V1.0 huji create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = ring
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH)
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/src/trap/hal_assert.c b/cp/ps/driver/src/public/src/trap/hal_assert.c
new file mode 100644
index 0000000..7861c02
--- /dev/null
+++ b/cp/ps/driver/src/public/src/trap/hal_assert.c
@@ -0,0 +1,686 @@
+/*******************************************************************************
+ * Copyright (C) 2007, ZTE Corporation.
+ *
+ * File Name: hal_assert.c
+ * File Mark:
+ * Description:
+ * Others:
+ * Version: v0.1
+ * Author: weizhigang
+ * Date: 2009-7-2
+ * History 1:
+ * Date:
+ * Version:
+ * Author:
+ * Modification:
+ * History 2:
+ * Date: 2009-12-02
+ * Version: V0.2
+ * Author: Qian Chen
+ * Modification:implement zDrv_assertInternal
+*******************************************************************************/
+
+/*******************************************************************************
+* Include files
+*******************************************************************************/
+#include "drvs_general.h"
+#include "drvs_cfg.h"
+#include "drvs_ramlog.h"
+
+
+/*******************************************************************************
+* Local Macros
+*******************************************************************************/
+#if 0
+#define HAL_EXCEPTION_MAX_NAME_LEN (64) /* include '\0' */
+#define HAL_EXCEPTION_INFO_ITEMS_NUM (8) /* 2^n, n>0 */
+#define HAL_EXCEPTION_ILLEGAL_DATA_ADDRESS (0x9000000DUL)
+#define HAL_EXCEPTION_FLASH_LOGIC_ADDRESS (NAND_BASE+0x027C0000)
+#define HAL_EXCEPTION_RAM_LOG_INDEX (*(UINT32*)(0x00070000UL))
+#define HAL_EXCEPTION_RAM_LOG_ADDRESS (0x00070004UL)
+#define HAL_EXCEPTION_LABEL "Assert"
+#define HAL_EXCEPTION_LOG_ETC "..."
+#define HAL_EXCEPTION_LOG_HEAD "\tHAL Assert:"
+#define HAL_EXCEPTION_LOG_INDEX "\tindex:%d"
+#define HAL_EXCEPTION_LOG_EXP "\texpression:%s"
+#define HAL_EXCEPTION_LOG_FILE_NAME "\tfile name:%s"
+#define HAL_EXCEPTION_LOG_FUNC_NAME "\tfunction name:%s"
+#define HAL_EXCEPTION_LOG_LINE_NUM "\tline#:%d"
+#define HAL_EXCEPTION_LOG_SP "\tSP:0x%8X"
+#define HAL_EXCEPTION_LOG_CPSR "\tCPSR:0x%8X"
+#define HAL_EXCEPTION_LOG_SPSR "\tSPSR:0x%8X"
+#define HAL_EXCEPTION_LOG_PID "\tPID:%d"
+#define HAL_EXCEPTION_LOG_PNAME "\tThreadName:%s"
+#define HAL_EXCEPTION_LOG_FORMAT HAL_EXCEPTION_LOG_HEAD \
+ HAL_EXCEPTION_LOG_INDEX \
+ HAL_EXCEPTION_LOG_EXP \
+ HAL_EXCEPTION_LOG_FILE_NAME \
+ HAL_EXCEPTION_LOG_FUNC_NAME \
+ HAL_EXCEPTION_LOG_LINE_NUM \
+ HAL_EXCEPTION_LOG_SP \
+ HAL_EXCEPTION_LOG_CPSR \
+ HAL_EXCEPTION_LOG_SPSR \
+ HAL_EXCEPTION_LOG_PID \
+ HAL_EXCEPTION_LOG_PNAME
+
+
+/*******************************************************************************
+* Local Types
+*******************************************************************************/
+typedef struct _T_HalAssert_Info
+{
+ CHAR m_label[8];
+ UINT32 m_index;
+ CHAR m_expression[HAL_EXCEPTION_MAX_NAME_LEN];
+ CHAR m_fileName[HAL_EXCEPTION_MAX_NAME_LEN];
+ CHAR m_funcName[HAL_EXCEPTION_MAX_NAME_LEN];
+ UINT32 m_lineNum;
+ UINT32 *m_sp;
+ UINT32 m_cpsr;
+ UINT32 m_spsr;
+ ZOSS_THREAD_ID m_pid;
+ CHAR m_threadName[HAL_EXCEPTION_MAX_NAME_LEN];
+}
+T_HalAssert_Info;
+
+typedef struct _T_DrvAssert_Info
+{
+ ZOSS_THREAD_ID pThread;
+ const CHAR* pExp;
+ const CHAR* pFile;
+ const CHAR* pFunc;
+ UINT32 dwLine;
+}
+T_DrvAssert_Info;
+#endif
+/*******************************************************************************
+* Local Constants
+*******************************************************************************/
+
+/*******************************************************************************
+* Local Function Prototypes
+*******************************************************************************/
+
+/*******************************************************************************
+* Global Constants
+*******************************************************************************/
+
+/*******************************************************************************
+* Global Variables
+*******************************************************************************/
+#if 0
+static BOOL s_bUsed = FALSE; /* ±êʶÊÇ·ñΪµÚÒ»´Î½øÈëÒì³££¬·ÀÖ¹Òì³£´¦ÀíǶÌ× */
+static UINT32 s_infoItemIndex;
+#if 0
+static T_HalAssert_Info s_aAssertInfo[HAL_EXCEPTION_INFO_ITEMS_NUM];
+#else
+static T_HalAssert_Info *s_pAssertInfo = {(T_HalAssert_Info*)(HAL_EXCEPTION_RAM_LOG_ADDRESS)};
+static T_HalAssert_Info* s_aAssertInfo[HAL_EXCEPTION_INFO_ITEMS_NUM] = {NULL};
+#endif
+static BOOL s_bExcepInitialized = FALSE;
+#endif
+
+//static volatile T_DrvAssert_Info g_zDrvAssertInfo = {0,};
+/*******************************************************************************
+* Global Function Prototypes
+*******************************************************************************/
+//static VOID halExcep_Abort(UINT32 Abort);
+#if 0
+static SINT32 halExcep_ShortFileName(const CHAR *inpath, CHAR *outfile, UINT32 len);
+static VOID halExcep_Info2RamLog(VOID);
+static VOID halExcep_PrintInfoRamLog(const T_HalAssert_Info *pInfo);
+static SINT32 halExcep_GenerateLog(CHAR *strLog, T_HalAssert_Info *pInfo);
+//extern SINT32 nand_Read(UINT32 dwStart, UINT32 dwLen, UINT8* to);
+//extern SINT32 nand_Program(UINT32 dwStart, UINT32 dwLen, UINT8* from);
+//extern SINT32 zDrvLcd_Initiate(VOID);
+//extern SINT32 zDrvBlg_Initiate(VOID);
+extern SINT32 zDrvExcep_Initiate(VOID);
+#endif
+
+#ifdef _OS_TOS
+extern void tos_assert_failed(const char *exp, const char *file, const char *func, int line);
+#endif
+
+/*******************************************************************************
+* Function Definitions
+*******************************************************************************/
+
+/*******************************************************************************
+ * Function: zDrvExcep_Handler
+ * Description: driver assert function
+ * Parameters:
+
+ * Input:
+ pcFileName: pointer to the file name when assert occurred
+ pcFuncName: pointer to the pcFuncName when assert occurred
+ dwLineNum: the error lines when assert occurred
+ * Output:None
+ *
+ * Returns:
+ * none
+ * Others:
+ ******************************************************************************/
+#if 0
+VOID zDrvExcep_Handler(CHAR *pExp, const CHAR * pcFileName, const CHAR * pcFuncName, UINT32 dwLineNum)
+{
+ SINT32 ret = DRV_SUCCESS;
+
+ g_zDrvAssertInfo.pThread = zOss_GetCurThreadID();
+
+ ZOSS_DISABLE_IRQ();
+
+ g_zDrvAssertInfo.pExp = pExp;
+ g_zDrvAssertInfo.pFile = pcFileName;
+ g_zDrvAssertInfo.pFunc = pcFuncName;
+ g_zDrvAssertInfo.dwLine = dwLineNum;
+
+#ifdef _OS_WIN
+ _assert(pExp, pcFileName, (unsigned int)dwLineNum);
+#elif defined (_OS_OSE)
+ ose_assertion_failed((char *)pExp, (char *)pcFileName, (unsigned int)dwLineNum);
+#elif defined (_OS_TOS)
+ tos_assert_failed((const char *)pExp, pcFileName, pcFuncName, dwLineNum);
+#elif defined (_OS_LINUX)
+ linux_assert_failed((const char *)pExp, pcFileName, pcFuncName, dwLineNum);
+#endif
+
+#if 0
+
+ SINT32 ret = DRV_SUCCESS;
+ SINT32 i = 0, offset = 0;
+ UINT32 len = 0;
+ UINT32 reg = 0;
+ #ifndef _USE_DATACARD
+ CHAR *pStrLog = NULL;
+ #endif
+ T_HalAssert_Info *pInfo = NULL;
+ ZOSS_THREAD_ID pThread = NULL;
+
+
+ if (!s_bUsed && (pExp != NULL) && (pcFileName != NULL) && (pcFuncName != NULL))
+ {
+ s_bUsed = TRUE;
+
+ /* Initial static log variables, when they are not initialized */
+ if (!s_bExcepInitialized)
+ {
+ /* information index */
+ s_infoItemIndex = HAL_EXCEPTION_RAM_LOG_INDEX;
+
+ /* all pointers to RAM space of information */
+ for (i = 0; i < HAL_EXCEPTION_INFO_ITEMS_NUM; i++)
+ {
+ s_aAssertInfo[i] = (T_HalAssert_Info*)(HAL_EXCEPTION_RAM_LOG_ADDRESS + offset);
+
+ /* make sure that all strings are legal */
+ pInfo = s_aAssertInfo[i];
+ pInfo->m_expression[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ pInfo->m_fileName[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ pInfo->m_funcName[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ pInfo->m_threadName[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ offset += sizeof(T_HalAssert_Info);
+ }
+
+ pInfo = (T_HalAssert_Info*)zOss_Malloc(sizeof(T_HalAssert_Info));
+ if (pInfo != NULL)
+ {
+ ret = nand_Read(HAL_EXCEPTION_FLASH_LOGIC_ADDRESS, sizeof(T_HalAssert_Info), (UINT8 *)pInfo);
+ if (ret == 0)
+ {
+ /* Update index and store it */
+ s_infoItemIndex = pInfo->m_index + 1;
+ HAL_EXCEPTION_RAM_LOG_INDEX = s_infoItemIndex;
+
+ zOss_Memcpy((VOID*)(&s_pAssertInfo[pInfo->m_index&(HAL_EXCEPTION_INFO_ITEMS_NUM-1)]), (VOID*)pInfo, sizeof(T_HalAssert_Info));
+ }
+ zOss_Free((VOID*)pInfo);
+ }
+ }
+
+ pInfo = &s_pAssertInfo[s_infoItemIndex&(HAL_EXCEPTION_INFO_ITEMS_NUM-1)];
+
+ /* Mask all interrupts */
+ zDrv_DisableIrq();
+
+ /* Set the current thread as highest priority one */
+ pThread = zOss_GetCurThreadID();
+ if (pThread != NULL)
+ {
+ (VOID)zOss_SetThreadPri(pThread, 0);
+ zOss_GetThreadInfo(pThread, (CHAR*)pInfo->m_threadName, NULL, NULL, NULL);
+ pInfo->m_pid = pThread;
+ }
+
+ /* Initialize log label and index */
+ sprintf((char*)pInfo->m_label, HAL_EXCEPTION_LABEL);
+ pInfo->m_index = s_infoItemIndex;
+
+ /* expression string */
+ len = strlen((const char*)pExp);
+ if (len < HAL_EXCEPTION_MAX_NAME_LEN)
+ {
+ sprintf((char*)pInfo->m_expression, "%s", (const char*)pExp);
+ }
+ else /* the first HAL_EXCEPTION_MAX_NAME_LEN-4 chars plus "..." and end of string */
+ {
+ len = sizeof(HAL_EXCEPTION_LOG_ETC);
+ strncpy((char*)pInfo->m_expression, (const char*)pExp, HAL_EXCEPTION_MAX_NAME_LEN-(len + 1));
+ sprintf((char*)(pInfo->m_expression + HAL_EXCEPTION_MAX_NAME_LEN -(len + 1)), HAL_EXCEPTION_LOG_ETC);
+ }
+
+ /* file name */
+ ret = halExcep_ShortFileName(pcFileName, pInfo->m_fileName, HAL_EXCEPTION_MAX_NAME_LEN);
+
+ /* function name */
+ len = strlen((const char*)pcFuncName);
+ len = (len >= HAL_EXCEPTION_MAX_NAME_LEN)?(HAL_EXCEPTION_MAX_NAME_LEN - 1):len;
+ strncpy((char*)pInfo->m_funcName, (const char*)pcFuncName, len);
+ pInfo->m_funcName[len] = '\0';
+
+ /* line# */
+ pInfo->m_lineNum = dwLineNum;
+
+ /* CPSR SPSR */
+#ifndef _OS_WIN
+
+ /* CPSR */
+#if __ARMCC_VERSION > 220000 /* RVCT */
+ __asm
+ {
+ MRS reg, CPSR
+ }
+#else
+#ifdef __GNUC__ /* gcc */
+ __asm__("MRS R0, CPSR");
+__asm__("str r0, %0": "=m"(reg));
+#endif /* #ifdef __GNUC__ */
+#endif /* #if __ARMCC_VERSION > 200000 */
+ pInfo->m_cpsr = reg;
+
+ /* SPSR */
+#ifdef __ARMCC_VERSION
+#if __ARMCC_VERSION > 220000
+ __asm
+ {
+ MRS reg, SPSR
+ }
+#else
+#ifdef __GNUC__
+ __asm__("MRS R0, SPSR");
+__asm__("str r0, %0": "=m"(reg));
+#endif /* #ifdef __GNUC__ */
+#endif /* #if __ARMCC_VERSION > 200000 */
+#endif /* #ifdef __ARMCC_VERSION */
+ pInfo->m_spsr = reg;
+
+#if __ARMCC_VERSION > 220000 /*rvct*/
+ {
+ __asm
+ {
+ mov reg, __current_sp()
+ }
+ }
+#else /*·ÇRVCT*/
+#ifdef __GNUC__
+__asm__("str r11, %0": "=m"(pfp)); /*Õ»ÖÐ×îÉϲãµÄÖ¡Ö¸Õë(fp)*/
+__asm__("str r13, %0": "=m"(psp)); /*Õ»¶¥µØÖ·(sp)*/
+#else /*·ÇRVCT,·ÇGCC*/
+#endif /*end #ifdef __GNUC__*/
+#endif /*end #if __ARMCC_VERSION > 220000*/
+ pInfo->m_sp = (UINT32 *)reg;
+#endif /* #ifndef _OS_WIN */
+
+
+
+
+
+ /* RAM log */
+ halExcep_PrintInfoRamLog(pInfo);
+
+ if (s_bExcepInitialized)
+ {
+ /* LCD for modem or handset, LED for datacard */
+#ifndef _USE_DATACARD
+ /* log string */
+ pStrLog = (CHAR*)zOss_Malloc(512);
+ if (pStrLog != NULL)
+ {
+ len = halExcep_GenerateLog(pStrLog, pInfo);
+
+ /* LCD&backlight */
+ ret = zDrvBlg_Initiate(); /* backlight */
+ if (ret == DRV_SUCCESS)
+ {
+ ret = halBlg_Open();
+ }
+ if (ret == DRV_SUCCESS)
+ {
+ ret = halBlg_LcdEnable(TRUE);
+ }
+ if (ret == DRV_SUCCESS)
+ {
+ ret = halBlg_LcdSetBrightness(255);
+ }
+
+ ret = zDrvLcd_Initiate(); /* LCD */
+ ret += zDrvLcd_Init();
+ if (ret == DRV_SUCCESS)
+ {
+ ret = halLcd_Open(LCD_MAIN);
+ }
+ if (ret == DRV_SUCCESS && pStrLog != NULL)
+ {
+ zDrvLcd_DisplayText(0, 0, pStrLog, len);
+ }
+ zOss_Free((VOID*)pStrLog);
+ }
+#else
+ /* yellow LED */
+ ret = zDrvLED_Set(LED_YELLOW);
+#endif
+ }
+
+ /* FLASH */
+ ret = nand_Program(HAL_EXCEPTION_FLASH_LOGIC_ADDRESS, sizeof(T_HalAssert_Info), (UINT8*)pInfo);
+
+ /* Update index and store it */
+ s_infoItemIndex++;
+ HAL_EXCEPTION_RAM_LOG_INDEX = s_infoItemIndex;
+ }/* if (!s_bUsed && (pExp != NULL) && (pcFileName != NULL) && (pcFuncName != NULL)) */
+ #endif
+
+ /* ARM exception */
+ halExcep_Abort(1);
+ ZOSS_ENABLE_IRQ();
+ (VOID)ret;
+ return;
+}
+
+/*******************************************************************************
+ * Function: halExcep_Abort
+ * Description: abort function, results in ARM exception.
+ * Parameters:
+
+ * Input: None
+ * Output:None
+ *
+ * Returns:
+ * none
+ * Others:
+ ******************************************************************************/
+static VOID halExcep_Abort(UINT32 Abort)
+{
+ UINT32 unAlignAddr = 0x01;
+ volatile UINT32 tmp = 0;
+
+ /*unAlign exception*/
+ tmp = *(volatile UINT32*)unAlignAddr;
+
+ /*div 0 exception*/
+ tmp = tmp/(Abort-0x1);
+#ifdef BUG_ON
+ BUG_ON(1);
+#endif
+ // tmp = *(volatile UINT32*)HAL_EXCEPTION_ILLEGAL_DATA_ADDRESS; /* Alignment trap */
+ //(VOID)tmp;
+ while(Abort);
+ return;
+}
+#endif
+#if 0
+static SINT32 halExcep_ShortFileName(const CHAR *inpath, CHAR *outfile, UINT32 len)
+{
+ const char *p = NULL;
+ UINT32 n = 0;
+
+ p = strrchr((char *)inpath, '\\');
+ if (NULL != p)
+ {
+ p++;
+ }
+ else
+ {
+ p = (char *)inpath;
+ }
+ n = strlen(p);
+
+ if (len <= n)
+ {
+ p += (n - len) + 1;
+ strncpy((char *)outfile, p, len - 1);
+ n = len-1;
+ }
+ else
+ {
+ strncpy((char *)outfile, p, n);
+ }
+
+ outfile[n] = '\0';
+ return((SINT32)n);
+}
+
+
+/*******************************************************************************
+ * Function: halExcep_PrintInfoRamLog
+ * Description: print log according to exception information
+ * in RAM or FLASH.
+ * Parameters:
+
+ * Input: None
+ * Output:None
+ *
+ * Returns:
+ * none
+ * Others:
+ ******************************************************************************/
+static VOID halExcep_PrintInfoRamLog(const T_HalAssert_Info *pInfo)
+{
+ if (pInfo == NULL)
+ {
+ return;
+ }
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_HEAD);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_INDEX, pInfo->m_index);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_EXP, pInfo->m_expression);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_FILE_NAME, pInfo->m_fileName);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_FUNC_NAME, pInfo->m_funcName);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_LINE_NUM, pInfo->m_lineNum);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_SP, pInfo->m_sp);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_CPSR, pInfo->m_cpsr);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_SPSR, pInfo->m_spsr);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_PID, pInfo->m_pid);
+ (VOID)zDrvRamlog_PRINTF(RAMLOG_MOD_ASSERT, (const VOID *)HAL_EXCEPTION_LOG_PNAME, pInfo->m_threadName);
+
+ return;
+}
+
+
+/*******************************************************************************
+ * Function: halExcep_Info2RamLog
+ * Description: generate log according to exception information
+ * in RAM or FLASH.
+ * Parameters:
+
+ * Input: None
+ * Output:None
+ *
+ * Returns:
+ * none
+ * Others:
+ ******************************************************************************/
+static VOID halExcep_Info2RamLog(VOID)
+{
+ T_HalAssert_Info *pInfoArray[HAL_EXCEPTION_INFO_ITEMS_NUM] = {NULL};
+ T_HalAssert_Info *pInfo = s_pAssertInfo;
+ SINT32 ret = 0;
+ UINT32 validInfoNum = 0;
+
+#ifdef _USE_RAMLOG
+ T_HalAssert_Info *pTemp = NULL;
+ UINT32 i = 0, k = 0;
+
+ /* search information */
+ for (i = 0; i < HAL_EXCEPTION_INFO_ITEMS_NUM; i++)
+ {
+ /* compare information head string with HAL_EXCEPTION_LABEL(including end of string '\0') */
+ ret = strncmp((char*)pInfo->m_label, HAL_EXCEPTION_LABEL, strlen(HAL_EXCEPTION_LABEL)+1);
+ if (ret == 0)
+ {
+ pInfoArray[validInfoNum] = pInfo;
+ validInfoNum++;
+ }
+ pInfo++;
+ }
+
+ /* sort information */
+ for (i = 0; i < validInfoNum; i++)
+ {
+ for (k = 0; k < validInfoNum-i-1; k++)
+ {
+ if (pInfoArray[k]->m_index > pInfoArray[k+1]->m_index)
+ {
+ pTemp = pInfoArray[k];
+ pInfoArray[k] = pInfoArray[k+1];
+ pInfoArray[k+1] = pTemp;
+ }
+ }
+ }
+
+ /* print ram log */
+ for (i = 0; i < validInfoNum; i++)
+ {
+ pInfo = pInfoArray[i];
+
+ /* print log string */
+ halExcep_PrintInfoRamLog(pInfo);
+ }
+
+#endif
+
+ pInfo = (T_HalAssert_Info*)zOss_Malloc(sizeof(T_HalAssert_Info));
+
+ if (pInfo != NULL)
+ {
+ //ret = nand_Read(HAL_EXCEPTION_FLASH_LOGIC_ADDRESS, sizeof(T_HalAssert_Info), (UINT8 *)pInfo);
+ if (ret == 0)
+ {
+ /* if there isn't any log in RAM, try to parse flash log */
+ if (validInfoNum == 0)
+ {
+ /* if it's a valid information? */
+ ret = strncmp((char*)pInfo->m_label, HAL_EXCEPTION_LABEL, strlen(HAL_EXCEPTION_LABEL));
+ if (ret == 0)
+ {
+ /* print log string */
+ halExcep_PrintInfoRamLog(pInfo);
+ }
+ }
+
+ /* Update index and store it */
+ s_infoItemIndex = pInfo->m_index + 1;
+ HAL_EXCEPTION_RAM_LOG_INDEX = s_infoItemIndex;
+
+ zOss_Memcpy((VOID*)(&s_pAssertInfo[pInfo->m_index&(HAL_EXCEPTION_INFO_ITEMS_NUM-1)]), (VOID*)pInfo, sizeof(T_HalAssert_Info));
+ }
+ zOss_Free((VOID*)pInfo);
+ }
+
+ return;
+}
+
+
+/*******************************************************************************
+ * Function: halExcep_GenerateLog
+ * Description: generate log string according to excetion information.
+ * Parameters:
+
+ * Input:
+ * pInfo:exception information.
+ * Output:
+ * strLog: log string.
+ * Returns:
+ * length of strLog
+ * Others:
+ ******************************************************************************/
+static SINT32 halExcep_GenerateLog(CHAR *strLog, T_HalAssert_Info *pInfo)
+{
+ if (strLog == NULL || pInfo == NULL)
+ {
+ return(DRV_ERR_INVALID_PARAM);
+ }
+ return((SINT32)sprintf((char*)strLog, HAL_EXCEPTION_LOG_FORMAT, \
+ pInfo->m_index, \
+ pInfo->m_expression, \
+ pInfo->m_fileName, \
+ pInfo->m_funcName, \
+ pInfo->m_lineNum, \
+ pInfo->m_sp, \
+ pInfo->m_cpsr, \
+ pInfo->m_spsr, \
+ pInfo->m_pid, \
+ pInfo->m_threadName));
+}
+
+
+#ifdef _USE_DATACARD
+/********************************************************************************
+ * Function: zDrvExcep_ShowDcAssertLed
+ * Description: show LED on data card for exception.
+ * Parameters:
+ * Input: None
+ * Output: None
+ * Returns:DRV_SUCCESS
+ * Others:
+*******************************************************************************/
+VOID zDrvExcep_ShowDcAssertLed(VOID)
+{
+ (VOID)zDrvLED_Set(LED_WHITE);
+ return;
+}
+#endif
+
+#endif
+/********************************************************************************
+ * Function: zDrvExcep_Initiate
+ * Description:initialize exception for hal_init.c
+ * Parameters:
+ * Input: None
+ * Output: None
+ * Returns:DRV_SUCCESS
+ * Others:
+*******************************************************************************/
+SINT32 zDrvExcep_Initiate(VOID)
+{
+ #if 0
+ SINT32 i = 0, offset = 0;
+ T_HalAssert_Info *pInfo = NULL;
+
+ if (s_bExcepInitialized)
+ {
+ return(DRV_SUCCESS);
+ }
+
+ /* information index */
+ s_infoItemIndex = HAL_EXCEPTION_RAM_LOG_INDEX;
+
+ /* all pointers to RAM space of information */
+ for (i = 0; i < HAL_EXCEPTION_INFO_ITEMS_NUM; i++)
+ {
+ s_aAssertInfo[i] = (T_HalAssert_Info*)(HAL_EXCEPTION_RAM_LOG_ADDRESS + offset);
+
+ /* make sure that all strings are legal */
+ pInfo = s_aAssertInfo[i];
+ pInfo->m_expression[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ pInfo->m_fileName[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ pInfo->m_funcName[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ pInfo->m_threadName[HAL_EXCEPTION_MAX_NAME_LEN - 1] = '\0';
+ offset += sizeof(T_HalAssert_Info);
+ }
+
+ halExcep_Info2RamLog();
+ s_bExcepInitialized = TRUE;
+ #endif
+ return(DRV_SUCCESS);
+}
+
+
diff --git a/cp/ps/driver/src/public/src/trap/makefile b/cp/ps/driver/src/public/src/trap/makefile
new file mode 100644
index 0000000..5759c77
--- /dev/null
+++ b/cp/ps/driver/src/public/src/trap/makefile
@@ -0,0 +1,50 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2001,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhalÄ£¿é
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2008/11/17 V1.0 huji create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+#===============================================
+# ·¾¶ÉèÖÃ
+#===============================================
+_MDL_NAME = trap
+
+_MDL_SRC_PATH = $(PUBLIC_SRC_PATH)/$(_MDL_NAME)
+_MDL_INC_PATH = $(PUBLIC_INC_PATH)
+_MDL_OBJ_PATH = $(PUBLIC_OBJ_PATH)/$(_MDL_NAME)
+
+#============================================
+#¸÷Ä£¿éÒÀÀµ¹«¹²Í·ÎļþÉèÖÃ
+#============================================
+INCLUDE += $(_EXTERNAL_INC_PATH) \
+ -I$(_MDL_INC_PATH)
+
+#============================================
+#×ÓϵͳÀ©Õ¹¶¨Òå
+#============================================
+DEFINE +=
+
+#============================================
+#Ä£¿éÎļþÐÅÏ¢
+#============================================
+_C_SOURCE = $(wildcard $(_MDL_SRC_PATH)/*.c)
+
+_s_SOURCE =
+
+_S_SOURCE =
+
+#============================================
+# ±àÒë¹æÔò
+#============================================
+
+include $(FRAME_PATH)/rules/mdl_rules.mk
+
diff --git a/cp/ps/driver/src/public/ws/makefile b/cp/ps/driver/src/public/ws/makefile
new file mode 100644
index 0000000..1bc9ddf
--- /dev/null
+++ b/cp/ps/driver/src/public/ws/makefile
@@ -0,0 +1,168 @@
+#***********************************************************************
+# °æÈ¨ËùÓÐ (C)2001,ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#
+# ÎļþÃû³Æ£º makefile
+# Îļþ±êʶ£º ±àÒëhal public
+# ÄÚÈÝÕªÒª£º
+#
+# ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+# ---------------------------------------------------------------------
+# 2008/11/17 V1.0 huji create
+#***********************************************************************/
+
+include $(PRJ_PATH)/config/project.mk
+include $(DRV_PATH)/ws/drv_cfg.mk
+
+
+#===============================================
+#
+#===============================================
+_SUBSYS_NAME = public
+
+#_SUBSYS_LIB_PATH = $(DRV_PATH)/lib/$(PRJ_NAME)/$(VERSION_TYPE)/$(ARMCORE_TYPE)/$(FLAVOR)
+_SUBSYS_LIB_PATH = $(DRV_LIB_PATH)
+
+export PUBLIC_SRC_PATH = $(PUBLIC_PATH)/src
+export PUBLIC_INC_PATH = $(PUBLIC_PATH)/inc -I$(DRV_PATH)/src/inc
+export PUBLIC_OBJ_PATH = $(DRV_OBJ_PATH)
+
+#===============================================
+# ring
+#===============================================
+ring:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/ring
+ringclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/ring clean
+
+_ALL_MDLS += ring
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/ring/*.o)
+
+
+#===============================================
+# trap
+#===============================================
+
+trap:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/trap
+trapclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/trap clean
+
+_ALL_MDLS += trap
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/trap/*.o)
+
+#===============================================
+# ramlog
+#===============================================
+
+ramlog:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/ramlog
+ramlogclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/ramlog clean
+
+_ALL_MDLS += ramlog
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/ramlog/*.o)
+
+#===============================================
+# config
+#===============================================
+
+config:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/config
+configclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/config clean
+
+_ALL_MDLS += config
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/config/*.o)
+
+#===============================================
+# qalloc
+#===============================================
+
+qalloc:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/qalloc
+qallocclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/qalloc clean
+
+#_ALL_MDLS += qalloc
+#_ALL_OBJECTS += $(wildcard $(OBJ_PATH)/drv/hal/qalloc/*.o)
+
+#===============================================
+# queue
+#===============================================
+
+queue:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/queue
+queueclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/queue clean
+
+_ALL_MDLS += queue
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/queue/*.o)
+
+#===============================================
+# requestQueue
+#===============================================
+
+requestQueue:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/requestQueue
+requestQueueclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/requestQueue clean
+
+#_ALL_MDLS += requestQueue
+#_ALL_OBJECTS += $(wildcard $(OBJ_PATH)/drv/hal/requestQueue/*.o)
+
+#===============================================
+# ioRequest
+#===============================================
+
+ioRequest:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/ioRequest
+ioRequestclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/ioRequest clean
+
+#_ALL_MDLS += ioRequest
+#_ALL_OBJECTS += $(wildcard $(OBJ_PATH)/drv/hal/ioRequest/*.o)
+
+#===============================================
+# iodev
+#===============================================
+
+iodev:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/iodev
+iodevclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/iodev clean
+
+_ALL_MDLS += iodev
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/iodev/*.o)
+
+#===============================================
+# random
+#===============================================
+
+
+#===============================================
+# debug
+#===============================================
+
+debug:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/debug
+debugclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/debug clean
+
+_ALL_MDLS += debug
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/debug/*.o)
+
+#===============================================
+# hisr
+#===============================================
+
+hisr:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/hisr
+hisrclean:
+ @$(GNUMAKE) --no-print-directory $(MAKEOPTS) -C $(PUBLIC_SRC_PATH)/hisr clean
+
+_ALL_MDLS += hisr
+_ALL_OBJECTS += $(wildcard $(PUBLIC_OBJ_PATH)/hisr/*.o)
+#============================================
+# ±àÒë¹æÔò
+#============================================
+include $(FRAME_PATH)/rules/lib_rules.mk