ts-7000
[Top] [All Lists]

Re: [ts-7000] A Simple Deamon

To:
Subject: Re: [ts-7000] A Simple Deamon
From: "Alvaro Aguirre" <>
Date: Tue, 19 Sep 2006 12:54:50 -0400
Do you solve your problem?
I don't really read very carefully your program but if you want to launch it as a daemon there are certain procedures you must follow.

The daemon program:
-stdin, stdout and stderr must be redirected to /dev/null, if not great problems you will have with your printf. <man daemon>
-you can ( a must for the script that launch the program) write the PID of the process in /var/run/yourprogram.pid <man getpid>

The script:
-modify the /etc/init.d/skeleton to your needs and rename it.
-after create the script you must run update-rc.d to create the simlinks <man update-rc.d> (use start on 2 3 4 5 and stop at S 0 1 6)

I'm familiar with daemons... any questions please write it here

Cheers,
Alvaro


On 9/15/06, Art <> wrote:

I have a program that sould serve as a simple deamon.
when I run it at the command line it runs just fine. I do have to
run it as root user or super user.

The program simple accesses the DIO pins and cycles thru eight
addresses. I am planning on using this in communcating with eight
diffrent spi devices.

The problem I am having is when I run this in the start up scripts.
I am thinking that the problem is access rights and I'm getting the
same error as if I were running it as a user. how do I set it up so
it runs with the correct rights? I have tried using the su command.
and now I am using start-stop-daemon. nothing in the script seems to
work. I have echo lines before and after the command so I know it is
getting ran. I also get the message from the parent process telling
me that it was successfull. But I don't try to access the memory
until I am running the child process.

My Code is below.

// filename button.c
// connect a button to DIO pin 1 and ground
// blinks green and red led on the ts-7200 when button is pressed
//
// compile arm-linux-gcc -o button button.c
//

#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>

// Required by for routine
#include <sys/types.h>
#include <unistd.h>

volatile unsigned int *SSPCR0, *SSPCR1, *SSPDR, *SSPSR, *SSPCPSR,
*SSPIIR, *SSPICR;
volatile unsigned int *PEDR, *PEDDR, *PBDR, *PBDDR, *GPIOBDB;

void SPI_SETUP(void)
{
unsigned char *start2;
int fd = open("/dev/mem", O_RDWR);
start2 = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0x808A0000);
// SPI registers
SSPCR0 = (unsigned int *)(start2 + 0); // Control register 0
SSPCR1 = (unsigned int *)(start2 + 4); // Control register 1
SSPDR = (unsigned int *)(start2 + 8); // Data Recieve / Data
Transmit
SSPSR = (unsigned int *)(start2 + 0xc); // SPI Status Register
SSPCPSR = (unsigned int *)(start2 + 0x10); // SPI Clock Prescale
register
SSPIIR = (unsigned int *)(start2 + 0x14); // Int ID register
SSPICR = (unsigned int *)(start2 + 0x14); // Int Clr register;
close(fd);
*PBDR = *PBDR&0x1; // Send Low to Receiving device
*SSPCR1 = 0x10; //set SSE
*SSPCPSR = 4;
*SSPCR0 = 0x0107; // SCR = 1; DSS = 8 bit;
//*SSPCPSR = 0xFE; // Slow way down
//*SSPCR0 = 0xff07; // SCR = 254; DSS = 8 bit;
*SSPCR1 = 0x0; // Master nothing special CLEAR SSE
*SSPCR1 = 0x10; //set SSE
}

void DIO_SETUP(void)
{
unsigned char *start;
int fd = open("/dev/mem", O_RDWR);
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0x80840000);
// DIO registers
PBDR = (unsigned int *)(start + 0x04); // port b
PBDDR = (unsigned int *)(start + 0x14); // port b direction
register
PEDR = (unsigned int *)(start + 0x20); // port e data
PEDDR = (unsigned int *)(start + 0x24); // port e direction
register
GPIOBDB = (unsigned int *)(start + 0xC4); // debounce on port b

*PBDDR = 0xff; // upper nibble output,
lower nibble input
*PEDDR = 0xff; // all output (just 2
bits)
*GPIOBDB = 0x01; // enable debounce on
bit 0
close(fd);
}

#define SPI_SEND_BUFF_FULL (*SSPSR & 0x2) == 0
#define SPI_SEND_BUFF_EMPTY (*SSPSR & 0x1) == 1
#define SPI_READ_BUFF_FULL (*SSPSR & 0x8) == 8
#define SPI_READ_BUFF_EMPTY (*SSPSR & 0x4) == 0
#define SPI_BUSY (*SSPSR & 0x10) == 0x10

unsigned int SPI_ReadSend(unsigned int data)
{
while (SPI_SEND_BUFF_FULL);
*SSPDR = data;
while (SPI_BUSY);
//while (SPI_READ_BUFF_EMPTY);
return *SSPDR; // Send Back data received
}

int main(int argc, char **argv)
{
int liLoop;
pid_t pID = fork();
if (pID == 0)
{
//DIO_SETUP();
//SPI_SETUP();
//for (liLoop = 0; liLoop < 101; liLoop++)
//{
// printf("|%x|",SPI_ReadSend(liLoop));
//}
//while (SPI_READ_BUFF_FULL)
//printf("|%x|",SPI_ReadSend(0));
while (1==1)
for (liLoop = 0; liLoop < 8; liLoop++)
{
//*PBDR = liLoop;
sleep(1);
printf("testing/n");
}
}
else if (pID < 0)
{
printf ("Error In fork\n");
}
else // parent process
{
printf ("Process Begins\n");
}
return 0;
}


__._,_.___


SPONSORED LINKS
Single board computer Hardware Computer running slow
Linux os Single board

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<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