static void ni52_rcv_int(struct device *dev) { int status; unsigned short totlen; struct sk_buff *skb; struct rbd_struct *rbd; struct priv *p = (struct priv *) dev->priv; for(;(status = p->rfd_top->status) & STAT_COMPL;) { rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); if(status & STAT_OK) /* frame received without error? */ { if( (totlen = rbd->status) & RBD_LAST) /* the first and the last buffer? */ { totlen &= RBD_MASK; /* length of this frame */ rbd->status = 0; skb = (struct sk_buff *) dev_alloc_skb(totlen+2); if(skb != NULL) { skb->dev = dev; skb_reserve(skb,2); /* 16 byte alignment */ memcpy(skb_put(skb,totlen),(char *) p->base+(unsigned long) rbd->buffer, totlen); skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); p->stats.rx_packets++; } else p->stats.rx_dropped++; } else { printk("%s: received oversized frame.\n",dev->name); p->stats.rx_dropped++; } } else /* frame !(ok), only with 'save-bad-frames' */ { printk("%s: oops! rfd-error-status: %04x\n",dev->name,status); p->stats.rx_errors++; } p->rfd_top->status = 0; p->rfd_top->last = RFD_SUSP; p->rfd_last->last = 0; /* delete RU_SUSP */ p->rfd_last = p->rfd_top; p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ } }
void CCID_BulkInMessage(void) { gi32UsbdMessageLength = USB_MESSAGE_HEADER_SIZE + make32(&UsbMessageBuffer[OFFSET_DWLENGTH]); pUsbMessageBuffer = UsbMessageBuffer; if (gu8IsBulkInReady) { if(gi32UsbdMessageLength >= EP2_MAX_PKT_SIZE) { gu8IsBulkInReady = 1; USBD_MemCopy((uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP2)), pUsbMessageBuffer, EP2_MAX_PKT_SIZE); USBD_SET_PAYLOAD_LEN(EP2, EP2_MAX_PKT_SIZE); pUsbMessageBuffer += EP2_MAX_PKT_SIZE; gi32UsbdMessageLength -= EP2_MAX_PKT_SIZE; } else { USBD_MemCopy((uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP2)), pUsbMessageBuffer, gi32UsbdMessageLength); USBD_SET_PAYLOAD_LEN(EP2, gi32UsbdMessageLength); gi32UsbdMessageLength = 0; gu8IsBulkInReady = 0; } } }
int32 rtc_read_int32(int8 addr) { int8 a,b,c,d; a=read_rtc(addr+0); // MSB b=read_rtc(addr+1); c=read_rtc(addr+2); d=read_rtc(addr+3); // LSB return make32(a,b,c,d); }
static BOOL check_sec_crc(u8 *p_buffer) { u16 section_len = 0; u32 crc = 0; section_len = MAKE_WORD(p_buffer[2], (p_buffer[1] & 0x0f)); section_len += 3; crc = crc_fast_calculate(CRC32_ARITHMETIC_CCITT, 0xFFFFFFFF, p_buffer, section_len - 4); return (crc == make32(p_buffer + section_len -4)); }
static BOOL check_sec_crc(dvb_priv_t *p_priv, dvb_section_t *p_sec) { u16 section_len = 0; u32 crc = 0; section_len = MAKE_WORD(p_sec->p_buffer[2], (p_sec->p_buffer[1] & 0x0f)); section_len += 3; crc = crc_fast_calculate(CRC32_ARITHMETIC_CCITT, 0xFFFFFFFF, (u8 *)p_sec->p_buffer, section_len - 4); //OS_PRINTF("crc check error table_id 0x%x, value: 0x%x, value2 : 0x%x\n", // p_sec->table_id, crc, make32(p_sec->p_buffer + section_len - 4)); return (crc == make32(p_sec->p_buffer + section_len -4)); }
float rtc_read_float(int8 addr) { int8 a,b,c,d; union_int32_float u; a=read_rtc(addr+0); // MSB b=read_rtc(addr+1); c=read_rtc(addr+2); d=read_rtc(addr+3); // LSB u.l = make32(a,b,c,d); return u.f; }
static void parse_cable_delivery_system_descriptor( u8* pBuf, cable_tp_info_t* pDesc ) { u8* data = pBuf; if( data != NULL && pDesc != NULL ) { pDesc->frequency = make32(data); pDesc->frequency = bcd_number_to_dec(pDesc->frequency)/10; pDesc->modulation = data[6] + 3; pDesc->symbol_rate = MT_MAKE_DWORD( MAKE_WORD((data[10] & 0xf0), data[9]), MAKE_WORD(data[8], data[7])); //pDesc->symbol_rate >>= 8; pDesc->symbol_rate = bcd_number_to_dec(pDesc->symbol_rate)/100; } }
void EP3_Handler(void) { /* BULK OUT */ static int offset = 0; uint32_t len; len = USBD_GET_PAYLOAD_LEN(EP3); USBD_MemCopy(&UsbMessageBuffer[offset], (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP3)), len); if((len >= 0x0A && len != 0xFF) || offset != 0) { if(offset == 0) { /* Calculate number of byte to receive to finish the message */ gi32UsbdMessageLength = USB_MESSAGE_HEADER_SIZE + make32(&UsbMessageBuffer[OFFSET_DWLENGTH]); } gi32UsbdMessageLength -= (int) len; /* Prepare next reception if whole message not received */ if(gi32UsbdMessageLength > 0) { pUsbMessageBuffer = UsbMessageBuffer + len; offset += len; } if(gi32UsbdMessageLength == 0) { gu8IsBulkOutReady = 1; offset = 0; } if(gi32UsbdMessageLength < 0) { UsbMessageBuffer[OFFSET_DWLENGTH] = 0xFF; UsbMessageBuffer[OFFSET_DWLENGTH+1] = 0xFF; UsbMessageBuffer[OFFSET_DWLENGTH+2] = 0xFF; UsbMessageBuffer[OFFSET_DWLENGTH+3] = 0xFF; gu8IsBulkOutReady = 1; } } CCID_DispatchMessage(); /* trigger next out packet */ if (gi32UsbdMessageLength > 0) USBD_SET_PAYLOAD_LEN(EP3, EP3_MAX_PKT_SIZE); }
void cs5463spi::Calibrate(int calType){ bool bSuccess = false; uint8_t rx1[4]; memset(rx1, 0x00, sizeof(rx1)); //checks data Ready: i.e. device in active state and ready to receive commands. if(CheckStatusReady(drdy)) { switch(calType) { case v_dc_offset_cal: ReadRegister(m_cs5463NumList[mode].addr, rx1); if(!IsSet(*(rx1+3), 5)) bSuccess = this->VchannDCoffsetCal(); if(bSuccess) cout << "Voltage DC Offset Calibration successfully performed." << endl; else{ cout << "HPF set, no need for Voltage Offset calibration" << endl; WriteRegister(m_cs5463NumList[v_dc_offset].addr, 0x00, 0x00, 0x00); //TODO: maybe set somewhere else } memset(rx1, 0x00, sizeof(rx1)); break; case i_dc_offset_cal: ReadRegister(m_cs5463NumList[mode].addr, rx1); if(!IsSet(*(rx1+3), 6)) { bSuccess = this->IchannDCoffsetCal(); if(bSuccess) cout << "Current DC Offset Calibration successfully performed." << endl; } else { cout << "HPF set, no need for Current Offset calibration" << endl; WriteRegister(m_cs5463NumList[i_dc_offset].addr, 0x00, 0x00, 0x00); //TODO: maybe set somewhere else } memset(rx1, 0x00, sizeof(rx1)); break; case iv_dc_offset_cal: //bSuccess = this-> break; case v_ac_offset_cal: bSuccess = this->VchannACoffsetCal(); if(bSuccess) cout << "Voltage AC Offset Calibration successfully performed." << endl; break; case i_ac_offset_cal: bSuccess = this->IchannACoffsetCal(); if(bSuccess) cout << "Current AC Offset Calibration successfully performed." << endl; break; case v_dc_gain_cal: //check V gain register.if it is 1, do not perform calibration cout << "hmm" << endl; ReadRegister(m_cs5463NumList[v_gain].addr, rx1); if(!(make32(rx1) == 1)) this->VChannDCGainCal(); else cout << "No Need for Voltage Channel AC Gain Calibration" << endl; break; case i_dc_gain_cal: break; case v_ac_gain_cal: break; case i_ac_gain_cal: break; default: break; } } else cout << "Status: " << m_statusWarn[drdy].c_str() << " NOT" << endl; }
void parse_bat(handle_t handle, dvb_section_t *p_sec) { dvb_t *p_dvb_handle = (dvb_t *)class_get_handle_by_id(DVB_CLASS_ID); service_t *p_svc = (service_t *)handle; os_msg_t msg = {0}; u8 *p_buf = p_sec->p_buffer; u16 bouquet_id = 0; u16 offset = 0; s16 bouquet_len = 0; s16 section_len = 0; s16 ts_loop_len = 0; s16 desc_len = 0; u8 dl_loop_len = 0; u8 i = 0; bat_t bat = {0}; u8 tmp_len = 0; //u8 seg_num,total_seg_num; //u16 table_ext_id; //u8 last_section_num; linkage_update_desc_t update_info = {0}; CHECK_FAIL_RET_VOID(p_dvb_handle != NULL); if(p_buf[0] != p_sec->table_id) { p_dvb_handle->filter_data_error(p_sec->p_svc, p_sec); return; } if ((p_buf[5] & 0x01) == 0) { p_dvb_handle->filter_data_error(p_sec->p_svc, p_sec); return; } bouquet_id = MAKE_WORD2(p_buf[3], p_buf[4]); /* Section length */ section_len = MAKE_WORD2((p_buf[1] & 0x0f), p_buf[2]); section_len += 3; memset(&bat, 0, sizeof(bat_t)); bat.bouquet_id = bouquet_id; bat.version_num = (p_buf[5] & 0x3E) >> 1; bat.sec_number = p_buf[6]; bat.last_sec_number = p_buf[7]; bouquet_len = MAKE_WORD2(p_buf[8] & 0x0F, p_buf[9]); offset = 10; while(bouquet_len > 0) { tmp_len = p_buf[offset + 1]; if(p_buf[offset] == DVB_DESC_LINKAGE) { bat.ts_id = update_info.ts_id = MAKE_WORD2(p_buf[offset + 2], p_buf[offset + 3]); bat.network_id = update_info.network_id = MAKE_WORD2(p_buf[offset + 4], p_buf[offset + 5]); bat.service_id = update_info.service_id = MAKE_WORD2(p_buf[offset + 6], p_buf[offset + 7]); if(p_buf[offset + 8] == 0xA0) // linkage type 0xA0 { update_info.operator_num = p_buf[offset + 9]; dl_loop_len = p_buf[offset + 10]; for(i = 0; i < dl_loop_len;) { update_info.manufacture_id = p_buf[offset + 11 + i]; update_info.hardware_id = MAKE_WORD2(p_buf[offset + 12 + i], p_buf[offset + 13 + i]); update_info.model_id = p_buf[offset + 14 + i]; update_info.software_ver = MAKE_WORD2(p_buf[offset + 15], p_buf[offset + 16 + i]); update_info.force_flag = p_buf[offset + 18 + i] & 0x03; update_info.start_STB_id = make32(&p_buf[offset + 19 + i]); update_info.end_STB_id = make32(&p_buf[offset + 23 + i]); i += 16; } } else if(p_buf[offset + 8] == 0x80) { // TODO: add linkage type of 0x80 parse codes here //get service info fdt pid and table_id //seg_num = p_buf[offset + 9]>>5; //total_seg_num = p_buf[offset + 12]>>5; bat.fdt_table_id = p_buf[offset + 11]; if(DVB_TABLE_ID_FDT == bat.fdt_table_id) { bat.fdt_pid = MAKE_WORD2(p_buf[offset + 9]&0x1F, p_buf[offset + 10 ]); bat.fdt_ver_num = p_buf[offset + 12]&0x1F; //get table_ext_id and section num info! //for(i=0;i<=total_seg_num;i++) //{ // table_ext_id = MAKE_WORD2(p_buf[offset+13+(3*i)],p_buf[offset+14+(3*i)]); // last_section_num = p_buf[offset+15+(3*i)]; //} } } } // descriptor name else if(p_buf[offset] == 0x47) { //OS_PRINTF("bat descriptor name: %s \n", &p_buf[offset + 2]); } else if(DVB_DESC_LOGICAL_CHANNEL == p_buf[offset]) { logical_channel_t *p_log_ch = bat.log_ch_info + bat.log_ch_num; u8 *p_log_des = p_buf + offset + 2; //skip tag and len u8 des_len = tmp_len; while(des_len) { if(bat.log_ch_num >= DVB_MAX_SDT_SVC_NUM) //check input { break; } p_log_ch->service_id = MAKE_WORD2(p_log_des[0] & 0x0F, p_log_des[1]); p_log_ch->logical_channel_id = (MAKE_WORD2(p_log_des[2] & 0x0F, p_log_des[3]) & 0x3FFF); p_log_ch++; bat.log_ch_num++; p_log_des += 4; if(des_len < 4) //for check error { des_len = 0; } else { des_len -= 4; } } } offset += (tmp_len + 2); bouquet_len -= (tmp_len + 2); } // TODO ts loop len while ts_loop_len = MAKE_WORD2(p_buf[offset] & 0xF, p_buf[offset + 1]); while(ts_loop_len > 0) { offset += 4; desc_len = MAKE_WORD2(p_buf[offset] & 0xF, p_buf[offset + 1]); offset += 2; ts_loop_len -= (desc_len + 6); while(desc_len > 0) { tmp_len = p_buf[offset + 1]; // add any trans desc parse here offset += (tmp_len + 2); desc_len -= (tmp_len + 2); } } msg.content = DVB_BAT_FOUND; //All the tasks receiving this message must have higher task priority //than DVB task msg.para1 = (u32)(&bat); msg.para2 = sizeof(bat_t); #ifdef __LINUX__ msg.is_ext = 1; #endif p_svc->notify(p_svc, &msg); return; }
static void ni52_rcv_int(struct net_device *dev) { int status, cnt = 0; unsigned short totlen; struct sk_buff *skb; struct rbd_struct __iomem *rbd; struct priv *p = netdev_priv(dev); if (debuglevel > 0) printk("R"); for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) { rbd = make32(readw(&p->rfd_top->rbd_offset)); if (status & RFD_OK) { /* */ totlen = readw(&rbd->status); if (totlen & RBD_LAST) { /* */ totlen &= RBD_MASK; /* */ writew(0x00, &rbd->status); skb = netdev_alloc_skb(dev, totlen + 2); if (skb != NULL) { skb_reserve(skb, 2); skb_put(skb, totlen); memcpy_fromio(skb->data, p->base + readl(&rbd->buffer), totlen); skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); dev->stats.rx_packets++; dev->stats.rx_bytes += totlen; } else dev->stats.rx_dropped++; } else { int rstat; /* */ totlen = 0; while (!((rstat = readw(&rbd->status)) & RBD_LAST)) { totlen += rstat & RBD_MASK; if (!rstat) { printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name); break; } writew(0, &rbd->status); rbd = make32(readw(&rbd->next)); } totlen += rstat & RBD_MASK; writew(0, &rbd->status); printk(KERN_ERR "%s: received oversized frame! length: %d\n", dev->name, totlen); dev->stats.rx_dropped++; } } else {/* */ printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n", dev->name, status); dev->stats.rx_errors++; } writeb(0, &p->rfd_top->stat_high); writeb(RFD_SUSP, &p->rfd_top->last); /* */ writew(0xffff, &p->rfd_top->rbd_offset); writeb(0, &p->rfd_last->last); /* */ p->rfd_last = p->rfd_top; p->rfd_top = make32(readw(&p->rfd_top->next)); /* */ writew(make16(p->rfd_top), &p->scb->rfa_offset); if (debuglevel > 0) printk("%d", cnt++); } if (automatic_resume) { wait_for_scb_cmd(dev); writeb(RUC_RESUME, &p->scb->cmd_ruc); ni_attn586(); wait_for_scb_cmd_ruc(dev); } #ifdef WAIT_4_BUSY { int i; for (i = 0; i < 1024; i++) { if (p->rfd_top->status) break; udelay(16); if (i == 1023) printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name); } } #endif if (debuglevel > 0) printk("r"); }
/* ========================================================================= */ void bootloader(void) { uint32 addr; uint16 addr_low; uint8 addr_high = 0; uint8 reclen; uint8 rectype; uint8 idx; uint8 buffer[HEX_LINE_LEN_MAX]; uint8 ch; bool hexend = 0; #if getenv("FLASH_ERASE_SIZE")>2 uint16 next_addr = 0; #endif /* until end of HEX file */ while(hexend == 0) { /* get one line of the HEX file via RS232 until we receive CR or */ /* we reached the end of the buffer */ idx = 0; do { /* get one byte */ ch = getch(); /* save to buffer */ buffer[idx] = ch; /* increment buffer index */ idx++; } while(ch != 0x0A); /* get record length */ reclen = get_hexbyte(&buffer[HEX_LEN_START]); /* check for proper checksum */ if (check_checksum(&buffer[HEX_LEN_START], reclen) != 0) { /* checkum error - send negative acknowledge */ putc(NAK); } else { /* checkum ok */ /* get address */ addr_low = make16(get_hexbyte(&buffer[HEX_ADDR_START]), get_hexbyte(&buffer[HEX_ADDR_START+2])); /* make 32 bit address */ addr = make32(addr_high, addr_low); /* get record type */ rectype = get_hexbyte(&buffer[HEX_TYPE_START]); if (rectype == HEX_DATA_REC) { /* only program code memory */ if ((addr_high < 0x30) && (addr >= RESET_VECTOR)) { for (idx=0; idx < reclen; idx++) { buffer[idx] = get_hexbyte(&buffer[HEX_DATA_START+(idx*2)]); } #if getenv("FLASH_ERASE_SIZE") > getenv("FLASH_WRITE_SIZE") #if defined(__PCM__) if ((addr_low!=next_addr)&&(addr_low&(getenv("FLASH_ERASE_SIZE")-1)!=0)) #else if ((addr_low!=next_addr)&&(addr_low&(getenv("FLASH_ERASE_SIZE")/2-1)!=0)) #endif erase_program_eeprom(addr); next_addr = addr_low + 1; #endif write_program_memory(addr, buffer, reclen); } } else if (rectype == HEX_EOF_REC) { hexend = 1; } else if (rectype == HEX_EXTADDR_REC) { /* to save resources, only take lower byte - this */ /* allows 24 bit addresses => enough for PIC18F */ //addr_high = make16(get_hexbyte(&buffer[HEX_DATA_START]), // get_hexbyte(&buffer[HEX_DATA_START+2])); addr_high = get_hexbyte(&buffer[HEX_DATA_START+2]); } /* send positive acknowledge */ putc(ACK); } } }
static void ni52_rcv_int(struct device *dev) { int status; unsigned short totlen,pnt; struct sk_buff *skb; struct rbd_struct *rbd,*rbd_first; struct priv *p = (struct priv *) dev->priv; for(;(status = p->rfd_top->status) & STAT_COMPL;) { rbd = rbd_first = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); #ifdef DEBUG1 { struct rbd_struct *rbd1 = rbd; if(rbd1==p->rbd_last) printk("L"); printk("S:%04x/%x/%02x >",(int) rbd1->status,(int) rbd1->size>>12,(int)((unsigned long) rbd1 & 0xff)); rbd1 = (struct rbd_struct *) make32(rbd1->next); for(;rbd1 != rbd_first;rbd1 = (struct rbd_struct *) make32(rbd1->next)) { if(rbd1 == p->rbd_last) printk("L:"); printk("%04x/%x-",(int) rbd1->status>>12,(int) rbd1->size>>12); } printk("< "); } { struct rfd_struct *rfd1 = p->rfd_top; if(rfd1==p->rfd_last) printk("L"); printk("S:%04x/%x/%02x >",(int) rfd1->status,(int) rfd1->last>>12,(int)((unsigned long) rfd1 & 0xff)); rfd1 = (struct rfd_struct *) make32(rfd1->next); for(;rfd1 != p->rfd_top;rfd1 = (struct rfd_struct *) make32(rfd1->next)) { if(rfd1 == p->rfd_last) printk("L:"); printk("%x/%x-",(int) rfd1->status>>12,(int) rfd1->last>>12); } printk("<\n"); } #endif p->rfd_top->status = 0; p->rfd_top->last = RFD_LAST; p->rfd_last->last = 0; /* delete RFD_LAST, no RU suspend */ p->rfd_last = p->rfd_top; p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); if(status & RFD_ERRMASK) printk("%s: RFD-Error ... status: %04x.\n",dev->name,status); if(status & STAT_OK) { for(totlen=0; !(rbd->status & RBD_LAST); rbd=(struct rbd_struct *) make32(rbd->next)) { totlen += RECV_BUFF_SIZE; rbd->status = 0; } totlen += rbd->status & RBD_MASK; rbd->status = 0; skb = (struct sk_buff *) alloc_skb(totlen, GFP_ATOMIC); if (skb != NULL) /* copy header */ { skb->len = totlen; skb->dev = dev; if(rbd->buffer < rbd_first->buffer) { pnt = p->max_cbuff24 - rbd_first->buffer; memcpy( (char *) skb->data,p->max_cbuff32-pnt,pnt); memcpy( (char *) skb->data+pnt,p->min_cbuff32,totlen-pnt); } else memcpy( (char *) skb->data,(char *) p->base+(unsigned long) rbd_first->buffer, totlen); rbd->size |= RBD_LAST; p->rbd_last->size &= ~RBD_LAST; p->rbd_last = rbd; netif_rx(skb); p->stats.rx_packets++; } else { rbd->size |= RBD_LAST; p->rbd_last->size &= ~RBD_LAST; p->rbd_last = rbd; } } else /* frame !(ok), only with 'save-bad-frames' */ { printk("%s: oops! rfd-error-status: %04x\n",dev->name,status); p->stats.rx_errors++; } } }
static BOOL parse_tfcas_codedownload_descriptor( u8* pBuf, u8 DescLength, update_t *p_up_info ) { BOOL bErr = FALSE; u8* pData = pBuf; s32 Length = DescLength; u16 ManufactureID = 0; u8 private_data_len = 0; cable_tp_info_t cable_tp_info = {0,}; #ifndef WIN32 #ifdef CAS_CONFIG_CDCAS extern RET_CODE cas_get_platformid(cas_module_id_t cam_id, u16 *platformid); #endif #endif if( pData != NULL && p_up_info != NULL ) { ManufactureID = ( ( ( u16 ) pData[0] ) << 8 ) | pData[1]; #ifndef WIN32 #ifdef CAS_CONFIG_CDCAS cas_get_platformid(CAS_ID_TF, &plat_id); #endif #endif OS_PRINTF("[Update] ManufactureID=0x%x;ManufactureID=0x%x, PlatID=0x%x\n",ManufactureID, ManufactureID_KINGVON, plat_id); if(ManufactureID_KINGVON == ManufactureID) { //skip manufacture id Length -= 2; pData += 2; while( Length > 0 ) { //skip cable delivery tag and len pData +=2; Length -=2; parse_cable_delivery_system_descriptor( pData, &cable_tp_info ); OS_PRINTF("[Update] Down freq=%d,Qam=%d,Sym=%d\n", cable_tp_info.frequency, cable_tp_info.modulation, cable_tp_info.symbol_rate ); //p_up_info->oui = ManufactureID; p_up_info->symbol = cable_tp_info.symbol_rate; p_up_info->freq = cable_tp_info.frequency; p_up_info->qam_mode = cable_tp_info.modulation; //skip cable delivery body pData += 11; Length -= 11; p_up_info->data_pid = (u16)(((pData[0]<<8)|(pData[1]&0xF8))>>3); OS_PRINTF("[Update] data_pid=0x%x\n",p_up_info->data_pid); p_up_info->ota_type = pData[1] & 0x7; OS_PRINTF("[Update] ota_type=0x%x\n",p_up_info->ota_type); private_data_len = pData[2]; /*skip the Private_data_Len and pid */ pData += 3; Length -= 3; /*Next is private data*/ //Hardware_version p_up_info->hwVersion = make32(&pData[0]); OS_PRINTF("[Update] hwVersion=0x%x\n",p_up_info->hwVersion); Length -= 4; pData += 4; //Software_version p_up_info->swVersion = make32(&pData[0]); OS_PRINTF("[Update] swVersion=0x%x\n",p_up_info->swVersion); Length -= 4; pData += 4; //platform id p_up_info->plat_id = make32(&pData[0]); OS_PRINTF("[Update] plat_id=0x%x\n",p_up_info->plat_id); Length -= 4; pData += 4; return TRUE; } }
void cs5463spi::MakeReadings() { uint8_t rx1[4], rx2[4], rx3[4], rx4[4], rx5[4], rx6[4], rx7[4], rx8[4], rx9[4], rx10[4]; uint8_t rx11[4], rx12[4], rx13[4]; while(1){ char *strAcc=0; struct timespec startTime; long long elapsedTime = 0; double current, power; memset(rx1, 0x00, sizeof(rx1)); memset(rx2, 0x00, sizeof(rx2)); memset(rx3, 0x00, sizeof(rx3)); memset(rx4, 0x00, sizeof(rx4)); memset(rx5, 0x00, sizeof(rx5)); memset(rx6, 0x00, sizeof(rx6)); memset(rx7, 0x00, sizeof(rx7)); memset(rx8, 0x00, sizeof(rx8)); memset(rx9, 0x00, sizeof(rx9)); memset(rx10, 0x00, sizeof(rx10)); memset(rx11, 0x00, sizeof(rx11)); memset(rx12, 0x00, sizeof(rx12)); memset(rx13, 0x00, sizeof(rx13)); m_cs5463NumList[p_act].value = 0; m_cs5463NumList[i_rms].value = 0; m_cs5463NumList[v_rms].value = 0; m_cs5463NumList[q].value = 0; m_cs5463NumList[temp].value = 0; m_cs5463NumList[i_int].value = 0; m_cs5463NumList[v_int].value = 0; m_cs5463NumList[q_trig].value = 0; m_cs5463NumList[pf].value = 0; m_cs5463NumList[p_h].value = 0; m_cs5463NumList[p_f].value = 0; m_cs5463NumList[q_f].value = 0; m_cs5463NumList[q_avg].value = 0; startTime = this->CurrentTime(); current = 0.0; power = 0.0; do{ elapsedTime = ElapsedTime(startTime); int bDone = false; WriteRegister(m_cs5463NumList[status].addr,m_cmds.SYNC_1, m_cmds.SYNC_1, m_cmds.SYNC_1); do { ReadRegister(m_cs5463NumList[p_act].addr, rx1); ReadRegister(m_cs5463NumList[i_rms].addr, rx2); ReadRegister(m_cs5463NumList[v_rms].addr, rx3); ReadRegister(m_cs5463NumList[q].addr, rx4); ReadRegister(m_cs5463NumList[temp].addr, rx5); ReadRegister(m_cs5463NumList[i_int].addr, rx6); ReadRegister(m_cs5463NumList[v_int].addr, rx7); ReadRegister(m_cs5463NumList[q_trig].addr, rx8); ReadRegister(m_cs5463NumList[pf].addr, rx9); ReadRegister(m_cs5463NumList[p_h].addr, rx10); ReadRegister(m_cs5463NumList[p_f].addr, rx11); ReadRegister(m_cs5463NumList[q_f].addr, rx12); ReadRegister(m_cs5463NumList[q_avg].addr, rx13); bDone = CheckStatusReady(drdy); } while(bDone == false); m_cs5463NumList[p_act].value = make32(rx1); //Average Power m_cs5463NumList[i_rms].value = make32(rx2); m_cs5463NumList[v_rms].value = make32(rx3); m_cs5463NumList[q].value = make32(rx4); //Instantaneous Reactive Power m_cs5463NumList[temp].value = make32(rx5); m_cs5463NumList[i_int].value = make32(rx6); m_cs5463NumList[v_int].value = make32(rx7); m_cs5463NumList[q_trig].value = make32(rx8); m_cs5463NumList[pf].value = make32(rx9); m_cs5463NumList[p_h].value = make32(rx10); m_cs5463NumList[p_f].value = make32(rx11); m_cs5463NumList[q_f].value = make32(rx12); m_cs5463NumList[q_avg].value = make32(rx13); NumNotationConv(p_act); NumNotationConv(i_rms); NumNotationConv(v_rms); NumNotationConv(q); NumNotationConv(temp); NumNotationConv(i_int); NumNotationConv(v_int); NumNotationConv(q_trig); NumNotationConv(pf); NumNotationConv(p_h); NumNotationConv(p_f); NumNotationConv(q_f); NumNotationConv(q_avg); current += m_cs5463NumList[i_int].valueDec; }while(elapsedTime < 2E9); cout << "Accum Current is: " << current << endl; asprintf(&strAcc, "%sT%f %f %f %f %f %f %f %f %f %f %f %f %f", m_dateTime.c_str(), m_cs5463NumList[p_act].valueDec, m_cs5463NumList[i_rms].valueDec, m_cs5463NumList[v_rms].valueDec, m_cs5463NumList[q].valueDec, //Instantaneous Reactive Power m_cs5463NumList[temp].valueDec, current, m_cs5463NumList[v_int].valueDec, m_cs5463NumList[q_trig].valueDec, m_cs5463NumList[pf].valueDec, m_cs5463NumList[p_h].valueDec, m_cs5463NumList[p_f].valueDec, m_cs5463NumList[q_f].valueDec, m_cs5463NumList[q_avg].valueDec ); printf("%s,\n", strAcc); m_pMyLogger->WriteReadRemote(strAcc); //write remote m_pMyLogger->WriteLocal(LOG_LOCAL0, LOG_WARNING, strAcc); //write local free(strAcc); //sleep(10); } }
static void sun3_82586_rcv_int(struct net_device *dev) { int status,cnt=0; unsigned short totlen; struct sk_buff *skb; struct rbd_struct *rbd; struct priv *p = netdev_priv(dev); if(debuglevel > 0) printk("R"); for(;(status = p->rfd_top->stat_high) & RFD_COMPL;) { rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); if(status & RFD_OK) /* frame received without error? */ { if( (totlen = swab16(rbd->status)) & RBD_LAST) /* the first and the last buffer? */ { totlen &= RBD_MASK; /* length of this frame */ rbd->status = 0; skb = (struct sk_buff *) dev_alloc_skb(totlen+2); if(skb != NULL) { skb_reserve(skb,2); skb_put(skb,totlen); skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen); skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); dev->stats.rx_packets++; } else dev->stats.rx_dropped++; } else { int rstat; /* free all RBD's until RBD_LAST is set */ totlen = 0; while(!((rstat=swab16(rbd->status)) & RBD_LAST)) { totlen += rstat & RBD_MASK; if(!rstat) { printk("%s: Whoops .. no end mark in RBD list\n",dev->name); break; } rbd->status = 0; rbd = (struct rbd_struct *) make32(rbd->next); } totlen += rstat & RBD_MASK; rbd->status = 0; printk("%s: received oversized frame! length: %d\n",dev->name,totlen); dev->stats.rx_dropped++; } } else /* frame !(ok), only with 'save-bad-frames' */ { printk("%s: oops! rfd-error-status: %04x\n",dev->name,status); dev->stats.rx_errors++; } p->rfd_top->stat_high = 0; p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */ p->rfd_top->rbd_offset = 0xffff; p->rfd_last->last = 0; /* delete RFD_SUSP */ p->rfd_last = p->rfd_top; p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ p->scb->rfa_offset = make16(p->rfd_top); if(debuglevel > 0) printk("%d",cnt++); } if(automatic_resume) { WAIT_4_SCB_CMD(); p->scb->cmd_ruc = RUC_RESUME; sun3_attn586(); WAIT_4_SCB_CMD_RUC(); } #ifdef WAIT_4_BUSY { int i; for(i=0;i<1024;i++) { if(p->rfd_top->status) break; DELAY_16(); if(i == 1023) printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name); } } #endif #if 0 if(!at_least_one) { int i; volatile struct rfd_struct *rfds=p->rfd_top; volatile struct rbd_struct *rbds; printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least); for(i=0;i< (p->num_recv_buffs+4);i++) { rbds = (struct rbd_struct *) make32(rfds->rbd_offset); printk("%04x:%04x ",rfds->status,rbds->status); rfds = (struct rfd_struct *) make32(rfds->next); } printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status); printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus); } old_at_least = at_least_one; #endif if(debuglevel > 0) printk("r"); }
void load_program(void) { int1 do_ACKLOD, done=FALSE; int8 checksum, line_type; int16 l_addr,h_addr=0; int8 to; int32 addr; int8 dataidx, i, count; int8 data[32]; int buffidx; char buffer[BUFFER_LEN_LOD]; while (!done) // Loop until the entire program is downloaded { usb_task(); if(!usb_cdc_kbhit()) continue; buffidx = 0; // Read into the buffer until 0x0D ('\r') is received or the buffer is full to = 250; //250 milliseconds do { if(!usb_cdc_kbhit()) { delay_ms(1); to--; if(!to) break; } else to = 250; i = usb_cdc_getc(); buffer[buffidx++] = i; }while((i != 0x0D) && (i != 0x0A) && (buffidx <= BUFFER_LEN_LOD)); if(!to) continue; usb_cdc_putc(XOFF); // Suspend sender do_ACKLOD = TRUE; // Only process data blocks that start with ':' if(buffer[0] == ':') { count = atoi_b16 (&buffer[1]); // Get the number of bytes from the buffer // Get the lower 16 bits of address l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5])); line_type = atoi_b16 (&buffer[7]); addr = make32(h_addr,l_addr); // If the line type is 1, then data is done being sent if(line_type == 1) { done = TRUE; } else if((addr >= (int32)APPLICATION_START) && (addr < ((int32)0x300000))) { checksum = 0; // Sum the bytes to find the check sum value for(i=1; i<(buffidx-3); i+=2) checksum += atoi_b16 (&buffer[i]); checksum = 0xFF - checksum + 1; if(checksum != atoi_b16 (&buffer[buffidx-3])) do_ACKLOD = FALSE; else { if(line_type == 0) { // Loops through all of the data and stores it in data // The last 2 bytes are the check sum, hence buffidx-3 for(i = 9,dataidx=0; i < buffidx-3; i += 2) data[dataidx++]=atoi_b16(&buffer[i]); rom_w(addr, data, count); } else if(line_type == 4) h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11])); } } } if(do_ACKLOD) usb_cdc_putc (ACKLOD); usb_cdc_putc(XON); } usb_cdc_putc(ACKLOD); usb_cdc_putc(XON); delay_ms(2000); //give time for packet to flush reset_cpu(); }