summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/rcb230/src/halUid.c
blob: 21976ce91362eb05f83023ef2280aa851e228fd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**************************************************************************//**
  \file   halUid.c

  \brief  Implementation of UID interface.

  \author
      Atmel Corporation: http://www.atmel.com \n
      Support email: avr@atmel.com

    Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
    Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
    History:
      7/12/07 A. Khromykh - Created
 ******************************************************************************/
/******************************************************************************
 *   WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK.  *
 *   EXPERT USERS SHOULD PROCEED WITH CAUTION.                                *
 ******************************************************************************/

/******************************************************************************
                   Includes section
******************************************************************************/
#include <halRfPio.h>
#include <halRfSpi.h>
#include <uid.h>

/******************************************************************************
                   Types section
******************************************************************************/
/** \brief uid type. */
typedef union
{
  uint64_t uid;
  uint8_t array[sizeof(uint64_t)];
} HalUid_t;

/******************************************************************************
                   Global variables section
******************************************************************************/
static HalUid_t halUid = {.uid = 0ull};

/******************************************************************************
                   Implementations section
******************************************************************************/
/******************************************************************************
 Reads uid from external spi eeprom at25010a.
******************************************************************************/
void halReadUid(void)
{
  uint8_t command = 0x03;
  uint8_t address = 0;
  uint8_t itr;

  GPIO_RF_RST_make_out();
  GPIO_RF_RST_clr();
  GPIO_SPI_CS_clr();

  HAL_WriteByteRfSpi(command);
  HAL_WriteByteRfSpi(address);
  for (itr=0; itr<sizeof(uint64_t); itr++)
  {
    halUid.array[itr] = HAL_WriteByteRfSpi(address);
  }

  GPIO_SPI_CS_set();
}

/******************************************************************************
 Returns number which was read from external eeprom.
 Parameters:
   id - UID buffer pointer.
 Returns:
   0 - if unique ID has been found without error;
  -1 - if there are some erros during UID discovery.
******************************************************************************/
int HAL_ReadUid(uint64_t *id)
{
  if (!id)
    return -1;

  *id = halUid.uid;
  return 0;
}

// eof uid.c