2 * AcessOS EDI Interface
5 * By John Hodge (thePowersGang)
7 * This file has been released into the public domain.
8 * You are free to use it as you wish.
14 uint16_t State; // 0: Unallocated, 1: Allocated, 2: Initialised, (Bit 0x8000 set if in heap)
16 interrupt_handler_t Handler;
20 void EDI_Int_IRQ_Handler(tRegs *Regs);
23 tEdiIRQ gEdi_IRQObjects[16];
27 * \fn object_pointer Edi_Int_IRQ_Construct(void)
28 * \brief Creates a new IRQ Object
29 * \return Pointer to object
31 object_pointer Edi_Int_IRQ_Construct(void)
34 // Search for a free irq
35 for( i = 0; i < 16; i ++ )
37 if(gEdi_IRQObjects[i].State) continue;
38 gEdi_IRQObjects[i].State = 1;
39 gEdi_IRQObjects[i].Num = 0;
40 gEdi_IRQObjects[i].Handler = NULL;
41 return &gEdi_IRQObjects[i];
47 * \fn void Edi_Int_IRQ_Destruct(object_pointer Object)
48 * \brief Destruct an IRQ Object
49 * \param Object Object to destroy
51 void Edi_Int_IRQ_Destruct(object_pointer Object)
55 VALIDATE_PTR(Object,);
56 obj = GET_DATA(Object);
58 if( !obj->State ) return;
61 irq_uninstall_handler( obj->Num );
63 if( obj->State & 0x8000 ) { // If in heap, free
65 } else { // Otherwise, mark as unallocated
71 * \fn int32_t Edi_Int_IRQ_InitInt(object_pointer Object, uint16_t Num, interrupt_handler_t Handler)
72 * \brief Initialises an IRQ
73 * \param Object Object Pointer (this)
74 * \param Num IRQ Number to use
75 * \param Handler Callback for IRQ
77 int32_t Edi_Int_IRQ_InitInt(object_pointer Object, uint16_t Num, interrupt_handler_t Handler)
81 //LogF("Edi_Int_IRQ_InitInt: (Object=0x%x, Num=%i, Handler=0x%x)\n", Object, Num, Handler);
83 VALIDATE_PTR(Object,0);
84 obj = GET_DATA(Object);
86 if( !obj->State ) return 0;
88 if(Num > 15) return 0;
90 // Install the IRQ if a handler is passed
92 if( !irq_install_handler(Num, Edi_Int_IRQ_Handler) )
94 obj->Handler = Handler;
98 obj->State &= ~0x3FFF;
99 obj->State |= 2; // Set initialised flag
104 * \fn uint16_t Edi_Int_IRQ_GetInt(object_pointer Object)
105 * \brief Returns the irq number associated with the object
106 * \param Object IRQ Object to get number from
109 uint16_t Edi_Int_IRQ_GetInt(object_pointer Object)
113 VALIDATE_PTR(Object,0);
114 obj = GET_DATA(Object);
116 if( !obj->State ) return 0;
121 * \fn void EDI_Int_IRQ_SetHandler(object_pointer Object, interrupt_handler_t Handler)
122 * \brief Set the IRQ handler for an IRQ object
123 * \param Object IRQ Object to alter
124 * \param Handler Function to use as handler
126 void EDI_Int_IRQ_SetHandler(object_pointer Object, interrupt_handler_t Handler)
131 VALIDATE_PTR(Object,);
132 obj = GET_DATA(Object);
134 // Sanity Check arguments
135 if( !obj->State ) return ;
137 // Only register the mediator if it is not already
138 if( Handler && !obj->Handler )
139 if( !irq_install_handler(obj->Num, Edi_Int_IRQ_Handler) )
141 obj->Handler = Handler;
145 * \fn void EDI_Int_IRQ_Return(object_pointer Object)
146 * \brief Return from interrupt
147 * \param Object IRQ Object
148 * \note Due to the structure of acess interrupts, this is a dummy
150 void EDI_Int_IRQ_Return(object_pointer Object)
155 * \fn void Edi_Int_IRQ_Handler(struct regs *Regs)
156 * \brief EDI IRQ Handler - Calls the handler
157 * \param Regs Register state at IRQ call
159 void Edi_Int_IRQ_Handler(struct regs *Regs)
162 for( i = 0; i < 16; i ++ )
164 if(!gEdi_IRQObjects[i].State) continue; // Unused, Skip
165 if(gEdi_IRQObjects[i].Num != Regs->int_no) continue; // Another IRQ, Skip
166 if(!gEdi_IRQObjects[i].Handler) continue; // No Handler, Skip
167 gEdi_IRQObjects[i].Handler( Regs->int_no ); // Call Handler
173 // === CLASS DECLARATION ===
174 static edi_function_declaration_t scEdi_Int_Functions_IRQ[] = {
175 {"int32_t", "init_interrupt", 1, 3, NULL, //scEdi_Int_Variables_IO[0],
176 (function_pointer)Edi_Int_IRQ_InitInt
178 {"uint32_t", "interrupt_get_irq", 1, 1, NULL, //scEdi_Int_Variables_IO[1],
179 (function_pointer)Edi_Int_IRQ_GetInt
181 {"void", "interrupt_set_handler", 1, 2, NULL, //scEdi_Int_Variables_IO[2],
182 (function_pointer)Edi_Int_IRQ_GetInt
184 {"void", "interrupt_return", 1, 1, NULL, //scEdi_Int_Variables_IO[3],
185 (function_pointer)Edi_Int_IRQ_GetInt
188 static edi_class_declaration_t scEdi_Int_Class_IRQ =
190 INTERRUPTS_CLASS, 1, 12,
191 scEdi_Int_Functions_IRQ,
192 Edi_Int_IRQ_Construct,
193 Edi_Int_IRQ_Destruct,