Beispiel #1
0
// Send speed, accelerometer and brake values to a 100 element MAIL queue
// car mail semaphore used to protect messages
// average speed and input semphore used to fix vales
// Repetition rate 0.2 Hz = 5 seconds
void sendToMail(void const *args){
    while(true){
        mail_t *mail = mail_box.alloc();
        CAR_MAIL_SEM.wait();

        AVR_SPEED_SEM.wait();
        mail->speedVal = averageSpeed; 
        AVR_SPEED_SEM.release();
        
        INPUT_SEM.wait();
        mail->accelerometerVal = accelerationValue;
        mail->breakVal = brakeValue;
        INPUT_SEM.release();
        
        write++;        
       
        mail_box.put(mail);
                
        CAR_MAIL_SEM.release();
                
        Thread::wait(5000);  
    }
}
Beispiel #2
0
// Call this on precise intervals
void adcISR() {

    
    //Read sample - make a copy
    float sample = adcIn;
    //Grab switch state
    uint32_t switch1State = sw1;
    uint32_t switch2State = sw2;
    
    //Allocate a block from the memory pool
    message_t *message = mail_box.alloc();
    if (message == NULL) {
        //Out of memory
        printf("Out of memory\n\r");
        redLED = 1;
        return;   
    }
    
    //Fill in the data
    message->adcValue = sample;
    message->sw1State = switch1State;
    message->sw2State = switch2State;
    
    //Write to queue
    osStatus stat = mail_box.put(message);    //Note we are sending the "pointer"
    
    //Check if succesful
    if (stat == osErrorResource) {
        redLED = 1; 
        printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat);   
        mail_box.free(message);
        return;
    }
    
    
}