/** uartRx_isr * Parameters: * @param pThisArg pointer to own object * * @return None */ void uartRx_isr(void *pThisArg) { //printf("RX finished\r\n"); // local pThis to avoid constant casting uartRx_t *pThis = (uartRx_t*) pThisArg; if ( *pDMA10_IRQ_STATUS & 0x1 ) { if (pThis->state == UARTRX_WAITING) { unsigned short packet_length = sramPending[2] + 1; if (0x7e == sramPending[0] && 0 < packet_length) { int i; for (i = 0; i < 3; i++) { pThis->pPending->s08_buff[i] = sramPending[i]; } pThis->state = UARTRX_COMPLETING; uartRx_dmaConfig(sramPending, packet_length); } else if (0x7e == sramPending[1]) { sramPending[0] = 0x7e; sramPending[1] = sramPending[2]; uartRx_dmaConfig(sramPending+2, 1); } else if (0x7e == sramPending[2]) { sramPending[0] = 0x7e; uartRx_dmaConfig(sramPending+1, 2); } else { uartRx_dmaConfig(sramPending, 3); } } else if (pThis->state == UARTRX_COMPLETING) { int i; for (i = 0; i < pThis->pPending->s08_buff[2] + 1; i++) { pThis->pPending->s08_buff[i+3] = sramPending[i]; } // chunk is now filled update the length pThis->pPending->bytesUsed = pThis->pPending->s08_buff[2] + 4; //pThis->pPending->size; /* Insert the chunk previously read by the DMA RX on the RX QUEUE and a data is inserted to queue */ if ( FAIL == queue_put(&pThis->queue, pThis->pPending) ) { // reuse the same buffer and overwrite last samples //uartRx_dmaConfig(pThis->pPending); uartRx_dmaConfig(sramPending, 3); //printf("[INT]: RX packet dropped\r\n"); } else { if ( PASS == bufferPool_acquire(pThis->pBuffP, &pThis->pPending ) ) { uartRx_dmaConfig(sramPending, 3); } else { //printf("Buffer pool empty!\r\n"); } } pThis->state = UARTRX_WAITING; } *pDMA10_IRQ_STATUS |= 0x0001; // clear the interrupt } }
void master_process() { MPI_Status status; queue work_queue = generate_initial_work_queue(); work_item work, current_work, current_longest; int * sequence_array, * work_array; int array_buffer_size, n_work_items; /* We don't want to terminate before all of the partitions of the * space are calculated, so we keep track of how many we are * waiting on as well. */ int n_outstanding = 0; int i, j; int index; long long int n_evaluated = 0; int current_longest_size = 0; do { /* Test for the existence of message coming from one of the * worker processes. */ MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); if (!(n_evaluated % 100000)) { printf("Evaluated: %lld\n", n_evaluated); printf("Queue size: %d\n", work_queue->size); if (current_longest_size) display_work_item(current_longest); } if (status.MPI_TAG == REQUEST_WORK) { /* If a request was received for more work, register that request. */ MPI_Recv(0, 0, MPI_INT, status.MPI_SOURCE, REQUEST_WORK, MPI_COMM_WORLD, &status); if (work_queue->size > 0) { queue_get(work_queue, (void **) &work); MPI_Send(convert_work_to_array(work), BUFFER_SIZE, MPI_INT, status.MPI_SOURCE, DO_WORK, MPI_COMM_WORLD); n_outstanding++; n_evaluated++; free(work); } else { MPI_Send(0, 0, MPI_INT, status.MPI_SOURCE, DELAY_WORK, MPI_COMM_WORLD); } } else if (status.MPI_TAG == DONE_WORK) { /* Determine the size of the array that must be allocated. */ MPI_Get_count(&status, MPI_INT, &array_buffer_size); sequence_array = (int *) malloc(sizeof(int) * array_buffer_size); MPI_Recv(sequence_array, array_buffer_size, MPI_INT, status.MPI_SOURCE, DONE_WORK, MPI_COMM_WORLD, &status); n_work_items = array_buffer_size / BUFFER_SIZE; index = 0; for (i = 0; i < n_work_items; i++) { work_array = malloc(sizeof(int) * BUFFER_SIZE); for (j = 0; j < BUFFER_SIZE; j++) { work_array[j] = sequence_array[index]; index++; } current_work = convert_array_to_work(work_array); if (current_work->size > current_longest_size) { current_longest_size = current_work->size; current_longest = current_work; } queue_put(work_queue, (void *) current_work); free(work_array); } free(sequence_array); /* A process submitted its results to the master process, so we have fewer * processes outstanding at this time. */ n_outstanding--; } else if (status.MPI_TAG == SEQUENCE_TERMINATED) { MPI_Recv(0, 0, MPI_INT, status.MPI_SOURCE, SEQUENCE_TERMINATED, MPI_COMM_WORLD, &status); n_outstanding--; } } while (work_queue->size > 0 || n_outstanding > 0); queue_close(work_queue); }
static void queue_send(hre_context_t context,hre_msg_t msg){ Debug("sending message %p",msg); queue_put(context,msg,msg->target); }
void *_handle_peer_interconnect(void *arg) { assert(arg != NULL); LOG("[%d] 收到 rpc 客户端连接\n", self_index); st_netfd_t client = (st_netfd_t)arg; arg = NULL; // 握手 // rpc客户端连入后,会主动发来客户端自己的 index // 长度为 1 字节 char buf[4096]; ssize_t len; // 先只读取 1 字节的客户端握手头,表示客户端自己的 index if ((len = st_read(client, buf, 1, ST_UTIME_NO_TIMEOUT)) < 0) { ERR("[%d] failed to handshake from client #%d: %s\n", self_index, *buf, strerror(errno)); goto close_fd_and_quit; } else if (len == 0) { goto close_fd_and_quit; } uint8_t client_index = (uint8_t)buf[0]; LOG("[%d] 来自 rpc 客户端 #%d 的握手已经成功建立\n", self_index, client_index); // 如果 client_index 等于自己的 self_index,则这个有问题 if (client_index == self_index) { ERR("[%d] rpc client promet the same index with mine.\n", self_index); goto close_fd_and_quit; } // 将客户端 fd 放入属于它 index 的 fd_list 内 // 在前面的 make link to peers 当中,已经把写去远程结点的 st_netfd_t 保存于 fd_list 之内了 // 所以不需要需要将远程连入的 st_netfd_t 保存在自己的 fd_list /*if (fd_list[client_index] != NULL) { ERR("[%d] This client #%d has connected before, replace it.\n", self_index, client_index); st_netfd_close(fd_list[client_index]); } fd_list[client_index] = client;*/ // 初始化用于读取流的包结构 struct rpc_package *package; package = (struct rpc_package*)calloc(1, sizeof(struct rpc_package)); // const size_t pkghead_len = sizeof(rpcpkg_len); size_t receive; size_t cursor; // 记录数据偏移到了 buf 的什么位置 // 循环服务处理 for (;;) { if ((len = st_read(client, buf, sizeof(buf), ST_UTIME_NO_TIMEOUT)) < 0) { ERR("[%d] failed when read from client #%d.\n", self_index, client_index); goto free_package_close_fd_and_quit; } else if (len == 0) { goto free_package_close_fd_and_quit; } else { if (len > sizeof(buf)) LOG("[%d] read %ld bytes into buffer with size: %lu bytes.\n", self_index, len, sizeof(buf)); // 流进来数据了 cursor = 0; while (cursor < len) { // 如果缓冲区内数据没有处理完 // 如果之前没切过包,或者前一包已经完成 if (package->total == package->received) { package->total = NTOH(*(rpcpkg_len *)(buf + cursor)); if (len - cursor - pkghead_len >= package->total) { package->received = package->total; } else { package->received = len - cursor - pkghead_len; } memcpy(&package->data, buf + cursor + pkghead_len, package->received); cursor += package->received + pkghead_len; } else { // 现在处理的是断开包 assert(package->received < package->total); receive = (len >= package->total - package->received) ? package->total - package->received : len; memcpy(&package->data + package->received, buf + cursor, receive); package->received += receive; cursor += receive; } // 如果刚刚处理过的包已经是完整包,则处决它 if (package->received == package->total) { struct rpc_package_head *head = protocol_decode(package); switch (head->type) { case UNKNOW: break; case REQUEST: LOG("[%d] receive an rpc request with method: %s and parameter: %s\n", self_index, head->body->request.method, head->body->request.parameter); queue_put(queue, head); break; case RESPONSE: LOG("[%d] response an rpc request with result: %s\n", self_index, head->body->response.result); // TODO: 对 response 对象的后续处理 protocol_package_free(head); head = NULL; break; } } } } } free_package_close_fd_and_quit: free(package); close_fd_and_quit: st_netfd_close(client); return 0; }
int syscall_que_put(int queid, void* msg) { if((unsigned long)msg < CFG_MEM_KERNELMAX) return ERRNO_NOTEXIST; return queue_put(queid, msg); }
/** * FUNZIONE player * *============================================================================*/ void *player(void *arg) { int num_giocatore = (int) arg; int num_puntato_dal_giocatore = 0; bet_t tipo_puntata; int status; int somma_puntata; puntata_t *mybet; // player_t player; // size_t nbytes; // ssize_t bytes_read; // FILE *log_file; // char *log_file_name = "player-log.txt"; #ifndef DEBUG /* Recupero le info dal client */ client_t *client = (client_t *) arg; player = malloc(sizeof (player_t)); /* leggo la porta di congratulazioni */ nbytes = sizeof (in_port_t); bytes_read = read(client->clientfd, &(player->congrat_port), nbytes); if (bytes_read < 0) { err_abort(errno, "Lettura Porta Congratulazioni"); } /* leggo i soldi */ nbytes = sizeof (int) bytes_read = read(client->clientfd, &(player->money), nbytes); if (bytes_read < 0) { err_abort(errno, "Lettura somma giocatore"); } /* leggo il nickname */ //TODO mettere un valore costante al posto di 50 bytes_read = read(client->clientfd, player->name, 50); if (bytes_read < 0) { err_abort(errno, "Lettura Nick Giocatore"); } printf("\n===== DATI GIOCATORE =====\n"); printf("Nickname: %s\n", player->name); printf("Soldi: %d\n", player->money); printf("Porta congratulazioni: %d\n", player->congrat_port); //TODO inserire le info nella lista dei giocatori #endif status = pthread_mutex_lock(&puntate_mutex); if (status != 0) { err_abort(status, "Lock sul mutex nel player"); } while (1) { /* in realtà la condizione (estratto < 0) va intesa come * (puntate_aperte == 1) */ while (estratto < 0) { printf("GIOCATORE %d CONDIZIONE FALSA\n", num_giocatore); status = pthread_cond_wait(&puntate_cond, &puntate_mutex); if (status != 0) { err_abort(status, "Wait nel player"); } } //here player can bet /* * unlock mutex * read bet on socket * insert bet in list * lock mutex * */ status = pthread_mutex_unlock(&puntate_mutex); if (status != 0) { err_abort(status, "Unlock sul mutex nel player"); } //questi valori in realtà viene preso dal client num_puntato_dal_giocatore = rand() % 37; tipo_puntata = (bet_t)(rand() % 3); somma_puntata = (rand() % 100)+1; sleep(1); //TODO rimuovere questa sleep status = pthread_mutex_lock(&puntate_mutex); if (status != 0) { err_abort(status, "Lock sul mutex nel player"); } /* aggiunge un nodo alla lista delle puntate * TODO modificare e integrare con funzioni di Antonio */ mybet = (puntata_t *) malloc(sizeof (puntata_t)); if (!mybet) { err_abort(errno, "Errore malloc!"); } mybet->puntata = num_puntato_dal_giocatore; mybet->tipo = tipo_puntata; mybet->somma_puntata = somma_puntata; queue_put(&(lista_puntate.puntate), (node *) mybet); printf("GIOCATORE %d ha aggiunto %d di tipo %d puntando %d€\n", num_giocatore, mybet->puntata, mybet->tipo, mybet->somma_puntata); num_requests++; } pthread_exit(NULL); }
/* glock: UNUSED */ void write_enqueue(inodedata *id) { queue_put(jqueue,0,0,(uint8_t*)id,0); }
/* Change current_running to the next task */ void scheduler() { ASSERT(disable_count); if( ENABLE_PRIORITIES ) current_running->total_process_time += get_timer() - current_running->last_entry_time; /* check if any sleeping threads are * scheduled to wake up now */ try_wake(); /* * Since all threads may be sleeping * (or blocked), it is possible * that the ready_queue is empty. */ while( queue_empty( &ready_queue ) ) { leave_critical(); /* If interrupts are disabled, * then the timeofday will not increment, * and sleeping processes will never * awaken. Here, we spend some time * so that timer interrupts might occur. */ idle(); enter_critical(); try_wake(); } my_rand = rand_step( my_rand ); priority_t choice = my_rand % total_ready_priority; pcb_t *chosen_process = NULL; for(;;) { /* select the front of the ready list */ chosen_process = (pcb_t *) queue_get(&ready_queue); if( choice >= chosen_process->priority ) { choice -= chosen_process->priority; queue_put( &ready_queue, (node_t*) chosen_process ); } else { /* choose this one */ break; } } current_running = chosen_process; current_running->entry_count++; if( ENABLE_PRIORITIES ) { total_ready_priority -= current_running->priority; current_running->last_entry_time = get_timer(); } /* returning from this function will * cause a context switch */ }
void event_put(EventQueue* queue, Event* event) { queue_put((Queue*)queue, (QueueItem*)event); }
/** *FunBranch: The branch thread entry function *@parameter: branch num(0-7) **/ void FunBranch(void* parameter) { struct branch *bx; unsigned char *pbuf; int size; int branch_num; unsigned long tick = 0;//回绕是个问题, 用Jiffies是否更好 //TODO spi和数据处理的是否应该分开两个锁 //struct timespec slptm; // dev_spi = open(bx->device, O_RDON); // if (dev_spi < 0) { // DebugError("open usb%d failed!\n", branch_num); // pthread_exit(NULL); // } for (branch_num = 0; branch_num < BRANCH_NUM; branch_num++) { if (branch_num < SEMG_NUM) { SemgDataInit(semg_recv_buf[branch_num], branch_num); pbuf = semg_recv_buf[branch_num]; } else { SensorDataInit(sensor_recv_buf[branch_num - SEMG_NUM], branch_num); pbuf = sensor_recv_buf[branch_num - SEMG_NUM]; } bx = &branches[branch_num]; memcpy(bx->data_pool, pbuf, bx->size); // 格式化data_poll中的数据 } while (1) { // wait for period interrupt pthread_mutex_lock(&mutex_tick); while (capture_state != 0) // wait for start pthread_cond_wait(&cond_tick, &mutex_tick); capture_state = 1; // mark state as processing pthread_mutex_unlock(&mutex_tick); // SEMG process //相邻通道切换实测时间接近200 -500us 1ms以内 //同一通道读写函数产生实际时钟间隔约100us左右 // if (branch_num == 0 || branch_num == 7) // DebugInfo("branch%d thread is running!%ld\n", branch_num, tick++); for (branch_num = 0; branch_num < BRANCH_NUM; branch_num++) { bx = &branches[branch_num]; if (bx->is_connected == FALSE) continue; if (branch_num < SEMG_NUM) pbuf = semg_recv_buf[branch_num]; else pbuf = sensor_recv_buf[branch_num - SEMG_NUM]; #ifndef MONI_DATA size = read(bx->devfd, pbuf, bx->size); if(size != bx->size) { // any unresolved error bx->data_pool[0] = 0x48;//spi you gui le DebugError("read semg%d failed(ErrCode %d): %s\n", branch_num, errno, strerror(errno)); bx->is_connected = FALSE; close(bx->devfd); bx->devfd = -1; continue; } // DebugInfo("read branch%d 3258 bytes\n", branch_num); queue_put(&semg_queue, bx->type, branch_num); #else int period = 100; pbuf = bx->data_pool; *pbuf = 0xb7; *(pbuf + 1) = branch_num; *(pbuf + 2) = (BRANCH_DATA_SIZE >> 8); *(pbuf + 3) = (unsigned char) BRANCH_DATA_SIZE; pbuf += 9; moni_data(pbuf, CHANNEL_NUM_OF_BRANCH , branch_num, &t, &period); #endif // send message to processer // 通过邮箱容量比如为2或3,来判断是否满确定处理是否来得及 } // 3 代表一帧读完了 queue_put(&semg_queue, 3, 0); // motion sensor process // pthread_mutex_lock(&mutex_tick); // attention: 有可能在处理完成前又发生中断了,表明处理来不及处理时,这时会被hanlder设成0:start if (capture_state == 1) // when proceesing capture_state = 2; // mark finish pthread_mutex_unlock(&mutex_tick); } }//FunBranch()
int main(void) { printf("-----------------------\n"); p_queue_t queue = NULL; int i; int *a = (int *)malloc(sizeof(int) * 10); for (i = 0; i < 10; i++) { a[i] = i; } for (i = 0; i < 10; i++) { printf("%4d", a[i]); } putchar('\n'); printf("-----------------------\n"); queue = queue_create(); if (NULL == queue) err_exit("create error"); queue_print(queue, show); printf("-----------------------\n"); if (queue_empty(queue)) printf("empty\n"); for (i = 0; i < 10; i++) { if (!queue_put(queue, &a[i])) err_exit("put error"); } if (!queue_empty(queue)) printf("full\n"); queue_print(queue, show); printf("\n%d\n", queue->size); printf("%d\n", *(int*)queue->head->data); printf("%d\n", *(int*)queue_gethead(queue)); int *c = (int *)malloc(sizeof(int)); *c = 4; if (queue_put(queue, c)) printf("%d\n", queue->size); queue_print(queue, show); if (queue_delete(queue)) printf("\n%d\n", queue->size); printf("\n%d\n", *(int*)queue->head->data); printf("%d\n", *(int*)queue_gethead(queue)); queue_print(queue, show); putchar('\n'); printf("****************************************************\n"); p_queue_t queue_test = NULL; queue_test = queue_create(); for (i = 0; i < 10; i++) { if (queue_insert_maxsize(queue_test, &a[i], compare) == false) err_exit("put error"); } queue_print(queue_test, show); putchar('\n'); printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"); // p_queue_t test = NULL; // test = queue_create(); // if (NULL == test) // err_exit("create error"); // for (i = 0; i < 10; i++) { if (queue_insert_minsize(queue_test, &a[i], compare) == false) err_exit("put error"); } queue_print(queue_test, show); printf("\n\n"); for (i = 0; i < 10; i++) { if (queue_insert_minsize(queue_test, &a[i], compare) == false) err_exit("put error"); } queue_print(queue_test, show); putchar('\n'); printf("############################################################\n"); int *p = (int *)malloc(sizeof(int)* 10); for (i = 0; i < 10; i++) { p[i] = i % 3; } for (i = 0; i < 10; i++) { printf("%4d", p[i]); } putchar('\n'); p_queue_t test = NULL; test = queue_create(); if (NULL == test) err_exit("create error"); for (i = 0; i < 10; i++) { if (queue_insert_minsize(test, p + i, compare) == false) err_exit("put error"); } queue_print(test, show); putchar('\n'); printf("%4d\n", test->size); printf("%4d\n",*((int *)test->head->data)); printf("%4d\n", *((int *)test->head->next->data)); queue_destroy(test); putchar('\n'); return 0; }
/* This function is executed in the interrupt context */ static void dma_rx_callback(void *arg, u32_t channel, int status) { struct device *dev = get_dev_from_rx_dma_channel(channel); const struct i2s_stm32_cfg *cfg = DEV_CFG(dev); struct i2s_stm32_data *const dev_data = DEV_DATA(dev); struct stream *stream = &dev_data->rx; void *mblk_tmp; int ret; if (status != 0) { ret = -EIO; stream->state = I2S_STATE_ERROR; goto rx_disable; } __ASSERT_NO_MSG(stream->mem_block != NULL); /* Stop reception if there was an error */ if (stream->state == I2S_STATE_ERROR) { goto rx_disable; } mblk_tmp = stream->mem_block; /* Prepare to receive the next data block */ ret = k_mem_slab_alloc(stream->cfg.mem_slab, &stream->mem_block, K_NO_WAIT); if (ret < 0) { stream->state = I2S_STATE_ERROR; goto rx_disable; } ret = reload_dma(dev_data->dev_dma, stream->dma_channel, &stream->dma_cfg, (void *)LL_SPI_DMA_GetRegAddr(cfg->i2s), stream->mem_block, stream->cfg.block_size); if (ret < 0) { LOG_DBG("Failed to start RX DMA transfer: %d", ret); goto rx_disable; } /* Assure cache coherency after DMA write operation */ DCACHE_INVALIDATE(mblk_tmp, stream->cfg.block_size); /* All block data received */ ret = queue_put(&stream->mem_block_queue, mblk_tmp, stream->cfg.block_size); if (ret < 0) { stream->state = I2S_STATE_ERROR; goto rx_disable; } k_sem_give(&stream->sem); /* Stop reception if we were requested */ if (stream->state == I2S_STATE_STOPPING) { stream->state = I2S_STATE_READY; goto rx_disable; } return; rx_disable: rx_stream_disable(stream, dev); }
void queue_send_message (T_QUEUE queue, T_QUEUE_MESSAGE message, OS_ERR_TYPE* err) { queue_put(queue, message); *err = E_OS_OK; }
void show_clock() { // setup // clear the screen //queue_put( &display_lcd_queue , CMD_MODE); //queue_put( &display_lcd_queue , LCD_CMD_CLEAR_SCREEN); // set the pointer queue_put( &display_lcd_queue , CMD_MODE); queue_put( &display_lcd_queue , LCD_CMD_RETURN_HOME); // write the text // hours queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_HOURS_HIGH)); queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_HOURS_LOW)); queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_COLON)); // minuts queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_MINUTES_HIGH)); queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_MINUTES_LOW)); queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_COLON)); // seconds queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_SECONDS_HIGH)); queue_put( &display_lcd_queue , DATA_MODE); queue_put( &display_lcd_queue , get_msg_state(SSM_SECONDS_LOW)); }
/*! * \brief * This function is the state machine for the Button functionality. * Can be called from Interrupt or from a thread in while() loop. * Detects keys and feeds them to Input Buffer. * Call _ib_get() to read them. * \param none * \retval none */ void btn_service (void) { static clock_t mark = 0; static clock_t rep_mark = 0; static btn_state_t state; static uint8_t rep_flag = 0; static keys_t key=0, pr_key=0, max_key=0, bounce_bf[2] = {0,0}; // 2 state de-bounce keys_t key_long; clock_t now = clock (); // 2 state De-bounce bounce_bf[0] = bounce_bf[1]; bounce_bf[1] = _get_buttons (); // Call the back-end to read the buttons if (bounce_bf[0] == bounce_bf[1]) key = bounce_bf[1]; else key = pr_key; /*! * \note * This state machine waits for key. filters it and put it to inbuf. * - For standard presses filters by finding the max value * - For long presses it uses the final (long pressed) value * * This number is the key returned to the user from Input Buffer ( _ib_get ()) * So any combinations to the keys produces a different key number * See also \see _get_buttons () */ switch (state) { case BTN_IDLE: if (key) { state = BTN_PRE; mark = rep_mark = now; } break; case BTN_PRE: // Button(s) is/are pressed /* * Wait until user has the same buttons pressed * and count the time to repetitive and long pressed. */ if (key != pr_key) mark = now; if (now - mark >= BTN.holdtime) { // Put Long keys state = BTN_LONG; key_long = key | BTN_LONG_PRE_MASK; queue_put (&btn_q, (void*)&key_long); } if (!key) { /* * Key released * \note Here we put the max_key NOT key */ queue_put (&btn_q, &max_key); max_key = 0; rep_flag = 0; state = BTN_IDLE; } break; case BTN_LONG: // Button(s) is/are long pressed if (now - mark >= (2*BTN.holdtime)) rep_flag = 1; if (!key) { // Long key released key_long = key | BTN_LONG_REL_MASK; queue_put (&btn_q, (void*)&key_long); max_key = 0; rep_flag = 0; state = BTN_IDLE; } break; } // Filter out any user attempts and hold only the final decision if (key > max_key) max_key = key; // Repetitive capability if (rep_flag && BTN.repetitive && (now - rep_mark >= BTN.reptime)) { queue_put (&btn_q, &key); rep_mark = now; } pr_key = key; }
void *dmb_read_thread(void *arg) { #if !defined(RTV_TDMB_MULTI_SUB_CHANNEL_ENABLE) MTV_TS_PKT_INFO *tsp; #else TDMB_CIF_TS_INFO *tsp; int len; #endif #if defined(RTV_IF_SPI) int dev = fd_dmb_dev; #elif defined(RTV_IF_MPEG2_SERIAL_TSIF) || defined(RTV_IF_SPI_SLAVE) || defined(RTV_IF_MPEG2_PARALLEL_TSIF) || defined(RTV_IF_QUALCOMM_TSIF) int dev = fd_tsif_dev; #endif printf("[dmb_read_thread] Entered\n"); for(;;) { if(dmb_thread_run == 0) { break; } #if !defined(RTV_TDMB_MULTI_SUB_CHANNEL_ENABLE) tsp = (MTV_TS_PKT_INFO *)queue_get(&tsp_pool_cb); #else tsp = (TDMB_CIF_TS_INFO *)queue_get(&tsp_pool_cb); #endif if(tsp == NULL) { printf("[dmb_read_thread] tsp_pool_cb full!!!\n"); continue; } // Read a TSP into a free buffer. #if !defined(RTV_TDMB_MULTI_SUB_CHANNEL_ENABLE) tsp->len = read(dev, tsp->msc_buf, MAX_READ_TSP_SIZE); if(tsp->len > 0) #else len = read(dev, tsp, sizeof(TDMB_CIF_TS_INFO)); if(len > 0) #endif { /* Enqueue a TSP to data queue. */ queue_put(&tsp_queue_cb, (unsigned int)tsp); /* Send the data-event to consumer. */ mrevent_trigger(&ts_read_event); } else { //printf("[dmb_read_thread] read() fail: %d, dmb_thread_run:%d\n", ret, dmb_thread_run); queue_put(&tsp_pool_cb, (unsigned int)tsp); } usleep(5 * 1000); } printf("[dmb_read_thread] Exit...\n"); pthread_exit((void *)NULL); }
static inline void isr(struct port *p) { int cause, len; unsigned char ch; disable(); /* Loop until all interrupts handled. */ while (1) { /* Only use lower 3 bits. */ cause = inportb(p->baseaddr + IIR) & 0x07; if (cause & 0x01) break; switch (cause) { /* "OE, PE, FE or BI of the LSR set. * Serviced by reading the LSR." */ case 0x06: inportb(p->baseaddr + LSR); break; /* "Receiver DR or trigger level reached. * Serviced by reading RBR until under level" */ case 0x04: ch = inportb(p->baseaddr + RBR); if (!queue_full(p->recv)) queue_put(p->recv, ch); break; /* "THRE. Serviced by reading IIR (if source of int only!) * or writing to THR." */ case 0x02: /* If FIFO is enabled, we can blast up to 16 * bytes into THR at once. */ len = (p->fifo_enabled) ? 16 : 1; while (!queue_empty(p->send) && (len--)) { queue_get(p->send, ch); outportb(p->baseaddr + THR, ch); } if (queue_empty(p->send)) disable_thre_int(p->baseaddr); break; /* "One of the delta flags in the MSR set. * Serviced by reading MSR." */ case 0x00: inportb(p->baseaddr + MSR); break; default: } } /* End of interrupt. */ outportb(0x20, 0x20); if (p->irq > 7) outportb(0xa0, 0x20); }