native: add and use callback type
This commit is contained in:
parent
7301a895f5
commit
7bcf896ec6
@ -46,6 +46,12 @@
|
|||||||
|
|
||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prototype for native's internal callbacks
|
||||||
|
*/
|
||||||
|
typedef void (*_native_callback_t)(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* internal functions
|
* internal functions
|
||||||
*/
|
*/
|
||||||
@ -120,7 +126,7 @@ ssize_t _native_write(int fd, const void *buf, size_t count);
|
|||||||
/**
|
/**
|
||||||
* register interrupt handler handler for interrupt sig
|
* register interrupt handler handler for interrupt sig
|
||||||
*/
|
*/
|
||||||
int register_interrupt(int sig, void (*handler)(void));
|
int register_interrupt(int sig, _native_callback_t handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unregister interrupt handler for interrupt sig
|
* unregister interrupt handler for interrupt sig
|
||||||
|
|||||||
@ -59,10 +59,7 @@ volatile unsigned int _native_saved_eip;
|
|||||||
volatile int _native_sigpend;
|
volatile int _native_sigpend;
|
||||||
int _sig_pipefd[2];
|
int _sig_pipefd[2];
|
||||||
|
|
||||||
struct int_handler_t {
|
static _native_callback_t native_irq_handlers[255];
|
||||||
void (*func)(void);
|
|
||||||
};
|
|
||||||
static struct int_handler_t native_irq_handlers[255];
|
|
||||||
char sigalt_stk[SIGSTKSZ];
|
char sigalt_stk[SIGSTKSZ];
|
||||||
|
|
||||||
void print_thread_sigmask(ucontext_t *cp)
|
void print_thread_sigmask(ucontext_t *cp)
|
||||||
@ -74,7 +71,7 @@ void print_thread_sigmask(ucontext_t *cp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < (NSIG); i++) {
|
for (int i = 1; i < (NSIG); i++) {
|
||||||
if (native_irq_handlers[i].func != NULL) {
|
if (native_irq_handlers[i] != NULL) {
|
||||||
printf("%s: %s\n",
|
printf("%s: %s\n",
|
||||||
strsignal(i),
|
strsignal(i),
|
||||||
(sigismember(&_native_sig_set, i) ? "blocked" : "unblocked")
|
(sigismember(&_native_sig_set, i) ? "blocked" : "unblocked")
|
||||||
@ -121,7 +118,7 @@ void native_print_signals(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < (NSIG); i++) {
|
for (int i = 1; i < (NSIG); i++) {
|
||||||
if (native_irq_handlers[i].func != NULL || i == SIGUSR1) {
|
if (native_irq_handlers[i] != NULL || i == SIGUSR1) {
|
||||||
printf("%s: %s in active thread\n",
|
printf("%s: %s in active thread\n",
|
||||||
strsignal(i),
|
strsignal(i),
|
||||||
(sigismember(&_native_sig_set, i) ? "blocked" : "unblocked")
|
(sigismember(&_native_sig_set, i) ? "blocked" : "unblocked")
|
||||||
@ -259,9 +256,9 @@ void native_irq_handler(void)
|
|||||||
int sig = _native_popsig();
|
int sig = _native_popsig();
|
||||||
_native_sigpend--;
|
_native_sigpend--;
|
||||||
|
|
||||||
if (native_irq_handlers[sig].func != NULL) {
|
if (native_irq_handlers[sig] != NULL) {
|
||||||
DEBUG("calling interrupt handler for %i\n", sig);
|
DEBUG("calling interrupt handler for %i\n", sig);
|
||||||
native_irq_handlers[sig].func();
|
native_irq_handlers[sig]();
|
||||||
}
|
}
|
||||||
else if (sig == SIGUSR1) {
|
else if (sig == SIGUSR1) {
|
||||||
DEBUG("ignoring SIGUSR1\n");
|
DEBUG("ignoring SIGUSR1\n");
|
||||||
@ -360,7 +357,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
|
|||||||
* TODO: use appropriate data structure for signal
|
* TODO: use appropriate data structure for signal
|
||||||
* handlers.
|
* handlers.
|
||||||
*/
|
*/
|
||||||
int register_interrupt(int sig, void (*handler)(void))
|
int register_interrupt(int sig, _native_callback_t handler)
|
||||||
{
|
{
|
||||||
DEBUG("register_interrupt()\n");
|
DEBUG("register_interrupt()\n");
|
||||||
|
|
||||||
@ -369,7 +366,7 @@ int register_interrupt(int sig, void (*handler)(void))
|
|||||||
err(EXIT_FAILURE, "register_interrupt: sigdelset");
|
err(EXIT_FAILURE, "register_interrupt: sigdelset");
|
||||||
}
|
}
|
||||||
|
|
||||||
native_irq_handlers[sig].func = handler;
|
native_irq_handlers[sig] = handler;
|
||||||
|
|
||||||
/* set current dINT sigmask for all signals */
|
/* set current dINT sigmask for all signals */
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@ -377,7 +374,7 @@ int register_interrupt(int sig, void (*handler)(void))
|
|||||||
sa.sa_mask = _native_sig_set_dint;
|
sa.sa_mask = _native_sig_set_dint;
|
||||||
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
|
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
|
||||||
for (int i = 0; i < 255; i++) {
|
for (int i = 0; i < 255; i++) {
|
||||||
if (native_irq_handlers[i].func != NULL) {
|
if (native_irq_handlers[i] != NULL) {
|
||||||
if (sigaction(sig, &sa, NULL)) {
|
if (sigaction(sig, &sa, NULL)) {
|
||||||
err(EXIT_FAILURE, "register_interrupt: sigaction");
|
err(EXIT_FAILURE, "register_interrupt: sigaction");
|
||||||
}
|
}
|
||||||
@ -400,7 +397,7 @@ int unregister_interrupt(int sig)
|
|||||||
err(EXIT_FAILURE, "unregister_interrupt: sigaddset");
|
err(EXIT_FAILURE, "unregister_interrupt: sigaddset");
|
||||||
}
|
}
|
||||||
|
|
||||||
native_irq_handlers[sig].func = NULL;
|
native_irq_handlers[sig] = NULL;
|
||||||
|
|
||||||
/* reset signal handler for sig */
|
/* reset signal handler for sig */
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@ -413,7 +410,7 @@ int unregister_interrupt(int sig)
|
|||||||
/* change sigmask for remaining signal handlers */
|
/* change sigmask for remaining signal handlers */
|
||||||
sa.sa_sigaction = native_isr_entry;
|
sa.sa_sigaction = native_isr_entry;
|
||||||
for (int i = 0; i < 255; i++) {
|
for (int i = 0; i < 255; i++) {
|
||||||
if (native_irq_handlers[i].func != NULL) {
|
if (native_irq_handlers[i] != NULL) {
|
||||||
if (sigaction(sig, &sa, NULL)) {
|
if (sigaction(sig, &sa, NULL)) {
|
||||||
err(EXIT_FAILURE, "register_interrupt: sigaction");
|
err(EXIT_FAILURE, "register_interrupt: sigaction");
|
||||||
}
|
}
|
||||||
@ -451,7 +448,7 @@ void native_interrupt_init(void)
|
|||||||
_native_sigpend = 0;
|
_native_sigpend = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 255; i++) {
|
for (int i = 0; i < 255; i++) {
|
||||||
native_irq_handlers[i].func = NULL;
|
native_irq_handlers[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.sa_sigaction = native_isr_entry;
|
sa.sa_sigaction = native_isr_entry;
|
||||||
|
|||||||
@ -29,15 +29,13 @@
|
|||||||
#include "transceiver.h"
|
#include "transceiver.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
|
|
||||||
|
#include "native_internal.h"
|
||||||
#include "tap.h"
|
#include "tap.h"
|
||||||
#include "nativenet.h"
|
#include "nativenet.h"
|
||||||
#include "nativenet_internal.h"
|
#include "nativenet_internal.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
||||||
struct nativenet_callback_s {
|
static _native_callback_t _nativenet_callbacks[255];
|
||||||
void (*func)(void);
|
|
||||||
};
|
|
||||||
static struct nativenet_callback_s _nativenet_callbacks[255];
|
|
||||||
|
|
||||||
struct rx_buffer_s _nativenet_rx_buffer[RX_BUF_SIZE];
|
struct rx_buffer_s _nativenet_rx_buffer[RX_BUF_SIZE];
|
||||||
static volatile uint8_t rx_buffer_next;
|
static volatile uint8_t rx_buffer_next;
|
||||||
@ -151,14 +149,14 @@ void nativenet_switch_to_rx(void)
|
|||||||
/* nativenet_internal.h *************************************************/
|
/* nativenet_internal.h *************************************************/
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
int _nativenet_register_cb(int event, void (*func)(void))
|
int _nativenet_register_cb(int event, _native_callback_t func)
|
||||||
{
|
{
|
||||||
if (event > NNEV_MAXEV) {
|
if (event > NNEV_MAXEV) {
|
||||||
DEBUG("_nativenet_register_cb: event > NNEV_MAXEV\n");
|
DEBUG("_nativenet_register_cb: event > NNEV_MAXEV\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nativenet_callbacks[event].func = func;
|
_nativenet_callbacks[event] = func;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +167,7 @@ int _nativenet_unregister_cb(int event)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nativenet_callbacks[event].func = NULL;
|
_nativenet_callbacks[event] = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,8 +178,8 @@ void do_cb(int event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nativenet_callbacks[event].func != NULL) {
|
if (_nativenet_callbacks[event] != NULL) {
|
||||||
_nativenet_callbacks[event].func();
|
_nativenet_callbacks[event]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user