void uos_init (void) { /* Configure 16 Mbyte of external Flash memory at nCS3. */ MC_CSCON3 = MC_CSCON_WS (4); /* Wait states */ /* Выделяем место для динамической памяти */ extern unsigned __bss_end[]; #ifdef ELVEES_DATA_SDRAM /* Динамическая память в SDRAM */ if (((unsigned) __bss_end & 0xF0000000) == 0x80000000) mem_init (&pool, (unsigned) __bss_end, 0x82000000); else mem_init (&pool, (unsigned) __bss_end, 0xa2000000); #else /* Динамическая память в CRAM */ extern unsigned _estack[]; mem_init (&pool, (unsigned) __bss_end, (unsigned) _estack - 256); #endif timer_init (&timer, KHZ, 20); /* * Create a group of two locks: timer and eth. */ mutex_group_t *g = mutex_group_init (group, sizeof(group)); mutex_group_add (g, ð->netif.lock); mutex_group_add (g, &timer.decisec); arp = arp_init (arp_data, sizeof(arp_data), &ip); ip_init (&ip, &pool, 70, &timer, arp, g); /* * Create interface eth0 */ const unsigned char my_macaddr[] = { 0, 9, 0x94, 0xf1, 0xf2, 0xf3 }; eth_init (eth, "eth0", 80, &pool, arp, my_macaddr); unsigned char my_ip[] = { 172, 0, 0, 18 }; route_add_netif (&ip, &route, my_ip, 24, ð->netif); h_udp_task = task_create (udp_task, 0, "udp", 65, stack_udp, sizeof (stack_udp)); init_trace(); }
void uos_init (void) { debug_printf ("\n\nTesting I2C...\n"); /* Configure 16 Mbyte of external Flash memory at nCS3. */ MC_CSCON3 = MC_CSCON_WS (4); /* Wait states */ MC_I2C_CTR = MC_I2C_PRST; MC_I2C_CTR = MC_I2C_EN; MC_I2C_PRER = KHZ / (5 * I2C_SPEED) - 1; /* Set address pointer register to select temperature */ debug_printf ("Setting address pointer register up\n"); MC_I2C_TXR = SLAVE_ADDR; MC_I2C_CR = MC_I2C_SND | MC_I2C_STA; udelay (1); while (MC_I2C_SR & MC_I2C_TIP); if (MC_I2C_SR & MC_I2C_AL) debug_printf ("Arbitration lost\n"); debug_printf ("SR = %02X, CR = %02X\n", MC_I2C_SR, MC_I2C_CR); MC_I2C_TXR = 0; MC_I2C_CR = MC_I2C_SND | MC_I2C_STO; udelay (1); while (MC_I2C_SR & MC_I2C_TIP); if (MC_I2C_SR & MC_I2C_AL) debug_printf ("Arbitration lost\n"); debug_printf ("SR = %02X, CR = %02X\n", MC_I2C_SR, MC_I2C_CR); /* Read 2-byte temperature value */ debug_printf ("Reading temperature value\n"); MC_I2C_TXR = SLAVE_ADDR | I2C_READ_OP; MC_I2C_CR = MC_I2C_SND | MC_I2C_STA; udelay (1); while (MC_I2C_SR & MC_I2C_TIP); if (MC_I2C_SR & MC_I2C_AL) debug_printf ("Arbitration lost\n"); debug_printf ("SR = %02X, CR = %02X\n", MC_I2C_SR, MC_I2C_CR); MC_I2C_CR = MC_I2C_RCV; udelay (1); while (MC_I2C_SR & MC_I2C_TIP); if (MC_I2C_SR & MC_I2C_AL) debug_printf ("Arbitration lost\n"); debug_printf ("SR = %02X, CR = %02X\n", MC_I2C_SR, MC_I2C_CR); int8_t hi_byte = MC_I2C_RXR; debug_printf ("Read: %02X\n", hi_byte); MC_I2C_CR = MC_I2C_RCV | MC_I2C_NACK | MC_I2C_STO; udelay (1); while (MC_I2C_SR & MC_I2C_TIP); if (MC_I2C_SR & MC_I2C_AL) debug_printf ("Arbitration lost\n"); debug_printf ("SR = %02X, CR = %02X\n", MC_I2C_SR, MC_I2C_CR); uint8_t low_byte = MC_I2C_RXR; debug_printf ("Read: %02X\n", low_byte); int16_t temp = ((hi_byte << 8) | low_byte) >> 6; debug_printf ("temp = %04X, approx. %d\n", temp, hi_byte); }