aboutsummaryrefslogtreecommitdiff
path: root/write-stm-device/stm_user_api.c
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 /write-stm-device/stm_user_api.c
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>
Diffstat (limited to 'write-stm-device/stm_user_api.c')
-rw-r--r--write-stm-device/stm_user_api.c78
1 files changed, 13 insertions, 65 deletions
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);
}