00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00040 #include <aversive.h>
00041
00042
00043 #include "encoders_eirbot.h"
00044
00045 #include "encoders_eirbot_config.h"
00046
00047 #ifdef ENCODERS_MODE_XILINX
00048
00049 #define ENCODERS_SELEC_MASK ((0xFF >> (8-ENCODERS_SELEC_NITS_NUM)) \
00050 << ENCODERS_SELEC_BIT0)
00051 #define ENCODERS_DATA_MASK ((0xFF >> (8-ENCODERS_DATA_NBBITS)) \
00052 << ENCODERS_DATA_BIT0)
00053
00054 #define DIFF_DATA_MASK ((0xFF >> ENCODERS_DATA_NBBITS) << ENCODERS_DATA_NBBITS)
00055
00056 volatile encoders g_codeur_valeurs[ENCODERS_NUMBER];
00057
00058 volatile int8_t g_codeur_preced[ENCODERS_NUMBER];
00059
00060
00061
00065 inline int8_t get_codeur(uint8_t num)
00066 {
00067 int8_t val;
00068 uint8_t flags;
00069
00070 IRQ_LOCK(flags);
00071
00072 ENCODERS_SELEC_PORT = ( ENCODERS_SELEC_PORT & (~ENCODERS_SELEC_MASK) ) | ( num << ENCODERS_SELEC_BIT0);
00073
00074 nop();
00075 nop();
00076
00077 val = (ENCODERS_PIN & ENCODERS_DATA_MASK) >> ENCODERS_DATA_BIT0;
00078
00079 IRQ_UNLOCK(flags);
00080
00081 return val;
00082 }
00083
00085 void encoders_init(void)
00086 {
00087 uint8_t number;
00088 uint8_t flags;
00089
00090 IRQ_LOCK(flags);
00091
00092 ENCODERS_SELEC_DDR |= ENCODERS_SELEC_MASK;
00093 ENCODERS_DATA_DDR &= (~ENCODERS_DATA_MASK);
00094
00095 for(number = 0 ; number < ENCODERS_NUMBER; number ++)
00096 {
00097 g_codeur_valeurs[number] = 0;
00098 g_codeur_preced[number] = get_codeur(number);
00099 }
00100
00101 IRQ_UNLOCK(flags);
00102 }
00103
00105 void encoders_manage(void)
00106 {
00107 uint8_t number;
00108 int8_t res, lu;
00109 uint8_t nombre_a_ajouter;
00110 uint8_t flags;
00111
00112 for(number = 0 ; number < ENCODERS_NUMBER; number ++)
00113 {
00114
00115 lu = get_codeur(number);
00116 res = lu - g_codeur_preced[number];
00117 g_codeur_preced[number] = lu;
00118
00119
00120 nombre_a_ajouter = ((res >> (ENCODERS_DATA_NBBITS - 1))&1) ? DIFF_DATA_MASK : 0;
00121 res = (res & ~DIFF_DATA_MASK) + nombre_a_ajouter;
00122
00123 IRQ_LOCK(flags);
00124 g_codeur_valeurs[number] += res;
00125 IRQ_UNLOCK(flags);
00126 }
00127 }
00128
00130 encoders encoders_get_value(uint8_t number)
00131 {
00132 encoders value;
00133 uint8_t flags;
00134
00135 IRQ_LOCK(flags);
00136 value = g_codeur_valeurs[number];
00137 IRQ_UNLOCK(flags);
00138
00139 return value;
00140 }
00141
00142 #else
00143 #error the irq version of the codeur module is not implemented yet
00144 #endif