| 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 |
#include "Command.h" |
| 46 |
#include "Console.h" |
| 47 |
#include "ad5172.h" |
| 48 |
#include "TIME.h" |
| 49 |
|
| 50 |
#define VDD 3.2 |
| 51 |
#define VDD_VSS VDD/2 |
| 52 |
#define MAXPOS 255 |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
const struct cmd_info cmdList[] = { |
| 58 |
[0] = { |
| 59 |
.name = "help?", |
| 60 |
.description = "Displays all available commands.", |
| 61 |
.acceptedValue = "None", |
| 62 |
.example = "", |
| 63 |
}, |
| 64 |
[1] = { |
| 65 |
.name = "rdac=", |
| 66 |
.description = "Load the wiper register with a give value.", |
| 67 |
.acceptedValue = "Accepted value:\r\n\ |
| 68 |
\tchannel:\r\n\ |
| 69 |
\t0 to 3 in function of the device type\r\n\ |
| 70 |
\tvalue:\r\n\ |
| 71 |
\t0 .. 255 - wiper register value", |
| 72 |
.example = "To load the wiper register of channel B with 128, \ |
| 73 |
type: rdac=1 128", |
| 74 |
}, |
| 75 |
[2] = { |
| 76 |
.name = "rdac?", |
| 77 |
.description = "Read back the value of the wiper register.", |
| 78 |
.acceptedValue = "Accepted values:\r\n\ |
| 79 |
\tchannel:\r\n\ |
| 80 |
\t0 .. 3 in function of the device type", |
| 81 |
.example = "To read back the value of the wiper register of channel B, \ |
| 82 |
type: rdac?1", |
| 83 |
}, |
| 84 |
[3] = { |
| 85 |
.name = "wbuf1?", |
| 86 |
.description = "Read back the value of the Wiper Buffer in voltage. \ |
| 87 |
(VDD=3.2V)", |
| 88 |
.acceptedValue = "None", |
| 89 |
.example = "", |
| 90 |
}, |
| 91 |
[4] = { |
| 92 |
.name = "shutdown=", |
| 93 |
.description = "Shutdown connects wiper to B terminal and open circuits\ |
| 94 |
the A terminal.", |
| 95 |
.acceptedValue = "Accepted values:\r\n\ |
| 96 |
\tchannel:\r\n\ |
| 97 |
\t0 .. 3 in function of the device type", |
| 98 |
.example = "To shutdown (or bring back from shutdown) the RDAC of the channel 0, type: shutdown=0", |
| 99 |
}, |
| 100 |
[5] = { |
| 101 |
.name = "shutdown?", |
| 102 |
.description = "Notify about the state of the selected RDAC. (It is in shutdown or not.)", |
| 103 |
.acceptedValue = "Accepted values:\r\n\ |
| 104 |
\tchannel:\r\n\ |
| 105 |
\t0 .. 3 in function of the device type", |
| 106 |
.example = "To verify the state of RDAC at channel 1, type shutdown?1", |
| 107 |
} |
| 108 |
}; |
| 109 |
|
| 110 |
const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info)); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
cmdFunction cmdFunctions[6] = {GetHelp, SetRdac, GetRdac, GetWBuf1, SetShutdown, |
| 116 |
GetShutdown}; |
| 117 |
|
| 118 |
AD5172_type_t deviceType; |
| 119 |
|
| 120 |
unsigned char channelNo = 0; |
| 121 |
unsigned char channelState[4] = {0,}; |
| 122 |
unsigned short rdacBuffer[4] = {0,}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
void DisplayError(unsigned char funcNo) |
| 130 |
{ |
| 131 |
|
| 132 |
CONSOLE_Print("Invalid parameter!\r\n"); |
| 133 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \ |
| 134 |
(char*)cmdList[funcNo].description, |
| 135 |
(char*)cmdList[funcNo].acceptedValue); |
| 136 |
CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
void DisplayCmdList() |
| 145 |
{ |
| 146 |
unsigned char displayCmd; |
| 147 |
|
| 148 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 149 |
{ |
| 150 |
CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \ |
| 151 |
(char*)cmdList[displayCmd].description); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
void paramLimit(double* param, |
| 164 |
unsigned short lowerLimit, |
| 165 |
unsigned short upperLimit) |
| 166 |
{ |
| 167 |
if(*param < lowerLimit) |
| 168 |
{ |
| 169 |
*param = lowerLimit; |
| 170 |
} |
| 171 |
else |
| 172 |
{ |
| 173 |
if(*param > upperLimit) |
| 174 |
{ |
| 175 |
*param = upperLimit; |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
void GetHelp(double* param, char paramNo) |
| 186 |
{ |
| 187 |
unsigned char displayCmd; |
| 188 |
|
| 189 |
CONSOLE_Print("Available commands:\r\n"); |
| 190 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 191 |
{ |
| 192 |
CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name, |
| 193 |
(char*)cmdList[displayCmd].description, |
| 194 |
(char*)cmdList[displayCmd].acceptedValue); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
void DoDeviceLock(void) |
| 204 |
{ |
| 205 |
char device = 0; |
| 206 |
char deviceLocked = -1; |
| 207 |
|
| 208 |
while(deviceLocked < 0) |
| 209 |
{ |
| 210 |
CONSOLE_Print("Please specify your device.\r\n\ |
| 211 |
For AD5162 type: 0\r\n\ |
| 212 |
For AD5172 type: 1\r\n\ |
| 213 |
For AD8403 type: 2\r\n"); |
| 214 |
|
| 215 |
CONSOLE_GetCommand(&device); |
| 216 |
if((device >= 0x30) && (device <= 0x33)) |
| 217 |
{ |
| 218 |
deviceLocked = 1; |
| 219 |
switch(device) |
| 220 |
{ |
| 221 |
case 0x30 : |
| 222 |
{ |
| 223 |
deviceType = ID_AD5162; |
| 224 |
channelNo = 2; |
| 225 |
break; |
| 226 |
} |
| 227 |
case 0x31 : |
| 228 |
{ |
| 229 |
deviceType = ID_AD5172; |
| 230 |
channelNo = 2; |
| 231 |
break; |
| 232 |
} |
| 233 |
case 0x32 : |
| 234 |
{ |
| 235 |
deviceType = ID_AD8403; |
| 236 |
channelNo = 4; |
| 237 |
break; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
else |
| 242 |
{ |
| 243 |
CONSOLE_Print("Please type the number corresponding for \ |
| 244 |
your device!\r\n"); |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
char DoDeviceInit(void) |
| 259 |
{ |
| 260 |
DoDeviceLock(); |
| 261 |
|
| 262 |
if(AD5172_Init(deviceType) == 0) |
| 263 |
{ |
| 264 |
CONSOLE_Print("Device OK\r\n"); |
| 265 |
DisplayCmdList(); |
| 266 |
return SUCCESS; |
| 267 |
} |
| 268 |
else |
| 269 |
{ |
| 270 |
CONSOLE_Print("Device Error\r\n"); |
| 271 |
return ERROR; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
void SetRdac(double* param, char paramNo) |
| 285 |
{ |
| 286 |
unsigned char channel = 0; |
| 287 |
unsigned char data8 = 0; |
| 288 |
|
| 289 |
|
| 290 |
if(paramNo >= 2) |
| 291 |
{ |
| 292 |
paramLimit(¶m[0], 0, channelNo-1); |
| 293 |
paramLimit(¶m[1], 0, MAXPOS); |
| 294 |
channel = (unsigned char)param[0]; |
| 295 |
data8 = (unsigned char)param[1]; |
| 296 |
|
| 297 |
AD5172_Write(channel, 0, data8); |
| 298 |
rdacBuffer[channel] = data8; |
| 299 |
|
| 300 |
CONSOLE_Print("RDAC[%d]=%d\r\n", channel, data8); |
| 301 |
} |
| 302 |
else |
| 303 |
{ |
| 304 |
|
| 305 |
DisplayError(1); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
void GetRdac(double* param, char paramNo) |
| 318 |
{ |
| 319 |
unsigned char channel = 0; |
| 320 |
|
| 321 |
|
| 322 |
if(paramNo >= 1) |
| 323 |
{ |
| 324 |
paramLimit(¶m[0], 0, channelNo-1); |
| 325 |
channel = (unsigned char)param[0]; |
| 326 |
|
| 327 |
if(deviceType == ID_AD5172) |
| 328 |
{ |
| 329 |
CONSOLE_Print("RDAC[%d]=%d\r\n", channel, \ |
| 330 |
AD5172_Read(channel, NULL)); |
| 331 |
} |
| 332 |
else |
| 333 |
{ |
| 334 |
CONSOLE_Print("RDAC[%d]=%d\r\n", channel, \ |
| 335 |
rdacBuffer[channel]); |
| 336 |
} |
| 337 |
|
| 338 |
} |
| 339 |
else |
| 340 |
{ |
| 341 |
|
| 342 |
DisplayError(2); |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
void GetWBuf1(double* param, char paramNo) |
| 355 |
{ |
| 356 |
float wBuf1 = 0; |
| 357 |
|
| 358 |
wBuf1 = VDD_VSS * ((float)rdacBuffer[0]/256); |
| 359 |
CONSOLE_Print("WBUF1 = %1.2fV\n\r", wBuf1); |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
void SetShutdown(double* param, char paramNo) |
| 374 |
{ |
| 375 |
unsigned char channel = 0; |
| 376 |
unsigned char command = 0; |
| 377 |
|
| 378 |
if((deviceType == ID_AD5172) || |
| 379 |
(deviceType == ID_AD8403)) |
| 380 |
{ |
| 381 |
|
| 382 |
if(paramNo >= 1) |
| 383 |
{ |
| 384 |
paramLimit(¶m[0], 0, channelNo-1); |
| 385 |
channel = (unsigned char)param[0]; |
| 386 |
|
| 387 |
if(channelState[channel]) |
| 388 |
{ |
| 389 |
command |= AD5172_CNTR_SD; |
| 390 |
} |
| 391 |
command ^= AD5172_CNTR_SD; |
| 392 |
channelState[channel] ^= 0x1; |
| 393 |
if(deviceType == ID_AD5172) |
| 394 |
{ |
| 395 |
AD5172_Write(channel, command, 0); |
| 396 |
} |
| 397 |
else |
| 398 |
{ |
| 399 |
if(channelState[channel]) |
| 400 |
{ |
| 401 |
AD5172_SHUTDOWN_LOW; |
| 402 |
} |
| 403 |
else |
| 404 |
{ |
| 405 |
AD5172_SHUTDOWN_HIGH; |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
if((command & AD5172_CNTR_SD) != 0) |
| 410 |
{ |
| 411 |
CONSOLE_Print("RDACs OFF.\r\n"); |
| 412 |
} |
| 413 |
else |
| 414 |
{ |
| 415 |
CONSOLE_Print("RDACs ON.\r\n"); |
| 416 |
} |
| 417 |
} |
| 418 |
else |
| 419 |
{ |
| 420 |
|
| 421 |
DisplayError(4); |
| 422 |
} |
| 423 |
} |
| 424 |
else |
| 425 |
{ |
| 426 |
CONSOLE_Print("This function is not supported by the current \ |
| 427 |
device.\r\n"); |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
void GetShutdown(double* param, char paramNo) |
| 440 |
{ |
| 441 |
unsigned char channel = 0; |
| 442 |
|
| 443 |
if((deviceType == ID_AD5172) || |
| 444 |
(deviceType == ID_AD8403)) |
| 445 |
{ |
| 446 |
|
| 447 |
if(paramNo >= 1) |
| 448 |
{ |
| 449 |
paramLimit(¶m[0], 0, channelNo-1); |
| 450 |
channel = (unsigned char)param[0]; |
| 451 |
|
| 452 |
if(channelState[channel] != 0) |
| 453 |
{ |
| 454 |
CONSOLE_Print("Shutdown pin is in active state.\r\n"); |
| 455 |
} |
| 456 |
else |
| 457 |
{ |
| 458 |
CONSOLE_Print("Shutdown pin is in inactive state.\r\n"); |
| 459 |
} |
| 460 |
} |
| 461 |
else |
| 462 |
{ |
| 463 |
|
| 464 |
DisplayError(4); |
| 465 |
} |
| 466 |
} |
| 467 |
else |
| 468 |
{ |
| 469 |
CONSOLE_Print("This function is not supported by the current \ |
| 470 |
device.\r\n"); |
| 471 |
} |
| 472 |
} |