Ejemplo n.º 1
0
void MAIN_vInit(void)
{
  // USER CODE BEGIN (Init,2)

  // USER CODE END

  //   globally disable interrupts
  PSW_IEN        =  0;          


  ///  -----------------------------------------------------------------------
  ///  Configuration of the System Clock:
  ///  -----------------------------------------------------------------------
  ///  - VCO clock used, input clock is connected
  ///  - input frequency is 8.00 MHz
  ///  - system clock is 80.00 MHz

  MAIN_vUnlockProtecReg();     // unlock write security

  MAIN_vChangeFreq();          // load PLL control register

  //   -----------------------------------------------------------------------
  //   SCU Interrupt Disable configuration:
  //   -----------------------------------------------------------------------
  SCU_INTDIS     =  0xFFFF;      // SCU Interrupt Disable Register

  //   -----------------------------------------------------------------------
  //   Initialization of the Peripherals:
  //   -----------------------------------------------------------------------

  //   initializes the Real Time Clock (RTC)
  RTC_vInit();


  //   -----------------------------------------------------------------------
  //   Initialization of the Bank Select registers:
  //   -----------------------------------------------------------------------


  //   -----------------------------------------------------------------------
  //   SCU Interrupt Source Selection configuration:
  //   -----------------------------------------------------------------------
  SCU_ISSR       =  0x0000;      // SCU Interrupt Source Select Register

  // USER CODE BEGIN (Init,3)

  // USER CODE END

  MAIN_vLockProtecReg();       // lock write security

  //   globally enable interrupts
  PSW_IEN        =  1;          

} //  End of function MAIN_vInit
Ejemplo n.º 2
0
void Project_Init(void)
{

  // USER CODE BEGIN (Project_Init,0)

  // USER CODE END

  /// the following initialization is made by the compiler EDE when you
  /// import the DAvE project

  /// --- initialization of the SYSCON Register ---
  ///- 256 words system stack
  ///- the internal ROM area is mapped to segment 1
  ///- the segmentation is enabled (CSP is saved/restored during interrupt entry/exit)
  ///- the internal ROM is disabled: accesses to the ROM area use the external bus
  ///- the pin #BHE (byte high enable) is enabled
  ///- the system clock output is disabled
  ///- the pin #WR acts as #WRL and pin #BHE acts as #WRH
  ///- the on-chip X-Peripherals are enabled and can be accessed
  ///- pin #RSTIN is an input only
  ///- the on-chip oscillator watchdog is disabled
  ///- latched CS mode; CS signals are latch internally


  /// --- initialization of the BUSCON 0-4 and ADRRSEL Registers 1-4 ---

  /// ---------- external bus 0 is enabled ----------
  ///- 16-bit multiplexed bus
  ///- memory cycle time control: 15 waitstates
  ///- read/write delay control: activate signal 1 TCL after falling edge of ALE  
  ///- chip select mode: address chip select 
  ///- memory tristate control: 1 waitstate
  ///- ALE lengthening control: lengthened ALE signal


  // initializes the IO ports
  IO_vInit();

  // initializes the Asynchronous/Synchronous Serial Interface (ASC)
  ASC_vInit();

  // initializes the On-Chip CAN Interface (CAN)
  CAN_vInit();

  // initializes the Analog/Digital Converter (ADC)
  ADC_vInit();

  // initializes the Capture/Compare Unit CAPCOM2
  CC2_vInit();

  // initializes the General Purpose Timer Unit 1 (GPT1)
  GT1_vInit();

  // initializes the Real Time Clock (RTC)
  RTC_vInit();

  // USER CODE BEGIN (Project_Init,1)

	// Compare-Wert neu setzen
	CC2_vSetCCxReg(CC_16, compare16);

  // USER CODE END

  /// globally enable interrupts
  IEN = 1;
}
Ejemplo n.º 3
0
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; 
}