Пример #1
0
Файл: h4.c Проект: 01org/zephyr
static inline void read_header(void)
{
	switch (rx.type) {
	case H4_NONE:
		h4_get_type();
		return;
	case H4_EVT:
		get_evt_hdr();
		break;
	case H4_ACL:
		get_acl_hdr();
		break;
	default:
		CODE_UNREACHABLE;
		return;
	}

	if (rx.have_hdr && rx.buf) {
		if (rx.remaining > net_buf_tailroom(rx.buf)) {
			BT_ERR("Not enough space in buffer");
			rx.discard = rx.remaining;
			reset_rx();
		} else {
			copy_hdr(rx.buf);
		}
	}
}
Пример #2
0
Файл: h4.c Проект: 01org/zephyr
static void rx_thread(void *p1, void *p2, void *p3)
{
	struct net_buf *buf;

	ARG_UNUSED(p1);
	ARG_UNUSED(p2);
	ARG_UNUSED(p3);

	BT_DBG("started");

	while (1) {
		BT_DBG("rx.buf %p", rx.buf);

		/* We can only do the allocation if we know the initial
		 * header, since Command Complete/Status events must use the
		 * original command buffer (if available).
		 */
		if (rx.have_hdr && !rx.buf) {
			rx.buf = get_rx(K_FOREVER);
			BT_DBG("Got rx.buf %p", rx.buf);
			if (rx.remaining > net_buf_tailroom(rx.buf)) {
				BT_ERR("Not enough space in buffer");
				rx.discard = rx.remaining;
				reset_rx();
			} else {
				copy_hdr(rx.buf);
			}
		}

		/* Let the ISR continue receiving new packets */
		uart_irq_rx_enable(h4_dev);

		buf = net_buf_get(&rx.fifo, K_FOREVER);
		do {
			uart_irq_rx_enable(h4_dev);

			BT_DBG("Calling bt_recv(%p)", buf);
			bt_recv(buf);

			/* Give other threads a chance to run if the ISR
			 * is receiving data so fast that rx.fifo never
			 * or very rarely goes empty.
			 */
			k_yield();

			uart_irq_rx_disable(h4_dev);
			buf = net_buf_get(&rx.fifo, K_NO_WAIT);
		} while (buf);
	}
}
Пример #3
0
main(int argc, char *argv[])
{
  FILE *fpin,*fpout;
  SEASAT_header_ext **hdr;
  int i, j, k, vals;
  int icnt = 0, ocnt = 0, curr = 0, optr = WINDOW_SIZE/2;
  int fcnt = 0, n=0;
 
  long int msec;
  double times[WINDOW_SIZE];
  double lines[WINDOW_SIZE];
  double a, b, c;
  double diff, save_diff, tmp;
  double pri;
  
  int offset=0, bad_cnt=0;

  if (argc!=3) {
    printf("Usage: %s <in_header_file> <out_cleaned_header_file>\n\n",argv[0]);
    printf("<in>\tName of input header file to clean");
    printf("<out>\tOutput name of cleaned header file");
    printf("\n\n");
    exit(1);
  }
  
  printf("\n\nDECODED SEASAT HEADER CLEANSING PROGRAM\n\n");
  printf("\topening files...\n");
  fpin=fopen(argv[1],"r");
  if (fpin==NULL) {printf("ERROR: Unable to open input file %s\n",argv[1]); exit(1);}
  fpout=fopen(argv[2],"w");
  if (fpout==NULL) {printf("ERROR: Unable to open output file %s\n",argv[2]); exit(1);}
  
  /* Allocate the array of headers */
  hdr = (SEASAT_header_ext **) malloc(sizeof(SEASAT_header_ext *)*WINDOW_SIZE);
  if (hdr == NULL) {printf("ERROR: unable to allocate hdr\n"); exit(1);}
  for (i=0; i<WINDOW_SIZE; i++)
    hdr[i] = (SEASAT_header_ext *) malloc(sizeof(SEASAT_header_ext));
  for (i=0; i<WINDOW_SIZE; i++)
    if (hdr[i]==NULL) {printf("Error in malloc\n"); exit(1);}

  vals = get_values(fpin,hdr[1]);
  if (vals != 20) {printf("ERROR: can't read from input file\n"); exit(1);}
  icnt++;

  pri = 1000* (1.0 / 1647.0);

  while (vals == 20) {
    if ((icnt%10000)==0) {printf("\tcleaning line %i\n",icnt);}

    copy_hdr(hdr[1],hdr[0]);
    fprintf(fpout,"%i %li %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i\n",
      hdr[1]->major_cnt,hdr[1]->major_sync_loc,hdr[1]->station_code,
      hdr[1]->lsd_year,hdr[1]->day_of_year,hdr[1]->msec,hdr[1]->clock_drift,
      hdr[1]->no_scan_indicator_bit,hdr[1]->bits_per_sample,hdr[1]->mfr_lock_bit,
      hdr[1]->prf_rate_code,hdr[1]->delay,hdr[1]->scu_bit,hdr[1]->sdf_bit,
      hdr[1]->adc_bit,hdr[1]->time_gate_bit,hdr[1]->local_prf_bit,hdr[1]->auto_prf_bit,
      hdr[1]->prf_lock_bit,hdr[1]->local_delay_bit);
    ocnt++;

    n = 1;
    vals = get_values(fpin,hdr[1]);
    if (vals==20) icnt++;
    
    while (vals==20 && hdr[1]->msec == hdr[0]->msec) {
       double offset = pri*(double)n;
       hdr[1]->msec = hdr[0]->msec + (int) offset;
       // printf("Fixing... was %li now %li offset %lf\n",hdr[0]->msec,hdr[1]->msec,offset);
       fprintf(fpout,"%i %li %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i\n",
         hdr[1]->major_cnt,hdr[1]->major_sync_loc,hdr[1]->station_code,
         hdr[1]->lsd_year,hdr[1]->day_of_year,hdr[1]->msec,hdr[1]->clock_drift,
         hdr[1]->no_scan_indicator_bit,hdr[1]->bits_per_sample,hdr[1]->mfr_lock_bit,
         hdr[1]->prf_rate_code,hdr[1]->delay,hdr[1]->scu_bit,hdr[1]->sdf_bit,
         hdr[1]->adc_bit,hdr[1]->time_gate_bit,hdr[1]->local_prf_bit,hdr[1]->auto_prf_bit,
         hdr[1]->prf_lock_bit,hdr[1]->local_delay_bit);
       ocnt++;
       n++;
       vals = get_values(fpin,hdr[1]);
       if (vals==20) icnt++;
       if ((int)offset>=1) fcnt++;
    }
  }
       
 /*
  fprintf(fpout,"%i %li %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i\n",
    hdr[1]->major_cnt,hdr[1]->major_sync_loc,hdr[1]->station_code,
    hdr[1]->lsd_year,hdr[1]->day_of_year,hdr[1]->msec,hdr[1]->clock_drift,
    hdr[1]->no_scan_indicator_bit,hdr[1]->bits_per_sample,hdr[1]->mfr_lock_bit,
    hdr[1]->prf_rate_code,hdr[1]->delay,hdr[1]->scu_bit,hdr[1]->sdf_bit,
    hdr[1]->adc_bit,hdr[1]->time_gate_bit,hdr[1]->local_prf_bit,hdr[1]->auto_prf_bit,
    hdr[1]->prf_lock_bit,hdr[1]->local_delay_bit);
  ocnt++;
  */
       
  if (icnt != ocnt) printf("ERROR: input/output don't match; read %i wrote %i\n",icnt,ocnt);
  else printf("\n\nDone with calculations - read and wrote %i lines; fixed %i time values (%f%%)\n\n",
  	icnt,fcnt, 100.0*(float)fcnt/(float)icnt);
  
  exit(0);
}
Пример #4
0
Файл: h4.c Проект: 01org/zephyr
static inline void read_payload(void)
{
	struct net_buf *buf;
	bool prio;
	int read;

	if (!rx.buf) {
		rx.buf = get_rx(K_NO_WAIT);
		if (!rx.buf) {
			if (rx.discardable) {
				BT_WARN("Discarding event 0x%02x", rx.evt.evt);
				rx.discard = rx.remaining;
				reset_rx();
				return;
			}

			BT_WARN("Failed to allocate, deferring to rx_thread");
			uart_irq_rx_disable(h4_dev);
			return;
		}

		BT_DBG("Allocated rx.buf %p", rx.buf);

		if (rx.remaining > net_buf_tailroom(rx.buf)) {
			BT_ERR("Not enough space in buffer");
			rx.discard = rx.remaining;
			reset_rx();
			return;
		}

		copy_hdr(rx.buf);
	}

	read = uart_fifo_read(h4_dev, net_buf_tail(rx.buf), rx.remaining);
	net_buf_add(rx.buf, read);
	rx.remaining -= read;

	BT_DBG("got %d bytes, remaining %u", read, rx.remaining);
	BT_DBG("Payload (len %u): %s", rx.buf->len,
	       bt_hex(rx.buf->data, rx.buf->len));

	if (rx.remaining) {
		return;
	}

	prio = (rx.type == H4_EVT && bt_hci_evt_is_prio(rx.evt.evt));

	buf = rx.buf;
	rx.buf = NULL;

	if (rx.type == H4_EVT) {
		bt_buf_set_type(buf, BT_BUF_EVT);
	} else {
		bt_buf_set_type(buf, BT_BUF_ACL_IN);
	}

	reset_rx();

	if (prio) {
		BT_DBG("Calling bt_recv_prio(%p)", buf);
		bt_recv_prio(buf);
	} else {
		BT_DBG("Putting buf %p to rx fifo", buf);
		net_buf_put(&rx.fifo, buf);
	}
}