| 1 | /**************************************************************************** |
|---|
| 2 | *_Copyright (c) 2004 DST Technologies Inc. All Rights Reserved. |
|---|
| 3 | * |
|---|
| 4 | * Module: dsthalsys.c |
|---|
| 5 | * |
|---|
| 6 | * Description: DST SYSTEM INTERFACE IMPLEMENTATION |
|---|
| 7 | * |
|---|
| 8 | * |
|---|
| 9 | * notes: jfet20040610 |
|---|
| 10 | * |
|---|
| 11 | ***************************************************************************/ |
|---|
| 12 | |
|---|
| 13 | #include "dsthalcommon.h" |
|---|
| 14 | #include "dsthalsys.h" |
|---|
| 15 | #include "dsthalfe.h" |
|---|
| 16 | #include "string.h" |
|---|
| 17 | #include <sys/utsname.h> |
|---|
| 18 | #include "dstddsys.h" |
|---|
| 19 | #include "dstversion.h" |
|---|
| 20 | |
|---|
| 21 | #include <stdlib.h> |
|---|
| 22 | #include <sys/types.h> |
|---|
| 23 | #include <sys/stat.h> |
|---|
| 24 | #include <fcntl.h> |
|---|
| 25 | |
|---|
| 26 | #include <unistd.h> |
|---|
| 27 | |
|---|
| 28 | #ifdef DMALLOC |
|---|
| 29 | #include <dmalloc.h> |
|---|
| 30 | #endif |
|---|
| 31 | |
|---|
| 32 | /****************************************************************************** |
|---|
| 33 | * Global variable declaration |
|---|
| 34 | ******************************************************************************/ |
|---|
| 35 | DS_U8 DhlSysInfoInit; |
|---|
| 36 | DS_U32 gdhlSysDbgLvl = 2; |
|---|
| 37 | DS_U32 gdhlExtDbgLvl = 2; |
|---|
| 38 | DHL_SYS_Info DhlSysInfo; |
|---|
| 39 | DHL_SYS_CONFIG g_dhlsys; |
|---|
| 40 | |
|---|
| 41 | /****************************************************************************** |
|---|
| 42 | * Imported variable declaration |
|---|
| 43 | ******************************************************************************/ |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | /****************************************************************************** |
|---|
| 47 | * Imported function declaration |
|---|
| 48 | ******************************************************************************/ |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | /****************************************************************************** |
|---|
| 52 | * Local definitions |
|---|
| 53 | ******************************************************************************/ |
|---|
| 54 | #define LOCK_SYS_MUTEX() do { \ |
|---|
| 55 | if ( OS_TakeMutex(g_dhlsys.SYSMutex) != OS_OK ) { \ |
|---|
| 56 | DHL_DbgPrintf(0,DHLDBG_SYS, "MUTEX ERROR, LINE=%d\n", __LINE__); \ |
|---|
| 57 | goto done; \ |
|---|
| 58 | } \ |
|---|
| 59 | } while (0) |
|---|
| 60 | |
|---|
| 61 | #define UNLOCK_SYS_MUTEX() do { \ |
|---|
| 62 | if ( OS_GiveMutex(g_dhlsys.SYSMutex) != OS_OK ) { \ |
|---|
| 63 | DHL_DbgPrintf(0,DHLDBG_SYS,"MUTEX ERROR, LINE=%d\n", __LINE__); \ |
|---|
| 64 | } \ |
|---|
| 65 | } while (0) |
|---|
| 66 | |
|---|
| 67 | /****************************************************************************** |
|---|
| 68 | * Local typedefs |
|---|
| 69 | ******************************************************************************/ |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | /****************************************************************************** |
|---|
| 73 | * Local variables declaration |
|---|
| 74 | ******************************************************************************/ |
|---|
| 75 | static DS_U32 g_BrdRev, g_BrdDiv; |
|---|
| 76 | |
|---|
| 77 | /****************************************************************************** |
|---|
| 78 | * Local function prototypes |
|---|
| 79 | ******************************************************************************/ |
|---|
| 80 | static void DHL_SYS_InitInfo(void ); |
|---|
| 81 | static int GetMemoryParam(char *iStream, const char *FindString, DS_U32 *pValue); |
|---|
| 82 | |
|---|
| 83 | /******************************************************************************** |
|---|
| 84 | FUNCTION: |
|---|
| 85 | DHL_SYS_INITITIATE |
|---|
| 86 | |
|---|
| 87 | Purpose: |
|---|
| 88 | |
|---|
| 89 | Arguments: |
|---|
| 90 | |
|---|
| 91 | Returns: |
|---|
| 92 | DHL_RESULT success - DHL_OK |
|---|
| 93 | fail - DHL_FAIL |
|---|
| 94 | *********************************************************************************/ |
|---|
| 95 | DHL_RESULT DHL_SYS_Initiate(void) |
|---|
| 96 | { |
|---|
| 97 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 98 | |
|---|
| 99 | dhlResult = DD_SYS_Initiate(); |
|---|
| 100 | SysASSERT( dhlResult == DHL_OK ); |
|---|
| 101 | |
|---|
| 102 | OS_Init(); |
|---|
| 103 | |
|---|
| 104 | g_dhlsys.SYSMutex = OS_CreateMutex( "SYS_Mutex" ); |
|---|
| 105 | if ( g_dhlsys.SYSMutex == (OS_MUTEX_ID)0 ) |
|---|
| 106 | { |
|---|
| 107 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS," |error|%d\r\n",__LINE__); |
|---|
| 108 | dhlResult = DHL_FAIL_CORE_DRIVER; |
|---|
| 109 | goto done; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | #if 0 |
|---|
| 113 | dhlResult = DD_SYS_CheckDevice(); |
|---|
| 114 | if(DHL_ERROR(dhlResult)) |
|---|
| 115 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, " |Error| %d Fail system Initiate.\r\n",__LINE__); |
|---|
| 116 | #endif |
|---|
| 117 | |
|---|
| 118 | // hwatk/060704 |
|---|
| 119 | //ºÎÆÃ½Ã ´ÙÀ½¶óÀο¡¼ ¸ØÃß´Â °æ¿ì°¡ ¹ß»ýÇÏ¿© Á¦°Å. |
|---|
| 120 | //system( "/bin/stty erase ^H" ); |
|---|
| 121 | |
|---|
| 122 | DHL_SYS_GetBoardVersion(&g_BrdRev); |
|---|
| 123 | |
|---|
| 124 | dhlResult = DHL_AUD_Init(); |
|---|
| 125 | done: |
|---|
| 126 | SysENSURE( dhlResult == DHL_OK ); |
|---|
| 127 | |
|---|
| 128 | return dhlResult; |
|---|
| 129 | } |
|---|
| 130 | /******************************************************************************** |
|---|
| 131 | FUNCTION: |
|---|
| 132 | DHL_SYS_InitInfo |
|---|
| 133 | |
|---|
| 134 | Purpose: |
|---|
| 135 | Get the dsthal,atidrivers,kernel,HW version information. |
|---|
| 136 | Arguments: |
|---|
| 137 | |
|---|
| 138 | Returns: |
|---|
| 139 | DHL_RESULT success - DHL_OK |
|---|
| 140 | fail - DHL_FAIL |
|---|
| 141 | *********************************************************************************/ |
|---|
| 142 | static void DHL_SYS_InitInfo(void ) |
|---|
| 143 | { |
|---|
| 144 | extern DS_U32 DD_FE_GetVersion( void ); |
|---|
| 145 | char buf[256], *ptr; |
|---|
| 146 | FILE *fp; |
|---|
| 147 | |
|---|
| 148 | fp = fopen("/proc/version", "r"); |
|---|
| 149 | if ( !fp ) { |
|---|
| 150 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, " |Error| %d.\n",__LINE__); |
|---|
| 151 | } else { |
|---|
| 152 | ptr = fgets( buf, 256, fp ); |
|---|
| 153 | if ( !ptr ) { |
|---|
| 154 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, " |Error| %d.\n",__LINE__); |
|---|
| 155 | } else { |
|---|
| 156 | ptr = strstr( buf, "DST_K" ); |
|---|
| 157 | if ( ptr ) |
|---|
| 158 | strncpy(DhlSysInfo.kernel_version, ptr, 9); |
|---|
| 159 | else |
|---|
| 160 | strncpy(DhlSysInfo.kernel_version, buf, 9); |
|---|
| 161 | } |
|---|
| 162 | DhlSysInfo.kernel_version[9] = '\0'; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | DhlSysInfo.dsthal_version = DSTHAL_VERSION; |
|---|
| 166 | DHL_SYS_GetBoardVersion( &DhlSysInfo.board_version ); |
|---|
| 167 | DhlSysInfo.driver_dst_version = DD_SYS_GetDrvDstVersion(); |
|---|
| 168 | DhlSysInfo.driver_ven_version = DD_SYS_GetDrvVenVersion(); |
|---|
| 169 | DhlSysInfo.fe_version = DD_FE_GetVersion(); |
|---|
| 170 | DhlSysInfo.loader_version = DD_SYS_GetLoaderVer(); |
|---|
| 171 | |
|---|
| 172 | DhlSysInfoInit = 1; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | /******************************************************************************** |
|---|
| 176 | FUNCTION: |
|---|
| 177 | DHL_SYS_GetInfo |
|---|
| 178 | Purpose: |
|---|
| 179 | Get version information for ati layer, dsthal, board and kernel version . |
|---|
| 180 | Arguments: |
|---|
| 181 | DHL_SYS_Info * |
|---|
| 182 | Returns: |
|---|
| 183 | DHL_RESULT if success - DHL_OK fail - DHL_FAIL |
|---|
| 184 | *********************************************************************************/ |
|---|
| 185 | |
|---|
| 186 | void DHL_SYS_GetInfo( pDHL_SYS_Info psys_info) |
|---|
| 187 | { |
|---|
| 188 | if(DhlSysInfoInit == 0) |
|---|
| 189 | DHL_SYS_InitInfo(); |
|---|
| 190 | *psys_info = DhlSysInfo; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | #define GET_DS_U8_0(x) (unsigned int)((x>>24)&0xFF) |
|---|
| 194 | #define GET_DS_U8_1(x) (unsigned int)((x>>16)&0xFF) |
|---|
| 195 | #define GET_DS_U8_2(x) (unsigned int)((x>>8)&0xFF) |
|---|
| 196 | #define GET_DS_U8_3(x) (unsigned int)((x)&0xFF) |
|---|
| 197 | |
|---|
| 198 | void DHL_SYS_DumpVersion(void) |
|---|
| 199 | { |
|---|
| 200 | if(DhlSysInfoInit == 0) |
|---|
| 201 | DHL_SYS_InitInfo(); |
|---|
| 202 | |
|---|
| 203 | DHL_DbgPrintf( 0, DHLDBG_PSI, " Kernel Version: %s\n", DhlSysInfo.kernel_version ); |
|---|
| 204 | |
|---|
| 205 | DHL_DbgPrintf( 0, DHLDBG_PSI, " DSTHAL Version: H%x.%x%x%x\n", |
|---|
| 206 | GET_DS_U8_0(DhlSysInfo.dsthal_version), GET_DS_U8_1(DhlSysInfo.dsthal_version), |
|---|
| 207 | GET_DS_U8_2(DhlSysInfo.dsthal_version), GET_DS_U8_3(DhlSysInfo.dsthal_version) ); |
|---|
| 208 | |
|---|
| 209 | DHL_DbgPrintf( 0, DHLDBG_PSI, " Board Version: 0x%02X\n", (unsigned int)DhlSysInfo.board_version ); |
|---|
| 210 | DHL_DbgPrintf( 0, DHLDBG_PSI, " Driver DST Version: D%x.%x%x%x\n", |
|---|
| 211 | GET_DS_U8_0(DhlSysInfo.driver_dst_version), GET_DS_U8_1(DhlSysInfo.driver_dst_version), |
|---|
| 212 | GET_DS_U8_2(DhlSysInfo.driver_dst_version), GET_DS_U8_3(DhlSysInfo.driver_dst_version) ); |
|---|
| 213 | |
|---|
| 214 | DHL_DbgPrintf( 0, DHLDBG_PSI, " Driver Vendor Version: Rel %x.%x.%x.%x\n", |
|---|
| 215 | GET_DS_U8_0(DhlSysInfo.driver_ven_version), GET_DS_U8_1(DhlSysInfo.driver_ven_version), |
|---|
| 216 | GET_DS_U8_2(DhlSysInfo.driver_ven_version), GET_DS_U8_3(DhlSysInfo.driver_ven_version) ); |
|---|
| 217 | |
|---|
| 218 | DHL_DbgPrintf( 0, DHLDBG_PSI, " FE Firmware Version: %x.%x.%x.%x\n", |
|---|
| 219 | GET_DS_U8_0(DhlSysInfo.fe_version), GET_DS_U8_1(DhlSysInfo.fe_version), |
|---|
| 220 | GET_DS_U8_2(DhlSysInfo.fe_version), GET_DS_U8_3(DhlSysInfo.fe_version) ); |
|---|
| 221 | |
|---|
| 222 | DHL_DbgPrintf( 0, DHLDBG_PSI, " BootLoader Version: %x.%x.%x.%x\n", |
|---|
| 223 | GET_DS_U8_0(DhlSysInfo.loader_version), GET_DS_U8_1(DhlSysInfo.loader_version), |
|---|
| 224 | GET_DS_U8_2(DhlSysInfo.loader_version), GET_DS_U8_3(DhlSysInfo.loader_version) ); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | /******************************************************************************** |
|---|
| 229 | FUNCTION: |
|---|
| 230 | DHL_SYS_TERMINATE |
|---|
| 231 | Purpose: |
|---|
| 232 | |
|---|
| 233 | Arguments: |
|---|
| 234 | |
|---|
| 235 | Returns: |
|---|
| 236 | DHL_RESULT if success - DHL_OK fail - DHL_FAIL |
|---|
| 237 | *********************************************************************************/ |
|---|
| 238 | DHL_RESULT DHL_SYS_Terminate(void) |
|---|
| 239 | { |
|---|
| 240 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 241 | dhlResult = DD_SYS_Terminate(); |
|---|
| 242 | if(DHL_ERROR(dhlResult)) |
|---|
| 243 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, |
|---|
| 244 | " |Error| %d Fail system Terminate \r\n",__LINE__); |
|---|
| 245 | else |
|---|
| 246 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS," |success|\r\n"); |
|---|
| 247 | return dhlResult; |
|---|
| 248 | } |
|---|
| 249 | /******************************************************************************** |
|---|
| 250 | FUNCTION: |
|---|
| 251 | DHL_SYS_IsUsbVaild |
|---|
| 252 | |
|---|
| 253 | Purpose: |
|---|
| 254 | |
|---|
| 255 | Arguments: |
|---|
| 256 | |
|---|
| 257 | Returns: |
|---|
| 258 | DHL_RESULT valid - DHL_OK, invaild - DHL_FAIL |
|---|
| 259 | Notes: |
|---|
| 260 | *********************************************************************************/ |
|---|
| 261 | DHL_RESULT DHL_SYS_IsUsbValid(void) |
|---|
| 262 | { |
|---|
| 263 | return DD_SYS_IsUsbValid(); |
|---|
| 264 | } |
|---|
| 265 | /******************************************************************************** |
|---|
| 266 | FUNCTION: |
|---|
| 267 | DHL_SYS_SetDbgLvl |
|---|
| 268 | |
|---|
| 269 | Purpose: |
|---|
| 270 | |
|---|
| 271 | Arguments: |
|---|
| 272 | |
|---|
| 273 | Returns: |
|---|
| 274 | DS_BOOL |
|---|
| 275 | Notes: |
|---|
| 276 | *********************************************************************************/ |
|---|
| 277 | void DHL_SYS_SetDbgLvl(DS_U32 uDbgLvl, DHL_SYS_DBGTYPE DbgType) |
|---|
| 278 | { |
|---|
| 279 | switch(DbgType) |
|---|
| 280 | { |
|---|
| 281 | case DHL_SYSDBG_DHLSYS: |
|---|
| 282 | gdhlSysDbgLvl = uDbgLvl; |
|---|
| 283 | break; |
|---|
| 284 | case DHL_SYSDBG_DDSYS: |
|---|
| 285 | DD_SYS_SetDbgLvl(uDbgLvl); |
|---|
| 286 | break; |
|---|
| 287 | case DHL_SYSDBG_END: |
|---|
| 288 | default: |
|---|
| 289 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, |
|---|
| 290 | " |Error| Not avaliable parameter %d\r\n",__LINE__); |
|---|
| 291 | break; |
|---|
| 292 | } |
|---|
| 293 | DHL_DbgPrintf(0,DHLDBG_SYS,"DHLSys DbgLvl(%d)\r\n",uDbgLvl); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | /******************************************************************************** |
|---|
| 297 | FUNCTION: |
|---|
| 298 | DHL_SYS_IsSTBYPowerMode |
|---|
| 299 | DHL_SYS_IsDCRBoard |
|---|
| 300 | |
|---|
| 301 | Purpose: |
|---|
| 302 | |
|---|
| 303 | Arguments: |
|---|
| 304 | |
|---|
| 305 | Returns: |
|---|
| 306 | DHL_SYS_IsSTBYPowerMode : 0 - Powered by host, 1 - Powered by POD. |
|---|
| 307 | DHL_SYS_IsDCRBoard : 1 - Step, 0 - Basic |
|---|
| 308 | |
|---|
| 309 | Notes: |
|---|
| 310 | *********************************************************************************/ |
|---|
| 311 | DHL_RESULT DHL_SYS_IsSTBYPowerMode( DS_BOOL *flag ) |
|---|
| 312 | { |
|---|
| 313 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 314 | |
|---|
| 315 | if(DHL_ERROR(dhlResult)) |
|---|
| 316 | DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, |
|---|
| 317 | " |Error| %d Cannot get stby power mode.\r\n",__LINE__); |
|---|
| 318 | |
|---|
| 319 | return dhlResult; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | DHL_RESULT DHL_SYS_GetBoardVersion(DS_U32 *ver) |
|---|
| 323 | { |
|---|
| 324 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 325 | DS_U8 boardVer = 0; |
|---|
| 326 | |
|---|
| 327 | *ver = boardVer; |
|---|
| 328 | |
|---|
| 329 | return dhlResult; |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | DHL_RESULT DHL_SYS_Reset(void) |
|---|
| 333 | { |
|---|
| 334 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 335 | |
|---|
| 336 | dhlResult = DD_SYS_Reset(); |
|---|
| 337 | SysASSERT( dhlResult == DHL_OK ); |
|---|
| 338 | |
|---|
| 339 | return dhlResult; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | int DHL_SYS_I2cWrite(unsigned char addr, int nSubAddress, int subAddress, unsigned char *buf, int len) |
|---|
| 343 | { |
|---|
| 344 | int ret = -1; |
|---|
| 345 | |
|---|
| 346 | if ( !buf && len ) { |
|---|
| 347 | DHL_DbgPrintf( 0, DHLDBG_SYS, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 348 | return -1; |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | LOCK_SYS_MUTEX(); |
|---|
| 352 | ret = DD_SYS_I2cWrite(0, addr, nSubAddress, subAddress, buf, len); |
|---|
| 353 | UNLOCK_SYS_MUTEX(); |
|---|
| 354 | |
|---|
| 355 | done: |
|---|
| 356 | return ret; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | int DHL_SYS_I2cRead(unsigned char addr, int nSubAddress, int subAddress, unsigned char *buf, int len) |
|---|
| 360 | { |
|---|
| 361 | int ret = -1; |
|---|
| 362 | |
|---|
| 363 | LOCK_SYS_MUTEX(); |
|---|
| 364 | ret = DD_SYS_I2cRead(0, addr, nSubAddress, subAddress, buf, len); |
|---|
| 365 | UNLOCK_SYS_MUTEX(); |
|---|
| 366 | |
|---|
| 367 | done: |
|---|
| 368 | return ret; |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | int DHL_SYS_MSPWrite(unsigned char WriteAddr,unsigned int addr,unsigned short length,unsigned short data) |
|---|
| 372 | { |
|---|
| 373 | int SubAddress; |
|---|
| 374 | |
|---|
| 375 | SubAddress = WriteAddr; |
|---|
| 376 | SubAddress += (((addr>>8) & 0xFF)<<8); |
|---|
| 377 | SubAddress += (addr & 0xFF)<<16; |
|---|
| 378 | return DHL_SYS_I2cWrite( 0x80, 3, SubAddress, (unsigned char *)&data, 2/*length*/ ); |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | int DHL_SYS_MSPRead(unsigned char subAddr, unsigned int addr,unsigned short length,unsigned char *rbuf) |
|---|
| 382 | { |
|---|
| 383 | int SubAddress; |
|---|
| 384 | |
|---|
| 385 | SubAddress = subAddr; |
|---|
| 386 | SubAddress += (((addr>>8) & 0xFF)<<8); |
|---|
| 387 | SubAddress += (addr & 0xFF)<<16; |
|---|
| 388 | |
|---|
| 389 | return DHL_SYS_I2cRead( 0x80, 3, SubAddress, rbuf, /*length*/2 ); |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | int DHL_SYS_ANXWrite(unsigned char port, unsigned char regAddr, unsigned char val) |
|---|
| 393 | { |
|---|
| 394 | int ret = -1; |
|---|
| 395 | int try_cnt; |
|---|
| 396 | |
|---|
| 397 | if (port == 0) |
|---|
| 398 | { |
|---|
| 399 | |
|---|
| 400 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 401 | { |
|---|
| 402 | LOCK_SYS_MUTEX(); |
|---|
| 403 | ret = DD_SYS_I2cWrite(1, HDMI_TX_PORT0_ADDR, 1, regAddr, &val, 1); |
|---|
| 404 | UNLOCK_SYS_MUTEX(); |
|---|
| 405 | if (ret == 2) |
|---|
| 406 | { |
|---|
| 407 | break; |
|---|
| 408 | } |
|---|
| 409 | OS_mDelay(10); |
|---|
| 410 | } |
|---|
| 411 | } |
|---|
| 412 | else if (port == 1) |
|---|
| 413 | { |
|---|
| 414 | |
|---|
| 415 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 416 | { |
|---|
| 417 | LOCK_SYS_MUTEX(); |
|---|
| 418 | ret = DD_SYS_I2cWrite(1, HDMI_TX_PORT1_ADDR, 1, regAddr, &val, 1); |
|---|
| 419 | UNLOCK_SYS_MUTEX(); |
|---|
| 420 | if (ret == 2) |
|---|
| 421 | { |
|---|
| 422 | break; |
|---|
| 423 | } |
|---|
| 424 | OS_mDelay(10); |
|---|
| 425 | } |
|---|
| 426 | } |
|---|
| 427 | |
|---|
| 428 | if (try_cnt==3) { |
|---|
| 429 | printf("|%s| ERROR: I2C error is occurred more than 3 times.\n", __FUNCTION__); |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | done: |
|---|
| 433 | return ret; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | int DHL_SYS_ANXRead(unsigned char port, unsigned char regAddr, unsigned char *buf) |
|---|
| 437 | { |
|---|
| 438 | int ret = -1; |
|---|
| 439 | int try_cnt; |
|---|
| 440 | |
|---|
| 441 | if (port == 0) |
|---|
| 442 | { |
|---|
| 443 | |
|---|
| 444 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 445 | { |
|---|
| 446 | LOCK_SYS_MUTEX(); |
|---|
| 447 | ret = DD_SYS_I2cRead(1, HDMI_TX_PORT0_ADDR, 1, regAddr, buf, 1); |
|---|
| 448 | UNLOCK_SYS_MUTEX(); |
|---|
| 449 | if (ret == 1) |
|---|
| 450 | { |
|---|
| 451 | break; |
|---|
| 452 | } |
|---|
| 453 | OS_mDelay(10); |
|---|
| 454 | } |
|---|
| 455 | } |
|---|
| 456 | else if (port == 1) |
|---|
| 457 | { |
|---|
| 458 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 459 | { |
|---|
| 460 | LOCK_SYS_MUTEX(); |
|---|
| 461 | ret = DD_SYS_I2cRead(1, HDMI_TX_PORT1_ADDR, 1, regAddr, buf, 1); |
|---|
| 462 | UNLOCK_SYS_MUTEX(); |
|---|
| 463 | if (ret == 1) |
|---|
| 464 | { |
|---|
| 465 | break; |
|---|
| 466 | } |
|---|
| 467 | OS_mDelay(10); |
|---|
| 468 | } |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | if (try_cnt==3) { |
|---|
| 472 | printf("|%s| ERROR: I2C error is occurred more than 3 times.\n", __FUNCTION__); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | done: |
|---|
| 476 | return ret; |
|---|
| 477 | } |
|---|
| 478 | |
|---|
| 479 | int DHL_SYS_8775Write(unsigned char port, unsigned char regAddr, unsigned char val) |
|---|
| 480 | { |
|---|
| 481 | int ret = -1; |
|---|
| 482 | |
|---|
| 483 | if (port == 0) |
|---|
| 484 | { |
|---|
| 485 | int try_cnt; |
|---|
| 486 | |
|---|
| 487 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 488 | { |
|---|
| 489 | LOCK_SYS_MUTEX(); |
|---|
| 490 | ret = DD_SYS_I2cWrite(1, HDMI_RX_PORT0_ADDR, 1, regAddr, &val, 1); |
|---|
| 491 | UNLOCK_SYS_MUTEX(); |
|---|
| 492 | if (ret == 2) |
|---|
| 493 | { |
|---|
| 494 | break; |
|---|
| 495 | } |
|---|
| 496 | OS_mDelay(10); |
|---|
| 497 | } |
|---|
| 498 | } |
|---|
| 499 | else if (port == 1) |
|---|
| 500 | { |
|---|
| 501 | int try_cnt; |
|---|
| 502 | |
|---|
| 503 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 504 | { |
|---|
| 505 | LOCK_SYS_MUTEX(); |
|---|
| 506 | ret = DD_SYS_I2cWrite(1, HDMI_RX_PORT1_ADDR, 1, regAddr, &val, 1); |
|---|
| 507 | UNLOCK_SYS_MUTEX(); |
|---|
| 508 | if (ret == 2) |
|---|
| 509 | { |
|---|
| 510 | break; |
|---|
| 511 | } |
|---|
| 512 | OS_mDelay(10); |
|---|
| 513 | } |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | done: |
|---|
| 517 | return ret; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | int DHL_SYS_8775Read(unsigned char port, unsigned char regAddr, unsigned char *buf) |
|---|
| 521 | { |
|---|
| 522 | int ret = -1; |
|---|
| 523 | |
|---|
| 524 | if (port == 0) |
|---|
| 525 | { |
|---|
| 526 | int try_cnt; |
|---|
| 527 | |
|---|
| 528 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 529 | { |
|---|
| 530 | LOCK_SYS_MUTEX(); |
|---|
| 531 | ret = DD_SYS_I2cRead(1, HDMI_RX_PORT0_ADDR, 1, regAddr, buf, 1); |
|---|
| 532 | UNLOCK_SYS_MUTEX(); |
|---|
| 533 | if (ret == 1) |
|---|
| 534 | { |
|---|
| 535 | break; |
|---|
| 536 | } |
|---|
| 537 | OS_mDelay(10); |
|---|
| 538 | } |
|---|
| 539 | } |
|---|
| 540 | else if (port == 1) |
|---|
| 541 | { |
|---|
| 542 | int try_cnt; |
|---|
| 543 | |
|---|
| 544 | for (try_cnt = 0; try_cnt < 3; try_cnt++) |
|---|
| 545 | { |
|---|
| 546 | LOCK_SYS_MUTEX(); |
|---|
| 547 | ret = DD_SYS_I2cRead(1, HDMI_RX_PORT1_ADDR, 1, regAddr, buf, 1); |
|---|
| 548 | UNLOCK_SYS_MUTEX(); |
|---|
| 549 | if (ret == 1) |
|---|
| 550 | { |
|---|
| 551 | break; |
|---|
| 552 | } |
|---|
| 553 | OS_mDelay(10); |
|---|
| 554 | } |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | done: |
|---|
| 558 | return ret; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | int DHL_SYS_I2cWriteEx(int i2cBus, unsigned char addr, int isSubAddress, int subAddress, unsigned char *buf, int len) |
|---|
| 562 | { |
|---|
| 563 | int ret = -1; |
|---|
| 564 | |
|---|
| 565 | if ( !buf && len ) { |
|---|
| 566 | DHL_DbgPrintf( 0, DHLDBG_SYS, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 567 | return -1; |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | LOCK_SYS_MUTEX(); |
|---|
| 571 | ret = DD_SYS_I2cWrite(i2cBus, addr, isSubAddress, subAddress, buf, len); |
|---|
| 572 | UNLOCK_SYS_MUTEX(); |
|---|
| 573 | |
|---|
| 574 | done: |
|---|
| 575 | return ret; |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | int DHL_SYS_I2cReadEx(int i2cBus, unsigned char addr, int isSubAddress, int subAddress, unsigned char *buf, int len) |
|---|
| 579 | { |
|---|
| 580 | int ret = -1; |
|---|
| 581 | |
|---|
| 582 | LOCK_SYS_MUTEX(); |
|---|
| 583 | ret = DD_SYS_I2cRead(i2cBus, addr, isSubAddress, subAddress, buf, len); |
|---|
| 584 | UNLOCK_SYS_MUTEX(); |
|---|
| 585 | |
|---|
| 586 | done: |
|---|
| 587 | return ret; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | DHL_RESULT DHL_SYS_SetI2CSpeed(unsigned char bus, unsigned int speed) |
|---|
| 591 | { |
|---|
| 592 | return DD_SYS_SetI2CSpeed(bus,speed); |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | // |
|---|
| 596 | // DHL_SYS_SetGPIO |
|---|
| 597 | // |
|---|
| 598 | // GpioNum: GPIO_XXX definition number |
|---|
| 599 | // Value: 0 or 1 |
|---|
| 600 | // |
|---|
| 601 | DHL_RESULT DHL_SYS_SetGPIO( int GpioNum, int Value ) |
|---|
| 602 | { |
|---|
| 603 | return DD_SYS_SetGPIO( GpioNum, Value ); |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | // |
|---|
| 607 | // DHL_SYS_GetGPIO |
|---|
| 608 | // |
|---|
| 609 | // GpioNum: GPIO_XXX definition number |
|---|
| 610 | // |
|---|
| 611 | int DHL_SYS_GetGPIO( int GpioNum ) |
|---|
| 612 | { |
|---|
| 613 | return DD_SYS_GetGPIO( GpioNum ); |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | int DHL_SYS_FindGPIONum( const char *gpioName ) |
|---|
| 617 | { |
|---|
| 618 | return DD_SYS_FindGPIONum( gpioName ); |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | char *DHL_SYS_GetGPIOName( int GpioNum ) |
|---|
| 622 | { |
|---|
| 623 | return DD_SYS_GetGPIOName( GpioNum ); |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | DS_U32 DHL_SYS_ReadRegister( DS_U32 Address ) |
|---|
| 627 | { |
|---|
| 628 | return OS_ReadRegister( Address ); |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | DS_U32 DHL_SYS_WriteRegister( DS_U32 Address, DS_U32 Value ) |
|---|
| 632 | { |
|---|
| 633 | return OS_WriteRegister(Address, Value); |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | DS_U32 DHL_SYS_GetCurrentTick(void) |
|---|
| 637 | { |
|---|
| 638 | return OS_GetTickCount(); |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | /**************************************************************************** |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | ****************************************************************************/ |
|---|
| 646 | DHL_RESULT DHL_SYS_IsSystemAlive(DS_U8 *pErrorCode) |
|---|
| 647 | { |
|---|
| 648 | DHL_RESULT dhlResult=DHL_OK; |
|---|
| 649 | |
|---|
| 650 | //dhlResult=DD_SYS_IsSystemAlive(pErrorCode); |
|---|
| 651 | |
|---|
| 652 | return dhlResult; |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | char *DHL_SYS_GetSystemErrorCode(DS_U8 ErrorCode) |
|---|
| 656 | { |
|---|
| 657 | char *ptr; |
|---|
| 658 | |
|---|
| 659 | ptr=DD_SYS_GetSystemErrorCode(ErrorCode); |
|---|
| 660 | |
|---|
| 661 | return ptr; |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | int DHL_SYS_GetCECSwitchStatus(void) |
|---|
| 665 | { |
|---|
| 666 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 667 | DS_U32 boardver = 0; |
|---|
| 668 | int tmp; |
|---|
| 669 | |
|---|
| 670 | dhlResult = DHL_SYS_GetBoardVersion(&boardver); |
|---|
| 671 | |
|---|
| 672 | if(dhlResult != DHL_OK){ |
|---|
| 673 | DHL_DbgPrintf( 0, DHLDBG_SYS, "Board Version Reading Fail\n"); |
|---|
| 674 | return -1; |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | if(boardver < 40){ |
|---|
| 678 | DHL_DbgPrintf( 0, DHLDBG_SYS, "Your Board don't have CECSwitchStatus GPIO\n"); |
|---|
| 679 | return -1; |
|---|
| 680 | } |
|---|
| 681 | tmp = DHL_SYS_GetGPIO(GPIO_CEC_ON); |
|---|
| 682 | DHL_DbgPrintf( 0, DHLDBG_SYS, "Input is %d\n",tmp); |
|---|
| 683 | return tmp; |
|---|
| 684 | } |
|---|
| 685 | |
|---|
| 686 | DHL_RESULT DHL_SYS_SetBoardRev(DS_U32 BrdDiv, DS_U32 BrdRev) |
|---|
| 687 | { |
|---|
| 688 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 689 | |
|---|
| 690 | g_BrdDiv = BrdDiv; |
|---|
| 691 | g_BrdRev = BrdRev; |
|---|
| 692 | |
|---|
| 693 | return dhlResult; |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | DS_U32 DHL_SYS_GetBoardRev(void) |
|---|
| 697 | { |
|---|
| 698 | return g_BrdRev; |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | DS_U32 DHL_SYS_GetBoardDiv(void) |
|---|
| 702 | { |
|---|
| 703 | return g_BrdDiv; |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | int DHL_SYS_GetHDMISwMux(void) |
|---|
| 707 | { |
|---|
| 708 | int port1, port2; |
|---|
| 709 | int mux = 0; |
|---|
| 710 | |
|---|
| 711 | port1 = DD_SYS_GetGPIOOut(GPIO_HDMI_S1); |
|---|
| 712 | port2 = DD_SYS_GetGPIOOut(GPIO_HDMI_S2); |
|---|
| 713 | |
|---|
| 714 | if (port1 == 1 && port2 == 1) |
|---|
| 715 | { |
|---|
| 716 | mux = 0; |
|---|
| 717 | } |
|---|
| 718 | else if (port1 == 0 && port2 == 1) |
|---|
| 719 | { |
|---|
| 720 | mux = 1; |
|---|
| 721 | } |
|---|
| 722 | else if (port1 == 0 && port2 == 0) |
|---|
| 723 | { |
|---|
| 724 | mux = 2; |
|---|
| 725 | } |
|---|
| 726 | else if (port1 == 1 && port2 == 0) |
|---|
| 727 | { |
|---|
| 728 | mux = 3; |
|---|
| 729 | } |
|---|
| 730 | else |
|---|
| 731 | { |
|---|
| 732 | mux = -1; |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | return mux; |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | int DHL_SYS_SetHDMISwMux(int mux) |
|---|
| 739 | { |
|---|
| 740 | int ret = 0; |
|---|
| 741 | |
|---|
| 742 | switch (mux) |
|---|
| 743 | { |
|---|
| 744 | case 0: |
|---|
| 745 | DHL_SYS_SetGPIO(GPIO_HDMI_S1, 1); |
|---|
| 746 | DHL_SYS_SetGPIO(GPIO_HDMI_S2, 1); |
|---|
| 747 | break; |
|---|
| 748 | case 1: |
|---|
| 749 | DHL_SYS_SetGPIO(GPIO_HDMI_S1, 0); |
|---|
| 750 | DHL_SYS_SetGPIO(GPIO_HDMI_S2, 1); |
|---|
| 751 | break; |
|---|
| 752 | case 2: |
|---|
| 753 | DHL_SYS_SetGPIO(GPIO_HDMI_S1, 0); |
|---|
| 754 | DHL_SYS_SetGPIO(GPIO_HDMI_S2, 0); |
|---|
| 755 | break; |
|---|
| 756 | case 3: |
|---|
| 757 | DHL_SYS_SetGPIO(GPIO_HDMI_S1, 1); |
|---|
| 758 | DHL_SYS_SetGPIO(GPIO_HDMI_S2, 0); |
|---|
| 759 | break; |
|---|
| 760 | default: |
|---|
| 761 | ret = -1; |
|---|
| 762 | break; |
|---|
| 763 | } |
|---|
| 764 | // wait hdmi rx switch's switching time. spec is max 15ns |
|---|
| 765 | OS_mDelay(1); |
|---|
| 766 | |
|---|
| 767 | return ret; |
|---|
| 768 | } |
|---|
| 769 | |
|---|
| 770 | int DHL_SYS_SetHDMI_EDID_WREn(int onoff) |
|---|
| 771 | { |
|---|
| 772 | int ret = 0; |
|---|
| 773 | |
|---|
| 774 | if (onoff == 0) |
|---|
| 775 | { |
|---|
| 776 | ret = DHL_SYS_SetGPIO(GPIO_EDID_WR_EN, 0); |
|---|
| 777 | } |
|---|
| 778 | else if (onoff == 1) |
|---|
| 779 | { |
|---|
| 780 | ret = DHL_SYS_SetGPIO(GPIO_EDID_WR_EN, 1); |
|---|
| 781 | } |
|---|
| 782 | else |
|---|
| 783 | { |
|---|
| 784 | ret = -1; |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | return ret; |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | int DHL_SYS_GenHDMI_HPD(void) |
|---|
| 791 | { |
|---|
| 792 | DHL_SYS_SetGPIO(GPIO_HDMI_HPD, 1); |
|---|
| 793 | OS_mDelay(100); |
|---|
| 794 | DHL_SYS_SetGPIO(GPIO_HDMI_HPD, 0); |
|---|
| 795 | |
|---|
| 796 | return 0; |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | #if 0 |
|---|
| 800 | ___DEBUG_APIs___() |
|---|
| 801 | #endif |
|---|
| 802 | void DHL_SYS_DumpRegister(DS_U32 Address, DS_U32 cnt) |
|---|
| 803 | { |
|---|
| 804 | DS_U32 i; |
|---|
| 805 | |
|---|
| 806 | if ( Address < 0xA0000000 || Address > 0xBFFFFFFF || |
|---|
| 807 | (Address+cnt) < 0xA0000000 || (Address+cnt) > 0xBFFFFFFF || |
|---|
| 808 | cnt <= 0 ) { |
|---|
| 809 | printf("ERROR: Invalid arguments: Address = 0x%08lX, cnt = 0x%08lX\n", Address, cnt ); |
|---|
| 810 | return; |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | if ( Address & 3 ) { |
|---|
| 814 | printf("ERROR: Address shall be aligned to 4.\n"); |
|---|
| 815 | return; |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | for (i=0; i<cnt; i+=4) { |
|---|
| 819 | if ( !(i%16) ) |
|---|
| 820 | printf("\n%08lX ", Address+i); |
|---|
| 821 | |
|---|
| 822 | printf("%08lX ", DHL_SYS_ReadRegister(Address+i)); |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | printf("\n"); |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | void DHL_SYS_DumpRegisterWord(DS_U32 Address, DS_U32 cnt) |
|---|
| 829 | { |
|---|
| 830 | DS_U32 i; |
|---|
| 831 | |
|---|
| 832 | if ( Address < 0xA0000000 || Address > 0xBFFFFFFF || |
|---|
| 833 | (Address+cnt) < 0xA0000000 || (Address+cnt) > 0xBFFFFFFF || |
|---|
| 834 | cnt <= 0 ) { |
|---|
| 835 | printf("ERROR: Invalid arguments: Address = 0x%08lX, cnt = 0x%08lX\n", Address, cnt ); |
|---|
| 836 | return; |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | if ( Address & 1 ) { |
|---|
| 840 | printf("ERROR: Address shall be aligned to 4.\n"); |
|---|
| 841 | return; |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | for (i=0; i<cnt; i+=2) { |
|---|
| 845 | if ( !(i%16) ) |
|---|
| 846 | printf("\n%08lX ", Address+i); |
|---|
| 847 | |
|---|
| 848 | printf("%04lX ", OS_ReadRegisterWord(Address+i)); |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | printf("\n"); |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | void DHL_SYS_DumpMemory(DS_U32 Address, DS_U32 cnt) |
|---|
| 855 | { |
|---|
| 856 | DS_U32 i; |
|---|
| 857 | |
|---|
| 858 | if ( Address & 3 ) { |
|---|
| 859 | printf("ERROR: Address shall be aligned to 4.\n"); |
|---|
| 860 | return; |
|---|
| 861 | } |
|---|
| 862 | |
|---|
| 863 | for (i=0; i<cnt; i+=4) { |
|---|
| 864 | if ( !(i%16) ) |
|---|
| 865 | printf("\n%08lX ", Address+i); |
|---|
| 866 | |
|---|
| 867 | printf("%08lX ", *(DS_U32 *)(Address+i)); |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | printf("\n"); |
|---|
| 871 | } |
|---|
| 872 | |
|---|
| 873 | DS_U32 DHL_SYS_PrintFreeMem(const char *pfunc, int line) |
|---|
| 874 | { |
|---|
| 875 | DS_U32 totalMem, usedMem, freeMem, buffer, cached; |
|---|
| 876 | |
|---|
| 877 | if ( DHL_SYS_GetSysinfo( &totalMem, &usedMem, &freeMem, &buffer, &cached ) == DHL_OK ) { |
|---|
| 878 | DHL_DbgPrintf(0,DHLDBG_SYS,"|%s:%d| TotalMem: %ld K, UsedMem: %ld K, FreeMem: %ld K\n", pfunc ? pfunc : "Unknown", line, totalMem, usedMem, freeMem+buffer+cached); |
|---|
| 879 | DHL_DbgPrintf(0,DHLDBG_SYS, "|%s:%d| FreeMemory: %ld K (Free:%ld K + Buffer:%ld K + Cached:%ld K)\n", pfunc ? pfunc : "Unknown", line, freeMem+buffer+cached, freeMem, buffer, cached); |
|---|
| 880 | |
|---|
| 881 | return (freeMem+buffer+cached); |
|---|
| 882 | } else { |
|---|
| 883 | return -1; |
|---|
| 884 | } |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | static char sysinfoBuffer[1024]; |
|---|
| 888 | static int GetMemoryParam(char *iStream, const char *FindString, DS_U32 *pValue) |
|---|
| 889 | { |
|---|
| 890 | int ret = 0; |
|---|
| 891 | int n; |
|---|
| 892 | char *ptr; |
|---|
| 893 | |
|---|
| 894 | ptr = strstr(iStream, FindString); |
|---|
| 895 | if ( !ptr ) { |
|---|
| 896 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot find \"Mem:\" string from /proc/meminfo\n"); |
|---|
| 897 | ret = -1; |
|---|
| 898 | goto done; |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | ptr += strlen(FindString); |
|---|
| 902 | n=sscanf(ptr, "%ld", pValue); |
|---|
| 903 | if ( n != 1 ) { |
|---|
| 904 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot get inform from /proc/meminfo.\n"); |
|---|
| 905 | ret = -1; |
|---|
| 906 | goto done; |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | done: |
|---|
| 910 | return ret; |
|---|
| 911 | } |
|---|
| 912 | |
|---|
| 913 | DHL_RESULT DHL_SYS_GetSysinfo(DS_U32 *pTotalMem, DS_U32 *pUsedMem, DS_U32 *pFreeMem, DS_U32 *pBuffer, DS_U32 *pCached) |
|---|
| 914 | { |
|---|
| 915 | int fd = -1; |
|---|
| 916 | int n; |
|---|
| 917 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 918 | DS_U32 totalMem, usedMem, freeMem, shared, buffer, cached; |
|---|
| 919 | // char *ptr; |
|---|
| 920 | |
|---|
| 921 | fd = open("/proc/meminfo", S_IRUSR | S_IRGRP | S_IROTH ); |
|---|
| 922 | if ( fd < 0 ) { |
|---|
| 923 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot open /proc/meminfo\n"); |
|---|
| 924 | dhlResult = DHL_FAIL; |
|---|
| 925 | goto done2; |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | n = read(fd, sysinfoBuffer, 1024); |
|---|
| 929 | if ( n <= 0 ) { |
|---|
| 930 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot read from /proc/meminfo\n"); |
|---|
| 931 | dhlResult = DHL_FAIL; |
|---|
| 932 | goto done; |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | totalMem=usedMem=freeMem=shared=buffer=cached=0; |
|---|
| 936 | #if 0 |
|---|
| 937 | ptr = strstr(sysinfoBuffer, "Mem:"); |
|---|
| 938 | if ( !ptr ) { |
|---|
| 939 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot find \"Mem:\" string from /proc/meminfo\n"); |
|---|
| 940 | dhlResult = DHL_FAIL; |
|---|
| 941 | goto done; |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | ptr += strlen("Mem:"); |
|---|
| 945 | n=sscanf(ptr, "%ld%ld%ld%ld%ld%ld", &totalMem, &usedMem, &freeMem, &shared, &buffer, &cached); |
|---|
| 946 | if ( n != 6 ) { |
|---|
| 947 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot get inform from /proc/meminfo.\n"); |
|---|
| 948 | dhlResult = DHL_FAIL; |
|---|
| 949 | goto done; |
|---|
| 950 | } |
|---|
| 951 | #else |
|---|
| 952 | n=GetMemoryParam(sysinfoBuffer, "MemTotal:", &totalMem); |
|---|
| 953 | if ( n<0) { |
|---|
| 954 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot get MemTotal from /proc/meminfo.\n"); |
|---|
| 955 | dhlResult = DHL_FAIL; |
|---|
| 956 | goto done; |
|---|
| 957 | } |
|---|
| 958 | |
|---|
| 959 | n=GetMemoryParam(sysinfoBuffer, "MemFree:", &freeMem); |
|---|
| 960 | if ( n<0) { |
|---|
| 961 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot get MemFree from /proc/meminfo.\n"); |
|---|
| 962 | dhlResult = DHL_FAIL; |
|---|
| 963 | goto done; |
|---|
| 964 | } |
|---|
| 965 | |
|---|
| 966 | n=GetMemoryParam(sysinfoBuffer, "Buffers:", &buffer); |
|---|
| 967 | if ( n<0) { |
|---|
| 968 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot get Buffers from /proc/meminfo.\n"); |
|---|
| 969 | dhlResult = DHL_FAIL; |
|---|
| 970 | goto done; |
|---|
| 971 | } |
|---|
| 972 | |
|---|
| 973 | n=GetMemoryParam(sysinfoBuffer, "Cached:", &cached); |
|---|
| 974 | if ( n<0) { |
|---|
| 975 | DHL_DbgPrintf(0,DHLDBG_SYS, "ERROR: cannot get Cached from /proc/meminfo.\n"); |
|---|
| 976 | dhlResult = DHL_FAIL; |
|---|
| 977 | goto done; |
|---|
| 978 | } |
|---|
| 979 | |
|---|
| 980 | usedMem = totalMem - freeMem - buffer - cached; |
|---|
| 981 | #endif |
|---|
| 982 | |
|---|
| 983 | if (pTotalMem) *pTotalMem = totalMem; |
|---|
| 984 | if (pUsedMem) *pUsedMem = usedMem; |
|---|
| 985 | if (pFreeMem) *pFreeMem = freeMem; |
|---|
| 986 | if (pBuffer) *pBuffer = buffer; |
|---|
| 987 | if (pCached) *pCached = cached; |
|---|
| 988 | |
|---|
| 989 | done: |
|---|
| 990 | close(fd); |
|---|
| 991 | |
|---|
| 992 | done2: |
|---|
| 993 | return dhlResult; |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | #if 0 |
|---|
| 997 | ___Small_Commands___() |
|---|
| 998 | #endif |
|---|
| 999 | void rr(DS_U32 Address) |
|---|
| 1000 | { |
|---|
| 1001 | if ( (Address & 3) || Address < 0xA0000000 || Address > 0xBFFFFFFF ) { |
|---|
| 1002 | printf("Invalid address: 0x%08lX\n", Address); |
|---|
| 1003 | return; |
|---|
| 1004 | } |
|---|
| 1005 | |
|---|
| 1006 | printf("0x%08lX: %08lX\n", Address, DHL_SYS_ReadRegister( Address ) ); |
|---|
| 1007 | } |
|---|
| 1008 | |
|---|
| 1009 | void rw(DS_U32 Address, DS_U32 Value) |
|---|
| 1010 | { |
|---|
| 1011 | if ( (Address & 3) || Address < 0xA0000000 || Address > 0xBFFFFFFF ) { |
|---|
| 1012 | printf("Invalid address: 0x%08lX\n", Address); |
|---|
| 1013 | return; |
|---|
| 1014 | } |
|---|
| 1015 | |
|---|
| 1016 | printf("[Before] 0x%08lX: %08lX\n", Address, DHL_SYS_ReadRegister( Address ) ); |
|---|
| 1017 | DHL_SYS_WriteRegister( Address, Value ); |
|---|
| 1018 | printf("[After ] 0x%08lX: %08lX\n", Address, DHL_SYS_ReadRegister( Address ) ); |
|---|
| 1019 | } |
|---|
| 1020 | |
|---|
| 1021 | |
|---|
| 1022 | void rrw(DS_U32 Address) |
|---|
| 1023 | { |
|---|
| 1024 | if ( (Address & 1) || Address < 0xA0000000 || Address > 0xBFFFFFFF ) { |
|---|
| 1025 | printf("Invalid address: 0x%08lX\n", Address); |
|---|
| 1026 | return; |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | printf("0x%08lX: %08lX\n", Address, OS_ReadRegisterWord( Address ) ); |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | void rww(DS_U32 Address, DS_U32 Value) |
|---|
| 1033 | { |
|---|
| 1034 | if ( (Address & 1) || Address < 0xA0000000 || Address > 0xBFFFFFFF ) { |
|---|
| 1035 | printf("Invalid address: 0x%08lX\n", Address); |
|---|
| 1036 | return; |
|---|
| 1037 | } |
|---|
| 1038 | |
|---|
| 1039 | printf("[Before] 0x%08lX: %08lX\n", Address, OS_ReadRegisterWord( Address ) ); |
|---|
| 1040 | OS_WriteRegisterWord( Address, Value ); |
|---|
| 1041 | printf("[After ] 0x%08lX: %08lX\n", Address, OS_ReadRegisterWord( Address ) ); |
|---|
| 1042 | } |
|---|
| 1043 | |
|---|
| 1044 | |
|---|
| 1045 | void rrb(DS_U32 Address) |
|---|
| 1046 | { |
|---|
| 1047 | if ( Address < 0xA0000000 || Address > 0xBFFFFFFF ) { |
|---|
| 1048 | printf("Invalid address: 0x%08lX\n", Address); |
|---|
| 1049 | return; |
|---|
| 1050 | } |
|---|
| 1051 | |
|---|
| 1052 | printf("0x%08lX: %08lX\n", Address, OS_ReadRegisterByte( Address ) ); |
|---|
| 1053 | } |
|---|
| 1054 | |
|---|
| 1055 | void rwb(DS_U32 Address, DS_U32 Value) |
|---|
| 1056 | { |
|---|
| 1057 | if ( Address < 0xA0000000 || Address > 0xBFFFFFFF ) { |
|---|
| 1058 | printf("Invalid address: 0x%08lX\n", Address); |
|---|
| 1059 | return; |
|---|
| 1060 | } |
|---|
| 1061 | |
|---|
| 1062 | printf("[Before] 0x%08lX: %08lX\n", Address, OS_ReadRegisterByte( Address ) ); |
|---|
| 1063 | OS_WriteRegisterByte( Address, Value ); |
|---|
| 1064 | printf("[After ] 0x%08lX: %08lX\n", Address, OS_ReadRegisterByte( Address ) ); |
|---|
| 1065 | } |
|---|
| 1066 | |
|---|
| 1067 | void MallocAndFill(int size) |
|---|
| 1068 | { |
|---|
| 1069 | char *ptr; |
|---|
| 1070 | int i; |
|---|
| 1071 | |
|---|
| 1072 | ptr = malloc(size); |
|---|
| 1073 | for (i=0; i<size; i++) |
|---|
| 1074 | ptr[i] = (char)i; |
|---|
| 1075 | |
|---|
| 1076 | printf("Malloc at 0x%08lX, size=%d\n", (unsigned long)ptr, size); |
|---|
| 1077 | } |
|---|
| 1078 | |
|---|
| 1079 | void Fill(int addr, int data, int size) |
|---|
| 1080 | { |
|---|
| 1081 | char *ptr; |
|---|
| 1082 | int i; |
|---|
| 1083 | |
|---|
| 1084 | ptr = (char *)addr; |
|---|
| 1085 | for (i=0; i<size; i++) |
|---|
| 1086 | ptr[i] = (char)data; |
|---|
| 1087 | |
|---|
| 1088 | printf("Fill at 0x%08lX, size=%d\n", (unsigned long)ptr, size); |
|---|
| 1089 | } |
|---|
| 1090 | |
|---|
| 1091 | void RegFill(int addr, int data, int size) |
|---|
| 1092 | { |
|---|
| 1093 | int i; |
|---|
| 1094 | |
|---|
| 1095 | for (i=0; i<size; i+=4) |
|---|
| 1096 | DD_SYS_SetRegister32( addr+i, data ); |
|---|
| 1097 | |
|---|
| 1098 | printf("Fill at 0x%08lX, size=%d\n", (unsigned long)addr, size); |
|---|
| 1099 | } |
|---|
| 1100 | |
|---|
| 1101 | void Fill32(int addr, int data, int size) |
|---|
| 1102 | { |
|---|
| 1103 | DS_U32 *ptr; |
|---|
| 1104 | int i; |
|---|
| 1105 | |
|---|
| 1106 | ptr = (DS_U32 *)addr; |
|---|
| 1107 | for (i=0; i<size; i++) |
|---|
| 1108 | ptr[i] = (DS_U32)data; |
|---|
| 1109 | |
|---|
| 1110 | printf("Fill at 0x%08lX, size=%d\n", (unsigned long)ptr, size); |
|---|
| 1111 | } |
|---|
| 1112 | |
|---|
| 1113 | void dumpFreeMemory(void) |
|---|
| 1114 | { |
|---|
| 1115 | system("cat /proc/meminfo"); |
|---|
| 1116 | } |
|---|
| 1117 | |
|---|
| 1118 | void hdumpver(void) |
|---|
| 1119 | { |
|---|
| 1120 | DHL_SYS_DumpVersion(); |
|---|
| 1121 | } |
|---|
| 1122 | |
|---|
| 1123 | void get_i2c(int bus, int addr, int subAddr) |
|---|
| 1124 | { |
|---|
| 1125 | int n=0; |
|---|
| 1126 | unsigned char buf[256]; |
|---|
| 1127 | |
|---|
| 1128 | n = DHL_SYS_I2cReadEx(bus, addr, 1, subAddr, buf, 2); |
|---|
| 1129 | if ( n <= 0 ) { |
|---|
| 1130 | printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 1131 | } |
|---|
| 1132 | |
|---|
| 1133 | printf("I2C-BUS%d: DEVADDR[0x%02X] ADDR[0x%02X] => 0x%02X-0x%02X\n", bus, addr, subAddr, buf[0], buf[1]); |
|---|
| 1134 | } |
|---|
| 1135 | |
|---|
| 1136 | void get_i2c_byte(int bus, int addr, int subAddr) |
|---|
| 1137 | { |
|---|
| 1138 | int n=0; |
|---|
| 1139 | unsigned char buf[256]; |
|---|
| 1140 | |
|---|
| 1141 | n = DHL_SYS_I2cReadEx(bus, addr, 1, subAddr, buf, 1); |
|---|
| 1142 | if ( n <= 0 ) { |
|---|
| 1143 | printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 1144 | } |
|---|
| 1145 | |
|---|
| 1146 | printf("I2C-BUS%d: DEVADDR[0x%02X] ADDR[0x%02X] => 0x%02X\n", bus, addr, subAddr, buf[0]); |
|---|
| 1147 | } |
|---|
| 1148 | |
|---|
| 1149 | void write_i2c_byte(int bus, int addr, int subAddr, int data) |
|---|
| 1150 | { |
|---|
| 1151 | int n=0; |
|---|
| 1152 | unsigned char buf[256]; |
|---|
| 1153 | |
|---|
| 1154 | buf[0] = data; |
|---|
| 1155 | n = DHL_SYS_I2cWriteEx(bus, addr, 1, subAddr, buf, 1); |
|---|
| 1156 | if ( n <= 0 ) { |
|---|
| 1157 | printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 1158 | } |
|---|
| 1159 | |
|---|
| 1160 | printf("I2C-BUS%d: DEVADDR[0x%02X] ADDR[0x%02X] <= 0x%02X\n", bus, addr, subAddr, buf[0]); |
|---|
| 1161 | } |
|---|
| 1162 | |
|---|
| 1163 | void ifconfig(int x, int y, int z, int w) |
|---|
| 1164 | { |
|---|
| 1165 | char buf[256]; |
|---|
| 1166 | |
|---|
| 1167 | sprintf(buf, "ifconfig eth0 %d.%d.%d.%d\n", x, y, z, w); |
|---|
| 1168 | system(buf); |
|---|
| 1169 | } |
|---|
| 1170 | |
|---|
| 1171 | void shcmd(void) |
|---|
| 1172 | { |
|---|
| 1173 | system("/bin/busybox sh"); |
|---|
| 1174 | } |
|---|
| 1175 | |
|---|
| 1176 | static int bIdleStart = 0; |
|---|
| 1177 | typedef void (cbFunc_t)(DS_U32 tick); |
|---|
| 1178 | static cbFunc_t *cbTickFunc = (cbFunc_t *)0; |
|---|
| 1179 | |
|---|
| 1180 | void tIdleTask(DS_U32 arg) |
|---|
| 1181 | { |
|---|
| 1182 | volatile DS_U32 oldTick=0, elapsedTick; |
|---|
| 1183 | register int loop_cnt; |
|---|
| 1184 | static int cnt; |
|---|
| 1185 | |
|---|
| 1186 | loop_cnt = 0; |
|---|
| 1187 | while (1) { |
|---|
| 1188 | if (bIdleStart == 0) { |
|---|
| 1189 | break; |
|---|
| 1190 | } |
|---|
| 1191 | #if 1 |
|---|
| 1192 | elapsedTick = OS_GetTickCount()-oldTick; |
|---|
| 1193 | if ( elapsedTick > 100 && OS_GetTickCount() != oldTick ) { |
|---|
| 1194 | oldTick = OS_GetTickCount(); |
|---|
| 1195 | printf("|%ld.%02ld| Counts per sec: %ld\n", oldTick/100, oldTick%100, (cnt * 100)/elapsedTick ); |
|---|
| 1196 | cnt = 0; |
|---|
| 1197 | |
|---|
| 1198 | DHL_SYS_PrintFreeMem(0, 0); |
|---|
| 1199 | |
|---|
| 1200 | if ( cbTickFunc ) |
|---|
| 1201 | cbTickFunc(oldTick); |
|---|
| 1202 | //if ( loop_cnt++ > 1000 ) |
|---|
| 1203 | //break; |
|---|
| 1204 | } |
|---|
| 1205 | #else |
|---|
| 1206 | oldTick = OS_GetTickCount(); |
|---|
| 1207 | for(i=0; i<arg; i++) |
|---|
| 1208 | ; |
|---|
| 1209 | curTick = OS_GetTickCount(); |
|---|
| 1210 | elapsedTick = curTick-oldTick; |
|---|
| 1211 | if (elapsedTick<0) { |
|---|
| 1212 | printf("ElapsedTick: %d (%ld-%ld)\n", elapsedTick, curTick, oldTick); |
|---|
| 1213 | printf("Prev TV: %ld.%ld, Cur TV:%ld.%ld\n", prevTv.tv_sec, prevTv.tv_usec, curTv.tv_sec, curTv.tv_usec); |
|---|
| 1214 | } |
|---|
| 1215 | #endif |
|---|
| 1216 | cnt++; |
|---|
| 1217 | } |
|---|
| 1218 | printf("|%s| IDLE task terminated.\n", __FUNCTION__); |
|---|
| 1219 | |
|---|
| 1220 | OS_DeleteTask(0); |
|---|
| 1221 | } |
|---|
| 1222 | |
|---|
| 1223 | void start_idle_task(int prio, int arg) |
|---|
| 1224 | { |
|---|
| 1225 | printf("Start IDLE task with prio=%d, arg=%d\n", prio, arg); |
|---|
| 1226 | |
|---|
| 1227 | bIdleStart = 1; |
|---|
| 1228 | OS_SpawnTask( tIdleTask, "tAgingTask", prio, 4096, (DS_U32)arg); |
|---|
| 1229 | } |
|---|
| 1230 | |
|---|
| 1231 | void set_tick_cbfunc(cbFunc_t *cbFunc) |
|---|
| 1232 | { |
|---|
| 1233 | cbTickFunc = cbFunc; |
|---|
| 1234 | } |
|---|
| 1235 | |
|---|
| 1236 | void stop_idle_task(void) |
|---|
| 1237 | { |
|---|
| 1238 | printf("Stop IDLE task.\n"); |
|---|
| 1239 | |
|---|
| 1240 | bIdleStart = 0; |
|---|
| 1241 | } |
|---|
| 1242 | |
|---|
| 1243 | void print_pid() |
|---|
| 1244 | { |
|---|
| 1245 | printf("PID: %d\n", (int)getpid()); |
|---|
| 1246 | } |
|---|