void main() { task* TI1; task* TI2; char* Data; char* Encoded; register unsigned int i; _asm; di ld sp,#0xffff ld a,#0x0 ld bc,#0x0 ld de,#0x0 ld hl,#0x0 ld ix,#0x0 ld iy,#0x0 _endasm; _SimWriteProtect((void*)0x0000, (void*)0x3fff); _SimPrintString("\n-------------------\n"); _SimPrintString("System reset\n"); _SimPrintString("-------------------\n"); IntsOff(); _SimPrintString("Interrupts disabled. Booting...\n"); TestMemory(); HardwareInit(); LocksInit(); SchedulingInit(); SupervisorMode(); TimeInit(); SystemInit(); MemoryInit(); //KeyboardInit(); //TapeInit(); ConsoleInit(); ConsoleWrite("LJL OS 0.1 FOR ZX SPECTRUM 48\n"); ConsoleWrite("\nCONSOLE OUTPUT\n\n"); /* TapeSave((void*)0x4000, (void*)0x5800); TapeLoad((void*)0x4000, (void*)0x5800); for(i=0; i<0x4000; i+=0x100) { ConsoleWrite("."); SaveBlock((void*)i); } Halt("Saved"); */ MainEntry=Task1; TI1=CreateTask(MainEntry, 100); MainEntry=Task2; TI2=CreateTask(MainEntry, 100); ConsoleWrite("TASKS CREATED\n"); SetScheduler(DefaultScheduler); ConsoleWrite("SCHEDULER SET\n"); Resume(); //ConsoleWrite("RESUMING\n"); //if(!IsMultitasking()) Halt("NOT MULTITASKING"); for(;;); Halt("SYSTEM SHUTDOWN"); }
void arch_init(void) { static_assert(OPTION_MODULE_GET(embox__arch__system, NUMBER, core_freq) == 144000000); SystemInit(); }
/** * @brief Main Function */ int main() { /* Set Systme init */ SystemInit(); // *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz /* CLK OUT Set */ // PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function /* < SSP_StructInit default values SSP_InitStructure.SSP_SerialClockRate = 0x00; SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_MO; SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b; SSP_InitStructure.SSP_SOD = SSP_SOD_RESET; SSP_InitStructure.SSP_Mode = SSP_Mode_Master; SSP_InitStructure.SSP_NSS = SSP_NSS_Hard; SSP_InitStructure.SSP_LBM = SSP_LBM_RESET; SSP_InitStructure.SSP_SSE = SSP_SSE_SET; SSP_InitStructure.SSP_BaudRatePrescaler = SSP_BaudRatePrescaler_2; */ /* SSP0 Init -- SSP Master */ SSP_StructInit(&SSP0_InitStructure); SSP0_InitStructure.SSP_FrameFormat = SSP_FrameFormat_MO; // Motorora SPI mode SSP0_InitStructure.SSP_DataSize = SSP_DataSize_16b; SSP_Init(SSP0,&SSP0_InitStructure); /* SSP1 Init -- SSP Slave */ SSP_StructInit(&SSP1_InitStructure); SSP1_InitStructure.SSP_DataSize = SSP_DataSize_16b; SSP1_InitStructure.SSP_Mode = SSP_Mode_Slave; // SSP1 = Slave SSP_Init(SSP1,&SSP1_InitStructure); /* GPIO LED(R) Setting */ GPIO_InitDef.GPIO_Pin = GPIO_Pin_8; // Connecting GPIO_Pin_8(LED(R)) GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC PAD_AFConfig(PAD_PC,GPIO_Pin_8, PAD_AF1); // PAD Config - LED used 2nd Function /* GPIO LED(G) Setting */ GPIO_InitDef.GPIO_Pin = GPIO_Pin_9; // Connecting GPIO_Pin_9(LED(G)) GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC PAD_AFConfig(PAD_PC,GPIO_Pin_9, PAD_AF1); // PAD Config - LED used 2nd Function GPIO_SetBits(GPIOC, GPIO_Pin_8); // LED red off GPIO_SetBits(GPIOC, GPIO_Pin_9); // LED green off /* Send only data to SSP1 */ for (TxIdx=0; TxIdx<BufferSize; TxIdx++) { SSP_SendData(SSP0, SSP0_Buffer_Tx[TxIdx]); while( SSP_GetFlagStatus(SSP0, SSP_FLAG_BSY) ); } /* Receive only data from SSP0 */ while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RNE)) { SSP1_Buffer_Rx[RxIdx] = (uint16_t)SSP_ReceiveData(SSP1); RxIdx++; } /* Check the received data with the send ones */ TransferStatus = Buffercmp(SSP0_Buffer_Tx, SSP1_Buffer_Rx, BufferSize); /* TransferStatus = PASSED, if the data transmitted and received are correct */ /* TransferStatus = FAILED, if the data transmitted and received are different */ if(TransferStatus == PASSED) { GPIO_ResetBits(GPIOC, GPIO_Pin_9); //Received are correct == LED green On } else if(TransferStatus == FAILED) { GPIO_ResetBits(GPIOC, GPIO_Pin_8); //Received are different == LED red On } }
__weak void Reset_Handler(void) { SystemInit(); __iar_program_start(); }
/** * @brief Configures the different system clocks. * @param None * @retval None */ void RCC_Configuration(void) { /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); }
int main(void) { SystemInit(); STM32F4_Discovery_LEDInit(LED3); //Orange STM32F4_Discovery_LEDInit(LED4); //Green STM32F4_Discovery_LEDInit(LED5); //Red STM32F4_Discovery_LEDInit(LED6); //Blue STM32F4_Discovery_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); USBD_Init(&USB_OTG_dev,USB_OTG_FS_CORE_ID,&USR_desc,&USBD_CDC_cb,&USR_cb); SystemCoreClockUpdate(); // inicjalizacja dystrybucji czasu procesora init_I2C1(); // na podstawie: http://eliaselectronics.com/stm32f4-tutorials/stm32f4-i2c-mastertutorial/ //acc I2C_start(I2C1, LSM303DL_A_ADDRESS, I2C_Direction_Transmitter); I2C_write(I2C1,0x20); // LSM303_CTRL_REG1_A 0x20 I2C_write(I2C1,0x27); // Enable Accelerometer // 0x27 = 0b00100111 // Normal power mode, all axes enabled I2C_stop(I2C1); // stop the transmission //acc //mag I2C_start(I2C1, LSM303DL_M_ADDRESS, I2C_Direction_Transmitter); I2C_write(I2C1,0x02); //LSM303_MR_REG_M 0x02 I2C_write(I2C1,0x00); // Enable Magnetometer // 0x00 = 0b00000000 // Continuous conversion mode I2C_stop(I2C1); //mag //gyro I2C_start(I2C1, LSM303DL_G_ADDRESS, I2C_Direction_Transmitter); I2C_write(I2C1, 0x20); //L3G_CTRL_REG1 0x20 I2C_write(I2C1, 0x0F); // 0x0F = 0b00001111 // Normal power mode, all axes enabled I2C_stop(I2C1); //gyro char start='0'; while(1) { Delay(5); read_acc(); read_mag(); read_gyro(); start='0'; while(1) { start = usb_cdc_getc(); if(start=='1') { break; } } } /*while (1){ if(usb_cdc_kbhit()){ char c, buffer_out[15]; c = usb_cdc_getc(); switch(c){ case '3': STM32F4_Discovery_LEDToggle(LED3); sprintf(buffer_out,"LED%c = %u\r\n",c,GPIO_ReadInputDataBit(GPIOD,LED3_PIN)); usb_cdc_printf(buffer_out); break; case '4': STM32F4_Discovery_LEDToggle(LED4); sprintf(buffer_out,"LED%c = %u\r\n",c,GPIO_ReadInputDataBit(GPIOD,LED4_PIN)); usb_cdc_printf(buffer_out); break; case '5': STM32F4_Discovery_LEDToggle(LED5); sprintf(buffer_out,"LED%c = %u\r\n",c,GPIO_ReadInputDataBit(GPIOD,LED5_PIN)); usb_cdc_printf(buffer_out); break; case '6': STM32F4_Discovery_LEDToggle(LED6); sprintf(buffer_out,"LED%c = %u\r\n",c,GPIO_ReadInputDataBit(GPIOD,LED6_PIN)); usb_cdc_printf(buffer_out); break; } } button_sts = STM32F4_Discovery_PBGetState(BUTTON_USER); if(button_sts){ STM32F4_Discovery_LEDOff(LED3); STM32F4_Discovery_LEDOff(LED5); STM32F4_Discovery_LEDOff(LED3); STM32F4_Discovery_LEDOff(LED5); } }*/ }
/** * @brief Main program * @param None * @retval None */ int main() { //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 }; //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 }; uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x71, 0x72, 0x77}; uint8_t src_addr[4] = {192, 168, 1, 98}; uint8_t gw_addr[4] = {192, 168, 1, 1}; uint8_t sub_addr[4] = {255, 255, 255, 0}; uint8_t tmp[8]; uint8_t i; /* External Clock */ //CRG_PLL_InputFrequencySelect(CRG_OCLK); /* Set Systme init */ SystemInit(); /* UART0 and UART1 configuration*/ //UART_StructInit(&UART_InitStructure); /* Configure UART1 */ //UART_Init(UART1,&UART_InitStructure); S_UART_Init(115200); /* SysTick_Config */ SysTick_Config((GetSystemClock()/1000)); /* LED configuration */ GPIO_Setting(); /* Set WZ_100US Register */ setTIC100US((GetSystemClock()/10000)); //getTIC100US(); //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", // GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US); #ifdef __DEF_USED_IC101AG__ //For using IC+101AG *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up *(volatile uint32_t *)(0x41003050) = 0x64; //TXE - set PAD strengh and pull-up #endif #ifdef __W7500P__ *(volatile uint32_t *)(0x41003070) = 0x61; *(volatile uint32_t *)(0x41003054) = 0x61; #endif #ifdef __DEF_USED_MDIO__ /* mdio Init */ mdio_init(GPIOB, MDC, MDIO ); /* PHY Link Check via gpio mdio */ while( link() == 0x0 ) { printf("."); delay(500); } printf("PHY is linked. \r\n"); #else delay(1000); #endif /* Network Configuration (Default setting) */ setSHAR(mac_addr); setSIPR(src_addr); setGAR(gw_addr); setSUBR(sub_addr); getSHAR(tmp); printf("MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); getSIPR(tmp); printf("IP ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); getGAR(tmp); printf("GW ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); getSUBR(tmp); printf("SN MASK: %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); /* Set Network Configuration */ //wizchip_init(tx_size, rx_size); /* HTTP Server Initialization */ httpServer_init(TX_BUF, RX_BUF, MAX_HTTPSOCK, socknumlist); // Tx/Rx buffers (1kB) reg_httpServer_cbfunc(NVIC_SystemReset, NULL); // Callback: MCU Reset { /* Web content registration (web content in webpage.h, Example web pages) */ // Index page and netinfo / base64 image demo reg_httpServer_webContent((uint8_t *)"index.html", (uint8_t *)index_page); // index.html : Main page example reg_httpServer_webContent((uint8_t *)"netinfo.html", (uint8_t *)netinfo_page); // netinfo.html : Network information example page reg_httpServer_webContent((uint8_t *)"netinfo.js", (uint8_t *)WIZwiki_W7500_web_netinfo_js); // netinfo.js : JavaScript for Read Network configuration (+ ajax.js) //reg_httpServer_webContent((uint8_t *)"img.html", (uint8_t *)img_page); // img.html : Base64 Image data example page // Example #1 reg_httpServer_webContent((uint8_t *)"dio.html", (uint8_t *)dio_page); // dio.html : Digital I/O control example page reg_httpServer_webContent((uint8_t *)"dio.js", (uint8_t *)WIZwiki_W7500_web_dio_js); // dio.js : JavaScript for digital I/O control (+ ajax.js) // Example #2 //reg_httpServer_webContent((uint8_t *)"ain.html", (uint8_t *)ain_page); // ain.html : Analog input monitor example page //reg_httpServer_webContent((uint8_t *)"ain.js", (uint8_t *)WIZwiki_W7500_web_ain_js); // ain.js : JavaScript for Analog input monitor (+ ajax.js) // Example #3 //reg_httpServer_webContent((uint8_t *)"ain_gauge.html", (uint8_t *)ain_gauge_page); // ain_gauge.html : Analog input monitor example page; using Google Gauge chart //reg_httpServer_webContent((uint8_t *)"ain_gauge.js", (uint8_t *)ain_gauge_js); // ain_gauge.js : JavaScript for Google Gauge chart (+ ajax.js) // AJAX JavaScript functions reg_httpServer_webContent((uint8_t *)"ajax.js", (uint8_t *)WIZwiki_W7500_web_ajax_js); // ajax.js : JavaScript for AJAX request transfer #ifdef _MAIN_DEBUG_ display_reg_webContent_list(); #endif } /* Main loop ***************************************/ while(1) { // TODO: insert user's code here for(i = 0; i < MAX_HTTPSOCK; i++) httpServer_run(i); // HTTP Server handler loopback_tcps(SOCK_TCPS, RX_BUF, 5000); } // End of Main loop }
/** * @brief Main program * @param None * @retval None */ int main() { //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 }; //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 }; uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x71, 0x72, 0x77}; uint8_t src_addr[4] = {192, 168, 77, 9}; uint8_t gw_addr[4] = {192, 168, 77, 1}; uint8_t sub_addr[4] = {255, 255, 255, 0}; //uint8_t dns_server[4] = {8, 8, 8, 8}; // for Example domain name server uint8_t tmp[8]; uint32_t toggle = 1; /* External Clock */ //CRG_PLL_InputFrequencySelect(CRG_OCLK); /* Set Systme init */ SystemInit(); /* UART0 and UART1 configuration*/ //UART_StructInit(&UART_InitStructure); /* Configure UART0 */ //UART_Init(UART1,&UART_InitStructure); S_UART_Init(115200); /* SysTick_Config */ SysTick_Config((GetSystemClock()/1000)); /* Set WZ_100US Register */ setTIC100US((GetSystemClock()/10000)); //getTIC100US(); //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", // GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US); #ifdef __DEF_USED_IC101AG__ //For using IC+101AG *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up *(volatile uint32_t *)(0x41003050) = 0x64; //TXE - set PAD strengh and pull-up #endif #ifdef __W7500P__ *(volatile uint32_t *)(0x41003070) = 0x61; *(volatile uint32_t *)(0x41003054) = 0x61; #endif #ifdef __DEF_USED_MDIO__ /* mdio Init */ mdio_init(GPIOB, MDC, MDIO ); //mdio_error_check(GPIOB, MDC, MDIO); //need verify... /* PHY Link Check via gpio mdio */ while( link() == 0x0 ) { printf("."); delay(500); } printf("PHY is linked. \r\n"); #else delay(1000); #endif /* Network Configuration (Default setting) */ setSHAR(mac_addr); setSIPR(src_addr); setGAR(gw_addr); setSUBR(sub_addr); getSHAR(tmp); printf("MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); getSIPR(tmp); printf("IP ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); getGAR(tmp); printf("GW ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); getSUBR(tmp); printf("SN MASK: %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); /* Set Network Configuration */ //wizchip_init(tx_size, rx_size); /* DHCP client Initialization */ DHCP_init(SOCK_DHCP, test_buf); /* DHCP IP allocation and check the DHCP lease time (for IP renewal) */ while(1) { switch(DHCP_run()) { case DHCP_IP_ASSIGN: case DHCP_IP_CHANGED: /* If this block empty, act with default_ip_assign & default_ip_update */ // // This example calls the registered 'my_ip_assign' in the two case. // // Add to ... // // toggle = 1; if(toggle) { getSIPR(tmp); printf("> DHCP IP : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); getGAR(tmp); printf("> DHCP GW : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); getSUBR(tmp); printf("> DHCP SN : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); toggle = 0; close(SOCK_TCPS); /* If renewal IP address was defferent previous IP address, socket becomes to disconnect or close for new connection. */ } break; case DHCP_IP_LEASED: // if(toggle) { getSIPR(tmp); printf("> DHCP IP : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); getGAR(tmp); printf("> DHCP GW : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); getSUBR(tmp); printf("> DHCP SN : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]); toggle = 0; } // TO DO YOUR NETWORK APPs. loopback_tcps(SOCK_TCPS, test_buf, 5000); break; case DHCP_FAILED: /* ===== Example pseudo code ===== */ // The below code can be replaced your code or omitted. // if omitted, retry to process DHCP my_dhcp_retry++; if(my_dhcp_retry > MY_MAX_DHCP_RETRY) { #if DEBUG_MODE != DEBUG_NO printf(">> DHCP %d Failed\r\n",my_dhcp_retry); #endif my_dhcp_retry = 0; DHCP_stop(); // if restart, recall DHCP_init() } break; default: break; } } }
/** * @brief Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources. * @param None * @retval None */ void System_Setup(void) { RCC_ClocksTypeDef RCC_Clocks; /* Setup STM32 clock, PLL and Flash configuration) */ SystemInit(); /* Enable USART2 clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* Enable ETHERNET clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx | RCC_AHBPeriph_ETH_MAC_Rx, ENABLE); /* Enable GPIOs and ADC1 clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1, ENABLE); /* NVIC configuration */ NVIC_Configuration(); /* ADC configuration */ ADC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Initialize the STM3210C-EVAL's LCD */ STM3210C_LCD_Init(); /* Initialize STM3210C-EVAL's LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Turn on leds available on STM3210X-EVAL */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* Clear the LCD */ LCD_Clear(Blue); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Display message on the LCD*/ LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); LCD_DisplayStringLine(Line3, MESSAGE4); /* Configure the Ethernet peripheral */ Ethernet_Configuration(); /* SystTick configuration: an interrupt every 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100); /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */ /* The Localtime should be updated during the Ethernet packets processing */ NVIC_SetPriority (SysTick_IRQn, 1); /* Configure the Key button */ STM_EVAL_PBInit(Button_KEY, Mode_GPIO); }
int main(void) { uint8_t i; /* Initialize system */ SystemInit(); /* Delay init */ TM_DELAY_Init(); /* Initialize GPS on 115200 baudrate */ TM_GPS_Init(&GPS_Data, 115200); /* Initialize USART2 for debug */ /* TX = PA2 */ TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200); /* Register custom GPGxx statements */ /* $GPRMC statement, term number 7 = Speed over ground in knots */ GPRMC = TM_GPS_AddCustom(&GPS_Data, "$GPRMC", 7); /* $GPGLL statement, term number 1 = Current latitude */ GPGLL = TM_GPS_AddCustom(&GPS_Data, "$GPGLL", 1); /* $GPGSA statement, term number 1 = M = Manual, forced to operate in 2D or 3D A=Automatic, 3D/2D */ GPGSA = TM_GPS_AddCustom(&GPS_Data, "$GPGSA", 1); /* Add here more custom tags you want */ /* ... */ /* Reset counter */ TM_DELAY_SetTime(0); while (1) { /* Update GPR data */ /* Call this as faster as possible */ result = TM_GPS_Update(&GPS_Data); /* If we have any unread data */ if (result == TM_GPS_Result_NewData) { /* We received new packet of useful data from GPS */ current = TM_GPS_Result_NewData; /* Is GPS signal valid? */ if (GPS_Data.Validity) { /* If you want to make a GPS tracker, now is the time to save your data on SD card */ /* We have valid GPS signal */ printf("New received data have valid GPS signal\n"); printf("---------------------------------------\n"); /* We have all data from GPS_Data structure valid, you can do here what you want */ /* We will in this example show only custom data to user */ /* Print custom statements */ printf("Custom statements defined by user:\n"); /* Go through all custom statements */ for (i = 0; i < GPS_Data.CustomStatementsCount; i++) { printf(" - Statement: %s; TermNumber: %d; Value: %s\n", GPS_Data.CustomStatements[i]->Statement, /*!< Statement value */ GPS_Data.CustomStatements[i]->TermNumber, /*!< Term number */ GPS_Data.CustomStatements[i]->Value /*!< Value from GPS receiver */ ); } /* You can do it this way too for all your custom statements separatelly */ printf(" - Statement2: %s; TermNumber: %d; Value: %s\n", GPRMC->Statement, GPRMC->TermNumber, GPRMC->Value ); printf("---------------------------------------\n"); } else { /* GPS signal is not valid */ printf("New received data haven't valid GPS signal!\n"); } } else if (result == TM_GPS_Result_FirstDataWaiting && current != TM_GPS_Result_FirstDataWaiting) { current = TM_GPS_Result_FirstDataWaiting; printf("Waiting first data from GPS!\n"); } else if (result == TM_GPS_Result_OldData && current != TM_GPS_Result_OldData) { current = TM_GPS_Result_OldData; /* We already read data, nothing new was received from GPS */ } } }
/*! * @brief Initializes the clock. * * Initializes the microprocessor clock if needed. * As with __cpuInitHardware() the developer may implement this * initialization elsewhere. Called from __systemInit(). * * @return Nothing. */ __STATIC __VOID __cpuInitClock(__VOID) { SystemInit(); }
int main(void) { /* Test Git */ GPIO_InitTypeDef GPIO_InitStructure; RCC_ClocksTypeDef RCC_ClockFreq; uint32_t i=0; SystemInit(); /* This function fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) **************/ RCC_GetClocksFreq(&RCC_ClockFreq); /* Output HSE clock on MCO1 pin(PA8) ****************************************/ /* Enable the GPIOA peripheral */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* Configure MCO1 pin(PA8) in alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* HSE clock selected to output on MCO1 pin(PA8)*/ RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1); /* Output SYS clock on MCO2 pin(Pc9) ****************************************/ /* Enable the GPIOC peripheral */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* Configure MCO1 pin(PA8) in alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* HSE clock selected to output on MCO1 pin(PC9)*/ RCC_MCO2Config(RCC_MCO2Source_SYSCLK, RCC_MCO2Div_1); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); while(1) { GPIOD->BSRRH = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIOD->BSRRL = GPIO_Pin_12; for(i=0;i<1000000;i++); GPIOD->BSRRH = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIOD->BSRRL = GPIO_Pin_13; for(i=0;i<1000000;i++); GPIOD->BSRRH = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIOD->BSRRL = GPIO_Pin_14; for(i=0;i<1000000;i++); GPIOD->BSRRH = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIOD->BSRRL = GPIO_Pin_15; for(i=0;i<1000000;i++); } }
void main(void) { ENTR_CRT_SECTION(); /* Setup STM32 system (clock, PLL and Flash configuration) */ SystemInit(); /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); // I2C1 init I2C1_Init(); EXT_CRT_SECTION(); // GLCD init GLCD_PowerUpInit(0x0); //( GLCD_Backlight(BACKLIGHT_ON); GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0); GLCD_SetWindow(10,10,131,131); // Init Accl sensor if(FALSE == Accl_Init()) { // Initialization fault GLCD_TextSetPos(0,0); GLCD_print("\fLIS3LV020 Init.\r\nfault\r\n"); while(1); } //Init CarControl and Delay Car_Init(); DWT_Init(); HCSR04_Init(); // SysTick end of count event each 0.5s with input clock equal to 9MHz (HCLK/8, default) SysTick_Config(150000); SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); DWT_Delayms(1000); while(1) { //while(1){GLCD_print("Current state: %d \r",GPIO_ReadInputDataBit(JS_LEFT_PORT, JS_LEFT_MASK));} //car_feedback=accl_feedback(); /* A = accX[1]; B = velX[1]; C = posX[1]; */ if(SysTickF1) { SysTickF1 = FALSE; //GLCD_TextSetPos(0,0); GLCD_print("%d, %d \r", get_Xvel(), accl_feedback()); DWT_Delayms(500); } if(NewInstr) // { DWT_Delayms(1000); NewInstr = FALSE; //GoCar(Test, TestTurn); // 1. Give command (desired state) //desiredState; // 2. Run machine learning to test action action = goToState(car_instr); GoCars(action); // testExp(); int runTime = 0; while (runTime < 1){ DWT_Delayms(700); runTime++; } GLCD_TextSetPos(0,0); GLCD_print("\f%d,%d;%d,%d\r\n", get_X_accFeedback(0), get_Y_accFeedback(0), get_X_vel(0), get_Y_vel(0)); GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(1), get_Y_accFeedback(1), get_X_vel(1), get_Y_vel(1)); GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(2), get_Y_accFeedback(2), get_X_vel(2), get_Y_vel(2)); GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(3), get_Y_accFeedback(3), get_X_vel(3), get_Y_vel(3)); GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(4), get_Y_accFeedback(4), get_X_vel(4), get_Y_vel(4)); GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(5), get_Y_accFeedback(5), get_X_vel(5), get_Y_vel(5)); GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(6), get_Y_accFeedback(6), get_X_vel(6), get_Y_vel(6)); // GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(7), get_Y_accFeedback(7), get_X_vel(7), get_Y_vel(7)); car_instr=car_stop; GoCars(car_instr); DWT_Delayms(2000); } //GoCars(3); //Stopping the car // 3. Wait x ms //Wait in ML-method testAllActions // 4. Return value from accelerometer //Return value from accelerometer in ML-method testAllActions // 5. Evaluate action compared to state //Already implemented in ML-file. No need to alter (probably) // 6. Repeat 3-5 until all actions has been tested //Already implemented in ML-file. No need to alter (probably) // 7. Choose the correct state //Already implemented in ML-file. No need to alter (probably) } }
void ResetISR(void) { #ifndef USE_OLD_STYLE_DATA_BSS_INIT // // Copy the data sections from flash to SRAM. // unsigned int LoadAddr, ExeAddr, SectionLen; unsigned int *SectionTableAddr; // Load base address of Global Section Table SectionTableAddr = &__data_section_table; // Copy the data sections from flash to SRAM. while (SectionTableAddr < &__data_section_table_end) { LoadAddr = *SectionTableAddr++; ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; data_init(LoadAddr, ExeAddr, SectionLen); } // At this point, SectionTableAddr = &__bss_section_table; // Zero fill the bss segment while (SectionTableAddr < &__bss_section_table_end) { ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; bss_init(ExeAddr, SectionLen); } #else // Use Old Style Data and BSS section initialization. // This will only initialize a single RAM bank. unsigned int * LoadAddr, *ExeAddr, *EndAddr, SectionLen; // Copy the data segment from flash to SRAM. LoadAddr = &_etext; ExeAddr = &_data; EndAddr = &_edata; SectionLen = (void*)EndAddr - (void*)ExeAddr; data_init((unsigned int)LoadAddr, (unsigned int)ExeAddr, SectionLen); // Zero fill the bss segment ExeAddr = &_bss; EndAddr = &_ebss; SectionLen = (void*)EndAddr - (void*)ExeAddr; bss_init ((unsigned int)ExeAddr, SectionLen); #endif #ifdef __USE_CMSIS SystemInit(); #endif #if defined (__cplusplus) // // Call C++ library initialisation // __libc_init_array(); #endif #if defined (__REDLIB__) // Call the Redlib library, which in turn calls main() __main() ; #else main(); #endif // // main() shouldn't return, but if it does, we'll just enter an infinite loop // while (1) { ; } }
int main(void) { uint32_t data_counter=0; //used as data timestamp uint8_t deadly_flashes=0,system_state=0,repetition_counter=0; int16_t sensor_data, sensor_raw_data[3]={}; //used for handling data passed back from sensors int16_t sfe_sensor_ref_buff[2][3],sfe_sensor_ref_buff_old[2][3];//used to detect and fix I2C bus lockup RTC_t RTC_time; wave_stuffer Gyro_wav_stuffer={0,0},Accel_wav_stuffer={0,0};//Used to controlling wav file bit packing SystemInit(); //Sets up the clk setup_gpio(); //Initialised pins, and detects boot source DBGMCU_Config(DBGMCU_IWDG_STOP, ENABLE); //Watchdog stopped during JTAG halt if(RCC->CSR&RCC_CSR_IWDGRSTF) { //Watchdog reset, turn off RCC->CSR|=RCC_CSR_RMVF; //Reset the reset flags shutdown(); } SysTick_Configuration(); //Start up system timer at 100Hz for uSD card functionality Watchdog_Config(WATCHDOG_TIMEOUT); //Set the watchdog Watchdog_Reset(); //Reset watchdog as soon as possible incase it is still running at power on rtc_init(); //Real time clock initialise - (keeps time unchanged if set) Usarts_Init(); ISR_Config(); rprintfInit(__usart_send_char); //Printf over the bluetooth if(USB_SOURCE==bootsource) { Set_System(); //This actually just inits the storage layer Set_USBClock(); USB_Interrupts_Config(); USB_Init(); uint32_t nojack=0x000FFFFF; //Countdown timer - a few hundered ms of 0v on jack detect forces a shutdown while (bDeviceState != CONFIGURED) { //Wait for USB config - timeout causes shutdown if(Millis>10000 || !nojack) //No USB cable - shutdown (Charger pin will be set to open drain, cant be disabled without usb) shutdown(); if(GET_CHRG_STATE) //Jack detect resets the countdown nojack=0x0FFFFF; nojack--; Watchdog_Reset(); //Reset watchdog here, if we are stalled here the Millis timeout should catch us } USB_Configured_LED(); EXTI_ONOFF_EN(); //Enable the off interrupt - allow some time for debouncing while(1) { //If running off USB (mounted as mass storage), stay in this loop - dont turn on anything if(Millis%1000>500) //1Hz on/off flashing switch_leds_on(); //Flash the LED(s) else switch_leds_off(); Watchdog_Reset(); __WFI(); //Sleep until something arrives } } else { if(!GET_PWR_STATE) //Check here to make sure the power button is still pressed, if not, sleep shutdown(); //This means a glitch on the supply line, or a power glitch results in sleep EXTI_ONOFF_EN(); //Enable the off interrupt - allow some time for debouncing ADC_Configuration(); //At present this is purely here to detect low battery do { battery_voltage=Battery_Voltage;//Have to flush adc for some reason Delay(25000); } while(fabs(Battery_Voltage-battery_voltage)>0.01 || !battery_voltage); I2C_Config(); //Setup the I2C bus Sensors=detect_sensors(0); //Search for connected sensors if(battery_voltage<BATTERY_STARTUP_LIMIT) deadly_flashes=1; if(!(Sensors&(1<<FOREHEAD_ACCEL))) //Check for any missing sensors deadly_flashes=2; if(!(Sensors&(1<<(FOREHEAD_GYRO-1)))) deadly_flashes=3; if(!(Sensors&(1<<(SFE_1_ACCEL-1)))) deadly_flashes=4; if(!(Sensors&(1<<(SFE_1_MAGNO-1)))) deadly_flashes=5; if(!(Sensors&(1<<(SFE_1_GYRO-1)))) deadly_flashes=6; if(!(Sensors&(1<<(SFE_2_ACCEL-3)))) deadly_flashes=7; if(!(Sensors&(1<<(SFE_2_MAGNO-3)))) deadly_flashes=8; if(!(Sensors&(1<<(SFE_2_GYRO-3)))) deadly_flashes=9; if((f_err_code = f_mount(0, &FATFS_Obj)))Usart_Send_Str((char*)"FatFs mount error\r\n");//This should only error if internal error else if(!deadly_flashes){ //FATFS and the I2C initialised ok, try init the card, this also sets up the SPI1 if(!f_open(&FATFS_logfile,"time.txt",FA_OPEN_EXISTING | FA_READ | FA_WRITE)) {//Try and open a time file to get the system time if(!f_stat((const TCHAR *)"time.txt",&FATFS_info)) {//Get file info if(!FATFS_info.fsize) {//Empty file RTC_time.year=(FATFS_info.fdate>>9)+1980;//populate the time struct (FAT start==1980, RTC.year==0) RTC_time.month=(FATFS_info.fdate>>5)&0x000F; RTC_time.mday=FATFS_info.fdate&0x001F; RTC_time.hour=(FATFS_info.ftime>>11)&0x001F; RTC_time.min=(FATFS_info.ftime>>5)&0x003F; RTC_time.sec=(FATFS_info.ftime<<1)&0x003E; rtc_settime(&RTC_time); rprintfInit(__fat_print_char);//printf to the open file printf("RTC set to %d/%d/%d %d:%d:%d\n",RTC_time.mday,RTC_time.month,RTC_time.year,\ RTC_time.hour,RTC_time.min,RTC_time.sec); } } f_close(&FATFS_logfile);//Close the time.txt file } rtc_gettime(&RTC_time); //Get the RTC time and put a timestamp on the start of the file rprintfInit(__str_print_char); //Print to the string //timestamp name printf("%d-%02d-%02dT%02d-%02d-%02d",RTC_time.year,RTC_time.month,RTC_time.mday,RTC_time.hour,RTC_time.min,RTC_time.sec); rprintfInit(__usart_send_char); //Printf over the bluetooth f_err_code = f_mkdir(print_string); //Try to make a directory where the logfiles will live if(f_err_code) { printf("FatFs drive error %d\r\n",f_err_code); if(f_err_code==FR_DISK_ERR || f_err_code==FR_NOT_READY) Usart_Send_Str((char*)"No uSD card inserted?\r\n"); repetition_counter=1; } else f_err_code=f_chdir(print_string);//enter our new directory if(f_err_code) { if(!repetition_counter) printf("FatFs drive error entering direcotry %d\r\n",f_err_code); repetition_counter=1; } else { strcat(print_string,".csv"); f_err_code=f_open(&FATFS_logfile,print_string,FA_CREATE_ALWAYS | FA_WRITE);//Try to open the main 100sps csv logfile } if(f_err_code) { if(!repetition_counter) printf("FatFs drive error creating logfile %d\r\n",f_err_code); repetition_counter=1; } else { print_string[strlen(print_string)-4]=0x00; //Wipe the .csv off the string strcat(print_string,"_accel.wav"); f_err_code=f_open(&FATFS_wavfile_accel,print_string,FA_CREATE_ALWAYS | FA_WRITE);//Try to open the accel wav logfile } if(f_err_code) { if(!repetition_counter) printf("FatFs drive error creating accel wav file %d\r\n",f_err_code); repetition_counter=1; } else { print_string[strlen(print_string)-9]=0x00; //Wipe the accel.wav off the string strcat(print_string,"gyro.wav"); f_err_code=f_open(&FATFS_wavfile_gyro,print_string,FA_CREATE_ALWAYS | FA_WRITE);//Try to open the gyro wav logfile } if(f_err_code) { if(!repetition_counter) printf("FatFs drive error creating gyro wav file %d\r\n",f_err_code); } else { //We have a mounted card print_string[0]=0x00; //Wipe the string f_err_code=f_lseek(&FATFS_logfile, PRE_SIZE);// Pre-allocate clusters if (f_err_code || f_tell(&FATFS_logfile) != PRE_SIZE)// Check if the file size has been increased correctly Usart_Send_Str((char*)"Pre-Allocation error\r\n"); else { if((f_err_code=f_lseek(&FATFS_logfile, 0)))//Seek back to start of file to start writing Usart_Send_Str((char*)"Seek error\r\n"); else rprintfInit(__str_print_char);//Printf to the logfile } if(f_err_code) f_close(&FATFS_logfile);//Close the already opened file on error else file_opened=0x01;//So we know to close the file properly on shutdown - bit mask for the files if(!f_err_code) { f_err_code=f_lseek(&FATFS_wavfile_accel, PRE_SIZE);// Pre-allocate clusters if (f_err_code || f_tell(&FATFS_wavfile_accel) != PRE_SIZE)// Check if the file size has been increased correctly Usart_Send_Str((char*)"Pre-Allocation error\r\n"); else { if((f_err_code=f_lseek(&FATFS_wavfile_accel, 0)))//Seek back to start of file to start writing Usart_Send_Str((char*)"Seek error\r\n"); } if(f_err_code) f_close(&FATFS_wavfile_accel);//Close the already opened file on error else file_opened|=0x02;//So we know to close the file properly on shutdown - bit mask for the files } if(!f_err_code) { f_err_code=f_lseek(&FATFS_wavfile_gyro, PRE_SIZE);// Pre-allocate clusters if (f_err_code || f_tell(&FATFS_wavfile_gyro) != PRE_SIZE)// Check if the file size has been increased correctly Usart_Send_Str((char*)"Pre-Allocation error\r\n"); else { if((f_err_code=f_lseek(&FATFS_wavfile_gyro, 0)))//Seek back to start of file to start writing Usart_Send_Str((char*)"Seek error\r\n"); } if(f_err_code) f_close(&FATFS_wavfile_gyro);//Close the already opened file on error else file_opened|=0x04;//So we know to close the file properly on shutdown - bit mask for the files } } } repetition_counter=0; //Reset this here //We die, but flash out a number of flashes first if(f_err_code || deadly_flashes) { //There was an init error for(;deadly_flashes;deadly_flashes--) { RED_LED_ON; Delay(200000); RED_LED_OFF; Delay(200000); Watchdog_Reset(); } RED_LED_ON; Delay(400000); shutdown(); //Abort after a (further )single red flash } }
int main(void) { int accelData[3]; int analogData[BUFFER]; int i=0; for(i=0;i<BUFFER;i++){ analogData[i]=0; } int a = 0; int analogIn = 0; int analogMin, analogMax; /* Initialize system */ SystemInit(); /* Initialize delay */ //TM_DELAY_Init(); /* Initialize PG13 (GREEN LED) and PG14 (RED LED) */ TM_GPIO_Init(GPIOG, GPIO_PIN_13 | GPIO_PIN_14, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast); TM_GPIO_SetPinValue(GPIOG, GPIO_PIN_14, 1); // Red: ON #ifdef ENABLE_USART /* Initialize USART1 at 115200 baud, TX: PA10, RX: PA9 */ TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200); #endif #ifdef ENABLE_VCP /* Initialize USB Virtual Comm Port */ TM_USB_VCP_Result status = TM_USB_VCP_NOT_CONNECTED; while (TM_USB_VCP_GetStatus() != TM_USB_VCP_CONNECTED) { TM_USB_VCP_Init(); TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14); Delay(500000); } SendString("USB VCP initialized and connected\n"); TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14 | GPIO_PIN_13); // Red: OFF, Gr: ON #endif #ifdef ENABLE_MMA /* Initialize MMA845X */ uint8_t mma_status = MMA845X_Initialize(MMA_RANGE_4G); if (mma_status == MMA_OK) { SendString("MMA initialized\n"); } else { SendString("MMA initialization failed, error code: "); // Add 48 to the byte value to have character representation, (48 = '0') SendChar('0'+mma_status); SendChar('\n'); } #endif /* Initialize Display */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_1); TM_ILI9341_SetLayer1(); TM_ILI9341_Fill(ILI9341_COLOR_BLACK); /* Fill data on layer 1 */ /* Initialize ADC1 */ TM_ADC_Init(CURRENT_ADC, CURRENT_CH); /* Initialize PE2 and PE3 for digital output (Motor direction) */ TM_GPIO_Init(GPIOE, GPIO_PIN_2 | GPIO_PIN_3, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast); // Set them to HIGH/LOW TM_GPIO_SetPinHigh(GPIOE, GPIO_PIN_3); TM_GPIO_SetPinLow(GPIOE, GPIO_PIN_2); #ifdef ENABLE_PWM /* Set up PE5 (in front of PE4) for PWM (TIM9 CH1 PP2) (Motor speed control) */ TM_PWM_TIM_t TIM9_Data; // Set PWM to 1kHz frequency on timer TIM4, 1 kHz = 1ms = 1000us TM_PWM_InitTimer(TIM9, &TIM9_Data, 1000); // Initialize PWM on TIM9, Channel 1 and PinsPack 2 = PE5 TM_PWM_InitChannel(&TIM9_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2); // Set channel 1 value, 50% duty cycle TM_PWM_SetChannelPercent(&TIM9_Data, TM_PWM_Channel_1, 50); #endif /* Initialize DAC channel 2, pin PA5 (Shaker control) */ //TM_DAC_Init(TM_DAC2); /* Set 12bit analog value of 2047/4096 * 3.3V */ //TM_DAC_SetValue(TM_DAC2, 4096); #ifdef ENABLE_DAC // DAC PIN PA5 /* Initialize DAC1, use TIM4 for signal generation */ TM_DAC_SIGNAL_Init(TM_DAC2, TIM4); /* Output predefined triangle signal with frequency of 5kHz */ TM_DAC_SIGNAL_SetSignal(TM_DAC2, TM_DAC_SIGNAL_Signal_Sinus, 50); #endif /* MAIN LOOP */ while (1) { // Read acceleration data #ifdef ENABLE_MMA MMA845X_ReadAcceleration(accelData); #endif // Read analog input analogData[a] = TM_ADC_Read(CURRENT_ADC, CURRENT_CH); a++; if(a==BUFFER) {a=0;} // Analog average analogIn=0; analogMax=0; analogMin=4096; for(i=0;i<BUFFER;i++){ if(analogData[i] > analogMax) { analogMax = analogData[i]; } if(analogData[i] < analogMin) { analogMin = analogData[i]; } analogIn+=analogData[i]; } analogIn/=BUFFER; // Print graphs printGraphsLCD(accelData, analogData[a], analogIn, analogMin, analogMax); // Toggle Green led TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_13); } }
int main(void) { SystemInit(); GPIOInit(); FLASH_Unlock(); EE_Init(); USBD_Init(&USB_OTG_dev, #ifdef USE_USB_OTG_HS USB_OTG_HS_CORE_ID, #else USB_OTG_FS_CORE_ID, #endif &USR_desc, &USBD_HID_cb, &USR_cb); bitCount = 0; currentValue = 0; set = 0; ignoreNext = 0; uppercaseNext = 0; shiftPressed = 0; buttonPressed = 0; getHowMany(); int i = 0; resetBuffer(); for(;;) { /* * Po wcisnieciu przycisku nastepuje wyslanie raportu USB * zawierajacego rejestr przycisnietych klaiwszy */ if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) { if (!buttonPressed) { buttonPressed = 1; for (i = 0; i < 64; i++) { EE_ReadVariable(VirtAddVarTab[i], &InBuffer[i]); } USBD_HID_SendReport (&USB_OTG_dev, InBuffer, 64); } } else if (buttonPressed) { buttonPressed = 0; } if (checkBufferReady()) { /* * Jezeli zapisano 64 wcisniecia klawiszy, * nalezy oproznic EEPROM przed kontynuacja zapisu * */ if(EEPROMFull()) { GPIO_ToggleBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); continue; } unsetBufferReady(); startTimer(); EE_WriteVariable(VirtAddVarTab[howMany=howMany+0x01], currentChar); EE_WriteVariable(VirtAddVarTab[63], howMany); } } }
//***************************************************************************** // Reset entry point for your code. // Sets up a simple runtime environment and initializes the C/C++ // library. // //***************************************************************************** void ResetISR(void) { // ************************************************************* // The following conditional block of code manually resets as // much of the peripheral set of the LPC43 as possible. This is // done because the LPC43 does not provide a means of triggering // a full system reset under debugger control, which can cause // problems in certain circumstances when debugging. // // You can prevent this code block being included if you require // (for example when creating a final executable which you will // not debug) by setting the define 'DONT_RESET_ON_RESTART'. // #ifndef DONT_RESET_ON_RESTART // Disable interrupts __asm volatile ("cpsid i"); // equivalent to CMSIS '__disable_irq()' function unsigned int *RESET_CONTROL = (unsigned int *) 0x40053100; // LPC_RGU->RESET_CTRL0 @ 0x40053100 // LPC_RGU->RESET_CTRL1 @ 0x40053104 // Note that we do not use the CMSIS register access mechanism, // as there is no guarantee that the project has been configured // to use CMSIS. // Write to LPC_RGU->RESET_CTRL0 *(RESET_CONTROL + 0) = 0x10DF1000; // GPIO_RST|AES_RST|ETHERNET_RST|SDIO_RST|DMA_RST| // USB1_RST|USB0_RST|LCD_RST|M0_SUB_RST // Write to LPC_RGU->RESET_CTRL1 *(RESET_CONTROL + 1) = 0x01DFF7FF; // M0APP_RST|CAN0_RST|CAN1_RST|I2S_RST|SSP1_RST|SSP0_RST| // I2C1_RST|I2C0_RST|UART3_RST|UART1_RST|UART1_RST|UART0_RST| // DAC_RST|ADC1_RST|ADC0_RST|QEI_RST|MOTOCONPWM_RST|SCT_RST| // RITIMER_RST|TIMER3_RST|TIMER2_RST|TIMER1_RST|TIMER0_RST // Clear all pending interrupts in the NVIC volatile unsigned int *NVIC_ICPR = (unsigned int *) 0xE000E280; unsigned int irqpendloop; for (irqpendloop = 0; irqpendloop < 8; irqpendloop++) { *(NVIC_ICPR + irqpendloop) = 0xFFFFFFFF; } // Reenable interrupts __asm volatile ("cpsie i"); // equivalent to CMSIS '__enable_irq()' function #endif // ifndef DONT_RESET_ON_RESTART // ************************************************************* #if defined (__USE_LPCOPEN) SystemInit(); #endif // // Copy the data sections from flash to SRAM. // unsigned int LoadAddr, ExeAddr, SectionLen; unsigned int *SectionTableAddr; // Load base address of Global Section Table SectionTableAddr = &__data_section_table; // Copy the data sections from flash to SRAM. while (SectionTableAddr < &__data_section_table_end) { LoadAddr = *SectionTableAddr++; ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; data_init(LoadAddr, ExeAddr, SectionLen); } // At this point, SectionTableAddr = &__bss_section_table; // Zero fill the bss segment while (SectionTableAddr < &__bss_section_table_end) { ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; bss_init(ExeAddr, SectionLen); } #if !defined (__USE_LPCOPEN) // LPCOpen init code deals with FP and VTOR initialisation #if defined (__VFP_FP__) && !defined (__SOFTFP__) /* * Code to enable the Cortex-M4 FPU only included * if appropriate build options have been selected. * Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C) */ // CPACR is located at address 0xE000ED88 asm("LDR.W R0, =0xE000ED88"); // Read CPACR asm("LDR R1, [R0]"); // Set bits 20-23 to enable CP10 and CP11 coprocessors asm(" ORR R1, R1, #(0xF << 20)"); // Write back the modified value to the CPACR asm("STR R1, [R0]"); #endif // (__VFP_FP__) && !(__SOFTFP__) // ****************************** // Check to see if we are running the code from a non-zero // address (eg RAM, external flash), in which case we need // to modify the VTOR register to tell the CPU that the // vector table is located at a non-0x0 address. // Note that we do not use the CMSIS register access mechanism, // as there is no guarantee that the project has been configured // to use CMSIS. unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08; if ((unsigned int *) g_pfnVectors != (unsigned int *) 0x00000000) { // CMSIS : SCB->VTOR = <address of vector table> *pSCB_VTOR = (unsigned int) g_pfnVectors; } #endif #if defined (__USE_CMSIS) SystemInit(); #endif #if defined (__cplusplus) // // Call C++ library initialisation // __libc_init_array(); #endif #if defined (__REDLIB__) // Call the Redlib library, which in turn calls main() __main(); #else main(); #endif // // main() shouldn't return, but if it does, we'll just enter an infinite loop // while (1) { ; } }
void ResetISR(void) { // // Copy the data sections from flash to SRAM. // unsigned int LoadAddr, ExeAddr, SectionLen; unsigned int *SectionTableAddr; // Load base address of Global Section Table SectionTableAddr = &__data_section_table; // Copy the data sections from flash to SRAM. while (SectionTableAddr < &__data_section_table_end) { LoadAddr = *SectionTableAddr++; ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; data_init(LoadAddr, ExeAddr, SectionLen); } // At this point, SectionTableAddr = &__bss_section_table; // Zero fill the bss segment while (SectionTableAddr < &__bss_section_table_end) { ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; bss_init(ExeAddr, SectionLen); } // Patch the AEABI integer divide functions to use MCU's romdivide library #ifdef __USE_ROMDIVIDE // Get address of Integer division routines function table in ROM unsigned int *div_ptr = (unsigned int *)((unsigned int *)*(PTR_ROM_DRIVER_TABLE))[4]; // Get addresses of integer divide routines in ROM // These address are then used by the code in aeabi_romdiv_patch.s pDivRom_idiv = (unsigned int *)div_ptr[0]; pDivRom_uidiv = (unsigned int *)div_ptr[1]; #endif #if defined (__USE_CMSIS) || defined (__USE_LPCOPEN) SystemInit(); #endif #if defined (__cplusplus) // // Call C++ library initialisation // __libc_init_array(); #endif #if defined (__REDLIB__) // Call the Redlib library, which in turn calls main() __main() ; #else main(); #endif // // main() shouldn't return, but if it does, we'll just enter an infinite loop // while (1) { ; } }
/******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ static void RCC_Configuration(void) { SystemInit(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); }
void RMC_DEMO(void) { TSB_RMC_TypeDef *RMCx; RMC_InitTypeDef myRMC; RMCx = TSB_RMC0; RMC_Command = 0U; SystemInit(); RMC_Configuration(RMCx); /*RMC IO initial */ __disable_irq(); TSB_CG->IMCGE = 0x00300000U; TSB_CG->ICRCG = 0x00000012U; TSB_CG->IMCGE = 0x00310000U; #ifdef TOSHIBA_FORMAT_RMC /*RMC register set for TOSHIBA format */ myRMC.LeaderPara.MaxCycle = RMC_MAX_CYCLE; myRMC.LeaderPara.MinCycle = RMC_MIN_CYCLE; myRMC.LeaderPara.MaxLowWidth = RMC_MAX_LOW_WIDTH; myRMC.LeaderPara.MinLowWidth = RMC_MIN_LOW_WIDTH; myRMC.LeaderPara.LeaderDetectionState = ENABLE; myRMC.LeaderPara.LeaderINTState = DISABLE; myRMC.FallingEdgeINTState = DISABLE; myRMC.SignalRxMethod = RMC_RX_IN_CYCLE_METHOD; myRMC.LowWidth = RMC_TRG_LOW_WIDTH; myRMC.MaxDataBitCycle = RMC_TRG_MAX_DATA_BIT_CYCLE; myRMC.LargerThreshold = RMC_LARGER_THRESHOLD; myRMC.SmallerThreshold = RMC_SMALLER_THRESHOLD; myRMC.InputSignalReversedState = DISABLE; myRMC.NoiseCancellationTime = RMC_NOISE_CANCELLATION_TIME; #endif #ifdef RC5_FORMAT_RMC /*RMC register set for RC5 format */ myRMC.LeaderPara.MaxCycle = RMC_MAX_CYCLE; myRMC.LeaderPara.MinCycle = RMC_MIN_CYCLE; myRMC.LeaderPara.MaxLowWidth = RMC_MAX_LOW_WIDTH; myRMC.LeaderPara.MinLowWidth = RMC_MIN_LOW_WIDTH; myRMC.LeaderPara.LeaderDetectionState = DISABLE; myRMC.LeaderPara.LeaderINTState = DISABLE; myRMC.FallingEdgeINTState = DISABLE; myRMC.SignalRxMethod = RMC_RX_IN_PHASE_METHOD; myRMC.LowWidth = RMC_TRG_LOW_WIDTH; myRMC.MaxDataBitCycle = RMC_TRG_MAX_DATA_BIT_CYCLE; myRMC.LargerThreshold = RMC_LARGER_THRESHOLD; myRMC.SmallerThreshold = RMC_SMALLER_THRESHOLD; myRMC.InputSignalReversedState = ENABLE; myRMC.NoiseCancellationTime = RMC_NOISE_CANCELLATION_TIME; #endif /* Enable and config the function for RMC channel */ RMC_Enable(RMCx); RMC_Init(RMCx, &myRMC); /* RMC Reception enable */ RMC_SetRxCtrl(RMCx, ENABLE); /* Enable the Receive interrupt for RMC channel */ /* RMC0 should to enable INTRMCRX0_IRQn, RMC1 should to enable INTRMCRX1_IRQn. */ NVIC_EnableIRQ(INTRMCRX0_IRQn); __enable_irq(); do { if (fRMCRx) { sprintf(message, "RMC DATA: 0x%x\n", RMC_Command ); UART_Print(UART, message); /*printf RMC read data */ fRMCRx = None; } } while (1); }
/*---------------------------------------------------------------------------- Reset Handler called on controller reset *----------------------------------------------------------------------------*/ void Reset_Handler(void) { uint32_t *pSrc, *pDest; uint32_t *pTable __attribute__((unused)); /* Firstly it copies data from read only memory to RAM. There are two schemes * to copy. One can copy more than one sections. Another can only copy * one section. The former scheme needs more instructions and read-only * data to implement than the latter. * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */ #ifdef __STARTUP_COPY_MULTIPLE /* Multiple sections scheme. * * Between symbol address __copy_table_start__ and __copy_table_end__, * there are array of triplets, each of which specify: * offset 0: LMA of start of a section to copy from * offset 4: VMA of start of a section to copy to * offset 8: size of the section to copy. Must be multiply of 4 * * All addresses must be aligned to 4 bytes boundary. */ pTable = &__copy_table_start__; for (; pTable < &__copy_table_end__; pTable = pTable + 3) { pSrc = (uint32_t*)*(pTable + 0); pDest = (uint32_t*)*(pTable + 1); for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; ) { *pDest++ = *pSrc++; } } #else /* Single section scheme. * * The ranges of copy from/to are specified by following symbols * __etext: LMA of start of the section to copy from. Usually end of text * __data_start__: VMA of start of the section to copy to * __data_end__: VMA of end of the section to copy to * * All addresses must be aligned to 4 bytes boundary. */ pSrc = &__etext; pDest = &__data_start__; for ( ; pDest < &__data_end__ ; ) { *pDest++ = *pSrc++; } #endif /*__STARTUP_COPY_MULTIPLE */ /* This part of work usually is done in C library startup code. Otherwise, * define this macro to enable it in this startup. * * There are two schemes too. One can clear multiple BSS sections. Another * can only clear one section. The former is more size expensive than the * latter. * * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former. * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later. */ #ifdef __STARTUP_CLEAR_BSS_MULTIPLE /* Multiple sections scheme. * * Between symbol address __copy_table_start__ and __copy_table_end__, * there are array of tuples specifying: * offset 0: Start of a BSS section * offset 4: Size of this BSS section. Must be multiply of 4 */ pTable = &__zero_table_start__; for (; pTable < &__zero_table_end__; pTable = pTable + 2) { pDest = (uint32_t*)*(pTable + 0); for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; ) { *pDest++ = 0; } } #elif defined (__STARTUP_CLEAR_BSS) /* Single BSS section scheme. * * The BSS section is specified by following symbols * __bss_start__: start of the BSS section. * __bss_end__: end of the BSS section. * * Both addresses must be aligned to 4 bytes boundary. */ pDest = &__bss_start__; for ( ; pDest < &__bss_end__ ; ) { *pDest++ = 0ul; } #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */ #ifndef __NO_SYSTEM_INIT SystemInit(); #endif #ifndef __START #define __START _start #endif __START(); }
/************************************************************************************//** ** \brief Initializes the microcontroller. ** \return none. ** ****************************************************************************************/ static void Init(void) { GPIO_InitTypeDef GPIO_InitStructure; #if (BOOT_COM_UART_ENABLE > 0) #elif (BOOT_FILE_SYS_ENABLE > 0) USART_InitTypeDef USART_InitStructure; #endif /* initialize the system and its clocks */ SystemInit(); /* initialize the button as a digital input. is used to override the starting of * the user program. */ /* enable the GPIO Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* configure the GPIO pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); #if (BOOT_COM_UART_ENABLE > 0) /* enable UART peripheral clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); /* enable GPIO peripheral clock for transmitter and receiver pins */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* connect the pin to the peripherals alternate function */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); /* configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOC, &GPIO_InitStructure); #elif (BOOT_FILE_SYS_ENABLE > 0) /* enable UART peripheral clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); /* enable GPIO peripheral clock for transmitter and receiver pins */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* connect the pin to the peripherals alternate function */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); /* configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOC, &GPIO_InitStructure); /* initialize the uart for the specified communication speed */ USART_InitStructure.USART_BaudRate = BOOT_COM_UART_BAUDRATE; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART6, &USART_InitStructure); /* enable UART */ USART_Cmd(USART6, ENABLE); #endif #if (BOOT_COM_CAN_ENABLE > 0) /* enable clocks for CAN2 transmitter and receiver pins */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* select alternate function for the CAN2 pins */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_CAN2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_CAN2); /* configure CAN2 RX and TX pins */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /* enable CAN clock. Note that CAN2 shares reception filters with CAN1 so for CAN2 * the CAN1 peripheral also needs to be enabled. */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2 | RCC_APB1Periph_CAN1, ENABLE); #endif } /*** end of Init ***/
/******************************************************************************* ** Main Function main() *******************************************************************************/ int main (void) { uint32_t i; SystemInit(); if ( I2CInit( (uint32_t)I2CMASTER ) == FALSE ) /* initialize I2c */ { while ( 1 ); /* Fatal error */ } /* In order to start the I2CEngine, the all the parameters must be set in advance, including I2CWriteLength, I2CReadLength, I2CCmd, and the I2cMasterBuffer which contains the stream command/data to the I2c slave device. (1) If it's a I2C write only, the number of bytes to be written is I2CWriteLength, I2CReadLength is zero, the content will be filled in the I2CMasterBuffer. (2) If it's a I2C read only, the number of bytes to be read is I2CReadLength, I2CWriteLength is 0, the read value will be filled in the I2CMasterBuffer. (3) If it's a I2C Write/Read with repeated start, specify the I2CWriteLength, fill the content of bytes to be written in I2CMasterBuffer, specify the I2CReadLength, after the repeated start and the device address with RD bit set, the content of the reading will be filled in I2CMasterBuffer index at I2CMasterBuffer[I2CWriteLength+2]. e.g. Start, DevAddr(W), WRByte1...WRByteN, Repeated-Start, DevAddr(R), RDByte1...RDByteN Stop. The content of the reading will be filled after (I2CWriteLength + two devaddr) bytes. */ /* Write SLA(W), address and one data byte */ I2CWriteLength = 6; I2CReadLength = 0; I2CMasterBuffer[0] = PCF8594_ADDR; I2CMasterBuffer[1] = 0x00; /* address */ I2CMasterBuffer[2] = 0x55; /* Data0 */ I2CMasterBuffer[3] = 0xAA; /* Data1 */ I2CMasterBuffer[4] = 0x12; /* Data0 */ I2CMasterBuffer[5] = 0x34; /* Data1 */ I2CEngine(); /* Be careful with below fixed delay. From device to device, or even same device with different write length, or various I2C clock, below delay length may need to be changed accordingly. Having a break point before Write/Read start will be helpful to isolate the problem. */ for ( i = 0; i < 0x200000; i++ ); /* Delay after write */ for ( i = 0; i < BUFSIZE; i++ ) { I2CSlaveBuffer[i] = 0x00; } /* Write SLA(W), address, SLA(R), and read one byte back. */ I2CWriteLength = 2; I2CReadLength = 4; I2CMasterBuffer[0] = PCF8594_ADDR; I2CMasterBuffer[1] = 0x00; /* address */ I2CMasterBuffer[2] = PCF8594_ADDR | RD_BIT; I2CEngine(); return 0; }
int main(void) { uint8_t already = 0; /* Set structs for all examples */ TM_USB_HIDDEVICE_Keyboard_t Keyboard; TM_USB_HIDDEVICE_Gamepad_t Gamepad1, Gamepad2; TM_USB_HIDDEVICE_Mouse_t Mouse; /* Initialize system */ SystemInit(); /* Initialize leds */ TM_DISCO_LedInit(); /* Initialize button */ TM_DISCO_ButtonInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize USB HID Device */ TM_USB_HIDDEVICE_Init(); /* Set default values for mouse struct */ TM_USB_HIDDEVICE_MouseStructInit(&Mouse); /* Set default values for keyboard struct */ TM_USB_HIDDEVICE_KeyboardStructInit(&Keyboard); /* Set default values for gamepad structs */ TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad1); TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad2); while (1) { /* If we are connected and drivers are OK */ if (TM_USB_HIDDEVICE_GetStatus() == TM_USB_HIDDEVICE_Status_Connected) { /* Turn on green LED */ TM_DISCO_LedOn(LED_GREEN); /* Simple sketch start */ /* If you pressed button right now and was not already pressed */ if (TM_DISCO_ButtonPressed() && already == 0) { /* Button on press */ already = 1; /* Set pressed keys = WIN + R */ Keyboard.L_GUI = TM_USB_HIDDEVICE_Button_Pressed; /* Win button */ Keyboard.Key1 = 0x15; /* R */ /* Result = "Run" command */ /* Send keyboard report */ TM_USB_HIDDEVICE_KeyboardSend(&Keyboard); } else if (!TM_DISCO_ButtonPressed() && already == 1) { /* Button on release */ already = 0; /* Release all buttons */ Keyboard.L_GUI = TM_USB_HIDDEVICE_Button_Released; /* No button */ Keyboard.Key1 = 0x00; /* No key */ /* Result = Released everything */ /* Send keyboard report */ TM_USB_HIDDEVICE_KeyboardSend(&Keyboard); } /* Simple sketch end */ } else { /* Turn off green LED */ TM_DISCO_LedOff(LED_GREEN); } } }
void init(void) { SystemInit(); //Setup SystickTimer if (SysTick_Config(SystemCoreClock / 1000)){ColorfulRingOfDeath();} GPIO_Configuration(); #ifdef USE_MICROUSB USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); #endif #ifdef USE_SDIO UB_Fatfs_Init(); #endif #ifdef USE_ADC ADC_Configuration(); #endif #ifdef USE_I2C I2C_Configuration(); #endif #ifdef USE_SPI SPI_Configuration(); #endif #ifdef USE_ENCODER TIM_encoder_Configuration(); #endif #ifdef USE_USART1 USART1_Configuration(); #endif #ifdef USE_USART2 USART2_Configuration(); #endif #ifdef USE_USART3 USART3_Configuration(); #endif #ifdef USE_CAN CAN_Configuration(); #endif #ifdef USE_PWM TIM_pwm_Configuration(); #endif #ifdef USE_EXTI EXTI_Configuration(); #endif NVIC_Configuration(); }
void init( void ) { SystemInit(); // Set Systick to 1ms interval, common to all SAM3 variants if (SysTick_Config(SystemCoreClock / 1000)) { // Capture error while (true); } // Disable watchdog WDT_Disable(WDT); // Initialize C library __libc_init_array(); // Disable pull-up on every pin for (int i = 0; i < PINS_COUNT; i++) digitalWrite(i, LOW); // Enable parallel access on PIO output data registers PIOA->PIO_OWER = 0xFFFFFFFF; PIOB->PIO_OWER = 0xFFFFFFFF; PIOC->PIO_OWER = 0xFFFFFFFF; PIOD->PIO_OWER = 0xFFFFFFFF; // Initialize Serial port U(S)ART pins PIO_Configure( g_APinDescription[PINS_UART].pPort, g_APinDescription[PINS_UART].ulPinType, g_APinDescription[PINS_UART].ulPin, g_APinDescription[PINS_UART].ulPinConfiguration); digitalWrite(0, HIGH); // Enable pullup for RX0 PIO_Configure( g_APinDescription[PINS_USART0].pPort, g_APinDescription[PINS_USART0].ulPinType, g_APinDescription[PINS_USART0].ulPin, g_APinDescription[PINS_USART0].ulPinConfiguration); PIO_Configure( g_APinDescription[PINS_USART1].pPort, g_APinDescription[PINS_USART1].ulPinType, g_APinDescription[PINS_USART1].ulPin, g_APinDescription[PINS_USART1].ulPinConfiguration); PIO_Configure( g_APinDescription[PINS_USART3].pPort, g_APinDescription[PINS_USART3].ulPinType, g_APinDescription[PINS_USART3].ulPin, g_APinDescription[PINS_USART3].ulPinConfiguration); // Initialize USB pins PIO_Configure( g_APinDescription[PINS_USB].pPort, g_APinDescription[PINS_USB].ulPinType, g_APinDescription[PINS_USB].ulPin, g_APinDescription[PINS_USB].ulPinConfiguration); // Initialize CAN pins /* PIO_Configure( g_APinDescription[PINS_CAN0].pPort, g_APinDescription[PINS_CAN0].ulPinType, g_APinDescription[PINS_CAN0].ulPin, g_APinDescription[PINS_CAN0].ulPinConfiguration); PIO_Configure( g_APinDescription[PINS_CAN1].pPort, g_APinDescription[PINS_CAN1].ulPinType, g_APinDescription[PINS_CAN1].ulPin, g_APinDescription[PINS_CAN1].ulPinConfiguration); */ // Initialize Analog Controller pmc_enable_periph_clk(ID_ADC); adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger. adc_disable_interrupt(ADC, 0xFFFFFFFF); // Disable all ADC interrupts. adc_disable_all_channel(ADC); // Initialize analogOutput module analogOutputInit(); }
/* SSP_LoopBack function */ void SSP_LoopBack(void) { SSP_InitTypeDef initSSP; SSP_FIFOState fifoState; uint16_t datTx = 0U; /* must use 16bit type */ uint32_t cntTx = 0U; uint32_t cntRx = 0U; uint16_t receive = 0U; uint16_t Rx_Buf[MAX_BUFSIZE] = { 0U }; uint16_t Tx_Buf[MAX_BUFSIZE] = { 0U }; SystemInit(); /* enable the LED on board to display some info */ UART_Configuration(UART); UART_Print(UART, "This is an example for SSP module!\n\r"); /* configure the SSP module */ initSSP.FrameFormat = SSP_FORMAT_SPI; /* default is to run at maximum bit rate */ initSSP.PreScale = 2U; initSSP.ClkRate = 1U; /* define BITRATE_MIN to run at minimum bit rate */ /* BitRate = fSYS / (PreScale x (1 + ClkRate)) */ #ifdef BITRATE_MIN initSSP.PreScale = 254U; initSSP.ClkRate = 255U; #endif initSSP.ClkPolarity = SSP_POLARITY_LOW; initSSP.ClkPhase = SSP_PHASE_FIRST_EDGE; initSSP.DataSize = 16U; initSSP.Mode = SSP_MASTER; SSP_Init(&initSSP); /* enable loop back mode for self test */ SSP_SetLoopBackMode(ENABLE); /* enable and run SSP module */ SSP_Enable(); while (1) { datTx++; /* send data if Tx FIFO is available */ fifoState = SSP_GetFIFOState(SSP_TX); if ((fifoState == SSP_FIFO_EMPTY) || (fifoState == SSP_FIFO_NORMAL)) { SSP_SetTxData(datTx); if (cntTx < MAX_BUFSIZE) { Tx_Buf[cntTx] = datTx; cntTx++; } else { /* do nothing */ } } else { /* do nothing */ } /* check if there is data arrived */ fifoState = SSP_GetFIFOState(SSP_RX); if ((fifoState == SSP_FIFO_FULL) || (fifoState == SSP_FIFO_NORMAL)) { receive = SSP_GetRxData(); if (cntRx < MAX_BUFSIZE) { Rx_Buf[cntRx] = receive; cntRx++; } else { /* Place a break point here to check if receive data is right. */ /* Success Criteria: */ /* Every data transmited from Tx_Buf is received in Rx_Buf. */ /* When the line "#define BITRATE_MIN" is commented, the SSP is run in maxium */ /* bit rate, so we can find there is enough time to transmit date from 1 to */ /* MAX_BUFSIZE one by one. but if we uncomment that line, SSP is run in */ /* minimum bit rate, we will find that receive data can't catch "datTx++", */ /* in this so slow bit rate, when the Tx FIFO is available, the cntTx has */ /* been increased so much. */ __NOP(); } } else { /* do nothing */ } sprintf(message, "Received data is %d\n\r" + (uint8_t)(receive / 8000)); UART_Print(UART, message); } }
int __start(void) { const volatile uint32_t *src; volatile uint32_t *dest; /* Set up BSS and copy data from flash */ for (src = &_eronly, dest = &_sdata; dest < &_edata;) { *dest++ = *src++; } for (dest = &_sbss; dest < &_ebss;) { *dest++ = 0; } SystemInit(); HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Make sure the flash option bytes are set such that we don't re-enter bootloader mode */ set_dfu_option_bytes(0u); MX_USB_DEVICE_Init(); /* Configure GPIO for the CAN_SILENT signal */ GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __GPIOA_CLK_ENABLE(); __GPIOB_CLK_ENABLE(); __CRS_CLK_ENABLE(); /*Configure GPIO pin : PB7 */ GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /**CAN GPIO Configuration PB8 ------> CAN_RX PB9 ------> CAN_TX */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_CAN; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure the bxCAN transceiver */ CAN_HandleTypeDef hcan; __CAN_CLK_ENABLE(); hcan.Instance = CAN; hcan.Init.Mode = CAN_MODE_SILENT; hcan.Init.TTCM = DISABLE; hcan.Init.ABOM = ENABLE; hcan.Init.AWUM = ENABLE; hcan.Init.NART = DISABLE; hcan.Init.RFLM = DISABLE; hcan.Init.TXFP = DISABLE; /* Set the bitrate and init */ set_can_bitrate(&hcan, 1000000u); CanRxMsgTypeDef rx_msg; hcan.pRxMsg = &rx_msg; CanTxMsgTypeDef tx_msg; hcan.pTxMsg = &tx_msg; CAN_FilterConfTypeDef filter; filter.FilterNumber = 0; filter.FilterMode = CAN_FILTERMODE_IDMASK; filter.FilterScale = CAN_FILTERSCALE_32BIT; filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; filter.FilterActivation = ENABLE; filter.BankNumber = 0; filter.FilterMaskIdLow = filter.FilterIdLow = filter.FilterMaskIdHigh = filter.FilterIdHigh = 0; HAL_CAN_ConfigFilter(&hcan, &filter); __HAL_UNLOCK(&hcan); /* Now that USB is active, we need to sync with the 1 kHz SOF packets to tune the HSI48 so it's accurate enough not to disrupt the CAN bus. */ RCC_CRSInitTypeDef crs_config; crs_config.Prescaler = RCC_CRS_SYNC_DIV1; crs_config.Source = RCC_CRS_SYNC_SOURCE_USB; crs_config.Polarity = RCC_CRS_SYNC_POLARITY_RISING; crs_config.ReloadValue = RCC_CRS_RELOADVALUE_DEFAULT; crs_config.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT; crs_config.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT; HAL_RCCEx_CRSConfig(&crs_config); /* Don't continue unless we're synced */ while (!(HAL_RCCEx_CRSWaitSynchronization(1000000u) & RCC_CRS_SYNCOK)); while (1) { /* Set up the command record */ size_t i; uint8_t current_cmd; uint8_t current_cmd_data[32]; uint8_t current_cmd_data_length; uint8_t channel_open; current_cmd = current_cmd_data_length = i = 0; channel_open = 0; rx_buffer_length = 0; while (hUsbDevice_0 && hUsbDevice_0->pClassData) { /* If the RX buffer is non-empty, process any commands/messages in it and then acknowledge the transfer to the USB stack */ if (rx_buffer_length) { /* Exit if we've read the entire buffer, or if transmit mailboxes are full and the current command is a transmit. */ for (; i < rx_buffer_length && ((current_cmd != 't' && current_cmd != 'T') || __HAL_CAN_GET_FLAG(&hcan, CAN_FLAG_TME0)); i++) { if (rx_buffer[i] == '\r') { uint8_t *buf = active_buffer ? tx_buffer_1 : tx_buffer_0; /* End of command -- process and reset state */ switch (current_cmd) { case 'S': /* Setup bitrate -- data should be a number from 0 to 8. */ if (current_cmd_data[0] < '0' || current_cmd_data[0] > '8') { buf[active_buffer_length++] = '\a'; } else if (set_can_bitrate( &hcan, bitrate_lookup[current_cmd_data[0] - '0'])) { buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 'O': /* Open channel -- take CAN out of silent mode and start receiving. */ if (!channel_open) { channel_open = 1; set_can_silent(&hcan, 0); buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 'L': /* Open in listen-only -- CAN should already be in silent mode but just make sure. */ if (!channel_open) { channel_open = 1; set_can_silent(&hcan, 1); buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 'C': /* Close channel -- put CAN back in silent mode. */ if (channel_open) { channel_open = 0; set_can_silent(&hcan, 1); buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 'V': /* Hardware version */ buf[active_buffer_length++] = 'V'; buf[active_buffer_length++] = '0'; buf[active_buffer_length++] = '0'; buf[active_buffer_length++] = '0'; buf[active_buffer_length++] = '1'; buf[active_buffer_length++] = '\r'; break; case 'v': /* Major/minor version */ buf[active_buffer_length++] = 'v'; buf[active_buffer_length++] = '0'; buf[active_buffer_length++] = '0'; buf[active_buffer_length++] = '0'; buf[active_buffer_length++] = '1'; buf[active_buffer_length++] = '\r'; break; case 'N': /* Serial number */ buf[active_buffer_length++] = 'N'; buf[active_buffer_length++] = 'F'; buf[active_buffer_length++] = 'F'; buf[active_buffer_length++] = 'F'; buf[active_buffer_length++] = 'F'; buf[active_buffer_length++] = '\r'; break; case 'T': /* Extended message */ if (read_ext_message(&tx_msg, current_cmd_data, current_cmd_data_length) && HAL_CAN_Transmit(&hcan, 0) == HAL_OK) { buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 't': /* Standard message */ if (read_std_message(&tx_msg, current_cmd_data, current_cmd_data_length) && HAL_CAN_Transmit(&hcan, 0) == HAL_OK) { buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 'R': /* Extended RTR */ if (read_ext_rtr(&tx_msg, current_cmd_data, current_cmd_data_length) && HAL_CAN_Transmit(&hcan, 0) == HAL_OK) { buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case 'r': /* Standard RTR */ if (read_std_rtr(&tx_msg, current_cmd_data, current_cmd_data_length) && HAL_CAN_Transmit(&hcan, 0) == HAL_OK) { buf[active_buffer_length++] = '\r'; } else { buf[active_buffer_length++] = '\a'; } break; case '_': /* Bootloader request */ if (current_cmd_data[0] == '_' && current_cmd_data[1] == 'd' && current_cmd_data[2] == 'f' && current_cmd_data[3] == 'u') { /* Set option bytes to force bootloader entry */ set_dfu_option_bytes(1u); NVIC_SystemReset(); } else { buf[active_buffer_length++] = '\a'; } break; case 'F': /* Read status flags -- return 4 hex digits */ case 'Z': /* Timestamp on/off -- 0=off, 1=on */ case 'M': /* Acceptance mask -- 8 hex digits */ case 'm': /* Acceptance value -- 8 hex digits */ case 's': /* Set bitrate register -- 6 hex digits */ default: /* NACK */ buf[active_buffer_length++] = '\a'; break; } current_cmd = current_cmd_data_length = 0; } else if (current_cmd) { /* Command data -- save it */ current_cmd_data[current_cmd_data_length++] = rx_buffer[i]; /* Reset command state if the data is too long */ if (current_cmd_data_length == 32u) { current_cmd = current_cmd_data_length = 0; } } else { /* The first letter of a line is the command type -- don't bother validating as we can't NACK until the data has been received. */ current_cmd = rx_buffer[i]; } } if (i == rx_buffer_length) { /* Mark last packet as received */ rx_buffer_length = i = 0; USBD_CDC_ReceivePacket(hUsbDevice_0); } } /* Check the CAN controller for messages and process them if the channel is open */ if (HAL_CAN_Receive(&hcan, CAN_FIFO0, 0) == HAL_OK && hUsbDevice_0 && channel_open) { /* Format the message and send it to the host. The data format for a standard ID message is: tiiildddddddddddddddd\r The data format for a standard ID RTR is: riii\r The data format for an extended ID message is: Tiiiiiiiildddddddddddddddd\r The data format for an extended ID RTR is: Riiiiiiii\r */ uint8_t *write_location; if (active_buffer_length + EXT_MESSAGE_LEN > TX_BUFFER_SIZE) { /* Reset buffer if we're too far behind -- use worst-case message length for calculation */ active_buffer_length = 0; } write_location = &((active_buffer ? tx_buffer_1 : tx_buffer_0)[active_buffer_length]); if (rx_msg.IDE == CAN_ID_EXT && rx_msg.RTR) { active_buffer_length += write_ext_rtr( write_location, &rx_msg); } else if (rx_msg.IDE == CAN_ID_EXT && !rx_msg.RTR) { active_buffer_length += write_ext_message( write_location, &rx_msg); } else if (rx_msg.IDE == CAN_ID_STD && rx_msg.RTR) { active_buffer_length += write_std_rtr( write_location, &rx_msg); } else if (rx_msg.IDE == CAN_ID_STD && !rx_msg.RTR) { active_buffer_length += write_std_message( write_location, &rx_msg); } } if (!hUsbDevice_0 || !hUsbDevice_0->pClassData) { /* Reset TX buffer if USB is not connected */ active_buffer_length = 0; } else if (active_buffer_length && ((USBD_CDC_HandleTypeDef*)hUsbDevice_0->pClassData)->TxState == 0) { /* Transmit the next buffer if one is available */ CDC_Transmit_FS(active_buffer ? tx_buffer_1 : tx_buffer_0, active_buffer_length); active_buffer_length = 0; active_buffer = active_buffer ? 0 : 1; } } } }
int main(void) { int j=0; unsigned char ch=0,ch_pre=0; unsigned char brightness=0;//这个值记录所有与台灯相关的亮度信息 SystemInit(); delay_init(72); //1、指示灯 LED_Init(); LED(OFF,ALL); //2.1、控制台灯亮度 PWM_Init(2400,0,0); //2.2、用于采集台灯的控制信号 TIM1_PWM_IN1(); //3、GPIO初始化用于控制风扇 gpio_0_init(); // //4、NFC的TAG初始化设置 // NFC初始化 // Write_Register(CONTROL_REG, SW_RESET); // delay_ms(5); // Write_Continuous(0, NDEF_Application_Data, 104); // delay_ms(5); // Write_Register(INT_ENABLE_REG, EOW_INT_ENABLE + EOR_INT_ENABLE); // delay_ms(5); // Write_Register(CONTROL_REG, INT_ENABLE + INTO_DRIVE + RF_ENABLE); //5、蓝牙串口 Init_USART3(); //Init_USART1(); while(1) { delay_ms(10); if(pulse_width1!=0) { if(9==pulse_width1/10) { ch=2; } if(37==pulse_width1/10) { ch=3; } pulse_width1=0; } else { if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9)) { ch=1; } if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9)) { ch=4; } } if(ch!=ch_pre) { if(1==ch) { PWM_Init(2400,30,30); brightness=30; } else if(2==ch) { PWM_Init(2400,60,60); brightness=60; } else if(3==ch) { PWM_Init(2400,100,100); brightness=100; } else { PWM_Init(2400,0,0); brightness=0; } } ch_pre=ch; //1、串口缓冲区已经满了,开始解析数据 if(USART_fifo_full) { //保存上一次的值 for(int i=0;i<detect_dst_length;i++) { detect_dst_pre[i]=detect_dst[i]; } USART_fifo_full=0; //读取串口队列中的数据 j=0; while(!USART_fifo_empty) { USART_Rec_Data[j]=USART_fifo_read(); j++; } USART_fifo_empty=0; Data_frame_handle(detect_src,detect_src_length,detect_dst,detect_dst_length);//分析数据 //串口打印接收数据 // for (int i = 0; i < USART_Queue_Size; ++i) // { // USART_SendData(USART1, detect_dst[i]); // delay_ms(10); // } } // detect_dst[0] .....灯 // 0~100 .....占空比数据 // 10 .....开灯 // 11 .....关灯 // 12 .....调亮 // 13 .....调暗 // detect_dst[1] .....风扇 // 0 关闭 // 1 1档 // 2 2档 // 3 3档 //2、根据有效内容,控制灯和风扇 // if(detect_dst_pre[0]!=detect_dst[0]) // { // //PWM_Init(2400,detect_dst[0],detect_dst[0]); // PWM1_Duty_Set(detect_dst[0]); // } if(0!=detect_dst[0]) { if(0x10==detect_dst[0]) { PWM1_Duty_Set(60); //开灯,调节到始终的亮度 brightness=60; } if(0x11==detect_dst[0]) { PWM1_Duty_Set(0); //关灯 brightness=0; } if(0x12==detect_dst[0]) { if(brightness<100) { brightness=brightness+10; } PWM1_Duty_Set(brightness); //调亮 } if(0x13==detect_dst[0]) { if(brightness>0) { brightness=brightness-10; } PWM1_Duty_Set(brightness); //调暗 } detect_dst[0]=0;//置位,等待下一次检测 } if(0!=detect_dst[1]) { switch(detect_dst[1]) { case 0x41: gpio_1(PB0,0); gpio_1(PB1,0); gpio_1(PB2,0); LED(ON,ALL); break; case 0x42: gpio_1(PB0,1); gpio_1(PB1,0); gpio_1(PB2,0); LED(OFF,ALL); LED(ON,D2); break; case 0x43: gpio_1(PB0,0); gpio_1(PB1,1); gpio_1(PB2,0); LED(OFF,ALL); LED(ON,D3); break; case 0x44: gpio_1(PB0,0); gpio_1(PB1,0); gpio_1(PB2,1); LED(OFF,ALL); LED(ON,D4); break; default: break; } detect_dst[1]=0; } } }