This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

malloc problem during ISR

Hi;

I have a ISR that used to collect data from the SCI interface RX data; my ISR should collect packet of data, and if it a valid one, allocate a memory for the packet, so the "main" can parse the incoming the data and then free the memory….

The problem is that when the first time the ISR is running it really allocates the memory space, but in the second time malloc return NULL pointer.

Firstly I thought that I don’t have enough space in the heap, so I resize it to 0x800, but did doesn't solve my problem…

So what do you think? What seems to be the thing I do thaw wrong way?

 

P.S:

A part of my code:

interrupt void SciaRxIsr(void)

{

  volatile RxPacket *rx_packet;

  Uint16    rx_byte;

 

  static char rx_buffer[MAX_PACKET_SIZE];

  static int  rx_buffer_index = 0;

  static Rx_Fsm fsm_curr_state = Wait_For_Stx_State;

 

  rx_byte = SciaRegs.SCIRXBUF.bit.RXDT;

  // if no frame error occurred and no parity error occurred

  if((SciaRegs.SCIRXBUF.bit.SCIFFFE & SciaRegs.SCIRXBUF.bit.SCIFFPE) == 0)

  {

    // Verifying ETX at the end of the packet

    case Wait_For_Etx_State:

    {

        if(rx_byte == ETX) // Read ETX                                                         

        {

          //add rx buffer to linked list

          rx_packet = (RxPacket*)malloc(sizeof(RxPacket));

          if(rx_packet == NULL)

          {   

                // Node creation failed

                fsm_curr_state = Wait_For_Stx_State;

          }

          else

          {

                // Allocate space for the command data

                rx_packet->command_data = (char*)malloc(sizeof(rx_buffer[0]));

                if(rx_packet->command_data == NULL)

                {

                  // Node creation failed

                  fsm_curr_state = Wait_For_Stx_State;

                }

        }

        SciaRegs.SCIFFRX.bit.RXFFOVRCLR =  1;               // Clear Overflow flag

        SciaRegs.SCIFFRX.bit.RXFFINTCLR =  1;       // Clear Interrupt flag

        PieCtrlRegs.PIEACK.all          |= 0x100;   // Issue PIE ack

}