Ignore:
Timestamp:
2013-02-13T22:10:05Z (11 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ddb3051
Parents:
4a09b86
Message:

write the timer registers in posted mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/drivers/am335x/timer.c

    r4a09b86 rf09f059  
    3838#include <errno.h>
    3939
     40typedef enum {
     41        REG_TCLR = 0x00,
     42        REG_TCRR = 0x01,
     43        REG_TLDR = 0x02,
     44        REG_TTGR = 0x04
     45} timer_reg_t;
    4046
    4147typedef struct timer_regs_mmap {
     
    5460        { .base = AM335x_DMTIMER7_BASE_ADDRESS, .size = AM335x_DMTIMER7_SIZE },
    5561};
     62
     63static void
     64write_register_posted(am335x_timer_t *timer, timer_reg_t reg, uint32_t value)
     65{
     66        am335x_timer_regs_t *regs = timer->regs;
     67
     68        while (regs->twps & reg);
     69
     70        switch (reg) {
     71        default:
     72                return;
     73        case REG_TCLR:
     74                regs->tclr = value;
     75                break;
     76        case REG_TCRR:
     77                regs->tcrr = value;
     78                break;
     79        case REG_TLDR:
     80                regs->tldr = value;
     81                break;
     82        }
     83}
    5684
    5785void
     
    75103        am335x_timer_regs_t *regs = timer->regs;
    76104
     105        /* Enable the posted mode of operation */
     106        regs->tsicr |= AM335x_TIMER_TSICR_POSTED_FLAG;
     107
    77108        /* Stop the timer */
    78109        am335x_timer_stop(timer);
     
    81112        am335x_timer_reset(timer);
    82113
     114        unsigned tclr = regs->tclr;
     115
     116        /* Disable compare mode */
     117        tclr &= ~AM335x_TIMER_TCLR_CE_FLAG;
    83118        /* Disable the prescaler */
    84         regs->tclr &= ~AM335x_TIMER_TCLR_PRE_FLAG;
     119        tclr &= ~AM335x_TIMER_TCLR_PRE_FLAG;
     120        /* Enable auto-reload mode */
     121        tclr |= AM335x_TIMER_TCLR_AR_FLAG;
    85122
    86         /* Enable auto-reload mode */
    87         regs->tclr |= AM335x_TIMER_TCLR_AR_FLAG;
     123        write_register_posted(timer, REG_TCLR, tclr);
    88124
    89125        /* Disable the emulation mode */
    90126        regs->tiocp_cfg |= AM335x_TIMER_TIOCPCFG_EMUFREE_FLAG;
    91127
    92         unsigned const count = 0xFFFFFFFE - (srcclk_hz / hz);
    93         regs->tcrr = count;
    94         regs->tldr = count;
     128        unsigned const count = 0xFFFFFFFF - (srcclk_hz / hz + 1);
     129        write_register_posted(timer, REG_TCRR, count);
     130        write_register_posted(timer, REG_TLDR, count);
    95131}
    96132
     
    116152        /* Disable the interrupt */
    117153        timer->regs->irqenable_clr |= AM335x_TIMER_IRQENABLE_CLR_OVF_FLAG;
     154        timer->regs->irqwakeen &= ~AM335x_TIMER_IRQWAKEEN_OVF_FLAG;
    118155        /* Stop the timer */
    119         timer->regs->tclr &= ~AM335x_TIMER_TCLR_ST_FLAG;
     156        write_register_posted(timer, REG_TCLR,
     157            timer->regs->tclr & ~AM335x_TIMER_TCLR_ST_FLAG);
    120158}
    121159
     
    125163        /* Enable the interrupt */
    126164        timer->regs->irqenable_set |= AM335x_TIMER_IRQENABLE_SET_OVF_FLAG;
     165        timer->regs->irqwakeen |= AM335x_TIMER_IRQWAKEEN_OVF_FLAG;
    127166        /* Start the clock */
    128         timer->regs->tclr |= AM335x_TIMER_TCLR_ST_FLAG;
     167        write_register_posted(timer, REG_TCLR,
     168            timer->regs->tclr | AM335x_TIMER_TCLR_ST_FLAG);
    129169}
    130170
Note: See TracChangeset for help on using the changeset viewer.