#include <math.h>

#include "defBF535.h"

#define DELAY_LOOP      0xFFFFF

volatile unsigned short * fio_dir_reg;

volatile unsigned short * fio_set_reg;

volatile unsigned short * fio_clr_reg;

void delay( void );

void main(){

         int i;

         // These lie in the General Purpose IO address space

         // FIO_DIR is the Peripheral Flag Direction Register

         // FIO_DIR is defined as 0xFFC02400

        fio_dir_reg = ( unsigned short *)FIO_DIR;

         // FIO_FLAG_C is the Peripheral Interrupt Flag Register (clear)

         // FIO_FLAG_C is defined as 0xFFC02404

        fio_set_reg = ( unsigned short *)FIO_FLAG_S;

         // FIO_FLAG_S is the Peripheral Interrupt Flag Register (set)

         // FIO_FLAG_S is defined as 0xFFC02406

        fio_clr_reg = ( unsigned short *)FIO_FLAG_C;

         // set PF0 - PF3 as output */

        *fio_dir_reg = ( unsigned short ) 0x00FF ;

         // i.e.,

         // 0000 0000 0000 1111

         while ( ( int )fio_dir_reg % ( int )pow( 2 , 6 ) == 0 ) {

                printf( "%X\n" ,fio_dir_reg);

                 for (i= 16 ;i> 0 ;i--) {

                         // clear all the LED

                        *fio_set_reg = ( unsigned short ) 0x000F ;

                        *fio_clr_reg = ( unsigned short ) i;

                        delay();

                         asm ( "ssync;" );

                }

        }

}

// a simple delay routine

void delay() {

         unsigned long   i;

         for (i= 0 ; i<DELAY_LOOP; i++) {

                 asm ( "nop;nop;nop;" );

        }

         asm ( "ssync;" );

         return ;

}