Revision 64fde4ba
| Makefile | ||
|---|---|---|
| 30 | 30 |
|
| 31 | 31 |
# include paths |
| 32 | 32 |
URTWARE_INC = $(URTWARE_DIR:/=) \ |
| 33 |
$(URTWARE_DIR)inc |
|
| 33 |
$(URTWARE_DIR)inc \ |
|
| 34 |
$(URTWARE_DIR)inc/urt_core.h \ |
|
| 35 |
$(URTWARE_DIR)inc/urt_node.h |
|
| 34 | 36 |
|
| 35 | 37 |
# C sources |
| 36 | 38 |
URTWARE_CSRC = $(URTWARE_DIR)src/urt_core.c \ |
| inc/urt_node.h | ||
|---|---|---|
| 22 | 22 |
#ifndef URTWARE_NODE_H |
| 23 | 23 |
#define URTWARE_NODE_H |
| 24 | 24 |
|
| 25 |
#include <urt_types.h> |
|
| 26 | 25 |
#include <urtware.h> |
| 27 | 26 |
|
| 28 | 27 |
/******************************************************************************/ |
| ... | ... | |
| 42 | 41 |
/******************************************************************************/ |
| 43 | 42 |
|
| 44 | 43 |
/** |
| 45 |
* @brief node |
|
| 46 |
*/ |
|
| 47 |
typedef struct urt_node |
|
| 48 |
{
|
|
| 49 |
urt_node_t* next; |
|
| 50 |
urt_osThread_t* thread; |
|
| 51 |
urt_nodeSetupCallback_t* setupcallback; |
|
| 52 |
void* setupparams; |
|
| 53 |
urt_nodeLoopCallback_t* loopcallback; |
|
| 54 |
void* loopparams; |
|
| 55 |
urt_nodeShutdownCallback_t* shutdowncallback; |
|
| 56 |
void* shutdownparams; |
|
| 57 |
urt_nodestage_t stage; |
|
| 58 |
urt_osEventListener_t listener; |
|
| 59 |
#if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING) |
|
| 60 |
uint64_t loops; |
|
| 61 |
#endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */ |
|
| 62 |
}urt_node_t; |
|
| 63 |
|
|
| 64 |
|
|
| 65 |
/** |
|
| 66 | 44 |
* @brief |
| 67 | 45 |
* |
| 68 | 46 |
* @param[in] node . |
| ... | ... | |
| 72 | 50 |
* @return . |
| 73 | 51 |
* |
| 74 | 52 |
*/ |
| 75 |
typedef void (*urt_nodeShutdownCallback_t)(urt_node_t* node, urt_status_t cause, void* arg);
|
|
| 53 |
typedef void (*urt_nodeShutdownCallback_t)(struct urt_node* node, urt_status_t cause, void* arg);
|
|
| 76 | 54 |
|
| 77 | 55 |
|
| 78 | 56 |
/** |
| ... | ... | |
| 84 | 62 |
* @return . |
| 85 | 63 |
* |
| 86 | 64 |
*/ |
| 87 |
typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(urt_node_t* node, void* arg);
|
|
| 65 |
typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(struct urt_node* node, void* arg);
|
|
| 88 | 66 |
|
| 89 | 67 |
|
| 90 | 68 |
/** |
| ... | ... | |
| 96 | 74 |
* |
| 97 | 75 |
* @return . |
| 98 | 76 |
*/ |
| 99 |
typedef urt_osEventMask_t (*urt_nodeLoopCallback_t)(urt_node_t* node, urt_osEventMask_t events, void* arg); |
|
| 77 |
typedef urt_osEventMask_t (*urt_nodeLoopCallback_t)(struct urt_node* node, urt_osEventMask_t events, void* arg); |
|
| 78 |
|
|
| 79 |
/** |
|
| 80 |
* @brief node |
|
| 81 |
*/ |
|
| 82 |
typedef struct urt_node |
|
| 83 |
{
|
|
| 84 |
struct urt_node* next; |
|
| 85 |
urt_osThread_t* thread; |
|
| 86 |
urt_nodeSetupCallback_t* setupcallback; |
|
| 87 |
void* setupparams; |
|
| 88 |
urt_nodeLoopCallback_t* loopcallback; |
|
| 89 |
void* loopparams; |
|
| 90 |
urt_nodeShutdownCallback_t* shutdowncallback; |
|
| 91 |
void* shutdownparams; |
|
| 92 |
urt_nodestage_t stage; |
|
| 93 |
urt_osEventListener_t listener; |
|
| 94 |
#if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING) |
|
| 95 |
uint64_t loops; |
|
| 96 |
#endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */ |
|
| 97 |
}urt_node_t; |
|
| 98 |
|
|
| 100 | 99 |
|
| 101 | 100 |
/******************************************************************************/ |
| 102 | 101 |
/* MACROS */ |
| src/urt_core.c | ||
|---|---|---|
| 33 | 33 |
/* LOCAL TYPES */ |
| 34 | 34 |
/******************************************************************************/ |
| 35 | 35 |
|
| 36 |
urt_core_t core; |
|
| 37 |
|
|
| 36 | 38 |
/******************************************************************************/ |
| 37 | 39 |
/* LOCAL VARIABLES */ |
| 38 | 40 |
/******************************************************************************/ |
| ... | ... | |
| 50 | 52 |
*/ |
| 51 | 53 |
void urtCoreInit(void) |
| 52 | 54 |
{
|
| 53 |
urt_core_t._nodes = NULL;
|
|
| 54 |
urt_core_t._status = URT_STATUS_OK;
|
|
| 55 |
urtEventSourceInit(urt_core_t._evtSource);
|
|
| 56 |
urtMutexInit(urt_core_t._lock);
|
|
| 55 |
core._nodes = NULL;
|
|
| 56 |
core._status = URT_STATUS_OK;
|
|
| 57 |
urtEventSourceInit(core._evtSource);
|
|
| 58 |
urtMutexInit(&core._lock);
|
|
| 57 | 59 |
#if (URT_CFG_PUBSUB_ENABLED) |
| 58 |
urt_core_t._topics = NULL;
|
|
| 60 |
core._topics = NULL;
|
|
| 59 | 61 |
#endif /* URT_CFG_PUBSUB_ENABLED */ |
| 60 | 62 |
#if (URT_CFG_RPC_ENABLED) |
| 61 |
urt_core_t.urt_service_t = NULL;
|
|
| 63 |
core.urt_service_t = NULL;
|
|
| 62 | 64 |
#endif /* URT_CFG_RPC_ENABLED */ |
| 63 | 65 |
return; |
| 64 | 66 |
} |
| ... | ... | |
| 68 | 70 |
* |
| 69 | 71 |
* @return Current system status. |
| 70 | 72 |
*/ |
| 71 |
urt_status_t urtCoreGetStatus(void) {return URT_STATUS_OK;}
|
|
| 73 |
urt_status_t urtCoreGetStatus(void) |
|
| 74 |
{
|
|
| 75 |
return core._status; |
|
| 76 |
} |
|
| 72 | 77 |
|
| 73 | 78 |
/** |
| 74 | 79 |
* @brief Start threads of all nodes of the Core. |
| 75 | 80 |
*/ |
| 76 |
void urtCoreStartNodes(void) {return;}
|
|
| 81 |
void urtCoreStartNodes(void) |
|
| 82 |
{
|
|
| 83 |
//TODO: Lock core |
|
| 84 |
urt_node_t* node = core._nodes; |
|
| 85 |
while (node) |
|
| 86 |
{
|
|
| 87 |
urtThreadStart(node->thread); |
|
| 88 |
node = node->next; |
|
| 89 |
} |
|
| 90 |
//TODO: Unlock core |
|
| 91 |
return; |
|
| 92 |
} |
|
| 77 | 93 |
|
| 78 | 94 |
/** |
| 79 | 95 |
* @brief Synchronize all nodes of the core. |
| ... | ... | |
| 85 | 101 |
* Returns URT_STATUS_SYNC_PENDING if there are nodes left to synchronize. |
| 86 | 102 |
* In the latter case, the node thread must still wait for the control event (proceed) to synchronize. |
| 87 | 103 |
*/ |
| 88 |
urt_status_t urtCoreSynchronize(urt_node_t* node) {return URT_STATUS_OK;}
|
|
| 104 |
urt_status_t urtCoreSynchronize(urt_node_t* node) |
|
| 105 |
{
|
|
| 106 |
//TODO: Lock core |
|
| 107 |
//TODO: Increment node's stage value |
|
| 108 |
urt_node_t* nodeFromCore = core._nodes; |
|
| 109 |
while (nodeFromCore /*stage equals stage*/) |
|
| 110 |
{
|
|
| 111 |
nodeFromCore = nodeFromCore->next; |
|
| 112 |
} |
|
| 113 |
bool temp = false; |
|
| 114 |
if (temp/*all nodes are the same stage*/) |
|
| 115 |
{
|
|
| 116 |
//TODO: Unlock core |
|
| 117 |
return URT_STATUS_OK; |
|
| 118 |
} |
|
| 119 |
else if (temp/*stage of the last checked node was one less than the argument*/) |
|
| 120 |
{
|
|
| 121 |
//TODO: Unlock core |
|
| 122 |
return URT_STATUS_SYNC_PENDING; |
|
| 123 |
} |
|
| 124 |
else |
|
| 125 |
{
|
|
| 126 |
urtCoreStopNodes(URT_STATUS_SYNC_ERROR); |
|
| 127 |
return URT_STATUS_SYNC_ERROR; |
|
| 128 |
} |
|
| 129 |
} |
|
| 89 | 130 |
|
| 90 | 131 |
/** |
| 91 | 132 |
* @brief Stop threads of all nodes of the Core. |
| ... | ... | |
| 95 | 136 |
* @return Returns URT_STATUS_OK if there was no call with another reason than URT_STATUS_OK before. |
| 96 | 137 |
* If the function has been called before with a different reason, that reason is returned. |
| 97 | 138 |
*/ |
| 98 |
urt_status_t urtCoreStopNodes(urt_status_t reason) {return URT_STATUS_OK;}
|
|
| 139 |
urt_status_t urtCoreStopNodes(urt_status_t reason) |
|
| 140 |
{
|
|
| 141 |
//TODO: Lock core |
|
| 142 |
if (core._status == URT_STATUS_OK) |
|
| 143 |
{
|
|
| 144 |
if (core._nodes->thread->prio < URT_THREAD_PRIO_HIGH_MAX) |
|
| 145 |
{
|
|
| 146 |
core._nodes->thread->prio = URT_THREAD_PRIO_HIGH_MAX; |
|
| 147 |
} |
|
| 148 |
else |
|
| 149 |
{
|
|
| 150 |
core._status = reason; |
|
| 151 |
urt_node_t* node = core._nodes; |
|
| 152 |
while (node) |
|
| 153 |
{
|
|
| 154 |
urt_node_t* tempNode = node; |
|
| 155 |
tempNode = NULL; |
|
| 156 |
node = node->next; |
|
| 157 |
} |
|
| 158 |
//TODO: broadcast control event (terminate) |
|
| 159 |
//TODO:Unlock core |
|
| 160 |
//TODO: Thread boosted its priority? |
|
| 161 |
} |
|
| 162 |
} |
|
| 163 |
else |
|
| 164 |
{
|
|
| 165 |
//TODO:Unlock core |
|
| 166 |
return core._status; |
|
| 167 |
} |
|
| 168 |
return URT_STATUS_OK; |
|
| 169 |
} |
|
| 99 | 170 |
|
| 100 | 171 |
/** |
| 101 | 172 |
* @brief Get the topic of the Core. |
| ... | ... | |
| 104 | 175 |
* |
| 105 | 176 |
* @return Returns a pointer to the requested service. Returns NULL if no service matches the given ID. |
| 106 | 177 |
*/ |
| 107 |
urt_topic_t* urtCoreGetTopic(urt_topicid_t id) {return urt_topic_t;}
|
|
| 178 |
#if (URT_CFG_PUBSUB_ENABLED) |
|
| 179 |
urt_topic_t* urtCoreGetTopic(urt_topicid_t id) {return urt_topic_t;}
|
|
| 180 |
#endif /* URT_CFG_PUBSUB_ENABLED */ |
|
| 181 |
|
|
| 108 | 182 |
|
| 109 | 183 |
/** |
| 110 | 184 |
* @brief Get the service of the Core. |
| ... | ... | |
| 112 | 186 |
* @param[in] id Identifier of the service to retrieve. |
| 113 | 187 |
* |
| 114 | 188 |
* @return Returns a pointer to the requested service. Returns NULL if no service matches the given ID. |
| 115 |
*/ |
|
| 116 |
urt_service_t urtCoreGetService(urt_serviceid_t id) {return urt_service_t;}
|
|
| 189 |
*/ |
|
| 190 |
#if (URT_CFG_RPC_ENABLED) |
|
| 191 |
urt_service_t urtCoreGetService(urt_serviceid_t id) {return urt_service_t;}
|
|
| 192 |
#endif /* URT_CFG_RPC_ENABLED */ |
|
| 193 |
|
|
| 117 | 194 |
|
| src/urt_node.c | ||
|---|---|---|
| 69 | 69 |
void* setupparams, urt_nodeLoopCallback_t* loopcallback, void* loopparams, |
| 70 | 70 |
urt_nodeShutdownCallback_t* shutdowncallback, void* shutdownparams) |
| 71 | 71 |
{
|
| 72 |
urt_node_t.next = NULL;
|
|
| 73 |
urt_node_t.thread = thread;
|
|
| 74 |
urt_node_t.setupcallback = setupcallback;
|
|
| 75 |
urt_node_t.setupparams = setupparams;
|
|
| 76 |
urt_node_t.loopparams = loopparams;
|
|
| 77 |
urt_node_t.shutdowncallback = loopcallback;
|
|
| 78 |
urt_node_t.shutdownparams = loopparams;
|
|
| 79 |
urt_node_t.stage = 0;
|
|
| 72 |
node->next = NULL;
|
|
| 73 |
node->thread = thread;
|
|
| 74 |
node->setupcallback = setupcallback;
|
|
| 75 |
node->setupparams = setupparams;
|
|
| 76 |
node->loopparams = loopparams;
|
|
| 77 |
node->shutdowncallback = loopcallback;
|
|
| 78 |
node->shutdownparams = loopparams;
|
|
| 79 |
node->stage = 0;
|
|
| 80 | 80 |
// add later: urteventlistenerinit |
| 81 | 81 |
#if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING) |
| 82 |
urt_node_t.loops = 0;
|
|
| 82 |
node->loops = 0;
|
|
| 83 | 83 |
#endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */ |
| 84 | 84 |
// add later: lock core,.. |
| 85 | 85 |
return; |
| urtware.h | ||
|---|---|---|
| 95 | 95 |
/* |
| 96 | 96 |
* TODO: Add further µRtWare includes here (e.g. urt_core.h). |
| 97 | 97 |
*/ |
| 98 |
#include <urt_core.h>
|
|
| 98 |
#include <apps_urtosal.h>
|
|
| 99 | 99 |
#include <urt_node.h> |
| 100 |
|
|
| 100 |
#include <urt_core.h> |
|
| 101 | 101 |
|
| 102 | 102 |
#endif /* URTWARE_H */ |
Also available in: Unified diff