Thread: loading struct from UART received data

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The tricky part is of coruse that you can't (or shouldn't) block inside the ISR, so you may find that the right thing to do is either to ENSURE that you never update stuff that ReadData() uses [e.g. readPtr] inside the ISR, or have some sort of "make this ISR happen at a later stage" type mechanism.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Embedded in C...
    Join Date
    Sep 2008
    Location
    Basingstoke, Hampshire
    Posts
    83
    Quote Originally Posted by Salem View Post
    > What do you mean by 'get a lock' and 'release lock'?
    It means a mechanism to ensure that only ONE of the functions updates the data.
    In readData(), if you did say readptr++ and at the wrong moment the isr() was called, then there's a good chance that the readptr++ would produce the wrong result.

    How you do this depends widely on your OS, for example
    http://www.rt.com/man/semget.2.html

    Do you have an OS on your embedded platform?
    That makes sense, its the same as mutual exclusive. I don't have an OS on this processor - its an STM32 ARM core, so just using standard C with the inbuilt libraries to do peripheral control.

    Off to do some more research on semaphores in C then...

    --dave

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    matsp has a good point, making sure the ISR doesn't block is essential.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Salem View Post
    matsp has a good point, making sure the ISR doesn't block is essential.
    Yes. I know this from experience - blocking in interrupts is a good way to stop the entire system from working (at least until the interrupt unblocks, and if it's waiting for a lower priority task, then we could be waiting a good while, like until the next power-cut or some such).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Embedded in C...
    Join Date
    Sep 2008
    Location
    Basingstoke, Hampshire
    Posts
    83
    Thanks for all your help chaps, the solution suggested by salem worked and made sense to me

    --dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  3. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Loading a struct with data from a file
    By TankCDR in forum C Programming
    Replies: 1
    Last Post: 10-28-2001, 08:58 AM