Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Callback functions return where?

Posted by Çağlar Akyüz on September 24, 2006
I have task named X. I'm registering for a callback function in my task X and then start blocking on a queue Y. When a packet is recieved from MAC my registered callback function is called. Everything is ok up to this point.

But when I try to post to queue Y in this function I face some problems. I could not localize the problem because of these questions.

1) Can we say this callback function is running in the context task X? or it is running in the context of MAC task(namely lwip' tcp_ip_thread).
2) Where does this callback function returns?

Thanks...



RE: Callback functions return where?

Posted by Nobody/Anonymous on September 24, 2006
I don't understand your question - sorry.

A function will run in the context of the task from which it is called, if this helps.

RE: Callback functions return where?

Posted by Nobody/Anonymous on September 25, 2006
Yes, it helps a lot. Thanks for the reply.

But I could not solve it. Let me clarify my situtaion with my source code. I'm using Sam7x Web server demo. There is two tasks which I'm interested. task_debug_info and tcp_ip_thread. As it is seen in the code, task_debug_info start receiving from a queue. When data arrives from ethernet tcp_ip_thread calls a function named net_recv. And net_recv sends data to the queue. Problem is if I don't post to the queue in the net_recv, everything is ok. But,if I call QueueSend than ethernet comm becomes faulty( I think tcp_ip_thread).

Below is my source-code. Thanks
void task_debug_info( void *pvParameters )
{
//Task specific variables
debug_info dbg;

//Ethernet variables.
struct netconn *listen_pc, *conn_pc = NULL;

/* Parameters are not used - suppress compiler error. */
(void ) pvParameters;

//Create debugging queue
debug_mes_queue = xQueueCreate( DEBUGGING_QUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( debug_info ) );
if( debug_mes_queue == NULL )
task_state = 0;

/* Create a new tcp connection handle */
listen_pc = netconn_new( NETCONN_TCP );

netconn_bind( listen_pc, NULL, DEBUG_LISTENING_PORT );
netconn_listen( listen_pc );
for(;;) {
if(conn_pc == NULL) {
conn_pc = netconn_accept(listen_pc);
//register for callback
tcp_recv( conn_pc->pcb.tcp , net_recv );
} else {
/* Send debugging info. */
switch ( conn_pc->pcb.tcp->state ) {
case 0: //Connection is closed, wait for another.
conn_pc = NULL;
break;
case 4: //Connection is established, send.
if( xQueueReceive( debug_mes_queue, &dbg , DEBUG_BLOCK_TIME ) )
send_the_state( &dbg , conn_pc );
break;
}
}
}
}
err_t net_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
debug_info dbg;
if ( p != NULL ) {
//Post something to the queue
dbg.reg[0] = 48;
dbg.reg[1] = 49;
//Needed by the tcp_ip_thread
pbuf_free(p);
//This sending operation causes the problem
xQueueSend( debug_mes_queue , &dbg , 0 );
}
return err;
}

RE: Callback functions return where?

Posted by Nobody/Anonymous on September 25, 2006
Looks ok. Could it simply be a stack problem? Have you tried increasing the task stacks?

RE: Callback functions return where?

Posted by Çağlar Akyüz on September 25, 2006
First of all, thanks for reviewing my code.

Yes, you were right, it is somewhat related to the stack. I increased the stack size and imposed some other precautions.

Best regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists