Revision 4ea18a07

View differences:

inc/urt_node.h
40 40
/* DATA STRUCTURES AND TYPES                                                  */
41 41
/******************************************************************************/
42 42

  
43
/*
44
 * forward declarations
45
 */
46
typedef struct urt_node urt_node_t;
47

  
43 48
/**
44 49
 * @brief
45 50
 *
......
50 55
 * @return    .
51 56
 *
52 57
 */
53
typedef void (*urt_nodeShutdownCallback_t)(struct urt_node* node, urt_status_t cause, void* arg);
58
typedef void (*urt_nodeShutdownCallback_t)(urt_node_t* node, urt_status_t cause, void* arg);
54 59

  
55 60

  
56 61
/**
......
62 67
 * @return    .
63 68
 *
64 69
 */
65
typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(struct urt_node* node, void* arg);
70
typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(urt_node_t* node, void* arg);
66 71

  
67 72

  
68 73
/**
......
74 79
 *
75 80
 * @return    .
76 81
 */
77
typedef urt_osEventMask_t (*urt_nodeLoopCallback_t)(struct urt_node* node, urt_osEventMask_t events, void* arg);
82
typedef urt_osEventMask_t (*urt_nodeLoopCallback_t)(urt_node_t* node, urt_osEventMask_t events, void* arg);
78 83

  
79 84
/**
80 85
 * @brief  node
81 86
 */
82
typedef struct urt_node
87
struct urt_node
83 88
{
84 89
  struct urt_node* next;
85 90
  urt_osThread_t* thread;
......
94 99
  #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
95 100
    uint64_t loops;
96 101
  #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
97
}urt_node_t;
102
};
98 103

  
99 104

  
100 105
/******************************************************************************/
......
109 114
extern "C" {
110 115
#endif /* defined(__cplusplus) */
111 116

  
112
  void urtNodeInit(urt_node_t* node, urt_osThread_t* thread, urt_osThreadPrio_t prio, urt_nodeSetupCallback_t* setupcallback,
113
                   void* setupparams, urt_nodeLoopCallback_t* loopcallback, void* loopparams,
114
                   urt_nodeShutdownCallback_t* shutdowncallback, void* shutdownparams);
117
  void urtNodeInit(urt_node_t* node, urt_osThread_t* thread, urt_osThreadPrio_t prio, urt_nodeSetupCallback_t setupcallback,
118
                   void* setupparams, urt_nodeLoopCallback_t loopcallback, void* loopparams,
119
                   urt_nodeShutdownCallback_t shutdowncallback, void* shutdownparams);
115 120
#if defined(__cplusplus)
116 121
}
117 122
#endif /* defined(__cplusplus) */
src/urt_node.c
37 37
/* LOCAL VARIABLES                                                            */
38 38
/******************************************************************************/
39 39

  
40
urt_node_t localNode;
41
static  URT_THREAD_MEMORY(_node_thread, AMIROOS_CFG_SHELL_STACKSIZE); //TODO: not here
42

  
43 40
/******************************************************************************/
44 41
/* LOCAL FUNCTIONS                                                            */
45 42
/******************************************************************************/
......
51 48
 */
52 49
void _main(void* arg)
53 50
{
51
  urt_node_t* localNode = (urt_node_t*)arg;
54 52
  urt_osEventMask_t mask;
55 53
  urt_osEventFlags_t flag = 0;
56
  urtEventRegister(urtCoreGetEvtSource(), &localNode.listener, mask, flag);
57
  if (localNode.setupcallback != NULL)
54
  urtEventRegister(urtCoreGetEvtSource(), &(localNode->listener), mask, flag);
55
  if (localNode->setupcallback != NULL)
58 56
  {
59
    mask = localNode.setupcallback(&localNode, arg);
57
    mask = localNode->setupcallback(localNode, localNode->setupparams);
60 58
    if (mask == urtCoreGetEventMask())
61 59
    {
62 60
        urtCoreStopNodes(URT_STATUS_NODE_INVALEVTMASK);
......
64 62
  }
65 63
  else
66 64
  {
67
     mask = ALL_EVENTS;
65
     mask = URT_EVENTMASK_ALL;
68 66
  }
69 67

  
70 68
  if (urtCoreGetStatus() == URT_STATUS_OK)
......
77 75
    urt_osEventMask_t temp = urtEventWait(mask, URT_EVENT_WAIT_ONE, URT_DELAY_INFINITE);
78 76
    if (temp == urtCoreGetEventMask())
79 77
    {
80
      localNode.loopcallback(&localNode, mask, arg);
78
      localNode->loopcallback(localNode, mask, localNode->loopparams);
81 79
      #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
82
        localNode.loops++;
80
        localNode->loops++;
83 81
      #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
84 82
      if (mask == urtCoreGetEventMask())
85 83
      {
......
88 86
    }
89 87
  }
90 88

  
91
  if (localNode.shutdowncallback)
89
  if (localNode->shutdowncallback)
92 90
  {
93
    localNode.shutdowncallback(&localNode, urtCoreGetStatus(), arg);
91
    localNode->shutdowncallback(localNode, urtCoreGetStatus(), localNode->shutdownparams);
94 92
  }
95
  urtEventUnregister(urtCoreGetEvtSource(), &localNode.listener);
93
  urtEventUnregister(urtCoreGetEvtSource(), &localNode->listener);
96 94

  
97
  urt_osThread_t* threadToTerminate = localNode.thread;
95
  urt_osThread_t* threadToTerminate = localNode->thread;
98 96
  while (threadToTerminate->children != NULL || threadToTerminate->sibling != NULL)
99 97
  {
100 98
    if (threadToTerminate->children != NULL)
......
104 102
  }
105 103
  urtThreadTerminate(&threadToTerminate, URT_THREAD_TERMINATE_REQUEST);
106 104

  
107
  urt_osThread_t* threadToJoin = localNode.thread;
105
  urt_osThread_t* threadToJoin = localNode->thread;
108 106
  while (threadToJoin->children != NULL || threadToJoin->sibling != NULL)
109 107
  {
110 108
    if (threadToJoin->children != NULL)
......
140 138
 *                            Must be NULL if no shutdown callback is specified.
141 139
 *                            May be NULL if the specified shutdown callback does not expect parameters.
142 140
 */
143
void urtNodeInit(urt_node_t* node, urt_osThread_t* thread, urt_osThreadPrio_t prio, urt_nodeSetupCallback_t* setupcallback,
144
                 void* setupparams, urt_nodeLoopCallback_t* loopcallback, void* loopparams,
145
                 urt_nodeShutdownCallback_t* shutdowncallback, void* shutdownparams)
141
void urtNodeInit(urt_node_t* node, urt_osThread_t* thread, urt_osThreadPrio_t prio, urt_nodeSetupCallback_t setupcallback,
142
                 void* setupparams, urt_nodeLoopCallback_t loopcallback, void* loopparams,
143
                 urt_nodeShutdownCallback_t shutdowncallback, void* shutdownparams)
146 144
{
147 145
  urtDebugAssert(node != NULL);
148 146
  urtDebugAssert(thread == NULL);
......
150 148
    urtDebugAssert(setupparams == NULL);
151 149

  
152 150
  node->next = NULL;
153
  node->thread = urtThreadInit(_node_thread, sizeof(_node_thread), prio, _main, setupparams);
151
  node->thread = urtThreadInit(thread, sizeof(thread), prio, _main, node);
154 152
  node->setupcallback = setupcallback;
155 153
  node->setupparams = setupparams;
156 154
  node->loopcallback = loopcallback;
......
168 166
    urt_node_t* nodeCore = urtCoreGetNodes();
169 167
    nodeCore = node;
170 168
  urtMutexUnlock(mutexTemp);
171
  localNode = *node;
172 169
  return;
173 170
}
urt_osal.h
236 236
 *    This constant is typically either 0x0..1 (low values have high priority)
237 237
 *    or 0x8..0 (high values have high priority).
238 238
 *    A value of 0 indicates that priorities are not supported.
239
 *
240
 * URT_EVENTMASK_ALL
241
 *    Constant of type urt_osEventMask_t to filter no events at all.
242
 *    Typically is 0xF..F.
239 243
 */
240 244

  
241 245
/**

Also available in: Unified diff