summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/powerpc/mpc55xx/include/watchdog.h
blob: d5a8af794e5753ea9b0da8294a7935dd3a409bbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * @file
 *
 * @ingroup mpc55xx
 *
 * @brief Header file for the watchdog timer.
 */

/*
 * Copyright (c) 2008
 * Embedded Brains GmbH
 * Obere Lagerstr. 30
 * D-82178 Puchheim
 * Germany
 * rtems@embedded-brains.de
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef LIBCPU_POWERPC_MPC55XX_WATCHDOG_H
#define LIBCPU_POWERPC_MPC55XX_WATCHDOG_H

#include <stdbool.h>

#include <rtems.h>

#include <libcpu/powerpc-utility.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

static inline void mpc55xx_watchdog_clear()
{
	PPC_SET_SPECIAL_PURPOSE_REGISTER( BOOKE_TSR, BOOKE_TSR_WIS);
}

static inline void mpc55xx_watchdog_enable_interrupt( bool enable)
{
	if (enable) {
		PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS( BOOKE_TCR, BOOKE_TCR_WIE);
	} else {
		PPC_CLEAR_SPECIAL_PURPOSE_REGISTER_BITS( BOOKE_TCR, BOOKE_TCR_WIE);
	}
}

static inline rtems_status_code mpc55xx_watchdog_set_time_base_bit( uint32_t bit)
{
	if (bit > 63) {
		return RTEMS_INVALID_NUMBER;
	}

	PPC_SET_SPECIAL_PURPOSE_REGISTER_BITS_MASKED(
		BOOKE_TCR,
		BOOKE_TCR_WP( bit) | BOOKE_TCR_WPEXT( bit >> 2),
		BOOKE_TCR_WP_MASK | BOOKE_TCR_WPEXT_MASK
	);

	return RTEMS_SUCCESSFUL;
}

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* LIBCPU_POWERPC_MPC55XX_WATCHDOG_H */