void ConnectUsbtinyPort(struct UPort *up) { Assert(up->port.kind == 'u'); // Ws(" -- ConnectUsbtinyPort entry. "); WriteUPort(up); Ws("UsbTiny"); Wd(up->port.index,1); Wc(' '); jmp_buf oldFailPoint; memcpy(oldFailPoint, FailPoint, sizeof(FailPoint)); if (setjmp(FailPoint)) { // Wsl(" -- Fail caught in ConnectUsbtinyPort."); up->port.baud = -1; } else { up->port.baud = 0; if (!up->handle) {up->handle = usb_open(up->device);} if (!up->handle) {PortFail(up, "Couldn't open UsbTiny port.");} DigisparkBreakAndSync(up); } memcpy(FailPoint, oldFailPoint, sizeof(FailPoint)); Ws("\r \r"); // Ws(" -- ConnectUsbtinyPort complete. "); WriteUPort(up); }
void WSramAddr(int addr) { if (SramSymbol[addr]) { Ws(SramSymbol[addr]); Ws(" ($"); Wx(addr,1); Wc(')'); } else { Wc('$'); Wx(addr,1); } }
void ConnectFirstPort(void) { DwFindPort(0,-1,0); if (CurrentPort >= 0) { Assert(Ports[CurrentPort]->character >= 0); Ws("Connected to "); DescribePort(CurrentPort); } }
void Full_Help(void) { strcpy(hstr, colour_str(LIGHTGREEN, BLUE)); /* Top row */ strncat(hstr, locate_str(1, 10), 80); strncat(hstr, (char *)"\xDA", 80); strncat(hstr, hLine_str(58), 80); strncat(hstr, (char *)"\xBF", 80); PUTSTR(chartran(hstr)); Ws(2); PUTSTR(chartran(hstr)); Ls(3); strncat(hstr, colour_str(YELLOW, BLUE), 80); strncat(hstr, padleft((char *)" Editor Help", 58, ' '), 80); Rs(); PUTSTR(chartran(hstr)); Ws(4); PUTSTR(chartran(hstr)); Hl( 5, (char *)"Ctrl-S or LeftArrow - Cursor left"); Hl( 6, (char *)"Ctrl-D or RightArrow - Cursor right"); Hl( 7, (char *)"Ctrl-E or UpArrow - Cursor up"); Hl( 8, (char *)"Ctrl-X or DownArrow - Cursor down"); Hl( 9, (char *)"Ctrl-V or Insert - Insert or Overwrite"); Hl(10, (char *)"Ctrl-N - Insert line"); Hl(11, (char *)"Ctrl-Y - Delete line"); Ws(12); PUTSTR(chartran(hstr)); Hl(13, (char *)"Ctrl-L - Refresh screen"); Hl(14, (char *)"Ctrl-R - Read from file"); Ws(15); PUTSTR(chartran(hstr)); strcpy(hstr, locate_str(16,10)); strncat(hstr, (char *)"\xC0", 80); strncat(hstr, hLine_str(58), 80); strncat(hstr, (char *)"\xD9", 80); PUTSTR(chartran(hstr)); }
void WriteFlash(u16 addr, const u8 *buf, int length) { Assert(addr + length <= FlashSize()); Assert(length >= 0); if (length == 0) return; DwGetRegs(0, R, 2); // Cache R0 and R1 int pageOffsetMask = PageSize()-1; int pageBaseMask = ~ pageOffsetMask; if (addr & pageOffsetMask) { // buf starts in the middle of a page int partBase = addr & pageBaseMask; int partOffset = addr & pageOffsetMask; int partLength = min(PageSize()-partOffset, length); DwReadFlash(partBase, PageSize(), pageBuffer); memcpy(pageBuffer+partOffset, buf, partLength); WriteFlashPage(partBase, pageBuffer); addr += partLength; buf += partLength; length -= partLength; } Assert(length == 0 || ((addr & pageOffsetMask) == 0)); // Write whole pages while (length >= PageSize()) { WriteFlashPage(addr, buf); addr += PageSize(); buf += PageSize(); length -= PageSize(); } // Write any remaining partial page if (length) { Assert(length > 0); Assert(length < PageSize()); Assert((addr & pageOffsetMask) == 0); DwReadFlash(addr, PageSize(), pageBuffer); memcpy(pageBuffer, buf, length); WriteFlashPage(addr, pageBuffer); } Ws(" \r"); // Restore cached registers R0 and R1 DwSetRegs(0, R, 2); }
void handle_client(int connfd) { char cmd[BUFSZ]; ssize_t r; while (1) { r = read_command(connfd, cmd, sizeof(cmd)); if (r < 1) { Ws("Error reading command. Error code: "); Wd(r,1); Fail("!"); } Ws("Got: "); Ws(cmd); Wl(); if (cmd[0] == 'k') break; // gdb quitting handle_command(connfd, cmd); } Close((FileHandle)connfd); return; }
void digisparkUSBSendBytes(struct UPort *up, u8 state, char *out, int outlen) { int tries = 0; int status = usb_control_msg(up->handle, OUT_TO_LW, 60, state, 0, out, outlen, USB_TIMEOUT); while ((tries < 200) && (status <= 0)) { // Wait for previous operation to complete tries++; delay(5); status = usb_control_msg(up->handle, OUT_TO_LW, 60, state, 0, out, outlen, USB_TIMEOUT); } if (status < outlen) {Ws("Failed to send bytes to AVR, status "); Wd(status,1); PortFail(up, "");} delay(3); // Wait at least until digispark starts to send the data. }
void CContextLocaAppUi::SettingChanged(TInt Setting) { if (Setting==SETTING_LOGGING_ENABLE) { TApaTaskList tl(Ws()); TApaTask booktask=tl.FindApp(KUidcontextbook); if (booktask.Exists()) { booktask.SendSystemEvent(EApaSystemEventShutdown); } TBool logging; Settings().GetSettingL(SETTING_LOGGING_ENABLE, logging); if (iLoggingRunning) { if (!logging) { iLoggingRunning->SetCurrentState( EMbmContextlocaL_not, EMbmContextlocaL_not ); } else { iLoggingRunning->SetCurrentState( EMbmContextlocaL, EMbmContextlocaL ); } } } }
void CCustomStep::InitialiseL() { CAnimationTestStep::InitialiseL(); ANIM_INFO1(_L("Begin test SYNCH")); TInt winborder = 2; iWinSize = Screen()->SizeInPixels(); iWinSize.iWidth /= 2; iWinPosition = TPoint(iWinSize.iWidth + winborder, winborder); iWinSize.iWidth -= winborder * 2; iWinSize.iHeight -= winborder * 2; iWinRect = TRect(iWinPosition, iWinSize); iWin = new (ELeave) CCustomStepAnimationWindow(Ws(), *GroupWin(), *Gc()); iWin->Window()->SetRequiredDisplayMode(EColor256); iWin->Window()->SetExtent(iWinPosition, iWinSize); iWin->Window()->SetBackgroundColor(iBackgroundColor1); iWin->Window()->SetVisible(ETrue); iWin->Window()->Activate(); }
void DescribePort(int i) { Assert(i < PortCount); if (Ports[i]->character < 0) { Ws("Unknown device "); } else { Ws(Characteristics[Ports[i]->character].name); } Ws(" on "); if (Ports[i]->kind == 's') { #if windows Ws("COM"); #elif defined(__APPLE__) Ws("/dev/tty.usbserial"); #else Ws("/dev/ttyUSB"); #endif } else { Ws("UsbTiny"); } Wd(Ports[i]->index,1); Ws(" at "); Wd(Ports[i]->baud,1); Wsl(" baud."); }
void DigisparkBreakAndSync(struct UPort *up) { // Ws(" -- DigisparkBreakAndSync entry. "); WriteUPort(up); for (int tries=0; tries<25; tries++) { // Tell digispark to send a break and capture any returned pulse timings int status = usb_control_msg(up->handle, OUT_TO_LW, 60, 33, 0, 0, 0, USB_TIMEOUT); if (status < 0) { if (status == -1) { Wsl("Access denied sending USB message to Digispark. Run dwdebug as root, or add a udev rule such as"); Wsl("file /etc/udev/rules.d/60-usbtiny.rules containing:"); Wsl("SUBSYSTEM==\"usb\", ATTR{idVendor}==\"1781\", ATTR{idProduct}==\"0c9f\", GROUP=\"plugdev\", MODE=\"0666\""); Wsl("And make sure that you are a member of the plugdev group."); } else { Ws("Digispark did not accept 'break and capture' command. Error code "); Wd(status,1); Wsl("."); } PortFail(up, ""); } else { delay(120); // Wait while digispark sends break and reads back pulse timings if (SetDwireBaud(up)) {return;} } Wc('.'); Wflush(); } Wl(); PortFail(up, "Digispark/LittleWire/UsbTiny could not capture pulse timings after 25 break attempts."); }
void DumpConfig(void) { u8 cb; u8 hfuse; u8 efuse; // Show Known device info Ws(Name()); Wsl("."); Ws("IO regs: "); Wx(32,2); Ws(".."); Wx(IoregSize()+31,2); Ws(" ("); Wd(IoregSize(),1); Wsl(" bytes)."); Ws("SRAM: "); Wx(IoregSize()+32,3); Ws(".."); Wx(31 + IoregSize() + SramSize(), 3); Ws(" ("); Wd(SramSize(),1); Wsl(" bytes)."); Ws("Flash: 0000.."); Wx(FlashSize()-1, 4); Ws(" ("); Wd(FlashSize(),1); Wsl(" bytes)."); Ws("EEPROM: 000.."); Wx(EepromSize()-1, 3); Ws(" ("); Wd(EepromSize(),1); Wsl(" bytes)."); // Dump uninterpreted fuse and lock bit values ReadConfigBits(0, &cb); Ws("Fuses: low "); Wx(cb,2); Wflush(); ReadConfigBits(3, &hfuse); Ws(", high "); Wx(hfuse,2); Wflush(); ReadConfigBits(2, &efuse); Ws(", extended "); Wx(efuse,2); Wflush(); ReadConfigBits(1, &cb); Ws(", lock bits "); Wx(cb,2); Wsl("."); // Interpret boot sector information if (BootFlags()) { int bootsize = 0; int bootvec = 0; switch (BootFlags()) { case 1: bootsize = 128 << (3 - ((efuse/2) & 3)); bootvec = efuse & 1; break; // atmega88 & 168 case 2: bootsize = 256 << (3 - ((hfuse/2) & 3)); bootvec = hfuse & 1; break; // atmega328 default: Fail("Invalid BootFlags global data setting."); } bootsize *= 2; // Bootsize is in words but we report in bytes. Ws(" Boot space: "); Wx(FlashSize()-bootsize, 4); Ws(".."); Wx(FlashSize()-1, 4); Ws(" ("); Wd(bootsize,1); Wsl(" bytes)."); Ws(" Vectors: "); if (bootvec) Wsl("0."); else {Wx(FlashSize()-bootsize, 4); Wsl(".");} } }
void ShowPageStatus(u16 a, char *msg) { Ws("$"); Wx(a,4); Ws(" - $"); Wx(a+PageSize()-1,4); Wc(' '); Ws(msg); Ws(". "); Wr(); }