Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Crash and semaphores

Hi,

when I make three tasks synchronized by semaphores (the tasks do nothing, they only make a Post and then a Pend to pass the control each other), after a number of iterations (this number is ever the same) the program is blocked. If I put a delay after the Pend, the number of iterations grew, but after this number of iterations the program crash. Why??

Thanks

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Italian,

    I know that this post is a bit old, but if you didn't already solved your problem I have a suggest for you. I took a look to your code and I saw the call to OSInit() function: :evil: you don't have to call it because it is already called within alt_main() function that is called before your main()! If you do it, that function initialize os structure, included semaphre, mailbox, queue, etc... If you call it a second time after one in alt_main() you will re-assign all previously initialized semaphore (e.g. uart one, jtag one, etc)!!!

    Ciao
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi Italian,

    I know that this post is a bit old, but if you didn't already solved your problem I have a suggest for you. I took a look to your code and I saw the call to OSInit() function: :evil: you don't have to call it because it is already called within alt_main() function that is called before your main()! If you do it, that function initialize os structure, included semaphre, mailbox, queue, etc... If you call it a second time after one in alt_main() you will re-assign all previously initialized semaphore (e.g. uart one, jtag one, etc)!!!

    Ciao

    --- Quote End ---

    Ho letto solo ora il tuo post, grazie per la risposta. Il problema l'ho risolto cambiando strategia di programmazione: un solo loop infinito senza sistema operativo. Però mi interessa capire il perché del malfunzionamento. Ho chiamato OSInit() perché ho seguito le indicazioni del libro su MicroC/OS-II. Dici che è già chiamata dentro alt_main()? Ma cos'è questa alt_main()?

    Grazie

    Ciao
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    alt_main() is the first C code called from the assembler startup code, it initialises things like stdin and stdout, then calls the uses's main().

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Moreover alt_sys_init() also instantiate and init all device you foreseen in your pld (e.g. ALTERA_AVALON_UART_INSTANCE and ALTERA_AVALON_UART_INIT); this has the consequence that isr function for uart is anyway linked and included in your firmware also if you provide another one written by yourself.

    alt_sys_init() function is in your source file named as alt_sys_init().c and you can find it within syslib folder or bsp folder.

    Ciao