Go to the documentation of this file.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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00054 #include "mTouch.h"
00055 #include "mComm.h"
00056
00057 #if defined(MCOMM_ENABLED)
00058 #if defined(MCOMM_TWO_WAY_ENABLED)
00059
00060
00061
00062
00063 const mComm_Opcode mComm_opcode[MCOMM_NUMBER_OPCODES] = MCOMM_OPCODE_VALUES;
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 const uint8_t mComm_ConfigBlock_Literals[MCOMM_CONFIG_LIT_SIZE] = MCOMM_CONFIG_LIT_INIT;
00080 uint8_t * const mComm_ConfigBlock_Addrs[MCOMM_CONFIG_ADDR_SIZE] = MCOMM_CONFIG_ADDR_INIT;
00081
00082 #if defined(MCOMM_ENABLE_STREAM)
00083 #if defined(MCOMM_STREAM_STORED_IN_RAM)
00084 mComm_Vector mComm_stream[MCOMM_STREAM_SIZE + 1] = MCOMM_STREAM_VALUES;
00085 #else
00086 const mComm_Vector mComm_stream[MCOMM_STREAM_SIZE + 1] = MCOMM_STREAM_VALUES;
00087 #endif
00088 mComm_StreamConfig mComm_streamConfig;
00089 #endif
00090
00091
00092
00093
00094
00095 #if defined(MCOMM_ENABLE_NVM_ACCESS)
00096 void mComm_processNVM (void);
00097 uint8_t mComm_nvmReadIterator (void);
00098 uint8_t mComm_nvmWriteIterator (void);
00099 #endif
00100
00101 void mComm_processRAM (void);
00102 uint8_t mComm_ramReadIterator (void);
00103 uint8_t mComm_ramWriteIterator (void);
00104
00105 #if defined(MCOMM_ENABLE_STREAM)
00106 void mComm_processStream (void);
00107 uint8_t mComm_StreamReadIterator (void);
00108 #endif
00109
00110 void mComm_ErrorProcess (void);
00111 uint8_t mComm_ErrorIterator (void);
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 #define MCOMM_INPUT_ADDRL_OFFSET 1
00123 #define MCOMM_INPUT_ADDRH_OFFSET 2
00124 #define MCOMM_INPUT_LENGTH_OFFSET 3
00125 #define MCOMM_INPUT_PAYLOAD_OFFSET 4
00126
00127 #if defined(MCOMM_ENABLE_NVM_ACCESS)
00128
00129 void mComm_processNVM(void)
00130 {
00131
00132 mComm_output.vector.pointer = (uint8_t*) mComm_input.buffer[MCOMM_INPUT_ADDRL_OFFSET];
00133 mComm_output.vector.length = mComm_input.buffer[MCOMM_INPUT_LENGTH_OFFSET];
00134 }
00135
00136 uint8_t mComm_nvmWriteIterator(void)
00137 {
00138 uint8_t address = (uint8_t)( mComm_output.vector.pointer) + mComm_output.counter;
00139
00140 #if defined(MTOUCH_EEPROM_ENABLED)
00141 if ((uint16_t) mComm_output.vector.pointer == 0)
00142 {
00143 mTouch_EEPROM_Reset();
00144 mComm_output.flags.bits.hasNext = 0;
00145 }
00146 else
00147 {
00148 #endif
00149 if (mComm_output.vector.length & 0x01)
00150 {
00151 #if !defined(MTOUCH_EEPROM_STORED_IN_RAM)
00152 eeprom_write(address, mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET] );
00153 #else
00154 mTouch_configOptions[address] = mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET];
00155 #endif
00156
00157 mComm_output.counter++;
00158 }
00159 else
00160 {
00161 #if !defined(MTOUCH_EEPROM_STORED_IN_RAM)
00162 eeprom_write(address, mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET] );
00163 eeprom_write(address+1, mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET + 1] );
00164 #else
00165 mTouch_configOptions[address] = mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET ];
00166 mTouch_configOptions[address+1] = mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET + 1 ];
00167 #endif
00168
00169 mComm_output.counter = mComm_output.counter + 2;
00170 }
00171
00172 if ( mComm_output.counter >= mComm_output.vector.length)
00173 {
00174 mComm_output.flags.bits.hasNext = 0;
00175 }
00176 #if defined(MTOUCH_EEPROM_ENABLED)
00177 }
00178 #endif
00179 return mComm_output.flags.bits.hasNext;
00180 }
00181
00182 uint8_t mComm_nvmReadIterator(void)
00183 {
00184
00185
00186
00187 if (mComm_output.flags.bits.first)
00188 {
00189 mComm_output.flags.bits.first = 0;
00190 #if defined(MCOMM_UART_IMPLEMENTED)
00191 mComm_output.flags.bits.second = 1;
00192 return (mComm_output.vector.length) + 2;
00193 #else
00194 return (mComm_output.vector.length) + 1;
00195 #endif
00196 }
00197 #if defined(MCOMM_UART_IMPLEMENTED)
00198 else if (mComm_output.flags.bits.second)
00199 {
00200 mComm_output.flags.bits.second = 0;
00201 return mComm_output.opcode;
00202 }
00203 #endif
00204 else
00205 {
00206 uint8_t data;
00207
00208 if (mComm_output.flags.bits.high)
00209 {
00210 data = mComm_output.latch;
00211 }
00212 else
00213 {
00214
00215 data = (uint8_t)(mComm_output.vector.pointer) + mComm_output.counter;
00216
00217
00218
00219
00220 #if !defined(MTOUCH_EEPROM_STORED_IN_RAM)
00221 mComm_output.latch = eeprom_read(data + 1);
00222 data = eeprom_read(data );
00223 #else
00224 mComm_output.latch = mTouch_configOptions[data + 1];
00225 data = mTouch_configOptions[data];
00226 #endif
00227
00228
00229 }
00230 mComm_output.flags.bits.high ^= 1;
00231
00232
00233
00234 mComm_output.counter++;
00235 if (mComm_output.counter >= mComm_output.vector.length)
00236 {
00237 mComm_output.flags.bits.hasNext = 0;
00238 }
00239
00240 return data;
00241 }
00242 }
00243
00244 #endif
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 void mComm_processRAM(void)
00257 {
00258 mComm_output.vector.pointer = (uint8_t*) ((mComm_input.buffer[MCOMM_INPUT_ADDRH_OFFSET] << 8) + mComm_input.buffer[MCOMM_INPUT_ADDRL_OFFSET]);
00259 mComm_output.vector.length = mComm_input.buffer[MCOMM_INPUT_LENGTH_OFFSET];
00260
00261
00262
00263 if ((uint16_t) mComm_output.vector.pointer == 0)
00264 {
00265 mComm_output.vector.length = MCOMM_CONFIG_LIT_SIZE;
00266 }
00267 else if ((uint16_t) mComm_output.vector.pointer == 1)
00268 {
00269 mComm_output.vector.length = MCOMM_CONFIG_ADDR_SIZE * 2;
00270 }
00271 }
00272
00273
00274 uint8_t mComm_ramReadIterator(void)
00275 {
00276
00277
00278
00279 if (mComm_output.flags.bits.first)
00280 {
00281 mComm_output.flags.bits.first = 0;
00282 #if defined(MCOMM_UART_IMPLEMENTED)
00283 mComm_output.flags.bits.second = 1;
00284 return (mComm_output.vector.length) + 2;
00285 #else
00286 return (mComm_output.vector.length) + 1;
00287 #endif
00288 }
00289 #if defined(MCOMM_UART_IMPLEMENTED)
00290 else if (mComm_output.flags.bits.second)
00291 {
00292 mComm_output.flags.bits.second = 0;
00293 mComm_output.flags.bits.high = 0;
00294 return mComm_output.opcode;
00295 }
00296 #endif
00297 else
00298 {
00299 uint8_t data;
00300
00301 if (mComm_output.flags.bits.high)
00302 {
00303 data = mComm_output.latch;
00304 }
00305 else
00306 {
00307
00308
00309
00310 if ((uint16_t) mComm_output.vector.pointer == 0)
00311 {
00312 data = mComm_ConfigBlock_Literals[mComm_output.counter ];
00313 mComm_output.latch = mComm_ConfigBlock_Literals[mComm_output.counter+1];
00314 }
00315 else if ((uint16_t) mComm_output.vector.pointer == 1)
00316 {
00317 uint8_t* address = mComm_ConfigBlock_Addrs [mComm_output.counter >> 1];
00318
00319 data = (uint8_t)(address);
00320 mComm_output.latch = (uint8_t)((uint16_t)(address) >> 8);
00321 }
00322 else
00323 {
00324 data = mComm_output.vector.pointer[mComm_output.counter ];
00325 mComm_output.latch = mComm_output.vector.pointer[mComm_output.counter+1];
00326 }
00327
00328
00329 }
00330 mComm_output.flags.bits.high ^= 1;
00331
00332 mComm_output.counter++;
00333 if (mComm_output.counter >= mComm_output.vector.length)
00334 {
00335 mComm_output.flags.bits.hasNext = 0;
00336 }
00337
00338 return data;
00339 }
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 uint8_t mComm_ramWriteIterator(void)
00354 {
00355
00356
00357
00358 mComm_output.vector.pointer[mComm_output.counter ] = mComm_input.buffer[mComm_output.counter + MCOMM_INPUT_PAYLOAD_OFFSET];
00359
00360 mComm_output.counter++;
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 if (mComm_output.counter >= mComm_output.vector.length)
00397 {
00398 mComm_output.flags.bits.hasNext = 0;
00399 }
00400 return mComm_output.flags.bits.hasNext;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 #if defined(MCOMM_ENABLE_STREAM)
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 void mComm_processStream(void)
00431 {
00432 mComm_streamConfig.index = 0;
00433 mComm_output.vector.pointer = mComm_stream[mComm_streamConfig.index].pointer;
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 uint8_t mComm_StreamReadIterator()
00453 {
00454
00455
00456
00457 if (mComm_output.flags.bits.first)
00458 {
00459 uint8_t i = 0;
00460 uint8_t length = 0;
00461 uint8_t count = 0;
00462
00463 mComm_output.flags.bits.high = 0;
00464 mComm_output.flags.bits.first = 0;
00465 #if defined(MCOMM_UART_IMPLEMENTED)
00466 mComm_output.flags.bits.second = 1;
00467 #endif
00468
00469 mComm_output.vector.length = mComm_stream[mComm_streamConfig.index].length;
00470
00471 do {
00472 length = mComm_stream[i].length;
00473 count += length;
00474 i++;
00475 } while (length > 0);
00476 #if defined(MCOMM_UART_IMPLEMENTED)
00477 return count + 2;
00478 #else
00479 return count + 1;
00480 #endif
00481 }
00482
00483 #if defined(MCOMM_UART_IMPLEMENTED)
00484 else if (mComm_output.flags.bits.second)
00485 {
00486 mComm_output.flags.bits.second = 0;
00487
00488 if (mComm_output.vector.length == 0)
00489 {
00490 mComm_output.flags.bits.hasNext = 0;
00491 }
00492
00493 return mComm_output.opcode;
00494 }
00495 #endif
00496
00497 else
00498 {
00499 uint8_t data;
00500
00501 if (mComm_output.flags.bits.high)
00502 {
00503 data = mComm_output.latch;
00504 }
00505 else
00506 {
00507
00508
00509
00510 data = mComm_output.vector.pointer[mComm_output.counter ];
00511 mComm_output.latch = mComm_output.vector.pointer[mComm_output.counter+1];
00512
00513
00514 }
00515 mComm_output.flags.bits.high ^= 1;
00516
00517 mComm_output.counter++;
00518 if (mComm_output.counter >= mComm_output.vector.length)
00519 {
00520 mComm_streamConfig.index++;
00521 mComm_output.flags.bits.high = 0;
00522 mComm_output.counter = 0;
00523 mComm_output.vector.pointer = mComm_stream[mComm_streamConfig.index].pointer;
00524 mComm_output.vector.length = mComm_stream[mComm_streamConfig.index].length;
00525
00526 if ((mComm_output.vector.length == 0) || (mComm_streamConfig.index >= MCOMM_STREAM_SIZE))
00527 {
00528 mComm_output.flags.bits.hasNext = 0;
00529 }
00530 }
00531
00532 return data;
00533 }
00534 }
00535
00536 #endif
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 uint8_t mComm_ErrorIterator(void)
00548 {
00549 mComm_output.flags.bits.hasNext = 0;
00550 return 0x00;
00551 }
00552 void mComm_ErrorProcess(void)
00553 {
00554 return;
00555 }
00556
00557 #endif
00558 #endif