#include "main.h" #include "spi_func.h" #include "spidev.h" #include "CddSbc.h" #include "Cdd_bd18397.h" #include "CddBoost.h" static int gcd(int a, int b) ; static int lcm_multiple(int numbers[], int length); int32_t TIMER_FLAGS[ ] = {1,2,5,10,100,150,200,1000}; int32_t TIMER_RELOADValue = 1000; uint8 Spi_Stat = 0; Std_VersionInfoType Ex_Spi_VersionInfo; void InitSPI(void) { MCALLIB_DEV_ASSERT_START(); #if EN_SPI #if(SPI_PRECOMPILE_SUPPORT == STD_ON) Spi_Init(NULL_PTR); #else Spi_Init(&Spi_Config); #endif Spi_GetVersionInfo(&Ex_Spi_VersionInfo); Spi_Stat = 1; //get timer lcm TIMER_RELOADValue = lcm_multiple(TIMER_FLAGS,sizeof(TIMER_FLAGS)/sizeof(uint32_t)); MCALLIB_DEV_ASSERT(TIMER_RELOADValue>0); #if (SBCTEST) CddSbc_Init(); CddSbc_SetWdgWindowModeAnd200ms(); #endif Gpt_EnableNotification(GptChlSPI); Gpt_StartTimer(GptChlSPI, 1000); //start GPT for SPI InitSPI_Dev(); #endif MCALLIB_DEV_ASSERT_END(); } static int gcd(int a, int b) { while (b != 0) { int temp = b; b = a % b; a = temp; } return a; } static int lcm_multiple(int numbers[], int length) { int result = numbers[0]; for (int i = 1; i < length; i++) { result = (result * numbers[i]) / gcd(result, numbers[i]); } return result; } PT_THREAD(TaskLMM(struct pt *pt1 )) { static uint8 index =ID_SYSTEM_REGISTER; static uint8 adsel_mode =ADSEL_Thermal; static uint16 led_para =0; //uint8 read_reg_value1[4]; static int CoutFlag= 0; CoutFlag++; CoutFlag = CoutFlag%TIMER_RELOADValue; PT_BEGIN(pt1); #if EN_SPI //1ms { if(BD18397RUV_get_current_register_id(index) ==index) { if(index==0) { BD18397_RUV_get_registor_data(ID_MAX_REGISTER-1); } else { BD18397_RUV_get_registor_data(index-1); } } } //2ms if(CoutFlag%2==0) { BD18397_RUV_get_registor_read_cmd(index); if(index < ID_MAX_REGISTER) { index=index+1; } else { index=ID_SYSTEM_REGISTER; } } //5ms if(CoutFlag%2==0) { /* 5ms timer counter */ } //10ms if(CoutFlag%10==1) //10ms + offset 1 { /* 10ms timer counter */ } //100ms if(CoutFlag%100==2) //100ms + offset 2 { // 100ms timer counter Cdd_bd18397_SPI_PWM_Dimming(1,led_para&0x3ff); if(led_para<0x3ff) { led_para++; } else { led_para=0; } } //150ms if(CoutFlag%150==3) //150ms + offset 3 { } //200ms if(CoutFlag%200==4) //200ms + offset 4 { } //1000ms if(CoutFlag%1000==5) //1000ms + offset 5 { BD18397_RUV_set_VMONSEL_mode(adsel_mode); if(adsel_mode< ADSEL_VSNSN2) { adsel_mode=adsel_mode+1; } else { adsel_mode=ADSEL_Thermal; } } #endif PT_END(pt1); } PT_THREAD(TaskEX_WDT(struct pt *pt1 )) { PT_BEGIN(pt1); PT_END(pt1); } void GPT_Notif_SPI(void) { } void Spi_Drv_ExternalDeviceConfig_SpiExternalDevice_0(void) { } void Spi_Drv_PhyUnitConfig_SpiPhyUnit_0(void) { } void Ex_Spi_StpJobEndNotification(void) { } void Ex_Spi_StpJobStartNotification(void) { } void Ex_Spi_SbcJobEndNotification(void) { } void Ex_Spi_SbcJobStartNotification(void) { } void Ex_Spi_BuckJobEndNotification(void) { } void Ex_Spi_BuckJobStartNotification(void) { } void Ex_Spi_BoostJobEndNotification(void) { Dio_WriteChannel(PTB17,STD_HIGH); } void Ex_Spi_BoostJobStartNotification(void) { } ///////////////////////////////////////////////////////// void Ex_Spi_StpSequenceEndNotification(void) { } void Ex_Spi_BuckSequenceEndNotification(void) { } void Ex_Spi_BoostSequenceEndNotification(void) { } void Ex_Spi_SbcSequenceEndNotification(void) { } uint8 Spi_Stat_Get(void) { return Spi_Stat; }