142 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			142 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#ifndef PLC_LIB_INTERNAL_H
 | 
						|
#define PLC_LIB_INTERNAL_H
 | 
						|
 | 
						|
/* os shim includes */
 | 
						|
#include "os_types.h"
 | 
						|
#include "os_lock.h"
 | 
						|
#include "os_event.h"
 | 
						|
#include "os_task.h"
 | 
						|
 | 
						|
/* common includes */
 | 
						|
#include "iot_queue.h"
 | 
						|
#include "iot_mem_pool.h"
 | 
						|
#include "iot_ipc.h"
 | 
						|
#include "iot_plc_api.h"
 | 
						|
#include "iot_task.h"
 | 
						|
#include "iot_pkt_api.h"
 | 
						|
#include "iot_config.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#if PLC_SUPPORT_CCO_ROLE
 | 
						|
 | 
						|
/* define plc lib message pool size */
 | 
						|
#define PLC_LIB_MSG_POOL_SIZE       255
 | 
						|
 | 
						|
#else
 | 
						|
 | 
						|
/* define plc lib message pool size */
 | 
						|
#define PLC_LIB_MSG_POOL_SIZE       128
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
/* define the plc lib message queue count and priorities, the higer the priority
 | 
						|
 * the lower the queue number.
 | 
						|
 */
 | 
						|
#define PLC_LIB_MSG_QUEUE_HP        0
 | 
						|
#define PLC_LIB_MSG_QUEUE_MAX_PRIO  1
 | 
						|
 | 
						|
/* define max number of concurrent app supported */
 | 
						|
#define PLC_LIB_APP_SUPP_MAX        4
 | 
						|
 | 
						|
/* define plc lib internal message id */
 | 
						|
#define PLC_LIB_MSG_IPC_EVENT       1
 | 
						|
 | 
						|
/* default request id */
 | 
						|
#define PLC_LIB_REQ_ID_DEFAULT      0
 | 
						|
 | 
						|
/* plc lib internal message */
 | 
						|
typedef struct _plc_lib_msg {
 | 
						|
    /* iot task message */
 | 
						|
    iot_task_msg_t  task_msg;
 | 
						|
    /* pointer to message data */
 | 
						|
    void            *data;
 | 
						|
} plc_lib_msg_t;
 | 
						|
 | 
						|
/* plc lib gobal variable */
 | 
						|
typedef struct _plc_lib_global {
 | 
						|
    /* plc lib task configuration */
 | 
						|
    iot_task_config_t   task_cfg;
 | 
						|
    /* plc lib task handle */
 | 
						|
    iot_task_h          task_h;
 | 
						|
    /* ipc handler to communicate with plc stack */
 | 
						|
    iot_ipc_h           ipc_h;
 | 
						|
    /* lock to protect the app array */
 | 
						|
    os_mutex_h          lock;
 | 
						|
    /* app info array */
 | 
						|
    iot_plc_app_t       app[PLC_LIB_APP_SUPP_MAX];
 | 
						|
    /* device running mode */
 | 
						|
    uint8_t             proto;
 | 
						|
    /* device running role */
 | 
						|
    uint8_t             client;
 | 
						|
} plc_lib_global_t;
 | 
						|
 | 
						|
extern plc_lib_global_t *p_plc_lib;
 | 
						|
 | 
						|
extern iot_ipc_addr_t plc_stack_addr;
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief plc_lib_find_app() - find plc app info by app id
 | 
						|
 * @param app_id:     application id to be searched
 | 
						|
 *
 | 
						|
 * @return:
 | 
						|
 *  NULL        -- for failure case
 | 
						|
 *  othersie    -- plc application info pointer
 | 
						|
 */
 | 
						|
iot_plc_app_t *plc_lib_find_app(uint8_t app_id);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief plc_lib_find_free_app() - find free plc app slot
 | 
						|
 *
 | 
						|
 * @return:
 | 
						|
 *  NULL        -- for failure case
 | 
						|
 *  othersie    -- free plc application slot pointer
 | 
						|
 */
 | 
						|
iot_plc_app_t *plc_lib_find_free_app();
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief plc_lib_prep_msg() - prepare plc lib message header a iot pkt
 | 
						|
 * @param pkt:        pointer to the packet
 | 
						|
 * @param app_id:     application id of the packet
 | 
						|
 * @param msg_id:     msg id of the packet
 | 
						|
 * @param req_id:     request id
 | 
						|
 * @return:
 | 
						|
 *  pointer to the buffer right after the plc lib message header
 | 
						|
 */
 | 
						|
uint8_t *plc_lib_prep_msg(iot_pkt_t *buf, uint8_t app_id,
 | 
						|
    uint8_t msg_id, uint8_t req_id);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_plc_query() - query plc info
 | 
						|
 * @param handle:       plc application handler
 | 
						|
 * @param req_id:       request id, the request id will be transferred back to
 | 
						|
 *                      app in the report. app can define the mean of each id
 | 
						|
 *                      itself.
 | 
						|
 * @param msg_id:       message id of the info to be queried.
 | 
						|
 *                      see IOT_PLC_MSG_XXX.
 | 
						|
 */
 | 
						|
void iot_plc_query(iot_plc_app_h handle, uint8_t req_id, uint8_t msg_id);
 | 
						|
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif /* PLC_LIB_INTERNAL_H */ |