1 /*******************************************************************
4 h2638_pkt_control.c - fce for TPU operation
6 Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com
8 *******************************************************************/
13 #include <system_def.h>
16 #include "bth_h8s2638.h"
22 * interrupt hanlder, increments the timer variable and blinks LEDs
24 void bth_inruppt_pkt_controll(void) __attribute__ ((interrupt_handler));
26 void bth_inruppt_pkt_controll(void)
28 static char count = 0;
30 if (count%2) DEB_LED_ON(0);
34 //*TPU_TSR1 &= ~TSR1_TCFVm ; //reset overflow flag (clear interrupt)
35 *TPU_TSR1 &= ~TSR1_TGFAm;
37 // *TPU_TSR1 &= ~TSR1_TCFVm ; //reset overflow flag (clear interrupt)
42 * Starts TPU channel 1
44 void bth_start_TPU_counter(void)
46 *TPU_TSTR|=(1<<1); /* Start channel 1 */
53 void bth_stop_TPU_counter(void)
55 *TPU_TSTR&=~(1<<1); /* Stop channel 1 */
62 void bth_clear_TPU_counter(void)
69 * Returns the number of timer interrupts
71 long int bth_get_timer(void)
77 * Zeroes the timer variable
79 void bth_nul_timer(void)
86 * Timer initialization - HW 1-timer overflow; 2-???Dosazeni citace hodnoty TIER1_TGIEAm
88 void bth_init_pkt_controll(void)
92 *SYS_MSTPCRA &= ~MSTPCRA_TPUm; // power TPU unit
94 *TPU_TCR1 =0x00 | 0x06; //rising edge, f divided by 256
95 *TPU_TMDR1 =0x00; // normal mode
96 *TPU_TSR1 &= ~TSR1_TCFVm ; //reset overflow flag
97 *TPU_TIER1 |=TIER1_TCIEVm; //enable overflow interrupt
99 excptvec_set(42,bth_inruppt_pkt_controll);
101 *TPU_TSTR |=TSTR_CST1m; //start timer
105 /* TPU initialization */
106 *SYS_MSTPCRA&=~MSTPCRA_TPUm;
107 // *TPU_TSTR&=~(1<<1); /* Stop channel 4 */
108 /* system clock/1 ,rising edge, clearing source TGRA */
109 *TPU_TCR1=(TPCR_TPSC_F64 | TPCR_CKEG_RIS | TPCR_CCLR_TGRA);
111 *TPU_TMDR1=TPMDR_MD_NORMAL;
112 /* TGRA initiates interrupt */
113 *TPU_TIER1|=TIER1_TGIEAm;
114 excptvec_set(EXCPTVEC_TGI1A,bth_inruppt_pkt_controll);
117 *TPU_TSTR |=TSTR_CST1m; //start timer
119 bth_controll_flag=10;