Пример #1
0
int repeater_run(struct repeater_config *config)
{
    int status;
    struct repeater repeater;

    status = init(&repeater, config);
    if (status == 0) {

        /* Start tasks and wait for a key press to shut down */
        status = start_tasks(&repeater);
        if (status < 0) {
            fprintf(stderr, "Failed to start tasks.\n");
        } else {
            printf("Repeater running. Press enter to stop.\n");
            getchar();
        }

        /* Stop tasks */
        stop_tasks(&repeater);

        deinit(&repeater);
    }

    return status;
}
Пример #2
0
int repeater_run(struct repeater_config *config)
{
    int status;
    char key;
    struct repeater repeater;

    status = term_init();
    if (status != 0) {
        return 1;
    }

    status = init(&repeater, config);
    if (status == 0) {

        /* Start tasks and wait for a key press to shut down */
        status = start_tasks(&repeater);
        if (status < 0) {
            fprintf(stderr, "Failed to start tasks.\r\n");
        } else {
            repeater_help();
            do {
                key = get_key();
                repeater_handle_key(&repeater, key);
            } while (key != KEY_QUIT);
        }

        /* Stop tasks */
        stop_tasks(&repeater);

        deinit(&repeater);
    }

    return term_deinit();
}
Пример #3
0
int main()
{
    int r = 0;
    int g = 100;
    int b = 0;
    int temp = 1;

    enable_interrupts();

    timer_init();

//  RGB_LED(0,0,0);

    delay_ms(2000);
    RGB_LED(100, 0, 0);

    uart0_write_string("blah");
    uart0_write_string("blah\r\n");

    start_tasks();

    for (;;) {
    	delay_ms(1000);
    	RGB_LED(r, g, b);
	    temp = r;
    	r = b;
    	b = g;
    	g = temp;
    	uart0_write_string
	        ("123456789012345678901234567890123456789012345678901234567890\n\r");
	    uart0_write_string("1234567890\r\n");
    	uart0_write_string("blah\r\n");
    }
}
Пример #4
0
int main(int argc, char** argv)
{
    I_LOG("Are you Ready? start my butler!!!!\n");

    start_tasks();

    while(1)
    {
        sleep(60);
    }

    return 0;
}
Пример #5
0
/* 
 * StartOS API call.
 * This service is called to start the operating system in a specific mode.
 */
void os_StartOS(AppModeType appmode)
{
	os_ipl save_ipl;
	
	OS_SAVE_IPL(save_ipl);									/* Save IPL on entry so can restore on exit, side-effect: assigns back to save_ipl */
	
	ENTER_KERNEL_DIRECT();								/* Set IPL to kernel level while setting up OS variables etc. */
	OS_API_TRACE_START_OS();
	INIT_STACKCHECK_TO_OFF();							/* Make sure stack checking is turned off so that when/if dispatch() is called there are no stack errors
														 * Note that this requires the kernel stack (i.e. main()'s stack) is big enough to support this call to
														 * StartOS plus a call to dispatch() and the entry into the subsequent task
														 */
#ifndef NDEBUG
	assert_initialized();								/* assert the C runtime startup has setup all vars to startup state */
#endif
	
	/* Saving a jmp_buf (os_startosenv) so that the entire OS can be terminated via a longjmp call inside a ShutdownOS call */
	/* $Req: artf1216 artf1219 $ */
	if (SETJMP(os_startosenv) == 0) {					
														/* This half of the 'if' is the half that is the run-on continuation */
		/* $Req: artf1214 artf1094 $ */
		os_appmode = appmode;							/* Store application mode in which the OS was started */

		/* setup the tasks and alarms that are to be autostarted for the given app mode */													
		start_tasks(appmode);
		
		/* Initialize all counters in the system to start running */
		start_counters();
		
		/* Autostart alarms */
		if(appmode->start_alarms_singleton) {
			appmode->start_alarms_singleton(appmode);
		}

		if(appmode->start_alarms_multi) {
			appmode->start_alarms_multi(appmode);
		}
		
		/* Autostarted schedule tables are autostarted implicitly by the underlying alarms being autostarted */

#ifdef STACK_CHECKING	
		os_curtos = OS_KS_TOP;
#endif

		/* Call startup hook if required to do so */
		/* $Req: artf1215 $ */
		if (os_flags.startuphook) {						/* check if need to call the startuphook handler */
														/* hook needs calling */
			ENABLE_STACKCHECK();						/* enable stack checking */
			/* @todo check that we really need to raise IPL to lock out all interrupts (both CAT1 and CAT2) within the hook */			
			OS_SET_IPL_MAX();							/* raise IPL to lock out all interrupts (both CAT1 and CAT2) within the hook */
			MARK_OUT_KERNEL();							/* drop out of the kernel, keeping IPL at max level  */
			/* $Req: artf1117 $ */
			StartupHook();								/* call the hook routine with IPL set to kernel level and stack checking on */
			MARK_IN_KERNEL();							/* go back into the kernel */
			OS_SET_IPL_KERNEL();						/* set IPL back to kernel level */
			DISABLE_STACKCHECK();						/* disable stack checking */
		}

		/* Start the scheduling activity */
		if (TASK_SWITCH_PENDING(os_curpri)) {
			os_ks_dispatch();
		}
		
		ENABLE_STACKCHECK();
		LEAVE_KERNEL();

		/* now running as the body of the os_idle task, with IPL at level 0 and priority of IDLEPRI */
		/* $Req: artf1116 $ */
		/* Note that interrupts will be enabled prior to here because the os_ks_dispatch() call above
		 * might switch to running autostarted tasks, which will lower interrupts to level 0
		 */		
		for ( ; ; ) {
			os_idle();										/* call the os_idle task entry function */
		}
		
		NOT_REACHED();
	}
	else {
														/* This half of the 'if' is the half that is RETURNING from a longjmp */
														/* We have come back from a ShutdownOS() call */
	}
	
	/* Reached here because ShutdownOS(E_OK) was called.
	 * 
	 * $Req: artf1219 $
	 */
	assert(KERNEL_LOCKED());
	assert(STACKCHECK_OFF());							/* Stack checking turned off prior to longjmp in shutdown() */
		
	/* Would normally stop the counters, reinitialise the kernel variables, etc. in case StartOS() were to be called again,
	 * but OS424 (artf1375) requires that StartOS() doesn't return, but instead goes into an infinite loop.
	 * Similarly, OS425 (artf1376) requires that interrupts are disabled before entering the loop.
	 * 
	 * If StartOS() is ever required to return to caller, see revision 568 of this file (startos.c) for the
	 * original code that did this.
	 * 
	 * $Req: artf1375 $
	 * $Req: artf1376 $
	 */
	OS_SET_IPL_MAX();
	for(;;)
		;
}
Пример #6
0
/*
 * Overall executable distribution using fast.
 */
int
distribute_executable(void)
{
    int ret = 1;  /* failure */

#if HAVE_FAST_DIST
    const char *fast_command = FAST_DIST_PATH;  /* from configure */
    int i;
    int numtasks_save;
    int local_numtasks;
    tasks_t *tasks_save;
    cl_args_t cl_args_save;
    config_spec_t cs, root_cs;
    growstr_t *g, *root_g;
    int temp_fd;
    char *file_template;
    int port_num;
    FILE *fp;
    const char *exec_to_dist;
    int *usenodes;

    exec_to_dist = config_get_unique_executable();
    if (!exec_to_dist)
        return ret;

    if (!stat_exe(fast_command, 0))
        return ret;

    /* analyze nodes */
    usenodes = Malloc(numnodes * sizeof(*usenodes));
    memset(usenodes, 0, numnodes * sizeof(*usenodes));
    local_numtasks = 0;
    for (i=0; i<numtasks; i++) {
        if (!usenodes[tasks[i].node]) {
            usenodes[tasks[i].node] = 1;
            ++local_numtasks;
        }
    }

    /* don't bother if there is only one node */
    if (local_numtasks <= 1) {
        free(usenodes);
        return ret;
    }

    /* create temporary node file */
    file_template = strsave("/tmp/mpiexec-fast-XXXXXX");
    temp_fd = mkstemp(file_template);
    if (!temp_fd)
        goto out;
    debug(1, "%s: temp node list file is %d",__func__, temp_fd);
    fp = fdopen(temp_fd, "w");
    if (!fp)
        goto out;

    /* add nodes to the node file */
    for (i=0; i<numnodes; i++) {
        if (!usenodes[i])
            continue;
        if (fprintf(fp, "%s\n", nodes[i].name) <= 0) {
            fclose(fp);
            goto out;
        }
    }
    if (fclose(fp) != 0)
        goto out;

    /* pick a random port number between 6 and 8 thousand */
    srand(time(NULL));
    port_num = rand() % 2000 + 6000;

    /*
     * Back up the tasks structure and number of tasks as well as command
     * line args.
     */
    tasks_save = tasks;
    numtasks_save = numtasks;
    memcpy(&cl_args_save, cl_args, sizeof(*cl_args));

    /* set the fast_dist executable name */
    cs.exe = fast_command;
    root_cs.exe = cs.exe;

    /* set up the args to pass to the non-root nodes */
    g = growstr_init();
    growstr_printf(g, "-p %d", port_num);
    cs.args = g->s;
    debug(1, "%s: arg string for non root: %s", __func__, g->s);

    /* and to the root node */
    root_g = growstr_init();
    growstr_printf(root_g, "-p %d -r %s -e %s -n %s",
                   port_num, nodes[tasks[0].node].name, exec_to_dist, file_template);
    root_cs.args = root_g->s;
    debug(1, "%s: arg string for root: %s", __func__, root_g->s);

    /* build new tasks */
    cl_args->which_stdin = STDIN_NONE;
    cl_args->comm = COMM_NONE;
    tasks = Malloc(local_numtasks * sizeof(*tasks));
    numtasks = local_numtasks;
    for (i=0; i < numtasks; i++) {
        tasks[i].num_copies = 1;
        tasks[i].done = DONE_NOT_STARTED;
        *tasks[i].status = -1;
        /*
         * Slight race condition in that the root wants to actively connect
         * to some other nodes, but it will retry a bit.  Put root last to
         * hope that there is a bit of delay in startup.
         */
        if (i == numtasks - 1) {
            tasks[i].node = tasks_save[0].node;
            tasks[i].conf = &root_cs;
        } else {
            tasks[i].node = tasks_save[i+1].node;
            tasks[i].conf = &cs;
        }
        debug(1, "%s: task %d on %d", __func__, i, tasks[i].node);
    }

    /* spawn tasks */
    start_tasks(0);
    debug(1, "%s: tasks started", __func__);

    /* wait for them to exit */
    wait_tasks();

    /* make sure everyone finished successfully */
    ret = 0;
    for (i=0; i<numtasks; i++) {
        if (tasks[i].done == DONE_NO_EXIT_STATUS)
            continue;
        if (*tasks[i].status != 0) {
            ret = 1;
            break;
        }
    }
    debug(1, "%s: done, ret = %d", __func__, ret);

    /* put back original tasks structures */
    free(tasks);
    tasks = tasks_save;
    numtasks = numtasks_save;
    memcpy(cl_args, &cl_args_save, sizeof(*cl_args));
    growstr_free(g);
    growstr_free(root_g);

    /*
     * Update executable in old config structure to point to new /tmp exec,
     * using the same algorithm as fast_dist.  It is not deleted upon
     * completion but relies on $TMPDIR being deleted when PBS cleans up the
     * job or normal /tmp cleaning.
     */
    if (ret == 0) {
        const char *cp, *base;
        growstr_t *h;

        h = growstr_init();
        cp = getenv("TMPDIR");
        if (!cp || !*cp)
            cp = "/tmp";
        growstr_append(h, cp);

        for (cp=base=exec_to_dist; *cp; cp++)
            if (*cp == '/')
                base = cp+1;
        growstr_append(h, "/");
        growstr_append(h, base);

        config_set_unique_executable(strsave(h->s));
        growstr_free(h);
    }

out:
    unlink(file_template);
    free(file_template);
    free(usenodes);
#endif /* HAVE_FAST_DIST */

    return ret;
}