cancel
Showing results for 
Search instead for 
Did you mean: 

TCP, GPIO and Timer running at the same time

xtian
Associate II
Posted on July 17, 2013 at 03:20

Hi Guys,

I want to implement a GPIO data acquisition UDP/TCP communication and tick count or microsecond counting HAPPENING all at the same time.. how can I do that? details: my data to be sent via tcp /udp is from the GPIO ports and tick count.. i want to have the actual tick time and how do I close the PCB? so i will not go out of stack space

/**
******************************************************************************
* @file udp_echoclient.c
* @author MCD Application Team
* @version V1.0.0
* @date 31-October-2011
* @brief UDP echo client
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <
h2
><
center
>© COPYRIGHT 2011 STMicroelectronics</
center
></
h2
>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include ''GlobalVars.h''
#include ''main.h''
#include ''pbuf.h''
#include ''udp.h''
#include ''tcp.h''
#include <
string.h
>
#include <
stdio.h
>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
u8_t data[250];
__IO uint32_t message_count = 0;
__IO uint8_t Flag = 0;
struct udp_pcb *upcb;
/* Private functions ---------------------------------------------------------*/
/**
* @brief Connect to UDP echo server
* @param None
* @retval None
*/
void udp_echoclient_connect(void)
{
// struct udp_pcb *upcb;
struct pbuf *p;
struct ip_addr DestIPaddr;
err_t err;
if (Flag == 0) {
Flag = 1;
/* Create a new UDP control block */
upcb = udp_new();
} else {
u8_t (*pointers)[250]= &data;
for (int ctr7 = 0; ctr7<250; ctr7++)
{
*pointers[ctr7] = data[ctr7] = 0;
}
for (int ctr7 = 0; ctr7<250; ctr7++)
{
*pointers[ctr7] = data[ctr7] = DATAS[ctr7];
}
//sprintf((char*)data, ''YEHEY %s'', DATAS);
p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)*pointers), PBUF_POOL);
if (p != NULL) {
/* copy data to pbuf */
pbuf_take(p, (char*)*pointers, strlen((char*)data));
/* send udp data */
udp_send(upcb, p); 
/* free pbuf */
pbuf_free(p);
} 
//Flag=0;
return ; 
}
if (upcb!=NULL) {
/*assign destination IP address */
IP4_ADDR( &DestIPaddr, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3 );
/* configure destination IP address and port */
err= udp_connect(upcb, &DestIPaddr, UDP_SERVER_PORT);
if (err == ERR_OK) {
/* Set a receive callback for the upcb */
udp_recv(upcb, udp_receive_callback, NULL);
u8_t (*pointers)[250]= &data;
for (int ctr7 = 0; ctr7<250; ctr7++)
{
*pointers[ctr7] = data[ctr7] = 0;
}
for (int ctr7 = 0; ctr7<250; ctr7++)
{
*pointers[ctr7] = data[ctr7] = DATAS[ctr7];
}
//sprintf((char*)data, ''sending udp client message %d'', DATAS);
/* allocate pbuf from pool*/
p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)*pointers), PBUF_POOL);
if (p != NULL) {
/* copy data to pbuf */
pbuf_take(p, (char*)*pointers, strlen((char*)*pointers));
/* send udp data */
udp_send(upcb, p); 
/* free pbuf */
pbuf_free(p);
} else {
#ifdef SERIAL_DEBUG
printf(''\n\r can not allocate pbuf '');
#endif
}
} else {
#ifdef SERIAL_DEBUG
printf(''\n\r can not connect udp pcb'');
#endif
}
} else {
#ifdef SERIAL_DEBUG
printf(''\n\r can not create udp pcb'');
#endif
} 
}
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
Flag = 0;
/*increment message count */
message_count++;
/* Free receive pbuf */
pbuf_free(p);
/* free the UDP connection, so we can accept new clients */
udp_remove(upcb); 
}
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

0 REPLIES 0