More annotations on errors

This commit is contained in:
Ben V. Brown 2023-05-09 08:05:38 +10:00
parent bac4f4b49f
commit 5306720e5d
2 changed files with 22 additions and 17 deletions

View File

@ -6,20 +6,25 @@ typedef enum {
// All error states must be <0. // All error states must be <0.
// Generic error return; for when we are unsure what failed // Generic error return; for when we are unsure what failed
BLISP_ERR_UNKNOWN = -1, 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, BLISP_ERR_NO_RESPONSE = -2,
// Failed to open a device, likely libusb or permissions // Failed to open a device, likely libusb or permissions
BLISP_ERR_DEVICE_NOT_FOUND = -3, BLISP_ERR_DEVICE_NOT_FOUND = -3, // We could not find a device
BLISP_ERR_CANT_OPEN_DEVICE = -4, 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 // Can't auto-find device due it doesn't have native USB
BLISP_ERR_NO_AUTO_FIND_AVAILABLE = -5, BLISP_ERR_NO_AUTO_FIND_AVAILABLE = -5,
BLISP_ERR_PENDING = -6, BLISP_ERR_PENDING = -6, // Internal error for device is busy and to come back
BLISP_ERR_CHIP_ERR = -7, BLISP_ERR_CHIP_ERR = -7, // Chip returned an error to us
BLISP_ERR_INVALID_CHIP_TYPE = -8, BLISP_ERR_INVALID_CHIP_TYPE = -8, // unsupported chip type provided
BLISP_ERR_OUT_OF_MEMORY = -9, BLISP_ERR_OUT_OF_MEMORY =
BLISP_ERR_INVALID_COMMAND = -10, -9, // System could not allocate enough ram (highly unlikely)
BLISP_ERR_CANT_OPEN_FILE=-11, BLISP_ERR_INVALID_COMMAND = -10, // Invalid user command provided
BLISP_ERR_NOT_IMPLEMENTED=-12, 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; } blisp_return_t;
#endif #endif

View File

@ -45,7 +45,7 @@ blisp_return_t blisp_device_open(struct blisp_device* device,
ret = sp_list_ports(&port_list); ret = sp_list_ports(&port_list);
if (ret != SP_OK) { if (ret != SP_OK) {
blisp_dlog("Couldn't list ports, err: %d", ret); 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++) { for (int i = 0; port_list[i] != NULL; i++) {
struct sp_port* port = port_list[i]; struct sp_port* port = port_list[i];
@ -99,8 +99,8 @@ blisp_return_t blisp_device_open(struct blisp_device* device,
#endif #endif
ret = sp_set_baudrate(serial_port, device->current_baud_rate); ret = sp_set_baudrate(serial_port, device->current_baud_rate);
if (ret != SP_OK) { if (ret != SP_OK) {
blisp_dlog("Set baud rate failed: %d... Also hello macOS user :)", ret); blisp_dlog("Set baud rate failed: %d... Also hello MacOS user :)", ret);
return BLISP_ERR_UNKNOWN; return BLISP_ERR_API_ERROR;
} }
device->serial_port = serial_port; 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); sp_blocking_write(serial_port, device->tx_buffer, 4 + payload_size, 1000);
if (ret != (4 + payload_size)) { if (ret != (4 + payload_size)) {
blisp_dlog("Received error or not written all data: %d", ret); blisp_dlog("Received error or not written all data: %d", ret);
return BLISP_ERR_UNKNOWN; return BLISP_ERR_API_ERROR;
} }
drain(serial_port); 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); ret = sp_blocking_read(serial_port, &device->rx_buffer[0], 2, 1000);
if (ret < 2) { if (ret < 2) {
blisp_dlog("Failed to receive response, ret: %d", ret); 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') { } else if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') {
if (expect_payload) { if (expect_payload) {
sp_blocking_read(serial_port, &device->rx_buffer[2], 2, 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, blisp_dlog("Failed to receive any response (err: %d, %d - %d)", ret,
device->rx_buffer[0], device->rx_buffer[1]); 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, 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); drain(serial_port);
if (ret < 0) { if (ret < 0) {
blisp_dlog("Handshake write failed, ret %d", ret); blisp_dlog("Handshake write failed, ret %d", ret);
return BLISP_ERR_UNKNOWN; return BLISP_ERR_API_ERROR;
} }
if (!in_ef_loader && !device->is_usb) { if (!in_ef_loader && !device->is_usb) {