summaryrefslogtreecommitdiff
path: root/maximus/stationtest/src/exception.c
blob: cbd0129cd161bb9d833f9a5a4de98235f2a22eaa (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    exception.c
 * \brief   how to catch an exception
 * \ingroup 
 *
 * this is a test program to check eCos well work
 */

#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>
#include <cyg/hal/hal_intr.h>
#include "common/std.h"
#include <host/station.h>

extern station_ctx_t my_station;

void system_call_exception(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info)
{
    switch(number)
    {
    case CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION: 
        diag_printf("eCos: Exception Error (Illegal Instruction)!!!\n");
        break;

    case CYGNUM_HAL_EXCEPTION_DATA_ACCESS: 
        diag_printf("eCos: Exception Error (Data Access)!!!\n");
        break;

    case CYGNUM_HAL_EXCEPTION_FPU:
        diag_printf("eCos: Exception Error (FPU)!!!\n");
        break;
    }
//    station_down(&my_station);
//    cyg_hal_sys_exit(1);
}

void cyg_user_start(void)
{
    char *ptr = 0x0000;
    cyg_exception_handler_t *oldHandler;
    cyg_addrword_t oldData;

    diag_write_string("debut du main\n");

    cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION,
                              &system_call_exception,
                              0,
                              &oldHandler,
                              &oldData);
    cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_DATA_ACCESS,
                              &system_call_exception,
                              0,
                              &oldHandler,
                              &oldData);
    cyg_exception_set_handler(CYGNUM_HAL_EXCEPTION_FPU,
                              &system_call_exception,
                              0,
                              &oldHandler,
                              &oldData);

    diag_write_string("exception enregistrees\n");

//    cyg_thread_delay(10);
    *ptr = 12;
    diag_write_string("fin du main\n");
}