Statistics
| Revision:

root / trunk / tp_info6 / bsp / uart0.c @ 2

History | View | Annotate | Download (2.16 KB)

1
// subroutines for control uart0 in interrupt mode for sending and receiving
2

    
3
#ifdef M32C87
4
        #include "sfr32c87.h"
5
#endif
6

    
7
#ifdef M32C83
8
        #include "sfr32c83.h"
9
#endif
10

    
11
#include <string.h>
12
#include <itron.h> 
13
#include <kernel.h> 
14
#include "kernel_id.h" 
15
#include "dma0.h"
16
#include "uart0.h"
17
#include "periph.h"
18

    
19
#define rx_buff_len 8
20
char rx_buff[rx_buff_len];
21
extern unsigned char dma0_fin_tr;
22

    
23
void uart0_init(void)
24
{
25
     u0mr = 0x05;              // transfert 8 bits 1 bit de stop sans parite
26
     u0c0 = 0x10;              // f1 selectionnee pas de CTS/RTS
27
     u0c1 = 0x05;              // emission et reception validees
28
                                                                // Fbaud = Fquartz / 16  /(n+1)
29
                                                                // n=(20 000 000 / Fbaud /16)-1
30
#ifdef M32C83                                                                
31
// Carte M32C83 Lp                                                        
32
     u0brg = 32000000/16/115200;     
33
#endif
34
#ifdef M32C87
35
// Carte M32C87 Cust           
36
         u0brg = 20000000/16/115200;
37
#endif
38

    
39
     s0tic = 0x00;             // aucune interruption en emission drapeau=0
40
     pd6_2 =0;              // broche RXD0 (P62) en entr?e
41
     pd6_3 =1;              // broche TXD0 (P63) en sortie
42
     ps0_2 =0;              // ps0_2 = 0
43
     ps0_3 =1;              // ps0_3 = 1
44
         s0ric = 0x04;
45
}
46

    
47
char uart0_tx(char c)
48
{
49
             while(!ti_u0c1);  //wait for free transmit register
50
             return u0tbl = c;       //send character
51
}
52

    
53

    
54

    
55
void uart0_str(char str[])
56
{
57
        while (uart0_tx(*str++));
58
}
59

    
60
void uart0_irx()
61
{
62
static int n=0;
63
char c;
64
static CanFrame rx;
65

    
66

    
67
        c=u0rb;
68

    
69
        if (c==0x0D || c==0x0A){
70
                if (n>=2 && n<7)
71
                        ipsnd_dtq (CanRx,(VP_INT) rx.msg);
72
                n=0;
73
                rx.data.id=rx.data.rtr=rx.data.val=0;
74
                return;
75
        }
76
        
77
        switch (n){
78
                case 0:rx.data.id=c; break;
79
                case 1:rx.data.rtr=c; break;
80
                case 2:
81
                case 3:
82
                case 4:
83
                case 5: if(c>='0' && c<='9') {
84
                                        rx.data.val=(rx.data.val<<4)+(c-'0');
85
                                        break;
86
                                }
87
                                c&=~32;
88
                                if (c>='A' || c<='F') 
89
                                        rx.data.val=(rx.data.val<<4)+(10+(c-'A'));
90
                                break;
91
        }
92
        n++;
93
}
94

    
95
char * ptx=NULL;
96

    
97
void uart0_itx(char str[])
98
{
99
        s0tic=3;
100
        ptx=str;
101
        u0tbl=*ptx++;        
102
}
103

    
104
void uart0_itx_ok(void)
105
{
106
        if (*ptx)
107
        {
108
                u0tbl=*ptx++;
109
        }
110
        else
111
        {
112
                iset_flg(ev_bus_fin_tr,(UINT) 1);
113
        }
114
}
115

    
116