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 <sys/types.h>
20 #include <sys/stat.h>
21 #include <sys/ioctl.h>
22 #include <poll.h>
23 #include <sys/time.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <pthread.h>
27 #include <math.h>
28 #include <unistd.h>
29 #include <signal.h>
30 #include "sample_comm.h"
31
32 #ifdef __cplusplus
33 #if __cplusplus
34 extern "C" {
35 #endif
36 #endif /* End of #ifdef __cplusplus */
37
SAMPLE_COMM_VPSS_Start(VPSS_GRP VpssGrp,HI_BOOL * pabChnEnable,VPSS_GRP_ATTR_S * pstVpssGrpAttr,VPSS_CHN_ATTR_S * pastVpssChnAttr)38 HI_S32 SAMPLE_COMM_VPSS_Start(VPSS_GRP VpssGrp, HI_BOOL *pabChnEnable, VPSS_GRP_ATTR_S *pstVpssGrpAttr,
39 VPSS_CHN_ATTR_S *pastVpssChnAttr)
40 {
41 VPSS_CHN VpssChn;
42 HI_S32 s32Ret;
43 HI_S32 j;
44
45 if ((pabChnEnable == NULL) || (pstVpssGrpAttr == NULL) || (pastVpssChnAttr == NULL)) {
46 SAMPLE_PRT("null pointer!\n");
47 return HI_FAILURE;
48 }
49 s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, pstVpssGrpAttr);
50 if (s32Ret != HI_SUCCESS) {
51 SAMPLE_PRT("HI_MPI_VPSS_CreateGrp(grp:%d) failed with %#x!\n", VpssGrp, s32Ret);
52 return HI_FAILURE;
53 }
54
55 for (j = 0; j < VPSS_MAX_PHY_CHN_NUM; j++) {
56 if (pabChnEnable[j] == HI_TRUE) {
57 VpssChn = j;
58 s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &pastVpssChnAttr[VpssChn]);
59 if (s32Ret != HI_SUCCESS) {
60 SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x\n", s32Ret);
61 return HI_FAILURE;
62 }
63
64 s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);
65 if (s32Ret != HI_SUCCESS) {
66 SAMPLE_PRT("HI_MPI_VPSS_EnableChn failed with %#x\n", s32Ret);
67 return HI_FAILURE;
68 }
69 }
70 }
71
72 s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);
73 if (s32Ret != HI_SUCCESS) {
74 SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);
75 return HI_FAILURE;
76 }
77
78 return HI_SUCCESS;
79 }
80
SAMPLE_COMM_VPSS_Stop(VPSS_GRP VpssGrp,HI_BOOL * pabChnEnable)81 HI_S32 SAMPLE_COMM_VPSS_Stop(VPSS_GRP VpssGrp, HI_BOOL *pabChnEnable)
82 {
83 HI_S32 j;
84 HI_S32 s32Ret = HI_SUCCESS;
85 VPSS_CHN VpssChn;
86
87 if (pabChnEnable == NULL) {
88 SAMPLE_PRT("null pointer!\n");
89 return HI_FAILURE;
90 }
91 for (j = 0; j < VPSS_MAX_PHY_CHN_NUM; j++) {
92 if (pabChnEnable[j] == HI_TRUE) {
93 VpssChn = j;
94 s32Ret = HI_MPI_VPSS_DisableChn(VpssGrp, VpssChn);
95 if (s32Ret != HI_SUCCESS) {
96 SAMPLE_PRT("failed with %#x!\n", s32Ret);
97 return HI_FAILURE;
98 }
99 }
100 }
101
102 s32Ret = HI_MPI_VPSS_StopGrp(VpssGrp);
103 if (s32Ret != HI_SUCCESS) {
104 SAMPLE_PRT("failed with %#x!\n", s32Ret);
105 return HI_FAILURE;
106 }
107
108 s32Ret = HI_MPI_VPSS_DestroyGrp(VpssGrp);
109 if (s32Ret != HI_SUCCESS) {
110 SAMPLE_PRT("failed with %#x!\n", s32Ret);
111 return HI_FAILURE;
112 }
113
114 return HI_SUCCESS;
115 }
116
117 #ifdef __cplusplus
118 #if __cplusplus
119 }
120 #endif
121 #endif /* End of #ifdef __cplusplus */
122