Ejemplo n.º 1
0
/* USB (low priority) interrupt */
void usb_lp_isr(void)
{
	u16 mask;
	u16 status;
	int ep_id;
	u16 trans;

	/* Interrupt mask */
	mask = usbdevfs_get_interrupt_mask(USBDEVFS_CORRECT_TRANSFER |
					   USBDEVFS_ERROR | USBDEVFS_RESET |
					   USBDEVFS_SOF);
	if (!mask)
		return;

	/* Interrupt status */
	status = usbdevfs_get_interrupt_status(USBDEVFS_CORRECT_TRANSFER |
					       USBDEVFS_ERROR |
					       USBDEVFS_RESET |
					       USBDEVFS_SOF |
					       USBDEVFS_DIR | USBDEVFS_EP_ID);
	if (!(status & (USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR |
			USBDEVFS_RESET | USBDEVFS_SOF)))
		return;

	/* Start of frame */
	if (mask & status & USBDEVFS_SOF) {
		sof();
		/* Clear interrupt. */
		usbdevfs_clear_interrupt(USBDEVFS_SOF);
	}

	/* Correct transfer */
	if (mask & status & USBDEVFS_CORRECT_TRANSFER) {
		ep_id = status & USBDEVFS_EP_ID;
		trans = usbdevfs_get_ep_status(ep_id, USBDEVFS_RX |
					       USBDEVFS_TX | USBDEVFS_SETUP);

		/* Rx (OUT/SETUP transaction) */
		if ((status & USBDEVFS_DIR) && (trans & USBDEVFS_RX))
			rx_packet(ep_id, trans & USBDEVFS_SETUP);

		/* Tx (IN transaction) */
		if (!(status & USBDEVFS_DIR) && (trans & USBDEVFS_TX))
			tx_packet(ep_id);
	}

	/* Error */
	if (mask & status & USBDEVFS_ERROR) {
		usb_error++;
		/* Clear interrupt. */
		usbdevfs_clear_interrupt(USBDEVFS_ERROR);
	}

	/* USB RESET */
	if (mask & status & USBDEVFS_RESET) {
		usb_reset();
		/* Clear interrupt. */
		usbdevfs_clear_interrupt(USBDEVFS_RESET);
	}
}
Ejemplo n.º 2
0
void adapter_interrupt(struct sdio_func *func)
{
	struct net_adapter		*adapter = sdio_get_drvdata(func);
	int				intrd = 0;
	struct buffer_descriptor *bufdsc;

	wake_lock_timeout(&adapter->pdata->g_cfg->wimax_rxtx_lock, 0.2 * HZ);

	/* read interrupt identification register and clear the interrupt */
	intrd = sdio_readb(func, SDIO_INT_STATUS_REG, NULL);
	sdio_writeb(func, intrd, SDIO_INT_STATUS_CLR_REG, NULL);

	if (likely(intrd & SDIO_INT_DATA_READY)) {
		bufdsc = rx_packet(adapter);
		if (unlikely(!bufdsc))
			return;
		spin_lock(&adapter->recv_lock);
		list_add_tail(&bufdsc->list, &adapter->q_recv);
		spin_unlock(&adapter->recv_lock);
		schedule_work(&adapter->receive_work);
	} else if (unlikely(intrd & SDIO_INT_ERROR)) {
		adapter->netstats.rx_errors++;
		pr_err("%s intrd = SDIO_INT_ERROR occurred",
			__func__);
	}

}
Ejemplo n.º 3
0
void main(void) {
	volatile packet_t *p;
	volatile uint8_t t=20;
	uint8_t chan;
	char c;

	gpio_data(0);
	
	gpio_pad_dir_set( 1ULL << LED );
        /* read from the data register instead of the pad */
	/* this is needed because the led clamps the voltage low */
	gpio_data_sel( 1ULL << LED);

	/* trim the reference osc. to 24MHz */
	trim_xtal();

	uart_init(UART1, 115200);

	vreg_init();

	maca_init();

        /* sets up tx_on, should be a board specific item */
        *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
	gpio_pad_dir_set( 1ULL << 44 );

	set_power(0x0f); /* 0dbm */
	chan = 0;
	set_channel(chan); /* channel 11 */

	*MACA_MACPANID = 0xaaaa;
	*MACA_MAC16ADDR = 0x1111;
	*MACA_TXACKDELAY = 68; /* 68 puts the tx ack at about the correct spot */
	set_prm_mode(AUTOACK);

	print_welcome("rftest-rx");
	while(1) {		

		/* call check_maca() periodically --- this works around */
		/* a few lockup conditions */
		check_maca();

		if((p = rx_packet())) {
			/* print and free the packet */
			printf("autoack-rx --- ");
			print_packet(p);
			maca_free_packet(p);
		}

		if(uart1_can_get()) {
			c = uart1_getc();
			if(c == 'z') t++;
			if(c == 'x') t--;
			*MACA_TXACKDELAY = t;
			printf("tx ack delay: %d\n\r", t);
		}

	}
}
Ejemplo n.º 4
0
void main(void) {
	volatile packet_t *p;
	char c;
	uint16_t r=30; /* start reception 100us before ack should arrive */
	uint16_t end=180; /* 750 us receive window*/

	/* trim the reference osc. to 24MHz */
	trim_xtal();

	uart_init(UART1, 115200);

	vreg_init();

	maca_init();

	set_channel(0); /* channel 11 */
//	set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
//	set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
	set_power(0x12); /* 0x12 is the highest, not documented */

        /* sets up tx_on, should be a board specific item */
	GPIO->FUNC_SEL_44 = 1;	 
	GPIO->PAD_DIR_SET_44 = 1;	 

	GPIO->FUNC_SEL_45 = 2;	 
	GPIO->PAD_DIR_SET_45 = 1;	 

	*MACA_RXACKDELAY = r;
	
	printf("rx warmup: %d\n\r", (int)(*MACA_WARMUP & 0xfff));

	*MACA_RXEND = end;

	printf("rx end: %d\n\r", (int)(*MACA_RXEND & 0xfff));

	set_prm_mode(AUTOACK);

	print_welcome("rftest-tx");

	while(1) {		
	    		
		/* call check_maca() periodically --- this works around */
		/* a few lockup conditions */
		check_maca();

		while((p = rx_packet())) {
			if(p) {
				printf("RX: ");
				print_packet(p);
				free_packet(p);
			}
		}

		if(uart1_can_get()) {
			c = uart1_getc();

			switch(c) {
			case 'z':
				r++;
				if(r > 4095) { r = 0; }
				*MACA_RXACKDELAY = r;
				printf("rx ack delay: %d\n\r", r);
				break;
			case 'x':
				if(r == 0) { r = 4095; } else { r--; }
				*MACA_RXACKDELAY = r;
				printf("rx ack delay: %d\n\r", r);
				break;
			case 'q':
				end++;
				if(r > 4095) { r = 0; }
				*MACA_RXEND = end;
				printf("rx end: %d\n\r", end);
				break;
			case 'w':
				end--;
				if(r == 0) { r = 4095; } else { r--; }
				*MACA_RXEND = end;
				printf("rx end: %d\n\r", end);
				break;
			default:
				p = get_free_packet();
				if(p) {
					fill_packet(p);
					
					printf("autoack-tx --- ");
					print_packet(p);
					
					tx_packet(p);				
				}
				break;
			}
		}
		
	}

}
Ejemplo n.º 5
0
void main(void) {
  volatile packet_t *p;
#ifdef CARRIER_SENSE
  volatile uint32_t i;
#endif
  uint16_t r=30; /* start reception 100us before ack should arrive */
  uint16_t end=180; /* 750 us receive window*/

  /* trim the reference osc. to 24MHz */
  trim_xtal();
  uart_init(INC, MOD, SAMP);
  vreg_init();
  maca_init();

  ///* Setup the timer */
  *TMR_ENBL = 0;                     /* tmrs reset to enabled */
  *TMR0_SCTRL = 0;
  *TMR0_LOAD = 0;                    /* reload to zero */
  *TMR0_COMP_UP = 18750;             /* trigger a reload at the end */
  *TMR0_CMPLD1 = 18750;              /* compare 1 triggered reload level, 10HZ maybe? */
  *TMR0_CNTR = 0;                    /* reset count register */
  *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE);
  *TMR_ENBL = 0xf;                   /* enable all the timers --- why not? */

  set_channel(CHANNEL); /* channel 11 */
  set_power(0x12); /* 0x12 is the highest, not documented */

  /* sets up tx_on, should be a board specific item */
  GPIO->FUNC_SEL_44 = 1;	 
  GPIO->PAD_DIR_SET_44 = 1;	 
  GPIO->FUNC_SEL_45 = 2;	 
  GPIO->PAD_DIR_SET_45 = 1;	 
  *MACA_RXACKDELAY = r;
  *MACA_RXEND = end;

  set_prm_mode(AUTOACK);

  while(1) {		

    if((*TMR0_SCTRL >> 15) != 0) 
      tick();

    /* call check_maca() periodically --- this works around */
    /* a few lockup conditions */
    check_maca();

    while((p = rx_packet())) {
      if(p) free_packet(p);
    }

    p = get_free_packet();
    if(p) {
      fill_packet(p);

#ifdef CARRIER_SENSE
      for(i=0; i<POWER_DELAY; i++) {continue;}
      while(get_power()>74) {}
#endif

#ifdef BLOCKING_TX
      blocking_tx_packet(p);
#else
      tx_packet(p);
#endif

      current_pkts++;

#if defined(RANDOM_WAIT_TIME) || defined(FIXED_WAIT)
      random_wait();
#endif
    }
  }
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {
//rcpDebugEnable();
	
	// initialize shared memory
	rcp_init(RCP_PROC_DNS);

	RcpPkt *pkt;
	pkt = malloc(sizeof(RcpPkt) + RCP_PKT_DATA_LEN);
	if (pkt == NULL) {
		fprintf(stderr, "Error: process %s, cannot allocate memory, exiting...\n", rcpGetProcName());
		exit(1);
	}



	struct stat s;
	if (stat("/opt/rcp/var/log/dnsproxy_at_startup", &s) == 0)
		proxy_disabled = 1;


	// open sockets if necessary
	if (shm->config.dns_server) {
		if (proxy_disabled) {		
			rcpLog(muxsock, RCP_PROC_DNS, RLOG_WARNING, RLOG_FC_DNS,
				"an external DNS proxy is already running on the system, RCP DNS proxy will be disabled");
		}
		else {
			client_sock = rx_open(DNS_SERVER_PORT); // the socket open to clients listens on the server socket
	
			if (client_sock == 0) {
				fprintf(stderr, "Error: process %s, cannot open sockets, exiting...\n", rcpGetProcName());
				exit(1);
			}
		}
	}
	
	// set the static cache entries
	cache_update_static();
	
	
	// drop privileges
	rcpDropPriv();
	
	// initialize request list
	rq_list_init();
	
	// receive loop
	int reconnect_timer = 0;
	struct timeval ts;
	ts.tv_sec = 1; // 1 second
	ts.tv_usec = 0;

	// use this timer to speed up rx loop when the system is busy
	uint32_t rcptic = rcpTic();

	while (1) {
		// reconnect mux socket if connection failed
		if (reconnect_timer >= 10) {
			// a regular reconnect will fail, this process runs with dropped privileges
			// end the process and restart it again
			break;
		}

		// set descriptors
		fd_set fds;
		FD_ZERO(&fds);
		int maxfd = 0;
		if (muxsock != 0) {
			FD_SET(muxsock, &fds);
			maxfd = (muxsock > maxfd)? muxsock: maxfd;
		}
		if (client_sock != 0) {
			FD_SET(client_sock, &fds);
			maxfd = (client_sock > maxfd)? client_sock: maxfd;
		}
		
		// set all server sockets
		DnsReq *rq = rq_active();
		while (rq) {
			if (rq->sock != 0) {
				FD_SET(rq->sock, &fds);
				maxfd = (rq->sock > maxfd)? rq->sock: maxfd;
			}

			rq = rq->next;
		}

		// wait for data
		errno = 0;
		int nready = select(maxfd + 1, &fds, (fd_set *) 0, (fd_set *) 0, &ts);
		if (nready < 0) {
			fprintf(stderr, "Error: process %s, select nready %d, errno %d\n",
				rcpGetProcName(), nready, errno);
		}
		else if (nready == 0) {
			// watchdog
			pstats->wproc++;

			// muxsocket reconnect timeout
			if (reconnect_timer > 0)
				reconnect_timer++;
			
			// age cache entries
			cache_timer();
			
			// age request queue entries
			rq_timer();
			
			// reset rate-limit counter
			rate_limit = 0;
			
			// reload ts
			rcptic++;
			if (rcpTic() > rcptic) {
				// speed up the clock
				ts.tv_sec = 0;
				ts.tv_usec = 800000;	// 0.8 seconds
				pstats->select_speedup++;
			}
			else {
				ts.tv_sec = 1; // 1 second
				ts.tv_usec = 0;
			}
		}
		// cli data
		else if (muxsock != 0 && FD_ISSET(muxsock, &fds)) {
			errno = 0;
			int nread = recv(muxsock, pkt, sizeof(RcpPkt), 0);
			if(nread < sizeof(RcpPkt) || errno != 0) {
//				fprintf(stderr, "Error: process %s, muxsocket nread %d, errno %d, disconnecting...\n",
//					rcpGetProcName(), nread, errno);
				close(muxsock);
				reconnect_timer = 1;
				muxsock = 0;
				continue;
			}
			// read the packet data
			if (pkt->data_len != 0) {
				nread += recv(muxsock, (unsigned char *) pkt + sizeof(RcpPkt), pkt->data_len, 0);
			}
			ASSERT(nread == sizeof(RcpPkt) + pkt->data_len);

			// process the cli packet
			if (pkt->type == RCP_PKT_TYPE_CLI && pkt->destination == RCP_PROC_DNS) {
				processCli(pkt);
				// forward the packet back to rcp
				send(muxsock, pkt, sizeof(RcpPkt) + pkt->data_len, 0);
			}
			// dns updates packet
			else if (pkt->type == RCP_PKT_TYPE_UPDATEDNS) {
				rcpLog(muxsock, RCP_PROC_DNS, RLOG_DEBUG, RLOG_FC_IPC,
					"processing DNS updates packet");
				cache_update_static();
			}
			
			else
				ASSERT(0);
			
			
		}
		// DNS packets from clients
		else if (client_sock != 0 && FD_ISSET(client_sock, &fds)) {
			rx_packet(client_sock);
		}
		// DNS packets from servers
		else {
			DnsReq *rq = rq_active();
			while (rq) {
				if (rq->sock != 0 && FD_ISSET(rq->sock, &fds)) {
					rx_packet(rq->sock);
					break;
				}
				rq = rq->next;
			}
		}

		if (force_restart) {
			rcpLog(muxsock, RCP_PROC_DNS, RLOG_NOTICE, RLOG_FC_IPC,
				"process %s exiting for configuration purposes", rcpGetProcName());
			if (pstats->wmonitor != 0)
				pstats->wproc = pstats->wmonitor;	// tigger a restart in the next monitoring cycle
			pstats->no_logging = 1;
			break; // exit from while(1)
		}
		
		if (force_shutdown)
			break;

	}
	
	fflush(0);
	sleep(1);
	
	// close sockets
	if (muxsock != 0) {
		close(muxsock);
	}
	if (client_sock != 0) {
		close(client_sock);
	}
	
	// remove cli memory
	cliRemoveFunctions();

	// clear request memory
	rq_clear_inactive();
	// remove cache memory	
	cache_clear();
	
	// remove packet memory
	if (pkt)
		free(pkt);
	
	return 0;
}