aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChunyan Zhang <zhang.chunyan@linaro.org>2016-08-19 20:56:48 +0800
committerChunyan Zhang <zhang.chunyan@linaro.org>2016-08-22 13:52:53 +0800
commit0fac4baa140f501f527d33a81c936a63eea45f63 (patch)
tree58dfde1ccddedb2dec50123abf28f154f4526db7
parent8eb9940ca4591dd6b92788b2aad6d4056cd74ec7 (diff)
downloadsample-app-stm-write-sample.tar.gz
write STM directly without policy assignationstm-write-sample
If no policy assigned to STM device before writing, a default policy will be applied, so we have to be sure that a policy named 'default' can be found under /config/stp-policy/<stm_device>/ Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org>
-rw-r--r--write-stm-device/example.c12
-rw-r--r--write-stm-device/readme24
-rw-r--r--write-stm-device/stm_user_api.c78
-rw-r--r--write-stm-device/stm_user_api.h40
4 files changed, 35 insertions, 119 deletions
diff --git a/write-stm-device/example.c b/write-stm-device/example.c
index dd58b0e..64e802e 100644
--- a/write-stm-device/example.c
+++ b/write-stm-device/example.c
@@ -14,23 +14,23 @@ 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))
+ if (request_stm_resource(&g_stm_dev, 0, 0))
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);
+ 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("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);
diff --git a/write-stm-device/readme b/write-stm-device/readme
index 6bd7dd9..8b91297 100644
--- a/write-stm-device/readme
+++ b/write-stm-device/readme
@@ -4,22 +4,28 @@ Before compiling the program, you must change the items below accroding to your
- STM device name in stm_user_api.h
- TMC device name in stm_user_api.h
+If you don't care what channel(s) will the trace data be written on, you don't need to read the following words.
+But if not, there will be two ways for you you to create and set a policy for the application program:
-And then you may need to mount configfs manually:
-/ # mount -t configfs none /config
+1) Set a policy in the program via ioctl() system call like [1] is doing, in this way you can use more than one channel,
+since the channel number you want to use can be set by ioctl().
+
+2) Simply use the first available channel selected from a policy named "default" which has to be created via sysfs:
+Mount configfs manually with:
+/ # mount -t configfs none /config
-Create policy directory for STM:
+Create policy directory for STM device:
/ # mkdir /config/stp-policy/20100000.stm.abc
NOTE:
-The STM directory name consists of the device name to which it applies and the actual policy name,
-separated by a dot.
-The device name (say 20100000.stm) have to be matched the name of STM device under /dev.
-The suffix is a random string without any dot
-
+The directory name consists of the STM device name to which the policy applies and the policy name separated by a dot.
+The device name (say 20100000.stm) have to be matched the name of STM device which can be found under /dev.
+The suffix is a arbitrary string without dot.
Create policy:
-/ # mkdir /config/stp-policy/20100000.stm.abc/test
+/ # mkdir /config/stp-policy/20100000.stm.abc/default
+The range of channels and masters of default policy can be changed according to your requirement.
+[1] https://git.linaro.org/people/zhang.chunyan/sample-app.git branch stm-mmap-sample
diff --git a/write-stm-device/stm_user_api.c b/write-stm-device/stm_user_api.c
index 776f20c..8a72e85 100644
--- a/write-stm-device/stm_user_api.c
+++ b/write-stm-device/stm_user_api.c
@@ -10,8 +10,6 @@
#include <unistd.h>
#include "stm_user_api.h"
-void release_stm_resource(struct stm_dev *dev);
-
static void enable_sink(const char *dev_name, unsigned int enable)
{
char buf[256] = {0};
@@ -28,32 +26,6 @@ static void enable_source(const char *dev_name, unsigned int enable)
system(buf);
}
-static int set_policy(int fd, struct stp_policy_id *policy,
- unsigned int chan, unsigned int width)
-{
- unsigned int chan_perpage = PAGE_SIZE / BYTES_PER_CHANNEL;
-
- if(width % chan_perpage || chan % chan_perpage) {
- chan = chan / chan_perpage;
- width = (width / chan_perpage + 1) * BYTES_PER_CHANNEL;
- }
-
- policy->channel = chan;
- policy->__reserved_0 = 0;
- policy->__reserved_1 = 0;
- policy->width = width;
- policy->size = sizeof(struct stp_policy_id) + POLICY_NAME_LEN;
- memcpy(policy->id, STP_POLICY_NAME, POLICY_NAME_LEN);
-
- if (ioctl(fd, STP_POLICY_ID_SET, policy) == -1) {
- printf("STP_POLICY_ID_SET failed %s %d\n",
- strerror(errno), errno);
- return -1;
- }
-
- return 0;
-}
-
/*
* dev - storing the information of stimulus resources and STM device
* chan - the start index of channels
@@ -65,8 +37,6 @@ int request_stm_resource(struct stm_dev *dev, unsigned int chan,
unsigned int width)
{
int fd;
- int ret = 0;
- struct stp_policy_id *policy;
if ((fd = open(STM_DEVICE_NAME, O_RDWR | O_SYNC)) == -1) {
printf("Failed to open %s %s\n", STM_DEVICE_NAME,
@@ -75,52 +45,30 @@ int request_stm_resource(struct stm_dev *dev, unsigned int chan,
}
dev->fd = fd;
- /*
- * Before allocating a policy for STM, the sink connected with STM must
- * be enabled.
- */
- enable_sink(ETF_SYS_NAME, 1);
-
- /* set a master/channel policy for this STM device, this
- * is because that kernel have to know how many channels
- * would be mapped, and the size of mapped memory must be
- * a multiple of page size.
- */
- dev->policy = malloc(sizeof(struct stp_policy_id) + POLICY_NAME_LEN);
- if (!dev->policy) {
- ret = -1;
- printf("Failed to malloc policy.\n");
- goto out;
- }
-
- if (set_policy(fd, dev->policy, chan, width)) {
- ret = -1;
- printf("Failed to set policy.\n");
- goto out;
- }
-
- return ret;
-
-out:
- release_stm_resource(dev);
- return ret;
+ return 0;
}
+
void release_stm_resource(struct stm_dev *dev)
{
- if (dev->policy) {
- free(dev->policy);
- dev->policy = NULL;
- }
if (dev->fd) {
close(dev->fd);
dev->fd = 0;
}
-
- //enable_source(STM_SYS_NAME, 0);
}
unsigned int stm_char_write(int fd, const char *data, unsigned int size)
{
+ /*
+ * Before writing to STM, the sink connected with STM must
+ * be enabled.
+ */
+ enable_sink(ETF_SYS_NAME, 1);
+
+ /*
+ * Before writing, STM must be enabled.
+ */
+ enable_source(STM_SYS_NAME, 1);
+
write(fd, data, size);
}
diff --git a/write-stm-device/stm_user_api.h b/write-stm-device/stm_user_api.h
index 0f9299e..ba043d6 100644
--- a/write-stm-device/stm_user_api.h
+++ b/write-stm-device/stm_user_api.h
@@ -1,58 +1,20 @@
#ifndef __STM_USER_API_H
#define __STM_USER_API_H
-#define BYTES_PER_CHANNEL 256
-#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) //4096
-#define MAP_MASK (PAGE_SIZE - 1)
-#define STM_MAP_SIZE PAGE_SIZE
-
#define STM_DEVICE_NAME "/dev/20100000.stm"
#define ETF_SYS_NAME "20010000.etf"
#define ETR_SYS_NAME "20070000.etr"
#define STM_SYS_NAME "20100000.stm"
-#define STP_POLICY_NAME "test"
#define TEST_DATA_SIZE 4
-#define POLICY_NAME_LEN 8
-
-#define STP_POLICY_ID_SET _IOWR('%', 0, struct stp_policy_id)
-
-enum stm_flags {
- STM_FLAG_TIMESTAMPED = 0x08,
- STM_FLAG_MARKED = 0x10,
- STM_FLAG_GUARANTEED = 0x80,
-};
-
-enum stm_pkt_type {
- STM_PKT_TYPE_DATA = 0x98,
- STM_PKT_TYPE_FLAG = 0xE8,
- STM_PKT_TYPE_TRIG = 0xF8,
-};
-
-enum error_no {
- E_COMMON = -1,
-};
-
-struct stp_policy_id {
- unsigned int size;
- unsigned short master;
- unsigned short channel;
- unsigned short width;
- /* padding */
- unsigned short __reserved_0;
- unsigned int __reserved_1;
- /* policy name */
- char id[0];
-};
struct stm_dev {
int fd;
- struct stp_policy_id *policy;
} g_stm_dev;
int request_stm_resource(struct stm_dev *dev, unsigned int chan,
unsigned int width);
-void release_stm_reaource(struct stm_dev *dev);
+void release_stm_resource(struct stm_dev *dev);
unsigned int stm_char_write(int fd, const char *data, unsigned int size);
#endif /* __STM_USER_API_H */