Menu

Arduino IDE 1.8.1 SEM Example will hang

MOP
2017-03-26
2017-03-26
  • MOP

    MOP - 2017-03-26

    Does it support Arduino IDE?
    Or it just supported Atmel Studio and GCC?
    Thanks a lot.

     

    Last edit: MOP 2017-03-26
    • moslevin

      moslevin - 2017-05-29

      Yes, Mark3 does support Arduino IDE -- the Arduino specific .zip release can be imported directly as a library. Note that support at this time is limited to AVR atmega328p and atmega1280/2560-based boards.

       
  • MOP

    MOP - 2017-04-06

    Tesing for some days.
    It's very depended on script coding.

    #include <mark3.h>
    
    unsigned long timer;
    int sta=0;
    /*#if !KERNEL_USE_IDLE_FUNC
    # error "This demo requires KERNEL_USE_IDLE_FUNC"
    #endif*/
    
    extern "C" {
    void __cxa_pure_virtual(void) { }
    }
    
    //---------------------------------------------------------------------------
    // This block declares the thread data for one main application thread.  It
    // defines a thread object, stack (in word-array form), and the entry-point
    // function used by the application thread.
    #define APP1_STACK_SIZE      (300/sizeof(K_WORD))
    static Thread  clApp1Thread;
    static K_WORD  awApp1Stack[APP1_STACK_SIZE];
    static void    App1Main(void *unused_);
    
    //---------------------------------------------------------------------------
    // This block declares the thread data for one main application thread.  It
    // defines a thread object, stack (in word-array form), and the entry-point
    // function used by the application thread.
    #define APP2_STACK_SIZE      (300/sizeof(K_WORD))
    static Thread  clApp2Thread;
    static K_WORD  awApp2Stack[APP2_STACK_SIZE];
    static void    App2Main(void *unused_);
    
    #define APP3_STACK_SIZE      (300/sizeof(K_WORD))
    static Thread  clApp3Thread;
    static K_WORD  awApp3Stack[APP3_STACK_SIZE];
    static void    App3Main(void *unused_);
    
    #define APP4_STACK_SIZE      (300/sizeof(K_WORD))
    static Thread  clApp4Thread;
    static K_WORD  awApp4Stack[APP4_STACK_SIZE];
    static void    App4Main(void *unused_);
    //---------------------------------------------------------------------------
    // This is the semaphore that we'll use to synchronize two threads in this
    // demo application
    static Semaphore   clMySem;
    
    void setup() {
        // put your setup code here, to run once:
        // start serial port at 9600 bps:
        Serial.begin(115200);
        while (!Serial) {
          ; // wait for serial port to connect. Needed for native USB port only
        }  
    
        pinMode(13,OUTPUT);
        Serial.print("Application start!...............\r\n");
    
        // See the annotations in previous labs for details on init.
        Kernel::Init();
        // In this example we create two threads to illustrate the use of a
        // binary semaphore as a synchronization method between two threads.
    
        // Thread 1 is a "consumer" thread -- It waits, blocked on the semaphore
        // until thread 2 is done doing some work.  Once the semaphore is posted,
        // the thread is unblocked, and does some work.
    
        // Thread 2 is thus the "producer" thread -- It does work, and once that
        // work is done, the semaphore is posted to indicate that the other thread
        // can use the producer's work product.
    
        clApp1Thread.Init(  awApp1Stack,  APP1_STACK_SIZE,  1, App1Main,  0);
        clApp2Thread.Init(  awApp2Stack,  APP2_STACK_SIZE,  1, App2Main,  0);
        clApp3Thread.Init(  awApp3Stack,  APP3_STACK_SIZE,  2, App3Main,  0);
        clApp4Thread.Init(  awApp4Stack,  APP4_STACK_SIZE,  1, App4Main,  0);
    
        clApp1Thread.Start();
        clApp2Thread.Start(); 
        clApp3Thread.Start();
        clApp4Thread.Start();
        // Initialize a binary semaphore (maximum value of one, initial value of
        // zero)
    
        clMySem.Init(0,1);
       /// clMySem.Post();
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      Kernel::Start();
    
    }
    
    //---------------------------------------------------------------------------
    void App1Main(void *unused_)
    {
        volatile uint32_t u32Counter = 0;
        while(1)
        {
            u32Counter++;
            // Wait until the semaphore is posted from the other thread
            if (u32Counter == 1000000)
            {
               u32Counter = 0;
               Serial.print("Wait1...");
               Serial.print(millis());
               Serial.print("\r\n");
               clMySem.Pend();
    
               // Producer thread has finished doing its work -- do something to
               // consume its output.  Once again - a contrived example, but we
               // can imagine that printing out the message is "consuming" the output
               // from the other thread.
               Serial.print("Triggered!1\r\n");
               Serial.print("Posted1...");
               Serial.print(millis());
               Serial.print("\r\n");
               digitalWrite(13,LOW);
               clMySem.Post();
    
            }
        }
    }
    
    //---------------------------------------------------------------------------
    void App2Main(void *unused_)
    {
        volatile uint32_t u32Counter = 0;
        while(1)
        {
            // Do some work.  Once the work is complete, post the semaphore.  This
            // will cause the other thread to wake up and then take some action.
            // It's a bit contrived, but imagine that the results of this process
            // are necessary to drive the work done by that other thread.
            u32Counter++;
    
            if (u32Counter == 2000000)
            {
                u32Counter = 0;
                Serial.print("Posted2...");
                Serial.print(millis());
                Serial.print("\r\n");   
                digitalWrite(13,LOW);         
                clMySem.Post();
            }      
        }
    }
    
    //---------------------------------------------------------------------------
    void App3Main(void *unused_)
    {
        volatile uint32_t u32Counter = 0;
        while(1)
        {
            u32Counter++;
            // Wait until the semaphore is posted from the other thread
            if (u32Counter == 1000000)
            {
               u32Counter = 0;
    
               Serial.print("Wait3...");
               Serial.print(millis());
               Serial.print("\r\n");
               clMySem.Pend();
    
               // Producer thread has finished doing its work -- do something to
               // consume its output.  Once again - a contrived example, but we
               // can imagine that printing out the message is "consuming" the output
               // from the other thread.
               Serial.print("Triggered!3\r\n");
               Serial.print("Posted3...");
               Serial.print(millis());
               Serial.print("\r\n");
               digitalWrite(13,HIGH);
               clMySem.Post();   
            }
        }
    }
    
    //---------------------------------------------------------------------------
    void App4Main(void *unused_)
    {
        volatile uint32_t u32Counter = 0;
        while(1)
        {
             u32Counter++;
            // Wait until the semaphore is posted from the other thread
            if (u32Counter == 500000)
            {
               u32Counter = 0;
               Serial.print("Wait4...");
               Serial.print(millis());
               Serial.print("\r\n");
               clMySem.Pend();
    
               // Producer thread has finished doing its work -- do something to
               // consume its output.  Once again - a contrived example, but we
               // can imagine that printing out the message is "consuming" the output
               // from the other thread.
               Serial.print("Triggered!4...");
               Serial.print(millis());
               Serial.print("\r\n");
               digitalWrite(13,HIGH);
            }
        }
    }
    

    if I comment some code,for example,digitalWrite or pinMode. It will loop on setup()
    or hang where NOTTHING happened...
    Older version (R1) have no problem with those issues.

     
    • moslevin

      moslevin - 2017-05-29

      From those symptoms sound like stack overflow. Newer releases such as R5, when compiled with the KERNEL_USE_IDLE_FUNC flag set (as is the case in the default Arduino version of mark3cfg.h) will incur a stack size penalty relative to older releases. Try increasing the stack size, or disabling the KERNEL_USE_IDLE_FUNC feature and adding a dedicated idle thread.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.