![](/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@97:8985817e8847, 2015-01-10 (annotated)
- Committer:
- klauss
- Date:
- Sat Jan 10 23:59:51 2015 +0000
- Revision:
- 97:8985817e8847
- Parent:
- 92:92df17f538a8
- Child:
- 99:e80850c51106
wip
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 | 74:81c47fff88a5 | 15 | uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 74:81c47fff88a5 | 16 | |
klauss | 74:81c47fff88a5 | 17 | uint8_t TXBuffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 74:81c47fff88a5 | 18 | |
klauss | 72:895ca792c647 | 19 | uint8_t tx_clear = 1; |
klauss | 0:4d17cd9c8f9d | 20 | |
klauss | 74:81c47fff88a5 | 21 | ring_buffer * rb = ring_buffer_init( NULL ); |
klauss | 74:81c47fff88a5 | 22 | ring_buffer test; |
klauss | 74:81c47fff88a5 | 23 | |
klauss | 72:895ca792c647 | 24 | // Print a variable using parallel protocol |
klauss | 72:895ca792c647 | 25 | void parallel_write( uint8_t data ){ |
klauss | 72:895ca792c647 | 26 | data0 = BIT0&(data); |
klauss | 72:895ca792c647 | 27 | data1 = BIT1&(data); |
klauss | 72:895ca792c647 | 28 | data2 = BIT2&(data); |
klauss | 72:895ca792c647 | 29 | data3 = BIT3&(data); |
klauss | 72:895ca792c647 | 30 | data4 = BIT4&(data); |
klauss | 72:895ca792c647 | 31 | data5 = BIT5&(data); |
klauss | 72:895ca792c647 | 32 | data6 = BIT6&(data); |
klauss | 72:895ca792c647 | 33 | data7 = BIT7&(data); |
klauss | 0:4d17cd9c8f9d | 34 | } |
klauss | 0:4d17cd9c8f9d | 35 | |
klauss | 72:895ca792c647 | 36 | // Needs: function parallel_write/ Global variables: TXBuffer, tx_clear / Configuration extern interrupt |
klauss | 74:81c47fff88a5 | 37 | void send2callboxes( uint8_t * buffer ){ |
klauss | 72:895ca792c647 | 38 | // Send the first position of TXBuffer first |
klauss | 72:895ca792c647 | 39 | if( tx_clear == 1 ){ |
klauss | 74:81c47fff88a5 | 40 | tx_clear = 0; |
klauss | 74:81c47fff88a5 | 41 | xmemcpy( TXBuffer, buffer, __CB_BUFFER_SIZE__ ); |
klauss | 74:81c47fff88a5 | 42 | parallel_write( TXBuffer[ 0 ] ); |
klauss | 74:81c47fff88a5 | 43 | DataReady = 1; |
klauss | 81:3656f00ab3db | 44 | xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ ); |
klauss | 81:3656f00ab3db | 45 | |
klauss | 92:92df17f538a8 | 46 | if( tx || debug_invite ){ |
klauss | 92:92df17f538a8 | 47 | if( ( debug_invite ) && ( ( buffer[ 6 ] == __INVITE__ ) || ( buffer[ 6 ] == __CB_BYE__ ) ) ){ |
klauss | 92:92df17f538a8 | 48 | char str[ 128 ]; |
klauss | 92:92df17f538a8 | 49 | strcpy( str, "TX -> CB:: \n\r " ); |
klauss | 92:92df17f538a8 | 50 | for( register uint16_t i = 0; i < 32; i++ ){ |
klauss | 92:92df17f538a8 | 51 | char tmp[ 16 ]; |
klauss | 92:92df17f538a8 | 52 | strcat( str, itoa( cb_tx_buffer[ i ], tmp, 16 ) ); |
klauss | 92:92df17f538a8 | 53 | |
klauss | 92:92df17f538a8 | 54 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 92:92df17f538a8 | 55 | |
klauss | 92:92df17f538a8 | 56 | else strcat( str, " " ); |
klauss | 92:92df17f538a8 | 57 | } |
klauss | 97:8985817e8847 | 58 | send_msg( "%s", str ); |
klauss | 92:92df17f538a8 | 59 | } else if( tx ){ |
klauss | 92:92df17f538a8 | 60 | char str[ 1024 ]; |
klauss | 92:92df17f538a8 | 61 | strcpy( str, "TX :: \n\r " ); |
klauss | 92:92df17f538a8 | 62 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 92:92df17f538a8 | 63 | char tmp[ 16 ]; |
klauss | 92:92df17f538a8 | 64 | strcat( str, itoa( cb_tx_buffer[ i ], tmp, 16 ) ); |
klauss | 92:92df17f538a8 | 65 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 92:92df17f538a8 | 66 | |
klauss | 92:92df17f538a8 | 67 | else strcat( str, " " ); |
klauss | 92:92df17f538a8 | 68 | } |
klauss | 92:92df17f538a8 | 69 | send_msg( "%s", str ); |
klauss | 92:92df17f538a8 | 70 | tx = false; |
klauss | 81:3656f00ab3db | 71 | } |
klauss | 81:3656f00ab3db | 72 | } |
klauss | 72:895ca792c647 | 73 | }else{ |
klauss | 72:895ca792c647 | 74 | // Error if the transmission is still in use |
klauss | 74:81c47fff88a5 | 75 | uint8_t ret = ring_buffer_add( rb, buffer ); |
klauss | 74:81c47fff88a5 | 76 | |
klauss | 92:92df17f538a8 | 77 | if( ret == 0x01 ) if( dparallel ) debug_msg("Error: Ring buffer fully charged"); |
klauss | 74:81c47fff88a5 | 78 | |
klauss | 92:92df17f538a8 | 79 | if( ret == 0x00 ) if( dparallel ) debug_msg("Success : package queued -- on queue %u", rb->size ); |
klauss | 72:895ca792c647 | 80 | } |
klauss | 0:4d17cd9c8f9d | 81 | } |
klauss | 0:4d17cd9c8f9d | 82 | |
klauss | 0:4d17cd9c8f9d | 83 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 84 | // EXTERN IRQ Handler |
klauss | 0:4d17cd9c8f9d | 85 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 86 | |
klauss | 72:895ca792c647 | 87 | void get2(){ |
klauss | 72:895ca792c647 | 88 | static uint16_t c = 1; |
klauss | 72:895ca792c647 | 89 | // Get Ready the new data |
klauss | 72:895ca792c647 | 90 | DataReady = 0; |
klauss | 0:4d17cd9c8f9d | 91 | tx_clear = 0; |
klauss | 72:895ca792c647 | 92 | |
klauss | 72:895ca792c647 | 93 | if ( c < 300 ){ |
klauss | 72:895ca792c647 | 94 | // Write the next data to be send |
klauss | 72:895ca792c647 | 95 | parallel_write ( TXBuffer[c] ) ; |
klauss | 72:895ca792c647 | 96 | // Allow the data to be capture |
klauss | 72:895ca792c647 | 97 | DataReady = 1; |
klauss | 0:4d17cd9c8f9d | 98 | }else{ |
klauss | 72:895ca792c647 | 99 | // Allow the next package to the transmitted |
klauss | 72:895ca792c647 | 100 | tx_clear = 1; |
klauss | 72:895ca792c647 | 101 | c = 0; |
klauss | 72:895ca792c647 | 102 | } |
klauss | 0:4d17cd9c8f9d | 103 | c++; |
klauss | 74:81c47fff88a5 | 104 | } |
klauss | 74:81c47fff88a5 | 105 | |
klauss | 74:81c47fff88a5 | 106 | void tx_buffer_ring_buffer_handler( void ){ |
klauss | 74:81c47fff88a5 | 107 | if( ( rb->size != 0x00 ) && ( tx_clear == 1 ) ){ |
klauss | 74:81c47fff88a5 | 108 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 74:81c47fff88a5 | 109 | uint8_t * _rb_next = ring_buffer_get_next( rb ); |
klauss | 74:81c47fff88a5 | 110 | xmemcpy( buffer, _rb_next, __CB_BUFFER_SIZE__ ); |
klauss | 74:81c47fff88a5 | 111 | if( dparallel ) send_msg( "Ring Buffer less one -- remain %u", rb->size ); |
klauss | 74:81c47fff88a5 | 112 | send2callboxes( buffer ); |
klauss | 74:81c47fff88a5 | 113 | } |
klauss | 0:4d17cd9c8f9d | 114 | } |