/*******************************************************************************
NMon User - Nohau Monitor User Application

PLEASE MODIFY THIS FILE - THIS IS THE USER MODIFIABLE PART OF NMON 
(Nohau Monitor).
 
Creator: Sten Larsson
$Header: /NCARM_Misc/Monitor/NMon/NMon_User.c 1     5/28/03 5:09p Stenl $
*******************************************************************************/
#include "NSrv.h"

/*******************************************************************************
This function is called at program start and for command NMON_SET_DEFAULTS. It 
gives the module a chance to initialize variables and hardware.
*******************************************************************************/
void NUsr_Init(void)
{
}


/*##############################################################################
## WRITE FUNCTIONS - only when NUSR_WRITE_ENABLE defined
##############################################################################*/
#ifdef NUSR_WRITE_ENABLE

/*******************************************************************************
This function returns TRUE if the Target Specific code wants to do the memory 
write. Otherwise, return FALSE.

See "NSrv.h" for documentation.
*******************************************************************************/
BOOL NUsr_WantWrite(void)
{
   if (NMon_Space != NSPACE_FLASH)
   {
      return FALSE; 
   }
   else
   {
      return TRUE; 
   }
}


/*******************************************************************************
This function should prepare the system/hardware before a write.

See "NSrv.h" for documentation.
*******************************************************************************/
BYTE NUsr_PreWrite(void)
{
   if (NMon_Space != NSPACE_FLASH)
   {
      return NSTAT_FAIL_NOIMPL;
   }
   
   return NSTAT_OK;
}


/*******************************************************************************
This function will normally write to flash - the sample here writes to RAM.

See "NSrv.h" for documentation.
*******************************************************************************/
BYTE NUsr_Write(void)
{
   BYTE* pBuf = NMon_Buf;
   
   if (NMon_Space != NSPACE_FLASH)
   {
      return NSTAT_FAIL_NOIMPL;
   }

   /* Write to flash - remember that it should be possible to write
   ** to the highest address, ie 0xFFFFFFFF on a 32 bit system - the 
   ** pointer will wrap to zero. 
   **
   ** Note that it is required that NMon_Addr_Curr always points at
   ** next address for write, as it may not be resent between send
   ** commands.
   */
   while (!NMon_Addr_Curr && (NMon_Addr_Curr <= NMon_Addr_Last))
   {
      /* This is just an example that writes to RAM - change it 
      ** so that it writes to flash. */ 
      *NMon_Addr_Curr++ = *pBuf++; 
   }
   
   return NSTAT_OK;
}


/*******************************************************************************
This function should restore the system/hardware after write.

See "NSrv.h" for documentation.
*******************************************************************************/
BYTE NUsr_PostWrite(void)
{
   if (NMon_Space != NSPACE_FLASH)
   {
      return NSTAT_FAIL_NOIMPL;
   }
   return NSTAT_OK;
}

#endif /* NUSR_WRITE_ENABLE */



/*##############################################################################
## READ FUNCTIONS - only when NUSR_READ_ENABLE defined
##############################################################################*/
#ifdef NUSR_READ_ENABLE

/*******************************************************************************
This function returns TRUE if the Target Specific code wants to do the memory 
read (this may be for serial EEPROM etc). Otherwise, return FALSE.

See "NSrv.h" for documentation.
*******************************************************************************/
BOOL NUsr_WantRead(void)
{
   if (NMon_Space != NSPACE_FLASH)
   {
      return FALSE; 
   }
   else
   {
      return TRUE; 
   }
}


/*******************************************************************************
This is where you implement reading. Copy data from addresses into NMon_Buf.

See "NSrv.h" for documentation.
*******************************************************************************/
BYTE NUsr_Read(void)
{
   BYTE* pBuf = NMon_Buf;
   
   if (NMon_Space != NSPACE_FLASH)
   {
      return NSTAT_FAIL_NOIMPL;
   }

   /* Read from flash - remember that it should be possible to read
   ** from the highest address, ie 0xFFFFFFFF on a 32 bit system - the 
   ** pointer will wrap to zero. 
   **
   ** Note that it is required that NMon_Addr_Curr always points at
   ** next address for write, as it may not be resent between send
   ** commands.
   */
   while (!NMon_Addr_Curr && (NMon_Addr_Curr <= NMon_Addr_Last))
   {
      /* This is just an example that writes to RAM - change it 
      ** so that it writes to flash. */ 
      *pBuf++ = *NMon_Addr_Curr++;
   }
   
   return NSTAT_OK;
}

#endif /* NUSR_READ_ENABLE */
