void ows_spm() { uint8_t cmd = ows_recv(); uint16_t addr = ows_recv() << 8; addr |= ows_recv(); switch(cmd) { case 0x33: /* read program memory page */ ow_crc16_reset(); for(uint8_t i = 0; i < PGM_PAGE_SIZE; ++i) { uint8_t c = pgm_read_byte_near(addr++); ows_send(c); ow_crc16_update(c); } addr = ow_crc16_get(); ows_send(addr >> 8); ows_send(addr & 0xFF); break; case 0x3C: /* fill program memory page write buffer, return crc */ ow_crc16_reset(); for(uint8_t i = 0; i < PGM_PAGE_SIZE; i += 2) { uint16_t w; uint8_t c = ows_recv(); ow_crc16_update(c); w = c << 8; c = ows_recv(); w |= c; boot_page_fill(addr + i, w); } addr = ow_crc16_get(); ows_send(addr >> 8); ows_send(addr & 0xFF); break; case 0x5A: /* write page buffer */ write_page(addr); ows_send(0); ows_send(0); ows_send(0); break; case 0xA5: /* read eeprom page */ break; case 0xAA: /* write eeprom page */ break; case 0xC3: /* jump to address */ break; case 0xCC: /* read device id and page size */ break; } }
bool DS2408::updateCRC(){ // ((sDS2408*)(this->memory))->CRC = crc16( this->memory, 11 ); ow_crc16_reset(); for (int i=0;i<11;i++) ow_crc16_update(this->memory[i]); ((sDS2408*)(this->memory))->CRC = ow_crc16_get(); //Serial.print("CRC="); //Serial.println( ((sDS2408*)(this->memory))->CRC, HEX); }
bool DS2450::duty(OneWireHub * hub) { uint16_t memory_address; uint16_t memory_address_start; uint8_t b; uint16_t crc; ow_crc16_reset(); uint8_t done = hub->recv(); switch (done) { // READ MEMORY case 0xAA: // Cmd ow_crc16_update(0xAA); // Adr1 b = hub->recv(); ((uint8_t*)&memory_address)[0] = b; ow_crc16_update(b); // Adr2 b = hub->recv(); ((uint8_t*)&memory_address)[1] = b; ow_crc16_update(b); memory_address_start = memory_address; for (int i=0;i<8;i++){ uint8_t b = this->memory[memory_address+i]; hub->send(b); } crc = ow_crc16_get(); hub->send(((uint8_t*)&crc)[0]); hub->send(((uint8_t*)&crc)[1]); #ifdef DEBUG_DS2450 Serial.print("DS2450 : READ MEMORY : "); Serial.println(memory_address_start, HEX); #endif break; default: #ifdef DEBUG_hint Serial.print("DS2450="); Serial.println(done, HEX); #endif break; } return TRUE; }
bool DS2423::duty(OneWireHub * hub) { uint16_t memory_address; uint16_t memory_address_start; uint8_t b; uint16_t crc; ow_crc16_reset(); uint8_t done = hub->recv(); switch (done) { // Read Memory + Counter case 0xA5: ow_crc16_update(0xA5); // Adr1 b = hub->recv(); ((uint8_t*)&memory_address)[0] = b; ow_crc16_update(b); // Adr2 b = hub->recv(); ((uint8_t*)&memory_address)[1] = b; ow_crc16_update(b); memory_address_start = memory_address; // data for (int i=0;i<32;i++){ hub->send(0xff); ow_crc16_update(0xff); } // cnt hub->send(0x00); ow_crc16_update(0x00); hub->send(0x00); ow_crc16_update(0x00); hub->send(0x00); ow_crc16_update(0x00); hub->send(0x00); ow_crc16_update(0x00); // zero hub->send(0x00); ow_crc16_update(0x00); hub->send(0x00); ow_crc16_update(0x00); hub->send(0x00); ow_crc16_update(0x00); hub->send(0x00); ow_crc16_update(0x00); // crc crc = ow_crc16_get(); hub->send(((uint8_t*)&crc)[0]); hub->send(((uint8_t*)&crc)[1]); ow_crc16_reset(); #ifdef DEBUG_DS2423 Serial.print("DS2423 : Read Memory + Counter : "); Serial.println(memory_address_start, HEX); #endif break; default: #ifdef DEBUG_hint Serial.print("DS2423="); Serial.println(done, HEX); #endif break; } return TRUE; }
void ows_process_cmds() { uint16_t memory_address; uint8_t b; ow_crc16_reset(); switch(ows_recv()) { case 0xAA: /* READ MEMORY */ ow_crc16_update(0xAA); b = ows_recv(); ((uint8_t*)&memory_address)[0] = b; ow_crc16_update(b); b = ows_recv(); ((uint8_t*)&memory_address)[1] = b; ow_crc16_update(b); for(;;) { uint8_t b = ((uint8_t*)&memory)[memory_address]; ows_send(b); ow_crc16_update(b); if(errno) break; if((memory_address & 0x0F) == 0x0F) /* end of page */ { uint16_t crc = ow_crc16_get(); ows_send(((uint8_t*)&crc)[0]); ows_send(((uint8_t*)&crc)[1]); ow_crc16_reset(); } ++memory_address; if(memory_address >= sizeof(memory)) while(! errno) ows_send(0xFF); } break; case 0x55: /* WRITE MEMORY */ ow_crc16_update(0x55); b = ows_recv(); ((uint8_t*)&memory_address)[0] = b; ow_crc16_update(b); b = ows_recv(); ((uint8_t*)&memory_address)[1] = b; ow_crc16_update(b); for(;;) { b = ows_recv(); if(errno) break; ow_crc16_update(b); uint16_t crc = ow_crc16_get(); ows_send(((uint8_t*)&crc)[0]); ows_send(((uint8_t*)&crc)[1]); ((uint8_t*)&memory)[memory_address] = b; ows_send(b); if(errno) break; ++memory_address; ow_crc16_reset(); ow_crc16_update(((uint8_t*)&memory_address)[0]); ow_crc16_update(((uint8_t*)&memory_address)[1]); } break; case 0x3C: /* CONVERT */ break; default: break; } }