Esempio n. 1
0
File: timer.c Progetto: Q-Mart/EMPR
/* Enable the RIT with some period `dt` */
void timer_enable_rit(int dt)
{
    RIT_dt = dt;
    RIT_Init(LPC_RIT);
    RIT_TimerConfig(LPC_RIT, dt);
    NVIC_EnableIRQ(RIT_IRQn);
}
Esempio n. 2
0
/*********************************************************************//**
 * @brief		c_entry: Main RIT program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void) {

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();
	 _DBG(menu);

	RIT_Init(LPC_RIT);
	/* Configure time_interval for RIT
	 * In this case: time_interval = 1000 ms = 1s
	 * So, RIT will generate interrupt each 1s
	 */
	RIT_TimerConfig(LPC_RIT,TIME_INTERVAL);

	_DBG("The time interval is: ");
	_DBD32(TIME_INTERVAL); _DBG_(" millisecond..");

#ifdef MCB_LPC_1768 /* Using LED2.2 for testing */
	//turn on LED2.2
	FIO_SetDir(2,(1<<2),1);
	FIO_SetValue(2,(1<<2));
#elif defined(IAR_LPC_1768) /* Using LED1 (P1.25 for testing */
	FIO_SetDir(1,(1<<25),1);
	FIO_ClearValue(1,(1<<25));
#endif
	NVIC_EnableIRQ(RIT_IRQn);

	while(1);
	return 1;
}
Esempio n. 3
0
void RIT_init(int interval)
{
	RIT_Init(LPC_RIT);	
	RIT_TimerConfig(LPC_RIT, interval);
	RIT_Cmd(LPC_RIT, ENABLE);

    NVIC_EnableIRQ(RIT_IRQn);
}
/********************************************************************//**
* @brief		Initializes the RITx peripheral according to the specified
*               parameters.
* @param[in]	RITx	  RIT peripheral selected, should be:
*   			- LPC_RIT: RIT peripheral
* @param[in]	Interval  Time interval in millisecond
* @return 		None
*********************************************************************/
void RIT_Config(LPC_RIT_TypeDef *RITx, uint32_t time_interval)
{
	RIT_Init(RITx);
			/* Configure time_interval for RIT
			 * In this case: time_interval = 1000 ms = 1s
			 * So, RIT will generate interrupt each 1s
			 */
	RIT_TimerConfig(RITx,time_interval);
	NVIC_EnableIRQ(RIT_IRQn);
}
Esempio n. 5
0
int _RIT_Init(uint8_t * args)
{
    uint8_t * arg_ptr;
    LPC_RIT_TypeDef* RITx;

    if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
    RITx = (LPC_RIT_TypeDef*) strtoul((char *) arg_ptr, NULL, 16);

    RIT_Init(RITx);
    return 0;
}
Esempio n. 6
0
/*********************************************************************//**
 * @brief	Main I2S program body
 **********************************************************************/
int c_entry (void) {                       /* Main Program  */
	RIT_CMP_VAL  value;
	PINSEL_CFG_Type PinCfg;

	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

	debug_frmwrk_init();
	 _DBG(menu);

	value.CMPVAL = 10000000;
	value.COUNTVAL = 0x00000000;
	value.MASKVAL = 0x00000000;
	RIT_Init(LPC_RIT);
	RIT_TimerConfig(LPC_RIT,&value);
	RIT_TimerClearCmd(LPC_RIT,ENABLE);

	_DBG("The value compare is: ");
	_DBD32(value.CMPVAL); _DBG_(" system tick");

	//Config P2.2 as GPO2.2
	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 2;
	PinCfg.Pinnum = 2;
	PINSEL_ConfigPin(&PinCfg);

	//turn on LED2.2
	GPIO_SetDir(2,(1<<2),1);
	GPIO_SetValue(2,(1<<2));

	NVIC_EnableIRQ(RIT_IRQn);

	while(1);
	return 1;
}
Esempio n. 7
0
void LED_init(){
	//TODO lsb first spi mode 0 0?
	
	GPIO_SetDir(LED_OE_PORT, LED_OE_BIT, 1);
	GPIO_SetValue(LED_OE_PORT, LED_OE_BIT);

	GPIO_SetDir(LED_LE_PORT, LED_LE_BIT, 1);
	GPIO_SetValue(LED_LE_PORT, LED_LE_BIT);

	GPIO_SetDir(WF_HIBERNATE_PORT, WF_HIBERNATE_BIT, 0);
	GPIO_SetValu(WF_HIBERNATE_PORT, WF_HIBERNATE_BIT);

	// Initialize SPI pin connect
	PINSEL_CFG_Type PinCfg;
	SSP_CFG_Type SSP_ConfigStruct;
	/* SCK1 */
	PinCfg.Funcnum   = PINSEL_FUNC_2;
	PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	PinCfg.Pinmode   = PINSEL_PINMODE_PULLDOWN;
	PinCfg.Pinnum    = LED_SCK_PIN;
	PinCfg.Portnum   = LED_SCK_PORT;
	PINSEL_ConfigPin(&PinCfg);
	/* MISO1 */
	PinCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
	PinCfg.Pinnum    = LED_MISO_PIN;
	PinCfg.Portnum   = LED_MISO_PORT;
	PINSEL_ConfigPin(&PinCfg);
	/* MOSI1 */
	PinCfg.Pinnum    = LED_MOSI_PIN;
	PinCfg.Portnum   = LED_MOSI_PORT;
	PINSEL_ConfigPin(&PinCfg);

	/* initialize SSP configuration structure */
	SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST;
	SSP_ConfigStruct.CPOL = SSP_CPOL_HI;
	SSP_ConfigStruct.ClockRate = 10000000; /* TLC5927 max freq = 30Mhz */
	SSP_ConfigStruct.Databit = SSP_DATABIT_16;
	SSP_ConfigStruct.Mode = SSP_MASTER_MODE;
	SSP_ConfigStruct.FrameFormat = SSP_FRAME_SPI;
	SSP_Init(LPC_SSP0, &SSP_ConfigStruct);

	RIT_Init(LPC_RIT);
	RIT_TimerConfig(LPC_RIT, TIME_INTERVAL); //TODO: decide on time interval
	NVIC_SetPriority(LPC_RIT, 0); // set according to main.c
	NVIC_EnableIRQ(LPC_RIT);

	/* Enable SSP peripheral */
	SSP_Cmd(LPC_SSP0, ENABLE);

}
Esempio n. 8
0
void LedColorInit(void)
{
	r_cnt = 0;
	g_cnt = 0;
	b_cnt = 0;
	base_cnt = 0;

	c_idx = 0;		/* Color index */

	/* Color initialization */
	color[0].r = 20;
	color[0].g = 0;
	color[0].b = 0;

	color[1].r = 15;
	color[1].g = 2;
	color[1].b = 2;

	color[2].r = 15;
	color[2].g = 2;
	color[2].b = 0;

	color[3].r = 15;
	color[3].g = 0;
	color[3].b = 2;

	color[4].r = 10;
	color[4].g = 0;
	color[4].b = 5;

	color[5].r = 0;
	color[5].g = 20;
	color[5].b = 0;

	color[6].r = 5;
	color[6].g = 15;
	color[6].b = 0;

	color[7].r = 3;
	color[7].g = 20;
	color[7].b = 3;

	color[8].r = 0;
	color[8].g = 15;
	color[8].b = 2;

	color[9].r = 5;
	color[9].g = 20;
	color[9].b = 10;

	color[10].r = 0;
	color[10].g = 0;
	color[10].b = 20;

	color[11].r = 5;
	color[11].g = 0;
	color[11].b = 15;

	color[12].r = 0;
	color[12].g = 10;
	color[12].b = 20;

	color[13].r = 15;
	color[13].g = 0;
	color[13].b = 20;

	color[14].r = 0;
	color[14].g = 15;
	color[14].b = 20;

	color[15].r = 20;
	color[15].g = 5;
	color[15].b = 20;

	/* Initialize drivers */
	LED_Init();
	RIT_Init(COLOR_TIMER_BASE);

	/* Turn off RGB led */
	LED_TurnOff(LED_RGB_R);
	LED_TurnOff(LED_RGB_G);
	LED_TurnOff(LED_RGB_B);
}