Microchip® Advanced Software Framework

Quick Start Guide for DIVAS - No Overload

In this use case, the Divide and Square Root Accelerator (DIVAS) module is used.

This use case will calculate the data in No 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 int32_t result_s[BUF_LEN], result_s_m[BUF_LEN];
static uint32_t result_u[BUF_LEN], result_u_m[BUF_LEN];
static uint32_t result_r[BUF_LEN];
static uint8_t result = 0;

Copy-paste the following function code to your user application:

static void signed_division(void)
{
int32_t numerator, denominator;
uint8_t i;
for (i = 0; i < BUF_LEN; i++) {
numerator = numerator_s[i];
denominator = i + 1;
result_s[i] = divas_idiv(numerator, denominator);
if(result_s[i] != excepted_s[i]) {
result |= 0x01;
}
}
}
static void unsigned_division(void)
{
uint32_t numerator, denominator;
uint8_t i;
for (i = 0; i < BUF_LEN; i++) {
numerator = numerator_u[i];
denominator = i + 1;
result_u[i] = divas_uidiv(numerator, denominator);
if(result_u[i] != excepted_u[i]) {
result |= 0x02;
}
}
}
static void signed_division_mod(void)
{
int32_t numerator, denominator;
uint8_t i;
for (i = 0; i < BUF_LEN; i++) {
numerator = numerator_s[i];
denominator = i + 1;
result_s_m[i] = divas_idivmod(numerator, denominator);
if(result_s_m[i] != excepted_s_m[i]) {
result |= 0x04;
}
}
}
static void unsigned_division_mod(void)
{
uint32_t numerator, denominator;
uint8_t i;
for (i = 0; i < BUF_LEN; i++) {
numerator = numerator_u[i];
denominator = i + 1;
result_u_m[i] = divas_uidivmod(numerator, denominator);
if(result_u_m[i] != excepted_u_m[i]) {
result |= 0x08;
}
}
}
static void squart_root(void)
{
uint32_t operator;
uint8_t i;
for (i = 0; i < BUF_LEN; i++) {
operator = numerator_u[i];
result_r[i] = divas_sqrt(operator);
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) {
/* Add a short delay to see LED toggle */
volatile uint32_t delay = 50000;
while(delay--) {
}
} else {
port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
}
}

Workflow

  1. Signed division calculation.
  2. Unsigned division calculation.
  3. Signed reminder calculation.
  4. Unsigned reminder calculation.
  5. Square root calculation.
  6. Infinite loop.
    while (true) {
    if(result) {
    /* Add a short delay to see LED toggle */
    volatile uint32_t delay = 50000;
    while(delay--) {
    }
    } else {
    port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
    }
    }