コード例 #1
0
ファイル: main.c プロジェクト: doumdi/ProjetVUE_VUE32
int main(void)
{
    InitBoard();

    //Set ErrorStateFlag
    ErrorStateFlag = FALSE;
    
    m_state = InitPeripheral;
    //LED2 ^= 1;

    //Most of the functions in the while(1) loop are timed by Timer1
    while (1)
    {
        // Process state machine        
        ImplBMS();

        ClearWDT();
        //CallBMSImpl();        
        
        
        /*NETV_MESSAGE oMsgRecep;

        EVERY_X_MS(1000)
            
            oMsgRecep.msg_cmd = 0;
            oMsgRecep.msg_comm_iface =0xFF;
            oMsgRecep.msg_data_length = 0;
            oMsgRecep.msg_dest = 0xFF;
            oMsgRecep.msg_remote = 1;
            oMsgRecep.msg_source = GetMyAddr();
            oMsgRecep.msg_type = 0x80;
            oMsgRecep.msg_priority = 1;
            netv_send_message(&oMsgRecep );
            LED1 ^= 1;
        END_OF_EVERY


        if(netv_transceiver((unsigned char)GetBoardID(), &oMsgRecep))
        {
            //LED2 ^= 1;
            OnMsgBMS(&oMsgRecep);
        }*/
    }

    return 0;
}
コード例 #2
0
/* main ***********************************************************************/
int main(void) {
    CO_NMT_reset_cmd_t reset = CO_RESET_NOT;

    InitCanLeds();
    DBGU_Configure(115200);
    TRACE_INFO_WP("\n\rCanOpenNode %s (%s %s)\n\r", cVer, __DATE__, __TIME__);
    /* Configure Timer interrupt function for execution every 1 millisecond */
    if (SysTick_Config(SysTick_1ms))
        TRACE_FATAL("SysTick_Config\n\r");
    initTimer(getTimer_us);

    /* Todo: initialize EEPROM */

    /*  Todo: Loading COD */
    TRACE_INFO("Loading COD\n\r");

    /* Verify, if OD structures have proper alignment of initial values */
    TRACE_DEBUG("Checking COD in RAM (size=%d)\n\r", &CO_OD_RAM.LastWord - &CO_OD_RAM.FirstWord);
    if (CO_OD_RAM.FirstWord != CO_OD_RAM.LastWord)
        TRACE_FATAL("Err COD in RAM\n\r");
    TRACE_DEBUG("Checking COD in EEPROM (size=%d)\n\r", &CO_OD_EEPROM.LastWord - &CO_OD_EEPROM.FirstWord);
    if (CO_OD_EEPROM.FirstWord != CO_OD_EEPROM.LastWord)
        TRACE_FATAL("Err COD in EEPROM\n\r");
    TRACE_DEBUG("Checking COD in ROM (size=%d)\n\r", &CO_OD_ROM.LastWord - &CO_OD_ROM.FirstWord);
    if (CO_OD_ROM.FirstWord != CO_OD_ROM.LastWord)
        TRACE_FATAL("Err COD in ROM\n\r");

    /* increase variable each startup. Variable is stored in eeprom. */
    OD_powerOnCounter++;

    TRACE_INFO("CO power-on (BTR=%dk Node=0x%x)\n\r", CO_OD_ROM.CANBitRate, CO_OD_ROM.CANNodeID);
    ttimer tprof;
    while (reset != CO_RESET_APP) {
        /* CANopen communication reset - initialize CANopen objects *******************/
        static uint32_t timer1msPrevious;
        CO_ReturnError_t err;

        /* disable timer interrupts, turn on red LED */
        canTimerOff = 1;
        CanLedsSet(eCoLed_Red);

        /* initialize CANopen */
        err = CO_init();
        if (err) {
            TRACE_FATAL("CO_init\n\r");
            /* CO_errorReport(CO->em, CO_EM_MEMORY_ALLOCATION_ERROR, CO_EMC_SOFTWARE_INTERNAL, err); */
        }

        /* start Timer */
        canTimerOff = 0;

        reset = CO_RESET_NOT;
        timer1msPrevious = CO_timer1ms;

        TRACE_INFO("CO (re)start\n\r");
        while (reset == CO_RESET_NOT) {
            saveTime(&tprof);
            /* loop for normal program execution ******************************************/
            uint32_t timer1msDiff;

            timer1msDiff = CO_timer1ms - timer1msPrevious;
            timer1msPrevious = CO_timer1ms;

            ClearWDT();

            /* CANopen process */
            reset = CO_process(CO, timer1msDiff);

            CanLedsSet((LED_GREEN_RUN(CO->NMT)>0 ? eCoLed_Green : 0) | (LED_RED_ERROR(CO->NMT)>0 ? eCoLed_Red : 0));

            ClearWDT();

            /* (not implemented) eeprom_process(&eeprom); */
            uint32_t t = getTime_us(&tprof);
            OD_performance[ODA_performance_mainCycleTime] = t;
            if (t > OD_performance[ODA_performance_mainCycleMaxTime])
                OD_performance[ODA_performance_mainCycleMaxTime] = t;

        } /*  while (reset != 0) */
    } /*  while (reset != 2) */
    /* program exit ***************************************************************/
    /* save variables to eeprom */
    CO_DISABLE_INTERRUPTS();

    CanLedsSet(eCoLed_None);
    /* (not implemented) eeprom_saveAll(&eeprom); */
    CanLedsSet(eCoLed_Red);
    /* delete CANopen object from memory */
    CO_delete();

    /* reset - by WD */
    return 0;
}
コード例 #3
0
//***********************************
//***********************************
//********** MAIN FUNCTION **********
//***********************************
//***********************************
int main (void)
{
	BYTE display_html_file_name[12];
	DWORD file_size;

	//**********************
	//**********************
	//***** INITIALISE *****
	//**********************
	//**********************
	initialise();





	//*********************
	//*********************
	//***** MAIN LOOP *****
	//*********************
	//*********************
	while(1)						//(Do forever)
	{
		//----- RESET THE WATCHDOG TIMEOUT TIMER -----
		ClearWDT();


		switches_1_new = 0;
		if (do_10ms_functions)
		{
			do_10ms_functions = 0;
		
			//----- READ SWITCHES -----
			read_switches();

		}


		//------------------------------------
		//----- CHECK FOR SWITCH PRESSES -----
		//------------------------------------
		if (SWITCH_UP_NEW_PRESS)
		{
			//----- UP PRESSED -----
			
			//Load the index.htm file
			if (display_html_setup_read_file(index_htm, 0, &file_size))			//Find HTML file ready to display it
				display_html_file(file_size);
		}
		else if (SWITCH_DOWN_NEW_PRESS)
		{
			//----- DOWN PRESSED -----
			
			//Load text1.htm using name as a variable to demonstrate finding file by name at run time
			display_html_file_name[0] = 'T';
			display_html_file_name[1] = 'E';
			display_html_file_name[2] = 'X';
			display_html_file_name[3] = 'T';
			display_html_file_name[4] = '1';
			display_html_file_name[5] = '.';
			display_html_file_name[6] = 'H';
			display_html_file_name[7] = 'T';
			display_html_file_name[8] = 'M';
			display_html_file_name[9] = 0x00;
			
			if (display_html_setup_read_file(0, display_html_file_name, &file_size))
			{
				display_html_file(file_size);
			}

		}
		else if (SWITCH_LEFT_NEW_PRESS)
		{
			//----- LEFT PRESSED -----
			
			//Load dynamic text demo HTML file - the text is added by the html_get_dynamic_text_character function below
			if (display_html_setup_read_file(dyntext_htm, 0, &file_size))
				display_html_file(file_size);
		}
		else if (SWITCH_RIGHT_NEW_PRESS)
		{
			//----- RIGHT PRESSED -----
			
			//Load text2.htm
			if (display_html_setup_read_file(text2_htm, 0, &file_size))
				display_html_file(file_size);
		}
		else if (SWITCH_FIRE_NEW_PRESS)
		{
			//----- FIRE PRESSED -----


			//Generate content using code instead of HTML
			display_clear_screen(DISPLAY_COLOUR_WHITE);
			
			display_bitmap(indeximg_bmp, 0, 0, 0x00ffffff);		//p_bitmap, x_coord, y_coord, transparency_colour(0xffffffff to not use)
		
		

			display_foreground_colour = DISPLAY_COLOUR_RED;
			display_background_colour = DISPLAY_COLOUR_TURQUOISE;
			display_const_string (disp_font_5w_7h, DISPLAY_TEXT_ALIGN_LEFT,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									20, 50,												//X start coord, Y start coord
									0, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text
	
	
			display_const_string(disp_font_5w_11h, DISPLAY_TEXT_ALIGN_LEFT,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									20, 70,												//X start coord, Y start coord
									0, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text


			display_foreground_colour = DISPLAY_COLOUR_VIOLET;
			display_background_colour = DISPLAY_COLOUR_YELLOW;
			display_const_string(disp_font_22h, DISPLAY_TEXT_ALIGN_CENTRE,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									20, 105,											//X start coord, Y start coord
									200, 160,											//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text



			display_foreground_colour = DISPLAY_COLOUR_BLACK;
			display_background_colour = DISPLAY_COLOUR_NULL;							//(DISPLAY_COLOUR_NULL == no background colour / leave existing colour)
	
			display_const_string(disp_font_15h, DISPLAY_TEXT_ALIGN_LEFT,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									176, 134,											//X start coord, Y start coord
									0, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text


			display_foreground_colour = DISPLAY_COLOUR_WHITE;
			display_background_colour = DISPLAY_COLOUR_BLUE;
			display_const_string(disp_font_42h, DISPLAY_TEXT_ALIGN_CENTRE,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									0, 170,												//X start coord, Y start coord
									319, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text
									

		}

		
	}
}
コード例 #4
0
void SLAVE_TASKS(void) {
    ClearWDT();
    if (FLAG.IndicatorINTEGRATED_OnOff == 0) {
        if (FLAG.FlagTimerRemaining3 == 0) {
            FLAG.FlagTimerRemaining3 = TIMER_SEC_Remaining3(10);
            if (FLAG.FlagTimerRemaining3 == 1) {
                if(FLAG.SensorACTIVE == 1){
                    ChangeFadeCOLOR(COLORS.RED_A, COLORS.GREEN_A, COLORS.BLUE_A, 0, 0, 0);
                    PWM1_OFF();
                    PWM2_OFF();
                    PWM4_OFF();
                    TIMER0_OFF();
                    FLAG.IndicatorINTEGRATED_OnOff = 0;
                }else{
                    ChangeFadeCOLOR(COLORS.RED_D, COLORS.GREEN_D, COLORS.BLUE_D, 0, 0, 0);
                    PWM1_OFF();
                    PWM2_OFF();
                    PWM4_OFF();
                    TIMER0_OFF();
                    FLAG.IndicatorINTEGRATED_OnOff = 0;
                }
                LED_AZUL = 0;
                LED_ROJO = 0;
                LED_VERDE = 0;
            }
        }
    }

    Task_UART_Slave(&BusSLAVE_R);
    if (FLAG.NOT_SENSE == 0) {
        PRESENCE_SONAR_4_0(&FLAG.StateSONAR);
        if (FLAG_TIMER_HIGH == 1) {
            FLAG_TIMER_HIGH = 0;
            if (FLAG.FlagTimerRemaining2 == 0) {
                FLAG.FlagTimerRemaining2 = TIMER_SEC_Remaining1(65 + (IDSlave.VAL));
                if (FLAG.FlagTimerRemaining2 == 1) {
                    FLAG.StartCommSLAVE = 1;
                    BusSLAVE_T.IDR = IDMaster.VAL;
                    BusSLAVE_T.IDT1 = IDSlave.VAL;
                    BusSLAVE_T.IDT2 = 0;
                    BusSLAVE_T.CMD = CMD1_PARKUEST;
                    BusSLAVE_T.Data[0].val = (unsigned char)FLAG.SensorACTIVE;
                    BusSLAVE_T.Data[1].val = STOP_COMMUNICATION;
                    BusSLAVE_T.Data[2].val = STOP_COMMUNICATION2;
                    SendDATA1(&BusSLAVE_T);                    
                }
            }
        }
        
        if (FLAG.StateSONAR == 3) {
            if (FLAG.ChangeSTATE == 1 && FLAG.INDICATOR_ACTIVE == 0) {
                FLAG.SensorACTIVE = 1;
                BusSLAVE_T.IDR = IDMaster.VAL;
                BusSLAVE_T.IDT1 = IDSlave.VAL;
                BusSLAVE_T.IDT2 = 0;
                BusSLAVE_T.CMD = CMD1_PARKUEST;
                BusSLAVE_T.Data[0].val = (unsigned char)FLAG.SensorACTIVE;
                BusSLAVE_T.Data[1].val = STOP_COMMUNICATION;
                BusSLAVE_T.Data[2].val = STOP_COMMUNICATION2;
                if(FLAG.StartCommSLAVE == 1) SendDATA1(&BusSLAVE_T);
                SmartOnlyOneIndicator(IDSlave.VAL, (unsigned char) FLAG.SensorACTIVE, ChangeStatusSOFTWARE_A);
                if (FLAG.ChangeSTATE == 1)ChangeFadeCOLOR(COLORS.RED_D, COLORS.GREEN_D, COLORS.BLUE_D, COLORS.RED_A, COLORS.GREEN_A, COLORS.BLUE_A);
                RGB_8bit(COLORS.RED_A, COLORS.GREEN_A, COLORS.BLUE_A);
            }
            FLAG.ChangeSTATE = 0;
            BusSLAVE_R.TimeOut2 = 0;
        } else {
            if (FLAG.ChangeSTATE == 0 && FLAG.INDICATOR_ACTIVE == 0) {
                FLAG.SensorACTIVE = 0;
                BusSLAVE_T.IDR = IDMaster.VAL;
                BusSLAVE_T.IDT1 = IDSlave.VAL;
                BusSLAVE_T.IDT2 = 0;
                BusSLAVE_T.CMD = CMD1_PARKUEST;
                BusSLAVE_T.Data[0].val = (unsigned char)FLAG.SensorACTIVE;
                BusSLAVE_T.Data[1].val = STOP_COMMUNICATION;
                BusSLAVE_T.Data[2].val = STOP_COMMUNICATION2;
                if(FLAG.StartCommSLAVE == 1) SendDATA1(&BusSLAVE_T);
                SmartOnlyOneIndicator(IDSlave.VAL, (unsigned char) FLAG.SensorACTIVE, ChangeStatusSOFTWARE_D);
                if (FLAG.ChangeSTATE == 0)ChangeFadeCOLOR(COLORS.RED_A, COLORS.GREEN_A, COLORS.BLUE_A, COLORS.RED_D, COLORS.GREEN_D, COLORS.BLUE_D);
                RGB_8bit(COLORS.RED_D, COLORS.GREEN_D, COLORS.BLUE_D);
            }
            FLAG.ChangeSTATE = 1;
            BusSLAVE_R.TimeOut1 = 0;
        }
    }
}
コード例 #5
0
ファイル: main_PIC32.c プロジェクト: mhaberler/canopennode
/* main ***********************************************************************/
int main (void){
    CO_NMT_reset_cmd_t reset = CO_RESET_NOT;

    /* Configure system for maximum performance and enable multi vector interrupts. */
    SYSTEMConfig(CO_FSYS*1000, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableInterrupts();

    /* Disable JTAG and trace port */
    DDPCONbits.JTAGEN = 0;
    DDPCONbits.TROEN = 0;


    /* Verify, if OD structures have proper alignment of initial values */
    if(CO_OD_RAM.FirstWord != CO_OD_RAM.LastWord) while(1) ClearWDT();
    if(CO_OD_EEPROM.FirstWord != CO_OD_EEPROM.LastWord) while(1) ClearWDT();
    if(CO_OD_ROM.FirstWord != CO_OD_ROM.LastWord) while(1) ClearWDT();


    /* initialize EEPROM - part 1 */
#ifdef USE_EEPROM
    CO_ReturnError_t eeStatus = CO_EE_init_1(&CO_EEO, (uint8_t*) &CO_OD_EEPROM, sizeof(CO_OD_EEPROM),
                            (uint8_t*) &CO_OD_ROM, sizeof(CO_OD_ROM));
#endif


    programStart();


    /* increase variable each startup. Variable is stored in eeprom. */
    OD_powerOnCounter++;


    while(reset != CO_RESET_APP){
/* CANopen communication reset - initialize CANopen objects *******************/
        CO_ReturnError_t err;
        uint16_t timer1msPrevious;
        uint16_t TMR_TMR_PREV = 0;

        /* disable timer and CAN interrupts */
        CO_TMR_ISR_ENABLE = 0;
        CO_CAN_ISR_ENABLE = 0;
        CO_CAN_ISR2_ENABLE = 0;


        /* initialize CANopen */
        err = CO_init();
        if(err != CO_ERROR_NO){
            while(1) ClearWDT();
            /* CO_errorReport(CO->em, CO_EM_MEMORY_ALLOCATION_ERROR, CO_EMC_SOFTWARE_INTERNAL, err); */
        }


        /* initialize eeprom - part 2 */
#ifdef USE_EEPROM
        CO_EE_init_2(&CO_EEO, eeStatus, CO->SDO, CO->em);
#endif


        /* initialize variables */
        timer1msPrevious = CO_timer1ms;
        OD_performance[ODA_performance_mainCycleMaxTime] = 0;
        OD_performance[ODA_performance_timerCycleMaxTime] = 0;
        reset = CO_RESET_NOT;



        /* Configure Timer interrupt function for execution every 1 millisecond */
        CO_TMR_CON = 0;
        CO_TMR_TMR = 0;
        #if CO_PBCLK > 65000
            #error wrong timer configuration
        #endif
        CO_TMR_PR = CO_PBCLK - 1;  /* Period register */
        CO_TMR_CON = 0x8000;       /* start timer (TON=1) */
        CO_TMR_ISR_FLAG = 0;       /* clear interrupt flag */
        CO_TMR_ISR_PRIORITY = 3;   /* interrupt - set lower priority than CAN (set the same value in interrupt) */

        /* Configure CAN1 Interrupt (Combined) */
        CO_CAN_ISR_FLAG = 0;       /* CAN1 Interrupt - Clear flag */
        CO_CAN_ISR_PRIORITY = 5;   /* CAN1 Interrupt - Set higher priority than timer (set the same value in '#define CO_CAN_ISR_PRIORITY') */
        CO_CAN_ISR2_FLAG = 0;      /* CAN2 Interrupt - Clear flag */
        CO_CAN_ISR2_PRIORITY = 5;  /* CAN Interrupt - Set higher priority than timer (set the same value in '#define CO_CAN_ISR_PRIORITY') */


        communicationReset();


        /* start CAN and enable interrupts */
        CO_CANsetNormalMode(ADDR_CAN1);
        CO_TMR_ISR_ENABLE = 1;
        CO_CAN_ISR_ENABLE = 1;

#if CO_NO_CAN_MODULES >= 2
        CO_CANsetNormalMode(ADDR_CAN2);
        CO_CAN_ISR2_ENABLE = 1;
#endif


        while(reset == CO_RESET_NOT){
/* loop for normal program execution ******************************************/
            uint16_t timer1msCopy, timer1msDiff;

            ClearWDT();


            /* calculate cycle time for performance measurement */
            timer1msCopy = CO_timer1ms;
            timer1msDiff = timer1msCopy - timer1msPrevious;
            timer1msPrevious = timer1msCopy;
            uint16_t t0 = CO_TMR_TMR;
            uint16_t t = t0;
            if(t >= TMR_TMR_PREV){
                t = t - TMR_TMR_PREV;
                t = (timer1msDiff * 100) + (t / (CO_PBCLK / 100));
            }
            else if(timer1msDiff){
                t = TMR_TMR_PREV - t;
                t = (timer1msDiff * 100) - (t / (CO_PBCLK / 100));
            }
            else t = 0;
            OD_performance[ODA_performance_mainCycleTime] = t;
            if(t > OD_performance[ODA_performance_mainCycleMaxTime])
                OD_performance[ODA_performance_mainCycleMaxTime] = t;
            TMR_TMR_PREV = t0;


            /* Application asynchronous program */
            programAsync(timer1msDiff);

            ClearWDT();


            /* CANopen process */
            reset = CO_process(CO, timer1msDiff);

            ClearWDT();


#ifdef USE_EEPROM
            CO_EE_process(&CO_EEO);
#endif
        }
    }


/* program exit ***************************************************************/
    CO_DISABLE_INTERRUPTS();

    /* delete objects from memory */
    programEnd();
    CO_delete();

    /* reset */
    SoftReset();
}