From 2da3f1d5b33f6fbc5c14faeff71bb275eb16fed6 Mon Sep 17 00:00:00 2001 From: schodet Date: Fri, 21 Jan 2005 01:20:48 +0000 Subject: Correction de la grosse merde que j'avais mise sur le CVS et optimisations. --- n/avr/proto/proto.c | 12 ++-- n/avr/proto/proto.h | 4 ++ n/avr/proto/proto_inline.c | 165 ++++++++++++++++++++++++++++++--------------- 3 files changed, 117 insertions(+), 64 deletions(-) (limited to 'n') diff --git a/n/avr/proto/proto.c b/n/avr/proto/proto.c index b23c6b4..2a62381 100644 --- a/n/avr/proto/proto.c +++ b/n/avr/proto/proto.c @@ -32,12 +32,8 @@ static void proto_accept_digit (uint8_t c); /* Send a hex digit. */ -static void -proto_hex (uint8_t h); - -/* Send a byte. */ inline static void -proto_arg (uint8_t a); +proto_hex (uint8_t h); /* -AutoDec */ @@ -131,14 +127,14 @@ proto_accept_digit (uint8_t c) } /* Send a hex digit. */ -static void +inline static void proto_hex (uint8_t h) { proto_putc (h >= 10 ? h - 10 + 'a' : h + '0'); } -/* Send a byte. */ -inline static void +/* Send a argument byte. */ +void proto_arg (uint8_t a) { proto_hex ((a >> 4) & 0xf); diff --git a/n/avr/proto/proto.h b/n/avr/proto/proto.h index 5d6319f..c52bb35 100644 --- a/n/avr/proto/proto.h +++ b/n/avr/proto/proto.h @@ -42,6 +42,10 @@ proto_putc (uint8_t c); void proto_accept (uint8_t c); +/* Send a argument byte. */ +void +proto_arg (uint8_t a); + /** Send a command, generic function. */ void proto_send (uint8_t cmd, uint8_t size, uint8_t *args); diff --git a/n/avr/proto/proto_inline.c b/n/avr/proto/proto_inline.c index 2919c50..bbeee20 100644 --- a/n/avr/proto/proto_inline.c +++ b/n/avr/proto/proto_inline.c @@ -27,133 +27,186 @@ extern inline void proto_send0 (uint8_t cmd) { - proto_send (cmd, 0, 0); + proto_putc ('!'); + proto_putc (cmd); + proto_putc ('\r'); } /* Send a command with 1 byte argument. */ extern inline void proto_send1b (uint8_t cmd, uint8_t arg0) { - uint8_t args[1]; - args[0] = arg0; - proto_send (cmd, 1, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg (arg0); + proto_putc ('\r'); } /* Send a command with 1 word argument. */ extern inline void proto_send1w (uint8_t cmd, uint16_t arg0) { - uint8_t args[1 * 2]; - args[0] = (arg0 >> 0) & 0xff; - args[0] = (arg0 >> 8) & 0xff; - proto_send (cmd, 1 * 2, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 1 double word argument. */ extern inline void proto_send1d (uint8_t cmd, uint32_t arg0) { - uint8_t args[1 * 4]; - args[0] = arg0; - proto_send (cmd, 1 * 4, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 24) & 0xff); + proto_arg ((arg0 >> 16) & 0xff); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 2 bytes arguments. */ extern inline void proto_send2b (uint8_t cmd, uint8_t arg0, uint8_t arg1) { - uint8_t args[2]; - args[0] = arg0; - args[1] = arg1; - proto_send (cmd, 2, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg (arg0); + proto_arg (arg1); + proto_putc ('\r'); } /* Send a command with 2 words arguments. */ extern inline void proto_send2w (uint8_t cmd, uint16_t arg0, uint16_t arg1) { - uint8_t args[2 * 2]; - args[0] = arg0; - args[1] = arg1; - proto_send (cmd, 2 * 2, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_arg ((arg1 >> 8) & 0xff); + proto_arg ((arg1 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 2 double words arguments. */ extern inline void proto_send2d (uint8_t cmd, uint32_t arg0, uint32_t arg1) { - uint8_t args[2 * 4]; - args[0] = arg0; - args[1] = arg1; - proto_send (cmd, 2 * 4, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 24) & 0xff); + proto_arg ((arg0 >> 16) & 0xff); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_arg ((arg1 >> 24) & 0xff); + proto_arg ((arg1 >> 16) & 0xff); + proto_arg ((arg1 >> 8) & 0xff); + proto_arg ((arg1 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 3 bytes arguments. */ extern inline void proto_send3b (uint8_t cmd, uint8_t arg0, uint8_t arg1, uint8_t arg2) { - uint8_t args[3]; - args[0] = arg0; - args[1] = arg1; - args[2] = arg2; - proto_send (cmd, 3, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg (arg0); + proto_arg (arg1); + proto_arg (arg2); + proto_putc ('\r'); } /* Send a command with 3 words arguments. */ extern inline void proto_send3w (uint8_t cmd, uint16_t arg0, uint16_t arg1, uint16_t arg2) { - uint8_t args[3 * 2]; - args[0] = arg0; - args[1] = arg1; - args[2] = arg2; - proto_send (cmd, 3 * 2, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_arg ((arg1 >> 8) & 0xff); + proto_arg ((arg1 >> 0) & 0xff); + proto_arg ((arg2 >> 8) & 0xff); + proto_arg ((arg2 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 3 double words arguments. */ extern inline void proto_send3d (uint8_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2) { - uint8_t args[3 * 4]; - args[0] = arg0; - args[1] = arg1; - args[2] = arg2; - proto_send (cmd, 3 * 4, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 24) & 0xff); + proto_arg ((arg0 >> 16) & 0xff); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_arg ((arg1 >> 24) & 0xff); + proto_arg ((arg1 >> 16) & 0xff); + proto_arg ((arg1 >> 8) & 0xff); + proto_arg ((arg1 >> 0) & 0xff); + proto_arg ((arg2 >> 24) & 0xff); + proto_arg ((arg2 >> 16) & 0xff); + proto_arg ((arg2 >> 8) & 0xff); + proto_arg ((arg2 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 4 bytes arguments. */ extern inline void proto_send4b (uint8_t cmd, uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t arg3) { - uint8_t args[4]; - args[0] = arg0; - args[1] = arg1; - args[2] = arg2; - args[3] = arg3; - proto_send (cmd, 4, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg (arg0); + proto_arg (arg1); + proto_arg (arg2); + proto_arg (arg3); + proto_putc ('\r'); } /* Send a command with 4 words arguments. */ extern inline void proto_send4w (uint8_t cmd, uint16_t arg0, uint16_t arg1, uint16_t arg2, uint16_t arg3) { - uint8_t args[4 * 2]; - args[0] = arg0; - args[1] = arg1; - args[2] = arg2; - args[3] = arg3; - proto_send (cmd, 4 * 2, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_arg ((arg1 >> 8) & 0xff); + proto_arg ((arg1 >> 0) & 0xff); + proto_arg ((arg2 >> 8) & 0xff); + proto_arg ((arg2 >> 0) & 0xff); + proto_arg ((arg3 >> 8) & 0xff); + proto_arg ((arg3 >> 0) & 0xff); + proto_putc ('\r'); } /* Send a command with 4 double words arguments. */ extern inline void proto_send4d (uint8_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) { - uint8_t args[4 * 4]; - args[0] = arg0; - args[1] = arg1; - args[2] = arg2; - args[3] = arg3; - proto_send (cmd, 4 * 4, args); + proto_putc ('!'); + proto_putc (cmd); + proto_arg ((arg0 >> 24) & 0xff); + proto_arg ((arg0 >> 16) & 0xff); + proto_arg ((arg0 >> 8) & 0xff); + proto_arg ((arg0 >> 0) & 0xff); + proto_arg ((arg1 >> 24) & 0xff); + proto_arg ((arg1 >> 16) & 0xff); + proto_arg ((arg1 >> 8) & 0xff); + proto_arg ((arg1 >> 0) & 0xff); + proto_arg ((arg2 >> 24) & 0xff); + proto_arg ((arg2 >> 16) & 0xff); + proto_arg ((arg2 >> 8) & 0xff); + proto_arg ((arg2 >> 0) & 0xff); + proto_arg ((arg3 >> 24) & 0xff); + proto_arg ((arg3 >> 16) & 0xff); + proto_arg ((arg3 >> 8) & 0xff); + proto_arg ((arg3 >> 0) & 0xff); + proto_putc ('\r'); } -- cgit v1.2.3