01.06.2013 Views

IPC@CHIP Documentation - SC12 @CHIP-RTOS V1.10

IPC@CHIP Documentation - SC12 @CHIP-RTOS V1.10

IPC@CHIP Documentation - SC12 @CHIP-RTOS V1.10

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Generic example using TCP/IP memory pool receive buffer:<br />

int huge myDevReceive1(DevUserIfaceHandle ifaceHandle,<br />

unsigned char far * far * dataPtr,<br />

int far * dataLength,<br />

DevUserBufferHandle bufferHandle)<br />

{<br />

int errorCode;<br />

unsigned int rcvdLength;<br />

unsigned char far *tcp_buffer ;<br />

}<br />

// Hardware specific: Check how many incoming data bytes are available.<br />

rcvdLength = .....; // =byte count<br />

// Get a buffer from TCP/IP by calling API service 0xA5 and save at dataPtr<br />

Dev_Get_Buffer(bufferHandle, dataPtr, rcvdLength); // C-Lib call<br />

tcp_buffer = *dataPtr ; // Check if memory allocation successful<br />

if (tcp_buffer != (unsigned char far *)0)<br />

{<br />

// Hardware specific: Move received data from device to tcp_buffer<br />

// Do not wait (sleep) here for indefinite times,<br />

// to avoid blocking of other function calls.<br />

*dataLength = recvdLength; // Report number of bytes now in tcp_buffer<br />

return 0; // success<br />

}<br />

else<br />

{<br />

return -1; // out of memory<br />

}<br />

// Generic example for using your own receive buffer:<br />

int huge myDevReceive2(DevUserIfaceHandle ifaceHandle,<br />

unsigned char far * far * dataPtr,<br />

int far * dataLength,<br />

DevUserBufferHandle bufferHandle)<br />

{<br />

// Save the pointer to the beginning of the data<br />

*dataPtr = myBuffer; // myBuffer somehow allocated by the user<br />

}<br />

Related Topics<br />

Top of list<br />

Index page<br />

// Hardware specific: Read data from your device and store in myBuffer<br />

// Save the length (in bytes) of received data<br />

*dataLength = deviceDataLength;<br />

// IMPORTANT: Null out the bufferhandle pointer<br />

*bufferHandle = (DevUserBuffer)0;<br />

return 0;<br />

DEV_GET_BUF API - Dev_Get_Buffer's implementation<br />

DevUserIfaceHandle type definition<br />

Device FreeReceive function<br />

Page 346 / 400

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!