xref: /utopia/UTPA2-700.0.x/modules/mbx/drv/mbx/api_mbx/mbx.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 #include "MsTypes.h"
2 #include "utopia.h"
3 #include <stdio.h>
4 #include <string.h>
5 #include "drvMBX.h"
6 //#include "apiMBX_St.h"
7 #include "mbx.h"
8 #include "utopia_dapi.h"
9 #include "apiMBX.h"
10 #include "MsOS.h"
11 #include "ULog.h"
12 
13 #define TAG_MBX "MBX"
14 
15 enum
16 {
17     MBX_POOL_ID_MIU0=0
18 } eMBXPoolID;
19 
MBXRegisterToUtopia(FUtopiaOpen ModuleType)20 void MBXRegisterToUtopia(FUtopiaOpen ModuleType)
21 {
22     // 1. deal with module
23     // 1. deal with module
24     void* pUtopiaModule = NULL;
25 	UtopiaModuleCreate(MODULE_MBX, 8, &pUtopiaModule);
26     UtopiaModuleRegister(pUtopiaModule);
27 	UtopiaModuleSetupFunctionPtr(pUtopiaModule, (FUtopiaOpen)MBXOpen, (FUtopiaClose)MBXClose, (FUtopiaIOctl)MBXIoctl);
28 
29     // 2. deal with resource
30 
31 	// 2. deal with resource
32     void* psResource = NULL;
33 	UtopiaModuleAddResourceStart(pUtopiaModule, MBX_POOL_ID_MIU0);
34     UtopiaResourceCreate("MBX", sizeof(MBX_RESOURCE_PRIVATE), &psResource);
35     UtopiaResourceRegister(pUtopiaModule, psResource, MBX_POOL_ID_MIU0);
36 	UtopiaModuleAddResourceEnd(pUtopiaModule, MBX_POOL_ID_MIU0);
37 }
38 
39 
40 
41 
MBXOpen(void ** ppInstance,MS_U32 u32ModuleVersion,void * pAttribute)42 MS_U32 MBXOpen(void** ppInstance, MS_U32 u32ModuleVersion, void* pAttribute)
43 {
44     MBX_INSTANT_PRIVATE *pMbxPri = NULL;
45 	UtopiaInstanceCreate(sizeof(MBX_INSTANT_PRIVATE), ppInstance);
46     UtopiaInstanceGetPrivate(*ppInstance, (void**)&pMbxPri);
47 
48 	pMbxPri->fpRegisterMSGWithCallBack = MApi_MBX_RegisterMSGWithCallBack;
49 	pMbxPri->fpRegisterMSG = MApi_MBX_RegisterMSG;
50 	pMbxPri->fpSendMsg = MApi_MBX_SendMsg;
51 	pMbxPri->fpRecvMsg = MApi_MBX_RecvMsg;
52 	pMbxPri->fpEnable = MApi_MBX_Enable;
53 	pMbxPri->fpQueryDynamicClass = MApi_MBX_QueryDynamicClass;
54 
55 
56 	MBX_INSTANT_ATTRIBUTE* pMbxAttribue = (MBX_INSTANT_ATTRIBUTE*) pAttribute;
57 
58 	MApi_MBX_Init(pMbxAttribue->eHKCPU, pMbxAttribue->eHostRole, pMbxAttribue->u32TimeoutMillSecs);
59 
60 	return TRUE;
61 }
62 
63 
64 
65 // FIXME: why static?
MBXIoctl(void ** pInstance,MS_U32 u32Cmd,MS_U32 * pu32Args)66 MS_U32 MBXIoctl(void** pInstance, MS_U32 u32Cmd, MS_U32* pu32Args)
67 {
68 
69     MBX_INSTANT_PRIVATE* psMbxInstPri ;
70 	void* pResource = NULL;
71 	void* pModule = NULL;
72 
73 	UtopiaInstanceGetPrivate(pInstance, (void*)&psMbxInstPri);
74 	UtopiaInstanceGetModule(pInstance, &pModule);
75 	MBX_RESOURCE_PRIVATE *pMbxResPri = (MBX_RESOURCE_PRIVATE *) pu32Args;
76 
77 
78     switch(u32Cmd)
79     {
80 		case MDrv_CMD_MBX_RegisterMSG:
81 			 if(UtopiaResourceObtain(pModule, MBX_POOL_ID_MIU0, &pResource) != 0)
82              {
83                     ULOGE(TAG_MBX, "UtopiaResourceObtainToInstant fail\n");
84 		            return UTOPIA_STATUS_ERR_NOT_AVAIL;
85              }
86 
87 			psMbxInstPri->fpRegisterMSG(pMbxResPri->privateRegisterMSG.eMsgClass,
88 								pMbxResPri->privateRegisterMSG.u16MsgQueueSize);
89 			UtopiaResourceRelease(pResource);
90 			break;
91 		case MDrv_CMD_MBX_RegisterMSGWithCallBack:
92 			if(UtopiaResourceObtain(pModule, MBX_POOL_ID_MIU0, &pResource) != 0)
93              {
94                     ULOGE(TAG_MBX, "UtopiaResourceObtainToInstant fail\n");
95 		            return UTOPIA_STATUS_ERR_NOT_AVAIL;
96              }
97 
98 			psMbxInstPri->fpRegisterMSGWithCallBack(pMbxResPri->privateRegisterMSGWithCallBack.eMsgClass,
99 								pMbxResPri->privateRegisterMSGWithCallBack.u16MsgQueueSize,
100 								pMbxResPri->privateRegisterMSGWithCallBack.notifier);
101 			UtopiaResourceRelease(pResource);
102 			break;
103 		case MDrv_CMD_MBX_SendMsg:
104 			if(UtopiaResourceObtain(pModule, MBX_POOL_ID_MIU0, &pResource) != 0)
105              {
106                     ULOGE(TAG_MBX, "UtopiaResourceObtainToInstant fail\n");
107 		            return UTOPIA_STATUS_ERR_NOT_AVAIL;
108              }
109 
110 			psMbxInstPri->fpSendMsg(pMbxResPri->privateSendMsg.pMsg);
111 			UtopiaResourceRelease(pResource);
112 			break;
113 		case MDrv_CMD_MBX_RecvMsg:
114 			if(UtopiaResourceObtain(pModule, MBX_POOL_ID_MIU0, &pResource) != 0)
115              {
116                     ULOGE(TAG_MBX, "UtopiaResourceObtainToInstant fail\n");
117 		            return UTOPIA_STATUS_ERR_NOT_AVAIL;
118              }
119 
120 			psMbxInstPri->fpRecvMsg(pMbxResPri->privateRecvMsg.eTargetClass,
121 									pMbxResPri->privateRecvMsg.pMsg,
122 									pMbxResPri->privateRecvMsg.u32WaitMillSecs,
123 									pMbxResPri->privateRecvMsg.u32Flag);
124 			UtopiaResourceRelease(pResource);
125 			break;
126 		case MDrv_CMD_MBX_Enable:
127 			if(UtopiaResourceObtain(pModule, MBX_POOL_ID_MIU0, &pResource) != 0)
128              {
129                     ULOGE(TAG_MBX, "UtopiaResourceObtainToInstant fail\n");
130 		            return UTOPIA_STATUS_ERR_NOT_AVAIL;
131              }
132 
133 			ULOGD(TAG_MBX, "==Doyle== %s, bEnable=0x%x\n", __FUNCTION__, pMbxResPri->privateEnable.bEnable);
134 			psMbxInstPri->fpEnable(pMbxResPri->privateEnable.bEnable);
135 
136 			UtopiaResourceRelease(pResource);
137 			break;
138 		case MDrv_CMD_MBX_QueryClass:
139 			if(UtopiaResourceObtain(pModule, MBX_POOL_ID_MIU0, &pResource) != 0)
140              {
141                     ULOGE(TAG_MBX, "UtopiaResourceObtainToInstant fail\n");
142 		            return UTOPIA_STATUS_ERR_NOT_AVAIL;
143              }
144 
145 			psMbxInstPri->fpQueryDynamicClass(pMbxResPri->privateQClass.eRoleID,
146 											  pMbxResPri->privateQClass.name,
147 											  &pMbxResPri->privateQClass.mbx_class);
148 
149 			UtopiaResourceRelease(pResource);
150 			break;
151         default:
152             break;
153     };
154 
155 	return 1; // FIXME: error code
156 }
157 
158 
MBXClose(void ** pInstance)159 MS_U32 MBXClose(void** pInstance)
160 {
161 	UtopiaInstanceDelete(pInstance);
162 	return TRUE;
163 }
164 
165