Пример #1
0
static void MOTtask(void *pvParameters) {
    int commsStatsCount = commStatsSecs;
    int initReply = 0;
    bool initialized = false;
    
    //start subsystem tasks
    initReply += SysLogInit();
    initReply += PubSubInit();
    initReply += NotificationsInit();
    initReply += UARTBrokerInit();
    initReply += PidInit();      //Controls the motor PWM
    initReply += EncoderInit();  //Measures motor speed
    //initReply += AmpsInit();   //Measures motor current

    while ((motQueue = psNewPubSubQueue(MOT_TASK_QUEUE_LENGTH)) == NULL) {
        SetCondition(MOT_INIT_ERROR);
        LogError( "Motor Task Q");
        initReply = -1;
    }
    
    if (initReply < 0) {
        SetCondition(MOT_INIT_ERROR);
        DebugPrint("MOT Init Error");
        
        while (1) {
            vTaskDelay(100);
            PORTToggleBits(USER_LED_IOPORT, USER_LED_BIT);
        }
    }
    
    CancelCondition(MOT_INIT_ERROR);
    CancelCondition(MOTORS_INHIBIT);
    CancelCondition(MOTORS_BUSY);
    CancelCondition(MOT_ANALOG_ERROR);
    CancelCondition(MOTORS_ERRORS);
    CancelCondition(MOT_MCP_COMMS_ERRORS);
    CancelCondition(MOT_MCP_COMMS_CONGESTION);

    {
        psMessage_t msg;
        psInitPublish(msg, SS_ONLINE);
        strcpy(msg.responsePayload.subsystem, "MOT");
        msg.responsePayload.flags = RESPONSE_FIRST_TIME;
        psSendMessage(msg);
    }
    
    DebugPrint("MOT Up");

    for (;;) {
        

        //wait for a message
        if (xQueueReceive(motQueue, &motRxMsg, portMAX_DELAY) == pdTRUE) {

            switch (motRxMsg.header.messageType) {
                case TICK_1S:
                    powerState = motRxMsg.tickPayload.systemPowerState;

                    if (--commsStatsCount <= 0) {
                        commsStatsCount = commStatsSecs;
                        if (commStats) {
                            UARTSendStats();
                        } else {
                            UARTResetStats();
                        }
                    }
                    break;
                case CONFIG:
                    if (motRxMsg.configPayload.responder == MOTOR_SUBSYSTEM) {
                        DebugPrint("Config message received");
                        int requestor = motRxMsg.configPayload.requestor;

                       configCount = 0;
#define optionmacro(name, var, minV, maxV, def) SendOptionConfig(name, &var, minV, maxV, requestor);
#include "Options.h"
#undef optionmacro

#define settingmacro(name, var, minV, maxV, def) SendSettingConfig(name, &var, minV, maxV, requestor);
#include "Settings.h"
#undef settingmacro
                        //report Config done
                        psInitPublish(motRxMsg, CONFIG_DONE);
                        motRxMsg.configPayload.requestor = requestor;
                        motRxMsg.configPayload.responder = MOTOR_SUBSYSTEM;
                        motRxMsg.configPayload.count = configCount;
                        psSendMessage(motRxMsg);

                        DebugPrint("Config sent");
                    }
                    break;
                case SET_OPTION: //option change
                    DebugPrint("New Option %s = %i", motRxMsg.optionPayload.name, motRxMsg.optionPayload.value);

#define optionmacro(n, var, minV, maxV, def) SetOption(&motRxMsg, n, &var, minV, maxV);
#include "Options.h"
#undef optionmacro
                    break;
                case NEW_SETTING: //setting change
                    DebugPrint("New Setting %s = %f", motRxMsg.settingPayload.name, motRxMsg.settingPayload.value);

#define settingmacro(n, var, minV, maxV, def) NewSetting(&motRxMsg, n, &var, minV, maxV);
#include "Settings.h"
#undef settingmacro
                    break;
                case PING_MSG:
                {
                    psMessage_t msg2;

                    DebugPrint("Ping Msg");

//                    PORTToggleBits(USER_LED_IOPORT, USER_LED_BIT);

                    psInitPublish(msg2, PING_RESPONSE)
                            
                    strncpy(msg2.responsePayload.subsystem, "MOT", 3);
                    msg2.responsePayload.flags = (initialized ? 0 : RESPONSE_FIRST_TIME);  
                    msg2.responsePayload.requestor = motRxMsg.requestPayload.requestor;
                  
                    psSendMessage(msg2);
                }

                    break;
                case GEN_STATS:
                    DebugPrint("Send Stats\n");
                    GenerateRunTimeTaskStats();
                    GenerateRunTimeSystemStats();
                    break;
                default:
                    break;
            }
        }
    }
}
Пример #2
0
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
    DEBUGDELAY* pDelay;
#endif
    // Board hardware initialization.
    SysBoardInit();

    // STEP 1
    // mTouch library initialization.
    MTouchInit();

    // STEP 2
    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
    // PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)


    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // Debug log initialization (allows streaming data to PC GUI). PC GUI helps to
    // choose right values for sensors' oversampling factors and thresholds.
    SysLogInit();

    // MTouchDebugDelay(sensorNumber) function calculates CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set adjusted CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);
    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
#endif

    // STEP 3
    // Slider initialization. All sliders must be initialized (see MTOUCH_2CHSLIDERS_NUMBER in mTouchConfig.h).
    // For example if slider is connected to sensor 5 and sensor 11
    // MTouchSet2ChSlider(0,           // slider number
    //                    5,           // first sensor number
    //                    11);         // second sensor number

    // slider #0
    MTouchSet2ChSlider(0, 0, 1);

    // STEP 4
    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();


    while(1)
    {

        // STEP 5
        // Decode all controls.
        MTouchDecode();


        // STEP 6
        // Get current value of the slider.

        if(MTouchGet2ChSliderState(0) == CONTROL_PRESSED)
        {
            Led_ALLOff();

            if(MTouchGet2ChSliderValue(0) > 15*1000/16) {
                Led15On();
            }

            else if(MTouchGet2ChSliderValue(0) > 14*1000/16) {
                Led14On();
            }

            else if(MTouchGet2ChSliderValue(0) > 13*1000/16) {
                Led13On();
            }

            else if(MTouchGet2ChSliderValue(0) > 12*1000/16) {
                Led12On();
            }

            else if(MTouchGet2ChSliderValue(0) > 11*1000/16) {
                Led11On();
            }

            else if(MTouchGet2ChSliderValue(0) > 10*1000/16) {
                Led10On();
            }

            else if(MTouchGet2ChSliderValue(0) > 9*1000/16)  {
                Led9On();
            }

            else if(MTouchGet2ChSliderValue(0) > 8*1000/16)  {
                Led8On();
            }

            else if(MTouchGet2ChSliderValue(0) > 7*1000/16)  {
                Led7On();
            }

            else if(MTouchGet2ChSliderValue(0) > 6*1000/16)  {
                Led6On();
            }

            else if(MTouchGet2ChSliderValue(0) > 5*1000/16)  {
                Led5On();
            }

            else if(MTouchGet2ChSliderValue(0) > 4*1000/16)  {
                Led4On();
            }

            else if(MTouchGet2ChSliderValue(0) > 3*1000/16)  {
                Led3On();
            }

            else if(MTouchGet2ChSliderValue(0) > 2*1000/16)  {
                Led2On();
            }

            else if(MTouchGet2ChSliderValue(0) > 1*1000/16)  {
                Led1On();
            }

            else if(MTouchGet2ChSliderValue(0) > 0)          {
                Led0On();
            }
        }

#ifdef MTOUCH_DEBUG
        // Log data from sensors to PC GUI.
        MTouchDebugLogDeltas();

#endif


    }

}
Пример #3
0
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
DEBUGDELAY*   pDelay;
#endif
    // Board hardware initialization.
    SysBoardInit();

    // STEP 1
    // mTouch library initialization.
    MTouchInit();

    // STEP 2
    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
	// PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)

                  
    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1);  
    // sensor #2
    MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1);  
    // sensor #3
    MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1);  
    // sensor #4
    MTouchSetSensor(4, CH4_TRIS, CH4_LAT, CH4_IO_BIT, CH4_AN_NUM, -1, -1, -1);  
    // sensor #5
    MTouchSetSensor(5, CH5_TRIS, CH5_LAT, CH5_IO_BIT, CH5_AN_NUM, -1, -1, -1);  
    // sensor #6
    MTouchSetSensor(6, CH6_TRIS, CH6_LAT, CH6_IO_BIT, CH6_AN_NUM, -1, -1, -1);  
    // sensor #7
    MTouchSetSensor(7, CH7_TRIS, CH7_LAT, CH7_IO_BIT, CH7_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // Debug log initialization (allows streaming data to PC GUI). PC GUI helps to
    // choose right values for sensors' oversampling factors and thresholds.
    SysLogInit();

	// MTouchDebugDelay(sensorNumber) function calculates an optimal CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set the adjusted optimal CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);

    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
    pDelay = MTouchDebugDelay(2);
    MTouchSetChargeDelay(2, pDelay->delay);
    pDelay = MTouchDebugDelay(3);
    MTouchSetChargeDelay(3, pDelay->delay);
    pDelay = MTouchDebugDelay(4);
    MTouchSetChargeDelay(4, pDelay->delay);
    pDelay = MTouchDebugDelay(5);
    MTouchSetChargeDelay(5, pDelay->delay);
    pDelay = MTouchDebugDelay(6);
    MTouchSetChargeDelay(6, pDelay->delay);
    pDelay = MTouchDebugDelay(7);
    MTouchSetChargeDelay(7, pDelay->delay);

#endif

    // STEP 3
    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();


    while(1)
    {

        // STEP 4
        // Get current states of the basic buttons.

        Led_ALLOff();
        // button #0
        if(MTouchGetSensorState(0) == SENSOR_PRESSED) { Led0On(); }
        // button #1
        if(MTouchGetSensorState(1) == SENSOR_PRESSED) { Led1On(); }
        // button #2
        if(MTouchGetSensorState(2) == SENSOR_PRESSED) { Led2On(); }
        // button #3
        if(MTouchGetSensorState(3) == SENSOR_PRESSED) { Led3On(); }
        // button #4
        if(MTouchGetSensorState(4) == SENSOR_PRESSED) { Led4On(); }
        // button #5
        if(MTouchGetSensorState(5) == SENSOR_PRESSED) { Led5On(); }
        // button #6
        if(MTouchGetSensorState(6) == SENSOR_PRESSED) { Led6On(); }
        // button #7
        if(MTouchGetSensorState(7) == SENSOR_PRESSED) { Led7On(); }


        #ifdef MTOUCH_DEBUG
           // Log data from sensors to PC GUI.
           MTouchDebugLogDeltas();

        #endif

     
    }

}