TASKQ *task_freeq (TASKQ *q) { TASK *t; task_stop (q); wait_mutex (q); debug ("freeing queue\n"); while ((t = q->queue) != NULL) { q->queue = t->next; free (t); } debug ("freeing pool\n"); while ((t = q->pool) != NULL) { q->pool = t->next; free (t); } debug ("closing event and critical section\n"); end_mutex (q); destroy_mutex (q); destroy_ready (q); free (q); return (NULL); }
void iboot_loader_run(void) { uint64_t startTime = timer_get_system_microtime(); // boot iboot when either the up button is pressed or after 10 seconds static Boolean buttonPressed = FALSE; static Boolean messageShown = FALSE; while(1) { if (!gpio_pin_state(BUTTONS_VOLUP) || (has_elapsed(startTime, 10 * 1000 * 1000) && !buttonPressed)) { load_iboot(); task_stop(); } if (gpio_pin_state(BUTTONS_HOLD)) { buttonPressed = TRUE; } if (has_elapsed(startTime, 2 * 1000 * 1000) && !messageShown) { // show a welcome message after 2 seconds to skip all of the usb spam bufferPrintf("===================\r\n"); bufferPrintf("Welcome to the 2g touch experimental openiBoot!\r\n"); bufferPrintf("iBoot will be automatically loaded after 10 seconds\r\n"); bufferPrintf("Press the power button to cancel automatic booting\r\n"); bufferPrintf("Press the volume up button to load ios\r\n"); bufferPrintf("===================\r\n"); bufferPrintf("\r\n\r\n\r\n"); messageShown = TRUE; } task_yield(); } }
static void acm_parse(int32_t _amt) { int i = 0; char **argv; int argc; char scratch[ACM_BUFFER_SIZE]; for(; i < _amt; i++) { if(acm_recv_buffer[i] == '\n' || acm_recv_buffer[i] == '\r') { _amt = i; break; } } acm_recv_buffer[_amt] = 0; memcpy(scratch, acm_recv_buffer, _amt+1); argv = command_parse(scratch, &argc); if(argc >= 3 && strcmp(argv[0], "sendfile") == 0) { acm_busy = TRUE; acm_file_ptr = (char*)parseNumber(argv[1]); acm_file_recv_left = parseNumber(argv[2]); received_file_size = acm_file_recv_left; bufferPrintf("ACM: Started receiving file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_recv_left, acm_file_recv_left); } else if(argc >= 3 && strcmp(argv[0], "recvfile") == 0) { acm_busy = TRUE; acm_file_ptr = (char*)parseNumber(argv[1]); acm_file_send_left = parseNumber(argv[2]); bufferPrintf("ACM: Started sending file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_send_left, acm_file_send_left); int amt = sprintf(acm_send_buffer, "ACM: Starting File: %d %d\n", (uint32_t)acm_file_ptr, acm_file_send_left); usb_send_bulk(ACM_EP_SEND, acm_send_buffer, amt); } else { bufferPrintf("ACM: Starting %s\n", acm_recv_buffer); if(command_run(argc, argv) == 0) bufferPrintf("ACM: Done: %s\n", acm_recv_buffer); else bufferPrintf("ACM: Unknown command: %s\n", argv[0]); } free(argv); EnterCriticalSection(); // Deliberately unended. usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps); task_stop(); }
int dc_task_stop(struct task *task) { int r = 0; if (task->running == 0 ) return 0; mod_process(task_stop(task)); task->running = 0; dc_on_task_stopped(task); return 0; }
void k9_task_exit(int code) { k9_cpu_intr_dis(); assert(cur_task != idle_task); cur_task->exit_code = code; task_stop(cur_task, K9_TASK_STATE_EXITED); _k9_task_resched(); }
void k9_task_stop(struct k9_task *task) { uint32 old; task = task_or_self(task); assert(task != idle_task); old = k9_cpu_intr_dis(); if (task_stop(task, K9_TASK_STATE_STOPPED)) _k9_task_resched(); k9_cpu_intr_restore(old); }
void task_run(void (*_fn)(void*), void *_arg) { LeaveCriticalSection(); //bufferPrintf("tasks: New task started %s. 0x%08x(0x%08x).\r\n", // CurrentRunning->taskName, _fn, _arg); _fn(_arg); //bufferPrintf("tasks: Task ending %s. 0x%08x(0x%08x).\r\n", // CurrentRunning->taskName, _fn, _arg); EnterCriticalSection(); task_stop(); }
/* * Poll all queues... * a thread, expected to be started from the TASKQ. Note you must * re-register processors once this task exits. * * Note we expect sender_xml to have QueueInfo embedded! */ int qpoller_task (void *parm) { int i, poll_interval, num_queues; QPOLLER *p; QPOLLERJOB *j; TASKQ *q; XML *xml = (XML *) parm; info ("Queue Poller starting\n"); num_queues = xml_count (xml, QP_QUEUE); if ((poll_interval = xml_get_int (xml, QP_INFO".PollInterval")) < 1) poll_interval = 5; poll_interval *= 1000; if ((i = xml_get_int (xml, QP_INFO".MaxThreads")) < 1) i = 1; q = task_allocq (i, poll_interval); debug ("%d queues %d interval\n", num_queues, poll_interval); while (phineas_running ()) { for (i = 0; i < num_queues; i++) { qpoller_poll (xml, i, q); } sleep (poll_interval); } debug ("Queue Poller shutting down...\n"); task_stop (q); task_freeq (q); while ((j = QpollerJobs) != NULL) { QpollerJobs = j->next; free (j); } while ((p = Qpoller) != NULL) { Qpoller = p->next; free (p); } info ("Queue Poller exiting\n"); return (0); }
/* * Listen for incoming connections until told to stop */ int server_listen (XML *xml, NETCON *conn, NETCON *ssl, SSL_CTX *ctx, int threads) { char *ch; TASKQ *t; struct timeval timeout; fd_set fds; if ((conn == NULL) && (ssl == NULL)) return (-1); t = task_allocq (threads, 2); timeout.tv_sec = 2; timeout.tv_usec = 0; /* * Keep servicing requests until they stop coming in AND we are * no longer running. This insures a nice shutdown, although a * naughty client could keep us from shutting down by flooding us * with requests. We could add a counter here to prevent that. */ while (1) { FD_ZERO (&fds); if (conn != NULL) FD_SET (conn->sock, &fds); if (ssl != NULL) FD_SET (ssl->sock, &fds); if (select (2, &fds, NULL, NULL, &timeout) <= 0) { if (phineas_running ()) continue; break; } if ((conn != NULL) && FD_ISSET (conn->sock, &fds)) server_accept (xml, conn, NULL, t); if ((ssl != NULL) && FD_ISSET (ssl->sock, &fds)) server_accept (xml, ssl, ctx, t); } task_stop (t); task_freeq (t); return (0); }
/** * Check the service still exists and start a worker that will * just perform a TCP-connect test. */ static int _check_tcp_service_task(gpointer udata, GError **error) { struct service_info_s *si; struct namespace_data_s *ns_data; struct taskdata_checksrv_s *task_data; task_data = udata; ns_data = g_hash_table_lookup(namespaces, task_data->ns_name); if (!ns_data) { task_done(task_data->task_name); GSETERROR(error, "Namespace unavailable"); return 0; } /* if the service does not exists, the task itself is de-scheduled */ if (!(si=g_hash_table_lookup(ns_data->local_services, task_data->srv_key)) && !(si=g_hash_table_lookup(ns_data->down_services, task_data->srv_key))) { task_done(task_data->task_name); task_stop(task_data->task_name); INFO("Service [%s] does not exist, stopping task [%s]", task_data->srv_key, task_data->task_name); return 1; } /* Now start a worker for this service. The worker has its own session_data, * without hard reference to the task_t or the namespace_data_t */ do { int fd = addrinfo_connect_nopoll(&(si->addr), 1000, error); if (0 > fd) { GSETERROR(error, "Connection to gridd server failed : (%d) %s", errno, strerror(errno)); return 0; } sock_set_linger(fd, 1, 0); struct workerdata_checksrv_s *wdata = g_malloc0(sizeof(*wdata)); g_strlcpy(wdata->task_name, task_data->task_name, sizeof(wdata->task_name)-1); g_strlcpy(wdata->ns_name, task_data->ns_name, sizeof(wdata->ns_name)-1); g_strlcpy(wdata->srv_key, task_data->srv_key, sizeof(wdata->srv_key)-1); worker_t *worker = g_malloc0(sizeof(worker_t)); worker->func = _check_tcp_service_worker_func; worker->clean = _check_tcp_service_worker_cleaner; worker->timeout.startup = 1000; worker->timeout.activity = 1000; worker->data.sock_timeout = 1000; worker->data.fd = fd; worker->data.session = wdata; if (!add_fd_to_io_scheduler(worker, EPOLLOUT, error)) { _mark_service_state(task_data->ns_name, wdata->srv_key, FALSE); task_done(task_data->task_name); g_free(worker); g_free(wdata); GSETERROR(error, "Failed to add socket fd=%d to io_scheduler : %s", fd, strerror(errno)); return 0; } TRACE("TCP-connect tried to [%s] for [%s] (fd=%d)", task_data->srv_key, task_data->task_name, fd); } while (0); return 1; }
void tx_task ( dword dummy /* Parameter required for REX. Tell lint to ignore it. */ /*lint -esym(715,dummy) */ ) { rex_sigs_type rex_signals_mask; /* Mask of signals returned by rex */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /*------------------------*/ /* Perform initialization */ /*------------------------*/ #ifdef FEATURE_ACP #error code not present #endif /* FEATURE_ACP */ txc_powerup_init(); /*------------------*/ /* Initialize timer */ /*------------------*/ rex_def_timer( &tx_rpt_timer, &tx_tcb, TX_RPT_TIMER_SIG ); /*-----------------------------------------------------*/ /* Process task startup procedure from task controller */ /*-----------------------------------------------------*/ task_start( TX_RPT_TIMER_SIG, /* report timer signal for task */ DOG_TX_RPT, /* watchdog report signal */ &tx_rpt_timer /* pointer to report timer */ ); /*--------------------------------------------------------------------*/ /* Initially kick watchdog and set timer for watchdog report interval */ /*--------------------------------------------------------------------*/ TX_WATCHDOG_REPORT( ); for (;;) { /* Never exit this loop... */ #ifdef FEATURE_ACP #error code not present #else rex_signals_mask = rex_wait( TX_RPT_TIMER_SIG | TX_CDMA_CMD_Q_SIG | TASK_OFFLINE_SIG | TASK_STOP_SIG ); #endif if ((rex_signals_mask & TX_RPT_TIMER_SIG) != 0) { /*-------------------------------*/ /* Kick watchdog and reset timer */ /*-------------------------------*/ TX_WATCHDOG_REPORT( ); } /*---------------------------------------------------------*/ /* Check if powerdown command signal was set. If set then */ /* clear signal, process task stop procedure, and proceed. */ /*---------------------------------------------------------*/ if ((rex_signals_mask & TASK_STOP_SIG) != 0) { MSG_MED( "TASK_STOP_SIG received", 0,0,0 ); (void) rex_clr_sigs( &tx_tcb, TASK_STOP_SIG ); task_stop(); #if (TG==T_PC) #error code not present #endif } /*-------------------------------------------------------*/ /* Check if offline command signal was set. If set then */ /* clear signal, process task offline procedure, and */ /* proceed. */ /*-------------------------------------------------------*/ if ((rex_signals_mask & TASK_OFFLINE_SIG) != 0) { MSG_MED( "TASK_OFFLINE_SIG received", 0,0,0 ); (void) rex_clr_sigs( &tx_tcb, TASK_OFFLINE_SIG ); task_offline(); } /*------------------------------------------------------------------*/ /* The (analog or CDMA) MC subtask indicates it wishes to acvtivate */ /* the (analog or CDMA) subtask by setting the command queue signal */ /* (via a call to acptx_cmd() or txc_cmd()). */ /*------------------------------------------------------------------*/ if ((rex_signals_mask & TX_CDMA_CMD_Q_SIG) != 0) { /*--------------------------------------------------------*/ /* Clear watchdog timer before passing control to subtask */ /*--------------------------------------------------------*/ TX_CLEAR_WATCHDOG_TIMER( ); /*------------------------------------*/ /* Activate the CDMA Transmit subtask */ /*------------------------------------*/ MSG_LOW( "Entering txc_subtask", 0,0,0 ); txc_subtask(); MSG_LOW( "Exiting txc_subtask", 0,0,0 ); /*-------------------------------*/ /* Kick watchdog and reset timer */ /*-------------------------------*/ TX_WATCHDOG_REPORT( ); } /* end if ((rex_signals_mask & TX_CDMA_CMD_Q_SIG) != 0) */ #ifdef FEATURE_ACP #error code not present #endif /* FEATURE_ACP */ } /* end for (;;) */ } /* end tx_task */
int test_basic() { task_info *info1=(task_info*)malloc(sizeof(task_info)); //initialize the signal //signal_init(); // initialize the task info1->task=task1; info1->tv.tv_sec = 5; info1->tv.tv_usec = 0; info1->arg=(int *)100; if( task_start(info1) ) ERR_EXIT("task_start task1 failure!"); sleep(1); printf("wakeup serval times\n"); //wake up several times if(task_wakeup(info1)) ERR_EXIT("task_wakeup task1 failure!"); if(task_wakeup(info1)) ERR_EXIT("task_wakeup task1 failure!"); if(task_wakeup(info1)) ERR_EXIT("task_wakeup task1 failure!"); sleep(1); printf("the nomal flow\n"); sleep(10); //suspend the task if(task_suspend(info1)) ERR_EXIT("task_suspend task1 failure!"); printf("be suspend here for 30 seconds\n"); sleep(30); printf("will be resume here\n"); //resume the task if(task_resume(info1)) ERR_EXIT("task_resume task1 failure!"); sleep(20); if(task_suspend(info1)) ERR_EXIT("task_suspend task1 failure!"); printf("be suspend here for 10 seconds\n"); sleep(10); printf("be stop here\n"); //stop the task if(task_stop(info1)) ERR_EXIT("task_stop task1 failure!"); //join the tasks pthread_join(info1->tid,NULL); return 0; }
int test_robust() { //int num=500; //int num=FD_SETSIZE; int num=2000; task_info *tasks[num]; int loop; for(loop=0;loop<num;++loop) { task_info *info1=(task_info*)malloc(sizeof(task_info)); // initialize the task info1->task=task1; info1->tv.tv_sec =2 ; info1->tv.tv_usec =0; info1->arg=(int *)loop; tasks[loop]=info1; } for(loop=0;loop<num;++loop) { if( task_start(tasks[loop]) ) ERR_EXIT("task_start task1 failure!"); } printf("will be wakeup here for several times\n"); sleep(10); for(loop=0;loop<1;++loop) { if(task_wakeup(tasks[loop])) ERR_EXIT("task_suspend task1 failure!"); } sleep(10); printf("will be suspended here for 10 seconds\n"); sleep(10); for(loop=0;loop<num;++loop) { if(task_suspend(tasks[loop])) ERR_EXIT("task_suspend task1 failure!"); } sleep(10); printf("will be resumed here\n"); sleep(2); for(loop=0;loop<num;++loop) { if(task_resume(tasks[loop])) ERR_EXIT("task_resume task1 failure!"); } sleep(10); printf("will be stop here\n"); sleep(2); for(loop=0;loop<num;++loop) { if(task_stop(tasks[loop])) ERR_EXIT("task_stop task1 failure!"); } for(loop=0;loop<num;++loop) { pthread_join(tasks[loop]->tid,NULL); } return 0; }
static void video_async_task (dword parm) { rex_sigs_type sigs; uint8 usedfilehandle; (void) parm; /*lint -e{716} infinite loop requires here */ while (1) { /* XXX: Replace 0xffffffff with the actual signal mask once we know * what signal to use to process the async writes. 0xffffffff will work * though. */ sigs = rex_wait (0xffffffff); (void)rex_clr_sigs (rex_self (), 0xffffffff); if ((sigs & TASK_OFFLINE_SIG) != 0) task_offline (); if ((sigs & TASK_STOP_SIG) != 0) task_stop (); if ((VIDEO_ASYNC_SIG & sigs) != 0) { efs_process_async_writes (); } if( ((sigs & VIDEO_ASYNC_SIG_FILECLOSE) != 0)|| ((sigs & VIDEO_ASYNC_SIG_FILEUNLINK) != 0) ) { for(usedfilehandle = 0;usedfilehandle<MAX_FILE_CLOSE_SIZE;usedfilehandle++) { if(fs_handle_close[usedfilehandle]) { (void)video_eng_file_fclose (fs_handle_close[usedfilehandle]); fs_handle_close[usedfilehandle] = NULL; } } for(usedfilehandle = 0;usedfilehandle<MAX_FILE_CLOSE_SIZE;usedfilehandle++) { if(filenames [usedfilehandle].used == 1) { efs_unlink (filenames [usedfilehandle].filename); filenames [usedfilehandle].used = 0; } } } /* this should be before INIT if block in this loop ** Here we assume that all the previous call to the efs ** are synchronous */ if (sigs & VIDEO_ASYNC_SIG_REQ_COMPLETE) { (void)rex_set_sigs(video_async_client_tcb, video_async_client_sig ); video_async_client_tcb = NULL; } } }
void ds_task ( dword ignored /* lint -esym(715,ignored) ** Have lint not complain about the ignored parameter 'ignored' which is ** specified to make this routine match the template for rex_def_task(). */ ) { rex_sigs_type requested_sigs; /* Signal mask to suspend on */ rex_sigs_type set_sigs; /* Signals set upon return from wait */ #ifndef FEATURE_DATA_STRIP_ATCOP rex_sigs_type siolib_sigs = 0; /* SIOLIB signals to suspend on */ rex_sigs_type atcop_sigs = 0; /* ATCoP signals to suspend on */ #endif rex_sigs_type ucsd_sigs = 0; /* UMTS CS Hdlr signals to suspend on */ rex_sigs_type wpsd_sigs = 0; /* WCDMA PS Hdlr signals to suspend on */ rex_sigs_type cdma_sigs = 0; /* CDMA sub-task signals to suspend on */ #ifndef FEATURE_ASYNC_DATA_NOOP rex_sigs_type async707_sigs= 0; /* 707 async signals to suspend on */ #endif /* FEATURE_ASYNC_DATA_NOOP */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /*------------------------------------------------------------------------- Do task initialization. The init function performs all the task-level initialization. -------------------------------------------------------------------------*/ dsi_task_init(); /*------------------------------------------------------------------------- Initialize timers -------------------------------------------------------------------------*/ ds3gi_timer_init(); #ifndef FEATURE_DATA_STRIP_ATCOP /*------------------------------------------------------------------------- Initialize SIOLIB -------------------------------------------------------------------------*/ siolib_sigs = ds3g_siolib_init(); #endif /*------------------------------------------------------------------------- Wait for the task start signal from task controller. -------------------------------------------------------------------------*/ task_start(DS_DOG_RPT_TIMER_SIG, DOG_DS_RPT, &ds_dog_rpt_timer); /*------------------------------------------------------------------------- Perform sub-task initialization. -------------------------------------------------------------------------*/ #if defined(FEATURE_DATA_WCDMA_PS) || defined(FEATURE_GSM_GPRS) #error code not present #endif /*(FEATURE_DATA_WCDMA_PS) || defined(FEATURE_GSM_GPRS) */ /*------------------------------------------------------------------------- Each sub-task returns a signal mask containing the signals it wishes to suspend on. Note that ATCoP initialization should always be performed first, since other sub-tasks may use AT parameter values during initialization. -------------------------------------------------------------------------*/ #ifndef FEATURE_DATA_STRIP_ATCOP atcop_sigs = dsat_init(); #else #ifdef FEATURE_UIM_SUPPORT_3GPD dsatprofile_init_me(); #endif /* FEATURE_UIM_SUPPORT_3GPD */ dsatprofile_nv_sync(); #endif /* FEATURE_DATA_STRIP_ATCOP */ ds3g_init(); #ifdef FEATURE_HDR #error code not present #endif /* FEATURE_HDR */ #if ((defined(FEATURE_WCDMA) && defined(FEATURE_DATA_WCDMA_CS)) || \ (defined(FEATURE_GSM) && defined(FEATURE_DATA_GCSD))) #error code not present #endif #if ((defined(FEATURE_WCDMA) && defined(FEATURE_DATA_WCDMA_PS)) || \ (defined(FEATURE_GSM ) && defined(FEATURE_GSM_GPRS))) #error code not present #endif #if defined(FEATURE_DATA_IS707) /*------------------------------------------------------------------------- Make sure that Pkt iface is always initialized before Async iface. This is because ps_iface assigns instance numbers to iface in sequential order. We want pkt iface to get instance 0...max_pkt_ifaces since Apps call ioctls on pkt iface using those instance numbers. -------------------------------------------------------------------------*/ cdma_sigs = ds707_pkt_mgr_init(); #ifndef FEATURE_ASYNC_DATA_NOOP async707_sigs= ds707_async_mgr_powerup_init(); #endif /*FEATURE_ASYNC_DATA_NOOP*/ #endif /*------------------------------------------------------------------------- Get DS NV Items. -------------------------------------------------------------------------*/ dsi_nv_init(); /*------------------------------------------------------------------------- Signal mask to suspend on is the combination of all the signals requested by each of the sub-tasks. -------------------------------------------------------------------------*/ requested_sigs = DS_CMD_Q_SIG | DS_TASK_STOP_SIG | DS_TASK_OFFLINE_SIG | #ifndef FEATURE_DATA_STRIP_ATCOP siolib_sigs | atcop_sigs | #endif ucsd_sigs | wpsd_sigs | #ifndef FEATURE_ASYNC_DATA_NOOP async707_sigs | #endif /* FEATURE_ASYNC_DATA_NOOP */ cdma_sigs; /*------------------------------------------------------------------------- Main task loop, never exits. -------------------------------------------------------------------------*/ for( ;; ) { /*---------------------------------------------------------------------- Wait for one of the specified signals to be set. Note that watchdog kicking is performed in the wait. -----------------------------------------------------------------------*/ set_sigs = dsi_wait( requested_sigs ); /*---------------------------------------------------------------------- We used to individually clear the wrong set of signals and some signals were getting lost. Here, we clear ds_tcb with set_sigs. set_sigs is not altered. ----------------------------------------------------------------------*/ (void)rex_clr_sigs( &ds_tcb, set_sigs ); /*---------------------------------------------------------------------- If any of the task signals were received, invoke the function to ACK task conroller. -----------------------------------------------------------------------*/ if( (set_sigs & DS_TASK_STOP_SIG) != 0 ) { task_stop(); } if( (set_sigs & DS_TASK_OFFLINE_SIG) != 0 ) { task_offline(); } /*---------------------------------------------------------------------- If the command queue signal was set, clear the signal and invoke the function that dispatches commands to the appropriate sub-task. -----------------------------------------------------------------------*/ if( (set_sigs & DS_CMD_Q_SIG) != 0 ) { dsi_process_cmds(); } /*---------------------------------------------------------------------- If any of the 3G SIOLIB signals were set, clear the signals and invoke a function to process the signals. -----------------------------------------------------------------------*/ #ifndef FEATURE_DATA_STRIP_ATCOP if( (set_sigs & siolib_sigs) != 0 ) { ds3g_siolib_process_signals( set_sigs ); } /*---------------------------------------------------------------------- If any of the ATCoP signals were set, clear the signals and invoke a function to process the signals. -----------------------------------------------------------------------*/ if( (set_sigs & atcop_sigs) != 0 ) { dsat_process_async_signal( set_sigs ); } #endif #if ((defined(FEATURE_WCDMA) && defined(FEATURE_DATA_WCDMA_CS)) || \ (defined(FEATURE_GSM) && defined(FEATURE_DATA_GCSD))) #error code not present #endif #if ((defined(FEATURE_WCDMA) && defined(FEATURE_DATA_WCDMA_PS)) ||\ (defined(FEATURE_GSM ) && defined(FEATURE_GSM_GPRS))) #error code not present #endif #if defined(FEATURE_DATA_IS707) /*---------------------------------------------------------------------- If any of the WCDMA CS Hdlr signals were set, clear the signals and invoke a function to process the signals. -----------------------------------------------------------------------*/ if( (set_sigs & cdma_sigs) != 0 ) { ds707_pkt_process_signals( set_sigs ); } /*---------------------------------------------------------------------- If any of the WCDMA CS Hdlr signals were set, clear the signals and invoke a function to process the signals. -----------------------------------------------------------------------*/ #ifndef FEATURE_ASYNC_DATA_NOOP if( (set_sigs & async707_sigs) != 0 ) { ds707_async_process_signals( set_sigs ); } #endif /* FEATURE_ASYNC_DATA_NOOP */ #endif } /* forever */ } /* ds_task() */
static void acm_parse(int32_t _amt) { int start = 0; int i = 0; if(acm_file_ptr != NULL && acm_file_recv_left > 0) { if(_amt >= acm_file_recv_left) { memcpy(acm_file_ptr, acm_recv_buffer, acm_file_recv_left); i = acm_file_recv_left; start = i; bufferPrintf("ACM: Received file (finished at 0x%08x)!\n", acm_file_ptr + acm_file_recv_left); acm_file_ptr = NULL; acm_file_recv_left = 0; } else { memcpy(acm_file_ptr, acm_recv_buffer, _amt); acm_file_ptr += _amt; acm_file_recv_left -= _amt; //bufferPrintf("ACM: Got %d of file (%d remain).\n", _amt, acm_file_recv_left); EnterCriticalSection(); // Deliberately unended. usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps); return; } } for(; i < _amt; i++) { if(acm_recv_buffer[i] == '\n') { acm_recv_buffer[i] = 0; if(i > 0) if(acm_recv_buffer[i-1] == '\r') acm_recv_buffer[i-1] = 0; char safeCommand[ACM_BUFFER_SIZE]; char *command = &acm_recv_buffer[start]; strcpy(safeCommand, command); int argc; char** argv = command_parse(command, &argc); if(argc >= 3 && strcmp(argv[0], "sendfile") == 0) { acm_file_ptr = (char*)parseNumber(argv[1]); acm_file_recv_left = parseNumber(argv[2]); received_file_size = acm_file_recv_left; bufferPrintf("ACM: Started receiving file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_recv_left, acm_file_recv_left); i = _amt; start = i; } else if(argc >= 3 && strcmp(argv[0], "recvfile") == 0) { acm_busy = TRUE; acm_file_ptr = (char*)parseNumber(argv[1]); acm_file_send_left = parseNumber(argv[2]); bufferPrintf("ACM: Started sending file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_send_left, acm_file_send_left); int amt = sprintf(acm_send_buffer, "ACM: Starting File: %d %d\n", (uint32_t)acm_file_ptr, acm_file_send_left); usb_send_bulk(ACM_EP_SEND, acm_send_buffer, amt+1); i = _amt; start = i; } else { bufferPrintf("ACM: Starting %s\n", safeCommand); if(command_run(argc, argv) == 0) bufferPrintf("ACM: Done: %s\n", safeCommand); else bufferPrintf("ACM: Unknown command: %s\n", command); start = i+1; } free(argv); } } EnterCriticalSection(); // Deliberately unended. if(start < _amt) { if(acm_unprocessed > 0) { bufferPrintf("ACM: command too long, discarding...\n"); acm_unprocessed = 0; usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps); task_stop(); return; } else memcpy(acm_recv_buffer, acm_recv_buffer+start, _amt-start); } acm_unprocessed = _amt-start; usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer+acm_unprocessed, acm_usb_mps); task_stop(); }