/*---------------------------------------------------------------------------*
  Project:  NitroSDK - RTC - include
  File:     control.h

  Copyright 2003,2004 Nintendo.  All rights reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law.  They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Log: control.h,v $
  Revision 1.5  2004/07/28 04:31:46  terui
  Fix padding of structure

  Revision 1.4  2004/07/27 07:08:45  yasu
  Add #pragma  warn_padding off

  Revision 1.3  2004/07/20 07:36:43  yada
  tick interval changed 500 -> 5000 (about 10ms)

  Revision 1.2  2004/05/12 11:02:57  terui
  Reduced thread stack size to compress code size.

  Revision 1.1  2004/05/12 02:28:12  terui
  initial upload

  $NoKeywords: $
 *---------------------------------------------------------------------------*/

#ifndef NITRO_RTC_ARM7_CONTROL_H_
#define NITRO_RTC_ARM7_CONTROL_H_

#ifdef  __cplusplus
extern "C" {
#endif

/*===========================================================================*/

#include    <nitro/os.h>

/*---------------------------------------------------------------------------*
    constant definitions
 *---------------------------------------------------------------------------*/
#define     RTC_MESSAGE_ARRAY_MAX       4   // size of message queue for thread synchronization
#define     RTC_THREAD_STACK_SIZE       256 // thread stack size
#define     RTC_POLLING_STACK_SIZE      256 // stack size of alarm monitoring thread
#define     RTC_POLLING_SPAN_TICK       5000    // polling interval (Ticks) when alarm monitoring


/*---------------------------------------------------------------------------*
    structure definitions
 *---------------------------------------------------------------------------*/
// work structure for RTC library

typedef struct RTCWork
{
    OSMessageQueue  msgQ;           // message queue for thread synchronization
    OSMessage       msgArray[ RTC_MESSAGE_ARRAY_MAX ];
                                    // buffer storing messages
    OSThread        thread;         // thread for RTC
    u64             stack[ RTC_THREAD_STACK_SIZE / sizeof(u64) ];
                                    // thread stack for RTC
    BOOL            busy;           // flag for exclusive access to device
    u16             command;        // for saving requests from ARM9
    u16             padding;
    OSThread        polling;        // thread for alarm monitoring
    OSThreadQueue   pollingQ;       // thread queue for monitoring thread queue

#if ( OS_THREAD_MAX_NUM <= 16 )
    u8              reserved[2];    // for padding 4byte align
#endif

    u64             pollingStack[ RTC_POLLING_STACK_SIZE / sizeof(u64) ];
                                    // thread stack for monitoring
    OSAlarm         pollingAlarm;   // timer for alarm monitoring polling
    
} RTCWork;

/*---------------------------------------------------------------------------*
    function definitions
 *---------------------------------------------------------------------------*/
void    RTC_Init( u32 priority );       // initialization, and start thread


/*===========================================================================*/

#ifdef  __cplusplus
}       /* extern "C" */
#endif

#endif  /* NITRO_RTC_ARM7_CONTROL_H_ */

/*---------------------------------------------------------------------------*
  End of file
 *---------------------------------------------------------------------------*/
