Interview questions: reset function


You have to implement a "Reset" function for a hardware module. The given function should run on a multithreading capable, pre-emptive real-time operating system. The hardware module is "memory mapped".

For the "Reset" the bits 0 and 1 on address 0xF0 have to be set to "1".

After 10 microseconds one can evaluate the successful execution of the Reset based on bit 1 of the same address. Value 0 indicates success, value 1 indicates failure. You may use a pseudo code for the implementation.

/* Resets the hardware
returns 0 on success and -1 on failure
int Hardware_Reset(void) {


typedef volatile uint8_t vint;
vint *reset_addr = (vint *) 0xF0;
static inline void reset(void)
   *reset_addr = *reset_addr | 0x3;
static inline int check_reset(void)
   return ((*reset_addr & 0x2) >> 1) - 1;
spinlock_t hr;
void spin_lock_irqsave(spinlock_t *lock, unsigned long flags);
void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags);
void udelay(unsigned long usecs);
int Hardware_Reset(void)
   int status;
   unsigned long flags;
   /* disables interrupts and preemption */
   spin_lock_irqsave(&hr, flags);
      udelay(10); /* Function. Can be called in atomic context. */
      status = check_reset();
   /* restores interrupts and enbales preemption */
   spin_unlock_irqrestore(&hr, flags);
   return status;


comments powered by Disqus