tapasco_address_map.c 2.26 KB
Newer Older
1
2
3
//
// Copyright (C) 2014 Jens Korinth, TU Darmstadt
//
4
// This file is part of Tapasco (TPC).
5
//
6
// Tapasco is free software: you can redistribute it and/or modify
7
8
9
10
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
11
// Tapasco is distributed in the hope that it will be useful,
12
13
14
15
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
17
// along with Tapasco.  If not, see <http://www.gnu.org/licenses/>.
18
//
19
//! @file	tapasco_address_map.c
20
21
22
23
24
//! @brief	Resolves logical registers to concrete AXI addresses on the
//!		Zynq platform (implementation of micro API).
//! @authors	J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
//!
#include <assert.h>
25
#include <tapasco_address_map.h>
26
#include <platform.h>
27

28
#define TAPASCO_MAX_INSTANCES			128
29

30
static platform_ctl_addr_t _bases[TAPASCO_MAX_INSTANCES] = { 0 };
31

32
33
34
static inline tapasco_reg_addr_t base_addr(uint32_t const slot_id) {
	assert(slot_id < TAPASCO_MAX_INSTANCES);
	tapasco_reg_addr_t ret = _bases[slot_id];
35
36
37
	if (! ret)
		ret = (_bases[slot_id] = platform_address_get_slot_base(slot_id, 0));
	assert(ret > 0);
38
39
40
	return ret;
}

41
tapasco_reg_addr_t tapasco_address_map_func_arg_register(tapasco_dev_ctx_t *dev_ctx,
42
43
44
45
46
47
48
		uint32_t const slot_id, uint32_t const arg_idx) {
	//! @todo Remove this stuff as soon as Vivado HLS can handle offsets correctly.
	return base_addr(slot_id) //platform_address_get_slot_base(slot_id, 0)
	     + 0x20			// first arg is at this offset from base
	     + arg_idx * 0x10;		// one byte seems to be reserved after each
}

49
50
tapasco_reg_addr_t tapasco_address_map_func_reg(tapasco_dev_ctx_t *dev_ctx,
		uint32_t const slot_id, tapasco_func_reg_t const reg) {
51
	switch (reg) {
52
53
	case TAPASCO_FUNC_REG_BASE:
	case TAPASCO_FUNC_REG_CONTROL:
54
		return platform_address_get_slot_base(slot_id, 0);
55
	case TAPASCO_FUNC_REG_IAR:
56
		return platform_address_get_slot_base(slot_id, 0) + 0x0c;
57
	case TAPASCO_FUNC_REG_RETURN:
58
59
60
61
62
		return platform_address_get_slot_base(slot_id, 0) + 0x10;
	default:
		return 0;
	}
}