Skip to content

Commit

Permalink
update nasa#285, Cleanup for RTEMS
Browse files Browse the repository at this point in the history
  • Loading branch information
jphickey committed Apr 21, 2020
1 parent 87558a7 commit 0a79ddf
Show file tree
Hide file tree
Showing 29 changed files with 636 additions and 264 deletions.
4 changes: 3 additions & 1 deletion src/os/rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ set(RTEMS_BASE_SRCLIST
src/os-impl-console.c
src/os-impl-countsem.c
src/os-impl-dirs.c
src/os-impl-errors.c
src/os-impl-files.c
src/os-impl-filesys.c
src/os-impl-fpu.c
src/os-impl-idmap.c
src/os-impl-heap.c
src/os-impl-interrupts.c
src/os-impl-mutex.c
Expand All @@ -40,7 +42,7 @@ set(RTEMS_IMPL_SRCLIST
# then build the module loader
if (OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER)
list(APPEND RTEMS_IMPL_SRCLIST
src/os-impl-module.c # Use RTEMS-specific versions of the load/unload routines
src/os-impl-loader.c # Use RTEMS-specific versions of the load/unload routines
../portable/os-impl-posix-dl-symtab.c # Use Standard POSIX implementation for symbol lookups
)
else ()
Expand Down
5 changes: 2 additions & 3 deletions src/os/rtems/inc/os-rtems.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
#include <rtems/malloc.h>
#include <rtems/rtems/intr.h>

#include "common_types.h"
#include "osapi.h"
#include "os-impl.h"
#include <osapi-shared-globaldefs.h>

/****************************************************************************************
DEFINES
Expand Down Expand Up @@ -83,6 +81,7 @@ int32 OS_Rtems_DirAPI_Impl_Init(void);
int32 OS_Rtems_FileSysAPI_Impl_Init(void);


int32 OS_Rtems_TableMutex_Init(uint32 idtype);


#endif /* INCLUDE_OS_RTEMS_H_ */
Expand Down
2 changes: 2 additions & 0 deletions src/os/rtems/src/os-impl-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "os-rtems.h"
#include "os-impl-binsem.h"
#include "osapi-binsem-impl.h"
#include "osapi-idmap-impl.h"


/****************************************************************************************
Expand Down
207 changes: 39 additions & 168 deletions src/os/rtems/src/os-impl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,124 +29,10 @@
***************************************************************************************/

#include "os-rtems.h"

/****************************************************************************************
DEFINES
***************************************************************************************/

#define OSAL_TABLE_MUTEX_ATTRIBS (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY)

/****************************************************************************************
GLOBALS
***************************************************************************************/

rtems_id OS_task_table_sem;
rtems_id OS_queue_table_sem;
rtems_id OS_bin_sem_table_sem;
rtems_id OS_mutex_table_sem;
rtems_id OS_count_sem_table_sem;
rtems_id OS_stream_table_mut;
rtems_id OS_dir_table_mut;
rtems_id OS_timebase_table_mut;
rtems_id OS_module_table_mut;
rtems_id OS_filesys_table_mut;
rtems_id OS_console_mut;

static rtems_id * const MUTEX_TABLE[] =
{
[OS_OBJECT_TYPE_UNDEFINED] = NULL,
[OS_OBJECT_TYPE_OS_TASK] = &OS_task_table_sem,
[OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_sem,
[OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_sem,
[OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_sem,
[OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_sem,
[OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut,
[OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut,
[OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut,
[OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut,
[OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut,
[OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut,
};

enum
{
MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0]))
};

const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } };
#include "osapi-common-impl.h"

RTEMS_GlobalVars_t RTEMS_GlobalVars = { 0 };

/*----------------------------------------------------------------
*
* Function: OS_Lock_Global_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype in os-impl.h for argument/return detail
*
*-----------------------------------------------------------------*/
int32 OS_Lock_Global_Impl(uint32 idtype)
{
rtems_id *mut;

if (idtype < MUTEX_TABLE_SIZE)
{
mut = MUTEX_TABLE[idtype];
}
else
{
mut = NULL;
}

if (mut == NULL)
{
return OS_ERROR;
}

if (rtems_semaphore_obtain(*mut, RTEMS_WAIT, RTEMS_NO_TIMEOUT) != 0)
{
return OS_ERROR;
}

return OS_SUCCESS;
} /* end OS_Lock_Global_Impl */

/*----------------------------------------------------------------
*
* Function: OS_Unlock_Global_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype in os-impl.h for argument/return detail
*
*-----------------------------------------------------------------*/
int32 OS_Unlock_Global_Impl(uint32 idtype)
{
rtems_id *mut;

if (idtype < MUTEX_TABLE_SIZE)
{
mut = MUTEX_TABLE[idtype];
}
else
{
mut = NULL;
}

if (mut == NULL)
{
return OS_ERROR;
}

if (rtems_semaphore_release(*mut) != 0)
{
return OS_ERROR;
}

return OS_SUCCESS;
} /* end OS_Unlock_Global_Impl */



/****************************************************************************************
INITIALIZATION FUNCTION
***************************************************************************************/
Expand All @@ -162,63 +48,48 @@ int32 OS_Unlock_Global_Impl(uint32 idtype)
int32 OS_API_Impl_Init(uint32 idtype)
{
int32 return_code = OS_SUCCESS;
rtems_status_code rtems_sc;

do
return_code = OS_Rtems_TableMutex_Init(idtype);
if (return_code != OS_SUCCESS)
{
/* Initialize the table mutex for the given idtype */
if (idtype < MUTEX_TABLE_SIZE && MUTEX_TABLE[idtype] != NULL)
{
rtems_sc = rtems_semaphore_create (idtype,
1, OSAL_TABLE_MUTEX_ATTRIBS, 0,
MUTEX_TABLE[idtype]);

if ( rtems_sc != RTEMS_SUCCESSFUL )
{
OS_DEBUG("Error: rtems_semaphore_create failed: %s\n", rtems_status_text(rtems_sc));
return_code = OS_ERROR;
break;
}
}

switch(idtype)
{
case OS_OBJECT_TYPE_OS_TASK:
return_code = OS_Rtems_TaskAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_QUEUE:
return_code = OS_Rtems_QueueAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_BINSEM:
return_code = OS_Rtems_BinSemAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_COUNTSEM:
return_code = OS_Rtems_CountSemAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_MUTEX:
return_code = OS_Rtems_MutexAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_MODULE:
return_code = OS_Rtems_ModuleAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_TIMEBASE:
return_code = OS_Rtems_TimeBaseAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_STREAM:
return_code = OS_Rtems_StreamAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_DIR:
return_code = OS_Rtems_DirAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_FILESYS:
return_code = OS_Rtems_FileSysAPI_Impl_Init();
break;
default:
break;
}
return return_code;
}
while (0);

switch(idtype)
{
case OS_OBJECT_TYPE_OS_TASK:
return_code = OS_Rtems_TaskAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_QUEUE:
return_code = OS_Rtems_QueueAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_BINSEM:
return_code = OS_Rtems_BinSemAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_COUNTSEM:
return_code = OS_Rtems_CountSemAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_MUTEX:
return_code = OS_Rtems_MutexAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_MODULE:
return_code = OS_Rtems_ModuleAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_TIMEBASE:
return_code = OS_Rtems_TimeBaseAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_STREAM:
return_code = OS_Rtems_StreamAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_DIR:
return_code = OS_Rtems_DirAPI_Impl_Init();
break;
case OS_OBJECT_TYPE_OS_FILESYS:
return_code = OS_Rtems_FileSysAPI_Impl_Init();
break;
default:
break;
}

return(return_code);
} /* end OS_API_Impl_Init */
Expand Down
2 changes: 2 additions & 0 deletions src/os/rtems/src/os-impl-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
***************************************************************************************/

#include "os-rtems.h"
#include "osapi-printf-impl.h"
#include "osapi-idmap-impl.h"

/****************************************************************************************
DEFINES
Expand Down
3 changes: 3 additions & 0 deletions src/os/rtems/src/os-impl-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "os-rtems.h"
#include "os-impl-countsem.h"

#include "osapi-countsem-impl.h"
#include "osapi-idmap-impl.h"

/****************************************************************************************
DEFINES
***************************************************************************************/
Expand Down
35 changes: 35 additions & 0 deletions src/os/rtems/src/os-impl-errors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright (c) 2020, United States government as represented by the
* administrator of the National Aeronautics Space Administration.
* All rights reserved. This software was created at NASA Goddard
* Space Flight Center pursuant to government contracts.
*
* This is governed by the NASA Open Source Agreement and may be used,
* distributed and modified only according to the terms of that agreement.
*
*/


/**
* \file os-impl-common.c
* \ingroup rtems
* \author joseph.p.hickey@nasa.gov
*
* This file contains some of the OS APIs abstraction layer for RTEMS
* This has been tested against the current RTEMS 4.11 release branch
*
* NOTE: This uses only the "Classic" RTEMS API. It is intended to
* work on RTEMS targets that do not provide the POSIX API, i.e.
* when "--disable-posix" is given during the configuration stage.
*/

/****************************************************************************************
INCLUDE FILES
***************************************************************************************/

#include "os-rtems.h"
#include "osapi-errors-impl.h"

const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } };

2 changes: 2 additions & 0 deletions src/os/rtems/src/os-impl-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <rtems/rtems-rfs.h>
#include <rtems/rtems-rfs-format.h>

#include "osapi-filesys-impl.h"
#include "osapi-idmap-impl.h"

/****************************************************************************************
Data Types
Expand Down
Loading

0 comments on commit 0a79ddf

Please sign in to comment.