5、我这次学主要是得益于我的师兄(李壮)的技术支持啊,有什么问题就看他博客,但是他的这个方面写的真没有前面的好。http://blog.chinaunix.net/uid/21658993.html(李壮博客的地址有事没事上上,可能在你没有头绪的时候找到问题的解决方案哦。)
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOF Periph clock enable */
RCC_AHB1PeriphClockCmd(LED1_RCC_AHBPeriph | LED2_RCC_AHBPeriph | LED3_RCC_AHBPeriph | LED4_RCC_AHBPeriph, ENABLE);
/* Configure PF6 PF7 PF8 PF9 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = LED1_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(LED1_Port, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LED2_Pin;
GPIO_Init(LED2_Port, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LED3_Pin;
GPIO_Init(LED3_Port, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LED4_Pin;
GPIO_Init(LED4_Port, &GPIO_InitStructure);
}
/****************************************************/
//ad2é¼ˉ¶¨ê±μÄ3õê¼»ˉ
/****************************************************/
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// TIM_OCInitTypeDef TIM_OCInitStructure;
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* »ù′¡éèÖÃ*/
TIM_TimeBaseStructure.TIM_Period =50000; //¼ÆÂúÖμ
TIM_TimeBaseStructure.TIM_Prescaler =7199; //Ô¤·ÖÆμ,′ËÖμ+1Îa·ÖÆμμÄ3yêy
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòéϼÆêy
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/*ê1ÄüԤװÔØ*/
TIM_ARRPreloadConfig(TIM2, ENABLE);
/*Ô¤ÏèÇå3yËùóDÖD¶Ïλ*/
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* ÔêDíTIM2¿aê¼¼Æêy */
TIM_Cmd(TIM2, ENABLE);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configuration the nested vectored interrupt controller.
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //Ô¤éèóÅÏ輶ÎòÔ¤éèμÄêÇ1¼′2éóÃò»Î»óÅÏ裬3λÏìó|
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/***********************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
static void mytask_1(void)
{
CPU_INT08U os_err;
os_err=os_err;
for(;;)
{
OSMutexPend(mutex,0,&os_err);
// OSSemPend(mysem[1],0,&os_err);
GPIO_SetBits(LED1_Port,LED1_Pin);
OSTimeDly(500);
GPIO_ResetBits(LED1_Port,LED1_Pin);
OSTimeDly(500);
// test_key=1;
OSMutexPost(mutex);
// OSTimeDly(500);
}
}
static void mytask_2(void)
{
CPU_INT08U os_err;
os_err=os_err;
for(;;)
{
OSMutexPend(mutex,0,&os_err);
// OSSemPend(mysem[2],0,&os_err);
GPIO_SetBits(LED2_Port,LED2_Pin);
OSTimeDly(500);
GPIO_ResetBits(LED2_Port,LED2_Pin);
OSMutexPost(mutex);
OSTimeDly(500);
// test_key=2;
// OSSemPost(mysem[1]);
// OSTimeDly(500);
}
}
static void mytask_key(void)
{
CPU_INT08U os_err;
os_err=os_err;
mutex=OSMutexCreate(MUTEX_PRIO,&os_err);
for(;;)
{
GPIO_SetBits(LED4_Port,LED4_Pin);
OSTimeDly(500);
}
}
void mytask_1_create (void)
{
CPU_INT08U os_err;
os_err = os_err; /* prevent warning... ·àÖ1±¨¾ˉ*/
os_err= OSTaskCreate( (void (*)(void *)) mytask_1,
(void *)0,
(OS_STK *)&task1_stk[128-1],
(INT8U )8
);
}
void mytask_2_create (void)
{
CPU_INT08U os_err;
os_err = os_err; /* prevent warning... ·àÖ1±¨¾ˉ*/
os_err= OSTaskCreate( (void (*)(void *)) mytask_2,
(void *)0,
(OS_STK *)&task2_stk[128-1],
(INT8U )7
);
}
void mytask_key_create (void)
{
CPU_INT08U os_err;
os_err = os_err; /* prevent warning... ·àÖ1±¨¾ˉ*/
os_err= OSTaskCreate( (void (*)(void *)) mytask_key,
(void *)0,
(OS_STK *)&task3_stk[128-1],
(INT8U )6
);
}
static void App_TaskStart (void *p_arg)
{
(void)p_arg;
mysem[1]=OSSemCreate(0);//′′½¨μÄὸöDÅoÅá¿mysem_0
mysem[2]=OSSemCreate(0);//′′½¨μÄὸöDÅoÅá¿mysem_1
/*************** Init hardware ***************/
GPIO_Configuration();
OS_CPU_SysTickInit(); /* Initialize the SysTick. */
GPIO_SetBits(LED1_Port,LED1_Pin);
GPIO_SetBits(LED2_Port,LED2_Pin);
GPIO_SetBits(LED3_Port,LED3_Pin);
GPIO_SetBits(LED4_Port,LED4_Pin);
OSTimeDly(500);
GPIO_ResetBits(LED1_Port,LED1_Pin);
GPIO_ResetBits(LED2_Port,LED2_Pin);
GPIO_ResetBits(LED3_Port,LED3_Pin);
GPIO_ResetBits(LED4_Port,LED4_Pin);
#if (OS_TASK_STAT_EN > 0) //Ô¤±àòëêÇ·ñÆô¶ˉí3¼Æoˉêy//±¾oˉêyéèÖÃÎaÆô¶ˉ OS_TASK_STAT_EN=1u
OSStatInit(); /* Determine CPU capacity. */
#endif
App_TaskCreate(); //óÅÏ輶êÇ /* Create application tasks. */
mytask_key_create();
mytask_1_create ();
mytask_2_create ();
for(;;)
{
OSTimeDlyHMSM(0, 1, 0, 0); /* Delay One minute Ö¸¶¨μÄÑóê±oˉêy*/
}
}