rt_err_t rt_eth_tx(rt_device_t device, struct pbuf *p) { /* lock eth device */ rt_sem_take(&sem_lock, RT_WAITING_FOREVER); DEBUG_MES("in %s\n", __FUNCTION__); s32 status; u32 pbuf; u64 dma_addr; u32 offload_needed = 0; u32 index; DmaDesc *dpr; struct rt_eth_dev *dev = (struct rt_eth_dev *) device; struct synopGMACNetworkAdapter *adapter; synopGMACdevice *gmacdev; adapter = (struct synopGMACNetworkAdapter *) dev->priv; if (adapter == NULL) return -1; gmacdev = (synopGMACdevice *) adapter->synopGMACdev; if (gmacdev == NULL) return -1; if (!synopGMAC_is_desc_owned_by_dma(gmacdev->TxNextDesc)) { pbuf = (u32)plat_alloc_memory(p->tot_len); //pbuf = (u32)pbuf_alloc(PBUF_LINK, p->len, PBUF_RAM); if (pbuf == 0) { rt_kprintf("===error in alloc bf1\n"); return -1; } DEBUG_MES("p->len = %d\n", p->len); pbuf_copy_partial(p, (void *)pbuf, p->tot_len, 0); dma_addr = plat_dma_map_single(gmacdev, (void *)pbuf, p->tot_len); status = synopGMAC_set_tx_qptr(gmacdev, dma_addr, p->tot_len, pbuf, 0, 0, 0, offload_needed, &index, dpr); if (status < 0) { rt_kprintf("%s No More Free Tx Descriptors\n", __FUNCTION__); plat_free_memory((void *)pbuf); return -16; } } synopGMAC_resume_dma_tx(gmacdev); s32 desc_index; u32 data1, data2; u32 dma_addr1, dma_addr2; u32 length1, length2; #ifdef ENH_DESC_8W u32 ext_status; u16 time_stamp_higher; u32 time_stamp_high; u32 time_stamp_low; #endif do { #ifdef ENH_DESC_8W desc_index = synopGMAC_get_tx_qptr(gmacdev, &status, &dma_addr1, &length1, &data1, &dma_addr2, &length2, &data2, &ext_status, &time_stamp_high, &time_stamp_low); synopGMAC_TS_read_timestamp_higher_val(gmacdev, &time_stamp_higher); #else desc_index = synopGMAC_get_tx_qptr(gmacdev, &status, &dma_addr1, &length1, &data1, &dma_addr2, &length2, &data2); #endif if (desc_index >= 0 && data1 != 0) { #ifdef IPC_OFFLOAD if (synopGMAC_is_tx_ipv4header_checksum_error(gmacdev, status)) { rt_kprintf("Harware Failed to Insert IPV4 Header Checksum\n"); } if (synopGMAC_is_tx_payload_checksum_error(gmacdev, status)) { rt_kprintf("Harware Failed to Insert Payload Checksum\n"); } #endif plat_free_memory((void *)(data1)); //sw: data1 = buffer1 if (synopGMAC_is_desc_valid(status)) { adapter->synopGMACNetStats.tx_bytes += length1; adapter->synopGMACNetStats.tx_packets++; } else { adapter->synopGMACNetStats.tx_errors++; adapter->synopGMACNetStats.tx_aborted_errors += synopGMAC_is_tx_aborted(status); adapter->synopGMACNetStats.tx_carrier_errors += synopGMAC_is_tx_carrier_error(status); } } adapter->synopGMACNetStats.collisions += synopGMAC_get_tx_collision_count(status); } while (desc_index >= 0); /* unlock eth device */ rt_sem_release(&sem_lock); // rt_kprintf("output %d bytes\n", p->len); u32 test_data; test_data = synopGMACReadReg(gmacdev->DmaBase, DmaStatus); return RT_EOK; }
struct pbuf *rt_eth_rx(rt_device_t device) { DEBUG_MES("%s : \n", __FUNCTION__); struct rt_eth_dev *dev = ð_dev; struct synopGMACNetworkAdapter *adapter; synopGMACdevice *gmacdev; // struct PmonInet * pinetdev; s32 desc_index; int i; char *ptr; u32 bf1; u32 data1; u32 data2; u32 len; u32 status; u32 dma_addr1; u32 dma_addr2; struct pbuf *pbuf = RT_NULL; rt_sem_take(&sem_lock, RT_WAITING_FOREVER); adapter = (struct synopGMACNetworkAdapter *) dev->priv; if (adapter == NULL) { rt_kprintf("%S : Unknown Device !!\n", __FUNCTION__); return NULL; } gmacdev = (synopGMACdevice *) adapter->synopGMACdev; if (gmacdev == NULL) { rt_kprintf("%s : GMAC device structure is missing\n", __FUNCTION__); return NULL; } /*Handle the Receive Descriptors*/ do { desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2); if (desc_index >= 0 && data1 != 0) { DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status); if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK) { pbuf = pbuf_alloc(PBUF_LINK, MAX_ETHERNET_PAYLOAD, PBUF_RAM); if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n"); dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE); len = synopGMAC_get_rx_desc_frame_length(status); //Not interested in Ethernet CRC bytes rt_memcpy(pbuf->payload, (char *)data1, len); DEBUG_MES("==get pkg len: %d\n", len); } else { rt_kprintf("s: %08x\n", status); adapter->synopGMACNetStats.rx_errors++; adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status); adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status); adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status); adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status); } desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0); if (desc_index < 0) { #if SYNOP_RX_DEBUG rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1); #endif plat_free_memory((void *)data1); } } }while(desc_index >= 0); rt_sem_release(&sem_lock); DEBUG_MES("%s : before return \n", __FUNCTION__); return pbuf; }
void config_comm(int fd, int speed_baud_rate, char parity, int data_bits, int stop_bits) { int valid_baud_rate = 0; struct termios new_tc; memset(&new_tc, 0x00, sizeof(struct termios)); valid_baud_rate = _check_baud_rate(speed_baud_rate); new_tc.c_cflag |= (CLOCAL | CREAD);//Enable in default. /* *Set baud rate. e.g B115200 is 115200 bauds. */ cfsetispeed(&new_tc, valid_baud_rate);//input speed cfsetospeed(&new_tc, valid_baud_rate);//output speed /* *Set parity. */ switch(parity) { case 'n': case 'N': new_tc.c_cflag &= ~PARENB; //Disable parity. break; case 'o': case 'O': new_tc.c_cflag |= PARENB; //Enable parity. new_tc.c_cflag |= PARODD; //Odd parity. break; case 'e': case 'E': new_tc.c_cflag |= PARENB; //Enable parity. new_tc.c_cflag &= ~PARODD; //even parity. break; } /* *Set data bits. */ new_tc.c_cflag &= ~CSIZE; switch(data_bits) { case 5: break; case 6: break; case 7: new_tc.c_cflag |= CS7; break; case 8: new_tc.c_cflag |= CS8; break; } /* *Set stop bits. */ (stop_bits == 2)?(new_tc.c_cflag |= CSTOPB):(new_tc.c_cflag &= ~ CSTOPB); tcflush(fd,TCIFLUSH); //new_tc.c_cc[VTIME] = 0; //new_tc.c_cc[VMIN] = 1; if( tcsetattr(fd, TCSANOW, &new_tc) != 0) { rt_kprintf("Set port config fail!\n"); } }
static rt_err_t eth_open(rt_device_t dev, rt_uint16_t oflag) { rt_kprintf("eth_open!!\n"); return RT_EOK; }
static void resource_checking(void) { rt_uint32_t index; char *msg = RT_NULL; startup_log("checking resource..."); index = 0; while (1) { DIR *dir; const char *path; path = _resource_paths[index]; if (path == RT_NULL) break; dir = opendir(path); if (dir == RT_NULL) { mkdir(path, 0); /* Handle /SD specially. We want the SD card to be mounted asap. */ if (strcmp(path, "/SD") == 0) { if (dfs_mount("sd0", "/SD", "elm", 0, 0) == 0) rt_kprintf("/SD mounted\n"); else rt_kprintf("/SD mount failed\n"); } } else closedir(dir); index++; } index = 0; while (1) { int fd; const struct resource_item *ritem; ritem = &_resource_items[index]; if (ritem->URL == RT_NULL) break; fd = open(ritem->local_fn, O_RDONLY, 0); if (fd < 0) { if (!msg) { msg = (char *)rt_malloc(128); rt_memset(msg, 0x0, 128); } rt_snprintf(msg, 128 - 1, "getting %s...", ritem->local_fn); startup_log(msg); if (copyfile(ritem->local_URL, ritem->local_fn) != RT_EOK) http_down(ritem->local_fn, ritem->URL); } else close(fd); index ++; } if (msg) rt_free(msg); startup_log("checking done!"); }
unsigned char Fetch_15minSpeed(unsigned char Num15) { unsigned char rec_num=0; unsigned char i=0,j=0,k=0; unsigned char Read_15minData[75]; unsigned int kk=0; //数据格式:15 1 xx xx xx xx xx sp 2 xx xx xx xx xx sp ... ...15 xx xx xx xx xx sp if(Temp_Gps_Gprs.Time[1]>=1) avgspd_Mint_Wr=Temp_Gps_Gprs.Time[1]-1; if(avgspd_Mint_Wr>=14) { //for(i=0;i<Num15;i++) //Speed_15min[1+j*7]=i+1; //avgspd_Mint_Wr=Temp_Gps_Gprs.Time[0]; //if(Temp_Gps_Gprs.Time[1]>=1) //avgspd_Mint_Wr=Temp_Gps_Gprs.Time[1]-1; //rt_kprintf("\r\n当前时间>=14min"); for(i=0;i<15;i++) { memcpy(&Speed_15min[2+i*7],Avrgspd_Mint.datetime,3);//BCD Speed_15min[2+i*7+3]=Temp_Gps_Gprs.Time[0]; Speed_15min[2+i*7+4]=avgspd_Mint_Wr-14+i;//不是BCD码 Speed_15min[2+i*7+5]=Avrgspd_Mint.avgrspd[avgspd_Mint_Wr-14+i]; } } else { rec_num=Api_DFdirectory_Query(spdpermin,0); //rt_kprintf("\r\n已有整小时记录条数",rec_num); //rt_kprintf("\r\n当前分钟数<15,已有 %d 条,需要从前一小时内读取 %d 条",avgspd_Mint_Wr,(15-avgspd_Mint_Wr)); if(rec_num) { Api_DFdirectory_Read(spdpermin,Read_15minData,70,0,0); // 从new-->old 读取 //rt_kprintf("\r\n存储最近一条整小时记录:"); //for(i=0;i<70;i++) //rt_kprintf(" %d",Read_15minData[i]); //rt_kprintf("\r\n"); //判断读出的前一条记录是不是当前小时的前一个小时 if((Read_15minData[2]==Avrgspd_Mint.datetime[2])&&(Avrgspd_Mint.datetime[3]==(Read_15minData[3]+1))) { for(i=0;i<(14-avgspd_Mint_Wr);i++)//avgspd_Mint_Wr { //rt_kprintf(" %d",Read_15minData[64-(14-avgspd_Mint_Wr-1)+i]);//不需要读取存储的数据 memcpy(&Speed_15min[2+i*7],Read_15minData,4);//yymmddhh Speed_15min[2+i*7+4]=60-(14-avgspd_Mint_Wr)+i;//mm Speed_15min[2+i*7+5]=Read_15minData[64-(13-avgspd_Mint_Wr)+i];//speed } k=i; } else//读出的前一条记录不是当前小时的前一个小时的数据 { for(i=0;i<(14-avgspd_Mint_Wr);i++)//avgspd_Mint_Wr { //rt_kprintf(" %d",Avrgspd_Mint.avgrspd[i]);//不需要读取存储的数据 memcpy(&Speed_15min[2+i*7+k*7],Avrgspd_Mint.datetime,3); kk=(Avrgspd_Mint.datetime[3]>>4)*10+(Avrgspd_Mint.datetime[3]&0x0f)-1; Speed_15min[2+i*7+k*7+3]=((kk/10)<<4)+(kk%10);// Speed_15min[2+i*7+k*7+4]=60-(14-avgspd_Mint_Wr)+i;; Speed_15min[2+i*7+k*7+5]=0; } k=i; } for(i=0;i<=avgspd_Mint_Wr;i++) { rt_kprintf(" %d",Avrgspd_Mint.avgrspd[i]);//不需要读取存储的数据 memcpy(&Speed_15min[2+i*7+k*7],Avrgspd_Mint.datetime,4); Speed_15min[2+i*7+k*7+4]=i; Speed_15min[2+i*7+k*7+5]=Avrgspd_Mint.avgrspd[i]; } } else //没有存过整小时的速度 { //rt_kprintf("\r\n 没有整小时的数据存入 "); for(i=0;i<(14-avgspd_Mint_Wr);i++)//avgspd_Mint_Wr { //rt_kprintf(" %d",Avrgspd_Mint.avgrspd[i]);//不需要读取存储的数据 memcpy(&Speed_15min[2+i*7+k*7],Avrgspd_Mint.datetime,3); kk=(Avrgspd_Mint.datetime[3]>>4)*10+(Avrgspd_Mint.datetime[3]&0x0f)-1; Speed_15min[2+i*7+k*7+3]=((kk/10)<<4)+(kk%10);// Speed_15min[2+i*7+k*7+4]=60-(14-avgspd_Mint_Wr)+i;; Speed_15min[2+i*7+k*7+5]=0; } k=i; //rt_kprintf("\r\n %d 条人为补充数据, 分钟数下标=%d",k,avgspd_Mint_Wr); for(i=0;i<=avgspd_Mint_Wr;i++) { //rt_kprintf(" %d",Avrgspd_Mint.avgrspd[i]);//不需要读取存储的数据 memcpy(&Speed_15min[2+i*7+k*7],Avrgspd_Mint.datetime,4); Speed_15min[2+i*7+k*7+4]=i; Speed_15min[2+i*7+k*7+5]=Avrgspd_Mint.avgrspd[i]; } } //rt_kprintf("\r\n 停车前15分钟车速读完"); }
u8 Process_RMC(u8* packet) { u8 CommaCount=0,iCount=0,k=0; u8 tmpinfo[15]; // 新版本的北斗模块经度更高了 //$GNRMC,085928.00,A,3920.020977,N,11744.385579,E,0.7,,020113,,,A*67 //$GNRMC,090954.00,A,3920.024800,N,11744.384457,E,0.3,,020113,,,A*65 // 11744.385579 u8 hour=0,min=0,sec=0,fDateModify=0; //---------------------------------------------- RMC_Counter++; if(RMC_Counter==20) { if(GNTXT_Counter==0) // 判断是否有TXT 报文 ,如果一直没有 BD_MODULE_3020C_check(); } //----------------- Initial Speed and Direction ----------------- GPRMC_Funs.Speed(tmpinfo, INIT, k); GPRMC_Funs.Direction(tmpinfo, INIT, k); //------------------------------------------------------------------- while (*packet!=0){ if(*packet==','){ CommaCount++; packet++; if(iCount==0) continue; switch(CommaCount){ case 2: //时间 //systemTickGPS_Set(); if ( iCount < 6 ) // 格式检查 { StatusReg_GPS_V(); return false; } if((tmpinfo[0]>=0x30)&&(tmpinfo[0]<=0x39)&&(tmpinfo[1]>=0x30)&&(tmpinfo[1]<=0x39)&&(tmpinfo[2]>=0x30)&&(tmpinfo[2]<=0x39)&&(tmpinfo[3]>=0x30)&&(tmpinfo[3]<=0x39)&&(tmpinfo[4]>=0x30)&&(tmpinfo[4]<=0x39)&&(tmpinfo[5]>=0x30)&&(tmpinfo[5]<=0x39)) ; else { StatusReg_GPS_V(); return false;} hour=(tmpinfo[0]-0x30)*10+(tmpinfo[1]-0x30)+8; min=(tmpinfo[2]-0x30)*10+(tmpinfo[3]-0x30); sec=(tmpinfo[4]-0x30)*10+(tmpinfo[5]-0x30); if(hour>23) { fDateModify=1; hour-=24; tmpinfo[0]=(hour/10)+'0'; tmpinfo[1]=(hour%10)+'0'; } //systemTickGPS_Clear(); //---------------------------------------------------- GPRMC_Funs.Time(tmpinfo, hour, min, sec); //----------------------------------------------------- break; case 3://数据有效性 GPRMC_Funs.Status(tmpinfo); break; case 4://纬度 if((tmpinfo[0]>=0x30)&&(tmpinfo[0]<=0x39)&&(tmpinfo[1]>=0x30)&&(tmpinfo[1]<=0x39)&&(tmpinfo[2]>=0x30)&&(tmpinfo[2]<=0x39)&&(tmpinfo[3]>=0x30)&&(tmpinfo[3]<=0x39)&&(tmpinfo[5]>=0x30)&&(tmpinfo[5]<=0x39)&&(tmpinfo[6]>=0x30)&&(tmpinfo[6]<=0x39)&&(tmpinfo[7]>=0x30)&&(tmpinfo[7]<=0x39)&&(tmpinfo[8]>=0x30)&&(tmpinfo[8]<=0x39)) ; else break; GPRMC_Funs.Latitude(tmpinfo); break; case 5://纬度半球 GPRMC_Funs.Latitude_NS(tmpinfo); break; case 6://经度 if((tmpinfo[0]>=0x30)&&(tmpinfo[0]<=0x39)&&(tmpinfo[1]>=0x30)&&(tmpinfo[1]<=0x39)&&(tmpinfo[2]>=0x30)&&(tmpinfo[2]<=0x39)&&(tmpinfo[3]>=0x30)&&(tmpinfo[3]<=0x39)&&(tmpinfo[4]>=0x30)&&(tmpinfo[4]<=0x39)&&(tmpinfo[6]>=0x30)&&(tmpinfo[6]<=0x39)&&(tmpinfo[7]>=0x30)&&(tmpinfo[7]<=0x39)&&(tmpinfo[8]>=0x30)&&(tmpinfo[8]<=0x39)&&(tmpinfo[9]>=0x30)&&(tmpinfo[9]<=0x39)) ; else break; GPRMC_Funs.Longitude(tmpinfo); break; case 7://经度半球 GPRMC_Funs.Longitude_WE(tmpinfo); break; case 8://速率 for ( k = 0; k < iCount; k++ ) { if ( tmpinfo[k] == '.' ) { break; } } if(k>=iCount) { rt_kprintf("\r\n K>=icount \r\n"); //break; k=0; } GPRMC_Funs.Speed(tmpinfo, PROCESS,k); break; case 9://方向 if ( iCount < 3 ) // 格式检查 { break; } for ( k = 0; k < iCount; k++ ) { if ( tmpinfo[k] == '.' ) { break; } } if(k>=iCount) break; GPRMC_Funs.Direction(tmpinfo,PROCESS,k); break; case 10://日期 if((tmpinfo[0]>=0x30)&&(tmpinfo[0]<=0x39)&&(tmpinfo[1]>=0x30)&&(tmpinfo[1]<=0x39)&&(tmpinfo[2]>=0x30)&&(tmpinfo[2]<=0x39)&&(tmpinfo[3]>=0x30)&&(tmpinfo[3]<=0x39)&&(tmpinfo[4]>=0x30)&&(tmpinfo[4]<=0x39)&&(tmpinfo[5]>=0x30)&&(tmpinfo[5]<=0x39)) ; else break; GPRMC_Funs.Date(tmpinfo,fDateModify,hour,min,sec); break; default: break; } iCount=0; } else { tmpinfo[iCount++]=*packet++; if(iCount<15) tmpinfo[iCount]=0; if(iCount>15) { // rt_kprintf("\r\n GPS GPRMC iCounte>12 : CommaCount=%d tmpinfo:%15s \r\n",CommaCount,tmpinfo); //return CommaCount; break; } } } //----------------------------------------------------- GPS_Delta_DurPro(); // 用GPS 定时触发 //----------------------------------------------------- return CommaCount; }
static rt_err_t lpc17xx_emac_init(rt_device_t dev) { /* Initialize the EMAC ethernet controller. */ rt_uint32_t regv, tout, id1, id2; /* Power Up the EMAC controller. */ LPC_SC->PCONP |= 0x40000000; /* Enable P1 Ethernet Pins. */ LPC_PINCON->PINSEL2 = 0x50150105; LPC_PINCON->PINSEL3 = (LPC_PINCON->PINSEL3 & ~0x0000000F) | 0x00000005; /* Reset all EMAC internal modules. */ LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | MAC1_SIM_RES | MAC1_SOFT_RES; LPC_EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES; /* A short delay after reset. */ for (tout = 100; tout; tout--); /* Initialize MAC control registers. */ LPC_EMAC->MAC1 = MAC1_PASS_ALL; LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN; LPC_EMAC->MAXF = ETH_MAX_FLEN; LPC_EMAC->CLRT = CLRT_DEF; LPC_EMAC->IPGR = IPGR_DEF; /* PCLK=18MHz, clock select=6, MDC=18/6=3MHz */ /* Enable Reduced MII interface. */ LPC_EMAC->MCFG = MCFG_CLK_DIV20 | MCFG_RES_MII; for (tout = 100; tout; tout--); LPC_EMAC->MCFG = MCFG_CLK_DIV20; /* Enable Reduced MII interface. */ LPC_EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM | CR_PASS_RX_FILT; /* Reset Reduced MII Logic. */ LPC_EMAC->SUPP = SUPP_RES_RMII | SUPP_SPEED; for (tout = 100; tout; tout--); LPC_EMAC->SUPP = SUPP_SPEED; /* Put the PHY in reset mode */ write_PHY (PHY_REG_BMCR, 0x8000); for (tout = 1000; tout; tout--); /* Wait for hardware reset to end. */ for (tout = 0; tout < 10000; tout++) { regv = read_PHY (PHY_REG_BMCR); if (!(regv & 0x8000)) { /* Reset complete */ break; } } if (tout >= 10000) { //return -RT_ERROR; /* reset failed */ rt_kprintf("\tPHY Read PHY_REG_BMSR,Reset timeout,tout: %d.\n",tout); } /* Check if this is a DP83848C PHY. */ id1 = read_PHY (PHY_REG_IDR1); id2 = read_PHY (PHY_REG_IDR2); if (((id1 << 16) | (id2 & 0xFFF0)) != DP83848C_ID) { // return -RT_ERROR; rt_kprintf("\tPHY Read PHY_REG_IDRx,PHY chip isn't DP83848C,Chip ID is %d.\n",((id1 << 16) | (id2 & 0xFFF0))); } else { /* Configure the PHY device */ /* Configure the PHY device */ switch (lpc17xx_emac_device.phy_mode) { case EMAC_PHY_AUTO: /* Use auto negotiation about the link speed. */ write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG); /* Wait to complete Auto_Negotiation. */ for (tout = 0; tout < 200000; tout++) { regv = read_PHY (PHY_REG_BMSR); if (regv & 0x0020) { /* Auto negotiation Complete. */ break; } } if(tout >= 200000) { rt_kprintf("\tPHY Read PHY_REG_BMSR,Auto nego timeout,tout: %d.\n",tout); } break; case EMAC_PHY_10MBIT: /* Connect at 10MBit */ write_PHY (PHY_REG_BMCR, PHY_FULLD_10M); break; case EMAC_PHY_100MBIT: /* Connect at 100MBit */ write_PHY (PHY_REG_BMCR, PHY_FULLD_100M); break; } } //if (tout >= 0x100000) return -RT_ERROR; // auto_neg failed /* Check the link status. */ for (tout = 0; tout < 100; tout++) { regv = read_PHY (PHY_REG_STS); if (regv & 0x0001) { /* Link is on. */ break; } } if (tout >= 100) { //return -RT_ERROR; rt_kprintf("\tPHY Read PHY_REG_BMSR,Link on timeout,tout: %d.\n",tout); } /* Configure Full/Half Duplex mode. */ if (regv & 0x0004) { /* Full duplex is enabled. */ LPC_EMAC->MAC2 |= MAC2_FULL_DUP; LPC_EMAC->Command |= CR_FULL_DUP; LPC_EMAC->IPGT = IPGT_FULL_DUP; } else { /* Half duplex mode. */ LPC_EMAC->IPGT = IPGT_HALF_DUP; } /* Configure 100MBit/10MBit mode. */ if (regv & 0x0002) { /* 10MBit mode. */ LPC_EMAC->SUPP = 0; } else { /* 100MBit mode. */ LPC_EMAC->SUPP = SUPP_SPEED; } /* Set the Ethernet MAC Address registers */ LPC_EMAC->SA0 = (lpc17xx_emac_device.dev_addr[1]<<8) | lpc17xx_emac_device.dev_addr[0]; LPC_EMAC->SA1 = (lpc17xx_emac_device.dev_addr[3]<<8) | lpc17xx_emac_device.dev_addr[2]; LPC_EMAC->SA2 = (lpc17xx_emac_device.dev_addr[5]<<8) | lpc17xx_emac_device.dev_addr[4]; /* Initialize Tx and Rx DMA Descriptors */ rx_descr_init (); tx_descr_init (); /* Receive Broadcast and Perfect Match Packets */ LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN; /* Reset all interrupts */ LPC_EMAC->IntClear = 0xFFFF; /* Enable EMAC interrupts. */ LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; /* Enable receive and transmit mode of MAC Ethernet core */ LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); LPC_EMAC->MAC1 |= MAC1_REC_EN; /* Enable the ENET Interrupt */ NVIC_EnableIRQ(ENET_IRQn); return RT_EOK; }
rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector) { rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); return RT_NULL; }
/*更新北斗线程,接收调试串口来的数据,透传到gps串口中*/ void thread_gps_upgrade_udisk( void* parameter ) { #define READ_PACKET_SIZE 1012 void ( *msg )( void *p ); int fd = -1, size; u32 count = 0; rt_uint8_t *pdata; /*数据*/ rt_uint8_t buf[32]; rt_uint8_t ch_h, ch_l; rt_err_t res; LENGTH_BUF uart_buf; rt_uint32_t file_datalen; /*升级文件长度*/ rt_uint8_t file_matchcode[2]; /*文件匹配码*/ rt_uint16_t packet_num; rt_uint16_t crc=0; msg = parameter; ptr_mem_packet = rt_malloc( READ_PACKET_SIZE+20 ); if( ptr_mem_packet == RT_NULL ) { msg( "E内存不足" ); return; } /*查找U盘*/ while( 1 ) { if( rt_device_find( "udisk" ) == RT_NULL ) /*没有找到*/ { count++; if( count <= 10 ) { msg( "I等待U盘插入" ); BD_upgrad_contr=1; }else { msg( "EU盘不存在" ); /*指示U盘不存在*/ BD_upgrad_contr=1; goto end_upgrade_usb_0; } rt_thread_delay( RT_TICK_PER_SECOND ); }else { msg( "I查找升级文件" ); break; } WatchDog_Feed(); } /*查找指定文件BEIDOU.IMG*/ fd = open( "/udisk/BEIDOU.IMG", O_RDONLY, 0 ); if( fd >= 0 ) { msg( "I分析文件" ); }else { msg( "E升级文件不存在" ); goto end_upgrade_usb_0; } size = read( fd, ptr_mem_packet, 16 ); pdata = ptr_mem_packet; if( ( *pdata != 0x54 ) || ( *( pdata + 1 ) != 0x44 ) ) { msg( "E文件头错误" ); goto end_upgrade_usb_1; } ch_h = ( *( pdata + 9 ) & 0xf0 ) >> 4; ch_l = ( *( pdata + 9 ) & 0xf ); sprintf( buf, "I版本:%d.%d.%d", ch_h, ch_l, *( pdata + 10 ) ); msg( buf ); /*升级数据长度*/ file_datalen =0; file_datalen = ( *( pdata + 11 ) ) << 24; file_datalen |= ( *( pdata + 12 ) ) << 16; file_datalen |= ( *( pdata + 13 ) ) << 8; file_datalen |= *( pdata + 14 ); rt_kprintf("file_datalen=%x",file_datalen); /*文件匹配码在尾部*/ count = 0; ch_h = 0; do{ res = read( fd, ptr_mem_packet,READ_PACKET_SIZE ); if(res) count = res; WatchDog_Feed(); }while(res>0); //rt_kprintf("res=%02x\r\n",res); //if(res==0) res=READ_PACKET_SIZE; if( ( ptr_mem_packet[count - 1] != 0x54 ) || ( ptr_mem_packet[count - 2] != 0x44 ) ) { msg( "E文件尾错误" ); goto end_upgrade_usb_1; } file_matchcode[0] = ptr_mem_packet[count - 6]; file_matchcode[1] = ptr_mem_packet[count - 5]; rt_kprintf("file datalen=%x matchcode=%02x%02x",file_datalen,file_matchcode[0],file_matchcode[1]); close( fd ); msg( "I配置端口" ); fd = open( "/udisk/BEIDOU.IMG", O_RDONLY, 0 ); if( fd < 0 ) { msg( "E升级文件不存在" ); goto end_upgrade_usb_0; } /*开始升级*/ /*停止gps线程*/ rt_thread_suspend( &thread_gps ); /*进入升级状态*/ memcpy( buf, "\x40\x30\xC0\x00\x03\x00\x01\x34\x21\x0D\x0A", 11 ); dev_gps_write( &dev_gps, 0, buf, 11 ); rt_thread_delay( RT_TICK_PER_SECOND ); /*版本查询*/ count = 0; dev_gps_write( &dev_gps, 0, "\x40\x10\xC0\x00\x10\x00\x01\xC2\x84\x0D\x0A", 11 ); while( 1 ) { rt_thread_delay(RT_TICK_PER_SECOND/10); res = rt_mq_recv( &mq_gps, (void*)&uart_buf, 124, 50 ); if( res == RT_EOK ) //收到一包数据 { count=0; // clear rt_kprintf("\r\n版本查询\r\n"); for( ch_h = 0; ch_h < uart_buf.wr; ch_h++ ) { rt_kprintf( "%02x ", uart_buf.body[ch_h] ); } rt_kprintf( "\r\n" ); if( ( uart_buf.wr == 15 ) && ( uart_buf.body[4] == 0x02 ) ) /*进入升级状态*/ { ch_h = ( uart_buf.body[7] & 0xf0 ) >> 4; ch_l = ( uart_buf.body[7] & 0xf ); sprintf( buf, "I版本:%d.%d.%d", ch_h, ch_l, uart_buf.body[8] ); msg( buf ); break; } }else /*超时*/
/* init finsh */ void finsh_system_init(void) { #ifdef FINSH_USING_SYMTAB #ifdef __CC_ARM /* ARM C Compiler */ extern int FSymTab$$Base; extern int FSymTab$$Limit; extern int VSymTab$$Base; extern int VSymTab$$Limit; finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit); finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit); #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */ finsh_system_function_init(__section_begin("FSymTab"), __section_end("FSymTab")); finsh_system_var_init(__section_begin("VSymTab"), __section_end("VSymTab")); #elif defined (__GNUC__) /* GNU GCC Compiler */ extern int __fsymtab_start; extern int __fsymtab_end; extern int __vsymtab_start; extern int __vsymtab_end; finsh_system_function_init(&__fsymtab_start, &__fsymtab_end); finsh_system_var_init(&__vsymtab_start, &__vsymtab_start); #endif #endif /* create or set shell structure */ #ifdef RT_USING_HEAP shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell)); if (shell == RT_NULL) { rt_kprintf("no memory for shell\n"); return; } memset(shell, 0, sizeof(struct finsh_shell)); rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); { rt_thread_t tid; tid = rt_thread_create("tshell", finsh_thread_entry, RT_NULL, FINSH_THREAD_STACK_SIZE, FINSH_THREAD_PRIORITY, 10); if (tid != RT_NULL) rt_thread_startup(tid); } #else { rt_err_t result; shell = &_shell; memset(shell, 0, sizeof(struct finsh_shell)); rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); result = rt_thread_init(&finsh_thread, "tshell", finsh_thread_entry, RT_NULL, &finsh_thread_stack[0], sizeof(finsh_thread_stack), FINSH_THREAD_PRIORITY, 10); if (result == RT_EOK) rt_thread_startup(&finsh_thread); } #endif }
void finsh_thread_entry(void* parameter) { char ch; /* normal is echo mode */ shell->echo_mode = 1; finsh_init(&shell->parser); rt_kprintf(FINSH_PROMPT); while (1) { /* wait receive */ if (rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER) != RT_EOK) continue; /* read one character from device */ while (rt_device_read(shell->device, 0, &ch, 1) == 1) { /* handle history key */ #ifdef FINSH_USING_HISTORY if (finsh_handle_history(shell, ch) == RT_TRUE) continue; #endif /* handle CR key */ if (ch == '\r') { char next; if (rt_device_read(shell->device, 0, &next, 1) == 1) ch = next; else ch = '\r'; } /* handle tab key */ else if (ch == '\t') { /* auto complete */ finsh_auto_complete(&shell->line[0]); /* re-calculate position */ shell->line_position = strlen(shell->line); continue; } /* handle backspace key */ else if (ch == 0x7f || ch == 0x08) { if (shell->line_position != 0) { rt_kprintf("%c %c", ch, ch); } if (shell->line_position <= 0) shell->line_position = 0; else shell->line_position --; shell->line[shell->line_position] = 0; continue; } /* handle end of line, break */ if (ch == '\r' || ch == '\n') { /* change to ';' and break */ shell->line[shell->line_position] = ';'; #ifdef FINSH_USING_HISTORY finsh_push_history(shell); #endif if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line); else rt_kprintf("\n"); rt_kprintf(FINSH_PROMPT); memset(shell->line, 0, sizeof(shell->line)); shell->line_position = 0; break; } /* it's a large line, discard it */ if (shell->line_position >= FINSH_CMD_SIZE) shell->line_position = 0; /* normal character */ shell->line[shell->line_position] = ch; ch = 0; if (shell->echo_mode) rt_kprintf("%c", shell->line[shell->line_position]); shell->line_position ++; shell->use_history = 0; /* it's a new command */ } /* end of device read */ } }
rt_bool_t finsh_handle_history(struct finsh_shell* shell, char ch) { /* * handle up and down key * up key : 0x1b 0x5b 0x41 * down key: 0x1b 0x5b 0x42 */ if (ch == 0x1b) { shell->stat = WAIT_SPEC_KEY; return RT_TRUE; } if ((shell->stat == WAIT_SPEC_KEY)) { if (ch == 0x5b) { shell->stat = WAIT_FUNC_KEY; return RT_TRUE; } shell->stat = WAIT_NORMAL; return RT_FALSE; } if (shell->stat == WAIT_FUNC_KEY) { shell->stat = WAIT_NORMAL; if (ch == 0x41) /* up key */ { /* prev history */ if (shell->current_history > 0)shell->current_history --; else { shell->current_history = 0; return RT_TRUE; } /* copy the history command */ memcpy(shell->line, &shell->cmd_history[shell->current_history][0], FINSH_CMD_SIZE); shell->line_position = strlen(shell->line); shell->use_history = 1; } else if (ch == 0x42) /* down key */ { /* next history */ if (shell->current_history < shell->history_count - 1) shell->current_history ++; else { /* set to the end of history */ if (shell->history_count != 0) { shell->current_history = shell->history_count - 1; } else return RT_TRUE; } memcpy(shell->line, &shell->cmd_history[shell->current_history][0], FINSH_CMD_SIZE); shell->line_position = strlen(shell->line); shell->use_history = 1; } if (shell->use_history) { rt_kprintf("\033[2K\r"); rt_kprintf("%s%s", FINSH_PROMPT, shell->line); return RT_TRUE;; } } return RT_FALSE; }
void eth_rx_irq(int irqno, void *param) { struct rt_eth_dev *dev = ð_dev; struct synopGMACNetworkAdapter *adapter = dev->priv; //DEBUG_MES("in irq!!\n"); #ifdef RT_USING_GMAC_INT_MODE int i ; for (i = 0; i < 7200; i++) ; #endif /*RT_USING_GMAC_INT_MODE*/ synopGMACdevice *gmacdev = (synopGMACdevice *)adapter->synopGMACdev; u32 interrupt, dma_status_reg; s32 status; u32 dma_addr; //rt_kprintf("irq i = %d\n", i++); dma_status_reg = synopGMACReadReg(gmacdev->DmaBase, DmaStatus); if (dma_status_reg == 0) { rt_kprintf("dma_status ==0 \n"); return; } //rt_kprintf("dma_status_reg is 0x%x\n", dma_status_reg); u32 gmacstatus; synopGMAC_disable_interrupt_all(gmacdev); gmacstatus = synopGMACReadReg(gmacdev->MacBase, GmacStatus); if (dma_status_reg & GmacPmtIntr) { rt_kprintf("%s:: Interrupt due to PMT module\n", __FUNCTION__); //synopGMAC_linux_powerup_mac(gmacdev); } if (dma_status_reg & GmacMmcIntr) { rt_kprintf("%s:: Interrupt due to MMC module\n", __FUNCTION__); DEBUG_MES("%s:: synopGMAC_rx_int_status = %08x\n", __FUNCTION__, synopGMAC_read_mmc_rx_int_status(gmacdev)); DEBUG_MES("%s:: synopGMAC_tx_int_status = %08x\n", __FUNCTION__, synopGMAC_read_mmc_tx_int_status(gmacdev)); } if (dma_status_reg & GmacLineIntfIntr) { rt_kprintf("%s:: Interrupt due to GMAC LINE module\n", __FUNCTION__); } interrupt = synopGMAC_get_interrupt_type(gmacdev); //rt_kprintf("%s:Interrupts to be handled: 0x%08x\n",__FUNCTION__,interrupt); if (interrupt & synopGMACDmaError) { u8 mac_addr0[6]; rt_kprintf("%s::Fatal Bus Error Inetrrupt Seen\n", __FUNCTION__); memcpy(mac_addr0, dev->dev_addr, 6); synopGMAC_disable_dma_tx(gmacdev); synopGMAC_disable_dma_rx(gmacdev); synopGMAC_take_desc_ownership_tx(gmacdev); synopGMAC_take_desc_ownership_rx(gmacdev); synopGMAC_init_tx_rx_desc_queue(gmacdev); synopGMAC_reset(gmacdev); synopGMAC_set_mac_addr(gmacdev, GmacAddr0High, GmacAddr0Low, mac_addr0); synopGMAC_dma_bus_mode_init(gmacdev, DmaFixedBurstEnable | DmaBurstLength8 | DmaDescriptorSkip2); synopGMAC_dma_control_init(gmacdev, DmaStoreAndForward); synopGMAC_init_rx_desc_base(gmacdev); synopGMAC_init_tx_desc_base(gmacdev); synopGMAC_mac_init(gmacdev); synopGMAC_enable_dma_rx(gmacdev); synopGMAC_enable_dma_tx(gmacdev); } if (interrupt & synopGMACDmaRxNormal) { //DEBUG_MES("%s:: Rx Normal \n", __FUNCTION__); //synop_handle_received_data(netdev); eth_device_ready(ð_dev.parent); } if (interrupt & synopGMACDmaRxAbnormal) { //rt_kprintf("%s::Abnormal Rx Interrupt Seen\n",__FUNCTION__); if (GMAC_Power_down == 0) { adapter->synopGMACNetStats.rx_over_errors++; synopGMACWriteReg(gmacdev->DmaBase, DmaStatus, 0x80); synopGMAC_resume_dma_rx(gmacdev); } } if (interrupt & synopGMACDmaRxStopped) { rt_kprintf("%s::Receiver stopped seeing Rx interrupts\n", __FUNCTION__); //Receiver gone in to stopped state } if (interrupt & synopGMACDmaTxNormal) { DEBUG_MES("%s::Finished Normal Transmission \n", __FUNCTION__); // synop_handle_transmit_over(netdev); } if (interrupt & synopGMACDmaTxAbnormal) { rt_kprintf("%s::Abnormal Tx Interrupt Seen\n", __FUNCTION__); } if (interrupt & synopGMACDmaTxStopped) { TR("%s::Transmitter stopped sending the packets\n", __FUNCTION__); if (GMAC_Power_down == 0) // If Mac is not in powerdown { synopGMAC_disable_dma_tx(gmacdev); synopGMAC_take_desc_ownership_tx(gmacdev); synopGMAC_enable_dma_tx(gmacdev); // netif_wake_queue(netdev); TR("%s::Transmission Resumed\n", __FUNCTION__); } } /* Enable the interrrupt before returning from ISR*/ synopGMAC_enable_interrupt(gmacdev, DmaIntEnable); return; }
//------------------ u8 Process_TXT(u8* packet) { // $GNTXT,01,01,01,ANTENNA SHORT*7D //$GNTXT,01,01,01,ANTENNA OK*2B //$GNTXT,01,01,01,ANTENNA OPEN*3B u8 CommaCount=0,iCount=0; u8 tmpinfo[12]; // float dop; //float Hight1=0,Hight2=0; GNTXT_Counter++; // 文本条数计数器 if(GNTXT_Counter==20) // 检查BD_Module { BD_MODULE_TXT_Check(); } while (*packet!=0){ if((*packet==',')||(*packet=='*')){ CommaCount++; packet++; if(iCount==0) continue; switch(CommaCount){ case 5: if(strncmp((char*)tmpinfo,"ANTENNA OPEN",12)==0)//开路检测 1:天线开路 { if(OutGPS_Flag==0) { if((Warn_Status[3]&0x20)==0) { rt_kprintf("\r\n 检测到 天线开路\r\n"); GpsStatus.Antenna_Flag=1; PositionSD_Enable(); Current_UDP_sd=1; } Warn_Status[3]|=0x20; Warn_Status[3]&=~0x40; } } if(strncmp((char*)tmpinfo,"ANTENNA SHORT",13)==0)//短路检测 0:天线短路 { Warn_Status[3]&=~0x20; Warn_Status[3]|=0x40; } else if(strncmp((char*)tmpinfo,"ANTENNA OK",10)==0) { GpsStatus.Antenna_Flag=0; if(Warn_Status[3]&0x20) { rt_kprintf("\r\n 检测到 天线恢复正常"); PositionSD_Enable(); Current_UDP_sd=1; } Warn_Status[3]&=~0x20; Warn_Status[3]&=~0x40; } break; default: break; } iCount=0; }else{ tmpinfo[iCount++]=*packet++; tmpinfo[iCount]=0; if(iCount>12) return CommaCount; } } return CommaCount; }
int rt_hw_eth_init(void) { u64 base_addr = Gmac_base; struct synopGMACNetworkAdapter *synopGMACadapter; static u8 mac_addr0[6] = DEFAULT_MAC_ADDRESS; int index; rt_sem_init(&sem_ack, "tx_ack", 1, RT_IPC_FLAG_FIFO); rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); for (index = 21; index <= 30; index++) { pin_set_purpose(index, PIN_PURPOSE_OTHER); pin_set_remap(index, PIN_REMAP_DEFAULT); } pin_set_purpose(35, PIN_PURPOSE_OTHER); pin_set_remap(35, PIN_REMAP_DEFAULT); *((volatile unsigned int *)0xbfd00424) &= ~(7 << 28); *((volatile unsigned int *)0xbfd00424) |= (1 << 30); //wl rmii memset(ð_dev, 0, sizeof(eth_dev)); synopGMACadapter = (struct synopGMACNetworkAdapter *)plat_alloc_memory(sizeof(struct synopGMACNetworkAdapter)); if (!synopGMACadapter) { rt_kprintf("Error in Memory Allocataion, Founction : %s \n", __FUNCTION__); } memset((char *)synopGMACadapter, 0, sizeof(struct synopGMACNetworkAdapter)); synopGMACadapter->synopGMACdev = NULL; synopGMACadapter->synopGMACdev = (synopGMACdevice *) plat_alloc_memory(sizeof(synopGMACdevice)); if (!synopGMACadapter->synopGMACdev) { rt_kprintf("Error in Memory Allocataion, Founction : %s \n", __FUNCTION__); } memset((char *)synopGMACadapter->synopGMACdev, 0, sizeof(synopGMACdevice)); /* * Attach the device to MAC struct This will configure all the required base addresses * such as Mac base, configuration base, phy base address(out of 32 possible phys) * */ synopGMAC_attach(synopGMACadapter->synopGMACdev, (regbase + MACBASE), regbase + DMABASE, DEFAULT_PHY_BASE, mac_addr0); init_phy(synopGMACadapter->synopGMACdev); synopGMAC_reset(synopGMACadapter->synopGMACdev); /* MII setup */ synopGMACadapter->mii.phy_id_mask = 0x1F; synopGMACadapter->mii.reg_num_mask = 0x1F; synopGMACadapter->mii.dev = synopGMACadapter; synopGMACadapter->mii.mdio_read = mdio_read; synopGMACadapter->mii.mdio_write = mdio_write; synopGMACadapter->mii.phy_id = synopGMACadapter->synopGMACdev->PhyBase; synopGMACadapter->mii.supports_gmii = mii_check_gmii_support(&synopGMACadapter->mii); eth_dev.iobase = base_addr; eth_dev.name = "e0"; eth_dev.priv = synopGMACadapter; eth_dev.dev_addr[0] = mac_addr0[0]; eth_dev.dev_addr[1] = mac_addr0[1]; eth_dev.dev_addr[2] = mac_addr0[2]; eth_dev.dev_addr[3] = mac_addr0[3]; eth_dev.dev_addr[4] = mac_addr0[4]; eth_dev.dev_addr[5] = mac_addr0[5]; eth_dev.parent.parent.type = RT_Device_Class_NetIf; eth_dev.parent.parent.init = eth_init; eth_dev.parent.parent.open = eth_open; eth_dev.parent.parent.close = eth_close; eth_dev.parent.parent.read = eth_read; eth_dev.parent.parent.write = eth_write; eth_dev.parent.parent.control = eth_control; eth_dev.parent.parent.user_data = RT_NULL; eth_dev.parent.eth_tx = rt_eth_tx; eth_dev.parent.eth_rx = rt_eth_rx; eth_device_init(&(eth_dev.parent), "e0"); eth_device_linkchange(ð_dev.parent, RT_TRUE); //linkup the e0 for lwip to check return 0; }
//------------------------------------------------------------------ void GPS_ANTENNA_status(void) // 天线开短路状态检测 { // 2013-4-20 更改PCB 用PD4 : GPS 天线开路 PB6 : GPS 天线短路 if(GPIO_ReadOutputDataBit(GPS_PWR_PORT, GPS_PWR_PIN )) // 在GPS 有电时有效 { if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4))//开路检测 1:天线开路 { if(OutGPS_Flag==0) { if((Warn_Status[3]&0x20)==0) rt_kprintf("\r\n 检测到 天线开路"); Warn_Status[3]|=0x20; Warn_Status[3]&=~0x40; GpsStatus.Antenna_Flag=1; Gps_Exception.GPS_circuit_short_couter=0; } } else if(!GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6))//短路检测 0:天线短路 { if(( Warn_Status[3]&0x40)==0) { Gps_Exception.GPS_short_keepTimer++; if( Gps_Exception.GPS_short_keepTimer>200) { Gps_Exception.GPS_short_keepTimer=0; // clear rt_kprintf("\r\n 检测到 天线短路"); rt_kprintf("\r\n 发现短路,立即断开GPS电源"); GPIO_ResetBits( GPS_PWR_PORT, GPS_PWR_PIN ); //------------------------------------------ Gps_Exception.GPS_circuit_short_couter++; if(Gps_Exception.GPS_circuit_short_couter>=4) { Gps_Exception.GPS_short_checkFlag=2; Gps_Exception.GPS_short_timer=0; // clear rt_kprintf("\r\n 短路检测大于3次 ,一直断开GPS 电源\r\n"); // 断开 GPS 电源后,得启动 本地定时 ,否则人家说丢包.NND /* */ } else { Gps_Exception.GPS_short_checkFlag=1; } //----------------------------------------------------- // set flag Warn_Status[3]&=~0x20; Warn_Status[3]|=0x40; //------------------------------------------ } } } else { if(Warn_Status[3]&0x20) rt_kprintf("\r\n 检测到 天线恢复正常"); Warn_Status[3]&=~0x20; Warn_Status[3]&=~0x40; GpsStatus.Antenna_Flag=0; Gps_Exception.GPS_circuit_short_couter=0; } } }
void CheckICInsert(void) { unsigned char write_flag=0; u8 result0=0,result1=0,result2=0,result3=0,result4=0,result5=0;//i=0; u8 FLagx=0;//,len=0; unsigned char reg_record[32]; u32 DriveCode32=0; //===================测试IC卡读写================================================== if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7)) { IC_Check_Count++; if(IC_Check_Count>=10) { IC_Check_Count=0; //带卡上电开8024的电 if(flag_8024off==1) { R_Flag|=b_CardEdge; Init8024Flag=2; flag_8024off=0; } //8024的off从低变高 if(Init8024Flag==1) { Init8024Flag=2; R_Flag|=b_CardEdge; //rt_kprintf("pc7 为 高,R_Flag=1\r\n"); } //检测到卡后初始化ic卡 if((R_Flag&b_CardEdge)&&(Init8024Flag==2)) { Init8024Flag=3; _CardCMDVCC_LOW; for(DelayCheckIc=0; DelayCheckIc<500; DelayCheckIc++) DELAY5us(); _CardSetPower_HIGH; _CardSetRST_LOW; for(DelayCheckIc=0; DelayCheckIc<15; DelayCheckIc++) { _CardSetCLK_LOW; DELAY5us(); DELAY5us(); DELAY5us(); _CardSetCLK_HIGH; DELAY5us(); DELAY5us(); DELAY5us(); _CardSetCLK_LOW; } R_Flag&=~b_CardEdge; write_flag=1; //rt_kprintf("只执行1次\r\n"); } } } else { IC_Check_Count=0; _CardSetRST_HIGH; _CardSetPower_LOW; _CardCMDVCC_HIGH; if(Init8024Flag==0) { Init8024Flag=1; //rt_kprintf("pc7 为 低\r\n"); } } if(write_flag==1) { write_flag=0; Rx_4442(241,13,reg_record); //管理员卡 if(strncmp((char *)reg_record,"administrator",13)==0) { rt_kprintf("\r\n管理员卡"); administrator_card=1; } else { memset(DriverCardNUM,0,sizeof(DriverCardNUM)); memset(DriverName,0,sizeof(DriverName)); //memset(JT808Conf_struct.Driver_Info,0,sizeof(JT808Conf_struct.Driver_Info)); result0=Rx_4442(70,10,(unsigned char *)DriverName); //读驾驶员姓名 rt_kprintf("\r\n驾驶员姓名:%s,result0=%d",DriverName,result0); result1=Rx_4442(52,18,(unsigned char *)DriverCardNUM); //读驾驶证号码 rt_kprintf("\r\n驾驶证代码:%s,result1=%d",DriverCardNUM,result1); memset(JT808Conf_struct.Driver_Info.DriveCode,0,sizeof(JT808Conf_struct.Driver_Info.DriveCode)); result2=Rx_4442(49,3,(unsigned char *)JT808Conf_struct.Driver_Info.DriveCode); //读驾驶员代码 DriveCode32=(JT808Conf_struct.Driver_Info.DriveCode[0]<<16)+(JT808Conf_struct.Driver_Info.DriveCode[1]<<8)+JT808Conf_struct.Driver_Info.DriveCode[2]; rt_kprintf("\r\n驾驶员代码:%d,result2=%d",DriveCode32,result2); memset(JT808Conf_struct.Driver_Info.Driver_ID,0,sizeof(JT808Conf_struct.Driver_Info.Driver_ID)); result3=Rx_4442(80,20,(unsigned char *)JT808Conf_struct.Driver_Info.Driver_ID); //身份证号码 rt_kprintf("\r\n身份证号码:%s,result3=%d",JT808Conf_struct.Driver_Info.Driver_ID,result3); memset(JT808Conf_struct.Driver_Info.Drv_CareerID,0,sizeof(JT808Conf_struct.Driver_Info.Drv_CareerID)); result4=Rx_4442(100,40,(unsigned char *)JT808Conf_struct.Driver_Info.Drv_CareerID); //从业资格证 rt_kprintf("\r\n从业资格证:%s,result4=%d",JT808Conf_struct.Driver_Info.Drv_CareerID,result4); memset(JT808Conf_struct.Driver_Info.Comfirm_agentID,0,sizeof(JT808Conf_struct.Driver_Info.Comfirm_agentID)); result5=Rx_4442(140,41,(unsigned char *)institution); //发证机构 memcpy(JT808Conf_struct.Driver_Info.Comfirm_agentID,&institution[1],40); rt_kprintf("\r\n发证机构:%s,result5=%d",JT808Conf_struct.Driver_Info.Comfirm_agentID,result5); if((result0==0)&&(result1==0)&&(result2==0)&&(result3==0)&&(result4==0)&&(result5==0))//读结果正确 { IC_CardInsert=1;//IC 卡插入正确 FLagx=0; //前18位为驾驶证号码-------------疲劳驾驶相关------看是否更换了卡 -------------- if(strncmp((char*)DriverCardNUM,(char*)JT808Conf_struct.Driver_Info.DriverCard_ID,18)!=0) { memset(JT808Conf_struct.Driver_Info.DriverCard_ID,0,sizeof(JT808Conf_struct.Driver_Info.DriverCard_ID)); memcpy(JT808Conf_struct.Driver_Info.DriverCard_ID,DriverCardNUM,18); FLagx=1; } //后20位为驾驶员姓名-------------疲劳驾驶相关------看是否更换了卡 -------------- if(strncmp((char*)DriverName,(char*)JT808Conf_struct.Driver_Info.DriveName,20)!=0) { memset(JT808Conf_struct.Driver_Info.DriveName,0,sizeof(JT808Conf_struct.Driver_Info.DriveName)); memcpy((u8*)JT808Conf_struct.Driver_Info.DriveName,DriverName,strlen((const char*)DriverName)); FLagx=2; } if(FLagx)//更换了IC 卡 清除疲劳驾驶相关 { TIRED_Drive_Init(); //清除疲劳驾驶的状态 GPIO_ResetBits(Buzzer_IO_Group,Buzzer_Group_Num); // 关闭蜂鸣器 Api_Config_Recwrite_Large(jt808,0,(u8*)&JT808Conf_struct,sizeof(JT808Conf_struct)); FLagx=0;//clear } BuzzerFlag=1;//响一声提示 pMenuItem=&Menu_2_5_DriverInfor; pMenuItem->show(); } else { BuzzerFlag=11;//响一声提示 IC_CardInsert=2;//IC 卡插入错误 } } Init8024Flag=0; GpsIo_Init(); } //===================测试IC卡读写完成================================================== }
//-------------------------------------------------------------------------------- void GPS_Rx_Process(u8 * Gps_str ,u16 gps_strLen) { u8 Gps_instr[160]; u8 GPRMC_Enable=0; memset(Gps_instr,0,sizeof(Gps_instr)); memcpy(Gps_instr,Gps_str,gps_strLen); if(GpsStatus.Raw_Output==1) rt_kprintf((const char*)Gps_instr); // rt_kprintf((const char*)Gps_str); //---------------- Mode Judge --------------------- if(strncmp((char*)Gps_instr,"$GNRMC,",7)==0) { GpsStatus.Position_Moule_Status=3; GPRMC_Enable=1; Car_Status[1]&=~0x0C; // clear bit3 bit2 Car_Status[1]|=0x0C; // BD+GPS mode 1100 } if(strncmp((char*)Gps_instr,"$BDRMC,",7)==0) { GpsStatus.Position_Moule_Status=1; GPRMC_Enable=1; Car_Status[1]&=~0x0C; // clear bit3 bit2 Car_Status[1]|=0x08; // BD mode 1000 } if(strncmp((char*)Gps_instr,"$GPRMC,",7)==0) { GpsStatus.Position_Moule_Status=2; GPRMC_Enable=1; Car_Status[1]&=~0x0C; // clear bit3 bit2 1100 Car_Status[1]|=0x04; // Gps mode 0100 } //-------------------------------------------------- //----------- Pick up useful -------------------------- if(GPRMC_Enable==1) { if(GpsStatus.Raw_Output==2) rt_kprintf(" gps_thread tx : %s",Gps_instr); Process_RMC(Gps_instr); Gps_Exception.current_datacou+=gps_strLen; return; } if((strncmp((char*)Gps_instr,"$GNTXT,",7)==0)||(strncmp((char*)Gps_instr,"$GPTXT,",7)==0)||(strncmp((char*)Gps_instr,"$BDTXT,",7)==0)) { //rt_kprintf("%s",GPSRx); Process_TXT(Gps_instr); return; } if((strncmp((char*)Gps_instr,"$GPGGA,",7)==0)||(strncmp((char*)Gps_instr,"$GNGGA,",7)==0)||(strncmp((char*)Gps_instr,"$BDGGA,",7)==0)) { //GNSS_Trans(); Process_GGA(Gps_instr); return; } if((strncmp((char*)Gps_instr,"$GPGSA,",7)==0)||(strncmp((char*)Gps_instr,"$BDGSA,",7)==0)||(strncmp((char*)Gps_instr,"$GNGSA,",7)==0)) { //rt_kprintf("%s",GPSRx); //GNSS_Trans(); Process_GSA(Gps_instr); return; } }
void rt_init_thread_entry(void *parameter) { /* Filesystem Initialization */ #ifdef RT_USING_DFS { /* init the device filesystem */ dfs_init(); #if defined(RT_USING_DFS_ELMFAT) /* init the elm chan FatFs filesystam*/ elm_init(); /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("File System initialized!\n"); } else rt_kprintf("File System initialzation failed!\n"); #endif #if defined(RT_USING_DFS_ROMFS) dfs_romfs_init(); if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0) { rt_kprintf("ROM File System initialized!\n"); } else rt_kprintf("ROM File System initialzation failed!\n"); #endif #if defined(RT_USING_DFS_DEVFS) devfs_init(); if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0) rt_kprintf("Device File System initialized!\n"); else rt_kprintf("Device File System initialzation failed!\n"); #ifdef RT_USING_NEWLIB /* init libc */ libc_system_init("uart0"); #endif #endif #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) /* NFSv3 Initialization */ nfs_init(); if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0) rt_kprintf("NFSv3 File System initialized!\n"); else rt_kprintf("NFSv3 File System initialzation failed!\n"); #endif #if defined(RT_USING_DFS_UFFS) /* init the uffs filesystem */ dfs_uffs_init(); /* mount flash device as flash directory */ if (dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0) rt_kprintf("UFFS File System initialized!\n"); else rt_kprintf("UFFS File System initialzation failed!\n"); #endif } #endif #ifdef RT_USING_RTGUI { extern void rtgui_system_server_init(void); rt_device_t lcd; /* init lcd */ rt_hw_lcd_init(); /* init touch panel */ rtgui_touch_hw_init(); /* init keypad */ rt_hw_key_init(); /* find lcd device */ lcd = rt_device_find("lcd"); /* set lcd device as rtgui graphic driver */ rtgui_graphic_set_device(lcd); /* initalize rtgui system server */ rtgui_system_server_init(); } #endif /* LwIP Initialization */ #ifdef RT_USING_LWIP { extern void lwip_sys_init(void); eth_system_device_init(); /* register ethernetif device */ rt_hw_dm9000_init(); /* init lwip system */ lwip_sys_init(); rt_kprintf("TCP/IP initialized!\n"); } #endif #ifdef RT_USING_FTK { rt_thread_t ftk_thread; /* init lcd */ rt_hw_lcd_init(); /* init touch panel */ rtgui_touch_hw_init(); /* init keypad */ rt_hw_key_init(); /* create ftk thread */ ftk_thread = rt_thread_create("ftk", rt_ftk_thread_entry, RT_NULL, 10 * 1024, 8, 20); /* startup ftk thread */ if (ftk_thread != RT_NULL) rt_thread_startup(ftk_thread); } #endif }
static rt_err_t eth_init(rt_device_t device) { struct eth_device *eth_device = (struct eth_device *)device; RT_ASSERT(eth_device != RT_NULL); s32 ijk; s32 status = 0; u64 dma_addr; u32 Mac_changed = 0; struct pbuf *pbuf; u8 macaddr[6] = DEFAULT_MAC_ADDRESS; struct rt_eth_dev *dev = ð_dev; struct synopGMACNetworkAdapter *adapter = dev->priv; synopGMACdevice *gmacdev = (synopGMACdevice *)adapter->synopGMACdev; synopGMAC_reset(gmacdev); synopGMAC_attach(gmacdev, (regbase + MACBASE), (regbase + DMABASE), DEFAULT_PHY_BASE, macaddr); synopGMAC_read_version(gmacdev); synopGMAC_set_mdc_clk_div(gmacdev, GmiiCsrClk3); gmacdev->ClockDivMdc = synopGMAC_get_mdc_clk_div(gmacdev); init_phy(adapter->synopGMACdev); DEBUG_MES("tx desc_queue\n"); synopGMAC_setup_tx_desc_queue(gmacdev, TRANSMIT_DESC_SIZE, RINGMODE); synopGMAC_init_tx_desc_base(gmacdev); DEBUG_MES("rx desc_queue\n"); synopGMAC_setup_rx_desc_queue(gmacdev, RECEIVE_DESC_SIZE, RINGMODE); synopGMAC_init_rx_desc_base(gmacdev); DEBUG_MES("DmaRxBaseAddr = %08x\n", synopGMACReadReg(gmacdev->DmaBase, DmaRxBaseAddr)); // u32 dmaRx_Base_addr = synopGMACReadReg(gmacdev->DmaBase,DmaRxBaseAddr); // rt_kprintf("first_desc_addr = 0x%x\n", dmaRx_Base_addr); #ifdef ENH_DESC_8W synopGMAC_dma_bus_mode_init(gmacdev, DmaBurstLength32 | DmaDescriptorSkip2 | DmaDescriptor8Words); #else //synopGMAC_dma_bus_mode_init(gmacdev, DmaBurstLength4 | DmaDescriptorSkip1); synopGMAC_dma_bus_mode_init(gmacdev, DmaBurstLength4 | DmaDescriptorSkip2); #endif synopGMAC_dma_control_init(gmacdev, DmaStoreAndForward | DmaTxSecondFrame | DmaRxThreshCtrl128); status = synopGMAC_check_phy_init(adapter); synopGMAC_mac_init(gmacdev); synopGMAC_pause_control(gmacdev); #ifdef IPC_OFFLOAD synopGMAC_enable_rx_chksum_offload(gmacdev); synopGMAC_rx_tcpip_chksum_drop_enable(gmacdev); #endif u32 skb; do { skb = (u32)plat_alloc_memory(RX_BUF_SIZE); //should skb aligned here? if (skb == RT_NULL) { rt_kprintf("ERROR in skb buffer allocation\n"); break; } dma_addr = plat_dma_map_single(gmacdev, (void *)skb, RX_BUF_SIZE); //获取 skb 的 dma 地址 status = synopGMAC_set_rx_qptr(gmacdev, dma_addr, RX_BUF_SIZE, (u32)skb, 0, 0, 0); if (status < 0) { rt_kprintf("status < 0!!\n"); plat_free_memory((void *)skb); } } while (status >= 0 && (status < (RECEIVE_DESC_SIZE - 1))); synopGMAC_clear_interrupt(gmacdev); synopGMAC_disable_mmc_tx_interrupt(gmacdev, 0xFFFFFFFF); synopGMAC_disable_mmc_rx_interrupt(gmacdev, 0xFFFFFFFF); synopGMAC_disable_mmc_ipc_rx_interrupt(gmacdev, 0xFFFFFFFF); // synopGMAC_disable_interrupt_all(gmacdev); synopGMAC_enable_interrupt(gmacdev, DmaIntEnable); synopGMAC_enable_dma_rx(gmacdev); synopGMAC_enable_dma_tx(gmacdev); plat_delay(DEFAULT_LOOP_VARIABLE); synopGMAC_check_phy_init(adapter); synopGMAC_mac_init(gmacdev); rt_timer_init(&dev->link_timer, "link_timer", synopGMAC_linux_cable_unplug_function, (void *)adapter, RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC); rt_timer_start(&dev->link_timer); #ifdef RT_USING_GMAC_INT_MODE /* installl isr */ DEBUG_MES("%s\n", __FUNCTION__); rt_hw_interrupt_install(LS1C_MAC_IRQ, eth_rx_irq, RT_NULL, "e0_isr"); rt_hw_interrupt_umask(LS1C_MAC_IRQ); #else rt_timer_init(&dev->rx_poll_timer, "rx_poll_timer", eth_rx_irq, (void *)adapter, 1, RT_TIMER_FLAG_PERIODIC); rt_timer_start(&dev->rx_poll_timer); #endif /*RT_USING_GMAC_INT_MODE*/ rt_kprintf("eth_inited!\n"); return RT_EOK; }
void rt_stm32f10x_spi_init(void) { rt_kprintf("rt_stm32f10x_spi_init \r\n"); #ifdef USING_SPI1 /* SPI1 config */ { //rt_kprintf("USE_SPI1 \r\n"); static struct stm32_spi_bus stm32_spi_1; GPIO_InitTypeDef GPIO_InitStructure; /* Enable SPI1 Periph clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_SPI1, ENABLE); #ifdef SPI_USE_DMA rt_kprintf("SPI_USE_DMA \r\n"); /* Enable the DMA1 Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); #endif /* #ifdef SPI_USE_DMA */ /* Configure SPI1 pins: PA5-SCK, PA6-MISO and PA7-MOSI */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); stm32_spi_register(SPI1, &stm32_spi_1, "spi1"); } /* SPI1 config */ #endif #ifdef USING_SPI2 /* SPI config */ { static struct stm32_spi_bus stm32_spi_2; GPIO_InitTypeDef GPIO_InitStructure; /* Enable SPI2 Periph clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); /*!< Enable the SPI and GPIO clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); #ifdef SPI_USE_DMA /* Enable the DMA1 Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); #endif /* Configure SPI2 pins: PB13-SCK, PB14-MISO and PB15-MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /*!< SPI SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; /* PB13 SPI2_SCK */ GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< SPI MISO pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; /* PB14 SPI2_MISO */ GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; /* PB15 SPI2_MOSI */ GPIO_Init(GPIOB, &GPIO_InitStructure); stm32_spi_register(SPI2, &stm32_spi_2, "spi2"); } /* SPI config */ #endif #ifdef USING_SPI3 /* SPI config */ { static struct stm32_spi_bus stm32_spi_3; GPIO_InitTypeDef GPIO_InitStructure; /* Enable SPI2 Periph clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); /*!< Enable the SPI and GPIO clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); #ifdef SPI_USE_DMA /* Enable the DMA2 Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); #endif /* Configure SPI2 pins: PB13-SCK, PB14-MISO and PB15-MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /*!< SPI SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; /* PB13 SPI2_SCK */ GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< SPI MISO pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; /* PB14 SPI2_MISO */ GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; /* PB15 SPI2_MOSI */ GPIO_Init(GPIOB, &GPIO_InitStructure); stm32_spi_register(SPI3, &stm32_spi_3, "spi3"); } /* SPI config */ #endif }
int recv_comm(int fd, unsigned char *buffer, rt_size_t size, struct timeval *timeout) { struct timeval t; int ret = 0; rt_size_t drv_recved = 0; int recved = 0, need = size; int timeout_cnt = 0; unsigned char *c = RT_NULL; fd_set readSet; RT_ASSERT(RT_NULL != buffer); if(fd == -1) { return -1; } t.tv_sec = 0; t.tv_usec = 100000; if(RT_NULL == timeout) { /* Wait forever approximate, it's a large time. */ timeout_cnt = 0xffffffff; } else { timeout_cnt = (timeout->tv_sec * 1000 * 1000 + timeout->tv_usec)/(t.tv_sec * 1000 * 1000 + t.tv_usec); } while(1) { FD_ZERO(&readSet); FD_SET(fd, &readSet); ret = select(fd+1,&readSet,RT_NULL,RT_NULL,&t); if(ret < 0) { rt_kprintf("select error %d\n",ret); break; } else if(ret == 0) { /* timeout */ timeout_cnt--; if(timeout_cnt == 0) { rt_kprintf("need %d data in timeout %d ms,but only %d recved.\n", size, timeout->tv_sec * 1000 + timeout->tv_usec / 1000, recved); recved = 0; break; } } else { if(FD_ISSET(fd, &readSet)) { c = &buffer[size - need]; ioctl(fd, FIONREAD, &drv_recved); /* check poll and ioctl */ RT_ASSERT(drv_recved != 0); drv_recved = (drv_recved > need ? need : drv_recved); recved = read(fd, c, drv_recved); if(recved != drv_recved) { rt_kprintf("fatal error %s(%d).\n",__FUNCTION__,__LINE__); RT_ASSERT(0); recved = 0; break; } need -= recved; if(need) { continue; } else if (need == 0) { recved = size; break; } else { rt_kprintf("fatal error %s(%d).\n",__FUNCTION__,__LINE__); RT_ASSERT(0); } } } } return recved; }