bluetooth/error_sd.go

93 lines
2.6 KiB
Go
Raw Normal View History

//go:build softdevice
2019-06-02 20:12:36 +03:00
package bluetooth
// #include <stdint.h>
// #include "nrf_error.h"
// #include "nrf_error_sdm.h"
import "C"
2019-06-02 20:12:36 +03:00
// Error is an error from within the SoftDevice.
type Error uint32
func (e Error) Error() string {
switch {
case e >= C.NRF_ERROR_BASE_NUM && e < C.NRF_ERROR_SDM_BASE_NUM:
2019-06-02 20:12:36 +03:00
// Global errors.
switch e {
case C.NRF_SUCCESS:
2019-06-02 20:12:36 +03:00
return "no error"
case C.NRF_ERROR_SVC_HANDLER_MISSING:
2019-06-02 20:12:36 +03:00
return "SVC handler is missing"
case C.NRF_ERROR_SOFTDEVICE_NOT_ENABLED:
2019-06-02 20:12:36 +03:00
return "SoftDevice has not been enabled"
case C.NRF_ERROR_INTERNAL:
2019-06-02 20:12:36 +03:00
return "internal error"
case C.NRF_ERROR_NO_MEM:
2019-06-02 20:12:36 +03:00
return "no memory for operation"
case C.NRF_ERROR_NOT_FOUND:
2019-06-02 20:12:36 +03:00
return "not found"
case C.NRF_ERROR_NOT_SUPPORTED:
2019-06-02 20:12:36 +03:00
return "not supported"
case C.NRF_ERROR_INVALID_PARAM:
2019-06-02 20:12:36 +03:00
return "invalid parameter"
case C.NRF_ERROR_INVALID_STATE:
2019-06-02 20:12:36 +03:00
return "invalid state, operation disallowed in this state"
case C.NRF_ERROR_INVALID_LENGTH:
2019-06-02 20:12:36 +03:00
return "invalid Length"
case C.NRF_ERROR_INVALID_FLAGS:
2019-06-02 20:12:36 +03:00
return "invalid flags"
case C.NRF_ERROR_INVALID_DATA:
2019-06-02 20:12:36 +03:00
return "invalid data"
case C.NRF_ERROR_DATA_SIZE:
2019-06-02 20:12:36 +03:00
return "invalid data size"
case C.NRF_ERROR_TIMEOUT:
2019-06-02 20:12:36 +03:00
return "operation timed out"
case C.NRF_ERROR_NULL:
2019-06-02 20:12:36 +03:00
return "null pointer"
case C.NRF_ERROR_FORBIDDEN:
2019-06-02 20:12:36 +03:00
return "forbidden operation"
case C.NRF_ERROR_INVALID_ADDR:
2019-06-02 20:12:36 +03:00
return "bad memory address"
case C.NRF_ERROR_BUSY:
2019-06-02 20:12:36 +03:00
return "busy"
case 18: // C.NRF_ERROR_CONN_COUNT, not available on nrf51
2019-06-02 20:12:36 +03:00
return "maximum connection count exceeded"
case 19: // C.NRF_ERROR_RESOURCES, not available on nrf51
2019-06-02 20:12:36 +03:00
return "not enough resources for operation"
default:
return "other global error"
}
case e >= C.NRF_ERROR_SDM_BASE_NUM && e < C.NRF_ERROR_SOC_BASE_NUM:
2019-06-02 20:12:36 +03:00
// SDM errors.
switch e {
case C.NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN:
2019-06-02 20:12:36 +03:00
return "unknown LFCLK source"
case C.NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION:
2019-06-02 20:12:36 +03:00
return "incorrect interrupt configuration"
case C.NRF_ERROR_SDM_INCORRECT_CLENR0:
2019-06-02 20:12:36 +03:00
return "incorrect CLENR0"
default:
return "other SDM error"
}
case e >= C.NRF_ERROR_SOC_BASE_NUM && e < C.NRF_ERROR_STK_BASE_NUM:
2019-06-02 20:12:36 +03:00
// SoC errors.
return "other SoC error"
case e >= C.NRF_ERROR_STK_BASE_NUM && e < 0x4000:
2019-06-02 20:12:36 +03:00
// STK errors.
return "other STK error"
default:
// Other errors.
return "other error"
}
}
// makeError returns an error (using the Error type) if the error code is
// non-zero, otherwise it returns nil. It is used with internal API calls.
func makeError(code C.uint32_t) error {
2019-06-02 20:12:36 +03:00
if code != 0 {
return Error(code)
}
return nil
}