Changeset f09f059 in mainline
- Timestamp:
- 2013-02-13T22:10:05Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ddb3051
- Parents:
- 4a09b86
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/drivers/am335x/timer.c
r4a09b86 rf09f059 38 38 #include <errno.h> 39 39 40 typedef enum { 41 REG_TCLR = 0x00, 42 REG_TCRR = 0x01, 43 REG_TLDR = 0x02, 44 REG_TTGR = 0x04 45 } timer_reg_t; 40 46 41 47 typedef struct timer_regs_mmap { … … 54 60 { .base = AM335x_DMTIMER7_BASE_ADDRESS, .size = AM335x_DMTIMER7_SIZE }, 55 61 }; 62 63 static void 64 write_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 } 56 84 57 85 void … … 75 103 am335x_timer_regs_t *regs = timer->regs; 76 104 105 /* Enable the posted mode of operation */ 106 regs->tsicr |= AM335x_TIMER_TSICR_POSTED_FLAG; 107 77 108 /* Stop the timer */ 78 109 am335x_timer_stop(timer); … … 81 112 am335x_timer_reset(timer); 82 113 114 unsigned tclr = regs->tclr; 115 116 /* Disable compare mode */ 117 tclr &= ~AM335x_TIMER_TCLR_CE_FLAG; 83 118 /* 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; 85 122 86 /* Enable auto-reload mode */ 87 regs->tclr |= AM335x_TIMER_TCLR_AR_FLAG; 123 write_register_posted(timer, REG_TCLR, tclr); 88 124 89 125 /* Disable the emulation mode */ 90 126 regs->tiocp_cfg |= AM335x_TIMER_TIOCPCFG_EMUFREE_FLAG; 91 127 92 unsigned const count = 0xFFFFFFF E - (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); 95 131 } 96 132 … … 116 152 /* Disable the interrupt */ 117 153 timer->regs->irqenable_clr |= AM335x_TIMER_IRQENABLE_CLR_OVF_FLAG; 154 timer->regs->irqwakeen &= ~AM335x_TIMER_IRQWAKEEN_OVF_FLAG; 118 155 /* 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); 120 158 } 121 159 … … 125 163 /* Enable the interrupt */ 126 164 timer->regs->irqenable_set |= AM335x_TIMER_IRQENABLE_SET_OVF_FLAG; 165 timer->regs->irqwakeen |= AM335x_TIMER_IRQWAKEEN_OVF_FLAG; 127 166 /* 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); 129 169 } 130 170
Note:
See TracChangeset
for help on using the changeset viewer.