/* ChibiOS - Copyright (C) 2017 Theodore Ateba Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /** * @file TIMv1/hal_st_lld.c * @brief AVR XMEGA ST subsystem low level driver source file. * * @addtogroup ST * @{ */ #include "hal.h" #if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__) /*==========================================================================*/ /* Driver local definitions. */ /*==========================================================================*/ /*==========================================================================*/ /* Driver exported variables. */ /*==========================================================================*/ /*==========================================================================*/ /* Driver local types. */ /*==========================================================================*/ /*==========================================================================*/ /* Driver local variables and types. */ /*==========================================================================*/ /*==========================================================================*/ /* Driver local functions. */ /*==========================================================================*/ /*==========================================================================*/ /* Driver interrupt handlers. */ /*==========================================================================*/ #if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__) /** * @brief Timer handler for periodic mode. */ OSAL_IRQ_HANDLER(TCC0_OVF_vect) { OSAL_IRQ_PROLOGUE(); osalSysLockFromISR(); osalOsTimerHandlerI(); osalSysUnlockFromISR(); OSAL_IRQ_EPILOGUE(); } #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ #if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) || defined(__DOXYGEN__) /* TODO: Add the Handler of the freerunning mode. */ #endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */ /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ /** * @brief Low level ST driver initialization. * * @notapi */ void st_lld_init(void) { #if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__) TCC0.PER = (F_CPU/OSAL_ST_FREQUENCY) - 1; TCC0.CTRLA = ( TCC0.CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_DIV1_gc; TCC0.INTCTRLA = ( TCC0.INTCTRLA & ~TC0_OVFINTLVL_gm ) | TC_OVFINTLVL_MED_gc; PMIC.CTRL |= PMIC_MEDLVLEN_bm; sei(); #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ #if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) || defined(__DOXYGEN__) /* TODO: Add freerunning mode for. */ #endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */ } #endif /* OSAL_ST_MODE != OSAL_ST_MODE_NONE */ /** @} */