Added a new timer function which can be used similar to the BeOS kernel add_timer function.
The difference is that these callback functions will be executed in thread (not interrupt) context, and that they shouldn't crash (as add_timer does). Integrated the timer funtions into the timeout() and untimeout() FreeBSD emulation framework. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7474 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,6 +14,7 @@ R5KernelAddon ipro1000 : kernel drivers bin :
|
|||||||
if_em_hw.c
|
if_em_hw.c
|
||||||
if_em_osdep.c
|
if_em_osdep.c
|
||||||
mempool.c
|
mempool.c
|
||||||
|
timer.c
|
||||||
util.c
|
util.c
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "timer.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
@@ -130,7 +131,7 @@ init_driver(void)
|
|||||||
if (info) {
|
if (info) {
|
||||||
char name[64];
|
char name[64];
|
||||||
sprintf(name, "net/ipro1000/%d", cards);
|
sprintf(name, "net/ipro1000/%d", cards);
|
||||||
TRACE("/dev/%s is a %s\n", name, info);
|
PRINT("/dev/%s is a %s\n", name, info);
|
||||||
gDevList[cards] = item;
|
gDevList[cards] = item;
|
||||||
gDevNameList[cards] = strdup(name);
|
gDevNameList[cards] = strdup(name);
|
||||||
gDevNameList[cards + 1] = NULL;
|
gDevNameList[cards + 1] = NULL;
|
||||||
@@ -148,16 +149,24 @@ init_driver(void)
|
|||||||
free(item);
|
free(item);
|
||||||
|
|
||||||
if (!cards)
|
if (!cards)
|
||||||
goto err;
|
goto err_cards;
|
||||||
|
|
||||||
if (mempool_init(cards * 768) != 0) {
|
if (initialize_timer() != B_OK) {
|
||||||
TRACE("mempool init failed\n");
|
ERROR("timer init failed\n");
|
||||||
goto err;
|
goto err_timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mempool_init(cards * 768) != B_OK) {
|
||||||
|
ERROR("mempool init failed\n");
|
||||||
|
goto err_mempool;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
err:
|
err_mempool:
|
||||||
|
terminate_timer();
|
||||||
|
err_timer:
|
||||||
|
err_cards:
|
||||||
put_module(B_PCI_MODULE_NAME);
|
put_module(B_PCI_MODULE_NAME);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -170,6 +179,8 @@ uninit_driver(void)
|
|||||||
|
|
||||||
TRACE("uninit_driver()\n");
|
TRACE("uninit_driver()\n");
|
||||||
|
|
||||||
|
terminate_timer();
|
||||||
|
|
||||||
mempool_exit();
|
mempool_exit();
|
||||||
|
|
||||||
for (i = 0; gDevNameList[i] != NULL; i++) {
|
for (i = 0; gDevNameList[i] != NULL; i++) {
|
||||||
|
|||||||
@@ -50,38 +50,24 @@ contigfree(void *p, int p1, int p2)
|
|||||||
delete_area(area_for(p));
|
delete_area(area_for(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32
|
|
||||||
timer_dispatch_hook(timer *t)
|
|
||||||
{
|
|
||||||
struct callout_handle *h = (struct callout_handle *)t;
|
|
||||||
TRACE("timer_dispatch_hook\n");
|
|
||||||
h->func(h->cookie);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
callout_handle_init(struct callout_handle *handle)
|
callout_handle_init(struct callout_handle *handle)
|
||||||
{
|
{
|
||||||
memset(handle, 0, sizeof(*handle));
|
handle->timer = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct callout_handle
|
struct callout_handle
|
||||||
timeout(timeout_func func, void *cookie, bigtime_t timeout)
|
timeout(timer_function func, void *cookie, bigtime_t timeout)
|
||||||
{
|
{
|
||||||
struct callout_handle h;
|
struct callout_handle handle;
|
||||||
|
handle.timer = create_timer(func, cookie, timeout, B_ONE_SHOT_RELATIVE_TIMER);
|
||||||
h.func = func;
|
return handle;
|
||||||
h.cookie = cookie;
|
|
||||||
|
|
||||||
// add_timer(&h.t, timer_dispatch_hook, timeout, B_ONE_SHOT_RELATIVE_TIMER);
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
untimeout(timeout_func func, void *cookie, struct callout_handle handle)
|
untimeout(timer_function func, void *cookie, struct callout_handle handle)
|
||||||
{
|
{
|
||||||
// cancel_timer(&handle.t);
|
delete_timer(handle.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct resource *
|
struct resource *
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
#define DBG 0
|
#define DBG 0
|
||||||
|
|
||||||
@@ -159,18 +160,14 @@ static inline unsigned long vtophys(unsigned long virtual_addr)
|
|||||||
#define PAGE_SIZE 4096
|
#define PAGE_SIZE 4096
|
||||||
|
|
||||||
|
|
||||||
typedef void (*timeout_func)(void *);
|
|
||||||
|
|
||||||
struct callout_handle
|
struct callout_handle
|
||||||
{
|
{
|
||||||
struct timer t; // must be on top
|
timer_id timer;
|
||||||
timeout_func func;
|
|
||||||
void *cookie;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void callout_handle_init(struct callout_handle *handle);
|
void callout_handle_init(struct callout_handle *handle);
|
||||||
struct callout_handle timeout(timeout_func func, void *cookie, bigtime_t timeout);
|
struct callout_handle timeout(timer_function func, void *cookie, bigtime_t timeout);
|
||||||
void untimeout(timeout_func func, void *cookie, struct callout_handle handle);
|
void untimeout(timer_function func, void *cookie, struct callout_handle handle);
|
||||||
|
|
||||||
|
|
||||||
// resource management
|
// resource management
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* Intel PRO/1000 Family Driver
|
||||||
|
* Copyright (C) 2004 Marcus Overhagen <[email protected]>. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify and distribute this software and its
|
||||||
|
* documentation for any purpose and without fee is hereby granted, provided
|
||||||
|
* that the above copyright notice appear in all copies, and that both the
|
||||||
|
* copyright notice and this permission notice appear in supporting documentation.
|
||||||
|
*
|
||||||
|
* Marcus Overhagen makes no representations about the suitability of this software
|
||||||
|
* for any purpose. It is provided "as is" without express or implied warranty.
|
||||||
|
*
|
||||||
|
* MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||||
|
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
|
||||||
|
* OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
|
||||||
|
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <Errors.h>
|
||||||
|
#include <OS.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "debug.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
|
timer_id
|
||||||
|
create_timer(timer_function func, void *cookie, bigtime_t period, uint32 flags)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
delete_timer(timer_id id)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
initialize_timer(void)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
terminate_timer(void)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Intel PRO/1000 Family Driver
|
||||||
|
* Copyright (C) 2004 Marcus Overhagen <[email protected]>. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify and distribute this software and its
|
||||||
|
* documentation for any purpose and without fee is hereby granted, provided
|
||||||
|
* that the above copyright notice appear in all copies, and that both the
|
||||||
|
* copyright notice and this permission notice appear in supporting documentation.
|
||||||
|
*
|
||||||
|
* Marcus Overhagen makes no representations about the suitability of this software
|
||||||
|
* for any purpose. It is provided "as is" without express or implied warranty.
|
||||||
|
*
|
||||||
|
* MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||||
|
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
|
||||||
|
* OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
|
||||||
|
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef __TIMER_H
|
||||||
|
#define __TIMER_H
|
||||||
|
|
||||||
|
#include <KernelExport.h>
|
||||||
|
|
||||||
|
// Since the BeOS kernel timers are executed in interrupt context,
|
||||||
|
// a new timer has been created. The timers are executed in thread
|
||||||
|
// context, and are passed a cookie.
|
||||||
|
|
||||||
|
typedef int32 timer_id;
|
||||||
|
|
||||||
|
typedef void (*timer_function)(void *cookie);
|
||||||
|
|
||||||
|
// create_timer() cannot be called from interrupt context.
|
||||||
|
// flags can be B_ONE_SHOT_ABSOLUTE_TIMER, B_ONE_SHOT_RELATIVE_TIMER or B_PERIODIC_TIMER
|
||||||
|
|
||||||
|
timer_id create_timer(timer_function func, void *cookie, bigtime_t period, uint32 flags);
|
||||||
|
status_t delete_timer(timer_id id);
|
||||||
|
|
||||||
|
|
||||||
|
status_t initialize_timer(void);
|
||||||
|
status_t terminate_timer(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user