Hallo
Ich habe es nun doch übersetzt bekommen. Da ich ja noch meine alte AVR-GCC-Installation verwende (never chance a runing system;) kann ich nicht sagen, ob die Probleme representativ sind:
-In allen Funktionsprototypen ein void in die Klammern eingefügt, auch in main()
-Alle #include "" nach <> geändert
-Trotz anscheinend korrekt eingebundener atomic.h klappte das Kompillieren erst nachdem ich überall die atomic-Funktionen mit cli()--sei() ersetzt hatte. atomic.h verhindert u.a. Fehler bei gleichzeitigem Zugriff von Programm und ISR auf eine mehr als 8bit-Variable und rettet wichtige Register. Änderungsbeispiel in motpwm.c:
Code:
void motpwm_stop(void) {
//ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
cli();
motpwm_motor_l = 0;
motpwm_motor_r = 0;
PWM_TIMER_OCRA = 0;
PWM_TIMER_OCRB = 0;
sei();
}
}
Meine atomic.h:
Code:
/* Copyright (c) 2007 Dean Camera
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* $Id: atomic.h,v 1.3 2007/12/20 14:17:56 joerg_wunsch Exp $ */
#ifndef _UTIL_ATOMIC_H_
#define _UTIL_ATOMIC_H_ 1
#include <avr/io.h>
#include <avr/interrupt.h>
#if !defined(__DOXYGEN__)
/* Internal helper functions. */
static __inline__ uint8_t __iSeiRetVal(void)
{
sei();
return 1;
}
static __inline__ uint8_t __iCliRetVal(void)
{
cli();
return 1;
}
static __inline__ void __iSeiParam(const uint8_t *__s)
{
sei();
__asm__ volatile ("" ::: "memory");
(void)__s;
}
static __inline__ void __iCliParam(const uint8_t *__s)
{
cli();
__asm__ volatile ("" ::: "memory");
(void)__s;
}
static __inline__ void __iRestore(const uint8_t *__s)
{
SREG = *__s;
__asm__ volatile ("" ::: "memory");
}
#endif /* !__DOXYGEN__ */
#if defined(__DOXYGEN__)
#define ATOMIC_BLOCK(type)
#else
#define ATOMIC_BLOCK(type) for ( type, __ToDo = __iCliRetVal(); \
__ToDo ; __ToDo = 0 )
#endif /* __DOXYGEN__ */
/** \def NONATOMIC_BLOCK(type)
\ingroup util_atomic
Creates a block of code that is executed non-atomically. Upon
entering the block the Global Interrupt Status flag in SREG is
enabled, and disabled upon exiting the block from any exit
path. This is useful when nested inside ATOMIC_BLOCK sections,
allowing for non-atomic execution of small blocks of code while
maintaining the atomic access of the other sections of the parent
ATOMIC_BLOCK.
Two possible macro parameters are permitted,
NONATOMIC_RESTORESTATE and NONATOMIC_FORCEOFF.
*/
#if defined(__DOXYGEN__)
#define NONATOMIC_BLOCK(type)
#else
#define NONATOMIC_BLOCK(type) for ( type, __ToDo = __iSeiRetVal(); \
__ToDo ; __ToDo = 0 )
#endif /* __DOXYGEN__ */
/** \def ATOMIC_RESTORESTATE
\ingroup util_atomic
This is a possible parameter for ATOMIC_BLOCK. When used, it will
cause the ATOMIC_BLOCK to restore the previous state of the SREG
register, saved before the Global Interrupt Status flag bit was
disabled. The net effect of this is to make the ATOMIC_BLOCK's
contents guaranteed atomic, without changing the state of the
Global Interrupt Status flag when execution of the block
completes.
*/
#if defined(__DOXYGEN__)
#define ATOMIC_RESTORESTATE
#else
#define ATOMIC_RESTORESTATE uint8_t sreg_save \
__attribute__((__cleanup__(__iRestore))) = SREG
#endif /* __DOXYGEN__ */
/** \def ATOMIC_FORCEON
\ingroup util_atomic
This is a possible parameter for ATOMIC_BLOCK. When used, it will
cause the ATOMIC_BLOCK to force the state of the SREG register on
exit, enabling the Global Interrupt Status flag bit. This saves on
flash space as the previous value of the SREG register does not
need to be saved at the start of the block.
Care should be taken that ATOMIC_FORCEON is only used when it is
known that interrupts are enabled before the block's execution or
when the side effects of enabling global interrupts at the block's
completion are known and understood.
*/
#if defined(__DOXYGEN__)
#define ATOMIC_FORCEON
#else
#define ATOMIC_FORCEON uint8_t sreg_save \
__attribute__((__cleanup__(__iSeiParam))) = 0
#endif /* __DOXYGEN__ */
/** \def NONATOMIC_RESTORESTATE
\ingroup util_atomic
This is a possible parameter for NONATOMIC_BLOCK. When used, it
will cause the NONATOMIC_BLOCK to restore the previous state of
the SREG register, saved before the Global Interrupt Status flag
bit was enabled. The net effect of this is to make the
NONATOMIC_BLOCK's contents guaranteed non-atomic, without changing
the state of the Global Interrupt Status flag when execution of
the block completes.
*/
#if defined(__DOXYGEN__)
#define NONATOMIC_RESTORESTATE
#else
#define NONATOMIC_RESTORESTATE uint8_t sreg_save \
__attribute__((__cleanup__(__iRestore))) = SREG
#endif /* __DOXYGEN__ */
/** \def NONATOMIC_FORCEOFF
\ingroup util_atomic
This is a possible parameter for NONATOMIC_BLOCK. When used, it
will cause the NONATOMIC_BLOCK to force the state of the SREG
register on exit, disabling the Global Interrupt Status flag
bit. This saves on flash space as the previous value of the SREG
register does not need to be saved at the start of the block.
Care should be taken that NONATOMIC_FORCEOFF is only used when it
is known that interrupts are disabled before the block's execution
or when the side effects of disabling global interrupts at the
block's completion are known and understood.
*/
#if defined(__DOXYGEN__)
#define NONATOMIC_FORCEOFF
#else
#define NONATOMIC_FORCEOFF uint8_t sreg_save \
__attribute__((__cleanup__(__iCliParam))) = 0
#endif /* __DOXYGEN__ */
#endif
-In der For-Schleife will mein Kompiller keine Variablendeklaration akzepieren
-Die Variable uint16_t nibobee_initialization von Hand erzeugt. Ich weiß noch nicht, wo die normalerweise herkommen sollte.
Meine mit 2386 Bytes übersetzte Version des Liniendemos sieht nun so aus:
Code:
// kleines Linienfolgedemo (nachbearbeitet) 14.10.09 mic
// https://www.roboternetz.de/phpBB2/vi...=470433#470433
// https://www.roboternetz.de/phpBB2/ze...=468642#468642
#include <nibobee/iodefs.h>
#include <nibobee/motpwm.h>
#include <nibobee/analog.h>
#include <nibobee/line.h>
#include <nibobee/led.h>
#include <nibobee/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
uint8_t i;
uint16_t nibobee_initialization;
int main(void) {
activate_output_group(IO_LEDS); // LED bits als Output
motpwm_init();
motpwm_setLeft(0);
motpwm_setRight(0);
analog_init();
line_readPersistent();
set_output_group(IO_SENS); // Pull-ups aktivieren
activate_output_bit(IO_LINE_EN);
int16_t speed_flt_l=0;
int16_t speed_flt_r=0;
// Countdown: LEDs blinken lassen
for (i=0; i<10; ++i) {
led_set(LED_L_RD, 1);
led_set(LED_R_RD, 1);
_delay_ms(10);
led_set(LED_L_RD, 0);
led_set(LED_R_RD, 0);
_delay_ms(990);
}
led_set(LED_L_YE, 1);
led_set(LED_R_YE, 1);
_delay_ms(1000);
led_set(LED_L_YE, 0);
led_set(LED_R_YE, 0);
// Hauptschleife:
while(1) {
sei();
_delay_ms(1);
int16_t speed_l=0;
int16_t speed_r=0;
int16_t lval = line_get(LINE_L);
int16_t cval = line_get(LINE_C);
int16_t rval = line_get(LINE_R);
if (lval+cval+rval < 20) {
led_set(LED_L_RD, 0);
led_set(LED_R_RD, 0);
speed_r=0, speed_l=0;
} else if ((lval<cval) && (lval<rval)) {
// lval is minimum
led_set(LED_L_RD, 1);
led_set(LED_R_RD, 0);
speed_r=550, speed_l=450-1*(cval-lval);
} else if ((rval<cval) && (rval<lval)) {
// rval is minimum
led_set(LED_L_RD, 0);
led_set(LED_R_RD, 1);
speed_r=450-1*(cval-rval), speed_l=550;
} else {
// cval is minimum
led_set(LED_L_RD, 1);
led_set(LED_R_RD, 1);
speed_r=750 + 1*(rval-cval), speed_l=750 + 1*(lval-cval);
}
speed_flt_l*=3; speed_flt_l+=speed_l; speed_flt_l/=4;
speed_flt_r*=3; speed_flt_r+=speed_r; speed_flt_r/=4;
motpwm_setLeft(speed_flt_l);
motpwm_setRight(speed_flt_r);
}
return 0;
}
Und kann das:
Bild hier
http://www.youtube.com/watch?v=WaxGDNcvVpo
Der Löthilfeschaumstoff hat mich locker eine halbe Stunde Zeit gekostet, weil die beiden Odo-IR-LEDs unter ihm versteckt (festgeklammert!) waren ;)
Gruß
mic
[Edit]
Achtung! Nach dem Übertragen des Programms schwirrt die Biene sofort los!
Lesezeichen