Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded: C Coding for Ctrl-C interrupt in u-boot terminal

I'm a beginner in embedded programming. I'm working on craneboard (ARM Cortex A8). The source code is available at github.

I have created a C code to make an external LED connected via GPIO, to blink. It can be executed in the u-boot console as a command. Currently,

I can't stop the blinking of LED by Ctrl-C.
Where does the coding for Ctrl-C interrupt reside?

ret=set_mmc_mux();
if(ret<0)
    printf("\n\nLED failed to glow!\n\n");
else{
        if(!omap_request_gpio(lpin))
    {
        omap_set_gpio_direction(lpin,0);

        for(i=1;i<21;i++)
        {
            ctr=0;
            if((i%2)==0)
            {
                num=num-1;
                omap_set_gpio_dataout(lpin,num);
            }
            else
            {
                num=num+1;
                omap_set_gpio_dataout(lpin,num);
            }

                    udelay(3000000);
             }

        }
}

Kindly guide me.

like image 559
Gomu Avatar asked Feb 27 '13 05:02

Gomu


Video Answer


2 Answers

Try the uboot ctrlc function:

if(ctrlc())
    return 1; // or whatever else you want to do
like image 184
nneonneo Avatar answered Sep 28 '22 03:09

nneonneo


You are working at a low level, so the methods you need to use are also low-level:

  • Check the UART "data-available" flag within your loop - this is very hardware dependent, but usually involves reading a register, masking some bits off and seeing if the right bit is set.
  • if data is available, check to see if it is a CTRL-C (0x03) character, exit if so, discard if not

Having now seen nneonneo's answer, I assume that's what the ctrlc() function does...

like image 45
Martin Thompson Avatar answered Sep 28 '22 03:09

Martin Thompson