forked from Polarisru/updiprog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevices.c
191 lines (178 loc) · 3.27 KB
/
devices.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
#include <string.h>
#include "devices.h"
tDevice DEVICES_List[] =
{
{
"tiny321x",
0x8000,
32 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny161x",
0x8000,
16 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny81x",
0x8000,
8 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny41x",
0x8000,
4 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
},
{
"tiny21x",
0x8000,
2 * 1024,
64,
0x0F00,
0x1000,
0x1100,
0x1280,
0x1300,
9
}
};
static int8_t DEVICE_Id = DEVICE_UNKNOWN_ID;
/** \brief Get device ID from name string
*
* \param [in] name Name to find as string
* \return index of the found device or -1 as error
*
*/
int8_t DEVICES_GetId(char *name)
{
uint8_t i;
for (i = 0; i < sizeof(DEVICES_List) / sizeof(tDevice); i++)
{
if (strcmp(name, DEVICES_List[i].name) == 0)
{
DEVICE_Id = i;
return i;
}
}
DEVICE_Id = DEVICE_UNKNOWN_ID;
return -1;
}
/** \brief Get flash memory length for selected device
*
* \return Size of the flash memory as uint16_t
*
*/
uint16_t DEVICES_GetFlashLength(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].flash_size;
}
/** \brief Get flash start address for selected device
*
* \return Address of the flash area as uint16_t
*
*/
uint16_t DEVICES_GetFlashStart(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].flash_start;
}
/** \brief Get flash page size for selected device
*
* \return Flash page size as uint16_t
*
*/
uint16_t DEVICES_GetPageSize(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].flash_pagesize;
}
/** \brief Get NVM control registers address for selected device
*
* \return NVM registers adress as uint16_t
*
*/
uint16_t DEVICES_GetNvmctrlAddress(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].nvmctrl_address;
}
/** \brief Get fuses address for selected device
*
* \return Fuses address as uint16_t
*
*/
uint16_t DEVICES_GetFusesAddress(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].fuses_address;
}
/** \brief Get number of the fuses for selected device
*
* \return Number of the fuses as uint8_t
*
*/
uint8_t DEVICES_GetFusesNumber(void)
{
if (DEVICE_Id == DEVICE_UNKNOWN_ID)
return 0;
else
return DEVICES_List[DEVICE_Id].number_of_fuses;
}
/** \brief Get number of devices in the list
*
* \return Number of the devices as uint8_t
*
*/
uint8_t DEVICES_GetNumber(void)
{
return (uint8_t)(sizeof(DEVICES_List) / sizeof(tDevice));
}
/** \brief Get string name of the device by ID
*
* \return Device name as string
*
*/
char *DEVICES_GetNameByNumber(uint8_t number)
{
if (number >= sizeof(DEVICES_List) / sizeof(tDevice))
number = 0;
return DEVICES_List[number].name;
}