root/branch/daval/bsp/radiocommande.c @ 381
2 | jalaffon | /***********************************************************************/
|
|
/* */
|
|||
/* FILE :radiocommande.c */
|
|||
/* DATE :Mon, Feb 13, 2006 */
|
|||
/* DESCRIPTION : measure 6 channels on the receiver */
|
|||
/* CPU GROUP :62P */
|
|||
/* */
|
|||
/* This file is generated by Renesas Project Generator (Ver.4.5). */
|
|||
/* */
|
|||
/***********************************************************************/
|
|||
#ifdef M32C87
|
|||
#include "sfr32c87.h"
|
|||
#endif
|
|||
#ifdef M32C83
|
|||
#include "sfr32c83.h"
|
|||
#endif
|
|||
#include <itron.h>
|
|||
#include <kernel.h>
|
|||
#include "kernel_id.h"
|
|||
//function's prototypes declaration
|
|||
int canal[7];
|
|||
int canal_ok;
|
|||
void capture_init(void)
|
|||
{
|
|||
prc2 = 1; //unprotect writing in pd9 register
|
|||
pd9_0 = 0;
|
|||
prc2=0;
|
|||
ps3_3=0;
|
|||
psl3_3=0;
|
|||
tb0mr = 0x4A; //timer B0 in duration measurement mode with f8
|
|||
tb0ic = 0x07; //enable timer B0 interrupt at level x
|
|||
tb0s = 1; //start timer B0
|
|||
canal_ok=0;
|
|||
}
|
|||
void mesure(void)
|
|||
{
|
|||
static char k=-1;
|
|||
static int flag=0;
|
|||
unsigned int tpulse;
|
|||
int val;
|
|||
tpulse=tb0>>1; // Pulse time
|
|||
if (tpulse<400) { // Too short pulse
|
|||
k=-1;
|
|||
canal_ok=0;
|
|||
return;
|
|||
}
|
|||
if (tpulse>10000) // Synchro pulse
|
|||
{
|
|||
k=0; // Return to canal 0
|
|||
return;
|
|||
}
|
|||
if (k==(char) -1) // Not synchronised
|
|||
return; // Nothing to do
|
|||
if (!(k & 0x01)) // 500us High pulse
|
|||
if (tpulse>600) {
|
|||
k=-1; // Invalidate mesure and wait a new synchro
|
|||
canal_ok=0;
|
|||
return;
|
|||
}
|
|||
if (k & 0x01) // Pulse timing
|
|||
canal[k>>1]=tpulse-1360; // 1360 neutral zone
|
|||
k++;
|
|||
if (k>11) {// Last canal
|
|||
k=-1;
|
|||
canal_ok=1;
|
|||
}
|
|||
}
|