For robots and stuff

Dependents:   Base Station

CC1101/CC1101-Threads.cpp

Committer:
jjones646
Date:
2014-12-31
Revision:
2:c42a035d71ed
Parent:
1:05a48c038381

File content as of revision 2:c42a035d71ed:

#include "Radio.h"


/*

// SERIAL THREAD
void CC1101::get_serial_data_thread(void const *arg)
{
    CC1101 *instance = (CC1101*)arg;
    osSignalWait(START_THREAD, osWaitForever);
    Timer t;

    while(1) {

        if (instance->_pc.readable()) {

            if (t.read_us()) {
                t.reset();
            } else {
                t.start();
            }

            instance->_rx_int->disable_irq();
            instance->rxBuf.putc(instance->_pc.getc());
            instance->_rx_int->enable_irq();
        }

        if ( (instance->rxBuf.use() > 20) | (t.read_ms() > 50)) {      // if more than 20 bytes received then tx the packet in RF
            // set the signal for sending data
            instance->_transmit_thread.signal_set(NEW_DATA);
            t.stop();
            t.reset();
        }

        Thread::wait(50);

    }
}

*/

// TRANSMITTING THREAD
void Radio::transmit_thread(void const *arg)
{
    Radio *instance = (Radio*)arg;
    osSignalWait(START_THREAD, osWaitForever);

    while(1) {

        osSignalWait(START_THREAD, osWaitForever);

        /* osEvent evt = instance->_tx_data.get();
        if (evt.status == osEventMail) {
            RTP_t *mail = (RTP_t*)evt.value.p;

            instance->put_pck(mail->payload, mail->size);    // send the packet over air
        }
        */
    }
}


// RECEIVING THREAD
void Radio::receive_thread(void const *arg)
{
    Radio *instance = (Radio*)arg;
    osSignalWait(START_THREAD, osWaitForever);

    // receiving operations
    while(1) {

        osSignalWait(START_THREAD, osWaitForever);


        /*
        osSignalWait(NEW_DATA, osWaitForever);

        // set the limit for max bytes to put in the buffer every time
        uint8_t rxlength = BUFFER_SIZE;

        instance->_spi->frequency(8500000);
        if (instance->get_pck(instance->buffer, &rxlength) ) {

            if (instance->buffer[0] == 0x02) {
                instance->_need_ack = false;
            } else {

                RTP_t *data = instance->_rx_data.alloc();
                data->payload = instance->buffer;
                instance->_rx_data.put(data);

                // send the data over the serial connection
        #if DEBUG_MODE > 0
                std::printf("  ==============\r\n");
                for (int i=0; i < rxlength; i++) {
                    std::printf("  |    0x%02X    |\r\n", instance->buffer[i]);
                }
                std::printf("  ==============\r\n");
        #endif

            }
        } else {
            std::printf("Receiving packet failure\r\n");
        }
        instance->_spi->frequency(5000000);
        */
    }
}