-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipc.c
More file actions
102 lines (91 loc) · 2.29 KB
/
ipc.c
File metadata and controls
102 lines (91 loc) · 2.29 KB
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
92
93
94
95
96
97
98
99
100
101
102
/* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty. This file is offered as-is,
* without any warranty.
*/
/*! @file main.c
* @brief Implements the IPC handling of the template application.
*/
#include "template.h"
#include <string.h>
OSC_ERR CheckIpcRequests(uint32 *pParamId)
{
OSC_ERR err;
struct IPC_DATA *pIpc = &data.ipc;
struct OSC_IPC_REQUEST *pReq = &pIpc->req;
if (pIpc->enReqState != REQ_STATE_IDLE)
{
/* This means we still have an unacknowledged request from
* last time. Proceed with the acknowledgement instead of
* already getting new ones.*/
return -ENO_MSG_AVAIL;
}
/* Get the next request. */
err = OscIpcGetRequest(pIpc->ipcChan, pReq);
if (err == SUCCESS)
{
/* We have a request. */
/* In case of success simply return the parameter ID of the requested parameter. */
*pParamId = pReq->paramID;
}
else
{
/* Getting request not successful => analyze why. */
if (likely(err == -ENO_MSG_AVAIL))
{
/* Simply no request available. */
}
else
{
OscLog(ERROR, "%s: Error getting IPC request! (%d)\n", __func__, err);
}
}
return err;
}
OSC_ERR AckIpcRequests()
{
struct IPC_DATA *pIpc = &data.ipc;
struct OSC_IPC_REQUEST *pReq = &pIpc->req;
OSC_ERR err;
bool bSuccess;
if (pIpc->enReqState == REQ_STATE_IDLE)
{
/* Nothing to acknowledge. */
return SUCCESS;
}
else if (pIpc->enReqState == REQ_STATE_NACK_PENDING)
{
bSuccess = FALSE;
}
else
{
bSuccess = TRUE;
}
err = OscIpcAckRequest(pIpc->ipcChan, pReq, bSuccess);
if (err == SUCCESS)
{
/* Ack sent successfully. Now we're ready for the next request.*/
pIpc->enReqState = REQ_STATE_IDLE;
}
else if (err == -ETRY_AGAIN)
{
/* Not really an error, just means we have to try again later, which will happen soon enough. */
err = SUCCESS;
}
return err;
}
void IpcSendImage_fr16(fract16 *f16Image, uint32 nPixels)
{
fract16 *pSrc = f16Image;
int i;
uint8 *pDst = (uint8*)data.ipc.req.pAddr;
/* Copy the corresponding image to the address supplied in
* the request. Only copy the more significant byte since
* it will be written as an 8bit bmp and the source image
* is 16 bit. */
for (i = 0; i < nPixels; i++)
{
*pDst = (uint8)(((uint32)((int32)(*pSrc) + 0x7fff)) >> 8);
pSrc++;
pDst++;
}
}