2002-04-21 22:06:12 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2002-05-05 18:34:06 +00:00
|
|
|
|
#include <stdlib.h>
|
2002-06-29 21:30:42 +00:00
|
|
|
|
#include <string.h>
|
2005-03-01 14:33:45 +00:00
|
|
|
|
#include "config.h"
|
2002-04-21 22:06:12 +00:00
|
|
|
|
#include "kernel.h"
|
2002-04-25 00:15:04 +00:00
|
|
|
|
#include "thread.h"
|
2004-10-27 07:07:54 +00:00
|
|
|
|
#include "cpu.h"
|
2002-05-05 18:34:06 +00:00
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "panic.h"
|
2002-04-21 22:06:12 +00:00
|
|
|
|
|
2006-02-05 17:34:49 +00:00
|
|
|
|
#if ((CONFIG_CPU != PP5020) && (CONFIG_CPU != PP5002)) || !defined(BOOTLOADER)
|
2002-04-21 22:06:12 +00:00
|
|
|
|
long current_tick = 0;
|
2006-01-05 17:02:48 +00:00
|
|
|
|
#endif
|
2002-04-21 22:06:12 +00:00
|
|
|
|
|
2002-12-18 14:57:45 +00:00
|
|
|
|
static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
|
2002-06-04 12:25:53 +00:00
|
|
|
|
|
2002-06-29 21:19:55 +00:00
|
|
|
|
/* This array holds all queues that are initiated. It is used for broadcast. */
|
|
|
|
|
static struct event_queue *all_queues[32];
|
|
|
|
|
static int num_queues;
|
|
|
|
|
|
2005-11-12 14:48:52 +00:00
|
|
|
|
void sleep(int ticks) ICODE_ATTR;
|
|
|
|
|
void queue_wait(struct event_queue *q, struct event *ev) ICODE_ATTR;
|
2002-08-01 08:14:01 +00:00
|
|
|
|
|
2002-05-05 18:34:06 +00:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Standard kernel stuff
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
void kernel_init(void)
|
|
|
|
|
{
|
2002-06-07 14:56:10 +00:00
|
|
|
|
/* Init the threading API */
|
|
|
|
|
init_threads();
|
|
|
|
|
|
2002-06-29 21:19:55 +00:00
|
|
|
|
memset(tick_funcs, 0, sizeof(tick_funcs));
|
|
|
|
|
|
|
|
|
|
num_queues = 0;
|
|
|
|
|
memset(all_queues, 0, sizeof(all_queues));
|
2006-01-05 17:02:48 +00:00
|
|
|
|
|
2002-05-07 23:01:42 +00:00
|
|
|
|
tick_start(1000/HZ);
|
2002-05-05 18:34:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-21 22:06:12 +00:00
|
|
|
|
void sleep(int ticks)
|
|
|
|
|
{
|
2002-05-08 08:41:19 +00:00
|
|
|
|
/* Always sleep at least 1 tick */
|
|
|
|
|
int timeout = current_tick + ticks + 1;
|
2002-04-21 22:06:12 +00:00
|
|
|
|
|
2002-05-08 08:41:19 +00:00
|
|
|
|
while (TIME_BEFORE( current_tick, timeout )) {
|
2003-02-14 09:44:34 +00:00
|
|
|
|
sleep_thread();
|
2002-05-08 08:41:19 +00:00
|
|
|
|
}
|
2003-02-14 09:44:34 +00:00
|
|
|
|
wake_up_thread();
|
2002-04-21 22:06:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yield(void)
|
|
|
|
|
{
|
2002-04-25 00:15:04 +00:00
|
|
|
|
switch_thread();
|
2003-02-14 09:44:34 +00:00
|
|
|
|
wake_up_thread();
|
2002-04-21 22:06:12 +00:00
|
|
|
|
}
|
2002-04-29 14:25:44 +00:00
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Queue handling stuff
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
void queue_init(struct event_queue *q)
|
|
|
|
|
{
|
|
|
|
|
q->read = 0;
|
|
|
|
|
q->write = 0;
|
2002-06-29 21:19:55 +00:00
|
|
|
|
|
|
|
|
|
/* Add it to the all_queues array */
|
|
|
|
|
all_queues[num_queues++] = q;
|
2002-04-29 14:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-23 10:53:47 +00:00
|
|
|
|
void queue_delete(struct event_queue *q)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2006-01-23 10:59:07 +00:00
|
|
|
|
bool found = false;
|
2006-01-23 10:53:47 +00:00
|
|
|
|
|
|
|
|
|
/* Find the queue to be deleted */
|
|
|
|
|
for(i = 0;i < num_queues;i++)
|
|
|
|
|
{
|
|
|
|
|
if(all_queues[i] == q)
|
2006-01-23 10:59:07 +00:00
|
|
|
|
{
|
|
|
|
|
found = true;
|
2006-01-23 10:53:47 +00:00
|
|
|
|
break;
|
2006-01-23 10:59:07 +00:00
|
|
|
|
}
|
2006-01-23 10:53:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-23 10:59:07 +00:00
|
|
|
|
if(found)
|
2006-01-23 10:53:47 +00:00
|
|
|
|
{
|
2006-01-23 10:59:07 +00:00
|
|
|
|
/* Move the following queues up in the list */
|
|
|
|
|
for(;i < num_queues-1;i++)
|
|
|
|
|
{
|
|
|
|
|
all_queues[i] = all_queues[i+1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num_queues--;
|
2006-01-23 10:53:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-16 20:57:32 +00:00
|
|
|
|
void queue_wait(struct event_queue *q, struct event *ev)
|
2002-04-29 14:25:44 +00:00
|
|
|
|
{
|
|
|
|
|
while(q->read == q->write)
|
|
|
|
|
{
|
2003-02-14 09:44:34 +00:00
|
|
|
|
sleep_thread();
|
2002-04-29 14:25:44 +00:00
|
|
|
|
}
|
2003-02-14 09:44:34 +00:00
|
|
|
|
wake_up_thread();
|
2002-04-29 14:25:44 +00:00
|
|
|
|
|
2002-05-16 20:57:32 +00:00
|
|
|
|
*ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
|
2002-04-29 14:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 08:56:23 +00:00
|
|
|
|
void queue_wait_w_tmo(struct event_queue *q, struct event *ev, int ticks)
|
|
|
|
|
{
|
|
|
|
|
unsigned int timeout = current_tick + ticks;
|
|
|
|
|
|
|
|
|
|
while(q->read == q->write && TIME_BEFORE( current_tick, timeout ))
|
|
|
|
|
{
|
2003-02-14 09:44:34 +00:00
|
|
|
|
sleep_thread();
|
2002-10-11 08:56:23 +00:00
|
|
|
|
}
|
2003-02-14 09:44:34 +00:00
|
|
|
|
wake_up_thread();
|
2002-10-11 08:56:23 +00:00
|
|
|
|
|
|
|
|
|
if(q->read != q->write)
|
|
|
|
|
{
|
|
|
|
|
*ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ev->id = SYS_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-24 14:26:24 +00:00
|
|
|
|
void queue_post(struct event_queue *q, long id, void *data)
|
2002-04-29 14:25:44 +00:00
|
|
|
|
{
|
2002-05-08 22:07:41 +00:00
|
|
|
|
int wr;
|
|
|
|
|
int oldlevel;
|
|
|
|
|
|
2004-03-02 11:32:59 +00:00
|
|
|
|
oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
|
2002-05-08 22:07:41 +00:00
|
|
|
|
wr = (q->write++) & QUEUE_LENGTH_MASK;
|
2002-04-29 14:25:44 +00:00
|
|
|
|
|
|
|
|
|
q->events[wr].id = id;
|
|
|
|
|
q->events[wr].data = data;
|
2002-05-08 22:07:41 +00:00
|
|
|
|
set_irq_level(oldlevel);
|
2002-04-29 14:25:44 +00:00
|
|
|
|
}
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
2004-08-16 23:37:23 +00:00
|
|
|
|
bool queue_empty(const struct event_queue* q)
|
2002-05-23 09:22:07 +00:00
|
|
|
|
{
|
|
|
|
|
return ( q->read == q->write );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-01 06:24:05 +00:00
|
|
|
|
void queue_clear(struct event_queue* q)
|
2004-09-01 06:20:21 +00:00
|
|
|
|
{
|
2004-09-01 06:24:05 +00:00
|
|
|
|
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
|
2004-09-01 06:20:21 +00:00
|
|
|
|
q->read = 0;
|
|
|
|
|
q->write = 0;
|
2004-09-01 06:24:05 +00:00
|
|
|
|
set_irq_level(oldlevel);
|
2004-09-01 06:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 15:40:25 +00:00
|
|
|
|
int queue_broadcast(long id, void *data)
|
2002-06-29 21:19:55 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for(i = 0;i < num_queues;i++)
|
|
|
|
|
{
|
|
|
|
|
queue_post(all_queues[i], id, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return num_queues;
|
|
|
|
|
}
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Timer tick
|
|
|
|
|
****************************************************************************/
|
2004-10-27 07:07:54 +00:00
|
|
|
|
#if CONFIG_CPU == SH7034
|
2005-03-01 14:33:45 +00:00
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
2002-05-05 18:34:06 +00:00
|
|
|
|
{
|
2005-10-03 09:24:36 +00:00
|
|
|
|
unsigned long count;
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
2005-10-03 09:24:36 +00:00
|
|
|
|
count = CPU_FREQ * interval_in_ms / 1000 / 8;
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
2005-10-03 09:24:36 +00:00
|
|
|
|
if(count > 0x10000)
|
2002-05-05 18:34:06 +00:00
|
|
|
|
{
|
|
|
|
|
panicf("Error! The tick interval is too long (%d ms)\n",
|
|
|
|
|
interval_in_ms);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We are using timer 0 */
|
|
|
|
|
|
|
|
|
|
TSTR &= ~0x01; /* Stop the timer */
|
|
|
|
|
TSNC &= ~0x01; /* No synchronization */
|
|
|
|
|
TMDR &= ~0x01; /* Operate normally */
|
|
|
|
|
|
|
|
|
|
TCNT0 = 0; /* Start counting at 0 */
|
2005-10-03 09:24:36 +00:00
|
|
|
|
GRA0 = (unsigned short)(count - 1);
|
2002-05-05 18:34:06 +00:00
|
|
|
|
TCR0 = 0x23; /* Clear at GRA match, sysclock/8 */
|
|
|
|
|
|
|
|
|
|
/* Enable interrupt on level 1 */
|
|
|
|
|
IPRC = (IPRC & ~0x00f0) | 0x0010;
|
|
|
|
|
|
|
|
|
|
TSR0 &= ~0x01;
|
|
|
|
|
TIER0 = 0xf9; /* Enable GRA match interrupt */
|
|
|
|
|
|
|
|
|
|
TSTR |= 0x01; /* Start timer 1 */
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-03 09:24:36 +00:00
|
|
|
|
void IMIA0(void) __attribute__ ((interrupt_handler));
|
2002-05-05 18:34:06 +00:00
|
|
|
|
void IMIA0(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Run through the list of tick tasks */
|
2002-06-04 12:47:39 +00:00
|
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
2002-05-05 18:34:06 +00:00
|
|
|
|
{
|
|
|
|
|
if(tick_funcs[i])
|
|
|
|
|
{
|
|
|
|
|
tick_funcs[i]();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_tick++;
|
2003-02-14 09:44:34 +00:00
|
|
|
|
wake_up_thread();
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
|
|
|
|
TSR0 &= ~0x01;
|
|
|
|
|
}
|
2005-07-18 12:40:29 +00:00
|
|
|
|
#elif defined(CPU_COLDFIRE)
|
2005-03-01 14:33:45 +00:00
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
2004-10-27 07:07:54 +00:00
|
|
|
|
{
|
2005-10-03 09:24:36 +00:00
|
|
|
|
unsigned long count;
|
|
|
|
|
int prescale;
|
2004-10-27 07:07:54 +00:00
|
|
|
|
|
2005-10-03 09:24:36 +00:00
|
|
|
|
count = CPU_FREQ/2 * interval_in_ms / 1000 / 16;
|
2004-10-27 07:07:54 +00:00
|
|
|
|
|
2005-10-03 09:24:36 +00:00
|
|
|
|
if(count > 0x10000)
|
2004-10-27 07:07:54 +00:00
|
|
|
|
{
|
|
|
|
|
panicf("Error! The tick interval is too long (%d ms)\n",
|
|
|
|
|
interval_in_ms);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-10-03 09:24:36 +00:00
|
|
|
|
|
|
|
|
|
prescale = cpu_frequency / CPU_FREQ;
|
|
|
|
|
/* Note: The prescaler is later adjusted on-the-fly on CPU frequency
|
|
|
|
|
changes within timer.c */
|
2004-10-27 07:07:54 +00:00
|
|
|
|
|
|
|
|
|
/* We are using timer 0 */
|
|
|
|
|
|
2005-10-03 09:24:36 +00:00
|
|
|
|
TRR0 = (unsigned short)(count - 1); /* The reference count */
|
2004-10-27 07:07:54 +00:00
|
|
|
|
TCN0 = 0; /* reset the timer */
|
2005-10-03 09:24:36 +00:00
|
|
|
|
TMR0 = 0x001d | ((unsigned short)(prescale - 1) << 8);
|
|
|
|
|
/* restart, CLK/16, enabled, prescaler */
|
2004-10-27 07:07:54 +00:00
|
|
|
|
|
|
|
|
|
TER0 = 0xff; /* Clear all events */
|
|
|
|
|
|
2005-11-05 03:28:20 +00:00
|
|
|
|
ICR1 = 0x8c; /* Interrupt on level 3.0 */
|
2004-10-27 07:07:54 +00:00
|
|
|
|
IMR &= ~0x200;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TIMER0(void) __attribute__ ((interrupt_handler));
|
|
|
|
|
void TIMER0(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Run through the list of tick tasks */
|
|
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
|
|
|
|
{
|
|
|
|
|
if(tick_funcs[i])
|
|
|
|
|
{
|
|
|
|
|
tick_funcs[i]();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_tick++;
|
|
|
|
|
wake_up_thread();
|
|
|
|
|
|
|
|
|
|
TER0 = 0xff; /* Clear all events */
|
|
|
|
|
}
|
2005-01-09 23:24:02 +00:00
|
|
|
|
|
|
|
|
|
#elif CONFIG_CPU == TCC730
|
|
|
|
|
|
|
|
|
|
void TIMER0(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2005-02-19 17:49:58 +00:00
|
|
|
|
|
|
|
|
|
/* Keep alive (?)
|
|
|
|
|
* If this is not done, power goes down when DC is unplugged.
|
|
|
|
|
*/
|
2005-02-13 17:06:35 +00:00
|
|
|
|
if (current_tick % 2 == 0)
|
|
|
|
|
P8 |= 1;
|
|
|
|
|
else
|
|
|
|
|
P8 &= ~1;
|
|
|
|
|
|
2005-01-09 23:24:02 +00:00
|
|
|
|
/* Run through the list of tick tasks */
|
|
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
|
|
|
|
{
|
|
|
|
|
if(tick_funcs[i])
|
|
|
|
|
{
|
|
|
|
|
tick_funcs[i]();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_tick++;
|
|
|
|
|
wake_up_thread();
|
|
|
|
|
|
|
|
|
|
/* re-enable timer by clearing the counter */
|
|
|
|
|
TACON |= 0x80;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-01 14:33:45 +00:00
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
2005-01-09 23:24:02 +00:00
|
|
|
|
{
|
2005-01-10 22:20:46 +00:00
|
|
|
|
long count;
|
2005-01-09 23:24:02 +00:00
|
|
|
|
count = (long)FREQ * (long)interval_in_ms / 1000 / 16;
|
|
|
|
|
|
|
|
|
|
if(count > 0xffffL)
|
|
|
|
|
{
|
2005-02-25 18:50:16 +00:00
|
|
|
|
panicf("Error! The tick interval is too long (%dms->%lx)\n",
|
2005-01-09 23:24:02 +00:00
|
|
|
|
interval_in_ms, count);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Use timer A */
|
|
|
|
|
TAPRE = 0x0;
|
2005-01-10 22:20:46 +00:00
|
|
|
|
TADATA = count;
|
2005-01-09 23:24:02 +00:00
|
|
|
|
|
|
|
|
|
TACON = 0x89;
|
|
|
|
|
/* counter clear; */
|
|
|
|
|
/* interval mode; */
|
|
|
|
|
/* TICS = F(osc) / 16 */
|
|
|
|
|
/* TCS = internal clock */
|
|
|
|
|
/* enable */
|
|
|
|
|
|
|
|
|
|
/* enable the interrupt */
|
2005-01-10 22:20:46 +00:00
|
|
|
|
interrupt_vector[2] = TIMER0;
|
2005-01-09 23:24:02 +00:00
|
|
|
|
IMR0 |= (1<<2);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-01 22:28:14 +00:00
|
|
|
|
#elif (CONFIG_CPU == PP5002) || (CONFIG_CPU == PP5020) || (CONFIG_CPU==PP5024)
|
2005-11-07 23:07:19 +00:00
|
|
|
|
|
2006-01-05 17:02:48 +00:00
|
|
|
|
#ifndef BOOTLOADER
|
2005-12-12 13:53:22 +00:00
|
|
|
|
void TIMER1(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2006-01-24 22:31:57 +00:00
|
|
|
|
TIMER1_VAL; /* Read value to ack IRQ */
|
2005-12-12 13:53:22 +00:00
|
|
|
|
/* Run through the list of tick tasks */
|
|
|
|
|
for (i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
|
|
|
|
{
|
|
|
|
|
if (tick_funcs[i])
|
|
|
|
|
{
|
|
|
|
|
tick_funcs[i]();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_tick++;
|
|
|
|
|
wake_up_thread();
|
|
|
|
|
}
|
2006-01-05 17:02:48 +00:00
|
|
|
|
#endif
|
2005-12-12 13:53:22 +00:00
|
|
|
|
|
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
|
|
|
|
{
|
2006-01-05 17:02:48 +00:00
|
|
|
|
#ifndef BOOTLOADER
|
2006-01-24 22:31:57 +00:00
|
|
|
|
TIMER1_CFG = 0x0;
|
|
|
|
|
TIMER1_VAL;
|
2006-01-24 22:16:27 +00:00
|
|
|
|
/* enable timer */
|
2006-01-24 22:31:57 +00:00
|
|
|
|
TIMER1_CFG = 0xc0000000 | (interval_in_ms*1000);
|
2005-12-12 13:53:22 +00:00
|
|
|
|
/* unmask interrupt source */
|
2006-01-24 22:31:57 +00:00
|
|
|
|
CPU_INT_EN = TIMER1_MASK;
|
2006-01-05 17:02:48 +00:00
|
|
|
|
#else
|
|
|
|
|
/* We don't enable interrupts in the bootloader */
|
|
|
|
|
(void)interval_in_ms;
|
|
|
|
|
#endif
|
2005-11-07 23:07:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-12 00:35:50 +00:00
|
|
|
|
#elif CONFIG_CPU == PNX0101
|
|
|
|
|
|
|
|
|
|
void timer_handler(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Run through the list of tick tasks */
|
|
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
|
|
|
|
{
|
|
|
|
|
if(tick_funcs[i])
|
|
|
|
|
tick_funcs[i]();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_tick++;
|
|
|
|
|
wake_up_thread();
|
|
|
|
|
|
|
|
|
|
TIMERR0C = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
|
|
|
|
{
|
|
|
|
|
TIMERR08 &= ~0x80;
|
|
|
|
|
TIMERR0C = 1;
|
|
|
|
|
TIMERR08 &= ~0x80;
|
|
|
|
|
TIMERR08 |= 0x40;
|
|
|
|
|
TIMERR00 = 3000000 * interval_in_ms / 1000;
|
|
|
|
|
TIMERR08 &= ~0xc;
|
|
|
|
|
TIMERR0C = 1;
|
|
|
|
|
|
|
|
|
|
irq_set_int_handler(4, timer_handler);
|
|
|
|
|
irq_enable_int(4);
|
|
|
|
|
|
|
|
|
|
TIMERR08 |= 0x80;
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-27 07:07:54 +00:00
|
|
|
|
#endif
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
|
|
|
|
int tick_add_task(void (*f)(void))
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2004-03-02 11:32:59 +00:00
|
|
|
|
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
|
|
|
|
/* Add a task if there is room */
|
2002-06-04 12:47:39 +00:00
|
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
2002-05-05 18:34:06 +00:00
|
|
|
|
{
|
|
|
|
|
if(tick_funcs[i] == NULL)
|
|
|
|
|
{
|
|
|
|
|
tick_funcs[i] = f;
|
|
|
|
|
set_irq_level(oldlevel);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set_irq_level(oldlevel);
|
2002-06-29 21:30:42 +00:00
|
|
|
|
panicf("Error! tick_add_task(): out of tasks");
|
2002-05-05 18:34:06 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int tick_remove_task(void (*f)(void))
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2004-03-02 11:32:59 +00:00
|
|
|
|
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
|
2002-05-05 18:34:06 +00:00
|
|
|
|
|
|
|
|
|
/* Remove a task if it is there */
|
2002-06-04 12:47:39 +00:00
|
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
2002-05-05 18:34:06 +00:00
|
|
|
|
{
|
|
|
|
|
if(tick_funcs[i] == f)
|
|
|
|
|
{
|
|
|
|
|
tick_funcs[i] = NULL;
|
|
|
|
|
set_irq_level(oldlevel);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_irq_level(oldlevel);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-05-16 20:57:32 +00:00
|
|
|
|
|
2005-02-22 12:19:12 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
/*
|
|
|
|
|
* Simulator versions in uisimulator/SIMVER/
|
|
|
|
|
*/
|
|
|
|
|
|
2002-05-16 20:57:32 +00:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Simple mutex functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
void mutex_init(struct mutex *m)
|
|
|
|
|
{
|
2002-06-04 12:47:39 +00:00
|
|
|
|
m->locked = false;
|
2002-05-16 20:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mutex_lock(struct mutex *m)
|
|
|
|
|
{
|
|
|
|
|
/* Wait until the lock is open... */
|
2002-06-04 12:47:39 +00:00
|
|
|
|
while(m->locked)
|
2003-02-14 09:44:34 +00:00
|
|
|
|
sleep_thread();
|
|
|
|
|
wake_up_thread();
|
2002-05-16 20:57:32 +00:00
|
|
|
|
|
|
|
|
|
/* ...and lock it */
|
2002-06-04 12:47:39 +00:00
|
|
|
|
m->locked = true;
|
2002-05-16 20:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mutex_unlock(struct mutex *m)
|
|
|
|
|
{
|
2002-06-04 12:47:39 +00:00
|
|
|
|
m->locked = false;
|
2002-05-16 20:57:32 +00:00
|
|
|
|
}
|
2005-02-22 12:19:12 +00:00
|
|
|
|
|
|
|
|
|
#endif
|