ts-7000
[Top] [All Lists]

Re: [ts-7000] wanted: a C/BASH coded example of a program woken up by an

To: <>
Subject: Re: [ts-7000] wanted: a C/BASH coded example of a program woken up by an input momentary switch.
From: " [ts-7000]" <>
Date: 19 Jun 2014 08:40:23 -0700


wow!  that looks really cool.  sorry to take so long to get back, I must of missed this message.    where can I get some documentation on waitqueue_active, atomic_set, wake_up_interruptible, poll_wait, etc...    I have never heard of these functions, what library, .h file is it in?   

What does ISR stand for?  I've never worked with wait queues, ISR's or interrupts other than some posix multi-threaded code where I left an io-handler thread waiting for an intterupt on a ethernet message.   


Your snippet implies as if I have two daemon processes running, the "ISR driver" and the polling function.   I'm afraid I'm only familiar with POSIX multi-threaded C code that I think is closest to what you are suggesting here.   

AFA the interrupts that are available, I'm working with a TS-7500, and I can use any of the 8 gpio pins that are broken out on the TS-752 enclosure box, where do I get the documentation for "the sord of interrupts are available for that [port?]  i/o pin?

TIA, 

Jleslie48







---In <> wrote :

It's fairly trivial. On the driver side you want to use a wait queue that gets woken up in response to an interrupt from the ioport, you will have to look up what sort of interrupts are available for that port.    
Here's a sketch:

in the ISR:
/* Interrupt has occured */
        rc=waitqueue_active(&wait_q);
        if (rc) {
                   atomic_set(&irq_occured,1);
                   wake_up_interruptible(&wait_q);
        }

in the POLLING function:

_poll(struct file *filp, poll_table *wait) {

    int mask = 0;
   
    /* Did irq occur? */
    if (atomic_read(&irq_occured)) {
        mask = POLLIN | POLLRDNORM;
        atomic_set(&irq_occured,0);
    } else {
        /* otherwise we go to sleep */
        poll_wait(filp, &wait_q, wait);
    }
     /* Returning a 0 will cause the select()/poll() to block */
    return mask;    
}



On Wednesday, June 11, 2014 12:40:37 PM, "Jonathan Leslie [ts-7000]" <> wrote:


 
OK, that sounds great!  how do I do that?  Any examples around?



From: " [ts-7000]" <>
To: "" <>
Sent: Wednesday, June 11, 2014 12:34 PM
Subject: Re: [ts-7000] wanted: a C/BASH coded example of a program woken up by an input momentary switch.

 
You need write a driver that services the dio port interrupt. Then your user program sleeps on the driver via the polling mechanism i.e. by select() and is woken up when a interrupt occurs. 

Mike McDonald
On Wednesday, June 11, 2014 12:03:31 PM, " [ts-7000]" <> wrote:


 
OK, so I have DIO.C working perfectly (code below) and I have a Momentary switch hooked up to DIO_40, and an LED hooked up to DIO_33   and everything works perfectly.   I can turn on and off the LED, with a "./dio set "  command, and when I look at pin 40 with the "./dio get 40" command it properly answers with a 0 or 1 depending on the state of the push button.   

What I want is a program that is interrupt based that uses little to no CPU time but wakes  up when the DIO_40 changes states,  I know I can put the "getdiopin(pin);" statement in a while loop and have it break out when the state changes, but that burns a lot of CPU time, or if "sleep" is utilized, then there will be a delay to respond.    

Is there any way to make a [threaded?] program where you have [a child thread that is just] waiting for the change of state of pin 40, not looping, and checking,  When I write ethernet drivers, I have a  multithreaded process where a child thread is waiting on an inbound message and it just sits there doing nothing, buring no CPU, until it gets woken up by traffic on the IP port.   I want something similar for an input button.   Any Ideas?


/*******************************************************************************
* Program:
*    Get DIO (dio.c)
*    Technologic Systems TS-7500 with TS-752 Development Board
*
* Summary:
*   This program will accept any pin number between 5 and 40 and attempt to get
* or set those pins in a c program rather than scripted.  You will need the
* TS-7500 and TS-752 development board. Although this program will enable the
* use of said pins, it will primarily enable the use of the 8 Inputs, 3 Outputs,
* and Relays on the TS-752.  Keep in mind that if a GND or PWR pin is read (or
* something else unlogical, we don't necessarily care about the output because
* it could be simply "junk".
*   Notice careful semaphore usage (sbuslock, sbusunlock) within main.
*
* Usage:
*   ./dio <get|set> <pin#> <set_value (0|1|2)>
*
* 0 - GND
* 1 - 3.3V
* 2 - Z (High Impedance)
*
* Examples:
*   To read an input pin (such as 1 through 8 on the TS-752):
*      ts7500:~/sbus# ./dio get 40
*      Result of getdiopin(38) is: 1
*
*   To set an output pin (such as 1 through 3 or relays on the TS-752):
*      ts7500:~/sbus# ./dio set 33 0
*      Pin#33 has been set to 0   [You may verify with DVM]
*
* Compile with:
*   gcc -mcpu=arm9 dio.c sbus.c -o dio


Date Whom Notes.
100112 JL Lets give it a try.



*******************************************************************************/
#include "sbus.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>

#define DIO_Z 2

/*******************************************************************************
* Main: accept input from the command line and act accordingly.
*******************************************************************************/
int main(int argc, char **argv)
{
   int pin;
   int val;
   int returnedValue;

   // Check for invalid command line arguments
   if ((argc > 4) | (argc < 3))
   {
       printf("Usage: %s <get|set> <pin#> <set_value (0|1|2)>\n", argv[0]);
       return 1;
   }

   // We only want to get val if there are more than 3 command line arguments
   if (argc == 3)
      pin = strtoul(argv[2], NULL, 0);
   else
   {
      pin = strtoul(argv[2], NULL, 0);
      val = strtoul(argv[3], NULL, 0);
   }

   // If anything other than pins 5 through 40, fail program
   assert(pin <= 40 && pin >= 5);

   // Parse through the command line arguments, check for valid inputs, and exec
   if (!(strcmp(argv[1], "get")) && (argc == 3))
   {
      sbuslock();
      returnedValue = getdiopin(pin);
      sbusunlock();

      printf("pin#%d = %d \n", pin, returnedValue);
   }
   else if(!(strcmp(argv[1], "set")) && (argc == 4) && (val <= 2))
   {
      sbuslock();
      setdiopin(pin, val);
      sbusunlock();

      printf("pin#%d set to %d\n", pin, val);
   }
   else
   {
      printf("Usage: %s <get|set> <pin#> <set_value (0|1|2)>\n", argv[0]);
      return 1;
   }
   return 0;
}
// EOF









__._,_.___

Posted by:



__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU