tapasco_status.c 2.46 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
//
/**
20
 *  @file	tapasco_status.c
21
22
23
24
25
26
27
28
29
30
31
 *  @brief	
 *  @author	J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
 **/
#ifdef __cplusplus
	#include <cstdint>
	#include <cstring>
#else
	#include <stdint.h>
	#include <string.h>
#endif
#include <platform_api.h>
32
33
34
#include <tapasco_status.h>
#include <tapasco_logging.h>
#include <tapasco_errors.h>
35

36
37
static platform_ctl_addr_t const TAPASCO_STATUS_SLOT_BASE   = 0x100;
static platform_ctl_addr_t const TAPASCO_STATUS_SLOT_OFFSET = 0x010;
38

39
static tapasco_res_t read_tapasco_status(tapasco_status_t **status)
40
41
42
43
44
45
46
47
48
49
{
	uint32_t d = 0;
	LOG(LALL_STATUS, "creating status info");
	platform_ctl_addr_t h = platform_address_get_special_base(
			PLATFORM_SPECIAL_CTL_STATUS);
	LOG(LALL_STATUS, "status address = 0x%08lx", (unsigned long)h);
	// check magic number
	platform_read_ctl(h, sizeof(d), &d, PLATFORM_CTL_FLAGS_NONE);
	if (d != 0xE5AE1337) {
		ERR("no TPC bitstream detected, load bitstream and restart");
50
		return TAPASCO_ERR_STATUS_CORE_NOT_FOUND;
51
52
	}

53
54
	h += TAPASCO_STATUS_SLOT_BASE;
	for (int i = 0; i < TAPASCO_MAX_INSTANCES; ++i, h += TAPASCO_STATUS_SLOT_OFFSET) {
55
56
57
58
		platform_read_ctl(h, sizeof(d), &d, PLATFORM_CTL_FLAGS_NONE);
		LOG(LALL_STATUS, "slot %u has kernel with id %u", i, d);
		(*status)->id[i] = d;
	}
59
	return TAPASCO_SUCCESS;
60
61
}

62
tapasco_res_t tapasco_status_init(tapasco_status_t **status)
63
{
64
65
	*status = (tapasco_status_t *)malloc(sizeof(**status));
	if (! status) return TAPASCO_ERR_OUT_OF_MEMORY;
66
	memset(*status, 0, sizeof(**status));
67
68
	tapasco_res_t ok = read_tapasco_status(status);
	if (ok != TAPASCO_SUCCESS) {
69
70
71
72
73
74
75
		ERR("initialization failed");
		free(*status);
		*status = NULL;
	}
	return ok;
}

76
void tapasco_status_deinit(tapasco_status_t *status)
77
78
79
80
{
	LOG(LALL_STATUS, "releasing status info");
	free(status);
}