|
10 | 10 |
|
11 | 11 | #define __STDC_FORMAT_MACROS |
12 | 12 | #include <cinttypes> |
| 13 | +#include <iomanip> |
13 | 14 | #include <iostream> |
| 15 | +#include <list> |
| 16 | +#include <sstream> |
14 | 17 | #include <string> |
15 | 18 |
|
16 | 19 | #include "device.hpp" |
@@ -284,76 +287,85 @@ void LatticeSSPI::program(unsigned int /*offset*/, bool /*unprotect_flash*/) |
284 | 287 | throw std::exception(); |
285 | 288 | } |
286 | 289 |
|
| 290 | +typedef struct { |
| 291 | + std::string description; |
| 292 | + uint8_t offset; |
| 293 | + uint8_t size; |
| 294 | + std::map<int, std::string> reg_cnt; |
| 295 | +} reg_struct_t; |
| 296 | + |
| 297 | +#define REG_ENTRY(_description, _offset, _size, ...) \ |
| 298 | + {_description, _offset, _size, {__VA_ARGS__}} |
| 299 | + |
| 300 | +static const std::map<std::string, std::list<reg_struct_t>> reg_content = { |
| 301 | + {"StatusRegister", std::list<reg_struct_t>{ |
| 302 | + REG_ENTRY("Transparent Mode", 0, 1, {0, "No"}, {1, "Yes"}), |
| 303 | + REG_ENTRY("Config Target Selection", 1, 3, {0, "SRAM array"}, {1, "Efuse"}), |
| 304 | + REG_ENTRY("JTAG Active", 4, 1, {0, "No"}, {1, "Yes"}), |
| 305 | + REG_ENTRY("PWD Protect", 5, 1, {0, "No"}, {1, "Yes"}), |
| 306 | + REG_ENTRY("Decrypt Enable", 7, 1, {0, "No"}, {1, "Yes"}), |
| 307 | + REG_ENTRY("Done", 8, 1, {0, "No"}, {1, "Yes"}), |
| 308 | + REG_ENTRY("ISC Enable", 9, 1, {0, "No"}, {1, "Yes"}), |
| 309 | + REG_ENTRY("Write Enable", 11, 1, {0, "Not Writable"}, {1, "Writable"}), |
| 310 | + REG_ENTRY("Read Enable", 11, 1, {0, "Not Readable"}, {1, "Readable"}), |
| 311 | + REG_ENTRY("Busy Flag", 12, 1, {0, "No"}, {1, "Yes"}), |
| 312 | + REG_ENTRY("Fail Flag", 13, 1, {0, "No"}, {1, "Yes"}), |
| 313 | + REG_ENTRY("FFEA OTP", 14, 1, {0, "No"}, {1, "Yes"}), |
| 314 | + REG_ENTRY("Decrypt Only", 15, 1, {0, "No"}, {1, "Yes"}), |
| 315 | + REG_ENTRY("PWD Enable", 16, 1, {0, "No"}, {1, "Yes"}), |
| 316 | + REG_ENTRY("Std Preamble", 20, 1, {0, "No"}, {1, "Yes"}), |
| 317 | + REG_ENTRY("SPIm Fail1", 21, 1, {0, "No"}, {1, "Yes"}), |
| 318 | + REG_ENTRY("BSE Error Code", 22, 3, |
| 319 | + { 0, "No err"}, |
| 320 | + { 1, "ID ERR"}, |
| 321 | + { 2, "CMD ERR"}, |
| 322 | + { 3, "CRC ERR"}, |
| 323 | + { 4, "Preamble ERR"}, |
| 324 | + { 5, "Abort ERR"}, |
| 325 | + { 6, "Overflow ERR"}, |
| 326 | + { 7, "SDM EOF"}, |
| 327 | + { 8, "Authentication ERR"}, |
| 328 | + { 9, "Authentication Setup ERR"}, |
| 329 | + {10, "Bitstream Engine Timeout ERR"}), |
| 330 | + REG_ENTRY("EXEC Error", 26, 1, {0, "No"}, {1, "Yes"}), |
| 331 | + REG_ENTRY("Device failed to verify", 27, 1, {0, "No"}, {1, "Yes"}), |
| 332 | + REG_ENTRY("Invalid Command", 28, 1, {0, "No"}, {1, "Yes"}), |
| 333 | + REG_ENTRY("SED Error", 29, 1, {0, "No"}, {1, "Yes"}), |
| 334 | + REG_ENTRY("Bypass Mode", 30, 1, {0, "No"}, {1, "Yes"}), |
| 335 | + REG_ENTRY("FT Mode", 31, 1, {0, "No"}, {1, "Yes"}), |
| 336 | + |
| 337 | + }}, |
| 338 | +}; |
| 339 | + |
287 | 340 | void LatticeSSPI::displayReadReg(uint32_t dev) |
288 | 341 | { |
289 | | - printf("displayReadReg 0x%08x\n", dev); |
290 | | - if (dev & 1<<0) printf("\tTRAN Mode\n"); |
291 | | - printf("\tConfig Target Selection : %" PRIx32 "\n", (dev >> 1) & 0x07); |
292 | | - if (dev & 1<<4) printf("\tJTAG Active\n"); |
293 | | - if (dev & 1<<5) printf("\tPWD Protect\n"); |
294 | | - if (dev & 1<<6) printf("\tOTP\n"); |
295 | | - if (dev & 1<<7) printf("\tDecrypt Enable\n"); |
296 | | - if (dev & REG_STATUS_DONE) printf("\tDone Flag\n"); |
297 | | - if (dev & REG_STATUS_ISC_EN) printf("\tISC Enable\n"); |
298 | | - if (dev & 1 << 10) printf("\tWrite Enable\n"); |
299 | | - if (dev & 1 << 11) printf("\tRead Enable\n"); |
300 | | - if (dev & REG_STATUS_BUSY) printf("\tBusy Flag\n"); |
301 | | - if (dev & REG_STATUS_FAIL) printf("\tFail Flag\n"); |
302 | | - if (dev & 1 << 14) printf("\tFFEA OTP\n"); |
303 | | - if (dev & 1 << 15) printf("\tDecrypt Only\n"); |
304 | | - if (dev & 1 << 16) printf("\tPWD Enable\n"); |
305 | | - if (dev & 1 << 17) printf("\tUFM OTP\n"); |
306 | | - if (dev & 1 << 18) printf("\tASSP\n"); |
307 | | - if (dev & 1 << 19) printf("\tSDM Enable\n"); |
308 | | - if (dev & 1 << 20) printf("\tEncryption PreAmble\n"); |
309 | | - if (dev & 1 << 21) printf("\tStd PreAmble\n"); |
310 | | - if (dev & 1 << 22) printf("\tSPIm Fail1\n"); |
311 | | - const uint8_t err = (dev >> 23)&0x07; |
312 | | - |
313 | | - printf("\tBSE Error Code\n"); |
314 | | - printf("\t\t"); |
315 | | - switch (err) { |
316 | | - case 0: |
317 | | - printf("No err\n"); |
318 | | - break; |
319 | | - case 1: |
320 | | - printf("ID ERR\n"); |
321 | | - break; |
322 | | - case 2: |
323 | | - printf("CMD ERR\n"); |
324 | | - break; |
325 | | - case 3: |
326 | | - printf("CRC ERR\n"); |
327 | | - break; |
328 | | - case 4: |
329 | | - printf("Preamble ERR\n"); |
330 | | - break; |
331 | | - case 5: |
332 | | - printf("Abort ERR\n"); |
333 | | - break; |
334 | | - case 6: |
335 | | - printf("Overflow ERR\n"); |
336 | | - break; |
337 | | - case 7: |
338 | | - printf("SDM EOF\n"); |
339 | | - break; |
340 | | - case 8: |
341 | | - printf("Authentication ERR\n"); |
342 | | - break; |
343 | | - case 9: |
344 | | - printf("Authentication Setup ERR\n"); |
345 | | - break; |
346 | | - case 10: |
347 | | - printf("Bitstream Engine Timeout ERR\n"); |
348 | | - break; |
349 | | - default: |
350 | | - printf("unknown error: %x\n", err); |
| 342 | + auto reg = reg_content.find("StatusRegister"); |
| 343 | + if (reg == reg_content.end()) { |
| 344 | + printError("Unknown register StatusRegister"); |
| 345 | + return; |
351 | 346 | } |
352 | 347 |
|
353 | | - if (dev & REG_STATUS_EXEC_ERR) printf("\tEXEC Error\n"); |
354 | | - if ((dev >> 27) & 0x01) printf("\tDevice failed to verify\n"); |
355 | | - if ((dev >> 28) & 0x01) printf("\tInvalid Command\n"); |
356 | | - if ((dev >> 29) & 0x01) printf("\tSED Error\n"); |
357 | | - if ((dev >> 30) & 0x01) printf("\tBypass Mode\n"); |
358 | | - if ((dev >> 31) & 0x01) printf("\tFT Mode\n"); |
| 348 | + std::stringstream raw_val; |
| 349 | + raw_val << "0x" << std::hex << dev; |
| 350 | + printSuccess("Register raw value: " + raw_val.str()); |
| 351 | + |
| 352 | + const std::list<reg_struct_t> regs = reg->second; |
| 353 | + for (reg_struct_t r: regs) { |
| 354 | + uint8_t offset = r.offset; |
| 355 | + uint8_t size = r.size; |
| 356 | + uint32_t mask = (1 << size) - 1; |
| 357 | + uint32_t val = (dev >> offset) & mask; |
| 358 | + std::stringstream ss, desc; |
| 359 | + desc << r.description; |
| 360 | + ss << std::setw(24) << std::left << r.description; |
| 361 | + if (r.reg_cnt.size() != 0) { |
| 362 | + ss << r.reg_cnt[val]; |
| 363 | + } else { |
| 364 | + std::stringstream hex_val; |
| 365 | + hex_val << "0x" << std::hex << val; |
| 366 | + ss << hex_val.str(); |
| 367 | + } |
| 368 | + |
| 369 | + printInfo(ss.str()); |
| 370 | + } |
359 | 371 | } |
0 commit comments