-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdsHost.c
198 lines (172 loc) · 6.81 KB
/
dsHost.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2017 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "dsTypes.h"
#include "dsError.h"
#include "dsHost.h"
extern "C" {
#include "interface/vmcs_host/vc_vchi_gencmd.h"
}
static uint32_t version_num = 0x10000;
static bool host_initialized = false;
#define FILE_SIZE 50
#define SIZE 10
dsError_t dsHostInit()
{
if (host_initialized) {
return dsERR_ALREADY_INITIALIZED;
}
// Initialization code here
host_initialized = true;
return dsERR_NONE;
}
dsError_t dsSetHostPowerMode(int newPower)
{
dsError_t ret = dsERR_NONE;
/* Raspberry pi doesn't have anykind of power management It is either plugged in or not.*/
return ret;
}
dsError_t dsGetHostPowerMode(int *currPower)
{
dsError_t ret = dsERR_NONE;
/* Raspberry pi doesn't have anykind of power management It is either plugged in or not.*/
return ret;
}
dsError_t dsGetCPUTemperature(float *cpuTemperature)
{
dsError_t ret = dsERR_NONE;
char Temp_File[FILE_SIZE];
char temp_value[SIZE];
FILE *fp = NULL;
if (!host_initialized) {
return dsERR_NOT_INITIALIZED;
}
if (cpuTemperature == NULL) {
return dsERR_INVALID_PARAM;
}
snprintf(Temp_File, FILE_SIZE, "/sys/class/thermal/thermal_zone0/temp");
fp = fopen(Temp_File, "r");
if (fread(temp_value, 1, SIZE, fp) <= 0) {
printf("Error reading cpu temp\n");
return ret;
}
*cpuTemperature = atof(temp_value)/1000;
printf("Cpu temperature %f", *cpuTemperature);
return ret;
}
dsError_t dsGetVersion(uint32_t *versionNumber)
{
printf("Entering into dsGetVersion\n");
dsError_t ret;
if(versionNumber != NULL)
{
printf("getting hal version in ds-hal\n");
*versionNumber = version_num;
return dsERR_NONE;
}
else ret = dsERR_INVALID_PARAM;
return ret;
}
dsError_t dsSetVersion(uint32_t versionNumber)
{
printf("Entering into dsGetVersion\n");
dsError_t ret = dsERR_NONE;
printf("setting hal version in ds-hal %x\n", versionNumber);
version_num = versionNumber;
return ret;
}
dsError_t dsGetFreeSystemGraphicsMemory(uint64_t* memory)
{
char buffer[512];
dsError_t ret = dsERR_NONE;
buffer[0] = '\0';
printf("Entering into dsGetFreeSystemGraphicsMemory\n");
if (vc_gencmd(buffer, sizeof(buffer), "get_mem reloc") != 0 )
{
printf( "Failed to get free GPU memory\n");
return dsERR_GENERAL;
}
buffer[sizeof(buffer) - 1] = '\0';
/* Extract response after = */
char* equal = strchr(buffer, '=');
if (equal != nullptr) {
equal++;
}
else {
equal = buffer;
}
*memory = strtol(equal, (char **)NULL, 10);
printf( "Free GPU memory is %lld\n", *memory);
return ret;
}
dsError_t dsGetTotalSystemGraphicsMemory(uint64_t* memory)
{
char buffer[512];
dsError_t ret = dsERR_NONE;
buffer[0] = '\0';
printf("Entering into dsGetTotalSystemGraphicsMemory\n");
if (vc_gencmd(buffer, sizeof(buffer), "get_mem reloc_total") != 0 )
{
printf( "Failed to get total GPU memory\n");
return dsERR_GENERAL;
}
buffer[sizeof(buffer) - 1] = '\0';
/* Extract response after = */
char* equal = strchr(buffer, '=');
if (equal != nullptr) {
equal++;
}
else {
equal = buffer;
}
*memory = strtol(equal, (char **)NULL, 10);
printf( "Total GPU memory is %lld\n", *memory);
return ret;
}
dsError_t dsHostTerm()
{
if (!host_initialized) {
return dsERR_NOT_INITIALIZED;
}
host_initialized = false;
return dsERR_NONE;
}
dsError_t dsGetHostEDID(unsigned char *edid, int *length)
{
if (!host_initialized) {
return dsERR_NOT_INITIALIZED;
}
if (edid == NULL || length == NULL ) {
return dsERR_INVALID_PARAM;
}
return dsERR_OPERATION_NOT_SUPPORTED;
}
dsError_t dsGetSocIDFromSDK(char *socID)
{
if (!host_initialized) {
return dsERR_NOT_INITIALIZED;
}
if (socID == NULL){
return dsERR_INVALID_PARAM;
}
return dsERR_OPERATION_NOT_SUPPORTED;
}