source: trunk/kernel/arch/ibmpc/rt_timer.c @ 188

Last change on this file since 188 was 11, checked in by alain, 8 years ago

Merge all FS related files in one single vfs directory.

File size: 2.4 KB
Line 
1/*
2 * rt_timer.c - real-time timer related operations
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <types.h>
24#include <rt_timer.h>
25#include <cpu.h>
26#include <chdev.h>
27#include <driver.h>
28#include <sysio.h>
29#include <thread.h>
30#include <kmem.h>
31
32extern struct device_s rt_timer;
33
34static void timer_irq_handler (struct irq_action_s *action)
35{
36        register struct cpu_s *cpu;
37        register struct thread_s *this;
38   
39        this = CURRENT_THREAD;
40        cpu = this->local_cpu;
41
42        if(this->type == PTHREAD)
43        {
44                MEM_CHECK(this->info.usr_stack_base);
45        }
46   
47        MEM_CHECK(this->info.sys_stack_base);
48   
49        cpu->alarm_mgr.action.irq_handler(&cpu->alarm_mgr.action);
50
51        cpu->tics_nr ++;
52        cpu->tics_count ++;
53        sched_clock(this);
54}
55
56/** Initialize Real-Time timer source */
57error_t rt_timer_init(uint_t period, uint_t withIrq)
58{
59        rt_timer.irq = 0;
60        rt_timer.action.irq_handler = &timer_irq_handler;
61        rt_timer.type = DEV_TIMER;
62
63        strcpy(rt_timer.name, "TIMER");
64        metafs_init(&rt_timer.node, rt_timer.name);
65
66        return 0;
67}
68
69/** Read Real-Time timer current value  */
70error_t rt_timer_read(uint_t *time)
71{
72        *time = CURRENT_THREAD->local_cpu->tics_nr * 20;
73        return 0;
74}
75
76/** Set Real-Time timer's current value */
77error_t rt_timer_set(uint_t time)
78{
79        return 0;
80}
81
82/** Set Real-Time timer's period */
83error_t rt_timer_setperiod(uint_t period)
84{
85        return 0;
86}
87
88/** Send commands to Real-Time timer device */
89error_t rt_timer_ctrl(struct rt_params_s *param)
90{
91        switch(param->rt_cmd)
92        {
93        case RT_TIMER_STOP:
94                //rt_timer.op.timer.stop(&rt_timer);
95                return 0;
96
97        case RT_TIMER_RUN:
98                //rt_timer.op.timer.run(&rt_timer, (uint_t)rt_timer.data);
99                return 0;
100
101        default:
102                return -1;
103        }
104}
Note: See TracBrowser for help on using the repository browser.