Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
parallelcpld.cpp
- Committer:
- klauss
- Date:
- 2015-01-10
- Revision:
- 92:92df17f538a8
- Parent:
- 81:3656f00ab3db
- Child:
- 97:8985817e8847
File content as of revision 92:92df17f538a8:
#include "parallelcpld.h" DigitalOut data0(p30); //LSB DigitalOut data1(p31); DigitalOut data2(p32); DigitalOut data3(p33); DigitalOut data4(p34); DigitalOut data5(p37); DigitalOut data6(p38); DigitalOut data7(p39); //MSB DigitalOut DataReady(p11); ///<IO 27 uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ]; uint8_t TXBuffer[ __CB_BUFFER_SIZE__ ]; uint8_t tx_clear = 1; ring_buffer * rb = ring_buffer_init( NULL ); ring_buffer test; // Print a variable using parallel protocol void parallel_write( uint8_t data ){ data0 = BIT0&(data); data1 = BIT1&(data); data2 = BIT2&(data); data3 = BIT3&(data); data4 = BIT4&(data); data5 = BIT5&(data); data6 = BIT6&(data); data7 = BIT7&(data); } // Needs: function parallel_write/ Global variables: TXBuffer, tx_clear / Configuration extern interrupt void send2callboxes( uint8_t * buffer ){ // Send the first position of TXBuffer first if( tx_clear == 1 ){ tx_clear = 0; xmemcpy( TXBuffer, buffer, __CB_BUFFER_SIZE__ ); parallel_write( TXBuffer[ 0 ] ); DataReady = 1; xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ ); if( tx || debug_invite ){ if( ( debug_invite ) && ( ( buffer[ 6 ] == __INVITE__ ) || ( buffer[ 6 ] == __CB_BYE__ ) ) ){ char str[ 128 ]; strcpy( str, "TX -> CB:: \n\r " ); for( register uint16_t i = 0; i < 32; i++ ){ char tmp[ 16 ]; strcat( str, itoa( cb_tx_buffer[ i ], tmp, 16 ) ); if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); else strcat( str, " " ); } debug_msg( "%s", str ); } else if( tx ){ char str[ 1024 ]; strcpy( str, "TX :: \n\r " ); for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ char tmp[ 16 ]; strcat( str, itoa( cb_tx_buffer[ i ], tmp, 16 ) ); if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); else strcat( str, " " ); } send_msg( "%s", str ); tx = false; } } }else{ // Error if the transmission is still in use uint8_t ret = ring_buffer_add( rb, buffer ); if( ret == 0x01 ) if( dparallel ) debug_msg("Error: Ring buffer fully charged"); if( ret == 0x00 ) if( dparallel ) debug_msg("Success : package queued -- on queue %u", rb->size ); } } //***************************************************************************** // EXTERN IRQ Handler //***************************************************************************** void get2(){ static uint16_t c = 1; // Get Ready the new data DataReady = 0; tx_clear = 0; if ( c < 300 ){ // Write the next data to be send parallel_write ( TXBuffer[c] ) ; // Allow the data to be capture DataReady = 1; }else{ // Allow the next package to the transmitted tx_clear = 1; c = 0; } c++; } void tx_buffer_ring_buffer_handler( void ){ if( ( rb->size != 0x00 ) && ( tx_clear == 1 ) ){ uint8_t buffer[ __CB_BUFFER_SIZE__ ]; uint8_t * _rb_next = ring_buffer_get_next( rb ); xmemcpy( buffer, _rb_next, __CB_BUFFER_SIZE__ ); if( dparallel ) send_msg( "Ring Buffer less one -- remain %u", rb->size ); send2callboxes( buffer ); } }