summaryrefslogtreecommitdiff
path: root/test_general/ecos/src/interrupt.c
blob: 8679e9eaeb6c9f5809a62078be5558c71dc70ac9 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    interrupt.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */

#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>

static cyg_interrupt int1;
static cyg_handle_t int1_handle;
static cyg_sem_t data_ready;

#define CYGNUM_HAL_PRI_HIGH 0

//
// Interrupt service routine for interrupt 1.
//
cyg_uint32 interrupt_1_isr(
    cyg_vector_t vector,
    cyg_addrword_t data)
{
    diag_write_char('i');
    // Block this interrupt from occurring until
    // the DSR completes.
    cyg_interrupt_mask(vector);

    // Tell the processor that we have received
    // the interrupt.
    cyg_interrupt_acknowledge(vector);

    // Tell the kernel that chained interrupt processing
    // is done and the DSR needs to be executed next.
    return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
}

//
// Deferred service routine for interrupt 1.
//
void interrupt_1_dsr(
    cyg_vector_t vector,
    cyg_ucount32 count,
    cyg_addrword_t data)
{
    diag_write_char('d');
    // Signal the thread to run for further processing.
    cyg_semaphore_post(&data_ready);

    // Allow this interrupt to occur again.
    cyg_interrupt_unmask(vector);
}

//
// Main starting point for the application.
//
void cyg_user_start(
    void)
{
    cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_8;
    cyg_priority_t int1_priority = CYGNUM_HAL_PRI_HIGH;

    // Initialize the semaphore used for interrupt 1.
    cyg_semaphore_init(&data_ready, 0);

    //
    // Create interrupt 1.
    //
    cyg_interrupt_create(
        int1_vector,
        int1_priority,
        0,
        &interrupt_1_isr,
        &interrupt_1_dsr,
        &int1_handle,
        &int1);

    // Attach the interrupt created to the vector.
    cyg_interrupt_attach(int1_handle);

    // Unmask the interrupt we just configured.
    cyg_interrupt_unmask(int1_vector);

    diag_write_char('m');
    while(1)
    {
//        diag_write_string("Waiting semaphore...\n");
//        // Wait semaphore
//        cyg_semaphore_wait(&data_ready);
//        diag_write_string("Thank you DSR, I will continue\n\n");
    }
}