How to compile source code downloaded from GitHub

Dear all,

I am working on a project to integrate M25P16 EEPROM with arduino328p.

Thankfully, I was able to find a sample code online at:
https://github.com/contiki/contiki-arduino/blob/master/platform/sensinode/dev/m25p16.c

However, I have been having a hard time compiling the code on the arduino IDE. I had tried adding the libraries and various forms of editing to make it work but to no avail.

Can any kind soul out there tell me the instructions to successfully upload the program to my dev board?

This is the link to download the source code:
https://github.com/contiki-os/contiki/archive/master.zip

#include "dev/n740.h"
#include "dev/m25p16.h"
#include "sys/clock.h"
#include "sys/energest.h"
#include "cc2430_sfr.h"

#define CLOCK_RISING()  {M25P16_PIN_CLOCK = 1; M25P16_PIN_CLOCK = 0;}
#define CLOCK_FALLING() {M25P16_PIN_CLOCK = 0; M25P16_PIN_CLOCK = 1;}
/*---------------------------------------------------------------------------*/
/* Bit-Bang write a byte to the chip */
static void
bit_bang_write(uint8_t byte) CC_NON_BANKED
{
  uint8_t i;
  uint8_t bit;

  /* bit-by-bit */
  for(i = 0x80; i > 0; i >>= 1) {
    /* Is the bit set? */
    bit = 0;
    if(i & byte) {
      /* If it was set, we want to send 1 */
      bit = 1;
    }
    /* Send the bit */
    M25P16_PIN_SER_I = bit;
    /* Clock - Rising */
    CLOCK_RISING();
  }
}
/*---------------------------------------------------------------------------*/
/* Bit-Bang read a byte from the chip */
static uint8_t
bit_bang_read() CC_NON_BANKED
{
  int8_t i;
  uint8_t bits = 0;

  /* bit-by-bit */
  for(i = 7; i >= 0; i--) {
    /* Clock - Falling */
    CLOCK_FALLING();

    /* Read the bit */
    bits |= (M25P16_PIN_SER_O << i);
  }
  return bits;
}
/*---------------------------------------------------------------------------*/
static void
select() CC_NON_BANKED
{
  /* Read current ser/par value */
  uint8_t ser_par = n740_ser_par_get();

  M25P16_PIN_CLOCK = 0;

  ser_par &= ~N740_SER_PAR_CHIP_SEL;  /* Select Flash */

  /* Write the new status back to the ser/par */
  n740_ser_par_set(ser_par);
}
/*---------------------------------------------------------------------------*/
static void
deselect() CC_NON_BANKED
{
  /* Read current ser/par value */
  uint8_t ser_par = n740_ser_par_get();

  ser_par |= N740_SER_PAR_CHIP_SEL;    /* De-Select Flash  */

  /* Write the new status back to the ser/par */
  n740_ser_par_set(ser_par);
}
/*---------------------------------------------------------------------------*/
void
m25p16_wren()
{
  select();
  bit_bang_write(M25P16_I_WREN);
  deselect();

  while(!M25P16_WEL());
}
/*---------------------------------------------------------------------------*/
void
m25p16_wrdi()
{
  select();
  bit_bang_write(M25P16_I_WRDI);
  deselect();
}
/*---------------------------------------------------------------------------*/
void
m25p16_rdid(struct m25p16_rdid * rdid)
{
  uint8_t i;

  select();
  bit_bang_write(M25P16_I_RDID);

  rdid->man_id = bit_bang_read();
  rdid->mem_type = bit_bang_read(); /* Device ID MSB */
  rdid->mem_size = bit_bang_read(); /* Device ID LSB */
  rdid->uid_len = bit_bang_read();
  for(i = 0; i < rdid->uid_len; i++) {
    rdid->uid[i] = bit_bang_read();
  }
  deselect();
}
/*---------------------------------------------------------------------------*/
uint8_t
m25p16_rdsr()
{
  uint8_t rv;

  select();
  bit_bang_write(M25P16_I_RDSR);
  rv = bit_bang_read();
  deselect();

  return rv;
}
/*---------------------------------------------------------------------------*/
void
m25p16_wrsr(uint8_t val)
{
  m25p16_wren(); /* Write Enable */

  select();
  ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE);
  bit_bang_write(M25P16_I_WRSR);
  bit_bang_write(val);
  ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE);
  deselect();
}
/*---------------------------------------------------------------------------*/
void
m25p16_read(uint8_t * addr, uint8_t * buff, uint8_t buff_len)
{
  uint8_t i;

  select();
  ENERGEST_ON(ENERGEST_TYPE_FLASH_READ);

#if M25P16_READ_FAST
  bit_bang_write(M25P16_I_FAST_READ);
#else
  bit_bang_write(M25P16_I_READ);
#endif

  /* Write the address, MSB in addr[0], bits [7:5] of the MSB: 'don't care' */
  for(i = 0; i < 3; i++) {
    bit_bang_write(addr[i]);
  }

  /* For FAST_READ, send the dummy byte */
#if M25P16_READ_FAST
  bit_bang_write(M25P16_DUMMY_BYTE);
#endif

  for(i = 0; i < buff_len; i++) {
    buff[i] = ~bit_bang_read();
  }
  ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ);
  deselect();
}
/*---------------------------------------------------------------------------*/
void
m25p16_pp(uint8_t * addr, uint8_t * buff, uint8_t buff_len)
{
  uint8_t i;

  m25p16_wren(); /* Write Enable */

  select();
  ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE);
  bit_bang_write(M25P16_I_PP);

  /* Write the address, MSB in addr[0] */
  for(i = 0; i < 3; i++) {
    bit_bang_write(addr[i]);
  }

  /* Write the bytes */
  for(i=0; i<buff_len; i++) {
    bit_bang_write(~buff[i]);
  }
  ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE);
  deselect();
}
/*---------------------------------------------------------------------------*/
void
m25p16_se(uint8_t s)
{
  m25p16_wren(); /* Write Enable */

  select();
  ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE);
  bit_bang_write(M25P16_I_SE);
  bit_bang_write(s);
  bit_bang_write(0x00);
  bit_bang_write(0x00);
  deselect();
  ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE);
}
/*---------------------------------------------------------------------------*/
void
m25p16_be()
{
  m25p16_wren(); /* Write Enable */

  select();
  bit_bang_write(M25P16_I_BE);
  deselect();
}
/*---------------------------------------------------------------------------*/
void
m25p16_dp()
{
  select();
  bit_bang_write(M25P16_I_DP);
  deselect();
}
/*---------------------------------------------------------------------------*/
/*
 * Release Deep Power Down. We do NOT read the Electronic Signature
 */
void
m25p16_res() {
  select();
  bit_bang_write(M25P16_I_RES);
  deselect();
  /* a few usec between RES and standby */
  while(M25P16_WIP());
}
/*---------------------------------------------------------------------------*/
/**
 * Release Deep Power Down. Read and return the Electronic Signature
 * must return 0x14
 *
 * \return The old style Electronic Signature. This must be 0x14
 */
uint8_t
m25p16_res_res() {
  uint8_t rv;

  select();
  bit_bang_write(M25P16_I_RES);
  bit_bang_write(M25P16_DUMMY_BYTE);
  bit_bang_write(M25P16_DUMMY_BYTE);
  bit_bang_write(M25P16_DUMMY_BYTE);

  rv = bit_bang_read();

  deselect();

  /* a few usec between RES and standby */
  while(M25P16_WIP());
  return rv;
}

It doesn't contain a main(), setup(), or loop() so you should probably treat it as a library. Put it in a library folder and re-start the IDE. Than you should be able to reference it from your sketch.

If it doesn't compile when you upload your sketch there may be other libraries it needs. Install them.