Skip to content

Commit

Permalink
added 32 bit ni driver
Browse files Browse the repository at this point in the history
  • Loading branch information
andersondomingues committed Sep 16, 2020
1 parent b80a09a commit 1a2cea4
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 81 deletions.
6 changes: 3 additions & 3 deletions Configuration.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# be included in compilation unless you edit the file
# os/hellfireos/orca-core/src/orca-core.cpp,
# where you should simple of tasks in each of the cores.
ORCA_APPLICATIONS := hfunit-example
ORCA_APPLICATIONS := dma-driver-test

# Software libraries (experimental)
#ORCA_LIBS := orca-pubsub orca-monitoring hf-printf orca-baremetal-dma-driver
ORCA_LIBS := hfunit
ORCA_LIBS := orca-baremetal-dma-driver

# part of the software, like the device drivers, might know plataform-specific details to parametrize the software.
# one example is the NoC driver and the orca-lib-client. Both of them require details about the Hw NoC, the size of the MpSoC, etc.
# ORCA_PLATFORM := (orca-mpsoc | single-core | single-core-nn)
ORCA_PLATFORM := hfriscv-with-extcomm
ORCA_PLATFORM := single-core-ext
#ORCA_PLATFORM := single-core

# select among the supported OS
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CFLAGS += $(PLAT_COMPLINE) $(MODELS_COMPLINE)
CXXFLAGS += $(PLAT_COMPLINE) $(MODELS_COMPLINE)

# get the models depedent parameters.
include $(ORCA_SIM_DIR)/models/Configuration.mk
# include $(ORCA_SIM_DIR)/models/Configuration.mk

# concat the required libs and apps to build the image
$(foreach module,$(ORCA_APPLICATIONS), $(eval APP_STATIC_LIBS := $(APP_STATIC_LIBS) app-$(module).a))
Expand Down Expand Up @@ -80,7 +80,7 @@ $(IMAGE_NAME).bin: $(OS_STATIC_LIB) lib app
@echo "$'\033[7m==================================\033[0m"
@echo "$'\033[7m Linking Software ... \033[0m"
@echo "$'\033[7m==================================\033[0m"
$(Q)$(LD) $(OS_OBJS) --start-group *.a --end-group $(LDFLAGS) -T$(LINKER_SCRIPT) -o $(IMAGE_NAME).elf
$(Q)$(LD) $(OS_OBJS) --start-group *.a --end-group $(LDFLAGS) -T$(LINKER_SCRIPT) -o $(IMAGE_NAME).elf --defsym=RAM_SIZE=64K
$(Q)$(DUMP) --disassemble --reloc $(IMAGE_NAME).elf > $(IMAGE_NAME).lst
$(Q)$(DUMP) -h $(IMAGE_NAME).elf > $(IMAGE_NAME).sec
$(Q)$(DUMP) -s $(IMAGE_NAME).elf > $(IMAGE_NAME).cnt
Expand Down
30 changes: 19 additions & 11 deletions applications/dma-driver-test/src/dma-driver-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,37 @@

int main(){

char buffer[BUFFER_SIZE];
uint8_t buffer[BUFFER_SIZE];

dma_init();

//periodically bursts messages through the network
while(1){

//holds until data is available from the
//network
while(!dma_recv_probe());
// while(!dma_recv_probe());

uint32_t x = 0;
uint32_t y = 0;
uint32_t size = 10;

int x, y, size;
for(int i = 0; i < 10; i++){
buffer[i] = i + 10;
}

//receive data
dma_recv_start(&x, &y, &size, buffer);
//push data back to the network
dma_send_start(x, y, buffer, size);

printf("app: received \"%s\" from x=%x y=%d (%d bytes)\n", &buffer[4], x, y, size);
while(dma_recv_probe()){
dma_recv_start(&x, &y, &size, buffer);
}

//change data
for(int i = 0; i < size; i++)
if(buffer[i] != '\0')
buffer[i]++;
for(int i = 0; i < 10; i++){
buffer[i] = buffer[i] + 1;
}

//push data back to the network
dma_send_start(x, y, buffer, size);
printf("app: replied \"%s\"\n", &buffer[4]);
}
}
25 changes: 25 additions & 0 deletions libs/orca-baremetal-dma-driver-16/ext.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Do not modify the lines below
ORCA_BAREMETAL_DMA_DRIVER_NAME := orca-baremetal-dma-driver
ORCA_BAREMETAL_DMA_DRIVER_DIR := $(ORCA_SW_DIR)/libs/$(ORCA_BAREMETAL_DMA_DRIVER_NAME)
ORCA_BAREMETAL_DMA_DRIVER_SRC := $(ORCA_BAREMETAL_DMA_DRIVER_DIR)/src
ORCA_BAREMETAL_DMA_DRIVER_INC := $(ORCA_BAREMETAL_DMA_DRIVER_DIR)/include
ORCA_BAREMETAL_DMA_DRIVER_LIB := lib-$(ORCA_BAREMETAL_DMA_DRIVER_NAME).a

INC_DIRS += -I$(ORCA_BAREMETAL_DMA_DRIVER_INC)

CFLAGS +=

ifeq ($(ORCA_OS), bare-metal/hf-riscv)
# define/undefine this symbol to turn newlib on/off
USE_LIBC = 1
# define/undefine this symbol to turn cpp on/off
#USE_CPP = 1
endif

# Update these lines with your source code
ORCA_BAREMETAL_DMA_DRIVER_SRCS := $(wildcard $(ORCA_BAREMETAL_DMA_DRIVER_SRC)/*.c)
ORCA_BAREMETAL_DMA_DRIVER_OBJS := $(ORCA_BAREMETAL_DMA_DRIVER_SRCS:.c=.o)

$(ORCA_BAREMETAL_DMA_DRIVER_LIB) : $(ORCA_BAREMETAL_DMA_DRIVER_OBJS)
$(Q)$(AR) rcs $(ORCA_BAREMETAL_DMA_DRIVER_LIB) $(ORCA_BAREMETAL_DMA_DRIVER_OBJS)
$(Q)$(AR) t $(ORCA_BAREMETAL_DMA_DRIVER_LIB)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/******************************************************************************
* This file is part of project ORCA. More information on the project
* can be found at the following repositories at GitHub's website.
*
* http://https://github.com/andersondomingues/orca-sim
* http://https://github.com/andersondomingues/orca-software
* http://https://github.com/andersondomingues/orca-mpsoc
* http://https://github.com/andersondomingues/orca-tools
*
* Copyright (C) 2018-2020 Anderson Domingues, <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
******************************************************************************/
#ifndef _ORCA_BAREMETAL_DMA_DRIVER_H
#define _ORCA_BAREMETAL_DMA_DRIVER_H

#include "/home/adomingues/gaph/orca-sim/platforms/hfriscv-with-extcomm/include/MemoryMap.h"
#include <inttypes.h>

/**
* @brief Checks whether there are any packets to be
* received from the network.
*
* @return int Returns 1 when a packet is available, Zero otherwise.
*/
int dma_recv_probe();

/**
* @brief Sends a packet through the network
*
* @param x The X-axis address of the target device
* @param y The Y-axis address of the target device
* @param size The number of bytes of the payload
* @param data_ptr A pointer to the data to be transmitted
* @return int Returns Zero is data is succefully transmitted,
* error code otherwirse.
*/
int dma_recv_start(int* x, int* y, int* size, char* data_ptr);

/**
* @brief Receives a packet from the network.
*
* @param x A pointer to a variable to store the X-address of the sender
* @param y A pointer to a variable to store the Y-address of the sender
* @param data_ptr A pointer to the place where the payload will be writen
* @param size The number of bytes of the received packet
* @return int Returns Zero if the packet has being succefully received, -1
* if there are no packets to be received, error code otherwise.
*/
int dma_send_start(int x, int y, char* data_ptr, int size);

#endif // _ORCA_BAREMETAL_DMA_DRIVER_H
125 changes: 125 additions & 0 deletions libs/orca-baremetal-dma-driver-16/src/orca-baremetal-dma-driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/******************************************************************************
* This file is part of project ORCA. More information on the project
* can be found at the following repositories at GitHub's website.
*
* http://https://github.com/andersondomingues/orca-sim
* http://https://github.com/andersondomingues/orca-software
* http://https://github.com/andersondomingues/orca-mpsoc
* http://https://github.com/andersondomingues/orca-tools
*
* Copyright (C) 2018-2020 Anderson Domingues, <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
******************************************************************************/
#include <orca-baremetal-dma-driver.h>
#include <stdio.h>

//cpu-specific signals
volatile uint8_t* sig_stall = (volatile uint8_t*)SIGNAL_CPU_STALL;
volatile uint8_t* sig_intr = (volatile uint8_t*)SIGNAL_CPU_INTR;

//signals to start the ni
volatile uint8_t* sig_send = (volatile uint8_t*)SIGNAL_PROG_SEND;
volatile uint8_t* sig_recv = (volatile uint8_t*)SIGNAL_PROG_RECV;

//signals to check on ni statuses
volatile uint8_t* sig_send_status = (volatile uint8_t*)SIGNAL_SEND_STATUS;
volatile uint32_t* sig_recv_status = (volatile uint32_t*)SIGNAL_RECV_STATUS;

//signals to ni programming
volatile uint32_t* sig_addr = (volatile uint32_t*)SIGNAL_PROG_ADDR;
volatile uint32_t* sig_size = (volatile uint32_t*)SIGNAL_PROG_SIZE;


//this method will report zero
//only if no packet if at the
//input. otherwise, it will report
//the size of the incoming packet
//in bytes
int dma_recv_probe(){
return *sig_recv_status;
}

int dma_send_start(int x, int y, char* data_ptr, int size){

uint16_t first_flit = (x << 4) & (0x00FF | y);
uint16_t second_flit = size;

// printf("%x\n", first_flit);
printf("");

char buffer[size + 4];

//copy first two flits into the buffer
*((uint16_t*)&(buffer[0])) = first_flit;
*((uint16_t*)&(buffer[2])) = second_flit;

//copy the payload
for(int i = 0; i < size; i++)
buffer[i + 4] = data_ptr[i];

//wait previous send to finish (if any)
while(*sig_send_status != 0);

//configure dma
*sig_size = size + 4;
*sig_addr = (uint32_t)buffer;

// printf("ni prog size %d, addr 0x%x\n", *sig_size, *sig_addr);
//stall and send
*sig_send = 0x1;
*sig_send = 0x1;
*sig_send = 0x1;
*sig_send = 0x1;

__asm__ volatile ("nop"); //skip one cycle
__asm__ volatile ("nop"); //skip one cycle
__asm__ volatile ("nop"); //skip one cycle
__asm__ volatile ("nop"); //skip one cycle

//flag off
*sig_send = 0x0;
*sig_send = 0x0;
*sig_send = 0x0;

return 0; //<<- no reason for failing
}

int dma_recv_start(int* x, int* y, int* size, char* data_ptr){

//cannot receive without
//a packet at the input
if(!dma_recv_probe()) return -1;

//configure dma
*sig_size = dma_recv_probe();
*sig_addr = (uint32_t)data_ptr;

*size = *sig_size;

//stall and recv
*sig_recv = 0x1;

//hold the cpu until no size is given
while(*sig_recv_status != 0x0);

//flag off
*sig_recv = 0x0;

*x = ((uint16_t*)(data_ptr))[0] >> 4;
*y = ((uint16_t*)(data_ptr))[0] & 0x00FF;

return 0; //<<- no reason to fail
}
38 changes: 35 additions & 3 deletions libs/orca-baremetal-dma-driver/include/orca-baremetal-dma-driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,41 @@
#ifndef _ORCA_BAREMETAL_DMA_DRIVER_H
#define _ORCA_BAREMETAL_DMA_DRIVER_H

#include "/home/adomingues/gaph/orca-sim/platforms/hfriscv-with-extcomm/include/MemoryMap.h"
// #include "/home/adomingues/gaph/orca-sim/platforms/hfriscv-with-extcomm/include/MemoryMap.h"

// @TODO maybe move these to the Configuration.mk file
#define ORCA_MEMORY_BASE_1 0x00000000
#define ORCA_MEMORY_SIZE_1 0x00000080
#define ORCA_MEMORY_BASE_2 0x00000080
#define ORCA_MEMORY_SIZE_2 0x00000080

// control wires (cpu <-> dma)
#define SIGNAL_CPU_STALL 0x40410000 /* 8 bits */
#define SIGNAL_CPU_INTR 0x40410001
// #define SIGNAL_SEND_STATUS 0x40410002
// 0x40410003
// #define SIGNAL_RECV_STATUS 0x40410004
// 0x40410005
// 0x40410006
// 0x40410007
// #define SIGNAL_PROG_SEND 0x40410008
// #define SIGNAL_PROG_RECV 0x40410009
// 0x4041000A
// 0x4041000B
// #define SIGNAL_PROG_ADDR 0x4041000C /* 32 bits */
// #define SIGNAL_PROG_SIZE 0x40410010

// tile indentifier, hardware fixed
// #define MAGIC_TILE_ID 0x40411000

#define MAGIC_TILE_ID 0xe0ff8000
#define SIGNAL_STATUS 0xe0ff8010
#define SIGNAL_PROG_ADDR 0xe0ff8020 /* 32 bits */
#define SIGNAL_PROG_SIZE 0xe0ff8030

#include <inttypes.h>

int dma_init();
/**
* @brief Checks whether there are any packets to be
* received from the network.
Expand All @@ -47,7 +79,7 @@ int dma_recv_probe();
* @return int Returns Zero is data is succefully transmitted,
* error code otherwirse.
*/
int dma_recv_start(int* x, int* y, int* size, char* data_ptr);
uint32_t dma_recv_start(uint32_t* x, uint32_t* y, uint32_t* size, uint8_t* data_ptr);

/**
* @brief Receives a packet from the network.
Expand All @@ -59,6 +91,6 @@ int dma_recv_start(int* x, int* y, int* size, char* data_ptr);
* @return int Returns Zero if the packet has being succefully received, -1
* if there are no packets to be received, error code otherwise.
*/
int dma_send_start(int x, int y, char* data_ptr, int size);
void dma_send_start(uint32_t x, uint32_t y, uint8_t* data_ptr, uint32_t size);

#endif // _ORCA_BAREMETAL_DMA_DRIVER_H
Loading

0 comments on commit 1a2cea4

Please sign in to comment.