Initial version.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "error.h"
|
||||
#include "unit_test_framework.h"
|
||||
#include "time_ctrl/time_ctrl.h"
|
||||
|
||||
#define HARDWARE_VERSION 0x00000001
|
||||
#define TIMER_H 0x00253253
|
||||
#define TIMER_L 0x00225533
|
||||
#define MAX_OPT_DELAY 100 // 1us = 100*10ns
|
||||
|
||||
uint32_t tmcReg[32] = {0};
|
||||
|
||||
TIMECTRL_CONFIG tmcConfig = {
|
||||
.baseAddr = 0,
|
||||
.reset = 10
|
||||
};
|
||||
|
||||
TIMECTRL_INST* tmcInstPtr = NULL;
|
||||
|
||||
void tmc_setup(void){
|
||||
int32_t Status;
|
||||
tmcReg[1] = HARDWARE_VERSION; // Version
|
||||
tmcReg[2] = 253; // Int
|
||||
tmcReg[3] = 253; // Frac
|
||||
tmcReg[4] = 0; // Reset
|
||||
tmcReg[5] = 0; // Preset H
|
||||
tmcReg[6] = 0; // Preset L
|
||||
tmcReg[7] = 0; // Adjustment H
|
||||
tmcReg[8] = 0; // Adjustment L
|
||||
tmcReg[9] = 0; // Adjustment Trigger
|
||||
tmcReg[10] = 0; // step opt
|
||||
tmcConfig.baseAddr = (uintptr_t)tmcReg;
|
||||
Status = TimeCtrl_Init(&tmcInstPtr, &tmcConfig);
|
||||
ASSERT_EQUAL(SUCCESS, Status);
|
||||
}
|
||||
|
||||
void tmc_teardown(void){
|
||||
TimeCtrl_Destroy(tmcInstPtr);
|
||||
}
|
||||
|
||||
TEST(tmc_version) {
|
||||
ASSERT_EQUAL(HARDWARE_VERSION, TimeCtrl_GetVersion(tmcInstPtr));
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(tmc_basic_operations) {
|
||||
TIME_WORD timeStamp;
|
||||
TIME_INT timeH;
|
||||
TIME_FRAC timeL;
|
||||
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStamp);
|
||||
timeH = TimeCtrl_GetIntCnt(tmcInstPtr);
|
||||
timeL = TimeCtrl_GetFracCnt(tmcInstPtr);
|
||||
if(timeL >= timeStamp.frac_part) {
|
||||
ASSERT_EQUAL(timeH, timeStamp.int_part);
|
||||
ASSERT_TRUE(timeL - timeStamp.frac_part < MAX_OPT_DELAY);
|
||||
}
|
||||
else {
|
||||
ASSERT_EQUAL(timeH, timeStamp.int_part+1);
|
||||
ASSERT_TRUE(timeL + COUNTE_FRAC_MAX - timeStamp.frac_part < MAX_OPT_DELAY);
|
||||
}
|
||||
|
||||
TIME_FRAC stepOpt;
|
||||
stepOpt = 0x00000253;
|
||||
TimeCtrl_SetOptimizeStep(tmcInstPtr, &stepOpt);
|
||||
TimeCtrl_GetCurrentStep(tmcInstPtr, &stepOpt);
|
||||
ASSERT_EQUAL(0x00000253, stepOpt);
|
||||
TimeCtrl_Reset(tmcInstPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
TEST_SUITE(tmc_unit_test) {
|
||||
TEST_SUITE_CONFIGURE(tmc_setup, tmc_teardown);
|
||||
RUN_TEST(tmc_version);
|
||||
RUN_TEST(tmc_basic_operations);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
RUN_TEST_SUITE(tmc_unit_test);
|
||||
TEST_REPORT();
|
||||
return TEST_EXIT_CODE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user