]> rtime.felk.cvut.cz Git - mirosot.git/blob - bluetooth/bth_inface.c
An unsucesfull attempt to clean bluetooth library and make it working.
[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
10 #include <bth_config.h>
11 #ifdef BTH_LX
12 #include <types.h>
13
14 #else
15 #include "types.h"
16 #include <stdio.h>
17 #endif
18
19 #include <stdlib.h>
20 #include "bth_inface.h"
21 #include "bth_inface.h"
22
23 #ifndef CONFIG_BLUETOOTH_LINUX
24 #include <periph/sci_rs232.h>
25 #endif
26
27 /* the number of communication structures i.e. how many channels can be used for communication. It alse specifies howmany
28    independent couples of I/O buffers is here.*/
29 /*pocet komunikacnich struktur - tj. pres kolik kanalu je mozno komunikovat,
30   to zaroven znamena, kolik je nezavislych dvojic I/O bufferu*/
31   bth_inface_info_t bth_inface_chan_array[BTH_INFACE_CHANAL];
32
33 //-- --- ----- ----- ---- ------ ----- -- ---- --
34 //-- --- ----- ----- ---- ------ ----- -- ---- --
35
36 /**
37   * fce write one char to in-buffer. Fce return a code of char. If a value is -1 its signal for error
38 */
39 int bth_inface_r_isr(int chan, int val)
40 {
41   if(bth_inface_que_put(&(bth_inface_chan_array[chan].bth_inface_que_in),val)<0)
42   {return (-1);};
43   return (val);
44 }
45
46 /**
47   * fce read one char of out-buffer. Fce return a code of char. If is a value -1 than is not new char
48 */
49 int bth_inface_t_isr(int chan)
50 {
51   short val;
52   if((val=bth_inface_que_get(&(bth_inface_chan_array[chan].bth_inface_que_out)))>=0)
53   {
54     return val;
55   }
56   return (-1);
57 }
58
59 /**
60   * init buffer for first chanal - 0 (nm. is index of array)
61 */
62 int bth_inface_setup(int chan)
63 {
64   bth_inface_info_t *bth_inface;
65   bth_inface = &(bth_inface_chan_array[chan]); // the number of communication interfaces bth - PC
66   bth_inface->bth_inface_que_in.buf_beg = bth_inface->bth_inface_buff_in;
67   bth_inface->bth_inface_que_in.buf_end = bth_inface->bth_inface_que_in.buf_beg+BTH_INFACE_BUF_LEN;
68   bth_inface->bth_inface_que_in.ip = bth_inface->bth_inface_que_in.buf_beg;
69   bth_inface->bth_inface_que_in.op = bth_inface->bth_inface_que_in.buf_beg;
70
71   bth_inface->bth_inface_que_out.buf_beg = bth_inface->bth_inface_buff_out;
72   bth_inface->bth_inface_que_out.buf_end = bth_inface->bth_inface_que_out.buf_beg+BTH_INFACE_BUF_LEN;
73   bth_inface->bth_inface_que_out.ip = bth_inface->bth_inface_que_out.buf_beg;
74   bth_inface->bth_inface_que_out.op = bth_inface->bth_inface_que_out.buf_beg;
75
76   return 1;
77 }
78
79
80 /****************************************************************************/
81 /****************************************************************************/
82
83
84 /**
85   * init using in your program
86 */
87 /*
88 int main()
89
90   bth_inface_setup(0);                                
91   bth_inface_r_isr(&bth_inface_chan_array[0],'c');    //internal-fce
92   bth_inface_recch(0);                                //read one char of buffer
93   bth_inface_sendch('a', 0);                           //write one char to out buffer for chanal 0
94   bth_inface_t_isr(&bth_inface_chan_array[0]);        //internal-fce
95
96   return 0;
97 };
98 */
99