void mpipe_rxndef(ot_u8* data, ot_bool blocking, mpipe_priority data_priority) { #if (MPIPE_USE_ACKS) if (data_priority == MPIPE_Ack) { mpipe.priority = data_priority; goto mpipe_rxndef_SETUP; } #endif if (blocking) { mpipe_wait(); } if (mpipe.state == MPIPE_Idle) { //mpipe.state = MPIPE_Idle; mpipe_rxndef_SETUP: MPIPE_DMAEN(OFF); # if (MPIPE_DMANUM == 0) DMA->CTL0 |= MPIPE_UART_RXTRIG; # elif (MPIPE_DMANUM == 1) DMA->CTL0 |= (MPIPE_UART_RXTRIG << 8); # elif (MPIPE_DMANUM == 2) DMA->CTL1 = MPIPE_UART_RXTRIG; # endif q_empty(mpipe_alp.inq); //mpipe_alp.inq->back -=10; MPIPE_DMA_RXCONFIG(mpipe_alp.inq->front, 6, ON); UART_OPEN(); UART_CLEAR_RXIFG(); } }
void mpipe_rxndef(ot_u8* data, ot_bool blocking, mpipe_priority data_priority) { #if (MPIPE_USE_ACKS) if (data_priority == MPIPE_Ack) { mpipe.priority = data_priority; goto mpipe_rxndef_SETUP; } #endif if (blocking) { mpipe_wait(); } if (mpipe.state == MPIPE_Idle) { //mpipe.state = MPIPE_Idle; mpipe_rxndef_SETUP: MPIPE_DMAEN(OFF); # if (MPIPE_DMANUM == 0) DMA->CTL0 |= MPIPE_UART_RXTRIG; # elif (MPIPE_DMANUM == 1) DMA->CTL0 |= (MPIPE_UART_RXTRIG << 8); # elif (MPIPE_DMANUM == 2) DMA->CTL1 = MPIPE_UART_RXTRIG; # endif DMA->CTL4 = ( DMA_Options_RMWDisable | \ DMA_Options_RoundRobinDisable | \ DMA_Options_ENMIEnable ); q_empty(mpipe_alp.inq); MPIPE_DMA_RXCONFIG(mpipe_alp.inq->front, 10, ON); UART_OPEN(); UART_CLEAR_RXIFG(); } }
void mpipe_txndef(ot_u8* data, ot_bool blocking, mpipe_priority data_priority) { /// Data TX will only occur if this function is called when the MPipe state is /// idle. The exception is when the function is called with ACK priority, in /// which case the state doesn't need to be Idle. Lastly, if you specify the /// blocking parameter, the function will not return until the packet is /// completely transmitted. ot_int data_length; #if (MPIPE_USE_ACKS) if (data_priority == MPIPE_Ack)) { mpipe.priority = data_priority; goto mpipe_txndef_SETUP; } #endif if (mpipe.state == MPIPE_Idle) { mpipe.state = MPIPE_Tx_Wait; mpipe_txndef_SETUP: MPIPE_DMAEN(OFF); # if (MPIPE_DMANUM == 0) DMA->CTL0 |= MPIPE_UART_TXTRIG; # elif (MPIPE_DMANUM == 1) DMA->CTL0 |= (MPIPE_UART_TXTRIG << 8); # elif (MPIPE_DMANUM == 2) DMA->CTL1 = MPIPE_UART_TXTRIG; # endif DMA->CTL4 = ( DMA_Options_RMWDisable | \ DMA_Options_RoundRobinDisable | \ DMA_Options_ENMIEnable ); // Sequence Number q_writeshort(mpipe_alp.outq, mpipe.sequence.ushort); // Data alignment data = mpipe_alp.outq->getcursor; data_length = mpipe_alp.outq->putcursor \ - mpipe_alp.outq->getcursor; // CRC q_writeshort(mpipe_alp.outq, platform_crc_block(data, data_length)); data_length += 2; mpipe_alp.outq->getcursor = mpipe_alp.outq->putcursor; MPIPE_DMA_TXCONFIG(data, data_length, ON); UART_OPEN(); MPIPE_DMA_TXTRIGGER(); if (blocking) { mpipe_wait(); } } }
void mpipe_txndef(ot_u8* data, ot_bool blocking, mpipe_priority data_priority) { /// Data TX will only occur if this function is called when the MPipe state is /// idle. The exception is when the function is called with ACK priority, in /// which case the state doesn't need to be Idle. Lastly, if you specify the /// blocking parameter, the function will not return until the packet is /// completely transmitted. ot_u16 scratch; #if (MPIPE_USE_ACKS) if (data_priority == MPIPE_Ack)) { mpipe.priority = data_priority; goto mpipe_txndef_SETUP; } #endif if (mpipe.state == MPIPE_Idle) { mpipe.state = MPIPE_Tx_Done; //MPIPE_Tx_Wait; mpipe_txndef_SETUP: MPIPE_DMAEN(OFF); # if (MPIPE_DMANUM == 0) DMA->CTL0 |= MPIPE_UART_TXTRIG; # elif (MPIPE_DMANUM == 1) DMA->CTL0 |= (MPIPE_UART_TXTRIG << 8); # elif (MPIPE_DMANUM == 2) DMA->CTL1 = MPIPE_UART_TXTRIG; # endif q_writeshort(mpipe_alp.outq, mpipe.sequence.ushort); // Sequence Number scratch = mpipe_alp.outq->putcursor - mpipe_alp.outq->getcursor; //data length scratch = platform_crc_block(mpipe_alp.outq->getcursor, scratch); //CRC value q_writeshort(mpipe_alp.outq, scratch); //Put CRC scratch = mpipe_alp.outq->putcursor \ - mpipe_alp.outq->getcursor; //data length w/ CRC data = mpipe_alp.outq->getcursor; //data start mpipe_alp.outq->getcursor = mpipe_alp.outq->putcursor; //move queue past packet // DMA setup MPIPE_DMA_TXCONFIG(data, scratch, ON); UART_OPEN(); MPIPE_DMA_TXTRIGGER(); if (blocking) { mpipe_wait(); } } }
/*主函数体*/ int main(int argc, char **argv) { int fd; //文件描述符 int err; //返回调用函数的状态 int len; int i; char rcv_buf[200]; char send_buf[30]="**This's a GPS Locator!**\n"; int listen_fd,accept_fd; struct sockaddr_in client_addr; int n; // int nbytes; if(argc != 3){ printf("Usage: %s /dev/ttyS* s-Send/r-Receive\n",argv[0]); return FALSE; } fd = UART_OPEN(fd,argv[1]); //打开串口,返回文件描述符 do{ err = UART_DEFAULT(fd); }while(FALSE == err || FALSE == fd); printf("Port is READY!\n"); if((listen_fd=socket(AF_INET,SOCK_STREAM,0))<0) //创建socket { printf("Socket Error:%s\n\a",strerror(errno)); return FALSE; } bzero(&client_addr,sizeof(struct sockaddr_in)); client_addr.sin_family=AF_INET; client_addr.sin_port=htons(MY_PORT); client_addr.sin_addr.s_addr=htonl(INADDR_ANY); n=1; setsockopt(listen_fd,SOL_SOCKET,SO_REUSEADDR,&n,sizeof(int)); //如果服务器终止后,服务器可以第二次快速启动而不用等待一段时间 if(bind(listen_fd,(struct sockaddr *)&client_addr,sizeof(client_addr))<0) //Bind { printf("Bind Error:%s\n\a",strerror(errno)); return FALSE; } listen(listen_fd,MAX_CONN_NUM); if(0 == strcmp(argv[2],"s")) { for(i = 0;i < 50;i++) { len = UART_SEND(fd,send_buf,30); if(len > 0) printf("Count.%d :Send data successful!\n",i); else printf("Count.%d :Send data failed!\n",i); sleep(1); } } else if(0 == strcmp(argv[2],"r")) { while (1) //循环读取数据 { accept_fd=accept(listen_fd,NULL,NULL); if((accept_fd<0)&&(errno==EINTR)) continue; else if(accept_fd<0) { printf("Accept Error:%s\n\a",strerror(errno)); continue; } if((n=fork())==0) { /* 子进程处理客户端的连接 */ unsigned int i; for(i=0;i<200;i++){ len = UART_RECV(fd, rcv_buf,MAX_REC_BUFF); if(len > 0) write(accept_fd,rcv_buf,len); else printf("(Time limit)No data now!\n"); } close(accept_fd); exit(0); } else if(n<0) printf("Fork Error:%s\n\a",strerror(errno)); } } else { fprintf(stderr,"Unsupported char:'s' or 'r'\n"); return (FALSE); } UART_CLOSE(fd); close(listen_fd); return 0; }