Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

TSE MAC and SGDMA

Altera_Forum
Honored Contributor II
1,634 Views

Hi there, 

 

I am using TSE MAC and SGDMA to capture a network frame,i am facing a issue related to receive frame. 

Let me first clear my receive flow. 

1)open the SGDMA by "alt_avalon_sgdma_open". 

2)Allocating Rx_descriptor table space from main memory(onchip memory) using malloc. 

3)Build a receive descriptor to and allocate buffer for that. 

4) Register the ISRs that will get called when each (full) transfer completes  

5)Starting receive transfers 

6)Blocking until the SGDMA interrupts fire 

7)Verify the returned data and free up the data buffers 

 

in the last step i compare my frame with my expected frame,if this frame is not matched then it return_code 1. 

if i found return_code 1 then build new descriptor using goto statement as you can see in the attached file. 

But when i jump to top and reallocate rx_descriptor table i found "Allocating the descriptor memory failed... exiting" error message in NIOS II console. 

i simply want to do compare and re build the descriptor if frame is not valid.  

 

i don't know whats going wrong,please help me. 

 

Thanks & Regards, 

Hitesh
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
662 Views

It would help to show your allocation functions too

0 Kudos
Altera_Forum
Honored Contributor II
662 Views

temp_ptr_rx = malloc((number_of_buffers + 2) * ALTERA_AVALON_SGDMA_DESCRIPTOR_SIZE); 

if(temp_ptr_rx == NULL) 

printf("Failed to allocate memory for the receive descriptors\n"); 

return 1;  

*receive_descriptors_copy = (alt_sgdma_descriptor *)temp_ptr_rx; 

 

this is the simple code to allocate memory for descriptor
0 Kudos
Altera_Forum
Honored Contributor II
662 Views

Do you free your data buffers too before going back up in the loop? (by the way a for or a while loop would be more elegant C than "goto repeat")

0 Kudos
Altera_Forum
Honored Contributor II
662 Views

Thanks, 

 

I think i am free the allocated buffer as shown below, 

 

do 

 

 

printf("Starting up the SGDMA Receive engines\n"); 

 

 

if(alt_avalon_sgdma_do_async_transfer(receive_DMA, &receive_descriptors[0]) != 0) 

printf("Writing the head of the receive descriptor list to the DMA failed\n"); 

return 1; 

 

 

/************************************************************** 

* Blocking until the SGDMA interrupts fire * 

************************************************************/ 

 

while(rx_done == 0) {} 

printf("The receive SGDMA has completed\n"); 

 

 

/************************************************************** 

* Verify the returned data and free up the data buffers * 

************************************************************/ 

success_code = validate_results_rx(receive_descriptors, 

NUMBER_OF_BUFFERS  

); 

 

printf("validate_result_rx_success_code %d\n",success_code); //0 for valid frame and 1 for other frame which i don't want.  

 

if(success_code == 1) 

/* Make sure SGDMA controller is not busy from a former command */ //In short we chech ready busy flag over here. 

while ((IORD_ALTERA_AVALON_SGDMA_STATUS(SGDMA_ST_TO_MM_BASE) & ALTERA_AVALON_SGDMA_STATUS_BUSY_MSK)) 

{ } 

 

printf("Its time to check another frame :) \n"); 

 

 

free(receive_descriptors_copy);//here i free my aloocated buffer 

 

else 

 

printf("You catch the correct frame\n"); 

}  

 

} while(success_code==1);
0 Kudos
Altera_Forum
Honored Contributor II
662 Views

I was thinking about the data. Apparently, according to your comments, create_test_data_rx() is allocating memory buffers and validate_results_rx() is freeing them. Are you sure this part is working correctly too?

0 Kudos
Altera_Forum
Honored Contributor II
662 Views

Hi Daixiwen, 

 

 

This is my simple code to create a descriptor chain,is there any mistake or i lacking in some setting to capture valid frame. 

please suggest me.  

 

Thanks,
0 Kudos
Altera_Forum
Honored Contributor II
662 Views

I didn't check in details, but the principle seems right. Are you still encountering any problems? 

The only strange thing I found was this/* Done with these, time to clean up after ourselves. */ printf("***********match_count %d\n",match_count); // free(receive_ptr_rx); why did you comment the free() call here? It should be the right place to do so, inside the for loop. If you put that line with the other free() calls at the end of your function you will only free the last buffer and not the first ones, and you'll have a memory leak.
0 Kudos
Reply