avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Release philosofy questions


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] Release philosofy questions
Date: Wed, 23 Oct 2002 18:55:03 +0200
User-agent: Mutt/1.2.5i

As Theodore A. Roth wrote:

> OT: Joerg, don't forget to update the NEWS file with the new interfaces
> you've added.

OK.  Well, probably rather a verbal summary, and a pointer to the
documentation.

> Also, could you make a simple test program available so I
> can start reviewing the new stuff? (I've been a bad boy and haven't looked
> at it yet, sorry :-( )

You mean, something to test printf() & Co with?

Here's my current test case.  Of course, the float formats are not
supposed to work with the CVS version of vfprintf(), but they should
at least be parsed correctly.  IIRC, they are supposed to print a
single `?'.

Also, linking against -lprintf_min is supposed to work, see the
documentation.

As you can see from the #defines :), this is currently being tested on
an ATmega128.  Other chips are supposed to work as well, except you
need quite a bit of flash for all my constant strings here.  My
floating point test is now already close to 8 KB flash in total, but
the non-FP version shouldn't use much more than 5 KB or so.

I'd appreciate if people could stress-test all this a bit.  All the
documented functionality is supposed to be functioning.

If you're going to emulate it in simulavr, put an #if 0 around the
loop_until_bit_is_set() call in uart_putchar().

You'll probably be as surprised as i've been when seeing how much
random garbage there is in your uninitialized RAM. :-)

#include <stdio.h>
#include <string.h>

#include <avr/io.h>
#include <avr/pgmspace.h>

//#define SYSCLK 9216000UL      /* CPU clock in Hertz */
#define SYSCLK 14745600UL
//#define SYSCLK 4000000UL      /* CPU clock in Hertz */

#ifndef UCSRB
# ifdef UCSR1A          /* ATmega128 */
#  define UCSRA UCSR1A
#  define UCSRB UCSR1B
#  define UBRR UBRR1L
#  define UDR UDR1
# else /* ATmega8 */
#  define UCSRA USR
#  define UCSRB UCR
# endif
#endif

/*
 * Do all the startup-time peripheral initializations.
 */
void
ioinit(void)
{

  UCSRB = _BV(TXEN);            /* tx enable */
  UBRR = (SYSCLK / (16 * 9600UL)) - 1; /* 9600 Bd */
}

/*
 * Some simple UART IO functions.
 */

/*
 * Send character c down the UART Tx, wait until tx holding register
 * is empty.
 */
int
uart_putchar(char c)
{

  if (c == '\n')
    uart_putchar('\r');
  loop_until_bit_is_set(UCSRA, UDRE);
  outb(UDR, c);
  return 0;
}


char b[50];

void
main(void)
{
  FILE *y;
  unsigned char *cp;
  size_t s;

  ioinit();

  y = fdevopen(uart_putchar, NULL, 0);
  fprintf(y, "Hi there!\n");
  fprintf_P(y, PSTR("y fdevopen()ed, y: %p\r\n__iob: %p\r\n"),
            (void *)y, (void *)__iob);

  sprintf_P(b, PSTR("float test %+-8.3eXX"), 3.1415926);
  printf("%s\n", b);
  printf_P(PSTR("More float: % 014.5E\n"), 4.134136e31);
  printf_P(PSTR("More float: %+014.5e\n"), 4.134136e31);
  printf_P(PSTR("More float: %+14.5E\n"), 4.134136e31);
  printf_P(PSTR("More float: % 014.5e\n"), -2.34234e-31);
  printf_P(PSTR("More float: % 014.5E\n"), -2.34234e-31);
  printf_P(PSTR("More float: %+14.5e\n"), -2.34234e-31);
  
  printf("First %d bytes of SRAM:\n", 0x300 - 0x100);
  for (cp = (unsigned char *)0x100; cp < (unsigned char *)0x300; cp++) {
    int i = (int)cp;

    if (i % 16 == 0)
      fprintf(y, "%04x: ", i);
    fprintf(y, "%02x", (int)*cp);
    if (i % 16 == 15)
      uart_putchar('\n');
    else
      uart_putchar(' ');
  }

  uart_putchar('\n');

  printf_P(PSTR("String alignment tests:\n%-30s\n%30s\n"), "hello",
           "world");
  printf_P(PSTR("Number formatting:\n%%+15d: %+15d\n"), 243, 243);
  s = snprintf(b, 20, "This will become very lengthy.");
  printf_P(PSTR("overflowing snprintf(), len %d, result %s\n"),
           s, b);
  printf_P(PSTR("My clock frequency (long int): %ld\n"), SYSCLK);
  printf_P(PSTR("%%06.04i test: %06.04i\n"), 42);
  printf_P(PSTR("More stress testing: %%+28i %+28i, %% .14i % .14i\n"),
           4532, 1234);
  fprintf(stderr, "That's all by now.\n");
}

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]