Main Page   Class Hierarchy   Compound List   File List   Header Files   Compound Members   File Members  

legOS/kernel/dsensor.c File Reference

direct sensor access. More...


Defines

#define DS_ALL_ACTIVE
all sensors active mode.

#define DS_ALL_PASSIVE
all sensors passive mode.


Functions

void ds_rotation_set (volatile unsigned *sensor,int pos)
set rotation to an absolute value. More...

void ds_rotation_handler ()
process rotation sensor on current A/D channel. More...

void ds_handler (void)
sensor A/D conversion IRQ handler.

 __asm__ (" .text .align 1 _ds_handler: ; r6 saved by ROM mov.b @_ds_channel,r6l ; r6l = current channel mov.b @_ds_activation,r6h ; r6h = activation bitmask btst r6l,r6h ; activate output? beq ds_noset bset r6l,@_PORT6:8 ; activate output of last port scanned ds_noset: " " mov.b @_ds_rotation,r6h ; r6h = rotation bitmask btst r6l,r6h ; process rotation sensor? beq ds_norot push r0 ; save r0..r3 push r1 push r2 push r3 ; r4..r6 saved by gcc if necessary jsr _ds_rotation_handler ; process rotation sensor pop r3 pop r2 pop r1 pop r0 ds_norot: " " inc r6l ; next channel and #0x03,r6l ; limit to 0-3 bclr r6l,@_PORT6:8 ; set output inactive for reading ; The settle time for reading the value from active sensor start here ; moved here for helping timing problems mov.b r6l,@_ds_channel ; store next channel ; Added a delay loop for sensor settle time mov.b #0x04, r6h ; delay loop settle: nop ; each nop is a 2 state clock delay dec.b r6h ; 2 states ? bne settle ; 4 states ; Total loop delay 32 states (?) mov.b @_AD_CSR:8,r6h ; r6h = A/D CSR and.b #0x7c,r6h ; reset scanmode and channel num or.b r6l,r6h ; scan next channel mov.b r6h,@_AD_CSR:8 ; put r6h back on A/D CSR ; The settle time for reading the value from active sensor finish here bset #0x5,@_AD_CSR:8 ; go! rts ")
void ds_init (void)
initialize sensor a/d conversion. More...

void ds_shutdown (void)
shutdown sensor a/d conversion. More...


Variables

volatile unsigned char ds_channel
current A/D channel.

unsigned char ds_activation
channel bitmask. 1-> active.

unsigned char ds_rotation
channel bitmask. 1-> rotation.

volatile int ds_rotations [3]
sensor revolutions * 16.

signed char rotation_state [3]
rotation state.

signed char rotation_new_state [3]
proposed rotation state.

unsigned int state_duration [3]
proposed rotation state duration.

const signed char ad2state [16]
convert a/d values to rotation states. More...

const signed char diff2change [7]
convert state difference to revolution count change. More...


Detailed Description

direct sensor access.

Author(s):
Markus L. Noga <markus@noga.de>

Define Documentation

#define DS_ALL_ACTIVE ()

all sensors active mode.

#define DS_ALL_PASSIVE ()

all sensors passive mode.


Function Documentation

void ds_rotation_set (volatile unsigned * sensor, int pos)

set rotation to an absolute value.

Parameters:
sensor   the sensor address, can be &SENSOR_1, &SENSOR_2 or &SENSOR_3
pos   desired absolute position

axis should be inert during the function call

void ds_rotation_handler ()

process rotation sensor on current A/D channel.

See also:
ds_channel current channel (global input value)

void ds_handler (void)

sensor A/D conversion IRQ handler.

__asm__ (".text.align 1_ds_handler:;r6 saved by ROM mov.b@ _ds_channel, r6l; r6l = current channel mov.b @_ds_activation, r6h; r6h = activation bitmask btst r6l, r6h;activate output? beq ds_noset bset r6l, @_PORT6:8;activate output of last port scanned ds_noset:""mov.b@ _ds_rotation, r6h; r6h = rotation bitmask btst r6l, r6h;process rotation sensor?beq ds_norot push r0;save r0..r3 push r1 push r2 push r3;r4..r6 saved by gcc if necessary jsr _ds_rotation_handler;process rotation sensor pop r3 pop r2 pop r1 pop r0 ds_norot:""inc r6l;next channel and# 0x03, r6l;limit to 0- 3 bclr r6l, @_PORT6:8;set output inactive for reading;The settle time for reading the value from active sensor start here;moved here for helping timing problems mov. b r6l, @_ds_channel;store next channel;Added a delay loop for sensor settle time mov.b# 0x04, r6h;delay loopsettle:nop;each nop is a 2 state clock delay dec.b r6h;2 states?bne settle;4 states;Total loop delay 32 states(?)mov.b@_AD_CSR:8, r6h; r6h = A/D CSR and.b #0x7c, r6h;reset scanmode and channel num or. b r6l, r6h;scan next channel mov. b r6h, @_AD_CSR:8;put r6h back on A/D CSR;The settle time for reading the value from active sensor finish here bset# 0x5, @_AD_CSR:8;go!rts")

void ds_init (void)

initialize sensor a/d conversion.

all sensors set to passive mode rotation tracking disabled

void ds_shutdown (void)

shutdown sensor a/d conversion.

all sensors set to passive mode


Variable Documentation

volatile unsigned char ds_channel

current A/D channel.

unsigned char ds_activation

channel bitmask. 1-> active.

unsigned char ds_rotation

channel bitmask. 1-> rotation.

volatile int ds_rotations[3]

sensor revolutions * 16.

signed char rotation_state[3] [static]

rotation state.

signed char rotation_new_state[3] [static]

proposed rotation state.

unsigned int state_duration[3] [static]

proposed rotation state duration.

const signed char ad2state[16] [static]

convert a/d values to rotation states.

Indexed with (value>>12). Invalid values yield negative states.

const signed char diff2change[7] [static]

convert state difference to revolution count change.

Indexed with (newstate-state)+3. Invalid differences yield zero change. Differences of magnitude two could have been acheived in either rotational sense, so their expected value is zero.

legOS-0.2.4 is released under the Mozilla Public License. Original code copyright 1998-1999 by the authors.