summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/drivers/OFD/src/ofdSpiSerializer.c
blob: 9994f2ed2841a66570875909693c1c915d368dfd (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
88
89
90
91
/**************************************************************************//**
\file  ofdSerializer.c

\brief Implementation of capturing of serial 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/08/09 A. Khromykh - Created
*******************************************************************************/
/******************************************************************************
 *   WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK.  *
 *   EXPERT USERS SHOULD PROCEED WITH CAUTION.                                *
 ******************************************************************************/

#ifdef _OTAU_
#if (APP_USE_OTAU == 1)
#if APP_USE_FAKE_OFD_DRIVER == 0

/******************************************************************************
                   Includes section
******************************************************************************/
#include <ofdExtMemory.h>
#include <ofdMemoryDriver.h>
#include <spi.h>

/******************************************************************************
                   External variables section
******************************************************************************/
extern OFD_Callback_t ofdCallback;

/******************************************************************************
                   Global variables section
******************************************************************************/
HAL_SpiDescriptor_t spiDesc;

/******************************************************************************
                   Implementations section
******************************************************************************/
/**************************************************************************//**
\brief Opens serial interface and checks memory type.

\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_Open(OFD_Callback_t cb)
{
  ofdCallback = cb;

#if defined(ATMEGA1281) || defined(ATMEGA128RFA1)
  spiDesc.tty       = SPI_CHANNEL_0;
  spiDesc.baudRate  = SPI_CLOCK_RATE_2000;
#elif  defined(ATXMEGA256A3) || defined(ATXMEGA256D3)
  spiDesc.tty       = SPI_CHANNEL_D;
  spiDesc.baudRate  = SPI_CLOCK_RATE_8000;
#endif
  spiDesc.clockMode = SPI_CLOCK_MODE3;
  spiDesc.dataOrder = SPI_DATA_MSB_FIRST;
  spiDesc.callback  = NULL;

  if (-1 == HAL_OpenSpi(&spiDesc))
    if (ofdCallback)
      ofdCallback(OFD_SERIAL_INTERFACE_BUSY);

  GPIO_EXT_MEM_CS_set();
  GPIO_EXT_MEM_CS_make_out();
  ofdFindStorageSpace();
#if EXTERNAL_MEMORY == AT25DF041A
  ofdUnprotectMemorySectors();
#endif
}

/**************************************************************************//**
\brief Closes serial interface.
******************************************************************************/
void OFD_Close(void)
{
  HAL_CloseSpi(&spiDesc);
}

#endif // APP_USE_FAKE_OFD_DRIVER == 0
#endif // (APP_USE_OTAU == 1)
#endif // _OTAU_

// eof ofdSerialize.c