BLE Firmware

From Neuromeka Wiki
Jump to: navigation, search
BB-Air


PRE-DEFINE

  • Set Define Value
INT_HEAP_LEN=3072
HALNODEBUG
OSAL_CBTIMER_NUM_TASKS=1
HAL_AES_DMA=TRUE
HAL_DMA=TRUE
xPOWER_SAVING
xPLUS_BROADCASTER
HAL_LCD=FALSE
HAL_LED=FALSE
HAL_KEY=FALSE
HAL_UART=TRUE
HAL_UART_ISR=2
HAL_UART_DMA=0
MYHAL_UART_ISR=1
MYHAL_UART_DMA=0
_USE_SIMPLE_KEY_
MY_BBAIR
  • Explain the Pre-Define

- HAL_UART=TRUE : Enable UART
- HAL_UART_ISR=2 : UART Mode is ISR(UART1)
- MYHAL_UART_ISR=1 : MYUART Mode is ISR(UART0)
- MY_BBAIR : BLE used for BBAIR

  • How to set the Pre-Define

1) Click the 'Project-Option'
2) Click the 'C/C++ Compiler' on Category
3) Click the 'Preprocessor' on tab
00 1 BLE PreDefine.png

SOURCE

  • Init
    //UART
  halUARTCfg_t uart0_config;
  uart0_config.configured           = TRUE;
/*  uart0_config.flowControl          = TRUE;
  uart0_config.flowControlThreshold = 48;
  uart0_config.rx.maxBufSize        = 128;
  uart0_config.tx.maxBufSize        = 128;
  uart0_config.idleTimeout          = 6;
  uart0_config.intEnable            = TRUE;*/
  uart0_config.baudRate             = HAL_UART_BR_115200;  
  uart0_config.callBackFunc         = NULL;    
  
  UART0_ALt2_config(&uart0_config);
  UART0_print("Neuromeka-BLE(0) ");
  UART0_print(saved_blename);
  UART0_print("\r\n");
  
  halUARTCfg_t uart1_config;
  uart1_config.configured           = TRUE;
/*  uart0_config.flowControl          = TRUE;
  uart0_config.flowControlThreshold = 48;
  uart0_config.rx.maxBufSize        = 128;
  uart0_config.tx.maxBufSize        = 128;
  uart0_config.idleTimeout          = 6;
  uart0_config.intEnable            = TRUE;*/
  uart1_config.baudRate             = HAL_UART_BR_115200;  
  uart1_config.callBackFunc         = NULL;    
    
  UART1_ALt2_config(&uart1_config);
  UART1_print("Neuromeka-BLE(1) ");
  UART1_print(saved_blename);
  UART1_print("\r\n");
  • performPeriodicTask
static void performPeriodicTask( void )
{
  static uint32 periodic_loop_cnt=0;
  static uint8 ble_comm_busy=0;

  uint8 rx_buf[SK_KEYPRESSED_DATA_SIZE];
  int res;
  
  ble_comm_busy=0;
  res= 0;
  //read buffer sent from Android Application
  res=BLEReadISR(rx_buf, SK_KEYPRESSED_DATA_SIZE); 
  if (res>0)
  {
    ble_comm_busy=1;
    rx_buf[res]=0;
    
    UART0_print(rx_buf);
  }

  res= 0;
  //Read UART0 buffer which is sent by user chip
  res=MyHalUARTRead(HAL_UART_PORT_0, rx_buf, SK_KEYPRESSED_DATA_SIZE); 
  if (res >0)
  {
    SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 )*res, rx_buf);
    
    //AT Command
    if (!ble_comm_busy)
      AT_Search(rx_buf, res);
  }
  
  res= 0;
  //Read UART1 buffer which is sent by user chip
  res=HalUARTRead(HAL_UART_PORT_1, rx_buf, SK_KEYPRESSED_DATA_SIZE); 
  if ((res >0) && (rx_buf[0]>0) && (rx_buf[0]<128))
  {
    SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 )*res, rx_buf);
        
    //AT Command
    if (!ble_comm_busy)
      AT_Search(rx_buf, res);
  }
}
  • AT Command
void AT_CMD_Process(int len)
{
  char dis[10];
  
  if ( (strlen(at_cmd_str)>=4) && (at_cmd_str[3] == 0x0D) )
  {
    UART0_print("OK\r\n");
    UART1_print("OK\r\n");
  }
  else if (strncmp(&at_cmd_str[3], "INFO", 4)==0)
  {
    Print_MAC();
    osal_snv_read( ZCD_NV_BLE_NAME, NAME_MAX_LEN, saved_blename);
    Print_Name(saved_blename);
    osal_snv_read( ZCD_NV_BLE_BAUD, 1, &saved_blebaud);
    Print_Baud(saved_blebaud);
  }
  else if (strncmp(&at_cmd_str[3], "RESET", 5)==0)
  {
    UART0_print("\r\nRESET\r\n");
    UART1_print("\r\nRESET\r\n");
    HAL_SYSTEM_RESET();
  }
  else if (strncmp(&at_cmd_str[3], "NAME", 4)==0)
  {
    if(at_cmd_str[7] != 0x0d)
    {
      memset(saved_blename, 0, NAME_MAX_LEN);
      strncpy(saved_blename, &at_cmd_str[7], len-7);
      osal_snv_write(ZCD_NV_BLE_NAME, NAME_MAX_LEN, saved_blename);
    }
    osal_snv_read( ZCD_NV_BLE_NAME, 1, &saved_blename);
    Print_Name(saved_blename);
  }
  else if (strncmp(&at_cmd_str[3], "BAUD", 4)==0)
  {
    if(at_cmd_str[7] == 0x0d)
    {
      UART0_print("\r\n1:9600/2:19200/3:38400/4:57400/5:115200\r\n");
      UART1_print("\r\n1:9600/2:19200/3:38400/4:57400/5:115200\r\n");
    }
    else
    {
      uint8 temp_baud=at_cmd_str[7]-'0';
      my_itoa(temp_baud, dis);
      UART0_print(dis);
      UART1_print(dis);
      if ( (temp_baud>=BBA_UART_BR_9600) && (temp_baud<=BBA_UART_BR_115200))
      {
        saved_blebaud=temp_baud;
        osal_snv_write( ZCD_NV_BLE_BAUD, 1, &saved_blebaud);
      }
      else
      {
        UART0_print("\r\nInvalid baud\r\n");
        UART1_print("\r\nInvalid baud\r\n");
      }
    }
    osal_snv_read( ZCD_NV_BLE_BAUD, 1, &saved_blebaud);
    Print_Baud(saved_blebaud);
  }
}