AIAANortheastern / karman-avionics

The avionics system for the Northeastern University AIAA Project Karman rocket
1 stars 0 forks source link

Branch SPI_Implementation spi service is flawed #3

Closed ADKaster closed 7 years ago

ADKaster commented 7 years ago

spi_master_push_request should be renamed spi_master_enqueue

spi_master_pop_request should be renamed spi_master_dequeue

spi_master_pop_request will never change which index is front.

This is the old state of pop_request

Bool spi_master_pop_request(spi_master_t *spi_interface)
{
    Bool popStatus = true;
    uint8_t oldFront = spi_interface->front;
    uint8_t newFront = (oldFront == SPI_MASTER_QUEUE_DEPTH) ? 0 : oldFront;
    /* newFront will never change, and always be 0 */

    if(spi_interface->requestQueue[oldFront].valid == false)
    {
        popStatus = false;
    }
    else
    {
        spi_interface->requestQueue[oldFront].valid = false;
        spi_interface->front = newFront;
    }

    return popStatus;
}

It should look something like this:

Bool spi_master_dequeue(spi_master_t *spi_interface)
{
    Bool popStatus = true;
    uint8_t oldFront = spi_interface->front;
    uint8_t newFront = (spi_interface->front == spi_interface->back) ? oldFront : oldFront + 1;

    if(newFront >= SPI_MASTER_QUEUE_DEPTH)
    {
         newFront = 0;
    }

    if(spi_interface->requestQueue[oldFront].valid == false)
    {
        popStatus = false;
    }
    else
    {
        spi_interface->requestQueue[oldFront].valid = false;
        spi_interface->front = newFront;
    }

    return popStatus;
}

Also waaay too many files were committed on this branch. The extra karman-avionics folder needs to go away asap