Skip to content
Snippets Groups Projects
Commit 15478274 authored by Mathias Kreider's avatar Mathias Kreider
Browse files

complete ebm api demo

parent fe36c0c5
Branches
Tags
No related merge requests found
dev=$1
ebadr=$((0x1000000))
#test=0x$(0x$(printf "%X\n" "$(($ebadr))")
#echo $test
echo "src mac"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x0C))")/4 #my mac
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x10))")/4
echo "src ip"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x14))")/4 #my ip
echo "src port"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x18))")/4 #my port
echo "dst mac"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x1C))")/4 #his mac
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x20))")/4
echo "dst ip"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x24))")/4 #his ip
echo "dst port"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x28))")/4 #his port
echo "len hibits maxops ebops"
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x2C))")/4
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x30))")/4 #adr hi bits
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x34))")/4 #max ops
eb-read $dev 0x$(printf "%X\n" "$(($ebadr + 0x40))")/4 #EB options
/** @file irq.c
* @brief MSI capable IRQ handler for the LM32
/** @file ebm.c
* @brief EtherBone Master API
*
* Copyright (C) 2011-2012 GSI Helmholtz Centre for Heavy Ion Research GmbH
*
......@@ -22,17 +22,58 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************
*/
#include <stdlib.h>
#include <string.h>
#include "ebm.h"
extern unsigned int* ebm;
static inline char* strsplit(const char* numstr, const char* delimeter);
static inline unsigned char* numStrToBytes(const char* numstr, unsigned char* bytes, unsigned char len, unsigned char base, const char* delimeter);
static inline unsigned char* addressStrToBytes(const char* addressStr, unsigned char* addressBytes, adress_type_t addtype);
static inline unsigned int ebm_parse_adr(struct eb_lm32_udp_link* link, const char* address);
void ebm_config_if(target_t conf, const char* con_info)
{
struct eb_lm32_udp_link* link;
unsigned int offset;
unsigned int tmp;
ebm_parse_adr(link, con_info);
if(conf == LOCAL) offset = EBM_OFFS_LOCAL;
if(conf == REMOTE) offset = EBM_OFFS_REMOTE;
tmp = (link->mac[0] << 24) | (link->mac[1] << 16) | (link->mac[2] << 8) | link->mac[3];
*(ebm + ((offset + EBM_OFFS_MAC_HI) >>2)) = tmp;
tmp = (link->mac[4] << 24) | (link->mac[5] << 16);
*(ebm + ((offset + EBM_OFFS_MAC_LO) >>2)) = tmp;
tmp = (link->ipv4[0] << 24) | (link->ipv4[1] << 16) | (link->ipv4[2] << 8) | link->ipv4[3];
*(ebm + ((offset + EBM_OFFS_IPV4) >>2)) = tmp;
*(ebm + ((offset + EBM_OFFS_UDP_PORT) >>2)) = (unsigned int)link->port;
}
void ebm_config_meta(unsigned int pac_len, unsigned int hi_bits, unsigned int max_ops, unsigned int eb_ops)
{
*(ebm + (EBM_REG_PAC_LEN >>2)) = pac_len;
*(ebm + (EBM_REG_OPA_HI >>2)) = hi_bits;
*(ebm + (EBM_REG_OPS_MAX >>2)) = max_ops;
*(ebm + (EBM_REG_EB_OPT >>2)) = eb_ops;
}
void ebm_op(unsigned int address, unsigned int value, unsigned int optype)
{
unsigned int offset = EBM_OFFS_DAT;
//set hibits according to desired address
*(ebm + (EBM_REG_OPA_HI >> 2)) = (address & ~ADR_MASK);
offset += optype;
offset += (address & ADR_MASK);
*(ebm + (offset>>2)) = value;
......@@ -44,3 +85,115 @@ void ebm_flush(void)
*(ebm + (EBM_REG_FLUSH>>2)) = 0x01;
}
//String helper functions
static char* strsplit(const char* numstr, const char* delimeter)
{
char* pch = (char*)numstr;
while (*(pch) != '\0')
if(*(pch++) == *delimeter) return pch;
return pch;
}
static unsigned char* numStrToBytes(const char* numstr, unsigned char* bytes, unsigned char len, unsigned char base, const char* delimeter)
{
char * pch;
char * pend;
unsigned char byteCount=0;
long tmpconv;
pch = (char *) numstr;
while ((pch != NULL) && byteCount < len )
{
pend = strsplit(pch, delimeter)-1;
tmpconv = strtol((const char *)pch, &(pend), base);
// in case of a 16 bit value
if(tmpconv > 255) bytes[byteCount++] = (unsigned char)(tmpconv>>8 & 0xff);
bytes[byteCount++] = (unsigned char)(tmpconv & 0xff);
pch = pend+1;
}
return bytes;
}
static unsigned char* addressStrToBytes(const char* addressStr, unsigned char* addressBytes, adress_type_t addtype)
{
unsigned char len;
unsigned char base;
char del;
if(addtype == MAC)
{
len = 6;
base = 16;
del = ':';
}
else if(addtype == IP)
{
len = 4;
base = 10;
del = '.';
}
else{
return NULL;
}
return numStrToBytes(addressStr, addressBytes, len, base, &del);
}
static unsigned int ebm_parse_adr(struct eb_lm32_udp_link* link, const char* address) {
char * pch;
unsigned int stat = 1;
//a proper address string must contain, MAC, IP and port: "hw/11:22:33:44:55:66/udp/192.168.0.1/port/60368"
//parse and fill link struct
pch = (char*) address;
if(pch != NULL)
{
if(strncmp("hw", pch, 2) == 0)
{
pch = strsplit(pch,"/");
if(pch != NULL)
{
addressStrToBytes((const char*)pch, link->mac, MAC);
pch = strsplit(pch,"/");
if(pch != NULL)
{
if(strncmp("udp", pch, 3) == 0)
{
pch = strsplit(pch,"/");
if(pch != NULL) addressStrToBytes(pch, link->ipv4, IP);
pch = strsplit(pch,"/");
if(pch != NULL)
if(strncmp("port", pch, 4) == 0)
{
pch = strsplit(pch,"/");
if(pch != NULL)
{
//addressStrToBytes(pch, link->port, PORT);
link->port = atoi (pch);
stat = 0;
}
}
}
}
}
}
}
return stat;
}
......@@ -23,9 +23,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************
*/
#ifndef __EBM_H_
#define __EBM_H_
#ifndef EBM_H
#define EBM_H
#define EBM_REG_RESET 0
......@@ -47,17 +46,42 @@
#define EBM_REG_EB_OPT (EBM_REG_ROA_BASE +4)
#define EBM_REG_LAST (EBM_REG_EB_OPT;
#define EBM_OFFS_DAT 0x00800000
#define EBM_OFFS_WR 0x00400000
#define EBM_OFFS_LOCAL (EBM_REG_SRC_MAC_HI)
#define EBM_OFFS_REMOTE (EBM_REG_DST_MAC_HI)
#define EBM_OFFS_MAC_HI 0
#define EBM_OFFS_MAC_LO (EBM_OFFS_MAC_HI +4)
#define EBM_OFFS_IPV4 (EBM_OFFS_MAC_LO +4)
#define EBM_OFFS_UDP_PORT (EBM_OFFS_IPV4 +4)
#define WRITE (EBM_OFFS_WR)
#define READ 0x00000000
#define ADR_MASK 0x003FFFFF
#define EBM_OFFS_DAT 0x00800000
#define EBM_OFFS_WR 0x00400000
typedef struct eb_lm32_udp_link {
/* Contents must fit in 12 bytes */
unsigned char mac[6];
unsigned char ipv4[4];
unsigned short port;
};
typedef unsigned int adress_type_t;
typedef unsigned char target_t;
#define WRITE (EBM_OFFS_WR)
#define READ 0x00000000
#define ADR_MASK 0x003FFFFF
static const target_t LOCAL = 0;
static const target_t REMOTE = 1;
static const adress_type_t MAC = 1;
static const adress_type_t IP = 2;
static const adress_type_t PORT = 3;
static const unsigned short myPort = 0xEBD0;
void ebm_config_if(target_t conf, const char* con_info);
void ebm_config_meta(unsigned int pac_len, unsigned int hi_bits, unsigned int max_ops, unsigned int eb_ops);
void ebm_op(unsigned int address, unsigned int value, unsigned int optype);
void ebm_flush(void);
#endif
......@@ -3,9 +3,9 @@
#include "irq.h"
#include "ebm.h"
volatile unsigned int* display = (unsigned int*)0x02900000;
volatile unsigned int* irq_slave = (unsigned int*)0x02000d00;
volatile unsigned int* ebm = (unsigned int*)0x01000000;
volatile unsigned int* display = (unsigned int*)0x02900000;
volatile unsigned int* irq_slave = (unsigned int*)0x02000d00;
volatile unsigned int* ebm = (unsigned int*)0x01000000;
char* mat_sprinthex(char* buffer, unsigned long val)
......@@ -29,21 +29,17 @@ void show_msi()
{
char buffer[12];
mat_sprinthex(buffer, global_msi.msg);
disp_put_str("D ");
disp_put_str(buffer);
disp_put_str(mat_sprinthex(buffer, global_msi.msg));
disp_put_c('\n');
mat_sprinthex(buffer, global_msi.src);
disp_put_str("A ");
disp_put_str(buffer);
disp_put_str(mat_sprinthex(buffer, global_msi.src));
disp_put_c('\n');
mat_sprinthex(buffer, (unsigned long)global_msi.sel);
disp_put_str("S ");
disp_put_str(buffer);
disp_put_str(mat_sprinthex(buffer, (unsigned long)global_msi.sel));
disp_put_c('\n');
}
......@@ -103,7 +99,11 @@ unsigned int time = 0;
char color = 0xFF;
x = 0;
y = 9;
yinc = -1;
xinc = 1;
addr_raw_off = 0;
disp_reset();
disp_put_c('\f');
......@@ -114,28 +114,26 @@ unsigned int time = 0;
x = 0;
y = 9;
yinc = -1;
xinc = 1;
addr_raw_off = 0;
///////////////////////////////////////////////////////////////////////////////////
//Init EB Master
ebm_config_if(LOCAL, "hw/08:00:30:e3:b0:5a/udp/192.168.191.254/port/60368");
ebm_config_if(REMOTE, "hw/bc:30:5b:e2:b0:88/udp/192.168.191.131/port/60368");
ebm_config_meta(80, 0x11, 16, 0x00000000 );
while (1) {
/* Rotate the LEDs */
disp_put_raw( get_pixcol_val((unsigned char)y), get_pixcol_addr((unsigned char)x, (unsigned char)y), color);
if(x == 63) xinc = -1;
if(x == 0) xinc = 1;
//Send packet heartbeat
if(time++ > 50) {
//create WB cycle
ebm_op(0x55000333, 0xDEADBEEF, WRITE);
ebm_op(0x22000333, 0xCAFEBABE, READ);
//send
ebm_flush();
}
///////////////////////////////////////////////////////////////////////////////////
if(y == 47) yinc = -1;
if(y == 0) yinc = 1;
x += xinc;
y += yinc;
......@@ -145,13 +143,26 @@ unsigned int time = 0;
* It runs at 125MHz.
* Sleep 0.2 second.
*/
for (j = 0; j < 125000000/160; ++j) {
// disp_put_raw( get_pixcol_val((unsigned char)y), get_pixcol_addr((unsigned char)x, (unsigned char)y), color);
for (j = 0; j < 62500000/160; ++j) {
asm("# noop"); /* no-op the compiler can't optimize away */
}
if(time++ > 50) {
ebm_op(0x333, 0xDEADBEEF, WRITE); ebm_flush();
}
if(x == 63) xinc = -1;
if(x == 0) xinc = 1;
if(y == 47) yinc = -1;
if(y == 0) yinc = 1;
x += xinc;
y += yinc;
if(time++ > 500) {time = 0; color = ~color; }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment