int main( void ) { avr_init(); pulse_init(); puts( "$Id: tach.c,v 2.0 2002/09/22 02:10:18 tramm Exp $" ); putnl(); while( 1 ) { puthex( high_bits ); puthex( time() ); putc( ':' ); puthexs( pulse_0 ); putc( ' ' ); puthexs( pulse_1 ); putnl(); pulse_1 = pulse_0 = 0; msleep( 8192 ); } return 0; }
void init_kheap() { kernel_heap = build_heap((uintptr_t*)HEAP_BEGIN, 1, 0); // Self-test puts("heap self-test\n"); uint32_t *test_alloc = (uint32_t*)kalloc(sizeof(uint32_t)); uint32_t *test_alloc_2 = (uint32_t*)kalloc(sizeof(uint32_t)); puts("var1(uint32_t)="); puthex((uintptr_t)test_alloc); puts(", var2(uint32_t)="); puthex((uintptr_t)test_alloc_2); puts("\n"); *test_alloc = 0x1234ABCD; *test_alloc_2 = 0xCAFEBEEF; kfree((uintptr_t*)test_alloc); kfree((uintptr_t*)test_alloc_2); uint32_t* test_alloc_3 = (uint32_t*)kalloc(sizeof(uint64_t)); puts("var1 and var2 freed, var3(uint64_t)="); puthex((uintptr_t)test_alloc_3); puts(", should be "); puthex((uintptr_t)test_alloc); puts("\n"); if(test_alloc_3 == test_alloc) puts("self-test succeeded\n"); kfree((uintptr_t*)test_alloc_3); }
void decompress_kernel(unsigned long boot_heap_start) { unsigned long zimage_start, zimage_size; __stack_chk_guard_setup(); zimage_start = (unsigned long)(&__image_begin); zimage_size = (unsigned long)(&__image_end) - (unsigned long)(&__image_begin); puts("zimage at: "); puthex(zimage_start); puts(" "); puthex(zimage_size + zimage_start); puts("\n"); /* This area are prepared for mallocing when decompressing */ free_mem_ptr = boot_heap_start; free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE; /* Display standard Linux/MIPS boot prompt */ puts("Uncompressing Linux at load address "); puthex(VMLINUX_LOAD_ADDRESS_ULL); puts("\n"); /* Decompress the kernel with according algorithm */ decompress((char *)zimage_start, zimage_size, 0, 0, (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error); /* FIXME: should we flush cache here? */ puts("Now, booting the kernel...\n"); }
void startup_message(void) { putcrlf(); #ifdef __GNUC__ putstring("GCC " __VERSION__ "\r\n"); #endif putstring(name_string); putspace(); putstring(version_string); /* Silicon Revision */ putstring(" Mask("); puthex(ECHV); /* ADC reading codes Board ID */ putstring(") ID("); putstring(board_id_to_string()); /* Stack pointer */ putstring(") SP("); puthex(SP); putstring(") "); putstring(date_string); putspace(); putstring(time_string); /* now for some manufacturing data */ putcrlf(); if( manufacturing_find_tag("T#") ) manufacturing_print_tag(); putspace(); if( manufacturing_find_tag("SN") || manufacturing_find_tag("S#") ) manufacturing_print_tag(); }
void debug_section_header(Elf64_Shdr* h) { puts("-- Section header --\n"); puts("Name: "); puthex(h->sh_name); puts("\n"); puts("Type: "); puthex(h->sh_type); puts("\n"); puts("Flags: "); puthex(h->sh_flags); puts("\n"); puts("Virtual address: "); puthex(h->sh_vaddr); puts("\n"); puts("Offset in file: "); puthex(h->sh_offset); puts("\n"); puts("Size of section: "); puthex(h->sh_size); puts("\n"); puts("Link: "); puthex(h->sh_link); puts("\n"); puts("Misc info: "); puthex(h->sh_info); puts("\n"); puts("Alignment: "); puthex(h->sh_addralign); puts("\n"); puts("Size of entries in section table: "); puthex(h->sh_entsize); puts("\n"); }
void ow_dump() { putspace(); puthex( transfer_state ); putspace(); puthex( transfer_cnt ); }
u8 NFC_Module::InListPassiveTarget(u8 *buf, u8 brty, u8 len, u8 *idata, u8 maxtg) { nfc_buf[0] = PN532_COMMAND_INLISTPASSIVETARGET; nfc_buf[1] = maxtg; nfc_buf[2] = brty; if(len){ memcpy(nfc_buf+3, idata, len); } if(!write_cmd_check_ack(nfc_buf, 3+len)){ return 0; } #ifdef PN532DEBUG puthex(nfc_buf, 3+len); Serial.println(); #endif // puthex(nfc_buf, 3+len); // Serial.println(); /** "Waiting for IRQ (indicates card presence)" */ wait_ready(); wait_ready(); wait_ready(); #ifdef PN532DEBUG Serial.print(" Found Card.\n"); #endif read_dt(nfc_buf,40); // puthex(nfc_buf, nfc_buf[3]+6); // Serial.println(); if(nfc_buf[NFC_FRAME_ID_INDEX-1] != 0xD5){ return 0; } puthex(nfc_buf, nfc_buf[3]+6); Serial.println(); if(nfc_buf[NFC_FRAME_ID_INDEX] != (PN532_COMMAND_INLISTPASSIVETARGET+1)){ return 0; } // if(nfc_buf[NFC_FRAME_ID_INDEX+1]!=1){ //#ifdef PN532DEBUG // Serial.println(nfc_buf[NFC_FRAME_ID_INDEX+1],DEC); //#endif // return 0; // } if(brty == PN532_BRTY_ISO14443A){ /** UUID length */ buf[0] = nfc_buf[12]; for(u8 i=1; i<5; i++){ buf[i] = nfc_buf[12+i]; } }else{ buf[0] = nfc_buf[3]; memcpy(buf, nfc_buf+5, nfc_buf[3]); } return 1; }
static void aes_dec_firstround(aes_cipher_state_t* state, const aes_roundkey_t* k) { uint8_t i; /// *** STEP 1: keyAdd *** for(i=0; i<16; ++i) { state->s[i] ^= k->ks[i]; } #ifdef ENCRYPTION_DEBUG beginSerial(115200, 0); digitalWrite(23,0x01); digitalWrite(11,0x00); printString("\n\n*** STEP 1: keyAdd --> ", 0); _delay_ms(3); for(i=0; i<16; ++i) { puthex((char)state->s[i],0); _delay_ms(3); } #endif /// *** STEP 2: invert shiftRows *** aes_invshiftcol(state->s+1, 1); aes_invshiftcol(state->s+2, 2); aes_invshiftcol(state->s+3, 3); #ifdef ENCRYPTION_DEBUG printString("\n*** STEP 2: shiftRows --> ", 0); _delay_ms(3); for(i=0; i<16; ++i) { puthex((char)state->s[i],0); _delay_ms(3); } #endif /// *** STEP 3: subBytes *** for(i=0; i<16; ++i) { state->s[i] = pgm_read_byte(aes_invsbox+state->s[i]); } #ifdef ENCRYPTION_DEBUG printString("\n*** STEP 3: subBytes --> ", 0); _delay_ms(3); for(i=0; i<16; ++i) { puthex((char)state->s[i],0); _delay_ms(3); } #endif }
//added by dongbo huang, this is to set the short address of this node static void set_rime_addr(void) { signed char i; #if CC2530_CONF_MAC_FROM_PRIMARY unsigned char __xdata *macp = &X_IEEE_ADDR; #else unsigned char __code *macp = (__code unsigned char *)0xFFE8; #endif //#if CC2530_CONF_MAC_FROM_PRIMARY // putstring("Reading MAC from Info Page\r\n"); //#else // putstring("Reading MAC from flash\r\n"); /* * The MAC is always stored in 0xFFE8 of the highest BANK of our flash. This * maps to address 0xFFF8 of our CODE segment, when this BANK is selected. * Load the bank, read 8 bytes starting at 0xFFE8 and restore last BANK. * Since we are called from main(), this MUST be BANK1 or something is very * wrong. This code can be used even without a bankable firmware. */ /* Don't interrupt us to make sure no BANK switching happens while working */ // DISABLE_INTERRUPTS(); /* Switch to the BANKn, * map CODE: 0x8000 - 0xFFFF to FLASH: 0xn8000 - 0xnFFFF */ // FMAP = CC2530_LAST_FLASH_BANK; //#endif for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) { rimeaddr_node_addr.u8[i] = *macp; macp++; } #if !CC2530_CONF_MAC_FROM_PRIMARY /* Remap 0x8000 - 0xFFFF to BANK1 */ FMAP = 1; ENABLE_INTERRUPTS(); #endif /* Now the address is stored MSB first */ #if STARTUP_CONF_VERBOSE putstring("Rime configured with address "); for(i = 0; i < RIMEADDR_SIZE - 1; i++) { puthex(rimeaddr_node_addr.u8[i]); putchar(':'); } puthex(rimeaddr_node_addr.u8[i]); putstring("\r\n"); #endif cc2530_rf_set_addr(IEEE802154_PANID); return; }
PROCESS_THREAD(test_send_process, ev, data) { static struct etimer et; static char hello[5]; static int i; static char *testvalue; PROCESS_BEGIN(); etimer_set(&et,CLOCK_CONF_SECOND/100); //event_temperature_send = process_alloc_event(); //event_uart_send = process_alloc_event(); //process_post(&test_send_process,event_uart_send,NULL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); //PROCESS_WAIT_EVENT_UNTIL(ev == event_uart_send); if(strncmp(rxbuf,"hello",5) == 0) { //putstring("instruction indicated"); strcpy(rxbuf,""); bufpos = 0; buflen = 0; unsigned char __code *dst = (__code unsigned char *)FRAME802154_BROADCASTADDR; puthex(*dst); puthex(*dst++); testvalue = getintvalue(); strcpy(testvalue,"hello"); printf("\r\ntest value is %s, function value = %d, initial value = %d\r\n", testvalue, (char*)getintvalue(),integerValue); //strcpy(hello,"hello"); //now I'm trying to test the basic cc2530rf functionality /*cc2530_rf_driver.init(); if(cc2530_rf_driver.send((void*)hello,sizeof("hello")) == RADIO_TX_OK) { strcpy(hello,""); putstring("some packets sent"); } else putstring("send failed"); */ //edited by dognbo huang, the codes commented below is used for to analyse the ADC module working procedure //puttemperature(); //putstring("getting temperature...\r\n"); //process_post(&sensors_test_process,event_temperature_send,NULL); } else { strcpy(rxbuf,""); bufpos = 0; buflen = 0; } etimer_reset(&et); } PROCESS_END(); }
void dumpmem (FILE * f, void *buf, unsigned int len, unsigned int offset) { unsigned int i; unsigned int address; unsigned char *p; static const unsigned int MASK_LOWER = 0x0f; char line[80]; if (offset >= len) return; address = offset; p = ((unsigned char *) buf) + offset; fputs(" Addr 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 2 4 6 8 A C E \n",f); fputs("-------- ---- ---- ---- ---- ---- ---- ---- ---- ----------------\n",f); while (p < ((unsigned char *) buf) + len) { for (i = 0; i < 50; i++) line[i] = ' '; for (; i < 80; i++) line[i] = 0; if ((address & ~MASK_LOWER) != address) /* address % 16 != 0 */ { puthex ((address & ~MASK_LOWER), 8, line, 0); for (i = 0; i < (address & MASK_LOWER); i++) { line[10 + i * 2 + i / 2] = ' '; line[10 + i * 2 + i / 2 + 1] = ' '; line[50 + i] = ' '; } address = address & ~MASK_LOWER; } else { puthex (address, 8, line, 0); i = 0; } for (; i < 16; i++) { puthex (((long) *p) & 0x0ff, 2, line, 10 + i * 2 + i / 2); line[50 + i] = '.'; if (isprint (*p)) line[50 + i] = *p; if (++p >= (unsigned char *) buf + len) break; } fputs (line, f); fputs ("\n", f); address += 16; } }
u8 NFC_Module::P2PInitiatorTxRx(u8 *t_buf, u8 t_len, u8 *r_buf, u8 *r_len) { // wait_ready(); // wait_ready(); wait_ready(15); nfc_buf[0] = PN532_COMMAND_INDATAEXCHANGE; nfc_buf[1] = 0x01; // logical number of the relevant target memcpy(nfc_buf+2, t_buf, t_len); if(!write_cmd_check_ack(nfc_buf, t_len+2)){ return 0; } #ifdef PN532_P2P_DEBUG Serial.println("Initiator DataExchange sent."); #endif wait_ready(200); read_dt(nfc_buf, 60); if(nfc_buf[5] != 0xD5){ return 0; } #ifdef PN532_P2P_DEBUG Serial.println("Initiator DataExchange Get."); #endif if(nfc_buf[NFC_FRAME_ID_INDEX] != (PN532_COMMAND_INDATAEXCHANGE+1)){ #ifdef PN532_P2P_DEBUG puthex(nfc_buf, nfc_buf[3]+7); Serial.println("Send data failed"); #endif return 0; } if(nfc_buf[NFC_FRAME_ID_INDEX+1]){ #ifdef PN532_P2P_DEBUG Serial.print("InExchangeData Error:"); puthex(nfc_buf, nfc_buf[3]+7); Serial.println(); #endif return 0; } #ifdef PN532_P2P_DEBUG puthex(nfc_buf, nfc_buf[3]+7); Serial.println(); #endif /** return read data */ *r_len = nfc_buf[3]-3; memcpy(r_buf, nfc_buf+8, *r_len); return 1; }
u8 NFC_Module::FelicaPoll(u8 *buf, u8 len, u8 *idata) { static u8 sta=0; if(!sta){ nfc_buf[0] = PN532_COMMAND_INLISTPASSIVETARGET; nfc_buf[1] = 0x02; nfc_buf[2] = 0x02; if(len){ memcpy(nfc_buf+3, idata, len); } if(!write_cmd_check_ack(nfc_buf, 3+len)){ return 0; } #ifdef PN532DEBUG puthex(nfc_buf, 3+len); Serial.println(); #endif // puthex(nfc_buf, 3+len); Serial.println("Send command"); } sta = 1; /** "Waiting for IRQ (indicates card presence)" */ wait_ready(); wait_ready(); wait_ready(); #ifdef PN532DEBUG Serial.print(" Found Card.\n"); #endif read_dt(nfc_buf,40); puthex(nfc_buf, nfc_buf[3]+6); Serial.println(); if(nfc_buf[NFC_FRAME_ID_INDEX-1] != 0xD5){ return 0; } sta = 0; puthex(nfc_buf, nfc_buf[3]+6); Serial.println(); if(nfc_buf[NFC_FRAME_ID_INDEX] != (PN532_COMMAND_INLISTPASSIVETARGET+1)){ return 0; } // if(nfc_buf[NFC_FRAME_ID_INDEX+1]!=1){ //#ifdef PN532DEBUG // Serial.println(nfc_buf[NFC_FRAME_ID_INDEX+1],DEC); //#endif // return 0; // } buf[0] = nfc_buf[3]; memcpy(buf, nfc_buf+5, nfc_buf[3]); return 1; }
int print_ptr(void *ptr) { int size; size = get_size(ptr); puthex((size_t)ptr); ft_putstr(" - "); puthex((size_t)(ptr + size)); ft_putstr(" : "); print_nbr(size); ft_putendl(" octets"); return (size); }
void debug_program_header(Elf64_Phdr* h) { puts("-- Program header --\n"); puts("Type: "); puthex(h->p_type); puts("\n"); puts("Flags: "); puthex(h->p_flags); puts("\n"); puts("Offset in file: "); puthex(h->p_offset); puts("\n"); puts("Virtual address: "); puthex(h->p_vaddr); puts("\n"); puts("Reserved: "); puthex(h->p_paddr); puts("\n"); puts("Segment size in file: "); puthex(h->p_filesz); puts("\n"); puts("Segment size in mem: "); puthex(h->p_memsz); puts("\n"); puts("Alignment: "); puthex(h->p_align); puts("\n"); }
/*---------------------------------------------------------------------------*/ static void tcpip_handler(void) { leds_on(LEDS_GREEN); if(uip_newdata()) { putstring("0x"); puthex(uip_datalen()); putstring(" bytes response=0x"); puthex((*(uint16_t *) uip_appdata) >> 8); puthex((*(uint16_t *) uip_appdata) & 0xFF); putchar('\n'); } leds_off(LEDS_GREEN); return; }
static void dump_entry(datum key, datum value) { int i; if (yflag) { if ((key.dsize >= 3) && (memcmp(key.dptr, "YP_", 3) == 0)) { return; } } if (pflag) { putchar(' '); for (i = 0; i < key.dsize; i++) { if (isprint(key.dptr[i]) && !isspace(key.dptr[i]) && (key.dptr[i] != '\\')) { putchar(key.dptr[i]); } else { putchar('\\'); puthex(key.dptr[i]); } } putchar('\n'); putchar(' '); for (i = 0; i < value.dsize; i++) { if (isprint(value.dptr[i]) && (value.dptr[i] != ' ') && (value.dptr[i] != '\t') && (value.dptr[i] != '\\')) { putchar(value.dptr[i]); } else { putchar('\\'); puthex(value.dptr[i]); } } putchar('\n'); } else { putchar(' '); for (i = 0; i < key.dsize; i++) { puthex(key.dptr[i]); } putchar('\n'); putchar(' '); for (i = 0; i < value.dsize; i++) { puthex(value.dptr[i]); } putchar('\n'); } }
u8 NFC_Module::MifareReadBlock(u8 block, u8 *buf) { nfc_buf[0] = PN532_COMMAND_INDATAEXCHANGE; nfc_buf[1] = 1; // logical number of the relevant target nfc_buf[2] = MIFARE_CMD_READ; nfc_buf[3] = block; if(!write_cmd_check_ack(nfc_buf, 4)){ return 0; } wait_ready(); read_dt(nfc_buf, 26); /** if(nfc_buf[5] == 0xD5){ Serial.print("Block receive:"); puthex(nfc_buf, nfc_buf[3]+6); Serial.println(); } */ if(nfc_buf[NFC_FRAME_ID_INDEX] != (PN532_COMMAND_INDATAEXCHANGE+1)){ #ifdef PN532DEBUG puthex(nfc_buf, 20); Serial.println("Authentication fail."); #endif return 0; } if(nfc_buf[NFC_FRAME_ID_INDEX+1]){ return 0; } memcpy(buf, nfc_buf+8, 16); return 1; }
u8 NFC_Module::MifareWriteBlock(u8 block, u8 *buf) { nfc_buf[0] = PN532_COMMAND_INDATAEXCHANGE; nfc_buf[1] = 1; // logical number of the relevant target nfc_buf[2] = MIFARE_CMD_WRITE; nfc_buf[3] = block; memcpy(nfc_buf+4, buf, 16); if(!write_cmd_check_ack(nfc_buf, 20)){ return 0; } wait_ready(); read_dt(nfc_buf, 26); if(nfc_buf[NFC_FRAME_ID_INDEX] != (PN532_COMMAND_INDATAEXCHANGE+1)){ #ifdef PN532DEBUG puthex(nfc_buf, 20); Serial.println("Authentication fail."); #endif return 0; } if(nfc_buf[NFC_FRAME_ID_INDEX+1]){ return 0; } return 1; }
int getbyte(int byte) { if (byte == 0) return 106; if (byte == 1) return 139; if (byte == 2) return 120; if (byte == 3) return 183; if (byte == 4) return 69; if (byte == 5) return 197; if (byte == 6) return 147; if (byte == 7) return 207; if (byte == 8) return 35; if (byte == 9) return 155; if (byte == 10) return 122; if (byte == 11) return 244; if (byte == 12) return 125; if (byte == 13) return 215; if (byte == 14) return 69; if (byte == 15) return 219; if (byte == 16) return 2; if (byte == 17) return 224; puts("FAIL [abort]: request for byte #"); puthex(byte); while(1); return 0; }
static void puthex (long n, unsigned int digits, char *buf, unsigned int pos) { if (digits > 1) puthex (n / 16, digits - 1, buf, pos); buf[pos + digits - 1] = "0123456789abcdef"[n % 16]; }
void __init balo_printf( char *f, ... ) { int *arg = (int*)&f + 1; char c; int format = 0; while((c = *f++) != 0) { switch(c) { default: if(format) { outc('%'); format = 0; } outc( c ); break; case '%': if( format ){ format = 0; outc(c); } else format = 1; break; case 'x': if(format) puthex( *arg++ ); else outc(c); format = 0; break; case 's': if( format ) outs((char *)*arg++); else outc(c); format = 0; break; } } }
/*---------------------------------------------------------------------------*/ void uip_debug_ipaddr_print(const uip_ipaddr_t *addr) { #if UIP_CONF_IPV6 uint16_t a; unsigned int i; int f; for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { a = (addr->u8[i] << 8) + addr->u8[i + 1]; if(a == 0 && f >= 0) { if(f++ == 0) { putstring("::"); } } else { if(f > 0) { f = -1; } else if(i > 0) { putstring(":"); } puthex(a >> 8); puthex(a & 0xFF); } } #else /* UIP_CONF_IPV6 */ PRINTA("%u.%u.%u.%u", addr->u8[0], addr->u8[1], addr->u8[2], addr->u8[3]); #endif /* UIP_CONF_IPV6 */ }
void gpf_handler(registers_t* regs) { puts("GPF: error code "); puthex(regs->err_code); puts("\n"); for (;;); }
void tracenum(uint16_t num) { putchar('0'); putchar('x'); puthex(num>>12); puthex(num>>8); puthex(num>>4); puthex(num); }
void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp) { z_stream s; int r, i, flags; /* skip header */ i = 10; flags = src[3]; if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) { puts("bad gzipped data\n"); exit(); } if ((flags & EXTRA_FIELD) != 0) i = 12 + src[10] + (src[11] << 8); if ((flags & ORIG_NAME) != 0) while (src[i++] != 0) ; if ((flags & COMMENT) != 0) while (src[i++] != 0) ; if ((flags & HEAD_CRC) != 0) i += 2; if (i >= *lenp) { puts("gunzip: ran out of data in header\n"); exit(); } /* Initialize ourself. */ s.workspace = zalloc(zlib_inflate_workspacesize()); r = zlib_inflateInit2(&s, -MAX_WBITS); if (r != Z_OK) { puts("zlib_inflateInit2 returned "); puthex(r); puts("\n"); exit(); } s.next_in = src + i; s.avail_in = *lenp - i; s.next_out = dst; s.avail_out = dstlen; r = zlib_inflate(&s, Z_FINISH); if (r != Z_OK && r != Z_STREAM_END) { puts("inflate returned "); puthex(r); puts("\n"); exit(); } *lenp = s.next_out - (unsigned char *) dst; zlib_inflateEnd(&s); }
void putrc( char *func, WORD rc ) { if( rc == 0 ) return; putstring( func ); putstring( " returned " ); puthex( rc ); putstring( "\r\n" ); }
void dump_long(char *str, uint32_t val) { putstr(str); puthex((val>>24)&0xff); puthex((val>>16)&0xff); puthex((val>>8)&0xff); puthex(val&0xff); putnl(); }
void PrintSector(void) { int i; for (i=0;i<256;i++) { puthex(minifatBuffer[i]); if ((i & 7)==7) puts(""); } }
void isr_handler(registers_t regs) { if (regs.int_no >= 0x20) write_apicr(0xb0, 0); // acknowledge ioapic interrupt if (handlers[regs.int_no] != 0) { isr_t handler = handlers[regs.int_no]; handler(®s); } else { puts("[ISR] INT "); puthex(regs.int_no); puts(", error code "); puthex(regs.err_code); puts("\n"); } }