Marlin_Firmware/Marlin/src/HAL/HAL_LPC1768/timers.cpp

67 lines
2.2 KiB
C++
Raw Normal View History

2017-06-17 16:19:42 -05:00
/**
* Marlin 3D Printer Firmware
*
2019-06-27 23:57:50 -05:00
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2017-06-17 16:19:42 -05:00
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Description:
*
* Timers for LPC1768
2017-06-17 16:19:42 -05:00
*/
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
2019-09-02 19:49:58 -05:00
#include "timers.h"
2017-06-17 16:19:42 -05:00
void HAL_timer_init(void) {
SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
2018-06-12 16:32:22 -05:00
LPC_TIM0->PR = (HAL_TIMER_RATE) / (STEPPER_TIMER_RATE) - 1; // Use prescaler to set frequency if needed
2017-06-17 16:19:42 -05:00
SBI(LPC_SC->PCONP, SBIT_TIMER1); // Power ON Timer 1
LPC_TIM1->PR = (HAL_TIMER_RATE) / 1000000 - 1;
2017-06-17 16:19:42 -05:00
}
2017-08-24 12:18:54 -05:00
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
switch (timer_num) {
case 0:
LPC_TIM0->MCR = _BV(SBIT_MR0I) | _BV(SBIT_MR0R); // Match on MR0, reset on MR0, interrupts when NVIC enables them
2018-06-12 16:32:22 -05:00
LPC_TIM0->MR0 = uint32_t(STEPPER_TIMER_RATE) / frequency; // Match value (period) to set frequency
LPC_TIM0->TCR = _BV(SBIT_CNTEN); // Counter Enable
2017-06-17 16:19:42 -05:00
2017-08-24 12:18:54 -05:00
NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
NVIC_EnableIRQ(TIMER0_IRQn);
2017-08-24 12:18:54 -05:00
break;
2017-08-24 12:18:54 -05:00
case 1:
LPC_TIM1->MCR = _BV(SBIT_MR0I) | _BV(SBIT_MR0R); // Match on MR0, reset on MR0, interrupts when NVIC enables them
2018-06-12 16:32:22 -05:00
LPC_TIM1->MR0 = uint32_t(TEMP_TIMER_RATE) / frequency;
LPC_TIM1->TCR = _BV(SBIT_CNTEN); // Counter Enable
2017-08-24 12:18:54 -05:00
NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
NVIC_EnableIRQ(TIMER1_IRQn);
2017-08-24 12:18:54 -05:00
break;
2017-06-17 16:19:42 -05:00
default: break;
2017-06-17 16:19:42 -05:00
}
}
#endif // TARGET_LPC1768