This is a part of the Kinetiszer project.

Dependencies:   inc

Dependents:   kinetisizer

Committer:
Clemo
Date:
Tue Oct 28 12:19:42 2014 +0000
Revision:
0:cb80470434eb
Error & warning free.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Clemo 0:cb80470434eb 1 /*
Clemo 0:cb80470434eb 2 * @brief Sample rate related timer stuff.
Clemo 0:cb80470434eb 3 *
Clemo 0:cb80470434eb 4 * @note
Clemo 0:cb80470434eb 5 * Copyright (C) Elektor, 2014
Clemo 0:cb80470434eb 6 * All rights reserved.
Clemo 0:cb80470434eb 7 *
Clemo 0:cb80470434eb 8 * @par
Clemo 0:cb80470434eb 9 * This software is supplied "AS IS" without any warranties of any kind,
Clemo 0:cb80470434eb 10 * and Elektor and its licensor disclaim any and all warranties, express
Clemo 0:cb80470434eb 11 * or implied, including all implied warranties of merchantability,
Clemo 0:cb80470434eb 12 * fitness for a particular purpose and non-infringement of intellectual
Clemo 0:cb80470434eb 13 * property rights. Elektor assumes no responsibility or liability for
Clemo 0:cb80470434eb 14 * the use of the software, conveys no license or rights under any patent,
Clemo 0:cb80470434eb 15 * copyright, mask work right, or any other intellectual property rights in
Clemo 0:cb80470434eb 16 * or to any products. Elektor reserves the right to make changes in the
Clemo 0:cb80470434eb 17 * software without notification. Elektor also makes no representation or
Clemo 0:cb80470434eb 18 * warranty that such application will be suitable for the specified use
Clemo 0:cb80470434eb 19 * without further testing or modification.
Clemo 0:cb80470434eb 20 *
Clemo 0:cb80470434eb 21 * @par
Clemo 0:cb80470434eb 22 * Permission to use, copy, modify, and distribute this software and its
Clemo 0:cb80470434eb 23 * documentation is hereby granted, under Elektor's and its licensor's
Clemo 0:cb80470434eb 24 * relevant copyrights in the software, without fee. This copyright,
Clemo 0:cb80470434eb 25 * permission, and disclaimer notice must appear in all copies of this code.
Clemo 0:cb80470434eb 26 */
Clemo 0:cb80470434eb 27
Clemo 0:cb80470434eb 28 #include "board.h"
Clemo 0:cb80470434eb 29 #include "sample_rate.h"
Clemo 0:cb80470434eb 30
Clemo 0:cb80470434eb 31 /*
Clemo 0:cb80470434eb 32 #if SAMPLE_RATE_TIMER_NR == TIMER16_0
Clemo 0:cb80470434eb 33 void TIMER16_0_IRQHandler(void)
Clemo 0:cb80470434eb 34 #elif SAMPLE_RATE_TIMER_NR == TIMER16_1
Clemo 0:cb80470434eb 35 void TIMER16_1_IRQHandler(void)
Clemo 0:cb80470434eb 36 #elif SAMPLE_RATE_TIMER_NR == TIMER32_0
Clemo 0:cb80470434eb 37 void TIMER32_0_IRQHandler(void)
Clemo 0:cb80470434eb 38 #elif SAMPLE_RATE_TIMER_NR == TIMER32_1
Clemo 0:cb80470434eb 39 void TIMER32_1_IRQHandler(void)
Clemo 0:cb80470434eb 40 #else
Clemo 0:cb80470434eb 41 // Does not exist.
Clemo 0:cb80470434eb 42 #pragma GCC error "Selected SAMPLE_RATE timer does not exist."
Clemo 0:cb80470434eb 43 void SampleRate_DummyIRQHandler(void)
Clemo 0:cb80470434eb 44 #endif
Clemo 0:cb80470434eb 45 {
Clemo 0:cb80470434eb 46 if (Chip_TIMER_MatchPending(SAMPLE_RATE_TIMER,SAMPLE_RATE_FREQUENCY_REGISTER))
Clemo 0:cb80470434eb 47 {
Clemo 0:cb80470434eb 48 Chip_TIMER_ClearMatch(SAMPLE_RATE_TIMER,SAMPLE_RATE_FREQUENCY_REGISTER);
Clemo 0:cb80470434eb 49 Board_LED_Toggle(0);
Clemo 0:cb80470434eb 50 }
Clemo 0:cb80470434eb 51 }
Clemo 0:cb80470434eb 52
Clemo 0:cb80470434eb 53
Clemo 0:cb80470434eb 54 void SampleRate_Init(uint32_t default_rate, uint32_t samples_per_period)
Clemo 0:cb80470434eb 55 {
Clemo 0:cb80470434eb 56 // Setup pin multiplexer.
Clemo 0:cb80470434eb 57 Chip_IOCON_PinMuxSet(LPC_IOCON,SAMPLE_RATE_IOCON,IOCON_DIGMODE_EN|IOCON_MODE_INACT|SAMPLE_RATE_IOCON_FUNC);
Clemo 0:cb80470434eb 58 // Make the pin an output.
Clemo 0:cb80470434eb 59 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,SAMPLE_RATE_MAT_PORT,SAMPLE_RATE_MAT_PIN,true);
Clemo 0:cb80470434eb 60
Clemo 0:cb80470434eb 61 Chip_TIMER_Init(SAMPLE_RATE_TIMER);
Clemo 0:cb80470434eb 62 Chip_TIMER_Reset(SAMPLE_RATE_TIMER);
Clemo 0:cb80470434eb 63 Chip_TIMER_MatchEnableInt(SAMPLE_RATE_TIMER,SAMPLE_RATE_FREQUENCY_REGISTER);
Clemo 0:cb80470434eb 64 Chip_TIMER_SetMatch(SAMPLE_RATE_TIMER,SAMPLE_RATE_FREQUENCY_REGISTER,Chip_Clock_GetSystemClockRate()/(default_rate*samples_per_period));
Clemo 0:cb80470434eb 65 Chip_TIMER_ResetOnMatchEnable(SAMPLE_RATE_TIMER,SAMPLE_RATE_FREQUENCY_REGISTER);
Clemo 0:cb80470434eb 66 Chip_TIMER_Enable(SAMPLE_RATE_TIMER);
Clemo 0:cb80470434eb 67
Clemo 0:cb80470434eb 68 // Enable timer interrupt.
Clemo 0:cb80470434eb 69 NVIC_ClearPendingIRQ(SAMPLE_RATE_TIMER_IRQ);
Clemo 0:cb80470434eb 70 NVIC_EnableIRQ(SAMPLE_RATE_TIMER_IRQ);
Clemo 0:cb80470434eb 71 }
Clemo 0:cb80470434eb 72 */