Commit d1d99f29 authored by Peter Zumbruch's avatar Peter Zumbruch
Browse files

- removed obsolete error code arrays

	- replaced by rule errorType * 100 + errorIndex

- refactored xxx_errorCode to xxxErrorCode

- xxx_init flags:
	- moved from main.c to api.c
	- changed to uint16_t
	

- cosmetics	

git-svn-id: https://subversion.gsi.de/epics/trunk/hadcon/API-Slave@401 50339f28-a4cd-11e1-ab1f-8360dde1fe65
parent fc6af26b
......@@ -71,7 +71,7 @@ void atmelReadADCs( struct uartStruct *ptr_uartStruct)
}
break;
default:
general_errorCode = CommunicationError_p(ERRG, dynamicMessage_ErrorIndex, TRUE, PSTR("invalid number of arguments"));
generalErrorCode = CommunicationError_p(ERRG, dynamicMessage_ErrorIndex, TRUE, PSTR("invalid number of arguments"));
break;
}
return;
......@@ -111,12 +111,12 @@ uint8_t atmelCollectSingleADCChannel( int8_t channelIndex, uint8_t quiet )
case 7:
if ( FALSE == disableJTAG_flag)
{
general_errorCode = CommunicationError_p(ERRG, GENERAL_ERROR_channel_undefined, TRUE, NULL);
generalErrorCode = CommunicationError_p(ERRG, GENERAL_ERROR_channel_undefined, TRUE, NULL);
return eADCwrongAddress;
}
break;
default:
general_errorCode = CommunicationError_p(ERRG, GENERAL_ERROR_channel_undefined, TRUE, NULL);
generalErrorCode = CommunicationError_p(ERRG, GENERAL_ERROR_channel_undefined, TRUE, NULL);
return eADCwrongAddress;
break;
}
......
......@@ -417,16 +417,6 @@ const char *serial_error[] PROGMEM = {
se00, se01, se02, se03, se04, se05, se06, se07, se08, se09, se10, se11, se12, se13, se14, se15, se16, se17, se18,
se19, se20, se21, se22, se23, se24, se25, se26, se27, se28, se29, se30, se31, se32 };
/* array for defined serial error number*/
const uint8_t serial_error_number[] = {
11, 12, 13, 14, 15, 16, 17, 18, 19, 110,
111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
131};
/* pointer of array for defined general error number*/
static const char ge00[] PROGMEM = "init for timer0 failed";
static const char ge01[] PROGMEM = "init for timer0A failed";
static const char ge02[] PROGMEM = "family code not found";
......@@ -441,35 +431,6 @@ static const char ge10[] PROGMEM = "invalid argument";
const char *general_error[] PROGMEM = { ge00, ge01, ge02, ge03, ge04, ge05, ge06, ge07, ge08, ge09, ge10 };
/* array for defined general error number*/
const uint16_t general_error_number[] = { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0x4A };
//static const char tw00[] PROGMEM = "Error Initiating TWI interface";
//static const char tw01[] PROGMEM = "Could not start TWI Bus for WRITE";
//static const char tw02[] PROGMEM = "Could not start TWI Bus for READ";
//static const char tw03[] PROGMEM = "unknown command";
//static const char tw04[] PROGMEM = "address_is_too_long";
//static const char tw05[] PROGMEM = "data length is too long";
//static const char tw06[] PROGMEM = "data 0 is too long";
//static const char tw07[] PROGMEM = "data 1 is too long";
//static const char tw08[] PROGMEM = "data 2 is too long";
//static const char tw09[] PROGMEM = "data 3 is too long";
//static const char tw10[] PROGMEM = "data 4 is too long";
//static const char tw11[] PROGMEM = "data 5 is too long";
//static const char tw12[] PROGMEM = "data 6 is too long";
//static const char tw13[] PROGMEM = "data 7 is too long";
//static const char tw14[] PROGMEM = "failed writing TWI_Bus";
//static const char tw15[] PROGMEM = "failed reading TWI_Bus";
//static const char tw16[] PROGMEM = "too few (numeric) arguments";
//static const char tw17[] PROGMEM = "wrong length or number of data bytes";
//const char *twi_error[] PROGMEM = { tw00, tw01, tw02, tw03, tw04,
// tw05, tw06, tw07, tw08, tw09,
// tw10, tw11, tw12, tw13, tw14,
// tw15, tw16, tw17 };
//
///* array for defined can error number*/
//const uint8_t twi_error_number[] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60};
/* pointer of array for defined general error number*/
static const char errorType00[] PROGMEM = "ERRG"; /*general*/
static const char errorType01[] PROGMEM = "ERRA"; /*api*/
......@@ -488,6 +449,12 @@ const char *errorTypes[] PROGMEM = {
errorType05
};
int8_t uart0_init = 0; /* return variable of UART0_Init function*/
int8_t can_init = 0; /* return variable of canInit function*/
int8_t twim_init = 0; /* return variable of TWIM_Init function*/
int8_t owi_init = 0; /* return variable of OWI_Init function*/
int8_t timer0_init = 0; /* return variable of Timer0_Init function*/
int8_t timer0A_init = 0;/* return variable of Timer0A_Init function*/
/*----------------------------------------------------------------------------------------------------*/
......@@ -710,7 +677,7 @@ int8_t uartSplitUartString( void )
if ( MAX_LENGTH_COMMAND < strlen(decrypt_uartString) )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_command_is_too_long, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_command_is_too_long, FALSE, NULL);
/* reset */
clearString(decrypt_uartString, BUFFER_SIZE);
......@@ -737,7 +704,7 @@ int8_t uartSplitUartString( void )
if (MAX_LENGTH_PARAMETER < strlen(result))
{
/* TODO: create correct error code*/
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_command_is_too_long, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_command_is_too_long, FALSE, NULL);
clearString(decrypt_uartString, BUFFER_SIZE);
/* "reset": decrypt_uartString[0] = '\0'; */
......@@ -750,7 +717,7 @@ int8_t uartSplitUartString( void )
if ( MAX_PARAMETER < parameterIndex )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_too_many_arguments, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_too_many_arguments, FALSE, NULL);
clearString(decrypt_uartString, BUFFER_SIZE);
/* "reset": decrypt_uartString[0] = '\0'; */
return 0;
......@@ -1031,7 +998,7 @@ int8_t Check_Error( struct uartStruct *ptr_uartStruct )
if ( 0 > ptr_uartStruct->commandKeywordIndex )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_no_valid_command_name,0,NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_no_valid_command_name,0,NULL);
error = TRUE;
}
else
......@@ -1040,7 +1007,7 @@ int8_t Check_Error( struct uartStruct *ptr_uartStruct )
{
if (0 != *ptr_setParameter[index])
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_argument_has_invalid_type + index, 0, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_argument_has_invalid_type + index, 0, NULL);
error = TRUE;
}
if ( TRUE == error )
......@@ -1454,6 +1421,7 @@ uint8_t CommunicationError( uint8_t errorType, const int16_t errorIndex, const u
* output: ERRG/C/U/A/M <error number> <error message> [<alternative/extra Error>]
* output: ERRA/C/U/A/M "<command key> <command arguments>" --- <error number> <error message>
*
* positive <error number> = ERRindex * 100 + errorIndex
* arguments:
* - Error type: defines the error class the error belongs to (ERRG, ERRA, ERRM, ERRC, ERRU)
* - use enums as input
......@@ -1563,27 +1531,27 @@ uint8_t CommunicationError( uint8_t errorType, const int16_t errorIndex, const u
switch (errorType)
{
case ERRG:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, general_error_number[errorIndex]);
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, (errorType * 100) + errorIndex);
strncat_P(uart_message_string, (const char*) (pgm_read_word( &(general_error[errorIndex]))), BUFFER_SIZE -1);
break;
case ERRC:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, (errorType * 100) + errorIndex);
strncat_P(uart_message_string, (const char*) (pgm_read_word( &(can_error[errorIndex]))), BUFFER_SIZE -1);
break;
case ERRA:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, serial_error_number[errorIndex]);
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, (errorType * 100) + errorIndex);
strncat_P(uart_message_string, (const char*) (pgm_read_word( &(serial_error[errorIndex]))), BUFFER_SIZE -1);
break;
case ERRM:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, mob_error_number[errorIndex]);
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, (errorType * 100) + errorIndex);
strncat_P(uart_message_string, (const char*) (pgm_read_word( &(mob_error[errorIndex]))), BUFFER_SIZE -1);
break;
case ERRC:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, can_error_number[errorIndex]);
strncat_P(uart_message_string, (const char*) (pgm_read_word( &(can_error[errorIndex]))), BUFFER_SIZE -1);
break;
case ERRT:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, twi_error_number[errorIndex]);
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, (errorType * 100) + errorIndex);
strncat_P(uart_message_string, (const char*) (pgm_read_word( &(twi_error[errorIndex]))), BUFFER_SIZE -1);
break;
case ERRU:
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, 0);
snprintf_P(uart_message_string, BUFFER_SIZE -1 , PSTR("%s %i "), uart_message_string, (errorType * 100) + errorIndex);
break;
default:
printDebug_p(debugLevelEventDebug, debugSystemApiMisc, __LINE__, PSTR(__FILE__), PSTR("wrong error type %i... returning"), errorType);
......@@ -1702,7 +1670,7 @@ void Initialization( void )
if( FALSE == twim_init)
{
twi_errorCode = CommunicationError_p(ERRT, TWI_ERROR_Error_in_initiating_TWI_interface, FALSE, NULL);
twiErrorCode = CommunicationError_p(ERRT, TWI_ERROR_Error_in_initiating_TWI_interface, FALSE, NULL);
}
owi_init = OWI_Init(0x3f);
......@@ -1728,7 +1696,7 @@ void Initialization( void )
if ( 1 != timer0_init )
{
general_errorCode = CommunicationError_p(ERRG, GENERAL_ERROR_init_for_timer0_failed, FALSE, NULL);
generalErrorCode = CommunicationError_p(ERRG, GENERAL_ERROR_init_for_timer0_failed, FALSE, NULL);
#warning exit must not be used - replace by "unsigned char status __attribute__ ((section (".noinit"))) / reset / retry / fallback "
exit(0);
}
......@@ -1738,7 +1706,7 @@ void Initialization( void )
}
if ( 1 != timer0A_init )
{
general_errorCode = CommunicationError_p(ERRG, GENERAL_ERROR_init_for_timer0A_failed, FALSE, NULL);
generalErrorCode = CommunicationError_p(ERRG, GENERAL_ERROR_init_for_timer0A_failed, FALSE, NULL);
#warning exit must not be used - replace by "unsigned char status __attribute__ ((section (".noinit"))) / reset / retry / fallback "
exit(0);
}
......
......@@ -26,11 +26,11 @@ extern int8_t owi_init; /* return variable of TWIM_Init function*/
extern int8_t timer0_init; /* return variable of Timer0_Init function*/
extern int8_t timer0A_init;/* return variable of Timer0A_Init function*/
extern uint8_t canErrorCode; /* error code for CAN-communication */
extern uint8_t twi_errorCode; /* error code for I2C/TWI-communication */
extern uint8_t general_errorCode; /*general error code */
extern uint8_t mailbox_errorCode; /* error code for Message Object Block */
extern uint8_t uart_errorCode; /* error code for UART-communication */
extern uint16_t canErrorCode; /* error code for CAN-communication */
extern uint16_t twiErrorCode; /* error code for I2C/TWI-communication */
extern uint16_t generalErrorCode; /*general error code */
extern uint16_t mobErrorCode; /* error code for Message Object Block */
extern uint16_t uartErrorCode; /* error code for UART-communication */
extern volatile unsigned char BufferFull;/*variable for UART Interrupt*/
extern volatile unsigned char canReady; /* variable for CAN ISR */
......@@ -59,19 +59,10 @@ extern uint8_t ptr_subscribe; /* pointer of variable subscribe_ID and subscribe_
extern uint8_t flag_pingActive; /* flag for PING mechanism */
extern const uint8_t serial_error_number[] ;
extern const char *serial_error[] PROGMEM;
extern const uint8_t can_error_number[];
extern const char *can_error[] PROGMEM;
extern const uint8_t twi_error_number[];
extern const char *twi_error[] PROGMEM;
extern const uint8_t mob_error_number[] ;
extern const char *mob_error[] PROGMEM;
extern const uint16_t general_error_number[];
extern const char *general_error[] PROGMEM;
extern char currentCommandKeyword[MAX_LENGTH_KEYWORD];/*variable to store current command keyword e.g. "SEND"*/
......
......@@ -67,8 +67,6 @@ static const char ce14[] PROGMEM = "Acknowledgment Error General";
const char *can_error[] PROGMEM = { ce00, ce01, ce02, ce03, ce04, ce05, ce06, ce07, ce08, ce09, ce10, ce11, ce12, ce13, ce14 };
/* array for defined can error number*/
const uint8_t can_error_number[] = { 21, 22, 23, 24, 25, 26, 27, 28, 29, 0x2A, 0x2B, 0x2c, 0x2d, 0x2e };
/* pointer of array for defined mailbox error */
static const char me00[] PROGMEM = "all mailboxes already in use";
......@@ -77,9 +75,6 @@ static const char me02[] PROGMEM = "this message already exists";
const char *mob_error[] PROGMEM = { me00, me01, me02 };
/* array for defined mailbox error number*/
const uint8_t mob_error_number[] = { 31, 32, 33 };
/*
* canSubscribeMessage creates/sets a listener to an ID/mask for a free MOb
* the function has a pointer of the serial structure as input and returns no parameter
......@@ -99,7 +94,7 @@ void canSubscribeMessage( struct uartStruct *ptr_uartStruct )
if ( ( ptr_uartStruct->Uart_Message_ID ) == ( subscribe_ID[count_subscribe] ) && ( ptr_uartStruct->Uart_Mask ) == ( subscribe_mask[count_subscribe] ) )
{
equality = 0;
mailbox_errorCode = CommunicationError_p(ERRM, MOB_ERROR_this_message_already_exists, FALSE, NULL);
mobErrorCode = CommunicationError_p(ERRM, MOB_ERROR_this_message_already_exists, FALSE, NULL);
}
}
if ( 1 == equality )
......@@ -117,7 +112,7 @@ void canSubscribeMessage( struct uartStruct *ptr_uartStruct )
if ( ( -1 ) == findMob )
{
mailbox_errorCode = CommunicationError_p(ERRM, MOB_ERROR_all_mailboxes_already_in_use, FALSE, NULL);
mobErrorCode = CommunicationError_p(ERRM, MOB_ERROR_all_mailboxes_already_in_use, FALSE, NULL);
}
else
{
......@@ -177,7 +172,7 @@ void canUnsubscribeMessage( struct uartStruct *ptr_uartStruct )
}
if ( 1 == inequality )
{
mailbox_errorCode = CommunicationError_p(ERRM, MOB_ERROR_message_ID_not_found, FALSE, NULL);
mobErrorCode = CommunicationError_p(ERRM, MOB_ERROR_message_ID_not_found, FALSE, NULL);
}
} //END of canUnsubscribeMessage
......@@ -993,31 +988,31 @@ void canShowGeneralStatusError( void )
{
canErrorCode = CAN_ERROR_Can_Bus_is_off_interrupt;
CommunicationError_p(ERRC, canErrorCode, FALSE,
PSTR("CANTEC: %i CANREC: %i stored CANGIT: 0x%x"), canCurrentTransmitErrorCounter, canCurrentReceiveErrorCounter,
PSTR("CANTEC: %i CANREC: %i CANGIT: 0x%x"), canCurrentTransmitErrorCounter, canCurrentReceiveErrorCounter,
canCurrentGeneralInterruptRegister);
}
if (canCurrentGeneralInterruptRegister & (1 << SERG))
{
canErrorCode = CAN_ERROR_Stuff_Error_General;
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("stored CANGIT: 0x%x"),
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("CANGIT: 0x%x"),
canCurrentGeneralInterruptRegister);
}
if (canCurrentGeneralInterruptRegister & (1 << CERG))
{
canErrorCode = CAN_ERROR_CRC_Error_General;
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("stored CANGIT: 0x%x"),
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("CANGIT: 0x%x"),
canCurrentGeneralInterruptRegister);
}
if (canCurrentGeneralInterruptRegister & (1 << FERG))
{
canErrorCode = CAN_ERROR_Form_Error_General;
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("stored CANGIT: 0x%x"),
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("CANGIT: 0x%x"),
canCurrentGeneralInterruptRegister);
}
if (canCurrentGeneralInterruptRegister & (1 << AERG))
{
canErrorCode = CAN_ERROR_Acknowledgment_Error_General;
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("stored CANGIT: 0x%x"),
CommunicationError_p(ERRC, canErrorCode, FALSE, PSTR("CANGIT: 0x%x"),
canCurrentGeneralInterruptRegister);
}
......@@ -1218,7 +1213,7 @@ uint8_t canCheckInputParameterError( uartMessage *ptr_uartStruct )
case 1:
if ( ( 0x7FFFFFF ) < ptr_uartStruct->Uart_Message_ID )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_ID_is_too_long, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_ID_is_too_long, FALSE, NULL);
error = TRUE;
break;
}
......@@ -1226,7 +1221,7 @@ uint8_t canCheckInputParameterError( uartMessage *ptr_uartStruct )
case 2:
if ( ( 0x7FFFFFF ) < ptr_uartStruct->Uart_Mask )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_mask_is_too_long, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_mask_is_too_long, FALSE, NULL);
error = TRUE;
break;
}
......@@ -1234,7 +1229,7 @@ uint8_t canCheckInputParameterError( uartMessage *ptr_uartStruct )
case 3:
if ( ( 1 ) < ptr_uartStruct->Uart_Rtr )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_rtr_is_too_long, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_rtr_is_too_long, FALSE, NULL);
error = TRUE;
break;
}
......@@ -1242,7 +1237,7 @@ uint8_t canCheckInputParameterError( uartMessage *ptr_uartStruct )
case 4:
if ( ( 8 ) < ptr_uartStruct->Uart_Length )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_length_is_too_long, FALSE, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_length_is_too_long, FALSE, NULL);
error = TRUE;
break;
}
......@@ -1259,7 +1254,7 @@ uint8_t canCheckInputParameterError( uartMessage *ptr_uartStruct )
{
if ( ( 0XFF ) < ptr_uartStruct->Uart_Data[i] )
{
uart_errorCode = CommunicationError_p(ERRA, SERIAL_ERROR_data_0_is_too_long + i, 0, NULL);
uartErrorCode = CommunicationError_p(ERRA, SERIAL_ERROR_data_0_is_too_long + i, 0, NULL);
error = TRUE;
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment