![](/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@132:05cd37f7e007, 2015-09-01 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 01 17:21:11 2015 +0000
- Revision:
- 132:05cd37f7e007
- Parent:
- 126:1f90756250fb
Substitui??o de; send_msg -> vz_printf; debug_msg -> vz_debug
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 | 126:1f90756250fb | 17 | uint8_t cb_tx_buffer [ CB_BUFFER_SIZE ]; |
klauss | 109:a5b8264ffbbc | 18 | |
klauss | 119:ee6a53069455 | 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 | 99:e80850c51106 | 24 | |
klauss | 72:895ca792c647 | 25 | // Print a variable using parallel protocol |
klauss | 72:895ca792c647 | 26 | void parallel_write( uint8_t data ){ |
klauss | 72:895ca792c647 | 27 | data0 = BIT0&(data); |
klauss | 72:895ca792c647 | 28 | data1 = BIT1&(data); |
klauss | 72:895ca792c647 | 29 | data2 = BIT2&(data); |
klauss | 72:895ca792c647 | 30 | data3 = BIT3&(data); |
klauss | 72:895ca792c647 | 31 | data4 = BIT4&(data); |
klauss | 72:895ca792c647 | 32 | data5 = BIT5&(data); |
klauss | 72:895ca792c647 | 33 | data6 = BIT6&(data); |
klauss | 72:895ca792c647 | 34 | data7 = BIT7&(data); |
klauss | 0:4d17cd9c8f9d | 35 | } |
klauss | 0:4d17cd9c8f9d | 36 | |
klauss | 72:895ca792c647 | 37 | // Needs: function parallel_write/ Global variables: TXBuffer, tx_clear / Configuration extern interrupt |
klauss | 126:1f90756250fb | 38 | void send2callboxes( uint8_t * buffer ) |
klauss | 126:1f90756250fb | 39 | { |
klauss | 126:1f90756250fb | 40 | if ( drop_entendi_pkg and ( buffer[ TYPE_PLACE ] == INVITE ) ) |
klauss | 109:a5b8264ffbbc | 41 | { |
klauss | 132:05cd37f7e007 | 42 | vz_debug ( "Droped entendi pkg" ); |
klauss | 114:472502b31a12 | 43 | return; |
klauss | 109:a5b8264ffbbc | 44 | } |
klauss | 126:1f90756250fb | 45 | |
klauss | 126:1f90756250fb | 46 | if( tx_clear == 1 ) |
klauss | 126:1f90756250fb | 47 | { |
klauss | 104:62646ef786a3 | 48 | tx_clear = 0; |
klauss | 126:1f90756250fb | 49 | xmemcpy ( TXBuffer, buffer, CB_BUFFER_SIZE ); |
klauss | 124:c1b6c893e1c3 | 50 | |
klauss | 104:62646ef786a3 | 51 | // Send the first position of TXBuffer first |
klauss | 126:1f90756250fb | 52 | parallel_write ( TXBuffer [ 0 ] ); |
klauss | 104:62646ef786a3 | 53 | DataReady = 1; |
klauss | 124:c1b6c893e1c3 | 54 | |
klauss | 104:62646ef786a3 | 55 | cpld_pkg_tx_counter++; |
klauss | 104:62646ef786a3 | 56 | |
klauss | 104:62646ef786a3 | 57 | uint16_t ext = ( ( uint16_t )buffer[ 0 ] ) << 8 | buffer[ 1 ]; |
klauss | 104:62646ef786a3 | 58 | uint16_t port = ( ( uint16_t )buffer[ 2 ] ) << 8 | buffer[ 3 ]; |
klauss | 126:1f90756250fb | 59 | uint8_t type = buffer [ TYPE_PLACE ]; |
klauss | 104:62646ef786a3 | 60 | |
klauss | 126:1f90756250fb | 61 | if ( debug_fw ) |
klauss | 126:1f90756250fb | 62 | { |
klauss | 104:62646ef786a3 | 63 | buffer[ 0 ] |= BIT7; |
klauss | 126:1f90756250fb | 64 | fw_cbx_pkg ( ext, ( char *)buffer ); |
klauss | 104:62646ef786a3 | 65 | } |
klauss | 104:62646ef786a3 | 66 | |
klauss | 126:1f90756250fb | 67 | if ( ( type not_eq AUDIO ) and not ( do_not_show_this_invite_pkg ) ) |
klauss | 124:c1b6c893e1c3 | 68 | { |
klauss | 126:1f90756250fb | 69 | xmemcpy ( cb_tx_buffer, buffer, CB_BUFFER_SIZE ); |
klauss | 124:c1b6c893e1c3 | 70 | |
klauss | 124:c1b6c893e1c3 | 71 | if ( debug_show_tx_cpld ) |
klauss | 124:c1b6c893e1c3 | 72 | { |
klauss | 126:1f90756250fb | 73 | char str [ 256 ]; |
klauss | 126:1f90756250fb | 74 | strcpy ( str, "TX :: \n\r" ); |
klauss | 126:1f90756250fb | 75 | for ( register uint16_t i = 0; i < 32; i++ ) |
klauss | 126:1f90756250fb | 76 | { |
klauss | 126:1f90756250fb | 77 | char tmp [ 8 ]; |
klauss | 126:1f90756250fb | 78 | sprintf ( tmp, "%02x ", cb_tx_buffer [ i ] ); |
klauss | 126:1f90756250fb | 79 | strcat ( str, tmp ); |
klauss | 124:c1b6c893e1c3 | 80 | } |
klauss | 125:8ff4dc96ad58 | 81 | strcat ( str, "\n\r " ); |
klauss | 125:8ff4dc96ad58 | 82 | |
klauss | 132:05cd37f7e007 | 83 | vz_printf ( "%s", str ); |
klauss | 124:c1b6c893e1c3 | 84 | } |
klauss | 125:8ff4dc96ad58 | 85 | |
klauss | 132:05cd37f7e007 | 86 | if ( debug_cb_tx ) vz_printf ("H -> CBx :: ( %d, %d ) -- Type :: %d", ext, port, type ); |
klauss | 126:1f90756250fb | 87 | |
klauss | 132:05cd37f7e007 | 88 | if ( debug_sqn ) vz_printf ("H -> CBx :: ( %d, %d ) -- Type :: %d -- seq_num :: %u", ext, port, type, cb_tx_buffer [ SEQ_NUM_PLACE ] ); |
klauss | 124:c1b6c893e1c3 | 89 | } |
klauss | 126:1f90756250fb | 90 | |
klauss | 126:1f90756250fb | 91 | do_not_show_this_invite_pkg = false; |
klauss | 124:c1b6c893e1c3 | 92 | |
klauss | 104:62646ef786a3 | 93 | }else{ |
klauss | 104:62646ef786a3 | 94 | // Error if the transmission is still in use |
klauss | 99:e80850c51106 | 95 | uint8_t ret = ring_buffer_add( rb, buffer ); |
klauss | 81:3656f00ab3db | 96 | |
klauss | 119:ee6a53069455 | 97 | delayed_pkg_to_cb++; |
klauss | 119:ee6a53069455 | 98 | |
klauss | 132:05cd37f7e007 | 99 | if( ret == 0x01 ) if( dparallel ) vz_debug ("Error: Ring buffer fully charged"); |
klauss | 74:81c47fff88a5 | 100 | |
klauss | 132:05cd37f7e007 | 101 | if( ret == 0x00 ) if( dparallel ) vz_debug ("Success : package queued -- on queue %u", rb->size ); |
klauss | 104:62646ef786a3 | 102 | } |
klauss | 0:4d17cd9c8f9d | 103 | } |
klauss | 0:4d17cd9c8f9d | 104 | |
klauss | 0:4d17cd9c8f9d | 105 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 106 | // EXTERN IRQ Handler |
klauss | 0:4d17cd9c8f9d | 107 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 108 | |
klauss | 72:895ca792c647 | 109 | void get2(){ |
klauss | 72:895ca792c647 | 110 | static uint16_t c = 1; |
klauss | 72:895ca792c647 | 111 | // Get Ready the new data |
klauss | 72:895ca792c647 | 112 | DataReady = 0; |
klauss | 0:4d17cd9c8f9d | 113 | tx_clear = 0; |
klauss | 72:895ca792c647 | 114 | |
klauss | 72:895ca792c647 | 115 | if ( c < 300 ){ |
klauss | 72:895ca792c647 | 116 | // Write the next data to be send |
klauss | 72:895ca792c647 | 117 | parallel_write ( TXBuffer[c] ) ; |
klauss | 72:895ca792c647 | 118 | // Allow the data to be capture |
klauss | 72:895ca792c647 | 119 | DataReady = 1; |
klauss | 0:4d17cd9c8f9d | 120 | }else{ |
klauss | 72:895ca792c647 | 121 | // Allow the next package to the transmitted |
klauss | 72:895ca792c647 | 122 | tx_clear = 1; |
klauss | 72:895ca792c647 | 123 | c = 0; |
klauss | 72:895ca792c647 | 124 | } |
klauss | 0:4d17cd9c8f9d | 125 | c++; |
klauss | 74:81c47fff88a5 | 126 | } |
klauss | 74:81c47fff88a5 | 127 | |
klauss | 74:81c47fff88a5 | 128 | void tx_buffer_ring_buffer_handler( void ){ |
klauss | 100:09a23fcd3bdf | 129 | if( ( rb->size != 0x00 ) && ( tx_clear == 1 ) ){ |
klauss | 74:81c47fff88a5 | 130 | uint8_t * _rb_next = ring_buffer_get_next( rb ); |
klauss | 132:05cd37f7e007 | 131 | if( dparallel ) vz_printf ( "Ring Buffer less one -- remain %u", rb->size ); |
klauss | 99:e80850c51106 | 132 | send2callboxes( _rb_next ); |
klauss | 74:81c47fff88a5 | 133 | } |
klauss | 0:4d17cd9c8f9d | 134 | } |