示例#1
0
文件: starter1.c 项目: manavm/Classes
int main0(void){  
  // "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers",
  // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.2
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  initClk();         // PLL 50 MHz, ADC needs PPL active          15
  ADC0_InitSWTriggerSeq3(7);  // Ain7 is on PD0                   16
  sl_Start(0, 0, 0); // Initializing the CC3100 device            17
  WlanConnect();     // connect to AP                             18
  sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,       // 19
               (unsigned char *)&ipV4);                        // 20
  Addr.sin_family = SL_AF_INET;                       //          21 
  Addr.sin_port = sl_Htons((UINT16)PORT_NUM);         //          22
  Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);   //          23
  AddrSize = sizeof(SlSockAddrIn_t);                  //          24
  SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);    //          25
  while(1){
    uBuf[0] = ATYPE;      // analog data type                     26
    uBuf[1] = '=';        //                                      27
    data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0            28
    Int2Str(data,(char*)&uBuf[2]); // 6 digit number              29
    sl_SendTo(SockID, uBuf, BUF_SIZE, 0,        //                30
                         (SlSockAddr_t *)&Addr, AddrSize); //     31
    ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25);  // 40ms          32
  }
}
示例#2
0
int main(void){
  PLL_Init();                           // 25 MHz
	

	
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F
   ADC0_InitSWTriggerSeq3(0);            // allow time to finish activating
 // ADC0_InitAllTriggerSeq3(0);           // allow time to finish activating
	Timer0A_Init10HzInt();                // set up Timer0A for 10 Hz interrupts
  Timer1_Init();												// Intitalize timer1 count down
	
  GPIO_PORTF_DIR_R |= 0x04;             // make PF2 out (built-in LED)
  GPIO_PORTF_AFSEL_R &= ~0x04;          // disable alt funct on PF2
  GPIO_PORTF_DEN_R |= 0x04;             // enable digital I/O on PF2
                                        // configure PF2 as GPIO
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000;
  GPIO_PORTF_AMSEL_R = 0;               // disable analog functionality on PF
  GPIO_PORTF2 = 0;                      // turn off LED
	 EnableInterrupts();
   ST7735_InitR(INITR_REDTAB);
	ST7735_FillScreen(0);  // set screen to black
	ST7735_SetCursor(0,0);
  ST7735_XYplotInit("Lab 2 PMF Averaging \n", 0, 4096, 0, 50);
	ST7735_OutString("1 point \n");
  while(1){
     WaitForInterrupt();
		 
//    GPIO_PORTF2 = 0x04;                 // profile
//    ADCvalue = ADC0_InSeq3();
//    GPIO_PORTF2 = 0x00;
		
		
		if(Buffer_Counter == 1000){
		    break;
		}
  }
		uint32_t Jitter;
	//	DisableInterrupts();
		//	TIMER1_CTL_R = 0x00000000;    // 10) enable TIMER1A
			GPIO_PORTF2 = 0x04;                   // profile
			
			
			Jitter = Calc_Jitter();  
			 uint32_t n = ADCvalue;
 	  //	 ST7735_OutUDec(n);
			Calc_PMF();  // will populate the frequency table ADC_Data = x-axis ADC_Freq = y-axis
			// Next line is call to the plot point function we created in lab1
		  //	ST7735_XYplotInit("PMF", 0, 4096, 0, 50);
		  //  ST7735_XYplot(1000, ADC_Data, ADC_Freq);
			int j = 0;
			uint32_t x = 0;
			uint32_t y = 0;
	    int i = 0;
			//ST7735_PlotClear(32, 159);
		//	for(j = 0; j < 1000; j+=1){
				ST7735_XYplotInit("Lab 2 PMF", 0, 4095, 0, 1000);
				ST7735_XYplot(1000, ADC_Data, ADC_Freq);
			 	// ST7735_PlotBar(ADC_Freq[j]);
				// ST7735_PlotBar(ADC_Freq[j]);
				 //ST7735_PlotBar(30);
				//ST7735_PlotNext();
				
			//	  y = 32+(127*(400-ADC_Freq[j]))/400;
		  //		x = 127-(127*(4095 - ADC_Data[j])/4095);
			//	  if(x<0)x = 0;
			//		if(x>127)x=127;
			//		if(y<32) y = 32;
			//	ST7735_PlotBar(y);
			//	if(y>159) y = 159;
			 // 	if(x > i){
				//		ST7735_PlotNext();
				 //	  i += 1;
				 // }
				
				/*
				if(j < 14){
				ST7735_OutUDec(ADC_Data[j]);
				ST7735_OutString(" ");
				ST7735_OutUDec(ADC_Freq[j]);
					ST7735_OutString("\n");
				}
				*/
//			}
			GPIO_PORTF2 = 0x00;
		//	EnableInterrupts();
}
示例#3
0
文件: starter1.c 项目: manavm/Classes
int main1(void){
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  INT16             Status = 1;  // ok
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz, ADC needs PPL active
  Board_Init();     // initialize LaunchPad I/O 
  ConfigureUART();  // Initialize the UART.
  UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
#if ADC
  ADC0_InitSWTriggerSeq3(7);  // Ain7 is on PD0
  UARTprintf("This node is configured to measure signals from Ain7=PD0\n");
#endif
#if EKG
  UARTprintf("This node is configured to generate simulated EKG data\n");
#endif
  UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
  while(1){
    sl_Start(0, 0, 0);/* Initializing the CC3100 device */
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();   // connect to AP
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    while(Status > 0){
      Addr.sin_family = SL_AF_INET;
      Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
      Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
      AddrSize = sizeof(SlSockAddrIn_t);
      SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
      if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        while(Status>0){
          UARTprintf("\nSending a UDP packet ...");
          uBuf[0] = ATYPE;   // defines this as an analog data type
          uBuf[1] = '='; 
#if ADC
          data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0
#endif
#if EKG
          data = EKGbuf[EKGindex];
          EKGindex = (EKGindex+1)%EKGSIZE; // 100 Hz
#endif
          Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
          UARTprintf(" %s ",uBuf);
          LED_Toggle();
          Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
          ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 80ms
          if( Status <= 0 ){
            UARTprintf("SockIDerror %d ",Status);
          }else{
           UARTprintf("ok");
          }     
        }
        sl_Close(SockID);
      }
    }
  }
}