|
| 1 | +/* Copyright (C) 2017 Bogdan Bogush <bogdan.s.bogush@gmail.com> |
| 2 | + * This program is free software; you can redistribute it and/or modify |
| 3 | + * it under the terms of the GNU General Public License version 3. |
| 4 | + */ |
| 5 | + |
| 6 | +#include "err.h" |
| 7 | + |
| 8 | +enum |
| 9 | +{ |
| 10 | + NP_ERR_INTERNAL = -1, |
| 11 | + NP_ERR_ADDR_EXCEEDED = -100, |
| 12 | + NP_ERR_ADDR_INVALID = -101, |
| 13 | + NP_ERR_ADDR_NOT_ALIGN = -102, |
| 14 | + NP_ERR_NAND_WR = -103, |
| 15 | + NP_ERR_NAND_RD = -104, |
| 16 | + NP_ERR_NAND_ERASE = -105, |
| 17 | + NP_ERR_CHIP_NOT_CONF = -106, |
| 18 | + NP_ERR_CMD_DATA_SIZE = -107, |
| 19 | + NP_ERR_CMD_INVALID = -108, |
| 20 | + NP_ERR_BUF_OVERFLOW = -109, |
| 21 | + NP_ERR_LEN_NOT_ALIGN = -110, |
| 22 | + NP_ERR_LEN_EXCEEDED = -111, |
| 23 | + NP_ERR_LEN_INVALID = -112, |
| 24 | + NP_ERR_BBT_OVERFLOW = -113, |
| 25 | +}; |
| 26 | + |
| 27 | +typedef struct |
| 28 | +{ |
| 29 | + long int code; |
| 30 | + const char *str; |
| 31 | +} code_str_t; |
| 32 | + |
| 33 | +static code_str_t err[] = |
| 34 | +{ |
| 35 | + { NP_ERR_INTERNAL, "Internal error" }, |
| 36 | + { NP_ERR_ADDR_EXCEEDED, "Operation address exceeded chip size" }, |
| 37 | + { NP_ERR_ADDR_INVALID, "Operation address is invalid" }, |
| 38 | + { NP_ERR_ADDR_NOT_ALIGN, |
| 39 | + "Operation address is not aligned to page/block size" }, |
| 40 | + { NP_ERR_NAND_WR, "Failed to write chip" }, |
| 41 | + { NP_ERR_NAND_RD, "Failed to read chip" }, |
| 42 | + { NP_ERR_NAND_ERASE, "Failed to erase chip" }, |
| 43 | + { NP_ERR_CHIP_NOT_CONF, |
| 44 | + "Programmer is not configured with chip parameters" }, |
| 45 | + { NP_ERR_CMD_DATA_SIZE, "Data size in command is wrong" }, |
| 46 | + { NP_ERR_CMD_INVALID, "Invalid command" }, |
| 47 | + { NP_ERR_BUF_OVERFLOW, "Buffer overflow" }, |
| 48 | + { NP_ERR_LEN_NOT_ALIGN, "Data length is not page aligned" }, |
| 49 | + { NP_ERR_LEN_EXCEEDED, "Data length exceeded chip size" }, |
| 50 | + { NP_ERR_LEN_INVALID, "Wrong data length" }, |
| 51 | + { NP_ERR_BBT_OVERFLOW, "Bad block table overflow" }, |
| 52 | +}; |
| 53 | + |
| 54 | +const char *errCode2str(long int code) |
| 55 | +{ |
| 56 | + for (unsigned int i = 0; i < sizeof(err) / sizeof (err[0]); i++) |
| 57 | + { |
| 58 | + if (err[i].code == code) |
| 59 | + return err[i].str; |
| 60 | + } |
| 61 | + |
| 62 | + return "Unknown error"; |
| 63 | +} |
0 commit comments