1 //======================================================================================================= 2 // dzc_layer.h - Serial command layer for DZcomm 3 // 4 //======================================================================================================= 5 6 //======================================================================================================= 7 //======================================================================================================= 8 9 #ifndef _DZC_LAYER_H 10 #define _DZC_LAYER_H 11 12 13 //=============================================================================== 14 // Include files 15 //=============================================================================== 16 17 #include <dzcomm.h> 18 19 //=============================================================================== 20 // Static variable definitions 21 //=============================================================================== 22 23 comm_port *comport; 24 25 //=============================================================================== 26 // Inline function definitions 27 //=============================================================================== 28 29 // Initialize the serial library 30 // Should return 0 if no error occurred GDBStub_SerInit(int port)31__inline int GDBStub_SerInit(int port) 32 { 33 int ret; 34 comm com; 35 36 ret = dzcomm_init(); 37 if (ret != 0) 38 { 39 switch (port) 40 { 41 case 4: 42 com = _com4; 43 break; 44 45 case 3: 46 com = _com3; 47 break; 48 49 case 2: 50 com = _com2; 51 break; 52 53 case 1: 54 default: 55 com = _com1; 56 break; 57 } 58 comport = comm_port_init(com); 59 } 60 return (ret == 0); 61 } 62 63 // Set the serial port speed (and other configurables) 64 // Should return 0 if the speed is set properly GDBStub_SerSpeed(int speed)65__inline int GDBStub_SerSpeed(int speed) 66 { 67 baud_bits bps; 68 69 switch (speed) 70 { 71 case 110: 72 bps = _110; 73 break; 74 75 case 150: 76 bps = _150; 77 break; 78 79 case 300: 80 bps = _300; 81 break; 82 83 case 600: 84 bps = _600; 85 break; 86 87 case 1200: 88 bps = _1200; 89 break; 90 91 case 2400: 92 bps = _2400; 93 break; 94 95 case 4800: 96 bps = _4800; 97 break; 98 99 case 9600: 100 bps = _9600; 101 break; 102 103 case 19200: 104 bps = _19200; 105 break; 106 107 case 38400: 108 bps = _38400; 109 break; 110 111 case 57600: 112 bps = _57600; 113 break; 114 115 case 115200: 116 default: 117 bps = _115200; 118 break; 119 } 120 121 comm_port_set_baud_rate(comport, bps); 122 comm_port_set_parity(comport, NO_PARITY); 123 comm_port_set_data_bits(comport, BITS_8); 124 comm_port_set_stop_bits(comport, STOP_1); 125 comm_port_set_flow_control(comport, RTS_CTS); 126 comm_port_install_handler(comport); 127 128 return 0; 129 } 130 131 // Check to see if there's room in the buffer to send data 132 // Should return 0 if it is okay to send GDBStub_SerSendOk(void)133__inline int GDBStub_SerSendOk(void) 134 { 135 return (comm_port_out_full(comport) == 0); 136 } 137 138 // Send a character to the serial port 139 // Should return 0 if the send succeeds GDBStub_SerSend(int c)140__inline int GDBStub_SerSend(int c) 141 { 142 return comm_port_out(comport, (unsigned char) c); 143 } 144 145 // Check to see if there are characters waiting in the buffer 146 // Should return 0 if there's data waiting GDBStub_SerRecvOk(void)147__inline int GDBStub_SerRecvOk(void) 148 { 149 return (comm_port_in_empty(comport) == 0); 150 } 151 152 // Read a character from the serial port 153 // Should return the character read GDBStub_SerRecv(void)154__inline int GDBStub_SerRecv(void) 155 { 156 return comm_port_test(comport); 157 } 158 159 160 161 162 #endif 163 164 /*================================================================== 165 166 $Log: $ 167 168 169 ===============================================================*/ 170