-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b80a09a
commit 1a2cea4
Showing
9 changed files
with
342 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
64 changes: 64 additions & 0 deletions
64
libs/orca-baremetal-dma-driver-16/include/orca-baremetal-dma-driver.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
125
libs/orca-baremetal-dma-driver-16/src/orca-baremetal-dma-driver.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.