target/avr/asuro_avr.c File Reference

AVR dependent part of interface to ASURO's devices. More...

#include "asuro.h"
#include "asuro_irrc5.h"

Go to the source code of this file.

Interrupt handlers

 SIGNAL (SIG_OVERFLOW2)
 ISR for timer2 overflow.
 SIGNAL (SIG_INTERRUPT1)
 ISR for switches.

Functions

void AS_Avr_Sleep (unsigned char ticks)
 Halt execution for a given time of 36kHz ticks.
void AS_Init ()
 Do some initialization stuff.
unsigned long AS_GetClockTicks ()
 Return the number of system clock ticks elapsed since system start.
unsigned long AS_GetSysTime ()
 Return the time in milliseconds elapsed since system start.
void AS_Sleep (unsigned int time)
 Halt execution for a given time in milliseconds.
void AS_StatusLED (unsigned char color)
 Set status LED to the specified color.
void AS_FrontLED (unsigned char status)
 Set front LED on or off.
void AS_BackLED (unsigned char left, unsigned char right)
 Set back LEDs on or off.
void AS_MotorSpeed (unsigned char left_speed, unsigned char right_speed)
 Set speed of left and right motor.
void AS_MotorDir (unsigned char left_dir, unsigned char right_dir)
 Set rotation direction of left and right motor.
void AS_SerWrite (unsigned char *data, unsigned char length)
 Send data via IR serial interface.
void AS_SensSwitchesInterruptOn (void)
 Turn on interrupt for activity on switches.
void AS_SensSwitchesInterruptOff (void)
 Disable interrupt for activity on switches.
unsigned char AS_SensSwitchesRead (void)
 Read status of switches.

Variables

volatile AS_UserIsr AS_UserIsrInterrupt1 = 0
 User defined ISR for INT1 (switches).
volatile unsigned char AS_count36kHz = 0
 Intermediate counter for system clock ticks.
volatile unsigned long AS_clockTicks = 0
 Counter for system clock ticks.
volatile unsigned char AS_irrc5DecodeEnabled = 1
 Enable/disable IR-RC5 decoding in ISR.
volatile char AS_sensSwitchesOn = 0
 Set to true if the interrupt for switches is enabled.
volatile char AS_sensSwitched = 0
 Set to true, when one or more of the switches are pressed.


Detailed Description

AVR dependent part of interface to ASURO's devices.

Author:
Denis Martin
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

Definition in file asuro_avr.c.


Function Documentation

void AS_Avr_Sleep unsigned char  ticks  )  [inline]
 

Halt execution for a given time of 36kHz ticks.

Parameters:
ticks Time to sleep in 36kHz ticks (0..255)

Definition at line 102 of file asuro_avr.c.

References AS_count36kHz.

Referenced by AS_SensSwitchesRead().

void AS_BackLED unsigned char  left,
unsigned char  right
[inline]
 

Set back LEDs on or off.

Note that you can also call AS_LED_RBACK_ON, AS_LED_RBACK_OFF, AS_LED_LBACK_ON and AS_LED_LBACK_OFF directly, but you have to switch to AS_BACK_LED_MODE before.

left Status for left back LED (AS_ON or AS_OFF) right Status for right back LED (AS_ON or AS_OFF)

Definition at line 222 of file asuro_avr.c.

References AS_BACK_LED_MODE, AS_LED_LBACK_OFF, AS_LED_LBACK_ON, AS_LED_ODO_OFF, AS_LED_RBACK_OFF, and AS_LED_RBACK_ON.

void AS_FrontLED unsigned char  status  )  [inline]
 

Set front LED on or off.

Note that you can also call AS_LED_FRONT_ON and AS_LED_FRONT_OFF directly.

Parameters:
status AS_ON or AS_OFF

Definition at line 209 of file asuro_avr.c.

References AS_LED_FRONT_OFF, and AS_LED_FRONT_ON.

unsigned long AS_GetClockTicks void   )  [inline]
 

Return the number of system clock ticks elapsed since system start.

Remember that it might overflow.

Returns:
Number of system clock ticks

Definition at line 158 of file asuro_avr.c.

References AS_clockTicks, and AS_count36kHz.

unsigned long AS_GetSysTime void   )  [inline]
 

Return the time in milliseconds elapsed since system start.

Remember that it might overflow.

Returns:
System time in milliseconds

Definition at line 169 of file asuro_avr.c.

References AS_clockTicks, and AS_count36kHz.

void AS_MotorDir unsigned char  left_dir,
unsigned char  right_dir
[inline]
 

Set rotation direction of left and right motor.

Possible values are AS_DIR_FWD (forward), AS_DIR_RWD (backward), AS_DIR_BREAK (stop) and AS_DIR_FREE (no change to direction).

Parameters:
left_dir Direction for left motor.
right_dir Direction for right motor.

Definition at line 255 of file asuro_avr.c.

References AS_DIR_LEFT, and AS_DIR_RIGHT.

Referenced by AS_Init().

void AS_MotorSpeed unsigned char  left_speed,
unsigned char  right_speed
[inline]
 

Set speed of left and right motor.

Use AS_MotorDir() before to specifiy the direction.

Parameters:
left_speed Speed of left motor (0..255)
right_speed Speed of right motor (0..255)

Definition at line 241 of file asuro_avr.c.

References OCR1A, and OCR1B.

Referenced by AS_Init().

void AS_SensSwitchesInterruptOn void   ) 
 

Turn on interrupt for activity on switches.

The user ISR assigned to AS_UserIsrInterrupt1 will be called if any of the switches was pushed.

Definition at line 292 of file asuro_avr.c.

References AS_PD_SWITCHES, AS_SENS_SWITCHES_OFF, AS_sensSwitched, DDRD, GICR, INT1, ISC10, ISC11, and MCUCR.

unsigned char AS_SensSwitchesRead void   ) 
 

Read status of switches.

The bits of the returned value represent the switches currently pressed. The mapping is the following:

bit0 = K6, bit1 = K5, bit2 = K4, bit3 = K3, bit4 = K2, bit5 = K1

Returns:
A value whose bits represent the switches currently pressed (see above)

Definition at line 323 of file asuro_avr.c.

References ADMUX, AS_ADC_FINISHED, AS_ADC_START, AS_ADC_STOP, AS_ADC_VALUE, AS_Avr_Sleep(), AS_MUX_SWITCHES, AS_SENS_SWITCHES_MODE, AS_SENS_SWITCHES_OFF, AS_SENS_SWITCHES_ON, and REFS0.

void AS_SerWrite unsigned char *  data,
unsigned char  length
 

Send data via IR serial interface.

IR-RC5 decoding will be disabled during write.

Parameters:
data Pointer to data buffer to send.
length Size of data in bytes.

Definition at line 268 of file asuro_avr.c.

References AS_irrc5DecodeEnabled, UCSRA, UCSRB, and UDR.

void AS_Sleep unsigned int  time  ) 
 

Halt execution for a given time in milliseconds.

Note: a value of zero will not return immediately as you might expect. Instead, the execution is halted for over a minute!

Parameters:
time Time to sleep in milliseconds

Definition at line 181 of file asuro_avr.c.

References AS_count36kHz.

void AS_StatusLED unsigned char  color  )  [inline]
 

Set status LED to the specified color.

Note that you can also call AS_LED_GREEN_ON, AS_LED_GREEN_OFF, AS_LED_RED_ON, AS_LED_RED_OFF, AS_LED_YELLOW_ON and AS_LED_YELLOW_OFF directly.

color Color (possible values: AS_GREEN, AS_RED, AS_YELLOW)

Definition at line 197 of file asuro_avr.c.

References AS_GREEN, AS_LED_GREEN_OFF, AS_LED_GREEN_ON, AS_LED_RED_OFF, AS_LED_RED_ON, and AS_RED.

SIGNAL SIG_INTERRUPT1   ) 
 

ISR for switches.

The interrupt is disabled here, so you have to reactivate it manually using AS_SensSwitchesInterruptOn().

Definition at line 83 of file asuro_avr.c.

References AS_sensSwitched, AS_SensSwitchesInterruptOff(), and AS_UserIsrInterrupt1.

SIGNAL SIG_OVERFLOW2   ) 
 

ISR for timer2 overflow.

timer2 is used as a 72kHz counter for IR communication. While the signal SIG_OUTPUT_COMPARE2 would be triggered every 1/72k seconds, this ISR is called only every 1/36k seconds.

Definition at line 65 of file asuro_avr.c.

References AS_clockTicks, AS_count36kHz, AS_irrc5DecodeEnabled, AS_isr_irrc5(), and TCNT2.


Variable Documentation

volatile unsigned long AS_clockTicks = 0
 

Counter for system clock ticks.

Don't read it directly, but use AS_GetClockTicks() or AS_GetSysTime() instead.

Definition at line 37 of file asuro_avr.c.

Referenced by AS_GetClockTicks(), AS_GetSysTime(), and SIGNAL().

volatile unsigned char AS_count36kHz = 0
 

Intermediate counter for system clock ticks.

Don't read it directly, but use AS_GetClockTicks() or AS_GetSysTime() instead.

Definition at line 31 of file asuro_avr.c.

Referenced by AS_Avr_Sleep(), AS_GetClockTicks(), AS_GetSysTime(), AS_Sleep(), and SIGNAL().

volatile unsigned char AS_irrc5DecodeEnabled = 1
 

Enable/disable IR-RC5 decoding in ISR.

Will be disabled during read/write on IR serial interface.

Definition at line 43 of file asuro_avr.c.

Referenced by AS_SerWrite(), and SIGNAL().

volatile char AS_sensSwitched = 0
 

Set to true, when one or more of the switches are pressed.

Note that you have to turn on the concerned interrupt using AS_SensSwitchesInterruptOn().

Definition at line 55 of file asuro_avr.c.

Referenced by AS_SensSwitchesInterruptOn(), and SIGNAL().

volatile char AS_sensSwitchesOn = 0
 

Set to true if the interrupt for switches is enabled.

If it is not enabled, you may activate it by using AS_SensSwitchesInterruptOn().

Definition at line 49 of file asuro_avr.c.

volatile AS_UserIsr AS_UserIsrInterrupt1 = 0
 

User defined ISR for INT1 (switches).

Assign a function to this global variable to get your own ISR called.

Definition at line 25 of file asuro_avr.c.

Referenced by SIGNAL().


Generated on Fri May 12 10:11:15 2006 for simsuro by  doxygen 1.4.6