xref: /utopia/UTPA2-700.0.x/modules/msos/utopia_core/ucos/utopia.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi #include "utopia_private.h"
2*53ee8cc1Swenshuai.xi #include <stdio.h>
3*53ee8cc1Swenshuai.xi #include "utopia.h"
4*53ee8cc1Swenshuai.xi #include "utopia_module.h"
5*53ee8cc1Swenshuai.xi #include "utopia_dapi.h"
6*53ee8cc1Swenshuai.xi #include "string.h"
7*53ee8cc1Swenshuai.xi #include "MsOS.h"
8*53ee8cc1Swenshuai.xi #include "MsCommon.h"
9*53ee8cc1Swenshuai.xi 
10*53ee8cc1Swenshuai.xi //Global Variable===================================================
11*53ee8cc1Swenshuai.xi UTOPIA_PRIVATE* psUtopiaPrivate;
12*53ee8cc1Swenshuai.xi 
13*53ee8cc1Swenshuai.xi char moduleNames[][40] = {
14*53ee8cc1Swenshuai.xi #define PREFIX(MODULE) "MODULE_"#MODULE,
15*53ee8cc1Swenshuai.xi 	INCLUDED_MODULE
16*53ee8cc1Swenshuai.xi #undef PREFIX
17*53ee8cc1Swenshuai.xi };
18*53ee8cc1Swenshuai.xi 
19*53ee8cc1Swenshuai.xi char rpoolNames[][40] = {
20*53ee8cc1Swenshuai.xi #define PREFIX(MODULE) "RPOOL_"#MODULE,
21*53ee8cc1Swenshuai.xi 	INCLUDED_MODULE
22*53ee8cc1Swenshuai.xi #undef PREFIX
23*53ee8cc1Swenshuai.xi };
24*53ee8cc1Swenshuai.xi 
25*53ee8cc1Swenshuai.xi char ResourceNames[][40] = {
26*53ee8cc1Swenshuai.xi #define PREFIX(MODULE) "RESOURCE_"#MODULE,
27*53ee8cc1Swenshuai.xi 	INCLUDED_MODULE
28*53ee8cc1Swenshuai.xi #undef PREFIX
29*53ee8cc1Swenshuai.xi };
30*53ee8cc1Swenshuai.xi 
31*53ee8cc1Swenshuai.xi void BDMARegisterToUtopia(FUtopiaOpen ModuleType);
32*53ee8cc1Swenshuai.xi #if defined(CHIP_KERES) || defined(CHIP_KIRIN) || defined(CHIP_KANO)
33*53ee8cc1Swenshuai.xi void CPURegisterToUtopia(FUtopiaOpen ModuleType);
34*53ee8cc1Swenshuai.xi void FLASHRegisterToUtopia(FUtopiaOpen ModuleType);
35*53ee8cc1Swenshuai.xi void IRRegisterToUtopia(FUtopiaOpen ModuleType);
36*53ee8cc1Swenshuai.xi void MBXRegisterToUtopia(FUtopiaOpen ModuleType);
37*53ee8cc1Swenshuai.xi void MVOPRegisterToUtopia(FUtopiaOpen ModuleType);
38*53ee8cc1Swenshuai.xi void MSPIRegisterToUtopia(FUtopiaOpen ModuleType);
39*53ee8cc1Swenshuai.xi void PWMRegisterToUtopia(FUtopiaOpen ModuleType);
40*53ee8cc1Swenshuai.xi void PWSRegisterToUtopia(FUtopiaOpen ModuleType);
41*53ee8cc1Swenshuai.xi void RTCRegisterToUtopia(FUtopiaOpen ModuleType);
42*53ee8cc1Swenshuai.xi void SARRegisterToUtopia(FUtopiaOpen ModuleType);
43*53ee8cc1Swenshuai.xi 
44*53ee8cc1Swenshuai.xi #if defined(CHIP_KERES) || defined(CHIP_KIRIN)
45*53ee8cc1Swenshuai.xi void CH34RegisterToUtopia(FUtopiaOpen ModuleType);
46*53ee8cc1Swenshuai.xi void VBIRegisterToUtopia(FUtopiaOpen ModuleType);
47*53ee8cc1Swenshuai.xi #endif
48*53ee8cc1Swenshuai.xi 
49*53ee8cc1Swenshuai.xi void ACERegisterToUtopia(FUtopiaOpen ModuleType);
50*53ee8cc1Swenshuai.xi void DLCRegisterToUtopia(FUtopiaOpen ModuleType);
51*53ee8cc1Swenshuai.xi void DMXRegisterToUtopia(FUtopiaOpen ModuleType);
52*53ee8cc1Swenshuai.xi void GFXRegisterToUtopia(FUtopiaOpen ModuleType);
53*53ee8cc1Swenshuai.xi void GOPRegisterToUtopia(FUtopiaOpen ModuleType);
54*53ee8cc1Swenshuai.xi void PNLRegisterToUtopia(FUtopiaOpen ModuleType);
55*53ee8cc1Swenshuai.xi void XCRegisterToUtopia(FUtopiaOpen ModuleType);
56*53ee8cc1Swenshuai.xi 
57*53ee8cc1Swenshuai.xi void VDEC_EXRegisterToUtopia(FUtopiaOpen ModuleType);
58*53ee8cc1Swenshuai.xi void SYSRegisterToUtopia(FUtopiaOpen ModuleType);
59*53ee8cc1Swenshuai.xi void UARTRegisterToUtopia(FUtopiaOpen ModuleType);
60*53ee8cc1Swenshuai.xi void TVENCODERRegisterToUtopia(FUtopiaOpen ModuleType);
61*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_JPEG_EX
62*53ee8cc1Swenshuai.xi void JPEG_EXRegisterToUtopia(FUtopiaOpen ModuleType);
63*53ee8cc1Swenshuai.xi #endif
64*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_NJPEG_EX
65*53ee8cc1Swenshuai.xi void NJPEG_EXRegisterToUtopia(FUtopiaOpen ModuleType);
66*53ee8cc1Swenshuai.xi #endif
67*53ee8cc1Swenshuai.xi void GPDRegisterToUtopia(FUtopiaOpen ModuleType);
68*53ee8cc1Swenshuai.xi 
69*53ee8cc1Swenshuai.xi void DACRegisterToUtopia(void);
70*53ee8cc1Swenshuai.xi void SEMRegisterToUtopia(void);
71*53ee8cc1Swenshuai.xi void DSCMBRegisterToUtopia(void);
72*53ee8cc1Swenshuai.xi void AESDMARegisterToUtopia(FUtopiaOpen ModuleType);
73*53ee8cc1Swenshuai.xi void ACPRegisterToUtopia(FUtopiaOpen ModuleType);
74*53ee8cc1Swenshuai.xi void HDMITXRegisterToUtopia(FUtopiaOpen ModuleType);
75*53ee8cc1Swenshuai.xi void CECRegisterToUtopia(FUtopiaOpen ModuleType);
76*53ee8cc1Swenshuai.xi 
77*53ee8cc1Swenshuai.xi #endif
78*53ee8cc1Swenshuai.xi 
UtopiaInit()79*53ee8cc1Swenshuai.xi MS_U32 UtopiaInit()
80*53ee8cc1Swenshuai.xi {
81*53ee8cc1Swenshuai.xi 	MS_U32 u32Ret = 0;
82*53ee8cc1Swenshuai.xi 	printf("\033[35m[eCos] UtopiaInit\033[m\n\n");
83*53ee8cc1Swenshuai.xi 
84*53ee8cc1Swenshuai.xi     psUtopiaPrivate = (UTOPIA_PRIVATE*)malloc(sizeof(UTOPIA_PRIVATE));
85*53ee8cc1Swenshuai.xi 	memset(psUtopiaPrivate, 0, sizeof(UTOPIA_PRIVATE));
86*53ee8cc1Swenshuai.xi 	psUtopiaPrivate->u32MutexID = MsOS_CreateMutex(E_MSOS_FIFO, "UtopiaPrivateMutex", MSOS_PROCESS_SHARED);
87*53ee8cc1Swenshuai.xi 
88*53ee8cc1Swenshuai.xi 	MsOS_ObtainMutex(psUtopiaPrivate->u32MutexID, MSOS_WAIT_FOREVER);
89*53ee8cc1Swenshuai.xi 
90*53ee8cc1Swenshuai.xi     /*
91*53ee8cc1Swenshuai.xi      * to avoid weak attribute malfunction in static lib,
92*53ee8cc1Swenshuai.xi      * we explicitly call needed functions
93*53ee8cc1Swenshuai.xi      */
94*53ee8cc1Swenshuai.xi     UTOPIARegisterToUtopia((FUtopiaOpen)MODULE_TYPE_UTOPIA_FULL);
95*53ee8cc1Swenshuai.xi     BDMARegisterToUtopia((FUtopiaOpen)MODULE_TYPE_BDMA_FULL);
96*53ee8cc1Swenshuai.xi 
97*53ee8cc1Swenshuai.xi #if defined(CHIP_KERES) || defined(CHIP_KIRIN) || defined(CHIP_KANO)
98*53ee8cc1Swenshuai.xi     CPURegisterToUtopia((FUtopiaOpen)MODULE_TYPE_CPU_FULL);
99*53ee8cc1Swenshuai.xi     MBXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MBX_FULL);
100*53ee8cc1Swenshuai.xi     SYSRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_SYS_FULL);
101*53ee8cc1Swenshuai.xi     UARTRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_UART_FULL);
102*53ee8cc1Swenshuai.xi #if 0 // Below is not necessary for ucos
103*53ee8cc1Swenshuai.xi     FLASHRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_FLASH_FULL);
104*53ee8cc1Swenshuai.xi     IRRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_IR_FULL);
105*53ee8cc1Swenshuai.xi     MVOPRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MVOP_FULL);
106*53ee8cc1Swenshuai.xi     MSPIRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MSPI_FULL);
107*53ee8cc1Swenshuai.xi     PWMRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_PWM_FULL);
108*53ee8cc1Swenshuai.xi     PWSRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_PWS_FULL);
109*53ee8cc1Swenshuai.xi     RTCRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_RTC_FULL);
110*53ee8cc1Swenshuai.xi     SARRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_SAR_FULL);
111*53ee8cc1Swenshuai.xi     CECRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_CEC_FULL);
112*53ee8cc1Swenshuai.xi     ACERegisterToUtopia((FUtopiaOpen)MODULE_TYPE_ACE_FULL);
113*53ee8cc1Swenshuai.xi     DLCRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_DLC_FULL);
114*53ee8cc1Swenshuai.xi     DMXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_DMX_FULL);
115*53ee8cc1Swenshuai.xi     GFXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_GFX_FULL);
116*53ee8cc1Swenshuai.xi     GOPRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_GOP_FULL);
117*53ee8cc1Swenshuai.xi     PNLRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_PNL_FULL);
118*53ee8cc1Swenshuai.xi     XCRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_XC_FULL);
119*53ee8cc1Swenshuai.xi 
120*53ee8cc1Swenshuai.xi #if defined(CHIP_KERES) || defined(CHIP_KIRIN)
121*53ee8cc1Swenshuai.xi     CH34RegisterToUtopia((FUtopiaOpen)MODULE_TYPE_CH34_FULL);
122*53ee8cc1Swenshuai.xi     VBIRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_VBI_FULL);
123*53ee8cc1Swenshuai.xi #endif
124*53ee8cc1Swenshuai.xi     VDEC_EXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_VDEC_EX_FULL);
125*53ee8cc1Swenshuai.xi     TVENCODERRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_TVENCODER_FULL);
126*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_JPEG_EX
127*53ee8cc1Swenshuai.xi     JPEG_EXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_NJPEG_EX_FULL);
128*53ee8cc1Swenshuai.xi #endif
129*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_NJPEG_EX
130*53ee8cc1Swenshuai.xi     NJPEG_EXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_NJPEG_EX_FULL);
131*53ee8cc1Swenshuai.xi #endif
132*53ee8cc1Swenshuai.xi     GPDRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_GPD_FULL);
133*53ee8cc1Swenshuai.xi 
134*53ee8cc1Swenshuai.xi     DACRegisterToUtopia();
135*53ee8cc1Swenshuai.xi     SEMRegisterToUtopia();
136*53ee8cc1Swenshuai.xi     DSCMBRegisterToUtopia();
137*53ee8cc1Swenshuai.xi     AESDMARegisterToUtopia((FUtopiaOpen)MODULE_TYPE_AESDMA_FULL);
138*53ee8cc1Swenshuai.xi     ACPRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_ACP_FULL);
139*53ee8cc1Swenshuai.xi     HDMITXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_HDMITX_FULL);
140*53ee8cc1Swenshuai.xi #endif
141*53ee8cc1Swenshuai.xi #endif
142*53ee8cc1Swenshuai.xi 
143*53ee8cc1Swenshuai.xi     MsOS_ReleaseMutex(psUtopiaPrivate->u32MutexID);
144*53ee8cc1Swenshuai.xi 
145*53ee8cc1Swenshuai.xi 	return u32Ret;
146*53ee8cc1Swenshuai.xi }
147*53ee8cc1Swenshuai.xi 
UtopiaOpen(MS_U32 u32ModuleID,void ** ppInstanceTmp,MS_U32 u32ModuleVersion,const void * const pAttribute)148*53ee8cc1Swenshuai.xi MS_U32 UtopiaOpen(MS_U32 u32ModuleID, void** ppInstanceTmp
149*53ee8cc1Swenshuai.xi 		, MS_U32 u32ModuleVersion, const void* const pAttribute)
150*53ee8cc1Swenshuai.xi {
151*53ee8cc1Swenshuai.xi     UTOPIA_MODULE* psUtopiaModule = psUtopiaPrivate->psModuleHead;
152*53ee8cc1Swenshuai.xi     UTOPIA_INSTANCE** ppInstance = (UTOPIA_INSTANCE**)ppInstanceTmp;
153*53ee8cc1Swenshuai.xi 
154*53ee8cc1Swenshuai.xi     while(psUtopiaModule != NULL)
155*53ee8cc1Swenshuai.xi     {
156*53ee8cc1Swenshuai.xi         if(psUtopiaModule->u32ModuleID == u32ModuleID)
157*53ee8cc1Swenshuai.xi         {
158*53ee8cc1Swenshuai.xi             int ret = psUtopiaModule->fpOpen((void**)ppInstance, pAttribute);
159*53ee8cc1Swenshuai.xi 
160*53ee8cc1Swenshuai.xi             if(ret)
161*53ee8cc1Swenshuai.xi             {
162*53ee8cc1Swenshuai.xi                 printf("[utopia error] fail to create instance\n");
163*53ee8cc1Swenshuai.xi                 return ret;
164*53ee8cc1Swenshuai.xi             }
165*53ee8cc1Swenshuai.xi 
166*53ee8cc1Swenshuai.xi             (*ppInstance)->psModule = psUtopiaModule;
167*53ee8cc1Swenshuai.xi 			(*ppInstance)->u32AppRequireModuleVersion = u32ModuleVersion;
168*53ee8cc1Swenshuai.xi             return ret;
169*53ee8cc1Swenshuai.xi         }
170*53ee8cc1Swenshuai.xi         psUtopiaModule = psUtopiaModule->psNext;
171*53ee8cc1Swenshuai.xi     }
172*53ee8cc1Swenshuai.xi 
173*53ee8cc1Swenshuai.xi 	printf("\033[35mFunction = %s, Line = %d, UtopiaOpen strange failed\033[m\n", __FUNCTION__, __LINE__);
174*53ee8cc1Swenshuai.xi 
175*53ee8cc1Swenshuai.xi 	return UTOPIA_STATUS_FAIL;
176*53ee8cc1Swenshuai.xi }
177*53ee8cc1Swenshuai.xi 
UtopiaIoctl(void * pInstanceTmp,MS_U32 u32Cmd,void * const pArgs)178*53ee8cc1Swenshuai.xi MS_U32 UtopiaIoctl(void* pInstanceTmp, MS_U32 u32Cmd, void* const pArgs)
179*53ee8cc1Swenshuai.xi {
180*53ee8cc1Swenshuai.xi 	UTOPIA_INSTANCE* pInstance = (UTOPIA_INSTANCE*)pInstanceTmp;
181*53ee8cc1Swenshuai.xi 	/* check param. */
182*53ee8cc1Swenshuai.xi 	if (pInstance == NULL)
183*53ee8cc1Swenshuai.xi 	{
184*53ee8cc1Swenshuai.xi 		printf("[utopia error] instance pointer should not be null\n");
185*53ee8cc1Swenshuai.xi 		return UTOPIA_STATUS_FAIL;
186*53ee8cc1Swenshuai.xi 	}
187*53ee8cc1Swenshuai.xi 
188*53ee8cc1Swenshuai.xi 	return TO_INSTANCE_PTR(pInstance)->psModule->fpIoctl(pInstance, u32Cmd, pArgs);
189*53ee8cc1Swenshuai.xi }
190*53ee8cc1Swenshuai.xi 
UtopiaClose(void * pInstantTmp)191*53ee8cc1Swenshuai.xi MS_U32 UtopiaClose(void* pInstantTmp)
192*53ee8cc1Swenshuai.xi {
193*53ee8cc1Swenshuai.xi     UTOPIA_INSTANCE* pInstant = (UTOPIA_INSTANCE*)pInstantTmp;
194*53ee8cc1Swenshuai.xi 
195*53ee8cc1Swenshuai.xi 	printf("\n[utopia info] close module id: %s\n",
196*53ee8cc1Swenshuai.xi 			moduleNames[pInstant->psModule->u32ModuleID]);
197*53ee8cc1Swenshuai.xi 
198*53ee8cc1Swenshuai.xi     UTOPIA_MODULE* psUtopiaModule = psUtopiaPrivate->psModuleHead;
199*53ee8cc1Swenshuai.xi     while(psUtopiaModule != NULL)
200*53ee8cc1Swenshuai.xi     {
201*53ee8cc1Swenshuai.xi         if(psUtopiaModule->u32ModuleID == pInstant->psModule->u32ModuleID)
202*53ee8cc1Swenshuai.xi         {
203*53ee8cc1Swenshuai.xi             return psUtopiaModule->fpClose(pInstant);
204*53ee8cc1Swenshuai.xi         }
205*53ee8cc1Swenshuai.xi         psUtopiaModule = psUtopiaModule->psNext;
206*53ee8cc1Swenshuai.xi     }
207*53ee8cc1Swenshuai.xi 	return 0;
208*53ee8cc1Swenshuai.xi }
209