/********************************************************************** **函数原型: WBAN_PRIMITIVE dataIndicationProcess() **入口参数: void **返 回 值: WBAN_PRIMITIVE **说 明: 当有数据到达PHY时,配置param.PL_DATA_indication ***********************************************************************/ WBAN_PRIMITIVE dataIndicationProcess(){ WORD j; SPI0_init(); spi0flash_cyclerx(fpga_buf); //输出的是从fpga接收来的16位01数据存放的数组:fpga_buf for(j = 0; j < FPGA_length - 1; j++){ fpga_buf[j] = fpga_buf[j + 1]; } fpga_buf[FPGA_length-1] = 0; FPGArxfun(fpga_buf); //输出的是将16位01转化成的复数数组:FPGArx(全局复数数组) /*printf("\n"); for(j=0;j<FPGA_length;j++) printf("%f+%fI ",FPGArx[j].re,FPGArx[j].im); printf("\n");*/ params.PL_DATA_indication.psduLength = PHYrx(FPGArx); //params.PL_DATA_indication.psduLength = mac_rxBufferlen; //测试用 params.PL_DATA_indication.psdu = mac_RxBuffer; #ifdef DEBUG1 printf("\n收到数据!将接收到的数据的Buffer的指针和长度赋值给\nPL_DATA_indication @dataIndicationProcess() @%ld\n", TickGet().Val); WORD i; BYTE* p; p = params.PL_DATA_indication.psdu; printf( "帧为:" ); for( i = 0; i < params.PL_DATA_indication.psduLength; i++ ) printf( "0x%x ", *(p++) ); printf("\n帧长为:%d\n", params.PL_DATA_indication.psduLength); #endif return PL_DATA_indication; }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { /* Main Program */ char state = 0; uint8_t buf[] = {0x5, 0xA, 0x3, 0x5A}; SysTick_Config(SystemCoreClock/100); /* Generate IRQ each ~10 ms */ LED_init(); /* LED Initialization */ SER_init(); /* UART#1 Initialization */ SPI0_init(); while (1) { /* Loop forever */ if (clock_1s) { clock_1s = 0; state++; if (state & 0x01) { LED_On(); sendchar('A'); sendchar('\n'); sendchar('\r'); SPI0_send(buf, 4); } else LED_Off(); } } }
/*------------------------------------------------------------------------------------------------------------*/ char VS10xx_INIT( void ) { // Steuerleitungen einrichten für MP3-Decoder POWER_DDR |= ( 1<<POWER ); RESET_DDR |= ( 1<<RESET ); BSYNC_DDR |= ( 1<<BSYNC ); DREQ_DDR &= ~( 1<<DREQ ); SS2_DDR |= ( 1<<SS2 ); // Steuerleitungen auf Startzustand setzen RESET_PORT |= ( 1<<RESET ); BSYNC_PORT &= ~( 1<<BSYNC ); DREQ_PORT &= ~( 1<<DREQ ); SS2_PORT |= ( 1<<SS2 ); SPI2_init(); // MP3-Decoder einschalten POWER_PORT |= ( 1<<POWER ); // 100ms warten bis Spannung stabil ist und Controller sie initialisiert hat CLOCK_delay( 1000 ); // reset the decoder CLOCK_delay(30); VS10xx_reset(HARD_RESET); CLOCK_delay(30); VS10xx_nulls(32); VS10xx_reset(SOFT_RESET); VS10xx_set_xtal (); // Wenn xtal nicht erfolgreich gesetzt ist REv.2 der Hardware vorhanden und muss per // HardwareSPI angesteuert werden if ( VS10xx_read( VS10xx_Register_CLOCKF ) != VS10xx_CLOCKF ) { hardwarespi=1; SPI0_init( SPI_HALF_SPEED ); // reset the decoder CLOCK_delay(30); if ( VS10xx_reset(HARD_RESET) == RESET_FAILED ) return( RESET_FAILED ); CLOCK_delay(30); VS10xx_nulls(32); if ( VS10xx_reset(SOFT_RESET) == RESET_FAILED ) return( RESET_FAILED ); VS10xx_set_xtal (); } // VS10xx_vol ( 200, 200 ); VS10xx_vol ( 255, 255 ); return( RESET_OK ); }
void initialize_hardware(){ sysclock_init(); LPC_MRT->Channel[0].CTRL=(1u<<1); //multi-rate timer canal 0 en mode 'one-shot interrupt' assign_pins(); // assignation des périphériques aux broches //LPC_SYSCON->IRQLATENCY=40; NVIC_SetPriority(SCT_IRQn,0); // plus haute priorité d'interruption NVIC_SetPriority(MRT_IRQn,3); // plus basse priorité PWM_init(); SPI0_init(); }//f()
/************************************************************************* * Function Name: MCU_init * Parameters: none * Return: none * Description: initialization of peripheral modules after reset *************************************************************************/ void MCU_init(void) { Clock_init(); ADC0_init(); PDB_init(); FTM0_init(); FTM1_init(); FTM2_init(); SPI0_init(); UART1_init(); GPIO_init(); MC33927_config(); }
void SPI_SetConfig(SpiConfigData_t* config) { uint8_t spiMode; csPin = config->CsPin; csPolarity = config->CsPolarity; switch(config->SpiMode) { case 0: spiMode = SPI0_CLKMODE_0; break; case 1: spiMode = SPI0_CLKMODE_1; break; case 2: spiMode = SPI0_CLKMODE_2; break; case 3: spiMode = SPI0_CLKMODE_3; break; } if(config->IsEnabled) { SFRPAGE = 0x20; SPI0CKR = config->CkrVal; SPI0_init(spiMode, true, false); SPI_Enable(); if(csPin != 0) { GPIO_MakeOutput(csPin, PushPullOutput); GPIO_WriteValue(csPin, !csPolarity); } } else SPI_Disable(); }
/********************************************************************** **函数原型: WBAN_PRIMITIVE PHYTasks(WBAN_PRIMITIVE inputPrimitive) **入口参数: WBAN_PRIMITIVE inputPrimitive **返 回 值: WBAN_PRIMITIVE **说 明: PHY层原语处理程序,根据不同的原语,作出相应的处理 ***********************************************************************/ WBAN_PRIMITIVE PHYTasks(WBAN_PRIMITIVE inputPrimitive) { BYTE temp[mac_PACKET_BUFFER_SIZE]; WORD i; BYTE* p; #ifdef DEBUG printf("\n数据传输至PHY层 @PHYTasks(...) @%ld\n", TickGet().Val); #endif #ifdef DEBUG1 p = params.PL_DATA_request.psdu; printf( "\n帧为:" ); for( i = 0; i < params.PL_DATA_request.psduLength; i++ ) printf( "0x%x ", *(p++) ); printf("\n帧长为:%d\n", params.PL_DATA_request.psduLength); #endif p = params.PL_DATA_request.psdu; for( i = 0; i < params.PL_DATA_request.psduLength; i++ ) temp[i] = *(p++); int mac_rate; switch( inputPrimitive ){ case PL_DATA_request: switch( params.PL_DATA_request.informationDataRate ){ case DATA_RATE_121_4: mac_rate = 121; break; case DATA_RATE_242_9: mac_rate = 242; break; case DATA_RATE_485_7: mac_rate = 485; break; case DATA_RATE_971_4: mac_rate = 971; break; default: ; } //接收参数为mac层数组,长度,速率,返回的是调制完的复数数组。传来的长度是整个psdu的字节数 //发送端没有用到全局的数组,用到了全局变量PLCP_Mod_len、PSDU_Mod_len PPDU_Mod = PHYtx( temp, params.PL_DATA_request.psduLength, mac_rate ); SPI0_init(); unsigned short *FPGAtx; FPGAtx = FPGAtxfun(PPDU_Mod, PLCP_Mod_len+PSDU_Mod_len); //里面free了ppdu_mod数组,动态开辟了FPGAtx数组 spi0flash_cycletx(FPGAtx,(PLCP_Mod_len+PSDU_Mod_len+3)/2); free(FPGAtx); FPGAtx=NULL; break; default: #ifdef DEBUG printf("\nWbanPHY.c PHYTasks() 找不到这个case\n"); #endif ; } if( (mac_currentPacket.frameType_Subtype & 0xF0) == mac_DATA_FRAME && mac_currentPacket.ackPolicy == mac_N_ACK && mac_currentPacket.non_finalFragment == FALSE){ params.MACS_DATA_confirm.RecipientID.v = mac_currentPacket.RecipientID.v; #ifdef I_AM_NODE params.MACS_DATA_confirm.TxDSN = macBIB.macTxDSN; #endif #ifdef I_AM_HUB params.MACS_DATA_confirm.TxDSN = macBIB.macTxDSN[getIndexFromNodeList(mac_currentPacket.RecipientID)]; #endif params.MACS_DATA_confirm.status = mac_SUCCESS; return MACS_DATA_confirm; } return NO_PRIMITIVE; }