00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "esos.h"
00031 #include "esos_comm.h"
00032
00033
00034 volatile uint8 __esos_comm_tx_buff[ESOS_SERIAL_IN_EP_SIZE];
00035 volatile uint8 __esos_comm_rx_buff[ESOS_SERIAL_OUT_EP_SIZE];
00036 volatile ESOS_COMM_BUFF_DSC __st_TxBuffer, __st_RxBuffer;
00037 volatile struct stTask __stChildTaskTx, __stChildTaskRx;
00038
00039
00040
00041
00042 void __esos_InitCommSystem(void) {
00043
00044 __st_TxBuffer.pau8_Data = &__esos_comm_tx_buff[0];
00045 __st_TxBuffer.u16_Head = 0;
00046 __st_TxBuffer.u16_Tail = 0;
00047 __st_TxBuffer.u16_Length = ESOS_SERIAL_IN_EP_SIZE;
00048 __st_RxBuffer.pau8_Data = __esos_comm_rx_buff;
00049 __st_RxBuffer.u16_Head = 0;
00050 __st_RxBuffer.u16_Tail = 0;
00051 __st_RxBuffer.u16_Length = ESOS_SERIAL_OUT_EP_SIZE;
00052
00053 __esos_hw_InitCommSystem();
00054
00055 }
00056
00057 uint8 __esos_u8_GetMSBHexCharFromUint8(uint8 u8_x) {
00058 uint8 u8_c;
00059
00060 u8_c = (u8_x>>4)& 0xf;
00061 if (u8_c > 9) return('A'+u8_c-10);
00062 else return('0'+u8_c);
00063 }
00064
00065 uint8 __esos_u8_GetLSBHexCharFromUint8(uint8 u8_x) {
00066 uint8 u8_c;
00067
00068 u8_c = u8_x & 0xf;
00069 if (u8_c > 9) return('A'+u8_c-10);
00070 else return('0'+u8_c);
00071 }
00072
00073
00074 ESOS_CHILD_TASK( __esos_OutChar, uint8 u8_c) {
00075 static uint16 u16_tmp;
00076 static uint8 u8_TempChar;
00077
00078 ESOS_TASK_BEGIN();
00079 u8_TempChar = u8_c;
00080
00081 __ESOS_COMM_TXFIFO_PREP();
00082
00083 ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
00084 __ESOS_COMM_WRITE_TXFIFO( u8_TempChar );
00085 __esos_hw_signal_start_tx();
00086
00087 ESOS_TASK_END();
00088 }
00089
00090
00091 ESOS_CHILD_TASK( __esos_OutUint8AsHexString, uint8 u8_x) {
00092 static uint8 au8_String[5];
00093 static uint8 u8_c;
00094 static uint16 u16_tmp;
00095
00096 ESOS_TASK_BEGIN();
00097 au8_String[0] = '0';
00098 au8_String[1] = 'x';
00099 au8_String[2] = __esos_u8_GetMSBHexCharFromUint8(u8_x);
00100 au8_String[3] = __esos_u8_GetLSBHexCharFromUint8(u8_x);
00101 au8_String[4] = 0;
00102 u8_c = 0;
00103
00104 while (u8_c < 4) {
00105 __ESOS_COMM_TXFIFO_PREP();
00106 ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
00107 __ESOS_COMM_WRITE_TXFIFO( au8_String[u8_c++] );
00108 __esos_hw_signal_start_tx();
00109 }
00110 ESOS_TASK_END();
00111
00112 }
00113
00114
00115 ESOS_CHILD_TASK( __esos_OutUint32AsHexString, uint32 u32_x) {
00116 static uint8 au8_String[11];
00117 static uint8 u8_c;
00118 static uint16 u16_tmp;
00119
00120 ESOS_TASK_BEGIN();
00121 au8_String[0] = '0';
00122 au8_String[1] = 'x';
00123 u8_c = (u32_x >> 24);
00124 au8_String[2] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
00125 au8_String[3] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
00126 u8_c = (u32_x >> 16);
00127 au8_String[4] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
00128 au8_String[5] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
00129 u8_c = (u32_x >> 8);
00130 au8_String[6] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
00131 au8_String[7] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
00132 u8_c = u32_x;
00133 au8_String[8] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
00134 au8_String[9] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
00135 au8_String[10] = 0;
00136 u8_c = 0;
00137
00138 while (u8_c < 10) {
00139 __ESOS_COMM_TXFIFO_PREP();
00140 ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
00141 __ESOS_COMM_WRITE_TXFIFO( au8_String[u8_c++] );
00142 __esos_hw_signal_start_tx();
00143 }
00144 ESOS_TASK_END();
00145
00146 }
00147
00148
00149 ESOS_CHILD_TASK( __esos_OutCharBuffer, uint8* pu8_out, uint8 u8_len) {
00150 static uint16 u16_tmp;
00151 static uint8 u8_i;
00152 static uint8 u8_StoreLen;
00153 static uint8* pu8_StorePtr;
00154
00155 ESOS_TASK_BEGIN();
00156 u8_StoreLen = u8_len;
00157 pu8_StorePtr = pu8_out;
00158 u8_i = 0;
00159 while (u8_StoreLen) {
00160 __ESOS_COMM_TXFIFO_PREP();
00161 ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
00162 __ESOS_COMM_WRITE_TXFIFO( pu8_StorePtr[u8_i++] );
00163 __esos_hw_signal_start_tx();
00164 u8_StoreLen--;
00165 }
00166 ESOS_TASK_END();
00167
00168 }
00169
00170 ESOS_CHILD_TASK( __esos_getBuffer, uint8* pau8_buff, uint8 u8_size) {
00171 static uint8 u8_i;
00172 static uint8* pau8_LocalPtr;
00173 static uint8 u8_LocalSize;
00174
00175 ESOS_TASK_BEGIN();
00176 u8_LocalSize = u8_size;
00177 pau8_LocalPtr = pau8_buff;
00178
00179 for (u8_i=0; u8_i<u8_size; u8_i++) {
00180
00181 ESOS_TASK_WAIT_WHILE ( __st_RxBuffer.u16_Head == __st_RxBuffer.u16_Tail);
00182
00183 __st_RxBuffer.u16_Tail++;
00184 if (__st_RxBuffer.u16_Tail == ESOS_SERIAL_OUT_EP_SIZE) __st_RxBuffer.u16_Tail=0;
00185
00186 pau8_buff[u8_i] = __st_RxBuffer.pau8_Data[__st_RxBuffer.u16_Tail];
00187 }
00188 ESOS_TASK_END();
00189 }
00190
00191
00192 ESOS_CHILD_TASK( __esos_getString, char* pau8_buff) {
00193 static uint8 u8_i;
00194
00195 ESOS_TASK_BEGIN();
00196 for (u8_i=0; u8_i<(ESOS_SERIAL_OUT_EP_SIZE-1); u8_i++) {
00197
00198 ESOS_TASK_WAIT_WHILE ( __st_RxBuffer.u16_Head == __st_RxBuffer.u16_Tail);
00199
00200 __st_RxBuffer.u16_Tail++;
00201 if (__st_RxBuffer.u16_Tail == ESOS_SERIAL_OUT_EP_SIZE) __st_RxBuffer.u16_Tail=0;
00202
00203 pau8_buff[u8_i] = __st_RxBuffer.pau8_Data[__st_RxBuffer.u16_Tail];
00204 if ((pau8_buff[u8_i] == '\n') || (pau8_buff[u8_i] == '\r') || (pau8_buff[u8_i] == 0)) break;
00205 }
00206 pau8_buff[u8_i] = 0;
00207 ESOS_TASK_END();
00208 }
00209
00210 ESOS_CHILD_TASK( __esos_OutString, char* psz_out ) {
00211 static uint16 u16_tmp;
00212 static char* psz_local;
00213
00214 ESOS_TASK_BEGIN();
00215 psz_local = psz_out;
00216 while ( *psz_local ) {
00217 __ESOS_COMM_TXFIFO_PREP();
00218 ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
00219 __ESOS_COMM_WRITE_TXFIFO( *psz_local++ );
00220 __esos_hw_signal_start_tx();
00221 }
00222 ESOS_TASK_END();
00223
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 void __esos_unsafe_PutUint8(uint8 u8_c) {
00236 uint16 u16_tmp;
00237
00238 __ESOS_COMM_TXFIFO_PREP();
00239
00240 while (u16_tmp == __st_TxBuffer.u16_Tail);
00241 __ESOS_COMM_WRITE_TXFIFO( u8_c );
00242 __esos_hw_signal_start_tx();
00243 }
00244
00245
00246 void __esos_unsafe_PutString(char* psz_in) {
00247 uint16 u16_tmp;
00248
00249 while ( *psz_in ) {
00250 __ESOS_COMM_TXFIFO_PREP();
00251
00252 while (u16_tmp == __st_TxBuffer.u16_Tail);
00253 __ESOS_COMM_WRITE_TXFIFO( *psz_in++ );
00254 __esos_hw_signal_start_tx();
00255 }
00256 }
00257
00258
00259 uint8 __esos_unsafe_GetUint8(void) {
00260
00261 while (__st_RxBuffer.u16_Head == __st_RxBuffer.u16_Tail);
00262 __st_RxBuffer.u16_Tail++;
00263 if (__st_RxBuffer.u16_Tail == ESOS_SERIAL_OUT_EP_SIZE) __st_RxBuffer.u16_Tail=0;
00264 return __st_RxBuffer.pau8_Data[__st_RxBuffer.u16_Tail];
00265 }