Receive.c File Reference

Receiving UDP packets. More...

#include <BoardSupport/inc/stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <Libs/NETlib/net.h>
#include <BoardSupport/inc/BoardSpecific.h>
#include <Common/Common.h>
#include <Common/uartio.h>
#include <Common/timer.h>
#include <Common/CPrintf.h>
#include <Common/xdump.h>
#include <BoardSupport/config/netconfig.c>

Macros

#define INC_XDUMP
 
#define DSP_PORT   5031
 
#define MAXDATA_SIZE   4
 
#define CHAR_SOCKET   1
 
#define DATATYPE   DATATYPE_CHAR /* data type 8 bits */
 
#define DATATYPE_t   char /* data type 8 bits */
 

Functions

int32_t udp_call_back (SOCKET *so, void *data, uint32_t len, uint32_t ec)
 
int main (void)
 

Variables

char * program_name = "receive"
 
SOCKET * udp_socket
 
DATATYPE_tudp_data
 

Detailed Description

                          _         _             _
                       __| |    ___(_) ____ _ __ | |_
                      / _` |   / __| |/ _` | '_ \| __|
                     | (_| | _ \__ \ | (_| | | | | |_
                      \__,_|(_) ___/_|\__, |_| |_|\__|
                     Signalprocessing |___/ Technology
Author
D.SignT GmbH & Co. KG, Claus Hermbusche
Date
2019-06-03

Simple DSP program for receiving UDP - packets. The received data is used to switch the LED's on and off.

Macro Definition Documentation

#define INC_XDUMP

include hex dump module: xdump.h

#define DSP_PORT   5031
Examples:
Receive.c.
#define MAXDATA_SIZE   4
Examples:
Receive.c.
#define CHAR_SOCKET   1
#define DATATYPE   DATATYPE_CHAR /* data type 8 bits */
Examples:
Receive.c.
#define DATATYPE_t   char /* data type 8 bits */
Examples:
Receive.c.

Function Documentation

int32_t udp_call_back ( SOCKET *  so,
void *  data,
uint32_t  len,
uint32_t  ec 
)
Examples:
Receive.c.
187 {
188  /***************************************************************************
189  locals
190  ***************************************************************************/
191  int32_t data_length; // net_recv_event_handler() return parameter
192 
193  /***************************************************************************
194  suppress unused parameter warning
195  ***************************************************************************/
197  UNREFERENCED_PARAMETER(len); // len is ignored, data_length is used instead
198  UNREFERENCED_PARAMETER(ec); // handled in net_recv_event_handler()
199 
200  /***************************************************************************
201  Check events
202  Use net_recv_event_handler() to determine the data length waiting in the
203  receive buffer
204  If NULL is passed as pLog parameter, no message is printed to output.
205  CPrintf is used here for demonstration purpose only. You shouldn't use
206  long blocking operation in callback functions.
207  ***************************************************************************/
208  data_length = net_recv_event_handler (so, CPrintf); /* with messages */
209  // data_length = net_recv_event_handler (so, NULL); /* without messages */
210 
211  /***************************************************************************
212  net_recv_event_handler() returns the amount of data waiting in the buffer
213  ***************************************************************************/
214  if (data_length)
215  {
216  /***********************************************************************
217  CPrintf is used here for demonstration purpose only. You shouldn't use
218  long blocking operation in callback functions.
219  ***********************************************************************/
220  CPrintf(" len = %"PRId32"\r\n", data_length);
221 
222  /***********************************************************************
223  dump the data
224  void xd (void *mem, uint32_t bufl, int16_t dochar, uint32_t address, size_t size);
225 
226  Parameter
227  mem - Address of buffer to dump.
228  bufl - Buffer length in bytes.
229  dochar - If non-zero, show ASCII/ISO characters
230  as well as hexadecimal.
231  address - address-offset
232  size - size of buffer element
233  ***********************************************************************/
234  xd (data, len, TRUE, (uint32_t)data, DATATYPE);
235  }
236 
237  /***************************************************************************
238  return true, if message processed
239  ***************************************************************************/
240  return (SOCKET_CB_OK);
241 }
int CPrintf(const char *_format,...)
Custom printf function.
Definition: cprintf.c:708
unsigned int uint32_t
Definition: stdint.h:47
#define DATATYPE
Definition: Receive.c:154
int int32_t
Definition: stdint.h:46
#define UNREFERENCED_PARAMETER(P)
Definition: Common.h:115
void xd(void *mem, uint32_t bufl, int16_t dochar, uint32_t address, size_t size)
Definition: xdump.c:218
#define SOCKET_CB_OK
Definition: net.h:576
int main ( void  )
Examples:
Receive.c.
252 {
253  /***************************************************************************
254  locals
255  ***************************************************************************/
256  int main_loop = 1; /* main loop switch, set to 0 to exit */
257  timeval stamp1, stamp2, delta; /* used to determine startup time */
258 
259  /***************************************************************************
260  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
261  (ref. \Common\Common.c)
262  ***************************************************************************/
263  AppInit (GET_CLOCK);
264 
265  /***************************************************************************
266  select output device for CPrintf (ref. \Common\cprintf.c)
267  possible settings:
268  CPRINTF_UART_OUTPUT -> output to UART
269  CPRINTF_CCS_OUTPUT -> output to CCS
270  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
271  ***************************************************************************/
272  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
273  xd_config_output ((void *)CPrintf);
274 
275  /***************************************************************************
276  print a start up message
277  ***************************************************************************/
278  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
279 
280  /**************************************************************************/
281  // CPrintfProgress (" Heap check ");
282  // at least 0x2000 bytes required for this app
283  /**************************************************************************/
284  ASSERT_HEAP (initial_heap_size, 0x2000);
285  // CPrintfProgressSuccess();
286 
287  /***************************************************************************
288  malloc space for data
289  ***************************************************************************/
290  CPrintfProgress (" Try to allocate data buffer ");
291  udp_data = (DATATYPE_t*) malloc (MAXDATA_SIZE * sizeof(DATATYPE_t));
292  if ( udp_data == NULL )
293  {
294  prg_exit ("out of memory error");
295  }
297 
298  /**************************************************************************/
299  CPrintfProgress (" Setup system time ");
300  // 1 milli seconds resolution
301  /**************************************************************************/
304  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
306 
307  /**************************************************************************/
308  CPrintfProgress (" Enable interrupts ");
309  /**************************************************************************/
312 
313  /**************************************************************************/
314  CPrintfProgress (" Start system timer ");
315  /**************************************************************************/
316  StartSystemTimer ();
318  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
319 
320  /***************************************************************************
321  measure network initialization time
322  ***************************************************************************/
323  stamp1 = GetTimeStamp();
324 
325  /**************************************************************************/
326  CPrintfProgress (" Initialize network ");
327  /**************************************************************************/
328  InitializeNetwork ( 64); // 64 bytes for ping
329 
330 
331  /***************************************************************************
332  open socket
333  ***************************************************************************/
334  udp_socket = socket_open (ANY_ADDRESS, /* all addresses */
335  ANY_PORT, /* destination port */
336  DSP_PORT, /* source port */
337  DATATYPE, /* data type char, int16_t or int32_t */
338  UDP_INIT_FUNC); /* udp protocol */
339  if ( udp_socket == INVALID_SOCKET )
340  {
341  prg_exit ("socket_open() error"); /* possibly insufficient heap */
342  } // if
343 
344  /***************************************************************************
345  define callback function for received UDP packets
346  ***************************************************************************/
349 
350  stamp2 = GetTimeStamp();
351 
352  tv_interval (&delta, &stamp1, &stamp2);
353  CPuts (" network startup time [sec]: ");
355  "%"PRId32".%03"PRId32"\r\n"
357  delta.tv_sec,
358  delta.tv_usec/1000);
359 
360 
361  /***************************************************************************
362  main program loop: set main_loop to 0 to exit loop
363  ***************************************************************************/
364  CPuts ("\r\n Entering main loop ...\r\n");
365  while ( main_loop )
366  {
367  /***********************************************************************
368  process net_isq()
369  ***********************************************************************/
370  net_isq (); // process ISQ
371 
372  /***********************************************************************
373  monitor link status
374  ***********************************************************************/
376 
377  /***********************************************************************
378  try to detect IP assignment
379  if DHCP is used, the assigned IP address may change
380  ***********************************************************************/
382 
383  /***********************************************************************
384  show that the program is running, perform symbol animation
385  ***********************************************************************/
387  }
388 
389  /***************************************************************************
390  exit program, shut down peripherals
391  ***************************************************************************/
392  return (0);
393 }
#define prg_exit(s)
Definition: Common.h:267
void BoardEnableInterrupts(void)
global enable interrupts
Definition: BoardSpecific.c:365
void socket_define_callback(SOCKET *so, int32_t(*call_back_function)(SOCKET *, void *, uint32_t, uint32_t), void *data, uint16_t maxdata)
Install a user callback function for a specific socket.
#define ANIMATE_SYMBOLS_COUNT
Definition: BoardSpecific.h:268
void StartSystemTimer(void)
start system timer
Definition: timer.c:447
int32_t udp_call_back(SOCKET *so, void *data, uint32_t len, uint32_t ec)
Definition: Receive.c:186
#define RES_MSECONDS
Definition: timer.h:67
uint16_t CPrintf_select_output(uint16_t device)
Definition: cprintf.c:206
#define ASSERT_HEAP(i, h)
Definition: Common.h:262
#define ANY_PORT
Definition: net.h:519
#define NULL
Definition: net.h:126
void xd_config_output(void *output)
Definition: xdump.c:108
time_t GetSystemTimerRes(void)
Definition: timer.c:160
DATATYPE_t * udp_data
Definition: Receive.c:165
#define GET_CLOCK
Definition: BoardSpecific.h:258
#define UDP_INIT_FUNC
Definition: net.h:500
#define MAXDATA_SIZE
Definition: Receive.c:129
int CPrintf(const char *_format,...)
Custom printf function.
Definition: cprintf.c:708
#define VT100_DEFAULT
Definition: cprintf.h:150
void SetupSystemTime(int32_t cpuint, int port, time_t resolution)
Setup System Time.
Definition: timer.c:392
void AppInit(uint32_t dsp_clock)
Initialize application.
Definition: Common.c:230
uint32_t initial_heap_size
Definition: Common.c:140
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
SOCKET * udp_socket
Definition: Receive.c:143
#define VT100_RED
Definition: cprintf.h:143
uint16_t CPrintAnimatedSymbol(char *c, time_t period, size_t size)
Definition: cprintf.c:816
int InitializeNetwork(uint16_t icmp_size)
Initialize MAC, sockets and protocols.
Definition: BoardSpecific.c:597
char sym_animate[]
Definition: BoardSpecific.c:129
#define DSP_PORT
Definition: Receive.c:124
SOCKET * socket_open(char *dest_addr, uint16_t dest_port, uint16_t src_port, uint8_t data_type, int32_t(*init_func)(SOCKET *))
Create a new socket.
Definition: timer.h:75
#define GetTimeStamp()
Definition: timer.h:81
void tv_interval(timeval *e, timeval *t1, timeval *t2)
compute elapsed time
Definition: timer.c:336
#define DATATYPE
Definition: Receive.c:154
#define ANY_ADDRESS
Definition: net.h:511
#define SYSTEM_TIMER_INT
Definition: BoardSpecific.h:174
#define SYSTEM_TIMER
Definition: BoardSpecific.h:167
void net_isq(void)
The main polling function for processing sockets, must be periodically called in the main application...
#define BLANK_REV
Definition: BoardSpecific.h:191
Uint16 SystemTimerDev
#define INVALID_SOCKET
Definition: net.h:540
uint16_t monitor_ip_address(tpOutputFunc pLog)
monitor IP assignment
Definition: BoardSpecific.c:545
#define START_UP_MESSAGE(rev)
Definition: BoardSpecific.h:192
#define RES_SECONDS
Definition: timer.h:70
uint16_t monitor_link_status(tpOutputFunc pLog)
monitor link status change
Definition: BoardSpecific.c:497
int CPuts(const char *_ptr)
Definition: cprintf.c:399
time_t tv_sec
Definition: timer.h:77
#define DATATYPE_t
Definition: Receive.c:155
#define CPrintfProgress(s)
Definition: cprintf.h:230
time_t tv_usec
Definition: timer.h:78
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "receive"
Examples:
Receive.c.
SOCKET* udp_socket
Examples:
Receive.c.
DATATYPE_t* udp_data
Examples:
Receive.c.