Subversion Repositories HomeAutomation

Rev

Rev 183 | Blame | Last modification | View Log | SVN | RSS feed

  1. #include <inttypes.h>
  2. #include <avr/interrupt.h>
  3. #include <bios.h>
  4.  
  5. static int app_putchar(char c, FILE *stream);
  6. static int app_getchar(FILE *stream);
  7.  
  8. static FILE mystdio = FDEV_SETUP_STREAM(app_putchar, app_getchar,
  9.                                          _FDEV_SETUP_RW);
  10.  
  11. static int app_putchar(char c, FILE *stream) {
  12.     bios->can_send(c);
  13.     return 0;
  14. }
  15.    
  16. static int app_getchar(FILE *stream) {
  17.     return bios->can_receive();
  18. }
  19.  
  20. int main(void)
  21. {
  22.     long time;
  23.     long time1 = 0;
  24.     long time2 = 0;
  25.    
  26.     sei();
  27.    
  28.     stdout = &mystdio;
  29.     stdin = &mystdio;
  30.    
  31.     printf("AVR Test Application\n");
  32.     printf("Using AVR BIOS version %x\n", bios->version);
  33.    
  34.     while (1) {
  35.         time = bios->timebase_get();
  36.         if ((time - time1) >= 2000) {
  37.             time1 = time;
  38.             printf("Two seconds passed, time is now %d.\n", (int)time);
  39.         }
  40.  
  41.         if ((time - time2) >= 20000) {
  42.             time2 = time;
  43.             printf("Will now hang node.\n");
  44.             cli();
  45.         }
  46.     }
  47.    
  48.     return 0;
  49. }
  50.