]> git.sur5r.net Git - u-boot/blobdiff - examples/timer.c
Reorganize and fix problems (returns) in the bootm command.
[u-boot] / examples / timer.c
index 8d60fc882689fa4d0765740ad56aebb40024d058..13ec06f02c44453b991329e49b97f052b47d204f 100644 (file)
@@ -24,7 +24,9 @@
 #include <common.h>
 #include <commproc.h>
 #include <mpc8xx_irq.h>
-#include <syscall.h>
+#include <exports.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 #undef DEBUG
 
@@ -104,7 +106,6 @@ typedef struct tid_8xx_cpmtimer_s {
 #define        CPMT_MR_CE_ANY          0x00C0  /* Capt./Interr. on any TIN edge*/
 
 
-
 /*
  * which CPM timer to use - index starts at 0 (= timer 1)
  */
@@ -116,17 +117,18 @@ static char *usage = "\n[q, b, e, ?] ";
 
 int timer (int argc, char *argv[])
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        cpmtimer8xx_t *cpmtimerp;       /* Pointer to the CPM Timer structure   */
        tid_8xx_cpmtimer_t hw;
        tid_8xx_cpmtimer_t *hwp = &hw;
        int c;
+       int running;
+
+       app_startup(argv);
 
        /* Pointer to CPM Timer structure */
        cpmtimerp = &((immap_t *) gd->bd->bi_immr_base)->im_cpmtimer;
 
-       mon_printf ("TIMERS=0x%x\n", (unsigned) cpmtimerp);
+       printf ("TIMERS=0x%x\n", (unsigned) cpmtimerp);
 
        /* Initialize pointers depending on which timer we use */
        switch (TID_TIMER_ID) {
@@ -166,7 +168,7 @@ int timer (int argc, char *argv[])
 
        hwp->tgcrp = &cpmtimerp->cpmt_tgcr;
 
-       mon_printf ("Using timer %d\n"
+       printf ("Using timer %d\n"
                        "tgcr @ 0x%x, tmr @ 0x%x, trr @ 0x%x,"
                        " tcr @ 0x%x, tcn @ 0x%x, ter @ 0x%x\n",
                        TID_TIMER_ID + 1,
@@ -184,22 +186,24 @@ int timer (int argc, char *argv[])
        /* clear all events */
        *hwp->terp = (CPMT_EVENT_CAP | CPMT_EVENT_REF);
 
-       mon_printf (usage);
-       while ((c = mon_getc()) != 'q') {
+       printf (usage);
+       running = 0;
+       while ((c = getc()) != 'q') {
            if (c == 'b') {
 
                setPeriod (hwp, TIMER_PERIOD);  /* Set period and start ticking */
 
                /* Install interrupt handler (enable timer in CIMR) */
-               mon_install_hdlr (hwp->cpm_vec, timer_handler, hwp);
+               install_hdlr (hwp->cpm_vec, timer_handler, hwp);
 
-               mon_printf ("Enabling timer\n");
+               printf ("Enabling timer\n");
 
                /* enable timer */
                *hwp->tgcrp |= (CPMT_GCR_RST << TID_TIMER_ID);
+               running = 1;
 
 #ifdef DEBUG
-               mon_printf ("tgcr=0x%x, tmr=0x%x, trr=0x%x,"
+               printf ("tgcr=0x%x, tmr=0x%x, trr=0x%x,"
                        " tcr=0x%x, tcn=0x%x, ter=0x%x\n",
                                *hwp->tgcrp, *hwp->tmrp, *hwp->trrp,
                                *hwp->tcrp,  *hwp->tcnp, *hwp->terp
@@ -207,19 +211,20 @@ int timer (int argc, char *argv[])
 #endif
            } else if (c == 'e') {
 
-               mon_printf ("Stopping timer\n");
+               printf ("Stopping timer\n");
 
                *hwp->tgcrp &= ~(CPMT_GCR_MASK << TID_TIMER_ID);
+               running = 0;
 
 #ifdef DEBUG
-               mon_printf ("tgcr=0x%x, tmr=0x%x, trr=0x%x,"
+               printf ("tgcr=0x%x, tmr=0x%x, trr=0x%x,"
                        " tcr=0x%x, tcn=0x%x, ter=0x%x\n",
                                *hwp->tgcrp, *hwp->tmrp, *hwp->trrp,
                                *hwp->tcrp,  *hwp->tcnp, *hwp->terp
                        );
 #endif
                /* Uninstall interrupt handler */
-               mon_free_hdlr (hwp->cpm_vec);
+               free_hdlr (hwp->cpm_vec);
 
            } else if (c == '?') {
 #ifdef DEBUG
@@ -227,13 +232,13 @@ int timer (int argc, char *argv[])
                sysconf8xx_t *siup = &((immap_t *) gd->bd->bi_immr_base)->im_siu_conf;
 #endif
 
-               mon_printf ("\ntgcr=0x%x, tmr=0x%x, trr=0x%x,"
+               printf ("\ntgcr=0x%x, tmr=0x%x, trr=0x%x,"
                        " tcr=0x%x, tcn=0x%x, ter=0x%x\n",
                                *hwp->tgcrp, *hwp->tmrp, *hwp->trrp,
                                *hwp->tcrp,  *hwp->tcnp, *hwp->terp
                        );
 #ifdef DEBUG
-               mon_printf ("SIUMCR=0x%08lx, SYPCR=0x%08lx,"
+               printf ("SIUMCR=0x%08lx, SYPCR=0x%08lx,"
                        " SIMASK=0x%08lx, SIPEND=0x%08lx\n",
                                siup->sc_siumcr,
                                siup->sc_sypcr,
@@ -241,17 +246,23 @@ int timer (int argc, char *argv[])
                                siup->sc_sipend
                        );
 
-               mon_printf ("CIMR=0x%08lx, CICR=0x%08lx, CIPR=0x%08lx\n",
+               printf ("CIMR=0x%08lx, CICR=0x%08lx, CIPR=0x%08lx\n",
                        cpm_icp->cpic_cimr,
                        cpm_icp->cpic_cicr,
                        cpm_icp->cpic_cipr
                        );
 #endif
            } else {
-               mon_printf ("\nEnter: q - quit, b - start timer, e - stop timer, ? - get status\n");
+               printf ("\nEnter: q - quit, b - start timer, e - stop timer, ? - get status\n");
            }
-           mon_printf (usage);
+           printf (usage);
        }
+       if (running) {
+               printf ("Stopping timer\n");
+               *hwp->tgcrp &= ~(CPMT_GCR_MASK << TID_TIMER_ID);
+               free_hdlr (hwp->cpm_vec);
+       }
+
        return (0);
 }
 
@@ -265,11 +276,11 @@ void setPeriod (tid_8xx_cpmtimer_t *hwp, ulong interval)
        unsigned short prescaler;
        unsigned long ticks;
 
-       mon_printf ("Set interval %ld us\n", interval);
+       printf ("Set interval %ld us\n", interval);
 
        /* Warn if requesting longer period than possible */
        if (interval > CPMT_MAX_INTERVAL) {
-               mon_printf ("Truncate interval %ld to maximum (%d)\n",
+               printf ("Truncate interval %ld to maximum (%d)\n",
                                interval, CPMT_MAX_INTERVAL);
                interval = CPMT_MAX_INTERVAL;
        }
@@ -294,7 +305,7 @@ void setPeriod (tid_8xx_cpmtimer_t *hwp, ulong interval)
        }
 
 #ifdef DEBUG
-       mon_printf ("clock/%d, prescale factor %d, reference %ld, ticks %ld\n",
+       printf ("clock/%d, prescale factor %d, reference %ld, ticks %ld\n",
                        (ticks > CPMT_MAX_TICKS) ? CPMT_CLOCK_DIV : 1,
                        CPMT_PRESCALER,
                        (ticks / CPMT_PRESCALER),
@@ -312,7 +323,7 @@ void setPeriod (tid_8xx_cpmtimer_t *hwp, ulong interval)
        *hwp->trrp = (unsigned short) (ticks / CPMT_PRESCALER);
 
 #ifdef DEBUG
-       mon_printf ("tgcr=0x%x, tmr=0x%x, trr=0x%x,"
+       printf ("tgcr=0x%x, tmr=0x%x, trr=0x%x,"
                " tcr=0x%x, tcn=0x%x, ter=0x%x\n",
                        *hwp->tgcrp, *hwp->tmrp, *hwp->trrp,
                        *hwp->tcrp,  *hwp->tcnp, *hwp->terp
@@ -331,7 +342,7 @@ void timer_handler (void *arg)
        /* printf ("** TER1=%04x ** ", *hwp->terp); */
 
        /* just for demonstration */
-       mon_printf (".");
+       printf (".");
 
        /* clear all possible events: Ref. and Cap. */
        *hwp->terp = (CPMT_EVENT_CAP | CPMT_EVENT_REF);