aboutsummaryrefslogtreecommitdiff
path: root/write-stm-device/example.c
blob: dd58b0edf398c80457084468f7d422945af4f85c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include "stm_user_api.h"

extern struct stm_dev g_stm_dev;

void main()
{
	unsigned int chan_start = 0;
        unsigned int width = PAGE_SIZE / BYTES_PER_CHANNEL;
	unsigned int wrbytes = sizeof(unsigned int) * TEST_DATA_SIZE;
	unsigned int real_wrbytes;
	unsigned int trace_data[TEST_DATA_SIZE] = {0x5555aaaa, 0xaaaa5555, 0x66666666, 0x99999999};

	if (request_stm_resource(&g_stm_dev, chan_start, width))
		return;

	/* 
	 * You can use any channel between [g_stm_dev.policy->channel ...
	 * (g_stm_dev.policy->channel + g_stm_dev.policy->width)]
	 */
	real_wrbytes = stm_char_write(g_stm_dev.fd, (char *)trace_data, wrbytes);
	if (real_wrbytes != wrbytes)
		printf("write %d bytes and left % bytes data\n", real_wrbytes, wrbytes - real_wrbytes);
	
	printf("Success to write %d bytes\n", real_wrbytes);

	release_stm_resource(&g_stm_dev);
}