root/branch/belin/Emb_App/programme_principal_etud.c
1 | jalaffon | /***********************************************************************/
|
|
/* */
|
|||
/* FILE :test_compil.c */
|
|||
/* DATE :Fri, Sep 29, 2006 */
|
|||
/* DESCRIPTION :main program file. */
|
|||
/* CPU GROUP :87 */
|
|||
/* */
|
|||
/* This file is generated by Renesas Project Generator (Ver.4.5). */
|
|||
/* m308 */
|
|||
/* nc308lib */
|
|||
/* c308mr */
|
|||
/* nc382lib */
|
|||
/* */
|
|||
/***********************************************************************/
|
|||
#include "sfr32c87.h"
|
|||
#include <stdio.h>
|
|||
#include <stdlib.h>
|
|||
#include <itron.h>
|
|||
#include <kernel.h>
|
|||
#include "kernel_id.h"
|
|||
#include "lcd.h"
|
|||
#include "clavier.h"
|
|||
#include "periph.h"
|
|||
#include "uart0.h"
|
|||
#include "can.h"
|
|||
#include "carte_io.h"
|
|||
#include "carte_m32.h"
|
|||
#include <math.h>
|
|||
// Potentiometre: lire les registres ad00 et ad01, les valeurs sont sur 10 bits.
|
|||
// Clavier: vrcv_dtq(QdmTouche,&code_touche) pour lire la derniere touche appuyee sur le clavier.
|
|||
// la variable code_touche doit etre du type short.
|
|||
// Bouton poussoir: Bp_G, Bp_M, Bp_D permettent de lire l'etat des boutons de la carte I/O
|
|||
// Leds: LED_R=1 ou LED_R=0 Pour allumer ou eteindre les leds (LED_R, LED_J, LED_V).
|
|||
// Pour communiquer avec le simulateur utiliser une variable de type CanFrame,
|
|||
// Definir les differents champs en utilisant la structure (S)eparee (comm.data)
|
|||
// Envoyer le message complet en utilisant l'union (comm.msg)
|
|||
// Exemple:
|
|||
// CanFrame comm;
|
|||
// comm.data.id='T'; comm.data.rtr=0; comm.data.val=-100;
|
|||
// snd_dtq (CanTx,comm.msg);
|
|||
// Pour interroger un peripherique et recuperer les donnees brutes renvoyees simulateur:
|
|||
// CanFrame demande;
|
|||
// CanFrame reponse;
|
|||
//
|
|||
// demande.data.id='R'; demande.data.rtr=1;
|
|||
// snd_dtq (CanTx,demande.msg); // Interrogation du peripherique
|
|||
// rcv_dtq (CanRx,&reponse.msg); // Attente de la reponse
|
|||
// reponse.data.val contient la valeur de retour du simulateur.
|
|||
// ATTENTION: Ne pas utiliser rcv_dtq(CanRx... si la tache ID_periph_rx est active
|
|||
// Lors de l'utilisation de la tache de reception et distribution des messages ID_periph_rx
|
|||
// Demarrer cette tache : sta_tsk(ID_periph_rx);
|
|||
// Pour lire la valeur d'un peripherique:
|
|||
// Il faut envoyer une demande de lecture:
|
|||
// CanFrame comm;
|
|||
// comm.data.id='R'; comm.data.rtr=1;
|
|||
// snd_dtq (CanTx,comm.msg);
|
|||
//
|
|||
// Des l'arrivee de la reponse du simlateur, les variables suivantes sont mises a jour:
|
|||
// periph[ADDR('R')].val : contient la derniere valeur renvoyee par le simulateur.
|
|||
//
|
|||
// Pour verifier si une nouvelle valeur a ete recue utiliser:
|
|||
// periph[ADDR('R')].maj (incremente a chaque reception).
|
|||
// Pour qu'un evenement soit declenche lors de la reception d'une donnee pour un peripherique:
|
|||
// periph[ADDR('R')].ev=0x01;
|
|||
// Pour se mettre en attente de l'evenement: wai_flg (ev_periph,0x01,TWF_ORW,&flag); // Declarer la variable flag comme : FLGPTN flag
|
|||
// Attention l'evenement n'est pas efface apres reception, il faut donc utiliser clr_flg(ev_periph,~0x01); par example
|
|||
// Les evenements:
|
|||
// Si le simulateur envoi un evenement sur 16 bits il est recu grace a:
|
|||
// par exemple: wai_flg(event,(FLGPTN) 0x0007,TWF_ORW,&flag); // Declarer la variable flag comme : FLGPTN flag
|
|||
// Attention l'evenement n'est pas efface apres reception, il faut donc utiliser clr_flg(event,~flag); par example
|
|||
//Bit Information associee Remarque
|
|||
//0 Capteur Vert, remis a zero lors de la lecture du peripherique 'C'
|
|||
//1 Capteur Jaune, remis a zero lors de la lecture du peripherique 'C'
|
|||
//2 Capteur Rouge, remis a zero lors de la lecture du peripherique 'C'
|
|||
//3 Capteur Bleu, remis a zero lors de la lecture du peripherique 'C'
|
|||
//4 Capteur Cyan, remis a zero lors de la lecture du peripherique 'C'
|
|||
//5
|
|||
//6 Collision avec le sol, remise a zero au changement de piste.
|
|||
//7 Fin de course (capteur vert), remis a zero lors de la lecture du peripherique 'C'
|
|||
//8 La piste a change , remis a zero lors de la lecture du peripherique 'M'
|
|||
//9 Le mode de course a change , remis a zero lors de la lecture du peripherique 'M'
|
|||
//10
|
|||
//11 Le vehicule a termine un tour, remis a zero au changement du mode de course.
|
|||
//12 Sortie de la piste,
|
|||
//13 Teleportation a ete utilisee, remis a zero au changement de piste ou du mode de course.
|
|||
//14 Faux depart remise a zero au changement du mode de course.
|
|||
//15
|
|||
// Peripheriques disponibles:
|
|||
//'V'/86/0x56?: Commande en vitesse des roues motrices du vehicule (en radian /secondes).
|
|||
//'D'/68/0x44?: Commande de l'angle des roues directrices (en 1/10 de degre).
|
|||
//'T'/84/0x54?: Commande en vitesse de la tourelle portant le telemetre (en 1/10 de degre/secondes).
|
|||
//'R'/82/0x52?: Lecture de l'angle effectif de la tourelle portant le telemetre (en 1/10 de degre).
|
|||
//'U'/85/0x55?: Distance mesuree par le telemetre (1/100 de metre)
|
|||
//'N'/78/0x4E?: Numero de la voiture (en fonction de l'ordre de connexion)
|
|||
//'E'/69/0x45?: Lecture des evenements,
|
|||
//'H'/72/0x48?: Donne le temps de course actuel
|
|||
//'S'/83/0x53?: Temps du tour precedent
|
|||
//'M'/77/0x7D?: Mode de course :
|
|||
// Bit 15?: Etat feu tricolore ( 1 -> Vert, 0 -> Orange ou Rouge),
|
|||
// Bits 14-8?: 1 Attente, 2 course, 3 essais libres)
|
|||
// Bits 7-0?: numero de la piste
|
|||
//'C'/67/0x43?: Informations sur le dernier capteur touche :
|
|||
// 8 bits de poids faible?: numero du capteur
|
|||
5 | jalaffon | // 8 bits de poids fort?: couleur ('C','R','J','B' ou 'V')
|
|
//'J'/74/0x4A : Proposition d'un code de d?v?rouillage.
|
|||
//'j'/106/06A : R?cup?ration du r?sultat de dernier code envoy?. 0x77 si aucun code n'a ?t? soumis. <0 si la r?ponse n'est pas
|
|||
// disponible. 0xab avec a-> nombre de couleurs bien plac?es et b -> couleurs pr?sentes mais mal plac?es.
|
|||
//'I'/73/Ox49 : D?finition du nom du v?hicule. Doit d?buter par le caract?re '#' et entraine le chargement de la configuration de piste
|
|||
162 | anbelin1 | // correspondant au nom du v?hicule si le nom se termine par '*'
|
|
457 | anbelin1 | short pos_tourelle;
|
|
257 | anbelin1 | unsigned short capt=0;
|
|
unsigned short GEL=0;
|
|||
348 | anbelin1 | unsigned short NomPiste;
|
|
457 | anbelin1 | short consigneP;
|
|
short Distance;
|
|||
short consigneT;
|
|||
unsigned short K;
|
|||
162 | anbelin1 | ||
209 | anbelin1 | ||
162 | anbelin1 | void asservissementTourelle(){
|
|
209 | anbelin1 | ||
CanFrame req;
|
|||
CanFrame comm;
|
|||
353 | anbelin1 | unsigned short correction, retour;
|
|
162 | anbelin1 | ||
348 | anbelin1 | consigneT=450;
|
|
162 | anbelin1 | ||
209 | anbelin1 | while(1){
|
|
348 | anbelin1 | //Lecture de R
|
|
req.data.id = 'R';
|
|||
req.data.rtr = 1;
|
|||
snd_dtq(CanTx, req.msg);
|
|||
retour=periph[ADDR('R')].val;
|
|||
162 | anbelin1 | ||
348 | anbelin1 | //Asservissement
|
|
457 | anbelin1 | correction=5*(consigneT-retour);
|
|
348 | anbelin1 | comm.data.id='T';
|
|
comm.data.rtr = 0;
|
|||
comm.data.val = correction;
|
|||
162 | anbelin1 | ||
348 | anbelin1 | snd_dtq(CanTx,comm.msg);
|
|
dly_tsk(10);
|
|||
162 | anbelin1 | }
|
|
209 | anbelin1 | ||
162 | anbelin1 | }
|
|
209 | anbelin1 | void commMoteur(unsigned short vitessemoteur){
|
|
162 | anbelin1 | CanFrame commMoteur;
|
|
209 | anbelin1 | ||
162 | anbelin1 | commMoteur.data.id='V';
|
|
commMoteur.data.rtr = 0;
|
|||
209 | anbelin1 | commMoteur.data.val = vitessemoteur;
|
|
162 | anbelin1 | snd_dtq(CanTx,commMoteur.msg);
|
|
}
|
|||
257 | anbelin1 | void position(){
|
|
209 | anbelin1 | CanFrame req;
|
|
257 | anbelin1 | CanFrame comm;
|
|
457 | anbelin1 | short correction;
|
|
348 | anbelin1 | consigneP=700;
|
|
257 | anbelin1 | ||
209 | anbelin1 | while(1){
|
|
348 | anbelin1 | req.data.id = 'U';
|
|
req.data.rtr = 1;
|
|||
snd_dtq(CanTx, req.msg);
|
|||
Distance=periph[ADDR('U')].val;
|
|||
353 | anbelin1 | ||
348 | anbelin1 | if(Distance>1500 || GEL==1 || Distance<350){
|
|
257 | anbelin1 | comm.data.id='D';
|
|
comm.data.rtr = 0;
|
|||
comm.data.val = 0;
|
|||
}
|
|||
else{
|
|||
//Asservissement
|
|||
457 | anbelin1 | correction=K*(Distance-consigneP);
|
|
257 | anbelin1 | comm.data.id='D';
|
|
comm.data.rtr = 0;
|
|||
comm.data.val = correction;
|
|||
162 | anbelin1 | ||
257 | anbelin1 | snd_dtq(CanTx,comm.msg);
|
|
dly_tsk(10);
|
|||
}
|
|||
457 | anbelin1 | dly_tsk(3);
|
|
257 | anbelin1 | }
|
|
162 | anbelin1 | }
|
|
495 | anbelin1 | void BP(){
|
|
while(1){
|
|||
if(Bp_G==1) commMoteur(0);
|
|||
dly_tsk(15);
|
|||
}
|
|||
}
|
|||
void LJ(){
|
|||
if (Distance>2000){
|
|||
LED_J=1;
|
|||
dly_tsk(1000);
|
|||
LED_J=!LED_J;
|
|||
}
|
|||
}
|
|||
257 | anbelin1 | void capteur(){
|
|
CanFrame req;
|
|||
209 | anbelin1 | CanFrame comm;
|
|
257 | anbelin1 | while (1){
|
|
348 | anbelin1 | GEL=0;
|
|
257 | anbelin1 | req.data.id = 'C';
|
|
req.data.rtr = 1;
|
|||
snd_dtq(CanTx, req.msg);
|
|||
capt=periph[ADDR('C')].val;
|
|||
348 | anbelin1 | ||
//Circuit rouge
|
|||
495 | anbelin1 | if(capt==0x6a02)commMoteur(5);
|
|
if(capt==0x5604) commMoteur(25);
|
|||
348 | anbelin1 | ||
if(capt==0x7610 && GEL==0){
|
|||
257 | anbelin1 | GEL=1;
|
|
495 | anbelin1 | commMoteur(53);
|
|
K=2;
|
|||
257 | anbelin1 | }
|
|
495 | anbelin1 | dly_tsk(30);
|
|
}
|
|||
348 | anbelin1 | ||
495 | anbelin1 | /* //Circuit noir
|
|
457 | anbelin1 | if(capt==0x5601){
|
|
GEL=1;
|
|||
K=1;
|
|||
commMoteur(25);
|
|||
consigneT=450;
|
|||
consigneP=700;
|
|||
348 | anbelin1 | }
|
|
457 | anbelin1 | if(capt==0x7600) consigneP=900;
|
|
if(capt==0x4a01)consigneP=700;
|
|||
if(capt==0x5602){
|
|||
K=3;
|
|||
commMoteur(10);
|
|||
consigneT=700;
|
|||
dly_tsk(80);
|
|||
consigneP=525;
|
|||
353 | anbelin1 | ||
457 | anbelin1 | }
|
|
if(capt==0x5603) commMoteur(20);
|
|||
495 | anbelin1 | if(capt==0x6380) commMoteur(10);
|
|
457 | anbelin1 | if(capt==0x7680){
|
|
495 | anbelin1 | commMoteur(70);
|
|
457 | anbelin1 | GEL=1;
|
|
K=1;
|
|||
}
|
|||
495 | anbelin1 | if(capt==0x4203 || GEL==1){
|
|
457 | anbelin1 | commMoteur(10);
|
|
GEL=0;
|
|||
}
|
|||
if(capt==0x6208)commMoteur(0);
|
|||
495 | anbelin1 | dly_tsk(30);*/
|
|
209 | anbelin1 | }
|
|
495 | anbelin1 | }
|
|
162 | anbelin1 | ||
353 | anbelin1 | void nomPiste(){
|
|
495 | anbelin1 | CanFrame req;
|
|
353 | anbelin1 | while(1){
|
|
495 | anbelin1 | lcd_init();
|
|
348 | anbelin1 | req.data.id = 'M';
|
|
req.data.rtr = 1;
|
|||
snd_dtq(CanTx, req.msg);
|
|||
NomPiste=periph[ADDR('M')].val;
|
|||
353 | anbelin1 | NomPiste=NomPiste<<8;
|
|
switch(NomPiste){
|
|||
495 | anbelin1 | case 0x0400:
|
|
lcd_str("Piste Noire");
|
|||
break;
|
|||
case 0x0300 :
|
|||
lcd_str("Piste Rouge");
|
|||
break;
|
|||
case 0x0200 :
|
|||
lcd_str("Piste Bleue");
|
|||
break;
|
|||
case 0x0100 :
|
|||
lcd_str("Piste Verte");
|
|||
break;
|
|||
dly_tsk(30);
|
|||
353 | anbelin1 | }
|
|
495 | anbelin1 | ||
353 | anbelin1 | }
|
|
495 | anbelin1 | ||
348 | anbelin1 | }
|
|
495 | anbelin1 | ||
162 | anbelin1 | void main()
|
|
209 | anbelin1 | {
|
|
1 | jalaffon | ports_mcu();
|
|
periph_init();
|
|||
257 | anbelin1 | periph_nom("#BelinMob*");
|
|
209 | anbelin1 | can_init();
|
|
1 | jalaffon | clavier_init(1);
|
|
348 | anbelin1 | capture_init();
|
|
495 | anbelin1 | ||
sta_tsk(ID_nomPiste);
|
|||
209 | anbelin1 | sta_tsk(ID_periph_rx);
|
|
sta_tsk(ID_tourelle);
|
|||
sta_tsk(ID_position);
|
|||
257 | anbelin1 | sta_tsk(ID_capteur);
|
|
495 | anbelin1 | sta_tsk(ID_BP);
|
|
348 | anbelin1 | dly_tsk(500);
|
|
353 | anbelin1 | commMoteur(25);
|
|
495 | anbelin1 | K=1;
|
|
1 | jalaffon | while(1)
|
|
495 | anbelin1 | {
|
|
LED_V=1;
|
|||
dly_tsk(1000);
|
|||
LED_V=!LED_V;
|
|||
dly_tsk(30);
|
|||
162 | anbelin1 | }
|
|
}
|
|||
1 | jalaffon | ||
void acqui()
|
|||
{
|
|||
LED_V=!LED_V;
|
|||
162 | anbelin1 | }
|
|