urtware / src / urt_node.c @ 17d978fe
History | View | Annotate | Download (5.398 KB)
| 1 |
/*
|
|---|---|
| 2 |
µRtWare is a lightweight publish/subscribe middleware for real-time
|
| 3 |
applications. It was developed as part of the software habitat for the
|
| 4 |
Autonomous Mini Robot [1] (AMiRo) but can be used for other purposes as well.
|
| 5 |
|
| 6 |
Copyright (C) 2018..2020 Thomas Schöpping et al.
|
| 7 |
|
| 8 |
This program is free software: you can redistribute it and/or modify
|
| 9 |
it under the terms of the GNU General Public License as published by
|
| 10 |
the Free Software Foundation, either version 3 of the License, or
|
| 11 |
(at your option) any later version.
|
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful,
|
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
GNU General Public License for more details.
|
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License
|
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
*/
|
| 21 |
|
| 22 |
#include <urtware.h> |
| 23 |
|
| 24 |
/******************************************************************************/
|
| 25 |
/* LOCAL DEFINITIONS */
|
| 26 |
/******************************************************************************/
|
| 27 |
|
| 28 |
/******************************************************************************/
|
| 29 |
/* EXPORTED VARIABLES */
|
| 30 |
/******************************************************************************/
|
| 31 |
|
| 32 |
/******************************************************************************/
|
| 33 |
/* LOCAL TYPES */
|
| 34 |
/******************************************************************************/
|
| 35 |
|
| 36 |
/******************************************************************************/
|
| 37 |
/* LOCAL VARIABLES */
|
| 38 |
/******************************************************************************/
|
| 39 |
|
| 40 |
urt_node_t localNode; //TODO:Correct?
|
| 41 |
|
| 42 |
/******************************************************************************/
|
| 43 |
/* LOCAL FUNCTIONS */
|
| 44 |
/******************************************************************************/
|
| 45 |
|
| 46 |
/**
|
| 47 |
* @brief Main function of a node.
|
| 48 |
*
|
| 49 |
* @param[in] arg Optional Argument to the thread main function.
|
| 50 |
*/
|
| 51 |
void _main(void* arg) |
| 52 |
{
|
| 53 |
//TODO: Register to core event
|
| 54 |
if (localNode.setupcallback != NULL) |
| 55 |
{
|
| 56 |
// urt_osEventMask_t mask = localNode.setupcallback(localNode, arg);
|
| 57 |
// TODOs
|
| 58 |
} |
| 59 |
else
|
| 60 |
{
|
| 61 |
//TODO: act as if setupcallback returned 0xF..F
|
| 62 |
} |
| 63 |
if (core._status == URT_STATUS_OK)
|
| 64 |
{
|
| 65 |
//TODO: Suspend all child threads
|
| 66 |
urtCoreSynchronizeNodes(&localNode); |
| 67 |
//TODO: Resume all child threads
|
| 68 |
} |
| 69 |
//TODOs
|
| 70 |
return;
|
| 71 |
} |
| 72 |
|
| 73 |
/******************************************************************************/
|
| 74 |
/* EXPORTED FUNCTIONS */
|
| 75 |
/******************************************************************************/
|
| 76 |
|
| 77 |
/**
|
| 78 |
* @brief Initalize a node.
|
| 79 |
*
|
| 80 |
* @param[in] node The node to initialize. Must not be NULL.
|
| 81 |
* @param[in] thread The already initialized, exclusive thread for the node. Must not be NULL.
|
| 82 |
* @param[in] setupcallback Callback function to be executed during setup.
|
| 83 |
* May be NULL if no custom setup is required.
|
| 84 |
* @param[in] setupparams Parameters for the setup callback function.
|
| 85 |
* Must be NULL if no setup callback is specified.
|
| 86 |
* May be NULL if the specified setup callback does not expect parameters.
|
| 87 |
* @param[in] loopcallback Callback function to be executed in a loop.
|
| 88 |
* Must not be NULL.
|
| 89 |
* @param[in] loopparams Parameters for the loop callback function.
|
| 90 |
* May be NULL if the specified loop callback does not expect parameters.
|
| 91 |
* @param[in] shutdowncallback Callback function to be executed during shutdown.
|
| 92 |
* May be NULL if no custom shutdown is required.
|
| 93 |
* @param[in] shutdownparams Parameters for the loop callback function.
|
| 94 |
* Must be NULL if no shutdown callback is specified.
|
| 95 |
* May be NULL if the specified shutdown callback does not expect parameters.
|
| 96 |
*/
|
| 97 |
void urtNodeInit(urt_node_t* node, urt_osThread_t* thread, urt_nodeSetupCallback_t* setupcallback,
|
| 98 |
void* setupparams, urt_nodeLoopCallback_t* loopcallback, void* loopparams, |
| 99 |
urt_nodeShutdownCallback_t* shutdowncallback, void* shutdownparams)
|
| 100 |
{
|
| 101 |
urtDebugAssert(node != NULL);
|
| 102 |
urtDebugAssert(thread != NULL);
|
| 103 |
//TODO: Setupcallback
|
| 104 |
if (setupcallback == NULL) |
| 105 |
urtDebugAssert(setupparams == NULL);
|
| 106 |
urtDebugAssert(loopcallback != NULL);
|
| 107 |
//urtDebugAssert(/*loopparams*/);
|
| 108 |
//urtDebugAssert(shutdowncallback);
|
| 109 |
//urtDebugAssert(shutdownparams);
|
| 110 |
|
| 111 |
node->next = NULL;
|
| 112 |
node->thread = thread; |
| 113 |
node->setupcallback = setupcallback; |
| 114 |
node->setupparams = setupparams; |
| 115 |
node->loopcallback = loopcallback; |
| 116 |
node->loopparams = loopparams; |
| 117 |
node->shutdowncallback = shutdowncallback; |
| 118 |
node->shutdownparams = shutdownparams; |
| 119 |
node->stage = 0;
|
| 120 |
urtEventListenerInit(node->listener); |
| 121 |
#if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
|
| 122 |
node->loops = 0;
|
| 123 |
#endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */ |
| 124 |
urtMutexLock(&core._lock); |
| 125 |
node->next = core._nodes; |
| 126 |
core._nodes = node; |
| 127 |
urtMutexUnlock(&core._lock); |
| 128 |
localNode = *node; |
| 129 |
return;
|
| 130 |
} |