Exemplo n.º 1
0
int main()
{
    // Configure IO pins with default mode and selector
    TIMER_ISR::Init();
    TIMER_TO_PROC1::Init();
    PROC1::Init();
    PROC2::Init();
    PROC3::Init();
    TIMER_HOOK::Init();
    IDLE_HOOK::Init();

    // Setup timer for TimerEvent generation
    // Timer 1, 25 MHz timer clock.
    // Interrupt rate slightly higher than 200 Hz for better scope view
    LPC_SC->PCONP   |= CLKPWR_PCONP_PCTIM1;
    LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & ~(0x03 << CLKPWR_PCLKSEL_TIMER1))
                     | (CLKPWR_PCLKSEL_CCLK_DIV_4 << CLKPWR_PCLKSEL_TIMER1);
    LPC_TIM1->CTCR = 0;

    LPC_TIM1->PR = 0;
    LPC_TIM1->PC = 0;
    LPC_TIM1->TC = 0;
    LPC_TIM1->MR0 = SYSTICKFREQ / 4 / 200.4 - 1;
    LPC_TIM1->MCR = TIM_RESET_ON_MATCH(0) | TIM_INT_ON_MATCH(0);
    LPC_TIM1->EMR = TIM_EM_SET(0, TIM_EM_TOGGLE);
    LPC_TIM1->TCR = (1 << 0);

    NVIC->IP[ TIMER1_IRQn ] = 0x80; // Middle priority
    NVIC->ISER[0] = (1 << TIMER1_IRQn);

    // run
    OS::run();
}
Exemplo n.º 2
0
/*********************************************************************//**
 * @brief 		Configuration for Match register
 * @param[in]	TIMx Pointer to timer device
 * @param[in]   TIM_MatchConfigStruct Pointer to TIM_MATCHCFG_Type
 * 					- MatchChannel : choose channel 0 or 1
 * 					- IntOnMatch	 : if SET, interrupt will be generated when MRxx match
 * 									the value in TC
 * 					- StopOnMatch	 : if SET, TC and PC will be stopped whenM Rxx match
 * 									the value in TC
 * 					- ResetOnMatch : if SET, Reset on MR0 when MRxx match
 * 									the value in TC
 * 					-ExtMatchOutputType: Select output for external match
 * 						 +	 0:	Do nothing for external output pin if match
 *						 +   1:	Force external output pin to low if match
 *						 + 	 2: Force external output pin to high if match
 *						 + 	 3: Toggle external output pin if match
 *					MatchValue: Set the value to be compared with TC value
 * @return 		None
 **********************************************************************/
void TIM_ConfigMatch(TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct)
{
	CHECK_PARAM(PARAM_TIMx(TIMx));
	CHECK_PARAM(PARAM_TIM_EXTMATCH_OPT(TIM_MatchConfigStruct->ExtMatchOutputType));
	uint32_t timer = TIM_ConverPtrToTimeNum(TIMx) ;
	//	TIMx->MR[TIM_MatchConfigStruct->MatchChannel] = TIM_MatchConfigStruct->MatchValue;
	switch(TIM_MatchConfigStruct->MatchChannel)
	{
	case 0:
		TIMx->MR0 = TIM_MatchConfigStruct->MatchValue;
		break;
	case 1:
		TIMx->MR1 = TIM_MatchConfigStruct->MatchValue;
		break;
	}
	//interrupt on MRn
	TIMx->MCR &=~TIM_MCR_CHANNEL_MASKBIT(TIM_MatchConfigStruct->MatchChannel);

	if (TIM_MatchConfigStruct->IntOnMatch)
		TIMx->MCR |= TIM_INT_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//reset on MRn
	if (TIM_MatchConfigStruct->ResetOnMatch)
		TIMx->MCR |= TIM_RESET_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//stop on MRn
	if (TIM_MatchConfigStruct->StopOnMatch)
		TIMx->MCR |= TIM_STOP_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	// match output type

	TIMx->EMR 	&= ~TIM_EM_MASK(TIM_MatchConfigStruct->MatchChannel);
	TIMx->EMR    = TIM_EM_SET(TIM_MatchConfigStruct->MatchChannel,TIM_MatchConfigStruct->ExtMatchOutputType);

		//pin output configuration
		if (TIM_MatchConfigStruct->ExtMatchOutputType >0)
		{
			if ((timer <2)&& (TIM_MatchConfigStruct->MatchChannel < 2))
			{
				PINSEL_ConfigPin((PINSEL_CFG_Type *)&timer_match_pin[2*timer +TIM_MatchConfigStruct->MatchChannel]);
			}
			if ((timer ==2))
			{
				PINSEL_ConfigPin( (PINSEL_CFG_Type *)&timer_match_pin[2*timer + TIM_MatchConfigStruct->MatchChannel]);
			}
			if ((timer ==3)&&(TIM_MatchConfigStruct->MatchChannel < 2))
			{
				PINSEL_ConfigPin( (PINSEL_CFG_Type *)&timer_match_pin[4*timer + TIM_MatchConfigStruct->MatchChannel]);
			}
		}
}
Exemplo n.º 3
0
/*********************************************************************//**
 * @brief 		Configuration for Match register
 * @param[in]	TIMx Pointer to timer device, should be:
 *   			- LPC_TIM0: TIMER0 peripheral
 * 				- LPC_TIM1: TIMER1 peripheral
 * 				- LPC_TIM2: TIMER2 peripheral
 * 				- LPC_TIM3: TIMER3 peripheral
 * @param[in]   TIM_MatchConfigStruct Pointer to TIM_MATCHCFG_Type
 * 					- MatchChannel : choose channel 0 or 1
 * 					- IntOnMatch	 : if SET, interrupt will be generated when MRxx match
 * 									the value in TC
 * 					- StopOnMatch	 : if SET, TC and PC will be stopped whenM Rxx match
 * 									the value in TC
 * 					- ResetOnMatch : if SET, Reset on MR0 when MRxx match
 * 									the value in TC
 * 					-ExtMatchOutputType: Select output for external match
 * 						 +	 0:	Do nothing for external output pin if match
 *						 +   1:	Force external output pin to low if match
 *						 + 	 2: Force external output pin to high if match
 *						 + 	 3: Toggle external output pin if match
 *					MatchValue: Set the value to be compared with TC value
 * @return 		None
 **********************************************************************/
void TIM_ConfigMatch(LPC_TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct)
{

	CHECK_PARAM(PARAM_TIMx(TIMx));
	CHECK_PARAM(PARAM_TIM_EXTMATCH_OPT(TIM_MatchConfigStruct->ExtMatchOutputType));

	switch(TIM_MatchConfigStruct->MatchChannel)
	{
	case 0:
		TIMx->MR0 = TIM_MatchConfigStruct->MatchValue;
		break;
	case 1:
		TIMx->MR1 = TIM_MatchConfigStruct->MatchValue;
		break;
	case 2:
		TIMx->MR2 = TIM_MatchConfigStruct->MatchValue;
		break;
	case 3:
		TIMx->MR3 = TIM_MatchConfigStruct->MatchValue;
		break;
	default:
		//Error match value
		//Error loop
		while(1);
	 break;
	}
	//interrupt on MRn
	TIMx->MCR &=~TIM_MCR_CHANNEL_MASKBIT(TIM_MatchConfigStruct->MatchChannel);

	if (TIM_MatchConfigStruct->IntOnMatch)
		TIMx->MCR |= TIM_INT_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//reset on MRn
	if (TIM_MatchConfigStruct->ResetOnMatch)
		TIMx->MCR |= TIM_RESET_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//stop on MRn
	if (TIM_MatchConfigStruct->StopOnMatch)
		TIMx->MCR |= TIM_STOP_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	// match output type

	TIMx->EMR 	&= ~TIM_EM_MASK(TIM_MatchConfigStruct->MatchChannel);
	TIMx->EMR   |= TIM_EM_SET(TIM_MatchConfigStruct->MatchChannel,TIM_MatchConfigStruct->ExtMatchOutputType);
}
Exemplo n.º 4
0
/*********************************************************************//**
 * @brief 		Configuration for Match register
 * @param[in]	TIMx Pointer to timer device
 * @param[in]   TIM_MatchConfigStruct Pointer to TIM_MATCHCFG_Type
 * 					- MatchChannel : choose channel 0 or 1
 * 					- IntOnMatch	 : if SET, interrupt will be generated when MRxx match
 * 									the value in TC
 * 					- StopOnMatch	 : if SET, TC and PC will be stopped whenM Rxx match
 * 									the value in TC
 * 					- ResetOnMatch : if SET, Reset on MR0 when MRxx match
 * 									the value in TC
 * 					-ExtMatchOutputType: Select output for external match
 * 						 +	 0:	Do nothing for external output pin if match
 *						 +   1:	Force external output pin to low if match
 *						 + 	 2: Force external output pin to high if match
 *						 + 	 3: Toggle external output pin if match
 *					MatchValue: Set the value to be compared with TC value
 * @return 		None
 **********************************************************************/
void TIM_ConfigMatch(LPC_TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct)
{
	uint32_t timer;

	CHECK_PARAM(PARAM_TIMx(TIMx));
	CHECK_PARAM(PARAM_TIM_EXTMATCH_OPT(TIM_MatchConfigStruct->ExtMatchOutputType));

	timer = TIM_ConverPtrToTimeNum(TIMx) ;
	switch(TIM_MatchConfigStruct->MatchChannel)
	{
	case 0:
		TIMx->MR0 = TIM_MatchConfigStruct->MatchValue;
		break;
	case 1:
		TIMx->MR1 = TIM_MatchConfigStruct->MatchValue;
		break;
	}
	//interrupt on MRn
	TIMx->MCR &=~TIM_MCR_CHANNEL_MASKBIT(TIM_MatchConfigStruct->MatchChannel);

	if (TIM_MatchConfigStruct->IntOnMatch)
		TIMx->MCR |= TIM_INT_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//reset on MRn
	if (TIM_MatchConfigStruct->ResetOnMatch)
		TIMx->MCR |= TIM_RESET_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//stop on MRn
	if (TIM_MatchConfigStruct->StopOnMatch)
		TIMx->MCR |= TIM_STOP_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
//	TIMx->MCR = 0x02;

	// match output type

	TIMx->EMR 	&= ~TIM_EM_MASK(TIM_MatchConfigStruct->MatchChannel);
	TIMx->EMR    = TIM_EM_SET(TIM_MatchConfigStruct->MatchChannel,TIM_MatchConfigStruct->ExtMatchOutputType);
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: inf3ct3d/fmtr
int main ()
{
	//int i, j;
//	TIM_TIMERCFG_Type timer_config;
//	TIM_MATCHCFG_Type match_config;
	UART_CFG_Type cfg;
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;

	/******************** GPIO **********************************/
	SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);
	GPIO_SetDir(PORT0, GPIO_Pin_7, 1);
	GPIO_SetDir(PORT3, GPIO_Pin_3, 0);

	IOCON_SetPinMode(IOCON_PIO3_3, PIN_MODE_PullUp);
	IOCON_SetPinMode(IOCON_PIO0_7, PIN_MODE_PullUp);
	/*************************************************************/

	/******************* LCD ***********************************/
	lcd_init();
	lcd_string(" ** Flow Meter ** ", 1);
	/************************************************************/

	/****************** 32 bit Counter ****************************/
	IOCON_SetPinFunc(IOCON_PIO1_5, PIO1_5_FUN_CT32B0_CAP0);
	SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_CT32B0, ENABLE);
	LPC_TMR32B0->CTCR = (1<<0);

//	LPC_TMR32B0->TCR = (1<<1);
//	LPC_TMR32B0->TCR = (1<<0);
	/***************************************************************/

	/****************** External Interrupt on GPIO *********************/
	gpio_init_config ();
	GPIO_EventInit(&gpio_int_struct);
	GPIO_PortIntCmd(PORT3, ENABLE);
	/*******************************************************************/

	/*************************** UART **************************************/
	/* Assign UART Pins */
	UART_PinsInit();

	cfg.Baud_rate = 115200;
	cfg.Parity = UART_PARITY_NONE;
	cfg.Databits = UART_DATABIT_8;
	cfg.Stopbits = UART_STOPBIT_1;
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

	UART_Init(LPC_UART, &cfg);
	UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct);

	/* Enable Transmit */
	UART_TxCmd(LPC_UART,ENABLE);


	/************************************************************************/

	/******************************** SPI *********************************/
	DAC_SPI1_Config ();
	/***********************************************************************/

	/************************ 32 Bit Timer1 ******************************/
	NVIC_EnableIRQ(TIMER_32_1_IRQn);
	/* Configure Timer Prescale */
	timer_config.PrescaleOption = TIM_PRESCALE_TICKVAL;
	/* We have a 48MHz clock, so a prescale of 48000 will mean the main timer ticks every millisecond. */
	timer_config.PrescaleValue = 11999;
	/* Init! */
	TIM_Init(LPC_TMR32B1, TIM_TIMER_MODE, &timer_config);
	/* COnfigure Timer Match */
	/* Match on channel 0 */
	match_config.MatchChannel = 0;
	/* Interrupt on match */
	match_config.IntOnMatch =   TIM_INT_ON_MATCH(0);
	/* Reset the timer on match */
	match_config.ResetOnMatch = TIM_RESET_ON_MATCH(0);
	/* Match on a count of 75, so interrupt every 75 milliseconds */
	match_config.MatchValue = 4000U;
	/*  Config the match */
	TIM_ConfigMatch(LPC_TMR32B1, &match_config);
	/* Clear the timer, and then start it */
	TIM_Cmd(LPC_TMR32B1, TIM_RESET);
	TIM_Cmd(LPC_TMR32B1, TIM_ENABLE);
	/******************************************************************/
	while(1)
	{
		// DAC_SPI1_Write(0x0E8B); // 3V
		//DAC_SPI1_Write(0x09b2); // 2V
		//DAC_SPI1_Write(0x04D9); // 1V
		//UART_Send(LPC_UART, (uint8_t *)"Hello, World!\n", sizeof("Hello, World!\n") - 1, NONE_BLOCKING);
		//_delay_ms(1000);

		Flow_Uart_Send (1, 5);
		_delay_ms(1);
		Flow_Uart_Send (20, 5);
		_delay_ms(1);
		Flow_Uart_Send (300, 5);
		_delay_ms(1);
		Flow_Uart_Send (4000, 5);
		_delay_ms(1);
		Flow_Uart_Send (50000, 5);

		//idle
	}
}