1
|
/**
|
2
|
* \file: main.cpp
|
3
|
*
|
4
|
* \brief ARM side main routine for DSP Hello World application.
|
5
|
* The ARM sets itself up, sends a message to the DSP,
|
6
|
* and then waits for a return message before exiting.
|
7
|
*
|
8
|
* o 0
|
9
|
* | / Copyright (c) 2005-2010
|
10
|
* (CL)---o Critical Link, LLC
|
11
|
* \
|
12
|
* O
|
13
|
*/
|
14
|
|
15
|
#include "dspapp.h"
|
16
|
#include <stdio.h>
|
17
|
#include <string.h>
|
18
|
#include <unistd.h>
|
19
|
|
20
|
#include "ipc_inbound.h"
|
21
|
#include "ipc_outbound.h"
|
22
|
|
23
|
using namespace MityDSP;
|
24
|
|
25
|
// Forward declarations
|
26
|
int handleInboundMessage(void *Buffer, uint16_t Length, void *UserArg);
|
27
|
|
28
|
volatile bool gbDone = false;
|
29
|
|
30
|
int main(int argc, char* argv[])
|
31
|
{
|
32
|
// tcDspApp class for booting and loading the DSP
|
33
|
tcDspApp* lpDspApp = NULL;
|
34
|
// Used to setup handling of inbound messages from DSP
|
35
|
tcIPCInbound* lpMessageInbound = NULL;
|
36
|
// Used to send messages to the DSP
|
37
|
tcIPCOutbound* lpMessageOutbound = NULL;
|
38
|
// Message to send to the DSP
|
39
|
char lpMessage[] = "Hello DSP";
|
40
|
// Pointer to buffer obtained from dsplink
|
41
|
char* lpMessageBuffer = NULL;
|
42
|
// Message from standard input
|
43
|
char lpUsrMsg[180] = {0};
|
44
|
|
45
|
// Check application usage
|
46
|
if (argc < 2)
|
47
|
{
|
48
|
printf("usage: HelloWorld dsp_image.out\n");
|
49
|
return -1;
|
50
|
}
|
51
|
|
52
|
// Create the DspApp object
|
53
|
lpDspApp = new tcDspApp();
|
54
|
|
55
|
// Load the DSP.out file
|
56
|
printf("Loading file %s\n", argv[1]);
|
57
|
lpDspApp->LoadApp(argv[1]);
|
58
|
|
59
|
printf("Starting application.\n");
|
60
|
|
61
|
// Create the object to handle incoming messages from the DSP
|
62
|
lpMessageInbound = new tcIPCInbound((char*)"GPPMSGQ1");
|
63
|
|
64
|
if (NULL != lpMessageInbound)
|
65
|
{
|
66
|
// Register the callback for handling messages from the DSP
|
67
|
lpMessageInbound->Register(handleInboundMessage, (void*)NULL);
|
68
|
|
69
|
// Intiailize the inbound controller to create the thread that handles the callbacks
|
70
|
lpMessageInbound->Initialize();
|
71
|
}
|
72
|
|
73
|
// Create the object used to send messages to the DSP
|
74
|
lpMessageOutbound = new tcIPCOutbound((char*)"DSPMSGQ0");
|
75
|
|
76
|
// Wait for the DSP to finish initialization
|
77
|
while(false == gbDone);
|
78
|
|
79
|
// Reset bool in prep for next receive message from DSP
|
80
|
gbDone = false;
|
81
|
|
82
|
// Get a buffer for a message to the DSP
|
83
|
lpMessageBuffer = (char*)lpMessageOutbound->GetBuffer(strlen(lpMessage)+1);
|
84
|
|
85
|
// Copy the message to the dsplink buffer
|
86
|
strcpy(lpMessageBuffer, lpMessage);
|
87
|
|
88
|
// Send the message to the DSP
|
89
|
printf("Sending a message to the DSP.\n");
|
90
|
lpMessageOutbound->SendMessage(lpMessageBuffer);
|
91
|
|
92
|
// Wait for a message to be received from the DSP or for user to quit
|
93
|
printf("Waiting for DSP response (type \'q\' to quit)...\n");
|
94
|
while(gbDone == false && lpUsrMsg[0] != 'q')
|
95
|
{
|
96
|
fgets(lpUsrMsg, 180, stdin);
|
97
|
}
|
98
|
|
99
|
printf("Exiting application.\n");
|
100
|
|
101
|
// Stop the DSP application from running
|
102
|
lpDspApp->StopApp();
|
103
|
|
104
|
// Cleanup
|
105
|
// Commented out because deletes throw Assert errors.
|
106
|
//delete lpDspApp;
|
107
|
//delete lpMessageInbound;
|
108
|
//delete lpMessageOutbound;
|
109
|
|
110
|
return 0;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Handle inbound messages from the DSP.
|
115
|
*
|
116
|
* \param apBuffer Pointer to the buffer containing the message.
|
117
|
* \param anLength The length of the message.
|
118
|
* \param apUserArg User defined argument.
|
119
|
*
|
120
|
* \return 0.
|
121
|
*/
|
122
|
int handleInboundMessage(void *apBuffer, uint16_t anLength, void *apUserArg)
|
123
|
{
|
124
|
printf("ARM received a message from the DSP:\n");
|
125
|
|
126
|
// Print the message we received
|
127
|
printf("\tDSP Message = \"%s\"\n", (char *)apBuffer);
|
128
|
|
129
|
// Notify the main function that we have received a message from the DSP and are done
|
130
|
gbDone = true;
|
131
|
|
132
|
return 0;
|
133
|
}
|
134
|
|