Example #1
0
void RTTeensyLink::background()
{
    while (Serial.available()) {
        if (!RTTeensyLinkReassemble(&(m_RXFrame), Serial.read())) {
            sendDebugMessage("Reassembly error");
        } else {
            if (m_RXFrame.complete) {
                processReceivedMessage();
                RTTeensyLinkRXFrameInit(&(m_RXFrame), &(m_RXFrameBuffer));
            }
        }
    }
}
/////////////////////////////////////////////////////////////////////////////
// This function searches for a givem voice. If it is already allocated,
// it continues at get(), otherwise it returns current_voice
// Note: this function will always return a valid voice, and never a negative
// result (therefore u8)
/////////////////////////////////////////////////////////////////////////////
u8 MbSidVoiceQueue::getLast(u8 instrument, u8 voice_asg, u8 num_voices, u8 search_voice)
{
    // search in queue for selected voice
    mbsid_voice_queue_item_t *item = (mbsid_voice_queue_item_t *)&queue.item[0];
    for(int voice=0; voice<SID_SE_NUM_VOICES; ++voice, ++item)
        if( item->voice == search_voice ) {
            // selected voice found
            // if instrument number not equal, we should get a new voice
            if( item->instrument != instrument )
                break;
            // if number of available voices has changed meanwhile (e.g. Stereo->Mono switch):
            // check that voice number still < n
            if( item->voice >= num_voices )
                break;

            // it's mine!

            // assign voice (again)
            item->ASSIGNED = 1;

            // if this isn't already the last voice, put this item to the end of the queue
            if( voice < (SID_SE_NUM_VOICES-1) ) {
                mbsid_voice_queue_item_t stored_item = *item;
                int i;
                for(i=voice; i<(SID_SE_NUM_VOICES-1); ++i)
                    queue.item[i] = queue.item[i+1];
                queue.item[SID_SE_NUM_VOICES-1] = stored_item;
            }

#if DEBUG_VERBOSE_LEVEL >= 2
            sendDebugMessage(sid);
#endif

            // return with voice number
            return queue.item[SID_SE_NUM_VOICES-1].voice;

        }

    // voice not found, continue at get()
    return get(instrument, voice_asg, num_voices);
}
void RTArduLink::background()
{
    unsigned char index;
    RTARDULINK_PORT *portInfo;

    for (index = 0; index < RTARDULINKHAL_MAX_PORTS; index++) {
        portInfo = m_ports + index;
        if (!portInfo->inUse)
            continue;

        while (RTArduLinkHALPortAvailable(&(portInfo->portHAL))) {
            if (!RTArduLinkReassemble(&(portInfo->RXFrame), RTArduLinkHALPortRead(&(portInfo->portHAL)))) {
                sendDebugMessage("Reassembly error");
            } else {
                if (portInfo->RXFrame.complete) {
                    processReceivedMessage(portInfo);
                    RTArduLinkRXFrameInit(&(portInfo->RXFrame), &(portInfo->RXFrameBuffer));
                }
            }
        }
    }
}
/////////////////////////////////////////////////////////////////////////////
// This function releases a voice, so that it is free for get()
// Note: this function will always return a valid voice, and never a negative
// result (therefore u8)
/////////////////////////////////////////////////////////////////////////////
u8 MbSidVoiceQueue::release(u8 release_voice)
{
    // search in voice queue for the voice
    mbsid_voice_queue_item_t *item = (mbsid_voice_queue_item_t *)&queue.item[0];
    for(int voice=0; voice<SID_SE_NUM_VOICES; ++voice, ++item)
        if( item->voice == release_voice ) {
            item->ASSIGNED = 0;

#if DEBUG_VERBOSE_LEVEL >= 2
            sendDebugMessage();
#endif

            return item->voice;
        }

    // we should never reach this part!
#if DEBUG_VERBOSE_LEVEL >= 1
    DEBUG_MSG("[voiceRelease] voice %d not in queue anymore!\n", release_voice);
#endif

    return 0; // take first voice on this error case

}
Example #5
0
void NFC_APP_Tasks ( void )
{
    char inChar;
    while(1) {
        while(!xQueueReceive(nfc_appData.inQ, &inChar, portMAX_DELAY));
        sendDebugMessage("CHECK NFC\0");
        checkNFC();
        sendDebugMessage("WAIT ON ACK\0");
        while(!getACK()) {
            sendDebugMessage("SEND NACK\0");
            sendNACK();
        }
        sendDebugMessage("GOT ACK\0");
        if (getCheckNFC()) {
            sendDebugMessage("TOKEN FOUND\0");
            addToUartTXQ(tokenFound());
        }
        else {
            sendDebugMessage("NO TOKEN\0");
        }

    }
}
// get/release functions
/////////////////////////////////////////////////////////////////////////////
// This function searches for a voice which is not allocated, or drops the
// voice which played the longest note.
// Note: this function will always return a valid voice, and never a negative
// result (therefore u8)
/////////////////////////////////////////////////////////////////////////////
u8 MbSidVoiceQueue::get(u8 instrument, u8 voice_asg, u8 num_voices)
{
    if( num_voices > SID_SE_NUM_VOICES )
        num_voices = SID_SE_NUM_VOICES;

    // determine allowed voices (each voice has a dedicated flag)
    u32 allowed_voice_mask;
    switch( voice_asg ) {
    case 0: // all voices
        allowed_voice_mask = (1 << SID_SE_NUM_VOICES)-1; // all voices
        break;

    case 1: // only left voices
        allowed_voice_mask = (1 << (SID_SE_NUM_VOICES/2))-1;
        break;

    case 2: // only right voices
        if( num_voices <= (SID_SE_NUM_VOICES/2) )
            allowed_voice_mask = (1 << (SID_SE_NUM_VOICES/2))-1; // Mono mode: take left voices
        else
            allowed_voice_mask = ((1 << (SID_SE_NUM_VOICES/2))-1) << (SID_SE_NUM_VOICES/2); // only right voices
        break;

    default: { // dedicated voice
        u8 dedicated_voice = (voice_asg-3) % num_voices; // if mono mode: take left voice
        allowed_voice_mask = (1 << dedicated_voice);
    }
    }

    // search for voice and allocate it
    mbsid_voice_queue_item_t *item = (mbsid_voice_queue_item_t *)&queue.item[0];
    for(int voice=0; voice<SID_SE_NUM_VOICES; ++voice, ++item) {
        if( allowed_voice_mask & (1 << item->voice) &&
            (!item->EXCLUSIVE || (item->instrument == instrument) || (voice_asg >= 3)) ) {
            // assign voice and save instrument number
            item->ASSIGNED = 1;
            item->EXCLUSIVE = (voice_asg >= 3) ? 1 : 0; // exclusive assignment?
            item->instrument = instrument;

            // if this isn't already the last voice, put this item to the end of the queue
            if( voice < (SID_SE_NUM_VOICES-1) ) {
                mbsid_voice_queue_item_t stored_item = *item;
                int i;
                for(i=voice; i<(SID_SE_NUM_VOICES-1); ++i)
                    queue.item[i] = queue.item[i+1];
                queue.item[SID_SE_NUM_VOICES-1] = stored_item;
            }

#if DEBUG_VERBOSE_LEVEL >= 2
            sendDebugMessage(sid);
#endif

            // return with voice number
            return queue.item[SID_SE_NUM_VOICES-1].voice;
        }
    }

    // we should never reach this part!
#if DEBUG_VERBOSE_LEVEL >= 1
    DEBUG_MSG("[VoiceQueueGet] voice not in queue anymore (voice_asg: 0x%02x, allowed_mask: 0x%02x)\n", voice_asg, allowed_voice_mask);
#endif

    return 0; // take first voice on this error case
}