![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
parallelcpld.cpp@116:39a41ebb675c, 2015-04-23 (annotated)
- Committer:
- klauss
- Date:
- Thu Apr 23 20:24:09 2015 +0000
- Revision:
- 116:39a41ebb675c
- Parent:
- 114:472502b31a12
- Child:
- 117:e9facba9db27
inicio do merge da vers?o da ultima vistoria com a da sprint 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "parallelcpld.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 74:81c47fff88a5 | 3 | DigitalOut data0(p30); //LSB |
klauss | 74:81c47fff88a5 | 4 | DigitalOut data1(p31); |
klauss | 74:81c47fff88a5 | 5 | DigitalOut data2(p32); |
klauss | 74:81c47fff88a5 | 6 | DigitalOut data3(p33); |
klauss | 74:81c47fff88a5 | 7 | DigitalOut data4(p34); |
klauss | 74:81c47fff88a5 | 8 | DigitalOut data5(p37); |
klauss | 74:81c47fff88a5 | 9 | DigitalOut data6(p38); |
klauss | 74:81c47fff88a5 | 10 | DigitalOut data7(p39); //MSB |
klauss | 74:81c47fff88a5 | 11 | |
klauss | 74:81c47fff88a5 | 12 | DigitalOut DataReady(p11); |
klauss | 74:81c47fff88a5 | 13 | ///<IO 27 |
klauss | 74:81c47fff88a5 | 14 | |
klauss | 109:a5b8264ffbbc | 15 | DigitalOut hw_extern_wdt( p23 ); |
klauss | 74:81c47fff88a5 | 16 | |
klauss | 116:39a41ebb675c | 17 | uint8_t cb_tx_buffer[ CB_BUFFER_SIZE ]; |
klauss | 109:a5b8264ffbbc | 18 | |
klauss | 116:39a41ebb675c | 19 | uint8_t TXBuffer[ CB_BUFFER_SIZE ]; |
klauss | 74:81c47fff88a5 | 20 | |
klauss | 72:895ca792c647 | 21 | uint8_t tx_clear = 1; |
klauss | 0:4d17cd9c8f9d | 22 | |
klauss | 74:81c47fff88a5 | 23 | ring_buffer * rb = ring_buffer_init( NULL ); |
klauss | 74:81c47fff88a5 | 24 | ring_buffer test; |
klauss | 74:81c47fff88a5 | 25 | |
klauss | 99:e80850c51106 | 26 | Timer delay_to_send_to_cbx; |
klauss | 99:e80850c51106 | 27 | |
klauss | 72:895ca792c647 | 28 | // Print a variable using parallel protocol |
klauss | 72:895ca792c647 | 29 | void parallel_write( uint8_t data ){ |
klauss | 72:895ca792c647 | 30 | data0 = BIT0&(data); |
klauss | 72:895ca792c647 | 31 | data1 = BIT1&(data); |
klauss | 72:895ca792c647 | 32 | data2 = BIT2&(data); |
klauss | 72:895ca792c647 | 33 | data3 = BIT3&(data); |
klauss | 72:895ca792c647 | 34 | data4 = BIT4&(data); |
klauss | 72:895ca792c647 | 35 | data5 = BIT5&(data); |
klauss | 72:895ca792c647 | 36 | data6 = BIT6&(data); |
klauss | 72:895ca792c647 | 37 | data7 = BIT7&(data); |
klauss | 0:4d17cd9c8f9d | 38 | } |
klauss | 0:4d17cd9c8f9d | 39 | |
klauss | 72:895ca792c647 | 40 | // Needs: function parallel_write/ Global variables: TXBuffer, tx_clear / Configuration extern interrupt |
klauss | 74:81c47fff88a5 | 41 | void send2callboxes( uint8_t * buffer ){ |
klauss | 99:e80850c51106 | 42 | static bool once = true; |
klauss | 99:e80850c51106 | 43 | if( once ){ |
klauss | 99:e80850c51106 | 44 | delay_to_send_to_cbx.start(); |
klauss | 99:e80850c51106 | 45 | once = false; |
klauss | 99:e80850c51106 | 46 | } |
klauss | 104:62646ef786a3 | 47 | |
klauss | 104:62646ef786a3 | 48 | delay_to_send_to_cbx.reset(); |
klauss | 104:62646ef786a3 | 49 | |
klauss | 112:6ae726539ab9 | 50 | if ( drop_entendi_pkg && ( buffer[ 6 ] == __INVITE__ ) ) |
klauss | 109:a5b8264ffbbc | 51 | { |
klauss | 109:a5b8264ffbbc | 52 | debug_msg( "Droped entendi pkg" ); |
klauss | 114:472502b31a12 | 53 | return; |
klauss | 109:a5b8264ffbbc | 54 | } |
klauss | 109:a5b8264ffbbc | 55 | |
klauss | 104:62646ef786a3 | 56 | if( tx_clear == 1 ){ |
klauss | 104:62646ef786a3 | 57 | tx_clear = 0; |
klauss | 116:39a41ebb675c | 58 | xmemcpy( TXBuffer, buffer, CB_BUFFER_SIZE ); |
klauss | 104:62646ef786a3 | 59 | // Send the first position of TXBuffer first |
klauss | 104:62646ef786a3 | 60 | parallel_write( TXBuffer[ 0 ] ); |
klauss | 104:62646ef786a3 | 61 | DataReady = 1; |
klauss | 116:39a41ebb675c | 62 | xmemcpy( cb_tx_buffer, buffer, CB_BUFFER_SIZE ); |
klauss | 104:62646ef786a3 | 63 | cpld_pkg_tx_counter++; |
klauss | 104:62646ef786a3 | 64 | |
klauss | 104:62646ef786a3 | 65 | uint16_t ext = ( ( uint16_t )buffer[ 0 ] ) << 8 | buffer[ 1 ]; |
klauss | 104:62646ef786a3 | 66 | uint16_t port = ( ( uint16_t )buffer[ 2 ] ) << 8 | buffer[ 3 ]; |
klauss | 104:62646ef786a3 | 67 | uint8_t type = buffer[ 6 ]; |
klauss | 104:62646ef786a3 | 68 | |
klauss | 104:62646ef786a3 | 69 | if( debug_fw ){ |
klauss | 104:62646ef786a3 | 70 | buffer[ 0 ] |= BIT7; |
klauss | 104:62646ef786a3 | 71 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 104:62646ef786a3 | 72 | } |
klauss | 104:62646ef786a3 | 73 | |
klauss | 104:62646ef786a3 | 74 | if( debug_cb_tx == true ){ |
klauss | 104:62646ef786a3 | 75 | if( type != __AUDIO__ ) send_msg("Pkg to CBx :: ( %d, %d ) -- Type :: %d", ext, port, type ); |
klauss | 104:62646ef786a3 | 76 | } |
klauss | 104:62646ef786a3 | 77 | }else{ |
klauss | 104:62646ef786a3 | 78 | // Error if the transmission is still in use |
klauss | 99:e80850c51106 | 79 | uint8_t ret = ring_buffer_add( rb, buffer ); |
klauss | 81:3656f00ab3db | 80 | |
klauss | 116:39a41ebb675c | 81 | delayed_pkg_to_cb++; |
klauss | 116:39a41ebb675c | 82 | |
klauss | 100:09a23fcd3bdf | 83 | if( ret == 0x01 ) if( dparallel ) debug_msg("Error: Ring buffer fully charged"); |
klauss | 74:81c47fff88a5 | 84 | |
klauss | 92:92df17f538a8 | 85 | if( ret == 0x00 ) if( dparallel ) debug_msg("Success : package queued -- on queue %u", rb->size ); |
klauss | 104:62646ef786a3 | 86 | } |
klauss | 0:4d17cd9c8f9d | 87 | } |
klauss | 0:4d17cd9c8f9d | 88 | |
klauss | 0:4d17cd9c8f9d | 89 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 90 | // EXTERN IRQ Handler |
klauss | 0:4d17cd9c8f9d | 91 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 92 | |
klauss | 72:895ca792c647 | 93 | void get2(){ |
klauss | 72:895ca792c647 | 94 | static uint16_t c = 1; |
klauss | 72:895ca792c647 | 95 | // Get Ready the new data |
klauss | 72:895ca792c647 | 96 | DataReady = 0; |
klauss | 0:4d17cd9c8f9d | 97 | tx_clear = 0; |
klauss | 72:895ca792c647 | 98 | |
klauss | 72:895ca792c647 | 99 | if ( c < 300 ){ |
klauss | 72:895ca792c647 | 100 | // Write the next data to be send |
klauss | 72:895ca792c647 | 101 | parallel_write ( TXBuffer[c] ) ; |
klauss | 72:895ca792c647 | 102 | // Allow the data to be capture |
klauss | 72:895ca792c647 | 103 | DataReady = 1; |
klauss | 0:4d17cd9c8f9d | 104 | }else{ |
klauss | 72:895ca792c647 | 105 | // Allow the next package to the transmitted |
klauss | 72:895ca792c647 | 106 | tx_clear = 1; |
klauss | 72:895ca792c647 | 107 | c = 0; |
klauss | 72:895ca792c647 | 108 | } |
klauss | 0:4d17cd9c8f9d | 109 | c++; |
klauss | 74:81c47fff88a5 | 110 | } |
klauss | 74:81c47fff88a5 | 111 | |
klauss | 74:81c47fff88a5 | 112 | void tx_buffer_ring_buffer_handler( void ){ |
klauss | 100:09a23fcd3bdf | 113 | //if( ( rb->size != 0x00 ) && ( tx_clear == 1 ) && ( delay_to_send_to_cbx.read_ms() > 7 ) ){ |
klauss | 100:09a23fcd3bdf | 114 | if( ( rb->size != 0x00 ) && ( tx_clear == 1 ) ){ |
klauss | 116:39a41ebb675c | 115 | //uint8_t buffer[ CB_BUFFER_SIZE ]; |
klauss | 74:81c47fff88a5 | 116 | uint8_t * _rb_next = ring_buffer_get_next( rb ); |
klauss | 116:39a41ebb675c | 117 | //xmemcpy( buffer, _rb_next, CB_BUFFER_SIZE ); |
klauss | 74:81c47fff88a5 | 118 | if( dparallel ) send_msg( "Ring Buffer less one -- remain %u", rb->size ); |
klauss | 99:e80850c51106 | 119 | send2callboxes( _rb_next ); |
klauss | 74:81c47fff88a5 | 120 | } |
klauss | 0:4d17cd9c8f9d | 121 | } |