In this use case, the Divide and Square Root Accelerator (DIVAS) module is used.
This use case will calculate the data in overload mode. If all the calculation results are the same as the desired results, the board LED will be lighted. Otherwise, the board LED will be flashing. The variable "result" can indicate which calculation is wrong.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
The following must be added to the user application source file, outside any function:
The signed and unsigned dividend:
#define BUF_LEN 8
const int32_t numerator_s[
BUF_LEN] = {
2046, 415, 26, 1, -1, -255, -3798, -65535};
const int32_t excepted_s[
BUF_LEN] = {
2046, 207, 8, 0, 0, -42, -542, -8191};
const int32_t excepted_s_m[
BUF_LEN] = {
0, 1, 2, 1, -1, -3, -4, -7};
const uint32_t numerator_u[
BUF_LEN] = {
0x00000001,
0x0000005A,
0x000007AB,
0x00006ABC,
0x0004567D,
0x0093846E,
0x20781945,
0x7FFFFFFF,
};
const uint32_t excepted_u[
BUF_LEN] = {
0x00000001,
0x0000002d,
0x0000028E,
0x00001AAF,
0x0000DE19,
0x00189612,
0x04A37153,
0x0FFFFFFF,
};
const uint32_t excepted_u_m[
BUF_LEN] = {
0, 0, 1, 0, 0, 2, 0, 7};
const uint32_t excepted_r[
BUF_LEN] = {
0x00000001,
0x00000009,
0x0000002C,
0x000000A5,
0x00000215,
0x00000C25,
0x00005B2B,
0x0000B504,
};
static uint8_t result = 0;
Copy-paste the following function code to your user application:
{
int32_t numerator, denominator;
numerator = numerator_s[
i];
denominator = i + 1;
result_s[
i] = numerator / denominator;
if(result_s[i] != excepted_s[i]) {
result |= 0x01;
}
}
}
{
uint32_t numerator, denominator;
numerator = numerator_u[
i];
denominator = i + 1;
result_u[
i] = numerator / denominator;
if(result_u[i] != excepted_u[i]) {
result |= 0x02;
}
}
}
{
int32_t numerator, denominator;
numerator = numerator_s[
i];
denominator = i + 1;
result_s_m[
i] = numerator % denominator;
if(result_s_m[i] != excepted_s_m[i]) {
result |= 0x04;
}
}
}
{
uint32_t numerator, denominator;
numerator = numerator_u[
i];
denominator = i + 1;
result_u_m[
i] = numerator % denominator;
if(result_u_m[i] != excepted_u_m[i]) {
result |= 0x08;
}
}
}
{
uint32_t operator;
operator = numerator_u[
i];
if(result_r[i] != excepted_r[i]) {
result |= 0x10;
}
}
}
Add to user application initialization (typically the start of main()
):
Implementation
Code
Copy-paste the following code to your user application:
while (true) {
if(result) {
volatile uint32_t delay = 50000;
while(delay--) {
}
} else {
}
}
Workflow
- Signed division calculation.
- Unsigned division calculation.
- Signed reminder calculation.
- Unsigned reminder calculation.
- Square root calculation.
- Infinite loop.
while (true) {
if(result) {
volatile uint32_t delay = 50000;
while(delay--) {
}
} else {
}
}