示例#1
0
/**
 * main entry point
 */
void main(void)
{
    unsigned char   n;

    // hardware initialisieren
    restart_hw();

    // warten bis der BUS stabil ist
    for (n=0; n<50; n++)
    {
        set_timer0(0xFFFF);
        while(!TF0);
    }

    // Protokoll zurücksetzen
    restart_prot();

#ifdef DEBUG
    // serielle Schnittstelle für DEBUG Ausgaben initialisieren
    rs_init(576);
#endif

    // initialize/reset application
    restart_app();

    // main loop
    while (1)
    {
        if (!TR1) // check if TR1 is active -> send/receive finished
        {
            // applikation ausführen
            app_process();

            if (RTCCON>=0x80)
            {
                stop_rtc();
                rtc_process();  // Realtime clock Ueberlauf
                start_rtc(65);  // RTC mit 65ms neu starten
            }
        }

        // check program button
        check_prog_button();
    }
}
示例#2
0
文件: main.c 项目: quark-mcu/qmsi
void soc_sleep(device_sleep_t dev)
{
	save_my_context(dev);

	if (dev == SOC_SLEEP) {
		start_rtc();
		QM_PUTS("SoC going to sleep");
		POWER_SOC_DEEP_SLEEP();
	} else {
		QM_PUTS("Core going to sleep");
		POWER_SLEEP_WAIT();
	}

	restore_my_context(dev);
	clear_flags();

#if !QM_SENSOR
	if (other_core_sleep_flag()) {
		sensor_activation();
	}
#endif
}
示例#3
0
/****************************** start main routine ******************************/
int main(void)
{
    char        input_buffer[INPUT_BUFFER]; //buffer for user input
    waitcnt(500000 + _CNT);                 //wait until initialization is complete
    printf("XMMC-cogc demo v%s",VERSION);   //display startup message  

/* start monitoring the real time clock DS3231 */
    int         cog;
    rtc_cb.rtc.tdb_lock = locknew();
    lockclr(rtc_cb.rtc.tdb_lock);
    cog = start_rtc(&rtc_cb.rtc);
    if(cog == -1)
    {
        printf("** error attempting to start rtc cog\n  cognew returned %i\n\n",cog);
        return 1;
    }     
    printf("  DS3231 monitored by code running on cog %i\n",cog);


/* set all cogs to not running */
    parA.A.cog = -1; 
    parB.B.cog = -1; 
    parC.C.cog = -1; 
/* loop forever */
    while(1) 
    {
        printf("\nenter command > ");                //prompt user
        fgets(input_buffer,INPUT_BUFFER,stdin);      //get a line of input
        input_buffer[strlen(input_buffer)-1] = '\0'; //get rid of trailing new line character
        switch(process(input_buffer))                //test input,take appropriate action
        {
            case 0:     //startA
                if(start_cogA(&parA.A)== -1)
                    printf("  problem starting cogA\n");
                else
                    printf("  cogA started\n");
                break;
            case 1:     //startB
                if(start_cogB(&parB.B)== -1)
                    printf("  problem starting cogB\n");
                else
                    printf("  cogB started\n");
                break;
            case 2:     //startC
                if(start_cogC(&parC.C)== -1)
                    printf("  problem starting cogC\n");
                else
                    printf("  cogC started\n");
                break;
            case 3:     //stopA
                cogstop(parA.A.cog);
                printf("  cog A stopped\n");
                parA.A.cog = -1;
                break;
            case 4:     //stopB
                cogstop(parB.B.cog);
                printf("  cog B stopped\n");
                parB.B.cog = -1;
                break;
            case 5:     //stopC
                cogstop(parC.C.cog);
                printf("  cog C stopped\n");
                parC.C.cog = -1;
                break;
            case 6:     //queryA
                if(parA.A.cog == -1)
                    printf("cog A is not running\n");              
                else
                    parA.A.query_flag = 1;
                break;
            case 7:     //queryB
                if(parB.B.cog == -1)
                    printf("cog B is not running\n");              
                else
                    parB.B.query_flag = 1;
                break;
            case 8:     //queryC
                if(parC.C.cog == -1)
                    printf("cog C is not running\n");              
                else
                    parC.C.query_flag = 1;
                break;
            case 9:     //status
                status();
                break;
            case 10:    //exit
                printf("exiting program\n");
                return 0;
            case 11:    //time
                printf("%s, %i:%02i:%02i  %i/%i/%i\n\n",
                    day_names_long[rtc_cb.rtc.dow-1],
                    rtc_cb.rtc.hour,
                    rtc_cb.rtc.min,
                    rtc_cb.rtc.sec,

                    rtc_cb.rtc.month,
                    rtc_cb.rtc.day,
                    rtc_cb.rtc.year+2000);
                break;
            default:
                printf("<%s> is not a valid command\n",input_buffer);

        }
    }
    return 0;
}
示例#4
0
int board_early_init_r(void)
{
	start_rtc();
	return 0;
}
示例#5
0
文件: Pcon.c 项目: mam1/Pcon
 int main(void)
{
    static int          cog;
    static char         tbuf[_TOKEN_BUFFER];
    char                c;   
/************************ initializations ****************************/
    sleep(1);   //wait for the serial terminal to start
/* display system info on serial terminal */
    printf("\n*** Pcon  %i.%i ***\n\n",_major_version,_minor_version);
    #if _DRIVEN == _DIOB
        printf("system is configured to drive a Parallax Digital IO Board\n");
    #else
        printf("system is configured to drive 5 IO pins\n");
    #endif
/* build file set prefix */
    strcat(file_set_prefix,_F_PREFIX);
    strcat(file_set_prefix,_FILE_SET_ID);
    printf("file set prefix <%s>\n",file_set_prefix);
/* check out the SD card */
    if(sd_setup())
    {
        printf("**** sd_setup aborted application ****\n");
        return 1;
    }    
/* start monitoring the real time clock DS3231 */
    rtc_cb.rtc.tdb_lock = locknew();
    lockclr(rtc_cb.rtc.tdb_lock);
    cog = start_rtc(&rtc_cb.rtc);
    if(cog == -1)
    {
        printf("** error attempting to start rtc cog\n  cognew returned %i\n\n",cog);
        return 1;
    }     
    printf(" DS3231 monitored by code running on cog %i\n",cog);
/* setup  the dio control block */
    dio_cb.dio.tdb_lock = rtc_cb.rtc.tdb_lock;
    dio_cb.dio.cca_lock = locknew();
    lockclr(dio_cb.dio.cca_lock);
    dio_cb.dio.sch_lock = locknew();
    lockclr(dio_cb.dio.sch_lock);
    dio_cb.dio.update_ptr = &(rtc_cb.rtc.update);
    dio_cb.dio.td_ptr = &(rtc_cb.rtc.td_buffer);
    *dio_cb.dio.update_ptr = 0;
    dio_cb.dio.sch_ptr = bbb; 

/* start the dio cog  */
    cog = start_dio(&dio_cb.dio);
    if(cog == -1)
    {
        printf("** error attempting to start dio cog\n  cognew returned %i\n\n",cog);
        return 1;
    }
    #if _DRIVEN == _DIOB
            printf(" DIO Board controlled by code running on cog %i\n",cog);
    #else
         printf(" relays controlled by code running on cog %i\n",cog);

    #endif      
/* set up unbuffered nonblocking io */
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);
    stdin->_flag &= ~_IOCOOKED;
    stdin->_flag |= _IONONBLOCK;
/* initialize fsm(s) parameters */
    input_buffer_ptr = input_buffer;//setup so actions routines can mess the buffer
    cmd_state = 0;                  //set initial command parser state
    char_state = 0;                 //set initial caracter parser state
    // hold_day = -1;                  //force schedule load first time through the main loop
    *input_buffer = ' ';            //load a a blank into the buffer to force first prompt
    process_buffer();
    printf("initialization complete\n");

/************************************************************/
/********************** main processing loop ****************/
/************************************************************/
    while(1)
    {
        /* check for problems */
        if(ckeck_abort())
            return 1;
        /* check the token stack */
        while(pop_cmd_q(tbuf))
        {
            cmd_fsm(tbuf,&cmd_state);   //cycle cmd fsm until queue is empty
        }
        /* grab a character from the keyboard if one is present  */
        c = fgetc(stdin);     //nonblocking read
        /*  process input char */
        if(c!=_NO_CHAR)       
        {
            fputc(c, stdout);       // echo char 
            if(c==_CR) fputc(_CR, stdout);   //second CR after uer input
            char_fsm(char_type(c),&char_state,&c);  //cycle fsm
        }
    };
    printf("\nnormal termination\n\n");
    return 0;
}