3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 uint32_t timer_base[] = { TIMER0_BASE, TIMER1_BASE, TIMER2_BASE, TIMER3_BASE };
27 uint32_t gptm_read_timer(uint8_t timerno, uint8_t b){
31 return HW_REG(timer_base[timerno]+(b?GPTM_TBV_OFFSET:GPTM_TAV_OFFSET));
34 void gptm_write_timer(uint8_t timerno, uint8_t b, uint32_t value){
38 HW_REG(timer_base[timerno]+(b?GPTM_TBV_OFFSET:GPTM_TAV_OFFSET)) = value;
41 void gptm_start_timer(uint8_t timerno, uint8_t b){
45 HW_REG(timer_base[timerno]+GPTM_CTL_OFFSET) |= _BV(b?GPTM_TBEN:GPTM_TAEN);
48 void gptm_stop_timer(uint8_t timerno, uint8_t b){
52 HW_REG(timer_base[timerno]+GPTM_CTL_OFFSET) &= ~_BV(b?GPTM_TBEN:GPTM_TAEN);
55 void gptm_set_timer_prescaler(uint8_t timerno, uint8_t b, uint8_t prescaler){
59 HW_REG(timer_base[timerno]+(b?GPTM_TBPR_OFFSET:GPTM_TAPR_OFFSET)) =
63 void gptm_set_timer_loadvalue(uint8_t timerno, uint8_t b, uint32_t value){
67 HW_REG(timer_base[timerno]+(b?GPTM_TBILR_OFFSET:GPTM_TAILR_OFFSET)) =
71 void gptm_set_timer_mode(uint8_t timerno, uint8_t b, uint8_t mode){
76 tmp = HW_REG(timer_base[timerno]+(b?GPTM_TBMR_OFFSET:GPTM_TAMR_OFFSET));
79 HW_REG(timer_base[timerno]+(b?GPTM_TBMR_OFFSET:GPTM_TAMR_OFFSET)) = tmp;
82 uint8_t gptm_get_timer_running(uint8_t timerno, uint8_t b){
86 return (HW_REG(timer_base[timerno]+GPTM_CTL_OFFSET)>>(b?GPTM_TBEN:GPTM_TAEN))&1;
90 void gptm_set_timer_32periodic(uint8_t timerno){
95 HW_REG(SYSCTL_BASE+RCGC1_OFFSET) |= _BV(16+timerno);
98 gptm_stop_timer(timerno, 0);
99 HW_REG(timer_base[timerno]+GPTM_CTL_OFFSET) = 0;
100 gptm_set_timer_mode(timerno, 0, GPTM_MODE_PERIODIC);
101 HW_REG(timer_base[timerno]+GPTM_TAMR_OFFSET) |= _BV(4);
102 gptm_set_timer_loadvalue(timerno, 0, 0xffffffff);