forked from DouglasSherk/RTOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_c.cpp
91 lines (76 loc) · 2.51 KB
/
process_c.cpp
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
/**
This file implements process c.
**/
#include "process_c.h"
#include "rtx.h"
#include <string.h>
Process::ProcessTuple ProcessC::process()
{
return ProcessTuple( PROCESS_C, LOW, 0 );
}
// Add a message to the local message queue.
int ProcessC::enqueue_local_message( MsgEnv * pMessage )
{
// Get a node, assign the message envelope to it, and enqueue it to the local message queue.
rtx_stl::node<MsgEnv> * pMessageNode = RTX::request_message_node();
pMessageNode->set(pMessage);
m_local_messages.enqueue(pMessageNode);
return 1;
}
// Get a message from the local message queue.
MsgEnv * ProcessC::dequeue_local_message()
{
// Get the message node from the local message queue.
rtx_stl::node<MsgEnv> * pMessageNode = m_local_messages.dequeue();
// Get the message from the node and release that node.
MsgEnv * pMessage = pMessageNode->get();
RTX::release_message_node( pMessageNode );
return pMessage;
}
void ProcessC::main()
{
while ( true )
{
// If the local message queue has messages in it, then read those messages first. Otherwise read messages from the inbox.
MsgEnv * pMessage = m_local_messages.empty() ? RTX::receive_message() : dequeue_local_message();
if( pMessage->get_type() == COUNT_REPORT )
{
// Get the count in the message.
int count;
sscanf( pMessage->m_data, "%i", &count );
if( count % 20 == 0 )
{
// Output "Process C" to the screen.
strcpy( pMessage->m_data, "Process C\n" );
RTX::send_console_chars( pMessage );
// Wait for acknowledgement from crt.
while ( true )
{
// Look for acknowledgement message from the crt helper process. If other messages are received, add them to the local message queue to be dealt with later.
pMessage = RTX::receive_message();
if ( pMessage->get_type() == DISPLAY_ACK )
break;
else
enqueue_local_message( pMessage );
}
// Request 10 second delay.
RTX::request_delay( 100, WAKEUP_CODE, pMessage );
// Look for wakeup message from the timer i-process. If other messages are received, add them to the local message queue to be dealt with later.
while ( true )
{
pMessage = RTX::receive_message();
if ( pMessage->get_type() == WAKEUP_CODE )
break;
else
enqueue_local_message(pMessage );
}
}
}
// Deallocate message and release processor.
RTX::release_msg_env( pMessage );
RTX::release_processor();
}
}
void ProcessC::terminate()
{
}