掌機 - Miyoo A30 - C/C++ - Alarm



main.c

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <time.h>
 
int main(int argc, char* argv[])
{
    int fd = -1;
    uint8_t *mem = NULL;
    volatile uint32_t *p = NULL;
    
    fd = open("/dev/mem", O_RDWR);
    mem = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x1f00000);

    // after 30 seconds
    p = (uint32_t *)(&mem[0x20]);
    *p = 30;

    // enable alarm
    p = (uint32_t *)(&mem[0x28]);
    *p = 1;

    // enable interrupt
    p = (uint32_t *)(&mem[0x2c]);
    *p = 1;

    munmap(mem, 4096);
    close(fd);
    return 0;
}