Exemple #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();    
}
/**
 * @brief  EXTI line detection callback.
 * @param  uint16_t GPIO_Pin Specifies the pins connected EXTI line
 * @retval None
 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  tHciDataPacket * hciReadPacket = NULL;
  uint8_t data_len;
  /* 
   * No need to call Clear_SPI_EXTI_Flag() here as
   * HAL_GPIO_EXTI_IRQHandler() already does it
   */
  
  if(GPIO_Pin == BNRG_SPI_EXTI_PIN) {
    
    while (HAL_GPIO_ReadPin(BNRG_SPI_EXTI_PORT, BNRG_SPI_EXTI_PIN) == GPIO_PIN_SET) {
      
      uint8_t rx_buffer[255];
      uint8_t rx_bytes;
      
      /* Data are available from BlueNRG: read them through SPI */
      rx_bytes = BlueNRG_SPI_Read_All(&SpiHandle, rx_buffer, sizeof(rx_buffer)); 
      /* Check if there is data is so, send it to VCOM */
      if (rx_bytes > 0) {
        int i;
        for (i = 0; i < rx_bytes; i++) {
          PRINTF("0x%x, ", rx_buffer[i]);

          if(HAL_UART_Transmit(&UartHandle, (uint8_t*)&rx_buffer[i], 1, 300)!= HAL_OK) {
            Error_Handler();
          }
        }
        PRINTF("\n");
      }
      
      Clear_SPI_EXTI_Flag();
    }
  }
}
Exemple #3
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();
  }
}
Exemple #4
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;
  
  
}
Exemple #5
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;
}