Skip to content

Commit

Permalink
sw/tests: Add dma_2d test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsc96 committed Nov 14, 2024
1 parent 5d9cef6 commit a7ee1a8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions sw/tests/dma_2d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Paul Scheffler <[email protected]>
//
// Simple test for iDMA. This is intended *only for execution from SPM*.

#include "util.h"
#include "dif/clint.h"
#include "dif/dma.h"

int main(void) {
volatile char src_cached[] = "This is a DMA test";
volatile char gold[] = "This ishis is is is as is a DMA test!";

// Allocate destination memory in SPM
volatile char dst_cached[sizeof(gold)];

// Get pointer to uncached SPM source and destination
volatile char *src = src_cached + 0x04000000;
volatile char *dst = dst_cached + 0x04000000;

// Copy from cached to uncached source to ensure it is DMA-accessible
for (unsigned i = 0; i < sizeof(src_cached); ++i) src[i] = src_cached[i];

// Pre-write finishing "!\0" to guard against overlength transfers
dst[sizeof(gold) - 2] = '!';
dst[sizeof(gold) - 1] = '\0';

// Issue blocking 2D memcpy (exclude null terminator from source)
sys_dma_2d_blk_memcpy((uintptr_t)(void *)dst, (uintptr_t)(void *)src, sizeof(src_cached) - 4, 7,
1, 4);

// Check destination string
int errors = sizeof(gold);
for (unsigned i = 0; i < sizeof(gold); ++i) errors -= (dst[i] == gold[i]);

return errors;
}

0 comments on commit a7ee1a8

Please sign in to comment.