Example #1
0
void EINT2_IRQHandler(void)
{
  /* clear the EINT2 flag */
  EXTI_ClearEXTIFlag(EXTI_EINT2);
  GPIO_ClearInt(FPGA_RST_SW_PORT, 0x01 << FPGA_RST_SW);
  reset_FPGA();
}
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void c_entry (void)
{
	EXTI_InitTypeDef EXTICfg;

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

	// print welcome screen
	print_menu();

	/* Initialize EXT pin and registers
	 * P2.10 as /EINT0
	 */
	PINSEL_ConfigPin(2,10,1);

	EXTI_Init();

	EXTICfg.EXTI_Line = EXTI_EINT0;
	/* edge sensitive */
	EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
	EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
	EXTI_ClearEXTIFlag(EXTI_EINT0);
	EXTI_Config(&EXTICfg);

	NVIC_SetPriorityGrouping(4);
	NVIC_SetPriority(EINT0_IRQn, 0);
	NVIC_EnableIRQ(EINT0_IRQn);

	_DBG_("Press '1' to enter system in deep sleep mode.\n\r"\
		  "If you want to wake-up the system, press INT/WAKE-UP button.");
	while(_DG !='1')
	{
		_DBG_("I'm waiting...\n\r");
	}

	_DBG_("I'm sleeping...");
	// Enter target deep sleep mode
	CLKPWR_DeepSleep();
	SystemInit();
	debug_frmwrk_init();

	// MCU will be here after waking up
	_DBG_("\n\r-------- I'm wake up! -------- ");
	while (1);
}
/*********************************************************************//**
 * @brief 		External interrupt 0 handler
 * 				This interrupt occurs when pressing button INT0
 * @param		None
 * @return 		None
 ***********************************************************************/
void EINT0_IRQHandler(void)
{
	uint8_t i;

	EXTI_ClearEXTIFlag(EXTI_EINT0);

	for (i = 0; i < 10; i++)
	{
		GPIO_SetValue(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK);

		delay();

		GPIO_ClearValue(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK);

		delay();
	}
}
/*********************************************************************//**
 * @brief		Print menu
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void EINT0_IRQHandler(void)
{
	EXTI_ClearEXTIFlag(EXTI_EINT0);

	toggle = ((toggle == TRUE) ? FALSE:TRUE);

#ifdef LPC177x_8x_ADC_BURST_MULTI
	if(toggle)
	{
		ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,ENABLE);

		//Turn on LED -> indicate that extended channel was enable
		GPIO_ClearValue(LED_PORT, LED_PIN);
	}
	else
	{
		ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,DISABLE);

		// Turn off LED ->indicate that extended channel was disable
		GPIO_SetValue(LED_PORT, LED_PIN);
	}
#endif
}
Example #5
0
void runHandler()
{
	EXTI_ClearEXTIFlag(EXTI_EINT1);
	doSleep = false;
}
Example #6
0
OpenOBC::OpenOBC() : displayMode(reinterpret_cast<volatile DisplayMode_Type&>(LPC_RTC->GPREG0)), averageLitresPer100km(reinterpret_cast<volatile float&>(LPC_RTC->GPREG1)), averageFuelConsumptionSeconds(reinterpret_cast<volatile uint32_t&>(LPC_RTC->GPREG2))
{
	wdt.start(10);
	GPIO_IntDisable(0, 0xffffffff, 0);
	GPIO_IntDisable(0, 0xffffffff, 1);
	GPIO_IntDisable(2, 0xffffffff, 0);
	GPIO_IntDisable(2, 0xffffffff, 1);

	//enable bus, usage, and memmanage faults
	SCB->SHCSR |= (1<<18) | (1<<17) | (1<<16);
	
	idle = new IO(2, 0, true);
	isr = new IO(2, 1, true);
	obcS = this;
	doHardwareTest = false;
	
	callback = new Callback();
// 	callback->addCallback(this, &OpenOBC::buttonMemo, 10000);
	
	__enable_irq();
	SysTick_Config(SystemCoreClock/1000 - 1); //interrupt period 1ms
	debug = new Debug(DEBUG_TX_PORTNUM, DEBUG_TX_PINNUM, DEBUG_RX_PORTNUM, DEBUG_RX_PINNUM, DEBUG_BAUD, &interruptManager); debugS = debug;

// 	printf("-"); fflush(stdout); delay(250); printf("-"); fflush(stdout); delay(250); printf("-"); fflush(stdout); delay(250); printf(">\r\n"); delay(250);
	printf("--->\r\n");
	printf("clock speed: %i MHz\r\n", SystemCoreClock / 1000000);
	printf("stack: 0x%lx heap: 0x%lx free: %li\r\n", get_stack_top(), get_heap_end(), get_mem_free());

	vrefEn = new IO(VREF_EN_PORT, VREF_EN_PIN, true, false);
	
	//spi coniguration
	spi0 = new SPI(SPI0_MOSI_PORT, SPI0_MOSI_PIN, SPI0_MISO_PORT, SPI0_MISO_PIN, SPI0_SCK_PORT, SPI0_SCK_PIN);
	spi1 = new SPI(SPI1_MOSI_PORT, SPI1_MOSI_PIN, SPI1_MISO_PORT, SPI1_MISO_PIN, SPI1_SCK_PORT, SPI1_SCK_PIN);
	
	//i2c configuration
	i2c0 = new I2C(I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SCL_PORT, I2C0_SCL_PIN);
	i2c1 = new I2C(I2C1_SDA_PORT, I2C1_SDA_PIN, I2C1_SCL_PORT, I2C1_SCL_PIN);
	
	//i/o expander configuration
	Input* io0Interrupt = new Input(PCA95XX_INTERRUPT_PORT, PCA95XX_INTERRUPT_PIN);
	io = new PCA95xx(*i2c0, PCA95XX_ADDRESS, *io0Interrupt, 400000);
	codeLed = new PCA95xxPin(*io, CODE_LED_PORT, CODE_LED_PIN, true);
	limitLed = new PCA95xxPin(*io, LIMIT_LED_PORT, LIMIT_LED_PIN, true);
	timerLed = new PCA95xxPin(*io, TIMER_LED_PORT, TIMER_LED_PIN, true);
	ccmLight = new PCA95xxPin(*io, CCM_LIGHT_PORT, CCM_LIGHT_PIN, true);
	chime0 = new PCA95xxPin(*io, CHIME0_PORT, CHIME0_PIN, true);
	chime1 = new PCA95xxPin(*io, CHIME1_PORT, CHIME1_PIN, true);
	ventilation = new PCA95xxPin(*io, VENTILATION_PORT, VENTILATION_PIN, true);
	antitheftHorn = new PCA95xxPin(*io, ANTITHEFT_HORN_PORT, ANTITHEFT_HORN_PIN, true);
	ews = new PCA95xxPin(*io, EWS_PORT, EWS_PIN, true);
	out0 = new PCA95xxPin(*io, OUT0_PORT, OUT0_PIN, true);
	out1 = new PCA95xxPin(*io, OUT1_PORT, OUT1_PIN, true);
	out2 = new PCA95xxPin(*io, OUT2_PORT, OUT2_PIN, true);
	out3 = new PCA95xxPin(*io, OUT3_PORT, OUT3_PIN, true);
	io0 = new PCA95xxPin(*io, IO0_PORT, IO0_PIN, false);
	io1 = new PCA95xxPin(*io, IO1_PORT, IO1_PIN, false);
	
	//lcd configuration
	lcdBiasEn = new PCA95xxPin(*io, LCD_BIAS_EN_PORT, LCD_BIAS_EN_PIN, true);
	lcdReset = new IO(LCD_RESET_PORT, LCD_RESET_PIN, false);
// 	IO lcdBias(LCD_BIASCLOCK_PORT, LCD_BIASCLOCK_PIN, true);
	lcdBiasClock = new PWM(LCD_BIASCLOCK_PORT, LCD_BIASCLOCK_PIN, .99);
	IO* lcdSel = new IO(LCD_SELECT_PORT, LCD_SELECT_PIN, true);
	IO* lcdRefresh = new IO(LCD_REFRESH_PORT, LCD_REFRESH_PIN, false);
	IO* lcdUnk0 = new IO(LCD_UNK0_PORT, LCD_UNK0_PIN, true);
	IO* lcdUnk1 = new IO(LCD_UNK1_PORT, LCD_UNK1_PIN, false);
	lcd = new ObcLcd(*spi1, *lcdSel, *lcdRefresh, *lcdUnk0, *lcdUnk1);
	*lcdReset = true;
	*lcdBiasEn = true;
	
	//backlight configuration
	lcdLight = new IO(LCD_BACKLIGHT_PORT, LCD_BACKLIGHT_PIN, true);
	clockLight = new IO(CLOCK_BACKLIGHT_PORT, CLOCK_BACKLIGHT_PIN, true);
	auxLight = new IO(AUX_BACKLIGHT_PORT, AUX_BACKLIGHT_PIN, true);
	keypadLight = new IO(KEYPAD_BACKLIGHT_PORT, KEYPAD_BACKLIGHT_PIN, true);
// 	lcdBacklight = new PWM(LCD_BACKLIGHT_PORT, LCD_BACKLIGHT_PIN, .2);
// 	clockBacklight = new PWM(CLOCK_BACKLIGHT_PORT, CLOCK_BACKLIGHT_PIN);

	printf("openOBC firmware version: %s\r\n", GIT_VERSION);

	//config file configuration
	IO* sdcardCs = new IO(SDCARD_CS_PORT, SDCARD_CS_PIN);
	sd = new SDFS(*spi1, *sdcardCs);
	sd->mount("sd");
	config = new ConfigFile("/sd/openobc.cfg");
	//parse the config file; create one with default parameters if it doesn't exist
	if(config->readConfig() < 0)
	{
		int32_t result = config->writeConfig();
		if(result >= 0)
		{
			DEBUG("created new config file: %s\r\n", config->getFilename().c_str());
		}
		else
		{
			DEBUG("couldn't open file for writing: %s\r\n", config->getFilename().c_str());
		}
	}

	ObcBootupText::mode mode;
	std::string bootupTextMode = config->getValueByNameWithDefault("BootupTextMode", "GitHash");
	std::string bootupText;
	std::string customBootupText = config->getValueByNameWithDefault("CustomBootupText", "openOBC");
	uint bootupDelay = atoi(config->getValueByNameWithDefault("BootupDelay", "800").c_str());
	if(bootupTextMode == "GitHash")
	{
		mode = ObcBootupText::GitHash;
		bootupText = "openOBC " GIT_VERSION;
		lcd->printfClock("%s", GIT_TAG);
	}
	else if(bootupTextMode == "Custom")
	{
		mode = ObcBootupText::Custom;
		bootupText = customBootupText;
	}
	else if(bootupTextMode == "None")
	{
		mode = ObcBootupText::None;
		bootupText = "";
	}

	lcd->printf("%s", bootupText.c_str());

	ccmLight->on();
	codeLed->on();
	limitLed->on();
	timerLed->on();

	delay(bootupDelay);

	if(config->getValueByNameWithDefault("LogConsoleToFile", "no") == "yes")
		freopen("/sd/stdout.log", "a", stdout);

	//default config file parameters
	if(config->getValueByName("DefaultDisplayMode") == "")
		config->setValueByName("DefaultDisplayMode", "DISPLAY_LAST_DISPLAYMODE");
	if(config->getValueByName("BatteryVoltageCalibration") == "")
		config->setValueByName("BatteryVoltageCalibration", "1.0000");

	//default display mode configuration
	std::string defaultDisplayModeString = config->getValueByName("DefaultDisplayMode");
	if(defaultDisplayModeString == "DISPLAY_LAST_DISPLAYMODE")
		displayMode = displayMode;
	else if(defaultDisplayModeString == "DISPLAY_CHECK")
		displayMode = DISPLAY_CHECK;
	else if(defaultDisplayModeString == "DISPLAY_CONSUM1")
		displayMode = DISPLAY_CONSUM1;
	else if(defaultDisplayModeString == "DISPLAY_CONSUM2")
		displayMode = DISPLAY_CONSUM2;
	else if(defaultDisplayModeString == "DISPLAY_CONSUM3")
		displayMode = DISPLAY_CONSUM3;
	else if(defaultDisplayModeString == "DISPLAY_CONSUM4")
		displayMode = DISPLAY_CONSUM4;
	else if(defaultDisplayModeString == "DISPLAY_FREEMEM")
		displayMode = DISPLAY_FREEMEM;
	else if(defaultDisplayModeString == "DISPLAY_RANGE1")
		displayMode = DISPLAY_RANGE1;
	else if(defaultDisplayModeString == "DISPLAY_RANGE2")
		displayMode = DISPLAY_RANGE2;
	else if(defaultDisplayModeString == "DISPLAY_ACCELEROMETER")
		displayMode = DISPLAY_ACCELEROMETER;
	else if(defaultDisplayModeString == "DISPLAY_OPENOBC")
		displayMode = DISPLAY_OPENOBC;
	else if(defaultDisplayModeString == "DISPLAY_SPEED")
		displayMode = DISPLAY_SPEED;
	else if(defaultDisplayModeString == "DISPLAY_TEMP")
		displayMode = DISPLAY_TEMP;
	else if(defaultDisplayModeString == "DISPLAY_VOLTAGE")
		displayMode = DISPLAY_VOLTAGE;
	else
		displayMode = DISPLAY_OPENOBC;

	clockDisplayMode = CLOCKDISPLAY_CLOCK;

	batteryVoltageCalibration = atof(config->getValueByName("BatteryVoltageCalibration").c_str());

	//rtc configuration
	rtc = new RTC(); rtcS = rtc;
	RTC_TIME_Type settime;
	settime.YEAR = 2012;
	settime.MONTH = 9;
	settime.DOM = 20;
	settime.HOUR = 20;
	settime.MIN = 29;
	settime.SEC = 0;
// 	rtc->setTime(&settime);

	//accelerometer configuration
	Input* accelInterrupt = new Input(ACCEL_INTERRUPT_PORT, ACCEL_INTERRUPT_PIN);
	accel = new MMA845x(*i2c0, ACCEL_ADDRESS, *accelInterrupt, interruptManager);

	//ccm configuration
	Input* ccmData = new Input(CCM_DATA_PORT, CCM_DATA_PIN);
	IO* ccmClock = new IO(CCM_CLOCK_PORT, CCM_CLOCK_PIN);
	IO* ccmLatch = new IO(CCM_LATCH_PORT, CCM_LATCH_PIN);
	uint8_t ccmDisableMask = strtoul(config->getValueByNameWithDefault("ObcCheckDisableMask", "0x%02x", DEFAULT_CCM_DISABLE_MASK).c_str(), NULL, 0);
	uint8_t ccmInvertMask = strtoul(config->getValueByNameWithDefault("ObcCheckInvertMask", "0x%02x", DEFAULT_CCM_INVERT_MASK).c_str(), NULL, 0);

	ccm = new CheckControlModule(*ccmData, *ccmClock, *ccmLatch, ccmDisableMask, ccmInvertMask);

	//fuel level configuration
	Input* fuelLevelInput = new Input(FUEL_LEVEL_PORT, FUEL_LEVEL_PIN);
	fuelLevel = new FuelLevel(*fuelLevelInput, interruptManager);

	//stalk button configuration
	stalkButton = new Input(STALK_BUTTON_PORT, STALK_BUTTON_PIN, false);

	//brake switch configuration
	brakeSwitch = new Input(BRAKE_SWITCH_PORT, BRAKE_SWITCH_PIN);
	brakeCheck = new Input(BRAKE_CHECK_PORT, BRAKE_CHECK_PIN);

	//illumination input configuration
	illumination = new Input(ILLUMINATION_PORT, ILLUMINATION_PIN);

	//ambient light input configuration
	ambientLight = new Input(AMBIENT_LIGHT_PORT, AMBIENT_LIGHT_PIN);

	//diagnostics interface configuration
	klWake = new IO(KL_WAKE_PORT, KL_WAKE_PIN, true);
	kline = new Uart(KLINE_TX_PORTNUM, KLINE_TX_PINNUM, KLINE_RX_PORTNUM, KLINE_RX_PINNUM, KLINE_BAUD, UART_PARITY_EVEN, &interruptManager);
	lline = new Uart(LLINE_TX_PORTNUM, LLINE_TX_PINNUM, LLINE_RX_PORTNUM, LLINE_RX_PINNUM, LLINE_BAUD, UART_PARITY_EVEN, &interruptManager);
	DS2Bus* k = new Bus(*kline);
	DS2Bus* l = new Bus(*lline);
	diag = new DS2(*k, *l);
	disableComms = false;

// 	while(1)
// 	{
// 		int length = (rand() % 15) + 1;
// 		uint8_t* data = new uint8_t[length];
// 		uint32_t r = rand();
// 		for(int i = 0; i < length; i++)
// 			data[i] = r >> (i*2);
// 		DS2Packet packet(0x55, data, length, DS2_16BIT);
// 		delete[] data;
// 		k->write(packet.getRawPacket(), packet.getPacketLength());
// // 		diag->query(packet, DS2_K);
// 		delay(200);
// 	}

	zke = new E36ZKE4(*diag);
	srs = new E36SRS(*diag);
	ihkr = new E36IHKR(*diag);
	kombi = new E36Kombi(*diag);
	mk4 = new E36MK4(*diag);

	//ignition/run/on input configuration
	run = new Input(RUN_PORT, RUN_PIN);
	PINSEL_CFG_Type pincfg;
	pincfg.Funcnum = PINSEL_FUNC_1;
	pincfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	pincfg.Pinmode = PINSEL_PINMODE_TRISTATE;
	pincfg.Portnum = RUN_PORT;
	pincfg.Pinnum = RUN_PIN;
	interruptManager.attach(IRQ_EINT1, &runHandler); //do this first...
	PINSEL_ConfigPin(&pincfg); //because this immediately triggers an unwanted interrupt
	EXTI_Init();
	EXTI_InitTypeDef EXTICfg;
	EXTICfg.EXTI_Line = EXTI_EINT1;
	EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
	EXTICfg.EXTI_polarity = EXTI_POLARITY_HIGH_ACTIVE_OR_RISING_EDGE;
	EXTI_ClearEXTIFlag(EXTI_EINT1);
	EXTI_Config(&EXTICfg);
	NVIC_SetPriorityGrouping(4);
	NVIC_SetPriority(EINT1_IRQn, 0);
	NVIC_EnableIRQ(EINT1_IRQn);

	//fuel consumption configuration
	Input* fuelConsInput = new Input(FUEL_CONS_PORT, FUEL_CONS_PIN);
	fuelConsInput->setPullup();
	fuelCons = new FuelConsumption(*fuelConsInput, interruptManager);

	//speed configuration
	Input* speedPin = new Input(SPEED_PORT, SPEED_PIN);
// 	speedPin->setPullup(); //for bench use only
	speed = new SpeedInput(*speedPin, interruptManager);

	//sd card configuration
	sdcardDetect = new Input(SDCARD_DETECT_PORT, SDCARD_DETECT_PIN, false);
	sdcardDetect->setPullup();

	//keypad configuration
	IO* x0 = new IO(1, 20);
	IO* x1 = new IO(1, 21);
	IO* x2 = new IO(1, 22);
	IO* x3 = new IO(1, 25);
	IO* x4 = new IO(1, 27);
	Input* y0 = new Input(0, 0);
	Input* y1 = new Input(0, 1);
	Input* y2 = new Input(0, 10);
	Input* y3 = new Input(0, 11);
	keypad = new ObcKeypad(*x0, *x1, *x2, *x3, *x4, *y0, *y1, *y2, *y3, interruptManager);
	keypad->attach(BUTTON_1000, this, &OpenOBC::button1000);
	keypad->attach(BUTTON_100, this, &OpenOBC::button100);
	keypad->attach(BUTTON_10, this, &OpenOBC::button10);
	keypad->attach(BUTTON_1, this, &OpenOBC::button1);

	//analog input configuration
	batteryVoltage = new AnalogIn(BATTERY_VOLTAGE_PORT, BATTERY_VOLTAGE_PIN, REFERENCE_VOLTAGE, (10.0 + 1.0) / 1.0 * REFERENCE_VOLTAGE, atof(config->getValueByName("BatteryVoltageCalibration").c_str()));
	temperature = new AnalogIn(EXT_TEMP_PORT,EXT_TEMP_PIN, REFERENCE_VOLTAGE);
	analogIn1 = new AnalogIn(ANALOG_IN1_PORT, ANALOG_IN1_PIN, REFERENCE_VOLTAGE);
	analogIn2 = new AnalogIn(ANALOG_IN2_PORT, ANALOG_IN2_PIN, REFERENCE_VOLTAGE);
	vstart = new AnalogIn(VSTART_PORT, VSTART_PIN, REFERENCE_VOLTAGE, (10.0 + 1.0) / 1.0 * REFERENCE_VOLTAGE);

	//analog output configuration
	analogOut = new AnalogOut(ANALOG_OUT_PORT, ANALOG_OUT_PIN, REFERENCE_VOLTAGE);
	analogOut->writeVoltage(1.0);

// 	averageFuelConsumptionSeconds = 0;
// 	averageLitresPer100km = 0;

	debug->attach(this, &OpenOBC::uartHandler);

	if(wdt.wasReset())
	{
		printf("WATCHDOG RESET\r\n");
		lcd->printfClock("!!!!");
		Timer flashTimer;
		while((keypad->getKeys() & BUTTON_SET_MASK) != BUTTON_SET_MASK)
		{
			if(flashTimer.read_ms() <= 1500)
			{
				lcd->printf("WATCHDOG RESET");
			}
			else if(flashTimer.read_ms() <= 3000)
			{
				lcd->printf("push SET to continue");
			}
			else
			{
				flashTimer.start();
			}
			wdt.feed();
		}
		lcd->clear();
		lcd->clearClock();
	}

	coolantTemperature = 0;

	ui = new ObcUI(*lcd, *keypad, *config);
	keypad->attachRaw(ui, &ObcUI::handleButtonEvent);
	ui->addTask(new ObcClock(*this));
	ui->addTask(new ObcOdometer(*this));
	ui->addTask(new ObcSpeed(*this));
	ui->addTask(new ObcMemo(*this));
	ui->addTask(new ObcTemp(*this));
	ui->addTask(new ObcCheck(*this));
	ui->addTask(new ObcLimit(*this));
	ui->addTask(new ObcConsum(*this));
	ui->addTask(new ObcDist(*this));
	ui->addTask(new ObcRange(*this));
	ui->addTask(new ObcTimer(*this));
	ui->addTask(new ObcKmmls(*this));
	ui->addTask(new ObcCode(*this));

	ui->wake();

	lcd->printf("");
	lcd->printfClock("");
	ccmLight->off();
	codeLed->off();
	limitLed->off();
	timerLed->off();

// 	if(keypad->getKeys() == (BUTTON_1000_MASK | BUTTON_10_MASK))
// 	if(*stalkButton)
	if(doHardwareTest)
		hardwareTest();
	
	doSleepCheck = true;
}
/*********************************************************************//**
 * @brief		External interrupt 0 handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void EINT0_IRQHandler(void)
{
	  //clear the EINT0 flag
	  EXTI_ClearEXTIFlag(EXTI_EINT0);

}
Example #8
0
/*********************************************************************//**
 * @brief		External interrupt 3 handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void EINT2_IRQHandler(void)
{
	  //clear the EINT2 flag
	  EXTI_ClearEXTIFlag(2);
}
Example #9
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	PINSEL_CFG_Type PinCfg;
	EXTI_InitTypeDef EXTICfg;

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

	// print welcome screen
	print_menu();

	/* Initialize LEDs
	 * - If using MCB1700 board:
	 * 		LEDs: P1.28 and P1.29 are available
	 * - If using IAR1700 board:
	 * 		LEDs: LED1(P1.25) and LED2(P0.4) are available
	 * Turn off LEDs after initialize
	 */
	InitLED();

	/* Initialize EXT pin and registers
	 * - If using MCB1700 board: EXTI0 is configured
	 * - If using IAR1700 board: EXTI2 is configured
	 */
#ifdef MCB_LPC_1768
	/* P2.10 as /EINT0 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 10;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);
#elif defined (IAR_LPC_1768)
	/* P2.12 as /EINT2 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 12;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);
#endif

	EXTI_Init();

	EXTICfg.EXTI_Line = _EXTINT;
	/* edge sensitive */
	EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
	EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
	EXTI_ClearEXTIFlag(_EXTINT);
	EXTI_Config(&EXTICfg);

	NVIC_SetPriorityGrouping(4);
	NVIC_SetPriority(_EXT_IRQ, 0);
	NVIC_EnableIRQ(_EXT_IRQ);

	_DBG_("First LED is blinking in normal mode...\n\r"	\
		  "Press '1' to enter system in sleep mode.\n\r"\
		  "If you want to wake-up the system, press INT/WAKE-UP button.");
	while(_DG !='1')
	{
		//Blink first LED
#ifdef MCB_LPC_1768
		//blink LED P1.28
		GPIO_SetValue(1, (1<<28));
		delay();
		GPIO_ClearValue(1, (1<<28));
		delay();
#elif defined (IAR_LPC_1768)
		//blink LED1 (P1.25)
		GPIO_SetValue(1, (1<<25));
		delay();
		GPIO_ClearValue(1, (1<<25));
		delay();
#endif
	}

	_DBG_("Sleeping...");
	// Enter target power down mode
	CLKPWR_Sleep();

	// MCU will be here after waking up
	_DBG_("System wake-up! Second LED is blinking...");
	//turn off first LED
#ifdef MCB_LPC_1768
	GPIO_ClearValue(1, (1<<29));
#elif defined (IAR_LPC_1768)
	GPIO_SetValue(1, (1<<25));
#endif
	while (1)
	{
		//Blink second LED
#ifdef MCB_LPC_1768
		//blink LED P1.29
		GPIO_SetValue(1, (1<<29));
		delay();
		GPIO_ClearValue(1, (1<<29));
		delay();
#elif defined (IAR_LPC_1768)
		//blink LED2 (P0.4)
		GPIO_SetValue(0, (1<<4));
		delay();
		GPIO_ClearValue(0, (1<<4));
		delay();
#endif
	}
}
Example #10
0
void gpio_init() {

  SPI_CFG_Type spiInitialization;

  PINSEL_CFG_Type PinSelCfg;

/*-----------------------------------------------------------------
 *--------------------------PORT 0---------------------------------
 *-----------------------------------------------------------------
 */
  GPIO_SetDir(0, 0xFFFFFFFF, OUTPUT);
  PinSelCfg.Portnum = PINSEL_PORT_0;

//  PinSelCfg.Pinnum = PINSEL_PIN_0;
//  PinSelCfg.Funcnum = PINSEL_FUNC_3;
//  PinSelCfg.OpenDrain = 0;
//  PinSelCfg.Pinmode = 0;
//  PINSEL_ConfigPin(&PinSelCfg);
//
//  PinSelCfg.Pinnum = PINSEL_PIN_1;
//  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_2;
  PinSelCfg.Funcnum = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_3;
  PINSEL_ConfigPin(&PinSelCfg);


  GPIO_SetDir(0, 0x01<<22, INPUT);


  PinSelCfg.Pinnum = PINSEL_PIN_10;
  PinSelCfg.Funcnum = PINSEL_FUNC_2;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_11;
  PINSEL_ConfigPin(&PinSelCfg);


  //SET FMC_I2C1 in Hi-Z
  GPIO_SetDir(0, 0x01<<19, INPUT);
  GPIO_SetDir(0, 0x01<<20, INPUT);
//  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
//  PinSelCfg.Funcnum = PINSEL_FUNC_3;
//  PinSelCfg.Pinnum = PINSEL_PIN_19;
//  PINSEL_ConfigPin(&PinSelCfg);
//
//  PinSelCfg.Pinnum = PINSEL_PIN_20;
//  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Funcnum = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
  PinSelCfg.Pinnum = PINSEL_PIN_27;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_28;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_29;
  PinSelCfg.Funcnum = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_30;
  PINSEL_ConfigPin(&PinSelCfg);

/*-----------------------------------------------------------------
 *---------------------END OF PORT 0-------------------------------
 *-----------------------------------------------------------------
 *-----------------------------------------------------------------
 * ------------------------PORT 1----------------------------------
 * ----------------------------------------------------------------
 */
  GPIO_SetDir(1, 0xFFFFFFFF, OUTPUT);

  GPIO_SetDir(1, ( 0x01<<IPMI_GA0 | 0x01<<IPMI_GA1 | 0x01<<IPMI_GA2 ), INPUT);
  GPIO_SetValue(LED_PORT, (0x01<<_IPMI_BLLED|0x01<<_IPMI_LED1|0x01<<_IPMI_LED2) );

//  PinSelCfg.Portnum = PINSEL_PORT_1;
//  PinSelCfg.Pinnum = PINSEL_PIN_30;
//  PinSelCfg.Funcnum = PINSEL_FUNC_2;
//  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
//  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
//  PINSEL_ConfigPin(&PinSelCfg);


  GPIO_SetDir(ENA_PORT, 0x001<<ENA_PIN, INPUT);

  GPIO_SetDir(2, 0x0400, INPUT);

  GPIO_SetDir(IPMI_EJTHDL_PORT, 0x001<<IPMI_EJTHDL, INPUT);

  GPIO_SetDir(1, 0x01<<22, INPUT);

  GPIO_SetDir(PGOOD_PORT, 0x01<<PGOOD_PIN, INPUT);



  gpio_clr_gpio_pin(_IPMI_BLLED, LED_PORT);						// turn on blue LED ASAP
  gpio_clr_gpio_pin(UC_PWRENOUT, UC_PWRENOUT_PORT);               // turn off power enable



  PinSelCfg.Pinnum  = PINSEL_PIN_15;
  PinSelCfg.Portnum = PINSEL_PORT_0;
  PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP;
  PinSelCfg.Funcnum = PINSEL_FUNC_3;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;

  PINSEL_ConfigPin(&PinSelCfg);


  PinSelCfg.Pinnum  = PINSEL_PIN_18;

  PINSEL_ConfigPin(&PinSelCfg);

  GPIO_SetDir(1, 0x01<<26, OUTPUT);

  GPIO_SetValue(1, 0x01<<26);

  GPIO_SetDir(0, 0x01<<21, OUTPUT);
  GPIO_SetDir(0, 0x01<<16, OUTPUT);
  GPIO_SetValue(0, 0x01<<16);
  GPIO_SetValue(0, 0x01<<21);


  GPIO_SetDir(PORT_EN_0, 0x01<<EN_P1V2, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_P1V8, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC2_P3V3, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC1_P3V3, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EM_FMC1_P12V, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC2_P12V, OUTPUT);


  GPIO_SetDir(PORT_EN_1, 0x01<<EN_FMC1_PVADJ, OUTPUT);
  GPIO_SetDir(PORT_EN_1, 0x01<<EN_FMC2_PVADJ, OUTPUT);
  GPIO_SetDir(PORT_EN_1, 0x01<<EN_P3V3, OUTPUT);
  GPIO_SetDir(PORT_EN_1, 0x01<<EN_1V5_VTT, OUTPUT);

  GPIO_SetDir(PORT_EN_1, 0x01<<EN_RTM_CONN, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<RTM_PRESENCE, INPUT);

  GPIO_SetDir(PORT_EN_3, 0x01<<EN_P1V0, OUTPUT);

  setDC_DC_ConvertersON();

  spiInitialization.CPOL = SPI_CPOL_LO;
  spiInitialization.CPHA = SPI_CPHA_FIRST;
  spiInitialization.Databit = SPI_DATABIT_10;
  spiInitialization.DataOrder = SPI_DATA_MSB_FIRST;
  spiInitialization.ClockRate = 10000000;

  SPI_Init(LPC_SPI, &spiInitialization);

  LPC_SPI->SPCR = 0xA24;



  GPIO_ClearValue(0, 0x01<<16);
  SPI_SendData(LPC_SPI, 0x0125);
  while(! ( SPI_CheckStatus( SPI_GetStatus(LPC_SPI), SPI_STAT_SPIF) ));
  GPIO_SetValue(0, 0x01<<16);

  GPIO_ClearValue(0, 0x01<<16);
  SPI_SendData(LPC_SPI, 0x0025);
  while(! ( SPI_CheckStatus( SPI_GetStatus(LPC_SPI), SPI_STAT_SPIF) ));
  GPIO_SetValue(0, 0x01<<16);


  //SCANSTA JTAG
  GPIO_SetDir(2, 0x0FF, OUTPUT);

  GPIO_SetValue(2, 0x080);

  GPIO_ClearValue(2, 0x07F);

  SPI_ConfigStructInit(&spiInitialization);


  //FPGA_SPI
  GPIO_SetDir(1, 0x01<<20, INPUT);
  GPIO_SetDir(1, 0x01<<21, INPUT);
  GPIO_SetDir(1, 0x01<<23, INPUT);
  GPIO_SetDir(1, 0x01<<24, INPUT);
  // SET PROGRAM_B AS OUTPUT
  // AND SET THIS PIN HIGH
  GPIO_SetDir(0, 0x01<<17, INPUT);
  // SET DONE PIN AS INPUT
  // turn on pull-up
  GPIO_SetDir(0, 0x01<<22, INPUT);
  ////////////////////////////////////////
  // P0_6 - FCS_B - use as FPGA - RST
  ////////////////////////////////////////
  GPIO_SetDir(0, 0x01<<6, INPUT);
  //GPIO_ClearValue(0, 0x01<<6);
  ///////////////////////////////////////
  GPIO_SetDir(0, 0x01<<7, INPUT);
  GPIO_SetDir(0, 0x01<<8, INPUT);
#ifdef AMC_CPU_COM_Express
  GPIO_SetDir(0, 0x01<<9, OUTPUT);
#else
  GPIO_SetDir(0, 0x01<<9, INPUT);
#endif

  ///////////////////////////////////////
  //FMC STATUS PORTS
  ///////////////////////////////////////
  GPIO_SetDir(1, 0x1<<14, INPUT);
  GPIO_SetDir(1, 0x1<<15, INPUT);
  GPIO_SetDir(1, 0x1<<16, INPUT);
  GPIO_SetDir(1, 0x1<<17, INPUT);
  GPIO_SetDir(1, 0x1<<18, INPUT);
  GPIO_SetDir(1, 0x1<<19, INPUT);
  ///////////////////////////////////////

  // FPGA Reset Button
  EXTI_InitTypeDef EXTICfg;

      /* Initialize EXT pin and register */
      /* P2.12 as /EINT2*/
  PinSelCfg.Funcnum   = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
  PinSelCfg.Pinnum    = FPGA_RST_SW;
  PinSelCfg.Portnum   = FPGA_RST_SW_PORT;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Funcnum   = PINSEL_FUNC_0;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
  PinSelCfg.Pinnum    = FPGA_RESETn;
  PinSelCfg.Portnum   = FPGA_RESETn_PORT;
  PINSEL_ConfigPin(&PinSelCfg);
  GPIO_SetDir(FPGA_RESETn_PORT, 1<<FPGA_RESETn, OUTPUT);

  EXTI_Init();

  EXTICfg.EXTI_Line = EXTI_EINT2;
  EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
  EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
  EXTI_ClearEXTIFlag(EXTI_EINT2);
  EXTI_Config(&EXTICfg);
  GPIO_IntCmd(0, 0x01 << FPGA_RST_SW, 1);

  NVIC_SetPriorityGrouping(0);
  NVIC_SetPriority(EINT2_IRQn, 4);
  NVIC_EnableIRQ(EINT2_IRQn);

}
Example #11
0
void EINT1_IRQHandler (void){
	EXTI_ClearEXTIFlag(EXTI_EINT1);
	intr_occured = 1;
//	xprintf(".");
}
Example #12
0
void EINT3_IRQHandler (void){
	EXTI_ClearEXTIFlag(EXTI_EINT3);
	intr_occured = 1;
}