int Test_HostPC_to_SDRAM() { int FilesizeH; clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); /* FilesizeH = hostpc_tx_size(matrix_UB); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); */ xillybus_close(); return 0; }
int Test_throughput_power() { int FilesizeH; //DWORD dwStartTime; //DWORD dwElapsed; clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); //dwStartTime = GetTickCount(); hostpc_tx_file(FilesizeH); //dwElapsed = GetTickCount() - dwStartTime; //printf("It took %d.%3d seconds to complete\n", dwElapsed/1000, dwElapsed - dwElapsed/1000); send_flag(ADDR00, FIN); wait_flag(ADDR01, NCN); clear_flag(); printf("\nFinish!"); clear_flag(); xillybus_close(); return 0; }
int HostPC_to_HwAcc_to_SDRAM_1_file() { int FilesizeH; clear_flag(); wait_flag(ADDR01, REQ); printf("\nA"); send_flag(ADDR00, RDY); FilesizeH = hostpc_tx_size(matrix_UA); printf("\nFilesizeH: %d", FilesizeH); hostpc_tx_file(FilesizeH); printf("\nB"); /* FilesizeH = hostpc_tx_size(matrix_UA); hostpc_tx_file(FilesizeH); */ wait_flag(ADDR01, FIN); send_flag(ADDR00, ACK); wait_flag(ADDR01, NCN); printf("\nC"); clear_flag(); xillybus_close(); return 0; }
void create() { clear_flag(NEED_TO_SEE); clear_flag(NEED_TO_BE_ALIVE); clear_flag(NEED_TO_THINK); add_rules( ({ "", "LIV" }) );
static int mxt_proc_proximity_msg(struct plugin_ac *p,unsigned long pl_flag) { const struct mxt_config *dcfg = p->dcfg; struct device *dev = dcfg->dev; struct t72_observer *obs = p->obs; int ret; dev_info2(dev, "mxt t72 at mxt_proc_proximity_msg flag 0x%lx pl_flag 0x%lx\n",obs->flag,pl_flag); //proximity if (test_flag(IRAD_FLAG_PROXIMITY_DETECTED, &obs->flag)) { proximity_enable(true); ret = get_proximity_data(); if (ret != 0) { dev_info(dev, "mxt t72 proximity removed\n"); clear_flag(IRAD_FLAG_PROXIMITY_DETECTED, &obs->flag); p->set_and_clr_flag(p->dev, PL_STATUS_FLAG_PROXIMITY_REMOVED, 0); } proximity_enable(false); }else if (test_flag(/*T72_FLAG_CAL*/T72_FLAG_RESUME, &obs->flag)) {//only check when proximity not detected proximity_enable(true); ret = get_proximity_data(); if (ret == 0) { dev_info(dev, "mxt t72 proximity detected\n"); set_flag(IRAD_FLAG_PROXIMITY_DETECTED, &obs->flag); }else { dev_info(dev, "mxt t72 proximity not detected\n"); clear_flag(IRAD_FLAG_PROXIMITY_DETECTED, &obs->flag); } proximity_enable(false); } return 0; }
DWORD WINAPI hostpc_tx_file_mat_mult(LPVOID arg) { FilesizeUse = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeUse); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeUse); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); printf("\nMatrix A has been transferred."); FilesizeUse = hostpc_tx_size(matrix_UB); send_flag(ADDR02, FilesizeUse); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeUse); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); printf("\nMatrix B has been transferred."); return 0; }
/** * \brief 接收数据到缓冲区 * 如果是加密包需要解密到解密缓冲区 * \return 实际接收字节数 * 返回-1,表示接收错误 * 返回0,表示接收超时 * 返回整数,不加密包表示实际接收的字节数,加密包返回解密后实际可用的字节数 */ int zSocket::recvToBuf() { //Zebra::logger->trace("zSocket::recvToBuf"); int retcode = 0; if(need_enc()) { if (isset_flag(INCOMPLETE_READ)) { clear_flag(INCOMPLETE_READ); goto do_select_enc; } _rcv_queue.wr_reserve(MAX_DATABUFFERSIZE); retcode = TEMP_FAILURE_RETRY(::recv(sock, _rcv_queue.wr_buf(), _rcv_queue.wr_size(), MSG_NOSIGNAL)); if (retcode == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { do_select_enc: retcode = waitForRead(); if (1 == retcode) retcode = TEMP_FAILURE_RETRY(::recv(sock, _rcv_queue.wr_buf(), _rcv_queue.wr_size(), MSG_NOSIGNAL)); else return retcode; } if (retcode > 0) success_recv_and_dec(); } else { if (isset_flag(INCOMPLETE_READ)) { clear_flag(INCOMPLETE_READ); goto do_select; } _rcv_queue.wr_reserve(MAX_DATABUFFERSIZE); retcode = TEMP_FAILURE_RETRY(::recv(sock, _rcv_queue.wr_buf(), _rcv_queue.wr_size(), MSG_NOSIGNAL)); if (retcode == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { do_select: retcode = waitForRead(); if (1 == retcode) retcode = TEMP_FAILURE_RETRY(::recv(sock, _rcv_queue.wr_buf(), _rcv_queue.wr_size(), MSG_NOSIGNAL)); else return retcode; } if (retcode > 0) success_recv(); } if (0 == retcode) return -1;//EOF return retcode; }
int Test_HostPC_Loopback() { struct packet fiforead; struct packet fifowriteA; HANDLE Handle_Of_Thread_1 = 0; // variable to hold handle of Thread 1 HANDLE Handle_Of_Thread_2 = 0; // variable to hold handle of Thread 2 HANDLE Array_Of_Thread_Handles[2]; // Aray to store thread handles FilesizeA = hostpc_tx_sizeA(matrix_UA); // size to be received //printf("\nFilesizeA: %d\n", FilesizeA); clear_flag(); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); // Create thread 1: Read Handle_Of_Thread_1 = CreateThread(NULL, 0, hostpc_rx_fileA, &fiforead, 0, NULL); if (Handle_Of_Thread_1 == NULL) { errorprint("Failed to create thread 1\n", GetLastError()); exit(1); } //printf("\nThread 1 creation completed."); // Create thread 2: Write Matrix A Handle_Of_Thread_2 = CreateThread(NULL, 0, hostpc_tx_fileA, &fifowriteA, 0, NULL); if (Handle_Of_Thread_2 == NULL) { errorprint("Failed to create thread 2\n", GetLastError()); exit(1); } //printf("\nThread 2 creation completed."); // Store Thread handles in Array of Thread Handles as per the requirement of WaitForMultipleObjects() Array_Of_Thread_Handles[0] = Handle_Of_Thread_1; Array_Of_Thread_Handles[1] = Handle_Of_Thread_2; // Wait until all threads have terminated. WaitForMultipleObjects(2, Array_Of_Thread_Handles, TRUE, INFINITE); //WaitForSingleObject(Handle_Of_Thread_1, INFINITE); //WaitForSingleObject(Handle_Of_Thread_2, INFINITE); // Close all thread handles upon completion. CloseHandle(Handle_Of_Thread_1); CloseHandle(Handle_Of_Thread_2); //printf("\nAll threads are closed now."); send_flag(ADDR00, FIN); wait_flag(ADDR01, NCN); //printf("\nFinish!"); clear_flag(); xillybus_close(); return 0; }
//int Test_HostPC_decompress_to_SDRAM_1_file() int decompress(char matrix_UA, char output_UA) { clear_flag(); send_flag(ADDR00, REQD); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); xillybus_close(); //return 0; return output_UA; }
int Test_HostPC_to_SDRAM_to_HwAcc_to_HostPC() { int FilesizeH; struct packet fiforead; HANDLE Handle_Of_Thread_1 = 0; // variable to hold handle of Thread 1 clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); FilesizeH = hostpc_tx_size(matrix_UB); send_flag(ADDR02, FilesizeH); send_flag(ADDR00, REQ); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); wait_flag(ADDR01, REQ); FilesizeUse = hostpc_rx_size(); printf("\nHostPC will receive %d Bytes from FPGA.", FilesizeUse); send_flag(ADDR00, RDY); // Create thread 1: Read Handle_Of_Thread_1 = CreateThread(NULL, 0, hostpc_rx_file, &fiforead, 0, NULL); if (Handle_Of_Thread_1 == NULL) { errorprint("Failed to create thread 1\n", GetLastError()); exit(1); } printf("\nThread 1 creation completed."); WaitForSingleObject(Handle_Of_Thread_1, INFINITE); CloseHandle(Handle_Of_Thread_1); wait_flag(ADDR01, FIN); send_flag(ADDR00, ACK); wait_flag(ADDR01, NCN); clear_flag(); // All flag from HostPC must be cleared before exit xillybus_close(); return 0; }
/** * \brief 向套接口发送原始数据,没有打包的数据,一般发送数据的时候需要加入额外的包头 * \param pBuffer 待发送的原始数据 * \param nSize 待发送的原始数据大小 * \return 实际发送的字节数 * 返回-1,表示发送错误 * 返回0,表示发送超时 * 返回整数,表示实际发送的字节数 */ int CSocket::sendRawData(const void *pBuffer,const int nSize) { if (isset_flag(INCOMPLETE_WRITE)) { clear_flag(INCOMPLETE_WRITE); goto do_select; } if( nSize > 10000 ) { int iii = 0; } int retcode = Send(sock,(const char*)pBuffer,nSize,MSG_NOSIGNAL); if (retcode == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { do_select: retcode = waitForWrite(); if (1 == retcode) { mutex.lock(); retcode = Send(sock,(const char*)pBuffer,nSize,MSG_NOSIGNAL); mutex.unlock(); } else return retcode; } if (retcode > 0 && retcode < nSize) set_flag(INCOMPLETE_WRITE); return retcode; }
/** * \brief 向套接口发送原始数据,没有打包的数据,一般发送数据的时候需要加入额外的包头 * \param pBuffer 待发送的原始数据 * \param nSize 待发送的原始数据大小 * \return 实际发送的字节数 * 返回-1,表示发送错误 * 返回0,表示发送超时 * 返回整数,表示实际发送的字节数 */ int zSocket::sendRawData(const void *pBuffer, const int nSize) { int retcode = 0; //Zebra::logger->trace("zSocket::sendRawData"); if (isset_flag(INCOMPLETE_WRITE)) { clear_flag(INCOMPLETE_WRITE); goto do_select; } retcode = TEMP_FAILURE_RETRY(::send(sock, pBuffer, nSize, MSG_NOSIGNAL)); if (retcode == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { do_select: retcode = waitForWrite(); if (1 == retcode) retcode = TEMP_FAILURE_RETRY(::send(sock, pBuffer, nSize, MSG_NOSIGNAL)); else return retcode; } if (retcode > 0 && retcode < nSize) set_flag(INCOMPLETE_WRITE); return retcode; }
/* * Allocate a page and add it to freelist of given pool. */ static int grow_pool(struct xv_pool *pool, gfp_t flags) { struct page *page; struct block_header *block; page = alloc_page(flags); if (unlikely(!page)) return -ENOMEM; stat_inc(&pool->total_pages); spin_lock(&pool->lock); block = get_ptr_atomic(page, 0); block->size = PAGE_SIZE - XV_ALIGN; set_flag(block, BLOCK_FREE); clear_flag(block, PREV_FREE); set_blockprev(block, 0); insert_block(pool, page, 0, block); put_ptr_atomic(block); spin_unlock(&pool->lock); return 0; }
void SocketSet::poll( socket_ptr_list* readable_list_ptr, socket_ptr_list* writable_list_ptr, socket_ptr_list* exception_list_ptr ) { if( m_sockets.empty() ) return; if(readable_list_ptr) readable_list_ptr->clear(); if(writable_list_ptr) writable_list_ptr->clear(); if(exception_list_ptr) exception_list_ptr->clear(); int max_fd_plus1 = m_sockets.rbegin()->first + 1; clear_flag(); int n; if( timeout_.tv_sec < 0 ) n = ::select( max_fd_plus1, &m_fdSet_r, &m_fdSet_w, &m_fdSet_e, 0); else n = ::select( max_fd_plus1, &m_fdSet_r, &m_fdSet_w, &m_fdSet_e, &timeout_); if( n > 0 ){ for( socket_map::const_iterator iter = m_sockets.begin(); iter != m_sockets.end(); ++iter ){ if( readable_list_ptr && FD_ISSET( iter->first, &m_fdSet_r ) ) readable_list_ptr->push_back( iter->second ); if( writable_list_ptr && FD_ISSET( iter->first, &m_fdSet_w ) ) writable_list_ptr->push_back( iter->second ); if( exception_list_ptr && FD_ISSET( iter->first, &m_fdSet_e ) ) exception_list_ptr->push_back( iter->second ); } } else if( n < 0) throw socket_exception("select(2)", errno); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(udp_server_thread(struct pt *pt)) { PT_BEGIN(pt); uint16_t payloadlen; static uint8_t str[64]; while(1) { PT_WAIT_UNTIL(pt,check_flag(new_packet,udp_server_flag)); if((buf[IP_PROTO_P]==IP_PROTO_UDP_V) && (buf[UDP_DST_PORT_H_P]==(MYUDPPORT>>8)) && (buf[UDP_DST_PORT_L_P]==(MYUDPPORT&0xff))) { /* calculate the udp message length */ payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN; /* replace the newline with string terminator */ buf[UDP_DATA_P+payloadlen-1] = '\0'; /* add some explanatory header to it */ sprintf(str,"> udp got: %s\r\n",buf+UDP_DATA_P); /* send the same message with little modification to the sender */ make_udp_reply_from_request(buf,str,strlen(str),MYUDPPORT); } clear_flag(new_packet,udp_server_flag); } PT_END(pt); }
static int mxt_proc_noise_msg(struct plugin_ac *p,unsigned long pl_flag) { const struct mxt_config *dcfg = p->dcfg; struct device *dev = dcfg->dev; struct t72_observer *obs = p->obs; dev_info2(dev, "mxt t72 at mxt_proc_noise_msg flag 0x%lx pl_flag 0x%lx\n",obs->flag,pl_flag); //very noise if (test_flag(PL_STATUS_FLAG_CAL_END,&pl_flag)) { if (test_flag(T72_FLAG_VERY_NOISE,&obs->flag)) { dev_info(dev, "mxt t72 enter very noise state\n"); p->set_t9_t100_cfg(p->dev, T9_T100_THLD_VERY_NOISE, BIT_MASK(MXT_T9_MRGTHR)|BIT_MASK(MXT_T9_MRGHYST)); p->set_t55_adp_thld(p->dev, T55_DISABLE); //noise }else if (test_flag(T72_FLAG_NOISE,&obs->flag)) { dev_info(dev, "mxt t72 enter noise state\n"); p->set_t9_t100_cfg(p->dev, T9_T100_THLD_NOISE, BIT_MASK(MXT_T9_MRGTHR)|BIT_MASK(MXT_T9_MRGHYST)); p->set_t55_adp_thld(p->dev, T55_DISABLE); //stable }else{ dev_info(dev, "mxt t72 enter very stable state\n"); p->set_t9_t100_cfg(p->dev, T9_T100_NORMAL, BIT_MASK(MXT_T9_MRGTHR)|BIT_MASK(MXT_T9_MRGHYST)); p->set_t55_adp_thld(p->dev, T55_NORMAL); } } clear_flag(T72_FLAG_STATE_CHANGE, &obs->flag); p->set_and_clr_flag(p->dev, PL_STATUS_FLAG_NOISE_CHANGE, 0); return 0; }
void Fl_Window::fullscreen_off(int X,int Y,int W,int H) { #ifndef _WIN32 clear_flag(Fl_Window::FL_NOBORDER); if (shown()) i->sendxjunk(); #endif resize(X, Y, W, H); }
static void plugin_cal_t72_start(struct plugin_ac *p, bool resume) { struct t72_observer *obs = p->obs; clear_flag(T72_FLAG_WORKAROUND_HALT, &obs->flag); if (resume) set_flag(T72_FLAG_RESUME, &obs->flag); }
void read_all_flags(char *str, size_t *result, size_t *i, int *flag) { size_t len; len = ft_strlen(str); clear_flag(flag); *i < len ? pr_simple_symbol(str, result, i) : 0; *i < len ? find_all_flags(flag, str, i) : 0; *i < len ? procenttecken(flag, str, i, result) : 0; }
//int Test_HostPC_to_SDRAM_1_file() int compress(char matrix_UA, int FilesizeH, int threshold, char output_UA) { int FilesizeH; clear_flag(); FilesizeH = hostpc_tx_size(matrix_UA); send_flag(ADDR02, FilesizeH); send_flag(ADDR02, threshold); send_flag(ADDR00, REQC); wait_flag(ADDR01, RDY); hostpc_tx_file(FilesizeH); send_flag(ADDR00, FIN); wait_flag(ADDR01, ACK); clear_flag(); xillybus_close(); //return 0; return output_UA; }
static int mxt_proc_timer_msg(struct plugin_ac *p,unsigned long pl_flag) { const struct mxt_config *dcfg = p->dcfg; struct device *dev = dcfg->dev; struct t72_observer *obs = p->obs; dev_info2(dev, "mxt t72 at mxt_proc_timer_msg flag 0x%lx pl_flag 0x%lx\n",obs->flag,pl_flag); clear_flag(T72_FLAG_START_T61, &obs->flag); return 0; }
void pifilestream::vseek(const pos_type n) { if (fseek(static_cast<FILE *>(m_file), static_cast<long>(n), SEEK_SET) < 0) throw file_e("File seek failed: {}", m_filename); else m_pos = n; if (feof(static_cast<FILE *>(m_file))) set_flag(FLAG_EOF); else clear_flag(FLAG_EOF); if (ferror(static_cast<FILE *>(m_file))) throw file_e("Generic file operation failed: {}", m_filename); }
static int mxt_proc_hw_msg(struct plugin_ac *p,unsigned long pl_flag) { const struct mxt_config *dcfg = p->dcfg; struct device *dev = dcfg->dev; struct t72_observer *obs = p->obs; dev_info2(dev, "mxt t72 at mxt_proc_hw_msg flag 0x%lx pl_flag 0x%lx\n",obs->flag,pl_flag); clear_flag(T72_FLAG_MASK_LOW, &obs->flag); obs->time_next_st = jiffies + 1; return 0; }
void pifilestream::vseek(const pos_type n) { check_seekable(); if (fseek((FILE *) m_file, SEEK_SET, n) < 0) set_flag(FLAG_ERROR); else m_pos = n; if (feof((FILE *) m_file)) set_flag(FLAG_EOF); else clear_flag(FLAG_EOF); if (ferror((FILE *) m_file)) set_flag(FLAG_ERROR); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(www_server_thread(struct pt *pt)) { PT_BEGIN(pt); while(1) { PT_WAIT_UNTIL(pt,check_flag(new_packet,www_server_flag)); if(dat_p > 0) { /*----------------------------------------------------------------- / HTTP GET message /------------------------------------------------------------------ / Example of a starting part of an HTTP GET message is: / GET /index.html HTTP/1.1 /----------------------------------------------------------------*/ if(strncmp("GET ",(char *)&(buf[dat_p]),4)==0) { /* just one web page in the "root directory" of the web server */ if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0) { /* this is basic header */ dat_p=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n")); /* this is our _website_ */ dat_p=fill_tcp_data_p(buf,dat_p,PSTR("<h2>Hello World!</h2>\n")); dat_p=fill_tcp_data_p(buf,dat_p,PSTR("This is a test page.\n")); /* send the data */ www_server_reply(buf,dat_p); } else { /* we dont have any website in this location */ dat_p=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 404 Not Found\r\nContent-Type: text/html\r\n\r\n<h1>404 Not Found</h1>")); /* send the data */ www_server_reply(buf,dat_p); } } } clear_flag(new_packet,www_server_flag); } PT_END(pt); }
/** * \brief 接收数据到缓冲区 * 如果是加密包需要解密到解密缓冲区 * \return 实际接收字节数 * 返回-1,表示接收错误 * 返回0,表示接收超时 * 返回整数,不加密包表示实际接收的字节数,加密包返回解密后实际可用的字节数 */ int CSocket::recvToBuf() { //printf("CSocket::recvToBuf\n"); int retcode = 0; if (isset_flag(INCOMPLETE_READ)) { clear_flag(INCOMPLETE_READ); goto do_select; } _rcv_queue.wr_reserve(MAX_DATABUFFERSIZE); if( m_bUseIocp ) { retcode = WaitRecv( true, rd_msec / 1000 ); if( retcode <= 0 ) return retcode; } else { retcode = ::recv(sock,(char*)_rcv_queue.wr_buf(),_rcv_queue.wr_size(),MSG_NOSIGNAL); } if ( retcode == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && !m_bUseIocp ) { do_select: if( m_bUseIocp ) { retcode = WaitRecv( true, rd_msec / 1000 ); if( retcode <= 0 ) return retcode; } else { retcode = waitForRead(); if (1 == retcode) retcode = ::recv(sock,(char*)_rcv_queue.wr_buf(),_rcv_queue.wr_size(),MSG_NOSIGNAL); else return retcode; } } if (retcode > 0) success_recv(); if (0 == retcode) return -1;//EOF return retcode; }
int main(int argc, char **argv) { Prover_input input; int return_code; print_banner(argc, argv, PROVER_NAME, PROGRAM_VERSION, PROGRAM_DATE, FALSE); /***************** Initialize and read the input ***************************/ input = std_prover_init_and_input(argc, argv, FALSE, // don't clausify TRUE, // echo input to stdout KILL_UNKNOWN); // unknown flags/parms are fatal if (input->usable || input->demods) fatal_error(PROVER_NAME ": all input clauses must be in sos, assumptions, " "or goals list"); /***************** Search for a proof **************************************/ if (flag(input->options->auto_denials)) { clear_flag(input->options->auto_denials, TRUE); printf("\n%% clear(auto_denials), because it is incompatiable with " "FOF reduction.\n"); } /***************** Search for a proof **************************************/ return_code = foffer(input); /***************** Print result message and exit ***************************/ if (return_code == MAX_PROOFS_EXIT) { printf("\nTHEOREM PROVED\n"); if (!flag(input->options->quiet)) fprintf(stderr, "\nTHEOREM PROVED\n"); } else { printf("\nSEARCH FAILED\n"); if (!flag(input->options->quiet)) fprintf(stderr, "\nSEARCH FAILED\n"); } exit_with_message(stdout, return_code); exit(1); // to satisfy the compiler (won't be called) } // main
/*---------------------------------------------------------------------------*/ static PT_THREAD(coap_server_thread(struct pt *pt)) { PT_BEGIN(pt); uint16_t xt; uint16_t tmp; while(1) { PT_WAIT_UNTIL(pt,check_flag(new_packet,coap_server_flag)); if((buf[IP_PROTO_P]==IP_PROTO_UDP_V) && (buf[UDP_DST_PORT_H_P]==(COAPPORT>>8)) && (buf[UDP_DST_PORT_L_P]==(COAPPORT&0xff))) { /* UDP message length calculation */ xt = ((buf[UDP_LEN_H_P]<<8)+buf[UDP_LEN_L_P])-8; #if 1 if(coap_parse(&pkt,buf+UDP_DATA_P,xt) != 0) { dbg(PSTR("\r\n> Bad coap packet\r\n")); } else { coap_handle_req(&scratch_buf, &pkt, &rsppkt); xt = sizeof(response); coap_build(response, &xt, &rsppkt); make_udp_reply_from_request(buf,response,xt,COAPPORT); } #endif } clear_flag(new_packet,coap_server_flag); } PT_END(pt); }/*---------------------------------------------------------------------------*/
static BLOCK *read_block(FS *fs, int location, int parse) { size_t nr; BLOCK *block = find_free_slot(fs); //printf("R %d %p, %d\n", location, fs->f, fileno(fs->f)); if (fseek(fs->f, location * fs->block_size, SEEK_SET)) error("Error seeking for reading block %d", location); nr = fread(block->buffer, fs->block_size, 1, fs->f); if (nr < 1) { clear_flag(block, F_CACHED); if (location != 0) printf("Error reading block %d, nr = %d, errno was %d\n", location, nr, errno); return NULL; } block->location = location; set_flag(block, F_CACHED); block->type = B_DATA; block->pins = 0; if (parse) { if (!parse_block(fs, block)) { printf("Error parsing block %d\n", location); return NULL; } } if (is_watched(block->location)) { printf("READ "); print_block(fs, block); } add_block_to_hash(fs, block); return block; }
void flush_block(FS *fs, BLOCK *block) { if (block->flags & F_CACHED && block->flags & F_DIRTY) { size_t nw; //printf("Saving block %d\n", block->location); populate_block(fs, block); if (fseek(fs->f, block->location * fs->block_size, SEEK_SET)) error("Error seeking for writing block %d (written %d)", block->location, fs->blocks_written); //printf("W %d %p, %d\n", block->location, fs->f, fileno(fs->f)); if (is_watched(block->location)) { printf("WRITE "); print_block(fs, block); } nw = fwrite(block->buffer, fs->block_size, 1, fs->f); if (nw < 1) error("Error saving block!\n"); clear_flag(block, F_DIRTY); } }