Exemplo n.º 1
0
void BTClientTasks(void)
{
	BYTE deviceStatus;

	// Make sure we�fre in an initialized state.
	if (btClientData.Initialized != TRUE)
		return;

	// Check device status.
	deviceStatus= USBHostDeviceStatus(deviceAddress);

	// Make sure our device hasn�ft been disconnected.
	if ( deviceStatus != USB_DEVICE_ATTACHED )
	{
		btClientData.Initialized = FALSE;
		btClientData.State = BT_STATE_IDLE;
		return;
	}

	// Perform state-specific tasks.
	switch (btClientData.State)
	{
		case BT_INITIALIZE:
			bt_init();
			tcount = 0;
			btClientData.State = BT_STATE_IDLE;
		break;
		case BT_STATE_IDLE:
	        if (!USBHostGenericRx1IsBusy(deviceAddress) )
			{
				USBHostGenericRead1(deviceAddress,buf1,DATA_PACKET_LENGTH);
			}
	        if (!USBHostGenericRx2IsBusy(deviceAddress) )
			{
				USBHostGenericRead2(deviceAddress,buf2,DATA_PACKET_LENGTH);
			}
		break;
		case BT_STATE_PROCESS:

		break;

		default:// invalid state!
		btClientData.State = BT_STATE_IDLE;
		break;
	}
	if(tcount > 1000)
	{
		l2cap_tmr();
		rfcomm_tmr();
		bt_spp_tmr();
		tcount = 0;
	}
	tcount++;
}
Exemplo n.º 2
0
/*-----------------------------------------------------------------------------------*/
void 
maintask(void)
{
  struct phybusif_cb *cb;
  CLKBLK ks_clk *tmr;
  u8_t bt_timer = 0;
  u16_t http_timer = 0;
  u16_t dma0bsz = TCR0+1; /* DMA 0 Buf size */
  u8_t bt_ip_timer = 0;

  mem_init();
  memp_init();
  pbuf_init(); 
  netif_init();
  ip_init();
  tcp_init();
  sio_print("TCP/IP initialized.\n");
  
  lwbt_memp_init();
  phybusif_init();
  if(hci_init() != ERR_OK) {
    sio_print("HCI initialization failed!");
  }
  l2cap_init();
  sdp_init();
  rfcomm_init();
  ppp_init();
  
  sio_print("Bluetooth initialized.\n");

  httpd_init();
  sio_print("Applications started.\n");

  cb = mem_malloc(sizeof(struct phybusif_cb));
  cb->dmabuf = get_dm0ichars();
  phybusif_reset(cb);
  
  tmr = KS_alloc_timer();
  if(tmr == 0) {
    sio_print("tmr==0!\n");
  }
  KS_start_timer(tmr, (TICKS)0, (TICKS)100/CLKTICK, TIMERSEM); /* TCP timer ticks every 100ms */

  /* Reset Bluetooth module */
  PD7.0 = 1; /* Enable output */
  sio_print("Reseting BT module\n");
  P7.0 = 1; /* Stop reset */
  
  KS_delay(SELFTASK,(TICKS)4000/CLKTICK); /* Wait for bluetooth module to init */

  /* Control application initialisation */
  bt_ip_start();

  while(1) {
    dma_input(cb, dma0bsz); /* Check for input */

    /* Handle timers */
    if(KS_inqsema(TIMERSEM) == SEMA_DONE) {
      KS_wait(TIMERSEM);
      tcp_tmr();
      ++bt_timer;
      if(bt_timer == 10) {
        l2cap_tmr();
        rfcomm_tmr();
        ppp_tmr();
        bt_timer = 0;
        ++bt_ip_timer;
        if(bt_ip_timer == 240) {
          bt_ip_tmr();
          bt_ip_timer = 0;
        } 
      }
      
    }
  }
}
Exemplo n.º 3
0
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  struct phybusif_cb *cb;
  struct timeval tcptv, bttv, now;
  struct timezone tz;
  u8_t btiptmr = 0;
  
#ifdef PERF
  perf_init("/tmp/minimal.perf");
#endif /* PERF */
#ifdef STATS
  stats_init();
#endif /* STATS */

  mem_init();
  memp_init();
  pbuf_init(); 
  netif_init();
  ip_init();
  //udp_init();
  tcp_init();
  printf("TCP/IP initialized.\n");
  lwbt_memp_init();
  phybusif_init();
  if(hci_init() != ERR_OK) {
    printf("HCI initialization failed!");
    exit(-1);
  }
  l2cap_init();
  sdp_init();
  rfcomm_init();
  ppp_init();
  printf("Bluetooth initialized.\n");

  //echo_init();
  httpd_init();
  printf("Applications started.\n");

  cb = malloc(sizeof(struct phybusif_cb));
  phybusif_reset(cb);

  gettimeofday(&bttv, &tz); /* Initialize Bluetooth timer (1s) */
  gettimeofday(&tcptv, &tz); /* Initialize TCP timer (TCP_TMR_INTERVAL) */

  /* Host controller initialization for DTs according to LAN access point (LAP) and dial up networking (DUN) profile */
  bt_ip_start(NULL);

  while(1) {
    phybusif_input(cb); /* Check for input */

    gettimeofday(&now, &tz); /* Get current time */

    /* Check if TCP timer  should be called */
    if((now.tv_sec - tcptv.tv_sec) * 1000000 + (now.tv_usec - tcptv.tv_usec) >= TCP_TMR_INTERVAL * 1000) {
      gettimeofday(&tcptv, &tz); /* Reset TCP timer */
      tcp_tmr();
    }

    /* Check if Bluetooth and NAT timers should be called */ 
    if((now.tv_sec - bttv.tv_sec) * 1000000 + (now.tv_usec - bttv.tv_usec) >= 1000000) {
      gettimeofday(&bttv, &tz); /* Restart Bluetooth timer */
      l2cap_tmr();
      rfcomm_tmr();
      ppp_tmr();
      nat_tmr();
      if(++btiptmr == 240) { /* Akes server special */
	bt_ip_tmr();
	btiptmr = 0;
      }
    }
  }
  
  return 0;
}