main.c

As with all files, rename the file, adding a preceding l (the letter after k and before m)

With only minute remnants of the previous file's contents, I'm posting the entire code for lmain.c



#include <rtl.h>
#include "lincludes.h"

/****************************************************************
* main Function : Must be a module!
* int init_module(void)
*
* By F. Mota 04/27/00
* and b m ledvina 10/21/2001
****************************************************************/

int __IO;
int __IRQ;
MODULE_PARM(__IO,"i"); /* register parameter as an int*/
MODULE_PARM(__IRQ,"i"); /* register parameter as an int */

int init_module(void) {
struct sched_param p;
int i,fnumber;
for(i=0;i<9;i++){
rtf_destroy(i);
fnumber = rtf_create(i, 4000);
if (fnumber)
rtl_printf("RTL measurement test fail. fifo_status=%d\n",fnumber);
}

if(__IRQ < 0 || __IRQ > 15)
__IRQ = 11;
if(__IO < 0x0200 || __IO > 0x03E0)
__IO = 0x300;

rtl_printf("IRQ# %d\n",__IRQ);
rtl_printf("IO %d",__IO);
fd_fifo[1] = open("/dev/rtf1", O_NONBLOCK);
if (fd_fifo[1] < 0){
rtl_printf("/dev/rtf2 open returned %d\n", fd_fifo[1]);
}

fd_fifo[2] = open("/dev/rtf2", O_NONBLOCK);
if (fd_fifo[2] < 0){
rtl_printf("/dev/rtf2 open returned %d\n", fd_fifo[2]);
}
fd_fifo[3] = open("/dev/rtf3", O_NONBLOCK);
if (fd_fifo[3] < 0){
rtl_printf("/dev/rtf3 open returned %d\n", fd_fifo[3]);
}
fd_fifo[4] = open("/dev/rtf4", O_NONBLOCK);
if (fd_fifo[4] < 0){
rtl_printf("/dev/rtf2 open returned %d\n", fd_fifo[4]);
}
fd_fifo[5] = open("/dev/rtf5", O_NONBLOCK);
if (fd_fifo[5] < 0){
rtl_printf("/dev/rtf5 open returned %d\n", fd_fifo[5]);
}
fd_fifo[6] = open("/dev/rtf6", O_NONBLOCK);
if (fd_fifo[6] < 0){
rtl_printf("/dev/rtf6 open returned %d\n", fd_fifo[6]);
}
ConfigureInterrupt(__IO,__IRQ);
TestingInterface = TRUE;
HardwareTest();
TestingInterface = FALSE;
GPIntCtr = 0;
InitialiseTasks();
InitialiseGP2021();
pthread_create (&thmain, NULL ,GpsBldr2Linux, (void *) 6);
p . sched_priority = 6;
pthread_setschedparam (thmain, SCHED_FIFO, &p);
pthread_wakeup_np(thmain);

//create handler to check input commands
rtf_create_handler(0, &CheckCommandBuffer);

return 0;
}

/**************************************************************************************/
void cleanup_module(void) {

int i;
pthread_delete_np (thTakeMeas);
pthread_delete_np(thNav);
pthread_delete_np (thDisplay);
pthread_delete_np(thProcSbf);
pthread_delete_np(thAlloc);
pthread_delete_np(thmain);
pthread_mutex_destroy (&PROTECT);
for(i=0;i<9;i++){
close(fd_fifo[i]);
rtf_destroy(i);
}
rtl_free_irq(GPINT);
rtl_printf("\n%lu TICs were counted.\n\n",TIC);
return; }
/*******************************************************************************
*
* These functions are necessary because the RTL version 2.2 has no support for
* recursive MUTEXES.
*
* inline int rec_mutex_lock(int thid), inline int rec_mutex_unlock(int thid)
*
* Input: int thid - identifies the calling thread
* Return Value: value returned by pthread_mutex_lock, otherwise zero.


******************************************************************************/
inline int rec_mutex_lock(int thid) {
unsigned long ret = 0;
if(locked[thid-1] == 0)
ret = pthread_mutex_lock(&PROTECT);
locked[thid-1]++;
return ret;
}
inline int rec_mutex_unlock(int thid) {
unsigned long ret = 0;
if(locked[thid-1] == 1)
ret = pthread_mutex_unlock(&PROTECT);
locked[thid-1]--;
return ret;
}

/****************************************************************************
* Function: void *GpsBldr2Linux(void *arg)
*
* Revision: 6.05
*
* Last Update: 11/05/00 by Mota, From GPSArchitect()
* 20/06/00 by Mota - Changed to be a thread.
*
* Initialize the GPS Architect hardware and software, then initiate
* multitasking and run the program until it is terminated.
*
* Input: arg - Thread Id.
*
* Output: None.
*
* Return Value: None.
****************************************************************************/
void *GpsBldr2Linux(void *arg) {

int sv;
pthread_setfp_np (pthread_self(), 1);
pthread_wait_np();

SetUpGlobals();
SetClockModel();
for(sv=1;sv<=MAXSATELLITES;sv++)
SVPredicts(sv, (int)arg); /* Initialise the Command buffer pointer.
- We don't need it*/
missa = missm = 0;
/* Initialise the "TIC_At_Last_SF_Decode" variable, to allow receiver
to search for satellites for maximum period "SF_DECODE_TIME_LIMIT"
defined in ALLOCATE.C */

CurrentTIC(&TIC_At_Last_SF_Decode);

return 0;
}