📄 bcc_init.c
字号:
#include "bcc.h"#include "ccparse.h"#include "common.h"#include "rua/include/rua_property.h"#include "dcc/include/dcc.h"#include "rmdef/rmdef.h"#include "rmcore/include/rmcore.h"#define DEBUG ENABLEstatic RMstatus create_bcc_parser (struct bcc *, RMnonAscii *);static void destroy_bcc_parser (struct bcc *);static RMstatus create_cc_fifo (struct bcc *, struct RUA *, struct dcc_context *);static void destroy_cc_fifo (struct bcc *, struct RUA *, struct dcc_context *);static RMstatus connect_fifo_to_mixer (struct bcc *, struct RUA *);static void disconnect_fifo_from_mixer(struct bcc *, struct RUA *);static RMstatus enable_cc_fifo (struct bcc *, struct RUA *);RMstatus bcc_init(struct bcc **ppbcc, RMnonAscii *bcc_filename, struct RUA *pRUA, struct dcc_context *pDCCinfo){ RMstatus status = RM_OK; if (NULL == (*ppbcc = RMMalloc(sizeof **ppbcc))) { RMDBGLOG((ENABLE, "Error: failed to allocate %#010x bytes in system memory.\n", sizeof **ppbcc)); status = RM_FATALOUTOFMEMORY; } else { if (RMFAILED((status = create_bcc_parser(*ppbcc, bcc_filename)))) { RMDBGLOG((ENABLE, "Error: failed to create bcc parser.\n")); } else { if (RMFAILED((status = create_cc_fifo(*ppbcc, pRUA, pDCCinfo)))) { RMDBGLOG((ENABLE, "Error: failed to create cc fifo.\n")); } else { if (RMFAILED((status = connect_fifo_to_mixer(*ppbcc, pRUA)))) { RMDBGLOG((ENABLE, "Error: failed to connect cc fifo to " "consumer mixer.\n")); } else { if (RMFAILED((status = enable_cc_fifo(*ppbcc, pRUA)))) { RMDBGLOG((ENABLE, "Error: failed to enable the " "cc fifo.\n")); } if (RMFAILED(status)) { RMDBGLOG((DEBUG, "Failure detected, disconnecting" "CC fifo from consumer mixer.\n")); disconnect_fifo_from_mixer(*ppbcc, pRUA); } } if (RMFAILED(status)) { RMDBGLOG((DEBUG, "Failure detected, destroying CC fifo.\n")); destroy_cc_fifo(*ppbcc, pRUA, pDCCinfo); } } if (RMFAILED(status)) { RMDBGLOG((DEBUG, "Failure detected, destroying bcc parser.\n")); destroy_bcc_parser(*ppbcc); } } if (RMFAILED(status)) { RMDBGLOG((DEBUG, "Failure detected, freeing BCC memory.\n")); RMFree(*ppbcc); } } return status;}static RMstatus create_bcc_parser(struct bcc *pbcc, RMnonAscii *bcc_filename){ RMstatus status = RM_OK; pbcc->bcc_parser = rmbcc_create(); if (NULL == pbcc->bcc_parser) { RMDBGLOG((ENABLE, "Error: failed to create BCC parser!\n")); status = RM_ERROR; } else { status = rmbcc_open(pbcc->bcc_parser, bcc_filename); if (RMFAILED(status)) { RMDBGLOG((ENABLE, "Error %s: failed to open BCC parser!\n", RMstatusToString(status))); rmbcc_destroy(pbcc->bcc_parser); pbcc->bcc_parser = NULL; } else { RMDBGLOG((ENABLE, "Successfully created and opened BCC parser.\n" "Source file is: '%s'.\n", bcc_filename)); pbcc->CCentry_consumed = TRUE; } } return status;}static void destroy_bcc_parser(struct bcc *pbcc){ if (NULL != pbcc->bcc_parser) { rmbcc_close(pbcc->bcc_parser); rmbcc_destroy(pbcc->bcc_parser); pbcc->bcc_parser = NULL; }}static RMstatus create_cc_fifo(struct bcc *pbcc, struct RUA *pRUA, struct dcc_context *pDCCinfo){ RMstatus status = RM_OK; struct CCFifo_Open_type cc_open; pbcc->ccfifo_id = EMHWLIB_MODULE(CCFifo, 1); cc_open.EntryCount = DEFAULT_CC_FIFO_SIZE; /* get the necessary size */ RUAExchangeProperty(pRUA, pbcc->ccfifo_id, RMCCFifoPropertyID_DRAMSize, &cc_open.EntryCount, sizeof cc_open.EntryCount, &cc_open.UncachedSize, sizeof cc_open.UncachedSize); /* allocate the buffer */ pbcc->ccfifo_buffer = DCCMalloc(pDCCinfo->pDCC, 0, RUA_DRAM_UNCACHED, cc_open.UncachedSize); if (0 == pbcc->ccfifo_buffer) { RMDBGLOG((ENABLE, "Error: could not allocate %#010x bytes in uncached RUA memory.\n", cc_open.UncachedSize)); status = RM_FATALOUTOFMEMORY; } else { cc_open.UncachedAddress = pbcc->ccfifo_buffer; DCCSTCGetModuleId(pDCCinfo->pStcSource, &cc_open.STCModuleId); RMDBGLOG((ENABLE, "Prepared to open the CC fifo:\n" " cc_open.UncachedAddress = %#010x\n" " cc_open.EntryCount = %lu\n" " cc_open.UncachedSize = %lu\n" " cc_open.STCModuleID = %lu\n", cc_open.UncachedAddress, cc_open.EntryCount, cc_open.UncachedSize, cc_open.STCModuleId)); while (RM_PENDING == (status = RUASetProperty(pRUA, pbcc->ccfifo_id, RMCCFifoPropertyID_Open, &cc_open, sizeof cc_open, 0))); if (RMFAILED(status)) { RMDBGLOG((ENABLE, "Error %s: failed to initialize CC fifo #%lu.\n\n", RMstatusToString(status), EMHWLIB_MODULE_INDEX(pbcc->ccfifo_id))); } else { RMDBGLOG((ENABLE, "Successfully initialized CC fifo #%lu.\n", EMHWLIB_MODULE_INDEX(pbcc->ccfifo_id))); } if (RMFAILED(status)) { RMDBGLOG((DEBUG, "Failure detected, freeing CC fifo buffer.\n")); DCCFree(pDCCinfo->pDCC, pbcc->ccfifo_buffer); } } return status;}static void destroy_cc_fifo(struct bcc *pbcc, struct RUA *pRUA, struct dcc_context *pDCCinfo){ while (RUASetProperty(pRUA, pbcc->ccfifo_id, RMCCFifoPropertyID_Close, NULL, 0, 0) == RM_PENDING); DCCFree(pDCCinfo->pDCC, pbcc->ccfifo_buffer);}static RMstatus connect_fifo_to_mixer(struct bcc *pbcc, struct RUA *pRUA){ RMstatus status = RM_OK; RMuint32 mixer_id = EMHWLIB_MODULE(DispMainMixer, 0); while (RM_PENDING == (status = RUASetProperty(pRUA, mixer_id, RMGenericPropertyID_CCFifo, &pbcc->ccfifo_id, sizeof pbcc->ccfifo_id, 0))); if (RMFAILED(status)) { RMDBGLOG((ENABLE, "Error %s: failed to connect CC fifo #%lu to consumer " "mixer #%lu.\n", RMstatusToString(status), EMHWLIB_MODULE_INDEX(pbcc->ccfifo_id), EMHWLIB_MODULE_INDEX(mixer_id) )); } else { RMDBGLOG((ENABLE, "Successfully connected CC fifo #%lu to consumer mixer #%lu.\n", EMHWLIB_MODULE_INDEX(pbcc->ccfifo_id), EMHWLIB_MODULE_INDEX(mixer_id) )); while (RM_PENDING == (status = RUASetProperty(pRUA, mixer_id, RMGenericPropertyID_Validate, NULL, 0, 0))); if (RMFAILED(status)) { RMDBGLOG((ENABLE, "Error %s: failed to validate settings for mixer #%lu.\n", RMstatusToString(status), EMHWLIB_MODULE_INDEX(mixer_id) )); } else { RMDBGLOG((ENABLE, "Successfully validated settings for mixer #%lu.\n", EMHWLIB_MODULE_INDEX(mixer_id) )); } if (RMFAILED(status)) { RMuint32 no_fifo = 0; RMDBGLOG((DEBUG, "Failure detected, disconnecting CC fifo from consumer.\n")); while (RM_PENDING == RUASetProperty(pRUA, mixer_id, RMGenericPropertyID_CCFifo, &no_fifo, sizeof no_fifo, 0)); } } return status;}static void disconnect_fifo_from_mixer(struct bcc *pbcc, struct RUA *pRUA){ RMuint32 mixer_id = EMHWLIB_MODULE(DispMainMixer, 0); RMuint32 no_fifo = 0; while (RM_PENDING == RUASetProperty(pRUA, mixer_id, RMGenericPropertyID_CCFifo, &no_fifo, sizeof no_fifo, 0)); while (RM_PENDING == RUASetProperty(pRUA, mixer_id, RMGenericPropertyID_Validate, NULL, 0, 0));}static RMstatus enable_cc_fifo(struct bcc *pbcc, struct RUA *pRUA){ RMstatus status = RM_OK; RMbool cc_enable = TRUE; while (RM_PENDING == (status = RUASetProperty(pRUA, pbcc->ccfifo_id, RMCCFifoPropertyID_Enable, &cc_enable, sizeof cc_enable, 0))); if (RMFAILED(status)) { RMDBGLOG((ENABLE, "Error %s: failed to enable CC fifo #%lu.\n", RMstatusToString(status), EMHWLIB_MODULE_INDEX(pbcc->ccfifo_id))); } else { RMDBGLOG((ENABLE, "Successfully emabled CC fifo #%lu.\n", EMHWLIB_MODULE_INDEX(pbcc->ccfifo_id))); } return status;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -