summaryrefslogtreecommitdiff
path: root/2004/n
diff options
context:
space:
mode:
authorschodet2004-05-08 12:10:57 +0000
committerschodet2004-05-08 12:10:57 +0000
commitdea79ec2d4c1166f0599379a62ff862a2e590fba (patch)
treef42459c988b0c1b2169393d803c22c899df4de58 /2004/n
parentec8d0c161152e7278e6b36fb70be762185ae0926 (diff)
Add: Routine de debug sur INT0.
Fix: Bug de stabilité du au port série.
Diffstat (limited to '2004/n')
-rw-r--r--2004/n/asserv/src/main.c22
-rw-r--r--2004/n/asserv/src/serial.c58
2 files changed, 61 insertions, 19 deletions
diff --git a/2004/n/asserv/src/main.c b/2004/n/asserv/src/main.c
index 2a1f54e..d3c90f4 100644
--- a/2004/n/asserv/src/main.c
+++ b/2004/n/asserv/src/main.c
@@ -76,7 +76,7 @@ Libre: a b c d e
#fuses H4,WDT,WDT128,PUT,NOBROWNOUT,NOLVP
#use delay(clock=40000000)
#use rs232(baud=115200,xmit=PIN_C6,parity=N,rcv=PIN_C7,bits=8)
-#priority RDA,TBE,TIMER2
+#priority EXT,RDA,TBE,TIMER2
#include "motor.c"
#include "serial.c"
@@ -121,6 +121,7 @@ irq_init (void)
enable_interrupts (INT_RDA);
disable_interrupts (INT_TBE);
enable_interrupts (GLOBAL);
+ enable_interrupts (INT_EXT);
}
void
@@ -134,3 +135,22 @@ main (void)
serial_send_rezet ();
motor_main ();
}
+
+#int_EXT
+debug_isr ()
+{
+ int tosl, tosh, tosu;
+#asm
+ movf 0xffd,w
+ movwf tosl
+ movf 0xffe,w
+ movwf tosh
+ movf 0xfff,w
+ movf tosu
+#endasm
+ putc ('!');
+ putc (tosl);
+ putc (tosh);
+ putc (tosu);
+ putc (CRLF);
+}
diff --git a/2004/n/asserv/src/serial.c b/2004/n/asserv/src/serial.c
index 784eb24..826539d 100644
--- a/2004/n/asserv/src/serial.c
+++ b/2004/n/asserv/src/serial.c
@@ -68,8 +68,8 @@ serial_init (void)
serial_recv ()
{
char c;
- if (serial_recv_full) return;
c = getc ();
+ if (serial_recv_full) return;
if (c == '\n' || c == '\r')
{
/* Fin de commande. */
@@ -108,25 +108,27 @@ serial_send ()
/* On ne fait pas le test, normalement ne doit pas arriver.
* assert (serial_send_buf_n < SERIAL_SEND_BUF_LEN); */
}
- else
+ else if (serial_unreliable_send_full)
{
- if (serial_unreliable_send_full)
+ /* Envoie le caractre non-fiable. */
+ c = serial_unreliable_send_buf[serial_unreliable_send_buf_n++];
+ /* Si fin de tampon, on le libre. */
+ if (c == EOB)
{
- /* Envoie le caractre non-fiable. */
- c = serial_unreliable_send_buf[serial_unreliable_send_buf_n++];
- /* Si fin de tampon, on le libre. */
- if (c == EOB)
- {
- serial_unreliable_send_buf_n = 0;
- serial_unreliable_send_full = 0;
- disable_interrupts (INT_TBE);
- }
- else
- putc (c);
- /* On ne fait pas le test, normalement ne doit pas arriver.
- * assert (serial_unreliable_send_buf_n <
- * SERIAL_UNRELIABLE_SEND_BUF_LEN); */
+ serial_unreliable_send_buf_n = 0;
+ serial_unreliable_send_full = 0;
+ disable_interrupts (INT_TBE);
}
+ else
+ putc (c);
+ /* On ne fait pas le test, normalement ne doit pas arriver.
+ * assert (serial_unreliable_send_buf_n <
+ * SERIAL_UNRELIABLE_SEND_BUF_LEN); */
+ }
+ else
+ {
+ /* Ne devrait pas arriver, mais soyons prudent. */
+ disable_interrupts (INT_TBE);
}
}
@@ -169,6 +171,23 @@ serial_send_rezet (void)
{
serial_send_char ('!');
serial_send_char ('z');
+ switch (restart_cause ())
+ {
+ case WDT_TIMEOUT:
+ serial_send_char ('w');
+ break;
+ case MCLR_FROM_SLEEP:
+ serial_send_char ('m');
+ break;
+ case BROWNOUT_RESTART:
+ serial_send_char ('b');
+ break;
+ case NORMAL_POWER_UP:
+ break;
+ default:
+ serial_send_char ('?');
+ break;
+ }
serial_send_char (CRLF);
}
@@ -194,7 +213,8 @@ serial_send_ok (void)
/* Envoie un rapport d'un moteur. */
void
-serial_send_motor_stat (char side, unsigned int vacc, unsigned long &e, unsigned long &pwm)
+serial_send_motor_stat (char side, unsigned int vacc, unsigned long &e,
+ unsigned long &pwm)
{
serial_unreliable_send_char ('!');
serial_unreliable_send_char ('M');
@@ -240,6 +260,7 @@ serial_send_char (char c)
/* Si fin de ligne, on envois. */
if (c == CRLF)
{
+ disable_interrupts (INT_TBE);
serial_send_full = 1;
serial_send_buf_n = 0;
enable_interrupts (INT_TBE);
@@ -258,6 +279,7 @@ serial_unreliable_send_char (char c)
/* Si fin de buffer, on envois. */
if (c == EOB)
{
+ disable_interrupts (INT_TBE);
serial_unreliable_send_full = 1;
serial_unreliable_send_buf_n = 0;
enable_interrupts (INT_TBE);