#include <stdio.h>
#include <hw/inout.h> /* for in*() a/nd out*() functions /
#include <sys/neutrino.h> / for ThreadCtl() */
#include <iostream.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/mman.h>
#include <inttypes.h> //need for uintptr_t type
#include <stdint.h>
using namespace std;
//Hardware specifications
#define COM1 0x3f8
#define IRQ4 4
#define DivisorLow 0x02
#define DivisorHi 0x00
//#define IIR_MASK 0x07
//#define IIR_MSR 0x00
//#define IIR_THE 0x02
//#define IIR_RX 0x04
//#define IIR_LSR 0x06
struct sigevent event;
void* int_thread (void *arg);
const struct sigevent * isr_handler (void *arg, int id);
int intId;
char buffer[1025];
int bufferin = 0;
/* Gain access to device registers */
uintptr_t reg0Id=mmap_device_io (0x01, COM1);
uintptr_t reg1Id=mmap_device_io (0x01, COM1+1);
uintptr_t reg2Id=mmap_device_io (0x01, COM1+2);
uintptr_t reg3Id=mmap_device_io (0x01, COM1+3);
uintptr_t reg4Id=mmap_device_io (0x01, COM1+4);
uintptr_t reg5Id=mmap_device_io (0x01, COM1+5);
uintptr_t reg6Id=mmap_device_io (0x01, COM1+6);
uintptr_t reg7Id=mmap_device_io (0x01, COM1+7);
//IRQ Register??
uintptr_t regIRQ=mmap_device_io (0x01, 0x21);
int main ()
{
// char value;
// perform initializations, etc.
event.sigev_notify = SIGEV_INTR;
// start up a thread that is dedicated to interrupt processing
pthread_create (NULL, NULL, int_thread, NULL);
cout << “I am in main”<<endl;
sleep(500);
}
// this thread is dedicated to handling and managing interrupts
void* int_thread (void *arg)
{
// enable I/O privilege
cout <<“ThreadCTL”<<ThreadCtl (_NTO_TCTL_IO, NULL)<<endl;
//-------initialize the 8250chip, etc.-----------------------
//First disable interrupt-----
out8( (COM1+1), 0x00 );
//Set the DLAB to 1
out8( (COM1+3), 0x80 );
//-------Set baud rate---------
//----------At 57600-----------
out8( (COM1), DivisorLow );
out8( (COM1+1), DivisorHi );
//-------Set Bit Pattern-------
//—8-N-1, No Parity----------
out8( (COM1+3), 0x03 );
//Set FIFO(First In/First Out)-
out8( (COM1+2), 0xc7 );
//Turn on DTR, RTS, and AUX Out2
out8( (COM1+4), 0x0b);
//Set IRQ??
// out8( regIRQ, (in8(0x21) & IRQ4) );
//Enable interrupts on the serial port
//MSR, THE, RX, LSR Interrupts
out8( (COM1+1), 0x0f );
// attach the ISR to IRQ 4
intId=InterruptAttach (IRQ4, isr_handler, NULL, 0, 0);
cout <<“intId”<< intId<<endl;
cout <<“IntUnMask”<< InterruptUnmask (IRQ4, intId)<<endl;
// now service the hardware when the ISR says to
while (1)
{
InterruptWait (NULL, NULL);
// InterruptUnmask (IRQ4, intId);
cout << “received interrupt” << endl;
}
}
// this is the ISR
const struct sigevent *
isr_handler (void *arg, int id)
{
return (&event);
}
When I said “freed” I meant I have used the mmap_device_io call to gain access to the registers.