void i2c(i2c_t *t) { if (!process_is_running(&i2c_process)) list_init(transactions); list_add(transactions, t); if (!process_is_running(&i2c_process)) process_start(&i2c_process, NULL); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_kill_process, ev, data) { struct shell_command *c; char *name; PROCESS_BEGIN(); name = data; if(name == NULL || strlen(name) == 0) { shell_output_str(&kill_command, "kill <command>: command name must be given", ""); } for(c = list_head(commands); c != NULL; c = c->next) { if(strcmp(name, c->command) == 0 && c != &kill_command && process_is_running(c->process)) { command_kill(c); PROCESS_EXIT(); } } shell_output_str(&kill_command, "Command not found: ", name); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_process, ev, data) { static struct process *started_process; struct shell_input *input; int ret; PROCESS_BEGIN(); /* Let the system start up before showing the prompt. */ PROCESS_PAUSE(); shell_start(); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); { input = data; ret = shell_start_command(input->data1, input->len1, NULL, &started_process); if(started_process != NULL && ret == SHELL_FOREGROUND && process_is_running(started_process)) { front_process = started_process; PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED && data == started_process); } front_process = &shell_process; } shell_prompt(shell_prompt_text); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static void killall(void) { struct shell_command *c; for(c = list_head(commands); c != NULL; c = c->next) { if(c != &killall_command && process_is_running(c->process)) { command_kill(c); } } }
// Disconnect from the server int mqtt_disconnect() { if(!process_is_running(&mqtt_process)) return -1; printf("mqtt: exiting...\n"); mqtt_flags &= ~MQTT_FLAG_READY; mqtt_flags |= MQTT_FLAG_EXIT; tcpip_poll_tcp(mqtt_state.tcp_connection); return 0; }
/*---------------------------------------------------------------------------*/ static void exit_process(struct process *p, struct process *fromprocess) { register struct process *q; struct process *old_current = process_current; WDTE=0xac; PRINTF("process: exit_process '%s'\n", PROCESS_NAME_STRING(p)); /* Make sure the process is in the process list before we try to exit it. */ for(q = process_list; q != p && q != NULL; q = q->next); if(q == NULL) { return; } if(process_is_running(p)) { /* Process was running */ p->state = PROCESS_STATE_NONE; /* * Post a synchronous event to all processes to inform them that * this process is about to exit. This will allow services to * deallocate state associated with this process. */ for(q = process_list; q != NULL; q = q->next) { if(p != q) { call_process(q, PROCESS_EVENT_EXITED, (process_data_t)p); } } if(p->thread != NULL && p != fromprocess) { /* Post the exit event to the process that is about to exit. */ process_current = p; p->thread(&p->pt, PROCESS_EVENT_EXIT, NULL); } } if(p == process_list) { process_list = process_list->next; } else { for(q = process_list; q != NULL; q = q->next) { if(q->next == p) { q->next = p->next; break; } } } process_current = old_current; }
// Connect to the specified server int mqtt_connect(uip_ip6addr_t* address, uint16_t port, int auto_reconnect, mqtt_connect_info_t* info) { if(process_is_running(&mqtt_process)) return -1; mqtt_state.address = *address; mqtt_state.port = port; mqtt_state.auto_reconnect = auto_reconnect; mqtt_state.connect_info = info; mqtt_state.calling_process = PROCESS_CURRENT(); process_start(&mqtt_process, (const char*)&mqtt_state); return 0; }
/*---------------------------------------------------------------------------*/ static void input_to_child_command(struct shell_command *c, char *data1, int len1, const char *data2, int len2) { struct shell_input input; if(process_is_running(c->process)) { input.data1 = data1; input.len1 = len1; input.data2 = data2; input.len2 = len2; process_post_synch(c->process, shell_event_input, &input); } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_netcmd_server_process, ev, data) { static struct process *child_command; int err; PROCESS_BEGIN(); /* XXX: direct output to null. */ printf("netcmd server got command string '%s'\n", (char *)data); err = shell_start_command(data, strlen((char * )data), NULL, &child_command); if(err == SHELL_FOREGROUND && process_is_running(child_command)) { PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT || (ev == PROCESS_EVENT_EXITED && data == child_command)); if(ev == PROCESS_EVENT_EXIT) { process_exit(child_command); } } PROCESS_END(); }
/* Public API */ void mqtt_connect(uip_ip6addr_t* address, uint16_t port, uint16_t keepalive, char *name) { if(process_is_running(&mqtt_process)) { printf("process is already running\n"); return; } /* Coppy the host address and port */ memcpy(&mqtt.address, address, sizeof(uip_ip6addr_t)); mqtt.port = port; mqtt.keepalive = keepalive * CLOCK_SECOND; mqtt.keepalive_error = 0; mqtt.calling_process = PROCESS_CURRENT(); mqtt.nb_topics = 0; strcpy(mqtt.name, name); /* Set connection in progress */ mqtt.state = MQTT_STATE_CONNECTION_IN_PROGRESS; process_start(&mqtt_process, (const char*)&mqtt); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_repeat_server_process, ev, data) { static char *command; static struct process *started_process; char command_copy[MAX_COMMANDLENGTH]; int ret; if(ev == shell_event_input) { goto exit; } PROCESS_BEGIN(); command = data; PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE && data == &shell_repeat_process); { strncpy(command_copy, command, MAX_COMMANDLENGTH); ret = shell_start_command(command_copy, (int)strlen(command_copy), &repeat_command, &started_process); if(started_process != NULL && process_is_running(started_process)) { PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED && data == started_process); } } /* PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); printf("haha \n"); if(repeat_command.child != NULL && process_is_running(repeat_command.child->process)) { process_post_synch(repeat_command.child->process, ev, data); }*/ exit: ; PROCESS_END(); }
void ieee_init() { void *mac; MAC_Pib_s *pib; if (process_is_running(&ieee_process)) return; /* initialize ieee_eventhandler and event queue*/ rxq_init(); /* setup mac <-> app interface */ u32AppApiInit((PR_GET_BUFFER) rxq_mlme_alloc, (PR_POST_CALLBACK) ieee_process_poll, NULL, (PR_GET_BUFFER) rxq_mcps_alloc, (PR_POST_CALLBACK) ieee_process_poll, NULL); /* get mac and pib handles */ mac = pvAppApiGetMacHandle(); pib = MAC_psPibGetHandle(mac); /* do a full reset */ req_reset(true); /* set panid and default parameters */ MAC_vPibSetPanId(mac, IEEE802154_PANDID); MAC_vPibSetRxOnWhenIdle(mac, true, false); /* allocate an event for this process */ ieee_event = process_alloc_event(); pib->bAutoRequest = true; /* bandwidth control, smaller interframe gap and higher data rate, * this is not standard conform! */ #if defined(__BA2__) && defined(JENNIC_CONF_JN5148_FASTDATARATE) vAHI_BbcSetHigherDataRate(E_AHI_BBC_CTRL_DATA_RATE_1_MBPS); vAHI_BbcSetInterFrameGap(48); #endif process_start(&ieee_process, NULL); }
/*---------------------------------------------------------------------------*/ void shell_input(char *commandline, int commandline_len) { struct shell_input input; /* printf("shell_input front_process '%s'\n", front_process->name);*/ if(commandline[0] == '~' && commandline[1] == 'K') { /* process_start(&shell_killall_process, commandline);*/ if(front_process != &shell_process) { process_exit(front_process); } } else { if(process_is_running(front_process)) { input.data1 = commandline; input.len1 = commandline_len; input.data2 = ""; input.len2 = 0; process_post_synch(front_process, shell_event_input, &input); } } }
/** * \brief Makes a resource available under the given URI path * \param resource A pointer to a resource implementation * \param path The URI path string for this resource * * The resource implementation must be imported first using the * extern keyword. The build system takes care of compiling every * *.c file in the ./resources/ sub-directory (see example Makefile). */ void rest_activate_resource(resource_t *resource, char *path) { resource->url = path; list_add(restful_services, resource); PRINTF("Activating: %s\n", resource->url); /* Only add periodic resources with a periodic_handler and a period > 0. */ if(resource->flags & IS_PERIODIC && resource->periodic->periodic_handler && resource->periodic->period) { PRINTF("Periodic resource: %p (%s)\n", resource->periodic, resource->periodic->resource->url); list_add(restful_periodic_services, resource->periodic); if(process_is_running(&rest_engine_process)) { PRINTF("Periodic: Set timer for /%s to %lu\n", resource->url, resource->periodic->period); PROCESS_CONTEXT_BEGIN(&rest_engine_process); etimer_set(&resource->periodic->periodic_timer, resource->periodic->period); PROCESS_CONTEXT_END(&rest_engine_process); } } }
gboolean is_seafile_daemon_running () { return process_is_running ("seaf-daemon"); }
/*---------------------------------------------------------------------------*/ static struct shell_command * start_command(char *commandline, struct shell_command *child) { char *next, *args; int command_len; struct shell_command *c; /* Shave off any leading spaces. */ while(*commandline == ' ') { commandline++; } /* Find the next command in a pipeline and start it. */ next = find_pipe(commandline); if(next != NULL) { *next = 0; child = start_command(next + 1, child); } /* Separate the command arguments, and remove braces. */ replace_braces(commandline); args = strchr(commandline, ' '); if(args != NULL) { args++; } /* Shave off any trailing spaces. */ command_len = (int)strlen(commandline); while(command_len > 0 && commandline[command_len - 1] == ' ') { commandline[command_len - 1] = 0; command_len--; } if(args == NULL) { command_len = (int)strlen(commandline); args = &commandline[command_len]; } else { command_len = (int)(args - commandline - 1); } /* Go through list of commands to find a match for the first word in the command line. */ for(c = list_head(commands); c != NULL && !(strncmp(c->command, commandline, command_len) == 0 && c->command[command_len] == 0); c = c->next); if(c == NULL) { shell_output_str(NULL, commandline, ": command not found (try 'help')"); command_kill(child); c = NULL; } else if(process_is_running(c->process) || child == c) { shell_output_str(NULL, commandline, ": command already running"); c->child = NULL; c = NULL; } else { c->child = child; /* printf("shell: start_command starting '%s'\n", c->process->name);*/ /* Start a new process for the command. */ process_start(c->process, args); } return c; }
/*---------------------------------------------------------------------------*/ static void exit_process(struct process *p, struct process *fromprocess) { register struct process *q; register struct process *r; struct process * tmp_ptr; //PT_THREAD((* tmp_func_ptr)(struct pt *, process_event_t, process_data_t)); struct process *old_current = process_current; int ret; bool any_marked; uint8_t tmp; PRINTF("process: exit_process '%s'\n", PROCESS_NAME_STRING(p)); /* Make sure the process is in the process list before we try to exit it. */ for (q = process_list; q != p && q != NULL; q = q->next); if (q == NULL) { return; } if (process_is_running(p)) { /* Process was running */ p->state = PROCESS_STATE_NONE; p->xc8_aux = XC8_AUX_STATE_MARKED_FOR_EXIT; } do { any_marked = false; /* * Post a synchronous event to all processes to inform them that * this process is about to exit. This will allow services to * deallocate state associated with this process. */ for (r = process_list; r != NULL; r = r->next) { if (r->xc8_aux & XC8_AUX_STATE_MARKED_FOR_EXIT) { for (q = process_list; q != NULL; q = q->next) { if ((q->xc8_aux & XC8_AUX_STATE_MARKED_FOR_EXIT) == 0) { //call_process(q, PROCESS_EVENT_EXITED, (process_data_t)p); /****************************** * * removing recursion * ***************************************************/ if ((q->state & PROCESS_STATE_RUNNING) && q->thread != NULL) { PRINTF("process: calling process '%s' with event PROCESS_EVENT_EXITED \n", PROCESS_NAME_STRING(q)); process_current = q; q->state = PROCESS_STATE_CALLED; ret = q->thread(&q->pt, PROCESS_EVENT_EXITED, (process_data_t) r); if (ret == PT_EXITED || ret == PT_ENDED /*|| PROCESS_EVENT_EXITED == PROCESS_EVENT_EXIT*/) { //exit_process(p,p); tmp = q->xc8_aux | XC8_AUX_STATE_MARKED_FOR_EXIT; q->xc8_aux = tmp; any_marked = true; if (process_is_running(q)) { q->state = PROCESS_STATE_NONE; } } else { q->state = PROCESS_STATE_RUNNING; } } } } } } } while (any_marked); //We are repeating until no process need exit if (p->thread != NULL && p != fromprocess) { /* Post the exit event to the process that is about to exit. */ process_current = p; p->thread(&p->pt, PROCESS_EVENT_EXIT, NULL); } // We are removing all processed marked for exit for (r = process_list; r != NULL; r = r->next) { if (r->xc8_aux & XC8_AUX_STATE_MARKED_FOR_EXIT) { r->xc8_aux = XC8_AUX_STATE_NONE; r->state = PROCESS_STATE_NONE; if (r == process_list) { process_list = process_list->next; } else { for (q = process_list; q != NULL; q = q->next) { if (q->next == r) { tmp_ptr = r->next; q->next = tmp_ptr; break; } } } } } process_current = old_current; }
static inline gboolean seafile_is_running () { return (process_is_running("ccnet-applet") || process_is_running ("seaf-daemon")); }
/* * The definition of the process. */ PROCESS_THREAD(twamp_tcp_control_server, ev, data) { /* * The process begins here. */ uip_ipaddr_t *ipaddr; PROCESS_BEGIN(); set_global_address(); /* * We start with setting up a listening TCP port. Note how we're * using the UIP_HTONS() macro to convert the port number (862) to * network byte order as required by the tcp_listen() function. */ tcp_listen(UIP_HTONS(862)); /* * We loop for ever, accepting new connections. */ while(1) { /* * We wait until we get the first TCP/IP event, which probably * comes because someone connected to us. */ PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); /* * If a peer connected with us, we'll initialize the protosocket * with PSOCK_INIT(). */ if(uip_connected()) { /* * The PSOCK_INIT() function initializes the protosocket and * binds the input buffer to the protosocket. */ PSOCK_INIT(&ps, buffer, sizeof(buffer)); printf("Someone connected!\n"); /* * We loop until the connection is aborted, closed, or times out. */ while(!(uip_aborted() || uip_closed() || uip_timedout())) { /* * We wait until we get a TCP/IP event. Remember that we * always need to wait for events inside a process, to let * other processes run while we are waiting. */ PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); /* * Here is where the real work is taking place: we call the * handle_connection() protothread that we defined above. This * protothread uses the protosocket to receive the data that * we want it to. */ if(state == 1){ connection_setup(&ps); } if(state == 2){ create_test_session(&ps); } if(state == 3){ timesynch(&ps); } if(state == 4){ //PT_INIT(&pthread); //run_test_session(&ps); process_start(&run_test_session,NULL); PROCESS_YIELD_UNTIL(!process_is_running(&run_test_session)); } } } } /* * We must always declare the end of a process. */ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_randwait_process, ev, data) { static int maxwait; static char command[MAX_COMMANDLENGTH]; static struct etimer etimer; static struct process *started_process; const char *args, *next; int ret; /* if(ev == shell_event_input) { struct shell_input *input; input = data; printf("shell randwait input %d %d\n", input->len1, input->len2); if(input->len1 + input->len2 != 0) { shell_output(&randwait_command, input->data1, input->len1, input->data2, input->len2); } }*/ PROCESS_BEGIN(); args = data; if(args == NULL) { shell_output_str(&randwait_command, "usage 0", ""); PROCESS_EXIT(); } maxwait = shell_strtolong(args, &next); if(next == args) { shell_output_str(&randwait_command, "usage 1", ""); PROCESS_EXIT(); } args = next; while(*args == ' ') { args++; } strncpy(command, args, MAX_COMMANDLENGTH); if(strlen(command) == 0) { shell_output_str(&repeat_command, "usage 3", ""); PROCESS_EXIT(); } /* printf("randwait %d command '%s'\n", maxwait, command);*/ etimer_set(&etimer, random_rand() % (CLOCK_SECOND * maxwait)); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); /* printf("Starting '%s' child %p (%s)\n", command, randwait_command.child, */ /* randwait_command.child == NULL? "null": randwait_command.child->command); */ ret = shell_start_command(command, (int)strlen(command), randwait_command.child, &started_process); if(started_process != NULL && process_is_running(started_process)) { PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED && data == started_process); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ void batmon_log(uint8_t trigger) { uint32_t next; /* Only continue if the process (us) is running */ if(!process_is_running(&batmon_process)) { return; } next = f.a; next |= (((uint32_t) f.p) << 8); next |= (((uint32_t) f.s) << 16); memcpy(r.magic, magic, sizeof(magic)); r.trigger = trigger; r.c = clock_seconds(); /* Read VDD and use as ADC reference */ r.v = s->value(ADC_SENSOR_TYPE_VDD); /* And then carry on with battery */ r.b = s->value(ADC_SENSOR_TYPE_BATTERY); #if ENERGEST_CONF_ON /* ENERGEST values */ r.mcu = energest_type_time(ENERGEST_TYPE_CPU); r.lpm = energest_type_time(ENERGEST_TYPE_LPM); r.irq = energest_type_time(ENERGEST_TYPE_IRQ); r.tx = energest_type_time(ENERGEST_TYPE_TRANSMIT); r.rx = energest_type_time(ENERGEST_TYPE_LISTEN); r.f_write = energest_type_time(ENERGEST_TYPE_FLASH_WRITE); r.f_read = energest_type_time(ENERGEST_TYPE_FLASH_READ); #endif n740_analog_deactivate(); /* Make sure we're on */ if(M25P16_WIP()) { m25p16_res(); } m25p16_pp((uint8_t *)&f, (uint8_t *)&r, sizeof(r)); n740_analog_activate(); PRINTF("BatMon: @%lu [%u] ", r.c, r.trigger); PRINTF("BatMon: 0x%02x%02x%02x\n", f.s, f.p, f.a); next += RECORD_SIZE; if(next >= FLASH_END_ADDR) { abort(); return; } f.s = ((next & 0xFF0000) >> 16); f.p = ((next & 0xFF00) >> 8); f.a = next & 0xFF; if(trigger == LOG_TRIGGER_PERIODIC) { etimer_reset(&et); } }