1
|
/**
|
2
|
* \file main.cpp
|
3
|
*
|
4
|
* \brief DSP side main routine for DSP Hello World application.
|
5
|
* The DSP simply sets itself up, and then waits for a
|
6
|
* message from the ARM, to which it replies.
|
7
|
*
|
8
|
* o 0
|
9
|
* | / Copyright (c) 2005-2010
|
10
|
* (CL)---o Critical Link, LLC
|
11
|
* \
|
12
|
* O
|
13
|
*/
|
14
|
|
15
|
#include <std.h>
|
16
|
#include <tsk.h>
|
17
|
#include <stdio.h>
|
18
|
#include <string.h>
|
19
|
|
20
|
#include "core/cl_ipc_inbound.h"
|
21
|
#include "core/cl_ipc_outbound.h"
|
22
|
|
23
|
using namespace MityDSP;
|
24
|
|
25
|
// Forward declarations
|
26
|
void init();
|
27
|
void debugPrint(char *buffer);
|
28
|
int handleInboundMessage(void *apBuffer, uint32_t anLength, void *apUserArg) ;
|
29
|
|
30
|
// Object for sending debug messages (these are received and printed to stdout by tcDspApp)
|
31
|
tcCL_IPCOutbound* gpDebug;
|
32
|
// Object for sending GPPMSGQ1 messages that the ARM will receive
|
33
|
tcCL_IPCOutbound* gpOutbound;
|
34
|
// Object for receiving DSPMSGQ0 messages that the DSP will receive
|
35
|
tcCL_IPCInbound* gpInbound;
|
36
|
|
37
|
/**
|
38
|
* Main routine.
|
39
|
*/
|
40
|
int main(int argc, char* argv[])
|
41
|
{
|
42
|
// initialize the DSPLink system
|
43
|
tcCL_IPCInit::GetInstance();
|
44
|
|
45
|
// Launch an initialization task
|
46
|
TSK_Attrs* lpAttrs = new TSK_Attrs;
|
47
|
*lpAttrs = TSK_ATTRS;
|
48
|
lpAttrs->name = "Initialize";
|
49
|
lpAttrs->stacksize = 8192*2;
|
50
|
lpAttrs->priority = 5;
|
51
|
TSK_create((Fxn)init,lpAttrs);
|
52
|
|
53
|
return 0;
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Initialize the inbound and outbound IPC objects.
|
58
|
*
|
59
|
* \return None.
|
60
|
*/
|
61
|
void init()
|
62
|
{
|
63
|
// Message to ARM core.
|
64
|
char lpReturnMessage[] = "DSP Initialization finished.";
|
65
|
// Buffer for return message
|
66
|
char* lpMessageBuffer = NULL;
|
67
|
|
68
|
// Create the outbound debug link
|
69
|
gpDebug = new tcCL_IPCOutbound("debug");
|
70
|
|
71
|
// Create the inbound link for messages to the DSP
|
72
|
gpInbound = new tcCL_IPCInbound();
|
73
|
|
74
|
gpInbound->Open("DSPMSGQ0", 8);
|
75
|
|
76
|
// Create the outbound controller for sending messages to the ARM
|
77
|
gpOutbound = new tcCL_IPCOutbound("GPPMSGQ1");
|
78
|
|
79
|
if (NULL != gpInbound)
|
80
|
{
|
81
|
// Register a callback function to handle messages from the ARM
|
82
|
gpInbound->RegisterCallback(handleInboundMessage, (void*)NULL);
|
83
|
}
|
84
|
|
85
|
// Now that initialization is complete, let the ARM know with a message
|
86
|
|
87
|
// Obtain a dsplink buffer for the return message
|
88
|
lpMessageBuffer = (char*)gpOutbound->GetBuffer(strlen(lpReturnMessage) + 1);
|
89
|
|
90
|
// Make sure we received a valid buffer
|
91
|
if (NULL != lpMessageBuffer)
|
92
|
{
|
93
|
// Copy our message to the buffer
|
94
|
strcpy(lpMessageBuffer, lpReturnMessage);
|
95
|
|
96
|
// Send the message back to the ARM
|
97
|
gpOutbound->SendMessage(lpMessageBuffer, strlen(lpMessageBuffer)+1);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Callback function that handles messages from the ARM.
|
103
|
*
|
104
|
* \param apBuffer Pointer to message buffer.
|
105
|
* \param anLength Length of message.
|
106
|
* \param apUserArg Pointer to user defined argument
|
107
|
*
|
108
|
* \return 0 on sucess.
|
109
|
*/
|
110
|
int handleInboundMessage(void* apBuffer, uint32_t anLength, void* apUserArg)
|
111
|
{
|
112
|
int retval = 0;
|
113
|
// The return message to the ARM
|
114
|
char lpReturnMessage[] = "Hello Word. DSP Received Message = \'";
|
115
|
// Buffer for return message
|
116
|
char* lpMessageBuffer = NULL;
|
117
|
|
118
|
// Obtain a dsplink buffer for the return message
|
119
|
lpMessageBuffer = (char*)gpOutbound->GetBuffer(strlen(lpReturnMessage) + strlen((const char*)apBuffer) + 2);
|
120
|
|
121
|
// Make sure we received a valid buffer
|
122
|
if (NULL != lpMessageBuffer)
|
123
|
{
|
124
|
// Copy our message to the buffer
|
125
|
strcpy(lpMessageBuffer, lpReturnMessage);
|
126
|
// Append the received message to the buffer
|
127
|
strcpy((char*)&lpMessageBuffer[strlen(lpReturnMessage)], (const char *)apBuffer);
|
128
|
// Null terminate the string
|
129
|
lpMessageBuffer[strlen(lpMessageBuffer)+1] = 0;
|
130
|
// Append the closing quotation
|
131
|
lpMessageBuffer[strlen(lpMessageBuffer)] = '\'';
|
132
|
|
133
|
// Send the message back to the ARM
|
134
|
retval = gpOutbound->SendMessage(lpMessageBuffer, strlen(lpMessageBuffer)+1);
|
135
|
}
|
136
|
else
|
137
|
{
|
138
|
retval = -1;
|
139
|
}
|
140
|
|
141
|
return retval;
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Function for sending debug messages to the ARM.
|
146
|
*
|
147
|
* \param buffer Null terminated string to be printed.
|
148
|
*
|
149
|
* \return None.
|
150
|
*/
|
151
|
void debugPrint(char* pMsg)
|
152
|
{
|
153
|
// The length of the message to be sent
|
154
|
int len = strlen(pMsg);
|
155
|
// Pointer to dsplink buffer where to write the message
|
156
|
char* pBuffer;
|
157
|
|
158
|
// Make sure the debug IPC outbound object has been initialized
|
159
|
if (gpDebug == NULL)
|
160
|
return;
|
161
|
|
162
|
// Get a buffer for the message
|
163
|
pBuffer = (char *)gpDebug->GetBuffer(len+1);
|
164
|
|
165
|
// Check that the buffer is valid
|
166
|
if (pBuffer)
|
167
|
{
|
168
|
// Copy the message to the buffer
|
169
|
strcpy(pBuffer, pMsg);
|
170
|
// Send the message
|
171
|
gpDebug->SendMessage(pBuffer, len+1);
|
172
|
}
|
173
|
}
|
174
|
|