Complete TPI protocol code to enter and exit TPI programming mode for the ATTINY...
[pub/USBasp.git] / Projects / AVRISP / Lib / XPROG / TINYNVM.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * Target-related functions for the TINY target's NVM module.
34 */
35
36 #define INCLUDE_FROM_TINYNVM_C
37 #include "TINYNVM.h"
38
39 #if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)
40
41 /** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read.
42 *
43 * \return Boolean true if the NVM controller became ready within the timeout period, false otherwise
44 */
45 bool TINYNVM_WaitWhileNVMBusBusy(void)
46 {
47 TCNT0 = 0;
48 TIFR0 = (1 << OCF1A);
49
50 uint8_t TimeoutMS = TINY_NVM_BUSY_TIMEOUT_MS;
51
52 /* Poll the STATUS register to check to see if NVM access has been enabled */
53 while (TimeoutMS)
54 {
55 /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */
56 XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);
57 if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)
58 return true;
59
60 if (TIFR0 & (1 << OCF1A))
61 {
62 TIFR0 = (1 << OCF1A);
63 TimeoutMS--;
64 }
65 }
66
67 return false;
68 }
69
70 /** Reads memory from the target's memory spaces.
71 *
72 * \param[in] ReadAddress Start address to read from within the target's address space
73 * \param[out] ReadBuffer Buffer to store read data into
74 * \param[in] ReadSize Number of bytes to read
75 *
76 * \return Boolean true if the command sequence complete successfully
77 */
78 bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize)
79 {
80 // TODO
81
82 return true;
83 }
84
85 /** Writes byte addressed memory to the target's memory spaces.
86 *
87 * \param[in] WriteCommand Command to send to the device to write each memory byte
88 * \param[in] WriteAddress Start address to write to within the target's address space
89 * \param[in] WriteBuffer Buffer to source data from
90 *
91 * \return Boolean true if the command sequence complete successfully
92 */
93 bool TINYNVM_WriteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer)
94 {
95 // TODO
96
97 return true;
98 }
99
100 /** Erases a specific memory space of the target.
101 *
102 * \param[in] EraseCommand NVM erase command to send to the device
103 * \param[in] Address Address inside the memory space to erase
104 *
105 * \return Boolean true if the command sequence complete successfully
106 */
107 bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address)
108 {
109 // TODO
110
111 return true;
112 }
113
114 #endif