Revision 64fde4ba src/urt_core.c

View differences:

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

  

Also available in: Unified diff