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

📄 thread.h

📁 U盘控制器USB97C223的固件代码,对2kPAGE NAND FLASH 有很好的支持.
💻 H
字号:
/*============================================================================
  ____________________________________________________________________________
                                ______________________________________________
   SSSS  M   M          CCCC          Standard Microsystems Corporation
  S      MM MM   SSSS  C                    Austin Design Center
   SSS   M M M  S      C                 11000 N. Mopac Expressway
      S  M   M   SSS   C                Stonelake Bldg. 6, Suite 500
  SSSS   M   M      S   CCCC                Austin, Texas 78759
                SSSS            ______________________________________________
  ____________________________________________________________________________

  Copyright(C) 1999, Standard Microsystems Corporation
  All Rights Reserved.

  This program code listing is proprietary to SMSC and may not be copied,
  distributed, or used without a license to do so.  Such license may have
  Limited or Restricted Rights. Please refer to the license for further
  clarification.
  ____________________________________________________________________________

  Notice: The program contained in this listing is a proprietary trade
  secret of SMSC, Hauppauge, New York, and is copyrighted
  under the United States Copyright Act of 1976 as an unpublished work,
  pursuant to Section 104 and Section 408 of Title XVII of the United
  States code. Unauthorized copying, adaption, distribution, use, or
  display is prohibited by this law.
  ____________________________________________________________________________

  Use, duplication, or disclosure by the Government is subject to
  restrictions as set forth in subparagraph(c)(1)(ii) of the Rights
  in Technical Data and Computer Software clause at DFARS 52.227-7013.
  Contractor/Manufacturer is Standard Microsystems Corporation,
  80 Arkay Drive, Hauppauge, New York, 1178-8847.
  ____________________________________________________________________________
  ____________________________________________________________________________

  thd.h - MinimOS threads.
  ____________________________________________________________________________

  comments tbd
  ____________________________________________________________________________

  Revision History
  Date      Who  Comment
  ________  ___  _____________________________________________________________
  05/31/00  tbh  initial version
  09/27/00  tbh  added documentation
  02/15/01  tbh  added thread_clr_sync_ex()
  03/15/01  tbh  -merged 10x and 20x versions for improved maintainability
                 -converted api macros into functions to facilitate
                  implementation, and facilitate debugging with an ice
  07/27/01  tbh  -tweak port for 20x family
  04/02/02  ds   Modified _thread_clr_sync to call macros instead of functions.
  06/21/02  tbh  added prototype for thread_clr_sync_ex
  07/18/02  tbh  thread_pop() had a nasty habbit of restoring the original
                 pre-dfa invocation value of the bits_got field.  this caused
                 two bugs - first, bits that were set before a push, then cleared
                 in the dfa, got re-set by the pop (the usbreset connundrum).
                 second, bits that got set after the push, but weren't handled
                 by the dfa, got cleared by the pop and thus events went into
                 the bit bucket.  so, i rearranged the fields in t_thread so
                 bits got is at the end of the struct, and changed thread_pop
                 to not re-write the last 16 bits of the context.
============================================================================*/

//------------------------------------------------------------------------------
// synchronizers
typedef uint16 t_sync;
//------------------------------------------------------------------------------
// This bit mask represents all synchronizers.
// It is typically used for receiving any synchronizers when yielding.
// It is never delivered to any threads; it is just a mask.
#define kbm_sync_any   65535
// This bit mask represents all synchronizers.
// It is typically used for clearing all received synchronizers when yielding.
// It is never delivered to any threads; it is just a mask.
#define kbm_sync_all   65535
// This bit mask represents no synchronizers.
// It is typically is not used, but could be used as a place holder to avoid
// clearing any synchronizers when during a yield.  It is never delivered to
// any threads; it is just a mask.
#define kbm_sync_none      0
// This synchronizer is delivered to each thread when it is first activated
// following its creation.  This essentially activates the start state for the
// thread, which should perform initialization, register for synchronizers of
// interest, and yield to another state.
#define kbm_sync_create    1
// This synchronizer is delivered to threads that register for it.
// It arrives when a packet with a valid CRC arrives on an endpoint owned by a
// thread that registered for it.  The packet number of the received packet can
// be obtained using thread_rd_rx_pnr().
#define kbm_sync_usbrx     2
// This synchronizer is delivered to threads that register for it.
// It arrives when a packet has been transmitted to, and ACK'd by, the host.
// The synchronizer is delivered to the thread that owns the endpoint that
// transmitted the packet.
#define kbm_sync_usbtx     4
// This synchronizer is delivered to threads who's associated endpoints NAK
// an OUT token.  MinimOS 1.1 only delivers this synchronizer to g_ix_ctl_thread,
// the USB default control pipe handler, which is part of the USB engine.
// $$$ Watch this spot for updates that address this limitation.
// $$$ keep watching.  were only up to ver 2.1 with no update here...:)
#define kbm_sync_outnak    8
// This synchronizer is delivered to threads who's associated endpoints NAK
// an IN token.  MinimOS 1.1 only delivers this synchronizer to g_ix_ctl_thread,
// the USB default control pipe handler, which is part of the USB engine.
// $$$ Watch this spot for updates that address this limitation.
// $$$ keep watching.  were only up to ver 2.1 with no update here...:)
#define kbm_sync_innak    16
// Each thread has a 16 bit timer that can be started by thread_set_timer().
// This synchronizer is delivered to a thread when its timer counts down to zero.
#define kbm_sync_timer    32
// These are reserved for future use.
// Using these synchronizers as "user" synchronizers will almost certainly
// render your application incompatible with future versions of MinimOS.
#define kbm_sync_rsrvd0   64
#define kbm_sync_rsrvd1  128
#define kbm_sync_rsrvd2  256
#define kbm_sync_rsrvd3  512
#define kbm_sync_rsrvd4 1024
// These are general purpose synchronizers available to the user application.
#define kbm_sync_usr0   2048
#define kbm_sync_usr1   4096
#define kbm_sync_usr2   8192
#define kbm_sync_usr3  16384
#define kbm_sync_usr4  32768

//------------------------------------------------------------------------------
// a thread code fragment
typedef void (code *t_thd_entry)(void) reentrant;

//------------------------------------------------------------------------------
typedef struct s_thread
{
  t_thd_entry entry;   // current entrypoint into thread's dfa
  t_thd_entry poller;  // poller for this thread's interupt-less events
  void *argp;          // pointer to arguments when invoked as a library dfa
  uint8 top;           // index of top element of dfa context stack
  uint8 base;          // base address of dfa context stack (IT IS A PNR!)
  uint16 timer;        // when timer hits 0 kbm_sync_timer is delivered
  t_sync bits_reg;     // synchronizers this thread wants to receive
  t_sync bits_got;     // synchronizers delivered to this thread
} t_thread;

//------------------------------------------------------------------------------
// the macro versions of the functions are faster, but trickier to use properly.
// they exist only to improve the performance of the kernel.
//------------------------------------------------------------------------------

//+-----------------------------------------------------------------------------
// Name:
//   _thread_got_sync
//
// Declaration:
//  t_sync _thread_got_sync(t_sync msk);
//
// Purpose:
//  Fast version for kernel and interface manager use.
//  Allows the active thread to determine which synchronizers have been
//  delivered to it.
//
// Arguments:
//  msk - a bit mask representing the synchronizer(s) to be checked.
//
// Return:
//  A t_sync bitmask representing the received synchronizers.
//
// Notes:
//   This is the macro version of thread_got_sync().
//   It is faster than the function.  Use where performance is critical.
//
// Since:
//   MinimOS-1.0
//------------------------------------------------------------------------------
#define _thread_got_sync(__msk) (g_thread[g_tid].bits_got & (__msk))

//+-----------------------------------------------------------------------------
// Name:
//   _thread_clr_sync
//
// Declaration:
//  void _thread_clr_sync(t_sync msk);
//
// Purpose:
//  Fast version for kernel and interface manager use.
//  Clears bits in the active thread's received synchronizer mask.
//
// Arguments:
//  msk - a bit mask representing the synchronizer(s) to be cleared.
//
// Return:
//  none.
//
// Notes:
//   This is the macro version of thread_clr_sync().
//   It is faster than the function.  Use where performance is critical.
//
// Since:
//   MinimOS-1.0
//------------------------------------------------------------------------------
#define _thread_clr_sync(__msk) { _mcu_begin_critical_section(); g_thread[g_tid].bits_got &= ~(__msk); _mcu_end_critical_section(); }

//+-----------------------------------------------------------------------------
// Name:
//   _thread_return_dfa
//
// Declaration:
//  void _thread_return_dfa(uint8 val);
//
// Purpose:
//   End a dfa and return a value.
//
// Arguments:
//  val - the uint8 to be returned from the dfa via the thread's argp.
//
// Return:
//  none.
//
// Notes:
//   thread_return_dfa is the early misnamed form.
//
// Since:
//   MinimOS-2.2
//------------------------------------------------------------------------------
#define thread_return_dfa _thread_return_dfa
#define _thread_return_dfa(__val) { (*(uint8 *)thread_rd_dfa_argp())=(__val) ; thread_end_dfa() ; }

//------------------------------------------------------------------------------
// prototypes from thread.c
uint8 thread_create(t_thd_entry entry, t_thd_entry poller, t_bool nested) reentrant;
void thread_suspend(uint8 tid) reentrant;
void thread_resume(uint8 tid) reentrant;
void thread_set_timer(uint16 ticks) reentrant;
void thread_set_timer_ex(uint8 tid, uint16 ticks) reentrant;
void thread_set_sync(uint8 tid, t_sync msk) reentrant;
void thread_clr_sync_ex(uint8 tid, t_sync msk) reentrant;
void thread_clr_sync(t_sync msk) reentrant;
t_sync thread_got_sync(t_sync msk) reentrant;
t_sync thread_got_sync_ex(uint8 tid, t_sync msk) reentrant;
void thread_reg_sync(t_sync msk) reentrant;
t_bool thread_is_reg_for(uint8 tid, t_sync msk) reentrant;
void thread_yield(void) reentrant;
void thread_yield_ex(t_sync clrmsk, t_sync regmsk, t_thd_entry entry) reentrant;
void thread_yield_ex2(t_sync regmsk, t_thd_entry entry) reentrant;
void thread_halt(void) reentrant;
void thread_set_state(t_thd_entry entry) reentrant;
void thread_set_poller(t_thd_entry poller) reentrant;
t_memory_ref thread_rd_dfa_argp(void) reentrant;
void thread_wr_dfa_argp(t_memory_ref value) reentrant;
void thread_run_dfa(t_thd_entry dfa, void *argp, t_thd_entry next) reentrant;
void thread_end_dfa(void) reentrant;
void thread_abort_dfa(t_thd_entry abort_entry, uint8 stack_top) reentrant;

//------------------------------------------------------------------------------
// exported globals from thread.c
#if defined(__kernel__) || defined(__manager__)
extern seg_knl_manager uint8 g_tid;
extern volatile t_thread seg_knl_table g_thread[k_dev_max_thread];
#endif
#ifdef __kernel__
extern seg_knl_manager uint8 g_ntid;
extern seg_knl_manager uint8 g_suspended;
#endif
//---eof------------------------------------------------------------------------


⌨️ 快捷键说明

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