tux-droid-svn Mailing List for Tux Droid CE (Page 220)
Status: Beta
Brought to you by:
ks156
You can subscribe to this list here.
2007 |
Jan
|
Feb
(32) |
Mar
(108) |
Apr
(71) |
May
(38) |
Jun
(128) |
Jul
(1) |
Aug
(14) |
Sep
(77) |
Oct
(104) |
Nov
(90) |
Dec
(71) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(81) |
Feb
(18) |
Mar
(40) |
Apr
(102) |
May
(151) |
Jun
(74) |
Jul
(151) |
Aug
(257) |
Sep
(447) |
Oct
(379) |
Nov
(404) |
Dec
(430) |
2009 |
Jan
(173) |
Feb
(236) |
Mar
(519) |
Apr
(300) |
May
(112) |
Jun
(232) |
Jul
(314) |
Aug
(58) |
Sep
(203) |
Oct
(293) |
Nov
(26) |
Dec
(109) |
2010 |
Jan
(19) |
Feb
(25) |
Mar
(33) |
Apr
(1) |
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: remi <c2m...@c2...> - 2007-09-19 08:17:39
|
Author: remi Date: 2007-09-19 10:16:13 +0200 (Wed, 19 Sep 2007) New Revision: 530 Added: software/tuxgi/trunk/sounds/10.wav software/tuxgi/trunk/sounds/11.wav software/tuxgi/trunk/sounds/12.wav software/tuxgi/trunk/sounds/13.wav software/tuxgi/trunk/sounds/14.wav software/tuxgi/trunk/sounds/15.wav software/tuxgi/trunk/sounds/16.wav Log: ADD: 7 new sounds Added: software/tuxgi/trunk/sounds/10.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/10.wav ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software/tuxgi/trunk/sounds/11.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/11.wav ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software/tuxgi/trunk/sounds/12.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/12.wav ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software/tuxgi/trunk/sounds/13.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/13.wav ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software/tuxgi/trunk/sounds/14.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/14.wav ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software/tuxgi/trunk/sounds/15.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/15.wav ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: software/tuxgi/trunk/sounds/16.wav =================================================================== (Binary files differ) Property changes on: software/tuxgi/trunk/sounds/16.wav ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
From: remi <c2m...@c2...> - 2007-09-19 08:09:52
|
Author: remi Date: 2007-09-19 10:09:47 +0200 (Wed, 19 Sep 2007) New Revision: 529 Modified: api/python/trunk/tuxapi_class.py Log: UPD: TTS speak system UPD: Socket send Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2007-09-18 15:00:17 UTC (rev 528) +++ api/python/trunk/tuxapi_class.py 2007-09-19 08:09:47 UTC (rev 529) @@ -68,7 +68,7 @@ Call the destroying function at the end of your script for closing the api correctly. >>> tux.destroy() - + "tts" class is compatible with "tuxttsd" v 0.3.0 or more recent """ #-------------------------------------------------------------------------- @@ -81,6 +81,7 @@ Example: >>> tux=TUXTCPCommunicator() """ + self.sock = None self.main_thread_list=[] self.exit_flag=False self.tcp_mutex=threading.Lock() @@ -136,6 +137,15 @@ print "Tux object has been destroyed" #-------------------------------------------------------------------------- + # Send a frame to tuxd + #-------------------------------------------------------------------------- + def _sock_send_frame(self, frame): + try: + self.sock.send(frame) + except: + pass + + #-------------------------------------------------------------------------- # SYSTEM function #-------------------------------------------------------------------------- def _loop_tux_tcp_msg(self): @@ -238,7 +248,7 @@ lock[1].acquire() lock[1].notify() lock[1].release() - self.lock_list.pop(i) + self.lock_list = [] self.lock_list_mutex.release() #-------------------------------------------------------------------------- @@ -441,7 +451,7 @@ if ord(data[5])==0: if self.event.on_spin_stop!=None: self.event.on_spin_stop() - #on status + #on status if self.event.on_status!=None: self.event.on_status(data) @@ -510,7 +520,7 @@ return False # Fill up the end of the frame with 0 data.extend([0] * (TCPIP_FRAME_LENGTH - len(data))) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) return self.parent.status.rsp_status(connection_command, timeout=5) #-------------------------------------------------------------------------- @@ -554,7 +564,7 @@ assert 0 < id < 0xFFFF id_msb = id >> 8 id_lsb = id & 0xFF - ack_frame = self.tux_connection(TUX_CONNECTION_CONNECT, + ack_frame = self.tux_connection(TUX_CONNECTION_CONNECT, [id_msb, id_lsb]) if not ack_frame or ord(ack_frame[5]) != TUX_CONNECTION_ACK: return False @@ -589,7 +599,7 @@ Get the ID of tux currently connected Returns: - "id" as uint16 (0 < id < 65536) if the command has been sent + "id" as uint16 (0 < id < 65536) if the command has been sent successfully, "False" otherwise. """ @@ -614,7 +624,7 @@ to issue this command multiple times until you don't get any new ID. Returns: - "id" as uint16 (0 < id < 65536) if the command has been sent + "id" as uint16 (0 < id < 65536) if the command has been sent successfully, "False" otherwise. """ @@ -646,7 +656,7 @@ assert 0 < id < 0xFFFF id_msb = id >> 8 id_lsb = id % 256 - ack_frame = self.tux_connection(TUX_CONNECTION_CHANGE_ID, + ack_frame = self.tux_connection(TUX_CONNECTION_CHANGE_ID, [id_msb, id_lsb]) if not ack_frame or ord(ack_frame[5]) != TUX_CONNECTION_ACK: return False @@ -713,7 +723,7 @@ "True" if the command has been sent successfully, "False" otherwise. """ - ack_frame = self.tux_connection(TUX_CONNECTION_WIRELESS_CHANNEL, + ack_frame = self.tux_connection(TUX_CONNECTION_WIRELESS_CHANNEL, [channel]) if not ack_frame or ord(ack_frame[5]) != TUX_CONNECTION_ACK: return False @@ -1596,7 +1606,7 @@ return 2 data=(DEST_TUX,SD_DEFAULT,DATA_TP_CMD,SUBDATA_TP_STRUCT, \ fct,cmd,param1,param2,param3,0,0,0,0,0,0,0) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) if self.no_ack: return 2 else: @@ -1624,7 +1634,7 @@ return 2 data=(DEST_TUX,SD_DEFAULT,DATA_TP_CMD,SUBDATA_TP_RAW, \ cmd,param1,param2,param3,0,0,0,0,0,0,0,0) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) if self.no_ack: return 2 else: @@ -2597,7 +2607,7 @@ return 0 data=(DEST_TUX,SD_DEFAULT,DATA_TP_REQ,SUBDATA_TP_STATUS,DATA_STATUS, \ 0,0,0,0,0,0,0,0,0,0,0) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) return self.rsp_status(DATA_STATUS) #-------------------------------------------------------------------------- @@ -3487,7 +3497,7 @@ return 2 data=(DEST_SUB_DAEMON,SD_DEFAULT,DATA_TP_CMD,SUBDATA_TP_STRUCT,cmd, param1,param2,param3,0,0,0,0,0,0,0,0) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) return 0 #-------------------------------------------------------------------------- @@ -3501,7 +3511,7 @@ return 2 data=(DEST_SUB_DAEMON,SD_DEFAULT,DATA_TP_REQ, \ SUBDATA_TP_INFO,req,param1,param2,param3,0,0,0,0,0,0,0,0) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) return self.rsp_info(req) #-------------------------------------------------------------------------- @@ -3571,7 +3581,7 @@ ord(name[2]),ord(name[3]),ord(name[4]),ord(name[5]), ord(name[6]),ord(name[7]),ord(name[8]),ord(name[9]), ord(name[10])) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) self.parent.my_name=name self.last_ack=self.cmd_ack() @@ -3724,7 +3734,7 @@ return (0,0,0,0,0) data=(DEST_TUX,SD_DEFAULT,DATA_TP_REQ,SUBDATA_TP_INFO, \ TUX_REQ_INFO_VERSION,cpu_index,0,0,0,0,0,0,0,0,0,0) - self.parent.sock.send("".join( [chr(x) for x in data] )) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) frame = self.parent.status.rsp_status(TUX_REQ_INFO_VERSION) if len(frame) > 0: ver_major=ord(frame[5]) @@ -3958,10 +3968,10 @@ Constructor of this class """ self.parent=parent - self.con_thread_list=[] + self.con_thread_list = [] self.connected=False - self.tcp_mutex=threading.Lock() - self.tts_mutex=threading.Lock() + self.tcp_mutex = threading.Lock() + self.tts_mutex = threading.Lock() self.tcp_data_list = [] self.print_status = False self.on_sound_on = None @@ -3977,6 +3987,77 @@ self.ac_address='localhost' self.authorized_voices_list = [] self.voice_loaded = False + self.speaking_stack = [] + self.speaking_stack_mutex = threading.Lock() + + def speaking_stack_add(self, speaking_conf): + self.speaking_stack_mutex.acquire() + self.speaking_stack.append(speaking_conf) + self.speaking_stack_mutex.release() + + def speaking_stack_get_size(self): + self.speaking_stack_mutex.acquire() + val = len(self.speaking_stack) + self.speaking_stack_mutex.release() + return val + + def speaking_stack_loop(self): + while self.connected: + if self.speaking_stack_get_size() > 0: + if not self.tts_mutex.locked(): + self.speaking_stack_mutex.acquire() + curr_speaking_conf = self.speaking_stack.pop(0) + self.speaking_stack_mutex.release() + self.my_pitch = curr_speaking_conf[1][1] + self.my_voice = curr_speaking_conf[1][0] + if curr_speaking_conf[2] == True: + self.__speak_free(curr_speaking_conf[0]) + else: + self.__speak(curr_speaking_conf[0]) + curr_speaking_conf[3].acquire() + curr_speaking_conf[3].notify() + curr_speaking_conf[3].release() + time.sleep(0.1) + self.speaking_stack_mutex.acquire() + for curr_speaking_conf in self.speaking_stack: + curr_speaking_conf[3].acquire() + curr_speaking_conf[3].notify() + curr_speaking_conf[3].release() + self.speaking_stack_mutex.release() + + def speak(self, text): + if not self.connected: + return + speaking_conf = [] + speaking_conf.append(text) + voice_conf = [] + voice_conf.append(self.my_voice) + voice_conf.append(self.my_pitch) + speaking_conf.append(voice_conf) + speaking_conf.append(False) + my_lock = threading.Condition(threading.Lock()) + speaking_conf.append(my_lock) + self.speaking_stack_add(speaking_conf) + my_lock.acquire() + my_lock.wait() + my_lock.release() + + def speak_free(self, text): + if not self.connected: + return + speaking_conf = [] + speaking_conf.append(text) + voice_conf = [] + voice_conf.append(self.my_voice) + voice_conf.append(self.my_pitch) + speaking_conf.append(voice_conf) + speaking_conf.append(True) + my_lock = threading.Condition(threading.Lock()) + speaking_conf.append(my_lock) + self.speaking_stack_add(speaking_conf) + my_lock.acquire() + my_lock.wait() + my_lock.release() #-------------------------------------------------------------------------- # Allow to connect the api to tuxttsd automatically @@ -4086,10 +4167,17 @@ t.setName('tts._loop_tux_data_dispatching') t.start() self.con_thread_list.append(t) + t=threading.Thread(target=self._loop_tcp_tts_msg) t.setName('tts._loop_tcp_tts_msg') t.start() self.con_thread_list.append(t) + + t=threading.Thread(target=self.speaking_stack_loop) + t.setName('tts.speaking_stack_loop') + t.start() + self.con_thread_list.append(t) + self.get_sound_state() return True @@ -4114,6 +4202,15 @@ self.sock.close() #-------------------------------------------------------------------------- + # Send a frame to tuxttsd + #-------------------------------------------------------------------------- + def _sock_send_frame(self, frame): + try: + self.sock.send(frame) + except: + pass + + #-------------------------------------------------------------------------- # SYSTEM function #-------------------------------------------------------------------------- def _loop_tcp_tts_msg(self): @@ -4212,7 +4309,7 @@ print "WARNING : Resource text to speech Acapela not found" return data=(cmd_type,cmd,param1,param2,param3,param4) - self.sock.send("".join( [chr(x) for x in data] )) + self._sock_send_frame("".join( [chr(x) for x in data] )) #-------------------------------------------------------------------------- # Reinit sound to tux sound card device @@ -4242,24 +4339,13 @@ Select a speaker voice Parameters: - "speaker" as integer : speaker id (SPK_FR_MALE|SPK_FR_FEMALE| - SPK_US_MALE|SPK_US_FEMALE| - SPK_B_FEMALE|SPK_D_MALE| - SPK_D_FEMALE|SPK_GB_MALE| - SPK_GB_FEMALE|SPK_AR_FEMALE| - SPK_DK_FEMALE|SPK_E_FEMALE| - SPK_I_FEMALE|SPK_NL_FEMALE| - SPK_N_FEMALE|SPK_P_FEMALE| - SPK_S_MALE|SPK_S_FEMALE) + "speaker" as integer : speaker id (SPK_FR_MALE|SPK_FR_FEMALE| + SPK_US_MALE|SPK_US_FEMALE) "pitch" as integer : raised pitch in % (100..330) Example: >>> tux.tts.select_voice(SPK_FR_MALE,100) """ - if speaker not in SPK_VOICE_LIST: - if self.parent.print_warnings: - print " Invalid speaker" - return if (pitch<100) or (pitch>330): if self.parent.print_warnings: print " Pitch not in range (100 - 330)" @@ -4367,7 +4453,7 @@ #-------------------------------------------------------------------------- # Speak a text with the acapela text to speech engine #-------------------------------------------------------------------------- - def speak(self,text): + def __speak(self,text): """ Speak a text with the acapela text to speech engine @@ -4393,26 +4479,35 @@ (text_length & 0x0000FF00) >> 8, (text_length & 0x000000FF), \ self.my_voice, self.my_pitch) self.voice_loaded = False - self.sock.send(text_to_send) + self._sock_send_frame(text_to_send) counter = 0 while ((self.voice_loaded == False) and (counter < 300)): counter = counter + 1 self.parent.sys.wait(0.1) + if self.speaking_stack_get_size() > 0: + break if counter == 300: self.stop() print "TTS Speak : Voice not loaded" + self.tts_mutex.release() return False self.parent.cmd.audio_channel_tts() counter = 0 while ((self.sound_on == False) and (counter < 100)): counter = counter + 1 self.parent.sys.wait(0.1) + if self.speaking_stack_get_size() > 0: + break if counter == 100: self.stop() + self.parent.cmd.audio_channel_general() print "TTS Speak : Timeout 10 sec" + self.tts_mutex.release() return False while self.sound_on == True: self.parent.sys.wait(0.1) + if self.speaking_stack_get_size() > 0: + break self.parent.cmd.audio_channel_general() self.tts_mutex.release() return True @@ -4420,7 +4515,7 @@ #-------------------------------------------------------------------------- # Speak a text with the acapela text to speech engine in free mode #-------------------------------------------------------------------------- - def speak_free(self,text): + def __speak_free(self,text): """ Speak a text with the acapela text to speech engine in free mode @@ -4430,7 +4525,7 @@ Example: >>> tux.tts.speak_free('My name is tux! tux droid !') """ - t=threading.Thread(target=self.speak,args=(text,)) + t=threading.Thread(target=self.__speak, args=(text,)) t.setName('tts.speak_free') t.start() self.parent.daemon.free_thread_list.append(t) |
From: jaguarondi <c2m...@c2...> - 2007-09-18 15:00:47
|
Author: jaguarondi Date: 2007-09-18 17:00:17 +0200 (Tue, 18 Sep 2007) New Revision: 528 Modified: daemon/trunk/libs/USBDaemon_status_table.c Log: * Now continuously sending light_level to the API. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-09-18 10:07:49 UTC (rev 527) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-09-18 15:00:17 UTC (rev 528) @@ -228,6 +228,7 @@ tcp_frame[5] = light_level / 256; tcp_frame[6] = light_level % 256; + tcp_server_send_raw(tcp_frame); } static void pong_event(unsigned char pong_number, unsigned char pong_received) @@ -558,8 +559,7 @@ * We substract here to represent the lightness instead of darkness */ light_level = 1128 - light_level; - if (light_level != sensors2.light_level) - sensors2_changed(light_level); + sensors2_changed(light_level); } break; |
From: jaguarondi <c2m...@c2...> - 2007-09-18 10:07:54
|
Author: jaguarondi Date: 2007-09-18 12:07:49 +0200 (Tue, 18 Sep 2007) New Revision: 527 Modified: firmware/tuxcore/trunk/sensors.c firmware/tuxcore/trunk/sensors.h Log: * Updated the thresholds of the light level measurement to change from one resistance to the other. Now the result is sent each time even if the resistance has to change. * Cleanup and commenting. Modified: firmware/tuxcore/trunk/sensors.c =================================================================== --- firmware/tuxcore/trunk/sensors.c 2007-09-18 09:54:28 UTC (rev 526) +++ firmware/tuxcore/trunk/sensors.c 2007-09-18 10:07:49 UTC (rev 527) @@ -19,45 +19,59 @@ /* $Id$ */ +/** \file sensors.c + \brief Sensors module + \ingroup sensors +*/ + #include <avr/interrupt.h> -#include <avr/io.h> #include "global.h" #include "hardware.h" -/* - * ADC conversion complete. - * TODO add battery level measurement +/** + \brief ADC conversion interrupt handling light and battery level + + The light sensor has 2 different values of pull-up resistors (1M and 10k) to + increase the range. It's necessary to switch from one to the other resistor + depending on the light level. This is done here. + + \todo TODO add battery level measurement */ ISR(SIG_ADC) { - if ((ADCL == 0x00) && (ADCH == 0x00) && !(LIGHT_PU_PORT & LIGHT_PU_MK)) + /* Save light mode before changing it below. */ + gStatus.lightM = LIGHT_PU_PORT & LIGHT_PU_MK; + /* Check if it's necessary to change the light mode. */ + if ((ADCL <= 0x28) && (ADCH == 0x00) && !(LIGHT_PU_PORT & LIGHT_PU_MK)) { LIGHT_PU_PORT |= LIGHT_PU_MK; LIGHT_PU_DDR |= LIGHT_PU_MK; - ADCSRA |= _BV(ADSC); } - else if ((ADCL == 0xFF) && (ADCH == 0x03) && (LIGHT_PU_PORT & LIGHT_PU_MK)) + else if ((ADCL >= 0xE8) && (ADCH == 0x03) && (LIGHT_PU_PORT & LIGHT_PU_MK)) { LIGHT_PU_PORT &= ~LIGHT_PU_MK; LIGHT_PU_DDR &= ~LIGHT_PU_MK; - ADCSRA |= _BV(ADSC); } - else - { - gStatus.lightL = ADCL; - gStatus.lightH = ADCH; - gStatus.lightM = LIGHT_PU_PORT & LIGHT_PU_MK; - light_f = 1; - } + /* ADCH should be read after ADCL otherwise ADCL stays wite protected (c.f. + * datasheet). */ + gStatus.lightL = ADCL; + gStatus.lightH = ADCH; + /* There's a new light value. */ + light_f = 1; } /** - * \brief Get light level - * - * Start one conversion. The result will be saved by the ADC interrupt. + * \name Light level + * @{ */ +/** \ingroup sensors */ +/** + \brief Start a light level measurement. + + Start a light level conversion. The result will be saved by the ADC interrupt. */ void getLight(void) { ADCSRA |= _BV(ADSC); } +/*! @} */ Modified: firmware/tuxcore/trunk/sensors.h =================================================================== --- firmware/tuxcore/trunk/sensors.h 2007-09-18 09:54:28 UTC (rev 526) +++ firmware/tuxcore/trunk/sensors.h 2007-09-18 10:07:49 UTC (rev 527) @@ -19,14 +19,21 @@ /* $Id$ */ -#ifndef SENSORS_H -#define SENSORS_H +/** \file sensors.h + \brief Sensors module interface + \ingroup sensors +*/ +/** \defgroup sensors Sensors + + The sensor module handles light and battery level measurement. As both + measurements are done with the same ADC (and same interrupt), it was + difficult to separate them as different modules. +*/ + +#ifndef _SENSORS_H_ +#define _SENSORS_H_ + void getLight(void); -#define isLeftWing (gStatus.sw & GSTATUS_LEFTWINGBTN_MK) -#define isRightWing (gStatus.sw & GSTATUS_RIGHTWINGBTN_MK) -#define isPlugged (gStatus.sw & GSTATUS_POWERPLUGSW_MK) -#define isHead (gStatus.sw & GSTATUS_HEADBTN_MK) - -#endif +#endif /* _SENSORS_H_ */ |
From: Paul_R <c2m...@c2...> - 2007-09-18 09:54:29
|
Author: Paul_R Date: 2007-09-18 11:54:28 +0200 (Tue, 18 Sep 2007) New Revision: 526 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * Added light measurment processing in order to get the light level as a single int from the three raw bytes. The two curves (from the two resistor values) are now merged into one. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-09-18 08:22:50 UTC (rev 525) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-09-18 09:54:28 UTC (rev 526) @@ -608,9 +608,8 @@ result[1] = sensors1.bits.PB7; break; case DATA_STATUS_LIGHT_LEVEL: - result[1] = sensors2.level_light_high.Byte; - result[2] = sensors2.level_light_low.Byte; - result[3] = sensors2.light_mode.Byte; + result[1] = sensors2.light_level / 256; + result[2] = sensors2.light_level % 256; break; case DATA_STATUS_EYES_POSITION_COUNTER: result[1] = position1.eyes_position.Byte; Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-09-18 08:22:50 UTC (rev 525) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-09-18 09:54:28 UTC (rev 526) @@ -211,8 +211,7 @@ sensors1.Byte = new_value; } -static void sensors2_changed(unsigned char new_value_high, unsigned char new_value_low, - unsigned char new_light_mode) +static void sensors2_changed(int light_level) { tcp_frame_t tcp_frame; @@ -225,12 +224,10 @@ tcp_frame[4] = DATA_STATUS_LIGHT_LEVEL; - sensors2.level_light_high.Byte = new_value_high; - sensors2.level_light_low.Byte = new_value_low; - sensors2.light_mode.Byte = new_light_mode; - - tcp_frame[5] = new_value_high; - tcp_frame[6] = new_value_low; + sensors2.light_level = light_level; + + tcp_frame[5] = light_level / 256; + tcp_frame[6] = light_level % 256; } static void pong_event(unsigned char pong_number, unsigned char pong_received) @@ -552,9 +549,18 @@ break; case STATUS_LIGHT_CMD: - if (sensors2.level_light_high.Byte != new_status[1] - || sensors2.level_light_low.Byte != new_status[2]) - sensors2_changed(new_status[1], new_status[2], new_status[3]); + { + int light_level; + light_level = (new_status[1] << 8) + new_status[2]; + if (new_status[3] == 0) + light_level = light_level / 8 + 1000; + /* 1128 is the maximum value when there is no light + * We substract here to represent the lightness instead of darkness + */ + light_level = 1128 - light_level; + if (light_level != sensors2.light_level) + sensors2_changed(light_level); + } break; case STATUS_POSITION1_CMD: Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-09-18 08:22:50 UTC (rev 525) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-09-18 09:54:28 UTC (rev 526) @@ -238,6 +238,7 @@ _PORT_BYTE_ level_light_high; _PORT_BYTE_ level_light_low; _PORT_BYTE_ light_mode; + int light_level; } sensors2; struct { |
From: jaguarondi <c2m...@c2...> - 2007-09-18 08:23:20
|
Author: jaguarondi Date: 2007-09-18 10:22:50 +0200 (Tue, 18 Sep 2007) New Revision: 525 Modified: firmware/tuxcore/trunk/parser.c Log: * Small bug introduced when cleaning up the led functions. Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-13 11:32:27 UTC (rev 524) +++ firmware/tuxcore/trunk/parser.c 2007-09-18 08:22:50 UTC (rev 525) @@ -148,7 +148,7 @@ } else if (command[0] == LED_L_OFF_CMD) { - turn_left_led_on(); + turn_left_led_off(); } else if (command[0] == LED_R_ON_CMD) { |
From: jaguarondi <c2m...@c2...> - 2007-09-13 11:32:27
|
Author: jaguarondi Date: 2007-09-13 13:32:27 +0200 (Thu, 13 Sep 2007) New Revision: 524 Modified: firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/led.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Cleanup. Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-09-13 09:34:02 UTC (rev 523) +++ firmware/tuxcore/trunk/led.c 2007-09-13 11:32:27 UTC (rev 524) @@ -52,7 +52,7 @@ if (!cnt) return; cnt--; /* the first toggle occurs here */ - toggleLeds(); + toggle_leds(); if (!cnt) /* if one toggle, nothing more to do */ return; led_delay = pulse_width; @@ -84,7 +84,7 @@ led_delay--; if (!led_delay) { - toggleLeds(); + toggle_leds(); if (--led_blinking_cnt) led_delay = led_blinking_pw; } Modified: firmware/tuxcore/trunk/led.h =================================================================== --- firmware/tuxcore/trunk/led.h 2007-09-13 09:34:02 UTC (rev 523) +++ firmware/tuxcore/trunk/led.h 2007-09-13 11:32:27 UTC (rev 524) @@ -39,61 +39,61 @@ \brief Turn both leds on. \ingroup led */ -#define turnLedsOn() (leds_buffer |= LED_MK) +#define turn_leds_on() (leds_buffer |= LED_MK) /** \brief Turn both leds off. \ingroup led */ -#define turnLedsOff() (leds_buffer &= ~LED_MK) +#define turn_leds_off() (leds_buffer &= ~LED_MK) /** \brief Turn left led on. \ingroup led */ -#define turnLeftLedOn() (leds_buffer |= LED_L_MK) +#define turn_left_led_on() (leds_buffer |= LED_L_MK) /** \brief Turn right led on. \ingroup led */ -#define turnRightLedOn() (leds_buffer |= LED_R_MK) +#define turn_right_led_on() (leds_buffer |= LED_R_MK) /** \brief Turn left led off. \ingroup led */ -#define turnLeftLedOff() (leds_buffer &= ~LED_L_MK) +#define turn_left_led_off() (leds_buffer &= ~LED_L_MK) /** \brief Turn right led off. \ingroup led */ -#define turnRightLedOff() (leds_buffer &= ~LED_R_MK) +#define turn_right_led_off() (leds_buffer &= ~LED_R_MK) /** \brief Read the value of the leds. \ingroup led */ -#define readLeds() (leds_buffer) +#define read_leds() (leds_buffer) /** \brief Toggle leds. \ingroup led */ -#define toggleLeds() (leds_buffer ^= LED_MK) +#define toggle_leds() (leds_buffer ^= LED_MK) /** \brief Toggle left led. \ingroup led */ -#define toggleLeftLed() (leds_buffer ^= LED_L_MK) +#define toggle_left_led() (leds_buffer ^= LED_L_MK) /** - \brief toggle right led. + \brief Toggle right led. \ingroup led */ -#define toggleRightLed() (leds_buffer ^= LED_R_MK) +#define toggle_right_led() (leds_buffer ^= LED_R_MK) /** \brief Turn both leds off directly on the I/O port. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-13 09:34:02 UTC (rev 523) +++ firmware/tuxcore/trunk/main.c 2007-09-13 11:32:27 UTC (rev 524) @@ -264,7 +264,7 @@ PCICR = 0; EIMSK = 0; ADCSRA = 0; - turnLedsOff(); + turn_leds_off(); turnIrOff(); } Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-13 09:34:02 UTC (rev 523) +++ firmware/tuxcore/trunk/parser.c 2007-09-13 11:32:27 UTC (rev 524) @@ -136,27 +136,27 @@ /* Leds */ else if (command[0] == LED_ON_CMD) { - turnLedsOn(); + turn_leds_on(); } else if (command[0] == LED_OFF_CMD) { - turnLedsOff(); + turn_leds_off(); } else if (command[0] == LED_L_ON_CMD) { - turnLeftLedOn(); + turn_left_led_on(); } else if (command[0] == LED_L_OFF_CMD) { - turnLeftLedOff(); + turn_left_led_on(); } else if (command[0] == LED_R_ON_CMD) { - turnRightLedOn(); + turn_right_led_on(); } else if (command[0] == LED_R_OFF_CMD) { - turnRightLedOff(); + turn_right_led_off(); } else if (command[0] == LED_BLINK_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-13 09:34:02 UTC (rev 523) +++ firmware/tuxcore/trunk/standalone.c 2007-09-13 11:32:27 UTC (rev 524) @@ -213,13 +213,13 @@ if (gStatus. sw & (GSTATUS_LEFTWINGBTN_MK | GSTATUS_RIGHTWINGBTN_MK | GSTATUS_HEADBTN_MK)) - turnLeftLedOn(); + turn_left_led_on(); else - turnLeftLedOff(); + turn_left_led_on(); if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) - turnRightLedOn(); + turn_right_led_on(); else - turnRightLedOff(); + turn_right_led_off(); } /* IR signal processing */ @@ -297,10 +297,10 @@ tux_config.ir_feedback = !tux_config.ir_feedback; break; case K_CHANNELPLUS: - toggleRightLed(); + toggle_right_led(); break; case K_VOLUMEPLUS: - toggleLeftLed(); + toggle_left_led(); break; case K_FASTREWIND: if (spin_PWM) |
From: jaguarondi <c2m...@c2...> - 2007-09-13 09:34:15
|
Author: jaguarondi Date: 2007-09-13 11:34:02 +0200 (Thu, 13 Sep 2007) New Revision: 523 Modified: firmware/tuxcore/trunk/global.c firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/led.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Reorganized the led functions to move all variables back to the module and make them static. Updated the comments. Modified: firmware/tuxcore/trunk/global.c =================================================================== --- firmware/tuxcore/trunk/global.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/global.c 2007-09-13 09:34:02 UTC (rev 523) @@ -38,7 +38,6 @@ uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag = 0; uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen = 0xFF; -uint8_t led_backup; /* * Condition flags Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/global.h 2007-09-13 09:34:02 UTC (rev 523) @@ -182,7 +182,6 @@ extern uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag; extern uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen; -extern uint8_t led_backup; /* * Sleep modes Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/led.c 2007-09-13 09:34:02 UTC (rev 523) @@ -24,23 +24,28 @@ \ingroup led */ -#include "global.h" -#include "hardware.h" #include "led.h" -uint8_t led_delay, led_blinking_pw, led_blinking_cnt; /* led blinking registers */ +/** Buffer the leds values before being applied on the I/O port. + * \ingroup led */ +uint8_t leds_buffer; +/** Counter for the delay between 2 toggles of the leds. */ +static uint8_t led_delay; +/** Delay between 2 toggles of the leds when blinking them. */ +static uint8_t led_blinking_pw; +/** Number of times the leds should be toggled when blinking. */ +static uint8_t led_blinking_cnt; + /** - \brief blinkLeds function + \brief Blink leds \ingroup led + \param cnt Number of blinks + \param pulse_width Blinking pulse width - \param cnt number of blinks before stop - \param pulse_width blink frequency - - The eyes will start until 'cnt' blink are executed. 'cnt' can be up to 256. - 'pulse_width' can be used to change the blink frequency. - */ - -void blinkLeds(uint8_t cnt, uint8_t pulse_width) + The leds will be toggled 'cnt' times. The pulse width can be used to change + the toggle frequency. +*/ +void blink_leds(uint8_t cnt, uint8_t pulse_width) { if (led_delay) /* cancel the blink if one is already happening */ return; @@ -56,30 +61,32 @@ } /** - \brief Refresh led port \ingroup led + \brief Refresh the leds I/O with the buffer value. + \ingroup led + */ +void refresh_leds(void) +{ + LED_PT &= ~LED_MK; + LED_PT |= leds_buffer; +} - \param mk Temp variable used to store the leds status. - - This function check the value of mk for both leds, and puts the value into the - output port. - - When the eyes are closed, the leds are switched off. To make possible to - change the leds status during the eyes are closed, the value is buffered. A - reveived command when the eyes are closed will be applied when the eyes - will reopened. +/** + \brief Periodic routine that controls the leds. + \ingroup led - This function is called when eyes are opened, and they're not blinking. - */ - -void setLeds(uint8_t mk) + This function should be called regularly as it controls the blinking. The + period this function is called will be the unit period of the led blinking. + */ +void led_control(void) { - if (mk & LED_R_MK) - LED_PT |= LED_R_MK; - else - LED_PT &= ~LED_R_MK; - - if (mk & LED_L_MK) - LED_PT |= LED_L_MK; - else - LED_PT &= ~LED_L_MK; + if (led_delay) + { + led_delay--; + if (!led_delay) + { + toggleLeds(); + if (--led_blinking_cnt) + led_delay = led_blinking_pw; + } + } } Modified: firmware/tuxcore/trunk/led.h =================================================================== --- firmware/tuxcore/trunk/led.h 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/led.h 2007-09-13 09:34:02 UTC (rev 523) @@ -19,116 +19,94 @@ /* $Id$ */ -/** \defgroup led Leds - - The led module contains all the function necessary to drive eyes leds and - manage the remote control. -*/ - /** \file led.h - \brief Blue leds control interface + \brief Blue leds control interface. \ingroup led */ -#ifndef LED_H -#define LED_H +/** \defgroup led Leds + The led module contains the functions that drive the eye leds. +*/ -extern uint8_t led_delay, led_blinking_pw, led_blinking_cnt; +#ifndef _LED_H_ +#define _LED_H_ -/** - \brief Turn both LEDs on - \ingroup led +#include "hardware.h" - */ -#define turnLedsOn() (led_backup |= LED_MK) +extern uint8_t leds_buffer; /** - \brief Turn both LEDs off + \brief Turn both leds on. \ingroup led - - This declaration is used to switch off the led when the eyes are opened. - - It may be used everywhere when the eyes must be off. */ -#define turnLedsOff() (led_backup &= ~LED_MK) +#define turnLedsOn() (leds_buffer |= LED_MK) /** - \brief Turn both LEDs off when eyes are closed + \brief Turn both leds off. \ingroup led - - This declaration is used to switch off the leds when eyes are closed. In - this case, led_backup must not be changed. - If not, the last value will be - lost, and the led status will not be restored when the eyes will be - reopened. - - \note This declaration is used only in the standalone_behavior.c. It souldn't - be used elsewhere. */ -#define turnLedsOffbEyes() (LED_PT &= ~LED_MK) +#define turnLedsOff() (leds_buffer &= ~LED_MK) /** - \brief Turn left LED on + \brief Turn left led on. \ingroup led */ -#define turnLeftLedOn() (led_backup |= LED_L_MK) +#define turnLeftLedOn() (leds_buffer |= LED_L_MK) /** - \brief Turn right LED on + \brief Turn right led on. \ingroup led */ -#define turnRightLedOn() (led_backup |= LED_R_MK) +#define turnRightLedOn() (leds_buffer |= LED_R_MK) /** - \brief Turn left LED off + \brief Turn left led off. \ingroup led */ -#define turnLeftLedOff() (led_backup &= ~LED_L_MK) +#define turnLeftLedOff() (leds_buffer &= ~LED_L_MK) /** - \brief Turn right LED off + \brief Turn right led off. \ingroup led */ -#define turnRightLedOff() (led_backup &= ~LED_R_MK) +#define turnRightLedOff() (leds_buffer &= ~LED_R_MK) /** - \brief read led's status + \brief Read the value of the leds. \ingroup led */ -#define readLeds() (LED_PIN & LED_MK) +#define readLeds() (leds_buffer) /** - \brief blink leds + \brief Toggle leds. \ingroup led - \param pulse_width Blinking pulse width - - Toggle both leds once then re-toggle them after a delay given as parameter. - The result looks like a blinking of the leds. */ -void blinkLeds(uint8_t cnt, uint8_t pulse_width); -void setLeds (uint8_t mk); +#define toggleLeds() (leds_buffer ^= LED_MK) + /** - \brief toggle leds + \brief Toggle left led. \ingroup led - - The led_toggle command is bufferised to prevent a bug : - - Without this buffer, if an odd number of blink is received, the leds will blink, but at the end of this sequence, the previous state (stored before the blinking sequence) is restored. - - The visible result is that tux has executed an even number of blink. */ -#define toggleLeds() (led_backup ^= LED_MK) +#define toggleLeftLed() (leds_buffer ^= LED_L_MK) /** - \brief toggle left led + \brief toggle right led. \ingroup led */ -#define toggleLeftLed() (led_backup ^= LED_L_MK) +#define toggleRightLed() (leds_buffer ^= LED_R_MK) /** - \brief toggle right led + \brief Turn both leds off directly on the I/O port. \ingroup led + + This function is used to switch off the leds when the eyes are closed. + You shouldn't use this function elsewhere as the I/O port will be refreshed + immediately with the leds_buffer value. */ -#define toggleRightLed() (led_backup ^= LED_R_MK) +#define mask_leds() (LED_PT &= ~LED_MK) -#endif +extern void blink_leds(uint8_t cnt, uint8_t pulse_width); +extern void refresh_leds(void); +extern void led_control(void); + +#endif /* _LED_H_ */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/main.c 2007-09-13 09:34:02 UTC (rev 523) @@ -171,17 +171,15 @@ if (ir_delay) ir_delay--; - /* Led blinking */ - if (led_delay) - { - led_delay--; - if (!led_delay) - { - toggleLeds(); - if (--led_blinking_cnt) - led_delay = led_blinking_pw; - } - } + /* Led blinking. */ + led_control(); + /* Refresh the leds. When the eyes are closed, the leds are + * switched off. They'll be refreshed again with the buffered value + * when the eyes will reopen. */ + if (cond_flags.eyes_closed) + mask_leds(); + else + refresh_leds(); } if (t100ms_flag) { @@ -330,12 +328,10 @@ void sleep(void) { - uint8_t led_bak; uint8_t PRR_bak; /* Set power savings configuration. */ cli(); - led_bak = readLeds(); closeIO(); powersave_movements(); stop_spinning(); @@ -358,7 +354,6 @@ /* Re-configure in normal mode. */ PRR = PRR_bak; - setLeds(led_bak); /* restore leds status */ i2cCommunicationInit(); init_movements(); initIO(); Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/parser.c 2007-09-13 09:34:02 UTC (rev 523) @@ -160,7 +160,7 @@ } else if (command[0] == LED_BLINK_CMD) { - blinkLeds(command[1], command[2]); + blink_leds(command[1], command[2]); } else if (command[0] == IR_SEND_RC5_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/standalone.c 2007-09-13 09:34:02 UTC (rev 523) @@ -200,11 +200,6 @@ if (!event_timer) eventTriggering(); - if (cond_flags.eyes_closed) - turnLedsOffbEyes(); - else - setLeds(led_backup); - /* Disable spinning when plugged */ if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) { @@ -237,7 +232,7 @@ /* IR feedback signal */ if (tux_config.ir_feedback) - blinkLeds(2, 4); + blink_leds(2, 4); /* ALT KEYS */ if (alt_mode) |
From: jaguarondi <c2m...@c2...> - 2007-09-13 09:30:59
|
Author: jaguarondi Date: 2007-09-13 11:30:32 +0200 (Thu, 13 Sep 2007) New Revision: 522 Modified: firmware/tuxcore/trunk/motors.c Log: * Slight changes on the comments. Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-13 07:30:10 UTC (rev 521) +++ firmware/tuxcore/trunk/motors.c 2007-09-13 09:30:32 UTC (rev 522) @@ -201,8 +201,8 @@ \brief Blink the eyes \ingroup eyes - \param cnt number of movements before the flippers will stop - \note Any mouth command is cancelled + \param cnt number of movements before the flippers will stop. + \note Any mouth command is cancelled. The eyes will start blinking until 'cnt' movements are executed. A movement is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is @@ -356,10 +356,10 @@ } /** - \brief Move the mouth + \brief Move the mouth. \ingroup mouth - \note Any eye command is cancelled - \param cnt number of movements before the mouth will stop + \note Any eye command is cancelled. + \param cnt number of movements before the mouth will stop. The mouth will start blinking until 'cnt' movements are executed. A movement is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is @@ -373,7 +373,7 @@ } /** - \brief Open the mouth + \brief Open the mouth. \ingroup mouth Open the mouth if they are closed. @@ -385,7 +385,7 @@ } /** - \brief Close the mouth + \brief Close the mouth. \ingroup mouth Close the mouth if they are opened. @@ -397,7 +397,7 @@ } /** - \brief Mouth position interrupt + \brief Mouth position interrupt. This interrupt stops the mouth when the desired number of movements have been executed. In order to stop the mouth quickly and block the motor, we @@ -473,10 +473,10 @@ } /** - \brief Start waving the flippers up and down + \brief Start waving the flippers up and down. \ingroup flippers - \param cnt number of movements before the flippers will stop - \param pwm pwm value between 1 (slow) and 5 (fast) + \param cnt number of movements before the flippers will stop. + \param pwm pwm value between 1 (slow) and 5 (fast). The flippers will start waving until 'cnt' movements have been executed. A movement is raising or lowering the flippers. 'cnt' can be up to 256. If @@ -495,7 +495,7 @@ } /** - \brief Reset flippers + \brief Reset flippers. \ingroup flippers This function resets the flippers position. flippers_timer is used to @@ -513,7 +513,7 @@ } /** - \brief Raise flippers + \brief Raise flippers. \ingroup flippers The condition to raise the flippers is that they aren't already in the upper @@ -539,7 +539,7 @@ } /** - \brief Lower flippers + \brief Lower flippers. \ingroup flippers The condition to lower the flippers is that they aren't already in the lower @@ -555,7 +555,7 @@ } /** - \brief Flippers position interrupt + \brief Flippers position interrupt. This interrupt stops the flippers when the desired number of movements have been executed. In order to stop the flippers quickly and block the motor, we @@ -593,10 +593,10 @@ flippers_timer = 0; flippers_revious_timer = 0; } - else /* continue */ + else { /* Unknow position, execute another movement to determine - * it */ + * it. */ flippers_revious_timer = flippers_timer; flippers_timer = FLIP_TIMER_INIT; return; @@ -640,8 +640,9 @@ } /** - \brief Spin left for the \c angle amount - \param angle Angle to turn, in 90° unit + \brief Spin left for the \c angle amount. + \param angle Angle to turn, in 90° unit. + \param pwm PWM value assigned to the spinning. \ingroup spin */ void spin_left(uint8_t angle, uint8_t pwm) @@ -660,8 +661,9 @@ } /** - \brief Spin right for the \c angle amount - \param angle Angle to turn, in 90° unit + \brief Spin right for the \c angle amount. + \param angle Angle to turn, in 90° unit. + \param pwm PWM value assigned to the spinning. \ingroup spin */ void spin_right(uint8_t angle, uint8_t pwm) @@ -679,7 +681,7 @@ spin_PWM_mask |= MOT_SPIN_R_MK; } /** - \brief Spin position interrupt + \brief Spin position interrupt. This interrupt stops the spinning motor when the desired number of movements have been executed. |
From: jaguarondi <c2m...@c2...> - 2007-09-13 07:30:11
|
Author: jaguarondi Date: 2007-09-13 09:30:10 +0200 (Thu, 13 Sep 2007) New Revision: 521 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Reorganized the spin functions. * This is the last cleanup of this module for now. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-13 06:32:43 UTC (rev 520) +++ firmware/tuxcore/trunk/main.c 2007-09-13 07:30:10 UTC (rev 521) @@ -338,7 +338,7 @@ led_bak = readLeds(); closeIO(); powersave_movements(); - stopSpin(); + stop_spinning(); stop_mouth(); stop_flippers(); PRR_bak = PRR; Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-13 06:32:43 UTC (rev 520) +++ firmware/tuxcore/trunk/motors.c 2007-09-13 07:30:10 UTC (rev 521) @@ -88,11 +88,20 @@ uint8_t spin_move_counter; /** PWM applied on the spinning motor. */ uint8_t spin_PWM = 5; +/** Direction type for spinning. */ +enum spin_direction +{ + LEFT, + RIGHT, +}; /** Spinning direction */ static uint8_t spin_direction; -/** PWM mask register applied on the port on a regular basis. */ +/** PWM mask register applied on the motor port on a regular basis to drive the + * flippers and spinning. */ uint8_t portB_PWM_mask; +#define flippers_PWMMask portB_PWM_mask +#define spin_PWM_mask portB_PWM_mask /** * \name Module configuration @@ -125,13 +134,14 @@ /* Enable 'Pin change interrupt 2' for the eyes position switches */ PCMSK2 = PSW_EYES_C_MK; PCICR |= _BV(PCIE2); - /* Enable 'INT1 interrupt' for the spin position switch in falling edge mode */ + /* Enable 'INT1 interrupt' for the spin position switch in falling edge + * mode */ EICRA |= _BV(ISC11); EIMSK |= _BV(INT1); } /** - \brief Initializes the position switches for minimal power consumption. + \brief Initialize the position switches for minimal power consumption. In normal mode, all pins have internal pull-up and each switch shorts the pin low. So in power save mode, we must set all pins as strong low. */ @@ -215,18 +225,18 @@ behavior in all states: - opened - no movement is required; - closed - just one movement is required to open the eyes; - - unknown - two movements are required as the eyes can only be stopped when - they are closing; a spring is used to open them. + - unknown - two movements are required as the eyes can only be stopped + when they are closing; a spring is used to open them. - We need to differentiate when the eyes are opened and stopped, and when + We need to differentiate when the eyes are opened and stopped, and when they are opened but blinking. In the first case, we don't need to do anything. But in the second, we need to stop the eyes in the open position. To stop the eyes in the open state by sending the open_eyes_cmd when they're blinking, eyes_move_counter is initalised but the blink_eyes function isn't called. - If the motor is running, it will execute two movements before stopping. If the - motor isn't switched on, nothing happens but eyes_move_counter is set to a - non zero value though they are no movements happening. + If the motor is running, it will execute two movements before stopping. If + the motor isn't switched on, nothing happens but eyes_move_counter is set to + a non zero value though they are no movements happening. \note The computer side (API, daemon) must be aware that the eyes_move_counter can be non zero with the motor switched off. @@ -464,8 +474,8 @@ /** \brief Start waving the flippers up and down - \ingroup flippers - \param cnt number of movements before the flippers will stop + \ingroup flippers + \param cnt number of movements before the flippers will stop \param pwm pwm value between 1 (slow) and 5 (fast) The flippers will start waving until 'cnt' movements have been executed. A @@ -502,9 +512,8 @@ wave_flippers(2, 5); } - /** - \brief Raise flippers + \brief Raise flippers \ingroup flippers The condition to raise the flippers is that they aren't already in the upper @@ -529,7 +538,6 @@ wave_flippers(1,5); } - /** \brief Lower flippers \ingroup flippers @@ -613,42 +621,22 @@ /*! @} */ /** - \brief Spin position interrupt - \ingroup spin - - This interrupt stops the spinning motor when the desired number of movements - have been executed. - - The switch is pushed each 90 degrees. We set the interrupt in falling edge - mode so there's no interrupt generated when the switch is released. - */ -ISR(SIG_INTERRUPT1) + * \name Spinning functions + * @{ */ +/** \brief Low level access to stop the spinning motor. */ +static inline void stop_spin_motor(void) __attribute__ ((always_inline)); +void stop_spin_motor(void) { - if (spin_move_counter) - { - spin_move_counter--; - - if (!spin_move_counter) - { - spin_PWM_mask &= ~MOT_SPIN_MK; - stopSpinMot(); - spin_stop_delay = SPIN_BRAKING_DLY; - if (spin_direction == LEFT) - spin_PWM_mask |= MOT_SPIN_R_MK; - else - spin_PWM_mask |= MOT_SPIN_L_MK; - } - } + spin_PWM_mask &= ~MOT_SPIN_MK; + MOT_SPIN_PT &= ~MOT_SPIN_MK; } - /** - \brief Stop the spinning motor - \ingroup primitives + \brief Stop spinning immediately. + \ingroup spin */ -void stopSpin(void) +void stop_spinning(void) { - spin_PWM_mask &= ~MOT_SPIN_MK; - stopSpinMot(); + stop_spin_motor(); } /** @@ -656,14 +644,14 @@ \param angle Angle to turn, in 90° unit \ingroup spin */ -void spinLeft(uint8_t angle, uint8_t pwm) +void spin_left(uint8_t angle, uint8_t pwm) { - /* Check if direction is changing and if pos. switch isn't push. Then, - * increment angle value to prevent too short rotation */ - if (spin_direction == RIGHT && (PSW_SPIN_PIN & PSW_SPIN_MK)) - { - angle += 1; - } + /* If the rotation direction is changing and we are not stopped exactly on + * the switch (position switch not pressed), we need to increment the angle + * value to prevent counting the first switch detection that will happen as + * soon as the rotation starts. */ + if ((spin_direction == RIGHT) && (PSW_SPIN_PIN & PSW_SPIN_MK)) + angle++; spin_direction = LEFT; spin_move_counter = angle; spin_PWM = pwm; @@ -676,13 +664,13 @@ \param angle Angle to turn, in 90° unit \ingroup spin */ -void spinRight(uint8_t angle, uint8_t pwm) +void spin_right(uint8_t angle, uint8_t pwm) { /* If the rotation direction is changing and we are not stopped exactly on * the switch (position switch not pressed), we need to increment the angle * value to prevent counting the first switch detection that will happen as * soon as the rotation starts. */ - if (spin_direction == LEFT && (PSW_SPIN_PIN & PSW_SPIN_MK)) + if ((spin_direction == LEFT) && (PSW_SPIN_PIN & PSW_SPIN_MK)) angle++; spin_direction = RIGHT; spin_move_counter = angle; @@ -690,10 +678,38 @@ spin_PWM_mask &= ~MOT_SPIN_L_MK; spin_PWM_mask |= MOT_SPIN_R_MK; } +/** + \brief Spin position interrupt + This interrupt stops the spinning motor when the desired number of movements + have been executed. + The switch is pushed each 90 degrees. We set the interrupt in falling edge + mode so there's no interrupt generated when the switch is released. + */ +ISR(SIG_INTERRUPT1) +{ + if (spin_move_counter) + { + spin_move_counter--; + + if (!spin_move_counter) + { + spin_PWM_mask &= ~MOT_SPIN_MK; + stop_spin_motor(); + spin_stop_delay = SPIN_BRAKING_DLY; + if (spin_direction == LEFT) + spin_PWM_mask |= MOT_SPIN_R_MK; + else + spin_PWM_mask |= MOT_SPIN_L_MK; + } + } +} +/*! @} */ + /** - \brief Control the PWM of the spinning & flippers and all motors braking. + \brief Periodic routine that controls the PWM of the spinning, flippers and + all motors braking. \fn motor_control \ingroup movements @@ -725,7 +741,7 @@ if (pwm_tim++ == PWM_PERIOD) { pwm_tim = 0; - PORTB |= portB_PWM_mask; /* spin and flippers */ + PORTB |= portB_PWM_mask; /* spin and flippers */ } /* Flippers timer to stop the flippers in any position */ @@ -775,7 +791,7 @@ spin_stop_delay--; if (!spin_stop_delay) { - stopSpinMot(); + stop_spin_motor(); } } } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-13 06:32:43 UTC (rev 520) +++ firmware/tuxcore/trunk/motors.h 2007-09-13 07:30:10 UTC (rev 521) @@ -59,14 +59,6 @@ #include "hardware.h" -#define flippers_PWMMask portB_PWM_mask -#define spin_PWM_mask portB_PWM_mask - -enum mouth_pos_s -{ OPEN, CLOSE, UNDEFINED }; -enum spin_direction -{ LEFT, RIGHT }; - /** \ingroup eyes */ extern uint8_t eyes_move_counter; /** \ingroup mouth */ @@ -76,9 +68,6 @@ /** \ingroup spin */ extern uint8_t spin_move_counter, spin_PWM; -/* pwm mask registers */ -extern uint8_t portB_PWM_mask; - /* * Module configuration */ @@ -102,38 +91,13 @@ extern void wave_flippers(uint8_t cnt, uint8_t pwm); extern void lower_flippers(void); extern void raise_flippers(void); -void stopSpin(void); -void spinLeft(uint8_t angle, uint8_t pwm); -void spinRight(uint8_t angle, uint8_t pwm); +extern void stop_spinning(void); +extern void spin_left(uint8_t angle, uint8_t pwm); +extern void spin_right(uint8_t angle, uint8_t pwm); /* - * Macro and inline functions definition + * Control */ - -/** - \brief Stop the spinning motor - \ingroup primitives - */ -static inline void stopSpinMot(void) __attribute__ ((always_inline)); -void stopSpinMot(void) -{ - spin_PWM_mask &= ~MOT_SPIN_MK; - MOT_SPIN_PT &= ~MOT_SPIN_MK; -} -/** - \brief Start spinning to the left - \ingroup primitives - */ -#define runSpinLeft() (MOT_SPIN_R_PT &= ~MOT_SPIN_R_MK); \ - (MOT_SPIN_L_PT |= MOT_SPIN_L_MK) - -/** - \brief Start spinning to the right - \ingroup primitives - */ -#define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); \ - (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) - extern void motor_control(void); #endif /* _MOTORS_H_ */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-13 06:32:43 UTC (rev 520) +++ firmware/tuxcore/trunk/parser.c 2007-09-13 07:30:10 UTC (rev 521) @@ -122,15 +122,15 @@ } else if (command[0] == SPIN_LEFT_CMD) { - spinLeft(command[1], command[2]); + spin_left(command[1], command[2]); } else if (command[0] == SPIN_RIGHT_CMD) { - spinRight(command[1], command[2]); + spin_right(command[1], command[2]); } else if (command[0] == STOP_SPIN_CMD) { - stopSpin(); + stop_spinning(); } /* Leds */ Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-13 06:32:43 UTC (rev 520) +++ firmware/tuxcore/trunk/standalone.c 2007-09-13 07:30:10 UTC (rev 521) @@ -208,7 +208,7 @@ /* Disable spinning when plugged */ if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) { - stopSpin(); /* flush the spinning commands */ + stop_spinning(); /* flush the spinning commands */ spin_move_counter = 0; } @@ -288,13 +288,13 @@ wave_flippers(mov_nbr, 5); break; case K_LEFT: - spinLeft(mov_nbr, spin_PWM); + spin_left(mov_nbr, spin_PWM); break; case K_RIGHT: - spinRight(mov_nbr, spin_PWM); + spin_right(mov_nbr, spin_PWM); break; case K_STOP: - stopSpin(); + stop_spinning(); stop_flippers(); stop_mouth(); break; |
From: jaguarondi <c2m...@c2...> - 2007-09-13 06:33:14
|
Author: jaguarondi Date: 2007-09-13 08:32:43 +0200 (Thu, 13 Sep 2007) New Revision: 520 Modified: firmware/tuxcore/trunk/hardware.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h Log: * Merged initialization of position switches, motors and interrupts in the same init function. * Cleanup. Modified: firmware/tuxcore/trunk/hardware.h =================================================================== --- firmware/tuxcore/trunk/hardware.h 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/hardware.h 2007-09-13 06:32:43 UTC (rev 520) @@ -71,13 +71,13 @@ /** Spin switch DDR. */ #define PSW_SPIN_DDR DDRD /** Flippers position switch PIN. */ -#define PSW_WINGS_PIN PINC +#define PSW_FLIPPERS_PIN PINC /** Flippers position switch PORT. */ -#define PSW_WINGS_PT PORTC +#define PSW_FLIPPERS_PT PORTC /** Flippers position switch DDR. */ -#define PSW_WINGS_DDR DDRC +#define PSW_FLIPPERS_DDR DDRC /** Flippers position switch mask. */ -#define PSW_WINGS_MK _BV(PC1) +#define PSW_FLIPPERS_MK _BV(PC1) /** Mouth position switches PIN. */ #define PSW_MOUTH_PIN PINB /** Mouth position switches PORT. */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/main.c 2007-09-13 06:32:43 UTC (rev 520) @@ -140,9 +140,8 @@ */ int main(void) { - /* I/O initialization */ - initPosSwitches(); - initMotors(); + /* Initialization */ + init_movements(); initIR(); main_tick_init(); initIO(); @@ -243,23 +242,6 @@ /* Set output for Led's */ LED_DDR |= LED_MK; - /* Enable 'Pin change interrupt 0' for mouth position switches */ - PCMSK0 = PSW_MOUTH_MK; - PCICR |= _BV(PCIE0); - - /* Enable 'Pin change interrupt 1' for wings position switch */ - PCMSK1 = PSW_WINGS_MK; - PCICR |= _BV(PCIE1); - - /* Enable 'Pin change interrupt 2' for eyes position switches */ - PCMSK2 = PSW_EYES_C_MK; - PCICR |= _BV(PCIE2); - - /* Enable 'INT1 interrupt' for spin position switch in falling edge mode - * and 'INT0 interrupt' for IR receiver in falling edge mode */ - EICRA = _BV(ISC11); // | _BV(ISC01); - EIMSK = _BV(INT1); // | _BV(INT0); - /* Enable ADC, select ADC clock = F_CPU / 128 (i.e. 16 Hz) * Single conversion mode */ @@ -355,7 +337,7 @@ cli(); led_bak = readLeds(); closeIO(); - closePosSwitches(); + powersave_movements(); stopSpin(); stop_mouth(); stop_flippers(); @@ -378,7 +360,7 @@ PRR = PRR_bak; setLeds(led_bak); /* restore leds status */ i2cCommunicationInit(); - initPosSwitches(); + init_movements(); initIO(); /* Trigger the post-sleep event */ Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/motors.c 2007-09-13 06:32:43 UTC (rev 520) @@ -101,30 +101,44 @@ * @{ */ /** \ingroup movements */ /** - \brief Initialize the position switches for normal operation. - Initialize all I/O of the position switches as input with internal pull-up. + \brief Initialize all I/O for normal movement operation. + This function sets all motor I/O as output, initializes all I/O of the + position switches as input with internal pull-up and enables all + corresponding interrupts. */ -void initPosSwitches(void) +void init_movements(void) { - PSW_WINGS_DDR &= ~PSW_WINGS_MK; - PSW_WINGS_PT |= PSW_WINGS_MK; + PSW_FLIPPERS_DDR &= ~PSW_FLIPPERS_MK; + PSW_FLIPPERS_PT |= PSW_FLIPPERS_MK; PSW_EYES_DDR &= ~PSW_EYES_MK; PSW_EYES_PT |= PSW_EYES_MK; PSW_MOUTH_DDR &= ~PSW_MOUTH_MK; PSW_MOUTH_PT |= PSW_MOUTH_MK; PSW_SPIN_DDR &= ~PSW_SPIN_MK; PSW_SPIN_PT |= PSW_SPIN_MK; + /* Enable 'Pin change interrupt 0' for the mouth position switches */ + PCMSK0 = PSW_MOUTH_MK; + PCICR |= _BV(PCIE0); + /* Enable 'Pin change interrupt 1' for the flippers position switch */ + PCMSK1 = PSW_FLIPPERS_MK; + PCICR |= _BV(PCIE1); + /* Enable 'Pin change interrupt 2' for the eyes position switches */ + PCMSK2 = PSW_EYES_C_MK; + PCICR |= _BV(PCIE2); + /* Enable 'INT1 interrupt' for the spin position switch in falling edge mode */ + EICRA |= _BV(ISC11); + EIMSK |= _BV(INT1); } /** \brief Initializes the position switches for minimal power consumption. - All pins have internal pull-up and the switch shorts the pin low so to avoid - undefined states, we must set all pins as strong low. + In normal mode, all pins have internal pull-up and each switch shorts the + pin low. So in power save mode, we must set all pins as strong low. */ -void closePosSwitches(void) +void powersave_movements(void) { - PSW_WINGS_PT &= ~PSW_WINGS_MK; - PSW_WINGS_DDR |= PSW_WINGS_MK; + PSW_FLIPPERS_PT &= ~PSW_FLIPPERS_MK; + PSW_FLIPPERS_DDR |= PSW_FLIPPERS_MK; PSW_EYES_PT &= ~PSW_EYES_MK; PSW_EYES_DDR |= PSW_EYES_MK; PSW_MOUTH_PT &= ~PSW_MOUTH_MK; @@ -132,19 +146,6 @@ PSW_SPIN_PT &= ~PSW_SPIN_MK; PSW_SPIN_DDR |= PSW_SPIN_MK; } - -/** - \brief Initalizes the motors for normal operation. - This sets all motor I/O as output - */ -void initMotors(void) -{ - MOT_EYES_DDR |= MOT_EYES_MK; - MOT_MOUTH_DDR |= MOT_MOUTH_MK; - MOT_FLIPPERS_FW_DDR |= MOT_FLIPPERS_FW_MK; - MOT_FLIPPERS_BW_DDR |= MOT_FLIPPERS_BW_MK; - MOT_SPIN_DDR |= MOT_SPIN_MK; -} /*! @} */ /** @@ -546,7 +547,7 @@ } /** - \brief Wings position interrupt + \brief Flippers position interrupt This interrupt stops the flippers when the desired number of movements have been executed. In order to stop the flippers quickly and block the motor, we @@ -562,7 +563,7 @@ ISR(SIG_PIN_CHANGE1) { /* We only count when the switch is pushed, not released. */ - if (~PSW_WINGS_PIN & PSW_WINGS_MK) + if (~PSW_FLIPPERS_PIN & PSW_FLIPPERS_MK) { /* This test prevents the toggle when the flippers are pushed. The * flippers motor must be switched on (flippers_PWM <> 0) to toggle the Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 14:53:05 UTC (rev 519) +++ firmware/tuxcore/trunk/motors.h 2007-09-13 06:32:43 UTC (rev 520) @@ -82,8 +82,8 @@ /* * Module configuration */ -void initPosSwitches(void); -void closePosSwitches(void); +void init_movements(void); +void powersave_movements(void); void initMotors(void); /* |
From: jaguarondi <c2m...@c2...> - 2007-09-12 14:53:32
|
Author: jaguarondi Date: 2007-09-12 16:53:05 +0200 (Wed, 12 Sep 2007) New Revision: 519 Modified: firmware/tuxcore/trunk/hardware.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Reorganized the flippers functions. Modified: firmware/tuxcore/trunk/hardware.h =================================================================== --- firmware/tuxcore/trunk/hardware.h 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/hardware.h 2007-09-12 14:53:05 UTC (rev 519) @@ -202,17 +202,17 @@ * the motor driver won't burn and the motor will simply turn in one direction. * @{ */ /** Flippers backward motor PORT. */ -#define MOT_WINGS_BW_PT PORTD +#define MOT_FLIPPERS_BW_PT PORTD /** Flippers backward motor DDR. */ -#define MOT_WINGS_BW_DDR DDRD +#define MOT_FLIPPERS_BW_DDR DDRD /** Flippers backward motor mask. */ -#define MOT_WINGS_BW_MK _BV(PD4) +#define MOT_FLIPPERS_BW_MK _BV(PD4) /** Flippers forward motor PORT. */ -#define MOT_WINGS_FW_PT PORTB +#define MOT_FLIPPERS_FW_PT PORTB /** Flippers forward motor DDR. */ -#define MOT_WINGS_FW_DDR DDRB +#define MOT_FLIPPERS_FW_DDR DDRB /** Flippers forward motor mask. */ -#define MOT_WINGS_FW_MK _BV(PB0) +#define MOT_FLIPPERS_FW_MK _BV(PB0) /** Mouth motor PORT. */ #define MOT_MOUTH_PT PORTD /** Mouth motor DDR. */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/main.c 2007-09-12 14:53:05 UTC (rev 519) @@ -358,7 +358,7 @@ closePosSwitches(); stopSpin(); stop_mouth(); - stopWings(); + stop_flippers(); PRR_bak = PRR; PRR = _BV(PRTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRADC); Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 14:53:05 UTC (rev 519) @@ -141,8 +141,8 @@ { MOT_EYES_DDR |= MOT_EYES_MK; MOT_MOUTH_DDR |= MOT_MOUTH_MK; - MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; - MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; + MOT_FLIPPERS_FW_DDR |= MOT_FLIPPERS_FW_MK; + MOT_FLIPPERS_BW_DDR |= MOT_FLIPPERS_BW_MK; MOT_SPIN_DDR |= MOT_SPIN_MK; } /*! @} */ @@ -250,7 +250,7 @@ Close the eyes if they are opened. When the close_eyes_cmd is received, if the eyes are closed, nothing - happens. But, when the eyes are blinking, this command must stop the eyes + happens. But, when the eyes are blinking, this command must stop the eyes in the closed position. To do this, eyes_move_counter is initialised, but the blink_eyes function isn't called. If the command is received when the eyes are blinking, two movements are executed before the motor is stopped. @@ -421,9 +421,133 @@ /*! @} */ /** - \brief Wings position interrupt + * \name Flippers functions + * @{ */ +/** \brief Low level access to stop the flippers motor. */ +static inline void stop_flippers_motor(void) __attribute__ ((always_inline)); +void stop_flippers_motor(void) +{ + flippers_PWMMask &= ~MOT_FLIPPERS_FW_MK; + MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; + MOT_FLIPPERS_FW_PT &= ~MOT_FLIPPERS_FW_MK; +} + +/** \brief Low level access to start the flippers motor. */ +static inline void run_flippers_motor(void) __attribute__ ((always_inline)); +void run_flippers_motor(void) +{ + MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; + MOT_FLIPPERS_FW_PT |= MOT_FLIPPERS_FW_MK; +} + +/** \brief Low level access to invert the flippers motor. */ +static inline void invert_flippers_motor(void) __attribute__ ((always_inline)); +void invert_flippers_motor(void) +{ + MOT_FLIPPERS_FW_PT &= ~MOT_FLIPPERS_FW_MK; + MOT_FLIPPERS_BW_PT |= MOT_FLIPPERS_BW_MK; +} + +/** + \brief Stop the flippers immediately. \ingroup flippers + The flippers motor will stop immediately, even if the flippers are not in + the up or down position. Use raise_flippers or lower_flippers instead if you + want to stop them in a given position. + */ +void stop_flippers(void) +{ + stop_flippers_motor(); +} + +/** + \brief Start waving the flippers up and down + \ingroup flippers + \param cnt number of movements before the flippers will stop + \param pwm pwm value between 1 (slow) and 5 (fast) + + The flippers will start waving until 'cnt' movements have been executed. A + movement is raising or lowering the flippers. 'cnt' can be up to 256. If + 'cnt' is null, waving will run indefinitely. pwm can be used to change the + speed of the motor although it's more directed to the power delivered to the + motor. It's possible that the smallest PWM values won't deliver enough power + to even start the motor. + */ +void wave_flippers(uint8_t cnt, uint8_t pwm) +{ + flippers_move_counter = cnt; + flippers_PWM = pwm; + flippers_stop_delay = 0; + MOT_FLIPPERS_BW_PT &= ~MOT_FLIPPERS_BW_MK; + flippers_PWMMask |= MOT_FLIPPERS_FW_MK; +} + +/** + \brief Reset flippers + \ingroup flippers + + This function resets the flippers position. flippers_timer is used to + determine the flippers positions. Times needed to raise or lower the + flippers are not the same. If 2 movements are executed (up - down - up), + flippers_timer allows to determine the shorter time, and get if the flippers + are up or low at the end. + */ +void reset_flippers(void) +{ + flippers_timer = FLIP_TIMER_INIT; + /* The first movement is to be sure the timer doesn't start counting from + * any unknown postion and that the motors are in regime. */ + wave_flippers(2, 5); +} + + +/** + \brief Raise flippers + \ingroup flippers + + The condition to raise the flippers is that they aren't already in the upper + position. If this condition is respected, a single movement is executed by + the wave_flippers function. + + If the flippers were in the higher position and have been lowered manually, + the flippers can't be raised directly. They must pass by the low position + (lower_flippers function) before being able to be raised. + + \note If the flippers are in a medium position, it's possible that they'll + first move low before raising. Implementing conditions to be able to raise + the flippers immeditely is not trivial and increases the code size too much + compared to the benefit. This would require changing the motor direction + when two consecutive commands are identical. Furthermore the absolute + position when the motor is switched off is important. So, the braking delay + couldn't be the same in both directions. + */ +void raise_flippers(void) +{ + if (gStatus.pos == 0) + wave_flippers(1,5); +} + + +/** + \brief Lower flippers + \ingroup flippers + + The condition to lower the flippers is that they aren't already in the lower + position. If this condition is respected, a single movement is executed by + the wave_flippers function. + + \note Has the same limitations as raise_flippers. + */ +void lower_flippers(void) +{ + if (gStatus.pos == 1) + wave_flippers(1,5); +} + +/** + \brief Wings position interrupt + This interrupt stops the flippers when the desired number of movements have been executed. In order to stop the flippers quickly and block the motor, we need to invert the motor for a small duration. @@ -431,7 +555,7 @@ When the signal is switching from high to low (switch pushed), the number of movements is decreased and when null, the flippers motor is switched backwards and will be stopped by timer0 overflow after the - FLIPPERS_BRAKING_DLY period. So we only count when the switch is pushed but + FLIPPERS_BRAKING_DLY period. So we only count when the switch is pushed but not when it is released. As the interrupt triggers on a signal change, we need to suppress the release interrupt. */ @@ -478,13 +602,14 @@ flippers_move_counter--; if (!flippers_move_counter) { - stopWings(); - runWingsBw(); + stop_flippers_motor(); + invert_flippers_motor(); flippers_stop_delay = FLIPPERS_BRAKING_DLY; } } } } +/*! @} */ /** \brief Spin position interrupt @@ -516,96 +641,6 @@ } /** - \brief Start waving the flippers up and down \ingroup flippers \param cnt - number of movements before the flippers will stop \param pwm pwm value - between 1 (slow) and 5 (fast) - - The flippers will start waving until 'cnt' movements are executed. A - movement is raising or lowering the flippers. 'cnt' can be up to 256. If - 'cnt' is null, waving will run indefinitely. pwm can be used to change the - speed of the motor although it's more directed to the power delivered to the - motor. It's possible that the smallest values won't deliver enough power to - even start the motor. - */ -void waveWings(uint8_t cnt, uint8_t pwm) -{ - flippers_move_counter = cnt; - flippers_PWM = pwm; - flippers_stop_delay = 0; - MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; - flippers_PWMMask |= MOT_WINGS_FW_MK; -} -/** - \brief Reset flippers - \ingroup flippers - - This function reset the flippers position. flippers_timer is used to - determine the flippers positions. Times needed to raise or lower the - flippers are not the same. - If two movements are executed, flippers_timer allow to determine the shorter - time, and then to know if flippers are up or low. - */ - -void resetWings(void) -{ - flippers_timer = FLIP_TIMER_INIT; - /* the first movement is to be sure the timer doesn't start counting from - * any unknown poistion and that the motors are in regime */ - waveWings(2, 5); -} - - -/** - \brief Raise flippers \ingroup flippers - - The condition to raise the flippers is that they aren't already in the upper - position. If this condition is respected, a single movement is executed by - the waveWings function. - - If the flippers was in the higher position and has been lowered manually, - the flippers can't be raised directly. They must pass by the low position - (lowerWings function) before being able to be raised. - - \note Implement conditions to be able to raise flippers without pass by the - low position increase code size and complicate the code. This - implementation need to toggle the motor sense when two or more same commands - are repeated. The mecanical position when the motor is switched off is - important. So, the braking delay couldn't be the same in both sense. - */ - -void raiseWings(void) -{ - if (gStatus.pos == 0) - waveWings(1,5); -} - - -/** - \brief Lower flippers - \ingroup flippers - - The condition to lower the flippers is that they aren't already in the lower - position. If this condition is respected, a single movement is executed by - the waveWings function. - - If the flippers was in the lower position and has been raised manually, the - flippers can't be lowered directly. They must pass by the high position - (raiseWings function) before being able to be lowered. - - \note Implement conditions to be able to lower flippers without pass by the - high position increase code size and complicate the code. This - implementation need to toggle the motor sense when two or more same commands - are repeated. The mecanical position when the motor is switched off is - important. So, the braking delay couldn't be the same in both sense. - - */ -void lowerWings(void) -{ - if (gStatus.pos == 1) - waveWings(1,5); -} - -/** \brief Stop the spinning motor \ingroup primitives */ @@ -675,7 +710,7 @@ /* Flippers PWM * Pulse is stopped here */ if (pwm_tim == flippers_PWM) - MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; + MOT_FLIPPERS_FW_PT &= ~MOT_FLIPPERS_FW_MK; /* Spin PWM * Pulse is stopped here */ @@ -698,7 +733,7 @@ flippers_timer--; if (!flippers_timer) { - stopWings(); + stop_flippers_motor(); } } @@ -708,7 +743,7 @@ flippers_stop_delay--; if (!flippers_stop_delay) { - stopWings(); + stop_flippers_motor(); flippers_PWM = 0; } } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 14:53:05 UTC (rev 519) @@ -97,10 +97,11 @@ extern void move_mouth(uint8_t cnt); extern void open_mouth(void); extern void close_mouth(void); -void resetWings(void); -void waveWings(uint8_t cnt, uint8_t pwm); -void lowerWings(void); -void raiseWings(void); +extern void stop_flippers(void); +extern void reset_flippers(void); +extern void wave_flippers(uint8_t cnt, uint8_t pwm); +extern void lower_flippers(void); +extern void raise_flippers(void); void stopSpin(void); void spinLeft(uint8_t angle, uint8_t pwm); void spinRight(uint8_t angle, uint8_t pwm); @@ -109,31 +110,7 @@ * Macro and inline functions definition */ - /** - \brief Stop the flippers motor - \ingroup flippers - */ -static inline void stopWings(void) __attribute__ ((always_inline)); -void stopWings(void) -{ - flippers_PWMMask &= ~MOT_WINGS_FW_MK; - MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; - MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; -} - -/** - \brief Start wing motor backwards - \ingroup flippers - - Used to brake the flippers motor only - */ -#define runWingsFw() {(MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK); \ - (MOT_WINGS_FW_PT |= MOT_WINGS_FW_MK);} -#define runWingsBw() {(MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK); \ - (MOT_WINGS_BW_PT |= MOT_WINGS_BW_MK);} - -/** \brief Stop the spinning motor \ingroup primitives */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/parser.c 2007-09-12 14:53:05 UTC (rev 519) @@ -102,23 +102,23 @@ } else if (command[0] == WAVE_WINGS_CMD) { - waveWings(command[1], command[2]); + wave_flippers(command[1], command[2]); } else if (command[0] == RAISE_WINGS_CMD) { - raiseWings(); + raise_flippers(); } else if (command[0] == LOWER_WINGS_CMD) { - lowerWings(); + lower_flippers(); } else if (command[0] == RESET_WINGS_CMD) { - resetWings(); + reset_flippers(); } else if (command[0] == STOP_WINGS_CMD) { - stopWings(); + stop_flippers(); } else if (command[0] == SPIN_LEFT_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-12 14:20:13 UTC (rev 518) +++ firmware/tuxcore/trunk/standalone.c 2007-09-12 14:53:05 UTC (rev 519) @@ -285,7 +285,7 @@ move_mouth(mov_nbr); break; case K_DOWN: - waveWings(mov_nbr, 5); + wave_flippers(mov_nbr, 5); break; case K_LEFT: spinLeft(mov_nbr, spin_PWM); @@ -295,7 +295,7 @@ break; case K_STOP: stopSpin(); - stopWings(); + stop_flippers(); stop_mouth(); break; case K_MUTE: |
From: jaguarondi <c2m...@c2...> - 2007-09-12 14:20:22
|
Author: jaguarondi Date: 2007-09-12 16:20:13 +0200 (Wed, 12 Sep 2007) New Revision: 518 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Reorganised the mouth functions. * Some more cleanup and comments. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/main.c 2007-09-12 14:20:13 UTC (rev 518) @@ -357,7 +357,7 @@ closeIO(); closePosSwitches(); stopSpin(); - stopMouth(); + stop_mouth(); stopWings(); PRR_bak = PRR; PRR = _BV(PRTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRADC); Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 14:20:13 UTC (rev 518) @@ -30,7 +30,7 @@ #include "global.h" #include "motors.h" -/** +/** * \name Braking delays * These functions access the motor I/O port. * @{ */ @@ -94,7 +94,7 @@ /** PWM mask register applied on the port on a regular basis. */ uint8_t portB_PWM_mask; -/** +/** * \name Module configuration * These functions initialize the motors and switches I/O ports for normal and * sleep mode. @@ -147,7 +147,7 @@ } /*! @} */ -/** +/** * \name Eyes functions * @{ */ /** \brief Low level access to stop the eyes motor. */ @@ -161,20 +161,20 @@ static inline void run_eyes_motor(void) __attribute__ ((always_inline)); void run_eyes_motor(void) { - (MOT_EYES_PT &= ~MOT_IEYES_MK); - (MOT_EYES_PT |= MOT_EYES_MK); + MOT_EYES_PT &= ~MOT_IEYES_MK; + MOT_EYES_PT |= MOT_EYES_MK; } /** \brief Low level access to invert the eyes motor. */ static inline void invert_eyes_motor(void) __attribute__ ((always_inline)); void invert_eyes_motor(void) { - (MOT_EYES_PT &= ~MOT_EYES_MK); - (MOT_EYES_PT |= MOT_IEYES_MK); + MOT_EYES_PT &= ~MOT_EYES_MK; + MOT_EYES_PT |= MOT_IEYES_MK; } /** - \brief Stop the eyes + \brief Stop the eyes immediately. \ingroup eyes The eyes motor will stop immediately, even if the eyes are not in the open @@ -205,36 +205,41 @@ } /** - \brief Open the eyes + \brief Open the eyes. \ingroup eyes Open the eyes if they are closed. The eyes can be in three different states and should have a different - behavior in all states. - - Eyes opened - no movement is required. - - Eyes closed - Just one movement is required to open the eyes. - - indeterminated - two movements are required. + behavior in all states: + - opened - no movement is required; + - closed - just one movement is required to open the eyes; + - unknown - two movements are required as the eyes can only be stopped when + they are closing; a spring is used to open them. - To prevent that the motor can be activated when the eyes are opened and to - stop the eyes in the open state by sending the open_eyes_cmd when they're + We need to differentiate when the eyes are opened and stopped, and when + they are opened but blinking. In the first case, we don't need to do + anything. But in the second, we need to stop the eyes in the open position. + To stop the eyes in the open state by sending the open_eyes_cmd when they're blinking, eyes_move_counter is initalised but the blink_eyes function isn't - call. - If the motor is running, it will execute two movements before stop. If the - motor isn't switched on, nothing happens. + called. + If the motor is running, it will execute two movements before stopping. If the + motor isn't switched on, nothing happens but eyes_move_counter is set to a + non zero value though they are no movements happening. - \note XXX The computer side (API, daemon) must know than eyes_move_counter - can be not null with the motor switched off. + \note The computer side (API, daemon) must be aware that the + eyes_move_counter can be non zero with the motor switched off. */ void open_eyes(void) { if ((PSW_EYES_PIN & PSW_EYES_O_MK) && (PSW_EYES_PIN & PSW_EYES_C_MK)) + /* Position unknown. */ blink_eyes(2); - else if (!(PSW_EYES_PIN & PSW_EYES_C_MK)) + /* Eyes are closed. */ blink_eyes(1); - else + /* Eyes are opened but possibly blinking. */ eyes_move_counter = 2; } @@ -247,21 +252,21 @@ When the close_eyes_cmd is received, if the eyes are closed, nothing happens. But, when the eyes are blinking, this command must stop the eyes in the closed position. To do this, eyes_move_counter is initialised, but - the blink_eyes function isn't call. So, if the command is received when the + the blink_eyes function isn't called. If the command is received when the eyes are blinking, two movements are executed before the motor is stopped. */ void close_eyes(void) { if (PSW_EYES_PIN & PSW_EYES_C_MK) + /* Eyes are not closed. */ blink_eyes(1); - else + /* Eyes are closed but possibly blinking. */ eyes_move_counter = 2; } /** \brief Eyes position interrupt - \ingroup eyes This interrupt stops the eyes when the desired number of movements have been executed. In order to stop the eyes quickly and block the motor, we need to @@ -301,9 +306,88 @@ /*! @} */ /** - \brief Mouth position interrupt + * \name Mouth functions + * @{ */ +/** \brief Low level access to stop the mouth motor. */ +static inline void stop_mouth_motor(void) __attribute__ ((always_inline)); +void stop_mouth_motor(void) +{ + MOT_MOUTH_PT &= ~(MOT_MOUTH_MK | MOT_IMOUTH_MK); +} + +/** \brief Low level access to start the mouth motor. */ +static inline void run_mouth_motor(void) __attribute__ ((always_inline)); +void run_mouth_motor(void) +{ + MOT_MOUTH_PT &= ~MOT_IMOUTH_MK; + MOT_MOUTH_PT |= MOT_MOUTH_MK; +} + +/** \brief Low level access to invert the mouth motor. */ +static inline void invert_mouth_motor(void) __attribute__ ((always_inline)); +void invert_mouth_motor(void) +{ + MOT_MOUTH_PT &= ~MOT_MOUTH_MK; + MOT_MOUTH_PT |= MOT_IMOUTH_MK; +} + +/** + \brief Stop the mouth immediately. \ingroup mouth + The mouth motor will stop immediately, even if the mouth is not in the open + or close position. Use open_mouth or close_mouth instead if you want to stop + them in a given position. + */ +void stop_mouth(void) +{ + stop_mouth_motor(); +} + +/** + \brief Move the mouth + \ingroup mouth + \note Any eye command is cancelled + \param cnt number of movements before the mouth will stop + + The mouth will start blinking until 'cnt' movements are executed. A movement + is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is + null, waving will run indefinitely. + */ +void move_mouth(uint8_t cnt) +{ + mouth_move_counter = cnt; + mouth_stop_delay = 0; + run_mouth_motor(); +} + +/** + \brief Open the mouth + \ingroup mouth + + Open the mouth if they are closed. + */ +void open_mouth(void) +{ + if (!(PSW_MOUTH_PIN & PSW_MOUTH_C_MK)) + move_mouth(1); +} + +/** + \brief Close the mouth + \ingroup mouth + + Close the mouth if they are opened. + */ +void close_mouth(void) +{ + if (!(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) + move_mouth(1); +} + +/** + \brief Mouth position interrupt + This interrupt stops the mouth when the desired number of movements have been executed. In order to stop the mouth quickly and block the motor, we need to invert the motor for a small duration. @@ -327,13 +411,14 @@ mouth_move_counter--; if (!mouth_move_counter) { - stopMouth(); - runIMouth(); + stop_mouth_motor(); + invert_mouth_motor(); mouth_stop_delay = MOUTH_BRAKING_DLY; } } } } +/*! @} */ /** \brief Wings position interrupt @@ -425,7 +510,7 @@ if (spin_direction == LEFT) spin_PWM_mask |= MOT_SPIN_R_MK; else - spin_PWM_mask |= MOT_SPIN_L_MK; + spin_PWM_mask |= MOT_SPIN_L_MK; } } } @@ -453,7 +538,7 @@ /** \brief Reset flippers \ingroup flippers - + This function reset the flippers position. flippers_timer is used to determine the flippers positions. Times needed to raise or lower the flippers are not the same. @@ -472,7 +557,7 @@ /** \brief Raise flippers \ingroup flippers - + The condition to raise the flippers is that they aren't already in the upper position. If this condition is respected, a single movement is executed by the waveWings function. @@ -489,10 +574,10 @@ */ void raiseWings(void) -{ +{ if (gStatus.pos == 0) waveWings(1,5); -} +} /** @@ -506,7 +591,7 @@ If the flippers was in the lower position and has been raised manually, the flippers can't be lowered directly. They must pass by the high position (raiseWings function) before being able to be lowered. - + \note Implement conditions to be able to lower flippers without pass by the high position increase code size and complicate the code. This implementation need to toggle the motor sense when two or more same commands @@ -515,53 +600,12 @@ */ void lowerWings(void) -{ +{ if (gStatus.pos == 1) waveWings(1,5); } /** - \brief Move the mouth - \ingroup mouth - \note Any eye command is cancelled - \param cnt number of movements before the mouth will stop - - The mouth will start blinking until 'cnt' movements are executed. A movement - is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is - null, waving will run indefinitely. - */ -void moveMouth(uint8_t cnt) -{ - mouth_move_counter = cnt; - mouth_stop_delay = 0; - runMouth(); -} - -/** - \brief Open the mouth - \ingroup mouth - - Open the mouth if they are closed. - */ -void openMouth(void) -{ - if (!(PSW_MOUTH_PIN & PSW_MOUTH_C_MK)) - moveMouth(1); -} - -/** - \brief Close the mouth - \ingroup mouth - - Close the mouth if they are opened. - */ -void closeMouth(void) -{ - if (!(PSW_MOUTH_PIN & PSW_MOUTH_O_MK)) - moveMouth(1); -} - -/** \brief Stop the spinning motor \ingroup primitives */ @@ -685,7 +729,7 @@ mouth_stop_delay--; if (!mouth_stop_delay) { - stopMouth(); + stop_mouth_motor(); } } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 14:20:13 UTC (rev 518) @@ -93,9 +93,10 @@ extern void blink_eyes(uint8_t cnt); extern void close_eyes(void); extern void open_eyes(void); -void moveMouth(uint8_t cnt); -void openMouth(void); -void closeMouth(void); +extern void stop_mouth(void); +extern void move_mouth(uint8_t cnt); +extern void open_mouth(void); +extern void close_mouth(void); void resetWings(void); void waveWings(uint8_t cnt, uint8_t pwm); void lowerWings(void); @@ -108,18 +109,8 @@ * Macro and inline functions definition */ -#define stopMouth() (MOT_MOUTH_PT &= ~(MOT_MOUTH_MK | MOT_IMOUTH_MK)) /** - \brief Start the mouth motor - \ingroup primitives - */ -#define runMouth() (MOT_MOUTH_PT &= ~MOT_IMOUTH_MK); \ - (MOT_MOUTH_PT |= MOT_MOUTH_MK) -#define runIMouth() (MOT_MOUTH_PT &= ~MOT_MOUTH_MK);\ - (MOT_MOUTH_PT |= MOT_IMOUTH_MK) - -/** \brief Stop the flippers motor \ingroup flippers */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/parser.c 2007-09-12 14:20:13 UTC (rev 518) @@ -86,19 +86,19 @@ } else if (command[0] == MOVE_MOUTH_CMD) { - moveMouth(command[1]); + move_mouth(command[1]); } else if (command[0] == OPEN_MOUTH_CMD) { - openMouth(); + open_mouth(); } else if (command[0] == CLOSE_MOUTH_CMD) { - closeMouth(); + close_mouth(); } else if (command[0] == STOP_MOUTH_CMD) { - stopMouth(); + stop_mouth(); } else if (command[0] == WAVE_WINGS_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-12 14:07:02 UTC (rev 517) +++ firmware/tuxcore/trunk/standalone.c 2007-09-12 14:20:13 UTC (rev 518) @@ -282,7 +282,7 @@ blink_eyes(mov_nbr); break; case K_OK: - moveMouth(mov_nbr); + move_mouth(mov_nbr); break; case K_DOWN: waveWings(mov_nbr, 5); @@ -296,7 +296,7 @@ case K_STOP: stopSpin(); stopWings(); - stopMouth(); + stop_mouth(); break; case K_MUTE: tux_config.ir_feedback = !tux_config.ir_feedback; |
From: Paul_R <c2m...@c2...> - 2007-09-12 14:07:11
|
Author: Paul_R Date: 2007-09-12 16:07:02 +0200 (Wed, 12 Sep 2007) New Revision: 517 Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c firmware/tuxaudio/branches/audio_cleanup/AT26F004.h firmware/tuxaudio/branches/audio_cleanup/flash.c Log: * Change some function and variable attribute Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-12 12:58:49 UTC (rev 516) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-12 14:07:02 UTC (rev 517) @@ -28,7 +28,7 @@ * \ingroup at26f004 * \brief initialize a table with the sectors adresses values */ -uint8_t sector_adress[11][3] = { +static uint8_t sector_adress[11][3] = { {SECTOR0}, {SECTOR1}, {SECTOR2}, Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-12 12:58:49 UTC (rev 516) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-12 14:07:02 UTC (rev 517) @@ -108,7 +108,6 @@ #define SECTOR9 0x07, 0xA0, 0x00 #define SECTOR10 0x07, 0xC0, 0x00 -extern uint8_t sector_adress[11][3]; /* @} */ Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-12 12:58:49 UTC (rev 516) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-12 14:07:02 UTC (rev 517) @@ -37,7 +37,7 @@ static void soundProgramming(void); static void endProgramming(void); -static void playInit(uint8_t nsound); +static void playInit(uint8_t const nsound); static void playingSound(void); static void stopPlaying(void); @@ -148,7 +148,7 @@ The next index is stored to identify the end of the sound track. */ -void playInit(uint8_t nsound) +static void playInit(uint8_t const nsound) { uint8_t count, i; uint8_t adp1, adp0, sounds_stored; // Address pointer varaible |
From: jaguarondi <c2m...@c2...> - 2007-09-12 12:58:53
|
Author: jaguarondi Date: 2007-09-12 14:58:49 +0200 (Wed, 12 Sep 2007) New Revision: 516 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h Log: * Deleted mouth_pos as it's not going to be used. * Changed low level functions from defines to static inline and moved them to their corresponding group. * Reordered the configuration functions. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 12:39:37 UTC (rev 515) +++ firmware/tuxcore/trunk/main.c 2007-09-12 12:58:49 UTC (rev 516) @@ -187,8 +187,8 @@ if (t100ms_flag) { t100ms_flag = FALSE; - updateStatusFlag = 1; /* XXX to move */ - if (event_timer) /* XXX to move */ + updateStatusFlag = 1; + if (event_timer) { event_timer--; event_manager_flag = 1; Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 12:39:37 UTC (rev 515) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 12:58:49 UTC (rev 516) @@ -55,6 +55,18 @@ * up to down and from down to up. */ #define FLIPPERS_RESETTIMER_HYST 0x10 +/** Number of periods remaining before stopping the eyes. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +static uint8_t eyes_stop_delay; +/** Number of movements remaining before stopping the flippers. */ +uint8_t eyes_move_counter; +/** Number of periods remaining before stopping the mouth. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +static uint8_t mouth_stop_delay; +/** Number of movements remaining before stopping the mouth. */ +uint8_t mouth_move_counter; /** Number of periods remaining before stopping the flippers. * Normally used when braking, to stop the motor after a short period of * inversion. */ @@ -68,18 +80,6 @@ uint8_t flippers_timer; /** Period taken by the previous movement of the flippers. */ uint8_t flippers_revious_timer; -/** Number of periods remaining before stopping the eyes. - * Normally used when braking, to stop the motor after a short period of - * inversion. */ -static uint8_t eyes_stop_delay; -/** Number of movements remaining before stopping the flippers. */ -uint8_t eyes_move_counter; -/** Number of periods remaining before stopping the mouth. - * Normally used when braking, to stop the motor after a short period of - * inversion. */ -static uint8_t mouth_stop_delay; -/** Number of movements remaining before stopping the mouth. */ -uint8_t mouth_move_counter; /** Number of periods remaining before stopping the rotation. * Normally used when braking, to stop the motor after a short period of * inversion. */ @@ -91,30 +91,88 @@ /** Spinning direction */ static uint8_t spin_direction; -uint8_t mouth_pos; /* XXX delete this */ - /** PWM mask register applied on the port on a regular basis. */ uint8_t portB_PWM_mask; /** - * \name Low level motor control - * These functions access the motor I/O port. + * \name Module configuration + * These functions initialize the motors and switches I/O ports for normal and + * sleep mode. * @{ */ -/** Stop the eyes motor. */ -#define stop_eyes_motor() {MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK);} +/** \ingroup movements */ +/** + \brief Initialize the position switches for normal operation. + Initialize all I/O of the position switches as input with internal pull-up. + */ +void initPosSwitches(void) +{ + PSW_WINGS_DDR &= ~PSW_WINGS_MK; + PSW_WINGS_PT |= PSW_WINGS_MK; + PSW_EYES_DDR &= ~PSW_EYES_MK; + PSW_EYES_PT |= PSW_EYES_MK; + PSW_MOUTH_DDR &= ~PSW_MOUTH_MK; + PSW_MOUTH_PT |= PSW_MOUTH_MK; + PSW_SPIN_DDR &= ~PSW_SPIN_MK; + PSW_SPIN_PT |= PSW_SPIN_MK; +} -/** Start the eyes motor. */ -#define run_eyes_motor() {(MOT_EYES_PT &= ~MOT_IEYES_MK); \ - (MOT_EYES_PT |= MOT_EYES_MK);} -/** Invert the eyes motor. */ -#define invert_eyes_motor() {(MOT_EYES_PT &= ~MOT_EYES_MK); \ - (MOT_EYES_PT |= MOT_IEYES_MK);} +/** + \brief Initializes the position switches for minimal power consumption. + All pins have internal pull-up and the switch shorts the pin low so to avoid + undefined states, we must set all pins as strong low. + */ +void closePosSwitches(void) +{ + PSW_WINGS_PT &= ~PSW_WINGS_MK; + PSW_WINGS_DDR |= PSW_WINGS_MK; + PSW_EYES_PT &= ~PSW_EYES_MK; + PSW_EYES_DDR |= PSW_EYES_MK; + PSW_MOUTH_PT &= ~PSW_MOUTH_MK; + PSW_MOUTH_DDR |= PSW_MOUTH_MK; + PSW_SPIN_PT &= ~PSW_SPIN_MK; + PSW_SPIN_DDR |= PSW_SPIN_MK; +} + +/** + \brief Initalizes the motors for normal operation. + This sets all motor I/O as output + */ +void initMotors(void) +{ + MOT_EYES_DDR |= MOT_EYES_MK; + MOT_MOUTH_DDR |= MOT_MOUTH_MK; + MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; + MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; + MOT_SPIN_DDR |= MOT_SPIN_MK; +} /*! @} */ /** * \name Eyes functions * @{ */ +/** \brief Low level access to stop the eyes motor. */ +static inline void stop_eyes_motor(void) __attribute__ ((always_inline)); +void stop_eyes_motor(void) +{ + MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK); +} +/** \brief Low level access to start the eyes motor. */ +static inline void run_eyes_motor(void) __attribute__ ((always_inline)); +void run_eyes_motor(void) +{ + (MOT_EYES_PT &= ~MOT_IEYES_MK); + (MOT_EYES_PT |= MOT_EYES_MK); +} + +/** \brief Low level access to invert the eyes motor. */ +static inline void invert_eyes_motor(void) __attribute__ ((always_inline)); +void invert_eyes_motor(void) +{ + (MOT_EYES_PT &= ~MOT_EYES_MK); + (MOT_EYES_PT |= MOT_IEYES_MK); +} + /** \brief Stop the eyes \ingroup eyes @@ -264,12 +322,6 @@ /* We only count when the switch is pushed, not released. */ if (~PSW_MOUTH_PIN & PSW_MOUTH_MK) { - if (~PSW_MOUTH_PIN & PSW_MOUTH_O_MK) - if (mouth_pos == CLOSE) /* XXX can we delete this line? */ - mouth_pos = OPEN; - if (~PSW_MOUTH_PIN & PSW_MOUTH_C_MK) - if (mouth_pos == OPEN) /* XXX can we delete this line? */ - mouth_pos = CLOSE; if (mouth_move_counter) { mouth_move_counter--; @@ -378,62 +430,6 @@ } } -/* - * POSITION SWITCHES - * Init as pull-up input - */ - -void initPosSwitches(void) -{ - /* flipper switch */ - PSW_WINGS_DDR &= ~PSW_WINGS_MK; - PSW_WINGS_PT |= PSW_WINGS_MK; - /* eyes switches */ - PSW_EYES_DDR &= ~PSW_EYES_MK; - PSW_EYES_PT |= PSW_EYES_MK; - /* mouth switches */ - PSW_MOUTH_DDR &= ~PSW_MOUTH_MK; - PSW_MOUTH_PT |= PSW_MOUTH_MK; - /* spin switch */ - PSW_SPIN_DDR &= ~PSW_SPIN_MK; - PSW_SPIN_PT |= PSW_SPIN_MK; -} - -/* - * Set position switches for minimal power consumption. - * - * All pins have internal pull-up and the switch shorts the pin low so to avoid - * undefined states, we must set all pins as strong low. - */ -void closePosSwitches(void) -{ - /* flipper switch */ - PSW_WINGS_PT &= ~PSW_WINGS_MK; - PSW_WINGS_DDR |= PSW_WINGS_MK; - /* eyes switches */ - PSW_EYES_PT &= ~PSW_EYES_MK; - PSW_EYES_DDR |= PSW_EYES_MK; - /* mouth switches */ - PSW_MOUTH_PT &= ~PSW_MOUTH_MK; - PSW_MOUTH_DDR |= PSW_MOUTH_MK; - /* spin switch */ - PSW_SPIN_PT &= ~PSW_SPIN_MK; - PSW_SPIN_DDR |= PSW_SPIN_MK; -} - -/* - * Set motors I/O as output - */ - -void initMotors(void) -{ - MOT_EYES_DDR |= MOT_EYES_MK; - MOT_MOUTH_DDR |= MOT_MOUTH_MK; - MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; - MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; - MOT_SPIN_DDR |= MOT_SPIN_MK; -} - /** \brief Start waving the flippers up and down \ingroup flippers \param cnt number of movements before the flippers will stop \param pwm pwm value Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 12:39:37 UTC (rev 515) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 12:58:49 UTC (rev 516) @@ -67,26 +67,27 @@ enum spin_direction { LEFT, RIGHT }; -/* counters to stop eye/mouth and flippers at timer int */ +/** \ingroup eyes */ +extern uint8_t eyes_move_counter; +/** \ingroup mouth */ +extern uint8_t mouth_move_counter; +/** \ingroup flippers */ extern uint8_t flippers_move_counter, flippers_PWM; -extern uint8_t eyes_move_counter; -extern uint8_t mouth_move_counter, mouth_pos; +/** \ingroup spin */ extern uint8_t spin_move_counter, spin_PWM; /* pwm mask registers */ extern uint8_t portB_PWM_mask; -void initMotors(void); - /* - * POSITION SWITCHES - * Init as pull-up input + * Module configuration */ void initPosSwitches(void); void closePosSwitches(void); +void initMotors(void); /* - * Basic movements + * Movements */ extern void stop_eyes(void); extern void blink_eyes(uint8_t cnt); |
From: Paul_R <c2m...@c2...> - 2007-09-12 12:39:38
|
Author: Paul_R Date: 2007-09-12 14:39:37 +0200 (Wed, 12 Sep 2007) New Revision: 515 Modified: firmware/tuxaudio/branches/audio_cleanup/main.c Log: * Cleanup main.c Modified: firmware/tuxaudio/branches/audio_cleanup/main.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/main.c 2007-09-12 12:20:09 UTC (rev 514) +++ firmware/tuxaudio/branches/audio_cleanup/main.c 2007-09-12 12:39:37 UTC (rev 515) @@ -36,6 +36,11 @@ #include "config.h" #include "PC_communication.h" +/* XXX AT26F004.h must be included here read_data function is used in + * send_info(). + */ +#include "AT26F004.h" + /* * Version number */ @@ -43,13 +48,13 @@ #define CPU_NUMBER TUXAUDIO_CPU_NUM /* audio CPU */ const author_t author __attribute__ ((section("version.3"))) = { -AUTHOR_CMD, AUTHOR_ID, 0}; + AUTHOR_CMD, AUTHOR_ID, 0}; const revision_t svn_revision __attribute__ ((section("version.2"))) = { -REVISION_CMD, SVN_REV, SVN_STATUS}; + REVISION_CMD, SVN_REV, SVN_STATUS}; const version_t tag_version __attribute__ ((section("version.1"))) = { -VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; + VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; static uint8_t info_flg = 0; /* indicates if version information should be sent */ static uint8_t pre_sleep_delay = 0; /* set when sleep should be entered */ @@ -183,7 +188,6 @@ i2cSlaveReceiveService(4, audioBuf); sei(); } - audioBufIdx = 0; /* clear buffer; this buffer can only hold one command so should be simply reset here */ } @@ -203,7 +207,6 @@ } else if (command[0] == STORE_INDEX_CMD) { - /* param: command[1] : lower address byte */ /* command[2] : middle address byte */ /* command[3] : higher address byte */ @@ -245,8 +248,6 @@ int main(void) { - - init_avr(); // Init AVR resetFifo(&PWMFifo); /* Initialise the PWM fifo */ @@ -277,8 +278,6 @@ { EIFR = (_BV(INT1) | _BV(INT0)); /* INT0, INT1 external interrupt flag */ EIMSK = (_BV(INT1) | _BV(INT0)); /* INT0, INT1 external interrupt request enable */ - /* EIFR= (_BV(INT1) | _BV(INT0)); [> INT0, INT1 external interrupt flag <] */ - /* EIMSK = (_BV(INT1)); [> INT0, INT1 external interrupt request enable <] */ } } @@ -296,14 +295,10 @@ } if (programmingFlash) // Restora all the context for flash programming - { flashProgramming(); - } if (flashPlay) - { playSound(); - } if (sendSensorsFlag) { @@ -338,8 +333,6 @@ DDRD &= ~0x02; } } - - sendCommands(); /* Send commands on I2C */ if (audioBufIdx) @@ -355,10 +348,16 @@ } } +// External Interrupt 0 service routine PD2 +ISR(SIG_INTERRUPT0) +{ + spi_start = 1; +} + // External Interrupt 1 service routine PD3 ISR(SIG_INTERRUPT1) { - spi_ready = 1; // Set the flag SPI ready from RF + spi_ready = 1; } /* @@ -419,13 +418,7 @@ //OCR0A = 250; // Normal operation for ADC sampling if FIFO Adaptative is on } } - if (--sendSensorsCmpt == 0) + if (--sendSensorsCmpt == 0) sendSensorsFlag = 1; /* send status to the behavioural CPU, 8KHz divided by 256 lead to a status sent each 32ms */ } } - -// External Interrupt 0 service routine PD2 -ISR(SIG_INTERRUPT0) -{ - spi_start = 1; -} |
From: Paul_R <c2m...@c2...> - 2007-09-12 12:20:16
|
Author: Paul_R Date: 2007-09-12 14:20:09 +0200 (Wed, 12 Sep 2007) New Revision: 514 Modified: firmware/tuxaudio/branches/audio_cleanup/init.c Log: * Replaced ASM by C code Modified: firmware/tuxaudio/branches/audio_cleanup/init.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/init.c 2007-09-12 12:19:00 UTC (rev 513) +++ firmware/tuxaudio/branches/audio_cleanup/init.c 2007-09-12 12:20:09 UTC (rev 514) @@ -153,9 +153,8 @@ SPCR = 0x50; SPSR = 0x00; - asm volatile /* clear the SPI interrupt flag by reading both SPSR and SPDR */ - ("in __tmp_reg__, %0" "\n\t" "in __tmp_reg__, %1" "\n\t":: - "I" (_SFR_IO_ADDR(SPSR)), "I"(_SFR_IO_ADDR(SPDR))); + /* Read the SPDR to clear the SPI interrupt flag */ + i = SPDR; // External Interrupt(s) initialization EICRA = (_BV(ISC11) | _BV(ISC10) | _BV(ISC01) | _BV(ISC00)); /* Rising edge of INT0 and rising edge of INT1 */ |
From: Paul_R <c2m...@c2...> - 2007-09-12 12:19:03
|
Author: Paul_R Date: 2007-09-12 14:19:00 +0200 (Wed, 12 Sep 2007) New Revision: 513 Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c firmware/tuxaudio/branches/audio_cleanup/AT26F004.h firmware/tuxaudio/branches/audio_cleanup/flash.c firmware/tuxaudio/branches/audio_cleanup/flash.h Log: * Added doxygen comments * Cleanup some functions Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-12 11:07:13 UTC (rev 512) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-12 12:19:00 UTC (rev 513) @@ -24,19 +24,22 @@ #include "hardware.h" #include "spi.h" - +/** + * \ingroup at26f004 + * \brief initialize a table with the sectors adresses values + */ uint8_t sector_adress[11][3] = { - {0x00, 0x00, 0x00}, - {0x01, 0x00, 0x00}, - {0x02, 0x00, 0x00}, - {0x03, 0x00, 0x00}, - {0x04, 0x00, 0x00}, - {0x05, 0x00, 0x00}, - {0x06, 0x00, 0x00}, - {0x07, 0x00, 0x00}, - {0x07, 0x80, 0x00}, - {0x07, 0xA0, 0x00}, - {0x07, 0xC0, 0x00} + {SECTOR0}, + {SECTOR1}, + {SECTOR2}, + {SECTOR3}, + {SECTOR4}, + {SECTOR5}, + {SECTOR6}, + {SECTOR7}, + {SECTOR8}, + {SECTOR9}, + {SECTOR10} }; /** @@ -153,6 +156,14 @@ FLASH_CS_OFF; } +/** + * \ingroup at26f004 + \param ad2 high address part + \param ad1 medium adress part + \param ad0 lower adress part + \return Data read + \brief This function read a single byte in the flash memory. + */ uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0) { uint8_t data1; Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-12 11:07:13 UTC (rev 512) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-12 12:19:00 UTC (rev 513) @@ -22,51 +22,69 @@ This module contains all specific definitions and functions to access the flash memory. */ + /** \file AT26F004.h \ingroup at26f004 \brief AT26F004 flash memory header - */ + +#ifndef AT26F004_H +#define AT26F004_H +#include "hardware.h" + /** \file AT26F004.c \ingroup at26f004 \brief AT26F004 functions - */ -#ifndef AT26F004_H -#define AT26F004_H -#include "hardware.h" - -/* Flash (AT26F004) OP CODE */ +/** + * \name Read opcodes + @{ */ #define READ_ARRAY 0x0B #define READ_ARRAY_LOW_F 0x03 - +/* @} */ +/** \name Erase opcodes + *@{ */ #define BLOCK_ERASE_4K 0x20 #define BLOCK_ERASE_32K 0x52 #define BLOCK_ERASE_64K 0xD8 #define CHIP_ERASE 0x60 +/* @} */ +/** \name Program opcodes + * @{ */ #define BYTE_PROGRAM 0x02 #define SEQU_PROGRAM 0xAF +/* @} */ +/** \name Sectors managment opcodes + * @{ */ #define WRITE_EN 0x06 #define WRITE_DIS 0x04 #define PROTECT_SECTOR 0x36 #define UNPROTECT_SECTOR 0x39 #define READ_SECT_PROTECT 0x3C - +/* @} */ +/** \name Status command + * @{ */ #define READ_STATUS_REG 0x05 #define WRITE_STATUS_REG 0x01 - +/* @} */ +/** \name Misc. opcodes + * @{ */ #define READ_MANUFACT 0x9F #define DEEP_POWER_MODE 0xB9 #define RESUME_DEEP_MODE 0xAB #define NOP 0x00 +/* @} */ -/* Flash status register masks */ +/** + * \name AT26F004 status register masks + * + * @{ */ #define BUSY 0x01 #define WEL 0X02 #define SWP 0x0C @@ -74,33 +92,61 @@ #define RES 0x20 #define SPM 0x40 #define SPRL 0x80 +/*! @} */ -/* Flash sector adresses */ +/** \name Flash sector adresses + * @{ */ +#define SECTOR0 0x00, 0x00, 0x00 +#define SECTOR1 0x01, 0x00, 0x00 +#define SECTOR2 0x02, 0x00, 0x00 +#define SECTOR3 0x03, 0x00, 0X00 +#define SECTOR4 0x04, 0x00, 0x00 +#define SECTOR5 0x05, 0x00, 0x00 +#define SECTOR6 0x06, 0X00, 0x00 +#define SECTOR7 0x07, 0x00, 0x00 +#define SECTOR8 0x07, 0x80, 0x00 +#define SECTOR9 0x07, 0xA0, 0x00 +#define SECTOR10 0x07, 0xC0, 0x00 extern uint8_t sector_adress[11][3]; +/* @} */ + + /** * \name Flash TOP address - * \ingroup at26f004 * The flash memory address range is 0x000000 - [TOP_A2 TOP_A1 TOP_A0] * The AT26F004 has an address range of 0x000000 - 0x7FFFFF - */ + * @{ */ + /** High byte of the TOP address. */ #define TOP_A2 0x07 /** Middle byte of the TOP address. */ #define TOP_A1 0xFF /** Low byte of the TOP address. */ #define TOP_A0 0xFF +/*! @} */ - +/** \name Status access functions + * @{ */ extern uint8_t read_status(void); +extern void write_status(uint8_t const status); +/* @} */ +/** \name Writing functions + * @{ */ extern void write_enable(void); extern void write_disable(void); -extern void write_status(uint8_t const status); +extern void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, + uint8_t const data); +/* @} */ +/** \name Reading function + * @{ */ +extern uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0); +/* @} */ +/** \name Misc. functions + * @{ */ extern void erase_flash(void); extern void unprotect_sector(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0); -extern void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, - uint8_t const data); -extern uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0); +/* @} */ #endif Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-12 11:07:13 UTC (rev 512) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-12 12:19:00 UTC (rev 513) @@ -115,6 +115,12 @@ /** * \ingroup flash \brief This function is used to play a sound from the flash memory. + + The first step (playInit) is to initialize the flash memory with the selected sound to play. + Many tests are made to ensure that the sound to play exist, the indexes are correct, etc. + + The second step (playingSound) is to fill the fifo with the sound's bytes, and to verify the adresses. + */ void playSound(void) { @@ -128,7 +134,20 @@ /* Static functions */ +/** + * \ingroup flash + \brief This function is used to init the memory to play a sound. + \param nsound Track number to be played. + To prevent bugs, some verifications are made : + - check if the sound to play exist + - check if the sound to play is not null + - check if the indexes are correct. (the address exist, and the start and end indexes are not the same. + + If these conditions are respected, the memory is initialised with the first sound's byte address. + The next index is stored to identify the end of the sound track. +*/ + void playInit(uint8_t nsound) { uint8_t count, i; @@ -229,6 +248,15 @@ flash_state = 0; } +/* Static functions */ +/** + * \ingroup flash + \brief Read the flash memory and fill the fifo. + + This function reads bytes into the flash memory and fill the fifo. + When the last byte is read, the sound play's sequence is stopped. + */ + static void playingSound(void) { uint8_t sound; @@ -260,6 +288,13 @@ sei(); } +/* Static functions */ +/** + * \ingroup flash + \brief Stop the play sequence. + + */ + static void stopPlaying(void) { flashPlay = 0; @@ -271,10 +306,9 @@ /** * \ingroup flash * \brief Erase the flash memory. + * * This funtion perform a full erase of the flash memory and initiate the sound * flash programming. - * This functions is called by the command_Parser function when a programming - * flash command is received. */ static void erasingFlash(void) { @@ -293,6 +327,7 @@ /** * \ingroup flash * \brief Write the number of sound to be stored. + * This function store the first TOC byte (numSound), received with the flash program command, at the first memory adress. */ @@ -309,6 +344,7 @@ /** * \ingroup flash * \brief Write the TOC in the memory. + * * This function store the the indexes into the memory. */ @@ -343,6 +379,7 @@ /** * \ingroup flash * \brief Initiate the sound programming. + * * This function initiate the sound flash memory for a sequential programming. */ @@ -374,6 +411,7 @@ /** * \ingroup flash * \brief Program the sound in the flash memory. + * * This function store the sound in the flash memory. */ static void soundProgramming(void) @@ -415,6 +453,8 @@ /** * \ingroup flash * \brief This function end the flash programming task. + * + * This function restore all the parameters. */ static void endProgramming (void) Modified: firmware/tuxaudio/branches/audio_cleanup/flash.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-12 11:07:13 UTC (rev 512) +++ firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-12 12:19:00 UTC (rev 513) @@ -34,20 +34,25 @@ #ifndef FLASH_H #define FLASH_H -/* Flash programming states */ +/** \name Flash programming states + @{ */ #define ERASE_STATE 0 #define FIRST_PROG_STATE 1 #define PROG_TOC_STATE 2 #define INIT_SOUND_PROG_STATE 3 #define SOUND_PROG_STATE 4 #define END_STATE 5 +/* @} */ extern void flashProgramming(void); extern void playSound(void); +/** start / end flash states flag */ extern uint8_t flash_state; +/** state machine variable */ extern uint8_t f_state; +/** sound number to be played */ extern uint8_t soundNum; #endif |
From: jaguarondi <c2m...@c2...> - 2007-09-12 11:07:17
|
Author: jaguarondi Date: 2007-09-12 13:07:13 +0200 (Wed, 12 Sep 2007) New Revision: 512 Modified: firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Moved motor_control from the interface to the module as it's not called from an interrupt anymore. * Reorganized the eyes functions, moved a couple of them from the interface to the module, added a couple of comments. * Removed a few unused stuff. Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 09:21:16 UTC (rev 511) +++ firmware/tuxcore/trunk/main.c 2007-09-12 11:07:13 UTC (rev 512) @@ -307,7 +307,7 @@ FifoPut(statusFifo, mouth_move_counter); FifoPut(statusFifo, flippers_move_counter); FifoPut(statusFifo, STATUS_POSITION2_CMD); - FifoPut(statusFifo, spin_stop_delay); + FifoPut(statusFifo, spin_move_counter); FifoPut(statusFifo, gStatus.pos); FifoPut(statusFifo, 0); if (light_f) /* send light measurement */ Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-12 09:21:16 UTC (rev 511) +++ firmware/tuxcore/trunk/motors.c 2007-09-12 11:07:13 UTC (rev 512) @@ -30,6 +30,10 @@ #include "global.h" #include "motors.h" +/** + * \name Braking delays + * These functions access the motor I/O port. + * @{ */ /** Delay during which the motor is inverted when braking the eyes to stop them * in the close position. There's no need to brake the motor when opening the * eyes with this gearbox design. */ @@ -44,6 +48,7 @@ * them either up or down. If we don't brake here, the flippers end up in a * medium position. */ #define FLIPPERS_BRAKING_DLY 4 +/*! @} */ /** Init value of the timer used to reset the flippers in the low position. */ #define FLIP_TIMER_INIT 0xFF /** Minimum difference required between the period the flippers are moving from @@ -53,7 +58,7 @@ /** Number of periods remaining before stopping the flippers. * Normally used when braking, to stop the motor after a short period of * inversion. */ -uint8_t flippers_stop_delay; +static uint8_t flippers_stop_delay; /** Number of movements remaining before stopping the flippers. */ uint8_t flippers_move_counter; /** PWM applied on the flippers motor. */ @@ -66,19 +71,19 @@ /** Number of periods remaining before stopping the eyes. * Normally used when braking, to stop the motor after a short period of * inversion. */ -uint8_t eyes_stop_delay; +static uint8_t eyes_stop_delay; /** Number of movements remaining before stopping the flippers. */ uint8_t eyes_move_counter; /** Number of periods remaining before stopping the mouth. * Normally used when braking, to stop the motor after a short period of * inversion. */ -uint8_t mouth_stop_delay; +static uint8_t mouth_stop_delay; /** Number of movements remaining before stopping the mouth. */ uint8_t mouth_move_counter; /** Number of periods remaining before stopping the rotation. * Normally used when braking, to stop the motor after a short period of * inversion. */ -uint8_t spin_stop_delay; +static uint8_t spin_stop_delay; /** Number of movements remaining before stopping the rotation. */ uint8_t spin_move_counter; /** PWM applied on the spinning motor. */ @@ -91,73 +96,112 @@ /** PWM mask register applied on the port on a regular basis. */ uint8_t portB_PWM_mask; +/** + * \name Low level motor control + * These functions access the motor I/O port. + * @{ */ +/** Stop the eyes motor. */ +#define stop_eyes_motor() {MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK);} + +/** Start the eyes motor. */ +#define run_eyes_motor() {(MOT_EYES_PT &= ~MOT_IEYES_MK); \ + (MOT_EYES_PT |= MOT_EYES_MK);} +/** Invert the eyes motor. */ +#define invert_eyes_motor() {(MOT_EYES_PT &= ~MOT_EYES_MK); \ + (MOT_EYES_PT |= MOT_IEYES_MK);} +/*! @} */ + +/** + * \name Eyes functions + * @{ */ + /** - \brief Wings position interrupt - \ingroup flippers + \brief Stop the eyes + \ingroup eyes - This interrupt stops the flippers when the desired number of movements have - been executed. In order to stop the flippers quickly and block the motor, we - need to invert the motor for a small duration. + The eyes motor will stop immediately, even if the eyes are not in the open + or close position. Use open_eyes or close_eyes instead if you want to stop + them in a given position. + */ +void stop_eyes(void) +{ + stop_eyes_motor(); +} - When the signal is switching from high to low (switch pushed), the number of - movements is decreased and when null, the flippers motor is switched - backwards and will be stopped by timer0 overflow after the - FLIPPERS_BRAKING_DLY period. So we only count when the switch is pushed but - not when it is released. As the interrupt triggers on a signal change, we - need to suppress the release interrupt. +/** + \brief Blink the eyes + \ingroup eyes + + \param cnt number of movements before the flippers will stop + \note Any mouth command is cancelled + + The eyes will start blinking until 'cnt' movements are executed. A movement + is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is + null, waving will run indefinitely. */ -ISR(SIG_PIN_CHANGE1) +void blink_eyes(uint8_t cnt) { - /* We only count when the switch is pushed, not released. */ - if (~PSW_WINGS_PIN & PSW_WINGS_MK) - { - /* This test prevents the toggle when the flippers are pushed. The - * flippers motor must be switched on (flippers_PWM <> 0) to toggle the - * position */ - if (flippers_PWM) - gStatus.pos ^= GSTATUS_POS_W0; /* toggle wigs position */ + eyes_move_counter = cnt; + eyes_stop_delay = 0; + run_eyes_motor(); +} - if (flippers_timer) /* if we need to reposition the flippers */ - { - if (flippers_move_counter == 1) - { - if ((flippers_revious_timer) && (flippers_timer < - (flippers_revious_timer - FLIPPERS_RESETTIMER_HYST))) - { - /* flippers are down */ - /* Position reached so init gStatus.pos bit to lower - * position */ - gStatus.pos &= ~GSTATUS_POS_W0; - flippers_timer = 0; - flippers_revious_timer = 0; - } - else /* continue */ - { - /* Unknow position, execute another movement to determine - * it */ - flippers_revious_timer = flippers_timer; - flippers_timer = FLIP_TIMER_INIT; - return; - } - } - else - flippers_timer = FLIP_TIMER_INIT; - } +/** + \brief Open the eyes + \ingroup eyes - if (flippers_move_counter) - { - flippers_move_counter--; - if (!flippers_move_counter) - { - stopWings(); - runWingsBw(); - flippers_stop_delay = FLIPPERS_BRAKING_DLY; - } - } - } + Open the eyes if they are closed. + + The eyes can be in three different states and should have a different + behavior in all states. + - Eyes opened - no movement is required. + - Eyes closed - Just one movement is required to open the eyes. + - indeterminated - two movements are required. + + To prevent that the motor can be activated when the eyes are opened and to + stop the eyes in the open state by sending the open_eyes_cmd when they're + blinking, eyes_move_counter is initalised but the blink_eyes function isn't + call. + If the motor is running, it will execute two movements before stop. If the + motor isn't switched on, nothing happens. + + \note XXX The computer side (API, daemon) must know than eyes_move_counter + can be not null with the motor switched off. + */ +void open_eyes(void) +{ + if ((PSW_EYES_PIN & PSW_EYES_O_MK) && (PSW_EYES_PIN & PSW_EYES_C_MK)) + blink_eyes(2); + + else if (!(PSW_EYES_PIN & PSW_EYES_C_MK)) + blink_eyes(1); + + else + eyes_move_counter = 2; } /** + \brief Close the eyes + \ingroup eyes + + Close the eyes if they are opened. + + When the close_eyes_cmd is received, if the eyes are closed, nothing + happens. But, when the eyes are blinking, this command must stop the eyes + in the closed position. To do this, eyes_move_counter is initialised, but + the blink_eyes function isn't call. So, if the command is received when the + eyes are blinking, two movements are executed before the motor is stopped. + */ +void close_eyes(void) +{ + if (PSW_EYES_PIN & PSW_EYES_C_MK) + blink_eyes(1); + + else + eyes_move_counter = 2; +} + +/** \brief Eyes position interrupt \ingroup eyes @@ -190,12 +234,13 @@ eyes_move_counter--; if (!eyes_move_counter) { - stopEyes(); - runIEyes(); + stop_eyes_motor(); + invert_eyes_motor(); eyes_stop_delay = EYES_BRAKING_DLY; } } } +/*! @} */ /** \brief Mouth position interrupt @@ -239,6 +284,72 @@ } /** + \brief Wings position interrupt + \ingroup flippers + + This interrupt stops the flippers when the desired number of movements have + been executed. In order to stop the flippers quickly and block the motor, we + need to invert the motor for a small duration. + + When the signal is switching from high to low (switch pushed), the number of + movements is decreased and when null, the flippers motor is switched + backwards and will be stopped by timer0 overflow after the + FLIPPERS_BRAKING_DLY period. So we only count when the switch is pushed but + not when it is released. As the interrupt triggers on a signal change, we + need to suppress the release interrupt. + */ +ISR(SIG_PIN_CHANGE1) +{ + /* We only count when the switch is pushed, not released. */ + if (~PSW_WINGS_PIN & PSW_WINGS_MK) + { + /* This test prevents the toggle when the flippers are pushed. The + * flippers motor must be switched on (flippers_PWM <> 0) to toggle the + * position */ + if (flippers_PWM) + gStatus.pos ^= GSTATUS_POS_W0; /* toggle wigs position */ + + if (flippers_timer) /* if we need to reposition the flippers */ + { + if (flippers_move_counter == 1) + { + if ((flippers_revious_timer) && (flippers_timer < + (flippers_revious_timer - FLIPPERS_RESETTIMER_HYST))) + { + /* flippers are down */ + /* Position reached so init gStatus.pos bit to lower + * position */ + gStatus.pos &= ~GSTATUS_POS_W0; + flippers_timer = 0; + flippers_revious_timer = 0; + } + else /* continue */ + { + /* Unknow position, execute another movement to determine + * it */ + flippers_revious_timer = flippers_timer; + flippers_timer = FLIP_TIMER_INIT; + return; + } + } + else + flippers_timer = FLIP_TIMER_INIT; + } + + if (flippers_move_counter) + { + flippers_move_counter--; + if (!flippers_move_counter) + { + stopWings(); + runWingsBw(); + flippers_stop_delay = FLIPPERS_BRAKING_DLY; + } + } + } +} + +/** \brief Spin position interrupt \ingroup spin @@ -250,15 +361,15 @@ */ ISR(SIG_INTERRUPT1) { - if (spin_stop_delay) + if (spin_move_counter) { - spin_stop_delay--; + spin_move_counter--; - if (!spin_stop_delay) + if (!spin_move_counter) { spin_PWM_mask &= ~MOT_SPIN_MK; stopSpinMot(); - spin_move_counter = SPIN_BRAKING_DLY; + spin_stop_delay = SPIN_BRAKING_DLY; if (spin_direction == LEFT) spin_PWM_mask |= MOT_SPIN_R_MK; else @@ -310,12 +421,6 @@ PSW_SPIN_DDR |= PSW_SPIN_MK; } -uint8_t getPosSwitches(void) -{ - // return (PINB & PSW_MK); - return 0; -} - /* * Set motors I/O as output */ @@ -420,79 +525,6 @@ } /** - \brief Blink the eyes - \ingroup eyes - - \param cnt number of movements before the flippers will stop - \note Any mouth command is cancelled - - The eyes will start blinking until 'cnt' movements are executed. A movement - is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is - null, waving will run indefinitely. - */ -void blinkEyes(uint8_t cnt) -{ - eyes_move_counter = cnt; - eyes_stop_delay = 0; - runEyes(); -} - -/** - \brief Open the eyes - \ingroup eyes - - Open the eyes if they are closed. - - The eyes can be in three different states and should have a different - behavior in all states. - - Eyes opened - no movement is required. - - Eyes closed - Just one movement is required to open the eyes. - - indeterminated - two movements are required. - - To prevent that the motor can be activated when the eyes are opened and to - stop the eyes in the open state by sending the open_eyes_cmd when they're - blinking, eyes_move_counter is initalised but the blinkEyes function isn't - call. - If the motor is running, it will execute two movements before stop. If the - motor isn't switched on, nothing happens. - - \note XXX The computer side (API, daemon) must know than eyes_move_counter - can be not null with the motor switched off. - */ -void openEyes(void) -{ - if ((PSW_EYES_PIN & PSW_EYES_O_MK) && (PSW_EYES_PIN & PSW_EYES_C_MK)) - blinkEyes(2); - - else if (!(PSW_EYES_PIN & PSW_EYES_C_MK)) - blinkEyes(1); - - else - eyes_move_counter = 2; -} - -/** - \brief Close the eyes - \ingroup eyes - - Close the eyes if they are opened. - - When the close_eyes_cmd is received, if the eyes are closed, nothing - happens. But, when the eyes are blinking, this command must stop the eyes - in the closed position. To do this, eyes_move_counter is initialised, but - the blinkEyes function isn't call. So, if the command is received when the - eyes are blinking, two movements are executed before the motor is stopped. - */ -void closeEyes(void) -{ - if (PSW_EYES_PIN & PSW_EYES_C_MK) - blinkEyes(1); - - else - eyes_move_counter = 2; -} - -/** \brief Move the mouth \ingroup mouth \note Any eye command is cancelled @@ -533,12 +565,21 @@ moveMouth(1); } +/** + \brief Stop the spinning motor + \ingroup primitives + */ void stopSpin(void) { spin_PWM_mask &= ~MOT_SPIN_MK; stopSpinMot(); } +/** + \brief Spin left for the \c angle amount + \param angle Angle to turn, in 90° unit + \ingroup spin + */ void spinLeft(uint8_t angle, uint8_t pwm) { /* Check if direction is changing and if pos. switch isn't push. Then, @@ -548,23 +589,117 @@ angle += 1; } spin_direction = LEFT; - spin_stop_delay = angle; + spin_move_counter = angle; spin_PWM = pwm; spin_PWM_mask &= ~MOT_SPIN_R_MK; spin_PWM_mask |= MOT_SPIN_L_MK; } +/** + \brief Spin right for the \c angle amount + \param angle Angle to turn, in 90° unit + \ingroup spin + */ void spinRight(uint8_t angle, uint8_t pwm) { - /* Check if direction is changing and if pos. switch isn't push. Then, - * increment angle value to prevent too short rotation */ + /* If the rotation direction is changing and we are not stopped exactly on + * the switch (position switch not pressed), we need to increment the angle + * value to prevent counting the first switch detection that will happen as + * soon as the rotation starts. */ if (spin_direction == LEFT && (PSW_SPIN_PIN & PSW_SPIN_MK)) - { - angle += 1; - } + angle++; spin_direction = RIGHT; - spin_stop_delay = angle; + spin_move_counter = angle; spin_PWM = pwm; spin_PWM_mask &= ~MOT_SPIN_L_MK; spin_PWM_mask |= MOT_SPIN_R_MK; } + + +/** + \brief Control the PWM of the spinning & flippers and all motors braking. + \fn motor_control + \ingroup movements + + This function should be called from a timer interrupt that will fix the PWM + resolution. + The PWM period will be PWM_PERIOD times * the timer period. + The braking time is dependant on the timer period too. + */ +/** Number of timer periods that constitutes the PWM period. This is also the + * number of PWM values you can get. */ +#define PWM_PERIOD 5 +void motor_control(void) +{ + static uint8_t pwm_tim; + /* Flippers PWM + * Pulse is stopped here */ + if (pwm_tim == flippers_PWM) + MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; + + /* Spin PWM + * Pulse is stopped here */ + if (pwm_tim == spin_PWM) + MOT_SPIN_PT &= ~MOT_SPIN_MK; + + /* PWM motor management + * Pulse is set here when pwm_tim is at maximum and is + * reset when pwm_tim equals the PWM value set by the user + */ + if (pwm_tim++ == PWM_PERIOD) + { + pwm_tim = 0; + PORTB |= portB_PWM_mask; /* spin and flippers */ + } + + /* Flippers timer to stop the flippers in any position */ + if (flippers_timer) + { + flippers_timer--; + if (!flippers_timer) + { + stopWings(); + } + } + + /* Flippers braking (motor reversed) delay */ + if (flippers_stop_delay) + { + flippers_stop_delay--; + if (!flippers_stop_delay) + { + stopWings(); + flippers_PWM = 0; + } + } + + /* eyes braking (motor reversed) delay */ + if (eyes_stop_delay) + { + eyes_stop_delay--; + if (!eyes_stop_delay) + { + stop_eyes_motor(); + } + } + + /* mouth braking (motor reversed) delay */ + if (mouth_stop_delay) + { + mouth_stop_delay--; + if (!mouth_stop_delay) + { + stopMouth(); + } + } + + /* spin braking (motor reversed) delay */ + if (spin_stop_delay) + { + spin_stop_delay--; + if (!spin_stop_delay) + { + stopSpinMot(); + } + } +} Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-12 09:21:16 UTC (rev 511) +++ firmware/tuxcore/trunk/motors.h 2007-09-12 11:07:13 UTC (rev 512) @@ -68,11 +68,10 @@ { LEFT, RIGHT }; /* counters to stop eye/mouth and flippers at timer int */ -extern uint8_t flippers_stop_delay, flippers_move_counter, flippers_PWM; -extern uint8_t flippers_timer, flippers_revious_timer; -extern uint8_t eyes_stop_delay, eyes_move_counter; -extern uint8_t mouth_stop_delay, mouth_move_counter, mouth_pos; -extern uint8_t spin_stop_delay, spin_move_counter, spin_PWM; +extern uint8_t flippers_move_counter, flippers_PWM; +extern uint8_t eyes_move_counter; +extern uint8_t mouth_move_counter, mouth_pos; +extern uint8_t spin_move_counter, spin_PWM; /* pwm mask registers */ extern uint8_t portB_PWM_mask; @@ -85,82 +84,29 @@ */ void initPosSwitches(void); void closePosSwitches(void); -uint8_t getPosSwitches(void); /* * Basic movements */ - -/** - \brief Spin left for the \c angle amount - \param angle Angle to turn, in 90 unit - \ingroup spin - */ -void spinLeft(uint8_t angle, uint8_t pwm); - -/** - \brief Spin right for the \c angle amount - \param angle Angle to turn, in 90 unit - \ingroup spin - */ -void spinRight(uint8_t angle, uint8_t pwm); - -void waveWings(uint8_t cnt, uint8_t pwm); -void lowerWings(void); -void raiseWings(void); -void resetWings(void); -void stopEyes(void); -void blinkEyes(uint8_t cnt); -void closeEyes(void); -void openEyes(void); +extern void stop_eyes(void); +extern void blink_eyes(uint8_t cnt); +extern void close_eyes(void); +extern void open_eyes(void); void moveMouth(uint8_t cnt); void openMouth(void); void closeMouth(void); - -/** - \brief Resets Tux's absolute angle reference - \ingroup primitives - */ -void resetSpinOri(void); - -/** - \brief Resets Tux's absolute turn reference - \ingroup primitives - - Compared to \c resetSpinOri(), this function only resets the turn count - reference, not the angle. See gStatus.ori - */ -void resetSpinTurns(void); - -/** - \brief Stop the spinning motor - \ingroup primitives - */ +void resetWings(void); +void waveWings(uint8_t cnt, uint8_t pwm); +void lowerWings(void); +void raiseWings(void); void stopSpin(void); +void spinLeft(uint8_t angle, uint8_t pwm); +void spinRight(uint8_t angle, uint8_t pwm); /* * Macro and inline functions definition */ -/** - \brief Stop the eyes motor - \ingroup eyes - */ -#define stopEyes() (MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK)) - -/** - \brief Start the eyes motor - \ingroup primitives - */ -#define runEyes() {(MOT_EYES_PT &= ~MOT_IEYES_MK); \ - (MOT_EYES_PT |= MOT_EYES_MK);} -#define runIEyes() {(MOT_EYES_PT &= ~MOT_EYES_MK); \ - (MOT_EYES_PT |= MOT_IEYES_MK);} - -/** - \brief Stop the mouth motor - \ingroup mouth - */ #define stopMouth() (MOT_MOUTH_PT &= ~(MOT_MOUTH_MK | MOT_IMOUTH_MK)) /** @@ -219,89 +165,6 @@ #define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); \ (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) -/** - \brief Control the PWM of the spinning & flippers and motor braking. - \ingroup primitives - * XXX Change group name - * This function should be called from a timer interrupt that will fix the PWM - * resolution. - * The PWM period will be PWM_PERIOD times * the timer period. - * The braking time is dependant on the timer period too. - */ -#define PWM_PERIOD 5 -uint8_t static pwm_tim; +extern void motor_control(void); -static inline void motor_control(void) __attribute__ ((always_inline)); -void motor_control(void) -{ - /* Flippers PWM - * Pulse is stopped here */ - if (pwm_tim == flippers_PWM) - MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; - - /* Spin PWM - * Pulse is stopped here */ - if (pwm_tim == spin_PWM) - MOT_SPIN_PT &= ~MOT_SPIN_MK; - - /* PWM motor management - * Pulse is set here when pwm_tim is at maximum and is - * reset when pwm_tim equals the PWM value set by the user - */ - if (pwm_tim++ == PWM_PERIOD) - { - pwm_tim = 0; - PORTB |= portB_PWM_mask; /* spin and flippers */ - } - /* Flippers timer to stop the flippers in any position */ - if (flippers_timer) - { - flippers_timer--; - if (!flippers_timer) - { - stopWings(); - } - } - - /* Flippers braking (motor reversed) delay */ - if (flippers_stop_delay) - { - flippers_stop_delay--; - if (!flippers_stop_delay) - { - stopWings(); - flippers_PWM = 0; - } - } - - /* eyes braking (motor reversed) delay */ - if (eyes_stop_delay) - { - eyes_stop_delay--; - if (!eyes_stop_delay) - { - stopEyes(); - } - } - - /* mouth braking (motor reversed) delay */ - if (mouth_stop_delay) - { - mouth_stop_delay--; - if (!mouth_stop_delay) - { - stopMouth(); - } - } - - /* spin braking (motor reversed) delay */ - if (spin_move_counter) - { - spin_move_counter--; - if (!spin_move_counter) - { - stopSpinMot(); - } - } -} #endif /* _MOTORS_H_ */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-12 09:21:16 UTC (rev 511) +++ firmware/tuxcore/trunk/parser.c 2007-09-12 11:07:13 UTC (rev 512) @@ -70,19 +70,19 @@ /* Moves */ else if (command[0] == BLINK_EYES_CMD) { - blinkEyes(command[1]); + blink_eyes(command[1]); } else if (command[0] == STOP_EYES_CMD) { - stopEyes(); + stop_eyes(); } else if (command[0] == OPEN_EYES_CMD) { - openEyes(); + open_eyes(); } else if (command[0] == CLOSE_EYES_CMD) { - closeEyes(); + close_eyes(); } else if (command[0] == MOVE_MOUTH_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-12 09:21:16 UTC (rev 511) +++ firmware/tuxcore/trunk/standalone.c 2007-09-12 11:07:13 UTC (rev 512) @@ -209,7 +209,7 @@ if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) { stopSpin(); /* flush the spinning commands */ - spin_stop_delay = 0; + spin_move_counter = 0; } if (remote_mode) @@ -279,7 +279,7 @@ mov_nbr = ir_command; break; case K_UP: - blinkEyes(mov_nbr); + blink_eyes(mov_nbr); break; case K_OK: moveMouth(mov_nbr); |
From: jaguarondi <c2m...@c2...> - 2007-09-12 09:21:44
|
Author: jaguarondi Date: 2007-09-12 11:21:16 +0200 (Wed, 12 Sep 2007) New Revision: 511 Modified: firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/main.c Log: * Cleaned the main tick timer interrupt and initialization. Added flags for 4ms, 100ms and 1s ticks. All actions triggered by these ticks have been moved from the interrupt into the main loop. Counters and flags are now static to main.c. This affects a couple of functions as the timing will be a bit less accurate though I don't think this will be noticeable. Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-09-12 09:14:40 UTC (rev 510) +++ firmware/tuxcore/trunk/global.h 2007-09-12 09:21:16 UTC (rev 511) @@ -162,13 +162,6 @@ extern volatile GSTATUS gStatus; /* - * Software timers - */ -extern uint8_t t4ms_tim; /* 4ms main tick timer */ -extern uint8_t t100ms_tim; /* 100ms tick timer */ -extern uint8_t t1s_tim; /* 1s tick timer XXX unused */ - -/* * intflags * Flags that are set inside interrupts, and reset outside when processed */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-12 09:14:40 UTC (rev 510) +++ firmware/tuxcore/trunk/main.c 2007-09-12 09:21:16 UTC (rev 511) @@ -49,83 +49,90 @@ #include "config.h" #include "debug.h" +/* + * DEBUG: if stack debugging is enabled in debug.h, this macro initializes the + * ram with a constant value in order to catch stack overflow by examining the + * stack at a breakpoint. + */ +DBG_STACK_INIT + +/** \brief Bool type. */ +typedef enum +{ + TRUE = 1, + FALSE = 0, +} bool; + +/** + * \name Software timers + * The main tick has a period of 4ms and is driven by a hardware timer + * interrupt. Counters are used to get 100ms and 1s ticks. + * @{ */ +/** Flag set each 4ms. */ +static bool t4ms_flag; +/** Flag set each 100ms. */ +static bool t100ms_flag; +/** Flag set each 1s. */ +static bool t1s_flag; +/** f4ms counter used to get the 100ms tick. */ +static uint8_t t4ms_cnt; +/** 100ms counter used to get the 1s tick. */ +static uint8_t t100ms_cnt; +/*! @} */ + void initIO(void); void closeIO(void); -void timer2Init(void); void updateStatus(void); void sleep(void); /* * External variables + * XXX to be removed from here */ volatile GSTATUS gStatus; extern volatile uint8_t i2c_pause; -/* - * Software timers - */ -uint8_t t4ms_tim; /* 4ms main tick timer */ -uint8_t t100ms_tim; /* 100ms tick timer */ -uint8_t t1s_tim; /* 1s tick timer */ +/** + \brief Main tick timer intitialization + \fn main_tick_init -/* - * If stack debugging is enabled, this macro initializes the ram with a - * constant value in order to catch stack overflow by examining the stack at a - * breakpoint. - */ -DBG_STACK_INIT + Main tick period: 4ms + Prescaler: 256 + The timer clock will be F_CPU/256 = 31.250 kHz + CTC mode of operation + Compare value: (F_CPU * 4) / (256UL * 1000)) = 125 +*/ +/** Compare value of the main tick timer. */ +#define MAIN_TICK_COMPARE 125 +void main_tick_init(void) +{ + TCCR2A = _BV(WGM21); + TCCR2B = _BV(CS22) | _BV(CS21); + TCNT2 = 0x00; + OCR2A = MAIN_TICK_COMPARE; + TIMSK2 = _BV(OCIE2A); +} -/* - * Timer2 overflow interrupt will be called each 4ms - * and will provide 100ms and 1s counters - * - * Ext int counters will also be managed +/** + \brief Main tick timer interrupt. + This interrupt is called each 4ms on the timer2 compare match. 100ms and 1s + ticks are also computed from software counters. Flags are set on each + different ticks: 4ms flag, 100ms flag and 1s flag. */ ISR(SIG_OUTPUT_COMPARE2A) { - t4ms_tim++; - - motor_control(); - - /* Every 100ms, update status and send it to the computer */ - if (t4ms_tim == 25) + t4ms_cnt++; + t4ms_flag = TRUE; + if (t4ms_cnt == 25) { - t4ms_tim = 0; - /* Every 1s */ - if (++t100ms_tim == 10) + t4ms_cnt = 0; + t100ms_flag = TRUE; + if (++t100ms_cnt == 10) { - t100ms_tim = 0; - t1s_tim++; - ir_send_flg = 1; + t100ms_cnt = 0; + t1s_flag = TRUE; } - - updateStatusFlag = 1; - if (event_timer) - { - event_timer--; - event_manager_flag = 1; - } } - - if (i2c_pause) - i2c_pause--; /* delay after a nack */ - /* Communication */ -// commandProcessFlag = 1; - - if (ir_delay) - ir_delay--; - - /* Led blinking */ - if (led_delay) - { - led_delay--; - if (!led_delay) - { - toggleLeds(); - if (--led_blinking_cnt) - led_delay = led_blinking_pw; - } - } } /* @@ -137,7 +144,7 @@ initPosSwitches(); initMotors(); initIR(); - timer2Init(); + main_tick_init(); initIO(); config_init(); @@ -152,6 +159,46 @@ */ for (;;) { + if (t4ms_flag) + { + t4ms_flag = FALSE; + motor_control(); + + if (i2c_pause) + i2c_pause--; /* delay after a nack */ + /* Communication */ + // commandProcessFlag = 1; + + if (ir_delay) + ir_delay--; + + /* Led blinking */ + if (led_delay) + { + led_delay--; + if (!led_delay) + { + toggleLeds(); + if (--led_blinking_cnt) + led_delay = led_blinking_pw; + } + } + } + if (t100ms_flag) + { + t100ms_flag = FALSE; + updateStatusFlag = 1; /* XXX to move */ + if (event_timer) /* XXX to move */ + { + event_timer--; + event_manager_flag = 1; + } + } + if (t1s_flag) + { + t1s_flag = FALSE; + ir_send_flg = 1; + } /* * Communication: updating status, receiving and sending commands */ @@ -241,27 +288,6 @@ turnIrOff(); } -/* - * timer 2 intitialisation - * - * Main tick timer every 4ms. A 8 bits software counter - * will provide ticks at 100ms and 1s - * - * CTC mode of operation, compare at 125 == 4ms - * Prescaler F_CPU/256 : 31.250 kHz - */ -#define MAIN_TICK 4 // ms -#define TIM2_CMP 125 //((F_CPU * MAIN_TICK) / (256UL * 1000)) - -void timer2Init(void) -{ - TCCR2A = _BV(WGM21); - TCCR2B = _BV(CS22) | _BV(CS21); - TCNT2 = 0x00; - OCR2A = TIM2_CMP; - TIMSK2 = _BV(OCIE2A); -} - #define STATUS_BYTE_SIZE 20 void updateStatus(void) { |
From: jaguarondi <c2m...@c2...> - 2007-09-12 09:14:42
|
Author: jaguarondi Date: 2007-09-12 11:14:40 +0200 (Wed, 12 Sep 2007) New Revision: 510 Modified: firmware/tuxaudio/branches/audio_cleanup/doc/Doxyfile firmware/tuxcore/trunk/doc/Doxyfile Log: * Updated the doxygen configuration files to use the first line of a commant as the brief description. This is better for all the defines and variables. Static and private members are no more hidden. Modified: firmware/tuxaudio/branches/audio_cleanup/doc/Doxyfile =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/doc/Doxyfile 2007-09-11 14:29:55 UTC (rev 509) +++ firmware/tuxaudio/branches/audio_cleanup/doc/Doxyfile 2007-09-12 09:14:40 UTC (rev 510) @@ -156,7 +156,7 @@ # comments will behave just like the Qt-style comments (thus requiring an # explicit @brief command for a brief description. -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// @@ -256,12 +256,12 @@ # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. -EXTRACT_PRIVATE = NO +EXTRACT_PRIVATE = YES # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. -EXTRACT_STATIC = NO +EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. Modified: firmware/tuxcore/trunk/doc/Doxyfile =================================================================== --- firmware/tuxcore/trunk/doc/Doxyfile 2007-09-11 14:29:55 UTC (rev 509) +++ firmware/tuxcore/trunk/doc/Doxyfile 2007-09-12 09:14:40 UTC (rev 510) @@ -156,7 +156,7 @@ # comments will behave just like the Qt-style comments (thus requiring an # explicit @brief command for a brief description. -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// @@ -256,12 +256,12 @@ # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. -EXTRACT_PRIVATE = NO +EXTRACT_PRIVATE = YES # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. -EXTRACT_STATIC = NO +EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. |
From: jaguarondi <c2m...@c2...> - 2007-09-11 14:30:23
|
Author: jaguarondi Date: 2007-09-11 16:29:55 +0200 (Tue, 11 Sep 2007) New Revision: 509 Modified: firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/standalone.c Log: * Added doxygen comments on a couple of variables of the motor module. Some variables and macros have been renamed. * Fixed some indentation and removed a few lines of test code variables. Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/global.h 2007-09-11 14:29:55 UTC (rev 509) @@ -29,17 +29,6 @@ #include <avr/io.h> #include "common/commands.h" -/* Control */ -#define EYES_OPEN_DLY 4 /* 4ms unit */ -#define EYES_ICLOSE_DLY 4 /* 4ms unit */ -#define MOUTH_OPEN_DLY 2 /* 4ms unit */ -#define MOUTH_ICLOSE_DLY 8 /* 4ms unit */ -#define SPIN_INTT_DLY 10 /* 4ms unit */ -#define SPIN_STOP_DLY 10 /* 4ms unit */ -#define WINGS_STOP_DLY 4 /* 4ms unit */ - -#define wingsPwmMask pwmMaskB -#define spinPwmMask pwmMaskB /* * -------------------------------------------------------- * STATUS @@ -67,7 +56,8 @@ * xxxxxxx0 === Wings lowered * xxxxxxx1 === Wings raised * xxxxxx0x === Motors stopped in a known position - * xxxxxx1x === Motors running or stopped in an unknown position. In this case, the previous bit means the last state the wings have passed in. */ + * xxxxxx1x === Motors running or stopped in an unknown position. In this + * case, the previous bit means the last state the wings have passed in. */ #define GSTATUS_POS_W0 0x01 #define GSTATUS_POS_W1 0x02 /* gStatus.mic:[3-2] Eyes position @@ -125,7 +115,8 @@ */ /* bits 5-0: - VTCCCCCC (C: RC5 6 bits command) */ -#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been received */ +#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been \ + received */ #define GSTATUS_IR_TOGGLE _BV(6) /* T: toggle bit of the RC5 code */ #define GSTATUS_IR_COMMAND 0x3F /* T: toggle bit of the RC5 code */ @@ -218,7 +209,9 @@ * TODO merge flags by categories in bitfields or bytes and masks */ -#define COND_RESET_NBR 9 /* number of flags that should be reset, change this according to the table below */ +/* Number of flags that should be reset, change this according to the table + * below. */ +#define COND_RESET_NBR 9 struct condition_table { /* flags reset by the COND_RESET_CMD */ @@ -239,13 +232,4 @@ extern struct condition_table cond_flags; -/* - * Test modes - */ - -#define sigout_set turnLeftLedOn -#define sigout_unset turnLeftLedOff -#define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ -#define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ - #endif /* _GLOBAL_H_ */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/main.c 2007-09-11 14:29:55 UTC (rev 509) @@ -22,6 +22,7 @@ /** \file main.c \brief Tuxcore main functions */ + /** \mainpage Tuxcore firmware documentation of the Tux Droid open source robot \section SVN SVN repository @@ -276,11 +277,11 @@ FifoPut(statusFifo, PINC); FifoPut(statusFifo, PIND); FifoPut(statusFifo, STATUS_POSITION1_CMD); - FifoPut(statusFifo, eyesPosCnt); - FifoPut(statusFifo, mouthPosCnt); - FifoPut(statusFifo, wingsPosCnt); + FifoPut(statusFifo, eyes_move_counter); + FifoPut(statusFifo, mouth_move_counter); + FifoPut(statusFifo, flippers_move_counter); FifoPut(statusFifo, STATUS_POSITION2_CMD); - FifoPut(statusFifo, spinPosCnt); + FifoPut(statusFifo, spin_stop_delay); FifoPut(statusFifo, gStatus.pos); FifoPut(statusFifo, 0); if (light_f) /* send light measurement */ Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/motors.c 2007-09-11 14:29:55 UTC (rev 509) @@ -19,77 +19,139 @@ /* $Id$ */ +/** \file motors.c + \brief Motor module + \ingroup movements +*/ + #include <avr/interrupt.h> #include <avr/io.h> #include "global.h" #include "motors.h" -/* counter to stop eye/mouth at timer int */ -uint8_t wingsStpCnt, wingsPosCnt, wingsPwm = 5; -uint8_t wings_tim, wings_prev_tim; /* timer for absolute position of the wings */ -uint8_t eyesStpCnt, eyesPosCnt; //, eyesPwm; -uint8_t mouthStpCnt, mouthPosCnt, mouth_pos; //, mouthPwm; -uint8_t spinPosCnt, spinStpCnt, spinPwm = 5, spinDirection; +/** Delay during which the motor is inverted when braking the eyes to stop them + * in the close position. There's no need to brake the motor when opening the + * eyes with this gearbox design. */ +#define EYES_BRAKING_DLY 4 +/** Delay during which the motor is inverted when braking the mouth to stop it + * in the open or close position. */ +#define MOUTH_BRAKING_DLY 8 +/** Delay during which the motor is inverted when braking the spinning. Braking + * here is necessary to improve the accuracy of the absolute position. */ +#define SPIN_BRAKING_DLY 10 +/** Delay during which the motor is inverted when braking the flippers to stop + * them either up or down. If we don't brake here, the flippers end up in a + * medium position. */ +#define FLIPPERS_BRAKING_DLY 4 +/** Init value of the timer used to reset the flippers in the low position. */ +#define FLIP_TIMER_INIT 0xFF +/** Minimum difference required between the period the flippers are moving from + * up to down and from down to up. */ +#define FLIPPERS_RESETTIMER_HYST 0x10 -/* pwm mask registers */ -uint8_t pwmMaskB; +/** Number of periods remaining before stopping the flippers. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t flippers_stop_delay; +/** Number of movements remaining before stopping the flippers. */ +uint8_t flippers_move_counter; +/** PWM applied on the flippers motor. */ +uint8_t flippers_PWM = 5; +/** Timer used to measure the period the flippers take between the low and high + * positions. */ +uint8_t flippers_timer; +/** Period taken by the previous movement of the flippers. */ +uint8_t flippers_revious_timer; +/** Number of periods remaining before stopping the eyes. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t eyes_stop_delay; +/** Number of movements remaining before stopping the flippers. */ +uint8_t eyes_move_counter; +/** Number of periods remaining before stopping the mouth. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t mouth_stop_delay; +/** Number of movements remaining before stopping the mouth. */ +uint8_t mouth_move_counter; +/** Number of periods remaining before stopping the rotation. + * Normally used when braking, to stop the motor after a short period of + * inversion. */ +uint8_t spin_stop_delay; +/** Number of movements remaining before stopping the rotation. */ +uint8_t spin_move_counter; +/** PWM applied on the spinning motor. */ +uint8_t spin_PWM = 5; +/** Spinning direction */ +static uint8_t spin_direction; +uint8_t mouth_pos; /* XXX delete this */ + +/** PWM mask register applied on the port on a regular basis. */ +uint8_t portB_PWM_mask; + /** \brief Wings position interrupt \ingroup flippers - This interrupt stops the wings when the desired number of movements have been - executed. In order to stop the wings quickly and block the motor, we need to - invert the motor for a small duration. + This interrupt stops the flippers when the desired number of movements have + been executed. In order to stop the flippers quickly and block the motor, we + need to invert the motor for a small duration. When the signal is switching from high to low (switch pushed), the number of - movements is decreased and when null, the wings motor is switched backwards - and will be stopped by timer0 overflow after the WINGS_STOP_DLY period. - So we only count when the switch is pushed but not when it is released. As - the interrupt triggers on a signal change, we need to suppress the release - interrupt. + movements is decreased and when null, the flippers motor is switched + backwards and will be stopped by timer0 overflow after the + FLIPPERS_BRAKING_DLY period. So we only count when the switch is pushed but + not when it is released. As the interrupt triggers on a signal change, we + need to suppress the release interrupt. */ ISR(SIG_PIN_CHANGE1) { - if (~PSW_WINGS_PIN & PSW_WINGS_MK) /* we only count when the switch is pushed, not released */ + /* We only count when the switch is pushed, not released. */ + if (~PSW_WINGS_PIN & PSW_WINGS_MK) { - /* This test prevent the toggle when the wings are pushed. The wings - * motor must be switched on (wingsPwm <> 0) to toggle the position */ - if (wingsPwm) + /* This test prevents the toggle when the flippers are pushed. The + * flippers motor must be switched on (flippers_PWM <> 0) to toggle the + * position */ + if (flippers_PWM) gStatus.pos ^= GSTATUS_POS_W0; /* toggle wigs position */ - if (wings_tim) /* if we need to reposition the wings */ + if (flippers_timer) /* if we need to reposition the flippers */ { - if (wingsPosCnt == 1) + if (flippers_move_counter == 1) { - if ((wings_prev_tim) && (wings_tim < (wings_prev_tim - WINGS_TIM_DIFF))) /* wings are down */ + if ((flippers_revious_timer) && (flippers_timer < + (flippers_revious_timer - FLIPPERS_RESETTIMER_HYST))) { - /* Position reached so init gStatus.pos bit to lower position */ + /* flippers are down */ + /* Position reached so init gStatus.pos bit to lower + * position */ gStatus.pos &= ~GSTATUS_POS_W0; - wings_tim = 0; /* reset timers */ - wings_prev_tim = 0; + flippers_timer = 0; + flippers_revious_timer = 0; } - else /* continue */ + else /* continue */ { - /* Unknow position, execute another movement to determine it */ - wings_prev_tim = wings_tim; - wings_tim = WINGS_TIM_RESET; + /* Unknow position, execute another movement to determine + * it */ + flippers_revious_timer = flippers_timer; + flippers_timer = FLIP_TIMER_INIT; return; } } else - wings_tim = WINGS_TIM_RESET; + flippers_timer = FLIP_TIMER_INIT; } - if (wingsPosCnt) + if (flippers_move_counter) { - wingsPosCnt--; - if (!wingsPosCnt) + flippers_move_counter--; + if (!flippers_move_counter) { stopWings(); runWingsBw(); - wingsStpCnt = WINGS_STOP_DLY; + flippers_stop_delay = FLIPPERS_BRAKING_DLY; } } } @@ -111,9 +173,10 @@ So we count when the switch is pushed (eyes closed) and when the switch is released (eyes opened) to know the number of movements that occurs - The movement counter eyesPosCnt is decreased and when null, the head motor is + The movement counter eyes_move_counter is decreased and when null, the head + motor is switched backwards and will be stopped by timer0 overflow after the - EYES_ICLOSE_DLY period. + EYES_BRAKING_DLY period. */ ISR(SIG_PIN_CHANGE2) { @@ -122,14 +185,14 @@ else cond_flags.eyes_closed = 0; - if (eyesPosCnt) + if (eyes_move_counter) { - eyesPosCnt--; - if (!eyesPosCnt) + eyes_move_counter--; + if (!eyes_move_counter) { stopEyes(); runIEyes(); - eyesStpCnt = EYES_ICLOSE_DLY; + eyes_stop_delay = EYES_BRAKING_DLY; } } } @@ -138,22 +201,23 @@ \brief Mouth position interrupt \ingroup mouth - This interrupt stops the mouth when the desired number of movements have been - executed. In order to stop the mouth quickly and block the motor, we need to - invert the motor for a small duration. + This interrupt stops the mouth when the desired number of movements have + been executed. In order to stop the mouth quickly and block the motor, we + need to invert the motor for a small duration. There are 2 switches to detect the mouth poistion: mouth open and mouth closed. When any of the switches is pushed, a movement is counted. So we only count when the switch is pushed but not when it is released. As the interrupt triggers on a signal change, we need to suppress the release interrupt. - The movement counter mouthPosCnt is decreased and when null, the head motor - is switched backwards and will be stopped by timer0 overflow after the - MOUTH_ICLOSE_DLY period. + The movement counter mouth_move_counter is decreased and when null, the head + motor is switched backwards and will be stopped by timer0 overflow after the + MOUTH_BRAKING_DLY period. */ ISR(SIG_PIN_CHANGE0) { - if (~PSW_MOUTH_PIN & PSW_MOUTH_MK) /* we only count when the switch is pushed, not released */ + /* We only count when the switch is pushed, not released. */ + if (~PSW_MOUTH_PIN & PSW_MOUTH_MK) { if (~PSW_MOUTH_PIN & PSW_MOUTH_O_MK) if (mouth_pos == CLOSE) /* XXX can we delete this line? */ @@ -161,16 +225,14 @@ if (~PSW_MOUTH_PIN & PSW_MOUTH_C_MK) if (mouth_pos == OPEN) /* XXX can we delete this line? */ mouth_pos = CLOSE; - if (mouthPosCnt) + if (mouth_move_counter) { - mouthPosCnt--; - if (!mouthPosCnt) + mouth_move_counter--; + if (!mouth_move_counter) { - { - stopMouth(); - runIMouth(); - mouthStpCnt = MOUTH_ICLOSE_DLY; - } + stopMouth(); + runIMouth(); + mouth_stop_delay = MOUTH_BRAKING_DLY; } } } @@ -188,19 +250,19 @@ */ ISR(SIG_INTERRUPT1) { - if (spinPosCnt) + if (spin_stop_delay) { - spinPosCnt--; - - if (!spinPosCnt) + spin_stop_delay--; + + if (!spin_stop_delay) { - spinPwmMask &= ~MOT_SPIN_MK; + spin_PWM_mask &= ~MOT_SPIN_MK; stopSpinMot(); - spinStpCnt = SPIN_STOP_DLY; - if (spinDirection == LEFT) - spinPwmMask |= MOT_SPIN_R_MK; + spin_move_counter = SPIN_BRAKING_DLY; + if (spin_direction == LEFT) + spin_PWM_mask |= MOT_SPIN_R_MK; else - spinPwmMask |= MOT_SPIN_L_MK; + spin_PWM_mask |= MOT_SPIN_L_MK; } } } @@ -264,62 +326,65 @@ MOT_MOUTH_DDR |= MOT_MOUTH_MK; MOT_WINGS_FW_DDR |= MOT_WINGS_FW_MK; MOT_WINGS_BW_DDR |= MOT_WINGS_BW_MK; - MOT_SPIN_DDR |= MOT_SPIN_MK; /* both pins on the same port so we can use this mask */ + MOT_SPIN_DDR |= MOT_SPIN_MK; } /** - \brief Start waving the wings up and down \ingroup flippers \param cnt - number of movements before the wings will stop \param pwm pwm value between - 1 (slow) and 5 (fast) + \brief Start waving the flippers up and down \ingroup flippers \param cnt + number of movements before the flippers will stop \param pwm pwm value + between 1 (slow) and 5 (fast) - The wings will start waving until 'cnt' movements are executed. A movement - is raising or lowering the wings. 'cnt' can be up to 256. If 'cnt' is null, - waving will run indefinitely. pwm can be used to change the speed of the - motor although it's more directed to the power delivered to the motor. It's - possible that the smallest values won't deliver enough power to even start - the motor. + The flippers will start waving until 'cnt' movements are executed. A + movement is raising or lowering the flippers. 'cnt' can be up to 256. If + 'cnt' is null, waving will run indefinitely. pwm can be used to change the + speed of the motor although it's more directed to the power delivered to the + motor. It's possible that the smallest values won't deliver enough power to + even start the motor. */ void waveWings(uint8_t cnt, uint8_t pwm) { - wingsPosCnt = cnt; - wingsPwm = pwm; - wingsStpCnt = 0; + flippers_move_counter = cnt; + flippers_PWM = pwm; + flippers_stop_delay = 0; MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; - wingsPwmMask |= MOT_WINGS_FW_MK; + flippers_PWMMask |= MOT_WINGS_FW_MK; } /** - \brief Reset wings + \brief Reset flippers \ingroup flippers - This function reset the wings position. wings_tim is used to determine the - wings positions. Times needed to raise or lower the wings are not the same. - If two movements are executed, wings_tim allow to determine the shorter - time, and then to know if wings are up or low. + This function reset the flippers position. flippers_timer is used to + determine the flippers positions. Times needed to raise or lower the + flippers are not the same. + If two movements are executed, flippers_timer allow to determine the shorter + time, and then to know if flippers are up or low. */ void resetWings(void) { - wings_tim = WINGS_TIM_RESET; - waveWings(2, 5); /* the first movement is to be sure the timer doesn't start counting from any unknown poistion and that the motors are in regime */ + flippers_timer = FLIP_TIMER_INIT; + /* the first movement is to be sure the timer doesn't start counting from + * any unknown poistion and that the motors are in regime */ + waveWings(2, 5); } /** - \brief Raise wings \ingroup flippers + \brief Raise flippers \ingroup flippers - The condition to raise the wings is that they aren't already in the upper + The condition to raise the flippers is that they aren't already in the upper position. If this condition is respected, a single movement is executed by the waveWings function. - If the wings was in the higher position and has been lowered manually, the - wings can't be raised directly. They must pass by the low position + If the flippers was in the higher position and has been lowered manually, + the flippers can't be raised directly. They must pass by the low position (lowerWings function) before being able to be raised. - \note Implement conditions to be able to raise wings without pass by the low - position increase code size and complicate the code. This implementation - need to toggle the motor sense when two or more same commands are repeated. - The mecanical position when the motor is switched off is important. So, the - braking delay couldn't be the same in both sense. + \note Implement conditions to be able to raise flippers without pass by the + low position increase code size and complicate the code. This + implementation need to toggle the motor sense when two or more same commands + are repeated. The mecanical position when the motor is switched off is + important. So, the braking delay couldn't be the same in both sense. */ void raiseWings(void) @@ -330,18 +395,22 @@ /** - \brief Lower wings + \brief Lower flippers \ingroup flippers - The condition to lower the wings is that they aren't already in the lower position. - If this condition is respected, a single movement is executed by the waveWings function. + The condition to lower the flippers is that they aren't already in the lower + position. If this condition is respected, a single movement is executed by + the waveWings function. - If the wings was in the lower position and has been raised manually, the wings can't be lowered directly. They must pass by the high position + If the flippers was in the lower position and has been raised manually, the + flippers can't be lowered directly. They must pass by the high position (raiseWings function) before being able to be lowered. - \note Implement conditions to be able to lower wings without pass by the high position increase code size and complicate the code. This implementation - need to toggle the motor sense when two or more same commands are repeated. - The mecanical position when the motor is switched off is important. So, the braking delay couldn't be the same in both sense. + \note Implement conditions to be able to lower flippers without pass by the + high position increase code size and complicate the code. This + implementation need to toggle the motor sense when two or more same commands + are repeated. The mecanical position when the motor is switched off is + important. So, the braking delay couldn't be the same in both sense. */ void lowerWings(void) @@ -354,16 +423,17 @@ \brief Blink the eyes \ingroup eyes - \param cnt number of movements before the wings will stop + \param cnt number of movements before the flippers will stop \note Any mouth command is cancelled - The eyes will start blinking until 'cnt' movements are executed. A movement is - raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is null, waving will run indefinitely. + The eyes will start blinking until 'cnt' movements are executed. A movement + is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is + null, waving will run indefinitely. */ void blinkEyes(uint8_t cnt) { - eyesPosCnt = cnt; - eyesStpCnt = 0; + eyes_move_counter = cnt; + eyes_stop_delay = 0; runEyes(); } @@ -373,19 +443,21 @@ Open the eyes if they are closed. - The eyes can be in three different states and should have a different behavior in all states. + The eyes can be in three different states and should have a different + behavior in all states. - Eyes opened - no movement is required. - Eyes closed - Just one movement is required to open the eyes. - indeterminated - two movements are required. To prevent that the motor can be activated when the eyes are opened and to stop the eyes in the open state by sending the open_eyes_cmd when they're - blinking, eyesPosCnt is initalised but the blinkEyes function isn't call. - If the motor is running, it will execute two movements before stop. If the motor - isn't switched on, nothing happens. + blinking, eyes_move_counter is initalised but the blinkEyes function isn't + call. + If the motor is running, it will execute two movements before stop. If the + motor isn't switched on, nothing happens. - \note XXX The computer side (API, daemon) must know than eyesPosCnt can be - not null with the motor switched off. + \note XXX The computer side (API, daemon) must know than eyes_move_counter + can be not null with the motor switched off. */ void openEyes(void) { @@ -396,7 +468,7 @@ blinkEyes(1); else - eyesPosCnt = 2; + eyes_move_counter = 2; } /** @@ -405,11 +477,11 @@ Close the eyes if they are opened. - When the close_eyes_cmd is received, if the eyes are closed, nothing happens. - But, when the eyes are blinking, this command must stop the eyes in the - closed position. To do this, eyesPosCnt is initialised, but the blinkEyes - function isn't call. So, if the command is received when the eyes are - blinking, two movements are executed before the motor is stopped. + When the close_eyes_cmd is received, if the eyes are closed, nothing + happens. But, when the eyes are blinking, this command must stop the eyes + in the closed position. To do this, eyes_move_counter is initialised, but + the blinkEyes function isn't call. So, if the command is received when the + eyes are blinking, two movements are executed before the motor is stopped. */ void closeEyes(void) { @@ -417,7 +489,7 @@ blinkEyes(1); else - eyesPosCnt = 2; + eyes_move_counter = 2; } /** @@ -426,13 +498,14 @@ \note Any eye command is cancelled \param cnt number of movements before the mouth will stop - The mouth will start blinking until 'cnt' movements are executed. A movement is - raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is null, waving will run indefinitely. + The mouth will start blinking until 'cnt' movements are executed. A movement + is raising or lowering the eyelids. 'cnt' can be up to 256. If 'cnt' is + null, waving will run indefinitely. */ void moveMouth(uint8_t cnt) { - mouthPosCnt = cnt; - mouthStpCnt = 0; + mouth_move_counter = cnt; + mouth_stop_delay = 0; runMouth(); } @@ -462,7 +535,7 @@ void stopSpin(void) { - spinPwmMask &= ~MOT_SPIN_MK; + spin_PWM_mask &= ~MOT_SPIN_MK; stopSpinMot(); } @@ -470,28 +543,28 @@ { /* Check if direction is changing and if pos. switch isn't push. Then, * increment angle value to prevent too short rotation */ - if (spinDirection == RIGHT && (PSW_SPIN_PIN & PSW_SPIN_MK)) + if (spin_direction == RIGHT && (PSW_SPIN_PIN & PSW_SPIN_MK)) { angle += 1; } - spinDirection = LEFT; - spinPosCnt = angle; - spinPwm = pwm; - spinPwmMask &= ~MOT_SPIN_R_MK; - spinPwmMask |= MOT_SPIN_L_MK; + spin_direction = LEFT; + spin_stop_delay = angle; + spin_PWM = pwm; + spin_PWM_mask &= ~MOT_SPIN_R_MK; + spin_PWM_mask |= MOT_SPIN_L_MK; } void spinRight(uint8_t angle, uint8_t pwm) { /* Check if direction is changing and if pos. switch isn't push. Then, * increment angle value to prevent too short rotation */ - if (spinDirection == LEFT && (PSW_SPIN_PIN & PSW_SPIN_MK)) + if (spin_direction == LEFT && (PSW_SPIN_PIN & PSW_SPIN_MK)) { angle += 1; } - spinDirection = RIGHT; - spinPosCnt = angle; - spinPwm = pwm; - spinPwmMask &= ~MOT_SPIN_L_MK; - spinPwmMask |= MOT_SPIN_R_MK; + spin_direction = RIGHT; + spin_stop_delay = angle; + spin_PWM = pwm; + spin_PWM_mask &= ~MOT_SPIN_L_MK; + spin_PWM_mask |= MOT_SPIN_R_MK; } Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/motors.h 2007-09-11 14:29:55 UTC (rev 509) @@ -19,9 +19,15 @@ /* $Id$ */ +/** \file motors.h + \brief Motor module interface + \ingroup movements +*/ + /** \defgroup movements Movements - The motor module contains all the functions necessery to control the movements of tux. + The motor module contains all the functions necessery to control the + movements of tux. */ /** \defgroup eyes Eyes @@ -48,34 +54,28 @@ This group contains all the functions to control the spinning. */ -/** \file motors.h - \ingroup movements -*/ - -/** \file motors.c - \ingroup movements -*/ #ifndef _MOTORS_H_ #define _MOTORS_H_ #include "hardware.h" -#define WINGS_TIM_RESET 0Xff -#define WINGS_TIM_DIFF 0x10 +#define flippers_PWMMask portB_PWM_mask +#define spin_PWM_mask portB_PWM_mask + enum mouth_pos_s { OPEN, CLOSE, UNDEFINED }; enum spin_direction { LEFT, RIGHT }; /* counters to stop eye/mouth and flippers at timer int */ -extern uint8_t wingsStpCnt, wingsPosCnt, wingsPwm; -extern uint8_t wings_tim, wings_prev_tim; -extern uint8_t eyesStpCnt, eyesPosCnt; -extern uint8_t mouthStpCnt, mouthPosCnt, mouth_pos; -extern uint8_t spinPosCnt, spinStpCnt, spinPwm; +extern uint8_t flippers_stop_delay, flippers_move_counter, flippers_PWM; +extern uint8_t flippers_timer, flippers_revious_timer; +extern uint8_t eyes_stop_delay, eyes_move_counter; +extern uint8_t mouth_stop_delay, mouth_move_counter, mouth_pos; +extern uint8_t spin_stop_delay, spin_move_counter, spin_PWM; /* pwm mask registers */ -extern uint8_t pwmMaskB; +extern uint8_t portB_PWM_mask; void initMotors(void); @@ -127,7 +127,8 @@ \brief Resets Tux's absolute turn reference \ingroup primitives - Compared to \c resetSpinOri(), this function only resets the turn count reference, not the angle. See gStatus.ori + Compared to \c resetSpinOri(), this function only resets the turn count + reference, not the angle. See gStatus.ori */ void resetSpinTurns(void); @@ -145,27 +146,31 @@ \brief Stop the eyes motor \ingroup eyes */ -#define stopEyes() (MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK)) +#define stopEyes() (MOT_EYES_PT &= ~(MOT_EYES_MK | MOT_IEYES_MK)) /** \brief Start the eyes motor \ingroup primitives */ -#define runEyes() {(MOT_EYES_PT &= ~MOT_IEYES_MK); (MOT_EYES_PT |= MOT_EYES_MK);} -#define runIEyes() {(MOT_EYES_PT &= ~MOT_EYES_MK); (MOT_EYES_PT |= MOT_IEYES_MK);} +#define runEyes() {(MOT_EYES_PT &= ~MOT_IEYES_MK); \ + (MOT_EYES_PT |= MOT_EYES_MK);} +#define runIEyes() {(MOT_EYES_PT &= ~MOT_EYES_MK); \ + (MOT_EYES_PT |= MOT_IEYES_MK);} /** - \brief Stop the mouth motor - \ingroup mouth - */ + \brief Stop the mouth motor + \ingroup mouth + */ #define stopMouth() (MOT_MOUTH_PT &= ~(MOT_MOUTH_MK | MOT_IMOUTH_MK)) /** \brief Start the mouth motor \ingroup primitives */ -#define runMouth() (MOT_MOUTH_PT &= ~MOT_IMOUTH_MK); (MOT_MOUTH_PT |= MOT_MOUTH_MK) -#define runIMouth() (MOT_MOUTH_PT &= ~MOT_MOUTH_MK); (MOT_MOUTH_PT |= MOT_IMOUTH_MK) +#define runMouth() (MOT_MOUTH_PT &= ~MOT_IMOUTH_MK); \ + (MOT_MOUTH_PT |= MOT_MOUTH_MK) +#define runIMouth() (MOT_MOUTH_PT &= ~MOT_MOUTH_MK);\ + (MOT_MOUTH_PT |= MOT_IMOUTH_MK) /** \brief Stop the flippers motor @@ -174,7 +179,7 @@ static inline void stopWings(void) __attribute__ ((always_inline)); void stopWings(void) { - wingsPwmMask &= ~MOT_WINGS_FW_MK; + flippers_PWMMask &= ~MOT_WINGS_FW_MK; MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK; MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; } @@ -185,8 +190,10 @@ Used to brake the flippers motor only */ -#define runWingsFw() {(MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK); (MOT_WINGS_FW_PT |= MOT_WINGS_FW_MK);} -#define runWingsBw() {(MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK); (MOT_WINGS_BW_PT |= MOT_WINGS_BW_MK);} +#define runWingsFw() {(MOT_WINGS_BW_PT &= ~MOT_WINGS_BW_MK); \ + (MOT_WINGS_FW_PT |= MOT_WINGS_FW_MK);} +#define runWingsBw() {(MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK); \ + (MOT_WINGS_BW_PT |= MOT_WINGS_BW_MK);} /** \brief Stop the spinning motor @@ -195,20 +202,23 @@ static inline void stopSpinMot(void) __attribute__ ((always_inline)); void stopSpinMot(void) { - spinPwmMask &= ~MOT_SPIN_MK; + spin_PWM_mask &= ~MOT_SPIN_MK; MOT_SPIN_PT &= ~MOT_SPIN_MK; } /** \brief Start spinning to the left \ingroup primitives */ -#define runSpinLeft() (MOT_SPIN_R_PT &= ~MOT_SPIN_R_MK); (MOT_SPIN_L_PT |= MOT_SPIN_L_MK) +#define runSpinLeft() (MOT_SPIN_R_PT &= ~MOT_SPIN_R_MK); \ + (MOT_SPIN_L_PT |= MOT_SPIN_L_MK) /** \brief Start spinning to the right \ingroup primitives */ -#define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) +#define runSpinRight() (MOT_SPIN_L_PT &= ~MOT_SPIN_L_MK); \ + (MOT_SPIN_R_PT |= MOT_SPIN_R_MK) + /** \brief Control the PWM of the spinning & flippers and motor braking. \ingroup primitives @@ -226,12 +236,12 @@ { /* Flippers PWM * Pulse is stopped here */ - if (pwm_tim == wingsPwm) + if (pwm_tim == flippers_PWM) MOT_WINGS_FW_PT &= ~MOT_WINGS_FW_MK; /* Spin PWM * Pulse is stopped here */ - if (pwm_tim == spinPwm) + if (pwm_tim == spin_PWM) MOT_SPIN_PT &= ~MOT_SPIN_MK; /* PWM motor management @@ -241,57 +251,57 @@ if (pwm_tim++ == PWM_PERIOD) { pwm_tim = 0; - PORTB |= pwmMaskB; /* spin and flippers */ + PORTB |= portB_PWM_mask; /* spin and flippers */ } /* Flippers timer to stop the flippers in any position */ - if (wings_tim) + if (flippers_timer) { - wings_tim--; - if (!wings_tim) + flippers_timer--; + if (!flippers_timer) { stopWings(); } } /* Flippers braking (motor reversed) delay */ - if (wingsStpCnt) + if (flippers_stop_delay) { - wingsStpCnt--; - if (!wingsStpCnt) + flippers_stop_delay--; + if (!flippers_stop_delay) { stopWings(); - wingsPwm = 0; + flippers_PWM = 0; } } /* eyes braking (motor reversed) delay */ - if (eyesStpCnt) + if (eyes_stop_delay) { - eyesStpCnt--; - if (!eyesStpCnt) + eyes_stop_delay--; + if (!eyes_stop_delay) { stopEyes(); } } /* mouth braking (motor reversed) delay */ - if (mouthStpCnt) + if (mouth_stop_delay) { - mouthStpCnt--; - if (!mouthStpCnt) + mouth_stop_delay--; + if (!mouth_stop_delay) { stopMouth(); } } /* spin braking (motor reversed) delay */ - if (spinStpCnt) + if (spin_move_counter) { - spinStpCnt--; - if (!spinStpCnt) - { - stopSpinMot(); - } + spin_move_counter--; + if (!spin_move_counter) + { + stopSpinMot(); + } } } #endif /* _MOTORS_H_ */ Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-11 14:07:55 UTC (rev 508) +++ firmware/tuxcore/trunk/standalone.c 2007-09-11 14:29:55 UTC (rev 509) @@ -209,7 +209,7 @@ if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) { stopSpin(); /* flush the spinning commands */ - spinPosCnt = 0; + spin_stop_delay = 0; } if (remote_mode) @@ -228,7 +228,8 @@ } /* IR signal processing */ - if (gStatus.ir != ir_oldvalue) /* put here things that should be done only once when a button is pushed */ + /* put here things that should be done only once when a button is pushed */ + if (gStatus.ir != ir_oldvalue) { ir_command = gStatus.ir & GSTATUS_IR_COMMAND; ir_toggle = gStatus.ir & GSTATUS_IR_TOGGLE; @@ -252,7 +253,9 @@ } /* Alt key pressed - * Leave this test after the ALT KEYS otherwise alt_mode is reset before the other commands are processed when you push the second key */ + * Leave this test after the ALT KEYS otherwise alt_mode is reset + * before the other commands are processed when you push the second key + * */ if (ir_command == K_ALT) alt_mode = 1; else @@ -285,10 +288,10 @@ waveWings(mov_nbr, 5); break; case K_LEFT: - spinLeft(mov_nbr, spinPwm); + spinLeft(mov_nbr, spin_PWM); break; case K_RIGHT: - spinRight(mov_nbr, spinPwm); + spinRight(mov_nbr, spin_PWM); break; case K_STOP: stopSpin(); @@ -305,20 +308,20 @@ toggleLeftLed(); break; case K_FASTREWIND: - if (spinPwm) - spinPwm--; + if (spin_PWM) + spin_PWM--; break; case K_FASTFORWARD: - if (spinPwm < 5) - spinPwm++; + if (spin_PWM < 5) + spin_PWM++; break; case K_PREVIOUS: - if (wingsPwm) - wingsPwm--; + if (flippers_PWM) + flippers_PWM--; break; case K_NEXT: - if (wingsPwm < 5) - wingsPwm++; + if (flippers_PWM < 5) + flippers_PWM++; break; } } |
From: jaguarondi <c2m...@c2...> - 2007-09-11 14:08:33
|
Author: jaguarondi Date: 2007-09-11 16:07:55 +0200 (Tue, 11 Sep 2007) New Revision: 508 Modified: firmware/tuxcore/trunk/fifo.c firmware/tuxcore/trunk/fifo.h firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/led.h Log: * Minor change on doxygen comments. Modified: firmware/tuxcore/trunk/fifo.c =================================================================== --- firmware/tuxcore/trunk/fifo.c 2007-09-10 14:59:45 UTC (rev 507) +++ firmware/tuxcore/trunk/fifo.c 2007-09-11 14:07:55 UTC (rev 508) @@ -19,16 +19,16 @@ /* $Id$ */ +/** \file fifo.c + \brief Circular buffer (FIFO) +*/ + #include <inttypes.h> #include "fifo.h" /** \weakgroup circular_buffer */ /*! @{ */ -/** \file fifo.c - \brief Circular buffer (FIFO) -*/ - /** \brief Empty the buffer by clearing the indexes. * \param p Fifo pointer. */ Modified: firmware/tuxcore/trunk/fifo.h =================================================================== --- firmware/tuxcore/trunk/fifo.h 2007-09-10 14:59:45 UTC (rev 507) +++ firmware/tuxcore/trunk/fifo.h 2007-09-11 14:07:55 UTC (rev 508) @@ -19,6 +19,24 @@ /* $Id$ */ +/** \file fifo.h + \ingroup circular_buffer + \brief Circular buffer (FIFO) + + \section Internals + + These routines are inspired from an article in Jack Ganssle's Embedded + Muse: http://www.ganssle.com/tem/tem110.pdf + + The buffer size must be a power of 2 and is limited to 128. This simplyfies + the wrap-around to a single AND operation which is only applied when + accessing the buffer but not applied on the in and out indexes. The indexes + increase from 0 to 255 then wrap to 0. With this method, the buffer is + empty when the indexes are equal and is full when the difference is equal + to the buffer size. Thus we can't use a buffer of 256 as it wouldn't be + possible to differentiate the buffer when it's empty or full. +*/ + #ifndef _FIFO_H_ #define _FIFO_H_ @@ -55,24 +73,6 @@ them with FifoPointer(). */ -/** \file fifo.h - \ingroup circular_buffer - \brief Circular buffer (FIFO) - - \section Internals - - These routines are inspired from an article in Jack Ganssle's Embedded - Muse: http://www.ganssle.com/tem/tem110.pdf - - The buffer size must be a power of 2 and is limited to 128. This simplyfies - the wrap-around to a single AND operation which is only applied when - accessing the buffer but not applied on the in and out indexes. The indexes - increase from 0 to 255 then wrap to 0. With this method, the buffer is - empty when the indexes are equal and is full when the difference is equal - to the buffer size. Thus we can't use a buffer of 256 as it wouldn't be - possible to differentiate the buffer when it's empty or full. -*/ - /* * Hidden from the interface */ Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-09-10 14:59:45 UTC (rev 507) +++ firmware/tuxcore/trunk/led.c 2007-09-11 14:07:55 UTC (rev 508) @@ -19,6 +19,11 @@ /* $Id$ */ +/** \file led.c + \brief Blue leds control module + \ingroup led +*/ + #include "global.h" #include "hardware.h" #include "led.h" Modified: firmware/tuxcore/trunk/led.h =================================================================== --- firmware/tuxcore/trunk/led.h 2007-09-10 14:59:45 UTC (rev 507) +++ firmware/tuxcore/trunk/led.h 2007-09-11 14:07:55 UTC (rev 508) @@ -26,14 +26,10 @@ */ /** \file led.h - \ingroup movements + \brief Blue leds control interface + \ingroup led */ -/** \file led.c - \ingroup movements -*/ - - #ifndef LED_H #define LED_H |
From: Paul_R <c2m...@c2...> - 2007-09-10 14:59:49
|
Author: Paul_R Date: 2007-09-10 16:59:45 +0200 (Mon, 10 Sep 2007) New Revision: 507 Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c Log: * Fix a bug in the playing audio functions - When a sound was played from the memory and, at the same time, a programming command was sent, the sound was not correctly stored in the data flash. At the end, the communication between tuxaudio and the RF was killed, and no more commands could not be sent. The only way to restart tux was to reflash tuxaudio firmware... Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-10 09:25:22 UTC (rev 506) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-10 14:59:45 UTC (rev 507) @@ -77,7 +77,7 @@ if (flash_state) erasingFlash(); - else if (read_status() & BUSY) + else if (!(read_status() & BUSY)) f_state ++; } else if (f_state == FIRST_PROG_STATE) @@ -175,23 +175,46 @@ FLASH_CS_OFF; // Chip Deselect /* Check adresses */ - if (ad[0] > TOP_A2) - return; /* don't read outside the flash */ + if (ad[0] > TOP_A2) + { + flashPlay = 0; + return; + } /* don't read outside the flash */ if (ad[3] > TOP_A2) - return; /* don't read outside the flash */ + { + flashPlay = 0; + return; + } /* don't read outside the flash */ if ((ad[0] == 0) && (ad[1] < 0x04)) - return; /* minimum index not respected */ + { + flashPlay = 0; + return; + } /* minimum index not respected */ if ((ad[4] == 0) && (ad[5] < 0x04)) - return; /* minimum index not respected */ + { + flashPlay = 0; + return; + } /* minimum index not respected */ if (ad[3] < ad[0]) - return; /* check that the stop index is greater than the start index */ + { + flashPlay = 0; + return; + } /* check that the stop index is greater than the start index */ else if (ad[3] == ad[0]) { if (ad[4] < ad[1]) + { + flashPlay = 0; return; + } else if (ad[4] == ad[1]) + { if (ad[5] <= ad[2]) + { + flashPlay = 0; return; + } + } } FLASH_CS_ON; // Chip Select |
From: Paul_R <c2m...@c2...> - 2007-09-10 09:25:24
|
Author: Paul_R Date: 2007-09-10 11:25:22 +0200 (Mon, 10 Sep 2007) New Revision: 506 Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c Log: * Corrected bug in the playSound function - with rev 505, if you play an incorrect sound (for ex. tux.cmd.sound_play(0)), you cannot play another sound. Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-10 08:59:09 UTC (rev 505) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-10 09:25:22 UTC (rev 506) @@ -136,9 +136,15 @@ sounds_stored = read_data(0x00, 0x00, 0x00); if (sounds_stored == 0xFF) /* if unprogrammed we have 0xFF stored in flash */ + { + flashPlay = 0; return; + } if (!nsound || (nsound > sounds_stored)) /* check the limits */ + { + flashPlay = 0; return; + } count = 1; adp1 = 0x00; |