#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <devctl.h>
#include <fcntl.h> 
#include <errno.h>
#include <inttypes.h>
#include "dcmd_f3s.h"


int fd;

int main(int argc, char **argv)
{
	int ret, chip;
	unsigned char lock = 0;
        char *path1 = argv[1];

        fd = open(path1, O_RDWR, S_IRUSR | S_IWUSR);
        if (fd == -1) {
                perror("open failed");
                exit(1);
        }
	if (argc < 3) {
		fprintf(stderr,"usage: statssr /dev/fs0 chip");
		return -1;
	}
	chip = atoi(argv[2]);

	// FIXME: move to targeted chip
	lseek(fd, chip * 0x8000000, SEEK_SET);

	/* lock test */
	ret = devctl(fd, DCMD_F3S_LOCKSSR, NULL, 0, NULL);

	/* lock stat test: get lock stat */
	lock = 0;
	fprintf(stderr, "statssr: check lock stat \n",);
	ret = devctl(fd, DCMD_F3S_SSRSTAT, &lock, 1, NULL);
	fprintf(stderr, "==> lock stat is %d \n", lock);
	close(fd);
	return 0;
}
