예제 #1
0
파일: main.c 프로젝트: EFraim/trans-vpn
int main(int argc, char *argv[])
{
    initPLL();
    initGPIO();
    vicInit();
    uart0Init(CLOCKS_PCLK, UART0_BAUD_RATE);
    boot_mode_t bootMode = selectBootMode();
    bootMode == APP_CON ? led_on(ADMIN_LED) : led_off(ADMIN_LED);
    
    LOG_INFO("Initializing USB Stack");
    usbUserDriver = bootMode == APP_NET ? usbNetDriver : usbConDriver;
    usbInit();
    
    if(bootMode == APP_NET) {
      LOG_INFO("Initializing Ethernet stack");
      enc28j60_init(&IODIR, &IOPIN, MACAddress);
    
      // Print MAC address
      enc28j60_get_mac_address((uint8_t*)MACAddress);
      LOG_INFO("MAC address: %X-%X-%X-%X-%X-%X\n", MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]);
    }
      
    LOG_INFO("Starting USB Stack");
    interruptsEnable();
    
    usbConnect();
    
    LOG_INFO("Entering main loop");
    
    bootMode == APP_NET ? appnet_loop() : appcon_loop();
    
    return 0;
}
예제 #2
0
파일: usb-eth.c 프로젝트: EFraim/trans-vpn
int main(int argc, char *argv[])
{
  uint16_t eth_hdr_type;
  int i;

  SCS      = BIT0 | BIT1;   /* use fast I/O registers    */

  VPBDIV = 0x00000001;  /* PCLK = CCLK */
  PLLCFG  = 0x00000024; /* Fosc=12MHz, CCLK=60MHz */
  PLLCON  = 0x00000001; /* enable the PLL  */
  PLLFEED = 0x000000AA; /* feed sequence   */
  PLLFEED = 0x00000055;
  while (!(PLLSTAT & 0x00000400));
  PLLCON = 3;     // enable and connect
  PLLFEED = 0xAA;
  PLLFEED = 0x55;

  //busywaitInit();
  //systickInit();
  //lcdInit();

  vicInit();
  uart0Init();

  DBG("Initializing USB Stack");
  usbInit();

  rndisInit();
  DBG("init 2");
  network_device_init();

  DBG("init 3");
  uip_init();

  /*
  ipaddr_set = 1;
  uip_ipaddr(ipaddr, 192, 168, 12, 1);
  uip_ipaddr(dhcpd_client_ipaddr, 192, 168, 12, 2);
  uip_sethostaddr(ipaddr);
*/
  uip_setethaddr(ethaddr);

  //uip_setethaddr(eaddr);

  //telnetd_init();

  //net_timers_init();

#ifdef USE_DHCPD
  dhcpdInit();
#endif


  DBG("Starting USB Stack");
  interruptsEnable();
  usbConnect();

  //lcdOn();
  //lcdClear();

  //int xyz = 0;
  //printf("Frame number %u ",usbFrameNumber());

  while(1) {
    //if (xyz) DBG("is there a packet? bulk ep status = %x",_usbGetEPStatus(RNDIS_BULK_EP | USB_EP_OUT));
    uip_len = network_device_read();
    //if (xyz) DBG("len=%d",uip_len);
    if (uip_len > 0) {
      eth_hdr_type = (uip_buf[0xc] << 8) | uip_buf[0xd];
      if(eth_hdr_type == UIP_ETHTYPE_IP) {
        //DBG("Hey, got an IP packet!!!");
        uip_arp_ipin();
        uip_input();
        if(uip_len > 0) {
          uip_arp_out();
          //DBG("IP Reply! (%d bytes)",uip_len);
          //int j;
          //for (j=0; j<uip_len; j++) {
          //  DBG(">%d %02x ",j,uip_buf[j]);
          //}
          //DBG("");
          network_device_send();
        }
      }
      else if (eth_hdr_type == UIP_ETHTYPE_ARP) {
        //DBG("Hey, got an ARP packet!!!");
        uip_arp_arpin();
        //xyz = 1;
        if(uip_len > 0) {
          //DBG("ARP Reply!");
          network_device_send();
        }
      } else {
        DBG("Hey, got some weird packet, not IP, not ARP, type=%x",eth_hdr_type);
      }

    }

    /*
     * we reply to DHCP requests on another connection, and the connection
     * is faster if we don't wait for expiration of the timer.
     * I tried to call uip_udp_periodic_conn(dhcpd_reply_conn) instead of
     * the loop, but it did not work.
     */
    //if (dhcpd_state != DHCPD_IDLE) {
    if (udp_poll_request) {
      udp_poll_request = 0;
      for(i = 0; i < UIP_UDP_CONNS; i++) {
        uip_udp_periodic(i);
        if(uip_len > 0) {
          uip_arp_out();
          network_device_send();
        }
      }
      //uip_udp_periodic_conn(dhcpd_reply_conn);
    }

    if (net_timers_ip_expired()) {
      net_timers_ip_reset();

      for(i = 0; i < UIP_CONNS; i++) {
        uip_periodic(i);
        if(uip_len > 0) {
          uip_arp_out();
          network_device_send();
        }
      }
#define USE_UDP_PERIODIC
#ifdef USE_UDP_PERIODIC
      for(i = 0; i < UIP_UDP_CONNS; i++) {
        uip_udp_periodic(i);
        if(uip_len > 0) {
          uip_arp_out();
          network_device_send();
        }
      }
#endif
      if(net_timers_arp_expired()) {
        net_timers_arp_reset();
        uip_arp_timer();
      }
    }
  }
  return 0;
}
예제 #3
0
파일: bsp.c 프로젝트: dweb-x/CaseAlarm
void lowLevelInit() {
  mamInit();
  clockInit();
  gpioInit();
  vicInit();
}
int main(void) {
  int c;

  char buff[100];
  int offset = 0;
  int started = 0;
	
  //ctc_clocksInit(12000000,60000000,1);
  //ctc_mamInit(MAM_FULLY_ENABLED);
  //ramvectorsInit();
  //busywaitInit();
  
  VPBDIV = 0x00000001;  /* PCLK = CCLK */
  PLLCFG  = 0x00000024; /* Fosc=12MHz, CCLK=60MHz */
  PLLCON  = 0x00000001; /* enable the PLL  */
  PLLFEED = 0x000000AA; /* feed sequence   */
  PLLFEED = 0x00000055;
  while (!(PLLSTAT & 0x00000400));
  PLLCON = 3;     // enable and connect
  PLLFEED = 0xAA;
  PLLFEED = 0x55;
  
  vicInit();
  uart0Init();
  
  DBG("Initializing USB stack\n");

  usbInit();

  vcomInit();
  
  DBG("Starting USB communication\n");

  interruptsEnable();
  
  usbConnect();

  lcdInit();

  // echo any character received (do USB stuff in interrupt)
  while (1) {
	  c = vcomGetchar(); 
	  if (c != -1) {
		  // show on console
		  if ((c == 9) || (c == 10) || (c == 13) || ((c >= 32) && (c <= 126))) {
			  uint8_t buf[2]; 
			  buf[0] = c; buf[1] = 0;
			  DBG((char*) buf);
		  } else {
			  DBG(".");
		  }
		  vcomPutchar(c);

		  if (c == 13) {
			  DBG("Cmd entered.\n");
			  buff[offset] = '\0';
			  offset = 0;
			  if (!strcmp(buff, "start"))
			  {
				started = 1;
   			  }
			  else if (started) {
				  if (!strcmp(buff, "bl-on"))
				  {
					  lcd_backlight_on();
				  }
				  else if (!strcmp(buff, "bl-off"))
				  {
					  lcd_backlight_off();
				  }
				  else if (!strcmp(buff, "clear"))
				  {
					  lcdClear();						  
				  }
				  else {
					  lcdPrintString(buff);
				  }
			  }
		  }
		  else {
			  buff[offset++] = c;
		  }
	  }
  }
}