本文整理汇总了C++中SystemInit函数的典型用法代码示例。如果您正苦于以下问题:C++ SystemInit函数的具体用法?C++ SystemInit怎么用?C++ SystemInit使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SystemInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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");
}
示例2: arch_init
void arch_init(void) {
static_assert(OPTION_MODULE_GET(embox__arch__system, NUMBER, core_freq) == 144000000);
SystemInit();
}
示例3: main
/**
* @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
}
}
示例4: Reset_Handler
__weak void Reset_Handler(void)
{
SystemInit();
__iar_program_start();
}
示例5: RCC_Configuration
/**
* @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();
}
示例6: main
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);
}
}*/
}
示例7: main
/**
* @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
//.........这里部分代码省略.........
示例8: main
/**
* @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)
//.........这里部分代码省略.........
示例9: System_Setup
/**
* @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);
}
示例10: main
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 */
}
}
}
示例11: main
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++);
}
}
示例12: main
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)
//.........这里部分代码省略.........
示例13: ResetISR
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) {
;
}
}
示例14: main
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
//.........这里部分代码省略.........
示例15: main
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
//.........这里部分代码省略.........