void register_read_test ( void ) { unsigned i; for ( i = 0; i <= ETH_TXCTRL; i += 4 ) { uart_print( UART1_BASE_ADDR, "Ethernet register at address 0x"); uart_print_hex( UART1_BASE_ADDR, i, 4 ); uart_print( UART1_BASE_ADDR, ", value 0x" ); uart_print_hex( UART1_BASE_ADDR, REG32( ETH_BASE + i ), 8 ); uart_print( UART1_BASE_ADDR, "." EOL ); } const uint32_t tx_bd_count = REG32( ETH_BASE + ETH_TX_BD_NUM ); for ( i = 0; i < BUFFER_DESCRIPTOR_COUNT; ++i ) { if ( i < tx_bd_count ) { uart_print( UART1_BASE_ADDR, "Ethernet Tx Buffer Descriptor "); } else { uart_print( UART1_BASE_ADDR, "Ethernet Rx Buffer Descriptor "); } uart_print_unsigned( UART1_BASE_ADDR, i ); uart_print( UART1_BASE_ADDR, ", flags 0x" ); uart_print_hex( UART1_BASE_ADDR, REG32( get_bd_status_addr( i ) ), 8 ); uart_print( UART1_BASE_ADDR, ", addr 0x" ); uart_print_hex( UART1_BASE_ADDR, REG32( get_bd_ptr_addr( i ) ), 8 ); uart_print( UART1_BASE_ADDR, "." EOL ); } }
void copy_bl2_to_sram(void){ uint32_t *load_address =(uint32_t*) (0xD0020FB0); // SRAM BL1 start address + 16k (binary kilo) debug_print("Copying BL2 started ...\n\r"); void (*BL2)(void); uint32_t channel = 0; copy_mmc_to_mem copy_func = (copy_mmc_to_mem) (*(uint32_t *) 0xD0037F98); //SdMccCopyToMem function from iROM documentation uint32_t ret = copy_func(channel, 33, COPY_BL2_SIZE/512,load_address, 0); if(ret == 1){ debug_print("BL2 loading successful, running it ...\n\r"); debug_print("The address where BL2 should be contains:\n\r"); uart_print_hex(*load_address); BL2 = (void*) load_address; (*BL2)(); // dereferencing and running ... }else{ debug_print("BL2 loading failed :-(\n\r"); } }
/** ******************************************************************************* * @brief Print task. * @param[in] pdata A pointer to parameter passed to task. * @param[out] None * @retval None * * @details This task print adc value by UART. ******************************************************************************* */ void uart_print(void *pdata) { int AD_value; pdata = pdata; for (;;) { CoEnterMutexSection(mut_uart); /*!< Enter mutex area. */ AD_value = ADC_ConvertedValue; uart_printf ("\r AD value = 0x"); uart_print_hex (AD_value,4); CoLeaveMutexSection(mut_uart); /*!< Leave mutex area. */ CoTickDelay(100); } }
static void print_mac_address ( const unsigned char * const addr ) { uart_print_hex( UART1_BASE_ADDR, addr[0], 2 ); uart_print_char( UART1_BASE_ADDR, ':' ); uart_print_hex( UART1_BASE_ADDR, addr[1], 2 ); uart_print_char( UART1_BASE_ADDR, ':' ); uart_print_hex( UART1_BASE_ADDR, addr[2], 2 ); uart_print_char( UART1_BASE_ADDR, ':' ); uart_print_hex( UART1_BASE_ADDR, addr[3], 2 ); uart_print_char( UART1_BASE_ADDR, ':' ); uart_print_hex( UART1_BASE_ADDR, addr[4], 2 ); uart_print_char( UART1_BASE_ADDR, ':' ); uart_print_hex( UART1_BASE_ADDR, addr[5], 2 ); }
int main(int argc, char const *argv[]) { unsigned flit; unsigned flit_type; unsigned payload; unsigned packet_counter = 1; /* Test UART */ setup_uart(CPU_SPEED, UART_BAUDRATE); uart_puts("UART TEST: If you can read this, then UART output works!\n"); #if (UART_IN_TEST == 1) uart_puts("Please press letter 'b' on the UART terminal:\n"); char uart_in = uart_getch(); if (uart_in == 'b') { uart_puts("UART INPUT TEST PASSED!\n\n"); } else { uart_puts("UART INPUT TEST FAILED!\n"); uart_puts("Received following letter: {ASCII:HEX}\n"); uart_putchar(uart_in); uart_putchar(':'); uart_print_hex(uart_in); uart_puts("\n\n"); } #endif #if (GPIO_TEST == 1) /* Test GPIO */ unsigned gpio_in = memory_read(GPIOA_IN); memory_write(GPIO0_SET, gpio_in); #endif uart_puts("\n\nBeginning communication test\n\n"); ni_write(build_header(DST_ADDR, 3)); ni_write(0b1111111111111111111111111111); ni_write(0); while (packet_counter <= SEND_PACKET_COUNT) { if ((ni_read_flags() & NI_READ_MASK) == 0) { flit = ni_read(); flit_type = get_flit_type(flit); if (flit_type == FLIT_TYPE_HEADER) { uart_puts("Sending packet number "); uart_print_num(packet_counter, 10, 0); uart_putchar('\n'); ni_write(build_header(DST_ADDR, 3)); packet_counter++; } else { payload = get_flit_payload(flit); ni_write(payload); } } } /* Run CPU test */ test_plasma_funcitons(); return 0; }
static void uart_print_address(uint32_t *address){ uart_print_hex(address); }
static void uart_print_address_contents(uint32_t *address){ uart_print_hex(*address); }
int main ( void ) { int_init(); // This is specific for OpenRISC, you may need to call some other routine here // in order to initialise interrupt support and so on. // We use a serial port console to display informational messages. init_uart( UART1_BASE_ADDR ); uart_print( UART1_BASE_ADDR, "This is the Ethernet example program." EOL ); init_ethernet(); int_add( ETH_IRQ, ð_interrupt, NULL ); // Use an Ethernet sniffer like Wireshark in order to see the test frame sent. uart_print( UART1_BASE_ADDR, "Sending the first test frame (which has invalid protocol contents)..." EOL ); int pos = 0; write_broadcast_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; write_own_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; eth_tx_packet[ pos + 0 ] = 0x10; eth_tx_packet[ pos + 1 ] = 0x20; eth_tx_packet[ pos + 2 ] = 0x30; eth_tx_packet[ pos + 3 ] = 0x40; eth_tx_packet[ pos + 4 ] = 0x50; eth_tx_packet[ pos + 5 ] = 0x60; pos += 6; int fill_to_end = 0; if ( fill_to_end ) { while ( pos < MAX_FRAME_LEN ) { eth_tx_packet[ pos ] = (unsigned char) pos; ++pos; } } start_ethernet_send( pos ); wait_until_frame_was_sent(); uart_print( UART1_BASE_ADDR, "Sending the second test frame (which has invalid protocol contents)..." EOL ); pos = 0; write_broadcast_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; write_own_mac_addr( ð_tx_packet[ pos ] ); pos += MAC_ADDR_LEN; eth_tx_packet[ pos + 0 ] = 0x11; eth_tx_packet[ pos + 1 ] = 0x22; eth_tx_packet[ pos + 2 ] = 0x33; eth_tx_packet[ pos + 3 ] = 0x44; eth_tx_packet[ pos + 4 ] = 0x55; eth_tx_packet[ pos + 5 ] = 0x66; pos += 6; start_ethernet_send( pos ); wait_until_frame_was_sent(); const int dump_all_register_values = 0; if ( dump_all_register_values ) { register_read_test(); } // Main infinite loop. // // Wait for incoming frames, dump their contents and reply to a single type of ARP request. // See the README file for an example on how to generate the right type of APR request with arping. for ( ; ; ) { uart_print( UART1_BASE_ADDR, "Waiting for a frame to be received..." EOL ); REG32( get_bd_ptr_addr( s_current_rx_bd_index ) ) = (unsigned long) eth_rx_packet; uint32_t receive_flags = ETH_RXBD_EMPTY | ETH_RXBD_IRQ; if ( s_current_rx_bd_index == BUFFER_DESCRIPTOR_COUNT - 1 ) receive_flags += ETH_RXBD_WRAP; REG32( get_bd_status_addr( s_current_rx_bd_index ) ) = receive_flags; uint32_t status; for ( ; ; ) { status = REG32( get_bd_status_addr( s_current_rx_bd_index ) ); if ( 0 == ( status & ETH_RXBD_EMPTY ) ) { uart_print( UART1_BASE_ADDR, "Frame received." EOL ); break; } } if ( status & ( ETH_RXBD_OR | ETH_RXBD_IS | ETH_RXBD_DN | ETH_RXBD_TL | ETH_RXBD_SF | ETH_RXBD_CRC | ETH_RXBD_LC ) ) { uart_print( UART1_BASE_ADDR, "Error receiving frame, rx status is: " ); uart_print_hex( UART1_BASE_ADDR, status, 8 ); uart_print( UART1_BASE_ADDR, EOL ); } else { const int eth_rx_len = ( status >> 16 ); const int should_dump_frame_contents = 0; if ( should_dump_frame_contents ) { uart_print( UART1_BASE_ADDR, "Received length: " ); uart_print_int( UART1_BASE_ADDR, eth_rx_len ); uart_print( UART1_BASE_ADDR, EOL ); uart_print( UART1_BASE_ADDR, "Frame data: " ); int i; for ( i = 0; i < eth_rx_len; i++ ) { uart_print_hex( UART1_BASE_ADDR, eth_rx_packet[i], 2 ); uart_print( UART1_BASE_ADDR," " ); } uart_print( UART1_BASE_ADDR, EOL "End of received data." EOL ); } if ( ! process_received_frame( eth_rx_len ) ) { uart_print( UART1_BASE_ADDR, "The received frame has been ignored." EOL ); } } ++s_current_rx_bd_index; if ( s_current_rx_bd_index == BUFFER_DESCRIPTOR_COUNT ) s_current_rx_bd_index = TX_BD_COUNT; } }