1 //#include <nuttx/config.h>
2 #include <stdio.h>
3 //#include "MsTypes.h"
4 //#include "stdlib.h"
5 #include "utopia.h" // for utopia open/ioctl/close
6 #include "utopia_driver_id.h" // for module id
7 #include "MsOS.h" // for MsOS_ObtainMutex test
8 //#include "drvMMIO.h"
9 //#include <string.h>
10 //#include <unistd.h>
11 //#include "drvMIU.h"
12
__aeabi_unwind_cpp_pr1(void)13 void __aeabi_unwind_cpp_pr1(void) {}
__aeabi_unwind_cpp_pr0(void)14 void __aeabi_unwind_cpp_pr0(void) {}
15
16 #define SEM
17 //#define SYS_DMD_VD_MBX
18 //#define CMDQ
19 //#define SYS
20
21 #ifdef SEM
22 #include "main_sem.h"
23 #endif
24 #ifdef SYS_DMD_VD_MBX
25 #endif
26 #ifdef CMDQ
27 #endif
28 #ifdef SYS
29 #include "main_sys.h"
30 #endif
31
32
main(int argc,char * argv[])33 int main(int argc, char *argv[])
34 {
35 unsigned int ret = 0;
36 UtopiaInit();
37
38 void* pInstance = NULL;
39 void* pArgs = NULL;
40
41 #ifdef SEM
42 // SEM
43 ret = UtopiaOpen(MODULE_SEM, &pInstance, 0, NULL);
44 if (!ret)
45 {
46 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
47 }
48 if(pInstance != NULL)
49 {
50 //sleep(5);
51 // try to use ioctl by the instance we got
52 ////////
53 pArgs = malloc(sizeof(SEM_RESETRESOURCE_PARAM));
54
55 ((PSEM_GETRESOURCE_PARAM)(pArgs))->u8SemID = 0x07;
56
57 UtopiaIoctl(pInstance, MDrv_CMD_SEM_Reset_Resource, pArgs);
58 free(pArgs);
59
60 ////////
61 pArgs = malloc(sizeof(SEM_GETRESOURCE_PARAM));
62
63 ((PSEM_GETRESOURCE_PARAM)(pArgs))->u8SemID = 0x07;
64 ((PSEM_GETRESOURCE_PARAM)(pArgs))->u16ResId = 2;
65
66 UtopiaIoctl(pInstance, MDrv_CMD_SEM_Get_Resource, pArgs);
67 free(pArgs);
68
69 /////////
70 /*
71 pArgs = malloc(sizeof(SEM_FREERESOURCE_PARAM));
72
73 ((PSEM_GETRESOURCE_PARAM)(pArgs))->u8SemID = 0x07;
74 ((PSEM_GETRESOURCE_PARAM)(pArgs))->u16ResId = 1;
75
76 UtopiaIoctl(pInstance, MDrv_CMD_SEM_Free_Resource, pArgs);
77 free(pArgs);
78 */
79
80 /////////
81 pArgs = malloc(sizeof(SEM_GETRESOURCEID_PARAM));
82
83 ((PSEM_GETRESOURCEID_PARAM)(pArgs))->u8SemID = 0x07;
84 ((PSEM_GETRESOURCEID_PARAM)(pArgs))->pu16ResId = malloc(sizeof(MS_U16));
85
86 UtopiaIoctl(pInstance, MDrv_CMD_SEM_Get_ResourceID, pArgs);
87 printf("\033[35mFunction = %s, Line = %d, u16ResId is %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, *((PSEM_GETRESOURCEID_PARAM)(pArgs))->pu16ResId); // joe.liu
88 free(pArgs);
89
90 /////////
91 pArgs = malloc(sizeof(MS_U32));
92
93 UtopiaIoctl(pInstance, MDrv_CMD_SEM_Get_Num, pArgs);
94 printf("\033[35mFunction = %s, Line = %d, SEM_MAX_NUM is %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, *((MS_U32 *)(pArgs))); // joe.liu
95 free(pArgs);
96
97
98
99
100
101
102 printf("\n\033[35mFunction = %s, Line = %d, Instance closing\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
103 UtopiaClose(pInstance);
104 }
105 else
106 {
107 printf("\033[35mFunction = %s, Line = %d, No Instance can be closed\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
108 }
109 printf("\n%s, %d\n", __FUNCTION__, __LINE__); // bob.fu
110 #endif
111
112 #ifdef SYS_DMD_VD_MBX
113 // SYS_DMD_VD_MBX
114 ret = UtopiaOpen(MODULE_SYS_DMD_VD_MBX, &pInstance, 0, NULL);
115 if (!ret)
116 {
117 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
118 }
119 if(pInstance != NULL)
120 {
121 sleep(5);
122 printf("\033[35mFunction = %s, Line = %d, Instance closing\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
123 UtopiaClose(pInstance);
124 }
125 else
126 {
127 printf("\033[35mFunction = %s, Line = %d, No Instance can be closed\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
128 }
129 printf("\n%s, %d\n", __FUNCTION__, __LINE__); // bob.fu
130 #endif
131
132 #ifdef CMDQ
133 // CMDQ
134 ret = UtopiaOpen(MODULE_CMDQ, &pInstance, 0, NULL);
135 if (!ret)
136 {
137 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
138 }
139 if(pInstance != NULL)
140 {
141 sleep(5);
142 printf("\033[35mFunction = %s, Line = %d, Instance closing\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
143 UtopiaClose(pInstance);
144 }
145 else
146 {
147 printf("\033[35mFunction = %s, Line = %d, No Instance can be closed\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
148 }
149 printf("\n%s, %d\n", __FUNCTION__, __LINE__); // bob.fu
150 #endif
151
152 #ifdef SYS
153 // SYS
154 ret = UtopiaOpen(MODULE_SYS, &pInstance, 0, NULL);
155 if (!ret)
156 {
157 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
158 }
159 if(pInstance != NULL)
160 {
161 //sleep(5);
162 // try to use ioctl by the instance we got
163 pArgs = malloc(sizeof(int));
164 UtopiaIoctl(pInstance, MDrv_CMD_SYS_GetChipRev, pArgs);
165 printf("\033[35mFunction = %s, Line = %d, ChipRev is %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, *(MS_U8 *)pArgs); // joe.liu
166 free(pArgs);
167
168 pArgs = malloc(sizeof(int));
169 UtopiaIoctl(pInstance, MDrv_CMD_SYS_GetChipID, pArgs);
170 printf("\033[35mFunction = %s, Line = %d, ChipID vaule is %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, *(MS_U16 *)pArgs); // joe.liu
171 free(pArgs);
172
173 pArgs = malloc(10 * sizeof(int));
174 UtopiaIoctl(pInstance, MDrv_CMD_SYS_GetInfo, pArgs);
175 printf("\033[35mFunction = %s, Line = %d, Return address is %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, pArgs); // joe.liu
176 free(pArgs);
177
178 pArgs = malloc(20 * sizeof(int));
179 UtopiaIoctl(pInstance, MDrv_CMD_SYS_GetLibVer, pArgs);
180 printf("\033[35mFunction = %s, Line = %d, Return address is %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, pArgs); // joe.liu
181 free(pArgs);
182
183 printf("\n\033[35mFunction = %s, Line = %d, Instance closing\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
184 UtopiaClose(pInstance);
185 }
186 else
187 {
188 printf("\033[35mFunction = %s, Line = %d, No Instance can be closed\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
189 }
190 printf("\n%s, %d\n", __FUNCTION__, __LINE__); // bob.fu
191 #endif
192
193 /*
194 // test for open second Instance
195 ret = UtopiaOpen(MODULE_CMDQ, &pInstance, 0, NULL);
196 if (!ret)
197 {
198 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
199 }
200 printf("\033[35mFunction = %s, Line = %d\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
201
202 // test for release Instance, then open again
203 UtopiaClose(pInstance);
204 ret = UtopiaOpen(MODULE_CMDQ, &pInstance, 0, NULL);
205 if (!ret)
206 {
207 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
208 }
209 printf("\033[35mFunction = %s, Line = %d\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
210
211 // test for open second Instance
212 ret = UtopiaOpen(MODULE_CMDQ, &pInstance, 0, NULL);
213 if (!ret)
214 {
215 printf("something wrong in UtopiaOpen, error = %d\n", ret); // bob.fu
216 }
217 printf("\033[35mFunction = %s, Line = %d\033[m\n", __PRETTY_FUNCTION__, __LINE__); // joe.liu
218 */
219 return 0;
220 }
221