mirror of
https://github.com/pine64/blisp.git
synced 2024-12-22 06:20:12 +00:00
More annotations on errors
This commit is contained in:
parent
bac4f4b49f
commit
5306720e5d
@ -6,20 +6,25 @@ typedef enum {
|
||||
// All error states must be <0.
|
||||
// Generic error return; for when we are unsure what failed
|
||||
BLISP_ERR_UNKNOWN = -1,
|
||||
// Device did not respond, if serial link, could be that its not in bootloader
|
||||
// Device did not respond, if serial link, could be that its not in boot
|
||||
// loader
|
||||
BLISP_ERR_NO_RESPONSE = -2,
|
||||
// Failed to open a device, likely libusb or permissions
|
||||
BLISP_ERR_DEVICE_NOT_FOUND = -3,
|
||||
BLISP_ERR_CANT_OPEN_DEVICE = -4,
|
||||
BLISP_ERR_DEVICE_NOT_FOUND = -3, // We could not find a device
|
||||
BLISP_ERR_CANT_OPEN_DEVICE =
|
||||
-4, // Couldn't open device; could it be permissions or its in use?
|
||||
// Can't auto-find device due it doesn't have native USB
|
||||
BLISP_ERR_NO_AUTO_FIND_AVAILABLE = -5,
|
||||
BLISP_ERR_PENDING = -6,
|
||||
BLISP_ERR_CHIP_ERR = -7,
|
||||
BLISP_ERR_INVALID_CHIP_TYPE = -8,
|
||||
BLISP_ERR_OUT_OF_MEMORY = -9,
|
||||
BLISP_ERR_INVALID_COMMAND = -10,
|
||||
BLISP_ERR_CANT_OPEN_FILE=-11,
|
||||
BLISP_ERR_NOT_IMPLEMENTED=-12,
|
||||
BLISP_ERR_PENDING = -6, // Internal error for device is busy and to come back
|
||||
BLISP_ERR_CHIP_ERR = -7, // Chip returned an error to us
|
||||
BLISP_ERR_INVALID_CHIP_TYPE = -8, // unsupported chip type provided
|
||||
BLISP_ERR_OUT_OF_MEMORY =
|
||||
-9, // System could not allocate enough ram (highly unlikely)
|
||||
BLISP_ERR_INVALID_COMMAND = -10, // Invalid user command provided
|
||||
BLISP_ERR_CANT_OPEN_FILE = -11, // Cant open the firmware file to flash
|
||||
BLISP_ERR_NOT_IMPLEMENTED = -12, // Non implemented function called
|
||||
BLISP_ERR_API_ERROR = -13, // Errors outside our control from api's we
|
||||
// integrate (Generally serial port/OS related)
|
||||
|
||||
} blisp_return_t;
|
||||
#endif
|
14
lib/blisp.c
14
lib/blisp.c
@ -45,7 +45,7 @@ blisp_return_t blisp_device_open(struct blisp_device* device,
|
||||
ret = sp_list_ports(&port_list);
|
||||
if (ret != SP_OK) {
|
||||
blisp_dlog("Couldn't list ports, err: %d", ret);
|
||||
return BLISP_ERR_UNKNOWN;
|
||||
return BLISP_ERR_DEVICE_NOT_FOUND;
|
||||
}
|
||||
for (int i = 0; port_list[i] != NULL; i++) {
|
||||
struct sp_port* port = port_list[i];
|
||||
@ -99,8 +99,8 @@ blisp_return_t blisp_device_open(struct blisp_device* device,
|
||||
#endif
|
||||
ret = sp_set_baudrate(serial_port, device->current_baud_rate);
|
||||
if (ret != SP_OK) {
|
||||
blisp_dlog("Set baud rate failed: %d... Also hello macOS user :)", ret);
|
||||
return BLISP_ERR_UNKNOWN;
|
||||
blisp_dlog("Set baud rate failed: %d... Also hello MacOS user :)", ret);
|
||||
return BLISP_ERR_API_ERROR;
|
||||
}
|
||||
device->serial_port = serial_port;
|
||||
|
||||
@ -134,7 +134,7 @@ blisp_return_t blisp_send_command(struct blisp_device* device,
|
||||
sp_blocking_write(serial_port, device->tx_buffer, 4 + payload_size, 1000);
|
||||
if (ret != (4 + payload_size)) {
|
||||
blisp_dlog("Received error or not written all data: %d", ret);
|
||||
return BLISP_ERR_UNKNOWN;
|
||||
return BLISP_ERR_API_ERROR;
|
||||
}
|
||||
drain(serial_port);
|
||||
|
||||
@ -149,7 +149,7 @@ blisp_return_t blisp_receive_response(struct blisp_device* device,
|
||||
ret = sp_blocking_read(serial_port, &device->rx_buffer[0], 2, 1000);
|
||||
if (ret < 2) {
|
||||
blisp_dlog("Failed to receive response, ret: %d", ret);
|
||||
return BLISP_ERR_UNKNOWN; // TODO: Terrible
|
||||
return BLISP_ERR_NO_RESPONSE;
|
||||
} else if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') {
|
||||
if (expect_payload) {
|
||||
sp_blocking_read(serial_port, &device->rx_buffer[2], 2,
|
||||
@ -171,7 +171,7 @@ blisp_return_t blisp_receive_response(struct blisp_device* device,
|
||||
}
|
||||
blisp_dlog("Failed to receive any response (err: %d, %d - %d)", ret,
|
||||
device->rx_buffer[0], device->rx_buffer[1]);
|
||||
return BLISP_ERR_UNKNOWN;
|
||||
return BLISP_ERR_NO_RESPONSE;
|
||||
}
|
||||
|
||||
blisp_return_t blisp_device_handshake(struct blisp_device* device,
|
||||
@ -208,7 +208,7 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device,
|
||||
drain(serial_port);
|
||||
if (ret < 0) {
|
||||
blisp_dlog("Handshake write failed, ret %d", ret);
|
||||
return BLISP_ERR_UNKNOWN;
|
||||
return BLISP_ERR_API_ERROR;
|
||||
}
|
||||
|
||||
if (!in_ef_loader && !device->is_usb) {
|
||||
|
Loading…
Reference in New Issue
Block a user