Commit from zer0 on branch b_zer0 (2008-01-07 23:48 CET) =================================
Allow to specify delay in avrdude aversive mk/aversive_project.mk 1.32.4.10 =============================== aversive/mk/aversive_project.mk (1.32.4.9 -> 1.32.4.10) =============================== @@ -111,7 +111,13 @@ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).$(FORMAT_EXTENSION) #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep -export AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -q +AVRDUDE_FLAGS = -e -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -q + +ifneq ($(DELAY),) +AVRDUDE_FLAGS += -i $(DELAY) +endif + +export AVRDUDE_FLAGS # Uncomment the following if you want avrdude's erase cycle counter. # Note that this counter needs to be initialized first using -Yn, @@ -128,7 +134,7 @@ #AVRDUDE_FLAGS += -v -v -AVARICE_WRITE_FLASH = --program --file $(TARGET).$(FORMAT_EXTENSION) +AVARICE_WRITE_FLASH = --erase --program --file $(TARGET).$(FORMAT_EXTENSION) #AVARICE_WRITE_EEPROM = XXX export AVARICE_FLAGS = -P $(MCU) --jtag $(AVARICE_PORT) --$(AVARICE_PROGRAMMER) Commit from zer0 on branch b_zer0 (2008-01-07 23:49 CET) ================================= remove debug in i2c module fix i2c commands in microb project aversive modules/comm/i2c/i2c.c 1.1.2.9 =============================== aversive/modules/comm/i2c/i2c.c (1.1.2.8 -> 1.1.2.9) =============================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c.c,v 1.1.2.8 2007-08-21 21:51:59 zer0 Exp $ + * Revision : $Id: i2c.c,v 1.1.2.9 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -43,57 +43,6 @@ #error "I2C_RECV_BUFFER_SIZE must be at least 1" #endif -/* to remove XXX */ -#ifdef _AVR_IOM128_H_ -#define LED1_ON() sbi(PORTE, 2) -#define LED1_OFF() cbi(PORTE, 2) - -#define LED2_ON() sbi(PORTE, 3) -#define LED2_OFF() cbi(PORTE, 3) - -#define LED3_ON() sbi(PORTB, 3) -#define LED3_OFF() cbi(PORTB, 3) - -#define LED4_ON() sbi(PORTB, 4) -#define LED4_OFF() cbi(PORTB, 4) - -#define LED5_ON() do {} while(0) -#define LED5_OFF() do {} while(0) - -#define LED6_ON() do {} while(0) -#define LED6_OFF() do {} while(0) - -#define LED7_ON() do {} while(0) -#define LED7_OFF() do {} while(0) -#else -/* to remove XXX */ -#define LED5BIT 2 -#define LED6BIT 3 -#define LED7BIT 4 - -/* to remove XXX */ -#define LED1_ON() do {} while(0) -#define LED1_OFF() do {} while(0) - -#define LED2_ON() do {} while(0) -#define LED2_OFF() do {} while(0) - -#define LED3_ON() do {} while(0) -#define LED3_OFF() do {} while(0) - -#define LED4_ON() do {} while(0) -#define LED4_OFF() do {} while(0) - -#define LED5_ON() sbi(PORTB, LED5BIT) -#define LED5_OFF() cbi(PORTB, LED5BIT) - -#define LED6_ON() sbi(PORTB, LED6BIT) -#define LED6_OFF() cbi(PORTB, LED6BIT) - -#define LED7_ON() sbi(PORTB, LED7BIT) -#define LED7_OFF() cbi(PORTB, LED7BIT) -#endif - /** recv event, called when we receive a frame * params are : data buffer and size */ static void (*g_recv_event)(uint8_t *, int8_t) = NULL; @@ -520,15 +469,9 @@ { uint8_t hard_status; uint8_t command = (1<<TWINT) | (1<<TWEN) | (1<<TWIE); - static char a=0; hard_status = TW_STATUS; - if(a) - LED7_OFF(); - else - LED7_ON(); - a = !a; switch(hard_status) { #ifdef CONFIG_MODULE_I2C_MASTER Commit from zer0 (2008-01-07 23:49 CET) ================ remove debug in i2c module fix i2c commands in microb project aversive_projects microb2008/common/i2c_commands.h 1.4 aversive_projects microb2008/extension/i2c_protocol.c 1.5 aversive_projects microb2008/extension/main.c 1.8 aversive_projects microb2008/main/commands.c 1.9 aversive_projects microb2008/main/i2c_protocol.c 1.7 aversive_projects microb2008/main/i2c_protocol.h 1.4 aversive_projects microb2008/main/main.c 1.15 ================================================== aversive_projects/microb2008/common/i2c_commands.h (1.3 -> 1.4) ================================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_commands.h,v 1.3 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: i2c_commands.h,v 1.4 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -63,6 +63,16 @@ uint8_t roller_angle; }; +/****/ + +#define I2C_CMD_EXTENSION_PWM 0x02 + +struct i2c_cmd_extension_pwm { + struct i2c_cmd_hdr hdr; + uint8_t num; + int16_t val; +}; + /****/ /* requests and their answers */ ===================================================== aversive_projects/microb2008/extension/i2c_protocol.c (1.4 -> 1.5) ===================================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_protocol.c,v 1.4 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: i2c_protocol.c,v 1.5 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -25,6 +25,7 @@ #include <aversive/list.h> #include <i2c.h> +#include <pwm.h> #include "main.h" #include "../common/i2c_commands.h" @@ -86,19 +87,31 @@ return c; } +static uint8_t val1=0, val2=0, val3=0; + void i2c_send_status(void) { struct i2c_ans_extension_status ans; i2c_flush(); ans.hdr.cmd = I2C_ANS_EXTENSION_STATUS; - ans.state = 1; - ans.white_ball_count = 2; - ans.colored_ball_count = 3; + ans.state = val1; + ans.white_ball_count = val2; + ans.colored_ball_count = val3; + /* XXX check return value. To wait is stupid because we are + called with irq disabled */ + i2c_send(I2C_ADD_MASTER, (uint8_t *) &ans, sizeof(ans), I2C_CTRL_GENERIC); } - void i2c_recvevent(uint8_t * buf, int8_t size) { + static uint8_t a=0; + a=!a; + if (a) + LED6_ON(); + else + LED6_OFF(); + + if (size <= 0) { goto error; } @@ -124,8 +137,21 @@ break; } + case I2C_CMD_EXTENSION_PWM: + { + struct i2c_cmd_extension_pwm * cmd = (struct i2c_cmd_extension_pwm *) buf; + if (size != sizeof (*cmd)) + goto error; + if (cmd->num == 0) + pwm_set((void *)PWM1A_NUM, cmd->val); + else + pwm_set((void *)PWM1B_NUM, cmd->val); + break; + } + /* Add other commands here ...*/ + /* Requests (answer needed) */ case I2C_REQ_READ_DEBUG_BUFFER: { ============================================= aversive_projects/microb2008/extension/main.c (1.7 -> 1.8) ============================================= @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: main.c,v 1.7 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: main.c,v 1.8 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -39,8 +39,6 @@ #define DEBUG_LED_BLINK - - void do_debug(void * dummy) { #ifdef DEBUG_LED_BLINK @@ -55,18 +53,12 @@ #endif } - - int main(void) { /* i/o */ DDRB = (1<<LED5BIT) | (1<<LED6BIT) | (1<<LED7BIT) ; - // pwm_init(); - -/* pwm_set((void *)PWM1B_NUM, 500); */ -/* pwm_set((void *)PWM1A_NUM, 4000); */ -/* while(1); */ + pwm_init(); /* scheduler */ scheduler_init(); @@ -83,8 +75,6 @@ /* debug via i2c (um zu gut zu machen) */ fdevopen(debug_send, NULL); - pwm_set((void *)PWM1B_NUM, 1000); - sei(); while(1) { ============================================ aversive_projects/microb2008/main/commands.c (1.8 -> 1.9) ============================================ @@ -18,6 +18,7 @@ #include <vt100.h> #include "main.h" +#include "i2c_protocol.h" #include "eeprom.h" //#include "test.h" #include "sensor.h" @@ -112,14 +113,19 @@ pwm_ptr = LEFT_PWM; else if (!strcmp_P(res->arg1, PSTR("right"))) pwm_ptr = RIGHT_PWM; + else if (!strcmp_P(res->arg1, PSTR("ext0"))) + i2c_pwm(0, res->arg2); + else if (!strcmp_P(res->arg1, PSTR("ext1"))) + i2c_pwm(1, res->arg2); - pwm_set(pwm_ptr, res->arg2); + if (pwm_ptr) + pwm_set(pwm_ptr, res->arg2); printf_P(PSTR("done\n")); } prog_char str_pwm_arg0[] = "pwm"; parse_pgm_token_string_t cmd_pwm_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_pwm_result, arg0, str_pwm_arg0); -prog_char str_pwm_arg1[] = "3C#1A#1B#2#left#right"; +prog_char str_pwm_arg1[] = "3C#1A#1B#2#left#right#ext0#ext1"; parse_pgm_token_string_t cmd_pwm_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_pwm_result, arg1, str_pwm_arg1); parse_pgm_token_num_t cmd_pwm_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_pwm_result, arg2, INT16); @@ -1440,6 +1446,12 @@ if (!strcmp_P(res->arg3, PSTR("on"))) { for (i=0; i<NB_LOGS; i++) { + if (robot.logs[i] == lognum) { + printf_P(PSTR("Already on\n")); + return; + } + } + for (i=0; i<NB_LOGS; i++) { if (robot.logs[i] == 0) { robot.logs[i] = lognum; break; ================================================ aversive_projects/microb2008/main/i2c_protocol.c (1.6 -> 1.7) ================================================ @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_protocol.c,v 1.6 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: i2c_protocol.c,v 1.7 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -129,12 +129,6 @@ } } else { - i2c_errors++; - NOTICE(E_USER_I2C_PROTO, "received error %d\n", i2c_state); - if (i2c_errors > I2C_MAX_ERRORS) { - WARNING(E_USER_I2C_PROTO, "I2C error, slave not ready\n"); - i2c_errors = 0; - } } poll_is_running = 0; @@ -144,7 +138,7 @@ (struct i2c_ans_write_debug_buffer * )buf; if (size != sizeof (*ans)) - break; + goto error; /* we may loose chars here, if the uart fifo is full */ /* XXX bad, we should use a fifo to buffer until we receive @@ -158,8 +152,7 @@ (struct i2c_ans_extension_status * )buf; if (size != sizeof (*ans)) - break; - + goto error; robot.extension_state = ans->state; robot.white_ball_count = ans->white_ball_count; robot.colored_ball_count = ans->colored_ball_count; @@ -170,6 +163,15 @@ default: break; } + + return; + error: + i2c_errors++; + NOTICE(E_USER_I2C_PROTO, "received error %d\n", i2c_state); + if (i2c_errors > I2C_MAX_ERRORS) { + WARNING(E_USER_I2C_PROTO, "I2C error, slave not ready\n"); + i2c_errors = 0; + } } /* unused */ @@ -194,9 +196,9 @@ { /* XXX log in case of error ? */ wait_cond_or_timeout(i2c_send(I2C_EXTENSION_ADDR, - (uint8_t*)&buf, - sizeof(buf), - I2C_CTRL_GENERIC)==ESUCCESS, I2C_TIMEOUT); + buf, size, + I2C_CTRL_GENERIC)==ESUCCESS, + I2C_TIMEOUT); } void i2c_led_control(uint8_t led, uint8_t state) @@ -208,6 +210,14 @@ i2c_send_command((uint8_t*)&buf, sizeof(buf)); } +void i2c_pwm(uint8_t num, int16_t val) +{ + struct i2c_cmd_extension_pwm buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_PWM; + buf.num = num; + buf.val = val; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} void i2c_harvest(void) { @@ -267,7 +277,7 @@ int8_t i2c_req_extension_status(void) { - struct i2c_req_read_debug_buffer buf; + struct i2c_req_extension_status buf; buf.hdr.cmd = I2C_REQ_EXTENSION_STATUS; ================================================ aversive_projects/microb2008/main/i2c_protocol.h (1.3 -> 1.4) ================================================ @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_protocol.h,v 1.3 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: i2c_protocol.h,v 1.4 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -38,6 +38,7 @@ void i2c_sendevent(int8_t size); void i2c_led_control(uint8_t led, uint8_t state); +void i2c_pwm(uint8_t num, int16_t val); int8_t i2c_req_read_debug_buffer(void); void i2c_harvest(void); ======================================== aversive_projects/microb2008/main/main.c (1.14 -> 1.15) ======================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: main.c,v 1.14 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: main.c,v 1.15 2008-01-07 22:49:06 zer0 Exp $ * */ @@ -72,7 +72,7 @@ void do_led_blink(void * dummy) { #if 1 /* simple blink */ - static u08 a=0; + static uint8_t a=0; if(a) LED1_ON(); _______________________________________________ Avr-list mailing list Avr-list@droids-corp.org CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive WIKI : http://wiki.droids-corp.org/index.php/Aversive DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/ BUGZILLA : http://bugzilla.droids-corp.org COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog