-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
135 lines (113 loc) · 4.79 KB
/
Copy pathmain.c
File metadata and controls
135 lines (113 loc) · 4.79 KB
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
// SPDX-License-Identifier: GPL-3.0
/*
* Author(s): Raphaël GALLAIS-POU <raphael.gallais.pou@gmail.com>
* gcc -static -DDSKW_TOGGLE main.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lvds.h"
int LVDS_Decode(int reg, int *bitmap, int lsb)
{
if (reg > 0xFFFFF || reg < 0x0)
return 1;
if (!((lsb == 0) || (lsb == 1)))
return 1;
if (!lsb)
{
bitmap[0] = ((reg & BIT_0_Msk) >> BIT_0_Pos);
bitmap[1] = ((reg & BIT_1_Msk) >> BIT_1_Pos);
bitmap[2] = ((reg & BIT_2_Msk) >> BIT_2_Pos);
} else {
bitmap[3] = ((reg & BIT_3_Msk) >> BIT_3_Pos);
bitmap[4] = ((reg & BIT_4_Msk) >> BIT_4_Pos);
bitmap[5] = ((reg & BIT_5_Msk) >> BIT_5_Pos);
bitmap[6] = ((reg & BIT_6_Msk) >> BIT_6_Pos);
}
return 0;
}
int LVDS_DecodeLane(int lsbreg, int msbreg, int *bitmap, char *lane)
{
char str[5] = {0};
if (LVDS_Decode(msbreg, bitmap, 0))
return 1;
if (LVDS_Decode(lsbreg, bitmap, 1))
return 1;
for (int i=0; i<7; i++)
{
LVDS_Convert(bitmap[i], str);
snprintf(lane + i*4*sizeof(char), 5, "%s", str);
}
return 0;
}
int LVDS_Convert(int bit, char *str)
{
switch (bit)
{
case HAL_LVDS_MAP_R_0: snprintf(str, 5, "<R0>"); break;
case HAL_LVDS_MAP_R_1: snprintf(str, 5, "<R1>"); break;
case HAL_LVDS_MAP_R_2: snprintf(str, 5, "<R2>"); break;
case HAL_LVDS_MAP_R_3: snprintf(str, 5, "<R3>"); break;
case HAL_LVDS_MAP_R_4: snprintf(str, 5, "<R4>"); break;
case HAL_LVDS_MAP_R_5: snprintf(str, 5, "<R5>"); break;
case HAL_LVDS_MAP_R_6: snprintf(str, 5, "<R6>"); break;
case HAL_LVDS_MAP_R_7: snprintf(str, 5, "<R7>"); break;
case HAL_LVDS_MAP_G_0: snprintf(str, 5, "<G0>"); break;
case HAL_LVDS_MAP_G_1: snprintf(str, 5, "<G1>"); break;
case HAL_LVDS_MAP_G_2: snprintf(str, 5, "<G2>"); break;
case HAL_LVDS_MAP_G_3: snprintf(str, 5, "<G3>"); break;
case HAL_LVDS_MAP_G_4: snprintf(str, 5, "<G4>"); break;
case HAL_LVDS_MAP_G_5: snprintf(str, 5, "<G5>"); break;
case HAL_LVDS_MAP_G_6: snprintf(str, 5, "<G6>"); break;
case HAL_LVDS_MAP_G_7: snprintf(str, 5, "<G7>"); break;
case HAL_LVDS_MAP_B_0: snprintf(str, 5, "<B0>"); break;
case HAL_LVDS_MAP_B_1: snprintf(str, 5, "<B1>"); break;
case HAL_LVDS_MAP_B_2: snprintf(str, 5, "<B2>"); break;
case HAL_LVDS_MAP_B_3: snprintf(str, 5, "<B3>"); break;
case HAL_LVDS_MAP_B_4: snprintf(str, 5, "<B4>"); break;
case HAL_LVDS_MAP_B_5: snprintf(str, 5, "<B5>"); break;
case HAL_LVDS_MAP_B_6: snprintf(str, 5, "<B6>"); break;
case HAL_LVDS_MAP_B_7: snprintf(str, 5, "<B7>"); break;
case HAL_LVDS_MAP_H_S: snprintf(str, 5, "<HS>"); break;
case HAL_LVDS_MAP_V_S: snprintf(str, 5, "<VS>"); break;
case HAL_LVDS_MAP_D_E: snprintf(str, 5, "<DE>"); break;
case HAL_LVDS_MAP_C_E: snprintf(str, 5, "<CE>"); break;
case HAL_LVDS_MAP_C_I: snprintf(str, 5, "<CI>"); break;
case HAL_LVDS_MAP_TOG: snprintf(str, 5, "<TO>"); break;
case HAL_LVDS_MAP_ONE: snprintf(str, 5, "<01>"); break;
case HAL_LVDS_MAP_ZER: snprintf(str, 5, "<00>"); break;
default: break;
}
return 0;
}
int LVDS_Encode(int *bitmap, char *lane)
{
char bit[3] = {0};
if (strlen(lane) != 12)
return 1;
if (bitmap == NULL)
return 1;
strncpy(lane, bit, (size_t) 2);
bit[2] = '\0';
// TODO convert to int
return 0;
}
int main(int argc, char **argv)
{
int bitmap[7] = {0};
char lane[36] = {0};
if (argc != 3)
{
printf("./a.out msbreg lsbreg\n");
printf("Example :\n");
printf("./a.out 0x00007BDF 0x000FFFDE\n");
return 1;
}
int msbreg = (int)strtol(argv[1], NULL, HEX_BASE);
int lsbreg = (int)strtol(argv[2], NULL, HEX_BASE);
LVDS_DecodeLane(lsbreg, msbreg, bitmap, lane);
printf("%s\n", lane);
printf(" %02x %02x %02x %02x %02x %02x %02x\n",
bitmap[0], bitmap[1], bitmap[2], bitmap[3], bitmap[4], bitmap[5], bitmap[6]);
return 0;
}