Skip to content

Commit

Permalink
Fix #345, Add CFE_PSP_StatusToString and CFE_PSP_STATUS_C
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jun 6, 2022
1 parent 4bf1eef commit 605ec72
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 20 deletions.
22 changes: 2 additions & 20 deletions fsw/inc/cfe_psp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,12 @@
#include "common_types.h"
#include "osapi.h"

#include "cfe_psp_error.h"

/*
** Macro Definitions
*/

/*
** Error and return codes
*/
#define CFE_PSP_SUCCESS (0)
#define CFE_PSP_ERROR (-1)
#define CFE_PSP_INVALID_POINTER (-2)
#define CFE_PSP_ERROR_ADDRESS_MISALIGNED (-3)
#define CFE_PSP_ERROR_TIMEOUT (-4)
#define CFE_PSP_INVALID_INT_NUM (-5)
#define CFE_PSP_INVALID_MEM_ADDR (-21)
#define CFE_PSP_INVALID_MEM_TYPE (-22)
#define CFE_PSP_INVALID_MEM_RANGE (-23)
#define CFE_PSP_INVALID_MEM_WORDSIZE (-24)
#define CFE_PSP_INVALID_MEM_SIZE (-25)
#define CFE_PSP_INVALID_MEM_ATTR (-26)
#define CFE_PSP_ERROR_NOT_IMPLEMENTED (-27)
#define CFE_PSP_INVALID_MODULE_NAME (-28)
#define CFE_PSP_INVALID_MODULE_ID (-29)
#define CFE_PSP_NO_EXCEPTION_DATA (-30)

/*
** Definitions for PSP PANIC types
*/
Expand Down
82 changes: 82 additions & 0 deletions fsw/inc/cfe_psp_error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
#ifndef CFE_PSP_ERROR_H
#define CFE_PSP_ERROR_H

/**
* \file
* \brief cFE PSP Error header
*/

#include "common_types.h"

/**
* \brief PSP Status type for readability and potentially type safety
*/
typedef int32 CFE_PSP_Status_t;

/**
* \brief PSP Status macro for literal
*/
#define CFE_PSP_STATUS_C(X) ((CFE_PSP_Status_t)(X))

/**
* \brief PSP Status converted to string length limit
*
* Used for sizing CFE_PSP_StatusString_t intended for use in printing CFE_PSP_Status_t values
* Sized for %ld (LONG_MIN) including NULL
*/
#define CFE_PSP_STATUS_STRING_LENGTH 12

/**
* @brief For the @ref CFE_PSP_StatusToString() function, to ensure
* everyone is making an array of the same length.
*/
typedef char CFE_PSP_StatusString_t[CFE_PSP_STATUS_STRING_LENGTH];

/**
* @brief Convert status to a string
*
* @param[in] status Status value to convert
* @param[out] status_string Buffer to store status converted to string
*
* @return Passed in string pointer
*/
CFE_PSP_StatusString_t *CFE_PSP_StatusToString(CFE_PSP_Status_t status, CFE_PSP_StatusString_t *status_string);

/*
* Error and return codes
*/
#define CFE_PSP_SUCCESS (CFE_PSP_STATUS_C(0))
#define CFE_PSP_ERROR (CFE_PSP_STATUS_C(-1))
#define CFE_PSP_INVALID_POINTER (CFE_PSP_STATUS_C(-2))
#define CFE_PSP_ERROR_ADDRESS_MISALIGNED (CFE_PSP_STATUS_C(-3))
#define CFE_PSP_ERROR_TIMEOUT (CFE_PSP_STATUS_C(-4))
#define CFE_PSP_INVALID_INT_NUM (CFE_PSP_STATUS_C(-5))
#define CFE_PSP_INVALID_MEM_ADDR (CFE_PSP_STATUS_C(-21))
#define CFE_PSP_INVALID_MEM_TYPE (CFE_PSP_STATUS_C(-22))
#define CFE_PSP_INVALID_MEM_RANGE (CFE_PSP_STATUS_C(-23))
#define CFE_PSP_INVALID_MEM_WORDSIZE (CFE_PSP_STATUS_C(-24))
#define CFE_PSP_INVALID_MEM_SIZE (CFE_PSP_STATUS_C(-25))
#define CFE_PSP_INVALID_MEM_ATTR (CFE_PSP_STATUS_C(-26))
#define CFE_PSP_ERROR_NOT_IMPLEMENTED (CFE_PSP_STATUS_C(-27))
#define CFE_PSP_INVALID_MODULE_NAME (CFE_PSP_STATUS_C(-28))
#define CFE_PSP_INVALID_MODULE_ID (CFE_PSP_STATUS_C(-29))
#define CFE_PSP_NO_EXCEPTION_DATA (CFE_PSP_STATUS_C(-30))

#endif /* CFE_PSP_ERROR_H */
1 change: 1 addition & 0 deletions fsw/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Build the shared implementation as a library
add_library(psp-${CFE_PSP_TARGETNAME}-shared OBJECT
src/cfe_psp_error.c
src/cfe_psp_exceptionstorage.c
src/cfe_psp_memrange.c
src/cfe_psp_memutils.c
Expand Down
43 changes: 43 additions & 0 deletions fsw/shared/src/cfe_psp_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
*
* Implements error APIs
*/
#include <stdio.h>

#include "cfe_psp_error.h"

/*----------------------------------------------------------------
*
* Function: CFE_PSP_StatusToString
*
* Purpose: Implemented per public PSP API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
CFE_PSP_StatusString_t *CFE_PSP_StatusToString(CFE_PSP_Status_t status, CFE_PSP_StatusString_t *status_string)
{
if (status_string != NULL)
{
snprintf(*status_string, sizeof(*status_string), "%ld", (long)status);
}
return status_string;
}
44 changes: 44 additions & 0 deletions ut-stubs/cfe_psp_error_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
#define CFE_PSP_ERROR_H

/**
* @file
*
* Auto-Generated stub implementations for functions defined in cfe_psp_error header
*/

#include "cfe_psp_error.h"
#include "utgenstub.h"

/*
* ----------------------------------------------------
* Generated stub function for CFE_PSP_StatusToString()
* ----------------------------------------------------
*/
CFE_PSP_StatusString_t *CFE_PSP_StatusToString(CFE_PSP_Status_t status, CFE_PSP_StatusString_t *status_string)
{
UT_GenStub_SetupReturnBuffer(CFE_PSP_StatusToString, CFE_PSP_StatusString_t *);

UT_GenStub_AddParam(CFE_PSP_StatusToString, CFE_PSP_Status_t, status);
UT_GenStub_AddParam(CFE_PSP_StatusToString, CFE_PSP_StatusString_t *, status_string);

UT_GenStub_Execute(CFE_PSP_StatusToString, Basic, NULL);

return UT_GenStub_GetReturnValue(CFE_PSP_StatusToString, CFE_PSP_StatusString_t *);
}

0 comments on commit 605ec72

Please sign in to comment.