// MyArm.h
// 타이머 카운터를 이용해서 LED 컨트롤
// 타이머 카운터를 이용하여 2개의 클럭 신호를 만들어 낸다. 한쪽 LED는 밝은 상태에서 점차 어두워지고, 다시 점차 밝아지는 동작을 반복한다. 나머지 한쪽은 그 반대로 동작한다.
// 처음에는 저번 시간과 같은 방법으로 셋팅을 했는데 TIOB0으로 신호가 나오지 않았다. 나중에 EEVT 필드 값을 01로 셋팅하자 TIOB0으로 신호가 나오기 시작했다. TIOB0으로 디폴트로 입력으로 설정 되어 있는 것 같았다.
// TCCLKS 필드를 (MASTERCLOCK / 2) 로 셋팅 했을 때, 출력이 동기화가 되지 않았다. 한쪽이 어두워지면 한쪽은 밝아져야 하는데, 한쪽 출력이 먼저 일어나고 그 다음 다른쪽이 출력되는걸로 보였다. 이는 TCCLKS 필드를 (MASTERCLOCK / 32) 즉 카운터 클럭을 낮추니 TIOA0과 TIOB0에서 제대로된 신호가 나왔다.
//----------------------------------------------------------------------------------------------------------
#define FIQ 0 //AIC = Advanced Interrupt Controller(FIQ)
#define SYS 1 //SYS = System Controller
#define PID2 2 //PIOA
//#define PID3 3 //reserved
#define PID4 4 //ADC = Analog to Digital Converter
#define PID5 5 //SPI = Serial Peripheral Interface
#define PID6 6 //US0 = USART0
#define PID7 7 //US1 = USART1
#define PID8 8 //SSC = Synchronous Serial Controller
#define PID9 9 //TWI = Two-Wire Interface
#define PID10 10 //PWMC= PWM Controller
#define PID11 11 //UDP = USB Device Port
#define PID12 12 //TC0 = Timer/Conuter 0
#define PID13 13 //TC1 = Timer/Conuter 1
#define PID14 14 //TC2 = Timer/Conuter 2
/*
#define PID15 15 //reserved
#define PID16 16
#define PID17 17
#define PID18 18
#define PID19 19
#define PID20 20
#define PID21 21
#define PID22 22
#define PID23 23
#define PID24 24
#define PID25 25
#define PID26 26
#define PID27 27
#define PID28 28
#define PID29 29
*/
#define PID30 30 //AIC = Advanced Interrupt Controller (IRQ0)
#define PID31 31 //AIC = Advanced Interrupt Controller (IRQ1)
//----------------------------------------------------------------------------------------------------------
#define P0 0
#define P1 1
#define P2 2
#define P3 3
#define P4 4
#define P5 5
#define P6 6
#define P7 7
#define P8 8
#define P9 9
#define P10 10
#define P11 11
#define P12 12
#define P13 13
#define P14 14
#define P15 15
#define P16 16
#define P17 17
#define P18 18
#define P19 19
#define P20 20
#define P21 21
#define P22 22
#define P23 23
#define P24 24
#define P25 25
#define P26 26
#define P27 27
#define P28 28
#define P29 29
#define P30 30
#define P31 31
//----------------------------------------------------------------------------------------------------------
//DBGU
#define RXEN 4
#define TXEN 6
#define RSTSTA 8
#define DRXD 9 //Debug Receive Data
#define DTXD 10 //Debug Transmit Data
#define RXRDY 0
#define TXRDY 1
//----------------------------------------------------------------------------------------------------------
//PIO = Parallel Input/Output Controller
#define PIO_PER (*(volatile unsigned int *) 0xFFFFF400) //PIO Enable Register
#define PIO_PDR (*(volatile unsigned int *) 0xFFFFF404) //PIO Disable Register
#define PIO_OER (*(volatile unsigned int *) 0xFFFFF410) //PIO Output Enable Register
#define PIO_ODR (*(volatile unsigned int *) 0xFFFFF414) //PIO Output Disable Register
#define PIO_IFER (*(volatile unsigned int *) 0xFFFFF420) //PIO Glitch Input Filter Enable Register
#define PIO_SODR (*(volatile unsigned int *) 0xFFFFF430) //PIO Controller Set Output Data Register
#define PIO_CODR (*(volatile unsigned int *) 0xFFFFF434) //PIO Controller Clear Output Data Register
#define PIO_IER (*(volatile unsigned int *) 0xFFFFF440) //PIO Interrupt Enable Register
#define PIO_IDR (*(volatile unsigned int *) 0xFFFFF444) //PIO Interrupt Disable Register
#define PIO_ISR (*(volatile unsigned int *) 0xFFFFF44C) //PIO Interrupt Status Register
#define PIO_PUDR (*(volatile unsigned int *) 0xFFFFF460) //PIO Pull-Up Disable Register
#define PIO_PUER (*(volatile unsigned int *) 0xFFFFF464) //PIO Pull-Up Enable Register
#define PIO_ASR (*(volatile unsigned int *) 0xFFFFF470) //PIO Peripheral A Select Register
#define PIO_BSR (*(volatile unsigned int *) 0xFFFFF474) //PIO Peripheral B Select Register
//----------------------------------------------------------------------------------------------------------
//AIC = Advance Interrupt Controller
#define AIC_SMR ( (volatile unsigned int *) 0xFFFFF000) //(Address of) AIC Source Mode Register
#define AIC_SVR ( (volatile unsigned int *) 0xFFFFF080) //(Address of) AIC Vector Register
#define AIC_IECR (*(volatile unsigned int *) 0xFFFFF120) //AIC Interrupt Enable Command Register
#define AIC_IDCR (*(volatile unsigned int *) 0xFFFFF124) //AIC Interrupt Disable Command Register
#define AIC_ICCR (*(volatile unsigned int *) 0xFFFFF128) //AIC Interrupt Clear Command Register
//----------------------------------------------------------------------------------------------------------
//DBGU = Debug Unit
#define DBGU_CR (*(volatile unsigned int *) 0xFFFFF200) //DBGU Control Register
#define DBGU_MR (*(volatile unsigned int *) 0xFFFFF204) //DBGU Mode Register
#define DBGU_SR (*(volatile unsigned int *) 0xFFFFF214) //DBGU Status Register
#define DBGU_RHR (*(volatile unsigned int *) 0xFFFFF218) //DBGU Receive Holding Register
#define DBGU_THR (*(volatile unsigned int *) 0xFFFFF21C) //DBGU Transmit Holding Register
#define DBGU_BRGR (*(volatile unsigned int *) 0xFFFFF220) //DBGU Baud Rate Generator Control Register
#define DBGU_IER (*(volatile unsigned int *) 0xFFFFF208) //DBGU Interrupt Enable Register
#define DBGU_IDR (*(volatile unsigned int *) 0xFFFFF20C) //DBGU Interrupt Disalbe Register
#define DBGU_IMR (*(volatile unsigned int *) 0xFFFFF210) //DBGU Interrupt Disalbe Register
//----------------------------------------------------------------------------------------------------------
//TC = Timer Counter
#define TC0_CCR (*(volatile unsigned int *) 0xFFFA0000) //TC Channel Control Register
#define TC0_CMR (*(volatile unsigned int *) 0xFFFA0004) //TC Channel Mode Register
#define TC0_CV (*(volatile unsigned int *) 0xFFFA0010) //TC Counter Value Register
#define TC0_RA (*(volatile unsigned int *) 0xFFFA0014) //TC Register A Register
#define TC0_RB (*(volatile unsigned int *) 0xFFFA0018) //TC Register B Register
#define TC0_RC (*(volatile unsigned int *) 0xFFFA001C) //TC Register C Register
#define TC0_SR (*(volatile unsigned int *) 0xFFFA0020) //TC Status Register
//----------------------------------------------------------------------------------------------------------
//PM = Power Management Controller
#define PMC_PCER (*(volatile unsigned int *) 0xFFFFFC10) //PMC Syetem Clock Enable Register
#define PMC_PCDR (*(volatile unsigned int *) 0xFFFFFC14) //PMC System clock Disable Register
#define MASTERCLOCK 48000000
//----------------------------------------------------------------------------------------------------------
// 타이머 카운터를 이용해서 LED 컨트롤
#include "MyArm.h"
#define INTERR 0x00000100
#define LED 0x00000010
//--------- Global Variable
void Delayms(unsigned int ms) //Delay Function..
{
volatile unsigned int count, countmax = (MASTERCLOCK / 10000) * ms;
for(count = 0; count < countmax; count++);
}
int main(void)
{
int flag = 1; // flag
int cnt = 0; // count flag
// PMC setting
PMC_PCER = (unsigned int)1 << PID12; // Peripheral 12 clock Enable
// PIO setting
PIO_PDR = (1 << P0) | (1 << P1); // PA0, PA1 PIO disable
PIO_BSR = (1 << P0) | (1 << P1); // Peripheral B select
// TC setting
TC0_CCR = (1 << P0) | (1 << P2); // Software Trigger, Counter Clock Enable
TC0_CMR = (1 << P15) | (1 << P16) | (1 << P19) | (1 << P24) | (1 << P27) | (1 << P10)
| (1 << P2); // (MCK / 32), Waveform mode
TC0_RA = 0x0000;
TC0_RB = 0xF906;
TC0_RC = 0xFFFF;
while(1)
{
if(flag)
{
TC0_RA += 0xFF;
TC0_RB -= 0xFF;
cnt++;
if(cnt >= 250)
{
flag = 0;
}
}
else
{
TC0_RA -= 0xFF;
TC0_RB += 0xFF;
cnt--;
if(cnt <= 0)
{
flag = 1;
}
}
Delayms(10);
}
return 0;
} // End Main....
// 처음에는 저번 시간과 같은 방법으로 셋팅을 했는데 TIOB0으로 신호가 나오지 않았다. 나중에 EEVT 필드 값을 01로 셋팅하자 TIOB0으로 신호가 나오기 시작했다. TIOB0으로 디폴트로 입력으로 설정 되어 있는 것 같았다.
// TCCLKS 필드를 (MASTERCLOCK / 2) 로 셋팅 했을 때, 출력이 동기화가 되지 않았다. 한쪽이 어두워지면 한쪽은 밝아져야 하는데, 한쪽 출력이 먼저 일어나고 그 다음 다른쪽이 출력되는걸로 보였다. 이는 TCCLKS 필드를 (MASTERCLOCK / 32) 즉 카운터 클럭을 낮추니 TIOA0과 TIOB0에서 제대로된 신호가 나왔다.