コード例 #1
0
ファイル: init.c プロジェクト: Draradech/wl_can
void init(void)
{
   // LEDs
   DDRC |= (1 << PC0);
   DDRD |= (1 << PD0);

   // Switch
   PORTD |= (1 << PD2);
   
   #ifdef DEBUG
   initUart();
   #endif

   initCan();
   
   // POC - led dimming
   POCR_RB = 4000;
   PCNF = (1 << POPA) | (1 << POPB);
   PMIC0 = (1 << POVEN0);
   PMIC1 = (1 << POVEN1);
   POCR0SA = 0;
   POCR0RA = 0;
   POCR1SA = 0;
   POCR1RA = 0;
   PCTL = (1 << PRUN);
   POC = (1 << POEN1A) | (1 << POEN0A);

   // Timer 0 - Mainloop
   TCCR0A = (1 << WGM01);      // CTC mode,
   TCCR0B = (1 << CS01);
   OCR0A  = 200 - 1;           // Prescalar 8, TOP 200 -> 10000 Hz

   TIMSK0 = (1 << OCIE0A);     // Output compare interrupt enable

   // Timer 1 - WSS Emulation
   TCCR1A = (1 << COM1B1) | (1 << COM1B0) | (1 << WGM10);
   TCCR1B = (1 << WGM13) | (1 << CS11);
   DDRC |= (1 << PC1);

   freq = 100;

   // Enable Interrupts
   sei();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: item28/tosqa-ssb
int main () {
    LPC_GPIO0->DIR |= 1<<7;     // LED is PIO0_7 on the LPCxpresso 11C24
    LPC_GPIO0->DATA &= ~(1<<7); // turn LED off

    delay(1000); // wait 1s after power-up before uploading to target

    initCan();

    /* Configure message object 1 to receive all 11-bit messages 0x5FD */
    static CCAN_MSG_OBJ_T msg;
    msg.msgobj = 1;
    msg.mode_id = 0x5FD;
    msg.mask = 0x7FF;
    LPC_CCAN_API->config_rxmsgobj(&msg);

    // read device type ("LPC1")
    uint32_t devType = sdoReadSegmented(0x1000, 0);
    if (memcmp(&devType, "LPC1", 4) != 0)
        blinkLed(4);

    // read 16-byte serial number
    // uint32_t uid[4];
    // uid[0] = sdoReadSegmented(0x5100, 1);
    // uid[1] = sdoReadSegmented(0x5100, 2);
    // uid[2] = sdoReadSegmented(0x5100, 3);
    // uid[3] = sdoReadSegmented(0x5100, 4);
    
    // unlock for upload
    uint16_t unlock = 23130;
    sdoWriteExpedited(0x5000, 0, unlock, sizeof unlock);    
    // prepare sectors
    sdoWriteExpedited(0x5020, 0, 0x0000, 2);
    // erase sectors
    sdoWriteExpedited(0x5030, 0, 0x0000, 2);

    if (getBootConfigByte() != 0) {
        // copy code to RAM buffer and add the boot config byte
        memset(codeBuf, 0xFF, sizeof codeBuf);
        memcpy(codeBuf, bootData, sizeof bootData);
        codeBuf[sizeof codeBuf-1] = getBootConfigByte();

        // start write to RAM
        sdoWriteExpedited(0x5015, 0, 0x10000800, 4); // ram address
        // upload code to RAM
        sdoWriteSegmented(0x1F50, 1, 0x1000);
        uint8_t toggle = 0;
        for (size_t i = 0; i < sizeof codeBuf; i += 7) {
            sdoWriteDataSegment(toggle, codeBuf + i, 7);
            toggle ^= 0x10;
        }

        // prepare sectors
        sdoWriteExpedited(0x5020, 0, 0x0000, 2);
        // copy ram to flash
        sdoWriteExpedited(0x5050, 1, 0x00000000, 4);    // flash address
        sdoWriteExpedited(0x5050, 2, 0x10000800, 4);    // ram address
        sdoWriteExpedited(0x5050, 3, 0x1000, 2);        // 4096 bytes
    }
    
    // G 0000
    sdoWriteExpedited(0x5070, 0, 0, 4);
    sdoWriteExpedited(0x1F51, 1, 1, 1);

    // 5 quick blips if there has been any CAN error, or steady blink if all ok
    blinkLed(error ? 5 : 0);

    return 0;
}
コード例 #3
0
ファイル: hardware.cpp プロジェクト: jmt42/rusefi
void initHardware(Logging *logger, Engine *engine) {
	engine_configuration_s *engineConfiguration = engine->engineConfiguration;
	efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration");
	board_configuration_s *boardConfiguration = &engineConfiguration->bc;

	printMsg(logger, "initHardware()");
	// todo: enable protection. it's disabled because it takes
	// 10 extra seconds to re-flash the chip
	//flashProtect();

	chMtxInit(&spiMtx);

#if EFI_HISTOGRAMS
	/**
	 * histograms is a data structure for CPU monitor, it does not depend on configuration
	 */
	initHistogramsModule();
#endif /* EFI_HISTOGRAMS */

	/**
	 * This is so early because we want to init logger
	 * which would be used while finding trigger synch index
	 * while config read
	 */
	initTriggerDecoder();

	/**
	 * We need the LED_ERROR pin even before we read configuration
	 */
	initPrimaryPins();

	if (hasFirmwareError()) {
		return;
	}

	initDataStructures(PASS_ENGINE_PARAMETER_F);

#if EFI_INTERNAL_FLASH

	palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);

	initFlash(engine);
	/**
	 * this call reads configuration from flash memory or sets default configuration
	 * if flash state does not look right.
	 */
	if (SHOULD_INGORE_FLASH()) {
		engineConfiguration->engineType = FORD_ASPIRE_1996;
		resetConfigurationExt(logger, engineConfiguration->engineType, engine);
		writeToFlash();
	} else {
		readFromFlash();
	}
#else
	engineConfiguration->engineType = FORD_ASPIRE_1996;
	resetConfigurationExt(logger, engineConfiguration->engineType, engineConfiguration, engineConfiguration2, boardConfiguration);
#endif /* EFI_INTERNAL_FLASH */

	if (hasFirmwareError()) {
		return;
	}

	mySetPadMode2("board test", boardConfiguration->boardTestModeJumperPin, PAL_MODE_INPUT_PULLUP);
	bool isBoardTestMode_b = GET_BOARD_TEST_MODE_VALUE();

	initAdcInputs(isBoardTestMode_b);

	if (isBoardTestMode_b) {
		// this method never returns
		initBoardTest();
	}

	initRtc();

	initOutputPins();

#if EFI_HIP_9011
	initHip9011();
#endif /* EFI_HIP_9011 */

#if EFI_MAX_31855
	initMax31855(boardConfiguration);
#endif /* EFI_MAX_31855 */

#if EFI_CAN_SUPPORT
	initCan();
#endif /* EFI_CAN_SUPPORT */

//	init_adc_mcp3208(&adcState, &SPID2);
//	requestAdcValue(&adcState, 0);

	// todo: figure out better startup logic
	initTriggerCentral(engine);

#if EFI_SHAFT_POSITION_INPUT
	initShaftPositionInputCapture();
#endif /* EFI_SHAFT_POSITION_INPUT */

	initSpiModules(boardConfiguration);

#if EFI_FILE_LOGGING
	initMmcCard();
#endif /* EFI_FILE_LOGGING */

//	initFixedLeds();

	//	initBooleanInputs();

#if EFI_UART_GPS
	initGps();
#endif

#if ADC_SNIFFER
	initAdcDriver();
#endif

#if EFI_HD44780_LCD
//	initI2Cmodule();
	lcd_HD44780_init();
	if (hasFirmwareError())
		return;

	lcd_HD44780_print_string(VCS_VERSION);

#endif /* EFI_HD44780_LCD */

	addConsoleActionII("i2c", sendI2Cbyte);

//	while (true) {
//		for (int addr = 0x20; addr < 0x28; addr++) {
//			sendI2Cbyte(addr, 0);
//			int err = i2cGetErrors(&I2CD1);
//			print("I2C: err=%x from %d\r\n", err, addr);
//			chThdSleepMilliseconds(5);
//			sendI2Cbyte(addr, 255);
//			chThdSleepMilliseconds(5);
//		}
//	}

	printMsg(logger, "initHardware() OK!");
}
コード例 #4
0
bool ForceTorqueCtrl::Init()
{
	initCan();
	//SetActiveCalibrationMatrix(0);
	//ReadCalibrationMatrix();
}
コード例 #5
0
ファイル: main.c プロジェクト: acranbury/ElevatorProject
void main(void) {
    char i, j;
	unsigned char txbuff[8] = "";
	word distance = 0;
	CANMessage message = { 0x00, 0x00, 0x00, {0}};
	unsigned char curFloor = 0;
	unsigned char elevatorDirection = 0;
	unsigned char callButtonsPressed[2][NUM_FLOORS] = { 0 };
	unsigned char panelButtonsPressed[NUM_FLOORS] = { 0 };
	unsigned char panicButton = 0;
	unsigned char elevatorTarget = 0;
	unsigned char targetFound = 0;

	timer_init();
	LCDinit();

	initCan();
	j=0;

	while (!(CANCTL0 & 0x10));

	CANRFLG = 0xC3;
	CANRIER = 0x01;

	//LCDprintf("Hello World");

	usonic_init();
	
	EnableInterrupts;

	for(;;) {
		LCDclear();
		
		
		
		//get elevator distance
		distance = usonic_getDistance();
		
		//generalized for NUM_FLOORS, for a given floor offset to the ground floor, and distance between floors (left in big if statement in case
		        //distance between floors is non-constant
		for(i=0; i< NUM_FLOORS; i++){
		   if (distance < (FLOOR_OFFSET + (FLOOR_DISTANCE*i) + ELEV_THRESHOLD) && distance > (FLOOR_OFFSET + (FLOOR_DISTANCE*i) - ELEV_THRESHOLD)) {
                //LCDprintf("1st Floor!\n %d mm", distance);
                curFloor = i+1;	
		   }
		}        
		 
        /*if (distance < (ELEV_1ST + ELEV_THRESHOLD) && distance > (ELEV_1ST - ELEV_THRESHOLD)) {
            //LCDprintf("1st Floor!\n %d mm", distance);
            curFloor = 1;
        } else if (distance < (ELEV_2ND + ELEV_THRESHOLD) && distance > (ELEV_2ND - ELEV_THRESHOLD)) {
            //LCDprintf("2nd Floor!\n %d mm", distance);  
            curFloor = 2;
    	} else if (distance < (ELEV_3RD + ELEV_THRESHOLD) && distance > (ELEV_3RD - ELEV_THRESHOLD)) {
            //LCDprintf("3rd Floor!\n %d mm", distance); 
            curFloor = 3; 
        } else if (distance < (ELEV_4TH + ELEV_THRESHOLD) && distance > (ELEV_4TH - ELEV_THRESHOLD)) {
    	    //LCDprintf("4th Floor!\n %d mm", distance);  
            curFloor = 4;
    	} else {
    	    //LCDprintf("Distance %d mm", distance);   
    	}                   */
		
    	if (elevatorTarget != curFloor) {
    	    if ((elevatorTarget - curFloor) > 0 ) { 
    	        elevatorDirection = DIR_UP;        
    	    } else {
    	        elevatorDirection = DIR_DOWN;
    	    }
    	    txbuff[0] = ELEV_LOCATION;
    	    txbuff[1] = curFloor;
    	    txbuff[2] = elevatorDirection;
      		
      		message.id = ELEVATOR_CAR_ID | FLOOR_1_ID | FLOOR_2_ID | FLOOR_3_ID;
      		message.priority = 0x00;
      		message.length = 8;
      		message.payload = txbuff;
      		
    	} else {   //elevatorTarget = curFloor, which means elevator is stationary   	    
    	    //elevatorDirection = DIR_STOPPED; //set direction to stationary
    	    txbuff[0] = ELEV_LOCATION;
    	    txbuff[1] = curFloor;
            txbuff[2] = elevatorDirection;
    	    
    	    message.id = ELEVATOR_CAR_ID | FLOOR_1_ID | FLOOR_2_ID | FLOOR_3_ID;
    	    message.priority = 0x00;
    	    message.length = 8;
    	    message.payload = txbuff;
    	   
    	    panelButtonsPressed[curFloor-1] = 0; //clear the panel floor button as we have reached the destination floor
    	    targetFound = 0; //clear the target found flag to find a new target
    	}
    	
    /*	j = (j+1) %3;
    	txbuff[0] = ELEV_LOCATION;
    	txbuff[1] = j+1;                            
    	txbuff[2] = DIR_UP;
    	message.id = BROADCAST_ID; //Broadcast
    	message.priority = 0;
    	message.length = 8;
    	message.payload = txbuff;*/	
		sendCanFrame(message);       
		
		if ( canRXFlag )  //have received a message from one of the various floor buttons, receive message and enter it into the required motor output.
		{
		    if (canRXData[0] == CALL_BTN_PRESS){
		        if(canRXData[2] == UP_CALL_BTN){
		            callButtonsPressed[UP_CALL_ROW][canRXData[1]-1] = 1;
		            LCDprintf("Call FLOOR %d Up", canRXData[1]);
		        }else {
		            callButtonsPressed[DOWN_CALL_ROW][canRXData[1]-1] = 1;
		            LCDprintf("Call FLOOR %d Down", canRXData[1]);
		        }
		        
		    } else if (canRXData[0] == PANEL_BTN_PRESS){
		        switch (canRXData[1]){
		            case PANEL_FLOOR_1:{
		                panelButtonsPressed[0] = 1;
						LCDprintf("Car FLOOR %d", canRXData[1]);
		                break;
		            }
		            case PANEL_FLOOR_2:{
		                panelButtonsPressed[1] = 1;
						LCDprintf("Car FLOOR %d", canRXData[1]);
		                break;
		            }
		            case PANEL_FLOOR_3:{
		                panelButtonsPressed[2] = 1;
						LCDprintf("Car FLOOR %d", canRXData[1]);
		                break;
		            }
		            case PANEL_FLOOR_4:{
		                panelButtonsPressed[3] = 1;
		                break;
		            }
		            case DOOR_CLOSE:{
						LCDprintf("Door Close");
		                break;
					}
		            case DOOR_OPEN:{
						LCDprintf("Door Open");
		                break;
					}
		            case EMERG_STOP:{
		                panicButton = 1;
		                break;
		            }
		            default:
		                break;
		        
		        }
		    } else if (canRXData[0] == ELEV_LOCATION){
		        LCDprintf("floor %d dir %d", canRXData[1], canRXData[2]);
		        
		        
		    } else if (canRXData[0] == ERROR_MSG){
		        
		    } //else ignore message
		    
		    //LCDprintf("Floor %d!\n %d mm", canRXData[0], distance);
			canRXFlag = 0;
		}
	    /*
	    //Logic to determine the current elevator target
	    if (targetFound == 0) {
	        elevatorTarget = curFloor; //set a back up target in case the target finding algorithm doesn't find any other targets
	        
    	    if (elevatorDirection == DIR_UP){    //Elevator is currently moving up, handle any up requests above elevator before moving down
    	        for(i=curFloor-1; i< NUM_FLOORS; i++){
    	            if(callButtonsPressed[UP_CALL_ROW][i] || panelButtonsPressed[i]){
    	                callButtonsPressed[UP_CALL_ROW][i] = 0;
    	                panelButtonsPressed[i] = 0;
    	                elevatorTarget = i+1;
    	                targetFound = 1;
    	                break;
    	            }
    	        }
    	        if (targetFound == 0) {             //No up requests above elevator current position, service any down requests, from the top floor first 
    	           for(i = NUM_FLOORS; i >= 0; i--){
    	                if(callButtonsPressed[DOWN_CALL_ROW][i] || panelButtonsPressed[i]){
    	                    callButtonsPressed[DOWN_CALL_ROW][i] = 0;
    	                    panelButtonsPressed[i] = 0;
    	                    elevatorTarget = i+1;
    	                    targetFound = 1;
    	                    break;
    	                }
    	           }
    	           if(targetFound == 0){                //no down requests found, service any up requests below the elevator's current floor
    	                for(i=0; i< curFloor-1; i++){
    	                    if(callButtonsPressed[UP_CALL_ROW][i]){
    	                        callButtonsPressed[UP_CALL_ROW][i] = 0;
    	                        elevatorTarget = i+1;
    	                        targetFound = 1;
    	                        break;
    	                    }
    	                }
    	           }
    	        }
    	    } else if (elevatorDirection == DIR_DOWN){    //Elevator currently moving down, handle any down requests below the elevator before moving back up
    	        for (i=curFloor-1; i >= 0; i--){
    	            if(callButtonsPressed[DOWN_CALL_ROW][i] || panelButtonsPressed[i]){
    	                callButtonsPressed[DOWN_CALL_ROW][i] = 0;
    	                panelButtonsPressed[i] = 0;
    	                elevatorTarget = i + 1;
    	                targetFound = 1;
    	                break;
    	            }
    	        }
    	        if (targetFound == 0) {             //No down requests below elevator current position, service any up requests, from the bottom floor first 
    	           for(i = 0; i < NUM_FLOORS; i++){
    	                if(callButtonsPressed[UP_CALL_ROW][i] || panelButtonsPressed[i]){
    	                    callButtonsPressed[UP_CALL_ROW][i] = 0;
    	                    panelButtonsPressed[i] = 0;
    	                    elevatorTarget = i+1;
    	                    targetFound = 1;
    	                    break;
    	                }
    	           }
    	           if(targetFound == 0){                //no up requests found, service any down requests above the elevator's current floor
    	                for(i=NUM_FLOORS; i >= curFloor-1; i--){
    	                    if(callButtonsPressed[DOWN_CALL_ROW][i]){
    	                        callButtonsPressed[DOWN_CALL_ROW][i] = 0;
    	                        elevatorTarget = i+1;
    	                        targetFound = 1;
    	                        break;
    	                    }
    	                }
    	           }
    	        }
    	    }
	    }*/
		if(panicButton){
		    LCDprintf("EMERGENCY!");
		}/* else if(targetFound){
		    LCDprintf("target floor: %d!", elevatorTarget);
		} else {
		    LCDprintf("No target");
		}  */           
		msleep(100);
  } 
}
コード例 #6
0
ファイル: hardware.cpp プロジェクト: jharvey/rusefi
void initHardware(Logging *l) {
	efiAssertVoid(CUSTOM_IH_STACK, getRemainingStack(chThdGetSelfX()) > 256, "init h");
	sharedLogger = l;
	engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr;
	efiAssertVoid(CUSTOM_EC_NULL, engineConfiguration!=NULL, "engineConfiguration");
	board_configuration_s *boardConfiguration = &engineConfiguration->bc;

	printMsg(sharedLogger, "initHardware()");
	// todo: enable protection. it's disabled because it takes
	// 10 extra seconds to re-flash the chip
	//flashProtect();

	chMtxObjectInit(&spiMtx);

#if EFI_HISTOGRAMS
	/**
	 * histograms is a data structure for CPU monitor, it does not depend on configuration
	 */
	initHistogramsModule();
#endif /* EFI_HISTOGRAMS */

	/**
	 * We need the LED_ERROR pin even before we read configuration
	 */
	initPrimaryPins();

	if (hasFirmwareError()) {
		return;
	}

#if EFI_INTERNAL_FLASH

	palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);

	initFlash(sharedLogger);
	/**
	 * this call reads configuration from flash memory or sets default configuration
	 * if flash state does not look right.
	 */
	if (SHOULD_INGORE_FLASH()) {
		engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
		resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
		writeToFlashNow();
	} else {
		readFromFlash();
	}
#else
	engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
	resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* EFI_INTERNAL_FLASH */

#if EFI_HD44780_LCD
//	initI2Cmodule();
	lcd_HD44780_init(sharedLogger);
	if (hasFirmwareError())
		return;

	lcd_HD44780_print_string(VCS_VERSION);

#endif /* EFI_HD44780_LCD */

	if (hasFirmwareError()) {
		return;
	}

#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
	initTriggerDecoder();
#endif

	bool isBoardTestMode_b;
	if (CONFIGB(boardTestModeJumperPin) != GPIO_UNASSIGNED) {
		efiSetPadMode("board test", CONFIGB(boardTestModeJumperPin),
		PAL_MODE_INPUT_PULLUP);
		isBoardTestMode_b = (!efiReadPin(CONFIGB(boardTestModeJumperPin)));

		// we can now relese this pin, it is actually used as output sometimes
		unmarkPin(CONFIGB(boardTestModeJumperPin));
	} else {
		isBoardTestMode_b = false;
	}

#if HAL_USE_ADC || defined(__DOXYGEN__)
	initAdcInputs(isBoardTestMode_b);
#endif

	if (isBoardTestMode_b) {
		// this method never returns
		initBoardTest();
	}

	initRtc();

	initOutputPins();

#if EFI_MAX_31855
	initMax31855(sharedLogger, getSpiDevice(CONFIGB(max31855spiDevice)), CONFIGB(max31855_cs));
#endif /* EFI_MAX_31855 */

#if EFI_CAN_SUPPORT
	initCan();
#endif /* EFI_CAN_SUPPORT */

//	init_adc_mcp3208(&adcState, &SPID2);
//	requestAdcValue(&adcState, 0);

#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
	// todo: figure out better startup logic
	initTriggerCentral(sharedLogger);
#endif /* EFI_SHAFT_POSITION_INPUT */

	turnOnHardware(sharedLogger);


#if HAL_USE_SPI || defined(__DOXYGEN__)
	initSpiModules(boardConfiguration);
#endif

#if EFI_HIP_9011 || defined(__DOXYGEN__)
	initHip9011(sharedLogger);
#endif /* EFI_HIP_9011 */

#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
	initMmcCard();
#endif /* EFI_FILE_LOGGING */

#if EFI_MEMS || defined(__DOXYGEN__)
	initAccelerometer(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif
//	initFixedLeds();


#if EFI_BOSCH_YAW || defined(__DOXYGEN__)
	initBoschYawRateSensor();
#endif /* EFI_BOSCH_YAW */

	//	initBooleanInputs();

#if EFI_UART_GPS || defined(__DOXYGEN__)
	initGps();
#endif

#if EFI_SERVO
	initServo();
#endif

#if ADC_SNIFFER || defined(__DOXYGEN__)
	initAdcDriver();
#endif

#if HAL_USE_I2C || defined(__DOXYGEN__)
	addConsoleActionII("i2c", sendI2Cbyte);
#endif


//	USBMassStorageDriver UMSD1;

//	while (true) {
//		for (int addr = 0x20; addr < 0x28; addr++) {
//			sendI2Cbyte(addr, 0);
//			int err = i2cGetErrors(&I2CD1);
//			print("I2C: err=%x from %d\r\n", err, addr);
//			chThdSleepMilliseconds(5);
//			sendI2Cbyte(addr, 255);
//			chThdSleepMilliseconds(5);
//		}
//	}

#if EFI_VEHICLE_SPEED || defined(__DOXYGEN__)
	initVehicleSpeed(sharedLogger);
#endif

#if EFI_CDM_INTEGRATION
	cdmIonInit();
#endif

#if HAL_USE_EXT || defined(__DOXYGEN__)
	initJoystick(sharedLogger);
#endif

	calcFastAdcIndexes();

	printMsg(sharedLogger, "initHardware() OK!");
}
コード例 #7
0
ファイル: main.c プロジェクト: arkaheb258/infineon
int main(void) {
	BOOL_T		err = CO_FALSE; /* error flag */
	UNSIGNED8   temp = 0;
	uword	time_lo = 0, time_hi = 0;

    /*--- hardware initialization e.g SIO, Chip-Selects, ...----------*/
    iniDevice();
	IO_vInit();
	USIC0_vInit();
	USIC1_vInit();
	USIC2_vInit();
#if HW_KPS == 1
	USIC3_vInit();
#endif
	//RTC init
    DAVE_vUnlockProtecReg();
	RTC_vInit();
    NOP();  /* one cycle delay */
    NOP();  /* one cycle delay */
    DAVE_vLockProtecReg();

	lNodeId = (~IO_uwReadPort(P2))&0xFF;
	if (lNodeId > 127) { lNodeId = 127; }
	temp = (~IO_uwReadPort(P10))&0x0F;
	switch(temp){
		case 0: bitRate = 10; break;
		case 1: bitRate = 20; break; 
		case 2: bitRate = 50; break; 
		case 3: bitRate = 125; break; 
		case 4: bitRate = 250; break; 
		case 5: bitRate = 500; break; 
		case 0x9:
		case 0xE:
		case 0xF:
			bitRate = 125;
			if (((~IO_uwReadPort(P2)) & 0xFF) == 0){ lNodeId = 127;	}
		break;
		default: bitRate = 500; break;
	}

    initCan(bitRate);
    init_Library();
    initTimer();
    Start_CAN();
    ENABLE_CPU_INTERRUPTS();
	RTC_vSetTime(0,0);

	sw_init();

	//PRINTF("loop\n");
    while (err == CO_FALSE) {
		FlushMbox();		         /* Do the CANopen job */
		myRTC_ulGetTime(&time_lo, &time_hi);

		//odczyt temperatury wewn.
		status_wewn[2] = ad7814_read(U2C0, SPI_CS3); 

		sw_loop();

		//sygnalizacja na diodach

		if (blink(time_lo, ch1_led_st)) {	//St1
			IO_vResetPin(IO_P0_0_LED_ST1);
		} else {
			IO_vSetPin(IO_P0_0_LED_ST1);
		}

		if (blink(time_lo, ch2_led_st)) {	//St2
			IO_vResetPin(IO_P4_1_LED_ST2);
		} else {
			IO_vSetPin(IO_P4_1_LED_ST2);
		}

		if (blink(time_lo, ch1_led_err)) {	//Err1
			IO_vResetPin(IO_P4_2_LED_ERR1);
		} else {
			IO_vSetPin(IO_P4_2_LED_ERR1);
		}

		if (blink(time_lo, ch2_led_err)) {	//Err2
			IO_vResetPin(IO_P4_0_LED_ERR2);
		} else {
			IO_vSetPin(IO_P4_0_LED_ERR2);
		}

//w funkcji err_code dopisac cykliczna informacje o kilku bledach (numer bledu jako bity w slowie "dev_led_st" a nie wartosc)
		if (err_code(time_lo, dev_led_st)) {	//err code - Yellow diode
			IO_vResetPin(IO_P2_8_LED_C);
		} else {
			IO_vSetPin(IO_P2_8_LED_C);
		}

		/* give a chance to finish the loop */
		err = endLoop();
    }
    PRINTF("\nSTOP\n");
    Stop_CAN();
    DISABLE_CPU_INTERRUPTS();
    releaseTimer();
    ResetIntMask();
    deinit_Library();
    return 0; 
}
コード例 #8
0
void initHardware() {
	// todo: enable protection. it's disabled because it takes
	// 10 extra seconds to re-flash the chip
	//flashProtect();

	/**
	 * histograms is a data structure for CPU monitor, it does not depend on configuration
	 */
	initHistogramsModule();



	/**
	 * We need the LED_ERROR pin even before we read configuration
	 */
	initPrimaryPins();

	/**
	 * this call reads configuration from flash memory or sets default configuration
	 * if flash state does not look right.
	 */
	initFlash();

	initRtc();

	initOutputPins();
	initAdcInputs();

#if EFI_HIP_9011
	initHip9011();
#endif /* EFI_HIP_9011 */

#if EFI_CAN_SUPPORT
	initCan();
#endif /* EFI_CAN_SUPPORT */

//	init_adc_mcp3208(&adcState, &SPID2);
//	requestAdcValue(&adcState, 0);


	// todo: figure out better startup logic
	initTriggerCentral();
	initShaftPositionInputCapture();

	initSpiModules();

#if EFI_FILE_LOGGING
	initMmcCard();
#endif /* EFI_FILE_LOGGING */

//	initFixedLeds();

	//	initBooleanInputs();

#if EFI_UART_GPS
	initGps();
#endif

#if ADC_SNIFFER
	initAdcDriver();
#endif

#if EFI_HD44780_LCD
//	initI2Cmodule();
	lcd_HD44780_init();

	char buffer[16];
	itoa10(buffer, SVN_VERSION);
	lcd_HD44780_print_string(buffer);

#endif

	addConsoleActionII("i2c", sendI2Cbyte);

//	while (true) {
//		for (int addr = 0x20; addr < 0x28; addr++) {
//			sendI2Cbyte(addr, 0);
//			int err = i2cGetErrors(&I2CD1);
//			print("I2C: err=%x from %d\r\n", err, addr);
//			chThdSleepMilliseconds(5);
//			sendI2Cbyte(addr, 255);
//			chThdSleepMilliseconds(5);
//		}
//	}

	initBoardTest();

}