void putMessage(MessageType msgType, uint16_t msgLength, uint16_t flags, const uint8_t *msg) { static uint32_t curId = 0; // Nasty way MsgHeader header; header.type = (uint16_t)msgType; header.flags = flags; header.length = msgLength; header.id = curId; header.crc = calcCrc16((uint8_t *)&header + 2, sizeof(MsgHeader) - 2); header.crc = calcCrc16(msg, msgLength, header.crc); curId++; // Start the message UARTputc(UART_PORT, '#'); // Send the message header writeHex((uint8_t *)&header, sizeof(header)); // Send the message writeHex(msg, msgLength); // End the message UARTputc(UART_PORT, '!'); }
static void dump_sg(struct sg_t *sg ) { write( DEFUART, "data " ); writeHex( DEFUART, (unsigned)sg->data ); write( DEFUART, ", len 0x" ); writeHex( DEFUART, sg->length ); write( DEFUART, ", offs 0x" ); writeHex( DEFUART, sg->offset ); write( DEFUART, "\r\n" ); }
Payload Status::getStatusPayload() { Payload s; writeHex(s.motor, 5, motor.getCurrentPosition()); writeHex(s.motorState, 1, motor.isMoving() ? 1 : 0); writeTemp(s.scopeTemp, scopeTemp.lastValue); writeTemp(s.extTemp, meteoTemp.lastTemperature()); writeHum(s.extHum, meteoTemp.lastHumidity()); writeVolt(s.battery, voltmeter.lastValue()); writeHex(s.heater, 2, resistor.pct); writeHex(s.filterwheel, 5, filterWheelMotor.getCurrentPosition()); s.filterwheelState = filterWheelMotor.getProtocolStatus(); return s; }
static unsigned fillOutput(unsigned epNum, struct transmitRequest_t *tx) { if( !isValidRamPtr(tx) ){ write( DEFUART, "Invalid tx ptr: 0x" ); writeHex( DEFUART, (unsigned long)tx ); write( DEFUART, "\r\n" ); reboot(); } assert( tx->txNext ); // or how did we get here? // // 2 cases here: // start of new message - check flags and send app id if necessary // continuing in same message - send data // // The second is performed in either case // unsigned max = endpointMaxSize[epNum]; if( ( tx->txStart == tx->txNext ) && ( 0 == tx->txStart->offset ) && ( tx->flags & NEEDAPPID ) ){ unsigned i ; struct appHeader_t header ; tx->flags &= ~NEEDAPPID ; unsigned char const *next = (unsigned char *)&header ; header.bd = '\xbd' ; header.appId = tx->flags & APPID_MASK ; header.length = sg_len(tx->txStart); unsigned char volatile *const fifo = (unsigned char *)&UDP->UDP_FDR[epNum]; for( i = 0 ; i < sizeof(header); i++ ){ *fifo = *next++ ; } // send header max -= sizeof(header); DEBUGMSG( "appId 0x" ); DEBUGHEXCHAR( header.appId ); DEBUGMSG( ", len 0x" ); DEBUGHEX(header.length); DEBUGMSG("\r\n" ); } unsigned total = 0 ; while( ( 0 < max ) && !SG_DONE(tx->txNext) ){ struct sg_t *sg = tx->txNext ; unsigned char *data = sg->data + sg->offset ; unsigned i ; unsigned len = SG_LEFT(sg); if(len>max) len = max ; unsigned char volatile *const fifo = (unsigned char *)&UDP->UDP_FDR[epNum]; for( i = 0 ; i < len ; i++ ) *fifo = *data++ ; sg->offset += len ; max -= len ; total += len ; if( SG_DONE(sg) ){ tx->txNext++ ; if(SG_END(tx->txNext)) break ; } // more space for data } return total ; }
static void writeVolt(char * buffer, float hum) { if (hum == NAN) { writeBlank(buffer, 3); } unsigned long scaledValue = round(hum * 100.0); writeHex(buffer, 3, scaledValue); }
void dumpEP(unsigned epNum){ struct endpointDetails_t const *ep = connections+epNum ; write( DEFUART, "------> ep details\r\n" ); write( DEFUART, "cb 0x" ); writeHex( DEFUART, (unsigned)ep->rx_callback ); write( DEFUART, "\r\n" ); write( DEFUART, "dat 0x" ); writeHex( DEFUART, (unsigned)ep->rx_data ); write( DEFUART, "\r\n" ); write( DEFUART, "rxop 0x" ); writeHex( DEFUART, (unsigned)ep->rx_opaque ); write( DEFUART, "\r\n" ); write( DEFUART, "ping 0x" ); writeHexChar( DEFUART, ep->pingPong ); write( DEFUART, "\r\n" ); write( DEFUART, "txAdd 0x" ); writeHexChar( DEFUART, ep->txAdd ); write( DEFUART, "\r\n" ); write( DEFUART, "txTake 0x" ); writeHexChar( DEFUART, ep->txTake ); write( DEFUART, "\r\n" ); write( DEFUART, "txState 0x" ); writeHexChar( DEFUART, ep->txState ); write( DEFUART, "\r\n" ); unsigned i = ep->txTake ; while( i != ep->txAdd ){ write( DEFUART, "[" ); writeHexChar( DEFUART, i ); write( DEFUART, "] == \n " ); struct transmitRequest_t const *tx = ep->txQueue+i ; write( DEFUART, "flags 0x" ); writeHexChar( DEFUART, tx->flags ); write( DEFUART, "\r\n " ); write( DEFUART, "start 0x" ); writeHex( DEFUART, (unsigned)tx->txStart ); write( DEFUART, "\r\n " ); if( tx->txStart ){ dump_sg( tx->txStart ); } write( DEFUART, "next 0x" ); writeHex( DEFUART, (unsigned)tx->txNext ); write( DEFUART, "\r\n " ); if( tx->txNext && ( tx->txNext != tx->txStart ) ){ dump_sg( tx->txStart ); } write( DEFUART, "cb 0x" ); writeHex( DEFUART, (unsigned)tx->callback ); write( DEFUART, "\r\n " ); write( DEFUART, "op 0x" ); writeHex( DEFUART, (unsigned)tx->opaque ); write( DEFUART, "\r\n" ); i++ ; if( i >= MAXTX_ENTRIES ){ i = 0 ; } } }
static void writeTemp(char * buffer, float temp) { if (temp == NAN) { writeBlank(buffer, 4); return; } unsigned long scaledValue = round(temp * 100 + 32768); writeHex(buffer, 4, scaledValue); }
static void process(){ rxBuf[rxAdd] = '\0' ; char const *rx = rxBuf ; unsigned long addr ; rx = readHex(rx,&addr); if( rx ){ unsigned long value ; rx = readHex(rx,&value); if( rx ){ showValue(addr); unsigned width ; switch( addr & 3 ){ case 0: width = 4 ; break ; case 1: case 3: width = 1 ; break ; case 2: width = 2 ; break ; } memcpy( (void *)addr, &value, width ); showValue(addr); } else { showValue(addr); } // read request } else if( ('r' == rxBuf[0]) || ('R' == rxBuf[0]) ) reboot(); else if( ('s' == rxBuf[0]) || ('S' == rxBuf[0]) ){ write( DEFUART, "wait 10\r\n" ); delay(10); write( DEFUART, "delay done\r\n" ); } else if( ('x' == rxBuf[0]) || ('X' == rxBuf[0]) ){ unsigned i ; write( DEFUART, "saved context\r\n" ); for( i = 0 ; i < 4 ; i++ ){ writeChar( DEFUART, '[' ); writeHexChar(DEFUART,i); write(DEFUART, "] == 0x" ); writeHex(DEFUART,savedCtx[i]); write( DEFUART, "\r\n" ); } } else if( ('p' == rxBuf[0]) || ('P' == rxBuf[0]) ){ dumpEP(0); } else if( ('u' == rxBuf[0]) || ('U' == rxBuf[0]) ){ usbSpew(); } else if( '.' == rxBuf[0] ){ dumpEP(USBEP_BULKIN); } else tx( "No address (Usage is \"address value\" in hex)\r\n" ); rxAdd = 0 ; }
void WifiCreds::connect(int indicator_pin) { if (!_is_eeprom_init){ EEPROM.begin(512); _is_eeprom_init = true; } read_ssid(_ssid); read_password(_password); if (_verbose) { Serial.println(""); Serial.print("Initializing connection to "); Serial.println(_ssid); Serial.println("Send \"ssid password\" to update credentials"); Serial.println(""); } WiFi.begin(_ssid, _password); while (_is_wifi_enabled && WiFi.status() != WL_CONNECTED) { if(indicator_pin >= 0) digitalWrite(indicator_pin, LOW); delay(5); if(indicator_pin >= 0) digitalWrite(indicator_pin, HIGH); if (Serial.available() > 0){ read_from_serial(_ssid, WifiCreds::ssid_max_length); read_from_serial(_password, WifiCreds::password_max_length); if (_verbose) { Serial.println(""); Serial.println("Got new wifi credentials."); Serial.print(" - SSID: "); Serial.println(_ssid); Serial.print(" - Password: "******"."); } if (_verbose) { Serial.println(""); if (_is_wifi_enabled) { Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); WiFi.macAddress(mac); writeHex(mac[5], id, 1, 2); writeHex(mac[4], id, 4, 5); writeHex(mac[3], id, 7, 8); writeHex(mac[2], id, 10, 11); writeHex(mac[1], id, 13, 14); writeHex(mac[0], id, 16, 17); Serial.print("MAC address: "); Serial.println(id); } else { Serial.println("Skipping wifi setup"); } } if (_is_wifi_enabled) _is_connected = true;; }
int main(void) { int i; int j; int data; int data2=0; char in = 0; i = 0x0000000004000500; int numBad = 1; int count; long long cpi; volatile void *wptr; short leds = 0; char capInit = 0; //mv1kC1(0x9800000040000000, 0x9800000000001000); //setInterrupts(); //__writeStringLoopback("Stack TLB entry setup.\n"); __writeString("Hello World! Have a BERI nice day!\n"); //debugTlb(); //cp0Regs(); // causeTrap(); // __writeString("Came back from trap and still alive :)\n"); // sysCtrlTest(); // data = rdtscl(5); //int coreid = getCoreID(); /* if (coreid == 0) { delay(); coreCount++; } else { coreCount++; } */ while(in != 'Q') { if (in != '\n') { //if (coreid == 0) { globalReset = 0; coreFlag = 0; __writeString("\n Number of Cores in Use : "); __writeHex(coreCount); __writeString("\n Menu:\n"); __writeString(" \"F\" for floating point co-processor test.\n"); __writeString(" \"L\" for load-linked and store-conditional test.\n"); __writeString(" \"A\" for arithmetic test result.\n"); __writeString(" \"B\" array bounds checking benchmark.\n"); __writeString(" \"D\" for multiply and divide test.\n"); __writeString(" \"C\" for Count register test.\n"); __writeString(" \"M\" for eternal memory test.\n"); //__writeString(" \"N\" for networking test.\n"); __writeString(" \"V\" for framebuffer test.\n"); __writeString(" \"K\" for Capability initialization.\n"); __writeString(" \"l\" to invert LEDs.\n"); __writeString(" \"T\" for touchscreen test.\n"); __writeString(" \"q\" for quicksort boundschecking test.\n"); __writeString(" \"d\" for domain crossing benchmark.\n"); __writeString(" \"G\" for compositor test.\n"); __writeString(" \"Q\" to quit.\n"); } } in = __readUARTChar(); __writeUARTChar(in); __writeString("\n"); //__writeHex(in); //__writeString("\n"); if (in == 'F') { __writeString("Floating Point co-processor test\n"); CoProFPTest(); } if (in == 'L') { __writeString("Load-linked and store-conditional test:\n"); data = 13; data = ll(&data); data = sc(&data, 14); //__writeHex(data); __writeString(" < load-linked and store-conditional result (0)\n"); data = testNset(&data, 14); //__writeHex(data); __writeString(" < test and set result (1)\n"); } if (in == 'A') { __writeString("Arithmetic test:\n"); data = 0; data = arithmaticTest(); __writeHex(data); __writeString(" < arithmetic test result (0)\n"); } if (in == 'T') { int * tX= (int *)0x9000000005000000; int * tY= (int *)0x9000000005000004; int * tDown= (int *)0x9000000005000008; __writeString("X:"); data = *tX; __writeHex(data); __writeString(" Y:"); data = *tY; __writeHex(data); __writeString(" Down:"); data = *tDown; __writeHex(data); __writeString("\n"); } if (in == 'G') { __writeString("Compositor test:\n"); } if (in == 'D') { numBad = 1; __writeString("Multiply and divide test.\n"); for (i = -10; i < 10; i++) { data = numBad * i; __writeHex(numBad); __writeString(" * "); __writeHex(i); __writeString(" = "); __writeHex(data); __writeString("\n"); if (i!=0) data2 = data / i; __writeHex(data); __writeString(" / "); __writeHex(i); __writeString(" = "); __writeHex(data2); __writeString("\n"); __writeString("\n"); if (data == 0) data = 1; numBad = data; } } if (in == 'M') { __writeString("Memory test:\n"); i = 0; while(1) { count = getCount(); //__writeString("count:"); //__writeHex(count); //__writeString("\n"); int idx = 0; for (j=0; j<0x4000; j++) { idx = i+j; ((volatile int *)DRAM_BASE)[idx] = DRAM_BASE + (idx<<2); } for (j=0; j<0x4000; j++) { idx = i+j; data = ((volatile int *)DRAM_BASE)[idx]; if (data != (int)(DRAM_BASE + (idx<<2))) { //__writeHex((int)(DRAM_BASE + (idx<<2))); //__writeString(" = "); //__writeHex(data); //__writeString("?\n"); numBad++; } } cpi = getCount() - count; //__writeString("newCount - count:"); //__writeHex(cpi); //__writeString("\n"); __writeHex((int)(DRAM_BASE + (idx<<2))); __writeString(" = "); __writeHex(data); __writeString("?\n"); if (numBad == 0) { __writeString("All good! \n"); } else { __writeHex(numBad); __writeString(" were bad :(\n"); numBad = 0; } cpi = (cpi*1000); //__writeString("diff*1000:"); //__writeHex(cpi); //__writeString("\n"); // 8 instructions in the first loop, 12 in the second. cpi = cpi/((8+12)*0x4000); __writeString("CPI of "); __writeDigit(cpi); __writeString("\n"); i+=0x4000; if (i > 0x07000000) i = 0; } } if (in == 'C') { __writeString("Count Register Test:\n"); for(i=0;i<10;i++) { data = ((volatile int *)MIPS_PHYS_TO_UNCACHED(CHERI_COUNT))[0]; __writeHex(data); __writeString(", "); } __writeString("\n"); } if (in == 'K') { if (capInit==0) { FBIncBase(0x9000000004000000); long length = FBGetLeng(); length = length - 800*600*2; FBDecLeng(length); capInit = 1; } __writeString("C4.base= ");__writeHex(FBGetBase());__writeString("\n"); __writeString("C4.length= ");__writeHex(FBGetLeng());__writeString("\n"); CapRegDump(); } if (in == 'V') { int color = 0x8888; int x = 50; int y = 50; int length = 75; int height = 50; long frameBuff = 0x9000000004000000; for (x=200; x<500; x+=100) { for (y=300; y<500; y+=75) { draw3DRect(color, x, y, length, height); } } for (i=0; i<(800*600/4); i++) { FBSDR(0x0C63F80007E0001F,i<<3); } int offset = y*800 + x; int addOff; int totOff; for (i=0; i<(800*600); i++) { ((volatile short*)frameBuff)[i] = i; } for (i=0; i<height; i++) { for (j=0; j<length; j++) { addOff = (800*i) + j; totOff = (offset+addOff); ((volatile short*)frameBuff)[totOff] = color; } } } if (in == 'l') { leds = ~leds; IO_WR(CHERI_LEDS,leds); } if (in == 'N') { wptr = (void *)CHERI_NET_RX; i = *(volatile int *)wptr; __writeString("After accessing CHERI_NET_RX, read:\n"); __writeDigit(i); i = 0xabcd; wptr = (void *)CHERI_NET_TX; __writeString("Before writing 123 to CHERI_NET_TX\n"); *((volatile int *)CHERI_NET_TX) = i; __writeString("After writing 123 to CHERI_NET_TX\n"); } if (in == 'B') { arrayBench(); } if (in == 'q') { doQuicksort(); } if (in == 'd') { armArray(); } // ADDED >> if (in == 'X') { int A[SORT_SIZE]; writeString("Branch Exercise:\n"); fillArray(A, SORT_SIZE/2, 1000); bubbleSort(A, SORT_SIZE/2); writeString("Finished Bubble Sort!\n"); for (i = 0; i<SORT_SIZE/2; i+= SORT_SIZE/2/32) { writeHex(i); writeString(" = "); writeHex(A[i]); writeString("\n"); } fillArray(A, SORT_SIZE, 1234); quickSort(A, 0, SORT_SIZE); writeString("Finished Quick Sort!\n"); for (i = 0; i<SORT_SIZE; i+= SORT_SIZE/32) { writeHex(i); writeString(" = "); writeHex(A[i]); writeString("\n"); } writeString("Searching for each element...\n"); for (j = 0; j<4; j++) { for (i = 0; i<SORT_SIZE; i++) { binarySearch(A, A[i], 0, SORT_SIZE); } } writeString("Searching Done.\n"); writeString("Starting Modular Eponentiation\n"); for (i = 0; i<SORT_SIZE/4; i++) { writeHex(modExp(i,0xAAAAAAAAAAAAAAAA)); writeString("\n"); } } // ADDED << //debugRegs(); } return 0; }
void apply() override { writeHex(0x102BFD78 + 30*4, "00 09"); // marks Kukri as Martial in the sense that picking "Martial Weapons Proficiency" will now list Kukri // see rest of fix in weapon.cpp IsMartialWeapon }
void apply() override { writeHex(0x100F9B70, "6A 02"); }
void apply() override { writeHex(0x1008D80E, "90 90 90 90 90"); }
void apply() override { writeHex(0x10278078, "73 69 7A 65 5F 63 6F 6C 6F 73 73 61 6C"); }
void apply() override{ // breakfree_on_entanglement_fix.txt writeHex(0x100D4259, "90 90 90 90 90 90"); // caravan_encounter_fix.txt // looks like it has been updated since then too! 13D6 instead of 13D5 writeHex(0x1006ED1E, "04"); writeHex(0x1006FE1B + 1, "D6 13"); writeHex(0x1007173C + 1, "D6 13"); writeHex(0x1012BDF2 + 1, "D6 13"); writeHex(0x1012C1EC + 1, "D6 13"); writeHex(0x1012C361 + 1, "D6 13"); // D20STDF_fix.txt writeHex(0x100B8454, "BA 00000000"); writeHex(0x100B8471 , "8D4A 0D"); // heavy_armor_prof_fix.txt writeHex(0x1007C49F, "6A 06"); // NPC_usePotion_AoO_fix.txt writeHex(0x10098DE7+6, "44000000"); // rep fallen paladin fix writeHex(0x1005481A, "00"); // rgr_fav_enemy_fix.txt writeHex(0x101AD9BE, "90 90"); // sp125_discern_lies_fix.txt // looks like this was actually forgotten to be implemented in the Co8 DLL writeHex(0x102D5454, "1E 00 00 00 22 00 00 00 00 2B 0D 10 00 00 00 00"); }
void initLEDBoard() { //Initialize the port expander //Switches as inputs peCommand = getPECommand4(P12_15_CONFIG, INPUT, INPUT, INPUT, INPUT); //Test mode off ssCommand = getPECommand1(TEST, 0); sendCommand2(peCommand, ssCommand); peCommand = getPECommand4(P16_19_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR); ssCommand = getPECommand1(INTENSITY, 8); sendCommand2(peCommand, ssCommand); peCommand = getPECommand4(P20_23_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR); ssCommand = getPECommand1(SCANLIMIT, 7); sendCommand2(peCommand, ssCommand); peCommand = getPECommand4(P24_27_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR); ssCommand = getPECommand1(DECODE, 0); sendCommand2(peCommand, ssCommand); peCommand = getPECommand4(P28_31_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR); ssCommand = getPECommand1(SSSHUTDOWN, 1); sendCommand2(peCommand, ssCommand); peCommand = getPECommand2(P16_17_CURRENT, LED_CURRENT_5, LED_CURRENT_5); ssCommand = getPECommand1(TEST, 1); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P18_19_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P20_21_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P22_23_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P24_25_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P26_27_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P28_29_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand2(P30_31_CURRENT, LED_CURRENT_5, LED_CURRENT_5); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand1(CONFIGURATION, NORMAL | INDIVIDUAL); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand1(RW_BYTE_16,0xFF); sendCommand2(peCommand, LED_NOOP); peCommand = getPECommand1(RW_BYTE_24,0xFF); sendCommand2(peCommand, LED_NOOP); //Clear the hex int i; for(i=1; i<=NUM_DIGITS; i++){ writeHex(i, 0); } }