rtc not showing output.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
aki522
Posts: 5
Joined: Sun Apr 01, 2012 12:34 am

rtc not showing output.

Post by aki522 »

i want to print out to the screen but im getting page fault when i use the following test code to open read and write to the screen. Please suggest what I am doing wrong.

Code: Select all

        int a;
	const uint8_t* filename_garbage;
	int buf[3];
        buf[0]=2;
        buf[1]=5;
        buf[2]=6;
	a = open_rtc(filename_garbage, 0, 0);
	a = read_rtc(buf1, 1, 0);
	a = write_rtc(buf, 4, 0);
	a = read_rtc(buf1, 1, 0);
here is the code for the rtc i had.

Code: Select all

volatile int flag = 0;
int rtc_read_map[16] = {0, 256, 128, 8192, 4096, 2048, 1024, 512, 
                            256, 128, 64, 32, 16, 8, 4, 2};
volatile int mark = 0;
void rtc_init(void)
{	
	enable_irq(8);
}
/* rtc_handler*/
void rtc_handle_interrupt(long exception)
{
	int flags;
    disable_irq(8);
        cli_and_save(flags);
                outb(0x0C, 0x70);
    			inb(0x71);  //read control register C
                flag = 1;          
            send_eoi(8);
        restore_flags(flags);
    enable_irq(8);
}

/* open_rtc
 * Parameters:  const uint8_t* filename_garbage - garbage for syscall linkage
 *                const int garbage - garbage for syscall linkage
 * Return Value: 0 after initialization of the RTC
 * Side Effects:  Enables Perodic Interrupts from the RTC
 */
int32_t open_rtc(const uint8_t* filename_garbage, const int garbage,
             int32_t position)
{
    enable_irq(8); 
    //set up control register B
    outb(0x0B, 0x70);
    outb(0xC0, 0x71);  //allows for periodic interrupts
    outb(0x0A, 0x70);
    outb(0x0F, 0x71); //set RTC to 2Hz Interrupts
    return 0;  //device driver, we return 0 for the inode
}

/* read_rtc
 * Parameters:  void* buf - holds the read value
 *                nbytes - number of bytes of buffer (always 1 for this)
 * Return Value - 0 for sucess, -1 for failure
 * Side Effects - places values of rate selector bits into buf
 */
int32_t read_rtc(void* buf, int32_t nbytes, int32_t position)
{
    sti();
    disable_irq(0);
    uint8_t temp;
    int read_val;
    while(!flag){}
    
    outb(0x0A, 0x70);
    temp = inb(0x71);  //get register A from RTC
    temp = temp & 0x0F;         //mask bits we don't care about
    read_val = rtc_read_map[temp];
    if(nbytes>0)
        memcpy(buf, &read_val, nbytes);
    flag = 0;      
	printf("reading freq:%d",read_val);
	return 0;
}

/* write_rtc
 * Parameters:  void* buf - holds the value we are writing
 *                nbytes - number of bytes of buffer
 * Return Value - writes value of buf into rate selector bits
 */
int32_t write_rtc(const void* buf, int32_t nbytes, int32_t position)
{
    uint8_t write_val;
    int buf_val;
    buf_val = *((int *)buf);
    if(nbytes!=4)
    {
        printf("INVALID NUMBER OF BYTES PASSED!\n");
        sti();
        return -1;
    }
    switch(buf_val)
    {
        case 2:
            write_val = 0x0F;
            break;
        case 4:
            write_val = 0x0E;
            break;
        case 8:
            write_val = 0x0D;
            break;
        case 16:
            write_val = 0x0C;
            break;
        case 32:
            write_val = 0x0B;
            break;
        case 64:
            write_val = 0x0A;
            break;
        case 128:
            write_val = 0x09;
            break;
        case 256:
            write_val = 0x08;
            break;
        case 512:
            write_val = 0x07;
            break;
        case 1024:
            write_val = 0x06;
            break;
        default:
            printf("INVALID RTC RATE!!!\n");
            sti();
            return -1;
            break;
    }
    outb(0x0A, 0x70);
    outb(write_val, 0x71);//write to the control register
    return 0;
}
User avatar
brain
Member
Member
Posts: 247
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Discord: https://discord.gg/brainbox
GitHub: https://github.com/braindigitalis
Contact:

Re: rtc not showing output.

Post by brain »

There is a lot of code here. have you used a debugger to backtrace and find out what part of the code causes the pf?
Post Reply