Test application/cases optimization for some low memory targets, macro changes and test fixes

pull/6983/head
Senthil Ramakrishnan 2018-05-21 08:57:50 -05:00
parent f9c25612ae
commit 147d9cac4e
20 changed files with 291 additions and 419 deletions

View File

@ -22,107 +22,6 @@
using utest::v1::Case;
/** Test logging of system errors
* and ensure the status/erro code is correct
*/
void test_system_errors()
{
mbed_error_status_t error = MAKE_ERROR(MODULE_APPLICATION, ERROR_CODE_UNKNOWN);
SET_WARNING(error, "Error Unknown", 0xAABBCCDD );
mbed_error_status_t lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
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(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(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);
}
/** Test logging of custom errors
* and ensure the status/erro code is correct
*/
void test_custom_errors()
{
mbed_error_status_t error = MAKE_CUSTOM_ERROR(MODULE_APPLICATION, ERROR_CODE_UNKNOWN);
SET_WARNING(error, "Custom Error Unknown", 0x1234 );
mbed_error_status_t lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(error, lastError);
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(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);
}
/** Test logging of posix errors
* and ensure the status/erro code is correct
*/
void test_posix_errors()
{
SET_WARNING(ERROR_EPERM, "Posix Error Eperm", 0x1234 );
mbed_error_status_t lastError = get_last_error();
printf("\nlastError = 0x%08X", lastError );
TEST_ASSERT_EQUAL_UINT(ERROR_EPERM, lastError);
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_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);
}
/** Test first and last error capture
*/
void test_first_and_last_error_capture()
{
//clear the errors and error count to 0
clear_all_errors();
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 );
mbed_error_status_t error = get_last_error();
printf("\nlastError = 0x%08X", error );
TEST_ASSERT_EQUAL_UINT(ERROR_SEMAPHORE_UNLOCK_FAILED, error);
error = get_first_error();
printf("\nfirstError = 0x%08X", error );
TEST_ASSERT_EQUAL_UINT(ERROR_OUT_OF_RESOURCES, error);
}
/** Test error count and reset functionality
*/
void test_error_count_and_reset()
@ -131,7 +30,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_WARNING(ERROR_OUT_OF_MEMORY, "Out of memory", i);
MBED_WARNING(MBED_ERROR_OUT_OF_MEMORY, "Out of memory", i);
}
TEST_ASSERT_EQUAL_INT(count, get_error_count());
@ -144,80 +43,74 @@ void test_error_count_and_reset()
}
/** Test error type encoding
/** Test error type encoding and test capturing of system, custom, posix errors
* and ensure the status/error code/type/error value is correct
*/
void test_error_encoding()
{
SET_WARNING(ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 );
mbed_error_status_t 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(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_OUT_OF_RESOURCES, GET_MBED_ERROR_CODE(lastError));
mbed_error_status_t 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(MODULE_PLATFORM, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_CREATE_FAILED, GET_MBED_ERROR_CODE(lastError));
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(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_EACCES, GET_MBED_ERROR_CODE(lastError));
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(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_ERANGE, GET_MBED_ERROR_CODE(lastError));
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(MODULE_HAL, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_UNKNOWN, GET_MBED_ERROR_CODE(lastError));
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(MODULE_UNKNOWN, GET_MBED_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(ERROR_CODE_UNKNOWN, GET_MBED_ERROR_CODE(lastError));
}
/** Test error value
*/
void test_error_value()
void test_error_capturing()
{
uint32_t error_value = 0xAA11BB22;
mbed_error_ctx error_ctx = {0};
SET_WARNING(ERROR_OUT_OF_RESOURCES, "System type error", error_value );
//first clear all errors and start afresh
MBED_WARNING(MBED_ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 );
mbed_error_status_t lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_SYSTEM, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_UNKNOWN, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_OUT_OF_RESOURCES, MBED_GET_ERROR_CODE(lastError));
mbed_error_status_t error = MAKE_ERROR(MODULE_DRIVER_SERIAL, MBED_ERROR_CODE_OUT_OF_RESOURCES);
MBED_WARNING(error, "Error Serial", 0xAA );
lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MAKE_CUSTOM_ERROR(MODULE_APPLICATION, MBED_ERROR_CODE_UNKNOWN);
MBED_WARNING(error, "Custom Error Unknown", 0x1234 );
lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(error, lastError);
MBED_WARNING(MBED_ERROR_EPERM, "Posix Error Eperm", 0x1234 );
lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_EPERM, lastError);
error = MAKE_CUSTOM_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_CREATE_FAILED);
MBED_WARNING(error, "Custom Error Type", error_value);
lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_CUSTOM, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_PLATFORM, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_CREATE_FAILED, MBED_GET_ERROR_CODE(lastError));
mbed_error_status_t status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
mbed_error_status_t error = MAKE_CUSTOM_ERROR(MODULE_PLATFORM, ERROR_CODE_CREATE_FAILED);
error_value = 0xABCD;
SET_WARNING(error, "Custom Error Type", error_value);
error_value = 0xAABBCC;
MBED_WARNING(MBED_ERROR_EACCES, "Posix Error", error_value );
lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_POSIX, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_UNKNOWN, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_EACCES, MBED_GET_ERROR_CODE(lastError));
status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
error_value = 0x11223344;
SET_WARNING(ERROR_EACCES, "Posix Error 1", error_value );
error_value = 0;
error = MAKE_ERROR(MODULE_HAL, MBED_ERROR_CODE_UNKNOWN);
MBED_WARNING(error, "HAL Entity error", error_value );
lastError = get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_SYSTEM, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MODULE_HAL, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_UNKNOWN, MBED_GET_ERROR_CODE(lastError));
status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
MBED_WARNING(MBED_ERROR_MUTEX_LOCK_FAILED, "Mutex lock failed", 0x4455 );
error = get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_MUTEX_LOCK_FAILED, error);
error = get_first_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_OUT_OF_RESOURCES, error);
}
/** Test error context capture
@ -227,9 +120,9 @@ void test_error_context_capture()
uint32_t error_value = 0xABCD;
mbed_error_ctx error_ctx = {0};
SET_WARNING(ERROR_INVALID_ARGUMENT, "System type error", error_value );
MBED_WARNING(MBED_ERROR_INVALID_ARGUMENT, "System type error", error_value );
mbed_error_status_t status = get_last_error_log_info( &error_ctx );
TEST_ASSERT(status == ERROR_SUCCESS);
TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
TEST_ASSERT_EQUAL_UINT(osThreadGetId(), error_ctx.thread_id);
@ -254,65 +147,53 @@ void test_error_logging()
clear_all_errors();
//log 3 errors and retrieve them to ensure they are correct
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 );
MBED_WARNING(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 1 );
MBED_WARNING(MBED_ERROR_INVALID_SIZE, "Invalid size", 2 );
MBED_WARNING(MBED_ERROR_INVALID_FORMAT, "Invalid format", 3 );
mbed_error_status_t status = get_error_log_info( 0, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_ARGUMENT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_ARGUMENT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(1, error_ctx.error_value);
status = get_error_log_info( 1, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_SIZE, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_SIZE, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(2, error_ctx.error_value);
status = get_error_log_info( 2, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_FORMAT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_FORMAT, error_ctx.error_status);
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_WARNING(ERROR_INVALID_DATA_DETECTED, "Invalid data", 4 );
SET_WARNING(ERROR_INVALID_OPERATION, "Invalid operation", 5 );
status = get_error_log_info( 2, &error_ctx );
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( 3, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_OPERATION, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(5, error_ctx.error_value);
//Log a bunch of errors to overflow the error log and retrieve them
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 );
MBED_WARNING(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 6 );
MBED_WARNING(MBED_ERROR_INVALID_SIZE, "Invalid size", 7 );
MBED_WARNING(MBED_ERROR_INVALID_FORMAT, "Invalid format", 8 );
MBED_WARNING(MBED_ERROR_NOT_READY, "Not ready error", 9 );
//Last 4 entries
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 );
MBED_WARNING(MBED_ERROR_TIME_OUT, "Timeout error", 10 );
MBED_WARNING(MBED_ERROR_ALREADY_IN_USE, "Already in use error", 11 );
MBED_WARNING(MBED_ERROR_UNSUPPORTED, "Not supported", 12 );
MBED_WARNING(MBED_ERROR_ACCESS_DENIED, "Access denied", 13 );
status = get_error_log_info( 0, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_TIME_OUT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TIME_OUT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(10, error_ctx.error_value);
status = get_error_log_info( 1, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_ALREADY_IN_USE, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_ALREADY_IN_USE, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(11, error_ctx.error_value);
status = get_error_log_info( 2, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_UNSUPPORTED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_UNSUPPORTED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(12, error_ctx.error_value);
status = get_error_log_info( 3, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_ACCESS_DENIED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_ACCESS_DENIED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(13, error_ctx.error_value);
//Try an index which is invalid, we should get ERROR_INVALID_ARGUMENT back
status = get_error_log_info( 99, &error_ctx );
TEST_ASSERT_EQUAL_UINT(ERROR_INVALID_ARGUMENT, status);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_ARGUMENT, status);
}
@ -322,7 +203,7 @@ void test_error_logging()
void err_thread_func(mbed_error_status_t *error_status)
{
//printf("\nError Status = 0x%08X\n",*error_status);
SET_WARNING(*error_status, "Error from Multi-Threaded error logging test", *error_status );
MBED_WARNING(*error_status, "Error from Multi-Threaded error logging test", *error_status );
}
@ -332,26 +213,26 @@ void test_error_logging_multithread()
{
mbed_error_ctx error_ctx = {0};
int i=0;
Thread errThread[NUM_TEST_THREADS];
Thread *errThread[NUM_TEST_THREADS];
mbed_error_status_t error_status[NUM_TEST_THREADS] = {
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
MBED_ERROR_INVALID_ARGUMENT, MBED_ERROR_INVALID_DATA_DETECTED, MBED_ERROR_INVALID_FORMAT, MBED_ERROR_INVALID_SIZE, MBED_ERROR_INVALID_OPERATION
};
for(; i<NUM_TEST_THREADS; i++) {
errThread[i].start(callback(err_thread_func, &error_status[i]));
errThread[i] = new Thread(osPriorityNormal1, 512, NULL, NULL);
errThread[i]->start(callback(err_thread_func, &error_status[i]));
}
wait(2.0);
for(i=0; i<NUM_TEST_THREADS; i++) {
errThread[i].join();
errThread[i]->join();
}
i = get_error_log_count()-1;
//printf("\nError log count = %d\n", i+1);
for(;i>=0;--i) {
mbed_error_status_t status = get_error_log_info( i, &error_ctx );
if(status != ERROR_SUCCESS) {
if(status != MBED_SUCCESS) {
TEST_FAIL();
}
@ -371,11 +252,11 @@ void MyErrorHook(const mbed_error_ctx *error_ctx)
*/
void test_error_hook()
{
if( ERROR_SUCCESS != set_error_hook(MyErrorHook)) {
if( MBED_SUCCESS != set_error_hook(MyErrorHook)) {
TEST_FAIL();
}
SET_WARNING(ERROR_INVALID_ARGUMENT, "Test for error hook", 1234);
MBED_WARNING(MBED_ERROR_INVALID_ARGUMENT, "Test for error hook", 1234);
int32_t sem_status = callback_sem.wait(5000);
TEST_ASSERT(sem_status > 0);
@ -416,16 +297,11 @@ MBED_TEST_SIM_BLOCKDEVICE_DECL;
void test_save_error_log()
{
//Log some errors
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 );
MBED_WARNING(MBED_ERROR_TIME_OUT, "Timeout error", 1 );
MBED_WARNING(MBED_ERROR_ALREADY_IN_USE, "Already in use error", 2 );
MBED_WARNING(MBED_ERROR_UNSUPPORTED, "Not supported error", 3 );
MBED_WARNING(MBED_ERROR_ACCESS_DENIED, "Access denied error", 4 );
MBED_WARNING(MBED_ERROR_ITEM_NOT_FOUND, "Not found error", 5 );
int error = 0;
@ -441,7 +317,7 @@ void test_save_error_log()
TEST_FAIL();
}
if(ERROR_SUCCESS != save_error_log("/fs/errors.log")) {
if(MBED_SUCCESS != save_error_log("/fs/errors.log")) {
printf("Failed saving error log");
TEST_FAIL();
}
@ -477,12 +353,7 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
Case cases[] = {
Case("Test error counting and reset", test_error_count_and_reset),
Case("Test system errors", test_system_errors),
Case("Test custom errors", test_custom_errors),
Case("Test posix errors", test_posix_errors),
Case("Test first and last error capture", test_first_and_last_error_capture),
Case("Test error encoding", test_error_encoding),
Case("Test error value", test_error_value),
Case("Test error encoding, value capture, first and last errors", test_error_capturing),
Case("Test error context capture", test_error_context_capture),
Case("Test error hook", test_error_hook),
#ifndef MBED_CONF_ERROR_LOG_DISABLED

View File

@ -53,9 +53,9 @@ void error(const char* format, ...) {
}
//Override the set_error function to trap the errors
mbed_error_status_t set_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
#endif

View File

@ -86,9 +86,9 @@ void error(const char* format, ...)
(void) format;
}
mbed_error_status_t set_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
#endif

View File

@ -56,9 +56,9 @@ void error(const char* format, ...) {
(void) format;
}
mbed_error_status_t set_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
#endif

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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_INVALID_SIZE), "sys_mbox_new size error\n", queue_sz);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_CREATE_FAILED), "sys_mbox_new create error\n", mbox->id);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_FREE_FAILED), "sys_mbox_free error\n", mbox->post_idx);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_CREATE_FAILED), "sys_sem_new create error\n", sem->id);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_mutex_lock error\n", mutex->id);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_UNLOCK_FAILED), "sys_mutex_unlock error\n", mutex->id);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_INITIALIZATION_FAILED), "sys_init error\n", lwip_sys_mutex);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_arch_protect error\n", lwip_sys_mutex);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_MUTEX_LOCK_FAILED), "sys_arch_unprotect error\n", lwip_sys_mutex);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new number error\n", thread_pool_index);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory", t);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_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(MAKE_ERROR(MODULE_NETWORK_STACK, ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new create error\n", t->id);
MBED_ERROR(MAKE_ERROR(MODULE_NETWORK_STACK, MBED_ERROR_CODE_THREAD_CREATE_FAILED), "sys_thread_new create error\n", t->id);
return t;
}

View File

@ -57,14 +57,14 @@ 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(MAKE_ERROR(MODULE_BLOCK_DEVICE, ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::program() not allowed", addr);
return ERROR_WRITE_PROTECTED;
MBED_ERROR(MAKE_ERROR(MODULE_BLOCK_DEVICE, MBED_ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::program() not allowed", addr);
return MBED_ERROR_WRITE_PROTECTED;
}
int ReadOnlyBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
SET_ERROR(MAKE_ERROR(MODULE_BLOCK_DEVICE, ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::erase() not allowed", addr);
return ERROR_WRITE_PROTECTED;
MBED_ERROR(MAKE_ERROR(MODULE_BLOCK_DEVICE, MBED_ERROR_CODE_WRITE_PROTECTED), "ReadOnlyBlockDevice::erase() not allowed", addr);
return MBED_ERROR_WRITE_PROTECTED;
}
bd_size_t ReadOnlyBlockDevice::get_read_size() const

View File

@ -29,7 +29,7 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
}
map++;
}
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "could not pinout", pin);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap not found for peripheral", peripheral);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PINMAP_INVALID), "pinmap not found for function", function);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_HAL, ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
MBED_ERROR(MAKE_ERROR(MODULE_HAL, MBED_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(MAKE_ERROR(MODULE_HAL, ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", deep_sleep_lock);
MBED_ERROR(MAKE_ERROR(MODULE_HAL, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", count);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", count);
}
}
@ -83,7 +83,7 @@ public:
}
if (count == USHRT_MAX) {
core_util_critical_section_exit();
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", count);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OPEN_FAILED), "Stream obj failure", _file);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OPEN_FAILED), "Stream obj failure", _file);
}
}

View File

@ -72,18 +72,22 @@ mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *e
//Error status should always be < 0
if(error_status >= 0) {
//This is a weird situation, someone called set_error with invalid error code.
//This is a weird situation, someone called mbed_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;
error_status = MBED_ERROR_INVALID_ARGUMENT;
}
//Use critsect here, as we don't want processing more than one error at the same time
//Prevent corruption by holding out other callers
//and we also need this until we remove the error call completely
while (error_in_progress == 1);
//Use critsect here, as we don't want inadvertant modification of this global variable
core_util_critical_section_enter();
error_in_progress = 1;
core_util_critical_section_exit();
//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);
@ -106,8 +110,6 @@ mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *e
}
#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);
@ -119,9 +121,6 @@ mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *e
//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();
#ifndef MBED_CONF_ERROR_LOG_DISABLED
//Log the error with error log
mbed_log_put_error(&current_error_ctx);
@ -132,7 +131,9 @@ mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *e
error_hook(&last_error_ctx);
}
return ERROR_SUCCESS;
error_in_progress = 0;
return MBED_SUCCESS;
}
//Return the first error
@ -157,20 +158,20 @@ int get_error_count(void)
}
//Sets a fatal error
mbed_error_status_t set_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
mbed_error_status_t mbed_warning(mbed_error_status_t 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
WEAK mbed_error_status_t set_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
WEAK mbed_error_status_t mbed_error(mbed_error_status_t 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 != handle_error(error_status, error_msg, error_value, filename, line_number) )
return ERROR_FAILED_OPERATION;
if( MBED_SUCCESS != handle_error(error_status, error_msg, error_value, filename, line_number) )
return MBED_ERROR_FAILED_OPERATION;
mbed_halt_system();
return ERROR_FAILED_OPERATION;
return MBED_ERROR_FAILED_OPERATION;
}
//Register an application defined callback with error handling
@ -179,24 +180,24 @@ mbed_error_status_t set_error_hook(mbed_error_hook_t error_hook_in)
//register the new hook/callback
if( error_hook_in != NULL ) {
error_hook = error_hook_in;
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
return ERROR_INVALID_ARGUMENT;
return MBED_ERROR_INVALID_ARGUMENT;
}
//Retrieve the first error context from error log
mbed_error_status_t get_first_error_log_info (mbed_error_ctx *error_info)
{
memcpy(error_info, &first_error_ctx, sizeof(first_error_ctx));
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
//Retrieve the last error context from error log
mbed_error_status_t get_last_error_log_info (mbed_error_ctx *error_info)
{
memcpy(error_info, &last_error_ctx, sizeof(mbed_error_ctx));
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
//Makes an mbed_error_status_t value
@ -204,19 +205,19 @@ mbed_error_status_t make_mbed_error(mbed_error_type_t error_type, mbed_module_ty
{
switch(error_type)
{
case ERROR_TYPE_POSIX:
case MBED_ERROR_TYPE_POSIX:
if(error_code >= MBED_POSIX_ERROR_BASE && error_code <= MBED_SYSTEM_ERROR_BASE)
return -error_code;
break;
case ERROR_TYPE_SYSTEM:
case MBED_ERROR_TYPE_SYSTEM:
if(error_code >= MBED_SYSTEM_ERROR_BASE && error_code <= MBED_CUSTOM_ERROR_BASE)
return MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, entity, error_code);
return MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, entity, error_code);
break;
case ERROR_TYPE_CUSTOM:
case MBED_ERROR_TYPE_CUSTOM:
if(error_code >= MBED_CUSTOM_ERROR_BASE)
return MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, entity, error_code);
return MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, entity, error_code);
break;
default:
@ -224,17 +225,17 @@ mbed_error_status_t make_mbed_error(mbed_error_type_t error_type, mbed_module_ty
}
//If we are passed incorrect values return a generic system error
return MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MODULE_UNKNOWN, ERROR_CODE_UNKNOWN);
return MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, MODULE_UNKNOWN, MBED_ERROR_CODE_UNKNOWN);
}
/**
* Clears all the last error, error count and all entries in the error log.
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
*
*/
mbed_error_status_t clear_all_errors(void)
{
mbed_error_status_t status = ERROR_SUCCESS;
mbed_error_status_t status = MBED_SUCCESS;
//Make sure we dont multiple clients resetting
core_util_critical_section_enter();
@ -265,20 +266,20 @@ int get_error_log_count(void)
mbed_error_status_t save_error_log(const char *path)
{
mbed_error_status_t ret = ERROR_SUCCESS;
mbed_error_status_t ret = MBED_SUCCESS;
mbed_error_ctx ctx = {0};
int log_count = mbed_log_get_error_log_count();
FILE *error_log_file = NULL;
//Ensure path is valid
if(path==NULL) {
ret = MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_INVALID_ARGUMENT);
ret = MAKE_ERROR(MODULE_PLATFORM, MBED_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(MODULE_PLATFORM, ERROR_CODE_OPEN_FAILED);
ret = MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OPEN_FAILED);
goto exit;
}
@ -288,7 +289,7 @@ mbed_error_status_t 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(MODULE_PLATFORM, ERROR_CODE_WRITE_FAILED);
ret = MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
goto exit;
}
@ -297,7 +298,7 @@ mbed_error_status_t save_error_log(const char *path)
(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);
ret = MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
goto exit;
}
@ -311,7 +312,7 @@ mbed_error_status_t 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(MODULE_PLATFORM, ERROR_CODE_WRITE_FAILED);
ret = MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_WRITE_FAILED);
goto exit;
}
}

View File

@ -63,9 +63,9 @@ extern "C" {
(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_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))
#define MBED_GET_ERROR_TYPE( error_status ) ((error_status & MBED_ERROR_STATUS_TYPE_MASK) >> MBED_ERROR_STATUS_TYPE_POS)
#define MBED_GET_ERROR_MODULE( error_status ) ((error_status & MBED_ERROR_STATUS_MODULE_MASK) >> MBED_ERROR_STATUS_MODULE_POS)
#define MBED_GET_ERROR_CODE( error_status ) (int)((MBED_GET_ERROR_TYPE( error_status ) == MBED_ERROR_TYPE_POSIX)?(-error_status):((error_status & MBED_ERROR_STATUS_CODE_MASK) >> MBED_ERROR_STATUS_CODE_POS))
/** mbed_error_status_t description
*
@ -102,8 +102,8 @@ typedef int mbed_error_status_t;
*
*/
#define MBED_DEFINE_POSIX_ERROR( error_name, error_code ) \
ERROR_CODE_##error_name = error_code, \
ERROR_##error_name = -(MBED_POSIX_ERROR_BASE + error_code)
MBED_ERROR_CODE_##error_name = error_code, \
MBED_ERROR_##error_name = -(MBED_POSIX_ERROR_BASE + error_code)
/**
* Macro for defining a System error status. This macro is used to define System error values in mbed_error_code_t enumeration.
@ -112,8 +112,8 @@ typedef int mbed_error_status_t;
*
*/
#define MBED_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, MODULE_UNKNOWN, ERROR_CODE_##error_name)
MBED_ERROR_CODE_##error_name = MBED_SYSTEM_ERROR_BASE + error_code, \
MBED_ERROR_##error_name = MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, MODULE_UNKNOWN, MBED_ERROR_CODE_##error_name)
/**
* Macro for defining a Custom error status. This macro is used to define custom error values in mbed_error_code_t enumeration.
@ -122,52 +122,52 @@ typedef int mbed_error_status_t;
*
*/
#define MBED_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, MODULE_UNKNOWN, ERROR_CODE_##error_name)
MBED_ERROR_CODE_##error_name = MBED_CUSTOM_ERROR_BASE + error_code, \
MBED_ERROR_##error_name = MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, MODULE_UNKNOWN, MBED_ERROR_CODE_##error_name)
/**
* Macro for setting a system error. This macro will log the error, prints the error report and return to the caller. Its a wrapper for calling set_error API.
* Macro for setting a system error. This macro will log the error, prints the error report and return to the caller. Its a wrapper for calling mbed_error API.
* @param error_status mbed_error_status_t status to be set(See mbed_error_status_t 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.
*
* @code
*
* SET_ERROR( ERROR_INVALID_SIZE, "MyDriver: Invalid size in read", size_val )
* MBED_ERROR( ERROR_INVALID_SIZE, "MyDriver: Invalid size in read", size_val )
*
* @endcode
* @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.
* @note The macro calls mbed_error API with filename and line number info without caller explicitly passing them.
* Since this macro is a wrapper for mbed_error API callers should process the return value from this macro which is the return value from calling mbed_error API.
*
*/
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
#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__ )
#define MBED_WARNING( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#else
#define SET_WARNING( error_status, error_msg, error_value ) set_warning( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define MBED_WARNING( error_status, error_msg, error_value ) mbed_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 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 mbed_error API
* @param error_status mbed_error_status_t status to be set(See mbed_error_status_t 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.
* @return 0 or ERROR_SUCCESS.
* ERROR_INVALID_ARGUMENT if called with invalid error status/codes
* @return 0 or MBED_SUCCESS.
* MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
*
* @code
*
* SET_ERROR( ERROR_MUTEX_LOCK_FAILED, "MyDriver: Can't lock driver Mutex", &my_mutex )
* MBED_ERROR( MBED_ERROR_MUTEX_LOCK_FAILED, "MyDriver: Can't lock driver Mutex", &my_mutex )
*
* @endcode
* @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.
* @note The macro calls mbed_error API with filename and line number info without caller explicitly passing them.
* Since this macro is a wrapper for mbed_error API callers should process the return value from this macro which is the return value from calling mbed_error API.
*
*/
#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 MBED_ERROR( error_status, error_msg, error_value ) mbed_error( 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 MBED_ERROR( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#endif
//Error Type definition
@ -175,19 +175,19 @@ typedef int mbed_error_status_t;
* @note
* This enumeration defines the Error types supported. The value of these enum values will be encoded into mbed_error_status_t TYPE field.\n
* See mbed_error_status_t description for more info.\n
* ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.\n
* ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.\n
* ERROR_TYPE_POSIX - Used to indicate that the error status is of Posix error type.\n
* MBED_ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.\n
* MBED_ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.\n
* MBED_ERROR_TYPE_POSIX - Used to indicate that the error status is of Posix error type.\n
*
*/
typedef enum _mbed_error_type_t
{
ERROR_TYPE_SYSTEM = 0,
ERROR_TYPE_CUSTOM = 1,
MBED_ERROR_TYPE_SYSTEM = 0,
MBED_ERROR_TYPE_CUSTOM = 1,
//2 is reserved
//Use 3 for POSIX because we are mapping -1 to -255 to POSIX error codes
//and thus we must use 3 to match the type bits in error status representation which are from 0xFFFFFFFF to 0xFFFFFF00
ERROR_TYPE_POSIX = 3
MBED_ERROR_TYPE_POSIX = 3
} mbed_error_type_t;
//Module type/id definitions
@ -195,13 +195,13 @@ typedef enum _mbed_error_type_t
* @note
* This enumeration defines the module types. The value of these enum values will be encoded into mbed_error_status_t MODULE field.\n\n
* See mbed_error_status_t description for 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
* MODULE_UNKNOWN - This module type can be used if caller of the mbed_error/mbed_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: mbed_error_status_t i2c_driver_error = MAKE_ERROR( MODULE_DRIVER_I2C, ERROR_CONFIG_UNSUPPORTED );
* Example: mbed_error_status_t i2c_driver_error = MAKE_ERROR( MODULE_DRIVER_I2C, MBED_ERROR_CONFIG_UNSUPPORTED );
* @endcode
*
* @note
@ -266,8 +266,8 @@ typedef enum _mbed_module_type
MODULE_MAX = MODULE_UNKNOWN
} mbed_module_type_t;
//Use ERROR_SUCCESS(=0) or any postive number for successful returns
#define ERROR_SUCCESS 0
//Use MBED_SUCCESS(=0) or any postive number for successful returns
#define MBED_SUCCESS 0
#define MBED_POSIX_ERROR_BASE 0
#define MBED_SYSTEM_ERROR_BASE 256
@ -806,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_WARNING/SET_ERROR macros
* or one of set_error/set_warning functions.
* This function has been deprecated, please use one of MBED_WARNING/MBED_ERROR macros
* or one of mbed_error/mbed_warning functions.
*
* @code
* #error "That shouldn't have happened!"
@ -846,7 +846,7 @@ typedef struct _mbed_error_ctx {
*
*/
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" )
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function has been deprecated, please use one of MBED_WARNING/MBED_ERROR macros or one of mbed_warning/mbed_error functions" )
void error(const char* format, ...);
@ -857,13 +857,13 @@ void error(const char* format, ...);
*
* @code
*
* mbed_error_status_t driver_error = MAKE_SYSTEM_ERROR( MODULE_DRIVER_USB, ERROR_CODE_INITIALIZATION_FAILED )
* mbed_error_status_t driver_error = MAKE_SYSTEM_ERROR( MODULE_DRIVER_USB, MBED_ERROR_CODE_INITIALIZATION_FAILED )
*
* @endcode
* @note This macro generate mbed_error_status_t-es with error type set to ERROR_TYPE_SYSTEM
* @note This macro generate mbed_error_status_t-es with error type set to MBED_ERROR_TYPE_SYSTEM
*
*/
#define MAKE_SYSTEM_ERROR(module, error_code) MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, module, error_code)
#define MAKE_SYSTEM_ERROR(module, error_code) MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, module, error_code)
/**
* Call this Macro to generate a mbed_error_status_t value for a Custom error
@ -875,10 +875,10 @@ void error(const char* format, ...);
* mbed_error_status_t custom_error = MAKE_CUSTOM_ERROR( MODULE_APPLICATION, 0xDEAD//16-bit custom error code )
*
* @endcode
* @note This macro generate mbed_error_status_t-es with error type set to ERROR_TYPE_CUSTOM
* @note This macro generate mbed_error_status_t-es with error type set to MBED_ERROR_TYPE_CUSTOM
*
*/
#define MAKE_CUSTOM_ERROR(module, error_code) MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, module, error_code)
#define MAKE_CUSTOM_ERROR(module, error_code) MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, module, error_code)
/**
* Call this Macro to generate a mbed_error_status_t value for a System error
@ -887,10 +887,10 @@ void error(const char* format, ...);
*
* @code
*
* mbed_error_status_t new_error = MAKE_ERROR( MODULE_DRIVER_USB, ERROR_INITIALIZATION_FAILED )
* mbed_error_status_t new_error = MAKE_ERROR( MODULE_DRIVER_USB, MBED_ERROR_INITIALIZATION_FAILED )
*
* @endcode
* @note This macro generate mbed_error_status_t-es with error type set to ERROR_TYPE_SYSTEM
* @note This macro generate mbed_error_status_t-es with error type set to MBED_ERROR_TYPE_SYSTEM
*
*/
#define MAKE_ERROR(module, error_code) MAKE_SYSTEM_ERROR(module, error_code)
@ -914,29 +914,29 @@ typedef void (*mbed_error_hook_t)(const mbed_error_ctx *error_ctx);
* @param error_value Value associated with the error status. This would depend on error code/error scenario.
* @param filename Name of the source file originating the error( Most callers can pass __FILE__ here ).
* @param line_number The line number of the source file originating the error( Most callers can pass __LINE__ here ) .
* @return 0 or ERROR_SUCCESS.
* ERROR_INVALID_ARGUMENT if called with invalid error status/codes
* @return 0 or MBED_SUCCESS.
* MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
*
* @code
*
* set_error( ERROR_OUT_OF_MEMORY, "Out of memory error", 0, __FILE__, __LINE__ )
* mbed_error( ERROR_OUT_OF_MEMORY, "Out of memory error", 0, __FILE__, __LINE__ )
*
* @endcode
*
* @note See SET_WARNING/SET_ERROR macros which provides a wrapper on this API
* @note See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API
*/
mbed_error_status_t set_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
/**
* Returns the first system error reported.
* @return mbed_error_status_t code logged for the first error or ERROR_SUCCESS if no errors are logged.
* @return mbed_error_status_t code logged for the first error or MBED_SUCCESS if no errors are logged.
*
*/
mbed_error_status_t get_first_error(void);
/**
* Returns the most recent system error reported.
* @return mbed_error_status_t code logged for the last error or ERROR_SUCCESS if no errors are logged.
* @return mbed_error_status_t code logged for the last error or MBED_SUCCESS if no errors are logged.
*
*/
mbed_error_status_t get_last_error(void);
@ -956,26 +956,26 @@ int get_error_count(void);
* @param error_value Value associated with the error status. This would depend on error code/error scenario.
* @param filename Name of the source file originating the error( Most callers can pass __FILE__ here ).
* @param line_number The line number of the source file originating the error( Most callers can pass __LINE__ here ) .
* @return 0 or ERROR_SUCCESS.
* ERROR_INVALID_ARGUMENT if called with invalid error status/codes
* @return 0 or MBED_SUCCESS.
* MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
*
* @code
*
* set_error( ERROR_PROHIBITED_OPERATION, "Prohibited operation tried", 0, __FILE__, __LINE__ )
* mbed_error( MBED_ERROR_PROHIBITED_OPERATION, "Prohibited operation tried", 0, __FILE__, __LINE__ )
*
* @endcode
*
* @note See SET_WARNING/SET_ERROR macros which provides a wrapper on this API
* @note See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API
*/
mbed_error_status_t set_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
mbed_error_status_t mbed_error(mbed_error_status_t 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_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.
* This function will be called with error context info whenever system handles a mbed_error/mbed_warning call
* NOTE: This function should be implemented for re-entrancy as multiple threads may invoke mbed_error which may cause error hook to be called.
* @param custom_error_hook mbed_error_status_t status to be set(See mbed_error_status_t 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
* @return 0 or MBED_SUCCESS on success.
* MBED_ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
*
* @code
*
@ -993,25 +993,25 @@ mbed_error_status_t set_error_hook(mbed_error_hook_t custom_error_hook);
/**
* Reads the first error context information logged.
* @param error_info This is the mbed_error_context info captured as part of the first set_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
* @return 0 or ERROR_SUCCESS on success.
* ERROR_INVALID_ARGUMENT in case of invalid index
* @param error_info This is the mbed_error_context info captured as part of the first mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
* @return 0 or MBED_SUCCESS on success.
* MBED_ERROR_INVALID_ARGUMENT in case of invalid index
*
*/
mbed_error_status_t get_first_error_log_info(mbed_error_ctx *error_info);
/**
* Reads the last error context information logged.
* @param error_info This is the mbed_error_context info captured as part of the last set_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
* @return 0 or ERROR_SUCCESS on success.
* ERROR_INVALID_ARGUMENT in case of invalid index
* @param error_info This is the mbed_error_context info captured as part of the last mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
* @return 0 or MBED_ERROR_SUCCESS on success.
* MBED_ERROR_INVALID_ARGUMENT in case of invalid index
*
*/
mbed_error_status_t get_last_error_log_info(mbed_error_ctx *error_info);
/**
* Clears all the last error, error count and all entries in the error log.
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
*
*/
mbed_error_status_t clear_all_errors(void);
@ -1021,7 +1021,7 @@ mbed_error_status_t clear_all_errors(void);
* @param error_type Error type based on mbed_error_type_t enum.
* @param module Module type based on mbed_module_type_t enum.
* @param error_code Error codes defined by mbed_error_code_t enum
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_ERROR_SUCCESS on success.
*
*/
mbed_error_status_t make_mbed_error(mbed_error_type_t error_type, mbed_module_type_t module, mbed_error_code_t error_code);
@ -1040,8 +1040,8 @@ int get_error_log_count(void);
* The number of entries in the error log depth is configured during build and the max index depends on max depth of error log.\n
* index = 0 points to the oldest entry in the log, and index = (max log depth - 1) points to the latest entry in the error log.\n
* @param error_info This is the mbed_error_context info captured as part of the log. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
* @return 0 or ERROR_SUCCESS on success.
* ERROR_INVALID_ARGUMENT in case of invalid index
* @return 0 or MBED_SUCCESS on success.
* MBED_ERROR_INVALID_ARGUMENT in case of invalid index
*
*/
mbed_error_status_t get_error_log_info(int index, mbed_error_ctx *error_info);
@ -1050,9 +1050,9 @@ mbed_error_status_t get_error_log_info(int index, mbed_error_ctx *error_info);
* Saves the error log information to a file
*
* @param path path to the file in the filesystem
* @return 0 or ERROR_SUCCESS on success.
* ERROR_WRITE_FAILED if writing to file failed
* ERROR_INVALID_ARGUMENT if path is not valid
* @return 0 or MBED_ERROR_SUCCESS on success.
* MBED_ERROR_WRITE_FAILED if writing to file failed
* MBED_ERROR_INVALID_ARGUMENT if path is not valid
*
* @note Filesystem support is required in order for this function to work.
*

View File

@ -31,7 +31,7 @@ mbed_error_status_t mbed_log_put_error(mbed_error_ctx *error_ctx)
{
//Return error if error_ctx is NULL
if(NULL == error_ctx) {
return ERROR_INVALID_ARGUMENT;
return MBED_ERROR_INVALID_ARGUMENT;
}
core_util_critical_section_enter();
@ -39,14 +39,14 @@ mbed_error_status_t mbed_log_put_error(mbed_error_ctx *error_ctx)
memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_LOG_SIZE], error_ctx, sizeof(mbed_error_ctx) );
core_util_critical_section_exit();
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
mbed_error_status_t mbed_log_get_error(int index, mbed_error_ctx *error_ctx)
{
//Return error if index is more than max log size
if(index >= MBED_CONF_ERROR_LOG_SIZE) {
return ERROR_INVALID_ARGUMENT;
return MBED_ERROR_INVALID_ARGUMENT;
}
core_util_critical_section_enter();
@ -57,7 +57,7 @@ mbed_error_status_t mbed_log_get_error(int index, mbed_error_ctx *error_ctx)
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;
return MBED_SUCCESS;
}
mbed_error_ctx *mbed_log_get_entry(void)
@ -73,13 +73,13 @@ mbed_error_ctx *mbed_log_get_entry(void)
mbed_error_status_t mbed_log_get_last_error(mbed_error_ctx *error_ctx)
{
if(-1 == error_log_count) {
return ERROR_ITEM_NOT_FOUND;
return MBED_ERROR_ITEM_NOT_FOUND;
}
core_util_critical_section_enter();
memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_LOG_SIZE], sizeof(mbed_error_ctx) );
core_util_critical_section_exit();
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
int mbed_log_get_error_log_count()
@ -93,7 +93,7 @@ mbed_error_status_t mbed_log_reset()
error_log_count = -1;
core_util_critical_section_exit();
return ERROR_SUCCESS;
return MBED_SUCCESS;
}
#endif

View File

@ -31,7 +31,7 @@ extern "C" {
* Puts/Adds an error entry into the error list
*
* @param error_ctx pointer to the mbed_error_ctx struct with the error context
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
* ERROR_WRITE_FAILED if writing to file failed
* ERROR_INVALID_ARGUMENT if path is not valid
*
@ -44,7 +44,7 @@ mbed_error_status_t mbed_log_put_error(mbed_error_ctx *error_ctx);
*
* @param index Index of the error context to be retrieved. It starts from 0 and 0 is the oldest.
* @param error_ctx pointer to the mbed_error_ctx struct where the error context will be filled, this should be allocated by the caller
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
* ERROR_WRITE_FAILED if writing to file failed
* ERROR_INVALID_ARGUMENT if path is not valid
*
@ -66,7 +66,7 @@ mbed_error_ctx *mbed_log_get_entry(void);
* Reads the last(latest) error entry from the error list
*
* @param error_ctx pointer to the mbed_error_ctx struct where the error context will be filled, this should be allocated by the caller
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
* ERROR_WRITE_FAILED if writing to file failed
* ERROR_INVALID_ARGUMENT if path is not valid
*
@ -86,7 +86,7 @@ int mbed_log_get_error_log_count(void);
/*
* Resets the error log by resetting the number of errors to 0 and clears all previous errors in the log
*
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
* ERROR_WRITE_FAILED if writing to file failed
* ERROR_INVALID_ARGUMENT if path is not valid
*
@ -98,7 +98,7 @@ mbed_error_status_t mbed_log_reset(void);
* Saves the error log information to a file
*
* @param path path to the file in the filesystem
* @return 0 or ERROR_SUCCESS on success.
* @return 0 or MBED_SUCCESS on success.
* ERROR_WRITE_FAILED if writing to file failed
* ERROR_INVALID_ARGUMENT if path is not valid
*

View File

@ -188,51 +188,51 @@ void mbed_report_error(mbed_error_ctx *error_ctx, char *error_msg)
{
uint32_t error_vals[3] = {0};
error_vals[0] = error_ctx->error_status;
error_vals[1] = GET_MBED_ERROR_CODE(error_ctx->error_status);
error_vals[2] = GET_MBED_ERROR_MODULE(error_ctx->error_status);
error_vals[1] = MBED_GET_ERROR_CODE(error_ctx->error_status);
error_vals[2] = MBED_GET_ERROR_MODULE(error_ctx->error_status);
mbed_error_print("\n\n++ MbedOS Error Info ++\nError Status: 0x%x Code: %d Entity: %d\nError Message: ", error_vals);
//Report error info based on error code, some errors require different
//error_vals[1] contains the error code
if(error_vals[1] == ERROR_CODE_HARDFAULT_EXCEPTION ||
error_vals[1] == ERROR_CODE_MEMMANAGE_EXCEPTION ||
error_vals[1] == ERROR_CODE_BUSFAULT_EXCEPTION ||
error_vals[1] == ERROR_CODE_USAGEFAULT_EXCEPTION ) {
if(error_vals[1] == MBED_ERROR_CODE_HARDFAULT_EXCEPTION ||
error_vals[1] == MBED_ERROR_CODE_MEMMANAGE_EXCEPTION ||
error_vals[1] == MBED_ERROR_CODE_BUSFAULT_EXCEPTION ||
error_vals[1] == MBED_ERROR_CODE_USAGEFAULT_EXCEPTION ) {
mbed_error_print(error_msg, NULL);
mbed_error_print("\nLocation: 0x%x\n", (uint32_t *)&error_ctx->error_value);
} else {
switch (error_vals[1]) {
//These are errors reported by kernel handled from mbed_rtx_handlers
case ERROR_CODE_RTOS_EVENT:
case MBED_ERROR_CODE_RTOS_EVENT:
mbed_error_print("Kernel Error: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_THREAD_EVENT:
case MBED_ERROR_CODE_RTOS_THREAD_EVENT:
mbed_error_print("Thread: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_MUTEX_EVENT:
case MBED_ERROR_CODE_RTOS_MUTEX_EVENT:
mbed_error_print("Mutex: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_SEMAPHORE_EVENT:
case MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT:
mbed_error_print("Semaphore: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_MEMORY_POOL_EVENT:
case MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT:
mbed_error_print("MemoryPool: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_EVENT_FLAGS_EVENT:
case MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT:
mbed_error_print("EventFlags: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_TIMER_EVENT:
case MBED_ERROR_CODE_RTOS_TIMER_EVENT:
mbed_error_print("Timer: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;
case ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT:
case MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT:
mbed_error_print("MessageQueue: 0x%x, ", (uint32_t *)&error_ctx->error_value);
break;

View File

@ -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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PROHIBITED_IN_ISR_CONTEXT), "Error - writing to a file in an ISR or critical section\r\n", fh);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_PROHIBITED_IN_ISR_CONTEXT), "Error - reading from a file in an ISR or critical section\r\n", fh);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_CLIB_EXCEPTION),"Exception", 0);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_CLIB_EXCEPTION),"Exception", 0);
}
}
extern "C" WEAK void __cxa_pure_virtual(void);
@ -1387,7 +1387,7 @@ void *operator new(std::size_t count)
{
void *buffer = malloc_wrapper(count, MBED_CALLER_ADDR());
if (NULL == buffer) {
error("Operator new out of memory\r\n");
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OUT_OF_MEMORY), "Operator new out of memory\r\n", count);
}
return buffer;
}
@ -1431,7 +1431,7 @@ void *operator new(std::size_t count)
{
void *buffer = malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
if (NULL == buffer) {
error("Operator new out of memory\r\n");
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OUT_OF_MEMORY), "Operator new out of memory\r\n", count);
}
return buffer;
}
@ -1440,7 +1440,7 @@ void *operator new[](std::size_t count)
{
void *buffer = malloc_wrapper(_REENT, count, MBED_CALLER_ADDR());
if (NULL == buffer) {
error("Operator new[] out of memory\r\n");
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OUT_OF_MEMORY), "Operator new out of memory\r\n", count);
}
return buffer;
}
@ -1471,7 +1471,7 @@ void *operator new(std::size_t count)
{
void *buffer = malloc(count);
if (NULL == buffer) {
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Operator new out of memory\r\n", count);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Operator new[] out of memory\r\n", count);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OUT_OF_MEMORY), "Operator new[] out of memory\r\n", count);
}
return buffer;
}

View File

@ -32,30 +32,30 @@ mbed_fault_context_t mbed_fault_context;
//This runs in fault context and uses special functions(defined in mbed_rtx_fault_handler.c) to print the information without using C-lib support.
__NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn)
{
mbed_error_status_t faultStatus = ERROR_SUCCESS;
mbed_error_status_t faultStatus = MBED_SUCCESS;
mbed_error_print("\n++ MbedOS Fault Handler ++\n\nFaultType: ",NULL);
switch( fault_type ) {
case HARD_FAULT_EXCEPTION:
mbed_error_print("HardFault",NULL);
faultStatus = ERROR_HARDFAULT_EXCEPTION;
faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION;
break;
case MEMMANAGE_FAULT_EXCEPTION:
mbed_error_print("MemManageFault",NULL);
faultStatus = ERROR_MEMMANAGE_EXCEPTION;
faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION;
break;
case BUS_FAULT_EXCEPTION:
mbed_error_print("BusFault",NULL);
faultStatus = ERROR_BUSFAULT_EXCEPTION;
faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION;
break;
case USAGE_FAULT_EXCEPTION:
mbed_error_print("UsageFault",NULL);
faultStatus = ERROR_USAGEFAULT_EXCEPTION;
faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION;
break;
default:
mbed_error_print("Unknown Fault",NULL);
faultStatus = ERROR_UNKNOWN;
faultStatus = MBED_ERROR_UNKNOWN;
break;
}
mbed_error_print("\n\nContext:",NULL);
@ -81,8 +81,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, 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_reg, NULL, 0 );
//Now call mbed_error, to log the error and halt the system
mbed_error( MAKE_ERROR( MODULE_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC_reg, 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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_INITIALIZATION_FAILED), "Pre main thread not created", &_main_thread_attr);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_STACK_OVERFLOW), "CMSIS-RTOS error: Stack overflow", code);
MBED_ERROR(MAKE_ERROR(MODULE_KERNEL, MBED_ERROR_CODE_STACK_OVERFLOW), "CMSIS-RTOS error: Stack overflow", code);
break;
case osRtxErrorISRQueueOverflow:
// ISR Queue overflow detected when inserting object (object_id)
SET_ERROR(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_ISR_QUEUE_OVERFLOW), "CMSIS-RTOS error: ISR Queue overflow", code);
MBED_ERROR(MAKE_ERROR(MODULE_KERNEL, MBED_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(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_TIMER_QUEUE_OVERFLOW), "CMSIS-RTOS error: User Timer Callback Queue overflow", code);
MBED_ERROR(MAKE_ERROR(MODULE_KERNEL, MBED_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(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_CLIB_SPACE_UNAVAILABLE), "CMSIS-RTOS error: STD C/C++ library libspace not available", code);
MBED_ERROR(MAKE_ERROR(MODULE_KERNEL, MBED_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(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_CLIB_MUTEX_INIT_FAILURE), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed", code);
MBED_ERROR(MAKE_ERROR(MODULE_KERNEL, MBED_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(MAKE_ERROR(MODULE_KERNEL, ERROR_CODE_UNKNOWN), "CMSIS-RTOS error: Unknown", code);
MBED_ERROR(MAKE_ERROR(MODULE_KERNEL, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_EVENT), error_msg(status), status);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_EVENT), error_msg(status), status);
}
void EvrRtxThreadError (osThreadId_t thread_id, int32_t status)
{
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_THREAD_EVENT), error_msg(status), thread_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_THREAD_EVENT), error_msg(status), thread_id);
}
void EvrRtxTimerError (osTimerId_t timer_id, int32_t status)
{
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_TIMER_EVENT), error_msg(status), timer_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_TIMER_EVENT), error_msg(status), timer_id);
}
void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status)
{
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_EVENT_FLAGS_EVENT), error_msg(status), ef_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT), error_msg(status), ef_id);
}
void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status)
{
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_MUTEX_EVENT), error_msg(status), mutex_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_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(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_SEMAPHORE_EVENT), error_msg(status), semaphore_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT), error_msg(status), semaphore_id);
}
void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status)
{
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_MEMORY_POOL_EVENT), error_msg(status), mp_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT), error_msg(status), mp_id);
}
void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status)
{
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT), error_msg(status), mq_id);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT), error_msg(status), mq_id);
}
#endif

View File

@ -78,13 +78,13 @@ void Thread::constructor(Callback<void()> task,
switch (start(task)) {
case osErrorResource:
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_RESOURCES), "OS ran out of threads!\n", task);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OUT_OF_RESOURCES), "OS ran out of threads!\n", task);
break;
case osErrorParameter:
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_ALREADY_IN_USE), "Thread already running!\n", task);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_ALREADY_IN_USE), "Thread already running!\n", task);
break;
case osErrorNoMemory:
SET_ERROR(MAKE_ERROR(MODULE_PLATFORM, ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory\n", task);
MBED_ERROR(MAKE_ERROR(MODULE_PLATFORM, MBED_ERROR_CODE_OUT_OF_MEMORY), "Error allocating the stack memory\n", task);
default:
break;
}