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