Mario Bambagini / Mbed 2 deprecated car_chassis

Dependencies:   Servo mbed-rtos mbed

main.cpp

Committer:
mariob
Date:
2015-08-02
Revision:
0:ce6055872f4e
Child:
1:79b1ee0f97ef

File content as of revision 0:ce6055872f4e:

#include "mbed.h"
#include "car_config.hpp"
#include "rtos.h"

int init();

int main()
{
    init();

    while(1) {};
}

void init_led();
void init_eeprom();

Thread *th_body;
Thread *th_can;

void thread_body(void const *args);
void thread_can(void const *args);

void init_threads ()
{
    th_body = new Thread(thread_body);
    th_can = new Thread(thread_can);
}
void init_body();

int init ()
{

    init_body();
    
    printf("INIT LED\r\n");
    init_led();
    
    printf("INIT EEPROM\r\n");
//    init_eeprom();

    printf("INIT CAN\r\n");
    init_can();

    
    printf("INIT THREAD\r\n");
    init_threads();



    return true;
}


/****************** EEPROM ******************/

eeprom_t eeprom(p7, p5, p6, p9, PAGENUMBER, PAGESIZE);

t_eeprom_data eeprom_data[] = {
    //SIZE,   ADDR
    {    2,      0}, //SOFTWARE VERSION
    {    2,      2}, //DATA VERSION
    {    4,      4}, //NUMBER OF STARTS
    {    4,     20}, //T_MISSING
    {    2,     22}, //MIN PWM ON
    {    2,     24}, //MAX PWM ON
    {    4,     40}, //ENGINE_LAST_MISSING
    {    4,     44}  //BODY_LAST_MISSING
};

void init_eeprom ()
{
    eeprom.init(eeprom_data, sizeof(eeprom_data)/sizeof(t_eeprom_data));

    uint16 sw = 0;
    uint16 dd = 0;
    uint32 num = 0;
    if ((eeprom.read(EEPROM_DATA_SW_VERS, (uint8*)(&sw)) != 2) ||
        (eeprom.read(EEPROM_DATA_DD_VERS, (uint8*)(&dd)) != 2) ||
        (sw != SW_VERSION) || (dd != DD_VERSION))
    {
        //error
        eeprom.reset();
        sw = SW_VERSION;
        eeprom.write(EEPROM_DATA_SW_VERS, (uint8*)(&sw));
        dd = DD_VERSION;
        eeprom.write(EEPROM_DATA_DD_VERS, (uint8*)(&dd));
    }

    if (eeprom.read(EEPROM_DATA_NSTARTS, (uint8*)(&num)) != 4)
        num = 0xffffffff;
    num++;
    eeprom.write(EEPROM_DATA_NSTARTS, (unsigned char*)(&num));
}