-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathcfe_psp_module.c
142 lines (127 loc) · 4.03 KB
/
cfe_psp_module.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 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 cfe_psp_module.c
*
* Created on: Jul 25, 2014
* Author: jphickey
*/
#include <stdio.h>
#include <string.h>
#include "osapi.h"
#include "cfe_psp_module.h"
/*
* When using an OSAL that also supports "opaque object ids", choose values here
* that will fit in with the OSAL object ID values and not overlap anything.
*/
#ifdef OS_OBJECT_TYPE_USER
#define CFE_PSP_MODULE_BASE ((OS_OBJECT_TYPE_USER + 0x100) << OS_OBJECT_TYPE_SHIFT)
#define CFE_PSP_MODULE_INDEX_MASK OS_OBJECT_INDEX_MASK
#else
#define CFE_PSP_MODULE_BASE 0x01100000
#define CFE_PSP_MODULE_INDEX_MASK 0xFFFF
#endif
static uint32 CFE_PSP_ModuleCount = 0;
/***************************************************
* Function Name: CFE_PSP_ModuleInitList
*
* Helper function to initalize a list of modules (not externally called)
*/
void CFE_PSP_ModuleInitList(CFE_StaticModuleLoadEntry_t *ListPtr)
{
CFE_StaticModuleLoadEntry_t *Entry;
CFE_PSP_ModuleApi_t * ApiPtr;
/*
* Call the init function for all statically linked modules
*/
Entry = ListPtr;
if (Entry != NULL)
{
while (Entry->Name != NULL)
{
ApiPtr = (CFE_PSP_ModuleApi_t *)Entry->Api;
if ((uint32)ApiPtr->ModuleType == CFE_PSP_MODULE_TYPE_SIMPLE && ApiPtr->Init != NULL)
{
(*ApiPtr->Init)(CFE_PSP_MODULE_BASE | CFE_PSP_ModuleCount);
}
++Entry;
++CFE_PSP_ModuleCount;
}
}
}
/***************************************************
* Function Name: CFE_PSP_ModuleInit
*
* See prototype for full description
*/
void CFE_PSP_ModuleInit(void)
{
/* First initialize the fixed set of modules for this PSP */
CFE_PSP_ModuleInitList(CFE_PSP_BASE_MODULE_LIST);
/* Then initialize any user-selected extension modules */
CFE_PSP_ModuleInitList(GLOBAL_CONFIGDATA.PspModuleList);
}
/***************************************************
* Function Name: CFE_PSP_Module_GetAPIEntry
*
* See prototype for full description
*/
int32 CFE_PSP_Module_GetAPIEntry(uint32 PspModuleId, CFE_PSP_ModuleApi_t **API)
{
int32 Result;
uint32 LocalId;
Result = CFE_PSP_INVALID_MODULE_ID;
if ((PspModuleId & ~CFE_PSP_MODULE_INDEX_MASK) == CFE_PSP_MODULE_BASE)
{
LocalId = PspModuleId & CFE_PSP_MODULE_INDEX_MASK;
if (LocalId < CFE_PSP_ModuleCount)
{
*API = (CFE_PSP_ModuleApi_t *)GLOBAL_CONFIGDATA.PspModuleList[LocalId].Api;
Result = CFE_PSP_SUCCESS;
}
}
return Result;
}
/***************************************************
* Function Name: CFE_PSP_Module_FindByName
*
* See prototype for full description
*/
int32 CFE_PSP_Module_FindByName(const char *ModuleName, uint32 *PspModuleId)
{
uint32 i;
int32 Result;
CFE_StaticModuleLoadEntry_t *Entry;
Entry = GLOBAL_CONFIGDATA.PspModuleList;
Result = CFE_PSP_INVALID_MODULE_NAME;
i = 0;
while (i < CFE_PSP_ModuleCount)
{
if (strcmp(Entry->Name, ModuleName) == 0)
{
*PspModuleId = CFE_PSP_MODULE_BASE | (i & CFE_PSP_MODULE_INDEX_MASK);
Result = CFE_PSP_SUCCESS;
break;
}
++Entry;
++i;
}
return Result;
}