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-04-23
- Revision:
- 117:e9facba9db27
- Parent:
- 116:39a41ebb675c
- Child:
- 119:ee6a53069455
File content as of revision 117:e9facba9db27:
#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 DigitalOut hw_extern_wdt( p23 ); 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; Timer delay_to_send_to_cbx; // 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 ){ static bool once = true; if( once ){ delay_to_send_to_cbx.start(); once = false; } delay_to_send_to_cbx.reset(); if ( drop_entendi_pkg && ( buffer[ 6 ] == __INVITE__ ) ) { debug_msg( "Droped entendi pkg" ); return; } if( tx_clear == 1 ){ tx_clear = 0; xmemcpy( TXBuffer, buffer, __CB_BUFFER_SIZE__ ); // Send the first position of TXBuffer first parallel_write( TXBuffer[ 0 ] ); DataReady = 1; xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ ); cpld_pkg_tx_counter++; uint16_t ext = ( ( uint16_t )buffer[ 0 ] ) << 8 | buffer[ 1 ]; uint16_t port = ( ( uint16_t )buffer[ 2 ] ) << 8 | buffer[ 3 ]; uint8_t type = buffer[ 6 ]; if( debug_fw ){ buffer[ 0 ] |= BIT7; fw_cbx_pkg( ext, port, ( char *)buffer ); } if( debug_cb_tx == true ){ if( type != __AUDIO__ ) send_msg("Pkg to CBx :: ( %d, %d ) -- Type :: %d", ext, port, type ); } }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 ) && ( delay_to_send_to_cbx.read_ms() > 7 ) ){ 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( _rb_next ); } }