예제 #1
0
__task void CMDHandler(void)
{
	uint8_t write_buf[128]={0};
	uint8_t read_buf[128]={0};
	uint8_t i=0;
	uint32_t err_count=0;
	uint32_t ok_count=0;
	unsigned short tmp=0;
	
	os_dly_wait(300);  // // 10MS * 10 = 100 mS

	Serial_PutString("AT\r\n");
	os_dly_wait(50);  // // 10MS * 10 = 100 mS
	Serial_PutString("ATE1\r\n");
	os_dly_wait(50);  // // 10MS * 10 = 100 mS
	Serial_PutString("AT+CPIN?\r\n");
	os_dly_wait(100);  // // 10MS * 10 = 100 mS
	ds18b20_start();
	while (1)
	{				

	Serial_PutString("AT+CSQ\r\n");
	ShowTime();
	printf("ACC:%5.2f %5.2f %5.2f  GYRO: %5.2f %5.2f %5.2f\r\n\r\n",Acc_Buffer[0],Acc_Buffer[1],Acc_Buffer[2],
																															Gyro_Buffer[0],Gyro_Buffer[1],Gyro_Buffer[2]);
		
		printf("SLOAR: %d, CHARGE: %d, BAT: %d (ADC Value)\r\n",Adc1Result.Channel_8, Adc1Result.Channel_9, Adc1Result.Channel_15);

		for(i=0;i<128;i++)
		write_buf[i]=rand();
		
		at25_write_page(0x00,128,write_buf);
		
		at25_read_page(0x00,128,read_buf);
	if(memcmp(read_buf,write_buf,128) == 0)
	{
		printf("> FRAM Write successed : %d\r\n" ,++ok_count);
	}
	else
	{
		printf("> FRAM Write failed: %d\r\n",++err_count);
	}		
		
	tmp=ds18b20_read();
		printf("> Tmp: %.1f (%d)\r\n",(tmp*0.0039),tmp);
	if(flag_usart3_rx==1)
	{
		flag_usart3_rx=0;
		printf("%s",UART3RecvBuf);
		printf("\r\n");
	}
	printf("---------------------------------------------------------------------------\r\n\r\n");

	os_dly_wait(100);  // // 10MS * 10 = 100 mS

		
	}
		
}
예제 #2
0
/**
  * @brief  Upload a file via serial port.
  * @param  None
  * @retval None
  */
void SerialUpload(void)
{
  uint8_t status = 0;

  Serial_PutString((uint8_t *)"\n\n\rSelect Receive File\n\r");

  HAL_UART_Receive(&UartHandle, &status, 1, RX_TIMEOUT);
  if ( status == CRC16)
  {
    /* Transmit the flash image through ymodem protocol */
    status = Ymodem_Transmit((uint8_t*)APPLICATION_ADDRESS, (const uint8_t*)"UploadedFlashImage.bin", USER_FLASH_SIZE);

    if (status != 0)
    {
      Serial_PutString((uint8_t *)"\n\rError Occurred while Transmitting File\n\r");
    }
    else
    {
      Serial_PutString((uint8_t *)"\n\rFile uploaded successfully \n\r");
    }
  }
}
void nRF24L01_ISR(void)
{
	int i;
	sta=SPI2_readReg(STATUS);
	SPI2_writeReg(WRITE_REG+STATUS,0xff);
	if(RX_DR)				
	{
		SPI2_readBuf(RD_RX_PLOAD,rx_buf,TX_PLOAD_WIDTH);
		Serial_PutString(rx_buf);				 //put whatever received to the UART
  }
	if(MAX_RT)
	{
		SPI2_writeReg(FLUSH_TX,0);
  }

	
	RX_Mode();	
}
예제 #4
0
/**
  * @brief  Download a file via serial port
  * @param  None
  * @retval None
  */
void SerialDownload(void)
{
  uint8_t number[11] = {0};
  uint32_t size = 0;
  COM_StatusTypeDef result;

  Serial_PutString((uint8_t *)"Waiting for the file to be sent ... (press 'a' to abort)\n\r");
  result = Ymodem_Receive( &size );
  if (result == COM_OK)
  {
    Serial_PutString((uint8_t *)"\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
    Serial_PutString(aFileName);
    Int2Str(number, size);
    Serial_PutString((uint8_t *)"\n\r Size: ");
    Serial_PutString(number);
    Serial_PutString((uint8_t *)" Bytes\r\n");
    Serial_PutString((uint8_t *)"-------------------\n");
  }
  else if (result == COM_LIMIT)
  {
    Serial_PutString((uint8_t *)"\n\n\rThe image size is higher than the allowed space memory!\n\r");
  }
  else if (result == COM_DATA)
  {
    Serial_PutString((uint8_t *)"\n\n\rVerification failed!\n\r");
  }
  else if (result == COM_ABORT)
  {
    Serial_PutString((uint8_t *)"\r\n\nAborted by user.\n\r");
  }
  else
  {
    Serial_PutString((uint8_t *)"\n\rFailed to receive the file!\n\r");
  }
}
예제 #5
0
/**
  * @brief  Display the Main Menu on HyperTerminal
  * @param  None
  * @retval None
  */
void Main_Menu(void)
{
  uint8_t key = 0;

  Serial_PutString((uint8_t *)"\r\n======================================================================");
  Serial_PutString((uint8_t *)"\r\n=              (C) COPYRIGHT 2015 STMicroelectronics                 =");
  Serial_PutString((uint8_t *)"\r\n=                                                                    =");
  Serial_PutString((uint8_t *)"\r\n=  STM32F1xx In-Application Programming Application  (Version 1.0.0) =");
  Serial_PutString((uint8_t *)"\r\n=                                                                    =");
  Serial_PutString((uint8_t *)"\r\n=                                   By MCD Application Team          =");
  Serial_PutString((uint8_t *)"\r\n======================================================================");
  Serial_PutString((uint8_t *)"\r\n\r\n");

  /* Test if any sector of Flash memory where user application will be loaded is write protected */
  FlashProtection = FLASH_If_GetWriteProtectionStatus();

  while (1)
  {

    Serial_PutString((uint8_t *)"\r\n=================== Main Menu ============================\r\n\n");
    Serial_PutString((uint8_t *)"  Download image to the internal Flash ----------------- 1\r\n\n");
    Serial_PutString((uint8_t *)"  Upload image from the internal Flash ----------------- 2\r\n\n");
    Serial_PutString((uint8_t *)"  Execute the loaded application ----------------------- 3\r\n\n");


    if(FlashProtection != FLASHIF_PROTECTION_NONE)
    {
      Serial_PutString((uint8_t *)"  Disable the write protection ------------------------- 4\r\n\n");
    }
    else
    {
      Serial_PutString((uint8_t *)"  Enable the write protection -------------------------- 4\r\n\n");
    }
    Serial_PutString((uint8_t *)"==========================================================\r\n\n");

    /* Clean the input path */
    __HAL_UART_FLUSH_DRREGISTER(&UartHandle);
	
    /* Receive key */
    HAL_UART_Receive(&UartHandle, &key, 1, RX_TIMEOUT);

    switch (key)
    {
    case '1' :
      /* Download user application in the Flash */
      SerialDownload();
      break;
    case '2' :
      /* Upload user application from the Flash */
      SerialUpload();
      break;
    case '3' :
      Serial_PutString((uint8_t *)"Start program execution......\r\n\n");
      /* execute the new program */
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      /* Jump to user application */
      JumpToApplication = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      JumpToApplication();
      break;
    case '4' :
      if (FlashProtection != FLASHIF_PROTECTION_NONE)
      {
        /* Disable the write protection */
        if (FLASH_If_WriteProtectionConfig(FLASHIF_WRP_DISABLE) == FLASHIF_OK)
        {
          Serial_PutString((uint8_t *)"Write Protection disabled...\r\n");
          Serial_PutString((uint8_t *)"System will now restart...\r\n");
          /* Launch the option byte loading */
          HAL_FLASH_OB_Launch();
        }
        else
        {
          Serial_PutString((uint8_t *)"Error: Flash write un-protection failed...\r\n");
        }
      }
      else
      {
        if (FLASH_If_WriteProtectionConfig(FLASHIF_WRP_ENABLE) == FLASHIF_OK)
        {
          Serial_PutString((uint8_t *)"Write Protection enabled...\r\n");
          Serial_PutString((uint8_t *)"System will now restart...\r\n");
          /* Launch the option byte loading */
          HAL_FLASH_OB_Launch();
        }
        else
        {
          Serial_PutString((uint8_t *)"Error: Flash write protection failed...\r\n");
        }
      }
      break;
	default:
	Serial_PutString((uint8_t *)"Invalid Number ! ==> The number should be either 1, 2, 3 or 4\r");
	break;
    }
  }
}
예제 #6
0
파일: main.c 프로젝트: bill-he/jackbill350
int main()
{
    char freq0Disp[16], freq1Disp[16];
    char usbRx[USBUART_BUFFER_SIZE], usbTx[USBUART_BUFFER_SIZE];
    
    
    /* Initializes the LCD. */
    LCD_Start();
    LCD_Position(1u,0u);
    LCD_Position(0u,0u);
    LCD_PrintString("F1=");
    
    WaveDAC_0_Clock_Start();
    WaveDAC_1_Clock_Start();
    
    // Needed for WaveDACs to operate concurrently
    // I think this might be a bug with PSoC
    WaveDAC_0_Start();
    WaveDAC_1_Start(); 
    WaveDAC_0_Stop();
    WaveDAC_1_Stop();

    USBUART_Start(USBFS_DEVICE, USBUART_5V_OPERATION);
    USBUART_CDC_Init();
    
    CyGlobalIntEnable;

    while (1) {
        if (USBUART_IsConfigurationChanged()) {
            if (USBUART_GetConfiguration()) {
                USBUART_CDC_Init();
            }
        }
        
        if (USBUART_GetConfiguration()) {
            if (USBUART_DataIsReady()) {
                int numArgs;
                int desiredFreq, newFreq, fnGenerator;
                char mode[USBUART_BUFFER_SIZE] = {0};
                
                Serial_GetString(usbRx);
                trimString(usbRx);
                numArgs = sscanf(usbRx, "%d %s %d", &fnGenerator, mode, &desiredFreq);
                if (numArgs == 3) {
                    if (!strcmp(mode, "square")) { 
                        newFreq = changeFrequency(desiredFreq, SQUARE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "sine")) { 
                        newFreq = changeFrequency(desiredFreq, SINE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "triangle")) { 
                        newFreq = changeFrequency(desiredFreq, TRIANGLE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "sawtooth")) { 
                        newFreq = changeFrequency(desiredFreq, SAWTOOTH, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "dc")) { 
                        newFreq = changeFrequency(desiredFreq, DC, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else {
                        sprintf(usbTx, "Invalid mode: %s\r\n", mode);
                    }
                    
                    
                } else if (numArgs == 2) {
                    if (!strcmp(mode, "off")) {
                        if (fnGenerator == 0) {
                            stopWaveDac(WAVEDAC_LOW_0);
                        } else if (fnGenerator == 1) {
                            stopWaveDac(WAVEDAC_LOW_1);   
                        }
                        sprintf(usbTx, "Stopped WaveDAC %d\r\n", fnGenerator);
                    } else {
                        sprintf(usbTx, "Invalid mode: %s\r\n", mode);
                    }
                } else {
                    sprintf(usbTx, "Invalid command: %s\r\n", usbRx);
                }
                
                Serial_PutString(usbTx);
            }
        }
    }
}