OpenCores
URL https://opencores.org/ocsvn/minsoc/minsoc/trunk

Subversion Repositories minsoc

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /minsoc/trunk/sw
    from Rev 36 to Rev 11
    Reverse comparison

Rev 36 → Rev 11

/drivers/Makefile File deleted
/drivers/i2c.c File deleted
/drivers/interrupts.c File deleted
/drivers/tick.h File deleted
/drivers/uart.h File deleted
/drivers/eth.c File deleted
/drivers/can.c File deleted
/drivers/i2c.h File deleted
/drivers/eth.h File deleted
/drivers/can.h File deleted
/drivers/tick.c File deleted
/drivers/uart.c File deleted
/support/Makefile.inc
4,7 → 4,7
 
#GCC_LIB_OPTS= -lgcc -liberty
 
GCC_OPT=-mhard-mul -g -nostdlib
GCC_OPT=-mhard-mul -g
 
ifdef UART_PRINTF
GCC_OPT += -DUART_PRINTF
/support/except.S
64,7 → 64,7
 
l.movhi r9,hi(end_except) //set return addr to end_except instruction
l.ori r9,r9,lo(end_except) //set return addr to end_except instruction
l.j _tick_except
l.j _lpint_except
l.nop
 
.org 0x400
106,7 → 106,7
 
l.movhi r9,hi(end_except) //set return addr to end_except instruction
l.ori r9,r9,lo(end_except) //set return addr to end_except instruction
l.j _ext_except //jmp to C interrupt handler (returns later to end_except)
l.j _hpint_except //jmp to C interrupt handler (returns later to end_except)
l.nop
 
 
/support/uart.c
29,7 → 29,7
 
void uart_init(void)
{
int divisor;
int devisor;
/* Reset receiver and transmiter */
/* Set RX interrupt for each byte */
36,16 → 36,16
REG8(UART_BASE + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_1;
/* Enable RX interrupt */
REG8(UART_BASE + UART_IER) = UART_IER_RDI | UART_IER_THRI;
REG8(UART_BASE + UART_IER) = 0x01;
/* Set 8 bit char, 1 stop bit, no parity */
REG8(UART_BASE + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY);
/* Set baud rate */
divisor = IN_CLK/(16 * UART_BAUD_RATE);
devisor = IN_CLK/(16 * UART_BAUD_RATE);
REG8(UART_BASE + UART_LCR) |= UART_LCR_DLAB;
REG8(UART_BASE + UART_DLL) = divisor & 0x000000ff;
REG8(UART_BASE + UART_DLM) = (divisor >> 8) & 0x000000ff;
REG8(UART_BASE + UART_DLL) = devisor & 0x000000ff;
REG8(UART_BASE + UART_DLM) = (devisor >> 8) & 0x000000ff;
REG8(UART_BASE + UART_LCR) &= ~(UART_LCR_DLAB);
return;
/support/support.c
15,9 → 15,24
#endif
 
#if OR32
void excpt_dummy();
void int_main();
 
void ext_except()
unsigned long excpt_buserr = (unsigned long) excpt_dummy;
unsigned long excpt_dpfault = (unsigned long) excpt_dummy;
unsigned long excpt_ipfault = (unsigned long) excpt_dummy;
unsigned long excpt_tick = (unsigned long) excpt_dummy;
unsigned long excpt_align = (unsigned long) excpt_dummy;
unsigned long excpt_illinsn = (unsigned long) excpt_dummy;
unsigned long excpt_int = (unsigned long) int_main;
unsigned long excpt_dtlbmiss = (unsigned long) excpt_dummy;
unsigned long excpt_itlbmiss = (unsigned long) excpt_dummy;
unsigned long excpt_range = (unsigned long) excpt_dummy;
unsigned long excpt_syscall = (unsigned long) excpt_dummy;
unsigned long excpt_break = (unsigned long) excpt_dummy;
unsigned long excpt_trap = (unsigned long) excpt_dummy;
 
void hpint_except()
{
int_main();
}
44,7 → 59,7
#define PRINTFBUFFER_SIZE 512
char PRINTFBUFFER[PRINTFBUFFER_SIZE]; // Declare a global printf buffer
 
void minsoc_printf(const char *fmt, ...)
void printf(const char *fmt, ...)
{
// init uart if not done already
if (!uart_init_done)
67,11 → 82,12
uart_putc(PRINTFBUFFER[c++]);
va_end(args);
}
 
#else
/* activate printf support in simulator */
void minsoc_printf(const char *fmt, ...)
void printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
165,3 → 181,6
}
 
#endif
 
 
void excpt_dummy() {}
/support/vfnprintf.c
96,7 → 96,7
 
// INCLUDES
 
//#include <stdlib.h> // For mbtowc()
#include <stdlib.h> // For mbtowc()
#include <stddef.h>
 
 
113,6 → 113,9
CYG_MACRO_END
 
#include <stdarg.h> // Variable argument definitions
//#include <stdio.h> // Standard header for all stdio files
#include <string.h> // memchr() and strlen() functions
//#include <cyg/libc/stdio/stream.hxx> // C library streams
 
#include "vfnprintf.h"
 
147,31 → 150,7
#define FPT 0x100 /* Floating point number */
#define SIZET 0x200 /* size_t */
 
int
strlen(const char *s)
{
const char *p;
 
for (p = s; *p != '\0'; p++)
;
return (s - p);
}
 
void *
memcpy(void *dst, const void *src, size_t len)
{
const char *csrc;
char *cdst;
int i;
 
cdst = dst;
csrc = src;
for (i = len; i >= 0; i--) {
cdst[i] = csrc[i];
}
return dst;
}
 
// Function which prints back to the buffer, ptr, len bytes
// returns 1 if it should finish up, otherwise 0 to continue
int print_back_to_string(char * ptr, int len, size_t * n, int * ret, char ** stream)
/support/support.h
16,7 → 16,7
#define REG16(add) *((volatile unsigned short *)(add))
#define REG32(add) *((volatile unsigned long *)(add))
 
void or32_printf(const char *fmt, ...);
void printf(const char *fmt, ...);
 
/* For writing into SPR. */
void mtspr(unsigned long spr, unsigned long value);
30,8 → 30,6
 
#endif /* OR1K */
 
#define printf or32_printf
 
/* Function to be called at entry point - not defined here. */
int main ();
 
65,5 → 63,4
extern unsigned long excpt_break;
extern unsigned long excpt_trap;
 
 
#endif /* SUPPORT_H */
#endif
/support/board.h
21,11 → 21,6
#define UART_IRQ 2
#define ETH_BASE 0x92000000
#define ETH_IRQ 4
#define I2C_BASE 0x9D000000
#define I2C_IRQ 3
#define CAN_BASE 0x94000000
#define CAN_IRQ 5
 
#define MC_BASE_ADDR 0x60000000
#define SPI_BASE 0xa0000000
 
/support/Makefile
1,3 → 1,5
include Makefile.inc
 
all: libsupport.a reset-nocache.o reset-ic.o reset-dc.o reset-icdc.o
 
libsupport.a: support.o int.o except.o uart.o vfnprintf.o
33,5 → 35,3
 
int.o: int.c
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) -c -o $@ $?
 
include Makefile.inc
/eth/eth.c
1,32 → 1,202
#include "../support/support.h"
#include "../support/board.h"
#include "../support/uart.h"
 
#include "../support/spr_defs.h"
 
#include "../drivers/uart.h"
#include "../drivers/eth.h"
#include "eth.h"
 
void uart_print_str(char *);
void uart_print_long(unsigned long);
 
extern int eth_rx_len;
extern int eth_rx_done, eth_tx_done;
extern unsigned char * eth_rx_data;
extern unsigned char * eth_tx_data;
// Dummy or32 except vectors
void buserr_except(){}
void dpf_except(){}
void ipf_except(){}
void lpint_except(){}
void align_except(){}
void illegal_except(){}
/*void hpint_except(){
 
}*/
void dtlbmiss_except(){}
void itlbmiss_except(){}
void range_except(){}
void syscall_except(){}
void res1_except(){}
void trap_except(){}
void res2_except(){}
 
 
void uart_interrupt()
{
char lala;
unsigned char interrupt_id;
interrupt_id = REG8(UART_BASE + UART_IIR);
if ( interrupt_id & UART_IIR_RDI )
{
lala = uart_getc();
uart_putc(lala+1);
}
 
}
 
 
void uart_print_str(char *p)
{
while(*p != 0) {
uart_putc(*p);
p++;
}
}
 
void uart_print_long(unsigned long ul)
{
int i;
char c;
 
uart_print_str("0x");
for(i=0; i<8; i++) {
 
c = (char) (ul>>((7-i)*4)) & 0xf;
if(c >= 0x0 && c<=0x9)
c += '0';
else
c += 'a' - 10;
uart_putc(c);
}
 
}
 
void uart_print_short(unsigned long ul)
{
int i;
char c;
char flag=0;
 
uart_print_str("0x");
for(i=0; i<8; i++) {
 
c = (char) (ul>>((7-i)*4)) & 0xf;
if(c >= 0x0 && c<=0x9)
c += '0';
else
c += 'a' - 10;
if ((c != '0') || (i==7))
flag=1;
if(flag)
uart_putc(c);
}
 
}
 
int tx_done;
int rx_done;
int rx_len;
char tx_data[1536]; //max length
char rx_data[1536];
 
void eth_init()
{
//TXEN & RXEN = 1; PAD & CRC = 1; FULLD = 1
REG32(ETH_BASE + ETH_MODER) = ETH_TXEN | ETH_RXEN | ETH_PAD | ETH_CRCEN | ETH_FULLD;
//PHY Address = 0x001
REG32(ETH_BASE + ETH_MIIADDRESS) = 0x00000001;
 
//enable all interrupts
REG32(ETH_BASE + ETH_INT_MASK) = ETH_RXC | ETH_TXC | ETH_BUSY | ETH_RXE | ETH_RXB | ETH_TXE | ETH_TXB;
 
//set MAC ADDRESS
REG32(ETH_BASE + ETH_MAC_ADDR1) = OWN_MAC_ADDRESS >> 32; //low word = mac address high word
REG32(ETH_BASE + ETH_MAC_ADDR0) = OWN_MAC_ADDRESS; //mac address rest
 
//configure TXBD0
REG32(ETH_BASE + ETH_TXBD0H) = tx_data; //address used for tx_data
REG32(ETH_BASE + ETH_TXBD0L) = TX_READY; //length = 0 | PAD & CRC = 1 | IRQ & WR = 1
 
//configure RXBD0
REG32(ETH_BASE + ETH_RXBD0H) = rx_data; //address used for tx_data
REG32(ETH_BASE + ETH_RXBD0L) = RX_READY; //len = 0 | IRQ & WR = 1 | EMPTY = 1
 
//set txdata
tx_data[0] = BROADCAST_ADDRESS >> 40;
tx_data[1] = BROADCAST_ADDRESS >> 32;
tx_data[2] = BROADCAST_ADDRESS >> 24;
tx_data[3] = BROADCAST_ADDRESS >> 16;
tx_data[4] = BROADCAST_ADDRESS >> 8;
tx_data[5] = BROADCAST_ADDRESS;
 
tx_data[6] = OWN_MAC_ADDRESS >> 40;
tx_data[7] = OWN_MAC_ADDRESS >> 32;
tx_data[8] = OWN_MAC_ADDRESS >> 24;
tx_data[9] = OWN_MAC_ADDRESS >> 16;
tx_data[10] = OWN_MAC_ADDRESS >> 8;
tx_data[11] = OWN_MAC_ADDRESS;
 
//erase interrupts
REG32(ETH_BASE + ETH_INT_SOURCE) = ETH_RXC | ETH_TXC | ETH_BUSY | ETH_RXE | ETH_RXB | ETH_TXE | ETH_TXB;
 
tx_done = 1;
rx_done = 0;
rx_len = 0;
}
 
void eth_send(int length)
{
if (!tx_done)
return;
 
tx_done = 0;
tx_data[12] = length >> 8;
tx_data[13] = length;
 
REG32(ETH_BASE + ETH_TXBD0L) = (( 0x0000FFFF & ( length + HDR_LEN ) ) << 16) | BD_SND;
}
 
void eth_receive()
{
int i;
uart_print_str("Length: \n");
uart_print_long(eth_rx_len);
uart_print_long(rx_len - HDR_LEN - CRC_LEN);
uart_print_str("\n");
uart_print_str("Data: \n");
for ( i = 0; i < eth_rx_len; i++ )
for ( i = 0; i < rx_len - HDR_LEN - CRC_LEN; i++ )
{
uart_print_short(eth_rx_data[i]);
uart_print_str("\n");
uart_print_short(rx_data[i+HDR_LEN]);
// uart_print_str("\n");
}
eth_recv_ack();
 
rx_done = 0;
rx_len = 0;
}
 
void eth_interrupt()
{
unsigned long source = REG32(ETH_BASE + ETH_INT_SOURCE);
switch (source)
{
case ETH_TXB:
tx_done = 1;
//erase interrupt
REG32(ETH_BASE + ETH_INT_SOURCE) |= ETH_TXB;
break;
 
case ETH_RXB:
rx_done = 1;
//erase interrupt
REG32(ETH_BASE + ETH_INT_SOURCE) |= ETH_RXB;
//accept further data (reset RXBD to empty)
rx_len = (REG32(ETH_BASE + ETH_RXBD0L) >> 16);
REG32(ETH_BASE + ETH_RXBD0L) = RX_READY; //len = 0 | IRQ & WR = 1 | EMPTY = 1
break;
 
default:
break;
}
}
 
int main()
{
unsigned long lalala;
33,7 → 203,6
uart_init();
 
int_init();
eth_init();
int_add(UART_IRQ, &uart_interrupt);
int_add(ETH_IRQ, &eth_interrupt);
41,16 → 210,18
we don't link C library. */
uart_print_str("Hello World.\n\r");
 
eth_tx_data[0] = 0xFF;
eth_tx_data[1] = 0x2B;
eth_tx_data[2] = 0x40;
eth_tx_data[3] = 0x50;
eth_init();
 
tx_data[14] = 0xFF;
tx_data[15] = 0x2B;
tx_data[16] = 0x40;
tx_data[17] = 0x50;
 
eth_send(4);
 
while(1)
{
if (eth_rx_done)
if (rx_done)
{
eth_receive();
}
/eth/eth.h
80,8 → 80,8
#define ETH_TXBD_CS 0x00000001
 
//user defines
#define OWN_MAC_ADDRESS 0x554734228892ULL
#define BROADCAST_ADDRESS 0xFFFFFFFFFFFFULL
#define OWN_MAC_ADDRESS 0x554734228892
#define BROADCAST_ADDRESS 0xFFFFFFFFFFFF
 
#define HDR_LEN 14
#define CRC_LEN 4
/eth/Makefile
1,10 → 1,10
include ../support/Makefile.inc
cases = eth-nocache eth-icdc
common = ../support/libsupport.a ../support/except.o
drivers = ../drivers/libdrivers.a
 
all: $(cases)
 
eth-nocache: eth.o ../support/reset-nocache.o $(common) $(drivers)
eth-nocache: eth.o ../support/reset-nocache.o $(common)
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex
11,8 → 11,8
../utils/bin2vmem $@.bin > $@.vmem
 
 
eth-icdc: eth.o ../support/reset-icdc.o $(common) $(drivers)
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32
eth-icdc: eth.o ../support/reset-icdc.o
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32 $(common)
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex
../utils/bin2vmem $@.bin > $@.vmem
21,4 → 21,3
eth.o: eth.c
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $? -c -o $@
 
include ../support/Makefile.inc
/uart/uart.c
1,10 → 1,96
#include "../support/support.h"
#include "../support/board.h"
#include "../support/uart.h"
 
#include "../support/spr_defs.h"
 
#include "../drivers/uart.h"
void uart_print_str(char *);
void uart_print_long(unsigned long);
 
// Dummy or32 except vectors
void buserr_except(){}
void dpf_except(){}
void ipf_except(){}
void lpint_except(){}
void align_except(){}
void illegal_except(){}
/*void hpint_except(){
 
}*/
void dtlbmiss_except(){}
void itlbmiss_except(){}
void range_except(){}
void syscall_except(){}
void res1_except(){}
void trap_except(){}
void res2_except(){}
 
 
void uart_interrupt()
{
char lala;
unsigned char interrupt_id;
interrupt_id = REG8(UART_BASE + UART_IIR);
if ( interrupt_id & UART_IIR_RDI )
{
lala = uart_getc();
uart_putc(lala+1);
}
}
 
 
void uart_print_str(char *p)
{
while(*p != 0) {
uart_putc(*p);
p++;
}
}
 
void uart_print_long(unsigned long ul)
{
int i;
char c;
 
uart_print_str("0x");
for(i=0; i<8; i++) {
 
c = (char) (ul>>((7-i)*4)) & 0xf;
if(c >= 0x0 && c<=0x9)
c += '0';
else
c += 'a' - 10;
uart_putc(c);
}
 
}
 
void uart_print_short(unsigned long ul)
{
int i;
char c;
char flag=0;
 
uart_print_str("0x");
for(i=0; i<8; i++) {
 
c = (char) (ul>>((7-i)*4)) & 0xf;
if(c >= 0x0 && c<=0x9)
c += '0';
else
c += 'a' - 10;
if ((c != '0') || (i==7))
flag=1;
if(flag)
uart_putc(c);
}
 
}
 
 
 
int main()
{
uart_init();
/uart/Makefile
1,10 → 1,10
include ../support/Makefile.inc
cases = uart-nocache uart-icdc
common = ../support/libsupport.a ../support/except.o
drivers = ../drivers/libdrivers.a
 
all: $(cases)
 
uart-nocache: uart.o ../support/reset-nocache.o $(common) $(drivers)
uart-nocache: uart.o ../support/reset-nocache.o $(common)
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex
11,8 → 11,8
../utils/bin2vmem $@.bin > $@.vmem
 
 
uart-icdc: uart.o ../support/reset-icdc.o $(common) $(drivers)
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32
uart-icdc: uart.o ../support/reset-icdc.o
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32 $(common)
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex
../utils/bin2vmem $@.bin > $@.vmem
21,4 → 21,3
uart.o: uart.c
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $? -c -o $@
 
include ../support/Makefile.inc

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.