void AcpiOsFree(void *Memory) { PRINTD("AcpiOsFree() called"); free(Memory); }
/*-------------------------------------------------------------------------*/ int main(void) { initialize(); #ifdef LOWPOWER rf2xx_set_txpower(0xf); #endif while(1) { process_run(); watchdog_periodic(); #if 0 /* Various entry points for debugging in the AVR Studio simulator. * Set as next statement and step into the routine. */ NETSTACK_RADIO.send(packetbuf_hdrptr(), 42); process_poll(&rf230_process); packetbuf_clear(); len = rf230_read(packetbuf_dataptr(), PACKETBUF_SIZE); packetbuf_set_datalen(42); NETSTACK_RDC.input(); #endif #if 0 /* Clock.c can trigger a periodic PLL calibration in the RF230BB driver. * This can show when that happens. */ extern uint8_t rf230_calibrated; if (rf230_calibrated) { PRINTD("\nRF230 calibrated!\n"); rf230_calibrated=0; } #endif /* Set DEBUGFLOWSIZE in contiki-conf.h to track path through MAC, RDC, and RADIO */ #if DEBUGFLOWSIZE if (debugflowsize) { debugflow[debugflowsize]=0; PRINTF("%s",debugflow); debugflowsize=0; } #endif #if PERIODICPRINTS #if TESTRTIMER /* Timeout can be increased up to 8 seconds maximum. * A one second cycle is convenient for triggering the various debug printouts. * The triggers are staggered to avoid printing everything at once. * My raven is 6% slow. */ if (rtimerflag) { rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL); rtimerflag=0; #else if (clocktime!=clock_seconds()) { clocktime=clock_seconds(); #endif #if STAMPS if ((clocktime%STAMPS)==0) { #if ENERGEST_CONF_ON #include "lib/print-stats.h" print_stats(); #elif RADIOSTATS extern volatile unsigned long radioontime; PRINTF("%u(%u)s\n",clocktime,radioontime); #else PRINTF("%us\n",clocktime); #endif } #endif #if TESTRTIMER clocktime+=1; #endif #if PINGS && UIP_CONF_IPV6 extern void raven_ping6(void); if ((clocktime%PINGS)==1) { PRINTF("**Ping\n"); raven_ping6(); } #endif #if ROUTES && UIP_CONF_IPV6 if ((clocktime%ROUTES)==2) { extern uip_ds6_nbr_t uip_ds6_nbr_cache[]; extern uip_ds6_route_t uip_ds6_routing_table[]; extern uip_ds6_netif_t uip_ds6_if; uint8_t i,j; PRINTF("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB); for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr); PRINTF("\n"); } } PRINTF("\nNeighbors [%u max]\n",UIP_DS6_NBR_NB); for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) { if(uip_ds6_nbr_cache[i].isused) { ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr); PRINTF("\n"); j=0; } } if (j) PRINTF(" <none>"); PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB); for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) { if(uip_ds6_routing_table[i].isused) { ipaddr_add(&uip_ds6_routing_table[i].ipaddr); PRINTF("/%u (via ", uip_ds6_routing_table[i].length); ipaddr_add(&uip_ds6_routing_table[i].nexthop); // if(uip_ds6_routing_table[i].state.lifetime < 600) { PRINTF(") %lus\n", uip_ds6_routing_table[i].state.lifetime); // } else { // PRINTF(")\n"); // } j=0; } } if (j) PRINTF(" <none>"); PRINTF("\n---------\n"); } #endif #if STACKMONITOR if ((clocktime%STACKMONITOR)==3) { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { if (*(uint16_t *)p != 0x4242) { PRINTF("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end); break; } p+=10; } while (p<RAMEND-10); } #endif } #endif /* PERIODICPRINTS */ //Use with RF230BB DEBUGFLOW to show path through driver #if RF230BB&&0 extern uint8_t rf230processflag; if (rf230processflag) { PRINTF("rf230p%d",rf230processflag); rf230processflag=0; } #endif #if RF230BB&&0 extern uint8_t rf230_interrupt_flag; if (rf230_interrupt_flag) { // if (rf230_interrupt_flag!=11) { PRINTF("**RI%u",rf230_interrupt_flag); // } rf230_interrupt_flag=0; } #endif } return 0; } /*---------------------------------------------------------------------------*/ void log_message(char *m1, char *m2) { PRINTF("%s%s\n", m1, m2); }
int Init() { long result; int i; LPTSTR readerName; result = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &ScardContext); if(result != SCARD_S_SUCCESS) { PRINTERR(("SCardEstablishContext Fail : %08X\n", result)); return 0; } PRINTD(("SCardEstablishContext Success\n")); // Find out ReaderNameLength result = SCardListReaders(ScardContext, NULL, NULL, &ReaderNameLength); if(result != SCARD_S_SUCCESS) { PRINTERR(("SCardListReadersA Fail : %08X\n", result)); ReaderNameLength = 100; return 0; } PRINTD(("SCardListReaders Success : %d\n", ReaderNameLength)); // Allcoate Memory for ReaderName ReaderName = (LPTSTR)malloc(ReaderNameLength); //new char[ReaderNameLength]; // List Reader Name ReadersNum = 0; result = SCardListReaders(ScardContext, NULL, ReaderName, &ReaderNameLength); if(result == SCARD_S_SUCCESS) { readerName = ReaderName; while((*readerName != '\0') && (ReadersNum < MAX_READER_NUMBER)) { ScardReaderState[ReadersNum].szReader = (LPTSTR)readerName; ScardReaderState[ReadersNum].dwCurrentState = SCARD_STATE_UNAWARE; ++ReadersNum; readerName += strlen(readerName) + 1; //readerName += wcslen(readerName) + 1; } } else { PRINTERR(("SCardListReadersA Fail : %08X\n", result)); return 0; } printf("Reader List (%d Readers): \n", ReadersNum); for(i = 0; i < (int)ReadersNum; ++i) { #ifdef WINCE_OS wprintf("%d)%s\n", i, ScardReaderState[i].szReader); #else printf(" (%d) %s\n", i, ScardReaderState[i].szReader); #endif } printf("\n"); return 1; }
static int memory_dumper(unsigned long start, unsigned long end, unsigned long data, int increment, int write, int color_en, int length, int ascii_en, int fd) { unsigned char progress_bar[] = "-\\|/"; char buffer[16]; const char *color = NULL; unsigned long read_data; int error = 0; int i, j; PRINTD("begin address: %#lx - end address: %#lx - length: %#x - operation: %#x\n", start, end, length, write); for(i = 0, j = 0, read_data = data; i < end - start; i += length, j++, data += increment, read_data += increment) { if(write) { if(write == WRITE_ONLY) printf("%c", progress_bar[(i >> 2) & 0x3]); error = memory_rw(start + i, &data, length, increment, write, fd); if(error) return EXIT_FAILURE; if(write == WRITE_ONLY) printf(DELETE); } if((write == READ_ONLY) || (write == WRITE_READ)) { error = memory_rw(start + i, &data, length, increment, READ_ONLY, fd); if(error) { printf("Error reading!\n"); return EXIT_FAILURE; } if(!(i % 16)) { j = 0; if(color_en) printf("\n" "%s" "%." NIBBLES_PER_WORD "lx - ", colors[yellow], start + i); else printf("\n%." NIBBLES_PER_WORD "lx - ", start + i); } if(!(i % 4)) printf("\t"); /* Save read data. */ buffer[j] = (char)data; switch(length) { case 2: if(color_en) { color = colors[light_cyan]; if(write == WRITE_READ) { if(read_data != data) { color = colors[red]; } else { color = colors[light_green]; } } printf("%s" "%.4lx ", color, data); } else { printf("%.4lx ", data); } break; case 4: if(color_en) { color = colors[light_cyan]; if(write == WRITE_READ) { if(read_data != data) { color = colors[red]; } else { color = colors[light_green]; } } printf("%s" "%.8lx ", color, data); } else { printf("%.8lx ", data); } break; #ifdef ARCH64 case 8: if(color_en) { color = colors[light_cyan]; if(write == WRITE_READ) { if(read_data != data) { color = colors[red]; } else { color = colors[light_green]; } } printf("%s" "%." NIBBLES_PER_WORD "lx ", color, data); } else { printf("%." NIBBLES_PER_WORD "lx ", data); } break; #endif case 1: default: if(color_en) { color = colors[light_cyan]; if(write == WRITE_READ) { if(read_data != data) { color = colors[red]; } else { color = colors[light_green]; } } printf("%s" "%.2lx ", color, data); } else { printf("%.2lx ", data); } break; } if(!((i + 1) % 16)) { if(ascii_en) { printf("\t"); for(j = 0; j < 16; j++) { if(isprint(buffer[j])) printf("%c", (char)buffer[j]); else printf("."); } } } } } if(color_en) printf("%s" "\n", colors[default_color]); else printf("\n"); return EXIT_SUCCESS; }
/*----------------------------------------------------------------------- * Read bytes */ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) { int shift; PRINTD("i2c_read: chip %02X addr %02X alen %d buffer %p len %d\n", chip, addr, alen, buffer, len); #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW /* * EEPROM chips that implement "address overflow" are ones * like Catalyst 24WC04/08/16 which has 9/10/11 bits of * address and the extra bits end up in the "chip address" * bit slots. This makes a 24WC08 (1Kbyte) chip look like * four 256 byte chips. * * Note that we consider the length of the address field to * still be one byte because the extra address bits are * hidden in the chip address. */ chip |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); PRINTD("i2c_read: fix addr_overflow: chip %02X addr %02X\n", chip, addr); #endif /* * Do the addressing portion of a write cycle to set the * chip's address pointer. If the address length is zero, * don't do the normal write cycle to set the address pointer, * there is no address pointer in this chip. */ send_start(); if(alen > 0) { if(write_byte(chip << 1)) { /* write cycle */ send_stop(); PRINTD("i2c_read, no chip responded %02X\n", chip); return(1); } shift = (alen-1) * 8; while(alen-- > 0) { if(write_byte(addr >> shift)) { PRINTD("i2c_read, address not <ACK>ed\n"); return(1); } shift -= 8; } /* Some I2C chips need a stop/start sequence here, * other chips don't work with a full stop and need * only a start. Default behaviour is to send the * stop/start sequence. */ #ifdef CONFIG_SOFT_I2C_READ_REPEATED_START send_start(); #else send_stop(); send_start(); #endif } /* * Send the chip address again, this time for a read cycle. * Then read the data. On the last byte, we do a NACK instead * of an ACK(len == 0) to terminate the read. */ write_byte((chip << 1) | 1); /* read cycle */ while(len-- > 0) { *buffer++ = read_byte(len == 0); } send_stop(); return(0); }
void p2p_send_prov_disc_req(void) { UWORD8 grp_cap = 0; UWORD8 *frm_ptr = 0; UWORD16 index = 0; UWORD16 ie_len_offset = 0; UWORD16 config_method = 0; TROUT_DBG4("P2P: send a P2P frame..."); frm_ptr = (UWORD8*)mem_alloc(g_shared_pkt_mem_handle, MANAGEMENT_FRAME_LEN); if(frm_ptr == NULL) { return; } add_p2p_mgmt_frame_hdr(frm_ptr, g_p2p_join_req.dev_dscr.dev_addr); g_p2p_dialog_token = get_random_byte(); /* rand dialog token */ index = add_p2p_pub_act_hdr(frm_ptr, g_p2p_dialog_token, P2P_PROV_DISC_REQ); /* Store the P2P IE length offset */ ie_len_offset = MAC_HDR_LEN + P2P_PUB_ACT_TAG_PARAM_OFF + 1; /*************************************************************************/ /* The following P2P attributes are added as per the P2P v1.1 spec */ /* Table 58—P2P attributes in the Provision Discovery Request frame */ /* - P2P Capability shall be present */ /* - P2P device info shall be present */ /* - P2P Group ID shall be present */ /*************************************************************************/ index += add_p2p_capability_attr(frm_ptr, index, get_p2p_dev_cap(), grp_cap); index += add_p2p_device_info_attr(frm_ptr, index); index += add_p2p_grp_id_attr(frm_ptr, index, g_p2p_join_req.dev_dscr.dev_addr, g_p2p_join_req.dev_dscr.grp_ssid); /* Update the P2P IE length */ frm_ptr[ie_len_offset] = index - ie_len_offset - 1; /* Add WSC IE */ switch(get_wps_pass_id_enr()) { case DEV_PASS_ID_USER_SPE: { config_method = WPS_CONFIG_METH_DISPLAY; } break; case DEV_PASS_ID_REG_SPE: { config_method = WPS_CONFIG_METH_KEYPAD; } break; case DEV_PASS_ID_PUSHBUTT: { config_method = WPS_CONFIG_METH_PUSHBUTTON; } break; default: { PRINTD("Invalid password ID for joining\n"); } } /* Add the WSC IE */ index += wps_add_config_method_ie(frm_ptr, index, config_method); /* Transmit the management frame */ tx_mgmt_frame(frm_ptr, index + FCS_LEN, HIGH_PRI_Q, 0); }
//////////////////////////////////////////////////////////////// // 割込みデータ出力 //////////////////////////////////////////////////////////////// void SUB6::OutData( void ) { switch( Status8049 ){ case D8049_JOY: // ゲーム用キー割込み データ出力 PRINTD( SUB_LOG, "[OutData JOY] Data: %02X\n", JoyCode ); WriteExt( JoyCode ); IntrFlag &= ~IR_JOY; break; case D8049_KEY1: // キー割込み1 その1 割込みベクタ出力 IntrFlag &= ~IR_KEY1; break; case D8049_KEY12: // キー割込み1 その2 割込みベクタ出力 IntrFlag &= ~IR_KEY12; break; case D8049_CMTR: // CMT READ割込み データ出力 PRINTD( SUB_LOG, "[OutData CMTR] Data: %02X\n", CmtData ); WriteExt( CmtData ); IntrFlag &= ~IR_CMTR; break; case D8049_CMTE: // CMT ERROR割込み 割込みベクタ出力 IntrFlag &= ~IR_CMTE; break; case D8049_KEY2: // キー割込み2 データ出力 PRINTD( SUB_LOG, "[OutData KEY2] Data: %02X\n", KeyCode ); WriteExt( KeyCode ); IntrFlag &= ~IR_KEY2; break; case D8049_KEY3: // キー割込み3 データ出力 PRINTD( SUB_LOG, "[OutData KEY3] Data: %02X\n", KeyCode ); WriteExt( KeyCode ); IntrFlag &= ~IR_KEY3; break; case D8049_SIO: // RS232C受信割込み データ出力 PRINTD( SUB_LOG, "[OutData SIO] Data: %02X\n", SioData ); WriteExt( SioData ); IntrFlag &= ~IR_SIO; break; case D8049_TVRR:{ // TV予約読込み割込み データ出力 BYTE tvd = TVRCnt >= (int)sizeof(TVRData) ? 0xff : TVRData[TVRCnt++]; PRINTD( SUB_LOG, "[OutData TVR] Data: %02X\n", tvd ); WriteExt( tvd ); if( tvd == 0xff ){ // FFHなら終了 IntrFlag &= ~IR_TVR; }else{ // FFH以外なら残りのデータ出力 vm->EventAdd( this, EID_DATA, WAIT_DATA, EV_LOOP|EV_STATE ); return; } break; } case D8049_DATE: // DATE割込み データ出力 PRINTD( SUB_LOG, "[OutData DATE] Data%d: %02X\n", DateCnt, DateData[DateCnt] ); WriteExt( DateData[DateCnt++] ); if( DateCnt > 4 ){ // 5回出力したら終了 IntrFlag &= ~IR_DATE; }else{ // 5回未満なら残りのデータ出力 vm->EventAdd( this, EID_DATA, WAIT_DATA, EV_LOOP|EV_STATE ); return; } break; } // 割込み処理終了 Status8049 = D8049_IDLE; // CPUに対する割込み要求をキャンセル(割込み禁止対策) vm->IntCancelIntr( IREQ_8049 ); }
void AcpiOsDeleteLock(ACPI_SPINLOCK Handle) { PRINTD("Not implemented AcpiOsDeleteLock() called"); /* Not implemented. */ }
void AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags) { PRINTD("Not implemented AcpiOsReleaseLock() called"); /* Not implemented. */ }
void AcpiOsStall(UINT32 Microseconds) { PRINTD("Not implemented AcpiOsStall() called"); /* Not implemented. */ }
void AcpiOsWaitEventsComplete(void) { PRINTD("Not implemented AcpiOsWaitEventsComplete() called"); /* Not implemented. */ }
void AcpiOsSleep(UINT64 Milliseconds) { PRINTD("AcpiOsSleep() called"); ksleep(Milliseconds); }
ACPI_THREAD_ID AcpiOsGetThreadId(void) { PRINTD("AcpiOsGetThreadId() called"); return thread_self()->id; }
BOOLEAN AcpiOsWritable(void *Pointer, ACPI_SIZE Length) { PRINTD("AcpiOsWritable() called"); return TRUE; }
void fakemem_free(void* ptr) { PRINTD("\nfree called. ptr = %p, CAS = %p, taken = %p\n", ptr, FAKEMEM_ALLOC_STATE, FAKEMEM_ALLOC_STATE->taken); if (FAKEMEM_ALLOC_STATE == NULL || FAKEMEM_ALLOC_STATE->taken == NULL) return; fakemem_block* walker = FAKEMEM_ALLOC_STATE->taken; fakemem_block* parent = walker; size_t off = (size_t)((uintptr_t)ptr - (uintptr_t)FAKEMEM_ALLOC_STATE->base_vaddr); PRINTD("Offset = %ld\n", off); while (walker != NULL) { PRINTMB("walker", walker); /*PRINTD("walker = %p, walker->next = %p, walker->offset = %lu\n", walker, walker->next, walker->offset);*/ if (walker->offset == off) break; if (parent != walker) parent = walker; walker = walker->next; } PRINTD("found walker %p\n", walker); // this should be an error in a safe language... if (walker == NULL) return; PRINTD("walker is %p, off is %lu\n", walker, walker->offset); // remove the node with the right offset if (walker == parent && walker->next == NULL) { // this is the case with only one... FAKEMEM_ALLOC_STATE->taken = NULL; } else { parent->next = walker->next; } walker->next = NULL; // add to the free list fakemem_block* new_block = walker; walker = FAKEMEM_ALLOC_STATE->free_blocks; parent = walker; PRINTLIST("taken", FAKEMEM_ALLOC_STATE->taken); // iterate over all free blocks, find the first one which is after out block // in: new_block, containing data to enlist // out: parent holds the place where to put the data while (walker != NULL) { PRINTMB("free-walk", walker); if (walker->offset > new_block->offset) break; if (parent != walker) parent = walker; walker = walker->next; } if (walker == NULL) return; PRINTD("walker = %p, parent = %p; parent->size = %lu, offset = %lu\n", walker, parent, parent->size, parent->offset); PRINTMB("new_block", new_block); PRINTLIST("free_blocks", FAKEMEM_ALLOC_STATE->free_blocks); if (parent->offset + parent->size == new_block->offset) { PRINTD("Will merge two nodes, parent in front\n"); // we will assimilate the block; parent->size += new_block->size; free(new_block); } else if (new_block->offset + new_block->size == parent->offset) { PRINTD("Will merge two nodes, parent in back\n"); parent->size += new_block->size; parent->offset -= new_block->size; free(new_block); } else { new_block->next = walker; if (parent == FAKEMEM_ALLOC_STATE->free_blocks) { FAKEMEM_ALLOC_STATE->free_blocks = new_block; } else { parent->next = new_block; } } // now, do the compacting... walker = parent = FAKEMEM_ALLOC_STATE->free_blocks; PRINTD("will try to compact...\n"); while (walker != NULL) { PRINTMB("walker", walker); /*PRINTD("walker = %p, walker->next = %p, walker->offset = %lu, walker->size = %lu\n", walker, walker->next, walker->offset, walker->size);*/ if (walker && walker->next) { if (walker->offset + walker->size == walker->next->offset) { // compact... PRINTD("will compact %p\n", walker->next); walker->size += walker->next->size; fakemem_block* temp = walker->next; walker->next = walker->next->next; PRINTD("removing %p\n", temp); free(temp); } } if (parent != walker) parent = walker; walker = walker->next; } #ifdef DEBUG fakemem_block* taken = FAKEMEM_ALLOC_STATE->taken; PRINTD("taken = %p, taken->next = %p\n", taken, taken?taken->next:taken); PRINTLIST("free", FAKEMEM_ALLOC_STATE->free_blocks); PRINTLIST("taken", FAKEMEM_ALLOC_STATE->taken); PRINTD("free ends\n\n"); #endif }
ACPI_STATUS AcpiOsInitialize(void) { PRINTD("AcpiOsInitialize() called"); return AE_OK; }
void* fakemem_malloc(size_t size) { // if we are not initialized, we need to allocate the initial data structures if (FAKEMEM_ALLOC_STATE == NULL && fakemem_init() == NULL) { errno = ENOMEM; return NULL; } if (size == 0) { errno = EINVAL; return NULL; } PRINTD("\nmalloc called. CAS = %p, size = %lu\n", FAKEMEM_ALLOC_STATE, size); // set the size to be of the granularity size = ((size-1)/FAKEMEM_ALLOC_BLOCK+1)*FAKEMEM_ALLOC_BLOCK; PRINTD("rounded size is %lu\n", size); fakemem_block* walker = FAKEMEM_ALLOC_STATE->free_blocks; fakemem_block* parent = walker; while (walker != NULL) { if (walker->size >= size) break; if (parent != walker) parent = walker; walker = walker->next; } if (walker == NULL) { errno = ENOMEM; return NULL; } PRINTD("found walker %p, offset %lu, size %lu\n", walker, walker->offset, walker->size); // this is what we put in taken fakemem_block* new_block = NULL; // first, update the free list // new_block will contain the block which needs to go to the taken list if (walker->size == size) { // we just move the block to the taken list new_block = walker; if (parent != walker) parent->next = walker->next; else FAKEMEM_ALLOC_STATE->free_blocks = walker->next; PRINTD("size matches chunk. parent = %p, new_block = %p\n", parent, new_block); } else { // we need to create and fill in the new block new_block = (fakemem_block*)malloc(sizeof(fakemem_block)); if (new_block == NULL) { errno = ENOMEM; return NULL; } new_block->offset = walker->offset; new_block->size = size; walker->offset += size; walker->size -= size; PRINTD("new block created. walker = %p, new_block = %p\n", walker, new_block); } PRINTD("parent %p, next %p\n", parent, parent->next); // then, proceed to adding a new block to the taken list walker = FAKEMEM_ALLOC_STATE->taken; parent = walker; while (walker != NULL) { PRINTD("new_block->offset = %lu, walker->offset = %lu\n", new_block->offset, walker->offset); if (new_block->offset > walker->offset) break; if (parent != walker) parent = walker; walker = walker->next; } new_block->next = walker; PRINTD("taken list: new_block->next = %p\n", new_block->next); PRINTD("taken list: parent = %p\n", parent); if (parent == NULL || parent == FAKEMEM_ALLOC_STATE->taken) FAKEMEM_ALLOC_STATE->taken = new_block; else parent->next = new_block; PRINTD("taken list: parent = %p, parent->next = %p, taken = %p\n", parent, parent?parent->next:parent, FAKEMEM_ALLOC_STATE->taken); PRINTLIST("free", FAKEMEM_ALLOC_STATE->free_blocks); PRINTLIST("taken", FAKEMEM_ALLOC_STATE->taken); PRINTD("malloc ends\n\n"); // finally, return the address we "allocated" return ((void*)((uintptr_t)FAKEMEM_ALLOC_STATE->base_vaddr + new_block->offset)); }
void AcpiOsVprintf(const char *Format, va_list Args) { PRINTD("AcpiOsVprintf() called"); vprintf(Format, Args); }
//////////////////////////////////////////////////////////////// // 割込みベクタ出力 //////////////////////////////////////////////////////////////// void SUB6::OutVector( void ) { BYTE IntrVector = IVEC_NOINTR; switch( Status8049 ){ case D8049_JOY: // ゲーム用キー割込み 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector JOY]\n" ); IntrVector = IVEC_JOY; break; case D8049_KEY1: // キー割込み1 その1 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector KEY1]\n" ); IntrVector = IVEC_KEY1; IntrFlag &= ~IR_KEY1; Status8049 = D8049_NODATA; break; case D8049_KEY12: // キー割込み1 その2 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector KEY12]\n" ); IntrVector = IVEC_KEY12; IntrFlag &= ~IR_KEY12; Status8049 = D8049_NODATA; break; case D8049_CMTR: // CMT READ割込み 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector CMTR]\n" ); IntrVector = IVEC_CMT_R; break; case D8049_CMTE: // CMT ERROR割込み 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector CMTE]\n" ); IntrVector = IVEC_CMT_E; IntrFlag &= ~IR_CMTE; Status8049 = D8049_NODATA; break; case D8049_KEY2: // キー割込み2 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector KEY2]\n" ); IntrVector = IVEC_KEY2; break; case D8049_KEY3: // キー割込み3 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector KEY3]\n" ); IntrVector = IVEC_KEY3; break; case D8049_SIO: // RS232C受信割込み 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector SIO]\n" ); IntrVector = IVEC_SIO; break; case D8049_TVRR: // TV予約割込み 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector TVR]\n" ); IntrVector = IVEC_TVR; break; case D8049_DATE: // DATE割込み 割込みベクタ出力 PRINTD( SUB_LOG, "[OutVector DATE]\n" ); IntrVector = IVEC_DATE; break; default: // どれでもなければベクタ出力なし return; } WriteExt( IntrVector ); vm->IntReqIntr( IREQ_8049 ); }
void AcpiOsRedirectOutput(void *Destination) { PRINTD("Not implemented AcpiOsRedirectOutput() called"); /* Not implemented. */ }
static int mem_op(unsigned long op, const char *resource, const char *device, const char *value) { unsigned long start; unsigned long end = 0; unsigned long data = 0; unsigned long increment = 0; char *temp; /* Op fields. */ int write = VALUE(op, RW); int color = VALUE(op, COLOR); int length = (1 << VALUE(op, LENGTH)); int ascii = VALUE(op, ASCII); /* File descriptor. */ int fd; PRINTD("%s: write %#x - color %#x - length %#x - ascii %#x\n", __FUNCTION__, write, color, length, ascii); /* Open device. */ fd = open(device ? device : DEVICE, (op & OPEN_SYNC) ? O_RDWR | O_SYNC : O_RDWR); if(fd == -1) { printf("Cannot open file descriptor...\n" "quitting...\n"); return EXIT_FAILURE; } /* Decoding of resource string. */ if(temp = strchr(resource, ':')) { *temp++ = '\0'; /* Set to zero the separator. */ start = hex_encoder(resource, 0); end = hex_encoder(temp, 0); } else { if(temp = strchr(resource, '+')) { *temp++ = '\0'; /* Set to zero the separator. */ start = hex_encoder(resource, 0); end = start + hex_encoder(temp, 0); } else { start = hex_encoder(resource, 0); end = start + length; } } if(value) { /* Decoding of value string. */ if(temp = strchr(value, '+')) { *temp++ = '\0'; /* Set to zero the separator. */ data = hex_encoder(value, 0); increment = hex_encoder(temp, 0); } else { data = hex_encoder(value, 0); } } PRINTD("%s: start %.8x - end %.8x - data %.8x - increment %.8x\n", __FUNCTION__, start, end, data, increment); memory_dumper(start, end, data, increment, write, color, length, ascii, fd); /* Close device. */ close(fd); return EXIT_SUCCESS; }
ACPI_STATUS AcpiOsTerminate(void) { PRINTD("AcpiOsTerminate() called"); return AE_OK; }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<SP-100); //don't overwrite our own stack } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); /* Leds are referred to by number to prevent any possible confusion :) */ /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */ Leds_init(); Led1_on(); /* Get a random (or probably different) seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference. ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock ADCSRA|=1<<ADSC; //Start conversion while (ADCSRA&(1<<ADSC)); //Wait till done PRINTD("ADC=%d\n",ADC); random_init(ADC); ADCSRA=0; //Disable ADC #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif #endif /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before USB or ctimer init */ process_start(&etimer_process, NULL); Led2_on(); /* Now we can start USB enumeration */ process_start(&usb_process, NULL); /* Start CDC enumeration, bearing in mind that it may fail */ /* Hopefully we'll get a stdout for startup messages, if we don't already */ #if USB_CONF_SERIAL process_start(&cdc_process, NULL); {unsigned short i; for (i=0;i<65535;i++) { process_run(); watchdog_periodic(); if (stdout) break; } #if !USB_CONF_RS232 PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif } #endif if (!stdout) Led3_on(); #if RF230BB #if JACKDAW_CONF_USE_SETTINGS PRINTA("Settings manager will be used.\n"); #else {uint8_t x[2]; *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel); if((uint8_t)x[0]!=(uint8_t)~x[1]) { PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n"); get_channel_from_eeprom(); } } #endif ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rf230_set_txpower(get_txpower_from_eeprom()); rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); PRINTA("%s %s, channel %u, panid 0x%X",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(), IEEE802154_PANID); if (NETSTACK_RDC.channel_check_interval) { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) PRINTA(", check rate %u Hz",tmp); } PRINTA("\n"); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTD ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTD ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTD ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF230BB */ /* Start ethernet network and storage process */ process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif /* Autostart other processes */ /* There are none in the default build so autostart_processes will be unresolved in the link. */ /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */ /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */ #if 0 autostart_start(autostart_processes); #endif #if ANNOUNCE #if USB_CONF_RS232 PRINTA("Online.\n"); #else PRINTA("Online. Type ? for Jackdaw menu.\n"); #endif #endif Leds_off(); }
void i2c_reg_write(uchar chip, uchar reg, uchar val) { PRINTD(("i2c_reg_write(chip=0x%02x, reg=0x%02x, val=0x%02x)\n",chip,reg,val)); i2c_write(chip, reg, 1, &val, 1); }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { #ifdef BUZZER buzz_id(); #endif watchdog_init(); watchdog_start(); clock_init(); PRINTD("\n\nChecking MCUSR...\n"); if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n"); if(MCUSR & (1<<EXTRF)) PRINTD("External reset!\n"); if(MCUSR & (1<<BORF )) PRINTD("Brownout reset!\n"); if(MCUSR & (1<<WDRF )) PRINTD("Watchdog reset!\n"); if(MCUSR & (1<<JTRF )) PRINTD("JTAG reset!\n"); MCUSR = 0; PRINTD("CLOCK_SECOND %d\n",CLOCK_SECOND); PRINTD("RTIMER_ARCH_SECOND %lu\n",RTIMER_ARCH_SECOND); PRINTD("F_CPU %lu\n",F_CPU); #if STACKMONITOR /* Simple stack pointer highwater monitor. Checks for magic numbers in the main * loop. In conjuction with PERIODICPRINTS, never-used stack will be printed * every STACKMONITOR seconds. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=10; } while (p<SP-10); //don't overwrite our own stack } #endif /* Calibrate internal mcu clock against external 32768Hz watch crystal */ #define CONF_CALIBRATE_OSCCAL 0 #if CONF_CALIBRATE_OSCCAL void calibrate_rc_osc_32k(); { extern uint8_t osccal_calibrated; uint8_t i; PRINTD("\nBefore calibration OSCCAL=%x\n",OSCCAL); for (i=0;i<10;i++) { calibrate_rc_osc_32k(); PRINTD("Calibrated=%x\n",osccal_calibrated); //#include <util/delay_basic.h> //#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) ) // delay_us(50000); } clock_init(); } #endif PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); leds_init(); leds_on(LEDS_RED); /* Initialize USART */ #ifdef CAMERA_INTERFACE camera_init(); #else init_usart(); #endif /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF2XXBB ds2401_init(); node_id_restore(); /* Get a random seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ random_init(rng_get_uint8()); ctimer_init(); init_net(); #else /* !RF2XXBB */ /* Original RF230 combined mac/radio driver */ /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF2XXBB */ /* Autostart other processes */ autostart_start(autostart_processes); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content PRINTA("No index.html file found, creating upload.html!\n"); PRINTA("Formatting FLASH file system for coffee..."); cfs_coffee_format(); PRINTA("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) PRINTA("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /* COFFEE_FILES */ /* Add addresses for testing */ #if 0 { uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); // uip_ds6_prefix_add(&ipaddr,64,0); } #endif /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT { #if AVR_WEBSERVER uint8_t i; char buf1[40],buf[40]; unsigned int size; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf); PRINTA("IPv6 Address: %s\n",buf); } } cli(); eeprom_read_block (buf1,eemem_server_name, sizeof(eemem_server_name)); eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name)); sei(); buf1[sizeof(eemem_server_name)]=0; PRINTA("%s",buf1); buf[sizeof(eemem_domain_name)]=0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES PRINTA(".%s online with fixed %u byte web content\n",buf,size); #elif COFFEE_FILES==1 PRINTA(".%s online with static %u byte EEPROM file system\n",buf,size); #elif COFFEE_FILES==2 PRINTA(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 PRINTA(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else PRINTA("Online\n"); #endif /* AVR_WEBSERVER */ #endif /* ANNOUNCE_BOOT */ } }
/* * i2c_read: - Read multiple bytes from an i2c device * * The higher level routines take into account that this function is only * called with len < page length of the device (see configuration file) * * @chip: address of the chip which is to be read * @addr: i2c data address within the chip * @alen: length of the i2c data address (1..2 bytes) * @buffer: where to write the data * @len: how much byte do we want to read * @return: 0 in case of success */ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) { struct mv_i2c_msg msg; u8 addr_bytes[3]; /* lowest...highest byte of data address */ PRINTD(("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, " "len=0x%02x)\n", chip, addr, alen, len)); i2c_reset(); /* dummy chip address write */ PRINTD(("i2c_read: dummy chip address write\n")); msg.condition = I2C_COND_START; msg.acknack = I2C_ACKNAK_WAITACK; msg.direction = I2C_WRITE; msg.data = (chip << 1); msg.data &= 0xFE; if (i2c_transfer(&msg)) return -1; /* * send memory address bytes; * alen defines how much bytes we have to send. */ /*addr &= ((1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)-1); */ addr_bytes[0] = (u8)((addr >> 0) & 0x000000FF); addr_bytes[1] = (u8)((addr >> 8) & 0x000000FF); addr_bytes[2] = (u8)((addr >> 16) & 0x000000FF); while (--alen >= 0) { PRINTD(("i2c_read: send memory word address byte %1d\n", alen)); msg.condition = I2C_COND_NORMAL; msg.acknack = I2C_ACKNAK_WAITACK; msg.direction = I2C_WRITE; msg.data = addr_bytes[alen]; if (i2c_transfer(&msg)) return -1; } /* start read sequence */ PRINTD(("i2c_read: start read sequence\n")); msg.condition = I2C_COND_START; msg.acknack = I2C_ACKNAK_WAITACK; msg.direction = I2C_WRITE; msg.data = (chip << 1); msg.data |= 0x01; if (i2c_transfer(&msg)) return -1; /* read bytes; send NACK at last byte */ while (len--) { if (len == 0) { msg.condition = I2C_COND_STOP; msg.acknack = I2C_ACKNAK_SENDNAK; } else { msg.condition = I2C_COND_NORMAL; msg.acknack = I2C_ACKNAK_SENDACK; } msg.direction = I2C_READ; msg.data = 0x00; if (i2c_transfer(&msg)) return -1; *buffer = msg.data; PRINTD(("i2c_read: reading byte (0x%08x)=0x%02x\n", (unsigned int)buffer, *buffer)); buffer++; } i2c_reset(); return 0; }
void logPacketTCP(int newSockSignal, ofstream *out) { int port; int newSockLog; struct sockaddr_in sockAddress; struct sockaddr_in srcAddress; int logSock, hold, hold2, dim2; struct info *infos = (struct info *) malloc(logbuffer_size * sizeof(info)); char *infosOffset; socklen_t sinLen = sizeof(srcAddress); fd_set activeSet; int dim_infos; #ifdef DEBUG int numRecvdPkt=0; int numTrip=0; #endif sockAddress.sin_family = AF_INET; sockAddress.sin_addr.s_addr = htonl(INADDR_ANY); createDataChannel(sockAddress,newSockSignal,logSock,port,"TCP"); if (listen(logSock, 5) < 0) reportErrorAndExit("logPacketTCP","listen","Error into listen on logSock"); newSockLog = accept(logSock, (struct sockaddr *) &srcAddress, &sinLen); PRINTD(1,"logPacketTCP: newSockLog TCP : %d \n",newSockLog); if (newSockLog < 0) reportErrorAndExit("logPacketTCP","accept","Error into accept on logSock"); while (1) { FD_ZERO(&activeSet); FD_SET((unsigned int)newSockSignal, &activeSet); FD_SET((unsigned int)newSockLog, &activeSet); if (select(FD_SETSIZE, &activeSet, NULL, NULL, 0) < 0) reportErrorAndExit("logPacketTCP","select", "Invalid file descriptor or operation interrupted by a signal - Close first Receiver"); if (FD_ISSET(newSockSignal, &activeSet)) { break; } else if (FD_ISSET(newSockLog, &activeSet)) { dim2 = logbuffer_size * sizeof(struct info); hold = 0; infosOffset = (char *)infos; do { hold2 = recv(newSockLog, (char *)infosOffset, dim2, 0); hold += hold2; dim2 -= hold2; infosOffset += hold2; } while (((hold % sizeof(struct info)) != 0) && (hold2 >= 0)); if (hold < 0) printf("** WARNING ** Data lost - Close First Receiver!\n"); else { dim_infos = hold / sizeof(struct info); infosntoh(infos, dim_infos); #ifdef DEBUG numRecvdPkt = numRecvdPkt + hold / sizeof(struct info); numTrip++; #endif if (!(*out).write((char *) infos, hold)) printf("** WARNING ** Can't write data!\n"); } } } #ifdef DEBUG char hostName[50]; char hostIP[20]; int rit1 = getnameinfo((sockaddr*)&senderLog,sizeof(senderLog),hostName, INET_ADDRSTRLEN, NULL, 0, NI_NOFQDN); int rit2 = getnameinfo((sockaddr*)&senderLog,sizeof(senderLog),hostIP, INET_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); if ((rit1 == 0) & (rit2 == 0)) printf("Data transmission ended on TCP channel from %s(%s)\n",hostName,hostIP); else if ((rit1 != 0) & (rit2 == 0)) printf("Data transmission ended on TCP channel from %s\n",hostIP); else #endif printf("Data transmission ended on TCP channel!\n"); fflush(stdout); free(infos); if (closeSock(logSock) < 0) reportErrorAndExit("logPacketTCP","closeSock","Cannot close logSock"); if (closeSock(newSockLog) < 0) reportErrorAndExit("logPacketTCP","closeSock","Cannot close newLogSock"); PRINTD(1,"logPacketTCP: Number of received packets : %d \n",numRecvdPkt); PRINTD(1,"logPacketTCP: Number of received infos : %d \n",numTrip); }
int main(int argc, char *argv[]) { char * filename = "fs"; int fd = 0; int counter = 0; int gb; // group block number if (argc >= 2) filename = argv[1]; fd = open(filename, O_RDWR); if (fd < 0) { printf("open file %s failed\n", filename); return 0; } printf("open file %s ok\n", filename); p = mmap(NULL, 1024*1024, PROT_WRITE, MAP_SHARED, fd, 0); close(fd); PRINTD(get_super_block()->s_inodes_count); PRINTD(get_super_block()->s_blocks_count); PRINTD(get_super_block()->s_log_block_size); PRINTD(get_super_block()->s_inode_size); PRINTD(get_super_block()->s_first_data_block); inode_size = get_super_block()->s_inode_size; block_size = 1024 << (get_super_block()->s_log_block_size); PRINTD(block_size); PRINTD(inode_size); group_block = get_super_block()->s_first_data_block + 1; gb = group_block; PRINTD(((struct ext2_group_desc *)get_block(gb))->bg_block_bitmap); PRINTD(((struct ext2_group_desc *)get_block(gb))->bg_inode_bitmap); PRINTD(((struct ext2_group_desc *)get_block(gb))->bg_inode_table); PRINTD(get_inode(2)->i_block[0]); //ls(); //cat("test.txt"); printf("\n"); while (1) { char buf[64]; char cmd[32]; char arg[32]; int ret = 0; printf("MyExt2 # "); //scanf("%s %s", cmd, arg); fgets(buf, 64, stdin); ret = sscanf(buf, "%s %s", cmd, arg); if (ret == 0) continue; PRINTS(cmd); PRINTS(arg); if (strcmp(cmd, "ls") == 0) ls(); if (strcmp(cmd, "cat") == 0) cat(arg); if (strcmp(cmd, "exit") == 0) break; } munmap(p, 1024*1024); return 0; }
/** * i2c_transfer: - Transfer one byte over the i2c bus * * This function can tranfer a byte over the i2c bus in both directions. * It is used by the public API functions. * * @return: 0: transfer successful * -1: message is empty * -2: transmit timeout * -3: ACK missing * -4: receive timeout * -5: illegal parameters * -6: bus is busy and couldn't be aquired */ int i2c_transfer(struct i2c_msg *msg) { int ret; if (!msg) goto transfer_error_msg_empty; switch(msg->direction) { case I2C_WRITE: /* check if bus is not busy */ if (!i2c_isr_set_cleared(0,ISR_IBB)) goto transfer_error_bus_busy; /* start transmission */ ICR &= ~ICR_START; ICR &= ~ICR_STOP; IDBR = msg->data; if (msg->condition == I2C_COND_START) ICR |= ICR_START; if (msg->condition == I2C_COND_STOP) ICR |= ICR_STOP; if (msg->acknack == I2C_ACKNAK_SENDNAK) ICR |= ICR_ACKNAK; if (msg->acknack == I2C_ACKNAK_SENDACK) ICR &= ~ICR_ACKNAK; ICR &= ~ICR_ALDIE; ICR |= ICR_TB; /* transmit register empty? */ if (!i2c_isr_set_cleared(ISR_ITE,0)) goto transfer_error_transmit_timeout; /* clear 'transmit empty' state */ ISR |= ISR_ITE; /* wait for ACK from slave */ if (msg->acknack == I2C_ACKNAK_WAITACK) if (!i2c_isr_set_cleared(0,ISR_ACKNAK)) goto transfer_error_ack_missing; break; case I2C_READ: /* check if bus is not busy */ if (!i2c_isr_set_cleared(0,ISR_IBB)) goto transfer_error_bus_busy; /* start receive */ ICR &= ~ICR_START; ICR &= ~ICR_STOP; if (msg->condition == I2C_COND_START) ICR |= ICR_START; if (msg->condition == I2C_COND_STOP) ICR |= ICR_STOP; if (msg->acknack == I2C_ACKNAK_SENDNAK) ICR |= ICR_ACKNAK; if (msg->acknack == I2C_ACKNAK_SENDACK) ICR &= ~ICR_ACKNAK; ICR &= ~ICR_ALDIE; ICR |= ICR_TB; /* receive register full? */ if (!i2c_isr_set_cleared(ISR_IRF,0)) goto transfer_error_receive_timeout; msg->data = IDBR; /* clear 'receive empty' state */ ISR |= ISR_IRF; break; default: goto transfer_error_illegal_param; } return 0; transfer_error_msg_empty: PRINTD(("i2c_transfer: error: 'msg' is empty\n")); ret = -1; goto i2c_transfer_finish; transfer_error_transmit_timeout: PRINTD(("i2c_transfer: error: transmit timeout\n")); ret = -2; goto i2c_transfer_finish; transfer_error_ack_missing: PRINTD(("i2c_transfer: error: ACK missing\n")); ret = -3; goto i2c_transfer_finish; transfer_error_receive_timeout: PRINTD(("i2c_transfer: error: receive timeout\n")); ret = -4; goto i2c_transfer_finish; transfer_error_illegal_param: PRINTD(("i2c_transfer: error: illegal parameters\n")); ret = -5; goto i2c_transfer_finish; transfer_error_bus_busy: PRINTD(("i2c_transfer: error: bus is busy\n")); ret = -6; goto i2c_transfer_finish; i2c_transfer_finish: PRINTD(("i2c_transfer: ISR: 0x%04x\n",ISR)); i2c_reset(); return ret; }
void *AcpiOsAllocate(ACPI_SIZE Size) { PRINTD("AcpiOsAllocate() called"); return malloc(Size); }