Project

General

Profile

Revision 153

change on ihs

View differences:

proj/Makefile
1 1
PROG=proj
2 2

  
3
SRCS= proj.c graphics.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c
3
SRCS= proj.c graphics.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c
4 4

  
5 5
CPPFLAGS += -pedantic -D __LCOM_OPTIMIZED_
6 6

  
proj/keyboard.h
5 5
#ifndef KEYBOARD_H_INCLUDED
6 6
#define KEYBOARD_H_INCLUDED
7 7

  
8
/**
9
 * @brief Subscribes Keyboard Interrupts and disables Minix Default IH
10
 * @param interrupt_bit Bit of Interrupt Vector that will be set when Keyboard Interrupt is pending
11
 * @param interrupt_id Keyboard Interrupt ID to specify the Keyboard Interrupt in other calls
12
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
13
 * @see {_ERRORS_H_::errors}
14
 */
8 15
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
9 16

  
10 17
uint8_t scancode[2];
proj/proj.c
18 18
#include "keyboard.h"
19 19
#include "mouse.h"
20 20
#include "utils.h"
21
#include "interrupts_func.h"
21 22

  
22 23
int main(int argc, char* argv[]) {
23 24

  
......
58 59
    /// loop stuff
59 60
    int ipc_status, r;
60 61
    message msg;
61
    /// Keyboard interrupt handling
62
    uint8_t kbc_irq_bit = KBC_IRQ;
63
    int kbc_id = 0;
64
    int kbc_irq = BIT(kbc_irq_bit);
65
    if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) {
66
        return 1;
67
    }
68 62

  
69
    /// Timer interrupt handling
70
    //const uint32_t frequency = sys_hz(); // Frequency asummed at 60Hz
71
    uint8_t timer_irq_bit = TIMER0_IRQ;
72
    int timer_id = 0;
73
    int timer_irq = BIT(timer_irq_bit);
74
    if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) {
75
        if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__);
76
        if (free_memory_map()) {
77
            printf("%s: lm_free failed\n", __func__);
78
        }
79
        return 1;
80
    }
63
    /// subscribe interrupts
64
    if (subscribe_all()) return 1;
81 65

  
82
    /// Mouse interrupt handling
83
    uint8_t mouse_irq_bit = MOUSE_IRQ;
84
    int mouse_id = 0;
85
    int mouse_irq = BIT(mouse_irq_bit);
86

  
87
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
88
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
89
    if (mouse_set_data_report(true)) return 1; // enables mouse data reporting
90
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
91

  
92 66
    /// cycle
93 67
    int good = 1;
94 68
    while (good) {
......
100 74
        if (is_ipc_notify(ipc_status)) { /* received notification */
101 75
            switch (_ENDPOINT_P(msg.m_source)) {
102 76
                case HARDWARE: /* hardware interrupt notification */
103
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
104
                        kbc_ih();
105
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
77
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
78
                        if (msg.m_notify.interrupts & n) {
79
                            interrupt_handler(i);
80
                        }
106 81
                    }
107
                    if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */
108
                        timer_int_handler();
109
                    }
110

  
111
                    if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */
112
                        mouse_ih();
113
                    }
82
                    if (scancode[0] == ESC_BREAK_CODE) good = 0;
114 83
                    break;
115 84
                default:
116 85
                    break; /* no other notifications expected: do nothing */
......
120 89
        }
121 90
    }
122 91

  
123
    // Unsubscribe Keyboard interrupts
124
    if (unsubscribe_interrupt(&kbc_id)) {
125
        return 1;
126
    };
92
    // Unsubscribe interrupts
93
    if (unsubscribe_all()) return 1;
127 94

  
128
    // Unsubscribe Timer Interrupts
129
    if (unsubscribe_interrupt(&timer_id)) {
130
        return 1;
131
    }
132 95

  
133
    // Unsubscribe Mouse Interrupts
134
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
135
    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
136
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
137
    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
138

  
139
    
140 96
    if (vg_exit()) {
141 97
        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
142 98
        if (free_memory_map()) printf("%s: lm_free failed\n", __func__);
......
148 104
        return 1;
149 105
    }
150 106

  
151
    
107

  
152 108
    #ifdef DIOGO
153 109
        hello
154 110
    #endif

Also available in: Unified diff