dnx RTOS 2.2.0 "Eagle"
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
CRC Driver

Detailed Description

Description

Driver handles CRC peripheral installed in the microcontroller.

Supported architectures

Details

Meaning of major and minor numbers

The major number determines selection of CRC peripheral. Minor number has no meaning and should be set to 0.

Driver initialization

To initialize driver the following code can be used:

driver_init("CRC", 0, 0, "/dev/CRC");

Driver release

To release driver the following code can be used:

driver_release("CRC", 0, 0);

Driver configuration

Configuration is limited to selection of CRC polynomial and initial value. Those options can be not supported by all architectures.

Data write

Data to the CRC device can be write as regular file.

#include <stdio.h>
#include <stdbool.h>
#include <dnx/misc.h>
#include <sys/ioctl.h>
static const char *dev_path = "/dev/CRC";
static const u8_t buf[] = {0,1,2,3,4,5,6,7,8,9};
GLOBAL_VARIABLES_SECTION {
u32_t CRC;
};
int_main(crc_ex, STACK_DEPTH_MEDIUM, int argc, char *argv[])
{
FILE *dev = fopen(dev_path, "r+");
if (dev) {
// calculate CRC
fseek(dev, 0x0, SEEK_SET);
fwrite(buf, sizeof(u8_t), sizeof(buf), dev);
// read CRC
fseek(dev, 0x0, SEEK_SET);
fread(global->CRC, sizeof(u32_t), 1, dev);
// close device
fclose(dev);
} else {
perror(dev_path);
}
return 0;
}

Data read

Data to the CRC device can be read as regular file.

#include <stdio.h>
#include <stdbool.h>
#include <dnx/misc.h>
#include <sys/ioctl.h>
static const char *dev_path = "/dev/CRC";
static const u8_t buf[] = {0,1,2,3,4,5,6,7,8,9};
GLOBAL_VARIABLES_SECTION {
u32_t CRC;
};
int_main(crc_ex, STACK_DEPTH_MEDIUM, int argc, char *argv[])
{
FILE *dev = fopen(dev_path, "r+");
if (dev) {
// calculate CRC
fseek(dev, 0x0, SEEK_SET);
fwrite(buf, sizeof(u8_t), sizeof(buf), dev);
// read CRC
fseek(dev, 0x0, SEEK_SET);
fread(global->CRC, sizeof(u32_t), 1, dev);
// close device
fclose(dev);
} else {
perror(dev_path);
}
return 0;
}

Macros

#define IOCTL_CRC__SET_POLYNOMIAL   _IOW(CRC, 0x00, const u32_t*)
 Set CRC polynomial (if supported by CRC peripheral). More...
 
#define IOCTL_CRC__SET_INITIAL_VALUE   _IOW(CRC, 0x01, const u32_t*)
 Set initial CRC value (if supported by CRC peripheral). More...
 

Macro Definition Documentation

#define IOCTL_CRC__SET_INITIAL_VALUE   _IOW(CRC, 0x01, const u32_t*)
Parameters
[WR]const u32_t * initial value
Returns
On success 0 is returned, otherwise -1 and errno code is set.
#define IOCTL_CRC__SET_POLYNOMIAL   _IOW(CRC, 0x00, const u32_t*)
Parameters
[WR]const u32_t * polynomial value
Returns
On success 0 is returned, otherwise -1 and errno code is set.