Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emBIOS.
7
//
8
//    emBIOS is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emBIOS is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
14 theseven 25
#include "panic.h"
15 theseven 26
#include "lcd.h"
27
#include "lcdconsole.h"
2 theseven 28
#include "console.h"
15 theseven 29
#include "format.h"
30
#include "thread.h"
31
#include "contextswitch.h"
2 theseven 32
 
33
 
15 theseven 34
void hang();
35
 
36
 
14 theseven 37
void handle_panic(enum panic_severity severity)
2 theseven 38
{
15 theseven 39
    thread_exit();
2 theseven 40
}
41
 
14 theseven 42
void panic(enum panic_severity severity, const char* string)
2 theseven 43
{
15 theseven 44
    if (severity == PANIC_FATAL)
45
    {
46
        enter_critical_section();
47
        while (!displaylcd_safe());
48
        lcdconsole_puts_noblit("\n*PANIC*\n", 0, -1);
49
        lcdconsole_puts_noblit(string, 0, -1);
50
        lcdconsole_puts_noblit("\n", 0, -1);
51
        lcdconsole_update();
52
        hang();
53
    }
54
    else
55
    {
56
        cputs(1, "\n*PANIC*\n");
57
        cputs(1, string);
58
        cputc(1, '\n');
59
        handle_panic(severity);
60
    }
2 theseven 61
}
62
 
15 theseven 63
static int pprfunc(void* ptr, unsigned char letter)
64
{
65
    lcdconsole_putc_noblit(letter, 0, -1);
66
    return true;
67
}
68
 
14 theseven 69
void panicf(enum panic_severity severity, const char* string, ...)
2 theseven 70
{
15 theseven 71
    va_list ap;
72
    if (severity == PANIC_FATAL)
73
    {
74
        enter_critical_section();
75
        while (!displaylcd_safe());
76
        lcdconsole_puts_noblit("\n*PANIC*\n", 0, -1);
77
        va_start(ap, string);
78
        format(pprfunc, NULL, string, ap);
79
        va_end(ap);
80
        lcdconsole_puts_noblit("\n", 0, -1);
81
        lcdconsole_update();
82
        hang();
83
    }
84
    else
85
    {
86
        cputs(1, "\n*PANIC*\n");
87
        va_start(ap, string);
88
        cvprintf(1, string, ap);
89
        va_end(ap);
90
        cputc(1, '\n');
91
        handle_panic(severity);
92
    }
2 theseven 93
}
94
 
95
void __div0()
96
{
15 theseven 97
    panic(PANIC_KILLTHREAD, "Division by zero!");
2 theseven 98
}