⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_cnf.c

📁 AVR系列单片机的ADC驱动程序库
💻 C
字号:

/*********************************************************/
/*             SCHWED-OS operating system                */
/*                                                       */
/*   (C) by J鰎g Schwedes 2009, All rights reserved      */
/*********************************************************/

/* version 1.0.1.0 */

#include <general.h>
#include <os.h>
#include <project.h>
#include <ad.h>


/*********** configuration unit ************/
/*
OS definitions and resources
for timebase and OS services
*/
/* OS interrupt definitions */

#define __OS_interrupt __interrupt
/* timebase interrupt */

#if defined(__ATtiny25__) ||defined(__ATtiny45__) || defined(__ATtiny85__)
#define OS_INT_TMB_VECT       TIM0_COMPA_vect
#define OS_INT_OVF_VECT       TIM0_OVF_vect
#define OS_INT_TMB_request(x) TIFR_Bit4=!(x);TIFR_Bit1=!(x)
#define OS_Get_OV_req() TIFR_Bit1
#define OS_Res_OV_req() TIFR_Bit1=1;
#define OS_INT_TMB_enable(x)  TIMSK_Bit4=(x);TIMSK_Bit1=(x)
u8 os_ov_ctr;
#else
#define OS_INT_TMB_VECT       TIMER1_COMPA_vect
#endif
#if defined(__ATmega48__) || defined(__ATmega88__) || defined(__ATmega168__)
#define OS_INT_TMB_request(x) TIFR1_Bit1=!(x)
#define OS_INT_TMB_enable(x)  TIMSK1_Bit1=(x)
#else
#if defined(__ATmega16__) || defined(__ATmega8__)
#define OS_INT_TMB_request(x) TIFR_Bit4=!(x)
#define OS_INT_TMB_enable(x)  TIMSK_Bit4=(x)
#endif
#endif
extern void OS_TimeBaseService(void);

/* OS Main scheduler */
__OS_NO_RETURN extern void OS_StartSchwedOS(void);

/*
OS service: Get time in micro seconds (HW dependent timer)

This service MUST be defined because it is used
by the OS itself.
*/
/*
u16 OS_GetTimeUs(void)
*/
u16 OS_GetTimeUs(void)
{
#if defined(__ATtiny25__) ||defined(__ATtiny45__) || defined(__ATtiny85__)
  /* 16-bit 祍 timer build is currently critical if interrupts are blocked longer then 500祍 */
    u16 temp = 0;   
    OS_SuspendInt(); /* ensure data consistency
                        due to 16-bit value read ! */
    temp = TCNT0;
  if(OS_Get_OV_req())
  {
    os_ov_ctr++;
    OS_Res_OV_req();
  }
  temp |= ((u16)os_ov_ctr)<<8;
  OS_ResumeInt();

  return(temp<<1); /* timer has only 2祍 resolution, bring it to 1祍 */
#else
  u16 temp;
  OS_SuspendInt(); /* ensure data consistency
                      due to 16-bit timer read ! */
  temp=TCNT1; /* read 16-bit HW timer */

  OS_ResumeInt();

  return(temp);
#endif
}
/*
static __OS_INLINE void OS_InitTask(void)
*/
static __OS_INLINE void OS_InitTask(void)
{
  /* application init hook */

  AD_Init();
  OS_ActDynPreempTask(AD_AutoScan_OS_1ms);
}
/*
static __OS_INLINE void OS_InitOS(void)
*/
static __OS_INLINE void OS_InitOS(void)
{
  /* init of OS Timer and interrupt */

  OS_INT_TMB_request(0);
#if defined(__ATtiny25__) ||defined(__ATtiny45__) || defined(__ATtiny85__)
  OCR0A = 250; /* next timebase int in 500祍 */

  /* Compare match / Pins disconnected */
  /* set prescaler 1/8 and start timer
     TCCR0B | =1 */
  TCCR0A= 0;
  TCCR0B_Bit1=1;
#else
  OCR1A = 1000; /* next interrupt in 1ms */

  /* Compare match / Pins disconnected */
  /* set prescaler 1/8 and start timer
     (TCCR1B |=1) */
  TCCR1A=0;
  TCCR1B_Bit1=1;
#endif
  OS_INT_TMB_enable(1);
}
#ifdef OS_USE_IDLE_TASK
/*
void OS_IdleTask(void)
*/
void OS_IdleTask(void)
{
  /* called in idle time of OS:
     add here only "fast" code < 150us */


}
#endif
#ifdef OS_USE_ERROR_TASK
/*
void OS_ErrorTask(void)
*/
void OS_ErrorTask(void)
{
  /* put here actions for error case */
  OS_SystemReset();
  while (1)
  {
    // mon();
  }
}
#endif
/*
+++++++++++++++++++++++++++++++++++++++++++++++++++
+++ OS Tasklist 5ms / 10ms and Preemptive Tasks +++
*/
#ifdef OS_USE_5MS_TASKS
/*
void (*const __OS_ROM OS_task_5ms[])(void) =
*/
/* ************************************ */
/* add here  5ms tasks                  */
void (*const __OS_ROM OS_task_5ms[])(void) =
{
  XXX,
  XXX
  /* after last function no comma !!*/
}
;

const u8 __OS_ROM OS_task_nr_5ms = sizeof(OS_task_5ms)/sizeof(OS_task_5ms[0]);
#endif
#ifdef OS_USE_10MS_TASKS
/*
void (*const __OS_ROM OS_task_10ms[])(void) =
*/
/* ************************************ */
/* add here 10ms tasks                  */
void (*const __OS_ROM OS_task_10ms[])(void) =
{
  XXX,
  XXX
  /* after last function no comma !!*/
}
;

const u8 __OS_ROM OS_task_nr_10ms = sizeof(OS_task_10ms)/sizeof(OS_task_10ms[0]);
#endif
#ifdef OS_USE_HIGH_PRIO_PREEMPTIVE_TASKS
/*
void (*const __OS_ROM OS_task_preemp[])(void) =
*/
/* ************************************ */
/* add here preemptive tasks (8 maximum)*/

/* preemptive tasks are executed only
   once after activation. They are started
   and terminated by the OS 1ms interrupt routine  */
void (*const __OS_ROM OS_task_preemp[])(void) =
{
  XXX,
  XXX
  /* after last function no comma !!*/
}
;

const u8 __OS_ROM OS_task_nr = sizeof(OS_task_preemp)/sizeof(OS_task_preemp[0]);
#endif
/*
void main (void)
*/
/*
void main (void)
*/
void main (void)
{
  OS_InitTask();

  OS_InitOS();

  /* NEVER enable global Interrupts !!!!!
     This job is done by OS_StartSchwedOS() itself */

  /* Configure and use OS_JUMP_TO_OS_StartSchwedOS();
     if compiler does not know that OS_StartSchwedOS() will
     never return. A JUMP will save stack on RSTACK */

  // OS_JUMP_TO_OS_StartSchwedOS(); /* NO CALL then JUMP to OS_... */

  OS_StartSchwedOS(); /* use call if compiler know: this a is never return
                         function.
                         (if not, you wasted some bytes on stack...) */
}
#pragma vector=OS_INT_TMB_VECT
/*
__OS_interrupt void OS_timebase_int(void)
*/
__OS_interrupt void OS_timebase_int(void)
{
  /* never enable global interrupts here !!!!! */
  /* never use OS_SuspendInt or OS_ResumeInt service here !!!!*/
#if defined(__ATtiny25__) ||defined(__ATtiny45__) || defined(__ATtiny85__)
  static flag os_1ms;
  OCR0A += 250; /* at 4Mhz 500祍 */
  if(os_1ms)
  {
    os_1ms = 0;
    /* OS service for system and timebase */
    OS_TimeBaseService();
  }
  else
  {
    os_1ms = 1;
  }
#else
  /* accurate 1ms interrupt (e.g if interrupts has been blocked before) */
  u16 temp;
  temp = TCNT1;
  temp -= OCR1A;
  temp = 1000 - temp;
  OCR1A  += temp;
  /* --> ( OCR1A = OCR1A + (1000-(TCNT1-OCR1A)); ) */

  /* faster but not accurate */
  /* OCR1A+=1000; */  /* next interrupt in 1ms */
  /* OS service for system and timebase */
  OS_TimeBaseService();
#endif
}
#if defined(__ATtiny25__) || defined(__ATtiny45__) || defined(__ATtiny85__)
/* interrupt for timer overflow */
#pragma vector=OS_INT_OVF_VECT
/*
__OS_interrupt void OS_timebase_overflow(void)
*/
__OS_interrupt void OS_timebase_overflow(void)
{
  os_ov_ctr++;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -