summaryrefslogtreecommitdiff
path: root/cesar/hal/leon/src/fatal_button.c
blob: 19a16e515149af8252424226591b803224bd9478 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/leon/src/fatal_button.c
 * \brief   Trigger a fatal error on a button pressed.
 * \ingroup hal_leon
 *
 * This will trigger a fatal error if a GPIO is pulled down.
 */
#include "common/std.h"

#include <cyg/hal/drv_api.h>

#include "hal/leon/gpio.h"
#include "hal/gpio/gpio.h"

#include "config/leon/fatal.h"

/**
 * Interrupt handler.
 * \param  vector  interrupt vector number
 * \param  data  nothing
 * \return  status
 */
cyg_uint32
leon_fatal_button_isr (cyg_vector_t vector, cyg_addrword_t data)
{
    cyg_drv_interrupt_acknowledge (vector);
    return CYG_ISR_CALL_DSR;
}

/**
 * DSR for the fatal button.
 * \param  vector  interrupt vector number.
 * \param  count  count number.
 * \param  data  nothing.
 */
void
leon_fatal_button_dsr (cyg_vector_t vector, cyg_ucount32 count,
                       cyg_addrword_t data)
{
    dbg_fatal ("fatal button pressed");
}

/**
 * Fatal Synchronisation, set LEON_FATAL_BUTTON GPIO to 0.
 */
static void
leon_fatal_sync (void)
{
    GPIO_SETUP (LEON_FATAL_BUTTON, GPIO_DIRECTION_OUT);
    GPIO_SET (LEON_FATAL_BUTTON, 0);
}

void
leon_fatal_button_init (void)
{
    static cyg_interrupt interrupt;
    static cyg_handle_t handle;
    /* Configure and attach interrupt. */
    cyg_drv_interrupt_create (LEON_GPIO_ITC1_IT (CONFIG_LEON_FATAL_BUTTON_IT),
                              0, 0, leon_fatal_button_isr,
                              leon_fatal_button_dsr, &handle,
                              &interrupt);
    cyg_drv_interrupt_attach (handle);
    cyg_drv_interrupt_unmask (
        LEON_GPIO_ITC1_IT (CONFIG_LEON_FATAL_BUTTON_IT));
    /* Configure GPIO. */
    LEON_GPIO_IT = LEON_GPIO_IT_CONFIG (CONFIG_LEON_FATAL_BUTTON_IT,
                                        LEON_GPIO_IT_CONFIG_ENABLED
                                        | LEON_GPIO_IT_CONFIG_EDGE
                                        | CONFIG_GPIO_LEON_FATAL_BUTTON_GPIO);
    /* Register callback to dbg lib. */
    dbg_assert (!dbg_fatal_cb[0]);
    dbg_fatal_cb[0] = leon_fatal_sync;
}