搜索
bottom↓
回复: 11

RTX 软件定时器?

[复制链接]

出0入0汤圆

发表于 2015-5-2 16:02:21 | 显示全部楼层 |阅读模式
RTX V4.70.1软件定时器,设定了3个,但是仅最后一个有效,其它的无效,在FreeRTOS 中则可以,用CMSIS_OS1.02编的,MDK5.14

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

发表于 2015-5-2 16:25:11 | 显示全部楼层
rtx_config里设定3个,初始化代码也要初始化

出0入0汤圆

 楼主| 发表于 2015-5-2 16:41:17 | 显示全部楼层
谢谢,贴上代码,在Debug时发现
osTimerId myTimer01Handle; 为"NULL"
osTimerId myTimer02Handle; 为"NULL"
osTimerId myTimer03Handle; 正常
MDK的优化设最低,则myTimer01Handle,myTimer03Handle正常 还有myTimer02Handle为NULL

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"

osTimerId myTimer01Handle;
osTimerId myTimer02Handle;
osTimerId myTimer03Handle;


void SystemClock_Config(void);
static void MX_GPIO_Init(void);

void Callback01(void const * argument);
void Callback02(void const * argument);
void Callback03(void const * argument);

void Callback01(void const * argument)
{
        HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_3);
}

void Callback02(void const * argument)
{
        HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_4);
}

void Callback03(void const * argument)
{
        HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_5);
}

int main(void)
{
       
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();       
       
        osTimerDef(myTimer01, Callback01);
  myTimer01Handle = osTimerCreate(osTimer(myTimer01), osTimerPeriodic, NULL);
  osTimerStart(myTimer01Handle,1001);

  osTimerDef(myTimer02, Callback02);
  myTimer02Handle = osTimerCreate(osTimer(myTimer02), osTimerPeriodic, NULL);
  osTimerStart(myTimer02Handle,501);

  osTimerDef(myTimer03, Callback03);
  myTimer03Handle = osTimerCreate(osTimer(myTimer03), osTimerPeriodic, NULL);
  osTimerStart(myTimer03Handle,101);       
       
        osKernelStart();
       
   while (1)
  {
  }

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);

  __HAL_RCC_AFIO_CLK_ENABLE();

}


void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOE_CLK_ENABLE();
  __GPIOC_CLK_ENABLE();

  /*Configure GPIO pin : PE5 */
  GPIO_InitStruct.Pin = GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pins : PC3 PC4 PC5 */
  GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

}

#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 CODE BEGIN 6 */
  /* 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) */
  /* USER CODE END 6 */

}

#endif

/**
  * @}
  */

/**
  * @}
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

出0入0汤圆

 楼主| 发表于 2015-5-2 16:43:57 | 显示全部楼层
rtx_config
#ifndef OS_TIMERPRIO
#define OS_TIMERPRIO   5
#endif

//   <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
//   <i> Defines stack size for Timer thread.
//   <i> Default: 200
#ifndef OS_TIMERSTKSZ
#define OS_TIMERSTKSZ  256     // this stack size value is in words
#endif

//   <o>Timer Callback Queue size <1-32>
//   <i> Number of concurrent active timer callback functions.
//   <i> Default: 4
#ifndef OS_TIMERCBQS
#define OS_TIMERCBQS   32
#endif

出0入0汤圆

 楼主| 发表于 2015-5-2 16:56:49 | 显示全部楼层
FreeRTOS在IAR和MDK都没有问题

出0入0汤圆

 楼主| 发表于 2015-5-2 17:05:35 | 显示全部楼层
Timers.zip是使用RTX4.7 OS有问题的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2015-5-2 19:23:25 | 显示全部楼层
看来还是freeRTOS靠普

出0入0汤圆

发表于 2015-5-2 19:32:28 | 显示全部楼层
R8C 发表于 2015-5-2 16:41
谢谢,贴上代码,在Debug时发现
osTimerId myTimer01Handle; 为"NULL"
osTimerId myTimer02Handle; 为"NULL"

你用的是cmsis-rtx,这个我不熟悉,从你的代码看,和原版差别还是非常大的

在原版rtx中,软件定时器初始化只需调用一次,就把所有预定义的软件定时器管理起来,使用时候新建一个即可,但是定时结束的时候就自动释放了

你的代码和配置,看上去这个软件定时器更像一个定时的任务

差别太大,可能不能提供有用的信息

出0入0汤圆

 楼主| 发表于 2015-5-2 20:10:19 | 显示全部楼层
具体说明:
cmsis-os和rtx配合,3个定时器IAR和MDK正常(LED指示:1000ms,500ms,100ms)
cmsis-os和rtx配合,3个定时器IAR正常,MDK前两个不正常,最后1个正常(100ms)

出0入0汤圆

 楼主| 发表于 2015-5-2 20:11:00 | 显示全部楼层
具体说明:
cmsis-os和freertos配合,3个定时器IAR和MDK正常(LED指示:1000ms,500ms,100ms)
cmsis-os和rtx配合,3个定时器IAR正常,MDK前两个不正常,最后1个正常(100ms)

出0入0汤圆

 楼主| 发表于 2015-5-2 20:12:14 | 显示全部楼层
9楼的不对,10楼的正确

出0入0汤圆

 楼主| 发表于 2015-5-2 20:54:13 | 显示全部楼层
结贴,MDK的优化问题,谢谢myxiaonia
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-27 09:56

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表