You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LiteOS-Reading/文豪/trace/pipeline/trace_pipeline.c

157 lines
6.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: LiteOS Trace Pipeline Implementation
* Author: Huawei LiteOS Team
* Create: 2020-03-31
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
#include "trace_pipeline.h"
#include "trace_tlv.h"
#include "los_trace_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//·ÀÖ¹»º³åÇøÒç³ö//
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_pipeSpin); //³õʼ»¯Ò»¸ö×ÔÐýËø//
#define PIPE_LOCK(state) LOS_SpinLockSave(&g_pipeSpin, &(state)) //¶Ô×ÔÐýËø¼ÓËø²Ù×÷//
#define PIPE_UNLOCK(state) LOS_SpinUnlockRestore(&g_pipeSpin, (state)) //¶Ô×ÔÐýËø½âËø²Ù×÷//
STATIC TlvTable g_traceTlvTblNotify[] = { //¶¨Òå½á¹¹ÌåµÄ³ÉÔ±±äÁ¿ÀàÐͺʹóС//
{ CMD, LOS_OFF_SET_OF(TraceNotifyFrame, cmd), sizeof(UINT32) },
{ PARAMS, LOS_OFF_SET_OF(TraceNotifyFrame, param), sizeof(UINT32) },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable g_traceTlvTblHead[] = { //¶¨Òå½á¹¹ÌåµÄ³ÉÔ±±äÁ¿ÀàÐͺʹóС//
{ ENDIAN, LOS_OFF_SET_OF(TraceBaseHeaderInfo, bigLittleEndian), sizeof(UINT32) },
{ VERSION, LOS_OFF_SET_OF(TraceBaseHeaderInfo, version), sizeof(UINT32) },
{ CLOCK_FREQ, LOS_OFF_SET_OF(TraceBaseHeaderInfo, clockFreq), sizeof(UINT32) },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable g_traceTlvTblObj[] = { //¶¨Òå½á¹¹ÌåµÄ³ÉÔ±±äÁ¿ÀàÐÍ¡¢Æ«ÒÆλÖúʹóС//
{ ADDR, LOS_OFF_SET_OF(ObjData, id), sizeof(UINT32) },
{ PRIO, LOS_OFF_SET_OF(ObjData, prio), sizeof(UINT32) },
{ NAME, LOS_OFF_SET_OF(ObjData, name), sizeof(CHAR) * LOSCFG_TRACE_OBJ_MAX_NAME_SIZE },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable g_traceTlvTblEvent[] = { //¶¨Òå½á¹¹ÌåµÄ³ÉÔ±±äÁ¿ÀàÐͺʹóС//
#ifdef LOSCFG_TRACE_FRAME_CORE_MSG
{ CORE, LOS_OFF_SET_OF(TraceEventFrame, core), sizeof(UINT32) },
#endif
{ EVENT_CODE, LOS_OFF_SET_OF(TraceEventFrame, eventType), sizeof(UINT32) },
{ CUR_TIME, LOS_OFF_SET_OF(TraceEventFrame, curTime), sizeof(UINT64) },
#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT
{ EVENT_COUNT, LOS_OFF_SET_OF(TraceEventFrame, eventCount), sizeof(UINT32) },
#endif
{ CUR_TASK, LOS_OFF_SET_OF(TraceEventFrame, curTask), sizeof(UINT32) },
{ IDENTITY, LOS_OFF_SET_OF(TraceEventFrame, identity), sizeof(UINTPTR) },
{ EVENT_PARAMS, LOS_OFF_SET_OF(TraceEventFrame, params), sizeof(UINTPTR) * LOSCFG_TRACE_FRAME_MAX_PARAMS },
{ TRACE_TLV_TYPE_NULL, 0, 0 },
};
STATIC TlvTable *g_traceTlvTbl[] = {
g_traceTlvTblNotify,
g_traceTlvTblHead,
g_traceTlvTblObj,
g_traceTlvTblEvent
};
STATIC UINT32 DefaultPipelineInit(VOID)
{
return LOS_OK;
}
STATIC VOID DefaultDataSend(UINT16 len, UINT8 *data)
{ //½«lenºÍdata²ÎÊý±ê¼ÇΪ"δʹÓÃ"//
(VOID)len; //±ÜÃâ±àÒëÆ÷²úÉú¾¯¸æ//
(VOID)data;
}
STATIC UINT32 DefaultDataReceive(UINT8 *data, UINT32 size, UINT32 timeout)
{
(VOID)data; //½«data¡¢sizeºÍtimeout²ÎÊý±ê¼ÇΪ"δʹÓÃ"//
(VOID)size;
(VOID)timeout;
return LOS_OK;
}
STATIC UINT32 DefaultWait(VOID)
{
return LOS_OK;
}
STATIC TracePipelineOps g_defaultOps = {
.init = DefaultPipelineInit,
.dataSend = DefaultDataSend,
.dataRecv = DefaultDataReceive,
.wait = DefaultWait,
};
STATIC const TracePipelineOps *g_tracePipelineOps = &g_defaultOps;
VOID OsTracePipelineReg(const TracePipelineOps *ops)
{
g_tracePipelineOps = ops; //ÓÃÓÚ×¢²áÒ»¸öTracePipelineOps½á¹¹ÌåÖ¸Õë//
}
VOID OsTraceDataSend(UINT8 type, UINT16 len, UINT8 *data) //ÓÃÓÚ·¢ËÍ×·×ÙÊý¾Ý//
{
UINT32 intSave;
UINT8 outBuf[LOSCFG_TRACE_TLV_BUF_SIZE] = {0};
if ((type > TRACE_MSG_MAX) || (len > LOSCFG_TRACE_TLV_BUF_SIZE)) { //ÊäÈë²ÎÊýµÄºÏ·¨ÐÔ¼ì²é//
return;
}
//¶ÔÊý¾Ý½øÐбàÂë//
len = OsTraceDataEncode(type, g_traceTlvTbl[type], data, &outBuf[0], sizeof(outBuf));
PIPE_LOCK(intSave); //»ñÈ¡¹ÜµÀËø£¬·ÀÖ¹¶àÏ̲߳¢·¢·ÃÎÊ//
g_tracePipelineOps->dataSend(len, &outBuf[0]); //·¢ËͱàÂëºóµÄÊý¾Ý//
PIPE_UNLOCK(intSave); //ÊͷŹܵÀËø//
}
UINT32 OsTraceDataRecv(UINT8 *data, UINT32 size, UINT32 timeout) //ÓÃÓÚ½ÓÊÕ×·×ÙÊý¾Ý//
{
return g_tracePipelineOps->dataRecv(data, size, timeout);
}
UINT32 OsTraceDataWait(VOID) //ÓÃÓڵȴý×·×ÙÊý¾Ý//
{
return g_tracePipelineOps->wait();
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */