Skip to content

Conversation

@wjn740
Copy link
Contributor

@wjn740 wjn740 commented Feb 10, 2020

Enable timer interrupt.
Please take a look. @coolgw @Aleksei_Burlakov.

include/timer.h Outdated
#define USED 1

typedef struct TIMER {
struct TIMER *next;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the next pointer? As I understand we have a pool of those rather than a linked list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I seems like can't recall what it does mean, :-) the code is long far away ago. The next pointer is not for a link list. might be mean where is the next fired.

unsigned int count, next;
struct TIMER *current;
struct TIMER pool[MAX_TIMER];
}timer_zone;
Copy link

@aleksei-burlakov aleksei-burlakov Feb 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a matter of taste, but I usually stick to the occam's razor rule, - be minimalistic in the code. We don't actually need those singletons like timer_zone and timer. And declaring the timer_zone timers; in the timer.c:5 can be immediatelly like TIMER_POOL timer.
And besides, I don't remember about how it was in our convention, but usually, people use the UPPERCASE_NAMES for constants and all magics. Naming the structures are usually lower_case_names.
@wjn740 @crazyss what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I think you are right. I don't have too much experience on this, but I'd like to improve it.

}
t = timers.current;
for(;;) {
if (t->timeout > timers.count) {
Copy link

@aleksei-burlakov aleksei-burlakov Feb 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make cleaner, like while(t->timeout <= timers.count) {...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me look into it. now

@wjn740 wjn740 force-pushed the jnwang/enable_timer_interrupt branch from 3a89bf8 to 7366464 Compare February 12, 2020 01:34
@wjn740 wjn740 added the Feature label Feb 12, 2020
}


timer* timer_alloc(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suppose this function will add new timer, and should has following parameters?

  1. timeout
  2. func name which will be called after timeout

unsigned int timeout, flags;
int data;
}timer;

Copy link
Contributor

@coolgw coolgw Feb 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be simple, i think following struct already can reach our goal.
timer {
struct timer *next;
void (*fun)();
long timeout;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your opinions look like a work queue.

James Wang added 5 commits February 13, 2020 19:22
Inital PIT controller, enable IRQ0, serial console as output.
timer.c is created for storing the code
@wjn740 wjn740 force-pushed the jnwang/enable_timer_interrupt branch from 99a0183 to 389ccb7 Compare February 13, 2020 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants