예제 #1
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();
  }
}
예제 #2
0
/**
 * @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();
    }
  }
}