コード例 #1
0
ファイル: queue.c プロジェクト: kilogram/EE319K
int testqueue(void){ 
 Fifo_Init(); 
 for(;;){ 
 Status[0] = Fifo_Get(&GetData[0]); // should fail, empty 
 Status[1] = Fifo_Put(1); // should succeed, 1 
 Status[2] = Fifo_Put(2); // should succeed, 1 2 
 Status[3] = Fifo_Put(3); // should succeed, 1 2 3 
 Status[4] = Fifo_Put(4); // should succeed, 1 2 3 4 
 Status[5] = Fifo_Put(5); // should succeed, 1 2 3 4 5 
 Status[6] = Fifo_Put(6); // should succeed, 1 2 3 4 5 6 
 Status[7] = Fifo_Put(7); // should fail, 1 2 3 4 5 6 
 Status[8] = Fifo_Get(&GetData[1]); // should succeed, 2 3 4 5 6 
 Status[9] = Fifo_Get(&GetData[2]); // should succeed, 3 4 5 6 
 Status[10] = Fifo_Put(7); // should succeed, 3 4 5 6 7 
 Status[11] = Fifo_Put(8); // should succeed, 3 4 5 6 7 8 
 Status[12] = Fifo_Put(9); // should fail, 3 4 5 6 7 8 
 Status[13] = Fifo_Get(&GetData[3]); // should succeed, 4 5 6 7 8 
 Status[14] = Fifo_Get(&GetData[4]); // should succeed, 5 6 7 8 
 Status[15] = Fifo_Get(&GetData[5]); // should succeed, 6 7 8 
 Status[16] = Fifo_Get(&GetData[6]); // should succeed, 7 8 
 Status[17] = Fifo_Get(&GetData[7]); // should succeed, 8 
 Status[18] = Fifo_Get(&GetData[8]); // should succeed, empty 
 Status[19] = Fifo_Get(&GetData[9]); // should fail, empty 
 } 
}
コード例 #2
0
ファイル: Lab2g.c プロジェクト: NickCarneiro/EE445L-Labs
void main(void){  	 
  PLL_Init();         // running at 24MHz
  DDRT |= 0x1F;       // debugging outputs
  PTT &= ~0x1F;
  Debug_Profile(0);   // 0 means initialization phase
  Fifo_Init();        // Initialize fifo
  OC0_Init();         // variable rate interrupt
  ForeExpected = 0;   // expected data
  for(;;){
    Debug_Profile(1); // 1 means start of foreground waiting 
    PTT_PTT1 = 0;     // falling edge of PT1 means start of foreground waiting
    while(Fifo_Get(&ForeData)==FIFOFAIL){
    }
    Debug_Profile(2); // 2 means foreground has new data
    PTT_PTT1 = 1;     // rising edge of PT1 means start of foreground processing
    if(ForeExpected != ForeData){
      Errors++;
      PTT ^= 0x10;                  // critical section found
      ForeExpected = ForeData+1; // resych to lost/bad data
    }  
    else{
      ForeExpected++;  // sequence is 0,1,2,3,...,254,255,0,1,...
    }
    if((ForeData%10)==0){
      Debug_Profile(3); // 3 means foreground has 10th data
   }
   }
}          
コード例 #3
0
ファイル: Serial.c プロジェクト: sasuqui/motor
interrupt VectorNumber_SCITransmit void SCI_Tx_Int(void){

  (void)SCS1;        //RECONOCE LA INTERRUPCION
  

  if ((Fifo_Get(&SCDR)==0)){
  
    SCC2_SCTIE = 0;
    txFlag=1; //Tx complete 
  }

}
コード例 #4
0
ファイル: Lab2g.c プロジェクト: NickCarneiro/EE445L-Labs
void main(void){ 
unsigned short First;
unsigned short Delay = 0;	 
EnableInterrupts;
  PLL_Init();       // running at 24MHz
  DDRT = 0xff;      // debugging outputs
  PTT = 0x00;
  SCI0_Init(115200);	// fastest standard baud rate on run mode 9S12DP512
  
  SCI0_OutString("EE445L Lab2g -JWV"); OutCRLF();
  TSCR1 = 0x80;     // Enable TCNT, 24MHz assuming PLL is active
  TSCR2 = 0;
// calibration offset  
  First = TCNT;
  //nothing here
  Delay = TCNT - First - 9;
  SCI0_OutString("Time to execute nothing "); 
  SCI0_OutUDec(Delay);
  SCI0_OutString(" cycles"); OutCRLF();

// measurement version 1, no debugging instruments 
  Fifo_Init();    // Initialize fifo
  Fifo_Put(1);    // make sure there is something in the fifo
  First = TCNT;
  Fifo_Get(&ForeData);
  Delay = TCNT-First-9;
  SCI0_OutString("Time to execute Fifo_Get with no debugging instruments is "); 
  SCI0_OutUDec(Delay);
  SCI0_OutString(" cycles"); OutCRLF();

// measurement version 2, print debugging instruments 
/*  Fifo_Init();    // Initialize fifo
  Fifo_Put(1);    // make sure there is something in the fifo
  First = TCNT;
  Fifo_Get2(&ForeData);
  Delay = TCNT-First-9;
  SCI0_OutString("Time to execute Fifo_Get2 with print debugging instruments is "); 
  SCI0_OutUDec(Delay);
  SCI0_OutString(" cycles"); OutCRLF();
  
// measurement version 3, dump debugging instruments 
  Fifo_Init();    // Initialize fifo
  Fifo_Put(1);    // make sure there is something in the fifo
  First = TCNT;
  Fifo_Get3(&ForeData);
  Delay = TCNT-First-9;
  SCI0_OutString("Time to execute Fifo_Get3 with dump debugging instruments is "); 
  SCI0_OutUDec(Delay);
  SCI0_OutString(" cycles"); OutCRLF();*/  
  for(;;){}
}
コード例 #5
0
ファイル: Lab2g.c プロジェクト: NickCarneiro/EE445L-Labs
// main program for Procedure part D
void main2(void){
dataType data;
  DDRT |= 0x01;       
  Fifo_Init();    // initialize 
  TSCR1 = 0x80;   // Enable TCNT, 24MHz assumming PLL is active
  First = TCNT;
  Delay = TCNT-First;
asm cli     
  for(;;){
    Fifo_Put(1);
    PTT_PTT0 = 1;     
    Fifo_Get(&data);
    PTT_PTT0 = 0;   
  }
}
コード例 #6
0
static char *IoLayer_EscapeString(IOLAYER *hPIO, char *pszData)
{
	IOLAYER_INST *hIO = (IOLAYER_INST*)hPIO;
	TYP_FIFO *hFifo;
	char szBuf[8], *pszRet;
	unsigned char *p;

	if (!(hFifo = Fifo_Init(strlen(pszData)))) return NULL;
	for (p=pszData; *p; p++)
	{
		if (isalnum(*p)) Fifo_Add (hFifo, p, 1);
		else {
			wsprintf (szBuf, "%%%02X", *p);
			Fifo_Add (hFifo, szBuf, 3);
		}
	}
	Fifo_Add (hFifo, "", 1);
	if (pszRet = Fifo_Get(hFifo, NULL))
		pszRet = strdup(pszRet);
	Fifo_Exit(hFifo);
	return pszRet;
}
コード例 #7
0
ファイル: UART1.c プロジェクト: kilogram/EE319K
//------------UART_InChar------------
// Wait for new serial port input
// Input: none
// Output: ASCII code for key typed
unsigned char UART1_InChar(void){
	unsigned char dat;
	while(Fifo_Get(&dat) == 0);
	return dat;
}
コード例 #8
0
ファイル: main.c プロジェクト: scyphio122/stm32f4-wav_player
int
main(int argc, char* argv[])
{
	volatile FATFS 		fatfs = {0};
	volatile FRESULT 	result;
	uint8_t 			fifo_command = 0;
	uint8_t				file_index = 0;



    ResetRCC();
    RCC_SetClockFrequency(PLLM_macro, PLLN_macro, PLLQ_macro, PLLP_macro);

    //  Enable clocks for the peripherals
    /*
     * 	GPIOA	-	NEC_CONTROLLER, TIM1 PWM, DAC
     * 	GPIOB	- 	SPI2
     * 	GPIOC	-	HD44780 Led Display
     * 	GPIOD	-	LED diodes, USART2(Log)
     */
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN |  RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;
    RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
    RCC->APB1ENR |= RCC_APB1ENR_TIM7EN | RCC_APB1ENR_SPI2EN | RCC_APB1ENR_USART2EN | RCC_APB1ENR_DACEN;


    /*< Configure board's leds to signal states */
    GPIO_OutputConfigure(GPIOD, PIN_12 | PIN_13 | PIN_14 | PIN_15, gpio_otyper_push_pull, gpio_speed_high, gpio_pupd_pull_down);
    /*< Configure NVIC Interrupt controller */
    //  Set two bits (out of four) as the main priority. The rest bits are used for preemptive priorities
    NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2);
    NVIC_Enable_Interrupts();

    /*< Configure USART2 module to create program log */
    UART_Config(USART2, USART_CR1_UE | USART_CR1_TE, 19200,false);
    GPIO_AlternateFunctionPrepare(GPIOD, PIN_5, gpio_otyper_push_pull, gpio_speed_medium, gpio_pupd_pull_up);
    GPIO_AlternateFunctionSet(GPIOD,PIN_5, AF7);
    Log_Uart("##### LOG START #####\n\r");

    /*<	MCO2 Pin configuration to watch the CPU Clock signal with an oscilloscope*/
    Log_Uart("Clock output pin configuration in progress...\n\r");
    RCC->CFGR |= RCC_CFGR_MCO2PRE_2 | RCC_CFGR_MCO2PRE_1;
    RCC->CFGR &= ~RCC_CFGR_MCO2;
    GPIO_AlternateFunctionPrepare(GPIOC, PIN_9, gpio_otyper_push_pull, gpio_speed_fast, gpio_pupd_no_pull);
    GPIO_AlternateFunctionSet(GPIOC,PIN_9, AF0);

    /*<	SysTick configuration */
    Log_Uart("SysTick configuration in progress...\n\r");
    SysTick_Config(SYSTICK_CLK_DIVIDER);	//	Configure SysTick to make a tick every 1 us
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);


    /*< PWM signal configuration */
    Log_Uart("PWM generation module configuration in progress...\n\r");
    GPIO_AlternateFunctionPrepare(GPIOA, PIN_8, gpio_otyper_push_pull, gpio_speed_fast, gpio_pupd_pull_down);
    GPIO_AlternateFunctionSet(GPIOA, PIN_8, AF1);	//	Pin for PWM signal
    TIM_PWMConfigure(TIM1, 168, 5000, 4000, TIM_Channel_1);
    TIM_Start(TIM1);
    /*< HD44780 display configuration */
    LCD_Config();


    /*< Remote controller receiver initialization */
    Log_Uart("IR remote controller configuration in progress...\n\r");
    NEC_Remote_Init();
    TIM_Start(TIM6);

    /*< SPI Module configuration. It is used to communicate with the SD card */
    Log_Uart("SPI module configuration in progress...\n\r");
    SPI_Master_Init(SPI2, SPI_FREQ_PCLK_DIV_256, SPI_CPOL0_CPHA0, SPI_BIT_ORDER_MSB_FIRST, true);

    /*< DAC configuration */
    DAC_Init(dac_dual_channel_simultanous, dac_trigger_tim7, true);

    /*< Timer 7 used to trigger the DAC config */
    TIM_Basic_Continuous_Counting(TIM7, 12);

    /*< Remote Controller command fifo configuration */
    Log_Uart("FIFO configuration in progress...\n\r");
    Fifo_Init(&remote_command_fifo, remote_command_queue, sizeof(remote_command_queue));


    TIM6->CR1 |= TIM_CR1_CEN;	/*< Continuously ticking timer, used in NEC IR remote */

    Log_Uart("Configuration OK!\n\r");




    TCHAR disk[] = "0";
    UINT byte_number;
    result = f_mount(&fatfs, disk, 1);

    uint16_t bytes;
   /* result = SD_Find_File_Name_Containing("/", "*.wav");
    result = SD_Get_File_List("/");
    result = f_open(&sd_current_file, &sd_files_list[3], FA_READ);
    result = Wav_Get_File_Header(&sd_current_file);
*/
    //	Initially, get the files list
    state = STATE_GET_FILES_LIST;

  while(1)
  {
	  switch(state)
	  {
		 /* case STATE_WAIT:
			  break;*/

		  case	STATE_GET_FILES_LIST:
		  {
			  result = SD_Find_File_Name_Containing("/", "*.wav");
			  if(result == FR_NO_FILE)
			  {
				  LCD_WriteText("Brak plikow .wav");
				  // Go to sleep in this case
				  while(1)
				  {
					  __WFI();
				  }
			  }
			  else
			  {
				  LCD_WriteText(sd_files_list[0]);
			  }
			  state = STATE_EXECUTE_USER_REQUESTS;
			  break;
		  }

		  case STATE_READ_SAMPLES:
		  {
			  //	If we didn't get to the end of file yet...
			  if(!f_eof(&sd_current_file))
				  //	... Then read next sample chunk
				  f_read(&sd_current_file, empty_data_buf_ptr, 512, &read_data_byte_counter);
			  else
				  // 	...	Else set the end of file flag
				  wav_eof = true;
			  state = STATE_EXECUTE_USER_REQUESTS;
			  break;
		  }

		  case STATE_EXECUTE_USER_REQUESTS:
		  {
			  do
			  {
				  Fifo_Get(&remote_command_fifo, &fifo_command);

				  switch(fifo_command)
				  {
					  case NEC_CH_PLUS:
					  {
						  //	Disable when the wav_file is currently played
						  if(!wav_file_playing)
						  {
							  wav_file_chosen = false;
							  if(file_index < sd_number_of_files_in_dir-1)
								  file_index++;

							  LCD_WriteText(sd_files_list[file_index]);
						  }
						  break;
					  }
					  case NEC_CH_MINUS:
					  {
						  //	Disable when the wav_file is currently played
						  if(!wav_file_playing)
						  {
							  wav_file_chosen = false;
							  if(file_index > 0)
								  file_index--;
							  LCD_WriteText(sd_files_list[file_index]);
						  }
						  break;
					  }
					  case NEC_CH:
					  {
						  //	Disable when the wav_file is currently played
						  if(!wav_file_chosen)
						  {

							  //	If the file is already opened then close it
							  if(sd_current_file.fs != 0)
								  f_close(&sd_current_file);
							  //	...Open the chosen file
							  f_open(&sd_current_file, sd_files_list[file_index], FA_READ);
							  //	Get the chosen files header
							  WAV_Get_File_Header(&sd_current_file);
							  //	Prepare the triggering timer frequency
							 // WAV_Set_Trigger_Frequency(TIM7);
							  TIM_Set_Timer_Max_Count(TIM7, (uint16_t)(TIM7_FREQ/current_wave_header.byte_field.sample_rate));
							  //	Get the rest audio file info
							  //f_read(&sd_current_file, sd_data_buffer, current_wave_header.byte_field.subchunk_2_size, &read_data_byte_counter);
							  //	Get the first portion of data

							  //	Set the wav_file_chosen flag
							  wav_file_chosen = true;
							  //	Clear the wav_eof flag
							  wav_eof  = false;

						  }
						  break;
					  }
					  case NEC_PLAY_PAUSE:
					  {
						 if(!wav_file_playing && wav_file_chosen)
						 {
							//	Clear the timer's counter
							TIM_Clear(TIM7);
							TIM7->DIER |= TIM_DIER_UIE;
							empty_data_buf_ptr = sd_data_buffer;
							  f_read(&sd_current_file, sd_data_buffer, sizeof(sd_data_buffer), &read_data_byte_counter);

							  f_read(&sd_current_file, sd_data_buffer_additional, sizeof(sd_data_buffer_additional), &read_data_byte_counter);
							//	Start the DAC triggering timer
							TIM_Start(TIM7);
							//	Set the wav_file_playing_flag
							wav_file_playing = true;
						 }
						 else
						 {
							 //	Stop the DAC triggering timer
							 TIM_Stop(TIM7);

							 //	Clear the wav_file_playing_ flag
							 wav_file_playing = false;
						 }
						 break;
					  }

					  default:
						  break;
				  }
				  fifo_command = 0;
			  }while(!Fifo_Empty(&remote_command_fifo));
			  break;
		  }
	  }
  }
}
コード例 #9
0
static char *IoLayer_Post(IOLAYER *hPIO, char *pszURL, char *pszPostFields, unsigned int cbPostFields, unsigned int *pdwLength)
{
	IOLAYER_INST *hIO = (IOLAYER_INST*)hPIO;
	URL_COMPONENTS urlInfo = {0};
	HINTERNET hUrl;
	DWORD dwFlags = 0, cbFlags = sizeof(dwFlags), dwRemaining = 0;
	char szHostName[INTERNET_MAX_HOST_NAME_LENGTH],
		szURLPath[INTERNET_MAX_URL_LENGTH], *p;

//OutputDebugString(pszPostFields);
	urlInfo.dwStructSize = sizeof (URL_COMPONENTS);
	urlInfo.lpszHostName = szHostName;
	urlInfo.dwHostNameLength = sizeof(szHostName);
	urlInfo.lpszUrlPath = szURLPath;
	urlInfo.dwUrlPathLength = sizeof(szURLPath);
	if (!InternetCrackUrl(pszURL, strlen(pszURL), 0, &urlInfo)) return NULL;
	/*
	if (!pszPostFields)
	{
		if (pszPostFields=strchr (pszURL, '?'))
			cbPostFields = strlen(pszPostFields);
	}
	*/

	if (!(hUrl = InternetConnect (hIO->hInet, szHostName, 
		INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0)))
	{
		FetchLastError (hIO);
		return NULL;
	}
	
	hIO->hRequest = HttpOpenRequest (hUrl, pszPostFields?"POST":"GET", szURLPath, NULL, NULL, NULL, 
		INET_FLAGS, 0);
	if (!hIO->hRequest)
	{
		FetchLastError (hIO);
		InternetCloseHandle (hUrl);
		return NULL;
	}
	
	InternetQueryOption (hIO->hRequest, INTERNET_OPTION_SECURITY_FLAGS, (LPVOID)&dwFlags, &cbFlags); 
	dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
	InternetSetOption (hIO->hRequest, INTERNET_OPTION_SECURITY_FLAGS, &dwFlags, sizeof (dwFlags));

	/*
	{
		char szCookies[4096];
		DWORD cbCookies, dwIndex=0;

		OutputDebugString ("Sending headers:\n");
		do
		{
			cbCookies=sizeof(szCookies);
			HttpQueryInfo (hIO->hRequest, HTTP_QUERY_FLAG_REQUEST_HEADERS|HTTP_QUERY_RAW_HEADERS_CRLF, szCookies, &cbCookies, &dwIndex);
			OutputDebugString (szCookies);
		} while (GetLastError() == ERROR_SUCCESS);
	}
	*/

	if (!(HttpSendRequest (hIO->hRequest, "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"
		"X-Requested-With: XMLHttpRequest", -1,
		pszPostFields, cbPostFields)))
	{
		FetchLastError (hIO);
		InternetCloseHandle (hIO->hRequest);
		hIO->hRequest = NULL;
		InternetCloseHandle (hUrl);
		return NULL;
	}

	/*
	{
		char szCookies[4096];
		DWORD cbCookies, dwIndex=0;

		OutputDebugString ("Received headers:\n");
		do
		{
			cbCookies=sizeof(szCookies);
			HttpQueryInfo (hIO->hRequest, HTTP_QUERY_FLAG_REQUEST_HEADERS|HTTP_QUERY_RAW_HEADERS_CRLF, szCookies, &cbCookies, &dwIndex);
			OutputDebugString (szCookies);
		} while (GetLastError() == ERROR_SUCCESS);
	}
	*/


	while (InternetQueryDataAvailable (hIO->hRequest, &dwRemaining, 0, 0) && dwRemaining > 0)
	{
		if (p = Fifo_AllocBuffer (hIO->hResult, dwRemaining))
			InternetReadFile (hIO->hRequest, p, dwRemaining, &dwRemaining);
	}
	if (!pdwLength)
	{
		// Get string
		Fifo_Add (hIO->hResult, "", 1);
		p = Fifo_Get (hIO->hResult, NULL);
	}
	else
	{
		// Get binary, return size of buffer
		*pdwLength = (unsigned int)-1;
		p = Fifo_Get (hIO->hResult, pdwLength);
	}
	InternetCloseHandle (hIO->hRequest);
	hIO->hRequest = NULL;
	InternetCloseHandle (hUrl);
OutputDebugString(p);
OutputDebugString("\n");
	return p;
}