 Question: How do I use sleep() & time_delay()
while other interrupts are enabled ?
Answer: Make the following changes to
timer40.h
sleep.c
wakeup.c
time_delay.c:
In the file timer40.h replace the line:
void wakeup();
With the following lines:
/* Change to replace wakeup() with c_int46() ISR */
/* void wakeup(); */
#define wakeup c_int46
void c_int46(); /* Change to make wakeup() an ISR */
Here is the new sleep.c file:
/****************************************************************************/
/* sleep v4.60 */
/* Copyright (c) 1992 Texas Instruments Incorporated */
/****************************************************************************/
/* -6/20/94: changed the IVTP location from 0x02ffe00 to DEFAULT */
/****************************************************************************/
#include <timer40.h>
#include <intpt40.h>
void sleep(float x)
{
TIMER_REG *tim_ptr = TIMER_ADDR(1); /* TIMER 1 REGISTER POINTER */
int i;
int iie;
int gie;
/*----------------------------------------------------------------------*/
/* SETUP TIMER 0 INTERRUPT FOR WAKEN UP */
/*----------------------------------------------------------------------*/
iie = iie_value(); /* Save original iie value */
gie = st_value() & 0x2000; /* Save original GIE value in st */
set_ivtp(DEFAULT); /* SET IVTP TO DEFAULT value */
install_int_vector((void *)wakeup,43); /* SET TINT0 INTERRUPT VECTOR */
set_iie(TIMER1); /* ENABLE TINT1 BIT IN IIE */
/*----------------------------------------------------------------------*/
/* SETUP TIMER 0 FUNCTION AND DELAY THE CPU UNTIL END OF PERIOD */
/*----------------------------------------------------------------------*/
i = (int)(TIMER_CLOCK*x) - SLEEP_CALL_DELAY;
tim_ptr->period = (i > 0) ? i : 0; /* SET DELAY TIME */
tim_ptr->gcontrol = TIM_START;
for(;;)
{
INT_DISABLE(); /* Temporarily disable interrupts */
if (iie_value() & 0x80000000) /* Is TINT1 enabled ? */
{
INT_ENABLE(); /* Enable interrupts now to insure */
CPU_IDLE(); /* that the CPU_IDLE is executed */
} /* before an interrupt can be taken. */
else break; /* wakeup() (c_int46()) has executed */
} /* so break from for loop. */
load_iie(iie); /* Restore original iie value */
if (gie) INT_ENABLE(); /* Restore original GIE value */
else INT_DISABLE();
/*----------------------------------------------------------------------*/
/* RESET TIMER 0 INTERRUPT FUNCTION SETUP */
/*----------------------------------------------------------------------*/
deinstall_int_vector(43); /* SET TINT1 INTERRUPT VECTOR */
reset_ivtp(); /* RESET IVTP TO PREVIOUS VALUE */
}
Here is the new wakeup.c file:
/****************************************************************************/
/* wakeup v4.60 */
/* Copyright (c) 1992 Texas Instruments Incorporated */
/****************************************************************************/
#include <timer40.h>
#include <intpt40.h>
/* void wakeup() changed to make it an ISR, see #define in timer40.h */
void c_int46()
{
TIMER_HALT(1); /* STOP TIMER 1 FUNCITON */
reset_iie(TIMER1); /* Disable TINT1 interrupt in iie */
}
Here is the new time_delay.c file:
/****************************************************************************/
/* time_delay v4.60 */
/* Copyright (c) 1992 Texas Instruments Incorporated */
/****************************************************************************/
/* -6/20/94: changed the IVTP location from 0x02ffe00 to DEFAULT */
/****************************************************************************/
#include <timer40.h>
#include <intpt40.h>
void time_delay(unsigned long x)
{
TIMER_REG *tim_ptr = TIMER_ADDR(1); /* TIMER 0 REGISTER POINTER */
int i;
int iie;
int gie;
/*----------------------------------------------------------------------*/
/* SETUP TIMER 0 INTERRUPT FOR WAKEN UP */
/*----------------------------------------------------------------------*/
iie = iie_value(); /* Save original iie value */
gie = st_value() & 0x2000; /* Save original GIE value in st */
set_ivtp(DEFAULT); /* SET IVTP TO DEFAULT value */
install_int_vector((void *)wakeup,43); /* SET TINT0 INTERRUPT VECTOR */
set_iie(TIMER1); /* ENABLE TINT0 BIT IN IIE */
/*----------------------------------------------------------------------*/
/* SETUP TIMER 0 FUNCTION AND DELAY THE CPU UNTIL END OF PERIOD */
/*----------------------------------------------------------------------*/
i = x - TIME_CALL_DELAY;
if (i <0) i="0;" tim_ptr->period = i/2; /* SET DELAY TIME */
tim_ptr->gcontrol = TIM_START;
for(;;)
{
INT_DISABLE(); /* Temporarily disable interrupts */
if (iie_value() & 0x80000000) /* Is TINT1 enabled ? */
{
INT_ENABLE(); /* Enable interrupts now to insure */
CPU_IDLE(); /* that the CPU_IDLE is executed */
} /* before an interrupt can be taken. */
else break; /* wakeup() (c_int46()) has executed */
} /* so break from for loop. */
load_iie(iie); /* Restore original iie value */
if (gie) INT_ENABLE(); /* Restore original GIE value */
else INT_DISABLE();
/*----------------------------------------------------------------------*/
/* RESET TIMER 0 INTERRUPT FUNCTION SETUP */
/*----------------------------------------------------------------------*/
deinstall_int_vector(43); /* SET TINT1 INTERRUPT VECTOR */
reset_ivtp(); /* RESET IVTP TO PREVIOUS VALUE */
}
|