RocketLogger  2.0.0
sysfs.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "sysfs.h"
+ Include dependency graph for sysfs.c:

Go to the source code of this file.

Macros

#define SYSFS_STRING_BUFFER_LENGTH   16
 String buffer size for dynamic string operations. More...
 

Functions

int sysfs_export (char const *const sysfs_file, int value)
 
int sysfs_unexport (char const *const sysfs_file, int value)
 
int sysfs_is_exported (char const *const sysfs_path)
 
int sysfs_export_unexported (char const *const sysfs_path, char const *const sysfs_export_file, int value)
 
int sysfs_unexport_exported (char const *const sysfs_path, char const *const sysfs_unexport_file, int value)
 
int sysfs_write_string (char const *const sysfs_file, char const *const value)
 
int sysfs_read_string (char const *const sysfs_file, char *const value, int length)
 
int sysfs_write_int (char const *const sysfs_file, int value)
 
int sysfs_read_int (char const *const sysfs_file, int *const value)
 

Macro Definition Documentation

◆ SYSFS_STRING_BUFFER_LENGTH

#define SYSFS_STRING_BUFFER_LENGTH   16

String buffer size for dynamic string operations.

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 45 of file sysfs.c.

Function Documentation

◆ sysfs_export()

int sysfs_export ( char const *const  sysfs_file,
int  value 
)

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Export (activate) a sysfs device.

If the ressource is busy an error is returned. You might want to use sysfs_unexport first to make sure a device is deactivated.

Parameters
sysfs_fileThe sysfs file used to export
valueThe resource number of the device to export
Returns
0 in case of success, -1 otherwise

Definition at line 50 of file sysfs.c.

References sysfs_write_int().

Referenced by sysfs_export_unexported().

+ Here is the call graph for this function:

◆ sysfs_export_unexported()

int sysfs_export_unexported ( char const *const  sysfs_path,
char const *const  sysfs_export_file,
int  value 
)

Export (activate) a sysfs device if it is not exported already.

Returns success immediately if the sysfs device is exported already, otherwise calls and returns sysfs_export result.

Parameters
sysfs_pathThe sysfs device path to check
sysfs_export_fileThe sysfs file to use to export
valueThe resource number of the device to export
Returns
0 if device successfully exported, 1 if device was exported already, -1 on failure

Definition at line 76 of file sysfs.c.

References sysfs_export(), and sysfs_is_exported().

Referenced by pwm_init().

+ Here is the call graph for this function:

◆ sysfs_is_exported()

int sysfs_is_exported ( char const *const  sysfs_path)

Check wether a sysfs device is exported and fully accessible.

Parameters
sysfs_pathThe sysfs device path to check
Returns
1 if device is exported, 0 if device is not exported, -1 on failure

Definition at line 58 of file sysfs.c.

Referenced by sysfs_export_unexported(), and sysfs_unexport_exported().

◆ sysfs_read_int()

int sysfs_read_int ( char const *const  sysfs_file,
int *const  value 
)

Write an integer to a sysfs device file.

Parameters
sysfs_fileThe sysfs file to read from
valuePointer to the integer variable to write to
Returns
0 in case of success, -1 otherwise

Definition at line 145 of file sysfs.c.

References sysfs_read_string().

+ Here is the call graph for this function:

◆ sysfs_read_string()

int sysfs_read_string ( char const *const  sysfs_file,
char *const  value,
int  length 
)

Read a string from a sysfs device file.

Parameters
sysfs_fileThe sysfs file to read from
valuePointer to the character array to write to
lengthMax length to the string to read
Returns
Read string length in case of success, -1 on failure

Definition at line 121 of file sysfs.c.

Referenced by sysfs_read_int().

◆ sysfs_unexport()

int sysfs_unexport ( char const *const  sysfs_file,
int  value 
)

Unexport (deactivate) a sysfs device.

Parameters
sysfs_fileThe sysfs file used to unexport
valueThe resource number of the device to unexport
Returns
0 in case of success, -1 otherwise.

Definition at line 54 of file sysfs.c.

References sysfs_write_int().

Referenced by pwm_deinit(), and sysfs_unexport_exported().

+ Here is the call graph for this function:

◆ sysfs_unexport_exported()

int sysfs_unexport_exported ( char const *const  sysfs_path,
char const *const  sysfs_unexport_file,
int  value 
)

Unexport (deactivate) a sysfs device if it is exported (active).

Returns success immediately if the sysfs device is not exported, otherwise calls and returns sysfs_unexport result.

Parameters
sysfs_pathThe sysfs device path to check
sysfs_unexport_fileThe sysfs file to use to unexport
valueThe resource number of the device to unexport
Returns
0 if device successfully unexported, 1 if device was not exported, -1 on failure

Definition at line 91 of file sysfs.c.

References sysfs_is_exported(), and sysfs_unexport().

+ Here is the call graph for this function:

◆ sysfs_write_int()

int sysfs_write_int ( char const *const  sysfs_file,
int  value 
)

Write an integer to a sysfs device file.

Parameters
sysfs_fileThe sysfs file to write to
valueThe value to write to write
Returns
0 in case of success, -1 otherwise

Definition at line 136 of file sysfs.c.

Referenced by pwm_deinit(), pwm_init(), sysfs_export(), and sysfs_unexport().

◆ sysfs_write_string()

int sysfs_write_string ( char const *const  sysfs_file,
char const *const  value 
)

Write a string to a sysfs device file.

Parameters
sysfs_fileThe sysfs file to write to
valueThe value to write to write
Returns
0 in case of success, -1 otherwise

Definition at line 106 of file sysfs.c.