Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

parallelcpld.cpp

Committer:
klauss
Date:
2014-11-24
Revision:
74:81c47fff88a5
Parent:
72:895ca792c647
Child:
81:3656f00ab3db

File content as of revision 74:81c47fff88a5:

#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__ );           
    }else{
        // Error if the transmission is still in use
        uint8_t ret = ring_buffer_add( rb, buffer );
        
        if( ret == 0x01 ) if( dparallel ) send_msg("Error: Ring buffer fully charged");
        
        if( ret == 0x00 ) if( dparallel ) send_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 );
    }
}