]> rtime.felk.cvut.cz Git - mirosot.git/blob - bluetooth/bth_inface.c
Initial import of Petr's work.
[mirosot.git] / bluetooth / bth_inface.c
1 /*******************************************************************
2   bluetooth library
3
4   bth_inface.c - fce for reading and getting and putting chars to a data queue
5
6   Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com
7
8  *******************************************************************/
9 #ifdef BTH_LX
10 #include <types.h>
11
12 #else
13 #include "types.h"
14 #include <stdio.h>
15 #endif
16
17 #include <stdlib.h>
18 #include "bth_inface.h"
19 #include "bth_inface.h"
20
21 #include <periph/sci_rs232.h>
22
23 /*pocet komunikacnich struktur - tj. pres kolik kanalu je mozno komunikovat,
24   to zaroven znamena, kolik je nezavislych dvojic I/O bufferu*/
25   bth_inface_info_t bth_inface_chan_array[BTH_INFACE_CHANAL];
26
27 //-- --- ----- ----- ---- ------ ----- -- ---- --
28 //-- --- ----- ----- ---- ------ ----- -- ---- --
29
30 /**
31   * fce write one char to in-buffer. Fce return a code of char. If a value is -1 its signal for error
32 */
33 int bth_inface_r_isr(int chan, int val)
34 {
35   if(bth_inface_que_put(&(bth_inface_chan_array[chan].bth_inface_que_in),val)<0)
36   {return (-1);};
37   return (val);
38 }
39
40 /**
41   * fce read one char of out-buffer. Fce return a code of char. If is a value -1 than is not new char
42 */
43 int bth_inface_t_isr(int chan)
44 {
45   short val;
46   if((val=bth_inface_que_get(&(bth_inface_chan_array[chan].bth_inface_que_out)))>=0)
47   {
48     return val;
49   }
50   return (-1);
51 }
52
53 /**
54   * fce write one char to out-buffer. Fce return a code of char. If a value is -1 its signal for error
55 */
56 int bth_inface_sendch(int val, int chan)
57 {
58   if(bth_inface_que_put(&(bth_inface_chan_array[chan].bth_inface_que_out),val)<0)
59   {return (-1);};
60   return (val);
61 };
62
63
64 /**
65   * fce read one char of in-buffer. Fce return a code of char. If is a value -1 than is not new char
66 */
67 int bth_inface_recch(int chan)
68 {
69   short val;
70   if((val=bth_inface_que_get(&(bth_inface_chan_array[chan].bth_inface_que_in)))>=0)
71   {
72     sci_rs232_sendch(val,sci_rs232_chan_default);
73     return val;
74   }
75   return (-1);
76 };
77
78
79 /**
80   * init buffer for first chanal - 0 (nm. is index of array)
81 */
82 int bth_inface_setup(int chan)
83 {
84   bth_inface_info_t *bth_inface;
85   bth_inface = &(bth_inface_chan_array[chan]); //mnozstvi komunikacnich rozhranni bth - PC
86   bth_inface->bth_inface_que_in.buf_beg = bth_inface->bth_inface_buff_in;
87   bth_inface->bth_inface_que_in.buf_end = bth_inface->bth_inface_que_in.buf_beg+BTH_INFACE_BUF_LEN;
88   bth_inface->bth_inface_que_in.ip = bth_inface->bth_inface_que_in.buf_beg;
89   bth_inface->bth_inface_que_in.op = bth_inface->bth_inface_que_in.buf_beg;
90
91   bth_inface->bth_inface_que_out.buf_beg = bth_inface->bth_inface_buff_out;
92   bth_inface->bth_inface_que_out.buf_end = bth_inface->bth_inface_que_out.buf_beg+BTH_INFACE_BUF_LEN;
93   bth_inface->bth_inface_que_out.ip = bth_inface->bth_inface_que_out.buf_beg;
94   bth_inface->bth_inface_que_out.op = bth_inface->bth_inface_que_out.buf_beg;
95
96   return 1;
97 }
98
99
100 /****************************************************************************/
101 /****************************************************************************/
102
103
104 /**
105   * init using in your program
106 */
107 /*
108 int main()
109
110   bth_inface_setup(0);                                
111   bth_inface_r_isr(&bth_inface_chan_array[0],'c');    //internal-fce
112   bth_inface_recch(0);                                //read one char of buffer
113   bth_inface_sendch('a', 0);                           //write one char to out buffer for chanal 0
114   bth_inface_t_isr(&bth_inface_chan_array[0]);        //internal-fce
115
116   return 0;
117 };
118 */
119