Change set_error/set_error_fatal to warning/error, add itm support and other changes

pull/6983/head
Senthil Ramakrishnan 2018-05-12 10:26:09 -05:00
parent 7c6c718f75
commit 2e28dd95e1
17 changed files with 383 additions and 313 deletions

View File

@ -27,26 +27,26 @@ using utest::v1::Case;
*/
void test_system_errors()
{
MbedErrorStatus error = MAKE_ERROR(ENTITY_APPLICATION, ERROR_CODE_UNKNOWN);
SET_ERROR(error, "Error Unknown", 0xAABBCCDD );
MbedErrorStatus error = MAKE_ERROR(MODULE_APPLICATION, ERROR_CODE_UNKNOWN);
SET_WARNING(error, "Error Unknown", 0xAABBCCDD );
MbedErrorStatus lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_CREATE_FAILED);
SET_ERROR(error, "Error Platform", 0xABCDABCD );
error = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_CREATE_FAILED);
SET_WARNING(error, "Error Platform", 0xABCDABCD );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MAKE_ERROR(ENTITY_DRIVER_SERIAL, ERROR_CODE_OUT_OF_RESOURCES);
SET_ERROR(error, "Error Serial driver", 0xAA );
error = MAKE_ERROR(MODULE_DRIVER_SERIAL, ERROR_CODE_OUT_OF_RESOURCES);
SET_WARNING(error, "Error Serial driver", 0xAA );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MAKE_ERROR(ENTITY_UNKNOWN, ERROR_CODE_OUT_OF_MEMORY);
SET_ERROR(error, "Error Out of resources", 0x11223344 );
error = MAKE_ERROR(MODULE_UNKNOWN, ERROR_CODE_OUT_OF_MEMORY);
SET_WARNING(error, "Error Out of resources", 0x11223344 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
@ -57,20 +57,20 @@ void test_system_errors()
*/
void test_custom_errors()
{
MbedErrorStatus error = MAKE_CUSTOM_ERROR(ENTITY_APPLICATION, ERROR_CODE_UNKNOWN);
SET_ERROR(error, "Custom Error Unknown", 0x1234 );
MbedErrorStatus error = MAKE_CUSTOM_ERROR(MODULE_APPLICATION, ERROR_CODE_UNKNOWN);
SET_WARNING(error, "Custom Error Unknown", 0x1234 );
MbedErrorStatus lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MAKE_CUSTOM_ERROR(ENTITY_PLATFORM, ERROR_CODE_CREATE_FAILED);
SET_ERROR(error, "Custom Error Platform", 0x5555 );
error = MAKE_CUSTOM_ERROR(MODULE_PLATFORM, ERROR_CODE_CREATE_FAILED);
SET_WARNING(error, "Custom Error Platform", 0x5555 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MAKE_CUSTOM_ERROR(ENTITY_HAL, ERROR_CODE_OUT_OF_MEMORY);
SET_ERROR(error, "Custom Error Unknown", 0x33445566 );
error = MAKE_CUSTOM_ERROR(MODULE_HAL, ERROR_CODE_OUT_OF_MEMORY);
SET_WARNING(error, "Custom Error Unknown", 0x33445566 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
@ -81,17 +81,17 @@ void test_custom_errors()
*/
void test_posix_errors()
{
SET_ERROR(ERROR_EPERM, "Posix Error Eperm", 0x1234 );
SET_WARNING(ERROR_EPERM, "Posix Error Eperm", 0x1234 );
MbedErrorStatus lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_EPERM, lastError);
SET_ERROR(ERROR_EBADF, "Posix Error, bad file descriptor", 0x5555 );
SET_WARNING(ERROR_EBADF, "Posix Error, bad file descriptor", 0x5555 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_EBADF, lastError);
SET_ERROR(ERROR_ENOENT, "Posix error, no file or dir", 0x33445566 );
SET_WARNING(ERROR_ENOENT, "Posix error, no file or dir", 0x33445566 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_ENOENT, lastError);
@ -104,14 +104,14 @@ void test_first_and_last_error_capture()
//clear the errors and error count to 0
clear_all_errors();
SET_ERROR(ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 );
SET_ERROR(ERROR_OUT_OF_MEMORY, "Out of memory", 0x2233);
SET_ERROR(ERROR_SEMAPHORE_LOCK_FAILED, "Sem lock failed", 0x3344 );
SET_ERROR(ERROR_MUTEX_LOCK_FAILED, "Mutex lock failed", 0x4455 );
SET_ERROR(ERROR_CREATE_FAILED, "Create failed", 0x5566 );
SET_ERROR(ERROR_TIMEOUT, "Time out error", 0x7788 );
SET_ERROR(ERROR_MUTEX_UNLOCK_FAILED, "Mutex unlock failed", 0x99AA );
SET_ERROR(ERROR_SEMAPHORE_UNLOCK_FAILED, "Semaphore unlock failed", 0xBBCC );
SET_WARNING(ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 );
SET_WARNING(ERROR_OUT_OF_MEMORY, "Out of memory", 0x2233);
SET_WARNING(ERROR_SEMAPHORE_LOCK_FAILED, "Sem lock failed", 0x3344 );
SET_WARNING(ERROR_MUTEX_LOCK_FAILED, "Mutex lock failed", 0x4455 );
SET_WARNING(ERROR_CREATE_FAILED, "Create failed", 0x5566 );
SET_WARNING(ERROR_TIME_OUT, "Time out error", 0x7788 );
SET_WARNING(ERROR_MUTEX_UNLOCK_FAILED, "Mutex unlock failed", 0x99AA );
SET_WARNING(ERROR_SEMAPHORE_UNLOCK_FAILED, "Semaphore unlock failed", 0xBBCC );
MbedErrorStatus error = get_last_error();
printf("\nlastError = 0x%08X", error );
@ -131,7 +131,7 @@ void test_error_count_and_reset()
//Log multiple errors and get the error count and make sure its 15
for(int i=0; i<count; i++) {
SET_ERROR(ERROR_OUT_OF_MEMORY, "Out of memory", i);
SET_WARNING(ERROR_OUT_OF_MEMORY, "Out of memory", i);
}
TEST_ASSERT_EQUAL_INT(count, get_error_count());
@ -148,48 +148,48 @@ void test_error_count_and_reset()
*/
void test_error_encoding()
{
SET_ERROR(ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 );
SET_WARNING(ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 );
MbedErrorStatus lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_TYPE_SYSTEM, GET_MBED_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(ENTITY_UNKNOWN, GET_MBED_ERROR_ENTITY(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_OUT_OF_RESOURCES, GET_MBED_ERROR_CODE(lastError));
MbedErrorStatus error = MAKE_CUSTOM_ERROR(ENTITY_PLATFORM, ERROR_CODE_CREATE_FAILED);
SET_ERROR(error, "Custom Error Type", 0x2233);
MbedErrorStatus error = MAKE_CUSTOM_ERROR(MODULE_PLATFORM, ERROR_CODE_CREATE_FAILED);
SET_WARNING(error, "Custom Error Type", 0x2233);
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_TYPE_CUSTOM, GET_MBED_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(ENTITY_PLATFORM, GET_MBED_ERROR_ENTITY(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_PLATFORM, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_CREATE_FAILED, GET_MBED_ERROR_CODE(lastError));
SET_ERROR(ERROR_EACCES, "Posix Error 1", 0x3344 );
SET_WARNING(ERROR_EACCES, "Posix Error 1", 0x3344 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_TYPE_POSIX, GET_MBED_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(ENTITY_UNKNOWN, GET_MBED_ERROR_ENTITY(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_EACCES, GET_MBED_ERROR_CODE(lastError));
SET_ERROR(ERROR_ERANGE, "Posix Error 2", 0x3355 );
SET_WARNING(ERROR_ERANGE, "Posix Error 2", 0x3355 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_TYPE_POSIX, GET_MBED_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(ENTITY_UNKNOWN, GET_MBED_ERROR_ENTITY(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_ERANGE, GET_MBED_ERROR_CODE(lastError));
error = MAKE_ERROR(ENTITY_HAL, ERROR_CODE_UNKNOWN);
SET_ERROR(error, "HAL Entity error", 0x5566 );
error = MAKE_ERROR(MODULE_HAL, ERROR_CODE_UNKNOWN);
SET_WARNING(error, "HAL Entity error", 0x5566 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_TYPE_SYSTEM, GET_MBED_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(ENTITY_HAL, GET_MBED_ERROR_ENTITY(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_HAL, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_UNKNOWN, GET_MBED_ERROR_CODE(lastError));
SET_ERROR(ERROR_UNKNOWN, "Unknown Entity error", 7788 );
SET_WARNING(ERROR_UNKNOWN, "Unknown Entity error", 7788 );
lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_TYPE_SYSTEM, GET_MBED_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(ENTITY_UNKNOWN, GET_MBED_ERROR_ENTITY(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_UNKNOWN, GET_MBED_ERROR_CODE(lastError));
}
@ -201,20 +201,20 @@ void test_error_value()
uint32_t error_value = 0xAA11BB22;
mbed_error_ctx error_ctx = {0};
SET_ERROR(ERROR_OUT_OF_RESOURCES, "System type error", error_value );
SET_WARNING(ERROR_OUT_OF_RESOURCES, "System type error", error_value );
MbedErrorStatus status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
MbedErrorStatus error = MAKE_CUSTOM_ERROR(ENTITY_PLATFORM, ERROR_CODE_CREATE_FAILED);
MbedErrorStatus error = MAKE_CUSTOM_ERROR(MODULE_PLATFORM, ERROR_CODE_CREATE_FAILED);
error_value = 0xABCD;
SET_ERROR(error, "Custom Error Type", error_value);
SET_WARNING(error, "Custom Error Type", error_value);
status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
error_value = 0x11223344;
SET_ERROR(ERROR_EACCES, "Posix Error 1", error_value );
SET_WARNING(ERROR_EACCES, "Posix Error 1", error_value );
status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
@ -227,7 +227,7 @@ void test_error_context_capture()
uint32_t error_value = 0xABCD;
mbed_error_ctx error_ctx = {0};
SET_ERROR(ERROR_INVALID_ARGUMENT, "System type error", error_value );
SET_WARNING(ERROR_INVALID_ARGUMENT, "System type error", error_value );
MbedErrorStatus status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
@ -254,9 +254,9 @@ void test_error_logging()
clear_all_errors();
//log 3 errors and retrieve them to ensure they are correct
SET_ERROR(ERROR_INVALID_ARGUMENT, "Invalid argument error", 1 );
SET_ERROR(ERROR_INVALID_SIZE, "Invalid size error", 2 );
SET_ERROR(ERROR_INVALID_FORMAT, "Invalid format error", 3 );
SET_WARNING(ERROR_INVALID_ARGUMENT, "Invalid argument error", 1 );
SET_WARNING(ERROR_INVALID_SIZE, "Invalid size error", 2 );
SET_WARNING(ERROR_INVALID_FORMAT, "Invalid format error", 3 );
MbedErrorStatus status = get_error_log_info( 0, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_ARGUMENT, error_ctx.error_status);
@ -271,11 +271,11 @@ void test_error_logging()
TEST_ASSERT_EQUAL_UINT(3, error_ctx.error_value);
//log 2 more errors to fill the log and then read them out to ensure that its correct
SET_ERROR(ERROR_INVALID_DATA, "Invalid data", 4 );
SET_ERROR(ERROR_INVALID_OPERATION, "Invalid operation", 5 );
SET_WARNING(ERROR_INVALID_DATA_DETECTED, "Invalid data", 4 );
SET_WARNING(ERROR_INVALID_OPERATION, "Invalid operation", 5 );
status = get_error_log_info( 3, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_DATA, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_DATA_DETECTED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(4, error_ctx.error_value);
status = get_error_log_info( 4, &error_ctx );
@ -283,20 +283,20 @@ void test_error_logging()
TEST_ASSERT_EQUAL_UINT(5, error_ctx.error_value);
//Log a bunch of errors to overflow the error log and retrieve them
SET_ERROR(ERROR_INVALID_ARGUMENT, "Invalid argument error", 6 );
SET_ERROR(ERROR_INVALID_SIZE, "Invalid size error", 7 );
SET_ERROR(ERROR_INVALID_FORMAT, "Invalid format error", 8 );
SET_ERROR(ERROR_NOT_READY, "Not ready error", 9 );
SET_WARNING(ERROR_INVALID_ARGUMENT, "Invalid argument error", 6 );
SET_WARNING(ERROR_INVALID_SIZE, "Invalid size error", 7 );
SET_WARNING(ERROR_INVALID_FORMAT, "Invalid format error", 8 );
SET_WARNING(ERROR_NOT_READY, "Not ready error", 9 );
//Last 5 entries
SET_ERROR(ERROR_TIMEOUT, "Timeout error", 10 );
SET_ERROR(ERROR_ALREADY_IN_USE, "Already in use error", 11 );
SET_ERROR(ERROR_NOT_SUPPORTED, "Not supported error", 12 );
SET_ERROR(ERROR_ACCESS_DENIED, "Access denied error", 13 );
SET_ERROR(ERROR_NOT_FOUND, "Not found error", 14 );
SET_WARNING(ERROR_TIME_OUT, "Timeout error", 10 );
SET_WARNING(ERROR_ALREADY_IN_USE, "Already in use error", 11 );
SET_WARNING(ERROR_UNSUPPORTED, "Not supported error", 12 );
SET_WARNING(ERROR_ACCESS_DENIED, "Access denied error", 13 );
SET_WARNING(ERROR_ITEM_NOT_FOUND, "Not found error", 14 );
status = get_error_log_info( 0, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_TIMEOUT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(ERROR_TIME_OUT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(10, error_ctx.error_value);
status = get_error_log_info( 1, &error_ctx );
@ -304,7 +304,7 @@ void test_error_logging()
TEST_ASSERT_EQUAL_UINT(11, error_ctx.error_value);
status = get_error_log_info( 2, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_NOT_SUPPORTED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(ERROR_UNSUPPORTED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(12, error_ctx.error_value);
status = get_error_log_info( 3, &error_ctx );
@ -312,7 +312,7 @@ void test_error_logging()
TEST_ASSERT_EQUAL_UINT(13, error_ctx.error_value);
status = get_error_log_info( 4, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_NOT_FOUND, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(ERROR_ITEM_NOT_FOUND, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(14, error_ctx.error_value);
//Try an index which is invalid, we should get ERROR_INVALID_ARGUMENT back
@ -326,8 +326,8 @@ void test_error_logging()
//Error logger threads
void err_thread_func(MbedErrorStatus *error_status)
{
printf("\nError Status = 0x%08X\n",*error_status);
SET_ERROR(*error_status, "Error from Multi-Threaded error logging test", *error_status );
//printf("\nError Status = 0x%08X\n",*error_status);
SET_WARNING(*error_status, "Error from Multi-Threaded error logging test", *error_status );
}
@ -339,8 +339,8 @@ void test_error_logging_multithread()
int i=0;
Thread errThread[NUM_TEST_THREADS];
MbedErrorStatus error_status[NUM_TEST_THREADS] = {
ERROR_INVALID_ARGUMENT, ERROR_INVALID_DATA, ERROR_INVALID_FORMAT, ERROR_INVALID_SIZE, ERROR_INVALID_OPERATION,
ERROR_NOT_FOUND, ERROR_ACCESS_DENIED, ERROR_FAILED_OPERATION, ERROR_OPERATION_PROHIBITED, ERROR_OPERATION_ABORTED
ERROR_INVALID_ARGUMENT, ERROR_INVALID_DATA_DETECTED, ERROR_INVALID_FORMAT, ERROR_INVALID_SIZE, ERROR_INVALID_OPERATION,
ERROR_ITEM_NOT_FOUND, ERROR_ACCESS_DENIED, ERROR_FAILED_OPERATION, ERROR_OPERATION_PROHIBITED, ERROR_OPERATION_ABORTED
};
@ -353,14 +353,14 @@ void test_error_logging_multithread()
}
i = get_error_log_count()-1;
printf("\nError log count = %d\n", i+1);
//printf("\nError log count = %d\n", i+1);
for(;i>=0;--i) {
MbedErrorStatus status = get_error_log_info( i, &error_ctx );
if(status != ERROR_SUCCESS) {
TEST_FAIL();
}
printf("\nError Status[%d] = 0x%08X Value = 0x%08X\n", i, (unsigned int)error_ctx.error_status, (unsigned int)error_ctx.error_value);
//printf("\nError Status[%d] = 0x%08X Value = 0x%08X\n", i, (unsigned int)error_ctx.error_status, (unsigned int)error_ctx.error_value);
TEST_ASSERT_EQUAL_UINT((unsigned int)error_ctx.error_value, (unsigned int)error_ctx.error_status);
}
}
@ -380,7 +380,7 @@ void test_error_hook()
TEST_FAIL();
}
SET_ERROR(ERROR_INVALID_ARGUMENT, "Test for error hook", 1234);
SET_WARNING(ERROR_INVALID_ARGUMENT, "Test for error hook", 1234);
int32_t sem_status = callback_sem.wait(5000);
TEST_ASSERT(sem_status > 0);
@ -421,16 +421,16 @@ MBED_TEST_SIM_BLOCKDEVICE_DECL;
void test_save_error_log()
{
//Log some errors
SET_ERROR(ERROR_TIMEOUT, "Timeout error", 1 );
SET_ERROR(ERROR_ALREADY_IN_USE, "Already in use error", 2 );
SET_ERROR(ERROR_NOT_SUPPORTED, "Not supported error", 3 );
SET_ERROR(ERROR_ACCESS_DENIED, "Access denied error", 4 );
SET_ERROR(ERROR_NOT_FOUND, "Not found error", 5 );
SET_ERROR(ERROR_INVALID_ARGUMENT, "Invalid argument error", 6 );
SET_ERROR(ERROR_INVALID_SIZE, "Invalid size error", 7 );
SET_ERROR(ERROR_INVALID_FORMAT, "Invalid format error", 8 );
SET_ERROR(ERROR_INVALID_OPERATION, "Invalid operation", 9 );
SET_ERROR(ERROR_NOT_READY, "Not ready error", 10 );
SET_WARNING(ERROR_TIME_OUT, "Timeout error", 1 );
SET_WARNING(ERROR_ALREADY_IN_USE, "Already in use error", 2 );
SET_WARNING(ERROR_UNSUPPORTED, "Not supported error", 3 );
SET_WARNING(ERROR_ACCESS_DENIED, "Access denied error", 4 );
SET_WARNING(ERROR_ITEM_NOT_FOUND, "Not found error", 5 );
SET_WARNING(ERROR_INVALID_ARGUMENT, "Invalid argument error", 6 );
SET_WARNING(ERROR_INVALID_SIZE, "Invalid size error", 7 );
SET_WARNING(ERROR_INVALID_FORMAT, "Invalid format error", 8 );
SET_WARNING(ERROR_INVALID_OPERATION, "Invalid operation", 9 );
SET_WARNING(ERROR_NOT_READY, "Not ready error", 10 );
int error = 0;

View File

@ -123,7 +123,7 @@ u32_t sys_now(void) {
*---------------------------------------------------------------------------*/
err_t sys_mbox_new(sys_mbox_t *mbox, int queue_sz) {
if (queue_sz > MB_SIZE)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_INVALID_SIZE), "sys_mbox_new size error\n", queue_sz);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_INVALID_SIZE), "sys_mbox_new size error\n", queue_sz);
memset(mbox, 0, sizeof(*mbox));
@ -131,7 +131,7 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int queue_sz) {
mbox->attr.cb_size = sizeof(mbox->data);
mbox->id = osEventFlagsNew(&mbox->attr);
if (mbox->id == NULL)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_CREATE_FAILED), "sys_mbox_new create error\n", mbox->id);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_CREATE_FAILED), "sys_mbox_new create error\n", mbox->id);
osEventFlagsSet(mbox->id, SYS_MBOX_POST_EVENT);
@ -150,7 +150,7 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int queue_sz) {
*---------------------------------------------------------------------------*/
void sys_mbox_free(sys_mbox_t *mbox) {
if (mbox->post_idx != mbox->fetch_idx)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_FREE_FAILED), "sys_mbox_free error\n", mbox->post_idx);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_FREE_FAILED), "sys_mbox_free error\n", mbox->post_idx);
}
/*---------------------------------------------------------------------------*
@ -309,7 +309,7 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count) {
sem->attr.cb_size = sizeof(sem->data);
sem->id = osSemaphoreNew(UINT16_MAX, count, &sem->attr);
if (sem->id == NULL)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_CREATE_FAILED), "sys_sem_new create error\n", sem->id);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_CREATE_FAILED), "sys_sem_new create error\n", sem->id);
return ERR_OK;
}
@ -388,14 +388,14 @@ err_t sys_mutex_new(sys_mutex_t *mutex) {
* @param mutex the mutex to lock */
void sys_mutex_lock(sys_mutex_t *mutex) {
if (osMutexAcquire(mutex->id, osWaitForever) != osOK)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_mutex_lock error\n", mutex->id);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_mutex_lock error\n", mutex->id);
}
/** Unlock a mutex
* @param mutex the mutex to unlock */
void sys_mutex_unlock(sys_mutex_t *mutex) {
if (osMutexRelease(mutex->id) != osOK)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_MUTEX_UNLOCK_FAILED), "sys_mutex_unlock error\n", mutex->id);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_UNLOCK_FAILED), "sys_mutex_unlock error\n", mutex->id);
}
/** Delete a mutex
@ -418,7 +418,7 @@ void sys_init(void) {
lwip_sys_mutex_attr.cb_size = sizeof(lwip_sys_mutex_data);
lwip_sys_mutex = osMutexNew(&lwip_sys_mutex_attr);
if (lwip_sys_mutex == NULL)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_INITIALIZATION_FAILED), "sys_init error\n", lwip_sys_mutex);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_INITIALIZATION_FAILED), "sys_init error\n", lwip_sys_mutex);
}
/*---------------------------------------------------------------------------*
@ -452,7 +452,7 @@ u32_t sys_jiffies(void) {
*---------------------------------------------------------------------------*/
sys_prot_t sys_arch_protect(void) {
if (osMutexAcquire(lwip_sys_mutex, osWaitForever) != osOK)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_arch_protect error\n", lwip_sys_mutex);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_arch_protect error\n", lwip_sys_mutex);
return (sys_prot_t) 1;
}
@ -469,7 +469,7 @@ sys_prot_t sys_arch_protect(void) {
*---------------------------------------------------------------------------*/
void sys_arch_unprotect(sys_prot_t p) {
if (osMutexRelease(lwip_sys_mutex) != osOK)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_arch_unprotect error\n", lwip_sys_mutex);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_arch_unprotect error\n", lwip_sys_mutex);
}
u32_t sys_now(void) {
@ -508,7 +508,7 @@ sys_thread_t sys_thread_new(const char *pcName,
LWIP_DEBUGF(SYS_DEBUG, ("New Thread: %s\n", pcName));
if (thread_pool_index >= SYS_THREAD_POOL_N)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new number error\n", thread_pool_index);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new number error\n", thread_pool_index);
sys_thread_t t = (sys_thread_t)&thread_pool[thread_pool_index];
thread_pool_index++;
@ -520,11 +520,11 @@ sys_thread_t sys_thread_new(const char *pcName,
t->attr.stack_size = stacksize;
t->attr.stack_mem = malloc(stacksize);
if (t->attr.stack_mem == NULL) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory", t);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory", t);
}
t->id = osThreadNew((osThreadFunc_t)thread, arg, &t->attr);
if (t->id == NULL)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_NETWORK_STACK, ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new create error\n", t->id);
SET_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new create error\n", t->id);
return t;
}

View File

@ -57,13 +57,13 @@ int ReadOnlyBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
int ReadOnlyBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_BLOCK_DEVICE, ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::program() not allowed", addr);
SET_ERROR(MAKE_ERROR(MODULE_BLOCK_DEVICE, ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::program() not allowed", addr);
return ERROR_WRITE_PROTECTED;
}
int ReadOnlyBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_BLOCK_DEVICE, ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::erase() not allowed", addr);
SET_ERROR(MAKE_ERROR(MODULE_BLOCK_DEVICE, ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::erase() not allowed", addr);
return ERROR_WRITE_PROTECTED;
}

View File

@ -29,7 +29,7 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
}
map++;
}
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_PINMAP_INVALID), "could not pinout", pin);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "could not pinout", pin);
}
uint32_t pinmap_merge(uint32_t a, uint32_t b) {
@ -44,7 +44,7 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b) {
return a;
// mis-match error case
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
return (uint32_t)NC;
}
@ -64,7 +64,7 @@ uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
return (uint32_t)NC;
peripheral = pinmap_find_peripheral(pin, map);
if ((uint32_t)NC == peripheral) // no mapping available
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral);
return peripheral;
}
@ -84,6 +84,6 @@ uint32_t pinmap_function(PinName pin, const PinMap* map) {
return (uint32_t)NC;
function = pinmap_find_function(pin, map);
if ((uint32_t)NC == function) // no mapping available
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function);
return function;
}

View File

@ -161,7 +161,7 @@ void sleep_manager_lock_deep_sleep_internal(void)
core_util_critical_section_enter();
if (deep_sleep_lock == USHRT_MAX) {
core_util_critical_section_exit();
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_HAL, ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
SET_ERROR(MAKE_ERROR(MODULE_HAL, ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
}
core_util_atomic_incr_u16(&deep_sleep_lock, 1);
core_util_critical_section_exit();
@ -172,7 +172,7 @@ void sleep_manager_unlock_deep_sleep_internal(void)
core_util_critical_section_enter();
if (deep_sleep_lock == 0) {
core_util_critical_section_exit();
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_HAL, ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", deep_sleep_lock);
SET_ERROR(MAKE_ERROR(MODULE_HAL, ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", deep_sleep_lock);
}
core_util_atomic_decr_u16(&deep_sleep_lock, 1);
core_util_critical_section_exit();

View File

@ -69,7 +69,7 @@ public:
sleep_manager_lock_deep_sleep();
}
if (0 == count) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", count);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", count);
}
}
@ -83,7 +83,7 @@ public:
}
if (count == USHRT_MAX) {
core_util_critical_section_exit();
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", count);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", count);
}
}
};

View File

@ -29,7 +29,7 @@ Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
if (_file) {
mbed_set_unbuffered_stream(_file);
} else {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OPEN_FAILED), "Stream obj failure", _file);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OPEN_FAILED), "Stream obj failure", _file);
}
}

View File

@ -23,6 +23,7 @@
#include "platform/mbed_error_log.h"
#include "platform/mbed_error_report.h"
#include "platform/mbed_interface.h"
#if DEVICE_STDIO_MESSAGES
#include <stdio.h>
#endif
@ -30,7 +31,7 @@
static uint8_t error_in_progress = 0;
static int error_count = 0;
static mbed_error_ctx first_error_ctx = {0};
static mbed_error_ctx current_error_ctx = {0};
static mbed_error_ctx last_error_ctx = {0};
static MbedErrorHook error_hook = NULL;
//Helper function to get the current SP
@ -83,11 +84,15 @@ WEAK void error(const char* format, ...) {
}
//Set an error status with the error handling system
MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
MbedErrorStatus handle_error(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
mbed_error_ctx current_error_ctx;
//Error status should always be < 0
if(error_status >= 0) {
return ERROR_INVALID_ARGUMENT;
//This is a weird situation, someone called set_error with invalid error code.
//We will still handle the situation but change the error code to ERROR_INVALID_ARGUMENT, atleast the context will have info on who called it
error_status = ERROR_INVALID_ARGUMENT;
}
//Use critsect here, as we don't want processing more than one error at the same time
@ -95,6 +100,8 @@ MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, u
//Increment error count
error_count++;
//Use critsect here, as we don't want processing more than one error at the same time
core_util_critical_section_exit();
//Clear the context capturing buffer
memset(&current_error_ctx, sizeof(mbed_error_ctx), 0);
@ -125,16 +132,13 @@ MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, u
current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem;
current_error_ctx.thread_current_sp = get_current_sp();
//Call the error hook if available
if(error_hook != NULL) {
error_hook(&current_error_ctx);
}
#ifndef MBED_CONF_ERROR_LOG_DISABLED
//Log the error with error log
mbed_log_put_error(&current_error_ctx);
#endif
//Use critsect here, as we don't want processing more than one error at the same time
core_util_critical_section_enter();
//Report the error
mbed_report_error(&current_error_ctx, (char *)error_msg);
@ -143,9 +147,17 @@ MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, u
memcpy(&first_error_ctx, &current_error_ctx, sizeof(mbed_error_ctx));
}
//copy this error to last error
memcpy(&last_error_ctx, &current_error_ctx, sizeof(mbed_error_ctx));
//Use critsect here, as we don't want processing more than one error at the same time
core_util_critical_section_exit();
//Call the error hook if available
if(error_hook != NULL) {
error_hook(&last_error_ctx);
}
return ERROR_SUCCESS;
}
@ -160,7 +172,7 @@ MbedErrorStatus get_first_error(void)
MbedErrorStatus get_last_error(void)
{
//return the last error recorded
return current_error_ctx.error_status;
return last_error_ctx.error_status;
}
//Gets the current error count
@ -171,10 +183,16 @@ int get_error_count(void)
}
//Sets a fatal error
MbedErrorStatus set_error_fatal(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
MbedErrorStatus set_warning(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return handle_error(error_status, error_msg, error_value, filename, line_number);
}
//Sets a fatal error
MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
//set the error reported and then halt the system
if( ERROR_SUCCESS != set_error(error_status, error_msg, error_value, filename, line_number) )
if( ERROR_SUCCESS != handle_error(error_status, error_msg, error_value, filename, line_number) )
return ERROR_FAILED_OPERATION;
mbed_halt_system();
@ -203,12 +221,12 @@ MbedErrorStatus get_first_error_log_info (mbed_error_ctx *error_info)
//Retrieve the last error context from error log
MbedErrorStatus get_last_error_log_info (mbed_error_ctx *error_info)
{
memcpy(error_info, &current_error_ctx, sizeof(mbed_error_ctx));
memcpy(error_info, &last_error_ctx, sizeof(mbed_error_ctx));
return ERROR_SUCCESS;
}
//Makes an MbedErrorStatus value
MbedErrorStatus make_mbed_error(MbedErrorType error_type, MbedEntityType entity, MbedErrorCode error_code)
MbedErrorStatus make_mbed_error(MbedErrorType error_type, MbedModuleType entity, MbedErrorCode error_code)
{
switch(error_type)
{
@ -232,7 +250,7 @@ MbedErrorStatus make_mbed_error(MbedErrorType error_type, MbedEntityType entity,
}
//If we are passed incorrect values return a generic system error
return MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, ENTITY_UNKNOWN, ERROR_CODE_UNKNOWN);
return MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MODULE_UNKNOWN, ERROR_CODE_UNKNOWN);
}
/**
@ -245,7 +263,7 @@ MbedErrorStatus clear_all_errors(void)
MbedErrorStatus status = ERROR_SUCCESS;
//Clear the error and context capturing buffer
memset(&current_error_ctx, sizeof(mbed_error_ctx), 0);
memset(&last_error_ctx, sizeof(mbed_error_ctx), 0);
//reset error count to 0
error_count = 0;
#ifndef MBED_CONF_ERROR_LOG_DISABLED
@ -276,13 +294,13 @@ MbedErrorStatus save_error_log(const char *path)
//Ensure path is valid
if(path==NULL) {
ret = MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_INVALID_ARGUMENT);
ret = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_INVALID_ARGUMENT);
goto exit;
}
//Open the file for saving the error log info
if((error_log_file = fopen( path, "w" ) ) == NULL){
ret = MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OPEN_FAILED);
ret = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OPEN_FAILED);
goto exit;
}
@ -292,16 +310,16 @@ MbedErrorStatus save_error_log(const char *path)
(unsigned int)first_error_ctx.thread_id,
(unsigned int)first_error_ctx.error_address,
(unsigned int)first_error_ctx.error_value) <= 0) {
ret = MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_WRITE_FAILED);
ret = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_WRITE_FAILED);
goto exit;
}
if(fprintf(error_log_file, "\nLast Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
(unsigned int)current_error_ctx.error_status,
(unsigned int)current_error_ctx.thread_id,
(unsigned int)current_error_ctx.error_address,
(unsigned int)current_error_ctx.error_value) <= 0) {
ret = MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_WRITE_FAILED);
(unsigned int)last_error_ctx.error_status,
(unsigned int)last_error_ctx.thread_id,
(unsigned int)last_error_ctx.error_address,
(unsigned int)last_error_ctx.error_value) <= 0) {
ret = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_WRITE_FAILED);
goto exit;
}
@ -315,7 +333,7 @@ MbedErrorStatus save_error_log(const char *path)
(unsigned int)ctx.thread_id,
(unsigned int)ctx.error_address,
(unsigned int)ctx.error_value) <= 0) {
ret = MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_WRITE_FAILED);
ret = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_WRITE_FAILED);
goto exit;
}
}

View File

@ -29,23 +29,25 @@
extern "C" {
#endif
//Define this macro to include filenames in error context, this can save memory. For release builds, do not include filename
//#define MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED 1
//Define this macro to disable error logging, note that the first and last error capture will still be active by default
//#define MBED_CONF_ERROR_LOG_DISABLED 1
/** Define this macro to include filenames in error context. For release builds, do not include filename to save memory.
* MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
*/
/** Define this macro to disable error logging, note that the first and last error capture will still be active by default.
* MBED_CONF_ERROR_LOG_DISABLED
*/
#ifndef MBED_CONF_MAX_ERROR_FILENAME_LEN
#define MBED_CONF_MAX_ERROR_FILENAME_LEN 16
#endif
#define MBED_ERROR_STATUS_CODE_MASK (0x0000FFFF)
#define MBED_ERROR_STATUS_CODE_POS (0)
#define MBED_ERROR_STATUS_CODE_FIELD_SIZE (16)
#define MBED_ERROR_STATUS_ENTITY_MASK (0x00FF0000)
#define MBED_ERROR_STATUS_ENTITY_POS (16)
#define MBED_ERROR_STATUS_ENTITY_FIELD_SIZE (8)
#define MBED_ERROR_STATUS_MODULE_MASK (0x00FF0000)
#define MBED_ERROR_STATUS_MODULE_POS (16)
#define MBED_ERROR_STATUS_MODULE_FIELD_SIZE (8)
#define MBED_ERROR_STATUS_TYPE_MASK (0x60000000)
#define MBED_ERROR_STATUS_TYPE_POS (29)
@ -53,33 +55,33 @@ extern "C" {
/* MbedErrorStatus Status Encoding */
//|31(1 bit) Always Negative|30-29(2 bits) |28-24 | 23-16(8 bits) | 15-0(16 bits) |
//|-1 |TYPE |(unused/reserved) | ENTITY TYPE | ERROR CODE |
//|-1 |TYPE |(unused/reserved) | MODULE TYPE | ERROR CODE |
#define MAKE_MBED_ERROR(type, entity, error_code) (MbedErrorStatus) \
#define MAKE_MBED_ERROR(type, module, error_code) (MbedErrorStatus) \
((0x80000000) | \
(MBED_ERROR_STATUS_CODE_MASK & (error_code << MBED_ERROR_STATUS_CODE_POS)) | \
(MBED_ERROR_STATUS_ENTITY_MASK & (entity << MBED_ERROR_STATUS_ENTITY_POS)) | \
(MBED_ERROR_STATUS_MODULE_MASK & (module << MBED_ERROR_STATUS_MODULE_POS)) | \
(MBED_ERROR_STATUS_TYPE_MASK & (type << MBED_ERROR_STATUS_TYPE_POS)))
#define GET_MBED_ERROR_TYPE( error_status ) ((error_status & MBED_ERROR_STATUS_TYPE_MASK) >> MBED_ERROR_STATUS_TYPE_POS)
#define GET_MBED_ERROR_ENTITY( error_status ) ((error_status & MBED_ERROR_STATUS_ENTITY_MASK) >> MBED_ERROR_STATUS_ENTITY_POS)
#define GET_MBED_ERROR_MODULE( error_status ) ((error_status & MBED_ERROR_STATUS_MODULE_MASK) >> MBED_ERROR_STATUS_MODULE_POS)
#define GET_MBED_ERROR_CODE( error_status ) (int)((GET_MBED_ERROR_TYPE( error_status ) == ERROR_TYPE_POSIX)?(-error_status):((error_status & MBED_ERROR_STATUS_CODE_MASK) >> MBED_ERROR_STATUS_CODE_POS))
/** MbedErrorStatus description
*
* MbedErrorStatus type represents the error status values under MbedOS. MbedErrorStatus values are signed integers and always be negative.\n
* Internally its encoded as below with bit-fields representing error type, entity and error code:\n\n
* Internally its encoded as below with bit-fields representing error type, module and error code:\n\n
* MbedErrorStatus Status Encoding:\n
*
\verbatim
| 31 Always Negative | 30-29(2 bits) | 28-24 | 23-16(8 bits) | 15-0(16 bits) |
| -1 | TYPE | (unused/reserved) | ENTITY TYPE | ERROR CODE |
| -1 | TYPE | (unused/reserved) | MODULE TYPE | ERROR CODE |
\endverbatim
*
* The error status value range for each error type is as follows:\n
* Posix Error Status-es - 0xFFFFFFFF to 0xFFFFFF01(-1 -255) - This corresponds to Posix error codes represented as negative.\n
* System Error Status-es - 0x80XX0100 to 0x80XX0FFF - This corresponds to System error codes range(all values are negative). Bits 23-16 will be entity type(marked with XX)\n
* Custom Error Status-es - 0xA0XX1000 to 0xA0XXFFFF - This corresponds to Custom error codes range(all values are negative). Bits 23-16 will be entity type(marked with XX)\n\n
* System Error Status-es - 0x80XX0100 to 0x80XX0FFF - This corresponds to System error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)\n
* Custom Error Status-es - 0xA0XX1000 to 0xA0XXFFFF - This corresponds to Custom error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)\n\n
*
* The ERROR CODE(values encoded into ERROR CODE bit-field in MbedErrorStatus) value range for each error type is also seperated as below:\n
* Posix Error Codes - 1 to 255.\n
@ -87,7 +89,7 @@ extern "C" {
* Custom Error Codes - 4096 to 65535.\n
*
* @note Posix error codes are always encoded as negative of their actual value. For example, EPERM is encoded as -EPERM.
* And, the ENTITY TYPE for Posix error codes are always encoded as ENTITY_UNKNOWN.\n
* And, the MODULE TYPE for Posix error codes are always encoded as MODULE_UNKNOWN.\n
* This is to enable easy injection of Posix error codes into MbedOS error handling system without altering the actual Posix error values.\n
* Accordingly, Posix error codes are represented as -1 to -255 under MbedOS error status representation.
*/
@ -111,7 +113,7 @@ typedef int MbedErrorStatus;
*/
#define DEFINE_SYSTEM_ERROR( error_name, error_code ) \
ERROR_CODE_##error_name = MBED_SYSTEM_ERROR_BASE + error_code, \
ERROR_##error_name = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, ENTITY_UNKNOWN, ERROR_CODE_##error_name)
ERROR_##error_name = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MODULE_UNKNOWN, ERROR_CODE_##error_name)
/**
* Macro for defining a Custom error status. This macro is used to define custom error values in MbedErrorCode enumeration.
@ -121,7 +123,7 @@ typedef int MbedErrorStatus;
*/
#define DEFINE_CUSTOM_ERROR( error_name, error_code ) \
ERROR_CODE_##error_name = MBED_CUSTOM_ERROR_BASE + error_code, \
ERROR_##error_name = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, ENTITY_UNKNOWN, ERROR_CODE_##error_name)
ERROR_##error_name = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MODULE_UNKNOWN, ERROR_CODE_##error_name)
/**
@ -140,13 +142,13 @@ typedef int MbedErrorStatus;
*
*/
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
#define SET_ERROR( error_status, error_msg, error_value ) set_error( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#define SET_WARNING( error_status, error_msg, error_value ) set_warning( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#else
#define SET_ERROR( error_status, error_msg, error_value ) set_error( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define SET_WARNING( error_status, error_msg, error_value ) set_warning( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#endif
/**
* Macro for setting a fatal system error. This macro will log the error, prints the error report and halts the system. Its a wrapper for calling set_error_fatal API
* Macro for setting a fatal system error. This macro will log the error, prints the error report and halts the system. Its a wrapper for calling set_error API
* @param error_status MbedErrorStatus status to be set(See MbedErrorStatus enum above for available error status values).
* @param error_msg The error message to be printed out to STDIO/Serial.
* @param error_value Value associated with the error status. This would depend on error code/error scenario.
@ -155,17 +157,17 @@ typedef int MbedErrorStatus;
*
* @code
*
* SET_ERROR_FATAL( ERROR_MUTEX_LOCK_FAILED, "MyDriver: Can't lock driver Mutex", &my_mutex )
* SET_ERROR( ERROR_MUTEX_LOCK_FAILED, "MyDriver: Can't lock driver Mutex", &my_mutex )
*
* @endcode
* @note The macro calls set_error_fatal API with filename and line number info without caller explicitly passing them.
* Since this macro is a wrapper for set_error_fatal API callers should process the return value from this macro which is the return value from calling set_error_fatal API.
* @note The macro calls set_error API with filename and line number info without caller explicitly passing them.
* Since this macro is a wrapper for set_error API callers should process the return value from this macro which is the return value from calling set_error API.
*
*/
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
#define SET_ERROR_FATAL( error_status, error_msg, error_value ) set_error_fatal( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#define SET_ERROR( error_status, error_msg, error_value ) set_error( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#else
#define SET_ERROR_FATAL( error_status, error_msg, error_value ) set_error_fatal( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define SET_ERROR( error_status, error_msg, error_value ) set_error( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#endif
//Error Type definition
@ -188,81 +190,81 @@ typedef enum _MbedErrorType
ERROR_TYPE_POSIX = 3
} MbedErrorType;
//Entity type/id definitions
/** MbedEntityType definition
//Module type/id definitions
/** MbedModuleType definition
* @note
* This enumeration defines the Entity types. The value of these enum values will be encoded into MbedErrorStatus ENTITY field.\n\n
* This enumeration defines the module types. The value of these enum values will be encoded into MbedErrorStatus MODULE field.\n\n
* See MbedErrorStatus description for more info.\n
* ENTITY_UNKNOWN - This entity type can be used if caller of the set_error/set_error_fatal doesn't know who is the actual originator of the error.\n
* Other entity values can be used to provide more info on who/where the error originated from.\n\n
* For example, if I2C driver is the component originating the error you can use ENTITY_DRIVER_I2C to provide more info.\n
* MODULE_UNKNOWN - This module type can be used if caller of the set_error/set_warning doesn't know who is the actual originator of the error.\n
* Other module values can be used to provide more info on who/where the error originated from.\n\n
* For example, if I2C driver is the component originating the error you can use MODULE_DRIVER_I2C to provide more info.\n
* Its used in call to MAKE_ERROR/MAKE_SYSTEM_ERROR/MAKE_CUSTOM_ERROR macros.\n
*
* @code
* Example: MbedErrorStatus i2c_driver_error = MAKE_ERROR( ENTITY_DRIVER_I2C, ERROR_CONFIG_UNSUPPORTED );
* Example: MbedErrorStatus i2c_driver_error = MAKE_ERROR( MODULE_DRIVER_I2C, ERROR_CONFIG_UNSUPPORTED );
* @endcode
*
* @note
* \n Below are the entity code mappings:\n
* \n Below are the module code mappings:\n
\verbatim
ENTITY_APPLICATION 0 Application
ENTITY_PLATFORM 1 Platform
ENTITY_KERNEL 2 RTX Kernel
ENTITY_NETWORK_STACK 3 Network stack
ENTITY_HAL 4 HAL - Hardware Abstraction Layer
ENTITY_MEMORY_SUBSYSTEM 5 Memory Subsystem
ENTITY_FILESYSTEM 6 Filesystem
ENTITY_BLOCK_DEVICE 7 Block device
ENTITY_DRIVER 8 Driver
ENTITY_DRIVER_SERIAL 9 Serial Driver
ENTITY_DRIVER_RTC 10 RTC Driver
ENTITY_DRIVER_I2C 11 I2C Driver
ENTITY_DRIVER_SPI 12 SPI Driver
ENTITY_DRIVER_GPIO 13 GPIO Driver
ENTITY_DRIVER_ANALOG 14 Analog Driver
ENTITY_DRIVER_DIGITAL 15 DigitalIO Driver
ENTITY_DRIVER_CAN 16 CAN Driver
ENTITY_DRIVER_ETHERNET 17 Ethernet Driver
ENTITY_DRIVER_CRC 18 CRC Module
ENTITY_DRIVER_PWM 19 PWM Driver
ENTITY_DRIVER_QSPI 20 QSPI Driver
ENTITY_DRIVER_USB 21 USB Driver
ENTITY_TARGET_SDK 22 SDK
MODULE_APPLICATION 0 Application
MODULE_PLATFORM 1 Platform
MODULE_KERNEL 2 RTX Kernel
MODULE_NETWORK_STACK 3 Network stack
MODULE_HAL 4 HAL - Hardware Abstraction Layer
MODULE_MEMORY_SUBSYSTEM 5 Memory Subsystem
MODULE_FILESYSTEM 6 Filesystem
MODULE_BLOCK_DEVICE 7 Block device
MODULE_DRIVER 8 Driver
MODULE_DRIVER_SERIAL 9 Serial Driver
MODULE_DRIVER_RTC 10 RTC Driver
MODULE_DRIVER_I2C 11 I2C Driver
MODULE_DRIVER_SPI 12 SPI Driver
MODULE_DRIVER_GPIO 13 GPIO Driver
MODULE_DRIVER_ANALOG 14 Analog Driver
MODULE_DRIVER_DIGITAL 15 DigitalIO Driver
MODULE_DRIVER_CAN 16 CAN Driver
MODULE_DRIVER_ETHERNET 17 Ethernet Driver
MODULE_DRIVER_CRC 18 CRC Module
MODULE_DRIVER_PWM 19 PWM Driver
MODULE_DRIVER_QSPI 20 QSPI Driver
MODULE_DRIVER_USB 21 USB Driver
MODULE_TARGET_SDK 22 SDK
ENTITY_UNKNOWN 255 Unknown entity
MODULE_UNKNOWN 255 Unknown module
\endverbatim
*
*/
typedef enum _MbedEntityType
typedef enum _MbedModuleType
{
ENTITY_APPLICATION = 0,
ENTITY_PLATFORM,
ENTITY_KERNEL,
ENTITY_NETWORK_STACK,
ENTITY_HAL,
ENTITY_MEMORY_SUBSYSTEM,
ENTITY_FILESYSTEM,
ENTITY_BLOCK_DEVICE,
ENTITY_DRIVER,
ENTITY_DRIVER_SERIAL,
ENTITY_DRIVER_RTC,
ENTITY_DRIVER_I2C,
ENTITY_DRIVER_SPI,
ENTITY_DRIVER_GPIO,
ENTITY_DRIVER_ANALOG,
ENTITY_DRIVER_DIGITAL,
ENTITY_DRIVER_CAN,
ENTITY_DRIVER_ETHERNET,
ENTITY_DRIVER_CRC,
ENTITY_DRIVER_PWM,
ENTITY_DRIVER_QSPI,
ENTITY_DRIVER_USB,
ENTITY_TARGET_SDK,
MODULE_APPLICATION = 0,
MODULE_PLATFORM,
MODULE_KERNEL,
MODULE_NETWORK_STACK,
MODULE_HAL,
MODULE_MEMORY_SUBSYSTEM,
MODULE_FILESYSTEM,
MODULE_BLOCK_DEVICE,
MODULE_DRIVER,
MODULE_DRIVER_SERIAL,
MODULE_DRIVER_RTC,
MODULE_DRIVER_I2C,
MODULE_DRIVER_SPI,
MODULE_DRIVER_GPIO,
MODULE_DRIVER_ANALOG,
MODULE_DRIVER_DIGITAL,
MODULE_DRIVER_CAN,
MODULE_DRIVER_ETHERNET,
MODULE_DRIVER_CRC,
MODULE_DRIVER_PWM,
MODULE_DRIVER_QSPI,
MODULE_DRIVER_USB,
MODULE_TARGET_SDK,
/* Add More entities here as required */
ENTITY_UNKNOWN = 255,
ENTITY_MAX = ENTITY_UNKNOWN
} MbedEntityType;
MODULE_UNKNOWN = 255,
MODULE_MAX = MODULE_UNKNOWN
} MbedModuleType;
//Use ERROR_SUCCESS(=0) or any postive number for successful returns
#define ERROR_SUCCESS 0
@ -274,7 +276,7 @@ typedef enum _MbedEntityType
//Error Code definitions
/** MbedErrorCode definition
*
* MbedErrorCode enumeration defines the Error codes and Error status values for ENTITY_UNKNOWN.\n
* MbedErrorCode enumeration defines the Error codes and Error status values for MODULE_UNKNOWN.\n
* It defines all of Posix Error Codes/Statuses and Mbed System Error Codes/Statuses.\n\n
*
* @note
@ -430,10 +432,10 @@ typedef enum _MbedEntityType
* MbedOS System Error codes are defined using the macro DEFINE_SYSTEM_ERROR\n
* For example DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ) macro defines the following values:\n
* ERROR_CODE_INVALID_ARGUMENT = MBED_SYSTEM_ERROR_BASE+1\n
* ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, ENTITY_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)\n
* ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MODULE_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)\n
* Its effectively equivalent to:\n
* ERROR_CODE_INVALID_ARGUMENT = 1\n
* ERROR_INVALID_ARGUMENT = 0x80FF0001\n (Note that ENTITY field is set to ENTITY_UNKNOWN)
* ERROR_INVALID_ARGUMENT = 0x80FF0001\n (Note that MODULE field is set to MODULE_UNKNOWN)
* New System Error codes should be defined using DEFINE_SYSTEM_ERROR macro and must have an unique error code value\n
* passed as the second argument in the DEFINE_SYSTEM_ERROR macro.\n\n
* Below are the Mbed System error codes and the description:
@ -510,26 +512,35 @@ typedef enum _MbedEntityType
* This is mainly meant to capture non-generic error codes specific to a device.
* For example DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR ,1 ) macro defines the following values:\n
* ERROR_CODE_MY_CUSTOM_ERROR = MBED_CUSTOM_ERROR_BASE+1\n
* ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, ENTITY_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)\n
* ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MODULE_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)\n
* Its effectively equivalent to:\n
* ERROR_CODE_MY_CUSTOM_ERROR = 4097\n
* ERROR_MY_CUSTOM_ERROR = 0xA0FF1001\n (Note that ENTITY field is set to ENTITY_UNKNOWN) \n\n
* ERROR_MY_CUSTOM_ERROR = 0xA0FF1001\n (Note that MODULE field is set to MODULE_UNKNOWN) \n\n
*
* @note
* **Using error codes:** \n
* Posix error codes may be used in modules/functions currently using Posix error codes and switching them to Mbed-OS error codes
* may cause interoperability issues. For example, some of the filesystem, network stack implementations may need to use
* Posix error codes in order to keep them compatible with other modules interfacing with them, and may continue to use Posix error codes.
*
* In all other cases, like for any native development of Mbed-OS modules Mbed-OS error codes should be used.
* This makes it easy to use Mbed-OS error reporting/logging infrastructure and makes debugging error scenarios
* much more efficient.
*
* @note
* **Searching for error codes in mbed-os source tree:** \n
* If you get an error report as below which you want to search for in mbed-os source tree, first take note of "Error Code" number. \n
* For example, the below error report has an error code of \b 259. Find the error name associated with the error code and in this case its \b INVALID_FORMAT. \n
* Use that error name(\b INVALID_FORMAT) to search the source tree for code locations setting that specific error code. \n
* If the Error Entity reported is not 255(which indicates unknown entity), you can also use that to narrow down to the specific component reporting the error.
* See MbedEntityType enum above for entity mapping. \n
* If the Error module reported is not 255(which indicates unknown module), you can also use that to narrow down to the specific component reporting the error.
* See MbedModuleType enum above for module mapping. \n
*
* \verbatim
++ MbedOS Error Info ++
Error Status: 0x80040103
Error Code: 259
Error Entity: 04
Error Message: HAL Entity error
Error Module: 04
Error Message: HAL Module error
Error Location: 0x000067C7
Error Value: 0x00005566
Current Thread: Id: 0x200024A8 EntryFn: 0x0000FB0D StackSize: 0x00001000 StackMem: 0x200014A8 SP: 0x2002FFD8
@ -680,18 +691,18 @@ typedef enum _MbedErrorCode
// Error Name Error Offset Error Code
DEFINE_SYSTEM_ERROR( UNKNOWN ,0 ), /* 256 Unknown error */
DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ), /* 257 Invalid Argument */
DEFINE_SYSTEM_ERROR( INVALID_DATA ,2 ), /* 258 Invalid data */
DEFINE_SYSTEM_ERROR( INVALID_DATA_DETECTED ,2 ), /* 258 Invalid data detected */
DEFINE_SYSTEM_ERROR( INVALID_FORMAT ,3 ), /* 259 Invalid format */
DEFINE_SYSTEM_ERROR( INVALID_INDEX ,4 ), /* 260 Invalid Index */
DEFINE_SYSTEM_ERROR( INVALID_SIZE ,5 ), /* 261 Inavlid Size */
DEFINE_SYSTEM_ERROR( INVALID_OPERATION ,6 ), /* 262 Invalid Operation */
DEFINE_SYSTEM_ERROR( NOT_FOUND ,7 ), /* 263 Not Found */
DEFINE_SYSTEM_ERROR( ITEM_NOT_FOUND ,7 ), /* 263 Item Not Found */
DEFINE_SYSTEM_ERROR( ACCESS_DENIED ,8 ), /* 264 Access Denied */
DEFINE_SYSTEM_ERROR( NOT_SUPPORTED ,9 ), /* 265 Not supported */
DEFINE_SYSTEM_ERROR( UNSUPPORTED ,9 ), /* 265 Unsupported */
DEFINE_SYSTEM_ERROR( BUFFER_FULL ,10 ), /* 266 Buffer Full */
DEFINE_SYSTEM_ERROR( MEDIA_FULL ,11 ), /* 267 Media/Disk Full */
DEFINE_SYSTEM_ERROR( ALREADY_IN_USE ,12 ), /* 268 Already in use */
DEFINE_SYSTEM_ERROR( TIMEOUT ,13 ), /* 269 Timeout error */
DEFINE_SYSTEM_ERROR( TIME_OUT ,13 ), /* 269 Timeout error */
DEFINE_SYSTEM_ERROR( NOT_READY ,14 ), /* 270 Not Ready */
DEFINE_SYSTEM_ERROR( FAILED_OPERATION ,15 ), /* 271 Requested Operation failed */
DEFINE_SYSTEM_ERROR( OPERATION_PROHIBITED ,16 ), /* 272 Operation prohibited */
@ -795,8 +806,8 @@ typedef struct _mbed_error_ctx {
* Code snippets below show valid format.
*
* @deprecated
* This function has been deprecated, please use one of SET_ERROR/SET_ERROR_FATAL macros
* or one of set_error/set_error_fatal functions.
* This function has been deprecated, please use one of SET_WARNING/SET_ERROR macros
* or one of set_error/set_warning functions.
*
* @code
* #error "That shouldn't have happened!"
@ -835,54 +846,54 @@ typedef struct _mbed_error_ctx {
*
*/
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function has been deprecated, please use one of SET_ERROR/SET_ERROR_FATAL macros or one of set_error/set_error_fatal functions" )
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function has been deprecated, please use one of SET_WARNING/SET_ERROR macros or one of set_warning/set_error functions" )
void error(const char* format, ...);
/**
* Call this Macro to generate a MbedErrorStatus value for a System error
* @param entity Entity generating the error code. If its unknown, pass ENTITY_UNKNOWN. See MbedEntityType for entity types.
* @param module Module generating the error code. If its unknown, pass MODULE_UNKNOWN. See MbedModuleType for module types.
* @param error_code The MbedErrorCode code to be used in generating the MbedErrorStatus. See MbedErrorCode for error codes.
*
* @code
*
* MbedErrorStatus driver_error = MAKE_SYSTEM_ERROR( ENTITY_DRIVER_USB, ERROR_CODE_INITIALIZATION_FAILED )
* MbedErrorStatus driver_error = MAKE_SYSTEM_ERROR( MODULE_DRIVER_USB, ERROR_CODE_INITIALIZATION_FAILED )
*
* @endcode
* @note This macro generate MbedErrorStatus-es with error type set to ERROR_TYPE_SYSTEM
*
*/
#define MAKE_SYSTEM_ERROR(entity, error_code) MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, entity, error_code)
#define MAKE_SYSTEM_ERROR(module, error_code) MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, module, error_code)
/**
* Call this Macro to generate a MbedErrorStatus value for a Custom error
* @param entity Entity generating the error code. If its unknown, pass ENTITY_UNKNOWN. See MbedEntityType for entity types.
* @param module Module generating the error code. If its unknown, pass MODULE_UNKNOWN. See MbedModuleType for module types.
* @param error_code The MbedErrorCode code to be used in generating the MbedErrorStatus. See MbedErrorCode for error codes.
*
* @code
*
* MbedErrorStatus custom_error = MAKE_CUSTOM_ERROR( ENTITY_APPLICATION, 0xDEAD//16-bit custom error code )
* MbedErrorStatus custom_error = MAKE_CUSTOM_ERROR( MODULE_APPLICATION, 0xDEAD//16-bit custom error code )
*
* @endcode
* @note This macro generate MbedErrorStatus-es with error type set to ERROR_TYPE_CUSTOM
*
*/
#define MAKE_CUSTOM_ERROR(entity, error_code) MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, entity, error_code)
#define MAKE_CUSTOM_ERROR(module, error_code) MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, module, error_code)
/**
* Call this Macro to generate a MbedErrorStatus value for a System error
* @param entity Entity generating the error code. If its unknown, pass ENTITY_UNKNOWN. See MbedEntityType for entity types.
* @param module Module generating the error code. If its unknown, pass MODULE_UNKNOWN. See MbedModuleType for module types.
* @param error_code The MbedErrorCode code to be used in generating the MbedErrorStatus. See MbedErrorCode for error codes.
*
* @code
*
* MbedErrorStatus new_error = MAKE_ERROR( ENTITY_DRIVER_USB, ERROR_INITIALIZATION_FAILED )
* MbedErrorStatus new_error = MAKE_ERROR( MODULE_DRIVER_USB, ERROR_INITIALIZATION_FAILED )
*
* @endcode
* @note This macro generate MbedErrorStatus-es with error type set to ERROR_TYPE_SYSTEM
*
*/
#define MAKE_ERROR(entity, error_code) MAKE_SYSTEM_ERROR(entity, error_code)
#define MAKE_ERROR(module, error_code) MAKE_SYSTEM_ERROR(module, error_code)
/**
* Callback/Error hook function prototype. Applications needing a callback when an error is reported can use set_error_hook function
@ -896,7 +907,7 @@ void error(const char* format, ...);
typedef void (*MbedErrorHook)(const mbed_error_ctx *error_ctx);
/**
* Call this function to set a system error. This function will log the error status with the context info, prints the error report and return to caller.
* Call this function to set a system error/warning. This function will log the error status with the context info, prints the error report and return to caller.
*
* @param error_status MbedErrorStatus status to be set(See MbedErrorStatus enum above for available error status values).
* @param error_msg The error message to be printed out to STDIO/Serial.
@ -912,9 +923,9 @@ typedef void (*MbedErrorHook)(const mbed_error_ctx *error_ctx);
*
* @endcode
*
* @note See SET_ERROR/SET_ERROR_FATAL macros which provides a wrapper on this API
* @note See SET_WARNING/SET_ERROR macros which provides a wrapper on this API
*/
MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
MbedErrorStatus set_warning(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
/**
* Returns the first system error reported.
@ -950,17 +961,18 @@ int get_error_count(void);
*
* @code
*
* set_error_fatal( ERROR_PROHIBITED_OPERATION, "Prohibited operation tried", 0, __FILE__, __LINE__ )
* set_error( ERROR_PROHIBITED_OPERATION, "Prohibited operation tried", 0, __FILE__, __LINE__ )
*
* @endcode
*
* @note See SET_ERROR/SET_ERROR_FATAL macros which provides a wrapper on this API
* @note See SET_WARNING/SET_ERROR macros which provides a wrapper on this API
*/
MbedErrorStatus set_error_fatal(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
MbedErrorStatus set_error(MbedErrorStatus error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
/**
* Registers an application defined error callback with the error handling system.
* This function will be called with error context info whenever system handles a set_error/set_error_fatal call
* This function will be called with error context info whenever system handles a set_error/set_warning call
* NOTE: This function should be implemented for re-entrancy as multiple threads may invoke set_error which may cause error hook to be called.
* @param custom_error_hook MbedErrorStatus status to be set(See MbedErrorStatus enum above for available error status values).
* @return 0 or ERROR_SUCCESS on success.
* ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
@ -974,6 +986,7 @@ MbedErrorStatus set_error_fatal(MbedErrorStatus error_status, const char *error_
* set_error_hook( my_custom_error_hook )
*
* @endcode
* @note The erro hook function implementation should be re-entrant.
*
*/
MbedErrorStatus set_error_hook(MbedErrorHook custom_error_hook);
@ -1004,14 +1017,14 @@ MbedErrorStatus get_last_error_log_info(mbed_error_ctx *error_info);
MbedErrorStatus clear_all_errors(void);
/**
* Generates a MbedErrorStatus value based on passed in values for type, entity and error code.
* Generates a MbedErrorStatus value based on passed in values for type, module and error code.
* @param error_type Error type based on MbedErrorType enum.
* @param entity Entity type based on MbedEntityType enum.
* @param module Module type based on MbedModuleType enum.
* @param error_code Error codes defined by MbedErrorCode enum
* @return 0 or ERROR_SUCCESS on success.
*
*/
MbedErrorStatus make_mbed_error(MbedErrorType error_type, MbedEntityType entity, MbedErrorCode error_code);
MbedErrorStatus make_mbed_error(MbedErrorType error_type, MbedModuleType module, MbedErrorCode error_code);
/**
* Returns the current number of entries in the error log, if there has been more than max number of errors logged the number returned will be max depth of error log.

View File

@ -27,16 +27,6 @@
static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_ERROR_LOG_SIZE] = {0};
static int error_log_count = -1;
static void mbed_log_lock()
{
core_util_critical_section_enter();
}
static void mbed_log_unlock()
{
core_util_critical_section_exit();
}
MbedErrorStatus mbed_log_put_error(mbed_error_ctx *error_ctx)
{
//Return error if error_ctx is NULL
@ -44,10 +34,10 @@ MbedErrorStatus mbed_log_put_error(mbed_error_ctx *error_ctx)
return ERROR_INVALID_ARGUMENT;
}
mbed_log_lock();
core_util_critical_section_enter();
error_log_count++;
memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_LOG_SIZE], error_ctx, sizeof(mbed_error_ctx) );
mbed_log_unlock();
core_util_critical_section_exit();
return ERROR_SUCCESS;
}
@ -59,12 +49,12 @@ MbedErrorStatus mbed_log_get_error(int index, mbed_error_ctx *error_ctx)
return ERROR_INVALID_ARGUMENT;
}
mbed_log_lock();
core_util_critical_section_enter();
//calculate the index where we want to pick the ctx
if(error_log_count >= MBED_CONF_ERROR_LOG_SIZE) {
index = (error_log_count + index + 1) % MBED_CONF_ERROR_LOG_SIZE;
}
mbed_log_unlock();
core_util_critical_section_exit();
memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_ERROR_LOG_SIZE], sizeof(mbed_error_ctx) );
return ERROR_SUCCESS;
@ -72,10 +62,10 @@ MbedErrorStatus mbed_log_get_error(int index, mbed_error_ctx *error_ctx)
mbed_error_ctx *mbed_log_get_entry(void)
{
mbed_log_lock();
core_util_critical_section_enter();
error_log_count++;
mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_LOG_SIZE];
mbed_log_unlock();
core_util_critical_section_exit();
return ctx;
}
@ -83,11 +73,11 @@ mbed_error_ctx *mbed_log_get_entry(void)
MbedErrorStatus mbed_log_get_last_error(mbed_error_ctx *error_ctx)
{
if(-1 == error_log_count) {
return ERROR_NOT_FOUND;
return ERROR_ITEM_NOT_FOUND;
}
mbed_log_lock();
core_util_critical_section_enter();
memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_LOG_SIZE], sizeof(mbed_error_ctx) );
mbed_log_unlock();
core_util_critical_section_exit();
return ERROR_SUCCESS;
}
@ -99,9 +89,9 @@ int mbed_log_get_error_log_count()
MbedErrorStatus mbed_log_reset()
{
mbed_log_lock();
core_util_critical_section_enter();
error_log_count = -1;
mbed_log_unlock();
core_util_critical_section_exit();
return ERROR_SUCCESS;
}

View File

@ -18,15 +18,15 @@
#include "rtx_os.h"
#include "mbed_rtx.h"
#include "hal/serial_api.h"
#include "hal/itm_api.h"
#include "platform/mbed_error.h"
#include "platform/mbed_error_report.h"
#if DEVICE_SERIAL
#ifdef DEVICE_SERIAL
extern int stdio_uart_inited;
extern serial_t stdio_uart;
#endif
/* Converts a uint32 to hex char string */
static void value_to_hex_str(uint32_t value, char *hex_str)
{
@ -56,6 +56,33 @@ static void value_to_dec_str(uint32_t value, char *dec_str)
}
}
void mbed_error_init(void)
{
#if DEVICE_SERIAL && (MBED_CONF_ERROR_REPORT_INTERFACE==DEVICE_SERIAL)
/* Initializes std uart if not init-ed yet */
if (!stdio_uart_inited) {
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
}
#endif
#if DEVICE_ITM && (MBED_CONF_ERROR_REPORT_INTERFACE==DEVICE_ITM)
/*Initialize ITM interfaces*/
mbed_itm_init();
#endif
}
void mbed_error_putc(char ch)
{
#if DEVICE_SERIAL && (MBED_CONF_ERROR_REPORT_INTERFACE==DEVICE_SERIAL)
serial_putc(&stdio_uart, ch);
#endif
#if DEVICE_ITM && (MBED_CONF_ERROR_REPORT_INTERFACE==DEVICE_ITM)
/*Initialize ITM interfaces*/
mbed_itm_send(ITM_PORT_SWO, ch);
#endif
}
/* Limited print functionality which prints the string out to
stdout/uart without using stdlib by directly calling serial-api
and also uses less resources
@ -72,10 +99,8 @@ void mbed_error_print(char *fmtstr, uint32_t *values)
char num_str[9]={0};
char *str=NULL;
/* Initializes std uart if not init-ed yet */
if (!stdio_uart_inited) {
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
}
//Init error reporting interfaces
mbed_error_init();
while(fmtstr[i] != '\0') {
if(fmtstr[i]=='%') {
@ -85,7 +110,7 @@ void mbed_error_print(char *fmtstr, uint32_t *values)
//print the number in hex format
value_to_hex_str(values[vidx++],num_str);
for(idx=7; idx>=0; idx--) {
serial_putc(&stdio_uart, num_str[idx]);
mbed_error_putc(num_str[idx]);
}
}
else if(fmtstr[i]=='d') {
@ -95,24 +120,28 @@ void mbed_error_print(char *fmtstr, uint32_t *values)
idx=7;
while(num_str[idx--]=='0' && idx > 0);//Dont print zeros at front
for(idx++;idx>=0; idx--) {
serial_putc(&stdio_uart, num_str[idx]);
mbed_error_putc(num_str[idx]);
}
}
else if(fmtstr[i]=='s') {
//print the string
str = (char *)((uint32_t)values[vidx++]);
while(*str != '\0') {
serial_putc(&stdio_uart, *str);
mbed_error_putc(*str);
str++;
}
str = NULL;
} else {
//print the % and char without formatting and keep going
serial_putc(&stdio_uart, '%');
serial_putc(&stdio_uart, fmtstr[i]);
mbed_error_putc('%');
mbed_error_putc(fmtstr[i]);
}
} else {
serial_putc(&stdio_uart, fmtstr[i]);
//handle carriage returns
if (fmtstr[i] == '\n') {
mbed_error_putc('\r');
}
mbed_error_putc(fmtstr[i]);
}
i++;
}
@ -144,7 +173,7 @@ void print_thread(osRtxThread_t *thread)
void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg)
{
int error_code = GET_MBED_ERROR_CODE(error_ctx->error_status);
int error_entity = GET_MBED_ERROR_ENTITY(error_ctx->error_status);
int error_entity = GET_MBED_ERROR_MODULE(error_ctx->error_status);
mbed_error_print("\n\n++ MbedOS Error Info ++\nError Status: 0x%x", (uint32_t *)&error_ctx->error_status);
mbed_error_print("\nError Code: %d", (uint32_t *)&error_code);

View File

@ -22,8 +22,12 @@
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MBED_CONF_ERROR_REPORT_INTERFACE
#define MBED_CONF_ERROR_REPORT_INTERFACE DEVICE_SERIAL
#endif
/* routine to report the error */
/* Routine to report the error */
void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg);
/* Prints thread info from a list */
@ -40,6 +44,12 @@ found in that it fetches a uint32 value from values buffer
and prints it in hex format.
*/
void mbed_error_print(char *fmtstr, uint32_t *values);
/*Initializes the data structures and interfaces for printing the error output*/
void mbed_error_init(void);
/*Routine which putc into serial/itm interface*/
void mbed_error_putc(char ch);
#ifdef __cplusplus
}

View File

@ -126,7 +126,6 @@ void remove_filehandle(FileHandle *file) {
#if DEVICE_SERIAL
extern int stdio_uart_inited;
extern serial_t stdio_uart;
#endif
/* Private FileHandle to implement backwards-compatible functionality of
* direct HAL serial access for default stdin/stdout/stderr.
@ -193,6 +192,7 @@ short DirectSerial::poll(short events) const {
}
return revents;
}
#endif
class Sink : public FileHandle {
public:
@ -538,7 +538,7 @@ extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsign
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_PROHIBITED_IN_ISR_CONTEXT), "Error - writing to a file in an ISR or critical section\r\n", fh);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PROHIBITED_IN_ISR_CONTEXT), "Error - writing to a file in an ISR or critical section\r\n", fh);
}
#endif
@ -646,7 +646,7 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_PROHIBITED_IN_ISR_CONTEXT), "Error - reading from a file in an ISR or critical section\r\n", fh);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PROHIBITED_IN_ISR_CONTEXT), "Error - reading from a file in an ISR or critical section\r\n", fh);
}
#endif
@ -1088,7 +1088,7 @@ extern "C" int statvfs(const char *path, struct statvfs *buf) {
#include "mbed_error.h"
namespace __gnu_cxx {
void __verbose_terminate_handler() {
SET_ERROR_FATAL(MAKE_ERROR( ENTITY_PLATFORM, ERROR_CODE_CLIB_EXCEPTION),"Exception", 0);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_CLIB_EXCEPTION),"Exception", 0);
}
}
extern "C" WEAK void __cxa_pure_virtual(void);
@ -1471,7 +1471,7 @@ void *operator new(std::size_t count)
{
void *buffer = malloc(count);
if (NULL == buffer) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Operator new out of memory\r\n", count);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Operator new out of memory\r\n", count);
}
return buffer;
}
@ -1480,7 +1480,7 @@ void *operator new[](std::size_t count)
{
void *buffer = malloc(count);
if (NULL == buffer) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Operator new[] out of memory\r\n", count);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Operator new[] out of memory\r\n", count);
}
return buffer;
}

View File

@ -82,8 +82,8 @@ __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_conte
mbed_error_print("\n\n-- MbedOS Fault Handler --\n\n",NULL);
//Now call set_error_fatal, to log the error and halt the system
set_error_fatal( MAKE_ERROR( ENTITY_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC, NULL, 0 );
//Now call set_error, to log the error and halt the system
set_error( MAKE_ERROR( MODULE_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC, NULL, 0 );
/* In case we return, just spin here, we have already crashed */
for (;;) {

View File

@ -323,7 +323,7 @@ void mbed_start_main(void)
_main_thread_attr.name = "main_thread";
osThreadId_t result = osThreadNew((osThreadFunc_t)pre_main, NULL, &_main_thread_attr);
if ((void *)result == NULL) {
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_INITIALIZATION_FAILED), "Pre main thread not created", &_main_thread_attr);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_INITIALIZATION_FAILED), "Pre main thread not created", &_main_thread_attr);
}
osKernelStart();

View File

@ -47,27 +47,27 @@ __NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id)
case osRtxErrorStackUnderflow:
// Stack underflow detected for thread (thread_id=object_id)
// Note: "overflow" is printed instead of "underflow" due to end user familiarity with overflow errors
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_KERNEL, ERROR_CODE_STACK_OVERFLOW), "CMSIS-RTOS error: Stack overflow", code);
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_STACK_OVERFLOW), "CMSIS-RTOS error: Stack overflow", code);
break;
case osRtxErrorISRQueueOverflow:
// ISR Queue overflow detected when inserting object (object_id)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_KERNEL, ERROR_CODE_ISR_QUEUE_OVERFLOW), "CMSIS-RTOS error: ISR Queue overflow", code);
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_ISR_QUEUE_OVERFLOW), "CMSIS-RTOS error: ISR Queue overflow", code);
break;
case osRtxErrorTimerQueueOverflow:
// User Timer Callback Queue overflow detected for timer (timer_id=object_id)
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_KERNEL, ERROR_CODE_TIMER_QUEUE_OVERFLOW), "CMSIS-RTOS error: User Timer Callback Queue overflow", code);
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_TIMER_QUEUE_OVERFLOW), "CMSIS-RTOS error: User Timer Callback Queue overflow", code);
break;
case osRtxErrorClibSpace:
// Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_KERNEL, ERROR_CODE_CLIB_SPACE_UNAVAILABLE), "CMSIS-RTOS error: STD C/C++ library libspace not available", code);
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_CLIB_SPACE_UNAVAILABLE), "CMSIS-RTOS error: STD C/C++ library libspace not available", code);
break;
case osRtxErrorClibMutex:
// Standard C/C++ library mutex initialization failed
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_KERNEL, ERROR_CODE_CLIB_MUTEX_INIT_FAILURE), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed", code);
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_CLIB_MUTEX_INIT_FAILURE), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed", code);
break;
default:
//Unknown error flagged from kernel
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_KERNEL, ERROR_CODE_UNKNOWN), "CMSIS-RTOS error: Unknown", code);
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_UNKNOWN), "CMSIS-RTOS error: Unknown", code);
break;
}
@ -99,27 +99,27 @@ static const char* error_msg(int32_t status)
void EvrRtxKernelError (int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_EVENT), error_msg(status), status);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_EVENT), error_msg(status), status);
}
void EvrRtxThreadError (osThreadId_t thread_id, int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_THREAD_EVENT), error_msg(status), thread_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_THREAD_EVENT), error_msg(status), thread_id);
}
void EvrRtxTimerError (osTimerId_t timer_id, int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_TIMER_EVENT), error_msg(status), timer_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_TIMER_EVENT), error_msg(status), timer_id);
}
void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_EVENT_FLAGS_EVENT), error_msg(status), ef_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_EVENT_FLAGS_EVENT), error_msg(status), ef_id);
}
void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_MUTEX_EVENT), error_msg(status), mutex_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_MUTEX_EVENT), error_msg(status), mutex_id);
}
void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status)
@ -129,17 +129,17 @@ void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status)
return;
}
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_SEMAPHORE_EVENT), error_msg(status), semaphore_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_SEMAPHORE_EVENT), error_msg(status), semaphore_id);
}
void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_MEMORY_POOL_EVENT), error_msg(status), mp_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_MEMORY_POOL_EVENT), error_msg(status), mp_id);
}
void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status)
{
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT), error_msg(status), mq_id);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT), error_msg(status), mq_id);
}
#endif

View File

@ -43,7 +43,11 @@ extern "C" void thread_terminate_hook(osThreadId_t id)
namespace rtos {
void Thread::constructor(osPriority priority,
#ifndef MBED_TZ_DEFAULT_ACCESS
#define MBED_TZ_DEFAULT_ACCESS 0
#endif
void Thread::constructor(uint32_t tz_module, osPriority priority,
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
const uintptr_t unaligned_mem = reinterpret_cast<uintptr_t>(stack_mem);
@ -60,21 +64,27 @@ void Thread::constructor(osPriority priority,
_attr.stack_size = aligned_size;
_attr.name = name ? name : "application_unnamed_thread";
_attr.stack_mem = reinterpret_cast<uint32_t*>(aligned_mem);
_attr.tz_module = tz_module;
}
void Thread::constructor(osPriority priority,
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
constructor(MBED_TZ_DEFAULT_ACCESS, priority, stack_size, stack_mem, name);
}
void Thread::constructor(Callback<void()> task,
osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name) {
constructor(priority, stack_size, stack_mem, name);
constructor(MBED_TZ_DEFAULT_ACCESS, priority, stack_size, stack_mem, name);
switch (start(task)) {
case osErrorResource:
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OUT_OF_RESOURCES), "OS ran out of threads!\n", task);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_RESOURCES), "OS ran out of threads!\n", task);
break;
case osErrorParameter:
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_ALREADY_IN_USE), "Thread already running!\n", task);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_ALREADY_IN_USE), "Thread already running!\n", task);
break;
case osErrorNoMemory:
SET_ERROR_FATAL(MAKE_ERROR(ENTITY_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory\n", task);
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory\n", task);
default:
break;
}