![](/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
- Committer:
- klauss
- Date:
- 2015-03-10
- Revision:
- 105:a930035b6556
- Parent:
- 104:62646ef786a3
- Child:
- 106:a34fcf9f0e02
File content as of revision 105:a930035b6556:
#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; 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( 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 ]; //pra debug, encaminha todos os pacotes da rede fibra para o servidor de fw 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 ); } }