Пример #1
0
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t sysTickRate;

	SystemCoreClockUpdate();
	Board_Init();
	Board_LED_Set(0, false);
	Board_LED_Set(1, true);

	/* The sysTick counter only has 24 bits of precision, so it will
	   overflow quickly with a fast core clock. You can alter the
	   sysTick divider to generate slower sysTick clock rates. */
	Chip_Clock_SetSysTickClockDiv(1);

	/* A SysTick divider is present that scales the sysTick rate down
	   from the core clock. Using the SystemCoreClock variable as a
	   rate reference for the SysTick_Config() function won't work,
	   so get the sysTick rate by calling Chip_Clock_GetSysTickClockRate() */
	sysTickRate = Chip_Clock_GetSysTickClockRate();

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(sysTickRate / TICKRATE_HZ1);

	/* LEDs toggle in interrupt handlers */
	while (1) {
		__WFI();
	}

	return 0;
}
Пример #2
0
void SysTick_Handler(void)
{
	uint16_t dataADC;
	//int i;
	uint32_t currentPWM;
	currentPWM=LPC_PWM1->MR1;

	//Board_LED_Toggle(0);
	Board_LED_Set(0,1);


	//Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

	//while (Chip_ADC_ReadStatus(_LPC_ADC_ID, _ADC_CHANNLE, ADC_DR_DONE_STAT) != SET) {}
	/* Read ADC value */
	Chip_ADC_ReadValue(_LPC_ADC_ID, _ADC_CHANNLE, &dataADC);
	/* Print ADC value */
	//App_print_ADC_value(dataADC);
	/*
	if(rotation_time<MEMORY_CAPACITY){
		rotation_debug_holder[rotation_time]=(int) dataADC;
		rotation_time++;
	}
	*/

	rotation_time++;
	//if(rotation_counter<MEMORY_CAPACITY){	//debug line
    if(dataADC>sensor_threshold){
        if(rotation_phase==0){
            	//rotation_debug_holder[rotation_counter]=rotation_time;		//debug line
            	//rotation_debug_holder2[rotation_counter]=dataADC;				//debug line

            	if(currentPWM < (1000-regulation_step) && currentPWM > (regulation_step)){	//debug needed here
            		if(rotation_time>desired_rotation_time){
            			PWM_SetCycle(currentPWM+regulation_step,1000);
            		}else{
            			PWM_SetCycle(currentPWM-regulation_step,1000);
            		}
            	}
            rotation_counter++;
            rotation_time=0;
            rotation_phase=1;
        }

    }else{
    	rotation_phase = 0;
    }

	//}				//debug line

    if(rotation_time==1000){
    	if(currentPWM < (1000-regulation_step)){
    		PWM_SetCycle(currentPWM+10*regulation_step,1000);
    	}
    	rotation_time=0;
    }


	Board_LED_Set(0,0);
}
Пример #3
0
/* HID Set Report Request Callback. Called automatically on HID Set Report Request */
static ErrorCode_t Keyboard_SetReport(USBD_HANDLE_T hHid, USB_SETUP_PACKET *pSetup, uint8_t * *pBuffer, uint16_t length)
{
	/* we will reuse standard EP0Buf */
	if (length == 0) {
		return LPC_OK;
	}
	/* ReportID = SetupPacket.wValue.WB.L; */
	switch (pSetup->wValue.WB.H) {
	case HID_REPORT_OUTPUT:
		/*  If the USB host tells us to turn on the NUM LOCK LED,
		 *  then turn on LED#2.
		 */
		if (**pBuffer & 0x01) {
			Board_LED_Set(0, 1);
		}
		else {
			Board_LED_Set(0, 0);
		}
		break;

	case HID_REPORT_INPUT:				/* Not Supported */
	case HID_REPORT_FEATURE:			/* Not Supported */
		return ERR_USBD_STALL;
	}
	return LPC_OK;
}
Пример #4
0
/* UART ROM error handler */
static void uartrom_error(UART_HANDLE_T hUART, uint32_t err)
{
	switch (err) {
	case UART_ERROR_FRAME:
		/* No stop bit in uart frame; mismatched baud(?) or incorrect/short BREAK condition(?) */
		Board_LED_Set(0, 1);
		break;

	case UART_ERROR_PARITY:
		/* Parity error; mismatched baud(?) */
		while (1) {}

	case UART_ERROR_AUTOBAUD:
		/* Autobaud timeout error */
		while (1) {}

	case UART_ERROR_OVERRUN:
		/* Uart received character before ROM_UART_Receive() is called */
		Board_LED_Set(1, 1);
		break;

	case UART_ERROR_RXNOISE:
		/* Typically problem is with the baud rate and or Over sampling count */
		while (1) {}

	default:
		/* Control will never reach this */
		break;
	}
}
Пример #5
0
/**
 * @brief	Main UART program body
 * @return	Doesn't return
 */
int main(void)
{
	/* initialize the board */
	SystemCoreClockUpdate();
	Board_Init();

	Board_CMP_Init();

	/* initialize the CMP */
	Chip_CMP_Init();

	/* Power-up */
	Chip_CMP_EnableCurrentSrc(CMP_ENCTRL_ENABLE);
	Chip_CMP_EnableBandGap(CMP_ENCTRL_ENABLE);
	Chip_CMP_Enable(CMP_ID, CMP_ENCTRL_ENABLE);
	
	/* Positive and negative references, both edges, no hysteresis */
	Chip_CMP_SetPosVoltRef(CMP_ID, CMP_INPUT_CMPx_IN0);
	Chip_CMP_SetNegVoltRef(CMP_ID, CMP_INPUT_INTERNAL_09VBG);
	Chip_CMP_SetHysteresis(CMP_ID, CMP_HYS_NONE);
	
	while (1) {
		if (Chip_CMP_GetCmpStatus(CMP_ID)) {
			Board_LED_Set(0, false);
		}
		else {
			Board_LED_Set(0, true);
		}
	}

	return 0;
}
Пример #6
0
void exit_error(int error_code) {
	taskDISABLE_INTERRUPTS();
	Board_LED_Set(0, false);
	Board_LED_Set(1, false);
	Board_LED_Set(2, false);
	blink_error_code(error_code);
	exit(error_code);
}
Пример #7
0
/**
 * @brief	main routine for timer example
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t timerBaseClock;

	SystemCoreClockUpdate();
	Board_Init();
	Board_LED_Set(0, false);
	Board_LED_Set(1, false);

	/* Initialize Timer 0 and Timer 1 */
	Chip_TIMER_Init(LPC_TIMER0);
	Chip_TIMER_Init(LPC_TIMER1);

	/* Setup prescale value on Timer 0 to PCLK */
	Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);
	/* Setup prescale value on Timer 1 for lower resolution */
	Chip_TIMER_PrescaleSet(LPC_TIMER1, PRESCALE_HZ2);

	/* Reset timers */
	Chip_TIMER_Reset(LPC_TIMER0);
	Chip_TIMER_Reset(LPC_TIMER1);

	/* Enable both timers to generate interrupts when time matches */
	Chip_TIMER_MatchEnableInt(LPC_TIMER0, 1);
	Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);

	/* Get rate of timer base clock */
	timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();

	/* Setup Timer 0 for a match every 1s */
	Chip_TIMER_SetMatch(LPC_TIMER0, 1, (timerBaseClock / TICKRATE_HZ1));

	/* Setup Timer 1 for a match twice in a second */
	Chip_TIMER_SetMatch(LPC_TIMER1, 1, (timerBaseClock / ((PRESCALE_HZ2 + 1) * TICKRATE_HZ2)) );

	/* Setup both timers to restart when match occurs */
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1);

	/* Start both timers */
	Chip_TIMER_Enable(LPC_TIMER0);
	Chip_TIMER_Enable(LPC_TIMER1);

	/* Clear both timers of any pending interrupts */
	NVIC_ClearPendingIRQ(CT32B0_IRQn);
	NVIC_ClearPendingIRQ(CT32B1_IRQn);

	/* Enable both timer interrupts */
	NVIC_EnableIRQ(CT32B0_IRQn);
	NVIC_EnableIRQ(CT32B1_IRQn);

	/* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
	while (1) {
		__WFI();
	}

	return 0;
}
Пример #8
0
inline void Set_LED(uint32_t LED_On_Off)
{
	if(LED_On_Off==0)
	{
		Board_LED_Set(0, false);
	}
	else
	{
		Board_LED_Set(0, true);
	}
}
Пример #9
0
inline void Toggle_LED(void)
{
	if(Board_LED_Test(0)!=false)
	{
		Board_LED_Set(0, false);
	}
	else
	{
		Board_LED_Set(0, true);
	}
}
Пример #10
0
void TIMER1_IRQHandler(void)
{
    if (Chip_TIMER_MatchPending(LPC_TIMER1, 0)) {
        Chip_TIMER_ClearMatch(LPC_TIMER1, 0);
        Board_LED_Set(0, 1);
    }
    if (Chip_TIMER_MatchPending(LPC_TIMER1, 1)) {
        Chip_TIMER_ClearMatch(LPC_TIMER1, 1);
        Board_LED_Set(0, 0);
    }
}
Пример #11
0
/* Function to blink the LED to show the error code
 * caused by M0 image boot failure
 */
static void booting_m0_failure(uint32_t msec)
{
	int32_t cnt = 60000 / (msec * 2);
	DEBUGSTR("ERROR: Boot failure!!\r\n");
	while (cnt--) {
		Board_LED_Set(ERROR_LED, 1);
		MSleep(msec);
		Board_LED_Set(ERROR_LED, 0);
		MSleep(msec);
	}
}
Пример #12
0
static void taskBlink(void * p) {
	portTickType ticks;
	tiempoOprimido = 100;
	uint32_t periodo = 1000;
	while (1) {
		ticks = xTaskGetTickCount();
		Board_LED_Set(LED3, 1);
		vTaskDelayUntil(&ticks, tiempoOprimido/portTICK_RATE_MS);
		Board_LED_Set(LED3, 0);
		vTaskDelayUntil(&ticks, (periodo-tiempoOprimido)/portTICK_RATE_MS);
	}
}
Пример #13
0
void SysTick_Handler(void)
{
	//Board_LED_Set(BOARD_LED1_GREEN,true);
	if (systick_counter==0xffffffff) systick_rollover_counter += 1;
	systick_counter += 1;

	if (systick_delay_counter!=0) systick_delay_counter -= 1;

	systick_seconds_counter += 1;
	if (systick_seconds_counter>=SYSTICK_RATE_HZ)
	{
		systick_seconds_counter = 0;
		SysTick_Seconds();
	}

	systick_led_counter -= 1;
	if (systick_led_counter==0)
	{
		systick_led_counter = LED_BLINK_RATE;
		//Board_LED_Toggle(BOARD_LED1_RED);
	}

//	loop_priority_high();
	keyboard_scan_encoders();
//	Board_LED_Set(BOARD_LED1_GREEN,false);

	if (systick_led1_green_counter>0)
	{
		systick_led1_green_counter -= 1;
		if (systick_led1_green_counter==0)
		{
			Board_LED_Set(BOARD_LED1_GREEN,BOARD_LED_OFF);
		}
	}

	if (systick_led1_red_counter>0)
	{
		systick_led1_red_counter -= 1;
		if (systick_led1_red_counter==0)
		{
			Board_LED_Set(BOARD_LED1_RED,BOARD_LED_OFF);
		}
	}

	if (systick_led3_counter>0)
	{
		systick_led3_counter -= 1;
		if (systick_led3_counter==0)
		{
			Board_LED_Set(BOARD_LED3,0);
		}
	}
}
Пример #14
0
static void tareaLED(void* p) {
	xQueueHandle queue = p;
	long delay;
	while (1) {
		if (xQueueReceive(queue, &delay, portMAX_DELAY) == pdTRUE) {
			Board_LED_Set(0, 1);
			vTaskDelay(delay / portTICK_RATE_MS);
			Board_LED_Set(0, 0);
		} else {
			// timeout
		}
	}
}
Пример #15
0
 /**
 * @brief	Main entry point
 * @return	Nothing
 */
int main(void)
{
	SPIFIobj *obj = &spifi_obj;
	uint32_t spifi_clk_mhz;
	SPIFIopers opers;
	int ret;
	spifi_rom_init(spifi);
	
	/* Initialize the board & LEDs for error indication */
	Board_Init();
	
	/* Since this code runs from SPIFI no special initialization required here */
	prepare_write_data(data_buffer, sizeof(data_buffer));

	spifi_clk_mhz = Chip_Clock_GetRate(CLK_MX_SPIFI) / 1000000;
	
	/* Typical time tCS is 20 ns min, we give 200 ns to be on safer side */
	if (spifi_init(obj, spifi_clk_mhz / 5, S_RCVCLK | S_FULLCLK, spifi_clk_mhz)) {
		DEBUGSTR("Error initializing SPIFI interface!\r\n");
		Board_LED_Set(1, 1);
		goto end_prog;
	}
	
	/* Prepare the operations structure */
	memset(&opers, 0, sizeof(SPIFIopers));
	opers.dest = (char *) SPIFI_WRITE_SECTOR_OFFSET;
	opers.length = sizeof(data_buffer);
	/* opers.options = S_VERIFY_PROG; */
	
	/* NOTE: All interrupts must be disabled before calling program as
	 * any triggered interrupts might attempt to run a code from SPIFI area
	 */
	ret = spifi_program(obj, (char *) data_buffer, &opers);
	if (ret) {
		DEBUGOUT("Error 0x%x: Programming of data buffer to SPIFI Failed!\r\n", ret);
		Board_LED_Set(1, 1);
		goto end_prog;
	}
	DEBUGSTR("SPIFI Programming successful!\r\n");

	if (verify_spifi_data((uint8_t *) SPIFI_WRITE_SECTOR_ADDRESS, sizeof(data_buffer))) {
		DEBUGSTR("Error verifying the SPIFI data\r\n");
		Board_LED_Set(1, 1);
		goto end_prog;
	}
	Board_LED_Set(0, 1);
	DEBUGSTR("SPIFI Data verified!\r\n");

end_prog:
	while(1) {__WFI();}
}
Пример #16
0
int getUserAverage(const uint8_t array[], double *averagePointer,
		uint8_t measureNumber, int size) {

	int sum = 0;
	double userAverage = 0;
	uint8_t userAverageArray[10] = { 0 };
	int ledNumber;

	if (measureNumber > size) {
		measureNumber = size;
	}

	for (int i = 0; i < measureNumber; i++) {
		if (size < 0) {
			size = 9;
		}
		userAverageArray[i] = array[size - 1];
		sum += userAverageArray[i];
		size--;
	}

	for (int x = 0; x < 10; x++) {
		DEBUGOUT("userAverageArray[%d]=%d\n", x, userAverageArray[x]);
	}

	DEBUGOUT("User sum=%d\n", sum);
	userAverage = 1.0 * sum / measureNumber;

	DEBUGOUT("Average all: %lf\n", *averagePointer);
	DEBUGOUT("Average user: %lf\n", userAverage);

	if (*averagePointer == userAverage) {
		DEBUGOUT("Equal average!\n");
		Board_LED_Set(RED_LED, false);
		Board_LED_Set(GREEN_LED, true);
		Board_LED_Set(BLUE_LED, false);
		ledNumber = 1;
	}

	if (*averagePointer < userAverage) {
		DEBUGOUT("User average is higher!\n");
		Board_LED_Set(RED_LED, true);
		Board_LED_Set(GREEN_LED, false);
		Board_LED_Set(BLUE_LED, false);
		ledNumber = 0;
	}

	if (*averagePointer > userAverage) {
		DEBUGOUT("User average is lower!\n");
		Board_LED_Set(RED_LED, false);
		Board_LED_Set(GREEN_LED, false);
		Board_LED_Set(BLUE_LED, true);
		ledNumber = 2;
	}
	return ledNumber;
}
Пример #17
0
int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif
    uint8_t ip[4] = {0,};
    uint8_t gw[4] = {0,};
    uint8_t sn[4] = {0,};
    uint8_t dns[4] = {0,};

    SPI_Init();
    W5500_Init();
    //Net_Conf();

//    if ( SOCK_TCPS0 == socket(SOCK_TCPS1,Sn_MR_UDP,DHCP_CLIENT_PORT,0) ){
//    	printf("%d Socket open\n\r", SOCK_TCPS1);
//    }

    DHCP_init(SOCK_TCPS0, gDATABUF);
    while (DHCP_run() != DHCP_IP_LEASED)	printf("."),delay_cnt(10000);
    printf("\r\n");
    Board_LED_Set(0, false);
    Board_LED_Set(1, true);
    getIPfromDHCP(ip);
    getGWfromDHCP(gw);
	getSNfromDHCP(sn);
	getDNSfromDHCP(dns);

	printf("< DHCP IP Leased!! >\r\n");
	//printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", DHCP_CHADDR[0], DHCP_CHADDR[1], DHCP_CHADDR[2],  DHCP_CHADDR[3], DHCP_CHADDR[4], DHCP_CHADDR[0]);
	printf("IP	: %3d.%3d.%3d.%3d\r\n", ip[0], ip[1], ip[2], ip[3]);
	printf("GW	: %3d.%3d.%3d.%3d\r\n", gw[0], gw[1], gw[2], gw[3]);
	printf("SN	: %3d.%3d.%3d.%3d\r\n", sn[0], sn[1], sn[2], sn[3]);
	printf("DNS	: %3d.%3d.%3d.%3d\r\n", dns[0], dns[1], dns[2], dns[3]);
	DHCP_stop();

	DNS_Query();
    while(1) {

    }
    return 0 ;
}
Пример #18
0
static void task_duty() {
	static int delay;
	while (1) {
		portTickType tick = xTaskGetTickCount();
		Board_LED_Set(0, true);

		taskENTER_CRITICAL();
		delay = pushed_ticks;
		taskEXIT_CRITICAL();

		vTaskDelay(delay / portTICK_RATE_MS);

		Board_LED_Set(0, false);
		vTaskDelayUntil(&tick, 1000 / portTICK_RATE_MS);
	}
}
Пример #19
0
/**
 * @brief	Main program body
 * @return	Does not return
 */
int main(void)
{
	/* Generic Initialization */
	SystemCoreClockUpdate();

	/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
	   Chip_GPIO_Init is not called again */
	Board_Init();
	Board_LED_Set(0, false);

	/* Configure GPIO interrupt pin as input */
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_INTERRUPT_PORT, GPIO_INTERRUPT_PIN);

	/* Configure the GPIO interrupt */
	Chip_GPIOINT_SetIntFalling(LPC_GPIOINT, GPIO_INTERRUPT_PORT, 1 << GPIO_INTERRUPT_PIN);

	/* Enable interrupt in the NVIC */
	NVIC_ClearPendingIRQ(GPIO_INTERRUPT_NVIC_NAME);
	NVIC_EnableIRQ(GPIO_INTERRUPT_NVIC_NAME);

	/* Wait for interrupts - LED will toggle on each wakeup event */
	while (1) {
		__WFI();
	}

	return 0;
}
Пример #20
0
/* Sets up system hardware */
static void prvSetupHardware(void)
{
	Board_Init();

	/* Initial LED0 state is off */
	Board_LED_Set(0, false);
}
int main(void) {

#if defined (__USE_LPCOPEN)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif

    // TODO: insert code here

    Chip_SWM_MovablePortPinAssign(SWM_SWO_O, 1, 2);

	SysTick_Config(SystemCoreClock / 1000);

	printf("Started\n");
	Setup();

    i2cTest();

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;
    }
    return 0 ;
}
Пример #22
0
/**
 * Wait for message from M4 core
 */
void M4_IRQHandler(void)
{
	int i = 0;
	ipcex_msg_t msg;
	Chip_CREG_ClearM4Event();

	if (IPC_tryPopMsg(&msg) != QUEUE_VALID) {
		return;
	}

	switch (msg.id.pid) {
	case PID_BLINKY:
		while (msg.data0) {
			Board_LED_Set(i, msg.data1 & 1);
			msg.data0 >>= 1;
			msg.data1 >>= 1;
		}
		break;

	default:
		/* Not for us just ignore */
		DEBUGOUT("M0 Ignoring unknown message!");
	}

}
Пример #23
0
/**
 * @brief	Main routine for SPI example
 * @return	Function should not exit
 */
int main(void)
{
	/* Generic Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	/* Clear activity LED */
	Board_LED_Set(0, false);

	/* Setup SPI pin muxing */
	Init_SPI_PinMux();

	/* Allocate SPI handle, setup rate, and initialize clocking */
	setupSpiMaster();

	/* Enable SPI0 interrupt */
	NVIC_EnableIRQ(SPI0_IRQn);

	/* Loop forever */
	while (1) {
		/* Write simple message over SPI */
		WriteSpiMssg(xferArray, sizeof(xferArray) / sizeof(xferArray[0]));

		/* Toggle LED to show activity. */
		Board_LED_Toggle(0);
	}

	/* Code never reaches here. Only used to satisfy standard main() */
	return 0;
}
Пример #24
0
static void initHardware(void)
{
    SystemCoreClockUpdate();
    SysTick_Config(SystemCoreClock/1000);
    Board_Init();
    Board_LED_Set(0, false);

    /* Timer */
    Chip_TIMER_Init(LPC_TIMER1);
    Chip_TIMER_PrescaleSet(LPC_TIMER1,
#ifdef lpc1769
                           Chip_Clock_GetPeripheralClockRate(SYSCTL_PCLK_TIMER1) / 1000000 - 1
#else
                           Chip_Clock_GetRate(CLK_MX_TIMER1) / 1000000 - 1
#endif
                          );

    /* Match 0 (period) */
    Chip_TIMER_MatchEnableInt(LPC_TIMER1, 0);
    Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 0);
    Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 0);
    Chip_TIMER_SetMatch(LPC_TIMER1, 0, 1000);

    /* Match 1 (duty) */
    Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);
    Chip_TIMER_ResetOnMatchDisable(LPC_TIMER1, 1);
    Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 1);
    Chip_TIMER_SetMatch(LPC_TIMER1, 1, 100);

    Chip_TIMER_Reset(LPC_TIMER1);
    Chip_TIMER_Enable(LPC_TIMER1);

    NVIC_EnableIRQ(TIMER1_IRQn);
}
Пример #25
0
/**
 * @brief	I2C interrupt handler
 * @return	Nothing
 */
void I2C_IRQHandler(void)
{
	static bool ledState = false;

	/* Call I2C ISR function in ROM with the I2C handle */
	LPC_I2CD_API->i2c_isr_handler(i2cHandleSlave);

	/* Has a receive operation been completed? */
	if (RXintErrCode != -1) {
		if (RXintErrCode == LPC_OK) {
			ledState = (bool) recvBuff[1];
			Board_LED_Set(0, ledState);
		}

		/* Toggle LED state on next master read */
		tranBuff[0] = 1 - recvBuff[1];

		/* Setup transmit processing */
		sendI2CSlave();
		RXintErrCode = -1;
	}

	/* Has a transmit operation been completed? */
	if (TXintErrCode != -1) {
		if (TXintErrCode == LPC_OK) {
			/* Do something here if need. This example doesn't need
			   to do anything here */
			/* Number of bytes sent = resultTX.n_bytes_sent; */
		}

		/* Setup receive processing */
		readI2CSlave();
		TXintErrCode = -1;
	}
}
Пример #26
0
/**
 * @brief	Main routine for I2C example
 * @return	Function should not exit
 */
int main(void)
{
	/* Generic Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	Board_LED_Set(0, false);

	/* Setup I2C at the board level (usually pin muxing) */
	Init_I2C_PinMux();

	/* Allocate I2C handle, setup I2C rate, and initialize I2C
	   clocking */
	setupI2CSlave();

	/* Enable the interrupt for the I2C */
	NVIC_EnableIRQ(I2C_IRQn);

	/* Setup I2C receive slave mode - this will setup a
	   non-blocking I2C mode which will be handled via the I2C interrupt */
	readI2CSlave();	/* From master first */

	/* I2C slave handler loop - wait for requests from master and
	   receive or send data */
	while (1) {
		/* Sleep while waiting for I2C master requests */
		__WFI();

		/* All I2C slave processing is performed in the I2C IRQ
		   handler, so there is nothing to really do here */
	}

	return 0;
}
Пример #27
0
/**
 * @brief	RTC interrupt handler
 * @return	Nothing
 */
void RTC_IRQHandler(void)
{
	uint32_t sec;

	/* Toggle heart beat LED for each second field change interrupt */
	if (Chip_RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE)) {
		/* Clear pending interrupt */
		Chip_RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE);
		On0 = (bool) !On0;
		Board_LED_Set(0, On0);
	}

	/* display timestamp every 5 seconds in the background */
	sec = Chip_RTC_GetTime(LPC_RTC, RTC_TIMETYPE_SECOND);
	if (!(sec % 5)) {
		fIntervalReached = true;	/* set flag for background */
	}

	/* Check for alarm match */
	if (Chip_RTC_GetIntPending(LPC_RTC, RTC_INT_ALARM)) {
		/* Clear pending interrupt */
		Chip_RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);
		fAlarmTimeMatched = true;	/* set alarm handler flag */
	}
}
Пример #28
0
/**
 * @brief	main routine for ATIMER example
 * @return	Nothing (function should not exit)
 */
int main(void)
{
	bool On = false;

	SystemCoreClockUpdate();
	Board_Init();

	/* Init Alarm Timer with Preset Count for about 1s */
	Chip_ATIMER_Init(LPC_ATIMER, PresetCount);

	/* Init EVRT */
	Chip_EVRT_Init();

	/* Enable EVRT in order to be able to read the ATIMER interrupt */
	Chip_EVRT_ConfigIntSrcActiveType(EVRT_SRC_ATIMER, EVRT_SRC_ACTIVE_HIGH_LEVEL);

	/* Enable Alarm Timer Source */
	Chip_EVRT_SetUpIntSrc(EVRT_SRC_ATIMER, ENABLE);

	/* Enable NVIC */
	NVIC_EnableIRQ(EVENTROUTER_IRQn);

	/* Clear the interrupt states */
	ATIMER_ClearInts();

	/* Enable Alarm Timer */
	Chip_ATIMER_IntEnable(LPC_ATIMER);

	while (1) {
		/* Sleep until ATIMER fires */
		__WFI();
		On = (bool) !On;
		Board_LED_Set(1, On);
	}
}
Пример #29
0
int main(void) {
	SystemCoreClockUpdate();

	Board_Init();

	Board_LED_Set(0, false);

	// SW4 setup
	Chip_GPIO_SetDir(LPC_GPIO, 1, 31, false);
	sw4 = debounce_add(DEBOUNCE_TIME / DEBOUNCE_CYCLE, is_sw4_pushed, NULL);

	// RGB Rojo
	Chip_GPIO_SetDir(LPC_GPIO, 2, 0, true);

	// RGB Verde
	Chip_GPIO_SetDir(LPC_GPIO, 2, 1, true);

	// RGB Azul
	Chip_GPIO_SetDir(LPC_GPIO, 0, 26, true);

	queue_init(&queue, 1, EventQueue, AlarmTimeoutPush, AlarmTimeoutPop, MutexQueue);

	StartOS(AppMode1);

	while (1) {
	}

	return 0;
}
Пример #30
0
/* UART ROM event handler */
static void uartrom_event(UART_HANDLE_T hUART, uint32_t evt)
{
	switch (evt) {
	case UART_EVENT_BREAK:
		Board_LED_Set(2, 1);		/* TURN ON LED_2 when BREAK is received on RX line */
		break;

	case UART_EVENT_NOBREAK:
		Board_LED_Set(2, 0);		/* TURN OFF LED_2 when RX comes out of break */
		break;

	case UART_EVENT_TXIDLE:
		/* Can be used for flow control */
		/* This will be called when the TX shift register is done with
		   sending the last bit to uart line; event will be called only
		   after calling ROM_UART_SetCtrl(hUART, UART_TXIDLE_ON), event
		   can be turned off using ROM_UART_SetCtrl(hUART, UART_TXIDLE_OFF)
		 */
		break;

	case UART_EVENT_TXPAUSED:
		/* Event will happen after ROM_UART_SetCtrl(hUART, UART_TX_PAUSE) is
		   called. This event does not mean the the TX is idle, meaning, the
		   TX holding register might contain data (which is not loaded into
		   TX shift register anymore) and the the TX shift register is done
		   sending the data that it was sending when UART_TX_PAUSE was called.
		 */
		/* Can be used to implement flow control or safely send BREAK signal
		   without createing frame errors in the currently transmitted data
		 */
		break;

	case UART_EVENT_CTSHI:
		/* CTS line went from Low to High */
		/* Could be used for flow control or RS-485 implementations */
		break;

	case UART_EVENT_CTSLO:
		/* CTS line went from High to Low */
		/* Could be used for flow control or RS-485 implementations */
		break;

	default:
		while (1) {}	/* Control will never reach here */
	}
}