/*! * \brief status callback used to print address given by DHCP */ void status_callback(struct netif *netif) { char mess[25]; if (netif_is_up(netif)) { display_print("Network up"); strcpy(mess,"IP="); strcat(mess,inet_ntoa(*(struct in_addr*)&(netif->ip_addr))); display_print(mess); } else { display_print("Network down"); } }
/*! * \brief set ethernet config */ static void prvEthernetConfigureInterface(void * param) { struct ip_addr xIpAddr, xNetMask, xGateway; extern err_t ethernetif_init( struct netif *netif ); unsigned char MacAddress[6]; /* Default MAC addr. */ MacAddress[0] = ETHERNET_CONF_ETHADDR0; MacAddress[1] = ETHERNET_CONF_ETHADDR1; MacAddress[2] = ETHERNET_CONF_ETHADDR2; MacAddress[3] = ETHERNET_CONF_ETHADDR3; MacAddress[4] = ETHERNET_CONF_ETHADDR4; MacAddress[5] = ETHERNET_CONF_ETHADDR5; /* pass the MAC address to MACB module */ vMACBSetMACAddress( MacAddress ); #if defined(DHCP_USED) xIpAddr.addr = 0; xNetMask.addr = 0; xNetMask.addr = 0; #else /* Default ip addr. */ IP4_ADDR( &xIpAddr,ETHERNET_CONF_IPADDR0,ETHERNET_CONF_IPADDR1,ETHERNET_CONF_IPADDR2,ETHERNET_CONF_IPADDR3 ); /* Default Subnet mask. */ IP4_ADDR( &xNetMask,ETHERNET_CONF_NET_MASK0,ETHERNET_CONF_NET_MASK1,ETHERNET_CONF_NET_MASK2,ETHERNET_CONF_NET_MASK3 ); /* Default Gw addr. */ IP4_ADDR( &xGateway,ETHERNET_CONF_GATEWAY_ADDR0,ETHERNET_CONF_GATEWAY_ADDR1,ETHERNET_CONF_GATEWAY_ADDR2,ETHERNET_CONF_GATEWAY_ADDR3 ); #endif /* add data to netif */ netif_add( &MACB_if, &xIpAddr, &xNetMask, &xGateway, NULL, ethernetif_init, ethernet_input ); /* make it the default interface */ netif_set_default( &MACB_if ); /* Setup callback function for netif status change */ netif_set_status_callback(&MACB_if, status_callback); /* bring it up */ #if defined(DHCP_USED) display_print("LwIP: DHCP Started"); dhcp_start( &MACB_if ); #else display_print("LwIP: Static IP Address Assigned"); netif_set_up( &MACB_if ); #endif }
void display_gui_bootup_line (const char* string, uint16_t wait) { display_print (string); display_flip(); display_gui_sleep (wait); }
void intrrupt_TMR0IF(void) { if (printON) { display_print(dinamic); dinamic++; if (dinamic >= DISPLAY_WIDTH)dinamic = 0; } }
void print(uint8_t value) { if (value) { printON = 1; } else { printON = 0; display_print(0x08); } }
/*********************************************************************** * dbg_exception_prolog * * Examine exception and decide if interactive mode is entered(return TRUE) * or exception is silently continued(return FALSE) * is_debug means the exception is a breakpoint or single step exception */ static unsigned dbg_exception_prolog(BOOL is_debug, BOOL first_chance, const EXCEPTION_RECORD* rec) { ADDRESS64 addr; BOOL is_break; char hexbuf[MAX_OFFSET_TO_STR_LEN]; memory_get_current_pc(&addr); break_suspend_execution(); dbg_curr_thread->excpt_record = *rec; dbg_curr_thread->in_exception = TRUE; if (!is_debug) { switch (addr.Mode) { case AddrModeFlat: dbg_printf(" in 32-bit code (%s)", memory_offset_to_string(hexbuf, addr.Offset, 0)); break; case AddrModeReal: dbg_printf(" in vm86 code (%04x:%04x)", addr.Segment, (unsigned) addr.Offset); break; case AddrMode1616: dbg_printf(" in 16-bit code (%04x:%04x)", addr.Segment, (unsigned) addr.Offset); break; case AddrMode1632: dbg_printf(" in 32-bit code (%04x:%08lx)", addr.Segment, (unsigned long) addr.Offset); break; default: dbg_printf(" bad address"); } dbg_printf(".\n"); } /* this will resynchronize builtin dbghelp's internal ELF module list */ SymLoadModule(dbg_curr_process->handle, 0, 0, 0, 0, 0); if (is_debug) break_adjust_pc(&addr, rec->ExceptionCode, first_chance, &is_break); /* * Do a quiet backtrace so that we have an idea of what the situation * is WRT the source files. */ stack_fetch_frames(); if (is_debug && !is_break && break_should_continue(&addr, rec->ExceptionCode)) return FALSE; if (addr.Mode != dbg_curr_thread->addr_mode) { const char* name = NULL; switch (addr.Mode) { case AddrMode1616: name = "16 bit"; break; case AddrMode1632: name = "32 bit"; break; case AddrModeReal: name = "vm86"; break; case AddrModeFlat: name = "32 bit"; break; } dbg_printf("In %s mode.\n", name); dbg_curr_thread->addr_mode = addr.Mode; } display_print(); if (!is_debug) { /* This is a real crash, dump some info */ be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); stack_info(); be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context); stack_backtrace(dbg_curr_tid); } else { static char* last_name; static char* last_file; char buffer[sizeof(SYMBOL_INFO) + 256]; SYMBOL_INFO* si = (SYMBOL_INFO*)buffer; void* lin = memory_to_linear_addr(&addr); DWORD64 disp64; IMAGEHLP_LINE il; DWORD disp; si->SizeOfStruct = sizeof(*si); si->MaxNameLen = 256; il.SizeOfStruct = sizeof(il); if (SymFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp64, si) && SymGetLineFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp, &il)) { if ((!last_name || strcmp(last_name, si->Name)) || (!last_file || strcmp(last_file, il.FileName))) { HeapFree(GetProcessHeap(), 0, last_name); HeapFree(GetProcessHeap(), 0, last_file); last_name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(si->Name) + 1), si->Name); last_file = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(il.FileName) + 1), il.FileName); dbg_printf("%s () at %s:%u\n", last_name, last_file, il.LineNumber); } } } if (!is_debug || is_break || dbg_curr_thread->exec_mode == dbg_exec_step_over_insn || dbg_curr_thread->exec_mode == dbg_exec_step_into_insn) { ADDRESS64 tmp = addr; /* Show where we crashed */ memory_disasm_one_insn(&tmp); } source_list_from_addr(&addr, 0); return TRUE; }
int main(int argc, char *argv[]) { key_t shmkey; int shmid, shmsize; int i, j, k, t = 0, c = 0; int pause = PAUSE, again = 1; int setupIndex = -1; int minSampleIndex = -1, minMessageIndex = -1; int maxSampleIndex = -1, maxMessageIndex = -1; int minSampleValue = INT_MAX, minMessageValue = INT_MAX; int maxSampleValue = INT_MIN, maxMessageValue = INT_MIN; int maxCountCleared = 0, countCleared = 0, countLoop = 0; int countInvalid = 0, countData = 0, countSetup = 0, countCancel = 0, countUnknown = 0; for (i=0; i<MAXNUMTRIGCHAN; i++) lastValue[i] = 0; /* make the shared memory key * if ((shmkey = ftok(ACQ_MSGQ_SHMPATH, ACQ_MSGQ_SHMPROJID)) == -1) { * perror("ftok"); * exit(1); * } */ /* use the pre-defined shared memory key */ shmkey = ACQ_MSGQ_SHMKEY; /* determine the size of the shared memory buffer */ shmsize = sizeof(ACQ_MessagePacketType) * ACQ_MSGQ_SIZE; /* connect to (and possibly create) the segment */ if ((shmid = shmget(shmkey, shmsize, PERMISSION | IPC_CREAT )) == -1) { perror("shmget"); exit(1); } /* attach to the segment to get a pointer to it */ packet = shmat(shmid, (void *)0, 0); if ((char *)packet == (char *)(-1)) { perror("shmat"); exit(1); } display_start(); display_print("initializing\n"); // clear_all_except_setup(); // clear_all(); display_refresh(); while (again) { clear(); setupIndex = -1; minSampleIndex = -1, minMessageIndex = -1; maxSampleIndex = -1, maxMessageIndex = -1; minSampleValue = INT_MAX, minMessageValue = INT_MAX; maxSampleValue = INT_MIN, maxMessageValue = INT_MIN; countInvalid = 0, countData = 0, countSetup = 0, countCancel = 0, countUnknown = 0; /******************************************************************************* * collect information about all packets in the buffer *******************************************************************************/ for (i=0; i<ACQ_MSGQ_SIZE; i++) { if (i<SHOWPACKET) print_packet(i); switch (packet[i].message_type) { case ACQ_MSGQ_SETUP_COLLECTION: if (countSetup>0) { /* multiple packets with a setup are not allowed, only keep the first */ display_print("clearing superfluous setup packet at %d (setup @ %d)\n", i, setupIndex); clear_packet(i); countCleared++; break; } countSetup++; setupIndex = i; /* update the specifications that relate to trigger maintenance */ numRealChan = packet[i].data[DATASIZE-TRIGSIZE*3-MAXNUMTRIGCHAN-2]; /* update the value */ numTrigChan = packet[i].data[DATASIZE-TRIGSIZE*3-MAXNUMTRIGCHAN-1]; /* update the value */ trigChan = packet[i].data+DATASIZE-TRIGSIZE*3-MAXNUMTRIGCHAN; /* update the pointer */ trigPointer = packet[i].data+DATASIZE-TRIGSIZE*3; /* update the pointer */ if (numRealChan<0) numRealChan = 0; if (numTrigChan<0) numTrigChan = 0; if (numTrigChan>MAXNUMTRIGCHAN) { display_print("cannot maintain more than %d trigger channels in real time\n", MAXNUMTRIGCHAN); numTrigChan = MAXNUMTRIGCHAN; } break; case ACQ_MSGQ_DATA: countData++; if (packet[i].sampleNumber<minSampleValue) { minSampleIndex = i; minSampleValue = packet[i].sampleNumber; } if (packet[i].sampleNumber>maxSampleValue) { maxSampleIndex = i; maxSampleValue = packet[i].sampleNumber; } if (packet[i].messageId<minMessageValue) { minMessageIndex = i; minMessageValue = packet[i].messageId; } if (packet[i].messageId>maxMessageValue) { maxMessageIndex = i; maxMessageValue = packet[i].messageId; } if ((packet[i].sampleNumber/ packet[i].numSamples)>lastPacket) { /* detect the flanks in the trigger channels */ lastPacket = packet[i].sampleNumber/ packet[i].numSamples; for (j=0; j<numTrigChan; j++) { if (trigChan[j]>-1 && trigChan[j]<numRealChan) for (k=0; k<packet[i].numSamples; k++) { int sample = k*numRealChan + trigChan[j]; /* detect changes in the value of the trigger channel */ if (packet[i].data[sample]!=lastValue[j]) { lastValue[j] = packet[i].data[sample]; if (lastValue[j]) { display_print("trigger detected\n"); /* only store it if it is an upgoing flank */ trigPointer[numTrigger+0] = trigChan[j]; /* channel number */ trigPointer[numTrigger+1] = packet[i].sampleNumber+k; /* sample number */ trigPointer[numTrigger+2] = lastValue[j]; /* sample value */ numTrigger = wrapnumtrigger(numTrigger+3); } } } } } break; case ACQ_MSGQ_CLOSE_CONNECTION: countCancel++; break; case ACQ_MSGQ_INVALID: countInvalid++; break; default: countUnknown++; clear_packet(i); countCleared++; break; } /* end switch */ } /* end for */ /******************************************************************************* * print information about all packets in the buffer *******************************************************************************/ display_print("\n"); display_print("buffer size = %d\n", ACQ_MSGQ_SIZE); display_print("shm size = %d\n", shmsize); display_print("shm key = %#x\n", shmkey); display_print("pause = %d\n", pause); if (setupIndex>=0) display_print("dataset = %s @ %d\n", (char *)packet[setupIndex].data, setupIndex); else display_print("dataset = <unknown>\n"); display_print("\n"); display_print("countSetup = %d\n", countSetup); display_print("countData = %d\n", countData); display_print("countCancel = %d\n", countCancel); display_print("countInvalid = %d\n", countInvalid); display_print("countUnknown = %d\n", countUnknown); display_print("countCleared = %d\n", countCleared); display_print("\n"); /* this might look like a weird location to reinitialize */ maxCountCleared = (countCleared>maxCountCleared ? countCleared : maxCountCleared); countCleared = 0; display_print("min(sampleNumber) = %d @ %d\n", minSampleValue, minSampleIndex); display_print("max(sampleNumber) = %d @ %d\n", maxSampleValue, maxSampleIndex); // display_print("min(messageId) = %d @ %d\n", minMessageValue, minMessageIndex); // display_print("max(messageId) = %d @ %d\n", maxMessageValue, maxMessageIndex); display_print("max(countCleared) = %d\n", maxCountCleared); display_print("\n"); if (maxSampleIndex>=0) display_print("current trial = %d @ %d\n", maxSampleValue/packet[maxSampleIndex].numSamples, maxSampleIndex); else display_print("current trial = <unknown>\n"); display_print("\n"); display_print("numRealChan = %d\n", numRealChan); display_print("numTrigChan = %d\n", numTrigChan); display_print("numTrigger = %d\n", numTrigger/3); display_print("lastPacket = %d\n", lastPacket); display_print("trigChan = "); for (i=0; i<numTrigChan; i++) display_print("%d\t", trigChan[i]); display_print("\n"); display_print("lastValue = "); for (i=0; i<numTrigChan; i++) display_print("%d\t", lastValue[i]); display_print("\n"); display_print("\n"); display_refresh(); /******************************************************************************* * do the desired maintenance on the packet buffer (only if a key was pressed) *******************************************************************************/ k = getch(); switch (k) { case 's': write_setup(0); break; case 'p': pause = PAUSE; break; case 'f': while (countInvalid && packet[t].message_type!=ACQ_MSGQ_INVALID) t = wrapnumpacket(t+1); while (packet[t].message_type==ACQ_MSGQ_INVALID) { write_data(t, c); t = wrapnumpacket(t+1); c++; } break; case 'd': while (countInvalid && packet[t].message_type!=ACQ_MSGQ_INVALID) t = wrapnumpacket(t+1); write_data(t, c); t = wrapnumpacket(t+1); c++; break; case 'c': maxCountCleared = 0; clear_all_except_setup(); break; case 'h': showDisplay = (!showDisplay); break; case 'x': maxCountCleared = 0; clear_all(); break; case 'q': again = 0; break; } if (k!=ERR) { display_print("key pressed = %d\n", k); display_refresh(); continue; } /******************************************************************************* * do the regular maintenance on the packet buffer *******************************************************************************/ if (countCancel) { display_print("initializing all packets\n"); clear_all(); countInvalid = ACQ_MSGQ_SIZE; countData = 0; countSetup = 0; countCancel = 0; } // if ((MINFREE-countInvalid)>1 && pause) { // pause/=(MINFREE-countInvalid); // display_print("decreasing pause to %d\n", pause); // } while (countInvalid<MINFREE && countData) /* make more empty packets available */ if (setupIndex>-1) { /* moving the setup one packet at a time may look inefficient, but this only happens at the start of online acquisition */ display_print("moving setup from %d to %d\n", setupIndex, minSampleIndex); memcpy(&packet[minSampleIndex], &packet[setupIndex], sizeof(ACQ_MessagePacketType)); countCleared++; countInvalid++; countData--; // NOTE: don't clear the packet, since Matlab might be reading from it // display_print("clearing packet %d\n", setupIndex); // clear_packet(setupIndex); packet[setupIndex].message_type = ACQ_MSGQ_INVALID; setupIndex = minSampleIndex; minSampleIndex = wrapnumpacket(minSampleIndex+1); /* the next is probably now the oldest */ } else { display_print("clearing packet %d\n", minSampleIndex); clear_packet(minSampleIndex); countCleared++; countInvalid++; countData--; minSampleIndex = wrapnumpacket(minSampleIndex+1); /* the next is probably now the oldest */ } while (setupIndex>-1 && countData && packet[wrapnumpacket(setupIndex+1)].message_type==ACQ_MSGQ_INVALID) { /* move the setup to the next empty packet */ /* moving the setup one packet at a time may look inefficient, but this only happens at the start of online acquisition */ display_print("moving setup from %d to %d\n", setupIndex, wrapnumpacket(setupIndex+1)); memcpy(&packet[wrapnumpacket(setupIndex+1)], &packet[setupIndex], sizeof(ACQ_MessagePacketType)); // NOTE: don't clear the packet, since Matlab might be reading from it // clear_packet(setupIndex); packet[setupIndex].message_type = ACQ_MSGQ_INVALID; countCleared++; setupIndex = wrapnumpacket(setupIndex+1); } display_refresh(); usleep(pause); if (countInvalid>4) printf("ok %d\n", countLoop); else printf("error %d\n", countLoop); countLoop++; } /* detach from the shared memory segment */ if (shmdt(packet) == -1) { perror("shmdt"); exit(1); } /* end curses mode */ display_stop(); /* end of program */ return 0; }
void print_packet(int i) { /* print the details of each package */ display_print("%4d : ", i); switch (packet[i].message_type) { case ACQ_MSGQ_SETUP_COLLECTION: display_print("setup \t"); break; case ACQ_MSGQ_DATA: display_print("data \t"); break; case ACQ_MSGQ_CLOSE_CONNECTION: display_print("close \t"); break; case ACQ_MSGQ_INVALID: display_print("- \t"); break; default: display_print("%d\t", packet[i].message_type); } display_print("%d\t", packet[i].messageId); display_print("%d\t", packet[i].sampleNumber); display_print("%d\t", packet[i].numSamples); display_print("%d\t", packet[i].numChannels); display_print("\n"); }