]> rtime.felk.cvut.cz Git - mirosot.git/blob - bth_tests/bluetooth/h2638_pkt_controll.c
Added bth_test application. Not finished.
[mirosot.git] / bth_tests / bluetooth / h2638_pkt_controll.c
1 /*******************************************************************
2   bluetooth library
3
4   h2638_pkt_control.c - fce for TPU operation
5
6   Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com
7
8  *******************************************************************/
9
10 #include <types.h>
11 #include <cpu_def.h>
12 #include <h8s2638h.h>
13 #include <system_def.h>
14 #include <stdlib.h>
15 #include "hci.h"
16 #include "bth_h8s2638.h"
17
18
19 long int timer;
20
21 /**
22  * interrupt hanlder, increments the timer variable and blinks LEDs
23  */
24 void bth_inruppt_pkt_controll(void) __attribute__ ((interrupt_handler));
25
26 void bth_inruppt_pkt_controll(void)
27 {
28   static char count = 0;
29   count++;
30   if (count%2) DEB_LED_ON(0);
31   else DEB_LED_OFF(0);
32
33   
34   //*TPU_TSR1 &= ~TSR1_TCFVm ; //reset overflow flag (clear interrupt)
35   *TPU_TSR1 &= ~TSR1_TGFAm;
36   timer++;
37 //  *TPU_TSR1 &= ~TSR1_TCFVm ; //reset overflow flag (clear interrupt)
38 };
39
40
41 /**
42  * Starts TPU channel 1
43 */
44 void bth_start_TPU_counter(void)
45 {
46     *TPU_TSTR|=(1<<1);          /* Start channel 1 */
47 };
48
49
50 /**
51  * Stop TPU 1
52  */
53 void bth_stop_TPU_counter(void)
54 {
55     *TPU_TSTR&=~(1<<1);         /* Stop channel 1 */
56 };
57
58
59 /**
60  * Reset TPU 1
61  */
62 void bth_clear_TPU_counter(void)
63 {
64   *TPU_TCNT1=0;
65 };
66
67
68 /**
69  * Returns the number of timer interrupts
70  */
71 long int bth_get_timer(void)
72 {
73   return timer;
74 };
75
76 /**
77  * Zeroes the timer variable
78  */
79 void bth_nul_timer(void)
80 {
81   timer=0;
82 };
83
84
85 /**
86  * Timer initialization - HW 1-timer overflow; 2-???Dosazeni citace hodnoty TIER1_TGIEAm
87  */
88 void bth_init_pkt_controll(void)
89 {
90
91 #if 0  
92   *SYS_MSTPCRA &= ~MSTPCRA_TPUm; // power TPU unit
93
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
98
99   excptvec_set(42,bth_inruppt_pkt_controll);
100
101   *TPU_TSTR |=TSTR_CST1m;     //start timer
102 #endif
103   
104 #if 1
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);
110   /* normal mode */
111   *TPU_TMDR1=TPMDR_MD_NORMAL;
112   /* TGRA initiates interrupt */
113   *TPU_TIER1|=TIER1_TGIEAm;
114   excptvec_set(EXCPTVEC_TGI1A,bth_inruppt_pkt_controll);
115
116   *TPU_TGR1A=(10000);
117   *TPU_TSTR |=TSTR_CST1m;     //start timer
118 #endif
119   bth_controll_flag=10;
120 };
121