/** * \brief Read one byte of data from QT1070 Register. * * \param pTwid Pointer to twi driver structure. * \param regAddr Register address to read. * \return value in the given register. */ static uint8_t QT1070_ReadReg(Twid *pTwid, uint8_t regAddr) { uint8_t data; TWID_Write(pTwid, QT1070_SLAVE_ADDRESS, 0, 0, ®Addr, 1, 0); TWID_Read(pTwid, QT1070_SLAVE_ADDRESS, 0, 0, &data, 1, 0); return data; }
//------------------------------------------------------------------------------ /// Initialize EEPROM devices and transfer one or sevral modules from EEPROM to the /// target memory (SRAM/SDRAM). /// \param pTd Pointer to transfer descriptor array. /// \param nbTd Number of transfer descriptors. //------------------------------------------------------------------------------ int BOOT_EEPROM_CopyBin(const Tdesc *pTd, unsigned char nbTd) { unsigned char *pDest; // Dest pointer for copy unsigned int sizeToCopy; // remaining bytes number to copy unsigned int memoryOffset; // Dataflash read offset unsigned int packetSize; // Dataflash read size Async async; // Initialize EEPROM EepromInit(); // Check word alignment if (pTd->offset % PAGE_SIZE) { TRACE_ERROR("Offset not word aligned\n\r"); return BOOT_EEPROM_ERROR_GP; } // Transfert data from EEPROM to External RAM //------------------------------------------------------------------------- memset(&async, 0, sizeof(async)); async.callback = (void *) TestCallback; // Foreach module transfer data from EEPROM to memory while (nbTd--) { TRACE_INFO("Copy \"%s\" (%d bytes) from EEPROM 0x%08x to 0x%08x\n\r", pTd->strDescr, pTd->size, pTd->offset, pTd->dest ); pDest = (unsigned char*)pTd->dest; sizeToCopy = pTd->size; memoryOffset = pTd->offset; while (sizeToCopy > 0) { // Write packet after packets packetSize = (sizeToCopy < PAGE_SIZE) ? sizeToCopy : PAGE_SIZE; // Read the page and copy TWID_Read(&twid, AT24C_ADDRESS, memoryOffset, 2, pDest, PAGE_SIZE, &async); while (!ASYNC_IsFinished(&async)); // Update pointer memoryOffset += packetSize; pDest += packetSize; sizeToCopy -= packetSize; } ++pTd; } return BOOT_EEPROM_SUCCESS; }
/** * \brief Read data from WM8904 Register. * * \param pTwid Pointer to twi driver structure * \param device Twi slave address. * \param regAddr Register address to read. * \return value in the given register. */ uint16_t WM8904_Read(Twid *pTwid, uint32_t device, uint32_t regAddr) { uint16_t bitsDataRegister; uint8_t Tdata[2]= {0,0}; TWID_Read(pTwid, device, regAddr, 1, Tdata, 2, 0); bitsDataRegister = (Tdata[0] << 8) | Tdata[1]; return bitsDataRegister; }
/** * \brief Read a value from a register in an OV sensor device. * \param pTwid TWI interface * \param reg Register to be read * \param isize Internal address size in bytes. * \param pData Data read * \return 0 if no error; otherwize TWID_ERROR_BUSY */ uint8_t ov_read_reg8(Twid *pTwid, uint8_t reg, uint8_t *pData) { uint8_t status; status = TWID_Write( pTwid, twiSlaveAddr, 0, 0, ®, 1, 0); status |= TWID_Read( pTwid, twiSlaveAddr, 0, 0, pData, 1, 0); if( status != 0 ) { TRACE_ERROR("ov_read_reg pb\n\r"); } return status; }
void bmo_read_registers(const uint8_t reg, uint8_t *data, const uint8_t length) { mutex_take(mutex_twi_bricklet, MUTEX_BLOCKING); TWID_Read(&twid, BMO055_ADDRESS_HIGH, reg, 1, data, length, NULL); mutex_give(mutex_twi_bricklet); }
uint8_t e4k_reg_read(struct e4k_state *e4k, uint8_t reg) { unsigned char rc; uint8_t val; rc = TWID_Read(e4k->i2c_dev, e4k->i2c_addr, reg, 1, &val, 1, NULL); if (rc != 0) { LOGP(DTUN, LOGL_ERROR, "Error %u in TWID_Read\n", rc); return -EIO; } return val; }
short lm75_read_temperature(void) { char Val[2]; short TempReg; #ifdef GPIO_SIM_I2C i2c_read_double(LM75_ADDR, &Val[0], &Val[1]); #else unsigned char cmd = LM75_CMD_ADC0; TWID_Read(&twid, LM75_ADDR, 0x0000, 0, &Val, 2, 0); #endif TempReg = Val[0]<<1 ; TempReg += Val[1]>>7; return TempReg; }
/** * \brief Read a value from a register in an OV sensor device. * \param pTwid TWI interface * \param reg Register to be read * \param pData Data read * \return 0 if no error; otherwise TWID_ERROR_BUSY */ uint8_t ov_read_reg16(Twid *pTwid, uint16_t reg, uint8_t *pData) { uint8_t status; uint8_t reg8[2]; reg8[0] = reg>>8; reg8[1] = reg & 0xff; status = TWID_Write( pTwid, twiSlaveAddr, 0, 0, reg8, 2, 0); status |= TWID_Read( pTwid, twiSlaveAddr, 0, 0, pData, 1, 0); if( status != 0 ) { TRACE_ERROR("ov_read_reg pb\n\r"); } return status; }
/** * \brief gmac_uip_telnetd example entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; uint32_t i; struct uip_eth_addr OrigiGMacAddr; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); TimeTick_Configure(); printf("-- GMAC uIP Telnetd Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Configure TWI pins. */ PIO_Configure(twiPins, PIO_LISTSIZE(twiPins)); /* Enable TWI */ PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM); TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK); TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM); /* Display MAC & IP settings */ TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x9A, 1, OrigiGMacAddr.addr, PAGE_SIZE, 0); if ((OrigiGMacAddr.addr[0] == 0xFC) && (OrigiGMacAddr.addr[1] == 0xC2) && (OrigiGMacAddr.addr[2] == 0x3D)) { for (i = 0; i < 6; i++) GMacAddress.addr[i] = OrigiGMacAddr.addr[i]; } printf("-- MAC %x:%x:%x:%x:%x:%x\n\r", GMacAddress.addr[0], GMacAddress.addr[1], GMacAddress.addr[2], GMacAddress.addr[3], GMacAddress.addr[4], GMacAddress.addr[5]); #ifndef __DHCPC_H__ printf(" - Host IP %d.%d.%d.%d\n\r", HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); printf(" - Router IP %d.%d.%d.%d\n\r", RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); printf(" - Net Mask %d.%d.%d.%d\n\r", NetMask[0], NetMask[1], NetMask[2], NetMask[3]); #endif /* System devices initialize */ gmac_tapdev_setmac((uint8_t *)GMacAddress.addr); gmac_tapdev_init(); clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); /* Init uIP */ uip_init(); #ifdef __DHCPC_H__ printf("P: DHCP Supported\n\r"); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #else /* Set the IP address of this host */ uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]); uip_setnetmask(ipaddr); #endif uip_setethaddr(GMacAddress); _app_init(); while (1) { uip_len = gmac_tapdev_read(); if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) gmac_tapdev_send(); } } else if (timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for (i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } #if UIP_UDP for (i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if (timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }
extern int main( void ) { volatile uint32_t delay; uint8_t i; uint8_t SNo[16]; Async async; /* Disable watchdog */ WDT_Disable( WDT ) ; /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); CallBackFired = 0; /* Output example information */ printf("-- TWI EEPROM Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); TimeTick_Configure(); /* Configure TWI pins. */ PIO_Configure(pins, PIO_LISTSIZE(pins)); PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM); /* Configure TWI */ twi_dma.pTwid = malloc(sizeof(Twid)); twi_dma.pTwiDma = malloc(sizeof(sXdmad)); TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK); TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM); TWID_DmaInitialize(&twi_dma, BOARD_BASE_TWI_EEPROM, 0); TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x80, 1, SNo, PAGE_SIZE, 0); /* Erase all page */ memset(pData, 0, PAGE_SIZE); for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Filling page #%d with zeroes ...\r\n", i); TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0); /* Wait at least 10 ms */ Wait(10); } printf("\r\n"); _fillBuffer(pData); /* Synchronous operation */ for(i=0; i< EEPROM_PAGES; i++) { printf("\n\r-I- Filling page #%d with checkerboard pattern ...\r", i); TWID_DmaWrite(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0); /* Wait at least 10 ms */ Wait(10); } printf("\r\n"); /* Read back data */ memset(pData, 0, PAGE_SIZE); for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Reading page #%d... ", i); TWID_DmaRead(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0); /* Wait at least 10 ms */ Wait(10); _checkReadBuffer(pData); } printf("\r\n"); /* Configure TWI interrupts */ NVIC_ClearPendingIRQ(TWIHS0_IRQn); NVIC_EnableIRQ(TWIHS0_IRQn); /* Asynchronous operation */ printf("-I- Read/write on page #0 (IRQ mode)\n\r"); /* Write checkerboard pattern in first page */ _fillBuffer(pData); memset(&async, 0, sizeof(async)); async.callback = (void *) TestCallback; for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Filling page #%d with checkerboard pattern ...\r", i); TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async); while (!ASYNC_IsFinished(&async)); /* Wait at least 10 ms */ Wait(10); } printf("\r\n"); /* Read back data */ memset(pData, 0, PAGE_SIZE); memset(&async, 0, sizeof(async)); async.callback = (void *) TestCallback; for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Reading page # %d...\r", i); TWID_Read(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async); while ( !ASYNC_IsFinished( &async ) ) ; /* Wait at least 10 ms */ Wait(10); _checkReadBuffer(pData); } printf("\r\n Callback Fired %d times", CallBackFired); return 0 ; }
void eeprom_readBytes(uint32_t address, uint8_t *buf, uint32_t len) { TWID_Read(&twid, 0x50, address, 0x01, buf, len, 0); }