Beispiel #1
0
void HCI_Process(void)
{
  uint8_t data_len;
  uint8_t buffer[HCI_READ_PACKET_SIZE];
  tHciDataPacket * hciReadPacket = NULL;
  
  Disable_SPI_IRQ();
  uint8_t list_empty = list_is_empty(&hciReadPktRxQueue);        
  /* process any pending events read */
  while(list_empty == FALSE)
  {
    list_remove_head (&hciReadPktRxQueue, (tListNode **)&hciReadPacket);
    Enable_SPI_IRQ();
    HCI_Event_CB(hciReadPacket->dataBuff);
    Disable_SPI_IRQ();
    list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket);
    list_empty = list_is_empty(&hciReadPktRxQueue);
  }
  if (readPacketListFull) {
    while(BlueNRG_DataPresent()) {
      data_len = BlueNRG_SPI_Read_All(&SpiHandle, buffer, HCI_READ_PACKET_SIZE);
      if(data_len > 0)
        HCI_Event_CB(buffer);
    }
    readPacketListFull = FALSE;
  }
  
  Enable_SPI_IRQ();    
}
Beispiel #2
0
void HCI_Isr(void)
{
  tHciDataPacket * hciReadPacket = NULL;
  uint8_t data_len;
    
  Clear_SPI_EXTI_Flag();
  while(BlueNRG_DataPresent()){        
    if (list_is_empty (&hciReadPktPool) == FALSE){
            
      /* enqueueing a packet for read */
      list_remove_head (&hciReadPktPool, (tListNode **)&hciReadPacket);
            
      data_len = BlueNRG_SPI_Read_All(&SpiHandle, hciReadPacket->dataBuff, HCI_PACKET_SIZE);
      if(data_len > 0){                    
	HCI_Input(hciReadPacket);
	// Packet will be inserted to te correct queue by 
      }
      else {
	// Insert the packet back into the pool.
	list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket);
      }
            
    }
    else{
      // HCI Read Packet Pool is empty, wait for a free packet.
      readPacketListFull = TRUE;
      Clear_SPI_EXTI_Flag();
      return;
    }
        
    Clear_SPI_EXTI_Flag();
  }
}
Beispiel #3
0
void HCI_Isr(void)
{
  tHciDataPacket * hciReadPacket = NULL;
  uint8_t data_len,i=0;
  uint8_t retries = 0;
  
  while(BlueNRG_DataPresent())
  {        
    if (list_is_empty (&hciReadPktPool) == FALSE){//check if we have free hci read packets
      
      /* enqueueing a packet for read */
      list_remove_head (&hciReadPktPool, (tListNode **)&hciReadPacket);
      
      data_len = BlueNRG_SPI_Read_All(hciReadPacket->dataBuff,HCI_READ_PACKET_SIZE);
      
      if(data_len > 0){   
        
        retries = 0;
        
        hciReadPacket->data_len = data_len;
        
        if(HCI_verify(hciReadPacket) == 0)
          list_insert_tail(&hciReadPktRxQueue, (tListNode *)hciReadPacket);
        else
          list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket);

        i++;
        if( i > HCI_READ_PACKET_NUM_MAX)
        {
            goto error;
        }
      }
      else 
      {
        // Insert the packet back into the pool.
        list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket);
        
        retries++; //Device was busy or did not respond correctly
        
        if(retries > 10)
        {    
            goto error;
        }
      }
    }
    else{
      // HCI Read Packet Pool is empty, wait for a free packet.
      readPacketListFull = TRUE;
      return;
    }

  }
  return;
  error:
  ISRDevice_busy = TRUE;
  return;
  
  
}
Beispiel #4
0
int HCI_Process(void)
{
  uint8_t data_len;
  
  tHciDataPacket * hciReadPacket = NULL;
  uint8_t retries = 0;
  
  uint8_t list_empty = list_is_empty(&hciReadPktRxQueue);        
  /* process any pending events read */
  //events are added to tail in ISR
  while(list_empty == FALSE)
  {
    list_remove_head (&hciReadPktRxQueue, (tListNode **)&hciReadPacket);
 
    HCI_Event_CB(hciReadPacket->dataBuff);
    
    list_insert_tail(&hciReadPktPool, (tListNode *)hciReadPacket);
    
    list_empty = list_is_empty(&hciReadPktRxQueue); 
  }
  

    if (readPacketListFull)  //readPacketListFull is set in interrupt context
    {
        while(BlueNRG_DataPresent()) 
        {
            __debug_hci("Data too fast"); 
            
            data_len = BlueNRG_SPI_Read_All(HCI_Process_buffer, HCI_READ_PACKET_SIZE);
      
            if(data_len > 0)
            {
                HCI_Event_CB(hciReadPacket->dataBuff);
    
                retries = 0;
            }
            else
            {
                retries++;
                if(retries > 1)
                {
                    return -1;
                    break;
                }
                
            }
        }
        readPacketListFull = FALSE; //check if we ever get here
    }
    if(ISRDevice_busy == TRUE)
    {
        ISRDevice_busy = FALSE;
        return -2;
    }
    return 1;
}