1376 lines
40 KiB
C
1376 lines
40 KiB
C
#include "SpbDriverApi.h"
|
||
#include "SpbApi.h"
|
||
#include "string.h"
|
||
#include "stdio.h"
|
||
#include "stdint.h"
|
||
#include "xtal.h"
|
||
#include "ram_bitband.h"
|
||
#include "bl_ic_config.h"
|
||
|
||
const uint16_t tab_4b5b[256]= {
|
||
0x3de, 0x3c9, 0x3d4, 0x3d5, 0x3ca, 0x3cb, 0x3ce, 0x3cf, 0x3d2, 0x3d3, 0x3d6, 0x3d7, 0x3da, 0x3db, 0x3dc, 0x3dd,
|
||
0x13e, 0x129, 0x134, 0x135, 0x12a, 0x12b, 0x12e, 0x12f, 0x132, 0x133, 0x136, 0x137, 0x13a, 0x13b, 0x13c, 0x13d,
|
||
0x29e, 0x289, 0x294, 0x295, 0x28a, 0x28b, 0x28e, 0x28f, 0x292, 0x293, 0x296, 0x297, 0x29a, 0x29b, 0x29c, 0x29d,
|
||
0x2be, 0x2a9, 0x2b4, 0x2b5, 0x2aa, 0x2ab, 0x2ae, 0x2af, 0x2b2, 0x2b3, 0x2b6, 0x2b7, 0x2ba, 0x2bb, 0x2bc, 0x2bd,
|
||
0x15e, 0x149, 0x154, 0x155, 0x14a, 0x14b, 0x14e, 0x14f, 0x152, 0x153, 0x156, 0x157, 0x15a, 0x15b, 0x15c, 0x15d,
|
||
0x17e, 0x169, 0x174, 0x175, 0x16a, 0x16b, 0x16e, 0x16f, 0x172, 0x173, 0x176, 0x177, 0x17a, 0x17b, 0x17c, 0x17d,
|
||
0x1de, 0x1c9, 0x1d4, 0x1d5, 0x1ca, 0x1cb, 0x1ce, 0x1cf, 0x1d2, 0x1d3, 0x1d6, 0x1d7, 0x1da, 0x1db, 0x1dc, 0x1dd,
|
||
0x1fe, 0x1e9, 0x1f4, 0x1f5, 0x1ea, 0x1eb, 0x1ee, 0x1ef, 0x1f2, 0x1f3, 0x1f6, 0x1f7, 0x1fa, 0x1fb, 0x1fc, 0x1fd,
|
||
0x25e, 0x249, 0x254, 0x255, 0x24a, 0x24b, 0x24e, 0x24f, 0x252, 0x253, 0x256, 0x257, 0x25a, 0x25b, 0x25c, 0x25d,
|
||
0x27e, 0x269, 0x274, 0x275, 0x26a, 0x26b, 0x26e, 0x26f, 0x272, 0x273, 0x276, 0x277, 0x27a, 0x27b, 0x27c, 0x27d,
|
||
0x2de, 0x2c9, 0x2d4, 0x2d5, 0x2ca, 0x2cb, 0x2ce, 0x2cf, 0x2d2, 0x2d3, 0x2d6, 0x2d7, 0x2da, 0x2db, 0x2dc, 0x2dd,
|
||
0x2fe, 0x2e9, 0x2f4, 0x2f5, 0x2ea, 0x2eb, 0x2ee, 0x2ef, 0x2f2, 0x2f3, 0x2f6, 0x2f7, 0x2fa, 0x2fb, 0x2fc, 0x2fd,
|
||
0x35e, 0x349, 0x354, 0x355, 0x34a, 0x34b, 0x34e, 0x34f, 0x352, 0x353, 0x356, 0x357, 0x35a, 0x35b, 0x35c, 0x35d,
|
||
0x37e, 0x369, 0x374, 0x375, 0x36a, 0x36b, 0x36e, 0x36f, 0x372, 0x373, 0x376, 0x377, 0x37a, 0x37b, 0x37c, 0x37d,
|
||
0x39e, 0x389, 0x394, 0x395, 0x38a, 0x38b, 0x38e, 0x38f, 0x392, 0x393, 0x396, 0x397, 0x39a, 0x39b, 0x39c, 0x39d,
|
||
0x3be, 0x3a9, 0x3b4, 0x3b5, 0x3aa, 0x3ab, 0x3ae, 0x3af, 0x3b2, 0x3b3, 0x3b6, 0x3b7, 0x3ba, 0x3bb, 0x3bc, 0x3bd
|
||
};
|
||
|
||
uint8_t bmc_h[2]= {
|
||
1,0
|
||
// {0,0},
|
||
};
|
||
|
||
uint8_t bmc_l[2][2]= {
|
||
//00-->11 0
|
||
//01-->10 1
|
||
//10-->00 0
|
||
//11-->01 1
|
||
{1,0},
|
||
{0,1},
|
||
};
|
||
|
||
#if defined HY8608 || HY8108
|
||
Frame_Format_t ospb_frame;
|
||
#endif
|
||
|
||
LANE_DATA_t lane_data[MAXDIP]= {0};
|
||
|
||
uint16_t lane_outbuf[PORTOUTBUFSIZE]= {0};
|
||
uint16_t ospb_di_short_0pos_outbuf[SHORT_CMD_PORTOUTBUFSIZE]={0};
|
||
uint16_t ospb_di_short_50pos_outbuf[SHORT_CMD_PORTOUTBUFSIZE]={0};
|
||
uint16_t ospb_di_short_0pos_outbuf2[SHORT_CMD_PORTOUTBUFSIZE]={0};
|
||
uint16_t ospb_di_short_50pos_outbuf2[SHORT_CMD_PORTOUTBUFSIZE]={0};
|
||
|
||
//di long cmd
|
||
void TIM2_IRQHandler(void) {
|
||
|
||
// if(spb_tx.step < spb_tx.tx_len )
|
||
// {
|
||
// if(spb_tx.step & 0x0001){ //<2F><>ֵ
|
||
// DI_PORT->POD = DI_PORT1->PID ^ *(spb_tx.OutDat1++);
|
||
// }
|
||
// else{ //bit<69><74>ת
|
||
// DI_PORT->POD =DI_PORT1->PID ^ machine.di_mask1;
|
||
// }
|
||
// spb_tx.step++;
|
||
// }
|
||
//
|
||
// else
|
||
// {
|
||
// Dip_Set_High();
|
||
// DI_TIM->CTRL1&=~(1<<0);
|
||
// spb_tx.status =0;
|
||
// }
|
||
|
||
|
||
DIP_PORT->POD =DIP_PORT->PID ^ machine.di_mask; //bit<69><74>ת
|
||
DIP_TIM->STS =0;
|
||
spb_tx.step++;
|
||
if(spb_tx.step==spb_tx.tx_len) {
|
||
DIP_TIM->CTRL1&=~1; //ִ<><D6B4><EFBFBD><EFBFBD>220ns nop<6F><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ô<EFBFBD><C3B4>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>Tnop=1/128M (<28><>10ns)
|
||
DIP_TIM->STS =0;
|
||
}
|
||
#if (MODEL_TYPE== A5H_85_28_16_448_HY8108)//A5H_85_28_16_448_HY8108<30><38><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD>50% <20><><EFBFBD><EFBFBD>33%
|
||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
|
||
__NOP(); __NOP();
|
||
__NOP(); __NOP(); __NOP(); __NOP();
|
||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
|
||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
|
||
#endif
|
||
|
||
DIP_PORT->POD = DIP_PORT->PID ^ *(spb_tx.OutDat1); //<2F><>ֵ
|
||
spb_tx.OutDat1++;
|
||
|
||
}
|
||
|
||
//di short cmd
|
||
void TIM3_IRQHandler(void) {
|
||
DIP_TIM2->STS =0;
|
||
if(spb_tx.step < spb_tx.tx_len ) {
|
||
// DI_PORT->POD = spb_tx.OutDat1[spb_tx.step];
|
||
((GPIO_Module*)spb_tx.port_addr)->POD = spb_tx.OutDat1[spb_tx.step];
|
||
spb_tx.step++;
|
||
}
|
||
else {
|
||
DIP_PORT->POD |=machine.di_mask;
|
||
// Dip_Set_High();
|
||
#if defined HY8810 || HY8811 || HY8603 || HY8822 || HY8612
|
||
// Dis_Set_High();
|
||
DIS_PORT->POD |=machine.dis_mask;
|
||
#elif defined HY8602
|
||
DIS_PORT->POD &=~machine.dis_mask;
|
||
#endif
|
||
DIP_TIM2->CTRL1&=~1;
|
||
spb_tx.status =0;
|
||
|
||
}
|
||
}
|
||
|
||
void DMA_Channel5_IRQHandler(void){
|
||
if(DMA->INTSTS &0x20000){
|
||
DMA->INTCLR |=0xf0000;
|
||
DIP_TIM2->CTRL1&=~1;
|
||
TIM_Dma_Disable(DIP_TIM2, TIM_DMA_CC1);
|
||
TIM_Dma_Disable(DIP_TIM2, TIM_DMA_UPDATE);
|
||
spb_tx.status =0;
|
||
}
|
||
}
|
||
|
||
static void SpbDriverApi_SpbFreqInit(void) {
|
||
uint16_t PrescalerValue = 0;
|
||
TIM_TimeBaseInitType TIM_TimeBaseStructure;
|
||
OCInitType TIME_Oc_Structure;
|
||
DMA_InitType DMA_InitSt;
|
||
|
||
RCC_APB1_Peripheral_Clock_Enable(RCC_APB1_PERIPH_TIM2);
|
||
RCC_APB1_Peripheral_Clock_Enable(RCC_APB1_PERIPH_TIM3);
|
||
RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_DMA);
|
||
|
||
//TIMER2 di send long packge
|
||
//64M
|
||
//1M 7 7
|
||
//1.5M 6 5
|
||
//2M 7 3
|
||
TIM_Base_Struct_Initialize(&TIM_TimeBaseStructure);
|
||
#if (MODEL_TYPE== A5H_85_28_16_448_HY8108)//A5H_85_28_16_448_HY8108Ƶ<38><C6B5>1M <20><><EFBFBD><EFBFBD>1.5M
|
||
PrescalerValue = 7;
|
||
TIM_TimeBaseStructure.Period = 7;
|
||
#else
|
||
PrescalerValue = 6;
|
||
TIM_TimeBaseStructure.Period = 5;
|
||
#endif
|
||
TIM_TimeBaseStructure.Prescaler = 0;
|
||
TIM_TimeBaseStructure.ClkDiv = 0;
|
||
TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
|
||
|
||
TIM_Base_Initialize(DIP_TIM, &TIM_TimeBaseStructure);
|
||
TIM_Auto_Reload_Preload_Enable(DIP_TIM);
|
||
TIM_Base_Prescaler_Set(DIP_TIM, PrescalerValue);
|
||
DIP_TIM->STS &=~1;
|
||
TIM_Interrupt_Enable(DIP_TIM, TIM_INT_UPDATE);
|
||
|
||
|
||
//TIMER3 dis send
|
||
//64M
|
||
//400K 10 7(period)
|
||
//500K 7 7(period)
|
||
//600K 12 3(period)
|
||
//700K 8 4(period)
|
||
//800K 9 3(period)
|
||
//900K 5 5(period)
|
||
//1M 7 3(period)
|
||
//1.1M 6 3(period)
|
||
TIM_Base_Struct_Initialize(&TIM_TimeBaseStructure);
|
||
PrescalerValue = 7;
|
||
TIM_TimeBaseStructure.Period = 9;
|
||
TIM_TimeBaseStructure.Prescaler = 0;
|
||
TIM_TimeBaseStructure.ClkDiv = 0;
|
||
TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
|
||
|
||
TIM_Base_Initialize(DIP_TIM2, &TIM_TimeBaseStructure);
|
||
TIM_Auto_Reload_Preload_Enable(DIP_TIM2);
|
||
TIM_Base_Prescaler_Set(DIP_TIM2, PrescalerValue);
|
||
TIME_Oc_Structure.OcMode=TIM_OCMODE_PWM1;
|
||
TIME_Oc_Structure.OcPolarity=TIM_OC_POLARITY_HIGH;
|
||
TIME_Oc_Structure.OutputState=TIM_OUTPUT_STATE_ENABLE;
|
||
TIME_Oc_Structure.Pulse=5;
|
||
TIM_Output_Channel1_Initialize(DIP_TIM2, &TIME_Oc_Structure);
|
||
TIM_Dma_Enable(DIP_TIM2, TIM_DMA_CC1);
|
||
TIM_Dma_Enable(DIP_TIM2, TIM_DMA_UPDATE);
|
||
DIP_TIM2->STS =0;
|
||
DMA_Reset(DMA_CH6);
|
||
DMA_Reset(DMA_CH5);
|
||
DMA_Structure_Initializes(&DMA_InitSt);
|
||
DMA_InitSt.PeriphAddr = (uint32_t)&GPIOA->POD;
|
||
DMA_InitSt.MemAddr = (uint32_t)ospb_di_short_50pos_outbuf;
|
||
DMA_InitSt.Direction = DMA_DIR_PERIPH_DST;
|
||
DMA_InitSt.BufSize = 0;
|
||
DMA_InitSt.PeriphInc = DMA_PERIPH_INC_MODE_DISABLE;
|
||
DMA_InitSt.MemoryInc = DMA_MEM_INC_MODE_ENABLE;
|
||
DMA_InitSt.PeriphDataSize = DMA_PERIPH_DATA_WIDTH_HALFWORD;
|
||
DMA_InitSt.MemDataSize = DMA_MEM_DATA_WIDTH_HALFWORD;
|
||
DMA_InitSt.CircularMode = DMA_CIRCULAR_MODE_DISABLE;
|
||
DMA_InitSt.Priority = DMA_CH_PRIORITY_HIGHEST;
|
||
DMA_InitSt.Mem2Mem = DMA_MEM2MEM_DISABLE;
|
||
DMA_Initializes(DMA_CH6, &DMA_InitSt);
|
||
DMA_InitSt.PeriphAddr = (uint32_t)&GPIOA->POD;
|
||
DMA_InitSt.MemAddr = (uint32_t)ospb_di_short_0pos_outbuf;
|
||
DMA_Initializes(DMA_CH5, &DMA_InitSt);
|
||
|
||
DMA_Channel_Request_Remap(DMA_CH6,DMA_REMAP_TIM3_CH1);
|
||
DMA_Channel_Request_Remap(DMA_CH5,DMA_REMAP_TIM3_UP);
|
||
DMA_CH5->CHCFG |=2;
|
||
}
|
||
|
||
void preamber_init(uint8_t type) {
|
||
uint8_t i=0;
|
||
uint16_t mask;
|
||
uint8_t len=0;
|
||
#if defined HY8810 || HY8811 || HY8603 || HY8822
|
||
mask=type?machine.di_mask:machine.dis_mask; //0:dis 1:dip
|
||
len=15;
|
||
#elif defined HY8602
|
||
mask=type?machine.di_mask:machine.dis_mask; //0:dis 1:dip
|
||
len=15;
|
||
#elif defined HY8612
|
||
mask=type?machine.di_mask:machine.dis_mask; //0:dis 1:dip
|
||
len=4;
|
||
#elif defined HY8608 || HY8108
|
||
mask=machine.di_mask; //0:dis 1:dip
|
||
len=4;
|
||
#endif
|
||
memset(ospb_di_short_0pos_outbuf,0,sizeof(ospb_di_short_0pos_outbuf));
|
||
memset(ospb_di_short_50pos_outbuf,0,sizeof(ospb_di_short_50pos_outbuf));
|
||
ospb_di_short_50pos_outbuf[0]=mask;
|
||
ospb_di_short_0pos_outbuf [0]=0;
|
||
for(i=0;i<len;i++){
|
||
ospb_di_short_50pos_outbuf[1+i*4]=0;
|
||
ospb_di_short_0pos_outbuf [1+i*4]=mask;
|
||
ospb_di_short_50pos_outbuf[2+i*4]=0;
|
||
ospb_di_short_0pos_outbuf [2+i*4]=mask;
|
||
ospb_di_short_50pos_outbuf[3+i*4]=mask;
|
||
ospb_di_short_0pos_outbuf [3+i*4]=0;
|
||
ospb_di_short_50pos_outbuf[4+i*4]=mask;
|
||
ospb_di_short_0pos_outbuf [4+i*4]=0;
|
||
}
|
||
}
|
||
|
||
void Spb_Init(void) {
|
||
SpbApi_SpbBspInit();
|
||
SpbDriverApi_SpbFreqInit();
|
||
RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_CRC);
|
||
preamber_init(1);
|
||
}
|
||
|
||
|
||
|
||
|
||
uint8_t SpbDriverApi_GetFbreadStatus(void) {
|
||
return spb_rx_dos.status&0x03;
|
||
}
|
||
|
||
const uint8_t decode_5b4b_tab[32] = {
|
||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x04,0x05,0xFF,0xFF,0x06,0x07,
|
||
0xFF,0xFF,0x08,0x09,0x02,0x03,0x0A,0x0B,0xFF,0xFF,0x0c,0x0d,0x0E,0x0F,0x00,0xFF,
|
||
};
|
||
|
||
fb_err_t SpbDriverApi_Fb_Decode(uint16_t *rdata) {
|
||
uint16_t i=0,j=0;
|
||
uint8_t temp=0;
|
||
|
||
uint32_t sop_head=0;
|
||
uint32_t startaddr=0;
|
||
uint32_t subaddr=0;
|
||
uint32_t feedback=0;
|
||
uint32_t datalength=0;
|
||
uint32_t data=0;
|
||
uint32_t crc=0;
|
||
uint32_t eop=0;
|
||
|
||
uint8_t max=0;
|
||
uint16_t t1=0;
|
||
uint8_t bmc_1=0;
|
||
uint16_t cnt=0;
|
||
|
||
uint8_t valid_pos=0;
|
||
uint8_t current_value=0;
|
||
uint8_t pre_value=0;
|
||
uint8_t xor_value=0;
|
||
uint16_t crc_cla=0;
|
||
|
||
|
||
for(i=0; i<8; i++) {
|
||
if(spb_dos_inbuf[i]>=t1) {
|
||
t1=spb_dos_inbuf[i];
|
||
max=i;
|
||
}
|
||
}
|
||
t1=spb_dos_inbuf[max]*0.75;
|
||
|
||
spb_dos_inbuf[0]=0;
|
||
cnt++;
|
||
for(i=max+1; i<spb_rx_dos.dos_len; i++) {
|
||
if(bmc_1) {
|
||
bmc_1=0;
|
||
}
|
||
else {
|
||
if(spb_dos_inbuf[i]<t1) { //1
|
||
spb_dos_inbuf[cnt++]=1;
|
||
bmc_1=1;
|
||
}
|
||
else { //0
|
||
spb_dos_inbuf[cnt++]=0;
|
||
}
|
||
}
|
||
}
|
||
if(cnt<=125) //DEBUG 25-9-5
|
||
{
|
||
spb_dos_inbuf[cnt++]=0;
|
||
}
|
||
pre_value=spb_dos_inbuf[0];
|
||
for(i=1; i<cnt; i++) {
|
||
current_value=spb_dos_inbuf[i];
|
||
xor_value=current_value^pre_value;
|
||
pre_value=current_value;
|
||
if(xor_value==0) {
|
||
valid_pos=i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
#if defined HY8810 || HY8811 || HY8603 || HY8822
|
||
for(i=19; i<20; i--) {
|
||
sop_head |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
if((sop_head!=SOP_ADDR) && (sop_head!=SOP_READ_BACK) ) {
|
||
printf("head err :%x\n",sop_head);
|
||
return 3;
|
||
} else if(sop_head==SOP_ADDR) {
|
||
sop_head=CMD_ADDR;
|
||
} else if(sop_head==SOP_READ_BACK) {
|
||
sop_head=CMD_READ_BACK;
|
||
}
|
||
|
||
startaddr=0;
|
||
//startaddr
|
||
for(i=1; i<=4; i++) {
|
||
temp=0;
|
||
for(j=0; j<5; j++) {
|
||
temp|=spb_dos_inbuf[valid_pos]<<(4-j);
|
||
valid_pos++;
|
||
}
|
||
startaddr|= decode_5b4b_tab[temp]<<((4-i)*4);
|
||
}
|
||
|
||
//data
|
||
for(i=1; i<=4; i++) {
|
||
temp=0;
|
||
for(j=0; j<5; j++) {
|
||
temp|=spb_dos_inbuf[valid_pos]<<(4-j);
|
||
valid_pos++;
|
||
}
|
||
data|= decode_5b4b_tab[temp]<<((4-i)*4);
|
||
}
|
||
|
||
//crc
|
||
for(i=1; i<=4; i++) {
|
||
temp=0;
|
||
for(j=0; j<5; j++) {
|
||
temp|=spb_dos_inbuf[valid_pos]<<(4-j);
|
||
valid_pos++;
|
||
}
|
||
crc|= decode_5b4b_tab[temp]<<((4-i)*4);
|
||
}
|
||
|
||
//eop
|
||
for(j=0; j<5; j++) {
|
||
eop|=spb_dos_inbuf[valid_pos]<<(4-j);
|
||
valid_pos++;
|
||
}
|
||
if(eop!=0x0d) { //eop err
|
||
printf("eop err[%d]\n",eop);
|
||
return EOP_ERR;
|
||
}
|
||
|
||
#elif defined HY8612 || HY8608 || HY8108
|
||
sop_head=0x4000;
|
||
for(i=13; i<14; i--) {
|
||
sop_head |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
if(((sop_head>>8)!=CMD_ADDR) && ((sop_head>>8)!=CMD_READ_BACK) ) {
|
||
printf("head err :%x\n",sop_head);
|
||
return 3;
|
||
}
|
||
|
||
startaddr=0;
|
||
for(i=15; i<16; i--) {
|
||
startaddr |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
|
||
subaddr=0;
|
||
for(i=15; i<16; i--) {
|
||
subaddr |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
|
||
#if defined HY8608 || HY8108
|
||
feedback=0;
|
||
for(i=15; i<16; i--) {
|
||
feedback |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
#endif
|
||
|
||
datalength=0;
|
||
for(i=15; i<16; i--) {
|
||
datalength |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
|
||
data=0;
|
||
for(i=15; i<16; i--) {
|
||
data |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
|
||
crc=0;
|
||
for(i=15; i<16; i--) {
|
||
crc |=spb_dos_inbuf[valid_pos]<<i;
|
||
valid_pos++;
|
||
}
|
||
|
||
#endif
|
||
|
||
CRC->CRC16D = 0xffff;
|
||
CRC->CRC16DAT =sop_head>>8;
|
||
CRC->CRC16DAT =sop_head&0x00ff;
|
||
CRC->CRC16DAT =startaddr>>8;
|
||
CRC->CRC16DAT =startaddr&0x00ff;
|
||
#if defined HY8612 || HY8608 || HY8108
|
||
CRC->CRC16DAT =subaddr>>8;
|
||
CRC->CRC16DAT =subaddr&0x00ff;
|
||
#if defined HY8608 || HY8108
|
||
CRC->CRC16DAT =feedback>>8;
|
||
CRC->CRC16DAT =feedback&0x00ff;
|
||
#endif
|
||
CRC->CRC16DAT =datalength>>8;
|
||
CRC->CRC16DAT =datalength&0x00ff;
|
||
#endif
|
||
CRC->CRC16DAT =data>>8;
|
||
CRC->CRC16DAT =data&0x00ff;
|
||
crc_cla = CRC->CRC16D;
|
||
|
||
if(crc_cla!=crc) { //crc err
|
||
printf("crc err:%x %x\n",crc_cla,crc);
|
||
return CRC_ERR;
|
||
}
|
||
|
||
*rdata=(uint16_t)data;
|
||
return OK;
|
||
|
||
}
|
||
|
||
|
||
|
||
void Di_Send_Data(uint16_t sLen, bool block) {
|
||
|
||
spb_tx.step = 0;
|
||
spb_tx.tx_len = sLen;
|
||
|
||
spb_tx.OutDat1 = lane_outbuf;//machine.di_out_buf;
|
||
|
||
//spb_tx.OutDat1--;
|
||
|
||
spb_tx.status |=1<<0;
|
||
|
||
DIP_TIM->CNT=0;
|
||
DIP_TIM->CTRL1 |=1;
|
||
|
||
if(block)
|
||
while(spb_tx.step<spb_tx.tx_len) {}
|
||
|
||
#if defined HY8602
|
||
Dip_Set_Low();
|
||
#else
|
||
Dip_Set_High();
|
||
#endif
|
||
DIP_TIM->CTRL1&=~(1<<0);
|
||
|
||
|
||
spb_tx.status =0;
|
||
}
|
||
|
||
void Dis_Send_Shortcmd(uint16_t sLen, bool block) {
|
||
|
||
DIP_TIM2->STS =0;
|
||
DIP_TIM2->CNT =0;
|
||
|
||
|
||
spb_tx.status |=1<<0;
|
||
|
||
DMA_CH5->CHCFG &=~1;
|
||
DMA_CH6->CHCFG &=~1;
|
||
DMA_CH6->MADDR=(uint32_t)ospb_di_short_50pos_outbuf;
|
||
DMA_CH6->TXNUM=sLen;
|
||
DMA_CH5->MADDR=(uint32_t)ospb_di_short_0pos_outbuf;
|
||
DMA_CH5->TXNUM=sLen;
|
||
DMA_CH5->CHCFG |=1;
|
||
DMA_CH6->CHCFG |=1;
|
||
TIM_Dma_Enable(DIP_TIM2, TIM_DMA_CC1);
|
||
TIM_Dma_Enable(DIP_TIM2, TIM_DMA_UPDATE);
|
||
DIP_TIM2->CTRL1 |=1;
|
||
}
|
||
|
||
uint16_t BMC_SAME_DATA(uint32_t data,uint16_t *p0_out,uint16_t *p50_out,uint16_t io_lv,uint16_t mask,uint8_t bit_width){
|
||
volatile uint16_t lv=0;
|
||
volatile int8_t j=0;
|
||
volatile uint8_t bit_value=0;
|
||
lv=io_lv;
|
||
j=(bit_width-1);
|
||
for(;j>=0;j--){
|
||
bit_value=(data>>j)&1;
|
||
if(bit_value)
|
||
*p50_out=lv^mask;
|
||
else *p50_out=lv;
|
||
*p0_out=*p50_out^mask;
|
||
lv=*p0_out;
|
||
p0_out++; //<2F><>ת
|
||
p50_out++;
|
||
}
|
||
return lv;
|
||
}
|
||
|
||
void PackDiShortCmdBuf(uint16_t *parames,uint16_t parames_len,uint16_t *data,uint16_t dlen,uint16_t mask) {
|
||
uint8_t i=0;
|
||
int8_t j=0;
|
||
// uint16_t crc_calc=0;
|
||
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
uint32_t temp_data=0;
|
||
#elif defined HY8608|| HY8612 || HY8108
|
||
uint16_t temp_data=0;
|
||
#endif
|
||
|
||
uint16_t *p0_out;
|
||
uint16_t *p50_out;
|
||
|
||
//ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD>
|
||
CRC->CRC16D = 0xffff;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
|
||
p0_out=&ospb_di_short_0pos_outbuf[61];
|
||
p50_out=&ospb_di_short_50pos_outbuf[61];
|
||
|
||
CRC->CRC16DAT =parames[0]>>8;
|
||
CRC->CRC16DAT =parames[0]&0xff;
|
||
if(parames[0]==CMD_ADDR) {
|
||
temp_data=SOP_ADDR;
|
||
if(machine.dip_dis_combine)spb_tx.port_addr=GPIOA_BASE;
|
||
else spb_tx.port_addr=GPIOD_BASE;
|
||
}
|
||
else if(parames[0]==CMD_READ_BACK) {
|
||
temp_data=SOP_READ_BACK;
|
||
if(machine.dip_dis_combine)spb_tx.port_addr=GPIOA_BASE;
|
||
else spb_tx.port_addr=GPIOD_BASE;
|
||
}
|
||
else if(parames[0]==CMD_CONFIG) {temp_data=SOP_CONFIG; spb_tx.port_addr=GPIOA_BASE;}
|
||
else if(parames[0]==CMD_BROADCAST) {temp_data=SOP_BROADCAST; spb_tx.port_addr=GPIOA_BASE;}
|
||
else if(parames[0]==CMD_DIMMING) {temp_data=SOP_DIMMING; spb_tx.port_addr=GPIOA_BASE;}
|
||
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
|
||
|
||
|
||
|
||
|
||
for(i=1; i<parames_len; i++) {
|
||
CRC->CRC16DAT =parames[i]>>8;
|
||
CRC->CRC16DAT =parames[i]&0xff;
|
||
temp_data= tab_4b5b[parames[i]&0xff] | (tab_4b5b[parames[i]>>8]<<10);
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
|
||
}
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
|
||
spb_tx.port_addr=GPIOA_BASE;
|
||
#if defined HY8612
|
||
if( ((parames[0]>>8)==CMD_ADDR) || ((parames[0]>>8)==CMD_READ_BACK) ) {
|
||
if(machine.dip_dis_combine)spb_tx.port_addr=GPIOA_BASE;
|
||
else spb_tx.port_addr=GPIOD_BASE;
|
||
}
|
||
#endif
|
||
|
||
p0_out=&ospb_di_short_0pos_outbuf[17];
|
||
p50_out=&ospb_di_short_50pos_outbuf[17];
|
||
for(i=0; i<parames_len; i++) {
|
||
CRC->CRC16DAT =parames[i]>>8;
|
||
CRC->CRC16DAT =parames[i]&0xff;
|
||
BMC_SAME_DATA(parames[i],p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
}
|
||
|
||
#endif
|
||
|
||
//datas
|
||
for(i=0; i<dlen; i++) {
|
||
CRC->CRC16DAT =data[i]>>8;
|
||
CRC->CRC16DAT =data[i]&0xff;
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
temp_data= tab_4b5b[data[i]&0xff] | (tab_4b5b[data[i]>>8]<<10);
|
||
#elif defined HY8608|| HY8612 || HY8108
|
||
temp_data=data[i];
|
||
#endif
|
||
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
}
|
||
|
||
|
||
//crc
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
temp_data= tab_4b5b[CRC->CRC16D&0xff] | (tab_4b5b[CRC->CRC16D>>8]<<10);
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
temp_data=CRC->CRC16D;
|
||
#endif
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
|
||
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
temp_data=0xd;
|
||
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,p0_out[data_pos-1],mask,5);
|
||
|
||
p0_out+=5,p50_out+=5;
|
||
data_pos+=5;
|
||
|
||
#endif
|
||
*(p0_out-1)=mask;
|
||
}
|
||
|
||
void PackDiShortCmdBuf2(uint16_t *parames,uint16_t parames_len,uint16_t *data,uint16_t dlen,uint16_t mask) {
|
||
uint8_t i=0;
|
||
int8_t j=0;
|
||
// uint16_t crc_calc=0;
|
||
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
uint32_t temp_data=0;
|
||
#elif defined HY8608|| HY8612 || HY8108
|
||
uint16_t temp_data=0;
|
||
#endif
|
||
|
||
uint16_t *p0_out;
|
||
uint16_t *p50_out;
|
||
|
||
//ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD>
|
||
CRC->CRC16D = 0xffff;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
|
||
p0_out=&ospb_di_short_0pos_outbuf[61];
|
||
p50_out=&ospb_di_short_50pos_outbuf[61];
|
||
|
||
CRC->CRC16DAT =parames[0]>>8;
|
||
CRC->CRC16DAT =parames[0]&0xff;
|
||
if(parames[0]==CMD_ADDR) {
|
||
temp_data=SOP_ADDR;
|
||
if(machine.dip_dis_combine)spb_tx.port_addr=GPIOA_BASE;
|
||
else spb_tx.port_addr=GPIOD_BASE;
|
||
}
|
||
else if(parames[0]==CMD_READ_BACK) {
|
||
temp_data=SOP_READ_BACK;
|
||
if(machine.dip_dis_combine)spb_tx.port_addr=GPIOA_BASE;
|
||
else spb_tx.port_addr=GPIOD_BASE;
|
||
}
|
||
else if(parames[0]==CMD_CONFIG) {temp_data=SOP_CONFIG; spb_tx.port_addr=GPIOA_BASE;}
|
||
else if(parames[0]==CMD_BROADCAST) {temp_data=SOP_BROADCAST; spb_tx.port_addr=GPIOA_BASE;}
|
||
else if(parames[0]==CMD_DIMMING) {temp_data=SOP_DIMMING; spb_tx.port_addr=GPIOA_BASE;}
|
||
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
|
||
|
||
|
||
|
||
|
||
for(i=1; i<parames_len; i++) {
|
||
CRC->CRC16DAT =parames[i]>>8;
|
||
CRC->CRC16DAT =parames[i]&0xff;
|
||
temp_data= tab_4b5b[parames[i]&0xff] | (tab_4b5b[parames[i]>>8]<<10);
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
|
||
}
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
|
||
spb_tx.port_addr=GPIOA_BASE;
|
||
#if defined HY8612
|
||
if( ((parames[0]>>8)==CMD_ADDR) || ((parames[0]>>8)==CMD_READ_BACK) ) {
|
||
if(machine.dip_dis_combine)spb_tx.port_addr=GPIOA_BASE;
|
||
else spb_tx.port_addr=GPIOD_BASE;
|
||
}
|
||
#endif
|
||
|
||
p0_out=&ospb_di_short_0pos_outbuf2[17];
|
||
p50_out=&ospb_di_short_50pos_outbuf2[17];
|
||
for(i=0; i<parames_len; i++) {
|
||
CRC->CRC16DAT =parames[i]>>8;
|
||
CRC->CRC16DAT =parames[i]&0xff;
|
||
BMC_SAME_DATA(parames[i],p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
}
|
||
|
||
#endif
|
||
|
||
//datas
|
||
for(i=0; i<dlen; i++) {
|
||
CRC->CRC16DAT =data[i]>>8;
|
||
CRC->CRC16DAT =data[i]&0xff;
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
temp_data= tab_4b5b[data[i]&0xff] | (tab_4b5b[data[i]>>8]<<10);
|
||
#elif defined HY8608|| HY8612 || HY8108
|
||
temp_data=data[i];
|
||
#endif
|
||
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
}
|
||
|
||
|
||
//crc
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
temp_data= tab_4b5b[CRC->CRC16D&0xff] | (tab_4b5b[CRC->CRC16D>>8]<<10);
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
temp_data=CRC->CRC16D;
|
||
#endif
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,*(p0_out-1),mask,BTI_WIDTH);
|
||
p0_out+=BTI_WIDTH,p50_out+=BTI_WIDTH;
|
||
|
||
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
temp_data=0xd;
|
||
|
||
BMC_SAME_DATA(temp_data,p0_out,p50_out,p0_out[data_pos-1],mask,5);
|
||
|
||
p0_out+=5,p50_out+=5;
|
||
data_pos+=5;
|
||
|
||
#endif
|
||
*(p0_out-1)=mask;
|
||
}
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
void PackDisBuf(uint16_t *parames,uint16_t parames_len,uint16_t dlen,uint32_t *outbuf) {
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
void PackDisBuf(uint16_t *parames,uint16_t parames_len,uint16_t dlen,uint16_t *outbuf) {
|
||
#endif
|
||
|
||
uint16_t i=0;
|
||
uint8_t index=0;
|
||
uint16_t out_index=0;
|
||
uint16_t temp=0;
|
||
|
||
//ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD>
|
||
CRC->CRC16D = 0xffff;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
outbuf[out_index++]=0x55555;
|
||
outbuf[out_index++]=0x55555;
|
||
outbuf[out_index++]=0x55555;
|
||
|
||
CRC->CRC16DAT =parames[0]>>8;
|
||
CRC->CRC16DAT =parames[0]&0xff;
|
||
if(parames[0]==CMD_ADDR) outbuf[out_index++]=SOP_ADDR;
|
||
else if(parames[0]==CMD_READ_BACK) outbuf[out_index++]=SOP_READ_BACK;
|
||
else if(parames[0]==CMD_CONFIG) outbuf[out_index++]=SOP_CONFIG;
|
||
else if(parames[0]==CMD_BROADCAST) outbuf[out_index++]=SOP_BROADCAST;
|
||
else if(parames[0]==CMD_DIMMING) outbuf[out_index++]=SOP_DIMMING;
|
||
index=1;
|
||
#elif defined HY8612 || HY8608 || HY8108
|
||
outbuf[out_index++]=0x5555;
|
||
memcpy(&outbuf[out_index],parames,parames_len*2);
|
||
index=0;
|
||
out_index+=parames_len;
|
||
// out_index+=dlen;
|
||
#endif
|
||
|
||
//frame head
|
||
for(i=index; i<parames_len; i++) {
|
||
CRC->CRC16DAT =parames[i]>>8;
|
||
CRC->CRC16DAT =parames[i]&0xff;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
outbuf[out_index++]=tab_4b5b[parames[i]&0xff] | (tab_4b5b[parames[i]>>8]<<10);
|
||
#endif
|
||
|
||
}
|
||
|
||
//data
|
||
for(i=0; i<dlen; i++) {
|
||
temp=outbuf[out_index];
|
||
CRC->CRC16DAT =temp>>8;
|
||
CRC->CRC16DAT =temp&0xff;
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
outbuf[out_index]=tab_4b5b[temp&0xff] | (tab_4b5b[temp>>8]<<10);
|
||
#endif
|
||
out_index++;
|
||
}
|
||
|
||
temp= CRC->CRC16D;
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
outbuf[out_index++]=tab_4b5b[temp&0xff] | (tab_4b5b[temp>>8]<<10);
|
||
outbuf[out_index]=0x68000;
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
outbuf[out_index]=temp;
|
||
#endif
|
||
|
||
}
|
||
|
||
//void AssembleDiOutBuf(uint16_t uwLen) {
|
||
|
||
// uint16_t i,j;
|
||
// uint16_t *p=(uint16_t *)&lane_outbuf[0];
|
||
// uint32_t *s[MAXDIP];
|
||
|
||
// uint8_t first_offset=0;
|
||
// uint8_t bit_offset=0;
|
||
|
||
//#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
// first_offset=208;
|
||
// bit_offset=52;
|
||
//#elif defined HY8612 || HY8608 || HY8108
|
||
// first_offset=128;
|
||
// bit_offset=32;
|
||
//#endif
|
||
|
||
|
||
// //ȡͷһbit<69><74>bit ram mappig
|
||
// for(i=0; i<MAXDIP; i++) {
|
||
// s[i]=(uint32_t *)(BITBAND((uint32_t )&lane_data[i].data[0],(BTI_WIDTH-1))-first_offset);
|
||
// }
|
||
//// s[0]=(uint32_t *)(BITBAND((uint32_t )&lane_data[0].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[1]=(uint32_t *)(BITBAND((uint32_t )&lane_data[1].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[2]=(uint32_t *)(BITBAND((uint32_t )&lane_data[2].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[3]=(uint32_t *)(BITBAND((uint32_t )&lane_data[3].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[4]=(uint32_t *)(BITBAND((uint32_t )&lane_data[4].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[5]=(uint32_t *)(BITBAND((uint32_t )&lane_data[5].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[6]=(uint32_t *)(BITBAND((uint32_t )&lane_data[6].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[7]=(uint32_t *)(BITBAND((uint32_t )&lane_data[7].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[8]=(uint32_t *)(BITBAND((uint32_t )&lane_data[8].data[0],(BTI_WIDTH-1))-first_offset);
|
||
//// s[9]=(uint32_t *)(BITBAND((uint32_t )&lane_data[9].data[0],(BTI_WIDTH-1))-first_offset);
|
||
|
||
// for(i=0; i<uwLen; i++) {
|
||
// if((i%BTI_WIDTH)==0) {
|
||
// for(j=0; j<MAXDIP; j++) {
|
||
// s[j]+=bit_offset;
|
||
//// s[0]+=bit_offset;
|
||
//// s[1]+=bit_offset;
|
||
//// s[2]+=bit_offset;
|
||
//// s[3]+=bit_offset;
|
||
//// s[4]+=bit_offset;
|
||
//// s[5]+=bit_offset;
|
||
//// s[6]+=bit_offset;
|
||
//// s[7]+=bit_offset;
|
||
//// s[8]+=bit_offset;
|
||
//// s[9]+=bit_offset;
|
||
// }
|
||
// }
|
||
|
||
// *p=0;
|
||
// for(j=0; j<MAXDIP; j++) {
|
||
// *p = (*s[j]<<machine.di_tab[j]) | (*p);
|
||
// }
|
||
//// *p= (*s[0]<<machine.di_tab[0]) |\
|
||
//// (*s[1]<<machine.di_tab[1]) |\
|
||
//// (*s[2]<<machine.di_tab[2]) |\
|
||
//// (*s[3]<<machine.di_tab[3]) |\
|
||
//// (*s[4]<<machine.di_tab[4]) |\
|
||
//// (*s[5]<<machine.di_tab[5]) |\
|
||
//// (*s[6]<<machine.di_tab[6]) |\
|
||
//// (*s[7]<<machine.di_tab[7]) ;
|
||
|
||
//// *p= (*s[0]<<machine.di_tab[0]) |\
|
||
//// (*s[1]<<machine.di_tab[1]) |\
|
||
//// (*s[2]<<machine.di_tab[2]) |\
|
||
//// (*s[3]<<machine.di_tab[3]) |\
|
||
//// (*s[4]<<machine.di_tab[4]) |\
|
||
//// (*s[5]<<machine.di_tab[5]) |\
|
||
//// (*s[6]<<machine.di_tab[6]) |\
|
||
//// (*s[7]<<machine.di_tab[7]) |\
|
||
//// (*s[8]<<machine.di_tab[8]) |\
|
||
//// (*s[9]<<machine.di_tab[9]) ;
|
||
// p++;
|
||
// for(j=0; j<MAXDIP; j++) {
|
||
// s[j]--;
|
||
// }
|
||
//// s[0]--; s[1]--; s[2]--; s[3]--; s[4]--;
|
||
//// s[5]--; s[6]--; s[7]--;
|
||
//// s[8]--; s[9]--;
|
||
|
||
// }
|
||
|
||
//}
|
||
|
||
void AssembleDiOutBuf(uint16_t uwLen) {
|
||
|
||
uint16_t i,j;
|
||
uint16_t *p=(uint16_t *)&lane_outbuf[0];
|
||
uint32_t *s[MAXDIP];
|
||
|
||
uint8_t first_offset=0;
|
||
uint8_t bit_offset=0;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
first_offset=208;
|
||
bit_offset=52;
|
||
#elif defined HY8612 || HY8608 || HY8108
|
||
first_offset=128;
|
||
bit_offset=32;
|
||
#endif
|
||
|
||
#if (MODEL_TYPE== A5H_85_28_16_448_HY8108 || MODEL_TYPE== A5HP_85_48_28_1344_HY8108)
|
||
//ȡͷһbit<69><74>bit ram mappig
|
||
s[0]=(uint32_t *)(BITBAND((uint32_t )&lane_data[0].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[1]=(uint32_t *)(BITBAND((uint32_t )&lane_data[1].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[2]=(uint32_t *)(BITBAND((uint32_t )&lane_data[2].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[3]=(uint32_t *)(BITBAND((uint32_t )&lane_data[3].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[4]=(uint32_t *)(BITBAND((uint32_t )&lane_data[4].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[5]=(uint32_t *)(BITBAND((uint32_t )&lane_data[5].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[6]=(uint32_t *)(BITBAND((uint32_t )&lane_data[6].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[7]=(uint32_t *)(BITBAND((uint32_t )&lane_data[7].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[8]=(uint32_t *)(BITBAND((uint32_t )&lane_data[8].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[9]=(uint32_t *)(BITBAND((uint32_t )&lane_data[9].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[10]=(uint32_t *)(BITBAND((uint32_t )&lane_data[10].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[11]=(uint32_t *)(BITBAND((uint32_t )&lane_data[11].data[0],(BTI_WIDTH-1))-first_offset);
|
||
|
||
for(i=0; i<uwLen; i++) {
|
||
if((i%BTI_WIDTH)==0) {
|
||
s[0]+=bit_offset;
|
||
s[1]+=bit_offset;
|
||
s[2]+=bit_offset;
|
||
s[3]+=bit_offset;
|
||
s[4]+=bit_offset;
|
||
s[5]+=bit_offset;
|
||
s[6]+=bit_offset;
|
||
s[7]+=bit_offset;
|
||
s[8]+=bit_offset;
|
||
s[9]+=bit_offset;
|
||
s[10]+=bit_offset;
|
||
s[11]+=bit_offset;
|
||
}
|
||
|
||
*p=0;
|
||
|
||
*p= (*s[0]<<machine.di_tab[0]) |\
|
||
(*s[1]<<machine.di_tab[1]) |\
|
||
(*s[2]<<machine.di_tab[2]) |\
|
||
(*s[3]<<machine.di_tab[3]) |\
|
||
(*s[4]<<machine.di_tab[4]) |\
|
||
(*s[5]<<machine.di_tab[5]) |\
|
||
(*s[6]<<machine.di_tab[6]) |\
|
||
(*s[7]<<machine.di_tab[7]) |\
|
||
(*s[8]<<machine.di_tab[8]) |\
|
||
(*s[9]<<machine.di_tab[9]) |\
|
||
(*s[10]<<machine.di_tab[10]) |\
|
||
(*s[11]<<machine.di_tab[11]) ;
|
||
p++;
|
||
|
||
s[0]--; s[1]--; s[2]--; s[3]--; s[4]--;
|
||
s[5]--; s[6]--; s[7]--;
|
||
s[8]--; s[9]--; s[10]--; s[11]--;
|
||
#elif (MODEL_TYPE== A5HP_65_40_22_880_HY8108)
|
||
//ȡͷһbit<69><74>bit ram mappig
|
||
s[0]=(uint32_t *)(BITBAND((uint32_t )&lane_data[0].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[1]=(uint32_t *)(BITBAND((uint32_t )&lane_data[1].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[2]=(uint32_t *)(BITBAND((uint32_t )&lane_data[2].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[3]=(uint32_t *)(BITBAND((uint32_t )&lane_data[3].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[4]=(uint32_t *)(BITBAND((uint32_t )&lane_data[4].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[5]=(uint32_t *)(BITBAND((uint32_t )&lane_data[5].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[6]=(uint32_t *)(BITBAND((uint32_t )&lane_data[6].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[7]=(uint32_t *)(BITBAND((uint32_t )&lane_data[7].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[8]=(uint32_t *)(BITBAND((uint32_t )&lane_data[8].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[9]=(uint32_t *)(BITBAND((uint32_t )&lane_data[9].data[0],(BTI_WIDTH-1))-first_offset);
|
||
|
||
for(i=0; i<uwLen; i++) {
|
||
if((i%BTI_WIDTH)==0) {
|
||
s[0]+=bit_offset;
|
||
s[1]+=bit_offset;
|
||
s[2]+=bit_offset;
|
||
s[3]+=bit_offset;
|
||
s[4]+=bit_offset;
|
||
s[5]+=bit_offset;
|
||
s[6]+=bit_offset;
|
||
s[7]+=bit_offset;
|
||
s[8]+=bit_offset;
|
||
s[9]+=bit_offset;
|
||
}
|
||
|
||
*p=0;
|
||
|
||
*p= (*s[0]<<machine.di_tab[0]) |\
|
||
(*s[1]<<machine.di_tab[1]) |\
|
||
(*s[2]<<machine.di_tab[2]) |\
|
||
(*s[3]<<machine.di_tab[3]) |\
|
||
(*s[4]<<machine.di_tab[4]) |\
|
||
(*s[5]<<machine.di_tab[5]) |\
|
||
(*s[6]<<machine.di_tab[6]) |\
|
||
(*s[7]<<machine.di_tab[7]) |\
|
||
(*s[8]<<machine.di_tab[8]) |\
|
||
(*s[9]<<machine.di_tab[9]) ;
|
||
p++;
|
||
|
||
s[0]--; s[1]--; s[2]--; s[3]--; s[4]--;
|
||
s[5]--; s[6]--; s[7]--;
|
||
s[8]--; s[9]--;
|
||
#elif (MODEL_TYPE== A5HP_75_44_24_1056_HY8108)
|
||
//ȡͷһbit<69><74>bit ram mappig
|
||
s[0]=(uint32_t *)(BITBAND((uint32_t )&lane_data[0].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[1]=(uint32_t *)(BITBAND((uint32_t )&lane_data[1].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[2]=(uint32_t *)(BITBAND((uint32_t )&lane_data[2].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[3]=(uint32_t *)(BITBAND((uint32_t )&lane_data[3].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[4]=(uint32_t *)(BITBAND((uint32_t )&lane_data[4].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[5]=(uint32_t *)(BITBAND((uint32_t )&lane_data[5].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[6]=(uint32_t *)(BITBAND((uint32_t )&lane_data[6].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[7]=(uint32_t *)(BITBAND((uint32_t )&lane_data[7].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[8]=(uint32_t *)(BITBAND((uint32_t )&lane_data[8].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[9]=(uint32_t *)(BITBAND((uint32_t )&lane_data[9].data[0],(BTI_WIDTH-1))-first_offset);
|
||
s[10]=(uint32_t *)(BITBAND((uint32_t )&lane_data[10].data[0],(BTI_WIDTH-1))-first_offset);
|
||
|
||
for(i=0; i<uwLen; i++) {
|
||
if((i%BTI_WIDTH)==0) {
|
||
s[0]+=bit_offset;
|
||
s[1]+=bit_offset;
|
||
s[2]+=bit_offset;
|
||
s[3]+=bit_offset;
|
||
s[4]+=bit_offset;
|
||
s[5]+=bit_offset;
|
||
s[6]+=bit_offset;
|
||
s[7]+=bit_offset;
|
||
s[8]+=bit_offset;
|
||
s[9]+=bit_offset;
|
||
s[10]+=bit_offset;
|
||
}
|
||
|
||
*p=0;
|
||
|
||
*p= (*s[0]<<machine.di_tab[0]) |\
|
||
(*s[1]<<machine.di_tab[1]) |\
|
||
(*s[2]<<machine.di_tab[2]) |\
|
||
(*s[3]<<machine.di_tab[3]) |\
|
||
(*s[4]<<machine.di_tab[4]) |\
|
||
(*s[5]<<machine.di_tab[5]) |\
|
||
(*s[6]<<machine.di_tab[6]) |\
|
||
(*s[7]<<machine.di_tab[7]) |\
|
||
(*s[8]<<machine.di_tab[8]) |\
|
||
(*s[9]<<machine.di_tab[9]) |\
|
||
(*s[10]<<machine.di_tab[10]) ;
|
||
p++;
|
||
|
||
s[0]--; s[1]--; s[2]--; s[3]--; s[4]--;
|
||
s[5]--; s[6]--; s[7]--;
|
||
s[8]--; s[9]--; s[10]--;
|
||
#endif
|
||
}
|
||
}
|
||
|
||
|
||
uint16_t LSB_Change(uint16_t value) {
|
||
uint8_t i=0;
|
||
uint16_t temp=0;
|
||
for(i=0; i<16; i++) {
|
||
temp<<=1;
|
||
if(value&(1<<i)) temp|=1;
|
||
|
||
}
|
||
return temp;
|
||
}
|
||
|
||
void Spb_ShortCmd(uint16_t head,uint16_t addr,uint16_t sub_addr,uint16_t *value) {
|
||
|
||
uint8_t i=0;
|
||
uint16_t parame[5]= {0};
|
||
uint8_t params_len=0;
|
||
volatile uint16_t slen=0;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
|
||
parame[0]=head; //sop
|
||
parame[1]=addr; //startaddr
|
||
params_len=2;
|
||
|
||
// memset(&ospb_di_short_cmd_outbuf[120],0,(200)*2);
|
||
|
||
#elif defined HY8612
|
||
parame[0]=head; //head
|
||
parame[1]=addr; //address
|
||
parame[2]=sub_addr; //subaddress
|
||
parame[3]=0x0000; //datalength
|
||
params_len=4;
|
||
|
||
// memset(&ospb_di_short_cmd_outbuf[32],0,(192)*2);
|
||
|
||
#elif defined HY8608 || HY8108
|
||
|
||
parame[0]=head; //head
|
||
parame[1]=LSB_Change(addr); //address
|
||
parame[2]=LSB_Change(sub_addr); //subaddress
|
||
parame[3]=ospb_frame.feedback; //feedback
|
||
parame[4]=LSB_Change((ospb_frame.next_commad_type)); //datalength
|
||
params_len=5;
|
||
|
||
// memset(&ospb_di_short_cmd_outbuf[32],0,(224)*2); //
|
||
#endif
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822 || HY8612
|
||
#if defined HY8612
|
||
if(((head>>8)==CMD_ADDR) || ((head>>8)==CMD_READ_BACK) ) { //DIS
|
||
#else
|
||
if((head==CMD_ADDR) || (head==CMD_READ_BACK) ) { //DIS
|
||
#endif
|
||
if(machine.dip_dis_combine) {
|
||
PackDiShortCmdBuf(parame,params_len,value,1,machine.di_mask);
|
||
}
|
||
else {
|
||
PackDiShortCmdBuf(parame,params_len,value,1,machine.dis_mask);
|
||
}
|
||
}
|
||
else { //DIP
|
||
PackDiShortCmdBuf(parame,params_len,value,1,machine.di_mask);
|
||
}
|
||
#elif defined HY8608 || HY8108
|
||
#if (MODEL_TYPE== A5H_85_28_16_448_HY8108)
|
||
if(((parame[0]&0xff00)>>8)==CMD_ADDR)
|
||
{
|
||
parame[1]=LSB_Change(((((addr&0xff00)>>8)-2)<<8)|(addr&0xff));
|
||
PackDiShortCmdBuf(parame,params_len,value,1,0x1ef);
|
||
|
||
memset(ospb_di_short_0pos_outbuf2,0,sizeof(ospb_di_short_0pos_outbuf2));
|
||
memset(ospb_di_short_50pos_outbuf2,0,sizeof(ospb_di_short_50pos_outbuf2));
|
||
parame[1]=LSB_Change(addr);
|
||
PackDiShortCmdBuf2(parame,params_len,value,1,0x9c00);
|
||
for(i=0;i<SHORT_CMD_PORTOUTBUFSIZE;i++)
|
||
{
|
||
ospb_di_short_0pos_outbuf[i] = ospb_di_short_0pos_outbuf[i] | ospb_di_short_0pos_outbuf2[i];
|
||
ospb_di_short_50pos_outbuf[i] = ospb_di_short_50pos_outbuf[i] | ospb_di_short_50pos_outbuf2[i];
|
||
}
|
||
}
|
||
else
|
||
{
|
||
PackDiShortCmdBuf(parame,params_len,value,1,machine.di_mask);
|
||
}
|
||
#else
|
||
PackDiShortCmdBuf(parame,params_len,value,1,machine.di_mask);
|
||
#endif
|
||
#endif
|
||
|
||
slen = BMC_BIT_LENGTH(1)+1;
|
||
|
||
Dis_Send_Shortcmd(slen,BLOCKING);
|
||
|
||
}
|
||
|
||
void Spb_cmd(uint16_t head,uint16_t addr,uint16_t sub_addr,uint16_t datas_len) {
|
||
|
||
uint8_t i=0;
|
||
uint16_t parame[5]= {0};
|
||
uint8_t params_len=0;
|
||
uint16_t slen=0;
|
||
|
||
// Systick_StartCount();
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
|
||
parame[0]=head; //sop
|
||
parame[1]=addr; //startaddr
|
||
params_len=2;
|
||
|
||
#elif defined HY8612
|
||
parame[0]=head; //head
|
||
parame[1]=addr; //address
|
||
parame[2]=sub_addr; //subaddress
|
||
parame[3]=(datas_len-1); //datalength
|
||
params_len=4;
|
||
|
||
#elif defined HY8608 || HY8108
|
||
parame[0]=head; //head
|
||
parame[1]=LSB_Change(addr); //address
|
||
parame[2]=LSB_Change(sub_addr); //subaddress
|
||
parame[3]=ospb_frame.feedback; //feedback
|
||
parame[4]=LSB_Change((ospb_frame.next_commad_type)|(datas_len-1)); //datalength
|
||
params_len=5;
|
||
#endif
|
||
// memset(&spb_dis_outbuf,0,sizeof(spb_dis_outbuf));
|
||
|
||
slen = BMC_BIT_LENGTH(datas_len);
|
||
for(i=0; i<machine.di_number; i++) {
|
||
PackDisBuf(parame,params_len,datas_len,lane_data[i].data);
|
||
}
|
||
|
||
AssembleDiOutBuf(slen);
|
||
|
||
// cnt=Systick_StopCount();
|
||
// printf("\tpack=:%d ms ,%d us\n",systick_ms,cnt);
|
||
|
||
Di_Send_Data(slen,BLOCKING);
|
||
|
||
}
|
||
|
||
void Spb_Address(uint8_t first_id,uint8_t last_id) {
|
||
|
||
uint16_t head;
|
||
uint16_t addr=0;
|
||
uint16_t value=0;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
|
||
head=CMD_ADDR;
|
||
addr=0x8000|(machine.pi_mode<<14)|first_id;
|
||
|
||
#elif defined HY8612
|
||
|
||
head=(CMD_ADDR<<8)| (machine.pi_mode<<7);
|
||
addr=(last_id<<8)|first_id;
|
||
|
||
#elif defined HY8608 || HY8108
|
||
|
||
head=(CMD_ADDR<<8)| (ospb_frame.dos_mode<<4) | 0xb0;
|
||
addr=(last_id<<8)|first_id;
|
||
|
||
#endif
|
||
while(spb_tx.status) {}
|
||
if(machine.dip_dis_combine)preamber_init(1);
|
||
else preamber_init(0);
|
||
Spb_ShortCmd(head,addr,0,&value);
|
||
|
||
}
|
||
|
||
void Spb_Readback(uint8_t reg,uint8_t id,uint8_t reg_num,uint8_t ic_num) {
|
||
uint16_t head;
|
||
uint16_t addr=0,subaddr=0;
|
||
uint16_t value=0;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
head=CMD_READ_BACK;
|
||
addr=0x8000|((reg&0x7f)<<8)|id;
|
||
#elif defined HY8612
|
||
head=(CMD_READ_BACK<<8);
|
||
addr=((ic_num-1)<<8)|id;
|
||
subaddr=((reg_num-1)<<8)|reg;
|
||
#elif defined HY8608 || HY8108
|
||
head=(CMD_READ_BACK<<8)| (ospb_frame.dos_mode<<4);
|
||
addr=((ic_num-1)<<8)|id;
|
||
subaddr=((reg_num-1)<<8)|reg;
|
||
|
||
#endif
|
||
while(spb_tx.status) {}
|
||
if(machine.dip_dis_combine)preamber_init(1);
|
||
else preamber_init(0);
|
||
Spb_ShortCmd(head,addr,subaddr,&value);
|
||
|
||
}
|
||
|
||
void Spb_Broadcast(uint8_t reg,uint16_t value,uint8_t head_L8){
|
||
|
||
uint16_t head;
|
||
uint16_t addr=0,subaddr=0;
|
||
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
head=CMD_BROADCAST;
|
||
addr=((reg&0x7f)<<8);
|
||
#elif defined HY8608 || HY8612 || HY8108
|
||
head=(CMD_BROADCAST<<8)| head_L8;
|
||
addr=0;
|
||
subaddr=reg;
|
||
#endif
|
||
while(spb_tx.status){}
|
||
preamber_init(1);
|
||
Spb_ShortCmd(head,addr,subaddr,&value);
|
||
|
||
}
|
||
|
||
void Spb_Config(uint8_t reg,uint8_t id,uint8_t reg_num,uint8_t ic_num,uint16_t datas_len) {
|
||
|
||
uint16_t head;
|
||
uint16_t addr=0,subaddr=0;
|
||
#if defined HY8810 || HY8602 || HY8811 || HY8603 || HY8822
|
||
head=CMD_CONFIG;
|
||
addr=(reg<<8)| id;
|
||
#elif defined HY8612
|
||
head=(CMD_CONFIG<<8);
|
||
addr=((ic_num-1)<<8)|id;
|
||
subaddr=((reg_num-1)<<8)|reg;
|
||
#elif defined HY8608 || HY8108
|
||
head=(CMD_CONFIG<<8)| (ospb_frame.dos_mode<<4);
|
||
addr=((ic_num-1)<<8)|id;
|
||
subaddr=((reg_num-1)<<8)|reg;
|
||
#endif
|
||
Spb_cmd(head,addr,subaddr,datas_len);
|
||
}
|
||
|
||
void Spb_Dimming(dimming_mode_t mode,dos_mode_t dos_mode,uint8_t id,uint8_t ic_num,uint16_t data_offset,uint16_t datas_len) {
|
||
uint16_t head;
|
||
uint16_t addr=0,subaddr=0;
|
||
#if defined HY8810 || HY8602
|
||
head=CMD_DIMMING;
|
||
addr= (mode<<12)| (dos_mode<<9) | id;
|
||
#elif defined HY8811 || HY8603 || HY8822
|
||
head=CMD_DIMMING;
|
||
addr= (mode<<12)| (dos_mode<<8) | id;
|
||
#elif defined HY8612
|
||
head=(CMD_DIMMING<<8)|(mode<<1);
|
||
addr=((ic_num-1)<<8)|id;
|
||
subaddr=0;
|
||
#elif defined HY8608 || HY8108
|
||
ospb_frame.dos_mode=dos_mode;
|
||
head=(CMD_DIMMING<<8)| (ospb_frame.dos_mode<<4)|(mode<<1)|(ospb_frame.effect);
|
||
addr=((ic_num-1)<<8)|id;
|
||
subaddr=data_offset;
|
||
#endif
|
||
Spb_cmd(head,addr,subaddr,datas_len);
|
||
}
|
||
|
||
void Spb_Lock(void)
|
||
{
|
||
uint16_t temp;
|
||
temp=0x5ac3;
|
||
Spb_Broadcast(0x78,temp,0);
|
||
}
|
||
|
||
void Spb_Unlock(void)
|
||
{
|
||
uint16_t temp;
|
||
temp=0xa5c9;
|
||
Spb_Broadcast(0x78,temp,0);
|
||
}
|
||
|
||
void Spb_Lock_REG58or5A(void)
|
||
{
|
||
uint16_t temp;
|
||
temp=0x5ac3;
|
||
Spb_Broadcast(0x7C,temp,0);
|
||
}
|
||
|
||
void Spb_Unlock_REG58or5A(void)
|
||
{
|
||
uint16_t temp;
|
||
temp=0xa5c9;
|
||
Spb_Broadcast(0x7C,temp,0);
|
||
}
|
||
|
||
|
||
|
||
#if defined HY8608 || HY8108
|
||
void update_frame_data(uint8_t dos_mode,uint16_t addr,uint16_t subaddr,uint16_t feedback) {
|
||
ospb_frame.dos_mode=dos_mode;
|
||
ospb_frame.address=addr;
|
||
ospb_frame.sub_addr=subaddr;
|
||
ospb_frame.feedback=feedback;
|
||
}
|
||
void update_frame_mode(uint8_t dos_mode,uint8_t dimming_mode,uint8_t effect,next_commad_type next_commad_type) {
|
||
ospb_frame.dos_mode=dos_mode;
|
||
ospb_frame.dimming_mode = dimming_mode;
|
||
ospb_frame.effect = effect;
|
||
ospb_frame.next_commad_type = next_commad_type;
|
||
}
|
||
#endif
|