• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <pthread.h>
21 #include <signal.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <sys/ioctl.h>
26 #include "hi_common.h"
27 #include "sample_vio.h"
28 #include "mpi_sys.h"
29 #include "sdk.h"
30 
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif /* End of #ifdef __cplusplus */
36 
37 static volatile sig_atomic_t g_sample_vio_exit = 0;
SAMPLE_VIO_GetChar(hi_void)38 hi_void SAMPLE_VIO_GetChar(hi_void)
39 {
40     if (g_sample_vio_exit == 1) {
41         return;
42     }
43     PAUSE();
44 }
45 
SAMPLE_VIO_HandleSig(HI_S32 signo)46 static void SAMPLE_VIO_HandleSig(HI_S32 signo)
47 {
48     if (g_sample_vio_exit == 1) {
49         return;
50     }
51 
52     if (signo == SIGINT || signo == SIGTERM) {
53         g_sample_vio_exit = 1;
54     }
55 }
56 
57 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
SAMPLE_VIO_SIGNAL(void (* func)(int))58 static hi_void SAMPLE_VIO_SIGNAL(void (*func)(int))
59 {
60     struct sigaction sa = { 0 };
61 
62     sa.sa_handler = func;
63     sa.sa_flags = 0;
64     sigaction(SIGINT, &sa, HI_NULL);
65     sigaction(SIGTERM, &sa, HI_NULL);
66 }
67 #endif
68 
SAMPLE_VIO_Usage(const char * sPrgNm)69 static void SAMPLE_VIO_Usage(const char *sPrgNm)
70 {
71     printf("Usage : %s <index>\n", sPrgNm);
72     printf("index:\n");
73     printf("\t 0)VI (Online) - VPSS(Offline) - VO.\n");
74     printf("\t 1)WDR(Offline)- VPSS(Offline) - VO. LDC+DIS+SPREAD.\n");
75     printf("\t 2)GDC - VPSS LowDelay.\n");
76     printf("\t 3)Double WDR Pipe.\n");
77     printf("\t 4)FPN Calibrate & Correction.\n");
78     printf("\t 5)WDR Switch.\n");
79     printf("\t 6)90/180/270/0/free Rotate.\n");
80     printf("\t 7)VI-VPSS-VO(MIPI_TX).\n\n");
81 
82     printf("\t Hi3516DV300/Hi3559V200/Hi3556V200) vo HDMI output.\n");
83     printf("\t Hi3516CV500) vo BT1120 output.\n");
84     printf("\t If you have any questions, please look at readme.txt!\n");
85     return;
86 }
87 
88 
89 #if defined(__HuaweiLite__) && (!defined(__OHOS__))
app_main(int argc,char * argv[])90 int app_main(int argc, char *argv[])
91 #else
92 int main(int argc, char *argv[])
93 #endif
94 {
95     HI_S32 s32Ret = HI_FAILURE;
96     HI_S32 s32Index;
97     HI_U32 u32VoIntfType = 0;
98     HI_U32 u32ChipId = 0xffffffff;
99     sdk_init();
100     if (argc != 2) { /* 2:arg num */
101         SAMPLE_VIO_Usage(argv[0]);
102         return HI_FAILURE;
103     }
104 
105     if (strncmp(argv[1], "-h", 2) == 0) { /* 2:arg num */
106         SAMPLE_VIO_Usage(argv[0]);
107         return HI_FAILURE;
108     }
109 
110     if (strlen(argv[1]) != 1) {
111         SAMPLE_VIO_Usage(argv[0]);
112         return HI_FAILURE;
113     }
114 
115     if (argv[1][0] < '0' || argv[1][0] > '9') {
116         SAMPLE_VIO_Usage(argv[0]);
117         return HI_FAILURE;
118     }
119 
120 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
121     SAMPLE_VIO_SIGNAL(SAMPLE_VIO_HandleSig);
122 #endif
123 
124     HI_MPI_SYS_GetChipId(&u32ChipId);
125     if (u32ChipId == HI3516C_V500) {
126         u32VoIntfType = 1;
127     } else {
128         u32VoIntfType = 0;
129     }
130 
131     s32Index = atoi(argv[1]);
132     switch (s32Index) {
133         case 0:
134             s32Ret = SAMPLE_VIO_ViOnlineVpssOfflineRoute(u32VoIntfType);
135             break;
136 
137         case 1: /* 1: value of arg[1] */
138             s32Ret = SAMPLE_VIO_WDR_LDC_DIS_SPREAD(u32VoIntfType);
139             break;
140 
141         case 2: /* 2: value of arg[1] */
142             s32Ret = SAMPLE_VIO_ViVpssLowDelay(u32VoIntfType);
143             break;
144 
145         case 3: /* 3: value of arg[1] */
146             s32Ret = SAMPLE_VIO_ViDoubleWdrPipe(u32VoIntfType);
147             break;
148 
149         case 4: /* 4: value of arg[1] */
150             s32Ret = SAMPLE_VIO_FPN(u32VoIntfType);
151             break;
152 
153         case 5: /* 5: value of arg[1] */
154             s32Ret = SAMPLE_VIO_ViWdrSwitch(u32VoIntfType);
155             break;
156 
157         case 6: /* 6: value of arg[1] */
158             s32Ret = SAMPLE_VIO_Rotate(u32VoIntfType);
159             break;
160 
161         case 7: /* 7: value of arg[1] */
162             s32Ret = SAMPLE_VIO_VPSS_VO_MIPI_TX();
163             break;
164 
165         default:
166             SAMPLE_PRT("the index %d is invalid!\n", s32Index);
167             SAMPLE_VIO_Usage(argv[0]);
168             return HI_FAILURE;
169     }
170 
171     if ((s32Ret == HI_SUCCESS) && (g_sample_vio_exit == 0)) {
172         SAMPLE_PRT("\033[0;32mprogram exit normally!\033[0;39m\n");
173     } else {
174         SAMPLE_PRT("\033[0;31mprogram exit abnormally!\033[0;39m\n");
175     }
176     sdk_exit();
177     return s32Ret;
178 }
179 
180 #ifdef __cplusplus
181 #if __cplusplus
182 }
183 #endif
184 #endif /* End of #ifdef __cplusplus */
185