forked from roboterclubaachen/xpcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hosted] Add binary error implementation.
- Loading branch information
Showing
7 changed files
with
194 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// coding: utf-8 | ||
/* Copyright (c) 2016, Roboterclub Aachen e.V. | ||
* All Rights Reserved. | ||
* | ||
* The file is part of the xpcc library and is released under the 3-clause BSD | ||
* license. See the file `LICENSE` for the full license governing this code. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef XPCC_ERROR_HPP | ||
#define XPCC_ERROR_HPP | ||
|
||
#include <stdint.h> | ||
#include <xpcc/architecture/utils.hpp> | ||
|
||
/** | ||
* @ingroup interface | ||
* @defgroup error Errors | ||
* | ||
* Errors at runtime | ||
* | ||
* @see driver | ||
* @author Niklas Hauser | ||
*/ | ||
|
||
#if defined XPCC__CPU_ARM || defined XPCC__CPU_AVR | ||
# define XPCC_MODULE_ERROR_NAME_LINKER_SECTION ".errorname" | ||
#elif defined XPCC__OS_OSX | ||
# define XPCC_MODULE_ERROR_NAME_LINKER_SECTION "__DATA,xpcc_errorname" | ||
#elif defined XPCC__OS_LINUX | ||
# define XPCC_MODULE_ERROR_NAME_LINKER_SECTION "xpcc_errorname" | ||
#endif | ||
|
||
xpcc_extern_c_begin | ||
|
||
typedef struct | ||
{ | ||
uint8_t module; | ||
uint8_t error; | ||
} xpcc_error_t; | ||
|
||
typedef struct | ||
{ | ||
const char * module_name; | ||
const char * (*stringify)(uint8_t error); | ||
} xpcc_module_error_stringify_t; | ||
|
||
const char * xpcc_error_module(xpcc_error_t error); | ||
const char * xpcc_error_stringify(xpcc_error_t error); | ||
|
||
xpcc_extern_c_end | ||
|
||
#ifdef XPCC_ERROR_LINKER_SECTION | ||
# define XPCC_MODULE_ERROR_STRINGIFY(module_name) \ | ||
static const char * error_stringify(xpcc_error_t); \ | ||
\ | ||
__attribute__((section(XPCC_MODULE_ERROR_NAME_LINKER_SECTION), used)) \ | ||
static const xpcc_module_error_stringify_t \ | ||
module_error_stringify = {module_name, error_stringify}; \ | ||
\ | ||
xpcc_extern_c uint8_t xpcc_get_module_id_from_stringify(const xpcc_module_error_stringify_t * module); \ | ||
static inline uint8_t module_id() { return xpcc_get_module_id_from_stringify(&module_error_stringify); } \ | ||
\ | ||
const char * error_stringify | ||
#else | ||
# define XPCC_MODULE_ERROR_STRINGIFY(module_name) \ | ||
const char * error_stringify | ||
#endif | ||
|
||
#endif // XPCC_ASSERT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/xpcc/architecture/platform/driver/core/hosted/error.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// coding: utf-8 | ||
/* Copyright (c) 2016, Roboterclub Aachen e.V. | ||
* All Rights Reserved. | ||
* | ||
* The file is part of the xpcc library and is released under the 3-clause BSD | ||
* license. See the file `LICENSE` for the full license governing this code. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <stdlib.h> | ||
#include <xpcc/debug/logger.hpp> | ||
#include <xpcc/architecture/interface/error.hpp> | ||
|
||
#ifdef XPCC__OS_OSX | ||
extern xpcc_module_error_stringify_t __errorname_table_start __asm("section$start$__DATA$xpcc_errorname"); | ||
extern xpcc_module_error_stringify_t __errorname_table_end __asm("section$end$__DATA$xpcc_errorname"); | ||
#else | ||
extern xpcc_module_error_stringify_t __errorname_table_start __asm("__start_xpcc_errorname"); | ||
extern xpcc_module_error_stringify_t __errorname_table_end __asm("__stop_xpcc_errorname"); | ||
#endif | ||
|
||
extern "C" { | ||
|
||
static uint8_t number_of_error_modules = 0; | ||
|
||
uint8_t xpcc_get_module_id_from_stringify(const xpcc_module_error_stringify_t * const module) | ||
{ | ||
number_of_error_modules = &__errorname_table_end - &__errorname_table_start; | ||
|
||
if (module < &__errorname_table_start || &__errorname_table_end <= module) return -1; | ||
return (module - &__errorname_table_start); | ||
} | ||
|
||
const char * xpcc_error_module(xpcc_error_t error) | ||
{ | ||
if (error.module >= number_of_error_modules) return "Invalid"; | ||
|
||
return (&__errorname_table_start)[error.module].module_name; | ||
} | ||
const char * xpcc_error_stringify(xpcc_error_t error) | ||
{ | ||
if (error.module >= number_of_error_modules) return "Invalid"; | ||
if (error.error == 0) return "Ok"; | ||
return (&__errorname_table_start)[error.module].stringify(error.error); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters